@dexterai/connect 0.26.2 → 0.26.4
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/README.md
CHANGED
|
@@ -95,6 +95,38 @@ import { passkeyLogin } from '@dexterai/connect';
|
|
|
95
95
|
const { session, vault } = await passkeyLogin({ transport: 'auto' });
|
|
96
96
|
```
|
|
97
97
|
|
|
98
|
+
By default, a successful sign-in immediately makes its wallet active in the
|
|
99
|
+
browser wallet store, preserving existing behavior. A flow that must finish a
|
|
100
|
+
separate account-level approval can instead keep the result provisional:
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
import { passkeyLogin, setActiveHandle } from '@dexterai/connect';
|
|
104
|
+
|
|
105
|
+
const result = await passkeyLogin({
|
|
106
|
+
transport: 'auto',
|
|
107
|
+
walletStore: 'provisional',
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
// Only after your approval has bound this exact wallet to the account:
|
|
111
|
+
if (result.vault) {
|
|
112
|
+
setActiveHandle(
|
|
113
|
+
result.vault.userHandle,
|
|
114
|
+
result.vault.walletLabel ?? undefined,
|
|
115
|
+
result.vault.credentialId,
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
`provisional` suppresses both active-handle and wallet-roster writes on the
|
|
121
|
+
hosted Dexter origin and the calling origin. It does not weaken passkey
|
|
122
|
+
verification or persist a second identity. `recoverWallet`, `createWallet`, and
|
|
123
|
+
every terminal sign-in/create branch of `continueWithDexter` accept the same
|
|
124
|
+
option. A provisional creation still completes the passkey and Vault ceremony
|
|
125
|
+
and returns the full `CreateWalletResult`; explicitly call
|
|
126
|
+
`setActiveHandle(result.handle, result.label ?? undefined, result.credentialId)`
|
|
127
|
+
only after the separate approval succeeds. The only supported modes are exact
|
|
128
|
+
`commit` and `provisional`; omitted means `commit`.
|
|
129
|
+
|
|
98
130
|
## Verify the session on your server
|
|
99
131
|
|
|
100
132
|
```ts
|
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
// src/types.ts
|
|
2
|
+
function resolveWalletStoreMode(mode) {
|
|
3
|
+
if (mode === void 0 || mode === "commit") return "commit";
|
|
4
|
+
if (mode === "provisional") return "provisional";
|
|
5
|
+
throw new ConnectError(
|
|
6
|
+
"invalid_wallet_store_mode",
|
|
7
|
+
"walletStore must be exactly commit or provisional"
|
|
8
|
+
);
|
|
9
|
+
}
|
|
2
10
|
var ConnectError = class extends Error {
|
|
3
11
|
code;
|
|
4
12
|
constructor(code, message) {
|
|
@@ -196,9 +204,11 @@ function openCeremonyPopup(op, config = {}) {
|
|
|
196
204
|
const openerOrigin = window.location.origin;
|
|
197
205
|
const requestId = makeNonce();
|
|
198
206
|
const signRequest = snapshotSignRequest(op, config.signRequest);
|
|
207
|
+
const walletStore = resolveWalletStoreMode(config.walletStore);
|
|
199
208
|
const params = new URLSearchParams({ v: "1", op, requestId, origin: openerOrigin });
|
|
200
209
|
if (config.name) params.set("name", config.name);
|
|
201
210
|
if (config.preferImmediate) params.set("preferImmediate", "1");
|
|
211
|
+
if (walletStore === "provisional") params.set("walletStore", "provisional");
|
|
202
212
|
const url = `${host}?${params.toString()}`;
|
|
203
213
|
return new Promise((resolve, reject) => {
|
|
204
214
|
const popup = window.open(url, "dexter-connect", popupFeatures());
|
|
@@ -353,14 +363,18 @@ async function readErrorCode(res) {
|
|
|
353
363
|
// src/enroll.ts
|
|
354
364
|
var DEFAULT_WALLET_NAME = "Dexter Wallet";
|
|
355
365
|
async function createWallet(config = {}) {
|
|
366
|
+
const walletStore = resolveWalletStoreMode(config.walletStore);
|
|
356
367
|
const apiBase = resolveDexterApiBase(config.apiBase);
|
|
357
368
|
resolveDexterRpId(config.rpId);
|
|
358
369
|
if (shouldUsePopup(config.transport)) {
|
|
359
370
|
const result = await openCeremonyPopup("create", {
|
|
360
371
|
connectHost: config.connectHost,
|
|
361
|
-
name: config.name
|
|
372
|
+
name: config.name,
|
|
373
|
+
...walletStore === "provisional" ? { walletStore } : {}
|
|
362
374
|
});
|
|
363
|
-
|
|
375
|
+
if (walletStore === "commit") {
|
|
376
|
+
setActiveHandle(result.handle, result.label ?? config.name, result.credentialId);
|
|
377
|
+
}
|
|
364
378
|
return result;
|
|
365
379
|
}
|
|
366
380
|
if (typeof navigator === "undefined" || !navigator.credentials) {
|
|
@@ -391,7 +405,9 @@ async function createWallet(config = {}) {
|
|
|
391
405
|
config.spendPolicy,
|
|
392
406
|
config.name?.trim() || void 0
|
|
393
407
|
);
|
|
394
|
-
|
|
408
|
+
if (walletStore === "commit") {
|
|
409
|
+
setActiveHandle(enrolled.userHandle, name, enrolled.credentialId);
|
|
410
|
+
}
|
|
395
411
|
return {
|
|
396
412
|
handle: enrolled.userHandle,
|
|
397
413
|
credentialId: enrolled.credentialId,
|
|
@@ -570,11 +586,13 @@ var ANON_SIGN_BASE = "/api/passkey-anon/sign";
|
|
|
570
586
|
primeImmediateSupport();
|
|
571
587
|
async function passkeyLogin(config = {}, onPhase) {
|
|
572
588
|
const apiBase = resolveDexterApiBase(config.apiBase);
|
|
589
|
+
const walletStore = resolveWalletStoreMode(config.walletStore);
|
|
573
590
|
if (shouldUsePopup(config.transport)) {
|
|
574
591
|
const result2 = await openCeremonyPopup("signin", {
|
|
575
|
-
connectHost: config.connectHost
|
|
592
|
+
connectHost: config.connectHost,
|
|
593
|
+
...walletStore === "provisional" ? { walletStore } : {}
|
|
576
594
|
});
|
|
577
|
-
if (result2.vault) {
|
|
595
|
+
if (walletStore === "commit" && result2.vault) {
|
|
578
596
|
setActiveHandle(result2.vault.userHandle, result2.vault.walletLabel ?? void 0, result2.vault.credentialId);
|
|
579
597
|
}
|
|
580
598
|
return result2;
|
|
@@ -593,27 +611,31 @@ async function passkeyLogin(config = {}, onPhase) {
|
|
|
593
611
|
}
|
|
594
612
|
onPhase?.("verifying");
|
|
595
613
|
const result = await submitLogin(apiBase, response);
|
|
596
|
-
if (result.vault) {
|
|
614
|
+
if (walletStore === "commit" && result.vault) {
|
|
597
615
|
setActiveHandle(result.vault.userHandle, result.vault.walletLabel ?? void 0, result.vault.credentialId);
|
|
598
616
|
}
|
|
599
617
|
return result;
|
|
600
618
|
}
|
|
601
619
|
async function continueWithDexter(config = {}, onPhase) {
|
|
620
|
+
const walletStore = resolveWalletStoreMode(config.walletStore);
|
|
602
621
|
resolveDexterApiBase(config.apiBase);
|
|
603
622
|
if (shouldUsePopup(config.transport)) {
|
|
604
623
|
const result = await openCeremonyPopup("continue", {
|
|
605
624
|
connectHost: config.connectHost,
|
|
606
|
-
name: config.name
|
|
625
|
+
name: config.name,
|
|
626
|
+
...walletStore === "provisional" ? { walletStore } : {}
|
|
607
627
|
});
|
|
608
|
-
if (
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
628
|
+
if (walletStore === "commit") {
|
|
629
|
+
if (result.kind === "create") {
|
|
630
|
+
setActiveHandle(result.handle, result.label ?? config.name, result.credentialId);
|
|
631
|
+
} else if (result.kind === "signin" && result.vault) {
|
|
632
|
+
setActiveHandle(result.vault.userHandle, result.vault.walletLabel ?? void 0, result.vault.credentialId);
|
|
633
|
+
}
|
|
612
634
|
}
|
|
613
635
|
return result;
|
|
614
636
|
}
|
|
615
637
|
if (await immediateGetSupported()) {
|
|
616
|
-
const probe = await immediatePasskeyLogin(config, onPhase);
|
|
638
|
+
const probe = await immediatePasskeyLogin(config, onPhase, walletStore);
|
|
617
639
|
if (probe.outcome === "signin") return { kind: "signin", ...probe.result };
|
|
618
640
|
if (probe.outcome === "cancelled") return { kind: "cancelled" };
|
|
619
641
|
if (!config.spendPolicy) return { kind: "needs_create" };
|
|
@@ -626,7 +648,7 @@ async function continueWithDexter(config = {}, onPhase) {
|
|
|
626
648
|
}
|
|
627
649
|
return { kind: "needs_choice" };
|
|
628
650
|
}
|
|
629
|
-
async function immediatePasskeyLogin(config, onPhase) {
|
|
651
|
+
async function immediatePasskeyLogin(config, onPhase, walletStore = "commit") {
|
|
630
652
|
const apiBase = resolveDexterApiBase(config.apiBase);
|
|
631
653
|
onPhase?.("challenge");
|
|
632
654
|
const options = await fetchLoginChallenge(apiBase);
|
|
@@ -642,7 +664,7 @@ async function immediatePasskeyLogin(config, onPhase) {
|
|
|
642
664
|
}
|
|
643
665
|
onPhase?.("verifying");
|
|
644
666
|
const result = await submitLogin(apiBase, response);
|
|
645
|
-
if (result.vault) {
|
|
667
|
+
if (walletStore === "commit" && result.vault) {
|
|
646
668
|
setActiveHandle(
|
|
647
669
|
result.vault.userHandle,
|
|
648
670
|
result.vault.walletLabel ?? void 0,
|
|
@@ -873,24 +895,35 @@ var ANON_SIGN_BASE3 = "/api/passkey-anon/sign";
|
|
|
873
895
|
primeImmediateSupport();
|
|
874
896
|
async function recoverWallet(config = {}) {
|
|
875
897
|
let apiBase;
|
|
898
|
+
let walletStore;
|
|
876
899
|
try {
|
|
877
900
|
apiBase = resolveDexterApiBase(config.apiBase);
|
|
878
901
|
} catch (err) {
|
|
879
902
|
return netError("untrusted_api_base", err);
|
|
880
903
|
}
|
|
904
|
+
try {
|
|
905
|
+
walletStore = resolveWalletStoreMode(config.walletStore);
|
|
906
|
+
} catch (err) {
|
|
907
|
+
return {
|
|
908
|
+
ok: false,
|
|
909
|
+
reason: "error",
|
|
910
|
+
error: err instanceof ConnectError ? err : new ConnectError("invalid_wallet_store_mode")
|
|
911
|
+
};
|
|
912
|
+
}
|
|
881
913
|
if (shouldUsePopup(config.transport)) {
|
|
882
914
|
let outcome;
|
|
883
915
|
try {
|
|
884
916
|
outcome = await openCeremonyPopup("recover", {
|
|
885
917
|
connectHost: config.connectHost,
|
|
886
|
-
preferImmediate: config.preferImmediate
|
|
918
|
+
preferImmediate: config.preferImmediate,
|
|
919
|
+
...walletStore === "provisional" ? { walletStore } : {}
|
|
887
920
|
});
|
|
888
921
|
} catch (err) {
|
|
889
922
|
const ce = err instanceof ConnectError ? err : new ConnectError("popup_failed", err instanceof Error ? err.message : String(err));
|
|
890
923
|
if (ce.code === "popup_closed") return { ok: false, reason: "cancelled" };
|
|
891
924
|
return { ok: false, reason: "error", error: ce };
|
|
892
925
|
}
|
|
893
|
-
if (outcome.ok) {
|
|
926
|
+
if (walletStore === "commit" && outcome.ok) {
|
|
894
927
|
setActiveHandle(outcome.userHandle, outcome.vault.walletLabel ?? void 0, outcome.credentialId);
|
|
895
928
|
}
|
|
896
929
|
return outcome;
|
|
@@ -983,7 +1016,9 @@ async function recoverWallet(config = {}) {
|
|
|
983
1016
|
} catch (err) {
|
|
984
1017
|
return netError("vault_status_failed", err);
|
|
985
1018
|
}
|
|
986
|
-
|
|
1019
|
+
if (walletStore === "commit") {
|
|
1020
|
+
setActiveHandle(userHandle, vault.walletLabel ?? void 0, credentialId);
|
|
1021
|
+
}
|
|
987
1022
|
return { ok: true, userHandle, credentialId, vault };
|
|
988
1023
|
}
|
|
989
1024
|
function netError(code, err) {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as ConnectVault, R as RecoverWalletConfig, a as RecoverOutcome, b as CeremonyPhase, I as IdentityKind } from './signals-
|
|
2
|
-
export { A as ACTIVE_WALLET_STORAGE_KEY, c as CeremonyOperation, d as ConnectError, e as ContinueResult, f as CreateWalletConfig, g as CreateWalletResult, D as DexterConnectConfig, H as HostedSignRequestPayload, h as HostedSignResult, i as HostedSignVaultIdentity, j as IdentityInput, P as
|
|
1
|
+
import { C as ConnectVault, R as RecoverWalletConfig, a as RecoverOutcome, b as CeremonyPhase, I as IdentityKind } from './signals-dIHYwlPh.js';
|
|
2
|
+
export { A as ACTIVE_WALLET_STORAGE_KEY, c as CeremonyOperation, d as ConnectError, e as ContinueResult, f as CreateWalletConfig, g as CreateWalletResult, D as DexterConnectConfig, H as HostedSignRequestPayload, h as HostedSignResult, i as HostedSignVaultIdentity, j as IdentityInput, P as PasskeyLoginConfig, k as PasskeyLoginTokens, l as PasskeySignalSupport, m as RecoverVault, n as ResolvedIdentity, S as SESSION_TTL_30D, o as SignInResult, p as SpendPolicy, q as StoredWallet, W as WalletStoreMode, r as authoredPolicy, s as continueWithDexter, t as createWallet, u as ejectActiveWallet, v as forgetWallet, w as getActiveHandle, x as getCredentialId, y as listWallets, z as passkeyLogin, B as passkeySignalSupport, E as prunePasskey, F as renamePasskey, G as resolveIdentity, J as setActiveHandle, K as subscribeWallet, L as switchWallet, M as syncAcceptedPasskeys, N as usdToAtomic } from './signals-dIHYwlPh.js';
|
|
3
3
|
import { PasskeySignerWithPublicKey } from '@dexterai/vault/signers';
|
|
4
4
|
|
|
5
5
|
/** What `issueChallenge` returns to the SDK signer. */
|
package/dist/index.js
CHANGED
package/dist/react.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PasskeySignerWithPublicKey } from '@dexterai/vault/signers';
|
|
2
|
-
import { b as CeremonyPhase,
|
|
3
|
-
export {
|
|
2
|
+
import { b as CeremonyPhase, o as SignInResult, a as RecoverOutcome, e as ContinueResult, k as PasskeyLoginTokens, C as ConnectVault, d as ConnectError, q as StoredWallet, l as PasskeySignalSupport, n as ResolvedIdentity, g as CreateWalletResult } from './signals-dIHYwlPh.js';
|
|
3
|
+
export { m as RecoverVault } from './signals-dIHYwlPh.js';
|
|
4
4
|
import { ReactElement, ButtonHTMLAttributes, ReactNode } from 'react';
|
|
5
5
|
|
|
6
6
|
type ConnectStatus = 'idle' | 'pending' | 'done' | 'error';
|
package/dist/react.js
CHANGED
|
@@ -43,6 +43,16 @@ interface SignInResult {
|
|
|
43
43
|
* challenge → passkey (the OS prompt) → verifying → finalizing (create only).
|
|
44
44
|
*/
|
|
45
45
|
type CeremonyPhase = 'challenge' | 'passkey' | 'verifying' | 'finalizing';
|
|
46
|
+
/**
|
|
47
|
+
* Controls whether a successful sign-in/recovery immediately changes the
|
|
48
|
+
* browser's active-wallet store.
|
|
49
|
+
*
|
|
50
|
+
* `commit` preserves the historical SDK behavior. `provisional` returns the
|
|
51
|
+
* verified session/vault without writing either the active handle or wallet
|
|
52
|
+
* roster, so a caller can finish an account-level approval first and then
|
|
53
|
+
* explicitly commit the approved wallet with `setActiveHandle`.
|
|
54
|
+
*/
|
|
55
|
+
type WalletStoreMode = 'commit' | 'provisional';
|
|
46
56
|
/** Exact action the hosted Dexter consent window is being asked to perform. */
|
|
47
57
|
type CeremonyOperation = 'signin' | 'create' | 'continue' | 'recover' | 'sign';
|
|
48
58
|
/** Minimal vault identity transferred to Dexter's hosted signing window. */
|
|
@@ -107,8 +117,19 @@ interface RecoverWalletConfig extends DexterConnectConfig {
|
|
|
107
117
|
* discoverable passkey (no empty account-picker sheet). Falls back to the
|
|
108
118
|
* normal modal wherever unsupported. */
|
|
109
119
|
preferImmediate?: boolean;
|
|
120
|
+
/** See `PasskeyLoginConfig.walletStore`. */
|
|
121
|
+
walletStore?: WalletStoreMode;
|
|
110
122
|
onPhase?: (phase: CeremonyPhase) => void;
|
|
111
123
|
}
|
|
124
|
+
/** Configuration for `passkeyLogin`. */
|
|
125
|
+
interface PasskeyLoginConfig extends DexterConnectConfig {
|
|
126
|
+
/**
|
|
127
|
+
* Wallet-store behavior after a successful passkey ceremony. Defaults to
|
|
128
|
+
* `commit` for backward compatibility. Use `provisional` when the returned
|
|
129
|
+
* wallet must pass a separate approval before becoming active.
|
|
130
|
+
*/
|
|
131
|
+
walletStore?: WalletStoreMode;
|
|
132
|
+
}
|
|
112
133
|
interface DexterConnectConfig {
|
|
113
134
|
/**
|
|
114
135
|
* Compatibility-only Dexter API base. Omit it or pass exactly
|
|
@@ -152,6 +173,12 @@ declare function usdToAtomic(input: string): bigint | null;
|
|
|
152
173
|
declare function authoredPolicy(usdInput: string): SpendPolicy | null;
|
|
153
174
|
|
|
154
175
|
interface CreateWalletConfig extends DexterConnectConfig {
|
|
176
|
+
/**
|
|
177
|
+
* Wallet-store behavior after successful creation. Defaults to `commit` for
|
|
178
|
+
* backward compatibility. Use `provisional` when the created wallet must
|
|
179
|
+
* pass a separate approval before becoming active.
|
|
180
|
+
*/
|
|
181
|
+
walletStore?: WalletStoreMode;
|
|
155
182
|
/** Label for the passkey in the OS keychain AND the wallet roster. Set at
|
|
156
183
|
* creation — the only moment naming is guaranteed to stick. Default "Dexter Wallet". */
|
|
157
184
|
name?: string;
|
|
@@ -181,7 +208,9 @@ interface CreateWalletResult {
|
|
|
181
208
|
label: string | null;
|
|
182
209
|
}
|
|
183
210
|
/**
|
|
184
|
-
* Mint a brand-new Dexter wallet (passkey + vault)
|
|
211
|
+
* Mint a brand-new Dexter wallet (passkey + vault). Commit mode (the default)
|
|
212
|
+
* makes it active immediately; provisional mode returns it without changing
|
|
213
|
+
* the active-wallet store.
|
|
185
214
|
*
|
|
186
215
|
* One passkey approval. Throws ConnectError on any failed leg (the `code` is the
|
|
187
216
|
* server's error string, or webauthn_failed / no_credential for the ceremony).
|
|
@@ -201,7 +230,7 @@ declare function createWallet(config?: CreateWalletConfig): Promise<CreateWallet
|
|
|
201
230
|
* Relays to dexter-api's ANON router — a first-time third-party user has no
|
|
202
231
|
* Supabase session, so the Supabase-gated router would 401.
|
|
203
232
|
*/
|
|
204
|
-
declare function passkeyLogin(config?:
|
|
233
|
+
declare function passkeyLogin(config?: PasskeyLoginConfig, onPhase?: (phase: CeremonyPhase) => void): Promise<SignInResult>;
|
|
205
234
|
type ContinueResult = ({
|
|
206
235
|
kind: 'signin';
|
|
207
236
|
} & SignInResult) | ({
|
|
@@ -351,4 +380,4 @@ declare function syncAcceptedPasskeys(args: {
|
|
|
351
380
|
rpId?: string;
|
|
352
381
|
}): Promise<boolean>;
|
|
353
382
|
|
|
354
|
-
export { ACTIVE_WALLET_STORAGE_KEY as A,
|
|
383
|
+
export { ACTIVE_WALLET_STORAGE_KEY as A, passkeySignalSupport as B, type ConnectVault as C, type DexterConnectConfig as D, prunePasskey as E, renamePasskey as F, resolveIdentity as G, type HostedSignRequestPayload as H, type IdentityKind as I, setActiveHandle as J, subscribe as K, switchWallet as L, syncAcceptedPasskeys as M, usdToAtomic as N, type PasskeyLoginConfig as P, type RecoverWalletConfig as R, SESSION_TTL_30D as S, type WalletStoreMode as W, type RecoverOutcome as a, type CeremonyPhase as b, type CeremonyOperation as c, ConnectError as d, type ContinueResult as e, type CreateWalletConfig as f, type CreateWalletResult as g, type HostedSignResult as h, type HostedSignVaultIdentity as i, type IdentityInput as j, type PasskeyLoginTokens as k, type PasskeySignalSupport as l, type RecoverVault as m, type ResolvedIdentity as n, type SignInResult as o, type SpendPolicy as p, type StoredWallet as q, authoredPolicy as r, continueWithDexter as s, createWallet as t, ejectActiveWallet as u, forgetWallet as v, getActiveHandle as w, getCredentialId as x, listWallets as y, passkeyLogin as z };
|