@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,103 @@
|
|
|
1
|
+
import { __name } from './chunk-7QVYU63E.js';
|
|
2
|
+
|
|
3
|
+
// src/common/converters/miscellaneous.ts
|
|
4
|
+
async function sleep(ms) {
|
|
5
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
6
|
+
}
|
|
7
|
+
__name(sleep, "sleep");
|
|
8
|
+
function base64ToUint8Array(base64) {
|
|
9
|
+
if (typeof Buffer !== "undefined") {
|
|
10
|
+
return new Uint8Array(Buffer.from(base64, "base64"));
|
|
11
|
+
}
|
|
12
|
+
return Uint8Array.from(atob(base64), (c) => c.codePointAt(0) ?? 0);
|
|
13
|
+
}
|
|
14
|
+
__name(base64ToUint8Array, "base64ToUint8Array");
|
|
15
|
+
function uint8ArrayToBase64(bytes) {
|
|
16
|
+
if (typeof Buffer !== "undefined") {
|
|
17
|
+
return Buffer.from(bytes).toString("base64");
|
|
18
|
+
}
|
|
19
|
+
return btoa(String.fromCodePoint(...bytes));
|
|
20
|
+
}
|
|
21
|
+
__name(uint8ArrayToBase64, "uint8ArrayToBase64");
|
|
22
|
+
function hexToBytes(hex) {
|
|
23
|
+
const cleaned = hex.startsWith("0x") || hex.startsWith("0X") ? hex.slice(2) : hex;
|
|
24
|
+
if (cleaned.length % 2 !== 0) {
|
|
25
|
+
throw new Error(`hexToBytes: hex string must have even length, got ${String(cleaned.length)}`);
|
|
26
|
+
}
|
|
27
|
+
const bytes = new Uint8Array(cleaned.length / 2);
|
|
28
|
+
for (let i = 0; i < cleaned.length; i += 2) {
|
|
29
|
+
const byte = parseInt(cleaned.substring(i, i + 2), 16);
|
|
30
|
+
if (Number.isNaN(byte)) {
|
|
31
|
+
throw new Error(`hexToBytes: invalid hex character at position ${String(i)}`);
|
|
32
|
+
}
|
|
33
|
+
bytes[i / 2] = byte;
|
|
34
|
+
}
|
|
35
|
+
return bytes;
|
|
36
|
+
}
|
|
37
|
+
__name(hexToBytes, "hexToBytes");
|
|
38
|
+
function bytesToHex(bytes) {
|
|
39
|
+
let hex = "";
|
|
40
|
+
for (const byte of bytes) {
|
|
41
|
+
hex += byte.toString(16).padStart(2, "0");
|
|
42
|
+
}
|
|
43
|
+
return hex;
|
|
44
|
+
}
|
|
45
|
+
__name(bytesToHex, "bytesToHex");
|
|
46
|
+
function encodeBigintToLeBytes(value, byteLength) {
|
|
47
|
+
if (value < 0n) {
|
|
48
|
+
throw new RangeError(`encodeBigintToLeBytes: value must be non-negative, got ${String(value)}`);
|
|
49
|
+
}
|
|
50
|
+
const maxValue = (1n << BigInt(byteLength * 8)) - 1n;
|
|
51
|
+
if (value > maxValue) {
|
|
52
|
+
throw new RangeError(
|
|
53
|
+
`encodeBigintToLeBytes: value ${String(value)} does not fit in ${String(byteLength)} bytes`
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
const bytes = new Uint8Array(byteLength);
|
|
57
|
+
let remaining = value;
|
|
58
|
+
for (let i = 0; i < byteLength; i++) {
|
|
59
|
+
bytes[i] = Number(remaining & 0xffn);
|
|
60
|
+
remaining >>= 8n;
|
|
61
|
+
}
|
|
62
|
+
return bytes;
|
|
63
|
+
}
|
|
64
|
+
__name(encodeBigintToLeBytes, "encodeBigintToLeBytes");
|
|
65
|
+
function encodeBigintToBeBytes(value, byteLength) {
|
|
66
|
+
if (value < 0n) {
|
|
67
|
+
throw new RangeError(`encodeBigintToBeBytes: value must be non-negative, got ${String(value)}`);
|
|
68
|
+
}
|
|
69
|
+
const maxValue = (1n << BigInt(byteLength * 8)) - 1n;
|
|
70
|
+
if (value > maxValue) {
|
|
71
|
+
throw new RangeError(
|
|
72
|
+
`encodeBigintToBeBytes: value ${String(value)} does not fit in ${String(byteLength)} bytes`
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
const bytes = new Uint8Array(byteLength);
|
|
76
|
+
let remaining = value;
|
|
77
|
+
for (let i = byteLength - 1; i >= 0; i--) {
|
|
78
|
+
bytes[i] = Number(remaining & 0xffn);
|
|
79
|
+
remaining >>= 8n;
|
|
80
|
+
}
|
|
81
|
+
return bytes;
|
|
82
|
+
}
|
|
83
|
+
__name(encodeBigintToBeBytes, "encodeBigintToBeBytes");
|
|
84
|
+
function decodeLeBytesToBigint(bytes) {
|
|
85
|
+
let value = 0n;
|
|
86
|
+
for (let i = bytes.length - 1; i >= 0; i--) {
|
|
87
|
+
value = value << 8n | BigInt(bytes[i]);
|
|
88
|
+
}
|
|
89
|
+
return value;
|
|
90
|
+
}
|
|
91
|
+
__name(decodeLeBytesToBigint, "decodeLeBytesToBigint");
|
|
92
|
+
function decodeBeBytesToBigint(bytes) {
|
|
93
|
+
let value = 0n;
|
|
94
|
+
for (const byte of bytes) {
|
|
95
|
+
value = value << 8n | BigInt(byte);
|
|
96
|
+
}
|
|
97
|
+
return value;
|
|
98
|
+
}
|
|
99
|
+
__name(decodeBeBytesToBigint, "decodeBeBytesToBigint");
|
|
100
|
+
|
|
101
|
+
export { base64ToUint8Array, bytesToHex, decodeBeBytesToBigint, decodeLeBytesToBigint, encodeBigintToBeBytes, encodeBigintToLeBytes, hexToBytes, sleep, uint8ArrayToBase64 };
|
|
102
|
+
//# sourceMappingURL=chunk-TLR7A64G.js.map
|
|
103
|
+
//# sourceMappingURL=chunk-TLR7A64G.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/common/converters/miscellaneous.ts"],"names":[],"mappings":";;;AAkEA,eAAsB,MAAM,EAAA,EAA2B;AACrD,EAAA,OAAO,IAAI,OAAA,CAAQ,CAAC,YAAY,UAAA,CAAW,OAAA,EAAS,EAAE,CAAC,CAAA;AACzD;AAFsB,MAAA,CAAA,KAAA,EAAA,OAAA,CAAA;AA2Bf,SAAS,mBAAmB,MAAA,EAA4B;AAC7D,EAAA,IAAI,OAAO,WAAW,WAAA,EAAa;AACjC,IAAA,OAAO,IAAI,UAAA,CAAW,MAAA,CAAO,IAAA,CAAK,MAAA,EAAQ,QAAQ,CAAC,CAAA;AAAA,EACrD;AACA,EAAA,OAAO,UAAA,CAAW,IAAA,CAAK,IAAA,CAAK,MAAM,CAAA,EAAG,CAAC,CAA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AAO,KAAA;AACT;AANgB,MAAA,CAAA,qBAAA,EAAA,uBAAA,CAAA;AAsBT,SAAS,sBAAsB,KAAA,EAA2B;AAC/D,EAAA,IAAI,KAAA,GAAQ,EAAA;AACZ,EAAA,KAAA,MAAW,QAAQ,KAAA,EAAO;AACxB,IAAA,KAAA,GAAS,KAAA,IAAS,EAAA,GAAM,MAAA,CAAO,IAAI,CAAA;AAAA,EACrC;AACA,EAAA,OAAO,KAAA;AACT;AANgB,MAAA,CAAA,qBAAA,EAAA,uBAAA,CAAA","file":"chunk-TLR7A64G.js","sourcesContent":["/**\n * Miscellaneous Utility Converters\n *\n * Provides general-purpose conversion and utility functions used across\n * multiple SDK modules. These are intentionally co-located in the converters\n * module to avoid duplication.\n *\n * @module common/converters/miscellaneous\n * @since 2.0.0\n */\n\n// =============================================================================\n// TYPE UTILITIES\n// =============================================================================\n\n/**\n * Utility type that removes `readonly` modifiers from all properties of a type.\n *\n * This is useful when you need to create a mutable version of an immutable type,\n * such as when building objects incrementally before freezing them.\n *\n * @typeParam T - The type to make writable\n *\n * @remarks\n * The `-readonly` modifier removes the `readonly` attribute from each property,\n * effectively making all properties mutable.\n *\n * @example\n * ```typescript\n * interface ReadonlyUser {\n * readonly id: string;\n * readonly name: string;\n * }\n *\n * // MutableUser has { id: string; name: string } (no readonly)\n * type MutableUser = Writable<ReadonlyUser>;\n *\n * const user: MutableUser = { id: \"1\", name: \"Alice\" };\n * user.name = \"Bob\"; // OK - property is now writable\n * ```\n *\n * @since 2.0.0\n * @public\n */\nexport type Writable<T> = {\n -readonly [P in keyof T]: T[P];\n};\n\n// =============================================================================\n// ASYNC UTILITIES\n// =============================================================================\n\n/**\n * Pauses execution for the specified number of milliseconds.\n *\n * @param ms - Duration to sleep in milliseconds. Must be a non-negative integer.\n * @returns A `Promise<void>` that resolves after `ms` milliseconds.\n *\n * @example\n * ```typescript\n * await sleep(2000); // Wait 2 seconds\n * ```\n *\n * @since 2.0.0\n * @public\n */\nexport async function sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\n// =============================================================================\n// ENCODING UTILITIES\n// =============================================================================\n\n/**\n * Decodes a base64-encoded string into a `Uint8Array`.\n *\n * Works in both browser (using `atob`) and Node.js (using `Buffer`) environments,\n * selecting the appropriate decoding strategy at runtime.\n *\n * @param base64 - The base64-encoded string to decode.\n * @returns The decoded bytes as a `Uint8Array`.\n *\n * @throws {Error} If the input is not valid base64.\n *\n * @example\n * ```typescript\n * const bytes = base64ToUint8Array(\"SGVsbG8=\"); // Uint8Array([72, 101, 108, 108, 111])\n * ```\n *\n * @since 2.0.0\n * @public\n */\nexport function base64ToUint8Array(base64: string): Uint8Array {\n if (typeof Buffer !== \"undefined\") {\n return new Uint8Array(Buffer.from(base64, \"base64\"));\n }\n return Uint8Array.from(atob(base64), (c) => c.codePointAt(0) ?? 0);\n}\n\n/**\n * Encodes a `Uint8Array` into a base64 string.\n *\n * Works in both browser (using `btoa`) and Node.js (using `Buffer`) environments.\n *\n * @param bytes - The byte array to encode.\n * @returns The base64-encoded string.\n *\n * @example\n * ```typescript\n * const b64 = uint8ArrayToBase64(new Uint8Array([72, 101, 108, 108, 111])); // \"SGVsbG8=\"\n * ```\n *\n * @since 2.0.0\n * @public\n */\nexport function uint8ArrayToBase64(bytes: Uint8Array): string {\n if (typeof Buffer !== \"undefined\") {\n return Buffer.from(bytes).toString(\"base64\");\n }\n return btoa(String.fromCodePoint(...bytes));\n}\n\n// =============================================================================\n// HEX ENCODING\n// =============================================================================\n\n/**\n * Decodes a hex string into a `Uint8Array`.\n *\n * @remarks\n * Accepts hex strings with or without a `0x` prefix. The input must have an\n * even number of hex characters (each byte is two hex digits).\n *\n * @param hex - The hex-encoded string to decode (e.g. `\"48656c6c6f\"` or `\"0x48656c6c6f\"`).\n * @returns The decoded bytes as a `Uint8Array`.\n *\n * @throws {Error} If the input contains non-hex characters or has odd length.\n *\n * @example\n * ```typescript\n * const bytes = hexToBytes(\"48656c6c6f\"); // Uint8Array([72, 101, 108, 108, 111])\n * const bytes2 = hexToBytes(\"0x48656c6c6f\"); // same result\n * ```\n *\n * @since 2.0.0\n * @public\n */\nexport function hexToBytes(hex: string): Uint8Array {\n const cleaned = hex.startsWith(\"0x\") || hex.startsWith(\"0X\") ? hex.slice(2) : hex;\n if (cleaned.length % 2 !== 0) {\n throw new Error(`hexToBytes: hex string must have even length, got ${String(cleaned.length)}`);\n }\n const bytes = new Uint8Array(cleaned.length / 2);\n for (let i = 0; i < cleaned.length; i += 2) {\n const byte = parseInt(cleaned.substring(i, i + 2), 16);\n if (Number.isNaN(byte)) {\n throw new Error(`hexToBytes: invalid hex character at position ${String(i)}`);\n }\n bytes[i / 2] = byte;\n }\n return bytes;\n}\n\n/**\n * Encodes a `Uint8Array` into a lowercase hex string (without `0x` prefix).\n *\n * @param bytes - The byte array to encode.\n * @returns The hex-encoded string (lowercase, no prefix).\n *\n * @example\n * ```typescript\n * const hex = bytesToHex(new Uint8Array([72, 101, 108, 108, 111])); // \"48656c6c6f\"\n * ```\n *\n * @since 2.0.0\n * @public\n */\nexport function bytesToHex(bytes: Uint8Array): string {\n let hex = \"\";\n for (const byte of bytes) {\n hex += byte.toString(16).padStart(2, \"0\");\n }\n return hex;\n}\n\n// =============================================================================\n// GENERIC BIGINT ↔ BYTES\n// =============================================================================\n\n/**\n * Encodes a non-negative bigint into a little-endian byte array of the specified length.\n *\n * @param value - The non-negative bigint to encode.\n * @param byteLength - The number of output bytes. The value must fit within this many bytes.\n * @returns A `Uint8Array` of exactly `byteLength` bytes in little-endian order.\n *\n * @throws {RangeError} If `value` is negative or doesn't fit in `byteLength` bytes.\n *\n * @example\n * ```typescript\n * const bytes = encodeBigintToLeBytes(256n, 4); // Uint8Array([0, 1, 0, 0])\n * ```\n *\n * @since 2.0.0\n * @public\n */\nexport function encodeBigintToLeBytes(value: bigint, byteLength: number): Uint8Array {\n if (value < 0n) {\n throw new RangeError(`encodeBigintToLeBytes: value must be non-negative, got ${String(value)}`);\n }\n const maxValue = (1n << BigInt(byteLength * 8)) - 1n;\n if (value > maxValue) {\n throw new RangeError(\n `encodeBigintToLeBytes: value ${String(value)} does not fit in ${String(byteLength)} bytes`,\n );\n }\n const bytes = new Uint8Array(byteLength);\n let remaining = value;\n for (let i = 0; i < byteLength; i++) {\n bytes[i] = Number(remaining & 0xffn);\n remaining >>= 8n;\n }\n return bytes;\n}\n\n/**\n * Encodes a non-negative bigint into a big-endian byte array of the specified length.\n *\n * @param value - The non-negative bigint to encode.\n * @param byteLength - The number of output bytes. The value must fit within this many bytes.\n * @returns A `Uint8Array` of exactly `byteLength` bytes in big-endian order.\n *\n * @throws {RangeError} If `value` is negative or doesn't fit in `byteLength` bytes.\n *\n * @example\n * ```typescript\n * const bytes = encodeBigintToBeBytes(256n, 4); // Uint8Array([0, 0, 1, 0])\n * ```\n *\n * @since 2.0.0\n * @public\n */\nexport function encodeBigintToBeBytes(value: bigint, byteLength: number): Uint8Array {\n if (value < 0n) {\n throw new RangeError(`encodeBigintToBeBytes: value must be non-negative, got ${String(value)}`);\n }\n const maxValue = (1n << BigInt(byteLength * 8)) - 1n;\n if (value > maxValue) {\n throw new RangeError(\n `encodeBigintToBeBytes: value ${String(value)} does not fit in ${String(byteLength)} bytes`,\n );\n }\n const bytes = new Uint8Array(byteLength);\n let remaining = value;\n for (let i = byteLength - 1; i >= 0; i--) {\n bytes[i] = Number(remaining & 0xffn);\n remaining >>= 8n;\n }\n return bytes;\n}\n\n/**\n * Decodes a little-endian `Uint8Array` into a non-negative bigint.\n *\n * @param bytes - The little-endian byte array to decode.\n * @returns The decoded bigint value.\n *\n * @example\n * ```typescript\n * const value = decodeLeBytesToBigint(new Uint8Array([0, 1, 0, 0])); // 256n\n * ```\n *\n * @since 2.0.0\n * @public\n */\nexport function decodeLeBytesToBigint(bytes: Uint8Array): bigint {\n let value = 0n;\n for (let i = bytes.length - 1; i >= 0; i--) {\n value = (value << 8n) | BigInt(bytes[i]);\n }\n return value;\n}\n\n/**\n * Decodes a big-endian `Uint8Array` into a non-negative bigint.\n *\n * @param bytes - The big-endian byte array to decode.\n * @returns The decoded bigint value.\n *\n * @example\n * ```typescript\n * const value = decodeBeBytesToBigint(new Uint8Array([0, 0, 1, 0])); // 256n\n * ```\n *\n * @since 2.0.0\n * @public\n */\nexport function decodeBeBytesToBigint(bytes: Uint8Array): bigint {\n let value = 0n;\n for (const byte of bytes) {\n value = (value << 8n) | BigInt(byte);\n }\n return value;\n}\n"]}
|
|
@@ -16,5 +16,5 @@ exports.ARCIUM_EXEC_POOL_SEED = ARCIUM_EXEC_POOL_SEED;
|
|
|
16
16
|
exports.ARCIUM_MEMPOOL_SEED = ARCIUM_MEMPOOL_SEED;
|
|
17
17
|
exports.ARCIUM_MXE_ACCOUNT_SEED = ARCIUM_MXE_ACCOUNT_SEED;
|
|
18
18
|
exports.ARCIUM_OFFSET_BUFFER_SIZE = ARCIUM_OFFSET_BUFFER_SIZE;
|
|
19
|
-
//# sourceMappingURL=chunk-
|
|
20
|
-
//# sourceMappingURL=chunk-
|
|
19
|
+
//# sourceMappingURL=chunk-TQQZGNOI.cjs.map
|
|
20
|
+
//# sourceMappingURL=chunk-TQQZGNOI.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/constants/arcium.ts"],"names":[],"mappings":";;;AAgBO,IAAM,uBAAA,GAA0B;AAQhC,IAAM,mBAAA,GAAsB;AAQ5B,IAAM,qBAAA,GAAwB;AAQ9B,IAAM,uBAAA,GAA0B;AAQhC,IAAM,oBAAA,GAAuB;AAQ7B,IAAM,mBAAA,GAAsB;AAQ5B,IAAM,yBAAA,GAA4B","file":"chunk-TQQZGNOI.cjs","sourcesContent":["/**\n * Arcium Protocol Constants\n *\n * This module contains constants for interacting with the Arcium protocol,\n * including the program address and PDA seed prefixes for various account types.\n *\n * @since 2.0.0\n * @module constants/arcium\n */\n\n/**\n * Seed prefix for MXE account PDAs.\n *\n * @remarks\n * Used to derive the MXE account address for a given program.\n */\nexport const ARCIUM_MXE_ACCOUNT_SEED = \"MXEAccount\";\n\n/**\n * Seed prefix for mempool account PDAs.\n *\n * @remarks\n * The mempool stores pending computations for a cluster.\n */\nexport const ARCIUM_MEMPOOL_SEED = \"Mempool\";\n\n/**\n * Seed prefix for executing pool account PDAs.\n *\n * @remarks\n * The executing pool tracks computations currently being processed.\n */\nexport const ARCIUM_EXEC_POOL_SEED = \"Execpool\";\n\n/**\n * Seed prefix for computation account PDAs.\n *\n * @remarks\n * Each computation gets its own account to track state and results.\n */\nexport const ARCIUM_COMPUTATION_SEED = \"ComputationAccount\";\n\n/**\n * Seed prefix for computation definition account PDAs.\n *\n * @remarks\n * Computation definitions describe the circuit/program to be executed.\n */\nexport const ARCIUM_COMP_DEF_SEED = \"ComputationDefinitionAccount\";\n\n/**\n * Seed prefix for cluster account PDAs.\n *\n * @remarks\n * Clusters are groups of MXE nodes that process computations together.\n */\nexport const ARCIUM_CLUSTER_SEED = \"Cluster\";\n\n/**\n * Buffer size for cluster/computation offsets in bytes.\n *\n * @remarks\n * Offsets are encoded as 4-byte little-endian unsigned integers.\n */\nexport const ARCIUM_OFFSET_BUFFER_SIZE = 4;\n"]}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { UmbraError } from './chunk-4TZVXB5G.js';
|
|
2
|
+
import { assertBytes, U8_BYTE_LENGTH, U16_BYTE_LENGTH, U32_BYTE_LENGTH, U64_BYTE_LENGTH, U128_BYTE_LENGTH, U256_BYTE_LENGTH, U512_BYTE_LENGTH, U1024_BYTE_LENGTH, assertX25519Bytes, assertX25519PublicKey, assertX25519PrivateKey, assertSharedSecret } from './chunk-CFTW5WNG.js';
|
|
3
|
+
import { __name } from './chunk-7QVYU63E.js';
|
|
4
|
+
|
|
5
|
+
// src/common/converters/errors.ts
|
|
6
|
+
var ConversionError = class extends UmbraError {
|
|
7
|
+
static {
|
|
8
|
+
__name(this, "ConversionError");
|
|
9
|
+
}
|
|
10
|
+
/** The original value that failed conversion. */
|
|
11
|
+
sourceValue;
|
|
12
|
+
/** The type name of the source value (e.g., `"bigint"`, `"number"`). */
|
|
13
|
+
sourceType;
|
|
14
|
+
/** The target branded type name (e.g., `"U8"`, `"Bn254FieldElement"`). */
|
|
15
|
+
targetType;
|
|
16
|
+
/**
|
|
17
|
+
* Human-readable explanation of why the conversion failed.
|
|
18
|
+
*
|
|
19
|
+
* @remarks
|
|
20
|
+
* Examples:
|
|
21
|
+
* - `"Value 300 exceeds U8 maximum of 255"`
|
|
22
|
+
* - `"Value exceeds BN254 field prime"`
|
|
23
|
+
* - `"Cannot convert negative value -1 to unsigned type"`
|
|
24
|
+
*/
|
|
25
|
+
reason;
|
|
26
|
+
/**
|
|
27
|
+
* @param message - A human-readable summary of the failure.
|
|
28
|
+
* @param options - Structured metadata about the failed conversion.
|
|
29
|
+
*/
|
|
30
|
+
constructor(message, options) {
|
|
31
|
+
super(message, {
|
|
32
|
+
code: `CONVERSION_${options.targetType.toUpperCase()}`
|
|
33
|
+
});
|
|
34
|
+
this.name = "ConversionError";
|
|
35
|
+
this.sourceValue = options.sourceValue;
|
|
36
|
+
this.sourceType = options.sourceType;
|
|
37
|
+
this.targetType = options.targetType;
|
|
38
|
+
this.reason = options.reason;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
function isConversionError(error) {
|
|
42
|
+
return error instanceof ConversionError;
|
|
43
|
+
}
|
|
44
|
+
__name(isConversionError, "isConversionError");
|
|
45
|
+
function assertBigintInRange(value, min, max, sourceType, targetType) {
|
|
46
|
+
if (value < min || value > max) {
|
|
47
|
+
throw new ConversionError(
|
|
48
|
+
`${sourceType} value ${String(value)} is out of range for ${targetType} [${String(min)}, ${String(max)}]`,
|
|
49
|
+
{
|
|
50
|
+
sourceValue: value,
|
|
51
|
+
sourceType,
|
|
52
|
+
targetType,
|
|
53
|
+
reason: `Value must be in range [${String(min)}, ${String(max)}]`
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
__name(assertBigintInRange, "assertBigintInRange");
|
|
59
|
+
function assertNumberInRange(value, min, max, targetType) {
|
|
60
|
+
if (!Number.isSafeInteger(value)) {
|
|
61
|
+
throw new ConversionError(
|
|
62
|
+
`Value ${String(value)} is not a safe integer`,
|
|
63
|
+
{
|
|
64
|
+
sourceValue: value,
|
|
65
|
+
sourceType: "number",
|
|
66
|
+
targetType,
|
|
67
|
+
reason: "Value must be a safe integer (Number.isSafeInteger)"
|
|
68
|
+
}
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
if (value < min || value > max) {
|
|
72
|
+
throw new ConversionError(
|
|
73
|
+
`number value ${String(value)} is out of range for ${targetType} [${String(min)}, ${String(max)}]`,
|
|
74
|
+
{
|
|
75
|
+
sourceValue: value,
|
|
76
|
+
sourceType: "number",
|
|
77
|
+
targetType,
|
|
78
|
+
reason: `Value must be in range [${String(min)}, ${String(max)}]`
|
|
79
|
+
}
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
__name(assertNumberInRange, "assertNumberInRange");
|
|
84
|
+
function assertByteLength(value, expectedLength, targetType) {
|
|
85
|
+
if (!(value instanceof Uint8Array)) {
|
|
86
|
+
throw new ConversionError(
|
|
87
|
+
`Expected Uint8Array, got ${typeof value}`,
|
|
88
|
+
{
|
|
89
|
+
sourceValue: value,
|
|
90
|
+
sourceType: typeof value,
|
|
91
|
+
targetType,
|
|
92
|
+
reason: "Input must be a Uint8Array"
|
|
93
|
+
}
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
if (value.length !== expectedLength) {
|
|
97
|
+
throw new ConversionError(
|
|
98
|
+
`Expected exactly ${String(expectedLength)} bytes, got ${String(value.length)}`,
|
|
99
|
+
{
|
|
100
|
+
sourceValue: value,
|
|
101
|
+
sourceType: "Uint8Array",
|
|
102
|
+
targetType,
|
|
103
|
+
reason: `Length must be exactly ${String(expectedLength)} bytes`
|
|
104
|
+
}
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
__name(assertByteLength, "assertByteLength");
|
|
109
|
+
|
|
110
|
+
// src/common/converters/branded.ts
|
|
111
|
+
function createBytes(value) {
|
|
112
|
+
assertBytes(value);
|
|
113
|
+
return value;
|
|
114
|
+
}
|
|
115
|
+
__name(createBytes, "createBytes");
|
|
116
|
+
function createU8LeBytes(value) {
|
|
117
|
+
assertByteLength(value, U8_BYTE_LENGTH, "U8LeBytes");
|
|
118
|
+
return value;
|
|
119
|
+
}
|
|
120
|
+
__name(createU8LeBytes, "createU8LeBytes");
|
|
121
|
+
function createU16LeBytes(value) {
|
|
122
|
+
assertByteLength(value, U16_BYTE_LENGTH, "U16LeBytes");
|
|
123
|
+
return value;
|
|
124
|
+
}
|
|
125
|
+
__name(createU16LeBytes, "createU16LeBytes");
|
|
126
|
+
function createU32LeBytes(value) {
|
|
127
|
+
assertByteLength(value, U32_BYTE_LENGTH, "U32LeBytes");
|
|
128
|
+
return value;
|
|
129
|
+
}
|
|
130
|
+
__name(createU32LeBytes, "createU32LeBytes");
|
|
131
|
+
function createU64LeBytes(value) {
|
|
132
|
+
assertByteLength(value, U64_BYTE_LENGTH, "U64LeBytes");
|
|
133
|
+
return value;
|
|
134
|
+
}
|
|
135
|
+
__name(createU64LeBytes, "createU64LeBytes");
|
|
136
|
+
function createU128LeBytes(value) {
|
|
137
|
+
assertByteLength(value, U128_BYTE_LENGTH, "U128LeBytes");
|
|
138
|
+
return value;
|
|
139
|
+
}
|
|
140
|
+
__name(createU128LeBytes, "createU128LeBytes");
|
|
141
|
+
function createU256LeBytes(value) {
|
|
142
|
+
assertByteLength(value, U256_BYTE_LENGTH, "U256LeBytes");
|
|
143
|
+
return value;
|
|
144
|
+
}
|
|
145
|
+
__name(createU256LeBytes, "createU256LeBytes");
|
|
146
|
+
function createU512LeBytes(value) {
|
|
147
|
+
assertByteLength(value, U512_BYTE_LENGTH, "U512LeBytes");
|
|
148
|
+
return value;
|
|
149
|
+
}
|
|
150
|
+
__name(createU512LeBytes, "createU512LeBytes");
|
|
151
|
+
function createU1024LeBytes(value) {
|
|
152
|
+
assertByteLength(value, U1024_BYTE_LENGTH, "U1024LeBytes");
|
|
153
|
+
return value;
|
|
154
|
+
}
|
|
155
|
+
__name(createU1024LeBytes, "createU1024LeBytes");
|
|
156
|
+
function createU8BeBytes(value) {
|
|
157
|
+
assertByteLength(value, U8_BYTE_LENGTH, "U8BeBytes");
|
|
158
|
+
return value;
|
|
159
|
+
}
|
|
160
|
+
__name(createU8BeBytes, "createU8BeBytes");
|
|
161
|
+
function createU16BeBytes(value) {
|
|
162
|
+
assertByteLength(value, U16_BYTE_LENGTH, "U16BeBytes");
|
|
163
|
+
return value;
|
|
164
|
+
}
|
|
165
|
+
__name(createU16BeBytes, "createU16BeBytes");
|
|
166
|
+
function createU32BeBytes(value) {
|
|
167
|
+
assertByteLength(value, U32_BYTE_LENGTH, "U32BeBytes");
|
|
168
|
+
return value;
|
|
169
|
+
}
|
|
170
|
+
__name(createU32BeBytes, "createU32BeBytes");
|
|
171
|
+
function createU64BeBytes(value) {
|
|
172
|
+
assertByteLength(value, U64_BYTE_LENGTH, "U64BeBytes");
|
|
173
|
+
return value;
|
|
174
|
+
}
|
|
175
|
+
__name(createU64BeBytes, "createU64BeBytes");
|
|
176
|
+
function createU128BeBytes(value) {
|
|
177
|
+
assertByteLength(value, U128_BYTE_LENGTH, "U128BeBytes");
|
|
178
|
+
return value;
|
|
179
|
+
}
|
|
180
|
+
__name(createU128BeBytes, "createU128BeBytes");
|
|
181
|
+
function createU256BeBytes(value) {
|
|
182
|
+
assertByteLength(value, U256_BYTE_LENGTH, "U256BeBytes");
|
|
183
|
+
return value;
|
|
184
|
+
}
|
|
185
|
+
__name(createU256BeBytes, "createU256BeBytes");
|
|
186
|
+
function createU512BeBytes(value) {
|
|
187
|
+
assertByteLength(value, U512_BYTE_LENGTH, "U512BeBytes");
|
|
188
|
+
return value;
|
|
189
|
+
}
|
|
190
|
+
__name(createU512BeBytes, "createU512BeBytes");
|
|
191
|
+
function createU1024BeBytes(value) {
|
|
192
|
+
assertByteLength(value, U1024_BYTE_LENGTH, "U1024BeBytes");
|
|
193
|
+
return value;
|
|
194
|
+
}
|
|
195
|
+
__name(createU1024BeBytes, "createU1024BeBytes");
|
|
196
|
+
function createX25519Bytes(value) {
|
|
197
|
+
assertX25519Bytes(value);
|
|
198
|
+
return value;
|
|
199
|
+
}
|
|
200
|
+
__name(createX25519Bytes, "createX25519Bytes");
|
|
201
|
+
function createX25519PublicKey(value) {
|
|
202
|
+
assertX25519PublicKey(value);
|
|
203
|
+
return value;
|
|
204
|
+
}
|
|
205
|
+
__name(createX25519PublicKey, "createX25519PublicKey");
|
|
206
|
+
function createX25519PrivateKey(value) {
|
|
207
|
+
assertX25519PrivateKey(value);
|
|
208
|
+
return value;
|
|
209
|
+
}
|
|
210
|
+
__name(createX25519PrivateKey, "createX25519PrivateKey");
|
|
211
|
+
function createSharedSecret(value) {
|
|
212
|
+
assertSharedSecret(value);
|
|
213
|
+
return value;
|
|
214
|
+
}
|
|
215
|
+
__name(createSharedSecret, "createSharedSecret");
|
|
216
|
+
|
|
217
|
+
export { ConversionError, assertBigintInRange, assertByteLength, assertNumberInRange, createBytes, createSharedSecret, createU1024BeBytes, createU1024LeBytes, createU128BeBytes, createU128LeBytes, createU16BeBytes, createU16LeBytes, createU256BeBytes, createU256LeBytes, createU32BeBytes, createU32LeBytes, createU512BeBytes, createU512LeBytes, createU64BeBytes, createU64LeBytes, createU8BeBytes, createU8LeBytes, createX25519Bytes, createX25519PrivateKey, createX25519PublicKey, isConversionError };
|
|
218
|
+
//# sourceMappingURL=chunk-UOFYS6M3.js.map
|
|
219
|
+
//# sourceMappingURL=chunk-UOFYS6M3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/common/converters/errors.ts","../src/common/converters/branded.ts"],"names":[],"mappings":";;;;;AA+CO,IAAM,eAAA,GAAN,cAA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AAA,qBAAA,CAAsB,KAAK,CAAA;AAC3B,EAAA,OAAO,KAAA;AACT;AAHgB,MAAA,CAAA,qBAAA,EAAA,uBAAA,CAAA;AAmBT,SAAS,uBAAuB,KAAA,EAAqC;AAC1E,EAAA,sBAAA,CAAuB,KAAK,CAAA;AAC5B,EAAA,OAAO,KAAA;AACT;AAHgB,MAAA,CAAA,sBAAA,EAAA,wBAAA,CAAA;AAmBT,SAAS,mBAAmB,KAAA,EAAiC;AAClE,EAAA,kBAAA,CAAmB,KAAK,CAAA;AACxB,EAAA,OAAO,KAAA;AACT;AAHgB,MAAA,CAAA,kBAAA,EAAA,oBAAA,CAAA","file":"chunk-UOFYS6M3.js","sourcesContent":["/**\n * Converter Error Classes\n *\n * Provides the {@link ConversionError} class thrown by all `convert*`, `create*`,\n * `encode*`, and `decode*` functions when a type transformation fails, along with\n * shared validation helpers used across all converter modules.\n *\n * @module common/converters/errors\n * @since 2.0.0\n */\n\nimport { UmbraError } from \"../errors\";\n\n/* =============================================================================\n * CONVERSION ERROR\n * ============================================================================= */\n\n/**\n * Error thrown when a type conversion fails.\n *\n * @remarks\n * Provides structured metadata about the failure: which value was being converted,\n * from which type, to which target type, and why it failed.\n *\n * ## When is this thrown?\n *\n * - **Narrowing conversions** (`convertU128ToU8`, etc.) — value exceeds target range.\n * - **Sign conversions** (`convertI64ToU64`, etc.) — negative to unsigned, or overflow.\n * - **Field element conversions** (`convertU256ToBn254FieldElement`, etc.) — value >= field prime.\n * - **Byte array constructors** (`createU128LeBytes`, etc.) — wrong length.\n * - **Number conversions** (`convertU64ToNumber`, etc.) — value exceeds `Number.MAX_SAFE_INTEGER`.\n *\n * @example\n * ```typescript\n * try {\n * const narrow = convertU128ToU8(createU128(300n));\n * } catch (error) {\n * if (error instanceof ConversionError) {\n * console.error(`Cannot convert ${error.sourceType} to ${error.targetType}`);\n * console.error(`Reason: ${error.reason}`);\n * }\n * }\n * ```\n *\n * @since 2.0.0\n * @public\n */\nexport class ConversionError extends UmbraError {\n /** The original value that failed conversion. */\n public readonly sourceValue: unknown;\n\n /** The type name of the source value (e.g., `\"bigint\"`, `\"number\"`). */\n public readonly sourceType: string;\n\n /** The target branded type name (e.g., `\"U8\"`, `\"Bn254FieldElement\"`). */\n public readonly targetType: string;\n\n /**\n * Human-readable explanation of why the conversion failed.\n *\n * @remarks\n * Examples:\n * - `\"Value 300 exceeds U8 maximum of 255\"`\n * - `\"Value exceeds BN254 field prime\"`\n * - `\"Cannot convert negative value -1 to unsigned type\"`\n */\n public readonly reason: string;\n\n /**\n * @param message - A human-readable summary of the failure.\n * @param options - Structured metadata about the failed conversion.\n */\n constructor(\n message: string,\n options: {\n sourceValue: unknown;\n sourceType: string;\n targetType: string;\n reason: string;\n },\n ) {\n super(message, {\n code: `CONVERSION_${options.targetType.toUpperCase()}`,\n });\n this.name = \"ConversionError\";\n this.sourceValue = options.sourceValue;\n this.sourceType = options.sourceType;\n this.targetType = options.targetType;\n this.reason = options.reason;\n }\n}\n\n/**\n * Type guard to check if a value is a {@link ConversionError}.\n *\n * @param error - The value to test.\n * @returns `true` and narrows `error` to {@link ConversionError}.\n *\n * @since 2.0.0\n * @public\n */\nexport function isConversionError(error: unknown): error is ConversionError {\n return error instanceof ConversionError;\n}\n\n/* =============================================================================\n * SHARED VALIDATION HELPERS\n * ============================================================================= */\n\n/**\n * Asserts that a bigint value is within the range `[min, max]` (inclusive).\n * Throws {@link ConversionError} if out of range.\n *\n * @param value - The value to check.\n * @param min - Minimum allowed value (inclusive).\n * @param max - Maximum allowed value (inclusive).\n * @param sourceType - Source type name for the error message.\n * @param targetType - Target type name for the error message.\n *\n * @throws {ConversionError} If value is outside the range.\n *\n * @internal\n */\nexport function assertBigintInRange(\n value: bigint,\n min: bigint,\n max: bigint,\n sourceType: string,\n targetType: string,\n): void {\n if (value < min || value > max) {\n throw new ConversionError(\n `${sourceType} value ${String(value)} is out of range for ${targetType} [${String(min)}, ${String(max)}]`,\n {\n sourceValue: value,\n sourceType,\n targetType,\n reason: `Value must be in range [${String(min)}, ${String(max)}]`,\n },\n );\n }\n}\n\n/**\n * Asserts that a number value is a safe integer within the range `[min, max]`.\n * Throws {@link ConversionError} if not a safe integer or out of range.\n *\n * @param value - The value to check.\n * @param min - Minimum allowed value (inclusive).\n * @param max - Maximum allowed value (inclusive).\n * @param targetType - Target type name for the error message.\n *\n * @throws {ConversionError} If value is not a safe integer or outside the range.\n *\n * @internal\n */\nexport function assertNumberInRange(\n value: number,\n min: number,\n max: number,\n targetType: string,\n): void {\n if (!Number.isSafeInteger(value)) {\n throw new ConversionError(\n `Value ${String(value)} is not a safe integer`,\n {\n sourceValue: value,\n sourceType: \"number\",\n targetType,\n reason: \"Value must be a safe integer (Number.isSafeInteger)\",\n },\n );\n }\n if (value < min || value > max) {\n throw new ConversionError(\n `number value ${String(value)} is out of range for ${targetType} [${String(min)}, ${String(max)}]`,\n {\n sourceValue: value,\n sourceType: \"number\",\n targetType,\n reason: `Value must be in range [${String(min)}, ${String(max)}]`,\n },\n );\n }\n}\n\n/**\n * Asserts that a Uint8Array has exactly the expected length.\n * Throws {@link ConversionError} if the length doesn't match.\n *\n * @param value - The byte array to check.\n * @param expectedLength - The required byte length.\n * @param targetType - Target type name for the error message.\n *\n * @throws {ConversionError} If value is not a Uint8Array or has wrong length.\n *\n * @internal\n */\nexport function assertByteLength(\n value: Uint8Array,\n expectedLength: number,\n targetType: string,\n): void {\n if (!(value instanceof Uint8Array)) {\n throw new ConversionError(\n `Expected Uint8Array, got ${typeof value}`,\n {\n sourceValue: value,\n sourceType: typeof value,\n targetType,\n reason: \"Input must be a Uint8Array\",\n },\n );\n }\n if (value.length !== expectedLength) {\n throw new ConversionError(\n `Expected exactly ${String(expectedLength)} bytes, got ${String(value.length)}`,\n {\n sourceValue: value,\n sourceType: \"Uint8Array\",\n targetType,\n reason: `Length must be exactly ${String(expectedLength)} bytes`,\n },\n );\n }\n}\n","/**\n * Branded Type Constructors\n *\n * Provides `create*` factory functions that wrap raw `Uint8Array` values into\n * their corresponding branded byte-array types after validating length constraints.\n *\n * For constructing branded types from raw `bigint` values, use the `assert*`\n * helpers exported from `common/types` or the `encode*` functions from\n * `byte-encoding`.\n *\n * @packageDocumentation\n * @module common/converters/branded\n * @since 2.0.0\n */\n\nimport {\n type Bytes,\n type U8LeBytes,\n type U8BeBytes,\n type U16LeBytes,\n type U16BeBytes,\n type U32LeBytes,\n type U32BeBytes,\n type U64LeBytes,\n type U64BeBytes,\n type U128LeBytes,\n type U128BeBytes,\n type U256LeBytes,\n type U256BeBytes,\n type U512LeBytes,\n type U512BeBytes,\n type U1024LeBytes,\n type U1024BeBytes,\n assertBytes,\n U8_BYTE_LENGTH,\n U16_BYTE_LENGTH,\n U32_BYTE_LENGTH,\n U64_BYTE_LENGTH,\n U128_BYTE_LENGTH,\n U256_BYTE_LENGTH,\n U512_BYTE_LENGTH,\n U1024_BYTE_LENGTH,\n} from \"../types\";\n\nimport {\n type X25519PublicKey,\n type X25519PrivateKey,\n type X25519Bytes,\n type SharedSecret,\n assertX25519PublicKey,\n assertX25519PrivateKey,\n assertX25519Bytes,\n assertSharedSecret,\n} from \"../../types/cryptography\";\n\nimport { assertByteLength } from \"./errors\";\n\n/* =============================================================================\n * GENERIC BYTE ARRAY CONSTRUCTOR\n * ============================================================================= */\n\n/**\n * Wraps a `Uint8Array` in the {@link Bytes} branded type.\n *\n * @param value - The raw `Uint8Array` to validate and brand.\n * @returns The same `Uint8Array`, branded as {@link Bytes}.\n * @throws {ConversionError} If `value` is not a `Uint8Array`.\n *\n * @since 2.0.0\n * @public\n */\nexport function createBytes(value: Uint8Array): Bytes {\n assertBytes(value);\n return value;\n}\n\n/* =============================================================================\n * LITTLE-ENDIAN BYTE ARRAY CONSTRUCTORS\n * ============================================================================= */\n\n/**\n * Wraps a 1-byte `Uint8Array` in the {@link U8LeBytes} branded type.\n *\n * @param value - A `Uint8Array` of exactly 1 byte.\n * @returns The same `Uint8Array`, branded as {@link U8LeBytes}.\n * @throws {ConversionError} If not exactly 1 byte.\n *\n * @since 2.0.0\n * @public\n */\nexport function createU8LeBytes(value: Uint8Array): U8LeBytes {\n assertByteLength(value, U8_BYTE_LENGTH, \"U8LeBytes\");\n return value as U8LeBytes;\n}\n\n/**\n * Wraps a 2-byte `Uint8Array` in the {@link U16LeBytes} branded type.\n *\n * @param value - A `Uint8Array` of exactly 2 bytes in little-endian order.\n * @returns The same `Uint8Array`, branded as {@link U16LeBytes}.\n * @throws {ConversionError} If not exactly 2 bytes.\n *\n * @since 2.0.0\n * @public\n */\nexport function createU16LeBytes(value: Uint8Array): U16LeBytes {\n assertByteLength(value, U16_BYTE_LENGTH, \"U16LeBytes\");\n return value as U16LeBytes;\n}\n\n/**\n * Wraps a 4-byte `Uint8Array` in the {@link U32LeBytes} branded type.\n *\n * @param value - A `Uint8Array` of exactly 4 bytes in little-endian order.\n * @returns The same `Uint8Array`, branded as {@link U32LeBytes}.\n * @throws {ConversionError} If not exactly 4 bytes.\n *\n * @since 2.0.0\n * @public\n */\nexport function createU32LeBytes(value: Uint8Array): U32LeBytes {\n assertByteLength(value, U32_BYTE_LENGTH, \"U32LeBytes\");\n return value as U32LeBytes;\n}\n\n/**\n * Wraps an 8-byte `Uint8Array` in the {@link U64LeBytes} branded type.\n *\n * @param value - A `Uint8Array` of exactly 8 bytes in little-endian order.\n * @returns The same `Uint8Array`, branded as {@link U64LeBytes}.\n * @throws {ConversionError} If not exactly 8 bytes.\n *\n * @since 2.0.0\n * @public\n */\nexport function createU64LeBytes(value: Uint8Array): U64LeBytes {\n assertByteLength(value, U64_BYTE_LENGTH, \"U64LeBytes\");\n return value as U64LeBytes;\n}\n\n/**\n * Wraps a 16-byte `Uint8Array` in the {@link U128LeBytes} branded type.\n *\n * @param value - A `Uint8Array` of exactly 16 bytes in little-endian order.\n * @returns The same `Uint8Array`, branded as {@link U128LeBytes}.\n * @throws {ConversionError} If not exactly 16 bytes.\n *\n * @since 2.0.0\n * @public\n */\nexport function createU128LeBytes(value: Uint8Array): U128LeBytes {\n assertByteLength(value, U128_BYTE_LENGTH, \"U128LeBytes\");\n return value as U128LeBytes;\n}\n\n/**\n * Wraps a 32-byte `Uint8Array` in the {@link U256LeBytes} branded type.\n *\n * @param value - A `Uint8Array` of exactly 32 bytes in little-endian order.\n * @returns The same `Uint8Array`, branded as {@link U256LeBytes}.\n * @throws {ConversionError} If not exactly 32 bytes.\n *\n * @since 2.0.0\n * @public\n */\nexport function createU256LeBytes(value: Uint8Array): U256LeBytes {\n assertByteLength(value, U256_BYTE_LENGTH, \"U256LeBytes\");\n return value as U256LeBytes;\n}\n\n/**\n * Wraps a 64-byte `Uint8Array` in the {@link U512LeBytes} branded type.\n *\n * @param value - A `Uint8Array` of exactly 64 bytes in little-endian order.\n * @returns The same `Uint8Array`, branded as {@link U512LeBytes}.\n * @throws {ConversionError} If not exactly 64 bytes.\n *\n * @since 2.0.0\n * @public\n */\nexport function createU512LeBytes(value: Uint8Array): U512LeBytes {\n assertByteLength(value, U512_BYTE_LENGTH, \"U512LeBytes\");\n return value as U512LeBytes;\n}\n\n/**\n * Wraps a 128-byte `Uint8Array` in the {@link U1024LeBytes} branded type.\n *\n * @param value - A `Uint8Array` of exactly 128 bytes in little-endian order.\n * @returns The same `Uint8Array`, branded as {@link U1024LeBytes}.\n * @throws {ConversionError} If not exactly 128 bytes.\n *\n * @since 2.0.0\n * @public\n */\nexport function createU1024LeBytes(value: Uint8Array): U1024LeBytes {\n assertByteLength(value, U1024_BYTE_LENGTH, \"U1024LeBytes\");\n return value as U1024LeBytes;\n}\n\n/* =============================================================================\n * BIG-ENDIAN BYTE ARRAY CONSTRUCTORS\n * ============================================================================= */\n\n/**\n * Wraps a 1-byte `Uint8Array` in the {@link U8BeBytes} branded type.\n *\n * @param value - A `Uint8Array` of exactly 1 byte.\n * @returns The same `Uint8Array`, branded as {@link U8BeBytes}.\n * @throws {ConversionError} If not exactly 1 byte.\n *\n * @since 2.0.0\n * @public\n */\nexport function createU8BeBytes(value: Uint8Array): U8BeBytes {\n assertByteLength(value, U8_BYTE_LENGTH, \"U8BeBytes\");\n return value as U8BeBytes;\n}\n\n/**\n * Wraps a 2-byte `Uint8Array` in the {@link U16BeBytes} branded type.\n *\n * @param value - A `Uint8Array` of exactly 2 bytes in big-endian order.\n * @returns The same `Uint8Array`, branded as {@link U16BeBytes}.\n * @throws {ConversionError} If not exactly 2 bytes.\n *\n * @since 2.0.0\n * @public\n */\nexport function createU16BeBytes(value: Uint8Array): U16BeBytes {\n assertByteLength(value, U16_BYTE_LENGTH, \"U16BeBytes\");\n return value as U16BeBytes;\n}\n\n/**\n * Wraps a 4-byte `Uint8Array` in the {@link U32BeBytes} branded type.\n *\n * @param value - A `Uint8Array` of exactly 4 bytes in big-endian order.\n * @returns The same `Uint8Array`, branded as {@link U32BeBytes}.\n * @throws {ConversionError} If not exactly 4 bytes.\n *\n * @since 2.0.0\n * @public\n */\nexport function createU32BeBytes(value: Uint8Array): U32BeBytes {\n assertByteLength(value, U32_BYTE_LENGTH, \"U32BeBytes\");\n return value as U32BeBytes;\n}\n\n/**\n * Wraps an 8-byte `Uint8Array` in the {@link U64BeBytes} branded type.\n *\n * @param value - A `Uint8Array` of exactly 8 bytes in big-endian order.\n * @returns The same `Uint8Array`, branded as {@link U64BeBytes}.\n * @throws {ConversionError} If not exactly 8 bytes.\n *\n * @since 2.0.0\n * @public\n */\nexport function createU64BeBytes(value: Uint8Array): U64BeBytes {\n assertByteLength(value, U64_BYTE_LENGTH, \"U64BeBytes\");\n return value as U64BeBytes;\n}\n\n/**\n * Wraps a 16-byte `Uint8Array` in the {@link U128BeBytes} branded type.\n *\n * @param value - A `Uint8Array` of exactly 16 bytes in big-endian order.\n * @returns The same `Uint8Array`, branded as {@link U128BeBytes}.\n * @throws {ConversionError} If not exactly 16 bytes.\n *\n * @since 2.0.0\n * @public\n */\nexport function createU128BeBytes(value: Uint8Array): U128BeBytes {\n assertByteLength(value, U128_BYTE_LENGTH, \"U128BeBytes\");\n return value as U128BeBytes;\n}\n\n/**\n * Wraps a 32-byte `Uint8Array` in the {@link U256BeBytes} branded type.\n *\n * @param value - A `Uint8Array` of exactly 32 bytes in big-endian order.\n * @returns The same `Uint8Array`, branded as {@link U256BeBytes}.\n * @throws {ConversionError} If not exactly 32 bytes.\n *\n * @since 2.0.0\n * @public\n */\nexport function createU256BeBytes(value: Uint8Array): U256BeBytes {\n assertByteLength(value, U256_BYTE_LENGTH, \"U256BeBytes\");\n return value as U256BeBytes;\n}\n\n/**\n * Wraps a 64-byte `Uint8Array` in the {@link U512BeBytes} branded type.\n *\n * @param value - A `Uint8Array` of exactly 64 bytes in big-endian order.\n * @returns The same `Uint8Array`, branded as {@link U512BeBytes}.\n * @throws {ConversionError} If not exactly 64 bytes.\n *\n * @since 2.0.0\n * @public\n */\nexport function createU512BeBytes(value: Uint8Array): U512BeBytes {\n assertByteLength(value, U512_BYTE_LENGTH, \"U512BeBytes\");\n return value as U512BeBytes;\n}\n\n/**\n * Wraps a 128-byte `Uint8Array` in the {@link U1024BeBytes} branded type.\n *\n * @param value - A `Uint8Array` of exactly 128 bytes in big-endian order.\n * @returns The same `Uint8Array`, branded as {@link U1024BeBytes}.\n * @throws {ConversionError} If not exactly 128 bytes.\n *\n * @since 2.0.0\n * @public\n */\nexport function createU1024BeBytes(value: Uint8Array): U1024BeBytes {\n assertByteLength(value, U1024_BYTE_LENGTH, \"U1024BeBytes\");\n return value as U1024BeBytes;\n}\n\n/* =============================================================================\n * CRYPTOGRAPHIC BYTE ARRAY CONSTRUCTORS\n * ============================================================================= */\n\n/**\n * Wraps a 32-byte `Uint8Array` in the {@link X25519Bytes} branded type.\n *\n * @param value - A `Uint8Array` of exactly 32 bytes.\n * @returns The same `Uint8Array`, branded as {@link X25519Bytes}.\n * @throws {CryptographyAssertionError} If not exactly 32 bytes.\n *\n * @since 2.0.0\n * @public\n */\nexport function createX25519Bytes(value: Uint8Array): X25519Bytes {\n assertX25519Bytes(value);\n return value;\n}\n\n/**\n * Wraps a 32-byte `Uint8Array` in the {@link X25519PublicKey} branded type.\n *\n * @param value - A `Uint8Array` of exactly 32 bytes representing an X25519 public key.\n * @returns The same `Uint8Array`, branded as {@link X25519PublicKey}.\n * @throws {CryptographyAssertionError} If not exactly 32 bytes.\n *\n * @since 2.0.0\n * @public\n */\nexport function createX25519PublicKey(value: Uint8Array): X25519PublicKey {\n assertX25519PublicKey(value);\n return value;\n}\n\n/**\n * Wraps a 32-byte `Uint8Array` in the {@link X25519PrivateKey} branded type.\n *\n * @remarks\n * **Security:** The caller is responsible for ensuring this value is treated as\n * secret material. Do not log, serialize, or transmit private keys.\n *\n * @param value - A `Uint8Array` of exactly 32 bytes representing an X25519 private key.\n * @returns The same `Uint8Array`, branded as {@link X25519PrivateKey}.\n * @throws {CryptographyAssertionError} If not exactly 32 bytes.\n *\n * @since 2.0.0\n * @public\n */\nexport function createX25519PrivateKey(value: Uint8Array): X25519PrivateKey {\n assertX25519PrivateKey(value);\n return value;\n}\n\n/**\n * Wraps a 32-byte `Uint8Array` in the {@link SharedSecret} branded type.\n *\n * @remarks\n * **Security:** Shared secrets are key material derived from ECDH.\n * Do not log or transmit.\n *\n * @param value - A `Uint8Array` of exactly 32 bytes.\n * @returns The same `Uint8Array`, branded as {@link SharedSecret}.\n * @throws {CryptographyAssertionError} If not exactly 32 bytes.\n *\n * @since 2.0.0\n * @public\n */\nexport function createSharedSecret(value: Uint8Array): SharedSecret {\n assertSharedSecret(value);\n return value;\n}\n\n// NOTE: createOptionalData32 is in common/type-helpers.ts (not duplicated here)\n"]}
|