@ton-community/ton-ledger 7.2.0 → 7.4.0-pre.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [7.3.0] - 2025-08-21
8
+
9
+ - New jettons
10
+ - Fixed `includeWalletOp`
11
+
7
12
  ## [7.2.0] - 2025-02-07
8
13
 
9
14
  - Added support for TON Ledger App 2.2.0 features, including:
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import Transport from "@ledgerhq/hw-transport";
3
4
  import { Address, Cell, SendMode, StateInit } from "@ton/core";
4
5
  export type KnownJetton = {
@@ -6,6 +7,12 @@ export type KnownJetton = {
6
7
  masterAddress: Address;
7
8
  };
8
9
  export declare const KNOWN_JETTONS: KnownJetton[];
10
+ export type ExtraCurrency = {
11
+ id: number;
12
+ symbol: string;
13
+ decimals: number;
14
+ };
15
+ export declare const KNOWN_EXTRA_CURRENCIES: ExtraCurrency[];
9
16
  export type TonPayloadFormat = {
10
17
  type: 'unsafe';
11
18
  message: Cell;
@@ -82,6 +89,22 @@ export type TonPayloadFormat = {
82
89
  type: 'token-bridge-pay-swap';
83
90
  queryId: bigint | null;
84
91
  swapId: Buffer;
92
+ } | {
93
+ type: 'tonwhales-pool-deposit';
94
+ queryId: bigint;
95
+ gasLimit: bigint;
96
+ } | {
97
+ type: 'tonwhales-pool-withdraw';
98
+ queryId: bigint;
99
+ gasLimit: bigint;
100
+ amount: bigint;
101
+ } | {
102
+ type: 'vesting-send-msg-comment';
103
+ queryId: bigint | null;
104
+ sendMode: number;
105
+ value: bigint;
106
+ destination: Address;
107
+ text: string;
85
108
  };
86
109
  export declare function parseMessage(cell: Cell, opts?: {
87
110
  disallowUnsafe?: boolean;
@@ -158,6 +181,10 @@ export declare class TonTransport {
158
181
  subwalletId?: number;
159
182
  includeWalletOp: boolean;
160
183
  };
184
+ extraCurrency?: {
185
+ index: number;
186
+ amount: bigint;
187
+ };
161
188
  }) => Promise<Cell>;
162
189
  getSettings(): Promise<{
163
190
  blindSigningEnabled: boolean;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TonTransport = exports.parseMessage = exports.KNOWN_JETTONS = void 0;
3
+ exports.TonTransport = exports.parseMessage = exports.KNOWN_EXTRA_CURRENCIES = exports.KNOWN_JETTONS = void 0;
4
4
  const core_1 = require("@ton/core");
5
5
  const crypto_1 = require("@ton/crypto");
6
6
  const teslabot_1 = require("teslabot");
@@ -44,6 +44,29 @@ exports.KNOWN_JETTONS = [
44
44
  symbol: 'STAKED',
45
45
  masterAddress: core_1.Address.parse('EQCqC6EhRJ_tpWngKxL6dV0k6DSnRUrs9GSVkLbfdCqsj6TE'),
46
46
  },
47
+ {
48
+ symbol: 'CATI',
49
+ masterAddress: core_1.Address.parse('EQD-cvR0Nz6XAyRBvbhz-abTrRC6sI5tvHvvpeQraV9UAAD7'),
50
+ },
51
+ {
52
+ symbol: 'DOGS',
53
+ masterAddress: core_1.Address.parse('EQCvxJy4eG8hyHBFsZ7eePxrRsUQSFE_jpptRAYBmcG_DOGS'),
54
+ },
55
+ {
56
+ symbol: 'X',
57
+ masterAddress: core_1.Address.parse('EQB4zZusHsbU2vVTPqjhlokIOoiZhEdCMT703CWEzhTOo__X'),
58
+ },
59
+ {
60
+ symbol: 'tgBTC',
61
+ masterAddress: core_1.Address.parse('EQBmjxpYsJ8yHEraYfTpLdejCekHMoKS2fOErP4lLHCf4SlU'),
62
+ },
63
+ ];
64
+ exports.KNOWN_EXTRA_CURRENCIES = [
65
+ {
66
+ id: 1,
67
+ symbol: 'tgBTC',
68
+ decimals: 8,
69
+ },
47
70
  ];
48
71
  const dnsWalletKey = Buffer.from([0xe8, 0xd4, 0x40, 0x50, 0x87, 0x3d, 0xba, 0x86, 0x5a, 0xa7, 0xc1, 0x70, 0xab, 0x4c, 0xce, 0x64,
49
72
  0xd9, 0x08, 0x39, 0xa3, 0x4d, 0xcf, 0xd6, 0xcf, 0x71, 0xd1, 0x4e, 0x02, 0x05, 0x44, 0x3b, 0x1b]);
@@ -336,6 +359,62 @@ function parseMessage(cell, opts) {
336
359
  swapId,
337
360
  };
338
361
  }
362
+ case 0x7bcd1fef: {
363
+ const queryId = s.loadUintBig(64);
364
+ if (queryId <= 0n) {
365
+ throw new Error('Incorrect query id: must be greater than 0');
366
+ }
367
+ const gasLimit = s.loadCoins();
368
+ s.endParse();
369
+ return {
370
+ type: 'tonwhales-pool-deposit',
371
+ queryId,
372
+ gasLimit,
373
+ };
374
+ }
375
+ case 0xda803efd: {
376
+ const queryId = s.loadUintBig(64);
377
+ if (queryId <= 0n) {
378
+ throw new Error('Incorrect query id: must be greater than 0');
379
+ }
380
+ const gasLimit = s.loadCoins();
381
+ const amount = s.loadCoins();
382
+ s.endParse();
383
+ return {
384
+ type: 'tonwhales-pool-withdraw',
385
+ queryId,
386
+ gasLimit,
387
+ amount,
388
+ };
389
+ }
390
+ case 0xa7733acd: {
391
+ const queryId = normalizeQueryId(s.loadUintBig(64));
392
+ const sendMode = s.loadUint(8);
393
+ const msgRefSlice = s.loadRef().beginParse();
394
+ s.endParse();
395
+ const msg = (0, core_1.loadMessageRelaxed)(msgRefSlice);
396
+ if (msg.info.type !== 'internal') {
397
+ throw new Error('Message is not internal');
398
+ }
399
+ const body = msg.body.beginParse();
400
+ const op = body.loadUint(32);
401
+ if (op !== 0) {
402
+ throw new Error('Message body is not a comment');
403
+ }
404
+ const text = body.loadStringTail();
405
+ if (text.length > 120) {
406
+ throw new Error('Comment must be at most 120 ASCII characters long');
407
+ }
408
+ body.endParse();
409
+ return {
410
+ type: 'vesting-send-msg-comment',
411
+ queryId,
412
+ sendMode,
413
+ value: msg.info.value.coins,
414
+ destination: msg.info.dest,
415
+ text,
416
+ };
417
+ }
339
418
  }
