@alephium/ledger-app 0.2.1 → 0.4.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.
@@ -1,123 +0,0 @@
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
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- const hw_transport_node_speculos_1 = __importDefault(require("@ledgerhq/hw-transport-node-speculos"));
30
- const src_1 = __importStar(require("../src"));
31
- const blakejs_1 = __importDefault(require("blakejs"));
32
- const node_fetch_1 = __importDefault(require("node-fetch"));
33
- const web3_1 = require("@alephium/web3");
34
- function sleep(ms) {
35
- return new Promise((resolve) => setTimeout(resolve, ms));
36
- }
37
- async function pressButton(button) {
38
- await sleep(500);
39
- return (0, node_fetch_1.default)(`http://localhost:25000/button/${button}`, {
40
- method: 'POST',
41
- body: JSON.stringify({ action: 'press-and-release' })
42
- });
43
- }
44
- function getRandomInt(min, max) {
45
- min = Math.ceil(min);
46
- max = Math.floor(max);
47
- return Math.floor(Math.random() * (max - min) + min); // The maximum is exclusive and the minimum is inclusive
48
- }
49
- describe('sdk', () => {
50
- const apduPort = 9999;
51
- let pathIndex;
52
- let path;
53
- beforeEach(() => {
54
- pathIndex = getRandomInt(0, 1000000);
55
- path = `m/44'/1234'/0'/0/` + pathIndex;
56
- });
57
- it('should get version', async () => {
58
- const transport = await hw_transport_node_speculos_1.default.open({ apduPort });
59
- const app = new src_1.default(transport);
60
- const version = await app.getVersion();
61
- expect(version).toBe('0.2.0');
62
- await app.close();
63
- });
64
- it('should get public key', async () => {
65
- const transport = await hw_transport_node_speculos_1.default.open({ apduPort });
66
- const app = new src_1.default(transport);
67
- const [account, hdIndex] = await app.getAccount(path);
68
- expect(hdIndex).toBe(pathIndex);
69
- console.log(account);
70
- await app.close();
71
- });
72
- it('should get public key for group', async () => {
73
- const transport = await hw_transport_node_speculos_1.default.open({ apduPort });
74
- const app = new src_1.default(transport);
75
- Array(src_1.GROUP_NUM).forEach(async (_, group) => {
76
- const [account, hdIndex] = await app.getAccount(path, group);
77
- expect(hdIndex >= pathIndex).toBe(true);
78
- expect((0, web3_1.groupOfAddress)(account.address)).toBe(group);
79
- expect(account.keyType).toBe('default');
80
- });
81
- await app.close();
82
- });
83
- it('should get public key for group for Schnorr signature', async () => {
84
- const transport = await hw_transport_node_speculos_1.default.open({ apduPort });
85
- const app = new src_1.default(transport);
86
- Array(src_1.GROUP_NUM).forEach(async (_, group) => {
87
- await expect(app.getAccount(path, group, 'bip340-schnorr')).rejects.toThrow('BIP340-Schnorr is not supported yet');
88
- });
89
- await app.close();
90
- });
91
- it('should sign hash', async () => {
92
- const transport = await hw_transport_node_speculos_1.default.open({ apduPort });
93
- const app = new src_1.default(transport);
94
- const [account] = await app.getAccount(path);
95
- console.log(account);
96
- const hash = Buffer.from(blakejs_1.default.blake2b(Buffer.from([0, 1, 2, 3, 4]), undefined, 32));
97
- setTimeout(async () => {
98
- await pressButton('both'); // review message
99
- await pressButton('both'); // done review
100
- await pressButton('right'); // select signing
101
- await pressButton('both'); // done selection
102
- }, 1000);
103
- const signature = await app.signHash(path, hash);
104
- console.log(signature);
105
- await app.close();
106
- expect((0, web3_1.transactionVerifySignature)(hash.toString('hex'), account.publicKey, signature)).toBe(true);
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);
123
- });
@@ -1,28 +0,0 @@
1
- import NodeTransport from '@ledgerhq/hw-transport-node-hid'
2
- import { listen } from '@ledgerhq/logs'
3
- import blake from 'blakejs'
4
-
5
- import { transactionVerifySignature } from '@alephium/web3'
6
-
7
- import AlephiumApp from '../src'
8
-
9
- describe.skip('Integration', () => {
10
- const path = `m/44'/1234'/0'/0/0`
11
-
12
- // enable this for integration test
13
- it('should test node', async () => {
14
- const transport = await NodeTransport.open('')
15
- listen((log) => console.log(log))
16
- const app = new AlephiumApp(transport)
17
-
18
- const [account] = await app.getAccount(path)
19
- console.log(`${JSON.stringify(account)}`)
20
-
21
- const hash = Buffer.from(blake.blake2b(Buffer.from([0, 1, 2, 3, 4]), undefined, 32))
22
- const signature = await app.signHash(path, hash)
23
- console.log(signature)
24
- expect(transactionVerifySignature(hash.toString('hex'), account.publicKey, signature)).toBe(true)
25
-
26
- await app.close()
27
- }, 100000)
28
- })
@@ -1,111 +0,0 @@
1
- import SpeculosTransport from '@ledgerhq/hw-transport-node-speculos'
2
- import AlephiumApp, { GROUP_NUM } from '../src'
3
- import blake from 'blakejs'
4
- import fetch from 'node-fetch'
5
- import { groupOfAddress, transactionVerifySignature } from '@alephium/web3'
6
-
7
- function sleep(ms) {
8
- return new Promise((resolve) => setTimeout(resolve, ms))
9
- }
10
-
11
- async function pressButton(button: 'left' | 'right' | 'both') {
12
- await sleep(500)
13
- return fetch(`http://localhost:25000/button/${button}`, {
14
- method: 'POST',
15
- body: JSON.stringify({ action: 'press-and-release' })
16
- })
17
- }
18
-
19
- function getRandomInt(min, max) {
20
- min = Math.ceil(min)
21
- max = Math.floor(max)
22
- return Math.floor(Math.random() * (max - min) + min) // The maximum is exclusive and the minimum is inclusive
23
- }
24
-
25
- describe('sdk', () => {
26
- const apduPort = 9999
27
- let pathIndex: number
28
- let path: string
29
-
30
- beforeEach(() => {
31
- pathIndex = getRandomInt(0, 1000000)
32
- path = `m/44'/1234'/0'/0/` + pathIndex
33
- })
34
-
35
- it('should get version', async () => {
36
- const transport = await SpeculosTransport.open({ apduPort })
37
- const app = new AlephiumApp(transport)
38
- const version = await app.getVersion()
39
- expect(version).toBe('0.2.0')
40
- await app.close()
41
- })
42
-
43
- it('should get public key', async () => {
44
- const transport = await SpeculosTransport.open({ apduPort })
45
- const app = new AlephiumApp(transport)
46
- const [account, hdIndex] = await app.getAccount(path)
47
- expect(hdIndex).toBe(pathIndex)
48
- console.log(account)
49
- await app.close()
50
- })
51
-
52
- it('should get public key for group', async () => {
53
- const transport = await SpeculosTransport.open({ apduPort })
54
- const app = new AlephiumApp(transport)
55
- Array(GROUP_NUM).forEach(async (_, group) => {
56
- const [account, hdIndex] = await app.getAccount(path, group)
57
- expect(hdIndex >= pathIndex).toBe(true)
58
- expect(groupOfAddress(account.address)).toBe(group)
59
- expect(account.keyType).toBe('default')
60
- })
61
- await app.close()
62
- })
63
-
64
- it('should get public key for group for Schnorr signature', async () => {
65
- const transport = await SpeculosTransport.open({ apduPort })
66
- const app = new AlephiumApp(transport)
67
- Array(GROUP_NUM).forEach(async (_, group) => {
68
- await expect(app.getAccount(path, group, 'bip340-schnorr')).rejects.toThrow('BIP340-Schnorr is not supported yet')
69
- })
70
- await app.close()
71
- })
72
-
73
- it('should sign hash', async () => {
74
- const transport = await SpeculosTransport.open({ apduPort })
75
- const app = new AlephiumApp(transport)
76
-
77
- const [account] = await app.getAccount(path)
78
- console.log(account)
79
-
80
- const hash = Buffer.from(blake.blake2b(Buffer.from([0, 1, 2, 3, 4]), undefined, 32))
81
- setTimeout(async () => {
82
- await pressButton('both') // review message
83
- await pressButton('both') // done review
84
- await pressButton('right') // select signing
85
- await pressButton('both') // done selection
86
- }, 1000)
87
- const signature = await app.signHash(path, hash)
88
- console.log(signature)
89
- await app.close()
90
-
91
- expect(transactionVerifySignature(hash.toString('hex'), account.publicKey, signature)).toBe(true)
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)
111
- })