@ledgerhq/live-common 21.14.0 → 21.14.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.
Files changed (28) hide show
  1. package/lib/__tests__/derivation.js +1 -1
  2. package/lib/__tests__/derivation.js.map +1 -1
  3. package/lib/__tests__/families/bitcoin/wallet-btc/wallet.integration.test.js +2 -2
  4. package/lib/families/bitcoin/wallet-btc/crypto/base.d.ts.map +1 -1
  5. package/lib/families/bitcoin/wallet-btc/crypto/base.js +1 -0
  6. package/lib/families/bitcoin/wallet-btc/crypto/base.js.map +1 -1
  7. package/lib/families/bitcoin/wallet-btc/crypto/bitcoincash.js +1 -1
  8. package/lib/families/bitcoin/wallet-btc/crypto/bitcoincash.js.map +1 -1
  9. package/lib/families/bitcoin/wallet-btc/crypto/zec.js +1 -1
  10. package/lib/families/bitcoin/wallet-btc/crypto/zec.js.map +1 -1
  11. package/lib/families/bitcoin/wallet-btc/crypto/zen.js +1 -1
  12. package/lib/families/bitcoin/wallet-btc/crypto/zen.js.map +1 -1
  13. package/lib/families/bitcoin/wallet-btc/utils.d.ts +1 -1
  14. package/lib/families/bitcoin/wallet-btc/utils.d.ts.map +1 -1
  15. package/lib/families/bitcoin/wallet-btc/utils.js +10 -6
  16. package/lib/families/bitcoin/wallet-btc/utils.js.map +1 -1
  17. package/lib/families/bitcoin/wallet-btc/wallet.js +1 -1
  18. package/lib/families/bitcoin/wallet-btc/wallet.js.map +1 -1
  19. package/package.json +1 -1
  20. package/src/__tests__/__snapshots__/all.libcore.ts.snap +49100 -49100
  21. package/src/__tests__/derivation.ts +1 -1
  22. package/src/__tests__/families/bitcoin/wallet-btc/wallet.integration.test.ts +2 -2
  23. package/src/families/bitcoin/wallet-btc/crypto/base.ts +1 -0
  24. package/src/families/bitcoin/wallet-btc/crypto/bitcoincash.ts +1 -1
  25. package/src/families/bitcoin/wallet-btc/crypto/zec.ts +1 -1
  26. package/src/families/bitcoin/wallet-btc/crypto/zen.ts +1 -1
  27. package/src/families/bitcoin/wallet-btc/utils.ts +10 -6
  28. package/src/families/bitcoin/wallet-btc/wallet.ts +1 -1
