@ledgerhq/hw-app-canton 0.3.0-nightly.2 → 0.3.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/.turbo/turbo-build.log +1 -1
- package/.unimportedrc.json +2 -1
- package/CHANGELOG.md +14 -7
- package/README.md +6 -3
- package/{src → __tests__}/Canton.test.ts +1 -21
- package/lib/Canton.d.ts +5 -10
- package/lib/Canton.d.ts.map +1 -1
- package/lib/Canton.integ.test.js +4 -49
- package/lib/Canton.integ.test.js.map +1 -1
- package/lib/Canton.js +13 -17
- package/lib/Canton.js.map +1 -1
- package/lib/MockDevice.d.ts +24 -0
- package/lib/MockDevice.d.ts.map +1 -0
- package/lib/MockDevice.js +141 -0
- package/lib/MockDevice.js.map +1 -0
- package/lib-es/Canton.d.ts +5 -10
- package/lib-es/Canton.d.ts.map +1 -1
- package/lib-es/Canton.integ.test.js +4 -26
- package/lib-es/Canton.integ.test.js.map +1 -1
- package/lib-es/Canton.js +13 -17
- package/lib-es/Canton.js.map +1 -1
- package/lib-es/MockDevice.d.ts +24 -0
- package/lib-es/MockDevice.d.ts.map +1 -0
- package/lib-es/MockDevice.js +137 -0
- package/lib-es/MockDevice.js.map +1 -0
- package/package.json +6 -5
- package/src/Canton.integ.test.ts +7 -33
- package/src/Canton.ts +17 -42
- package/src/MockDevice.ts +170 -0
- package/lib/Canton.test.d.ts +0 -2
- package/lib/Canton.test.d.ts.map +0 -1
- package/lib/Canton.test.js +0 -101
- package/lib/Canton.test.js.map +0 -1
- package/lib-es/Canton.test.d.ts +0 -2
- package/lib-es/Canton.test.d.ts.map +0 -1
- package/lib-es/Canton.test.js +0 -96
- package/lib-es/Canton.test.js.map +0 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
|
|
2
|
-
> @ledgerhq/hw-app-canton@0.3.0
|
|
2
|
+
> @ledgerhq/hw-app-canton@0.3.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,24 +1,31 @@
|
|
|
1
1
|
# @ledgerhq/hw-app-canton
|
|
2
2
|
|
|
3
|
-
## 0.3.0
|
|
3
|
+
## 0.3.0
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
7
|
-
- [#
|
|
8
|
-
|
|
9
|
-
## 0.3.0-nightly.1
|
|
7
|
+
- [#11481](https://github.com/LedgerHQ/ledger-live/pull/11481) [`d571ef1`](https://github.com/LedgerHQ/ledger-live/commit/d571ef1104092e41de4dfb6dd9b26d27348b82cf) Thanks [@sprohaszka-ledger](https://github.com/sprohaszka-ledger)! - Add integration tests and communicate with a real transport implementation
|
|
10
8
|
|
|
11
9
|
### Patch Changes
|
|
12
10
|
|
|
13
|
-
- Updated dependencies [[`12277dc`](https://github.com/LedgerHQ/ledger-live/commit/12277dcb478f24152060e3e11e2eb37d650b5b60), [`
|
|
14
|
-
- @ledgerhq/coin-canton@0.4.0
|
|
11
|
+
- Updated dependencies [[`12277dc`](https://github.com/LedgerHQ/ledger-live/commit/12277dcb478f24152060e3e11e2eb37d650b5b60), [`212f772`](https://github.com/LedgerHQ/ledger-live/commit/212f772b17dc3db97009ebe62912f8f183c1ef2e), [`8936f39`](https://github.com/LedgerHQ/ledger-live/commit/8936f390edbe9cbc36ac6590b01562daf5c580e1)]:
|
|
12
|
+
- @ledgerhq/coin-canton@0.4.0
|
|
13
|
+
- @ledgerhq/errors@6.25.0
|
|
14
|
+
- @ledgerhq/hw-transport@6.31.10
|
|
15
15
|
|
|
16
|
-
## 0.3.0-
|
|
16
|
+
## 0.3.0-next.0
|
|
17
17
|
|
|
18
18
|
### Minor Changes
|
|
19
19
|
|
|
20
20
|
- [#11481](https://github.com/LedgerHQ/ledger-live/pull/11481) [`d571ef1`](https://github.com/LedgerHQ/ledger-live/commit/d571ef1104092e41de4dfb6dd9b26d27348b82cf) Thanks [@sprohaszka-ledger](https://github.com/sprohaszka-ledger)! - Add integration tests and communicate with a real transport implementation
|
|
21
21
|
|
|
22
|
+
### Patch Changes
|
|
23
|
+
|
|
24
|
+
- Updated dependencies [[`12277dc`](https://github.com/LedgerHQ/ledger-live/commit/12277dcb478f24152060e3e11e2eb37d650b5b60), [`212f772`](https://github.com/LedgerHQ/ledger-live/commit/212f772b17dc3db97009ebe62912f8f183c1ef2e), [`8936f39`](https://github.com/LedgerHQ/ledger-live/commit/8936f390edbe9cbc36ac6590b01562daf5c580e1)]:
|
|
25
|
+
- @ledgerhq/coin-canton@0.4.0-next.0
|
|
26
|
+
- @ledgerhq/errors@6.25.0-next.0
|
|
27
|
+
- @ledgerhq/hw-transport@6.31.10-next.0
|
|
28
|
+
|
|
22
29
|
## 0.2.2
|
|
23
30
|
|
|
24
31
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -32,6 +32,7 @@ For a smooth and quick integration:
|
|
|
32
32
|
* [signTransaction](#signtransaction)
|
|
33
33
|
* [Parameters](#parameters-2)
|
|
34
34
|
* [getAppConfiguration](#getappconfiguration)
|
|
35
|
+
* [MockCantonDevice](#mockcantondevice)
|
|
35
36
|
|
|
36
37
|
### Canton
|
|
37
38
|
|
|
@@ -60,7 +61,7 @@ Sign a Canton transaction.
|
|
|
60
61
|
##### Parameters
|
|
61
62
|
|
|
62
63
|
* `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** a path in BIP-32 format
|
|
63
|
-
* `
|
|
64
|
+
* `rawTx` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the raw transaction to sign
|
|
64
65
|
|
|
65
66
|
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<CantonSignature>** the signature
|
|
66
67
|
|
|
@@ -70,6 +71,10 @@ Get the app configuration.
|
|
|
70
71
|
|
|
71
72
|
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<AppConfig>** the app configuration including version
|
|
72
73
|
|
|
74
|
+
### MockCantonDevice
|
|
75
|
+
|
|
76
|
+
Mock Canton "@ledgerhq/hw-app-canton" device implementation for development and testing
|
|
77
|
+
|
|
73
78
|
## Integration tests
|
|
74
79
|
|
|
75
80
|
### 1. Prerequisite
|
|
@@ -101,5 +106,3 @@ From Ledger Live root directory:
|
|
|
101
106
|
```sh
|
|
102
107
|
pnpm ljs:hw-app-canton test-integ
|
|
103
108
|
```
|
|
104
|
-
|
|
105
|
-
You can take a look at [Speculos UI](http://127.0.0.1:5000/)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { openTransportReplayer, RecordStore } from "@ledgerhq/hw-transport-mocker";
|
|
2
|
-
import Canton from "
|
|
2
|
+
import Canton from "../src/Canton";
|
|
3
3
|
|
|
4
4
|
describe("Canton", () => {
|
|
5
5
|
describe("decorateAppAPIMethods", () => {
|
|
@@ -82,26 +82,6 @@ describe("Canton", () => {
|
|
|
82
82
|
|
|
83
83
|
// should request blind signature when required
|
|
84
84
|
|
|
85
|
-
it("should sign transaction hash", async () => {
|
|
86
|
-
const transport = await openTransportReplayer(
|
|
87
|
-
RecordStore.fromString(`
|
|
88
|
-
=> e006000315058000002c80001a6f800000008000000080000000
|
|
89
|
-
<= 9000
|
|
90
|
-
=> e006000020d1e98829444207b0e170346b2e80b58a2ffc602b01e190fb742016d407c84efd
|
|
91
|
-
<= 40a65f53c3657bc04efefb67a425ba093a5cb5391d18142f148bb2c48daacf316114cff920a58d5996ca828c7ce265f537f1d7fca8fa82c3c73bd944a96e701a00009000
|
|
92
|
-
`),
|
|
93
|
-
);
|
|
94
|
-
|
|
95
|
-
const canton = new Canton(transport);
|
|
96
|
-
const txHash = "d1e98829444207b0e170346b2e80b58a2ffc602b01e190fb742016d407c84efd";
|
|
97
|
-
|
|
98
|
-
const result = await canton.signTransaction("44'/6767'/0'/0'/0'", txHash);
|
|
99
|
-
|
|
100
|
-
expect(result).toEqual(
|
|
101
|
-
"40a65f53c3657bc04efefb67a425ba093a5cb5391d18142f148bb2c48daacf316114cff920a58d5996ca828c7ce265f537f1d7fca8fa82c3c73bd944a96e701a0000",
|
|
102
|
-
);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
85
|
it("should handle user refused transaction", async () => {
|
|
106
86
|
const transport = await openTransportReplayer(
|
|
107
87
|
RecordStore.fromString(`
|
package/lib/Canton.d.ts
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
import type Transport from "@ledgerhq/hw-transport";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
export type CantonAddress = {
|
|
6
|
-
publicKey: string;
|
|
7
|
-
address: string;
|
|
8
|
-
};
|
|
9
|
-
export type CantonSignature = string;
|
|
2
|
+
import { CantonAddress, CantonSignature } from "@ledgerhq/coin-canton";
|
|
3
|
+
import { MockCantonDevice, AppConfig } from "./MockDevice";
|
|
10
4
|
/**
|
|
11
5
|
* Canton BOLOS API
|
|
12
6
|
*/
|
|
13
7
|
export default class Canton {
|
|
14
8
|
transport: Transport;
|
|
9
|
+
transportMock: MockCantonDevice;
|
|
15
10
|
constructor(transport: Transport, scrambleKey?: string);
|
|
16
11
|
/**
|
|
17
12
|
* Get a Canton address for a given BIP-32 path.
|
|
@@ -25,10 +20,10 @@ export default class Canton {
|
|
|
25
20
|
* Sign a Canton transaction.
|
|
26
21
|
*
|
|
27
22
|
* @param path a path in BIP-32 format
|
|
28
|
-
* @param
|
|
23
|
+
* @param rawTx the raw transaction to sign
|
|
29
24
|
* @return the signature
|
|
30
25
|
*/
|
|
31
|
-
signTransaction(path: string,
|
|
26
|
+
signTransaction(path: string, rawTx: string): Promise<CantonSignature>;
|
|
32
27
|
/**
|
|
33
28
|
* Get the app configuration.
|
|
34
29
|
* @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;AAEpD,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAGvE,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAqB3D;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,MAAM;IACzB,SAAS,EAAE,SAAS,CAAC;IACrB,aAAa,EAAE,gBAAgB,CAAC;gBAEpB,SAAS,EAAE,SAAS,EAAE,WAAW,SAAgC;IAW7E;;;;;;OAMG;IACG,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,OAAe,GAAG,OAAO,CAAC,aAAa,CAAC;IAsBhF;;;;;;OAMG;IACG,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAa5E;;;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,41 +1,15 @@
|
|
|
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
|
-
};
|
|
25
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
4
|
};
|
|
28
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
const hw_transport_node_speculos_http_1 =
|
|
6
|
+
const hw_transport_node_speculos_http_1 = __importDefault(require("@ledgerhq/hw-transport-node-speculos-http"));
|
|
30
7
|
const Canton_1 = __importDefault(require("./Canton"));
|
|
31
8
|
describe("AppCanton", () => {
|
|
32
9
|
let transport;
|
|
33
10
|
beforeAll(async () => {
|
|
34
11
|
transport = await hw_transport_node_speculos_http_1.default.open({});
|
|
35
12
|
});
|
|
36
|
-
afterAll(async () => {
|
|
37
|
-
transport.close();
|
|
38
|
-
});
|
|
39
13
|
describe("getAppConfiguration", () => {
|
|
40
14
|
it("returns app version", async () => {
|
|
41
15
|
// GIVEN
|
|
@@ -57,32 +31,13 @@ describe("AppCanton", () => {
|
|
|
57
31
|
const result = await app.getAddress(derivationPath);
|
|
58
32
|
// THEN
|
|
59
33
|
expect(result).toEqual({
|
|
60
|
-
address: "
|
|
61
|
-
publicKey: "
|
|
34
|
+
address: "canton_10cd9ed0",
|
|
35
|
+
publicKey: "0x043b462de34ec31fba274f2a381947aef26697912194312fc289c46cc1b2b4f6b00828dc1e4f96001b10463083edf85f2e0550862a3dc99ed411ca6d25f2bc19a8",
|
|
62
36
|
});
|
|
63
37
|
});
|
|
64
38
|
});
|
|
65
39
|
describe("signTransaction", () => {
|
|
66
|
-
it("returns sign transaction"
|
|
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
|
-
});
|
|
40
|
+
it.todo("returns sign transaction");
|
|
86
41
|
});
|
|
87
42
|
});
|
|
88
43
|
//# 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,gHAA8E;AAC9E,sDAA8B;AAG9B,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;IACzB,IAAI,SAAoB,CAAC;IAEzB,SAAS,CAAC,KAAK,IAAI,EAAE;QACnB,SAAS,GAAG,MAAM,yCAAqB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACnD,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,CAAC;gBACrB,OAAO,EAAE,iBAAiB;gBAC1B,SAAS,EACP,sIAAsI;aACzI,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;QAC/B,EAAE,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/lib/Canton.js
CHANGED
|
@@ -5,15 +5,11 @@ 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");
|
|
8
9
|
const CLA = 0xe0;
|
|
9
10
|
const P1_NON_CONFIRM = 0x00;
|
|
10
11
|
const P1_CONFIRM = 0x01;
|
|
11
|
-
|
|
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;
|
|
12
|
+
const P2 = 0x00;
|
|
17
13
|
const INS = {
|
|
18
14
|
GET_VERSION: 0x03,
|
|
19
15
|
GET_APP_NAME: 0x04,
|
|
@@ -29,8 +25,10 @@ const STATUS = {
|
|
|
29
25
|
*/
|
|
30
26
|
class Canton {
|
|
31
27
|
transport;
|
|
28
|
+
transportMock;
|
|
32
29
|
constructor(transport, scrambleKey = "canton_default_scramble_key") {
|
|
33
30
|
this.transport = transport;
|
|
31
|
+
this.transportMock = new MockDevice_1.MockCantonDevice();
|
|
34
32
|
transport.decorateAppAPIMethods(this, ["getAddress", "signTransaction", "getAppConfiguration"], scrambleKey);
|
|
35
33
|
}
|
|
36
34
|
/**
|
|
@@ -44,14 +42,15 @@ class Canton {
|
|
|
44
42
|
const bipPath = bip32_path_1.default.fromString(path).toPathArray();
|
|
45
43
|
const serializedPath = this.serializePath(bipPath);
|
|
46
44
|
const p1 = display ? P1_CONFIRM : P1_NON_CONFIRM;
|
|
47
|
-
const response = await this.transport.send(CLA, INS.GET_ADDR, p1,
|
|
45
|
+
const response = await this.transport.send(CLA, INS.GET_ADDR, p1, P2, serializedPath);
|
|
48
46
|
const responseData = this.handleTransportResponse(response, "address");
|
|
49
47
|
const { pubKey } = this.extractPubkeyAndChainCode(responseData);
|
|
48
|
+
// Handle 65-byte uncompressed SECP256R1 public key
|
|
50
49
|
const publicKey = "0x" + pubKey;
|
|
51
50
|
const addressHash = this.hashString(publicKey);
|
|
52
51
|
const address = "canton_" + addressHash.substring(0, 36);
|
|
53
52
|
return {
|
|
54
|
-
publicKey
|
|
53
|
+
publicKey,
|
|
55
54
|
address,
|
|
56
55
|
};
|
|
57
56
|
}
|
|
@@ -59,19 +58,16 @@ class Canton {
|
|
|
59
58
|
* Sign a Canton transaction.
|
|
60
59
|
*
|
|
61
60
|
* @param path a path in BIP-32 format
|
|
62
|
-
* @param
|
|
61
|
+
* @param rawTx the raw transaction to sign
|
|
63
62
|
* @return the signature
|
|
64
63
|
*/
|
|
65
|
-
async signTransaction(path,
|
|
66
|
-
// 1. Send the derivation path
|
|
64
|
+
async signTransaction(path, rawTx) {
|
|
67
65
|
const bipPath = bip32_path_1.default.fromString(path).toPathArray();
|
|
68
66
|
const serializedPath = this.serializePath(bipPath);
|
|
69
|
-
const
|
|
70
|
-
this.
|
|
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"));
|
|
67
|
+
const payload = Buffer.concat([serializedPath, Buffer.from(rawTx, "hex")]);
|
|
68
|
+
const response = await this.transportMock.send(CLA, INS.SIGN, P1_CONFIRM, P2, payload);
|
|
73
69
|
const responseData = this.handleTransportResponse(response, "transaction");
|
|
74
|
-
const signature = responseData.toString("hex");
|
|
70
|
+
const signature = "0x" + responseData.toString("hex");
|
|
75
71
|
return signature;
|
|
76
72
|
}
|
|
77
73
|
/**
|
|
@@ -79,7 +75,7 @@ class Canton {
|
|
|
79
75
|
* @return the app configuration including version
|
|
80
76
|
*/
|
|
81
77
|
async getAppConfiguration() {
|
|
82
|
-
const response = await this.transport.send(CLA, INS.GET_VERSION, P1_NON_CONFIRM,
|
|
78
|
+
const response = await this.transport.send(CLA, INS.GET_VERSION, P1_NON_CONFIRM, P2, Buffer.alloc(0));
|
|
83
79
|
const responseData = this.handleTransportResponse(response, "version");
|
|
84
80
|
const { major, minor, patch } = this.extractVersion(responseData);
|
|
85
81
|
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;AAE3E,4DAAiC;AAEjC,6CAA2D;AAE3D,MAAM,GAAG,GAAG,IAAI,CAAC;AAEjB,MAAM,cAAc,GAAG,IAAI,CAAC;AAC5B,MAAM,UAAU,GAAG,IAAI,CAAC;AAExB,MAAM,EAAE,GAAG,IAAI,CAAC;AAEhB,MAAM,GAAG,GAAG;IACV,WAAW,EAAE,IAAI;IACjB,YAAY,EAAE,IAAI;IAClB,QAAQ,EAAE,IAAI;IACd,IAAI,EAAE,IAAI;CACX,CAAC;AAEF,MAAM,MAAM,GAAG;IACb,EAAE,EAAE,MAAM;IACV,WAAW,EAAE,MAAM;CACpB,CAAC;AAEF;;GAEG;AACH,MAAqB,MAAM;IACzB,SAAS,CAAY;IACrB,aAAa,CAAmB;IAEhC,YAAY,SAAoB,EAAE,WAAW,GAAG,6BAA6B;QAC3E,IAAI,CAAC,SAAS,GAAG,SAAS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,CAAC;CACF;AAtKD,yBAsKC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
export type AppConfig = {
|
|
4
|
+
version: string;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Mock Canton "@ledgerhq/hw-app-canton" device implementation for development and testing
|
|
8
|
+
*/
|
|
9
|
+
export declare class MockCantonDevice {
|
|
10
|
+
private mockAddresses;
|
|
11
|
+
private mockSignatures;
|
|
12
|
+
constructor();
|
|
13
|
+
send(cla: number, ins: number, p1: number, p2: number, data: Buffer): Promise<Buffer>;
|
|
14
|
+
private getAddressResponse;
|
|
15
|
+
private signTransactionResponse;
|
|
16
|
+
private getAppConfigurationResponse;
|
|
17
|
+
private parsePathFromData;
|
|
18
|
+
private simulateDeviceDelay;
|
|
19
|
+
/**
|
|
20
|
+
* Simple deterministic hash function for generating mock data
|
|
21
|
+
*/
|
|
22
|
+
private hashString;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=MockDevice.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MockDevice.d.ts","sourceRoot":"","sources":["../src/MockDevice.ts"],"names":[],"mappings":";;AAaA,MAAM,MAAM,SAAS,GAAG;IACtB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAsBF;;GAEG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,aAAa,CAAyC;IAC9D,OAAO,CAAC,cAAc,CAA2C;;IAS3D,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;YAa7E,kBAAkB;YAiClB,uBAAuB;YA0BvB,2BAA2B;IAYzC,OAAO,CAAC,iBAAiB;YAkBX,mBAAmB;IAIjC;;OAEG;IACH,OAAO,CAAC,UAAU;CASnB"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MockCantonDevice = void 0;
|
|
4
|
+
const INS = {
|
|
5
|
+
GET_VERSION: 0x04,
|
|
6
|
+
GET_ADDR: 0x05,
|
|
7
|
+
SIGN: 0x06,
|
|
8
|
+
};
|
|
9
|
+
const STATUS = {
|
|
10
|
+
OK: 0x9000,
|
|
11
|
+
USER_CANCEL: 0x6985,
|
|
12
|
+
};
|
|
13
|
+
// SECP256R1-compatible mock addresses
|
|
14
|
+
const SECP256R1_MOCK_ADDRESSES = {
|
|
15
|
+
"44'/6767'/0'/0'/0'": {
|
|
16
|
+
// Uncompressed SECP256R1 public key (65 bytes: 0x04 + 32-byte X + 32-byte Y)
|
|
17
|
+
publicKey: "0x04" +
|
|
18
|
+
"1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef" +
|
|
19
|
+
"abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890",
|
|
20
|
+
address: "canton_1a2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p7q8r9s0t1u2v3w4x5y6z",
|
|
21
|
+
},
|
|
22
|
+
"44'/6767'/0'/0'/1'": {
|
|
23
|
+
// Another valid SECP256R1 public key
|
|
24
|
+
publicKey: "0x04" +
|
|
25
|
+
"abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890" +
|
|
26
|
+
"1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcd",
|
|
27
|
+
address: "canton_2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p7q8r9s0t1u2v3w4x5y6z7a",
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Mock Canton "@ledgerhq/hw-app-canton" device implementation for development and testing
|
|
32
|
+
*/
|
|
33
|
+
class MockCantonDevice {
|
|
34
|
+
mockAddresses = new Map();
|
|
35
|
+
mockSignatures = new Map();
|
|
36
|
+
constructor() {
|
|
37
|
+
// Initialize with SECP256R1-compatible addresses
|
|
38
|
+
Object.entries(SECP256R1_MOCK_ADDRESSES).forEach(([path, address]) => {
|
|
39
|
+
this.mockAddresses.set(path, address);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
async send(cla, ins, p1, p2, data) {
|
|
43
|
+
switch (ins) {
|
|
44
|
+
case INS.GET_ADDR:
|
|
45
|
+
return this.getAddressResponse(data);
|
|
46
|
+
case INS.SIGN:
|
|
47
|
+
return this.signTransactionResponse(data);
|
|
48
|
+
case INS.GET_VERSION:
|
|
49
|
+
return this.getAppConfigurationResponse();
|
|
50
|
+
default:
|
|
51
|
+
throw new Error(`Unsupported instruction: ${ins}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async getAddressResponse(data) {
|
|
55
|
+
await this.simulateDeviceDelay();
|
|
56
|
+
// Parse the path from the data
|
|
57
|
+
const pathData = data.slice(1); // Skip length byte
|
|
58
|
+
const path = this.parsePathFromData(pathData);
|
|
59
|
+
const mockAddress = this.mockAddresses.get(path);
|
|
60
|
+
if (!mockAddress) {
|
|
61
|
+
// Generate SECP256R1-compatible mock address
|
|
62
|
+
const pathHash = this.hashString(path);
|
|
63
|
+
const newAddress = {
|
|
64
|
+
// Create valid uncompressed SECP256R1 public key format
|
|
65
|
+
publicKey: "0x04" +
|
|
66
|
+
pathHash.substring(0, 64).padEnd(64, "0") +
|
|
67
|
+
pathHash.substring(64, 128).padEnd(64, "0"),
|
|
68
|
+
address: `canton_${pathHash.substring(0, 36)}`,
|
|
69
|
+
};
|
|
70
|
+
this.mockAddresses.set(path, newAddress);
|
|
71
|
+
}
|
|
72
|
+
const address = this.mockAddresses.get(path);
|
|
73
|
+
// Return 65-byte uncompressed public key (0x04 + 32-byte X + 32-byte Y)
|
|
74
|
+
const publicKeyBytes = Buffer.from(address.publicKey.slice(2), "hex");
|
|
75
|
+
const response = Buffer.alloc(65 + 2);
|
|
76
|
+
publicKeyBytes.copy(response, 0);
|
|
77
|
+
response.writeUInt16BE(STATUS.OK, 65);
|
|
78
|
+
return response;
|
|
79
|
+
}
|
|
80
|
+
async signTransactionResponse(data) {
|
|
81
|
+
await this.simulateDeviceDelay();
|
|
82
|
+
// Parse the path and transaction from the data
|
|
83
|
+
const pathData = data.slice(0, 21); // First 21 bytes are path
|
|
84
|
+
const txData = data.slice(21); // Rest is transaction data
|
|
85
|
+
const path = this.parsePathFromData(pathData);
|
|
86
|
+
const signatureKey = `${path}:${txData.toString("hex")}`;
|
|
87
|
+
let signature = this.mockSignatures.get(signatureKey);
|
|
88
|
+
if (!signature) {
|
|
89
|
+
// Generate SECP256R1-compatible mock signature (64 bytes: r + s)
|
|
90
|
+
const combinedHash = this.hashString(signatureKey);
|
|
91
|
+
signature = `0x${combinedHash.substring(0, 64).padEnd(64, "0")}`;
|
|
92
|
+
this.mockSignatures.set(signatureKey, signature);
|
|
93
|
+
}
|
|
94
|
+
// Return 64-byte signature (r + s components)
|
|
95
|
+
const response = Buffer.alloc(64 + 2);
|
|
96
|
+
Buffer.from(signature.slice(2), "hex").copy(response, 0); // Remove '0x' prefix
|
|
97
|
+
response.writeUInt16BE(STATUS.OK, 64);
|
|
98
|
+
return response;
|
|
99
|
+
}
|
|
100
|
+
async getAppConfigurationResponse() {
|
|
101
|
+
await this.simulateDeviceDelay();
|
|
102
|
+
// Create response buffer: version data + status code
|
|
103
|
+
const versionData = Buffer.from([0x00, 0x01, 0x00, 0x06]); // Version 0.1.0
|
|
104
|
+
const response = Buffer.alloc(versionData.length + 2);
|
|
105
|
+
versionData.copy(response, 0);
|
|
106
|
+
response.writeUInt16BE(STATUS.OK, versionData.length);
|
|
107
|
+
return response;
|
|
108
|
+
}
|
|
109
|
+
parsePathFromData(data) {
|
|
110
|
+
// Convert the path data back to a BIP32 path string
|
|
111
|
+
const segments = [];
|
|
112
|
+
for (let i = 0; i < data.length; i += 4) {
|
|
113
|
+
const segment = data.readUInt32BE(i);
|
|
114
|
+
segments.push(segment);
|
|
115
|
+
}
|
|
116
|
+
// Convert to BIP32 path string
|
|
117
|
+
const pathParts = segments.map(seg => {
|
|
118
|
+
const isHardened = (seg & 0x80000000) !== 0;
|
|
119
|
+
const value = seg & 0x7fffffff;
|
|
120
|
+
return isHardened ? `${value}'` : `${value}`;
|
|
121
|
+
});
|
|
122
|
+
return pathParts.join("/");
|
|
123
|
+
}
|
|
124
|
+
async simulateDeviceDelay() {
|
|
125
|
+
await new Promise(resolve => setTimeout(resolve, 50));
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Simple deterministic hash function for generating mock data
|
|
129
|
+
*/
|
|
130
|
+
hashString(str) {
|
|
131
|
+
let hash = 0;
|
|
132
|
+
for (let i = 0; i < str.length; i++) {
|
|
133
|
+
const char = str.charCodeAt(i);
|
|
134
|
+
hash = (hash << 5) - hash + char;
|
|
135
|
+
hash = hash & hash; // Convert to 32-bit integer
|
|
136
|
+
}
|
|
137
|
+
return Math.abs(hash).toString(16);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
exports.MockCantonDevice = MockCantonDevice;
|
|
141
|
+
//# sourceMappingURL=MockDevice.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MockDevice.js","sourceRoot":"","sources":["../src/MockDevice.ts"],"names":[],"mappings":";;;AAEA,MAAM,GAAG,GAAG;IACV,WAAW,EAAE,IAAI;IACjB,QAAQ,EAAE,IAAI;IACd,IAAI,EAAE,IAAI;CACX,CAAC;AAEF,MAAM,MAAM,GAAG;IACb,EAAE,EAAE,MAAM;IACV,WAAW,EAAE,MAAM;CACpB,CAAC;AAMF,sCAAsC;AACtC,MAAM,wBAAwB,GAAG;IAC/B,oBAAoB,EAAE;QACpB,6EAA6E;QAC7E,SAAS,EACP,MAAM;YACN,kEAAkE;YAClE,kEAAkE;QACpE,OAAO,EAAE,6DAA6D;KACvE;IACD,oBAAoB,EAAE;QACpB,qCAAqC;QACrC,SAAS,EACP,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AC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACpC,MAAM,IAAI,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;YAC/B,IAAI,GAAG,CAAC,IAAI,IAAI,CAAC,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;YACjC,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC,4BAA4B;QAClD,CAAC;QACD,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACrC,CAAC;CACF;AAjID,4CAiIC"}
|
package/lib-es/Canton.d.ts
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
import type Transport from "@ledgerhq/hw-transport";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
export type CantonAddress = {
|
|
6
|
-
publicKey: string;
|
|
7
|
-
address: string;
|
|
8
|
-
};
|
|
9
|
-
export type CantonSignature = string;
|
|
2
|
+
import { CantonAddress, CantonSignature } from "@ledgerhq/coin-canton";
|
|
3
|
+
import { MockCantonDevice, AppConfig } from "./MockDevice";
|
|
10
4
|
/**
|
|
11
5
|
* Canton BOLOS API
|
|
12
6
|
*/
|
|
13
7
|
export default class Canton {
|
|
14
8
|
transport: Transport;
|
|
9
|
+
transportMock: MockCantonDevice;
|
|
15
10
|
constructor(transport: Transport, scrambleKey?: string);
|
|
16
11
|
/**
|
|
17
12
|
* Get a Canton address for a given BIP-32 path.
|
|
@@ -25,10 +20,10 @@ export default class Canton {
|
|
|
25
20
|
* Sign a Canton transaction.
|
|
26
21
|
*
|
|
27
22
|
* @param path a path in BIP-32 format
|
|
28
|
-
* @param
|
|
23
|
+
* @param rawTx the raw transaction to sign
|
|
29
24
|
* @return the signature
|
|
30
25
|
*/
|
|
31
|
-
signTransaction(path: string,
|
|
26
|
+
signTransaction(path: string, rawTx: string): Promise<CantonSignature>;
|
|
32
27
|
/**
|
|
33
28
|
* Get the app configuration.
|
|
34
29
|
* @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;AAEpD,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAGvE,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAqB3D;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,MAAM;IACzB,SAAS,EAAE,SAAS,CAAC;IACrB,aAAa,EAAE,gBAAgB,CAAC;gBAEpB,SAAS,EAAE,SAAS,EAAE,WAAW,SAAgC;IAW7E;;;;;;OAMG;IACG,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,OAAe,GAAG,OAAO,CAAC,aAAa,CAAC;IAsBhF;;;;;;OAMG;IACG,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAa5E;;;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,13 +1,10 @@
|
|
|
1
|
-
import SpeculosTransportHttp
|
|
1
|
+
import SpeculosTransportHttp 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
|
-
});
|
|
11
8
|
describe("getAppConfiguration", () => {
|
|
12
9
|
it("returns app version", async () => {
|
|
13
10
|
// GIVEN
|
|
@@ -29,32 +26,13 @@ describe("AppCanton", () => {
|
|
|
29
26
|
const result = await app.getAddress(derivationPath);
|
|
30
27
|
// THEN
|
|
31
28
|
expect(result).toEqual({
|
|
32
|
-
address: "
|
|
33
|
-
publicKey: "
|
|
29
|
+
address: "canton_10cd9ed0",
|
|
30
|
+
publicKey: "0x043b462de34ec31fba274f2a381947aef26697912194312fc289c46cc1b2b4f6b00828dc1e4f96001b10463083edf85f2e0550862a3dc99ed411ca6d25f2bc19a8",
|
|
34
31
|
});
|
|
35
32
|
});
|
|
36
33
|
});
|
|
37
34
|
describe("signTransaction", () => {
|
|
38
|
-
it("returns sign transaction"
|
|
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
|
-
});
|
|
35
|
+
it.todo("returns sign transaction");
|
|
58
36
|
});
|
|
59
37
|
});
|
|
60
38
|
//# sourceMappingURL=Canton.integ.test.js.map
|