@cascade-fyi/compression-kit 0.1.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/dist/index.cjs ADDED
@@ -0,0 +1,1653 @@
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) {
13
+ __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ }
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
25
+ }) : target, mod));
26
+
27
+ //#endregion
28
+ let bs58 = require("bs58");
29
+ bs58 = __toESM(bs58);
30
+ let _solana_kit = require("@solana/kit");
31
+ let _noble_hashes_sha3_js = require("@noble/hashes/sha3.js");
32
+
33
+ //#region src/state/types.ts
34
+ /**
35
+ * Tree type enum matching the on-chain representation.
36
+ */
37
+ let TreeType = /* @__PURE__ */ function(TreeType$1) {
38
+ /** v1 state merkle tree */
39
+ TreeType$1[TreeType$1["StateV1"] = 1] = "StateV1";
40
+ /** v1 address merkle tree */
41
+ TreeType$1[TreeType$1["AddressV1"] = 2] = "AddressV1";
42
+ /** v2 state merkle tree */
43
+ TreeType$1[TreeType$1["StateV2"] = 3] = "StateV2";
44
+ /** v2 address merkle tree */
45
+ TreeType$1[TreeType$1["AddressV2"] = 4] = "AddressV2";
46
+ return TreeType$1;
47
+ }({});
48
+
49
+ //#endregion
50
+ //#region src/constants.ts
51
+ /**
52
+ * Light Protocol constants using Solana Kit patterns.
53
+ *
54
+ * Uses:
55
+ * - Address type (branded string) instead of PublicKey
56
+ * - Native bigint instead of BN.js
57
+ */
58
+ let VERSION = /* @__PURE__ */ function(VERSION$1) {
59
+ VERSION$1["V1"] = "V1";
60
+ VERSION$1["V2"] = "V2";
61
+ return VERSION$1;
62
+ }({});
63
+ /**
64
+ * Feature flags for protocol versioning.
65
+ * @internal
66
+ */
67
+ const featureFlags = {
68
+ version: VERSION.V1,
69
+ isV2: () => featureFlags.version === VERSION.V2
70
+ };
71
+ /**
72
+ * Returns versioned endpoint name.
73
+ * @example versionedEndpoint('getCompressedAccount') -> 'getCompressedAccountV2' (if V2)
74
+ */
75
+ const versionedEndpoint = (base) => featureFlags.isV2() ? `${base}V2` : base;
76
+ /**
77
+ * BN254 prime field size.
78
+ * All hashes must be less than this value for ZK circuit compatibility.
79
+ */
80
+ const FIELD_SIZE = 21888242871839275222246405745257275088548364400416034343698204186575808495617n;
81
+ /**
82
+ * Highest address plus one (used for address validation).
83
+ */
84
+ const HIGHEST_ADDRESS_PLUS_ONE = 452312848583266388373324160190187140051835877600158453279131187530910662655n;
85
+ /** Light System Program ID */
86
+ const LIGHT_SYSTEM_PROGRAM = (0, _solana_kit.address)("SySTEM1eSU2p4BGQfQpimFEWWSC1XDFeun3Nqzz3rT7");
87
+ /** Account Compression Program ID */
88
+ const ACCOUNT_COMPRESSION_PROGRAM = (0, _solana_kit.address)("compr6CUsB5m2jS4Y3831ztGSTnDpnKJTKS95d64XVq");
89
+ /** Noop Program ID (for logging) */
90
+ const NOOP_PROGRAM = (0, _solana_kit.address)("noopb9bkMVfRPU8AsbpTUg8AQkHtKwMYZiFUjNRtMmV");
91
+ /** Compressed Token Program ID */
92
+ const COMPRESSED_TOKEN_PROGRAM = (0, _solana_kit.address)("cTokenmWW8bLPjZEBAUgYy3zKxQZW6VKi7bqNFEVv3m");
93
+ /** Registered Program PDA (constant) */
94
+ const REGISTERED_PROGRAM_PDA = (0, _solana_kit.address)("35hkDgaAKwMCaxRz2ocSZ6NaUrtKkyNqU6c4RV3tYJRh");
95
+ const INVOKE_DISCRIMINATOR = new Uint8Array([
96
+ 26,
97
+ 16,
98
+ 169,
99
+ 7,
100
+ 21,
101
+ 202,
102
+ 242,
103
+ 25
104
+ ]);
105
+ const INVOKE_CPI_DISCRIMINATOR = new Uint8Array([
106
+ 49,
107
+ 212,
108
+ 191,
109
+ 129,
110
+ 39,
111
+ 194,
112
+ 43,
113
+ 196
114
+ ]);
115
+ const INVOKE_CPI_WITH_READ_ONLY_DISCRIMINATOR = new Uint8Array([
116
+ 86,
117
+ 47,
118
+ 163,
119
+ 166,
120
+ 21,
121
+ 223,
122
+ 92,
123
+ 8
124
+ ]);
125
+ const INVOKE_CPI_WITH_ACCOUNT_INFO_DISCRIMINATOR = new Uint8Array([
126
+ 228,
127
+ 34,
128
+ 128,
129
+ 84,
130
+ 47,
131
+ 139,
132
+ 86,
133
+ 240
134
+ ]);
135
+ const INSERT_INTO_QUEUES_DISCRIMINATOR = new Uint8Array([
136
+ 180,
137
+ 143,
138
+ 159,
139
+ 153,
140
+ 35,
141
+ 46,
142
+ 248,
143
+ 163
144
+ ]);
145
+ const COMPUTE_BUDGET_PATTERN = new Uint8Array([
146
+ 2,
147
+ 64,
148
+ 66,
149
+ 15,
150
+ 0
151
+ ]);
152
+ /** Mainnet state tree lookup table */
153
+ const STATE_TREE_LOOKUP_TABLE_MAINNET = (0, _solana_kit.address)("7i86eQs3GSqHjN47WdWLTCGMW6gde1q96G2EVnUyK2st");
154
+ /** Mainnet nullified state tree lookup table */
155
+ const NULLIFIED_STATE_TREE_LOOKUP_TABLE_MAINNET = (0, _solana_kit.address)("H9QD4u1fG7KmkAzn2tDXhheushxFe1EcrjGGyEFXeMqT");
156
+ /** Devnet state tree lookup table */
157
+ const STATE_TREE_LOOKUP_TABLE_DEVNET = (0, _solana_kit.address)("Dk9mNkbiZXJZ4By8DfSP6HEE4ojZzRvucwpawLeuwq8q");
158
+ /** Devnet nullified state tree lookup table */
159
+ const NULLIFIED_STATE_TREE_LOOKUP_TABLE_DEVNET = (0, _solana_kit.address)("AXbHzp1NgjLvpfnD6JRTTovXZ7APUCdtWZFCRr5tCxse");
160
+ /**
161
+ * Returns default state tree lookup tables for each network.
162
+ */
163
+ function defaultStateTreeLookupTables() {
164
+ return {
165
+ mainnet: [{
166
+ stateTreeLookupTable: STATE_TREE_LOOKUP_TABLE_MAINNET,
167
+ nullifyLookupTable: NULLIFIED_STATE_TREE_LOOKUP_TABLE_MAINNET
168
+ }],
169
+ devnet: [{
170
+ stateTreeLookupTable: STATE_TREE_LOOKUP_TABLE_DEVNET,
171
+ nullifyLookupTable: NULLIFIED_STATE_TREE_LOOKUP_TABLE_DEVNET
172
+ }]
173
+ };
174
+ }
175
+ const MERKLE_TREE_PUBKEY = (0, _solana_kit.address)("smt1NamzXdq4AMqS2fS2F1i5KTYPZRhoHgWx38d8WsT");
176
+ const NULLIFIER_QUEUE_PUBKEY = (0, _solana_kit.address)("nfq1NvQDJ2GEgnS8zt9prAe8rjjpAW1zFkrvZoBR148");
177
+ const CPI_CONTEXT_PUBKEY = (0, _solana_kit.address)("cpi1uHzrEhBG733DoEJNgHCyRS3XmmyVNZx5fonubE4");
178
+ const MERKLE_TREE_2_PUBKEY = (0, _solana_kit.address)("smt2rJAFdyJJupwMKAqTNAJwvjhmiZ4JYGZmbVRw1Ho");
179
+ const NULLIFIER_QUEUE_2_PUBKEY = (0, _solana_kit.address)("nfq2hgS7NYemXsFaFUCe3EMXSDSfnZnAe27jC6aPP1X");
180
+ const CPI_CONTEXT_2_PUBKEY = (0, _solana_kit.address)("cpi2cdhkH5roePvcudTgUL8ppEBfTay1desGh8G8QxK");
181
+ const ADDRESS_TREE = (0, _solana_kit.address)("amt1Ayt45jfbdw5YSo7iz6WZxUmnZsQTYXy82hVwyC2");
182
+ const ADDRESS_QUEUE = (0, _solana_kit.address)("aq1S9z4reTSQAdgWHGD2zDaS39sjGrAxbR31vxJ2F4F");
183
+ const BATCH_MERKLE_TREE_1 = (0, _solana_kit.address)("bmt1LryLZUMmF7ZtqESaw7wifBXLfXHQYoE4GAmrahU");
184
+ const BATCH_QUEUE_1 = (0, _solana_kit.address)("oq1na8gojfdUhsfCpyjNt6h4JaDWtHf1yQj4koBWfto");
185
+ const BATCH_CPI_CONTEXT_1 = (0, _solana_kit.address)("cpi15BoVPKgEPw5o8wc2T816GE7b378nMXnhH3Xbq4y");
186
+ const BATCH_MERKLE_TREE_2 = (0, _solana_kit.address)("bmt2UxoBxB9xWev4BkLvkGdapsz6sZGkzViPNph7VFi");
187
+ const BATCH_QUEUE_2 = (0, _solana_kit.address)("oq2UkeMsJLfXt2QHzim242SUi3nvjJs8Pn7Eac9H9vg");
188
+ const BATCH_CPI_CONTEXT_2 = (0, _solana_kit.address)("cpi2yGapXUR3As5SjnHBAVvmApNiLsbeZpF3euWnW6B");
189
+ const BATCH_ADDRESS_TREE = (0, _solana_kit.address)("amt2kaJA14v3urZbZvnc5v2np8jqvc4Z8zDep5wbtzx");
190
+ const TEST_BATCH_ADDRESS_TREE = (0, _solana_kit.address)("EzKE84aVTkCUhDHLELqyJaq1Y7UVVmqxXqZjVHwHY3rK");
191
+ const DEFAULT_MERKLE_TREE_HEIGHT = 26;
192
+ const DEFAULT_MERKLE_TREE_ROOTS = 2800;
193
+ /** Threshold for UTXO merging (per asset) */
194
+ const UTXO_MERGE_THRESHOLD = 20;
195
+ const UTXO_MERGE_MAXIMUM = 10;
196
+ /** Tree rollover threshold (95% capacity) */
197
+ const TRANSACTION_MERKLE_TREE_ROLLOVER_THRESHOLD = BigInt(Math.floor(2 ** DEFAULT_MERKLE_TREE_HEIGHT * .95));
198
+ /** Fee per output compressed account (for tree rollover) */
199
+ const STATE_MERKLE_TREE_ROLLOVER_FEE = featureFlags.isV2() ? 1n : 300n;
200
+ /** Fee per new address (for address tree rollover) */
201
+ const ADDRESS_QUEUE_ROLLOVER_FEE = 392n;
202
+ /** Network fee for nullifying compressed accounts */
203
+ const STATE_MERKLE_TREE_NETWORK_FEE = 5000n;
204
+ /** V1 network fee per new address */
205
+ const ADDRESS_TREE_NETWORK_FEE_V1 = 5000n;
206
+ /** V2 network fee per new address */
207
+ const ADDRESS_TREE_NETWORK_FEE_V2 = 10000n;
208
+ /**
209
+ * Derives the account compression authority PDA.
210
+ */
211
+ async function getAccountCompressionAuthority() {
212
+ const [pda] = await (0, _solana_kit.getProgramDerivedAddress)({
213
+ programAddress: LIGHT_SYSTEM_PROGRAM,
214
+ seeds: [new TextEncoder().encode("cpi_authority")]
215
+ });
216
+ return pda;
217
+ }
218
+ /**
219
+ * Returns static accounts needed for Light System Program calls.
220
+ */
221
+ async function defaultStaticAccounts() {
222
+ return [
223
+ REGISTERED_PROGRAM_PDA,
224
+ NOOP_PROGRAM,
225
+ ACCOUNT_COMPRESSION_PROGRAM,
226
+ await getAccountCompressionAuthority()
227
+ ];
228
+ }
229
+ /**
230
+ * Check if URL is localhost/localnet.
231
+ * @internal
232
+ */
233
+ function isLocalTest(url) {
234
+ return url.includes("localhost") || url.includes("127.0.0.1");
235
+ }
236
+ /**
237
+ * Returns default test state tree accounts for localnet.
238
+ */
239
+ function defaultTestStateTreeAccounts() {
240
+ return {
241
+ nullifierQueue: NULLIFIER_QUEUE_PUBKEY,
242
+ merkleTree: MERKLE_TREE_PUBKEY,
243
+ merkleTreeHeight: DEFAULT_MERKLE_TREE_HEIGHT,
244
+ addressTree: ADDRESS_TREE,
245
+ addressQueue: ADDRESS_QUEUE
246
+ };
247
+ }
248
+ /**
249
+ * Returns active state tree infos for localnet testing.
250
+ * @internal
251
+ */
252
+ function localTestActiveStateTreeInfos() {
253
+ const v1Trees = [{
254
+ tree: MERKLE_TREE_PUBKEY,
255
+ queue: NULLIFIER_QUEUE_PUBKEY,
256
+ cpiContext: CPI_CONTEXT_PUBKEY,
257
+ treeType: TreeType.StateV1,
258
+ nextTreeInfo: null
259
+ }, {
260
+ tree: MERKLE_TREE_2_PUBKEY,
261
+ queue: NULLIFIER_QUEUE_2_PUBKEY,
262
+ cpiContext: CPI_CONTEXT_2_PUBKEY,
263
+ treeType: TreeType.StateV1,
264
+ nextTreeInfo: null
265
+ }];
266
+ if (!featureFlags.isV2()) return v1Trees;
267
+ return [
268
+ ...v1Trees,
269
+ {
270
+ tree: BATCH_MERKLE_TREE_1,
271
+ queue: BATCH_QUEUE_1,
272
+ cpiContext: BATCH_CPI_CONTEXT_1,
273
+ treeType: TreeType.StateV2,
274
+ nextTreeInfo: null
275
+ },
276
+ {
277
+ tree: BATCH_MERKLE_TREE_2,
278
+ queue: BATCH_QUEUE_2,
279
+ cpiContext: BATCH_CPI_CONTEXT_2,
280
+ treeType: TreeType.StateV2,
281
+ nextTreeInfo: null
282
+ },
283
+ {
284
+ tree: BATCH_ADDRESS_TREE,
285
+ queue: BATCH_ADDRESS_TREE,
286
+ treeType: TreeType.AddressV2,
287
+ nextTreeInfo: null
288
+ }
289
+ ];
290
+ }
291
+ /**
292
+ * Returns default address tree info.
293
+ */
294
+ function getDefaultAddressTreeInfo() {
295
+ if (featureFlags.isV2()) return {
296
+ tree: BATCH_ADDRESS_TREE,
297
+ queue: BATCH_ADDRESS_TREE,
298
+ treeType: TreeType.AddressV2,
299
+ nextTreeInfo: null
300
+ };
301
+ return {
302
+ tree: ADDRESS_TREE,
303
+ queue: ADDRESS_QUEUE,
304
+ treeType: TreeType.AddressV1,
305
+ nextTreeInfo: null
306
+ };
307
+ }
308
+
309
+ //#endregion
310
+ //#region src/errors.ts
311
+ /**
312
+ * Error types for Light Protocol stateless operations.
313
+ */
314
+ let UtxoErrorCode = /* @__PURE__ */ function(UtxoErrorCode$1) {
315
+ UtxoErrorCode$1["NEGATIVE_LAMPORTS"] = "NEGATIVE_LAMPORTS";
316
+ UtxoErrorCode$1["NOT_U64"] = "NOT_U64";
317
+ UtxoErrorCode$1["BLINDING_EXCEEDS_FIELD_SIZE"] = "BLINDING_EXCEEDS_FIELD_SIZE";
318
+ return UtxoErrorCode$1;
319
+ }({});
320
+ let SelectInUtxosErrorCode = /* @__PURE__ */ function(SelectInUtxosErrorCode$1) {
321
+ SelectInUtxosErrorCode$1["FAILED_TO_FIND_UTXO_COMBINATION"] = "FAILED_TO_FIND_UTXO_COMBINATION";
322
+ SelectInUtxosErrorCode$1["INVALID_NUMBER_OF_IN_UTXOS"] = "INVALID_NUMBER_OF_IN_UTXOS";
323
+ return SelectInUtxosErrorCode$1;
324
+ }({});
325
+ let CreateUtxoErrorCode = /* @__PURE__ */ function(CreateUtxoErrorCode$1) {
326
+ CreateUtxoErrorCode$1["OWNER_UNDEFINED"] = "OWNER_UNDEFINED";
327
+ CreateUtxoErrorCode$1["INVALID_OUTPUT_UTXO_LENGTH"] = "INVALID_OUTPUT_UTXO_LENGTH";
328
+ CreateUtxoErrorCode$1["UTXO_DATA_UNDEFINED"] = "UTXO_DATA_UNDEFINED";
329
+ return CreateUtxoErrorCode$1;
330
+ }({});
331
+ let RpcErrorCode = /* @__PURE__ */ function(RpcErrorCode$1) {
332
+ RpcErrorCode$1["CONNECTION_UNDEFINED"] = "CONNECTION_UNDEFINED";
333
+ RpcErrorCode$1["RPC_PUBKEY_UNDEFINED"] = "RPC_PUBKEY_UNDEFINED";
334
+ RpcErrorCode$1["RPC_METHOD_NOT_IMPLEMENTED"] = "RPC_METHOD_NOT_IMPLEMENTED";
335
+ RpcErrorCode$1["RPC_INVALID"] = "RPC_INVALID";
336
+ return RpcErrorCode$1;
337
+ }({});
338
+ let LookupTableErrorCode = /* @__PURE__ */ function(LookupTableErrorCode$1) {
339
+ LookupTableErrorCode$1["LOOK_UP_TABLE_UNDEFINED"] = "LOOK_UP_TABLE_UNDEFINED";
340
+ LookupTableErrorCode$1["LOOK_UP_TABLE_NOT_INITIALIZED"] = "LOOK_UP_TABLE_NOT_INITIALIZED";
341
+ return LookupTableErrorCode$1;
342
+ }({});
343
+ let HashErrorCode = /* @__PURE__ */ function(HashErrorCode$1) {
344
+ HashErrorCode$1["NO_POSEIDON_HASHER_PROVIDED"] = "NO_POSEIDON_HASHER_PROVIDED";
345
+ return HashErrorCode$1;
346
+ }({});
347
+ let ProofErrorCode = /* @__PURE__ */ function(ProofErrorCode$1) {
348
+ ProofErrorCode$1["INVALID_PROOF"] = "INVALID_PROOF";
349
+ ProofErrorCode$1["PROOF_INPUT_UNDEFINED"] = "PROOF_INPUT_UNDEFINED";
350
+ ProofErrorCode$1["PROOF_GENERATION_FAILED"] = "PROOF_GENERATION_FAILED";
351
+ return ProofErrorCode$1;
352
+ }({});
353
+ let MerkleTreeErrorCode = /* @__PURE__ */ function(MerkleTreeErrorCode$1) {
354
+ MerkleTreeErrorCode$1["MERKLE_TREE_NOT_INITIALIZED"] = "MERKLE_TREE_NOT_INITIALIZED";
355
+ MerkleTreeErrorCode$1["SOL_MERKLE_TREE_UNDEFINED"] = "SOL_MERKLE_TREE_UNDEFINED";
356
+ MerkleTreeErrorCode$1["MERKLE_TREE_UNDEFINED"] = "MERKLE_TREE_UNDEFINED";
357
+ MerkleTreeErrorCode$1["INPUT_UTXO_NOT_INSERTED_IN_MERKLE_TREE"] = "INPUT_UTXO_NOT_INSERTED_IN_MERKLE_TREE";
358
+ MerkleTreeErrorCode$1["MERKLE_TREE_INDEX_UNDEFINED"] = "MERKLE_TREE_INDEX_UNDEFINED";
359
+ MerkleTreeErrorCode$1["MERKLE_TREE_SET_SPACE_UNDEFINED"] = "MERKLE_TREE_SET_SPACE_UNDEFINED";
360
+ return MerkleTreeErrorCode$1;
361
+ }({});
362
+ let UtilsErrorCode = /* @__PURE__ */ function(UtilsErrorCode$1) {
363
+ UtilsErrorCode$1["ACCOUNT_NAME_UNDEFINED_IN_IDL"] = "ACCOUNT_NAME_UNDEFINED_IN_IDL";
364
+ UtilsErrorCode$1["PROPERTY_UNDEFINED"] = "PROPERTY_UNDEFINED";
365
+ UtilsErrorCode$1["LOOK_UP_TABLE_CREATION_FAILED"] = "LOOK_UP_TABLE_CREATION_FAILED";
366
+ UtilsErrorCode$1["UNSUPPORTED_ARCHITECTURE"] = "UNSUPPORTED_ARCHITECTURE";
367
+ UtilsErrorCode$1["UNSUPPORTED_PLATFORM"] = "UNSUPPORTED_PLATFORM";
368
+ UtilsErrorCode$1["ACCOUNTS_UNDEFINED"] = "ACCOUNTS_UNDEFINED";
369
+ UtilsErrorCode$1["INVALID_NUMBER"] = "INVALID_NUMBER";
370
+ return UtilsErrorCode$1;
371
+ }({});
372
+ let BN254ErrorCode = /* @__PURE__ */ function(BN254ErrorCode$1) {
373
+ BN254ErrorCode$1["VALUE_TOO_LARGE"] = "VALUE_TOO_LARGE";
374
+ BN254ErrorCode$1["INVALID_BASE58"] = "INVALID_BASE58";
375
+ return BN254ErrorCode$1;
376
+ }({});
377
+ /**
378
+ * Base error class for Light Protocol errors.
379
+ */
380
+ var LightError = class extends Error {
381
+ constructor(code, functionName, codeMessage) {
382
+ super(`${code}: ${codeMessage ?? ""}`);
383
+ this.name = this.constructor.name;
384
+ this.code = code;
385
+ this.functionName = functionName;
386
+ this.codeMessage = codeMessage;
387
+ }
388
+ };
389
+ var UtxoError = class extends LightError {};
390
+ var SelectInUtxosError = class extends LightError {};
391
+ var CreateUtxoError = class extends LightError {};
392
+ var RpcError = class extends LightError {};
393
+ var LookupTableError = class extends LightError {};
394
+ var HashError = class extends LightError {};
395
+ var ProofError = class extends LightError {};
396
+ var MerkleTreeError = class extends LightError {};
397
+ var UtilsError = class extends LightError {};
398
+ var BN254Error = class extends LightError {};
399
+ function createUtxoError(code, functionName, message) {
400
+ return new UtxoError(code, functionName, message);
401
+ }
402
+ function createRpcError(code, functionName, message) {
403
+ return new RpcError(code, functionName, message);
404
+ }
405
+ function createProofError(code, functionName, message) {
406
+ return new ProofError(code, functionName, message);
407
+ }
408
+ function createBN254Error(code, functionName, message) {
409
+ return new BN254Error(code, functionName, message);
410
+ }
411
+
412
+ //#endregion
413
+ //#region src/state/bn254.ts
414
+ /**
415
+ * BN254 field element utilities using native bigint.
416
+ *
417
+ * BN254 is the elliptic curve used by Light Protocol's ZK proofs.
418
+ * All hashes must be less than the field modulus (~2^254) for circuit compatibility.
419
+ *
420
+ * This module replaces BN.js with native bigint for:
421
+ * - Better performance
422
+ * - No Node.js Buffer dependency
423
+ * - Edge/browser compatibility
424
+ */
425
+ /**
426
+ * Check if a bigint is within the BN254 field.
427
+ */
428
+ function isBN254(value) {
429
+ return value >= 0n && value < FIELD_SIZE;
430
+ }
431
+ /**
432
+ * Assert that a bigint is within the BN254 field.
433
+ * @throws BN254Error if value is out of range
434
+ */
435
+ function assertIsBN254(value) {
436
+ if (!isBN254(value)) throw createBN254Error(BN254ErrorCode.VALUE_TOO_LARGE, "assertIsBN254", `Value ${value} exceeds BN254 field size`);
437
+ }
438
+ /**
439
+ * Enforce BN254 field size constraint.
440
+ * @throws BN254Error if value is out of range
441
+ */
442
+ function enforceFieldSize(value) {
443
+ assertIsBN254(value);
444
+ return value;
445
+ }
446
+ /**
447
+ * Create a BN254 field element from various input types.
448
+ *
449
+ * @param input - Number, string, bigint, or byte array
450
+ * @param base - Optional base for string parsing: 10, 16, 'hex', or 'base58'
451
+ * @returns BN254 field element
452
+ * @throws BN254Error if value exceeds field size
453
+ */
454
+ function createBN254(input, base) {
455
+ let value;
456
+ if (base === "base58") {
457
+ if (typeof input !== "string") throw createBN254Error(BN254ErrorCode.INVALID_BASE58, "createBN254", "Base58 input must be a string");
458
+ value = bytesToBigIntBE(bs58.default.decode(input));
459
+ } else if (typeof input === "bigint") value = input;
460
+ else if (typeof input === "number") value = BigInt(input);
461
+ else if (typeof input === "string") if (base === "hex" || base === 16) {
462
+ const cleanHex = input.startsWith("0x") ? input.slice(2) : input;
463
+ value = BigInt(`0x${cleanHex}`);
464
+ } else value = BigInt(input);
465
+ else if (input instanceof Uint8Array || Array.isArray(input)) value = bytesToBigIntBE(input instanceof Uint8Array ? input : new Uint8Array(input));
466
+ else throw createBN254Error(BN254ErrorCode.VALUE_TOO_LARGE, "createBN254", `Unsupported input type: ${typeof input}`);
467
+ return enforceFieldSize(value);
468
+ }
469
+ /**
470
+ * Create a BN254 from a 32-byte array (big-endian).
471
+ */
472
+ function bn254FromBytes(bytes) {
473
+ if (bytes.length !== 32) throw createBN254Error(BN254ErrorCode.VALUE_TOO_LARGE, "bn254FromBytes", `Expected 32 bytes, got ${bytes.length}`);
474
+ return createBN254(bytes);
475
+ }
476
+ /**
477
+ * Convert a BN254 field element to a base58 string.
478
+ */
479
+ function encodeBN254toBase58(value) {
480
+ const bytes = bigIntToBytesBE(value, 32);
481
+ return bs58.default.encode(bytes);
482
+ }
483
+ /**
484
+ * Convert a BN254 field element to a hex string (with 0x prefix).
485
+ */
486
+ function encodeBN254toHex(value) {
487
+ return `0x${value.toString(16).padStart(64, "0")}`;
488
+ }
489
+ /**
490
+ * Convert a BN254 field element to a 32-byte array (big-endian).
491
+ */
492
+ function bn254ToBytes(value) {
493
+ return bigIntToBytesBE(value, 32);
494
+ }
495
+ /**
496
+ * Convert a BN254 field element to a decimal string.
497
+ */
498
+ function bn254ToDecimalString(value) {
499
+ return value.toString(10);
500
+ }
501
+ /**
502
+ * Convert bytes to bigint (big-endian).
503
+ */
504
+ function bytesToBigIntBE(bytes) {
505
+ let result = 0n;
506
+ for (const byte of bytes) result = result << 8n | BigInt(byte);
507
+ return result;
508
+ }
509
+ /**
510
+ * Convert bytes to bigint (little-endian).
511
+ */
512
+ function bytesToBigIntLE(bytes) {
513
+ let result = 0n;
514
+ for (let i = bytes.length - 1; i >= 0; i--) result = result << 8n | BigInt(bytes[i]);
515
+ return result;
516
+ }
517
+ /**
518
+ * Convert bigint to bytes (big-endian).
519
+ */
520
+ function bigIntToBytesBE(value, length) {
521
+ const bytes = new Uint8Array(length);
522
+ let remaining = value;
523
+ for (let i = length - 1; i >= 0; i--) {
524
+ bytes[i] = Number(remaining & 255n);
525
+ remaining >>= 8n;
526
+ }
527
+ return bytes;
528
+ }
529
+ /**
530
+ * Convert bigint to bytes (little-endian).
531
+ */
532
+ function bigIntToBytesLE(value, length) {
533
+ const bytes = new Uint8Array(length);
534
+ let remaining = value;
535
+ for (let i = 0; i < length; i++) {
536
+ bytes[i] = Number(remaining & 255n);
537
+ remaining >>= 8n;
538
+ }
539
+ return bytes;
540
+ }
541
+ /**
542
+ * Add two BN254 values with modular reduction.
543
+ */
544
+ function bn254Add(a, b) {
545
+ return (a + b) % FIELD_SIZE;
546
+ }
547
+ /**
548
+ * Subtract two BN254 values with modular reduction.
549
+ */
550
+ function bn254Sub(a, b) {
551
+ const result = (a - b) % FIELD_SIZE;
552
+ return result < 0n ? result + FIELD_SIZE : result;
553
+ }
554
+ /**
555
+ * Multiply two BN254 values with modular reduction.
556
+ */
557
+ function bn254Mul(a, b) {
558
+ return a * b % FIELD_SIZE;
559
+ }
560
+ /**
561
+ * Check if a value is smaller than the BN254 field size (big-endian bytes).
562
+ */
563
+ function isSmallerThanFieldSize(bytes) {
564
+ return bytesToBigIntBE(bytes) < FIELD_SIZE;
565
+ }
566
+
567
+ //#endregion
568
+ //#region src/utils/conversion.ts
569
+ /**
570
+ * Conversion and hashing utilities for Light Protocol.
571
+ *
572
+ * Uses @noble/hashes for Keccak256 - pure JS, works in all environments.
573
+ */
574
+ /**
575
+ * Hash multiple byte arrays with Keccak256 and truncate to BN254 field size.
576
+ *
577
+ * This is the primary hash function used by Light Protocol. It:
578
+ * 1. Concatenates all input arrays
579
+ * 2. Hashes with Keccak256
580
+ * 3. Sets the first byte to 0 to ensure the result fits in BN254 field
581
+ *
582
+ * @param inputs - Array of byte arrays to hash
583
+ * @returns 32-byte hash that fits in BN254 field
584
+ */
585
+ function hashvToBn254FieldSizeBe(inputs) {
586
+ const hasher = _noble_hashes_sha3_js.keccak_256.create();
587
+ for (const input of inputs) hasher.update(input);
588
+ const hash = hasher.digest();
589
+ hash[0] = 0;
590
+ return hash;
591
+ }
592
+ /**
593
+ * Hash multiple byte arrays with Keccak256, appending 0xFF bump seed.
594
+ *
595
+ * This variant appends a 255 bump seed before hashing, matching the
596
+ * on-chain behavior for certain hash derivations.
597
+ *
598
+ * @param inputs - Array of byte arrays to hash
599
+ * @returns 32-byte hash that fits in BN254 field
600
+ */
601
+ function hashvToBn254FieldSizeBeWithBump(inputs) {
602
+ const hasher = _noble_hashes_sha3_js.keccak_256.create();
603
+ for (const input of inputs) hasher.update(input);
604
+ hasher.update(new Uint8Array([255]));
605
+ const hash = hasher.digest();
606
+ hash[0] = 0;
607
+ return hash;
608
+ }
609
+ /**
610
+ * Hash bytes with Keccak256 and find a valid bump seed.
611
+ *
612
+ * @deprecated Use hashvToBn254FieldSizeBe instead.
613
+ *
614
+ * This function iterates through bump seeds (255 down to 0) to find one
615
+ * that produces a hash smaller than the BN254 field size. This is the
616
+ * legacy approach - the simpler truncation method is now preferred.
617
+ *
618
+ * @param bytes - Bytes to hash
619
+ * @returns Tuple of [hash, bumpSeed] or null if no valid bump found
620
+ */
621
+ function hashToBn254FieldSizeBe(bytes) {
622
+ let bumpSeed = 255;
623
+ while (bumpSeed >= 0) {
624
+ const inputWithBump = new Uint8Array(bytes.length + 1);
625
+ inputWithBump.set(bytes);
626
+ inputWithBump[bytes.length] = bumpSeed;
627
+ const hash = (0, _noble_hashes_sha3_js.keccak_256)(inputWithBump);
628
+ if (hash.length !== 32) throw new Error("Invalid hash length");
629
+ hash[0] = 0;
630
+ if (isSmallerThanFieldSize(hash)) return [hash, bumpSeed];
631
+ bumpSeed--;
632
+ }
633
+ return null;
634
+ }
635
+ /**
636
+ * Convert hex string to bytes.
637
+ */
638
+ function hexToBytes(hex) {
639
+ const cleanHex = hex.startsWith("0x") ? hex.slice(2) : hex;
640
+ if (cleanHex.length % 2 !== 0) throw new Error("Invalid hex string length");
641
+ const bytes = new Uint8Array(cleanHex.length / 2);
642
+ for (let i = 0; i < bytes.length; i++) bytes[i] = parseInt(cleanHex.slice(i * 2, i * 2 + 2), 16);
643
+ return bytes;
644
+ }
645
+ /**
646
+ * Convert bytes to hex string (no 0x prefix).
647
+ */
648
+ function bytesToHex(bytes) {
649
+ return Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
650
+ }
651
+ /**
652
+ * Convert bigint to hex string with 0x prefix.
653
+ */
654
+ function toHex(value) {
655
+ return `0x${value.toString(16)}`;
656
+ }
657
+ /**
658
+ * Ensure value is an array.
659
+ */
660
+ function toArray(value) {
661
+ return Array.isArray(value) ? value : [value];
662
+ }
663
+ /**
664
+ * Merge bytes arrays into one.
665
+ */
666
+ function mergeBytes(arrays) {
667
+ const totalLength = arrays.reduce((acc, arr) => acc + arr.length, 0);
668
+ const result = new Uint8Array(totalLength);
669
+ let offset = 0;
670
+ for (const arr of arrays) {
671
+ result.set(arr, offset);
672
+ offset += arr.length;
673
+ }
674
+ return result;
675
+ }
676
+ /**
677
+ * Compare two byte arrays for equality.
678
+ */
679
+ function bytesEqual(a, b) {
680
+ if (a.length !== b.length) return false;
681
+ for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;
682
+ return true;
683
+ }
684
+ /**
685
+ * Pad bytes to a fixed length (right-pad with zeros).
686
+ */
687
+ function padBytes(bytes, length) {
688
+ if (bytes.length >= length) return bytes;
689
+ const result = new Uint8Array(length);
690
+ result.set(bytes);
691
+ return result;
692
+ }
693
+ /**
694
+ * Push unique items to an array.
695
+ * Mutates the array in place.
696
+ */
697
+ function pushUniqueItems(items, target) {
698
+ for (const item of items) if (!target.includes(item)) target.push(item);
699
+ }
700
+ /**
701
+ * Convert bytes to decimal string (for ZK circuit compatibility).
702
+ */
703
+ function bytesToDecimalString(bytes) {
704
+ return bytesToBigIntBE(bytes).toString(10);
705
+ }
706
+ /**
707
+ * Validate that a hash value is within BN254 field size.
708
+ */
709
+ function validateBN254Hash(hash) {
710
+ if (hash.length !== 32) return false;
711
+ return isSmallerThanFieldSize(hash);
712
+ }
713
+ /**
714
+ * Assert hash is valid BN254 field element.
715
+ */
716
+ function assertValidBN254Hash(hash) {
717
+ if (!validateBN254Hash(hash)) throw new Error(`Invalid BN254 hash: must be 32 bytes and less than field size`);
718
+ }
719
+
720
+ //#endregion
721
+ //#region src/utils/address.ts
722
+ /**
723
+ * Address derivation utilities for Light Protocol.
724
+ *
725
+ * Light Protocol uses a custom address derivation scheme that produces
726
+ * addresses within the BN254 field for ZK circuit compatibility.
727
+ */
728
+ /**
729
+ * Derive an address seed from seeds and program ID.
730
+ *
731
+ * This combines the program ID with user-provided seeds and hashes
732
+ * them to produce a 32-byte seed suitable for address derivation.
733
+ *
734
+ * @param seeds - User-provided seed bytes
735
+ * @param programId - The program ID that "owns" this address
736
+ * @returns 32-byte address seed
737
+ */
738
+ function deriveAddressSeed(seeds, programId) {
739
+ const encoder = (0, _solana_kit.getAddressEncoder)();
740
+ return hashvToBn254FieldSizeBe([Uint8Array.from(encoder.encode(programId)), ...seeds]);
741
+ }
742
+ /**
743
+ * Derive a compressed account address from a seed and address tree.
744
+ *
745
+ * @param seed - 32-byte seed (typically from deriveAddressSeed)
746
+ * @param addressMerkleTreePubkey - The address tree to derive from
747
+ * @returns Derived address as a Solana Address
748
+ *
749
+ * @example
750
+ * ```typescript
751
+ * import { deriveAddressSeed, deriveAddress } from '@cascade-fyi/compression-kit';
752
+ * import { address } from '@solana/kit';
753
+ *
754
+ * const programId = address('YourProgramId...');
755
+ * const seed = deriveAddressSeed([new TextEncoder().encode('my-seed')], programId);
756
+ * const compressedAddress = deriveAddress(seed);
757
+ * ```
758
+ */
759
+ function deriveAddress(seed, addressMerkleTreePubkey) {
760
+ if (seed.length !== 32) throw new Error("Seed length must be 32 bytes");
761
+ const treePubkey = addressMerkleTreePubkey ?? defaultTestStateTreeAccounts().addressTree;
762
+ const encoder = (0, _solana_kit.getAddressEncoder)();
763
+ const hashResult = hashToBn254FieldSizeBe(mergeBytes([Uint8Array.from(encoder.encode(treePubkey)), seed]));
764
+ if (hashResult === null) throw new Error("DeriveAddressError: Failed to find valid bump seed");
765
+ const [hash] = hashResult;
766
+ return (0, _solana_kit.address)(bs58.default.encode(hash));
767
+ }
768
+ /**
769
+ * Derive address seed using V2 method (no program ID in combined seeds).
770
+ *
771
+ * @param seeds - Seeds to hash together
772
+ * @returns 32-byte address seed
773
+ */
774
+ function deriveAddressSeedV2(seeds) {
775
+ return hashvToBn254FieldSizeBeWithBump(seeds);
776
+ }
777
+ /**
778
+ * Derive address using V2 method (matches Rust derive_address_from_seed).
779
+ *
780
+ * @param addressSeed - 32-byte address seed
781
+ * @param addressMerkleTreePubkey - Address tree pubkey
782
+ * @param programId - Program ID
783
+ * @returns Derived address
784
+ */
785
+ function deriveAddressV2(addressSeed, addressMerkleTreePubkey, programId) {
786
+ if (addressSeed.length !== 32) throw new Error("Address seed length must be 32 bytes");
787
+ const encoder = (0, _solana_kit.getAddressEncoder)();
788
+ const hash = hashvToBn254FieldSizeBeWithBump([
789
+ addressSeed,
790
+ Uint8Array.from(encoder.encode(addressMerkleTreePubkey)),
791
+ Uint8Array.from(encoder.encode(programId))
792
+ ]);
793
+ return (0, _solana_kit.address)(bs58.default.encode(hash));
794
+ }
795
+ /**
796
+ * Get the index of an address in an array, adding it if not present.
797
+ */
798
+ function getIndexOrAdd(accounts, pubkey) {
799
+ const existingIndex = accounts.indexOf(pubkey);
800
+ if (existingIndex !== -1) return existingIndex;
801
+ accounts.push(pubkey);
802
+ return accounts.length - 1;
803
+ }
804
+ /**
805
+ * Pack new address params for instruction data.
806
+ *
807
+ * Converts NewAddressParams to NewAddressParamsPacked by replacing
808
+ * pubkeys with their indices in the remaining accounts array.
809
+ *
810
+ * @param newAddressParams - Array of new address parameters
811
+ * @param remainingAccounts - Existing remaining accounts (will be modified)
812
+ * @returns Packed params and updated remaining accounts
813
+ */
814
+ function packNewAddressParams(newAddressParams, remainingAccounts) {
815
+ const accounts = [...remainingAccounts];
816
+ const newAddressParamsPacked = newAddressParams.map((params) => ({
817
+ seed: params.seed,
818
+ addressMerkleTreeRootIndex: params.addressMerkleTreeRootIndex,
819
+ addressMerkleTreeAccountIndex: 0,
820
+ addressQueueAccountIndex: 0
821
+ }));
822
+ for (let i = 0; i < newAddressParams.length; i++) newAddressParamsPacked[i].addressMerkleTreeAccountIndex = getIndexOrAdd(accounts, newAddressParams[i].addressMerkleTreePubkey);
823
+ for (let i = 0; i < newAddressParams.length; i++) newAddressParamsPacked[i].addressQueueAccountIndex = getIndexOrAdd(accounts, newAddressParams[i].addressQueuePubkey);
824
+ return {
825
+ newAddressParamsPacked,
826
+ remainingAccounts: accounts
827
+ };
828
+ }
829
+ /**
830
+ * Convert an address to bytes.
831
+ */
832
+ function addressToBytes(addr) {
833
+ const encoder = (0, _solana_kit.getAddressEncoder)();
834
+ return Uint8Array.from(encoder.encode(addr));
835
+ }
836
+ /**
837
+ * Convert bytes to an address.
838
+ *
839
+ * Note: This performs base58 encoding on the bytes. The bytes should
840
+ * be a valid 32-byte representation of an address.
841
+ */
842
+ function bytesToAddress(bytes) {
843
+ if (bytes.length !== 32) throw new Error("Address must be 32 bytes");
844
+ return (0, _solana_kit.address)(bs58.default.encode(bytes));
845
+ }
846
+
847
+ //#endregion
848
+ //#region src/utils/instruction.ts
849
+ /**
850
+ * Instruction building utilities for Light Protocol.
851
+ *
852
+ * Uses Solana Kit patterns:
853
+ * - AccountMeta with Address and AccountRole
854
+ * - Pure data objects instead of classes where possible
855
+ */
856
+ /**
857
+ * Create a basic system account config.
858
+ */
859
+ function createSystemAccountConfig(selfProgram) {
860
+ return { selfProgram };
861
+ }
862
+ /**
863
+ * Create a system account config with CPI context.
864
+ */
865
+ function createSystemAccountConfigWithCpi(selfProgram, cpiContext) {
866
+ return {
867
+ selfProgram,
868
+ cpiContext
869
+ };
870
+ }
871
+ /**
872
+ * Derive the CPI signer PDA for a program.
873
+ */
874
+ async function getCpiSignerPda(selfProgram) {
875
+ const [pda] = await (0, _solana_kit.getProgramDerivedAddress)({
876
+ programAddress: selfProgram,
877
+ seeds: [new TextEncoder().encode("cpi_authority")]
878
+ });
879
+ return pda;
880
+ }
881
+ /**
882
+ * Derive the account compression authority PDA.
883
+ */
884
+ async function getAccountCompressionAuthority$1() {
885
+ const [pda] = await (0, _solana_kit.getProgramDerivedAddress)({
886
+ programAddress: LIGHT_SYSTEM_PROGRAM,
887
+ seeds: [new TextEncoder().encode("cpi_authority")]
888
+ });
889
+ return pda;
890
+ }
891
+ /**
892
+ * Get the system program address.
893
+ */
894
+ function getSystemProgram() {
895
+ return "11111111111111111111111111111111";
896
+ }
897
+ /**
898
+ * Build Light System account metas (V1 layout).
899
+ *
900
+ * @param config - System account configuration
901
+ * @returns Array of account metas for Light System Program
902
+ *
903
+ * @example
904
+ * ```typescript
905
+ * import { getLightSystemAccountMetas, createSystemAccountConfig } from '@cascade-fyi/compression-kit';
906
+ * import { address } from '@solana/kit';
907
+ *
908
+ * const programId = address('YourProgramId...');
909
+ * const config = createSystemAccountConfig(programId);
910
+ * const metas = await getLightSystemAccountMetas(config);
911
+ * ```
912
+ */
913
+ async function getLightSystemAccountMetas(config) {
914
+ const cpiSigner = await getCpiSignerPda(config.selfProgram);
915
+ const compressionAuthority = await getAccountCompressionAuthority$1();
916
+ const metas = [
917
+ {
918
+ address: LIGHT_SYSTEM_PROGRAM,
919
+ role: _solana_kit.AccountRole.READONLY
920
+ },
921
+ {
922
+ address: cpiSigner,
923
+ role: _solana_kit.AccountRole.READONLY
924
+ },
925
+ {
926
+ address: REGISTERED_PROGRAM_PDA,
927
+ role: _solana_kit.AccountRole.READONLY
928
+ },
929
+ {
930
+ address: NOOP_PROGRAM,
931
+ role: _solana_kit.AccountRole.READONLY
932
+ },
933
+ {
934
+ address: compressionAuthority,
935
+ role: _solana_kit.AccountRole.READONLY
936
+ },
937
+ {
938
+ address: ACCOUNT_COMPRESSION_PROGRAM,
939
+ role: _solana_kit.AccountRole.READONLY
940
+ },
941
+ {
942
+ address: config.selfProgram,
943
+ role: _solana_kit.AccountRole.READONLY
944
+ }
945
+ ];
946
+ if (config.solPoolPda) metas.push({
947
+ address: config.solPoolPda,
948
+ role: _solana_kit.AccountRole.WRITABLE
949
+ });
950
+ if (config.solCompressionRecipient) metas.push({
951
+ address: config.solCompressionRecipient,
952
+ role: _solana_kit.AccountRole.WRITABLE
953
+ });
954
+ metas.push({
955
+ address: getSystemProgram(),
956
+ role: _solana_kit.AccountRole.READONLY
957
+ });
958
+ if (config.cpiContext) metas.push({
959
+ address: config.cpiContext,
960
+ role: _solana_kit.AccountRole.WRITABLE
961
+ });
962
+ return metas;
963
+ }
964
+ /**
965
+ * Build Light System account metas (V2 layout - no noop program).
966
+ */
967
+ async function getLightSystemAccountMetasV2(config) {
968
+ const cpiSigner = await getCpiSignerPda(config.selfProgram);
969
+ const compressionAuthority = await getAccountCompressionAuthority$1();
970
+ const metas = [
971
+ {
972
+ address: LIGHT_SYSTEM_PROGRAM,
973
+ role: _solana_kit.AccountRole.READONLY
974
+ },
975
+ {
976
+ address: cpiSigner,
977
+ role: _solana_kit.AccountRole.READONLY
978
+ },
979
+ {
980
+ address: REGISTERED_PROGRAM_PDA,
981
+ role: _solana_kit.AccountRole.READONLY
982
+ },
983
+ {
984
+ address: compressionAuthority,
985
+ role: _solana_kit.AccountRole.READONLY
986
+ },
987
+ {
988
+ address: ACCOUNT_COMPRESSION_PROGRAM,
989
+ role: _solana_kit.AccountRole.READONLY
990
+ },
991
+ {
992
+ address: getSystemProgram(),
993
+ role: _solana_kit.AccountRole.READONLY
994
+ }
995
+ ];
996
+ if (config.solPoolPda) metas.push({
997
+ address: config.solPoolPda,
998
+ role: _solana_kit.AccountRole.WRITABLE
999
+ });
1000
+ if (config.solCompressionRecipient) metas.push({
1001
+ address: config.solCompressionRecipient,
1002
+ role: _solana_kit.AccountRole.WRITABLE
1003
+ });
1004
+ if (config.cpiContext) metas.push({
1005
+ address: config.cpiContext,
1006
+ role: _solana_kit.AccountRole.WRITABLE
1007
+ });
1008
+ return metas;
1009
+ }
1010
+ /**
1011
+ * Helper class for building remaining accounts for Light Protocol instructions.
1012
+ *
1013
+ * Manages three categories of accounts:
1014
+ * 1. Pre-accounts: Signers and other accounts that come first
1015
+ * 2. System accounts: Light System Program static accounts
1016
+ * 3. Packed accounts: Dynamic accounts indexed by pubkey
1017
+ */
1018
+ var PackedAccounts = class PackedAccounts {
1019
+ constructor() {
1020
+ this.preAccounts = [];
1021
+ this.systemAccounts = [];
1022
+ this.nextIndex = 0;
1023
+ this.accountMap = /* @__PURE__ */ new Map();
1024
+ }
1025
+ /**
1026
+ * Create a new PackedAccounts with system accounts (V1 layout).
1027
+ */
1028
+ static async newWithSystemAccounts(config) {
1029
+ const instance = new PackedAccounts();
1030
+ await instance.addSystemAccounts(config);
1031
+ return instance;
1032
+ }
1033
+ /**
1034
+ * Create a new PackedAccounts with system accounts (V2 layout).
1035
+ */
1036
+ static async newWithSystemAccountsV2(config) {
1037
+ const instance = new PackedAccounts();
1038
+ await instance.addSystemAccountsV2(config);
1039
+ return instance;
1040
+ }
1041
+ /**
1042
+ * Add a signer to pre-accounts (readonly).
1043
+ */
1044
+ addPreAccountsSigner(pubkey) {
1045
+ this.preAccounts.push({
1046
+ address: pubkey,
1047
+ role: _solana_kit.AccountRole.READONLY_SIGNER
1048
+ });
1049
+ }
1050
+ /**
1051
+ * Add a writable signer to pre-accounts.
1052
+ */
1053
+ addPreAccountsSignerMut(pubkey) {
1054
+ this.preAccounts.push({
1055
+ address: pubkey,
1056
+ role: _solana_kit.AccountRole.WRITABLE_SIGNER
1057
+ });
1058
+ }
1059
+ /**
1060
+ * Add an account meta to pre-accounts.
1061
+ */
1062
+ addPreAccountsMeta(accountMeta) {
1063
+ this.preAccounts.push(accountMeta);
1064
+ }
1065
+ /**
1066
+ * Add system accounts (V1 layout).
1067
+ */
1068
+ async addSystemAccounts(config) {
1069
+ const metas = await getLightSystemAccountMetas(config);
1070
+ this.systemAccounts.push(...metas);
1071
+ }
1072
+ /**
1073
+ * Add system accounts (V2 layout).
1074
+ */
1075
+ async addSystemAccountsV2(config) {
1076
+ const metas = await getLightSystemAccountMetasV2(config);
1077
+ this.systemAccounts.push(...metas);
1078
+ }
1079
+ /**
1080
+ * Insert or get index for a writable account.
1081
+ */
1082
+ insertOrGet(pubkey) {
1083
+ return this.insertOrGetConfig(pubkey, false, true);
1084
+ }
1085
+ /**
1086
+ * Insert or get index for a readonly account.
1087
+ */
1088
+ insertOrGetReadOnly(pubkey) {
1089
+ return this.insertOrGetConfig(pubkey, false, false);
1090
+ }
1091
+ /**
1092
+ * Insert or get index with full configuration.
1093
+ */
1094
+ insertOrGetConfig(pubkey, isSigner, isWritable) {
1095
+ const key = pubkey;
1096
+ const existing = this.accountMap.get(key);
1097
+ if (existing) return existing[0];
1098
+ const index = this.nextIndex++;
1099
+ let role;
1100
+ if (isSigner && isWritable) role = _solana_kit.AccountRole.WRITABLE_SIGNER;
1101
+ else if (isSigner) role = _solana_kit.AccountRole.READONLY_SIGNER;
1102
+ else if (isWritable) role = _solana_kit.AccountRole.WRITABLE;
1103
+ else role = _solana_kit.AccountRole.READONLY;
1104
+ const meta = {
1105
+ address: pubkey,
1106
+ role
1107
+ };
1108
+ this.accountMap.set(key, [index, meta]);
1109
+ return index;
1110
+ }
1111
+ /**
1112
+ * Get packed accounts sorted by insertion order.
1113
+ */
1114
+ getPackedAccountMetas() {
1115
+ const entries = Array.from(this.accountMap.entries());
1116
+ entries.sort((a, b) => a[1][0] - b[1][0]);
1117
+ return entries.map(([, [, meta]]) => meta);
1118
+ }
1119
+ /**
1120
+ * Get offsets for system and packed accounts.
1121
+ */
1122
+ getOffsets() {
1123
+ const systemStart = this.preAccounts.length;
1124
+ return [systemStart, systemStart + this.systemAccounts.length];
1125
+ }
1126
+ /**
1127
+ * Build final remaining accounts array with offsets.
1128
+ */
1129
+ toAccountMetas() {
1130
+ const packed = this.getPackedAccountMetas();
1131
+ const [systemStart, packedStart] = this.getOffsets();
1132
+ return {
1133
+ remainingAccounts: [
1134
+ ...this.preAccounts,
1135
+ ...this.systemAccounts,
1136
+ ...packed
1137
+ ],
1138
+ systemStart,
1139
+ packedStart
1140
+ };
1141
+ }
1142
+ };
1143
+
1144
+ //#endregion
1145
+ //#region src/rpc.ts
1146
+ let requestId = 0n;
1147
+ /**
1148
+ * Light Protocol Photon RPC client.
1149
+ *
1150
+ * Provides methods for querying compressed accounts, requesting validity proofs,
1151
+ * and other indexer operations.
1152
+ */
1153
+ var PhotonRpc = class {
1154
+ constructor(endpoint, headers) {
1155
+ this.endpoint = endpoint;
1156
+ this.headers = {
1157
+ "Content-Type": "application/json",
1158
+ Accept: "application/json",
1159
+ ...headers
1160
+ };
1161
+ }
1162
+ /**
1163
+ * Make a JSON-RPC request to the Photon indexer.
1164
+ */
1165
+ async request(method, params) {
1166
+ const body = {
1167
+ jsonrpc: "2.0",
1168
+ id: (++requestId).toString(),
1169
+ method,
1170
+ params
1171
+ };
1172
+ const response = await fetch(this.endpoint, {
1173
+ method: "POST",
1174
+ headers: this.headers,
1175
+ body: JSON.stringify(body)
1176
+ });
1177
+ if (!response.ok) throw createRpcError(RpcErrorCode.RPC_INVALID, "request", `HTTP ${response.status}: ${response.statusText}`);
1178
+ const json = await response.json();
1179
+ if (json.error) throw createRpcError(RpcErrorCode.RPC_INVALID, method, `${json.error.code}: ${json.error.message}`);
1180
+ return json.result;
1181
+ }
1182
+ /**
1183
+ * Request with context wrapper.
1184
+ */
1185
+ async requestWithContext(method, params) {
1186
+ return this.request(method, params);
1187
+ }
1188
+ /**
1189
+ * Get indexer health status.
1190
+ */
1191
+ async getIndexerHealth() {
1192
+ return this.request("getIndexerHealth", {});
1193
+ }
1194
+ /**
1195
+ * Get current indexer slot.
1196
+ */
1197
+ async getIndexerSlot() {
1198
+ return this.request("getIndexerSlot", {});
1199
+ }
1200
+ /**
1201
+ * Get a single compressed account by address or hash.
1202
+ */
1203
+ async getCompressedAccount(addressOrHash) {
1204
+ const method = versionedEndpoint("getCompressedAccount");
1205
+ const params = {};
1206
+ if (addressOrHash.address) params.address = addressOrHash.address;
1207
+ if (addressOrHash.hash !== void 0) params.hash = encodeBN254(addressOrHash.hash);
1208
+ const result = await this.requestWithContext(method, params);
1209
+ if (!result.value) return null;
1210
+ return parseCompressedAccount(result.value);
1211
+ }
1212
+ /**
1213
+ * Get multiple compressed accounts by hashes.
1214
+ */
1215
+ async getMultipleCompressedAccounts(hashes) {
1216
+ const method = versionedEndpoint("getMultipleCompressedAccounts");
1217
+ const params = { hashes: hashes.map(encodeBN254) };
1218
+ return (await this.requestWithContext(method, params)).value.items.map(parseCompressedAccount);
1219
+ }
1220
+ /**
1221
+ * Get compressed accounts by owner.
1222
+ */
1223
+ async getCompressedAccountsByOwner(owner, config) {
1224
+ const method = versionedEndpoint("getCompressedAccountsByOwner");
1225
+ const params = {
1226
+ owner,
1227
+ cursor: config?.cursor,
1228
+ limit: config?.limit
1229
+ };
1230
+ const result = await this.requestWithContext(method, params);
1231
+ return {
1232
+ items: result.value.items.map(parseCompressedAccount),
1233
+ cursor: result.value.cursor
1234
+ };
1235
+ }
1236
+ /**
1237
+ * Get compressed SOL balance by owner.
1238
+ */
1239
+ async getCompressedBalanceByOwner(owner) {
1240
+ const method = versionedEndpoint("getCompressedBalanceByOwner");
1241
+ const result = await this.requestWithContext(method, { owner });
1242
+ return BigInt(result.value);
1243
+ }
1244
+ /**
1245
+ * Get merkle proof for a compressed account.
1246
+ */
1247
+ async getCompressedAccountProof(hash) {
1248
+ const method = versionedEndpoint("getCompressedAccountProof");
1249
+ const params = { hash: encodeBN254(hash) };
1250
+ return parseMerkleProof((await this.requestWithContext(method, params)).value);
1251
+ }
1252
+ /**
1253
+ * Get merkle proofs for multiple compressed accounts.
1254
+ */
1255
+ async getMultipleCompressedAccountProofs(hashes) {
1256
+ const method = versionedEndpoint("getMultipleCompressedAccountProofs");
1257
+ const params = { hashes: hashes.map(encodeBN254) };
1258
+ return (await this.requestWithContext(method, params)).value.map(parseMerkleProof);
1259
+ }
1260
+ /**
1261
+ * Get validity proof for compressed accounts and/or new addresses.
1262
+ *
1263
+ * This is the main method for obtaining ZK proofs needed to use
1264
+ * compressed accounts in transactions.
1265
+ */
1266
+ async getValidityProof(hashes, newAddresses) {
1267
+ const method = versionedEndpoint("getValidityProof");
1268
+ const params = {
1269
+ hashes: hashes.map((h) => ({
1270
+ hash: encodeBN254(h.hash),
1271
+ tree: h.stateTreeInfo.tree,
1272
+ queue: h.stateTreeInfo.queue
1273
+ })),
1274
+ newAddresses: newAddresses.map((a) => ({
1275
+ address: encodeBN254(a.address),
1276
+ tree: a.addressTreeInfo.tree,
1277
+ queue: a.addressTreeInfo.queue
1278
+ }))
1279
+ };
1280
+ return parseValidityProof((await this.requestWithContext(method, params)).value);
1281
+ }
1282
+ /**
1283
+ * Get compressed token accounts by owner.
1284
+ */
1285
+ async getCompressedTokenAccountsByOwner(owner, config) {
1286
+ const method = versionedEndpoint("getCompressedTokenAccountsByOwner");
1287
+ const params = {
1288
+ owner,
1289
+ mint: config?.mint,
1290
+ cursor: config?.cursor,
1291
+ limit: config?.limit
1292
+ };
1293
+ const result = await this.requestWithContext(method, params);
1294
+ return {
1295
+ items: result.value.items.map(parseTokenAccount),
1296
+ cursor: result.value.cursor
1297
+ };
1298
+ }
1299
+ /**
1300
+ * Get compressed token balances by owner.
1301
+ */
1302
+ async getCompressedTokenBalancesByOwner(owner, config) {
1303
+ const method = versionedEndpoint("getCompressedTokenBalancesByOwner");
1304
+ const params = {
1305
+ owner,
1306
+ mint: config?.mint,
1307
+ cursor: config?.cursor,
1308
+ limit: config?.limit
1309
+ };
1310
+ const result = await this.requestWithContext(method, params);
1311
+ return {
1312
+ items: result.value.items.map((item) => ({
1313
+ balance: BigInt(item.balance),
1314
+ mint: (0, _solana_kit.address)(item.mint)
1315
+ })),
1316
+ cursor: result.value.cursor
1317
+ };
1318
+ }
1319
+ /**
1320
+ * Get compression signatures for an account hash.
1321
+ */
1322
+ async getCompressionSignaturesForAccount(hash) {
1323
+ const method = "getCompressionSignaturesForAccount";
1324
+ const params = { hash: encodeBN254(hash) };
1325
+ return (await this.requestWithContext(method, params)).value.items;
1326
+ }
1327
+ /**
1328
+ * Get compression signatures for an address.
1329
+ */
1330
+ async getCompressionSignaturesForAddress(addr, options) {
1331
+ const method = "getCompressionSignaturesForAddress";
1332
+ const params = {
1333
+ address: addr,
1334
+ cursor: options?.cursor,
1335
+ limit: options?.limit
1336
+ };
1337
+ const result = await this.requestWithContext(method, params);
1338
+ return {
1339
+ items: result.value.items,
1340
+ cursor: result.value.cursor
1341
+ };
1342
+ }
1343
+ /**
1344
+ * Get compression signatures for an owner.
1345
+ */
1346
+ async getCompressionSignaturesForOwner(owner, options) {
1347
+ const method = "getCompressionSignaturesForOwner";
1348
+ const params = {
1349
+ owner,
1350
+ cursor: options?.cursor,
1351
+ limit: options?.limit
1352
+ };
1353
+ const result = await this.requestWithContext(method, params);
1354
+ return {
1355
+ items: result.value.items,
1356
+ cursor: result.value.cursor
1357
+ };
1358
+ }
1359
+ /**
1360
+ * Get latest non-voting signatures (compression transactions).
1361
+ */
1362
+ async getLatestCompressionSignatures(cursor, limit) {
1363
+ const method = "getLatestCompressionSignatures";
1364
+ const params = {
1365
+ cursor,
1366
+ limit
1367
+ };
1368
+ const result = await this.requestWithContext(method, params);
1369
+ return {
1370
+ items: result.value.items,
1371
+ cursor: result.value.cursor
1372
+ };
1373
+ }
1374
+ };
1375
+ /**
1376
+ * Encode BN254 to base58 string for RPC params.
1377
+ */
1378
+ function encodeBN254(value) {
1379
+ const bytes = new Uint8Array(32);
1380
+ let remaining = value;
1381
+ for (let i = 31; i >= 0; i--) {
1382
+ bytes[i] = Number(remaining & 255n);
1383
+ remaining >>= 8n;
1384
+ }
1385
+ return bs58.default.encode(bytes);
1386
+ }
1387
+ function parseCompressedAccount(raw) {
1388
+ const treeInfo = parseTreeInfo(raw);
1389
+ return {
1390
+ owner: (0, _solana_kit.address)(raw.owner),
1391
+ lamports: BigInt(raw.lamports),
1392
+ address: raw.address ? base58ToBytes(raw.address) : null,
1393
+ data: raw.data ? {
1394
+ discriminator: hexToBytes$1(raw.data.discriminator),
1395
+ data: base64ToBytes(raw.data.data),
1396
+ dataHash: base58ToBytes(raw.data.dataHash)
1397
+ } : null,
1398
+ treeInfo,
1399
+ hash: createBN254(raw.hash, "base58"),
1400
+ leafIndex: raw.leafIndex,
1401
+ proveByIndex: raw.proveByIndex ?? false,
1402
+ readOnly: false
1403
+ };
1404
+ }
1405
+ function parseTreeInfo(raw) {
1406
+ if (featureFlags.isV2() && "merkleContext" in raw && raw.merkleContext) {
1407
+ const ctx = raw.merkleContext;
1408
+ return {
1409
+ tree: (0, _solana_kit.address)(ctx.tree),
1410
+ queue: (0, _solana_kit.address)(ctx.queue),
1411
+ treeType: ctx.treeType,
1412
+ cpiContext: ctx.cpiContext ? (0, _solana_kit.address)(ctx.cpiContext) : void 0,
1413
+ nextTreeInfo: null
1414
+ };
1415
+ }
1416
+ if ("treeContext" in raw && raw.treeContext) {
1417
+ const ctx = raw.treeContext;
1418
+ return {
1419
+ tree: (0, _solana_kit.address)(ctx.tree),
1420
+ queue: (0, _solana_kit.address)(ctx.queue),
1421
+ treeType: ctx.treeType,
1422
+ cpiContext: ctx.cpiContext ? (0, _solana_kit.address)(ctx.cpiContext) : void 0,
1423
+ nextTreeInfo: null
1424
+ };
1425
+ }
1426
+ const tree = "tree" in raw && raw.tree ? raw.tree : "merkleTree" in raw ? raw.merkleTree ?? "" : "";
1427
+ return {
1428
+ tree: (0, _solana_kit.address)(tree),
1429
+ queue: (0, _solana_kit.address)(tree),
1430
+ treeType: 1,
1431
+ nextTreeInfo: null
1432
+ };
1433
+ }
1434
+ function parseMerkleProof(raw) {
1435
+ return {
1436
+ treeInfo: parseTreeInfo(raw),
1437
+ hash: createBN254(raw.hash, "base58"),
1438
+ leafIndex: raw.leafIndex,
1439
+ proveByIndex: raw.proveByIndex ?? false,
1440
+ merkleProof: raw.proof.map((p) => createBN254(p, "base58")),
1441
+ rootIndex: raw.rootSeq,
1442
+ root: createBN254(raw.root, "base58")
1443
+ };
1444
+ }
1445
+ function parseValidityProof(raw) {
1446
+ const proof = raw.compressedProof ? {
1447
+ a: new Uint8Array(raw.compressedProof.a),
1448
+ b: new Uint8Array(raw.compressedProof.b),
1449
+ c: new Uint8Array(raw.compressedProof.c)
1450
+ } : null;
1451
+ if (raw.accounts) return {
1452
+ compressedProof: proof,
1453
+ roots: raw.accounts.map((a) => createBN254(a.root, "base58")),
1454
+ rootIndices: raw.accounts.map((a) => a.rootIndex.rootIndex),
1455
+ leafIndices: raw.accounts.map((a) => a.leafIndex),
1456
+ leaves: raw.accounts.map((a) => createBN254(a.hash, "base58")),
1457
+ treeInfos: raw.accounts.map((a) => ({
1458
+ tree: (0, _solana_kit.address)(a.merkleContext.tree),
1459
+ queue: (0, _solana_kit.address)(a.merkleContext.queue),
1460
+ treeType: a.merkleContext.treeType,
1461
+ nextTreeInfo: null
1462
+ })),
1463
+ proveByIndices: raw.accounts.map((a) => a.rootIndex.proveByIndex)
1464
+ };
1465
+ return {
1466
+ compressedProof: proof,
1467
+ roots: raw.roots.map((r) => createBN254(r, "base58")),
1468
+ rootIndices: raw.rootIndices,
1469
+ leafIndices: raw.leafIndices,
1470
+ leaves: raw.leaves.map((l) => createBN254(l, "base58")),
1471
+ treeInfos: (raw.merkleTrees ?? []).map((t) => ({
1472
+ tree: (0, _solana_kit.address)(t),
1473
+ queue: (0, _solana_kit.address)(t),
1474
+ treeType: 1,
1475
+ nextTreeInfo: null
1476
+ })),
1477
+ proveByIndices: raw.leafIndices.map(() => false)
1478
+ };
1479
+ }
1480
+ function parseTokenAccount(raw) {
1481
+ return {
1482
+ compressedAccount: parseCompressedAccount(raw.account),
1483
+ parsed: {
1484
+ mint: (0, _solana_kit.address)(raw.tokenData.mint),
1485
+ owner: (0, _solana_kit.address)(raw.tokenData.owner),
1486
+ amount: BigInt(raw.tokenData.amount),
1487
+ delegate: raw.tokenData.delegate ? (0, _solana_kit.address)(raw.tokenData.delegate) : null,
1488
+ state: raw.tokenData.state === "initialized" ? 1 : 0,
1489
+ tlv: null
1490
+ }
1491
+ };
1492
+ }
1493
+ function base58ToBytes(value) {
1494
+ return bs58.default.decode(value);
1495
+ }
1496
+ function base64ToBytes(value) {
1497
+ const binary = atob(value);
1498
+ const bytes = new Uint8Array(binary.length);
1499
+ for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
1500
+ return bytes;
1501
+ }
1502
+ function hexToBytes$1(hex) {
1503
+ const cleanHex = hex.startsWith("0x") ? hex.slice(2) : hex;
1504
+ const bytes = new Uint8Array(cleanHex.length / 2);
1505
+ for (let i = 0; i < bytes.length; i++) bytes[i] = parseInt(cleanHex.slice(i * 2, i * 2 + 2), 16);
1506
+ return bytes;
1507
+ }
1508
+ /**
1509
+ * Create a Photon RPC client.
1510
+ *
1511
+ * @param endpoint - Photon indexer URL (e.g., "https://zk-testnet.helius.dev:8784")
1512
+ * @param headers - Optional additional headers
1513
+ * @returns PhotonRpc instance
1514
+ *
1515
+ * @example
1516
+ * ```typescript
1517
+ * import { createPhotonRpc } from '@cascade-fyi/compression-kit';
1518
+ *
1519
+ * const rpc = createPhotonRpc('https://mainnet.helius-rpc.com/?api-key=YOUR_KEY');
1520
+ * const accounts = await rpc.getCompressedAccountsByOwner(ownerAddress);
1521
+ * ```
1522
+ */
1523
+ function createPhotonRpc(endpoint, headers) {
1524
+ return new PhotonRpc(endpoint, headers);
1525
+ }
1526
+
1527
+ //#endregion
1528
+ exports.ACCOUNT_COMPRESSION_PROGRAM = ACCOUNT_COMPRESSION_PROGRAM;
1529
+ exports.ADDRESS_QUEUE = ADDRESS_QUEUE;
1530
+ exports.ADDRESS_QUEUE_ROLLOVER_FEE = ADDRESS_QUEUE_ROLLOVER_FEE;
1531
+ exports.ADDRESS_TREE = ADDRESS_TREE;
1532
+ exports.ADDRESS_TREE_NETWORK_FEE_V1 = ADDRESS_TREE_NETWORK_FEE_V1;
1533
+ exports.ADDRESS_TREE_NETWORK_FEE_V2 = ADDRESS_TREE_NETWORK_FEE_V2;
1534
+ exports.BATCH_ADDRESS_TREE = BATCH_ADDRESS_TREE;
1535
+ exports.BATCH_CPI_CONTEXT_1 = BATCH_CPI_CONTEXT_1;
1536
+ exports.BATCH_CPI_CONTEXT_2 = BATCH_CPI_CONTEXT_2;
1537
+ exports.BATCH_MERKLE_TREE_1 = BATCH_MERKLE_TREE_1;
1538
+ exports.BATCH_MERKLE_TREE_2 = BATCH_MERKLE_TREE_2;
1539
+ exports.BATCH_QUEUE_1 = BATCH_QUEUE_1;
1540
+ exports.BATCH_QUEUE_2 = BATCH_QUEUE_2;
1541
+ exports.BN254Error = BN254Error;
1542
+ exports.BN254ErrorCode = BN254ErrorCode;
1543
+ exports.COMPRESSED_TOKEN_PROGRAM = COMPRESSED_TOKEN_PROGRAM;
1544
+ exports.COMPUTE_BUDGET_PATTERN = COMPUTE_BUDGET_PATTERN;
1545
+ exports.CPI_CONTEXT_2_PUBKEY = CPI_CONTEXT_2_PUBKEY;
1546
+ exports.CPI_CONTEXT_PUBKEY = CPI_CONTEXT_PUBKEY;
1547
+ exports.CreateUtxoError = CreateUtxoError;
1548
+ exports.CreateUtxoErrorCode = CreateUtxoErrorCode;
1549
+ exports.DEFAULT_MERKLE_TREE_HEIGHT = DEFAULT_MERKLE_TREE_HEIGHT;
1550
+ exports.DEFAULT_MERKLE_TREE_ROOTS = DEFAULT_MERKLE_TREE_ROOTS;
1551
+ exports.FIELD_SIZE = FIELD_SIZE;
1552
+ exports.HIGHEST_ADDRESS_PLUS_ONE = HIGHEST_ADDRESS_PLUS_ONE;
1553
+ exports.HashError = HashError;
1554
+ exports.HashErrorCode = HashErrorCode;
1555
+ exports.INSERT_INTO_QUEUES_DISCRIMINATOR = INSERT_INTO_QUEUES_DISCRIMINATOR;
1556
+ exports.INVOKE_CPI_DISCRIMINATOR = INVOKE_CPI_DISCRIMINATOR;
1557
+ exports.INVOKE_CPI_WITH_ACCOUNT_INFO_DISCRIMINATOR = INVOKE_CPI_WITH_ACCOUNT_INFO_DISCRIMINATOR;
1558
+ exports.INVOKE_CPI_WITH_READ_ONLY_DISCRIMINATOR = INVOKE_CPI_WITH_READ_ONLY_DISCRIMINATOR;
1559
+ exports.INVOKE_DISCRIMINATOR = INVOKE_DISCRIMINATOR;
1560
+ exports.LIGHT_SYSTEM_PROGRAM = LIGHT_SYSTEM_PROGRAM;
1561
+ exports.LookupTableError = LookupTableError;
1562
+ exports.LookupTableErrorCode = LookupTableErrorCode;
1563
+ exports.MERKLE_TREE_2_PUBKEY = MERKLE_TREE_2_PUBKEY;
1564
+ exports.MERKLE_TREE_PUBKEY = MERKLE_TREE_PUBKEY;
1565
+ exports.MerkleTreeError = MerkleTreeError;
1566
+ exports.MerkleTreeErrorCode = MerkleTreeErrorCode;
1567
+ exports.NOOP_PROGRAM = NOOP_PROGRAM;
1568
+ exports.NULLIFIED_STATE_TREE_LOOKUP_TABLE_DEVNET = NULLIFIED_STATE_TREE_LOOKUP_TABLE_DEVNET;
1569
+ exports.NULLIFIED_STATE_TREE_LOOKUP_TABLE_MAINNET = NULLIFIED_STATE_TREE_LOOKUP_TABLE_MAINNET;
1570
+ exports.NULLIFIER_QUEUE_2_PUBKEY = NULLIFIER_QUEUE_2_PUBKEY;
1571
+ exports.NULLIFIER_QUEUE_PUBKEY = NULLIFIER_QUEUE_PUBKEY;
1572
+ exports.PackedAccounts = PackedAccounts;
1573
+ exports.PhotonRpc = PhotonRpc;
1574
+ exports.ProofError = ProofError;
1575
+ exports.ProofErrorCode = ProofErrorCode;
1576
+ exports.REGISTERED_PROGRAM_PDA = REGISTERED_PROGRAM_PDA;
1577
+ exports.RpcError = RpcError;
1578
+ exports.RpcErrorCode = RpcErrorCode;
1579
+ exports.STATE_MERKLE_TREE_NETWORK_FEE = STATE_MERKLE_TREE_NETWORK_FEE;
1580
+ exports.STATE_MERKLE_TREE_ROLLOVER_FEE = STATE_MERKLE_TREE_ROLLOVER_FEE;
1581
+ exports.STATE_TREE_LOOKUP_TABLE_DEVNET = STATE_TREE_LOOKUP_TABLE_DEVNET;
1582
+ exports.STATE_TREE_LOOKUP_TABLE_MAINNET = STATE_TREE_LOOKUP_TABLE_MAINNET;
1583
+ exports.SelectInUtxosError = SelectInUtxosError;
1584
+ exports.SelectInUtxosErrorCode = SelectInUtxosErrorCode;
1585
+ exports.TEST_BATCH_ADDRESS_TREE = TEST_BATCH_ADDRESS_TREE;
1586
+ exports.TRANSACTION_MERKLE_TREE_ROLLOVER_THRESHOLD = TRANSACTION_MERKLE_TREE_ROLLOVER_THRESHOLD;
1587
+ exports.TreeType = TreeType;
1588
+ exports.UTXO_MERGE_MAXIMUM = UTXO_MERGE_MAXIMUM;
1589
+ exports.UTXO_MERGE_THRESHOLD = UTXO_MERGE_THRESHOLD;
1590
+ exports.UtilsError = UtilsError;
1591
+ exports.UtilsErrorCode = UtilsErrorCode;
1592
+ exports.UtxoError = UtxoError;
1593
+ exports.UtxoErrorCode = UtxoErrorCode;
1594
+ exports.VERSION = VERSION;
1595
+ exports.addressToBytes = addressToBytes;
1596
+ exports.assertIsBN254 = assertIsBN254;
1597
+ exports.assertValidBN254Hash = assertValidBN254Hash;
1598
+ exports.bigIntToBytesBE = bigIntToBytesBE;
1599
+ exports.bigIntToBytesLE = bigIntToBytesLE;
1600
+ exports.bn254Add = bn254Add;
1601
+ exports.bn254FromBytes = bn254FromBytes;
1602
+ exports.bn254Mul = bn254Mul;
1603
+ exports.bn254Sub = bn254Sub;
1604
+ exports.bn254ToBytes = bn254ToBytes;
1605
+ exports.bn254ToDecimalString = bn254ToDecimalString;
1606
+ exports.bytesEqual = bytesEqual;
1607
+ exports.bytesToAddress = bytesToAddress;
1608
+ exports.bytesToBigIntBE = bytesToBigIntBE;
1609
+ exports.bytesToBigIntLE = bytesToBigIntLE;
1610
+ exports.bytesToDecimalString = bytesToDecimalString;
1611
+ exports.bytesToHex = bytesToHex;
1612
+ exports.createBN254 = createBN254;
1613
+ exports.createBN254Error = createBN254Error;
1614
+ exports.createPhotonRpc = createPhotonRpc;
1615
+ exports.createProofError = createProofError;
1616
+ exports.createRpcError = createRpcError;
1617
+ exports.createSystemAccountConfig = createSystemAccountConfig;
1618
+ exports.createSystemAccountConfigWithCpi = createSystemAccountConfigWithCpi;
1619
+ exports.createUtxoError = createUtxoError;
1620
+ exports.defaultStateTreeLookupTables = defaultStateTreeLookupTables;
1621
+ exports.defaultStaticAccounts = defaultStaticAccounts;
1622
+ exports.defaultTestStateTreeAccounts = defaultTestStateTreeAccounts;
1623
+ exports.deriveAddress = deriveAddress;
1624
+ exports.deriveAddressSeed = deriveAddressSeed;
1625
+ exports.deriveAddressSeedV2 = deriveAddressSeedV2;
1626
+ exports.deriveAddressV2 = deriveAddressV2;
1627
+ exports.encodeBN254toBase58 = encodeBN254toBase58;
1628
+ exports.encodeBN254toHex = encodeBN254toHex;
1629
+ exports.featureFlags = featureFlags;
1630
+ exports.getAccountCompressionAuthority = getAccountCompressionAuthority;
1631
+ exports.getCompressionAuthority = getAccountCompressionAuthority$1;
1632
+ exports.getCpiSignerPda = getCpiSignerPda;
1633
+ exports.getDefaultAddressTreeInfo = getDefaultAddressTreeInfo;
1634
+ exports.getIndexOrAdd = getIndexOrAdd;
1635
+ exports.getLightSystemAccountMetas = getLightSystemAccountMetas;
1636
+ exports.getLightSystemAccountMetasV2 = getLightSystemAccountMetasV2;
1637
+ exports.getSystemProgram = getSystemProgram;
1638
+ exports.hashToBn254FieldSizeBe = hashToBn254FieldSizeBe;
1639
+ exports.hashvToBn254FieldSizeBe = hashvToBn254FieldSizeBe;
1640
+ exports.hashvToBn254FieldSizeBeWithBump = hashvToBn254FieldSizeBeWithBump;
1641
+ exports.hexToBytes = hexToBytes;
1642
+ exports.isBN254 = isBN254;
1643
+ exports.isLocalTest = isLocalTest;
1644
+ exports.isSmallerThanFieldSize = isSmallerThanFieldSize;
1645
+ exports.localTestActiveStateTreeInfos = localTestActiveStateTreeInfos;
1646
+ exports.mergeBytes = mergeBytes;
1647
+ exports.packNewAddressParams = packNewAddressParams;
1648
+ exports.padBytes = padBytes;
1649
+ exports.pushUniqueItems = pushUniqueItems;
1650
+ exports.toArray = toArray;
1651
+ exports.toHex = toHex;
1652
+ exports.validateBN254Hash = validateBN254Hash;
1653
+ exports.versionedEndpoint = versionedEndpoint;