@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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":["v1Trees: TreeInfo[]","value: bigint","newAddressParamsPacked: NewAddressParamsPacked[]","getAccountCompressionAuthority","metas: AccountMeta[]","role: AccountRole","meta: AccountMeta","body: JsonRpcRequest","params: Record<string, string>","hexToBytes","proof: ValidityProof | null"],"sources":["../src/state/types.ts","../src/constants.ts","../src/errors.ts","../src/state/bn254.ts","../src/utils/conversion.ts","../src/utils/address.ts","../src/utils/instruction.ts","../src/rpc.ts"],"sourcesContent":["/**\n * Core types for Light Protocol stateless operations.\n *\n * Uses Solana Kit v5+ patterns:\n * - Address instead of PublicKey\n * - Native bigint instead of BN.js\n * - Branded types for type safety\n */\n\nimport type { Address } from \"@solana/kit\";\n\n// =============================================================================\n// Tree Types\n// =============================================================================\n\n/**\n * Tree type enum matching the on-chain representation.\n */\nexport enum TreeType {\n /** v1 state merkle tree */\n StateV1 = 1,\n /** v1 address merkle tree */\n AddressV1 = 2,\n /** v2 state merkle tree */\n StateV2 = 3,\n /** v2 address merkle tree */\n AddressV2 = 4,\n}\n\n/**\n * Tree info - metadata about a state or address tree.\n *\n * Used for:\n * - State trees: store compressed accounts\n * - Address trees: store PDAs\n */\nexport interface TreeInfo {\n /** Pubkey of the tree account */\n tree: Address;\n /** Pubkey of the queue account associated with the tree */\n queue: Address;\n /** The type of tree */\n treeType: TreeType;\n /** Optional compressed CPI context account */\n cpiContext?: Address;\n /** Next tree info if this tree is full/rolled over */\n nextTreeInfo: TreeInfo | null;\n}\n\n/**\n * @deprecated Use TreeInfo instead.\n */\nexport type StateTreeInfo = TreeInfo;\n\n/**\n * @deprecated Use TreeInfo instead.\n */\nexport type AddressTreeInfo = Omit<TreeInfo, \"cpiContext\" | \"nextTreeInfo\"> & {\n nextTreeInfo: AddressTreeInfo | null;\n};\n\n// =============================================================================\n// Merkle Context Types\n// =============================================================================\n\n/**\n * Packed merkle context for instruction data.\n */\nexport interface PackedMerkleContext {\n /** Merkle tree pubkey index in remaining accounts */\n merkleTreePubkeyIndex: number;\n /** Queue pubkey index in remaining accounts */\n queuePubkeyIndex: number;\n /** Leaf index in the tree */\n leafIndex: number;\n /** Whether to prove by index or validity proof */\n proveByIndex: boolean;\n}\n\n/**\n * Packed state tree info for compressed accounts.\n */\nexport interface PackedStateTreeInfo {\n /** Recent valid root index */\n rootIndex: number;\n /** Whether the account can be proven by index */\n proveByIndex: boolean;\n /** Index of the merkle tree in remaining accounts */\n merkleTreePubkeyIndex: number;\n /** Index of the queue in remaining accounts */\n queuePubkeyIndex: number;\n /** Index of the leaf in the state tree */\n leafIndex: number;\n}\n\n/**\n * Packed address tree info for new PDAs.\n */\nexport interface PackedAddressTreeInfo {\n /** Index of the address tree in remaining accounts */\n addressMerkleTreePubkeyIndex: number;\n /** Index of the address queue in remaining accounts */\n addressQueuePubkeyIndex: number;\n /** Recent valid root index */\n rootIndex: number;\n}\n\n// =============================================================================\n// Compressed Account Types\n// =============================================================================\n\n/**\n * Data attached to a compressed account.\n */\nexport interface CompressedAccountData {\n /** 8-byte discriminator */\n discriminator: Uint8Array;\n /** Account data */\n data: Uint8Array;\n /** 32-byte hash of the data */\n dataHash: Uint8Array;\n}\n\n/**\n * Merkle context for a compressed account.\n */\nexport interface MerkleContext {\n /** Tree info */\n treeInfo: TreeInfo;\n /** Poseidon hash of the account (stored as leaf) */\n hash: bigint;\n /** Position in the state tree */\n leafIndex: number;\n /** Whether the account can be proven by index */\n proveByIndex: boolean;\n}\n\n/**\n * Merkle context with full merkle proof.\n */\nexport interface MerkleContextWithProof extends MerkleContext {\n /** Merkle proof path */\n merkleProof: bigint[];\n /** Root index the proof is valid for */\n rootIndex: number;\n /** Current root */\n root: bigint;\n}\n\n/**\n * Compressed account with merkle context.\n */\nexport interface CompressedAccount extends MerkleContext {\n /** Owner program or user */\n owner: Address;\n /** Lamports attached to the account */\n lamports: bigint;\n /** Optional persistent address */\n address: Uint8Array | null;\n /** Optional account data */\n data: CompressedAccountData | null;\n /** Whether this account is read-only in the transaction */\n readOnly: boolean;\n}\n\n/**\n * Compressed account meta for instruction data.\n */\nexport interface CompressedAccountMeta {\n /** Packed tree info */\n treeInfo: PackedStateTreeInfo;\n /** Address (32 bytes or null) */\n address: Uint8Array | null;\n /** Lamports or null */\n lamports: bigint | null;\n /** Output state tree index */\n outputStateTreeIndex: number;\n}\n\n// =============================================================================\n// Proof Types\n// =============================================================================\n\n/**\n * Validity proof for compressed accounts.\n *\n * Proves existence of N compressed accounts or uniqueness of N PDAs.\n */\nexport interface ValidityProof {\n /** 32 bytes - G1 point x */\n a: Uint8Array;\n /** 64 bytes - G2 point */\n b: Uint8Array;\n /** 32 bytes - G1 point y */\n c: Uint8Array;\n}\n\n/**\n * Validity proof with context information.\n */\nexport interface ValidityProofWithContext {\n /** The proof (null if prove-by-index for all accounts) */\n compressedProof: ValidityProof | null;\n /** State roots */\n roots: bigint[];\n /** Root indices */\n rootIndices: number[];\n /** Leaf indices */\n leafIndices: number[];\n /** Leaf hashes */\n leaves: bigint[];\n /** Tree infos */\n treeInfos: TreeInfo[];\n /** Whether to prove by index for each account */\n proveByIndices: boolean[];\n}\n\n/**\n * Account proof input for validity proof request.\n */\nexport interface AccountProofInput {\n /** Account hash */\n hash: bigint;\n /** Tree info */\n treeInfo: TreeInfo;\n /** Leaf index */\n leafIndex: number;\n /** Root index */\n rootIndex: number;\n /** Whether to prove by index */\n proveByIndex: boolean;\n}\n\n/**\n * New address proof input for validity proof request.\n */\nexport interface NewAddressProofInput {\n /** Tree info */\n treeInfo: TreeInfo;\n /** Address bytes (32) */\n address: Uint8Array;\n /** Root index */\n rootIndex: number;\n /** Current root */\n root: bigint;\n}\n\n// =============================================================================\n// Token Types\n// =============================================================================\n\n/**\n * Compressed token data.\n */\nexport interface TokenData {\n /** Token mint */\n mint: Address;\n /** Token owner */\n owner: Address;\n /** Token amount */\n amount: bigint;\n /** Delegate (if any) */\n delegate: Address | null;\n /** Account state (0=uninitialized, 1=initialized, 2=frozen) */\n state: number;\n /** Token extension TLV data */\n tlv: Uint8Array | null;\n}\n\n/**\n * Parsed token account combining compressed account and token data.\n */\nexport interface ParsedTokenAccount {\n /** Compressed account */\n compressedAccount: CompressedAccount;\n /** Parsed token data */\n parsed: TokenData;\n}\n\n// =============================================================================\n// Instruction Types\n// =============================================================================\n\n/**\n * Compressed CPI context for multi-program transactions.\n */\nexport interface CompressedCpiContext {\n /** Whether to set the CPI context */\n setContext: boolean;\n /** Whether this is the first context set (wipes previous) */\n firstSetContext: boolean;\n /** Index of CPI context account in remaining accounts */\n cpiContextAccountIndex: number;\n}\n\n/**\n * New address parameters for creating PDAs.\n */\nexport interface NewAddressParams {\n /** Seed for address derivation */\n seed: Uint8Array;\n /** Root index for address tree */\n addressMerkleTreeRootIndex: number;\n /** Address tree pubkey */\n addressMerkleTreePubkey: Address;\n /** Address queue pubkey */\n addressQueuePubkey: Address;\n}\n\n/**\n * Packed new address parameters for instruction data.\n */\nexport interface NewAddressParamsPacked {\n /** Seed bytes */\n seed: Uint8Array;\n /** Address tree root index */\n addressMerkleTreeRootIndex: number;\n /** Index of address tree in remaining accounts */\n addressMerkleTreeAccountIndex: number;\n /** Index of address queue in remaining accounts */\n addressQueueAccountIndex: number;\n}\n","/**\n * Light Protocol constants using Solana Kit patterns.\n *\n * Uses:\n * - Address type (branded string) instead of PublicKey\n * - Native bigint instead of BN.js\n */\n\nimport { address, type Address, getProgramDerivedAddress } from \"@solana/kit\";\nimport { type TreeInfo, TreeType } from \"./state/types.js\";\n\n// =============================================================================\n// Protocol Version\n// =============================================================================\n\nexport enum VERSION {\n V1 = \"V1\",\n V2 = \"V2\",\n}\n\n/**\n * Feature flags for protocol versioning.\n * @internal\n */\nexport const featureFlags = {\n version: VERSION.V1 as VERSION,\n isV2: () => featureFlags.version === VERSION.V2,\n};\n\n/**\n * Returns versioned endpoint name.\n * @example versionedEndpoint('getCompressedAccount') -> 'getCompressedAccountV2' (if V2)\n */\nexport const versionedEndpoint = (base: string): string => (featureFlags.isV2() ? `${base}V2` : base);\n\n// =============================================================================\n// BN254 Field Constants\n// =============================================================================\n\n/**\n * BN254 prime field size.\n * All hashes must be less than this value for ZK circuit compatibility.\n */\nexport const FIELD_SIZE = 21888242871839275222246405745257275088548364400416034343698204186575808495617n;\n\n/**\n * Highest address plus one (used for address validation).\n */\nexport const HIGHEST_ADDRESS_PLUS_ONE = 452312848583266388373324160190187140051835877600158453279131187530910662655n;\n\n// =============================================================================\n// Program IDs\n// =============================================================================\n\n/** Light System Program ID */\nexport const LIGHT_SYSTEM_PROGRAM = address(\"SySTEM1eSU2p4BGQfQpimFEWWSC1XDFeun3Nqzz3rT7\");\n\n/** Account Compression Program ID */\nexport const ACCOUNT_COMPRESSION_PROGRAM = address(\"compr6CUsB5m2jS4Y3831ztGSTnDpnKJTKS95d64XVq\");\n\n/** Noop Program ID (for logging) */\nexport const NOOP_PROGRAM = address(\"noopb9bkMVfRPU8AsbpTUg8AQkHtKwMYZiFUjNRtMmV\");\n\n/** Compressed Token Program ID */\nexport const COMPRESSED_TOKEN_PROGRAM = address(\"cTokenmWW8bLPjZEBAUgYy3zKxQZW6VKi7bqNFEVv3m\");\n\n/** Registered Program PDA (constant) */\nexport const REGISTERED_PROGRAM_PDA = address(\"35hkDgaAKwMCaxRz2ocSZ6NaUrtKkyNqU6c4RV3tYJRh\");\n\n// =============================================================================\n// Instruction Discriminators\n// =============================================================================\n\nexport const INVOKE_DISCRIMINATOR = new Uint8Array([26, 16, 169, 7, 21, 202, 242, 25]);\n\nexport const INVOKE_CPI_DISCRIMINATOR = new Uint8Array([49, 212, 191, 129, 39, 194, 43, 196]);\n\nexport const INVOKE_CPI_WITH_READ_ONLY_DISCRIMINATOR = new Uint8Array([86, 47, 163, 166, 21, 223, 92, 8]);\n\nexport const INVOKE_CPI_WITH_ACCOUNT_INFO_DISCRIMINATOR = new Uint8Array([228, 34, 128, 84, 47, 139, 86, 240]);\n\nexport const INSERT_INTO_QUEUES_DISCRIMINATOR = new Uint8Array([180, 143, 159, 153, 35, 46, 248, 163]);\n\nexport const COMPUTE_BUDGET_PATTERN = new Uint8Array([2, 64, 66, 15, 0]);\n\n// =============================================================================\n// State Tree Lookup Tables\n// =============================================================================\n\n/** Mainnet state tree lookup table */\nexport const STATE_TREE_LOOKUP_TABLE_MAINNET = address(\"7i86eQs3GSqHjN47WdWLTCGMW6gde1q96G2EVnUyK2st\");\n\n/** Mainnet nullified state tree lookup table */\nexport const NULLIFIED_STATE_TREE_LOOKUP_TABLE_MAINNET = address(\"H9QD4u1fG7KmkAzn2tDXhheushxFe1EcrjGGyEFXeMqT\");\n\n/** Devnet state tree lookup table */\nexport const STATE_TREE_LOOKUP_TABLE_DEVNET = address(\"Dk9mNkbiZXJZ4By8DfSP6HEE4ojZzRvucwpawLeuwq8q\");\n\n/** Devnet nullified state tree lookup table */\nexport const NULLIFIED_STATE_TREE_LOOKUP_TABLE_DEVNET = address(\"AXbHzp1NgjLvpfnD6JRTTovXZ7APUCdtWZFCRr5tCxse\");\n\nexport interface StateTreeLUTPair {\n stateTreeLookupTable: Address;\n nullifyLookupTable: Address;\n}\n\n/**\n * Returns default state tree lookup tables for each network.\n */\nexport function defaultStateTreeLookupTables(): {\n mainnet: StateTreeLUTPair[];\n devnet: StateTreeLUTPair[];\n} {\n return {\n mainnet: [\n {\n stateTreeLookupTable: STATE_TREE_LOOKUP_TABLE_MAINNET,\n nullifyLookupTable: NULLIFIED_STATE_TREE_LOOKUP_TABLE_MAINNET,\n },\n ],\n devnet: [\n {\n stateTreeLookupTable: STATE_TREE_LOOKUP_TABLE_DEVNET,\n nullifyLookupTable: NULLIFIED_STATE_TREE_LOOKUP_TABLE_DEVNET,\n },\n ],\n };\n}\n\n// =============================================================================\n// Test Tree Accounts (Localnet)\n// =============================================================================\n\n// V1 State Trees\nexport const MERKLE_TREE_PUBKEY = address(\"smt1NamzXdq4AMqS2fS2F1i5KTYPZRhoHgWx38d8WsT\");\nexport const NULLIFIER_QUEUE_PUBKEY = address(\"nfq1NvQDJ2GEgnS8zt9prAe8rjjpAW1zFkrvZoBR148\");\nexport const CPI_CONTEXT_PUBKEY = address(\"cpi1uHzrEhBG733DoEJNgHCyRS3XmmyVNZx5fonubE4\");\n\nexport const MERKLE_TREE_2_PUBKEY = address(\"smt2rJAFdyJJupwMKAqTNAJwvjhmiZ4JYGZmbVRw1Ho\");\nexport const NULLIFIER_QUEUE_2_PUBKEY = address(\"nfq2hgS7NYemXsFaFUCe3EMXSDSfnZnAe27jC6aPP1X\");\nexport const CPI_CONTEXT_2_PUBKEY = address(\"cpi2cdhkH5roePvcudTgUL8ppEBfTay1desGh8G8QxK\");\n\n// V1 Address Trees\nexport const ADDRESS_TREE = address(\"amt1Ayt45jfbdw5YSo7iz6WZxUmnZsQTYXy82hVwyC2\");\nexport const ADDRESS_QUEUE = address(\"aq1S9z4reTSQAdgWHGD2zDaS39sjGrAxbR31vxJ2F4F\");\n\n// V2 Batch State Trees\nexport const BATCH_MERKLE_TREE_1 = address(\"bmt1LryLZUMmF7ZtqESaw7wifBXLfXHQYoE4GAmrahU\");\nexport const BATCH_QUEUE_1 = address(\"oq1na8gojfdUhsfCpyjNt6h4JaDWtHf1yQj4koBWfto\");\nexport const BATCH_CPI_CONTEXT_1 = address(\"cpi15BoVPKgEPw5o8wc2T816GE7b378nMXnhH3Xbq4y\");\n\nexport const BATCH_MERKLE_TREE_2 = address(\"bmt2UxoBxB9xWev4BkLvkGdapsz6sZGkzViPNph7VFi\");\nexport const BATCH_QUEUE_2 = address(\"oq2UkeMsJLfXt2QHzim242SUi3nvjJs8Pn7Eac9H9vg\");\nexport const BATCH_CPI_CONTEXT_2 = address(\"cpi2yGapXUR3As5SjnHBAVvmApNiLsbeZpF3euWnW6B\");\n\n// V2 Address Trees\nexport const BATCH_ADDRESS_TREE = address(\"amt2kaJA14v3urZbZvnc5v2np8jqvc4Z8zDep5wbtzx\");\nexport const TEST_BATCH_ADDRESS_TREE = address(\"EzKE84aVTkCUhDHLELqyJaq1Y7UVVmqxXqZjVHwHY3rK\");\n\n// =============================================================================\n// Tree Configuration\n// =============================================================================\n\nexport const DEFAULT_MERKLE_TREE_HEIGHT = 26;\nexport const DEFAULT_MERKLE_TREE_ROOTS = 2800;\n\n/** Threshold for UTXO merging (per asset) */\nexport const UTXO_MERGE_THRESHOLD = 20;\nexport const UTXO_MERGE_MAXIMUM = 10;\n\n/** Tree rollover threshold (95% capacity) */\nexport const TRANSACTION_MERKLE_TREE_ROLLOVER_THRESHOLD = BigInt(Math.floor(2 ** DEFAULT_MERKLE_TREE_HEIGHT * 0.95));\n\n// =============================================================================\n// Fees\n// =============================================================================\n\n/** Fee per output compressed account (for tree rollover) */\nexport const STATE_MERKLE_TREE_ROLLOVER_FEE = featureFlags.isV2() ? 1n : 300n;\n\n/** Fee per new address (for address tree rollover) */\nexport const ADDRESS_QUEUE_ROLLOVER_FEE = 392n;\n\n/** Network fee for nullifying compressed accounts */\nexport const STATE_MERKLE_TREE_NETWORK_FEE = 5000n;\n\n/** V1 network fee per new address */\nexport const ADDRESS_TREE_NETWORK_FEE_V1 = 5000n;\n\n/** V2 network fee per new address */\nexport const ADDRESS_TREE_NETWORK_FEE_V2 = 10000n;\n\n// =============================================================================\n// Helper Functions\n// =============================================================================\n\n/**\n * Derives the account compression authority PDA.\n */\nexport async function getAccountCompressionAuthority(): Promise<Address> {\n const [pda] = await getProgramDerivedAddress({\n programAddress: LIGHT_SYSTEM_PROGRAM,\n seeds: [new TextEncoder().encode(\"cpi_authority\")],\n });\n return pda;\n}\n\n/**\n * Returns static accounts needed for Light System Program calls.\n */\nexport async function defaultStaticAccounts(): Promise<Address[]> {\n const authority = await getAccountCompressionAuthority();\n return [REGISTERED_PROGRAM_PDA, NOOP_PROGRAM, ACCOUNT_COMPRESSION_PROGRAM, authority];\n}\n\n/**\n * Check if URL is localhost/localnet.\n * @internal\n */\nexport function isLocalTest(url: string): boolean {\n return url.includes(\"localhost\") || url.includes(\"127.0.0.1\");\n}\n\n/**\n * Returns default test state tree accounts for localnet.\n */\nexport function defaultTestStateTreeAccounts(): {\n nullifierQueue: Address;\n merkleTree: Address;\n merkleTreeHeight: number;\n addressTree: Address;\n addressQueue: Address;\n} {\n return {\n nullifierQueue: NULLIFIER_QUEUE_PUBKEY,\n merkleTree: MERKLE_TREE_PUBKEY,\n merkleTreeHeight: DEFAULT_MERKLE_TREE_HEIGHT,\n addressTree: ADDRESS_TREE,\n addressQueue: ADDRESS_QUEUE,\n };\n}\n\n/**\n * Returns active state tree infos for localnet testing.\n * @internal\n */\nexport function localTestActiveStateTreeInfos(): TreeInfo[] {\n const v1Trees: TreeInfo[] = [\n {\n tree: MERKLE_TREE_PUBKEY,\n queue: NULLIFIER_QUEUE_PUBKEY,\n cpiContext: CPI_CONTEXT_PUBKEY,\n treeType: TreeType.StateV1,\n nextTreeInfo: null,\n },\n {\n tree: MERKLE_TREE_2_PUBKEY,\n queue: NULLIFIER_QUEUE_2_PUBKEY,\n cpiContext: CPI_CONTEXT_2_PUBKEY,\n treeType: TreeType.StateV1,\n nextTreeInfo: null,\n },\n ];\n\n if (!featureFlags.isV2()) {\n return v1Trees;\n }\n\n // V2 includes batch trees\n return [\n ...v1Trees,\n {\n tree: BATCH_MERKLE_TREE_1,\n queue: BATCH_QUEUE_1,\n cpiContext: BATCH_CPI_CONTEXT_1,\n treeType: TreeType.StateV2,\n nextTreeInfo: null,\n },\n {\n tree: BATCH_MERKLE_TREE_2,\n queue: BATCH_QUEUE_2,\n cpiContext: BATCH_CPI_CONTEXT_2,\n treeType: TreeType.StateV2,\n nextTreeInfo: null,\n },\n {\n tree: BATCH_ADDRESS_TREE,\n queue: BATCH_ADDRESS_TREE, // V2 address queue is part of tree account\n treeType: TreeType.AddressV2,\n nextTreeInfo: null,\n },\n ];\n}\n\n/**\n * Returns default address tree info.\n */\nexport function getDefaultAddressTreeInfo(): TreeInfo {\n if (featureFlags.isV2()) {\n return {\n tree: BATCH_ADDRESS_TREE,\n queue: BATCH_ADDRESS_TREE,\n treeType: TreeType.AddressV2,\n nextTreeInfo: null,\n };\n }\n return {\n tree: ADDRESS_TREE,\n queue: ADDRESS_QUEUE,\n treeType: TreeType.AddressV1,\n nextTreeInfo: null,\n };\n}\n","/**\n * Error types for Light Protocol stateless operations.\n */\n\n// =============================================================================\n// Error Codes\n// =============================================================================\n\nexport enum UtxoErrorCode {\n NEGATIVE_LAMPORTS = \"NEGATIVE_LAMPORTS\",\n NOT_U64 = \"NOT_U64\",\n BLINDING_EXCEEDS_FIELD_SIZE = \"BLINDING_EXCEEDS_FIELD_SIZE\",\n}\n\nexport enum SelectInUtxosErrorCode {\n FAILED_TO_FIND_UTXO_COMBINATION = \"FAILED_TO_FIND_UTXO_COMBINATION\",\n INVALID_NUMBER_OF_IN_UTXOS = \"INVALID_NUMBER_OF_IN_UTXOS\",\n}\n\nexport enum CreateUtxoErrorCode {\n OWNER_UNDEFINED = \"OWNER_UNDEFINED\",\n INVALID_OUTPUT_UTXO_LENGTH = \"INVALID_OUTPUT_UTXO_LENGTH\",\n UTXO_DATA_UNDEFINED = \"UTXO_DATA_UNDEFINED\",\n}\n\nexport enum RpcErrorCode {\n CONNECTION_UNDEFINED = \"CONNECTION_UNDEFINED\",\n RPC_PUBKEY_UNDEFINED = \"RPC_PUBKEY_UNDEFINED\",\n RPC_METHOD_NOT_IMPLEMENTED = \"RPC_METHOD_NOT_IMPLEMENTED\",\n RPC_INVALID = \"RPC_INVALID\",\n}\n\nexport enum LookupTableErrorCode {\n LOOK_UP_TABLE_UNDEFINED = \"LOOK_UP_TABLE_UNDEFINED\",\n LOOK_UP_TABLE_NOT_INITIALIZED = \"LOOK_UP_TABLE_NOT_INITIALIZED\",\n}\n\nexport enum HashErrorCode {\n NO_POSEIDON_HASHER_PROVIDED = \"NO_POSEIDON_HASHER_PROVIDED\",\n}\n\nexport enum ProofErrorCode {\n INVALID_PROOF = \"INVALID_PROOF\",\n PROOF_INPUT_UNDEFINED = \"PROOF_INPUT_UNDEFINED\",\n PROOF_GENERATION_FAILED = \"PROOF_GENERATION_FAILED\",\n}\n\nexport enum MerkleTreeErrorCode {\n MERKLE_TREE_NOT_INITIALIZED = \"MERKLE_TREE_NOT_INITIALIZED\",\n SOL_MERKLE_TREE_UNDEFINED = \"SOL_MERKLE_TREE_UNDEFINED\",\n MERKLE_TREE_UNDEFINED = \"MERKLE_TREE_UNDEFINED\",\n INPUT_UTXO_NOT_INSERTED_IN_MERKLE_TREE = \"INPUT_UTXO_NOT_INSERTED_IN_MERKLE_TREE\",\n MERKLE_TREE_INDEX_UNDEFINED = \"MERKLE_TREE_INDEX_UNDEFINED\",\n MERKLE_TREE_SET_SPACE_UNDEFINED = \"MERKLE_TREE_SET_SPACE_UNDEFINED\",\n}\n\nexport enum UtilsErrorCode {\n ACCOUNT_NAME_UNDEFINED_IN_IDL = \"ACCOUNT_NAME_UNDEFINED_IN_IDL\",\n PROPERTY_UNDEFINED = \"PROPERTY_UNDEFINED\",\n LOOK_UP_TABLE_CREATION_FAILED = \"LOOK_UP_TABLE_CREATION_FAILED\",\n UNSUPPORTED_ARCHITECTURE = \"UNSUPPORTED_ARCHITECTURE\",\n UNSUPPORTED_PLATFORM = \"UNSUPPORTED_PLATFORM\",\n ACCOUNTS_UNDEFINED = \"ACCOUNTS_UNDEFINED\",\n INVALID_NUMBER = \"INVALID_NUMBER\",\n}\n\nexport enum BN254ErrorCode {\n VALUE_TOO_LARGE = \"VALUE_TOO_LARGE\",\n INVALID_BASE58 = \"INVALID_BASE58\",\n}\n\n// =============================================================================\n// Error Classes\n// =============================================================================\n\n/**\n * Base error class for Light Protocol errors.\n */\nclass LightError extends Error {\n readonly code: string;\n readonly functionName: string;\n readonly codeMessage?: string;\n\n constructor(code: string, functionName: string, codeMessage?: string) {\n super(`${code}: ${codeMessage ?? \"\"}`);\n this.name = this.constructor.name;\n this.code = code;\n this.functionName = functionName;\n this.codeMessage = codeMessage;\n }\n}\n\nexport class UtxoError extends LightError {}\nexport class SelectInUtxosError extends LightError {}\nexport class CreateUtxoError extends LightError {}\nexport class RpcError extends LightError {}\nexport class LookupTableError extends LightError {}\nexport class HashError extends LightError {}\nexport class ProofError extends LightError {}\nexport class MerkleTreeError extends LightError {}\nexport class UtilsError extends LightError {}\nexport class BN254Error extends LightError {}\n\n// =============================================================================\n// Error Factory Functions\n// =============================================================================\n\nexport function createUtxoError(code: UtxoErrorCode, functionName: string, message?: string): UtxoError {\n return new UtxoError(code, functionName, message);\n}\n\nexport function createRpcError(code: RpcErrorCode, functionName: string, message?: string): RpcError {\n return new RpcError(code, functionName, message);\n}\n\nexport function createProofError(code: ProofErrorCode, functionName: string, message?: string): ProofError {\n return new ProofError(code, functionName, message);\n}\n\nexport function createBN254Error(code: BN254ErrorCode, functionName: string, message?: string): BN254Error {\n return new BN254Error(code, functionName, message);\n}\n","/**\n * BN254 field element utilities using native bigint.\n *\n * BN254 is the elliptic curve used by Light Protocol's ZK proofs.\n * All hashes must be less than the field modulus (~2^254) for circuit compatibility.\n *\n * This module replaces BN.js with native bigint for:\n * - Better performance\n * - No Node.js Buffer dependency\n * - Edge/browser compatibility\n */\n\nimport bs58 from \"bs58\";\nimport { FIELD_SIZE } from \"../constants.js\";\nimport { BN254ErrorCode, createBN254Error } from \"../errors.js\";\n\n// =============================================================================\n// Type Definitions\n// =============================================================================\n\n/**\n * BN254 field element type.\n *\n * This is a bigint that is guaranteed to be less than the BN254 field modulus.\n * While we can't enforce this at the type level with branded types (since bigint\n * operations return plain bigint), we validate at creation time.\n */\nexport type BN254 = bigint;\n\n// =============================================================================\n// Validation\n// =============================================================================\n\n/**\n * Check if a bigint is within the BN254 field.\n */\nexport function isBN254(value: bigint): boolean {\n return value >= 0n && value < FIELD_SIZE;\n}\n\n/**\n * Assert that a bigint is within the BN254 field.\n * @throws BN254Error if value is out of range\n */\nexport function assertIsBN254(value: bigint): asserts value is BN254 {\n if (!isBN254(value)) {\n throw createBN254Error(BN254ErrorCode.VALUE_TOO_LARGE, \"assertIsBN254\", `Value ${value} exceeds BN254 field size`);\n }\n}\n\n/**\n * Enforce BN254 field size constraint.\n * @throws BN254Error if value is out of range\n */\nfunction enforceFieldSize(value: bigint): BN254 {\n assertIsBN254(value);\n return value;\n}\n\n// =============================================================================\n// Creation Functions\n// =============================================================================\n\n/**\n * Create a BN254 field element from various input types.\n *\n * @param input - Number, string, bigint, or byte array\n * @param base - Optional base for string parsing: 10, 16, 'hex', or 'base58'\n * @returns BN254 field element\n * @throws BN254Error if value exceeds field size\n */\nexport function createBN254(\n input: string | number | bigint | Uint8Array | number[],\n base?: number | \"hex\" | \"base58\",\n): BN254 {\n let value: bigint;\n\n if (base === \"base58\") {\n if (typeof input !== \"string\") {\n throw createBN254Error(BN254ErrorCode.INVALID_BASE58, \"createBN254\", \"Base58 input must be a string\");\n }\n const bytes = bs58.decode(input);\n value = bytesToBigIntBE(bytes);\n } else if (typeof input === \"bigint\") {\n value = input;\n } else if (typeof input === \"number\") {\n value = BigInt(input);\n } else if (typeof input === \"string\") {\n if (base === \"hex\" || base === 16) {\n const cleanHex = input.startsWith(\"0x\") ? input.slice(2) : input;\n value = BigInt(`0x${cleanHex}`);\n } else {\n // Default to decimal\n value = BigInt(input);\n }\n } else if (input instanceof Uint8Array || Array.isArray(input)) {\n const bytes = input instanceof Uint8Array ? input : new Uint8Array(input);\n value = bytesToBigIntBE(bytes);\n } else {\n throw createBN254Error(BN254ErrorCode.VALUE_TOO_LARGE, \"createBN254\", `Unsupported input type: ${typeof input}`);\n }\n\n return enforceFieldSize(value);\n}\n\n/**\n * Create a BN254 from a 32-byte array (big-endian).\n */\nexport function bn254FromBytes(bytes: Uint8Array): BN254 {\n if (bytes.length !== 32) {\n throw createBN254Error(BN254ErrorCode.VALUE_TOO_LARGE, \"bn254FromBytes\", `Expected 32 bytes, got ${bytes.length}`);\n }\n return createBN254(bytes);\n}\n\n// =============================================================================\n// Conversion Functions\n// =============================================================================\n\n/**\n * Convert a BN254 field element to a base58 string.\n */\nexport function encodeBN254toBase58(value: BN254): string {\n const bytes = bigIntToBytesBE(value, 32);\n return bs58.encode(bytes);\n}\n\n/**\n * Convert a BN254 field element to a hex string (with 0x prefix).\n */\nexport function encodeBN254toHex(value: BN254): string {\n return `0x${value.toString(16).padStart(64, \"0\")}`;\n}\n\n/**\n * Convert a BN254 field element to a 32-byte array (big-endian).\n */\nexport function bn254ToBytes(value: BN254): Uint8Array {\n return bigIntToBytesBE(value, 32);\n}\n\n/**\n * Convert a BN254 field element to a decimal string.\n */\nexport function bn254ToDecimalString(value: BN254): string {\n return value.toString(10);\n}\n\n// =============================================================================\n// Byte Array Utilities\n// =============================================================================\n\n/**\n * Convert bytes to bigint (big-endian).\n */\nexport function bytesToBigIntBE(bytes: Uint8Array): bigint {\n let result = 0n;\n for (const byte of bytes) {\n result = (result << 8n) | BigInt(byte);\n }\n return result;\n}\n\n/**\n * Convert bytes to bigint (little-endian).\n */\nexport function bytesToBigIntLE(bytes: Uint8Array): bigint {\n let result = 0n;\n for (let i = bytes.length - 1; i >= 0; i--) {\n result = (result << 8n) | BigInt(bytes[i]);\n }\n return result;\n}\n\n/**\n * Convert bigint to bytes (big-endian).\n */\nexport function bigIntToBytesBE(value: bigint, length: number): Uint8Array {\n const bytes = new Uint8Array(length);\n let remaining = value;\n for (let i = length - 1; i >= 0; i--) {\n bytes[i] = Number(remaining & 0xffn);\n remaining >>= 8n;\n }\n return bytes;\n}\n\n/**\n * Convert bigint to bytes (little-endian).\n */\nexport function bigIntToBytesLE(value: bigint, length: number): Uint8Array {\n const bytes = new Uint8Array(length);\n let remaining = value;\n for (let i = 0; i < length; i++) {\n bytes[i] = Number(remaining & 0xffn);\n remaining >>= 8n;\n }\n return bytes;\n}\n\n// =============================================================================\n// Arithmetic Helpers (for field operations if needed)\n// =============================================================================\n\n/**\n * Add two BN254 values with modular reduction.\n */\nexport function bn254Add(a: BN254, b: BN254): BN254 {\n return (a + b) % FIELD_SIZE;\n}\n\n/**\n * Subtract two BN254 values with modular reduction.\n */\nexport function bn254Sub(a: BN254, b: BN254): BN254 {\n const result = (a - b) % FIELD_SIZE;\n return result < 0n ? result + FIELD_SIZE : result;\n}\n\n/**\n * Multiply two BN254 values with modular reduction.\n */\nexport function bn254Mul(a: BN254, b: BN254): BN254 {\n return (a * b) % FIELD_SIZE;\n}\n\n/**\n * Check if a value is smaller than the BN254 field size (big-endian bytes).\n */\nexport function isSmallerThanFieldSize(bytes: Uint8Array): boolean {\n const value = bytesToBigIntBE(bytes);\n return value < FIELD_SIZE;\n}\n","/**\n * Conversion and hashing utilities for Light Protocol.\n *\n * Uses @noble/hashes for Keccak256 - pure JS, works in all environments.\n */\n\nimport { keccak_256 } from \"@noble/hashes/sha3.js\";\nimport { bytesToBigIntBE, isSmallerThanFieldSize } from \"../state/bn254.js\";\n\n// =============================================================================\n// Hash Functions\n// =============================================================================\n\n/**\n * Hash multiple byte arrays with Keccak256 and truncate to BN254 field size.\n *\n * This is the primary hash function used by Light Protocol. It:\n * 1. Concatenates all input arrays\n * 2. Hashes with Keccak256\n * 3. Sets the first byte to 0 to ensure the result fits in BN254 field\n *\n * @param inputs - Array of byte arrays to hash\n * @returns 32-byte hash that fits in BN254 field\n */\nexport function hashvToBn254FieldSizeBe(inputs: Uint8Array[]): Uint8Array {\n const hasher = keccak_256.create();\n for (const input of inputs) {\n hasher.update(input);\n }\n const hash = hasher.digest();\n // Truncate to 31 bytes by zeroing the first byte\n hash[0] = 0;\n return hash;\n}\n\n/**\n * Hash multiple byte arrays with Keccak256, appending 0xFF bump seed.\n *\n * This variant appends a 255 bump seed before hashing, matching the\n * on-chain behavior for certain hash derivations.\n *\n * @param inputs - Array of byte arrays to hash\n * @returns 32-byte hash that fits in BN254 field\n */\nexport function hashvToBn254FieldSizeBeWithBump(inputs: Uint8Array[]): Uint8Array {\n const hasher = keccak_256.create();\n for (const input of inputs) {\n hasher.update(input);\n }\n hasher.update(new Uint8Array([255]));\n const hash = hasher.digest();\n hash[0] = 0;\n return hash;\n}\n\n/**\n * Hash bytes with Keccak256 and find a valid bump seed.\n *\n * @deprecated Use hashvToBn254FieldSizeBe instead.\n *\n * This function iterates through bump seeds (255 down to 0) to find one\n * that produces a hash smaller than the BN254 field size. This is the\n * legacy approach - the simpler truncation method is now preferred.\n *\n * @param bytes - Bytes to hash\n * @returns Tuple of [hash, bumpSeed] or null if no valid bump found\n */\nexport function hashToBn254FieldSizeBe(bytes: Uint8Array): [Uint8Array, number] | null {\n let bumpSeed = 255;\n while (bumpSeed >= 0) {\n const inputWithBump = new Uint8Array(bytes.length + 1);\n inputWithBump.set(bytes);\n inputWithBump[bytes.length] = bumpSeed;\n\n const hash = keccak_256(inputWithBump);\n if (hash.length !== 32) {\n throw new Error(\"Invalid hash length\");\n }\n hash[0] = 0;\n\n if (isSmallerThanFieldSize(hash)) {\n return [hash, bumpSeed];\n }\n bumpSeed--;\n }\n return null;\n}\n\n// =============================================================================\n// Byte/Hex Conversion\n// =============================================================================\n\n/**\n * Convert hex string to bytes.\n */\nexport function hexToBytes(hex: string): Uint8Array {\n const cleanHex = hex.startsWith(\"0x\") ? hex.slice(2) : hex;\n if (cleanHex.length % 2 !== 0) {\n throw new Error(\"Invalid hex string length\");\n }\n const bytes = new Uint8Array(cleanHex.length / 2);\n for (let i = 0; i < bytes.length; i++) {\n bytes[i] = parseInt(cleanHex.slice(i * 2, i * 2 + 2), 16);\n }\n return bytes;\n}\n\n/**\n * Convert bytes to hex string (no 0x prefix).\n */\nexport function bytesToHex(bytes: Uint8Array): string {\n return Array.from(bytes)\n .map((b) => b.toString(16).padStart(2, \"0\"))\n .join(\"\");\n}\n\n/**\n * Convert bigint to hex string with 0x prefix.\n */\nexport function toHex(value: bigint): string {\n return `0x${value.toString(16)}`;\n}\n\n// =============================================================================\n// Array Utilities\n// =============================================================================\n\n/**\n * Ensure value is an array.\n */\nexport function toArray<T>(value: T | T[]): T[] {\n return Array.isArray(value) ? value : [value];\n}\n\n/**\n * Merge bytes arrays into one.\n */\nexport function mergeBytes(arrays: Uint8Array[]): Uint8Array {\n const totalLength = arrays.reduce((acc, arr) => acc + arr.length, 0);\n const result = new Uint8Array(totalLength);\n let offset = 0;\n for (const arr of arrays) {\n result.set(arr, offset);\n offset += arr.length;\n }\n return result;\n}\n\n/**\n * Compare two byte arrays for equality.\n */\nexport function bytesEqual(a: Uint8Array, b: Uint8Array): boolean {\n if (a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) {\n if (a[i] !== b[i]) return false;\n }\n return true;\n}\n\n/**\n * Pad bytes to a fixed length (right-pad with zeros).\n */\nexport function padBytes(bytes: Uint8Array, length: number): Uint8Array {\n if (bytes.length >= length) return bytes;\n const result = new Uint8Array(length);\n result.set(bytes);\n return result;\n}\n\n/**\n * Push unique items to an array.\n * Mutates the array in place.\n */\nexport function pushUniqueItems<T>(items: T[], target: T[]): void {\n for (const item of items) {\n if (!target.includes(item)) {\n target.push(item);\n }\n }\n}\n\n// =============================================================================\n// Decimal String Conversion\n// =============================================================================\n\n/**\n * Convert bytes to decimal string (for ZK circuit compatibility).\n */\nexport function bytesToDecimalString(bytes: Uint8Array): string {\n return bytesToBigIntBE(bytes).toString(10);\n}\n\n// =============================================================================\n// Validation\n// =============================================================================\n\n/**\n * Validate that a hash value is within BN254 field size.\n */\nexport function validateBN254Hash(hash: Uint8Array): boolean {\n if (hash.length !== 32) return false;\n return isSmallerThanFieldSize(hash);\n}\n\n/**\n * Assert hash is valid BN254 field element.\n */\nexport function assertValidBN254Hash(hash: Uint8Array): void {\n if (!validateBN254Hash(hash)) {\n throw new Error(`Invalid BN254 hash: must be 32 bytes and less than field size`);\n }\n}\n","/**\n * Address derivation utilities for Light Protocol.\n *\n * Light Protocol uses a custom address derivation scheme that produces\n * addresses within the BN254 field for ZK circuit compatibility.\n */\n\nimport { address, type Address, getAddressEncoder } from \"@solana/kit\";\nimport bs58 from \"bs58\";\nimport { defaultTestStateTreeAccounts } from \"../constants.js\";\nimport {\n hashvToBn254FieldSizeBe,\n hashvToBn254FieldSizeBeWithBump,\n hashToBn254FieldSizeBe,\n mergeBytes,\n} from \"./conversion.js\";\nimport type { NewAddressParams, NewAddressParamsPacked } from \"../state/types.js\";\n\n// =============================================================================\n// Address Derivation\n// =============================================================================\n\n/**\n * Derive an address seed from seeds and program ID.\n *\n * This combines the program ID with user-provided seeds and hashes\n * them to produce a 32-byte seed suitable for address derivation.\n *\n * @param seeds - User-provided seed bytes\n * @param programId - The program ID that \"owns\" this address\n * @returns 32-byte address seed\n */\nexport function deriveAddressSeed(seeds: Uint8Array[], programId: Address): Uint8Array {\n const encoder = getAddressEncoder();\n const programIdBytes = Uint8Array.from(encoder.encode(programId));\n const combinedSeeds: Uint8Array[] = [programIdBytes, ...seeds];\n return hashvToBn254FieldSizeBe(combinedSeeds);\n}\n\n/**\n * Derive a compressed account address from a seed and address tree.\n *\n * @param seed - 32-byte seed (typically from deriveAddressSeed)\n * @param addressMerkleTreePubkey - The address tree to derive from\n * @returns Derived address as a Solana Address\n *\n * @example\n * ```typescript\n * import { deriveAddressSeed, deriveAddress } from '@cascade-fyi/compression-kit';\n * import { address } from '@solana/kit';\n *\n * const programId = address('YourProgramId...');\n * const seed = deriveAddressSeed([new TextEncoder().encode('my-seed')], programId);\n * const compressedAddress = deriveAddress(seed);\n * ```\n */\nexport function deriveAddress(seed: Uint8Array, addressMerkleTreePubkey?: Address): Address {\n if (seed.length !== 32) {\n throw new Error(\"Seed length must be 32 bytes\");\n }\n\n const treePubkey = addressMerkleTreePubkey ?? defaultTestStateTreeAccounts().addressTree;\n const encoder = getAddressEncoder();\n const treeBytes = Uint8Array.from(encoder.encode(treePubkey));\n\n const combined = mergeBytes([treeBytes, seed]);\n const hashResult = hashToBn254FieldSizeBe(combined);\n\n if (hashResult === null) {\n throw new Error(\"DeriveAddressError: Failed to find valid bump seed\");\n }\n\n const [hash] = hashResult;\n return address(bs58.encode(hash));\n}\n\n/**\n * Derive address seed using V2 method (no program ID in combined seeds).\n *\n * @param seeds - Seeds to hash together\n * @returns 32-byte address seed\n */\nexport function deriveAddressSeedV2(seeds: Uint8Array[]): Uint8Array {\n return hashvToBn254FieldSizeBeWithBump(seeds);\n}\n\n/**\n * Derive address using V2 method (matches Rust derive_address_from_seed).\n *\n * @param addressSeed - 32-byte address seed\n * @param addressMerkleTreePubkey - Address tree pubkey\n * @param programId - Program ID\n * @returns Derived address\n */\nexport function deriveAddressV2(\n addressSeed: Uint8Array,\n addressMerkleTreePubkey: Address,\n programId: Address,\n): Address {\n if (addressSeed.length !== 32) {\n throw new Error(\"Address seed length must be 32 bytes\");\n }\n\n const encoder = getAddressEncoder();\n const merkleTreeBytes = Uint8Array.from(encoder.encode(addressMerkleTreePubkey));\n const programIdBytes = Uint8Array.from(encoder.encode(programId));\n\n // Match Rust: hash [seed, merkle_tree_pubkey, program_id]\n const combined: Uint8Array[] = [addressSeed, merkleTreeBytes, programIdBytes];\n const hash = hashvToBn254FieldSizeBeWithBump(combined);\n\n return address(bs58.encode(hash));\n}\n\n// =============================================================================\n// Address Packing for Instructions\n// =============================================================================\n\n/**\n * Get the index of an address in an array, adding it if not present.\n */\nexport function getIndexOrAdd(accounts: Address[], pubkey: Address): number {\n const existingIndex = accounts.indexOf(pubkey);\n if (existingIndex !== -1) {\n return existingIndex;\n }\n accounts.push(pubkey);\n return accounts.length - 1;\n}\n\n/**\n * Pack new address params for instruction data.\n *\n * Converts NewAddressParams to NewAddressParamsPacked by replacing\n * pubkeys with their indices in the remaining accounts array.\n *\n * @param newAddressParams - Array of new address parameters\n * @param remainingAccounts - Existing remaining accounts (will be modified)\n * @returns Packed params and updated remaining accounts\n */\nexport function packNewAddressParams(\n newAddressParams: NewAddressParams[],\n remainingAccounts: Address[],\n): {\n newAddressParamsPacked: NewAddressParamsPacked[];\n remainingAccounts: Address[];\n} {\n const accounts = [...remainingAccounts];\n\n const newAddressParamsPacked: NewAddressParamsPacked[] = newAddressParams.map((params) => ({\n seed: params.seed,\n addressMerkleTreeRootIndex: params.addressMerkleTreeRootIndex,\n addressMerkleTreeAccountIndex: 0, // Will be assigned below\n addressQueueAccountIndex: 0, // Will be assigned below\n }));\n\n // Assign tree indices\n for (let i = 0; i < newAddressParams.length; i++) {\n newAddressParamsPacked[i].addressMerkleTreeAccountIndex = getIndexOrAdd(\n accounts,\n newAddressParams[i].addressMerkleTreePubkey,\n );\n }\n\n // Assign queue indices\n for (let i = 0; i < newAddressParams.length; i++) {\n newAddressParamsPacked[i].addressQueueAccountIndex = getIndexOrAdd(\n accounts,\n newAddressParams[i].addressQueuePubkey,\n );\n }\n\n return { newAddressParamsPacked, remainingAccounts: accounts };\n}\n\n// =============================================================================\n// Address Utilities\n// =============================================================================\n\n/**\n * Convert an address to bytes.\n */\nexport function addressToBytes(addr: Address): Uint8Array {\n const encoder = getAddressEncoder();\n return Uint8Array.from(encoder.encode(addr));\n}\n\n/**\n * Convert bytes to an address.\n *\n * Note: This performs base58 encoding on the bytes. The bytes should\n * be a valid 32-byte representation of an address.\n */\nexport function bytesToAddress(bytes: Uint8Array): Address {\n if (bytes.length !== 32) {\n throw new Error(\"Address must be 32 bytes\");\n }\n return address(bs58.encode(bytes));\n}\n","/**\n * Instruction building utilities for Light Protocol.\n *\n * Uses Solana Kit patterns:\n * - AccountMeta with Address and AccountRole\n * - Pure data objects instead of classes where possible\n */\n\nimport { type Address, type AccountMeta, AccountRole, getProgramDerivedAddress } from \"@solana/kit\";\nimport {\n LIGHT_SYSTEM_PROGRAM,\n REGISTERED_PROGRAM_PDA,\n NOOP_PROGRAM,\n ACCOUNT_COMPRESSION_PROGRAM,\n} from \"../constants.js\";\n\n// =============================================================================\n// System Account Configuration\n// =============================================================================\n\n/**\n * Configuration for Light System Program account metas.\n */\nexport interface SystemAccountMetaConfig {\n /** The program making the CPI call */\n selfProgram: Address;\n /** Optional CPI context account */\n cpiContext?: Address;\n /** Optional SOL compression recipient */\n solCompressionRecipient?: Address;\n /** Optional SOL pool PDA */\n solPoolPda?: Address;\n}\n\n/**\n * Create a basic system account config.\n */\nexport function createSystemAccountConfig(selfProgram: Address): SystemAccountMetaConfig {\n return { selfProgram };\n}\n\n/**\n * Create a system account config with CPI context.\n */\nexport function createSystemAccountConfigWithCpi(selfProgram: Address, cpiContext: Address): SystemAccountMetaConfig {\n return { selfProgram, cpiContext };\n}\n\n// =============================================================================\n// Account Metas Helpers\n// =============================================================================\n\n/**\n * Derive the CPI signer PDA for a program.\n */\nexport async function getCpiSignerPda(selfProgram: Address): Promise<Address> {\n const [pda] = await getProgramDerivedAddress({\n programAddress: selfProgram,\n seeds: [new TextEncoder().encode(\"cpi_authority\")],\n });\n return pda;\n}\n\n/**\n * Derive the account compression authority PDA.\n */\nexport async function getAccountCompressionAuthority(): Promise<Address> {\n const [pda] = await getProgramDerivedAddress({\n programAddress: LIGHT_SYSTEM_PROGRAM,\n seeds: [new TextEncoder().encode(\"cpi_authority\")],\n });\n return pda;\n}\n\n/**\n * Get the system program address.\n */\nexport function getSystemProgram(): Address {\n return \"11111111111111111111111111111111\" as Address;\n}\n\n/**\n * Build Light System account metas (V1 layout).\n *\n * @param config - System account configuration\n * @returns Array of account metas for Light System Program\n *\n * @example\n * ```typescript\n * import { getLightSystemAccountMetas, createSystemAccountConfig } from '@cascade-fyi/compression-kit';\n * import { address } from '@solana/kit';\n *\n * const programId = address('YourProgramId...');\n * const config = createSystemAccountConfig(programId);\n * const metas = await getLightSystemAccountMetas(config);\n * ```\n */\nexport async function getLightSystemAccountMetas(config: SystemAccountMetaConfig): Promise<AccountMeta[]> {\n const cpiSigner = await getCpiSignerPda(config.selfProgram);\n const compressionAuthority = await getAccountCompressionAuthority();\n\n const metas: AccountMeta[] = [\n { address: LIGHT_SYSTEM_PROGRAM, role: AccountRole.READONLY },\n { address: cpiSigner, role: AccountRole.READONLY },\n { address: REGISTERED_PROGRAM_PDA, role: AccountRole.READONLY },\n { address: NOOP_PROGRAM, role: AccountRole.READONLY },\n { address: compressionAuthority, role: AccountRole.READONLY },\n { address: ACCOUNT_COMPRESSION_PROGRAM, role: AccountRole.READONLY },\n { address: config.selfProgram, role: AccountRole.READONLY },\n ];\n\n if (config.solPoolPda) {\n metas.push({ address: config.solPoolPda, role: AccountRole.WRITABLE });\n }\n if (config.solCompressionRecipient) {\n metas.push({\n address: config.solCompressionRecipient,\n role: AccountRole.WRITABLE,\n });\n }\n metas.push({ address: getSystemProgram(), role: AccountRole.READONLY });\n if (config.cpiContext) {\n metas.push({ address: config.cpiContext, role: AccountRole.WRITABLE });\n }\n\n return metas;\n}\n\n/**\n * Build Light System account metas (V2 layout - no noop program).\n */\nexport async function getLightSystemAccountMetasV2(config: SystemAccountMetaConfig): Promise<AccountMeta[]> {\n const cpiSigner = await getCpiSignerPda(config.selfProgram);\n const compressionAuthority = await getAccountCompressionAuthority();\n\n const metas: AccountMeta[] = [\n { address: LIGHT_SYSTEM_PROGRAM, role: AccountRole.READONLY },\n { address: cpiSigner, role: AccountRole.READONLY },\n { address: REGISTERED_PROGRAM_PDA, role: AccountRole.READONLY },\n { address: compressionAuthority, role: AccountRole.READONLY },\n { address: ACCOUNT_COMPRESSION_PROGRAM, role: AccountRole.READONLY },\n { address: getSystemProgram(), role: AccountRole.READONLY },\n ];\n\n if (config.solPoolPda) {\n metas.push({ address: config.solPoolPda, role: AccountRole.WRITABLE });\n }\n if (config.solCompressionRecipient) {\n metas.push({\n address: config.solCompressionRecipient,\n role: AccountRole.WRITABLE,\n });\n }\n if (config.cpiContext) {\n metas.push({ address: config.cpiContext, role: AccountRole.WRITABLE });\n }\n\n return metas;\n}\n\n// =============================================================================\n// PackedAccounts Class\n// =============================================================================\n\n/**\n * Helper class for building remaining accounts for Light Protocol instructions.\n *\n * Manages three categories of accounts:\n * 1. Pre-accounts: Signers and other accounts that come first\n * 2. System accounts: Light System Program static accounts\n * 3. Packed accounts: Dynamic accounts indexed by pubkey\n */\nexport class PackedAccounts {\n private preAccounts: AccountMeta[] = [];\n private systemAccounts: AccountMeta[] = [];\n private nextIndex: number = 0;\n private accountMap: Map<string, [number, AccountMeta]> = new Map();\n\n /**\n * Create a new PackedAccounts with system accounts (V1 layout).\n */\n static async newWithSystemAccounts(config: SystemAccountMetaConfig): Promise<PackedAccounts> {\n const instance = new PackedAccounts();\n await instance.addSystemAccounts(config);\n return instance;\n }\n\n /**\n * Create a new PackedAccounts with system accounts (V2 layout).\n */\n static async newWithSystemAccountsV2(config: SystemAccountMetaConfig): Promise<PackedAccounts> {\n const instance = new PackedAccounts();\n await instance.addSystemAccountsV2(config);\n return instance;\n }\n\n /**\n * Add a signer to pre-accounts (readonly).\n */\n addPreAccountsSigner(pubkey: Address): void {\n this.preAccounts.push({\n address: pubkey,\n role: AccountRole.READONLY_SIGNER,\n });\n }\n\n /**\n * Add a writable signer to pre-accounts.\n */\n addPreAccountsSignerMut(pubkey: Address): void {\n this.preAccounts.push({\n address: pubkey,\n role: AccountRole.WRITABLE_SIGNER,\n });\n }\n\n /**\n * Add an account meta to pre-accounts.\n */\n addPreAccountsMeta(accountMeta: AccountMeta): void {\n this.preAccounts.push(accountMeta);\n }\n\n /**\n * Add system accounts (V1 layout).\n */\n async addSystemAccounts(config: SystemAccountMetaConfig): Promise<void> {\n const metas = await getLightSystemAccountMetas(config);\n this.systemAccounts.push(...metas);\n }\n\n /**\n * Add system accounts (V2 layout).\n */\n async addSystemAccountsV2(config: SystemAccountMetaConfig): Promise<void> {\n const metas = await getLightSystemAccountMetasV2(config);\n this.systemAccounts.push(...metas);\n }\n\n /**\n * Insert or get index for a writable account.\n */\n insertOrGet(pubkey: Address): number {\n return this.insertOrGetConfig(pubkey, false, true);\n }\n\n /**\n * Insert or get index for a readonly account.\n */\n insertOrGetReadOnly(pubkey: Address): number {\n return this.insertOrGetConfig(pubkey, false, false);\n }\n\n /**\n * Insert or get index with full configuration.\n */\n insertOrGetConfig(pubkey: Address, isSigner: boolean, isWritable: boolean): number {\n const key = pubkey as string;\n const existing = this.accountMap.get(key);\n if (existing) {\n return existing[0];\n }\n\n const index = this.nextIndex++;\n let role: AccountRole;\n if (isSigner && isWritable) {\n role = AccountRole.WRITABLE_SIGNER;\n } else if (isSigner) {\n role = AccountRole.READONLY_SIGNER;\n } else if (isWritable) {\n role = AccountRole.WRITABLE;\n } else {\n role = AccountRole.READONLY;\n }\n\n const meta: AccountMeta = { address: pubkey, role };\n this.accountMap.set(key, [index, meta]);\n return index;\n }\n\n /**\n * Get packed accounts sorted by insertion order.\n */\n private getPackedAccountMetas(): AccountMeta[] {\n const entries = Array.from(this.accountMap.entries());\n entries.sort((a, b) => a[1][0] - b[1][0]);\n return entries.map(([, [, meta]]) => meta);\n }\n\n /**\n * Get offsets for system and packed accounts.\n */\n private getOffsets(): [number, number] {\n const systemStart = this.preAccounts.length;\n const packedStart = systemStart + this.systemAccounts.length;\n return [systemStart, packedStart];\n }\n\n /**\n * Build final remaining accounts array with offsets.\n */\n toAccountMetas(): {\n remainingAccounts: AccountMeta[];\n systemStart: number;\n packedStart: number;\n } {\n const packed = this.getPackedAccountMetas();\n const [systemStart, packedStart] = this.getOffsets();\n\n return {\n remainingAccounts: [...this.preAccounts, ...this.systemAccounts, ...packed],\n systemStart,\n packedStart,\n };\n }\n}\n","/**\n * Light Protocol Photon RPC Client using native fetch.\n *\n * This is a portable implementation that works in:\n * - Cloudflare Workers\n * - Browsers\n * - Node.js\n * - Deno\n *\n * Uses Kit-native patterns but with a simple fetch-based transport\n * for the Photon indexer API (not standard Solana RPC).\n */\n\nimport type { Address } from \"@solana/kit\";\nimport { address } from \"@solana/kit\";\nimport bs58 from \"bs58\";\nimport { versionedEndpoint, featureFlags } from \"./constants.js\";\nimport type {\n CompressedAccount,\n MerkleContextWithProof,\n TreeInfo,\n TreeType,\n ValidityProof,\n ValidityProofWithContext,\n ParsedTokenAccount,\n} from \"./state/types.js\";\nimport { createBN254, type BN254 } from \"./state/bn254.js\";\nimport { RpcErrorCode, createRpcError } from \"./errors.js\";\n\n// =============================================================================\n// Types\n// =============================================================================\n\nlet requestId = 0n;\n\n/**\n * JSON-RPC request structure.\n */\ninterface JsonRpcRequest {\n jsonrpc: \"2.0\";\n id: string;\n method: string;\n params: unknown;\n}\n\n/**\n * JSON-RPC response structure.\n */\ninterface JsonRpcResponse<T> {\n jsonrpc: \"2.0\";\n id: string;\n result?: T;\n error?: {\n code: number;\n message: string;\n data?: unknown;\n };\n}\n\n/**\n * Context wrapper for RPC responses.\n */\nexport interface WithContext<T> {\n context: { slot: number };\n value: T;\n}\n\n/**\n * Cursor-based pagination wrapper.\n */\nexport interface WithCursor<T> {\n cursor: string | null;\n items: T;\n}\n\n/**\n * Options for paginated requests.\n */\nexport interface PaginatedOptions {\n cursor?: string;\n limit?: number;\n}\n\n/**\n * Options for getCompressedAccountsByOwner.\n */\nexport interface GetCompressedAccountsByOwnerConfig {\n cursor?: string;\n limit?: number;\n}\n\n/**\n * Options for getCompressedTokenAccountsByOwner.\n */\nexport interface GetCompressedTokenAccountsConfig {\n mint?: Address;\n cursor?: string;\n limit?: number;\n}\n\n/**\n * Hash with tree info for proof requests.\n */\nexport interface HashWithTreeInfo {\n hash: BN254;\n stateTreeInfo: TreeInfo;\n}\n\n/**\n * Address with tree info for proof requests.\n */\nexport interface AddressWithTreeInfo {\n address: BN254;\n addressTreeInfo: TreeInfo;\n}\n\n/**\n * Signature metadata from compression indexer.\n */\nexport interface SignatureWithMetadata {\n blockTime: number;\n signature: string;\n slot: number;\n}\n\n/**\n * Token balance info.\n */\nexport interface TokenBalance {\n balance: bigint;\n mint: Address;\n}\n\n// =============================================================================\n// RPC Client\n// =============================================================================\n\n/**\n * Light Protocol Photon RPC client.\n *\n * Provides methods for querying compressed accounts, requesting validity proofs,\n * and other indexer operations.\n */\nexport class PhotonRpc {\n readonly endpoint: string;\n private readonly headers: Record<string, string>;\n\n constructor(endpoint: string, headers?: Record<string, string>) {\n this.endpoint = endpoint;\n this.headers = {\n \"Content-Type\": \"application/json\",\n Accept: \"application/json\",\n ...headers,\n };\n }\n\n // ===========================================================================\n // Core RPC Methods\n // ===========================================================================\n\n /**\n * Make a JSON-RPC request to the Photon indexer.\n */\n private async request<T>(method: string, params: unknown): Promise<T> {\n const id = (++requestId).toString();\n const body: JsonRpcRequest = {\n jsonrpc: \"2.0\",\n id,\n method,\n params,\n };\n\n const response = await fetch(this.endpoint, {\n method: \"POST\",\n headers: this.headers,\n body: JSON.stringify(body),\n });\n\n if (!response.ok) {\n throw createRpcError(RpcErrorCode.RPC_INVALID, \"request\", `HTTP ${response.status}: ${response.statusText}`);\n }\n\n const json = (await response.json()) as JsonRpcResponse<T>;\n\n if (json.error) {\n throw createRpcError(RpcErrorCode.RPC_INVALID, method, `${json.error.code}: ${json.error.message}`);\n }\n\n return json.result as T;\n }\n\n /**\n * Request with context wrapper.\n */\n private async requestWithContext<T>(method: string, params: unknown): Promise<WithContext<T>> {\n return this.request<WithContext<T>>(method, params);\n }\n\n // ===========================================================================\n // Health & Status\n // ===========================================================================\n\n /**\n * Get indexer health status.\n */\n async getIndexerHealth(): Promise<string> {\n return this.request<string>(\"getIndexerHealth\", {});\n }\n\n /**\n * Get current indexer slot.\n */\n async getIndexerSlot(): Promise<number> {\n return this.request<number>(\"getIndexerSlot\", {});\n }\n\n // ===========================================================================\n // Compressed Accounts\n // ===========================================================================\n\n /**\n * Get a single compressed account by address or hash.\n */\n async getCompressedAccount(addressOrHash: { address?: Address; hash?: BN254 }): Promise<CompressedAccount | null> {\n const method = versionedEndpoint(\"getCompressedAccount\");\n const params: Record<string, string> = {};\n\n if (addressOrHash.address) {\n params.address = addressOrHash.address;\n }\n if (addressOrHash.hash !== undefined) {\n params.hash = encodeBN254(addressOrHash.hash);\n }\n\n const result = await this.requestWithContext<RawCompressedAccount | null>(method, params);\n\n if (!result.value) return null;\n return parseCompressedAccount(result.value);\n }\n\n /**\n * Get multiple compressed accounts by hashes.\n */\n async getMultipleCompressedAccounts(hashes: BN254[]): Promise<CompressedAccount[]> {\n const method = versionedEndpoint(\"getMultipleCompressedAccounts\");\n const params = {\n hashes: hashes.map(encodeBN254),\n };\n\n const result = await this.requestWithContext<{ items: RawCompressedAccount[] }>(method, params);\n\n return result.value.items.map(parseCompressedAccount);\n }\n\n /**\n * Get compressed accounts by owner.\n */\n async getCompressedAccountsByOwner(\n owner: Address,\n config?: GetCompressedAccountsByOwnerConfig,\n ): Promise<WithCursor<CompressedAccount[]>> {\n const method = versionedEndpoint(\"getCompressedAccountsByOwner\");\n const params = {\n owner,\n cursor: config?.cursor,\n limit: config?.limit,\n };\n\n const result = await this.requestWithContext<{\n items: RawCompressedAccount[];\n cursor: string | null;\n }>(method, params);\n\n return {\n items: result.value.items.map(parseCompressedAccount),\n cursor: result.value.cursor,\n };\n }\n\n /**\n * Get compressed SOL balance by owner.\n */\n async getCompressedBalanceByOwner(owner: Address): Promise<bigint> {\n const method = versionedEndpoint(\"getCompressedBalanceByOwner\");\n const result = await this.requestWithContext<string>(method, { owner });\n return BigInt(result.value);\n }\n\n // ===========================================================================\n // Merkle Proofs\n // ===========================================================================\n\n /**\n * Get merkle proof for a compressed account.\n */\n async getCompressedAccountProof(hash: BN254): Promise<MerkleContextWithProof> {\n const method = versionedEndpoint(\"getCompressedAccountProof\");\n const params = { hash: encodeBN254(hash) };\n\n const result = await this.requestWithContext<RawMerkleProof>(method, params);\n return parseMerkleProof(result.value);\n }\n\n /**\n * Get merkle proofs for multiple compressed accounts.\n */\n async getMultipleCompressedAccountProofs(hashes: BN254[]): Promise<MerkleContextWithProof[]> {\n const method = versionedEndpoint(\"getMultipleCompressedAccountProofs\");\n const params = { hashes: hashes.map(encodeBN254) };\n\n const result = await this.requestWithContext<RawMerkleProof[]>(method, params);\n return result.value.map(parseMerkleProof);\n }\n\n // ===========================================================================\n // Validity Proofs\n // ===========================================================================\n\n /**\n * Get validity proof for compressed accounts and/or new addresses.\n *\n * This is the main method for obtaining ZK proofs needed to use\n * compressed accounts in transactions.\n */\n async getValidityProof(\n hashes: HashWithTreeInfo[],\n newAddresses: AddressWithTreeInfo[],\n ): Promise<ValidityProofWithContext> {\n const method = versionedEndpoint(\"getValidityProof\");\n const params = {\n hashes: hashes.map((h) => ({\n hash: encodeBN254(h.hash),\n tree: h.stateTreeInfo.tree,\n queue: h.stateTreeInfo.queue,\n })),\n newAddresses: newAddresses.map((a) => ({\n address: encodeBN254(a.address),\n tree: a.addressTreeInfo.tree,\n queue: a.addressTreeInfo.queue,\n })),\n };\n\n const result = await this.requestWithContext<RawValidityProof>(method, params);\n return parseValidityProof(result.value);\n }\n\n // ===========================================================================\n // Token Accounts\n // ===========================================================================\n\n /**\n * Get compressed token accounts by owner.\n */\n async getCompressedTokenAccountsByOwner(\n owner: Address,\n config?: GetCompressedTokenAccountsConfig,\n ): Promise<WithCursor<ParsedTokenAccount[]>> {\n const method = versionedEndpoint(\"getCompressedTokenAccountsByOwner\");\n const params = {\n owner,\n mint: config?.mint,\n cursor: config?.cursor,\n limit: config?.limit,\n };\n\n const result = await this.requestWithContext<{\n items: RawTokenAccount[];\n cursor: string | null;\n }>(method, params);\n\n return {\n items: result.value.items.map(parseTokenAccount),\n cursor: result.value.cursor,\n };\n }\n\n /**\n * Get compressed token balances by owner.\n */\n async getCompressedTokenBalancesByOwner(\n owner: Address,\n config?: GetCompressedTokenAccountsConfig,\n ): Promise<WithCursor<TokenBalance[]>> {\n const method = versionedEndpoint(\"getCompressedTokenBalancesByOwner\");\n const params = {\n owner,\n mint: config?.mint,\n cursor: config?.cursor,\n limit: config?.limit,\n };\n\n const result = await this.requestWithContext<{\n items: Array<{ balance: string; mint: string }>;\n cursor: string | null;\n }>(method, params);\n\n return {\n items: result.value.items.map((item) => ({\n balance: BigInt(item.balance),\n mint: address(item.mint),\n })),\n cursor: result.value.cursor,\n };\n }\n\n // ===========================================================================\n // Signatures\n // ===========================================================================\n\n /**\n * Get compression signatures for an account hash.\n */\n async getCompressionSignaturesForAccount(hash: BN254): Promise<SignatureWithMetadata[]> {\n const method = \"getCompressionSignaturesForAccount\";\n const params = { hash: encodeBN254(hash) };\n\n const result = await this.requestWithContext<{\n items: SignatureWithMetadata[];\n }>(method, params);\n\n return result.value.items;\n }\n\n /**\n * Get compression signatures for an address.\n */\n async getCompressionSignaturesForAddress(\n addr: Address,\n options?: PaginatedOptions,\n ): Promise<WithCursor<SignatureWithMetadata[]>> {\n const method = \"getCompressionSignaturesForAddress\";\n const params = {\n address: addr,\n cursor: options?.cursor,\n limit: options?.limit,\n };\n\n const result = await this.requestWithContext<{\n items: SignatureWithMetadata[];\n cursor: string | null;\n }>(method, params);\n\n return {\n items: result.value.items,\n cursor: result.value.cursor,\n };\n }\n\n /**\n * Get compression signatures for an owner.\n */\n async getCompressionSignaturesForOwner(\n owner: Address,\n options?: PaginatedOptions,\n ): Promise<WithCursor<SignatureWithMetadata[]>> {\n const method = \"getCompressionSignaturesForOwner\";\n const params = {\n owner,\n cursor: options?.cursor,\n limit: options?.limit,\n };\n\n const result = await this.requestWithContext<{\n items: SignatureWithMetadata[];\n cursor: string | null;\n }>(method, params);\n\n return {\n items: result.value.items,\n cursor: result.value.cursor,\n };\n }\n\n /**\n * Get latest non-voting signatures (compression transactions).\n */\n async getLatestCompressionSignatures(cursor?: string, limit?: number): Promise<WithCursor<SignatureWithMetadata[]>> {\n const method = \"getLatestCompressionSignatures\";\n const params = { cursor, limit };\n\n const result = await this.requestWithContext<{\n items: SignatureWithMetadata[];\n cursor: string | null;\n }>(method, params);\n\n return {\n items: result.value.items,\n cursor: result.value.cursor,\n };\n }\n}\n\n// =============================================================================\n// Helper Functions\n// =============================================================================\n\n/**\n * Encode BN254 to base58 string for RPC params.\n */\nfunction encodeBN254(value: BN254): string {\n // Convert to 32-byte big-endian and base58 encode\n const bytes = new Uint8Array(32);\n let remaining = value;\n for (let i = 31; i >= 0; i--) {\n bytes[i] = Number(remaining & 0xffn);\n remaining >>= 8n;\n }\n // Use bs58 to encode to base58 string\n return bs58.encode(bytes);\n}\n\n// =============================================================================\n// Raw Response Types (from Photon API)\n// =============================================================================\n\ninterface RawCompressedAccount {\n address: string | null;\n hash: string;\n data: {\n data: string;\n dataHash: string;\n discriminator: string;\n } | null;\n lamports: string;\n owner: string;\n leafIndex: number;\n tree?: string; // V1\n merkleContext?: {\n tree: string;\n queue: string;\n treeType: number;\n cpiContext?: string | null;\n }; // V2\n proveByIndex?: boolean;\n seq?: string | null;\n slotCreated: string;\n}\n\ninterface RawMerkleProof {\n hash: string;\n leafIndex: number;\n merkleTree?: string; // V1\n treeContext?: {\n tree: string;\n queue: string;\n treeType: number;\n cpiContext?: string | null;\n }; // V2\n proof: string[];\n root: string;\n rootSeq: number;\n proveByIndex?: boolean;\n}\n\ninterface RawValidityProof {\n compressedProof: {\n a: number[];\n b: number[];\n c: number[];\n } | null;\n roots: string[];\n rootIndices: number[];\n leafIndices: number[];\n leaves: string[];\n merkleTrees?: string[]; // V1\n accounts?: Array<{\n hash: string;\n root: string;\n rootIndex: { rootIndex: number; proveByIndex: boolean };\n merkleContext: {\n tree: string;\n queue: string;\n treeType: number;\n };\n leafIndex: number;\n }>; // V2\n}\n\ninterface RawTokenAccount {\n account: RawCompressedAccount;\n tokenData: {\n mint: string;\n owner: string;\n amount: string;\n delegate: string | null;\n state: string;\n };\n}\n\n// =============================================================================\n// Parsing Functions\n// =============================================================================\n\nfunction parseCompressedAccount(raw: RawCompressedAccount): CompressedAccount {\n const treeInfo = parseTreeInfo(raw);\n\n return {\n owner: address(raw.owner),\n lamports: BigInt(raw.lamports),\n address: raw.address ? base58ToBytes(raw.address) : null,\n data: raw.data\n ? {\n discriminator: hexToBytes(raw.data.discriminator),\n data: base64ToBytes(raw.data.data),\n dataHash: base58ToBytes(raw.data.dataHash),\n }\n : null,\n treeInfo,\n hash: createBN254(raw.hash, \"base58\"),\n leafIndex: raw.leafIndex,\n proveByIndex: raw.proveByIndex ?? false,\n readOnly: false,\n };\n}\n\nfunction parseTreeInfo(raw: RawCompressedAccount | RawMerkleProof): TreeInfo {\n if (featureFlags.isV2() && \"merkleContext\" in raw && raw.merkleContext) {\n const ctx = raw.merkleContext;\n return {\n tree: address(ctx.tree),\n queue: address(ctx.queue),\n treeType: ctx.treeType as TreeType,\n cpiContext: ctx.cpiContext ? address(ctx.cpiContext) : undefined,\n nextTreeInfo: null,\n };\n }\n\n if (\"treeContext\" in raw && raw.treeContext) {\n const ctx = raw.treeContext;\n return {\n tree: address(ctx.tree),\n queue: address(ctx.queue),\n treeType: ctx.treeType as TreeType,\n cpiContext: ctx.cpiContext ? address(ctx.cpiContext) : undefined,\n nextTreeInfo: null,\n };\n }\n\n // V1 fallback\n const tree =\n \"tree\" in raw && raw.tree ? raw.tree : \"merkleTree\" in raw ? ((raw as RawMerkleProof).merkleTree ?? \"\") : \"\";\n return {\n tree: address(tree),\n queue: address(tree), // V1 doesn't have separate queue in response\n treeType: 1 as TreeType, // StateV1\n nextTreeInfo: null,\n };\n}\n\nfunction parseMerkleProof(raw: RawMerkleProof): MerkleContextWithProof {\n const treeInfo = parseTreeInfo(raw);\n\n return {\n treeInfo,\n hash: createBN254(raw.hash, \"base58\"),\n leafIndex: raw.leafIndex,\n proveByIndex: raw.proveByIndex ?? false,\n merkleProof: raw.proof.map((p) => createBN254(p, \"base58\")),\n rootIndex: raw.rootSeq,\n root: createBN254(raw.root, \"base58\"),\n };\n}\n\nfunction parseValidityProof(raw: RawValidityProof): ValidityProofWithContext {\n const proof: ValidityProof | null = raw.compressedProof\n ? {\n a: new Uint8Array(raw.compressedProof.a),\n b: new Uint8Array(raw.compressedProof.b),\n c: new Uint8Array(raw.compressedProof.c),\n }\n : null;\n\n // Parse based on V1 vs V2 response format\n if (raw.accounts) {\n // V2 format\n return {\n compressedProof: proof,\n roots: raw.accounts.map((a) => createBN254(a.root, \"base58\")),\n rootIndices: raw.accounts.map((a) => a.rootIndex.rootIndex),\n leafIndices: raw.accounts.map((a) => a.leafIndex),\n leaves: raw.accounts.map((a) => createBN254(a.hash, \"base58\")),\n treeInfos: raw.accounts.map((a) => ({\n tree: address(a.merkleContext.tree),\n queue: address(a.merkleContext.queue),\n treeType: a.merkleContext.treeType as TreeType,\n nextTreeInfo: null,\n })),\n proveByIndices: raw.accounts.map((a) => a.rootIndex.proveByIndex),\n };\n }\n\n // V1 format\n return {\n compressedProof: proof,\n roots: raw.roots.map((r) => createBN254(r, \"base58\")),\n rootIndices: raw.rootIndices,\n leafIndices: raw.leafIndices,\n leaves: raw.leaves.map((l) => createBN254(l, \"base58\")),\n treeInfos: (raw.merkleTrees ?? []).map((t) => ({\n tree: address(t),\n queue: address(t),\n treeType: 1 as TreeType,\n nextTreeInfo: null,\n })),\n proveByIndices: raw.leafIndices.map(() => false),\n };\n}\n\nfunction parseTokenAccount(raw: RawTokenAccount): ParsedTokenAccount {\n return {\n compressedAccount: parseCompressedAccount(raw.account),\n parsed: {\n mint: address(raw.tokenData.mint),\n owner: address(raw.tokenData.owner),\n amount: BigInt(raw.tokenData.amount),\n delegate: raw.tokenData.delegate ? address(raw.tokenData.delegate) : null,\n state: raw.tokenData.state === \"initialized\" ? 1 : 0,\n tlv: null,\n },\n };\n}\n\n// =============================================================================\n// Encoding Utilities\n// =============================================================================\n\nfunction base58ToBytes(value: string): Uint8Array {\n return bs58.decode(value);\n}\n\nfunction base64ToBytes(value: string): Uint8Array {\n // atob is available in all modern runtimes: browsers, Node.js 16+,\n // Cloudflare Workers, Deno, and Bun\n const binary = atob(value);\n const bytes = new Uint8Array(binary.length);\n for (let i = 0; i < binary.length; i++) {\n bytes[i] = binary.charCodeAt(i);\n }\n return bytes;\n}\n\nfunction hexToBytes(hex: string): Uint8Array {\n const cleanHex = hex.startsWith(\"0x\") ? hex.slice(2) : hex;\n const bytes = new Uint8Array(cleanHex.length / 2);\n for (let i = 0; i < bytes.length; i++) {\n bytes[i] = parseInt(cleanHex.slice(i * 2, i * 2 + 2), 16);\n }\n return bytes;\n}\n\n// =============================================================================\n// Factory Function\n// =============================================================================\n\n/**\n * Create a Photon RPC client.\n *\n * @param endpoint - Photon indexer URL (e.g., \"https://zk-testnet.helius.dev:8784\")\n * @param headers - Optional additional headers\n * @returns PhotonRpc instance\n *\n * @example\n * ```typescript\n * import { createPhotonRpc } from '@cascade-fyi/compression-kit';\n *\n * const rpc = createPhotonRpc('https://mainnet.helius-rpc.com/?api-key=YOUR_KEY');\n * const accounts = await rpc.getCompressedAccountsByOwner(ownerAddress);\n * ```\n */\nexport function createPhotonRpc(endpoint: string, headers?: Record<string, string>): PhotonRpc {\n return new PhotonRpc(endpoint, headers);\n}\n"],"mappings":";;;;;;;;AAkBA,IAAY,gDAAL;;AAEL;;AAEA;;AAEA;;AAEA;;;;;;;;;;;;;ACXF,IAAY,8CAAL;AACL;AACA;;;;;;;AAOF,MAAa,eAAe;CAC1B,SAAS,QAAQ;CACjB,YAAY,aAAa,YAAY,QAAQ;CAC9C;;;;;AAMD,MAAa,qBAAqB,SAA0B,aAAa,MAAM,GAAG,GAAG,KAAK,MAAM;;;;;AAUhG,MAAa,aAAa;;;;AAK1B,MAAa,2BAA2B;;AAOxC,MAAa,uBAAuB,QAAQ,8CAA8C;;AAG1F,MAAa,8BAA8B,QAAQ,8CAA8C;;AAGjG,MAAa,eAAe,QAAQ,8CAA8C;;AAGlF,MAAa,2BAA2B,QAAQ,8CAA8C;;AAG9F,MAAa,yBAAyB,QAAQ,+CAA+C;AAM7F,MAAa,uBAAuB,IAAI,WAAW;CAAC;CAAI;CAAI;CAAK;CAAG;CAAI;CAAK;CAAK;CAAG,CAAC;AAEtF,MAAa,2BAA2B,IAAI,WAAW;CAAC;CAAI;CAAK;CAAK;CAAK;CAAI;CAAK;CAAI;CAAI,CAAC;AAE7F,MAAa,0CAA0C,IAAI,WAAW;CAAC;CAAI;CAAI;CAAK;CAAK;CAAI;CAAK;CAAI;CAAE,CAAC;AAEzG,MAAa,6CAA6C,IAAI,WAAW;CAAC;CAAK;CAAI;CAAK;CAAI;CAAI;CAAK;CAAI;CAAI,CAAC;AAE9G,MAAa,mCAAmC,IAAI,WAAW;CAAC;CA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AAI,YAAY,UAAU,MAAM;EACjD;;AAGH,SAAS,kBAAkB,KAA0C;AACnE,QAAO;EACL,mBAAmB,uBAAuB,IAAI,QAAQ;EACtD,QAAQ;GACN,MAAM,QAAQ,IAAI,UAAU,KAAK;GACjC,OAAO,QAAQ,IAAI,UAAU,MAAM;GACnC,QAAQ,OAAO,IAAI,UAAU,OAAO;GACpC,UAAU,IAAI,UAAU,WAAW,QAAQ,IAAI,UAAU,SAAS,GAAG;GACrE,OAAO,IAAI,UAAU,UAAU,gBAAgB,IAAI;GACnD,KAAK;GACN;EACF;;AAOH,SAAS,cAAc,OAA2B;AAChD,QAAO,KAAK,OAAO,MAAM;;AAG3B,SAAS,cAAc,OAA2B;CAGhD,MAAM,SAAS,KAAK,MAAM;CAC1B,MAAM,QAAQ,IAAI,WAAW,OAAO,OAAO;AAC3C,MAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,IACjC,OAAM,KAAK,OAAO,WAAW,EAAE;AAEjC,QAAO;;AAGT,SAASD,aAAW,KAAyB;CAC3C,MAAM,WAAW,IAAI,WAAW,KAAK,GAAG,IAAI,MAAM,EAAE,GAAG;CACvD,MAAM,QAAQ,IAAI,WAAW,SAAS,SAAS,EAAE;AACjD,MAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,IAChC,OAAM,KAAK,SAAS,SAAS,MAAM,IAAI,GAAG,IAAI,IAAI,EAAE,EAAE,GAAG;AAE3D,QAAO;;;;;;;;;;;;;;;;;AAsBT,SAAgB,gBAAgB,UAAkB,SAA6C;AAC7F,QAAO,IAAI,UAAU,UAAU,QAAQ"}
package/package.json ADDED
@@ -0,0 +1,75 @@
1
+ {
2
+ "name": "@cascade-fyi/compression-kit",
3
+ "version": "0.1.0",
4
+ "description": "Solana Kit native implementation of Light Protocol stateless.js - portable, edge-compatible",
5
+ "type": "module",
6
+ "sideEffects": false,
7
+ "main": "./dist/index.cjs",
8
+ "module": "./dist/index.mjs",
9
+ "types": "./dist/index.d.mts",
10
+ "exports": {
11
+ ".": {
12
+ "import": {
13
+ "types": "./dist/index.d.mts",
14
+ "default": "./dist/index.mjs"
15
+ },
16
+ "require": {
17
+ "types": "./dist/index.d.cts",
18
+ "default": "./dist/index.cjs"
19
+ }
20
+ },
21
+ "./package.json": "./package.json"
22
+ },
23
+ "files": [
24
+ "dist/**",
25
+ "README.md",
26
+ "LICENSE"
27
+ ],
28
+ "keywords": [
29
+ "solana",
30
+ "light-protocol",
31
+ "zk-compression",
32
+ "compressed-accounts",
33
+ "edge-compatible",
34
+ "cloudflare-workers",
35
+ "solana-kit"
36
+ ],
37
+ "author": "Cascade",
38
+ "license": "Apache-2.0",
39
+ "repository": {
40
+ "type": "git",
41
+ "url": "git+https://github.com/cascade-protocol/sati.git",
42
+ "directory": "packages/compression-kit"
43
+ },
44
+ "homepage": "https://github.com/cascade-protocol/sati/tree/main/packages/compression-kit#readme",
45
+ "bugs": {
46
+ "url": "https://github.com/cascade-protocol/sati/issues"
47
+ },
48
+ "engines": {
49
+ "node": ">=20.18.0"
50
+ },
51
+ "dependencies": {
52
+ "@noble/hashes": "^2.0.1",
53
+ "@solana/kit": "^5.1.0",
54
+ "bs58": "^6.0.0"
55
+ },
56
+ "devDependencies": {
57
+ "@arethetypeswrong/core": "^0.18.2",
58
+ "@types/node": "^25.0.3",
59
+ "publint": "^0.3.16",
60
+ "tsdown": "^0.18.3",
61
+ "typescript": "^5.9.3",
62
+ "vitest": "^4.0.16"
63
+ },
64
+ "scripts": {
65
+ "build": "tsdown --publint",
66
+ "dev": "tsdown --watch",
67
+ "type-check": "tsc --noEmit",
68
+ "lint": "biome check",
69
+ "lint:fix": "biome check --write",
70
+ "check": "pnpm run \"/^(type-check|lint:fix)$/\"",
71
+ "test": "vitest run",
72
+ "test:watch": "vitest",
73
+ "clean": "rm -rf dist"
74
+ }
75
+ }