@ledgerhq/live-common 21.32.3 → 21.32.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.
Files changed (54) hide show
  1. package/lib/__tests__/families/bitcoin/wallet-btc/wallet.integration.test.js +1 -0
  2. package/lib/__tests__/families/bitcoin/wallet-btc/wallet.integration.test.js.map +1 -1
  3. package/lib/__tests__/families/bitcoin/wallet-btc/xpub.getAddress.js +26 -0
  4. package/lib/__tests__/families/bitcoin/wallet-btc/xpub.getAddress.js.map +1 -1
  5. package/lib/env.d.ts +10 -5
  6. package/lib/env.d.ts.map +1 -1
  7. package/lib/env.js +5 -0
  8. package/lib/env.js.map +1 -1
  9. package/lib/env.react.d.ts +1 -1
  10. package/lib/env.react.d.ts.map +1 -1
  11. package/lib/families/bitcoin/wallet-btc/crypto/bip32.js +2 -2
  12. package/lib/families/bitcoin/wallet-btc/crypto/bip32.js.map +1 -1
  13. package/lib/families/bitcoin/wallet-btc/crypto/zec.d.ts +2 -2
  14. package/lib/families/bitcoin/wallet-btc/crypto/zec.d.ts.map +1 -1
  15. package/lib/families/bitcoin/wallet-btc/crypto/zec.js +37 -16
  16. package/lib/families/bitcoin/wallet-btc/crypto/zec.js.map +1 -1
  17. package/lib/families/bitcoin/wallet-btc/crypto/zen.d.ts +0 -1
  18. package/lib/families/bitcoin/wallet-btc/crypto/zen.d.ts.map +1 -1
  19. package/lib/families/bitcoin/wallet-btc/crypto/zen.js +46 -24
  20. package/lib/families/bitcoin/wallet-btc/crypto/zen.js.map +1 -1
  21. package/lib/families/solana/test-dataset.d.ts.map +1 -1
  22. package/lib/families/solana/test-dataset.js +1 -2
  23. package/lib/families/solana/test-dataset.js.map +1 -1
  24. package/lib/families/tezos/synchronisation.d.ts.map +1 -1
  25. package/lib/families/tezos/synchronisation.js +2 -0
  26. package/lib/families/tezos/synchronisation.js.map +1 -1
  27. package/lib/featureFlags/FeatureToggle.js +2 -2
  28. package/lib/featureFlags/FeatureToggle.js.map +1 -1
  29. package/lib/featureFlags/defaultFeatures.js +1 -1
  30. package/lib/featureFlags/defaultFeatures.js.map +1 -1
  31. package/lib/featureFlags/types.d.ts +1 -1
  32. package/lib/featureFlags/types.d.ts.map +1 -1
  33. package/lib/platform/PlatformAppProvider/helpers.d.ts +1 -0
  34. package/lib/platform/PlatformAppProvider/helpers.d.ts.map +1 -1
  35. package/lib/platform/PlatformAppProvider/helpers.js +23 -1
  36. package/lib/platform/PlatformAppProvider/helpers.js.map +1 -1
  37. package/lib/platform/PlatformAppProvider/index.d.ts.map +1 -1
  38. package/lib/platform/PlatformAppProvider/index.js +2 -1
  39. package/lib/platform/PlatformAppProvider/index.js.map +1 -1
  40. package/package.json +1 -1
  41. package/src/__tests__/__snapshots__/all.libcore.ts.snap +109 -0
  42. package/src/__tests__/families/bitcoin/wallet-btc/wallet.integration.test.ts +2 -0
  43. package/src/__tests__/families/bitcoin/wallet-btc/xpub.getAddress.ts +31 -0
  44. package/src/env.ts +5 -0
  45. package/src/families/bitcoin/wallet-btc/crypto/bip32.ts +2 -2
  46. package/src/families/bitcoin/wallet-btc/crypto/zec.ts +19 -19
  47. package/src/families/bitcoin/wallet-btc/crypto/zen.ts +26 -27
  48. package/src/families/solana/test-dataset.ts +3 -4
  49. package/src/families/tezos/synchronisation.ts +2 -0
  50. package/src/featureFlags/FeatureToggle.tsx +2 -2
  51. package/src/featureFlags/defaultFeatures.ts +1 -1
  52. package/src/featureFlags/types.ts +1 -1
  53. package/src/platform/PlatformAppProvider/helpers.ts +29 -0
  54. package/src/platform/PlatformAppProvider/index.tsx +3 -2
