@swype-org/react-sdk 0.1.27 → 0.1.28
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 +28 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +24 -11
- package/dist/index.d.ts +24 -11
- package/dist/index.js +28 -20
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -219,7 +219,7 @@ async function fetchAccounts(apiBaseUrl, token, credentialId) {
|
|
|
219
219
|
}
|
|
220
220
|
async function createTransfer(apiBaseUrl, token, params) {
|
|
221
221
|
const body = {
|
|
222
|
-
id: crypto.randomUUID(),
|
|
222
|
+
id: params.id ?? crypto.randomUUID(),
|
|
223
223
|
credentialId: params.credentialId,
|
|
224
224
|
sources: [{ [params.sourceType]: params.sourceId }],
|
|
225
225
|
destinations: [
|
|
@@ -816,6 +816,11 @@ async function createPasskeyCredential(params) {
|
|
|
816
816
|
};
|
|
817
817
|
}
|
|
818
818
|
async function deviceHasPasskey(credentialId) {
|
|
819
|
+
const found = await findDevicePasskey([credentialId]);
|
|
820
|
+
return found != null;
|
|
821
|
+
}
|
|
822
|
+
async function findDevicePasskey(credentialIds) {
|
|
823
|
+
if (credentialIds.length === 0) return null;
|
|
819
824
|
try {
|
|
820
825
|
const challenge = new Uint8Array(32);
|
|
821
826
|
crypto.getRandomValues(challenge);
|
|
@@ -824,17 +829,18 @@ async function deviceHasPasskey(credentialId) {
|
|
|
824
829
|
publicKey: {
|
|
825
830
|
challenge,
|
|
826
831
|
rpId: resolvePasskeyRpId(),
|
|
827
|
-
allowCredentials:
|
|
832
|
+
allowCredentials: credentialIds.map((id) => ({
|
|
828
833
|
type: "public-key",
|
|
829
|
-
id: base64ToBytes(
|
|
830
|
-
}
|
|
834
|
+
id: base64ToBytes(id)
|
|
835
|
+
})),
|
|
831
836
|
userVerification: "discouraged",
|
|
832
837
|
timeout: 3e4
|
|
833
838
|
}
|
|
834
839
|
});
|
|
835
|
-
|
|
840
|
+
if (!assertion) return null;
|
|
841
|
+
return toBase64(assertion.rawId);
|
|
836
842
|
} catch {
|
|
837
|
-
return
|
|
843
|
+
return null;
|
|
838
844
|
}
|
|
839
845
|
}
|
|
840
846
|
function useTransferPolling(intervalMs = 3e3) {
|
|
@@ -2199,7 +2205,8 @@ function SwypePayment({
|
|
|
2199
2205
|
destination,
|
|
2200
2206
|
onComplete,
|
|
2201
2207
|
onError,
|
|
2202
|
-
useWalletConnector
|
|
2208
|
+
useWalletConnector,
|
|
2209
|
+
idempotencyKey
|
|
2203
2210
|
}) {
|
|
2204
2211
|
const { apiBaseUrl, tokens, depositAmount } = useSwypeConfig();
|
|
2205
2212
|
const { ready, authenticated, user, login, logout, getAccessToken } = reactAuth.usePrivy();
|
|
@@ -2266,20 +2273,20 @@ function SwypePayment({
|
|
|
2266
2273
|
}
|
|
2267
2274
|
return;
|
|
2268
2275
|
}
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2276
|
+
if (cancelled) return;
|
|
2277
|
+
const credentialIds = allPasskeys.map((p) => p.credentialId);
|
|
2278
|
+
const matched = await findDevicePasskey(credentialIds);
|
|
2279
|
+
if (cancelled) return;
|
|
2280
|
+
if (matched) {
|
|
2281
|
+
setActiveCredentialId(matched);
|
|
2282
|
+
window.localStorage.setItem(ACTIVE_CREDENTIAL_STORAGE_KEY, matched);
|
|
2283
|
+
if (depositAmount != null && depositAmount > 0) {
|
|
2284
|
+
setStep("ready");
|
|
2285
|
+
} else {
|
|
2286
|
+
setStep("enter-amount");
|
|
2280
2287
|
}
|
|
2288
|
+
return;
|
|
2281
2289
|
}
|
|
2282
|
-
if (cancelled) return;
|
|
2283
2290
|
setStep("register-passkey");
|
|
2284
2291
|
} catch {
|
|
2285
2292
|
if (!cancelled) {
|
|
@@ -2513,6 +2520,7 @@ function SwypePayment({
|
|
|
2513
2520
|
}
|
|
2514
2521
|
}
|
|
2515
2522
|
const t = await createTransfer(apiBaseUrl, token, {
|
|
2523
|
+
id: idempotencyKey,
|
|
2516
2524
|
credentialId: activeCredentialId,
|
|
2517
2525
|
sourceType: effectiveSourceType,
|
|
2518
2526
|
sourceId: effectiveSourceId,
|
|
@@ -3551,6 +3559,7 @@ exports.SwypeProvider = SwypeProvider;
|
|
|
3551
3559
|
exports.createPasskeyCredential = createPasskeyCredential;
|
|
3552
3560
|
exports.darkTheme = darkTheme;
|
|
3553
3561
|
exports.deviceHasPasskey = deviceHasPasskey;
|
|
3562
|
+
exports.findDevicePasskey = findDevicePasskey;
|
|
3554
3563
|
exports.getTheme = getTheme;
|
|
3555
3564
|
exports.lightTheme = lightTheme;
|
|
3556
3565
|
exports.swypeApi = api_exports;
|