@alephium/ledger-app 0.1.3 → 0.1.4

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,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { Account } from '@alephium/web3';
2
+ import { Account, KeyType } from '@alephium/web3';
3
3
  import Transport from '@ledgerhq/hw-transport';
4
4
  export declare const CLA = 128;
5
5
  export declare enum INS {
@@ -13,6 +13,6 @@ export default class AlephiumApp {
13
13
  readonly transport: Transport;
14
14
  constructor(transport: Transport);
15
15
  getVersion(): Promise<string>;
16
- getAccount(startPath: string, targetGroup?: number): Promise<readonly [Account, number]>;
16
+ getAccount(startPath: string, targetGroup?: number, keyType?: KeyType): Promise<readonly [Account, number]>;
17
17
  signHash(path: string, hash: Buffer): Promise<string>;
18
18
  }
package/dist/src/index.js CHANGED
@@ -48,7 +48,7 @@ class AlephiumApp {
48
48
  return `${response[0]}.${response[1]}.${response[2]}`;
49
49
  }
50
50
  // TODO: make address display optional
51
- async getAccount(startPath, targetGroup) {
51
+ async getAccount(startPath, targetGroup, keyType) {
52
52
  if ((targetGroup ?? 0) >= exports.GROUP_NUM) {
53
53
  throw Error(`Invalid targetGroup: ${targetGroup}`);
54
54
  }
@@ -59,7 +59,7 @@ class AlephiumApp {
59
59
  const address = (0, web3_1.addressFromPublicKey)(publicKey);
60
60
  const group = (0, web3_1.groupOfAddress)(address);
61
61
  const hdIndex = response.slice(65, 69).readUInt32BE(0);
62
- return [{ publicKey: publicKey, address: address, group: group, keyType: 'default' }, hdIndex];
62
+ return [{ publicKey: publicKey, address: address, group: group, keyType: keyType ?? 'default' }, hdIndex];
63
63
  }
64
64
  async signHash(path, hash) {
65
65
  if (hash.length !== exports.HASH_LEN) {
@@ -76,6 +76,18 @@ describe('sdk', () => {
76
76
  const [account, hdIndex] = await app.getAccount(path, group);
77
77
  expect(hdIndex >= pathIndex).toBe(true);
78
78
  expect((0, web3_1.groupOfAddress)(account.address)).toBe(group);
79
+ expect(account.keyType).toBe('default');
80
+ });
81
+ await transport.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
+ const [account, hdIndex] = await app.getAccount(path, group, 'bip340-schnorr');
88
+ expect(hdIndex >= pathIndex).toBe(true);
89
+ expect((0, web3_1.groupOfAddress)(account.address)).toBe(group);
90
+ expect(account.keyType).toBe('bip340-schnorr');
79
91
  });
80
92
  await transport.close();
81
93
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alephium/ledger-app",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "license": "GPL",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "exports": {
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Account, addressFromPublicKey, encodeHexSignature, groupOfAddress } from '@alephium/web3'
1
+ import { Account, KeyType, addressFromPublicKey, encodeHexSignature, groupOfAddress } from '@alephium/web3'
2
2
  import Transport, { StatusCodes } from '@ledgerhq/hw-transport'
3
3
  import * as serde from './serde'
4
4
  import { ec as EC } from 'elliptic'
@@ -29,7 +29,7 @@ export default class AlephiumApp {
29
29
  }
30
30
 
31
31
  // TODO: make address display optional
32
- async getAccount(startPath: string, targetGroup?: number): Promise<readonly [Account, number]> {
32
+ async getAccount(startPath: string, targetGroup?: number, keyType?: KeyType): Promise<readonly [Account, number]> {
33
33
  if ((targetGroup ?? 0) >= GROUP_NUM) {
34
34
  throw Error(`Invalid targetGroup: ${targetGroup}`)
35
35
  }
@@ -42,7 +42,7 @@ export default class AlephiumApp {
42
42
  const group = groupOfAddress(address)
43
43
  const hdIndex = response.slice(65, 69).readUInt32BE(0)
44
44
 
45
- return [{ publicKey: publicKey, address: address, group: group, keyType: 'default' }, hdIndex] as const
45
+ return [{ publicKey: publicKey, address: address, group: group, keyType: keyType ?? 'default' }, hdIndex] as const
46
46
  }
47
47
 
48
48
  async signHash(path: string, hash: Buffer): Promise<string> {
@@ -56,6 +56,19 @@ describe('sdk', () => {
56
56
  const [account, hdIndex] = await app.getAccount(path, group)
57
57
  expect(hdIndex >= pathIndex).toBe(true)
58
58
  expect(groupOfAddress(account.address)).toBe(group)
59
+ expect(account.keyType).toBe('default')
60
+ })
61
+ await transport.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
+ const [account, hdIndex] = await app.getAccount(path, group, 'bip340-schnorr')
69
+ expect(hdIndex >= pathIndex).toBe(true)
70
+ expect(groupOfAddress(account.address)).toBe(group)
71
+ expect(account.keyType).toBe('bip340-schnorr')
59
72
  })
60
73
  await transport.close()
61
74
  })