@qntx/wallet 0.4.0 → 0.5.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.
@@ -1,3 +1,3 @@
1
- import { b as WalletErrorCode } from "./types-D4OUjGVS.mjs";
2
- import { $ as NOSTR_METHODS, A as FrostSignJob, B as SPARK_METHODS, C as BackupInfo, Ct as str, D as backupHeader, E as backupEnvelopeText, F as PrepareTransferRequest, G as SparkApproveIntent, H as SigningTarget, I as PreparedClaim, J as SparkNetwork, K as SparkKey, L as PreparedLightningReceive, M as IdentityStatement, N as OperatorCommitment, O as backupInfo, P as PrepareClaimRequest, Q as KeyResult, R as PreparedTransfer, S as BackupHeaderWire, St as record, T as backupEnvelopeFactor, Tt as validate, U as SparkAccountRef, V as SigningCommitment, W as SparkApprovalSummary, X as StaticDepositClaimResult, Y as StaticDepositClaimRequest, Z as StaticDepositClaimStatement, _ as requestBytes, _t as int, a as MethodName, at as UnwrapResult, b as BackupEnvelopeWire, bt as obj, c as PROTOCOL_VERSION, ct as CreatedResult, d as Request, dt as walletErrorCode, et as NostrExportFormat, f as Response, ft as ValidationError, g as kernelEvent, gt as bytes, h as isProtocolValue, ht as bool, i as METHODS, it as UnsignedEventInput, j as HtlcTimeoutSignRequest, k as FrostAggregateJob, l as ParamsOf, lt as Factor, m as UNATTRIBUTED_ID, mt as arr, n as KernelEvent, nt as Rumor, o as MethodTablesDisjoint, ot as BackupFactor, p as ResultOf, pt as Validator, q as SparkLeafKey, r as MAX_REQUEST_BYTES, rt as SignedEvent, s as NullValue, st as CORE_METHODS, t as ErrorPayload, tt as NostrImportInput, u as ProtocolValue, ut as MethodSpec, v as responseError, vt as literal, w as backupEnvelope, wt as union, x as BackupHeaderWallet, xt as opt, y as BackupEnvelopeFactor, yt as nullValue, z as PreparedTransferLeaf } from "./index-Dhf6wGjQ.mjs";
3
- export { type BackupEnvelopeFactor, type BackupEnvelopeWire, type BackupFactor, type BackupHeaderWallet, type BackupHeaderWire, type BackupInfo, CORE_METHODS, type CreatedResult, ErrorPayload, type Factor, type FrostAggregateJob, type FrostSignJob, type HtlcTimeoutSignRequest, type IdentityStatement, KernelEvent, type KeyResult, MAX_REQUEST_BYTES, METHODS, MethodName, type MethodSpec, MethodTablesDisjoint, NOSTR_METHODS, type NostrExportFormat, type NostrImportInput, NullValue, type OperatorCommitment, PROTOCOL_VERSION, ParamsOf, type PrepareClaimRequest, type PrepareTransferRequest, type PreparedClaim, type PreparedLightningReceive, type PreparedTransfer, type PreparedTransferLeaf, ProtocolValue, Request, Response, ResultOf, type Rumor, SPARK_METHODS, type SignedEvent, type SigningCommitment, type SigningTarget, type SparkAccountRef, type SparkApprovalSummary, type SparkApproveIntent, type SparkKey, type SparkLeafKey, type SparkNetwork, type StaticDepositClaimRequest, type StaticDepositClaimResult, type StaticDepositClaimStatement, UNATTRIBUTED_ID, type UnsignedEventInput, type UnwrapResult, ValidationError, type Validator, type WalletErrorCode, arr, backupEnvelope, backupEnvelopeFactor, backupEnvelopeText, backupHeader, backupInfo, bool, bytes, int, isProtocolValue, kernelEvent, literal, nullValue, obj, opt, record, requestBytes, responseError, str, union, validate, walletErrorCode };
1
+ import { b as WalletErrorCode } from "./types-BD9fuAUj.mjs";
2
+ import { $ as PreparedTransfer, A as isProtocolValue, At as opt, B as backupEnvelopeFactor, C as PROTOCOL_VERSION, Ct as arr, D as Response, Dt as literal, E as Request, Et as int, F as BackupEnvelopeWire, G as FrostSignJob, H as backupHeader, I as BackupHeaderWallet, J as OperatorCommitment, K as HtlcTimeoutSignRequest, L as BackupHeaderWire, M as requestBytes, Mt as str, N as responseError, Nt as union, O as ResultOf, Ot as nullValue, P as BackupEnvelopeFactor, Pt as validate, Q as PreparedLightningReceive, R as BackupInfo, S as NullValue, St as Validator, T as ProtocolValue, Tt as bytes, U as backupInfo, V as backupEnvelopeText, W as FrostAggregateJob, X as PrepareTransferRequest, Y as PrepareClaimRequest, Z as PreparedClaim, _ as KernelEvent, _t as Rumor, a as ChainSignResult, at as SparkApprovalSummary, b as MethodName, bt as UnwrapResult, c as BackupUnlockFactor, ct as SparkLeafKey, d as CreatedResult, dt as StaticDepositClaimResult, et as PreparedTransferLeaf, f as Factor, ft as StaticDepositClaimStatement, g as ErrorPayload, gt as NostrImportInput, h as walletErrorCode, ht as NostrExportFormat, it as SparkAccountRef, j as kernelEvent, jt as record, k as UNATTRIBUTED_ID, kt as obj, l as CORE_METHODS, lt as SparkNetwork, m as RestoreWithPasskeyParams, mt as NOSTR_METHODS, n as ChainAccount, nt as SigningCommitment, o as ChainTemplate, ot as SparkApproveIntent, p as MethodSpec, pt as KeyResult, q as IdentityStatement, r as ChainAccountsParams, rt as SigningTarget, s as BackupFactor, st as SparkKey, t as CHAINS_METHODS, tt as SPARK_METHODS, u as CreateWithPasskeyParams, ut as StaticDepositClaimRequest, v as MAX_REQUEST_BYTES, vt as SignedEvent, w as ParamsOf, wt as bool, x as MethodTablesDisjoint, xt as ValidationError, y as METHODS, yt as UnsignedEventInput, z as backupEnvelope } from "./chains-D_jfwTPT.mjs";
3
+ export { type BackupEnvelopeFactor, type BackupEnvelopeWire, type BackupFactor, type BackupHeaderWallet, type BackupHeaderWire, type BackupInfo, type BackupUnlockFactor, CHAINS_METHODS, CORE_METHODS, type ChainAccount, type ChainAccountsParams, type ChainSignResult, type ChainTemplate, type CreateWithPasskeyParams, type CreatedResult, ErrorPayload, type Factor, type FrostAggregateJob, type FrostSignJob, type HtlcTimeoutSignRequest, type IdentityStatement, KernelEvent, type KeyResult, MAX_REQUEST_BYTES, METHODS, MethodName, type MethodSpec, MethodTablesDisjoint, NOSTR_METHODS, type NostrExportFormat, type NostrImportInput, NullValue, type OperatorCommitment, PROTOCOL_VERSION, ParamsOf, type PrepareClaimRequest, type PrepareTransferRequest, type PreparedClaim, type PreparedLightningReceive, type PreparedTransfer, type PreparedTransferLeaf, ProtocolValue, Request, Response, type RestoreWithPasskeyParams, ResultOf, type Rumor, SPARK_METHODS, type SignedEvent, type SigningCommitment, type SigningTarget, type SparkAccountRef, type SparkApprovalSummary, type SparkApproveIntent, type SparkKey, type SparkLeafKey, type SparkNetwork, type StaticDepositClaimRequest, type StaticDepositClaimResult, type StaticDepositClaimStatement, UNATTRIBUTED_ID, type UnsignedEventInput, type UnwrapResult, ValidationError, type Validator, type WalletErrorCode, arr, backupEnvelope, backupEnvelopeFactor, backupEnvelopeText, backupHeader, backupInfo, bool, bytes, int, isProtocolValue, kernelEvent, literal, nullValue, obj, opt, record, requestBytes, responseError, str, union, validate, walletErrorCode };
package/dist/protocol.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { C as opt, D as validate, E as union, S as obj, T as str, _ as bool, b as literal, f as walletErrorCode, g as arr, h as ValidationError, t as CORE_METHODS, v as bytes, w as record, x as nullValue, y as int } from "./core-QJ66nLLG.mjs";
2
- import { a as isProtocolValue, c as responseError, d as backupEnvelope, f as backupEnvelopeFactor, h as backupInfo, i as UNATTRIBUTED_ID, l as SPARK_METHODS, m as backupHeader, n as METHODS, o as kernelEvent, p as backupEnvelopeText, r as PROTOCOL_VERSION, s as requestBytes, t as MAX_REQUEST_BYTES, u as NOSTR_METHODS } from "./protocol-D9xBuMzq.mjs";
3
- export { CORE_METHODS, MAX_REQUEST_BYTES, METHODS, NOSTR_METHODS, PROTOCOL_VERSION, SPARK_METHODS, UNATTRIBUTED_ID, ValidationError, arr, backupEnvelope, backupEnvelopeFactor, backupEnvelopeText, backupHeader, backupInfo, bool, bytes, int, isProtocolValue, kernelEvent, literal, nullValue, obj, opt, record, requestBytes, responseError, str, union, validate, walletErrorCode };
1
+ import { C as opt, D as validate, E as union, S as obj, T as str, _ as bool, b as literal, f as walletErrorCode, g as arr, h as ValidationError, t as CORE_METHODS, v as bytes, w as record, x as nullValue, y as int } from "./core-Dmz5SbyJ.mjs";
2
+ import { a as isProtocolValue, c as responseError, d as CHAINS_METHODS, f as backupEnvelope, g as backupInfo, h as backupHeader, i as UNATTRIBUTED_ID, l as SPARK_METHODS, m as backupEnvelopeText, n as METHODS, o as kernelEvent, p as backupEnvelopeFactor, r as PROTOCOL_VERSION, s as requestBytes, t as MAX_REQUEST_BYTES, u as NOSTR_METHODS } from "./protocol-DvzlUKB8.mjs";
3
+ export { CHAINS_METHODS, CORE_METHODS, MAX_REQUEST_BYTES, METHODS, NOSTR_METHODS, PROTOCOL_VERSION, SPARK_METHODS, UNATTRIBUTED_ID, ValidationError, arr, backupEnvelope, backupEnvelopeFactor, backupEnvelopeText, backupHeader, backupInfo, bool, bytes, int, isProtocolValue, kernelEvent, literal, nullValue, obj, opt, record, requestBytes, responseError, str, union, validate, walletErrorCode };
@@ -0,0 +1,203 @@
1
+ import { WalletError } from "./types.mjs";
2
+ import { base64urlnopad } from "@scure/base";
3
+ //#region src/factors.ts
4
+ /**
5
+ * Factor plumbing for the host connector: public `UnlockFactor`/`InitialFactor` inputs become wire
6
+ * `Factor` material, passkey material comes from the host's WebAuthn ceremony, and every secret
7
+ * byte travels in a fresh exact-size buffer on the transfer list.
8
+ */
9
+ /** Purpose bytes stamped into the first byte of a credential's WebAuthn user handle. */
10
+ const PASSKEY_PURPOSE_WALLET = 1;
11
+ const PASSKEY_PURPOSE_VAULT = 2;
12
+ const HARDWARE = { kind: "hardware" };
13
+ function hardwareOnly() {
14
+ return new WalletError("factor-unavailable", "this host unlocks only with the hardware factor");
15
+ }
16
+ function noHardware() {
17
+ return new WalletError("factor-unavailable", "hardware factors exist only on React Native");
18
+ }
19
+ /** The factor `vault.unlock()` uses when the caller passes none. */
20
+ function defaultUnlockFactor(source) {
21
+ return source.mode === "hardware" ? { kind: "hardware" } : { kind: "passkey" };
22
+ }
23
+ function vaultSaltBytes(source) {
24
+ return new TextEncoder().encode(source.passkey.vaultSalt);
25
+ }
26
+ function walletSaltBytes(source) {
27
+ return new TextEncoder().encode(source.passkey.walletSalt);
28
+ }
29
+ function backupSaltBytes(source) {
30
+ return new TextEncoder().encode(source.passkey.backupSalt);
31
+ }
32
+ /**
33
+ * The host-run backup passkey ceremony (web): the PRF is evaluated over `backupSalt` with one of
34
+ * the vault's passkey credentials, producing `prfBackup` instead of the vault `prf`.
35
+ */
36
+ async function hostBackupPasskey(source, transfer) {
37
+ const result = await requireCeremony(source).assert({
38
+ credentialIds: passkeyCredentialIds(source),
39
+ salts: { first: backupSaltBytes(source) }
40
+ });
41
+ return {
42
+ kind: "passkey",
43
+ ceremony: "host",
44
+ credentialId: wireBytes(result.credentialId, transfer),
45
+ prfBackup: wireBytes(result.first, transfer, true)
46
+ };
47
+ }
48
+ function backupPassword(factor, transfer) {
49
+ if (factor.kind === "hardware") throw new WalletError("invalid-input", "backup factors are passkeys or passwords");
50
+ return factor.kind === "password" ? {
51
+ kind: "password",
52
+ password: wireSecretText(factor.password, transfer)
53
+ } : void 0;
54
+ }
55
+ /**
56
+ * Resolves a public `UnlockFactor` to a factor that seals a new backup key. A hardware host lets
57
+ * the kernel register the protection credential itself; nothing secret crosses the channel.
58
+ */
59
+ async function resolveBackupFactor(source, factor, transfer) {
60
+ const password = backupPassword(factor, transfer);
61
+ if (password !== void 0) return password;
62
+ if (source.mode === "hardware") return {
63
+ kind: "passkey",
64
+ ceremony: "kernel",
65
+ rpId: source.passkey.rpId,
66
+ rpName: source.passkey.rpName,
67
+ backupSalt: source.passkey.backupSalt
68
+ };
69
+ return hostBackupPasskey(source, transfer);
70
+ }
71
+ /** Resolves a public `UnlockFactor` to a factor that opens a backup envelope. */
72
+ async function resolveBackupUnlockFactor(source, factor, transfer) {
73
+ const password = backupPassword(factor, transfer);
74
+ if (password !== void 0) return password;
75
+ if (source.mode === "hardware") return {
76
+ kind: "passkey",
77
+ ceremony: "kernel",
78
+ rpId: source.passkey.rpId,
79
+ backupSalt: source.passkey.backupSalt
80
+ };
81
+ return hostBackupPasskey(source, transfer);
82
+ }
83
+ /** Passkey credential ids of the current vault factors, for `assert`'s allowCredentials. */
84
+ function passkeyCredentialIds(source) {
85
+ return source.factors().flatMap((factor) => factor.kind === "passkey" ? [base64urlnopad.decode(factor.credentialId)] : []);
86
+ }
87
+ /**
88
+ * A Uint8Array is placed on the wire in a fresh exact-size buffer whose ArrayBuffer goes into the
89
+ * transfer list — the bytes move to the kernel and cannot detach caller-owned memory. Secret
90
+ * sources are wiped after copying.
91
+ */
92
+ function wireBytes(source, transfer, wipeSource = false) {
93
+ const wire = new Uint8Array(source);
94
+ if (wipeSource) source.fill(0);
95
+ transfer.push(wire.buffer);
96
+ return wire;
97
+ }
98
+ function wireSecretText(text, transfer) {
99
+ return wireBytes(new TextEncoder().encode(text), transfer);
100
+ }
101
+ function requireCeremony(source) {
102
+ if (source.ceremony === void 0) throw new WalletError("factor-unavailable", "no passkey ceremony is configured");
103
+ return source.ceremony;
104
+ }
105
+ /** A passkey credential's display name: trimmed, 1–64 UTF-16 code units, else invalid-input. */
106
+ function passkeyName(name) {
107
+ const trimmed = name.trim();
108
+ if (trimmed.length === 0 || trimmed.length > 64) throw new WalletError("invalid-input", "the passkey name must be 1–64 characters");
109
+ return trimmed;
110
+ }
111
+ /**
112
+ * Resolves a public `UnlockFactor` to wire factor material. `transfer` collects every buffer the
113
+ * port must move. Ceremony errors surface as they are (cancelled / factor-unavailable).
114
+ */
115
+ async function resolveFactor(source, factor, transfer) {
116
+ if (source.mode === "hardware") {
117
+ if (factor.kind !== "hardware") throw hardwareOnly();
118
+ return HARDWARE;
119
+ }
120
+ if (factor.kind === "hardware") throw noHardware();
121
+ if (factor.kind === "password") return {
122
+ kind: "password",
123
+ password: wireSecretText(factor.password, transfer)
124
+ };
125
+ const result = await requireCeremony(source).assert({
126
+ credentialIds: passkeyCredentialIds(source),
127
+ salts: { first: vaultSaltBytes(source) }
128
+ });
129
+ return {
130
+ kind: "passkey",
131
+ credentialId: wireBytes(result.credentialId, transfer),
132
+ prf: wireBytes(result.first, transfer, true)
133
+ };
134
+ }
135
+ /**
136
+ * Resolves a public `InitialFactor` (a factor being created). For `create/restoreWithPasskey` the
137
+ * default passkey factor reuses the wallet ceremony's own credential and `second` PRF output; a
138
+ * hardware host always establishes the hardware factor and drops that output.
139
+ */
140
+ async function resolveInitialFactor(source, factor, transfer, walletCeremony) {
141
+ if (source.mode === "hardware") {
142
+ walletCeremony?.second?.fill(0);
143
+ if (factor !== void 0 && factor.kind !== "hardware") throw hardwareOnly();
144
+ return HARDWARE;
145
+ }
146
+ if (factor === void 0 || factor.kind === "passkey") {
147
+ const name = factor === void 0 ? void 0 : passkeyName(factor.name);
148
+ if (walletCeremony !== void 0) {
149
+ const { second } = walletCeremony;
150
+ if (second === void 0) throw new WalletError("factor-unavailable", "the ceremony returned no vault PRF output");
151
+ return {
152
+ kind: "passkey",
153
+ credentialId: wireBytes(walletCeremony.credentialId, transfer),
154
+ prf: wireBytes(second, transfer, true)
155
+ };
156
+ }
157
+ if (name === void 0) throw new WalletError("invalid-input", "a passkey factor requires a name");
158
+ const result = await requireCeremony(source).create({
159
+ purpose: "vault",
160
+ name,
161
+ salts: { first: vaultSaltBytes(source) }
162
+ });
163
+ return {
164
+ kind: "passkey",
165
+ credentialId: wireBytes(result.credentialId, transfer),
166
+ prf: wireBytes(result.first, transfer, true)
167
+ };
168
+ }
169
+ if (factor.kind === "password") {
170
+ walletCeremony?.second?.fill(0);
171
+ return {
172
+ kind: "password",
173
+ password: wireSecretText(factor.password, transfer)
174
+ };
175
+ }
176
+ throw noHardware();
177
+ }
178
+ //#endregion
179
+ //#region src/secret.ts
180
+ /**
181
+ * One-shot secret bytes handed to the app: `read` returns them exactly once, `wipe` zeroes them.
182
+ * The second `read` fails closed.
183
+ */
184
+ var SingleUseSecret = class {
185
+ bytes;
186
+ constructor(bytes) {
187
+ this.bytes = bytes;
188
+ }
189
+ read() {
190
+ const { bytes } = this;
191
+ if (bytes === void 0) throw new WalletError("invalid-input", "secret already read or wiped");
192
+ this.bytes = void 0;
193
+ return bytes;
194
+ }
195
+ wipe() {
196
+ this.bytes?.fill(0);
197
+ this.bytes = void 0;
198
+ }
199
+ };
200
+ //#endregion
201
+ export { passkeyName as a, resolveBackupUnlockFactor as c, vaultSaltBytes as d, walletSaltBytes as f, defaultUnlockFactor as i, resolveFactor as l, wireSecretText as m, PASSKEY_PURPOSE_VAULT as n, requireCeremony as o, wireBytes as p, PASSKEY_PURPOSE_WALLET as r, resolveBackupFactor as s, SingleUseSecret as t, resolveInitialFactor as u };
202
+
203
+ //# sourceMappingURL=secret-BiyX0Hus.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secret-BiyX0Hus.mjs","names":[],"sources":["../src/factors.ts","../src/secret.ts"],"sourcesContent":["/**\n * Factor plumbing for the host connector: public `UnlockFactor`/`InitialFactor` inputs become wire\n * `Factor` material, passkey material comes from the host's WebAuthn ceremony, and every secret\n * byte travels in a fresh exact-size buffer on the transfer list.\n */\nimport { base64urlnopad } from \"@scure/base\";\n\nimport type { BackupFactor, BackupUnlockFactor, Factor } from \"./protocol/index.ts\";\nimport { WalletError } from \"./types.ts\";\nimport type { FactorInfo, InitialFactor, PasskeyConfig, UnlockFactor } from \"./types.ts\";\n\nexport type PrfSalts = { readonly first: Uint8Array; readonly second?: Uint8Array };\n\n/** Purpose bytes stamped into the first byte of a credential's WebAuthn user handle. */\nexport const PASSKEY_PURPOSE_WALLET = 0x01;\nexport const PASSKEY_PURPOSE_VAULT = 0x02;\n\nexport type PrfResult = {\n readonly credentialId: Uint8Array;\n readonly first: Uint8Array;\n readonly second?: Uint8Array;\n /** The assertion's `userHandle` — its first byte declares the credential's purpose. */\n readonly userHandle?: Uint8Array;\n /** The credential survives this device: the authenticator data's BE and BS flags are both set. */\n readonly synced: boolean;\n};\n\n/**\n * The WebAuthn ceremony the host performs. Implementations throw `WalletError` — \"cancelled\" when\n * the user aborts, \"factor-unavailable\" when the credential cannot produce a PRF. `name` is the new\n * credential's display name, validated by the host before the call (1–64 characters).\n */\nexport type PasskeyCeremony = {\n readonly create: (input: {\n readonly purpose: \"wallet\" | \"vault\";\n readonly name: string;\n readonly salts: PrfSalts;\n }) => Promise<PrfResult>;\n readonly assert: (input: {\n readonly credentialIds?: ReadonlyArray<Uint8Array>;\n readonly salts: PrfSalts;\n }) => Promise<PrfResult>;\n};\n\n/**\n * Which vault factors a host offers: `hardware` (React Native — the platform keystore is the only\n * factor, and omitted factors mean it) or `software` (web/node — passkey and password). The kernel\n * enforces the same rule; resolving here keeps a doomed request from firing a ceremony.\n */\nexport type FactorMode = \"hardware\" | \"software\";\n\n/** What factor resolution needs from the wallet: config, the ceremony, live factor records. */\nexport type FactorSource = {\n readonly mode: FactorMode;\n readonly passkey: PasskeyConfig;\n readonly ceremony: PasskeyCeremony | undefined;\n readonly factors: () => ReadonlyArray<FactorInfo>;\n};\n\nconst HARDWARE: Factor = { kind: \"hardware\" };\n\nfunction hardwareOnly(): WalletError {\n return new WalletError(\"factor-unavailable\", \"this host unlocks only with the hardware factor\");\n}\n\nfunction noHardware(): WalletError {\n return new WalletError(\"factor-unavailable\", \"hardware factors exist only on React Native\");\n}\n\n/** The factor `vault.unlock()` uses when the caller passes none. */\nexport function defaultUnlockFactor(source: FactorSource): UnlockFactor {\n return source.mode === \"hardware\" ? { kind: \"hardware\" } : { kind: \"passkey\" };\n}\n\nexport function vaultSaltBytes(source: FactorSource): Uint8Array {\n return new TextEncoder().encode(source.passkey.vaultSalt);\n}\n\nexport function walletSaltBytes(source: FactorSource): Uint8Array {\n return new TextEncoder().encode(source.passkey.walletSalt);\n}\n\nexport function backupSaltBytes(source: FactorSource): Uint8Array {\n return new TextEncoder().encode(source.passkey.backupSalt);\n}\n\n/**\n * The host-run backup passkey ceremony (web): the PRF is evaluated over `backupSalt` with one of\n * the vault's passkey credentials, producing `prfBackup` instead of the vault `prf`.\n */\nasync function hostBackupPasskey(\n source: FactorSource,\n transfer: ArrayBuffer[],\n): Promise<Extract<BackupFactor, { ceremony: \"host\" }>> {\n const ceremony = requireCeremony(source);\n const result = await ceremony.assert({\n credentialIds: passkeyCredentialIds(source),\n salts: { first: backupSaltBytes(source) },\n });\n return {\n kind: \"passkey\",\n ceremony: \"host\",\n credentialId: wireBytes(result.credentialId, transfer),\n prfBackup: wireBytes(result.first, transfer, true),\n };\n}\n\nfunction backupPassword(\n factor: UnlockFactor,\n transfer: ArrayBuffer[],\n): { readonly kind: \"password\"; readonly password: Uint8Array } | undefined {\n if (factor.kind === \"hardware\") {\n throw new WalletError(\"invalid-input\", \"backup factors are passkeys or passwords\");\n }\n return factor.kind === \"password\"\n ? { kind: \"password\", password: wireSecretText(factor.password, transfer) }\n : undefined;\n}\n\n/**\n * Resolves a public `UnlockFactor` to a factor that seals a new backup key. A hardware host lets\n * the kernel register the protection credential itself; nothing secret crosses the channel.\n */\nexport async function resolveBackupFactor(\n source: FactorSource,\n factor: UnlockFactor,\n transfer: ArrayBuffer[],\n): Promise<BackupFactor> {\n const password = backupPassword(factor, transfer);\n if (password !== undefined) {\n return password;\n }\n if (source.mode === \"hardware\") {\n return {\n kind: \"passkey\",\n ceremony: \"kernel\",\n rpId: source.passkey.rpId,\n rpName: source.passkey.rpName,\n backupSalt: source.passkey.backupSalt,\n };\n }\n return hostBackupPasskey(source, transfer);\n}\n\n/** Resolves a public `UnlockFactor` to a factor that opens a backup envelope. */\nexport async function resolveBackupUnlockFactor(\n source: FactorSource,\n factor: UnlockFactor,\n transfer: ArrayBuffer[],\n): Promise<BackupUnlockFactor> {\n const password = backupPassword(factor, transfer);\n if (password !== undefined) {\n return password;\n }\n if (source.mode === \"hardware\") {\n return {\n kind: \"passkey\",\n ceremony: \"kernel\",\n rpId: source.passkey.rpId,\n backupSalt: source.passkey.backupSalt,\n };\n }\n return hostBackupPasskey(source, transfer);\n}\n\n/** Passkey credential ids of the current vault factors, for `assert`'s allowCredentials. */\nfunction passkeyCredentialIds(source: FactorSource): Uint8Array[] {\n return source\n .factors()\n .flatMap((factor) =>\n factor.kind === \"passkey\" ? [base64urlnopad.decode(factor.credentialId)] : [],\n );\n}\n\n/**\n * A Uint8Array is placed on the wire in a fresh exact-size buffer whose ArrayBuffer goes into the\n * transfer list — the bytes move to the kernel and cannot detach caller-owned memory. Secret\n * sources are wiped after copying.\n */\nexport function wireBytes(\n source: Uint8Array,\n transfer: ArrayBuffer[],\n wipeSource = false,\n): Uint8Array {\n // Always a fresh exact-size buffer: transferring must never detach caller-owned memory.\n const wire = new Uint8Array(source);\n if (wipeSource) {\n source.fill(0);\n }\n transfer.push(wire.buffer);\n return wire;\n}\n\nexport function wireSecretText(text: string, transfer: ArrayBuffer[]): Uint8Array {\n return wireBytes(new TextEncoder().encode(text), transfer);\n}\n\nexport function requireCeremony(source: FactorSource): PasskeyCeremony {\n if (source.ceremony === undefined) {\n throw new WalletError(\"factor-unavailable\", \"no passkey ceremony is configured\");\n }\n return source.ceremony;\n}\n\n/** A passkey credential's display name: trimmed, 1–64 UTF-16 code units, else invalid-input. */\nexport function passkeyName(name: string): string {\n const trimmed = name.trim();\n if (trimmed.length === 0 || trimmed.length > 64) {\n throw new WalletError(\"invalid-input\", \"the passkey name must be 1–64 characters\");\n }\n return trimmed;\n}\n\n/**\n * Resolves a public `UnlockFactor` to wire factor material. `transfer` collects every buffer the\n * port must move. Ceremony errors surface as they are (cancelled / factor-unavailable).\n */\nexport async function resolveFactor(\n source: FactorSource,\n factor: UnlockFactor,\n transfer: ArrayBuffer[],\n): Promise<Factor> {\n if (source.mode === \"hardware\") {\n if (factor.kind !== \"hardware\") {\n throw hardwareOnly();\n }\n return HARDWARE;\n }\n if (factor.kind === \"hardware\") {\n throw noHardware();\n }\n if (factor.kind === \"password\") {\n return { kind: \"password\", password: wireSecretText(factor.password, transfer) };\n }\n const ceremony = requireCeremony(source);\n const result = await ceremony.assert({\n credentialIds: passkeyCredentialIds(source),\n salts: { first: vaultSaltBytes(source) },\n });\n return {\n kind: \"passkey\",\n credentialId: wireBytes(result.credentialId, transfer),\n prf: wireBytes(result.first, transfer, true),\n };\n}\n\n/**\n * Resolves a public `InitialFactor` (a factor being created). For `create/restoreWithPasskey` the\n * default passkey factor reuses the wallet ceremony's own credential and `second` PRF output; a\n * hardware host always establishes the hardware factor and drops that output.\n */\nexport async function resolveInitialFactor(\n source: FactorSource,\n factor: InitialFactor | undefined,\n transfer: ArrayBuffer[],\n walletCeremony?: PrfResult,\n): Promise<Factor> {\n if (source.mode === \"hardware\") {\n walletCeremony?.second?.fill(0);\n if (factor !== undefined && factor.kind !== \"hardware\") {\n throw hardwareOnly();\n }\n return HARDWARE;\n }\n if (factor === undefined || factor.kind === \"passkey\") {\n const name = factor === undefined ? undefined : passkeyName(factor.name);\n if (walletCeremony !== undefined) {\n const { second } = walletCeremony;\n if (second === undefined) {\n throw new WalletError(\"factor-unavailable\", \"the ceremony returned no vault PRF output\");\n }\n return {\n kind: \"passkey\",\n credentialId: wireBytes(walletCeremony.credentialId, transfer),\n prf: wireBytes(second, transfer, true),\n };\n }\n if (name === undefined) {\n // No caller reaches this today (createFactorParam requires a factor), but the ceremony\n // contract needs a name — fail closed rather than inventing one.\n throw new WalletError(\"invalid-input\", \"a passkey factor requires a name\");\n }\n const result = await requireCeremony(source).create({\n purpose: \"vault\",\n name,\n salts: { first: vaultSaltBytes(source) },\n });\n return {\n kind: \"passkey\",\n credentialId: wireBytes(result.credentialId, transfer),\n prf: wireBytes(result.first, transfer, true),\n };\n }\n if (factor.kind === \"password\") {\n walletCeremony?.second?.fill(0); // the passkey vault factor is not needed\n return { kind: \"password\", password: wireSecretText(factor.password, transfer) };\n }\n throw noHardware();\n}\n","import { WalletError } from \"./types.ts\";\nimport type { ExportedSecret } from \"./types.ts\";\n\n/**\n * One-shot secret bytes handed to the app: `read` returns them exactly once, `wipe` zeroes them.\n * The second `read` fails closed.\n */\nexport class SingleUseSecret implements ExportedSecret {\n private bytes: Uint8Array | undefined;\n\n constructor(bytes: Uint8Array) {\n this.bytes = bytes;\n }\n\n read(): Uint8Array {\n const { bytes } = this;\n if (bytes === undefined) {\n throw new WalletError(\"invalid-input\", \"secret already read or wiped\");\n }\n this.bytes = undefined;\n return bytes;\n }\n\n wipe(): void {\n this.bytes?.fill(0);\n this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AAc,UAAU,OAAO,cAAc,QAAQ;GACrD,KAAK,UAAU,OAAO,OAAO,UAAU,IAAI;EAC7C;CACF;CACA,IAAI,OAAO,SAAS,YAAY;EAC9B,gBAAgB,QAAQ,KAAK,CAAC;EAC9B,OAAO;GAAE,MAAM;GAAY,UAAU,eAAe,OAAO,UAAU,QAAQ;EAAE;CACjF;CACA,MAAM,WAAW;AACnB;;;;;;;ACnSA,IAAa,kBAAb,MAAuD;CACrD;CAEA,YAAY,OAAmB;EAC7B,KAAK,QAAQ;CACf;CAEA,OAAmB;EACjB,MAAM,EAAE,UAAU;EAClB,IAAI,UAAU,KAAA,GACZ,MAAM,IAAI,YAAY,iBAAiB,8BAA8B;EAEvE,KAAK,QAAQ,KAAA;EACb,OAAO;CACT;CAEA,OAAa;EACX,KAAK,OAAO,KAAK,CAAC;EAClB,KAAK,QAAQ,KAAA;CACf;AACF"}
package/dist/spark.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { h as UnlockFactor, v as Wallet } from "./types-D4OUjGVS.mjs";
2
- import { G as SparkApproveIntent, U as SparkAccountRef, W as SparkApprovalSummary } from "./index-Dhf6wGjQ.mjs";
1
+ import { h as UnlockFactor, v as Wallet } from "./types-BD9fuAUj.mjs";
2
+ import { at as SparkApprovalSummary, it as SparkAccountRef, ot as SparkApproveIntent } from "./chains-D_jfwTPT.mjs";
3
3
  import { SparkSigner, SparkSigner as SparkSigner$1 } from "@qntx/spark/signer";
