@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.
- package/README.md +10 -10
- package/dist/cjs/browser/constants.d.ts +24 -7
- package/dist/cjs/browser/index.cjs +1 -1
- package/dist/cjs/browser/index.cjs.map +1 -1
- package/dist/cjs/browser/rpc-interface.d.ts +275 -275
- package/dist/cjs/browser/rpc.d.ts +5 -1
- package/dist/cjs/browser/test-helpers/test-rpc/test-rpc.d.ts +4 -0
- package/dist/cjs/browser/utils/address.d.ts +7 -6
- package/dist/cjs/browser/utils/conversion.d.ts +1 -0
- package/dist/cjs/browser/utils/index.d.ts +1 -0
- package/dist/cjs/browser/utils/instruction.d.ts +35 -0
- package/dist/cjs/node/constants.d.ts +24 -7
- package/dist/cjs/node/index.cjs +1 -1
- package/dist/cjs/node/index.cjs.map +1 -1
- package/dist/cjs/node/rpc-interface.d.ts +275 -275
- package/dist/cjs/node/rpc.d.ts +5 -1
- package/dist/cjs/node/test-helpers/test-rpc/test-rpc.d.ts +4 -0
- package/dist/cjs/node/utils/address.d.ts +7 -6
- package/dist/cjs/node/utils/conversion.d.ts +1 -0
- package/dist/cjs/node/utils/index.d.ts +1 -0
- package/dist/cjs/node/utils/instruction.d.ts +35 -0
- package/dist/es/browser/actions/compress.d.ts +18 -0
- package/dist/es/browser/actions/create-account.d.ts +38 -0
- package/dist/es/browser/actions/decompress.d.ts +15 -0
- package/dist/es/browser/actions/index.d.ts +5 -0
- package/dist/es/browser/actions/transfer.d.ts +16 -0
- package/dist/es/browser/constants.d.ts +157 -0
- package/dist/es/browser/errors.d.ts +74 -0
- package/dist/es/browser/index.d.ts +9 -0
- package/dist/es/browser/index.js +2 -0
- package/dist/es/browser/index.js.map +1 -0
- package/dist/es/browser/programs/index.d.ts +1 -0
- package/dist/es/browser/programs/system/idl.d.ts +997 -0
- package/dist/es/browser/programs/system/index.d.ts +5 -0
- package/dist/es/browser/programs/system/layout.d.ts +77 -0
- package/dist/es/browser/programs/system/pack.d.ts +74 -0
- package/dist/es/browser/programs/system/program.d.ts +175 -0
- package/dist/es/browser/programs/system/select-compressed-accounts.d.ts +10 -0
- package/dist/es/browser/rpc-interface.d.ts +2779 -0
- package/dist/es/browser/rpc.d.ts +284 -0
- package/dist/es/browser/state/BN254.d.ts +13 -0
- package/dist/es/browser/state/bn.d.ts +3 -0
- package/dist/es/browser/state/compressed-account.d.ts +205 -0
- package/dist/es/browser/state/index.d.ts +4 -0
- package/dist/es/browser/state/types.d.ts +449 -0
- package/dist/es/browser/test-helpers/index.d.ts +3 -0
- package/dist/es/browser/test-helpers/merkle-tree/index.d.ts +2 -0
- package/dist/es/browser/test-helpers/merkle-tree/indexed-array.d.ts +85 -0
- package/dist/es/browser/test-helpers/merkle-tree/merkle-tree.d.ts +92 -0
- package/dist/es/browser/test-helpers/test-rpc/get-compressed-accounts.d.ts +7 -0
- package/dist/es/browser/test-helpers/test-rpc/get-compressed-token-accounts.d.ts +40 -0
- package/dist/es/browser/test-helpers/test-rpc/get-parsed-events.d.ts +15 -0
- package/dist/es/browser/test-helpers/test-rpc/index.d.ts +3 -0
- package/dist/es/browser/test-helpers/test-rpc/test-rpc.d.ts +239 -0
- package/dist/es/browser/test-helpers/test-utils.d.ts +31 -0
- package/dist/es/browser/utils/address.d.ts +64 -0
- package/dist/es/browser/utils/airdrop.d.ts +7 -0
- package/dist/es/browser/utils/calculate-compute-unit-price.d.ts +7 -0
- package/dist/es/browser/utils/conversion.d.ts +36 -0
- package/dist/es/browser/utils/dedupe-signer.d.ts +3 -0
- package/dist/es/browser/utils/get-state-tree-infos.d.ts +48 -0
- package/dist/es/browser/utils/index.d.ts +13 -0
- package/dist/es/browser/utils/instruction.d.ts +35 -0
- package/dist/es/browser/utils/parse-validity-proof.d.ts +20 -0
- package/dist/es/browser/utils/pipe.d.ts +2 -0
- package/dist/es/browser/utils/send-and-confirm.d.ts +52 -0
- package/dist/es/browser/utils/sleep.d.ts +1 -0
- package/dist/es/browser/utils/state-tree-lookup-table.d.ts +68 -0
- package/dist/es/browser/utils/validation.d.ts +8 -0
- package/dist/types/index.d.ts +78 -16
- package/package.json +16 -8
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import { Connection, ConnectionConfig, PublicKey } from '@solana/web3.js';
|
|
2
|
+
import { Buffer } from 'buffer';
|
|
3
|
+
import { ValidityProofWithContext, CompressedTransaction, CompressionApiInterface, GetCompressedTokenAccountsByOwnerOrDelegateOptions, HexInputsForProver, ParsedTokenAccount, SignatureWithMetadata, LatestNonVotingSignatures, LatestNonVotingSignaturesPaginated, WithContext, GetCompressedAccountsByOwnerConfig, WithCursor, AddressWithTree, HashWithTree, CompressedMintTokenHolders, TokenBalance, PaginatedOptions } from './rpc-interface';
|
|
4
|
+
import { MerkleContextWithMerkleProof, BN254, CompressedAccountWithMerkleContext, ValidityProof, AddressTreeInfo } from './state';
|
|
5
|
+
import BN from 'bn.js';
|
|
6
|
+
import { LightWasm } from './test-helpers';
|
|
7
|
+
import { TreeInfo } from './state/types';
|
|
8
|
+
/** @internal */
|
|
9
|
+
export declare function parseAccountData({ discriminator, data, dataHash, }: {
|
|
10
|
+
discriminator: BN;
|
|
11
|
+
data: string;
|
|
12
|
+
dataHash: BN;
|
|
13
|
+
}): {
|
|
14
|
+
discriminator: number[];
|
|
15
|
+
data: Buffer<ArrayBuffer>;
|
|
16
|
+
dataHash: number[];
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Establish a Compression-compatible JSON RPC connection
|
|
20
|
+
*
|
|
21
|
+
* @param endpointOrWeb3JsConnection endpoint to the solana cluster or
|
|
22
|
+
* Connection object
|
|
23
|
+
* @param compressionApiEndpoint Endpoint to the compression server
|
|
24
|
+
* @param proverEndpoint Endpoint to the prover server. defaults
|
|
25
|
+
* to endpoint
|
|
26
|
+
* @param connectionConfig Optional connection config
|
|
27
|
+
*/
|
|
28
|
+
export declare function createRpc(endpointOrWeb3JsConnection?: string | Connection, compressionApiEndpoint?: string, proverEndpoint?: string, config?: ConnectionConfig): Rpc;
|
|
29
|
+
/**
|
|
30
|
+
* Helper function to preprocess the response to wrap numbers as strings
|
|
31
|
+
* @param {string} text - The JSON string to preprocess
|
|
32
|
+
* @returns {string} - The preprocessed JSON string with numbers wrapped as strings
|
|
33
|
+
*/
|
|
34
|
+
export declare function wrapBigNumbersAsStrings(text: string): string;
|
|
35
|
+
/** @internal */
|
|
36
|
+
export declare const rpcRequest: (rpcEndpoint: string, method: string, params?: any, convertToCamelCase?: boolean, debug?: boolean) => Promise<any>;
|
|
37
|
+
/** @internal */
|
|
38
|
+
export declare const proverRequest: (proverEndpoint: string, method: "inclusion" | "new-address" | "combined", params?: any, log?: boolean, _publicInputHash?: BN | undefined) => Promise<ValidityProof>;
|
|
39
|
+
export type NonInclusionMerkleProofInputs = {
|
|
40
|
+
root: BN;
|
|
41
|
+
value: BN;
|
|
42
|
+
leaf_lower_range_value: BN;
|
|
43
|
+
leaf_higher_range_value: BN;
|
|
44
|
+
nextIndex: BN;
|
|
45
|
+
merkle_proof_hashed_indexed_element_leaf: BN[];
|
|
46
|
+
index_hashed_indexed_element_leaf: BN;
|
|
47
|
+
};
|
|
48
|
+
export type MerkleContextWithNewAddressProof = {
|
|
49
|
+
root: BN;
|
|
50
|
+
rootIndex: number;
|
|
51
|
+
value: BN;
|
|
52
|
+
leafLowerRangeValue: BN;
|
|
53
|
+
leafHigherRangeValue: BN;
|
|
54
|
+
nextIndex: BN;
|
|
55
|
+
merkleProofHashedIndexedElementLeaf: BN[];
|
|
56
|
+
indexHashedIndexedElementLeaf: BN;
|
|
57
|
+
treeInfo: AddressTreeInfo;
|
|
58
|
+
};
|
|
59
|
+
export type NonInclusionJsonStruct = {
|
|
60
|
+
root: string;
|
|
61
|
+
value: string;
|
|
62
|
+
pathIndex: number;
|
|
63
|
+
pathElements: string[];
|
|
64
|
+
leafLowerRangeValue: string;
|
|
65
|
+
leafHigherRangeValue: string;
|
|
66
|
+
nextIndex: number;
|
|
67
|
+
};
|
|
68
|
+
export declare function convertMerkleProofsWithContextToHex(merkleProofsWithContext: MerkleContextWithMerkleProof[]): HexInputsForProver[];
|
|
69
|
+
export declare function convertNonInclusionMerkleProofInputsToHex(nonInclusionMerkleProofInputs: MerkleContextWithNewAddressProof[]): NonInclusionJsonStruct[];
|
|
70
|
+
export declare function getPublicInputHash(accountProofs: MerkleContextWithMerkleProof[], accountHashes: BN254[], newAddressProofs: MerkleContextWithNewAddressProof[], lightWasm: LightWasm): BN;
|
|
71
|
+
export interface NullifierMetadata {
|
|
72
|
+
nullifier: BN254;
|
|
73
|
+
txHash: BN254;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
*
|
|
77
|
+
*/
|
|
78
|
+
export declare class Rpc extends Connection implements CompressionApiInterface {
|
|
79
|
+
compressionApiEndpoint: string;
|
|
80
|
+
proverEndpoint: string;
|
|
81
|
+
allStateTreeInfos: TreeInfo[] | null;
|
|
82
|
+
lastStateTreeFetchTime: number | null;
|
|
83
|
+
CACHE_TTL: number;
|
|
84
|
+
fetchPromise: Promise<TreeInfo[]> | null;
|
|
85
|
+
constructor(endpoint: string, compressionApiEndpoint: string, proverEndpoint: string, config?: ConnectionConfig);
|
|
86
|
+
/**
|
|
87
|
+
* @deprecated Use {@link getStateTreeInfos} instead
|
|
88
|
+
*/
|
|
89
|
+
getCachedActiveStateTreeInfo(): Promise<void>;
|
|
90
|
+
/**
|
|
91
|
+
* @deprecated Use {@link getStateTreeInfos} instead
|
|
92
|
+
*/
|
|
93
|
+
getCachedActiveStateTreeInfos(): Promise<void>;
|
|
94
|
+
/**
|
|
95
|
+
* Get a list of all state tree infos. If not already cached, fetches from
|
|
96
|
+
* the cluster.
|
|
97
|
+
*/
|
|
98
|
+
getStateTreeInfos(): Promise<TreeInfo[]>;
|
|
99
|
+
/**
|
|
100
|
+
* @internal
|
|
101
|
+
*/
|
|
102
|
+
doFetch(): Promise<TreeInfo[]>;
|
|
103
|
+
/**
|
|
104
|
+
* Get a V2 address tree info.
|
|
105
|
+
*/
|
|
106
|
+
getAddressTreeInfoV2(): Promise<TreeInfo>;
|
|
107
|
+
/**
|
|
108
|
+
* Fetch the compressed account for the specified account address or hash
|
|
109
|
+
*/
|
|
110
|
+
getCompressedAccount(address?: BN254, hash?: BN254): Promise<CompressedAccountWithMerkleContext | null>;
|
|
111
|
+
/**
|
|
112
|
+
* Fetch the compressed balance for the specified account address or hash
|
|
113
|
+
*/
|
|
114
|
+
getCompressedBalance(address?: BN254, hash?: BN254): Promise<BN>;
|
|
115
|
+
/**
|
|
116
|
+
* Fetch the total compressed balance for the specified owner public key
|
|
117
|
+
*/
|
|
118
|
+
getCompressedBalanceByOwner(owner: PublicKey): Promise<BN>;
|
|
119
|
+
/**
|
|
120
|
+
* Fetch the latest merkle proof for the specified account hash from the
|
|
121
|
+
* cluster
|
|
122
|
+
*/
|
|
123
|
+
getCompressedAccountProof(hash: BN254): Promise<MerkleContextWithMerkleProof>;
|
|
124
|
+
/**
|
|
125
|
+
* Fetch all the account info for multiple compressed accounts specified by
|
|
126
|
+
* an array of account hashes
|
|
127
|
+
*/
|
|
128
|
+
getMultipleCompressedAccounts(hashes: BN254[]): Promise<CompressedAccountWithMerkleContext[]>;
|
|
129
|
+
/**
|
|
130
|
+
* Fetch the latest merkle proofs for multiple compressed accounts specified
|
|
131
|
+
* by an array account hashes
|
|
132
|
+
*/
|
|
133
|
+
getMultipleCompressedAccountProofs(hashes: BN254[]): Promise<MerkleContextWithMerkleProof[]>;
|
|
134
|
+
/**
|
|
135
|
+
* Fetch all the compressed accounts owned by the specified public key.
|
|
136
|
+
* Owner can be a program or user account
|
|
137
|
+
*/
|
|
138
|
+
getCompressedAccountsByOwner(owner: PublicKey, config?: GetCompressedAccountsByOwnerConfig | undefined): Promise<WithCursor<CompressedAccountWithMerkleContext[]>>;
|
|
139
|
+
/**
|
|
140
|
+
* Fetch all the compressed token accounts owned by the specified public
|
|
141
|
+
* key. Owner can be a program or user account
|
|
142
|
+
*/
|
|
143
|
+
getCompressedTokenAccountsByOwner(owner: PublicKey, options?: GetCompressedTokenAccountsByOwnerOrDelegateOptions): Promise<WithCursor<ParsedTokenAccount[]>>;
|
|
144
|
+
/**
|
|
145
|
+
* Fetch all the compressed accounts delegated to the specified public key.
|
|
146
|
+
*/
|
|
147
|
+
getCompressedTokenAccountsByDelegate(delegate: PublicKey, options?: GetCompressedTokenAccountsByOwnerOrDelegateOptions): Promise<WithCursor<ParsedTokenAccount[]>>;
|
|
148
|
+
/**
|
|
149
|
+
* Fetch the compressed token balance for the specified account hash
|
|
150
|
+
*/
|
|
151
|
+
getCompressedTokenAccountBalance(hash: BN254): Promise<{
|
|
152
|
+
amount: BN;
|
|
153
|
+
}>;
|
|
154
|
+
/**
|
|
155
|
+
* @deprecated use {@link getCompressedTokenBalancesByOwnerV2} instead.
|
|
156
|
+
*
|
|
157
|
+
* Fetch all the compressed token balances owned by the specified public
|
|
158
|
+
* key. Can filter by mint. Returns without context.
|
|
159
|
+
*/
|
|
160
|
+
getCompressedTokenBalancesByOwner(owner: PublicKey, options?: GetCompressedTokenAccountsByOwnerOrDelegateOptions): Promise<WithCursor<TokenBalance[]>>;
|
|
161
|
+
/**
|
|
162
|
+
* Fetch the compressed token balances owned by the specified public
|
|
163
|
+
* key. Paginated. Can filter by mint. Returns with context.
|
|
164
|
+
*/
|
|
165
|
+
getCompressedTokenBalancesByOwnerV2(owner: PublicKey, options?: GetCompressedTokenAccountsByOwnerOrDelegateOptions): Promise<WithContext<WithCursor<TokenBalance[]>>>;
|
|
166
|
+
/**
|
|
167
|
+
* Returns confirmed compression signatures for transactions involving the specified
|
|
168
|
+
* account hash forward in time from genesis to the most recent confirmed
|
|
169
|
+
* block
|
|
170
|
+
*
|
|
171
|
+
* @param hash queried account hash
|
|
172
|
+
*/
|
|
173
|
+
getCompressionSignaturesForAccount(hash: BN254): Promise<SignatureWithMetadata[]>;
|
|
174
|
+
/**
|
|
175
|
+
* Fetch a confirmed or finalized transaction from the cluster. Return with
|
|
176
|
+
* CompressionInfo
|
|
177
|
+
*/
|
|
178
|
+
getTransactionWithCompressionInfo(signature: string): Promise<CompressedTransaction | null>;
|
|
179
|
+
/**
|
|
180
|
+
* Returns confirmed signatures for transactions involving the specified
|
|
181
|
+
* address forward in time from genesis to the most recent confirmed 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
|
+
* Ensure that the Compression Indexer has already indexed the transaction
|
|
206
|
+
*/
|
|
207
|
+
confirmTransactionIndexed(slot: number): Promise<boolean>;
|
|
208
|
+
/**
|
|
209
|
+
* Fetch the current slot that the node is processing
|
|
210
|
+
*/
|
|
211
|
+
getIndexerSlot(): Promise<number>;
|
|
212
|
+
/**
|
|
213
|
+
* Fetch all the compressed token holders for a given mint. Paginated.
|
|
214
|
+
*/
|
|
215
|
+
getCompressedMintTokenHolders(mint: PublicKey, options?: PaginatedOptions): Promise<WithContext<WithCursor<CompressedMintTokenHolders[]>>>;
|
|
216
|
+
/**
|
|
217
|
+
* Fetch the latest compression signatures on the cluster. Results are
|
|
218
|
+
* paginated.
|
|
219
|
+
*/
|
|
220
|
+
getLatestCompressionSignatures(cursor?: string, limit?: number): Promise<LatestNonVotingSignaturesPaginated>;
|
|
221
|
+
/**
|
|
222
|
+
* Fetch all non-voting signatures
|
|
223
|
+
*/
|
|
224
|
+
getLatestNonVotingSignatures(limit?: number, cursor?: string): Promise<LatestNonVotingSignatures>;
|
|
225
|
+
/**
|
|
226
|
+
* Fetch the latest address proofs for new unique addresses specified by an
|
|
227
|
+
* array of addresses.
|
|
228
|
+
*
|
|
229
|
+
* the proof states that said address have not yet been created in
|
|
230
|
+
* respective address tree.
|
|
231
|
+
* @param addresses Array of BN254 new addresses
|
|
232
|
+
* @returns Array of validity proofs for new addresses
|
|
233
|
+
*/
|
|
234
|
+
getMultipleNewAddressProofs(addresses: BN254[]): Promise<MerkleContextWithNewAddressProof[]>;
|
|
235
|
+
/**
|
|
236
|
+
* @deprecated use {@link getValidityProofV0} instead.
|
|
237
|
+
*
|
|
238
|
+
* Fetch the latest validity proof for (1) compressed accounts specified by
|
|
239
|
+
* an array of account hashes. (2) new unique addresses specified by an
|
|
240
|
+
* array of addresses.
|
|
241
|
+
*
|
|
242
|
+
* Validity proofs prove the presence of compressed accounts in state trees
|
|
243
|
+
* and the non-existence of addresses in address trees, respectively. They
|
|
244
|
+
* enable verification without recomputing the merkle proof path, thus
|
|
245
|
+
* lowering verification and data costs.
|
|
246
|
+
*
|
|
247
|
+
* @param hashes Array of BN254 hashes.
|
|
248
|
+
* @param newAddresses Array of BN254 new addresses.
|
|
249
|
+
* @returns validity proof with context
|
|
250
|
+
*/
|
|
251
|
+
getValidityProof(hashes?: BN254[], newAddresses?: BN254[]): Promise<ValidityProofWithContext>;
|
|
252
|
+
/**
|
|
253
|
+
* Fetch the latest validity proof for (1) compressed accounts specified by
|
|
254
|
+
* an array of account hashes. (2) new unique addresses specified by an
|
|
255
|
+
* array of addresses.
|
|
256
|
+
*
|
|
257
|
+
* Validity proofs prove the presence of compressed accounts in state trees
|
|
258
|
+
* and the non-existence of addresses in address trees, respectively. They
|
|
259
|
+
* enable verification without recomputing the merkle proof path, thus
|
|
260
|
+
* lowering verification and data costs.
|
|
261
|
+
*
|
|
262
|
+
* @param hashes Array of { hash: BN254, tree: PublicKey, queue: PublicKey }.
|
|
263
|
+
* @param newAddresses Array of { address: BN254, tree: PublicKey, queue: PublicKey }.
|
|
264
|
+
* @returns validity proof with context
|
|
265
|
+
*/
|
|
266
|
+
getValidityProofV0(hashes?: HashWithTree[], newAddresses?: AddressWithTree[]): Promise<ValidityProofWithContext>;
|
|
267
|
+
/**
|
|
268
|
+
* Fetch the latest validity proof for (1) compressed accounts specified by
|
|
269
|
+
* an array of account hashes. (2) new unique addresses specified by an
|
|
270
|
+
* array of addresses. Returns with context slot.
|
|
271
|
+
*
|
|
272
|
+
* Validity proofs prove the presence of compressed accounts in state trees
|
|
273
|
+
* and the non-existence of addresses in address trees, respectively. They
|
|
274
|
+
* enable verification without recomputing the merkle proof path, thus
|
|
275
|
+
* lowering verification and data costs.
|
|
276
|
+
*
|
|
277
|
+
* @param hashes Array of BN254 hashes.
|
|
278
|
+
* @param newAddresses Array of BN254 new addresses. Optionally specify the
|
|
279
|
+
* tree and queue for each address. Default to public
|
|
280
|
+
* state tree/queue.
|
|
281
|
+
* @returns validity proof with context
|
|
282
|
+
*/
|
|
283
|
+
getValidityProofAndRpcContext(hashes?: HashWithTree[], newAddresses?: AddressWithTree[]): Promise<WithContext<ValidityProofWithContext>>;
|
|
284
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import BN from 'bn.js';
|
|
2
|
+
import { Buffer } from 'buffer';
|
|
3
|
+
/**
|
|
4
|
+
* bignumber with <254-bit max size. Anchor serialization doesn't support native
|
|
5
|
+
* bigint yet, so we wrap BN. This wrapper has simple base10 encoding which is
|
|
6
|
+
* needed for zk circuit compat, in addition to the base58 encoding that users
|
|
7
|
+
* are used to from working with the web3.js PublicKey type.
|
|
8
|
+
*/
|
|
9
|
+
export type BN254 = BN;
|
|
10
|
+
/** Create a bigint instance with <254-bit max size and base58 capabilities */
|
|
11
|
+
export declare const createBN254: (number: string | number | BN | Buffer | Uint8Array | number[], base?: number | "hex" | "base58" | undefined) => BN254;
|
|
12
|
+
/** Convert <254-bit bigint to Base58 string. */
|
|
13
|
+
export declare function encodeBN254toBase58(bigintNumber: BN): string;
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { PublicKey } from '@solana/web3.js';
|
|
2
|
+
import { CompressedAccountData, CompressedAccountLegacy, PackedMerkleContextLegacy, TreeInfo } from './types';
|
|
3
|
+
import BN from 'bn.js';
|
|
4
|
+
import { BN254 } from './BN254';
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated use {@link CompressedAccount} instead
|
|
7
|
+
*/
|
|
8
|
+
export type CompressedAccountWithMerkleContext = CompressedAccount & MerkleContext & {
|
|
9
|
+
readOnly: boolean;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* @deprecated use {@link CompressedAccount} instead
|
|
13
|
+
*/
|
|
14
|
+
export type CompressedAccountWithMerkleContextLegacy = CompressedAccount & MerkleContext;
|
|
15
|
+
/**
|
|
16
|
+
* Compressed account + metadata about the state tree in which the account is
|
|
17
|
+
* stored.
|
|
18
|
+
*/
|
|
19
|
+
export type CompressedAccount = {
|
|
20
|
+
/**
|
|
21
|
+
* Public key of program or user owning the account.
|
|
22
|
+
*/
|
|
23
|
+
owner: PublicKey;
|
|
24
|
+
/**
|
|
25
|
+
* Lamports attached to the account.
|
|
26
|
+
*/
|
|
27
|
+
lamports: BN;
|
|
28
|
+
/**
|
|
29
|
+
* Optional unique account ID that is persistent across transactions.
|
|
30
|
+
*/
|
|
31
|
+
address: number[] | null;
|
|
32
|
+
/**
|
|
33
|
+
* Optional data attached to the account.
|
|
34
|
+
*/
|
|
35
|
+
data: CompressedAccountData | null;
|
|
36
|
+
} & MerkleContext & {
|
|
37
|
+
/**
|
|
38
|
+
* Read only.
|
|
39
|
+
*/
|
|
40
|
+
readOnly: boolean;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* @deprecated use {@link MerkleContext} instead.
|
|
44
|
+
*
|
|
45
|
+
* Legacy MerkleContext.
|
|
46
|
+
*/
|
|
47
|
+
export type MerkleContextLegacy = {
|
|
48
|
+
/**
|
|
49
|
+
* State tree
|
|
50
|
+
*/
|
|
51
|
+
merkleTree: PublicKey;
|
|
52
|
+
/**
|
|
53
|
+
* Nullifier queue
|
|
54
|
+
*/
|
|
55
|
+
nullifierQueue: PublicKey;
|
|
56
|
+
/**
|
|
57
|
+
* Poseidon hash of the account. Stored as leaf in state tree
|
|
58
|
+
*/
|
|
59
|
+
hash: number[];
|
|
60
|
+
/**
|
|
61
|
+
* Position of `hash` in the State tree
|
|
62
|
+
*/
|
|
63
|
+
leafIndex: number;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Context for compressed account stored in a state tree
|
|
67
|
+
*/
|
|
68
|
+
export type MerkleContext = {
|
|
69
|
+
/**
|
|
70
|
+
* Tree info
|
|
71
|
+
*/
|
|
72
|
+
treeInfo: TreeInfo;
|
|
73
|
+
/**
|
|
74
|
+
* Poseidon hash of the account. Stored as leaf in state tree
|
|
75
|
+
*/
|
|
76
|
+
hash: BN;
|
|
77
|
+
/**
|
|
78
|
+
* Position of `hash` in the State tree
|
|
79
|
+
*/
|
|
80
|
+
leafIndex: number;
|
|
81
|
+
/**
|
|
82
|
+
* Whether the account can be proven by index or by merkle proof
|
|
83
|
+
*/
|
|
84
|
+
proveByIndex: boolean;
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* MerkleContext with merkle proof
|
|
88
|
+
*/
|
|
89
|
+
export type MerkleContextWithMerkleProof = MerkleContext & {
|
|
90
|
+
/**
|
|
91
|
+
* Recent valid 'hash' proof path, expires after n slots
|
|
92
|
+
*/
|
|
93
|
+
merkleProof: BN254[];
|
|
94
|
+
/**
|
|
95
|
+
* Index of state root the merkleproof is valid for, expires after n slots
|
|
96
|
+
*/
|
|
97
|
+
rootIndex: number;
|
|
98
|
+
/**
|
|
99
|
+
* Current root
|
|
100
|
+
*/
|
|
101
|
+
root: BN254;
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* Packed compressed account and state tree info.
|
|
105
|
+
*/
|
|
106
|
+
export type PackedStateTreeInfo = {
|
|
107
|
+
/**
|
|
108
|
+
* Recent valid root index.
|
|
109
|
+
*/
|
|
110
|
+
rootIndex: number;
|
|
111
|
+
/**
|
|
112
|
+
* Whether the account can be proven by index or by merkle proof
|
|
113
|
+
*/
|
|
114
|
+
proveByIndex: boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Index of the merkle tree in which the account is stored.
|
|
117
|
+
*/
|
|
118
|
+
merkleTreePubkeyIndex: number;
|
|
119
|
+
/**
|
|
120
|
+
* Index of the queue in which the account is stored.
|
|
121
|
+
*/
|
|
122
|
+
queuePubkeyIndex: number;
|
|
123
|
+
/**
|
|
124
|
+
* Index of the leaf in the state tree.
|
|
125
|
+
*/
|
|
126
|
+
leafIndex: number;
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* Packed tree info for a new program-derived address (PDA).
|
|
130
|
+
*/
|
|
131
|
+
export type PackedAddressTreeInfo = {
|
|
132
|
+
/**
|
|
133
|
+
* Index of the merkle tree in which the account is stored.
|
|
134
|
+
*/
|
|
135
|
+
addressMerkleTreePubkeyIndex: number;
|
|
136
|
+
/**
|
|
137
|
+
* Index of the queue in which the account is stored.
|
|
138
|
+
*/
|
|
139
|
+
addressQueuePubkeyIndex: number;
|
|
140
|
+
/**
|
|
141
|
+
* Recent valid root index.
|
|
142
|
+
*/
|
|
143
|
+
rootIndex: number;
|
|
144
|
+
};
|
|
145
|
+
/**
|
|
146
|
+
* Compressed account meta in instruction.
|
|
147
|
+
*
|
|
148
|
+
*/
|
|
149
|
+
export type CompressedAccountMeta = {
|
|
150
|
+
/**
|
|
151
|
+
* Packed Tree info.
|
|
152
|
+
*/
|
|
153
|
+
treeInfo: PackedStateTreeInfo;
|
|
154
|
+
/**
|
|
155
|
+
* Address.
|
|
156
|
+
*/
|
|
157
|
+
address: number[] | null;
|
|
158
|
+
/**
|
|
159
|
+
* Lamports.
|
|
160
|
+
*/
|
|
161
|
+
lamports: BN | null;
|
|
162
|
+
/**
|
|
163
|
+
* index of state tree in which the new account state is stored.
|
|
164
|
+
*/
|
|
165
|
+
outputStateTreeIndex: number;
|
|
166
|
+
};
|
|
167
|
+
/**
|
|
168
|
+
* Create an output compressed account meta for a new account.
|
|
169
|
+
* Client-side only.
|
|
170
|
+
*/
|
|
171
|
+
export declare const createCompressedAccountMeta: (treeInfo: PackedStateTreeInfo, outputStateTreeIndex: number, address?: number[], lamports?: BN) => CompressedAccountMeta;
|
|
172
|
+
/**
|
|
173
|
+
* @deprecated Use {@link PackedStateTreeInfo} instead.
|
|
174
|
+
* Packed compressed account with merkle context.
|
|
175
|
+
*/
|
|
176
|
+
export interface PackedCompressedAccountWithMerkleContext {
|
|
177
|
+
/**
|
|
178
|
+
* Compressed account.
|
|
179
|
+
*/
|
|
180
|
+
compressedAccount: CompressedAccountLegacy;
|
|
181
|
+
/**
|
|
182
|
+
* Merkle context.
|
|
183
|
+
*/
|
|
184
|
+
merkleContext: PackedMerkleContextLegacy;
|
|
185
|
+
/**
|
|
186
|
+
* Root index.
|
|
187
|
+
*/
|
|
188
|
+
rootIndex: number;
|
|
189
|
+
/**
|
|
190
|
+
* Read only.
|
|
191
|
+
*/
|
|
192
|
+
readOnly: boolean;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* @deprecated use {@link createCompressedAccountMeta} instead.
|
|
196
|
+
*/
|
|
197
|
+
export declare const createCompressedAccountLegacy: (owner: PublicKey, lamports?: BN, data?: CompressedAccountData, address?: number[]) => CompressedAccountLegacy;
|
|
198
|
+
/**
|
|
199
|
+
* @deprecated.
|
|
200
|
+
*/
|
|
201
|
+
export declare const createCompressedAccountWithMerkleContextLegacy: (merkleContext: MerkleContext, owner: PublicKey, lamports?: BN, data?: CompressedAccountData, address?: number[]) => CompressedAccountWithMerkleContext;
|
|
202
|
+
/**
|
|
203
|
+
* @deprecated use {@link createCompressedAccountMeta} instead.
|
|
204
|
+
*/
|
|
205
|
+
export declare const createMerkleContextLegacy: (treeInfo: TreeInfo, hash: BN254, leafIndex: number, proveByIndex?: boolean) => MerkleContext;
|