@swype-org/react-sdk 0.1.86 → 0.1.87
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +30 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +30 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -804,7 +804,12 @@ var VERIFY_POPUP_TIMEOUT_MS = 6e4;
|
|
|
804
804
|
function findDevicePasskeyViaPopup(options) {
|
|
805
805
|
return new Promise((resolve, reject) => {
|
|
806
806
|
const channelId = `swype-pv-${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
807
|
-
const
|
|
807
|
+
const verificationToken = crypto.randomUUID();
|
|
808
|
+
const payload = {
|
|
809
|
+
...options,
|
|
810
|
+
channelId,
|
|
811
|
+
verificationToken
|
|
812
|
+
};
|
|
808
813
|
const encoded = btoa(JSON.stringify(payload));
|
|
809
814
|
const popupUrl = `${window.location.origin}/passkey-verify#${encoded}`;
|
|
810
815
|
const popup = window.open(popupUrl, "swype-passkey-verify");
|
|
@@ -824,7 +829,15 @@ function findDevicePasskeyViaPopup(options) {
|
|
|
824
829
|
setTimeout(() => {
|
|
825
830
|
if (!settled) {
|
|
826
831
|
cleanup();
|
|
827
|
-
|
|
832
|
+
checkServerForVerifiedPasskey(
|
|
833
|
+
options.authToken,
|
|
834
|
+
options.apiBaseUrl,
|
|
835
|
+
verificationToken
|
|
836
|
+
).then((credentialId) => {
|
|
837
|
+
resolve(credentialId);
|
|
838
|
+
}).catch(() => {
|
|
839
|
+
resolve(null);
|
|
840
|
+
});
|
|
828
841
|
}
|
|
829
842
|
}, POPUP_CLOSED_GRACE_MS);
|
|
830
843
|
}
|
|
@@ -860,6 +873,17 @@ function findDevicePasskeyViaPopup(options) {
|
|
|
860
873
|
}
|
|
861
874
|
});
|
|
862
875
|
}
|
|
876
|
+
async function checkServerForVerifiedPasskey(authToken, apiBaseUrl, verificationToken) {
|
|
877
|
+
if (!authToken || !apiBaseUrl) return null;
|
|
878
|
+
const res = await fetch(`${apiBaseUrl}/v1/users/config`, {
|
|
879
|
+
headers: { Authorization: `Bearer ${authToken}` }
|
|
880
|
+
});
|
|
881
|
+
if (!res.ok) return null;
|
|
882
|
+
const body = await res.json();
|
|
883
|
+
const passkeys = body.config.passkeys ?? [];
|
|
884
|
+
const matched = passkeys.find((p) => p.lastVerificationToken === verificationToken);
|
|
885
|
+
return matched?.credentialId ?? null;
|
|
886
|
+
}
|
|
863
887
|
async function checkServerForNewPasskey(authToken, apiBaseUrl, existingCredentialIds) {
|
|
864
888
|
if (!authToken || !apiBaseUrl) return null;
|
|
865
889
|
const res = await fetch(`${apiBaseUrl}/v1/users/config`, {
|
|
@@ -5591,14 +5615,16 @@ function SwypePaymentInner({
|
|
|
5591
5615
|
setVerifyingPasskeyPopup(true);
|
|
5592
5616
|
setError(null);
|
|
5593
5617
|
try {
|
|
5618
|
+
const token = await getAccessToken();
|
|
5594
5619
|
const matched = await findDevicePasskeyViaPopup({
|
|
5595
5620
|
credentialIds: knownCredentialIds,
|
|
5596
|
-
rpId: resolvePasskeyRpId()
|
|
5621
|
+
rpId: resolvePasskeyRpId(),
|
|
5622
|
+
authToken: token ?? void 0,
|
|
5623
|
+
apiBaseUrl
|
|
5597
5624
|
});
|
|
5598
5625
|
if (matched) {
|
|
5599
5626
|
setActiveCredentialId(matched);
|
|
5600
5627
|
window.localStorage.setItem(ACTIVE_CREDENTIAL_STORAGE_KEY, matched);
|
|
5601
|
-
const token = await getAccessToken();
|
|
5602
5628
|
if (token) {
|
|
5603
5629
|
reportPasskeyActivity(apiBaseUrl, token, matched).catch(() => {
|
|
5604
5630
|
});
|