340
419
  throw new Error('Unknown op: ' + op);
341
420
  }
@@ -706,6 +785,92 @@ function convertPayload(input) {
706
785
  ]);
707
786
  break;
708
787
  }
788
+ case 'tonwhales-pool-deposit': {
789
+ hints = Buffer.concat([
790
+ (0, ledgerWriter_1.writeUint8)(1),
791
+ (0, ledgerWriter_1.writeUint32)(0x0B)
792
+ ]);
793
+ const cell = (0, core_1.beginCell)()
794
+ .storeUint(0x7bcd1fef, 32)
795
+ .storeUint(input.queryId, 64)
796
+ .storeCoins(input.gasLimit)
797
+ .endCell();
798
+ const buffer = Buffer.concat([
799
+ (0, ledgerWriter_1.writeUint64)(input.queryId),
800
+ (0, ledgerWriter_1.writeVarUInt)(input.gasLimit)
801
+ ]);
802
+ payload = cell;
803
+ hints = Buffer.concat([
804
+ hints,
805
+ (0, ledgerWriter_1.writeUint16)(buffer.length),
806
+ buffer
807
+ ]);
808
+ break;
809
+ }
810
+ case 'tonwhales-pool-withdraw': {
811
+ hints = Buffer.concat([
812
+ (0, ledgerWriter_1.writeUint8)(1),
813
+ (0, ledgerWriter_1.writeUint32)(0x0C)
814
+ ]);
815
+ const cell = (0, core_1.beginCell)()
816
+ .storeUint(0xda803efd, 32)
817
+ .storeUint(input.queryId, 64)
818
+ .storeCoins(input.gasLimit)
819
+ .storeCoins(input.amount)
820
+ .endCell();
821
+ const buffer = Buffer.concat([
822
+ (0, ledgerWriter_1.writeUint64)(input.queryId),
823
+ (0, ledgerWriter_1.writeVarUInt)(input.gasLimit),
824
+ (0, ledgerWriter_1.writeVarUInt)(input.amount)
825
+ ]);
826
+ payload = cell;
827
+ hints = Buffer.concat([
828
+ hints,
829
+ (0, ledgerWriter_1.writeUint16)(buffer.length),
830
+ buffer
831
+ ]);
832
+ break;
833
+ }
834
+ case 'vesting-send-msg-comment': {
835
+ hints = Buffer.concat([
836
+ (0, ledgerWriter_1.writeUint8)(1),
837
+ (0, ledgerWriter_1.writeUint32)(0x0D)
838
+ ]);
839
+ let builder = (0, core_1.beginCell)()
840
+ .storeUint(0xa7733acd, 32);
841
+ let buffer = Buffer.alloc(0);
842
+ if (input.queryId !== null) {
843
+ builder = builder.storeUint(input.queryId, 64);
844
+ buffer = Buffer.concat([buffer, (0, ledgerWriter_1.writeUint8)(1), (0, ledgerWriter_1.writeUint64)(input.queryId)]);
845
+ }
846
+ else {
847
+ builder = builder.storeUint(0, 64);
848
+ buffer = Buffer.concat([buffer, (0, ledgerWriter_1.writeUint8)(0)]);
849
+ }
850
+ builder = builder.storeUint(input.sendMode, 8);
851
+ buffer = Buffer.concat([buffer, (0, ledgerWriter_1.writeUint8)(input.sendMode)]);
852
+ const msg = (0, core_1.internal)({
853
+ to: input.destination,
854
+ value: input.value,
855
+ body: (0, core_1.beginCell)().storeUint(0, 32).storeStringTail(input.text).endCell(),
856
+ });
857
+ const msgRefBuilder = (0, core_1.beginCell)();
858
+ (0, core_1.storeMessageRelaxed)(msg)(msgRefBuilder);
859
+ builder = builder.storeRef(msgRefBuilder.endCell());
860
+ buffer = Buffer.concat([buffer, (0, ledgerWriter_1.writeAddress)(input.destination)]);
861
+ buffer = Buffer.concat([buffer, (0, ledgerWriter_1.writeVarUInt)(input.value)]);
862
+ if (input.text.length > 120) {
863
+ throw new Error('Comment must be at most 120 ASCII characters long');
864
+ }
865
+ buffer = Buffer.concat([buffer, (0, ledgerWriter_1.writeUint8)(Buffer.from(input.text).length), Buffer.from(input.text)]);
866
+ payload = builder.endCell();
867
+ hints = Buffer.concat([
868
+ hints,
869
+ (0, ledgerWriter_1.writeUint16)(buffer.length),
870
+ buffer
871
+ ]);
872
+ break;
873
+ }
709
874
  default: {
710
875
  throw new Error('Unknown payload type: ' + input.type);
711
876
  }
