Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/wasm-solana/js/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class Transaction {
* Get the transaction ID (first signature as base58).
*
* For Solana, the transaction ID is the first signature.
* Returns "UNSIGNED" if the transaction has no valid signatures.
* Returns `undefined` if the transaction is unsigned (no signatures or all-zeros signature).
*
* @example
* ```typescript
Expand All @@ -100,7 +100,7 @@ export class Transaction {
* console.log(tx.id); // Base58 encoded signature
* ```
*/
get id(): string {
get id(): string | undefined {
return this._wasm.id;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/wasm-solana/js/versioned.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ export class VersionedTransaction {
* Get the transaction ID (first signature as base58).
*
* For Solana, the transaction ID is the first signature.
* Returns "UNSIGNED" if the transaction has no valid signatures.
* Returns `undefined` if the transaction is unsigned (no signatures or all-zeros signature).
*/
get id(): string {
get id(): string | undefined {
return this.inner.id;
}

Expand Down
20 changes: 10 additions & 10 deletions packages/wasm-solana/src/wasm/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,18 @@ impl WasmTransaction {
/// Get the transaction ID (first signature as base58).
///
/// For Solana, the transaction ID is the first signature.
/// Returns "UNSIGNED" if the first signature is all zeros (unsigned transaction).
/// Returns `undefined` if the transaction is unsigned (no signatures or all-zeros signature).
#[wasm_bindgen(getter)]
pub fn id(&self) -> String {
pub fn id(&self) -> Option<String> {
if let Some(sig) = self.inner.signatures.first() {
let bytes: &[u8] = sig.as_ref();
// Check if signature is all zeros (unsigned)
if bytes.iter().all(|&b| b == 0) {
return "UNSIGNED".to_string();
return None;
}
bs58::encode(bytes).into_string()
Some(bs58::encode(bytes).into_string())
} else {
"UNSIGNED".to_string()
None
}
}

Expand Down Expand Up @@ -270,18 +270,18 @@ impl WasmVersionedTransaction {
/// Get the transaction ID (first signature as base58).
///
/// For Solana, the transaction ID is the first signature.
/// Returns "UNSIGNED" if the first signature is all zeros (unsigned transaction).
/// Returns `undefined` if the transaction is unsigned (no signatures or all-zeros signature).
#[wasm_bindgen(getter)]
pub fn id(&self) -> String {
pub fn id(&self) -> Option<String> {
if let Some(sig) = self.inner.signatures.first() {
let bytes: &[u8] = sig.as_ref();
// Check if signature is all zeros (unsigned)
if bytes.iter().all(|&b| b == 0) {
return "UNSIGNED".to_string();
return None;
}
bs58::encode(bytes).into_string()
Some(bs58::encode(bytes).into_string())
} else {
"UNSIGNED".to_string()
None
}
}

Expand Down
8 changes: 4 additions & 4 deletions packages/wasm-solana/test/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ describe("Transaction", () => {
});

describe("id getter", () => {
it("should return UNSIGNED for unsigned transaction", () => {
it("should return undefined for unsigned transaction", () => {
const tx = Transaction.fromBytes(TEST_TX_BYTES);
// The test transaction has an all-zeros signature (unsigned)
assert.strictEqual(tx.id, "UNSIGNED");
assert.strictEqual(tx.id, undefined);
});

it("should return base58 signature after signing", () => {
Expand All @@ -144,8 +144,8 @@ describe("Transaction", () => {

// ID should now be a base58-encoded string of the signature
const id = tx.id;
assert.notStrictEqual(id, "UNSIGNED");
assert.ok(id.length > 20); // base58 encoded 64 bytes should be ~80+ chars
assert.notStrictEqual(id, undefined);
assert.ok(id && id.length > 20); // base58 encoded 64 bytes should be ~80+ chars
});
});

Expand Down
8 changes: 4 additions & 4 deletions packages/wasm-solana/test/versioned.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ describe("VersionedTransaction", () => {
});

describe("id getter", () => {
it("should return UNSIGNED for unsigned transaction", () => {
it("should return undefined for unsigned transaction", () => {
const bytes = Buffer.from(LEGACY_TX_BASE64, "base64");
const tx = VersionedTransaction.fromBytes(bytes);
// The test transaction has an all-zeros signature (unsigned)
assert.strictEqual(tx.id, "UNSIGNED");
assert.strictEqual(tx.id, undefined);
});

it("should return base58 signature after signing", () => {
Expand All @@ -113,8 +113,8 @@ describe("VersionedTransaction", () => {

// ID should now be a base58-encoded string of the signature
const id = tx.id;
assert.notStrictEqual(id, "UNSIGNED");
assert.ok(id.length > 20); // base58 encoded 64 bytes should be ~80+ chars
assert.notStrictEqual(id, undefined);
assert.ok(id && id.length > 20); // base58 encoded 64 bytes should be ~80+ chars
});
});
});