Skip to content

feat: add TON blockchain support#782

Merged
NeOMakinG merged 60 commits intomasterfrom
ton-chain
Jan 16, 2026
Merged

feat: add TON blockchain support#782
NeOMakinG merged 60 commits intomasterfrom
ton-chain

Conversation

@NeOMakinG
Copy link
Contributor

@NeOMakinG NeOMakinG commented Jan 12, 2026

Summary

Adds TON (The Open Network) blockchain support to HDWallet.

Changes

Core Types (packages/hdwallet-core/src/ton.ts)

  • TonGetAddress - Interface for address derivation
  • TonSignTx - Interface for transaction signing (BOC message bytes)
  • TonSignedTx - Signed transaction result
  • TonWalletInfo / TonWallet - Wallet interface with TON support
  • tonDescribePath - Path description for TON derivation
  • tonGetAccountPaths - Account path generation

Utils (packages/hdwallet-core/src/utils.ts)

  • Added Ton: 607 to slip44ByCoin mapping

Native Wallet (packages/hdwallet-native/)

  • ton.ts - Mixin classes for native TON wallet support
  • crypto/isolation/adapters/ton.ts - Ed25519 crypto adapter for TON
    • WalletV4R2 address derivation from public key
    • User-friendly base64 address formatting
    • Transaction signing with Ed25519

TON Chain Specifications

Property Value
SLIP44 Coin Type 607
Derivation Path m/44'/607'/<account>' (3-level hardened)
Signing Algorithm Ed25519
Address Format User-friendly base64 (48 chars)
Address Type WalletV4R2 StateInit

Derivation Path

TON uses a 3-level hardened path similar to Stellar (SEP-0005):

m/44'/607'/<account>'

This is because TON uses Ed25519 which requires all path components to be hardened.

Testing

  • Build: yarn build
  • Lint: yarn lint
  • Test: yarn test

Summary by CodeRabbit

  • New Features

    • Added TON blockchain support: address derivation, account path management, transaction signing, and adapter-based integrations.
    • Wallets can be initialized with a TON master key and derive TON seeds from mnemonics.
  • Chores

    • Updated test setup to mock TON dependencies.
    • Added TON library dependencies and bumped package versions across releases.

✏️ Tip: You can customize this high-level summary in your review settings.

