@zondax/ledger-cosmos-js 2.1.8 → 3.0.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/LICENSE +1 -1
- package/README.md +39 -7
- package/dist/commandsV1.d.ts +4 -0
- package/dist/commandsV1.js +129 -0
- package/dist/commandsV1.js.map +1 -0
- package/dist/commandsV2.d.ts +4 -0
- package/dist/commandsV2.js +104 -0
- package/dist/commandsV2.js.map +1 -0
- package/dist/common.d.ts +39 -0
- package/dist/common.js +143 -132
- package/dist/common.js.map +1 -0
- package/dist/cosmosApp.d.ts +19 -0
- package/dist/cosmosApp.js +377 -0
- package/dist/cosmosApp.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +17 -608
- package/dist/index.js.map +1 -0
- package/package.json +64 -50
- package/yarn.lock +6661 -0
- package/.babelrc +0 -13
- package/.circleci/config.yml +0 -62
- package/.editorconfig +0 -14
- package/.eslintrc.json +0 -31
- package/.idea/codeStyles/Project.xml +0 -57
- package/.idea/codeStyles/codeStyleConfig.xml +0 -5
- package/.idea/inspectionProfiles/Project_Default.xml +0 -6
- package/.idea/jsLibraryMappings.xml +0 -6
- package/.idea/ledger-cosmos-js.iml +0 -12
- package/.idea/modules.xml +0 -8
- package/.idea/vcs.xml +0 -6
- package/.idea/workspace.xml +0 -57
- package/.prettierrc.json +0 -4
- package/certs/.gitkeep +0 -0
- package/certs/openssl.cnf +0 -12
- package/dist/helperV1.js +0 -127
- package/dist/helperV2.js +0 -97
- package/docs/example.png +0 -0
- package/jest.config.integration.js +0 -9
- package/jest.config.js +0 -32
- package/jest.config.unit.js +0 -9
- package/public/favicon.ico +0 -0
- package/public/index.html +0 -17
- package/src/common.js +0 -114
- package/src/helperV1.js +0 -73
- package/src/helperV2.js +0 -44
- package/src/index.js +0 -336
- package/tests/basic.ispec.js +0 -390
- package/tests/basic.spec.js +0 -8
- package/tests/jest.js +0 -2
- package/vue.config.js +0 -11
- package/vue_example/App.vue +0 -29
- package/vue_example/assets/logo.png +0 -0
- package/vue_example/components/LedgerExample.vue +0 -252
- package/vue_example/main.js +0 -9
package/tests/basic.ispec.js
DELETED
|
@@ -1,390 +0,0 @@
|
|
|
1
|
-
import CosmosApp from "index.js";
|
|
2
|
-
import TransportNodeHid from "@ledgerhq/hw-transport-node-hid";
|
|
3
|
-
import { expect, test } from "jest";
|
|
4
|
-
import secp256k1 from "secp256k1/elliptic";
|
|
5
|
-
import crypto from "crypto";
|
|
6
|
-
import { ERROR_CODE } from "../src/common";
|
|
7
|
-
|
|
8
|
-
test("get version", async () => {
|
|
9
|
-
const transport = await TransportNodeHid.create(1000);
|
|
10
|
-
|
|
11
|
-
const app = new CosmosApp(transport);
|
|
12
|
-
const resp = await app.getVersion();
|
|
13
|
-
console.log(resp);
|
|
14
|
-
|
|
15
|
-
expect(resp.return_code).toEqual(ERROR_CODE.NoError);
|
|
16
|
-
expect(resp.error_message).toEqual("No errors");
|
|
17
|
-
expect(resp).toHaveProperty("test_mode");
|
|
18
|
-
expect(resp).toHaveProperty("major");
|
|
19
|
-
expect(resp).toHaveProperty("minor");
|
|
20
|
-
expect(resp).toHaveProperty("patch");
|
|
21
|
-
expect(resp.test_mode).toEqual(false);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
test("publicKey", async () => {
|
|
25
|
-
const transport = await TransportNodeHid.create(1000);
|
|
26
|
-
const app = new CosmosApp(transport);
|
|
27
|
-
|
|
28
|
-
// Derivation path. First 3 items are automatically hardened!
|
|
29
|
-
const path = [44, 118, 0, 0, 0];
|
|
30
|
-
|
|
31
|
-
const resp = await app.publicKey(path);
|
|
32
|
-
|
|
33
|
-
expect(resp.return_code).toEqual(ERROR_CODE.NoError);
|
|
34
|
-
expect(resp.error_message).toEqual("No errors");
|
|
35
|
-
expect(resp).toHaveProperty("compressed_pk");
|
|
36
|
-
expect(resp.compressed_pk.length).toEqual(33);
|
|
37
|
-
expect(resp.compressed_pk.toString("hex")).toEqual(
|
|
38
|
-
"034fef9cd7c4c63588d3b03feb5281b9d232cba34d6f3d71aee59211ffbfe1fe87",
|
|
39
|
-
);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
test("getAddressAndPubKey", async () => {
|
|
43
|
-
jest.setTimeout(60000);
|
|
44
|
-
|
|
45
|
-
const transport = await TransportNodeHid.create(1000);
|
|
46
|
-
const app = new CosmosApp(transport);
|
|
47
|
-
|
|
48
|
-
// Derivation path. First 3 items are automatically hardened!
|
|
49
|
-
const path = [44, 118, 5, 0, 3];
|
|
50
|
-
const resp = await app.getAddressAndPubKey(path, "cosmos");
|
|
51
|
-
|
|
52
|
-
console.log(resp);
|
|
53
|
-
|
|
54
|
-
expect(resp.return_code).toEqual(ERROR_CODE.NoError);
|
|
55
|
-
expect(resp.error_message).toEqual("No errors");
|
|
56
|
-
|
|
57
|
-
expect(resp).toHaveProperty("bech32_address");
|
|
58
|
-
expect(resp).toHaveProperty("compressed_pk");
|
|
59
|
-
|
|
60
|
-
expect(resp.bech32_address).toEqual("cosmos1wkd9tfm5pqvhhaxq77wv9tvjcsazuaykwsld65");
|
|
61
|
-
expect(resp.compressed_pk.length).toEqual(33);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
test("showAddressAndPubKey", async () => {
|
|
65
|
-
jest.setTimeout(60000);
|
|
66
|
-
|
|
67
|
-
const transport = await TransportNodeHid.create(1000);
|
|
68
|
-
const app = new CosmosApp(transport);
|
|
69
|
-
|
|
70
|
-
// Derivation path. First 3 items are automatically hardened!
|
|
71
|
-
const path = [44, 118, 5, 0, 3];
|
|
72
|
-
const resp = await app.showAddressAndPubKey(path, "cosmos");
|
|
73
|
-
|
|
74
|
-
console.log(resp);
|
|
75
|
-
|
|
76
|
-
expect(resp.return_code).toEqual(ERROR_CODE.NoError);
|
|
77
|
-
expect(resp.error_message).toEqual("No errors");
|
|
78
|
-
|
|
79
|
-
expect(resp).toHaveProperty("bech32_address");
|
|
80
|
-
expect(resp).toHaveProperty("compressed_pk");
|
|
81
|
-
|
|
82
|
-
expect(resp.bech32_address).toEqual("cosmos1wkd9tfm5pqvhhaxq77wv9tvjcsazuaykwsld65");
|
|
83
|
-
expect(resp.compressed_pk.length).toEqual(33);
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
test("appInfo", async () => {
|
|
87
|
-
const transport = await TransportNodeHid.create(1000);
|
|
88
|
-
const app = new CosmosApp(transport);
|
|
89
|
-
|
|
90
|
-
const resp = await app.appInfo();
|
|
91
|
-
|
|
92
|
-
console.log(resp);
|
|
93
|
-
|
|
94
|
-
expect(resp.return_code).toEqual(ERROR_CODE.NoError);
|
|
95
|
-
expect(resp.error_message).toEqual("No errors");
|
|
96
|
-
|
|
97
|
-
expect(resp).toHaveProperty("appName");
|
|
98
|
-
expect(resp).toHaveProperty("appVersion");
|
|
99
|
-
expect(resp).toHaveProperty("flagLen");
|
|
100
|
-
expect(resp).toHaveProperty("flagsValue");
|
|
101
|
-
expect(resp).toHaveProperty("flag_recovery");
|
|
102
|
-
expect(resp).toHaveProperty("flag_signed_mcu_code");
|
|
103
|
-
expect(resp).toHaveProperty("flag_onboarded");
|
|
104
|
-
expect(resp).toHaveProperty("flag_pin_validated");
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
test("deviceInfo", async () => {
|
|
108
|
-
const transport = await TransportNodeHid.create(1000);
|
|
109
|
-
const app = new CosmosApp(transport);
|
|
110
|
-
|
|
111
|
-
const resp = await app.deviceInfo();
|
|
112
|
-
|
|
113
|
-
console.log(resp);
|
|
114
|
-
|
|
115
|
-
expect(resp.return_code).toEqual(ERROR_CODE.NoError);
|
|
116
|
-
expect(resp.error_message).toEqual("No errors");
|
|
117
|
-
|
|
118
|
-
expect(resp).toHaveProperty("targetId");
|
|
119
|
-
expect(resp).toHaveProperty("seVersion");
|
|
120
|
-
expect(resp).toHaveProperty("flag");
|
|
121
|
-
expect(resp).toHaveProperty("mcuVersion");
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
test("sign_and_verify", async () => {
|
|
125
|
-
jest.setTimeout(60000);
|
|
126
|
-
|
|
127
|
-
const transport = await TransportNodeHid.create(1000);
|
|
128
|
-
const app = new CosmosApp(transport);
|
|
129
|
-
|
|
130
|
-
// Derivation path. First 3 items are automatically hardened!
|
|
131
|
-
const path = [44, 118, 0, 0, 0];
|
|
132
|
-
const message = String.raw`{"account_number":"6571","chain_id":"cosmoshub-2","fee":{"amount":[{"amount":"5000","denom":"uatom"}],"gas":"200000"},"memo":"Delegated with Ledger from union.market","msgs":[{"type":"cosmos-sdk/MsgDelegate","value":{"amount":{"amount":"1000000","denom":"uatom"},"delegator_address":"cosmos102hty0jv2s29lyc4u0tv97z9v298e24t3vwtpl","validator_address":"cosmosvaloper1grgelyng2v6v3t8z87wu3sxgt9m5s03xfytvz7"}}],"sequence":"0"}`;
|
|
133
|
-
|
|
134
|
-
const responsePk = await app.publicKey(path);
|
|
135
|
-
console.log(responsePk);
|
|
136
|
-
expect(responsePk.return_code).toEqual(ERROR_CODE.NoError);
|
|
137
|
-
expect(responsePk.error_message).toEqual("No errors");
|
|
138
|
-
|
|
139
|
-
const responseSign = await app.sign(path, message);
|
|
140
|
-
console.log(responseSign);
|
|
141
|
-
expect(responseSign.return_code).toEqual(ERROR_CODE.NoError);
|
|
142
|
-
expect(responseSign.error_message).toEqual("No errors");
|
|
143
|
-
|
|
144
|
-
// Check signature is valid
|
|
145
|
-
const hash = crypto.createHash("sha256");
|
|
146
|
-
const msgHash = hash.update(message).digest();
|
|
147
|
-
|
|
148
|
-
const signatureDER = responseSign.signature;
|
|
149
|
-
const signature = secp256k1.signatureImport(signatureDER);
|
|
150
|
-
const signatureOk = secp256k1.verify(msgHash, signature, responsePk.compressed_pk);
|
|
151
|
-
expect(signatureOk).toEqual(true);
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
test("sign_tiny_memo", async () => {
|
|
155
|
-
jest.setTimeout(60000);
|
|
156
|
-
|
|
157
|
-
const transport = await TransportNodeHid.create(1000);
|
|
158
|
-
const app = new CosmosApp(transport);
|
|
159
|
-
|
|
160
|
-
// Derivation path. First 3 items are automatically hardened!
|
|
161
|
-
const path = [44, 118, 0, 0, 0];
|
|
162
|
-
const message = String.raw`{"account_number":"0","chain_id":"test-chain-1","fee":{"amount":[{"amount":"5","denom":"photon"}],"gas":"10000"},"memo":"A","msgs":[{"inputs":[{"address":"cosmosaccaddr1d9h8qat5e4ehc5","coins":[{"amount":"10","denom":"atom"}]}],"outputs":[{"address":"cosmosaccaddr1da6hgur4wse3jx32","coins":[{"amount":"10","denom":"atom"}]}]}],"sequence":"1"}`;
|
|
163
|
-
|
|
164
|
-
const responsePk = await app.publicKey(path);
|
|
165
|
-
const responseSign = await app.sign(path, message);
|
|
166
|
-
|
|
167
|
-
console.log(responsePk);
|
|
168
|
-
console.log(responseSign);
|
|
169
|
-
|
|
170
|
-
expect(responsePk.return_code).toEqual(ERROR_CODE.NoError);
|
|
171
|
-
expect(responsePk.error_message).toEqual("No errors");
|
|
172
|
-
expect(responseSign.return_code).toEqual(ERROR_CODE.NoError);
|
|
173
|
-
expect(responseSign.error_message).toEqual("No errors");
|
|
174
|
-
|
|
175
|
-
// Check signature is valid
|
|
176
|
-
const hash = crypto.createHash("sha256");
|
|
177
|
-
const msgHash = hash.update(message).digest();
|
|
178
|
-
|
|
179
|
-
const signatureDER = responseSign.signature;
|
|
180
|
-
const signature = secp256k1.signatureImport(signatureDER);
|
|
181
|
-
const signatureOk = secp256k1.verify(msgHash, signature, responsePk.compressed_pk);
|
|
182
|
-
expect(signatureOk).toEqual(true);
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
test("sign_empty_memo", async () => {
|
|
186
|
-
jest.setTimeout(60000);
|
|
187
|
-
|
|
188
|
-
const transport = await TransportNodeHid.create(1000);
|
|
189
|
-
const app = new CosmosApp(transport);
|
|
190
|
-
|
|
191
|
-
// Derivation path. First 3 items are automatically hardened!
|
|
192
|
-
const path = [44, 118, 0, 0, 0];
|
|
193
|
-
const message = String.raw`{"account_number":"0","chain_id":"test-chain-1","fee":{"amount":[{"amount":"5","denom":"photon"}],"gas":"10000"},"memo":"","msgs":[{"inputs":[{"address":"cosmosaccaddr1d9h8qat5e4ehc5","coins":[{"amount":"10","denom":"atom"}]}],"outputs":[{"address":"cosmosaccaddr1da6hgur4wse3jx32","coins":[{"amount":"10","denom":"atom"}]}]}],"sequence":"1"}`;
|
|
194
|
-
|
|
195
|
-
const responsePk = await app.publicKey(path);
|
|
196
|
-
const responseSign = await app.sign(path, message);
|
|
197
|
-
|
|
198
|
-
console.log(responsePk);
|
|
199
|
-
console.log(responseSign);
|
|
200
|
-
|
|
201
|
-
expect(responsePk.return_code).toEqual(ERROR_CODE.NoError);
|
|
202
|
-
expect(responsePk.error_message).toEqual("No errors");
|
|
203
|
-
expect(responseSign.return_code).toEqual(ERROR_CODE.NoError);
|
|
204
|
-
expect(responseSign.error_message).toEqual("No errors");
|
|
205
|
-
|
|
206
|
-
// Check signature is valid
|
|
207
|
-
const hash = crypto.createHash("sha256");
|
|
208
|
-
const msgHash = hash.update(message).digest();
|
|
209
|
-
|
|
210
|
-
const signatureDER = responseSign.signature;
|
|
211
|
-
const signature = secp256k1.signatureImport(signatureDER);
|
|
212
|
-
const signatureOk = secp256k1.verify(msgHash, signature, responsePk.compressed_pk);
|
|
213
|
-
expect(signatureOk).toEqual(true);
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
test("sign_withdraw", async () => {
|
|
217
|
-
jest.setTimeout(60000);
|
|
218
|
-
|
|
219
|
-
const transport = await TransportNodeHid.create(1000);
|
|
220
|
-
const app = new CosmosApp(transport);
|
|
221
|
-
|
|
222
|
-
// Derivation path. First 3 items are automatically hardened!
|
|
223
|
-
const path = [44, 118, 0, 0, 0];
|
|
224
|
-
|
|
225
|
-
const tx_str = {
|
|
226
|
-
account_number: "108",
|
|
227
|
-
chain_id: "cosmoshub-2",
|
|
228
|
-
fee: {
|
|
229
|
-
amount: [
|
|
230
|
-
{
|
|
231
|
-
amount: "600",
|
|
232
|
-
denom: "uatom",
|
|
233
|
-
},
|
|
234
|
-
],
|
|
235
|
-
gas: "200000",
|
|
236
|
-
},
|
|
237
|
-
memo: "",
|
|
238
|
-
msgs: [
|
|
239
|
-
{
|
|
240
|
-
type: "cosmos-sdk/MsgWithdrawDelegationReward",
|
|
241
|
-
value: {
|
|
242
|
-
delegator_address: "cosmos1kky4yzth6gdrm8ga5zlfwhav33yr7hl87jycah",
|
|
243
|
-
validator_address: "cosmosvaloper1kn3wugetjuy4zetlq6wadchfhvu3x740ae6z6x",
|
|
244
|
-
},
|
|
245
|
-
},
|
|
246
|
-
{
|
|
247
|
-
type: "cosmos-sdk/MsgWithdrawDelegationReward",
|
|
248
|
-
value: {
|
|
249
|
-
delegator_address: "cosmos1kky4yzth6gdrm8ga5zlfwhav33yr7hl87jycah",
|
|
250
|
-
validator_address: "cosmosvaloper1sjllsnramtg3ewxqwwrwjxfgc4n4ef9u2lcnj0",
|
|
251
|
-
},
|
|
252
|
-
},
|
|
253
|
-
{
|
|
254
|
-
type: "cosmos-sdk/MsgWithdrawDelegationReward",
|
|
255
|
-
value: {
|
|
256
|
-
delegator_address: "cosmos1kky4yzth6gdrm8ga5zlfwhav33yr7hl87jycah",
|
|
257
|
-
validator_address: "cosmosvaloper1ey69r37gfxvxg62sh4r0ktpuc46pzjrm873ae8",
|
|
258
|
-
},
|
|
259
|
-
},
|
|
260
|
-
{
|
|
261
|
-
type: "cosmos-sdk/MsgWithdrawDelegationReward",
|
|
262
|
-
value: {
|
|
263
|
-
delegator_address: "cosmos1kky4yzth6gdrm8ga5zlfwhav33yr7hl87jycah",
|
|
264
|
-
validator_address: "cosmosvaloper1648ynlpdw7fqa2axt0w2yp3fk542junl7rsvq6",
|
|
265
|
-
},
|
|
266
|
-
},
|
|
267
|
-
],
|
|
268
|
-
sequence: "106",
|
|
269
|
-
};
|
|
270
|
-
|
|
271
|
-
const message = JSON.stringify(tx_str);
|
|
272
|
-
|
|
273
|
-
const responsePk = await app.publicKey(path);
|
|
274
|
-
const responseSign = await app.sign(path, message);
|
|
275
|
-
|
|
276
|
-
console.log(responsePk);
|
|
277
|
-
console.log(responseSign);
|
|
278
|
-
|
|
279
|
-
expect(responsePk.return_code).toEqual(ERROR_CODE.NoError);
|
|
280
|
-
expect(responsePk.error_message).toEqual("No errors");
|
|
281
|
-
expect(responseSign.return_code).toEqual(ERROR_CODE.NoError);
|
|
282
|
-
expect(responseSign.error_message).toEqual("No errors");
|
|
283
|
-
|
|
284
|
-
// Check signature is valid
|
|
285
|
-
const hash = crypto.createHash("sha256");
|
|
286
|
-
const msgHash = hash.update(message).digest();
|
|
287
|
-
|
|
288
|
-
const signatureDER = responseSign.signature;
|
|
289
|
-
const signature = secp256k1.signatureImport(signatureDER);
|
|
290
|
-
const signatureOk = secp256k1.verify(msgHash, signature, responsePk.compressed_pk);
|
|
291
|
-
expect(signatureOk).toEqual(true);
|
|
292
|
-
});
|
|
293
|
-
|
|
294
|
-
test("sign_big_tx", async () => {
|
|
295
|
-
jest.setTimeout(60000);
|
|
296
|
-
|
|
297
|
-
const transport = await TransportNodeHid.create(1000);
|
|
298
|
-
const app = new CosmosApp(transport);
|
|
299
|
-
|
|
300
|
-
const path = [44, 118, 0, 0, 0]; // Derivation path. First 3 items are automatically hardened!
|
|
301
|
-
const message =
|
|
302
|
-
'{"account_number":"108","chain_id":"cosmoshub-2",' +
|
|
303
|
-
'"fee":{"amount":[{"amount":"600","denom":"uatom"}],"gas":"200000"},"memo":"",' +
|
|
304
|
-
'"msgs":[{"type":"cosmos-sdk/MsgWithdrawDelegationReward","value":' +
|
|
305
|
-
'{"delegator_address":"cosmos14lultfckehtszvzw4ehu0apvsr77afvyhgqhwh","validator_address":' +
|
|
306
|
-
'"cosmosvaloper1qwl879nx9t6kef4supyazayf7vjhennyh568ys"}},{"type":"cosmos-sdk/MsgWithdrawDelegationReward",' +
|
|
307
|
-
'"value":{"delegator_address":"cosmos14lultfckehtszvzw4ehu0apvsr77afvyhgqhwh","validator_address":' +
|
|
308
|
-
'"cosmosvaloper1x88j7vp2xnw3zec8ur3g4waxycyz7m0mahdv3p"}},{"type":"cosmos-sdk/MsgWithdrawDelegationReward",' +
|
|
309
|
-
'"value":{"delegator_address":"cosmos14lultfckehtszvzw4ehu0apvsr77afvyhgqhwh","validator_address":' +
|
|
310
|
-
'"cosmosvaloper1grgelyng2v6v3t8z87wu3sxgt9m5s03xfytvz7"}},{"type":"cosmos-sdk/MsgWithdrawDelegationReward",' +
|
|
311
|
-
'"value":{"delegator_address":"cosmos14lultfckehtszvzw4ehu0apvsr77afvyhgqhwh","validator_address":' +
|
|
312
|
-
'"cosmosvaloper1ttfytaf43nkytzp8hkfjfgjc693ky4t3y2n2ku"}},{"type":"cosmos-sdk/MsgWithdrawDelegationReward",' +
|
|
313
|
-
'"value":{"delegator_address":"cosmos14lultfckehtszvzw4ehu0apvsr77afvyhgqhwh","validator_address":' +
|
|
314
|
-
'"cosmosvaloper1wdrypwex63geqswmcy5qynv4w3z3dyef2qmyna"}},{"type":"cosmos-sdk/MsgWithdrawDelegationReward",' +
|
|
315
|
-
'"value":{"delegator_address":"cosmos14lultfckehtszvzw4ehu0apvsr77afvyhgqhwh","validator_address":' +
|
|
316
|
-
'"cosmosvaloper102ruvpv2srmunfffxavttxnhezln6fnc54at8c"}},{"type":"cosmos-sdk/MsgWithdrawDelegationReward",' +
|
|
317
|
-
'"value":{"delegator_address":"cosmos14lultfckehtszvzw4ehu0apvsr77afvyhgqhwh","validator_address":' +
|
|
318
|
-
'"cosmosvaloper10e4vsut6suau8tk9m6dnrm0slgd6npe3jx5xpv"}},{"type":"cosmos-sdk/MsgWithdrawDelegationReward",' +
|
|
319
|
-
'"value":{"delegator_address":"cosmos14lultfckehtszvzw4ehu0apvsr77afvyhgqhwh","validator_address":' +
|
|
320
|
-
'"cosmosvaloper1sxx9mszve0gaedz5ld7qdkjkfv8z992ax69k08"}},{"type":"cosmos-sdk/MsgWithdrawDelegationReward",' +
|
|
321
|
-
'"value":{"delegator_address":"cosmos14lultfckehtszvzw4ehu0apvsr77afvyhgqhwh","validator_address":' +
|
|
322
|
-
'"cosmosvaloper1ssm0d433seakyak8kcf93yefhknjleeds4y3em"}},{"type":"cosmos-sdk/MsgWithdrawDelegationReward",' +
|
|
323
|
-
'"value":{"delegator_address":"cosmos14lultfckehtszvzw4ehu0apvsr77afvyhgqhwh","validator_address":' +
|
|
324
|
-
'"cosmosvaloper13sduv92y3xdhy3rpmhakrc3v7t37e7ps9l0kpv"}},{"type":"cosmos-sdk/MsgWithdrawDelegationReward",' +
|
|
325
|
-
'"value":{"delegator_address":"cosmos14lultfckehtszvzw4ehu0apvsr77afvyhgqhwh","validator_address":' +
|
|
326
|
-
'"cosmosvaloper15urq2dtp9qce4fyc85m6upwm9xul3049e02707"}},{"type":"cosmos-sdk/MsgWithdrawDelegationReward",' +
|
|
327
|
-
'"value":{"delegator_address":"cosmos14lultfckehtszvzw4ehu0apvsr77afvyhgqhwh","validator_address":' +
|
|
328
|
-
'"cosmosvaloper14kn0kk33szpwus9nh8n87fjel8djx0y070ymmj"}},{"type":"cosmos-sdk/MsgWithdrawDelegationReward",' +
|
|
329
|
-
'"value":{"delegator_address":"cosmos14lultfckehtszvzw4ehu0apvsr77afvyhgqhwh","validator_address":' +
|
|
330
|
-
'"cosmosvaloper14lultfckehtszvzw4ehu0apvsr77afvyju5zzy"}},{"type":"cosmos-sdk/MsgWithdrawDelegationReward",' +
|
|
331
|
-
'"value":{"delegator_address":"cosmos14lultfckehtszvzw4ehu0apvsr77afvyhgqhwh","validator_address":' +
|
|
332
|
-
'"cosmosvaloper1k9a0cs97vul8w2vwknlfmpez6prv8klv03lv3d"}},{"type":"cosmos-sdk/MsgWithdrawDelegationReward",' +
|
|
333
|
-
'"value":{"delegator_address":"cosmos14lultfckehtszvzw4ehu0apvsr77afvyhgqhwh","validator_address":' +
|
|
334
|
-
'"cosmosvaloper1kj0h4kn4z5xvedu2nd9c4a9a559wvpuvu0h6qn"}},{"type":"cosmos-sdk/MsgWithdrawDelegationReward",' +
|
|
335
|
-
'"value":{"delegator_address":"cosmos14lultfckehtszvzw4ehu0apvsr77afvyhgqhwh","validator_address":' +
|
|
336
|
-
'"cosmosvaloper1hjct6q7npsspsg3dgvzk3sdf89spmlpfdn6m9d"}}],"sequence":"106"}';
|
|
337
|
-
|
|
338
|
-
const responsePk = await app.publicKey(path);
|
|
339
|
-
const responseSign = await app.sign(path, message);
|
|
340
|
-
|
|
341
|
-
console.log(responsePk);
|
|
342
|
-
console.log(responseSign);
|
|
343
|
-
|
|
344
|
-
expect(responsePk.return_code).toEqual(ERROR_CODE.NoError);
|
|
345
|
-
expect(responsePk.error_message).toEqual("No errors");
|
|
346
|
-
|
|
347
|
-
switch (app.versionResponse.major) {
|
|
348
|
-
case 1:
|
|
349
|
-
expect(responseSign.return_code).toEqual(0x6a80);
|
|
350
|
-
expect(responseSign.error_message).toEqual(
|
|
351
|
-
"Bad key handle : NOMEM: JSON string contains too many tokens",
|
|
352
|
-
);
|
|
353
|
-
break;
|
|
354
|
-
case 2:
|
|
355
|
-
expect(responseSign.return_code).toEqual(0x6984);
|
|
356
|
-
expect(responseSign.error_message).toEqual("Data is invalid : JSON. Too many tokens");
|
|
357
|
-
break;
|
|
358
|
-
default:
|
|
359
|
-
expect.fail("Version not supported");
|
|
360
|
-
}
|
|
361
|
-
});
|
|
362
|
-
|
|
363
|
-
test("sign_invalid", async () => {
|
|
364
|
-
jest.setTimeout(60000);
|
|
365
|
-
|
|
366
|
-
const transport = await TransportNodeHid.create(1000);
|
|
367
|
-
const app = new CosmosApp(transport);
|
|
368
|
-
|
|
369
|
-
const path = [44, 118, 0, 0, 0]; // Derivation path. First 3 items are automatically hardened!
|
|
370
|
-
const invalidMessage =
|
|
371
|
-
'{"chain_id":"local-testnet","fee":{"amount":[],"gas":"500000"},"memo":"","msgs":[{"delegator_addr":"cosmos1qpd4xgtqmxyf9ktjh757nkdfnzpnkamny3cpzv","validator_addr":"cosmosvaloper1zyp0axz2t55lxkmgrvg4vpey2rf4ratcsud07t","value":{"amount":"1","denom":"stake"}}],"sequence":"0"}';
|
|
372
|
-
|
|
373
|
-
const responseSign = await app.sign(path, invalidMessage);
|
|
374
|
-
|
|
375
|
-
console.log(responseSign);
|
|
376
|
-
|
|
377
|
-
switch (app.versionResponse.major) {
|
|
378
|
-
case 1:
|
|
379
|
-
expect(responseSign.return_code).toEqual(0x6a80);
|
|
380
|
-
expect(responseSign.error_message).toEqual("Bad key handle : JSON Missing account_number");
|
|
381
|
-
break;
|
|
382
|
-
case 2:
|
|
383
|
-
expect(responseSign.return_code).toEqual(0x6984);
|
|
384
|
-
expect(responseSign.error_message).toEqual("Data is invalid : JSON Missing account number");
|
|
385
|
-
break;
|
|
386
|
-
default:
|
|
387
|
-
console.log("Version not supported");
|
|
388
|
-
expect(false).toEqual(true);
|
|
389
|
-
}
|
|
390
|
-
});
|
package/tests/basic.spec.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import CosmosApp from "index.js";
|
|
2
|
-
|
|
3
|
-
test("check address conversion", async () => {
|
|
4
|
-
const pkStr = "034fef9cd7c4c63588d3b03feb5281b9d232cba34d6f3d71aee59211ffbfe1fe87";
|
|
5
|
-
const pk = Buffer.from(pkStr, "hex");
|
|
6
|
-
const addr = CosmosApp.getBech32FromPK("cosmos", pk);
|
|
7
|
-
expect(addr).toEqual("cosmos1w34k53py5v5xyluazqpq65agyajavep2rflq6h");
|
|
8
|
-
});
|
package/tests/jest.js
DELETED
package/vue.config.js
DELETED
package/vue_example/App.vue
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div id="app">
|
|
3
|
-
<img alt="Zondax logo" src="./assets/logo.png" width="300" />
|
|
4
|
-
<h1>Cosmos integration example</h1>
|
|
5
|
-
<LedgerExample msg="Minimal integration example" />
|
|
6
|
-
</div>
|
|
7
|
-
</template>
|
|
8
|
-
|
|
9
|
-
<script>
|
|
10
|
-
import LedgerExample from "./components/LedgerExample.vue";
|
|
11
|
-
|
|
12
|
-
export default {
|
|
13
|
-
name: "App",
|
|
14
|
-
components: {
|
|
15
|
-
LedgerExample,
|
|
16
|
-
},
|
|
17
|
-
};
|
|
18
|
-
</script>
|
|
19
|
-
|
|
20
|
-
<style>
|
|
21
|
-
#app {
|
|
22
|
-
font-family: "Avenir", Helvetica, Arial, sans-serif;
|
|
23
|
-
-webkit-font-smoothing: antialiased;
|
|
24
|
-
-moz-osx-font-smoothing: grayscale;
|
|
25
|
-
text-align: center;
|
|
26
|
-
color: #2c3e50;
|
|
27
|
-
margin-top: 60px;
|
|
28
|
-
}
|
|
29
|
-
</style>
|
|
Binary file
|