@dexterai/connect 0.29.0 → 0.29.1
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 +17 -0
- package/dist/chunk-2BTS6DCR.js +618 -0
- package/dist/{chunk-XKOVUW5P.js → chunk-CZL7NGVV.js} +82 -608
- package/dist/chunk-LHYU2EZQ.js +183 -0
- package/dist/connectionContract-CR478cfF.d.ts +228 -0
- package/dist/enroll-DrgEW0X8.d.ts +245 -0
- package/dist/hosted.d.ts +72 -0
- package/dist/hosted.js +95 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +16 -182
- package/dist/react.d.ts +4 -2
- package/dist/react.js +9 -7
- package/package.json +5 -1
- package/dist/connectionContract-QGRidIHM.d.ts +0 -470
|
@@ -44,9 +44,6 @@ function parseWalletIdentityProof(value) {
|
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
// src/bindingResolver.ts
|
|
48
|
-
import { PublicKey } from "@solana/web3.js";
|
|
49
|
-
|
|
50
47
|
// src/trust.ts
|
|
51
48
|
var DEXTER_API_BASE = "https://api.dexter.cash";
|
|
52
49
|
var DEXTER_CONNECT_HOST = "https://dexter.cash/connect";
|
|
@@ -81,6 +78,7 @@ function bytesEqual(a, b) {
|
|
|
81
78
|
}
|
|
82
79
|
|
|
83
80
|
// src/bindingResolver.ts
|
|
81
|
+
import { PublicKey } from "@solana/web3.js";
|
|
84
82
|
var WALLET_ACCOUNT_BINDING_PATH = "/api/passkey-anon/binding/resolve";
|
|
85
83
|
var walletBindings = /* @__PURE__ */ new WeakMap();
|
|
86
84
|
var accountTokens = /* @__PURE__ */ new WeakMap();
|
|
@@ -1076,402 +1074,6 @@ async function initializeVault(apiBase, userHandle, credentialId, spendPolicy, l
|
|
|
1076
1074
|
return await res.json();
|
|
1077
1075
|
}
|
|
1078
1076
|
|
|
1079
|
-
// src/relationController.ts
|
|
1080
|
-
function provisionalRelation(walletPresent, accountPresent) {
|
|
1081
|
-
if (walletPresent) return "wallet_only";
|
|
1082
|
-
if (accountPresent) return "account_only";
|
|
1083
|
-
return "none";
|
|
1084
|
-
}
|
|
1085
|
-
function frozenRuntime(runtime) {
|
|
1086
|
-
return Object.freeze({ ...runtime });
|
|
1087
|
-
}
|
|
1088
|
-
function frozenSnapshot(relation, runtime, walletPresent, accountPresent, verifiedAt, revision) {
|
|
1089
|
-
const readyAndBound = relation === "bound" && runtime.phase === "ready";
|
|
1090
|
-
return Object.freeze({
|
|
1091
|
-
relation,
|
|
1092
|
-
runtime: frozenRuntime(runtime),
|
|
1093
|
-
walletPresent,
|
|
1094
|
-
accountPresent,
|
|
1095
|
-
privateAccountAccess: readyAndBound,
|
|
1096
|
-
quarantined: relation === "conflict",
|
|
1097
|
-
verifiedAt: readyAndBound || relation === "conflict" ? verifiedAt : null,
|
|
1098
|
-
revision
|
|
1099
|
-
});
|
|
1100
|
-
}
|
|
1101
|
-
function isVerifiedResult(value) {
|
|
1102
|
-
if (!value || typeof value !== "object") return false;
|
|
1103
|
-
const result = value;
|
|
1104
|
-
if (result.ok !== true) return false;
|
|
1105
|
-
if (result.relation !== "bound" && result.relation !== "conflict") return false;
|
|
1106
|
-
return result.verifiedAt === void 0 || Number.isFinite(result.verifiedAt);
|
|
1107
|
-
}
|
|
1108
|
-
function isFailureResult(value) {
|
|
1109
|
-
if (!value || typeof value !== "object") return false;
|
|
1110
|
-
const result = value;
|
|
1111
|
-
if (result.ok !== false) return false;
|
|
1112
|
-
if (result.reason === "offline") return true;
|
|
1113
|
-
if (result.reason === "expired") {
|
|
1114
|
-
return result.subject === "wallet" || result.subject === "account" || result.subject === "both";
|
|
1115
|
-
}
|
|
1116
|
-
return result.reason === "error" && typeof result.code === "string" && result.code.length > 0;
|
|
1117
|
-
}
|
|
1118
|
-
var WalletAccountRelationController = class {
|
|
1119
|
-
wallet = null;
|
|
1120
|
-
account = null;
|
|
1121
|
-
revision = 0;
|
|
1122
|
-
activeCheck = null;
|
|
1123
|
-
listeners = /* @__PURE__ */ new Set();
|
|
1124
|
-
verify;
|
|
1125
|
-
now;
|
|
1126
|
-
snapshot;
|
|
1127
|
-
constructor(options) {
|
|
1128
|
-
this.verify = options.verify;
|
|
1129
|
-
this.now = options.now ?? Date.now;
|
|
1130
|
-
this.snapshot = frozenSnapshot("none", { phase: "hydrating" }, false, false, null, 0);
|
|
1131
|
-
}
|
|
1132
|
-
getSnapshot() {
|
|
1133
|
-
return this.snapshot;
|
|
1134
|
-
}
|
|
1135
|
-
subscribe(listener) {
|
|
1136
|
-
this.listeners.add(listener);
|
|
1137
|
-
return () => this.listeners.delete(listener);
|
|
1138
|
-
}
|
|
1139
|
-
/** Restore cached candidates, then verify the exact pair before unlocking account access. */
|
|
1140
|
-
restore(candidates) {
|
|
1141
|
-
this.replaceCandidates(candidates.wallet, candidates.account, { phase: "hydrating" });
|
|
1142
|
-
return this.settle("restore");
|
|
1143
|
-
}
|
|
1144
|
-
/** Lock account-owned data while the host restores its account session. */
|
|
1145
|
-
beginRestore() {
|
|
1146
|
-
this.invalidate({ phase: "hydrating" });
|
|
1147
|
-
}
|
|
1148
|
-
/** An explicit Wallet event always invalidates prior binding, even for the same object. */
|
|
1149
|
-
setWallet(wallet) {
|
|
1150
|
-
this.replaceCandidates(wallet, this.account, this.runtimeAfterChange("wallet_change", wallet, this.account));
|
|
1151
|
-
return this.settle("wallet_change");
|
|
1152
|
-
}
|
|
1153
|
-
/** An explicit account event always invalidates prior binding, even for the same object. */
|
|
1154
|
-
setAccount(account) {
|
|
1155
|
-
this.replaceCandidates(this.wallet, account, this.runtimeAfterChange("account_change", this.wallet, account));
|
|
1156
|
-
return this.settle("account_change");
|
|
1157
|
-
}
|
|
1158
|
-
retry() {
|
|
1159
|
-
this.invalidate(this.runtimeAfterChange("retry", this.wallet, this.account));
|
|
1160
|
-
return this.settle("retry");
|
|
1161
|
-
}
|
|
1162
|
-
dispose() {
|
|
1163
|
-
this.activeCheck?.abort();
|
|
1164
|
-
this.activeCheck = null;
|
|
1165
|
-
this.listeners.clear();
|
|
1166
|
-
}
|
|
1167
|
-
runtimeAfterChange(reason, wallet, account) {
|
|
1168
|
-
return wallet !== null && account !== null ? { phase: "checking", reason } : { phase: "ready" };
|
|
1169
|
-
}
|
|
1170
|
-
replaceCandidates(wallet, account, runtime) {
|
|
1171
|
-
this.wallet = wallet;
|
|
1172
|
-
this.account = account;
|
|
1173
|
-
this.invalidate(runtime);
|
|
1174
|
-
}
|
|
1175
|
-
invalidate(runtime) {
|
|
1176
|
-
this.activeCheck?.abort();
|
|
1177
|
-
this.activeCheck = null;
|
|
1178
|
-
this.revision += 1;
|
|
1179
|
-
const walletPresent = this.wallet !== null;
|
|
1180
|
-
const accountPresent = this.account !== null;
|
|
1181
|
-
this.publish(
|
|
1182
|
-
provisionalRelation(walletPresent, accountPresent),
|
|
1183
|
-
runtime,
|
|
1184
|
-
walletPresent,
|
|
1185
|
-
accountPresent,
|
|
1186
|
-
null,
|
|
1187
|
-
this.revision
|
|
1188
|
-
);
|
|
1189
|
-
}
|
|
1190
|
-
settle(reason) {
|
|
1191
|
-
if (this.wallet !== null && this.account !== null) return this.runCheck(reason);
|
|
1192
|
-
if (this.snapshot.runtime.phase !== "ready") {
|
|
1193
|
-
this.publish(
|
|
1194
|
-
provisionalRelation(this.wallet !== null, this.account !== null),
|
|
1195
|
-
{ phase: "ready" },
|
|
1196
|
-
this.wallet !== null,
|
|
1197
|
-
this.account !== null,
|
|
1198
|
-
null,
|
|
1199
|
-
this.revision
|
|
1200
|
-
);
|
|
1201
|
-
}
|
|
1202
|
-
return Promise.resolve(this.snapshot);
|
|
1203
|
-
}
|
|
1204
|
-
async runCheck(reason) {
|
|
1205
|
-
const wallet = this.wallet;
|
|
1206
|
-
const account = this.account;
|
|
1207
|
-
if (wallet === null || account === null) return this.settle(reason);
|
|
1208
|
-
const revision = this.revision;
|
|
1209
|
-
const check = new AbortController();
|
|
1210
|
-
this.activeCheck?.abort();
|
|
1211
|
-
this.activeCheck = check;
|
|
1212
|
-
if (this.snapshot.runtime.phase !== "checking" || this.snapshot.runtime.reason !== reason) {
|
|
1213
|
-
this.publish(
|
|
1214
|
-
provisionalRelation(true, true),
|
|
1215
|
-
{ phase: "checking", reason },
|
|
1216
|
-
true,
|
|
1217
|
-
true,
|
|
1218
|
-
null,
|
|
1219
|
-
revision
|
|
1220
|
-
);
|
|
1221
|
-
}
|
|
1222
|
-
try {
|
|
1223
|
-
const result = await this.verify({ wallet, account, reason, signal: check.signal });
|
|
1224
|
-
if (!this.isCurrentCheck(check, revision)) return this.snapshot;
|
|
1225
|
-
this.activeCheck = null;
|
|
1226
|
-
if (isVerifiedResult(result)) {
|
|
1227
|
-
this.publish(result.relation, { phase: "ready" }, true, true, result.verifiedAt ?? this.now(), revision);
|
|
1228
|
-
return this.snapshot;
|
|
1229
|
-
}
|
|
1230
|
-
if (isFailureResult(result)) {
|
|
1231
|
-
const runtime = result.reason === "offline" ? { phase: "offline" } : result.reason === "expired" ? { phase: "expired", subject: result.subject } : { phase: "error", code: result.code };
|
|
1232
|
-
this.publish("wallet_only", runtime, true, true, null, revision);
|
|
1233
|
-
return this.snapshot;
|
|
1234
|
-
}
|
|
1235
|
-
this.publish("wallet_only", { phase: "error", code: "invalid_verification_result" }, true, true, null, revision);
|
|
1236
|
-
} catch (error) {
|
|
1237
|
-
if (!this.isCurrentCheck(check, revision)) return this.snapshot;
|
|
1238
|
-
this.activeCheck = null;
|
|
1239
|
-
const code = error && typeof error === "object" && "code" in error && typeof error.code === "string" ? error.code : "verification_failed";
|
|
1240
|
-
this.publish("wallet_only", { phase: "error", code }, true, true, null, revision);
|
|
1241
|
-
}
|
|
1242
|
-
return this.snapshot;
|
|
1243
|
-
}
|
|
1244
|
-
isCurrentCheck(check, revision) {
|
|
1245
|
-
return this.activeCheck === check && this.revision === revision && !check.signal.aborted;
|
|
1246
|
-
}
|
|
1247
|
-
publish(relation, runtime, walletPresent, accountPresent, verifiedAt, revision) {
|
|
1248
|
-
this.snapshot = frozenSnapshot(
|
|
1249
|
-
relation,
|
|
1250
|
-
runtime,
|
|
1251
|
-
walletPresent,
|
|
1252
|
-
accountPresent,
|
|
1253
|
-
verifiedAt,
|
|
1254
|
-
revision
|
|
1255
|
-
);
|
|
1256
|
-
for (const listener of this.listeners) {
|
|
1257
|
-
try {
|
|
1258
|
-
listener(this.snapshot);
|
|
1259
|
-
} catch {
|
|
1260
|
-
}
|
|
1261
|
-
}
|
|
1262
|
-
}
|
|
1263
|
-
};
|
|
1264
|
-
|
|
1265
|
-
// src/identityCoordinator.ts
|
|
1266
|
-
import { decodeJwt } from "jose";
|
|
1267
|
-
var CANONICAL_ACCOUNT_SUBJECT = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
|
|
1268
|
-
function walletCandidate(wallet, proofStore) {
|
|
1269
|
-
if (!wallet) return null;
|
|
1270
|
-
let proof = null;
|
|
1271
|
-
try {
|
|
1272
|
-
proof = wallet.vaultPda ? proofStore.bindingCandidate(wallet.handle, {
|
|
1273
|
-
userHandle: wallet.handle,
|
|
1274
|
-
vaultPda: wallet.vaultPda
|
|
1275
|
-
}) : null;
|
|
1276
|
-
} catch {
|
|
1277
|
-
proof = null;
|
|
1278
|
-
}
|
|
1279
|
-
return Object.freeze({ handle: wallet.handle, wallet, proof });
|
|
1280
|
-
}
|
|
1281
|
-
function accountCandidate(accessToken) {
|
|
1282
|
-
return accessToken ? accountBindingCandidate(accessToken) : null;
|
|
1283
|
-
}
|
|
1284
|
-
function canonicalAccountSubject(accessToken) {
|
|
1285
|
-
try {
|
|
1286
|
-
const subject = decodeJwt(accessToken).sub;
|
|
1287
|
-
return typeof subject === "string" && CANONICAL_ACCOUNT_SUBJECT.test(subject) ? subject : null;
|
|
1288
|
-
} catch {
|
|
1289
|
-
return null;
|
|
1290
|
-
}
|
|
1291
|
-
}
|
|
1292
|
-
function createDexterIdentityCoordinator(options = {}) {
|
|
1293
|
-
const proofStore = options.proofSessionStore ?? walletProofSessionStore;
|
|
1294
|
-
const bindingClient = options.bindingClient ?? createWalletAccountBindingClient({
|
|
1295
|
-
...options.apiBase ? { apiBase: options.apiBase } : {},
|
|
1296
|
-
...options.fetch ? { fetch: options.fetch } : {}
|
|
1297
|
-
});
|
|
1298
|
-
const controller = new WalletAccountRelationController({
|
|
1299
|
-
verify: async ({ wallet, account, reason, signal }) => {
|
|
1300
|
-
if (!wallet.proof) {
|
|
1301
|
-
return {
|
|
1302
|
-
ok: false,
|
|
1303
|
-
reason: "expired",
|
|
1304
|
-
subject: "wallet"
|
|
1305
|
-
};
|
|
1306
|
-
}
|
|
1307
|
-
return bindingClient.verify({
|
|
1308
|
-
wallet: wallet.proof,
|
|
1309
|
-
account,
|
|
1310
|
-
reason,
|
|
1311
|
-
signal
|
|
1312
|
-
});
|
|
1313
|
-
}
|
|
1314
|
-
});
|
|
1315
|
-
let currentAccount = null;
|
|
1316
|
-
let currentAccountAccessToken = null;
|
|
1317
|
-
let currentAccountSubject = null;
|
|
1318
|
-
let invalidatedAccountSubject = null;
|
|
1319
|
-
let allowedAccountAccessToken = null;
|
|
1320
|
-
let pendingAccountSettlement = null;
|
|
1321
|
-
let accountLoading = false;
|
|
1322
|
-
let disposed = false;
|
|
1323
|
-
let started = false;
|
|
1324
|
-
let unsubscribeWallet = null;
|
|
1325
|
-
let unsubscribeProof = null;
|
|
1326
|
-
let proofExpiryTimer = null;
|
|
1327
|
-
const currentWallet = () => walletCandidate(getActiveWallet(), proofStore);
|
|
1328
|
-
const clearCurrentAccount = () => {
|
|
1329
|
-
currentAccount = null;
|
|
1330
|
-
currentAccountAccessToken = null;
|
|
1331
|
-
currentAccountSubject = null;
|
|
1332
|
-
pendingAccountSettlement = null;
|
|
1333
|
-
};
|
|
1334
|
-
const setCurrentAccount = (accountAccessToken) => {
|
|
1335
|
-
currentAccount = accountCandidate(accountAccessToken);
|
|
1336
|
-
currentAccountAccessToken = accountAccessToken;
|
|
1337
|
-
currentAccountSubject = canonicalAccountSubject(accountAccessToken);
|
|
1338
|
-
};
|
|
1339
|
-
const keepAccountLoadingLocked = (wallet) => {
|
|
1340
|
-
clearCurrentAccount();
|
|
1341
|
-
void controller.restore({ wallet, account: null });
|
|
1342
|
-
controller.beginRestore();
|
|
1343
|
-
};
|
|
1344
|
-
const clearProofExpiryTimer = () => {
|
|
1345
|
-
if (proofExpiryTimer !== null) clearTimeout(proofExpiryTimer);
|
|
1346
|
-
proofExpiryTimer = null;
|
|
1347
|
-
};
|
|
1348
|
-
const scheduleProofExpiry = () => {
|
|
1349
|
-
clearProofExpiryTimer();
|
|
1350
|
-
const active = getActiveWallet();
|
|
1351
|
-
if (!active) return;
|
|
1352
|
-
const session = proofStore.load(active.handle);
|
|
1353
|
-
if (!session) return;
|
|
1354
|
-
const remainingMs = Math.max(0, session.expiresAt * 1e3 - Date.now());
|
|
1355
|
-
const delayMs = Math.min(remainingMs, 2147e6);
|
|
1356
|
-
proofExpiryTimer = setTimeout(() => {
|
|
1357
|
-
proofExpiryTimer = null;
|
|
1358
|
-
if (Date.now() < session.expiresAt * 1e3) {
|
|
1359
|
-
scheduleProofExpiry();
|
|
1360
|
-
return;
|
|
1361
|
-
}
|
|
1362
|
-
void controller.setWallet(currentWallet());
|
|
1363
|
-
scheduleProofExpiry();
|
|
1364
|
-
}, delayMs);
|
|
1365
|
-
};
|
|
1366
|
-
const start = () => {
|
|
1367
|
-
if (started || disposed) return;
|
|
1368
|
-
started = true;
|
|
1369
|
-
unsubscribeWallet = subscribe((event) => {
|
|
1370
|
-
if (disposed || !event.invalidatesAccountBinding) return;
|
|
1371
|
-
scheduleProofExpiry();
|
|
1372
|
-
const wallet = currentWallet();
|
|
1373
|
-
if (accountLoading) {
|
|
1374
|
-
keepAccountLoadingLocked(wallet);
|
|
1375
|
-
return;
|
|
1376
|
-
}
|
|
1377
|
-
invalidatedAccountSubject = currentAccountSubject ?? invalidatedAccountSubject;
|
|
1378
|
-
clearCurrentAccount();
|
|
1379
|
-
void controller.restore({ wallet, account: null });
|
|
1380
|
-
});
|
|
1381
|
-
unsubscribeProof = proofStore.subscribe((event) => {
|
|
1382
|
-
if (disposed) return;
|
|
1383
|
-
const active = getActiveWallet();
|
|
1384
|
-
if (!active) return;
|
|
1385
|
-
if (event.handle !== null && event.handle !== active.handle) return;
|
|
1386
|
-
scheduleProofExpiry();
|
|
1387
|
-
const wallet = walletCandidate(active, proofStore);
|
|
1388
|
-
if (accountLoading) {
|
|
1389
|
-
keepAccountLoadingLocked(wallet);
|
|
1390
|
-
return;
|
|
1391
|
-
}
|
|
1392
|
-
void controller.setWallet(wallet);
|
|
1393
|
-
});
|
|
1394
|
-
scheduleProofExpiry();
|
|
1395
|
-
};
|
|
1396
|
-
const restore = (accountAccessToken) => {
|
|
1397
|
-
start();
|
|
1398
|
-
accountLoading = false;
|
|
1399
|
-
invalidatedAccountSubject = null;
|
|
1400
|
-
allowedAccountAccessToken = null;
|
|
1401
|
-
if (accountAccessToken) setCurrentAccount(accountAccessToken);
|
|
1402
|
-
else clearCurrentAccount();
|
|
1403
|
-
return controller.restore({
|
|
1404
|
-
wallet: currentWallet(),
|
|
1405
|
-
account: currentAccount
|
|
1406
|
-
});
|
|
1407
|
-
};
|
|
1408
|
-
const setAccountSession = (accountAccessToken) => {
|
|
1409
|
-
start();
|
|
1410
|
-
const wasAccountLoading = accountLoading;
|
|
1411
|
-
accountLoading = false;
|
|
1412
|
-
if (accountAccessToken) {
|
|
1413
|
-
if (accountAccessToken === currentAccountAccessToken && !wasAccountLoading) {
|
|
1414
|
-
return pendingAccountSettlement?.accessToken === accountAccessToken ? pendingAccountSettlement.promise : Promise.resolve(controller.getSnapshot());
|
|
1415
|
-
}
|
|
1416
|
-
const nextSubject = canonicalAccountSubject(accountAccessToken);
|
|
1417
|
-
const allowed = accountAccessToken === allowedAccountAccessToken;
|
|
1418
|
-
if (nextSubject === null || !allowed && invalidatedAccountSubject !== null && nextSubject === invalidatedAccountSubject) {
|
|
1419
|
-
clearCurrentAccount();
|
|
1420
|
-
return controller.setAccount(null);
|
|
1421
|
-
}
|
|
1422
|
-
allowedAccountAccessToken = null;
|
|
1423
|
-
invalidatedAccountSubject = null;
|
|
1424
|
-
setCurrentAccount(accountAccessToken);
|
|
1425
|
-
} else {
|
|
1426
|
-
allowedAccountAccessToken = null;
|
|
1427
|
-
clearCurrentAccount();
|
|
1428
|
-
}
|
|
1429
|
-
const settlement = controller.setAccount(currentAccount);
|
|
1430
|
-
if (accountAccessToken) {
|
|
1431
|
-
const tracked = { accessToken: accountAccessToken, promise: settlement };
|
|
1432
|
-
pendingAccountSettlement = tracked;
|
|
1433
|
-
const clearTrackedSettlement = () => {
|
|
1434
|
-
if (pendingAccountSettlement === tracked) {
|
|
1435
|
-
pendingAccountSettlement = null;
|
|
1436
|
-
}
|
|
1437
|
-
};
|
|
1438
|
-
void settlement.then(clearTrackedSettlement, clearTrackedSettlement);
|
|
1439
|
-
} else {
|
|
1440
|
-
pendingAccountSettlement = null;
|
|
1441
|
-
}
|
|
1442
|
-
return settlement;
|
|
1443
|
-
};
|
|
1444
|
-
return Object.freeze({
|
|
1445
|
-
getSnapshot: () => controller.getSnapshot(),
|
|
1446
|
-
subscribe: (listener) => controller.subscribe(listener),
|
|
1447
|
-
restore,
|
|
1448
|
-
setAccountSession,
|
|
1449
|
-
setAccountLoading: () => {
|
|
1450
|
-
start();
|
|
1451
|
-
accountLoading = true;
|
|
1452
|
-
controller.beginRestore();
|
|
1453
|
-
},
|
|
1454
|
-
allowAccountSession: (accountAccessToken) => {
|
|
1455
|
-
if (canonicalAccountSubject(accountAccessToken) === null) {
|
|
1456
|
-
throw new ConnectError("invalid_account_access_token");
|
|
1457
|
-
}
|
|
1458
|
-
allowedAccountAccessToken = accountAccessToken;
|
|
1459
|
-
},
|
|
1460
|
-
retry: () => {
|
|
1461
|
-
start();
|
|
1462
|
-
return controller.retry();
|
|
1463
|
-
},
|
|
1464
|
-
dispose: () => {
|
|
1465
|
-
if (disposed) return;
|
|
1466
|
-
disposed = true;
|
|
1467
|
-
clearProofExpiryTimer();
|
|
1468
|
-
unsubscribeWallet?.();
|
|
1469
|
-
unsubscribeProof?.();
|
|
1470
|
-
controller.dispose();
|
|
1471
|
-
}
|
|
1472
|
-
});
|
|
1473
|
-
}
|
|
1474
|
-
|
|
1475
1077
|
// src/relay.ts
|
|
1476
1078
|
import { startAuthentication, browserSupportsWebAuthn } from "@simplewebauthn/browser";
|
|
1477
1079
|
|
|
@@ -1482,9 +1084,9 @@ function immediateGetSupported() {
|
|
|
1482
1084
|
immediateCapPromise = (async () => {
|
|
1483
1085
|
try {
|
|
1484
1086
|
if (typeof window === "undefined") return false;
|
|
1485
|
-
const
|
|
1486
|
-
if (!
|
|
1487
|
-
const caps = await
|
|
1087
|
+
const pkc = window.PublicKeyCredential;
|
|
1088
|
+
if (!pkc || typeof pkc.getClientCapabilities !== "function") return false;
|
|
1089
|
+
const caps = await pkc.getClientCapabilities.call(pkc);
|
|
1488
1090
|
return caps?.immediateGet === true;
|
|
1489
1091
|
} catch {
|
|
1490
1092
|
return false;
|
|
@@ -1572,6 +1174,78 @@ async function passkeyLogin(config = {}, onPhase) {
|
|
|
1572
1174
|
}
|
|
1573
1175
|
return result;
|
|
1574
1176
|
}
|
|
1177
|
+
async function continueWithDexter(config = {}, onPhase) {
|
|
1178
|
+
const walletStore = resolveWalletStoreMode(config.walletStore);
|
|
1179
|
+
const agentDelegation = resolveAgentDelegationMode(
|
|
1180
|
+
config.agentDelegation ?? (config.spendPolicy ? "configure-now" : void 0)
|
|
1181
|
+
);
|
|
1182
|
+
const hasExplicitCreationChoice = config.agentDelegation !== void 0 || Boolean(config.spendPolicy);
|
|
1183
|
+
resolveDexterApiBase(config.apiBase);
|
|
1184
|
+
if (agentDelegation === "deferred" && config.spendPolicy) {
|
|
1185
|
+
throw new ConnectError(
|
|
1186
|
+
"conflicting_agent_delegation",
|
|
1187
|
+
"agentDelegation deferred cannot include a spendPolicy"
|
|
1188
|
+
);
|
|
1189
|
+
}
|
|
1190
|
+
if (shouldUsePopup(config.transport)) {
|
|
1191
|
+
const popupResult = await openCeremonyPopup("continue", {
|
|
1192
|
+
connectHost: config.connectHost,
|
|
1193
|
+
name: config.name,
|
|
1194
|
+
...walletStore === "provisional" ? { walletStore } : {},
|
|
1195
|
+
agentDelegation
|
|
1196
|
+
});
|
|
1197
|
+
const result = popupResult.kind === "signin" ? { kind: "signin", ...normalizeSignInResult(popupResult) } : popupResult.kind === "create" ? {
|
|
1198
|
+
...popupResult,
|
|
1199
|
+
walletIdentityProof: parseWalletIdentityProof(
|
|
1200
|
+
popupResult.walletIdentityProof
|
|
1201
|
+
)
|
|
1202
|
+
} : popupResult;
|
|
1203
|
+
if (walletStore === "commit") {
|
|
1204
|
+
if (result.kind === "create") {
|
|
1205
|
+
activateConnectVault(result.vault, result.walletIdentityProof);
|
|
1206
|
+
} else if (result.kind === "signin") {
|
|
1207
|
+
activateConnectVault(result.vault, result.walletIdentityProof);
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
return result;
|
|
1211
|
+
}
|
|
1212
|
+
if (await immediateGetSupported()) {
|
|
1213
|
+
const probe = await immediatePasskeyLogin(config, onPhase, walletStore);
|
|
1214
|
+
if (probe.outcome === "signin") return { kind: "signin", ...probe.result };
|
|
1215
|
+
if (probe.outcome === "cancelled") return { kind: "cancelled" };
|
|
1216
|
+
if (!hasExplicitCreationChoice) {
|
|
1217
|
+
return { kind: "needs_create" };
|
|
1218
|
+
}
|
|
1219
|
+
const created = await createWallet({ ...config, onPhase });
|
|
1220
|
+
return { kind: "create", ...created };
|
|
1221
|
+
}
|
|
1222
|
+
if (getActiveHandle()) {
|
|
1223
|
+
const result = await passkeyLogin(config, onPhase);
|
|
1224
|
+
return { kind: "signin", ...result };
|
|
1225
|
+
}
|
|
1226
|
+
return { kind: "needs_choice" };
|
|
1227
|
+
}
|
|
1228
|
+
async function immediatePasskeyLogin(config, onPhase, walletStore = "commit") {
|
|
1229
|
+
const apiBase = resolveDexterApiBase(config.apiBase);
|
|
1230
|
+
onPhase?.("challenge");
|
|
1231
|
+
const options = await fetchLoginChallenge(apiBase);
|
|
1232
|
+
onPhase?.("passkey");
|
|
1233
|
+
let response;
|
|
1234
|
+
try {
|
|
1235
|
+
response = await immediateAuthentication(options);
|
|
1236
|
+
} catch (err) {
|
|
1237
|
+
if (classifyWebAuthnRejection(err)) {
|
|
1238
|
+
return { outcome: "no_credential" };
|
|
1239
|
+
}
|
|
1240
|
+
throw new ConnectError("webauthn_failed", err instanceof Error ? err.message : String(err));
|
|
1241
|
+
}
|
|
1242
|
+
onPhase?.("verifying");
|
|
1243
|
+
const result = await submitLogin(apiBase, response);
|
|
1244
|
+
if (walletStore === "commit") {
|
|
1245
|
+
activateConnectVault(result.vault, result.walletIdentityProof);
|
|
1246
|
+
}
|
|
1247
|
+
return { outcome: "signin", result };
|
|
1248
|
+
}
|
|
1575
1249
|
async function fetchLoginChallenge(apiBase) {
|
|
1576
1250
|
const res = await fetch(`${apiBase}${ANON_SIGN_BASE}/login-challenge`, {
|
|
1577
1251
|
method: "POST",
|
|
@@ -1627,213 +1301,20 @@ function normalizeSignInResult(value) {
|
|
|
1627
1301
|
};
|
|
1628
1302
|
}
|
|
1629
1303
|
|
|
1630
|
-
// src/identityTransition.ts
|
|
1631
|
-
function restoreWallet(previousWallet) {
|
|
1632
|
-
if (previousWallet) {
|
|
1633
|
-
return setActiveWallet(previousWallet);
|
|
1634
|
-
}
|
|
1635
|
-
return getActiveWallet() === null || disconnectActiveWallet();
|
|
1636
|
-
}
|
|
1637
|
-
async function connectDexterIdentity(config, onPhase) {
|
|
1638
|
-
const {
|
|
1639
|
-
installAccountSession,
|
|
1640
|
-
bindingFetch,
|
|
1641
|
-
...passkeyConfig
|
|
1642
|
-
} = config;
|
|
1643
|
-
const previousWallet = getActiveWallet();
|
|
1644
|
-
const result = await passkeyLogin(
|
|
1645
|
-
{ ...passkeyConfig, walletStore: "provisional" },
|
|
1646
|
-
onPhase
|
|
1647
|
-
);
|
|
1648
|
-
const bindingClient = createWalletAccountBindingClient({
|
|
1649
|
-
...passkeyConfig.apiBase ? { apiBase: passkeyConfig.apiBase } : {},
|
|
1650
|
-
...bindingFetch ? { fetch: bindingFetch } : {}
|
|
1651
|
-
});
|
|
1652
|
-
const resolution = await bindingClient.resolve({
|
|
1653
|
-
wallet: walletBindingCandidate(result.walletIdentityProof.token, {
|
|
1654
|
-
userHandle: result.vault.userHandle,
|
|
1655
|
-
vaultPda: result.vault.vaultPda
|
|
1656
|
-
}),
|
|
1657
|
-
account: accountBindingCandidate(result.session.accessToken)
|
|
1658
|
-
});
|
|
1659
|
-
if (!resolution.ok) {
|
|
1660
|
-
throw new ConnectError(
|
|
1661
|
-
resolution.reason === "expired" ? `identity_${resolution.subject}_expired` : resolution.reason === "offline" ? "identity_binding_offline" : resolution.code
|
|
1662
|
-
);
|
|
1663
|
-
}
|
|
1664
|
-
if (resolution.relation !== "bound") {
|
|
1665
|
-
throw new ConnectError("identity_binding_conflict");
|
|
1666
|
-
}
|
|
1667
|
-
if (!activateConnectVault(result.vault, result.walletIdentityProof)) {
|
|
1668
|
-
throw new ConnectError("wallet_activation_failed");
|
|
1669
|
-
}
|
|
1670
|
-
try {
|
|
1671
|
-
await installAccountSession(result.session);
|
|
1672
|
-
} catch (cause) {
|
|
1673
|
-
if (!restoreWallet(previousWallet)) {
|
|
1674
|
-
throw new ConnectError(
|
|
1675
|
-
"identity_rollback_failed",
|
|
1676
|
-
"The previous Wallet could not be restored after account installation failed."
|
|
1677
|
-
);
|
|
1678
|
-
}
|
|
1679
|
-
if (cause instanceof ConnectError) throw cause;
|
|
1680
|
-
throw new ConnectError(
|
|
1681
|
-
"account_session_install_failed",
|
|
1682
|
-
cause instanceof Error ? cause.message : String(cause)
|
|
1683
|
-
);
|
|
1684
|
-
}
|
|
1685
|
-
return result;
|
|
1686
|
-
}
|
|
1687
|
-
async function disconnectDexterIdentity(config) {
|
|
1688
|
-
const previousWallet = getActiveWallet();
|
|
1689
|
-
if (previousWallet && !disconnectActiveWallet()) {
|
|
1690
|
-
throw new ConnectError("identity_wallet_disconnect_failed");
|
|
1691
|
-
}
|
|
1692
|
-
try {
|
|
1693
|
-
await config.clearAccountSession();
|
|
1694
|
-
} catch (cause) {
|
|
1695
|
-
if (!restoreWallet(previousWallet)) {
|
|
1696
|
-
throw new ConnectError(
|
|
1697
|
-
"identity_rollback_failed",
|
|
1698
|
-
"The previous Wallet could not be restored after account sign-out failed."
|
|
1699
|
-
);
|
|
1700
|
-
}
|
|
1701
|
-
throw new ConnectError(
|
|
1702
|
-
"account_session_clear_failed",
|
|
1703
|
-
cause instanceof Error ? cause.message : String(cause)
|
|
1704
|
-
);
|
|
1705
|
-
}
|
|
1706
|
-
return true;
|
|
1707
|
-
}
|
|
1708
|
-
|
|
1709
|
-
// src/connectionContract.ts
|
|
1710
|
-
var CAPABILITIES = Object.freeze({
|
|
1711
|
-
identity: Object.freeze(["identity"]),
|
|
1712
|
-
wallet: Object.freeze(["identity", "wallet.read", "wallet.use"]),
|
|
1713
|
-
agent: Object.freeze(["identity", "wallet.read", "agent.authority"])
|
|
1714
|
-
});
|
|
1715
|
-
function stageFor(relation, intent) {
|
|
1716
|
-
if (relation.runtime.phase === "hydrating" || relation.runtime.phase === "checking") {
|
|
1717
|
-
return "checking";
|
|
1718
|
-
}
|
|
1719
|
-
if (relation.runtime.phase === "offline") return "offline";
|
|
1720
|
-
if (relation.runtime.phase === "error") return "error";
|
|
1721
|
-
if (relation.runtime.phase === "expired" || relation.relation === "conflict") {
|
|
1722
|
-
return "repair";
|
|
1723
|
-
}
|
|
1724
|
-
if (relation.relation === "none") return "connect";
|
|
1725
|
-
if (relation.relation === "bound") return "ready";
|
|
1726
|
-
if (relation.relation === "wallet_only" && intent === "wallet") return "ready";
|
|
1727
|
-
return "repair";
|
|
1728
|
-
}
|
|
1729
|
-
function primaryActionFor(stage) {
|
|
1730
|
-
if (stage === "connect") return "connect";
|
|
1731
|
-
if (stage === "ready") return "use_another_wallet";
|
|
1732
|
-
if (stage === "repair") return "repair";
|
|
1733
|
-
return "retry";
|
|
1734
|
-
}
|
|
1735
|
-
function createDexterControlModel(intent, relation) {
|
|
1736
|
-
const stage = stageFor(relation, intent);
|
|
1737
|
-
const ready = relation.runtime.phase === "ready";
|
|
1738
|
-
const bound = ready && relation.relation === "bound" && relation.privateAccountAccess;
|
|
1739
|
-
const ownerWalletReady = intent === "wallet" && ready && relation.walletPresent && (relation.relation === "wallet_only" || bound);
|
|
1740
|
-
return Object.freeze({
|
|
1741
|
-
intent,
|
|
1742
|
-
stage,
|
|
1743
|
-
primaryAction: primaryActionFor(stage),
|
|
1744
|
-
permissions: Object.freeze({
|
|
1745
|
-
capabilities: CAPABILITIES[intent],
|
|
1746
|
-
walletIdentityVisible: ready && relation.walletPresent && relation.relation !== "conflict",
|
|
1747
|
-
walletDataVisible: ownerWalletReady || bound && intent === "agent",
|
|
1748
|
-
ownerWalletUseEnabled: ownerWalletReady,
|
|
1749
|
-
accountContentVisible: bound,
|
|
1750
|
-
agentAuthorityVisible: bound && intent === "agent"
|
|
1751
|
-
})
|
|
1752
|
-
});
|
|
1753
|
-
}
|
|
1754
|
-
|
|
1755
|
-
// src/phase.ts
|
|
1756
|
-
var PHASE_LABEL = {
|
|
1757
|
-
challenge: "Preparing\u2026",
|
|
1758
|
-
passkey: "Waiting for your passkey\u2026",
|
|
1759
|
-
verifying: "Verifying\u2026",
|
|
1760
|
-
finalizing: "Finishing\u2026"
|
|
1761
|
-
};
|
|
1762
|
-
function ceremonyPhaseLabel(phase) {
|
|
1763
|
-
return PHASE_LABEL[phase];
|
|
1764
|
-
}
|
|
1765
|
-
|
|
1766
|
-
// src/signals.ts
|
|
1767
|
-
function pkc() {
|
|
1768
|
-
if (typeof window === "undefined") return null;
|
|
1769
|
-
const g = globalThis.PublicKeyCredential;
|
|
1770
|
-
return g ?? null;
|
|
1771
|
-
}
|
|
1772
|
-
function defaultRpId() {
|
|
1773
|
-
return typeof window !== "undefined" ? window.location.hostname : "";
|
|
1774
|
-
}
|
|
1775
|
-
function passkeySignalSupport() {
|
|
1776
|
-
const p = pkc();
|
|
1777
|
-
return {
|
|
1778
|
-
rename: typeof p?.signalCurrentUserDetails === "function",
|
|
1779
|
-
prune: typeof p?.signalUnknownCredential === "function",
|
|
1780
|
-
syncAccepted: typeof p?.signalAllAcceptedCredentials === "function"
|
|
1781
|
-
};
|
|
1782
|
-
}
|
|
1783
|
-
async function renamePasskey(args) {
|
|
1784
|
-
const p = pkc();
|
|
1785
|
-
if (typeof p?.signalCurrentUserDetails !== "function") return false;
|
|
1786
|
-
try {
|
|
1787
|
-
await p.signalCurrentUserDetails({
|
|
1788
|
-
rpId: args.rpId ?? defaultRpId(),
|
|
1789
|
-
userId: args.userId,
|
|
1790
|
-
name: args.name,
|
|
1791
|
-
displayName: args.displayName ?? args.name
|
|
1792
|
-
});
|
|
1793
|
-
return true;
|
|
1794
|
-
} catch {
|
|
1795
|
-
return false;
|
|
1796
|
-
}
|
|
1797
|
-
}
|
|
1798
|
-
async function prunePasskey(args) {
|
|
1799
|
-
const p = pkc();
|
|
1800
|
-
if (typeof p?.signalUnknownCredential !== "function") return false;
|
|
1801
|
-
try {
|
|
1802
|
-
await p.signalUnknownCredential({
|
|
1803
|
-
rpId: args.rpId ?? defaultRpId(),
|
|
1804
|
-
credentialId: args.credentialId
|
|
1805
|
-
});
|
|
1806
|
-
return true;
|
|
1807
|
-
} catch {
|
|
1808
|
-
return false;
|
|
1809
|
-
}
|
|
1810
|
-
}
|
|
1811
|
-
async function syncAcceptedPasskeys(args) {
|
|
1812
|
-
const p = pkc();
|
|
1813
|
-
if (typeof p?.signalAllAcceptedCredentials !== "function") return false;
|
|
1814
|
-
try {
|
|
1815
|
-
await p.signalAllAcceptedCredentials({
|
|
1816
|
-
rpId: args.rpId ?? defaultRpId(),
|
|
1817
|
-
userId: args.userId,
|
|
1818
|
-
allAcceptedCredentialIds: args.acceptedCredentialIds
|
|
1819
|
-
});
|
|
1820
|
-
return true;
|
|
1821
|
-
} catch {
|
|
1822
|
-
return false;
|
|
1823
|
-
}
|
|
1824
|
-
}
|
|
1825
|
-
|
|
1826
1304
|
export {
|
|
1827
1305
|
resolveWalletStoreMode,
|
|
1306
|
+
resolveAgentDelegationMode,
|
|
1828
1307
|
ConnectError,
|
|
1829
1308
|
parseWalletIdentityProof,
|
|
1830
1309
|
readErrorCode,
|
|
1310
|
+
DEXTER_API_BASE,
|
|
1831
1311
|
resolveDexterApiBase,
|
|
1832
1312
|
resolveDexterRpId,
|
|
1833
1313
|
bytesEqual,
|
|
1834
1314
|
shouldUsePopup,
|
|
1835
1315
|
openCeremonyPopup,
|
|
1836
1316
|
getActiveHandle,
|
|
1317
|
+
getActiveWallet,
|
|
1837
1318
|
setActiveWallet,
|
|
1838
1319
|
setActiveHandle,
|
|
1839
1320
|
disconnectActiveWallet,
|
|
@@ -1850,6 +1331,7 @@ export {
|
|
|
1850
1331
|
WALLET_PROOF_SESSION_STORAGE_PREFIX,
|
|
1851
1332
|
createWalletProofSessionStore,
|
|
1852
1333
|
walletProofSessionStore,
|
|
1334
|
+
activateConnectVault,
|
|
1853
1335
|
activateRecoveredVault,
|
|
1854
1336
|
SESSION_TTL_30D,
|
|
1855
1337
|
usdToAtomic,
|
|
@@ -1859,14 +1341,6 @@ export {
|
|
|
1859
1341
|
primeImmediateSupport,
|
|
1860
1342
|
immediateAuthentication,
|
|
1861
1343
|
classifyWebAuthnRejection,
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
connectDexterIdentity,
|
|
1865
|
-
disconnectDexterIdentity,
|
|
1866
|
-
createDexterControlModel,
|
|
1867
|
-
ceremonyPhaseLabel,
|
|
1868
|
-
passkeySignalSupport,
|
|
1869
|
-
renamePasskey,
|
|
1870
|
-
prunePasskey,
|
|
1871
|
-
syncAcceptedPasskeys
|
|
1344
|
+
passkeyLogin,
|
|
1345
|
+
continueWithDexter
|
|
1872
1346
|
};
|