@dexterai/connect 0.25.1 → 0.26.2
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 +24 -6
- package/dist/{chunk-VGERNAQ3.js → chunk-QP2WXXKP.js} +252 -38
- package/dist/{chunk-PW33ZOCP.js → chunk-TLCQSAE5.js} +7 -2
- package/dist/index.d.ts +31 -18
- package/dist/index.js +190 -31
- package/dist/react.d.ts +15 -9
- package/dist/react.js +160 -69
- package/dist/{signals-C4JSE_4X.d.ts → signals-BIh8JvP-.d.ts} +31 -2
- package/dist/worldid.js +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
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
|
|
3
|
-
import {
|
|
1
|
+
import { C as ConnectVault, R as RecoverWalletConfig, a as RecoverOutcome, b as CeremonyPhase, I as IdentityKind } from './signals-BIh8JvP-.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 PasskeyLoginTokens, k as PasskeySignalSupport, l as RecoverVault, m as ResolvedIdentity, S as SESSION_TTL_30D, n as SignInResult, o as SpendPolicy, p as StoredWallet, q as authoredPolicy, r as continueWithDexter, s as createWallet, t as ejectActiveWallet, u as forgetWallet, v as getActiveHandle, w as getCredentialId, x as listWallets, y as passkeyLogin, z as passkeySignalSupport, B as prunePasskey, E as renamePasskey, F as resolveIdentity, G as setActiveHandle, J as subscribeWallet, K as switchWallet, L as syncAcceptedPasskeys, M as usdToAtomic } from './signals-BIh8JvP-.js';
|
|
3
|
+
import { PasskeySignerWithPublicKey } from '@dexterai/vault/signers';
|
|
4
4
|
|
|
5
5
|
/** What `issueChallenge` returns to the SDK signer. */
|
|
6
6
|
interface AnonChallengeResult {
|
|
7
|
-
/** Server-issued
|
|
7
|
+
/** Server-issued canonical 200-byte passkey-authorization envelope. */
|
|
8
8
|
challenge: Uint8Array;
|
|
9
9
|
/** Credential id the server resolved from the userHandle (allowCredentials[0]). */
|
|
10
10
|
credentialId: Uint8Array;
|
|
@@ -15,6 +15,7 @@ interface AnonChallengeResult {
|
|
|
15
15
|
interface AnonServerPolicy {
|
|
16
16
|
issueChallenge(args: {
|
|
17
17
|
userHandle: Uint8Array;
|
|
18
|
+
operationMessage: Uint8Array;
|
|
18
19
|
operationHash: Uint8Array;
|
|
19
20
|
}): Promise<AnonChallengeResult>;
|
|
20
21
|
verify(args: {
|
|
@@ -28,10 +29,11 @@ interface AnonServerPolicy {
|
|
|
28
29
|
/**
|
|
29
30
|
* Build the anon ServerPolicy for a given dexter-api base.
|
|
30
31
|
*
|
|
31
|
-
* `issueChallenge` → POST /challenge
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
32
|
+
* `issueChallenge` → POST /challenge
|
|
33
|
+
* { userHandle, operationHash, operationMessage,
|
|
34
|
+
* operation: 'vault_operation' }.
|
|
35
|
+
* The server returns the canonical authorization envelope; the SDK validates
|
|
36
|
+
* its operation/program/vault binding before invoking WebAuthn.
|
|
35
37
|
* `verify` → POST /verify { credential, userHandle }. NOTE: the SDK hands us the
|
|
36
38
|
* COMPACT 64-byte signature; dexter-api's WebAuthn verifier wants DER, so we
|
|
37
39
|
* re-encode compact → DER here (compactSignatureToDer).
|
|
@@ -47,6 +49,12 @@ type AssertionLike = {
|
|
|
47
49
|
authenticatorData: Uint8Array;
|
|
48
50
|
}>;
|
|
49
51
|
};
|
|
52
|
+
interface CreatePasskeySignerOptions {
|
|
53
|
+
/** Compatibility-only hosted page; omitted or exactly Dexter's pinned URL. */
|
|
54
|
+
connectHost?: string;
|
|
55
|
+
/** Test-only injected assertion. Never used by the off-origin hosted path. */
|
|
56
|
+
__assertion?: AssertionLike;
|
|
57
|
+
}
|
|
50
58
|
/**
|
|
51
59
|
* Construct the guest signer from a connected `ConnectVault`.
|
|
52
60
|
*
|
|
@@ -54,12 +62,10 @@ type AssertionLike = {
|
|
|
54
62
|
* is base64url (server-minted). Both are decoded to the Uint8Arrays the SDK wants.
|
|
55
63
|
*
|
|
56
64
|
* @param vault the connected vault from useSignInWithDexter()
|
|
57
|
-
* @param apiBase
|
|
65
|
+
* @param apiBase compatibility-only; omitted or exactly https://api.dexter.cash
|
|
58
66
|
* @param opts.__assertion test-only injected assertion (skips real WebAuthn)
|
|
59
67
|
*/
|
|
60
|
-
declare function createPasskeySigner(vault: ConnectVault, apiBase?: string, opts?:
|
|
61
|
-
__assertion?: AssertionLike;
|
|
62
|
-
}): DexterApiBrowserPasskeySigner;
|
|
68
|
+
declare function createPasskeySigner(vault: ConnectVault, apiBase?: string, opts?: CreatePasskeySignerOptions): PasskeySignerWithPublicKey;
|
|
63
69
|
|
|
64
70
|
declare function recoverWallet(config?: RecoverWalletConfig): Promise<RecoverOutcome>;
|
|
65
71
|
|
|
@@ -168,6 +174,14 @@ declare class AgentSpendError extends Error {
|
|
|
168
174
|
}
|
|
169
175
|
/** Map an AgentSpendError.code to plain, user-facing copy. */
|
|
170
176
|
declare function describeAgentSpendError(code: string): string;
|
|
177
|
+
/** A caller may supply Connect's hosted signer on an arbitrary website. */
|
|
178
|
+
interface AgentSpendOperationSigner {
|
|
179
|
+
signOperation(operationMessage: Uint8Array): Promise<{
|
|
180
|
+
signature: Uint8Array;
|
|
181
|
+
clientDataJSON: Uint8Array;
|
|
182
|
+
authenticatorData: Uint8Array;
|
|
183
|
+
}>;
|
|
184
|
+
}
|
|
171
185
|
interface RevokeAgentSpendResult {
|
|
172
186
|
revoked: boolean;
|
|
173
187
|
}
|
|
@@ -179,12 +193,11 @@ interface RevokeAgentSpendResult {
|
|
|
179
193
|
*
|
|
180
194
|
* @param id WHO is active — must be the passkey-vault (Dexter Wallet).
|
|
181
195
|
* @param vaultPda The vault PDA, base58 string. Becomes the signed message.
|
|
182
|
-
* @param apiOrigin
|
|
183
|
-
* caller owns env; connect reads none.
|
|
196
|
+
* @param apiOrigin Compatibility-only: must be https://api.dexter.cash.
|
|
184
197
|
* @param credentialId The wallet's passkey credential id (base64url), to make
|
|
185
198
|
* the assertion a direct biometric, not an account picker.
|
|
186
199
|
*/
|
|
187
|
-
declare function revokeAgentSpend(id: AgentSpendIdentity, vaultPda: string, apiOrigin: string, credentialId?: string | null): Promise<RevokeAgentSpendResult>;
|
|
200
|
+
declare function revokeAgentSpend(id: AgentSpendIdentity, vaultPda: string, apiOrigin: string, credentialId?: string | null, signer?: AgentSpendOperationSigner): Promise<RevokeAgentSpendResult>;
|
|
188
201
|
interface EnableAgentSpendResult {
|
|
189
202
|
enabled: boolean;
|
|
190
203
|
}
|
|
@@ -197,9 +210,9 @@ interface EnableAgentSpendResult {
|
|
|
197
210
|
*
|
|
198
211
|
* @param id WHO is active — must be the passkey-vault (Dexter Wallet).
|
|
199
212
|
* @param vaultPda The vault PDA, base58 string.
|
|
200
|
-
* @param apiOrigin
|
|
213
|
+
* @param apiOrigin Compatibility-only: must be https://api.dexter.cash.
|
|
201
214
|
* @param credentialId The wallet's passkey credential id (base64url).
|
|
202
215
|
*/
|
|
203
|
-
declare function enableAgentSpend(id: AgentSpendIdentity, vaultPda: string, apiOrigin: string, credentialId?: string | null): Promise<EnableAgentSpendResult>;
|
|
216
|
+
declare function enableAgentSpend(id: AgentSpendIdentity, vaultPda: string, apiOrigin: string, credentialId?: string | null, signer?: AgentSpendOperationSigner): Promise<EnableAgentSpendResult>;
|
|
204
217
|
|
|
205
|
-
export { AgentSpendError, type AgentSpendIdentity, type AgentSpendStatus, type AgentSpendTab, type AnonChallengeResult, type AnonServerPolicy, type AutomaticAgentSpend, CeremonyPhase, ConnectVault, type EnableAgentSpendResult, IdentityKind, type RawAgentSpendSession, type RawAgentSpendStatus, RecoverOutcome, RecoverWalletConfig, type RevokeAgentSpendResult, assembleAgentSpendStatus, ceremonyPhaseLabel, createAnonServerPolicy, createPasskeySigner, describeAgentSpendError, enableAgentSpend, recoverWallet, revokeAgentSpend };
|
|
218
|
+
export { AgentSpendError, type AgentSpendIdentity, type AgentSpendStatus, type AgentSpendTab, type AnonChallengeResult, type AnonServerPolicy, type AutomaticAgentSpend, CeremonyPhase, ConnectVault, type CreatePasskeySignerOptions, type EnableAgentSpendResult, IdentityKind, type RawAgentSpendSession, type RawAgentSpendStatus, RecoverOutcome, RecoverWalletConfig, type RevokeAgentSpendResult, assembleAgentSpendStatus, ceremonyPhaseLabel, createAnonServerPolicy, createPasskeySigner, describeAgentSpendError, enableAgentSpend, recoverWallet, revokeAgentSpend };
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,9 @@ import {
|
|
|
3
3
|
ConnectError,
|
|
4
4
|
SESSION_TTL_30D,
|
|
5
5
|
authoredPolicy,
|
|
6
|
-
|
|
6
|
+
base64urlToBytes,
|
|
7
|
+
bytesEqual,
|
|
8
|
+
bytesToBase64,
|
|
7
9
|
bytesToBase64url,
|
|
8
10
|
ceremonyPhaseLabel,
|
|
9
11
|
continueWithDexter,
|
|
@@ -20,18 +22,21 @@ import {
|
|
|
20
22
|
prunePasskey,
|
|
21
23
|
recoverWallet,
|
|
22
24
|
renamePasskey,
|
|
25
|
+
resolveDexterApiBase,
|
|
26
|
+
resolveDexterRpId,
|
|
23
27
|
resolveIdentity,
|
|
24
28
|
setActiveHandle,
|
|
25
29
|
subscribe,
|
|
26
30
|
switchWallet,
|
|
27
31
|
syncAcceptedPasskeys,
|
|
28
32
|
usdToAtomic
|
|
29
|
-
} from "./chunk-
|
|
33
|
+
} from "./chunk-QP2WXXKP.js";
|
|
30
34
|
|
|
31
35
|
// src/agentSpend.ts
|
|
32
36
|
import { PublicKey } from "@solana/web3.js";
|
|
33
|
-
import {
|
|
34
|
-
import {
|
|
37
|
+
import { WebAuthnAssertion } from "@dexterai/vault/signers/browser";
|
|
38
|
+
import { validatePasskeyAuthorizationChallenge } from "@dexterai/vault";
|
|
39
|
+
import { enableAgentSpendMessage, revokeAgentSpendV2Message } from "@dexterai/vault/messages";
|
|
35
40
|
import { DEXTER_VAULT_PROGRAM_ID } from "@dexterai/vault/constants";
|
|
36
41
|
function shortCounterparty(a) {
|
|
37
42
|
return a.length > 12 ? `${a.slice(0, 4)}\u2026${a.slice(-4)}` : a;
|
|
@@ -89,6 +94,12 @@ function describeAgentSpendError(code) {
|
|
|
89
94
|
return "The server couldn't complete it \u2014 try again shortly.";
|
|
90
95
|
case "not_guest":
|
|
91
96
|
return "This control is only available on a Dexter Wallet.";
|
|
97
|
+
case "hosted_signer_required":
|
|
98
|
+
return "Open Dexter\u2019s secure approval window to confirm this change.";
|
|
99
|
+
case "challenge_malformed":
|
|
100
|
+
case "challenge_mismatch":
|
|
101
|
+
case "credential_mismatch":
|
|
102
|
+
return "Dexter could not verify exactly what you were asked to approve.";
|
|
92
103
|
default:
|
|
93
104
|
return code;
|
|
94
105
|
}
|
|
@@ -107,46 +118,173 @@ function assertDexterWallet(id) {
|
|
|
107
118
|
throw new AgentSpendError("not_guest", "agent-spend off/on switch is Dexter Wallet only");
|
|
108
119
|
}
|
|
109
120
|
}
|
|
110
|
-
function
|
|
111
|
-
|
|
121
|
+
function assertHostedSignerIfNeeded(signer) {
|
|
122
|
+
if (!signer && (typeof window === "undefined" || window.location.origin !== "https://dexter.cash")) {
|
|
123
|
+
throw new AgentSpendError(
|
|
124
|
+
"hosted_signer_required",
|
|
125
|
+
"agent-spend consent on a third-party website requires Dexter's hosted signer"
|
|
126
|
+
);
|
|
127
|
+
}
|
|
112
128
|
}
|
|
113
|
-
function
|
|
114
|
-
|
|
129
|
+
function signedPayload(result) {
|
|
130
|
+
if (result.signature.length !== 64 || result.clientDataJSON.length === 0 || result.authenticatorData.length < 37) {
|
|
131
|
+
throw new AgentSpendError("verification_failed", "signer returned malformed assertion bytes");
|
|
132
|
+
}
|
|
133
|
+
return {
|
|
134
|
+
clientDataJSON: bytesToBase64(result.clientDataJSON),
|
|
135
|
+
authenticatorData: bytesToBase64(result.authenticatorData),
|
|
136
|
+
signature: bytesToBase64(result.signature)
|
|
137
|
+
};
|
|
115
138
|
}
|
|
116
|
-
async function
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
139
|
+
async function sha256(bytes) {
|
|
140
|
+
if (!globalThis.crypto?.subtle) {
|
|
141
|
+
throw new AgentSpendError("webauthn_unavailable", "Web Crypto is unavailable");
|
|
142
|
+
}
|
|
143
|
+
return new Uint8Array(
|
|
144
|
+
await globalThis.crypto.subtle.digest("SHA-256", new Uint8Array(bytes))
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
async function assertCanonicalOperationInline(messageBytes, userHandle, expectedVault, apiBase, credentialId) {
|
|
148
|
+
if (typeof window === "undefined" || window.location.origin !== "https://dexter.cash") {
|
|
149
|
+
throw new AgentSpendError(
|
|
150
|
+
"hosted_signer_required",
|
|
151
|
+
"agent-spend consent on a third-party website requires Dexter's hosted signer"
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
const operationHash = await sha256(messageBytes);
|
|
155
|
+
const challengeRes = await fetch(`${apiBase}/api/passkey-anon/sign/challenge`, {
|
|
156
|
+
method: "POST",
|
|
157
|
+
headers: { "content-type": "application/json" },
|
|
158
|
+
body: JSON.stringify({
|
|
159
|
+
userHandle,
|
|
160
|
+
operationMessage: bytesToBase64url(messageBytes),
|
|
161
|
+
operationHash: bytesToBase64url(operationHash),
|
|
162
|
+
operation: "vault_operation"
|
|
163
|
+
})
|
|
124
164
|
});
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
165
|
+
if (!challengeRes.ok) throw await agentSpendError(challengeRes);
|
|
166
|
+
const data = await challengeRes.json();
|
|
167
|
+
const options = data.options;
|
|
168
|
+
const serverCredential = options?.allowCredentials?.[0];
|
|
169
|
+
if (!options?.challenge || !serverCredential?.id) {
|
|
170
|
+
throw new AgentSpendError("challenge_malformed", "Dexter returned an incomplete challenge");
|
|
171
|
+
}
|
|
172
|
+
const rpId = resolveDexterRpId(options.rpId);
|
|
173
|
+
if (credentialId && credentialId !== serverCredential.id) {
|
|
174
|
+
throw new AgentSpendError("credential_mismatch", "Dexter returned a different credential");
|
|
175
|
+
}
|
|
176
|
+
const challenge = base64urlToBytes(options.challenge);
|
|
177
|
+
try {
|
|
178
|
+
validatePasskeyAuthorizationChallenge({
|
|
179
|
+
challenge,
|
|
180
|
+
operationHash,
|
|
181
|
+
expectedVault
|
|
182
|
+
});
|
|
183
|
+
} catch {
|
|
184
|
+
throw new AgentSpendError("challenge_mismatch", "Dexter returned an unbound challenge");
|
|
185
|
+
}
|
|
186
|
+
const assertion = await new WebAuthnAssertion({
|
|
187
|
+
credentialId: base64urlToBytes(serverCredential.id),
|
|
188
|
+
rpId,
|
|
189
|
+
allowCredentials: [{
|
|
190
|
+
id: base64urlToBytes(serverCredential.id),
|
|
191
|
+
transports: serverCredential.transports
|
|
192
|
+
}]
|
|
193
|
+
}).assertOver(challenge);
|
|
194
|
+
const credential = {
|
|
195
|
+
id: serverCredential.id,
|
|
196
|
+
rawId: serverCredential.id,
|
|
197
|
+
type: "public-key",
|
|
198
|
+
response: {
|
|
199
|
+
clientDataJSON: bytesToBase64url(assertion.clientDataJSON),
|
|
200
|
+
authenticatorData: bytesToBase64url(assertion.authenticatorData),
|
|
201
|
+
signature: bytesToBase64url(assertion.signatureDer),
|
|
202
|
+
userHandle: null
|
|
203
|
+
},
|
|
204
|
+
clientExtensionResults: {},
|
|
205
|
+
authenticatorAttachment: null
|
|
129
206
|
};
|
|
207
|
+
const verifyRes = await fetch(`${apiBase}/api/passkey-anon/sign/verify`, {
|
|
208
|
+
method: "POST",
|
|
209
|
+
headers: { "content-type": "application/json" },
|
|
210
|
+
body: JSON.stringify({ credential, userHandle })
|
|
211
|
+
});
|
|
212
|
+
if (!verifyRes.ok) throw await agentSpendError(verifyRes);
|
|
213
|
+
const verified = await verifyRes.json();
|
|
214
|
+
if (verified.verified !== true) {
|
|
215
|
+
throw new AgentSpendError("verification_failed", "Dexter did not verify the assertion");
|
|
216
|
+
}
|
|
217
|
+
return signedPayload(assertion);
|
|
130
218
|
}
|
|
131
|
-
async function
|
|
219
|
+
async function authorizeAgentSpendOperation(messageBytes, id, expectedVault, apiBase, credentialId, signer) {
|
|
220
|
+
if (!id.userHandle) throw new AgentSpendError("missing_fields", "wallet handle is required");
|
|
221
|
+
if (signer) return signedPayload(await signer.signOperation(new Uint8Array(messageBytes)));
|
|
222
|
+
return assertCanonicalOperationInline(
|
|
223
|
+
new Uint8Array(messageBytes),
|
|
224
|
+
id.userHandle,
|
|
225
|
+
expectedVault,
|
|
226
|
+
apiBase,
|
|
227
|
+
credentialId
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
async function revokeAgentSpend(id, vaultPda, apiOrigin, credentialId, signer) {
|
|
132
231
|
assertDexterWallet(id);
|
|
133
|
-
const origin =
|
|
134
|
-
|
|
232
|
+
const origin = resolveDexterApiBase(apiOrigin);
|
|
233
|
+
assertHostedSignerIfNeeded(signer);
|
|
234
|
+
if (!id.userHandle) throw new AgentSpendError("missing_fields", "wallet handle is required");
|
|
235
|
+
const challengeRes = await fetch(
|
|
236
|
+
`${origin}/api/passkey-vault-anon/revoke-agent-spend/challenge`,
|
|
237
|
+
{
|
|
238
|
+
method: "POST",
|
|
239
|
+
headers: { "content-type": "application/json" },
|
|
240
|
+
body: JSON.stringify({ userHandle: id.userHandle })
|
|
241
|
+
}
|
|
242
|
+
);
|
|
243
|
+
if (!challengeRes.ok) throw await agentSpendError(challengeRes);
|
|
244
|
+
const challenge = await challengeRes.json();
|
|
245
|
+
if (typeof challenge.nonce !== "string" || !/^(0|[1-9][0-9]*)$/.test(challenge.nonce) || typeof challenge.expiry !== "number" || !Number.isSafeInteger(challenge.expiry) || typeof challenge.operationMessage !== "string") {
|
|
246
|
+
throw new AgentSpendError("challenge_malformed", "Dexter returned an incomplete revoke intent");
|
|
247
|
+
}
|
|
248
|
+
const expectedVault = new PublicKey(vaultPda);
|
|
249
|
+
const message = revokeAgentSpendV2Message({
|
|
135
250
|
programId: DEXTER_VAULT_PROGRAM_ID,
|
|
136
|
-
vaultPda:
|
|
251
|
+
vaultPda: expectedVault,
|
|
252
|
+
nonce: BigInt(challenge.nonce),
|
|
253
|
+
expiry: BigInt(challenge.expiry)
|
|
137
254
|
});
|
|
138
|
-
|
|
255
|
+
let serverMessage;
|
|
256
|
+
try {
|
|
257
|
+
serverMessage = base64urlToBytes(challenge.operationMessage);
|
|
258
|
+
} catch {
|
|
259
|
+
throw new AgentSpendError("challenge_malformed", "Dexter returned invalid revoke bytes");
|
|
260
|
+
}
|
|
261
|
+
if (!bytesEqual(serverMessage, message)) {
|
|
262
|
+
throw new AgentSpendError("challenge_mismatch", "Dexter returned a different revoke operation");
|
|
263
|
+
}
|
|
264
|
+
const signed = await authorizeAgentSpendOperation(
|
|
265
|
+
serverMessage,
|
|
266
|
+
id,
|
|
267
|
+
expectedVault,
|
|
268
|
+
origin,
|
|
269
|
+
credentialId,
|
|
270
|
+
signer
|
|
271
|
+
);
|
|
139
272
|
const res = await fetch(`${origin}/api/passkey-vault-anon/revoke-agent-spend`, {
|
|
140
273
|
method: "POST",
|
|
141
274
|
headers: { "content-type": "application/json" },
|
|
142
|
-
body: JSON.stringify({
|
|
275
|
+
body: JSON.stringify({
|
|
276
|
+
userHandle: id.userHandle,
|
|
277
|
+
nonce: challenge.nonce,
|
|
278
|
+
signedPasskeyPayload: signed
|
|
279
|
+
})
|
|
143
280
|
});
|
|
144
281
|
if (!res.ok) throw await agentSpendError(res);
|
|
145
282
|
return await res.json();
|
|
146
283
|
}
|
|
147
|
-
async function enableAgentSpend(id, vaultPda, apiOrigin, credentialId) {
|
|
284
|
+
async function enableAgentSpend(id, vaultPda, apiOrigin, credentialId, signer) {
|
|
148
285
|
assertDexterWallet(id);
|
|
149
|
-
const origin =
|
|
286
|
+
const origin = resolveDexterApiBase(apiOrigin);
|
|
287
|
+
assertHostedSignerIfNeeded(signer);
|
|
150
288
|
const challengeRes = await fetch(
|
|
151
289
|
`${origin}/api/passkey-vault-anon/enable-agent-spend/challenge`,
|
|
152
290
|
{
|
|
@@ -156,14 +294,35 @@ async function enableAgentSpend(id, vaultPda, apiOrigin, credentialId) {
|
|
|
156
294
|
}
|
|
157
295
|
);
|
|
158
296
|
if (!challengeRes.ok) throw await agentSpendError(challengeRes);
|
|
159
|
-
const
|
|
297
|
+
const challenge = await challengeRes.json();
|
|
298
|
+
if (typeof challenge.nonce !== "string" || typeof challenge.expiry !== "number" || typeof challenge.operationMessage !== "string") {
|
|
299
|
+
throw new AgentSpendError("challenge_malformed", "Dexter returned an incomplete enable intent");
|
|
300
|
+
}
|
|
301
|
+
const { nonce, expiry } = challenge;
|
|
302
|
+
const expectedVault = new PublicKey(vaultPda);
|
|
160
303
|
const message = enableAgentSpendMessage({
|
|
161
304
|
programId: DEXTER_VAULT_PROGRAM_ID,
|
|
162
|
-
vaultPda:
|
|
305
|
+
vaultPda: expectedVault,
|
|
163
306
|
nonce: BigInt(nonce),
|
|
164
307
|
expiry: BigInt(expiry)
|
|
165
308
|
});
|
|
166
|
-
|
|
309
|
+
let serverMessage;
|
|
310
|
+
try {
|
|
311
|
+
serverMessage = base64urlToBytes(challenge.operationMessage);
|
|
312
|
+
} catch {
|
|
313
|
+
throw new AgentSpendError("challenge_malformed", "Dexter returned invalid enable bytes");
|
|
314
|
+
}
|
|
315
|
+
if (!bytesEqual(serverMessage, message)) {
|
|
316
|
+
throw new AgentSpendError("challenge_mismatch", "Dexter returned a different enable operation");
|
|
317
|
+
}
|
|
318
|
+
const signed = await authorizeAgentSpendOperation(
|
|
319
|
+
serverMessage,
|
|
320
|
+
id,
|
|
321
|
+
expectedVault,
|
|
322
|
+
origin,
|
|
323
|
+
credentialId,
|
|
324
|
+
signer
|
|
325
|
+
);
|
|
167
326
|
const verifyRes = await fetch(
|
|
168
327
|
`${origin}/api/passkey-vault-anon/enable-agent-spend/verify`,
|
|
169
328
|
{
|
package/dist/react.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { b as CeremonyPhase,
|
|
3
|
-
export {
|
|
1
|
+
import { PasskeySignerWithPublicKey } from '@dexterai/vault/signers';
|
|
2
|
+
import { b as CeremonyPhase, n as SignInResult, a as RecoverOutcome, e as ContinueResult, P as PasskeyLoginTokens, C as ConnectVault, d as ConnectError, p as StoredWallet, k as PasskeySignalSupport, m as ResolvedIdentity, g as CreateWalletResult } from './signals-BIh8JvP-.js';
|
|
3
|
+
export { l as RecoverVault } from './signals-BIh8JvP-.js';
|
|
4
4
|
import { ReactElement, ButtonHTMLAttributes, ReactNode } from 'react';
|
|
5
5
|
|
|
6
6
|
type ConnectStatus = 'idle' | 'pending' | 'done' | 'error';
|
|
7
7
|
interface UseSignInWithDexterConfig {
|
|
8
|
-
/**
|
|
8
|
+
/** Compatibility-only: omitted or exactly https://api.dexter.cash. */
|
|
9
9
|
apiBase?: string;
|
|
10
10
|
/** RPC for the connected-chip balance read. Default: Dexter's Helius proxy. */
|
|
11
11
|
rpcUrl?: string;
|
|
@@ -50,7 +50,7 @@ interface UseSignInWithDexter {
|
|
|
50
50
|
credentialId: string | null;
|
|
51
51
|
/** Guest passkey signer for authorizing spends / opening x402 tabs. null until
|
|
52
52
|
* a vault is connected. Drive it via `passkeySigner.signOperation(op)`. */
|
|
53
|
-
passkeySigner:
|
|
53
|
+
passkeySigner: PasskeySignerWithPublicKey | null;
|
|
54
54
|
/** USD available. number once read; null = unknown → chip shows wallet only. */
|
|
55
55
|
usdcBalance: number | null;
|
|
56
56
|
refreshBalance: () => Promise<void>;
|
|
@@ -230,6 +230,8 @@ interface AllowanceChipsProps {
|
|
|
230
230
|
onChange: (usd: string | null) => void;
|
|
231
231
|
/** Extra className composed after the brand classes. */
|
|
232
232
|
className?: string;
|
|
233
|
+
/** Disable every choice and the custom amount field. */
|
|
234
|
+
disabled?: boolean;
|
|
233
235
|
}
|
|
234
236
|
/** The consent-at-birth allowance chips. */
|
|
235
237
|
declare function AllowanceChips(props: AllowanceChipsProps): ReactElement;
|
|
@@ -239,7 +241,7 @@ interface CreateWalletPanelProps {
|
|
|
239
241
|
onCreated?: (result: CreateWalletResult) => void;
|
|
240
242
|
/** Fired with the typed error if the ceremony fails. */
|
|
241
243
|
onError?: (error: ConnectError) => void;
|
|
242
|
-
/**
|
|
244
|
+
/** Compatibility-only: omitted or exactly https://api.dexter.cash. */
|
|
243
245
|
apiBase?: string;
|
|
244
246
|
/** Where the WebAuthn ceremony runs. Default 'auto' (createWallet's default). */
|
|
245
247
|
transport?: 'auto' | 'popup' | 'inline';
|
|
@@ -251,13 +253,15 @@ interface CreateWalletPanelProps {
|
|
|
251
253
|
/** The turnkey consent-at-birth create panel. */
|
|
252
254
|
declare function CreateWalletPanel(props: CreateWalletPanelProps): ReactElement;
|
|
253
255
|
|
|
254
|
-
type InstallApp = 'cursor' | 'vscode' | 'hermes' | 'claude-code';
|
|
256
|
+
type InstallApp = 'claude' | 'chatgpt' | 'cursor' | 'vscode' | 'hermes' | 'claude-code';
|
|
255
257
|
interface AppInstallButtonsProps {
|
|
256
258
|
/** MCP endpoint to install. Default: OpenDexter. */
|
|
257
259
|
mcpUrl?: string;
|
|
260
|
+
/** Human-facing connector name. Default: OpenDexter. */
|
|
261
|
+
displayName?: string;
|
|
258
262
|
/** Server name written into the app's config. Default: opendexter. */
|
|
259
263
|
serverName?: string;
|
|
260
|
-
/** Which app buttons to render, in order. Default:
|
|
264
|
+
/** Which app buttons to render, in order. Default: the four desktop clients. */
|
|
261
265
|
apps?: InstallApp[];
|
|
262
266
|
/** Stack full-width instead of a wrapping row. */
|
|
263
267
|
block?: boolean;
|
|
@@ -265,6 +269,8 @@ interface AppInstallButtonsProps {
|
|
|
265
269
|
/** Observability hook: fired on every action a user takes. */
|
|
266
270
|
onAction?: (app: InstallApp, action: 'deeplink' | 'copied') => void;
|
|
267
271
|
}
|
|
272
|
+
declare function claudeWebConnectorUrl(displayName: string, mcpUrl: string): string;
|
|
273
|
+
declare function chatgptPluginsUrl(): string;
|
|
268
274
|
declare function cursorInstallUrl(name: string, mcpUrl: string): string;
|
|
269
275
|
declare function vscodeInstallUrl(name: string, mcpUrl: string): string;
|
|
270
276
|
declare function hermesInstallCommand(name: string, mcpUrl: string): string;
|
|
@@ -272,4 +278,4 @@ declare function hermesOpenUrl(name: string): string;
|
|
|
272
278
|
declare function claudeCodeInstallCommand(name: string, mcpUrl: string): string;
|
|
273
279
|
declare function AppInstallButtons(props: AppInstallButtonsProps): ReactElement;
|
|
274
280
|
|
|
275
|
-
export { AllowanceChips, type AllowanceChipsProps, AppInstallButtons, type AppInstallButtonsProps, type ConnectStatus, CreateWalletPanel, type CreateWalletPanelProps, DexterButton, type DexterButtonProps, DexterMark, DexterWalletChip, type DexterWalletChipProps, DexterWalletMenu, type DexterWalletMenuProps, type InstallApp, RecoverOutcome, SignInWithDexter, type SignInWithDexterProps, type UseDexterWallet, type UseIdentityConfig, type UseSignInWithDexter, type UseSignInWithDexterConfig, claudeCodeInstallCommand, cursorInstallUrl, hermesInstallCommand, hermesOpenUrl, useDexterWallet, useIdentity, useSignInWithDexter, vscodeInstallUrl };
|
|
281
|
+
export { AllowanceChips, type AllowanceChipsProps, AppInstallButtons, type AppInstallButtonsProps, type ConnectStatus, CreateWalletPanel, type CreateWalletPanelProps, DexterButton, type DexterButtonProps, DexterMark, DexterWalletChip, type DexterWalletChipProps, DexterWalletMenu, type DexterWalletMenuProps, type InstallApp, RecoverOutcome, SignInWithDexter, type SignInWithDexterProps, type UseDexterWallet, type UseIdentityConfig, type UseSignInWithDexter, type UseSignInWithDexterConfig, chatgptPluginsUrl, claudeCodeInstallCommand, claudeWebConnectorUrl, cursorInstallUrl, hermesInstallCommand, hermesOpenUrl, useDexterWallet, useIdentity, useSignInWithDexter, vscodeInstallUrl };
|