- Add TON core types (TonGetAddress, TonSignTx, TonWallet, TonWalletInfo)
- Add TON derivation path support (m/44'/607'/<account>')
- Add TON native wallet implementation with Ed25519 crypto adapter
- Add WalletV4R2 address derivation from public key

TON Chain specs:
- SLIP44 Coin Type: 607
- Derivation Path: m/44'/607'/<account>' (3-level hardened, Ed25519)
- Address Format: User-friendly base64 (48 chars, WalletV4R2 StateInit)
@vercel
Copy link

vercel bot commented Jan 12, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
hdwallet Ready Ready Preview, Comment Jan 16, 2026 9:55pm

Request Review

@coderabbitai
Copy link

coderabbitai bot commented Jan 12, 2026

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

Adds TON (The Open Network) support across core and native packages: new core types/helpers, slip44 entry, native Ed25519 seed/adapter, native wallet mixins, Jest mock and dependency updates.

Changes

Cohort / File(s) Summary
Core TON types & helpers
packages/hdwallet-core/src/ton.ts, packages/hdwallet-core/src/index.ts
New TON interfaces, tonDescribePath, tonGetAccountPaths and re-export from core index.
Slip44 & guards
packages/hdwallet-core/src/utils.ts, packages/hdwallet-core/src/wallet.ts
Adds Ton: 607 to slip44Table and introduces supportsTon / infoTon type guards.
Native TON adapter
packages/hdwallet-native/src/crypto/isolation/adapters/ton.ts, packages/hdwallet-native/src/crypto/isolation/adapters/index.ts
New TonAdapter implementing address/publicKey derivation, signing, and BOC transfer creation; exported from adapters index.
Seed derivation (bip32/bip39)
packages/hdwallet-native/src/crypto/isolation/engines/default/bip32.ts, packages/hdwallet-native/src/crypto/isolation/engines/default/bip39.ts, packages/hdwallet-native/src/crypto/isolation/core/bip39/interfaces.ts
Adds TonSeed, toTonMasterKey, and Mnemonic.toTonSeed PBKDF2 flow for TON master key derivation.
Native wallet integration
packages/hdwallet-native/src/ton.ts, packages/hdwallet-native/src/native.ts
Adds MixinNativeTonWalletInfo and MixinNativeTonWallet; threads tonMasterKey through load/init/wipe and exposes tonGetAddress / tonSignTx.
Adapter args & docs
packages/hdwallet-native/src/adapter.ts
NativeAdapterArgs extended to accept/provide tonMasterKey; docs updated to describe TON derivation semantics.
Jest mock & config
jest.config.js, packages/hdwallet-native/__mocks__/@ton/ton.js
Jest transformIgnorePatterns updated; adds moduleNameMapper for ^@ton/ton$ and a mock implementation for @ton/ton.
Dependencies & version bumps
packages/hdwallet-native/package.json, lerna.json, various package.json files (multiple packages...)
Adds @ton/core, @ton/crypto, @ton/ton to native; bumps package versions to 1.62.40 and updates internal dependency ranges.

Sequence Diagram(s)

sequenceDiagram
    participant Mnemonic
    participant PBKDF2 as PBKDF2-SHA512
    participant TonSeed
    participant HMAC as HMAC-SHA512
    participant TonMasterKey as Ed25519 Master Key
    participant TonAdapter
    participant WalletContractV4
    participant SignedBoc as Signed Transfer BOC

    Mnemonic->>PBKDF2: toTonSeed(password)
    PBKDF2->>TonSeed: 64-byte seed
    TonSeed->>HMAC: toTonMasterKey()
    HMAC->>TonMasterKey: derive Ed25519 node (IL/IR)
    TonMasterKey->>TonAdapter: tonInitializeWallet(ed25519 node)
    TonAdapter->>TonAdapter: derive public key from path
    TonAdapter->>WalletContractV4: create(publicKey)
    TonAdapter->>SignedBoc: createSignedTransferBoc(params)
    SignedBoc-->>TonAdapter: return signed BOC
    TonAdapter-->>Caller: address / signed BOC
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested reviewers

  • gomesalexandre

Poem

🐰 Through seed and PBKDF2 I hop,

Ed25519 keys I stitch and crop,
I sign BOCs, derive each address,
TON now nestles in our mesh—
Hooray, a carrot-coded toss! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: add TON blockchain support' accurately describes the main change—comprehensive TON blockchain integration across the hdwallet monorepo.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ton-chain

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • SEP-0005: Entity not found: Issue - Could not find referenced Issue.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/hdwallet-native/src/native.ts (1)

493-521: Clear/revoke #tonMasterKey on wipe.

wipe() clears other master keys but leaves the TON master key in memory; this undermines wipe semantics and can retain sensitive material.

🔧 Suggested fix
-    const oldEd25519MasterKey = this.#ed25519MasterKey;
+    const oldEd25519MasterKey = this.#ed25519MasterKey;
+    const oldTonMasterKey = this.#tonMasterKey;
 
     this.#initialized = false;
     this.#secp256k1MasterKey = undefined;
     this.#ed25519MasterKey = undefined;
+    this.#tonMasterKey = undefined;
@@
     (await oldSecp256k1MasterKey)?.revoke?.();
     (await oldEd25519MasterKey)?.revoke?.();
+    (await oldTonMasterKey)?.revoke?.();
♻️ Duplicate comments (2)
packages/hdwallet-native/src/native.ts (2)

337-342: Guard optional toTonSeed before calling.

toTonSeed is optional; the non‑null assertion can throw at runtime when the mnemonic implementation doesn’t support TON derivation. Add an explicit guard and error message.

🔧 Suggested fix
-      this.#tonMasterKey = (async () => {
+      this.#tonMasterKey = (async () => {
         const isolatedMnemonic =
           typeof mnemonic === "string" ? await Isolation.Engines.Default.BIP39.Mnemonic.create(mnemonic) : mnemonic;
-        const tonSeed = await isolatedMnemonic.toTonSeed!();
+        if (!isolatedMnemonic.toTonSeed) {
+          throw new Error("Mnemonic implementation does not support TON key derivation");
+        }
+        const tonSeed = await isolatedMnemonic.toTonSeed();
         return await tonSeed.toTonMasterKey();
       })();

596-608: Guard optional toTonSeed before calling (loadDevice path).

Same issue as the constructor path: toTonSeed is optional and should be checked before use.

🔧 Suggested fix
-        const tonSeed = await isolatedMnemonic.toTonSeed!();
+        if (!isolatedMnemonic.toTonSeed) {
+          throw new Error("Mnemonic implementation does not support TON key derivation");
+        }
+        const tonSeed = await isolatedMnemonic.toTonSeed();
🧹 Nitpick comments (1)
packages/hdwallet-native/src/crypto/isolation/engines/default/bip39.ts (1)

45-61: Implementation correctly follows BIP-39 → SLIP-0010 Ed25519 for Trust Wallet compatibility.

The derivation uses standard BIP-39 parameters (2048 iterations, "mnemonic{password}" salt, SHA512) with proper NFKD normalization. The resulting TonSeed then provides SLIP-0010 Ed25519 master key derivation via toTonMasterKey().

