@umbra-privacy/sdk 1.0.0 → 2.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.
- package/README.md +104 -25
- package/dist/{addresses-Brzgurv_.d.ts → addresses-B7HybtbJ.d.ts} +2 -1
- package/dist/{addresses-D_0YAS6B.d.cts → addresses-CTVY1oi7.d.cts} +2 -1
- package/dist/arcium-BXXlryfe.d.cts +20 -0
- package/dist/arcium-BXXlryfe.d.ts +20 -0
- package/dist/chunk-4RHXVBNI.js +203 -0
- package/dist/chunk-4RHXVBNI.js.map +1 -0
- package/dist/chunk-4TZVXB5G.js +324 -0
- package/dist/chunk-4TZVXB5G.js.map +1 -0
- package/dist/chunk-5GUSMQ74.cjs +549 -0
- package/dist/chunk-5GUSMQ74.cjs.map +1 -0
- package/dist/chunk-5KPQXPQM.js +36 -0
- package/dist/chunk-5KPQXPQM.js.map +1 -0
- package/dist/chunk-AXD7LXYY.cjs +405 -0
- package/dist/chunk-AXD7LXYY.cjs.map +1 -0
- package/dist/{chunk-HOEXDXRC.cjs → chunk-BL6WXLPV.cjs} +32 -360
- package/dist/chunk-BL6WXLPV.cjs.map +1 -0
- package/dist/chunk-CFFLOE7D.cjs +598 -0
- package/dist/chunk-CFFLOE7D.cjs.map +1 -0
- package/dist/{chunk-BM7N6N7E.js → chunk-CFTW5WNG.js} +3 -325
- package/dist/chunk-CFTW5WNG.js.map +1 -0
- package/dist/chunk-DD2WCK4C.js +327 -0
- package/dist/chunk-DD2WCK4C.js.map +1 -0
- package/dist/chunk-DMPMQ74B.cjs +246 -0
- package/dist/chunk-DMPMQ74B.cjs.map +1 -0
- package/dist/{chunk-2Q75CQQJ.js → chunk-EEKF4553.js} +2 -2
- package/dist/chunk-EEKF4553.js.map +1 -0
- package/dist/chunk-ENVYYEM4.cjs +113 -0
- package/dist/chunk-ENVYYEM4.cjs.map +1 -0
- package/dist/chunk-FQX6ZYGJ.js +500 -0
- package/dist/chunk-FQX6ZYGJ.js.map +1 -0
- package/dist/chunk-FSK2ICMB.cjs +39 -0
- package/dist/chunk-FSK2ICMB.cjs.map +1 -0
- package/dist/chunk-FZYWLQAF.cjs +355 -0
- package/dist/chunk-FZYWLQAF.cjs.map +1 -0
- package/dist/chunk-GP26R377.js +436 -0
- package/dist/chunk-GP26R377.js.map +1 -0
- package/dist/chunk-HA5FLM63.js +393 -0
- package/dist/chunk-HA5FLM63.js.map +1 -0
- package/dist/chunk-INJ73LXQ.js +1107 -0
- package/dist/chunk-INJ73LXQ.js.map +1 -0
- package/dist/chunk-JPDF7BIT.cjs +10892 -0
- package/dist/chunk-JPDF7BIT.cjs.map +1 -0
- package/dist/{chunk-MDFSBU5W.cjs → chunk-LTCKPTZC.cjs} +2 -351
- package/dist/chunk-LTCKPTZC.cjs.map +1 -0
- package/dist/chunk-MKNCBUFA.js +564 -0
- package/dist/chunk-MKNCBUFA.js.map +1 -0
- package/dist/chunk-NKVMSABR.cjs +207 -0
- package/dist/chunk-NKVMSABR.cjs.map +1 -0
- package/dist/chunk-OFDWNWCL.js +70 -0
- package/dist/chunk-OFDWNWCL.js.map +1 -0
- package/dist/chunk-QJAUUYZU.cjs +331 -0
- package/dist/chunk-QJAUUYZU.cjs.map +1 -0
- package/dist/chunk-RVUYPKKD.js +10750 -0
- package/dist/chunk-RVUYPKKD.js.map +1 -0
- package/dist/chunk-TLR7A64G.js +103 -0
- package/dist/chunk-TLR7A64G.js.map +1 -0
- package/dist/{chunk-MVKTV3FT.cjs → chunk-TQQZGNOI.cjs} +2 -2
- package/dist/chunk-TQQZGNOI.cjs.map +1 -0
- package/dist/chunk-UOFYS6M3.js +219 -0
- package/dist/chunk-UOFYS6M3.js.map +1 -0
- package/dist/chunk-UXMQI6B7.js +2406 -0
- package/dist/chunk-UXMQI6B7.js.map +1 -0
- package/dist/chunk-WN75ORDT.js +571 -0
- package/dist/chunk-WN75ORDT.js.map +1 -0
- package/dist/chunk-Y55PYKXH.cjs +595 -0
- package/dist/chunk-Y55PYKXH.cjs.map +1 -0
- package/dist/chunk-YEZBTYCP.cjs +77 -0
- package/dist/chunk-YEZBTYCP.cjs.map +1 -0
- package/dist/chunk-ZQOIYCGA.cjs +1126 -0
- package/dist/chunk-ZQOIYCGA.cjs.map +1 -0
- package/dist/chunk-ZY3TSHMJ.cjs +2665 -0
- package/dist/chunk-ZY3TSHMJ.cjs.map +1 -0
- package/dist/client-DkVBHMWb.d.cts +2613 -0
- package/dist/client-V4AF6Bz9.d.ts +2613 -0
- package/dist/common/pda/index.cjs +145 -0
- package/dist/common/pda/index.cjs.map +1 -0
- package/dist/common/pda/index.d.cts +1250 -0
- package/dist/common/pda/index.d.ts +1250 -0
- package/dist/common/pda/index.js +8 -0
- package/dist/common/pda/index.js.map +1 -0
- package/dist/constants/index.cjs +38 -164
- package/dist/constants/index.cjs.map +1 -1
- package/dist/constants/index.d.cts +8 -425
- package/dist/constants/index.d.ts +8 -425
- package/dist/constants/index.js +15 -124
- package/dist/constants/index.js.map +1 -1
- package/dist/crypto/index.cjs +583 -0
- package/dist/crypto/index.cjs.map +1 -0
- package/dist/crypto/index.d.cts +6731 -0
- package/dist/crypto/index.d.ts +6731 -0
- package/dist/crypto/index.js +14 -0
- package/dist/crypto/index.js.map +1 -0
- package/dist/{cryptography-BTGC72u-.d.ts → cryptography-BFSJcvi6.d.ts} +3 -2465
- package/dist/{cryptography-BTGC72u-.d.cts → cryptography-D6tPDh-Y.d.cts} +3 -2465
- package/dist/errors/index.cjs +64 -54
- package/dist/errors/index.d.cts +7 -797
- package/dist/errors/index.d.ts +7 -797
- package/dist/errors/index.js +3 -1
- package/dist/errors-B9EoPeWV.d.cts +593 -0
- package/dist/errors-B9EoPeWV.d.ts +593 -0
- package/dist/errors-DAIrstEL.d.cts +300 -0
- package/dist/errors-DPNMfyh0.d.ts +300 -0
- package/dist/index-BG0yjL7C.d.cts +6006 -0
- package/dist/index-ByynoyBO.d.ts +6006 -0
- package/dist/index.cjs +5126 -16118
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1031 -7685
- package/dist/index.d.ts +1031 -7685
- package/dist/index.js +3219 -14905
- package/dist/index.js.map +1 -1
- package/dist/interfaces/index.d.cts +14 -6
- package/dist/interfaces/index.d.ts +14 -6
- package/dist/interfaces-43cReBcS.d.cts +3346 -0
- package/dist/interfaces-B8xKNl_6.d.ts +997 -0
- package/dist/interfaces-D2NO6kDD.d.cts +997 -0
- package/dist/interfaces-z_xYJlgV.d.ts +3346 -0
- package/dist/math/index.cjs +115 -0
- package/dist/math/index.cjs.map +1 -0
- package/dist/math/index.d.cts +1327 -0
- package/dist/math/index.d.ts +1327 -0
- package/dist/math/index.js +10 -0
- package/dist/math/index.js.map +1 -0
- package/dist/networks-RMd3abPE.d.ts +44 -0
- package/dist/networks-yAoO8peQ.d.cts +44 -0
- package/dist/relayer-NRRMSMNB.js +4 -0
- package/dist/relayer-NRRMSMNB.js.map +1 -0
- package/dist/relayer-RJHEIXJG.cjs +21 -0
- package/dist/relayer-RJHEIXJG.cjs.map +1 -0
- package/dist/solana/index.cjs +56 -0
- package/dist/solana/index.cjs.map +1 -0
- package/dist/solana/index.d.cts +105 -0
- package/dist/solana/index.d.ts +105 -0
- package/dist/solana/index.js +7 -0
- package/dist/solana/index.js.map +1 -0
- package/dist/{index-CLj_zWSD.d.ts → temporal-BbRaEPoO.d.ts} +1 -1
- package/dist/{index-CX6_pIRS.d.cts → temporal-oUj7iCaq.d.cts} +1 -1
- package/dist/transaction-forwarder-5mAMTjw6.d.ts +1155 -0
- package/dist/transaction-forwarder-C6gMUG7a.d.cts +1155 -0
- package/dist/types/index.cjs +232 -231
- package/dist/types/index.d.cts +15 -1485
- package/dist/types/index.d.ts +15 -1485
- package/dist/types/index.js +2 -1
- package/dist/types-BohhvPth.d.cts +87 -0
- package/dist/types-CW0oTT0j.d.ts +87 -0
- package/dist/types-C_V_CaKK.d.cts +2468 -0
- package/dist/types-C_V_CaKK.d.ts +2468 -0
- package/dist/types-Ca7frykr.d.ts +793 -0
- package/dist/types-CuKeoI19.d.cts +1296 -0
- package/dist/types-CxfTIpN9.d.ts +1052 -0
- package/dist/{types-n-sHFcgr.d.ts → types-D1jDUjfN.d.ts} +2 -2
- package/dist/types-DKEDUlH9.d.ts +1296 -0
- package/dist/types-EKuIfxTz.d.cts +1052 -0
- package/dist/{types-BBuELtY8.d.cts → types-IMGYmlv-.d.cts} +2 -2
- package/dist/types-PwNLi_2k.d.cts +793 -0
- package/dist/utils/index.cjs +823 -525
- package/dist/utils/index.d.cts +1711 -4021
- package/dist/utils/index.d.ts +1711 -4021
- package/dist/utils/index.js +9 -3
- package/dist/{versions-D9PqsEvj.d.cts → versions-BRlR36EA.d.cts} +1 -0
- package/dist/{versions-D9PqsEvj.d.ts → versions-BRlR36EA.d.ts} +1 -0
- package/package.json +79 -18
- package/dist/chunk-2Q75CQQJ.js.map +0 -1
- package/dist/chunk-BM7N6N7E.js.map +0 -1
- package/dist/chunk-GXKSUB2U.cjs +0 -4416
- package/dist/chunk-GXKSUB2U.cjs.map +0 -1
- package/dist/chunk-HOEXDXRC.cjs.map +0 -1
- package/dist/chunk-MDFSBU5W.cjs.map +0 -1
- package/dist/chunk-MQY7HDIA.js +0 -600
- package/dist/chunk-MQY7HDIA.js.map +0 -1
- package/dist/chunk-MVKTV3FT.cjs.map +0 -1
- package/dist/chunk-PG2J6V6Y.js +0 -4094
- package/dist/chunk-PG2J6V6Y.js.map +0 -1
- package/dist/chunk-VEGLTTYQ.cjs +0 -621
- package/dist/chunk-VEGLTTYQ.cjs.map +0 -1
- package/dist/chunk-WVHQ46DD.js +0 -758
- package/dist/chunk-WVHQ46DD.js.map +0 -1
- package/dist/index-B9pDY73x.d.ts +0 -12933
- package/dist/index-D33yo0qB.d.cts +0 -12933
- package/dist/networks-C-orpSFW.d.ts +0 -65
- package/dist/networks-FxYERGD1.d.cts +0 -65
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
import { __name } from './chunk-7QVYU63E.js';
|
|
2
|
+
|
|
3
|
+
// src/common/errors.ts
|
|
4
|
+
var UmbraError = class _UmbraError extends Error {
|
|
5
|
+
static {
|
|
6
|
+
__name(this, "UmbraError");
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* A machine-readable error code for programmatic error handling.
|
|
10
|
+
*
|
|
11
|
+
* @remarks
|
|
12
|
+
* Defaults to `"UMBRA_ERROR"` when no code is supplied in the constructor options.
|
|
13
|
+
* Sub-classes or specific throw sites should supply a more specific code to allow
|
|
14
|
+
* callers to branch on error identity without string-matching `message`.
|
|
15
|
+
*
|
|
16
|
+
* @readonly
|
|
17
|
+
*/
|
|
18
|
+
code;
|
|
19
|
+
/**
|
|
20
|
+
* Additional context about the error.
|
|
21
|
+
*
|
|
22
|
+
* @remarks
|
|
23
|
+
* A free-form key-value map of diagnostic data attached to the error at the throw site.
|
|
24
|
+
* Useful for logging and debugging — consumers should not rely on specific keys for
|
|
25
|
+
* control flow; use `code` for programmatic branching instead.
|
|
26
|
+
*
|
|
27
|
+
* Will be `undefined` when no context was provided to the constructor.
|
|
28
|
+
*
|
|
29
|
+
* @readonly
|
|
30
|
+
*/
|
|
31
|
+
context;
|
|
32
|
+
/**
|
|
33
|
+
* The original error that caused this error, if any.
|
|
34
|
+
*
|
|
35
|
+
* @remarks
|
|
36
|
+
* When an SDK function wraps a lower-level error (e.g., a failed RPC call or a
|
|
37
|
+
* cryptographic library error), it sets `cause` to the original thrown value so
|
|
38
|
+
* callers can inspect the full error chain.
|
|
39
|
+
*
|
|
40
|
+
* Will be `undefined` when there is no underlying cause.
|
|
41
|
+
*
|
|
42
|
+
* @readonly
|
|
43
|
+
*/
|
|
44
|
+
cause;
|
|
45
|
+
/**
|
|
46
|
+
* Creates a new UmbraError.
|
|
47
|
+
*
|
|
48
|
+
* @param message - Human-readable description of what went wrong. Should be
|
|
49
|
+
* actionable and specific enough for a developer to understand the failure
|
|
50
|
+
* without reading source code.
|
|
51
|
+
* @param options - Optional structured metadata attached to the error.
|
|
52
|
+
* @param options.code - Machine-readable error code for programmatic branching.
|
|
53
|
+
* Defaults to `"UMBRA_ERROR"` if omitted.
|
|
54
|
+
* @param options.context - Free-form diagnostic key-value pairs. Omit or set to
|
|
55
|
+
* `undefined` to leave the `context` property unset.
|
|
56
|
+
* @param options.cause - The original error that triggered this one. Enables
|
|
57
|
+
* full error-chain inspection. Omit or set to `undefined` when there is no
|
|
58
|
+
* underlying cause.
|
|
59
|
+
*
|
|
60
|
+
* @defaultValue `options` — `undefined` (all options optional)
|
|
61
|
+
* @defaultValue `options.code` — `"UMBRA_ERROR"`
|
|
62
|
+
*/
|
|
63
|
+
constructor(message, options) {
|
|
64
|
+
super(message);
|
|
65
|
+
this.name = "UmbraError";
|
|
66
|
+
this.code = options?.code ?? "UMBRA_ERROR";
|
|
67
|
+
if (options?.context !== void 0) {
|
|
68
|
+
this.context = options.context;
|
|
69
|
+
}
|
|
70
|
+
if (options?.cause !== void 0) {
|
|
71
|
+
this.cause = options.cause;
|
|
72
|
+
}
|
|
73
|
+
Error.captureStackTrace(this, _UmbraError);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
function isUmbraError(error) {
|
|
77
|
+
return error instanceof UmbraError;
|
|
78
|
+
}
|
|
79
|
+
__name(isUmbraError, "isUmbraError");
|
|
80
|
+
var MathematicsAssertionError = class _MathematicsAssertionError extends Error {
|
|
81
|
+
static {
|
|
82
|
+
__name(this, "MathematicsAssertionError");
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* The actual value that failed the assertion.
|
|
86
|
+
*
|
|
87
|
+
* @remarks
|
|
88
|
+
* The runtime type reflects what was actually passed to the assertion function:
|
|
89
|
+
* - `bigint` for integer assertions (`assertU8`, `assertU256`, etc.)
|
|
90
|
+
* - `Uint8Array` for byte-array assertions (`assertU256LeBytes`, `assertU32LeBytes`, etc.)
|
|
91
|
+
* - Any other type when a non-numeric value was passed unexpectedly
|
|
92
|
+
*
|
|
93
|
+
* @readonly
|
|
94
|
+
*/
|
|
95
|
+
value;
|
|
96
|
+
/**
|
|
97
|
+
* The type that was expected.
|
|
98
|
+
*
|
|
99
|
+
* @remarks
|
|
100
|
+
* Contains the branded type name exactly as it appears in the SDK type system,
|
|
101
|
+
* e.g., `"U8"`, `"U256"`, `"U32LeBytes"`. Use this for structured logging or
|
|
102
|
+
* to build user-facing error messages without parsing the `message` string.
|
|
103
|
+
*
|
|
104
|
+
* @readonly
|
|
105
|
+
*/
|
|
106
|
+
expectedType;
|
|
107
|
+
/**
|
|
108
|
+
* Description of the constraint that was violated.
|
|
109
|
+
*
|
|
110
|
+
* @remarks
|
|
111
|
+
* Is `undefined` when only a type check failed (e.g., a `string` was passed where a
|
|
112
|
+
* `bigint` was expected). Contains a human-readable inequality or length rule when a
|
|
113
|
+
* value of the correct type was out of the allowed range.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* - `"0 <= value <= 255"` — U8 range violation
|
|
117
|
+
* - `"length === 32"` — U256LeBytes length violation
|
|
118
|
+
* - `"value >= 0"` — negative value passed to an unsigned integer assertion
|
|
119
|
+
*
|
|
120
|
+
* @readonly
|
|
121
|
+
*/
|
|
122
|
+
constraint;
|
|
123
|
+
/**
|
|
124
|
+
* Creates a new MathematicsAssertionError.
|
|
125
|
+
*
|
|
126
|
+
* @param message - Human-readable description of the assertion failure. Should name
|
|
127
|
+
* the assertion function, the expected type, and the constraint that was violated.
|
|
128
|
+
* @param options - Structured diagnostic details attached to the error.
|
|
129
|
+
* @param options.value - The actual value that was supplied and failed the assertion.
|
|
130
|
+
* @param options.expectedType - The name of the branded type that was expected
|
|
131
|
+
* (e.g., `"U8"`, `"U256LeBytes"`).
|
|
132
|
+
* @param options.constraint - Optional human-readable constraint description
|
|
133
|
+
* (e.g., `"0 <= value <= 255"`). Omit when the failure is a type mismatch rather
|
|
134
|
+
* than a range violation.
|
|
135
|
+
*/
|
|
136
|
+
constructor(message, options) {
|
|
137
|
+
super(message);
|
|
138
|
+
this.name = "MathematicsAssertionError";
|
|
139
|
+
this.value = options.value;
|
|
140
|
+
this.expectedType = options.expectedType;
|
|
141
|
+
this.constraint = options.constraint;
|
|
142
|
+
Error.captureStackTrace(this, _MathematicsAssertionError);
|
|
143
|
+
Object.setPrototypeOf(this, _MathematicsAssertionError.prototype);
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
var CryptographyAssertionError = class _CryptographyAssertionError extends Error {
|
|
147
|
+
static {
|
|
148
|
+
__name(this, "CryptographyAssertionError");
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* The actual value that failed the assertion.
|
|
152
|
+
*
|
|
153
|
+
* @remarks
|
|
154
|
+
* The runtime type reflects what was actually passed to the assertion function:
|
|
155
|
+
* - `bigint` for field element assertions (`assertBn254FieldElement`, etc.)
|
|
156
|
+
* - `Uint8Array` for byte-array assertions (`assertAesKey`, `assertX25519PrivateKey`, etc.)
|
|
157
|
+
* - Any other type when an entirely wrong value type was supplied
|
|
158
|
+
*
|
|
159
|
+
* @readonly
|
|
160
|
+
*/
|
|
161
|
+
value;
|
|
162
|
+
/**
|
|
163
|
+
* The type that was expected (e.g., `"Bn254FieldElement"`, `"PoseidonKey"`, `"AesKey"`).
|
|
164
|
+
*
|
|
165
|
+
* @remarks
|
|
166
|
+
* Contains the branded type name exactly as it appears in the SDK type system.
|
|
167
|
+
* Use this property for structured logging without parsing the `message` string.
|
|
168
|
+
*
|
|
169
|
+
* @readonly
|
|
170
|
+
*/
|
|
171
|
+
expectedType;
|
|
172
|
+
/**
|
|
173
|
+
* Description of the constraint that was violated.
|
|
174
|
+
*
|
|
175
|
+
* @remarks
|
|
176
|
+
* Is `undefined` for pure type-mismatch failures (e.g., `string` instead of `bigint`).
|
|
177
|
+
* Contains a human-readable constraint description for range and length violations
|
|
178
|
+
* (e.g., `"value < BN254_FIELD_PRIME"`, `"length === 32"`).
|
|
179
|
+
*
|
|
180
|
+
* @readonly
|
|
181
|
+
*/
|
|
182
|
+
constraint;
|
|
183
|
+
/**
|
|
184
|
+
* Creates a new CryptographyAssertionError.
|
|
185
|
+
*
|
|
186
|
+
* @param message - Human-readable description of the assertion failure. Should name
|
|
187
|
+
* the assertion function, the expected type, and the constraint that was violated.
|
|
188
|
+
* @param options - Structured diagnostic details attached to the error.
|
|
189
|
+
* @param options.value - The actual value that was supplied and failed the assertion.
|
|
190
|
+
* @param options.expectedType - The name of the branded cryptographic type that was
|
|
191
|
+
* expected (e.g., `"Bn254FieldElement"`, `"AesKey"`).
|
|
192
|
+
* @param options.constraint - Optional human-readable constraint description.
|
|
193
|
+
* Omit when the failure is a type mismatch rather than a range or length violation.
|
|
194
|
+
*/
|
|
195
|
+
constructor(message, options) {
|
|
196
|
+
super(message);
|
|
197
|
+
this.name = "CryptographyAssertionError";
|
|
198
|
+
this.value = options.value;
|
|
199
|
+
this.expectedType = options.expectedType;
|
|
200
|
+
this.constraint = options.constraint;
|
|
201
|
+
Error.captureStackTrace(this, _CryptographyAssertionError);
|
|
202
|
+
Object.setPrototypeOf(this, _CryptographyAssertionError.prototype);
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
var SolanaAssertionError = class _SolanaAssertionError extends Error {
|
|
206
|
+
static {
|
|
207
|
+
__name(this, "SolanaAssertionError");
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* The actual value that failed the assertion.
|
|
211
|
+
*
|
|
212
|
+
* @remarks
|
|
213
|
+
* The runtime type reflects what was actually passed to the assertion function:
|
|
214
|
+
* - `string` for Base58-encoded assertions (`assertTransactionSignature`, etc.)
|
|
215
|
+
* - `Uint8Array` for byte-array assertions (`assertSignatureBytes`, etc.)
|
|
216
|
+
* - Any other type when a completely wrong value type was supplied
|
|
217
|
+
*
|
|
218
|
+
* @readonly
|
|
219
|
+
*/
|
|
220
|
+
value;
|
|
221
|
+
/**
|
|
222
|
+
* The type that was expected (e.g., `"TransactionSignature"`, `"SignatureBytes"`).
|
|
223
|
+
*
|
|
224
|
+
* @remarks
|
|
225
|
+
* Contains the branded type name exactly as it appears in the SDK type system.
|
|
226
|
+
* Use this for structured logging without parsing the `message` string.
|
|
227
|
+
*
|
|
228
|
+
* @readonly
|
|
229
|
+
*/
|
|
230
|
+
expectedType;
|
|
231
|
+
/**
|
|
232
|
+
* Description of the constraint that was violated.
|
|
233
|
+
*
|
|
234
|
+
* @remarks
|
|
235
|
+
* Is `undefined` for pure type-mismatch failures. Contains a human-readable rule
|
|
236
|
+
* for encoding or length violations (e.g., `"valid Base58"`, `"length === 64"`).
|
|
237
|
+
*
|
|
238
|
+
* @readonly
|
|
239
|
+
*/
|
|
240
|
+
constraint;
|
|
241
|
+
/**
|
|
242
|
+
* Creates a new SolanaAssertionError.
|
|
243
|
+
*
|
|
244
|
+
* @param message - Human-readable description of the assertion failure. Should name
|
|
245
|
+
* the assertion function, the expected type, and the constraint that was violated.
|
|
246
|
+
* @param options - Structured diagnostic details attached to the error.
|
|
247
|
+
* @param options.value - The actual value that was supplied and failed the assertion.
|
|
248
|
+
* @param options.expectedType - The name of the branded Solana type that was expected
|
|
249
|
+
* (e.g., `"TransactionSignature"`, `"SignatureBytes"`).
|
|
250
|
+
* @param options.constraint - Optional human-readable constraint description.
|
|
251
|
+
* Omit when the failure is a type mismatch rather than an encoding or length violation.
|
|
252
|
+
*/
|
|
253
|
+
constructor(message, options) {
|
|
254
|
+
super(message);
|
|
255
|
+
this.name = "SolanaAssertionError";
|
|
256
|
+
this.value = options.value;
|
|
257
|
+
this.expectedType = options.expectedType;
|
|
258
|
+
this.constraint = options.constraint;
|
|
259
|
+
Error.captureStackTrace(this, _SolanaAssertionError);
|
|
260
|
+
Object.setPrototypeOf(this, _SolanaAssertionError.prototype);
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
var TemporalAssertionError = class extends Error {
|
|
264
|
+
static {
|
|
265
|
+
__name(this, "TemporalAssertionError");
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* The actual value that failed the assertion.
|
|
269
|
+
*
|
|
270
|
+
* @remarks
|
|
271
|
+
* Will be a `bigint` for all temporal assertions since the temporal types are
|
|
272
|
+
* BigInt-backed branded types (e.g., `Year`, `Month`, `Day`). May also be any
|
|
273
|
+
* other type when a non-bigint value was supplied unexpectedly.
|
|
274
|
+
*
|
|
275
|
+
* @readonly
|
|
276
|
+
*/
|
|
277
|
+
value;
|
|
278
|
+
/**
|
|
279
|
+
* The type that was expected (e.g., `"Year"`, `"Month"`, `"Hour"`).
|
|
280
|
+
*
|
|
281
|
+
* @remarks
|
|
282
|
+
* Contains the branded temporal type name exactly as it appears in the SDK type system.
|
|
283
|
+
* Use this for structured logging without parsing the `message` string.
|
|
284
|
+
*
|
|
285
|
+
* @readonly
|
|
286
|
+
*/
|
|
287
|
+
expectedType;
|
|
288
|
+
/**
|
|
289
|
+
* Description of the constraint that was violated.
|
|
290
|
+
*
|
|
291
|
+
* @remarks
|
|
292
|
+
* Contains a human-readable range rule for out-of-range values
|
|
293
|
+
* (e.g., `"1 <= value <= 12"` for a month violation). Is `undefined` only for
|
|
294
|
+
* pure type-mismatch failures (e.g., a `string` passed where a `bigint` was expected),
|
|
295
|
+
* which should not occur in normal usage.
|
|
296
|
+
*
|
|
297
|
+
* @readonly
|
|
298
|
+
*/
|
|
299
|
+
constraint;
|
|
300
|
+
/**
|
|
301
|
+
* Creates a new TemporalAssertionError.
|
|
302
|
+
*
|
|
303
|
+
* @param message - Human-readable description of the assertion failure. Should name
|
|
304
|
+
* the assertion function, the expected type, and the violated range constraint.
|
|
305
|
+
* @param details - Structured diagnostic details attached to the error.
|
|
306
|
+
* @param details.value - The actual `bigint` value (or other type) that was supplied
|
|
307
|
+
* and failed the temporal assertion.
|
|
308
|
+
* @param details.expectedType - The name of the branded temporal type that was expected
|
|
309
|
+
* (e.g., `"Year"`, `"Month"`, `"Hour"`).
|
|
310
|
+
* @param details.constraint - Optional human-readable range description
|
|
311
|
+
* (e.g., `"1 <= value <= 12"`). Omit when the failure is a type mismatch.
|
|
312
|
+
*/
|
|
313
|
+
constructor(message, details) {
|
|
314
|
+
super(message);
|
|
315
|
+
this.name = "TemporalAssertionError";
|
|
316
|
+
this.value = details.value;
|
|
317
|
+
this.expectedType = details.expectedType;
|
|
318
|
+
this.constraint = details.constraint;
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
export { CryptographyAssertionError, MathematicsAssertionError, SolanaAssertionError, TemporalAssertionError, UmbraError, isUmbraError };
|
|
323
|
+
//# sourceMappingURL=chunk-4TZVXB5G.js.map
|
|
324
|
+
//# sourceMappingURL=chunk-4TZVXB5G.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/common/errors.ts"],"names":[],"mappings":";;;AAqEO,IAAM,UAAA,GAAN,MAAM,WAAA,SAAmB,KAAA,CAAM;AAAA,EArEtC;AAqEsC,IAAA,MAAA,CAAA,IAAA,EAAA,YAAA,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAW3B,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAcA,OAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAcS,KAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAoBlB,WAAA,CACE,SACA,OAAA,EAKA;AACA,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,IAAA,GAAO,YAAA;AACZ,IAAA,IAAA,CAAK,IAAA,GAAO,SAAS,IAAA,IAAQ,aAAA;AAC7B,IAAA,IAAI,OAAA,EAAS,YAAY,MAAA,EAAW;AAClC,MAAA,IAAA,CAAK,UAAU,OAAA,CAAQ,OAAA;AAAA,IACz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archy for the Umbra SDK.\n * Contains the base `UmbraError` and all domain-specific assertion error classes.\n *\n * @remarks\n * The SDK uses a two-level error hierarchy:\n *\n * 1. `UmbraError` — top-level base class for all SDK errors. Consumers can use\n * `instanceof UmbraError` (or the `isUmbraError` type guard) to distinguish SDK errors\n * from third-party or built-in errors in a catch block.\n *\n * 2. Domain assertion errors — thrown by type-assertion functions when a value fails\n * validation. Each domain has its own class to make it easy to catch errors from a\n * specific subsystem:\n * - `MathematicsAssertionError` — thrown by `assertU8`, `assertU256`, etc.\n * - `CryptographyAssertionError` — thrown by `assertBn254FieldElement`, `assertAesKey`, etc.\n * - `SolanaAssertionError` — thrown by Solana-type assertion functions.\n * - `TemporalAssertionError` — thrown by `assertYear`, `assertMonth`, etc.\n *\n * All four assertion error classes share the same three properties:\n * - `value` — the actual value that failed\n * - `expectedType` — the name of the expected branded type\n * - `constraint` — optional human-readable constraint description\n *\n * @packageDocumentation\n * @since 2.0.0\n * @module common/errors\n */\n\n/* =============================================================================\n * BASE ERROR\n *\n * The root error class for all Umbra SDK errors.\n * ============================================================================= */\n\n/**\n * Base error class for all Umbra SDK errors.\n *\n * All errors thrown by the SDK extend this class, allowing consumers\n * to distinguish SDK errors from other errors using `instanceof`.\n *\n * @remarks\n * Prefer using the `isUmbraError` type guard over `instanceof UmbraError` when writing\n * defensive catch handlers — the type guard also works across module boundaries and\n * iframe/realm boundaries where `instanceof` may fail due to different class references.\n *\n * Sub-classes (domain assertion errors) extend this class so callers can catch either\n * all SDK errors at once (`instanceof UmbraError`) or only a specific domain's failures\n * (e.g., `instanceof MathematicsAssertionError`).\n *\n * @example\n * ```typescript\n * try {\n * await umbraClient.register();\n * } catch (error) {\n * if (error instanceof UmbraError) {\n * console.log('SDK error:', error.message);\n * console.log('Error code:', error.code);\n * } else {\n * throw error; // Re-throw non-SDK errors\n * }\n * }\n * ```\n *\n * @see {@link isUmbraError}\n * @public\n */\nexport class UmbraError extends Error {\n /**\n * A machine-readable error code for programmatic error handling.\n *\n * @remarks\n * Defaults to `\"UMBRA_ERROR\"` when no code is supplied in the constructor options.\n * Sub-classes or specific throw sites should supply a more specific code to allow\n * callers to branch on error identity without string-matching `message`.\n *\n * @readonly\n */\n readonly code: string;\n\n /**\n * Additional context about the error.\n *\n * @remarks\n * A free-form key-value map of diagnostic data attached to the error at the throw site.\n * Useful for logging and debugging — consumers should not rely on specific keys for\n * control flow; use `code` for programmatic branching instead.\n *\n * Will be `undefined` when no context was provided to the constructor.\n *\n * @readonly\n */\n readonly context?: Record<string, unknown>;\n\n /**\n * The original error that caused this error, if any.\n *\n * @remarks\n * When an SDK function wraps a lower-level error (e.g., a failed RPC call or a\n * cryptographic library error), it sets `cause` to the original thrown value so\n * callers can inspect the full error chain.\n *\n * Will be `undefined` when there is no underlying cause.\n *\n * @readonly\n */\n override readonly cause?: unknown;\n\n /**\n * Creates a new UmbraError.\n *\n * @param message - Human-readable description of what went wrong. Should be\n * actionable and specific enough for a developer to understand the failure\n * without reading source code.\n * @param options - Optional structured metadata attached to the error.\n * @param options.code - Machine-readable error code for programmatic branching.\n * Defaults to `\"UMBRA_ERROR\"` if omitted.\n * @param options.context - Free-form diagnostic key-value pairs. Omit or set to\n * `undefined` to leave the `context` property unset.\n * @param options.cause - The original error that triggered this one. Enables\n * full error-chain inspection. Omit or set to `undefined` when there is no\n * underlying cause.\n *\n * @defaultValue `options` — `undefined` (all options optional)\n * @defaultValue `options.code` — `\"UMBRA_ERROR\"`\n */\n constructor(\n message: string,\n options?: {\n code?: string;\n context?: Record<string, unknown>;\n cause?: unknown;\n },\n ) {\n super(message);\n this.name = \"UmbraError\";\n this.code = options?.code ?? \"UMBRA_ERROR\";\n if (options?.context !== undefined) {\n this.context = options.context;\n }\n if (options?.cause !== undefined) {\n this.cause = options.cause;\n }\n\n // Maintains proper stack trace for where our error was thrown (only available on V8)\n Error.captureStackTrace(this, UmbraError);\n }\n}\n\n/**\n * Type guard to check if an error is an UmbraError.\n *\n * @remarks\n * Prefer this guard over `error instanceof UmbraError` in generic catch handlers because\n * it is safe to call with any value (including `null`, primitives, and non-Error objects)\n * and narrows the type to `UmbraError` for TypeScript's type system in the true branch.\n *\n * @param error - The value to test. Typically the caught value in a `catch (error)` block,\n * typed as `unknown`.\n * @returns `true` and narrows `error` to `UmbraError` when the value is an instance of\n * `UmbraError` (or any sub-class such as `MathematicsAssertionError`). Returns `false`\n * for all other values.\n *\n * @example\n * ```typescript\n * try {\n * await operation();\n * } catch (error) {\n * if (isUmbraError(error)) {\n * // error is narrowed to UmbraError here\n * console.log('SDK error code:', error.code);\n * console.log('SDK error context:', error.context);\n * }\n * }\n * ```\n *\n * @see {@link UmbraError}\n * @public\n */\nexport function isUmbraError(error: unknown): error is UmbraError {\n return error instanceof UmbraError;\n}\n\n/* =============================================================================\n * MATHEMATICS ASSERTION ERROR\n *\n * Error thrown when mathematical type assertions fail.\n * ============================================================================= */\n\n/**\n * Error thrown when a value fails a mathematical type assertion.\n *\n * This error provides detailed information about why an assertion failed,\n * including the actual value, the expected type, and the constraint that\n * was violated.\n *\n * @remarks\n * All assertion functions in the mathematics module (e.g., `assertU8`, `assertU256`,\n * `assertU32LeBytes`) throw this error type on failure. Catch it specifically to handle\n * mathematical type validation failures differently from cryptographic or Solana errors.\n *\n * The three diagnostic properties together allow automated logging pipelines to produce\n * structured records without parsing the `message` string:\n * - `value` — the actual value that was supplied\n * - `expectedType` — the branded type name (e.g., `\"U8\"`, `\"U256LeBytes\"`)\n * - `constraint` — the violated range or length rule, or `undefined` for type mismatches\n *\n * Note that this class does NOT extend `UmbraError`. It extends `Error` directly to keep\n * the assertion error classes lightweight and independent of the UmbraError hierarchy.\n * Use `isUmbraError` only to detect top-level SDK operational errors; use\n * `instanceof MathematicsAssertionError` for assertion failures.\n *\n * @example\n * ```typescript\n * import { assertU8, MathematicsAssertionError } from \"./mathematics\";\n *\n * try {\n * const value = assertU8(256n); // Will throw\n * } catch (error) {\n * if (error instanceof MathematicsAssertionError) {\n * console.error(`Assertion failed for ${error.expectedType}`);\n * console.error(`Value: ${error.value}`);\n * console.error(`Constraint: ${error.constraint}`);\n * // Output:\n * // Assertion failed for U8\n * // Value: 256\n * // Constraint: 0 <= value <= 255\n * }\n * }\n * ```\n *\n * @example\n * ```typescript\n * // Safe parse pattern — returns null instead of throwing\n * function safeParseU8(value: bigint): U8 | null {\n * try {\n * return assertU8(value);\n * } catch (error) {\n * if (error instanceof MathematicsAssertionError) {\n * console.warn(`Invalid U8 value: ${value}`);\n * return null;\n * }\n * throw error; // Re-throw unexpected errors\n * }\n * }\n * ```\n *\n * @sealed\n * @public\n */\nexport class MathematicsAssertionError extends Error {\n /**\n * The actual value that failed the assertion.\n *\n * @remarks\n * The runtime type reflects what was actually passed to the assertion function:\n * - `bigint` for integer assertions (`assertU8`, `assertU256`, etc.)\n * - `Uint8Array` for byte-array assertions (`assertU256LeBytes`, `assertU32LeBytes`, etc.)\n * - Any other type when a non-numeric value was passed unexpectedly\n *\n * @readonly\n */\n public readonly value: unknown;\n\n /**\n * The type that was expected.\n *\n * @remarks\n * Contains the branded type name exactly as it appears in the SDK type system,\n * e.g., `\"U8\"`, `\"U256\"`, `\"U32LeBytes\"`. Use this for structured logging or\n * to build user-facing error messages without parsing the `message` string.\n *\n * @readonly\n */\n public readonly expectedType: string;\n\n /**\n * Description of the constraint that was violated.\n *\n * @remarks\n * Is `undefined` when only a type check failed (e.g., a `string` was passed where a\n * `bigint` was expected). Contains a human-readable inequality or length rule when a\n * value of the correct type was out of the allowed range.\n *\n * @example\n * - `\"0 <= value <= 255\"` — U8 range violation\n * - `\"length === 32\"` — U256LeBytes length violation\n * - `\"value >= 0\"` — negative value passed to an unsigned integer assertion\n *\n * @readonly\n */\n public readonly constraint: string | undefined;\n\n /**\n * Creates a new MathematicsAssertionError.\n *\n * @param message - Human-readable description of the assertion failure. Should name\n * the assertion function, the expected type, and the constraint that was violated.\n * @param options - Structured diagnostic details attached to the error.\n * @param options.value - The actual value that was supplied and failed the assertion.\n * @param options.expectedType - The name of the branded type that was expected\n * (e.g., `\"U8\"`, `\"U256LeBytes\"`).\n * @param options.constraint - Optional human-readable constraint description\n * (e.g., `\"0 <= value <= 255\"`). Omit when the failure is a type mismatch rather\n * than a range violation.\n */\n constructor(\n message: string,\n options: {\n value: unknown;\n expectedType: string;\n constraint?: string;\n },\n ) {\n super(message);\n this.name = \"MathematicsAssertionError\";\n this.value = options.value;\n this.expectedType = options.expectedType;\n this.constraint = options.constraint;\n\n // Maintains proper stack trace for where our error was thrown (V8 only)\n Error.captureStackTrace(this, MathematicsAssertionError);\n\n // Set the prototype explicitly for proper instanceof checks\n Object.setPrototypeOf(this, MathematicsAssertionError.prototype);\n }\n}\n\n/* =============================================================================\n * CRYPTOGRAPHY ASSERTION ERROR\n *\n * Error thrown when cryptographic type assertions fail.\n * ============================================================================= */\n\n/**\n * Error thrown when a value fails a cryptographic type assertion.\n *\n * This error provides detailed information about why an assertion failed,\n * including the actual value, the expected type, and the constraint that\n * was violated.\n *\n * @remarks\n * Thrown by assertion functions in the cryptography module, such as\n * `assertBn254FieldElement`, `assertAesKey`, `assertX25519PrivateKey`, and similar.\n * Each function validates that a value conforms to a branded cryptographic type,\n * throwing this error with a precise `expectedType` and `constraint` when it does not.\n *\n * Common reasons for failure:\n * - A `bigint` field element exceeds the BN254 or Curve25519 field prime\n * - A byte array has the wrong length (e.g., a 31-byte array passed as an AES-256 key)\n * - A wrong JavaScript type was supplied (e.g., a `number` instead of a `bigint`)\n *\n * @example\n * ```typescript\n * import { assertBn254FieldElement, CryptographyAssertionError } from \"./cryptography\";\n *\n * try {\n * assertBn254FieldElement(invalidValue); // Will throw\n * } catch (error) {\n * if (error instanceof CryptographyAssertionError) {\n * console.error(`Assertion failed for ${error.expectedType}`);\n * console.error(`Value: ${error.value}`);\n * console.error(`Constraint: ${error.constraint}`);\n * }\n * }\n * ```\n *\n * @example\n * ```typescript\n * // Distinguish cryptographic assertion failures from mathematical ones\n * try {\n * const key = assertAesKey(rawBytes);\n * } catch (error) {\n * if (error instanceof CryptographyAssertionError) {\n * console.warn(\"Crypto assertion failed:\", error.expectedType, error.constraint);\n * } else if (error instanceof MathematicsAssertionError) {\n * console.warn(\"Math assertion failed:\", error.expectedType, error.constraint);\n * }\n * }\n * ```\n *\n * @see {@link MathematicsAssertionError}\n * @see {@link SolanaAssertionError}\n * @see {@link TemporalAssertionError}\n * @sealed\n * @public\n */\nexport class CryptographyAssertionError extends Error {\n /**\n * The actual value that failed the assertion.\n *\n * @remarks\n * The runtime type reflects what was actually passed to the assertion function:\n * - `bigint` for field element assertions (`assertBn254FieldElement`, etc.)\n * - `Uint8Array` for byte-array assertions (`assertAesKey`, `assertX25519PrivateKey`, etc.)\n * - Any other type when an entirely wrong value type was supplied\n *\n * @readonly\n */\n public readonly value: unknown;\n\n /**\n * The type that was expected (e.g., `\"Bn254FieldElement\"`, `\"PoseidonKey\"`, `\"AesKey\"`).\n *\n * @remarks\n * Contains the branded type name exactly as it appears in the SDK type system.\n * Use this property for structured logging without parsing the `message` string.\n *\n * @readonly\n */\n public readonly expectedType: string;\n\n /**\n * Description of the constraint that was violated.\n *\n * @remarks\n * Is `undefined` for pure type-mismatch failures (e.g., `string` instead of `bigint`).\n * Contains a human-readable constraint description for range and length violations\n * (e.g., `\"value < BN254_FIELD_PRIME\"`, `\"length === 32\"`).\n *\n * @readonly\n */\n public readonly constraint: string | undefined;\n\n /**\n * Creates a new CryptographyAssertionError.\n *\n * @param message - Human-readable description of the assertion failure. Should name\n * the assertion function, the expected type, and the constraint that was violated.\n * @param options - Structured diagnostic details attached to the error.\n * @param options.value - The actual value that was supplied and failed the assertion.\n * @param options.expectedType - The name of the branded cryptographic type that was\n * expected (e.g., `\"Bn254FieldElement\"`, `\"AesKey\"`).\n * @param options.constraint - Optional human-readable constraint description.\n * Omit when the failure is a type mismatch rather than a range or length violation.\n */\n constructor(\n message: string,\n options: {\n value: unknown;\n expectedType: string;\n constraint?: string;\n },\n ) {\n super(message);\n this.name = \"CryptographyAssertionError\";\n this.value = options.value;\n this.expectedType = options.expectedType;\n this.constraint = options.constraint;\n\n Error.captureStackTrace(this, CryptographyAssertionError);\n\n Object.setPrototypeOf(this, CryptographyAssertionError.prototype);\n }\n}\n\n/* =============================================================================\n * SOLANA ASSERTION ERROR\n *\n * Error thrown when Solana type assertions fail.\n * ============================================================================= */\n\n/**\n * Error thrown when a Solana type assertion fails.\n *\n * This error provides detailed information about why the assertion failed,\n * including the actual value, expected type, and constraint that was violated.\n *\n * @remarks\n * Thrown by assertion functions for Solana-specific branded types, such as\n * `assertTransactionSignature`, `assertSignatureBytes`, and similar validators.\n * These assertions verify that string or byte-array values conform to Solana's\n * encoding and length conventions (e.g., Base58-encoded 64-byte Ed25519 signatures).\n *\n * Common reasons for failure:\n * - A string that fails Base58 decoding or has the wrong decoded length\n * - A `Uint8Array` with the wrong byte length for a signature or public key\n * - A wrong JavaScript type (e.g., `number` instead of `string`)\n *\n * @example\n * ```typescript\n * import { assertTransactionSignature, SolanaAssertionError } from \"./solana\";\n *\n * try {\n * assertTransactionSignature(\"invalid!signature\"); // Will throw\n * } catch (error) {\n * if (error instanceof SolanaAssertionError) {\n * console.error(`Assertion failed for ${error.expectedType}`);\n * console.error(`Value: ${error.value}`);\n * console.error(`Constraint: ${error.constraint}`);\n * }\n * }\n * ```\n *\n * @example\n * ```typescript\n * // Safe parse pattern — returns null on failure\n * function tryParseSignature(raw: unknown): TransactionSignature | null {\n * try {\n * return assertTransactionSignature(raw);\n * } catch (error) {\n * if (error instanceof SolanaAssertionError) return null;\n * throw error;\n * }\n * }\n * ```\n *\n * @see {@link MathematicsAssertionError}\n * @see {@link CryptographyAssertionError}\n * @see {@link TemporalAssertionError}\n * @sealed\n * @public\n */\nexport class SolanaAssertionError extends Error {\n /**\n * The actual value that failed the assertion.\n *\n * @remarks\n * The runtime type reflects what was actually passed to the assertion function:\n * - `string` for Base58-encoded assertions (`assertTransactionSignature`, etc.)\n * - `Uint8Array` for byte-array assertions (`assertSignatureBytes`, etc.)\n * - Any other type when a completely wrong value type was supplied\n *\n * @readonly\n */\n public readonly value: unknown;\n\n /**\n * The type that was expected (e.g., `\"TransactionSignature\"`, `\"SignatureBytes\"`).\n *\n * @remarks\n * Contains the branded type name exactly as it appears in the SDK type system.\n * Use this for structured logging without parsing the `message` string.\n *\n * @readonly\n */\n public readonly expectedType: string;\n\n /**\n * Description of the constraint that was violated.\n *\n * @remarks\n * Is `undefined` for pure type-mismatch failures. Contains a human-readable rule\n * for encoding or length violations (e.g., `\"valid Base58\"`, `\"length === 64\"`).\n *\n * @readonly\n */\n public readonly constraint: string | undefined;\n\n /**\n * Creates a new SolanaAssertionError.\n *\n * @param message - Human-readable description of the assertion failure. Should name\n * the assertion function, the expected type, and the constraint that was violated.\n * @param options - Structured diagnostic details attached to the error.\n * @param options.value - The actual value that was supplied and failed the assertion.\n * @param options.expectedType - The name of the branded Solana type that was expected\n * (e.g., `\"TransactionSignature\"`, `\"SignatureBytes\"`).\n * @param options.constraint - Optional human-readable constraint description.\n * Omit when the failure is a type mismatch rather than an encoding or length violation.\n */\n constructor(\n message: string,\n options: {\n value: unknown;\n expectedType: string;\n constraint?: string;\n },\n ) {\n super(message);\n this.name = \"SolanaAssertionError\";\n this.value = options.value;\n this.expectedType = options.expectedType;\n this.constraint = options.constraint;\n\n Error.captureStackTrace(this, SolanaAssertionError);\n\n Object.setPrototypeOf(this, SolanaAssertionError.prototype);\n }\n}\n\n/* =============================================================================\n * TEMPORAL ASSERTION ERROR\n *\n * Error thrown when temporal type assertions fail.\n * ============================================================================= */\n\n/**\n * Error thrown when a temporal type assertion fails.\n *\n * This error provides detailed information about why an assertion failed,\n * including the actual value, the expected type, and the constraint that\n * was violated.\n *\n * @remarks\n * Thrown by assertion functions for branded temporal types: `assertYear`, `assertMonth`,\n * `assertDay`, `assertHour`, `assertMinute`, and `assertSecond`. These functions validate\n * that a `bigint` value falls within the calendar range appropriate for each component\n * (e.g., months must be in `[1, 12]`, hours in `[0, 23]`).\n *\n * Temporal assertions are used to validate the output of UTC timestamp extraction before\n * the components are used in time-scoped viewing key derivation. In normal operation they\n * should never throw (JavaScript's `Date` always produces in-range values), but callers\n * that construct components manually can encounter these errors.\n *\n * @example\n * ```typescript\n * import { assertMonth, TemporalAssertionError } from \"./temporal\";\n *\n * try {\n * assertMonth(13n); // Will throw — month must be 1–12\n * } catch (error) {\n * if (error instanceof TemporalAssertionError) {\n * console.error(`Assertion failed for ${error.expectedType}`);\n * console.error(`Value: ${error.value}`);\n * console.error(`Constraint: ${error.constraint}`);\n * // Output:\n * // Assertion failed for Month\n * // Value: 13\n * // Constraint: 1 <= value <= 12\n * }\n * }\n * ```\n *\n * @example\n * ```typescript\n * // Safe parse of a user-supplied year value\n * function tryParseYear(raw: bigint): Year | null {\n * try {\n * return assertYear(raw);\n * } catch (error) {\n * if (error instanceof TemporalAssertionError) return null;\n * throw error;\n * }\n * }\n * ```\n *\n * @see {@link MathematicsAssertionError}\n * @see {@link CryptographyAssertionError}\n * @see {@link SolanaAssertionError}\n * @sealed\n * @public\n */\nexport class TemporalAssertionError extends Error {\n /**\n * The actual value that failed the assertion.\n *\n * @remarks\n * Will be a `bigint` for all temporal assertions since the temporal types are\n * BigInt-backed branded types (e.g., `Year`, `Month`, `Day`). May also be any\n * other type when a non-bigint value was supplied unexpectedly.\n *\n * @readonly\n */\n public readonly value: unknown;\n\n /**\n * The type that was expected (e.g., `\"Year\"`, `\"Month\"`, `\"Hour\"`).\n *\n * @remarks\n * Contains the branded temporal type name exactly as it appears in the SDK type system.\n * Use this for structured logging without parsing the `message` string.\n *\n * @readonly\n */\n public readonly expectedType: string;\n\n /**\n * Description of the constraint that was violated.\n *\n * @remarks\n * Contains a human-readable range rule for out-of-range values\n * (e.g., `\"1 <= value <= 12\"` for a month violation). Is `undefined` only for\n * pure type-mismatch failures (e.g., a `string` passed where a `bigint` was expected),\n * which should not occur in normal usage.\n *\n * @readonly\n */\n public readonly constraint: string | undefined;\n\n /**\n * Creates a new TemporalAssertionError.\n *\n * @param message - Human-readable description of the assertion failure. Should name\n * the assertion function, the expected type, and the violated range constraint.\n * @param details - Structured diagnostic details attached to the error.\n * @param details.value - The actual `bigint` value (or other type) that was supplied\n * and failed the temporal assertion.\n * @param details.expectedType - The name of the branded temporal type that was expected\n * (e.g., `\"Year\"`, `\"Month\"`, `\"Hour\"`).\n * @param details.constraint - Optional human-readable range description\n * (e.g., `\"1 <= value <= 12\"`). Omit when the failure is a type mismatch.\n */\n constructor(\n message: string,\n details: {\n value: unknown;\n expectedType: string;\n constraint?: string;\n },\n ) {\n super(message);\n this.name = \"TemporalAssertionError\";\n this.value = details.value;\n this.expectedType = details.expectedType;\n this.constraint = details.constraint;\n }\n}\n"]}
|