@ledgerhq/hw-app-canton 0.6.0 → 0.7.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/CHANGELOG.md +6 -0
- package/README.md +3 -2
- package/lib/Canton.d.ts +51 -5
- package/lib/Canton.d.ts.map +1 -1
- package/lib/Canton.js +217 -38
- package/lib/Canton.js.map +1 -1
- package/lib-es/Canton.d.ts +51 -5
- package/lib-es/Canton.d.ts.map +1 -1
- package/lib-es/Canton.js +218 -39
- package/lib-es/Canton.js.map +1 -1
- package/package.json +5 -5
- package/src/Canton.test.ts +118 -39
- package/src/Canton.ts +306 -47
- package/lib/Canton.integ.test.d.ts +0 -2
- package/lib/Canton.integ.test.d.ts.map +0 -1
- package/lib/Canton.integ.test.js +0 -88
- package/lib/Canton.integ.test.js.map +0 -1
- package/lib/Canton.test.d.ts +0 -2
- package/lib/Canton.test.d.ts.map +0 -1
- package/lib/Canton.test.js +0 -127
- package/lib/Canton.test.js.map +0 -1
- package/lib-es/Canton.integ.test.d.ts +0 -2
- package/lib-es/Canton.integ.test.d.ts.map +0 -1
- package/lib-es/Canton.integ.test.js +0 -60
- package/lib-es/Canton.integ.test.js.map +0 -1
- package/lib-es/Canton.test.d.ts +0 -2
- package/lib-es/Canton.test.d.ts.map +0 -1
- package/lib-es/Canton.test.js +0 -122
- package/lib-es/Canton.test.js.map +0 -1
package/lib/Canton.test.js
DELETED
|
@@ -1,127 +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
|
-
const hw_transport_mocker_1 = require("@ledgerhq/hw-transport-mocker");
|
|
7
|
-
const Canton_1 = __importDefault(require("./Canton"));
|
|
8
|
-
describe("Canton", () => {
|
|
9
|
-
describe("decorateAppAPIMethods", () => {
|
|
10
|
-
it("should properly decorate transport methods", async () => {
|
|
11
|
-
// GIVEN
|
|
12
|
-
const transport = await (0, hw_transport_mocker_1.openTransportReplayer)(new hw_transport_mocker_1.RecordStore());
|
|
13
|
-
// WHEN
|
|
14
|
-
const canton = new Canton_1.default(transport);
|
|
15
|
-
// THEN
|
|
16
|
-
expect(canton.transport).toBeDefined();
|
|
17
|
-
expect(typeof canton.getAddress).toBe("function");
|
|
18
|
-
expect(typeof canton.signTransaction).toBe("function");
|
|
19
|
-
expect(typeof canton.getAppConfiguration).toBe("function");
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
describe("getAddress", () => {
|
|
23
|
-
it("should get address without display", async () => {
|
|
24
|
-
// GIVEN
|
|
25
|
-
const transport = await (0, hw_transport_mocker_1.openTransportReplayer)(hw_transport_mocker_1.RecordStore.fromString(`
|
|
26
|
-
=> e005000015058000002c80001a6f800000008000000080000000
|
|
27
|
-
<= 20c59f7f29374d24506dd6490a5db472cf00958e195e146f3dc9c97f96d5c5109720c59f7f29374d24506dd6490a5db472cf00958e195e146f3dc9c97f96d5c510979000
|
|
28
|
-
`));
|
|
29
|
-
const canton = new Canton_1.default(transport);
|
|
30
|
-
// WHEN
|
|
31
|
-
const result = await canton.getAddress("44'/6767'/0'/0'/0'");
|
|
32
|
-
// THEN
|
|
33
|
-
expect(result).toEqual({
|
|
34
|
-
address: "canton_402f2e68",
|
|
35
|
-
path: "44'/6767'/0'/0'/0'",
|
|
36
|
-
publicKey: "c59f7f29374d24506dd6490a5db472cf00958e195e146f3dc9c97f96d5c51097",
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
it("should get address with display", async () => {
|
|
40
|
-
// GIVEN
|
|
41
|
-
const transport = await (0, hw_transport_mocker_1.openTransportReplayer)(hw_transport_mocker_1.RecordStore.fromString(`
|
|
42
|
-
=> e005010015058000002c80001a6f800000008000000080000000
|
|
43
|
-
<= 20c59f7f29374d24506dd6490a5db472cf00958e195e146f3dc9c97f96d5c5109720c59f7f29374d24506dd6490a5db472cf00958e195e146f3dc9c97f96d5c510979000
|
|
44
|
-
`));
|
|
45
|
-
const canton = new Canton_1.default(transport);
|
|
46
|
-
// WHEN
|
|
47
|
-
const result = await canton.getAddress("44'/6767'/0'/0'/0'", true);
|
|
48
|
-
// THEN
|
|
49
|
-
expect(result).toEqual({
|
|
50
|
-
address: "canton_402f2e68",
|
|
51
|
-
path: "44'/6767'/0'/0'/0'",
|
|
52
|
-
publicKey: "c59f7f29374d24506dd6490a5db472cf00958e195e146f3dc9c97f96d5c51097",
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
it("should throw on invalid derivation path", async () => {
|
|
56
|
-
// GIVEN
|
|
57
|
-
const transport = await (0, hw_transport_mocker_1.openTransportReplayer)(new hw_transport_mocker_1.RecordStore());
|
|
58
|
-
const canton = new Canton_1.default(transport);
|
|
59
|
-
// WHEN & THEN
|
|
60
|
-
return expect(canton.getAddress("invalid path")).rejects.toThrow();
|
|
61
|
-
});
|
|
62
|
-
it("should handle various derivation paths", async () => {
|
|
63
|
-
// GIVEN
|
|
64
|
-
const transport = await (0, hw_transport_mocker_1.openTransportReplayer)(hw_transport_mocker_1.RecordStore.fromString(`
|
|
65
|
-
=> e005000015058000002c80001a6f800000008000000080000001
|
|
66
|
-
<= 205e66a10773c0860e73bb6015947806555765df5f9b5b4636df4255a57c57d702205e66a10773c0860e73bb6015947806555765df5f9b5b4636df4255a57c57d7029000
|
|
67
|
-
`));
|
|
68
|
-
const canton = new Canton_1.default(transport);
|
|
69
|
-
// WHEN
|
|
70
|
-
const result = await canton.getAddress("44'/6767'/0'/0'/1'");
|
|
71
|
-
// THEN
|
|
72
|
-
expect(result).toBeDefined();
|
|
73
|
-
expect(result.address).toBeDefined();
|
|
74
|
-
expect(result.publicKey).toBeDefined();
|
|
75
|
-
});
|
|
76
|
-
// should handle user refused address
|
|
77
|
-
});
|
|
78
|
-
describe("signTransaction", () => {
|
|
79
|
-
// should sign transaction
|
|
80
|
-
// should handle large transaction payloads
|
|
81
|
-
// should handle empty transaction
|
|
82
|
-
// should request blind signature when required
|
|
83
|
-
it("should sign transaction hash", async () => {
|
|
84
|
-
// GIVEN
|
|
85
|
-
const transport = await (0, hw_transport_mocker_1.openTransportReplayer)(hw_transport_mocker_1.RecordStore.fromString(`
|
|
86
|
-
=> e006000315058000002c80001a6f800000008000000080000000
|
|
87
|
-
<= 9000
|
|
88
|
-
=> e006000420d1e98829444207b0e170346b2e80b58a2ffc602b01e190fb742016d407c84efd
|
|
89
|
-
<= 40a65f53c3657bc04efefb67a425ba093a5cb5391d18142f148bb2c48daacf316114cff920a58d5996ca828c7ce265f537f1d7fca8fa82c3c73bd944a96e701a00009000
|
|
90
|
-
`));
|
|
91
|
-
const canton = new Canton_1.default(transport);
|
|
92
|
-
const txHash = "d1e98829444207b0e170346b2e80b58a2ffc602b01e190fb742016d407c84efd";
|
|
93
|
-
// WHEN
|
|
94
|
-
const result = await canton.signTransaction("44'/6767'/0'/0'/0'", txHash);
|
|
95
|
-
// THEN
|
|
96
|
-
expect(result).toEqual("a65f53c3657bc04efefb67a425ba093a5cb5391d18142f148bb2c48daacf316114cff920a58d5996ca828c7ce265f537f1d7fca8fa82c3c73bd944a96e701a00");
|
|
97
|
-
});
|
|
98
|
-
it("should handle user refused transaction", async () => {
|
|
99
|
-
// GIVEN
|
|
100
|
-
const transport = await (0, hw_transport_mocker_1.openTransportReplayer)(hw_transport_mocker_1.RecordStore.fromString(`
|
|
101
|
-
=> e006010015058000002c80001a6f800000008000000080000000
|
|
102
|
-
<= 6985
|
|
103
|
-
`));
|
|
104
|
-
const canton = new Canton_1.default(transport);
|
|
105
|
-
// WHEN & THEN
|
|
106
|
-
return expect(canton.signTransaction("44'/6767'/0'/0'/0'", "test")).rejects.toThrow();
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
describe("getAppConfiguration", () => {
|
|
110
|
-
it("should get app configuration", async () => {
|
|
111
|
-
// GIVEN
|
|
112
|
-
const transport = await (0, hw_transport_mocker_1.openTransportReplayer)(hw_transport_mocker_1.RecordStore.fromString(`
|
|
113
|
-
=> e003000000
|
|
114
|
-
<= 0202029000
|
|
115
|
-
`));
|
|
116
|
-
const canton = new Canton_1.default(transport);
|
|
117
|
-
// WHEN
|
|
118
|
-
const result = await canton.getAppConfiguration();
|
|
119
|
-
// THEN
|
|
120
|
-
expect(result).toEqual({
|
|
121
|
-
version: "2.2.2",
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
// should handle configuration error
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
//# sourceMappingURL=Canton.test.js.map
|
package/lib/Canton.test.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Canton.test.js","sourceRoot":"","sources":["../src/Canton.test.ts"],"names":[],"mappings":";;;;;AAAA,uEAAmF;AACnF,sDAA8B;AAE9B,QAAQ,CAAC,QAAQ,EAAE,GAAG,EAAE;IACtB,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE;QACrC,EAAE,CAAC,4CAA4C,EAAE,KAAK,IAAI,EAAE;YAC1D,QAAQ;YACR,MAAM,SAAS,GAAG,MAAM,IAAA,2CAAqB,EAAC,IAAI,iCAAW,EAAE,CAAC,CAAC;YAEjE,OAAO;YACP,MAAM,MAAM,GAAG,IAAI,gBAAM,CAAC,SAAS,CAAC,CAAC;YAErC,OAAO;YACP,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,CAAC;YACvC,MAAM,CAAC,OAAO,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YAClD,MAAM,CAAC,OAAO,MAAM,CAAC,eAAe,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YACvD,MAAM,CAAC,OAAO,MAAM,CAAC,mBAAmB,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC7D,CAAC,CAAC,CAAC;IAC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AC;YAE1E,OAAO;YACP,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CACpB,kIAAkI,CACnI,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,wCAAwC,EAAE,KAAK,IAAI,EAAE;YACtD,QAAQ;YACR,MAAM,SAAS,GAAG,MAAM,IAAA,2CAAqB,EAC3C,iCAAW,CAAC,UAAU,CAAC;;;SAGtB,CAAC,CACH,CAAC;YACF,MAAM,MAAM,GAAG,IAAI,gBAAM,CAAC,SAAS,CAAC,CAAC;YAErC,cAAc;YACd,OAAO,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,oBAAoB,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;QACxF,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;QACnC,EAAE,CAAC,8BAA8B,EAAE,KAAK,IAAI,EAAE;YAC5C,QAAQ;YACR,MAAM,SAAS,GAAG,MAAM,IAAA,2CAAqB,EAC3C,iCAAW,CAAC,UAAU,CAAC;;;SAGtB,CAAC,CACH,CAAC;YACF,MAAM,MAAM,GAAG,IAAI,gBAAM,CAAC,SAAS,CAAC,CAAC;YAErC,OAAO;YACP,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,mBAAmB,EAAE,CAAC;YAElD,OAAO;YACP,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC;gBACrB,OAAO,EAAE,OAAO;aACjB,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,oCAAoC;IACtC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Canton.integ.test.d.ts","sourceRoot":"","sources":["../src/Canton.integ.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import SpeculosTransportHttp, { SpeculosButton } from "@ledgerhq/hw-transport-node-speculos-http";
|
|
2
|
-
import Canton from "./Canton";
|
|
3
|
-
describe("AppCanton", () => {
|
|
4
|
-
let transport;
|
|
5
|
-
beforeAll(async () => {
|
|
6
|
-
transport = await SpeculosTransportHttp.open({});
|
|
7
|
-
});
|
|
8
|
-
afterAll(async () => {
|
|
9
|
-
transport.close();
|
|
10
|
-
});
|
|
11
|
-
describe("getAppConfiguration", () => {
|
|
12
|
-
it("returns app version", async () => {
|
|
13
|
-
// GIVEN
|
|
14
|
-
const app = new Canton(transport);
|
|
15
|
-
// WHEN
|
|
16
|
-
const result = await app.getAppConfiguration();
|
|
17
|
-
// THEN
|
|
18
|
-
expect(result).toEqual({
|
|
19
|
-
version: "2.2.2",
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
describe("getAddress", () => {
|
|
24
|
-
it("retrieves address from app", async () => {
|
|
25
|
-
// GIVEN
|
|
26
|
-
const app = new Canton(transport);
|
|
27
|
-
const derivationPath = "44'/6767'/0'/0'/0'";
|
|
28
|
-
// WHEN
|
|
29
|
-
const result = await app.getAddress(derivationPath);
|
|
30
|
-
// THEN
|
|
31
|
-
expect(result).toEqual({
|
|
32
|
-
address: "canton_1a7a97e0",
|
|
33
|
-
publicKey: "c59f7f29374d24506dd6490a5db472cf00958e195e146f3dc9c97f96d5c51097",
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
describe("signTransaction", () => {
|
|
38
|
-
it("returns sign transaction", async () => {
|
|
39
|
-
// GIVEN
|
|
40
|
-
const app = new Canton(transport);
|
|
41
|
-
const derivationPath = "44'/6767'/0'/0'/0'";
|
|
42
|
-
const txHash = "d1e98829444207b0e170346b2e80b58a2ffc602b01e190fb742016d407c84efd";
|
|
43
|
-
// WHEN
|
|
44
|
-
const signPromise = app.signTransaction(derivationPath, txHash);
|
|
45
|
-
// Waiting Speculos receive APDUs
|
|
46
|
-
const delay = (ms) => new Promise(f => setTimeout(f, ms));
|
|
47
|
-
await delay(500);
|
|
48
|
-
// Valid transaction butotn interaction sequence
|
|
49
|
-
await transport.button(SpeculosButton.BOTH);
|
|
50
|
-
await transport.button(SpeculosButton.RIGHT);
|
|
51
|
-
await transport.button(SpeculosButton.RIGHT);
|
|
52
|
-
await transport.button(SpeculosButton.RIGHT);
|
|
53
|
-
await transport.button(SpeculosButton.BOTH);
|
|
54
|
-
const result = await signPromise;
|
|
55
|
-
// THEN
|
|
56
|
-
expect(result).toEqual("40a65f53c3657bc04efefb67a425ba093a5cb5391d18142f148bb2c48daacf316114cff920a58d5996ca828c7ce265f537f1d7fca8fa82c3c73bd944a96e701a0000");
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
//# sourceMappingURL=Canton.integ.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Canton.integ.test.js","sourceRoot":"","sources":["../src/Canton.integ.test.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,EAAE,EAAE,cAAc,EAAE,MAAM,2CAA2C,CAAC;AAClG,OAAO,MAAM,MAAM,UAAU,CAAC;AAE9B,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;IACzB,IAAI,SAAgC,CAAC;IAErC,SAAS,CAAC,KAAK,IAAI,EAAE;QACnB,SAAS,GAAG,MAAM,qBAAqB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACnD,CAAC,CAAC,CAAC;IACH,QAAQ,CAAC,KAAK,IAAI,EAAE;QAClB,SAAS,CAAC,KAAK,EAAE,CAAC;IACpB,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;QACnC,EAAE,CAAC,qBAAqB,EAAE,KAAK,IAAI,EAAE;YACnC,QAAQ;YACR,MAAM,GAAG,GAAG,IAAI,MAAM,CAAC,SAAS,CAAC,CAAC;YAElC,OAAO;YACP,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,mBAAmB,EAAE,C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AI,CAAC,CAAC;YAC5C,MAAM,SAAS,CAAC,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;YAC7C,MAAM,SAAS,CAAC,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;YAC7C,MAAM,SAAS,CAAC,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;YAC7C,MAAM,SAAS,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;YAE5C,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC;YAEjC,OAAO;YACP,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CACpB,sIAAsI,CACvI,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/lib-es/Canton.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Canton.test.d.ts","sourceRoot":"","sources":["../src/Canton.test.ts"],"names":[],"mappings":""}
|
package/lib-es/Canton.test.js
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import { openTransportReplayer, RecordStore } from "@ledgerhq/hw-transport-mocker";
|
|
2
|
-
import Canton from "./Canton";
|
|
3
|
-
describe("Canton", () => {
|
|
4
|
-
describe("decorateAppAPIMethods", () => {
|
|
5
|
-
it("should properly decorate transport methods", async () => {
|
|
6
|
-
// GIVEN
|
|
7
|
-
const transport = await openTransportReplayer(new RecordStore());
|
|
8
|
-
// WHEN
|
|
9
|
-
const canton = new Canton(transport);
|
|
10
|
-
// THEN
|
|
11
|
-
expect(canton.transport).toBeDefined();
|
|
12
|
-
expect(typeof canton.getAddress).toBe("function");
|
|
13
|
-
expect(typeof canton.signTransaction).toBe("function");
|
|
14
|
-
expect(typeof canton.getAppConfiguration).toBe("function");
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
describe("getAddress", () => {
|
|
18
|
-
it("should get address without display", async () => {
|
|
19
|
-
// GIVEN
|
|
20
|
-
const transport = await openTransportReplayer(RecordStore.fromString(`
|
|
21
|
-
=> e005000015058000002c80001a6f800000008000000080000000
|
|
22
|
-
<= 20c59f7f29374d24506dd6490a5db472cf00958e195e146f3dc9c97f96d5c5109720c59f7f29374d24506dd6490a5db472cf00958e195e146f3dc9c97f96d5c510979000
|
|
23
|
-
`));
|
|
24
|
-
const canton = new Canton(transport);
|
|
25
|
-
// WHEN
|
|
26
|
-
const result = await canton.getAddress("44'/6767'/0'/0'/0'");
|
|
27
|
-
// THEN
|
|
28
|
-
expect(result).toEqual({
|
|
29
|
-
address: "canton_402f2e68",
|
|
30
|
-
path: "44'/6767'/0'/0'/0'",
|
|
31
|
-
publicKey: "c59f7f29374d24506dd6490a5db472cf00958e195e146f3dc9c97f96d5c51097",
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
it("should get address with display", async () => {
|
|
35
|
-
// GIVEN
|
|
36
|
-
const transport = await openTransportReplayer(RecordStore.fromString(`
|
|
37
|
-
=> e005010015058000002c80001a6f800000008000000080000000
|
|
38
|
-
<= 20c59f7f29374d24506dd6490a5db472cf00958e195e146f3dc9c97f96d5c5109720c59f7f29374d24506dd6490a5db472cf00958e195e146f3dc9c97f96d5c510979000
|
|
39
|
-
`));
|
|
40
|
-
const canton = new Canton(transport);
|
|
41
|
-
// WHEN
|
|
42
|
-
const result = await canton.getAddress("44'/6767'/0'/0'/0'", true);
|
|
43
|
-
// THEN
|
|
44
|
-
expect(result).toEqual({
|
|
45
|
-
address: "canton_402f2e68",
|
|
46
|
-
path: "44'/6767'/0'/0'/0'",
|
|
47
|
-
publicKey: "c59f7f29374d24506dd6490a5db472cf00958e195e146f3dc9c97f96d5c51097",
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
it("should throw on invalid derivation path", async () => {
|
|
51
|
-
// GIVEN
|
|
52
|
-
const transport = await openTransportReplayer(new RecordStore());
|
|
53
|
-
const canton = new Canton(transport);
|
|
54
|
-
// WHEN & THEN
|
|
55
|
-
return expect(canton.getAddress("invalid path")).rejects.toThrow();
|
|
56
|
-
});
|
|
57
|
-
it("should handle various derivation paths", async () => {
|
|
58
|
-
// GIVEN
|
|
59
|
-
const transport = await openTransportReplayer(RecordStore.fromString(`
|
|
60
|
-
=> e005000015058000002c80001a6f800000008000000080000001
|
|
61
|
-
<= 205e66a10773c0860e73bb6015947806555765df5f9b5b4636df4255a57c57d702205e66a10773c0860e73bb6015947806555765df5f9b5b4636df4255a57c57d7029000
|
|
62
|
-
`));
|
|
63
|
-
const canton = new Canton(transport);
|
|
64
|
-
// WHEN
|
|
65
|
-
const result = await canton.getAddress("44'/6767'/0'/0'/1'");
|
|
66
|
-
// THEN
|
|
67
|
-
expect(result).toBeDefined();
|
|
68
|
-
expect(result.address).toBeDefined();
|
|
69
|
-
expect(result.publicKey).toBeDefined();
|
|
70
|
-
});
|
|
71
|
-
// should handle user refused address
|
|
72
|
-
});
|
|
73
|
-
describe("signTransaction", () => {
|
|
74
|
-
// should sign transaction
|
|
75
|
-
// should handle large transaction payloads
|
|
76
|
-
// should handle empty transaction
|
|
77
|
-
// should request blind signature when required
|
|
78
|
-
it("should sign transaction hash", async () => {
|
|
79
|
-
// GIVEN
|
|
80
|
-
const transport = await openTransportReplayer(RecordStore.fromString(`
|
|
81
|
-
=> e006000315058000002c80001a6f800000008000000080000000
|
|
82
|
-
<= 9000
|
|
83
|
-
=> e006000420d1e98829444207b0e170346b2e80b58a2ffc602b01e190fb742016d407c84efd
|
|
84
|
-
<= 40a65f53c3657bc04efefb67a425ba093a5cb5391d18142f148bb2c48daacf316114cff920a58d5996ca828c7ce265f537f1d7fca8fa82c3c73bd944a96e701a00009000
|
|
85
|
-
`));
|
|
86
|
-
const canton = new Canton(transport);
|
|
87
|
-
const txHash = "d1e98829444207b0e170346b2e80b58a2ffc602b01e190fb742016d407c84efd";
|
|
88
|
-
// WHEN
|
|
89
|
-
const result = await canton.signTransaction("44'/6767'/0'/0'/0'", txHash);
|
|
90
|
-
// THEN
|
|
91
|
-
expect(result).toEqual("a65f53c3657bc04efefb67a425ba093a5cb5391d18142f148bb2c48daacf316114cff920a58d5996ca828c7ce265f537f1d7fca8fa82c3c73bd944a96e701a00");
|
|
92
|
-
});
|
|
93
|
-
it("should handle user refused transaction", async () => {
|
|
94
|
-
// GIVEN
|
|
95
|
-
const transport = await openTransportReplayer(RecordStore.fromString(`
|
|
96
|
-
=> e006010015058000002c80001a6f800000008000000080000000
|
|
97
|
-
<= 6985
|
|
98
|
-
`));
|
|
99
|
-
const canton = new Canton(transport);
|
|
100
|
-
// WHEN & THEN
|
|
101
|
-
return expect(canton.signTransaction("44'/6767'/0'/0'/0'", "test")).rejects.toThrow();
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
describe("getAppConfiguration", () => {
|
|
105
|
-
it("should get app configuration", async () => {
|
|
106
|
-
// GIVEN
|
|
107
|
-
const transport = await openTransportReplayer(RecordStore.fromString(`
|
|
108
|
-
=> e003000000
|
|
109
|
-
<= 0202029000
|
|
110
|
-
`));
|
|
111
|
-
const canton = new Canton(transport);
|
|
112
|
-
// WHEN
|
|
113
|
-
const result = await canton.getAppConfiguration();
|
|
114
|
-
// THEN
|
|
115
|
-
expect(result).toEqual({
|
|
116
|
-
version: "2.2.2",
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
// should handle configuration error
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
//# sourceMappingURL=Canton.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Canton.test.js","sourceRoot":"","sources":["../src/Canton.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AACnF,OAAO,MAAM,MAAM,UAAU,CAAC;AAE9B,QAAQ,CAAC,QAAQ,EAAE,GAAG,EAAE;IACtB,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE;QACrC,EAAE,CAAC,4CAA4C,EAAE,KAAK,I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