passkey-kit 0.18.3 → 0.19.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.
@@ -0,0 +1,263 @@
1
+ /**
2
+ * Legacy (pre-1.0) wallet upgrade helpers.
3
+ *
4
+ * The kit cannot connect to a pre-1.0 wallet (`connectWallet` throws
5
+ * {@link LegacyWalletError}), but it can still craft the one transaction such
6
+ * a wallet needs: an in-place `update_contract_code` to the legacy-line build
7
+ * that reads both pre-1.0 storage layouts, followed for the bare-layout cohort
8
+ * by a `migrate_signers` call. This module builds those transactions from the
9
+ * wallet's actual on-chain state, so an application only has to sign and
10
+ * submit. See docs/legacy-wallet-upgrade.md for the full procedure.
11
+ *
12
+ * @packageDocumentation
13
+ */
14
+ import { Address, xdr } from "@stellar/stellar-sdk";
15
+ import { AssembledTransaction } from "@stellar/stellar-sdk/contract";
16
+ import { KNOWN_VULNERABLE_WALLET_WASM_HASHES, LEGACY_UPGRADE_TARGET_WASM_HASH, LEGACY_WALLET_UPGRADE_GUIDE_URL, LEGACY_WALLET_WASM_HASHES, } from "../constants.js";
17
+ import { PasskeyKitErrorCode, SigningError, ValidationError } from "../errors.js";
18
+ import { signerKeyToScVal } from "./auth-payload.js";
19
+ import { assertAdminRootMatchesHostFunction, signAuthEntry, } from "./tx-ops.js";
20
+ import { toContractSignerKey } from "./wallet-ops.js";
21
+ /**
22
+ * Pre-1.0 wallets that store signers in the pre-`6a27d48` (2024-12-13)
23
+ * layout. Every later build fails to decode them, which is why only the
24
+ * legacy-line target is a safe upgrade for them and why `migrate_signers`
25
+ * exists.
26
+ */
27
+ export const BARE_LAYOUT_WALLET_WASM_HASHES = [
28
+ "0c0a264d4cc0b3e79b8533e2a2e1f0ed21501a5a3f9f2455d2f18c232940b865",
29
+ "19868df3653d427cafa1c30bdb6cec1ca5c8c815eeabab8a8bae6d83efb1fedd",
30
+ ];
31
+ /** Classify a code hash without touching the network. */
32
+ export function classifyWasmHash(wasmHash, acceptedWasmHashes) {
33
+ const hash = wasmHash.toLowerCase();
34
+ if (acceptedWasmHashes.includes(hash)) {
35
+ return { status: "current", cohort: null };
36
+ }
37
+ if (KNOWN_VULNERABLE_WALLET_WASM_HASHES.includes(hash)) {
38
+ return {
39
+ status: "vulnerable",
40
+ cohort: BARE_LAYOUT_WALLET_WASM_HASHES.includes(hash) ? "bare" : "wrapped",
41
+ };
42
+ }
43
+ if (LEGACY_WALLET_WASM_HASHES.includes(hash)) {
44
+ return { status: "legacy", cohort: "wrapped" };
45
+ }
46
+ return { status: "unknown", cohort: null };
47
+ }
48
+ function instanceLedgerKey(contractId) {
49
+ return xdr.LedgerKey.contractData(new xdr.LedgerKeyContractData({
50
+ contract: Address.fromString(contractId).toScAddress(),
51
+ key: xdr.ScVal.scvLedgerKeyContractInstance(),
52
+ durability: xdr.ContractDataDurability.persistent(),
53
+ }));
54
+ }
55
+ function codeLedgerKey(wasmHash) {
56
+ return xdr.LedgerKey.contractCode(new xdr.LedgerKeyContractCode({ hash: Buffer.from(wasmHash, "hex") }));
57
+ }
58
+ /**
59
+ * Read a wallet's code hash and the liveness of the entries an upgrade
60
+ * touches, and say what to do.
61
+ */
62
+ export async function inspectLegacyWallet(deps, contractId) {
63
+ const wasmHash = (await deps.contractWasmHash(contractId)).toLowerCase();
64
+ const { status, cohort } = classifyWasmHash(wasmHash, deps.acceptedWasmHashes);
65
+ const upgradeTarget = LEGACY_UPGRADE_TARGET_WASM_HASH;
66
+ const keys = [instanceLedgerKey(contractId), codeLedgerKey(wasmHash), codeLedgerKey(upgradeTarget)];
67
+ const response = await deps.rpc.getLedgerEntries(...keys);
68
+ const latest = response.latestLedger;
69
+ const liveByKey = new Map();
70
+ for (const entry of response.entries) {
71
+ const liveUntil = entry.liveUntilLedgerSeq;
72
+ // An entry is live through its liveUntil ledger inclusive.
73
+ liveByKey.set(entry.key.toXDR("base64"), liveUntil !== undefined && liveUntil >= latest);
74
+ }
75
+ const isLive = (key) => liveByKey.get(key.toXDR("base64")) === true;
76
+ const archived = {
77
+ instance: !isLive(keys[0]),
78
+ code: !isLive(keys[1]),
79
+ target: !isLive(keys[2]),
80
+ };
81
+ const upgradeRequired = status === "vulnerable";
82
+ const migrateRequired = cohort === "bare";
83
+ let recommendation;
84
+ switch (status) {
85
+ case "vulnerable":
86
+ recommendation =
87
+ `This wallet runs known-vulnerable code ${wasmHash.slice(0, 8)}…; anyone can overwrite ` +
88
+ `its signers. Upgrade it in place now: ` +
89
+ (archived.instance || archived.code || archived.target
90
+ ? `restore the archived entries (${[
91
+ archived.instance && "instance",
92
+ archived.code && "current code",
93
+ archived.target && "target code",
94
+ ]
95
+ .filter(Boolean)
96
+ .join(", ")}), then `
97
+ : "") +
98
+ `call update_contract_code(${upgradeTarget.slice(0, 8)}…) authorized by an existing signer` +
99
+ (migrateRequired
100
+ ? `, then call migrate_signers with every signer key (this wallet stores the pre-6a27d48 layout)`
101
+ : "") +
102
+ `. Or move its funds out. Guide: ${LEGACY_WALLET_UPGRADE_GUIDE_URL}`;
103
+ break;
104
+ case "legacy":
105
+ recommendation =
106
+ `This wallet runs patched pre-1.0 code ${wasmHash.slice(0, 8)}…. It is not vulnerable; ` +
107
+ `operate it with the passkey-kit 0.10.20–0.12.x line. Guide: ${LEGACY_WALLET_UPGRADE_GUIDE_URL}`;
108
+ break;
109
+ case "current":
110
+ recommendation = "This wallet runs accepted current code. No upgrade is needed.";
111
+ break;
112
+ default:
113
+ recommendation =
114
+ `This wallet runs code ${wasmHash.slice(0, 8)}… that this kit does not recognize. ` +
115
+ `Verify its provenance before acting.`;
116
+ }
117
+ return {
118
+ contractId,
119
+ wasmHash,
120
+ status,
121
+ cohort,
122
+ upgradeTarget,
123
+ upgradeRequired,
124
+ migrateRequired,
125
+ archived,
126
+ guideUrl: LEGACY_WALLET_UPGRADE_GUIDE_URL,
127
+ recommendation,
128
+ };
129
+ }
130
+ /**
131
+ * Build `wallet.update_contract_code(target)` for a legacy wallet.
132
+ *
133
+ * The transaction's single auth entry is the wallet's own, to be signed by an
134
+ * existing signer through {@link signLegacyUpgradeTx}. The envelope source is
135
+ * the SDK's placeholder account, so submit through `PasskeyServer.send` (a
136
+ * relayer supplies the source and fees) or rebuild with your own funded source.
137
+ */
138
+ export function buildLegacyUpgradeTx(deps, contractId, target = LEGACY_UPGRADE_TARGET_WASM_HASH) {
139
+ if (!/^[0-9a-f]{64}$/i.test(target)) {
140
+ throw new ValidationError("upgrade target must be a 32-byte hex WASM hash", PasskeyKitErrorCode.INVALID_INPUT, { target });
141
+ }
142
+ return AssembledTransaction.build({
143
+ method: "update_contract_code",
144
+ args: [xdr.ScVal.scvBytes(Buffer.from(target, "hex"))],
145
+ contractId,
146
+ rpcUrl: deps.rpcUrl,
147
+ networkPassphrase: deps.networkPassphrase,
148
+ timeoutInSeconds: deps.timeoutInSeconds,
149
+ parseResultXdr: () => null,
150
+ });
151
+ }
152
+ /**
153
+ * Build `wallet.migrate_signers(keys)` for a wallet already on the legacy-line
154
+ * target. The call needs no wallet authorization (it is a value-preserving
155
+ * re-encoding), so any funded source can submit it. Returns the number of
156
+ * entries rewritten when simulated or executed.
157
+ *
158
+ * Soroban has no storage iteration, so the caller supplies the keys: the
159
+ * hosted passkey indexer (`MercuryIndexer.getSigners` /
160
+ * `PasskeyServer.getSigners`) lists every signer a wallet has ever held.
161
+ */
162
+ export function buildLegacyMigrateTx(deps, contractId, signerKeys) {
163
+ if (signerKeys.length === 0) {
164
+ throw new ValidationError("migrate_signers needs at least one signer key", PasskeyKitErrorCode.INVALID_INPUT, { contractId });
165
+ }
166
+ const keys = signerKeys.map((key) => signerKeyToScVal(deps.spec, toContractSignerKey(key)));
167
+ return AssembledTransaction.build({
168
+ method: "migrate_signers",
169
+ args: [xdr.ScVal.scvVec(keys)],
170
+ contractId,
171
+ rpcUrl: deps.rpcUrl,
172
+ networkPassphrase: deps.networkPassphrase,
173
+ timeoutInSeconds: deps.timeoutInSeconds,
174
+ parseResultXdr: (value) => value.u32(),
175
+ });
176
+ }
177
+ /**
178
+ * Sign a legacy wallet's `update_contract_code` auth entry with one of its
179
+ * existing signers, without a connected wallet.
180
+ *
181
+ * Passkey and Ed25519 signature entries encode identically on every pre-1.0
182
+ * build, and the signature covers the V2 address-bound payload the host
183
+ * presents to any custom account, so the kit's normal signers work here. The
184
+ * entry root is pinned to the transaction's own host function, as for every
185
+ * wallet-admin write.
186
+ */
187
+ export async function signLegacyUpgradeTx(deps, tx, signer, options) {
188
+ const built = tx.built;
189
+ const topOp = built?.operations[0];
190
+ const topFunc = topOp?.type === "invokeHostFunction"
191
+ ? topOp.func
192
+ : undefined;
193
+ if (!topFunc) {
194
+ throw new ValidationError("the transaction has no invoke-host-function operation to sign", PasskeyKitErrorCode.INVALID_INPUT, { contractId: deps.contractId });
195
+ }
196
+ // Resolve the expiration once here (the kit's own ledger-based default) so
197
+ // the SDK does not fetch it, and pass the same value to every entry.
198
+ const expiration = options?.expiration ?? (await deps.calculateExpiration());
199
+ await tx.signAuthEntries({
200
+ address: deps.contractId,
201
+ expiration,
202
+ authorizeEntry: async (entry) => {
203
+ const clone = xdr.SorobanAuthorizationEntry.fromXDR(entry.toXDR());
204
+ assertRootIsExactlyThisCall(clone, deps.contractId, topFunc);
205
+ assertUpgradeTarget(clone, options?.expectedTarget ?? LEGACY_UPGRADE_TARGET_WASM_HASH);
206
+ assertAdminRootMatchesHostFunction(clone, deps.contractId, topFunc);
207
+ const { expectedTarget: _expectedTarget, ...signOptions } = options ?? {};
208
+ return signAuthEntry(deps, clone, signer, {
209
+ ...signOptions,
210
+ expiration,
211
+ allowWalletReentry: true,
212
+ });
213
+ },
214
+ });
215
+ return tx;
216
+ }
217
+ /**
218
+ * The legacy upgrade signs exactly one thing: this wallet's own
219
+ * `update_contract_code` (or `migrate_signers`) as the transaction's
220
+ * top-level call, with no sub-invocations. Anything else is refused before
221
+ * hashing, so a hostile transaction cannot borrow this signing path.
222
+ */
223
+ function assertRootIsExactlyThisCall(entry, contractId, topFunc) {
224
+ const root = entry.rootInvocation();
225
+ const fn = root.function();
226
+ const expected = topFunc.switch().name === "hostFunctionTypeInvokeContract"
227
+ ? topFunc.invokeContract()
228
+ : undefined;
229
+ const actual = fn.switch().name === "sorobanAuthorizedFunctionTypeContractFn" ? fn.contractFn() : undefined;
230
+ const name = actual?.functionName().toString();
231
+ const ok = expected !== undefined &&
232
+ actual !== undefined &&
233
+ root.subInvocations().length === 0 &&
234
+ (name === "update_contract_code" || name === "migrate_signers") &&
235
+ Address.fromScAddress(actual.contractAddress()).toString() === contractId &&
236
+ actual.toXDR("base64") === expected.toXDR("base64");
237
+ if (!ok) {
238
+ throw new SigningError(`Refusing to sign: the auth entry must root at ${contractId}'s own top-level ` +
239
+ `update_contract_code / migrate_signers call with no sub-invocations` +
240
+ (name ? ` (got ${name})` : ""), PasskeyKitErrorCode.SIGNING_FAILED, { contractId });
241
+ }
242
+ }
243
+ /**
244
+ * An `update_contract_code` root may only carry the expected target hash.
245
+ * `migrate_signers` and any other call pass through unchanged.
246
+ */
247
+ function assertUpgradeTarget(entry, expectedTarget) {
248
+ const fn = entry.rootInvocation().function();
249
+ if (fn.switch().name !== "sorobanAuthorizedFunctionTypeContractFn") {
250
+ return;
251
+ }
252
+ const call = fn.contractFn();
253
+ if (call.functionName().toString() !== "update_contract_code") {
254
+ return;
255
+ }
256
+ const arg = call.args()[0];
257
+ const actual = arg && arg.switch().name === "scvBytes" ? Buffer.from(arg.bytes()).toString("hex") : "";
258
+ if (actual !== expectedTarget.toLowerCase()) {
259
+ throw new SigningError(`Refusing to sign update_contract_code(${actual.slice(0, 8) || "?"}…): the only ` +
260
+ `accepted upgrade target is ${expectedTarget.slice(0, 8)}…`, PasskeyKitErrorCode.SIGNING_FAILED, { actual, expectedTarget });
261
+ }
262
+ }
263
+ //# sourceMappingURL=legacy-ops.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"legacy-ops.js","sourceRoot":"","sources":["../../src/kit/legacy-ops.ts"],"names":[],"mappings":"AAAA;;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AC,cAAc,EAAE,CAAC,QAAQ,EAAE,CAAC;IAC7C,IAAI,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,KAAK,yCAAyC,EAAE,CAAC;QACnE,OAAO;IACT,CAAC;IACD,MAAM,IAAI,GAAG,EAAE,CAAC,UAAU,EAAE,CAAC;IAC7B,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC,QAAQ,EAAE,KAAK,sBAAsB,EAAE,CAAC;QAC9D,OAAO;IACT,CAAC;IACD,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IAC3B,MAAM,MAAM,GACV,GAAG,IAAI,GAAG,CAAC,MAAM,EAAE,CAAC,IAAI,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAC1F,IAAI,MAAM,KAAK,cAAc,CAAC,WAAW,EAAE,EAAE,CAAC;QAC5C,MAAM,IAAI,YAAY,CACpB,yCAAyC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,GAAG,eAAe;YAC/E,8BAA8B,cAAc,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,EAC7D,mBAAmB,CAAC,cAAc,EAClC,EAAE,MAAM,EAAE,cAAc,EAAE,CAC3B,CAAC;IACJ,CAAC;AACH,CAAC"}
package/dist/kit.d.ts CHANGED
@@ -22,6 +22,7 @@ import { type Signer } from "./signers.js";
22
22
  import type { WebAuthnClient } from "./kit/webauthn-ops.js";
