@qntx/wallet 0.12.0 → 0.14.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.
Files changed (56) hide show
  1. package/README.md +145 -22
  2. package/dist/backup-CLzMs8DP.mjs +51 -0
  3. package/dist/backup-CLzMs8DP.mjs.map +1 -0
  4. package/dist/card.d.mts +12 -0
  5. package/dist/card.mjs +119 -0
  6. package/dist/card.mjs.map +1 -0
  7. package/dist/{chains-BSP0x9RI.d.mts → chains-u1M0CWkT.d.mts} +175 -26
  8. package/dist/chains.d.mts +11 -4
  9. package/dist/chains.mjs +19 -62
  10. package/dist/chains.mjs.map +1 -1
  11. package/dist/{channel-BQg--l_3.mjs → channel-BCZXU3pt.mjs} +105 -44
  12. package/dist/channel-BCZXU3pt.mjs.map +1 -0
  13. package/dist/check-C1fUpgva.mjs +193 -0
  14. package/dist/check-C1fUpgva.mjs.map +1 -0
  15. package/dist/{core-DDfzuSIa.mjs → core-Cx7p-0nG.mjs} +136 -15
  16. package/dist/core-Cx7p-0nG.mjs.map +1 -0
  17. package/dist/hardware-BL6zvhQh.d.mts +107 -0
  18. package/dist/hardware.d.mts +81 -0
  19. package/dist/hardware.mjs +446 -0
  20. package/dist/hardware.mjs.map +1 -0
  21. package/dist/host.d.mts +27 -19
  22. package/dist/host.mjs +471 -144
  23. package/dist/host.mjs.map +1 -1
  24. package/dist/{index-DDyJ9KqA.d.mts → index-UclKfprm.d.mts} +274 -18
  25. package/dist/index.d.mts +5 -3
  26. package/dist/index.mjs +3 -33
  27. package/dist/{internal-CAKfHjIg.mjs → internal-DwCus_Ws.mjs} +1 -6
  28. package/dist/internal-DwCus_Ws.mjs.map +1 -0
  29. package/dist/nostr.d.mts +2 -2
  30. package/dist/nostr.mjs +14 -14
  31. package/dist/nostr.mjs.map +1 -1
  32. package/dist/{protocol-C8x0H3Rr.mjs → protocol-DLE6lHmP.mjs} +493 -52
  33. package/dist/protocol-DLE6lHmP.mjs.map +1 -0
  34. package/dist/protocol.d.mts +5 -4
  35. package/dist/protocol.mjs +3 -3
  36. package/dist/secret-CbjbY5-f.mjs +25 -0
  37. package/dist/secret-CbjbY5-f.mjs.map +1 -0
  38. package/dist/sessions.d.mts +52 -0
  39. package/dist/sessions.mjs +71 -0
  40. package/dist/sessions.mjs.map +1 -0
  41. package/dist/spark.d.mts +3 -3
  42. package/dist/spark.mjs +5 -8
  43. package/dist/spark.mjs.map +1 -1
  44. package/dist/types-CRnacSqJ.d.mts +390 -0
  45. package/dist/types.d.mts +2 -2
  46. package/dist/types.mjs +7 -1
  47. package/dist/types.mjs.map +1 -1
  48. package/package.json +27 -13
  49. package/dist/channel-BQg--l_3.mjs.map +0 -1
  50. package/dist/core-DDfzuSIa.mjs.map +0 -1
  51. package/dist/index.mjs.map +0 -1
  52. package/dist/internal-CAKfHjIg.mjs.map +0 -1
  53. package/dist/protocol-C8x0H3Rr.mjs.map +0 -1
  54. package/dist/secret-CcjyF8D3.mjs +0 -205
  55. package/dist/secret-CcjyF8D3.mjs.map +0 -1
  56. package/dist/types-Dub5eUl3.d.mts +0 -239