@@ -906,6 +1071,9 @@ class TonTransport {
906
1071
  signTransaction = async (path, transaction) => {
907
1072
  // Check path
908
1073
  validatePath(path);
1074
+ if (transaction.extraCurrency !== undefined && transaction.extraCurrency.index >= exports.KNOWN_EXTRA_CURRENCIES.length) {
1075
+ throw Error('Invalid extra currency index');
1076
+ }
909
1077
  //
910
1078
  // Fetch key
911
1079
  //
@@ -913,14 +1081,31 @@ class TonTransport {
913
1081
  //
914
1082
  // Create package
915
1083
  //
1084
+ const includeWalletOp = transaction.walletSpecifiers?.includeWalletOp ?? true;
1085
+ const subwalletId = transaction.walletSpecifiers?.subwalletId ?? DEFAULT_SUBWALLET_ID;
1086
+ const useTag1 = transaction.walletSpecifiers !== undefined || transaction.extraCurrency !== undefined;
916
1087
  let pkg = Buffer.concat([
917
- (0, ledgerWriter_1.writeUint8)(transaction.walletSpecifiers === undefined ? 0 : 1), // tag
1088
+ (0, ledgerWriter_1.writeUint8)(useTag1 ? 1 : 0), // tag
918
1089
  ]);
919
- if (transaction.walletSpecifiers !== undefined) {
1090
+ if (useTag1) {
1091
+ let flags = 0;
1092
+ if (includeWalletOp) {
1093
+ flags |= 1;
1094
+ }
1095
+ if (transaction.extraCurrency !== undefined) {
1096
+ flags |= 2;
1097
+ }
920
1098
  pkg = Buffer.concat([
921
1099
  pkg,
922
- (0, ledgerWriter_1.writeUint32)(transaction.walletSpecifiers.subwalletId ?? DEFAULT_SUBWALLET_ID),
923
- (0, ledgerWriter_1.writeUint8)(transaction.walletSpecifiers.includeWalletOp ? 1 : 0),
1100
+ (0, ledgerWriter_1.writeUint32)(subwalletId),
1101
+ (0, ledgerWriter_1.writeUint8)(flags),
1102
+ ]);
1103
+ }
1104
+ let ecBuf = Buffer.alloc(0);
1105
+ if (transaction.extraCurrency !== undefined) {
1106
+ ecBuf = Buffer.concat([
1107
+ (0, ledgerWriter_1.writeUint8)(transaction.extraCurrency.index),
1108
+ (0, ledgerWriter_1.writeVarUInt)(transaction.extraCurrency.amount),
924
1109
  ]);
925
1110
  }
926
1111
  pkg = Buffer.concat([
@@ -928,6 +1113,7 @@ class TonTransport {
928
1113
  (0, ledgerWriter_1.writeUint32)(transaction.seqno),
929
1114
  (0, ledgerWriter_1.writeUint32)(transaction.timeout),
930
1115
  (0, ledgerWriter_1.writeVarUInt)(transaction.amount),
1116
+ ecBuf,
931
1117
  (0, ledgerWriter_1.writeAddress)(transaction.to),
932
1118
  (0, ledgerWriter_1.writeUint8)(transaction.bounce ? 1 : 0),
933
1119
  (0, ledgerWriter_1.writeUint8)(transaction.sendMode),
@@ -992,8 +1178,20 @@ class TonTransport {
992
1178
  .storeBit(false)
993
1179
  .storeAddress(null)
994
1180
  .storeAddress(transaction.to)
995
- .storeCoins(transaction.amount)
996
- .storeBit(false)
1181
+ .storeCoins(transaction.amount);
1182
+ if (transaction.extraCurrency !== undefined) {
1183
+ orderBuilder = orderBuilder
1184
+ .storeBit(true)
1185
+ .storeRef((0, core_1.beginCell)()
1186
+ .storeUint(0b10, 2)
1187
+ .storeUint(32, 6)
1188
+ .storeUint(exports.KNOWN_EXTRA_CURRENCIES[transaction.extraCurrency.index].id, 32)
1189
+ .storeVarUint(transaction.extraCurrency.amount, 5));
1190
+ }
1191
+ else {
1192
+ orderBuilder = orderBuilder.storeBit(false);
1193
+ }
1194
+ orderBuilder = orderBuilder
997
1195
  .storeCoins(0)
998
1196
  .storeCoins(0)
999
1197
  .storeUint(0, 64)
@@ -1021,10 +1219,10 @@ class TonTransport {
1021
1219
  }
1022
1220
  // Transfer message
1023
1221
  let transferB = (0, core_1.beginCell)()
1024
- .storeUint(transaction.walletSpecifiers?.subwalletId ?? DEFAULT_SUBWALLET_ID, 32)
1222
+ .storeUint(subwalletId, 32)
1025
1223
  .storeUint(transaction.timeout, 32)
1026
1224
  .storeUint(transaction.seqno, 32);
1027
- if (transaction.walletSpecifiers?.includeWalletOp ?? true) {
1225
+ if (includeWalletOp) {
1028
1226
  transferB = transferB.storeUint(0, 8);
1029
1227
  }
1030
1228
  let transfer = transferB.storeUint(transaction.sendMode, 8)
package/dist/index.d.ts CHANGED
@@ -1 +1 @@
1
- export { TonPayloadFormat, TonTransport, SignDataRequest, parseMessage, KNOWN_JETTONS } from './TonTransport';
1
+ export { TonPayloadFormat, TonTransport, SignDataRequest, parseMessage, KnownJetton, KNOWN_JETTONS, ExtraCurrency, KNOWN_EXTRA_CURRENCIES } from './TonTransport';
package/dist/index.js CHANGED
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.KNOWN_JETTONS = exports.parseMessage = exports.TonTransport = void 0;
3
+ exports.KNOWN_EXTRA_CURRENCIES = exports.KNOWN_JETTONS = exports.parseMessage = exports.TonTransport = void 0;
4
4
  var TonTransport_1 = require("./TonTransport");
5
5
  Object.defineProperty(exports, "TonTransport", { enumerable: true, get: function () { return TonTransport_1.TonTransport; } });
6
6
  Object.defineProperty(exports, "parseMessage", { enumerable: true, get: function () { return TonTransport_1.parseMessage; } });
7
7
  Object.defineProperty(exports, "KNOWN_JETTONS", { enumerable: true, get: function () { return TonTransport_1.KNOWN_JETTONS; } });
8
+ Object.defineProperty(exports, "KNOWN_EXTRA_CURRENCIES", { enumerable: true, get: function () { return TonTransport_1.KNOWN_EXTRA_CURRENCIES; } });
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import { Cell } from '@ton/core';
3
4
  export declare function getInit(publicKey: Buffer, subwalletId: number, isV3R2: boolean): {
4
5
  code: Cell;
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import { Address, Cell } from '@ton/core';
3
4
  export declare function writeUint32(value: number): Buffer;
4
5
  export declare function writeUint16(value: number): Buffer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ton-community/ton-ledger",
3
- "version": "7.2.0",
3
+ "version": "7.4.0-pre.0",
4
4
  "repository": "https://github.com/ton-community/ton-ledger-ts",
5
5
  "author": "Steve Korshakov <steve@korshakov.com>",
6
6
  "license": "MIT",
@@ -18,11 +18,10 @@
18
18
  "@ton/core": ">=0.52.2"
19
19
  },
20
20
  "devDependencies": {
21
- "@ledgerhq/hw-transport-node-hid": "^6.27.15",
22
21
  "@release-it/keep-a-changelog": "^3.1.0",
23
22
  "@ton/core": "^0.52.2",
24
23
  "@types/jest": "^29.5.2",
25
- "@types/node": "^20.2.5",
24
+ "@types/node": "^22.18.1",
26
25
  "jest": "^29.5.0",
27
26
  "release-it": "^15.11.0",
28
27
  "ts-jest": "^29.1.0",
@@ -30,7 +29,7 @@
30
29
  "typescript": "^4.9.5"
31
30
  },
32
31
  "dependencies": {
33
- "@ledgerhq/hw-transport": "^6.28.4",
32
+ "@ledgerhq/hw-transport": "^6.31.4",
34
33
  "@ton/crypto": "^3.2.0",
35
34
  "teslabot": "^1.5.0"
36
35
  },
@@ -47,5 +46,6 @@
47
46
  "filename": "CHANGELOG.md"
48
47
  }
49
48
  }
50
- }
49
+ },
50
+ "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
51
51
  }