@qntx/wallet 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +43 -4
- package/dist/{protocol-D9_0sY_Y.mjs → core-QJ66nLLG.mjs} +91 -228
- package/dist/core-QJ66nLLG.mjs.map +1 -0
- package/dist/host.d.mts +19 -3
- package/dist/host.mjs +101 -11
- package/dist/host.mjs.map +1 -1
- package/dist/index-Dhf6wGjQ.d.mts +668 -0
- package/dist/index.d.mts +18 -2
- package/dist/index.mjs +35 -1
- package/dist/index.mjs.map +1 -0
- package/dist/internal-LBHal13j.mjs +25 -0
- package/dist/internal-LBHal13j.mjs.map +1 -0
- package/dist/nostr.d.mts +2 -2
- package/dist/nostr.mjs +13 -5
- package/dist/nostr.mjs.map +1 -1
- package/dist/protocol-D9xBuMzq.mjs +697 -0
- package/dist/protocol-D9xBuMzq.mjs.map +1 -0
- package/dist/protocol.d.mts +3 -3
- package/dist/protocol.mjs +3 -2
- package/dist/{secret-B-P3QOym.mjs → secret-IcTjjaX0.mjs} +113 -31
- package/dist/secret-IcTjjaX0.mjs.map +1 -0
- package/dist/spark.d.mts +30 -0
- package/dist/spark.mjs +303 -0
- package/dist/spark.mjs.map +1 -0
- package/dist/{types-DXNdAt_L.d.mts → types-D4OUjGVS.d.mts} +62 -13
- package/dist/types.d.mts +2 -2
- package/dist/types.mjs.map +1 -1
- package/package.json +16 -5
- package/dist/index-0nfJuuWM.d.mts +0 -286
- package/dist/protocol-D9_0sY_Y.mjs.map +0 -1
- package/dist/secret-B-P3QOym.mjs.map +0 -1
|
@@ -1,286 +0,0 @@
|
|
|
1
|
-
import { _ as WalletErrorCode, a as FactorInfo, f as StatusPayload, l as NostrKeyInfo, r as DerivedNostrKey, s as LockReason, v as WalletInfo } from "./types-DXNdAt_L.mjs";
|
|
2
|
-
//#region src/protocol/validate.d.ts
|
|
3
|
-
declare class ValidationError extends Error {
|
|
4
|
-
name: string;
|
|
5
|
-
}
|
|
6
|
-
type Validator<T> = (value: unknown) => T;
|
|
7
|
-
declare function literal<T extends NullValue | boolean | number | string>(expected: T): Validator<T>;
|
|
8
|
-
declare const nullValue: Validator<NullValue>;
|
|
9
|
-
declare const bool: Validator<boolean>;
|
|
10
|
-
declare function int(min: number, max: number): Validator<number>;
|
|
11
|
-
declare function str(max: number, pattern?: RegExp): Validator<string>;
|
|
12
|
-
declare function bytes(min: number, max?: number): Validator<Uint8Array>;
|
|
13
|
-
declare function arr<T>(item: Validator<T>, max: number, min?: number): Validator<ReadonlyArray<T>>;
|
|
14
|
-
declare class Opt<T> {
|
|
15
|
-
readonly validator: Validator<T>;
|
|
16
|
-
constructor(validator: Validator<T>);
|
|
17
|
-
}
|
|
18
|
-
declare function opt<T>(validator: Validator<T>): Opt<T>;
|
|
19
|
-
type Field = Validator<unknown> | Opt<unknown>;
|
|
20
|
-
type Shape = Record<string, Field>;
|
|
21
|
-
type RequiredKeys<S extends Shape> = { readonly [K in keyof S as S[K] extends Opt<unknown> ? never : K]: S[K] extends Validator<infer T> ? T : never; };
|
|
22
|
-
type OptionalKeys<S extends Shape> = { readonly [K in keyof S as S[K] extends Opt<unknown> ? K : never]?: S[K] extends Opt<infer T> ? T : never; };
|
|
23
|
-
type ShapeResult<S extends Shape> = RequiredKeys<S> & OptionalKeys<S>;
|
|
24
|
-
/** Exact key set: required keys present, optional keys allowed, nothing else. */
|
|
25
|
-
declare function obj<S extends Shape>(shape: S): Validator<ShapeResult<S>>;
|
|
26
|
-
/** Tries each branch in order; the first match wins. */
|
|
27
|
-
declare function union<Vs extends ReadonlyArray<Validator<unknown>>>(...branches: Vs): Validator<ReturnType<Vs[number]>>;
|
|
28
|
-
/** Validates a value and returns it, or undefined on a shape mismatch. */
|
|
29
|
-
declare function validate<T>(validator: Validator<T>, value: unknown): T | undefined;
|
|
30
|
-
//#endregion
|
|
31
|
-
//#region src/protocol/core.d.ts
|
|
32
|
-
type MethodSpec<P, R> = {
|
|
33
|
-
readonly session: boolean;
|
|
34
|
-
readonly params: Validator<P>;
|
|
35
|
-
readonly result: Validator<R>;
|
|
36
|
-
};
|
|
37
|
-
type Factor = {
|
|
38
|
-
readonly kind: "password";
|
|
39
|
-
readonly password: Uint8Array;
|
|
40
|
-
} | {
|
|
41
|
-
readonly kind: "passkey";
|
|
42
|
-
readonly credentialId: Uint8Array;
|
|
43
|
-
readonly prf: Uint8Array;
|
|
44
|
-
};
|
|
45
|
-
/**
|
|
46
|
-
* The result of every "create or import" wallet command: the new wallet's public info plus the
|
|
47
|
-
* session it opened. Creating a wallet derives no protocol keys — modules add keys separately.
|
|
48
|
-
*/
|
|
49
|
-
type CreatedResult = {
|
|
50
|
-
readonly wallet: WalletInfo;
|
|
51
|
-
readonly session: string;
|
|
52
|
-
};
|
|
53
|
-
declare const CORE_METHODS: {
|
|
54
|
-
readonly "vault.unlock": MethodSpec<{
|
|
55
|
-
readonly factor: Factor;
|
|
56
|
-
}, {
|
|
57
|
-
readonly session: string;
|
|
58
|
-
}>;
|
|
59
|
-
readonly "vault.lock": MethodSpec<NullValue, NullValue>;
|
|
60
|
-
readonly "vault.reset": MethodSpec<NullValue, NullValue>;
|
|
61
|
-
readonly "vault.addFactor": MethodSpec<{
|
|
62
|
-
readonly verify: Factor;
|
|
63
|
-
readonly factor: Factor;
|
|
64
|
-
}, FactorInfo>;
|
|
65
|
-
readonly "vault.removeFactor": MethodSpec<{
|
|
66
|
-
readonly verify: Factor;
|
|
67
|
-
readonly id: string;
|
|
68
|
-
}, NullValue>;
|
|
69
|
-
readonly "wallet.createWithPasskey": MethodSpec<{
|
|
70
|
-
readonly credentialId: Uint8Array;
|
|
71
|
-
readonly prfWallet: Uint8Array;
|
|
72
|
-
readonly factor?: Factor;
|
|
73
|
-
}, CreatedResult>;
|
|
74
|
-
readonly "wallet.restoreWithPasskey": MethodSpec<{
|
|
75
|
-
readonly credentialId: Uint8Array;
|
|
76
|
-
readonly prfWallet: Uint8Array;
|
|
77
|
-
readonly factor?: Factor;
|
|
78
|
-
}, CreatedResult>;
|
|
79
|
-
readonly "wallet.createMnemonic": MethodSpec<{
|
|
80
|
-
readonly words: 12 | 24;
|
|
81
|
-
readonly factor?: Factor;
|
|
82
|
-
}, {
|
|
83
|
-
readonly draft: string;
|
|
84
|
-
readonly words: Uint8Array;
|
|
85
|
-
readonly quiz: ReadonlyArray<number>;
|
|
86
|
-
}>;
|
|
87
|
-
readonly "wallet.confirmMnemonic": MethodSpec<{
|
|
88
|
-
readonly draft: string;
|
|
89
|
-
readonly answers: ReadonlyArray<Uint8Array>;
|
|
90
|
-
}, CreatedResult>;
|
|
91
|
-
readonly "wallet.discardMnemonic": MethodSpec<{
|
|
92
|
-
readonly draft: string;
|
|
93
|
-
}, NullValue>;
|
|
94
|
-
readonly "wallet.importMnemonic": MethodSpec<{
|
|
95
|
-
readonly mnemonic: Uint8Array;
|
|
96
|
-
readonly factor?: Factor;
|
|
97
|
-
}, CreatedResult>;
|
|
98
|
-
readonly "wallet.exportMnemonic": MethodSpec<{
|
|
99
|
-
readonly verify: Factor;
|
|
100
|
-
readonly walletId: string;
|
|
101
|
-
}, Uint8Array>;
|
|
102
|
-
readonly "wallet.delete": MethodSpec<{
|
|
103
|
-
readonly verify: Factor;
|
|
104
|
-
readonly walletId: string;
|
|
105
|
-
}, NullValue>;
|
|
106
|
-
readonly "dataKeys.get": MethodSpec<{
|
|
107
|
-
readonly purpose: string;
|
|
108
|
-
}, Uint8Array>;
|
|
109
|
-
};
|
|
110
|
-
//#endregion
|
|
111
|
-
//#region src/protocol/nostr.d.ts
|
|
112
|
-
/**
|
|
113
|
-
* The unsigned event input the kernel signs. `pubkey` is optional: callers may omit it and the
|
|
114
|
-
* kernel fills the signing key's own. Structurally compatible with @qntx/nostr's UnsignedEvent.
|
|
115
|
-
*/
|
|
116
|
-
type UnsignedEventInput = {
|
|
117
|
-
readonly kind: number;
|
|
118
|
-
readonly created_at: number;
|
|
119
|
-
readonly tags: ReadonlyArray<ReadonlyArray<string>>;
|
|
120
|
-
readonly content: string;
|
|
121
|
-
readonly pubkey?: string;
|
|
122
|
-
};
|
|
123
|
-
/** The signed event the kernel returns — the Nostr event minus `id`-less forms. */
|
|
124
|
-
type SignedEvent = {
|
|
125
|
-
readonly id: string;
|
|
126
|
-
readonly pubkey: string;
|
|
127
|
-
readonly sig: string;
|
|
128
|
-
readonly kind: number;
|
|
129
|
-
readonly created_at: number;
|
|
130
|
-
readonly tags: ReadonlyArray<ReadonlyArray<string>>;
|
|
131
|
-
readonly content: string;
|
|
132
|
-
};
|
|
133
|
-
/** A NIP-59 rumor: an unsigned event carrying a computed `id` but no `sig`. */
|
|
134
|
-
type Rumor = {
|
|
135
|
-
readonly id: string;
|
|
136
|
-
readonly pubkey: string;
|
|
137
|
-
readonly kind: number;
|
|
138
|
-
readonly created_at: number;
|
|
139
|
-
readonly tags: ReadonlyArray<ReadonlyArray<string>>;
|
|
140
|
-
readonly content: string;
|
|
141
|
-
};
|
|
142
|
-
type NostrImportInput = {
|
|
143
|
-
readonly kind: "nsec";
|
|
144
|
-
readonly nsec: Uint8Array;
|
|
145
|
-
} | {
|
|
146
|
-
readonly kind: "ncryptsec";
|
|
147
|
-
readonly ncryptsec: string;
|
|
148
|
-
readonly password: Uint8Array;
|
|
149
|
-
};
|
|
150
|
-
type NostrExportFormat = {
|
|
151
|
-
readonly kind: "nsec";
|
|
152
|
-
} | {
|
|
153
|
-
readonly kind: "ncryptsec";
|
|
154
|
-
readonly password: Uint8Array;
|
|
155
|
-
};
|
|
156
|
-
/** One "import/generate a key" result: the key's public info plus the session it may have opened. */
|
|
157
|
-
type KeyResult = {
|
|
158
|
-
readonly key: NostrKeyInfo;
|
|
159
|
-
readonly session: string;
|
|
160
|
-
};
|
|
161
|
-
type UnwrapResult = {
|
|
162
|
-
readonly ok: Rumor;
|
|
163
|
-
} | {
|
|
164
|
-
readonly err: WalletErrorCode;
|
|
165
|
-
};
|
|
166
|
-
declare const NOSTR_METHODS: {
|
|
167
|
-
readonly "nostr.discover": MethodSpec<{
|
|
168
|
-
readonly walletId: string;
|
|
169
|
-
readonly from: number;
|
|
170
|
-
readonly count: number;
|
|
171
|
-
}, {
|
|
172
|
-
readonly keys: ReadonlyArray<DerivedNostrKey>;
|
|
173
|
-
}>;
|
|
174
|
-
readonly "nostr.deriveKey": MethodSpec<{
|
|
175
|
-
readonly walletId: string;
|
|
176
|
-
readonly groupIndex: number;
|
|
177
|
-
}, NostrKeyInfo>;
|
|
178
|
-
readonly "nostr.importKey": MethodSpec<{
|
|
179
|
-
readonly input: NostrImportInput;
|
|
180
|
-
readonly factor?: Factor;
|
|
181
|
-
}, KeyResult>;
|
|
182
|
-
readonly "nostr.generateKey": MethodSpec<{
|
|
183
|
-
readonly factor?: Factor;
|
|
184
|
-
}, KeyResult>;
|
|
185
|
-
readonly "nostr.createNip46ClientKey": MethodSpec<NullValue, NostrKeyInfo>;
|
|
186
|
-
readonly "nostr.removeKey": MethodSpec<{
|
|
187
|
-
readonly publicKey: string;
|
|
188
|
-
readonly verify?: Factor;
|
|
189
|
-
}, NullValue>;
|
|
190
|
-
readonly "nostr.exportKey": MethodSpec<{
|
|
191
|
-
readonly verify: Factor;
|
|
192
|
-
readonly publicKey: string;
|
|
193
|
-
readonly format: NostrExportFormat;
|
|
194
|
-
}, Uint8Array>;
|
|
195
|
-
readonly "nostr.signEvent": MethodSpec<{
|
|
196
|
-
readonly publicKey: string;
|
|
197
|
-
readonly event: UnsignedEventInput;
|
|
198
|
-
}, SignedEvent>;
|
|
199
|
-
readonly "nostr.nip04Encrypt": MethodSpec<{
|
|
200
|
-
readonly publicKey: string;
|
|
201
|
-
readonly peer: string;
|
|
202
|
-
readonly text: string;
|
|
203
|
-
}, string>;
|
|
204
|
-
readonly "nostr.nip04Decrypt": MethodSpec<{
|
|
205
|
-
readonly publicKey: string;
|
|
206
|
-
readonly peer: string;
|
|
207
|
-
readonly text: string;
|
|
208
|
-
}, string>;
|
|
209
|
-
readonly "nostr.nip44Encrypt": MethodSpec<{
|
|
210
|
-
readonly publicKey: string;
|
|
211
|
-
readonly peer: string;
|
|
212
|
-
readonly text: string;
|
|
213
|
-
}, string>;
|
|
214
|
-
readonly "nostr.nip44Decrypt": MethodSpec<{
|
|
215
|
-
readonly publicKey: string;
|
|
216
|
-
readonly peer: string;
|
|
217
|
-
readonly text: string;
|
|
218
|
-
}, string>;
|
|
219
|
-
readonly "nostr.unwrapGiftWraps": MethodSpec<{
|
|
220
|
-
readonly publicKey: string;
|
|
221
|
-
readonly events: ReadonlyArray<SignedEvent>;
|
|
222
|
-
}, {
|
|
223
|
-
readonly results: ReadonlyArray<UnwrapResult>;
|
|
224
|
-
}>;
|
|
225
|
-
};
|
|
226
|
-
//#endregion
|
|
227
|
-
//#region src/protocol/index.d.ts
|
|
228
|
-
declare const PROTOCOL_VERSION = 1;
|
|
229
|
-
/**
|
|
230
|
-
* Responses to requests whose `id` cannot be parsed (malformed envelope) carry id 0. Main-side
|
|
231
|
-
* request ids start at 1, so a `0` is never a real pending request.
|
|
232
|
-
*/
|
|
233
|
-
declare const UNATTRIBUTED_ID = 0;
|
|
234
|
-
type NullValue = null;
|
|
235
|
-
type ProtocolValue = NullValue | boolean | number | string | Uint8Array | ReadonlyArray<ProtocolValue> | {
|
|
236
|
-
readonly [key: string]: ProtocolValue;
|
|
237
|
-
};
|
|
238
|
-
type Request = {
|
|
239
|
-
readonly v: 1;
|
|
240
|
-
readonly id: number;
|
|
241
|
-
readonly method: string;
|
|
242
|
-
readonly session?: string;
|
|
243
|
-
readonly params: ProtocolValue;
|
|
244
|
-
};
|
|
245
|
-
type ErrorPayload = {
|
|
246
|
-
readonly code: WalletErrorCode;
|
|
247
|
-
readonly retryAt?: number;
|
|
248
|
-
};
|
|
249
|
-
type Response = {
|
|
250
|
-
readonly v: 1;
|
|
251
|
-
readonly id: number;
|
|
252
|
-
readonly ok: ProtocolValue;
|
|
253
|
-
} | {
|
|
254
|
-
readonly v: 1;
|
|
255
|
-
readonly id: number;
|
|
256
|
-
readonly err: ErrorPayload;
|
|
257
|
-
};
|
|
258
|
-
type KernelEvent = {
|
|
259
|
-
readonly v: 1;
|
|
260
|
-
readonly event: "status";
|
|
261
|
-
readonly status: StatusPayload;
|
|
262
|
-
} | {
|
|
263
|
-
readonly v: 1;
|
|
264
|
-
readonly event: "locked";
|
|
265
|
-
readonly reason: LockReason;
|
|
266
|
-
};
|
|
267
|
-
/** Deep check that a structured-cloned value is a strict ProtocolValue (no cycles detected). */
|
|
268
|
-
declare function isProtocolValue(value: unknown): value is ProtocolValue;
|
|
269
|
-
declare const METHODS: {
|
|
270
|
-
readonly status: MethodSpec<NullValue, StatusPayload>;
|
|
271
|
-
} & typeof CORE_METHODS & typeof NOSTR_METHODS;
|
|
272
|
-
type AssertNever<T extends never> = T;
|
|
273
|
-
type MethodTablesDisjoint = AssertNever<keyof typeof CORE_METHODS & keyof typeof NOSTR_METHODS>;
|
|
274
|
-
type MethodName = keyof typeof METHODS;
|
|
275
|
-
type ParamsOf<M extends MethodName> = ReturnType<(typeof METHODS)[M]["params"]>;
|
|
276
|
-
type ResultOf<M extends MethodName> = ReturnType<(typeof METHODS)[M]["result"]>;
|
|
277
|
-
/** Host-side validators: `kernelEvent` covers the two push messages. */
|
|
278
|
-
declare const kernelEvent: Validator<KernelEvent>;
|
|
279
|
-
/** Validates the `err` payload of a response; `ok` is checked against `METHODS[m].result`. */
|
|
280
|
-
declare const responseError: Validator<{
|
|
281
|
-
code: WalletErrorCode;
|
|
282
|
-
retryAt?: number | undefined;
|
|
283
|
-
}>;
|
|
284
|
-
//#endregion
|
|
285
|
-
export { Validator as A, union as B, UnsignedEventInput as C, Factor as D, CreatedResult as E, literal as F, nullValue as I, obj as L, bool as M, bytes as N, MethodSpec as O, int as P, opt as R, SignedEvent as S, CORE_METHODS as T, validate as V, KeyResult as _, MethodTablesDisjoint as a, NostrImportInput as b, ParamsOf as c, Response as d, ResultOf as f, responseError as g, kernelEvent as h, MethodName as i, arr as j, ValidationError as k, ProtocolValue as l, isProtocolValue as m, KernelEvent as n, NullValue as o, UNATTRIBUTED_ID as p, METHODS as r, PROTOCOL_VERSION as s, ErrorPayload as t, Request as u, NOSTR_METHODS as v, UnwrapResult as w, Rumor as x, NostrExportFormat as y, str as z };
|
|
286
|
-
//# sourceMappingURL=index-0nfJuuWM.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"protocol-D9_0sY_Y.mjs","names":[],"sources":["../src/protocol/validate.ts","../src/protocol/core.ts","../src/protocol/nostr.ts","../src/protocol/index.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 (!(key in shape)) {\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 (!(key in record)) {\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\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 readonly params: Validator<P>;\n readonly result: Validator<R>;\n};\n\n// Size caps (UTF-16 units for strings, bytes for Uint8Array). A whole message is capped at 1 MiB\n// by the host; these bound individual fields.\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 = 256;\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\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 backedUp: bool,\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(\"rate-limited\"),\n literal(\"invalid-input\"),\n literal(\"not-found\"),\n literal(\"already-exists\"),\n literal(\"integrity\"),\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.lock\": MethodSpec<NullValue, NullValue>;\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 \"wallet.createWithPasskey\": MethodSpec<\n {\n readonly credentialId: Uint8Array;\n readonly prfWallet: Uint8Array;\n readonly factor?: Factor;\n },\n CreatedResult\n >;\n readonly \"wallet.restoreWithPasskey\": MethodSpec<\n {\n readonly credentialId: Uint8Array;\n readonly prfWallet: Uint8Array;\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 \"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 \"vault.unlock\": {\n session: false,\n params: obj({ factor }),\n result: obj({ session: sessionId }),\n },\n \"vault.lock\": { session: false, params: nullValue, result: nullValue },\n \"vault.reset\": { session: false, params: nullValue, result: nullValue },\n \"vault.addFactor\": {\n session: true,\n params: obj({ verify: factor, factor }),\n result: factorInfo,\n },\n \"vault.removeFactor\": {\n session: true,\n params: obj({ verify: factor, id: sessionId }),\n result: nullValue,\n },\n \"wallet.createWithPasskey\": {\n session: false,\n params: obj({ credentialId: bytes(1, 1023), prfWallet: bytes(32), factor: opt(factor) }),\n result: createdResult,\n },\n \"wallet.restoreWithPasskey\": {\n session: false,\n params: obj({ credentialId: bytes(1, 1023), prfWallet: bytes(32), factor: opt(factor) }),\n result: createdResult,\n },\n \"wallet.createMnemonic\": {\n session: false,\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 params: obj({ draft: draftId, answers: arr(bytes(1, 64), 3, 3) }),\n result: createdResult,\n },\n \"wallet.discardMnemonic\": {\n session: false,\n params: obj({ draft: draftId }),\n result: nullValue,\n },\n \"wallet.importMnemonic\": {\n session: false,\n params: obj({ mnemonic: bytes(1, 1024), factor: opt(factor) }),\n result: createdResult,\n },\n \"wallet.exportMnemonic\": {\n session: true,\n params: obj({ verify: factor, walletId }),\n result: bytes(16, 1024),\n },\n \"wallet.delete\": {\n session: true,\n params: obj({ verify: factor, walletId }),\n result: nullValue,\n },\n \"dataKeys.get\": {\n session: true,\n params: obj({ purpose: str(32, /^[a-z0-9-]{1,32}$/) }),\n result: bytes(32),\n },\n};\n","/**\n * The nostr module's method table and wire validators. The protocol stays free of @qntx/nostr\n * imports — even types — so the event shapes it validates are declared here structurally; a\n * type-level test in packages/wallet/tests pins them assignable to and from @qntx/nostr's\n * Event/UnsignedEvent/Rumor.\n */\nimport type { DerivedNostrKey, NostrKeyInfo, WalletErrorCode } from \"../types.ts\";\nimport {\n factor,\n groupIndex,\n MAX_BATCH,\n MAX_SNAPSHOT_ITEMS,\n MAX_TAG_ITEM,\n MAX_TAG_ITEMS,\n MAX_TAGS,\n MAX_TEXT,\n publicKey,\n safeTime,\n sessionId,\n walletErrorCode,\n walletId,\n} from \"./core.ts\";\nimport type { Factor } from \"./core.ts\";\nimport type { MethodSpec, NullValue } from \"./index.ts\";\nimport type { Validator } from \"./validate.ts\";\nimport { arr, bytes, int, literal, nullValue, obj, opt, str, union } from \"./validate.ts\";\n\n/**\n * The unsigned event input the kernel signs. `pubkey` is optional: callers may omit it and the\n * kernel fills the signing key's own. Structurally compatible with @qntx/nostr's UnsignedEvent.\n */\nexport type UnsignedEventInput = {\n readonly kind: number;\n readonly created_at: number;\n readonly tags: ReadonlyArray<ReadonlyArray<string>>;\n readonly content: string;\n readonly pubkey?: string;\n};\n\n/** The signed event the kernel returns — the Nostr event minus `id`-less forms. */\nexport type SignedEvent = {\n readonly id: string;\n readonly pubkey: string;\n readonly sig: string;\n readonly kind: number;\n readonly created_at: number;\n readonly tags: ReadonlyArray<ReadonlyArray<string>>;\n readonly content: string;\n};\n\n/** A NIP-59 rumor: an unsigned event carrying a computed `id` but no `sig`. */\nexport type Rumor = {\n readonly id: string;\n readonly pubkey: string;\n readonly kind: number;\n readonly created_at: number;\n readonly tags: ReadonlyArray<ReadonlyArray<string>>;\n readonly content: string;\n};\n\nexport type NostrImportInput =\n | { readonly kind: \"nsec\"; readonly nsec: Uint8Array }\n | { readonly kind: \"ncryptsec\"; readonly ncryptsec: string; readonly password: Uint8Array };\n\nexport type NostrExportFormat =\n | { readonly kind: \"nsec\" }\n | { readonly kind: \"ncryptsec\"; readonly password: Uint8Array };\n\n/** One \"import/generate a key\" result: the key's public info plus the session it may have opened. */\nexport type KeyResult = { readonly key: NostrKeyInfo; readonly session: string };\n\nexport type UnwrapResult = { readonly ok: Rumor } | { readonly err: WalletErrorCode };\n\nconst hex128: Validator<string> = str(128, /^[0-9a-f]{128}$/);\n\nconst nostrKeyRef = union(\n obj({ kind: literal(\"derived\"), walletId, groupIndex }),\n obj({ kind: literal(\"standalone\"), id: publicKey }),\n obj({ kind: literal(\"nip46-client\"), id: publicKey }),\n);\n\nexport const nostrKeyInfo: Validator<NostrKeyInfo> = obj({\n ref: nostrKeyRef,\n publicKey,\n origin: union(\n literal(\"derived\"),\n literal(\"nsec\"),\n literal(\"ncryptsec\"),\n literal(\"generated\"),\n literal(\"nip46-client\"),\n ),\n createdAt: safeTime,\n});\n\n/** The nostr section of the status payload, composed by protocol/index.ts. */\nexport const nostrStatus: Validator<{ readonly keys: ReadonlyArray<NostrKeyInfo> }> = obj({\n keys: arr(nostrKeyInfo, MAX_SNAPSHOT_ITEMS),\n});\n\nconst keyResult: Validator<KeyResult> = obj({ key: nostrKeyInfo, session: sessionId });\n\nconst derivedNostrKey: Validator<DerivedNostrKey> = obj({ groupIndex, publicKey });\n\nconst tags: Validator<ReadonlyArray<ReadonlyArray<string>>> = arr(\n arr(str(MAX_TAG_ITEM), MAX_TAG_ITEMS),\n MAX_TAGS,\n);\n\nconst signEventInput: Validator<UnsignedEventInput> = obj({\n kind: int(0, 65535),\n created_at: safeTime,\n tags,\n content: str(MAX_TEXT),\n pubkey: opt(publicKey),\n});\n\nconst signedEvent: Validator<SignedEvent> = obj({\n id: publicKey,\n pubkey: publicKey,\n sig: hex128,\n kind: int(0, 65535),\n created_at: safeTime,\n tags,\n content: str(MAX_TEXT),\n});\n\nconst rumor: Validator<Rumor> = obj({\n id: publicKey,\n pubkey: publicKey,\n kind: int(0, 65535),\n created_at: safeTime,\n tags,\n content: str(MAX_TEXT),\n});\n\nconst nostrImportInput: Validator<NostrImportInput> = union(\n obj({ kind: literal(\"nsec\"), nsec: bytes(1, 256) }),\n obj({ kind: literal(\"ncryptsec\"), ncryptsec: str(512, /^ncryptsec1/), password: bytes(1, 1024) }),\n);\n\nconst nostrExportFormat: Validator<NostrExportFormat> = union(\n obj({ kind: literal(\"nsec\") }),\n obj({ kind: literal(\"ncryptsec\"), password: bytes(1, 1024) }),\n);\n\nconst textParams = obj({ publicKey, peer: publicKey, text: str(MAX_TEXT) });\nconst textResult = str(MAX_TEXT * 4);\n\nexport const NOSTR_METHODS: {\n readonly \"nostr.discover\": MethodSpec<\n { readonly walletId: string; readonly from: number; readonly count: number },\n { readonly keys: ReadonlyArray<DerivedNostrKey> }\n >;\n readonly \"nostr.deriveKey\": MethodSpec<\n { readonly walletId: string; readonly groupIndex: number },\n NostrKeyInfo\n >;\n readonly \"nostr.importKey\": MethodSpec<\n { readonly input: NostrImportInput; readonly factor?: Factor },\n KeyResult\n >;\n readonly \"nostr.generateKey\": MethodSpec<{ readonly factor?: Factor }, KeyResult>;\n readonly \"nostr.createNip46ClientKey\": MethodSpec<NullValue, NostrKeyInfo>;\n readonly \"nostr.removeKey\": MethodSpec<\n { readonly publicKey: string; readonly verify?: Factor },\n NullValue\n >;\n readonly \"nostr.exportKey\": MethodSpec<\n { readonly verify: Factor; readonly publicKey: string; readonly format: NostrExportFormat },\n Uint8Array\n >;\n readonly \"nostr.signEvent\": MethodSpec<\n { readonly publicKey: string; readonly event: UnsignedEventInput },\n SignedEvent\n >;\n readonly \"nostr.nip04Encrypt\": MethodSpec<\n { readonly publicKey: string; readonly peer: string; readonly text: string },\n string\n >;\n readonly \"nostr.nip04Decrypt\": MethodSpec<\n { readonly publicKey: string; readonly peer: string; readonly text: string },\n string\n >;\n readonly \"nostr.nip44Encrypt\": MethodSpec<\n { readonly publicKey: string; readonly peer: string; readonly text: string },\n string\n >;\n readonly \"nostr.nip44Decrypt\": MethodSpec<\n { readonly publicKey: string; readonly peer: string; readonly text: string },\n string\n >;\n readonly \"nostr.unwrapGiftWraps\": MethodSpec<\n { readonly publicKey: string; readonly events: ReadonlyArray<SignedEvent> },\n { readonly results: ReadonlyArray<UnwrapResult> }\n >;\n} = {\n \"nostr.discover\": {\n session: true,\n params: obj({ walletId, from: groupIndex, count: int(1, 20) }),\n result: obj({ keys: arr(derivedNostrKey, 20) }),\n },\n \"nostr.deriveKey\": {\n session: true,\n params: obj({ walletId, groupIndex }),\n result: nostrKeyInfo,\n },\n \"nostr.importKey\": {\n session: false,\n params: obj({ input: nostrImportInput, factor: opt(factor) }),\n result: keyResult,\n },\n \"nostr.generateKey\": {\n session: false,\n params: obj({ factor: opt(factor) }),\n result: keyResult,\n },\n \"nostr.createNip46ClientKey\": { session: true, params: nullValue, result: nostrKeyInfo },\n \"nostr.removeKey\": {\n session: true,\n params: obj({ publicKey, verify: opt(factor) }),\n result: nullValue,\n },\n \"nostr.exportKey\": {\n session: true,\n params: obj({ verify: factor, publicKey, format: nostrExportFormat }),\n result: bytes(16, 4096),\n },\n \"nostr.signEvent\": {\n session: true,\n params: obj({ publicKey, event: signEventInput }),\n result: signedEvent,\n },\n \"nostr.nip04Encrypt\": { session: true, params: textParams, result: textResult },\n \"nostr.nip04Decrypt\": { session: true, params: textParams, result: textResult },\n \"nostr.nip44Encrypt\": { session: true, params: textParams, result: textResult },\n \"nostr.nip44Decrypt\": { session: true, params: textParams, result: textResult },\n \"nostr.unwrapGiftWraps\": {\n session: true,\n params: obj({ publicKey, events: arr(signedEvent, MAX_BATCH) }),\n result: obj({\n results: arr(union(obj({ ok: rumor }), obj({ err: walletErrorCode })), MAX_BATCH),\n }),\n },\n};\n","/**\n * Secret-area wire protocol (design/impl/wallet-e0.mdx \"协议与传输\"). Shared by the kernel and the main\n * runtime: the kernel validates every request, the host validates every response. Web/Node carry\n * ProtocolValue via structured clone; the RN host encodes the same values as CBOR.\n *\n * This file is the method-table composition point: `METHODS` spreads the core table\n * (protocol/core.ts) and the nostr module's table (protocol/nostr.ts), and the status result\n * validator composes the core sections with each module's status section.\n */\nimport type { LockReason, StatusPayload, WalletErrorCode } from \"../types.ts\";\n// oxlint-disable-next-line unicorn/prefer-export-from -- the tables are composed locally AND re-exported\nimport {\n CORE_METHODS,\n factorInfo,\n MAX_SNAPSHOT_ITEMS,\n safeTime,\n walletErrorCode,\n walletInfo,\n} from \"./core.ts\";\nimport type { MethodSpec } from \"./core.ts\";\n// oxlint-disable-next-line unicorn/prefer-export-from -- the table is composed locally AND re-exported\nimport { NOSTR_METHODS, nostrStatus } from \"./nostr.ts\";\nimport { arr, literal, nullValue, obj, opt, union } from \"./validate.ts\";\nimport type { Validator } from \"./validate.ts\";\n\nexport type { WalletErrorCode } from \"../types.ts\";\n\nexport const PROTOCOL_VERSION = 1;\n\n/**\n * Responses to requests whose `id` cannot be parsed (malformed envelope) carry id 0. Main-side\n * request ids start at 1, so a `0` is never a real pending request.\n */\nexport const UNATTRIBUTED_ID = 0;\n\n// oxlint-disable-next-line typescript/no-restricted-types -- JSON null is a protocol value\nexport type NullValue = null;\n\nexport type ProtocolValue =\n | NullValue\n | boolean\n | number // safe integer\n | string\n | Uint8Array\n | ReadonlyArray<ProtocolValue>\n | { readonly [key: string]: ProtocolValue };\n\nexport type Request = {\n readonly v: 1;\n readonly id: number;\n readonly method: string;\n readonly session?: string;\n readonly params: ProtocolValue;\n};\n\nexport type ErrorPayload = {\n readonly code: WalletErrorCode;\n readonly retryAt?: number; // only for \"rate-limited\"\n};\n\nexport type Response =\n | { readonly v: 1; readonly id: number; readonly ok: ProtocolValue }\n | { readonly v: 1; readonly id: number; readonly err: ErrorPayload };\n\nexport type KernelEvent =\n | { readonly v: 1; readonly event: \"status\"; readonly status: StatusPayload }\n | { readonly v: 1; readonly event: \"locked\"; readonly reason: LockReason };\n\n/** Deep check that a structured-cloned value is a strict ProtocolValue (no cycles detected). */\nexport function isProtocolValue(value: unknown): value is ProtocolValue {\n switch (typeof value) {\n case \"boolean\":\n case \"string\":\n return true;\n case \"number\":\n return Number.isSafeInteger(value);\n case \"object\":\n break;\n default:\n return false;\n }\n if (value === null || value instanceof Uint8Array) {\n return true;\n }\n if (Array.isArray(value)) {\n return value.every(isProtocolValue);\n }\n if (Object.getPrototypeOf(value) !== Object.prototype) {\n return false;\n }\n return Object.values(value).every(isProtocolValue);\n}\n\n/** The status payload: core sections plus one object section per protocol module. */\nconst statusPayload: Validator<StatusPayload> = obj({\n protocol: literal(1),\n vault: union(\n literal(\"uninitialized\"),\n literal(\"locked\"),\n literal(\"unlocked\"),\n literal(\"corrupted\"),\n ),\n factors: arr(factorInfo, MAX_SNAPSHOT_ITEMS),\n wallets: arr(walletInfo, MAX_SNAPSHOT_ITEMS),\n nostr: nostrStatus,\n});\n\n// The explicit annotation is the composition contract: a key missing from either table fails\n// declaration emit, and a duplicated key fails assignability (the spread's type for that key\n// cannot satisfy the intersection).\nexport const METHODS: {\n readonly status: MethodSpec<NullValue, StatusPayload>;\n} & typeof CORE_METHODS &\n typeof NOSTR_METHODS = {\n status: {\n session: false,\n params: nullValue,\n result: statusPayload,\n },\n ...CORE_METHODS,\n ...NOSTR_METHODS,\n};\n\n// A method name must live in exactly one table: an overlap violates the never constraint.\ntype AssertNever<T extends never> = T;\nexport type MethodTablesDisjoint = AssertNever<\n keyof typeof CORE_METHODS & keyof typeof NOSTR_METHODS\n>;\n\nexport type MethodName = keyof typeof METHODS;\nexport type ParamsOf<M extends MethodName> = ReturnType<(typeof METHODS)[M][\"params\"]>;\nexport type ResultOf<M extends MethodName> = ReturnType<(typeof METHODS)[M][\"result\"]>;\n\nconst lockReason: Validator<LockReason> = union(\n literal(\"cold-start\"),\n literal(\"user\"),\n literal(\"idle\"),\n literal(\"background\"),\n literal(\"expired\"),\n literal(\"crashed\"),\n);\n\nconst errorPayload = obj({ code: walletErrorCode, retryAt: opt(safeTime) });\n\n/** Host-side validators: `kernelEvent` covers the two push messages. */\nexport const kernelEvent: Validator<KernelEvent> = union(\n obj({ v: literal(1), event: literal(\"status\"), status: statusPayload }),\n obj({ v: literal(1), event: literal(\"locked\"), reason: lockReason }),\n);\n\n/** Validates the `err` payload of a response; `ok` is checked against `METHODS[m].result`. */\nexport const responseError: Validator<{ code: WalletErrorCode; retryAt?: number | undefined }> =\n errorPayload;\n\nexport { CORE_METHODS, NOSTR_METHODS };\nexport type { MethodSpec } from \"./core.ts\";\nexport type { CreatedResult, Factor } from \"./core.ts\";\nexport type {\n KeyResult,\n NostrExportFormat,\n NostrImportInput,\n Rumor,\n SignedEvent,\n UnsignedEventInput,\n UnwrapResult,\n} from \"./nostr.ts\";\nexport {\n ValidationError,\n arr,\n bool,\n bytes,\n int,\n literal,\n nullValue,\n obj,\n opt,\n str,\n union,\n validate,\n type Validator,\n} from \"./validate.ts\";\n"],"mappings":";AAOA,IAAa,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,MACL,QAAQ,eAAe,GACvB,QAAQ,QAAQ,GAChB,QAAQ,UAAU,GAClB,QAAQ,WAAW,CACrB;CACA,SAAS,IAAI,YAAY,kBAAkB;CAC3C,SAAS,IAAI,YAAY,kBAAkB;CAC3C,OAAO;AACT,CAAC;AAKD,MAAa,UAGY;CACvB,QAAQ;EACN,SAAS;EACT,QAAQ;EACR,QAAQ;CACV;CACA,GAAG;CACH,GAAG;AACL;AAYA,MAAM,aAAoC,MACxC,QAAQ,YAAY,GACpB,QAAQ,MAAM,GACd,QAAQ,MAAM,GACd,QAAQ,YAAY,GACpB,QAAQ,SAAS,GACjB,QAAQ,SAAS,CACnB;AAEA,MAAM,eAAe,IAAI;CAAE,MAAM;CAAiB,SAAS,IAAI,QAAQ;AAAE,CAAC;;AAG1E,MAAa,cAAsC,MACjD,IAAI;CAAE,GAAG,QAAQ,CAAC;CAAG,OAAO,QAAQ,QAAQ;CAAG,QAAQ;AAAc,CAAC,GACtE,IAAI;CAAE,GAAG,QAAQ,CAAC;CAAG,OAAO,QAAQ,QAAQ;CAAG,QAAQ;AAAW,CAAC,CACrE;;AAGA,MAAa,gBACX"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"secret-B-P3QOym.mjs","names":[],"sources":["../src/channel.ts","../src/factors.ts","../src/internal.ts","../src/secret.ts"],"sourcesContent":["/**\n * The host side of the kernel channel (design/enclave.mdx \"协议与传输\"): port lifecycle, respawn,\n * request/response correlation and wire validation. Internal to the `./host` subpath — reserved for\n * host packages (wallet-worker, wallet-native); applications must not use it.\n */\nimport {\n isProtocolValue,\n kernelEvent,\n METHODS,\n PROTOCOL_VERSION,\n responseError,\n ValidationError,\n} from \"./protocol/index.ts\";\nimport type { MethodName, ParamsOf, ProtocolValue, ResultOf } from \"./protocol/index.ts\";\nimport { WalletError } from \"./types.ts\";\nimport type { LockReason, StatusPayload } from \"./types.ts\";\n\n/** The host packages' side of the kernel channel (worker, JSI runtime, in-process test port). */\nexport type MainPort = {\n readonly post: (message: ProtocolValue, transfer: ArrayBuffer[]) => void;\n readonly listen: (handler: (message: unknown) => void) => () => void;\n readonly onExit: (handler: () => void) => () => void;\n readonly terminate: () => void;\n};\n\nexport function integrity(message: string): WalletError {\n return new WalletError(\"integrity\", message);\n}\n\ntype Pending = {\n readonly method: MethodName;\n readonly resolve: (value: unknown) => void;\n readonly reject: (error: WalletError) => void;\n};\n\n/**\n * State callbacks: the channel owns the port lifecycle and message ordering; the wallet owns the\n * snapshot state these events describe. `onLocked`/`onCrashed` fire before the port is replaced so\n * the wallet can stamp the lock reason.\n */\nexport type ChannelHandlers = {\n readonly onStatus: (status: StatusPayload) => void;\n readonly onLocked: (reason: LockReason) => void;\n readonly onCrashed: () => void;\n};\n\nexport class Channel {\n /** The live kernel session; attached to every request and cleared whenever it is gone. */\n session: string | undefined;\n\n private port: MainPort | undefined;\n private unlisten: (() => void) | undefined;\n private unlistenExit: (() => void) | undefined;\n private generation = 0;\n\n private readonly pending = new Map<number, Pending>();\n private nextId = 1;\n private destroyed = false;\n /** Terminal state: the kernel peer proved untrustworthy; every later call fails with it. */\n private broken: WalletError | undefined;\n /** Whether the current port has delivered its first valid status event. */\n private portReady = false;\n private readyPromise: Promise<void>;\n private resolveReady: (() => void) | undefined;\n private rejectReady: ((error: WalletError) => void) | undefined;\n\n private readonly spawn: () => MainPort;\n private readonly handlers: ChannelHandlers;\n\n constructor(spawn: () => MainPort, handlers: ChannelHandlers) {\n this.spawn = spawn;\n this.handlers = handlers;\n this.readyPromise = new Promise((resolve, reject) => {\n this.resolveReady = resolve;\n this.rejectReady = reject;\n });\n }\n\n /** Spawns the first kernel and resolves once its initial status event arrives. */\n async start(): Promise<void> {\n this.respawn();\n return this.readyPromise;\n }\n\n /** Resolves when the current port has delivered its first status event. */\n get ready(): Promise<void> {\n return this.readyPromise;\n }\n\n /**\n * Terminates the current port and spawns a fresh secret runtime, keeping the vault image (the\n * host-side store survives the worker). \"Lock destroys the enclave.\"\n */\n respawn(): void {\n if (this.destroyed || this.broken !== undefined) {\n return;\n }\n this.unlisten?.();\n this.unlistenExit?.();\n this.port?.terminate();\n this.port = undefined;\n this.session = undefined;\n this.portReady = false;\n\n const generation = ++this.generation;\n // Settle the previous gate: a call still awaiting it must not hang — the kernel it was\n // waiting for is gone, so \"locked\" (session destroyed) applies.\n // oxlint-disable-next-line promise/prefer-await-to-then -- marks the stale gate as handled without swallowing it for awaiters\n void this.readyPromise.catch(() => undefined);\n this.rejectReady?.(new WalletError(\"locked\", \"the kernel restarted\"));\n this.readyPromise = new Promise((resolve, reject) => {\n this.resolveReady = resolve;\n this.rejectReady = reject;\n });\n // A rejected gate with nobody awaiting it (e.g. destroy() mid-boot) must not surface as\n // an unhandled rejection; callers that do await still observe the rejection.\n // oxlint-disable-next-line promise/prefer-await-to-then -- marks the gate as handled without swallowing it for awaiters\n void this.readyPromise.catch(() => undefined);\n try {\n const port = this.spawn();\n this.unlisten = port.listen((message) => {\n this.onMessage(message, generation);\n });\n this.unlistenExit = port.onExit(() => {\n this.onExit(generation);\n });\n this.port = port;\n } catch {\n // A host that cannot spawn has no kernel to talk to — fail closed like a dead peer.\n this.breakChannel(integrity(\"could not spawn the kernel port\"));\n }\n }\n\n private onExit(generation: number): void {\n if (generation !== this.generation || this.destroyed || this.broken !== undefined) {\n return;\n }\n this.session = undefined;\n if (!this.portReady) {\n // Death before the first valid status means the runtime never ran honestly (worker\n // blocked by CSP, a script that fails to load, protocol skew): no respawn — a fresh\n // spawn would face the same broken peer. Initial connect rejects with integrity;\n // a respawned port dying this way breaks the wallet.\n this.breakChannel(integrity(\"the kernel port died before its first status\"));\n return;\n }\n // A proven port dying is a crash: fail everything in flight, mark it, respawn.\n this.failPending(new WalletError(\"crashed\", \"the kernel port exited\"));\n this.handlers.onCrashed();\n this.respawn();\n }\n\n private failPending(error: WalletError): void {\n for (const [, pending] of this.pending) {\n pending.reject(error);\n }\n this.pending.clear();\n }\n\n /**\n * Terminal failure: terminate the port, fail everything in flight, and latch `broken` so every\n * later call rejects with the same error. The snapshot is left untouched.\n */\n private breakChannel(error: WalletError): void {\n this.broken = error;\n this.session = undefined;\n this.failPending(error);\n this.rejectReady?.(error);\n this.unlisten?.();\n this.unlistenExit?.();\n this.port?.terminate();\n this.port = undefined;\n this.generation++; // anything the dead port still emits is stale\n }\n\n /** A malformed protocol peer cannot be trusted — it fails closed, never respawns. */\n private poison(reason: string): void {\n this.breakChannel(integrity(reason));\n }\n\n private onMessage(raw: unknown, generation: number): void {\n if (generation !== this.generation) {\n return; // a dead port must not steer the wallet\n }\n if (\n !isProtocolValue(raw) ||\n typeof raw !== \"object\" ||\n raw === null ||\n raw instanceof Uint8Array ||\n Array.isArray(raw)\n ) {\n this.poison(\"malformed kernel message\");\n return;\n }\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- narrowed to a plain record above\n const message = raw as Readonly<Record<string, ProtocolValue>>;\n if (\"id\" in message) {\n this.onResponse(message);\n return;\n }\n if (\"event\" in message) {\n let event;\n try {\n event = kernelEvent(message);\n } catch (error) {\n if (!(error instanceof ValidationError)) {\n throw error;\n }\n this.poison(\"malformed kernel event\");\n return;\n }\n if (event.event === \"status\") {\n if (event.status.vault !== \"unlocked\") {\n this.session = undefined;\n }\n this.portReady = true;\n this.handlers.onStatus(event.status);\n this.resolveReady?.();\n } else {\n // A locked event destroys the enclave: drop the session, tear down the port, respawn.\n this.session = undefined;\n this.handlers.onLocked(event.reason);\n this.failPending(new WalletError(\"locked\", \"the vault locked\"));\n this.respawn();\n }\n return;\n }\n this.poison(\"unrecognised kernel message\");\n }\n\n private onResponse(message: Readonly<Record<string, ProtocolValue>>): void {\n const { id } = message;\n if (typeof id !== \"number\" || !Number.isSafeInteger(id) || message[\"v\"] !== PROTOCOL_VERSION) {\n this.poison(\"malformed response envelope\");\n return;\n }\n const pending = this.pending.get(id);\n if (pending === undefined) {\n // Includes UNATTRIBUTED_ID 0 — never a live request.\n this.poison(\"response for an unknown request\");\n return;\n }\n const hasOk = \"ok\" in message;\n const hasErr = \"err\" in message;\n if (hasOk === hasErr) {\n // Keep the entry so poison's failPending rejects this caller too.\n this.poison(\"malformed response body\");\n return;\n }\n if (hasErr) {\n try {\n const err = responseError(message[\"err\"]);\n this.pending.delete(id);\n pending.reject(\n new WalletError(\n err.code,\n `kernel returned ${err.code}`,\n typeof err.retryAt === \"number\" ? err.retryAt : undefined,\n ),\n );\n } catch (error) {\n if (!(error instanceof ValidationError)) {\n throw error;\n }\n this.poison(\"malformed error payload\");\n }\n return;\n }\n try {\n const result = METHODS[pending.method].result(message[\"ok\"]);\n this.pending.delete(id);\n pending.resolve(result);\n } catch (error) {\n if (!(error instanceof ValidationError)) {\n throw error;\n }\n this.poison(\"invalid result from the kernel\");\n }\n }\n\n /**\n * Sends one request and resolves with the validated result. The kernel answers with status →\n * response → locked, so the snapshot is already current when this promise settles.\n */\n async call<M extends MethodName>(\n method: M,\n params: ParamsOf<M>,\n transfer: ArrayBuffer[] = [],\n ): Promise<ResultOf<M>> {\n await this.readyPromise;\n if (this.broken !== undefined) {\n throw this.broken;\n }\n const { port } = this;\n if (this.destroyed || port === undefined) {\n throw new WalletError(\"locked\", \"wallet is destroyed\");\n }\n const id = this.nextId++;\n const message: Record<string, ProtocolValue> = { v: PROTOCOL_VERSION, id, method, params };\n // Attach the session whenever we hold one: the create/import methods are session:false\n // in the table because the rule is dynamic (required exactly when the vault is initialized).\n if (this.session !== undefined) {\n message[\"session\"] = this.session;\n }\n const result = await new Promise<unknown>((resolve, reject) => {\n this.pending.set(id, { method, resolve, reject });\n try {\n port.post(message, transfer);\n } catch {\n this.pending.delete(id);\n reject(integrity(\"the kernel port refused the message\"));\n }\n });\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- validated by METHODS[method].result\n return result as ResultOf<M>;\n }\n\n /** Terminates the port without respawn; later calls fail \"locked\". */\n destroy(): void {\n if (this.destroyed) {\n return;\n }\n this.destroyed = true;\n this.unlisten?.();\n this.unlistenExit?.();\n this.port?.terminate();\n this.port = undefined;\n this.session = undefined;\n this.rejectReady?.(new WalletError(\"locked\", \"wallet is destroyed\"));\n this.failPending(new WalletError(\"locked\", \"wallet is destroyed\"));\n }\n}\n","/**\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 { 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\nexport type PrfResult = {\n readonly credentialId: Uint8Array;\n readonly first: Uint8Array;\n readonly second?: Uint8Array;\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/** What factor resolution needs from the wallet: config, the ceremony, live factor records. */\nexport type FactorSource = {\n readonly passkey: PasskeyConfig;\n readonly ceremony: PasskeyCeremony | undefined;\n readonly factors: () => ReadonlyArray<FactorInfo>;\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\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 (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.\n */\nexport async function resolveInitialFactor(\n source: FactorSource,\n factor: InitialFactor | undefined,\n transfer: ArrayBuffer[],\n walletCeremony?: PrfResult,\n): Promise<Factor> {\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 new WalletError(\"factor-unavailable\", \"hardware factors exist only on React Native\");\n}\n","import type { Factor, MethodName, ParamsOf, ResultOf } from \"./protocol/index.ts\";\n/**\n * Channel internals shared between the core Wallet and the protocol subpath modules\n * (@qntx/wallet/nostr, later spark/chains). This file is NOT a package subpath — modules look a\n * Wallet up in the WeakMap, so a foreign object has no channel to reach.\n */\nimport { WalletError } from \"./types.ts\";\nimport type { InitialFactor, UnlockFactor, Wallet, WalletSnapshot } from \"./types.ts\";\n\nexport type WalletInternals = {\n /** One validated request on the kernel channel (awaits the live port's first status). */\n readonly call: <M extends MethodName>(\n method: M,\n params: ParamsOf<M>,\n transfer?: ArrayBuffer[],\n ) => Promise<ResultOf<M>>;\n /** The live kernel port's first-status gate — re-read per call (a respawn replaces it). */\n readonly ready: () => Promise<void>;\n readonly snapshot: () => WalletSnapshot;\n /** Marks a user verification in flight on the snapshot (`verifying`). */\n readonly withVerifying: <T>(fn: () => Promise<T>) => Promise<T>;\n /** Public UnlockFactor → wire factor material (the passkey ceremony runs here). */\n readonly resolveFactor: (factor: UnlockFactor, transfer: ArrayBuffer[]) => Promise<Factor>;\n /** The create/import factor gate: required on an uninitialized vault, forbidden after. */\n readonly createFactorParam: (\n factor: InitialFactor | undefined,\n transfer: ArrayBuffer[],\n ) => Promise<Factor | undefined>;\n /** Adopts the session a create/import result opened onto the channel. */\n readonly sessionOf: (result: { readonly session: string }) => void;\n};\n\nconst internals = new WeakMap<Wallet, WalletInternals>();\n\nexport function registerInternals(wallet: Wallet, value: WalletInternals): void {\n internals.set(wallet, value);\n}\n\n/**\n * The internals behind a Wallet from this package — or `invalid-input` for anything else. A foreign\n * object can imitate the Wallet shape but can never hold the channel: modules that look it up here\n * get a closed failure, not a crafted kernel.\n */\nexport function internalsOf(wallet: Wallet): WalletInternals {\n const found = internals.get(wallet);\n if (found === undefined) {\n throw new WalletError(\"invalid-input\", \"not a Wallet from @qntx/wallet\");\n }\n return found;\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":";;;;;;;;;AAyBA,SAAgB,UAAU,SAA8B;CACtD,OAAO,IAAI,YAAY,aAAa,OAAO;AAC7C;AAmBA,IAAa,UAAb,MAAqB;;C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