@exodus/hw-ledger 3.2.0 → 3.3.1

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/CHANGELOG.md CHANGED
@@ -3,6 +3,18 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [3.3.1](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/hw-ledger@3.3.0...@exodus/hw-ledger@3.3.1) (2024-10-24)
7
+
8
+ ### Bug Fixes
9
+
10
+ - support legacy transaction signing ([#10154](https://github.com/ExodusMovement/exodus-hydra/issues/10154)) ([55c3d63](https://github.com/ExodusMovement/exodus-hydra/commit/55c3d63e809397b94aa08309b03715fe6d0ed831))
11
+
12
+ ## [3.3.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/hw-ledger@3.2.0...@exodus/hw-ledger@3.3.0) (2024-10-22)
13
+
14
+ ### Features
15
+
16
+ - support cancelling an action on the ledger device ([#10105](https://github.com/ExodusMovement/exodus-hydra/issues/10105)) ([f1c1fbf](https://github.com/ExodusMovement/exodus-hydra/commit/f1c1fbff6ec70b7ddc68dd700ffb556b673b7a5a))
17
+
6
18
  ## [3.2.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/hw-ledger@3.1.0...@exodus/hw-ledger@3.2.0) (2024-10-21)
7
19
 
8
20
  ### Features
@@ -1,4 +1,4 @@
1
- import secp256k1 from '@exodus/secp256k1';
1
+ import * as secp256k1 from '@exodus/crypto/secp256k1';
2
2
  import * as ethers from '@exodus/ethersproject-transactions';
3
3
  import AppEth, { ledgerService } from '@exodus/ledgerhq-hw-app-eth';
4
4
  import { TypedDataUtils, SignTypedDataVersion } from '@metamask/eth-sig-util';
@@ -36,13 +36,20 @@ async function createHandler(transport) {
36
36
  },
37
37
  getXPub: async (params) => {
38
38
  const { publicKey, chainCode } = await app.getAddress(params.derivationPath.replace('m/', ''), false, true);
39
- const compressedPublicKey = Buffer.from(secp256k1.publicKeyConvert(Buffer.from(publicKey, 'hex'), true));
39
+ const compressedPublicKey = secp256k1.publicKeyConvert({
40
+ publicKey: Buffer.from(publicKey, 'hex'),
41
+ compressed: true,
42
+ format: 'buffer',
43
+ });
40
44
  return buildFauxXPUB(compressedPublicKey, Buffer.from(chainCode, 'hex'));
41
45
  },
42
46
  getPublicKey: async (params) => {
43
47
  const { publicKey } = await app.getAddress(params.derivationPath.replace('m/', ''));
44
- const compressedPublicKey = secp256k1.publicKeyConvert(Buffer.from(publicKey, 'hex'), true);
45
- return Buffer.from(compressedPublicKey);
48
+ return secp256k1.publicKeyConvert({
49
+ publicKey: Buffer.from(publicKey, 'hex'),
50
+ compressed: true,
51
+ format: 'buffer',
52
+ });
46
53
  },
47
54
  signTransaction: async (params) => {
48
55
  assert(Array.isArray(params.derivationPaths) && params.derivationPaths.length === 1, 'derivationsPath array must be one element long');
@@ -1,2 +1,2 @@
1
- import * as bitcoin from '@exodus/bitcoinjs-lib';
1
+ import * as bitcoin from '@exodus/bitcoinjs';
2
2
  export declare function buildBip322PSBT(message: string, address: string): bitcoin.Psbt;
@@ -1,4 +1,4 @@
1
- import * as bitcoin from '@exodus/bitcoinjs-lib';
1
+ import * as bitcoin from '@exodus/bitcoinjs';
2
2
  import { BIP322, Address } from '@exodus/bip322-js';
3
3
  export function buildBip322PSBT(message, address) {
4
4
  const scriptPubKey = Address.convertAdressToScriptPubkey(address);
@@ -1,6 +1,6 @@
1
1
  import assert from 'minimalistic-assert';
2
2
  import { DefaultWalletPolicy, WalletPolicy } from '@exodus/ledger-bitcoin';
3
- import { payments, address as baddress } from '@exodus/bitcoinjs-lib';
3
+ import { payments, address as baddress, Transaction } from '@exodus/bitcoinjs';
4
4
  import { buildBip44PathFromNumber, assertBip44PathNumber, splitBip44PathToNumber, splitBip44DerivationPath, } from './derivation-paths';
5
5
  export function assertPsbtOnlyHasAllowedDerivationPaths(psbt, masterFingerprint, derivationPaths) {
6
6
  for (let i = 0; i < psbt.getGlobalInputCount(); i++) {
@@ -36,12 +36,23 @@ export function tagPsbtWithDerivationPaths(psbt, masterFingerprint, derivationPa
36
36
  const scriptPubKeyToDerivationPathMap = computeScriptPubKeyToDerivationPathMap(derivationPathToPublicKeyMap);
37
37
  for (let inputIndex = 0; inputIndex < psbt.getGlobalInputCount(); inputIndex++) {
38
38
  const witnessUtxo = psbt.getInputWitnessUtxo(inputIndex);
39
- assert(witnessUtxo, `witnessUtxo is currently the only supported type`);
40
- const scriptPubKey = witnessUtxo.scriptPubKey.toString('hex');
41
- let derivationPath = scriptPubKeyToDerivationPathMap[scriptPubKey];
39
+ const nonWitnessUtxo = psbt.getInputNonWitnessUtxo(inputIndex);
40
+ let scriptPubKey;
41
+ if (witnessUtxo) {
42
+ scriptPubKey = witnessUtxo.scriptPubKey;
43
+ }
44
+ else if (nonWitnessUtxo) {
45
+ const prevOutputIndex = psbt.getInputOutputIndex(inputIndex);
46
+ const decodedTransaction = Transaction.fromBuffer(nonWitnessUtxo);
47
+ scriptPubKey = decodedTransaction.outs[prevOutputIndex].script;
48
+ }
49
+ else {
50
+ throw new Error('missing witnessUtxo or nonWitnessUtxo');
51
+ }
52
+ let derivationPath = scriptPubKeyToDerivationPathMap[scriptPubKey.toString('hex')];
42
53
  if (addressToDerivationPathMap && !derivationPath) {
43
54
  try {
44
- const address = baddress.fromOutputScript(witnessUtxo.scriptPubKey);
55
+ const address = baddress.fromOutputScript(scriptPubKey);
45
56
  derivationPath = addressToDerivationPathMap[address];
46
57
  }
47
58
  catch { }
@@ -50,7 +61,7 @@ export function tagPsbtWithDerivationPaths(psbt, masterFingerprint, derivationPa
50
61
  const publicKey = derivationPathToPublicKeyMap[derivationPath];
51
62
  assert(Buffer.isBuffer(publicKey), `no public key found for derivation path`);
52
63
  const derivationPathNumerical = splitBip44PathToNumber(derivationPath);
53
- if (isTaproot(witnessUtxo.scriptPubKey)) {
64
+ if (isTaproot(scriptPubKey)) {
54
65
  psbt.setInputTapBip32Derivation(inputIndex, publicKey.slice(1), [], masterFingerprintBuffer, derivationPathNumerical);
55
66
  }
56
67
  else {
@@ -83,25 +94,41 @@ export function tagPsbtWithDerivationPaths(psbt, masterFingerprint, derivationPa
83
94
  }
84
95
  function computeScriptPubKeyToDerivationPathMap(derivationPathToPublicKeyMap) {
85
96
  return Object.entries(derivationPathToPublicKeyMap).reduce((acc, [derivationPath, publicKey]) => {
86
- if (derivationPath.startsWith('m/84')) {
87
- const segwitV0 = payments.p2wpkh({
97
+ if (derivationPath.startsWith('m/44')) {
98
+ const p2pkh = payments.p2pkh({
88
99
  pubkey: publicKey,
89
100
  }).output;
90
- if (segwitV0) {
91
- Object.assign(acc, {
92
- [segwitV0.toString('hex')]: derivationPath,
93
- });
94
- }
101
+ assert(p2pkh, 'failed to compute p2pkh scriptPubKey');
102
+ Object.assign(acc, {
103
+ [p2pkh.toString('hex')]: derivationPath,
104
+ });
105
+ }
106
+ else if (derivationPath.startsWith('m/49')) {
107
+ const nestedSegwit = payments.p2sh({
108
+ redeem: payments.p2wpkh({ pubkey: publicKey }),
109
+ }).output;
110
+ assert(nestedSegwit, 'failed to compute p2pkh scriptPubKey');
111
+ Object.assign(acc, {
112
+ [nestedSegwit.toString('hex')]: derivationPath,
113
+ });
114
+ }
115
+ else if (derivationPath.startsWith('m/84')) {
116
+ const p2wpkh = payments.p2wpkh({
117
+ pubkey: publicKey,
118
+ }).output;
119
+ assert(p2wpkh, 'failed to compute p2wpkh scriptPubKey');
120
+ Object.assign(acc, {
121
+ [p2wpkh.toString('hex')]: derivationPath,
122
+ });
95
123
  }
96
124
  else if (derivationPath.startsWith('m/86')) {
97
- const taproot = payments.p2tr({
125
+ const p2tr = payments.p2tr({
98
126
  internalPubkey: publicKey.slice(1),
99
127
  }).output;
100
- if (taproot) {
101
- Object.assign(acc, {
102
- [taproot.toString('hex')]: derivationPath,
103
- });
104
- }
128
+ assert(p2tr, 'failed to compute p2tr scriptPubKey');
129
+ Object.assign(acc, {
130
+ [p2tr.toString('hex')]: derivationPath,
131
+ });
105
132
  }
106
133
  return acc;
107
134
  }, Object.create(null));
@@ -10,6 +10,7 @@ export declare class LedgerDevice implements HardwareWalletDevice {
10
10
  #private;
11
11
  constructor({ transportFactory, descriptor, walletPolicyAtom }: Dependencies);
12
12
  get descriptor(): HardwareWalletDescriptor;
13
+ cancelAction: () => Promise<void>;
13
14
  ensureApplicationIsOpened: (baseAssetName: string) => Promise<void>;
14
15
  listSupportedAssetNames: () => Promise<string[]>;
15
16
  listInstalledAssetNames: () => Promise<string[]>;
@@ -7,6 +7,7 @@ export class LedgerDevice {
7
7
  #transportFactory;
8
8
  #descriptor;
9
9
  #walletPolicyAtom;
10
+ #cancelPendingAction;
10
11
  constructor({ transportFactory, descriptor, walletPolicyAtom }) {
11
12
  this.#transportFactory = transportFactory;
12
13
  this.#descriptor = descriptor;
@@ -17,6 +18,7 @@ export class LedgerDevice {
17
18
  }
18
19
  #runInSession = async (operation, expectErrorWhenClosing = false) => {
19
20
  const transport = await this.#transportFactory.open(this.#descriptor.internalDescriptor);
21
+ this.#cancelPendingAction = async () => transport.close();
20
22
  try {
21
23
  return await operation(transport);
22
24
  }
@@ -24,6 +26,7 @@ export class LedgerDevice {
24
26
  throw transformToCommonError(err);
25
27
  }
26
28
  finally {
29
+ this.#cancelPendingAction = undefined;
27
30
  if (expectErrorWhenClosing) {
28
31
  await transport.close().catch((err) => {
29
32
  console.warn(`caught error while closing ledger transport but was expected = `, err);
@@ -64,6 +67,12 @@ export class LedgerDevice {
64
67
  return handler.quitApplication();
65
68
  });
66
69
  };
70
+ cancelAction = async () => {
71
+ if (this.#cancelPendingAction) {
72
+ await this.#cancelPendingAction();
73
+ await this.#quitApplication();
74
+ }
75
+ };
67
76
  ensureApplicationIsOpened = async (baseAssetName) => {
68
77
  const { applications } = this.#getAssetApplication(baseAssetName);
69
78
  const supportedApplicationNames = applications.map(({ applicationName }) => applicationName);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/hw-ledger",
3
- "version": "3.2.0",
3
+ "version": "3.3.1",
4
4
  "description": "The ledger module",
5
5
  "author": "Exodus Movement, Inc.",
6
6
  "repository": {
@@ -22,24 +22,24 @@
22
22
  "build": "run -T tsc --build tsconfig.build.json",
23
23
  "build:watch": "run -T tsc --build tsconfig.build.json && run -T tsc --build -w tsconfig.build.json",
24
24
  "clean": "run -T tsc --build --clean",
25
- "test": "run -T jest --testMatch='**/*.unit.test.js' --coverageDirectory coverage/unit",
25
+ "test": "RUN_TESTS=unit run -T exodus-test --jest --esbuild",
26
26
  "zemu:install": "docker pull zondax/builder-zemu:speculos-745fe46f81cfc18114b94a37beaefb58a09c0fcd",
27
- "test:integration": "yarn zemu:install && run -T exodus-test --jest --esbuild",
27
+ "test:integration": "yarn zemu:install && RUN_TESTS=integration run -T exodus-test --jest --esbuild",
28
28
  "lint": "run -T eslint .",
29
29
  "lint:fix": "yarn lint --fix",
30
30
  "prepublishOnly": "yarn run -T build --scope @exodus/hw-ledger"
31
31
  },
32
32
  "dependencies": {
33
33
  "@exodus/atoms": "^9.0.0",
34
- "@exodus/bip322-js": "^1.1.0-exodus.4",
35
- "@exodus/bitcoinjs-lib": "^6.1.5-exodus.0",
34
+ "@exodus/bip322-js": "^1.2.1",
35
+ "@exodus/bitcoinjs": "^1.1.0",
36
+ "@exodus/crypto": "^1.0.0-rc.14",
36
37
  "@exodus/ethersproject-transactions": "^5.4.2-exodus.0",
37
- "@exodus/hw-common": "^3.0.0",
38
+ "@exodus/hw-common": "^3.1.0",
38
39
  "@exodus/ledger-bitcoin": "^0.2.3-exodus.3",
39
40
  "@exodus/ledgerhq-devices": "^8.1.0-exodus.3",
40
41
  "@exodus/ledgerhq-hw-app-eth": "^6.33.7-exodus.8",
41
42
  "@exodus/redux-dependency-injection": "^4.0.0",
42
- "@exodus/secp256k1": "^4.0.2-exodus.0",
43
43
  "@ledgerhq/hw-app-solana": "^7.0.10",
44
44
  "@ledgerhq/hw-transport": "^6.28.5",
45
45
  "@metamask/eth-sig-util": "^4.0.1",
@@ -56,14 +56,13 @@
56
56
  "@types/bs58": "^4.0.1",
57
57
  "@types/bs58check": "^2.1.0",
58
58
  "@types/minimalistic-assert": "^1.0.1",
59
- "@types/secp256k1": "^4.0.3",
60
59
  "@types/semver": "^7.3.5",
61
60
  "@zondax/zemu": "^0.43.1",
62
61
  "bitcoinjs-lib": "^6.1.3",
63
62
  "ecpair": "^2.1.0",
63
+ "p-defer": "^4.0.1",
64
64
  "redux": "^4.2.1",
65
- "tiny-secp256k1": "^2.2.3",
66
- "ts-jest": "^29.0.3"
65
+ "tiny-secp256k1": "^2.2.3"
67
66
  },
68
- "gitHead": "6bb100cacdf1975464a78ab0c54b84c2b922d8a2"
67
+ "gitHead": "75c0ccc137017dbd6fea08e2c42f6b46e2e85f9c"
69
68
  }