@@ -1,11 +1,8 @@
1
1
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2
2
  // @ts-ignore
3
- import { toOutputScript } from "bitcoinjs-lib/src/address";
4
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
5
- // @ts-ignore
6
3
  import zec from "zcash-bitcore-lib";
7
4
  import bs58check from "bs58check";
8
- import coininfo from "coininfo";
5
+ import * as bjs from "bitcoinjs-lib";
9
6
  import { InvalidAddress } from "@ledgerhq/errors";
10
7
  import { DerivationModes } from "../types";
11
8
  import Base from "./base";
@@ -32,19 +29,13 @@ class ZCash extends Base {
32
29
  return bs58check.encode(Buffer.from(taddr));
33
30
  }
34
31
 
35
- private static toBitcoinAddr(taddr: string) {
36
- // refer to https://runkitcdn.com/gojomo/baddr2taddr/1.0.2
37
- const baddr = new Uint8Array(21);
38
- baddr.set(bs58check.decode(taddr).slice(2), 1);
39
- return bs58check.encode(Buffer.from(baddr));
40
- }
41
-
42
32
  // eslint-disable-next-line
43
33
  getLegacyAddress(xpub: string, account: number, index: number): string {
44
- const pubkey = new zec.HDPublicKey(xpub);
45
- const child = pubkey.derive(account).derive(index);
46
- const address = new zec.Address(child.publicKey, zec.Networks.livenet);
47
- return address.toString();
34
+ const pk = bjs.crypto.hash160(this.getPubkeyAt(xpub, account, index));
35
+ const payload = Buffer.allocUnsafe(22);
36
+ payload.writeUInt16BE(this.network.pubKeyHash, 0);
37
+ pk.copy(payload, 2);
38
+ return bs58check.encode(payload);
48
39
  }
49
40
 
