@lightprotocol/stateless.js 0.1.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +58 -0
- package/dist/cjs/index.cjs +4031 -0
- package/dist/es/index.js +3988 -0
- package/dist/types/actions/common.d.ts +3 -0
- package/dist/types/actions/compress-lamports.d.ts +16 -0
- package/dist/types/actions/decompress-lamports.d.ts +16 -0
- package/dist/types/actions/index.d.ts +4 -0
- package/dist/types/actions/init-sol-omnibus-account.d.ts +13 -0
- package/dist/types/constants.d.ts +34 -0
- package/dist/types/errors.d.ts +74 -0
- package/dist/types/idls/account_compression.d.ts +932 -0
- package/dist/types/idls/index.d.ts +5 -0
- package/dist/types/idls/light.d.ts +192 -0
- package/dist/types/idls/psp_compressed_pda.d.ts +607 -0
- package/dist/types/idls/user_registry.d.ts +69 -0
- package/dist/types/index.d.ts +12 -0
- package/dist/types/instruction/index.d.ts +1 -0
- package/dist/types/instruction/pack-compressed-accounts.d.ts +30 -0
- package/dist/types/programs/compressed-pda.d.ts +148 -0
- package/dist/types/programs/index.d.ts +1 -0
- package/dist/types/rpc-interface.d.ts +430 -0
- package/dist/types/rpc.d.ts +26 -0
- package/dist/types/state/BN254.d.ts +20 -0
- package/dist/types/state/compressed-account.d.ts +35 -0
- package/dist/types/state/index.d.ts +3 -0
- package/dist/types/state/types.d.ts +108 -0
- package/dist/types/test-utils/common.d.ts +32 -0
- package/dist/types/test-utils/index.d.ts +5 -0
- package/dist/types/test-utils/merkle-tree.d.ts +92 -0
- package/dist/types/test-utils/parse-event.d.ts +7 -0
- package/dist/types/test-utils/parse-validity-proof.d.ts +20 -0
- package/dist/types/test-utils/test-rpc.d.ts +51 -0
- package/dist/types/utils/airdrop.d.ts +7 -0
- package/dist/types/utils/conversion.d.ts +10 -0
- package/dist/types/utils/index.d.ts +6 -0
- package/dist/types/utils/pipe.d.ts +2 -0
- package/dist/types/utils/send-and-confirm.d.ts +18 -0
- package/dist/types/utils/sleep.d.ts +1 -0
- package/dist/types/utils/validation.d.ts +4 -0
- package/dist/types/wallet/index.d.ts +1 -0
- package/dist/types/wallet/interface.d.ts +25 -0
- package/dist/types/wallet/use-wallet.d.ts +9 -0
- package/dist/umd/index.js +4027 -0
- package/package.json +81 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { AccountMeta, PublicKey } from '@solana/web3.js';
|
|
2
|
+
import { PackedCompressedAccountWithMerkleContext } from '../state';
|
|
3
|
+
import { CompressedAccountWithMerkleContext } from '../state/compressed-account';
|
|
4
|
+
/**
|
|
5
|
+
* @internal Finds the index of a PublicKey in an array, or adds it if not
|
|
6
|
+
* present
|
|
7
|
+
* */
|
|
8
|
+
export declare function getIndexOrAdd(accountsArray: PublicKey[], key: PublicKey): number;
|
|
9
|
+
/** @internal */
|
|
10
|
+
export declare function padOutputStateMerkleTrees(outputStateMerkleTrees: PublicKey[] | PublicKey | undefined, numberOfOutputCompressedAccounts: number, inputCompressedAccountsWithMerkleContext: CompressedAccountWithMerkleContext[]): PublicKey[];
|
|
11
|
+
/**
|
|
12
|
+
* Packs Compressed Accounts.
|
|
13
|
+
*
|
|
14
|
+
* Replaces PublicKey with index pointer to remaining accounts.
|
|
15
|
+
*
|
|
16
|
+
* @param inputCompressedAccounts ix input state to be consumed
|
|
17
|
+
* @param numberOfOutputCompressedAccounts ix ouput state to be created
|
|
18
|
+
* @param outputStateMerkleTrees State trees that the output should
|
|
19
|
+
* be inserted into. Defaults to the
|
|
20
|
+
* 0th state tree of the input state.
|
|
21
|
+
* Gets padded to the length of
|
|
22
|
+
* outputCompressedAccounts.
|
|
23
|
+
* @param remainingAccounts Optional existing array of accounts
|
|
24
|
+
* to append to.
|
|
25
|
+
**/
|
|
26
|
+
export declare function packCompressedAccounts(inputCompressedAccounts: CompressedAccountWithMerkleContext[], numberOfOutputCompressedAccounts: number, outputStateMerkleTrees?: PublicKey[] | PublicKey, remainingAccounts?: PublicKey[]): {
|
|
27
|
+
packedInputCompressedAccounts: PackedCompressedAccountWithMerkleContext[];
|
|
28
|
+
outputStateMerkleTreeIndices: number[];
|
|
29
|
+
remainingAccountMetas: AccountMeta[];
|
|
30
|
+
};
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { Program, BN } from '@coral-xyz/anchor';
|
|
2
|
+
import { PublicKey, TransactionInstruction } from '@solana/web3.js';
|
|
3
|
+
import { PspCompressedPda } from '../idls/psp_compressed_pda';
|
|
4
|
+
import { CompressedAccount, CompressedAccountWithMerkleContext, CompressedProof } from '../state';
|
|
5
|
+
export declare const sumUpLamports: (accounts: CompressedAccountWithMerkleContext[]) => BN;
|
|
6
|
+
/**
|
|
7
|
+
* Defines the parameters for the transfer method
|
|
8
|
+
*/
|
|
9
|
+
type TransferParams = {
|
|
10
|
+
/**
|
|
11
|
+
* The payer of the transaction.
|
|
12
|
+
*/
|
|
13
|
+
payer: PublicKey;
|
|
14
|
+
/**
|
|
15
|
+
* The input state to be consumed.
|
|
16
|
+
*/
|
|
17
|
+
inputCompressedAccounts: CompressedAccountWithMerkleContext[];
|
|
18
|
+
/**
|
|
19
|
+
* Recipient address
|
|
20
|
+
*/
|
|
21
|
+
toAddress: PublicKey;
|
|
22
|
+
/**
|
|
23
|
+
* amount of lamports to transfer.
|
|
24
|
+
*/
|
|
25
|
+
lamports: number | BN;
|
|
26
|
+
/**
|
|
27
|
+
* The recent state root indices of the input state. The expiry is tied to
|
|
28
|
+
* the proof.
|
|
29
|
+
*
|
|
30
|
+
* TODO: Add support for passing recent-values after instruction creation.
|
|
31
|
+
*/
|
|
32
|
+
recentInputStateRootIndices: number[];
|
|
33
|
+
/**
|
|
34
|
+
* The recent validity proof for state inclusion of the input state. It
|
|
35
|
+
* expires after n slots.
|
|
36
|
+
*/
|
|
37
|
+
recentValidityProof: CompressedProof;
|
|
38
|
+
/**
|
|
39
|
+
* The state trees that the tx output should be inserted into. This can be a
|
|
40
|
+
* single PublicKey or an array of PublicKey. Defaults to the 0th state tree
|
|
41
|
+
* of input state.
|
|
42
|
+
*/
|
|
43
|
+
outputStateTrees?: PublicKey[] | PublicKey;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Defines the parameters for the transfer method
|
|
47
|
+
*/
|
|
48
|
+
type CompressParams = {
|
|
49
|
+
/**
|
|
50
|
+
* The payer of the transaction.
|
|
51
|
+
*/
|
|
52
|
+
payer: PublicKey;
|
|
53
|
+
/**
|
|
54
|
+
* address that the lamports are attached to. also defaults to the recipient owner
|
|
55
|
+
*/
|
|
56
|
+
toAddress: PublicKey;
|
|
57
|
+
/**
|
|
58
|
+
* amount of lamports to compress.
|
|
59
|
+
*/
|
|
60
|
+
lamports: number | BN;
|
|
61
|
+
/**
|
|
62
|
+
* The state tree that the tx output should be inserted into. This can be a
|
|
63
|
+
*
|
|
64
|
+
*/
|
|
65
|
+
outputStateTree: PublicKey;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Defines the parameters for the transfer method
|
|
69
|
+
*/
|
|
70
|
+
type DecompressParams = {
|
|
71
|
+
/**
|
|
72
|
+
* The payer of the transaction.
|
|
73
|
+
*/
|
|
74
|
+
payer: PublicKey;
|
|
75
|
+
/**
|
|
76
|
+
* The input state to be consumed.
|
|
77
|
+
*/
|
|
78
|
+
inputCompressedAccounts: CompressedAccountWithMerkleContext[];
|
|
79
|
+
/**
|
|
80
|
+
* Recipient address of uncompressed lamports
|
|
81
|
+
*/
|
|
82
|
+
toAddress: PublicKey;
|
|
83
|
+
/**
|
|
84
|
+
* amount of lamports to decompress.
|
|
85
|
+
*/
|
|
86
|
+
lamports: number | BN;
|
|
87
|
+
/**
|
|
88
|
+
* The recent state root indices of the input state. The expiry is tied to
|
|
89
|
+
* the proof.
|
|
90
|
+
*
|
|
91
|
+
* TODO: Add support for passing recent-values after instruction creation.
|
|
92
|
+
*/
|
|
93
|
+
recentInputStateRootIndices: number[];
|
|
94
|
+
/**
|
|
95
|
+
* The recent validity proof for state inclusion of the input state. It
|
|
96
|
+
* expires after n slots.
|
|
97
|
+
*/
|
|
98
|
+
recentValidityProof: CompressedProof;
|
|
99
|
+
/**
|
|
100
|
+
* The state trees that the tx output should be inserted into. This can be a
|
|
101
|
+
* single PublicKey or an array of PublicKey. Defaults to the 0th state tree
|
|
102
|
+
* of input state.
|
|
103
|
+
*/
|
|
104
|
+
outputStateTree?: PublicKey;
|
|
105
|
+
};
|
|
106
|
+
export declare class LightSystemProgram {
|
|
107
|
+
/**
|
|
108
|
+
* @internal
|
|
109
|
+
*/
|
|
110
|
+
constructor();
|
|
111
|
+
/**
|
|
112
|
+
* Public key that identifies the CompressedPda program
|
|
113
|
+
*/
|
|
114
|
+
static programId: PublicKey;
|
|
115
|
+
private static _program;
|
|
116
|
+
static get program(): Program<PspCompressedPda>;
|
|
117
|
+
/**
|
|
118
|
+
* @internal
|
|
119
|
+
* Cwct1kQLwJm8Z3HetLu8m4SXkhD6FZ5fXbJQCxTxPnGY
|
|
120
|
+
*/
|
|
121
|
+
static deriveCompressedSolPda(): PublicKey;
|
|
122
|
+
/**
|
|
123
|
+
* Initializes the program statically if not already initialized.
|
|
124
|
+
*/
|
|
125
|
+
private static initializeProgram;
|
|
126
|
+
static createTransferOutputState(inputCompressedAccounts: CompressedAccountWithMerkleContext[], toAddress: PublicKey, lamports: number | BN): CompressedAccount[];
|
|
127
|
+
static createDecompressOutputState(inputCompressedAccounts: CompressedAccountWithMerkleContext[], lamports: number | BN): CompressedAccount[];
|
|
128
|
+
/**
|
|
129
|
+
* Creates a transaction instruction that transfers compressed lamports from
|
|
130
|
+
* one owner to another.
|
|
131
|
+
*/
|
|
132
|
+
static transfer(params: TransferParams): Promise<TransactionInstruction[]>;
|
|
133
|
+
/**
|
|
134
|
+
* Initialize the compressed sol pda
|
|
135
|
+
*/
|
|
136
|
+
static initCompressedSolPda(feePayer: PublicKey): Promise<TransactionInstruction>;
|
|
137
|
+
/**
|
|
138
|
+
* Creates a transaction instruction that transfers compressed lamports from
|
|
139
|
+
* one owner to another.
|
|
140
|
+
*/
|
|
141
|
+
static compress(params: CompressParams): Promise<TransactionInstruction[]>;
|
|
142
|
+
/**
|
|
143
|
+
* Creates a transaction instruction that transfers compressed lamports from
|
|
144
|
+
* one owner to another.
|
|
145
|
+
*/
|
|
146
|
+
static decompress(params: DecompressParams): Promise<TransactionInstruction[]>;
|
|
147
|
+
}
|
|
148
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './compressed-pda';
|
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
import { PublicKey, DataSizeFilter, MemcmpFilter } from '@solana/web3.js';
|
|
2
|
+
import type { Struct } from 'superstruct';
|
|
3
|
+
import { MerkleUpdateContext, BN254, CompressedProof, CompressedAccountWithMerkleContext, MerkleContextWithMerkleProof, TokenData } from './state';
|
|
4
|
+
import { BN } from '@coral-xyz/anchor';
|
|
5
|
+
export type CompressedProofWithContext = {
|
|
6
|
+
compressedProof: CompressedProof;
|
|
7
|
+
roots: string[];
|
|
8
|
+
rootIndices: number[];
|
|
9
|
+
leafIndices: number[];
|
|
10
|
+
leaves: BN[];
|
|
11
|
+
merkleTree: PublicKey;
|
|
12
|
+
nullifierQueue: PublicKey;
|
|
13
|
+
};
|
|
14
|
+
export interface GetCompressedTokenAccountsByOwnerOrDelegateOptions {
|
|
15
|
+
mint?: PublicKey;
|
|
16
|
+
cursor?: string;
|
|
17
|
+
limit?: BN;
|
|
18
|
+
}
|
|
19
|
+
export type GetCompressedAccountsFilter = MemcmpFilter | DataSizeFilter;
|
|
20
|
+
export type GetCompressedAccountConfig = {
|
|
21
|
+
encoding?: string;
|
|
22
|
+
};
|
|
23
|
+
export type GetCompressedAccountsConfig = {
|
|
24
|
+
encoding?: string;
|
|
25
|
+
filters?: GetCompressedAccountsFilter[];
|
|
26
|
+
};
|
|
27
|
+
export interface ParsedTokenAccount {
|
|
28
|
+
compressedAccount: CompressedAccountWithMerkleContext;
|
|
29
|
+
parsed: TokenData;
|
|
30
|
+
}
|
|
31
|
+
export type WithMerkleUpdateContext<T> = {
|
|
32
|
+
/** merkle update context */
|
|
33
|
+
context: MerkleUpdateContext | null;
|
|
34
|
+
/** response value */
|
|
35
|
+
value: T;
|
|
36
|
+
};
|
|
37
|
+
export type WithContext<T> = {
|
|
38
|
+
/** context */
|
|
39
|
+
context: {
|
|
40
|
+
slot: number;
|
|
41
|
+
};
|
|
42
|
+
/** response value */
|
|
43
|
+
value: T;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* @internal
|
|
47
|
+
*/
|
|
48
|
+
export declare function createRpcResult<T, U>(result: Struct<T, U>): Struct<import("superstruct/dist/utils").Simplify<import("superstruct/dist/utils").Optionalize<{
|
|
49
|
+
jsonrpc: "2.0";
|
|
50
|
+
id: string;
|
|
51
|
+
result: T;
|
|
52
|
+
}>> | {
|
|
53
|
+
jsonrpc: "2.0";
|
|
54
|
+
id: string;
|
|
55
|
+
error: {
|
|
56
|
+
message: string;
|
|
57
|
+
code: unknown;
|
|
58
|
+
data?: any;
|
|
59
|
+
};
|
|
60
|
+
}, null>;
|
|
61
|
+
/**
|
|
62
|
+
* @internal
|
|
63
|
+
*/
|
|
64
|
+
export declare function jsonRpcResult<T, U>(schema: Struct<T, U>): Struct<import("superstruct/dist/utils").Simplify<import("superstruct/dist/utils").Optionalize<{
|
|
65
|
+
jsonrpc: "2.0";
|
|
66
|
+
id: string;
|
|
67
|
+
result: T;
|
|
68
|
+
}>> | {
|
|
69
|
+
jsonrpc: "2.0";
|
|
70
|
+
id: string;
|
|
71
|
+
error: {
|
|
72
|
+
message: string;
|
|
73
|
+
code: unknown;
|
|
74
|
+
data?: any;
|
|
75
|
+
};
|
|
76
|
+
}, null>;
|
|
77
|
+
/**
|
|
78
|
+
* @internal
|
|
79
|
+
*/
|
|
80
|
+
export declare function jsonRpcResultAndContext<T, U>(value: Struct<T, U>): Struct<import("superstruct/dist/utils").Simplify<import("superstruct/dist/utils").Optionalize<{
|
|
81
|
+
jsonrpc: "2.0";
|
|
82
|
+
id: string;
|
|
83
|
+
result: import("superstruct/dist/utils").Simplify<import("superstruct/dist/utils").Optionalize<{
|
|
84
|
+
context: {
|
|
85
|
+
slot: number;
|
|
86
|
+
};
|
|
87
|
+
value: T;
|
|
88
|
+
}>>;
|
|
89
|
+
}>> | {
|
|
90
|
+
jsonrpc: "2.0";
|
|
91
|
+
id: string;
|
|
92
|
+
error: {
|
|
93
|
+
message: string;
|
|
94
|
+
code: unknown;
|
|
95
|
+
data?: any;
|
|
96
|
+
};
|
|
97
|
+
}, null>;
|
|
98
|
+
/**
|
|
99
|
+
* @internal
|
|
100
|
+
*/
|
|
101
|
+
export declare const CompressedAccountResult: Struct<{
|
|
102
|
+
leafIndex: number;
|
|
103
|
+
owner: PublicKey;
|
|
104
|
+
lamports: BN;
|
|
105
|
+
address: PublicKey | null;
|
|
106
|
+
data: string | null;
|
|
107
|
+
discriminator: BN;
|
|
108
|
+
dataHash: BN | null;
|
|
109
|
+
hash: BN;
|
|
110
|
+
tree: PublicKey | null;
|
|
111
|
+
seq: BN | null;
|
|
112
|
+
slotUpdated: BN;
|
|
113
|
+
}, {
|
|
114
|
+
hash: Struct<BN, null>;
|
|
115
|
+
address: Struct<PublicKey | null, null>;
|
|
116
|
+
data: Struct<string | null, null>;
|
|
117
|
+
dataHash: Struct<BN | null, null>;
|
|
118
|
+
discriminator: Struct<BN, null>;
|
|
119
|
+
owner: Struct<PublicKey, null>;
|
|
120
|
+
lamports: Struct<BN, null>;
|
|
121
|
+
tree: Struct<PublicKey | null, null>;
|
|
122
|
+
seq: Struct<BN | null, null>;
|
|
123
|
+
slotUpdated: Struct<BN, null>;
|
|
124
|
+
leafIndex: Struct<number, null>;
|
|
125
|
+
}>;
|
|
126
|
+
/**
|
|
127
|
+
* @internal
|
|
128
|
+
*/
|
|
129
|
+
export declare const CompressedTokenAccountResult: Struct<{
|
|
130
|
+
leafIndex: number;
|
|
131
|
+
owner: PublicKey;
|
|
132
|
+
lamports: BN;
|
|
133
|
+
address: PublicKey | null;
|
|
134
|
+
data: string | null;
|
|
135
|
+
discriminator: BN;
|
|
136
|
+
dataHash: BN | null;
|
|
137
|
+
frozen: boolean;
|
|
138
|
+
hash: BN;
|
|
139
|
+
tree: PublicKey;
|
|
140
|
+
seq: BN;
|
|
141
|
+
amount: BN;
|
|
142
|
+
delegate: PublicKey | null;
|
|
143
|
+
closeAuthority: PublicKey | null;
|
|
144
|
+
isNative: boolean;
|
|
145
|
+
mint: PublicKey;
|
|
146
|
+
}, {
|
|
147
|
+
address: Struct<PublicKey | null, null>;
|
|
148
|
+
amount: Struct<BN, null>;
|
|
149
|
+
delegate: Struct<PublicKey | null, null>;
|
|
150
|
+
closeAuthority: Struct<PublicKey | null, null>;
|
|
151
|
+
isNative: Struct<boolean, null>;
|
|
152
|
+
frozen: Struct<boolean, null>;
|
|
153
|
+
mint: Struct<PublicKey, null>;
|
|
154
|
+
owner: Struct<PublicKey, null>;
|
|
155
|
+
hash: Struct<BN, null>;
|
|
156
|
+
data: Struct<string | null, null>;
|
|
157
|
+
dataHash: Struct<BN | null, null>;
|
|
158
|
+
discriminator: Struct<BN, null>;
|
|
159
|
+
lamports: Struct<BN, null>;
|
|
160
|
+
tree: Struct<PublicKey, null>;
|
|
161
|
+
seq: Struct<BN, null>;
|
|
162
|
+
leafIndex: Struct<number, null>;
|
|
163
|
+
}>;
|
|
164
|
+
/**
|
|
165
|
+
* @internal
|
|
166
|
+
*/
|
|
167
|
+
export declare const MultipleCompressedAccountsResult: Struct<{
|
|
168
|
+
items: {
|
|
169
|
+
leafIndex: number;
|
|
170
|
+
owner: PublicKey;
|
|
171
|
+
lamports: BN;
|
|
172
|
+
address: PublicKey | null;
|
|
173
|
+
data: string | null;
|
|
174
|
+
discriminator: BN;
|
|
175
|
+
dataHash: BN | null;
|
|
176
|
+
hash: BN;
|
|
177
|
+
tree: PublicKey | null;
|
|
178
|
+
seq: BN | null;
|
|
179
|
+
slotUpdated: BN;
|
|
180
|
+
}[];
|
|
181
|
+
}, {
|
|
182
|
+
items: Struct<{
|
|
183
|
+
leafIndex: number;
|
|
184
|
+
owner: PublicKey;
|
|
185
|
+
lamports: BN;
|
|
186
|
+
address: PublicKey | null;
|
|
187
|
+
data: string | null;
|
|
188
|
+
discriminator: BN;
|
|
189
|
+
dataHash: BN | null;
|
|
190
|
+
hash: BN;
|
|
191
|
+
tree: PublicKey | null;
|
|
192
|
+
seq: BN | null;
|
|
193
|
+
slotUpdated: BN;
|
|
194
|
+
}[], Struct<{
|
|
195
|
+
leafIndex: number;
|
|
196
|
+
owner: PublicKey;
|
|
197
|
+
lamports: BN;
|
|
198
|
+
address: PublicKey | null;
|
|
199
|
+
data: string | null;
|
|
200
|
+
discriminator: BN;
|
|
201
|
+
dataHash: BN | null;
|
|
202
|
+
hash: BN;
|
|
203
|
+
tree: PublicKey | null;
|
|
204
|
+
seq: BN | null;
|
|
205
|
+
slotUpdated: BN;
|
|
206
|
+
}, {
|
|
207
|
+
hash: Struct<BN, null>;
|
|
208
|
+
address: Struct<PublicKey | null, null>;
|
|
209
|
+
data: Struct<string | null, null>;
|
|
210
|
+
dataHash: Struct<BN | null, null>;
|
|
211
|
+
discriminator: Struct<BN, null>;
|
|
212
|
+
owner: Struct<PublicKey, null>;
|
|
213
|
+
lamports: Struct<BN, null>;
|
|
214
|
+
tree: Struct<PublicKey | null, null>;
|
|
215
|
+
seq: Struct<BN | null, null>;
|
|
216
|
+
slotUpdated: Struct<BN, null>;
|
|
217
|
+
leafIndex: Struct<number, null>;
|
|
218
|
+
}>>;
|
|
219
|
+
}>;
|
|
220
|
+
/**
|
|
221
|
+
* @internal
|
|
222
|
+
*/
|
|
223
|
+
export declare const CompressedAccountsByOwnerResult: Struct<{
|
|
224
|
+
items: {
|
|
225
|
+
leafIndex: number;
|
|
226
|
+
owner: PublicKey;
|
|
227
|
+
lamports: BN;
|
|
228
|
+
address: PublicKey | null;
|
|
229
|
+
data: string | null;
|
|
230
|
+
discriminator: BN;
|
|
231
|
+
dataHash: BN | null;
|
|
232
|
+
hash: BN;
|
|
233
|
+
tree: PublicKey | null;
|
|
234
|
+
seq: BN | null;
|
|
235
|
+
slotUpdated: BN;
|
|
236
|
+
}[];
|
|
237
|
+
}, {
|
|
238
|
+
items: Struct<{
|
|
239
|
+
leafIndex: number;
|
|
240
|
+
owner: PublicKey;
|
|
241
|
+
lamports: BN;
|
|
242
|
+
address: PublicKey | null;
|
|
243
|
+
data: string | null;
|
|
244
|
+
discriminator: BN;
|
|
245
|
+
dataHash: BN | null;
|
|
246
|
+
hash: BN;
|
|
247
|
+
tree: PublicKey | null;
|
|
248
|
+
seq: BN | null;
|
|
249
|
+
slotUpdated: BN;
|
|
250
|
+
}[], Struct<{
|
|
251
|
+
leafIndex: number;
|
|
252
|
+
owner: PublicKey;
|
|
253
|
+
lamports: BN;
|
|
254
|
+
address: PublicKey | null;
|
|
255
|
+
data: string | null;
|
|
256
|
+
discriminator: BN;
|
|
257
|
+
dataHash: BN | null;
|
|
258
|
+
hash: BN;
|
|
259
|
+
tree: PublicKey | null;
|
|
260
|
+
seq: BN | null;
|
|
261
|
+
slotUpdated: BN;
|
|
262
|
+
}, {
|
|
263
|
+
hash: Struct<BN, null>;
|
|
264
|
+
address: Struct<PublicKey | null, null>;
|
|
265
|
+
data: Struct<string | null, null>;
|
|
266
|
+
dataHash: Struct<BN | null, null>;
|
|
267
|
+
discriminator: Struct<BN, null>;
|
|
268
|
+
owner: Struct<PublicKey, null>;
|
|
269
|
+
lamports: Struct<BN, null>;
|
|
270
|
+
tree: Struct<PublicKey | null, null>;
|
|
271
|
+
seq: Struct<BN | null, null>;
|
|
272
|
+
slotUpdated: Struct<BN, null>;
|
|
273
|
+
leafIndex: Struct<number, null>;
|
|
274
|
+
}>>;
|
|
275
|
+
}>;
|
|
276
|
+
/**
|
|
277
|
+
* @internal
|
|
278
|
+
*/
|
|
279
|
+
export declare const CompressedTokenAccountsByOwnerOrDelegateResult: Struct<{
|
|
280
|
+
items: {
|
|
281
|
+
leafIndex: number;
|
|
282
|
+
owner: PublicKey;
|
|
283
|
+
lamports: BN;
|
|
284
|
+
address: PublicKey | null;
|
|
285
|
+
data: string | null;
|
|
286
|
+
discriminator: BN;
|
|
287
|
+
dataHash: BN | null;
|
|
288
|
+
frozen: boolean;
|
|
289
|
+
hash: BN;
|
|
290
|
+
tree: PublicKey;
|
|
291
|
+
seq: BN;
|
|
292
|
+
amount: BN;
|
|
293
|
+
delegate: PublicKey | null;
|
|
294
|
+
closeAuthority: PublicKey | null;
|
|
295
|
+
isNative: boolean;
|
|
296
|
+
mint: PublicKey;
|
|
297
|
+
}[];
|
|
298
|
+
}, {
|
|
299
|
+
items: Struct<{
|
|
300
|
+
leafIndex: number;
|
|
301
|
+
owner: PublicKey;
|
|
302
|
+
lamports: BN;
|
|
303
|
+
address: PublicKey | null;
|
|
304
|
+
data: string | null;
|
|
305
|
+
discriminator: BN;
|
|
306
|
+
dataHash: BN | null;
|
|
307
|
+
frozen: boolean;
|
|
308
|
+
hash: BN;
|
|
309
|
+
tree: PublicKey;
|
|
310
|
+
seq: BN;
|
|
311
|
+
amount: BN;
|
|
312
|
+
delegate: PublicKey | null;
|
|
313
|
+
closeAuthority: PublicKey | null;
|
|
314
|
+
isNative: boolean;
|
|
315
|
+
mint: PublicKey;
|
|
316
|
+
}[], Struct<{
|
|
317
|
+
leafIndex: number;
|
|
318
|
+
owner: PublicKey;
|
|
319
|
+
lamports: BN;
|
|
320
|
+
address: PublicKey | null;
|
|
321
|
+
data: string | null;
|
|
322
|
+
discriminator: BN;
|
|
323
|
+
dataHash: BN | null;
|
|
324
|
+
frozen: boolean;
|
|
325
|
+
hash: BN;
|
|
326
|
+
tree: PublicKey;
|
|
327
|
+
seq: BN;
|
|
328
|
+
amount: BN;
|
|
329
|
+
delegate: PublicKey | null;
|
|
330
|
+
closeAuthority: PublicKey | null;
|
|
331
|
+
isNative: boolean;
|
|
332
|
+
mint: PublicKey;
|
|
333
|
+
}, {
|
|
334
|
+
address: Struct<PublicKey | null, null>;
|
|
335
|
+
amount: Struct<BN, null>;
|
|
336
|
+
delegate: Struct<PublicKey | null, null>;
|
|
337
|
+
closeAuthority: Struct<PublicKey | null, null>;
|
|
338
|
+
isNative: Struct<boolean, null>;
|
|
339
|
+
frozen: Struct<boolean, null>;
|
|
340
|
+
mint: Struct<PublicKey, null>;
|
|
341
|
+
owner: Struct<PublicKey, null>;
|
|
342
|
+
hash: Struct<BN, null>;
|
|
343
|
+
data: Struct<string | null, null>;
|
|
344
|
+
dataHash: Struct<BN | null, null>;
|
|
345
|
+
discriminator: Struct<BN, null>;
|
|
346
|
+
lamports: Struct<BN, null>;
|
|
347
|
+
tree: Struct<PublicKey, null>;
|
|
348
|
+
seq: Struct<BN, null>;
|
|
349
|
+
leafIndex: Struct<number, null>;
|
|
350
|
+
}>>;
|
|
351
|
+
}>;
|
|
352
|
+
/**
|
|
353
|
+
* @internal
|
|
354
|
+
*/
|
|
355
|
+
export declare const SlotResult: Struct<number, null>;
|
|
356
|
+
/**
|
|
357
|
+
* @internal
|
|
358
|
+
*/
|
|
359
|
+
export declare const HealthResult: Struct<string, null>;
|
|
360
|
+
/**
|
|
361
|
+
* @internal
|
|
362
|
+
*/
|
|
363
|
+
export declare const MerkeProofResult: Struct<{
|
|
364
|
+
leafIndex: number;
|
|
365
|
+
proof: BN[];
|
|
366
|
+
hash: BN;
|
|
367
|
+
merkleTree: PublicKey;
|
|
368
|
+
}, {
|
|
369
|
+
hash: Struct<BN, null>;
|
|
370
|
+
merkleTree: Struct<PublicKey, null>;
|
|
371
|
+
leafIndex: Struct<number, null>;
|
|
372
|
+
proof: Struct<BN[], Struct<BN, null>>;
|
|
373
|
+
}>;
|
|
374
|
+
/**
|
|
375
|
+
* @internal
|
|
376
|
+
*/
|
|
377
|
+
export declare const MultipleMerkleProofsResult: Struct<{
|
|
378
|
+
leafIndex: number;
|
|
379
|
+
proof: BN[];
|
|
380
|
+
hash: BN;
|
|
381
|
+
merkleTree: PublicKey;
|
|
382
|
+
}[], Struct<{
|
|
383
|
+
leafIndex: number;
|
|
384
|
+
proof: BN[];
|
|
385
|
+
hash: BN;
|
|
386
|
+
merkleTree: PublicKey;
|
|
387
|
+
}, {
|
|
388
|
+
hash: Struct<BN, null>;
|
|
389
|
+
merkleTree: Struct<PublicKey, null>;
|
|
390
|
+
leafIndex: Struct<number, null>;
|
|
391
|
+
proof: Struct<BN[], Struct<BN, null>>;
|
|
392
|
+
}>>;
|
|
393
|
+
/**
|
|
394
|
+
* @internal
|
|
395
|
+
*/
|
|
396
|
+
export declare const BalanceResult: Struct<BN, null>;
|
|
397
|
+
export declare const AccountProofResult: Struct<{
|
|
398
|
+
root: number[];
|
|
399
|
+
proof: number[][];
|
|
400
|
+
hash: number[];
|
|
401
|
+
}, {
|
|
402
|
+
hash: Struct<number[], Struct<number, null>>;
|
|
403
|
+
root: Struct<number[], Struct<number, null>>;
|
|
404
|
+
proof: Struct<number[][], Struct<number[], Struct<number, null>>>;
|
|
405
|
+
}>;
|
|
406
|
+
export interface CompressionApiInterface {
|
|
407
|
+
/** Retrieve compressed account by hash or address */
|
|
408
|
+
getCompressedAccount(hash: BN254): Promise<CompressedAccountWithMerkleContext | null>;
|
|
409
|
+
/** Retrieve compressed account by hash or address */
|
|
410
|
+
getCompressedBalance(hash: BN254): Promise<BN | null>;
|
|
411
|
+
/** Retrieve merkle proof for a compressed account */
|
|
412
|
+
getCompressedAccountProof(hash: BN254): Promise<MerkleContextWithMerkleProof>;
|
|
413
|
+
/** Retrieve compressed account by hash or address */
|
|
414
|
+
getMultipleCompressedAccounts(hashes: BN254[]): Promise<CompressedAccountWithMerkleContext[] | null>;
|
|
415
|
+
/** Retrieve multiple merkle proofs for compressed accounts */
|
|
416
|
+
getMultipleCompressedAccountProofs(hashes: BN254[]): Promise<MerkleContextWithMerkleProof[] | null>;
|
|
417
|
+
/** Retrieve compressed accounts by owner */
|
|
418
|
+
getCompressedAccountsByOwner(owner: PublicKey): Promise<CompressedAccountWithMerkleContext[] | null>;
|
|
419
|
+
/** Receive validity Proof for n compressed accounts */
|
|
420
|
+
getValidityProof(hashes: BN254[]): Promise<CompressedProofWithContext>;
|
|
421
|
+
/** Retrieve health status of the node */
|
|
422
|
+
getHealth(): Promise<string>;
|
|
423
|
+
/** Retrieve the current slot */
|
|
424
|
+
getSlot(): Promise<number>;
|
|
425
|
+
getCompressedTokenAccountsByOwner(publicKey: PublicKey, options?: GetCompressedTokenAccountsByOwnerOrDelegateOptions): Promise<ParsedTokenAccount[]>;
|
|
426
|
+
getCompressedTokenAccountsByDelegate(delegate: PublicKey, options?: GetCompressedTokenAccountsByOwnerOrDelegateOptions): Promise<ParsedTokenAccount[]>;
|
|
427
|
+
getCompressedTokenAccountBalance(hash: BN254): Promise<{
|
|
428
|
+
amount: BN;
|
|
429
|
+
}>;
|
|
430
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Connection, ConnectionConfig, PublicKey } from '@solana/web3.js';
|
|
2
|
+
import { CompressedProofWithContext, CompressionApiInterface, GetCompressedTokenAccountsByOwnerOrDelegateOptions, ParsedTokenAccount } from './rpc-interface';
|
|
3
|
+
import { MerkleContextWithMerkleProof, BN254, CompressedAccountWithMerkleContext } from './state';
|
|
4
|
+
import { BN } from '@coral-xyz/anchor';
|
|
5
|
+
export declare function createRpc(endpointOrWeb3JsConnection?: string | Connection, compressionApiEndpoint?: string, config?: ConnectionConfig): Rpc;
|
|
6
|
+
export declare class Rpc extends Connection implements CompressionApiInterface {
|
|
7
|
+
compressionApiEndpoint: string;
|
|
8
|
+
constructor(endpoint: string, compressionApiEndpoint: string, proverEndpoint?: string, config?: ConnectionConfig);
|
|
9
|
+
getCompressedAccount(hash: BN254): Promise<CompressedAccountWithMerkleContext | null>;
|
|
10
|
+
getCompressedBalance(hash: BN254): Promise<BN | null>;
|
|
11
|
+
/** Retrieve the merkle proof for a compressed account */
|
|
12
|
+
getCompressedAccountProof(hash: BN254): Promise<MerkleContextWithMerkleProof>;
|
|
13
|
+
getMultipleCompressedAccounts(hashes: BN254[]): Promise<CompressedAccountWithMerkleContext[] | null>;
|
|
14
|
+
/** Retrieve the merkle proof for a compressed account */
|
|
15
|
+
getMultipleCompressedAccountProofs(hashes: BN254[]): Promise<MerkleContextWithMerkleProof[] | null>;
|
|
16
|
+
getCompressedAccountsByOwner(owner: PublicKey): Promise<CompressedAccountWithMerkleContext[]>;
|
|
17
|
+
getValidityProof(hashes: BN254[]): Promise<CompressedProofWithContext>;
|
|
18
|
+
getHealth(): Promise<string>;
|
|
19
|
+
/** TODO: use from Connection */
|
|
20
|
+
getSlot(): Promise<number>;
|
|
21
|
+
getCompressedTokenAccountsByOwner(owner: PublicKey, options?: GetCompressedTokenAccountsByOwnerOrDelegateOptions): Promise<ParsedTokenAccount[]>;
|
|
22
|
+
getCompressedTokenAccountsByDelegate(delegate: PublicKey, options?: GetCompressedTokenAccountsByOwnerOrDelegateOptions): Promise<ParsedTokenAccount[]>;
|
|
23
|
+
getCompressedTokenAccountBalance(hash: BN254): Promise<{
|
|
24
|
+
amount: BN;
|
|
25
|
+
}>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { PublicKey } from '@solana/web3.js';
|
|
3
|
+
import { BN } from '@coral-xyz/anchor';
|
|
4
|
+
import { Buffer } from 'buffer';
|
|
5
|
+
/**
|
|
6
|
+
* bignumber with <254-bit max size. Anchor serialization doesn't support native
|
|
7
|
+
* bigint yet, so we wrap BN. This wrapper has simple base10 encoding which is
|
|
8
|
+
* needed for zk circuit compat, in addition to the base58 encoding that users
|
|
9
|
+
* are used to from working with the web3.js PublicKey type.
|
|
10
|
+
*/
|
|
11
|
+
export type BN254 = BN;
|
|
12
|
+
export declare const bn: (number: string | number | BN | Buffer | Uint8Array | number[], base?: number | 'hex' | undefined, endian?: BN.Endianness | undefined) => BN;
|
|
13
|
+
/** Create a bigint instance with <254-bit max size and base58 capabilities */
|
|
14
|
+
export declare const createBN254: (number: string | number | BN | Buffer | Uint8Array | number[], base?: number | 'hex' | 'base58' | undefined) => BN254;
|
|
15
|
+
/** Convert <254-bit bigint to Base58 string. Fills up to 32 bytes. */
|
|
16
|
+
export declare function encodeBN254toBase58(bigintNumber: BN254, pad?: number): string;
|
|
17
|
+
/** Convert Base58 string to <254-bit Solana Public key*/
|
|
18
|
+
export declare function bigint254ToPublicKey(bigintNumber: BN254): PublicKey;
|
|
19
|
+
/** Convert Solana Public key to <254-bit bigint */
|
|
20
|
+
export declare function PublicKeyToBN254(publicKey: PublicKey): BN254;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { BN } from '@coral-xyz/anchor';
|
|
2
|
+
import { PublicKey } from '@solana/web3.js';
|
|
3
|
+
import { CompressedAccount, CompressedAccountData } from './types';
|
|
4
|
+
import { BN254 } from './BN254';
|
|
5
|
+
export type CompressedAccountWithMerkleContext = CompressedAccount & MerkleContext;
|
|
6
|
+
/**
|
|
7
|
+
* Context for compressed account inserted into a state Merkle tree
|
|
8
|
+
* */
|
|
9
|
+
export type MerkleContext = {
|
|
10
|
+
/** State Merkle tree */
|
|
11
|
+
merkleTree: PublicKey;
|
|
12
|
+
/** The state nullfier queue belonging to merkleTree */
|
|
13
|
+
nullifierQueue: PublicKey;
|
|
14
|
+
/** Poseidon hash of the utxo preimage. Is a leaf in state merkle tree */
|
|
15
|
+
hash: number[];
|
|
16
|
+
/** 'hash' position within the Merkle tree */
|
|
17
|
+
leafIndex: number;
|
|
18
|
+
};
|
|
19
|
+
export type MerkleUpdateContext = {
|
|
20
|
+
/** Context slot */
|
|
21
|
+
slot: number;
|
|
22
|
+
/** Slot that the compressed account was appended at */
|
|
23
|
+
slotCreated?: number;
|
|
24
|
+
/** Sequence */
|
|
25
|
+
seq?: number;
|
|
26
|
+
};
|
|
27
|
+
export type MerkleContextWithMerkleProof = MerkleContext & {
|
|
28
|
+
/** Recent valid 'hash' proof path, expires after n slots */
|
|
29
|
+
merkleProof: BN254[];
|
|
30
|
+
/** Index of state root the merkleproof is valid for, expires after n slots */
|
|
31
|
+
rootIndex: number;
|
|
32
|
+
};
|
|
33
|
+
export declare const createCompressedAccount: (owner: PublicKey, lamports?: BN, data?: CompressedAccountData, address?: PublicKey) => CompressedAccount;
|
|
34
|
+
export declare const createCompressedAccountWithMerkleContext: (merkleContext: MerkleContext, owner: PublicKey, lamports?: BN, data?: CompressedAccountData, address?: PublicKey) => CompressedAccountWithMerkleContext;
|
|
35
|
+
export declare const createMerkleContext: (merkleTree: PublicKey, nullifierQueue: PublicKey, hash: number[], leafIndex: number) => MerkleContext;
|