@ledgerhq/hw-app-canton 0.3.0 → 0.3.1-nightly.1
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 +12 -0
- package/README.md +3 -6
- package/lib/Canton.d.ts +21 -8
- 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 +60 -26
- 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 +127 -0
- package/lib/Canton.test.js.map +1 -0
- package/lib-es/Canton.d.ts +21 -8
- 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 +60 -26
- 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 +122 -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 -18
- package/src/Canton.ts +95 -32
- 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/.turbo/turbo-build.log
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
|
|
2
|
-
> @ledgerhq/hw-app-canton@0.3.0 build /home/runner/work/ledger-live/ledger-live/libs/ledgerjs/packages/hw-app-canton
|
|
2
|
+
> @ledgerhq/hw-app-canton@0.3.1-nightly.0 build /home/runner/work/ledger-live/ledger-live/libs/ledgerjs/packages/hw-app-canton
|
|
3
3
|
> tsc && tsc -m esnext --moduleResolution bundler --outDir lib-es
|
|
4
4
|
|
package/.unimportedrc.json
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @ledgerhq/hw-app-canton
|
|
2
2
|
|
|
3
|
+
## 0.3.1-nightly.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#11769](https://github.com/LedgerHQ/ledger-live/pull/11769) [`6941aac`](https://github.com/LedgerHQ/ledger-live/commit/6941aac638dcc8d4fb03aa92f42d2a71d4089202) Thanks [@ishaba](https://github.com/ishaba)! - fix canton receive flow
|
|
8
|
+
|
|
9
|
+
## 0.3.1-nightly.0
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#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
|
|
14
|
+
|
|
3
15
|
## 0.3.0
|
|
4
16
|
|
|
5
17
|
### 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,18 @@
|
|
|
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
|
+
path: string;
|
|
9
|
+
};
|
|
10
|
+
export type CantonSignature = string;
|
|
4
11
|
/**
|
|
5
12
|
* Canton BOLOS API
|
|
6
13
|
*/
|
|
7
14
|
export default class Canton {
|
|
8
15
|
transport: Transport;
|
|
9
|
-
transportMock: MockCantonDevice;
|
|
10
16
|
constructor(transport: Transport, scrambleKey?: string);
|
|
11
17
|
/**
|
|
12
18
|
* Get a Canton address for a given BIP-32 path.
|
|
@@ -20,15 +26,21 @@ export default class Canton {
|
|
|
20
26
|
* Sign a Canton transaction.
|
|
21
27
|
*
|
|
22
28
|
* @param path a path in BIP-32 format
|
|
23
|
-
* @param
|
|
29
|
+
* @param txHash the transaction hash to sign
|
|
24
30
|
* @return the signature
|
|
25
31
|
*/
|
|
26
|
-
signTransaction(path: string,
|
|
32
|
+
signTransaction(path: string, txHash: string): Promise<CantonSignature>;
|
|
27
33
|
/**
|
|
28
34
|
* Get the app configuration.
|
|
29
35
|
* @return the app configuration including version
|
|
30
36
|
*/
|
|
31
37
|
getAppConfiguration(): Promise<AppConfig>;
|
|
38
|
+
/**
|
|
39
|
+
* Converts 65-byte Canton format to 64-byte Ed25519:
|
|
40
|
+
* [40][64_bytes_signature][00] (132 hex chars)
|
|
41
|
+
* @private
|
|
42
|
+
*/
|
|
43
|
+
private cleanSignatureFormat;
|
|
32
44
|
/**
|
|
33
45
|
* Helper method to handle transport response and check for errors
|
|
34
46
|
* @private
|
|
@@ -40,15 +52,16 @@ export default class Canton {
|
|
|
40
52
|
*/
|
|
41
53
|
private serializePath;
|
|
42
54
|
/**
|
|
43
|
-
*
|
|
55
|
+
* Convert public key to address
|
|
44
56
|
* @private
|
|
45
57
|
*/
|
|
46
|
-
private
|
|
58
|
+
private publicKeyToAddress;
|
|
47
59
|
/**
|
|
48
60
|
* Extract Pubkey info from APDU response
|
|
49
61
|
* @private
|
|
62
|
+
* @returns Object with publicKey and chainCode as Buffer objects
|
|
50
63
|
*/
|
|
51
|
-
private
|
|
64
|
+
private extractPublicKeyAndChainCode;
|
|
52
65
|
/**
|
|
53
66
|
* Extract AppVersion from APDU response
|
|
54
67
|
* @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;IAChB,IAAI,EAAE,MAAM,CAAC;CACd,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;IAmBhF;;;;;;OAMG;IACG,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IA8B7E;;;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,kBAAkB;IAU1B;;;;OAIG;IACH,OAAO,CAAC,4BAA4B;IAwBpC;;;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,MAAM,cAAc,GAAG,oBAAoB,CAAC;YAE5C,OAAO;YACP,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC;YAEpD,OAAO;YACP,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO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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
|
/**
|
|
@@ -42,46 +48,63 @@ class Canton {
|
|
|
42
48
|
const bipPath = bip32_path_1.default.fromString(path).toPathArray();
|
|
43
49
|
const serializedPath = this.serializePath(bipPath);
|
|
44
50
|
const p1 = display ? P1_CONFIRM : P1_NON_CONFIRM;
|
|
45
|
-
const response = await this.transport.send(CLA, INS.GET_ADDR, p1,
|
|
51
|
+
const response = await this.transport.send(CLA, INS.GET_ADDR, p1, P2_NONE, serializedPath);
|
|
46
52
|
const responseData = this.handleTransportResponse(response, "address");
|
|
47
|
-
const {
|
|
48
|
-
|
|
49
|
-
const publicKey = "0x" + pubKey;
|
|
50
|
-
const addressHash = this.hashString(publicKey);
|
|
51
|
-
const address = "canton_" + addressHash.substring(0, 36);
|
|
53
|
+
const { publicKey } = this.extractPublicKeyAndChainCode(responseData);
|
|
54
|
+
const address = this.publicKeyToAddress(publicKey);
|
|
52
55
|
return {
|
|
53
56
|
publicKey,
|
|
54
57
|
address,
|
|
58
|
+
path,
|
|
55
59
|
};
|
|
56
60
|
}
|
|
57
61
|
/**
|
|
58
62
|
* Sign a Canton transaction.
|
|
59
63
|
*
|
|
60
64
|
* @param path a path in BIP-32 format
|
|
61
|
-
* @param
|
|
65
|
+
* @param txHash the transaction hash to sign
|
|
62
66
|
* @return the signature
|
|
63
67
|
*/
|
|
64
|
-
async signTransaction(path,
|
|
68
|
+
async signTransaction(path, txHash) {
|
|
69
|
+
// 1. Send the derivation path
|
|
65
70
|
const bipPath = bip32_path_1.default.fromString(path).toPathArray();
|
|
66
71
|
const serializedPath = this.serializePath(bipPath);
|
|
67
|
-
const
|
|
68
|
-
|
|
72
|
+
const pathResponse = await this.transport.send(CLA, INS.SIGN, P1_NON_CONFIRM, P2_FIRST | P2_MORE, serializedPath);
|
|
73
|
+
this.handleTransportResponse(pathResponse, "transaction");
|
|
74
|
+
// 2. Send the transaction hash
|
|
75
|
+
const response = await this.transport.send(CLA, INS.SIGN, P1_NON_CONFIRM, P2_MSG_END, Buffer.from(txHash, "hex"));
|
|
69
76
|
const responseData = this.handleTransportResponse(response, "transaction");
|
|
70
|
-
const
|
|
71
|
-
return
|
|
77
|
+
const rawSignature = responseData.toString("hex");
|
|
78
|
+
return this.cleanSignatureFormat(rawSignature);
|
|
72
79
|
}
|
|
73
80
|
/**
|
|
74
81
|
* Get the app configuration.
|
|
75
82
|
* @return the app configuration including version
|
|
76
83
|
*/
|
|
77
84
|
async getAppConfiguration() {
|
|
78
|
-
const response = await this.transport.send(CLA, INS.GET_VERSION, P1_NON_CONFIRM,
|
|
85
|
+
const response = await this.transport.send(CLA, INS.GET_VERSION, P1_NON_CONFIRM, P2_NONE, Buffer.alloc(0));
|
|
79
86
|
const responseData = this.handleTransportResponse(response, "version");
|
|
80
87
|
const { major, minor, patch } = this.extractVersion(responseData);
|
|
81
88
|
return {
|
|
82
89
|
version: `${major}.${minor}.${patch}`,
|
|
83
90
|
};
|
|
84
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* Converts 65-byte Canton format to 64-byte Ed25519:
|
|
94
|
+
* [40][64_bytes_signature][00] (132 hex chars)
|
|
95
|
+
* @private
|
|
96
|
+
*/
|
|
97
|
+
cleanSignatureFormat(signature) {
|
|
98
|
+
if (signature.length === ED25519_SIGNATURE_HEX_LENGTH) {
|
|
99
|
+
return signature;
|
|
100
|
+
}
|
|
101
|
+
if (signature.length === CANTON_SIGNATURE_HEX_LENGTH) {
|
|
102
|
+
const cleanedSignature = signature.slice(2, -2);
|
|
103
|
+
return cleanedSignature;
|
|
104
|
+
}
|
|
105
|
+
console.warn(`[Canton]: Unknown signature format (${signature.length} chars)`);
|
|
106
|
+
return signature;
|
|
107
|
+
}
|
|
85
108
|
/**
|
|
86
109
|
* Helper method to handle transport response and check for errors
|
|
87
110
|
* @private
|
|
@@ -114,28 +137,39 @@ class Canton {
|
|
|
114
137
|
return data;
|
|
115
138
|
}
|
|
116
139
|
/**
|
|
117
|
-
*
|
|
140
|
+
* Convert public key to address
|
|
118
141
|
* @private
|
|
119
142
|
*/
|
|
120
|
-
|
|
143
|
+
publicKeyToAddress(str) {
|
|
121
144
|
let hash = 0;
|
|
122
145
|
for (let i = 0; i < str.length; i++) {
|
|
123
146
|
const char = str.charCodeAt(i);
|
|
124
147
|
hash = (hash << 5) - hash + char;
|
|
125
|
-
hash = hash & hash;
|
|
148
|
+
hash = hash & hash;
|
|
126
149
|
}
|
|
127
150
|
return Math.abs(hash).toString(16);
|
|
128
151
|
}
|
|
129
152
|
/**
|
|
130
153
|
* Extract Pubkey info from APDU response
|
|
131
154
|
* @private
|
|
155
|
+
* @returns Object with publicKey and chainCode as Buffer objects
|
|
132
156
|
*/
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
157
|
+
extractPublicKeyAndChainCode(data) {
|
|
158
|
+
// Parse the response according to the Python unpack_get_addr_response format:
|
|
159
|
+
// response = pubkey_len (1) + pubkey (var) + chaincode_len (1) + chaincode (var)
|
|
160
|
+
let offset = 0;
|
|
161
|
+
// Extract public key length (1 byte)
|
|
162
|
+
const pubkeySize = data.readUInt8(offset);
|
|
163
|
+
offset += 1;
|
|
164
|
+
// Extract public key
|
|
165
|
+
const pubKey = data.subarray(offset, offset + pubkeySize);
|
|
166
|
+
offset += pubkeySize;
|
|
167
|
+
// Extract chain code length (1 byte)
|
|
168
|
+
const chainCodeSize = data.readUInt8(offset);
|
|
169
|
+
offset += 1;
|
|
170
|
+
// Extract chain code
|
|
171
|
+
const chainCode = data.subarray(offset, offset + chainCodeSize);
|
|
172
|
+
return { publicKey: pubKey.toString("hex"), chainCode: chainCode.toString("hex") };
|
|
139
173
|
}
|
|
140
174
|
/**
|
|
141
175
|
* Extract AppVersion from APDU response
|
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","s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C;SACzD,CAAC;IACJ,CAAC;CACF;AAlND,yBAkNC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Canton.test.d.ts","sourceRoot":"","sources":["../src/Canton.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,127 @@
|
|
|
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: "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: "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
|
|
@@ -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,MAAM,IAAA,2CAAqB,EAAC,IAAI,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;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,18 @@
|
|
|
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
|
+
path: string;
|
|
9
|
+
};
|
|
10
|
+
export type CantonSignature = string;
|
|
4
11
|
/**
|
|
5
12
|
* Canton BOLOS API
|
|
6
13
|
*/
|
|
7
14
|
export default class Canton {
|
|
8
15
|
transport: Transport;
|
|
9
|
-
transportMock: MockCantonDevice;
|
|
10
16
|
constructor(transport: Transport, scrambleKey?: string);
|
|
11
17
|
/**
|
|
12
18
|
* Get a Canton address for a given BIP-32 path.
|
|
@@ -20,15 +26,21 @@ export default class Canton {
|
|
|
20
26
|
* Sign a Canton transaction.
|
|
21
27
|
*
|
|
22
28
|
* @param path a path in BIP-32 format
|
|
23
|
-
* @param
|
|
29
|
+
* @param txHash the transaction hash to sign
|
|
24
30
|
* @return the signature
|
|
25
31
|
*/
|
|
26
|
-
signTransaction(path: string,
|
|
32
|
+
signTransaction(path: string, txHash: string): Promise<CantonSignature>;
|
|
27
33
|
/**
|
|
28
34
|
* Get the app configuration.
|
|
29
35
|
* @return the app configuration including version
|
|
30
36
|
*/
|
|
31
37
|
getAppConfiguration(): Promise<AppConfig>;
|
|
38
|
+
/**
|
|
39
|
+
* Converts 65-byte Canton format to 64-byte Ed25519:
|
|
40
|
+
* [40][64_bytes_signature][00] (132 hex chars)
|
|
41
|
+
* @private
|
|
42
|
+
*/
|
|
43
|
+
private cleanSignatureFormat;
|
|
32
44
|
/**
|
|
33
45
|
* Helper method to handle transport response and check for errors
|
|
34
46
|
* @private
|
|
@@ -40,15 +52,16 @@ export default class Canton {
|
|
|
40
52
|
*/
|
|
41
53
|
private serializePath;
|
|
42
54
|
/**
|
|
43
|
-
*
|
|
55
|
+
* Convert public key to address
|
|
44
56
|
* @private
|
|
45
57
|
*/
|
|
46
|
-
private
|
|
58
|
+
private publicKeyToAddress;
|
|
47
59
|
/**
|
|
48
60
|
* Extract Pubkey info from APDU response
|
|
49
61
|
* @private
|
|
62
|
+
* @returns Object with publicKey and chainCode as Buffer objects
|
|
50
63
|
*/
|
|
51
|
-
private
|
|
64
|
+
private extractPublicKeyAndChainCode;
|
|
52
65
|
/**
|
|
53
66
|
* Extract AppVersion from APDU response
|
|
54
67
|
* @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;IAChB,IAAI,EAAE,MAAM,CAAC;CACd,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;IAmBhF;;;;;;OAMG;IACG,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IA8B7E;;;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,kBAAkB;IAU1B;;;;OAIG;IACH,OAAO,CAAC,4BAA4B;IAwBpC;;;OAGG;IACH,OAAO,CAAC,cAAc;CAOvB"}
|