@bitgo/wasm-solana 1.4.1 → 1.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/dist/cjs/js/builder.d.ts +499 -0
  2. package/dist/cjs/js/builder.js +113 -0
  3. package/dist/cjs/js/index.d.ts +16 -0
  4. package/dist/cjs/js/index.js +79 -0
  5. package/dist/cjs/js/keypair.d.ts +47 -0
  6. package/dist/cjs/js/keypair.js +69 -0
  7. package/dist/cjs/js/parser.d.ts +253 -0
  8. package/dist/cjs/js/parser.js +58 -0
  9. package/dist/cjs/js/pubkey.d.ts +54 -0
  10. package/dist/cjs/js/pubkey.js +76 -0
  11. package/dist/cjs/js/transaction.d.ts +156 -0
  12. package/dist/cjs/js/transaction.js +176 -0
  13. package/dist/cjs/js/versioned.d.ts +177 -0
  14. package/dist/cjs/js/versioned.js +197 -0
  15. package/dist/cjs/js/wasm/wasm_solana.d.ts +1030 -0
  16. package/dist/cjs/js/wasm/wasm_solana.js +6216 -0
  17. package/dist/cjs/js/wasm/wasm_solana_bg.wasm +0 -0
  18. package/dist/cjs/js/wasm/wasm_solana_bg.wasm.d.ts +341 -0
  19. package/dist/cjs/package.json +1 -0
  20. package/dist/esm/js/builder.d.ts +499 -0
  21. package/dist/esm/js/builder.js +109 -0
  22. package/dist/esm/js/index.d.ts +16 -0
  23. package/dist/esm/js/index.js +24 -0
  24. package/dist/esm/js/keypair.d.ts +47 -0
  25. package/dist/esm/js/keypair.js +65 -0
  26. package/dist/esm/js/parser.d.ts +253 -0
  27. package/dist/esm/js/parser.js +55 -0
  28. package/dist/esm/js/pubkey.d.ts +54 -0
  29. package/dist/esm/js/pubkey.js +72 -0
  30. package/dist/esm/js/transaction.d.ts +156 -0
  31. package/dist/esm/js/transaction.js +172 -0
  32. package/dist/esm/js/versioned.d.ts +177 -0
  33. package/dist/esm/js/versioned.js +192 -0
  34. package/dist/esm/js/wasm/wasm_solana.d.ts +1030 -0
  35. package/dist/esm/js/wasm/wasm_solana.js +4 -0
  36. package/dist/esm/js/wasm/wasm_solana_bg.js +6138 -0
  37. package/dist/esm/js/wasm/wasm_solana_bg.wasm +0 -0
  38. package/dist/esm/js/wasm/wasm_solana_bg.wasm.d.ts +341 -0
  39. package/package.json +1 -1
