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

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 (33) hide show
  1. package/README.md +4 -1
  2. package/dist/cjs/browser/constants.d.ts +22 -3
  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 +96 -2
  6. package/dist/cjs/browser/rpc.d.ts +80 -3
  7. package/dist/cjs/browser/test-helpers/test-rpc/get-compressed-token-accounts.d.ts +0 -2
  8. package/dist/cjs/browser/test-helpers/test-rpc/test-rpc.d.ts +6 -0
  9. package/dist/cjs/browser/utils/get-state-tree-infos.d.ts +15 -0
  10. package/dist/cjs/browser/utils/index.d.ts +1 -0
  11. package/dist/cjs/browser/utils/pack-decompress.d.ts +31 -0
  12. package/dist/cjs/node/constants.d.ts +22 -3
  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 +96 -2
  16. package/dist/cjs/node/rpc.d.ts +80 -3
  17. package/dist/cjs/node/test-helpers/test-rpc/get-compressed-token-accounts.d.ts +0 -2
  18. package/dist/cjs/node/test-helpers/test-rpc/test-rpc.d.ts +6 -0
  19. package/dist/cjs/node/utils/get-state-tree-infos.d.ts +15 -0
  20. package/dist/cjs/node/utils/index.d.ts +1 -0
  21. package/dist/cjs/node/utils/pack-decompress.d.ts +31 -0
  22. package/dist/es/browser/constants.d.ts +22 -3
  23. package/dist/es/browser/index.js +1 -1
  24. package/dist/es/browser/index.js.map +1 -1
  25. package/dist/es/browser/rpc-interface.d.ts +96 -2
  26. package/dist/es/browser/rpc.d.ts +80 -3
  27. package/dist/es/browser/test-helpers/test-rpc/get-compressed-token-accounts.d.ts +0 -2
  28. package/dist/es/browser/test-helpers/test-rpc/test-rpc.d.ts +6 -0
  29. package/dist/es/browser/utils/get-state-tree-infos.d.ts +15 -0
  30. package/dist/es/browser/utils/index.d.ts +1 -0
  31. package/dist/es/browser/utils/pack-decompress.d.ts +31 -0
  32. package/dist/types/index.d.ts +243 -6
  33. package/package.json +4 -4
@@ -1,6 +1,6 @@
1
- import { PublicKey, MemcmpFilter, DataSlice } from '@solana/web3.js';
1
+ import { PublicKey, MemcmpFilter, DataSlice, Commitment, GetAccountInfoConfig, AccountInfo, ConfirmedSignatureInfo, SignaturesForAddressOptions, TokenAmount } from '@solana/web3.js';
2
2
  import { Struct } from 'superstruct';
3
- import { BN254, ValidityProof, CompressedAccountWithMerkleContext, MerkleContextWithMerkleProof, TokenData, TreeInfo, AddressTreeInfo, CompressedProof } from './state';
3
+ import { BN254, ValidityProof, CompressedAccountWithMerkleContext, MerkleContextWithMerkleProof, TokenData, TreeInfo, AddressTreeInfo, CompressedProof, MerkleContext } from './state';
4
4
  import BN from 'bn.js';
