@ledgerhq/hw-app-canton 0.3.0-nightly.0 → 0.3.0-nightly.2
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/.turbo/turbo-build.log +1 -1
- package/.unimportedrc.json +1 -2
- package/CHANGELOG.md +13 -0
- package/README.md +3 -6
- package/lib/Canton.d.ts +10 -5
- package/lib/Canton.d.ts.map +1 -1
- package/lib/Canton.integ.test.js +49 -4
- package/lib/Canton.integ.test.js.map +1 -1
- package/lib/Canton.js +17 -13
- package/lib/Canton.js.map +1 -1
- package/lib/Canton.test.d.ts +2 -0
- package/lib/Canton.test.d.ts.map +1 -0
- package/lib/Canton.test.js +101 -0
- package/lib/Canton.test.js.map +1 -0
- package/lib-es/Canton.d.ts +10 -5
- package/lib-es/Canton.d.ts.map +1 -1
- package/lib-es/Canton.integ.test.js +26 -4
- package/lib-es/Canton.integ.test.js.map +1 -1
- package/lib-es/Canton.js +17 -13
- package/lib-es/Canton.js.map +1 -1
- package/lib-es/Canton.test.d.ts +2 -0
- package/lib-es/Canton.test.d.ts.map +1 -0
- package/lib-es/Canton.test.js +96 -0
- package/lib-es/Canton.test.js.map +1 -0
- package/package.json +3 -4
- package/src/Canton.integ.test.ts +33 -7
- package/{__tests__ → src}/Canton.test.ts +21 -1
- package/src/Canton.ts +42 -17
- package/lib/MockDevice.d.ts +0 -24
- package/lib/MockDevice.d.ts.map +0 -1
- package/lib/MockDevice.js +0 -141
- package/lib/MockDevice.js.map +0 -1
- package/lib-es/MockDevice.d.ts +0 -24
- package/lib-es/MockDevice.d.ts.map +0 -1
- package/lib-es/MockDevice.js +0 -137
- package/lib-es/MockDevice.js.map +0 -1
- package/src/MockDevice.ts +0 -170
package/lib-es/Canton.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Canton.js","sourceRoot":"","sources":["../src/Canton.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,mBA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E,UAAU,GAAG,CAAC,CAAC,CAAC;QAEhD,MAAM,aAAa,GAAG,QAAQ,CAC5B,IAAI,CAAC,QAAQ,CAAC,UAAU,GAAG,CAAC,EAAE,UAAU,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,EAC7D,EAAE,CACH,CAAC;QACF,MAAM,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC,UAAU,GAAG,CAAC,EAAE,UAAU,GAAG,aAAa,GAAG,CAAC,CAAC,CAAC;QAChF,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,EAAE,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;IAClF,CAAC;IAED;;;OAGG;IACK,cAAc,CAAC,IAAY;QACjC,OAAO;YACL,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC;YACxD,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC;YACxD,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC;SACzD,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Canton.test.d.ts","sourceRoot":"","sources":["../src/Canton.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,96 @@
|
|
|
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
|
+
const transport = await openTransportReplayer(new RecordStore());
|
|
7
|
+
const canton = new Canton(transport);
|
|
8
|
+
expect(canton.transport).toBeDefined();
|
|
9
|
+
expect(typeof canton.getAddress).toBe("function");
|
|
10
|
+
expect(typeof canton.signTransaction).toBe("function");
|
|
11
|
+
expect(typeof canton.getAppConfiguration).toBe("function");
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
describe("getAddress", () => {
|
|
15
|
+
it("should get address without display", async () => {
|
|
16
|
+
const transport = await openTransportReplayer(RecordStore.fromString(`
|
|
17
|
+
=> e005000015058000002c80001a6f800000008000000080000000
|
|
18
|
+
<= 4d65a10662b9759d62bb59048366705454654cf4f9b4b3525cf314429e46c6919000
|
|
19
|
+
`));
|
|
20
|
+
const canton = new Canton(transport);
|
|
21
|
+
const result = await canton.getAddress("44'/6767'/0'/0'/0'");
|
|
22
|
+
expect(result).toBeDefined();
|
|
23
|
+
expect(result.address).toBeDefined();
|
|
24
|
+
expect(result.publicKey).toBeDefined();
|
|
25
|
+
});
|
|
26
|
+
it("should get address with display", async () => {
|
|
27
|
+
const transport = await openTransportReplayer(RecordStore.fromString(`
|
|
28
|
+
=> e005010015058000002c80001a6f800000008000000080000000
|
|
29
|
+
<= 4d65a10662b9759d62bb59048366705454654cf4f9b4b3525cf314429e46c6919000
|
|
30
|
+
`));
|
|
31
|
+
const canton = new Canton(transport);
|
|
32
|
+
const result = await canton.getAddress("44'/6767'/0'/0'/0'", true);
|
|
33
|
+
expect(result).toBeDefined();
|
|
34
|
+
expect(result.address).toBeDefined();
|
|
35
|
+
expect(result.publicKey).toBeDefined();
|
|
36
|
+
});
|
|
37
|
+
it("should throw on invalid derivation path", async () => {
|
|
38
|
+
const transport = await openTransportReplayer(new RecordStore());
|
|
39
|
+
const canton = new Canton(transport);
|
|
40
|
+
return expect(canton.getAddress("invalid path")).rejects.toThrow();
|
|
41
|
+
});
|
|
42
|
+
it("should handle various derivation paths", async () => {
|
|
43
|
+
const transport = await openTransportReplayer(RecordStore.fromString(`
|
|
44
|
+
=> e005000015058000002c80001a6f800000008000000080000001
|
|
45
|
+
<= 5e66a10773c0860e73bb6015947806555765df5f9b5b4636df4255a57c57d7029000
|
|
46
|
+
`));
|
|
47
|
+
const canton = new Canton(transport);
|
|
48
|
+
const result = await canton.getAddress("44'/6767'/0'/0'/1'");
|
|
49
|
+
expect(result).toBeDefined();
|
|
50
|
+
expect(result.address).toBeDefined();
|
|
51
|
+
expect(result.publicKey).toBeDefined();
|
|
52
|
+
});
|
|
53
|
+
// should handle user refused address
|
|
54
|
+
});
|
|
55
|
+
describe("signTransaction", () => {
|
|
56
|
+
// should sign transaction
|
|
57
|
+
// should handle large transaction payloads
|
|
58
|
+
// should handle empty transaction
|
|
59
|
+
// should request blind signature when required
|
|
60
|
+
it("should sign transaction hash", async () => {
|
|
61
|
+
const transport = await openTransportReplayer(RecordStore.fromString(`
|
|
62
|
+
=> e006000315058000002c80001a6f800000008000000080000000
|
|
63
|
+
<= 9000
|
|
64
|
+
=> e006000020d1e98829444207b0e170346b2e80b58a2ffc602b01e190fb742016d407c84efd
|
|
65
|
+
<= 40a65f53c3657bc04efefb67a425ba093a5cb5391d18142f148bb2c48daacf316114cff920a58d5996ca828c7ce265f537f1d7fca8fa82c3c73bd944a96e701a00009000
|
|
66
|
+
`));
|
|
67
|
+
const canton = new Canton(transport);
|
|
68
|
+
const txHash = "d1e98829444207b0e170346b2e80b58a2ffc602b01e190fb742016d407c84efd";
|
|
69
|
+
const result = await canton.signTransaction("44'/6767'/0'/0'/0'", txHash);
|
|
70
|
+
expect(result).toEqual("40a65f53c3657bc04efefb67a425ba093a5cb5391d18142f148bb2c48daacf316114cff920a58d5996ca828c7ce265f537f1d7fca8fa82c3c73bd944a96e701a0000");
|
|
71
|
+
});
|
|
72
|
+
it("should handle user refused transaction", async () => {
|
|
73
|
+
const transport = await openTransportReplayer(RecordStore.fromString(`
|
|
74
|
+
=> e006010015058000002c80001a6f800000008000000080000000
|
|
75
|
+
<= 6985
|
|
76
|
+
`));
|
|
77
|
+
const canton = new Canton(transport);
|
|
78
|
+
return expect(canton.signTransaction("44'/6767'/0'/0'/0'", "test")).rejects.toThrow();
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
describe("getAppConfiguration", () => {
|
|
82
|
+
it("should get app configuration", async () => {
|
|
83
|
+
const transport = await openTransportReplayer(RecordStore.fromString(`
|
|
84
|
+
=> e003000000
|
|
85
|
+
<= 0202029000
|
|
86
|
+
`));
|
|
87
|
+
const canton = new Canton(transport);
|
|
88
|
+
const result = await canton.getAppConfiguration();
|
|
89
|
+
expect(result).toBeDefined();
|
|
90
|
+
expect(result).toHaveProperty("version");
|
|
91
|
+
expect(typeof result.version).toBe("string");
|
|
92
|
+
});
|
|
93
|
+
// should handle configuration error
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
//# sourceMappingURL=Canton.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,IAAI,EAAE;YAC1D,MAAM,SAAS,GAAG,MAAM,qBAAqB,CAAC,IAAI,WAAW,EAAE,CAAC,CAAC;YACjE,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,SAAS,CAAC,CAAC;YAErC,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,M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",
|
|
3
|
-
"version": "0.3.0-nightly.
|
|
3
|
+
"version": "0.3.0-nightly.2",
|
|
4
4
|
"description": "Ledger Hardware Wallet Canton Application API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ledger",
|
|
@@ -26,9 +26,8 @@
|
|
|
26
26
|
"license": "Apache-2.0",
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"bip32-path": "^0.4.2",
|
|
29
|
-
"@ledgerhq/errors": "^6.25.0-nightly.0",
|
|
30
29
|
"@ledgerhq/hw-transport": "^6.31.10-nightly.0",
|
|
31
|
-
"@ledgerhq/
|
|
30
|
+
"@ledgerhq/errors": "^6.25.0-nightly.0"
|
|
32
31
|
},
|
|
33
32
|
"devDependencies": {
|
|
34
33
|
"@types/jest": "^29.5.10",
|
|
@@ -40,7 +39,7 @@
|
|
|
40
39
|
"ts-jest": "^29.1.1",
|
|
41
40
|
"ts-node": "^10.4.0",
|
|
42
41
|
"@ledgerhq/hw-transport-mocker": "^6.29.10-nightly.0",
|
|
43
|
-
"@ledgerhq/hw-transport-node-speculos-http": "^6.
|
|
42
|
+
"@ledgerhq/hw-transport-node-speculos-http": "^6.30.0-nightly.1"
|
|
44
43
|
},
|
|
45
44
|
"scripts": {
|
|
46
45
|
"clean": "rimraf lib lib-es",
|
package/src/Canton.integ.test.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import SpeculosTransportHttp from "@ledgerhq/hw-transport-node-speculos-http";
|
|
1
|
+
import SpeculosTransportHttp, { SpeculosButton } from "@ledgerhq/hw-transport-node-speculos-http";
|
|
2
2
|
import Canton from "./Canton";
|
|
3
|
-
import Transport from "@ledgerhq/hw-transport";
|
|
4
3
|
|
|
5
4
|
describe("AppCanton", () => {
|
|
6
|
-
let transport:
|
|
5
|
+
let transport: SpeculosTransportHttp;
|
|
7
6
|
|
|
8
7
|
beforeAll(async () => {
|
|
9
8
|
transport = await SpeculosTransportHttp.open({});
|
|
10
9
|
});
|
|
10
|
+
afterAll(async () => {
|
|
11
|
+
transport.close();
|
|
12
|
+
});
|
|
11
13
|
|
|
12
14
|
describe("getAppConfiguration", () => {
|
|
13
15
|
it("returns app version", async () => {
|
|
@@ -35,14 +37,38 @@ describe("AppCanton", () => {
|
|
|
35
37
|
|
|
36
38
|
// THEN
|
|
37
39
|
expect(result).toEqual({
|
|
38
|
-
address: "
|
|
39
|
-
publicKey:
|
|
40
|
-
"0x043b462de34ec31fba274f2a381947aef26697912194312fc289c46cc1b2b4f6b00828dc1e4f96001b10463083edf85f2e0550862a3dc99ed411ca6d25f2bc19a8",
|
|
40
|
+
address: "canton_1a7a97e0",
|
|
41
|
+
publicKey: "c59f7f29374d24506dd6490a5db472cf00958e195e146f3dc9c97f96d5c51097",
|
|
41
42
|
});
|
|
42
43
|
});
|
|
43
44
|
});
|
|
44
45
|
|
|
45
46
|
describe("signTransaction", () => {
|
|
46
|
-
it
|
|
47
|
+
it("returns sign transaction", async () => {
|
|
48
|
+
// GIVEN
|
|
49
|
+
const app = new Canton(transport);
|
|
50
|
+
const derivationPath = "44'/6767'/0'/0'/0'";
|
|
51
|
+
const txHash = "d1e98829444207b0e170346b2e80b58a2ffc602b01e190fb742016d407c84efd";
|
|
52
|
+
|
|
53
|
+
// WHEN
|
|
54
|
+
const signPromise = app.signTransaction(derivationPath, txHash);
|
|
55
|
+
|
|
56
|
+
// Waiting Speculos receive APDUs
|
|
57
|
+
const delay = (ms: number): Promise<void> => new Promise(f => setTimeout(f, ms));
|
|
58
|
+
await delay(500);
|
|
59
|
+
// Valid transaction butotn interaction sequence
|
|
60
|
+
await transport.button(SpeculosButton.BOTH);
|
|
61
|
+
await transport.button(SpeculosButton.RIGHT);
|
|
62
|
+
await transport.button(SpeculosButton.RIGHT);
|
|
63
|
+
await transport.button(SpeculosButton.RIGHT);
|
|
64
|
+
await transport.button(SpeculosButton.BOTH);
|
|
65
|
+
|
|
66
|
+
const result = await signPromise;
|
|
67
|
+
|
|
68
|
+
// THEN
|
|
69
|
+
expect(result).toEqual(
|
|
70
|
+
"40a65f53c3657bc04efefb67a425ba093a5cb5391d18142f148bb2c48daacf316114cff920a58d5996ca828c7ce265f537f1d7fca8fa82c3c73bd944a96e701a0000",
|
|
71
|
+
);
|
|
72
|
+
});
|
|
47
73
|
});
|
|
48
74
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { openTransportReplayer, RecordStore } from "@ledgerhq/hw-transport-mocker";
|
|
2
|
-
import Canton from "
|
|
2
|
+
import Canton from "./Canton";
|
|
3
3
|
|
|
4
4
|
describe("Canton", () => {
|
|
5
5
|
describe("decorateAppAPIMethods", () => {
|
|
@@ -82,6 +82,26 @@ describe("Canton", () => {
|
|
|
82
82
|
|
|
83
83
|
// should request blind signature when required
|
|
84
84
|
|
|
85
|
+
it("should sign transaction hash", async () => {
|
|
86
|
+
const transport = await openTransportReplayer(
|
|
87
|
+
RecordStore.fromString(`
|
|
88
|
+
=> e006000315058000002c80001a6f800000008000000080000000
|
|
89
|
+
<= 9000
|
|
90
|
+
=> e006000020d1e98829444207b0e170346b2e80b58a2ffc602b01e190fb742016d407c84efd
|
|
91
|
+
<= 40a65f53c3657bc04efefb67a425ba093a5cb5391d18142f148bb2c48daacf316114cff920a58d5996ca828c7ce265f537f1d7fca8fa82c3c73bd944a96e701a00009000
|
|
92
|
+
`),
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
const canton = new Canton(transport);
|
|
96
|
+
const txHash = "d1e98829444207b0e170346b2e80b58a2ffc602b01e190fb742016d407c84efd";
|
|
97
|
+
|
|
98
|
+
const result = await canton.signTransaction("44'/6767'/0'/0'/0'", txHash);
|
|
99
|
+
|
|
100
|
+
expect(result).toEqual(
|
|
101
|
+
"40a65f53c3657bc04efefb67a425ba093a5cb5391d18142f148bb2c48daacf316114cff920a58d5996ca828c7ce265f537f1d7fca8fa82c3c73bd944a96e701a0000",
|
|
102
|
+
);
|
|
103
|
+
});
|
|
104
|
+
|
|
85
105
|
it("should handle user refused transaction", async () => {
|
|
86
106
|
const transport = await openTransportReplayer(
|
|
87
107
|
RecordStore.fromString(`
|
package/src/Canton.ts
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import type Transport from "@ledgerhq/hw-transport";
|
|
2
2
|
import { UserRefusedAddress, UserRefusedOnDevice } from "@ledgerhq/errors";
|
|
3
|
-
import { CantonAddress, CantonSignature } from "@ledgerhq/coin-canton";
|
|
4
3
|
import BIPPath from "bip32-path";
|
|
5
4
|
|
|
6
|
-
import { MockCantonDevice, AppConfig } from "./MockDevice";
|
|
7
|
-
|
|
8
5
|
const CLA = 0xe0;
|
|
9
6
|
|
|
10
7
|
const P1_NON_CONFIRM = 0x00;
|
|
11
8
|
const P1_CONFIRM = 0x01;
|
|
12
9
|
|
|
13
|
-
|
|
10
|
+
// P2 indicating no information.
|
|
11
|
+
const P2_NONE = 0x00;
|
|
12
|
+
// P2 indicating first APDU in a large request.
|
|
13
|
+
const P2_FIRST = 0x01;
|
|
14
|
+
// P2 indicating that this is not the last APDU in a large request.
|
|
15
|
+
const P2_MORE = 0x02;
|
|
14
16
|
|
|
15
17
|
const INS = {
|
|
16
18
|
GET_VERSION: 0x03,
|
|
@@ -24,16 +26,25 @@ const STATUS = {
|
|
|
24
26
|
USER_CANCEL: 0x6985,
|
|
25
27
|
};
|
|
26
28
|
|
|
29
|
+
export type AppConfig = {
|
|
30
|
+
version: string;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export type CantonAddress = {
|
|
34
|
+
publicKey: string;
|
|
35
|
+
address: string;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export type CantonSignature = string;
|
|
39
|
+
|
|
27
40
|
/**
|
|
28
41
|
* Canton BOLOS API
|
|
29
42
|
*/
|
|
30
43
|
export default class Canton {
|
|
31
44
|
transport: Transport;
|
|
32
|
-
transportMock: MockCantonDevice;
|
|
33
45
|
|
|
34
46
|
constructor(transport: Transport, scrambleKey = "canton_default_scramble_key") {
|
|
35
47
|
this.transport = transport;
|
|
36
|
-
this.transportMock = new MockCantonDevice();
|
|
37
48
|
|
|
38
49
|
transport.decorateAppAPIMethods(
|
|
39
50
|
this,
|
|
@@ -54,19 +65,17 @@ export default class Canton {
|
|
|
54
65
|
const serializedPath = this.serializePath(bipPath);
|
|
55
66
|
|
|
56
67
|
const p1 = display ? P1_CONFIRM : P1_NON_CONFIRM;
|
|
57
|
-
const response = await this.transport.send(CLA, INS.GET_ADDR, p1,
|
|
68
|
+
const response = await this.transport.send(CLA, INS.GET_ADDR, p1, P2_NONE, serializedPath);
|
|
58
69
|
|
|
59
70
|
const responseData = this.handleTransportResponse(response, "address");
|
|
60
71
|
const { pubKey } = this.extractPubkeyAndChainCode(responseData);
|
|
61
72
|
|
|
62
|
-
// Handle 65-byte uncompressed SECP256R1 public key
|
|
63
73
|
const publicKey = "0x" + pubKey;
|
|
64
|
-
|
|
65
74
|
const addressHash = this.hashString(publicKey);
|
|
66
75
|
const address = "canton_" + addressHash.substring(0, 36);
|
|
67
76
|
|
|
68
77
|
return {
|
|
69
|
-
publicKey,
|
|
78
|
+
publicKey: pubKey,
|
|
70
79
|
address,
|
|
71
80
|
};
|
|
72
81
|
}
|
|
@@ -75,19 +84,35 @@ export default class Canton {
|
|
|
75
84
|
* Sign a Canton transaction.
|
|
76
85
|
*
|
|
77
86
|
* @param path a path in BIP-32 format
|
|
78
|
-
* @param
|
|
87
|
+
* @param txHash the transaction hash to sign
|
|
79
88
|
* @return the signature
|
|
80
89
|
*/
|
|
81
|
-
async signTransaction(path: string,
|
|
90
|
+
async signTransaction(path: string, txHash: string): Promise<CantonSignature> {
|
|
91
|
+
// 1. Send the derivation path
|
|
82
92
|
const bipPath = BIPPath.fromString(path).toPathArray();
|
|
83
93
|
const serializedPath = this.serializePath(bipPath);
|
|
84
|
-
const payload = Buffer.concat([serializedPath, Buffer.from(rawTx, "hex")]);
|
|
85
94
|
|
|
86
|
-
const
|
|
95
|
+
const pathResponse = await this.transport.send(
|
|
96
|
+
CLA,
|
|
97
|
+
INS.SIGN,
|
|
98
|
+
P1_NON_CONFIRM,
|
|
99
|
+
P2_FIRST | P2_MORE,
|
|
100
|
+
serializedPath,
|
|
101
|
+
);
|
|
87
102
|
|
|
88
|
-
|
|
103
|
+
this.handleTransportResponse(pathResponse, "transaction");
|
|
104
|
+
|
|
105
|
+
// 2. Send the transaction hash
|
|
106
|
+
const response = await this.transport.send(
|
|
107
|
+
CLA,
|
|
108
|
+
INS.SIGN,
|
|
109
|
+
P1_NON_CONFIRM,
|
|
110
|
+
P2_NONE,
|
|
111
|
+
Buffer.from(txHash, "hex"),
|
|
112
|
+
);
|
|
89
113
|
|
|
90
|
-
const
|
|
114
|
+
const responseData = this.handleTransportResponse(response, "transaction");
|
|
115
|
+
const signature = responseData.toString("hex");
|
|
91
116
|
return signature;
|
|
92
117
|
}
|
|
93
118
|
|
|
@@ -100,7 +125,7 @@ export default class Canton {
|
|
|
100
125
|
CLA,
|
|
101
126
|
INS.GET_VERSION,
|
|
102
127
|
P1_NON_CONFIRM,
|
|
103
|
-
|
|
128
|
+
P2_NONE,
|
|
104
129
|
Buffer.alloc(0),
|
|
105
130
|
);
|
|
106
131
|
|
package/lib/MockDevice.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
export type AppConfig = {
|
|
4
|
-
version: string;
|
|
5
|
-
};
|
|
6
|
-
/**
|
|
7
|
-
* Mock Canton "@ledgerhq/hw-app-canton" device implementation for development and testing
|
|
8
|
-
*/
|
|
9
|
-
export declare class MockCantonDevice {
|
|
10
|
-
private mockAddresses;
|
|
11
|
-
private mockSignatures;
|
|
12
|
-
constructor();
|
|
13
|
-
send(cla: number, ins: number, p1: number, p2: number, data: Buffer): Promise<Buffer>;
|
|
14
|
-
private getAddressResponse;
|
|
15
|
-
private signTransactionResponse;
|
|
16
|
-
private getAppConfigurationResponse;
|
|
17
|
-
private parsePathFromData;
|
|
18
|
-
private simulateDeviceDelay;
|
|
19
|
-
/**
|
|
20
|
-
* Simple deterministic hash function for generating mock data
|
|
21
|
-
*/
|
|
22
|
-
private hashString;
|
|
23
|
-
}
|
|
24
|
-
//# sourceMappingURL=MockDevice.d.ts.map
|
package/lib/MockDevice.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MockDevice.d.ts","sourceRoot":"","sources":["../src/MockDevice.ts"],"names":[],"mappings":";;AAaA,MAAM,MAAM,SAAS,GAAG;IACtB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAsBF;;GAEG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,aAAa,CAAyC;IAC9D,OAAO,CAAC,cAAc,CAA2C;;IAS3D,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;YAa7E,kBAAkB;YAiClB,uBAAuB;YA0BvB,2BAA2B;IAYzC,OAAO,CAAC,iBAAiB;YAkBX,mBAAmB;IAIjC;;OAEG;IACH,OAAO,CAAC,UAAU;CASnB"}
|
package/lib/MockDevice.js
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MockCantonDevice = void 0;
|
|
4
|
-
const INS = {
|
|
5
|
-
GET_VERSION: 0x04,
|
|
6
|
-
GET_ADDR: 0x05,
|
|
7
|
-
SIGN: 0x06,
|
|
8
|
-
};
|
|
9
|
-
const STATUS = {
|
|
10
|
-
OK: 0x9000,
|
|
11
|
-
USER_CANCEL: 0x6985,
|
|
12
|
-
};
|
|
13
|
-
// SECP256R1-compatible mock addresses
|
|
14
|
-
const SECP256R1_MOCK_ADDRESSES = {
|
|
15
|
-
"44'/6767'/0'/0'/0'": {
|
|
16
|
-
// Uncompressed SECP256R1 public key (65 bytes: 0x04 + 32-byte X + 32-byte Y)
|
|
17
|
-
publicKey: "0x04" +
|
|
18
|
-
"1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef" +
|
|
19
|
-
"abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890",
|
|
20
|
-
address: "canton_1a2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p7q8r9s0t1u2v3w4x5y6z",
|
|
21
|
-
},
|
|
22
|
-
"44'/6767'/0'/0'/1'": {
|
|
23
|
-
// Another valid SECP256R1 public key
|
|
24
|
-
publicKey: "0x04" +
|
|
25
|
-
"abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890" +
|
|
26
|
-
"1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcd",
|
|
27
|
-
address: "canton_2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p7q8r9s0t1u2v3w4x5y6z7a",
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
/**
|
|
31
|
-
* Mock Canton "@ledgerhq/hw-app-canton" device implementation for development and testing
|
|
32
|
-
*/
|
|
33
|
-
class MockCantonDevice {
|
|
34
|
-
mockAddresses = new Map();
|
|
35
|
-
mockSignatures = new Map();
|
|
36
|
-
constructor() {
|
|
37
|
-
// Initialize with SECP256R1-compatible addresses
|
|
38
|
-
Object.entries(SECP256R1_MOCK_ADDRESSES).forEach(([path, address]) => {
|
|
39
|
-
this.mockAddresses.set(path, address);
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
async send(cla, ins, p1, p2, data) {
|
|
43
|
-
switch (ins) {
|
|
44
|
-
case INS.GET_ADDR:
|
|
45
|
-
return this.getAddressResponse(data);
|
|
46
|
-
case INS.SIGN:
|
|
47
|
-
return this.signTransactionResponse(data);
|
|
48
|
-
case INS.GET_VERSION:
|
|
49
|
-
return this.getAppConfigurationResponse();
|
|
50
|
-
default:
|
|
51
|
-
throw new Error(`Unsupported instruction: ${ins}`);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
async getAddressResponse(data) {
|
|
55
|
-
await this.simulateDeviceDelay();
|
|
56
|
-
// Parse the path from the data
|
|
57
|
-
const pathData = data.slice(1); // Skip length byte
|
|
58
|
-
const path = this.parsePathFromData(pathData);
|
|
59
|
-
const mockAddress = this.mockAddresses.get(path);
|
|
60
|
-
if (!mockAddress) {
|
|
61
|
-
// Generate SECP256R1-compatible mock address
|
|
62
|
-
const pathHash = this.hashString(path);
|
|
63
|
-
const newAddress = {
|
|
64
|
-
// Create valid uncompressed SECP256R1 public key format
|
|
65
|
-
publicKey: "0x04" +
|
|
66
|
-
pathHash.substring(0, 64).padEnd(64, "0") +
|
|
67
|
-
pathHash.substring(64, 128).padEnd(64, "0"),
|
|
68
|
-
address: `canton_${pathHash.substring(0, 36)}`,
|
|
69
|
-
};
|
|
70
|
-
this.mockAddresses.set(path, newAddress);
|
|
71
|
-
}
|
|
72
|
-
const address = this.mockAddresses.get(path);
|
|
73
|
-
// Return 65-byte uncompressed public key (0x04 + 32-byte X + 32-byte Y)
|
|
74
|
-
const publicKeyBytes = Buffer.from(address.publicKey.slice(2), "hex");
|
|
75
|
-
const response = Buffer.alloc(65 + 2);
|
|
76
|
-
publicKeyBytes.copy(response, 0);
|
|
77
|
-
response.writeUInt16BE(STATUS.OK, 65);
|
|
78
|
-
return response;
|
|
79
|
-
}
|
|
80
|
-
async signTransactionResponse(data) {
|
|
81
|
-
await this.simulateDeviceDelay();
|
|
82
|
-
// Parse the path and transaction from the data
|
|
83
|
-
const pathData = data.slice(0, 21); // First 21 bytes are path
|
|
84
|
-
const txData = data.slice(21); // Rest is transaction data
|
|
85
|
-
const path = this.parsePathFromData(pathData);
|
|
86
|
-
const signatureKey = `${path}:${txData.toString("hex")}`;
|
|
87
|
-
let signature = this.mockSignatures.get(signatureKey);
|
|
88
|
-
if (!signature) {
|
|
89
|
-
// Generate SECP256R1-compatible mock signature (64 bytes: r + s)
|
|
90
|
-
const combinedHash = this.hashString(signatureKey);
|
|
91
|
-
signature = `0x${combinedHash.substring(0, 64).padEnd(64, "0")}`;
|
|
92
|
-
this.mockSignatures.set(signatureKey, signature);
|
|
93
|
-
}
|
|
94
|
-
// Return 64-byte signature (r + s components)
|
|
95
|
-
const response = Buffer.alloc(64 + 2);
|
|
96
|
-
Buffer.from(signature.slice(2), "hex").copy(response, 0); // Remove '0x' prefix
|
|
97
|
-
response.writeUInt16BE(STATUS.OK, 64);
|
|
98
|
-
return response;
|
|
99
|
-
}
|
|
100
|
-
async getAppConfigurationResponse() {
|
|
101
|
-
await this.simulateDeviceDelay();
|
|
102
|
-
// Create response buffer: version data + status code
|
|
103
|
-
const versionData = Buffer.from([0x00, 0x01, 0x00, 0x06]); // Version 0.1.0
|
|
104
|
-
const response = Buffer.alloc(versionData.length + 2);
|
|
105
|
-
versionData.copy(response, 0);
|
|
106
|
-
response.writeUInt16BE(STATUS.OK, versionData.length);
|
|
107
|
-
return response;
|
|
108
|
-
}
|
|
109
|
-
parsePathFromData(data) {
|
|
110
|
-
// Convert the path data back to a BIP32 path string
|
|
111
|
-
const segments = [];
|
|
112
|
-
for (let i = 0; i < data.length; i += 4) {
|
|
113
|
-
const segment = data.readUInt32BE(i);
|
|
114
|
-
segments.push(segment);
|
|
115
|
-
}
|
|
116
|
-
// Convert to BIP32 path string
|
|
117
|
-
const pathParts = segments.map(seg => {
|
|
118
|
-
const isHardened = (seg & 0x80000000) !== 0;
|
|
119
|
-
const value = seg & 0x7fffffff;
|
|
120
|
-
return isHardened ? `${value}'` : `${value}`;
|
|
121
|
-
});
|
|
122
|
-
return pathParts.join("/");
|
|
123
|
-
}
|
|
124
|
-
async simulateDeviceDelay() {
|
|
125
|
-
await new Promise(resolve => setTimeout(resolve, 50));
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Simple deterministic hash function for generating mock data
|
|
129
|
-
*/
|
|
130
|
-
hashString(str) {
|
|
131
|
-
let hash = 0;
|
|
132
|
-
for (let i = 0; i < str.length; i++) {
|
|
133
|
-
const char = str.charCodeAt(i);
|
|
134
|
-
hash = (hash << 5) - hash + char;
|
|
135
|
-
hash = hash & hash; // Convert to 32-bit integer
|
|
136
|
-
}
|
|
137
|
-
return Math.abs(hash).toString(16);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
exports.MockCantonDevice = MockCantonDevice;
|
|
141
|
-
//# sourceMappingURL=MockDevice.js.map
|
package/lib/MockDevice.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MockDevice.js","sourceRoot":"","sources":["../src/MockDevice.ts"],"names":[],"mappings":";;;AAEA,MAAM,GAAG,GAAG;IACV,WAAW,EAAE,IAAI;IACjB,QAAQ,EAAE,IAAI;IACd,IAAI,EAAE,IAAI;CACX,CAAC;AAEF,MAAM,MAAM,GAAG;IACb,EAAE,EAAE,MAAM;IACV,WAAW,EAAE,MAAM;CACpB,CAAC;AAMF,sCAAsC;AACtC,MAAM,wBAAwB,GAAG;IAC/B,oBAAoB,EAAE;QACpB,6EAA6E;QAC7E,SAAS,EACP,MAAM;YACN,kEAAkE;YAClE,kEAAkE;QACpE,OAAO,EAAE,6DAA6D;KACvE;IACD,oBAAoB,EAAE;QACpB,qCAAqC;QACrC,SAAS,EACP,MAAM;YACN,kEAAkE;YAClE,gEAAgE;QAClE,OAAO,EAAE,6DAA6D;KACvE;CACF,CAAC;AAEF;;GAEG;AACH,MAAa,gBAAgB;IACnB,aAAa,GAA+B,IAAI,GAAG,EAAE,CAAC;IACtD,cAAc,GAAiC,IAAI,GAAG,EAAE,CAAC;IAEjE;QACE,iDAAiD;QACjD,MAAM,CAAC,OAAO,CAAC,wBAAwB,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,EAAE;YACnE,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACxC,CAAC,CAAC,CAAC;IACL,CAAC;IAED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/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
export type AppConfig = {
|
|
4
|
-
version: string;
|
|
5
|
-
};
|
|
6
|
-
/**
|
|
7
|
-
* Mock Canton "@ledgerhq/hw-app-canton" device implementation for development and testing
|
|
8
|
-
*/
|
|
9
|
-
export declare class MockCantonDevice {
|
|
10
|
-
private mockAddresses;
|
|
11
|
-
private mockSignatures;
|
|
12
|
-
constructor();
|
|
13
|
-
send(cla: number, ins: number, p1: number, p2: number, data: Buffer): Promise<Buffer>;
|
|
14
|
-
private getAddressResponse;
|
|
15
|
-
private signTransactionResponse;
|
|
16
|
-
private getAppConfigurationResponse;
|
|
17
|
-
private parsePathFromData;
|
|
18
|
-
private simulateDeviceDelay;
|
|
19
|
-
/**
|
|
20
|
-
* Simple deterministic hash function for generating mock data
|
|
21
|
-
*/
|
|
22
|
-
private hashString;
|
|
23
|
-
}
|
|
24
|
-
//# sourceMappingURL=MockDevice.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MockDevice.d.ts","sourceRoot":"","sources":["../src/MockDevice.ts"],"names":[],"mappings":";;AAaA,MAAM,MAAM,SAAS,GAAG;IACtB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAsBF;;GAEG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,aAAa,CAAyC;IAC9D,OAAO,CAAC,cAAc,CAA2C;;IAS3D,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;YAa7E,kBAAkB;YAiClB,uBAAuB;YA0BvB,2BAA2B;IAYzC,OAAO,CAAC,iBAAiB;YAkBX,mBAAmB;IAIjC;;OAEG;IACH,OAAO,CAAC,UAAU;CASnB"}
|