4
4
  //#region src/spark/types.d.ts
5
5
  type SparkApi = {
@@ -3,6 +3,8 @@
3
3
  type LockReason = "cold-start" | "user" | "idle" | "background" | "expired" | "crashed" | "invalidated";
4
4
  type FactorInfo = {
5
5
  readonly kind: "hardware";
6
+ readonly id: string;
7
+ readonly createdAt: number;
6
8
  } | {
7
9
  readonly kind: "passkey";
8
10
  readonly id: string;
@@ -88,8 +90,13 @@ declare class WalletError extends Error {
88
90
  readonly retryAt: number | undefined;
89
91
  constructor(code: WalletErrorCode, message: string, retryAt?: number);
90
92
  }
91
- /** A factor the user proves again for a guarded operation (Web/Node). */
93
+ /**
94
+ * A factor the user proves again for a guarded operation. `hardware` is the React Native factor:
95
+ * the kernel shows the system verification prompt with text it renders itself.
96
+ */
92
97
  type UnlockFactor = {
98
+ readonly kind: "hardware";
99
+ } | {
93
100
  readonly kind: "passkey";
94
101
  } | {
95
102
  readonly kind: "password";
@@ -219,4 +226,4 @@ type Wallet = {
219
226
  };
220
227
  //#endregion
221
228
  export { WalletSnapshot as C, WalletOptions as S, VaultState as _, DerivedNostrKey as a, WalletErrorCode as b, InitialFactor as c, NostrKeyInfo as d, NostrKeyRef as f, VaultApi as g, UnlockFactor as h, DataKeyApi as i, LockReason as l, StatusPayload as m, BackupApi as n, ExportedSecret as o, PasskeyConfig as p, BackupInfo as r, FactorInfo as s, AutoLockPolicy as t, MnemonicDraft as u, Wallet as v, WalletsApi as w, WalletInfo as x, WalletError as y };
222
- //# sourceMappingURL=types-D4OUjGVS.d.mts.map
229
+ //# sourceMappingURL=types-BD9fuAUj.d.mts.map
package/dist/types.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { C as WalletSnapshot, S as WalletOptions, _ as VaultState, a as DerivedNostrKey, b as WalletErrorCode, c as InitialFactor, d as NostrKeyInfo, f as NostrKeyRef, g as VaultApi, h as UnlockFactor, i as DataKeyApi, l as LockReason, m as StatusPayload, n as BackupApi, o as ExportedSecret, p as PasskeyConfig, r as BackupInfo, s as FactorInfo, t as AutoLockPolicy, u as MnemonicDraft, v as Wallet, w as WalletsApi, x as WalletInfo, y as WalletError } from "./types-D4OUjGVS.mjs";
1
+ import { C as WalletSnapshot, S as WalletOptions, _ as VaultState, a as DerivedNostrKey, b as WalletErrorCode, c as InitialFactor, d as NostrKeyInfo, f as NostrKeyRef, g as VaultApi, h as UnlockFactor, i as DataKeyApi, l as LockReason, m as StatusPayload, n as BackupApi, o as ExportedSecret, p as PasskeyConfig, r as BackupInfo, s as FactorInfo, t as AutoLockPolicy, u as MnemonicDraft, v as Wallet, w as WalletsApi, x as WalletInfo, y as WalletError } from "./types-BD9fuAUj.mjs";
2
2
  export { AutoLockPolicy, BackupApi, BackupInfo, DataKeyApi, DerivedNostrKey, ExportedSecret, FactorInfo, InitialFactor, LockReason, MnemonicDraft, NostrKeyInfo, NostrKeyRef, PasskeyConfig, StatusPayload, UnlockFactor, VaultApi, VaultState, Wallet, WalletError, WalletErrorCode, WalletInfo, WalletOptions, WalletSnapshot, WalletsApi };
@@ -1 +1 @@
1
- {"version":3,"file":"types.mjs","names":[],"sources":["../src/types.ts"],"sourcesContent":["/** Public types of @qntx/wallet, per design/entry.mdx. Secret data never appears here. */\nexport type LockReason =\n | \"cold-start\"\n | \"user\"\n | \"idle\"\n | \"background\"\n | \"expired\"\n | \"crashed\"\n | \"invalidated\";\n\nexport type FactorInfo =\n | { readonly kind: \"hardware\" }\n | {\n readonly kind: \"passkey\";\n readonly id: string;\n /** Base64url, public data — the main side passes it as allowCredentials. */\n readonly credentialId: string;\n readonly createdAt: number;\n }\n | { readonly kind: \"password\"; readonly id: string; readonly createdAt: number };\n\nexport type WalletInfo = {\n readonly walletId: string;\n readonly origin: \"passkey\" | \"mnemonic\";\n readonly words: 12 | 15 | 18 | 21 | 24;\n /**\n * Mnemonic: the user holds the phrase (passed the writing-down quiz, imported it, or exported at\n * least once). passkey: protected only by a synced passkey — still lost when the password manager\n * or account is lost, so the UI should prompt to export. none: exists only on this device (a\n * device-bound passkey).\n */\n readonly backup: \"none\" | \"passkey\" | \"mnemonic\";\n readonly createdAt: number;\n};\n\nexport type NostrKeyRef =\n | { readonly kind: \"derived\"; readonly walletId: string; readonly groupIndex: number }\n | { readonly kind: \"standalone\"; readonly id: string }\n | { readonly kind: \"nip46-client\"; readonly id: string };\n\nexport type NostrKeyInfo = {\n readonly ref: NostrKeyRef;\n readonly publicKey: string; // 64 lowercase hex\n readonly origin: \"derived\" | \"nsec\" | \"ncryptsec\" | \"generated\" | \"nip46-client\";\n /**\n * Only standalone keys carry it: derived keys recover from the wallet, nip46-client keys are\n * ephemeral.\n */\n readonly backedUp?: boolean;\n readonly createdAt: number;\n};\n\n/** One entry of a `nostr.discover` result: the public key an account group would produce. */\nexport type DerivedNostrKey = { readonly groupIndex: number; readonly publicKey: string };\n\nexport type WalletErrorCode =\n | \"locked\"\n | \"cancelled\"\n | \"factor-unavailable\"\n | \"factor-invalidated\"\n | \"wrong-password\"\n | \"wrong-passkey\"\n | \"rate-limited\"\n | \"invalid-input\"\n | \"not-found\"\n | \"already-exists\"\n | \"conflict\"\n | \"unsupported\"\n | \"unavailable\"\n | \"integrity\"\n | \"approval-required\"\n | \"crashed\";\n\n/**\n * The vault half of the status payload: `corrupted` means authentication or structural data failed\n * to verify, `unsupported` means a newer build wrote it (data untouched, update the app),\n * `unavailable` means a transient store I/O failure (retried on the next request or change).\n */\nexport type VaultState =\n | \"uninitialized\"\n | \"locked\"\n | \"unlocked\"\n | \"corrupted\"\n | \"unsupported\"\n | \"unavailable\";\n\n/**\n * `status` result / status event payload. Locked snapshots come from unauthenticated headers;\n * \"corrupted\" means the vault data itself failed to load or verify (reset is the only way out).\n * Each protocol module contributes one section (here: `nostr`).\n */\nexport type StatusPayload = {\n readonly protocol: 1;\n readonly vault: VaultState;\n readonly factors: ReadonlyArray<FactorInfo>;\n readonly wallets: ReadonlyArray<WalletInfo>;\n readonly nostr: { readonly keys: ReadonlyArray<NostrKeyInfo> };\n // oxlint-disable-next-line typescript/no-restricted-types -- wire contract: backup is null when off\n readonly backup: BackupInfo | null;\n};\n\n/** Public summary of a retained backup key — factors are the unwrap paths, never secrets. */\nexport type BackupInfo = {\n readonly id: string; // 32 lowercase hex, derived from the BEK\n readonly factors: ReadonlyArray<\"passkey\" | \"password\">;\n readonly createdAt: number;\n};\n\n/** One error class for the whole API; `code` carries the distinction. Messages never echo input. */\nexport class WalletError extends Error {\n readonly code: WalletErrorCode;\n readonly retryAt: number | undefined;\n\n constructor(code: WalletErrorCode, message: string, retryAt?: number) {\n super(message);\n this.name = \"WalletError\";\n this.code = code;\n this.retryAt = retryAt;\n }\n}\n\n/** A factor the user proves again for a guarded operation (Web/Node). */\nexport type UnlockFactor =\n | { readonly kind: \"passkey\" }\n | { readonly kind: \"password\"; readonly password: string };\n\n/**\n * A factor being created; `hardware` exists only on React Native. `name` is the passkey\n * credential's display name — the host validates it before the ceremony (1–64 characters).\n */\nexport type InitialFactor =\n | { readonly kind: \"hardware\" }\n | { readonly kind: \"passkey\"; readonly name: string }\n | { readonly kind: \"password\"; readonly password: string };\n\n/**\n * WebAuthn RP identity + PRF salt labels the host configures once. `rpId`, `walletSalt` and\n * `vaultSalt` are permanent identifiers: changing any of them makes every existing passkey factor\n * and passkey-derived wallet unrecoverable, and the two salts must differ. Moving a wallet to a\n * different domain requires WebAuthn related origins (`/.well-known/webauthn`); hosts should offer\n * `exportMnemonic` for passkey-derived wallets so they survive an RP migration.\n */\nexport type PasskeyConfig = {\n /** RP id — the origin's effective domain or a registrable parent of it (e.g. meowl.social). */\n readonly rpId: string;\n readonly rpName: string;\n readonly walletSalt: string;\n readonly vaultSalt: string;\n /** PRF salt for the cloud-backup factor — a third, distinct permanent label. */\n readonly backupSalt: string;\n};\n\nexport type AutoLockPolicy =\n | { readonly platform: \"native\"; readonly backgroundSeconds: 0 | 60 | 300 | 900 }\n | { readonly platform: \"web\"; readonly idleMinutes: 5 | 15 | 60 };\n\nexport type WalletOptions = {\n readonly passkey: PasskeyConfig;\n readonly autoLock: AutoLockPolicy;\n};\n\nexport type WalletSnapshot = {\n readonly vault: VaultState;\n readonly lockReason: LockReason | undefined;\n readonly verifying: boolean; // a user verification is in flight\n readonly factors: ReadonlyArray<FactorInfo>;\n readonly wallets: ReadonlyArray<WalletInfo>;\n readonly nostr: { readonly keys: ReadonlyArray<NostrKeyInfo> };\n /** The retained backup key's public id, or null when cloud backup is off. */\n // oxlint-disable-next-line typescript/no-restricted-types -- wire contract: backup is null when off\n readonly backup: BackupInfo | null;\n};\n\n/** A one-shot secret buffer: `read` detaches the bytes to the caller, `wipe` zeroes them. */\nexport type ExportedSecret = {\n readonly read: () => Uint8Array; // UTF-8 text; single use — the second call throws\n readonly wipe: () => void;\n};\n\nexport type MnemonicDraft = {\n readonly words: ExportedSecret; // read once, then the host is responsible for wiping\n readonly quiz: ReadonlyArray<number>; // three positions the enclave picked\n readonly confirm: (answers: ReadonlyArray<string>) => Promise<WalletInfo>;\n readonly discard: () => Promise<void>;\n};\n\nexport type VaultApi = {\n readonly unlock: (factor?: UnlockFactor) => Promise<void>;\n readonly lock: () => Promise<void>;\n readonly addFactor: (factor: InitialFactor, verify: UnlockFactor) => Promise<FactorInfo>;\n readonly removeFactor: (id: string, verify: UnlockFactor) => Promise<void>; // ≥1 factor remains\n readonly reset: () => Promise<void>;\n};\n\nexport type WalletsApi = {\n readonly createWithPasskey: (options: {\n /** Display name for the new passkey credential (1–64 characters after trimming). */\n readonly name: string;\n readonly factor?: InitialFactor;\n }) => Promise<WalletInfo>;\n readonly restoreWithPasskey: (options?: {\n readonly factor?: InitialFactor;\n }) => Promise<WalletInfo>;\n readonly createMnemonic: (options: {\n readonly words: 12 | 24;\n readonly factor?: InitialFactor;\n }) => Promise<MnemonicDraft>;\n readonly importMnemonic: (options: {\n readonly mnemonic: string;\n readonly factor?: InitialFactor;\n }) => Promise<WalletInfo>;\n /** One-shot mnemonic export; requires re-verification every call. */\n readonly exportMnemonic: (walletId: string, verify: UnlockFactor) => Promise<ExportedSecret>;\n readonly delete: (walletId: string, verify: UnlockFactor) => Promise<void>;\n};\n\nexport type DataKeyApi = {\n readonly get: (purpose: string) => Promise<Uint8Array>;\n};\n\n/**\n * Cloud-backup entry points. `enable` re-verifies and retains a fresh BEK in the vault; `update`\n * rewrites the sealed envelope JSON with the retained BEK (no factor ceremony, so an auto-sync can\n * run silently); `restore` merges an envelope into the vault. Factor inputs reuse `UnlockFactor` —\n * passkey assertions evaluate the PRF over `backupSalt`.\n */\nexport type BackupApi = {\n readonly enable: (options: {\n readonly verify: UnlockFactor;\n readonly factors: ReadonlyArray<UnlockFactor>;\n }) => Promise<void>;\n readonly update: () => Promise<string>;\n readonly disable: () => Promise<void>;\n readonly restore: (options: {\n readonly envelope: string;\n readonly backupFactor: UnlockFactor;\n readonly factor?: InitialFactor;\n }) => Promise<ReadonlyArray<WalletInfo>>;\n};\n\nexport type Wallet = {\n readonly getSnapshot: () => WalletSnapshot;\n readonly subscribe: (listener: () => void) => () => void;\n readonly vault: VaultApi;\n readonly wallets: WalletsApi;\n readonly dataKeys: DataKeyApi;\n readonly backup: BackupApi;\n readonly destroy: () => Promise<void>;\n};\n"],"mappings":";;AA6GA,IAAa,cAAb,cAAiC,MAAM;CACrC;CACA;CAEA,YAAY,MAAuB,SAAiB,SAAkB;EACpE,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,OAAO;EACZ,KAAK,UAAU;CACjB;AACF"}
1
+ {"version":3,"file":"types.mjs","names":[],"sources":["../src/types.ts"],"sourcesContent":["/** Public types of @qntx/wallet, per design/entry.mdx. Secret data never appears here. */\nexport type LockReason =\n | \"cold-start\"\n | \"user\"\n | \"idle\"\n | \"background\"\n | \"expired\"\n | \"crashed\"\n | \"invalidated\";\n\nexport type FactorInfo =\n | { readonly kind: \"hardware\"; readonly id: string; readonly createdAt: number }\n | {\n readonly kind: \"passkey\";\n readonly id: string;\n /** Base64url, public data — the main side passes it as allowCredentials. */\n readonly credentialId: string;\n readonly createdAt: number;\n }\n | { readonly kind: \"password\"; readonly id: string; readonly createdAt: number };\n\nexport type WalletInfo = {\n readonly walletId: string;\n readonly origin: \"passkey\" | \"mnemonic\";\n readonly words: 12 | 15 | 18 | 21 | 24;\n /**\n * Mnemonic: the user holds the phrase (passed the writing-down quiz, imported it, or exported at\n * least once). passkey: protected only by a synced passkey — still lost when the password manager\n * or account is lost, so the UI should prompt to export. none: exists only on this device (a\n * device-bound passkey).\n */\n readonly backup: \"none\" | \"passkey\" | \"mnemonic\";\n readonly createdAt: number;\n};\n\nexport type NostrKeyRef =\n | { readonly kind: \"derived\"; readonly walletId: string; readonly groupIndex: number }\n | { readonly kind: \"standalone\"; readonly id: string }\n | { readonly kind: \"nip46-client\"; readonly id: string };\n\nexport type NostrKeyInfo = {\n readonly ref: NostrKeyRef;\n readonly publicKey: string; // 64 lowercase hex\n readonly origin: \"derived\" | \"nsec\" | \"ncryptsec\" | \"generated\" | \"nip46-client\";\n /**\n * Only standalone keys carry it: derived keys recover from the wallet, nip46-client keys are\n * ephemeral.\n */\n readonly backedUp?: boolean;\n readonly createdAt: number;\n};\n\n/** One entry of a `nostr.discover` result: the public key an account group would produce. */\nexport type DerivedNostrKey = { readonly groupIndex: number; readonly publicKey: string };\n\nexport type WalletErrorCode =\n | \"locked\"\n | \"cancelled\"\n | \"factor-unavailable\"\n | \"factor-invalidated\"\n | \"wrong-password\"\n | \"wrong-passkey\"\n | \"rate-limited\"\n | \"invalid-input\"\n | \"not-found\"\n | \"already-exists\"\n | \"conflict\"\n | \"unsupported\"\n | \"unavailable\"\n | \"integrity\"\n | \"approval-required\"\n | \"crashed\";\n\n/**\n * The vault half of the status payload: `corrupted` means authentication or structural data failed\n * to verify, `unsupported` means a newer build wrote it (data untouched, update the app),\n * `unavailable` means a transient store I/O failure (retried on the next request or change).\n */\nexport type VaultState =\n | \"uninitialized\"\n | \"locked\"\n | \"unlocked\"\n | \"corrupted\"\n | \"unsupported\"\n | \"unavailable\";\n\n/**\n * `status` result / status event payload. Locked snapshots come from unauthenticated headers;\n * \"corrupted\" means the vault data itself failed to load or verify (reset is the only way out).\n * Each protocol module contributes one section (here: `nostr`).\n */\nexport type StatusPayload = {\n readonly protocol: 1;\n readonly vault: VaultState;\n readonly factors: ReadonlyArray<FactorInfo>;\n readonly wallets: ReadonlyArray<WalletInfo>;\n readonly nostr: { readonly keys: ReadonlyArray<NostrKeyInfo> };\n // oxlint-disable-next-line typescript/no-restricted-types -- wire contract: backup is null when off\n readonly backup: BackupInfo | null;\n};\n\n/** Public summary of a retained backup key — factors are the unwrap paths, never secrets. */\nexport type BackupInfo = {\n readonly id: string; // 32 lowercase hex, derived from the BEK\n readonly factors: ReadonlyArray<\"passkey\" | \"password\">;\n readonly createdAt: number;\n};\n\n/** One error class for the whole API; `code` carries the distinction. Messages never echo input. */\nexport class WalletError extends Error {\n readonly code: WalletErrorCode;\n readonly retryAt: number | undefined;\n\n constructor(code: WalletErrorCode, message: string, retryAt?: number) {\n super(message);\n this.name = \"WalletError\";\n this.code = code;\n this.retryAt = retryAt;\n }\n}\n\n/**\n * A factor the user proves again for a guarded operation. `hardware` is the React Native factor:\n * the kernel shows the system verification prompt with text it renders itself.\n */\nexport type UnlockFactor =\n | { readonly kind: \"hardware\" }\n | { readonly kind: \"passkey\" }\n | { readonly kind: \"password\"; readonly password: string };\n\n/**\n * A factor being created; `hardware` exists only on React Native. `name` is the passkey\n * credential's display name — the host validates it before the ceremony (1–64 characters).\n */\nexport type InitialFactor =\n | { readonly kind: \"hardware\" }\n | { readonly kind: \"passkey\"; readonly name: string }\n | { readonly kind: \"password\"; readonly password: string };\n\n/**\n * WebAuthn RP identity + PRF salt labels the host configures once. `rpId`, `walletSalt` and\n * `vaultSalt` are permanent identifiers: changing any of them makes every existing passkey factor\n * and passkey-derived wallet unrecoverable, and the two salts must differ. Moving a wallet to a\n * different domain requires WebAuthn related origins (`/.well-known/webauthn`); hosts should offer\n * `exportMnemonic` for passkey-derived wallets so they survive an RP migration.\n */\nexport type PasskeyConfig = {\n /** RP id — the origin's effective domain or a registrable parent of it (e.g. meowl.social). */\n readonly rpId: string;\n readonly rpName: string;\n readonly walletSalt: string;\n readonly vaultSalt: string;\n /** PRF salt for the cloud-backup factor — a third, distinct permanent label. */\n readonly backupSalt: string;\n};\n\nexport type AutoLockPolicy =\n | { readonly platform: \"native\"; readonly backgroundSeconds: 0 | 60 | 300 | 900 }\n | { readonly platform: \"web\"; readonly idleMinutes: 5 | 15 | 60 };\n\nexport type WalletOptions = {\n readonly passkey: PasskeyConfig;\n readonly autoLock: AutoLockPolicy;\n};\n\nexport type WalletSnapshot = {\n readonly vault: VaultState;\n readonly lockReason: LockReason | undefined;\n readonly verifying: boolean; // a user verification is in flight\n readonly factors: ReadonlyArray<FactorInfo>;\n readonly wallets: ReadonlyArray<WalletInfo>;\n readonly nostr: { readonly keys: ReadonlyArray<NostrKeyInfo> };\n /** The retained backup key's public id, or null when cloud backup is off. */\n // oxlint-disable-next-line typescript/no-restricted-types -- wire contract: backup is null when off\n readonly backup: BackupInfo | null;\n};\n\n/** A one-shot secret buffer: `read` detaches the bytes to the caller, `wipe` zeroes them. */\nexport type ExportedSecret = {\n readonly read: () => Uint8Array; // UTF-8 text; single use — the second call throws\n readonly wipe: () => void;\n};\n\nexport type MnemonicDraft = {\n readonly words: ExportedSecret; // read once, then the host is responsible for wiping\n readonly quiz: ReadonlyArray<number>; // three positions the enclave picked\n readonly confirm: (answers: ReadonlyArray<string>) => Promise<WalletInfo>;\n readonly discard: () => Promise<void>;\n};\n\nexport type VaultApi = {\n readonly unlock: (factor?: UnlockFactor) => Promise<void>;\n readonly lock: () => Promise<void>;\n readonly addFactor: (factor: InitialFactor, verify: UnlockFactor) => Promise<FactorInfo>;\n readonly removeFactor: (id: string, verify: UnlockFactor) => Promise<void>; // ≥1 factor remains\n readonly reset: () => Promise<void>;\n};\n\nexport type WalletsApi = {\n readonly createWithPasskey: (options: {\n /** Display name for the new passkey credential (1–64 characters after trimming). */\n readonly name: string;\n readonly factor?: InitialFactor;\n }) => Promise<WalletInfo>;\n readonly restoreWithPasskey: (options?: {\n readonly factor?: InitialFactor;\n }) => Promise<WalletInfo>;\n readonly createMnemonic: (options: {\n readonly words: 12 | 24;\n readonly factor?: InitialFactor;\n }) => Promise<MnemonicDraft>;\n readonly importMnemonic: (options: {\n readonly mnemonic: string;\n readonly factor?: InitialFactor;\n }) => Promise<WalletInfo>;\n /** One-shot mnemonic export; requires re-verification every call. */\n readonly exportMnemonic: (walletId: string, verify: UnlockFactor) => Promise<ExportedSecret>;\n readonly delete: (walletId: string, verify: UnlockFactor) => Promise<void>;\n};\n\nexport type DataKeyApi = {\n readonly get: (purpose: string) => Promise<Uint8Array>;\n};\n\n/**\n * Cloud-backup entry points. `enable` re-verifies and retains a fresh BEK in the vault; `update`\n * rewrites the sealed envelope JSON with the retained BEK (no factor ceremony, so an auto-sync can\n * run silently); `restore` merges an envelope into the vault. Factor inputs reuse `UnlockFactor` —\n * passkey assertions evaluate the PRF over `backupSalt`.\n */\nexport type BackupApi = {\n readonly enable: (options: {\n readonly verify: UnlockFactor;\n readonly factors: ReadonlyArray<UnlockFactor>;\n }) => Promise<void>;\n readonly update: () => Promise<string>;\n readonly disable: () => Promise<void>;\n readonly restore: (options: {\n readonly envelope: string;\n readonly backupFactor: UnlockFactor;\n readonly factor?: InitialFactor;\n }) => Promise<ReadonlyArray<WalletInfo>>;\n};\n\nexport type Wallet = {\n readonly getSnapshot: () => WalletSnapshot;\n readonly subscribe: (listener: () => void) => () => void;\n readonly vault: VaultApi;\n readonly wallets: WalletsApi;\n readonly dataKeys: DataKeyApi;\n readonly backup: BackupApi;\n readonly destroy: () => Promise<void>;\n};\n"],"mappings":";;AA6GA,IAAa,cAAb,cAAiC,MAAM;CACrC;CACA;CAEA,YAAY,MAAuB,SAAiB,SAAkB;EACpE,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,OAAO;EACZ,KAAK,UAAU;CACjB;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qntx/wallet",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Self-custodial wallet SDK: Wallet host entry, protocol and types",
5
5
  "keywords": [
6
6
  "sdk",
@@ -57,18 +57,22 @@
57
57
  "import": "./dist/types.mjs",
58
58
  "default": "./dist/types.mjs"
59
59
  },
60
- "./package.json": "./package.json"
60
+ "./package.json": "./package.json",
61
+ "./chains": {
62
+ "types": "./dist/chains.d.mts",
63
+ "default": "./dist/chains.mjs"
64
+ }
61
65
  },
62
66
  "publishConfig": {
63
67
  "access": "public"
64
68
  },
65
69
  "scripts": {
66
- "build": "vp pack",
70
+ "build": "vp run @qntx/wallet-chains#build && vp pack",
67
71
  "dev": "vp pack --watch",
68
72
  "test": "vp test",
69
73
  "test:coverage": "vp test --coverage",
70
74
  "typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.src.json",
71
- "check:pkg": "vp pack && bun run check:chunks && publint && attw --pack . --profile esm-only",
75
+ "check:pkg": "vp run @qntx/wallet-chains#build && vp pack && bun ../../scripts/check-dist-deps.ts . && bun run check:chunks && publint && attw --pack . --profile esm-only",
72
76
  "check:chunks": "bun scripts/check-nostr-free.ts",
73
77
  "pack:local": "vp pack && bun pm pack"
74
78
  },
@@ -77,9 +81,13 @@
77
81
  },
78
82
  "devDependencies": {
79
83
  "@arethetypeswrong/cli": "0.18.5",
80
- "@qntx/nostr": "0.15.0",
81
- "@qntx/spark": "0.5.0",
84
+ "@qntx/nostr": "0.15.3",
85
+ "@qntx/spark": "0.5.2",
82
86
  "@qntx/tsconfig": "1.0.1",
87
+ "@qntx/wallet-chains": "0.5.0",
88
+ "@scure/bip32": "2.4.0",
89
+ "@scure/bip39": "2.4.0",
90
+ "@scure/btc-signer": "2.4.1",
83
91
  "@types/node": "26.6.5",
84
92
  "publint": "0.3.25",
85
93
  "typescript": "7.0.2",
@@ -87,7 +95,8 @@
87
95
  },
88
96
  "peerDependencies": {
89
97
  "@qntx/nostr": "^0.15.0",
90
- "@qntx/spark": "^0.5.0"
98
+ "@qntx/spark": "^0.5.0",
99
+ "@qntx/wallet-chains": "0.5.0"
91
100
  },
92
101
  "peerDependenciesMeta": {
93
102
  "@qntx/nostr": {
@@ -95,6 +104,9 @@
95
104
  },
96
105
  "@qntx/spark": {
97
106
  "optional": true
107
+ },
108
+ "@qntx/wallet-chains": {
109
+ "optional": true
98
110
  }
99
111
  },
100
112
  "devEngines": {
@@ -1 +0,0 @@
1
- {"version":3,"file":"core-QJ66nLLG.mjs","names":[],"sources":["../src/protocol/validate.ts","../src/protocol/core.ts"],"sourcesContent":["/**\n * Strict validator combinators for the secret-area protocol. Both sides share them: the kernel\n * validates every request, the host validates every response. Anything that does not match is a\n * `ValidationError` — never a partially-accepted value.\n */\nimport type { NullValue } from \"./index.ts\";\n\nexport class ValidationError extends Error {\n override name = \"ValidationError\";\n}\n\nexport type Validator<T> = (value: unknown) => T;\n\nfunction fail(): never {\n throw new ValidationError();\n}\n\nexport function literal<T extends NullValue | boolean | number | string>(\n expected: T,\n): Validator<T> {\n return (value) => {\n if (value !== expected) {\n fail();\n }\n return expected;\n };\n}\n\nexport const nullValue: Validator<NullValue> = literal(null);\nexport const bool: Validator<boolean> = (value) => {\n if (typeof value !== \"boolean\") {\n fail();\n }\n return value;\n};\n\nexport function int(min: number, max: number): Validator<number> {\n return (value) => {\n if (typeof value !== \"number\" || !Number.isSafeInteger(value) || value < min || value > max) {\n fail();\n }\n return value;\n };\n}\n\nexport function str(max: number, pattern?: RegExp): Validator<string> {\n return (value) => {\n if (\n typeof value !== \"string\" ||\n value.length > max ||\n (pattern !== undefined && !pattern.test(value))\n ) {\n fail();\n }\n return value;\n };\n}\n\nexport function bytes(min: number, max?: number): Validator<Uint8Array> {\n const high = max ?? min;\n return (value) => {\n if (!(value instanceof Uint8Array) || value.length < min || value.length > high) {\n fail();\n }\n return value;\n };\n}\n\nexport function arr<T>(item: Validator<T>, max: number, min = 0): Validator<ReadonlyArray<T>> {\n return (value) => {\n if (!Array.isArray(value) || value.length < min || value.length > max) {\n fail();\n }\n const out: T[] = [];\n for (const element of value) {\n out.push(item(element));\n }\n return out;\n };\n}\n\nclass Opt<T> {\n readonly validator: Validator<T>;\n\n constructor(validator: Validator<T>) {\n this.validator = validator;\n }\n}\n\nexport function opt<T>(validator: Validator<T>): Opt<T> {\n return new Opt(validator);\n}\n\ntype Field = Validator<unknown> | Opt<unknown>;\ntype Shape = Record<string, Field>;\n\ntype RequiredKeys<S extends Shape> = {\n readonly [K in keyof S as S[K] extends Opt<unknown> ? never : K]: S[K] extends Validator<infer T>\n ? T\n : never;\n};\ntype OptionalKeys<S extends Shape> = {\n readonly [K in keyof S as S[K] extends Opt<unknown> ? K : never]?: S[K] extends Opt<infer T>\n ? T\n : never;\n};\ntype ShapeResult<S extends Shape> = RequiredKeys<S> & OptionalKeys<S>;\n\n/** Exact key set: required keys present, optional keys allowed, nothing else. */\nexport function obj<S extends Shape>(shape: S): Validator<ShapeResult<S>> {\n const keys = Object.keys(shape);\n return (value) => {\n if (\n typeof value !== \"object\" ||\n value === null ||\n Array.isArray(value) ||\n value instanceof Uint8Array\n ) {\n fail();\n }\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- narrowed to a plain object above\n const record = value as Record<string, unknown>;\n for (const key of Object.keys(record)) {\n if (!Object.hasOwn(shape, key)) {\n fail();\n }\n }\n const out: Record<string, unknown> = {};\n for (const key of keys) {\n const field = shape[key];\n if (field === undefined) {\n fail();\n }\n const raw = record[key];\n if (field instanceof Opt) {\n if (raw !== undefined) {\n out[key] = field.validator(raw);\n }\n } else {\n if (!Object.hasOwn(record, key)) {\n fail();\n }\n out[key] = field(raw);\n }\n }\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- the shape guarantees the keys\n return out as ShapeResult<S>;\n };\n}\n\nconst FORBIDDEN_RECORD_KEYS = new Set([\"__proto__\", \"constructor\", \"prototype\"]);\n\n/**\n * A `Record<K, V>` wire value: plain objects only, every key checked by `key`, every value by\n * `value`, at most `max` entries. Prototype-polluting keys are rejected outright — a validated\n * record must be safe to copy key-by-key.\n */\nexport function record<K extends string, V>(\n key: Validator<K>,\n value: Validator<V>,\n max: number,\n): Validator<Record<K, V>> {\n return (input) => {\n if (\n typeof input !== \"object\" ||\n input === null ||\n Array.isArray(input) ||\n input instanceof Uint8Array ||\n Object.getPrototypeOf(input) !== Object.prototype\n ) {\n fail();\n }\n const out: Record<string, V> = {};\n const entries = Object.entries(input);\n if (entries.length > max) {\n fail();\n }\n for (const [name, item] of entries) {\n if (FORBIDDEN_RECORD_KEYS.has(name)) {\n fail();\n }\n out[key(name)] = value(item);\n }\n return out;\n };\n}\n\n/** Tries each branch in order; the first match wins. */\nexport function union<Vs extends ReadonlyArray<Validator<unknown>>>(\n ...branches: Vs\n): Validator<ReturnType<Vs[number]>> {\n return (value) => {\n for (const branch of branches) {\n try {\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- ReturnType of the branch union\n return branch(value) as ReturnType<Vs[number]>;\n } catch (error) {\n if (!(error instanceof ValidationError)) {\n throw error;\n }\n }\n }\n return fail();\n };\n}\n\n/** Validates a value and returns it, or undefined on a shape mismatch. */\nexport function validate<T>(validator: Validator<T>, value: unknown): T | undefined {\n try {\n return validator(value);\n } catch (error) {\n if (error instanceof ValidationError) {\n return undefined;\n }\n throw error;\n }\n}\n","/**\n * The core method table: vault, wallet and data-key commands — nothing protocol-specific. \"Create\n * or import\" commands (createWithPasskey/restoreWithPasskey/createMnemonic/importMnemonic) are\n * `session: false` here because the rule is dynamic: with an uninitialized vault they carry\n * `factor` and establish the vault in one commit; with an established vault `factor` must be absent\n * and a valid session is required.\n *\n * The shared wire validators (factor, wallet info, ids) live here too so the nostr module's table\n * can reuse them — `protocol/nostr.ts` imports only from this file.\n */\nimport type { FactorInfo, WalletErrorCode, WalletInfo } from \"../types.ts\";\nimport type { NullValue } from \"./index.ts\";\nimport type { Validator } from \"./validate.ts\";\nimport { arr, bool, bytes, int, literal, nullValue, obj, opt, str, union } from \"./validate.ts\";\n\nexport type MethodSpec<P, R> = {\n readonly session: boolean;\n /** Whether a successful call refreshes the idle timer — presence-bearing methods only. */\n readonly presence: boolean;\n readonly params: Validator<P>;\n readonly result: Validator<R>;\n};\n\n// Size caps (UTF-16 units for strings, bytes for Uint8Array). These bound individual fields; the\n// whole-request cap MAX_REQUEST_BYTES (protocol/index.ts) is enforced by host and kernel.\nexport const MAX_TEXT = 262_144;\nexport const MAX_TAGS = 1024;\nexport const MAX_TAG_ITEMS = 64;\nexport const MAX_TAG_ITEM = 4096;\nexport const MAX_BATCH = 64;\nexport const MAX_SNAPSHOT_ITEMS = 4096;\n\nexport const sessionId: Validator<string> = str(32, /^[0-9a-f]{32}$/);\nexport const draftId: Validator<string> = str(32, /^[0-9a-f]{32}$/);\nexport const walletId: Validator<string> = str(16, /^[0-9a-f]{16}$/);\nexport const publicKey: Validator<string> = str(64, /^[0-9a-f]{64}$/);\nexport const credentialId: Validator<string> = str(1364, /^[A-Za-z0-9_-]+$/);\nexport const safeTime: Validator<number> = int(0, Number.MAX_SAFE_INTEGER);\nexport const groupIndex: Validator<number> = int(0, 0x7fffffff);\n\nexport type Factor =\n | { readonly kind: \"password\"; readonly password: Uint8Array }\n | { readonly kind: \"passkey\"; readonly credentialId: Uint8Array; readonly prf: Uint8Array };\n\nexport const factor: Validator<Factor> = union(\n obj({ kind: literal(\"password\"), password: bytes(1, 1024) }),\n obj({ kind: literal(\"passkey\"), credentialId: bytes(1, 1023), prf: bytes(32) }),\n);\n\n/**\n * A backup-envelope factor: same shapes as `Factor`, except the passkey arm carries `prfBackup` —\n * the PRF evaluated over `backupSalt`, not the vault or wallet salt.\n */\nexport type BackupFactor =\n | { readonly kind: \"password\"; readonly password: Uint8Array }\n | {\n readonly kind: \"passkey\";\n readonly credentialId: Uint8Array;\n readonly prfBackup: Uint8Array;\n };\n\nexport const backupFactor: Validator<BackupFactor> = union(\n obj({ kind: literal(\"password\"), password: bytes(1, 1024) }),\n obj({ kind: literal(\"passkey\"), credentialId: bytes(1, 1023), prfBackup: bytes(32) }),\n);\n\nexport const factorInfo: Validator<FactorInfo> = union(\n obj({ kind: literal(\"hardware\") }),\n obj({\n kind: literal(\"passkey\"),\n id: sessionId,\n credentialId,\n createdAt: safeTime,\n }),\n obj({ kind: literal(\"password\"), id: sessionId, createdAt: safeTime }),\n);\n\nexport const walletInfo: Validator<WalletInfo> = obj({\n walletId,\n origin: union(literal(\"passkey\"), literal(\"mnemonic\")),\n words: union(literal(12), literal(15), literal(18), literal(21), literal(24)),\n backup: union(literal(\"none\"), literal(\"passkey\"), literal(\"mnemonic\")),\n createdAt: safeTime,\n});\n\nexport const walletErrorCode: Validator<WalletErrorCode> = union(\n literal(\"locked\"),\n literal(\"cancelled\"),\n literal(\"factor-unavailable\"),\n literal(\"factor-invalidated\"),\n literal(\"wrong-password\"),\n literal(\"wrong-passkey\"),\n literal(\"rate-limited\"),\n literal(\"invalid-input\"),\n literal(\"not-found\"),\n literal(\"already-exists\"),\n literal(\"conflict\"),\n literal(\"unsupported\"),\n literal(\"unavailable\"),\n literal(\"integrity\"),\n literal(\"approval-required\"),\n literal(\"crashed\"),\n);\n\n/**\n * The result of every \"create or import\" wallet command: the new wallet's public info plus the\n * session it opened. Creating a wallet derives no protocol keys — modules add keys separately.\n */\nexport type CreatedResult = {\n readonly wallet: WalletInfo;\n readonly session: string;\n};\n\nconst createdResult: Validator<CreatedResult> = obj({ wallet: walletInfo, session: sessionId });\n\n// `status` itself is a core method, but its result validator composes every module's status\n// section — it is wired in protocol/index.ts, not here.\nexport const CORE_METHODS: {\n readonly \"vault.unlock\": MethodSpec<{ readonly factor: Factor }, { readonly session: string }>;\n readonly \"vault.reset\": MethodSpec<NullValue, NullValue>;\n readonly \"vault.addFactor\": MethodSpec<\n { readonly verify: Factor; readonly factor: Factor },\n FactorInfo\n >;\n readonly \"vault.removeFactor\": MethodSpec<\n { readonly verify: Factor; readonly id: string },\n NullValue\n >;\n readonly \"session.touch\": MethodSpec<NullValue, NullValue>;\n readonly \"wallet.createWithPasskey\": MethodSpec<\n {\n readonly credentialId: Uint8Array;\n readonly prfWallet: Uint8Array;\n readonly synced: boolean;\n readonly factor?: Factor;\n },\n CreatedResult\n >;\n readonly \"wallet.restoreWithPasskey\": MethodSpec<\n {\n readonly credentialId: Uint8Array;\n readonly prfWallet: Uint8Array;\n readonly synced: boolean;\n readonly factor?: Factor;\n },\n CreatedResult\n >;\n readonly \"wallet.createMnemonic\": MethodSpec<\n { readonly words: 12 | 24; readonly factor?: Factor },\n { readonly draft: string; readonly words: Uint8Array; readonly quiz: ReadonlyArray<number> }\n >;\n readonly \"wallet.confirmMnemonic\": MethodSpec<\n { readonly draft: string; readonly answers: ReadonlyArray<Uint8Array> },\n CreatedResult\n >;\n readonly \"wallet.discardMnemonic\": MethodSpec<{ readonly draft: string }, NullValue>;\n readonly \"backup.enable\": MethodSpec<\n {\n readonly verify: Factor;\n readonly factors: ReadonlyArray<BackupFactor>;\n },\n NullValue\n >;\n readonly \"backup.update\": MethodSpec<NullValue, { readonly envelope: string }>;\n readonly \"backup.disable\": MethodSpec<NullValue, NullValue>;\n readonly \"backup.restore\": MethodSpec<\n {\n readonly envelope: string;\n readonly backupFactor: BackupFactor;\n readonly factor?: Factor;\n },\n { readonly wallets: ReadonlyArray<WalletInfo>; readonly session: string }\n >;\n readonly \"wallet.importMnemonic\": MethodSpec<\n { readonly mnemonic: Uint8Array; readonly factor?: Factor },\n CreatedResult\n >;\n readonly \"wallet.exportMnemonic\": MethodSpec<\n { readonly verify: Factor; readonly walletId: string },\n Uint8Array\n >;\n readonly \"wallet.delete\": MethodSpec<\n { readonly verify: Factor; readonly walletId: string },\n NullValue\n >;\n readonly \"dataKeys.get\": MethodSpec<{ readonly purpose: string }, Uint8Array>;\n} = {\n \"session.touch\": {\n session: true,\n presence: true,\n params: nullValue,\n result: nullValue,\n },\n \"vault.unlock\": {\n session: false,\n presence: true,\n params: obj({ factor }),\n result: obj({ session: sessionId }),\n },\n \"vault.reset\": { session: false, presence: false, params: nullValue, result: nullValue },\n \"vault.addFactor\": {\n session: true,\n presence: true,\n params: obj({ verify: factor, factor }),\n result: factorInfo,\n },\n \"vault.removeFactor\": {\n session: true,\n presence: true,\n params: obj({ verify: factor, id: sessionId }),\n result: nullValue,\n },\n \"wallet.createWithPasskey\": {\n session: false,\n presence: true,\n params: obj({\n credentialId: bytes(1, 1023),\n prfWallet: bytes(32),\n synced: bool,\n factor: opt(factor),\n }),\n result: createdResult,\n },\n \"wallet.restoreWithPasskey\": {\n session: false,\n presence: true,\n params: obj({\n credentialId: bytes(1, 1023),\n prfWallet: bytes(32),\n synced: bool,\n factor: opt(factor),\n }),\n result: createdResult,\n },\n \"wallet.createMnemonic\": {\n session: false,\n presence: true,\n params: obj({ words: union(literal(12), literal(24)), factor: opt(factor) }),\n result: obj({\n draft: draftId,\n words: bytes(16, 1024),\n quiz: arr(int(0, 23), 3, 3),\n }),\n },\n \"wallet.confirmMnemonic\": {\n session: false,\n presence: true,\n params: obj({ draft: draftId, answers: arr(bytes(1, 64), 3, 3) }),\n result: createdResult,\n },\n \"wallet.discardMnemonic\": {\n session: false,\n presence: false,\n params: obj({ draft: draftId }),\n result: nullValue,\n },\n \"backup.enable\": {\n session: true,\n presence: true,\n params: obj({ verify: factor, factors: arr(backupFactor, 5, 1) }),\n result: nullValue,\n },\n \"backup.update\": {\n session: true,\n presence: false,\n params: nullValue,\n result: obj({ envelope: str(4_000_000) }),\n },\n \"backup.disable\": {\n session: true,\n presence: true,\n params: nullValue,\n result: nullValue,\n },\n \"backup.restore\": {\n session: false,\n presence: true,\n params: obj({ envelope: str(4_000_000), backupFactor, factor: opt(factor) }),\n result: obj({ wallets: arr(walletInfo, 1000), session: sessionId }),\n },\n \"wallet.importMnemonic\": {\n session: false,\n presence: true,\n params: obj({ mnemonic: bytes(1, 1024), factor: opt(factor) }),\n result: createdResult,\n },\n \"wallet.exportMnemonic\": {\n session: true,\n presence: true,\n params: obj({ verify: factor, walletId }),\n result: bytes(16, 1024),\n },\n \"wallet.delete\": {\n session: true,\n presence: true,\n params: obj({ verify: factor, walletId }),\n result: nullValue,\n },\n \"dataKeys.get\": {\n session: true,\n presence: false,\n params: obj({ purpose: str(32, /^[a-z0-9-]{1,32}$/) }),\n result: bytes(32),\n },\n};\n"],"mappings":";AAOA,IAAa,kBAAb,cAAqC,MAAM;CACzC,OAAgB;AAClB;AAIA,SAAS,OAAc;CACrB,MAAM,IAAI,gBAAgB;AAC5B;AAEA,SAA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