@dexterai/connect 0.31.3 → 0.34.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/README.md +64 -0
- package/dist/{enroll-Cqou8Pbi.d.ts → accountIdentity-DQ_C-WAi.d.ts} +57 -3
- package/dist/{chunk-GIEQOIYI.js → chunk-3SBEND6T.js} +1 -1
- package/dist/{chunk-IPEINLMT.js → chunk-Q7HTBUJF.js} +294 -15
- package/dist/{chunk-UQE76AJW.js → chunk-SLI2QCWN.js} +1 -1
- package/dist/{connectionContract-BgecDiDk.d.ts → connectionContract-BA03zq2D.d.ts} +1 -1
- package/dist/hosted.d.ts +16 -5
- package/dist/hosted.js +21 -3
- package/dist/index.d.ts +166 -5
- package/dist/index.js +372 -3
- package/dist/react.d.ts +17 -8
- package/dist/react.js +319 -38
- package/dist/server.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -9,13 +9,16 @@ import {
|
|
|
9
9
|
prunePasskey,
|
|
10
10
|
renamePasskey,
|
|
11
11
|
syncAcceptedPasskeys
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-SLI2QCWN.js";
|
|
13
13
|
import {
|
|
14
14
|
recoverMissingVaultForAccount,
|
|
15
15
|
recoverWallet
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-3SBEND6T.js";
|
|
17
17
|
import {
|
|
18
|
+
ACCOUNT_IDENTITY_API_PATH,
|
|
18
19
|
ConnectError,
|
|
20
|
+
DEXTER_API_BASE,
|
|
21
|
+
DEXTER_RP_ID,
|
|
19
22
|
SESSION_TTL_30D,
|
|
20
23
|
WALLET_ACCOUNT_BINDING_PATH,
|
|
21
24
|
WALLET_PROOF_SESSION_STORAGE_PREFIX,
|
|
@@ -25,16 +28,20 @@ import {
|
|
|
25
28
|
createWallet,
|
|
26
29
|
createWalletAccountBindingClient,
|
|
27
30
|
createWalletProofSessionStore,
|
|
31
|
+
enrollAccountAccess,
|
|
32
|
+
enrollAccountIdentity,
|
|
28
33
|
fetchWithWalletIdentity,
|
|
29
34
|
openCeremonyPopup,
|
|
30
35
|
readErrorCode,
|
|
31
36
|
resolveDexterApiBase,
|
|
32
37
|
resolveDexterRpId,
|
|
33
38
|
shouldUsePopup,
|
|
39
|
+
signInAccountAccess,
|
|
40
|
+
signInAccountIdentity,
|
|
34
41
|
usdToAtomic,
|
|
35
42
|
walletBindingCandidate,
|
|
36
43
|
walletProofSessionStore
|
|
37
|
-
} from "./chunk-
|
|
44
|
+
} from "./chunk-Q7HTBUJF.js";
|
|
38
45
|
import {
|
|
39
46
|
base64ToBytes,
|
|
40
47
|
base64urlToBytes,
|
|
@@ -209,6 +216,353 @@ async function validateHostedSignResult(result, operationMessage, expectedVault)
|
|
|
209
216
|
};
|
|
210
217
|
}
|
|
211
218
|
|
|
219
|
+
// src/accountOperations.ts
|
|
220
|
+
import { browserSupportsWebAuthn, startAuthentication } from "@simplewebauthn/browser";
|
|
221
|
+
var ACCOUNT_API_PATH = "/api/account/v1";
|
|
222
|
+
var MAX_STEPS = 8;
|
|
223
|
+
var NOT_READY_RETRIES = 2;
|
|
224
|
+
var AccountOperationUnsettledError = class extends ConnectError {
|
|
225
|
+
operationId;
|
|
226
|
+
flow;
|
|
227
|
+
step;
|
|
228
|
+
constructor(operationId, flow, step) {
|
|
229
|
+
super("account_operation_unsettled");
|
|
230
|
+
this.name = "AccountOperationUnsettledError";
|
|
231
|
+
this.operationId = operationId;
|
|
232
|
+
this.flow = flow;
|
|
233
|
+
this.step = step;
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
function record(value) {
|
|
237
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
238
|
+
}
|
|
239
|
+
var text = (value, max = 200) => typeof value === "string" && value.length > 0 && value.length <= max;
|
|
240
|
+
var address = (value) => typeof value === "string" && /^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(value);
|
|
241
|
+
var units = (value) => typeof value === "string" && /^(0|[1-9][0-9]{0,19})$/.test(value);
|
|
242
|
+
function malformed() {
|
|
243
|
+
throw new ConnectError("account_response_malformed");
|
|
244
|
+
}
|
|
245
|
+
function bearer(identity) {
|
|
246
|
+
const session = identity?.session;
|
|
247
|
+
if (!session || session.tokenType !== "Bearer" || !text(session.accessToken, 8192)) {
|
|
248
|
+
throw new ConnectError("account_session_required");
|
|
249
|
+
}
|
|
250
|
+
if (session.expiresAt * 1e3 <= Date.now()) throw new ConnectError("account_session_expired");
|
|
251
|
+
return session.accessToken;
|
|
252
|
+
}
|
|
253
|
+
function cancelled(signal) {
|
|
254
|
+
if (signal?.aborted) throw new ConnectError("user_cancelled");
|
|
255
|
+
}
|
|
256
|
+
async function call(identity, method, path, body, uncertain, signal) {
|
|
257
|
+
const token = bearer(identity);
|
|
258
|
+
let response;
|
|
259
|
+
try {
|
|
260
|
+
response = await fetch(`${DEXTER_API_BASE}${ACCOUNT_API_PATH}${path}`, {
|
|
261
|
+
method,
|
|
262
|
+
headers: {
|
|
263
|
+
Accept: "application/json",
|
|
264
|
+
Authorization: `Bearer ${token}`,
|
|
265
|
+
...method === "POST" ? { "Content-Type": "application/json" } : {}
|
|
266
|
+
},
|
|
267
|
+
...method === "POST" ? { body: JSON.stringify(body) } : {},
|
|
268
|
+
credentials: "omit",
|
|
269
|
+
cache: "no-store",
|
|
270
|
+
redirect: "error",
|
|
271
|
+
signal
|
|
272
|
+
});
|
|
273
|
+
} catch {
|
|
274
|
+
cancelled(signal);
|
|
275
|
+
throw new ConnectError(uncertain ? "account_operation_uncertain" : "account_unavailable");
|
|
276
|
+
}
|
|
277
|
+
let parsed;
|
|
278
|
+
try {
|
|
279
|
+
parsed = await response.json();
|
|
280
|
+
} catch {
|
|
281
|
+
throw new ConnectError(response.ok ? uncertain ? "account_operation_uncertain" : "account_response_malformed" : `http_${response.status}`);
|
|
282
|
+
}
|
|
283
|
+
if (!response.ok) {
|
|
284
|
+
const code = record(parsed) && text(parsed.error, 80) ? parsed.error : `http_${response.status}`;
|
|
285
|
+
const message = record(parsed) && text(parsed.message, 400) ? parsed.message : void 0;
|
|
286
|
+
throw new ConnectError(code, message);
|
|
287
|
+
}
|
|
288
|
+
return parsed;
|
|
289
|
+
}
|
|
290
|
+
function accountFrom(value) {
|
|
291
|
+
if (!record(value) || !("account" in value)) malformed();
|
|
292
|
+
const account = value.account;
|
|
293
|
+
if (account === null) return null;
|
|
294
|
+
if (!record(account) || !address(account.principal) || account.wallet !== null && account.wallet !== void 0 && !address(account.wallet) || account.status !== "ready" && account.status !== "held" && account.status !== "setting-up" || account.nextStep !== null && account.nextStep !== void 0 && !text(account.nextStep, 80)) malformed();
|
|
295
|
+
return Object.freeze({
|
|
296
|
+
principal: account.principal,
|
|
297
|
+
wallet: account.wallet ?? null,
|
|
298
|
+
status: account.status,
|
|
299
|
+
nextStep: account.nextStep ?? null
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
function detailsFrom(value) {
|
|
303
|
+
if (value === void 0 || value === null) return null;
|
|
304
|
+
const absent = (field) => field === void 0 || field === null;
|
|
305
|
+
if (!record(value) || !(value.mint === "SOL" || address(value.mint)) || !(absent(value.amount) || units(value.amount)) || !(absent(value.to) || address(value.to)) || typeof value.decimals !== "number" || !Number.isInteger(value.decimals) || value.decimals < 0 || value.decimals > 18 || value.symbol !== null && value.symbol !== void 0 && !text(value.symbol, 20)) malformed();
|
|
306
|
+
return Object.freeze({
|
|
307
|
+
mint: value.mint,
|
|
308
|
+
symbol: value.symbol ?? null,
|
|
309
|
+
decimals: value.decimals,
|
|
310
|
+
amount: value.amount ?? null,
|
|
311
|
+
to: value.to ?? null
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
function preparedFrom(value, identity) {
|
|
315
|
+
if (record(value) && value.status === "complete" && (value.next === null || value.next === void 0)) return null;
|
|
316
|
+
if (!record(value) || !text(value.operationId) || !text(value.step, 80) || typeof value.summary !== "string" || value.summary.length > 300 || !record(value.publicKey)) malformed();
|
|
317
|
+
const options = value.publicKey;
|
|
318
|
+
let challenge;
|
|
319
|
+
try {
|
|
320
|
+
challenge = base64urlToBytes(String(options.challenge));
|
|
321
|
+
} catch {
|
|
322
|
+
malformed();
|
|
323
|
+
}
|
|
324
|
+
const allowed = options.allowCredentials;
|
|
325
|
+
if (challenge.length !== 32 || bytesToBase64url(challenge) !== options.challenge || options.rpId !== DEXTER_RP_ID || options.userVerification !== "required" || !Array.isArray(allowed) || allowed.length !== 1 || !record(allowed[0]) || allowed[0].type !== "public-key" || allowed[0].id !== identity.credential.credentialId) {
|
|
326
|
+
throw new ConnectError("account_challenge_refused");
|
|
327
|
+
}
|
|
328
|
+
const timeout = typeof options.timeout === "number" && options.timeout >= 1e4 && options.timeout <= 6e5 ? options.timeout : 12e4;
|
|
329
|
+
const remaining = value.stepsRemaining;
|
|
330
|
+
return Object.freeze({
|
|
331
|
+
operationId: value.operationId,
|
|
332
|
+
step: value.step,
|
|
333
|
+
summary: value.summary,
|
|
334
|
+
statement: text(value.statement, 1e3) ? value.statement : null,
|
|
335
|
+
stepsRemaining: typeof remaining === "number" && Number.isInteger(remaining) && remaining >= 0 ? remaining : null,
|
|
336
|
+
details: detailsFrom(value.details),
|
|
337
|
+
publicKey: Object.freeze({
|
|
338
|
+
challenge: options.challenge,
|
|
339
|
+
rpId: DEXTER_RP_ID,
|
|
340
|
+
allowCredentials: [{ type: "public-key", id: identity.credential.credentialId }],
|
|
341
|
+
userVerification: "required",
|
|
342
|
+
timeout
|
|
343
|
+
})
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
function assertApprovalContext() {
|
|
347
|
+
if (typeof window === "undefined" || window.top !== window.self || window.location.origin !== "https://dexter.cash") {
|
|
348
|
+
throw new ConnectError("hosted_ceremony_origin_required");
|
|
349
|
+
}
|
|
350
|
+
if (!browserSupportsWebAuthn()) throw new ConnectError("webauthn_unsupported");
|
|
351
|
+
}
|
|
352
|
+
var approvalInProgress = false;
|
|
353
|
+
async function prepare(config, flow, body) {
|
|
354
|
+
for (let attempt = 0; ; attempt += 1) {
|
|
355
|
+
try {
|
|
356
|
+
return preparedFrom(
|
|
357
|
+
await call(config.identity, "POST", `/${flow}/prepare`, body, false, config.signal),
|
|
358
|
+
config.identity
|
|
359
|
+
);
|
|
360
|
+
} catch (cause) {
|
|
361
|
+
if (!(cause instanceof ConnectError) || cause.code !== "chain_not_ready" || attempt >= NOT_READY_RETRIES) throw cause;
|
|
362
|
+
cancelled(config.signal);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
async function complete(config, flow, body) {
|
|
367
|
+
try {
|
|
368
|
+
return await call(config.identity, "POST", `/${flow}/complete`, body, true);
|
|
369
|
+
} catch (cause) {
|
|
370
|
+
if (!(cause instanceof ConnectError) || cause.code !== "account_operation_uncertain") throw cause;
|
|
371
|
+
return call(config.identity, "POST", `/${flow}/complete`, body, true);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
function confirmedFrom(value, flow) {
|
|
375
|
+
if (!record(value) || value.status !== "confirmed") malformed();
|
|
376
|
+
const held = flow === "setup" && (value.signature === null || value.signature === void 0);
|
|
377
|
+
if (!held && !text(value.signature)) malformed();
|
|
378
|
+
if (value.next !== null && value.next !== void 0 && !text(value.next, 80)) malformed();
|
|
379
|
+
return { signature: held ? null : value.signature, next: value.next ?? null };
|
|
380
|
+
}
|
|
381
|
+
async function settle(config, flow, step, operationId, cause) {
|
|
382
|
+
let state;
|
|
383
|
+
try {
|
|
384
|
+
state = await getAccountOperation({ identity: config.identity, operationId });
|
|
385
|
+
} catch {
|
|
386
|
+
throw new AccountOperationUnsettledError(operationId, flow, step);
|
|
387
|
+
}
|
|
388
|
+
if (state.status === "confirmed" && (state.signature || flow === "setup")) return { signature: state.signature, next: state.next };
|
|
389
|
+
if (state.status === "failed" || state.status === "prepared" || state.status === "expired") {
|
|
390
|
+
throw cause instanceof ConnectError && cause.code !== "account_operation_uncertain" ? cause : new ConnectError("account_operation_failed");
|
|
391
|
+
}
|
|
392
|
+
throw new AccountOperationUnsettledError(operationId, flow, step);
|
|
393
|
+
}
|
|
394
|
+
async function runFlow(config, flow, body, check) {
|
|
395
|
+
assertApprovalContext();
|
|
396
|
+
if (approvalInProgress) throw new ConnectError("account_operation_in_progress");
|
|
397
|
+
approvalInProgress = true;
|
|
398
|
+
const signatures = [];
|
|
399
|
+
try {
|
|
400
|
+
for (let count = 0; count < MAX_STEPS; count += 1) {
|
|
401
|
+
cancelled(config.signal);
|
|
402
|
+
const prepared = await prepare(config, flow, body);
|
|
403
|
+
if (prepared === null) return Object.freeze({ signatures: Object.freeze(signatures) });
|
|
404
|
+
check?.(prepared.step, prepared.details);
|
|
405
|
+
const view = {
|
|
406
|
+
step: prepared.step,
|
|
407
|
+
summary: prepared.summary,
|
|
408
|
+
statement: prepared.statement,
|
|
409
|
+
stepsRemaining: prepared.stepsRemaining,
|
|
410
|
+
details: prepared.details,
|
|
411
|
+
signature: null
|
|
412
|
+
};
|
|
413
|
+
if (config.confirmStep) {
|
|
414
|
+
config.onStep?.({ ...view, phase: "ready" });
|
|
415
|
+
try {
|
|
416
|
+
await config.confirmStep({ ...view, phase: "ready" });
|
|
417
|
+
} catch {
|
|
418
|
+
throw new ConnectError("user_cancelled");
|
|
419
|
+
}
|
|
420
|
+
cancelled(config.signal);
|
|
421
|
+
}
|
|
422
|
+
config.onStep?.({ ...view, phase: "passkey" });
|
|
423
|
+
let credential;
|
|
424
|
+
try {
|
|
425
|
+
credential = await startAuthentication({ optionsJSON: { ...prepared.publicKey, allowCredentials: [...prepared.publicKey.allowCredentials] } });
|
|
426
|
+
} catch (cause) {
|
|
427
|
+
throw new ConnectError(cause instanceof Error && (cause.name === "NotAllowedError" || cause.name === "AbortError") ? "user_cancelled" : "webauthn_failed");
|
|
428
|
+
}
|
|
429
|
+
if (credential.id !== config.identity.credential.credentialId) {
|
|
430
|
+
throw new ConnectError("account_credential_mismatch");
|
|
431
|
+
}
|
|
432
|
+
cancelled(config.signal);
|
|
433
|
+
config.onStep?.({ ...view, phase: "sending" });
|
|
434
|
+
let result;
|
|
435
|
+
try {
|
|
436
|
+
result = confirmedFrom(await complete(config, flow, {
|
|
437
|
+
operationId: prepared.operationId,
|
|
438
|
+
assertion: {
|
|
439
|
+
credentialId: credential.id,
|
|
440
|
+
authenticatorData: credential.response.authenticatorData,
|
|
441
|
+
clientDataJSON: credential.response.clientDataJSON,
|
|
442
|
+
signature: credential.response.signature,
|
|
443
|
+
userHandle: credential.response.userHandle ?? null
|
|
444
|
+
}
|
|
445
|
+
}), flow);
|
|
446
|
+
} catch (cause) {
|
|
447
|
+
result = await settle(config, flow, prepared.step, prepared.operationId, cause);
|
|
448
|
+
}
|
|
449
|
+
if (result.signature) signatures.push(result.signature);
|
|
450
|
+
config.onStep?.({ ...view, phase: "confirmed", signature: result.signature });
|
|
451
|
+
const next = result.next;
|
|
452
|
+
if (next === null) return Object.freeze({ signatures: Object.freeze(signatures) });
|
|
453
|
+
config.onStep?.({
|
|
454
|
+
step: next,
|
|
455
|
+
summary: "",
|
|
456
|
+
statement: null,
|
|
457
|
+
stepsRemaining: null,
|
|
458
|
+
details: null,
|
|
459
|
+
signature: null,
|
|
460
|
+
phase: "preparing"
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
throw new ConnectError("account_flow_too_long");
|
|
464
|
+
} finally {
|
|
465
|
+
approvalInProgress = false;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
async function getAccount(config) {
|
|
469
|
+
return accountFrom(await call(config.identity, "GET", "/me", void 0, false, config.signal));
|
|
470
|
+
}
|
|
471
|
+
async function getAccountOverview(config) {
|
|
472
|
+
const value = await call(config.identity, "GET", "/me", void 0, false, config.signal);
|
|
473
|
+
const account = accountFrom(value);
|
|
474
|
+
const body = value;
|
|
475
|
+
const network = body.network === "mainnet" ? "mainnet" : text(body.network, 40) ? "test" : null;
|
|
476
|
+
const raw = body.passkey;
|
|
477
|
+
const created = record(raw) && text(raw.createdAt, 40) && !Number.isNaN(Date.parse(raw.createdAt)) ? raw.createdAt : null;
|
|
478
|
+
const passkey = record(raw) ? Object.freeze({ name: text(raw.name, 80) ? raw.name : null, createdAt: created }) : null;
|
|
479
|
+
const pending = body.unsettled;
|
|
480
|
+
const unsettled = record(pending) && text(pending.operationId) && (pending.flow === "setup" || pending.flow === "send") && text(pending.step, 80) ? Object.freeze({ operationId: pending.operationId, flow: pending.flow, step: pending.step }) : null;
|
|
481
|
+
return Object.freeze({ account, network, passkey, unsettled });
|
|
482
|
+
}
|
|
483
|
+
async function getAccountOperation(config) {
|
|
484
|
+
if (!text(config.operationId) || !/^[A-Za-z0-9_-]+$/.test(config.operationId)) throw new ConnectError("invalid_account_operation");
|
|
485
|
+
const value = await call(config.identity, "GET", `/operations/${config.operationId}`, void 0, false, config.signal);
|
|
486
|
+
const statuses = ["prepared", "sending", "confirmed", "failed", "expired"];
|
|
487
|
+
if (!record(value) || value.operationId !== config.operationId || value.flow !== "setup" && value.flow !== "send" || !text(value.step, 80) || typeof value.status !== "string" || !statuses.includes(value.status) || value.signature !== null && value.signature !== void 0 && !text(value.signature) || value.next !== null && value.next !== void 0 && !text(value.next, 80) || value.status === "confirmed" && value.flow === "send" && !text(value.signature)) malformed();
|
|
488
|
+
return Object.freeze({
|
|
489
|
+
operationId: value.operationId,
|
|
490
|
+
flow: value.flow,
|
|
491
|
+
step: value.step,
|
|
492
|
+
status: value.status,
|
|
493
|
+
signature: value.signature ?? null,
|
|
494
|
+
next: value.next ?? null
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
async function getAccountBalances(config) {
|
|
498
|
+
const value = await call(config.identity, "GET", "/balances", void 0, false, config.signal);
|
|
499
|
+
if (!record(value) || !address(value.wallet) || !record(value.sol) || !units(value.sol.lamports) || !Array.isArray(value.tokens) || typeof value.slot !== "number" || typeof value.commitment !== "string") malformed();
|
|
500
|
+
const tokens = value.tokens.map((token) => {
|
|
501
|
+
if (!record(token) || !address(token.mint) || !units(token.amount) || typeof token.decimals !== "number" || !Number.isInteger(token.decimals) || token.decimals < 0 || token.decimals > 18 || token.symbol !== null && token.symbol !== void 0 && !text(token.symbol, 20)) malformed();
|
|
502
|
+
return Object.freeze({
|
|
503
|
+
mint: token.mint,
|
|
504
|
+
symbol: token.symbol ?? null,
|
|
505
|
+
decimals: token.decimals,
|
|
506
|
+
amount: token.amount
|
|
507
|
+
});
|
|
508
|
+
});
|
|
509
|
+
return Object.freeze({
|
|
510
|
+
wallet: value.wallet,
|
|
511
|
+
sol: Object.freeze({ lamports: value.sol.lamports }),
|
|
512
|
+
tokens: Object.freeze(tokens),
|
|
513
|
+
slot: value.slot,
|
|
514
|
+
commitment: value.commitment
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
async function openAccount(config) {
|
|
518
|
+
const existing = await getAccount(config);
|
|
519
|
+
if (existing?.status === "ready" || existing?.status === "held") return existing;
|
|
520
|
+
config.onStep?.({
|
|
521
|
+
step: existing?.nextStep ?? "create-account",
|
|
522
|
+
summary: "",
|
|
523
|
+
statement: null,
|
|
524
|
+
stepsRemaining: null,
|
|
525
|
+
details: null,
|
|
526
|
+
signature: null,
|
|
527
|
+
phase: "preparing"
|
|
528
|
+
});
|
|
529
|
+
await runFlow(config, "setup", {});
|
|
530
|
+
const account = await getAccount(config);
|
|
531
|
+
if (!account) malformed();
|
|
532
|
+
return account;
|
|
533
|
+
}
|
|
534
|
+
async function sendFromAccount(config) {
|
|
535
|
+
const { send } = config;
|
|
536
|
+
if (!record(send) || !(send.mint === "SOL" || address(send.mint)) || !units(send.amount) || send.amount === "0" || !address(send.to)) {
|
|
537
|
+
throw new ConnectError("invalid_account_send");
|
|
538
|
+
}
|
|
539
|
+
const request = { mint: send.mint, amount: send.amount, to: send.to };
|
|
540
|
+
return runFlow(config, "send", request, (step, details) => {
|
|
541
|
+
const sameToken = details !== null && details.mint === request.mint;
|
|
542
|
+
if (step === "prepare-token" ? !sameToken || details.amount !== null || details.to !== null : !sameToken || details.amount !== request.amount || details.to !== request.to) {
|
|
543
|
+
throw new ConnectError("account_operation_mismatch");
|
|
544
|
+
}
|
|
545
|
+
});
|
|
546
|
+
}
|
|
547
|
+
function formatAccountAmount(amount, decimals) {
|
|
548
|
+
if (!units(amount) || !Number.isInteger(decimals) || decimals < 0 || decimals > 18) {
|
|
549
|
+
throw new ConnectError("invalid_account_amount");
|
|
550
|
+
}
|
|
551
|
+
if (decimals === 0) return amount;
|
|
552
|
+
const padded = amount.padStart(decimals + 1, "0");
|
|
553
|
+
const fraction = padded.slice(-decimals).replace(/0+$/, "");
|
|
554
|
+
return fraction ? `${padded.slice(0, -decimals)}.${fraction}` : padded.slice(0, -decimals);
|
|
555
|
+
}
|
|
556
|
+
function parseAccountAmount(input, decimals) {
|
|
557
|
+
if (!Number.isInteger(decimals) || decimals < 0 || decimals > 18) return null;
|
|
558
|
+
const match = /^([0-9]{0,20})(?:\.([0-9]*))?$/.exec(typeof input === "string" ? input.trim() : "");
|
|
559
|
+
if (!match || match[1] === "" && !match[2]) return null;
|
|
560
|
+
const fraction = match[2] ?? "";
|
|
561
|
+
if (fraction.length > decimals) return null;
|
|
562
|
+
const value = BigInt(`${match[1] || "0"}${fraction.padEnd(decimals, "0")}`);
|
|
563
|
+
return value > 0n && value < 1n << 64n ? value.toString() : null;
|
|
564
|
+
}
|
|
565
|
+
|
|
212
566
|
// src/agentSpend.ts
|
|
213
567
|
import { PublicKey as PublicKey2 } from "@solana/web3.js";
|
|
214
568
|
import { WebAuthnAssertion } from "@dexterai/vault/signers/browser";
|
|
@@ -926,8 +1280,11 @@ async function readAgentAuthority(input) {
|
|
|
926
1280
|
return payload;
|
|
927
1281
|
}
|
|
928
1282
|
export {
|
|
1283
|
+
ACCOUNT_API_PATH,
|
|
1284
|
+
ACCOUNT_IDENTITY_API_PATH,
|
|
929
1285
|
AGENT_AUTHORITY_NAMESPACE,
|
|
930
1286
|
AGENT_AUTHORITY_STATUS_NAMESPACE,
|
|
1287
|
+
AccountOperationUnsettledError,
|
|
931
1288
|
AgentAuthorityError,
|
|
932
1289
|
AgentSpendError,
|
|
933
1290
|
AgentAuthorityError as BoundedX402AuthorityError,
|
|
@@ -962,10 +1319,19 @@ export {
|
|
|
962
1319
|
describeAgentSpendError,
|
|
963
1320
|
disconnectDexterIdentity,
|
|
964
1321
|
enableAgentSpend,
|
|
1322
|
+
enrollAccountAccess,
|
|
1323
|
+
enrollAccountIdentity,
|
|
965
1324
|
exactAgentAuthorityApprovalRedirect,
|
|
966
1325
|
exactBoundedX402ApprovalRedirect,
|
|
967
1326
|
fetchWithWalletIdentity,
|
|
1327
|
+
formatAccountAmount,
|
|
1328
|
+
getAccount,
|
|
1329
|
+
getAccountBalances,
|
|
1330
|
+
getAccountOperation,
|
|
1331
|
+
getAccountOverview,
|
|
968
1332
|
noCustomX402Limits,
|
|
1333
|
+
openAccount,
|
|
1334
|
+
parseAccountAmount,
|
|
969
1335
|
passkeySignalSupport,
|
|
970
1336
|
prunePasskey,
|
|
971
1337
|
readAgentAuthority,
|
|
@@ -973,6 +1339,9 @@ export {
|
|
|
973
1339
|
recoverWallet,
|
|
974
1340
|
renamePasskey,
|
|
975
1341
|
revokeAgentSpend,
|
|
1342
|
+
sendFromAccount,
|
|
1343
|
+
signInAccountAccess,
|
|
1344
|
+
signInAccountIdentity,
|
|
976
1345
|
stageAgentAuthority,
|
|
977
1346
|
stageBoundedX402Authority,
|
|
978
1347
|
syncAcceptedPasskeys,
|
package/dist/react.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { d as ConnectVault, R as RecoverOutcome,
|
|
3
|
-
import { i as DexterControlModel, a as WalletAccountRelationSnapshot, g as DexterConnectionIntent, e as AccountSessionInstaller, d as AccountSessionClearer, B as BindingFetch } from './connectionContract-
|
|
4
|
-
export { D as DexterConnectionCapability, h as DexterConnectionPermissions, j as DexterControlPrimaryAction, k as DexterControlStage } from './connectionContract-
|
|
1
|
+
import { f as ConnectError, S as SignInResult, I as PasskeyLoginConfig, A as AccountIdentityResult, C as CreateWalletResult, m as AgentDelegationMode } from './accountIdentity-DQ_C-WAi.js';
|
|
2
|
+
export { d as ConnectVault, R as RecoverOutcome, t as RecoverVault, g as WalletIdentityProof } from './accountIdentity-DQ_C-WAi.js';
|
|
3
|
+
import { i as DexterControlModel, a as WalletAccountRelationSnapshot, g as DexterConnectionIntent, e as AccountSessionInstaller, d as AccountSessionClearer, B as BindingFetch } from './connectionContract-BA03zq2D.js';
|
|
4
|
+
export { D as DexterConnectionCapability, h as DexterConnectionPermissions, j as DexterControlPrimaryAction, k as DexterControlStage } from './connectionContract-BA03zq2D.js';
|
|
5
5
|
import * as react from 'react';
|
|
6
6
|
import { ButtonHTMLAttributes, ReactNode, ReactElement, ComponentType, AnchorHTMLAttributes } from 'react';
|
|
7
7
|
|
|
8
8
|
/** The Dexter passkey mark carried on the branded button. */
|
|
9
9
|
declare function DexterMark(): ReactElement;
|
|
10
10
|
interface DexterButtonProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'children' | 'onClick' | 'disabled' | 'className' | 'type'> {
|
|
11
|
-
/** Button content (e.g. "
|
|
11
|
+
/** Button content (e.g. "Connect Dexter", "Create your Dexter Wallet"). */
|
|
12
12
|
children?: ReactNode;
|
|
13
13
|
/** Loading state: shows the animated spinner + `loadingLabel`, disables click. */
|
|
14
14
|
loading?: boolean;
|
|
@@ -117,6 +117,8 @@ interface AllowanceChipsProps {
|
|
|
117
117
|
declare function AllowanceChips(props: AllowanceChipsProps): ReactElement;
|
|
118
118
|
|
|
119
119
|
interface CreateWalletPanelProps {
|
|
120
|
+
/** Use the credential-only Account ceremony in place of wallet creation. */
|
|
121
|
+
onCredentialCreated?: (result: AccountIdentityResult) => void;
|
|
120
122
|
/** Fired with the minted wallet the moment creation succeeds. */
|
|
121
123
|
onCreated?: (result: CreateWalletResult) => void;
|
|
122
124
|
/** Fired with the typed error if the ceremony fails. */
|
|
@@ -125,8 +127,8 @@ interface CreateWalletPanelProps {
|
|
|
125
127
|
apiBase?: string;
|
|
126
128
|
/** Where the WebAuthn ceremony runs. Default 'auto' (createWallet's default). */
|
|
127
129
|
transport?: 'auto' | 'popup' | 'inline';
|
|
128
|
-
/**
|
|
129
|
-
showName?: boolean;
|
|
130
|
+
/** Show the optional name field immediately (default), on request, or never. */
|
|
131
|
+
showName?: boolean | 'on-request';
|
|
130
132
|
/**
|
|
131
133
|
* `deferred` is the default and omits the agent-allowance UI.
|
|
132
134
|
* `configure-now` is the explicit compatibility flow for an allowance.
|
|
@@ -172,6 +174,13 @@ interface AccountMenuItem {
|
|
|
172
174
|
interface DexterAccountControlProps {
|
|
173
175
|
/** Reuse the app's canonical useDexterConnection instance. */
|
|
174
176
|
connection: UseDexterConnection;
|
|
177
|
+
/** Provide an independent sign-in for people without a connected wallet. */
|
|
178
|
+
credentialAccess?: {
|
|
179
|
+
signedIn: boolean;
|
|
180
|
+
loading: boolean;
|
|
181
|
+
accept: (result: AccountIdentityResult) => void;
|
|
182
|
+
clear: () => void;
|
|
183
|
+
};
|
|
175
184
|
open?: boolean;
|
|
176
185
|
onOpenChange?: (open: boolean) => void;
|
|
177
186
|
/** Shown only after the connection verifies account access. */
|
|
@@ -191,7 +200,7 @@ interface DexterAccountControlProps {
|
|
|
191
200
|
styleNonce?: string;
|
|
192
201
|
}
|
|
193
202
|
/** Branded account entry with canonical connection, balance and settings. */
|
|
194
|
-
declare function DexterAccountControl({ connection: dexter, open: controlledOpen, onOpenChange, profile, navigation, items, LinkComponent, renderSummary, formatError, className, triggerClassName, styleNonce, }: DexterAccountControlProps): react.JSX.Element;
|
|
203
|
+
declare function DexterAccountControl({ connection: dexter, open: controlledOpen, onOpenChange, credentialAccess, profile, navigation, items, LinkComponent, renderSummary, formatError, className, triggerClassName, styleNonce, }: DexterAccountControlProps): react.JSX.Element;
|
|
195
204
|
|
|
196
205
|
interface DexterAccountSummaryProps {
|
|
197
206
|
/** Formatted value from a read bound to the currently selected account. */
|