Minor naming inconsistency: The parameter is named password here but passphrase in toSeed. Consider aligning for consistency.

🔧 Optional: Align parameter naming with toSeed
-  async toTonSeed(password?: string): Promise<TonSeed> {
+  async toTonSeed(passphrase?: string): Promise<TonSeed> {
     const mnemonic = this.#mnemonic;
-    const salt = new TextEncoder().encode(`mnemonic${password ?? ""}`.normalize("NFKD"));
+    const salt = new TextEncoder().encode(`mnemonic${passphrase ?? ""}`.normalize("NFKD"));

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 20

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (4)
packages/hdwallet-walletconnectV2/package.json (1)

17-23: Fix invalid JSON (trailing comma breaks parsing).

The trailing comma after the dependencies block makes this package.json invalid JSON and will break tooling. Remove the trailing comma.

🧩 Proposed fix
   "dependencies": {
     "@shapeshiftoss/hdwallet-core": "1.62.39",
     "@walletconnect/ethereum-provider": "^2.20.2",
     "@walletconnect/modal": "^2.6.2",
     "ethers": "^5.6.5"
-  },
+  }
 }
packages/hdwallet-trezor/package.json (1)

25-30: Remove trailing comma to fix invalid JSON.

The comma after the devDependencies object makes the top-level JSON invalid and is already triggering a parse error in Biome. Remove the trailing comma to keep package.json valid.

🛠️ Proposed fix
   "devDependencies": {
     "@types/bchaddrjs": "^0.4.0",
     "@types/lodash": "^4.14.168",
     "typedoc": "^0.20.36"
-  },
+  }
 }
packages/hdwallet-keepkey-tcp/package.json (1)

16-21: Remove trailing comma to keep package.json valid JSON.

The trailing comma after the last property makes this invalid JSON and breaks tooling.

🔧 Proposed fix
-  },
+  }
packages/hdwallet-trezor-connect/package.json (1)

16-21: Remove trailing comma to keep package.json valid JSON.

The trailing comma after the last property makes this invalid JSON and breaks tooling.

🔧 Proposed fix
-  },
+  }
🤖 Fix all issues with AI agents
In `@packages/hdwallet-coinbase/package.json`:
- Around line 24-25: The package.json contains a trailing comma before the final
closing brace which makes the JSON invalid; open
packages/hdwallet-coinbase/package.json and remove the trailing comma after the
last top-level property so the JSON object ends with "}" (i.e., ensure the last
key/value pair in the root object has no trailing comma), then run a JSON lint
or npm pack to confirm parsing succeeds.

In `@packages/hdwallet-core/package.json`:
- Around line 31-32: Remove the trailing comma in the package.json object before
the final closing brace to produce valid JSON; locate the dangling comma
immediately before the final "}" in the package.json and delete it so the file
ends with "}" without a preceding comma.

In `@packages/hdwallet-gridplus/package.json`:
- Around line 35-39: The package.json contains a trailing comma after the
"nohoist" array which makes the JSON invalid; remove the extra comma following
the array/object closure so the "nohoist" property (and its entries
"@ethereumjs/common" and "@ethereumjs/tx") end cleanly without a trailing comma,
ensuring valid JSON for tools to parse.

In `@packages/hdwallet-keepkey-chromeusb/package.json`:
- Around line 16-20: The package.json has a trailing comma after the
dependencies block which makes the JSON invalid; open package.json and remove
the comma after the closing dependencies object so the file ends with the
dependencies block that contains "@shapeshiftoss/hdwallet-core": "1.62.39" and
"@shapeshiftoss/hdwallet-keepkey": "1.62.39" without a trailing comma, ensuring
valid JSON for tooling like Biome.

In `@packages/hdwallet-keepkey-electron/package.json`:
- Around line 23-27: Remove the trailing comma after the root object in
package.json by deleting the comma following the closing brace of
"devDependencies" so the JSON is valid; specifically update the block containing
"devDependencies" (entries "@types/uuid" and "electron") to end with a closing
brace only, not "},", ensuring the file parses as valid JSON.

In `@packages/hdwallet-keepkey-nodehid/package.json`:
- Around line 24-25: Remove the trailing comma after the final object in
packages/hdwallet-keepkey-nodehid/package.json (the comma following the closing
brace “}”), making the JSON valid; update the file to end with a single closing
brace without a comma and validate the JSON (eg. with a JSON linter or npm/yarn)
before committing.

In `@packages/hdwallet-keepkey-nodewebusb/package.json`:
- Around line 25-26: The package.json contains an invalid trailing comma after
the devDependencies object which breaks JSON parsing; open the package.json and
remove the extraneous comma following the closing brace of the "devDependencies"
object so the JSON ends with a single closing brace and is valid for yarn/npm
operations.

