@lightprotocol/stateless.js 0.22.0 → 0.22.1-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/README.md +10 -10
  2. package/dist/cjs/browser/constants.d.ts +24 -7
  3. package/dist/cjs/browser/index.cjs +1 -1
  4. package/dist/cjs/browser/index.cjs.map +1 -1
  5. package/dist/cjs/browser/rpc-interface.d.ts +275 -275
  6. package/dist/cjs/browser/rpc.d.ts +5 -1
  7. package/dist/cjs/browser/test-helpers/test-rpc/test-rpc.d.ts +4 -0
  8. package/dist/cjs/browser/utils/address.d.ts +7 -6
  9. package/dist/cjs/browser/utils/conversion.d.ts +1 -0
  10. package/dist/cjs/browser/utils/index.d.ts +1 -0
  11. package/dist/cjs/browser/utils/instruction.d.ts +35 -0
  12. package/dist/cjs/node/constants.d.ts +24 -7
  13. package/dist/cjs/node/index.cjs +1 -1
  14. package/dist/cjs/node/index.cjs.map +1 -1
  15. package/dist/cjs/node/rpc-interface.d.ts +275 -275
  16. package/dist/cjs/node/rpc.d.ts +5 -1
  17. package/dist/cjs/node/test-helpers/test-rpc/test-rpc.d.ts +4 -0
  18. package/dist/cjs/node/utils/address.d.ts +7 -6
  19. package/dist/cjs/node/utils/conversion.d.ts +1 -0
  20. package/dist/cjs/node/utils/index.d.ts +1 -0
  21. package/dist/cjs/node/utils/instruction.d.ts +35 -0
  22. package/dist/es/browser/actions/compress.d.ts +18 -0
  23. package/dist/es/browser/actions/create-account.d.ts +38 -0
  24. package/dist/es/browser/actions/decompress.d.ts +15 -0
  25. package/dist/es/browser/actions/index.d.ts +5 -0
  26. package/dist/es/browser/actions/transfer.d.ts +16 -0
  27. package/dist/es/browser/constants.d.ts +157 -0
  28. package/dist/es/browser/errors.d.ts +74 -0
  29. package/dist/es/browser/index.d.ts +9 -0
  30. package/dist/es/browser/index.js +2 -0
  31. package/dist/es/browser/index.js.map +1 -0
  32. package/dist/es/browser/programs/index.d.ts +1 -0
  33. package/dist/es/browser/programs/system/idl.d.ts +997 -0
  34. package/dist/es/browser/programs/system/index.d.ts +5 -0
  35. package/dist/es/browser/programs/system/layout.d.ts +77 -0
  36. package/dist/es/browser/programs/system/pack.d.ts +74 -0
  37. package/dist/es/browser/programs/system/program.d.ts +175 -0
  38. package/dist/es/browser/programs/system/select-compressed-accounts.d.ts +10 -0
  39. package/dist/es/browser/rpc-interface.d.ts +2779 -0
  40. package/dist/es/browser/rpc.d.ts +284 -0
  41. package/dist/es/browser/state/BN254.d.ts +13 -0
  42. package/dist/es/browser/state/bn.d.ts +3 -0
  43. package/dist/es/browser/state/compressed-account.d.ts +205 -0
  44. package/dist/es/browser/state/index.d.ts +4 -0
  45. package/dist/es/browser/state/types.d.ts +449 -0
  46. package/dist/es/browser/test-helpers/index.d.ts +3 -0
  47. package/dist/es/browser/test-helpers/merkle-tree/index.d.ts +2 -0
  48. package/dist/es/browser/test-helpers/merkle-tree/indexed-array.d.ts +85 -0
  49. package/dist/es/browser/test-helpers/merkle-tree/merkle-tree.d.ts +92 -0
  50. package/dist/es/browser/test-helpers/test-rpc/get-compressed-accounts.d.ts +7 -0
  51. package/dist/es/browser/test-helpers/test-rpc/get-compressed-token-accounts.d.ts +40 -0
  52. package/dist/es/browser/test-helpers/test-rpc/get-parsed-events.d.ts +15 -0
  53. package/dist/es/browser/test-helpers/test-rpc/index.d.ts +3 -0
  54. package/dist/es/browser/test-helpers/test-rpc/test-rpc.d.ts +239 -0
  55. package/dist/es/browser/test-helpers/test-utils.d.ts +31 -0
  56. package/dist/es/browser/utils/address.d.ts +64 -0
  57. package/dist/es/browser/utils/airdrop.d.ts +7 -0
  58. package/dist/es/browser/utils/calculate-compute-unit-price.d.ts +7 -0
  59. package/dist/es/browser/utils/conversion.d.ts +36 -0
  60. package/dist/es/browser/utils/dedupe-signer.d.ts +3 -0
  61. package/dist/es/browser/utils/get-state-tree-infos.d.ts +48 -0
  62. package/dist/es/browser/utils/index.d.ts +13 -0
  63. package/dist/es/browser/utils/instruction.d.ts +35 -0
  64. package/dist/es/browser/utils/parse-validity-proof.d.ts +20 -0
  65. package/dist/es/browser/utils/pipe.d.ts +2 -0
  66. package/dist/es/browser/utils/send-and-confirm.d.ts +52 -0
  67. package/dist/es/browser/utils/sleep.d.ts +1 -0
  68. package/dist/es/browser/utils/state-tree-lookup-table.d.ts +68 -0
  69. package/dist/es/browser/utils/validation.d.ts +8 -0
  70. package/dist/types/index.d.ts +78 -16
  71. package/package.json +16 -8
