decane-connect-kit 2.9.1 → 2.10.0
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 +25 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +25 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2271,6 +2271,15 @@ var Storage = class {
|
|
|
2271
2271
|
async getShare(userId) {
|
|
2272
2272
|
return (await this._db).get(STORE, userId) ?? null;
|
|
2273
2273
|
}
|
|
2274
|
+
/**
|
|
2275
|
+
* Every share this browser holds. Needed because signing out clears the
|
|
2276
|
+
* remembered identity while deliberately leaving the share behind, so the
|
|
2277
|
+
* userId that keys it is no longer known and the share can only be found by
|
|
2278
|
+
* enumeration. See passkeyDeviceCandidate().
|
|
2279
|
+
*/
|
|
2280
|
+
async listShares() {
|
|
2281
|
+
return (await this._db).getAll(STORE);
|
|
2282
|
+
}
|
|
2274
2283
|
async putShare(share) {
|
|
2275
2284
|
await (await this._db).put(STORE, share);
|
|
2276
2285
|
}
|
|
@@ -4024,7 +4033,15 @@ async function createDecaneConnect(config) {
|
|
|
4024
4033
|
}
|
|
4025
4034
|
async function passkeyLoginCandidate() {
|
|
4026
4035
|
if (!persisted?.userId || !isPasskeySupported()) return null;
|
|
4027
|
-
|
|
4036
|
+
return usablePasskeyShare(await storage.getShare(persisted.userId));
|
|
4037
|
+
}
|
|
4038
|
+
async function passkeyDeviceCandidate() {
|
|
4039
|
+
if (!isPasskeySupported()) return null;
|
|
4040
|
+
if (persisted?.userId) return passkeyLoginCandidate();
|
|
4041
|
+
const candidates = (await storage.listShares()).map(usablePasskeyShare).filter(Boolean);
|
|
4042
|
+
return candidates.length === 1 ? candidates[0] : null;
|
|
4043
|
+
}
|
|
4044
|
+
function usablePasskeyShare(stored) {
|
|
4028
4045
|
if (!stored || stored.unlockMethod !== "passkey") return null;
|
|
4029
4046
|
if (!stored.credentialId || !stored.prfSalt) return null;
|
|
4030
4047
|
return stored;
|
|
@@ -4183,10 +4200,10 @@ async function createDecaneConnect(config) {
|
|
|
4183
4200
|
return handleAuthResult(result);
|
|
4184
4201
|
},
|
|
4185
4202
|
async canSignInWithPasskey() {
|
|
4186
|
-
return await
|
|
4203
|
+
return await passkeyDeviceCandidate() !== null;
|
|
4187
4204
|
},
|
|
4188
4205
|
async signInWithPasskey() {
|
|
4189
|
-
const candidate = await
|
|
4206
|
+
const candidate = await passkeyDeviceCandidate();
|
|
4190
4207
|
if (!candidate) throw new NewDeviceError();
|
|
4191
4208
|
return passkeyLogin(candidate);
|
|
4192
4209
|
},
|
|
@@ -6763,7 +6780,11 @@ function DecaneKit({ config, children }) {
|
|
|
6763
6780
|
"session-expired",
|
|
6764
6781
|
() => setSocialAuth((p) => ({ ...p, isUnlocked: false, sessionExpiresAt: null }))
|
|
6765
6782
|
);
|
|
6766
|
-
sdk.on("disconnected", () =>
|
|
6783
|
+
sdk.on("disconnected", () => {
|
|
6784
|
+
setSocialAuth(DEFAULT_SOCIAL);
|
|
6785
|
+
sdk.canSignInWithPasskey().then((can) => setSocialAuth((p) => ({ ...p, canUsePasskey: can }))).catch(() => {
|
|
6786
|
+
});
|
|
6787
|
+
});
|
|
6767
6788
|
sdk.on("wallet-creating", () => setSocialAuth((p) => ({ ...p, phase: "creating" })));
|
|
6768
6789
|
sdk.on("wallet-unlocking", () => setSocialAuth((p) => ({ ...p, phase: "unlocking" })));
|
|
6769
6790
|
sdk.on("connected", () => setSocialAuth((p) => ({ ...p, phase: null })));
|