@ton-community/ton-ledger 4.0.0 → 4.0.1

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,12 @@ 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
+ ## [4.0.1] - 2023-06-16
8
+
9
+ ### Fixed
10
+
11
+ - Fixed the address flags communication
12
+
7
13
  ## [4.0.0] - 2023-06-09
8
14
 
9
15
  ### Added
@@ -19,6 +19,19 @@ function chunks(buf, n) {
19
19
  }
20
20
  return cs;
21
21
  }
22
+ function processAddressFlags(opts) {
23
+ const bounceable = opts?.bounceable ?? true;
24
+ const testOnly = opts?.testOnly ?? false;
25
+ const chain = opts?.chain ?? 0;
26
+ let flags = 0x00;
27
+ if (testOnly) {
28
+ flags |= 0x01;
29
+ }
30
+ if (chain === -1) {
31
+ flags |= 0x02;
32
+ }
33
+ return { bounceable, testOnly, chain, flags };
34
+ }
22
35
  class TonTransport {
23
36
  transport;
24
37
  #lock = new teslabot_1.AsyncLock();
@@ -57,27 +70,7 @@ class TonTransport {
57
70
  // Check path
58
71
  validatePath(path);
59
72
  // Resolve flags
60
- let bounceable = true;
61
- let chain = 0;
62
- let test = false;
63
- let flags = 0x00;
64
- if (opts && opts.bounceable !== undefined && !opts.bounceable) {
65
- flags |= 0x01;
66
- bounceable = false;
67
- }
68
- if (opts && opts.testOnly) {
69
- flags |= 0x02;
70
- test = true;
71
- }
72
- if (opts && opts.chain !== undefined) {
73
- if (opts.chain !== 0 && opts.chain !== -1) {
74
- throw Error('Invalid chain');
75
- }
76
- chain = opts.chain;
77
- if (opts.chain === -1) {
78
- flags |= 0x04;
79
- }
80
- }
73
+ const { bounceable, testOnly, chain } = processAddressFlags(opts);
81
74
  // Get public key
82
75
  let response = await this.#doRequest(INS_ADDRESS, 0x00, 0x00, pathElementsToBuffer(path.map((v) => v + 0x80000000)));
83
76
  if (response.length !== 32) {
@@ -86,33 +79,13 @@ class TonTransport {
86
79
  // Contract
87
80
  const contract = (0, getInit_1.getInit)(chain, response);
88
81
  const address = (0, ton_core_1.contractAddress)(chain, contract);
89
- return { address: address.toString({ bounceable: bounceable, testOnly: test }), publicKey: response };
82
+ return { address: address.toString({ bounceable, testOnly }), publicKey: response };
90
83
  }
91
84
  async validateAddress(path, opts) {
92
85
  // Check path
93
86
  validatePath(path);
94
87
  // Resolve flags
95
- let bounceable = true;
96
- let chain = 0;
97
- let test = false;
98
- let flags = 0x00;
99
- if (opts && opts.bounceable !== undefined && !opts.bounceable) {
100
- flags |= 0x01;
101
- bounceable = false;
102
- }
103
- if (opts && opts.testOnly) {
104
- flags |= 0x02;
105
- test = true;
106
- }
107
- if (opts && opts.chain !== undefined) {
108
- if (opts.chain !== 0 && opts.chain !== -1) {
109
- throw Error('Invalid chain');
110
- }
111
- chain = opts.chain;
112
- if (opts.chain === -1) {
113
- flags |= 0x04;
114
- }
115
- }
88
+ const { bounceable, testOnly, chain, flags } = processAddressFlags(opts);
116
89
  // Get public key
117
90
  let response = await this.#doRequest(INS_ADDRESS, 0x01, flags, pathElementsToBuffer(path.map((v) => v + 0x80000000)));
118
91
  if (response.length !== 32) {
@@ -121,34 +94,14 @@ class TonTransport {
121
94
  // Contract
122
95
  const contract = (0, getInit_1.getInit)(chain, response);
123
96
  const address = (0, ton_core_1.contractAddress)(chain, contract);
124
- return { address: address.toString({ bounceable: bounceable, testOnly: test }), publicKey: response };
97
+ return { address: address.toString({ bounceable, testOnly }), publicKey: response };
125
98
  }
126
99
  async getAddressProof(path, params, opts) {
127
100
  // Check path
128
101
  validatePath(path);
129
102
  let publicKey = (await this.getAddress(path)).publicKey;
130
103
  // Resolve flags
131
- let bounceable = true;
132
- let chain = 0;
133
- let test = false;
134
- let flags = 0x00;
135
- if (opts && opts.bounceable !== undefined && !opts.bounceable) {
136
- flags |= 0x01;
137
- bounceable = false;
138
- }
139
- if (opts && opts.testOnly) {
140
- flags |= 0x02;
141
- test = true;
142
- }
143
- if (opts && opts.chain !== undefined) {
144
- if (opts.chain !== 0 && opts.chain !== -1) {
145
- throw Error('Invalid chain');
146
- }
147
- chain = opts.chain;
148
- if (opts.chain === -1) {
149
- flags |= 0x04;
150
- }
151
- }
104
+ const { flags } = processAddressFlags(opts);
152
105
  const domainBuf = Buffer.from(params.domain, 'utf-8');
153
106
  const reqBuf = Buffer.concat([
154
107
  pathElementsToBuffer(path.map((v) => v + 0x80000000)),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ton-community/ton-ledger",
3
- "version": "4.0.0",
3
+ "version": "4.0.1",
4
4
  "repository": "https://github.com/ton-community/ton-ledger-ts",
5
5
  "author": "Steve Korshakov <steve@korshakov.com>",
6
6
  "license": "MIT",