@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,156 @@
1
+ import { WasmTransaction } from "./wasm/wasm_solana.js";
2
+ import { Pubkey } from "./pubkey.js";
3
+ /**
4
+ * Account metadata for an instruction
5
+ */
6
+ export interface AccountMeta {
7
+ /** The account public key as a base58 string */
8
+ pubkey: string;
9
+ /** Whether this account is a signer */
10
+ isSigner: boolean;
11
+ /** Whether this account is writable */
12
+ isWritable: boolean;
13
+ }
14
+ /**
15
+ * A decoded Solana instruction
16
+ */
17
+ export interface Instruction {
18
+ /** The program ID (base58 string) that will execute this instruction */
19
+ programId: string;
20
+ /** The accounts required by this instruction */
21
+ accounts: AccountMeta[];
22
+ /** The instruction data */
23
+ data: Uint8Array;
24
+ }
25
+ /**
26
+ * Solana Transaction wrapper for low-level deserialization and inspection.
27
+ *
28
+ * This class provides low-level access to transaction structure.
29
+ * For high-level semantic parsing with decoded instructions, use `parseTransaction()` instead.
30
+ *
31
+ * @example
32
+ * ```typescript
33
+ * import { Transaction, parseTransaction } from '@bitgo/wasm-solana';
34
+ *
35
+ * // Low-level access:
36
+ * const tx = Transaction.fromBytes(txBytes);
37
+ * console.log(tx.feePayer);
38
+ *
39
+ * // High-level parsing (preferred):
40
+ * const parsed = parseTransaction(txBytes);
41
+ * console.log(parsed.instructionsData); // Decoded instruction types
42
+ * ```
43
+ */
44
+ export declare class Transaction {
45
+ private _wasm;
46
+ private constructor();
47
+ /**
48
+ * Deserialize a transaction from raw bytes
49
+ * @param bytes - The raw transaction bytes
50
+ * @returns A Transaction instance
51
+ */
52
+ static fromBytes(bytes: Uint8Array): Transaction;
53
+ /**
54
+ * Create a Transaction from a WasmTransaction instance.
55
+ * @internal Used by builder functions
56
+ */
57
+ static fromWasm(wasm: WasmTransaction): Transaction;
58
+ /**
59
+ * Get the fee payer address as a base58 string
60
+ * Returns null if there are no account keys (shouldn't happen for valid transactions)
61
+ */
62
+ get feePayer(): string | null;
63
+ /**
64
+ * Get the recent blockhash as a base58 string
65
+ */
66
+ get recentBlockhash(): string;
67
+ /**
68
+ * Get the number of signatures in the transaction
69
+ */
70
+ get numSignatures(): number;
71
+ /**
72
+ * Get the signable message payload (what gets signed)
73
+ * This is the serialized message that signers sign
74
+ * @returns The message bytes
75
+ */
76
+ signablePayload(): Uint8Array;
77
+ /**
78
+ * Serialize the message portion of the transaction.
79
+ * Alias for signablePayload() - provides compatibility with @solana/web3.js API.
80
+ * Returns a Buffer for compatibility with code expecting .toString('base64').
81
+ * @returns The serialized message bytes as a Buffer
82
+ */
83
+ serializeMessage(): Buffer;
84
+ /**
85
+ * Serialize the transaction to bytes
86
+ * @returns The serialized transaction bytes
87
+ */
88
+ toBytes(): Uint8Array;
89
+ /**
90
+ * Get all account keys as Pubkey instances
91
+ * @returns Array of account public keys
92
+ */
93
+ accountKeys(): Pubkey[];
94
+ /**
95
+ * Get all signatures as byte arrays.
96
+ * Provides compatibility with @solana/web3.js Transaction.signatures API.
97
+ * @returns Array of signature byte arrays
98
+ */
99
+ get signatures(): Uint8Array[];
100
+ /**
101
+ * Get all signatures as byte arrays (method form).
102
+ * Alias for the `signatures` property getter.
103
+ * @returns Array of signature byte arrays
104
+ */
105
+ getSignatures(): Uint8Array[];
106
+ /**
107
+ * Get all instructions in the transaction.
108
+ * Returns an array with programId, accounts, and data for each instruction.
109
+ *
110
+ * Note: This is a getter property to provide compatibility with code
111
+ * expecting @solana/web3.js Transaction.instructions API. If you need
112
+ * to call this as a method, use `getInstructions()` instead.
113
+ */
114
+ get instructions(): Instruction[];
115
+ /**
116
+ * Get all instructions in the transaction (method form).
117
+ * Alias for the `instructions` property getter.
118
+ * @returns Array of instructions with programId, accounts, and data
119
+ */
120
+ getInstructions(): Instruction[];
121
+ /**
122
+ * Add a signature for a given public key.
123
+ *
124
+ * The pubkey must be one of the required signers in the transaction.
125
+ * The signature must be exactly 64 bytes (Ed25519 signature).
126
+ *
127
+ * @param pubkey - The public key as a base58 string
128
+ * @param signature - The 64-byte signature as Uint8Array
129
+ * @throws Error if pubkey is not a signer or signature is invalid
130
+ *
131
+ * @example
132
+ * ```typescript
133
+ * // Add a pre-computed signature (e.g., from TSS)
134
+ * tx.addSignature(signerPubkey, signatureBytes);
135
+ *
136
+ * // Serialize and broadcast
137
+ * const signedTxBytes = tx.toBytes();
138
+ * ```
139
+ */
140
+ addSignature(pubkey: string, signature: Uint8Array): void;
141
+ /**
142
+ * Get the signer index for a public key.
143
+ *
144
+ * Returns the index in the signatures array where this pubkey's
145
+ * signature should be placed, or null if the pubkey is not a signer.
146
+ *
147
+ * @param pubkey - The public key as a base58 string
148
+ * @returns The signer index, or null if not a signer
149
+ */
150
+ signerIndex(pubkey: string): number | null;
151
+ /**
152
+ * Get the underlying WASM instance (internal use only)
153
+ * @internal
154
+ */
155
+ get wasm(): WasmTransaction;
156
+ }
@@ -0,0 +1,176 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Transaction = void 0;
4
+ const wasm_solana_js_1 = require("./wasm/wasm_solana.js");
5
+ const pubkey_js_1 = require("./pubkey.js");
6
+ /**
7
+ * Solana Transaction wrapper for low-level deserialization and inspection.
8
+ *
9
+ * This class provides low-level access to transaction structure.
10
+ * For high-level semantic parsing with decoded instructions, use `parseTransaction()` instead.
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * import { Transaction, parseTransaction } from '@bitgo/wasm-solana';
15
+ *
16
+ * // Low-level access:
17
+ * const tx = Transaction.fromBytes(txBytes);
18
+ * console.log(tx.feePayer);
19
+ *
20
+ * // High-level parsing (preferred):
21
+ * const parsed = parseTransaction(txBytes);
22
+ * console.log(parsed.instructionsData); // Decoded instruction types
23
+ * ```
24
+ */
25
+ class Transaction {
26
+ _wasm;
27
+ constructor(_wasm) {
28
+ this._wasm = _wasm;
29
+ }
30
+ /**
31
+ * Deserialize a transaction from raw bytes
32
+ * @param bytes - The raw transaction bytes
33
+ * @returns A Transaction instance
34
+ */
35
+ static fromBytes(bytes) {
36
+ const wasm = wasm_solana_js_1.WasmTransaction.from_bytes(bytes);
37
+ return new Transaction(wasm);
38
+ }
39
+ /**
40
+ * Create a Transaction from a WasmTransaction instance.
41
+ * @internal Used by builder functions
42
+ */
43
+ static fromWasm(wasm) {
44
+ return new Transaction(wasm);
45
+ }
46
+ /**
47
+ * Get the fee payer address as a base58 string
48
+ * Returns null if there are no account keys (shouldn't happen for valid transactions)
49
+ */
50
+ get feePayer() {
51
+ return this._wasm.fee_payer ?? null;
52
+ }
53
+ /**
54
+ * Get the recent blockhash as a base58 string
55
+ */
56
+ get recentBlockhash() {
57
+ return this._wasm.recent_blockhash;
58
+ }
59
+ /**
60
+ * Get the number of signatures in the transaction
61
+ */
62
+ get numSignatures() {
63
+ return this._wasm.num_signatures;
64
+ }
65
+ /**
66
+ * Get the signable message payload (what gets signed)
67
+ * This is the serialized message that signers sign
68
+ * @returns The message bytes
69
+ */
70
+ signablePayload() {
71
+ return this._wasm.signable_payload();
72
+ }
73
+ /**
74
+ * Serialize the message portion of the transaction.
75
+ * Alias for signablePayload() - provides compatibility with @solana/web3.js API.
76
+ * Returns a Buffer for compatibility with code expecting .toString('base64').
77
+ * @returns The serialized message bytes as a Buffer
78
+ */
79
+ serializeMessage() {
80
+ return Buffer.from(this.signablePayload());
81
+ }
82
+ /**
83
+ * Serialize the transaction to bytes
84
+ * @returns The serialized transaction bytes
85
+ */
86
+ toBytes() {
87
+ return this._wasm.to_bytes();
88
+ }
89
+ /**
90
+ * Get all account keys as Pubkey instances
91
+ * @returns Array of account public keys
92
+ */
93
+ accountKeys() {
94
+ const keys = Array.from(this._wasm.account_keys());
95
+ return keys.map((k) => pubkey_js_1.Pubkey.fromBase58(k));
96
+ }
97
+ /**
98
+ * Get all signatures as byte arrays.
99
+ * Provides compatibility with @solana/web3.js Transaction.signatures API.
100
+ * @returns Array of signature byte arrays
101
+ */
102
+ get signatures() {
103
+ return Array.from(this._wasm.signatures());
104
+ }
105
+ /**
106
+ * Get all signatures as byte arrays (method form).
107
+ * Alias for the `signatures` property getter.
108
+ * @returns Array of signature byte arrays
109
+ */
110
+ getSignatures() {
111
+ return this.signatures;
112
+ }
113
+ /**
114
+ * Get all instructions in the transaction.
115
+ * Returns an array with programId, accounts, and data for each instruction.
116
+ *
117
+ * Note: This is a getter property to provide compatibility with code
118
+ * expecting @solana/web3.js Transaction.instructions API. If you need
119
+ * to call this as a method, use `getInstructions()` instead.
120
+ */
121
+ get instructions() {
122
+ const rawInstructions = this._wasm.instructions();
123
+ return Array.from(rawInstructions);
124
+ }
125
+ /**
126
+ * Get all instructions in the transaction (method form).
127
+ * Alias for the `instructions` property getter.
128
+ * @returns Array of instructions with programId, accounts, and data
129
+ */
130
+ getInstructions() {
131
+ return this.instructions;
132
+ }
133
+ /**
134
+ * Add a signature for a given public key.
135
+ *
136
+ * The pubkey must be one of the required signers in the transaction.
137
+ * The signature must be exactly 64 bytes (Ed25519 signature).
138
+ *
139
+ * @param pubkey - The public key as a base58 string
140
+ * @param signature - The 64-byte signature as Uint8Array
141
+ * @throws Error if pubkey is not a signer or signature is invalid
142
+ *
143
+ * @example
144
+ * ```typescript
145
+ * // Add a pre-computed signature (e.g., from TSS)
146
+ * tx.addSignature(signerPubkey, signatureBytes);
147
+ *
148
+ * // Serialize and broadcast
149
+ * const signedTxBytes = tx.toBytes();
150
+ * ```
151
+ */
152
+ addSignature(pubkey, signature) {
153
+ this._wasm.add_signature(pubkey, signature);
154
+ }
155
+ /**
156
+ * Get the signer index for a public key.
157
+ *
158
+ * Returns the index in the signatures array where this pubkey's
159
+ * signature should be placed, or null if the pubkey is not a signer.
160
+ *
161
+ * @param pubkey - The public key as a base58 string
162
+ * @returns The signer index, or null if not a signer
163
+ */
164
+ signerIndex(pubkey) {
165
+ const idx = this._wasm.signer_index(pubkey);
166
+ return idx ?? null;
167
+ }
168
+ /**
169
+ * Get the underlying WASM instance (internal use only)
170
+ * @internal
171
+ */
172
+ get wasm() {
173
+ return this._wasm;
174
+ }
175
+ }
176
+ exports.Transaction = Transaction;
@@ -0,0 +1,177 @@
1
+ /**
2
+ * Versioned Transaction Support
3
+ *
4
+ * Handles both legacy and versioned (MessageV0) Solana transactions.
5
+ * Versioned transactions use Address Lookup Tables (ALTs) to compress
6
+ * transaction size by referencing accounts via lookup table indices.
7
+ */
8
+ import { WasmVersionedTransaction } from "./wasm/wasm_solana.js";
9
+ import type { RawVersionedTransactionData } from "./builder.js";
10
+ /**
11
+ * Address Lookup Table data extracted from versioned transactions.
12
+ */
13
+ export interface AddressLookupTableData {
14
+ /** The lookup table account address (base58) */
15
+ accountKey: string;
16
+ /** Indices of writable accounts in the lookup table */
17
+ writableIndexes: Uint8Array;
18
+ /** Indices of readonly accounts in the lookup table */
19
+ readonlyIndexes: Uint8Array;
20
+ }
21
+ /**
22
+ * Account metadata for instructions.
23
+ */
24
+ export interface VersionedAccountMeta {
25
+ /** Account index within the transaction */
26
+ index: number;
27
+ /** Account pubkey (only present for static accounts) */
28
+ pubkey?: string;
29
+ /** Whether this account is from an Address Lookup Table */
30
+ isLookupTable: boolean;
31
+ /** Whether this account is a signer */
32
+ isSigner: boolean;
33
+ }
34
+ /**
35
+ * Instruction from a versioned transaction.
36
+ */
37
+ export interface VersionedInstruction {
38
+ /** Program ID */
39
+ programId: string;
40
+ /** Accounts used by the instruction */
41
+ accounts: VersionedAccountMeta[];
42
+ /** Instruction data */
43
+ data: Uint8Array;
44
+ }
45
+ /**
46
+ * Detect if transaction bytes represent a versioned transaction (MessageV0).
47
+ *
48
+ * @param bytes - Raw transaction bytes
49
+ * @returns true if versioned, false if legacy
50
+ */
51
+ export declare function isVersionedTransaction(bytes: Uint8Array): boolean;
52
+ /**
53
+ * Versioned Transaction class.
54
+ *
55
+ * Handles both legacy and versioned (MessageV0) transactions.
56
+ * Provides access to Address Lookup Table data for versioned transactions.
57
+ */
58
+ export declare class VersionedTransaction {
59
+ private inner;
60
+ private constructor();
61
+ /**
62
+ * Deserialize a transaction from raw bytes.
63
+ * Automatically handles both legacy and versioned formats.
64
+ */
65
+ static fromBytes(bytes: Uint8Array): VersionedTransaction;
66
+ /**
67
+ * Deserialize a transaction from base64 string.
68
+ */
69
+ static fromBase64(base64: string): VersionedTransaction;
70
+ /**
71
+ * Create a VersionedTransaction from a WasmVersionedTransaction instance.
72
+ * @internal Used by builder functions
73
+ */
74
+ static fromWasm(wasm: WasmVersionedTransaction): VersionedTransaction;
75
+ /**
76
+ * Create a versioned transaction from raw MessageV0 data.
77
+ *
78
+ * This is used for the `fromVersionedTransactionData()` path where we have
79
+ * pre-compiled versioned data (indexes + ALT refs). No instruction compilation
80
+ * is needed - this just constructs the transaction from the raw structure.
81
+ *
82
+ * @param data - Raw versioned transaction data
83
+ * @returns A VersionedTransaction instance
84
+ *
85
+ * @example
86
+ * ```typescript
87
+ * const tx = VersionedTransaction.fromVersionedData({
88
+ * staticAccountKeys: ['pubkey1', 'pubkey2', ...],
89
+ * addressLookupTables: [
90
+ * { accountKey: 'altPubkey', writableIndexes: [0, 1], readonlyIndexes: [2] }
91
+ * ],
92
+ * versionedInstructions: [
93
+ * { programIdIndex: 0, accountKeyIndexes: [1, 2], data: 'base58EncodedData' }
94
+ * ],
95
+ * messageHeader: {
96
+ * numRequiredSignatures: 1,
97
+ * numReadonlySignedAccounts: 0,
98
+ * numReadonlyUnsignedAccounts: 3
99
+ * },
100
+ * recentBlockhash: 'blockhash'
101
+ * });
102
+ * ```
103
+ */
104
+ static fromVersionedData(data: RawVersionedTransactionData): VersionedTransaction;
105
+ /**
106
+ * Check if this is a versioned transaction (MessageV0).
107
+ */
108
+ get isVersioned(): boolean;
109
+ /**
110
+ * Get the fee payer address.
111
+ */
112
+ get feePayer(): string | undefined;
113
+ /**
114
+ * Get the recent blockhash.
115
+ */
116
+ get recentBlockhash(): string;
117
+ /**
118
+ * Get the number of instructions.
119
+ */
120
+ get numInstructions(): number;
121
+ /**
122
+ * Get the number of signatures.
123
+ */
124
+ get numSignatures(): number;
125
+ /**
126
+ * Get the signable message payload.
127
+ */
128
+ signablePayload(): Uint8Array;
129
+ /**
130
+ * Serialize the message portion of the transaction.
131
+ * Alias for signablePayload() - provides compatibility with @solana/web3.js API.
132
+ * Returns a Buffer for compatibility with code expecting .toString('base64').
133
+ * @returns The serialized message bytes as a Buffer
134
+ */
135
+ serializeMessage(): Buffer;
136
+ /**
137
+ * Serialize the transaction to bytes.
138
+ */
139
+ toBytes(): Uint8Array;
140
+ /**
141
+ * Serialize the transaction to base64.
142
+ */
143
+ toBase64(): string;
144
+ /**
145
+ * Get static account keys (accounts stored directly in the message).
146
+ * For versioned transactions, additional accounts may be referenced via ALTs.
147
+ */
148
+ staticAccountKeys(): string[];
149
+ /**
150
+ * Get Address Lookup Table data.
151
+ * Returns empty array for legacy transactions.
152
+ */
153
+ addressLookupTables(): AddressLookupTableData[];
154
+ /**
155
+ * Get all signatures as byte arrays.
156
+ * Provides compatibility with @solana/web3.js Transaction.signatures API.
157
+ */
158
+ get signatures(): Uint8Array[];
159
+ /**
160
+ * Add a signature for a given public key.
161
+ *
162
+ * @param pubkey - The public key as base58 string
163
+ * @param signature - The 64-byte Ed25519 signature
164
+ */
165
+ addSignature(pubkey: string, signature: Uint8Array): void;
166
+ /**
167
+ * Get the signer index for a public key.
168
+ * Returns undefined if the pubkey is not a required signer.
169
+ */
170
+ signerIndex(pubkey: string): number | undefined;
171
+ /**
172
+ * Get all instructions.
173
+ * Note: For versioned transactions, account indices may reference
174
+ * accounts from Address Lookup Tables.
175
+ */
176
+ instructions(): VersionedInstruction[];
177
+ }
@@ -0,0 +1,197 @@
1
+ "use strict";
2
+ /**
3
+ * Versioned Transaction Support
4
+ *
5
+ * Handles both legacy and versioned (MessageV0) Solana transactions.
6
+ * Versioned transactions use Address Lookup Tables (ALTs) to compress
7
+ * transaction size by referencing accounts via lookup table indices.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.VersionedTransaction = void 0;
11
+ exports.isVersionedTransaction = isVersionedTransaction;
12
+ const wasm_solana_js_1 = require("./wasm/wasm_solana.js");
13
+ /**
14
+ * Detect if transaction bytes represent a versioned transaction (MessageV0).
15
+ *
16
+ * @param bytes - Raw transaction bytes
17
+ * @returns true if versioned, false if legacy
18
+ */
19
+ function isVersionedTransaction(bytes) {
20
+ return (0, wasm_solana_js_1.is_versioned_transaction)(bytes);
21
+ }
22
+ /**
23
+ * Versioned Transaction class.
24
+ *
25
+ * Handles both legacy and versioned (MessageV0) transactions.
26
+ * Provides access to Address Lookup Table data for versioned transactions.
27
+ */
28
+ class VersionedTransaction {
29
+ inner;
30
+ constructor(inner) {
31
+ this.inner = inner;
32
+ }
33
+ /**
34
+ * Deserialize a transaction from raw bytes.
35
+ * Automatically handles both legacy and versioned formats.
36
+ */
37
+ static fromBytes(bytes) {
38
+ return new VersionedTransaction(wasm_solana_js_1.WasmVersionedTransaction.from_bytes(bytes));
39
+ }
40
+ /**
41
+ * Deserialize a transaction from base64 string.
42
+ */
43
+ static fromBase64(base64) {
44
+ const bytes = Uint8Array.from(Buffer.from(base64, "base64"));
45
+ return VersionedTransaction.fromBytes(bytes);
46
+ }
47
+ /**
48
+ * Create a VersionedTransaction from a WasmVersionedTransaction instance.
49
+ * @internal Used by builder functions
50
+ */
51
+ static fromWasm(wasm) {
52
+ return new VersionedTransaction(wasm);
53
+ }
54
+ /**
55
+ * Create a versioned transaction from raw MessageV0 data.
56
+ *
57
+ * This is used for the `fromVersionedTransactionData()` path where we have
58
+ * pre-compiled versioned data (indexes + ALT refs). No instruction compilation
59
+ * is needed - this just constructs the transaction from the raw structure.
60
+ *
61
+ * @param data - Raw versioned transaction data
62
+ * @returns A VersionedTransaction instance
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * const tx = VersionedTransaction.fromVersionedData({
67
+ * staticAccountKeys: ['pubkey1', 'pubkey2', ...],
68
+ * addressLookupTables: [
69
+ * { accountKey: 'altPubkey', writableIndexes: [0, 1], readonlyIndexes: [2] }
70
+ * ],
71
+ * versionedInstructions: [
72
+ * { programIdIndex: 0, accountKeyIndexes: [1, 2], data: 'base58EncodedData' }
73
+ * ],
74
+ * messageHeader: {
75
+ * numRequiredSignatures: 1,
76
+ * numReadonlySignedAccounts: 0,
77
+ * numReadonlyUnsignedAccounts: 3
78
+ * },
79
+ * recentBlockhash: 'blockhash'
80
+ * });
81
+ * ```
82
+ */
83
+ static fromVersionedData(data) {
84
+ // Build the transaction using WASM and wrap in TypeScript class
85
+ const wasm = wasm_solana_js_1.BuilderNamespace.build_from_versioned_data(data);
86
+ return VersionedTransaction.fromWasm(wasm);
87
+ }
88
+ /**
89
+ * Check if this is a versioned transaction (MessageV0).
90
+ */
91
+ get isVersioned() {
92
+ return this.inner.is_versioned;
93
+ }
94
+ /**
95
+ * Get the fee payer address.
96
+ */
97
+ get feePayer() {
98
+ return this.inner.fee_payer ?? undefined;
99
+ }
100
+ /**
101
+ * Get the recent blockhash.
102
+ */
103
+ get recentBlockhash() {
104
+ return this.inner.recent_blockhash;
105
+ }
106
+ /**
107
+ * Get the number of instructions.
108
+ */
109
+ get numInstructions() {
110
+ return this.inner.num_instructions;
111
+ }
112
+ /**
113
+ * Get the number of signatures.
114
+ */
115
+ get numSignatures() {
116
+ return this.inner.num_signatures;
117
+ }
118
+ /**
119
+ * Get the signable message payload.
120
+ */
121
+ signablePayload() {
122
+ return this.inner.signable_payload();
123
+ }
124
+ /**
125
+ * Serialize the message portion of the transaction.
126
+ * Alias for signablePayload() - provides compatibility with @solana/web3.js API.
127
+ * Returns a Buffer for compatibility with code expecting .toString('base64').
128
+ * @returns The serialized message bytes as a Buffer
129
+ */
130
+ serializeMessage() {
131
+ return Buffer.from(this.signablePayload());
132
+ }
133
+ /**
134
+ * Serialize the transaction to bytes.
135
+ */
136
+ toBytes() {
137
+ return this.inner.to_bytes();
138
+ }
139
+ /**
140
+ * Serialize the transaction to base64.
141
+ */
142
+ toBase64() {
143
+ return Buffer.from(this.toBytes()).toString("base64");
144
+ }
145
+ /**
146
+ * Get static account keys (accounts stored directly in the message).
147
+ * For versioned transactions, additional accounts may be referenced via ALTs.
148
+ */
149
+ staticAccountKeys() {
150
+ return Array.from(this.inner.static_account_keys());
151
+ }
152
+ /**
153
+ * Get Address Lookup Table data.
154
+ * Returns empty array for legacy transactions.
155
+ */
156
+ addressLookupTables() {
157
+ const alts = this.inner.address_lookup_tables();
158
+ return Array.from(alts).map((alt) => ({
159
+ accountKey: alt.accountKey,
160
+ writableIndexes: alt.writableIndexes,
161
+ readonlyIndexes: alt.readonlyIndexes,
162
+ }));
163
+ }
164
+ /**
165
+ * Get all signatures as byte arrays.
166
+ * Provides compatibility with @solana/web3.js Transaction.signatures API.
167
+ */
168
+ get signatures() {
169
+ return Array.from(this.inner.signatures());
170
+ }
171
+ /**
172
+ * Add a signature for a given public key.
173
+ *
174
+ * @param pubkey - The public key as base58 string
175
+ * @param signature - The 64-byte Ed25519 signature
176
+ */
177
+ addSignature(pubkey, signature) {
178
+ this.inner.add_signature(pubkey, signature);
179
+ }
180
+ /**
181
+ * Get the signer index for a public key.
182
+ * Returns undefined if the pubkey is not a required signer.
183
+ */
184
+ signerIndex(pubkey) {
185
+ return this.inner.signer_index(pubkey) ?? undefined;
186
+ }
187
+ /**
188
+ * Get all instructions.
189
+ * Note: For versioned transactions, account indices may reference
190
+ * accounts from Address Lookup Tables.
191
+ */
192
+ instructions() {
193
+ const instructions = this.inner.instructions();
194
+ return Array.from(instructions);
195
+ }
196
+ }
197
+ exports.VersionedTransaction = VersionedTransaction;