In `@packages/hdwallet-keepkey-webusb/package.json`:
- Around line 20-22: package.json contains an invalid trailing comma after the
"devDependencies" block; open the package.json, locate the "devDependencies"
object (the entry containing "@types/w3c-web-usb"), and remove the trailing
comma following that block so the JSON is syntactically valid (or reformat the
file to ensure proper commas between top-level properties).

In `@packages/hdwallet-keepkey/package.json`:
- Around line 49-50: The package.json contains an invalid trailing comma right
before the closing brace which causes JSON parse errors; open package.json and
remove the extra comma after the last property so the final object ends with "}"
not ",}" (identify the trailing comma near the end of the file where the object
closes) and validate the JSON to ensure no other dangling commas remain.

In `@packages/hdwallet-keplr/package.json`:
- Around line 31-32: The package.json contains a trailing comma after the final
closing object (the comma after the "}" in the file) which makes the JSON
invalid; remove that trailing comma so the file ends with a single closing brace
(no comma) to restore valid JSON and allow yarn install/build to parse the
manifest.

In `@packages/hdwallet-ledger-webhid/package.json`:
- Around line 24-25: The package.json contains a trailing comma after the
dependencies block which makes the JSON invalid; open the package.json file,
locate the closing of the "dependencies" object (the comma after that block) and
remove the trailing comma so the top-level object ends with "}" only, ensuring
the JSON parses correctly for package managers.

In `@packages/hdwallet-ledger-webusb/package.json`:
- Around line 30-31: The package.json currently contains a trailing comma after
the final property which makes the JSON invalid; open
packages/hdwallet-ledger-webusb/package.json, remove the extraneous trailing
comma at the end of the object (the comma following the last closing property)
so the file is valid JSON, then run a quick JSON parse or npm pack/ci to verify
no parse errors.

In `@packages/hdwallet-ledger/package.json`:
- Around line 48-49: The package.json contains a trailing comma after the final
closing brace which makes the JSON invalid; open
packages/hdwallet-ledger/package.json and remove the comma following the final
"}" so the file ends with a single closing brace and valid JSON (ensure no
trailing commas remain anywhere in the top-level object).

In `@packages/hdwallet-metamask-multichain/package.json`:
- Around line 27-31: The JSON file contains an extra trailing comma after the
"devDependencies" object which makes the package.json invalid; remove the comma
immediately following the closing brace of the "devDependencies" block (the
comma after "@types/lodash": "^4.14.168" } ) so the file is valid JSON and
package tooling can parse it correctly.

In `@packages/hdwallet-native-vault/package.json`:
- Around line 29-30: The package.json contains a trailing comma after the
devDependencies object which makes the JSON invalid; open the package.json,
locate the closing brace for "devDependencies" and remove the comma that follows
it so the file is valid JSON (ensure the final top-level object ends with just
"}" not "},").

In `@packages/hdwallet-native/package.json`:
- Around line 63-65: The package.json contains a trailing comma after the final
property ("msw": "^0.27.1") which makes the JSON invalid; open
packages/hdwallet-native/package.json and remove the trailing comma after the
last property so the file ends with a single closing brace/brace-pair (ensure
the final line is `  }` then `}` with no comma), then run a quick JSON lint or
npm/yarn command to validate the file.

In `@packages/hdwallet-phantom/package.json`:
- Around line 27-28: Remove the invalid trailing comma after the closing brace
of the devDependencies object in package.json; locate the devDependencies block
in packages/hdwallet-phantom/package.json and delete the comma following the `}`
so the JSON is valid and parses correctly.

In `@packages/hdwallet-portis/package.json`:
- Around line 29-30: The package.json contains a trailing comma after the final
object entry which makes the JSON invalid; open the package.json in the
hdwallet-portis package and remove the trailing comma at the end of the root
object so the file ends with "}" (no comma) to restore valid JSON and allow
package managers like yarn to parse it.

In `@packages/hdwallet-vultisig/package.json`:
- Around line 27-30: The package.json contains an invalid trailing comma after
the devDependencies object; remove the extra comma following the closing brace
of the "devDependencies" object so the JSON is valid (ensure the
"devDependencies" key and its object remain unchanged except for removing the
trailing comma).

In `@packages/hdwallet-walletconnect/package.json`:
- Around line 22-23: The package.json contains an invalid trailing comma after
the closing brace of the "dependencies" object; remove the extraneous comma
after that closing brace so the JSON is valid (ensure the "dependencies" object
ends with "}" and the overall JSON remains properly comma-separated between
top-level properties if any); verify the file parses (e.g., with a JSON linter)
after removing the trailing comma.

@NeOMakinG NeOMakinG merged commit 4408884 into master Jan 16, 2026
4 of 5 checks passed
@NeOMakinG NeOMakinG deleted the ton-chain branch January 16, 2026 22:03
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