50
41
  customGetAddress(
@@ -65,11 +56,20 @@ class ZCash extends Base {
65
56
  if (!this.validateAddress(address)) {
66
57
  throw new InvalidAddress();
67
58
  }
68
- // TODO find a better way to calculate the script from zec address instead of converting to bitcoin address
69
- return toOutputScript(
70
- ZCash.toBitcoinAddr(address),
71
- coininfo.bitcoin.main.toBitcoinJS()
59
+ const version = Number(
60
+ "0x" + bs58check.decode(address).slice(0, 2).toString("hex")
72
61
  );
62
+ if (version === this.network.pubKeyHash) {
63
+ //Pay-to-PubkeyHash
64
+ return bjs.payments.p2pkh({ hash: bs58check.decode(address).slice(2) })
65
+ .output as Buffer;
66
+ }
67
+ if (version === this.network.scriptHash) {
68
+ //Pay-to-Script-Hash
69
+ return bjs.payments.p2sh({ hash: bs58check.decode(address).slice(2) })
70
+ .output as Buffer;
71
+ }
72
+ throw new InvalidAddress();
73
73
  }
74
74
 
75
75
  // eslint-disable-next-line class-methods-use-this
@@ -1,14 +1,8 @@
1
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2
- // @ts-ignore
3
- import { toOutputScript } from "bitcoinjs-lib/src/address";
4
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
5
- // @ts-ignore
6
- import zec from "zcash-bitcore-lib";
7
1
  import bs58check from "bs58check";
8
- import coininfo from "coininfo";
9
2
  import { InvalidAddress } from "@ledgerhq/errors";
10
3
  import { DerivationModes } from "../types";
11
4
  import Base from "./base";
5
+ import * as bjs from "bitcoinjs-lib";
12
6
 
13
7
  class Zen extends Base {
14
8
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -26,15 +20,15 @@ class Zen extends Base {
26
20
  },
27
21
  bip44: 121,
28
22
  private: 0x80,
29
- public: 0x2096,
30
- scripthash: 0x2089,
23
+ public: 0x2089,
24
+ scripthash: 0x2096,
31
25
  };
32
26
  this.network.name = "Zencash";
33
27
  this.network.unit = "ZEN";
34
28
  this.network.messagePrefix = "Zencash Signed Message:\n";
35
29
  this.network.wif = 0x80;
36
- this.network.pubKeyHash = 0x2096;
37
- this.network.scriptHash = 0x2089;
30
+ this.network.pubKeyHash = 0x2089;
31
+ this.network.scriptHash = 0x2096;
38
32
  this.network.dustThreshold = 10000;
39
33
  this.network.dustPolicy = "FIXED";
40
34
  this.network.usesTimestampedTransaction = false;
@@ -50,21 +44,13 @@ class Zen extends Base {
50
44
  return bs58check.encode(Buffer.from(taddr));
51
45
  }
52
46
 
53
- private static toBitcoinAddr(taddr: string) {
54
- // refer to https://runkitcdn.com/gojomo/baddr2taddr/1.0.2
55
- const baddr = new Uint8Array(21);
56
- baddr.set(bs58check.decode(taddr).slice(2), 1);
57
- return bs58check.encode(Buffer.from(baddr));
58
- }
59
-
60
47
  // eslint-disable-next-line
61
48
  getLegacyAddress(xpub: string, account: number, index: number): string {
62
- const pubkey = new zec.HDPublicKey(xpub);
63
- const child = pubkey.derive(account).derive(index);
64
- const address = new zec.Address(child.publicKey, zec.Networks.livenet);
65
- const baddr = new Uint8Array(21);
66
- baddr.set(bs58check.decode(address.toString()).slice(2), 1);
67
- return this.baddrToTaddr(bs58check.encode(Buffer.from(baddr)));
49
+ const pk = bjs.crypto.hash160(this.getPubkeyAt(xpub, account, index));
50
+ const payload = Buffer.allocUnsafe(22);
51
+ payload.writeUInt16BE(this.network.pubKeyHash, 0);
52
+ pk.copy(payload, 2);
53
+ return bs58check.encode(payload);
68
54
  }
69
55
 
70
56
  customGetAddress(
@@ -85,10 +71,23 @@ class Zen extends Base {
85
71
  if (!this.validateAddress(address)) {
86
72
  throw new InvalidAddress();
87
73
  }
88
- const outputScript = toOutputScript(
89
- Zen.toBitcoinAddr(address),
90
- coininfo.bitcoin.main.toBitcoinJS()
74
+ let outputScript: Buffer;
75
+ const version = Number(
76
+ "0x" + bs58check.decode(address).slice(0, 2).toString("hex")
91
77
  );
78
+ if (version === this.network.pubKeyHash) {
79
+ //Pay-to-PubkeyHash
80
+ outputScript = bjs.payments.p2pkh({
81
+ hash: bs58check.decode(address).slice(2),
82
+ }).output as Buffer;
83
+ } else if (version === this.network.scriptHash) {
84
+ //Pay-to-Script-Hash
85
+ outputScript = bjs.payments.p2sh({
86
+ hash: bs58check.decode(address).slice(2),
87
+ }).output as Buffer;
88
+ } else {
89
+ throw new InvalidAddress();
90
+ }
92
91
  // refer to https://github.com/LedgerHQ/lib-ledger-core/blob/fc9d762b83fc2b269d072b662065747a64ab2816/core/src/wallet/bitcoin/scripts/BitcoinLikeScript.cpp#L139 and https://github.com/LedgerHQ/lib-ledger-core/blob/fc9d762b83fc2b269d072b662065747a64ab2816/core/src/wallet/bitcoin/networks.cpp#L39 for bip115 Script and its network parameters
93
92
  const bip115Script = Buffer.from(
94
93
  "209ec9845acb02fab24e1c0368b3b517c1a4488fba97f0e3459ac053ea0100000003c01f02b4",
@@ -1,5 +1,5 @@
1
1
  import BigNumber from "bignumber.js";
2
- import { DatasetTest, encodeAccountId } from "../../types";
2
+ import { CurrenciesData, DatasetTest, encodeAccountId } from "../../types";
3
3
 
4
4
  import { Transaction, TransactionModel } from "./types";
5
5
 
@@ -75,8 +75,7 @@ const fees = (signatureCount: number) =>
75
75
 
76
76
  const zero = new BigNumber(0);
77
77
 
78
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
79
- const solana = {
78
+ const solana: CurrenciesData<Transaction> = {
80
79
  scanAccounts: [scanAccounts1],
81
80
  accounts: [
82
81
  {
@@ -438,7 +437,7 @@ const solana = {
438
437
  const dataset: DatasetTest<Transaction> = {
439
438
  implementations: [getEnv("MOCK") ? "mock" : "js"], // FIXME we should actually put both mock and js like other dataset do
440
439
  currencies: {
441
- // solana, // TODO re enable when it's ready
440
+ solana,
442
441
  },
443
442
  };
444
443
 
@@ -74,6 +74,7 @@ export const getAccountShape: GetAccountShape = async (infoInput) => {
74
74
  if (apiAccount.type === "empty") {
75
75
  return {
76
76
  id: accountId,
77
+ xpub: address,
77
78
  blockHeight,
78
79
  lastSyncDate: new Date(),
79
80
  tezosResources: {
@@ -110,6 +111,7 @@ export const getAccountShape: GetAccountShape = async (infoInput) => {
110
111
 
111
112
  const accountShape = {
112
113
  id: accountId,
114
+ xpub: address,
113
115
  operations,
114
116
  balance,
115
117
  subAccounts,
@@ -17,8 +17,8 @@ export const FeatureToggle = ({
17
17
  const feature = useFeature(featureId);
18
18
 
19
19
  if (!feature || !feature.enabled) {
20
- return fallback;
20
+ return fallback ?? null;
21
21
  }
22
22
 
23
- return children;
23
+ return children ?? null;
24
24
  };
@@ -1,7 +1,7 @@
1
1
  import { DefaultFeatures } from "./types";
2
2
 
3
3
  export const defaultFeatures: DefaultFeatures = {
4
- market: {
4
+ learn: {
5
5
  enabled: false,
6
6
  },
7
7
  };
@@ -1,4 +1,4 @@
1
- export type FeatureId = "market"; // Add others with union
1
+ export type FeatureId = "learn"; // Add others with union (e.g. "learn" | "market" | "foo")
2
2
 
3
3
  // We use objects instead of direct booleans for potential future improvements
4
4
  // like feature versioning etc
@@ -6,6 +6,7 @@ export type FilterParams = {
6
6
  private?: boolean;
7
7
  version?: string;
8
8
  };
9
+ import { getEnv } from "../../env";
9
10
 
10
11
  function matchVersion(filterParams: FilterParams, manifest: AppManifest) {
11
12
  return (
@@ -52,3 +53,31 @@ export function mergeManifestLists(
52
53
  const newIds = new Set(list2.map((elem) => elem.id));
53
54
  return [...list1.filter((elem) => !newIds.has(elem.id)), ...list2];
54
55
  }
56
+
57
+ export const initializeLocalManifest = (): Map<string, AppManifest> => {
58
+ const localManifestJsonRaw: string | null | undefined = getEnv(
59
+ "PLATFORM_LOCAL_MANIFEST_JSON"
60
+ );
61
+
62
+ if (!localManifestJsonRaw) {
63
+ return new Map();
64
+ }
65
+
66
+ try {
67
+ const manifest: AppManifest | [AppManifest] =
68
+ JSON.parse(localManifestJsonRaw);
69
+
70
+ const manifestArray = Array.isArray(manifest) ? manifest : [manifest];
71
+
72
+ const map = new Map(manifestArray.map((m) => [m.id, m]));
73
+
74
+ return map;
75
+ } catch (error) {
76
+ /**
77
+ * Probable error during `JSON.parse` call, log error and return empty map
78
+ * as if env variable was not defined
79
+ */
80
+ console.error(error);
81
+ return new Map();
82
+ }
83
+ };
@@ -9,11 +9,12 @@ import React, {
9
9
  import type { PlatformAppContextType, Props, State } from "./types";
10
10
  import api from "./api";
11
11
  import type { AppManifest } from "../types";
12
+ import { initializeLocalManifest } from "./helpers";
12
13
 
13
14
  // @ts-expect-error empty object creates an error
14
15
  const PlatformAppContext = createContext<PlatformAppContextType>({});
15
16
  const initialState: State = {
16
- localManifests: new Map(),
17
+ localManifests: initializeLocalManifest(),
17
18
  remoteManifests: new Map(),
18
19
  isLoading: false,
19
20
  lastUpdateTime: undefined,
@@ -28,7 +29,7 @@ export function PlatformAppProvider({
28
29
  autoUpdateDelay,
29
30
  platformAppsServerURL,
30
31
  children,
31
- }: Props) {
32
+ }: Props): JSX.Element {
32
33
  const [state, setState] = useState<State>(initialState);
33
34
 
34
35
  const addLocalManifest = useCallback((manifest: AppManifest) => {