@rialo/ts-cdk 0.1.9 → 0.2.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/dist/index.d.ts CHANGED
@@ -1,140 +1,3 @@
1
- /**
2
- * Error handling for the Rialo CDK.
3
- *
4
- * This module defines the common error types used throughout the Rialo CDK.
5
- * It provides a centralized error handling mechanism for all operations.
6
- */
7
- /**
8
- * Structured RPC error information parsed from JSON-RPC error responses.
9
- */
10
- interface RpcErrorDetails$1 {
11
- /** HTTP status code (e.g., 200, 422, 500) */
12
- status?: number;
13
- /** JSON-RPC error code (e.g., -32002) */
14
- code: number;
15
- /** Human-readable error message */
16
- message: string;
17
- }
18
- /**
19
- * Error types for different subsystems in the Rialo CDK.
20
- */
21
- declare enum RialoErrorType {
22
- /** Errors related to file or system I/O operations */
23
- IO = "IO",
24
- /** Errors occurring during RPC communication with blockchain nodes */
25
- RPC = "RPC",
26
- /** Errors related to public key parsing or validation */
27
- PARSE_PUBKEY = "PARSE_PUBKEY",
28
- /** Errors related to blockhash parsing or validation */
29
- INVALID_BLOCKHASH_FORMAT = "INVALID_BLOCKHASH_FORMAT",
30
- /** Errors related to wallet operations such as creation, loading, or signing */
31
- WALLET = "WALLET",
32
- /** Errors related to configuration loading, parsing, or validation */
33
- CONFIG = "CONFIG",
34
- /** Errors occurring during transaction building, signing, or submission */
35
- TRANSACTION = "TRANSACTION",
36
- /** Network-related errors, including HTTP client errors */
37
- NETWORK = "NETWORK",
38
- /** Errors related to password handling, validation, or verification */
39
- PASSWORD = "PASSWORD",
40
- /** Errors related to encryption or decryption operations */
41
- ENCRYPTION = "ENCRYPTION",
42
- /** Errors occurring during JSON parsing, serialization, or deserialization */
43
- JSON = "JSON",
44
- /** Errors related to BIP32 key derivation */
45
- BIP32 = "BIP32",
46
- /** Errors related to invalid input parameters or data */
47
- INVALID_INPUT = "INVALID_INPUT",
48
- /** Errors related to serialization/deserialization */
49
- SERIALIZATION = "SERIALIZATION"
50
- }
51
- /**
52
- * Base error class for all Rialo CDK errors.
53
- *
54
- * Provides structured error handling with type categorization and optional
55
- * cause tracking for error chains. Use the static factory methods for
56
- * consistent error creation across the SDK.
57
- *
58
- * @example
59
- * ```typescript
60
- * // Create typed errors using factory methods
61
- * throw RialoError.invalidInput("Amount must be positive");
62
- * throw RialoError.network("Connection failed", originalError);
63
- * throw RialoError.rpc({ code: -32002, message: "Invalid params" });
64
- *
65
- * // Handle errors with type information
66
- * try {
67
- * await client.sendTransaction(tx);
68
- * } catch (error) {
69
- * if (error instanceof RialoError && error.type === RialoErrorType.NETWORK) {
70
- * console.log("Network error, retrying...");
71
- * }
72
- * }
73
- * ```
74
- */
75
- declare class RialoError extends Error {
76
- readonly type: RialoErrorType;
77
- readonly cause?: Error;
78
- readonly details?: RpcErrorDetails$1;
79
- constructor(type: RialoErrorType, message: string, cause?: Error, details?: RpcErrorDetails$1);
80
- /**
81
- * Creates an IO error.
82
- */
83
- static io(message: string, cause?: Error): RialoError;
84
- /**
85
- * Creates an RPC error.
86
- */
87
- static rpc(details: RpcErrorDetails$1): RialoError;
88
- /**
89
- * Creates a public key parsing error.
90
- */
91
- static parsePubkey(message: string): RialoError;
92
- /**
93
- * Creates a blockhash format error.
94
- */
95
- static invalidBlockhash(message: string): RialoError;
96
- /**
97
- * Creates a wallet error.
98
- */
99
- static wallet(message: string): RialoError;
100
- /**
101
- * Creates a configuration error.
102
- */
103
- static config(message: string): RialoError;
104
- /**
105
- * Creates a transaction error.
106
- */
107
- static transaction(message: string): RialoError;
108
- /**
109
- * Creates a network error.
110
- */
111
- static network(message: string, cause?: Error): RialoError;
112
- /**
113
- * Creates a password error.
114
- */
115
- static password(message: string): RialoError;
116
- /**
117
- * Creates an encryption error.
118
- */
119
- static encryption(message: string): RialoError;
120
- /**
121
- * Creates a JSON error.
122
- */
123
- static json(message: string, cause?: Error): RialoError;
124
- /**
125
- * Creates a BIP32 error.
126
- */
127
- static bip32(message: string): RialoError;
128
- /**
129
- * Creates an invalid input error.
130
- */
131
- static invalidInput(message: string): RialoError;
132
- /**
133
- * Creates a serialization error.
134
- */
135
- static serialization(message: string): RialoError;
136
- }
137
-
138
1
  interface HttpTransportConfig {
139
2
  /** Request timeout in milliseconds */
140
3
  timeout?: number;
@@ -228,10 +91,13 @@ declare const URL_TESTNET: string;
228
91
  declare const URL_DEVNET: string;
229
92
  /** Rialo localnet RPC URL */
230
93
  declare const URL_LOCALNET: string;
94
+ /** Rialo shitnet RPC URL */
95
+ declare const URL_SHITNET: string;
231
96
  declare const RIALO_MAINNET_CHAIN: ChainDefinition;
232
97
  declare const RIALO_TESTNET_CHAIN: ChainDefinition;
233
98
  declare const RIALO_DEVNET_CHAIN: ChainDefinition;
234
99
  declare const RIALO_LOCALNET_CHAIN: ChainDefinition;
100
+ declare const RIALO_SHITNET_CHAIN: ChainDefinition;
235
101
  /** System program ID */
236
102
  declare const SYSTEM_PROGRAM_ID: string;
237
103
  /** Base derivation path for Rialo wallets (BIP44 coin type 756) */
@@ -252,7 +118,12 @@ declare enum CryptoErrorCode {
252
118
  INVALID_BLOCKHASH = "INVALID_BLOCKHASH",
253
119
  INVALID_MNEMONIC = "INVALID_MNEMONIC",
254
120
  KEY_DERIVATION_FAILED = "KEY_DERIVATION_FAILED",
255
- KEYPAIR_DISPOSED = "KEYPAIR_DISPOSED"
121
+ KEYPAIR_DISPOSED = "KEYPAIR_DISPOSED",
122
+ MAX_SEED_LENGTH_EXCEEDED = "MAX_SEED_LENGTH_EXCEEDED",
123
+ MAX_SEEDS_EXCEEDED = "MAX_SEEDS_EXCEEDED",
124
+ INVALID_SEEDS_ON_CURVE = "INVALID_SEEDS_ON_CURVE",
125
+ NO_VIABLE_BUMP_SEED = "NO_VIABLE_BUMP_SEED",
126
+ INVALID_SEED = "INVALID_SEED"
256
127
  }
257
128
  /**
258
129
  * Error class for cryptographic operations.
@@ -316,6 +187,18 @@ declare class Signature {
316
187
  toJSON(): string;
317
188
  }
318
189
 
190
+ /**
191
+ * A seed for PDA derivation - string (UTF-8) or raw bytes.
192
+ */
193
+ type Seed = string | Uint8Array;
194
+ /**
195
+ * Bump seed (0-255) that pushes derived address off the Ed25519 curve.
196
+ */
197
+ type Bump = number;
198
+ /**
199
+ * Result of PDA derivation: [address, bump].
200
+ */
201
+ type PDA = readonly [PublicKey, Bump];
319
202
  /**
320
203
  * Represents a 32-byte Ed25519 public key.
321
204
  *
@@ -350,6 +233,80 @@ declare class PublicKey {
350
233
  * @throws {CryptoError} If string is invalid or decodes to wrong length
351
234
  */
352
235
  static fromString(str: string): PublicKey;
236
+ /**
237
+ * Derives a program address from seeds and a program ID.
238
+ *
239
+ * @remarks
240
+ * This is the low-level derivation function. It will throw if the resulting
241
+ * address falls on the Ed25519 curve. For most use cases, prefer
242
+ * {@link findProgramAddress} which automatically finds a valid bump seed.
243
+ *
244
+ * Use this method when you already know the bump seed (e.g., stored on-chain
245
+ * or passed from a previous computation) for better performance.
246
+ *
247
+ * @param seeds - Array of seeds (strings or byte arrays, max 16 seeds, each max 32 bytes)
248
+ * @param programId - The program that will own this PDA
249
+ * @returns The derived public key
250
+ * @throws {CryptoError} If seeds exceed limits or result is on curve
251
+ *
252
+ * @example
253
+ * ```typescript
254
+ * // With known bump seed (most efficient for verification)
255
+ * const pda = PublicKey.createProgramAddress(
256
+ * ["metadata", mintPubkey.toBytes(), new Uint8Array([254])],
257
+ * metadataProgramId
258
+ * );
259
+ * ```
260
+ */
261
+ static createProgramAddress(seeds: Seed[], programId: PublicKey): PublicKey;
262
+ /**
263
+ * Finds a valid program derived address by searching for a bump seed.
264
+ *
265
+ * @remarks
266
+ * Iterates from bump 255 down to 0, returning the first combination that
267
+ * produces an address off the Ed25519 curve. The bump seed should be stored
268
+ * or passed to programs to allow efficient verification via {@link createProgramAddress}.
269
+ *
270
+ * @param seeds - Array of seeds (max 16 seeds, each max 32 bytes)
271
+ * @param programId - The program that will own this PDA
272
+ * @returns Tuple of [PublicKey, Bump] where bump is 0-255
273
+ * @throws {CryptoError} If no valid bump found (extremely rare) or seeds invalid
274
+ *
275
+ * @example
276
+ * ```typescript
277
+ * const [vaultPda, vaultBump] = PublicKey.findProgramAddress(
278
+ * ["vault", userPubkey.toBytes()],
279
+ * programId
280
+ * );
281
+ *
282
+ * // Store bump for later use
283
+ * console.log(`Vault: ${vaultPda}, Bump: ${vaultBump}`);
284
+ * ```
285
+ */
286
+ static findProgramAddress(seeds: Seed[], programId: PublicKey): PDA;
287
+ /**
288
+ * Creates a derived address from a base address, seed string, and program ID.
289
+ *
290
+ * @remarks
291
+ * Unlike PDAs, this derivation CAN produce addresses on the curve.
292
+ * This is useful for creating deterministic addresses that a user can sign for,
293
+ * where the base address's private key holder can sign transactions.
294
+ *
295
+ * @param baseAddress - The base public key (signer)
296
+ * @param seed - A seed string (max 32 bytes when UTF-8 encoded)
297
+ * @param programId - The program that will own the derived account
298
+ * @returns The derived address
299
+ *
300
+ * @example
301
+ * ```typescript
302
+ * const derivedAddress = PublicKey.createWithSeed(
303
+ * userPubkey,
304
+ * "savings-account",
305
+ * systemProgramId
306
+ * );
307
+ * ```
308
+ */
309
+ static createWithSeed(baseAddress: PublicKey, seed: string, programId: PublicKey): PublicKey;
353
310
  /**
354
311
  * Returns a copy of the raw bytes.
355
312
  */
@@ -377,6 +334,12 @@ declare class PublicKey {
377
334
  * ```
378
335
  */
379
336
  verify(message: Uint8Array, signature: Signature): boolean;
337
+ /**
338
+ * Checks if the public key is on the Ed25519 curve.
339
+ *
340
+ * @returns True if the public key is on the curve, false otherwise
341
+ */
342
+ isOnCurve(): boolean;
380
343
  /**
381
344
  * JSON serialization (returns base58 string).
382
345
  */
@@ -599,1437 +562,1911 @@ declare class Mnemonic {
599
562
  }
600
563
 
601
564
  /**
602
- * Metadata about an account in a transaction.
603
- */
604
- interface AccountMeta {
605
- /** Account public key */
606
- readonly pubkey: PublicKey;
607
- /** Whether this account must sign the transaction */
608
- readonly isSigner: boolean;
609
- /** Whether this account's data will be modified */
610
- readonly isWritable: boolean;
611
- }
612
- /**
613
- * An instruction to execute on-chain.
565
+ * Checks if a 32-byte array represents a valid point on the Ed25519 curve.
566
+ *
567
+ * This is used for PDA (Program Derived Address) derivation, where valid PDAs
568
+ * must NOT be on the curve to ensure they can only be signed by the program.
569
+ *
570
+ * @param bytes - 32-byte public key or hash to check
571
+ * @returns true if the bytes represent a valid Ed25519 point, false otherwise
572
+ *
573
+ * @example
574
+ * ```typescript
575
+ * const hash = sha256(data);
576
+ * if (!isOnCurve(hash)) {
577
+ * // Valid PDA - not on curve
578
+ * }
579
+ * ```
614
580
  */
615
- interface Instruction {
616
- /** Program that will execute this instruction */
617
- readonly programId: PublicKey;
618
- /** Accounts used by this instruction */
619
- readonly accounts: readonly AccountMeta[];
620
- /** Instruction-specific data */
621
- readonly data: Uint8Array;
622
- }
581
+ declare function isOnCurve(bytes: Uint8Array): boolean;
623
582
  /**
624
- * Message header containing signature requirements.
583
+ * Converts a seed to a 32-byte array.
584
+ *
585
+ * @param seed - Seed to convert
586
+ * @returns 32-byte array
625
587
  */
626
- interface MessageHeader {
627
- /** Number of signatures required */
628
- readonly numRequiredSignatures: number;
629
- /** Number of read-only signed accounts */
630
- readonly numReadonlySignedAccounts: number;
631
- /** Number of read-only unsigned accounts */
632
- readonly numReadonlyUnsignedAccounts: number;
633
- }
588
+ declare function seedToBytes(seed: Seed): Uint8Array;
634
589
  /**
635
- * Compiled instruction with account indices.
590
+ * Concatenates multiple byte arrays into a single byte array.
591
+ *
592
+ * @param arrays - Byte arrays to concatenate
593
+ * @returns Concatenated byte array
636
594
  */
637
- interface CompiledInstruction {
638
- /** Index of program in account keys array */
639
- readonly programIdIndex: number;
640
- /** Indices of accounts in account keys array */
641
- readonly accountKeyIndexes: readonly number[];
642
- /** Instruction data */
643
- readonly data: Uint8Array;
644
- }
595
+ declare function concatBytes(...arrays: Uint8Array[]): Uint8Array;
645
596
 
646
597
  /**
647
- * Account metadata table for deduplication and sorting.
648
- * Avoids: Complex account sorting logic scattered throughout builder
598
+ * Error handling for the Rialo CDK.
599
+ *
600
+ * This module defines the common error types used throughout the Rialo CDK.
601
+ * It provides a centralized error handling mechanism for all operations.
649
602
  */
650
-
651
603
  /**
652
- * Internal account entry with aggregated metadata.
604
+ * Structured RPC error information parsed from JSON-RPC error responses.
653
605
  */
654
- interface AccountEntry {
655
- pubkey: PublicKey;
656
- isSigner: boolean;
657
- isWritable: boolean;
606
+ interface RpcErrorDetails$1 {
607
+ /** HTTP status code (e.g., 200, 422, 500) */
608
+ status?: number;
609
+ /** JSON-RPC error code (e.g., -32002) */
610
+ code: number;
611
+ /** Human-readable error message */
612
+ message: string;
658
613
  }
659
614
  /**
660
- * Manages account deduplication and sorting for transaction messages.
661
- *
662
- * Accounts are sorted according to these rules:
663
- * 1. Signer + writable accounts first
664
- * 2. Then signer + readonly accounts
665
- * 3. Then non-signer + writable accounts
666
- * 4. Finally non-signer + readonly accounts
667
- * 5. Within each group, sort by public key bytes
668
- *
669
- * This matches Solana's account sorting rules for compatibility.
615
+ * Error types for different subsystems in the Rialo CDK.
670
616
  */
671
- declare class AccountMetaTable {
672
- private readonly accounts;
673
- private readonly accountOrder;
674
- /**
675
- * Add or update an account in the table.
676
- * If account already exists, merges signer/writable flags (OR operation).
617
+ declare enum RialoErrorType {
618
+ /** Errors related to file or system I/O operations */
619
+ IO = "IO",
620
+ /** Errors occurring during RPC communication with blockchain nodes */
621
+ RPC = "RPC",
622
+ /** Errors related to public key parsing or validation */
623
+ PARSE_PUBKEY = "PARSE_PUBKEY",
624
+ /** Errors related to blockhash parsing or validation */
625
+ INVALID_BLOCKHASH_FORMAT = "INVALID_BLOCKHASH_FORMAT",
626
+ /** Errors related to wallet operations such as creation, loading, or signing */
627
+ WALLET = "WALLET",
628
+ /** Errors related to configuration loading, parsing, or validation */
629
+ CONFIG = "CONFIG",
630
+ /** Errors occurring during transaction building, signing, or submission */
631
+ TRANSACTION = "TRANSACTION",
632
+ /** Network-related errors, including HTTP client errors */
633
+ NETWORK = "NETWORK",
634
+ /** Errors related to password handling, validation, or verification */
635
+ PASSWORD = "PASSWORD",
636
+ /** Errors related to encryption or decryption operations */
637
+ ENCRYPTION = "ENCRYPTION",
638
+ /** Errors occurring during JSON parsing, serialization, or deserialization */
639
+ JSON = "JSON",
640
+ /** Errors related to BIP32 key derivation */
641
+ BIP32 = "BIP32",
642
+ /** Errors related to invalid input parameters or data */
643
+ INVALID_INPUT = "INVALID_INPUT",
644
+ /** Errors related to serialization/deserialization */
645
+ SERIALIZATION = "SERIALIZATION"
646
+ }
647
+ /**
648
+ * Base error class for all Rialo CDK errors.
649
+ *
650
+ * Provides structured error handling with type categorization and optional
651
+ * cause tracking for error chains. Use the static factory methods for
652
+ * consistent error creation across the SDK.
653
+ *
654
+ * @example
655
+ * ```typescript
656
+ * // Create typed errors using factory methods
657
+ * throw RialoError.invalidInput("Amount must be positive");
658
+ * throw RialoError.network("Connection failed", originalError);
659
+ * throw RialoError.rpc({ code: -32002, message: "Invalid params" });
660
+ *
661
+ * // Handle errors with type information
662
+ * try {
663
+ * await client.sendTransaction(tx);
664
+ * } catch (error) {
665
+ * if (error instanceof RialoError && error.type === RialoErrorType.NETWORK) {
666
+ * console.log("Network error, retrying...");
667
+ * }
668
+ * }
669
+ * ```
670
+ */
671
+ declare class RialoError extends Error {
672
+ readonly type: RialoErrorType;
673
+ readonly cause?: Error;
674
+ readonly details?: RpcErrorDetails$1;
675
+ constructor(type: RialoErrorType, message: string, cause?: Error, details?: RpcErrorDetails$1);
676
+ /**
677
+ * Creates an IO error.
677
678
  */
678
- add(meta: AccountMeta): void;
679
+ static io(message: string, cause?: Error): RialoError;
679
680
  /**
680
- * Add multiple accounts at once.
681
+ * Creates an RPC error.
681
682
  */
682
- addAll(metas: readonly AccountMeta[]): void;
683
+ static rpc(details: RpcErrorDetails$1): RialoError;
683
684
  /**
684
- * Get the index of an account in the sorted order.
685
- * Returns -1 if account not found.
685
+ * Creates a public key parsing error.
686
686
  */
687
- getIndex(pubkey: PublicKey): number;
687
+ static parsePubkey(message: string): RialoError;
688
688
  /**
689
- * Get sorted accounts according to transaction rules.
689
+ * Creates a blockhash format error.
690
690
  */
691
- getSortedAccounts(): readonly AccountEntry[];
691
+ static invalidBlockhash(message: string): RialoError;
692
692
  /**
693
- * Get the message header based on sorted accounts.
693
+ * Creates a wallet error.
694
694
  */
695
- getHeader(): MessageHeader;
695
+ static wallet(message: string): RialoError;
696
696
  /**
697
- * Get sorted public keys.
697
+ * Creates a configuration error.
698
698
  */
699
- getPublicKeys(): readonly PublicKey[];
699
+ static config(message: string): RialoError;
700
700
  /**
701
- * Get number of accounts in table.
701
+ * Creates a transaction error.
702
702
  */
703
- size(): number;
703
+ static transaction(message: string): RialoError;
704
+ /**
705
+ * Creates a network error.
706
+ */
707
+ static network(message: string, cause?: Error): RialoError;
708
+ /**
709
+ * Creates a password error.
710
+ */
711
+ static password(message: string): RialoError;
712
+ /**
713
+ * Creates an encryption error.
714
+ */
715
+ static encryption(message: string): RialoError;
716
+ /**
717
+ * Creates a JSON error.
718
+ */
719
+ static json(message: string, cause?: Error): RialoError;
720
+ /**
721
+ * Creates a BIP32 error.
722
+ */
723
+ static bip32(message: string): RialoError;
724
+ /**
725
+ * Creates an invalid input error.
726
+ */
727
+ static invalidInput(message: string): RialoError;
728
+ /**
729
+ * Creates a serialization error.
730
+ */
731
+ static serialization(message: string): RialoError;
732
+ }
733
+
734
+ /**
735
+ * Base client with JSON-RPC protocol handling.
736
+ *
737
+ * All specific clients (QueryClient, TransactionClient) extend this.
738
+ */
739
+ declare class BaseRpcClient {
740
+ protected readonly transport: HttpTransport;
741
+ private requestId;
742
+ constructor(transport: HttpTransport);
743
+ /**
744
+ * Makes a JSON-RPC 2.0 method call with type safety.
745
+ *
746
+ * Handles request serialization, response validation, and error mapping.
747
+ */
748
+ protected call<T>(method: string, params?: unknown[]): Promise<T>;
749
+ /**
750
+ * Validate JSON-RPC response structure
751
+ */
752
+ private isValidJsonRpcResponse;
753
+ /**
754
+ * Generates the next request ID with Overflow Protection.
755
+ * @returns The next request ID.
756
+ */
757
+ private nextRequestId;
758
+ /**
759
+ * Returns the configured RPC endpoint URL.
760
+ */
761
+ getUrl(): string;
762
+ }
763
+
764
+ /**
765
+ * RPC type definitions for the Rialo blockchain.
766
+ */
767
+
768
+ /**
769
+ * Account information response.
770
+ */
771
+ interface AccountInfo {
772
+ /** Account balance in smallest denomination */
773
+ balance: bigint;
774
+ /** Owner program public key */
775
+ owner: PublicKey;
776
+ /** Account data */
777
+ data: Uint8Array;
778
+ /** Whether the account is executable */
779
+ executable: boolean;
780
+ /** Rent epoch */
781
+ rentEpoch: bigint;
782
+ }
783
+ /**
784
+ * Transaction response.
785
+ */
786
+ interface TransactionResponse {
787
+ /** Transaction signature */
788
+ signature: string;
789
+ /** Block height */
790
+ blockHeight?: bigint;
791
+ /** Error message if transaction failed */
792
+ err?: string;
793
+ }
794
+ /**
795
+ * Options for sending a transaction.
796
+ */
797
+ interface SendTransactionOptions {
798
+ /** Skip preflight transaction checks */
799
+ skipPreflight?: boolean;
800
+ /** Maximum number of times to retry */
801
+ maxRetries?: number;
802
+ }
803
+ /**
804
+ * Epoch information response.
805
+ */
806
+ interface EpochInfoResponse {
807
+ /** Current epoch */
808
+ epoch: bigint;
809
+ /** Current slot in the epoch */
810
+ slotIndex: bigint;
811
+ /** Total slots in the epoch */
812
+ slotsInEpoch: bigint;
813
+ /** Absolute slot number */
814
+ absoluteSlot: bigint;
815
+ /** Block height */
816
+ blockHeight: bigint;
817
+ /** Transaction count */
818
+ transactionCount?: bigint;
819
+ }
820
+ /**
821
+ * Subscription kind.
822
+ */
823
+ type SubscriptionKind = "Persistent" | "OneShot";
824
+ /**
825
+ * Subscription data.
826
+ */
827
+ interface Subscription {
828
+ /** Type of subscription */
829
+ kind: SubscriptionKind;
830
+ /** Topic for the subscription */
831
+ topic: string;
832
+ /** Instructions to execute when triggered */
833
+ instructions: unknown[];
834
+ /** Subscriber public key (base58) */
835
+ subscriber: string;
836
+ /** Event account public key (base58) */
837
+ eventAccount?: string;
838
+ /** Timestamp range [start, end] */
839
+ timestampRange?: [bigint, bigint];
840
+ }
841
+ /**
842
+ * Triggered transaction data.
843
+ */
844
+ interface TriggeredTransaction {
845
+ /** Transaction signature (base58) */
846
+ signature: string;
847
+ /** Block number where the transaction was executed */
848
+ blockNumber: bigint;
849
+ }
850
+ /**
851
+ * Get workflow lineage request.
852
+ */
853
+ interface GetWorkflowLineageRequest {
854
+ /** Root transaction signature (base58) */
855
+ signature: string;
856
+ /** Maximum depth to traverse (1-100, default 3) */
857
+ maxDepth?: number;
858
+ /** Whether to include event details */
859
+ includeEvents?: boolean;
860
+ }
861
+ /**
862
+ * Event data from a workflow trigger.
863
+ */
864
+ interface EventData {
865
+ /** Event topic */
866
+ topic: string;
867
+ /** Event attributes */
868
+ attributes: Record<string, unknown>;
869
+ }
870
+ /**
871
+ * Timestamp range.
872
+ */
873
+ interface TimestampRange {
874
+ /** Start timestamp (unix) */
875
+ from: bigint;
876
+ /** End timestamp (unix) */
877
+ to: bigint;
878
+ }
879
+ /**
880
+ * Information about what triggered a workflow transaction.
881
+ */
882
+ interface TriggerInfo {
883
+ /** Event that triggered the transaction */
884
+ event: EventData;
885
+ /** Subscription public key (base58) */
886
+ subscriptionPubkey: string;
887
+ /** Timestamp range for the trigger */
888
+ timestampRange?: TimestampRange;
889
+ /** Event account public key (base58) */
890
+ eventAccount?: string;
891
+ }
892
+ /**
893
+ * Transaction node data within a workflow.
894
+ */
895
+ interface TransactionNodeData {
896
+ /** Block height */
897
+ blockHeight: bigint;
898
+ /** Timestamp (unix) */
899
+ timestamp: bigint;
900
+ /** Whether the transaction succeeded */
901
+ success: boolean;
902
+ /** Number of instructions */
903
+ instructionCount: number;
904
+ /** Program IDs of instructions (base58) */
905
+ instructionProgramIds: string[];
906
+ }
907
+ /**
908
+ * A node in the workflow lineage tree.
909
+ */
910
+ interface WorkflowNode {
911
+ /** Transaction signature (base58) */
912
+ id: string;
913
+ /** Distance from root transaction */
914
+ depth: number;
915
+ /** Transaction data */
916
+ data: TransactionNodeData;
917
+ /** Subscriptions on this transaction */
918
+ subscriptions: Subscription[];
919
+ /** What triggered this transaction */
920
+ triggeredBy?: TriggerInfo;
921
+ /** Child transaction signatures (base58) */
922
+ workflowChildren: string[];
923
+ /** Whether there are more children not shown */
924
+ hasMoreChildren: boolean;
925
+ }
926
+ /**
927
+ * Workflow lineage tree.
928
+ */
929
+ interface WorkflowLineage {
930
+ /** Nodes in the workflow tree */
931
+ workflowNodes: WorkflowNode[];
932
+ }
933
+ /**
934
+ * Reason for truncating workflow lineage traversal.
935
+ */
936
+ type TruncationReason = "MaxDepth" | "MaxNodes" | "None";
937
+ /**
938
+ * Get workflow lineage response.
939
+ */
940
+ interface GetWorkflowLineageResponse {
941
+ /** Workflow lineage tree */
942
+ lineage: WorkflowLineage;
943
+ /** Leaf transaction signatures (base58) */
944
+ leaves: string[];
945
+ /** Whether traversal was truncated */
946
+ truncated: boolean;
947
+ /** Reason for truncation */
948
+ truncationReason: TruncationReason;
949
+ /** Hints for continuing traversal (base58 signatures) */
950
+ continuationHints: string[];
951
+ }
952
+ /**
953
+ * Get signatures for address configuration.
954
+ */
955
+ interface GetSignaturesForAddressConfig {
956
+ /** Maximum number of signatures to return */
957
+ limit?: number;
958
+ /** Start searching backwards from this signature */
959
+ before?: string;
960
+ /** Start searching forwards from this signature */
961
+ until?: string;
962
+ }
963
+ /**
964
+ * Signature information.
965
+ */
966
+ interface SignatureInfo {
967
+ signature: string;
968
+ blockHeight: bigint;
969
+ blockTime: bigint;
970
+ err?: string;
971
+ }
972
+ /**
973
+ * Get health response.
974
+ */
975
+ type GetHealthResponse = "ok" | string;
976
+ /**
977
+ * Get transactions configuration.
978
+ */
979
+ interface GetTransactionsConfig {
980
+ /** Maximum number of transactions to return */
981
+ limit?: number;
982
+ /** Encoding format */
983
+ encoding?: "json" | "base58" | "base64";
704
984
  }
705
-
706
985
  /**
707
- * Error codes for transaction operations.
986
+ * Get transactions response.
708
987
  */
709
- declare enum TransactionErrorCode {
710
- INVALID_INSTRUCTION = "INVALID_INSTRUCTION",
711
- INVALID_ACCOUNT_META = "INVALID_ACCOUNT_META",
712
- NO_INSTRUCTIONS = "NO_INSTRUCTIONS",
713
- DUPLICATE_ACCOUNT = "DUPLICATE_ACCOUNT",
714
- MISSING_SIGNATURE = "MISSING_SIGNATURE",
715
- INVALID_SIGNATURE = "INVALID_SIGNATURE",
716
- SIGNATURE_OUT_OF_BOUNDS = "SIGNATURE_OUT_OF_BOUNDS",
717
- SIGNER_NOT_FOUND = "SIGNER_NOT_FOUND",
718
- ALREADY_SIGNED = "ALREADY_SIGNED",
719
- INVALID_MESSAGE_FORMAT = "INVALID_MESSAGE_FORMAT",
720
- INSUFFICIENT_DATA = "INSUFFICIENT_DATA",
721
- SERIALIZATION_FAILED = "SERIALIZATION_FAILED",
722
- SIMULATION_FAILED = "SIMULATION_FAILED",
723
- INSUFFICIENT_FUNDS = "INSUFFICIENT_FUNDS",
724
- BLOCKHASH_EXPIRED = "BLOCKHASH_EXPIRED"
988
+ interface GetTransactionsResponse {
989
+ /** Array of transaction data */
990
+ transactions: Array<Record<string, unknown>>;
725
991
  }
726
992
  /**
727
- * Error class for transaction operations with structured error information.
993
+ * Signature status from the RPC.
728
994
  */
729
- declare class TransactionError extends Error {
730
- readonly code: TransactionErrorCode;
731
- readonly details?: Record<string, unknown> | undefined;
732
- constructor(code: TransactionErrorCode, message: string, details?: Record<string, unknown> | undefined);
733
- static noInstructions(): TransactionError;
734
- static signerNotFound(pubkey: string): TransactionError;
735
- static missingSignature(index: number, pubkey: string): TransactionError;
736
- static simulationFailed(logs: string[], error: string): TransactionError;
737
- static insufficientFunds(required: bigint, available: bigint): TransactionError;
738
- toJSON(): {
739
- code: TransactionErrorCode;
740
- message: string;
741
- details?: Record<string, unknown>;
742
- };
995
+ interface SignatureStatus {
996
+ /** Slot in which the transaction was processed */
997
+ slot: bigint;
998
+ /** Whether the transaction has been executed */
999
+ executed: boolean;
1000
+ /** Error message if transaction failed */
1001
+ err?: string;
743
1002
  }
744
-
745
1003
  /**
746
- * Create an instruction with Borsh-encoded data.
747
- *
748
- * @example
749
- * ```typescript
750
- * // Define your instruction data class
751
- * class MyInstructionData {
752
- * @field({ type: 'u8' })
753
- * instruction: number;
754
- *
755
- * @field({ type: 'u64' })
756
- * amount: bigint;
757
- *
758
- * @field({ type: option('string') })
759
- * memo?: string;
760
- * }
761
- *
762
- * // Create instruction
763
- * const instruction = createBorshInstruction({
764
- * programId: myProgramId,
765
- * accounts: [
766
- * { pubkey: account1, isSigner: true, isWritable: true },
767
- * { pubkey: account2, isSigner: false, isWritable: false },
768
- * ],
769
- * data: new MyInstructionData({
770
- * instruction: 5,
771
- * amount: 1000n,
772
- * memo: "Hello, Rialo!",
773
- * }),
774
- * });
775
- * ```
1004
+ * Options for confirming a transaction.
776
1005
  */
777
- declare function createBorshInstruction<T>(params: {
778
- programId: PublicKey;
779
- accounts: AccountMeta[];
780
- data: T;
781
- }): Instruction;
1006
+ interface ConfirmTransactionOptions {
1007
+ /** Maximum number of retry attempts (default: 30) */
1008
+ maxRetries?: number;
1009
+ /** Delay between retries in milliseconds (default: 1000) */
1010
+ retryDelay?: number;
1011
+ }
782
1012
  /**
783
- * Helper for creating Borsh-serialized instruction data from a plain object.
784
- *
785
- * This is useful when you don't want to define a class with decorators.
786
- *
787
- * @example
788
- * ```typescript
789
- * const data = encodeBorshData({
790
- * instruction: { type: 'u8', value: 1 },
791
- * amount: { type: 'u64', value: 1000n },
792
- * recipient: { type: fixedArray('u8', 32), value: recipientBytes },
793
- * });
794
- * ```
1013
+ * Options for sending and confirming a transaction.
795
1014
  */
796
- declare function encodeBorshData(_schema: Record<string, {
797
- type: unknown;
798
- value: unknown;
799
- }>): Uint8Array;
800
-
1015
+ interface SendAndConfirmOptions extends SendTransactionOptions, ConfirmTransactionOptions {
1016
+ }
801
1017
  /**
802
- * System program instruction types.
1018
+ * Result of a confirmed transaction.
803
1019
  */
804
- declare enum SystemInstruction {
805
- CreateAccount = 0,
806
- Assign = 1,
807
- Transfer = 2,
808
- CreateAccountWithSeed = 3,
809
- AdvanceNonceAccount = 4,
810
- WithdrawNonceAccount = 5,
811
- InitializeNonceAccount = 6,
812
- AuthorizeNonceAccount = 7,
813
- Allocate = 8,
814
- AllocateWithSeed = 9,
815
- AssignWithSeed = 10,
816
- TransferWithSeed = 11
1020
+ interface ConfirmedTransaction {
1021
+ /** Transaction signature */
1022
+ signature: string;
1023
+ /** Whether the transaction was executed */
1024
+ executed: boolean;
1025
+ /** Error message if transaction failed */
1026
+ err?: string;
817
1027
  }
818
1028
  /**
819
- * Create a transfer instruction.
820
- *
821
- * Transfers native tokens from one account to another.
822
- *
823
- * @param from - Source account (must be signer)
824
- * @param to - Destination account
825
- * @param amount - Amount to transfer in smallest denomination (lamports)
826
- *
827
- * @example
828
- * ```typescript
829
- * const instruction = transferInstruction(fromPubkey, toPubkey, 1_000_000n);
830
- *
831
- * const tx = TransactionBuilder.create()
832
- * .setPayer(fromPubkey)
833
- * .addInstruction(instruction)
834
- * .build();
835
- * ```
1029
+ * Configuration for getAccountsByOwner.
836
1030
  */
837
- declare function transferInstruction(from: PublicKey, to: PublicKey, amount: bigint): Instruction;
1031
+ interface GetAccountsByOwnerConfig {
1032
+ /** Encoding format for account data */
1033
+ encoding?: "base64" | "base58" | "json" | "jsonParsed";
1034
+ /** Maximum number of accounts to return */
1035
+ limit?: number;
1036
+ /** Cursor for pagination (base58 pubkey) */
1037
+ after?: string;
1038
+ }
838
1039
  /**
839
- * Create an account creation instruction.
840
- *
841
- * @param from - Funding account (must be signer)
842
- * @param newAccount - New account to create (must be signer)
843
- * @param lamports - Initial balance for new account
844
- * @param space - Number of bytes to allocate for account data
845
- * @param owner - Program that will own the new account
1040
+ * Filter for getAccountsByOwner.
1041
+ * Matches Rust serde serialization format.
1042
+ */
1043
+ type AccountFilter = {
1044
+ type: "programAccounts";
1045
+ } | {
1046
+ type: "tokenAccounts";
1047
+ mint?: string;
1048
+ };
1049
+ /**
1050
+ * An account owned by a program or address.
846
1051
  */
847
- declare function createAccount(from: PublicKey, newAccount: PublicKey, lamports: bigint, space: bigint, owner: PublicKey): Instruction;
1052
+ interface OwnerAccount {
1053
+ /** Account public key */
1054
+ pubkey: PublicKey;
1055
+ /** Account information */
1056
+ account: AccountInfo;
1057
+ }
1058
+ /**
1059
+ * Pagination information.
1060
+ */
1061
+ interface PaginationInfo {
1062
+ /** Whether there are more results */
1063
+ hasMore: boolean;
1064
+ /** Cursor for next page (base58 pubkey) */
1065
+ nextCursor?: string;
1066
+ }
1067
+ /**
1068
+ * Get accounts by owner response.
1069
+ */
1070
+ interface GetAccountsByOwnerResponse {
1071
+ /** Array of owned accounts */
1072
+ value: OwnerAccount[];
1073
+ /** Pagination information */
1074
+ pagination?: PaginationInfo;
1075
+ }
848
1076
 
849
1077
  /**
850
- * An unsigned transaction message ready to be signed.
1078
+ * Main Rialo RPC client for blockchain interactions.
1079
+ */
1080
+
1081
+ /**
1082
+ * High-level Rialo RPC client for blockchain interactions.
851
1083
  *
852
- * This is the data that gets signed by transaction signers.
853
- * It's immutable to prevent accidental modification after creation.
1084
+ * Provides a unified interface for querying blockchain state and
1085
+ * sending transactions. Internally delegates to specialized clients
1086
+ * (QueryRpcClient, TransactionRpcClient) for modular organization.
854
1087
  *
855
1088
  * @example
856
1089
  * ```typescript
857
- * const message = MessageBuilder.create()
858
- * .setPayer(payer)
859
- * .setValidFrom(validFrom)
860
- * .addInstruction(transferInstruction)
861
- * .build();
1090
+ * import { createRialoClient, RIALO_DEVNET_CHAIN } from '@rialo/ts-cdk';
862
1091
  *
863
- * // Serialize for signing
864
- * const messageBytes = message.serialize();
1092
+ * const client = createRialoClient({ chain: RIALO_DEVNET_CHAIN });
1093
+ *
1094
+ * // Query operations
1095
+ * const balance = await client.getBalance(publicKey);
1096
+ * const chainId = client.getChainIdentifier();
1097
+ *
1098
+ * // Transaction operations
1099
+ * const signature = await client.sendTransaction(signedTx);
865
1100
  * ```
866
1101
  */
867
- declare class Message {
868
- /** Message header with signature requirements */
869
- readonly header: MessageHeader;
870
- /** All account public keys referenced in the transaction */
871
- readonly accountKeys: readonly PublicKey[];
872
- /** Transaction valid from (milliseconds since Unix epoch) */
873
- validFrom?: bigint;
874
- /** Compiled instructions with account indices */
875
- readonly instructions: readonly CompiledInstruction[];
876
- /** Cached serialized bytes */
877
- private serializedCache?;
878
- constructor(header: MessageHeader, accountKeys: readonly PublicKey[], validFrom: bigint, instructions: readonly CompiledInstruction[]);
1102
+ declare class RialoClient {
1103
+ private readonly queryClient;
1104
+ private readonly transactionClient;
1105
+ private readonly transport;
1106
+ private readonly chain;
1107
+ constructor(transport: HttpTransport, chain: ChainDefinition);
1108
+ /**
1109
+ * Returns the configured RPC endpoint URL.
1110
+ */
1111
+ getUrl(): string;
1112
+ /**
1113
+ * Returns the chain identifier.
1114
+ */
1115
+ getChainIdentifier(): IdentifierString;
1116
+ /**
1117
+ * Returns the chain configuration.
1118
+ */
1119
+ getChainConfig(): ChainDefinition;
1120
+ /**
1121
+ * Retrieves the balance of an account in kelvins (smallest unit).
1122
+ */
1123
+ getBalance(pubkey: PublicKey): Promise<bigint>;
1124
+ /**
1125
+ * Retrieves detailed information about an account.
1126
+ *
1127
+ * @returns Account info or null if account doesn't exist
1128
+ */
1129
+ getAccountInfo(pubkey: PublicKey): Promise<AccountInfo | null>;
1130
+ /**
1131
+ * Retrieves the current block height.
1132
+ */
1133
+ getBlockHeight(): Promise<bigint>;
1134
+ /**
1135
+ * Retrieves the signatures for an address.
1136
+ */
1137
+ getSignaturesForAddress(address: PublicKey, config?: GetSignaturesForAddressConfig): Promise<SignatureInfo[]>;
1138
+ /**
1139
+ * Retrieves detailed information about a transaction.
1140
+ *
1141
+ * @returns Transaction info or null if transaction not found
1142
+ */
1143
+ getTransaction(signature: string): Promise<TransactionResponse | null>;
1144
+ /**
1145
+ * Retrieves the total number of transactions processed since genesis.
1146
+ */
1147
+ getTransactionCount(): Promise<bigint>;
1148
+ /**
1149
+ * Retrieves the status of multiple transaction signatures.
1150
+ */
1151
+ getSignatureStatuses(signatures: string[]): Promise<(SignatureStatus | null)[]>;
879
1152
  /**
880
- * Serialize message to bytes for signing.
881
- * Result is cached for performance.
1153
+ * Retrieves current epoch information.
882
1154
  */
883
- serialize(): Uint8Array;
1155
+ getEpochInfo(): Promise<EpochInfoResponse>;
884
1156
  /**
885
- * Deserialize a message from wire format.
1157
+ * Checks the health status of the RPC node.
886
1158
  *
887
- * @param data - Serialized message bytes
888
- * @returns Deserialized Message
1159
+ * @returns "ok" if healthy, error message otherwise
889
1160
  */
890
- static deserialize(data: Uint8Array): Message;
891
- private serializeInternal;
892
- private serializeCompactArray;
893
- private serializeCompactU16;
1161
+ getHealth(): Promise<"ok" | string>;
894
1162
  /**
895
- * Get all signers required for this message.
1163
+ * Submits a signed transaction to the blockchain.
1164
+ *
1165
+ * @param transaction - Serialized signed transaction bytes
1166
+ * @param options - Transaction submission options
1167
+ * @returns Transaction signature
896
1168
  */
897
- getSigners(): readonly PublicKey[];
1169
+ sendTransaction(transaction: Uint8Array, options?: SendTransactionOptions): Promise<string>;
898
1170
  /**
899
- * Check if a public key is a required signer.
1171
+ * Requests an airdrop of tokens to an account.
1172
+ *
1173
+ * **Note**: Only available on devnet and testnet.
1174
+ *
1175
+ * @param pubkey - Account to receive the airdrop
1176
+ * @param amount - Amount in kelvins (smallest unit)
1177
+ * @returns Transaction signature
900
1178
  */
901
- isSignerRequired(pubkey: PublicKey): boolean;
1179
+ requestAirdrop(pubkey: PublicKey, amount: bigint): Promise<string>;
902
1180
  /**
903
- * Get the index of a signer in the signers array.
904
- * Returns -1 if not a signer.
1181
+ * Submits a signed transaction and waits for confirmation.
1182
+ *
1183
+ * @param transaction - Serialized signed transaction bytes
1184
+ * @param options - Transaction submission and confirmation options
1185
+ * @returns Confirmed transaction details
1186
+ * @throws {TransactionFailedError} If the transaction fails on-chain
1187
+ * @throws {TransactionConfirmationTimeoutError} If confirmation times out
1188
+ *
1189
+ * @example
1190
+ * ```typescript
1191
+ * const result = await client.sendAndConfirmTransaction(signedTx);
1192
+ * console.log(`Confirmed in slot ${result.slot}`);
1193
+ * ```
905
1194
  */
906
- getSignerIndex(pubkey: PublicKey): number;
907
- }
908
-
909
- /**
910
- * Interface for signing messages and transactions.
911
- *
912
- * Enables multiple signing strategies:
913
- * - **KeypairSigner**: Local keypair signing
914
- * - **Browser Wallet**: Browser extension integration
915
- * - **Hardware Wallet**: Ledger, Trezor, etc.
916
- * - **Remote Signer**: API-based signing services
917
- *
918
- * @example
919
- * ```typescript
920
- * // Browser wallet implementation
921
- * class BrowserWalletSigner implements Signer {
922
- * async getPublicKey(): Promise<PublicKey> {
923
- * const pubkey = await window.rialoWallet.getPublicKey();
924
- * return PublicKey.fromString(pubkey);
925
- * }
926
- *
927
- * async signMessage(message: Uint8Array): Promise<Signature> {
928
- * const sig = await window.rialoWallet.signMessage(message);
929
- * return Signature.fromBytes(sig);
930
- * }
931
- * }
932
- *
933
- * // Usage
934
- * const signer = new BrowserWalletSigner();
935
- * const publicKey = await signer.getPublicKey();
936
- * const signature = await signer.signMessage(message);
937
- * ```
938
- */
939
- interface Signer {
1195
+ sendAndConfirmTransaction(transaction: Uint8Array, options?: SendAndConfirmOptions): Promise<ConfirmedTransaction>;
940
1196
  /**
941
- * Retrieves the signer's public key.
1197
+ * Waits for a transaction to be confirmed.
942
1198
  *
943
- * **Note**: May trigger wallet connection prompts for browser wallets.
1199
+ * @param signature - Transaction signature to monitor
1200
+ * @param options - Confirmation options
1201
+ * @returns Confirmed transaction details
944
1202
  */
945
- getPublicKey(): Promise<PublicKey>;
1203
+ confirmTransaction(signature: string, options?: ConfirmTransactionOptions): Promise<ConfirmedTransaction>;
946
1204
  /**
947
- * Signs arbitrary message bytes.
1205
+ * Requests an airdrop and waits for confirmation.
948
1206
  *
949
- * @param message - Message bytes to sign
950
- * @returns Ed25519 signature over the message
1207
+ * **Note**: Only available on devnet and testnet.
951
1208
  */
952
- signMessage(message: Uint8Array): Promise<Signature>;
953
- }
954
-
955
- /**
956
- * Signer implementation using a local Ed25519 keypair.
957
- *
958
- * Provides synchronous signing without external dependencies.
959
- * Suitable for server-side applications, CLIs, and testing.
960
- *
961
- * @example
962
- * ```typescript
963
- * import { Keypair, KeypairSigner } from '@rialo/ts-cdk';
964
- *
965
- * // Generate new keypair
966
- * const keypair = Keypair.generate();
967
- * const signer = new KeypairSigner(keypair);
968
- *
969
- * // Or from mnemonic
970
- * const mnemonic = Mnemonic.generate();
971
- * const keypair = await mnemonic.toKeypair(0);
972
- * const signer = new KeypairSigner(keypair);
973
- *
974
- * // Sign messages
975
- * const publicKey = await signer.getPublicKey();
976
- * const signature = await signer.signMessage(message);
977
- * ```
978
- */
979
- declare class KeypairSigner implements Signer {
980
- private readonly keypair;
981
- constructor(keypair: Keypair);
1209
+ requestAirdropAndConfirm(pubkey: PublicKey, amount: bigint, options?: ConfirmTransactionOptions): Promise<ConfirmedTransaction>;
982
1210
  /**
983
- * Returns the keypair's public key.
1211
+ * Calculate the minimum balance required for an account to be rent-exempt.
1212
+ *
1213
+ * @param accountDataSize - The size of the account data in bytes
1214
+ * @returns The minimum balance in kelvins required for rent exemption
984
1215
  */
985
- getPublicKey(): Promise<PublicKey>;
1216
+ getMinimumBalanceForRentExemption(accountDataSize: number): Promise<bigint>;
986
1217
  /**
987
- * Signs a message using the keypair's private key.
1218
+ * Get the fee required to process a specific message.
1219
+ *
1220
+ * @param message - Base64-encoded serialized versioned message
1221
+ * @returns Fee in kelvins, or null if message is invalid
988
1222
  */
989
- signMessage(message: Uint8Array): Promise<Signature>;
1223
+ getFeeForMessage(message: string): Promise<bigint | null>;
1224
+ /**
1225
+ * Get information for multiple accounts in a single request.
1226
+ *
1227
+ * @param pubkeys - Array of public keys to query (1-100)
1228
+ * @returns Account information for each address
1229
+ */
1230
+ getMultipleAccounts(pubkeys: PublicKey[]): Promise<Array<AccountInfo | null>>;
1231
+ /**
1232
+ * Get all accounts owned by a specific program or address.
1233
+ *
1234
+ * @param owner - Program ID or owner public key
1235
+ * @param filter - Filter type (ProgramAccounts or TokenAccounts)
1236
+ * @param config - Optional configuration for pagination and encoding
1237
+ * @returns Accounts owned by the specified owner
1238
+ */
1239
+ getAccountsByOwner(owner: PublicKey, filter?: AccountFilter, config?: GetAccountsByOwnerConfig): Promise<GetAccountsByOwnerResponse>;
1240
+ /**
1241
+ * Get workflow lineage information for tracking execution history.
1242
+ *
1243
+ * @param request - Workflow lineage request with signature and options
1244
+ * @returns Workflow lineage tree with nodes and metadata
1245
+ */
1246
+ getWorkflowLineage(request: GetWorkflowLineageRequest): Promise<GetWorkflowLineageResponse>;
1247
+ /**
1248
+ * Get subscription for a given subscriber address and nonce.
1249
+ *
1250
+ * @param subscriber - The subscriber's public key
1251
+ * @param nonce - The nonce identifying the subscription
1252
+ * @returns The subscription for the subscriber and nonce
1253
+ */
1254
+ getSubscription(subscriber: PublicKey, nonce: string): Promise<Subscription>;
1255
+ /**
1256
+ * Get transactions triggered by a subscription account.
1257
+ *
1258
+ * @param subscriptionAccount - The subscription account public key
1259
+ * @param limit - Optional limit on transactions returned
1260
+ * @returns Triggered transactions for the subscription
1261
+ */
1262
+ getTriggeredTransactions(subscriptionAccount: PublicKey, limit?: number): Promise<TriggeredTransaction[]>;
990
1263
  }
991
1264
 
992
1265
  /**
993
- * A transaction with zero or more signatures.
994
- *
995
- * Transactions are immutable - signing methods return new instances.
996
- * This prevents accidental modification and signature tampering.
997
- *
998
- * @example
999
- * ```typescript
1000
- * // Simple signing
1001
- * const tx = builder.build();
1002
- * const signed = tx.sign(keypair);
1003
- *
1004
- * // Method chaining
1005
- * const signed = tx
1006
- * .sign(keypair1)
1007
- * .sign(keypair2)
1008
- * .sign(keypair3);
1266
+ * Query client for read-only RPC operations.
1267
+ */
1268
+
1269
+ /**
1270
+ * Client for querying blockchain state.
1009
1271
  *
1010
- * // Multi-sig convenience
1011
- * const signed = tx.signAll([keypair1, keypair2, keypair3]);
1012
- * ```
1272
+ * Handles all read-only operations like getting balances, account info, etc.
1013
1273
  */
1014
- declare class Transaction {
1015
- /** The unsigned message */
1016
- private readonly message;
1017
- /** Signatures (64 bytes each), aligned with message.header.numRequiredSignatures */
1018
- private readonly signatures;
1019
- private constructor();
1274
+ declare class QueryRpcClient extends BaseRpcClient {
1020
1275
  /**
1021
- * Create an unsigned transaction from a message.
1022
- * All signature slots are initialized to zero.
1276
+ * Retrieve the balance of an account in kelvins (smallest unit).
1023
1277
  *
1024
- * @internal - Users should use TransactionBuilder instead
1278
+ * @param pubkey - The public key of the account to query
1279
+ * @returns The account balance in kelvins
1280
+ *
1281
+ * @example
1282
+ * ```typescript
1283
+ * const balance = await client.getBalance(publicKey);
1284
+ * console.log(`Balance: ${balance} kelvins`);
1285
+ * ```
1025
1286
  */
1026
- static fromMessage(message: Message): Transaction;
1287
+ getBalance(pubkey: PublicKey): Promise<bigint>;
1027
1288
  /**
1028
- * Create transaction from message and existing signatures.
1029
- * @internal
1289
+ * Retrieve detailed information about an account.
1290
+ *
1291
+ * Returns account data including balance, owner program, stored data,
1292
+ * executable status, and rent epoch.
1293
+ *
1294
+ * @param pubkey - The public key of the account to query
1295
+ * @returns Account information, or null if the account does not exist
1296
+ *
1297
+ * @example
1298
+ * ```typescript
1299
+ * const info = await client.getAccountInfo(publicKey);
1300
+ * if (info) {
1301
+ * console.log(`Owner: ${info.owner}`);
1302
+ * console.log(`Balance: ${info.balance} kelvins`);
1303
+ * console.log(`Data length: ${info.data.length} bytes`);
1304
+ * }
1305
+ * ```
1030
1306
  */
1031
- static fromMessageAndSignatures(message: Message, signatures: readonly Uint8Array[]): Transaction;
1307
+ getAccountInfo(pubkey: PublicKey): Promise<AccountInfo | null>;
1032
1308
  /**
1033
- * Deserialize a transaction from wire format.
1309
+ * Retrieve the current block height of the blockchain.
1310
+ *
1311
+ * The block height represents the number of blocks that have been
1312
+ * confirmed on the chain since genesis.
1313
+ *
1314
+ * @returns The current block height
1315
+ *
1316
+ * @example
1317
+ * ```typescript
1318
+ * const height = await client.getBlockHeight();
1319
+ * console.log(`Current block height: ${height}`);
1320
+ * ```
1321
+ */
1322
+ getBlockHeight(): Promise<bigint>;
1323
+ /**
1324
+ * Retrieve transaction signatures for a given address.
1325
+ *
1326
+ * Returns transaction signatures with metadata associated with the specified
1327
+ * address, ordered by slot height (most recent first).
1328
+ *
1329
+ * @param address - The public key of the address to query
1330
+ * @param config - Optional configuration options for the query (limit, before, until)
1331
+ * @returns Response containing context and array of signature info with blockHeight and blockTime
1332
+ *
1333
+ * @example
1334
+ * ```typescript
1335
+ * const result = await client.getSignaturesForAddress(publicKey, { limit: 10 });
1336
+ * console.log(`Query slot: ${result.context.slot}`);
1337
+ * result.value.forEach(sig => {
1338
+ * console.log(`Transaction: ${sig.signature}, block: ${sig.blockHeight}`);
1339
+ * });
1340
+ * ```
1341
+ */
1342
+ getSignaturesForAddress(address: PublicKey, config?: GetSignaturesForAddressConfig): Promise<SignatureInfo[]>;
1343
+ /**
1344
+ * Retrieve detailed information about a confirmed transaction.
1345
+ *
1346
+ * Returns transaction metadata including the block height it was
1347
+ * confirmed in and any execution errors.
1348
+ *
1349
+ * @param signature - The transaction signature to query
1350
+ * @returns Transaction information, or null if the transaction is not found
1351
+ *
1352
+ * @example
1353
+ * ```typescript
1354
+ * const tx = await client.getTransaction(signature);
1355
+ * if (tx) {
1356
+ * console.log(`Confirmed in block: ${tx.blockHeight}`);
1357
+ * if (tx.err) {
1358
+ * console.log(`Transaction failed: ${tx.err}`);
1359
+ * }
1360
+ * }
1361
+ * ```
1034
1362
  */
1035
- static deserialize(data: Uint8Array): Transaction;
1036
- getMessage(): Message;
1363
+ getTransaction(signature: string): Promise<TransactionResponse | null>;
1037
1364
  /**
1038
- * Sign the transaction with a keypair.
1039
- * Returns a NEW Transaction instance.
1365
+ * Retrieve the total number of transactions processed since genesis.
1040
1366
  *
1041
- * @param keypair - Keypair to sign with
1042
- * @returns New Transaction instance with signature added
1367
+ * @returns The total transaction count
1043
1368
  *
1044
1369
  * @example
1045
1370
  * ```typescript
1046
- * const signedTx = tx.sign(keypair);
1047
- * await client.sendTransaction(signedTx.serialize());
1371
+ * const count = await client.getTransactionCount();
1372
+ * console.log(`Total transactions: ${count}`);
1048
1373
  * ```
1049
1374
  */
1050
- sign(keypair: Keypair): Transaction;
1375
+ getTransactionCount(): Promise<bigint>;
1051
1376
  /**
1052
- * Sign with multiple keypairs at once.
1053
- * Returns a NEW Transaction instance.
1377
+ * Retrieve the status of multiple transaction signatures in a single request.
1378
+ *
1379
+ * Useful for batch-checking transaction confirmations. Returns null for
1380
+ * signatures that are not found or have expired from the status cache.
1381
+ *
1382
+ * @param signatures - Array of transaction signatures to query
1383
+ * @returns Array of signature statuses (null if signature not found)
1054
1384
  *
1055
1385
  * @example
1056
1386
  * ```typescript
1057
- * const signed = tx.signAll([keypair1, keypair2, keypair3]);
1387
+ * const statuses = await client.getSignatureStatuses([sig1, sig2, sig3]);
1388
+ * statuses.forEach((status, i) => {
1389
+ * if (status) {
1390
+ * console.log(`${signatures[i]}: slot ${status.slot}, executed: ${status.executed}`);
1391
+ * } else {
1392
+ * console.log(`${signatures[i]}: not found`);
1393
+ * }
1394
+ * });
1058
1395
  * ```
1059
1396
  */
1060
- signAll(keypairs: Keypair[]): Transaction;
1397
+ getSignatureStatuses(signatures: string[]): Promise<(SignatureStatus | null)[]>;
1061
1398
  /**
1062
- * Sign the transaction with a Signer interface (async).
1063
- * Returns a NEW Transaction instance.
1399
+ * Retrieve information about the current epoch.
1400
+ *
1401
+ * Returns epoch metadata including the current epoch number, slot position
1402
+ * within the epoch, total slots per epoch, and current block height.
1403
+ *
1404
+ * @returns Current epoch information
1064
1405
  *
1065
1406
  * @example
1066
1407
  * ```typescript
1067
- * const signedTx = await tx.signWith(browserWallet);
1408
+ * const info = await client.getEpochInfo();
1409
+ * console.log(`Epoch: ${info.epoch}`);
1410
+ * console.log(`Slot ${info.slotIndex} of ${info.slotsInEpoch}`);
1411
+ * console.log(`Block height: ${info.blockHeight}`);
1068
1412
  * ```
1069
1413
  */
1070
- signWith(signer: Signer): Promise<Transaction>;
1414
+ getEpochInfo(): Promise<EpochInfoResponse>;
1071
1415
  /**
1072
- * Sign with multiple signers.
1073
- * Returns a NEW Transaction instance.
1416
+ * Check the health status of the RPC node.
1417
+ *
1418
+ * Returns "ok" if the node is healthy. If the node is unhealthy,
1419
+ * returns an error message describing the issue.
1420
+ *
1421
+ * @returns "ok" if healthy, otherwise an error message
1422
+ *
1423
+ * @example
1424
+ * ```typescript
1425
+ * const health = await client.getHealth();
1426
+ * if (health === "ok") {
1427
+ * console.log("Node is healthy");
1428
+ * } else {
1429
+ * console.log(`Node unhealthy: ${health}`);
1430
+ * }
1431
+ * ```
1074
1432
  */
1075
- signAllWith(signers: Signer[]): Promise<Transaction>;
1433
+ getHealth(): Promise<"ok" | string>;
1076
1434
  /**
1077
- * Partially sign the transaction (for multi-sig transactions).
1078
- * Returns a NEW Transaction instance.
1435
+ * Calculate the minimum balance required for an account to be rent-exempt.
1436
+ *
1437
+ * Accounts with at least this balance are exempt from paying rent.
1438
+ *
1439
+ * @param accountDataSize - The size of the account data in bytes
1440
+ * @returns The minimum balance in kelvins required for rent exemption
1079
1441
  *
1080
1442
  * @example
1081
1443
  * ```typescript
1082
- * const signedTx = tx
1083
- * .partialSign(signer1)
1084
- * .partialSign(signer2);
1444
+ * const minBalance = await client.getMinimumBalanceForRentExemption(128);
1445
+ * console.log(`Need at least ${minBalance} kelvins for 128 bytes`);
1085
1446
  * ```
1086
1447
  */
1087
- partialSign(keypair: Keypair): Transaction;
1448
+ getMinimumBalanceForRentExemption(accountDataSize: number): Promise<bigint>;
1088
1449
  /**
1089
- * Partially sign with a Signer interface (async).
1090
- * Returns a NEW Transaction instance.
1450
+ * Get the fee required to process a specific message.
1451
+ *
1452
+ * @param message - Base64-encoded serialized versioned message
1453
+ * @returns Fee in kelvins, or null if message is invalid
1454
+ *
1455
+ * @example
1456
+ * ```typescript
1457
+ * const fee = await client.getFeeForMessage(base64Message);
1458
+ * if (fee !== null) {
1459
+ * console.log(`Fee: ${fee} kelvins`);
1460
+ * }
1461
+ * ```
1091
1462
  */
1092
- partialSignWith(signer: Signer): Promise<Transaction>;
1463
+ getFeeForMessage(message: string): Promise<bigint | null>;
1093
1464
  /**
1094
- * Add a signature at a specific index.
1095
- * Returns a NEW Transaction instance.
1465
+ * Get information for multiple accounts in a single request.
1096
1466
  *
1097
- * Most users should use sign() or signAll() instead.
1467
+ * Useful for batch operations and reducing RPC calls.
1468
+ *
1469
+ * @param pubkeys - Array of public keys to query (1-100)
1470
+ * @returns Account information for each address (null for non-existent accounts)
1471
+ *
1472
+ * @example
1473
+ * ```typescript
1474
+ * const accounts = await client.getMultipleAccounts([pubkey1, pubkey2]);
1475
+ * accounts.value.forEach((account, i) => {
1476
+ * if (account) {
1477
+ * console.log(`Account ${i}: ${account.balance} kelvins`);
1478
+ * }
1479
+ * });
1480
+ * ```
1098
1481
  */
1099
- addSignature(index: number, signature: Signature | Uint8Array): Transaction;
1482
+ getMultipleAccounts(pubkeys: PublicKey[]): Promise<Array<AccountInfo | null>>;
1100
1483
  /**
1101
- * Add a signature for a specific public key.
1102
- * Returns a NEW Transaction instance.
1484
+ * Get all accounts owned by a specific program or address.
1103
1485
  *
1104
- * Most users should use sign() or signAll() instead.
1486
+ * Essential for querying token accounts, program data, and more.
1487
+ *
1488
+ * @param owner - Program ID or owner public key
1489
+ * @param filter - Filter type (ProgramAccounts or TokenAccounts)
1490
+ * @param config - Optional configuration for pagination and encoding
1491
+ * @returns Accounts owned by the specified owner with pagination info
1492
+ *
1493
+ * @example
1494
+ * ```typescript
1495
+ * const result = await client.getAccountsByOwner(programId);
1496
+ * console.log(`Found ${result.value.length} accounts`);
1497
+ * result.value.forEach(({ pubkey, account }) => {
1498
+ * console.log(`${pubkey}: ${account.balance} kelvins`);
1499
+ * });
1500
+ * ```
1105
1501
  */
1106
- addSignatureForPubkey(pubkey: PublicKey, signature: Signature | Uint8Array): Transaction;
1502
+ getAccountsByOwner(owner: PublicKey, filter?: AccountFilter, config?: GetAccountsByOwnerConfig): Promise<GetAccountsByOwnerResponse>;
1107
1503
  /**
1108
- * Check if transaction is fully signed (all signatures present).
1504
+ * Get workflow lineage information for tracking execution history.
1505
+ *
1506
+ * Returns the tree of transactions spawned from a root transaction
1507
+ * through subscriptions and triggers.
1508
+ *
1509
+ * @param request - Workflow lineage request with signature and options
1510
+ * @returns Workflow lineage tree with nodes and metadata
1511
+ *
1512
+ * @example
1513
+ * ```typescript
1514
+ * const lineage = await client.getWorkflowLineage({
1515
+ * signature: rootTxSignature,
1516
+ * maxDepth: 5,
1517
+ * });
1518
+ * console.log(`Found ${lineage.lineage.workflowNodes.length} nodes`);
1519
+ * ```
1109
1520
  */
1110
- isSigned(): boolean;
1521
+ getWorkflowLineage(request: GetWorkflowLineageRequest): Promise<GetWorkflowLineageResponse>;
1111
1522
  /**
1112
- * Check if a specific signature slot is filled.
1523
+ * Get subscriptions for a given subscriber address.
1524
+ *
1525
+ * Returns subscriptions that will trigger transactions when matching events occur.
1526
+ *
1527
+ * @param subscriber - The subscriber's public key
1528
+ * @param nonce - The nonce identifying the subscription
1529
+ * @returns The subscription for the subscriber and nonce
1530
+ *
1531
+ * @example
1532
+ * ```typescript
1533
+ * const subscription = await client.getSubscription(subscriberPubkey, "my-nonce");
1534
+ * console.log(`Topic: ${subscription.topic}, Kind: ${subscription.kind}`);
1535
+ * ```
1113
1536
  */
1114
- isSignaturePresent(index: number): boolean;
1537
+ getSubscription(subscriber: PublicKey, nonce: string): Promise<Subscription>;
1115
1538
  /**
1116
- * Get all signatures (returns copies to prevent mutation).
1539
+ * Get transactions triggered by a subscription account.
1540
+ *
1541
+ * Returns the history of transactions that were automatically executed
1542
+ * in response to subscription matches.
1543
+ *
1544
+ * @param subscriptionAccount - The subscription account public key
1545
+ * @param limit - Optional limit on transactions returned
1546
+ * @returns Triggered transactions for the subscription
1547
+ *
1548
+ * @example
1549
+ * ```typescript
1550
+ * const result = await client.getTriggeredTransactions(subscriptionPubkey, 10);
1551
+ * result.transactions.forEach(tx => {
1552
+ * console.log(`Signature: ${tx.signature}, Block: ${tx.blockNumber}`);
1553
+ * });
1554
+ * ```
1117
1555
  */
1118
- getSignatures(): readonly Uint8Array[];
1556
+ getTriggeredTransactions(subscriptionAccount: PublicKey, limit?: number): Promise<TriggeredTransaction[]>;
1557
+ }
1558
+
1559
+ /**
1560
+ * Query client for read-only RPC operations.
1561
+ */
1562
+
1563
+ /**
1564
+ * Client for sending/simulating transactions and requesting airdrops.
1565
+ *
1566
+ * Handles all transaction operations like sending transactions, requesting airdrops, etc.
1567
+ */
1568
+ declare class TransactionRpcClient extends BaseRpcClient {
1119
1569
  /**
1120
- * Get a specific signature (returns copy).
1570
+ * Submit a signed transaction to the blockchain.
1571
+ *
1572
+ * Sends the transaction to the network for processing. The transaction
1573
+ * must be fully signed before submission. Returns immediately with the
1574
+ * transaction signature - use {@link confirmTransaction} or
1575
+ * {@link sendAndConfirmTransaction} to wait for confirmation.
1576
+ *
1577
+ * @param transaction - Serialized signed transaction bytes
1578
+ * @param options - Transaction submission options
1579
+ * @returns Transaction signature (base58 encoded)
1580
+ *
1581
+ * @example
1582
+ * ```typescript
1583
+ * const signature = await client.sendTransaction(signedTx);
1584
+ * console.log(`Submitted: ${signature}`);
1585
+ *
1586
+ * // With options
1587
+ * const signature = await client.sendTransaction(signedTx, {
1588
+ * skipPreflight: true,
1589
+ * maxRetries: 3,
1590
+ * });
1591
+ * ```
1121
1592
  */
1122
- getSignature(index: number): Uint8Array;
1593
+ sendTransaction(transaction: Uint8Array, options?: SendTransactionOptions): Promise<string>;
1123
1594
  /**
1124
- * Get a specific signature for a public key.
1595
+ * Wait for a transaction to be confirmed.
1596
+ *
1597
+ * A transaction is considered confirmed when:
1598
+ * - It has been processed in a block (`blockHeight > 0`)
1599
+ *
1600
+ * @param signature - Transaction signature to monitor
1601
+ * @param options - Confirmation options
1602
+ * @returns Confirmed transaction details
1603
+ * @throws {TransactionFailedError} If the transaction fails on-chain
1604
+ * @throws {TransactionConfirmationTimeoutError} If confirmation times out
1125
1605
  */
1126
- getSignatureForPubkey(pubkey: PublicKey): Uint8Array;
1606
+ confirmTransaction(signature: string, options?: ConfirmTransactionOptions): Promise<ConfirmedTransaction>;
1127
1607
  /**
1128
- * Get required signers for this transaction.
1608
+ * Submit a signed transaction and wait for confirmation.
1609
+ *
1610
+ * Polls the transaction status until it is confirmed (blockHeight > 0),
1611
+ * or until the maximum number of retries is reached.
1612
+ *
1613
+ * @param transaction - Serialized signed transaction bytes
1614
+ * @param options - Transaction submission and confirmation options
1615
+ * @returns Confirmed transaction details
1616
+ * @throws {TransactionFailedError} If the transaction fails on-chain
1617
+ * @throws {TransactionConfirmationTimeoutError} If confirmation times out
1618
+ *
1619
+ * @example
1620
+ * ```typescript
1621
+ * const result = await client.sendAndConfirmTransaction(signedTx);
1622
+ * console.log(`Confirmed in block ${result.blockHeight}, executed: ${result.executed}`);
1623
+ *
1624
+ * // With custom retry settings
1625
+ * const result = await client.sendAndConfirmTransaction(signedTx, {
1626
+ * maxRetries: 3,
1627
+ * retryDelay: 500,
1628
+ * });
1629
+ * ```
1129
1630
  */
1130
- getSigners(): readonly PublicKey[];
1631
+ sendAndConfirmTransaction(transaction: Uint8Array, options?: SendAndConfirmOptions): Promise<ConfirmedTransaction>;
1131
1632
  /**
1132
- * Get the number of required signatures.
1633
+ * Request an airdrop of tokens to an account.
1634
+ *
1635
+ * **Note**: Only available on devnet and testnet networks.
1636
+ *
1637
+ * Returns immediately with the airdrop transaction signature.
1638
+ * Use {@link requestAirdropAndConfirm} to wait for the airdrop to complete.
1639
+ *
1640
+ * @param pubkey - The public key of the account to receive tokens
1641
+ * @param amount - Amount to airdrop in kelvins (smallest unit)
1642
+ * @returns Airdrop transaction signature
1643
+ *
1644
+ * @example
1645
+ * ```typescript
1646
+ * const signature = await client.requestAirdrop(publicKey, 1_000_000_000n);
1647
+ * console.log(`Airdrop requested: ${signature}`);
1648
+ * ```
1133
1649
  */
1134
- getRequiredSignatureCount(): number;
1650
+ requestAirdrop(pubkey: PublicKey, amount: bigint): Promise<string>;
1135
1651
  /**
1136
- * Throw an error if the transaction is not fully signed.
1652
+ * Request an airdrop of tokens and wait for confirmation.
1137
1653
  *
1138
- * @throws {TransactionError} If transaction is not fully signed
1654
+ * **Note**: Only available on devnet and testnet networks.
1655
+ *
1656
+ * Combines {@link requestAirdrop} and {@link confirmTransaction} into
1657
+ * a single call for convenience.
1658
+ *
1659
+ * @param pubkey - The public key of the account to receive tokens
1660
+ * @param amount - Amount to airdrop in kelvins (smallest unit)
1661
+ * @param options - Confirmation options (max retries, retry delay)
1662
+ * @returns Confirmed transaction details
1663
+ * @throws {RpcError} If the airdrop transaction fails or confirmation times out
1139
1664
  *
1140
1665
  * @example
1141
1666
  * ```typescript
1142
- * signedTx.ensureSigned(); // Throws if not signed
1143
- * await client.sendTransaction(signedTx.serialize());
1667
+ * const result = await client.requestAirdropAndConfirm(publicKey, 1_000_000_000n);
1668
+ * if (result.executed) {
1669
+ * console.log("Airdrop confirmed!");
1670
+ * }
1144
1671
  * ```
1145
1672
  */
1146
- ensureSigned(): void;
1673
+ requestAirdropAndConfirm(pubkey: PublicKey, amount: bigint, options?: ConfirmTransactionOptions): Promise<ConfirmedTransaction>;
1674
+ private getTransaction;
1147
1675
  /**
1148
- * Serialize transaction to wire format.
1676
+ * Sleeps for a given number of milliseconds.
1677
+ * @param ms - The number of milliseconds to sleep.
1678
+ * @returns A promise that resolves when the sleep is complete.
1149
1679
  */
1150
- serialize(): Uint8Array;
1680
+ private sleep;
1151
1681
  }
1152
1682
 
1153
1683
  /**
1154
- * Fluent API for building transactions.
1155
- * Returns Transaction directly (not Message).
1684
+ * Error codes for RPC operations, categorized by type.
1685
+ */
1686
+ declare enum RpcErrorCode {
1687
+ REQUEST_TIMEOUT = "REQUEST_TIMEOUT",
1688
+ NETWORK_ERROR = "NETWORK_ERROR",
1689
+ CONNECTION_REFUSED = "CONNECTION_REFUSED",
1690
+ INVALID_NETWORK = "INVALID_NETWORK",
1691
+ INVALID_RESPONSE = "INVALID_RESPONSE",
1692
+ PARSE_ERROR = "PARSE_ERROR",
1693
+ INVALID_REQUEST = "INVALID_REQUEST",
1694
+ METHOD_NOT_FOUND = "METHOD_NOT_FOUND",
1695
+ INVALID_PARAMS = "INVALID_PARAMS",
1696
+ INTERNAL_ERROR = "INTERNAL_ERROR",
1697
+ TRANSACTION_REJECTED = "TRANSACTION_REJECTED",
1698
+ INSUFFICIENT_FUNDS = "INSUFFICIENT_FUNDS",
1699
+ TRANSACTION_CONFIRMATION_TIMEOUT = "TRANSACTION_CONFIRMATION_TIMEOUT",
1700
+ ACCOUNT_NOT_FOUND = "ACCOUNT_NOT_FOUND",
1701
+ RATE_LIMIT_EXCEEDED = "RATE_LIMIT_EXCEEDED",
1702
+ NODE_UNHEALTHY = "NODE_UNHEALTHY"
1703
+ }
1704
+ /**
1705
+ * Detailed error context for debugging and error handling.
1706
+ */
1707
+ interface RpcErrorDetails {
1708
+ method?: string;
1709
+ params?: unknown;
1710
+ requestId?: number;
1711
+ url?: string;
1712
+ httpStatus?: number;
1713
+ rpcCode?: number;
1714
+ timeout?: number;
1715
+ attempts?: number;
1716
+ [key: string]: unknown;
1717
+ }
1718
+ /**
1719
+ * Error class for RPC operations with structured error information.
1720
+ *
1721
+ * Provides actionable error messages and indicates whether errors are retryable.
1156
1722
  */
1723
+ declare class RpcError extends Error {
1724
+ readonly code: RpcErrorCode;
1725
+ readonly details: RpcErrorDetails;
1726
+ readonly retryable: boolean;
1727
+ constructor(code: RpcErrorCode, message: string, details?: RpcErrorDetails, retryable?: boolean);
1728
+ static requestTimeout(timeoutMs: number, details: RpcErrorDetails): RpcError;
1729
+ static networkError(message: string, details: RpcErrorDetails): RpcError;
1730
+ static invalidResponse(details: RpcErrorDetails): RpcError;
1731
+ static accountNotFound(pubkey: string): RpcError;
1732
+ static rateLimitExceeded(details: RpcErrorDetails): RpcError;
1733
+ static fromRpcCode(rpcCode: number, message: string, details: RpcErrorDetails): RpcError;
1734
+ toJSON(): {
1735
+ code: RpcErrorCode;
1736
+ message: string;
1737
+ details?: Record<string, unknown>;
1738
+ retryable: boolean;
1739
+ };
1740
+ }
1157
1741
 
1158
1742
  /**
1159
- * Builder for creating transactions with a fluent API.
1743
+ * Creates an RPC client with automatic retry and timeout handling.
1160
1744
  *
1161
- * Provides an intuitive interface for constructing transactions.
1162
- * Call build() to get an unsigned Transaction ready for signing.
1745
+ * @param config - Client configuration with chain definition and optional transport settings
1746
+ * @param config.chain - Chain definition (e.g., RIALO_DEVNET_CHAIN, RIALO_MAINNET_CHAIN) or a custom chain with your own rpcUrl
1747
+ * @param config.transport - Optional transport configuration (timeout, retries, headers)
1748
+ * @returns Configured RialoClient instance
1163
1749
  *
1164
1750
  * @example
1165
1751
  * ```typescript
1166
- * // Simple transfer
1167
- * const tx = TransactionBuilder.create()
1168
- * .setPayer(payer)
1169
- * .setValidFrom(validFrom)
1170
- * .addInstruction(transfer(from, to, 1_000_000n))
1171
- * .build();
1752
+ * // Basic usage with preset chain
1753
+ * const client = createRialoClient({ chain: RIALO_DEVNET_CHAIN });
1172
1754
  *
1173
- * const signedTx = tx.sign(keypair);
1174
- * await client.transaction.sendTransaction(signedTx.serialize());
1755
+ * // With custom transport config
1756
+ * const client = createRialoClient({
1757
+ * chain: RIALO_MAINNET_CHAIN,
1758
+ * transport: { timeout: 30000, maxRetries: 5 }
1759
+ * });
1760
+ *
1761
+ * // With custom RPC URL
1762
+ * const client = createRialoClient({
1763
+ * chain: {
1764
+ * id: 'rialo:mainnet',
1765
+ * name: 'Mainnet',
1766
+ * rpcUrl: 'https://mainnet.custom-rpc.com:4101'
1767
+ * },
1768
+ * });
1175
1769
  * ```
1770
+ */
1771
+ declare function createRialoClient(config: RialoClientConfig): RialoClient;
1772
+ /**
1773
+ * Returns a default RialoClientConfig for a given network.
1774
+ *
1775
+ * Provides preset chain configurations for standard Rialo networks, making it easy
1776
+ * to connect to mainnet, devnet, testnet, or localnet without manual configuration.
1777
+ *
1778
+ * @param network - Network identifier: "mainnet", "devnet", "testnet", or "localnet"
1779
+ * @returns Default RialoClientConfig for the specified network
1780
+ * @throws {RpcError} With code INVALID_NETWORK if an unknown network is provided
1176
1781
  *
1177
1782
  * @example
1178
1783
  * ```typescript
1179
- * // Multi-instruction transaction
1180
- * const tx = TransactionBuilder.create()
1181
- * .setPayer(payer)
1182
- * .setValidFrom(validFrom)
1183
- * .addInstruction(transfer(from, to, 1_000_000n))
1184
- * .addInstruction(memoInstruction("Payment for invoice #123"))
1185
- * .build();
1784
+ * // Get devnet config and create client
1785
+ * const config = getDefaultRialoClientConfig('devnet');
1786
+ * const client = createRialoClient(config);
1787
+ *
1788
+ * // Customize the config with transport options
1789
+ * const config = getDefaultRialoClientConfig('mainnet');
1790
+ * const client = createRialoClient({
1791
+ * ...config,
1792
+ * transport: { timeout: 60000, maxRetries: 5 }
1793
+ * });
1794
+ *
1795
+ * // Use custom RPC URL while preserving network identity
1796
+ * const config = getDefaultRialoClientConfig('mainnet');
1797
+ * const client = createRialoClient({
1798
+ * ...config,
1799
+ * chain: {
1800
+ * ...config.chain,
1801
+ * rpcUrl: 'https://mainnet.custom-rpc.com:4101'
1802
+ * },
1803
+ * });
1186
1804
  * ```
1187
1805
  */
1188
- declare class TransactionBuilder {
1189
- private payer?;
1190
- private validFrom?;
1191
- private readonly instructions;
1192
- private constructor();
1193
- /**
1194
- * Create a new transaction builder.
1195
- */
1196
- static create(): TransactionBuilder;
1197
- /**
1198
- * Set the fee payer for this transaction.
1199
- *
1200
- * The payer will be the first account and must sign the transaction.
1201
- * The payer pays for transaction fees.
1202
- *
1203
- * @param payer - Public key of the fee payer
1204
- */
1205
- setPayer(payer: PublicKey): this;
1206
- /**
1207
- * Set the Transaction valid from.
1208
- *
1209
- * This is the time the transaction is valid from, in milliseconds since Unix epoch.
1210
- * It can be used for additional replay protection or auditing.
1211
- *
1212
- * @param validFrom - Transaction valid from in milliseconds since Unix epoch
1213
- */
1214
- setValidFrom(validFrom: bigint): this;
1215
- /**
1216
- * Add an instruction to the transaction.
1217
- *
1218
- * @param instruction - Instruction to add
1219
- */
1220
- addInstruction(instruction: Instruction): this;
1806
+ declare function getDefaultRialoClientConfig(network: RialoNetwork): RialoClientConfig;
1807
+
1808
+ /**
1809
+ * Interface for signing messages and transactions.
1810
+ *
1811
+ * Enables multiple signing strategies:
1812
+ * - **KeypairSigner**: Local keypair signing
1813
+ * - **Browser Wallet**: Browser extension integration
1814
+ * - **Hardware Wallet**: Ledger, Trezor, etc.
1815
+ * - **Remote Signer**: API-based signing services
1816
+ *
1817
+ * @example
1818
+ * ```typescript
1819
+ * // Browser wallet implementation
1820
+ * class BrowserWalletSigner implements Signer {
1821
+ * async getPublicKey(): Promise<PublicKey> {
1822
+ * const pubkey = await window.rialoWallet.getPublicKey();
1823
+ * return PublicKey.fromString(pubkey);
1824
+ * }
1825
+ *
1826
+ * async signMessage(message: Uint8Array): Promise<Signature> {
1827
+ * const sig = await window.rialoWallet.signMessage(message);
1828
+ * return Signature.fromBytes(sig);
1829
+ * }
1830
+ * }
1831
+ *
1832
+ * // Usage
1833
+ * const signer = new BrowserWalletSigner();
1834
+ * const publicKey = await signer.getPublicKey();
1835
+ * const signature = await signer.signMessage(message);
1836
+ * ```
1837
+ */
1838
+ interface Signer {
1221
1839
  /**
1222
- * Add multiple instructions at once.
1840
+ * Retrieves the signer's public key.
1223
1841
  *
1224
- * @param instructions - Array of instructions to add
1842
+ * **Note**: May trigger wallet connection prompts for browser wallets.
1225
1843
  */
1226
- addInstructions(instructions: readonly Instruction[]): this;
1844
+ getPublicKey(): Promise<PublicKey>;
1227
1845
  /**
1228
- * Build the transaction (unsigned).
1229
- *
1230
- * Returns an unsigned Transaction that's ready to be signed.
1231
- *
1232
- * @returns Unsigned Transaction
1233
- * @throws {TransactionError} If payer, valid_from, or instructions are missing
1846
+ * Signs arbitrary message bytes.
1234
1847
  *
1235
- * @example
1236
- * ```typescript
1237
- * const tx = builder.build();
1238
- * const signedTx = tx.sign(keypair);
1239
- * ```
1848
+ * @param message - Message bytes to sign
1849
+ * @returns Ed25519 signature over the message
1240
1850
  */
1241
- build(): Transaction;
1851
+ signMessage(message: Uint8Array): Promise<Signature>;
1242
1852
  }
1243
1853
 
1244
1854
  /**
1245
- * Base client with JSON-RPC protocol handling.
1855
+ * Signer implementation using a local Ed25519 keypair.
1246
1856
  *
1247
- * All specific clients (QueryClient, TransactionClient) extend this.
1248
- */
1249
- declare class BaseRpcClient {
1250
- protected readonly transport: HttpTransport;
1251
- private requestId;
1252
- constructor(transport: HttpTransport);
1253
- /**
1254
- * Makes a JSON-RPC 2.0 method call with type safety.
1255
- *
1256
- * Handles request serialization, response validation, and error mapping.
1257
- */
1258
- protected call<T>(method: string, params?: unknown[]): Promise<T>;
1259
- /**
1260
- * Validate JSON-RPC response structure
1261
- */
1262
- private isValidJsonRpcResponse;
1857
+ * Provides synchronous signing without external dependencies.
1858
+ * Suitable for server-side applications, CLIs, and testing.
1859
+ *
1860
+ * @example
1861
+ * ```typescript
1862
+ * import { Keypair, KeypairSigner } from '@rialo/ts-cdk';
1863
+ *
1864
+ * // Generate new keypair
1865
+ * const keypair = Keypair.generate();
1866
+ * const signer = new KeypairSigner(keypair);
1867
+ *
1868
+ * // Or from mnemonic
1869
+ * const mnemonic = Mnemonic.generate();
1870
+ * const keypair = await mnemonic.toKeypair(0);
1871
+ * const signer = new KeypairSigner(keypair);
1872
+ *
1873
+ * // Sign messages
1874
+ * const publicKey = await signer.getPublicKey();
1875
+ * const signature = await signer.signMessage(message);
1876
+ * ```
1877
+ */
1878
+ declare class KeypairSigner implements Signer {
1879
+ private readonly keypair;
1880
+ constructor(keypair: Keypair);
1263
1881
  /**
1264
- * Generates the next request ID with Overflow Protection.
1265
- * @returns The next request ID.
1882
+ * Returns the keypair's public key.
1266
1883
  */
1267
- private nextRequestId;
1884
+ getPublicKey(): Promise<PublicKey>;
1268
1885
  /**
1269
- * Returns the configured RPC endpoint URL.
1886
+ * Signs a message using the keypair's private key.
1270
1887
  */
1271
- getUrl(): string;
1888
+ signMessage(message: Uint8Array): Promise<Signature>;
1272
1889
  }
1273
1890
 
1274
1891
  /**
1275
- * RPC type definitions for the Rialo blockchain.
1276
- */
1277
-
1278
- /**
1279
- * Account information response.
1280
- */
1281
- interface AccountInfo {
1282
- /** Account balance in smallest denomination */
1283
- balance: bigint;
1284
- /** Owner program public key */
1285
- owner: PublicKey;
1286
- /** Account data */
1287
- data: Uint8Array;
1288
- /** Whether the account is executable */
1289
- executable: boolean;
1290
- /** Rent epoch */
1291
- rentEpoch: bigint;
1292
- }
1293
- /**
1294
- * Transaction response.
1295
- */
1296
- interface TransactionResponse {
1297
- /** Transaction signature */
1298
- signature: string;
1299
- /** Block height */
1300
- blockHeight?: bigint;
1301
- /** Error message if transaction failed */
1302
- err?: string;
1303
- }
1304
- /**
1305
- * Options for sending a transaction.
1306
- */
1307
- interface SendTransactionOptions {
1308
- /** Skip preflight transaction checks */
1309
- skipPreflight?: boolean;
1310
- /** Maximum number of times to retry */
1311
- maxRetries?: number;
1312
- }
1313
- /**
1314
- * Epoch information response.
1892
+ * Metadata about an account in a transaction.
1315
1893
  */
1316
- interface EpochInfoResponse {
1317
- /** Current epoch */
1318
- epoch: bigint;
1319
- /** Current slot in the epoch */
1320
- slotIndex: bigint;
1321
- /** Total slots in the epoch */
1322
- slotsInEpoch: bigint;
1323
- /** Absolute slot number */
1324
- absoluteSlot: bigint;
1325
- /** Block height */
1326
- blockHeight: bigint;
1327
- /** Transaction count */
1328
- transactionCount?: bigint;
1894
+ interface AccountMeta {
1895
+ /** Account public key */
1896
+ readonly pubkey: PublicKey;
1897
+ /** Whether this account must sign the transaction */
1898
+ readonly isSigner: boolean;
1899
+ /** Whether this account's data will be modified */
1900
+ readonly isWritable: boolean;
1329
1901
  }
1330
1902
  /**
1331
- * Fee for message response.
1903
+ * An instruction to execute on-chain.
1332
1904
  */
1333
- interface GetFeeForMessageResponse {
1334
- /** Fee in smallest denomination */
1335
- value: bigint;
1905
+ interface Instruction {
1906
+ /** Program that will execute this instruction */
1907
+ readonly programId: PublicKey;
1908
+ /** Accounts used by this instruction */
1909
+ readonly accounts: readonly AccountMeta[];
1910
+ /** Instruction-specific data */
1911
+ readonly data: Uint8Array;
1336
1912
  }
1337
1913
  /**
1338
- * Multiple accounts response.
1914
+ * Message header containing signature requirements.
1339
1915
  */
1340
- interface MultipleAccountsResponse {
1341
- /** Array of account information */
1342
- value: Array<AccountInfo | null>;
1916
+ interface MessageHeader {
1917
+ /** Number of signatures required */
1918
+ readonly numRequiredSignatures: number;
1919
+ /** Number of read-only signed accounts */
1920
+ readonly numReadonlySignedAccounts: number;
1921
+ /** Number of read-only unsigned accounts */
1922
+ readonly numReadonlyUnsignedAccounts: number;
1343
1923
  }
1344
1924
  /**
1345
- * Get subscriptions response.
1925
+ * Compiled instruction with account indices.
1346
1926
  */
1347
- interface GetSubscriptionsResponse {
1348
- /** Array of subscription data */
1349
- subscriptions: Array<Record<string, unknown>>;
1927
+ interface CompiledInstruction {
1928
+ /** Index of program in account keys array */
1929
+ readonly programIdIndex: number;
1930
+ /** Indices of accounts in account keys array */
1931
+ readonly accountKeyIndexes: readonly number[];
1932
+ /** Instruction data */
1933
+ readonly data: Uint8Array;
1350
1934
  }
1935
+
1351
1936
  /**
1352
- * Get triggered transactions response.
1937
+ * Account metadata table for deduplication and sorting.
1938
+ * Avoids: Complex account sorting logic scattered throughout builder
1353
1939
  */
1354
- interface GetTriggeredTransactionsResponse {
1355
- /** Array of triggered transaction data */
1356
- transactions: Array<Record<string, unknown>>;
1357
- }
1940
+
1358
1941
  /**
1359
- * Get workflow lineage request.
1942
+ * Internal account entry with aggregated metadata.
1360
1943
  */
1361
- interface GetWorkflowLineageRequest {
1362
- /** Workflow account public key */
1363
- workflowAccount: PublicKey;
1364
- /** Optional limit on results */
1365
- limit?: number;
1944
+ interface AccountEntry {
1945
+ pubkey: PublicKey;
1946
+ isSigner: boolean;
1947
+ isWritable: boolean;
1366
1948
  }
1367
1949
  /**
1368
- * Get workflow lineage response.
1950
+ * Manages account deduplication and sorting for transaction messages.
1951
+ *
1952
+ * Accounts are sorted according to these rules:
1953
+ * 1. Signer + writable accounts first
1954
+ * 2. Then signer + readonly accounts
1955
+ * 3. Then non-signer + writable accounts
1956
+ * 4. Finally non-signer + readonly accounts
1957
+ * 5. Within each group, sort by public key bytes
1958
+ *
1959
+ * This matches Solana's account sorting rules for compatibility.
1369
1960
  */
1370
- interface GetWorkflowLineageResponse {
1371
- /** Workflow lineage data */
1372
- lineage: Array<Record<string, unknown>>;
1961
+ declare class AccountMetaTable {
1962
+ private readonly accounts;
1963
+ private readonly accountOrder;
1964
+ /**
1965
+ * Add or update an account in the table.
1966
+ * If account already exists, merges signer/writable flags (OR operation).
1967
+ */
1968
+ add(meta: AccountMeta): void;
1969
+ /**
1970
+ * Add multiple accounts at once.
1971
+ */
1972
+ addAll(metas: readonly AccountMeta[]): void;
1973
+ /**
1974
+ * Get the index of an account in the sorted order.
1975
+ * Returns -1 if account not found.
1976
+ */
1977
+ getIndex(pubkey: PublicKey): number;
1978
+ /**
1979
+ * Get sorted accounts according to transaction rules.
1980
+ */
1981
+ getSortedAccounts(): readonly AccountEntry[];
1982
+ /**
1983
+ * Get the message header based on sorted accounts.
1984
+ */
1985
+ getHeader(): MessageHeader;
1986
+ /**
1987
+ * Get sorted public keys.
1988
+ */
1989
+ getPublicKeys(): readonly PublicKey[];
1990
+ /**
1991
+ * Get number of accounts in table.
1992
+ */
1993
+ size(): number;
1373
1994
  }
1995
+
1374
1996
  /**
1375
- * Get signatures for address configuration.
1997
+ * Error codes for transaction operations.
1376
1998
  */
1377
- interface GetSignaturesForAddressConfig {
1378
- /** Maximum number of signatures to return */
1379
- limit?: number;
1380
- /** Start searching backwards from this signature */
1381
- before?: string;
1382
- /** Start searching forwards from this signature */
1383
- until?: string;
1999
+ declare enum TransactionErrorCode {
2000
+ INVALID_INSTRUCTION = "INVALID_INSTRUCTION",
2001
+ INVALID_ACCOUNT_META = "INVALID_ACCOUNT_META",
2002
+ NO_INSTRUCTIONS = "NO_INSTRUCTIONS",
2003
+ DUPLICATE_ACCOUNT = "DUPLICATE_ACCOUNT",
2004
+ MISSING_SIGNATURE = "MISSING_SIGNATURE",
2005
+ INVALID_SIGNATURE = "INVALID_SIGNATURE",
2006
+ SIGNATURE_OUT_OF_BOUNDS = "SIGNATURE_OUT_OF_BOUNDS",
2007
+ SIGNER_NOT_FOUND = "SIGNER_NOT_FOUND",
2008
+ ALREADY_SIGNED = "ALREADY_SIGNED",
2009
+ INVALID_MESSAGE_FORMAT = "INVALID_MESSAGE_FORMAT",
2010
+ INSUFFICIENT_DATA = "INSUFFICIENT_DATA",
2011
+ SERIALIZATION_FAILED = "SERIALIZATION_FAILED",
2012
+ SIMULATION_FAILED = "SIMULATION_FAILED",
2013
+ INSUFFICIENT_FUNDS = "INSUFFICIENT_FUNDS",
2014
+ BLOCKHASH_EXPIRED = "BLOCKHASH_EXPIRED"
1384
2015
  }
1385
2016
  /**
1386
- * Get signatures for address response.
2017
+ * Error class for transaction operations with structured error information.
1387
2018
  */
1388
- interface GetSignaturesForAddressResponse {
1389
- context: {
1390
- slot: bigint;
1391
- apiVersion: string;
2019
+ declare class TransactionError extends Error {
2020
+ readonly code: TransactionErrorCode;
2021
+ readonly details?: Record<string, unknown> | undefined;
2022
+ constructor(code: TransactionErrorCode, message: string, details?: Record<string, unknown> | undefined);
2023
+ static noInstructions(): TransactionError;
2024
+ static signerNotFound(pubkey: string): TransactionError;
2025
+ static missingSignature(index: number, pubkey: string): TransactionError;
2026
+ static simulationFailed(logs: string[], error: string): TransactionError;
2027
+ static insufficientFunds(required: bigint, available: bigint): TransactionError;
2028
+ toJSON(): {
2029
+ code: TransactionErrorCode;
2030
+ message: string;
2031
+ details?: Record<string, unknown>;
1392
2032
  };
1393
- /** Array of signature information */
1394
- value: Array<{
1395
- signature: string;
1396
- blockHeight: bigint;
1397
- blockTime: bigint;
1398
- err?: string;
1399
- }>;
1400
- }
1401
- /**
1402
- * Is blockhash valid response.
1403
- */
1404
- interface IsBlockhashValidResponse {
1405
- /** Whether the blockhash is valid */
1406
- value: boolean;
1407
- }
1408
- /**
1409
- * Get health response.
1410
- */
1411
- type GetHealthResponse = "ok" | string;
1412
- /**
1413
- * Get validator health response.
1414
- */
1415
- type GetValidatorHealthResponse = "ok" | string;
1416
- /**
1417
- * Get connected full nodes response.
1418
- */
1419
- interface GetConnectedFullNodesResponse {
1420
- /** Array of connected nodes */
1421
- nodes: Array<{
1422
- publicKey: string;
1423
- connectedTime: bigint;
1424
- }>;
1425
2033
  }
2034
+
1426
2035
  /**
1427
- * Get transactions configuration.
1428
- */
1429
- interface GetTransactionsConfig {
1430
- /** Maximum number of transactions to return */
1431
- limit?: number;
1432
- /** Encoding format */
1433
- encoding?: "json" | "base58" | "base64";
1434
- }
2036
+ * Create an instruction with Borsh-encoded data.
2037
+ *
2038
+ * @example
2039
+ * ```typescript
2040
+ * // Define your instruction data class
2041
+ * class MyInstructionData {
2042
+ * @field({ type: 'u8' })
2043
+ * instruction: number;
2044
+ *
2045
+ * @field({ type: 'u64' })
2046
+ * amount: bigint;
2047
+ *
2048
+ * @field({ type: option('string') })
2049
+ * memo?: string;
2050
+ * }
2051
+ *
2052
+ * // Create instruction
2053
+ * const instruction = createBorshInstruction({
2054
+ * programId: myProgramId,
2055
+ * accounts: [
2056
+ * { pubkey: account1, isSigner: true, isWritable: true },
2057
+ * { pubkey: account2, isSigner: false, isWritable: false },
2058
+ * ],
2059
+ * data: new MyInstructionData({
2060
+ * instruction: 5,
2061
+ * amount: 1000n,
2062
+ * memo: "Hello, Rialo!",
2063
+ * }),
2064
+ * });
2065
+ * ```
2066
+ */
2067
+ declare function createBorshInstruction<T>(params: {
2068
+ programId: PublicKey;
2069
+ accounts: AccountMeta[];
2070
+ data: T;
2071
+ }): Instruction;
1435
2072
  /**
1436
- * Get transactions response.
2073
+ * Helper for creating Borsh-serialized instruction data from a plain object.
2074
+ *
2075
+ * This is useful when you don't want to define a class with decorators.
2076
+ *
2077
+ * @example
2078
+ * ```typescript
2079
+ * const data = encodeBorshData({
2080
+ * instruction: { type: 'u8', value: 1 },
2081
+ * amount: { type: 'u64', value: 1000n },
2082
+ * recipient: { type: fixedArray('u8', 32), value: recipientBytes },
2083
+ * });
2084
+ * ```
1437
2085
  */
1438
- interface GetTransactionsResponse {
1439
- /** Array of transaction data */
1440
- transactions: Array<Record<string, unknown>>;
1441
- }
2086
+ declare function encodeBorshData(_schema: Record<string, {
2087
+ type: unknown;
2088
+ value: unknown;
2089
+ }>): Uint8Array;
2090
+
1442
2091
  /**
1443
- * Signature status from the RPC.
2092
+ * System program instruction types.
1444
2093
  */
1445
- interface SignatureStatus {
1446
- /** Slot in which the transaction was processed */
1447
- slot: bigint;
1448
- /** Whether the transaction has been executed */
1449
- executed: boolean;
1450
- /** Error message if transaction failed */
1451
- err?: string;
2094
+ declare enum SystemInstruction {
2095
+ CreateAccount = 0,
2096
+ Assign = 1,
2097
+ Transfer = 2,
2098
+ CreateAccountWithSeed = 3,
2099
+ AdvanceNonceAccount = 4,
2100
+ WithdrawNonceAccount = 5,
2101
+ InitializeNonceAccount = 6,
2102
+ AuthorizeNonceAccount = 7,
2103
+ Allocate = 8,
2104
+ AllocateWithSeed = 9,
2105
+ AssignWithSeed = 10,
2106
+ TransferWithSeed = 11
1452
2107
  }
1453
2108
  /**
1454
- * Options for confirming a transaction.
2109
+ * Create a transfer instruction.
2110
+ *
2111
+ * Transfers native tokens from one account to another.
2112
+ *
2113
+ * @param from - Source account (must be signer)
2114
+ * @param to - Destination account
2115
+ * @param amount - Amount to transfer in smallest denomination (kelvins)
2116
+ *
2117
+ * @example
2118
+ * ```typescript
2119
+ * const instruction = transferInstruction(fromPubkey, toPubkey, 1_000_000n);
2120
+ *
2121
+ * const tx = TransactionBuilder.create()
2122
+ * .setPayer(fromPubkey)
2123
+ * .addInstruction(instruction)
2124
+ * .build();
2125
+ * ```
1455
2126
  */
1456
- interface ConfirmTransactionOptions {
1457
- /** Maximum number of retry attempts (default: 30) */
1458
- maxRetries?: number;
1459
- /** Delay between retries in milliseconds (default: 1000) */
1460
- retryDelay?: number;
1461
- }
2127
+ declare function transferInstruction(from: PublicKey, to: PublicKey, amount: bigint): Instruction;
1462
2128
  /**
1463
- * Options for sending and confirming a transaction.
2129
+ * Create an account creation instruction.
2130
+ *
2131
+ * @param from - Funding account (must be signer)
2132
+ * @param newAccount - New account to create (must be signer)
2133
+ * @param kelvins - Initial balance for new account
2134
+ * @param space - Number of bytes to allocate for account data
2135
+ * @param owner - Program that will own the new account
1464
2136
  */
1465
- interface SendAndConfirmOptions extends SendTransactionOptions, ConfirmTransactionOptions {
1466
- }
2137
+ declare function createAccount(from: PublicKey, newAccount: PublicKey, kelvins: bigint, space: bigint, owner: PublicKey): Instruction;
1467
2138
  /**
1468
- * Result of a confirmed transaction.
2139
+ * Create an allocate instruction.
2140
+ *
2141
+ * Allocates space for an account's data. The account must be owned by
2142
+ * the system program and must sign the transaction.
2143
+ *
2144
+ * @param account - Account to allocate space for (must be signer)
2145
+ * @param space - Number of bytes to allocate
1469
2146
  */
1470
- interface ConfirmedTransaction {
1471
- /** Transaction signature */
1472
- signature: string;
1473
- /** Whether the transaction was executed */
1474
- executed: boolean;
1475
- /** Error message if transaction failed */
1476
- err?: string;
1477
- }
1478
-
2147
+ declare function allocateInstruction(account: PublicKey, space: bigint): Instruction;
1479
2148
  /**
1480
- * Main Rialo RPC client for blockchain interactions.
2149
+ * Create an assign instruction.
2150
+ *
2151
+ * Changes the owner of an account. The account must currently be owned
2152
+ * by the system program and must sign the transaction.
2153
+ *
2154
+ * @param account - Account to reassign (must be signer)
2155
+ * @param owner - New owner program
1481
2156
  */
2157
+ declare function assignInstruction(account: PublicKey, owner: PublicKey): Instruction;
1482
2158
 
1483
2159
  /**
1484
- * High-level Rialo RPC client for blockchain interactions.
2160
+ * An unsigned transaction message ready to be signed.
1485
2161
  *
1486
- * Provides a unified interface for querying blockchain state and
1487
- * sending transactions. Internally delegates to specialized clients
1488
- * (QueryRpcClient, TransactionRpcClient) for modular organization.
2162
+ * This is the data that gets signed by transaction signers.
2163
+ * It's immutable to prevent accidental modification after creation.
1489
2164
  *
1490
2165
  * @example
1491
2166
  * ```typescript
1492
- * import { createRialoClient, RIALO_DEVNET_CHAIN } from '@rialo/ts-cdk';
1493
- *
1494
- * const client = createRialoClient({ chain: RIALO_DEVNET_CHAIN });
1495
- *
1496
- * // Query operations
1497
- * const balance = await client.getBalance(publicKey);
1498
- * const chainId = client.getChainIdentifier();
2167
+ * const message = MessageBuilder.create()
2168
+ * .setPayer(payer)
2169
+ * .setValidFrom(validFrom)
2170
+ * .addInstruction(transferInstruction)
2171
+ * .build();
1499
2172
  *
1500
- * // Transaction operations
1501
- * const signature = await client.sendTransaction(signedTx);
2173
+ * // Serialize for signing
2174
+ * const messageBytes = message.serialize();
1502
2175
  * ```
1503
2176
  */
1504
- declare class RialoClient {
1505
- private readonly queryClient;
1506
- private readonly transactionClient;
1507
- private readonly transport;
1508
- private readonly chain;
1509
- constructor(transport: HttpTransport, chain: ChainDefinition);
1510
- /**
1511
- * Returns the configured RPC endpoint URL.
1512
- */
1513
- getUrl(): string;
1514
- /**
1515
- * Returns the chain identifier.
1516
- */
1517
- getChainIdentifier(): IdentifierString;
1518
- /**
1519
- * Returns the chain configuration.
1520
- */
1521
- getChainConfig(): ChainDefinition;
1522
- /**
1523
- * Retrieves the balance of an account in kelvins (smallest unit).
1524
- */
1525
- getBalance(pubkey: PublicKey): Promise<bigint>;
1526
- /**
1527
- * Retrieves detailed information about an account.
1528
- *
1529
- * @returns Account info or null if account doesn't exist
1530
- */
1531
- getAccountInfo(pubkey: PublicKey): Promise<AccountInfo | null>;
1532
- /**
1533
- * Retrieves the current block height.
1534
- */
1535
- getBlockHeight(): Promise<bigint>;
2177
+ declare class Message {
2178
+ /** Message header with signature requirements */
2179
+ readonly header: MessageHeader;
2180
+ /** All account public keys referenced in the transaction */
2181
+ readonly accountKeys: readonly PublicKey[];
2182
+ /** Transaction valid from (milliseconds since Unix epoch) */
2183
+ validFrom?: bigint;
2184
+ /** Compiled instructions with account indices */
2185
+ readonly instructions: readonly CompiledInstruction[];
2186
+ /** Cached serialized bytes */
2187
+ private serializedCache?;
2188
+ constructor(header: MessageHeader, accountKeys: readonly PublicKey[], validFrom: bigint, instructions: readonly CompiledInstruction[]);
1536
2189
  /**
1537
- * Retrieves the signatures for an address.
2190
+ * Serialize message to bytes for signing.
2191
+ * Result is cached for performance.
1538
2192
  */
1539
- getSignaturesForAddress(address: PublicKey, config?: GetSignaturesForAddressConfig): Promise<GetSignaturesForAddressResponse>;
2193
+ serialize(): Uint8Array;
1540
2194
  /**
1541
- * Retrieves detailed information about a transaction.
2195
+ * Deserialize a message from wire format.
1542
2196
  *
1543
- * @returns Transaction info or null if transaction not found
1544
- */
1545
- getTransaction(signature: string): Promise<TransactionResponse | null>;
1546
- /**
1547
- * Retrieves the total number of transactions processed since genesis.
1548
- */
1549
- getTransactionCount(): Promise<bigint>;
1550
- /**
1551
- * Retrieves the status of multiple transaction signatures.
1552
- */
1553
- getSignatureStatuses(signatures: string[]): Promise<(SignatureStatus | null)[]>;
1554
- /**
1555
- * Retrieves current epoch information.
2197
+ * @param data - Serialized message bytes
2198
+ * @returns Deserialized Message
1556
2199
  */
1557
- getEpochInfo(): Promise<EpochInfoResponse>;
2200
+ static deserialize(data: Uint8Array): Message;
2201
+ private serializeInternal;
2202
+ private serializeCompactArray;
2203
+ private serializeCompactU16;
1558
2204
  /**
1559
- * Checks the health status of the RPC node.
1560
- *
1561
- * @returns "ok" if healthy, error message otherwise
2205
+ * Get all signers required for this message.
1562
2206
  */
1563
- getHealth(): Promise<"ok" | string>;
2207
+ getSigners(): readonly PublicKey[];
1564
2208
  /**
1565
- * Submits a signed transaction to the blockchain.
1566
- *
1567
- * @param transaction - Serialized signed transaction bytes
1568
- * @param options - Transaction submission options
1569
- * @returns Transaction signature
2209
+ * Check if a public key is a required signer.
1570
2210
  */
1571
- sendTransaction(transaction: Uint8Array, options?: SendTransactionOptions): Promise<string>;
2211
+ isSignerRequired(pubkey: PublicKey): boolean;
1572
2212
  /**
1573
- * Requests an airdrop of tokens to an account.
1574
- *
1575
- * **Note**: Only available on devnet and testnet.
1576
- *
1577
- * @param pubkey - Account to receive the airdrop
1578
- * @param amount - Amount in kelvins (smallest unit)
1579
- * @returns Transaction signature
2213
+ * Get the index of a signer in the signers array.
2214
+ * Returns -1 if not a signer.
1580
2215
  */
1581
- requestAirdrop(pubkey: PublicKey, amount: bigint): Promise<string>;
1582
- /**
1583
- * Submits a signed transaction and waits for confirmation.
1584
- *
1585
- * @param transaction - Serialized signed transaction bytes
1586
- * @param options - Transaction submission and confirmation options
1587
- * @returns Confirmed transaction details
1588
- * @throws {TransactionFailedError} If the transaction fails on-chain
1589
- * @throws {TransactionConfirmationTimeoutError} If confirmation times out
2216
+ getSignerIndex(pubkey: PublicKey): number;
2217
+ }
2218
+
2219
+ /**
2220
+ * A transaction with zero or more signatures.
2221
+ *
2222
+ * Transactions are immutable - signing methods return new instances.
2223
+ * This prevents accidental modification and signature tampering.
2224
+ *
2225
+ * @example
2226
+ * ```typescript
2227
+ * // Simple signing
2228
+ * const tx = builder.build();
2229
+ * const signed = tx.sign(keypair);
2230
+ *
2231
+ * // Method chaining
2232
+ * const signed = tx
2233
+ * .sign(keypair1)
2234
+ * .sign(keypair2)
2235
+ * .sign(keypair3);
2236
+ *
2237
+ * // Multi-sig convenience
2238
+ * const signed = tx.signAll([keypair1, keypair2, keypair3]);
2239
+ * ```
2240
+ */
2241
+ declare class Transaction {
2242
+ /** The unsigned message */
2243
+ private readonly message;
2244
+ /** Signatures (64 bytes each), aligned with message.header.numRequiredSignatures */
2245
+ private readonly signatures;
2246
+ private constructor();
2247
+ /**
2248
+ * Create an unsigned transaction from a message.
2249
+ * All signature slots are initialized to zero.
1590
2250
  *
1591
- * @example
1592
- * ```typescript
1593
- * const result = await client.sendAndConfirmTransaction(signedTx);
1594
- * console.log(`Confirmed in slot ${result.slot}`);
1595
- * ```
2251
+ * @internal - Users should use TransactionBuilder instead
1596
2252
  */
1597
- sendAndConfirmTransaction(transaction: Uint8Array, options?: SendAndConfirmOptions): Promise<ConfirmedTransaction>;
2253
+ static fromMessage(message: Message): Transaction;
1598
2254
  /**
1599
- * Waits for a transaction to be confirmed.
1600
- *
1601
- * @param signature - Transaction signature to monitor
1602
- * @param options - Confirmation options
1603
- * @returns Confirmed transaction details
2255
+ * Create transaction from message and existing signatures.
2256
+ * @internal
1604
2257
  */
1605
- confirmTransaction(signature: string, options?: ConfirmTransactionOptions): Promise<ConfirmedTransaction>;
2258
+ static fromMessageAndSignatures(message: Message, signatures: readonly Uint8Array[]): Transaction;
1606
2259
  /**
1607
- * Requests an airdrop and waits for confirmation.
1608
- *
1609
- * **Note**: Only available on devnet and testnet.
2260
+ * Deserialize a transaction from wire format.
1610
2261
  */
1611
- requestAirdropAndConfirm(pubkey: PublicKey, amount: bigint, options?: ConfirmTransactionOptions): Promise<ConfirmedTransaction>;
1612
- }
1613
-
1614
- /**
1615
- * Query client for read-only RPC operations.
1616
- */
1617
-
1618
- /**
1619
- * Client for querying blockchain state.
1620
- *
1621
- * Handles all read-only operations like getting balances, account info, etc.
1622
- */
1623
- declare class QueryRpcClient extends BaseRpcClient {
2262
+ static deserialize(data: Uint8Array): Transaction;
2263
+ getMessage(): Message;
1624
2264
  /**
1625
- * Retrieve the balance of an account in kelvins (smallest unit).
2265
+ * Sign the transaction with a keypair.
2266
+ * Returns a NEW Transaction instance.
1626
2267
  *
1627
- * @param pubkey - The public key of the account to query
1628
- * @returns The account balance in kelvins
2268
+ * @param keypair - Keypair to sign with
2269
+ * @returns New Transaction instance with signature added
1629
2270
  *
1630
2271
  * @example
1631
2272
  * ```typescript
1632
- * const balance = await client.getBalance(publicKey);
1633
- * console.log(`Balance: ${balance} kelvins`);
2273
+ * const signedTx = tx.sign(keypair);
2274
+ * await client.sendTransaction(signedTx.serialize());
1634
2275
  * ```
1635
2276
  */
1636
- getBalance(pubkey: PublicKey): Promise<bigint>;
2277
+ sign(keypair: Keypair): Transaction;
1637
2278
  /**
1638
- * Retrieve detailed information about an account.
1639
- *
1640
- * Returns account data including balance, owner program, stored data,
1641
- * executable status, and rent epoch.
1642
- *
1643
- * @param pubkey - The public key of the account to query
1644
- * @returns Account information, or null if the account does not exist
2279
+ * Sign with multiple keypairs at once.
2280
+ * Returns a NEW Transaction instance.
1645
2281
  *
1646
2282
  * @example
1647
2283
  * ```typescript
1648
- * const info = await client.getAccountInfo(publicKey);
1649
- * if (info) {
1650
- * console.log(`Owner: ${info.owner}`);
1651
- * console.log(`Balance: ${info.balance} kelvins`);
1652
- * console.log(`Data length: ${info.data.length} bytes`);
1653
- * }
2284
+ * const signed = tx.signAll([keypair1, keypair2, keypair3]);
1654
2285
  * ```
1655
2286
  */
1656
- getAccountInfo(pubkey: PublicKey): Promise<AccountInfo | null>;
2287
+ signAll(keypairs: Keypair[]): Transaction;
1657
2288
  /**
1658
- * Retrieve the current block height of the blockchain.
1659
- *
1660
- * The block height represents the number of blocks that have been
1661
- * confirmed on the chain since genesis.
1662
- *
1663
- * @returns The current block height
2289
+ * Sign the transaction with a Signer interface (async).
2290
+ * Returns a NEW Transaction instance.
1664
2291
  *
1665
2292
  * @example
1666
2293
  * ```typescript
1667
- * const height = await client.getBlockHeight();
1668
- * console.log(`Current block height: ${height}`);
2294
+ * const signedTx = await tx.signWith(browserWallet);
1669
2295
  * ```
1670
2296
  */
1671
- getBlockHeight(): Promise<bigint>;
2297
+ signWith(signer: Signer): Promise<Transaction>;
1672
2298
  /**
1673
- * Retrieve transaction signatures for a given address.
1674
- *
1675
- * Returns transaction signatures with metadata associated with the specified
1676
- * address, ordered by slot height (most recent first).
1677
- *
1678
- * @param address - The public key of the address to query
1679
- * @param config - Optional configuration options for the query (limit, before, until)
1680
- * @returns Response containing context and array of signature info with blockHeight and blockTime
1681
- *
1682
- * @example
1683
- * ```typescript
1684
- * const result = await client.getSignaturesForAddress(publicKey, { limit: 10 });
1685
- * console.log(`Query slot: ${result.context.slot}`);
1686
- * result.value.forEach(sig => {
1687
- * console.log(`Transaction: ${sig.signature}, block: ${sig.blockHeight}`);
1688
- * });
1689
- * ```
2299
+ * Sign with multiple signers.
2300
+ * Returns a NEW Transaction instance.
1690
2301
  */
1691
- getSignaturesForAddress(address: PublicKey, config?: GetSignaturesForAddressConfig): Promise<GetSignaturesForAddressResponse>;
2302
+ signAllWith(signers: Signer[]): Promise<Transaction>;
1692
2303
  /**
1693
- * Retrieve detailed information about a confirmed transaction.
1694
- *
1695
- * Returns transaction metadata including the block height it was
1696
- * confirmed in and any execution errors.
1697
- *
1698
- * @param signature - The transaction signature to query
1699
- * @returns Transaction information, or null if the transaction is not found
2304
+ * Partially sign the transaction (for multi-sig transactions).
2305
+ * Returns a NEW Transaction instance.
1700
2306
  *
1701
2307
  * @example
1702
2308
  * ```typescript
1703
- * const tx = await client.getTransaction(signature);
1704
- * if (tx) {
1705
- * console.log(`Confirmed in block: ${tx.blockHeight}`);
1706
- * if (tx.err) {
1707
- * console.log(`Transaction failed: ${tx.err}`);
1708
- * }
1709
- * }
2309
+ * const signedTx = tx
2310
+ * .partialSign(signer1)
2311
+ * .partialSign(signer2);
1710
2312
  * ```
1711
2313
  */
1712
- getTransaction(signature: string): Promise<TransactionResponse | null>;
2314
+ partialSign(keypair: Keypair): Transaction;
1713
2315
  /**
1714
- * Retrieve the total number of transactions processed since genesis.
1715
- *
1716
- * @returns The total transaction count
1717
- *
1718
- * @example
1719
- * ```typescript
1720
- * const count = await client.getTransactionCount();
1721
- * console.log(`Total transactions: ${count}`);
1722
- * ```
2316
+ * Partially sign with a Signer interface (async).
2317
+ * Returns a NEW Transaction instance.
1723
2318
  */
1724
- getTransactionCount(): Promise<bigint>;
2319
+ partialSignWith(signer: Signer): Promise<Transaction>;
1725
2320
  /**
1726
- * Retrieve the status of multiple transaction signatures in a single request.
1727
- *
1728
- * Useful for batch-checking transaction confirmations. Returns null for
1729
- * signatures that are not found or have expired from the status cache.
1730
- *
1731
- * @param signatures - Array of transaction signatures to query
1732
- * @returns Array of signature statuses (null if signature not found)
2321
+ * Add a signature at a specific index.
2322
+ * Returns a NEW Transaction instance.
1733
2323
  *
1734
- * @example
1735
- * ```typescript
1736
- * const statuses = await client.getSignatureStatuses([sig1, sig2, sig3]);
1737
- * statuses.forEach((status, i) => {
1738
- * if (status) {
1739
- * console.log(`${signatures[i]}: slot ${status.slot}, executed: ${status.executed}`);
1740
- * } else {
1741
- * console.log(`${signatures[i]}: not found`);
1742
- * }
1743
- * });
1744
- * ```
2324
+ * Most users should use sign() or signAll() instead.
1745
2325
  */
1746
- getSignatureStatuses(signatures: string[]): Promise<(SignatureStatus | null)[]>;
2326
+ addSignature(index: number, signature: Signature | Uint8Array): Transaction;
1747
2327
  /**
1748
- * Retrieve information about the current epoch.
1749
- *
1750
- * Returns epoch metadata including the current epoch number, slot position
1751
- * within the epoch, total slots per epoch, and current block height.
1752
- *
1753
- * @returns Current epoch information
2328
+ * Add a signature for a specific public key.
2329
+ * Returns a NEW Transaction instance.
1754
2330
  *
1755
- * @example
1756
- * ```typescript
1757
- * const info = await client.getEpochInfo();
1758
- * console.log(`Epoch: ${info.epoch}`);
1759
- * console.log(`Slot ${info.slotIndex} of ${info.slotsInEpoch}`);
1760
- * console.log(`Block height: ${info.blockHeight}`);
1761
- * ```
2331
+ * Most users should use sign() or signAll() instead.
1762
2332
  */
1763
- getEpochInfo(): Promise<EpochInfoResponse>;
2333
+ addSignatureForPubkey(pubkey: PublicKey, signature: Signature | Uint8Array): Transaction;
1764
2334
  /**
1765
- * Check the health status of the RPC node.
1766
- *
1767
- * Returns "ok" if the node is healthy. If the node is unhealthy,
1768
- * returns an error message describing the issue.
1769
- *
1770
- * @returns "ok" if healthy, otherwise an error message
1771
- *
1772
- * @example
1773
- * ```typescript
1774
- * const health = await client.getHealth();
1775
- * if (health === "ok") {
1776
- * console.log("Node is healthy");
1777
- * } else {
1778
- * console.log(`Node unhealthy: ${health}`);
1779
- * }
1780
- * ```
2335
+ * Check if transaction is fully signed (all signatures present).
1781
2336
  */
1782
- getHealth(): Promise<"ok" | string>;
1783
- }
1784
-
1785
- /**
1786
- * Query client for read-only RPC operations.
1787
- */
1788
-
1789
- /**
1790
- * Client for sending/simulating transactions and requesting airdrops.
1791
- *
1792
- * Handles all transaction operations like sending transactions, requesting airdrops, etc.
1793
- */
1794
- declare class TransactionRpcClient extends BaseRpcClient {
2337
+ isSigned(): boolean;
1795
2338
  /**
1796
- * Submit a signed transaction to the blockchain.
1797
- *
1798
- * Sends the transaction to the network for processing. The transaction
1799
- * must be fully signed before submission. Returns immediately with the
1800
- * transaction signature - use {@link confirmTransaction} or
1801
- * {@link sendAndConfirmTransaction} to wait for confirmation.
1802
- *
1803
- * @param transaction - Serialized signed transaction bytes
1804
- * @param options - Transaction submission options
1805
- * @returns Transaction signature (base58 encoded)
1806
- *
1807
- * @example
1808
- * ```typescript
1809
- * const signature = await client.sendTransaction(signedTx);
1810
- * console.log(`Submitted: ${signature}`);
1811
- *
1812
- * // With options
1813
- * const signature = await client.sendTransaction(signedTx, {
1814
- * skipPreflight: true,
1815
- * maxRetries: 3,
1816
- * });
1817
- * ```
2339
+ * Check if a specific signature slot is filled.
1818
2340
  */
1819
- sendTransaction(transaction: Uint8Array, options?: SendTransactionOptions): Promise<string>;
2341
+ isSignaturePresent(index: number): boolean;
1820
2342
  /**
1821
- * Wait for a transaction to be confirmed.
1822
- *
1823
- * A transaction is considered confirmed when:
1824
- * - It has been processed in a block (`blockHeight > 0`)
1825
- *
1826
- * @param signature - Transaction signature to monitor
1827
- * @param options - Confirmation options
1828
- * @returns Confirmed transaction details
1829
- * @throws {TransactionFailedError} If the transaction fails on-chain
1830
- * @throws {TransactionConfirmationTimeoutError} If confirmation times out
2343
+ * Get all signatures (returns copies to prevent mutation).
1831
2344
  */
1832
- confirmTransaction(signature: string, options?: ConfirmTransactionOptions): Promise<ConfirmedTransaction>;
2345
+ getSignatures(): readonly Uint8Array[];
2346
+ /**
2347
+ * Get a specific signature (returns copy).
2348
+ */
2349
+ getSignature(index: number): Uint8Array;
2350
+ /**
2351
+ * Get a specific signature for a public key.
2352
+ */
2353
+ getSignatureForPubkey(pubkey: PublicKey): Uint8Array;
1833
2354
  /**
1834
- * Submit a signed transaction and wait for confirmation.
1835
- *
1836
- * Polls the transaction status until it is confirmed (blockHeight > 0),
1837
- * or until the maximum number of retries is reached.
1838
- *
1839
- * @param transaction - Serialized signed transaction bytes
1840
- * @param options - Transaction submission and confirmation options
1841
- * @returns Confirmed transaction details
1842
- * @throws {TransactionFailedError} If the transaction fails on-chain
1843
- * @throws {TransactionConfirmationTimeoutError} If confirmation times out
1844
- *
1845
- * @example
1846
- * ```typescript
1847
- * const result = await client.sendAndConfirmTransaction(signedTx);
1848
- * console.log(`Confirmed in block ${result.blockHeight}, executed: ${result.executed}`);
1849
- *
1850
- * // With custom retry settings
1851
- * const result = await client.sendAndConfirmTransaction(signedTx, {
1852
- * maxRetries: 3,
1853
- * retryDelay: 500,
1854
- * });
1855
- * ```
2355
+ * Get required signers for this transaction.
1856
2356
  */
1857
- sendAndConfirmTransaction(transaction: Uint8Array, options?: SendAndConfirmOptions): Promise<ConfirmedTransaction>;
2357
+ getSigners(): readonly PublicKey[];
1858
2358
  /**
1859
- * Request an airdrop of tokens to an account.
1860
- *
1861
- * **Note**: Only available on devnet and testnet networks.
1862
- *
1863
- * Returns immediately with the airdrop transaction signature.
1864
- * Use {@link requestAirdropAndConfirm} to wait for the airdrop to complete.
1865
- *
1866
- * @param pubkey - The public key of the account to receive tokens
1867
- * @param amount - Amount to airdrop in kelvins (smallest unit)
1868
- * @returns Airdrop transaction signature
1869
- *
1870
- * @example
1871
- * ```typescript
1872
- * const signature = await client.requestAirdrop(publicKey, 1_000_000_000n);
1873
- * console.log(`Airdrop requested: ${signature}`);
1874
- * ```
2359
+ * Get the number of required signatures.
1875
2360
  */
1876
- requestAirdrop(pubkey: PublicKey, amount: bigint): Promise<string>;
2361
+ getRequiredSignatureCount(): number;
1877
2362
  /**
1878
- * Request an airdrop of tokens and wait for confirmation.
1879
- *
1880
- * **Note**: Only available on devnet and testnet networks.
1881
- *
1882
- * Combines {@link requestAirdrop} and {@link confirmTransaction} into
1883
- * a single call for convenience.
2363
+ * Throw an error if the transaction is not fully signed.
1884
2364
  *
1885
- * @param pubkey - The public key of the account to receive tokens
1886
- * @param amount - Amount to airdrop in kelvins (smallest unit)
1887
- * @param options - Confirmation options (max retries, retry delay)
1888
- * @returns Confirmed transaction details
1889
- * @throws {RpcError} If the airdrop transaction fails or confirmation times out
2365
+ * @throws {TransactionError} If transaction is not fully signed
1890
2366
  *
1891
2367
  * @example
1892
2368
  * ```typescript
1893
- * const result = await client.requestAirdropAndConfirm(publicKey, 1_000_000_000n);
1894
- * if (result.executed) {
1895
- * console.log("Airdrop confirmed!");
1896
- * }
2369
+ * signedTx.ensureSigned(); // Throws if not signed
2370
+ * await client.sendTransaction(signedTx.serialize());
1897
2371
  * ```
1898
2372
  */
1899
- requestAirdropAndConfirm(pubkey: PublicKey, amount: bigint, options?: ConfirmTransactionOptions): Promise<ConfirmedTransaction>;
1900
- private getTransaction;
2373
+ ensureSigned(): void;
1901
2374
  /**
1902
- * Sleeps for a given number of milliseconds.
1903
- * @param ms - The number of milliseconds to sleep.
1904
- * @returns A promise that resolves when the sleep is complete.
2375
+ * Serialize transaction to wire format.
1905
2376
  */
1906
- private sleep;
2377
+ serialize(): Uint8Array;
1907
2378
  }
1908
2379
 
1909
2380
  /**
1910
- * Error codes for RPC operations, categorized by type.
1911
- */
1912
- declare enum RpcErrorCode {
1913
- REQUEST_TIMEOUT = "REQUEST_TIMEOUT",
1914
- NETWORK_ERROR = "NETWORK_ERROR",
1915
- CONNECTION_REFUSED = "CONNECTION_REFUSED",
1916
- INVALID_NETWORK = "INVALID_NETWORK",
1917
- INVALID_RESPONSE = "INVALID_RESPONSE",
1918
- PARSE_ERROR = "PARSE_ERROR",
1919
- INVALID_REQUEST = "INVALID_REQUEST",
1920
- METHOD_NOT_FOUND = "METHOD_NOT_FOUND",
1921
- INVALID_PARAMS = "INVALID_PARAMS",
1922
- INTERNAL_ERROR = "INTERNAL_ERROR",
1923
- TRANSACTION_REJECTED = "TRANSACTION_REJECTED",
1924
- INSUFFICIENT_FUNDS = "INSUFFICIENT_FUNDS",
1925
- TRANSACTION_CONFIRMATION_TIMEOUT = "TRANSACTION_CONFIRMATION_TIMEOUT",
1926
- ACCOUNT_NOT_FOUND = "ACCOUNT_NOT_FOUND",
1927
- RATE_LIMIT_EXCEEDED = "RATE_LIMIT_EXCEEDED",
1928
- NODE_UNHEALTHY = "NODE_UNHEALTHY"
1929
- }
1930
- /**
1931
- * Detailed error context for debugging and error handling.
1932
- */
1933
- interface RpcErrorDetails {
1934
- method?: string;
1935
- params?: unknown;
1936
- requestId?: number;
1937
- url?: string;
1938
- httpStatus?: number;
1939
- rpcCode?: number;
1940
- timeout?: number;
1941
- attempts?: number;
1942
- [key: string]: unknown;
1943
- }
1944
- /**
1945
- * Error class for RPC operations with structured error information.
1946
- *
1947
- * Provides actionable error messages and indicates whether errors are retryable.
2381
+ * Fluent API for building transactions.
2382
+ * Returns Transaction directly (not Message).
1948
2383
  */
1949
- declare class RpcError extends Error {
1950
- readonly code: RpcErrorCode;
1951
- readonly details: RpcErrorDetails;
1952
- readonly retryable: boolean;
1953
- constructor(code: RpcErrorCode, message: string, details?: RpcErrorDetails, retryable?: boolean);
1954
- static requestTimeout(timeoutMs: number, details: RpcErrorDetails): RpcError;
1955
- static networkError(message: string, details: RpcErrorDetails): RpcError;
1956
- static invalidResponse(details: RpcErrorDetails): RpcError;
1957
- static accountNotFound(pubkey: string): RpcError;
1958
- static rateLimitExceeded(details: RpcErrorDetails): RpcError;
1959
- static fromRpcCode(rpcCode: number, message: string, details: RpcErrorDetails): RpcError;
1960
- toJSON(): {
1961
- code: RpcErrorCode;
1962
- message: string;
1963
- details?: Record<string, unknown>;
1964
- retryable: boolean;
1965
- };
1966
- }
1967
2384
 
1968
2385
  /**
1969
- * Creates an RPC client with automatic retry and timeout handling.
2386
+ * Builder for creating transactions with a fluent API.
1970
2387
  *
1971
- * @param config - Client configuration with chain definition and optional transport settings
1972
- * @param config.chain - Chain definition (e.g., RIALO_DEVNET_CHAIN, RIALO_MAINNET_CHAIN) or a custom chain with your own rpcUrl
1973
- * @param config.transport - Optional transport configuration (timeout, retries, headers)
1974
- * @returns Configured RialoClient instance
2388
+ * Provides an intuitive interface for constructing transactions.
2389
+ * Call build() to get an unsigned Transaction ready for signing.
1975
2390
  *
1976
2391
  * @example
1977
2392
  * ```typescript
1978
- * // Basic usage with preset chain
1979
- * const client = createRialoClient({ chain: RIALO_DEVNET_CHAIN });
1980
- *
1981
- * // With custom transport config
1982
- * const client = createRialoClient({
1983
- * chain: RIALO_MAINNET_CHAIN,
1984
- * transport: { timeout: 30000, maxRetries: 5 }
1985
- * });
2393
+ * // Simple transfer
2394
+ * const tx = TransactionBuilder.create()
2395
+ * .setPayer(payer)
2396
+ * .setValidFrom(validFrom)
2397
+ * .addInstruction(transfer(from, to, 1_000_000n))
2398
+ * .build();
1986
2399
  *
1987
- * // With custom RPC URL
1988
- * const client = createRialoClient({
1989
- * chain: {
1990
- * id: 'rialo:mainnet',
1991
- * name: 'Mainnet',
1992
- * rpcUrl: 'https://mainnet.custom-rpc.com:4101'
1993
- * },
1994
- * });
2400
+ * const signedTx = tx.sign(keypair);
2401
+ * await client.transaction.sendTransaction(signedTx.serialize());
1995
2402
  * ```
1996
- */
1997
- declare function createRialoClient(config: RialoClientConfig): RialoClient;
1998
- /**
1999
- * Returns a default RialoClientConfig for a given network.
2000
- *
2001
- * Provides preset chain configurations for standard Rialo networks, making it easy
2002
- * to connect to mainnet, devnet, testnet, or localnet without manual configuration.
2003
- *
2004
- * @param network - Network identifier: "mainnet", "devnet", "testnet", or "localnet"
2005
- * @returns Default RialoClientConfig for the specified network
2006
- * @throws {RpcError} With code INVALID_NETWORK if an unknown network is provided
2007
2403
  *
2008
2404
  * @example
2009
2405
  * ```typescript
2010
- * // Get devnet config and create client
2011
- * const config = getDefaultRialoClientConfig('devnet');
2012
- * const client = createRialoClient(config);
2013
- *
2014
- * // Customize the config with transport options
2015
- * const config = getDefaultRialoClientConfig('mainnet');
2016
- * const client = createRialoClient({
2017
- * ...config,
2018
- * transport: { timeout: 60000, maxRetries: 5 }
2019
- * });
2020
- *
2021
- * // Use custom RPC URL while preserving network identity
2022
- * const config = getDefaultRialoClientConfig('mainnet');
2023
- * const client = createRialoClient({
2024
- * ...config,
2025
- * chain: {
2026
- * ...config.chain,
2027
- * rpcUrl: 'https://mainnet.custom-rpc.com:4101'
2028
- * },
2029
- * });
2406
+ * // Multi-instruction transaction
2407
+ * const tx = TransactionBuilder.create()
2408
+ * .setPayer(payer)
2409
+ * .setValidFrom(validFrom)
2410
+ * .addInstruction(transfer(from, to, 1_000_000n))
2411
+ * .addInstruction(memoInstruction("Payment for invoice #123"))
2412
+ * .build();
2030
2413
  * ```
2031
2414
  */
2032
- declare function getDefaultRialoClientConfig(network: RialoNetwork): RialoClientConfig;
2415
+ declare class TransactionBuilder {
2416
+ private payer?;
2417
+ private validFrom?;
2418
+ private readonly instructions;
2419
+ private constructor();
2420
+ /**
2421
+ * Create a new transaction builder.
2422
+ */
2423
+ static create(): TransactionBuilder;
2424
+ /**
2425
+ * Set the fee payer for this transaction.
2426
+ *
2427
+ * The payer will be the first account and must sign the transaction.
2428
+ * The payer pays for transaction fees.
2429
+ *
2430
+ * @param payer - Public key of the fee payer
2431
+ */
2432
+ setPayer(payer: PublicKey): this;
2433
+ /**
2434
+ * Set the Transaction valid from.
2435
+ *
2436
+ * This is the time the transaction is valid from, in milliseconds since Unix epoch.
2437
+ * It can be used for additional replay protection or auditing.
2438
+ *
2439
+ * @param validFrom - Transaction valid from in milliseconds since Unix epoch
2440
+ */
2441
+ setValidFrom(validFrom: bigint): this;
2442
+ /**
2443
+ * Add an instruction to the transaction.
2444
+ *
2445
+ * @param instruction - Instruction to add
2446
+ */
2447
+ addInstruction(instruction: Instruction): this;
2448
+ /**
2449
+ * Add multiple instructions at once.
2450
+ *
2451
+ * @param instructions - Array of instructions to add
2452
+ */
2453
+ addInstructions(instructions: readonly Instruction[]): this;
2454
+ /**
2455
+ * Build the transaction (unsigned).
2456
+ *
2457
+ * Returns an unsigned Transaction that's ready to be signed.
2458
+ *
2459
+ * @returns Unsigned Transaction
2460
+ * @throws {TransactionError} If payer, valid_from, or instructions are missing
2461
+ *
2462
+ * @example
2463
+ * ```typescript
2464
+ * const tx = builder.build();
2465
+ * const signedTx = tx.sign(keypair);
2466
+ * ```
2467
+ */
2468
+ build(): Transaction;
2469
+ }
2033
2470
 
2034
2471
  /**
2035
2472
  * Converts bytes to base64 string.
@@ -2075,4 +2512,4 @@ declare function getMainnetUrl(): string;
2075
2512
  */
2076
2513
  declare function getLocalnetUrl(): string;
2077
2514
 
2078
- export { type AccountInfo, type AccountMeta, AccountMetaTable, BASE_DERIVATION_PATH, BaseRpcClient, type ChainDefinition, type CompiledInstruction, type ConfirmTransactionOptions, type ConfirmedTransaction, CryptoError, CryptoErrorCode, DEFAULT_NUM_ACCOUNTS, type EpochInfoResponse, type GetConnectedFullNodesResponse, type GetFeeForMessageResponse, type GetHealthResponse, type GetSignaturesForAddressConfig, type GetSignaturesForAddressResponse, type GetSubscriptionsResponse, type GetTransactionsConfig, type GetTransactionsResponse, type GetTriggeredTransactionsResponse, type GetValidatorHealthResponse, type GetWorkflowLineageRequest, type GetWorkflowLineageResponse, HttpTransport, type HttpTransportConfig, type IdentifierString, type Instruction, type IsBlockhashValidResponse, KELVIN_PER_RLO, Keypair, KeypairSigner, Message, type MessageHeader, Mnemonic, type MnemonicStrength, type MultipleAccountsResponse, PUBLIC_KEY_LENGTH, PublicKey, QueryRpcClient, RIALO_DEVNET_CHAIN, RIALO_LOCALNET_CHAIN, RIALO_MAINNET_CHAIN, RIALO_TESTNET_CHAIN, RialoClient, type RialoClientConfig, RialoError, RialoErrorType, type RialoNetwork, RpcError, RpcErrorCode, type RpcErrorDetails$1 as RpcErrorDetails, SECRET_KEY_LENGTH, SIGNATURE_LENGTH, SYSTEM_PROGRAM_ID, type SendAndConfirmOptions, type SendTransactionOptions, Signature, type SignatureStatus, type Signer, SystemInstruction, Transaction, TransactionBuilder, TransactionError, TransactionErrorCode, type TransactionResponse, TransactionRpcClient, URL_DEVNET, URL_LOCALNET, URL_MAINNET, URL_TESTNET, calculateBackoff, createAccount, createBorshInstruction, createRialoClient, encodeBorshData, fromBase64, getDefaultRialoClientConfig, getDevnetUrl, getLocalnetUrl, getMainnetUrl, getTestnetUrl, sleep, toBase64, transferInstruction };
2515
+ export { type AccountFilter, type AccountInfo, type AccountMeta, AccountMetaTable, BASE_DERIVATION_PATH, BaseRpcClient, type Bump, type ChainDefinition, type CompiledInstruction, type ConfirmTransactionOptions, type ConfirmedTransaction, CryptoError, CryptoErrorCode, DEFAULT_NUM_ACCOUNTS, type EpochInfoResponse, type EventData, type GetAccountsByOwnerConfig, type GetAccountsByOwnerResponse, type GetHealthResponse, type GetSignaturesForAddressConfig, type GetTransactionsConfig, type GetTransactionsResponse, type GetWorkflowLineageRequest, type GetWorkflowLineageResponse, HttpTransport, type HttpTransportConfig, type IdentifierString, type Instruction, KELVIN_PER_RLO, Keypair, KeypairSigner, Message, type MessageHeader, Mnemonic, type MnemonicStrength, type OwnerAccount, type PDA, PUBLIC_KEY_LENGTH, type PaginationInfo, PublicKey, QueryRpcClient, RIALO_DEVNET_CHAIN, RIALO_LOCALNET_CHAIN, RIALO_MAINNET_CHAIN, RIALO_SHITNET_CHAIN, RIALO_TESTNET_CHAIN, RialoClient, type RialoClientConfig, RialoError, RialoErrorType, type RialoNetwork, RpcError, RpcErrorCode, type RpcErrorDetails$1 as RpcErrorDetails, SECRET_KEY_LENGTH, SIGNATURE_LENGTH, SYSTEM_PROGRAM_ID, type Seed, type SendAndConfirmOptions, type SendTransactionOptions, Signature, type SignatureInfo, type SignatureStatus, type Signer, type Subscription, type SubscriptionKind, SystemInstruction, type TimestampRange, Transaction, TransactionBuilder, TransactionError, TransactionErrorCode, type TransactionNodeData, type TransactionResponse, TransactionRpcClient, type TriggerInfo, type TriggeredTransaction, type TruncationReason, URL_DEVNET, URL_LOCALNET, URL_MAINNET, URL_SHITNET, URL_TESTNET, type WorkflowLineage, type WorkflowNode, allocateInstruction, assignInstruction, calculateBackoff, concatBytes, createAccount, createBorshInstruction, createRialoClient, encodeBorshData, fromBase64, getDefaultRialoClientConfig, getDevnetUrl, getLocalnetUrl, getMainnetUrl, getTestnetUrl, isOnCurve, seedToBytes, sleep, toBase64, transferInstruction };