@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.
- package/dist/cjs/js/builder.d.ts +499 -0
- package/dist/cjs/js/builder.js +113 -0
- package/dist/cjs/js/index.d.ts +16 -0
- package/dist/cjs/js/index.js +79 -0
- package/dist/cjs/js/keypair.d.ts +47 -0
- package/dist/cjs/js/keypair.js +69 -0
- package/dist/cjs/js/parser.d.ts +253 -0
- package/dist/cjs/js/parser.js +58 -0
- package/dist/cjs/js/pubkey.d.ts +54 -0
- package/dist/cjs/js/pubkey.js +76 -0
- package/dist/cjs/js/transaction.d.ts +156 -0
- package/dist/cjs/js/transaction.js +176 -0
- package/dist/cjs/js/versioned.d.ts +177 -0
- package/dist/cjs/js/versioned.js +197 -0
- package/dist/cjs/js/wasm/wasm_solana.d.ts +1030 -0
- package/dist/cjs/js/wasm/wasm_solana.js +6216 -0
- package/dist/cjs/js/wasm/wasm_solana_bg.wasm +0 -0
- package/dist/cjs/js/wasm/wasm_solana_bg.wasm.d.ts +341 -0
- package/dist/cjs/package.json +1 -0
- package/dist/esm/js/builder.d.ts +499 -0
- package/dist/esm/js/builder.js +109 -0
- package/dist/esm/js/index.d.ts +16 -0
- package/dist/esm/js/index.js +24 -0
- package/dist/esm/js/keypair.d.ts +47 -0
- package/dist/esm/js/keypair.js +65 -0
- package/dist/esm/js/parser.d.ts +253 -0
- package/dist/esm/js/parser.js +55 -0
- package/dist/esm/js/pubkey.d.ts +54 -0
- package/dist/esm/js/pubkey.js +72 -0
- package/dist/esm/js/transaction.d.ts +156 -0
- package/dist/esm/js/transaction.js +172 -0
- package/dist/esm/js/versioned.d.ts +177 -0
- package/dist/esm/js/versioned.js +192 -0
- package/dist/esm/js/wasm/wasm_solana.d.ts +1030 -0
- package/dist/esm/js/wasm/wasm_solana.js +4 -0
- package/dist/esm/js/wasm/wasm_solana_bg.js +6138 -0
- package/dist/esm/js/wasm/wasm_solana_bg.wasm +0 -0
- package/dist/esm/js/wasm/wasm_solana_bg.wasm.d.ts +341 -0
- package/package.json +1 -1
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { WasmKeypair } from "./wasm/wasm_solana.js";
|
|
2
|
+
/**
|
|
3
|
+
* Solana Ed25519 Keypair for address generation and signing
|
|
4
|
+
*
|
|
5
|
+
* A keypair consists of a 32-byte secret key and a 32-byte public key.
|
|
6
|
+
* The public key (base58-encoded) is the Solana address.
|
|
7
|
+
*/
|
|
8
|
+
export declare class Keypair {
|
|
9
|
+
private _wasm;
|
|
10
|
+
private constructor();
|
|
11
|
+
/**
|
|
12
|
+
* Create a keypair from a 32-byte secret key
|
|
13
|
+
* @param secretKey - The 32-byte Ed25519 secret key
|
|
14
|
+
* @returns A Keypair instance
|
|
15
|
+
*/
|
|
16
|
+
static fromSecretKey(secretKey: Uint8Array): Keypair;
|
|
17
|
+
/**
|
|
18
|
+
* Create a keypair from a 64-byte Solana secret key (secret + public concatenated)
|
|
19
|
+
* This is the format used by @solana/web3.js Keypair.fromSecretKey()
|
|
20
|
+
* @param secretKey - The 64-byte Solana secret key
|
|
21
|
+
* @returns A Keypair instance
|
|
22
|
+
*/
|
|
23
|
+
static fromSolanaSecretKey(secretKey: Uint8Array): Keypair;
|
|
24
|
+
/**
|
|
25
|
+
* Get the public key as a 32-byte Uint8Array
|
|
26
|
+
*/
|
|
27
|
+
get publicKey(): Uint8Array;
|
|
28
|
+
/**
|
|
29
|
+
* Get the secret key as a 32-byte Uint8Array
|
|
30
|
+
*/
|
|
31
|
+
get secretKey(): Uint8Array;
|
|
32
|
+
/**
|
|
33
|
+
* Get the Solana address (base58-encoded public key)
|
|
34
|
+
* @returns The address as a base58 string
|
|
35
|
+
*/
|
|
36
|
+
getAddress(): string;
|
|
37
|
+
/**
|
|
38
|
+
* Get the public key as a base58 string
|
|
39
|
+
* @returns The public key as a base58 string
|
|
40
|
+
*/
|
|
41
|
+
toBase58(): string;
|
|
42
|
+
/**
|
|
43
|
+
* Get the underlying WASM instance (internal use only)
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
get wasm(): WasmKeypair;
|
|
47
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { WasmKeypair } from "./wasm/wasm_solana.js";
|
|
2
|
+
/**
|
|
3
|
+
* Solana Ed25519 Keypair for address generation and signing
|
|
4
|
+
*
|
|
5
|
+
* A keypair consists of a 32-byte secret key and a 32-byte public key.
|
|
6
|
+
* The public key (base58-encoded) is the Solana address.
|
|
7
|
+
*/
|
|
8
|
+
export class Keypair {
|
|
9
|
+
_wasm;
|
|
10
|
+
constructor(_wasm) {
|
|
11
|
+
this._wasm = _wasm;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Create a keypair from a 32-byte secret key
|
|
15
|
+
* @param secretKey - The 32-byte Ed25519 secret key
|
|
16
|
+
* @returns A Keypair instance
|
|
17
|
+
*/
|
|
18
|
+
static fromSecretKey(secretKey) {
|
|
19
|
+
const wasm = WasmKeypair.from_secret_key(secretKey);
|
|
20
|
+
return new Keypair(wasm);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Create a keypair from a 64-byte Solana secret key (secret + public concatenated)
|
|
24
|
+
* This is the format used by @solana/web3.js Keypair.fromSecretKey()
|
|
25
|
+
* @param secretKey - The 64-byte Solana secret key
|
|
26
|
+
* @returns A Keypair instance
|
|
27
|
+
*/
|
|
28
|
+
static fromSolanaSecretKey(secretKey) {
|
|
29
|
+
const wasm = WasmKeypair.from_solana_secret_key(secretKey);
|
|
30
|
+
return new Keypair(wasm);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Get the public key as a 32-byte Uint8Array
|
|
34
|
+
*/
|
|
35
|
+
get publicKey() {
|
|
36
|
+
return this._wasm.public_key;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Get the secret key as a 32-byte Uint8Array
|
|
40
|
+
*/
|
|
41
|
+
get secretKey() {
|
|
42
|
+
return this._wasm.secret_key;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Get the Solana address (base58-encoded public key)
|
|
46
|
+
* @returns The address as a base58 string
|
|
47
|
+
*/
|
|
48
|
+
getAddress() {
|
|
49
|
+
return this._wasm.address();
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Get the public key as a base58 string
|
|
53
|
+
* @returns The public key as a base58 string
|
|
54
|
+
*/
|
|
55
|
+
toBase58() {
|
|
56
|
+
return this._wasm.to_base58();
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Get the underlying WASM instance (internal use only)
|
|
60
|
+
* @internal
|
|
61
|
+
*/
|
|
62
|
+
get wasm() {
|
|
63
|
+
return this._wasm;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* High-level transaction parsing.
|
|
3
|
+
*
|
|
4
|
+
* Provides types and functions for parsing Solana transactions into semantic data
|
|
5
|
+
* matching BitGoJS's TxData format.
|
|
6
|
+
*
|
|
7
|
+
* All monetary amounts (amount, fee, lamports, poolTokens) are returned as bigint.
|
|
8
|
+
* Accepts both raw bytes and Transaction objects for convenience.
|
|
9
|
+
*/
|
|
10
|
+
import type { Transaction } from "./transaction.js";
|
|
11
|
+
import type { VersionedTransaction } from "./versioned.js";
|
|
12
|
+
/**
|
|
13
|
+
* Input type for parseTransaction - accepts bytes or Transaction objects.
|
|
14
|
+
*/
|
|
15
|
+
export type TransactionInput = Uint8Array | Transaction | VersionedTransaction;
|
|
16
|
+
/** SOL transfer parameters */
|
|
17
|
+
export interface TransferParams {
|
|
18
|
+
type: "Transfer";
|
|
19
|
+
fromAddress: string;
|
|
20
|
+
toAddress: string;
|
|
21
|
+
amount: bigint;
|
|
22
|
+
}
|
|
23
|
+
/** Create account parameters */
|
|
24
|
+
export interface CreateAccountParams {
|
|
25
|
+
type: "CreateAccount";
|
|
26
|
+
fromAddress: string;
|
|
27
|
+
newAddress: string;
|
|
28
|
+
amount: bigint;
|
|
29
|
+
space: number;
|
|
30
|
+
owner: string;
|
|
31
|
+
}
|
|
32
|
+
/** Nonce advance parameters */
|
|
33
|
+
export interface NonceAdvanceParams {
|
|
34
|
+
type: "NonceAdvance";
|
|
35
|
+
walletNonceAddress: string;
|
|
36
|
+
authWalletAddress: string;
|
|
37
|
+
}
|
|
38
|
+
/** Create nonce account parameters (combined type) */
|
|
39
|
+
export interface CreateNonceAccountParams {
|
|
40
|
+
type: "CreateNonceAccount";
|
|
41
|
+
fromAddress: string;
|
|
42
|
+
nonceAddress: string;
|
|
43
|
+
authAddress: string;
|
|
44
|
+
amount: bigint;
|
|
45
|
+
}
|
|
46
|
+
/** Nonce initialize parameters (intermediate - combined into CreateNonceAccount) */
|
|
47
|
+
export interface NonceInitializeParams {
|
|
48
|
+
type: "NonceInitialize";
|
|
49
|
+
nonceAddress: string;
|
|
50
|
+
authAddress: string;
|
|
51
|
+
}
|
|
52
|
+
/** Stake initialize parameters (intermediate - combined into StakingActivate) */
|
|
53
|
+
export interface StakeInitializeParams {
|
|
54
|
+
type: "StakeInitialize";
|
|
55
|
+
stakingAddress: string;
|
|
56
|
+
staker: string;
|
|
57
|
+
withdrawer: string;
|
|
58
|
+
}
|
|
59
|
+
/** Staking activate parameters (combined type) */
|
|
60
|
+
export interface StakingActivateParams {
|
|
61
|
+
type: "StakingActivate";
|
|
62
|
+
fromAddress: string;
|
|
63
|
+
stakingAddress: string;
|
|
64
|
+
amount: bigint;
|
|
65
|
+
validator: string;
|
|
66
|
+
stakingType: "NATIVE" | "JITO" | "MARINADE";
|
|
67
|
+
}
|
|
68
|
+
/** Staking deactivate parameters */
|
|
69
|
+
export interface StakingDeactivateParams {
|
|
70
|
+
type: "StakingDeactivate";
|
|
71
|
+
stakingAddress: string;
|
|
72
|
+
fromAddress: string;
|
|
73
|
+
}
|
|
74
|
+
/** Staking withdraw parameters */
|
|
75
|
+
export interface StakingWithdrawParams {
|
|
76
|
+
type: "StakingWithdraw";
|
|
77
|
+
fromAddress: string;
|
|
78
|
+
stakingAddress: string;
|
|
79
|
+
amount: bigint;
|
|
80
|
+
}
|
|
81
|
+
/** Staking delegate parameters */
|
|
82
|
+
export interface StakingDelegateParams {
|
|
83
|
+
type: "StakingDelegate";
|
|
84
|
+
stakingAddress: string;
|
|
85
|
+
fromAddress: string;
|
|
86
|
+
validator: string;
|
|
87
|
+
}
|
|
88
|
+
/** Staking authorize parameters */
|
|
89
|
+
export interface StakingAuthorizeParams {
|
|
90
|
+
type: "StakingAuthorize";
|
|
91
|
+
stakingAddress: string;
|
|
92
|
+
oldAuthorizeAddress: string;
|
|
93
|
+
newAuthorizeAddress: string;
|
|
94
|
+
authorizeType: "Staker" | "Withdrawer";
|
|
95
|
+
custodianAddress?: string;
|
|
96
|
+
}
|
|
97
|
+
/** Stake initialize parameters (intermediate type) */
|
|
98
|
+
export interface StakeInitializeParams {
|
|
99
|
+
type: "StakeInitialize";
|
|
100
|
+
stakingAddress: string;
|
|
101
|
+
staker: string;
|
|
102
|
+
withdrawer: string;
|
|
103
|
+
}
|
|
104
|
+
/** Set compute unit limit parameters */
|
|
105
|
+
export interface SetComputeUnitLimitParams {
|
|
106
|
+
type: "SetComputeUnitLimit";
|
|
107
|
+
units: number;
|
|
108
|
+
}
|
|
109
|
+
/** Set priority fee parameters */
|
|
110
|
+
export interface SetPriorityFeeParams {
|
|
111
|
+
type: "SetPriorityFee";
|
|
112
|
+
fee: bigint;
|
|
113
|
+
}
|
|
114
|
+
/** Token transfer parameters */
|
|
115
|
+
export interface TokenTransferParams {
|
|
116
|
+
type: "TokenTransfer";
|
|
117
|
+
fromAddress: string;
|
|
118
|
+
toAddress: string;
|
|
119
|
+
amount: bigint;
|
|
120
|
+
sourceAddress: string;
|
|
121
|
+
tokenAddress?: string;
|
|
122
|
+
programId: string;
|
|
123
|
+
decimalPlaces?: number;
|
|
124
|
+
}
|
|
125
|
+
/** Create associated token account parameters */
|
|
126
|
+
export interface CreateAtaParams {
|
|
127
|
+
type: "CreateAssociatedTokenAccount";
|
|
128
|
+
mintAddress: string;
|
|
129
|
+
ataAddress: string;
|
|
130
|
+
ownerAddress: string;
|
|
131
|
+
payerAddress: string;
|
|
132
|
+
programId: string;
|
|
133
|
+
}
|
|
134
|
+
/** Close associated token account parameters */
|
|
135
|
+
export interface CloseAtaParams {
|
|
136
|
+
type: "CloseAssociatedTokenAccount";
|
|
137
|
+
accountAddress: string;
|
|
138
|
+
destinationAddress: string;
|
|
139
|
+
authorityAddress: string;
|
|
140
|
+
}
|
|
141
|
+
/** Memo parameters */
|
|
142
|
+
export interface MemoParams {
|
|
143
|
+
type: "Memo";
|
|
144
|
+
memo: string;
|
|
145
|
+
}
|
|
146
|
+
/** Stake pool deposit SOL parameters (Jito liquid staking) */
|
|
147
|
+
export interface StakePoolDepositSolParams {
|
|
148
|
+
type: "StakePoolDepositSol";
|
|
149
|
+
stakePool: string;
|
|
150
|
+
withdrawAuthority: string;
|
|
151
|
+
reserveStake: string;
|
|
152
|
+
fundingAccount: string;
|
|
153
|
+
destinationPoolAccount: string;
|
|
154
|
+
managerFeeAccount: string;
|
|
155
|
+
referralPoolAccount: string;
|
|
156
|
+
poolMint: string;
|
|
157
|
+
lamports: bigint;
|
|
158
|
+
}
|
|
159
|
+
/** Stake pool withdraw stake parameters (Jito liquid staking) */
|
|
160
|
+
export interface StakePoolWithdrawStakeParams {
|
|
161
|
+
type: "StakePoolWithdrawStake";
|
|
162
|
+
stakePool: string;
|
|
163
|
+
validatorList: string;
|
|
164
|
+
withdrawAuthority: string;
|
|
165
|
+
validatorStake: string;
|
|
166
|
+
destinationStake: string;
|
|
167
|
+
destinationStakeAuthority: string;
|
|
168
|
+
sourceTransferAuthority: string;
|
|
169
|
+
sourcePoolAccount: string;
|
|
170
|
+
managerFeeAccount: string;
|
|
171
|
+
poolMint: string;
|
|
172
|
+
poolTokens: bigint;
|
|
173
|
+
}
|
|
174
|
+
/** Account metadata for unknown instructions */
|
|
175
|
+
export interface AccountMeta {
|
|
176
|
+
pubkey: string;
|
|
177
|
+
isSigner: boolean;
|
|
178
|
+
isWritable: boolean;
|
|
179
|
+
}
|
|
180
|
+
/** Unknown instruction parameters */
|
|
181
|
+
export interface UnknownInstructionParams {
|
|
182
|
+
type: "Unknown";
|
|
183
|
+
programId: string;
|
|
184
|
+
accounts: AccountMeta[];
|
|
185
|
+
data: string;
|
|
186
|
+
}
|
|
187
|
+
/** Union of all instruction parameter types */
|
|
188
|
+
export type InstructionParams = TransferParams | CreateAccountParams | NonceAdvanceParams | CreateNonceAccountParams | NonceInitializeParams | StakingActivateParams | StakingDeactivateParams | StakingWithdrawParams | StakingDelegateParams | StakingAuthorizeParams | StakeInitializeParams | SetComputeUnitLimitParams | SetPriorityFeeParams | TokenTransferParams | CreateAtaParams | CloseAtaParams | MemoParams | StakePoolDepositSolParams | StakePoolWithdrawStakeParams | UnknownInstructionParams;
|
|
189
|
+
/** Durable nonce information */
|
|
190
|
+
export interface DurableNonce {
|
|
191
|
+
walletNonceAddress: string;
|
|
192
|
+
authWalletAddress: string;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* A fully parsed Solana transaction with decoded instructions.
|
|
196
|
+
*
|
|
197
|
+
* This structure matches BitGoJS's TxData interface for seamless integration.
|
|
198
|
+
* All monetary amounts are returned as bigint directly from WASM.
|
|
199
|
+
*/
|
|
200
|
+
export interface ParsedTransaction {
|
|
201
|
+
/** The fee payer address (base58) */
|
|
202
|
+
feePayer: string;
|
|
203
|
+
/** Number of required signatures */
|
|
204
|
+
numSignatures: number;
|
|
205
|
+
/** The blockhash or nonce value (base58) */
|
|
206
|
+
nonce: string;
|
|
207
|
+
/** If this is a durable nonce transaction, contains the nonce info */
|
|
208
|
+
durableNonce?: DurableNonce;
|
|
209
|
+
/** All decoded instructions with semantic types */
|
|
210
|
+
instructionsData: InstructionParams[];
|
|
211
|
+
/** All account keys (base58 strings) */
|
|
212
|
+
accountKeys: string[];
|
|
213
|
+
/** All signatures (base58 strings). Non-empty signatures indicate signed transaction. */
|
|
214
|
+
signatures: string[];
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Parse a Solana transaction into structured data.
|
|
218
|
+
*
|
|
219
|
+
* This is the main entry point for transaction parsing. It deserializes the
|
|
220
|
+
* transaction and decodes all instructions into semantic types.
|
|
221
|
+
*
|
|
222
|
+
* All monetary amounts (amount, fee, lamports, poolTokens) are returned as bigint
|
|
223
|
+
* directly from WASM - no post-processing needed.
|
|
224
|
+
*
|
|
225
|
+
* Note: This returns the raw parsed data including NonceAdvance instructions.
|
|
226
|
+
* Consumers (like BitGoJS) may choose to filter NonceAdvance from instructionsData
|
|
227
|
+
* since that info is also available in durableNonce.
|
|
228
|
+
*
|
|
229
|
+
* @param input - Raw transaction bytes, Transaction, or VersionedTransaction
|
|
230
|
+
* @returns A ParsedTransaction with all instructions decoded
|
|
231
|
+
* @throws Error if the transaction cannot be parsed
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* ```typescript
|
|
235
|
+
* import { parseTransaction, buildTransaction, Transaction } from '@bitgo/wasm-solana';
|
|
236
|
+
*
|
|
237
|
+
* // From bytes
|
|
238
|
+
* const txBytes = Buffer.from(base64EncodedTx, 'base64');
|
|
239
|
+
* const parsed = parseTransaction(txBytes);
|
|
240
|
+
*
|
|
241
|
+
* // Directly from a Transaction object (no roundtrip through bytes)
|
|
242
|
+
* const tx = buildTransaction(intent);
|
|
243
|
+
* const parsed = parseTransaction(tx);
|
|
244
|
+
*
|
|
245
|
+
* console.log(parsed.feePayer);
|
|
246
|
+
* for (const instr of parsed.instructionsData) {
|
|
247
|
+
* if (instr.type === 'Transfer') {
|
|
248
|
+
* console.log(`Transfer ${instr.amount} from ${instr.fromAddress} to ${instr.toAddress}`);
|
|
249
|
+
* }
|
|
250
|
+
* }
|
|
251
|
+
* ```
|
|
252
|
+
*/
|
|
253
|
+
export declare function parseTransaction(input: TransactionInput): ParsedTransaction;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* High-level transaction parsing.
|
|
3
|
+
*
|
|
4
|
+
* Provides types and functions for parsing Solana transactions into semantic data
|
|
5
|
+
* matching BitGoJS's TxData format.
|
|
6
|
+
*
|
|
7
|
+
* All monetary amounts (amount, fee, lamports, poolTokens) are returned as bigint.
|
|
8
|
+
* Accepts both raw bytes and Transaction objects for convenience.
|
|
9
|
+
*/
|
|
10
|
+
import { ParserNamespace } from "./wasm/wasm_solana.js";
|
|
11
|
+
// =============================================================================
|
|
12
|
+
// parseTransaction function
|
|
13
|
+
// =============================================================================
|
|
14
|
+
/**
|
|
15
|
+
* Parse a Solana transaction into structured data.
|
|
16
|
+
*
|
|
17
|
+
* This is the main entry point for transaction parsing. It deserializes the
|
|
18
|
+
* transaction and decodes all instructions into semantic types.
|
|
19
|
+
*
|
|
20
|
+
* All monetary amounts (amount, fee, lamports, poolTokens) are returned as bigint
|
|
21
|
+
* directly from WASM - no post-processing needed.
|
|
22
|
+
*
|
|
23
|
+
* Note: This returns the raw parsed data including NonceAdvance instructions.
|
|
24
|
+
* Consumers (like BitGoJS) may choose to filter NonceAdvance from instructionsData
|
|
25
|
+
* since that info is also available in durableNonce.
|
|
26
|
+
*
|
|
27
|
+
* @param input - Raw transaction bytes, Transaction, or VersionedTransaction
|
|
28
|
+
* @returns A ParsedTransaction with all instructions decoded
|
|
29
|
+
* @throws Error if the transaction cannot be parsed
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* import { parseTransaction, buildTransaction, Transaction } from '@bitgo/wasm-solana';
|
|
34
|
+
*
|
|
35
|
+
* // From bytes
|
|
36
|
+
* const txBytes = Buffer.from(base64EncodedTx, 'base64');
|
|
37
|
+
* const parsed = parseTransaction(txBytes);
|
|
38
|
+
*
|
|
39
|
+
* // Directly from a Transaction object (no roundtrip through bytes)
|
|
40
|
+
* const tx = buildTransaction(intent);
|
|
41
|
+
* const parsed = parseTransaction(tx);
|
|
42
|
+
*
|
|
43
|
+
* console.log(parsed.feePayer);
|
|
44
|
+
* for (const instr of parsed.instructionsData) {
|
|
45
|
+
* if (instr.type === 'Transfer') {
|
|
46
|
+
* console.log(`Transfer ${instr.amount} from ${instr.fromAddress} to ${instr.toAddress}`);
|
|
47
|
+
* }
|
|
48
|
+
* }
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export function parseTransaction(input) {
|
|
52
|
+
// If input is a Transaction or VersionedTransaction, extract bytes
|
|
53
|
+
const bytes = input instanceof Uint8Array ? input : input.toBytes();
|
|
54
|
+
return ParserNamespace.parse_transaction(bytes);
|
|
55
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { WasmPubkey } from "./wasm/wasm_solana.js";
|
|
2
|
+
/**
|
|
3
|
+
* Solana public key (address)
|
|
4
|
+
*
|
|
5
|
+
* A Solana address is a 32-byte Ed25519 public key, typically represented as a base58 string.
|
|
6
|
+
*/
|
|
7
|
+
export declare class Pubkey {
|
|
8
|
+
private _wasm;
|
|
9
|
+
private constructor();
|
|
10
|
+
/**
|
|
11
|
+
* Create a Pubkey from a base58 string
|
|
12
|
+
* @param address - The base58-encoded address
|
|
13
|
+
* @returns A Pubkey instance
|
|
14
|
+
*/
|
|
15
|
+
static fromBase58(address: string): Pubkey;
|
|
16
|
+
/**
|
|
17
|
+
* Create a Pubkey from raw bytes (32 bytes)
|
|
18
|
+
* @param bytes - The 32-byte public key
|
|
19
|
+
* @returns A Pubkey instance
|
|
20
|
+
*/
|
|
21
|
+
static fromBytes(bytes: Uint8Array): Pubkey;
|
|
22
|
+
/**
|
|
23
|
+
* Convert to base58 string (the standard Solana address format)
|
|
24
|
+
* @returns The address as a base58 string
|
|
25
|
+
*/
|
|
26
|
+
toBase58(): string;
|
|
27
|
+
/**
|
|
28
|
+
* Get as raw bytes (32 bytes)
|
|
29
|
+
* @returns The public key as a Uint8Array
|
|
30
|
+
*/
|
|
31
|
+
toBytes(): Uint8Array;
|
|
32
|
+
/**
|
|
33
|
+
* Check if two pubkeys are equal
|
|
34
|
+
* @param other - The other Pubkey to compare
|
|
35
|
+
* @returns true if the pubkeys are equal
|
|
36
|
+
*/
|
|
37
|
+
equals(other: Pubkey): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Check if this public key is on the Ed25519 curve.
|
|
40
|
+
*
|
|
41
|
+
* Regular Solana keypair addresses are on the curve, while Program Derived Addresses (PDAs)
|
|
42
|
+
* are intentionally off the curve to ensure they can only be signed by programs.
|
|
43
|
+
*
|
|
44
|
+
* This is equivalent to `@solana/web3.js` `PublicKey.isOnCurve()`.
|
|
45
|
+
*
|
|
46
|
+
* @returns true if the public key is on the Ed25519 curve
|
|
47
|
+
*/
|
|
48
|
+
isOnCurve(): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Get the underlying WASM instance (internal use only)
|
|
51
|
+
* @internal
|
|
52
|
+
*/
|
|
53
|
+
get wasm(): WasmPubkey;
|
|
54
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { WasmPubkey } from "./wasm/wasm_solana.js";
|
|
2
|
+
/**
|
|
3
|
+
* Solana public key (address)
|
|
4
|
+
*
|
|
5
|
+
* A Solana address is a 32-byte Ed25519 public key, typically represented as a base58 string.
|
|
6
|
+
*/
|
|
7
|
+
export class Pubkey {
|
|
8
|
+
_wasm;
|
|
9
|
+
constructor(_wasm) {
|
|
10
|
+
this._wasm = _wasm;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Create a Pubkey from a base58 string
|
|
14
|
+
* @param address - The base58-encoded address
|
|
15
|
+
* @returns A Pubkey instance
|
|
16
|
+
*/
|
|
17
|
+
static fromBase58(address) {
|
|
18
|
+
const wasm = WasmPubkey.from_base58(address);
|
|
19
|
+
return new Pubkey(wasm);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Create a Pubkey from raw bytes (32 bytes)
|
|
23
|
+
* @param bytes - The 32-byte public key
|
|
24
|
+
* @returns A Pubkey instance
|
|
25
|
+
*/
|
|
26
|
+
static fromBytes(bytes) {
|
|
27
|
+
const wasm = WasmPubkey.from_bytes(bytes);
|
|
28
|
+
return new Pubkey(wasm);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Convert to base58 string (the standard Solana address format)
|
|
32
|
+
* @returns The address as a base58 string
|
|
33
|
+
*/
|
|
34
|
+
toBase58() {
|
|
35
|
+
return this._wasm.to_base58();
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Get as raw bytes (32 bytes)
|
|
39
|
+
* @returns The public key as a Uint8Array
|
|
40
|
+
*/
|
|
41
|
+
toBytes() {
|
|
42
|
+
return this._wasm.to_bytes();
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Check if two pubkeys are equal
|
|
46
|
+
* @param other - The other Pubkey to compare
|
|
47
|
+
* @returns true if the pubkeys are equal
|
|
48
|
+
*/
|
|
49
|
+
equals(other) {
|
|
50
|
+
return this._wasm.equals(other._wasm);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Check if this public key is on the Ed25519 curve.
|
|
54
|
+
*
|
|
55
|
+
* Regular Solana keypair addresses are on the curve, while Program Derived Addresses (PDAs)
|
|
56
|
+
* are intentionally off the curve to ensure they can only be signed by programs.
|
|
57
|
+
*
|
|
58
|
+
* This is equivalent to `@solana/web3.js` `PublicKey.isOnCurve()`.
|
|
59
|
+
*
|
|
60
|
+
* @returns true if the public key is on the Ed25519 curve
|
|
61
|
+
*/
|
|
62
|
+
isOnCurve() {
|
|
63
|
+
return this._wasm.is_on_curve();
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Get the underlying WASM instance (internal use only)
|
|
67
|
+
* @internal
|
|
68
|
+
*/
|
|
69
|
+
get wasm() {
|
|
70
|
+
return this._wasm;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -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
|
+
}
|