@umbra-privacy/sdk 1.0.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 (77) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +122 -0
  3. package/dist/addresses-Brzgurv_.d.ts +145 -0
  4. package/dist/addresses-D_0YAS6B.d.cts +145 -0
  5. package/dist/chunk-2Q75CQQJ.js +12 -0
  6. package/dist/chunk-2Q75CQQJ.js.map +1 -0
  7. package/dist/chunk-7QVYU63E.js +6 -0
  8. package/dist/chunk-7QVYU63E.js.map +1 -0
  9. package/dist/chunk-BM7N6N7E.js +1883 -0
  10. package/dist/chunk-BM7N6N7E.js.map +1 -0
  11. package/dist/chunk-GXKSUB2U.cjs +4416 -0
  12. package/dist/chunk-GXKSUB2U.cjs.map +1 -0
  13. package/dist/chunk-HOEXDXRC.cjs +792 -0
  14. package/dist/chunk-HOEXDXRC.cjs.map +1 -0
  15. package/dist/chunk-MDFSBU5W.cjs +2033 -0
  16. package/dist/chunk-MDFSBU5W.cjs.map +1 -0
  17. package/dist/chunk-MQY7HDIA.js +600 -0
  18. package/dist/chunk-MQY7HDIA.js.map +1 -0
  19. package/dist/chunk-MVKTV3FT.cjs +20 -0
  20. package/dist/chunk-MVKTV3FT.cjs.map +1 -0
  21. package/dist/chunk-PG2J6V6Y.js +4094 -0
  22. package/dist/chunk-PG2J6V6Y.js.map +1 -0
  23. package/dist/chunk-PK6SKIKE.cjs +8 -0
  24. package/dist/chunk-PK6SKIKE.cjs.map +1 -0
  25. package/dist/chunk-VEGLTTYQ.cjs +621 -0
  26. package/dist/chunk-VEGLTTYQ.cjs.map +1 -0
  27. package/dist/chunk-WVHQ46DD.js +758 -0
  28. package/dist/chunk-WVHQ46DD.js.map +1 -0
  29. package/dist/constants/index.cjs +316 -0
  30. package/dist/constants/index.cjs.map +1 -0
  31. package/dist/constants/index.d.cts +739 -0
  32. package/dist/constants/index.d.ts +739 -0
  33. package/dist/constants/index.js +193 -0
  34. package/dist/constants/index.js.map +1 -0
  35. package/dist/cryptography-BTGC72u-.d.cts +4809 -0
  36. package/dist/cryptography-BTGC72u-.d.ts +4809 -0
  37. package/dist/errors/index.cjs +141 -0
  38. package/dist/errors/index.cjs.map +1 -0
  39. package/dist/errors/index.d.cts +1415 -0
  40. package/dist/errors/index.d.ts +1415 -0
  41. package/dist/errors/index.js +4 -0
  42. package/dist/errors/index.js.map +1 -0
  43. package/dist/index-B9pDY73x.d.ts +12933 -0
  44. package/dist/index-CLj_zWSD.d.ts +235 -0
  45. package/dist/index-CX6_pIRS.d.cts +235 -0
  46. package/dist/index-D33yo0qB.d.cts +12933 -0
  47. package/dist/index.cjs +22464 -0
  48. package/dist/index.cjs.map +1 -0
  49. package/dist/index.d.cts +11694 -0
  50. package/dist/index.d.ts +11694 -0
  51. package/dist/index.js +22314 -0
  52. package/dist/index.js.map +1 -0
  53. package/dist/interfaces/index.cjs +4 -0
  54. package/dist/interfaces/index.cjs.map +1 -0
  55. package/dist/interfaces/index.d.cts +8 -0
  56. package/dist/interfaces/index.d.ts +8 -0
  57. package/dist/interfaces/index.js +3 -0
  58. package/dist/interfaces/index.js.map +1 -0
  59. package/dist/networks-C-orpSFW.d.ts +65 -0
  60. package/dist/networks-FxYERGD1.d.cts +65 -0
  61. package/dist/types/index.cjs +605 -0
  62. package/dist/types/index.cjs.map +1 -0
  63. package/dist/types/index.d.cts +1853 -0
  64. package/dist/types/index.d.ts +1853 -0
  65. package/dist/types/index.js +4 -0
  66. package/dist/types/index.js.map +1 -0
  67. package/dist/types-BBuELtY8.d.cts +495 -0
  68. package/dist/types-n-sHFcgr.d.ts +495 -0
  69. package/dist/utils/index.cjs +1295 -0
  70. package/dist/utils/index.cjs.map +1 -0
  71. package/dist/utils/index.d.cts +9559 -0
  72. package/dist/utils/index.d.ts +9559 -0
  73. package/dist/utils/index.js +6 -0
  74. package/dist/utils/index.js.map +1 -0
  75. package/dist/versions-D9PqsEvj.d.cts +173 -0
  76. package/dist/versions-D9PqsEvj.d.ts +173 -0
  77. package/package.json +151 -0