5
5
  export interface LatestNonVotingSignatures {
6
6
  context: {
@@ -83,6 +83,14 @@ export interface AddressWithTreeInfo {
83
83
  address: BN254;
84
84
  treeInfo: AddressTreeInfo;
85
85
  }
86
+ export interface AddressWithTreeInfoV2 {
87
+ address: Uint8Array;
88
+ treeInfo: TreeInfo;
89
+ }
90
+ export declare enum DerivationMode {
91
+ compressible = "compressible",
92
+ standard = "standard"
93
+ }
86
94
  export interface CompressedTransaction {
87
95
  compressionInfo: {
88
96
  closedAccounts: {
@@ -2761,6 +2769,15 @@ export interface CompressionApiInterface {
2761
2769
  getLatestCompressionSignatures(cursor?: string, limit?: number): Promise<LatestNonVotingSignaturesPaginated>;
2762
2770
  getIndexerHealth(): Promise<string>;
2763
2771
  getIndexerSlot(): Promise<number>;
2772
+ getAccountInfoInterface(address: PublicKey, programId: PublicKey, commitmentOrConfig?: Commitment | GetAccountInfoConfig, addressSpace?: TreeInfo): Promise<{
2773
+ accountInfo: AccountInfo<Buffer>;
2774
+ isCold: boolean;
2775
+ loadContext?: MerkleContext;
2776
+ } | null>;
2777
+ getSignaturesForAddressInterface(address: PublicKey, options?: SignaturesForAddressOptions, compressedOptions?: PaginatedOptions): Promise<SignaturesForAddressInterfaceResult>;
2778
+ getSignaturesForOwnerInterface(owner: PublicKey, options?: SignaturesForAddressOptions, compressedOptions?: PaginatedOptions): Promise<SignaturesForAddressInterfaceResult>;
2779
+ getTokenAccountBalanceInterface(address: PublicKey, owner: PublicKey, mint: PublicKey, commitment?: Commitment): Promise<UnifiedTokenBalance>;
2780
+ getBalanceInterface(address: PublicKey, commitment?: Commitment): Promise<UnifiedBalance>;
2764
2781
  }
2765
2782
  export type RpcResultSuccess<T> = {
2766
2783
  jsonrpc: '2.0';
@@ -2777,3 +2794,80 @@ export type RpcResultError = {
2777
2794
  };
2778
2795
  };
2779
2796
  export type RpcResult<T> = RpcResultSuccess<T> | RpcResultError;
2797
+ /**
2798
+ * Source type for signature data.
2799
+ */
2800
+ export declare const SignatureSource: {
2801
+ /** From standard Solana RPC (getSignaturesForAddress) */
2802
+ readonly Solana: "solana";
2803
+ /** From compression indexer (getCompressionSignaturesFor*) */
2804
+ readonly Compressed: "compressed";
2805
+ };
2806
+ export type SignatureSourceType = (typeof SignatureSource)[keyof typeof SignatureSource];
2807
+ /**
2808
+ * Unified signature info combining data from both Solana RPC and compression indexer.
2809
+ *
2810
+ * Design rationale:
2811
+ * - `sources` array indicates where this signature was found (can be both!)
2812
+ * - Primary data comes from Solana RPC when available (richer: err, memo, confirmationStatus)
2813
+ * - Compression-only signatures still included for complete transaction history
2814
+ */
2815
+ export interface UnifiedSignatureInfo {
2816
+ /** Transaction signature (base58) */
2817
+ signature: string;
2818
+ /** Slot when the transaction was processed */
2819
+ slot: number;
2820
+ /** Block time (unix timestamp), null if not available */
2821
+ blockTime: number | null;
2822
+ /** Transaction error, null if successful. Only from Solana RPC. */
2823
+ err: any | null;
2824
+ /** Memo data. Only from Solana RPC. */
2825
+ memo: string | null;
2826
+ /** Confirmation status. Only from Solana RPC. */
2827
+ confirmationStatus?: string;
2828
+ /**
2829
+ * Sources where this signature was found.
2830
+ * - ['solana'] = only in Solana RPC
2831
+ * - ['compressed'] = only in compression indexer
2832
+ * - ['solana', 'compressed'] = found in both (compression tx indexed by both)
2833
+ */
2834
+ sources: SignatureSourceType[];
2835
+ }
2836
+ /**
2837
+ * Result of getSignaturesForAddressInterface / getSignaturesForOwnerInterface.
2838
+ *
2839
+ * Design rationale:
2840
+ * - `signatures`: Unified view, merged and deduplicated, sorted by slot desc
2841
+ * - `solana` / `compressed`: Raw responses preserved for clients that need source-specific data
2842
+ * - Allows callers to use the unified view OR drill into specific sources
2843
+ */
2844
+ export interface SignaturesForAddressInterfaceResult {
2845
+ /** Merged signatures from all sources, sorted by slot (descending) */
2846
+ signatures: UnifiedSignatureInfo[];
2847
+ /** Raw signatures from Solana RPC */
2848
+ solana: ConfirmedSignatureInfo[];
2849
+ /** Raw signatures from compression indexer */
2850
+ compressed: SignatureWithMetadata[];
2851
+ }
2852
+ /**
2853
+ * Unified token balance combining hot and cold token balances.
2854
+ */
2855
+ export interface UnifiedTokenBalance {
2856
+ /** Total balance (hot + cold) */
2857
+ amount: BN;
2858
+ /** True if any cold balance exists - call load() before usage */
2859
+ hasColdBalance: boolean;
2860
+ /** Token decimals (from on-chain mint or 0 if unknown) */
2861
+ decimals: number;
2862
+ /** Raw Solana RPC TokenAmount response, null if no on-chain account */
2863
+ solana: TokenAmount | null;
2864
+ }
2865
+ /**
2866
+ * Unified SOL balance combining hot and cold SOL balances.
2867
+ */
2868
+ export interface UnifiedBalance {
2869
+ /** Total balance (hot + cold) in lamports */
2870
+ total: BN;
2871
+ /** True if any cold balance exists - call load() before usage */
2872
+ hasColdBalance: boolean;
2873
+ }
@@ -1,8 +1,9 @@
1
- import { Connection, ConnectionConfig, PublicKey } from '@solana/web3.js';
1
+ import { AccountInfo, Commitment, Connection, ConnectionConfig, GetAccountInfoConfig, PublicKey, SignaturesForAddressOptions } from '@solana/web3.js';
2
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';
3
+ import { ValidityProofWithContext, CompressedTransaction, CompressionApiInterface, GetCompressedTokenAccountsByOwnerOrDelegateOptions, HexInputsForProver, ParsedTokenAccount, SignatureWithMetadata, LatestNonVotingSignatures, LatestNonVotingSignaturesPaginated, WithContext, GetCompressedAccountsByOwnerConfig, WithCursor, AddressWithTree, HashWithTree, CompressedMintTokenHolders, TokenBalance, PaginatedOptions, DerivationMode, AddressWithTreeInfoV2, SignaturesForAddressInterfaceResult, UnifiedSignatureInfo, UnifiedTokenBalance, UnifiedBalance } from './rpc-interface';
4
+ import { MerkleContextWithMerkleProof, BN254, CompressedAccountWithMerkleContext, ValidityProof, AddressTreeInfo, MerkleContext } from './state';
5
5
  import BN from 'bn.js';
6
+ import { ConfirmedSignatureInfo } from '@solana/web3.js';
6
7
  import { LightWasm } from './test-helpers';
7
8
  import { TreeInfo } from './state/types';
8
9
  /** @internal */
@@ -72,6 +73,12 @@ export interface NullifierMetadata {
72
73
  nullifier: BN254;
73
74
  txHash: BN254;
74
75
  }
76
+ /**
77
+ * Merge signatures from Solana RPC and compression indexer.
78
+ * Deduplicates by signature, tracking sources in the `sources` array.
79
+ * When a signature exists in both, uses Solana data (richer) but marks both sources.
80
+ */
81
+ export declare function mergeSignatures(solanaSignatures: ConfirmedSignatureInfo[], compressedSignatures: SignatureWithMetadata[]): UnifiedSignatureInfo[];
75
82
  /**
76
83
  *
77
84
  */
@@ -264,6 +271,17 @@ export declare class Rpc extends Connection implements CompressionApiInterface {
264
271
  * @returns validity proof with context
265
272
  */
266
273
  getValidityProofV0(hashes?: HashWithTree[], newAddresses?: AddressWithTree[]): Promise<ValidityProofWithContext>;
274
+ /**
275
+ * Fetch the latest validity proof for (1) compressed accounts specified by
276
+ * an array of account Merkle contexts, and (2) new unique addresses specified by
277
+ * an array of address objects with tree info.
278
+ *
279
+ * Validity proofs prove the presence of compressed accounts in state trees
280
+ * and the non-existence of addresses in address trees, respectively. They
281
+ * enable verification without recomputing the merkle proof path, thus
282
+ * lowering verification and data costs.
283
+ */
284
+ getValidityProofV2(accountMerkleContexts?: (MerkleContext | undefined)[], newAddresses?: AddressWithTreeInfoV2[], derivationMode?: DerivationMode): Promise<ValidityProofWithContext>;
267
285
  /**
268
286
  * Fetch the latest validity proof for (1) compressed accounts specified by
269
287
  * an array of account hashes. (2) new unique addresses specified by an
@@ -281,4 +299,63 @@ export declare class Rpc extends Connection implements CompressionApiInterface {
281
299
  * @returns validity proof with context
282
300
  */
283
301
  getValidityProofAndRpcContext(hashes?: HashWithTree[], newAddresses?: AddressWithTree[]): Promise<WithContext<ValidityProofWithContext>>;
302
+ /**
303
+ * Fetch the account info for the specified public key. Returns metadata
304
+ * to load in case the account is cold.
305
+ * @param address The account address to fetch.
306
+ * @param programId The owner program ID.
307
+ * @param commitmentOrConfig Optional. The commitment or config to use
308
+ * for the onchain account fetch.
309
+ * @param addressSpace Optional. The address space info that was
310
+ * used at init.
311
+ *
312
+ * @returns Account info with load info, or null if
313
+ * account doesn't exist. LoadContext is always
314
+ * some if the account is compressible. isCold
315
+ * indicates the current state of the account,
316
+ * if true the account must referenced in a
317
+ * load instruction before use.
318
+ */
319
+ getAccountInfoInterface(address: PublicKey, programId: PublicKey, commitmentOrConfig?: Commitment | GetAccountInfoConfig, addressSpace?: TreeInfo): Promise<{
320
+ accountInfo: AccountInfo<Buffer>;
321
+ isCold: boolean;
322
+ loadContext?: MerkleContext;
323
+ } | null>;
324
+ /**
325
+ * Get signatures for an address from both Solana and compression indexer.
326
+ *
327
+ * @param address Address to fetch signatures for.
328
+ * @param options Options for the Solana getSignaturesForAddress call.
329
+ * @param compressedOptions Options for the compression getCompressionSignaturesForAddress call.
330
+ * @returns Unified signatures from both sources.
331
+ */
332
+ getSignaturesForAddressInterface(address: PublicKey, options?: SignaturesForAddressOptions, compressedOptions?: PaginatedOptions): Promise<SignaturesForAddressInterfaceResult>;
333
+ /**
334
+ * Get signatures for an owner from both Solana and compression indexer.
335
+ *
336
+ * @param owner Owner address to fetch signatures for.
337
+ * @param options Options for the Solana getSignaturesForAddress call.
338
+ * @param compressedOptions Options for the compression getCompressionSignaturesForOwner call.
339
+ * @returns Unified signatures from both sources.
340
+ */
341
+ getSignaturesForOwnerInterface(owner: PublicKey, options?: SignaturesForAddressOptions, compressedOptions?: PaginatedOptions): Promise<SignaturesForAddressInterfaceResult>;
342
+ /**
343
+ * Get token account balance for an address, regardless of whether the token
344
+ * account is hot or cold.
345
+ *
346
+ * @param address Token account address.
347
+ * @param owner Owner public key.
348
+ * @param mint Mint public key.
349
+ * @param commitment Commitment level for on-chain query.
350
+ * @returns Unified token balance from both sources.
351
+ */
352
+ getTokenAccountBalanceInterface(address: PublicKey, owner: PublicKey, mint: PublicKey, commitment?: Commitment): Promise<UnifiedTokenBalance>;
353
+ /**
354
+ * Get SOL balance for an address, regardless of whether the account is hot or cold.
355
+ *
356
+ * @param address Address to fetch balance for.
357
+ * @param commitment Commitment level for on-chain query.
358
+ * @returns Unified SOL balance.
359
+ */
360
+ getBalanceInterface(address: PublicKey, commitment?: Commitment): Promise<UnifiedBalance>;
284
361
  }
@@ -3,7 +3,6 @@ import BN from 'bn.js';
3
3
  import { Rpc } from '../../rpc';
4
4
  import { ParsedTokenAccount, WithCursor } from '../../rpc-interface';
5
5
  import { PublicTransactionEvent, CompressedAccountLegacy } from '../../state';
6
- import { Layout } from '@coral-xyz/borsh';
7
6
  type TokenData = {
8
7
  mint: PublicKey;
9
8
  owner: PublicKey;
@@ -12,7 +11,6 @@ type TokenData = {
12
11
  state: number;
13
12
  tlv: Buffer | null;
14
13
  };
15
- export declare const TokenDataLayout: Layout<TokenData>;
16
14
  export type EventWithParsedTokenTlvData = {
17
15
  inputCompressedAccountHashes: number[][];
18
16
  outputCompressedAccounts: ParsedTokenAccount[];
@@ -236,4 +236,10 @@ export declare class TestRpc extends Connection implements CompressionApiInterfa
236
236
  */
237
237
  getValidityProof(hashes?: BN254[], newAddresses?: BN254[]): Promise<ValidityProofWithContext>;
238
238
  getValidityProofV0(hashes?: HashWithTree[], newAddresses?: AddressWithTree[]): Promise<ValidityProofWithContext>;
239
+ getValidityProofV2(accountMerkleContexts?: any[], newAddresses?: any[], derivationMode?: any): Promise<ValidityProofWithContext>;
240
+ getAccountInfoInterface(_address: PublicKey, _programId: PublicKey, _addressSpaceInfo: any): Promise<any>;
241
+ getSignaturesForAddressInterface(_address: PublicKey, _options?: any, _compressedOptions?: PaginatedOptions): Promise<any>;
242
+ getSignaturesForOwnerInterface(_owner: PublicKey, _options?: any, _compressedOptions?: PaginatedOptions): Promise<any>;
243
+ getTokenAccountBalanceInterface(_address: PublicKey, _owner: PublicKey, _mint: PublicKey, _commitment?: any): Promise<any>;
244
+ getBalanceInterface(_address: PublicKey, _commitment?: any): Promise<any>;
239
245
  }
@@ -1,6 +1,21 @@
1
1
  import { Connection, PublicKey } from '@solana/web3.js';
2
2
  import { TreeInfo, TreeType } from '../state/types';
3
+ import { MerkleContext } from '../state/compressed-account';
3
4
  import { StateTreeLUTPair } from '../constants';
5
+ /**
6
+ * Get the currently active output queue from a merkle context.
7
+ *
8
+ * @param merkleContext The merkle context to get the output queue from
9
+ * @returns The output queue public key
10
+ */
11
+ export declare function getOutputQueue(merkleContext: MerkleContext): PublicKey;
12
+ /**
13
+ * Get the currently active output tree info from a merkle context.
14
+ *
15
+ * @param merkleContext The merkle context to get the output tree info from
16
+ * @returns The output tree info
17
+ */
18
+ export declare function getOutputTreeInfo(merkleContext: MerkleContext): TreeInfo;
4
19
  /**
5
20
  * @deprecated use {@link getTreeInfoByPubkey} instead
6
21
  */
@@ -11,3 +11,4 @@ export * from './sleep';
11
11
  export * from './validation';
12
12
  export * from './state-tree-lookup-table';
13
13
  export * from './get-state-tree-infos';
14
+ export * from './pack-decompress';
@@ -0,0 +1,31 @@
1
+ import { PublicKey, AccountMeta } from '@solana/web3.js';
2
+ import { ValidityProof } from '../state';
3
+ import { TreeInfo } from '../state/types';
4
+ export interface AccountDataWithTreeInfo {
5
+ key: string;
6
+ data: any;
7
+ treeInfo: TreeInfo;
8
+ }
9
+ export interface PackedDecompressResult {
10
+ proofOption: {
11
+ 0: ValidityProof | null;
12
+ };
13
+ compressedAccounts: any[];
14
+ systemAccountsOffset: number;
15
+ remainingAccounts: AccountMeta[];
16
+ }
17
+ /**
18
+ * Pack accounts and proof for decompressAccountsIdempotent instruction.
19
+ * This function prepares compressed account data, validity proof, and remaining accounts
20
+ * for idempotent decompression operations.
21
+ *
22
+ * @param programId - The program ID
23
+ * @param proof - The validity proof with context
24
+ * @param accountsData - Array of account data with tree info
25
+ * @param addresses - Array of account addresses
26
+ * @returns Packed instruction parameters
27
+ */
28
+ export declare function packDecompressAccountsIdempotent(programId: PublicKey, proof: {
29
+ compressedProof: ValidityProof | null;
30
+ treeInfos: TreeInfo[];
31
+ }, accountsData: AccountDataWithTreeInfo[], addresses: PublicKey[]): Promise<PackedDecompressResult>;