@rialo/ts-cdk 0.2.0-alpha.3 → 0.2.0-alpha.4
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.mts +2895 -0
- package/dist/index.d.ts +2895 -0
- package/dist/index.js +9818 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +9743 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +2 -3
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,2895 @@
|
|
|
1
|
+
export { field, fixedArray, option, vec } from '@dao-xyz/borsh';
|
|
2
|
+
|
|
3
|
+
interface HttpTransportConfig {
|
|
4
|
+
/** Request timeout in milliseconds */
|
|
5
|
+
timeout?: number;
|
|
6
|
+
/** Maximum number of retry attempts */
|
|
7
|
+
maxRetries?: number;
|
|
8
|
+
/** Base delay for exponential backoff (ms) */
|
|
9
|
+
retryBaseDelay?: number;
|
|
10
|
+
/** Maximum retry delay (ms) */
|
|
11
|
+
retryMaxDelay?: number;
|
|
12
|
+
/** Custom headers to include in requests */
|
|
13
|
+
headers?: Record<string, string>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* HTTP transport with built-in retry logic and timeout handling.
|
|
17
|
+
*
|
|
18
|
+
* Features:
|
|
19
|
+
* - Automatic retries with exponential backoff
|
|
20
|
+
* - Request timeouts using AbortController
|
|
21
|
+
* - Network error recovery
|
|
22
|
+
* - Rate limit handling
|
|
23
|
+
* - Proper HTTP status code handling
|
|
24
|
+
*/
|
|
25
|
+
declare class HttpTransport {
|
|
26
|
+
private readonly url;
|
|
27
|
+
private readonly config;
|
|
28
|
+
constructor(url: string, config?: HttpTransportConfig);
|
|
29
|
+
/**
|
|
30
|
+
* Makes an HTTP request with automatic retry logic.
|
|
31
|
+
*
|
|
32
|
+
* Retries are attempted for network errors and server errors (5xx).
|
|
33
|
+
* Uses exponential backoff between retry attempts.
|
|
34
|
+
*/
|
|
35
|
+
request(body: string, requestDetails?: Record<string, unknown>): Promise<unknown>;
|
|
36
|
+
/**
|
|
37
|
+
* Make a single HTTP request with timeout
|
|
38
|
+
*/
|
|
39
|
+
private makeRequest;
|
|
40
|
+
/**
|
|
41
|
+
* Handle HTTP error responses.
|
|
42
|
+
*
|
|
43
|
+
* Parses the response body to extract JSON-RPC error details when available,
|
|
44
|
+
* regardless of HTTP status code. Falls back to HTTP status-based error handling.
|
|
45
|
+
*/
|
|
46
|
+
private handleHttpError;
|
|
47
|
+
/**
|
|
48
|
+
* Parse error response body to extract message and RPC error code.
|
|
49
|
+
*
|
|
50
|
+
* Handles multiple formats:
|
|
51
|
+
* - JSON-RPC error: { error: { code, message, data? } }
|
|
52
|
+
* - Simple JSON: { message: "..." }
|
|
53
|
+
* - Non-JSON responses
|
|
54
|
+
*/
|
|
55
|
+
private parseErrorResponse;
|
|
56
|
+
/**
|
|
57
|
+
* Returns the configured RPC endpoint URL.
|
|
58
|
+
*/
|
|
59
|
+
getUrl(): string;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
type IdentifierString = `${string}:${string}`;
|
|
63
|
+
type RialoNetwork = "mainnet" | "devnet" | "testnet" | "localnet";
|
|
64
|
+
interface ChainDefinition {
|
|
65
|
+
/** * The Wallet Standard Chain Identifier.
|
|
66
|
+
* e.g., 'rialo:mainnet', 'rialo:devnet'
|
|
67
|
+
*/
|
|
68
|
+
id: IdentifierString;
|
|
69
|
+
/** Human-readable name for UI */
|
|
70
|
+
name: string;
|
|
71
|
+
/** The default RPC URL for this chain */
|
|
72
|
+
rpcUrl: string;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Configuration for the Rialo Client.
|
|
76
|
+
*/
|
|
77
|
+
interface RialoClientConfig {
|
|
78
|
+
/**
|
|
79
|
+
* The Chain Definition.
|
|
80
|
+
* Can be a preset (RIALO_MAINNET) or a custom object.
|
|
81
|
+
*/
|
|
82
|
+
chain: ChainDefinition;
|
|
83
|
+
transport?: HttpTransportConfig;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Default number of accounts to derive in HD wallets */
|
|
87
|
+
declare const DEFAULT_NUM_ACCOUNTS: number;
|
|
88
|
+
/** Rialo mainnet RPC URL */
|
|
89
|
+
declare const URL_MAINNET: string;
|
|
90
|
+
/** Rialo testnet RPC URL */
|
|
91
|
+
declare const URL_TESTNET: string;
|
|
92
|
+
/** Rialo devnet RPC URL */
|
|
93
|
+
declare const URL_DEVNET: string;
|
|
94
|
+
/** Rialo localnet RPC URL */
|
|
95
|
+
declare const URL_LOCALNET: string;
|
|
96
|
+
/** Rialo shitnet RPC URL */
|
|
97
|
+
declare const URL_SHITNET: string;
|
|
98
|
+
declare const RIALO_MAINNET_CHAIN: ChainDefinition;
|
|
99
|
+
declare const RIALO_TESTNET_CHAIN: ChainDefinition;
|
|
100
|
+
declare const RIALO_DEVNET_CHAIN: ChainDefinition;
|
|
101
|
+
declare const RIALO_LOCALNET_CHAIN: ChainDefinition;
|
|
102
|
+
declare const RIALO_SHITNET_CHAIN: ChainDefinition;
|
|
103
|
+
/** System program ID */
|
|
104
|
+
declare const SYSTEM_PROGRAM_ID: string;
|
|
105
|
+
/** Base derivation path for Rialo wallets (BIP44 coin type 756) */
|
|
106
|
+
/** Coin type 756 follows the telephone keypad convention: R=7, L=5, O=6 */
|
|
107
|
+
declare const BASE_DERIVATION_PATH: string;
|
|
108
|
+
declare const KELVIN_PER_RLO: number;
|
|
109
|
+
declare const PUBLIC_KEY_LENGTH: number;
|
|
110
|
+
declare const SECRET_KEY_LENGTH: number;
|
|
111
|
+
declare const SIGNATURE_LENGTH: number;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Error codes for cryptographic operations.
|
|
115
|
+
*/
|
|
116
|
+
declare enum CryptoErrorCode {
|
|
117
|
+
INVALID_KEY_LENGTH = "INVALID_KEY_LENGTH",
|
|
118
|
+
INVALID_SIGNATURE = "INVALID_SIGNATURE",
|
|
119
|
+
INVALID_PUBLIC_KEY = "INVALID_PUBLIC_KEY",
|
|
120
|
+
INVALID_BLOCKHASH = "INVALID_BLOCKHASH",
|
|
121
|
+
INVALID_MNEMONIC = "INVALID_MNEMONIC",
|
|
122
|
+
KEY_DERIVATION_FAILED = "KEY_DERIVATION_FAILED",
|
|
123
|
+
KEYPAIR_DISPOSED = "KEYPAIR_DISPOSED",
|
|
124
|
+
MAX_SEED_LENGTH_EXCEEDED = "MAX_SEED_LENGTH_EXCEEDED",
|
|
125
|
+
MAX_SEEDS_EXCEEDED = "MAX_SEEDS_EXCEEDED",
|
|
126
|
+
INVALID_SEEDS_ON_CURVE = "INVALID_SEEDS_ON_CURVE",
|
|
127
|
+
NO_VIABLE_BUMP_SEED = "NO_VIABLE_BUMP_SEED",
|
|
128
|
+
INVALID_SEED = "INVALID_SEED"
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Error class for cryptographic operations.
|
|
132
|
+
*
|
|
133
|
+
* Provides structured error information with error codes and contextual details
|
|
134
|
+
* for better debugging and error handling.
|
|
135
|
+
*/
|
|
136
|
+
declare class CryptoError extends Error {
|
|
137
|
+
readonly code: CryptoErrorCode;
|
|
138
|
+
readonly details?: Record<string, unknown>;
|
|
139
|
+
constructor(code: CryptoErrorCode, message: string, details?: Record<string, unknown>);
|
|
140
|
+
static invalidKeyLength(expected: number, actual: number): CryptoError;
|
|
141
|
+
static invalidMnemonic(reason?: string): CryptoError;
|
|
142
|
+
static keyDerivationFailed(path: string, cause?: Error): CryptoError;
|
|
143
|
+
static keypairDisposed(): CryptoError;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Represents a 64-byte Ed25519 signature.
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```typescript
|
|
151
|
+
* // From bytes
|
|
152
|
+
* const sig = Signature.fromBytes(signatureBytes);
|
|
153
|
+
*
|
|
154
|
+
* // From base58 string
|
|
155
|
+
* const sig = Signature.fromString("3Bxs4h...");
|
|
156
|
+
*
|
|
157
|
+
* // Serialize
|
|
158
|
+
* const base58 = sig.toString();
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
declare class Signature {
|
|
162
|
+
private readonly bytes;
|
|
163
|
+
private constructor();
|
|
164
|
+
/**
|
|
165
|
+
* Creates a Signature from raw bytes.
|
|
166
|
+
*
|
|
167
|
+
* @param bytes - 64-byte Ed25519 signature
|
|
168
|
+
* @throws {CryptoError} If bytes length is not 64
|
|
169
|
+
*/
|
|
170
|
+
static fromBytes(bytes: Uint8Array): Signature;
|
|
171
|
+
/**
|
|
172
|
+
* Creates a Signature from a base58-encoded string.
|
|
173
|
+
*
|
|
174
|
+
* @param str - Base58-encoded signature
|
|
175
|
+
* @throws {CryptoError} If string is invalid or decodes to wrong length
|
|
176
|
+
*/
|
|
177
|
+
static fromString(str: string): Signature;
|
|
178
|
+
/**
|
|
179
|
+
* Returns a copy of the raw bytes.
|
|
180
|
+
*/
|
|
181
|
+
toBytes(): Uint8Array;
|
|
182
|
+
/**
|
|
183
|
+
* Returns the base58-encoded string representation.
|
|
184
|
+
*/
|
|
185
|
+
toString(): string;
|
|
186
|
+
/**
|
|
187
|
+
* JSON serialization (returns base58 string).
|
|
188
|
+
*/
|
|
189
|
+
toJSON(): string;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* A seed for PDA derivation - string (UTF-8) or raw bytes.
|
|
194
|
+
*/
|
|
195
|
+
type Seed = string | Uint8Array;
|
|
196
|
+
/**
|
|
197
|
+
* Bump seed (0-255) that pushes derived address off the Ed25519 curve.
|
|
198
|
+
*/
|
|
199
|
+
type Bump = number;
|
|
200
|
+
/**
|
|
201
|
+
* Result of PDA derivation: [address, bump].
|
|
202
|
+
*/
|
|
203
|
+
type PDA = readonly [PublicKey, Bump];
|
|
204
|
+
/**
|
|
205
|
+
* Represents a 32-byte Ed25519 public key.
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* ```typescript
|
|
209
|
+
* // From base58 string
|
|
210
|
+
* const pubkey = PublicKey.fromString("5ZqB9U...");
|
|
211
|
+
*
|
|
212
|
+
* // From bytes
|
|
213
|
+
* const pubkey = PublicKey.fromBytes(new Uint8Array(32));
|
|
214
|
+
*
|
|
215
|
+
* // Comparison
|
|
216
|
+
* if (pubkey1.equals(pubkey2)) {
|
|
217
|
+
* console.log("Keys match");
|
|
218
|
+
* }
|
|
219
|
+
* ```
|
|
220
|
+
*/
|
|
221
|
+
declare class PublicKey {
|
|
222
|
+
private readonly bytes;
|
|
223
|
+
private constructor();
|
|
224
|
+
/**
|
|
225
|
+
* Creates a PublicKey from raw bytes.
|
|
226
|
+
*
|
|
227
|
+
* @param bytes - 32-byte Ed25519 public key
|
|
228
|
+
* @throws {CryptoError} If bytes length is not 32
|
|
229
|
+
*/
|
|
230
|
+
static fromBytes(bytes: Uint8Array): PublicKey;
|
|
231
|
+
/**
|
|
232
|
+
* Creates a PublicKey from a base58-encoded string.
|
|
233
|
+
*
|
|
234
|
+
* @param str - Base58-encoded public key
|
|
235
|
+
* @throws {CryptoError} If string is invalid or decodes to wrong length
|
|
236
|
+
*/
|
|
237
|
+
static fromString(str: string): PublicKey;
|
|
238
|
+
/**
|
|
239
|
+
* Derives a program address from seeds and a program ID.
|
|
240
|
+
*
|
|
241
|
+
* @remarks
|
|
242
|
+
* This is the low-level derivation function. It will throw if the resulting
|
|
243
|
+
* address falls on the Ed25519 curve. For most use cases, prefer
|
|
244
|
+
* {@link findProgramAddress} which automatically finds a valid bump seed.
|
|
245
|
+
*
|
|
246
|
+
* Use this method when you already know the bump seed (e.g., stored on-chain
|
|
247
|
+
* or passed from a previous computation) for better performance.
|
|
248
|
+
*
|
|
249
|
+
* @param seeds - Array of seeds (strings or byte arrays, max 16 seeds, each max 32 bytes)
|
|
250
|
+
* @param programId - The program that will own this PDA
|
|
251
|
+
* @returns The derived public key
|
|
252
|
+
* @throws {CryptoError} If seeds exceed limits or result is on curve
|
|
253
|
+
*
|
|
254
|
+
* @example
|
|
255
|
+
* ```typescript
|
|
256
|
+
* // With known bump seed (most efficient for verification)
|
|
257
|
+
* const pda = PublicKey.createProgramAddress(
|
|
258
|
+
* ["metadata", mintPubkey.toBytes(), new Uint8Array([254])],
|
|
259
|
+
* metadataProgramId
|
|
260
|
+
* );
|
|
261
|
+
* ```
|
|
262
|
+
*/
|
|
263
|
+
static createProgramAddress(seeds: Seed[], programId: PublicKey): PublicKey;
|
|
264
|
+
/**
|
|
265
|
+
* Finds a valid program derived address by searching for a bump seed.
|
|
266
|
+
*
|
|
267
|
+
* @remarks
|
|
268
|
+
* Iterates from bump 255 down to 0, returning the first combination that
|
|
269
|
+
* produces an address off the Ed25519 curve. The bump seed should be stored
|
|
270
|
+
* or passed to programs to allow efficient verification via {@link createProgramAddress}.
|
|
271
|
+
*
|
|
272
|
+
* @param seeds - Array of seeds (max 16 seeds, each max 32 bytes)
|
|
273
|
+
* @param programId - The program that will own this PDA
|
|
274
|
+
* @returns Tuple of [PublicKey, Bump] where bump is 0-255
|
|
275
|
+
* @throws {CryptoError} If no valid bump found (extremely rare) or seeds invalid
|
|
276
|
+
*
|
|
277
|
+
* @example
|
|
278
|
+
* ```typescript
|
|
279
|
+
* const [vaultPda, vaultBump] = PublicKey.findProgramAddress(
|
|
280
|
+
* ["vault", userPubkey.toBytes()],
|
|
281
|
+
* programId
|
|
282
|
+
* );
|
|
283
|
+
*
|
|
284
|
+
* // Store bump for later use
|
|
285
|
+
* console.log(`Vault: ${vaultPda}, Bump: ${vaultBump}`);
|
|
286
|
+
* ```
|
|
287
|
+
*/
|
|
288
|
+
static findProgramAddress(seeds: Seed[], programId: PublicKey): PDA;
|
|
289
|
+
/**
|
|
290
|
+
* Creates a derived address from a base address, seed string, and program ID.
|
|
291
|
+
*
|
|
292
|
+
* @remarks
|
|
293
|
+
* Unlike PDAs, this derivation CAN produce addresses on the curve.
|
|
294
|
+
* This is useful for creating deterministic addresses that a user can sign for,
|
|
295
|
+
* where the base address's private key holder can sign transactions.
|
|
296
|
+
*
|
|
297
|
+
* @param baseAddress - The base public key (signer)
|
|
298
|
+
* @param seed - A seed string (max 32 bytes when UTF-8 encoded)
|
|
299
|
+
* @param programId - The program that will own the derived account
|
|
300
|
+
* @returns The derived address
|
|
301
|
+
*
|
|
302
|
+
* @example
|
|
303
|
+
* ```typescript
|
|
304
|
+
* const derivedAddress = PublicKey.createWithSeed(
|
|
305
|
+
* userPubkey,
|
|
306
|
+
* "savings-account",
|
|
307
|
+
* systemProgramId
|
|
308
|
+
* );
|
|
309
|
+
* ```
|
|
310
|
+
*/
|
|
311
|
+
static createWithSeed(baseAddress: PublicKey, seed: string, programId: PublicKey): PublicKey;
|
|
312
|
+
/**
|
|
313
|
+
* Returns a copy of the raw bytes.
|
|
314
|
+
*/
|
|
315
|
+
toBytes(): Uint8Array;
|
|
316
|
+
/**
|
|
317
|
+
* Returns the base58-encoded string representation.
|
|
318
|
+
*/
|
|
319
|
+
toString(): string;
|
|
320
|
+
/**
|
|
321
|
+
* Checks equality with another public key using constant-time comparison.
|
|
322
|
+
*/
|
|
323
|
+
equals(other: PublicKey): boolean;
|
|
324
|
+
/**
|
|
325
|
+
* Verifies an Ed25519 signature over a message.
|
|
326
|
+
*
|
|
327
|
+
* @param message - Message bytes that were signed
|
|
328
|
+
* @param signature - Signature to verify
|
|
329
|
+
* @returns True if signature is valid, false otherwise
|
|
330
|
+
*
|
|
331
|
+
* @example
|
|
332
|
+
* ```typescript
|
|
333
|
+
* const message = new Uint8Array([1, 2, 3]);
|
|
334
|
+
* const signature = keypair.sign(message);
|
|
335
|
+
* const isValid = keypair.publicKey.verify(message, signature);
|
|
336
|
+
* ```
|
|
337
|
+
*/
|
|
338
|
+
verify(message: Uint8Array, signature: Signature): boolean;
|
|
339
|
+
/**
|
|
340
|
+
* Checks if the public key is on the Ed25519 curve.
|
|
341
|
+
*
|
|
342
|
+
* @returns True if the public key is on the curve, false otherwise
|
|
343
|
+
*/
|
|
344
|
+
isOnCurve(): boolean;
|
|
345
|
+
/**
|
|
346
|
+
* JSON serialization (returns base58 string).
|
|
347
|
+
*/
|
|
348
|
+
toJSON(): string;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Represents an Ed25519 keypair for signing transactions.
|
|
353
|
+
*
|
|
354
|
+
* Provides secure key generation, signing, and disposal capabilities.
|
|
355
|
+
* Call {@link dispose} when finished to securely erase the private key from memory.
|
|
356
|
+
*
|
|
357
|
+
* @example
|
|
358
|
+
* ```typescript
|
|
359
|
+
* // Generate random keypair
|
|
360
|
+
* const keypair = Keypair.generate();
|
|
361
|
+
*
|
|
362
|
+
* // Sign a message
|
|
363
|
+
* const message = new TextEncoder().encode("Hello");
|
|
364
|
+
* const signature = keypair.sign(message);
|
|
365
|
+
*
|
|
366
|
+
* // Verify signature
|
|
367
|
+
* const isValid = keypair.verify(message, signature);
|
|
368
|
+
*
|
|
369
|
+
* // Secure cleanup
|
|
370
|
+
* keypair.dispose();
|
|
371
|
+
* ```
|
|
372
|
+
*/
|
|
373
|
+
declare class Keypair {
|
|
374
|
+
readonly publicKey: PublicKey;
|
|
375
|
+
private secretKey;
|
|
376
|
+
private disposed;
|
|
377
|
+
private constructor();
|
|
378
|
+
/**
|
|
379
|
+
* Generates a random keypair using cryptographically secure randomness.
|
|
380
|
+
*/
|
|
381
|
+
static generate(): Keypair;
|
|
382
|
+
/**
|
|
383
|
+
* Creates a keypair from a 32-byte secret key.
|
|
384
|
+
* The public key will be derived from the secret key.
|
|
385
|
+
*
|
|
386
|
+
* @param secretKey - 32-byte Ed25519 secret key
|
|
387
|
+
*/
|
|
388
|
+
static fromSecretKey(secretKey: Uint8Array): Keypair;
|
|
389
|
+
/**
|
|
390
|
+
* Creates a keypair from a secret key and pre-computed public key.
|
|
391
|
+
*
|
|
392
|
+
* Use this for SLIP-0010/BIP32 derived keys where the public key
|
|
393
|
+
* should NOT be re-derived (compatibility with hierarchical derivation).
|
|
394
|
+
*
|
|
395
|
+
* @param secretKey - 32-byte Ed25519 secret key
|
|
396
|
+
* @param publicKey - 32-byte Ed25519 public key (pre-computed)
|
|
397
|
+
*/
|
|
398
|
+
static fromKeyPair(secretKey: Uint8Array, publicKey: Uint8Array): Keypair;
|
|
399
|
+
/**
|
|
400
|
+
* Signs a message with this keypair.
|
|
401
|
+
*
|
|
402
|
+
* @param message - Message bytes to sign
|
|
403
|
+
* @returns Ed25519 signature
|
|
404
|
+
* @throws {CryptoError} If keypair has been disposed
|
|
405
|
+
*/
|
|
406
|
+
sign(message: Uint8Array): Signature;
|
|
407
|
+
/**
|
|
408
|
+
* Verifies a signature against a message using this keypair's public key.
|
|
409
|
+
*
|
|
410
|
+
* @param message - Original message that was signed
|
|
411
|
+
* @param signature - Signature to verify
|
|
412
|
+
* @returns true if signature is valid
|
|
413
|
+
*/
|
|
414
|
+
verify(message: Uint8Array, signature: Signature): boolean;
|
|
415
|
+
/**
|
|
416
|
+
* Exports the secret key for storage.
|
|
417
|
+
*
|
|
418
|
+
* **WARNING**: Keep this secret! Never expose it in logs, APIs, or client-side code.
|
|
419
|
+
*
|
|
420
|
+
* @returns Copy of the 32-byte secret key
|
|
421
|
+
* @throws {CryptoError} If keypair has been disposed
|
|
422
|
+
*/
|
|
423
|
+
secretKeyBytes(): Uint8Array;
|
|
424
|
+
/**
|
|
425
|
+
* Checks if this keypair has been disposed.
|
|
426
|
+
*/
|
|
427
|
+
isDisposed(): boolean;
|
|
428
|
+
/**
|
|
429
|
+
* Securely erases the secret key from memory.
|
|
430
|
+
*
|
|
431
|
+
* After calling this method, the keypair can no longer be used for signing.
|
|
432
|
+
* This is important for security when the keypair is no longer needed.
|
|
433
|
+
*/
|
|
434
|
+
dispose(): void;
|
|
435
|
+
private ensureNotDisposed;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
type MnemonicStrength = 128 | 256;
|
|
439
|
+
/**
|
|
440
|
+
* Represents a validated BIP39 mnemonic phrase with SLIP-0010 Ed25519 hierarchical key derivation.
|
|
441
|
+
*
|
|
442
|
+
* Implements the SLIP-0010 standard for Ed25519 key derivation, ensuring compatibility
|
|
443
|
+
* with other implementations (e.g., Rust CDK). The default derivation path uses coin type
|
|
444
|
+
* 756 (R=7, L=5, O=6 on telephone keypad).
|
|
445
|
+
*
|
|
446
|
+
* @example
|
|
447
|
+
* ```typescript
|
|
448
|
+
* // Generate new mnemonic (12 or 24 words)
|
|
449
|
+
* const mnemonic = Mnemonic.generate(128); // 12 words
|
|
450
|
+
*
|
|
451
|
+
* // Restore from existing phrase
|
|
452
|
+
* const restored = Mnemonic.fromPhrase("word1 word2 ...");
|
|
453
|
+
*
|
|
454
|
+
* // Derive keypairs at specific account indices
|
|
455
|
+
* const keypair0 = await mnemonic.toKeypair(0); // m/44'/756'/0'/0'
|
|
456
|
+
* const keypair1 = await mnemonic.toKeypair(1); // m/44'/756'/1'/0'
|
|
457
|
+
*
|
|
458
|
+
* // With custom passphrase (BIP39 extension)
|
|
459
|
+
* const secure = await mnemonic.toKeypair(0, {
|
|
460
|
+
* passphrase: "my-secret"
|
|
461
|
+
* });
|
|
462
|
+
* ```
|
|
463
|
+
*
|
|
464
|
+
* @see {@link https://github.com/satoshilabs/slips/blob/master/slip-0010.md SLIP-0010 Specification}
|
|
465
|
+
*/
|
|
466
|
+
declare class Mnemonic {
|
|
467
|
+
private readonly phrase;
|
|
468
|
+
private constructor();
|
|
469
|
+
/**
|
|
470
|
+
* Generates a new random BIP39 mnemonic phrase.
|
|
471
|
+
*
|
|
472
|
+
* @param strength - Entropy strength (128 = 12 words, 256 = 24 words). Default: 128
|
|
473
|
+
* @returns Validated Mnemonic instance
|
|
474
|
+
*/
|
|
475
|
+
static generate(strength?: MnemonicStrength): Mnemonic;
|
|
476
|
+
/**
|
|
477
|
+
* Creates a Mnemonic from an existing phrase.
|
|
478
|
+
*
|
|
479
|
+
* @param phrase - BIP39 mnemonic phrase (12 or 24 space-separated words)
|
|
480
|
+
* @returns Validated Mnemonic instance
|
|
481
|
+
* @throws {CryptoError} If phrase is invalid (wrong words or checksum)
|
|
482
|
+
*/
|
|
483
|
+
static fromPhrase(phrase: string): Mnemonic;
|
|
484
|
+
/**
|
|
485
|
+
* Validates a phrase without creating an instance.
|
|
486
|
+
*
|
|
487
|
+
* Checks both word validity and BIP39 checksum.
|
|
488
|
+
*
|
|
489
|
+
* @param phrase - Mnemonic phrase to validate
|
|
490
|
+
* @returns true if phrase is valid
|
|
491
|
+
*/
|
|
492
|
+
static isValid(phrase: string): boolean;
|
|
493
|
+
private getMasterKeyFromSeed;
|
|
494
|
+
private deriveChildKey;
|
|
495
|
+
private derivePath;
|
|
496
|
+
/**
|
|
497
|
+
* Derives a keypair at a specific account index.
|
|
498
|
+
*
|
|
499
|
+
* Uses SLIP-0010 Ed25519 derivation with the default path:
|
|
500
|
+
* `m/44'/756'/{accountIndex}'/0'`
|
|
501
|
+
*
|
|
502
|
+
* Coin type 756 follows the telephone keypad convention (R=7, L=5, O=6).
|
|
503
|
+
*
|
|
504
|
+
* @param accountIndex - Account index to derive (default: 0)
|
|
505
|
+
* @param options - Derivation options
|
|
506
|
+
* @param options.passphrase - Optional BIP39 passphrase for additional security
|
|
507
|
+
* @param options.baseDerivationPath - Base path (default: "m/44'/756'")
|
|
508
|
+
* @returns Keypair for the derived account
|
|
509
|
+
*/
|
|
510
|
+
toKeypair(accountIndex?: number, options?: {
|
|
511
|
+
passphrase?: string;
|
|
512
|
+
baseDerivationPath?: string;
|
|
513
|
+
}): Promise<Keypair>;
|
|
514
|
+
/**
|
|
515
|
+
* Derives a keypair using an explicit full derivation path.
|
|
516
|
+
*
|
|
517
|
+
* @param fullPath - Complete derivation path (e.g., "m/44'/756'/0'/0'")
|
|
518
|
+
* @param passphrase - Optional BIP39 passphrase
|
|
519
|
+
*/
|
|
520
|
+
toKeypairWithPath(fullPath: string, passphrase?: string): Promise<Keypair>;
|
|
521
|
+
/**
|
|
522
|
+
* Derives multiple keypairs sequentially from this mnemonic.
|
|
523
|
+
*
|
|
524
|
+
* @param count - Number of keypairs to derive
|
|
525
|
+
* @param startIndex - Starting account index (default: 0)
|
|
526
|
+
* @param options - Derivation options (passphrase and path)
|
|
527
|
+
*/
|
|
528
|
+
deriveKeypairs(count: number, startIndex?: number, options?: {
|
|
529
|
+
passphrase?: string;
|
|
530
|
+
baseDerivationPath?: string;
|
|
531
|
+
}): Promise<Keypair[]>;
|
|
532
|
+
/**
|
|
533
|
+
* Converts the mnemonic to a BIP39 seed.
|
|
534
|
+
*
|
|
535
|
+
* @param passphrase - Optional BIP39 passphrase for additional security
|
|
536
|
+
* @returns 64-byte seed
|
|
537
|
+
*/
|
|
538
|
+
toSeed(passphrase?: string): Promise<Uint8Array>;
|
|
539
|
+
/**
|
|
540
|
+
* Returns the mnemonic phrase as a string.
|
|
541
|
+
*/
|
|
542
|
+
toString(): string;
|
|
543
|
+
/**
|
|
544
|
+
* Returns the individual words of the mnemonic.
|
|
545
|
+
*/
|
|
546
|
+
getWords(): string[];
|
|
547
|
+
/**
|
|
548
|
+
* Returns the word count (12 or 24).
|
|
549
|
+
*/
|
|
550
|
+
getWordCount(): 12 | 24;
|
|
551
|
+
/**
|
|
552
|
+
* Returns the entropy strength (128 or 256 bits).
|
|
553
|
+
*/
|
|
554
|
+
getStrength(): MnemonicStrength;
|
|
555
|
+
/**
|
|
556
|
+
* Checks equality with another mnemonic using constant-time comparison.
|
|
557
|
+
*/
|
|
558
|
+
equals(other: Mnemonic): boolean;
|
|
559
|
+
/**
|
|
560
|
+
* JSON serialization (returns the mnemonic phrase).
|
|
561
|
+
*/
|
|
562
|
+
toJSON(): string;
|
|
563
|
+
private buildFullPath;
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
/**
|
|
567
|
+
* Checks if a 32-byte array represents a valid point on the Ed25519 curve.
|
|
568
|
+
*
|
|
569
|
+
* This is used for PDA (Program Derived Address) derivation, where valid PDAs
|
|
570
|
+
* must NOT be on the curve to ensure they can only be signed by the program.
|
|
571
|
+
*
|
|
572
|
+
* @param bytes - 32-byte public key or hash to check
|
|
573
|
+
* @returns true if the bytes represent a valid Ed25519 point, false otherwise
|
|
574
|
+
*
|
|
575
|
+
* @example
|
|
576
|
+
* ```typescript
|
|
577
|
+
* const hash = sha256(data);
|
|
578
|
+
* if (!isOnCurve(hash)) {
|
|
579
|
+
* // Valid PDA - not on curve
|
|
580
|
+
* }
|
|
581
|
+
* ```
|
|
582
|
+
*/
|
|
583
|
+
declare function isOnCurve(bytes: Uint8Array): boolean;
|
|
584
|
+
/**
|
|
585
|
+
* Converts a seed to a 32-byte array.
|
|
586
|
+
*
|
|
587
|
+
* @param seed - Seed to convert
|
|
588
|
+
* @returns 32-byte array
|
|
589
|
+
*/
|
|
590
|
+
declare function seedToBytes(seed: Seed): Uint8Array;
|
|
591
|
+
/**
|
|
592
|
+
* Concatenates multiple byte arrays into a single byte array.
|
|
593
|
+
*
|
|
594
|
+
* @param arrays - Byte arrays to concatenate
|
|
595
|
+
* @returns Concatenated byte array
|
|
596
|
+
*/
|
|
597
|
+
declare function concatBytes(...arrays: Uint8Array[]): Uint8Array;
|
|
598
|
+
|
|
599
|
+
/**
|
|
600
|
+
* Error handling for the Rialo CDK.
|
|
601
|
+
*
|
|
602
|
+
* This module defines the common error types used throughout the Rialo CDK.
|
|
603
|
+
* It provides a centralized error handling mechanism for all operations.
|
|
604
|
+
*/
|
|
605
|
+
/**
|
|
606
|
+
* Structured RPC error information parsed from JSON-RPC error responses.
|
|
607
|
+
*/
|
|
608
|
+
interface RpcErrorDetails$1 {
|
|
609
|
+
/** HTTP status code (e.g., 200, 422, 500) */
|
|
610
|
+
status?: number;
|
|
611
|
+
/** JSON-RPC error code (e.g., -32002) */
|
|
612
|
+
code: number;
|
|
613
|
+
/** Human-readable error message */
|
|
614
|
+
message: string;
|
|
615
|
+
}
|
|
616
|
+
/**
|
|
617
|
+
* Error types for different subsystems in the Rialo CDK.
|
|
618
|
+
*/
|
|
619
|
+
declare enum RialoErrorType {
|
|
620
|
+
/** Errors related to file or system I/O operations */
|
|
621
|
+
IO = "IO",
|
|
622
|
+
/** Errors occurring during RPC communication with blockchain nodes */
|
|
623
|
+
RPC = "RPC",
|
|
624
|
+
/** Errors related to public key parsing or validation */
|
|
625
|
+
PARSE_PUBKEY = "PARSE_PUBKEY",
|
|
626
|
+
/** Errors related to blockhash parsing or validation */
|
|
627
|
+
INVALID_BLOCKHASH_FORMAT = "INVALID_BLOCKHASH_FORMAT",
|
|
628
|
+
/** Errors related to wallet operations such as creation, loading, or signing */
|
|
629
|
+
WALLET = "WALLET",
|
|
630
|
+
/** Errors related to configuration loading, parsing, or validation */
|
|
631
|
+
CONFIG = "CONFIG",
|
|
632
|
+
/** Errors occurring during transaction building, signing, or submission */
|
|
633
|
+
TRANSACTION = "TRANSACTION",
|
|
634
|
+
/** Network-related errors, including HTTP client errors */
|
|
635
|
+
NETWORK = "NETWORK",
|
|
636
|
+
/** Errors related to password handling, validation, or verification */
|
|
637
|
+
PASSWORD = "PASSWORD",
|
|
638
|
+
/** Errors related to encryption or decryption operations */
|
|
639
|
+
ENCRYPTION = "ENCRYPTION",
|
|
640
|
+
/** Errors occurring during JSON parsing, serialization, or deserialization */
|
|
641
|
+
JSON = "JSON",
|
|
642
|
+
/** Errors related to BIP32 key derivation */
|
|
643
|
+
BIP32 = "BIP32",
|
|
644
|
+
/** Errors related to invalid input parameters or data */
|
|
645
|
+
INVALID_INPUT = "INVALID_INPUT",
|
|
646
|
+
/** Errors related to serialization/deserialization */
|
|
647
|
+
SERIALIZATION = "SERIALIZATION"
|
|
648
|
+
}
|
|
649
|
+
/**
|
|
650
|
+
* Base error class for all Rialo CDK errors.
|
|
651
|
+
*
|
|
652
|
+
* Provides structured error handling with type categorization and optional
|
|
653
|
+
* cause tracking for error chains. Use the static factory methods for
|
|
654
|
+
* consistent error creation across the SDK.
|
|
655
|
+
*
|
|
656
|
+
* @example
|
|
657
|
+
* ```typescript
|
|
658
|
+
* // Create typed errors using factory methods
|
|
659
|
+
* throw RialoError.invalidInput("Amount must be positive");
|
|
660
|
+
* throw RialoError.network("Connection failed", originalError);
|
|
661
|
+
* throw RialoError.rpc({ code: -32002, message: "Invalid params" });
|
|
662
|
+
*
|
|
663
|
+
* // Handle errors with type information
|
|
664
|
+
* try {
|
|
665
|
+
* await client.sendTransaction(tx);
|
|
666
|
+
* } catch (error) {
|
|
667
|
+
* if (error instanceof RialoError && error.type === RialoErrorType.NETWORK) {
|
|
668
|
+
* console.log("Network error, retrying...");
|
|
669
|
+
* }
|
|
670
|
+
* }
|
|
671
|
+
* ```
|
|
672
|
+
*/
|
|
673
|
+
declare class RialoError extends Error {
|
|
674
|
+
readonly type: RialoErrorType;
|
|
675
|
+
readonly cause?: Error;
|
|
676
|
+
readonly details?: RpcErrorDetails$1;
|
|
677
|
+
constructor(type: RialoErrorType, message: string, cause?: Error, details?: RpcErrorDetails$1);
|
|
678
|
+
/**
|
|
679
|
+
* Creates an IO error.
|
|
680
|
+
*/
|
|
681
|
+
static io(message: string, cause?: Error): RialoError;
|
|
682
|
+
/**
|
|
683
|
+
* Creates an RPC error.
|
|
684
|
+
*/
|
|
685
|
+
static rpc(details: RpcErrorDetails$1): RialoError;
|
|
686
|
+
/**
|
|
687
|
+
* Creates a public key parsing error.
|
|
688
|
+
*/
|
|
689
|
+
static parsePubkey(message: string): RialoError;
|
|
690
|
+
/**
|
|
691
|
+
* Creates a blockhash format error.
|
|
692
|
+
*/
|
|
693
|
+
static invalidBlockhash(message: string): RialoError;
|
|
694
|
+
/**
|
|
695
|
+
* Creates a wallet error.
|
|
696
|
+
*/
|
|
697
|
+
static wallet(message: string): RialoError;
|
|
698
|
+
/**
|
|
699
|
+
* Creates a configuration error.
|
|
700
|
+
*/
|
|
701
|
+
static config(message: string): RialoError;
|
|
702
|
+
/**
|
|
703
|
+
* Creates a transaction error.
|
|
704
|
+
*/
|
|
705
|
+
static transaction(message: string): RialoError;
|
|
706
|
+
/**
|
|
707
|
+
* Creates a network error.
|
|
708
|
+
*/
|
|
709
|
+
static network(message: string, cause?: Error): RialoError;
|
|
710
|
+
/**
|
|
711
|
+
* Creates a password error.
|
|
712
|
+
*/
|
|
713
|
+
static password(message: string): RialoError;
|
|
714
|
+
/**
|
|
715
|
+
* Creates an encryption error.
|
|
716
|
+
*/
|
|
717
|
+
static encryption(message: string): RialoError;
|
|
718
|
+
/**
|
|
719
|
+
* Creates a JSON error.
|
|
720
|
+
*/
|
|
721
|
+
static json(message: string, cause?: Error): RialoError;
|
|
722
|
+
/**
|
|
723
|
+
* Creates a BIP32 error.
|
|
724
|
+
*/
|
|
725
|
+
static bip32(message: string): RialoError;
|
|
726
|
+
/**
|
|
727
|
+
* Creates an invalid input error.
|
|
728
|
+
*/
|
|
729
|
+
static invalidInput(message: string): RialoError;
|
|
730
|
+
/**
|
|
731
|
+
* Creates a serialization error.
|
|
732
|
+
*/
|
|
733
|
+
static serialization(message: string): RialoError;
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
/**
|
|
737
|
+
* Base client with JSON-RPC protocol handling.
|
|
738
|
+
*
|
|
739
|
+
* All specific clients (QueryClient, TransactionClient) extend this.
|
|
740
|
+
*/
|
|
741
|
+
declare class BaseRpcClient {
|
|
742
|
+
protected readonly transport: HttpTransport;
|
|
743
|
+
private requestId;
|
|
744
|
+
constructor(transport: HttpTransport);
|
|
745
|
+
/**
|
|
746
|
+
* Makes a JSON-RPC 2.0 method call with type safety.
|
|
747
|
+
*
|
|
748
|
+
* Handles request serialization, response validation, and error mapping.
|
|
749
|
+
*/
|
|
750
|
+
protected call<T>(method: string, params?: unknown[]): Promise<T>;
|
|
751
|
+
/**
|
|
752
|
+
* Validate JSON-RPC response structure
|
|
753
|
+
*/
|
|
754
|
+
private isValidJsonRpcResponse;
|
|
755
|
+
/**
|
|
756
|
+
* Generates the next request ID with Overflow Protection.
|
|
757
|
+
* @returns The next request ID.
|
|
758
|
+
*/
|
|
759
|
+
private nextRequestId;
|
|
760
|
+
/**
|
|
761
|
+
* Returns the configured RPC endpoint URL.
|
|
762
|
+
*/
|
|
763
|
+
getUrl(): string;
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
/**
|
|
767
|
+
* RPC type definitions for the Rialo blockchain.
|
|
768
|
+
*/
|
|
769
|
+
|
|
770
|
+
/**
|
|
771
|
+
* Account information response.
|
|
772
|
+
*/
|
|
773
|
+
interface AccountInfo {
|
|
774
|
+
/** Account balance in smallest denomination */
|
|
775
|
+
balance: bigint;
|
|
776
|
+
/** Owner program public key */
|
|
777
|
+
owner: PublicKey;
|
|
778
|
+
/** Account data */
|
|
779
|
+
data: Uint8Array;
|
|
780
|
+
/** Whether the account is executable */
|
|
781
|
+
executable: boolean;
|
|
782
|
+
/** Rent epoch */
|
|
783
|
+
rentEpoch: bigint;
|
|
784
|
+
}
|
|
785
|
+
/**
|
|
786
|
+
* Transaction response.
|
|
787
|
+
*/
|
|
788
|
+
interface TransactionResponse {
|
|
789
|
+
/** Transaction signature */
|
|
790
|
+
signature: string;
|
|
791
|
+
/** Block height */
|
|
792
|
+
blockHeight?: bigint;
|
|
793
|
+
/** Error message if transaction failed */
|
|
794
|
+
err?: string;
|
|
795
|
+
}
|
|
796
|
+
/**
|
|
797
|
+
* Options for sending a transaction.
|
|
798
|
+
*/
|
|
799
|
+
interface SendTransactionOptions {
|
|
800
|
+
/** Skip preflight transaction checks */
|
|
801
|
+
skipPreflight?: boolean;
|
|
802
|
+
/** Maximum number of times to retry */
|
|
803
|
+
maxRetries?: number;
|
|
804
|
+
}
|
|
805
|
+
/**
|
|
806
|
+
* Epoch information response.
|
|
807
|
+
*/
|
|
808
|
+
interface EpochInfoResponse {
|
|
809
|
+
/** Current epoch */
|
|
810
|
+
epoch: bigint;
|
|
811
|
+
/** Current slot in the epoch */
|
|
812
|
+
slotIndex: bigint;
|
|
813
|
+
/** Total slots in the epoch */
|
|
814
|
+
slotsInEpoch: bigint;
|
|
815
|
+
/** Absolute slot number */
|
|
816
|
+
absoluteSlot: bigint;
|
|
817
|
+
/** Block height */
|
|
818
|
+
blockHeight: bigint;
|
|
819
|
+
/** Transaction count */
|
|
820
|
+
transactionCount?: bigint;
|
|
821
|
+
}
|
|
822
|
+
/**
|
|
823
|
+
* Subscription kind.
|
|
824
|
+
*/
|
|
825
|
+
type SubscriptionKind = "Persistent" | "OneShot";
|
|
826
|
+
/**
|
|
827
|
+
* Subscription data.
|
|
828
|
+
*/
|
|
829
|
+
interface Subscription {
|
|
830
|
+
/** Type of subscription */
|
|
831
|
+
kind: SubscriptionKind;
|
|
832
|
+
/** Topic for the subscription */
|
|
833
|
+
topic: string;
|
|
834
|
+
/** Instructions to execute when triggered */
|
|
835
|
+
instructions: unknown[];
|
|
836
|
+
/** Subscriber public key (base58) */
|
|
837
|
+
subscriber: string;
|
|
838
|
+
/** Event account public key (base58) */
|
|
839
|
+
eventAccount?: string;
|
|
840
|
+
/** Timestamp range [start, end] */
|
|
841
|
+
timestampRange?: [bigint, bigint];
|
|
842
|
+
}
|
|
843
|
+
/**
|
|
844
|
+
* Triggered transaction data.
|
|
845
|
+
*/
|
|
846
|
+
interface TriggeredTransaction {
|
|
847
|
+
/** Transaction signature (base58) */
|
|
848
|
+
signature: string;
|
|
849
|
+
/** Block number where the transaction was executed */
|
|
850
|
+
blockNumber: bigint;
|
|
851
|
+
}
|
|
852
|
+
/**
|
|
853
|
+
* Get workflow lineage request.
|
|
854
|
+
*/
|
|
855
|
+
interface GetWorkflowLineageRequest {
|
|
856
|
+
/** Root transaction signature (base58) */
|
|
857
|
+
signature: string;
|
|
858
|
+
/** Maximum depth to traverse (1-100, default 3) */
|
|
859
|
+
maxDepth?: number;
|
|
860
|
+
/** Whether to include event details */
|
|
861
|
+
includeEvents?: boolean;
|
|
862
|
+
}
|
|
863
|
+
/**
|
|
864
|
+
* Event data from a workflow trigger.
|
|
865
|
+
*/
|
|
866
|
+
interface EventData {
|
|
867
|
+
/** Event topic */
|
|
868
|
+
topic: string;
|
|
869
|
+
/** Event attributes */
|
|
870
|
+
attributes: Record<string, unknown>;
|
|
871
|
+
}
|
|
872
|
+
/**
|
|
873
|
+
* Timestamp range.
|
|
874
|
+
*/
|
|
875
|
+
interface TimestampRange {
|
|
876
|
+
/** Start timestamp (unix) */
|
|
877
|
+
from: bigint;
|
|
878
|
+
/** End timestamp (unix) */
|
|
879
|
+
to: bigint;
|
|
880
|
+
}
|
|
881
|
+
/**
|
|
882
|
+
* Information about what triggered a workflow transaction.
|
|
883
|
+
*/
|
|
884
|
+
interface TriggerInfo {
|
|
885
|
+
/** Event that triggered the transaction */
|
|
886
|
+
event: EventData;
|
|
887
|
+
/** Subscription public key (base58) */
|
|
888
|
+
subscriptionPubkey: string;
|
|
889
|
+
/** Timestamp range for the trigger */
|
|
890
|
+
timestampRange?: TimestampRange;
|
|
891
|
+
/** Event account public key (base58) */
|
|
892
|
+
eventAccount?: string;
|
|
893
|
+
}
|
|
894
|
+
/**
|
|
895
|
+
* Transaction node data within a workflow.
|
|
896
|
+
*/
|
|
897
|
+
interface TransactionNodeData {
|
|
898
|
+
/** Block height */
|
|
899
|
+
blockHeight: bigint;
|
|
900
|
+
/** Timestamp (unix) */
|
|
901
|
+
timestamp: bigint;
|
|
902
|
+
/** Whether the transaction succeeded */
|
|
903
|
+
success: boolean;
|
|
904
|
+
/** Number of instructions */
|
|
905
|
+
instructionCount: number;
|
|
906
|
+
/** Program IDs of instructions (base58) */
|
|
907
|
+
instructionProgramIds: string[];
|
|
908
|
+
}
|
|
909
|
+
/**
|
|
910
|
+
* A node in the workflow lineage tree.
|
|
911
|
+
*/
|
|
912
|
+
interface WorkflowNode {
|
|
913
|
+
/** Transaction signature (base58) */
|
|
914
|
+
id: string;
|
|
915
|
+
/** Distance from root transaction */
|
|
916
|
+
depth: number;
|
|
917
|
+
/** Transaction data */
|
|
918
|
+
data: TransactionNodeData;
|
|
919
|
+
/** Subscriptions on this transaction */
|
|
920
|
+
subscriptions: Subscription[];
|
|
921
|
+
/** What triggered this transaction */
|
|
922
|
+
triggeredBy?: TriggerInfo;
|
|
923
|
+
/** Child transaction signatures (base58) */
|
|
924
|
+
workflowChildren: string[];
|
|
925
|
+
/** Whether there are more children not shown */
|
|
926
|
+
hasMoreChildren: boolean;
|
|
927
|
+
}
|
|
928
|
+
/**
|
|
929
|
+
* Workflow lineage tree.
|
|
930
|
+
*/
|
|
931
|
+
interface WorkflowLineage {
|
|
932
|
+
/** Nodes in the workflow tree */
|
|
933
|
+
workflowNodes: WorkflowNode[];
|
|
934
|
+
}
|
|
935
|
+
/**
|
|
936
|
+
* Reason for truncating workflow lineage traversal.
|
|
937
|
+
*/
|
|
938
|
+
type TruncationReason = "MaxDepth" | "MaxNodes" | "None";
|
|
939
|
+
/**
|
|
940
|
+
* Get workflow lineage response.
|
|
941
|
+
*/
|
|
942
|
+
interface GetWorkflowLineageResponse {
|
|
943
|
+
/** Workflow lineage tree */
|
|
944
|
+
lineage: WorkflowLineage;
|
|
945
|
+
/** Leaf transaction signatures (base58) */
|
|
946
|
+
leaves: string[];
|
|
947
|
+
/** Whether traversal was truncated */
|
|
948
|
+
truncated: boolean;
|
|
949
|
+
/** Reason for truncation */
|
|
950
|
+
truncationReason: TruncationReason;
|
|
951
|
+
/** Hints for continuing traversal (base58 signatures) */
|
|
952
|
+
continuationHints: string[];
|
|
953
|
+
}
|
|
954
|
+
/**
|
|
955
|
+
* Get signatures for address configuration.
|
|
956
|
+
*/
|
|
957
|
+
interface GetSignaturesForAddressConfig {
|
|
958
|
+
/** Maximum number of signatures to return */
|
|
959
|
+
limit?: number;
|
|
960
|
+
/** Start searching backwards from this signature */
|
|
961
|
+
before?: string;
|
|
962
|
+
/** Start searching forwards from this signature */
|
|
963
|
+
until?: string;
|
|
964
|
+
}
|
|
965
|
+
/**
|
|
966
|
+
* Signature information.
|
|
967
|
+
*/
|
|
968
|
+
interface SignatureInfo {
|
|
969
|
+
signature: string;
|
|
970
|
+
blockHeight: bigint;
|
|
971
|
+
blockTime: bigint;
|
|
972
|
+
err?: string;
|
|
973
|
+
}
|
|
974
|
+
/**
|
|
975
|
+
* Get health response.
|
|
976
|
+
*/
|
|
977
|
+
type GetHealthResponse = "ok" | string;
|
|
978
|
+
/**
|
|
979
|
+
* Get transactions response.
|
|
980
|
+
*/
|
|
981
|
+
interface GetTransactionsResponse {
|
|
982
|
+
/** Array of transaction data */
|
|
983
|
+
transactions: Array<Record<string, unknown>>;
|
|
984
|
+
}
|
|
985
|
+
/**
|
|
986
|
+
* Signature status from the RPC.
|
|
987
|
+
*/
|
|
988
|
+
interface SignatureStatus {
|
|
989
|
+
/** Slot in which the transaction was processed */
|
|
990
|
+
slot: bigint;
|
|
991
|
+
/** Whether the transaction has been executed */
|
|
992
|
+
executed: boolean;
|
|
993
|
+
/** Error message if transaction failed */
|
|
994
|
+
err?: string;
|
|
995
|
+
}
|
|
996
|
+
/**
|
|
997
|
+
* Options for confirming a transaction.
|
|
998
|
+
*/
|
|
999
|
+
interface ConfirmTransactionOptions {
|
|
1000
|
+
/** Maximum number of retry attempts (default: 30) */
|
|
1001
|
+
maxRetries?: number;
|
|
1002
|
+
/** Delay between retries in milliseconds (default: 1000) */
|
|
1003
|
+
retryDelay?: number;
|
|
1004
|
+
}
|
|
1005
|
+
/**
|
|
1006
|
+
* Options for sending and confirming a transaction.
|
|
1007
|
+
*/
|
|
1008
|
+
interface SendAndConfirmOptions extends SendTransactionOptions, ConfirmTransactionOptions {
|
|
1009
|
+
}
|
|
1010
|
+
/**
|
|
1011
|
+
* Result of a confirmed transaction.
|
|
1012
|
+
*/
|
|
1013
|
+
interface ConfirmedTransaction {
|
|
1014
|
+
/** Transaction signature */
|
|
1015
|
+
signature: string;
|
|
1016
|
+
/** Whether the transaction was executed */
|
|
1017
|
+
executed: boolean;
|
|
1018
|
+
/** Error message if transaction failed */
|
|
1019
|
+
err?: string;
|
|
1020
|
+
}
|
|
1021
|
+
/**
|
|
1022
|
+
* Configuration for getAccountsByOwner.
|
|
1023
|
+
*/
|
|
1024
|
+
interface GetAccountsByOwnerConfig {
|
|
1025
|
+
/** Maximum number of accounts to return */
|
|
1026
|
+
limit?: number;
|
|
1027
|
+
/** Cursor for pagination (base58 pubkey) */
|
|
1028
|
+
after?: string;
|
|
1029
|
+
}
|
|
1030
|
+
/**
|
|
1031
|
+
* Filter for getAccountsByOwner.
|
|
1032
|
+
* Matches Rust serde serialization format.
|
|
1033
|
+
*/
|
|
1034
|
+
type AccountFilter = {
|
|
1035
|
+
type: "programAccounts";
|
|
1036
|
+
} | {
|
|
1037
|
+
type: "tokenAccounts";
|
|
1038
|
+
mint?: string;
|
|
1039
|
+
};
|
|
1040
|
+
/**
|
|
1041
|
+
* An account owned by a program or address.
|
|
1042
|
+
*/
|
|
1043
|
+
interface OwnerAccount {
|
|
1044
|
+
/** Account public key */
|
|
1045
|
+
pubkey: PublicKey;
|
|
1046
|
+
/** Account information */
|
|
1047
|
+
account: AccountInfo;
|
|
1048
|
+
}
|
|
1049
|
+
/**
|
|
1050
|
+
* Pagination information.
|
|
1051
|
+
*/
|
|
1052
|
+
interface PaginationInfo {
|
|
1053
|
+
/** Whether there are more results */
|
|
1054
|
+
hasMore: boolean;
|
|
1055
|
+
/** Cursor for next page (base58 pubkey) */
|
|
1056
|
+
nextCursor?: string;
|
|
1057
|
+
}
|
|
1058
|
+
/**
|
|
1059
|
+
* Get accounts by owner response.
|
|
1060
|
+
*/
|
|
1061
|
+
interface GetAccountsByOwnerResponse {
|
|
1062
|
+
/** Array of owned accounts */
|
|
1063
|
+
value: OwnerAccount[];
|
|
1064
|
+
/** Pagination information */
|
|
1065
|
+
pagination?: PaginationInfo;
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
/**
|
|
1069
|
+
* Main Rialo RPC client for blockchain interactions.
|
|
1070
|
+
*/
|
|
1071
|
+
|
|
1072
|
+
/**
|
|
1073
|
+
* High-level Rialo RPC client for blockchain interactions.
|
|
1074
|
+
*
|
|
1075
|
+
* Provides a unified interface for querying blockchain state and
|
|
1076
|
+
* sending transactions. Internally delegates to specialized clients
|
|
1077
|
+
* (QueryRpcClient, TransactionRpcClient) for modular organization.
|
|
1078
|
+
*
|
|
1079
|
+
* @example
|
|
1080
|
+
* ```typescript
|
|
1081
|
+
* import { createRialoClient, RIALO_DEVNET_CHAIN } from '@rialo/ts-cdk';
|
|
1082
|
+
*
|
|
1083
|
+
* const client = createRialoClient({ chain: RIALO_DEVNET_CHAIN });
|
|
1084
|
+
*
|
|
1085
|
+
* // Query operations
|
|
1086
|
+
* const balance = await client.getBalance(publicKey);
|
|
1087
|
+
* const chainId = client.getChainIdentifier();
|
|
1088
|
+
*
|
|
1089
|
+
* // Transaction operations
|
|
1090
|
+
* const signature = await client.sendTransaction(signedTx);
|
|
1091
|
+
* ```
|
|
1092
|
+
*/
|
|
1093
|
+
declare class RialoClient {
|
|
1094
|
+
private readonly queryClient;
|
|
1095
|
+
private readonly transactionClient;
|
|
1096
|
+
private readonly transport;
|
|
1097
|
+
private readonly chain;
|
|
1098
|
+
constructor(transport: HttpTransport, chain: ChainDefinition);
|
|
1099
|
+
/**
|
|
1100
|
+
* Returns the configured RPC endpoint URL.
|
|
1101
|
+
*/
|
|
1102
|
+
getUrl(): string;
|
|
1103
|
+
/**
|
|
1104
|
+
* Returns the chain identifier.
|
|
1105
|
+
*/
|
|
1106
|
+
getChainIdentifier(): IdentifierString;
|
|
1107
|
+
/**
|
|
1108
|
+
* Returns the chain configuration.
|
|
1109
|
+
*/
|
|
1110
|
+
getChainConfig(): ChainDefinition;
|
|
1111
|
+
/**
|
|
1112
|
+
* Retrieves the balance of an account in kelvins (smallest unit).
|
|
1113
|
+
*/
|
|
1114
|
+
getBalance(pubkey: PublicKey): Promise<bigint>;
|
|
1115
|
+
/**
|
|
1116
|
+
* Retrieves detailed information about an account.
|
|
1117
|
+
*
|
|
1118
|
+
* @returns Account info or null if account doesn't exist
|
|
1119
|
+
*/
|
|
1120
|
+
getAccountInfo(pubkey: PublicKey): Promise<AccountInfo | null>;
|
|
1121
|
+
/**
|
|
1122
|
+
* Retrieves the current block height.
|
|
1123
|
+
*/
|
|
1124
|
+
getBlockHeight(): Promise<bigint>;
|
|
1125
|
+
/**
|
|
1126
|
+
* Retrieves the signatures for an address.
|
|
1127
|
+
*/
|
|
1128
|
+
getSignaturesForAddress(address: PublicKey, config?: GetSignaturesForAddressConfig): Promise<SignatureInfo[]>;
|
|
1129
|
+
/**
|
|
1130
|
+
* Retrieves detailed information about a transaction.
|
|
1131
|
+
*
|
|
1132
|
+
* @returns Transaction info or null if transaction not found
|
|
1133
|
+
*/
|
|
1134
|
+
getTransaction(signature: string): Promise<TransactionResponse | null>;
|
|
1135
|
+
/**
|
|
1136
|
+
* Retrieves the total number of transactions processed since genesis.
|
|
1137
|
+
*/
|
|
1138
|
+
getTransactionCount(): Promise<bigint>;
|
|
1139
|
+
/**
|
|
1140
|
+
* Retrieves the status of multiple transaction signatures.
|
|
1141
|
+
*/
|
|
1142
|
+
getSignatureStatuses(signatures: string[]): Promise<(SignatureStatus | null)[]>;
|
|
1143
|
+
/**
|
|
1144
|
+
* Retrieves current epoch information.
|
|
1145
|
+
*/
|
|
1146
|
+
getEpochInfo(): Promise<EpochInfoResponse>;
|
|
1147
|
+
/**
|
|
1148
|
+
* Checks the health status of the RPC node.
|
|
1149
|
+
*
|
|
1150
|
+
* @returns "ok" if healthy, error message otherwise
|
|
1151
|
+
*/
|
|
1152
|
+
getHealth(): Promise<"ok" | string>;
|
|
1153
|
+
/**
|
|
1154
|
+
* Submits a signed transaction to the blockchain.
|
|
1155
|
+
*
|
|
1156
|
+
* @param transaction - Serialized signed transaction bytes
|
|
1157
|
+
* @param options - Transaction submission options
|
|
1158
|
+
* @returns Transaction signature
|
|
1159
|
+
*/
|
|
1160
|
+
sendTransaction(transaction: Uint8Array, options?: SendTransactionOptions): Promise<string>;
|
|
1161
|
+
/**
|
|
1162
|
+
* Requests an airdrop of tokens to an account.
|
|
1163
|
+
*
|
|
1164
|
+
* **Note**: Only available on devnet and testnet.
|
|
1165
|
+
*
|
|
1166
|
+
* @param pubkey - Account to receive the airdrop
|
|
1167
|
+
* @param amount - Amount in kelvins (smallest unit)
|
|
1168
|
+
* @returns Transaction signature
|
|
1169
|
+
*/
|
|
1170
|
+
requestAirdrop(pubkey: PublicKey, amount: bigint): Promise<string>;
|
|
1171
|
+
/**
|
|
1172
|
+
* Submits a signed transaction and waits for confirmation.
|
|
1173
|
+
*
|
|
1174
|
+
* @param transaction - Serialized signed transaction bytes
|
|
1175
|
+
* @param options - Transaction submission and confirmation options
|
|
1176
|
+
* @returns Confirmed transaction details
|
|
1177
|
+
* @throws {TransactionFailedError} If the transaction fails on-chain
|
|
1178
|
+
* @throws {TransactionConfirmationTimeoutError} If confirmation times out
|
|
1179
|
+
*
|
|
1180
|
+
* @example
|
|
1181
|
+
* ```typescript
|
|
1182
|
+
* const result = await client.sendAndConfirmTransaction(signedTx);
|
|
1183
|
+
* console.log(`Confirmed in slot ${result.slot}`);
|
|
1184
|
+
* ```
|
|
1185
|
+
*/
|
|
1186
|
+
sendAndConfirmTransaction(transaction: Uint8Array, options?: SendAndConfirmOptions): Promise<ConfirmedTransaction>;
|
|
1187
|
+
/**
|
|
1188
|
+
* Waits for a transaction to be confirmed.
|
|
1189
|
+
*
|
|
1190
|
+
* @param signature - Transaction signature to monitor
|
|
1191
|
+
* @param options - Confirmation options
|
|
1192
|
+
* @returns Confirmed transaction details
|
|
1193
|
+
*/
|
|
1194
|
+
confirmTransaction(signature: string, options?: ConfirmTransactionOptions): Promise<ConfirmedTransaction>;
|
|
1195
|
+
/**
|
|
1196
|
+
* Requests an airdrop and waits for confirmation.
|
|
1197
|
+
*
|
|
1198
|
+
* **Note**: Only available on devnet and testnet.
|
|
1199
|
+
*/
|
|
1200
|
+
requestAirdropAndConfirm(pubkey: PublicKey, amount: bigint, options?: ConfirmTransactionOptions): Promise<ConfirmedTransaction>;
|
|
1201
|
+
/**
|
|
1202
|
+
* Calculate the minimum balance required for an account to be rent-exempt.
|
|
1203
|
+
*
|
|
1204
|
+
* @param accountDataSize - The size of the account data in bytes
|
|
1205
|
+
* @returns The minimum balance in kelvins required for rent exemption
|
|
1206
|
+
*/
|
|
1207
|
+
getMinimumBalanceForRentExemption(accountDataSize: number): Promise<bigint>;
|
|
1208
|
+
/**
|
|
1209
|
+
* Get the fee required to process a specific message.
|
|
1210
|
+
*
|
|
1211
|
+
* @param message - Base64-encoded serialized versioned message
|
|
1212
|
+
* @returns Fee in kelvins, or null if message is invalid
|
|
1213
|
+
*/
|
|
1214
|
+
getFeeForMessage(message: string): Promise<bigint | null>;
|
|
1215
|
+
/**
|
|
1216
|
+
* Get information for multiple accounts in a single request.
|
|
1217
|
+
*
|
|
1218
|
+
* @param pubkeys - Array of public keys to query (1-100)
|
|
1219
|
+
* @returns Account information for each address
|
|
1220
|
+
*/
|
|
1221
|
+
getMultipleAccounts(pubkeys: PublicKey[]): Promise<Array<AccountInfo | null>>;
|
|
1222
|
+
/**
|
|
1223
|
+
* Get all accounts owned by a specific program or address.
|
|
1224
|
+
*
|
|
1225
|
+
* @param owner - Program ID or owner public key
|
|
1226
|
+
* @param filter - Filter type (ProgramAccounts or TokenAccounts)
|
|
1227
|
+
* @param config - Optional configuration for pagination and encoding
|
|
1228
|
+
* @returns Accounts owned by the specified owner
|
|
1229
|
+
*/
|
|
1230
|
+
getAccountsByOwner(owner: PublicKey, filter?: AccountFilter, config?: GetAccountsByOwnerConfig): Promise<GetAccountsByOwnerResponse>;
|
|
1231
|
+
/**
|
|
1232
|
+
* Get workflow lineage information for tracking execution history.
|
|
1233
|
+
*
|
|
1234
|
+
* @param request - Workflow lineage request with signature and options
|
|
1235
|
+
* @returns Workflow lineage tree with nodes and metadata
|
|
1236
|
+
*/
|
|
1237
|
+
getWorkflowLineage(request: GetWorkflowLineageRequest): Promise<GetWorkflowLineageResponse>;
|
|
1238
|
+
/**
|
|
1239
|
+
* Get subscription for a given subscriber address and nonce.
|
|
1240
|
+
*
|
|
1241
|
+
* @param subscriber - The subscriber's public key
|
|
1242
|
+
* @param nonce - The nonce identifying the subscription
|
|
1243
|
+
* @returns The subscription for the subscriber and nonce
|
|
1244
|
+
*/
|
|
1245
|
+
getSubscription(subscriber: PublicKey, nonce: string): Promise<Subscription>;
|
|
1246
|
+
/**
|
|
1247
|
+
* Get transactions triggered by a subscription account.
|
|
1248
|
+
*
|
|
1249
|
+
* @param subscriptionAccount - The subscription account public key
|
|
1250
|
+
* @param limit - Optional limit on transactions returned
|
|
1251
|
+
* @returns Triggered transactions for the subscription
|
|
1252
|
+
*/
|
|
1253
|
+
getTriggeredTransactions(subscriptionAccount: PublicKey, limit?: number): Promise<TriggeredTransaction[]>;
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1256
|
+
/**
|
|
1257
|
+
* Query client for read-only RPC operations.
|
|
1258
|
+
*/
|
|
1259
|
+
|
|
1260
|
+
/**
|
|
1261
|
+
* Client for querying blockchain state.
|
|
1262
|
+
*
|
|
1263
|
+
* Handles all read-only operations like getting balances, account info, etc.
|
|
1264
|
+
*/
|
|
1265
|
+
declare class QueryRpcClient extends BaseRpcClient {
|
|
1266
|
+
/**
|
|
1267
|
+
* Retrieve the balance of an account in kelvins (smallest unit).
|
|
1268
|
+
*
|
|
1269
|
+
* @param pubkey - The public key of the account to query
|
|
1270
|
+
* @returns The account balance in kelvins
|
|
1271
|
+
*
|
|
1272
|
+
* @example
|
|
1273
|
+
* ```typescript
|
|
1274
|
+
* const balance = await client.getBalance(publicKey);
|
|
1275
|
+
* console.log(`Balance: ${balance} kelvins`);
|
|
1276
|
+
* ```
|
|
1277
|
+
*/
|
|
1278
|
+
getBalance(pubkey: PublicKey): Promise<bigint>;
|
|
1279
|
+
/**
|
|
1280
|
+
* Retrieve detailed information about an account.
|
|
1281
|
+
*
|
|
1282
|
+
* Returns account data including balance, owner program, stored data,
|
|
1283
|
+
* executable status, and rent epoch.
|
|
1284
|
+
*
|
|
1285
|
+
* @param pubkey - The public key of the account to query
|
|
1286
|
+
* @returns Account information, or null if the account does not exist
|
|
1287
|
+
*
|
|
1288
|
+
* @example
|
|
1289
|
+
* ```typescript
|
|
1290
|
+
* const info = await client.getAccountInfo(publicKey);
|
|
1291
|
+
* if (info) {
|
|
1292
|
+
* console.log(`Owner: ${info.owner}`);
|
|
1293
|
+
* console.log(`Balance: ${info.balance} kelvins`);
|
|
1294
|
+
* console.log(`Data length: ${info.data.length} bytes`);
|
|
1295
|
+
* }
|
|
1296
|
+
* ```
|
|
1297
|
+
*/
|
|
1298
|
+
getAccountInfo(pubkey: PublicKey): Promise<AccountInfo | null>;
|
|
1299
|
+
/**
|
|
1300
|
+
* Retrieve the current block height of the blockchain.
|
|
1301
|
+
*
|
|
1302
|
+
* The block height represents the number of blocks that have been
|
|
1303
|
+
* confirmed on the chain since genesis.
|
|
1304
|
+
*
|
|
1305
|
+
* @returns The current block height
|
|
1306
|
+
*
|
|
1307
|
+
* @example
|
|
1308
|
+
* ```typescript
|
|
1309
|
+
* const height = await client.getBlockHeight();
|
|
1310
|
+
* console.log(`Current block height: ${height}`);
|
|
1311
|
+
* ```
|
|
1312
|
+
*/
|
|
1313
|
+
getBlockHeight(): Promise<bigint>;
|
|
1314
|
+
/**
|
|
1315
|
+
* Retrieve transaction signatures for a given address.
|
|
1316
|
+
*
|
|
1317
|
+
* Returns transaction signatures with metadata associated with the specified
|
|
1318
|
+
* address, ordered by slot height (most recent first).
|
|
1319
|
+
*
|
|
1320
|
+
* @param address - The public key of the address to query
|
|
1321
|
+
* @param config - Optional configuration options for the query (limit, before, until)
|
|
1322
|
+
* @returns Response containing context and array of signature info with blockHeight and blockTime
|
|
1323
|
+
*
|
|
1324
|
+
* @example
|
|
1325
|
+
* ```typescript
|
|
1326
|
+
* const result = await client.getSignaturesForAddress(publicKey, { limit: 10 });
|
|
1327
|
+
* console.log(`Query slot: ${result.context.slot}`);
|
|
1328
|
+
* result.value.forEach(sig => {
|
|
1329
|
+
* console.log(`Transaction: ${sig.signature}, block: ${sig.blockHeight}`);
|
|
1330
|
+
* });
|
|
1331
|
+
* ```
|
|
1332
|
+
*/
|
|
1333
|
+
getSignaturesForAddress(address: PublicKey, config?: GetSignaturesForAddressConfig): Promise<SignatureInfo[]>;
|
|
1334
|
+
/**
|
|
1335
|
+
* Retrieve detailed information about a confirmed transaction.
|
|
1336
|
+
*
|
|
1337
|
+
* Returns transaction metadata including the block height it was
|
|
1338
|
+
* confirmed in and any execution errors.
|
|
1339
|
+
*
|
|
1340
|
+
* @param signature - The transaction signature to query
|
|
1341
|
+
* @returns Transaction information, or null if the transaction is not found
|
|
1342
|
+
*
|
|
1343
|
+
* @example
|
|
1344
|
+
* ```typescript
|
|
1345
|
+
* const tx = await client.getTransaction(signature);
|
|
1346
|
+
* if (tx) {
|
|
1347
|
+
* console.log(`Confirmed in block: ${tx.blockHeight}`);
|
|
1348
|
+
* if (tx.err) {
|
|
1349
|
+
* console.log(`Transaction failed: ${tx.err}`);
|
|
1350
|
+
* }
|
|
1351
|
+
* }
|
|
1352
|
+
* ```
|
|
1353
|
+
*/
|
|
1354
|
+
getTransaction(signature: string): Promise<TransactionResponse | null>;
|
|
1355
|
+
/**
|
|
1356
|
+
* Retrieve the total number of transactions processed since genesis.
|
|
1357
|
+
*
|
|
1358
|
+
* @returns The total transaction count
|
|
1359
|
+
*
|
|
1360
|
+
* @example
|
|
1361
|
+
* ```typescript
|
|
1362
|
+
* const count = await client.getTransactionCount();
|
|
1363
|
+
* console.log(`Total transactions: ${count}`);
|
|
1364
|
+
* ```
|
|
1365
|
+
*/
|
|
1366
|
+
getTransactionCount(): Promise<bigint>;
|
|
1367
|
+
/**
|
|
1368
|
+
* Retrieve the status of multiple transaction signatures in a single request.
|
|
1369
|
+
*
|
|
1370
|
+
* Useful for batch-checking transaction confirmations. Returns null for
|
|
1371
|
+
* signatures that are not found or have expired from the status cache.
|
|
1372
|
+
*
|
|
1373
|
+
* @param signatures - Array of transaction signatures to query
|
|
1374
|
+
* @returns Array of signature statuses (null if signature not found)
|
|
1375
|
+
*
|
|
1376
|
+
* @example
|
|
1377
|
+
* ```typescript
|
|
1378
|
+
* const statuses = await client.getSignatureStatuses([sig1, sig2, sig3]);
|
|
1379
|
+
* statuses.forEach((status, i) => {
|
|
1380
|
+
* if (status) {
|
|
1381
|
+
* console.log(`${signatures[i]}: slot ${status.slot}, executed: ${status.executed}`);
|
|
1382
|
+
* } else {
|
|
1383
|
+
* console.log(`${signatures[i]}: not found`);
|
|
1384
|
+
* }
|
|
1385
|
+
* });
|
|
1386
|
+
* ```
|
|
1387
|
+
*/
|
|
1388
|
+
getSignatureStatuses(signatures: string[]): Promise<(SignatureStatus | null)[]>;
|
|
1389
|
+
/**
|
|
1390
|
+
* Retrieve information about the current epoch.
|
|
1391
|
+
*
|
|
1392
|
+
* Returns epoch metadata including the current epoch number, slot position
|
|
1393
|
+
* within the epoch, total slots per epoch, and current block height.
|
|
1394
|
+
*
|
|
1395
|
+
* @returns Current epoch information
|
|
1396
|
+
*
|
|
1397
|
+
* @example
|
|
1398
|
+
* ```typescript
|
|
1399
|
+
* const info = await client.getEpochInfo();
|
|
1400
|
+
* console.log(`Epoch: ${info.epoch}`);
|
|
1401
|
+
* console.log(`Slot ${info.slotIndex} of ${info.slotsInEpoch}`);
|
|
1402
|
+
* console.log(`Block height: ${info.blockHeight}`);
|
|
1403
|
+
* ```
|
|
1404
|
+
*/
|
|
1405
|
+
getEpochInfo(): Promise<EpochInfoResponse>;
|
|
1406
|
+
/**
|
|
1407
|
+
* Check the health status of the RPC node.
|
|
1408
|
+
*
|
|
1409
|
+
* Returns "ok" if the node is healthy. If the node is unhealthy,
|
|
1410
|
+
* returns an error message describing the issue.
|
|
1411
|
+
*
|
|
1412
|
+
* @returns "ok" if healthy, otherwise an error message
|
|
1413
|
+
*
|
|
1414
|
+
* @example
|
|
1415
|
+
* ```typescript
|
|
1416
|
+
* const health = await client.getHealth();
|
|
1417
|
+
* if (health === "ok") {
|
|
1418
|
+
* console.log("Node is healthy");
|
|
1419
|
+
* } else {
|
|
1420
|
+
* console.log(`Node unhealthy: ${health}`);
|
|
1421
|
+
* }
|
|
1422
|
+
* ```
|
|
1423
|
+
*/
|
|
1424
|
+
getHealth(): Promise<"ok" | string>;
|
|
1425
|
+
/**
|
|
1426
|
+
* Calculate the minimum balance required for an account to be rent-exempt.
|
|
1427
|
+
*
|
|
1428
|
+
* Accounts with at least this balance are exempt from paying rent.
|
|
1429
|
+
*
|
|
1430
|
+
* @param accountDataSize - The size of the account data in bytes
|
|
1431
|
+
* @returns The minimum balance in kelvins required for rent exemption
|
|
1432
|
+
*
|
|
1433
|
+
* @example
|
|
1434
|
+
* ```typescript
|
|
1435
|
+
* const minBalance = await client.getMinimumBalanceForRentExemption(128);
|
|
1436
|
+
* console.log(`Need at least ${minBalance} kelvins for 128 bytes`);
|
|
1437
|
+
* ```
|
|
1438
|
+
*/
|
|
1439
|
+
getMinimumBalanceForRentExemption(accountDataSize: number): Promise<bigint>;
|
|
1440
|
+
/**
|
|
1441
|
+
* Get the fee required to process a specific message.
|
|
1442
|
+
*
|
|
1443
|
+
* @param message - Base64-encoded serialized versioned message
|
|
1444
|
+
* @returns Fee in kelvins, or null if message is invalid
|
|
1445
|
+
*
|
|
1446
|
+
* @example
|
|
1447
|
+
* ```typescript
|
|
1448
|
+
* const fee = await client.getFeeForMessage(base64Message);
|
|
1449
|
+
* if (fee !== null) {
|
|
1450
|
+
* console.log(`Fee: ${fee} kelvins`);
|
|
1451
|
+
* }
|
|
1452
|
+
* ```
|
|
1453
|
+
*/
|
|
1454
|
+
getFeeForMessage(message: string): Promise<bigint | null>;
|
|
1455
|
+
/**
|
|
1456
|
+
* Get information for multiple accounts in a single request.
|
|
1457
|
+
*
|
|
1458
|
+
* Useful for batch operations and reducing RPC calls.
|
|
1459
|
+
*
|
|
1460
|
+
* @param pubkeys - Array of public keys to query (1-100)
|
|
1461
|
+
* @returns Account information for each address (null for non-existent accounts)
|
|
1462
|
+
*
|
|
1463
|
+
* @example
|
|
1464
|
+
* ```typescript
|
|
1465
|
+
* const accounts = await client.getMultipleAccounts([pubkey1, pubkey2]);
|
|
1466
|
+
* accounts.value.forEach((account, i) => {
|
|
1467
|
+
* if (account) {
|
|
1468
|
+
* console.log(`Account ${i}: ${account.balance} kelvins`);
|
|
1469
|
+
* }
|
|
1470
|
+
* });
|
|
1471
|
+
* ```
|
|
1472
|
+
*/
|
|
1473
|
+
getMultipleAccounts(pubkeys: PublicKey[]): Promise<Array<AccountInfo | null>>;
|
|
1474
|
+
/**
|
|
1475
|
+
* Get all accounts owned by a specific program or address.
|
|
1476
|
+
*
|
|
1477
|
+
* Essential for querying token accounts, program data, and more.
|
|
1478
|
+
*
|
|
1479
|
+
* @param owner - Program ID or owner public key
|
|
1480
|
+
* @param filter - Filter type (ProgramAccounts or TokenAccounts)
|
|
1481
|
+
* @param config - Optional configuration for pagination and encoding
|
|
1482
|
+
* @returns Accounts owned by the specified owner with pagination info
|
|
1483
|
+
*
|
|
1484
|
+
* @example
|
|
1485
|
+
* ```typescript
|
|
1486
|
+
* const result = await client.getAccountsByOwner(programId);
|
|
1487
|
+
* console.log(`Found ${result.value.length} accounts`);
|
|
1488
|
+
* result.value.forEach(({ pubkey, account }) => {
|
|
1489
|
+
* console.log(`${pubkey}: ${account.balance} kelvins`);
|
|
1490
|
+
* });
|
|
1491
|
+
* ```
|
|
1492
|
+
*/
|
|
1493
|
+
getAccountsByOwner(owner: PublicKey, filter?: AccountFilter, config?: GetAccountsByOwnerConfig): Promise<GetAccountsByOwnerResponse>;
|
|
1494
|
+
/**
|
|
1495
|
+
* Get workflow lineage information for tracking execution history.
|
|
1496
|
+
*
|
|
1497
|
+
* Returns the tree of transactions spawned from a root transaction
|
|
1498
|
+
* through subscriptions and triggers.
|
|
1499
|
+
*
|
|
1500
|
+
* @param request - Workflow lineage request with signature and options
|
|
1501
|
+
* @returns Workflow lineage tree with nodes and metadata
|
|
1502
|
+
*
|
|
1503
|
+
* @example
|
|
1504
|
+
* ```typescript
|
|
1505
|
+
* const lineage = await client.getWorkflowLineage({
|
|
1506
|
+
* signature: rootTxSignature,
|
|
1507
|
+
* maxDepth: 5,
|
|
1508
|
+
* });
|
|
1509
|
+
* console.log(`Found ${lineage.lineage.workflowNodes.length} nodes`);
|
|
1510
|
+
* ```
|
|
1511
|
+
*/
|
|
1512
|
+
getWorkflowLineage(request: GetWorkflowLineageRequest): Promise<GetWorkflowLineageResponse>;
|
|
1513
|
+
/**
|
|
1514
|
+
* Get subscriptions for a given subscriber address.
|
|
1515
|
+
*
|
|
1516
|
+
* Returns subscriptions that will trigger transactions when matching events occur.
|
|
1517
|
+
*
|
|
1518
|
+
* @param subscriber - The subscriber's public key
|
|
1519
|
+
* @param nonce - The nonce identifying the subscription
|
|
1520
|
+
* @returns The subscription for the subscriber and nonce
|
|
1521
|
+
*
|
|
1522
|
+
* @example
|
|
1523
|
+
* ```typescript
|
|
1524
|
+
* const subscription = await client.getSubscription(subscriberPubkey, "my-nonce");
|
|
1525
|
+
* console.log(`Topic: ${subscription.topic}, Kind: ${subscription.kind}`);
|
|
1526
|
+
* ```
|
|
1527
|
+
*/
|
|
1528
|
+
getSubscription(subscriber: PublicKey, nonce: string): Promise<Subscription>;
|
|
1529
|
+
/**
|
|
1530
|
+
* Get transactions triggered by a subscription account.
|
|
1531
|
+
*
|
|
1532
|
+
* Returns the history of transactions that were automatically executed
|
|
1533
|
+
* in response to subscription matches.
|
|
1534
|
+
*
|
|
1535
|
+
* @param subscriptionAccount - The subscription account public key
|
|
1536
|
+
* @param limit - Optional limit on transactions returned
|
|
1537
|
+
* @returns Triggered transactions for the subscription
|
|
1538
|
+
*
|
|
1539
|
+
* @example
|
|
1540
|
+
* ```typescript
|
|
1541
|
+
* const result = await client.getTriggeredTransactions(subscriptionPubkey, 10);
|
|
1542
|
+
* result.transactions.forEach(tx => {
|
|
1543
|
+
* console.log(`Signature: ${tx.signature}, Block: ${tx.blockNumber}`);
|
|
1544
|
+
* });
|
|
1545
|
+
* ```
|
|
1546
|
+
*/
|
|
1547
|
+
getTriggeredTransactions(subscriptionAccount: PublicKey, limit?: number): Promise<TriggeredTransaction[]>;
|
|
1548
|
+
}
|
|
1549
|
+
|
|
1550
|
+
/**
|
|
1551
|
+
* Query client for read-only RPC operations.
|
|
1552
|
+
*/
|
|
1553
|
+
|
|
1554
|
+
/**
|
|
1555
|
+
* Client for sending/simulating transactions and requesting airdrops.
|
|
1556
|
+
*
|
|
1557
|
+
* Handles all transaction operations like sending transactions, requesting airdrops, etc.
|
|
1558
|
+
*/
|
|
1559
|
+
declare class TransactionRpcClient extends BaseRpcClient {
|
|
1560
|
+
/**
|
|
1561
|
+
* Submit a signed transaction to the blockchain.
|
|
1562
|
+
*
|
|
1563
|
+
* Sends the transaction to the network for processing. The transaction
|
|
1564
|
+
* must be fully signed before submission. Returns immediately with the
|
|
1565
|
+
* transaction signature - use {@link confirmTransaction} or
|
|
1566
|
+
* {@link sendAndConfirmTransaction} to wait for confirmation.
|
|
1567
|
+
*
|
|
1568
|
+
* @param transaction - Serialized signed transaction bytes
|
|
1569
|
+
* @param options - Transaction submission options
|
|
1570
|
+
* @returns Transaction signature (base58 encoded)
|
|
1571
|
+
*
|
|
1572
|
+
* @example
|
|
1573
|
+
* ```typescript
|
|
1574
|
+
* const signature = await client.sendTransaction(signedTx);
|
|
1575
|
+
* console.log(`Submitted: ${signature}`);
|
|
1576
|
+
*
|
|
1577
|
+
* // With options
|
|
1578
|
+
* const signature = await client.sendTransaction(signedTx, {
|
|
1579
|
+
* skipPreflight: true,
|
|
1580
|
+
* maxRetries: 3,
|
|
1581
|
+
* });
|
|
1582
|
+
* ```
|
|
1583
|
+
*/
|
|
1584
|
+
sendTransaction(transaction: Uint8Array, options?: SendTransactionOptions): Promise<string>;
|
|
1585
|
+
/**
|
|
1586
|
+
* Wait for a transaction to be confirmed.
|
|
1587
|
+
*
|
|
1588
|
+
* A transaction is considered confirmed when:
|
|
1589
|
+
* - It has been processed in a block (`blockHeight > 0`)
|
|
1590
|
+
*
|
|
1591
|
+
* @param signature - Transaction signature to monitor
|
|
1592
|
+
* @param options - Confirmation options
|
|
1593
|
+
* @returns Confirmed transaction details
|
|
1594
|
+
* @throws {TransactionFailedError} If the transaction fails on-chain
|
|
1595
|
+
* @throws {TransactionConfirmationTimeoutError} If confirmation times out
|
|
1596
|
+
*/
|
|
1597
|
+
confirmTransaction(signature: string, options?: ConfirmTransactionOptions): Promise<ConfirmedTransaction>;
|
|
1598
|
+
/**
|
|
1599
|
+
* Submit a signed transaction and wait for confirmation.
|
|
1600
|
+
*
|
|
1601
|
+
* Polls the transaction status until it is confirmed (blockHeight > 0),
|
|
1602
|
+
* or until the maximum number of retries is reached.
|
|
1603
|
+
*
|
|
1604
|
+
* @param transaction - Serialized signed transaction bytes
|
|
1605
|
+
* @param options - Transaction submission and confirmation options
|
|
1606
|
+
* @returns Confirmed transaction details
|
|
1607
|
+
* @throws {TransactionFailedError} If the transaction fails on-chain
|
|
1608
|
+
* @throws {TransactionConfirmationTimeoutError} If confirmation times out
|
|
1609
|
+
*
|
|
1610
|
+
* @example
|
|
1611
|
+
* ```typescript
|
|
1612
|
+
* const result = await client.sendAndConfirmTransaction(signedTx);
|
|
1613
|
+
* console.log(`Confirmed in block ${result.blockHeight}, executed: ${result.executed}`);
|
|
1614
|
+
*
|
|
1615
|
+
* // With custom retry settings
|
|
1616
|
+
* const result = await client.sendAndConfirmTransaction(signedTx, {
|
|
1617
|
+
* maxRetries: 3,
|
|
1618
|
+
* retryDelay: 500,
|
|
1619
|
+
* });
|
|
1620
|
+
* ```
|
|
1621
|
+
*/
|
|
1622
|
+
sendAndConfirmTransaction(transaction: Uint8Array, options?: SendAndConfirmOptions): Promise<ConfirmedTransaction>;
|
|
1623
|
+
/**
|
|
1624
|
+
* Request an airdrop of tokens to an account.
|
|
1625
|
+
*
|
|
1626
|
+
* **Note**: Only available on devnet and testnet networks.
|
|
1627
|
+
*
|
|
1628
|
+
* Returns immediately with the airdrop transaction signature.
|
|
1629
|
+
* Use {@link requestAirdropAndConfirm} to wait for the airdrop to complete.
|
|
1630
|
+
*
|
|
1631
|
+
* @param pubkey - The public key of the account to receive tokens
|
|
1632
|
+
* @param amount - Amount to airdrop in kelvins (smallest unit)
|
|
1633
|
+
* @returns Airdrop transaction signature
|
|
1634
|
+
*
|
|
1635
|
+
* @example
|
|
1636
|
+
* ```typescript
|
|
1637
|
+
* const signature = await client.requestAirdrop(publicKey, 1_000_000_000n);
|
|
1638
|
+
* console.log(`Airdrop requested: ${signature}`);
|
|
1639
|
+
* ```
|
|
1640
|
+
*/
|
|
1641
|
+
requestAirdrop(pubkey: PublicKey, amount: bigint): Promise<string>;
|
|
1642
|
+
/**
|
|
1643
|
+
* Request an airdrop of tokens and wait for confirmation.
|
|
1644
|
+
*
|
|
1645
|
+
* **Note**: Only available on devnet and testnet networks.
|
|
1646
|
+
*
|
|
1647
|
+
* Combines {@link requestAirdrop} and {@link confirmTransaction} into
|
|
1648
|
+
* a single call for convenience.
|
|
1649
|
+
*
|
|
1650
|
+
* @param pubkey - The public key of the account to receive tokens
|
|
1651
|
+
* @param amount - Amount to airdrop in kelvins (smallest unit)
|
|
1652
|
+
* @param options - Confirmation options (max retries, retry delay)
|
|
1653
|
+
* @returns Confirmed transaction details
|
|
1654
|
+
* @throws {RpcError} If the airdrop transaction fails or confirmation times out
|
|
1655
|
+
*
|
|
1656
|
+
* @example
|
|
1657
|
+
* ```typescript
|
|
1658
|
+
* const result = await client.requestAirdropAndConfirm(publicKey, 1_000_000_000n);
|
|
1659
|
+
* if (result.executed) {
|
|
1660
|
+
* console.log("Airdrop confirmed!");
|
|
1661
|
+
* }
|
|
1662
|
+
* ```
|
|
1663
|
+
*/
|
|
1664
|
+
requestAirdropAndConfirm(pubkey: PublicKey, amount: bigint, options?: ConfirmTransactionOptions): Promise<ConfirmedTransaction>;
|
|
1665
|
+
private getTransaction;
|
|
1666
|
+
/**
|
|
1667
|
+
* Sleeps for a given number of milliseconds.
|
|
1668
|
+
* @param ms - The number of milliseconds to sleep.
|
|
1669
|
+
* @returns A promise that resolves when the sleep is complete.
|
|
1670
|
+
*/
|
|
1671
|
+
private sleep;
|
|
1672
|
+
}
|
|
1673
|
+
|
|
1674
|
+
/**
|
|
1675
|
+
* Error codes for RPC operations, categorized by type.
|
|
1676
|
+
*/
|
|
1677
|
+
declare enum RpcErrorCode {
|
|
1678
|
+
REQUEST_TIMEOUT = "REQUEST_TIMEOUT",
|
|
1679
|
+
NETWORK_ERROR = "NETWORK_ERROR",
|
|
1680
|
+
CONNECTION_REFUSED = "CONNECTION_REFUSED",
|
|
1681
|
+
INVALID_NETWORK = "INVALID_NETWORK",
|
|
1682
|
+
INVALID_RESPONSE = "INVALID_RESPONSE",
|
|
1683
|
+
PARSE_ERROR = "PARSE_ERROR",
|
|
1684
|
+
INVALID_REQUEST = "INVALID_REQUEST",
|
|
1685
|
+
METHOD_NOT_FOUND = "METHOD_NOT_FOUND",
|
|
1686
|
+
INVALID_PARAMS = "INVALID_PARAMS",
|
|
1687
|
+
INTERNAL_ERROR = "INTERNAL_ERROR",
|
|
1688
|
+
TRANSACTION_REJECTED = "TRANSACTION_REJECTED",
|
|
1689
|
+
INSUFFICIENT_FUNDS = "INSUFFICIENT_FUNDS",
|
|
1690
|
+
TRANSACTION_CONFIRMATION_TIMEOUT = "TRANSACTION_CONFIRMATION_TIMEOUT",
|
|
1691
|
+
ACCOUNT_NOT_FOUND = "ACCOUNT_NOT_FOUND",
|
|
1692
|
+
RATE_LIMIT_EXCEEDED = "RATE_LIMIT_EXCEEDED",
|
|
1693
|
+
NODE_UNHEALTHY = "NODE_UNHEALTHY"
|
|
1694
|
+
}
|
|
1695
|
+
/**
|
|
1696
|
+
* Detailed error context for debugging and error handling.
|
|
1697
|
+
*/
|
|
1698
|
+
interface RpcErrorDetails {
|
|
1699
|
+
method?: string;
|
|
1700
|
+
params?: unknown;
|
|
1701
|
+
requestId?: number;
|
|
1702
|
+
url?: string;
|
|
1703
|
+
httpStatus?: number;
|
|
1704
|
+
rpcCode?: number;
|
|
1705
|
+
timeout?: number;
|
|
1706
|
+
attempts?: number;
|
|
1707
|
+
[key: string]: unknown;
|
|
1708
|
+
}
|
|
1709
|
+
/**
|
|
1710
|
+
* Error class for RPC operations with structured error information.
|
|
1711
|
+
*
|
|
1712
|
+
* Provides actionable error messages and indicates whether errors are retryable.
|
|
1713
|
+
*/
|
|
1714
|
+
declare class RpcError extends Error {
|
|
1715
|
+
readonly code: RpcErrorCode;
|
|
1716
|
+
readonly details: RpcErrorDetails;
|
|
1717
|
+
readonly retryable: boolean;
|
|
1718
|
+
constructor(code: RpcErrorCode, message: string, details?: RpcErrorDetails, retryable?: boolean);
|
|
1719
|
+
static requestTimeout(timeoutMs: number, details: RpcErrorDetails): RpcError;
|
|
1720
|
+
static networkError(message: string, details: RpcErrorDetails): RpcError;
|
|
1721
|
+
static invalidResponse(details: RpcErrorDetails): RpcError;
|
|
1722
|
+
static accountNotFound(pubkey: string): RpcError;
|
|
1723
|
+
static rateLimitExceeded(details: RpcErrorDetails): RpcError;
|
|
1724
|
+
static fromRpcCode(rpcCode: number, message: string, details: RpcErrorDetails): RpcError;
|
|
1725
|
+
toJSON(): {
|
|
1726
|
+
code: RpcErrorCode;
|
|
1727
|
+
message: string;
|
|
1728
|
+
details?: Record<string, unknown>;
|
|
1729
|
+
retryable: boolean;
|
|
1730
|
+
};
|
|
1731
|
+
}
|
|
1732
|
+
|
|
1733
|
+
/**
|
|
1734
|
+
* Creates an RPC client with automatic retry and timeout handling.
|
|
1735
|
+
*
|
|
1736
|
+
* @param config - Client configuration with chain definition and optional transport settings
|
|
1737
|
+
* @param config.chain - Chain definition (e.g., RIALO_DEVNET_CHAIN, RIALO_MAINNET_CHAIN) or a custom chain with your own rpcUrl
|
|
1738
|
+
* @param config.transport - Optional transport configuration (timeout, retries, headers)
|
|
1739
|
+
* @returns Configured RialoClient instance
|
|
1740
|
+
*
|
|
1741
|
+
* @example
|
|
1742
|
+
* ```typescript
|
|
1743
|
+
* // Basic usage with preset chain
|
|
1744
|
+
* const client = createRialoClient({ chain: RIALO_DEVNET_CHAIN });
|
|
1745
|
+
*
|
|
1746
|
+
* // With custom transport config
|
|
1747
|
+
* const client = createRialoClient({
|
|
1748
|
+
* chain: RIALO_MAINNET_CHAIN,
|
|
1749
|
+
* transport: { timeout: 30000, maxRetries: 5 }
|
|
1750
|
+
* });
|
|
1751
|
+
*
|
|
1752
|
+
* // With custom RPC URL
|
|
1753
|
+
* const client = createRialoClient({
|
|
1754
|
+
* chain: {
|
|
1755
|
+
* id: 'rialo:mainnet',
|
|
1756
|
+
* name: 'Mainnet',
|
|
1757
|
+
* rpcUrl: 'https://mainnet.custom-rpc.com:4101'
|
|
1758
|
+
* },
|
|
1759
|
+
* });
|
|
1760
|
+
* ```
|
|
1761
|
+
*/
|
|
1762
|
+
declare function createRialoClient(config: RialoClientConfig): RialoClient;
|
|
1763
|
+
/**
|
|
1764
|
+
* Returns a default RialoClientConfig for a given network.
|
|
1765
|
+
*
|
|
1766
|
+
* Provides preset chain configurations for standard Rialo networks, making it easy
|
|
1767
|
+
* to connect to mainnet, devnet, testnet, or localnet without manual configuration.
|
|
1768
|
+
*
|
|
1769
|
+
* @param network - Network identifier: "mainnet", "devnet", "testnet", or "localnet"
|
|
1770
|
+
* @returns Default RialoClientConfig for the specified network
|
|
1771
|
+
* @throws {RpcError} With code INVALID_NETWORK if an unknown network is provided
|
|
1772
|
+
*
|
|
1773
|
+
* @example
|
|
1774
|
+
* ```typescript
|
|
1775
|
+
* // Get devnet config and create client
|
|
1776
|
+
* const config = getDefaultRialoClientConfig('devnet');
|
|
1777
|
+
* const client = createRialoClient(config);
|
|
1778
|
+
*
|
|
1779
|
+
* // Customize the config with transport options
|
|
1780
|
+
* const config = getDefaultRialoClientConfig('mainnet');
|
|
1781
|
+
* const client = createRialoClient({
|
|
1782
|
+
* ...config,
|
|
1783
|
+
* transport: { timeout: 60000, maxRetries: 5 }
|
|
1784
|
+
* });
|
|
1785
|
+
*
|
|
1786
|
+
* // Use custom RPC URL while preserving network identity
|
|
1787
|
+
* const config = getDefaultRialoClientConfig('mainnet');
|
|
1788
|
+
* const client = createRialoClient({
|
|
1789
|
+
* ...config,
|
|
1790
|
+
* chain: {
|
|
1791
|
+
* ...config.chain,
|
|
1792
|
+
* rpcUrl: 'https://mainnet.custom-rpc.com:4101'
|
|
1793
|
+
* },
|
|
1794
|
+
* });
|
|
1795
|
+
* ```
|
|
1796
|
+
*/
|
|
1797
|
+
declare function getDefaultRialoClientConfig(network: RialoNetwork): RialoClientConfig;
|
|
1798
|
+
|
|
1799
|
+
/**
|
|
1800
|
+
* Bincode deserialization reader
|
|
1801
|
+
*
|
|
1802
|
+
* Matches Rust's bincode crate with default configuration:
|
|
1803
|
+
* - Little-endian byte order
|
|
1804
|
+
* - Fixed-size integer encoding (no varint)
|
|
1805
|
+
* - u64 length prefixes for dynamic collections
|
|
1806
|
+
* - u32 enum variant indices
|
|
1807
|
+
*/
|
|
1808
|
+
declare class BincodeReader {
|
|
1809
|
+
private view;
|
|
1810
|
+
private offset;
|
|
1811
|
+
private bytes;
|
|
1812
|
+
constructor(data: Uint8Array);
|
|
1813
|
+
getOffset(): number;
|
|
1814
|
+
remaining(): number;
|
|
1815
|
+
isExhausted(): boolean;
|
|
1816
|
+
skip(bytes: number): this;
|
|
1817
|
+
/**
|
|
1818
|
+
* Peek at bytes without advancing the offset
|
|
1819
|
+
*/
|
|
1820
|
+
peek(length: number): Uint8Array;
|
|
1821
|
+
/**
|
|
1822
|
+
* Reset reader to beginning
|
|
1823
|
+
*/
|
|
1824
|
+
reset(): this;
|
|
1825
|
+
/**
|
|
1826
|
+
* Seek to specific offset
|
|
1827
|
+
*/
|
|
1828
|
+
seek(offset: number): this;
|
|
1829
|
+
readU8(): number;
|
|
1830
|
+
readU16(): number;
|
|
1831
|
+
readU32(): number;
|
|
1832
|
+
readU64(): bigint;
|
|
1833
|
+
readU128(): bigint;
|
|
1834
|
+
readI8(): number;
|
|
1835
|
+
readI16(): number;
|
|
1836
|
+
readI32(): number;
|
|
1837
|
+
readI64(): bigint;
|
|
1838
|
+
readI128(): bigint;
|
|
1839
|
+
readF32(): number;
|
|
1840
|
+
readF64(): number;
|
|
1841
|
+
readBool(): boolean;
|
|
1842
|
+
readBytes(length: number): Uint8Array;
|
|
1843
|
+
readFixedArray(length: number): Uint8Array;
|
|
1844
|
+
readVecBytes(): Uint8Array;
|
|
1845
|
+
readString(): string;
|
|
1846
|
+
readVariant(): number;
|
|
1847
|
+
readOption<T>(readValue: () => T): T | null;
|
|
1848
|
+
readVec<T>(readElement: () => T): T[];
|
|
1849
|
+
/**
|
|
1850
|
+
* Read a tuple of fixed size with heterogeneous types
|
|
1851
|
+
*/
|
|
1852
|
+
readTuple<T extends unknown[]>(readers: {
|
|
1853
|
+
[K in keyof T]: () => T[K];
|
|
1854
|
+
}): T;
|
|
1855
|
+
readMap<K, V>(readKey: () => K, readValue: () => V): Map<K, V>;
|
|
1856
|
+
/**
|
|
1857
|
+
* Read length as u64 but validate it's within safe integer range
|
|
1858
|
+
*/
|
|
1859
|
+
private readLength;
|
|
1860
|
+
private ensureAvailable;
|
|
1861
|
+
}
|
|
1862
|
+
|
|
1863
|
+
/**
|
|
1864
|
+
* Type definitions for bincode schemas
|
|
1865
|
+
*
|
|
1866
|
+
* IMPORTANT: For structs and enums, field/variant order MUST match Rust definition order.
|
|
1867
|
+
* Use arrays of tuples instead of objects to guarantee order preservation.
|
|
1868
|
+
*/
|
|
1869
|
+
type BincodeSchema = {
|
|
1870
|
+
type: "u8";
|
|
1871
|
+
} | {
|
|
1872
|
+
type: "u16";
|
|
1873
|
+
} | {
|
|
1874
|
+
type: "u32";
|
|
1875
|
+
} | {
|
|
1876
|
+
type: "u64";
|
|
1877
|
+
} | {
|
|
1878
|
+
type: "u128";
|
|
1879
|
+
} | {
|
|
1880
|
+
type: "i8";
|
|
1881
|
+
} | {
|
|
1882
|
+
type: "i16";
|
|
1883
|
+
} | {
|
|
1884
|
+
type: "i32";
|
|
1885
|
+
} | {
|
|
1886
|
+
type: "i64";
|
|
1887
|
+
} | {
|
|
1888
|
+
type: "i128";
|
|
1889
|
+
} | {
|
|
1890
|
+
type: "f32";
|
|
1891
|
+
} | {
|
|
1892
|
+
type: "f64";
|
|
1893
|
+
} | {
|
|
1894
|
+
type: "bool";
|
|
1895
|
+
} | {
|
|
1896
|
+
type: "string";
|
|
1897
|
+
} | {
|
|
1898
|
+
type: "bytes";
|
|
1899
|
+
} | {
|
|
1900
|
+
type: "unit";
|
|
1901
|
+
} | {
|
|
1902
|
+
type: "fixedArray";
|
|
1903
|
+
length: number;
|
|
1904
|
+
} | {
|
|
1905
|
+
type: "vec";
|
|
1906
|
+
element: BincodeSchema;
|
|
1907
|
+
} | {
|
|
1908
|
+
type: "option";
|
|
1909
|
+
inner: BincodeSchema;
|
|
1910
|
+
} | {
|
|
1911
|
+
type: "tuple";
|
|
1912
|
+
elements: BincodeSchema[];
|
|
1913
|
+
} | {
|
|
1914
|
+
type: "struct";
|
|
1915
|
+
fields: StructField[];
|
|
1916
|
+
} | {
|
|
1917
|
+
type: "enum";
|
|
1918
|
+
variants: EnumVariant[];
|
|
1919
|
+
} | {
|
|
1920
|
+
type: "map";
|
|
1921
|
+
key: BincodeSchema;
|
|
1922
|
+
value: BincodeSchema;
|
|
1923
|
+
} | {
|
|
1924
|
+
type: "pubkey";
|
|
1925
|
+
};
|
|
1926
|
+
/**
|
|
1927
|
+
* Struct field definition - order matters!
|
|
1928
|
+
*/
|
|
1929
|
+
interface StructField {
|
|
1930
|
+
name: string;
|
|
1931
|
+
schema: BincodeSchema;
|
|
1932
|
+
}
|
|
1933
|
+
/**
|
|
1934
|
+
* Enum variant definition - order matters!
|
|
1935
|
+
*/
|
|
1936
|
+
interface EnumVariant {
|
|
1937
|
+
name: string;
|
|
1938
|
+
schema: BincodeSchema | null;
|
|
1939
|
+
}
|
|
1940
|
+
declare const Schema: {
|
|
1941
|
+
readonly u8: () => BincodeSchema;
|
|
1942
|
+
readonly u16: () => BincodeSchema;
|
|
1943
|
+
readonly u32: () => BincodeSchema;
|
|
1944
|
+
readonly u64: () => BincodeSchema;
|
|
1945
|
+
readonly u128: () => BincodeSchema;
|
|
1946
|
+
readonly i8: () => BincodeSchema;
|
|
1947
|
+
readonly i16: () => BincodeSchema;
|
|
1948
|
+
readonly i32: () => BincodeSchema;
|
|
1949
|
+
readonly i64: () => BincodeSchema;
|
|
1950
|
+
readonly i128: () => BincodeSchema;
|
|
1951
|
+
readonly f32: () => BincodeSchema;
|
|
1952
|
+
readonly f64: () => BincodeSchema;
|
|
1953
|
+
readonly bool: () => BincodeSchema;
|
|
1954
|
+
readonly string: () => BincodeSchema;
|
|
1955
|
+
readonly bytes: () => BincodeSchema;
|
|
1956
|
+
readonly unit: () => BincodeSchema;
|
|
1957
|
+
readonly fixedArray: (length: number) => BincodeSchema;
|
|
1958
|
+
readonly vec: (element: BincodeSchema) => BincodeSchema;
|
|
1959
|
+
readonly option: (inner: BincodeSchema) => BincodeSchema;
|
|
1960
|
+
readonly tuple: (...elements: BincodeSchema[]) => BincodeSchema;
|
|
1961
|
+
/**
|
|
1962
|
+
* Define a struct with ordered fields
|
|
1963
|
+
* @example
|
|
1964
|
+
* Schema.struct([
|
|
1965
|
+
* ["id", Schema.u64()],
|
|
1966
|
+
* ["name", Schema.string()],
|
|
1967
|
+
* ["active", Schema.bool()],
|
|
1968
|
+
* ])
|
|
1969
|
+
*/
|
|
1970
|
+
readonly struct: (fields: [string, BincodeSchema][]) => BincodeSchema;
|
|
1971
|
+
/**
|
|
1972
|
+
* Define an enum with ordered variants
|
|
1973
|
+
* @example
|
|
1974
|
+
* Schema.enum([
|
|
1975
|
+
* ["None", null],
|
|
1976
|
+
* ["Some", Schema.u64()],
|
|
1977
|
+
* ["Error", Schema.string()],
|
|
1978
|
+
* ])
|
|
1979
|
+
*/
|
|
1980
|
+
readonly enum: (variants: [string, BincodeSchema | null][]) => BincodeSchema;
|
|
1981
|
+
readonly map: (key: BincodeSchema, value: BincodeSchema) => BincodeSchema;
|
|
1982
|
+
readonly pubkey: () => BincodeSchema;
|
|
1983
|
+
};
|
|
1984
|
+
/**
|
|
1985
|
+
* Serialize a value according to a schema
|
|
1986
|
+
*/
|
|
1987
|
+
declare function serialize(schema: BincodeSchema, value: unknown): Uint8Array;
|
|
1988
|
+
/**
|
|
1989
|
+
* Deserialize bytes according to a schema
|
|
1990
|
+
*/
|
|
1991
|
+
declare function deserialize<T>(schema: BincodeSchema, data: Uint8Array): T;
|
|
1992
|
+
/**
|
|
1993
|
+
* Deserialize bytes with strict validation
|
|
1994
|
+
*/
|
|
1995
|
+
declare function deserializeStrict<T>(schema: BincodeSchema, data: Uint8Array): T;
|
|
1996
|
+
/**
|
|
1997
|
+
* Infer TypeScript type from schema (for documentation purposes)
|
|
1998
|
+
*
|
|
1999
|
+
* Usage:
|
|
2000
|
+
* const mySchema = Schema.struct([...]);
|
|
2001
|
+
* type MyType = InferSchema<typeof mySchema>;
|
|
2002
|
+
*/
|
|
2003
|
+
type InferSchema<S extends BincodeSchema> = S extends {
|
|
2004
|
+
type: "u8";
|
|
2005
|
+
} ? number : S extends {
|
|
2006
|
+
type: "u16";
|
|
2007
|
+
} ? number : S extends {
|
|
2008
|
+
type: "u32";
|
|
2009
|
+
} ? number : S extends {
|
|
2010
|
+
type: "u64";
|
|
2011
|
+
} ? bigint : S extends {
|
|
2012
|
+
type: "u128";
|
|
2013
|
+
} ? bigint : S extends {
|
|
2014
|
+
type: "i8";
|
|
2015
|
+
} ? number : S extends {
|
|
2016
|
+
type: "i16";
|
|
2017
|
+
} ? number : S extends {
|
|
2018
|
+
type: "i32";
|
|
2019
|
+
} ? number : S extends {
|
|
2020
|
+
type: "i64";
|
|
2021
|
+
} ? bigint : S extends {
|
|
2022
|
+
type: "i128";
|
|
2023
|
+
} ? bigint : S extends {
|
|
2024
|
+
type: "f32";
|
|
2025
|
+
} ? number : S extends {
|
|
2026
|
+
type: "f64";
|
|
2027
|
+
} ? number : S extends {
|
|
2028
|
+
type: "bool";
|
|
2029
|
+
} ? boolean : S extends {
|
|
2030
|
+
type: "string";
|
|
2031
|
+
} ? string : S extends {
|
|
2032
|
+
type: "bytes";
|
|
2033
|
+
} ? Uint8Array : S extends {
|
|
2034
|
+
type: "unit";
|
|
2035
|
+
} ? undefined : S extends {
|
|
2036
|
+
type: "fixedArray";
|
|
2037
|
+
} ? Uint8Array : S extends {
|
|
2038
|
+
type: "pubkey";
|
|
2039
|
+
} ? Uint8Array : S extends {
|
|
2040
|
+
type: "vec";
|
|
2041
|
+
element: infer E;
|
|
2042
|
+
} ? E extends BincodeSchema ? InferSchema<E>[] : never : S extends {
|
|
2043
|
+
type: "option";
|
|
2044
|
+
inner: infer I;
|
|
2045
|
+
} ? I extends BincodeSchema ? InferSchema<I> | null : never : unknown;
|
|
2046
|
+
|
|
2047
|
+
/**
|
|
2048
|
+
* Bincode serialization writer
|
|
2049
|
+
*
|
|
2050
|
+
* Matches Rust's bincode crate with default configuration:
|
|
2051
|
+
* - Little-endian byte order
|
|
2052
|
+
* - Fixed-size integer encoding (no varint)
|
|
2053
|
+
* - u64 length prefixes for dynamic collections
|
|
2054
|
+
* - u32 enum variant indices
|
|
2055
|
+
*/
|
|
2056
|
+
declare class BincodeWriter {
|
|
2057
|
+
private buffer;
|
|
2058
|
+
private offset;
|
|
2059
|
+
private view;
|
|
2060
|
+
constructor(initialCapacity?: number);
|
|
2061
|
+
writeU8(value: number): this;
|
|
2062
|
+
writeU16(value: number): this;
|
|
2063
|
+
writeU32(value: number): this;
|
|
2064
|
+
writeU64(value: bigint | number): this;
|
|
2065
|
+
writeU128(value: bigint): this;
|
|
2066
|
+
writeI8(value: number): this;
|
|
2067
|
+
writeI16(value: number): this;
|
|
2068
|
+
writeI32(value: number): this;
|
|
2069
|
+
writeI64(value: bigint): this;
|
|
2070
|
+
writeI128(value: bigint): this;
|
|
2071
|
+
writeF32(value: number): this;
|
|
2072
|
+
writeF64(value: number): this;
|
|
2073
|
+
writeBool(value: boolean): this;
|
|
2074
|
+
writeBytes(bytes: Uint8Array): this;
|
|
2075
|
+
writeFixedArray(bytes: Uint8Array, expectedLength?: number): this;
|
|
2076
|
+
writeVecBytes(bytes: Uint8Array): this;
|
|
2077
|
+
writeString(str: string): this;
|
|
2078
|
+
writeVariant(index: number): this;
|
|
2079
|
+
writeOption<T>(value: T | null | undefined, writeValue: (writer: BincodeWriter, val: T) => void): this;
|
|
2080
|
+
writeVec<T>(items: T[], writeItem: (writer: BincodeWriter, item: T) => void): this;
|
|
2081
|
+
/**
|
|
2082
|
+
* Write a tuple (fixed-size heterogeneous collection)
|
|
2083
|
+
*/
|
|
2084
|
+
writeTuple<T extends unknown[]>(items: T, writers: {
|
|
2085
|
+
[K in keyof T]: (writer: BincodeWriter, val: T[K]) => void;
|
|
2086
|
+
}): this;
|
|
2087
|
+
writeMap<K, V>(map: Map<K, V>, writeKey: (writer: BincodeWriter, key: K) => void, writeValue: (writer: BincodeWriter, value: V) => void): this;
|
|
2088
|
+
toBytes(): Uint8Array;
|
|
2089
|
+
/**
|
|
2090
|
+
* Get a view of the written bytes WITHOUT copying.
|
|
2091
|
+
*
|
|
2092
|
+
* ⚠️ WARNING: This returns a view into the internal buffer.
|
|
2093
|
+
* The view becomes INVALID if:
|
|
2094
|
+
* - The writer continues writing (may trigger resize)
|
|
2095
|
+
* - The writer is cleared via clear()
|
|
2096
|
+
*
|
|
2097
|
+
* Use toBytes() for a safe copy, or use this only for immediate
|
|
2098
|
+
* read-only access when performance is critical.
|
|
2099
|
+
*/
|
|
2100
|
+
toView(): Uint8Array;
|
|
2101
|
+
length(): number;
|
|
2102
|
+
clear(): this;
|
|
2103
|
+
/**
|
|
2104
|
+
* Reserve additional capacity
|
|
2105
|
+
*/
|
|
2106
|
+
reserve(additionalBytes: number): this;
|
|
2107
|
+
private ensureCapacity;
|
|
2108
|
+
}
|
|
2109
|
+
|
|
2110
|
+
/**
|
|
2111
|
+
* Serializes data using Borsh (Binary Object Representation Serializer for Hashing) encoding.
|
|
2112
|
+
*
|
|
2113
|
+
* Borsh is efficient for complex types like enums, Options, vectors, and nested structs.
|
|
2114
|
+
* Use the exported decorators (@field, @option, @vec) to define your data structures.
|
|
2115
|
+
*
|
|
2116
|
+
* @param data - Data object to serialize
|
|
2117
|
+
* @returns Serialized bytes
|
|
2118
|
+
*
|
|
2119
|
+
* @example
|
|
2120
|
+
* ```typescript
|
|
2121
|
+
* import { serializeBorsh, field, option } from '@rialo/ts-cdk';
|
|
2122
|
+
*
|
|
2123
|
+
* class SwapInstruction {
|
|
2124
|
+
* @field({ type: 'u8' })
|
|
2125
|
+
* instruction: number;
|
|
2126
|
+
*
|
|
2127
|
+
* @field({ type: 'u64' })
|
|
2128
|
+
* amountIn: bigint;
|
|
2129
|
+
*
|
|
2130
|
+
* @field({ type: option('u64') })
|
|
2131
|
+
* minAmountOut?: bigint;
|
|
2132
|
+
* }
|
|
2133
|
+
*
|
|
2134
|
+
* const data = serializeBorsh(new SwapInstruction({
|
|
2135
|
+
* instruction: 1,
|
|
2136
|
+
* amountIn: 1000n,
|
|
2137
|
+
* minAmountOut: 900n,
|
|
2138
|
+
* }));
|
|
2139
|
+
* ```
|
|
2140
|
+
*/
|
|
2141
|
+
declare function serializeBorsh<T>(data: T): Uint8Array;
|
|
2142
|
+
/**
|
|
2143
|
+
* Deserializes Borsh-encoded data into a typed object.
|
|
2144
|
+
*
|
|
2145
|
+
* @param data - Borsh-encoded bytes
|
|
2146
|
+
* @param type - Class constructor for the target type
|
|
2147
|
+
* @returns Deserialized object instance
|
|
2148
|
+
*/
|
|
2149
|
+
declare function deserializeBorsh<T>(data: Uint8Array, type: new () => T): T;
|
|
2150
|
+
|
|
2151
|
+
/**
|
|
2152
|
+
* Serializes a u16 value into compact encoding.
|
|
2153
|
+
*
|
|
2154
|
+
* @param buffer - Output buffer to append bytes to
|
|
2155
|
+
* @param value - Value to encode (0-65535)
|
|
2156
|
+
* @throws {TransactionError} If value is out of range
|
|
2157
|
+
*/
|
|
2158
|
+
declare function serializeCompactU16(buffer: number[], value: number): void;
|
|
2159
|
+
/**
|
|
2160
|
+
* Deserializes a compact-u16 value from bytes.
|
|
2161
|
+
*
|
|
2162
|
+
* @param data - Input byte array
|
|
2163
|
+
* @param currentCursor - Starting position in the array
|
|
2164
|
+
* @returns Tuple of [decoded value, new cursor position]
|
|
2165
|
+
* @throws {TransactionError} If data is insufficient or malformed
|
|
2166
|
+
*/
|
|
2167
|
+
declare function deserializeCompactU16(data: Uint8Array, currentCursor: number): [number, number];
|
|
2168
|
+
/**
|
|
2169
|
+
* Writes a compact-u16 value directly to a buffer (zero-copy).
|
|
2170
|
+
*
|
|
2171
|
+
* Optimized version for in-place writing without intermediate allocations.
|
|
2172
|
+
*
|
|
2173
|
+
* @param buffer - Target buffer
|
|
2174
|
+
* @param offset - Starting position to write at
|
|
2175
|
+
* @param value - Value to encode (0-127 only, uses 1-2 bytes)
|
|
2176
|
+
* @returns New offset after writing
|
|
2177
|
+
*/
|
|
2178
|
+
declare function writeCompactU16(buffer: Uint8Array, offset: number, value: number): number;
|
|
2179
|
+
|
|
2180
|
+
/**
|
|
2181
|
+
* Interface for signing messages and transactions.
|
|
2182
|
+
*
|
|
2183
|
+
* Enables multiple signing strategies:
|
|
2184
|
+
* - **KeypairSigner**: Local keypair signing
|
|
2185
|
+
* - **Browser Wallet**: Browser extension integration
|
|
2186
|
+
* - **Hardware Wallet**: Ledger, Trezor, etc.
|
|
2187
|
+
* - **Remote Signer**: API-based signing services
|
|
2188
|
+
*
|
|
2189
|
+
* @example
|
|
2190
|
+
* ```typescript
|
|
2191
|
+
* // Browser wallet implementation
|
|
2192
|
+
* class BrowserWalletSigner implements Signer {
|
|
2193
|
+
* async getPublicKey(): Promise<PublicKey> {
|
|
2194
|
+
* const pubkey = await window.rialoWallet.getPublicKey();
|
|
2195
|
+
* return PublicKey.fromString(pubkey);
|
|
2196
|
+
* }
|
|
2197
|
+
*
|
|
2198
|
+
* async signMessage(message: Uint8Array): Promise<Signature> {
|
|
2199
|
+
* const sig = await window.rialoWallet.signMessage(message);
|
|
2200
|
+
* return Signature.fromBytes(sig);
|
|
2201
|
+
* }
|
|
2202
|
+
* }
|
|
2203
|
+
*
|
|
2204
|
+
* // Usage
|
|
2205
|
+
* const signer = new BrowserWalletSigner();
|
|
2206
|
+
* const publicKey = await signer.getPublicKey();
|
|
2207
|
+
* const signature = await signer.signMessage(message);
|
|
2208
|
+
* ```
|
|
2209
|
+
*/
|
|
2210
|
+
interface Signer {
|
|
2211
|
+
/**
|
|
2212
|
+
* Retrieves the signer's public key.
|
|
2213
|
+
*
|
|
2214
|
+
* **Note**: May trigger wallet connection prompts for browser wallets.
|
|
2215
|
+
*/
|
|
2216
|
+
getPublicKey(): Promise<PublicKey>;
|
|
2217
|
+
/**
|
|
2218
|
+
* Signs arbitrary message bytes.
|
|
2219
|
+
*
|
|
2220
|
+
* @param message - Message bytes to sign
|
|
2221
|
+
* @returns Ed25519 signature over the message
|
|
2222
|
+
*/
|
|
2223
|
+
signMessage(message: Uint8Array): Promise<Signature>;
|
|
2224
|
+
}
|
|
2225
|
+
|
|
2226
|
+
/**
|
|
2227
|
+
* Signer implementation using a local Ed25519 keypair.
|
|
2228
|
+
*
|
|
2229
|
+
* Provides synchronous signing without external dependencies.
|
|
2230
|
+
* Suitable for server-side applications, CLIs, and testing.
|
|
2231
|
+
*
|
|
2232
|
+
* @example
|
|
2233
|
+
* ```typescript
|
|
2234
|
+
* import { Keypair, KeypairSigner } from '@rialo/ts-cdk';
|
|
2235
|
+
*
|
|
2236
|
+
* // Generate new keypair
|
|
2237
|
+
* const keypair = Keypair.generate();
|
|
2238
|
+
* const signer = new KeypairSigner(keypair);
|
|
2239
|
+
*
|
|
2240
|
+
* // Or from mnemonic
|
|
2241
|
+
* const mnemonic = Mnemonic.generate();
|
|
2242
|
+
* const keypair = await mnemonic.toKeypair(0);
|
|
2243
|
+
* const signer = new KeypairSigner(keypair);
|
|
2244
|
+
*
|
|
2245
|
+
* // Sign messages
|
|
2246
|
+
* const publicKey = await signer.getPublicKey();
|
|
2247
|
+
* const signature = await signer.signMessage(message);
|
|
2248
|
+
* ```
|
|
2249
|
+
*/
|
|
2250
|
+
declare class KeypairSigner implements Signer {
|
|
2251
|
+
private readonly keypair;
|
|
2252
|
+
constructor(keypair: Keypair);
|
|
2253
|
+
/**
|
|
2254
|
+
* Returns the keypair's public key.
|
|
2255
|
+
*/
|
|
2256
|
+
getPublicKey(): Promise<PublicKey>;
|
|
2257
|
+
/**
|
|
2258
|
+
* Signs a message using the keypair's private key.
|
|
2259
|
+
*/
|
|
2260
|
+
signMessage(message: Uint8Array): Promise<Signature>;
|
|
2261
|
+
}
|
|
2262
|
+
|
|
2263
|
+
/**
|
|
2264
|
+
* Metadata about an account in a transaction.
|
|
2265
|
+
*/
|
|
2266
|
+
interface AccountMeta {
|
|
2267
|
+
/** Account public key */
|
|
2268
|
+
readonly pubkey: PublicKey;
|
|
2269
|
+
/** Whether this account must sign the transaction */
|
|
2270
|
+
readonly isSigner: boolean;
|
|
2271
|
+
/** Whether this account's data will be modified */
|
|
2272
|
+
readonly isWritable: boolean;
|
|
2273
|
+
}
|
|
2274
|
+
/**
|
|
2275
|
+
* An instruction to execute on-chain.
|
|
2276
|
+
*/
|
|
2277
|
+
interface Instruction {
|
|
2278
|
+
/** Program that will execute this instruction */
|
|
2279
|
+
readonly programId: PublicKey;
|
|
2280
|
+
/** Accounts used by this instruction */
|
|
2281
|
+
readonly accounts: readonly AccountMeta[];
|
|
2282
|
+
/** Instruction-specific data */
|
|
2283
|
+
readonly data: Uint8Array;
|
|
2284
|
+
}
|
|
2285
|
+
/**
|
|
2286
|
+
* Message header containing signature requirements.
|
|
2287
|
+
*/
|
|
2288
|
+
interface MessageHeader {
|
|
2289
|
+
/** Number of signatures required */
|
|
2290
|
+
readonly numRequiredSignatures: number;
|
|
2291
|
+
/** Number of read-only signed accounts */
|
|
2292
|
+
readonly numReadonlySignedAccounts: number;
|
|
2293
|
+
/** Number of read-only unsigned accounts */
|
|
2294
|
+
readonly numReadonlyUnsignedAccounts: number;
|
|
2295
|
+
}
|
|
2296
|
+
/**
|
|
2297
|
+
* Compiled instruction with account indices.
|
|
2298
|
+
*/
|
|
2299
|
+
interface CompiledInstruction {
|
|
2300
|
+
/** Index of program in account keys array */
|
|
2301
|
+
readonly programIdIndex: number;
|
|
2302
|
+
/** Indices of accounts in account keys array */
|
|
2303
|
+
readonly accountKeyIndexes: readonly number[];
|
|
2304
|
+
/** Instruction data */
|
|
2305
|
+
readonly data: Uint8Array;
|
|
2306
|
+
}
|
|
2307
|
+
|
|
2308
|
+
/**
|
|
2309
|
+
* Account metadata table for deduplication and sorting.
|
|
2310
|
+
* Avoids: Complex account sorting logic scattered throughout builder
|
|
2311
|
+
*/
|
|
2312
|
+
|
|
2313
|
+
/**
|
|
2314
|
+
* Internal account entry with aggregated metadata.
|
|
2315
|
+
*/
|
|
2316
|
+
interface AccountEntry {
|
|
2317
|
+
pubkey: PublicKey;
|
|
2318
|
+
isSigner: boolean;
|
|
2319
|
+
isWritable: boolean;
|
|
2320
|
+
}
|
|
2321
|
+
/**
|
|
2322
|
+
* Manages account deduplication and sorting for transaction messages.
|
|
2323
|
+
*
|
|
2324
|
+
* Accounts are sorted according to these rules:
|
|
2325
|
+
* 1. Signer + writable accounts first
|
|
2326
|
+
* 2. Then signer + readonly accounts
|
|
2327
|
+
* 3. Then non-signer + writable accounts
|
|
2328
|
+
* 4. Finally non-signer + readonly accounts
|
|
2329
|
+
* 5. Within each group, sort by public key bytes
|
|
2330
|
+
*
|
|
2331
|
+
* This matches Solana's account sorting rules for compatibility.
|
|
2332
|
+
*/
|
|
2333
|
+
declare class AccountMetaTable {
|
|
2334
|
+
private readonly accounts;
|
|
2335
|
+
private readonly accountOrder;
|
|
2336
|
+
private payerKey;
|
|
2337
|
+
/**
|
|
2338
|
+
* Set the fee payer for this transaction.
|
|
2339
|
+
* The fee payer is always pinned at index 0 in the sorted account list,
|
|
2340
|
+
* regardless of lexicographic ordering. This matches Solana's invariant
|
|
2341
|
+
* that account_keys[0] is always the fee payer.
|
|
2342
|
+
*/
|
|
2343
|
+
setFeePayer(pubkey: PublicKey): void;
|
|
2344
|
+
/**
|
|
2345
|
+
* Add or update an account in the table.
|
|
2346
|
+
* If account already exists, merges signer/writable flags (OR operation).
|
|
2347
|
+
*/
|
|
2348
|
+
add(meta: AccountMeta): void;
|
|
2349
|
+
/**
|
|
2350
|
+
* Add multiple accounts at once.
|
|
2351
|
+
*/
|
|
2352
|
+
addAll(metas: readonly AccountMeta[]): void;
|
|
2353
|
+
/**
|
|
2354
|
+
* Get the index of an account in the sorted order.
|
|
2355
|
+
* Returns -1 if account not found.
|
|
2356
|
+
*/
|
|
2357
|
+
getIndex(pubkey: PublicKey): number;
|
|
2358
|
+
/**
|
|
2359
|
+
* Get sorted accounts according to transaction rules.
|
|
2360
|
+
*/
|
|
2361
|
+
getSortedAccounts(): readonly AccountEntry[];
|
|
2362
|
+
/**
|
|
2363
|
+
* Get the message header based on sorted accounts.
|
|
2364
|
+
*/
|
|
2365
|
+
getHeader(): MessageHeader;
|
|
2366
|
+
/**
|
|
2367
|
+
* Get sorted public keys.
|
|
2368
|
+
*/
|
|
2369
|
+
getPublicKeys(): readonly PublicKey[];
|
|
2370
|
+
/**
|
|
2371
|
+
* Get number of accounts in table.
|
|
2372
|
+
*/
|
|
2373
|
+
size(): number;
|
|
2374
|
+
}
|
|
2375
|
+
|
|
2376
|
+
/**
|
|
2377
|
+
* Error codes for transaction operations.
|
|
2378
|
+
*/
|
|
2379
|
+
declare enum TransactionErrorCode {
|
|
2380
|
+
INVALID_INSTRUCTION = "INVALID_INSTRUCTION",
|
|
2381
|
+
INVALID_ACCOUNT_META = "INVALID_ACCOUNT_META",
|
|
2382
|
+
NO_INSTRUCTIONS = "NO_INSTRUCTIONS",
|
|
2383
|
+
DUPLICATE_ACCOUNT = "DUPLICATE_ACCOUNT",
|
|
2384
|
+
MISSING_SIGNATURE = "MISSING_SIGNATURE",
|
|
2385
|
+
INVALID_SIGNATURE = "INVALID_SIGNATURE",
|
|
2386
|
+
SIGNATURE_OUT_OF_BOUNDS = "SIGNATURE_OUT_OF_BOUNDS",
|
|
2387
|
+
SIGNER_NOT_FOUND = "SIGNER_NOT_FOUND",
|
|
2388
|
+
ALREADY_SIGNED = "ALREADY_SIGNED",
|
|
2389
|
+
INVALID_MESSAGE_FORMAT = "INVALID_MESSAGE_FORMAT",
|
|
2390
|
+
INSUFFICIENT_DATA = "INSUFFICIENT_DATA",
|
|
2391
|
+
SERIALIZATION_FAILED = "SERIALIZATION_FAILED",
|
|
2392
|
+
SIMULATION_FAILED = "SIMULATION_FAILED",
|
|
2393
|
+
INSUFFICIENT_FUNDS = "INSUFFICIENT_FUNDS",
|
|
2394
|
+
BLOCKHASH_EXPIRED = "BLOCKHASH_EXPIRED"
|
|
2395
|
+
}
|
|
2396
|
+
/**
|
|
2397
|
+
* Error class for transaction operations with structured error information.
|
|
2398
|
+
*/
|
|
2399
|
+
declare class TransactionError extends Error {
|
|
2400
|
+
readonly code: TransactionErrorCode;
|
|
2401
|
+
readonly details?: Record<string, unknown> | undefined;
|
|
2402
|
+
constructor(code: TransactionErrorCode, message: string, details?: Record<string, unknown> | undefined);
|
|
2403
|
+
static noInstructions(): TransactionError;
|
|
2404
|
+
static signerNotFound(pubkey: string): TransactionError;
|
|
2405
|
+
static missingSignature(index: number, pubkey: string): TransactionError;
|
|
2406
|
+
static simulationFailed(logs: string[], error: string): TransactionError;
|
|
2407
|
+
static insufficientFunds(required: bigint, available: bigint): TransactionError;
|
|
2408
|
+
toJSON(): {
|
|
2409
|
+
code: TransactionErrorCode;
|
|
2410
|
+
message: string;
|
|
2411
|
+
details?: Record<string, unknown>;
|
|
2412
|
+
};
|
|
2413
|
+
}
|
|
2414
|
+
|
|
2415
|
+
/**
|
|
2416
|
+
* Create an instruction with Borsh-encoded data.
|
|
2417
|
+
*
|
|
2418
|
+
* @example
|
|
2419
|
+
* ```typescript
|
|
2420
|
+
* // Define your instruction data class
|
|
2421
|
+
* class MyInstructionData {
|
|
2422
|
+
* @field({ type: 'u8' })
|
|
2423
|
+
* instruction: number;
|
|
2424
|
+
*
|
|
2425
|
+
* @field({ type: 'u64' })
|
|
2426
|
+
* amount: bigint;
|
|
2427
|
+
*
|
|
2428
|
+
* @field({ type: option('string') })
|
|
2429
|
+
* memo?: string;
|
|
2430
|
+
* }
|
|
2431
|
+
*
|
|
2432
|
+
* // Create instruction
|
|
2433
|
+
* const instruction = createBorshInstruction({
|
|
2434
|
+
* programId: myProgramId,
|
|
2435
|
+
* accounts: [
|
|
2436
|
+
* { pubkey: account1, isSigner: true, isWritable: true },
|
|
2437
|
+
* { pubkey: account2, isSigner: false, isWritable: false },
|
|
2438
|
+
* ],
|
|
2439
|
+
* data: new MyInstructionData({
|
|
2440
|
+
* instruction: 5,
|
|
2441
|
+
* amount: 1000n,
|
|
2442
|
+
* memo: "Hello, Rialo!",
|
|
2443
|
+
* }),
|
|
2444
|
+
* });
|
|
2445
|
+
* ```
|
|
2446
|
+
*/
|
|
2447
|
+
declare function createBorshInstruction<T>(params: {
|
|
2448
|
+
programId: PublicKey;
|
|
2449
|
+
accounts: AccountMeta[];
|
|
2450
|
+
data: T;
|
|
2451
|
+
}): Instruction;
|
|
2452
|
+
/**
|
|
2453
|
+
* Helper for creating Borsh-serialized instruction data from a plain object.
|
|
2454
|
+
*
|
|
2455
|
+
* This is useful when you don't want to define a class with decorators.
|
|
2456
|
+
*
|
|
2457
|
+
* @example
|
|
2458
|
+
* ```typescript
|
|
2459
|
+
* const data = encodeBorshData({
|
|
2460
|
+
* instruction: { type: 'u8', value: 1 },
|
|
2461
|
+
* amount: { type: 'u64', value: 1000n },
|
|
2462
|
+
* recipient: { type: fixedArray('u8', 32), value: recipientBytes },
|
|
2463
|
+
* });
|
|
2464
|
+
* ```
|
|
2465
|
+
*/
|
|
2466
|
+
declare function encodeBorshData(_schema: Record<string, {
|
|
2467
|
+
type: unknown;
|
|
2468
|
+
value: unknown;
|
|
2469
|
+
}>): Uint8Array;
|
|
2470
|
+
|
|
2471
|
+
/**
|
|
2472
|
+
* System program instruction types.
|
|
2473
|
+
*/
|
|
2474
|
+
declare enum SystemInstruction {
|
|
2475
|
+
CreateAccount = 0,
|
|
2476
|
+
Assign = 1,
|
|
2477
|
+
Transfer = 2,
|
|
2478
|
+
CreateAccountWithSeed = 3,
|
|
2479
|
+
AdvanceNonceAccount = 4,
|
|
2480
|
+
WithdrawNonceAccount = 5,
|
|
2481
|
+
InitializeNonceAccount = 6,
|
|
2482
|
+
AuthorizeNonceAccount = 7,
|
|
2483
|
+
Allocate = 8,
|
|
2484
|
+
AllocateWithSeed = 9,
|
|
2485
|
+
AssignWithSeed = 10,
|
|
2486
|
+
TransferWithSeed = 11
|
|
2487
|
+
}
|
|
2488
|
+
/**
|
|
2489
|
+
* Create a transfer instruction.
|
|
2490
|
+
*
|
|
2491
|
+
* Transfers native tokens from one account to another.
|
|
2492
|
+
*
|
|
2493
|
+
* @param from - Source account (must be signer)
|
|
2494
|
+
* @param to - Destination account
|
|
2495
|
+
* @param amount - Amount to transfer in smallest denomination (kelvins)
|
|
2496
|
+
*
|
|
2497
|
+
* @example
|
|
2498
|
+
* ```typescript
|
|
2499
|
+
* const instruction = transferInstruction(fromPubkey, toPubkey, 1_000_000n);
|
|
2500
|
+
*
|
|
2501
|
+
* const tx = TransactionBuilder.create()
|
|
2502
|
+
* .setPayer(fromPubkey)
|
|
2503
|
+
* .addInstruction(instruction)
|
|
2504
|
+
* .build();
|
|
2505
|
+
* ```
|
|
2506
|
+
*/
|
|
2507
|
+
declare function transferInstruction(from: PublicKey, to: PublicKey, amount: bigint): Instruction;
|
|
2508
|
+
/**
|
|
2509
|
+
* Create an account creation instruction.
|
|
2510
|
+
*
|
|
2511
|
+
* @param from - Funding account (must be signer)
|
|
2512
|
+
* @param newAccount - New account to create (must be signer)
|
|
2513
|
+
* @param kelvins - Initial balance for new account
|
|
2514
|
+
* @param space - Number of bytes to allocate for account data
|
|
2515
|
+
* @param owner - Program that will own the new account
|
|
2516
|
+
*/
|
|
2517
|
+
declare function createAccount(from: PublicKey, newAccount: PublicKey, kelvins: bigint, space: bigint, owner: PublicKey): Instruction;
|
|
2518
|
+
/**
|
|
2519
|
+
* Create an allocate instruction.
|
|
2520
|
+
*
|
|
2521
|
+
* Allocates space for an account's data. The account must be owned by
|
|
2522
|
+
* the system program and must sign the transaction.
|
|
2523
|
+
*
|
|
2524
|
+
* @param account - Account to allocate space for (must be signer)
|
|
2525
|
+
* @param space - Number of bytes to allocate
|
|
2526
|
+
*/
|
|
2527
|
+
declare function allocateInstruction(account: PublicKey, space: bigint): Instruction;
|
|
2528
|
+
/**
|
|
2529
|
+
* Create an assign instruction.
|
|
2530
|
+
*
|
|
2531
|
+
* Changes the owner of an account. The account must currently be owned
|
|
2532
|
+
* by the system program and must sign the transaction.
|
|
2533
|
+
*
|
|
2534
|
+
* @param account - Account to reassign (must be signer)
|
|
2535
|
+
* @param owner - New owner program
|
|
2536
|
+
*/
|
|
2537
|
+
declare function assignInstruction(account: PublicKey, owner: PublicKey): Instruction;
|
|
2538
|
+
|
|
2539
|
+
/**
|
|
2540
|
+
* An unsigned transaction message ready to be signed.
|
|
2541
|
+
*
|
|
2542
|
+
* This is the data that gets signed by transaction signers.
|
|
2543
|
+
* It's immutable to prevent accidental modification after creation.
|
|
2544
|
+
*
|
|
2545
|
+
* @example
|
|
2546
|
+
* ```typescript
|
|
2547
|
+
* const message = MessageBuilder.create()
|
|
2548
|
+
* .setPayer(payer)
|
|
2549
|
+
* .setValidFrom(validFrom)
|
|
2550
|
+
* .addInstruction(transferInstruction)
|
|
2551
|
+
* .build();
|
|
2552
|
+
*
|
|
2553
|
+
* // Serialize for signing
|
|
2554
|
+
* const messageBytes = message.serialize();
|
|
2555
|
+
* ```
|
|
2556
|
+
*/
|
|
2557
|
+
declare class Message {
|
|
2558
|
+
/** Message header with signature requirements */
|
|
2559
|
+
readonly header: MessageHeader;
|
|
2560
|
+
/** All account public keys referenced in the transaction */
|
|
2561
|
+
readonly accountKeys: readonly PublicKey[];
|
|
2562
|
+
/** Transaction valid from (milliseconds since Unix epoch) */
|
|
2563
|
+
validFrom?: bigint;
|
|
2564
|
+
/** Compiled instructions with account indices */
|
|
2565
|
+
readonly instructions: readonly CompiledInstruction[];
|
|
2566
|
+
/** Cached serialized bytes */
|
|
2567
|
+
private serializedCache?;
|
|
2568
|
+
constructor(header: MessageHeader, accountKeys: readonly PublicKey[], validFrom: bigint, instructions: readonly CompiledInstruction[]);
|
|
2569
|
+
/**
|
|
2570
|
+
* Serialize message to bytes for signing.
|
|
2571
|
+
* Result is cached for performance.
|
|
2572
|
+
*/
|
|
2573
|
+
serialize(): Uint8Array;
|
|
2574
|
+
/**
|
|
2575
|
+
* Deserialize a message from wire format.
|
|
2576
|
+
*
|
|
2577
|
+
* @param data - Serialized message bytes
|
|
2578
|
+
* @returns Deserialized Message
|
|
2579
|
+
*/
|
|
2580
|
+
static deserialize(data: Uint8Array): Message;
|
|
2581
|
+
private serializeInternal;
|
|
2582
|
+
private serializeCompactArray;
|
|
2583
|
+
private serializeCompactU16;
|
|
2584
|
+
/**
|
|
2585
|
+
* Get all signers required for this message.
|
|
2586
|
+
*/
|
|
2587
|
+
getSigners(): readonly PublicKey[];
|
|
2588
|
+
/**
|
|
2589
|
+
* Check if a public key is a required signer.
|
|
2590
|
+
*/
|
|
2591
|
+
isSignerRequired(pubkey: PublicKey): boolean;
|
|
2592
|
+
/**
|
|
2593
|
+
* Get the index of a signer in the signers array.
|
|
2594
|
+
* Returns -1 if not a signer.
|
|
2595
|
+
*/
|
|
2596
|
+
getSignerIndex(pubkey: PublicKey): number;
|
|
2597
|
+
}
|
|
2598
|
+
|
|
2599
|
+
/**
|
|
2600
|
+
* A transaction with zero or more signatures.
|
|
2601
|
+
*
|
|
2602
|
+
* Transactions are immutable - signing methods return new instances.
|
|
2603
|
+
* This prevents accidental modification and signature tampering.
|
|
2604
|
+
*
|
|
2605
|
+
* @example
|
|
2606
|
+
* ```typescript
|
|
2607
|
+
* // Simple signing
|
|
2608
|
+
* const tx = builder.build();
|
|
2609
|
+
* const signed = tx.sign(keypair);
|
|
2610
|
+
*
|
|
2611
|
+
* // Method chaining
|
|
2612
|
+
* const signed = tx
|
|
2613
|
+
* .sign(keypair1)
|
|
2614
|
+
* .sign(keypair2)
|
|
2615
|
+
* .sign(keypair3);
|
|
2616
|
+
*
|
|
2617
|
+
* // Multi-sig convenience
|
|
2618
|
+
* const signed = tx.signAll([keypair1, keypair2, keypair3]);
|
|
2619
|
+
* ```
|
|
2620
|
+
*/
|
|
2621
|
+
declare class Transaction {
|
|
2622
|
+
/** The unsigned message */
|
|
2623
|
+
private readonly message;
|
|
2624
|
+
/** Signatures (64 bytes each), aligned with message.header.numRequiredSignatures */
|
|
2625
|
+
private readonly signatures;
|
|
2626
|
+
private constructor();
|
|
2627
|
+
/**
|
|
2628
|
+
* Create an unsigned transaction from a message.
|
|
2629
|
+
* All signature slots are initialized to zero.
|
|
2630
|
+
*
|
|
2631
|
+
* @internal - Users should use TransactionBuilder instead
|
|
2632
|
+
*/
|
|
2633
|
+
static fromMessage(message: Message): Transaction;
|
|
2634
|
+
/**
|
|
2635
|
+
* Create transaction from message and existing signatures.
|
|
2636
|
+
* @internal
|
|
2637
|
+
*/
|
|
2638
|
+
static fromMessageAndSignatures(message: Message, signatures: readonly Uint8Array[]): Transaction;
|
|
2639
|
+
/**
|
|
2640
|
+
* Deserialize a transaction from wire format.
|
|
2641
|
+
*/
|
|
2642
|
+
static deserialize(data: Uint8Array): Transaction;
|
|
2643
|
+
getMessage(): Message;
|
|
2644
|
+
/**
|
|
2645
|
+
* Sign the transaction with a keypair.
|
|
2646
|
+
* Returns a NEW Transaction instance.
|
|
2647
|
+
*
|
|
2648
|
+
* @param keypair - Keypair to sign with
|
|
2649
|
+
* @returns New Transaction instance with signature added
|
|
2650
|
+
*
|
|
2651
|
+
* @example
|
|
2652
|
+
* ```typescript
|
|
2653
|
+
* const signedTx = tx.sign(keypair);
|
|
2654
|
+
* await client.sendTransaction(signedTx.serialize());
|
|
2655
|
+
* ```
|
|
2656
|
+
*/
|
|
2657
|
+
sign(keypair: Keypair): Transaction;
|
|
2658
|
+
/**
|
|
2659
|
+
* Sign with multiple keypairs at once.
|
|
2660
|
+
* Returns a NEW Transaction instance.
|
|
2661
|
+
*
|
|
2662
|
+
* @example
|
|
2663
|
+
* ```typescript
|
|
2664
|
+
* const signed = tx.signAll([keypair1, keypair2, keypair3]);
|
|
2665
|
+
* ```
|
|
2666
|
+
*/
|
|
2667
|
+
signAll(keypairs: Keypair[]): Transaction;
|
|
2668
|
+
/**
|
|
2669
|
+
* Sign the transaction with a Signer interface (async).
|
|
2670
|
+
* Returns a NEW Transaction instance.
|
|
2671
|
+
*
|
|
2672
|
+
* @example
|
|
2673
|
+
* ```typescript
|
|
2674
|
+
* const signedTx = await tx.signWith(browserWallet);
|
|
2675
|
+
* ```
|
|
2676
|
+
*/
|
|
2677
|
+
signWith(signer: Signer): Promise<Transaction>;
|
|
2678
|
+
/**
|
|
2679
|
+
* Sign with multiple signers.
|
|
2680
|
+
* Returns a NEW Transaction instance.
|
|
2681
|
+
*/
|
|
2682
|
+
signAllWith(signers: Signer[]): Promise<Transaction>;
|
|
2683
|
+
/**
|
|
2684
|
+
* Partially sign the transaction (for multi-sig transactions).
|
|
2685
|
+
* Returns a NEW Transaction instance.
|
|
2686
|
+
*
|
|
2687
|
+
* @example
|
|
2688
|
+
* ```typescript
|
|
2689
|
+
* const signedTx = tx
|
|
2690
|
+
* .partialSign(signer1)
|
|
2691
|
+
* .partialSign(signer2);
|
|
2692
|
+
* ```
|
|
2693
|
+
*/
|
|
2694
|
+
partialSign(keypair: Keypair): Transaction;
|
|
2695
|
+
/**
|
|
2696
|
+
* Partially sign with a Signer interface (async).
|
|
2697
|
+
* Returns a NEW Transaction instance.
|
|
2698
|
+
*/
|
|
2699
|
+
partialSignWith(signer: Signer): Promise<Transaction>;
|
|
2700
|
+
/**
|
|
2701
|
+
* Add a signature at a specific index.
|
|
2702
|
+
* Returns a NEW Transaction instance.
|
|
2703
|
+
*
|
|
2704
|
+
* Most users should use sign() or signAll() instead.
|
|
2705
|
+
*/
|
|
2706
|
+
addSignature(index: number, signature: Signature | Uint8Array): Transaction;
|
|
2707
|
+
/**
|
|
2708
|
+
* Add a signature for a specific public key.
|
|
2709
|
+
* Returns a NEW Transaction instance.
|
|
2710
|
+
*
|
|
2711
|
+
* Most users should use sign() or signAll() instead.
|
|
2712
|
+
*/
|
|
2713
|
+
addSignatureForPubkey(pubkey: PublicKey, signature: Signature | Uint8Array): Transaction;
|
|
2714
|
+
/**
|
|
2715
|
+
* Check if transaction is fully signed (all signatures present).
|
|
2716
|
+
*/
|
|
2717
|
+
isSigned(): boolean;
|
|
2718
|
+
/**
|
|
2719
|
+
* Check if a specific signature slot is filled.
|
|
2720
|
+
*/
|
|
2721
|
+
isSignaturePresent(index: number): boolean;
|
|
2722
|
+
/**
|
|
2723
|
+
* Get all signatures (returns copies to prevent mutation).
|
|
2724
|
+
*/
|
|
2725
|
+
getSignatures(): readonly Uint8Array[];
|
|
2726
|
+
/**
|
|
2727
|
+
* Get a specific signature (returns copy).
|
|
2728
|
+
*/
|
|
2729
|
+
getSignature(index: number): Uint8Array;
|
|
2730
|
+
/**
|
|
2731
|
+
* Get a specific signature for a public key.
|
|
2732
|
+
*/
|
|
2733
|
+
getSignatureForPubkey(pubkey: PublicKey): Uint8Array;
|
|
2734
|
+
/**
|
|
2735
|
+
* Get required signers for this transaction.
|
|
2736
|
+
*/
|
|
2737
|
+
getSigners(): readonly PublicKey[];
|
|
2738
|
+
/**
|
|
2739
|
+
* Get the number of required signatures.
|
|
2740
|
+
*/
|
|
2741
|
+
getRequiredSignatureCount(): number;
|
|
2742
|
+
/**
|
|
2743
|
+
* Throw an error if the transaction is not fully signed.
|
|
2744
|
+
*
|
|
2745
|
+
* @throws {TransactionError} If transaction is not fully signed
|
|
2746
|
+
*
|
|
2747
|
+
* @example
|
|
2748
|
+
* ```typescript
|
|
2749
|
+
* signedTx.ensureSigned(); // Throws if not signed
|
|
2750
|
+
* await client.sendTransaction(signedTx.serialize());
|
|
2751
|
+
* ```
|
|
2752
|
+
*/
|
|
2753
|
+
ensureSigned(): void;
|
|
2754
|
+
/**
|
|
2755
|
+
* Serialize transaction to wire format.
|
|
2756
|
+
*/
|
|
2757
|
+
serialize(): Uint8Array;
|
|
2758
|
+
}
|
|
2759
|
+
|
|
2760
|
+
/**
|
|
2761
|
+
* Fluent API for building transactions.
|
|
2762
|
+
* Returns Transaction directly (not Message).
|
|
2763
|
+
*/
|
|
2764
|
+
|
|
2765
|
+
/**
|
|
2766
|
+
* Builder for creating transactions with a fluent API.
|
|
2767
|
+
*
|
|
2768
|
+
* Provides an intuitive interface for constructing transactions.
|
|
2769
|
+
* Call build() to get an unsigned Transaction ready for signing.
|
|
2770
|
+
*
|
|
2771
|
+
* @example
|
|
2772
|
+
* ```typescript
|
|
2773
|
+
* // Simple transfer
|
|
2774
|
+
* const tx = TransactionBuilder.create()
|
|
2775
|
+
* .setPayer(payer)
|
|
2776
|
+
* .setValidFrom(validFrom)
|
|
2777
|
+
* .addInstruction(transfer(from, to, 1_000_000n))
|
|
2778
|
+
* .build();
|
|
2779
|
+
*
|
|
2780
|
+
* const signedTx = tx.sign(keypair);
|
|
2781
|
+
* await client.transaction.sendTransaction(signedTx.serialize());
|
|
2782
|
+
* ```
|
|
2783
|
+
*
|
|
2784
|
+
* @example
|
|
2785
|
+
* ```typescript
|
|
2786
|
+
* // Multi-instruction transaction
|
|
2787
|
+
* const tx = TransactionBuilder.create()
|
|
2788
|
+
* .setPayer(payer)
|
|
2789
|
+
* .setValidFrom(validFrom)
|
|
2790
|
+
* .addInstruction(transfer(from, to, 1_000_000n))
|
|
2791
|
+
* .addInstruction(memoInstruction("Payment for invoice #123"))
|
|
2792
|
+
* .build();
|
|
2793
|
+
* ```
|
|
2794
|
+
*/
|
|
2795
|
+
declare class TransactionBuilder {
|
|
2796
|
+
private payer?;
|
|
2797
|
+
private validFrom?;
|
|
2798
|
+
private readonly instructions;
|
|
2799
|
+
private constructor();
|
|
2800
|
+
/**
|
|
2801
|
+
* Create a new transaction builder.
|
|
2802
|
+
*/
|
|
2803
|
+
static create(): TransactionBuilder;
|
|
2804
|
+
/**
|
|
2805
|
+
* Set the fee payer for this transaction.
|
|
2806
|
+
*
|
|
2807
|
+
* The payer will be the first account and must sign the transaction.
|
|
2808
|
+
* The payer pays for transaction fees.
|
|
2809
|
+
*
|
|
2810
|
+
* @param payer - Public key of the fee payer
|
|
2811
|
+
*/
|
|
2812
|
+
setPayer(payer: PublicKey): this;
|
|
2813
|
+
/**
|
|
2814
|
+
* Set the Transaction valid from.
|
|
2815
|
+
*
|
|
2816
|
+
* This is the time the transaction is valid from, in milliseconds since Unix epoch.
|
|
2817
|
+
* It can be used for additional replay protection or auditing.
|
|
2818
|
+
*
|
|
2819
|
+
* @param validFrom - Transaction valid from in milliseconds since Unix epoch
|
|
2820
|
+
*/
|
|
2821
|
+
setValidFrom(validFrom: bigint): this;
|
|
2822
|
+
/**
|
|
2823
|
+
* Add an instruction to the transaction.
|
|
2824
|
+
*
|
|
2825
|
+
* @param instruction - Instruction to add
|
|
2826
|
+
*/
|
|
2827
|
+
addInstruction(instruction: Instruction): this;
|
|
2828
|
+
/**
|
|
2829
|
+
* Add multiple instructions at once.
|
|
2830
|
+
*
|
|
2831
|
+
* @param instructions - Array of instructions to add
|
|
2832
|
+
*/
|
|
2833
|
+
addInstructions(instructions: readonly Instruction[]): this;
|
|
2834
|
+
/**
|
|
2835
|
+
* Build the transaction (unsigned).
|
|
2836
|
+
*
|
|
2837
|
+
* Returns an unsigned Transaction that's ready to be signed.
|
|
2838
|
+
*
|
|
2839
|
+
* @returns Unsigned Transaction
|
|
2840
|
+
* @throws {TransactionError} If payer, valid_from, or instructions are missing
|
|
2841
|
+
*
|
|
2842
|
+
* @example
|
|
2843
|
+
* ```typescript
|
|
2844
|
+
* const tx = builder.build();
|
|
2845
|
+
* const signedTx = tx.sign(keypair);
|
|
2846
|
+
* ```
|
|
2847
|
+
*/
|
|
2848
|
+
build(): Transaction;
|
|
2849
|
+
}
|
|
2850
|
+
|
|
2851
|
+
/**
|
|
2852
|
+
* Converts bytes to base64 string.
|
|
2853
|
+
*
|
|
2854
|
+
* Works in both browser and Node.js environments.
|
|
2855
|
+
*/
|
|
2856
|
+
declare function toBase64(bytes: Uint8Array): string;
|
|
2857
|
+
/**
|
|
2858
|
+
* Converts base64 string to bytes.
|
|
2859
|
+
*
|
|
2860
|
+
* Works in both browser and Node.js environments.
|
|
2861
|
+
*/
|
|
2862
|
+
declare function fromBase64(base64: string): Uint8Array;
|
|
2863
|
+
/**
|
|
2864
|
+
* Sleeps for the specified duration.
|
|
2865
|
+
*
|
|
2866
|
+
* @param ms - Milliseconds to sleep
|
|
2867
|
+
*/
|
|
2868
|
+
declare function sleep(ms: number): Promise<void>;
|
|
2869
|
+
/**
|
|
2870
|
+
* Calculates exponential backoff delay with jitter.
|
|
2871
|
+
*
|
|
2872
|
+
* @param attempt - Current retry attempt (0-indexed)
|
|
2873
|
+
* @param baseMs - Base delay in milliseconds
|
|
2874
|
+
* @param maxMs - Maximum delay in milliseconds
|
|
2875
|
+
* @returns Calculated delay with 30% random jitter
|
|
2876
|
+
*/
|
|
2877
|
+
declare function calculateBackoff(attempt: number, baseMs?: number, maxMs?: number): number;
|
|
2878
|
+
/**
|
|
2879
|
+
* Returns the devnet RPC URL.
|
|
2880
|
+
*/
|
|
2881
|
+
declare function getDevnetUrl(): string;
|
|
2882
|
+
/**
|
|
2883
|
+
* Returns the testnet RPC URL.
|
|
2884
|
+
*/
|
|
2885
|
+
declare function getTestnetUrl(): string;
|
|
2886
|
+
/**
|
|
2887
|
+
* Returns the mainnet RPC URL.
|
|
2888
|
+
*/
|
|
2889
|
+
declare function getMainnetUrl(): string;
|
|
2890
|
+
/**
|
|
2891
|
+
* Returns the localnet RPC URL.
|
|
2892
|
+
*/
|
|
2893
|
+
declare function getLocalnetUrl(): string;
|
|
2894
|
+
|
|
2895
|
+
export { type AccountFilter, type AccountInfo, type AccountMeta, AccountMetaTable, BASE_DERIVATION_PATH, BaseRpcClient, BincodeReader, type BincodeSchema, BincodeWriter, type Bump, type ChainDefinition, type CompiledInstruction, type ConfirmTransactionOptions, type ConfirmedTransaction, CryptoError, CryptoErrorCode, DEFAULT_NUM_ACCOUNTS, type EnumVariant, type EpochInfoResponse, type EventData, type GetAccountsByOwnerConfig, type GetAccountsByOwnerResponse, type GetHealthResponse, type GetSignaturesForAddressConfig, type GetTransactionsResponse, type GetWorkflowLineageRequest, type GetWorkflowLineageResponse, HttpTransport, type HttpTransportConfig, type IdentifierString, type InferSchema, 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, Schema, type Seed, type SendAndConfirmOptions, type SendTransactionOptions, Signature, type SignatureInfo, type SignatureStatus, type Signer, type StructField, 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, deserialize, deserializeBorsh, deserializeCompactU16, deserializeStrict, encodeBorshData, fromBase64, getDefaultRialoClientConfig, getDevnetUrl, getLocalnetUrl, getMainnetUrl, getTestnetUrl, isOnCurve, seedToBytes, serialize, serializeBorsh, serializeCompactU16, sleep, toBase64, transferInstruction, writeCompactU16 };
|