Skip to content

feat: add @bitgo/wasm-ton package#235

Draft
lcovar wants to merge 1 commit intomasterfrom
wasm-ton
Draft

feat: add @bitgo/wasm-ton package#235
lcovar wants to merge 1 commit intomasterfrom
wasm-ton

Conversation

@lcovar
Copy link
Copy Markdown
Contributor

@lcovar lcovar commented Mar 27, 2026

Summary

  • New @bitgo/wasm-ton WASM package for offline TON transaction building, parsing, and signing support
  • Built on toner (tlb-ton 0.7.3) Rust crate, compiles to wasm32-unknown-unknown
  • Supports all TON transaction types: transfer, token transfer (jetton), staking (TonWhales, SingleNominator, MultiNominator), vesting, consolidation, fillNonce
  • Two-layer architecture: core Rust logic in src/, thin #[wasm_bindgen] wrappers in src/wasm/, TypeScript wrappers in js/
  • No signing in WASM, only signablePayload() and addSignature() for TSS integration
  • 32 TypeScript tests covering address, transaction, and builder flows
  • private: true in package.json until npm package is created by velocity team

Ticket: BTC-3212

Copy link
Copy Markdown
Contributor

@OttoAllmendinger OttoAllmendinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's get rid of the enums

not super happy about the base conversion bloat but so far it's not out of control

Comment on lines +11 to +28
/** Staking provider types - runtime string enum */
export enum TonStakingType {
TonWhales = "TonWhales",
SingleNominator = "SingleNominator",
MultiNominator = "MultiNominator",
}

/** Transaction type enum - runtime string enum */
export enum TonTransactionType {
Transfer = "Transfer",
TokenTransfer = "TokenTransfer",
WhalesDeposit = "WhalesDeposit",
WhalesVestingDeposit = "WhalesVestingDeposit",
WhalesWithdraw = "WhalesWithdraw",
WhalesVestingWithdraw = "WhalesVestingWithdraw",
SingleNominatorWithdraw = "SingleNominatorWithdraw",
Unknown = "Unknown",
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we had type cast issues due to enum before

this is better:

const TonStakingType = ["TonWhales", ... ] as const;
typeof TonStakingType = typeof TonStakingType[number];

let's add it to the toplevel conventions

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines +36 to +41
/**
* Get the signable payload as base64 string.
*/
signablePayloadBase64(): string {
return this._wasm.signablePayloadBase64();
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

meh

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

Comment on lines +57 to +62
/**
* Serialize to base64 for broadcast.
*/
toBroadcastFormat(): string {
return this._wasm.toBroadcastFormat();
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

meh

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

Comment on lines +101 to +106
/**
* Convenience function to create a Transaction from base64.
*/
export function transactionFromBase64(b64: string): Transaction {
return Transaction.fromBase64(b64);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean at least we have the fromBytes as well

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

@lcovar lcovar force-pushed the wasm-ton branch 5 times, most recently from 7478e88 to deb8e6e Compare March 27, 2026 18:03
Rust/WASM package for TON (The Open Network) transaction building,
parsing, and signing. Uses toner v0.7.3 (pure Rust TON SDK) compiled
to wasm32-unknown-unknown.

Supports all wallet-platform intent types:
- payment (native TON + jetton token transfers)
- fillNonce (nonce hole filling via self-send)
- consolidate (native + token, 7-day expiry)
- delegate (TonWhales, SingleNominator, MultiNominator)
- undelegate (TonWhales, SingleNominator, MultiNominator)
- vesting contract variants for Whales deposit/withdraw

Architecture follows wasm-solana/wasm-dot patterns:
- Two-layer rule: core Rust logic in src/, thin WASM bindings in src/wasm/
- TypeScript wrappers in js/ with bigint for all monetary amounts
- Transaction signing via signablePayload() + addSignature()
- Standalone parseTransaction() for all 7 transaction shapes
- Intent-based buildTransaction() with BuildContext for offline building

32 TypeScript tests + Rust unit tests.

BTC-3211
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants