@ledgerhq/hw-app-canton 0.3.0 → 0.3.1-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/.unimportedrc.json +1 -2
- package/CHANGELOG.md +6 -0
- package/README.md +3 -6
- package/lib/Canton.d.ts +16 -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 +56 -20
- 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 +126 -0
- package/lib/Canton.test.js.map +1 -0
- package/lib-es/Canton.d.ts +16 -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 +56 -20
- 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 +121 -0
- package/lib-es/Canton.test.js.map +1 -0
- package/package.json +2 -3
- package/src/Canton.integ.test.ts +33 -7
- package/{__tests__ → src}/Canton.test.ts +63 -19
- package/src/Canton.ts +90 -26
- 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/.unimportedrc.json
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @ledgerhq/hw-app-canton
|
|
2
2
|
|
|
3
|
+
## 0.3.1-nightly.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#11722](https://github.com/LedgerHQ/ledger-live/pull/11722) [`a87922d`](https://github.com/LedgerHQ/ledger-live/commit/a87922dc99e4f2e4b40a46fd52ad08a71012fe94) Thanks [@hedi-edelbloute](https://github.com/hedi-edelbloute)! - Add canton onboard ui flow
|
|
8
|
+
|
|
3
9
|
## 0.3.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -32,7 +32,6 @@ For a smooth and quick integration:
|
|
|
32
32
|
* [signTransaction](#signtransaction)
|
|
33
33
|
* [Parameters](#parameters-2)
|
|
34
34
|
* [getAppConfiguration](#getappconfiguration)
|
|
35
|
-
* [MockCantonDevice](#mockcantondevice)
|
|
36
35
|
|
|
37
36
|
### Canton
|
|
38
37
|
|
|
@@ -61,7 +60,7 @@ Sign a Canton transaction.
|
|
|
61
60
|
##### Parameters
|
|
62
61
|
|
|
63
62
|
* `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** a path in BIP-32 format
|
|
64
|
-
* `
|
|
63
|
+
* `txHash` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the transaction hash to sign
|
|
65
64
|
|
|
66
65
|
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<CantonSignature>** the signature
|
|
67
66
|
|
|
@@ -71,10 +70,6 @@ Get the app configuration.
|
|
|
71
70
|
|
|
72
71
|
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<AppConfig>** the app configuration including version
|
|
73
72
|
|
|
74
|
-
### MockCantonDevice
|
|
75
|
-
|
|
76
|
-
Mock Canton "@ledgerhq/hw-app-canton" device implementation for development and testing
|
|
77
|
-
|
|
78
73
|
## Integration tests
|
|
79
74
|
|
|
80
75
|
### 1. Prerequisite
|
|
@@ -106,3 +101,5 @@ From Ledger Live root directory:
|
|
|
106
101
|
```sh
|
|
107
102
|
pnpm ljs:hw-app-canton test-integ
|
|
108
103
|
```
|
|
104
|
+
|
|
105
|
+
You can take a look at [Speculos UI](http://127.0.0.1:5000/)
|
package/lib/Canton.d.ts
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import type Transport from "@ledgerhq/hw-transport";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
export type AppConfig = {
|
|
3
|
+
version: string;
|
|
4
|
+
};
|
|
5
|
+
export type CantonAddress = {
|
|
6
|
+
publicKey: string;
|
|
7
|
+
address: string;
|
|
8
|
+
};
|
|
9
|
+
export type CantonSignature = string;
|
|
4
10
|
/**
|
|
5
11
|
* Canton BOLOS API
|
|
6
12
|
*/
|
|
7
13
|
export default class Canton {
|
|
8
14
|
transport: Transport;
|
|
9
|
-
transportMock: MockCantonDevice;
|
|
10
15
|
constructor(transport: Transport, scrambleKey?: string);
|
|
11
16
|
/**
|
|
12
17
|
* Get a Canton address for a given BIP-32 path.
|
|
@@ -20,15 +25,21 @@ export default class Canton {
|
|
|
20
25
|
* Sign a Canton transaction.
|
|
21
26
|
*
|
|
22
27
|
* @param path a path in BIP-32 format
|
|
23
|
-
* @param
|
|
28
|
+
* @param txHash the transaction hash to sign
|
|
24
29
|
* @return the signature
|
|
25
30
|
*/
|
|
26
|
-
signTransaction(path: string,
|
|
31
|
+
signTransaction(path: string, txHash: string): Promise<CantonSignature>;
|
|
27
32
|
/**
|
|
28
33
|
* Get the app configuration.
|
|
29
34
|
* @return the app configuration including version
|
|
30
35
|
*/
|
|
31
36
|
getAppConfiguration(): Promise<AppConfig>;
|
|
37
|
+
/**
|
|
38
|
+
* Converts 65-byte Canton format to 64-byte Ed25519:
|
|
39
|
+
* [40][64_bytes_signature][00] (132 hex chars)
|
|
40
|
+
* @private
|
|
41
|
+
*/
|
|
42
|
+
private cleanSignatureFormat;
|
|
32
43
|
/**
|
|
33
44
|
* Helper method to handle transport response and check for errors
|
|
34
45
|
* @private
|
package/lib/Canton.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Canton.d.ts","sourceRoot":"","sources":["../src/Canton.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"Canton.d.ts","sourceRoot":"","sources":["../src/Canton.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,wBAAwB,CAAC;AAiCpD,MAAM,MAAM,SAAS,GAAG;IACtB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC;AAErC;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,MAAM;IACzB,SAAS,EAAE,SAAS,CAAC;gBAET,SAAS,EAAE,SAAS,EAAE,WAAW,SAAgC;IAU7E;;;;;;OAMG;IACG,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,OAAe,GAAG,OAAO,CAAC,aAAa,CAAC;IAqBhF;;;;;;OAMG;IACG,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IA+B7E;;;OAGG;IACG,mBAAmB,IAAI,OAAO,CAAC,SAAS,CAAC;IAiB/C;;;;OAIG;IACH,OAAO,CAAC,oBAAoB;IAc5B;;;OAGG;IACH,OAAO,CAAC,uBAAuB;IAqB/B;;;OAGG;IACH,OAAO,CAAC,aAAa;IAWrB;;;OAGG;IACH,OAAO,CAAC,UAAU;IAUlB;;;OAGG;IACH,OAAO,CAAC,yBAAyB;IAwBjC;;;OAGG;IACH,OAAO,CAAC,cAAc;CAOvB"}
|
package/lib/Canton.integ.test.js
CHANGED
|
@@ -1,15 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
27
|
};
|
|
5
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const hw_transport_node_speculos_http_1 =
|
|
29
|
+
const hw_transport_node_speculos_http_1 = __importStar(require("@ledgerhq/hw-transport-node-speculos-http"));
|
|
7
30
|
const Canton_1 = __importDefault(require("./Canton"));
|
|
8
31
|
describe("AppCanton", () => {
|
|
9
32
|
let transport;
|
|
10
33
|
beforeAll(async () => {
|
|
11
34
|
transport = await hw_transport_node_speculos_http_1.default.open({});
|
|
12
35
|
});
|
|
36
|
+
afterAll(async () => {
|
|
37
|
+
transport.close();
|
|
38
|
+
});
|
|
13
39
|
describe("getAppConfiguration", () => {
|
|
14
40
|
it("returns app version", async () => {
|
|
15
41
|
// GIVEN
|
|
@@ -31,13 +57,32 @@ describe("AppCanton", () => {
|
|
|
31
57
|
const result = await app.getAddress(derivationPath);
|
|
32
58
|
// THEN
|
|
33
59
|
expect(result).toEqual({
|
|
34
|
-
address: "
|
|
35
|
-
publicKey: "
|
|
60
|
+
address: "canton_1a7a97e0",
|
|
61
|
+
publicKey: "c59f7f29374d24506dd6490a5db472cf00958e195e146f3dc9c97f96d5c51097",
|
|
36
62
|
});
|
|
37
63
|
});
|
|
38
64
|
});
|
|
39
65
|
describe("signTransaction", () => {
|
|
40
|
-
it
|
|
66
|
+
it("returns sign transaction", async () => {
|
|
67
|
+
// GIVEN
|
|
68
|
+
const app = new Canton_1.default(transport);
|
|
69
|
+
const derivationPath = "44'/6767'/0'/0'/0'";
|
|
70
|
+
const txHash = "d1e98829444207b0e170346b2e80b58a2ffc602b01e190fb742016d407c84efd";
|
|
71
|
+
// WHEN
|
|
72
|
+
const signPromise = app.signTransaction(derivationPath, txHash);
|
|
73
|
+
// Waiting Speculos receive APDUs
|
|
74
|
+
const delay = (ms) => new Promise(f => setTimeout(f, ms));
|
|
75
|
+
await delay(500);
|
|
76
|
+
// Valid transaction butotn interaction sequence
|
|
77
|
+
await transport.button(hw_transport_node_speculos_http_1.SpeculosButton.BOTH);
|
|
78
|
+
await transport.button(hw_transport_node_speculos_http_1.SpeculosButton.RIGHT);
|
|
79
|
+
await transport.button(hw_transport_node_speculos_http_1.SpeculosButton.RIGHT);
|
|
80
|
+
await transport.button(hw_transport_node_speculos_http_1.SpeculosButton.RIGHT);
|
|
81
|
+
await transport.button(hw_transport_node_speculos_http_1.SpeculosButton.BOTH);
|
|
82
|
+
const result = await signPromise;
|
|
83
|
+
// THEN
|
|
84
|
+
expect(result).toEqual("40a65f53c3657bc04efefb67a425ba093a5cb5391d18142f148bb2c48daacf316114cff920a58d5996ca828c7ce265f537f1d7fca8fa82c3c73bd944a96e701a0000");
|
|
85
|
+
});
|
|
41
86
|
});
|
|
42
87
|
});
|
|
43
88
|
//# sourceMappingURL=Canton.integ.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Canton.integ.test.js","sourceRoot":"","sources":["../src/Canton.integ.test.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Canton.integ.test.js","sourceRoot":"","sources":["../src/Canton.integ.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6GAAkG;AAClG,sDAA8B;AAE9B,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;IACzB,IAAI,SAAgC,CAAC;IAErC,SAAS,CAAC,KAAK,IAAI,EAAE;QACnB,SAAS,GAAG,MAAM,yCAAqB,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,gBAAM,CAAC,SAAS,CAAC,CAAC;YAElC,OAAO;YACP,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,mBAAmB,EAAE,CAAC;YAE/C,OAAO;YACP,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC;gBACrB,OAAO,EAAE,OAAO;aACjB,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;QAC1B,EAAE,CAAC,4BAA4B,EAAE,KAAK,IAAI,EAAE;YAC1C,QAAQ;YACR,MAAM,GAAG,GAAG,IAAI,gBAAM,CAAC,SAAS,CAAC,CAAC;YAClC,MAA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AC;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/Canton.js
CHANGED
|
@@ -5,11 +5,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const errors_1 = require("@ledgerhq/errors");
|
|
7
7
|
const bip32_path_1 = __importDefault(require("bip32-path"));
|
|
8
|
-
const MockDevice_1 = require("./MockDevice");
|
|
9
8
|
const CLA = 0xe0;
|
|
10
9
|
const P1_NON_CONFIRM = 0x00;
|
|
11
10
|
const P1_CONFIRM = 0x01;
|
|
12
|
-
|
|
11
|
+
// P2 indicating no information.
|
|
12
|
+
const P2_NONE = 0x00;
|
|
13
|
+
// P2 indicating first APDU in a large request.
|
|
14
|
+
const P2_FIRST = 0x01;
|
|
15
|
+
// P2 indicating that this is not the last APDU in a large request.
|
|
16
|
+
const P2_MORE = 0x02;
|
|
17
|
+
// P2 indicating that this is the last APDU of a message in a multi message request.
|
|
18
|
+
const P2_MSG_END = 0x04;
|
|
13
19
|
const INS = {
|
|
14
20
|
GET_VERSION: 0x03,
|
|
15
21
|
GET_APP_NAME: 0x04,
|
|
@@ -20,15 +26,15 @@ const STATUS = {
|
|
|
20
26
|
OK: 0x9000,
|
|
21
27
|
USER_CANCEL: 0x6985,
|
|
22
28
|
};
|
|
29
|
+
const ED25519_SIGNATURE_HEX_LENGTH = 128; // hex characters (64 bytes)
|
|
30
|
+
const CANTON_SIGNATURE_HEX_LENGTH = 132; // hex characters (66 bytes with framing)
|
|
23
31
|
/**
|
|
24
32
|
* Canton BOLOS API
|
|
25
33
|
*/
|
|
26
34
|
class Canton {
|
|
27
35
|
transport;
|
|
28
|
-
transportMock;
|
|
29
36
|
constructor(transport, scrambleKey = "canton_default_scramble_key") {
|
|
30
37
|
this.transport = transport;
|
|
31
|
-
this.transportMock = new MockDevice_1.MockCantonDevice();
|
|
32
38
|
transport.decorateAppAPIMethods(this, ["getAddress", "signTransaction", "getAppConfiguration"], scrambleKey);
|
|
33
39
|
}
|
|
34
40
|
/**
|
|
@@ -39,18 +45,18 @@ class Canton {
|
|
|
39
45
|
* @return the address and public key
|
|
40
46
|
*/
|
|
41
47
|
async getAddress(path, display = false) {
|
|
42
|
-
|
|
48
|
+
// TODO: replace with the actual path fix wrong path "44'/6767'/0'" being used
|
|
49
|
+
const bipPath = bip32_path_1.default.fromString("m/44'/6767'/0'/0'/0'").toPathArray();
|
|
43
50
|
const serializedPath = this.serializePath(bipPath);
|
|
44
51
|
const p1 = display ? P1_CONFIRM : P1_NON_CONFIRM;
|
|
45
|
-
const response = await this.transport.send(CLA, INS.GET_ADDR, p1,
|
|
52
|
+
const response = await this.transport.send(CLA, INS.GET_ADDR, p1, P2_NONE, serializedPath);
|
|
46
53
|
const responseData = this.handleTransportResponse(response, "address");
|
|
47
54
|
const { pubKey } = this.extractPubkeyAndChainCode(responseData);
|
|
48
|
-
// Handle 65-byte uncompressed SECP256R1 public key
|
|
49
55
|
const publicKey = "0x" + pubKey;
|
|
50
56
|
const addressHash = this.hashString(publicKey);
|
|
51
57
|
const address = "canton_" + addressHash.substring(0, 36);
|
|
52
58
|
return {
|
|
53
|
-
publicKey,
|
|
59
|
+
publicKey: pubKey,
|
|
54
60
|
address,
|
|
55
61
|
};
|
|
56
62
|
}
|
|
@@ -58,30 +64,50 @@ class Canton {
|
|
|
58
64
|
* Sign a Canton transaction.
|
|
59
65
|
*
|
|
60
66
|
* @param path a path in BIP-32 format
|
|
61
|
-
* @param
|
|
67
|
+
* @param txHash the transaction hash to sign
|
|
62
68
|
* @return the signature
|
|
63
69
|
*/
|
|
64
|
-
async signTransaction(path,
|
|
65
|
-
|
|
70
|
+
async signTransaction(path, txHash) {
|
|
71
|
+
// 1. Send the derivation path
|
|
72
|
+
// TODO: replace with the actual path fix wrong path "44'/6767'/0'" being used
|
|
73
|
+
const bipPath = bip32_path_1.default.fromString("m/44'/6767'/0'/0'/0'").toPathArray();
|
|
66
74
|
const serializedPath = this.serializePath(bipPath);
|
|
67
|
-
const
|
|
68
|
-
|
|
75
|
+
const pathResponse = await this.transport.send(CLA, INS.SIGN, P1_NON_CONFIRM, P2_FIRST | P2_MORE, serializedPath);
|
|
76
|
+
this.handleTransportResponse(pathResponse, "transaction");
|
|
77
|
+
// 2. Send the transaction hash
|
|
78
|
+
const response = await this.transport.send(CLA, INS.SIGN, P1_NON_CONFIRM, P2_MSG_END, Buffer.from(txHash, "hex"));
|
|
69
79
|
const responseData = this.handleTransportResponse(response, "transaction");
|
|
70
|
-
const
|
|
71
|
-
return
|
|
80
|
+
const rawSignature = responseData.toString("hex");
|
|
81
|
+
return this.cleanSignatureFormat(rawSignature);
|
|
72
82
|
}
|
|
73
83
|
/**
|
|
74
84
|
* Get the app configuration.
|
|
75
85
|
* @return the app configuration including version
|
|
76
86
|
*/
|
|
77
87
|
async getAppConfiguration() {
|
|
78
|
-
const response = await this.transport.send(CLA, INS.GET_VERSION, P1_NON_CONFIRM,
|
|
88
|
+
const response = await this.transport.send(CLA, INS.GET_VERSION, P1_NON_CONFIRM, P2_NONE, Buffer.alloc(0));
|
|
79
89
|
const responseData = this.handleTransportResponse(response, "version");
|
|
80
90
|
const { major, minor, patch } = this.extractVersion(responseData);
|
|
81
91
|
return {
|
|
82
92
|
version: `${major}.${minor}.${patch}`,
|
|
83
93
|
};
|
|
84
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Converts 65-byte Canton format to 64-byte Ed25519:
|
|
97
|
+
* [40][64_bytes_signature][00] (132 hex chars)
|
|
98
|
+
* @private
|
|
99
|
+
*/
|
|
100
|
+
cleanSignatureFormat(signature) {
|
|
101
|
+
if (signature.length === ED25519_SIGNATURE_HEX_LENGTH) {
|
|
102
|
+
return signature;
|
|
103
|
+
}
|
|
104
|
+
if (signature.length === CANTON_SIGNATURE_HEX_LENGTH) {
|
|
105
|
+
const cleanedSignature = signature.slice(2, -2);
|
|
106
|
+
return cleanedSignature;
|
|
107
|
+
}
|
|
108
|
+
console.warn(`[Canton]: Unknown signature format (${signature.length} chars)`);
|
|
109
|
+
return signature;
|
|
110
|
+
}
|
|
85
111
|
/**
|
|
86
112
|
* Helper method to handle transport response and check for errors
|
|
87
113
|
* @private
|
|
@@ -131,10 +157,20 @@ class Canton {
|
|
|
131
157
|
* @private
|
|
132
158
|
*/
|
|
133
159
|
extractPubkeyAndChainCode(data) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
160
|
+
// Parse the response according to the Python unpack_get_addr_response format:
|
|
161
|
+
// response = pubkey_len (1) + pubkey (var) + chaincode_len (1) + chaincode (var)
|
|
162
|
+
let offset = 0;
|
|
163
|
+
// Extract public key length (1 byte)
|
|
164
|
+
const pubkeySize = data.readUInt8(offset);
|
|
165
|
+
offset += 1;
|
|
166
|
+
// Extract public key
|
|
167
|
+
const pubKey = data.subarray(offset, offset + pubkeySize);
|
|
168
|
+
offset += pubkeySize;
|
|
169
|
+
// Extract chain code length (1 byte)
|
|
170
|
+
const chainCodeSize = data.readUInt8(offset);
|
|
171
|
+
offset += 1;
|
|
172
|
+
// Extract chain code
|
|
173
|
+
const chainCode = data.subarray(offset, offset + chainCodeSize);
|
|
138
174
|
return { pubKey: pubKey.toString("hex"), chainCode: chainCode.toString("hex") };
|
|
139
175
|
}
|
|
140
176
|
/**
|
package/lib/Canton.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Canton.js","sourceRoot":"","sources":["../src/Canton.ts"],"names":[],"mappings":";;;;;AACA,6CAA2E;
|
|
1
|
+
{"version":3,"file":"Canton.js","sourceRoot":"","sources":["../src/Canton.ts"],"names":[],"mappings":";;;;;AACA,6CAA2E;AAC3E,4DAAiC;AAEjC,MAAM,GAAG,GAAG,IAAI,CAAC;AAEjB,MAAM,cAA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CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC;SACzD,CAAC;IACJ,CAAC;CACF;AApND,yBAoNC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Canton.test.d.ts","sourceRoot":"","sources":["../src/Canton.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,126 @@
|
|
|
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_1a7a97e0",
|
|
35
|
+
publicKey: "c59f7f29374d24506dd6490a5db472cf00958e195e146f3dc9c97f96d5c51097",
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
it("should get address with display", async () => {
|
|
39
|
+
// GIVEN
|
|
40
|
+
const transport = await (0, hw_transport_mocker_1.openTransportReplayer)(hw_transport_mocker_1.RecordStore.fromString(`
|
|
41
|
+
=> e005010015058000002c80001a6f800000008000000080000000
|
|
42
|
+
<= 20c59f7f29374d24506dd6490a5db472cf00958e195e146f3dc9c97f96d5c5109720c59f7f29374d24506dd6490a5db472cf00958e195e146f3dc9c97f96d5c510979000
|
|
43
|
+
`));
|
|
44
|
+
const canton = new Canton_1.default(transport);
|
|
45
|
+
// WHEN
|
|
46
|
+
const result = await canton.getAddress("44'/6767'/0'/0'/0'", true);
|
|
47
|
+
// THEN
|
|
48
|
+
expect(result).toEqual({
|
|
49
|
+
address: "canton_1a7a97e0",
|
|
50
|
+
publicKey: "c59f7f29374d24506dd6490a5db472cf00958e195e146f3dc9c97f96d5c51097",
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
it("should throw on invalid derivation path", async () => {
|
|
54
|
+
// GIVEN
|
|
55
|
+
const transport = await (0, hw_transport_mocker_1.openTransportReplayer)(new hw_transport_mocker_1.RecordStore());
|
|
56
|
+
const canton = new Canton_1.default(transport);
|
|
57
|
+
// WHEN & THEN
|
|
58
|
+
return expect(canton.getAddress("invalid path")).rejects.toThrow();
|
|
59
|
+
});
|
|
60
|
+
// unskip when TODO comment is handled
|
|
61
|
+
it.skip("should handle various derivation paths", async () => {
|
|
62
|
+
// GIVEN
|
|
63
|
+
const transport = await (0, hw_transport_mocker_1.openTransportReplayer)(hw_transport_mocker_1.RecordStore.fromString(`
|
|
64
|
+
=> e005000015058000002c80001a6f800000008000000080000001
|
|
65
|
+
<= 205e66a10773c0860e73bb6015947806555765df5f9b5b4636df4255a57c57d702205e66a10773c0860e73bb6015947806555765df5f9b5b4636df4255a57c57d7029000
|
|
66
|
+
`));
|
|
67
|
+
const canton = new Canton_1.default(transport);
|
|
68
|
+
// WHEN
|
|
69
|
+
const result = await canton.getAddress("44'/6767'/0'/0'/1'");
|
|
70
|
+
// THEN
|
|
71
|
+
expect(result).toBeDefined();
|
|
72
|
+
expect(result.address).toBeDefined();
|
|
73
|
+
expect(result.publicKey).toBeDefined();
|
|
74
|
+
});
|
|
75
|
+
// should handle user refused address
|
|
76
|
+
});
|
|
77
|
+
describe("signTransaction", () => {
|
|
78
|
+
// should sign transaction
|
|
79
|
+
// should handle large transaction payloads
|
|
80
|
+
// should handle empty transaction
|
|
81
|
+
// should request blind signature when required
|
|
82
|
+
it("should sign transaction hash", async () => {
|
|
83
|
+
// GIVEN
|
|
84
|
+
const transport = await (0, hw_transport_mocker_1.openTransportReplayer)(hw_transport_mocker_1.RecordStore.fromString(`
|
|
85
|
+
=> e006000315058000002c80001a6f800000008000000080000000
|
|
86
|
+
<= 9000
|
|
87
|
+
=> e006000420d1e98829444207b0e170346b2e80b58a2ffc602b01e190fb742016d407c84efd
|
|
88
|
+
<= 40a65f53c3657bc04efefb67a425ba093a5cb5391d18142f148bb2c48daacf316114cff920a58d5996ca828c7ce265f537f1d7fca8fa82c3c73bd944a96e701a00009000
|
|
89
|
+
`));
|
|
90
|
+
const canton = new Canton_1.default(transport);
|
|
91
|
+
const txHash = "d1e98829444207b0e170346b2e80b58a2ffc602b01e190fb742016d407c84efd";
|
|
92
|
+
// WHEN
|
|
93
|
+
const result = await canton.signTransaction("44'/6767'/0'/0'/0'", txHash);
|
|
94
|
+
// THEN
|
|
95
|
+
expect(result).toEqual("a65f53c3657bc04efefb67a425ba093a5cb5391d18142f148bb2c48daacf316114cff920a58d5996ca828c7ce265f537f1d7fca8fa82c3c73bd944a96e701a00");
|
|
96
|
+
});
|
|
97
|
+
it("should handle user refused transaction", async () => {
|
|
98
|
+
// GIVEN
|
|
99
|
+
const transport = await (0, hw_transport_mocker_1.openTransportReplayer)(hw_transport_mocker_1.RecordStore.fromString(`
|
|
100
|
+
=> e006010015058000002c80001a6f800000008000000080000000
|
|
101
|
+
<= 6985
|
|
102
|
+
`));
|
|
103
|
+
const canton = new Canton_1.default(transport);
|
|
104
|
+
// WHEN & THEN
|
|
105
|
+
return expect(canton.signTransaction("44'/6767'/0'/0'/0'", "test")).rejects.toThrow();
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
describe("getAppConfiguration", () => {
|
|
109
|
+
it("should get app configuration", async () => {
|
|
110
|
+
// GIVEN
|
|
111
|
+
const transport = await (0, hw_transport_mocker_1.openTransportReplayer)(hw_transport_mocker_1.RecordStore.fromString(`
|
|
112
|
+
=> e003000000
|
|
113
|
+
<= 0202029000
|
|
114
|
+
`));
|
|
115
|
+
const canton = new Canton_1.default(transport);
|
|
116
|
+
// WHEN
|
|
117
|
+
const result = await canton.getAppConfiguration();
|
|
118
|
+
// THEN
|
|
119
|
+
expect(result).toEqual({
|
|
120
|
+
version: "2.2.2",
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
// should handle configuration error
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
//# sourceMappingURL=Canton.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,MA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C,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"}
|
package/lib-es/Canton.d.ts
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import type Transport from "@ledgerhq/hw-transport";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
export type AppConfig = {
|
|
3
|
+
version: string;
|
|
4
|
+
};
|
|
5
|
+
export type CantonAddress = {
|
|
6
|
+
publicKey: string;
|
|
7
|
+
address: string;
|
|
8
|
+
};
|
|
9
|
+
export type CantonSignature = string;
|
|
4
10
|
/**
|
|
5
11
|
* Canton BOLOS API
|
|
6
12
|
*/
|
|
7
13
|
export default class Canton {
|
|
8
14
|
transport: Transport;
|
|
9
|
-
transportMock: MockCantonDevice;
|
|
10
15
|
constructor(transport: Transport, scrambleKey?: string);
|
|
11
16
|
/**
|
|
12
17
|
* Get a Canton address for a given BIP-32 path.
|
|
@@ -20,15 +25,21 @@ export default class Canton {
|
|
|
20
25
|
* Sign a Canton transaction.
|
|
21
26
|
*
|
|
22
27
|
* @param path a path in BIP-32 format
|
|
23
|
-
* @param
|
|
28
|
+
* @param txHash the transaction hash to sign
|
|
24
29
|
* @return the signature
|
|
25
30
|
*/
|
|
26
|
-
signTransaction(path: string,
|
|
31
|
+
signTransaction(path: string, txHash: string): Promise<CantonSignature>;
|
|
27
32
|
/**
|
|
28
33
|
* Get the app configuration.
|
|
29
34
|
* @return the app configuration including version
|
|
30
35
|
*/
|
|
31
36
|
getAppConfiguration(): Promise<AppConfig>;
|
|
37
|
+
/**
|
|
38
|
+
* Converts 65-byte Canton format to 64-byte Ed25519:
|
|
39
|
+
* [40][64_bytes_signature][00] (132 hex chars)
|
|
40
|
+
* @private
|
|
41
|
+
*/
|
|
42
|
+
private cleanSignatureFormat;
|
|
32
43
|
/**
|
|
33
44
|
* Helper method to handle transport response and check for errors
|
|
34
45
|
* @private
|
package/lib-es/Canton.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Canton.d.ts","sourceRoot":"","sources":["../src/Canton.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"Canton.d.ts","sourceRoot":"","sources":["../src/Canton.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,wBAAwB,CAAC;AAiCpD,MAAM,MAAM,SAAS,GAAG;IACtB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC;AAErC;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,MAAM;IACzB,SAAS,EAAE,SAAS,CAAC;gBAET,SAAS,EAAE,SAAS,EAAE,WAAW,SAAgC;IAU7E;;;;;;OAMG;IACG,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,OAAe,GAAG,OAAO,CAAC,aAAa,CAAC;IAqBhF;;;;;;OAMG;IACG,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IA+B7E;;;OAGG;IACG,mBAAmB,IAAI,OAAO,CAAC,SAAS,CAAC;IAiB/C;;;;OAIG;IACH,OAAO,CAAC,oBAAoB;IAc5B;;;OAGG;IACH,OAAO,CAAC,uBAAuB;IAqB/B;;;OAGG;IACH,OAAO,CAAC,aAAa;IAWrB;;;OAGG;IACH,OAAO,CAAC,UAAU;IAUlB;;;OAGG;IACH,OAAO,CAAC,yBAAyB;IAwBjC;;;OAGG;IACH,OAAO,CAAC,cAAc;CAOvB"}
|
|
@@ -1,10 +1,13 @@
|
|
|
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
3
|
describe("AppCanton", () => {
|
|
4
4
|
let transport;
|
|
5
5
|
beforeAll(async () => {
|
|
6
6
|
transport = await SpeculosTransportHttp.open({});
|
|
7
7
|
});
|
|
8
|
+
afterAll(async () => {
|
|
9
|
+
transport.close();
|
|
10
|
+
});
|
|
8
11
|
describe("getAppConfiguration", () => {
|
|
9
12
|
it("returns app version", async () => {
|
|
10
13
|
// GIVEN
|
|
@@ -26,13 +29,32 @@ describe("AppCanton", () => {
|
|
|
26
29
|
const result = await app.getAddress(derivationPath);
|
|
27
30
|
// THEN
|
|
28
31
|
expect(result).toEqual({
|
|
29
|
-
address: "
|
|
30
|
-
publicKey: "
|
|
32
|
+
address: "canton_1a7a97e0",
|
|
33
|
+
publicKey: "c59f7f29374d24506dd6490a5db472cf00958e195e146f3dc9c97f96d5c51097",
|
|
31
34
|
});
|
|
32
35
|
});
|
|
33
36
|
});
|
|
34
37
|
describe("signTransaction", () => {
|
|
35
|
-
it
|
|
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
|
+
});
|
|
36
58
|
});
|
|
37
59
|
});
|
|
38
60
|
//# sourceMappingURL=Canton.integ.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Canton.integ.test.js","sourceRoot":"","sources":["../src/Canton.integ.test.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,MAAM,2CAA2C,CAAC;
|
|
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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