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.js
CHANGED
|
@@ -2195,6 +2195,15 @@ var Storage = class {
|
|
|
2195
2195
|
async getShare(userId) {
|
|
2196
2196
|
return (await this._db).get(STORE, userId) ?? null;
|
|
2197
2197
|
}
|
|
2198
|
+
/**
|
|
2199
|
+
* Every share this browser holds. Needed because signing out clears the
|
|
2200
|
+
* remembered identity while deliberately leaving the share behind, so the
|
|
2201
|
+
* userId that keys it is no longer known and the share can only be found by
|
|
2202
|
+
* enumeration. See passkeyDeviceCandidate().
|
|
2203
|
+
*/
|
|
2204
|
+
async listShares() {
|
|
2205
|
+
return (await this._db).getAll(STORE);
|
|
2206
|
+
}
|
|
2198
2207
|
async putShare(share) {
|
|
2199
2208
|
await (await this._db).put(STORE, share);
|
|
2200
2209
|
}
|
|
@@ -3948,7 +3957,15 @@ async function createDecaneConnect(config) {
|
|
|
3948
3957
|
}
|
|
3949
3958
|
async function passkeyLoginCandidate() {
|
|
3950
3959
|
if (!persisted?.userId || !isPasskeySupported()) return null;
|
|
3951
|
-
|
|
3960
|
+
return usablePasskeyShare(await storage.getShare(persisted.userId));
|
|
3961
|
+
}
|
|
3962
|
+
async function passkeyDeviceCandidate() {
|
|
3963
|
+
if (!isPasskeySupported()) return null;
|
|
3964
|
+
if (persisted?.userId) return passkeyLoginCandidate();
|
|
3965
|
+
const candidates = (await storage.listShares()).map(usablePasskeyShare).filter(Boolean);
|
|
3966
|
+
return candidates.length === 1 ? candidates[0] : null;
|
|
3967
|
+
}
|
|
3968
|
+
function usablePasskeyShare(stored) {
|
|
3952
3969
|
if (!stored || stored.unlockMethod !== "passkey") return null;
|
|
3953
3970
|
if (!stored.credentialId || !stored.prfSalt) return null;
|
|
3954
3971
|
return stored;
|
|
@@ -4107,10 +4124,10 @@ async function createDecaneConnect(config) {
|
|
|
4107
4124
|
return handleAuthResult(result);
|
|
4108
4125
|
},
|
|
4109
4126
|
async canSignInWithPasskey() {
|
|
4110
|
-
return await
|
|
4127
|
+
return await passkeyDeviceCandidate() !== null;
|
|
4111
4128
|
},
|
|
4112
4129
|
async signInWithPasskey() {
|
|
4113
|
-
const candidate = await
|
|
4130
|
+
const candidate = await passkeyDeviceCandidate();
|
|
4114
4131
|
if (!candidate) throw new NewDeviceError();
|
|
4115
4132
|
return passkeyLogin(candidate);
|
|
4116
4133
|
},
|
|
@@ -6694,7 +6711,11 @@ function DecaneKit({ config, children }) {
|
|
|
6694
6711
|
"session-expired",
|
|
6695
6712
|
() => setSocialAuth((p) => ({ ...p, isUnlocked: false, sessionExpiresAt: null }))
|
|
6696
6713
|
);
|
|
6697
|
-
sdk.on("disconnected", () =>
|
|
6714
|
+
sdk.on("disconnected", () => {
|
|
6715
|
+
setSocialAuth(DEFAULT_SOCIAL);
|
|
6716
|
+
sdk.canSignInWithPasskey().then((can) => setSocialAuth((p) => ({ ...p, canUsePasskey: can }))).catch(() => {
|
|
6717
|
+
});
|
|
6718
|
+
});
|
|
6698
6719
|
sdk.on("wallet-creating", () => setSocialAuth((p) => ({ ...p, phase: "creating" })));
|
|
6699
6720
|
sdk.on("wallet-unlocking", () => setSocialAuth((p) => ({ ...p, phase: "unlocking" })));
|
|
6700
6721
|
sdk.on("connected", () => setSocialAuth((p) => ({ ...p, phase: null })));
|