@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
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { CantonAddress, CantonSignature } from "@ledgerhq/coin-canton";
|
|
2
|
+
|
|
3
|
+
const INS = {
|
|
4
|
+
GET_VERSION: 0x04,
|
|
5
|
+
GET_ADDR: 0x05,
|
|
6
|
+
SIGN: 0x06,
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const STATUS = {
|
|
10
|
+
OK: 0x9000,
|
|
11
|
+
USER_CANCEL: 0x6985,
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type AppConfig = {
|
|
15
|
+
version: string;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// SECP256R1-compatible mock addresses
|
|
19
|
+
const SECP256R1_MOCK_ADDRESSES = {
|
|
20
|
+
"44'/6767'/0'/0'/0'": {
|
|
21
|
+
// Uncompressed SECP256R1 public key (65 bytes: 0x04 + 32-byte X + 32-byte Y)
|
|
22
|
+
publicKey:
|
|
23
|
+
"0x04" +
|
|
24
|
+
"1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef" +
|
|
25
|
+
"abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890",
|
|
26
|
+
address: "canton_1a2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p7q8r9s0t1u2v3w4x5y6z",
|
|
27
|
+
},
|
|
28
|
+
"44'/6767'/0'/0'/1'": {
|
|
29
|
+
// Another valid SECP256R1 public key
|
|
30
|
+
publicKey:
|
|
31
|
+
"0x04" +
|
|
32
|
+
"abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890" +
|
|
33
|
+
"1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcd",
|
|
34
|
+
address: "canton_2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p7q8r9s0t1u2v3w4x5y6z7a",
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Mock Canton "@ledgerhq/hw-app-canton" device implementation for development and testing
|
|
40
|
+
*/
|
|
41
|
+
export class MockCantonDevice {
|
|
42
|
+
private mockAddresses: Map<string, CantonAddress> = new Map();
|
|
43
|
+
private mockSignatures: Map<string, CantonSignature> = new Map();
|
|
44
|
+
|
|
45
|
+
constructor() {
|
|
46
|
+
// Initialize with SECP256R1-compatible addresses
|
|
47
|
+
Object.entries(SECP256R1_MOCK_ADDRESSES).forEach(([path, address]) => {
|
|
48
|
+
this.mockAddresses.set(path, address);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async send(cla: number, ins: number, p1: number, p2: number, data: Buffer): Promise<Buffer> {
|
|
53
|
+
switch (ins) {
|
|
54
|
+
case INS.GET_ADDR:
|
|
55
|
+
return this.getAddressResponse(data);
|
|
56
|
+
case INS.SIGN:
|
|
57
|
+
return this.signTransactionResponse(data);
|
|
58
|
+
case INS.GET_VERSION:
|
|
59
|
+
return this.getAppConfigurationResponse();
|
|
60
|
+
default:
|
|
61
|
+
throw new Error(`Unsupported instruction: ${ins}`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private async getAddressResponse(data: Buffer): Promise<Buffer> {
|
|
66
|
+
await this.simulateDeviceDelay();
|
|
67
|
+
|
|
68
|
+
// Parse the path from the data
|
|
69
|
+
const pathData = data.slice(1); // Skip length byte
|
|
70
|
+
const path = this.parsePathFromData(pathData);
|
|
71
|
+
|
|
72
|
+
const mockAddress = this.mockAddresses.get(path);
|
|
73
|
+
if (!mockAddress) {
|
|
74
|
+
// Generate SECP256R1-compatible mock address
|
|
75
|
+
const pathHash = this.hashString(path);
|
|
76
|
+
const newAddress: CantonAddress = {
|
|
77
|
+
// Create valid uncompressed SECP256R1 public key format
|
|
78
|
+
publicKey:
|
|
79
|
+
"0x04" +
|
|
80
|
+
pathHash.substring(0, 64).padEnd(64, "0") +
|
|
81
|
+
pathHash.substring(64, 128).padEnd(64, "0"),
|
|
82
|
+
address: `canton_${pathHash.substring(0, 36)}`,
|
|
83
|
+
};
|
|
84
|
+
this.mockAddresses.set(path, newAddress);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const address = this.mockAddresses.get(path)!;
|
|
88
|
+
|
|
89
|
+
// Return 65-byte uncompressed public key (0x04 + 32-byte X + 32-byte Y)
|
|
90
|
+
const publicKeyBytes = Buffer.from(address.publicKey.slice(2), "hex");
|
|
91
|
+
const response = Buffer.alloc(65 + 2);
|
|
92
|
+
publicKeyBytes.copy(response, 0);
|
|
93
|
+
response.writeUInt16BE(STATUS.OK, 65);
|
|
94
|
+
|
|
95
|
+
return response;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
private async signTransactionResponse(data: Buffer): Promise<Buffer> {
|
|
99
|
+
await this.simulateDeviceDelay();
|
|
100
|
+
|
|
101
|
+
// Parse the path and transaction from the data
|
|
102
|
+
const pathData = data.slice(0, 21); // First 21 bytes are path
|
|
103
|
+
const txData = data.slice(21); // Rest is transaction data
|
|
104
|
+
const path = this.parsePathFromData(pathData);
|
|
105
|
+
|
|
106
|
+
const signatureKey = `${path}:${txData.toString("hex")}`;
|
|
107
|
+
let signature = this.mockSignatures.get(signatureKey);
|
|
108
|
+
|
|
109
|
+
if (!signature) {
|
|
110
|
+
// Generate SECP256R1-compatible mock signature (64 bytes: r + s)
|
|
111
|
+
const combinedHash = this.hashString(signatureKey);
|
|
112
|
+
signature = `0x${combinedHash.substring(0, 64).padEnd(64, "0")}`;
|
|
113
|
+
this.mockSignatures.set(signatureKey, signature);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Return 64-byte signature (r + s components)
|
|
117
|
+
const response = Buffer.alloc(64 + 2);
|
|
118
|
+
Buffer.from(signature.slice(2), "hex").copy(response, 0); // Remove '0x' prefix
|
|
119
|
+
response.writeUInt16BE(STATUS.OK, 64);
|
|
120
|
+
|
|
121
|
+
return response;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
private async getAppConfigurationResponse(): Promise<Buffer> {
|
|
125
|
+
await this.simulateDeviceDelay();
|
|
126
|
+
|
|
127
|
+
// Create response buffer: version data + status code
|
|
128
|
+
const versionData = Buffer.from([0x00, 0x01, 0x00, 0x06]); // Version 0.1.0
|
|
129
|
+
const response = Buffer.alloc(versionData.length + 2);
|
|
130
|
+
versionData.copy(response, 0);
|
|
131
|
+
response.writeUInt16BE(STATUS.OK, versionData.length);
|
|
132
|
+
|
|
133
|
+
return response;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
private parsePathFromData(data: Buffer): string {
|
|
137
|
+
// Convert the path data back to a BIP32 path string
|
|
138
|
+
const segments: number[] = [];
|
|
139
|
+
for (let i = 0; i < data.length; i += 4) {
|
|
140
|
+
const segment = data.readUInt32BE(i);
|
|
141
|
+
segments.push(segment);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Convert to BIP32 path string
|
|
145
|
+
const pathParts = segments.map(seg => {
|
|
146
|
+
const isHardened = (seg & 0x80000000) !== 0;
|
|
147
|
+
const value = seg & 0x7fffffff;
|
|
148
|
+
return isHardened ? `${value}'` : `${value}`;
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
return pathParts.join("/");
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
private async simulateDeviceDelay(): Promise<void> {
|
|
155
|
+
await new Promise(resolve => setTimeout(resolve, 50));
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Simple deterministic hash function for generating mock data
|
|
160
|
+
*/
|
|
161
|
+
private hashString(str: string): string {
|
|
162
|
+
let hash = 0;
|
|
163
|
+
for (let i = 0; i < str.length; i++) {
|
|
164
|
+
const char = str.charCodeAt(i);
|
|
165
|
+
hash = (hash << 5) - hash + char;
|
|
166
|
+
hash = hash & hash; // Convert to 32-bit integer
|
|
167
|
+
}
|
|
168
|
+
return Math.abs(hash).toString(16);
|
|
169
|
+
}
|
|
170
|
+
}
|
package/lib/Canton.test.d.ts
DELETED
package/lib/Canton.test.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Canton.test.d.ts","sourceRoot":"","sources":["../src/Canton.test.ts"],"names":[],"mappings":""}
|
package/lib/Canton.test.js
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
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
|
package/lib/Canton.test.js.map
DELETED
|
@@ -1 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AA8B,EAAE,KAAK,IAAI,EAAE;YAC5C,MAAM,SAAS,GAAG,MAAM,IAAA,2CAAqB,EAC3C,iCAAW,CAAC,UAAU,CAAC;;;SAGtB,CAAC,CACH,CAAC;YAEF,MAAM,MAAM,GAAG,IAAI,gBAAM,CAAC,SAAS,CAAC,CAAC;YACrC,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,mBAAmB,EAAE,CAAC;YAElD,MAAM,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC;YAC7B,MAAM,CAAC,MAAM,CAAC,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;YACzC,MAAM,CAAC,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC/C,CAAC,CAAC,CAAC;QAEH,oCAAoC;IACtC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/lib-es/Canton.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Canton.test.d.ts","sourceRoot":"","sources":["../src/Canton.test.ts"],"names":[],"mappings":""}
|
package/lib-es/Canton.test.js
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { openTransportReplayer, RecordStore } from "@ledgerhq/hw-transport-mocker";
|
|
2
|
-
import Canton from "./Canton";
|
|
3
|
-
describe("Canton", () => {
|
|
4
|
-
describe("decorateAppAPIMethods", () => {
|
|
5
|
-
it("should properly decorate transport methods", async () => {
|
|
6
|
-
const transport = await openTransportReplayer(new RecordStore());
|
|
7
|
-
const canton = new Canton(transport);
|
|
8
|
-
expect(canton.transport).toBeDefined();
|
|
9
|
-
expect(typeof canton.getAddress).toBe("function");
|
|
10
|
-
expect(typeof canton.signTransaction).toBe("function");
|
|
11
|
-
expect(typeof canton.getAppConfiguration).toBe("function");
|
|
12
|
-
});
|
|
13
|
-
});
|
|
14
|
-
describe("getAddress", () => {
|
|
15
|
-
it("should get address without display", async () => {
|
|
16
|
-
const transport = await openTransportReplayer(RecordStore.fromString(`
|
|
17
|
-
=> e005000015058000002c80001a6f800000008000000080000000
|
|
18
|
-
<= 4d65a10662b9759d62bb59048366705454654cf4f9b4b3525cf314429e46c6919000
|
|
19
|
-
`));
|
|
20
|
-
const canton = new Canton(transport);
|
|
21
|
-
const result = await canton.getAddress("44'/6767'/0'/0'/0'");
|
|
22
|
-
expect(result).toBeDefined();
|
|
23
|
-
expect(result.address).toBeDefined();
|
|
24
|
-
expect(result.publicKey).toBeDefined();
|
|
25
|
-
});
|
|
26
|
-
it("should get address with display", async () => {
|
|
27
|
-
const transport = await openTransportReplayer(RecordStore.fromString(`
|
|
28
|
-
=> e005010015058000002c80001a6f800000008000000080000000
|
|
29
|
-
<= 4d65a10662b9759d62bb59048366705454654cf4f9b4b3525cf314429e46c6919000
|
|
30
|
-
`));
|
|
31
|
-
const canton = new Canton(transport);
|
|
32
|
-
const result = await canton.getAddress("44'/6767'/0'/0'/0'", true);
|
|
33
|
-
expect(result).toBeDefined();
|
|
34
|
-
expect(result.address).toBeDefined();
|
|
35
|
-
expect(result.publicKey).toBeDefined();
|
|
36
|
-
});
|
|
37
|
-
it("should throw on invalid derivation path", async () => {
|
|
38
|
-
const transport = await openTransportReplayer(new RecordStore());
|
|
39
|
-
const canton = new Canton(transport);
|
|
40
|
-
return expect(canton.getAddress("invalid path")).rejects.toThrow();
|
|
41
|
-
});
|
|
42
|
-
it("should handle various derivation paths", async () => {
|
|
43
|
-
const transport = await openTransportReplayer(RecordStore.fromString(`
|
|
44
|
-
=> e005000015058000002c80001a6f800000008000000080000001
|
|
45
|
-
<= 5e66a10773c0860e73bb6015947806555765df5f9b5b4636df4255a57c57d7029000
|
|
46
|
-
`));
|
|
47
|
-
const canton = new Canton(transport);
|
|
48
|
-
const result = await canton.getAddress("44'/6767'/0'/0'/1'");
|
|
49
|
-
expect(result).toBeDefined();
|
|
50
|
-
expect(result.address).toBeDefined();
|
|
51
|
-
expect(result.publicKey).toBeDefined();
|
|
52
|
-
});
|
|
53
|
-
// should handle user refused address
|
|
54
|
-
});
|
|
55
|
-
describe("signTransaction", () => {
|
|
56
|
-
// should sign transaction
|
|
57
|
-
// should handle large transaction payloads
|
|
58
|
-
// should handle empty transaction
|
|
59
|
-
// should request blind signature when required
|
|
60
|
-
it("should sign transaction hash", async () => {
|
|
61
|
-
const transport = await openTransportReplayer(RecordStore.fromString(`
|
|
62
|
-
=> e006000315058000002c80001a6f800000008000000080000000
|
|
63
|
-
<= 9000
|
|
64
|
-
=> e006000020d1e98829444207b0e170346b2e80b58a2ffc602b01e190fb742016d407c84efd
|
|
65
|
-
<= 40a65f53c3657bc04efefb67a425ba093a5cb5391d18142f148bb2c48daacf316114cff920a58d5996ca828c7ce265f537f1d7fca8fa82c3c73bd944a96e701a00009000
|
|
66
|
-
`));
|
|
67
|
-
const canton = new Canton(transport);
|
|
68
|
-
const txHash = "d1e98829444207b0e170346b2e80b58a2ffc602b01e190fb742016d407c84efd";
|
|
69
|
-
const result = await canton.signTransaction("44'/6767'/0'/0'/0'", txHash);
|
|
70
|
-
expect(result).toEqual("40a65f53c3657bc04efefb67a425ba093a5cb5391d18142f148bb2c48daacf316114cff920a58d5996ca828c7ce265f537f1d7fca8fa82c3c73bd944a96e701a0000");
|
|
71
|
-
});
|
|
72
|
-
it("should handle user refused transaction", async () => {
|
|
73
|
-
const transport = await openTransportReplayer(RecordStore.fromString(`
|
|
74
|
-
=> e006010015058000002c80001a6f800000008000000080000000
|
|
75
|
-
<= 6985
|
|
76
|
-
`));
|
|
77
|
-
const canton = new Canton(transport);
|
|
78
|
-
return expect(canton.signTransaction("44'/6767'/0'/0'/0'", "test")).rejects.toThrow();
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
describe("getAppConfiguration", () => {
|
|
82
|
-
it("should get app configuration", async () => {
|
|
83
|
-
const transport = await openTransportReplayer(RecordStore.fromString(`
|
|
84
|
-
=> e003000000
|
|
85
|
-
<= 0202029000
|
|
86
|
-
`));
|
|
87
|
-
const canton = new Canton(transport);
|
|
88
|
-
const result = await canton.getAppConfiguration();
|
|
89
|
-
expect(result).toBeDefined();
|
|
90
|
-
expect(result).toHaveProperty("version");
|
|
91
|
-
expect(typeof result.version).toBe("string");
|
|
92
|
-
});
|
|
93
|
-
// should handle configuration error
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
//# sourceMappingURL=Canton.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Canton.test.js","sourceRoot":"","sources":["../src/Canton.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AACnF,OAAO,MAAM,MAAM,UAAU,CAAC;AAE9B,QAAQ,CAAC,QAAQ,EAAE,GAAG,EAAE;IACtB,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE;QACrC,EAAE,CAAC,4CAA4C,EAAE,KAAK,IAAI,EAAE;YAC1D,MAAM,SAAS,GAAG,MAAM,qBAAqB,CAAC,IAAI,WAAW,EAAE,CAAC,CAAC;YACjE,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,SAAS,CAAC,CAAC;YAErC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,CAAC;YACvC,MAAM,CAAC,OAAO,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YAClD,MAAM,CAAC,OAAO,MAAM,CAAC,eAAe,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YACvD,MAAM,CAAC,OAAO,MAAM,CAAC,mBAAmB,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC7D,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;QAC1B,EAAE,CAAC,oCAAoC,EAAE,KAAK,IAAI,EAAE;YAClD,MAAM,SAAS,GAAG,MAAM,qBAA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