@@ -0,0 +1,1415 @@
1
+ /**
2
+ * Error Classes
3
+ *
4
+ * Centralized error hierarchy for the Umbra SDK.
5
+ * Contains the base `UmbraError` and all domain-specific assertion error classes.
6
+ *
7
+ * @remarks
8
+ * The SDK uses a two-level error hierarchy:
9
+ *
10
+ * 1. `UmbraError` — top-level base class for all SDK errors. Consumers can use
11
+ * `instanceof UmbraError` (or the `isUmbraError` type guard) to distinguish SDK errors
12
+ * from third-party or built-in errors in a catch block.
13
+ *
14
+ * 2. Domain assertion errors — thrown by type-assertion functions when a value fails
15
+ * validation. Each domain has its own class to make it easy to catch errors from a
16
+ * specific subsystem:
17
+ * - `MathematicsAssertionError` — thrown by `assertU8`, `assertU256`, etc.
18
+ * - `CryptographyAssertionError` — thrown by `assertBn254FieldElement`, `assertAesKey`, etc.
19
+ * - `SolanaAssertionError` — thrown by Solana-type assertion functions.
20
+ * - `TemporalAssertionError` — thrown by `assertYear`, `assertMonth`, etc.
21
+ *
22
+ * All four assertion error classes share the same three properties:
23
+ * - `value` — the actual value that failed
24
+ * - `expectedType` — the name of the expected branded type
25
+ * - `constraint` — optional human-readable constraint description
26
+ *
27
+ * @packageDocumentation
28
+ * @module common/errors
29
+ */
30
+ /**
31
+ * Base error class for all Umbra SDK errors.
32
+ *
33
+ * All errors thrown by the SDK extend this class, allowing consumers
34
+ * to distinguish SDK errors from other errors using `instanceof`.
35
+ *
36
+ * @remarks
37
+ * Prefer using the `isUmbraError` type guard over `instanceof UmbraError` when writing
38
+ * defensive catch handlers — the type guard also works across module boundaries and
39
+ * iframe/realm boundaries where `instanceof` may fail due to different class references.
40
+ *
41
+ * Sub-classes (domain assertion errors) extend this class so callers can catch either
42
+ * all SDK errors at once (`instanceof UmbraError`) or only a specific domain's failures
43
+ * (e.g., `instanceof MathematicsAssertionError`).
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * try {
48
+ * await umbraClient.register();
49
+ * } catch (error) {
50
+ * if (error instanceof UmbraError) {
51
+ * console.log('SDK error:', error.message);
52
+ * console.log('Error code:', error.code);
53
+ * } else {
54
+ * throw error; // Re-throw non-SDK errors
55
+ * }
56
+ * }
57
+ * ```
58
+ *
59
+ * @see {@link isUmbraError}
60
+ * @public
61
+ */
62
+ declare class UmbraError extends Error {
63
+ /**
64
+ * A machine-readable error code for programmatic error handling.
65
+ *
66
+ * @remarks
67
+ * Defaults to `"UMBRA_ERROR"` when no code is supplied in the constructor options.
68
+ * Sub-classes or specific throw sites should supply a more specific code to allow
69
+ * callers to branch on error identity without string-matching `message`.
70
+ *
71
+ * @readonly
72
+ */
73
+ readonly code: string;
74
+ /**
75
+ * Additional context about the error.
76
+ *
77
+ * @remarks
78
+ * A free-form key-value map of diagnostic data attached to the error at the throw site.
79
+ * Useful for logging and debugging — consumers should not rely on specific keys for
80
+ * control flow; use `code` for programmatic branching instead.
81
+ *
82
+ * Will be `undefined` when no context was provided to the constructor.
83
+ *
84
+ * @readonly
85
+ */
86
+ readonly context?: Record<string, unknown>;
87
+ /**
88
+ * The original error that caused this error, if any.
89
+ *
90
+ * @remarks
91
+ * When an SDK function wraps a lower-level error (e.g., a failed RPC call or a
92
+ * cryptographic library error), it sets `cause` to the original thrown value so
93
+ * callers can inspect the full error chain.
94
+ *
95
+ * Will be `undefined` when there is no underlying cause.
96
+ *
97
+ * @readonly
98
+ */
99
+ readonly cause?: unknown;
100
+ /**
101
+ * Creates a new UmbraError.
102
+ *
103
+ * @param message - Human-readable description of what went wrong. Should be
104
+ * actionable and specific enough for a developer to understand the failure
105
+ * without reading source code.
106
+ * @param options - Optional structured metadata attached to the error.
107
+ * @param options.code - Machine-readable error code for programmatic branching.
108
+ * Defaults to `"UMBRA_ERROR"` if omitted.
109
+ * @param options.context - Free-form diagnostic key-value pairs. Omit or set to
110
+ * `undefined` to leave the `context` property unset.
111
+ * @param options.cause - The original error that triggered this one. Enables
112
+ * full error-chain inspection. Omit or set to `undefined` when there is no
113
+ * underlying cause.
114
+ *
115
+ * @defaultValue `options` — `undefined` (all options optional)
116
+ * @defaultValue `options.code` — `"UMBRA_ERROR"`
117
+ */
118
+ constructor(message: string, options?: {
119
+ code?: string;
120
+ context?: Record<string, unknown>;
121
+ cause?: unknown;
122
+ });
123
+ }
124
+ /**
125
+ * Type guard to check if an error is an UmbraError.
126
+ *
127
+ * @remarks
128
+ * Prefer this guard over `error instanceof UmbraError` in generic catch handlers because
129
+ * it is safe to call with any value (including `null`, primitives, and non-Error objects)
130
+ * and narrows the type to `UmbraError` for TypeScript's type system in the true branch.
131
+ *
132
+ * @param error - The value to test. Typically the caught value in a `catch (error)` block,
133
+ * typed as `unknown`.
134
+ * @returns `true` and narrows `error` to `UmbraError` when the value is an instance of
135
+ * `UmbraError` (or any sub-class such as `MathematicsAssertionError`). Returns `false`
136
+ * for all other values.
137
+ *
138
+ * @example
139
+ * ```typescript
140
+ * try {
141
+ * await operation();
142
+ * } catch (error) {
143
+ * if (isUmbraError(error)) {
144
+ * // error is narrowed to UmbraError here
145
+ * console.log('SDK error code:', error.code);
146
+ * console.log('SDK error context:', error.context);
147
+ * }
148
+ * }
149
+ * ```
150
+ *
151
+ * @see {@link UmbraError}
152
+ * @public
153
+ */
154
+ declare function isUmbraError(error: unknown): error is UmbraError;
155
+ /**
156
+ * Error thrown when a value fails a mathematical type assertion.
157
+ *
158
+ * This error provides detailed information about why an assertion failed,
159
+ * including the actual value, the expected type, and the constraint that
160
+ * was violated.
161
+ *
162
+ * @remarks
163
+ * All assertion functions in the mathematics module (e.g., `assertU8`, `assertU256`,
164
+ * `assertU32LeBytes`) throw this error type on failure. Catch it specifically to handle
165
+ * mathematical type validation failures differently from cryptographic or Solana errors.
166
+ *
167
+ * The three diagnostic properties together allow automated logging pipelines to produce
168
+ * structured records without parsing the `message` string:
169
+ * - `value` — the actual value that was supplied
170
+ * - `expectedType` — the branded type name (e.g., `"U8"`, `"U256LeBytes"`)
171
+ * - `constraint` — the violated range or length rule, or `undefined` for type mismatches
172
+ *
173
+ * Note that this class does NOT extend `UmbraError`. It extends `Error` directly to keep
174
+ * the assertion error classes lightweight and independent of the UmbraError hierarchy.
175
+ * Use `isUmbraError` only to detect top-level SDK operational errors; use
176
+ * `instanceof MathematicsAssertionError` for assertion failures.
177
+ *
178
+ * @example
179
+ * ```typescript
180
+ * import { assertU8, MathematicsAssertionError } from "./mathematics";
181
+ *
182
+ * try {
183
+ * const value = assertU8(256n); // Will throw
184
+ * } catch (error) {
185
+ * if (error instanceof MathematicsAssertionError) {
186
+ * console.error(`Assertion failed for ${error.expectedType}`);
187
+ * console.error(`Value: ${error.value}`);
188
+ * console.error(`Constraint: ${error.constraint}`);
189
+ * // Output:
190
+ * // Assertion failed for U8
191
+ * // Value: 256
192
+ * // Constraint: 0 <= value <= 255
193
+ * }
194
+ * }
195
+ * ```
196
+ *
197
+ * @example
198
+ * ```typescript
199
+ * // Safe parse pattern — returns null instead of throwing
200
+ * function safeParseU8(value: bigint): U8 | null {
201
+ * try {
202
+ * return assertU8(value);
203
+ * } catch (error) {
204
+ * if (error instanceof MathematicsAssertionError) {
205
+ * console.warn(`Invalid U8 value: ${value}`);
206
+ * return null;
207
+ * }
208
+ * throw error; // Re-throw unexpected errors
209
+ * }
210
+ * }
211
+ * ```
212
+ *
213
+ * @sealed
214
+ * @public
215
+ */
216
+ declare class MathematicsAssertionError extends Error {
217
+ /**
218
+ * The actual value that failed the assertion.
219
+ *
220
+ * @remarks
221
+ * The runtime type reflects what was actually passed to the assertion function:
222
+ * - `bigint` for integer assertions (`assertU8`, `assertU256`, etc.)
223
+ * - `Uint8Array` for byte-array assertions (`assertU256LeBytes`, `assertU32LeBytes`, etc.)
224
+ * - Any other type when a non-numeric value was passed unexpectedly
225
+ *
226
+ * @readonly
227
+ */
228
+ readonly value: unknown;
229
+ /**
230
+ * The type that was expected.
231
+ *
232
+ * @remarks
233
+ * Contains the branded type name exactly as it appears in the SDK type system,
234
+ * e.g., `"U8"`, `"U256"`, `"U32LeBytes"`. Use this for structured logging or
235
+ * to build user-facing error messages without parsing the `message` string.
236
+ *
237
+ * @readonly
238
+ */
239
+ readonly expectedType: string;
240
+ /**
241
+ * Description of the constraint that was violated.
242
+ *
243
+ * @remarks
244
+ * Is `undefined` when only a type check failed (e.g., a `string` was passed where a
245
+ * `bigint` was expected). Contains a human-readable inequality or length rule when a
246
+ * value of the correct type was out of the allowed range.
247
+ *
248
+ * @example
249
+ * - `"0 <= value <= 255"` — U8 range violation
250
+ * - `"length === 32"` — U256LeBytes length violation
251
+ * - `"value >= 0"` — negative value passed to an unsigned integer assertion
252
+ *
253
+ * @readonly
254
+ */
255
+ readonly constraint: string | undefined;
256
+ /**
257
+ * Creates a new MathematicsAssertionError.
258
+ *
259
+ * @param message - Human-readable description of the assertion failure. Should name
260
+ * the assertion function, the expected type, and the constraint that was violated.
261
+ * @param options - Structured diagnostic details attached to the error.
262
+ * @param options.value - The actual value that was supplied and failed the assertion.
263
+ * @param options.expectedType - The name of the branded type that was expected
264
+ * (e.g., `"U8"`, `"U256LeBytes"`).
265
+ * @param options.constraint - Optional human-readable constraint description
266
+ * (e.g., `"0 <= value <= 255"`). Omit when the failure is a type mismatch rather
267
+ * than a range violation.
268
+ */
269
+ constructor(message: string, options: {
270
+ value: unknown;
271
+ expectedType: string;
272
+ constraint?: string;
273
+ });
274
+ }
275
+ /**
276
+ * Error thrown when a value fails a cryptographic type assertion.
277
+ *
278
+ * This error provides detailed information about why an assertion failed,
279
+ * including the actual value, the expected type, and the constraint that
280
+ * was violated.
281
+ *
282
+ * @remarks
283
+ * Thrown by assertion functions in the cryptography module, such as
284
+ * `assertBn254FieldElement`, `assertAesKey`, `assertX25519PrivateKey`, and similar.
285
+ * Each function validates that a value conforms to a branded cryptographic type,
286
+ * throwing this error with a precise `expectedType` and `constraint` when it does not.
287
+ *
288
+ * Common reasons for failure:
289
+ * - A `bigint` field element exceeds the BN254 or Curve25519 field prime
290
+ * - A byte array has the wrong length (e.g., a 31-byte array passed as an AES-256 key)
291
+ * - A wrong JavaScript type was supplied (e.g., a `number` instead of a `bigint`)
292
+ *
293
+ * @example
294
+ * ```typescript
295
+ * import { assertBn254FieldElement, CryptographyAssertionError } from "./cryptography";
296
+ *
297
+ * try {
298
+ * assertBn254FieldElement(invalidValue); // Will throw
299
+ * } catch (error) {
300
+ * if (error instanceof CryptographyAssertionError) {
301
+ * console.error(`Assertion failed for ${error.expectedType}`);
302
+ * console.error(`Value: ${error.value}`);
303
+ * console.error(`Constraint: ${error.constraint}`);
304
+ * }
305
+ * }
306
+ * ```
307
+ *
308
+ * @example
309
+ * ```typescript
310
+ * // Distinguish cryptographic assertion failures from mathematical ones
311
+ * try {
312
+ * const key = assertAesKey(rawBytes);
313
+ * } catch (error) {
314
+ * if (error instanceof CryptographyAssertionError) {
315
+ * console.warn("Crypto assertion failed:", error.expectedType, error.constraint);
316
+ * } else if (error instanceof MathematicsAssertionError) {
317
+ * console.warn("Math assertion failed:", error.expectedType, error.constraint);
318
+ * }
319
+ * }
320
+ * ```
321
+ *
322
+ * @see {@link MathematicsAssertionError}
323
+ * @see {@link SolanaAssertionError}
324
+ * @see {@link TemporalAssertionError}
325
+ * @sealed
326
+ * @public
327
+ */
328
+ declare class CryptographyAssertionError extends Error {
329
+ /**
330
+ * The actual value that failed the assertion.
331
+ *
332
+ * @remarks
333
+ * The runtime type reflects what was actually passed to the assertion function:
334
+ * - `bigint` for field element assertions (`assertBn254FieldElement`, etc.)
335
+ * - `Uint8Array` for byte-array assertions (`assertAesKey`, `assertX25519PrivateKey`, etc.)
336
+ * - Any other type when an entirely wrong value type was supplied
337
+ *
338
+ * @readonly
339
+ */
340
+ readonly value: unknown;
341
+ /**
342
+ * The type that was expected (e.g., `"Bn254FieldElement"`, `"PoseidonKey"`, `"AesKey"`).
343
+ *
344
+ * @remarks
345
+ * Contains the branded type name exactly as it appears in the SDK type system.
346
+ * Use this property for structured logging without parsing the `message` string.
347
+ *
348
+ * @readonly
349
+ */
350
+ readonly expectedType: string;
351
+ /**
352
+ * Description of the constraint that was violated.
353
+ *
354
+ * @remarks
355
+ * Is `undefined` for pure type-mismatch failures (e.g., `string` instead of `bigint`).
356
+ * Contains a human-readable constraint description for range and length violations
357
+ * (e.g., `"value < BN254_FIELD_PRIME"`, `"length === 32"`).
358
+ *
359
+ * @readonly
360
+ */
361
+ readonly constraint: string | undefined;
362
+ /**
363
+ * Creates a new CryptographyAssertionError.
364
+ *
365
+ * @param message - Human-readable description of the assertion failure. Should name
366
+ * the assertion function, the expected type, and the constraint that was violated.
367
+ * @param options - Structured diagnostic details attached to the error.
368
+ * @param options.value - The actual value that was supplied and failed the assertion.
369
+ * @param options.expectedType - The name of the branded cryptographic type that was
370
+ * expected (e.g., `"Bn254FieldElement"`, `"AesKey"`).
371
+ * @param options.constraint - Optional human-readable constraint description.
372
+ * Omit when the failure is a type mismatch rather than a range or length violation.
373
+ */
374
+ constructor(message: string, options: {
375
+ value: unknown;
376
+ expectedType: string;
377
+ constraint?: string;
378
+ });
379
+ }
380
+ /**
381
+ * Error thrown when a Solana type assertion fails.
382
+ *
383
+ * This error provides detailed information about why the assertion failed,
384
+ * including the actual value, expected type, and constraint that was violated.
385
+ *
386
+ * @remarks
387
+ * Thrown by assertion functions for Solana-specific branded types, such as
388
+ * `assertTransactionSignature`, `assertSignatureBytes`, and similar validators.
389
+ * These assertions verify that string or byte-array values conform to Solana's
390
+ * encoding and length conventions (e.g., Base58-encoded 64-byte Ed25519 signatures).
391
+ *
392
+ * Common reasons for failure:
393
+ * - A string that fails Base58 decoding or has the wrong decoded length
394
+ * - A `Uint8Array` with the wrong byte length for a signature or public key
395
+ * - A wrong JavaScript type (e.g., `number` instead of `string`)
396
+ *
397
+ * @example
398
+ * ```typescript
399
+ * import { assertTransactionSignature, SolanaAssertionError } from "./solana";
400
+ *
401
+ * try {
402
+ * assertTransactionSignature("invalid!signature"); // Will throw
403
+ * } catch (error) {
404
+ * if (error instanceof SolanaAssertionError) {
405
+ * console.error(`Assertion failed for ${error.expectedType}`);
406
+ * console.error(`Value: ${error.value}`);
407
+ * console.error(`Constraint: ${error.constraint}`);
408
+ * }
409
+ * }
410
+ * ```
411
+ *
412
+ * @example
413
+ * ```typescript
414
+ * // Safe parse pattern — returns null on failure
415
+ * function tryParseSignature(raw: unknown): TransactionSignature | null {
416
+ * try {
417
+ * return assertTransactionSignature(raw);
418
+ * } catch (error) {
419
+ * if (error instanceof SolanaAssertionError) return null;
420
+ * throw error;
421
+ * }
422
+ * }
423
+ * ```
424
+ *
425
+ * @see {@link MathematicsAssertionError}
426
+ * @see {@link CryptographyAssertionError}
427
+ * @see {@link TemporalAssertionError}
428
+ * @sealed
429
+ * @public
430
+ */
431
+ declare class SolanaAssertionError extends Error {
432
+ /**
433
+ * The actual value that failed the assertion.
434
+ *
435
+ * @remarks
436
+ * The runtime type reflects what was actually passed to the assertion function:
437
+ * - `string` for Base58-encoded assertions (`assertTransactionSignature`, etc.)
438
+ * - `Uint8Array` for byte-array assertions (`assertSignatureBytes`, etc.)
439
+ * - Any other type when a completely wrong value type was supplied
440
+ *
441
+ * @readonly
442
+ */
443
+ readonly value: unknown;
444
+ /**
445
+ * The type that was expected (e.g., `"TransactionSignature"`, `"SignatureBytes"`).
446
+ *
447
+ * @remarks
448
+ * Contains the branded type name exactly as it appears in the SDK type system.
449
+ * Use this for structured logging without parsing the `message` string.
450
+ *
451
+ * @readonly
452
+ */
453
+ readonly expectedType: string;
454
+ /**
455
+ * Description of the constraint that was violated.
456
+ *
457
+ * @remarks
458
+ * Is `undefined` for pure type-mismatch failures. Contains a human-readable rule
459
+ * for encoding or length violations (e.g., `"valid Base58"`, `"length === 64"`).
460
+ *
461
+ * @readonly
462
+ */
463
+ readonly constraint: string | undefined;
464
+ /**
465
+ * Creates a new SolanaAssertionError.
466
+ *
467
+ * @param message - Human-readable description of the assertion failure. Should name
468
+ * the assertion function, the expected type, and the constraint that was violated.
469
+ * @param options - Structured diagnostic details attached to the error.
470
+ * @param options.value - The actual value that was supplied and failed the assertion.
471
+ * @param options.expectedType - The name of the branded Solana type that was expected
472
+ * (e.g., `"TransactionSignature"`, `"SignatureBytes"`).
473
+ * @param options.constraint - Optional human-readable constraint description.
474
+ * Omit when the failure is a type mismatch rather than an encoding or length violation.
475
+ */
476
+ constructor(message: string, options: {
477
+ value: unknown;
478
+ expectedType: string;
479
+ constraint?: string;
480
+ });
481
+ }
482
+ /**
483
+ * Error thrown when a temporal type assertion fails.
484
+ *
485
+ * This error provides detailed information about why an assertion failed,
486
+ * including the actual value, the expected type, and the constraint that
487
+ * was violated.
488
+ *
489
+ * @remarks
490
+ * Thrown by assertion functions for branded temporal types: `assertYear`, `assertMonth`,
491
+ * `assertDay`, `assertHour`, `assertMinute`, and `assertSecond`. These functions validate
492
+ * that a `bigint` value falls within the calendar range appropriate for each component
493
+ * (e.g., months must be in `[1, 12]`, hours in `[0, 23]`).
494
+ *
495
+ * Temporal assertions are used to validate the output of UTC timestamp extraction before
496
+ * the components are used in time-scoped viewing key derivation. In normal operation they
497
+ * should never throw (JavaScript's `Date` always produces in-range values), but callers
498
+ * that construct components manually can encounter these errors.
499
+ *
500
+ * @example
501
+ * ```typescript
502
+ * import { assertMonth, TemporalAssertionError } from "./temporal";
503
+ *
504
+ * try {
505
+ * assertMonth(13n); // Will throw — month must be 1–12
506
+ * } catch (error) {
507
+ * if (error instanceof TemporalAssertionError) {
508
+ * console.error(`Assertion failed for ${error.expectedType}`);
509
+ * console.error(`Value: ${error.value}`);
510
+ * console.error(`Constraint: ${error.constraint}`);
511
+ * // Output:
512
+ * // Assertion failed for Month
513
+ * // Value: 13
514
+ * // Constraint: 1 <= value <= 12
515
+ * }
516
+ * }
517
+ * ```
518
+ *
519
+ * @example
520
+ * ```typescript
521
+ * // Safe parse of a user-supplied year value
522
+ * function tryParseYear(raw: bigint): Year | null {
523
+ * try {
524
+ * return assertYear(raw);
525
+ * } catch (error) {
526
+ * if (error instanceof TemporalAssertionError) return null;
527
+ * throw error;
528
+ * }
529
+ * }
530
+ * ```
531
+ *
532
+ * @see {@link MathematicsAssertionError}
533
+ * @see {@link CryptographyAssertionError}
534
+ * @see {@link SolanaAssertionError}
535
+ * @sealed
536
+ * @public
537
+ */
538
+ declare class TemporalAssertionError extends Error {
539
+ /**
540
+ * The actual value that failed the assertion.
541
+ *
542
+ * @remarks
543
+ * Will be a `bigint` for all temporal assertions since the temporal types are
544
+ * BigInt-backed branded types (e.g., `Year`, `Month`, `Day`). May also be any
545
+ * other type when a non-bigint value was supplied unexpectedly.
546
+ *
547
+ * @readonly
548
+ */
549
+ readonly value: unknown;
550
+ /**
551
+ * The type that was expected (e.g., `"Year"`, `"Month"`, `"Hour"`).
552
+ *
553
+ * @remarks
554
+ * Contains the branded temporal type name exactly as it appears in the SDK type system.
555
+ * Use this for structured logging without parsing the `message` string.
556
+ *
557
+ * @readonly
558
+ */
559
+ readonly expectedType: string;
560
+ /**
561
+ * Description of the constraint that was violated.
562
+ *
563
+ * @remarks
564
+ * Contains a human-readable range rule for out-of-range values
565
+ * (e.g., `"1 <= value <= 12"` for a month violation). Is `undefined` only for
566
+ * pure type-mismatch failures (e.g., a `string` passed where a `bigint` was expected),
567
+ * which should not occur in normal usage.
568
+ *
569
+ * @readonly
570
+ */
571
+ readonly constraint: string | undefined;
572
+ /**
573
+ * Creates a new TemporalAssertionError.
574
+ *
575
+ * @param message - Human-readable description of the assertion failure. Should name
576
+ * the assertion function, the expected type, and the violated range constraint.
577
+ * @param details - Structured diagnostic details attached to the error.
578
+ * @param details.value - The actual `bigint` value (or other type) that was supplied
579
+ * and failed the temporal assertion.
580
+ * @param details.expectedType - The name of the branded temporal type that was expected
581
+ * (e.g., `"Year"`, `"Month"`, `"Hour"`).
582
+ * @param details.constraint - Optional human-readable range description
583
+ * (e.g., `"1 <= value <= 12"`). Omit when the failure is a type mismatch.
584
+ */
585
+ constructor(message: string, details: {
586
+ value: unknown;
587
+ expectedType: string;
588
+ constraint?: string;
589
+ });
590
+ }
591
+
592
+ /**
593
+ * Cryptography Error Classes
594
+ *
595
+ * This module provides error classes for cryptographic operation failures
596
+ * in the Umbra SDK.
597
+ *
598
+ * @module crypto/errors
599
+ */
600
+
601
+ /**
602
+ * Error thrown when a cryptographic operation fails.
603
+ *
604
+ * This includes key derivation failures, encryption/decryption errors,
605
+ * hash computation failures, and ZK proof generation errors.
606
+ *
607
+ * @example
608
+ * ```typescript
609
+ * try {
610
+ * const commitment = await generateUserCommitment(mvk, index, seed);
611
+ * } catch (error) {
612
+ * if (error instanceof CryptographyError) {
613
+ * console.log('Crypto operation failed:', error.operation);
614
+ * }
615
+ * }
616
+ * ```
617
+ */
618
+ declare class CryptographyError extends UmbraError {
619
+ /**
620
+ * The cryptographic operation that failed.
621
+ */
622
+ readonly operation?: string;
623
+ constructor(message: string, options?: {
624
+ code?: string;
625
+ operation?: string;
626
+ context?: Record<string, unknown>;
627
+ cause?: unknown;
628
+ });
629
+ }
630
+ /**
631
+ * Type guard to check if an error is a CryptographyError.
632
+ */
633
+ declare function isCryptographyError(error: unknown): error is CryptographyError;
634
+
635
+ /**
636
+ * Solana-Specific Error Classes.
637
+ *
638
+ * This module defines the structured error hierarchy for Solana-related failures
639
+ * in the Umbra SDK. All classes extend `UmbraError` from `../common/errors` and
640
+ * carry structured context that makes programmatic error handling and logging
641
+ * straightforward.
642
+ *
643
+ * @remarks
644
+ * The error hierarchy is:
645
+ * ```
646
+ * UmbraError (base)
647
+ * ├── InstructionError — instruction build/validation failures
648
+ * ├── RpcError — JSON-RPC request failures
649
+ * └── TransactionError — transaction lifecycle failures
650
+ * ├── TransactionSigningError — signing-phase failures
651
+ * │ └── MasterSeedSigningRejectedError — master seed derivation rejection
652
+ * ```
653
+ *
654
+ * **Type guards** — Each concrete error class has a matching `is*` type guard
655
+ * function ({@link isInstructionError}, {@link isRpcError},
656
+ * {@link isTransactionError}, {@link isTransactionSigningError}). Prefer these
657
+ * over `instanceof` checks in code that may cross module or bundle boundaries,
658
+ * where `instanceof` can fail due to different class references.
659
+ *
660
+ * **Recovery strategies by error type:**
661
+ *
662
+ * - `InstructionError` — inspect `instructionName` and `context` to determine
663
+ * which account is missing or which parameter is invalid; fix the call site.
664
+ *
665
+ * - `RpcError` — check `statusCode` (HTTP) and `rpcErrorCode` (JSON-RPC) to
666
+ * distinguish rate limiting (429), node overload (503), or invalid request
667
+ * (400). Transient errors are typically retryable.
668
+ *
669
+ * - `TransactionError` — check `simulationLogs` for program error messages that
670
+ * identify the on-chain failure. If `signature` is set, the transaction landed
671
+ * on-chain but was reverted.
672
+ *
673
+ * - `TransactionSigningError` — check `wasRejected` to distinguish a deliberate
674
+ * user rejection from a hardware wallet communication failure.
675
+ *
676
+ * - `MasterSeedSigningRejectedError` — the user declined the master seed
677
+ * derivation message; prompt the user and retry with `getUmbraClientFromSigner`.
678
+ *
679
+ * @packageDocumentation
680
+ */
681
+
682
+ /**
683
+ * Error thrown when building or validating a Solana instruction fails.
684
+ *
685
+ * This error is raised during the instruction-construction phase — before any
686
+ * RPC or network interaction occurs. Common causes include missing required
687
+ * accounts, invalid parameter values, PDA derivation failures, and instruction
688
+ * serialization errors.
689
+ *
690
+ * @remarks
691
+ * The `instructionName` field identifies which instruction failed, which is
692
+ * particularly useful when a single SDK operation constructs multiple
693
+ * instructions. The `context` field (inherited from `UmbraError`) carries
694
+ * arbitrary key-value pairs for additional diagnostic information, such as
695
+ * the list of missing accounts or the conflicting parameter values.
696
+ *
697
+ * **Default error code** — `"INSTRUCTION_ERROR"`. Sub-classes or callers may
698
+ * override this via the `code` option.
699
+ *
700
+ * @example
701
+ * Catching and inspecting an instruction build failure:
702
+ * ```typescript
703
+ * import { isInstructionError } from "@umbra-privacy/sdk";
704
+ *
705
+ * try {
706
+ * const instruction = buildRegisterInstruction(params);
707
+ * } catch (error) {
708
+ * if (isInstructionError(error)) {
709
+ * console.error(`Instruction "${error.instructionName}" failed: ${error.message}`);
710
+ * console.error("Context:", error.context);
711
+ * }
712
+ * }
713
+ * ```
714
+ *
715
+ * @example
716
+ * Throwing an `InstructionError` from a builder:
717
+ * ```typescript
718
+ * import { InstructionError } from "@umbra-privacy/sdk";
719
+ *
720
+ * throw new InstructionError("Required account 'poolConfig' not found", {
721
+ * instructionName: "encryptedDeposit",
722
+ * context: { missingAccounts: ["poolConfig"], providedMint: mint.toString() },
723
+ * });
724
+ * ```
725
+ *
726
+ * @see {@link isInstructionError} for the corresponding type guard
727
+ * @public
728
+ */
729
+ declare class InstructionError extends UmbraError {
730
+ /**
731
+ * The name of the instruction that failed during construction or validation.
732
+ *
733
+ * @remarks
734
+ * Matches the Anchor instruction name (camelCase), e.g. `"encryptedDeposit"`,
735
+ * `"initUserAccount"`. May be `undefined` if the failing instruction could
736
+ * not be identified at the throw site.
737
+ */
738
+ readonly instructionName?: string;
739
+ /**
740
+ * Creates a new `InstructionError`.
741
+ *
742
+ * @param message - Human-readable description of the instruction failure.
743
+ * @param options - Optional structured metadata.
744
+ * @param options.code - Error code string. Defaults to `"INSTRUCTION_ERROR"`.
745
+ * @param options.instructionName - The name of the failing instruction.
746
+ * @param options.context - Arbitrary key-value pairs for diagnostic context.
747
+ * @param options.cause - The underlying error that caused this failure, if any.
748
+ */
749
+ constructor(message: string, options?: {
750
+ code?: string;
751
+ instructionName?: string;
752
+ context?: Record<string, unknown>;
753
+ cause?: unknown;
754
+ });
755
+ }
756
+ /**
757
+ * Error thrown when a Solana JSON-RPC request fails.
758
+ *
759
+ * This error covers all network-level and protocol-level failures that occur
760
+ * while communicating with a Solana RPC node: unreachable endpoints, HTTP
761
+ * errors, rate limiting, malformed responses, and JSON-RPC error objects
762
+ * returned by the node.
763
+ *
764
+ * @remarks
765
+ * **HTTP errors** — Use `statusCode` to check for common HTTP failure modes:
766
+ * - `429` — rate limited; back off and retry with exponential delay
767
+ * - `503` — node overloaded or temporarily unavailable; retry after a pause
768
+ * - `400` — malformed request; usually a client bug, not retryable
769
+ *
770
+ * **JSON-RPC errors** — Use `rpcErrorCode` to distinguish Solana-specific
771
+ * error codes returned in the `error.code` field of an RPC response body.
772
+ * Common codes: `-32002` (transaction not found), `-32005` (node behind),
773
+ * `-32007` (slot skipped).
774
+ *
775
+ * **Retryability** — `statusCode >= 500` or `statusCode === 429` generally
776
+ * indicates a transient error. Client-side errors (`statusCode === 400`) are
777
+ * not retryable without fixing the request.
778
+ *
779
+ * **Default error code** — `"RPC_ERROR"`.
780
+ *
781
+ * @example
782
+ * Distinguishing rate-limit errors from other RPC failures:
783
+ * ```typescript
784
+ * import { isRpcError } from "@umbra-privacy/sdk";
785
+ *
786
+ * try {
787
+ * const account = await rpc.getAccountInfo(address);
788
+ * } catch (error) {
789
+ * if (isRpcError(error)) {
790
+ * if (error.statusCode === 429) {
791
+ * console.warn("Rate limited — retry after delay");
792
+ * } else {
793
+ * console.error(`RPC failure at ${error.endpoint}: ${error.message}`);
794
+ * }
795
+ * }
796
+ * }
797
+ * ```
798
+ *
799
+ * @example
800
+ * Constructing an `RpcError`:
801
+ * ```typescript
802
+ * import { RpcError } from "@umbra-privacy/sdk";
803
+ *
804
+ * throw new RpcError("Failed to fetch account", {
805
+ * endpoint: "https://api.mainnet-beta.solana.com",
806
+ * statusCode: 503,
807
+ * cause: originalError,
808
+ * });
809
+ * ```
810
+ *
811
+ * @see {@link isRpcError} for the corresponding type guard
812
+ * @public
813
+ */
814
+ declare class RpcError extends UmbraError {
815
+ /**
816
+ * The RPC endpoint URL that was called when the error occurred.
817
+ *
818
+ * @remarks
819
+ * May be `undefined` if the endpoint was not known at the throw site (e.g.,
820
+ * when the error originates deep within `@solana/kit` internals).
821
+ */
822
+ readonly endpoint?: string;
823
+ /**
824
+ * The HTTP status code returned by the RPC node, if applicable.
825
+ *
826
+ * @remarks
827
+ * `undefined` for network-level failures (e.g., DNS resolution failure,
828
+ * connection refused) where no HTTP response was received.
829
+ */
830
+ readonly statusCode?: number;
831
+ /**
832
+ * The JSON-RPC error code from the response body, if any.
833
+ *
834
+ * @remarks
835
+ * Set when the RPC node returns a well-formed JSON-RPC error object with a
836
+ * numeric `code` field. `undefined` for HTTP-level failures or when the node
837
+ * returns a malformed response body.
838
+ */
839
+ readonly rpcErrorCode?: number;
840
+ /**
841
+ * Creates a new `RpcError`.
842
+ *
843
+ * @param message - Human-readable description of the RPC failure.
844
+ * @param options - Optional structured metadata.
845
+ * @param options.code - Error code string. Defaults to `"RPC_ERROR"`.
846
+ * @param options.endpoint - The RPC endpoint URL that was called.
847
+ * @param options.statusCode - HTTP status code from the response, if any.
848
+ * @param options.rpcErrorCode - JSON-RPC error code from the response, if any.
849
+ * @param options.context - Arbitrary key-value pairs for diagnostic context.
850
+ * @param options.cause - The underlying error that caused this failure, if any.
851
+ */
852
+ constructor(message: string, options?: {
853
+ code?: string;
854
+ endpoint?: string;
855
+ statusCode?: number;
856
+ rpcErrorCode?: number;
857
+ context?: Record<string, unknown>;
858
+ cause?: unknown;
859
+ });
860
+ }
861
+ /**
862
+ * Error thrown when a transaction operation fails.
863
+ *
864
+ * This error covers failures across the full transaction lifecycle: building the
865
+ * transaction message, running preflight simulation, submitting to the network,
866
+ * and waiting for confirmation. It is the base class for more specific
867
+ * transaction-related errors.
868
+ *
869
+ * @remarks
870
+ * **Simulation logs** — When available, `simulationLogs` contain the program
871
+ * log output from a failed preflight simulation. These logs often include the
872
+ * Anchor error code and a human-readable message describing why the on-chain
873
+ * program rejected the transaction.
874
+ *
875
+ * **Signature** — When `signature` is present, the transaction was accepted by
876
+ * the network and executed but the execution itself failed (on-chain error).
877
+ * When `signature` is absent, the transaction was rejected before reaching the
878
+ * network (e.g., preflight failure, malformed transaction).
879
+ *
880
+ * **Default error code** — `"TRANSACTION_ERROR"`.
881
+ *
882
+ * @example
883
+ * Inspecting simulation logs on failure:
884
+ * ```typescript
885
+ * import { isTransactionError } from "@umbra-privacy/sdk";
886
+ *
887
+ * try {
888
+ * const signatures = await forwarder.forwardSequentially([signedTx]);
889
+ * } catch (error) {
890
+ * if (isTransactionError(error)) {
891
+ * console.error("Transaction failed:", error.message);
892
+ * if (error.simulationLogs) {
893
+ * console.error("Simulation logs:");
894
+ * for (const log of error.simulationLogs) {
895
+ * console.error(" ", log);
896
+ * }
897
+ * }
898
+ * if (error.signature) {
899
+ * console.error("Failed signature:", error.signature);
900
+ * }
901
+ * }
902
+ * }
903
+ * ```
904
+ *
905
+ * @example
906
+ * Constructing a `TransactionError`:
907
+ * ```typescript
908
+ * import { TransactionError } from "@umbra-privacy/sdk";
909
+ *
910
+ * throw new TransactionError("Transaction simulation failed", {
911
+ * simulationLogs: ["Program log: AnchorError: Error Code: 6001"],
912
+ * cause: originalError,
913
+ * });
914
+ * ```
915
+ *
916
+ * @see {@link isTransactionError} for the corresponding type guard
917
+ * @see {@link TransactionSigningError} for signing-phase failures
918
+ * @public
919
+ */
920
+ declare class TransactionError extends UmbraError {
921
+ /**
922
+ * The transaction signature, if available.
923
+ *
924
+ * @remarks
925
+ * Base58-encoded signature string. Present when the transaction was submitted
926
+ * to the network but failed during execution. Use this to look up the failed
927
+ * transaction in a block explorer.
928
+ */
929
+ readonly signature?: string;
930
+ /**
931
+ * Simulation log output from the transaction preflight, if available.
932
+ *
933
+ * @remarks
934
+ * Each entry in the array is one line of program log output (e.g.,
935
+ * `"Program log: ..."` or `"Program <address> failed: ..."`). Anchor programs
936
+ * emit error codes and names here when constraints are violated.
937
+ */
938
+ readonly simulationLogs?: string[];
939
+ /**
940
+ * Creates a new `TransactionError`.
941
+ *
942
+ * @param message - Human-readable description of the transaction failure.
943
+ * @param options - Optional structured metadata.
944
+ * @param options.code - Error code string. Defaults to `"TRANSACTION_ERROR"`.
945
+ * @param options.signature - Base58-encoded transaction signature, if available.
946
+ * @param options.simulationLogs - Program log output from preflight simulation.
947
+ * @param options.context - Arbitrary key-value pairs for diagnostic context.
948
+ * @param options.cause - The underlying error that caused this failure, if any.
949
+ */
950
+ constructor(message: string, options?: {
951
+ code?: string;
952
+ signature?: string;
953
+ simulationLogs?: string[];
954
+ context?: Record<string, unknown>;
955
+ cause?: unknown;
956
+ });
957
+ }
958
+ /**
959
+ * Error thrown when transaction signing fails.
960
+ *
961
+ * This is a specific sub-class of {@link TransactionError} that occurs during
962
+ * the signing phase — after the transaction is built but before it is submitted
963
+ * to the network. Common causes include explicit user rejection in a wallet UI,
964
+ * hardware wallet disconnection or timeout, and missing key material.
965
+ *
966
+ * @remarks
967
+ * **User rejection** — When `wasRejected` is `true`, the user deliberately
968
+ * declined to sign in the wallet prompt. This is not an error condition in the
969
+ * traditional sense — the user made an intentional choice. UIs should catch this
970
+ * and show a user-friendly cancellation message rather than an error dialog.
971
+ *
972
+ * **Hardware wallet issues** — When `wasRejected` is `false`, the failure was
973
+ * not deliberate. It may indicate a disconnected Ledger, a timeout waiting for
974
+ * the user to confirm on-device, or an incompatible app version on the device.
975
+ *
976
+ * **Signer address** — `signerAddress` identifies which signer's key was needed
977
+ * at the time of failure. In multi-signer flows this helps identify which party
978
+ * must re-sign.
979
+ *
980
+ * **Default error code** — `"TRANSACTION_SIGNING_ERROR"`.
981
+ *
982
+ * @example
983
+ * Handling user rejection gracefully:
984
+ * ```typescript
985
+ * import { isTransactionSigningError } from "@umbra-privacy/sdk";
986
+ *
987
+ * try {
988
+ * const signedTx = await walletSigner.signTransaction(tx);
989
+ * } catch (error) {
990
+ * if (isTransactionSigningError(error)) {
991
+ * if (error.wasRejected) {
992
+ * showToast("Transaction cancelled by user");
993
+ * } else {
994
+ * showToast(`Signing failed: ${error.message}`);
995
+ * }
996
+ * }
997
+ * }
998
+ * ```
999
+ *
1000
+ * @example
1001
+ * Constructing a `TransactionSigningError`:
1002
+ * ```typescript
1003
+ * import { TransactionSigningError } from "@umbra-privacy/sdk";
1004
+ *
1005
+ * throw new TransactionSigningError("User rejected the transaction", {
1006
+ * wasRejected: true,
1007
+ * signerAddress: wallet.publicKey.toString(),
1008
+ * });
1009
+ * ```
1010
+ *
1011
+ * @see {@link isTransactionSigningError} for the corresponding type guard
1012
+ * @see {@link MasterSeedSigningRejectedError} for the master seed rejection sub-class
1013
+ * @public
1014
+ */
1015
+ declare class TransactionSigningError extends TransactionError {
1016
+ /**
1017
+ * Whether the signing was explicitly rejected by the user.
1018
+ *
1019
+ * @remarks
1020
+ * `true` when the wallet UI presented a sign request and the user actively
1021
+ * clicked "Reject" or equivalent. `false` when the failure was due to a
1022
+ * technical issue (disconnected device, timeout, missing key).
1023
+ *
1024
+ * @defaultValue `false`
1025
+ */
1026
+ readonly wasRejected: boolean;
1027
+ /**
1028
+ * The address of the signer that failed to produce a signature.
1029
+ *
1030
+ * @remarks
1031
+ * Base58-encoded public key string. May be `undefined` if the failing signer
1032
+ * could not be identified at the throw site.
1033
+ */
1034
+ readonly signerAddress?: string;
1035
+ /**
1036
+ * Creates a new `TransactionSigningError`.
1037
+ *
1038
+ * @param message - Human-readable description of the signing failure.
1039
+ * @param options - Optional structured metadata.
1040
+ * @param options.code - Error code string. Defaults to `"TRANSACTION_SIGNING_ERROR"`.
1041
+ * @param options.wasRejected - Whether the user deliberately rejected. Defaults to `false`.
1042
+ * @param options.signerAddress - Base58 address of the signer that failed.
1043
+ * @param options.signature - Transaction signature, if the transaction was partially signed.
1044
+ * @param options.context - Arbitrary key-value pairs for diagnostic context.
1045
+ * @param options.cause - The underlying error that caused this failure, if any.
1046
+ */
1047
+ constructor(message: string, options?: {
1048
+ code?: string;
1049
+ wasRejected?: boolean;
1050
+ signerAddress?: string;
1051
+ signature?: string;
1052
+ context?: Record<string, unknown>;
1053
+ cause?: unknown;
1054
+ });
1055
+ }
1056
+ /**
1057
+ * Error thrown when master seed signing is rejected by the user.
1058
+ *
1059
+ * The Umbra privacy protocol derives a deterministic master seed by asking the
1060
+ * user's wallet to sign a fixed message. This seed is the root of the key
1061
+ * hierarchy used for encrypting and decrypting confidential balances. If the
1062
+ * user declines to sign this message, no Umbra operations that require private
1063
+ * key material can proceed.
1064
+ *
1065
+ * @remarks
1066
+ * This error always has `wasRejected: true` because it is only thrown when the
1067
+ * user deliberately declines — hardware wallet failures or timeouts during the
1068
+ * seed derivation flow produce a generic {@link TransactionSigningError} instead.
1069
+ *
1070
+ * **Recovery** — Prompt the user to explain that the Umbra seed derivation
1071
+ * signature is used only to derive encryption keys locally and is never
1072
+ * broadcast to the network. Then call `getUmbraClientFromSigner` again.
1073
+ *
1074
+ * **Default error code** — `"MASTER_SEED_SIGNING_REJECTED"`.
1075
+ *
1076
+ * @example
1077
+ * Distinguishing master seed rejection from other signing errors:
1078
+ * ```typescript
1079
+ * import {
1080
+ * MasterSeedSigningRejectedError,
1081
+ * isTransactionSigningError,
1082
+ * } from "@umbra-privacy/sdk";
1083
+ *
1084
+ * try {
1085
+ * const client = await getUmbraClientFromSigner({ signer });
1086
+ * } catch (error) {
1087
+ * if (error instanceof MasterSeedSigningRejectedError) {
1088
+ * showModal(
1089
+ * "Umbra needs a signature to derive your private keys locally. " +
1090
+ * "This signature is never sent to the network.",
1091
+ * );
1092
+ * } else if (isTransactionSigningError(error)) {
1093
+ * showToast(`Signing error: ${error.message}`);
1094
+ * }
1095
+ * }
1096
+ * ```
1097
+ *
1098
+ * @see {@link TransactionSigningError} for the parent class
1099
+ * @public
1100
+ */
1101
+ declare class MasterSeedSigningRejectedError extends TransactionSigningError {
1102
+ /**
1103
+ * Creates a new `MasterSeedSigningRejectedError`.
1104
+ *
1105
+ * @param message - Human-readable description. Defaults to a standard rejection
1106
+ * message explaining that the user declined the required derivation signature.
1107
+ * @param options - Optional structured metadata.
1108
+ * @param options.signerAddress - Base58 address of the wallet that rejected.
1109
+ * @param options.context - Arbitrary key-value pairs for diagnostic context.
1110
+ * @param options.cause - The underlying error that caused this failure, if any.
1111
+ */
1112
+ constructor(message?: string, options?: {
1113
+ signerAddress?: string;
1114
+ context?: Record<string, unknown>;
1115
+ cause?: unknown;
1116
+ });
1117
+ }
1118
+ /**
1119
+ * Type guard to check whether an unknown value is an {@link InstructionError}.
1120
+ *
1121
+ * @remarks
1122
+ * Prefer this function over `instanceof InstructionError` in code that may
1123
+ * cross module or bundle boundaries where the class reference might differ.
1124
+ *
1125
+ * @param error - The value to test.
1126
+ * @returns `true` if `error` is an instance of `InstructionError`, narrowing
1127
+ * the type accordingly.
1128
+ *
1129
+ * @example
1130
+ * ```typescript
1131
+ * if (isInstructionError(error)) {
1132
+ * console.error("Instruction:", error.instructionName);
1133
+ * }
1134
+ * ```
1135
+ *
1136
+ * @see {@link InstructionError}
1137
+ * @public
1138
+ */
1139
+ declare function isInstructionError(error: unknown): error is InstructionError;
1140
+ /**
1141
+ * Type guard to check whether an unknown value is an {@link RpcError}.
1142
+ *
1143
+ * @remarks
1144
+ * Prefer this function over `instanceof RpcError` in code that may cross
1145
+ * module or bundle boundaries where the class reference might differ.
1146
+ *
1147
+ * @param error - The value to test.
1148
+ * @returns `true` if `error` is an instance of `RpcError`, narrowing the type
1149
+ * accordingly.
1150
+ *
1151
+ * @example
1152
+ * ```typescript
1153
+ * if (isRpcError(error) && error.statusCode === 429) {
1154
+ * await sleep(backoffMs);
1155
+ * return retry();
1156
+ * }
1157
+ * ```
1158
+ *
1159
+ * @see {@link RpcError}
1160
+ * @public
1161
+ */
1162
+ declare function isRpcError(error: unknown): error is RpcError;
1163
+ /**
1164
+ * Type guard to check whether an unknown value is a {@link TransactionError}.
1165
+ *
1166
+ * @remarks
1167
+ * Because {@link TransactionSigningError} and {@link MasterSeedSigningRejectedError}
1168
+ * extend `TransactionError`, this guard returns `true` for those sub-classes as
1169
+ * well. Use the more specific guards ({@link isTransactionSigningError}) when the
1170
+ * sub-type matters.
1171
+ *
1172
+ * @param error - The value to test.
1173
+ * @returns `true` if `error` is an instance of `TransactionError` or any of its
1174
+ * sub-classes, narrowing the type accordingly.
1175
+ *
1176
+ * @example
1177
+ * ```typescript
1178
+ * if (isTransactionError(error) && error.simulationLogs) {
1179
+ * console.error("Simulation logs:", error.simulationLogs.join("\n"));
1180
+ * }
1181
+ * ```
1182
+ *
1183
+ * @see {@link TransactionError}
1184
+ * @see {@link isTransactionSigningError}
1185
+ * @public
1186
+ */
1187
+ declare function isTransactionError(error: unknown): error is TransactionError;
1188
+ /**
1189
+ * Type guard to check whether an unknown value is a {@link TransactionSigningError}.
1190
+ *
1191
+ * @remarks
1192
+ * Because {@link MasterSeedSigningRejectedError} extends `TransactionSigningError`,
1193
+ * this guard returns `true` for that sub-class as well.
1194
+ *
1195
+ * @param error - The value to test.
1196
+ * @returns `true` if `error` is an instance of `TransactionSigningError` or any
1197
+ * of its sub-classes, narrowing the type accordingly.
1198
+ *
1199
+ * @example
1200
+ * ```typescript
1201
+ * if (isTransactionSigningError(error) && error.wasRejected) {
1202
+ * showCancellationMessage();
1203
+ * }
1204
+ * ```
1205
+ *
1206
+ * @see {@link TransactionSigningError}
1207
+ * @see {@link MasterSeedSigningRejectedError}
1208
+ * @public
1209
+ */
1210
+ declare function isTransactionSigningError(error: unknown): error is TransactionSigningError;
1211
+
1212
+ /**
1213
+ * Umbra Error Classes
1214
+ *
1215
+ * This module provides error classes for all Umbra SDK operation failures,
1216
+ * each carrying a `stage` field that identifies exactly where in the pipeline
1217
+ * the failure occurred.
1218
+ *
1219
+ * @module umbra/errors
1220
+ */
1221
+
1222
+ /**
1223
+ * Stage of the encrypted deposit operation where an error occurred.
1224
+ *
1225
+ * Each stage represents a distinct phase in the deposit flow:
1226
+ *
1227
+ * | Stage | Description |
1228
+ * |-------|-------------|
1229
+ * | `initialization` | Factory-level validation failed |
1230
+ * | `validation` | Input parameter validation failed |
1231
+ * | `mint-fetch` | Failed to fetch mint account data |
1232
+ * | `fee-calculation` | Failed to calculate transfer fee |
1233
+ * | `pda-derivation` | PDA address generation failed |
1234
+ * | `account-fetch` | Failed to fetch account data from RPC |
1235
+ * | `instruction-build` | Failed to build the deposit instruction |
1236
+ * | `transaction-build` | Failed to build transaction message |
1237
+ * | `transaction-compile` | Failed to compile the transaction |
1238
+ * | `transaction-sign` | Failed to sign the transaction |
1239
+ * | `transaction-validate` | Transaction validation failed |
1240
+ * | `transaction-send` | Failed to send or confirm the transaction |
1241
+ */
1242
+ type EncryptedDepositStage = "initialization" | "validation" | "mint-fetch" | "fee-calculation" | "pda-derivation" | "account-fetch" | "instruction-build" | "transaction-build" | "transaction-compile" | "transaction-sign" | "transaction-validate" | "transaction-send";
1243
+ /** Error thrown when an encrypted deposit operation fails. */
1244
+ declare class EncryptedDepositError extends UmbraError {
1245
+ readonly stage: EncryptedDepositStage;
1246
+ constructor(stage: EncryptedDepositStage, message: string, cause?: Error);
1247
+ }
1248
+ /** Type guard to check if an error is an EncryptedDepositError. */
1249
+ declare function isEncryptedDepositError(error: unknown): error is EncryptedDepositError;
1250
+ /**
1251
+ * Stage of the encrypted withdrawal operation where an error occurred.
1252
+ *
1253
+ * | Stage | Description |
1254
+ * |-------|-------------|
1255
+ * | `initialization` | Factory-level validation failed |
1256
+ * | `validation` | Input parameter validation failed |
1257
+ * | `mint-fetch` | Failed to fetch mint account data |
1258
+ * | `pda-derivation` | PDA address generation failed |
1259
+ * | `instruction-build` | Failed to build the withdrawal instruction |
1260
+ * | `transaction-build` | Failed to build transaction message |
1261
+ * | `transaction-compile` | Failed to compile the transaction |
1262
+ * | `transaction-sign` | Failed to sign the transaction |
1263
+ * | `transaction-send` | Failed to send or confirm the transaction |
1264
+ */
1265
+ type EncryptedWithdrawalStage = "initialization" | "validation" | "mint-fetch" | "pda-derivation" | "instruction-build" | "transaction-build" | "transaction-compile" | "transaction-sign" | "transaction-send";
1266
+ /** Error thrown when an encrypted withdrawal operation fails. */
1267
+ declare class EncryptedWithdrawalError extends UmbraError {
1268
+ readonly stage: EncryptedWithdrawalStage;
1269
+ constructor(stage: EncryptedWithdrawalStage, message: string, cause?: Error);
1270
+ }
1271
+ /** Type guard to check if an error is an EncryptedWithdrawalError. */
1272
+ declare function isEncryptedWithdrawalError(error: unknown): error is EncryptedWithdrawalError;
1273
+ /**
1274
+ * Stage of the user registration operation where an error occurred.
1275
+ *
1276
+ * | Stage | Description |
1277
+ * |-------|-------------|
1278
+ * | `initialization` | Factory-level validation failed |
1279
+ * | `master-seed-derivation` | Master seed signing was rejected or failed |
1280
+ * | `account-fetch` | RPC call to read existing registration state failed |
1281
+ * | `key-derivation` | Cryptographic key derivation from master seed failed |
1282
+ * | `zk-proof-generation` | Groth16 proof generation failed (anonymous step) |
1283
+ * | `pda-derivation` | PDA address generation failed |
1284
+ * | `instruction-build` | Failed to build an instruction |
1285
+ * | `transaction-build` | Blockhash fetch or transaction assembly failed |
1286
+ * | `transaction-compile` | Failed to compile the transaction |
1287
+ * | `transaction-sign` | Wallet rejected signing |
1288
+ * | `transaction-validate` | Pre-flight simulation failed |
1289
+ * | `transaction-send` | Transaction sent but confirmation timed out |
1290
+ */
1291
+ type RegistrationStage = "initialization" | "master-seed-derivation" | "account-fetch" | "key-derivation" | "zk-proof-generation" | "pda-derivation" | "instruction-build" | "transaction-build" | "transaction-compile" | "transaction-sign" | "transaction-validate" | "transaction-send";
1292
+ /** Error thrown when a user registration operation fails. */
1293
+ declare class RegistrationError extends UmbraError {
1294
+ readonly stage: RegistrationStage;
1295
+ constructor(stage: RegistrationStage, message: string, cause?: unknown);
1296
+ }
1297
+ /** Type guard to check if an error is a RegistrationError. */
1298
+ declare function isRegistrationError(error: unknown): error is RegistrationError;
1299
+ /**
1300
+ * Stage of the MXE-to-Shared conversion operation where an error occurred.
1301
+ *
1302
+ * | Stage | Description |
1303
+ * |-------|-------------|
1304
+ * | `initialization` | Factory-level validation failed |
1305
+ * | `account-fetch` | Batch RPC fetch of token account PDAs failed |
1306
+ * | `pda-derivation` | PDA address generation failed |
1307
+ * | `instruction-build` | Failed to build a conversion instruction |
1308
+ * | `transaction-build` | Blockhash fetch or transaction assembly failed |
1309
+ * | `transaction-compile` | Failed to compile the transaction |
1310
+ * | `transaction-sign` | Wallet rejected signing for a per-mint transaction |
1311
+ * | `transaction-validate` | Pre-flight simulation failed |
1312
+ * | `transaction-send` | Transaction sent but confirmation timed out |
1313
+ */
1314
+ type ConversionStage = "initialization" | "account-fetch" | "pda-derivation" | "instruction-build" | "transaction-build" | "transaction-compile" | "transaction-sign" | "transaction-validate" | "transaction-send";
1315
+ /** Error thrown when an MXE-to-Shared conversion operation fails. */
1316
+ declare class ConversionError extends UmbraError {
1317
+ readonly stage: ConversionStage;
1318
+ constructor(stage: ConversionStage, message: string, cause?: unknown);
1319
+ }
1320
+ /** Type guard to check if an error is a ConversionError. */
1321
+ declare function isConversionError(error: unknown): error is ConversionError;
1322
+ /**
1323
+ * Stage of a UTXO creation operation where an error occurred.
1324
+ *
1325
+ * | Stage | Description |
1326
+ * |-------|-------------|
1327
+ * | `initialization` | Factory-level validation failed |
1328
+ * | `validation` | Input parameter validation failed |
1329
+ * | `account-fetch` | Failed to fetch recipient or token account data |
1330
+ * | `mint-fetch` | Failed to fetch mint account data |
1331
+ * | `fee-calculation` | Token-2022 transfer fee calculation failed |
1332
+ * | `key-derivation` | Key derivation from master seed failed |
1333
+ * | `zk-proof-generation` | Groth16 proof generation failed |
1334
+ * | `pda-derivation` | PDA address generation failed |
1335
+ * | `instruction-build` | Failed to build an instruction |
1336
+ * | `transaction-build` | Blockhash fetch or transaction assembly failed |
1337
+ * | `transaction-compile` | Failed to compile the transaction |
1338
+ * | `transaction-sign` | Wallet rejected signing |
1339
+ * | `transaction-validate` | Pre-flight simulation failed |
1340
+ * | `transaction-send` | Transaction sent but confirmation timed out |
1341
+ */
1342
+ type CreateUtxoStage = "initialization" | "validation" | "account-fetch" | "mint-fetch" | "fee-calculation" | "key-derivation" | "zk-proof-generation" | "pda-derivation" | "instruction-build" | "transaction-build" | "transaction-compile" | "transaction-sign" | "transaction-validate" | "transaction-send";
1343
+ /** Error thrown when a UTXO creation operation fails. */
1344
+ declare class CreateUtxoError extends UmbraError {
1345
+ readonly stage: CreateUtxoStage;
1346
+ constructor(stage: CreateUtxoStage, message: string, cause?: unknown);
1347
+ }
1348
+ /** Type guard to check if an error is a CreateUtxoError. */
1349
+ declare function isCreateUtxoError(error: unknown): error is CreateUtxoError;
1350
+ /**
1351
+ * Stage of a UTXO fetch operation where an error occurred.
1352
+ *
1353
+ * | Stage | Description |
1354
+ * |-------|-------------|
1355
+ * | `initialization` | Factory construction failed — missing indexerApiEndpoint |
1356
+ * | `validation` | Invalid tree index or insertion index parameters |
1357
+ * | `key-derivation` | X25519 private key derivation from master seed failed |
1358
+ * | `indexer-fetch` | Indexer HTTP call failed |
1359
+ * | `proof-fetch` | Merkle proof HTTP call failed |
1360
+ */
1361
+ type FetchUtxosStage = "initialization" | "validation" | "key-derivation" | "indexer-fetch" | "proof-fetch";
1362
+ /** Error thrown when a UTXO fetch operation fails. */
1363
+ declare class FetchUtxosError extends UmbraError {
1364
+ readonly stage: FetchUtxosStage;
1365
+ constructor(stage: FetchUtxosStage, message: string, cause?: unknown);
1366
+ }
1367
+ /** Type guard to check if an error is a FetchUtxosError. */
1368
+ declare function isFetchUtxosError(error: unknown): error is FetchUtxosError;
1369
+ /**
1370
+ * Stage of a UTXO claim operation where an error occurred.
1371
+ *
1372
+ * | Stage | Description |
1373
+ * |-------|-------------|
1374
+ * | `initialization` | Factory-level validation failed |
1375
+ * | `validation` | Invalid UTXO data or Merkle proof parameters |
1376
+ * | `key-derivation` | Key derivation from master seed failed |
1377
+ * | `zk-proof-generation` | Groth16 proof generation failed |
1378
+ * | `pda-derivation` | PDA address generation failed |
1379
+ * | `instruction-build` | Failed to build an instruction |
1380
+ * | `transaction-build` | Blockhash fetch or transaction assembly failed |
1381
+ * | `transaction-compile` | Failed to compile the transaction |
1382
+ * | `transaction-sign` | Wallet rejected signing |
1383
+ * | `transaction-validate` | Pre-flight simulation failed — also surfaces stale Merkle proof |
1384
+ * | `transaction-send` | Transaction sent but confirmation timed out |
1385
+ */
1386
+ type ClaimUtxoStage = "initialization" | "validation" | "key-derivation" | "zk-proof-generation" | "pda-derivation" | "instruction-build" | "transaction-build" | "transaction-compile" | "transaction-sign" | "transaction-validate" | "transaction-send";
1387
+ /** Error thrown when a UTXO claim operation fails. */
1388
+ declare class ClaimUtxoError extends UmbraError {
1389
+ readonly stage: ClaimUtxoStage;
1390
+ constructor(stage: ClaimUtxoStage, message: string, cause?: unknown);
1391
+ }
1392
+ /** Type guard to check if an error is a ClaimUtxoError. */
1393
+ declare function isClaimUtxoError(error: unknown): error is ClaimUtxoError;
1394
+ /**
1395
+ * Stage of a query operation where an error occurred.
1396
+ *
1397
+ * | Stage | Description |
1398
+ * |-------|-------------|
1399
+ * | `initialization` | Factory-level validation failed |
1400
+ * | `pda-derivation` | PDA address generation failed |
1401
+ * | `account-fetch` | RPC fetch failed |
1402
+ * | `account-decode` | On-chain account data could not be decoded |
1403
+ * | `key-derivation` | X25519 key derivation failed (encrypted balance query) |
1404
+ * | `decryption` | Rescue cipher decryption failed (encrypted balance query) |
1405
+ */
1406
+ type QueryStage = "initialization" | "pda-derivation" | "account-fetch" | "account-decode" | "key-derivation" | "decryption";
1407
+ /** Error thrown when a query operation fails. */
1408
+ declare class QueryError extends UmbraError {
1409
+ readonly stage: QueryStage;
1410
+ constructor(stage: QueryStage, message: string, cause?: unknown);
1411
+ }
1412
+ /** Type guard to check if an error is a QueryError. */
1413
+ declare function isQueryError(error: unknown): error is QueryError;
1414
+
1415
+ export { ClaimUtxoError, type ClaimUtxoStage, ConversionError, type ConversionStage, CreateUtxoError, type CreateUtxoStage, CryptographyAssertionError, CryptographyError, EncryptedDepositError, type EncryptedDepositStage, EncryptedWithdrawalError, type EncryptedWithdrawalStage, FetchUtxosError, type FetchUtxosStage, InstructionError, MasterSeedSigningRejectedError, MathematicsAssertionError, QueryError, type QueryStage, RegistrationError, type RegistrationStage, RpcError, SolanaAssertionError, TemporalAssertionError, TransactionError, TransactionSigningError, UmbraError, isClaimUtxoError, isConversionError, isCreateUtxoError, isCryptographyError, isEncryptedDepositError, isEncryptedWithdrawalError, isFetchUtxosError, isInstructionError, isQueryError, isRegistrationError, isRpcError, isTransactionError, isTransactionSigningError, isUmbraError };