23
23
  import type { CreatedPasskey } from "./kit/webauthn-ops.js";
24
24
  import type { SignOptions } from "./kit/tx-ops.js";
25
+ import { type LegacyWalletInspection } from "./kit/legacy-ops.js";
25
26
  import { type PolicySignerTxOptions, type WalletTx } from "./kit/wallet-ops.js";
26
27
  import type { WalletCandidateLookup } from "./indexer/types.js";
27
28
  import { type VerifiedWalletBirth } from "./kit/birth-verification.js";
@@ -97,6 +98,8 @@ export declare class PasskeyKit {
97
98
  readonly acceptedWasmHashes: readonly string[];
98
99
  /** Accepted immutable birth code identities, lowercase hex. Never empty. */
99
100
  readonly acceptedBirthWasmHashes: readonly string[];
101
+ /** Funded key used only for footprint restores, when configured. */
102
+ private readonly restoreKeypair?;
100
103
  /** Full-history source for immutable wallet-birth verification. */
101
104
  readonly history?: Horizon.Server;
102
105
  readonly rpId?: string;
@@ -143,6 +146,13 @@ export declare class PasskeyKit {
143
146
  * @throws {WalletOwnershipError} If the keyId is not a signer on the wallet.
144
147
  */
145
148
  connectWallet(options?: ConnectOptions): Promise<ConnectWalletResult>;
149
+ /**
150
+ * Reject a wallet whose current code is a pre-1.0 build, with guidance.
151
+ * Known-vulnerable builds get the upgrade instructions; patched legacy
152
+ * builds get the "use the 0.10.20–0.12.x kit" instruction. Accepted hashes
153
+ * are never legacy, so an integrator cannot opt into a vulnerable build.
154
+ */
155
+ private assertNotLegacyWallet;
146
156
  private assertWalletWasmHash;
147
157
  private contractWasmHash;
148
158
  /** Create the address-bound proof required for a Secp256r1 signer write. */
@@ -154,6 +164,49 @@ export declare class PasskeyKit {
154
164
  private assertWebAuthnVerificationConfig;
155
165
  /** Disconnect the current wallet. */
156
166
  disconnect(): void;
167
+ /**
168
+ * Inspect a wallet this kit cannot connect to and say what it needs:
169
+ * its code status (vulnerable / legacy / current / unknown), its storage
170
+ * cohort, which ledger entries are archived, and a plain recommendation.
171
+ * Read-only.
172
+ */
173
+ inspectLegacyWallet(contractId: string): Promise<LegacyWalletInspection>;
174
+ private legacyTxDeps;
175
+ /**
176
+ * Restore archived entries a simulated transaction needs, using the
177
+ * configured `restoreSource`, and rebuild. Throws with guidance when no
178
+ * restore source is configured.
179
+ */
180
+ private withRestore;
181
+ /**
182
+ * Build the in-place upgrade for a pre-1.0 wallet:
183
+ * `update_contract_code(<legacy-line target>)`, authorized by the wallet.
184
+ * Refuses wallets that are not on a known pre-1.0 build. Restores archived
185
+ * entries first when `restoreSource` is configured.
186
+ *
187
+ * Sign it with {@link signLegacyUpgradeTx} and submit through
188
+ * `PasskeyServer.send` (or your own funded source).
189
+ */
190
+ buildLegacyUpgradeTx(contractId: string): Promise<{
191
+ inspection: LegacyWalletInspection;
192
+ tx: AssembledTransaction<null>;
193
+ }>;
194
+ /**
195
+ * Build `migrate_signers(keys)` for a wallet already upgraded to the
196
+ * legacy-line target. Needs no wallet authorization; any funded source can
197
+ * submit it. Get the keys from `PasskeyServer.getSigners` /
198
+ * `MercuryIndexer.getSigners`.
199
+ */
200
+ buildLegacyMigrateTx(contractId: string, signerKeys: readonly SignerKey[]): Promise<AssembledTransaction<number>>;
201
+ /**
202
+ * Sign a legacy wallet's upgrade transaction with one of its existing
203
+ * signers, without connecting. Defaults to a discoverable passkey prompt;
204
+ * pass `new PasskeySigner(keyId)` to require a specific credential, or an
205
+ * `Ed25519Signer`.
206
+ */
207
+ signLegacyUpgradeTx<T>(tx: AssembledTransaction<T>, contractId: string, signer?: Signer, options?: Omit<SignOptions, "allowWalletReentry"> & {
208
+ expectedTarget?: string;
209
+ }): Promise<AssembledTransaction<T>>;
157
210
  /** Sign a single auth entry (defaults to the connected passkey signer). */
158
211
  signAuthEntry(entry: xdr.SorobanAuthorizationEntry, signer?: Signer, options?: SignOptions): Promise<xdr.SorobanAuthorizationEntry>;
159
212
  /** Sign an assembled transaction's wallet auth entries. */
package/dist/kit.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"kit.d.ts","sourceRoot":"","sources":["../src/kit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,OAAO,EAAqB,GAAG,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAO,MAAM,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAIL,KAAK,8BAA8B,EACpC,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EACV,oB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OAAO,CAAC,QAAQ,CAAC;IAwDpB;;;OAGG;IACH,eAAe,CACb,KAAK,EAAE,MAAM,GAAG,UAAU,EAC1B,MAAM,EAAE,YAAY,EACpB,KAAK,EAAE,WAAW,EAClB,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,QAAQ,CAAC;IAGpB,UAAU,CACR,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,YAAY,EACpB,KAAK,EAAE,WAAW,EAClB,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,QAAQ,CAAC;IAGpB,aAAa,CACX,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,YAAY,EACpB,KAAK,EAAE,WAAW,EAClB,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,QAAQ,CAAC;IAGpB;;;;OAIG;IACH,SAAS,CACP,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,YAAY,EACpB,KAAK,EAAE,WAAW,EAClB,UAAU,CAAC,EAAE,MAAM,EACnB,OAAO,CAAC,EAAE,qBAAqB,GAC9B,OAAO,CAAC,QAAQ,CAAC;IAGpB,YAAY,CACV,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,YAAY,EACpB,KAAK,EAAE,WAAW,EAClB,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,QAAQ,CAAC;IAGpB,MAAM,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,QAAQ,CAAC;IAI/C,8EAA8E;IAC9E,OAAO,CAAC,WAAW,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO,CAAC,QAAQ,CAAC;IAI5D,yEAAyE;IACzE,SAAS,CAAC,SAAS,EAAE,SAAS;IAI9B,4CAA4C;IAC5C,aAAa,IAAI,aAAa;CAM/B"}
package/dist/kit.js CHANGED
@@ -17,14 +17,16 @@ import { startAuthentication, startRegistration, } from "@simplewebauthn/browser
17
17
  import { Client as PasskeyClient, } from "passkey-kit-sdk";
18
18
  import base64url from "./base64url.js";
19
19
  import { SignerKey, SignerStore, } from "./types.js";
20
- import { ConfigurationError, PasskeyKitError, PasskeyKitErrorCode, WalletNotConnectedError, WalletOwnershipError, WalletAmbiguousError, } from "./errors.js";
20
+ import { ConfigurationError, PasskeyKitError, ValidationError, PasskeyKitErrorCode, WalletNotConnectedError, WalletOwnershipError, WalletAmbiguousError, LegacyWalletError, } from "./errors.js";
21
21
  import { PasskeyEventEmitter } from "./events.js";
22
22
  import { isDefaultDeployer } from "./utils.js";
23
- import { DEFAULT_TIMEOUT_SECONDS } from "./constants.js";
23
+ import { DEFAULT_TIMEOUT_SECONDS, KNOWN_VULNERABLE_WALLET_WASM_HASHES, LEGACY_UPGRADE_TARGET_WASM_HASH, LEGACY_WALLET_UPGRADE_GUIDE_URL, LEGACY_WALLET_WASM_HASHES, } from "./constants.js";
24
24
  import { PasskeySigner } from "./signers.js";
25
25
  import { calculateExpiration } from "./kit/tx-ops.js";
26
26
  import { CredentialManager, SignerManager, SubmissionManager, } from "./managers/index.js";
27
27
  import { resolveDeployer } from "./kit/deploy-ops.js";
28
+ import { buildLegacyMigrateTx, buildLegacyUpgradeTx, inspectLegacyWallet, signLegacyUpgradeTx, } from "./kit/legacy-ops.js";
29
+ import { restoreFootprint } from "./kit/tx-ops.js";
28
30
  import { buildSecp256r1Signer, } from "./kit/wallet-ops.js";
29
31
  import { verifyWalletBirth, } from "./kit/birth-verification.js";
30
32
  import { bindingChallenge, verifyBindingRecord, verifyFreshAssertion, verifyStoredProof, } from "./kit/webauthn-verify.js";
@@ -44,6 +46,8 @@ export class PasskeyKit {
44
46
  acceptedWasmHashes;
45
47
  /** Accepted immutable birth code identities, lowercase hex. Never empty. */
46
48
  acceptedBirthWasmHashes;
49
+ /** Funded key used only for footprint restores, when configured. */
50
+ restoreKeypair;
47
51
  /** Full-history source for immutable wallet-birth verification. */
48
52
  history;
49
53
  rpId;
@@ -70,6 +74,18 @@ export class PasskeyKit {
70
74
  if (!config.walletWasmHash) {
71
75
  throw new ConfigurationError("walletWasmHash is required", PasskeyKitErrorCode.MISSING_CONFIG);
72
76
  }
77
+ for (const configured of [
78
+ config.walletWasmHash,
79
+ ...(config.acceptedWasmHashes ?? []),
80
+ ...(config.acceptedBirthWasmHashes ?? []),
81
+ ]) {
82
+ if (KNOWN_VULNERABLE_WALLET_WASM_HASHES.includes(configured.toLowerCase())) {
83
+ throw new ConfigurationError(`walletWasmHash ${configured.slice(0, 8)}… is a known-vulnerable legacy build ` +
84
+ `(update_signer has no authorization check). Do not deploy from it or accept it. ` +
85
+ `Existing wallets on it must upgrade to ${LEGACY_UPGRADE_TARGET_WASM_HASH}; ` +
86
+ `see ${LEGACY_WALLET_UPGRADE_GUIDE_URL}`, PasskeyKitErrorCode.INVALID_CONFIG, { wasmHash: configured.toLowerCase() });
87
+ }
88
+ }
73
89
  this.rpc = new Server(config.rpcUrl);
74
90
  this.rpcUrl = config.rpcUrl;
75
91
  this.networkPassphrase = config.networkPassphrase;
@@ -130,6 +146,7 @@ export class PasskeyKit {
130
146
  getSignerContext: () => this.signerContext(),
131
147
  calculateExpiration: () => calculateExpiration({ rpc: this.rpc, timeoutInSeconds: this.timeoutInSeconds }),
132
148
  });
149
+ this.restoreKeypair = restoreKeypair;
133
150
  this.submissionManager = new SubmissionManager({
134
151
  rpc: this.rpc,
135
152
  rpcUrl: config.rpcUrl,
@@ -299,6 +316,9 @@ export class PasskeyKit {
299
316
  // The last definitive rejection, rethrown verbatim when nothing verifies so
300
317
  // its context (e.g. the rejected wasm hash) is not replaced by a summary.
301
318
  let lastMismatch;
319
+ // A candidate on pre-1.0 code is a definitive answer with its own guidance.
320
+ // It is reported in preference to any generic mismatch when nothing verifies.
321
+ let legacyMismatch;
302
322
  for (const candidate of candidates) {
303
323
  const wallet = new PasskeyClient({
304
324
  contractId: candidate.contractId,
@@ -308,6 +328,10 @@ export class PasskeyKit {
308
328
  this.wallet = wallet;
309
329
  this.keyId = keyIdBase64;
310
330
  try {
331
+ // Before birth verification: a legacy wallet fails that check for
332
+ // reasons that would hide the real problem (no constructor birth, an
333
+ // unaccepted hash). Name the legacy code and the upgrade path instead.
334
+ await this.assertNotLegacyWallet(candidate.contractId);
311
335
  const birth = await verifyWalletBirth({
312
336
  rpc: this.rpc,
313
337
  history: this.history,
@@ -358,6 +382,10 @@ export class PasskeyKit {
358
382
  catch (err) {
359
383
  this.wallet = undefined;
360
384
  this.keyId = undefined;
385
+ if (err instanceof LegacyWalletError) {
386
+ legacyMismatch = err;
387
+ continue;
388
+ }
361
389
  if (err instanceof WalletOwnershipError) {
362
390
  lastMismatch = err;
363
391
  continue;
@@ -368,7 +396,8 @@ export class PasskeyKit {
368
396
  this.wallet = undefined;
369
397
  this.keyId = undefined;
370
398
  if (verified.size === 0) {
371
- throw (lastMismatch ??
399
+ throw (legacyMismatch ??
400
+ lastMismatch ??
372
401
  new WalletOwnershipError("The passkey is not a signer on any resolved wallet", {
373
402
  candidates: candidates.map(({ contractId }) => contractId),
374
403
  keyId: keyIdBase64,
@@ -392,6 +421,26 @@ export class PasskeyKit {
392
421
  this.events.emit("walletConnected", { contractId, keyId: keyIdBase64 });
393
422
  return { rawResponse, keyId: keyIdBuffer, keyIdBase64, contractId };
394
423
  }
424
+ /**
425
+ * Reject a wallet whose current code is a pre-1.0 build, with guidance.
426
+ * Known-vulnerable builds get the upgrade instructions; patched legacy
427
+ * builds get the "use the 0.10.20–0.12.x kit" instruction. Accepted hashes
428
+ * are never legacy, so an integrator cannot opt into a vulnerable build.
429
+ */
430
+ async assertNotLegacyWallet(contractId) {
431
+ const wasmHash = await this.contractWasmHash(contractId);
432
+ const vulnerable = KNOWN_VULNERABLE_WALLET_WASM_HASHES.includes(wasmHash);
433
+ if (!vulnerable && !LEGACY_WALLET_WASM_HASHES.includes(wasmHash)) {
434
+ return;
435
+ }
436
+ throw new LegacyWalletError({
437
+ contractId,
438
+ wasmHash,
439
+ vulnerable,
440
+ upgradeTarget: LEGACY_UPGRADE_TARGET_WASM_HASH,
441
+ guideUrl: LEGACY_WALLET_UPGRADE_GUIDE_URL,
442
+ });
443
+ }
395
444
  async assertWalletWasmHash(contractId) {
396
445
  const wasmHash = await this.contractWasmHash(contractId);
397
446
  if (!this.acceptedWasmHashes.includes(wasmHash)) {
@@ -512,6 +561,102 @@ export class PasskeyKit {
512
561
  this.events.emit("walletDisconnected", { contractId });
513
562
  }
514
563
  }
564
+ // -- Legacy (pre-1.0) wallet upgrade ------------------------------------------
565
+ /**
566
+ * Inspect a wallet this kit cannot connect to and say what it needs:
567
+ * its code status (vulnerable / legacy / current / unknown), its storage
568
+ * cohort, which ledger entries are archived, and a plain recommendation.
569
+ * Read-only.
570
+ */
571
+ inspectLegacyWallet(contractId) {
572
+ return inspectLegacyWallet({
573
+ rpc: this.rpc,
574
+ acceptedWasmHashes: this.acceptedWasmHashes,
575
+ contractWasmHash: (id) => this.contractWasmHash(id),
576
+ }, contractId);
577
+ }
578
+ legacyTxDeps(contractId) {
579
+ return {
580
+ rpcUrl: this.rpcUrl,
581
+ networkPassphrase: this.networkPassphrase,
582
+ timeoutInSeconds: this.timeoutInSeconds,
583
+ spec: new PasskeyClient({
584
+ contractId,
585
+ rpcUrl: this.rpcUrl,
586
+ networkPassphrase: this.networkPassphrase,
587
+ }).spec,
588
+ };
589
+ }
590
+ /**
591
+ * Restore archived entries a simulated transaction needs, using the
592
+ * configured `restoreSource`, and rebuild. Throws with guidance when no
593
+ * restore source is configured.
594
+ */
595
+ async withRestore(build, contractId) {
596
+ let tx = await build();
597
+ const simulation = tx.simulation;
598
+ if (simulation && Api.isSimulationRestore(simulation)) {
599
+ if (!this.restoreKeypair) {
600
+ throw new PasskeyKitError(`Wallet ${contractId} has archived ledger entries that must be restored before this ` +
601
+ `call can run. Configure \`restoreSource\` (a funded key) on the kit, or submit a ` +
602
+ `RestoreFootprint operation yourself, then retry.`, PasskeyKitErrorCode.RESTORE_REQUIRED, { context: { contractId } });
603
+ }
604
+ await restoreFootprint({
605
+ rpc: this.rpc,
606
+ networkPassphrase: this.networkPassphrase,
607
+ sourceKeypair: this.restoreKeypair,
608
+ timeoutInSeconds: this.timeoutInSeconds,
609
+ }, simulation.restorePreamble);
610
+ tx = await build();
611
+ }
612
+ return tx;
613
+ }
614
+ /**
615
+ * Build the in-place upgrade for a pre-1.0 wallet:
616
+ * `update_contract_code(<legacy-line target>)`, authorized by the wallet.
617
+ * Refuses wallets that are not on a known pre-1.0 build. Restores archived
618
+ * entries first when `restoreSource` is configured.
619
+ *
620
+ * Sign it with {@link signLegacyUpgradeTx} and submit through
621
+ * `PasskeyServer.send` (or your own funded source).
622
+ */
623
+ async buildLegacyUpgradeTx(contractId) {
624
+ const inspection = await this.inspectLegacyWallet(contractId);
625
+ if (inspection.wasmHash === inspection.upgradeTarget) {
626
+ throw new ValidationError(`Wallet ${contractId} already runs the legacy-line target ${inspection.upgradeTarget.slice(0, 8)}…; ` +
627
+ `nothing to upgrade. ${inspection.recommendation}`, PasskeyKitErrorCode.INVALID_INPUT, { contractId, wasmHash: inspection.wasmHash, status: inspection.status });
628
+ }
629
+ if (inspection.status !== "vulnerable" && inspection.status !== "legacy") {
630
+ throw new ValidationError(`Wallet ${contractId} is not on a known pre-1.0 build (${inspection.status}); ` +
631
+ `there is no legacy upgrade to build. ${inspection.recommendation}`, PasskeyKitErrorCode.INVALID_INPUT, { contractId, wasmHash: inspection.wasmHash, status: inspection.status });
632
+ }
633
+ const tx = await this.withRestore(() => buildLegacyUpgradeTx(this.legacyTxDeps(contractId), contractId, inspection.upgradeTarget), contractId);
634
+ return { inspection, tx };
635
+ }
636
+ /**
637
+ * Build `migrate_signers(keys)` for a wallet already upgraded to the
638
+ * legacy-line target. Needs no wallet authorization; any funded source can
639
+ * submit it. Get the keys from `PasskeyServer.getSigners` /
640
+ * `MercuryIndexer.getSigners`.
641
+ */
642
+ buildLegacyMigrateTx(contractId, signerKeys) {
643
+ return this.withRestore(() => buildLegacyMigrateTx(this.legacyTxDeps(contractId), contractId, signerKeys), contractId);
644
+ }
645
+ /**
646
+ * Sign a legacy wallet's upgrade transaction with one of its existing
647
+ * signers, without connecting. Defaults to a discoverable passkey prompt;
648
+ * pass `new PasskeySigner(keyId)` to require a specific credential, or an
649
+ * `Ed25519Signer`.
650
+ */
651
+ signLegacyUpgradeTx(tx, contractId, signer = new PasskeySigner("any"), options) {
652
+ return signLegacyUpgradeTx({
653
+ networkPassphrase: this.networkPassphrase,
654
+ spec: this.legacyTxDeps(contractId).spec,
655
+ signerContext: this.signerContext(),
656
+ calculateExpiration: () => calculateExpiration({ rpc: this.rpc, timeoutInSeconds: this.timeoutInSeconds }),
657
+ contractId,
658
+ }, tx, signer, options);
659
+ }
515
660
  // -- Signing -----------------------------------------------------------------
516
661
  /** Sign a single auth entry (defaults to the connected passkey signer). */
517
662
  signAuthEntry(entry, signer, options) {