@exodus/hw-ledger 2.2.1 → 2.2.3

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
+ ## [2.2.3](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/hw-ledger@2.2.2...@exodus/hw-ledger@2.2.3) (2024-01-23)
7
+
8
+ ### Bug Fixes
9
+
10
+ - allow signing bitcoin transactions with multiple wallet policies ([#5479](https://github.com/ExodusMovement/exodus-hydra/issues/5479)) ([92a923b](https://github.com/ExodusMovement/exodus-hydra/commit/92a923b8bf30413040d6aa346281ae1b3d5ec8d8))
11
+
12
+ ## [2.2.2](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/hw-ledger@2.2.1...@exodus/hw-ledger@2.2.2) (2024-01-18)
13
+
14
+ ### Bug Fixes
15
+
16
+ - proper error handling for eth ([#5447](https://github.com/ExodusMovement/exodus-hydra/issues/5447)) ([4f72307](https://github.com/ExodusMovement/exodus-hydra/commit/4f72307b52c6dcd2584a7bf347139b9b7cf42387))
17
+
6
18
  ## [2.2.1](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/hw-ledger@2.2.0...@exodus/hw-ledger@2.2.1) (2024-01-16)
7
19
 
8
20
  ### Bug Fixes
@@ -1,24 +1,15 @@
1
1
  import bs58 from 'bs58';
2
- import { AppClient, DefaultWalletPolicy, PsbtV2, } from '@exodus/ledger-bitcoin';
2
+ import { AppClient, PsbtV2 } from '@exodus/ledger-bitcoin';
3
3
  import { splitBip44DerivationPath } from './utils';
4
4
  import assert from 'minimalistic-assert';
5
- import { assertPsbtOnlyHasAllowedDerivationPaths, tagPsbtWithDerivationPaths } from './utils/psbt';
5
+ import { assertPsbtOnlyHasAllowedDerivationPaths, tagPsbtWithDerivationPaths, getWalletPolicy, derivationPathsToWalletPolicy, } from './utils/psbt';
6
6
  async function createHandler(transport) {
7
7
  const app = new AppClient(transport);
8
- const getWalletPolicy = async (purpose, coin, account) => {
9
- const fpr = await app.getMasterFingerprint();
10
- const xpub = await app.getExtendedPubkey(`m/${purpose}/${coin}/${account}`);
11
- const desc = {
12
- "44'": 'pkh(@0/**)',
13
- "49'": 'sh(wpkh(@0/**))',
14
- "84'": 'wpkh(@0/**)',
15
- "86'": 'tr(@0/**)',
16
- }[purpose];
17
- return new DefaultWalletPolicy(desc, `[${fpr}/${purpose}/${coin}/${account}]${xpub}`);
18
- };
19
8
  const getAddress = async (params) => {
20
9
  const [purpose, coin, account, change, address] = splitBip44DerivationPath(params.derivationPath);
21
- const walletPolicy = await getWalletPolicy(purpose, coin, account);
10
+ const fpr = await app.getMasterFingerprint();
11
+ const xpub = await app.getExtendedPubkey(`m/${purpose}/${coin}/${account}`);
12
+ const walletPolicy = getWalletPolicy(fpr, xpub, purpose, coin, account);
22
13
  return app.getWalletAddress(walletPolicy, null, Number(change), Number(address), false);
23
14
  };
24
15
  const getXPub = async (params) => {
@@ -34,7 +25,7 @@ async function createHandler(transport) {
34
25
  psbt.deserialize(psbtBuffer);
35
26
  const [purpose, coin, account] = splitBip44DerivationPath(params.derivationPaths[0]);
36
27
  const fpr = await app.getMasterFingerprint();
37
- const walletPolicy = await getWalletPolicy(purpose, coin, account);
28
+ const xpub = await app.getExtendedPubkey(`m/${purpose}/${coin}/${account}`);
38
29
  const derivationPathToPublicKeyMap = Object.create(null);
39
30
  for (const derivationPath of params.derivationPaths) {
40
31
  derivationPathToPublicKeyMap[derivationPath] = await getPublicKey({
@@ -44,7 +35,12 @@ async function createHandler(transport) {
44
35
  }
45
36
  tagPsbtWithDerivationPaths(psbt, fpr, derivationPathToPublicKeyMap);
46
37
  assertPsbtOnlyHasAllowedDerivationPaths(psbt, fpr, params.derivationPaths);
47
- const signatures = await app.signPsbt(psbt.serialize(), walletPolicy, null);
38
+ const signatures = [];
39
+ const walletPolicies = derivationPathsToWalletPolicy(fpr, xpub, params.derivationPaths);
40
+ for (const walletPolicy of walletPolicies) {
41
+ const _signatures = await app.signPsbt(psbt.serialize(), walletPolicy, null);
42
+ signatures.push(..._signatures);
43
+ }
48
44
  const result = signatures.map(([inputIndex, partialSignature]) => ({
49
45
  inputIndex,
50
46
  publicKey: partialSignature.pubkey,
@@ -74,14 +74,14 @@ async function createHandler(transport) {
74
74
  });
75
75
  }
76
76
  catch (err) {
77
- if (err instanceof Error && err.message.includes('EthAppNftNotSupported')) {
77
+ if (err.name === 'EthAppNftNotSupported') {
78
78
  response = await signTransaction({
79
79
  derivationPath: params.derivationPaths[0],
80
80
  serializedTransactionHex,
81
81
  withNFT: false,
82
82
  });
83
83
  }
84
- else if (err instanceof Error && err.message.includes('EthAppPleaseEnableContractData')) {
84
+ else if (err.name === 'EthAppPleaseEnableContractData') {
85
85
  throw new RequiresBlindSigningError();
86
86
  }
87
87
  else {
@@ -1,4 +1,6 @@
1
1
  /// <reference types="node" />
2
- import { PsbtV2 } from '@exodus/ledger-bitcoin';
2
+ import { DefaultWalletPolicy, PsbtV2, WalletPolicy } from '@exodus/ledger-bitcoin';
3
3
  export declare function assertPsbtOnlyHasAllowedDerivationPaths(psbt: PsbtV2, masterFingerprint: string, derivationPaths: string[]): void;
4
4
  export declare function tagPsbtWithDerivationPaths(psbt: PsbtV2, masterFingerprint: string, derivationPathToPublicKeyMap: Record<string, Buffer>): void;
5
+ export declare const getWalletPolicy: (fpr: string, xpub: string, purpose: string, coin: string, account: string) => DefaultWalletPolicy;
6
+ export declare function derivationPathsToWalletPolicy(fpr: string, xpub: string, derivationPaths: string[]): WalletPolicy[];
@@ -1,6 +1,7 @@
1
1
  import assert from 'minimalistic-assert';
2
+ import { DefaultWalletPolicy, } from '@exodus/ledger-bitcoin';
2
3
  import { payments } from '@exodus/bitcoinjs-lib';
3
- import { buildBip44PathFromNumber, assertBip44PathNumber, splitBip44PathToNumber, } from './derivation-paths';
4
+ import { buildBip44PathFromNumber, assertBip44PathNumber, splitBip44PathToNumber, splitBip44DerivationPath, } from './derivation-paths';
4
5
  export function assertPsbtOnlyHasAllowedDerivationPaths(psbt, masterFingerprint, derivationPaths) {
5
6
  for (let i = 0; i < psbt.getGlobalInputCount(); i++) {
6
7
  const BIP32_DERIVATION = 6;
@@ -94,3 +95,25 @@ function computeScriptPubKeyToDerivationPathMap(derivationPathToPublicKeyMap) {
94
95
  function isTaproot(scriptPubKey) {
95
96
  return scriptPubKey.length === 34 && scriptPubKey.at(0) === 0x51 && scriptPubKey.at(1) === 0x20;
96
97
  }
98
+ export const getWalletPolicy = (fpr, xpub, purpose, coin, account) => {
99
+ const desc = {
100
+ "44'": 'pkh(@0/**)',
101
+ "49'": 'sh(wpkh(@0/**))',
102
+ "84'": 'wpkh(@0/**)',
103
+ "86'": 'tr(@0/**)',
104
+ }[purpose];
105
+ return new DefaultWalletPolicy(desc, `[${fpr}/${purpose}/${coin}/${account}]${xpub}`);
106
+ };
107
+ export function derivationPathsToWalletPolicy(fpr, xpub, derivationPaths) {
108
+ const walletPolicies = derivationPaths
109
+ .map(splitBip44DerivationPath)
110
+ .map(([purpose, coin, account]) => {
111
+ return getWalletPolicy(fpr, xpub, purpose, coin, account);
112
+ });
113
+ const deduped = Object.create(null);
114
+ for (const walletPolicy of walletPolicies) {
115
+ const uniqueId = walletPolicy.getId().toString('hex');
116
+ deduped[uniqueId] = walletPolicy;
117
+ }
118
+ return Object.values(deduped);
119
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/hw-ledger",
3
- "version": "2.2.1",
3
+ "version": "2.2.3",
4
4
  "description": "The ledger module",
5
5
  "author": "Exodus Movement Inc.",
6
6
  "repository": {
@@ -67,5 +67,5 @@
67
67
  "ts-jest": "^29.0.3",
68
68
  "typescript": "^4.7.3"
69
69
  },
70
- "gitHead": "58a6b3ab7d222a9a18a48fae2f450ebef9c67738"
70
+ "gitHead": "eae25afb3c619cf0d093cee791c9f899bda3e22e"
71
71
  }