@ledgerhq/hw-app-str 6.29.0-nightly.3 → 8.0.0-nightly.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/tests/Str.test.ts CHANGED
@@ -3,53 +3,358 @@ import {
3
3
  RecordStore,
4
4
  } from "@ledgerhq/hw-transport-mocker";
5
5
  import Str from "../src/Str";
6
+ import { StellarHashSigningNotEnabledError, StellarDataParsingFailedError, StellarUserRefusedError, StellarDataTooLargeError } from "../src/errors";
7
+ import { TransportStatusError } from "@ledgerhq/errors";
6
8
 
7
- test("getAppConfiguration", async () => {
9
+ test("getAppConfiguration (hash signing disabled)", async () => {
8
10
  const transport = await openTransportReplayer(
9
11
  RecordStore.fromString(`
10
12
  => e006000000
11
- <= 000300019000
13
+ <= 00050401061a9000
12
14
  `)
13
15
  );
14
16
  const str = new Str(transport);
15
17
  const result = await str.getAppConfiguration();
16
- expect(result).toEqual({ multiOpsEnabled: false, version: "3.0.1" });
18
+ expect(result).toEqual({ hashSigningEnabled: false, maxDataSize: 1562, version: "5.4.1" });
17
19
  });
18
20
 
19
- test("getPublicKey", async () => {
21
+ test("getAppConfiguration (hash signing enabled)", async () => {
20
22
  const transport = await openTransportReplayer(
21
23
  RecordStore.fromString(`
22
- => e002010117038000002c8000009480000000766961206c756d696e61
23
- <= 7691d85048acc4ed085d9061ce0948bbdf7de6a92b790aaf241d31b7dcaa423881b9f7cb3bd2fad4f0fdab9da1407e8e85f702fa58584fba3104e4549b85ca8046d73a4010870bc4765eff7e0bafcfe91390c4475ba3fcc598750758ed770e0f9000
24
+ => e006000000
25
+ <= 01050401061a9000
26
+ `)
27
+ );
28
+ const str = new Str(transport);
29
+ const result = await str.getAppConfiguration();
30
+ expect(result).toEqual({ hashSigningEnabled: true, maxDataSize: 1562, version: "5.4.1" });
31
+ });
32
+
33
+ test("getAppConfiguration (old version app < 5.4.1)", async () => {
34
+ const transport = await openTransportReplayer(
35
+ RecordStore.fromString(`
36
+ => e006000000
37
+ <= 000504019000
38
+ `)
39
+ );
40
+ const str = new Str(transport);
41
+ const result = await str.getAppConfiguration();
42
+ expect(result).toStrictEqual({ hashSigningEnabled: false, maxDataSize: undefined, version: "5.4.1" });
43
+ });
44
+
45
+ test("getPublicKey (without confirm)", async () => {
46
+ const transport = await openTransportReplayer(
47
+ RecordStore.fromString(`
48
+ => e00200000d038000002c8000009480000000
49
+ <= 9a222500cf47b03d05edec04ed3294cece1de727ccadb401f47d6b4b230e81a09000
50
+ `)
51
+ );
52
+ const str = new Str(transport);
53
+ const { rawPublicKey } = await str.getPublicKey("44'/148'/0'", false);
54
+ expect(rawPublicKey.toString("hex")).toEqual(
55
+ "9a222500cf47b03d05edec04ed3294cece1de727ccadb401f47d6b4b230e81a0"
56
+ );
57
+ });
58
+
59
+ test("getPublicKey (with confirm)", async () => {
60
+ const transport = await openTransportReplayer(
61
+ RecordStore.fromString(`
62
+ => e00200010d038000002c8000009480000000
63
+ <= 9a222500cf47b03d05edec04ed3294cece1de727ccadb401f47d6b4b230e81a09000
24
64
  `)
25
65
  );
26
66
  const str = new Str(transport);
27
- const { publicKey, raw } = await str.getPublicKey("44'/148'/0'", true, true);
28
- expect(publicKey).toEqual(
29
- "GB3JDWCQJCWMJ3IILWIGDTQJJC5567PGVEVXSCVPEQOTDN64VJBDQBYX"
67
+ const { rawPublicKey } = await str.getPublicKey("44'/148'/0'", true);
68
+ expect(rawPublicKey.toString("hex")).toEqual(
69
+ "9a222500cf47b03d05edec04ed3294cece1de727ccadb401f47d6b4b230e81a0"
30
70
  );
31
- expect(raw.toString("hex")).toEqual(
32
- "7691d85048acc4ed085d9061ce0948bbdf7de6a92b790aaf241d31b7dcaa4238"
71
+ });
72
+
73
+ test("getPublicKey (with confirm and rejected)", async () => {
74
+ const transport = await openTransportReplayer(
75
+ RecordStore.fromString(`
76
+ => e00200010d038000002c8000009480000000
77
+ <= 6985
78
+ `)
33
79
  );
80
+ const str = new Str(transport);
81
+ await expect(str.getPublicKey("44'/148'/0'", true)).rejects.toThrow(StellarUserRefusedError);
34
82
  });
35
83
 
36
- test("signTransaction", async () => {
84
+ test("signHash (hash signing enabled)", async () => {
37
85
  const transport = await openTransportReplayer(
38
86
  RecordStore.fromString(`
39
- => e004008096038000002c80000094800000007ac33997544e3175d266bd022439b22cdb16508c01163f26e5cb2a3e1045a979000000020000000020da998b75e42b1f7f85d075c127f5b246df12ad96f010bcf7f76f72b16e57130000006400c5b4a5000000190000000000000000000000010000000000000001000000009541f02746240c1e9f3843d28e56f0a583ecd27502fb0f4a27d4d0922f
87
+ => e00800002d038000002c8000009480000000a85c933d37847689825acbdfeb50e66d791814abf03b9be4bd6450abb6c99616
88
+ <= bd4ddd948dd1b27d92672d968eba50b8822eacebf67142f77eda5c5ee9c569c048c90b074a677470984bb203417e911d5b1d74270c2a82772cb80893fca1d70b9000
89
+ `)
90
+ );
91
+ const str = new Str(transport);
92
+ const hash = Buffer.from("a85c933d37847689825acbdfeb50e66d791814abf03b9be4bd6450abb6c99616", "hex");
93
+ const { signature } = await str.signHash("44'/148'/0'", hash);
94
+ const result = signature.toString("hex");
95
+ expect(result).toEqual(
96
+ "bd4ddd948dd1b27d92672d968eba50b8822eacebf67142f77eda5c5ee9c569c048c90b074a677470984bb203417e911d5b1d74270c2a82772cb80893fca1d70b"
97
+ );
98
+ })
99
+
100
+ test("signHash (hash signing disabled)", async () => {
101
+ const transport = await openTransportReplayer(
102
+ RecordStore.fromString(`
103
+ => e00800002d038000002c8000009480000000a85c933d37847689825acbdfeb50e66d791814abf03b9be4bd6450abb6c99616
104
+ <= 6c66
105
+ `)
106
+ );
107
+ const str = new Str(transport);
108
+ const hash = Buffer.from("a85c933d37847689825acbdfeb50e66d791814abf03b9be4bd6450abb6c99616", "hex");
109
+ await expect(str.signHash("44'/148'/0'", hash)).rejects.toThrow(StellarHashSigningNotEnabledError);
110
+ })
111
+
112
+ test("signHash (rejected)", async () => {
113
+ const transport = await openTransportReplayer(
114
+ RecordStore.fromString(`
115
+ => e00800002d038000002c8000009480000000a85c933d37847689825acbdfeb50e66d791814abf03b9be4bd6450abb6c99616
116
+ <= 6985
117
+ `)
118
+ );
119
+ const str = new Str(transport);
120
+ const hash = Buffer.from("a85c933d37847689825acbdfeb50e66d791814abf03b9be4bd6450abb6c99616", "hex");
121
+ await expect(str.signHash("44'/148'/0'", hash)).rejects.toThrow(StellarUserRefusedError);
122
+ })
123
+
124
+ test("signTransaction (size exceeds APDU_MAX_PAYLOAD)", async () => {
125
+ const transport = await openTransportReplayer(
126
+ RecordStore.fromString(`
127
+ => e0040080ff038000002c80000094800000007ac33997544e3175d266bd022439b22cdb16508c01163f26e5cb2a3e1045a9790000000200000000e93388bbfd2fbd11806dd0bd59cea9079e7cc70ce7b1e154f114cdfe4e466ecd000071d7002d9fed000000010000000000000000000000010000000100000000e93388bbfd2fbd11806dd0bd59cea9079e7cc70ce7b1e154f114cdfe4e466ecd00000018000000020000024c0061736d0100000001150460027e7e017e60037e7e7e017e6000017e600000021904016c01300000016c01310000016c015f0001016c013800000305040203030305030100100619037f01418080c0000b7f00418080c0000b7f00418080
128
+ <= 9000
129
+ => e0048080ffc0000b073505066d656d6f7279020009696e6372656d656e740004015f00070a5f5f646174615f656e6403010b5f5f686561705f6261736503020aa70104920102017f017e41002100024002400240428ebad0af86d43942021080808080004201520d00428ebad0af86d4394202108180808000220142ff01834204520d012001422088a721000b200041016a2200450d01428ebad0af86d4392000ad422086420484220142021082808080001a4284808080a0064284808080c00c1083808080001a20010f0b00000b108580808000000b0900108680808000000b040000000b02000b00730e636f6e74726163747370656376300000000000000040496e
130
+ <= 9000
131
+ => e0048080ff6372656d656e7420696e6372656d656e747320616e20696e7465726e616c20636f756e7465722c20616e642072657475726e73207468652076616c75652e00000009696e6372656d656e74000000000000000000000100000004001e11636f6e7472616374656e766d657461763000000000000000140000003900730e636f6e74726163746d65746176300000000000000005727376657200000000000006312e37332e3000000000000000000008727373646b7665720000003332302e302e302d72633223303939323431336639623035653562666231663837326263653939653839643931323962326536310000000000000000010000000000000001
40
132
  <= 9000
41
- => e004800013e064a200000000000000000098968000000000
42
- <= 79e6da561676d16f17e91ad0dbbe917e3da0fffe660aa9f277669385960b0aec8dcf002b7305b329cc02f2eabd2f20320dee4828b412ed2850b9771ffb23920d9000
133
+ => e00480003c0000000713e16858bde4ab50a006dbf07172288f3ec19d8640d1a853016c60c15c2511170000000000186636000002b000000000000000000000000c
134
+ <= 83968afc83b45d0672f5b5259a7bab68ee030f6ffda0c2f3fd550e3b5dd40b3a6bee1f246e760523ab6bd434f9e11f237ffd16bc8f18bb58a59eb94abe1a5a0c9000
135
+ `)
136
+ );
137
+ const str = new Str(transport);
138
+ const transaction = Buffer.from(
139
+ "7ac33997544e3175d266bd022439b22cdb16508c01163f26e5cb2a3e1045a9790000000200000000e93388bbfd2fbd11806dd0bd59cea9079e7cc70ce7b1e154f114cdfe4e466ecd000071d7002d9fed000000010000000000000000000000010000000100000000e93388bbfd2fbd11806dd0bd59cea9079e7cc70ce7b1e154f114cdfe4e466ecd00000018000000020000024c0061736d0100000001150460027e7e017e60037e7e7e017e6000017e600000021904016c01300000016c01310000016c015f0001016c013800000305040203030305030100100619037f01418080c0000b7f00418080c0000b7f00418080c0000b073505066d656d6f7279020009696e6372656d656e740004015f00070a5f5f646174615f656e6403010b5f5f686561705f6261736503020aa70104920102017f017e41002100024002400240428ebad0af86d43942021080808080004201520d00428ebad0af86d4394202108180808000220142ff01834204520d012001422088a721000b200041016a2200450d01428ebad0af86d4392000ad422086420484220142021082808080001a4284808080a0064284808080c00c1083808080001a20010f0b00000b108580808000000b0900108680808000000b040000000b02000b00730e636f6e74726163747370656376300000000000000040496e6372656d656e7420696e6372656d656e747320616e20696e7465726e616c20636f756e7465722c20616e642072657475726e73207468652076616c75652e00000009696e6372656d656e74000000000000000000000100000004001e11636f6e7472616374656e766d657461763000000000000000140000003900730e636f6e74726163746d65746176300000000000000005727376657200000000000006312e37332e3000000000000000000008727373646b7665720000003332302e302e302d726332233039393234313366396230356535626662316638373262636539396538396439313239623265363100000000000000000100000000000000010000000713e16858bde4ab50a006dbf07172288f3ec19d8640d1a853016c60c15c2511170000000000186636000002b000000000000000000000000c",
140
+ "hex"
141
+ );
142
+ const { signature } = await str.signTransaction("44'/148'/0'", transaction);
143
+ const result = signature.toString("hex");
144
+ expect(result).toEqual(
145
+ "83968afc83b45d0672f5b5259a7bab68ee030f6ffda0c2f3fd550e3b5dd40b3a6bee1f246e760523ab6bd434f9e11f237ffd16bc8f18bb58a59eb94abe1a5a0c"
146
+ );
147
+ });
148
+
149
+ test("signTransaction (size does not exceed APDU_MAX_PAYLOAD)", async () => {
150
+ const transport = await openTransportReplayer(
151
+ RecordStore.fromString(`
152
+ => e0040000ff038000002c80000094800000007ac33997544e3175d266bd022439b22cdb16508c01163f26e5cb2a3e1045a9790000000200000000e93388bbfd2fbd11806dd0bd59cea9079e7cc70ce7b1e154f114cdfe4e466ecd000071d7002d9fed000000010000000000000000000000010000000100000000e93388bbfd2fbd11806dd0bd59cea9079e7cc70ce7b1e154f114cdfe4e466ecd00000018000000020000024c0061736d0100000001150460027e7e017e60037e7e7e017e6000017e600000021904016c01300000016c01310000016c015f0001016c013800000305040203030305030100100619037f01418080c0000b7f00418080c0000b7f00418080
153
+ <= f30f5d707a6dbde681f9604832391295719130790578ecaca0b1d37a68923b15714b36f4507e56aff2d0e3256ed5af496a6b021896e13dca00a8283e426860089000
43
154
  `)
44
155
  );
45
156
  const str = new Str(transport);
46
157
  const transaction = Buffer.from(
47
- "7ac33997544e3175d266bd022439b22cdb16508c01163f26e5cb2a3e1045a979000000020000000020da998b75e42b1f7f85d075c127f5b246df12ad96f010bcf7f76f72b16e57130000006400c5b4a5000000190000000000000000000000010000000000000001000000009541f02746240c1e9f3843d28e56f0a583ecd27502fb0f4a27d4d0922fe064a200000000000000000098968000000000",
158
+ "7ac33997544e3175d266bd022439b22cdb16508c01163f26e5cb2a3e1045a9790000000200000000e93388bbfd2fbd11806dd0bd59cea9079e7cc70ce7b1e154f114cdfe4e466ecd000071d7002d9fed000000010000000000000000000000010000000100000000e93388bbfd2fbd11806dd0bd59cea9079e7cc70ce7b1e154f114cdfe4e466ecd00000018000000020000024c0061736d0100000001150460027e7e017e60037e7e7e017e6000017e600000021904016c01300000016c01310000016c015f0001016c013800000305040203030305030100100619037f01418080c0000b7f00418080c0000b7f00418080",
48
159
  "hex"
49
160
  );
50
161
  const { signature } = await str.signTransaction("44'/148'/0'", transaction);
51
162
  const result = signature.toString("hex");
52
163
  expect(result).toEqual(
53
- "79e6da561676d16f17e91ad0dbbe917e3da0fffe660aa9f277669385960b0aec8dcf002b7305b329cc02f2eabd2f20320dee4828b412ed2850b9771ffb23920d"
164
+ "f30f5d707a6dbde681f9604832391295719130790578ecaca0b1d37a68923b15714b36f4507e56aff2d0e3256ed5af496a6b021896e13dca00a8283e42686008"
165
+ );
166
+ });
167
+
168
+ test("signTransaction (size too long)", async () => {
169
+ const transport = await openTransportReplayer(
170
+ RecordStore.fromString(`
171
+ => e0040080ff038000002c80000094800000007ac33997544e3175d266bd022439b22cdb16508c01163f26e5cb2a3e1045a9790000000200000000e93388bbfd2fbd11806dd0bd59cea9079e7cc70ce7b1e154f114cdfe4e466ecd000071d7002d9fed000000010000000000000000000000010000000100000000e93388bbfd2fbd11806dd0bd59cea9079e7cc70ce7b1e154f114cdfe4e466ecd00000018000000020000024c0061736d0100000001150460027e7e017e60037e7e7e017e6000017e600000021904016c01300000016c01310000016c015f0001016c013800000305040203030305030100100619037f01418080c0000b7f00418080c0000b7f00418080
172
+ <= 9000
173
+ => e0048080ffc0000b073505066d656d6f7279020009696e6372656d656e740004015f00070a5f5f646174615f656e6403010b5f5f686561705f6261736503020aa70104920102017f017e41002100024002400240428ebad0af86d43942021080808080004201520d00428ebad0af86d4394202108180808000220142ff01834204520d012001422088a721000b200041016a2200450d01428ebad0af86d4392000ad422086420484220142021082808080001a4284808080a0064284808080c00c1083808080001a20010f0b00000b108580808000000b0900108680808000000b040000000b02000b00730e636f6e74726163747370656376300000000000000040496e
174
+ <= 9000
175
+ => e0048080ff6372656d656e7420696e6372656d656e747320616e20696e7465726e616c20636f756e7465722c20616e642072657475726e73207468652076616c75652e00000009696e6372656d656e74000000000000000000000100000004001e11636f6e7472616374656e766d657461763000000000000000140000003900730e636f6e74726163746d65746176300000000000000005727376657200000000000006312e37332e3000000000000000000008727373646b7665720000003332302e302e302d72633223303939323431336639623035653562666231663837326263653939653839643931323962326536310000000000000000010000000000000001
176
+ <= b004
177
+ `)
178
+ );
179
+ const str = new Str(transport);
180
+ const transaction = Buffer.from(
181
+ "7ac33997544e3175d266bd022439b22cdb16508c01163f26e5cb2a3e1045a9790000000200000000e93388bbfd2fbd11806dd0bd59cea9079e7cc70ce7b1e154f114cdfe4e466ecd000071d7002d9fed000000010000000000000000000000010000000100000000e93388bbfd2fbd11806dd0bd59cea9079e7cc70ce7b1e154f114cdfe4e466ecd00000018000000020000024c0061736d0100000001150460027e7e017e60037e7e7e017e6000017e600000021904016c01300000016c01310000016c015f0001016c013800000305040203030305030100100619037f01418080c0000b7f00418080c0000b7f00418080c0000b073505066d656d6f7279020009696e6372656d656e740004015f00070a5f5f646174615f656e6403010b5f5f686561705f6261736503020aa70104920102017f017e41002100024002400240428ebad0af86d43942021080808080004201520d00428ebad0af86d4394202108180808000220142ff01834204520d012001422088a721000b200041016a2200450d01428ebad0af86d4392000ad422086420484220142021082808080001a4284808080a0064284808080c00c1083808080001a20010f0b00000b108580808000000b0900108680808000000b040000000b02000b00730e636f6e74726163747370656376300000000000000040496e6372656d656e7420696e6372656d656e747320616e20696e7465726e616c20636f756e7465722c20616e642072657475726e73207468652076616c75652e00000009696e6372656d656e74000000000000000000000100000004001e11636f6e7472616374656e766d657461763000000000000000140000003900730e636f6e74726163746d65746176300000000000000005727376657200000000000006312e37332e3000000000000000000008727373646b7665720000003332302e302e302d726332233039393234313366396230356535626662316638373262636539396538396439313239623265363100000000000000000100000000000000010000000713e16858bde4ab50a006dbf07172288f3ec19d8640d1a853016c60c15c2511170000000000186636000002b000000000000000000000000c",
182
+ "hex"
183
+ );
184
+ await expect(str.signTransaction("44'/148'/0'", transaction)).rejects.toThrow(StellarDataTooLargeError);
185
+ });
186
+
187
+ test("signTransaction (rejected)", async () => {
188
+ const transport = await openTransportReplayer(
189
+ RecordStore.fromString(`
190
+ => e0040080ff038000002c80000094800000007ac33997544e3175d266bd022439b22cdb16508c01163f26e5cb2a3e1045a9790000000200000000e93388bbfd2fbd11806dd0bd59cea9079e7cc70ce7b1e154f114cdfe4e466ecd000071d7002d9fed000000010000000000000000000000010000000100000000e93388bbfd2fbd11806dd0bd59cea9079e7cc70ce7b1e154f114cdfe4e466ecd00000018000000020000024c0061736d0100000001150460027e7e017e60037e7e7e017e6000017e600000021904016c01300000016c01310000016c015f0001016c013800000305040203030305030100100619037f01418080c0000b7f00418080c0000b7f00418080
191
+ <= 9000
192
+ => e0048080ffc0000b073505066d656d6f7279020009696e6372656d656e740004015f00070a5f5f646174615f656e6403010b5f5f686561705f6261736503020aa70104920102017f017e41002100024002400240428ebad0af86d43942021080808080004201520d00428ebad0af86d4394202108180808000220142ff01834204520d012001422088a721000b200041016a2200450d01428ebad0af86d4392000ad422086420484220142021082808080001a4284808080a0064284808080c00c1083808080001a20010f0b00000b108580808000000b0900108680808000000b040000000b02000b00730e636f6e74726163747370656376300000000000000040496e
193
+ <= 9000
194
+ => e0048080ff6372656d656e7420696e6372656d656e747320616e20696e7465726e616c20636f756e7465722c20616e642072657475726e73207468652076616c75652e00000009696e6372656d656e74000000000000000000000100000004001e11636f6e7472616374656e766d657461763000000000000000140000003900730e636f6e74726163746d65746176300000000000000005727376657200000000000006312e37332e3000000000000000000008727373646b7665720000003332302e302e302d72633223303939323431336639623035653562666231663837326263653939653839643931323962326536310000000000000000010000000000000001
195
+ <= 9000
196
+ => e00480003c0000000713e16858bde4ab50a006dbf07172288f3ec19d8640d1a853016c60c15c2511170000000000186636000002b000000000000000000000000c
197
+ <= 6985
198
+ `)
199
+ );
200
+ const str = new Str(transport);
201
+ const transaction = Buffer.from(
202
+ "7ac33997544e3175d266bd022439b22cdb16508c01163f26e5cb2a3e1045a9790000000200000000e93388bbfd2fbd11806dd0bd59cea9079e7cc70ce7b1e154f114cdfe4e466ecd000071d7002d9fed000000010000000000000000000000010000000100000000e93388bbfd2fbd11806dd0bd59cea9079e7cc70ce7b1e154f114cdfe4e466ecd00000018000000020000024c0061736d0100000001150460027e7e017e60037e7e7e017e6000017e600000021904016c01300000016c01310000016c015f0001016c013800000305040203030305030100100619037f01418080c0000b7f00418080c0000b7f00418080c0000b073505066d656d6f7279020009696e6372656d656e740004015f00070a5f5f646174615f656e6403010b5f5f686561705f6261736503020aa70104920102017f017e41002100024002400240428ebad0af86d43942021080808080004201520d00428ebad0af86d4394202108180808000220142ff01834204520d012001422088a721000b200041016a2200450d01428ebad0af86d4392000ad422086420484220142021082808080001a4284808080a0064284808080c00c1083808080001a20010f0b00000b108580808000000b0900108680808000000b040000000b02000b00730e636f6e74726163747370656376300000000000000040496e6372656d656e7420696e6372656d656e747320616e20696e7465726e616c20636f756e7465722c20616e642072657475726e73207468652076616c75652e00000009696e6372656d656e74000000000000000000000100000004001e11636f6e7472616374656e766d657461763000000000000000140000003900730e636f6e74726163746d65746176300000000000000005727376657200000000000006312e37332e3000000000000000000008727373646b7665720000003332302e302e302d726332233039393234313366396230356535626662316638373262636539396538396439313239623265363100000000000000000100000000000000010000000713e16858bde4ab50a006dbf07172288f3ec19d8640d1a853016c60c15c2511170000000000186636000002b000000000000000000000000c",
203
+ "hex"
204
+ );
205
+ await expect(str.signTransaction("44'/148'/0'", transaction)).rejects.toThrow(StellarUserRefusedError);
206
+ });
207
+
208
+ test("signTransaction (parse data failed)", async () => {
209
+ const transport = await openTransportReplayer(
210
+ RecordStore.fromString(`
211
+ => e0040000ff038000002c80000094800000007ac33997544e3175d266bd022439b22cdb16508c01163f26e5cb2a3e1045a9790000000200000000e93388bbfd2fbd11806dd0bd59cea9079e7cc70ce7b1e154f114cdfe4e466ecd000071d7002d9fed000000010000000000000000000000010000000100000000e93388bbfd2fbd11806dd0bd59cea9079e7cc70ce7b1e154f114cdfe4e466ecd00000018000000020000024c0061736d0100000001150460027e7e017e60037e7e7e017e6000017e600000021904016c01300000016c01310000016c015f0001016c013800000305040203030305030100100619037f01418080c0000b7f00418080c0000b7f00418080
212
+ <= b005
213
+ `)
214
+ );
215
+ const str = new Str(transport);
216
+ const transaction = Buffer.from(
217
+ "7ac33997544e3175d266bd022439b22cdb16508c01163f26e5cb2a3e1045a9790000000200000000e93388bbfd2fbd11806dd0bd59cea9079e7cc70ce7b1e154f114cdfe4e466ecd000071d7002d9fed000000010000000000000000000000010000000100000000e93388bbfd2fbd11806dd0bd59cea9079e7cc70ce7b1e154f114cdfe4e466ecd00000018000000020000024c0061736d0100000001150460027e7e017e60037e7e7e017e6000017e600000021904016c01300000016c01310000016c015f0001016c013800000305040203030305030100100619037f01418080c0000b7f00418080c0000b7f00418080",
218
+ "hex"
219
+ );
220
+ await expect(str.signTransaction("44'/148'/0'", transaction)).rejects.toThrow(StellarDataParsingFailedError);
221
+ });
222
+
223
+ test("signSorobanAuthorization (size exceeds APDU_MAX_PAYLOAD)", async () => {
224
+ const transport = await openTransportReplayer(
225
+ RecordStore.fromString(`
226
+ => e00a0080ff038000002c8000009480000000000000097ac33997544e3175d266bd022439b22cdb16508c01163f26e5cb2a3e1045a9790000000049756d450210c89f0000000000000001d7928b72c2703ccfeaf7eb9ff4ef4d504a55a8b979fc9b450ea2c842b4d1ce61000000087472616e7366657200000003000000120000000000000000acd0adc778238000bdb6bad22e919923897f7a87e310cef1505e6c0b0b71542500000012000000000000000079a5a13baf5571637a2157c6affb7491d7c4454eecd2b0b7e40e67023f096fac0000000a00000000000000000000000269440500000000020000000000000001d7928b72c2703ccfeaf7eb9ff4ef4d504a55
227
+ <= 9000
228
+ => e00a8080ffa8b979fc9b450ea2c842b4d1ce61000000087472616e7366657200000003000000120000000000000000acd0adc778238000bdb6bad22e919923897f7a87e310cef1505e6c0b0b71542500000012000000000000000079a5a13baf5571637a2157c6affb7491d7c4454eecd2b0b7e40e67023f096fac0000000a00000000000000000000000269440500000000000000000000000001d7928b72c2703ccfeaf7eb9ff4ef4d504a55a8b979fc9b450ea2c842b4d1ce61000000087472616e7366657200000003000000120000000000000000acd0adc778238000bdb6bad22e919923897f7a87e310cef1505e6c0b0b71542500000012000000000000000079
229
+ <= 9000
230
+ => e00a800037a5a13baf5571637a2157c6affb7491d7c4454eecd2b0b7e40e67023f096fac0000000a0000000000000000000000026944050000000000
231
+ <= 2e45c6d44fe613c3d7b38c9f7147bd70dc58cf7e1badb80d33632dcdafb90944674096da05dfe0f185da86535a6ca1a1fcef852a19ae99b22e4438ca5c43b9089000
232
+ `)
233
+ );
234
+ const str = new Str(transport);
235
+ const hashIdPreimage = Buffer.from(
236
+ "000000097ac33997544e3175d266bd022439b22cdb16508c01163f26e5cb2a3e1045a9790000000049756d450210c89f0000000000000001d7928b72c2703ccfeaf7eb9ff4ef4d504a55a8b979fc9b450ea2c842b4d1ce61000000087472616e7366657200000003000000120000000000000000acd0adc778238000bdb6bad22e919923897f7a87e310cef1505e6c0b0b71542500000012000000000000000079a5a13baf5571637a2157c6affb7491d7c4454eecd2b0b7e40e67023f096fac0000000a00000000000000000000000269440500000000020000000000000001d7928b72c2703ccfeaf7eb9ff4ef4d504a55a8b979fc9b450ea2c842b4d1ce61000000087472616e7366657200000003000000120000000000000000acd0adc778238000bdb6bad22e919923897f7a87e310cef1505e6c0b0b71542500000012000000000000000079a5a13baf5571637a2157c6affb7491d7c4454eecd2b0b7e40e67023f096fac0000000a00000000000000000000000269440500000000000000000000000001d7928b72c2703ccfeaf7eb9ff4ef4d504a55a8b979fc9b450ea2c842b4d1ce61000000087472616e7366657200000003000000120000000000000000acd0adc778238000bdb6bad22e919923897f7a87e310cef1505e6c0b0b71542500000012000000000000000079a5a13baf5571637a2157c6affb7491d7c4454eecd2b0b7e40e67023f096fac0000000a0000000000000000000000026944050000000000",
237
+ "hex"
238
+ );
239
+ const { signature } = await str.signSorobanAuthorization("44'/148'/0'", hashIdPreimage);
240
+ const result = signature.toString("hex");
241
+ expect(result).toEqual(
242
+ "2e45c6d44fe613c3d7b38c9f7147bd70dc58cf7e1badb80d33632dcdafb90944674096da05dfe0f185da86535a6ca1a1fcef852a19ae99b22e4438ca5c43b908"
54
243
  );
55
244
  });
245
+
246
+ test("signSorobanAuthorization (size does not exceed APDU_MAX_PAYLOAD)", async () => {
247
+ const transport = await openTransportReplayer(
248
+ RecordStore.fromString(`
249
+ => e00a0000fd038000002c8000009480000000000000097ac33997544e3175d266bd022439b22cdb16508c01163f26e5cb2a3e1045a9790000000049756d450210c89f0000000000000001d7928b72c2703ccfeaf7eb9ff4ef4d504a55a8b979fc9b450ea2c842b4d1ce61000000087472616e7366657200000003000000120000000000000000acd0adc778238000bdb6bad22e919923897f7a87e310cef1505e6c0b0b71542500000012000000000000000079a5a13baf5571637a2157c6affb7491d7c4454eecd2b0b7e40e67023f096fac0000000a00000000000000000000000269440500000000020000000000000001d7928b72c2703ccfeaf7eb9ff4ef4d50
250
+ <= 2e45c6d44fe613c3d7b38c9f7147bd70dc58cf7e1badb80d33632dcdafb90944674096da05dfe0f185da86535a6ca1a1fcef852a19ae99b22e4438ca5c43b9089000
251
+ `)
252
+ );
253
+ const str = new Str(transport);
254
+ const hashIdPreimage = Buffer.from(
255
+ "000000097ac33997544e3175d266bd022439b22cdb16508c01163f26e5cb2a3e1045a9790000000049756d450210c89f0000000000000001d7928b72c2703ccfeaf7eb9ff4ef4d504a55a8b979fc9b450ea2c842b4d1ce61000000087472616e7366657200000003000000120000000000000000acd0adc778238000bdb6bad22e919923897f7a87e310cef1505e6c0b0b71542500000012000000000000000079a5a13baf5571637a2157c6affb7491d7c4454eecd2b0b7e40e67023f096fac0000000a00000000000000000000000269440500000000020000000000000001d7928b72c2703ccfeaf7eb9ff4ef4d50",
256
+ "hex"
257
+ );
258
+ const { signature } = await str.signSorobanAuthorization("44'/148'/0'", hashIdPreimage);
259
+ const result = signature.toString("hex");
260
+ expect(result).toEqual(
261
+ "2e45c6d44fe613c3d7b38c9f7147bd70dc58cf7e1badb80d33632dcdafb90944674096da05dfe0f185da86535a6ca1a1fcef852a19ae99b22e4438ca5c43b908"
262
+ );
263
+ });
264
+
265
+ test("signSorobanAuthorization (size too long)", async () => {
266
+ const transport = await openTransportReplayer(
267
+ RecordStore.fromString(`
268
+ => e00a0080ff038000002c8000009480000000000000097ac33997544e3175d266bd022439b22cdb16508c01163f26e5cb2a3e1045a9790000000049756d450210c89f0000000000000001d7928b72c2703ccfeaf7eb9ff4ef4d504a55a8b979fc9b450ea2c842b4d1ce61000000087472616e7366657200000003000000120000000000000000acd0adc778238000bdb6bad22e919923897f7a87e310cef1505e6c0b0b71542500000012000000000000000079a5a13baf5571637a2157c6affb7491d7c4454eecd2b0b7e40e67023f096fac0000000a00000000000000000000000269440500000000020000000000000001d7928b72c2703ccfeaf7eb9ff4ef4d504a55
269
+ <= 9000
270
+ => e00a8080ffa8b979fc9b450ea2c842b4d1ce61000000087472616e7366657200000003000000120000000000000000acd0adc778238000bdb6bad22e919923897f7a87e310cef1505e6c0b0b71542500000012000000000000000079a5a13baf5571637a2157c6affb7491d7c4454eecd2b0b7e40e67023f096fac0000000a00000000000000000000000269440500000000000000000000000001d7928b72c2703ccfeaf7eb9ff4ef4d504a55a8b979fc9b450ea2c842b4d1ce61000000087472616e7366657200000003000000120000000000000000acd0adc778238000bdb6bad22e919923897f7a87e310cef1505e6c0b0b71542500000012000000000000000079
271
+ <= b004
272
+ `)
273
+ );
274
+ const str = new Str(transport);
275
+ const hashIdPreimage = Buffer.from(
276
+ "000000097ac33997544e3175d266bd022439b22cdb16508c01163f26e5cb2a3e1045a9790000000049756d450210c89f0000000000000001d7928b72c2703ccfeaf7eb9ff4ef4d504a55a8b979fc9b450ea2c842b4d1ce61000000087472616e7366657200000003000000120000000000000000acd0adc778238000bdb6bad22e919923897f7a87e310cef1505e6c0b0b71542500000012000000000000000079a5a13baf5571637a2157c6affb7491d7c4454eecd2b0b7e40e67023f096fac0000000a00000000000000000000000269440500000000020000000000000001d7928b72c2703ccfeaf7eb9ff4ef4d504a55a8b979fc9b450ea2c842b4d1ce61000000087472616e7366657200000003000000120000000000000000acd0adc778238000bdb6bad22e919923897f7a87e310cef1505e6c0b0b71542500000012000000000000000079a5a13baf5571637a2157c6affb7491d7c4454eecd2b0b7e40e67023f096fac0000000a00000000000000000000000269440500000000000000000000000001d7928b72c2703ccfeaf7eb9ff4ef4d504a55a8b979fc9b450ea2c842b4d1ce61000000087472616e7366657200000003000000120000000000000000acd0adc778238000bdb6bad22e919923897f7a87e310cef1505e6c0b0b71542500000012000000000000000079a5a13baf5571637a2157c6affb7491d7c4454eecd2b0b7e40e67023f096fac0000000a0000000000000000000000026944050000000000",
277
+ "hex"
278
+ );
279
+ await expect(str.signSorobanAuthorization("44'/148'/0'", hashIdPreimage)).rejects.toThrow(StellarDataTooLargeError);
280
+ });
281
+
282
+ test("signSorobanAuthorization (rejected)", async () => {
283
+ const transport = await openTransportReplayer(
284
+ RecordStore.fromString(`
285
+ => e00a0000fd038000002c8000009480000000000000097ac33997544e3175d266bd022439b22cdb16508c01163f26e5cb2a3e1045a9790000000049756d450210c89f0000000000000001d7928b72c2703ccfeaf7eb9ff4ef4d504a55a8b979fc9b450ea2c842b4d1ce61000000087472616e7366657200000003000000120000000000000000acd0adc778238000bdb6bad22e919923897f7a87e310cef1505e6c0b0b71542500000012000000000000000079a5a13baf5571637a2157c6affb7491d7c4454eecd2b0b7e40e67023f096fac0000000a00000000000000000000000269440500000000020000000000000001d7928b72c2703ccfeaf7eb9ff4ef4d50
286
+ <= 6985
287
+ `)
288
+ );
289
+ const str = new Str(transport);
290
+ const hashIdPreimage = Buffer.from(
291
+ "000000097ac33997544e3175d266bd022439b22cdb16508c01163f26e5cb2a3e1045a9790000000049756d450210c89f0000000000000001d7928b72c2703ccfeaf7eb9ff4ef4d504a55a8b979fc9b450ea2c842b4d1ce61000000087472616e7366657200000003000000120000000000000000acd0adc778238000bdb6bad22e919923897f7a87e310cef1505e6c0b0b71542500000012000000000000000079a5a13baf5571637a2157c6affb7491d7c4454eecd2b0b7e40e67023f096fac0000000a00000000000000000000000269440500000000020000000000000001d7928b72c2703ccfeaf7eb9ff4ef4d50",
292
+ "hex"
293
+ );
294
+ await expect(str.signSorobanAuthorization("44'/148'/0'", hashIdPreimage)).rejects.toThrow(StellarUserRefusedError);
295
+ });
296
+
297
+ test("signSorobanAuthorization (parse data failed)", async () => {
298
+ const transport = await openTransportReplayer(
299
+ RecordStore.fromString(`
300
+ => e00a0080ff038000002c8000009480000000000000097ac33997544e3175d266bd022439b22cdb16508c01163f26e5cb2a3e1045a9790000000049756d450210c89f0000000000000001d7928b72c2703ccfeaf7eb9ff4ef4d504a55a8b979fc9b450ea2c842b4d1ce61000000087472616e7366657200000003000000120000000000000000acd0adc778238000bdb6bad22e919923897f7a87e310cef1505e6c0b0b71542500000012000000000000000079a5a13baf5571637a2157c6affb7491d7c4454eecd2b0b7e40e67023f096fac0000000a00000000000000000000000269440500000000020000000000000001d7928b72c2703ccfeaf7eb9ff4ef4d504a55
301
+ <= 9000
302
+ => e00a8080ffa8b979fc9b450ea2c842b4d1ce61000000087472616e7366657200000003000000120000000000000000acd0adc778238000bdb6bad22e919923897f7a87e310cef1505e6c0b0b71542500000012000000000000000079a5a13baf5571637a2157c6affb7491d7c4454eecd2b0b7e40e67023f096fac0000000a00000000000000000000000269440500000000000000000000000001d7928b72c2703ccfeaf7eb9ff4ef4d504a55a8b979fc9b450ea2c842b4d1ce61000000087472616e7366657200000003000000120000000000000000acd0adc778238000bdb6bad22e919923897f7a87e310cef1505e6c0b0b71542500000012000000000000000079
303
+ <= 9000
304
+ => e00a800037a5a13baf5571637a2157c6affb7491d7c4454eecd2b0b7e40e67023f096fac0000000a0000000000000000000000026944050000000000
305
+ <= b005
306
+ `)
307
+ );
308
+ const str = new Str(transport);
309
+ const hashIdPreimage = Buffer.from(
310
+ "000000097ac33997544e3175d266bd022439b22cdb16508c01163f26e5cb2a3e1045a9790000000049756d450210c89f0000000000000001d7928b72c2703ccfeaf7eb9ff4ef4d504a55a8b979fc9b450ea2c842b4d1ce61000000087472616e7366657200000003000000120000000000000000acd0adc778238000bdb6bad22e919923897f7a87e310cef1505e6c0b0b71542500000012000000000000000079a5a13baf5571637a2157c6affb7491d7c4454eecd2b0b7e40e67023f096fac0000000a00000000000000000000000269440500000000020000000000000001d7928b72c2703ccfeaf7eb9ff4ef4d504a55a8b979fc9b450ea2c842b4d1ce61000000087472616e7366657200000003000000120000000000000000acd0adc778238000bdb6bad22e919923897f7a87e310cef1505e6c0b0b71542500000012000000000000000079a5a13baf5571637a2157c6affb7491d7c4454eecd2b0b7e40e67023f096fac0000000a00000000000000000000000269440500000000000000000000000001d7928b72c2703ccfeaf7eb9ff4ef4d504a55a8b979fc9b450ea2c842b4d1ce61000000087472616e7366657200000003000000120000000000000000acd0adc778238000bdb6bad22e919923897f7a87e310cef1505e6c0b0b71542500000012000000000000000079a5a13baf5571637a2157c6affb7491d7c4454eecd2b0b7e40e67023f096fac0000000a0000000000000000000000026944050000000000",
311
+ "hex"
312
+ );
313
+ await expect(str.signSorobanAuthorization("44'/148'/0'", hashIdPreimage)).rejects.toThrow(StellarDataParsingFailedError);
314
+ });
315
+
316
+ test("pathToBuffer (44'/148'/19773')", async () => {
317
+ const transport = await openTransportReplayer(
318
+ RecordStore.fromString(`
319
+ => e00200000d038000002c8000009480004d3d
320
+ <= 04becf1537ae24f24d326368a2ad8a09b06cb0671e96e6878d4e623aab4bf6e79000
321
+ `)
322
+ );
323
+ const str = new Str(transport);
324
+ const { rawPublicKey } = await str.getPublicKey("44'/148'/19773'", false);
325
+ expect(rawPublicKey.toString("hex")).toEqual(
326
+ "04becf1537ae24f24d326368a2ad8a09b06cb0671e96e6878d4e623aab4bf6e7"
327
+ );
328
+ });
329
+
330
+ test("pathToBuffer (44'/148'/19773)", async () => {
331
+ const transport = await openTransportReplayer(
332
+ RecordStore.fromString(`
333
+ => e00200000d038000002c8000009480004d3d
334
+ <= 04becf1537ae24f24d326368a2ad8a09b06cb0671e96e6878d4e623aab4bf6e79000
335
+ `)
336
+ );
337
+ const str = new Str(transport);
338
+ const { rawPublicKey } = await str.getPublicKey("44'/148'/19773", false);
339
+ expect(rawPublicKey.toString("hex")).toEqual(
340
+ "04becf1537ae24f24d326368a2ad8a09b06cb0671e96e6878d4e623aab4bf6e7"
341
+ );
342
+ });
343
+
344
+ test("remapErrors (unexpected)", async () => {
345
+ const transport = await openTransportReplayer(
346
+ RecordStore.fromString(`
347
+ => e00200000d038000002c8000009480004d3d
348
+ <= b001
349
+ `)
350
+ );
351
+ const str = new Str(transport);
352
+ try {
353
+ await str.getPublicKey("44'/148'/19773", false);
354
+ } catch (error) {
355
+ expect(error).toBeInstanceOf(TransportStatusError);
356
+ if (error instanceof TransportStatusError) {
357
+ expect(error.statusCode).toBe(0xb001);
358
+ }
359
+ }
360
+ });
package/lib/utils.d.ts DELETED
@@ -1,9 +0,0 @@
1
- /// <reference types="node" />
2
- export declare function splitPath(path: string): number[];
3
- export declare function foreach<T, A>(arr: T[], callback: (arg0: T, arg1: number) => Promise<A>): Promise<A[]>;
4
- export declare function crc16xmodem(buf: Buffer, previous?: number): number;
5
- export declare function encodeEd25519PublicKey(rawPublicKey: Buffer): string;
6
- export declare function verifyEd25519Signature(data: Buffer, signature: Buffer, publicKey: Buffer): boolean;
7
- export declare function hash(data: Buffer): any;
8
- export declare function checkStellarBip32Path(path: string): void;
9
- //# sourceMappingURL=utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";AAoBA,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAiBhD;AACD,wBAAgB,OAAO,CAAC,CAAC,EAAE,CAAC,EAC1B,GAAG,EAAE,CAAC,EAAE,EACR,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,GAC9C,OAAO,CAAC,CAAC,EAAE,CAAC,CAad;AACD,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAiBlE;AACD,wBAAgB,sBAAsB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAUnE;AACD,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,GAChB,OAAO,CAMT;AACD,wBAAgB,IAAI,CAAC,IAAI,EAAE,MAAM,OAIhC;AACD,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAUxD"}
package/lib/utils.js DELETED
@@ -1,106 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.checkStellarBip32Path = exports.hash = exports.verifyEd25519Signature = exports.encodeEd25519PublicKey = exports.crc16xmodem = exports.foreach = exports.splitPath = void 0;
7
- /********************************************************************************
8
- * Ledger Node JS API
9
- * (c) 2017-2018 Ledger
10
- *
11
- * Licensed under the Apache License, Version 2.0 (the "License");
12
- * you may not use this file except in compliance with the License.
13
- * You may obtain a copy of the License at
14
- *
15
- * http://www.apache.org/licenses/LICENSE-2.0
16
- *
17
- * Unless required by applicable law or agreed to in writing, software
18
- * distributed under the License is distributed on an "AS IS" BASIS,
19
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
- * See the License for the specific language governing permissions and
21
- * limitations under the License.
22
- ********************************************************************************/
23
- const base32_js_1 = __importDefault(require("base32.js"));
24
- const tweetnacl_1 = __importDefault(require("tweetnacl"));
25
- const sha_js_1 = require("sha.js");
26
- // TODO use bip32-path library
27
- function splitPath(path) {
28
- const result = [];
29
- const components = path.split("/");
30
- components.forEach(element => {
31
- let number = parseInt(element, 10);
32
- if (isNaN(number)) {
33
- return; // FIXME shouldn't it throws instead?
34
- }
35
- if (element.length > 1 && element[element.length - 1] === "'") {
36
- number += 0x80000000;
37
- }
38
- result.push(number);
39
- });
40
- return result;
41
- }
42
- exports.splitPath = splitPath;
43
- function foreach(arr, callback) {
44
- function iterate(index, array, result) {
45
- if (index >= array.length) {
46
- return result;
47
- }
48
- else {
49
- return callback(array[index], index).then(function (res) {
50
- result.push(res);
51
- return iterate(index + 1, array, result);
52
- });
53
- }
54
- }
55
- return Promise.resolve().then(() => iterate(0, arr, []));
56
- }
57
- exports.foreach = foreach;
58
- function crc16xmodem(buf, previous) {
59
- let crc = typeof previous !== "undefined" ? ~~previous : 0x0;
60
- for (let index = 0; index < buf.length; index++) {
61
- const byte = buf[index];
62
- let code = (crc >>> 8) & 0xff;
63
- code ^= byte & 0xff;
64
- code ^= code >>> 4;
65
- crc = (crc << 8) & 0xffff;
66
- crc ^= code;
67
- code = (code << 5) & 0xffff;
68
- crc ^= code;
69
- code = (code << 7) & 0xffff;
70
- crc ^= code;
71
- }
72
- return crc;
73
- }
74
- exports.crc16xmodem = crc16xmodem;
75
- function encodeEd25519PublicKey(rawPublicKey) {
76
- const versionByte = 6 << 3; // 'G'
77
- const data = Buffer.from(rawPublicKey);
78
- const versionBuffer = Buffer.from([versionByte]);
79
- const payload = Buffer.concat([versionBuffer, data]);
80
- const checksum = Buffer.alloc(2);
81
- checksum.writeUInt16LE(crc16xmodem(payload), 0);
82
- const unencoded = Buffer.concat([payload, checksum]);
83
- return base32_js_1.default.encode(unencoded);
84
- }
85
- exports.encodeEd25519PublicKey = encodeEd25519PublicKey;
86
- function verifyEd25519Signature(data, signature, publicKey) {
87
- return tweetnacl_1.default.sign.detached.verify(new Uint8Array(data.toJSON().data), new Uint8Array(signature.toJSON().data), new Uint8Array(publicKey.toJSON().data));
88
- }
89
- exports.verifyEd25519Signature = verifyEd25519Signature;
90
- function hash(data) {
91
- const hasher = new sha_js_1.sha256();
92
- hasher.update(data, "utf8");
93
- return hasher.digest();
94
- }
95
- exports.hash = hash;
96
- function checkStellarBip32Path(path) {
97
- path.split("/").forEach(function (element) {
98
- if (!element.toString().endsWith("'")) {
99
- throw new Error("Detected a non-hardened path element in requested BIP32 path." +
100
- " Non-hardended paths are not supported at this time. Please use an all-hardened path." +
101
- " Example: 44'/148'/0'");
102
- }
103
- });
104
- }
105
- exports.checkStellarBip32Path = checkStellarBip32Path;
106
- //# sourceMappingURL=utils.js.map
package/lib/utils.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;;;;AAAA;;;;;;;;;;;;;;;kFAekF;AAClF,0DAA+B;AAC/B,0DAA6B;AAC7B,mCAAgC;AAChC,8BAA8B;AAC9B,SAAgB,SAAS,CAAC,IAAY;IACpC,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACnC,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;QAC3B,IAAI,MAAM,GAAG,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QAEnC,IAAI,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;YAClB,OAAO,CAAC,qCAAqC;QAC/C,CAAC;QAED,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;YAC9D,MAAM,IAAI,UAAU,CAAC;QACvB,CAAC;QAED,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACtB,CAAC,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAChB,CAAC;AAjBD,8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DAUC;AACD,SAAgB,IAAI,CAAC,IAAY;IAC/B,MAAM,MAAM,GAAG,IAAI,eAAM,EAAE,CAAC;IAC5B,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAC5B,OAAO,MAAM,CAAC,MAAM,EAAE,CAAC;AACzB,CAAC;AAJD,oBAIC;AACD,SAAgB,qBAAqB,CAAC,IAAY;IAChD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,UAAU,OAAO;QACvC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YACtC,MAAM,IAAI,KAAK,CACb,+DAA+D;gBAC7D,uFAAuF;gBACvF,uBAAuB,CAC1B,CAAC;QACJ,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAVD,sDAUC"}
package/lib-es/utils.d.ts DELETED
@@ -1,9 +0,0 @@
1
- /// <reference types="node" />
2
- export declare function splitPath(path: string): number[];
3
- export declare function foreach<T, A>(arr: T[], callback: (arg0: T, arg1: number) => Promise<A>): Promise<A[]>;
4
- export declare function crc16xmodem(buf: Buffer, previous?: number): number;
5
- export declare function encodeEd25519PublicKey(rawPublicKey: Buffer): string;
6
- export declare function verifyEd25519Signature(data: Buffer, signature: Buffer, publicKey: Buffer): boolean;
7
- export declare function hash(data: Buffer): any;
8
- export declare function checkStellarBip32Path(path: string): void;
9
- //# sourceMappingURL=utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";AAoBA,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAiBhD;AACD,wBAAgB,OAAO,CAAC,CAAC,EAAE,CAAC,EAC1B,GAAG,EAAE,CAAC,EAAE,EACR,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,GAC9C,OAAO,CAAC,CAAC,EAAE,CAAC,CAad;AACD,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAiBlE;AACD,wBAAgB,sBAAsB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAUnE;AACD,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,GAChB,OAAO,CAMT;AACD,wBAAgB,IAAI,CAAC,IAAI,EAAE,MAAM,OAIhC;AACD,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAUxD"}
package/lib-es/utils.js DELETED
@@ -1,93 +0,0 @@
1
- /********************************************************************************
2
- * Ledger Node JS API
3
- * (c) 2017-2018 Ledger
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- ********************************************************************************/
17
- import base32 from "base32.js";
18
- import nacl from "tweetnacl";
19
- import { sha256 } from "sha.js";
20
- // TODO use bip32-path library
21
- export function splitPath(path) {
22
- const result = [];
23
- const components = path.split("/");
24
- components.forEach(element => {
25
- let number = parseInt(element, 10);
26
- if (isNaN(number)) {
27
- return; // FIXME shouldn't it throws instead?
28
- }
29
- if (element.length > 1 && element[element.length - 1] === "'") {
30
- number += 0x80000000;
31
- }
32
- result.push(number);
33
- });
34
- return result;
35
- }
36
- export function foreach(arr, callback) {
37
- function iterate(index, array, result) {
38
- if (index >= array.length) {
39
- return result;
40
- }
41
- else {
42
- return callback(array[index], index).then(function (res) {
43
- result.push(res);
44
- return iterate(index + 1, array, result);
45
- });
46
- }
47
- }
48
- return Promise.resolve().then(() => iterate(0, arr, []));
49
- }
50
- export function crc16xmodem(buf, previous) {
51
- let crc = typeof previous !== "undefined" ? ~~previous : 0x0;
52
- for (let index = 0; index < buf.length; index++) {
53
- const byte = buf[index];
54
- let code = (crc >>> 8) & 0xff;
55
- code ^= byte & 0xff;
56
- code ^= code >>> 4;
57
- crc = (crc << 8) & 0xffff;
58
- crc ^= code;
59
- code = (code << 5) & 0xffff;
60
- crc ^= code;
61
- code = (code << 7) & 0xffff;
62
- crc ^= code;
63
- }
64
- return crc;
65
- }
66
- export function encodeEd25519PublicKey(rawPublicKey) {
67
- const versionByte = 6 << 3; // 'G'
68
- const data = Buffer.from(rawPublicKey);
69
- const versionBuffer = Buffer.from([versionByte]);
70
- const payload = Buffer.concat([versionBuffer, data]);
71
- const checksum = Buffer.alloc(2);
72
- checksum.writeUInt16LE(crc16xmodem(payload), 0);
73
- const unencoded = Buffer.concat([payload, checksum]);
74
- return base32.encode(unencoded);
75
- }
76
- export function verifyEd25519Signature(data, signature, publicKey) {
77
- return nacl.sign.detached.verify(new Uint8Array(data.toJSON().data), new Uint8Array(signature.toJSON().data), new Uint8Array(publicKey.toJSON().data));
78
- }
79
- export function hash(data) {
80
- const hasher = new sha256();
81
- hasher.update(data, "utf8");
82
- return hasher.digest();
83
- }
84
- export function checkStellarBip32Path(path) {
85
- path.split("/").forEach(function (element) {
86
- if (!element.toString().endsWith("'")) {
87
- throw new Error("Detected a non-hardened path element in requested BIP32 path." +
88
- " Non-hardended paths are not supported at this time. Please use an all-hardened path." +
89
- " Example: 44'/148'/0'");
90
- }
91
- });
92
- }
93
- //# sourceMappingURL=utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;kFAekF;AAClF,OAAO,MAAM,MAAM,WAAW,CAAC;AAC/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