@@ -0,0 +1,499 @@
1
+ /**
2
+ * Transaction building from high-level intents.
3
+ *
4
+ * Provides types and functions for building Solana transactions from a
5
+ * declarative intent structure, without requiring the full @solana/web3.js dependency.
6
+ */
7
+ import { Transaction } from "./transaction.js";
8
+ import { VersionedTransaction } from "./versioned.js";
9
+ /** Use a recent blockhash for the transaction */
10
+ export interface BlockhashNonceSource {
11
+ type: "blockhash";
12
+ /** The recent blockhash value (base58) */
13
+ value: string;
14
+ }
15
+ /** Use a durable nonce account for the transaction */
16
+ export interface DurableNonceSource {
17
+ type: "durable";
18
+ /** The nonce account address (base58) */
19
+ address: string;
20
+ /** The nonce authority address (base58) */
21
+ authority: string;
22
+ /** The nonce value stored in the account (base58) - this becomes the blockhash */
23
+ value: string;
24
+ }
25
+ /** Nonce source for the transaction */
26
+ export type NonceSource = BlockhashNonceSource | DurableNonceSource;
27
+ /**
28
+ * Address Lookup Table data for versioned transactions.
29
+ *
30
+ * ALTs allow transactions to reference more accounts than the legacy format
31
+ * by storing account addresses in on-chain lookup tables.
32
+ */
33
+ export interface AddressLookupTable {
34
+ /** The lookup table account address (base58) */
35
+ accountKey: string;
36
+ /** Indices of writable accounts in the lookup table */
37
+ writableIndexes: number[];
38
+ /** Indices of readonly accounts in the lookup table */
39
+ readonlyIndexes: number[];
40
+ }
41
+ /** SOL transfer instruction */
42
+ export interface TransferInstruction {
43
+ type: "transfer";
44
+ /** Source account (base58) */
45
+ from: string;
46
+ /** Destination account (base58) */
47
+ to: string;
48
+ /** Amount in lamports */
49
+ lamports: bigint;
50
+ }
51
+ /** Create new account instruction */
52
+ export interface CreateAccountInstruction {
53
+ type: "createAccount";
54
+ /** Funding account (base58) */
55
+ from: string;
56
+ /** New account address (base58) */
57
+ newAccount: string;
58
+ /** Lamports to transfer */
59
+ lamports: bigint;
60
+ /** Space to allocate in bytes */
61
+ space: number;
62
+ /** Owner program (base58) */
63
+ owner: string;
64
+ }
65
+ /** Advance durable nonce instruction */
66
+ export interface NonceAdvanceInstruction {
67
+ type: "nonceAdvance";
68
+ /** Nonce account address (base58) */
69
+ nonce: string;
70
+ /** Nonce authority (base58) */
71
+ authority: string;
72
+ }
73
+ /** Initialize nonce account instruction */
74
+ export interface NonceInitializeInstruction {
75
+ type: "nonceInitialize";
76
+ /** Nonce account address (base58) */
77
+ nonce: string;
78
+ /** Nonce authority (base58) */
79
+ authority: string;
80
+ }
81
+ /** Allocate space instruction */
82
+ export interface AllocateInstruction {
83
+ type: "allocate";
84
+ /** Account to allocate (base58) */
85
+ account: string;
86
+ /** Space to allocate in bytes */
87
+ space: number;
88
+ }
89
+ /** Assign account to program instruction */
90
+ export interface AssignInstruction {
91
+ type: "assign";
92
+ /** Account to assign (base58) */
93
+ account: string;
94
+ /** New owner program (base58) */
95
+ owner: string;
96
+ }
97
+ /** Memo instruction */
98
+ export interface MemoInstruction {
99
+ type: "memo";
100
+ /** The memo message */
101
+ message: string;
102
+ }
103
+ /** Compute budget instruction */
104
+ export interface ComputeBudgetInstruction {
105
+ type: "computeBudget";
106
+ /** Compute unit limit (optional) */
107
+ unitLimit?: number;
108
+ /** Compute unit price in micro-lamports (optional) */
109
+ unitPrice?: number;
110
+ }
111
+ /** Initialize a stake account instruction */
112
+ export interface StakeInitializeInstruction {
113
+ type: "stakeInitialize";
114
+ /** Stake account address (base58) */
115
+ stake: string;
116
+ /** Authorized staker pubkey (base58) */
117
+ staker: string;
118
+ /** Authorized withdrawer pubkey (base58) */
119
+ withdrawer: string;
120
+ }
121
+ /** Delegate stake to a validator instruction */
122
+ export interface StakeDelegateInstruction {
123
+ type: "stakeDelegate";
124
+ /** Stake account address (base58) */
125
+ stake: string;
126
+ /** Vote account (validator) to delegate to (base58) */
127
+ vote: string;
128
+ /** Stake authority (base58) */
129
+ authority: string;
130
+ }
131
+ /** Deactivate a stake account instruction */
132
+ export interface StakeDeactivateInstruction {
133
+ type: "stakeDeactivate";
134
+ /** Stake account address (base58) */
135
+ stake: string;
136
+ /** Stake authority (base58) */
137
+ authority: string;
138
+ }
139
+ /** Withdraw from a stake account instruction */
140
+ export interface StakeWithdrawInstruction {
141
+ type: "stakeWithdraw";
142
+ /** Stake account address (base58) */
143
+ stake: string;
144
+ /** Recipient address (base58) */
145
+ recipient: string;
146
+ /** Amount in lamports to withdraw */
147
+ lamports: bigint;
148
+ /** Withdraw authority (base58) */
149
+ authority: string;
150
+ }
151
+ /** Change stake account authorization instruction */
152
+ export interface StakeAuthorizeInstruction {
153
+ type: "stakeAuthorize";
154
+ /** Stake account address (base58) */
155
+ stake: string;
156
+ /** New authority pubkey (base58) */
157
+ newAuthority: string;
158
+ /** Authorization type: "staker" or "withdrawer" */
159
+ authorizeType: "staker" | "withdrawer";
160
+ /** Current authority (base58) */
161
+ authority: string;
162
+ }
163
+ /** Split stake account instruction (for partial deactivation) */
164
+ export interface StakeSplitInstruction {
165
+ type: "stakeSplit";
166
+ /** Source stake account address (base58) */
167
+ stake: string;
168
+ /** Destination stake account (must be uninitialized/created first) (base58) */
169
+ splitStake: string;
170
+ /** Stake authority (base58) */
171
+ authority: string;
172
+ /** Amount in lamports to split */
173
+ lamports: bigint;
174
+ }
175
+ /** Transfer tokens instruction (uses TransferChecked) */
176
+ export interface TokenTransferInstruction {
177
+ type: "tokenTransfer";
178
+ /** Source token account (base58) */
179
+ source: string;
180
+ /** Destination token account (base58) */
181
+ destination: string;
182
+ /** Token mint address (base58) */
183
+ mint: string;
184
+ /** Amount of tokens (in smallest units) */
185
+ amount: bigint;
186
+ /** Number of decimals for the token */
187
+ decimals: number;
188
+ /** Owner/authority of the source account (base58) */
189
+ authority: string;
190
+ /** Token program ID (optional, defaults to SPL Token) */
191
+ programId?: string;
192
+ }
193
+ /** Create an Associated Token Account instruction */
194
+ export interface CreateAssociatedTokenAccountInstruction {
195
+ type: "createAssociatedTokenAccount";
196
+ /** Payer for account creation (base58) */
197
+ payer: string;
198
+ /** Owner of the new ATA (base58) */
199
+ owner: string;
200
+ /** Token mint address (base58) */
201
+ mint: string;
202
+ /** Token program ID (optional, defaults to SPL Token) */
203
+ tokenProgramId?: string;
204
+ }
205
+ /** Close an Associated Token Account instruction */
206
+ export interface CloseAssociatedTokenAccountInstruction {
207
+ type: "closeAssociatedTokenAccount";
208
+ /** Token account to close (base58) */
209
+ account: string;
210
+ /** Destination for remaining lamports (base58) */
211
+ destination: string;
212
+ /** Authority of the account (base58) */
213
+ authority: string;
214
+ /** Token program ID (optional, defaults to SPL Token) */
215
+ programId?: string;
216
+ }
217
+ /** Mint tokens to an account instruction */
218
+ export interface MintToInstruction {
219
+ type: "mintTo";
220
+ /** Token mint address (base58) */
221
+ mint: string;
222
+ /** Destination token account (base58) */
223
+ destination: string;
224
+ /** Mint authority (base58) */
225
+ authority: string;
226
+ /** Amount of tokens to mint (in smallest units) */
227
+ amount: bigint;
228
+ /** Token program ID (optional, defaults to SPL Token) */
229
+ programId?: string;
230
+ }
231
+ /** Burn tokens from an account instruction */
232
+ export interface BurnInstruction {
233
+ type: "burn";
234
+ /** Token mint address (base58) */
235
+ mint: string;
236
+ /** Source token account to burn from (base58) */
237
+ account: string;
238
+ /** Token account authority (base58) */
239
+ authority: string;
240
+ /** Amount of tokens to burn (in smallest units) */
241
+ amount: bigint;
242
+ /** Token program ID (optional, defaults to SPL Token) */
243
+ programId?: string;
244
+ }
245
+ /** Approve a delegate to transfer tokens instruction */
246
+ export interface ApproveInstruction {
247
+ type: "approve";
248
+ /** Token account to approve delegation for (base58) */
249
+ account: string;
250
+ /** Delegate address (who can transfer) (base58) */
251
+ delegate: string;
252
+ /** Token account owner (base58) */
253
+ owner: string;
254
+ /** Amount of tokens to approve (in smallest units) */
255
+ amount: bigint;
256
+ /** Token program ID (optional, defaults to SPL Token) */
257
+ programId?: string;
258
+ }
259
+ /** Deposit SOL into a stake pool (Jito liquid staking) */
260
+ export interface StakePoolDepositSolInstruction {
261
+ type: "stakePoolDepositSol";
262
+ /** Stake pool address (base58) */
263
+ stakePool: string;
264
+ /** Withdraw authority PDA (base58) */
265
+ withdrawAuthority: string;
266
+ /** Reserve stake account (base58) */
267
+ reserveStake: string;
268
+ /** Funding account (SOL source, signer) (base58) */
269
+ fundingAccount: string;
270
+ /** Destination for pool tokens (base58) */
271
+ destinationPoolAccount: string;
272
+ /** Manager fee account (base58) */
273
+ managerFeeAccount: string;
274
+ /** Referral pool account (base58) */
275
+ referralPoolAccount: string;
276
+ /** Pool mint address (base58) */
277
+ poolMint: string;
278
+ /** Amount in lamports to deposit */
279
+ lamports: bigint;
280
+ }
281
+ /** Withdraw stake from a stake pool (Jito liquid staking) */
282
+ export interface StakePoolWithdrawStakeInstruction {
283
+ type: "stakePoolWithdrawStake";
284
+ /** Stake pool address (base58) */
285
+ stakePool: string;
286
+ /** Validator list account (base58) */
287
+ validatorList: string;
288
+ /** Withdraw authority PDA (base58) */
289
+ withdrawAuthority: string;
290
+ /** Validator stake account to split from (base58) */
291
+ validatorStake: string;
292
+ /** Destination stake account (uninitialized) (base58) */
293
+ destinationStake: string;
294
+ /** Authority for the destination stake account (base58) */
295
+ destinationStakeAuthority: string;
296
+ /** Source pool token account authority (signer) (base58) */
297
+ sourceTransferAuthority: string;
298
+ /** Source pool token account (base58) */
299
+ sourcePoolAccount: string;
300
+ /** Manager fee account (base58) */
301
+ managerFeeAccount: string;
302
+ /** Pool mint address (base58) */
303
+ poolMint: string;
304
+ /** Amount of pool tokens to burn */
305
+ poolTokens: bigint;
306
+ }
307
+ /** Account metadata for custom instructions */
308
+ export interface CustomAccountMeta {
309
+ /** Account public key (base58) */
310
+ pubkey: string;
311
+ /** Whether the account is a signer */
312
+ isSigner: boolean;
313
+ /** Whether the account is writable */
314
+ isWritable: boolean;
315
+ }
316
+ /**
317
+ * Custom instruction for invoking any program.
318
+ * Enables passthrough of arbitrary instructions for extensibility.
319
+ */
320
+ export interface CustomInstruction {
321
+ type: "custom";
322
+ /** The program ID to invoke (base58) */
323
+ programId: string;
324
+ /** Account metas for the instruction */
325
+ accounts: CustomAccountMeta[];
326
+ /** Instruction data (base64 or hex encoded) */
327
+ data: string;
328
+ /** Encoding of the data field: "base64" (default) or "hex" */
329
+ encoding?: "base64" | "hex";
330
+ }
331
+ /** Union of all instruction types */
332
+ export type Instruction = TransferInstruction | CreateAccountInstruction | NonceAdvanceInstruction | NonceInitializeInstruction | AllocateInstruction | AssignInstruction | MemoInstruction | ComputeBudgetInstruction | StakeInitializeInstruction | StakeDelegateInstruction | StakeDeactivateInstruction | StakeWithdrawInstruction | StakeAuthorizeInstruction | StakeSplitInstruction | TokenTransferInstruction | CreateAssociatedTokenAccountInstruction | CloseAssociatedTokenAccountInstruction | MintToInstruction | BurnInstruction | ApproveInstruction | StakePoolDepositSolInstruction | StakePoolWithdrawStakeInstruction | CustomInstruction;
333
+ /**
334
+ * A declarative intent to build a Solana transaction.
335
+ *
336
+ * @example
337
+ * ```typescript
338
+ * const intent: TransactionIntent = {
339
+ * feePayer: 'DgT9qyYwYKBRDyDw3EfR12LHQCQjtNrKu2qMsXHuosmB',
340
+ * nonce: {
341
+ * type: 'blockhash',
342
+ * value: 'GWaQEymC3Z9SHM2gkh8u12xL1zJPMHPCSVR3pSDpEXE4'
343
+ * },
344
+ * instructions: [
345
+ * { type: 'transfer', from: '...', to: '...', lamports: '1000000' }
346
+ * ]
347
+ * };
348
+ * ```
349
+ */
350
+ export interface TransactionIntent {
351
+ /** The fee payer's public key (base58) */
352
+ feePayer: string;
353
+ /** The nonce source (blockhash or durable nonce) */
354
+ nonce: NonceSource;
355
+ /** List of instructions to include */
356
+ instructions: Instruction[];
357
+ /**
358
+ * Address Lookup Tables for versioned transactions.
359
+ * If provided, builds a MessageV0 transaction instead of legacy.
360
+ */
361
+ addressLookupTables?: AddressLookupTable[];
362
+ /**
363
+ * Static account keys (for versioned transaction round-trip).
364
+ * These are the accounts stored directly in the message.
365
+ */
366
+ staticAccountKeys?: string[];
367
+ }
368
+ /**
369
+ * Build a Solana transaction from a high-level intent.
370
+ *
371
+ * This function takes a declarative TransactionIntent and produces a Transaction
372
+ * object that can be inspected, signed, and serialized.
373
+ *
374
+ * The returned transaction is unsigned - signatures should be added via
375
+ * `addSignature()` before serializing with `toBytes()` and broadcasting.
376
+ *
377
+ * @param intent - The transaction intent describing what to build
378
+ * @returns A Transaction object that can be inspected, signed, and serialized
379
+ * @throws Error if the intent cannot be built (e.g., invalid addresses)
380
+ *
381
+ * @example
382
+ * ```typescript
383
+ * import { buildTransaction } from '@bitgo/wasm-solana';
384
+ *
385
+ * // Build a simple SOL transfer
386
+ * const tx = buildTransaction({
387
+ * feePayer: sender,
388
+ * nonce: { type: 'blockhash', value: blockhash },
389
+ * instructions: [
390
+ * { type: 'transfer', from: sender, to: recipient, lamports: 1000000n }
391
+ * ]
392
+ * });
393
+ *
394
+ * // Inspect the transaction
395
+ * console.log(tx.feePayer);
396
+ * console.log(tx.recentBlockhash);
397
+ *
398
+ * // Get the signable payload for signing
399
+ * const payload = tx.signablePayload();
400
+ *
401
+ * // Add signature and serialize
402
+ * tx.addSignature(signerPubkey, signature);
403
+ * const txBytes = tx.toBytes();
404
+ * ```
405
+ *
406
+ * @example
407
+ * ```typescript
408
+ * // Build with durable nonce and priority fee
409
+ * const tx = buildTransaction({
410
+ * feePayer: sender,
411
+ * nonce: { type: 'durable', address: nonceAccount, authority: sender, value: nonceValue },
412
+ * instructions: [
413
+ * { type: 'computeBudget', unitLimit: 200000, unitPrice: 5000 },
414
+ * { type: 'transfer', from: sender, to: recipient, lamports: 1000000n },
415
+ * { type: 'memo', message: 'BitGo transfer' }
416
+ * ]
417
+ * });
418
+ * ```
419
+ */
420
+ export declare function buildTransaction(intent: TransactionIntent): Transaction;
421
+ /**
422
+ * A pre-compiled versioned instruction (uses indexes, not pubkeys).
423
+ * This is the format used in MessageV0 transactions.
424
+ */
425
+ export interface VersionedInstruction {
426
+ /** Index into the account keys array for the program ID */
427
+ programIdIndex: number;
428
+ /** Indexes into the account keys array for instruction accounts */
429
+ accountKeyIndexes: number[];
430
+ /** Instruction data (base58 encoded) */
431
+ data: string;
432
+ }
433
+ /**
434
+ * Message header for versioned transactions.
435
+ * Describes the structure of the account keys array.
436
+ */
437
+ export interface MessageHeader {
438
+ /** Number of required signatures */
439
+ numRequiredSignatures: number;
440
+ /** Number of readonly signed accounts */
441
+ numReadonlySignedAccounts: number;
442
+ /** Number of readonly unsigned accounts */
443
+ numReadonlyUnsignedAccounts: number;
444
+ }
445
+ /**
446
+ * Raw versioned transaction data for direct serialization.
447
+ * This is used when we have pre-formed MessageV0 data that just needs to be serialized.
448
+ * No instruction compilation is needed - just serialize the raw structure.
449
+ */
450
+ export interface RawVersionedTransactionData {
451
+ /** Static account keys (base58 encoded public keys) */
452
+ staticAccountKeys: string[];
453
+ /** Address lookup tables */
454
+ addressLookupTables: AddressLookupTable[];
455
+ /** Pre-compiled instructions with index-based account references */
456
+ versionedInstructions: VersionedInstruction[];
457
+ /** Message header */
458
+ messageHeader: MessageHeader;
459
+ /** Recent blockhash (base58) */
460
+ recentBlockhash: string;
461
+ }
462
+ /**
463
+ * Build a versioned transaction directly from raw MessageV0 data.
464
+ *
465
+ * This function is used for the `fromVersionedTransactionData()` path where we already
466
+ * have pre-compiled versioned data (indexes + ALT refs). No instruction compilation
467
+ * is needed - we just serialize the raw structure.
468
+ *
469
+ * @param data - Raw versioned transaction data
470
+ * @returns A VersionedTransaction object that can be inspected, signed, and serialized
471
+ * @throws Error if the data is invalid
472
+ *
473
+ * @example
474
+ * ```typescript
475
+ * import { buildFromVersionedData } from '@bitgo/wasm-solana';
476
+ *
477
+ * const tx = buildFromVersionedData({
478
+ * staticAccountKeys: ['pubkey1', 'pubkey2', ...],
479
+ * addressLookupTables: [
480
+ * { accountKey: 'altPubkey', writableIndexes: [0, 1], readonlyIndexes: [2] }
481
+ * ],
482
+ * versionedInstructions: [
483
+ * { programIdIndex: 0, accountKeyIndexes: [1, 2], data: 'base58EncodedData' }
484
+ * ],
485
+ * messageHeader: {
486
+ * numRequiredSignatures: 1,
487
+ * numReadonlySignedAccounts: 0,
488
+ * numReadonlyUnsignedAccounts: 3
489
+ * },
490
+ * recentBlockhash: 'blockhash'
491
+ * });
492
+ *
493
+ * // Inspect, sign, and serialize
494
+ * console.log(tx.feePayer);
495
+ * tx.addSignature(signerPubkey, signature);
496
+ * const txBytes = tx.toBytes();
497
+ * ```
498
+ */
499
+ export declare function buildFromVersionedData(data: RawVersionedTransactionData): VersionedTransaction;
@@ -0,0 +1,109 @@
1
+ /**
2
+ * Transaction building from high-level intents.
3
+ *
4
+ * Provides types and functions for building Solana transactions from a
5
+ * declarative intent structure, without requiring the full @solana/web3.js dependency.
6
+ */
7
+ import { BuilderNamespace } from "./wasm/wasm_solana.js";
8
+ import { Transaction } from "./transaction.js";
9
+ import { VersionedTransaction } from "./versioned.js";
10
+ // =============================================================================
11
+ // buildTransaction function
12
+ // =============================================================================
13
+ /**
14
+ * Build a Solana transaction from a high-level intent.
15
+ *
16
+ * This function takes a declarative TransactionIntent and produces a Transaction
17
+ * object that can be inspected, signed, and serialized.
18
+ *
19
+ * The returned transaction is unsigned - signatures should be added via
20
+ * `addSignature()` before serializing with `toBytes()` and broadcasting.
21
+ *
22
+ * @param intent - The transaction intent describing what to build
23
+ * @returns A Transaction object that can be inspected, signed, and serialized
24
+ * @throws Error if the intent cannot be built (e.g., invalid addresses)
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * import { buildTransaction } from '@bitgo/wasm-solana';
29
+ *
30
+ * // Build a simple SOL transfer
31
+ * const tx = buildTransaction({
32
+ * feePayer: sender,
33
+ * nonce: { type: 'blockhash', value: blockhash },
34
+ * instructions: [
35
+ * { type: 'transfer', from: sender, to: recipient, lamports: 1000000n }
36
+ * ]
37
+ * });
38
+ *
39
+ * // Inspect the transaction
40
+ * console.log(tx.feePayer);
41
+ * console.log(tx.recentBlockhash);
42
+ *
43
+ * // Get the signable payload for signing
44
+ * const payload = tx.signablePayload();
45
+ *
46
+ * // Add signature and serialize
47
+ * tx.addSignature(signerPubkey, signature);
48
+ * const txBytes = tx.toBytes();
49
+ * ```
50
+ *
51
+ * @example
52
+ * ```typescript
53
+ * // Build with durable nonce and priority fee
54
+ * const tx = buildTransaction({
55
+ * feePayer: sender,
56
+ * nonce: { type: 'durable', address: nonceAccount, authority: sender, value: nonceValue },
57
+ * instructions: [
58
+ * { type: 'computeBudget', unitLimit: 200000, unitPrice: 5000 },
59
+ * { type: 'transfer', from: sender, to: recipient, lamports: 1000000n },
60
+ * { type: 'memo', message: 'BitGo transfer' }
61
+ * ]
62
+ * });
63
+ * ```
64
+ */
65
+ export function buildTransaction(intent) {
66
+ const wasm = BuilderNamespace.build_transaction(intent);
67
+ return Transaction.fromWasm(wasm);
68
+ }
69
+ /**
70
+ * Build a versioned transaction directly from raw MessageV0 data.
71
+ *
72
+ * This function is used for the `fromVersionedTransactionData()` path where we already
73
+ * have pre-compiled versioned data (indexes + ALT refs). No instruction compilation
74
+ * is needed - we just serialize the raw structure.
75
+ *
76
+ * @param data - Raw versioned transaction data
77
+ * @returns A VersionedTransaction object that can be inspected, signed, and serialized
78
+ * @throws Error if the data is invalid
79
+ *
80
+ * @example
81
+ * ```typescript
82
+ * import { buildFromVersionedData } from '@bitgo/wasm-solana';
83
+ *
84
+ * const tx = buildFromVersionedData({
85
+ * staticAccountKeys: ['pubkey1', 'pubkey2', ...],
86
+ * addressLookupTables: [
87
+ * { accountKey: 'altPubkey', writableIndexes: [0, 1], readonlyIndexes: [2] }
88
+ * ],
89
+ * versionedInstructions: [
90
+ * { programIdIndex: 0, accountKeyIndexes: [1, 2], data: 'base58EncodedData' }
91
+ * ],
92
+ * messageHeader: {
93
+ * numRequiredSignatures: 1,
94
+ * numReadonlySignedAccounts: 0,
95
+ * numReadonlyUnsignedAccounts: 3
96
+ * },
97
+ * recentBlockhash: 'blockhash'
98
+ * });
99
+ *
100
+ * // Inspect, sign, and serialize
101
+ * console.log(tx.feePayer);
102
+ * tx.addSignature(signerPubkey, signature);
103
+ * const txBytes = tx.toBytes();
104
+ * ```
105
+ */
106
+ export function buildFromVersionedData(data) {
107
+ const wasm = BuilderNamespace.build_from_versioned_data(data);
108
+ return VersionedTransaction.fromWasm(wasm);
109
+ }
@@ -0,0 +1,16 @@
1
+ export * as keypair from "./keypair.js";
2
+ export * as pubkey from "./pubkey.js";
3
+ export * as transaction from "./transaction.js";
4
+ export * as parser from "./parser.js";
5
+ export * as builder from "./builder.js";
6
+ export { Keypair } from "./keypair.js";
7
+ export { Pubkey } from "./pubkey.js";
8
+ export { Transaction } from "./transaction.js";
9
+ export { VersionedTransaction, isVersionedTransaction } from "./versioned.js";
10
+ export type { AddressLookupTableData } from "./versioned.js";
11
+ export { parseTransaction } from "./parser.js";
12
+ export { buildTransaction, buildFromVersionedData } from "./builder.js";
13
+ export { system_program_id as systemProgramId, stake_program_id as stakeProgramId, compute_budget_program_id as computeBudgetProgramId, memo_program_id as memoProgramId, token_program_id as tokenProgramId, token_2022_program_id as token2022ProgramId, ata_program_id as ataProgramId, stake_pool_program_id as stakePoolProgramId, stake_account_space as stakeAccountSpace, nonce_account_space as nonceAccountSpace, sysvar_recent_blockhashes as sysvarRecentBlockhashes, get_associated_token_address as getAssociatedTokenAddress, find_withdraw_authority_program_address as findWithdrawAuthorityProgramAddress, } from "./wasm/wasm_solana.js";
14
+ export type { AccountMeta, Instruction } from "./transaction.js";
15
+ export type { TransactionInput, ParsedTransaction, DurableNonce, InstructionParams, TransferParams, CreateAccountParams, NonceAdvanceParams, CreateNonceAccountParams, NonceInitializeParams, StakeInitializeParams, StakingActivateParams, StakingDeactivateParams, StakingWithdrawParams, StakingDelegateParams, StakingAuthorizeParams, SetComputeUnitLimitParams, SetPriorityFeeParams, TokenTransferParams, CreateAtaParams, CloseAtaParams, MemoParams, StakePoolDepositSolParams, StakePoolWithdrawStakeParams, UnknownInstructionParams, } from "./parser.js";
16
+ export type { TransactionIntent, NonceSource, BlockhashNonceSource, DurableNonceSource, AddressLookupTable as BuilderAddressLookupTable, Instruction as BuilderInstruction, TransferInstruction, CreateAccountInstruction, NonceAdvanceInstruction, NonceInitializeInstruction, AllocateInstruction, AssignInstruction, MemoInstruction, ComputeBudgetInstruction, StakeInitializeInstruction, StakeDelegateInstruction, StakeDeactivateInstruction, StakeWithdrawInstruction, StakeAuthorizeInstruction, StakeSplitInstruction, TokenTransferInstruction, CreateAssociatedTokenAccountInstruction, CloseAssociatedTokenAccountInstruction, MintToInstruction, BurnInstruction, ApproveInstruction, StakePoolDepositSolInstruction, StakePoolWithdrawStakeInstruction, CustomInstruction as BuilderCustomInstruction, CustomAccountMeta, RawVersionedTransactionData, VersionedInstruction as BuilderVersionedInstruction, MessageHeader, } from "./builder.js";
@@ -0,0 +1,24 @@
1
+ import * as wasm from "./wasm/wasm_solana.js";
2
+ // Force webpack to include the WASM module
3
+ void wasm;
4
+ // Namespace exports for explicit imports
5
+ export * as keypair from "./keypair.js";
6
+ export * as pubkey from "./pubkey.js";
7
+ export * as transaction from "./transaction.js";
8
+ export * as parser from "./parser.js";
9
+ export * as builder from "./builder.js";
10
+ // Top-level class exports for convenience
11
+ export { Keypair } from "./keypair.js";
12
+ export { Pubkey } from "./pubkey.js";
13
+ export { Transaction } from "./transaction.js";
14
+ // Versioned transaction support
15
+ export { VersionedTransaction, isVersionedTransaction } from "./versioned.js";
16
+ // Top-level function exports
17
+ export { parseTransaction } from "./parser.js";
18
+ export { buildTransaction, buildFromVersionedData } from "./builder.js";
19
+ // Program ID constants (from WASM)
20
+ export { system_program_id as systemProgramId, stake_program_id as stakeProgramId, compute_budget_program_id as computeBudgetProgramId, memo_program_id as memoProgramId, token_program_id as tokenProgramId, token_2022_program_id as token2022ProgramId, ata_program_id as ataProgramId, stake_pool_program_id as stakePoolProgramId, stake_account_space as stakeAccountSpace, nonce_account_space as nonceAccountSpace,
21
+ // Sysvar addresses
22
+ sysvar_recent_blockhashes as sysvarRecentBlockhashes,
23
+ // PDA derivation functions (eliminates @solana/web3.js dependency)
24
+ get_associated_token_address as getAssociatedTokenAddress, find_withdraw_authority_program_address as findWithdrawAuthorityProgramAddress, } from "./wasm/wasm_solana.js";