@@ -1 +0,0 @@
1
- {"version":3,"file":"secret-CcjyF8D3.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, \"passkey-prf-unsupported\" when the credential cannot produce a PRF. `name` is\n * the new 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(\"unsupported\", \"this host unlocks only with the hardware factor\");\n}\n\nfunction noHardware(): WalletError {\n return new WalletError(\"unsupported\", \"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\n/** The `passphrase` wire field for a BIP-39 passphrase: absent for none (undefined or \"\"). */\nexport function wirePassphrase(\n text: string | undefined,\n transfer: ArrayBuffer[],\n): { readonly passphrase?: Uint8Array } {\n return text === undefined || text === \"\" ? {} : { passphrase: wireSecretText(text, transfer) };\n}\n\nexport function requireCeremony(source: FactorSource): PasskeyCeremony {\n if (source.ceremony === undefined) {\n throw new WalletError(\"unsupported\", \"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 / passkey-prf-unsupported).\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(\n \"passkey-prf-unsupported\",\n \"the ceremony returned no vault PRF output\",\n );\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.bytes = undefined;\n }\n}\n"],"mappings":";;;;;;;;;AAcA,MAAa,yBAAyB;AACtC,MAAa,wBAAwB;AA4CrC,MAAM,WAAmB,EAAE,MAAM,WAAW;AAE5C,SAAS,eAA4B;CACnC,OAAO,IAAI,YAAY,eAAe,iDAAiD;AACzF;AAEA,SAAS,aAA0B;CACjC,OAAO,IAAI,YAAY,eAAe,6CAA6C;AACrF;;AAGA,SAAgB,oBAAoB,QAAoC;CACtE,OAAO,OAAO,SAAS,aAAa,EAAE,MAAM,WAAW,IAAI,EAAE,MAAM,UAAU;AAC/E;AAEA,SAAgB,eAAe,QAAkC;CAC/D,OAAO,IAAI,YAAY,CAAC,CAAC,OAAO,OAAO,QAAQ,SAAS;AAC1D;AAEA,SAAgB,gBAAgB,QAAkC;CAChE,OAAO,IAAI,YAAY,CAAC,CAAC,OAAO,OAAO,QAAQ,UAAU;AAC3D;AAEA,SAAgB,gBAAgB,QAAkC;CAChE,OAAO,IAAI,Y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ACX,KAAK,OAAO,KAAK,CAAC;EAClB,KAAK,QAAQ,KAAA;CACf;AACF"}
@@ -1,239 +0,0 @@
1
- /** Public types of @qntx/wallet, per design/entry.mdx. Secret data never appears here. */
2
- type LockReason = "cold-start" | "user" | "idle" | "background" | "expired" | "crashed" | "invalidated";
3
- type FactorInfo = {
4
- readonly kind: "hardware";
5
- readonly id: string;
6
- readonly createdAt: number;
7
- } | {
8
- readonly kind: "passkey";
9
- readonly id: string;
10
- /** Base64url, public data — the main side passes it as allowCredentials. */
11
- readonly credentialId: string;
12
- readonly createdAt: number;
13
- } | {
14
- readonly kind: "password";
15
- readonly id: string;
16
- readonly createdAt: number;
17
- };
18
- type WalletInfo = {
19
- readonly walletId: string;
20
- readonly origin: "passkey" | "mnemonic";
21
- readonly words: 12 | 15 | 18 | 21 | 24;
22
- /**
23
- * Mnemonic: the user holds the phrase (passed the writing-down quiz, imported it, or exported at
24
- * least once). passkey: protected only by a synced passkey — still lost when the password manager
25
- * or account is lost, so the UI should prompt to export. none: exists only on this device (a
26
- * device-bound passkey).
27
- */
28
- readonly backup: "none" | "passkey" | "mnemonic";
29
- /** The wallet derives from its mnemonic plus a BIP-39 passphrase; only mnemonic wallets can. */
30
- readonly passphrase: boolean;
31
- readonly createdAt: number;
32
- };
33
- type NostrKeyRef = {
34
- readonly kind: "derived";
35
- readonly walletId: string;
36
- readonly index: number;
37
- };
38
- type NostrKeyInfo = {
39
- readonly ref: NostrKeyRef;
40
- readonly publicKey: string;
41
- readonly createdAt: number;
42
- };
43
- /** One entry of a `nostr.discover` result: the public key an identity index produces. */
44
- type DerivedNostrKey = {
45
- readonly index: number;
46
- readonly publicKey: string;
47
- };
48
- type WalletErrorCode = "locked" | "cancelled" | "factor-invalidated" | "no-device-credential" | "passkey-not-configured" | "passkey-prf-unsupported" | "wrong-password" | "wrong-passkey" | "rate-limited" | "invalid-input" | "not-found" | "already-exists" | "conflict" | "unsupported" | "unavailable" | "integrity" | "approval-required" | "crashed";
49
- /**
50
- * The vault half of the status payload: `corrupted` means authentication or structural data failed
51
- * to verify, `unsupported` means a newer build wrote it (data untouched, update the app),
52
- * `unavailable` means a transient store I/O failure (retried on the next request or change).
53
- */
54
- type VaultState = "uninitialized" | "locked" | "unlocked" | "corrupted" | "unsupported" | "unavailable";
55
- /**
56
- * `status` result / status event payload. Locked snapshots come from unauthenticated headers;
57
- * "corrupted" means the vault data itself failed to load or verify (reset is the only way out).
58
- * Each protocol module contributes one section (here: `nostr`).
59
- */
60
- type StatusPayload = {
61
- readonly protocol: 2;
62
- readonly vault: VaultState;
63
- readonly factors: ReadonlyArray<FactorInfo>;
64
- readonly wallets: ReadonlyArray<WalletInfo>;
65
- readonly nostr: {
66
- readonly keys: ReadonlyArray<NostrKeyInfo>;
67
- };
68
- readonly backup: BackupInfo | null;
69
- };
70
- /** Public summary of a retained backup key — factors are the unwrap paths, never secrets. */
71
- type BackupInfo = {
72
- readonly id: string;
73
- readonly factors: ReadonlyArray<"passkey" | "password">;
74
- readonly createdAt: number;
75
- };
76
- /** One error class for the whole API; `code` carries the distinction. Messages never echo input. */
77
- declare class WalletError extends Error {
78
- readonly code: WalletErrorCode;
79
- readonly retryAt: number | undefined;
80
- /**
81
- * A platform diagnostic as `"<domain>:<code>"` (e.g. `"LAErrorDomain:-5"`,
82
- * `"android:KeyPermanentlyInvalidatedException"`): never userInfo, localized text or input.
83
- */
84
- readonly detail: string | undefined;
85
- constructor(code: WalletErrorCode, message: string, retryAt?: number, detail?: string);
86
- }
87
- /**
88
- * A factor the user proves again for a guarded operation. `hardware` is the React Native factor:
89
- * the kernel shows the system verification prompt with text it renders itself.
90
- */
91
- type UnlockFactor = {
92
- readonly kind: "hardware";
93
- } | {
94
- readonly kind: "passkey";
95
- } | {
96
- readonly kind: "password";
97
- readonly password: string;
98
- };
99
- /**
100
- * A factor being created; `hardware` exists only on React Native. `name` is the passkey
101
- * credential's display name — the host validates it before the ceremony (1–64 characters).
102
- */
103
- type InitialFactor = {
104
- readonly kind: "hardware";
105
- } | {
106
- readonly kind: "passkey";
107
- readonly name: string;
108
- } | {
109
- readonly kind: "password";
110
- readonly password: string;
111
- };
112
- /**
113
- * WebAuthn RP identity + PRF salt labels the host configures once. `rpId`, `walletSalt` and
114
- * `vaultSalt` are permanent identifiers: changing any of them makes every existing passkey factor
115
- * and passkey-derived wallet unrecoverable, and the two salts must differ. Moving a wallet to a
116
- * different domain requires WebAuthn related origins (`/.well-known/webauthn`); hosts should offer
117
- * `exportMnemonic` for passkey-derived wallets so they survive an RP migration.
118
- */
119
- type PasskeyConfig = {
120
- /** RP id — the origin's effective domain or a registrable parent of it (e.g. meowl.social). */
121
- readonly rpId: string;
122
- readonly rpName: string;
123
- readonly walletSalt: string;
124
- readonly vaultSalt: string;
125
- /** PRF salt for the cloud-backup factor — a third, distinct permanent label. */
126
- readonly backupSalt: string;
127
- };
128
- type AutoLockPolicy = {
129
- readonly platform: "native";
130
- readonly backgroundSeconds: 0 | 60 | 300 | 900;
131
- } | {
132
- readonly platform: "web";
133
- readonly idleMinutes: 5 | 15 | 60;
134
- };
135
- type WalletSnapshot = {
136
- readonly vault: VaultState;
137
- readonly lockReason: LockReason | undefined;
138
- readonly verifying: boolean;
139
- readonly factors: ReadonlyArray<FactorInfo>;
140
- readonly wallets: ReadonlyArray<WalletInfo>;
141
- readonly nostr: {
142
- readonly keys: ReadonlyArray<NostrKeyInfo>;
143
- };
144
- /** The retained backup key's public id, or null when cloud backup is off. */
145
- readonly backup: BackupInfo | null;
146
- };
147
- /** A one-shot secret buffer: `read` detaches the bytes to the caller, `wipe` zeroes them. */
148
- type ExportedSecret = {
149
- readonly read: () => Uint8Array;
150
- readonly wipe: () => void;
151
- };
152
- /** What `exportMnemonic` returns: the phrase, and the BIP-39 passphrase when the wallet has one. */
153
- type ExportedMnemonic = {
154
- readonly mnemonic: ExportedSecret;
155
- readonly passphrase?: ExportedSecret;
156
- };
157
- type MnemonicDraft = {
158
- readonly words: ExportedSecret;
159
- readonly quiz: ReadonlyArray<number>;
160
- /** `passphrase` becomes the wallet's BIP-39 passphrase; omit or pass "" for none. */
161
- readonly confirm: (answers: ReadonlyArray<string>, options?: {
162
- readonly passphrase?: string;
163
- }) => Promise<WalletInfo>;
164
- readonly discard: () => Promise<void>;
165
- };
166
- type VaultApi = {
167
- readonly unlock: (factor?: UnlockFactor) => Promise<void>;
168
- readonly lock: () => Promise<void>;
169
- readonly addFactor: (factor: InitialFactor, verify: UnlockFactor) => Promise<FactorInfo>;
170
- readonly removeFactor: (id: string, verify: UnlockFactor) => Promise<void>;
171
- readonly reset: () => Promise<void>;
172
- };
173
- type WalletsApi = {
174
- readonly createWithPasskey: (options: {
175
- /** Display name for the new passkey credential (1–64 characters after trimming). */
176
- readonly name: string;
177
- readonly factor?: InitialFactor;
178
- }) => Promise<WalletInfo>;
179
- readonly restoreWithPasskey: (options?: {
180
- readonly factor?: InitialFactor;
181
- }) => Promise<WalletInfo>;
182
- readonly createMnemonic: (options: {
183
- readonly words: 12 | 24;
184
- readonly factor?: InitialFactor;
185
- }) => Promise<MnemonicDraft>;
186
- readonly importMnemonic: (options: {
187
- readonly mnemonic: string;
188
- /** BIP-39 passphrase; omit or pass "" for none. Spaces are significant. */
189
- readonly passphrase?: string;
190
- readonly factor?: InitialFactor;
191
- }) => Promise<WalletInfo>;
192
- /** One-shot mnemonic (and passphrase) export; requires re-verification every call. */
193
- readonly exportMnemonic: (walletId: string, verify: UnlockFactor) => Promise<ExportedMnemonic>;
194
- readonly delete: (walletId: string, verify: UnlockFactor) => Promise<void>;
195
- };
196
- type DataKeyApi = {
197
- readonly get: (purpose: string) => Promise<Uint8Array>;
198
- };
199
- /**
200
- * Cloud-backup entry points. `enable` re-verifies and retains a fresh BEK in the vault; `update`
201
- * rewrites the sealed envelope JSON with the retained BEK (no factor ceremony, so an auto-sync can
202
- * run silently); `restore` merges an envelope into the vault. Factor inputs reuse `UnlockFactor` —
203
- * passkey assertions evaluate the PRF over `backupSalt`.
204
- */
205
- type BackupApi = {
206
- readonly enable: (options: {
207
- readonly verify: UnlockFactor;
208
- readonly factors: ReadonlyArray<UnlockFactor>;
209
- }) => Promise<void>;
210
- readonly update: () => Promise<string>;
211
- readonly disable: () => Promise<void>;
212
- /**
213
- * Wallets whose header is flagged `passphrase` restore only when `passphrases` carries theirs;
214
- * the rest are listed in `passphraseRequired` and a later restore can bring them in.
215
- */
216
- readonly restore: (options: {
217
- readonly envelope: string;
218
- readonly backupFactor: UnlockFactor;
219
- readonly passphrases?: ReadonlyArray<{
220
- readonly walletId: string;
221
- readonly passphrase: string;
222
- }>;
223
- readonly factor?: InitialFactor;
224
- }) => Promise<{
225
- readonly wallets: ReadonlyArray<WalletInfo>;
226
- readonly passphraseRequired: ReadonlyArray<string>;
227
- }>;
228
- };
229
- type Wallet = {
230
- readonly getSnapshot: () => WalletSnapshot;
231
- readonly subscribe: (listener: () => void) => () => void;
232
- readonly vault: VaultApi;
233
- readonly wallets: WalletsApi;
234
- readonly dataKeys: DataKeyApi;
235
- readonly backup: BackupApi;
236
- readonly destroy: () => Promise<void>;
237
- };
238
- export { WalletSnapshot as C, WalletInfo as S, VaultApi as _, DerivedNostrKey as a, WalletError as b, FactorInfo as c, MnemonicDraft as d, NostrKeyInfo as f, UnlockFactor as g, StatusPayload as h, DataKeyApi as i, InitialFactor as l, PasskeyConfig as m, BackupApi as n, ExportedMnemonic as o, NostrKeyRef as p, BackupInfo as r, ExportedSecret as s, AutoLockPolicy as t, LockReason as u, VaultState as v, WalletsApi as w, WalletErrorCode as x, Wallet as y };
239
- //# sourceMappingURL=types-Dub5eUl3.d.mts.map