@@ -0,0 +1,239 @@
1
+ import { Connection, ConnectionConfig, PublicKey } from '@solana/web3.js';
2
+ import BN from 'bn.js';
3
+ import { AddressWithTree, CompressedMintTokenHolders, CompressedTransaction, GetCompressedAccountsByOwnerConfig, PaginatedOptions, HashWithTree, LatestNonVotingSignatures, LatestNonVotingSignaturesPaginated, SignatureWithMetadata, WithContext, WithCursor } from '../../rpc-interface';
4
+ import { ValidityProofWithContext, CompressionApiInterface, GetCompressedTokenAccountsByOwnerOrDelegateOptions, ParsedTokenAccount, TokenBalance } from '../../rpc-interface';
5
+ import { BN254, CompressedAccountWithMerkleContext, MerkleContextWithMerkleProof } from '../../state';
6
+ import { MerkleContextWithNewAddressProof } from '../../rpc';
7
+ import { TreeInfo } from '../../state/types';
8
+ export interface TestRpcConfig {
9
+ /**
10
+ * Depth of state tree. Defaults to the public default test state tree depth
11
+ */
12
+ depth?: number;
13
+ /**
14
+ * Log proof generation time
15
+ */
16
+ log?: boolean;
17
+ }
18
+ export type ClientSubscriptionId = number;
19
+ export interface LightWasm {
20
+ blakeHash(input: string | Uint8Array, hashLength: number): Uint8Array;
21
+ poseidonHash(input: string[] | BN[]): Uint8Array;
22
+ poseidonHashString(input: string[] | BN[]): string;
23
+ poseidonHashBN(input: string[] | BN[]): BN;
24
+ }
25
+ /**
26
+ * Returns a mock RPC instance for use in unit tests.
27
+ *
28
+ * @param lightWasm Wasm hasher instance.
29
+ * @param endpoint RPC endpoint URL. Defaults to
30
+ * 'http://127.0.0.1:8899'.
31
+ * @param proverEndpoint Prover server endpoint URL. Defaults to
32
+ * 'http://localhost:3001'.
33
+ * @param merkleTreeAddress Address of the merkle tree to index. Defaults
34
+ * to the public default test state tree.
35
+ * @param nullifierQueueAddress Optional address of the associated nullifier
36
+ * queue.
37
+ * @param depth Depth of the merkle tree.
38
+ * @param log Log proof generation time.
39
+ */
40
+ export declare function getTestRpc(lightWasm: LightWasm, endpoint?: string, compressionApiEndpoint?: string, proverEndpoint?: string, depth?: number, log?: boolean): Promise<TestRpc>;
41
+ /**
42
+ * Mock RPC for unit tests that simulates the ZK Compression RPC interface.
43
+ * Parses events and builds merkletree on-demand. It does not persist state.
44
+ * Constraints:
45
+ * - Can only index up to 1000 transactions
46
+ *
47
+ * For advanced testing use `Rpc` class which uses photon:
48
+ * https://github.com/helius-labs/photon
49
+ */
50
+ export declare class TestRpc extends Connection implements CompressionApiInterface {
51
+ compressionApiEndpoint: string;
52
+ proverEndpoint: string;
53
+ lightWasm: LightWasm;
54
+ depth: number;
55
+ log: boolean;
56
+ allStateTreeInfos: TreeInfo[] | null;
57
+ lastStateTreeFetchTime: number | null;
58
+ fetchPromise: Promise<TreeInfo[]> | null;
59
+ CACHE_TTL: number;
60
+ /**
61
+ * Establish a Compression-compatible JSON RPC mock-connection
62
+ *
63
+ * @param endpoint endpoint to the solana cluster (use for
64
+ * localnet only)
65
+ * @param hasher light wasm hasher instance
66
+ * @param compressionApiEndpoint Endpoint to the compression server.
67
+ * @param proverEndpoint Endpoint to the prover server. defaults
68
+ * to endpoint
69
+ * @param connectionConfig Optional connection config
70
+ * @param testRpcConfig Config for the mock rpc
71
+ */
72
+ constructor(endpoint: string, hasher: LightWasm, compressionApiEndpoint: string, proverEndpoint: string, connectionConfig?: ConnectionConfig, testRpcConfig?: TestRpcConfig);
73
+ /**
74
+ * @deprecated Use {@link getStateTreeInfos} instead
75
+ */
76
+ getCachedActiveStateTreeInfo(): Promise<void>;
77
+ /**
78
+ * @deprecated Use {@link getStateTreeInfos} instead
79
+ */
80
+ getCachedActiveStateTreeInfos(): Promise<void>;
81
+ /**
82
+ * Returns local test state trees.
83
+ */
84
+ getStateTreeInfos(): Promise<TreeInfo[]>;
85
+ doFetch(): Promise<TreeInfo[]>;
86
+ /**
87
+ * Get a V2 address tree info.
88
+ */
89
+ getAddressTreeInfoV2(): Promise<TreeInfo>;
90
+ /**
91
+ * Fetch the compressed account for the specified account hash
92
+ */
93
+ getCompressedAccount(address?: BN254, hash?: BN254): Promise<CompressedAccountWithMerkleContext | null>;
94
+ /**
95
+ * Fetch the compressed balance for the specified account hash
96
+ */
97
+ getCompressedBalance(address?: BN254, hash?: BN254): Promise<BN>;
98
+ /**
99
+ * Fetch the total compressed balance for the specified owner public key
100
+ */
101
+ getCompressedBalanceByOwner(owner: PublicKey): Promise<BN>;
102
+ /**
103
+ * Fetch the latest merkle proof for the specified account hash from the
104
+ * cluster
105
+ */
106
+ getCompressedAccountProof(hash: BN254): Promise<MerkleContextWithMerkleProof>;
107
+ /**
108
+ * Fetch all the account info for multiple compressed accounts specified by
109
+ * an array of account hashes
110
+ */
111
+ getMultipleCompressedAccounts(hashes: BN254[]): Promise<CompressedAccountWithMerkleContext[]>;
112
+ /**
113
+ * Ensure that the Compression Indexer has already indexed the transaction
114
+ */
115
+ confirmTransactionIndexed(_slot: number): Promise<boolean>;
116
+ /**
117
+ * Fetch the latest merkle proofs for multiple compressed accounts specified
118
+ * by an array account hashes
119
+ */
120
+ getMultipleCompressedAccountProofs(hashes: BN254[]): Promise<MerkleContextWithMerkleProof[]>;
121
+ /**
122
+ * Fetch all the compressed accounts owned by the specified public key.
123
+ * Owner can be a program or user account
124
+ */
125
+ getCompressedAccountsByOwner(owner: PublicKey, _config?: GetCompressedAccountsByOwnerConfig): Promise<WithCursor<CompressedAccountWithMerkleContext[]>>;
126
+ /**
127
+ * Fetch the latest compression signatures on the cluster. Results are
128
+ * paginated.
129
+ */
130
+ getLatestCompressionSignatures(_cursor?: string, _limit?: number): Promise<LatestNonVotingSignaturesPaginated>;
131
+ /**
132
+ * Fetch the latest non-voting signatures on the cluster. Results are
133
+ * not paginated.
134
+ */
135
+ getLatestNonVotingSignatures(_limit?: number): Promise<LatestNonVotingSignatures>;
136
+ /**
137
+ * Fetch all the compressed token accounts owned by the specified public
138
+ * key. Owner can be a program or user account
139
+ */
140
+ getCompressedTokenAccountsByOwner(owner: PublicKey, options: GetCompressedTokenAccountsByOwnerOrDelegateOptions): Promise<WithCursor<ParsedTokenAccount[]>>;
141
+ /**
142
+ * Fetch all the compressed accounts delegated to the specified public key.
143
+ */
144
+ getCompressedTokenAccountsByDelegate(delegate: PublicKey, options: GetCompressedTokenAccountsByOwnerOrDelegateOptions): Promise<WithCursor<ParsedTokenAccount[]>>;
145
+ /**
146
+ * Fetch the compressed token balance for the specified account hash
147
+ */
148
+ getCompressedTokenAccountBalance(hash: BN254): Promise<{
149
+ amount: BN;
150
+ }>;
151
+ /**
152
+ * @deprecated use {@link getCompressedTokenBalancesByOwnerV2}.
153
+ * Fetch all the compressed token balances owned by the specified public
154
+ * key. Can filter by mint.
155
+ */
156
+ getCompressedTokenBalancesByOwner(publicKey: PublicKey, options: GetCompressedTokenAccountsByOwnerOrDelegateOptions): Promise<WithCursor<{
157
+ balance: BN;
158
+ mint: PublicKey;
159
+ }[]>>;
160
+ /**
161
+ * Fetch all the compressed token balances owned by the specified public
162
+ * key. Can filter by mint. Uses context.
163
+ */
164
+ getCompressedTokenBalancesByOwnerV2(publicKey: PublicKey, options: GetCompressedTokenAccountsByOwnerOrDelegateOptions): Promise<WithContext<WithCursor<TokenBalance[]>>>;
165
+ /**
166
+ * Returns confirmed signatures for transactions involving the specified
167
+ * account hash forward in time from genesis to the most recent confirmed
168
+ * block
169
+ *
170
+ * @param hash queried account hash
171
+ */
172
+ getCompressionSignaturesForAccount(_hash: BN254): Promise<SignatureWithMetadata[]>;
173
+ /**
174
+ * Fetch a confirmed or finalized transaction from the cluster. Return with
175
+ * CompressionInfo
176
+ */
177
+ getTransactionWithCompressionInfo(_signature: string): Promise<CompressedTransaction>;
178
+ /**
179
+ * Returns confirmed signatures for transactions involving the specified
180
+ * address forward in time from genesis to the most recent confirmed
181
+ * block
182
+ *
183
+ * @param address queried compressed account address
184
+ */
185
+ getCompressionSignaturesForAddress(_address: PublicKey, _options?: PaginatedOptions): Promise<WithCursor<SignatureWithMetadata[]>>;
186
+ /**
187
+ * Returns confirmed signatures for compression transactions involving the
188
+ * specified account owner forward in time from genesis to the
189
+ * most recent confirmed block
190
+ *
191
+ * @param owner queried owner public key
192
+ */
193
+ getCompressionSignaturesForOwner(_owner: PublicKey, _options?: PaginatedOptions): Promise<WithCursor<SignatureWithMetadata[]>>;
194
+ /**
195
+ * Returns confirmed signatures for compression transactions involving the
196
+ * specified token account owner forward in time from genesis to the most
197
+ * recent confirmed block
198
+ */
199
+ getCompressionSignaturesForTokenOwner(_owner: PublicKey, _options?: PaginatedOptions): Promise<WithCursor<SignatureWithMetadata[]>>;
200
+ /**
201
+ * Fetch the current indexer health status
202
+ */
203
+ getIndexerHealth(): Promise<string>;
204
+ /**
205
+ * Fetch the current slot that the node is processing
206
+ */
207
+ getIndexerSlot(): Promise<number>;
208
+ /**
209
+ * Fetch the latest address proofs for new unique addresses specified by an
210
+ * array of addresses.
211
+ *
212
+ * the proof states that said address have not yet been created in respective address tree.
213
+ * @param addresses Array of BN254 new addresses
214
+ * @returns Array of validity proofs for new addresses
215
+ */
216
+ getMultipleNewAddressProofs(addresses: BN254[]): Promise<MerkleContextWithNewAddressProof[]>;
217
+ getCompressedMintTokenHolders(_mint: PublicKey, _options?: PaginatedOptions): Promise<WithContext<WithCursor<CompressedMintTokenHolders[]>>>;
218
+ /**
219
+ * @deprecated This method is not available for TestRpc. Please use
220
+ * {@link getValidityProof} instead.
221
+ */
222
+ getValidityProofAndRpcContext(hashes?: HashWithTree[], newAddresses?: AddressWithTree[]): Promise<WithContext<ValidityProofWithContext>>;
223
+ /**
224
+ * Fetch the latest validity proof for (1) compressed accounts specified by
225
+ * an array of account hashes. (2) new unique addresses specified by an
226
+ * array of addresses.
227
+ *
228
+ * Validity proofs prove the presence of compressed accounts in state trees
229
+ * and the non-existence of addresses in address trees, respectively. They
230
+ * enable verification without recomputing the merkle proof path, thus
231
+ * lowering verification and data costs.
232
+ *
233
+ * @param hashes Array of BN254 hashes.
234
+ * @param newAddresses Array of BN254 new addresses.
235
+ * @returns validity proof with context
236
+ */
237
+ getValidityProof(hashes?: BN254[], newAddresses?: BN254[]): Promise<ValidityProofWithContext>;
238
+ getValidityProofV0(hashes?: HashWithTree[], newAddresses?: AddressWithTree[]): Promise<ValidityProofWithContext>;
239
+ }
@@ -0,0 +1,31 @@
1
+ import { Connection, Keypair, Signer } from '@solana/web3.js';
2
+ import { Rpc } from '../rpc';
3
+ export declare const ALICE: Keypair;
4
+ export declare const BOB: Keypair;
5
+ export declare const CHARLIE: Keypair;
6
+ export declare const DAVE: Keypair;
7
+ /**
8
+ * Deep comparison of two objects. Handles BN comparison correctly.
9
+ *
10
+ * @param ref - The reference object to compare.
11
+ * @param val - The value object to compare.
12
+ * @returns True if the objects are deeply equal, false otherwise.
13
+ */
14
+ export declare function deepEqual(ref: any, val: any): boolean;
15
+ /**
16
+ * Create a new account and airdrop lamports to it
17
+ *
18
+ * @param rpc connection to use
19
+ * @param lamports amount of lamports to airdrop
20
+ * @param counter counter to use for generating the keypair.
21
+ * If undefined or >255, generates random keypair.
22
+ */
23
+ export declare function newAccountWithLamports(rpc: Rpc, lamports?: number, counter?: number | undefined): Promise<Signer>;
24
+ export declare function getConnection(): Connection;
25
+ /**
26
+ * For use in tests.
27
+ * Generate a unique keypair by passing in a counter <255. If no counter
28
+ * is supplied, it uses and increments a global counter.
29
+ * if counter > 255, generates random keypair
30
+ */
31
+ export declare function getTestKeypair(counter?: number | undefined): Keypair;
@@ -0,0 +1,64 @@
1
+ import { PublicKey } from '@solana/web3.js';
2
+ export declare function deriveAddressSeed(seeds: Uint8Array[], programId: PublicKey): Uint8Array;
3
+ export declare function deriveAddress(seed: Uint8Array, addressMerkleTreePubkey?: PublicKey): PublicKey;
4
+ export declare function deriveAddressSeedV2(seeds: Uint8Array[]): Uint8Array;
5
+ /**
6
+ * Derives an address from a seed using the v2 method (matching Rust's derive_address_from_seed)
7
+ *
8
+ * @param addressSeed The address seed (32 bytes)
9
+ * @param addressMerkleTreePubkey Merkle tree public key
10
+ * @param programId Program ID
11
+ * @returns Derived address
12
+ */
13
+ export declare function deriveAddressV2(addressSeed: Uint8Array, addressMerkleTreePubkey: PublicKey, programId: PublicKey): PublicKey;
14
+ export interface NewAddressParams {
15
+ /**
16
+ * Seed for the compressed account. Must be seed used to derive
17
+ * newAccountAddress
18
+ */
19
+ seed: Uint8Array;
20
+ /**
21
+ * Recent state root index of the address tree. The expiry is tied to the
22
+ * validity proof.
23
+ */
24
+ addressMerkleTreeRootIndex: number;
25
+ /**
26
+ * Address tree pubkey. Must be base pubkey used to derive new address
27
+ */
28
+ addressMerkleTreePubkey: PublicKey;
29
+ /**
30
+ * Address space queue pubkey. Associated with the state tree.
31
+ */
32
+ addressQueuePubkey: PublicKey;
33
+ }
34
+ export interface NewAddressParamsPacked {
35
+ /**
36
+ * Seed for the compressed account. Must be seed used to derive
37
+ * newAccountAddress
38
+ */
39
+ seed: number[];
40
+ /**
41
+ * Recent state root index of the address tree. The expiry is tied to the
42
+ * validity proof.
43
+ */
44
+ addressMerkleTreeRootIndex: number;
45
+ /**
46
+ * Index of the address merkle tree account in the remaining accounts array
47
+ */
48
+ addressMerkleTreeAccountIndex: number;
49
+ /**
50
+ * Index of the address queue account in the remaining accounts array
51
+ */
52
+ addressQueueAccountIndex: number;
53
+ }
54
+ /**
55
+ * Packs new address params for instruction data in TypeScript clients
56
+ *
57
+ * @param newAddressParams New address params
58
+ * @param remainingAccounts Remaining accounts
59
+ * @returns Packed new address params
60
+ */
61
+ export declare function packNewAddressParams(newAddressParams: NewAddressParams[], remainingAccounts: PublicKey[]): {
62
+ newAddressParamsPacked: NewAddressParamsPacked[];
63
+ remainingAccounts: PublicKey[];
64
+ };
@@ -0,0 +1,7 @@
1
+ import { Commitment, Connection, PublicKey } from '@solana/web3.js';
2
+ export declare function airdropSol({ connection, lamports, recipientPublicKey, }: {
3
+ connection: Connection;
4
+ lamports: number;
5
+ recipientPublicKey: PublicKey;
6
+ }): Promise<string>;
7
+ export declare function confirmTransaction(connection: Connection, signature: string, confirmation?: Commitment): Promise<import("@solana/web3.js").RpcResponseAndContext<import("@solana/web3.js").SignatureResult>>;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @param targetLamports - Target priority fee in lamports
3
+ * @param computeUnits - Expected compute units used by the transaction
4
+ * @returns microLamports per compute unit (use in
5
+ * {@link https://github.com/solana-foundation/solana-web3.js/blob/maintenance/v1.x/src/programs/compute-budget.ts#L218})
6
+ */
7
+ export declare function calculateComputeUnitPrice(targetLamports: number, computeUnits: number): number;
@@ -0,0 +1,36 @@
1
+ import { Buffer } from 'buffer';
2
+ import { Keypair } from '@solana/web3.js';
3
+ import BN from 'bn.js';
4
+ import { InstructionDataInvoke } from '../state';
5
+ export declare function byteArrayToKeypair(byteArray: number[]): Keypair;
6
+ /**
7
+ * @internal
8
+ * convert BN to hex with '0x' prefix
9
+ */
10
+ export declare function toHex(bn: BN): string;
11
+ export declare const toArray: <T>(value: T | T[]) => T[];
12
+ export declare const bufToDecStr: (buf: Buffer) => string;
13
+ export declare function isSmallerThanBn254FieldSizeBe(bytes: Buffer): boolean;
14
+ export declare const toCamelCase: (object: any) => any;
15
+ /**
16
+ /**
17
+ * Hash the provided `bytes` with Keccak256 and ensure the result fits in the
18
+ * BN254 prime field by repeatedly hashing the inputs with various "bump seeds"
19
+ * and truncating the resulting hash to 31 bytes.
20
+ *
21
+ * @deprecated Use `hashvToBn254FieldSizeBe` instead.
22
+ */
23
+ export declare function hashToBn254FieldSizeBe(bytes: Buffer): [Buffer, number] | null;
24
+ export declare function hashvToBn254FieldSizeBeU8Array(bytes: Uint8Array[]): Uint8Array;
25
+ /**
26
+ * Hash the provided `bytes` with Keccak256 and ensure that the result fits in
27
+ * the BN254 prime field by truncating the resulting hash to 31 bytes.
28
+ *
29
+ * @param bytes Input bytes
30
+ *
31
+ * @returns Hash digest
32
+ */
33
+ export declare function hashvToBn254FieldSizeBe(bytes: Uint8Array[]): Uint8Array;
34
+ /** Mutates array in place */
35
+ export declare function pushUniqueItems<T>(items: T[], map: T[]): void;
36
+ export declare function convertInvokeCpiWithReadOnlyToInvoke(data: any): InstructionDataInvoke;
@@ -0,0 +1,3 @@
1
+ import { Signer } from '@solana/web3.js';
2
+ /** @internal remove signer from signers if part of signers */
3
+ export declare function dedupeSigner(signer: Signer, signers: Signer[]): Signer[];
@@ -0,0 +1,48 @@
1
+ import { Connection, PublicKey } from '@solana/web3.js';
2
+ import { TreeInfo, TreeType } from '../state/types';
3
+ import { StateTreeLUTPair } from '../constants';
4
+ /**
5
+ * @deprecated use {@link getTreeInfoByPubkey} instead
6
+ */
7
+ export declare function getStateTreeInfoByPubkey(treeInfos: TreeInfo[], treeOrQueue: PublicKey): TreeInfo;
8
+ export declare function getTreeInfoByPubkey(treeInfos: TreeInfo[], treeOrQueue: PublicKey): TreeInfo;
9
+ /**
10
+ * @deprecated use {@link selectStateTreeInfo} instead.
11
+ *
12
+ * Get a random tree and queue from a set of provided state tree infos.
13
+ *
14
+ * @param infos Set of state tree infos
15
+ * @returns A random tree and queue
16
+ */
17
+ export declare function pickRandomTreeAndQueue(infos: TreeInfo[]): {
18
+ tree: PublicKey;
19
+ queue: PublicKey;
20
+ };
21
+ /**
22
+ * Select a pseudo-random active state tree info from the set of provided state
23
+ * tree infos.
24
+ *
25
+ * Using this reduces write-lock contention on state trees.
26
+ *
27
+ * @param infos Set of state tree infos
28
+ *
29
+ * @param treeType Optional: Only use if you know what you are
30
+ * doing. The type of tree.
31
+ * @param useMaxConcurrency Optional: Only use if you know what you are
32
+ * doing. If true, select from all infos.
33
+ *
34
+ * @returns A pseudo-randomly selected tree info
35
+ */
36
+ export declare function selectStateTreeInfo(infos: TreeInfo[], treeType?: TreeType, useMaxConcurrency?: boolean): TreeInfo;
37
+ /**
38
+ * Get active state tree infos from LUTs.
39
+ *
40
+ * @param connection The connection to the cluster
41
+ * @param stateTreeLUTPairs The state tree lookup table pairs
42
+ *
43
+ * @returns The active state tree infos
44
+ */
45
+ export declare function getAllStateTreeInfos({ connection, stateTreeLUTPairs, }: {
46
+ connection: Connection;
47
+ stateTreeLUTPairs: StateTreeLUTPair[];
48
+ }): Promise<TreeInfo[]>;
@@ -0,0 +1,13 @@
1
+ export * from './address';
2
+ export * from './airdrop';
3
+ export * from './calculate-compute-unit-price';
4
+ export * from './conversion';
5
+ export * from './dedupe-signer';
6
+ export * from './instruction';
7
+ export * from './parse-validity-proof';
8
+ export * from './pipe';
9
+ export * from './send-and-confirm';
10
+ export * from './sleep';
11
+ export * from './validation';
12
+ export * from './state-tree-lookup-table';
13
+ export * from './get-state-tree-infos';
@@ -0,0 +1,35 @@
1
+ import { AccountMeta, PublicKey } from '@solana/web3.js';
2
+ export declare class PackedAccounts {
3
+ private preAccounts;
4
+ private systemAccounts;
5
+ private nextIndex;
6
+ private map;
7
+ static newWithSystemAccounts(config: SystemAccountMetaConfig): PackedAccounts;
8
+ static newWithSystemAccountsV2(config: SystemAccountMetaConfig): PackedAccounts;
9
+ addPreAccountsSigner(pubkey: PublicKey): void;
10
+ addPreAccountsSignerMut(pubkey: PublicKey): void;
11
+ addPreAccountsMeta(accountMeta: AccountMeta): void;
12
+ addSystemAccounts(config: SystemAccountMetaConfig): void;
13
+ addSystemAccountsV2(config: SystemAccountMetaConfig): void;
14
+ insertOrGet(pubkey: PublicKey): number;
15
+ insertOrGetReadOnly(pubkey: PublicKey): number;
16
+ insertOrGetConfig(pubkey: PublicKey, isSigner: boolean, isWritable: boolean): number;
17
+ private hashSetAccountsToMetas;
18
+ private getOffsets;
19
+ toAccountMetas(): {
20
+ remainingAccounts: AccountMeta[];
21
+ systemStart: number;
22
+ packedStart: number;
23
+ };
24
+ }
25
+ export declare class SystemAccountMetaConfig {
26
+ selfProgram: PublicKey;
27
+ cpiContext?: PublicKey;
28
+ solCompressionRecipient?: PublicKey;
29
+ solPoolPda?: PublicKey;
30
+ private constructor();
31
+ static new(selfProgram: PublicKey): SystemAccountMetaConfig;
32
+ static newWithCpiContext(selfProgram: PublicKey, cpiContext: PublicKey): SystemAccountMetaConfig;
33
+ }
34
+ export declare function getLightSystemAccountMetas(config: SystemAccountMetaConfig): AccountMeta[];
35
+ export declare function getLightSystemAccountMetasV2(config: SystemAccountMetaConfig): AccountMeta[];
@@ -0,0 +1,20 @@
1
+ import { ValidityProof } from '../state';
2
+ interface GnarkProofJson {
3
+ ar: string[];
4
+ bs: string[][];
5
+ krs: string[];
6
+ }
7
+ type ProofABC = {
8
+ a: Uint8Array;
9
+ b: Uint8Array;
10
+ c: Uint8Array;
11
+ };
12
+ export declare const placeholderValidityProof: () => {
13
+ a: number[];
14
+ b: number[];
15
+ c: number[];
16
+ };
17
+ export declare const checkValidityProofShape: (proof: ValidityProof) => void;
18
+ export declare function proofFromJsonStruct(json: GnarkProofJson): ProofABC;
19
+ export declare function negateAndCompressProof(proof: ProofABC): ValidityProof;
20
+ export {};
@@ -0,0 +1,2 @@
1
+ /** pipe function */
2
+ export declare function pipe<T, R>(initialFunction: (arg: T) => R, ...functions: ((arg: R) => R)[]): (initialValue: T) => R;
@@ -0,0 +1,52 @@
1
+ import { VersionedTransaction, SignatureResult, RpcResponseAndContext, Signer, TransactionInstruction, ConfirmOptions, TransactionSignature, PublicKey, AddressLookupTableAccount } from '@solana/web3.js';
2
+ import { Rpc } from '../rpc';
3
+ /**
4
+ * Builds a versioned Transaction from instructions.
5
+ *
6
+ * @param instructions instructions to include
7
+ * @param payerPublicKey fee payer public key
8
+ * @param blockhash blockhash to use
9
+ * @param lookupTableAccounts lookup table accounts to include
10
+ *
11
+ * @return VersionedTransaction
12
+ */
13
+ export declare function buildTx(instructions: TransactionInstruction[], payerPublicKey: PublicKey, blockhash: string, lookupTableAccounts?: AddressLookupTableAccount[]): VersionedTransaction;
14
+ /**
15
+ * Sends a versioned transaction and confirms it.
16
+ *
17
+ * @param rpc connection to use
18
+ * @param tx versioned transaction to send
19
+ * @param confirmOptions confirmation options
20
+ * @param blockHashCtx blockhash context for confirmation
21
+ *
22
+ * @return TransactionSignature
23
+ */
24
+ export declare function sendAndConfirmTx(rpc: Rpc, tx: VersionedTransaction, confirmOptions?: ConfirmOptions, blockHashCtx?: {
25
+ blockhash: string;
26
+ lastValidBlockHeight: number;
27
+ }): Promise<TransactionSignature>;
28
+ /**
29
+ * Confirms a transaction with a given txId.
30
+ *
31
+ * @param rpc connection to use
32
+ * @param txId transaction signature to confirm
33
+ * @param confirmOptions confirmation options
34
+ * @param blockHashCtx blockhash context for confirmation
35
+ * @return SignatureResult
36
+ */
37
+ export declare function confirmTx(rpc: Rpc, txId: string, confirmOptions?: ConfirmOptions, _blockHashCtx?: {
38
+ blockhash: string;
39
+ lastValidBlockHeight: number;
40
+ }): Promise<RpcResponseAndContext<SignatureResult>>;
41
+ /**
42
+ * Builds a versioned Transaction from instructions and signs it.
43
+ *
44
+ * @param instructions instructions to include in the transaction
45
+ * @param payer payer of the transaction
46
+ * @param blockhash recent blockhash to use in the transaction
47
+ * @param additionalSigners non-feepayer signers to include in the
48
+ * transaction
49
+ * @param lookupTableAccounts lookup table accounts to include in the
50
+ * transaction
51
+ */
52
+ export declare function buildAndSignTx(instructions: TransactionInstruction[], payer: Signer, blockhash: string, additionalSigners?: Signer[], lookupTableAccounts?: AddressLookupTableAccount[]): VersionedTransaction;
@@ -0,0 +1 @@
1
+ export declare function sleep(ms: number): Promise<void>;
@@ -0,0 +1,68 @@
1
+ import { PublicKey, Keypair, Connection } from '@solana/web3.js';
2
+ /**
3
+ * Create two lookup tables storing all public state tree and queue addresses
4
+ * returns lookup table addresses and txId
5
+ *
6
+ * @internal
7
+ * @param connection Connection to the Solana network
8
+ * @param payer Keypair of the payer
9
+ * @param authority Keypair of the authority
10
+ * @param recentSlot Slot of the recent block
11
+ */
12
+ export declare function createStateTreeLookupTable({ connection, payer, authority, recentSlot, }: {
13
+ connection: Connection;
14
+ payer: Keypair;
15
+ authority: Keypair;
16
+ recentSlot: number;
17
+ }): Promise<{
18
+ address: PublicKey;
19
+ txId: string;
20
+ }>;
21
+ /**
22
+ * Extend state tree lookup table with new state tree and queue addresses
23
+ *
24
+ * @internal
25
+ * @param connection Connection to the Solana network
26
+ * @param tableAddress Address of the lookup table to extend
27
+ * @param newStateTreeAddresses Addresses of the new state trees to add
28
+ * @param newQueueAddresses Addresses of the new queues to add
29
+ * @param newCpiContextAddresses Addresses of the new cpi contexts to add
30
+ * @param payer Keypair of the payer
31
+ * @param authority Keypair of the authority
32
+ */
33
+ export declare function extendStateTreeLookupTable({ connection, tableAddress, newStateTreeAddresses, newQueueAddresses, newCpiContextAddresses, payer, authority, }: {
34
+ connection: Connection;
35
+ tableAddress: PublicKey;
36
+ newStateTreeAddresses: PublicKey[];
37
+ newQueueAddresses: PublicKey[];
38
+ newCpiContextAddresses: PublicKey[];
39
+ payer: Keypair;
40
+ authority: Keypair;
41
+ }): Promise<{
42
+ tableAddress: PublicKey;
43
+ txId: string;
44
+ }>;
45
+ /**
46
+ * Adds state tree address to lookup table. Acts as nullifier lookup for rolled
47
+ * over state trees.
48
+ *
49
+ * @internal
50
+ * @param connection Connection to the Solana network
51
+ * @param stateTreeAddress Address of the state tree to nullify
52
+ * @param nullifyLookupTableAddress Address of the nullifier lookup table to
53
+ * store address in
54
+ * @param stateTreeLookupTableAddress lookup table storing all state tree
55
+ * addresses
56
+ * @param payer Keypair of the payer
57
+ * @param authority Keypair of the authority
58
+ */
59
+ export declare function nullifyLookupTable({ connection, fullStateTreeAddress, nullifyLookupTableAddress, stateTreeLookupTableAddress, payer, authority, }: {
60
+ connection: Connection;
61
+ fullStateTreeAddress: PublicKey;
62
+ nullifyLookupTableAddress: PublicKey;
63
+ stateTreeLookupTableAddress: PublicKey;
64
+ payer: Keypair;
65
+ authority: Keypair;
66
+ }): Promise<{
67
+ txId: string;
68
+ }>;
@@ -0,0 +1,8 @@
1
+ import BN from 'bn.js';
2
+ import { CompressedAccountLegacy, CompressedAccountWithMerkleContext } from '../state';
3
+ export declare const validateSufficientBalance: (balance: BN) => void;
4
+ export declare const validateSameOwner: (compressedAccounts: CompressedAccountLegacy[] | CompressedAccountWithMerkleContext[]) => void;
5
+ export declare const validateNumbersForProof: (hashesLength: number, newAddressesLength: number) => void;
6
+ export declare const validateNumbersForInclusionProof: (hashesLength: number) => void;
7
+ export declare const validateNumbersForNonInclusionProof: (newAddressesLength: number) => void;
8
+ export declare const validateNumbers: (length: number, allowedNumbers: number[], type: string) => void;