@alephium/ledger-app 0.1.5 → 0.1.7
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/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +5 -2
- package/dist/test/release.test.js +1 -1
- package/dist/test/speculos.test.js +21 -6
- package/package.json +1 -1
- package/src/index.ts +6 -2
- package/test/release.test.ts +1 -1
- package/test/speculos.test.ts +24 -6
package/dist/src/index.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export declare const HASH_LEN = 32;
|
|
|
12
12
|
export default class AlephiumApp {
|
|
13
13
|
readonly transport: Transport;
|
|
14
14
|
constructor(transport: Transport);
|
|
15
|
+
close(): Promise<void>;
|
|
15
16
|
getVersion(): Promise<string>;
|
|
16
17
|
getAccount(startPath: string, targetGroup?: number, keyType?: KeyType): Promise<readonly [Account, number]>;
|
|
17
18
|
signHash(path: string, hash: Buffer): Promise<string>;
|
package/dist/src/index.js
CHANGED
|
@@ -42,6 +42,9 @@ class AlephiumApp {
|
|
|
42
42
|
constructor(transport) {
|
|
43
43
|
this.transport = transport;
|
|
44
44
|
}
|
|
45
|
+
async close() {
|
|
46
|
+
await this.transport.close();
|
|
47
|
+
}
|
|
45
48
|
async getVersion() {
|
|
46
49
|
const response = await this.transport.send(exports.CLA, INS.GET_VERSION, 0x00, 0x00);
|
|
47
50
|
console.log(`response ${response.length} - ${response.toString('hex')}`);
|
|
@@ -52,8 +55,8 @@ class AlephiumApp {
|
|
|
52
55
|
if ((targetGroup ?? 0) >= exports.GROUP_NUM) {
|
|
53
56
|
throw Error(`Invalid targetGroup: ${targetGroup}`);
|
|
54
57
|
}
|
|
55
|
-
if (keyType ===
|
|
56
|
-
throw Error(
|
|
58
|
+
if (keyType === 'bip340-schnorr') {
|
|
59
|
+
throw Error('BIP340-Schnorr is not supported yet');
|
|
57
60
|
}
|
|
58
61
|
const p1 = targetGroup === undefined ? 0x00 : exports.GROUP_NUM;
|
|
59
62
|
const p2 = targetGroup === undefined ? 0x00 : targetGroup;
|
|
@@ -21,6 +21,6 @@ describe.skip('Integration', () => {
|
|
|
21
21
|
const signature = await app.signHash(path, hash);
|
|
22
22
|
console.log(signature);
|
|
23
23
|
expect((0, web3_1.transactionVerifySignature)(hash.toString('hex'), account.publicKey, signature)).toBe(true);
|
|
24
|
-
await
|
|
24
|
+
await app.close();
|
|
25
25
|
}, 100000);
|
|
26
26
|
});
|
|
@@ -59,7 +59,7 @@ describe('sdk', () => {
|
|
|
59
59
|
const app = new src_1.default(transport);
|
|
60
60
|
const version = await app.getVersion();
|
|
61
61
|
expect(version).toBe('0.1.0');
|
|
62
|
-
await
|
|
62
|
+
await app.close();
|
|
63
63
|
});
|
|
64
64
|
it('should get public key', async () => {
|
|
65
65
|
const transport = await hw_transport_node_speculos_1.default.open({ apduPort });
|
|
@@ -67,7 +67,7 @@ describe('sdk', () => {
|
|
|
67
67
|
const [account, hdIndex] = await app.getAccount(path);
|
|
68
68
|
expect(hdIndex).toBe(pathIndex);
|
|
69
69
|
console.log(account);
|
|
70
|
-
await
|
|
70
|
+
await app.close();
|
|
71
71
|
});
|
|
72
72
|
it('should get public key for group', async () => {
|
|
73
73
|
const transport = await hw_transport_node_speculos_1.default.open({ apduPort });
|
|
@@ -78,15 +78,15 @@ describe('sdk', () => {
|
|
|
78
78
|
expect((0, web3_1.groupOfAddress)(account.address)).toBe(group);
|
|
79
79
|
expect(account.keyType).toBe('default');
|
|
80
80
|
});
|
|
81
|
-
await
|
|
81
|
+
await app.close();
|
|
82
82
|
});
|
|
83
83
|
it('should get public key for group for Schnorr signature', async () => {
|
|
84
84
|
const transport = await hw_transport_node_speculos_1.default.open({ apduPort });
|
|
85
85
|
const app = new src_1.default(transport);
|
|
86
86
|
Array(src_1.GROUP_NUM).forEach(async (_, group) => {
|
|
87
|
-
expect(app.getAccount(path, group, 'bip340-schnorr')).rejects.toThrow('BIP340-Schnorr is not supported yet');
|
|
87
|
+
await expect(app.getAccount(path, group, 'bip340-schnorr')).rejects.toThrow('BIP340-Schnorr is not supported yet');
|
|
88
88
|
});
|
|
89
|
-
await
|
|
89
|
+
await app.close();
|
|
90
90
|
});
|
|
91
91
|
it('should sign hash', async () => {
|
|
92
92
|
const transport = await hw_transport_node_speculos_1.default.open({ apduPort });
|
|
@@ -102,7 +102,22 @@ describe('sdk', () => {
|
|
|
102
102
|
}, 1000);
|
|
103
103
|
const signature = await app.signHash(path, hash);
|
|
104
104
|
console.log(signature);
|
|
105
|
-
await
|
|
105
|
+
await app.close();
|
|
106
106
|
expect((0, web3_1.transactionVerifySignature)(hash.toString('hex'), account.publicKey, signature)).toBe(true);
|
|
107
107
|
}, 10000);
|
|
108
|
+
it('should reject signing', async () => {
|
|
109
|
+
const transport = await hw_transport_node_speculos_1.default.open({ apduPort });
|
|
110
|
+
const app = new src_1.default(transport);
|
|
111
|
+
const [account] = await app.getAccount(path);
|
|
112
|
+
console.log(account);
|
|
113
|
+
const hash = Buffer.from(blakejs_1.default.blake2b(Buffer.from([0, 1, 2, 3, 4]), undefined, 32));
|
|
114
|
+
setTimeout(async () => {
|
|
115
|
+
await pressButton('both'); // review message
|
|
116
|
+
await pressButton('both'); // done review
|
|
117
|
+
await pressButton('left'); // select signing
|
|
118
|
+
await pressButton('both'); // done selection
|
|
119
|
+
}, 1000);
|
|
120
|
+
await expect(app.signHash(path, hash)).rejects.toThrow();
|
|
121
|
+
await app.close();
|
|
122
|
+
}, 10000);
|
|
108
123
|
});
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -22,6 +22,10 @@ export default class AlephiumApp {
|
|
|
22
22
|
this.transport = transport
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
async close(): Promise<void> {
|
|
26
|
+
await this.transport.close()
|
|
27
|
+
}
|
|
28
|
+
|
|
25
29
|
async getVersion(): Promise<string> {
|
|
26
30
|
const response = await this.transport.send(CLA, INS.GET_VERSION, 0x00, 0x00)
|
|
27
31
|
console.log(`response ${response.length} - ${response.toString('hex')}`)
|
|
@@ -34,8 +38,8 @@ export default class AlephiumApp {
|
|
|
34
38
|
throw Error(`Invalid targetGroup: ${targetGroup}`)
|
|
35
39
|
}
|
|
36
40
|
|
|
37
|
-
if (keyType ===
|
|
38
|
-
throw Error(
|
|
41
|
+
if (keyType === 'bip340-schnorr') {
|
|
42
|
+
throw Error('BIP340-Schnorr is not supported yet')
|
|
39
43
|
}
|
|
40
44
|
|
|
41
45
|
const p1 = targetGroup === undefined ? 0x00 : GROUP_NUM
|
package/test/release.test.ts
CHANGED
package/test/speculos.test.ts
CHANGED
|
@@ -37,7 +37,7 @@ describe('sdk', () => {
|
|
|
37
37
|
const app = new AlephiumApp(transport)
|
|
38
38
|
const version = await app.getVersion()
|
|
39
39
|
expect(version).toBe('0.1.0')
|
|
40
|
-
await
|
|
40
|
+
await app.close()
|
|
41
41
|
})
|
|
42
42
|
|
|
43
43
|
it('should get public key', async () => {
|
|
@@ -46,7 +46,7 @@ describe('sdk', () => {
|
|
|
46
46
|
const [account, hdIndex] = await app.getAccount(path)
|
|
47
47
|
expect(hdIndex).toBe(pathIndex)
|
|
48
48
|
console.log(account)
|
|
49
|
-
await
|
|
49
|
+
await app.close()
|
|
50
50
|
})
|
|
51
51
|
|
|
52
52
|
it('should get public key for group', async () => {
|
|
@@ -58,16 +58,16 @@ describe('sdk', () => {
|
|
|
58
58
|
expect(groupOfAddress(account.address)).toBe(group)
|
|
59
59
|
expect(account.keyType).toBe('default')
|
|
60
60
|
})
|
|
61
|
-
await
|
|
61
|
+
await app.close()
|
|
62
62
|
})
|
|
63
63
|
|
|
64
64
|
it('should get public key for group for Schnorr signature', async () => {
|
|
65
65
|
const transport = await SpeculosTransport.open({ apduPort })
|
|
66
66
|
const app = new AlephiumApp(transport)
|
|
67
67
|
Array(GROUP_NUM).forEach(async (_, group) => {
|
|
68
|
-
expect(app.getAccount(path, group, 'bip340-schnorr')).rejects.toThrow('BIP340-Schnorr is not supported yet')
|
|
68
|
+
await expect(app.getAccount(path, group, 'bip340-schnorr')).rejects.toThrow('BIP340-Schnorr is not supported yet')
|
|
69
69
|
})
|
|
70
|
-
await
|
|
70
|
+
await app.close()
|
|
71
71
|
})
|
|
72
72
|
|
|
73
73
|
it('should sign hash', async () => {
|
|
@@ -86,8 +86,26 @@ describe('sdk', () => {
|
|
|
86
86
|
}, 1000)
|
|
87
87
|
const signature = await app.signHash(path, hash)
|
|
88
88
|
console.log(signature)
|
|
89
|
-
await
|
|
89
|
+
await app.close()
|
|
90
90
|
|
|
91
91
|
expect(transactionVerifySignature(hash.toString('hex'), account.publicKey, signature)).toBe(true)
|
|
92
92
|
}, 10000)
|
|
93
|
+
|
|
94
|
+
it('should reject signing', async () => {
|
|
95
|
+
const transport = await SpeculosTransport.open({ apduPort })
|
|
96
|
+
const app = new AlephiumApp(transport)
|
|
97
|
+
|
|
98
|
+
const [account] = await app.getAccount(path)
|
|
99
|
+
console.log(account)
|
|
100
|
+
|
|
101
|
+
const hash = Buffer.from(blake.blake2b(Buffer.from([0, 1, 2, 3, 4]), undefined, 32))
|
|
102
|
+
setTimeout(async () => {
|
|
103
|
+
await pressButton('both') // review message
|
|
104
|
+
await pressButton('both') // done review
|
|
105
|
+
await pressButton('left') // select signing
|
|
106
|
+
await pressButton('both') // done selection
|
|
107
|
+
}, 1000)
|
|
108
|
+
await expect(app.signHash(path, hash)).rejects.toThrow()
|
|
109
|
+
await app.close()
|
|
110
|
+
}, 10000)
|
|
93
111
|
})
|