@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/.turbo/turbo-build.log
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
|
|
2
|
-
> @ledgerhq/hw-app-canton@0.
|
|
2
|
+
> @ledgerhq/hw-app-canton@0.3.0-nightly.1 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,18 @@
|
|
|
1
1
|
# @ledgerhq/hw-app-canton
|
|
2
2
|
|
|
3
|
+
## 0.3.0-nightly.2
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#11535](https://github.com/LedgerHQ/ledger-live/pull/11535) [`205458e`](https://github.com/LedgerHQ/ledger-live/commit/205458e2d3ca5ec1d7a50d30b63050a692a5e045) Thanks [@sprohaszka-ledger](https://github.com/sprohaszka-ledger)! - Canton add sign hash function
|
|
8
|
+
|
|
9
|
+
## 0.3.0-nightly.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [[`12277dc`](https://github.com/LedgerHQ/ledger-live/commit/12277dcb478f24152060e3e11e2eb37d650b5b60), [`c1209a7`](https://github.com/LedgerHQ/ledger-live/commit/c1209a70f6362fe8a52139ad5ad0b4705aac00fb), [`58ef394`](https://github.com/LedgerHQ/ledger-live/commit/58ef39468870e56745a3a4bc95a1292a1e1f64ca)]:
|
|
14
|
+
- @ledgerhq/coin-canton@0.4.0-nightly.0
|
|
15
|
+
|
|
3
16
|
## 0.3.0-nightly.0
|
|
4
17
|
|
|
5
18
|
### 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,10 +25,10 @@ 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
|
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;AA4BpD,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;IAoBhF;;;;;;OAMG;IACG,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IA6B7E;;;OAGG;IACG,mBAAmB,IAAI,OAAO,CAAC,SAAS,CAAC;IAiB/C;;;OAGG;IACH,OAAO,CAAC,uBAAuB;IAqB/B;;;OAGG;IACH,OAAO,CAAC,aAAa;IAWrB;;;OAGG;IACH,OAAO,CAAC,UAAU;IAUlB;;;OAGG;IACH,OAAO,CAAC,yBAAyB;IAYjC;;;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,mBA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gDAAc,CAAC,IAAI,CAAC,CAAC;YAC5C,MAAM,SAAS,CAAC,MAAM,CAAC,gDAAc,CAAC,KAAK,CAAC,CAAC;YAC7C,MAAM,SAAS,CAAC,MAAM,CAAC,gDAAc,CAAC,KAAK,CAAC,CAAC;YAC7C,MAAM,SAAS,CAAC,MAAM,CAAC,gDAAc,CAAC,KAAK,CAAC,CAAC;YAC7C,MAAM,SAAS,CAAC,MAAM,CAAC,gDAAc,CAAC,IAAI,CAAC,CAAC;YAE5C,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC;YAEjC,OAAO;YACP,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CACpB,sIAAsI,CACvI,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/lib/Canton.js
CHANGED
|
@@ -5,11 +5,15 @@ 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;
|
|
13
17
|
const INS = {
|
|
14
18
|
GET_VERSION: 0x03,
|
|
15
19
|
GET_APP_NAME: 0x04,
|
|
@@ -25,10 +29,8 @@ const STATUS = {
|
|
|
25
29
|
*/
|
|
26
30
|
class Canton {
|
|
27
31
|
transport;
|
|
28
|
-
transportMock;
|
|
29
32
|
constructor(transport, scrambleKey = "canton_default_scramble_key") {
|
|
30
33
|
this.transport = transport;
|
|
31
|
-
this.transportMock = new MockDevice_1.MockCantonDevice();
|
|
32
34
|
transport.decorateAppAPIMethods(this, ["getAddress", "signTransaction", "getAppConfiguration"], scrambleKey);
|
|
33
35
|
}
|
|
34
36
|
/**
|
|
@@ -42,15 +44,14 @@ class Canton {
|
|
|
42
44
|
const bipPath = bip32_path_1.default.fromString(path).toPathArray();
|
|
43
45
|
const serializedPath = this.serializePath(bipPath);
|
|
44
46
|
const p1 = display ? P1_CONFIRM : P1_NON_CONFIRM;
|
|
45
|
-
const response = await this.transport.send(CLA, INS.GET_ADDR, p1,
|
|
47
|
+
const response = await this.transport.send(CLA, INS.GET_ADDR, p1, P2_NONE, serializedPath);
|
|
46
48
|
const responseData = this.handleTransportResponse(response, "address");
|
|
47
49
|
const { pubKey } = this.extractPubkeyAndChainCode(responseData);
|
|
48
|
-
// Handle 65-byte uncompressed SECP256R1 public key
|
|
49
50
|
const publicKey = "0x" + pubKey;
|
|
50
51
|
const addressHash = this.hashString(publicKey);
|
|
51
52
|
const address = "canton_" + addressHash.substring(0, 36);
|
|
52
53
|
return {
|
|
53
|
-
publicKey,
|
|
54
|
+
publicKey: pubKey,
|
|
54
55
|
address,
|
|
55
56
|
};
|
|
56
57
|
}
|
|
@@ -58,16 +59,19 @@ class Canton {
|
|
|
58
59
|
* Sign a Canton transaction.
|
|
59
60
|
*
|
|
60
61
|
* @param path a path in BIP-32 format
|
|
61
|
-
* @param
|
|
62
|
+
* @param txHash the transaction hash to sign
|
|
62
63
|
* @return the signature
|
|
63
64
|
*/
|
|
64
|
-
async signTransaction(path,
|
|
65
|
+
async signTransaction(path, txHash) {
|
|
66
|
+
// 1. Send the derivation path
|
|
65
67
|
const bipPath = bip32_path_1.default.fromString(path).toPathArray();
|
|
66
68
|
const serializedPath = this.serializePath(bipPath);
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
+
const pathResponse = await this.transport.send(CLA, INS.SIGN, P1_NON_CONFIRM, P2_FIRST | P2_MORE, serializedPath);
|
|
70
|
+
this.handleTransportResponse(pathResponse, "transaction");
|
|
71
|
+
// 2. Send the transaction hash
|
|
72
|
+
const response = await this.transport.send(CLA, INS.SIGN, P1_NON_CONFIRM, P2_NONE, Buffer.from(txHash, "hex"));
|
|
69
73
|
const responseData = this.handleTransportResponse(response, "transaction");
|
|
70
|
-
const signature =
|
|
74
|
+
const signature = responseData.toString("hex");
|
|
71
75
|
return signature;
|
|
72
76
|
}
|
|
73
77
|
/**
|
|
@@ -75,7 +79,7 @@ class Canton {
|
|
|
75
79
|
* @return the app configuration including version
|
|
76
80
|
*/
|
|
77
81
|
async getAppConfiguration() {
|
|
78
|
-
const response = await this.transport.send(CLA, INS.GET_VERSION, P1_NON_CONFIRM,
|
|
82
|
+
const response = await this.transport.send(CLA, INS.GET_VERSION, P1_NON_CONFIRM, P2_NONE, Buffer.alloc(0));
|
|
79
83
|
const responseData = this.handleTransportResponse(response, "version");
|
|
80
84
|
const { major, minor, patch } = this.extractVersion(responseData);
|
|
81
85
|
return {
|
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,cAAc,GAAG,IAAI,CAAC;AAC5B,MAAM,UAAU,GAAG,IAAI,CAAC;AAExB,gCAAgC;AAChC,MAAM,OAAO,GAAG,IAAI,CAAC;AACrB,+CAA+C;AAC/C,MAAM,QAAQ,GAAG,IAAI,CAAC;AACtB,mEAAmE;AACnE,MAAM,OAAO,GAAG,IAAI,CAAC;AAErB,MAAM,GAAG,GAAG;IACV,WAAW,EAAE,IAAI;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AC,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;AAlLD,yBAkLC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Canton.test.d.ts","sourceRoot":"","sources":["../src/Canton.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,101 @@
|
|
|
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
|
+
const transport = await (0, hw_transport_mocker_1.openTransportReplayer)(new hw_transport_mocker_1.RecordStore());
|
|
12
|
+
const canton = new Canton_1.default(transport);
|
|
13
|
+
expect(canton.transport).toBeDefined();
|
|
14
|
+
expect(typeof canton.getAddress).toBe("function");
|
|
15
|
+
expect(typeof canton.signTransaction).toBe("function");
|
|
16
|
+
expect(typeof canton.getAppConfiguration).toBe("function");
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
describe("getAddress", () => {
|
|
20
|
+
it("should get address without display", async () => {
|
|
21
|
+
const transport = await (0, hw_transport_mocker_1.openTransportReplayer)(hw_transport_mocker_1.RecordStore.fromString(`
|
|
22
|
+
=> e005000015058000002c80001a6f800000008000000080000000
|
|
23
|
+
<= 4d65a10662b9759d62bb59048366705454654cf4f9b4b3525cf314429e46c6919000
|
|
24
|
+
`));
|
|
25
|
+
const canton = new Canton_1.default(transport);
|
|
26
|
+
const result = await canton.getAddress("44'/6767'/0'/0'/0'");
|
|
27
|
+
expect(result).toBeDefined();
|
|
28
|
+
expect(result.address).toBeDefined();
|
|
29
|
+
expect(result.publicKey).toBeDefined();
|
|
30
|
+
});
|
|
31
|
+
it("should get address with display", async () => {
|
|
32
|
+
const transport = await (0, hw_transport_mocker_1.openTransportReplayer)(hw_transport_mocker_1.RecordStore.fromString(`
|
|
33
|
+
=> e005010015058000002c80001a6f800000008000000080000000
|
|
34
|
+
<= 4d65a10662b9759d62bb59048366705454654cf4f9b4b3525cf314429e46c6919000
|
|
35
|
+
`));
|
|
36
|
+
const canton = new Canton_1.default(transport);
|
|
37
|
+
const result = await canton.getAddress("44'/6767'/0'/0'/0'", true);
|
|
38
|
+
expect(result).toBeDefined();
|
|
39
|
+
expect(result.address).toBeDefined();
|
|
40
|
+
expect(result.publicKey).toBeDefined();
|
|
41
|
+
});
|
|
42
|
+
it("should throw on invalid derivation path", async () => {
|
|
43
|
+
const transport = await (0, hw_transport_mocker_1.openTransportReplayer)(new hw_transport_mocker_1.RecordStore());
|
|
44
|
+
const canton = new Canton_1.default(transport);
|
|
45
|
+
return expect(canton.getAddress("invalid path")).rejects.toThrow();
|
|
46
|
+
});
|
|
47
|
+
it("should handle various derivation paths", async () => {
|
|
48
|
+
const transport = await (0, hw_transport_mocker_1.openTransportReplayer)(hw_transport_mocker_1.RecordStore.fromString(`
|
|
49
|
+
=> e005000015058000002c80001a6f800000008000000080000001
|
|
50
|
+
<= 5e66a10773c0860e73bb6015947806555765df5f9b5b4636df4255a57c57d7029000
|
|
51
|
+
`));
|
|
52
|
+
const canton = new Canton_1.default(transport);
|
|
53
|
+
const result = await canton.getAddress("44'/6767'/0'/0'/1'");
|
|
54
|
+
expect(result).toBeDefined();
|
|
55
|
+
expect(result.address).toBeDefined();
|
|
56
|
+
expect(result.publicKey).toBeDefined();
|
|
57
|
+
});
|
|
58
|
+
// should handle user refused address
|
|
59
|
+
});
|
|
60
|
+
describe("signTransaction", () => {
|
|
61
|
+
// should sign transaction
|
|
62
|
+
// should handle large transaction payloads
|
|
63
|
+
// should handle empty transaction
|
|
64
|
+
// should request blind signature when required
|
|
65
|
+
it("should sign transaction hash", async () => {
|
|
66
|
+
const transport = await (0, hw_transport_mocker_1.openTransportReplayer)(hw_transport_mocker_1.RecordStore.fromString(`
|
|
67
|
+
=> e006000315058000002c80001a6f800000008000000080000000
|
|
68
|
+
<= 9000
|
|
69
|
+
=> e006000020d1e98829444207b0e170346b2e80b58a2ffc602b01e190fb742016d407c84efd
|
|
70
|
+
<= 40a65f53c3657bc04efefb67a425ba093a5cb5391d18142f148bb2c48daacf316114cff920a58d5996ca828c7ce265f537f1d7fca8fa82c3c73bd944a96e701a00009000
|
|
71
|
+
`));
|
|
72
|
+
const canton = new Canton_1.default(transport);
|
|
73
|
+
const txHash = "d1e98829444207b0e170346b2e80b58a2ffc602b01e190fb742016d407c84efd";
|
|
74
|
+
const result = await canton.signTransaction("44'/6767'/0'/0'/0'", txHash);
|
|
75
|
+
expect(result).toEqual("40a65f53c3657bc04efefb67a425ba093a5cb5391d18142f148bb2c48daacf316114cff920a58d5996ca828c7ce265f537f1d7fca8fa82c3c73bd944a96e701a0000");
|
|
76
|
+
});
|
|
77
|
+
it("should handle user refused transaction", async () => {
|
|
78
|
+
const transport = await (0, hw_transport_mocker_1.openTransportReplayer)(hw_transport_mocker_1.RecordStore.fromString(`
|
|
79
|
+
=> e006010015058000002c80001a6f800000008000000080000000
|
|
80
|
+
<= 6985
|
|
81
|
+
`));
|
|
82
|
+
const canton = new Canton_1.default(transport);
|
|
83
|
+
return expect(canton.signTransaction("44'/6767'/0'/0'/0'", "test")).rejects.toThrow();
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
describe("getAppConfiguration", () => {
|
|
87
|
+
it("should get app configuration", async () => {
|
|
88
|
+
const transport = await (0, hw_transport_mocker_1.openTransportReplayer)(hw_transport_mocker_1.RecordStore.fromString(`
|
|
89
|
+
=> e003000000
|
|
90
|
+
<= 0202029000
|
|
91
|
+
`));
|
|
92
|
+
const canton = new Canton_1.default(transport);
|
|
93
|
+
const result = await canton.getAppConfiguration();
|
|
94
|
+
expect(result).toBeDefined();
|
|
95
|
+
expect(result).toHaveProperty("version");
|
|
96
|
+
expect(typeof result.version).toBe("string");
|
|
97
|
+
});
|
|
98
|
+
// should handle configuration error
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
//# 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,MAAM,SAAS,GAAG,MAAM,IAAA,2CAAqB,EAAC,IAAI,iCAAW,EAAE,CAAC,CAAC;YACjE,MAAM,MAAM,GAAG,IAAI,gBAAM,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,MAAM,CAAC,eAAe,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YACvD,MAAM,CAAC,OAAO,MAAM,CAAC,mBAAm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Config = {
|
|
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,10 +25,10 @@ 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
|
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;AA4BpD,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;IAoBhF;;;;;;OAMG;IACG,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IA6B7E;;;OAGG;IACG,mBAAmB,IAAI,OAAO,CAAC,SAAS,CAAC;IAiB/C;;;OAGG;IACH,OAAO,CAAC,uBAAuB;IAqB/B;;;OAGG;IACH,OAAO,CAAC,aAAa;IAWrB;;;OAGG;IACH,OAAO,CAAC,UAAU;IAUlB;;;OAGG;IACH,OAAO,CAAC,yBAAyB;IAYjC;;;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,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AiB,EAAE,GAAG,EAAE;QAC/B,EAAE,CAAC,0BAA0B,EAAE,KAAK,IAAI,EAAE;YACxC,QAAQ;YACR,MAAM,GAAG,GAAG,IAAI,MAAM,CAAC,SAAS,CAAC,CAAC;YAClC,MAAM,cAAc,GAAG,oBAAoB,CAAC;YAC5C,MAAM,MAAM,GAAG,kEAAkE,CAAC;YAElF,OAAO;YACP,MAAM,WAAW,GAAG,GAAG,CAAC,eAAe,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;YAEhE,iCAAiC;YACjC,MAAM,KAAK,GAAG,CAAC,EAAU,EAAiB,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;YACjF,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;YACjB,gDAAgD;YAChD,MAAM,SAAS,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;YAC5C,MAAM,SAAS,CAAC,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;YAC7C,MAAM,SAAS,CAAC,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;YAC7C,MAAM,SAAS,CAAC,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;YAC7C,MAAM,SAAS,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;YAE5C,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC;YAEjC,OAAO;YACP,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CACpB,sIAAsI,CACvI,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/lib-es/Canton.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { UserRefusedAddress, UserRefusedOnDevice } from "@ledgerhq/errors";
|
|
2
2
|
import BIPPath from "bip32-path";
|
|
3
|
-
import { MockCantonDevice } from "./MockDevice";
|
|
4
3
|
const CLA = 0xe0;
|
|
5
4
|
const P1_NON_CONFIRM = 0x00;
|
|
6
5
|
const P1_CONFIRM = 0x01;
|
|
7
|
-
|
|
6
|
+
// P2 indicating no information.
|
|
7
|
+
const P2_NONE = 0x00;
|
|
8
|
+
// P2 indicating first APDU in a large request.
|
|
9
|
+
const P2_FIRST = 0x01;
|
|
10
|
+
// P2 indicating that this is not the last APDU in a large request.
|
|
11
|
+
const P2_MORE = 0x02;
|
|
8
12
|
const INS = {
|
|
9
13
|
GET_VERSION: 0x03,
|
|
10
14
|
GET_APP_NAME: 0x04,
|
|
@@ -20,10 +24,8 @@ const STATUS = {
|
|
|
20
24
|
*/
|
|
21
25
|
export default class Canton {
|
|
22
26
|
transport;
|
|
23
|
-
transportMock;
|
|
24
27
|
constructor(transport, scrambleKey = "canton_default_scramble_key") {
|
|
25
28
|
this.transport = transport;
|
|
26
|
-
this.transportMock = new MockCantonDevice();
|
|
27
29
|
transport.decorateAppAPIMethods(this, ["getAddress", "signTransaction", "getAppConfiguration"], scrambleKey);
|
|
28
30
|
}
|
|
29
31
|
/**
|
|
@@ -37,15 +39,14 @@ export default class Canton {
|
|
|
37
39
|
const bipPath = BIPPath.fromString(path).toPathArray();
|
|
38
40
|
const serializedPath = this.serializePath(bipPath);
|
|
39
41
|
const p1 = display ? P1_CONFIRM : P1_NON_CONFIRM;
|
|
40
|
-
const response = await this.transport.send(CLA, INS.GET_ADDR, p1,
|
|
42
|
+
const response = await this.transport.send(CLA, INS.GET_ADDR, p1, P2_NONE, serializedPath);
|
|
41
43
|
const responseData = this.handleTransportResponse(response, "address");
|
|
42
44
|
const { pubKey } = this.extractPubkeyAndChainCode(responseData);
|
|
43
|
-
// Handle 65-byte uncompressed SECP256R1 public key
|
|
44
45
|
const publicKey = "0x" + pubKey;
|
|
45
46
|
const addressHash = this.hashString(publicKey);
|
|
46
47
|
const address = "canton_" + addressHash.substring(0, 36);
|
|
47
48
|
return {
|
|
48
|
-
publicKey,
|
|
49
|
+
publicKey: pubKey,
|
|
49
50
|
address,
|
|
50
51
|
};
|
|
51
52
|
}
|
|
@@ -53,16 +54,19 @@ export default class Canton {
|
|
|
53
54
|
* Sign a Canton transaction.
|
|
54
55
|
*
|
|
55
56
|
* @param path a path in BIP-32 format
|
|
56
|
-
* @param
|
|
57
|
+
* @param txHash the transaction hash to sign
|
|
57
58
|
* @return the signature
|
|
58
59
|
*/
|
|
59
|
-
async signTransaction(path,
|
|
60
|
+
async signTransaction(path, txHash) {
|
|
61
|
+
// 1. Send the derivation path
|
|
60
62
|
const bipPath = BIPPath.fromString(path).toPathArray();
|
|
61
63
|
const serializedPath = this.serializePath(bipPath);
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
+
const pathResponse = await this.transport.send(CLA, INS.SIGN, P1_NON_CONFIRM, P2_FIRST | P2_MORE, serializedPath);
|
|
65
|
+
this.handleTransportResponse(pathResponse, "transaction");
|
|
66
|
+
// 2. Send the transaction hash
|
|
67
|
+
const response = await this.transport.send(CLA, INS.SIGN, P1_NON_CONFIRM, P2_NONE, Buffer.from(txHash, "hex"));
|
|
64
68
|
const responseData = this.handleTransportResponse(response, "transaction");
|
|
65
|
-
const signature =
|
|
69
|
+
const signature = responseData.toString("hex");
|
|
66
70
|
return signature;
|
|
67
71
|
}
|
|
68
72
|
/**
|
|
@@ -70,7 +74,7 @@ export default class Canton {
|
|
|
70
74
|
* @return the app configuration including version
|
|
71
75
|
*/
|
|
72
76
|
async getAppConfiguration() {
|
|
73
|
-
const response = await this.transport.send(CLA, INS.GET_VERSION, P1_NON_CONFIRM,
|
|
77
|
+
const response = await this.transport.send(CLA, INS.GET_VERSION, P1_NON_CONFIRM, P2_NONE, Buffer.alloc(0));
|
|
74
78
|
const responseData = this.handleTransportResponse(response, "version");
|
|
75
79
|
const { major, minor, patch } = this.extractVersion(responseData);
|
|
76
80
|
return {
|