@@ -6,7 +6,7 @@ import {
6
6
  describe("derivation", () => {
7
7
  test("getPreferredNewAccountScheme should return a list of schemes for a given currency", () => {
8
8
  const testData = [
9
- ["bitcoin", ["native_segwit", "segwit", ""]],
9
+ ["bitcoin", ["native_segwit", "taproot", "segwit", ""]],
10
10
  ["ethereum", null],
11
11
  ["cosmos", null],
12
12
  ["litecoin", ["native_segwit", "segwit", ""]],
@@ -63,7 +63,7 @@ describe("testing wallet", () => {
63
63
  fromAccount: account,
64
64
  txInfo,
65
65
  });
66
- expect(tx).toEqual("66ad13fd62ca677ae4d169ec5fe84be2f846562a");
66
+ expect(tx).toEqual("d6154bba4915d07453bb09d4fa02d62e975b4475");
67
67
  });
68
68
 
69
69
  it("should allow to build a transaction splitting outputs", async () => {
@@ -87,7 +87,7 @@ describe("testing wallet", () => {
87
87
  fromAccount: account,
88
88
  txInfo,
89
89
  });
90
- expect(tx).toEqual("23ab414d38fe836e22619d6ee84fdebafa6b5168");
90
+ expect(tx).toEqual("d922a70d6a66b96cdaba4565270a21f97eb23a6d");
91
91
  });
92
92
 
93
93
  it("should throw during sync if there is an error in explorer", async () => {
@@ -150,6 +150,7 @@ class Base implements ICrypto {
150
150
  );
151
151
  }
152
152
 
153
+ // eslint-disable-next-line
153
154
  isTaprootAddress(address: string): boolean {
154
155
  return false;
155
156
  }
@@ -71,7 +71,7 @@ class BitcoinCash implements ICrypto {
71
71
  return bchaddr.isValidAddress(address);
72
72
  }
73
73
 
74
- // eslint-disable-next-line class-methods-use-this
74
+ // eslint-disable-next-line
75
75
  isTaprootAddress(address: string): boolean {
76
76
  return false;
77
77
  }
@@ -75,7 +75,7 @@ class ZCash implements ICrypto {
75
75
  return zec.Address.isValid(address, "livenet");
76
76
  }
77
77
 
78
- // eslint-disable-next-line class-methods-use-this
78
+ // eslint-disable-next-line
79
79
  isTaprootAddress(address: string): boolean {
80
80
  return false;
81
81
  }
@@ -103,7 +103,7 @@ class Zen implements ICrypto {
103
103
  );
104
104
  }
105
105
 
106
- // eslint-disable-next-line class-methods-use-this
106
+ // eslint-disable-next-line
107
107
  isTaprootAddress(address: string): boolean {
108
108
  return false;
109
109
  }
@@ -83,12 +83,12 @@ export function byteSize(count: number) {
83
83
  return 1;
84
84
  }
85
85
  if (count <= 0xffff) {
86
- return 2;
86
+ return 3;
87
87
  }
88
88
  if (count <= 0xffffffff) {
89
- return 4;
89
+ return 5;
90
90
  }
91
- return 8;
91
+ return 9;
92
92
  }
93
93
 
94
94
  // refer to https://github.com/LedgerHQ/lib-ledger-core/blob/fc9d762b83fc2b269d072b662065747a64ab2816/core/src/wallet/bitcoin/api_impl/BitcoinLikeTransactionApi.cpp#L217
@@ -106,10 +106,14 @@ export function estimateTxSize(
106
106
  fixedSize += byteSize(inputCount); // Number of inputs
107
107
  fixedSize += byteSize(outputCount); // Number of outputs
108
108
  fixedSize += 4; // Timelock
109
+ if (derivationMode !== DerivationModes.LEGACY) {
110
+ fixedSize += 0.5; // Segwit marker & segwit flag
111
+ }
109
112
  // refer to https://medium.com/coinmonks/on-bitcoin-transaction-sizes-part-2-9445373d17f4
110
113
  // and https://bitcoin.stackexchange.com/questions/96017/what-are-the-sizes-of-single-sig-and-2-of-3-multisig-taproot-inputs
114
+ // and https://bitcoinops.org/en/tools/calc-size/
111
115
  if (derivationMode === DerivationModes.TAPROOT) {
112
- txSize = fixedSize + 57.5 * inputCount + 43 * outputCount;
116
+ txSize = fixedSize + 57.75 * inputCount + 43 * outputCount;
113
117
  return Math.ceil(txSize);
114
118
  }
115
119
  const isSegwit =
@@ -120,12 +124,12 @@ export function estimateTxSize(
120
124
  // P2SH: 32 PrevTxHash + 4 Index + 23 scriptPubKey + 4 sequence
121
125
  const isNativeSegwit = derivationMode === DerivationModes.NATIVE_SEGWIT;
122
126
  const inputSize = isNativeSegwit ? 41 : 63;
123
- const noWitness = fixedSize + inputSize * inputCount + 34 * outputCount;
127
+ const noWitness = fixedSize + inputSize * inputCount + 43 * outputCount; //43 is the biggest output(taproot output) size, we use the biggest one for safety
124
128
  // Include flag and marker size (one byte each)
125
129
  const witnessSize = noWitness + 108 * inputCount + 2;
126
130
  txSize = (noWitness * 3 + witnessSize) / 4;
127
131
  } else {
128
- txSize = fixedSize + 148 * inputCount + 34 * outputCount;
132
+ txSize = fixedSize + 148 * inputCount + 43 * outputCount;
129
133
  }
130
134
  return Math.ceil(txSize); // We don't allow floating value
131
135
  }
@@ -263,7 +263,7 @@ class BitcoinLikeWallet {
263
263
  return [
264
264
  btc.splitTransaction(
265
265
  i.txHex,
266
- segwit,
266
+ true,
267
267
  false, // FIXME hasTimestamp needed for LL-7539
268
268
  hasExtraData,
269
269
  additionals