@ukeyfe/hardware-transport 1.1.13
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/.eslintrc +24 -0
- package/README.md +29 -0
- package/__tests__/build-receive.test.js +117 -0
- package/__tests__/decode-features.test.js +72 -0
- package/__tests__/encode-decode-basic.test.js +272 -0
- package/__tests__/encode-decode.test.js +532 -0
- package/__tests__/messages.test.js +86 -0
- package/dist/constants.d.ts +6 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/index.d.ts +5203 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +942 -0
- package/dist/serialization/index.d.ts +6 -0
- package/dist/serialization/index.d.ts.map +1 -0
- package/dist/serialization/protobuf/decode.d.ts +6 -0
- package/dist/serialization/protobuf/decode.d.ts.map +1 -0
- package/dist/serialization/protobuf/encode.d.ts +5 -0
- package/dist/serialization/protobuf/encode.d.ts.map +1 -0
- package/dist/serialization/protobuf/index.d.ts +4 -0
- package/dist/serialization/protobuf/index.d.ts.map +1 -0
- package/dist/serialization/protobuf/messages.d.ts +11 -0
- package/dist/serialization/protobuf/messages.d.ts.map +1 -0
- package/dist/serialization/protocol/decode.d.ts +11 -0
- package/dist/serialization/protocol/decode.d.ts.map +1 -0
- package/dist/serialization/protocol/encode.d.ts +11 -0
- package/dist/serialization/protocol/encode.d.ts.map +1 -0
- package/dist/serialization/protocol/index.d.ts +3 -0
- package/dist/serialization/protocol/index.d.ts.map +1 -0
- package/dist/serialization/receive.d.ts +8 -0
- package/dist/serialization/receive.d.ts.map +1 -0
- package/dist/serialization/send.d.ts +7 -0
- package/dist/serialization/send.d.ts.map +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/messages.d.ts +3762 -0
- package/dist/types/messages.d.ts.map +1 -0
- package/dist/types/transport.d.ts +62 -0
- package/dist/types/transport.d.ts.map +1 -0
- package/dist/utils/highlevel-checks.d.ts +10 -0
- package/dist/utils/highlevel-checks.d.ts.map +1 -0
- package/dist/utils/logBlockCommand.d.ts +2 -0
- package/dist/utils/logBlockCommand.d.ts.map +1 -0
- package/dist/utils/protobuf.d.ts +2 -0
- package/dist/utils/protobuf.d.ts.map +1 -0
- package/jest.config.js +7 -0
- package/package.json +31 -0
- package/protocol.md +21 -0
- package/scripts/protobuf-build.sh +58 -0
- package/scripts/protobuf-patches/TxAck.js +44 -0
- package/scripts/protobuf-patches/TxInputType.js +49 -0
- package/scripts/protobuf-patches/TxOutputType.js +50 -0
- package/scripts/protobuf-patches/index.js +274 -0
- package/scripts/protobuf-types.js +283 -0
- package/src/constants.ts +8 -0
- package/src/index.ts +41 -0
- package/src/serialization/index.ts +8 -0
- package/src/serialization/protobuf/decode.ts +95 -0
- package/src/serialization/protobuf/encode.ts +79 -0
- package/src/serialization/protobuf/index.ts +3 -0
- package/src/serialization/protobuf/messages.ts +37 -0
- package/src/serialization/protocol/decode.ts +48 -0
- package/src/serialization/protocol/encode.ts +59 -0
- package/src/serialization/protocol/index.ts +2 -0
- package/src/serialization/receive.ts +18 -0
- package/src/serialization/send.ts +56 -0
- package/src/types/index.ts +2 -0
- package/src/types/messages.ts +4864 -0
- package/src/types/transport.ts +71 -0
- package/src/utils/highlevel-checks.ts +88 -0
- package/src/utils/logBlockCommand.ts +1 -0
- package/src/utils/protobuf.ts +24 -0
- package/tsconfig.json +11 -0
|
@@ -0,0 +1,532 @@
|
|
|
1
|
+
const ProtoBuf = require('protobufjs/light');
|
|
2
|
+
|
|
3
|
+
const { encode } = require('../src/serialization/protobuf/encode');
|
|
4
|
+
const { decode } = require('../src/serialization/protobuf/decode');
|
|
5
|
+
|
|
6
|
+
const HDNodeType = {
|
|
7
|
+
fields: {
|
|
8
|
+
depth: {
|
|
9
|
+
rule: 'required',
|
|
10
|
+
type: 'uint32',
|
|
11
|
+
id: 1,
|
|
12
|
+
},
|
|
13
|
+
fingerprint: {
|
|
14
|
+
rule: 'required',
|
|
15
|
+
type: 'uint32',
|
|
16
|
+
id: 2,
|
|
17
|
+
},
|
|
18
|
+
child_num: {
|
|
19
|
+
rule: 'required',
|
|
20
|
+
type: 'uint32',
|
|
21
|
+
id: 3,
|
|
22
|
+
},
|
|
23
|
+
chain_code: {
|
|
24
|
+
rule: 'required',
|
|
25
|
+
type: 'bytes',
|
|
26
|
+
id: 4,
|
|
27
|
+
},
|
|
28
|
+
private_key: {
|
|
29
|
+
type: 'bytes',
|
|
30
|
+
id: 5,
|
|
31
|
+
},
|
|
32
|
+
public_key: {
|
|
33
|
+
rule: 'required',
|
|
34
|
+
type: 'bytes',
|
|
35
|
+
id: 6,
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const MultisigRedeemScriptType = {
|
|
41
|
+
fields: {
|
|
42
|
+
pubkeys: {
|
|
43
|
+
rule: 'repeated',
|
|
44
|
+
type: 'HDNodePathType',
|
|
45
|
+
id: 1,
|
|
46
|
+
},
|
|
47
|
+
signatures: {
|
|
48
|
+
rule: 'repeated',
|
|
49
|
+
type: 'bytes',
|
|
50
|
+
id: 2,
|
|
51
|
+
},
|
|
52
|
+
m: {
|
|
53
|
+
rule: 'required',
|
|
54
|
+
type: 'uint32',
|
|
55
|
+
id: 3,
|
|
56
|
+
},
|
|
57
|
+
nodes: {
|
|
58
|
+
rule: 'repeated',
|
|
59
|
+
type: 'HDNodeType',
|
|
60
|
+
id: 4,
|
|
61
|
+
},
|
|
62
|
+
address_n: {
|
|
63
|
+
rule: 'repeated',
|
|
64
|
+
type: 'uint32',
|
|
65
|
+
id: 5,
|
|
66
|
+
options: {
|
|
67
|
+
packed: false,
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
nested: {
|
|
72
|
+
HDNodePathType: {
|
|
73
|
+
fields: {
|
|
74
|
+
node: {
|
|
75
|
+
rule: 'required',
|
|
76
|
+
type: 'HDNodeType',
|
|
77
|
+
id: 1,
|
|
78
|
+
},
|
|
79
|
+
address_n: {
|
|
80
|
+
rule: 'repeated',
|
|
81
|
+
type: 'uint32',
|
|
82
|
+
id: 2,
|
|
83
|
+
options: {
|
|
84
|
+
packed: false,
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const fixtures = [
|
|
93
|
+
{
|
|
94
|
+
name: 'Initialize',
|
|
95
|
+
message: {
|
|
96
|
+
Initialize: {
|
|
97
|
+
fields: {
|
|
98
|
+
session_id: {
|
|
99
|
+
type: 'bytes',
|
|
100
|
+
id: 0,
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
in: {},
|
|
106
|
+
encoded: '',
|
|
107
|
+
out: { session_id: null },
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
name: 'Address',
|
|
111
|
+
message: {
|
|
112
|
+
Address: {
|
|
113
|
+
fields: {
|
|
114
|
+
address: {
|
|
115
|
+
rule: 'required',
|
|
116
|
+
type: 'string',
|
|
117
|
+
id: 1,
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
in: { address: 'abcd' },
|
|
123
|
+
encoded: '0a0461626364',
|
|
124
|
+
out: { address: 'abcd' },
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
name: 'GetAddress',
|
|
128
|
+
message: {
|
|
129
|
+
GetAddress: {
|
|
130
|
+
fields: {
|
|
131
|
+
address_n: {
|
|
132
|
+
rule: 'repeated',
|
|
133
|
+
type: 'uint32',
|
|
134
|
+
id: 1,
|
|
135
|
+
options: {
|
|
136
|
+
packed: false,
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
coin_name: {
|
|
140
|
+
type: 'string',
|
|
141
|
+
id: 2,
|
|
142
|
+
options: {
|
|
143
|
+
default: 'Bitcoin',
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
show_display: {
|
|
147
|
+
type: 'bool',
|
|
148
|
+
id: 3,
|
|
149
|
+
},
|
|
150
|
+
multisig: {
|
|
151
|
+
type: 'MultisigRedeemScriptType',
|
|
152
|
+
id: 4,
|
|
153
|
+
},
|
|
154
|
+
ignore_xpub_magic: {
|
|
155
|
+
type: 'bool',
|
|
156
|
+
id: 6,
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
MultisigRedeemScriptType,
|
|
161
|
+
HDNodeType,
|
|
162
|
+
},
|
|
163
|
+
in: {
|
|
164
|
+
address_n: [1],
|
|
165
|
+
coin_name: 'btc',
|
|
166
|
+
show_display: null,
|
|
167
|
+
ignore_xpub_magic: null,
|
|
168
|
+
multisig: {
|
|
169
|
+
pubkeys: [
|
|
170
|
+
{
|
|
171
|
+
node: {
|
|
172
|
+
depth: 1,
|
|
173
|
+
fingerprint: 1,
|
|
174
|
+
child_num: 1,
|
|
175
|
+
chain_code:
|
|
176
|
+
'851fc9542342321af63ecbba7d3ece545f2a42bad01ba32cff5535b18e54b6d3106e10b6a4525993d185a1443d9a125186960e028eabfdd8d76cf70a3a7e3100',
|
|
177
|
+
private_key:
|
|
178
|
+
'851fc9542342321af63ecbba7d3ece545f2a42bad01ba32cff5535b18e54b6d3106e10b6a4525993d185a1443d9a125186960e028eabfdd8d76cf70a3a7e3100',
|
|
179
|
+
public_key:
|
|
180
|
+
'851fc9542342321af63ecbba7d3ece545f2a42bad01ba32cff5535b18e54b6d3106e10b6a4525993d185a1443d9a125186960e028eabfdd8d76cf70a3a7e3100',
|
|
181
|
+
},
|
|
182
|
+
address_n: [1],
|
|
183
|
+
},
|
|
184
|
+
],
|
|
185
|
+
signatures: [
|
|
186
|
+
'851fc9542342321af63ecbba7d3ece545f2a42bad01ba32cff5535b18e54b6d3106e10b6a4525993d185a1443d9a125186960e028eabfdd8d76cf70a3a7e3100',
|
|
187
|
+
],
|
|
188
|
+
m: 1,
|
|
189
|
+
nodes: [
|
|
190
|
+
{
|
|
191
|
+
depth: 1,
|
|
192
|
+
fingerprint: 1,
|
|
193
|
+
child_num: 1,
|
|
194
|
+
chain_code:
|
|
195
|
+
'851fc9542342321af63ecbba7d3ece545f2a42bad01ba32cff5535b18e54b6d3106e10b6a4525993d185a1443d9a125186960e028eabfdd8d76cf70a3a7e3100',
|
|
196
|
+
private_key:
|
|
197
|
+
'851fc9542342321af63ecbba7d3ece545f2a42bad01ba32cff5535b18e54b6d3106e10b6a4525993d185a1443d9a125186960e028eabfdd8d76cf70a3a7e3100',
|
|
198
|
+
public_key:
|
|
199
|
+
'851fc9542342321af63ecbba7d3ece545f2a42bad01ba32cff5535b18e54b6d3106e10b6a4525993d185a1443d9a125186960e028eabfdd8d76cf70a3a7e3100',
|
|
200
|
+
},
|
|
201
|
+
],
|
|
202
|
+
address_n: [1],
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
encoded:
|
|
206
|
+
'0801120362746322e9030ad1010acc010801100118012240851fc9542342321af63ecbba7d3ece545f2a42bad01ba32cff5535b18e54b6d3106e10b6a4525993d185a1443d9a125186960e028eabfdd8d76cf70a3a7e31002a40851fc9542342321af63ecbba7d3ece545f2a42bad01ba32cff5535b18e54b6d3106e10b6a4525993d185a1443d9a125186960e028eabfdd8d76cf70a3a7e31003240851fc9542342321af63ecbba7d3ece545f2a42bad01ba32cff5535b18e54b6d3106e10b6a4525993d185a1443d9a125186960e028eabfdd8d76cf70a3a7e310010011240851fc9542342321af63ecbba7d3ece545f2a42bad01ba32cff5535b18e54b6d3106e10b6a4525993d185a1443d9a125186960e028eabfdd8d76cf70a3a7e3100180122cc010801100118012240851fc9542342321af63ecbba7d3ece545f2a42bad01ba32cff5535b18e54b6d3106e10b6a4525993d185a1443d9a125186960e028eabfdd8d76cf70a3a7e31002a40851fc9542342321af63ecbba7d3ece545f2a42bad01ba32cff5535b18e54b6d3106e10b6a4525993d185a1443d9a125186960e028eabfdd8d76cf70a3a7e31003240851fc9542342321af63ecbba7d3ece545f2a42bad01ba32cff5535b18e54b6d3106e10b6a4525993d185a1443d9a125186960e028eabfdd8d76cf70a3a7e31002801',
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
name: 'TxRequest',
|
|
210
|
+
message: {
|
|
211
|
+
TxRequest: {
|
|
212
|
+
fields: {
|
|
213
|
+
request_type: {
|
|
214
|
+
type: 'RequestType',
|
|
215
|
+
id: 1,
|
|
216
|
+
},
|
|
217
|
+
details: {
|
|
218
|
+
type: 'TxRequestDetailsType',
|
|
219
|
+
id: 2,
|
|
220
|
+
},
|
|
221
|
+
serialized: {
|
|
222
|
+
type: 'TxRequestSerializedType',
|
|
223
|
+
id: 3,
|
|
224
|
+
},
|
|
225
|
+
},
|
|
226
|
+
nested: {
|
|
227
|
+
RequestType: {
|
|
228
|
+
values: {
|
|
229
|
+
TXINPUT: 0,
|
|
230
|
+
TXOUTPUT: 1,
|
|
231
|
+
TXMETA: 2,
|
|
232
|
+
TXFINISHED: 3,
|
|
233
|
+
TXEXTRADATA: 4,
|
|
234
|
+
TXORIGINPUT: 5,
|
|
235
|
+
TXORIGOUTPUT: 6,
|
|
236
|
+
},
|
|
237
|
+
},
|
|
238
|
+
TxRequestDetailsType: {
|
|
239
|
+
fields: {
|
|
240
|
+
request_index: {
|
|
241
|
+
type: 'uint32',
|
|
242
|
+
id: 1,
|
|
243
|
+
},
|
|
244
|
+
tx_hash: {
|
|
245
|
+
type: 'bytes',
|
|
246
|
+
id: 2,
|
|
247
|
+
},
|
|
248
|
+
extra_data_len: {
|
|
249
|
+
type: 'uint32',
|
|
250
|
+
id: 3,
|
|
251
|
+
},
|
|
252
|
+
extra_data_offset: {
|
|
253
|
+
type: 'uint32',
|
|
254
|
+
id: 4,
|
|
255
|
+
},
|
|
256
|
+
},
|
|
257
|
+
},
|
|
258
|
+
TxRequestSerializedType: {
|
|
259
|
+
fields: {
|
|
260
|
+
signature_index: {
|
|
261
|
+
type: 'uint32',
|
|
262
|
+
id: 1,
|
|
263
|
+
},
|
|
264
|
+
signature: {
|
|
265
|
+
type: 'bytes',
|
|
266
|
+
id: 2,
|
|
267
|
+
},
|
|
268
|
+
serialized_tx: {
|
|
269
|
+
type: 'bytes',
|
|
270
|
+
id: 3,
|
|
271
|
+
},
|
|
272
|
+
},
|
|
273
|
+
},
|
|
274
|
+
},
|
|
275
|
+
},
|
|
276
|
+
},
|
|
277
|
+
in: {
|
|
278
|
+
request_type: 0,
|
|
279
|
+
details: { request_index: 0 },
|
|
280
|
+
serialized: {
|
|
281
|
+
serialized_tx:
|
|
282
|
+
'851fc9542342321af63ecbba7d3ece545f2a42bad01ba32cff5535b18e54b6d3106e10b6a4525993d185a1443d9a125186960e028eabfdd8d76cf70a3a7e3100',
|
|
283
|
+
},
|
|
284
|
+
},
|
|
285
|
+
encoded:
|
|
286
|
+
'0800120208001a421a40851fc9542342321af63ecbba7d3ece545f2a42bad01ba32cff5535b18e54b6d3106e10b6a4525993d185a1443d9a125186960e028eabfdd8d76cf70a3a7e3100',
|
|
287
|
+
out: {
|
|
288
|
+
request_type: 'TXINPUT',
|
|
289
|
+
details: {
|
|
290
|
+
request_index: 0,
|
|
291
|
+
tx_hash: null,
|
|
292
|
+
extra_data_len: null,
|
|
293
|
+
extra_data_offset: null,
|
|
294
|
+
},
|
|
295
|
+
serialized: {
|
|
296
|
+
serialized_tx:
|
|
297
|
+
'851fc9542342321af63ecbba7d3ece545f2a42bad01ba32cff5535b18e54b6d3106e10b6a4525993d185a1443d9a125186960e028eabfdd8d76cf70a3a7e3100',
|
|
298
|
+
signature: null,
|
|
299
|
+
signature_index: null,
|
|
300
|
+
},
|
|
301
|
+
},
|
|
302
|
+
},
|
|
303
|
+
{
|
|
304
|
+
// taken from TrezorConnect fixtures signTransactionsMultisig.js. There is interesting part signatures: ['', '', ''];
|
|
305
|
+
name: 'MultisigRedeemScriptType',
|
|
306
|
+
message: {
|
|
307
|
+
HDNodeType,
|
|
308
|
+
MultisigRedeemScriptType,
|
|
309
|
+
},
|
|
310
|
+
in: {
|
|
311
|
+
pubkeys: [
|
|
312
|
+
{
|
|
313
|
+
node: {
|
|
314
|
+
depth: 4,
|
|
315
|
+
child_num: 2147483648,
|
|
316
|
+
fingerprint: 2559962404,
|
|
317
|
+
public_key: '02d598ec0f8f418c80859b690e8ee731e2bf7c8e2233d7fa722249bc3f27a65151',
|
|
318
|
+
chain_code: 'fd5fd24c06088bce57f3d817df206d0891adf5a77f5391bdc12793ef1917460e',
|
|
319
|
+
},
|
|
320
|
+
address_n: [0, 0],
|
|
321
|
+
},
|
|
322
|
+
{
|
|
323
|
+
node: {
|
|
324
|
+
depth: 4,
|
|
325
|
+
child_num: 2147483648,
|
|
326
|
+
fingerprint: 3563901430,
|
|
327
|
+
public_key: '03e2a1f110b6e42de5bcf7a15881c66e2455fb62137e55678692a5f690fc8de10f',
|
|
328
|
+
chain_code: 'ca9268e9c323cfceb971ee96c418a91b2f3415dfbb0dc1d11dd8fcdff73a9ab9',
|
|
329
|
+
},
|
|
330
|
+
address_n: [0, 0],
|
|
331
|
+
},
|
|
332
|
+
{
|
|
333
|
+
node: {
|
|
334
|
+
depth: 4,
|
|
335
|
+
child_num: 2147483648,
|
|
336
|
+
fingerprint: 598174955,
|
|
337
|
+
public_key: '032b9bdd9510f75f4d32631ffe11a56b11d332c8c0f0e0801b686f6eec806e7a2f',
|
|
338
|
+
chain_code: '267ba0b69f9b0c9aa6add7d7162ff5ac675aa420c8d7a468778a6630d5c82f60',
|
|
339
|
+
},
|
|
340
|
+
address_n: [0, 0],
|
|
341
|
+
},
|
|
342
|
+
],
|
|
343
|
+
signatures: ['', '', ''],
|
|
344
|
+
m: 2,
|
|
345
|
+
},
|
|
346
|
+
encoded:
|
|
347
|
+
'0a590a53080410a4dad7c4091880808080082220fd5fd24c06088bce57f3d817df206d0891adf5a77f5391bdc12793ef1917460e322102d598ec0f8f418c80859b690e8ee731e2bf7c8e2233d7fa722249bc3f27a65151100010000a590a53080410f6a3b3a30d1880808080082220ca9268e9c323cfceb971ee96c418a91b2f3415dfbb0dc1d11dd8fcdff73a9ab9322103e2a1f110b6e42de5bcf7a15881c66e2455fb62137e55678692a5f690fc8de10f100010000a590a53080410ebd99d9d021880808080082220267ba0b69f9b0c9aa6add7d7162ff5ac675aa420c8d7a468778a6630d5c82f603221032b9bdd9510f75f4d32631ffe11a56b11d332c8c0f0e0801b686f6eec806e7a2f100010001200120012001802',
|
|
348
|
+
out: {
|
|
349
|
+
// additional field. todo: not sure if shouldn't be omitted
|
|
350
|
+
address_n: [],
|
|
351
|
+
// additional field. todo: not sure if shouldn't be omitted
|
|
352
|
+
nodes: [],
|
|
353
|
+
pubkeys: [
|
|
354
|
+
{
|
|
355
|
+
node: {
|
|
356
|
+
depth: 4,
|
|
357
|
+
child_num: 2147483648,
|
|
358
|
+
fingerprint: 2559962404,
|
|
359
|
+
public_key: '02d598ec0f8f418c80859b690e8ee731e2bf7c8e2233d7fa722249bc3f27a65151',
|
|
360
|
+
chain_code: 'fd5fd24c06088bce57f3d817df206d0891adf5a77f5391bdc12793ef1917460e',
|
|
361
|
+
// additional field to maintain backwards compatibility
|
|
362
|
+
private_key: null,
|
|
363
|
+
},
|
|
364
|
+
address_n: [0, 0],
|
|
365
|
+
},
|
|
366
|
+
{
|
|
367
|
+
node: {
|
|
368
|
+
depth: 4,
|
|
369
|
+
child_num: 2147483648,
|
|
370
|
+
fingerprint: 3563901430,
|
|
371
|
+
public_key: '03e2a1f110b6e42de5bcf7a15881c66e2455fb62137e55678692a5f690fc8de10f',
|
|
372
|
+
chain_code: 'ca9268e9c323cfceb971ee96c418a91b2f3415dfbb0dc1d11dd8fcdff73a9ab9',
|
|
373
|
+
// additional field to maintain backwards compatibility
|
|
374
|
+
private_key: null,
|
|
375
|
+
},
|
|
376
|
+
address_n: [0, 0],
|
|
377
|
+
},
|
|
378
|
+
{
|
|
379
|
+
node: {
|
|
380
|
+
depth: 4,
|
|
381
|
+
child_num: 2147483648,
|
|
382
|
+
fingerprint: 598174955,
|
|
383
|
+
public_key: '032b9bdd9510f75f4d32631ffe11a56b11d332c8c0f0e0801b686f6eec806e7a2f',
|
|
384
|
+
chain_code: '267ba0b69f9b0c9aa6add7d7162ff5ac675aa420c8d7a468778a6630d5c82f60',
|
|
385
|
+
// additional field to maintain backwards compatibility
|
|
386
|
+
private_key: null,
|
|
387
|
+
},
|
|
388
|
+
address_n: [0, 0],
|
|
389
|
+
},
|
|
390
|
+
],
|
|
391
|
+
// point of interest.
|
|
392
|
+
// signatures are repeated bytes. if they sent from TrezorConnect as empty strings, encoding them as bytes makes trezor not accept this message
|
|
393
|
+
signatures: ['', '', ''],
|
|
394
|
+
m: 2,
|
|
395
|
+
},
|
|
396
|
+
},
|
|
397
|
+
{
|
|
398
|
+
name: 'Features',
|
|
399
|
+
message: {
|
|
400
|
+
SafetyCheckLevel: {
|
|
401
|
+
values: {
|
|
402
|
+
Strict: 0,
|
|
403
|
+
PromptAlways: 1,
|
|
404
|
+
PromptTemporarily: 2,
|
|
405
|
+
},
|
|
406
|
+
},
|
|
407
|
+
Features: {
|
|
408
|
+
fields: {
|
|
409
|
+
capabilities: {
|
|
410
|
+
rule: 'repeated',
|
|
411
|
+
type: 'Capability',
|
|
412
|
+
id: 30,
|
|
413
|
+
options: {
|
|
414
|
+
packed: false,
|
|
415
|
+
},
|
|
416
|
+
},
|
|
417
|
+
safety_checks: {
|
|
418
|
+
type: 'SafetyCheckLevel',
|
|
419
|
+
id: 37,
|
|
420
|
+
},
|
|
421
|
+
},
|
|
422
|
+
nested: {
|
|
423
|
+
Capability: {
|
|
424
|
+
options: {
|
|
425
|
+
'(has_bitcoin_only_values)': true,
|
|
426
|
+
},
|
|
427
|
+
values: {
|
|
428
|
+
Capability_Bitcoin: 1,
|
|
429
|
+
Capability_Bitcoin_like: 2,
|
|
430
|
+
},
|
|
431
|
+
},
|
|
432
|
+
},
|
|
433
|
+
},
|
|
434
|
+
},
|
|
435
|
+
in: { capabilities: [1], safety_checks: 'Strict' },
|
|
436
|
+
encoded: 'f00101a80200',
|
|
437
|
+
out: { capabilities: [1], safety_checks: 'Strict' },
|
|
438
|
+
},
|
|
439
|
+
{
|
|
440
|
+
name: 'CardanoTxWitnessRequest',
|
|
441
|
+
message: {
|
|
442
|
+
CardanoTxWitnessRequest: {
|
|
443
|
+
fields: {
|
|
444
|
+
path: {
|
|
445
|
+
rule: 'repeated',
|
|
446
|
+
type: 'uint32',
|
|
447
|
+
id: 1,
|
|
448
|
+
options: {
|
|
449
|
+
packed: false,
|
|
450
|
+
},
|
|
451
|
+
},
|
|
452
|
+
},
|
|
453
|
+
},
|
|
454
|
+
},
|
|
455
|
+
in: {
|
|
456
|
+
path: [2147485500, 2147485463, 2147483648, 2, 0],
|
|
457
|
+
},
|
|
458
|
+
encoded: '08bc8e80800808978e80800808808080800808020800',
|
|
459
|
+
out: {
|
|
460
|
+
path: [2147485500, 2147485463, 2147483648, 2, 0],
|
|
461
|
+
},
|
|
462
|
+
},
|
|
463
|
+
{
|
|
464
|
+
name: 'TxAckPrevExtraData',
|
|
465
|
+
message: {
|
|
466
|
+
TxAckPrevExtraData: {
|
|
467
|
+
options: {
|
|
468
|
+
'(wire_type)': 22,
|
|
469
|
+
'(include_in_bitcoin_only)': true,
|
|
470
|
+
},
|
|
471
|
+
fields: {
|
|
472
|
+
tx: {
|
|
473
|
+
rule: 'required',
|
|
474
|
+
type: 'TxAckPrevExtraDataWrapper',
|
|
475
|
+
id: 1,
|
|
476
|
+
},
|
|
477
|
+
},
|
|
478
|
+
nested: {
|
|
479
|
+
TxAckPrevExtraDataWrapper: {
|
|
480
|
+
fields: {
|
|
481
|
+
extra_data_chunk: {
|
|
482
|
+
rule: 'required',
|
|
483
|
+
type: 'bytes',
|
|
484
|
+
id: 8,
|
|
485
|
+
},
|
|
486
|
+
},
|
|
487
|
+
},
|
|
488
|
+
},
|
|
489
|
+
},
|
|
490
|
+
},
|
|
491
|
+
in: {
|
|
492
|
+
tx: {
|
|
493
|
+
extra_data_chunk:
|
|
494
|
+
'851fc9542342321af63ecbba7d3ece545f2a42bad01ba32cff5535b18e54b6d3106e10b6a4525993d185a1443d9a125186960e028eabfdd8d76cf70a3a7e3100',
|
|
495
|
+
},
|
|
496
|
+
},
|
|
497
|
+
encoded:
|
|
498
|
+
'0a424240851fc9542342321af63ecbba7d3ece545f2a42bad01ba32cff5535b18e54b6d3106e10b6a4525993d185a1443d9a125186960e028eabfdd8d76cf70a3a7e3100',
|
|
499
|
+
out: {
|
|
500
|
+
tx: {
|
|
501
|
+
extra_data_chunk:
|
|
502
|
+
'851fc9542342321af63ecbba7d3ece545f2a42bad01ba32cff5535b18e54b6d3106e10b6a4525993d185a1443d9a125186960e028eabfdd8d76cf70a3a7e3100',
|
|
503
|
+
},
|
|
504
|
+
},
|
|
505
|
+
},
|
|
506
|
+
];
|
|
507
|
+
|
|
508
|
+
describe('Real messages', () => {
|
|
509
|
+
fixtures.forEach(f => {
|
|
510
|
+
describe(f.name, () => {
|
|
511
|
+
const Messages = ProtoBuf.Root.fromJSON({
|
|
512
|
+
nested: { messages: { nested: { ...f.message } } },
|
|
513
|
+
});
|
|
514
|
+
const Message = Messages.lookup(`messages.${f.name}`);
|
|
515
|
+
|
|
516
|
+
test('encode and decode', () => {
|
|
517
|
+
// serialize
|
|
518
|
+
const encoded = encode(Message, f.in);
|
|
519
|
+
expect(encoded.toString('hex')).toEqual(f.encoded);
|
|
520
|
+
// deserialize
|
|
521
|
+
const decoded = decode(Message, encoded);
|
|
522
|
+
expect(decoded).toEqual(f.out ? f.out : f.in);
|
|
523
|
+
});
|
|
524
|
+
});
|
|
525
|
+
});
|
|
526
|
+
|
|
527
|
+
test('without Messages object', () => {
|
|
528
|
+
expect(() => {
|
|
529
|
+
encode(null, {});
|
|
530
|
+
}).toThrowError();
|
|
531
|
+
});
|
|
532
|
+
});
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
const {
|
|
2
|
+
createMessageFromName,
|
|
3
|
+
createMessageFromType,
|
|
4
|
+
parseConfigure,
|
|
5
|
+
} = require('../src/serialization/protobuf/messages');
|
|
6
|
+
// const json = require('./data/messages.json');
|
|
7
|
+
|
|
8
|
+
const json = {
|
|
9
|
+
nested: {
|
|
10
|
+
Initialize: {
|
|
11
|
+
fields: {
|
|
12
|
+
session_id: {
|
|
13
|
+
type: 'bytes',
|
|
14
|
+
id: 1,
|
|
15
|
+
},
|
|
16
|
+
_skip_passphrase: {
|
|
17
|
+
type: 'bool',
|
|
18
|
+
id: 2,
|
|
19
|
+
options: {
|
|
20
|
+
deprecated: true,
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
derive_cardano: {
|
|
24
|
+
type: 'bool',
|
|
25
|
+
id: 3,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
TxAckInput: {
|
|
30
|
+
options: {
|
|
31
|
+
'(wire_type)': 22,
|
|
32
|
+
},
|
|
33
|
+
fields: {
|
|
34
|
+
tx: {
|
|
35
|
+
rule: 'required',
|
|
36
|
+
type: 'TxAckInputWrapper',
|
|
37
|
+
id: 1,
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
nested: {
|
|
41
|
+
TxAckInputWrapper: {
|
|
42
|
+
fields: {
|
|
43
|
+
input: {
|
|
44
|
+
rule: 'required',
|
|
45
|
+
type: 'TxInput',
|
|
46
|
+
id: 2,
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
MessageType: {
|
|
53
|
+
values: {
|
|
54
|
+
MessageType_Initialize: 0,
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
describe('messages', () => {
|
|
61
|
+
test('createMessageFromName (common case)', () => {
|
|
62
|
+
const messages = parseConfigure(json);
|
|
63
|
+
const name = 'Initialize';
|
|
64
|
+
|
|
65
|
+
expect(() => createMessageFromName(messages, name)).not.toThrow();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test('createMessageFromType (common case)', () => {
|
|
69
|
+
const messages = parseConfigure(json);
|
|
70
|
+
expect(() => createMessageFromType(messages, 0)).not.toThrow();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test('createMessageFromName (wire_type case)', () => {
|
|
74
|
+
const messages = parseConfigure(json);
|
|
75
|
+
const name = 'TxAckInput';
|
|
76
|
+
|
|
77
|
+
expect(() => createMessageFromName(messages, name)).not.toThrow();
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test('[compatibility]: descriptors as string', () => {
|
|
81
|
+
const messages = parseConfigure(JSON.stringify(json));
|
|
82
|
+
const name = 'TxAckInput';
|
|
83
|
+
|
|
84
|
+
expect(() => createMessageFromName(messages, name)).not.toThrow();
|
|
85
|
+
});
|
|
86
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,KAAS,CAAC;AACvC,eAAO,MAAM,mBAAmB,KAAO,CAAC;AACxC,eAAO,MAAM,WAAW,QAAgB,CAAC;AACzC,eAAO,MAAM,WAAW,KAAK,CAAC;AAI9B,eAAO,MAAM,kBAAkB,IAAI,CAAC"}
|