Skip to content

Commit 171820c

Browse files
authored
Merge pull request #114 from BitGo/BTC-2929-add-signatures
feat: add signatures to parsed transactions
2 parents bc27288 + 38d33ce commit 171820c

3 files changed

Lines changed: 31 additions & 1 deletion

File tree

packages/wasm-solana/js/parser.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,9 @@ export interface ParsedTransaction {
255255

256256
/** All account keys (base58 strings) */
257257
accountKeys: string[];
258+
259+
/** All signatures (base58 strings). Non-empty signatures indicate signed transaction. */
260+
signatures: string[];
258261
}
259262

260263
// =============================================================================

packages/wasm-solana/src/parser.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ pub struct ParsedTransaction {
3535

3636
/// All account keys (base58 strings).
3737
pub account_keys: Vec<String>,
38+
39+
/// All signatures (base58 strings). Non-empty signatures indicate signed transaction.
40+
pub signatures: Vec<String>,
3841
}
3942

4043
/// Durable nonce information for nonce-based transactions.
@@ -64,7 +67,8 @@ impl TryIntoJsValue for ParsedTransaction {
6467
"nonce" => self.nonce,
6568
"durableNonce" => self.durable_nonce,
6669
"instructionsData" => self.instructions_data,
67-
"accountKeys" => self.account_keys
70+
"accountKeys" => self.account_keys,
71+
"signatures" => self.signatures
6872
)
6973
}
7074
}
@@ -139,13 +143,17 @@ pub fn parse_transaction(bytes: &[u8]) -> Result<ParsedTransaction, String> {
139143
// (which is the nonce value from the nonce account)
140144
let nonce = message.recent_blockhash.to_string();
141145

146+
// Extract signatures as base58 strings
147+
let signatures: Vec<String> = tx.signatures.iter().map(|s| s.to_string()).collect();
148+
142149
Ok(ParsedTransaction {
143150
fee_payer,
144151
num_signatures: message.header.num_required_signatures,
145152
nonce,
146153
durable_nonce,
147154
instructions_data,
148155
account_keys,
156+
signatures,
149157
})
150158
}
151159

@@ -168,6 +176,11 @@ mod tests {
168176
assert!(!parsed.nonce.is_empty());
169177
assert_eq!(parsed.instructions_data.len(), 1);
170178

179+
// Check signatures are returned
180+
assert_eq!(parsed.signatures.len(), 1);
181+
// Unsigned transactions have all-zero signatures (base58 encoded)
182+
assert!(!parsed.signatures[0].is_empty());
183+
171184
// Check the instruction is a Transfer
172185
match &parsed.instructions_data[0] {
173186
ParsedInstruction::Transfer(params) => {

packages/wasm-solana/test/parser.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@ describe("parseTransaction", () => {
2525
assert.ok(parsed.accountKeys.length > 0);
2626
});
2727

28+
it("should include signatures as base58 strings", () => {
29+
const parsed = parseTransaction(TEST_TX_BYTES);
30+
31+
// Should have signatures array
32+
assert.ok(Array.isArray(parsed.signatures));
33+
assert.strictEqual(parsed.signatures.length, parsed.numSignatures);
34+
35+
// Each signature should be a non-empty string (base58 encoded)
36+
for (const sig of parsed.signatures) {
37+
assert.strictEqual(typeof sig, "string");
38+
assert.ok(sig.length > 0);
39+
}
40+
});
41+
2842
it("should decode SOL transfer instruction correctly", () => {
2943
const parsed = parseTransaction(TEST_TX_BYTES);
3044

0 commit comments

Comments
 (0)