Skip to content

Commit af43fb4

Browse files
committed
refactor(sdk-coin-ton): add support to use custom sub wallet id
Ticket: WIN-7823
1 parent e39c339 commit af43fb4

File tree

6 files changed

+26
-48
lines changed

6 files changed

+26
-48
lines changed

modules/sdk-coin-ton/CHANGELOG.md

Lines changed: 5 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,88 +5,48 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
55

66
## [3.10.3](https://github.com/BitGo/BitGoJS/compare/@bitgo/sdk-coin-ton@3.10.2...@bitgo/sdk-coin-ton@3.10.3) (2025-11-06)
77

8-
98
### Bug Fixes
109

11-
* **sdk-coin-ton:** build tx using tx builder factory ([ef94b98](https://github.com/BitGo/BitGoJS/commit/ef94b98976789ce0b967933d2e0d1ed7ea4f4b37))
12-
13-
14-
15-
10+
- **sdk-coin-ton:** build tx using tx builder factory ([ef94b98](https://github.com/BitGo/BitGoJS/commit/ef94b98976789ce0b967933d2e0d1ed7ea4f4b37))
1611

1712
## [3.10.2](https://github.com/BitGo/BitGoJS/compare/@bitgo/sdk-coin-ton@3.10.1...@bitgo/sdk-coin-ton@3.10.2) (2025-10-31)
1813

1914
**Note:** Version bump only for package @bitgo/sdk-coin-ton
2015

21-
22-
23-
24-
2516
## [3.10.1](https://github.com/BitGo/BitGoJS/compare/@bitgo/sdk-coin-ton@3.10.0...@bitgo/sdk-coin-ton@3.10.1) (2025-10-29)
2617

2718
**Note:** Version bump only for package @bitgo/sdk-coin-ton
2819

29-
30-
31-
32-
3320
# [3.10.0](https://github.com/BitGo/BitGoJS/compare/@bitgo/sdk-coin-ton@3.9.7...@bitgo/sdk-coin-ton@3.10.0) (2025-10-24)
3421

35-
3622
### Features
3723

38-
* **sdk-coin-ton:** add wallet contract v3 transaction support ([b5653fb](https://github.com/BitGo/BitGoJS/commit/b5653fb7678d5b7b418bba682dc501d4f495b848))
39-
40-
41-
42-
24+
- **sdk-coin-ton:** add wallet contract v3 transaction support ([b5653fb](https://github.com/BitGo/BitGoJS/commit/b5653fb7678d5b7b418bba682dc501d4f495b848))
4325

4426
## [3.9.7](https://github.com/BitGo/BitGoJS/compare/@bitgo/sdk-coin-ton@3.9.6...@bitgo/sdk-coin-ton@3.9.7) (2025-10-21)
4527

4628
**Note:** Version bump only for package @bitgo/sdk-coin-ton
4729

48-
49-
50-
51-
5230
## [3.9.6](https://github.com/BitGo/BitGoJS/compare/@bitgo/sdk-coin-ton@3.9.5...@bitgo/sdk-coin-ton@3.9.6) (2025-10-16)
5331

5432
**Note:** Version bump only for package @bitgo/sdk-coin-ton
5533

56-
57-
58-
59-
6034
## [3.9.5](https://github.com/BitGo/BitGoJS/compare/@bitgo/sdk-coin-ton@3.9.4...@bitgo/sdk-coin-ton@3.9.5) (2025-10-13)
6135

6236
**Note:** Version bump only for package @bitgo/sdk-coin-ton
6337

64-
65-
66-
67-
6838
## [3.9.4](https://github.com/BitGo/BitGoJS/compare/@bitgo/sdk-coin-ton@3.9.3...@bitgo/sdk-coin-ton@3.9.4) (2025-10-09)
6939

70-
7140
### Bug Fixes
7241

73-
* run check-fmt on code files only ([9745196](https://github.com/BitGo/BitGoJS/commit/9745196b02b9678c740d290a4638ceb153a8fd75))
74-
75-
76-
77-
42+
- run check-fmt on code files only ([9745196](https://github.com/BitGo/BitGoJS/commit/9745196b02b9678c740d290a4638ceb153a8fd75))
7843

7944
## [3.9.3](https://github.com/BitGo/BitGoJS/compare/@bitgo/sdk-coin-ton@3.9.2...@bitgo/sdk-coin-ton@3.9.3) (2025-10-08)
8045

81-
8246
### Bug Fixes
8347

84-
* add explicit 'files' in package json ([3b00373](https://github.com/BitGo/BitGoJS/commit/3b0037396f6ac16bb9380bd85bf37f2b133068f4))
85-
* **sdk-coin-ton:** parse token transactions correctly ([4fd4c0a](https://github.com/BitGo/BitGoJS/commit/4fd4c0a769e46bfe5d3a187e1a9c0ecfc72bc5e2))
86-
87-
88-
89-
48+
- add explicit 'files' in package json ([3b00373](https://github.com/BitGo/BitGoJS/commit/3b0037396f6ac16bb9380bd85bf37f2b133068f4))
49+
- **sdk-coin-ton:** parse token transactions correctly ([4fd4c0a](https://github.com/BitGo/BitGoJS/commit/4fd4c0a769e46bfe5d3a187e1a9c0ecfc72bc5e2))
9050

9151
## [3.9.2](https://github.com/BitGo/BitGoJS/compare/@bitgo/sdk-coin-ton@3.9.1...@bitgo/sdk-coin-ton@3.9.2) (2025-10-02)
9252

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export const VESTING_CONTRACT_WALLET_ID = 268;
12
export const WALLET_ID = 698983191;
23
export const JETTON_TRANSFER_OPCODE = 0x0f8a7ea5;
34
export const WITHDRAW_OPCODE = '00001000';

modules/sdk-coin-ton/src/lib/iface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface TxData {
1414
seqno: number;
1515
expirationTime: number;
1616
publicKey: string;
17+
sub_wallet_id: number;
1718
signature: string;
1819
bounceable: boolean;
1920
}

modules/sdk-coin-ton/src/lib/transaction.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Cell } from 'tonweb/dist/types/boc/cell';
55
import { BaseKey, BaseTransaction, Entry, Recipient, TransactionRecipient, TransactionType } from '@bitgo/sdk-core';
66
import { BaseCoin as CoinConfig } from '@bitgo/statics';
77
import { TransactionExplanation, TxData } from './iface';
8-
import { WITHDRAW_OPCODE, WALLET_ID, JETTON_TRANSFER_OPCODE } from './constants';
8+
import { WITHDRAW_OPCODE, WALLET_ID, JETTON_TRANSFER_OPCODE, VESTING_CONTRACT_WALLET_ID } from './constants';
99

1010
export class Transaction extends BaseTransaction {
1111
public recipient: Recipient;
@@ -19,6 +19,7 @@ export class Transaction extends BaseTransaction {
1919
sender: string;
2020
publicKey: string;
2121
isV3ContractMessage: boolean;
22+
sub_wallet_id: number;
2223
protected unsignedMessage: string;
2324
protected finalMessage: string;
2425

@@ -52,6 +53,7 @@ export class Transaction extends BaseTransaction {
5253
amount: this.recipient.amount,
5354
withdrawAmount: this.withdrawAmount,
5455
seqno: this.seqno,
56+
sub_wallet_id: this.sub_wallet_id,
5557
expirationTime: this.expireTime,
5658
publicKey: this.publicKey,
5759
signature: this._signatures[0],
@@ -72,7 +74,14 @@ export class Transaction extends BaseTransaction {
7274
}
7375

7476
async build(): Promise<void> {
75-
const signingMessage = this.createSigningMessage(WALLET_ID, this.seqno, this.expireTime);
77+
if (!this.sub_wallet_id) {
78+
if (this.isV3ContractMessage) {
79+
this.sub_wallet_id = VESTING_CONTRACT_WALLET_ID;
80+
} else {
81+
this.sub_wallet_id = WALLET_ID;
82+
}
83+
}
84+
const signingMessage = this.createSigningMessage(this.sub_wallet_id, this.seqno, this.expireTime);
7685
const sendMode = 3; // default sendMode
7786
signingMessage.bits.writeUint8(sendMode);
7887
const outMsg = this.createOutMsg(this.recipient.address, this.recipient.amount, this.message);
@@ -189,6 +198,7 @@ export class Transaction extends BaseTransaction {
189198
this.message = parsed.payload;
190199
this._signatures.push(parsed.signature);
191200
this.bounceable = parsed.bounce;
201+
this.sub_wallet_id = parsed.walletId;
192202
} catch (e) {
193203
throw new Error('invalid raw transaction');
194204
}
@@ -263,7 +273,7 @@ export class Transaction extends BaseTransaction {
263273
// signing message
264274

265275
const walletId = slice.loadUint(32).toNumber();
266-
if (walletId !== WALLET_ID) throw new Error('invalid walletId');
276+
if (walletId !== WALLET_ID && walletId !== VESTING_CONTRACT_WALLET_ID) throw new Error('invalid walletId');
267277

268278
const expireAt = slice.loadUint(32).toNumber();
269279

modules/sdk-coin-ton/src/lib/transactionBuilder.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,4 +184,8 @@ export abstract class TransactionBuilder extends BaseTransactionBuilder {
184184
this.transaction.isV3ContractMessage = bool;
185185
return this;
186186
}
187+
subWalletId(id: number): TransactionBuilder {
188+
this.transaction.sub_wallet_id = id;
189+
return this;
190+
}
187191
}

modules/sdk-coin-ton/test/unit/transferBuilder.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import TonWeb from 'tonweb';
33
import { TransactionType } from '@bitgo/sdk-core';
44
import { coins } from '@bitgo/statics';
55
import { TransactionBuilderFactory, KeyPair } from '../../src';
6+
import { WALLET_ID } from '../../src/lib/constants';
67
import * as testData from '../resources/ton';
78
import * as utils from '../../src/lib/utils';
89

@@ -258,5 +259,6 @@ describe('Ton Transfer Builder', () => {
258259
jsonTx.seqno.should.equal(3);
259260
jsonTx.expirationTime.should.equal(1761215512);
260261
jsonTx.bounceable.should.equal(true);
262+
jsonTx.sub_wallet_id.should.equal(WALLET_ID);
261263
});
262264
});

0 commit comments

Comments
 (0)