@ledgerhq/coin-bitcoin 0.7.3-nightly.2 → 0.7.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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +2 -22
- package/jest.config.js +0 -1
- package/lib/bridge/js.d.ts +1 -5
- package/lib/bridge/js.d.ts.map +1 -1
- package/lib/bridge/js.js +7 -7
- package/lib/bridge/js.js.map +1 -1
- package/lib/getTransactionStatus.js.map +1 -1
- package/lib/hw-signMessage.test.js +39 -2
- package/lib/hw-signMessage.test.js.map +1 -1
- package/lib/synchronisation.d.ts +1 -7
- package/lib/synchronisation.d.ts.map +1 -1
- package/lib/synchronisation.js +1 -16
- package/lib/synchronisation.js.map +1 -1
- package/lib-es/bridge/js.d.ts +1 -5
- package/lib-es/bridge/js.d.ts.map +1 -1
- package/lib-es/bridge/js.js +7 -7
- package/lib-es/bridge/js.js.map +1 -1
- package/lib-es/getTransactionStatus.js.map +1 -1
- package/lib-es/hw-signMessage.test.js +35 -1
- package/lib-es/hw-signMessage.test.js.map +1 -1
- package/lib-es/synchronisation.d.ts +1 -7
- package/lib-es/synchronisation.d.ts.map +1 -1
- package/lib-es/synchronisation.js +1 -16
- package/lib-es/synchronisation.js.map +1 -1
- package/package.json +7 -7
- package/src/bridge/js.ts +8 -16
- package/src/getTransactionStatus.ts +1 -1
- package/src/hw-signMessage.test.ts +41 -1
- package/src/synchronisation.ts +1 -30
- package/lib/__tests__/fixtures/common.fixtures.d.ts +0 -16
- package/lib/__tests__/fixtures/common.fixtures.d.ts.map +0 -1
- package/lib/__tests__/fixtures/common.fixtures.js +0 -131
- package/lib/__tests__/fixtures/common.fixtures.js.map +0 -1
- package/lib/__tests__/unit/buildTransaction.unit.test.d.ts +0 -2
- package/lib/__tests__/unit/buildTransaction.unit.test.d.ts.map +0 -1
- package/lib/__tests__/unit/buildTransaction.unit.test.js +0 -75
- package/lib/__tests__/unit/buildTransaction.unit.test.js.map +0 -1
- package/lib/__tests__/unit/synchronisation.unit.test.d.ts +0 -2
- package/lib/__tests__/unit/synchronisation.unit.test.d.ts.map +0 -1
- package/lib/__tests__/unit/synchronisation.unit.test.js +0 -69
- package/lib/__tests__/unit/synchronisation.unit.test.js.map +0 -1
- package/lib/wallet-btc/__tests__/fixtures/common.fixtures.d.ts +0 -10
- package/lib/wallet-btc/__tests__/fixtures/common.fixtures.d.ts.map +0 -1
- package/lib/wallet-btc/__tests__/fixtures/common.fixtures.js +0 -84
- package/lib/wallet-btc/__tests__/fixtures/common.fixtures.js.map +0 -1
- package/lib/wallet-btc/__tests__/wallet.unit.test.d.ts +0 -2
- package/lib/wallet-btc/__tests__/wallet.unit.test.d.ts.map +0 -1
- package/lib/wallet-btc/__tests__/wallet.unit.test.js +0 -194
- package/lib/wallet-btc/__tests__/wallet.unit.test.js.map +0 -1
- package/lib/wallet-btc/__tests__/xpub.unit.test.d.ts +0 -2
- package/lib/wallet-btc/__tests__/xpub.unit.test.d.ts.map +0 -1
- package/lib/wallet-btc/__tests__/xpub.unit.test.js +0 -149
- package/lib/wallet-btc/__tests__/xpub.unit.test.js.map +0 -1
- package/lib-es/__tests__/fixtures/common.fixtures.d.ts +0 -16
- package/lib-es/__tests__/fixtures/common.fixtures.d.ts.map +0 -1
- package/lib-es/__tests__/fixtures/common.fixtures.js +0 -123
- package/lib-es/__tests__/fixtures/common.fixtures.js.map +0 -1
- package/lib-es/__tests__/unit/buildTransaction.unit.test.d.ts +0 -2
- package/lib-es/__tests__/unit/buildTransaction.unit.test.d.ts.map +0 -1
- package/lib-es/__tests__/unit/buildTransaction.unit.test.js +0 -70
- package/lib-es/__tests__/unit/buildTransaction.unit.test.js.map +0 -1
- package/lib-es/__tests__/unit/synchronisation.unit.test.d.ts +0 -2
- package/lib-es/__tests__/unit/synchronisation.unit.test.d.ts.map +0 -1
- package/lib-es/__tests__/unit/synchronisation.unit.test.js +0 -67
- package/lib-es/__tests__/unit/synchronisation.unit.test.js.map +0 -1
- package/lib-es/wallet-btc/__tests__/fixtures/common.fixtures.d.ts +0 -10
- package/lib-es/wallet-btc/__tests__/fixtures/common.fixtures.d.ts.map +0 -1
- package/lib-es/wallet-btc/__tests__/fixtures/common.fixtures.js +0 -77
- package/lib-es/wallet-btc/__tests__/fixtures/common.fixtures.js.map +0 -1
- package/lib-es/wallet-btc/__tests__/wallet.unit.test.d.ts +0 -2
- package/lib-es/wallet-btc/__tests__/wallet.unit.test.d.ts.map +0 -1
- package/lib-es/wallet-btc/__tests__/wallet.unit.test.js +0 -189
- package/lib-es/wallet-btc/__tests__/wallet.unit.test.js.map +0 -1
- package/lib-es/wallet-btc/__tests__/xpub.unit.test.d.ts +0 -2
- package/lib-es/wallet-btc/__tests__/xpub.unit.test.d.ts.map +0 -1
- package/lib-es/wallet-btc/__tests__/xpub.unit.test.js +0 -144
- package/lib-es/wallet-btc/__tests__/xpub.unit.test.js.map +0 -1
- package/src/__tests__/fixtures/common.fixtures.ts +0 -175
- package/src/__tests__/unit/buildTransaction.unit.test.ts +0 -72
- package/src/__tests__/unit/synchronisation.unit.test.ts +0 -63
- package/src/wallet-btc/__tests__/fixtures/common.fixtures.ts +0 -86
- package/src/wallet-btc/__tests__/wallet.unit.test.ts +0 -226
- package/src/wallet-btc/__tests__/xpub.unit.test.ts +0 -172
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ledgerhq/coin-bitcoin",
|
|
3
|
-
"version": "0.7.3
|
|
3
|
+
"version": "0.7.3",
|
|
4
4
|
"description": "Ledger Bitcoin Coin integration",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ledger",
|
|
@@ -63,12 +63,12 @@
|
|
|
63
63
|
"sha.js": "^2.4.11",
|
|
64
64
|
"utility-types": "^3.10.0",
|
|
65
65
|
"varuint-bitcoin": "1.1.2",
|
|
66
|
-
"@ledgerhq/coin-framework": "^0.17.
|
|
67
|
-
"@ledgerhq/cryptoassets": "^13.
|
|
68
|
-
"@ledgerhq/devices": "^8.4.
|
|
69
|
-
"@ledgerhq/errors": "^6.
|
|
70
|
-
"@ledgerhq/live-env": "^2.
|
|
71
|
-
"@ledgerhq/live-network": "^1.4.
|
|
66
|
+
"@ledgerhq/coin-framework": "^0.17.0",
|
|
67
|
+
"@ledgerhq/cryptoassets": "^13.3.0",
|
|
68
|
+
"@ledgerhq/devices": "^8.4.2",
|
|
69
|
+
"@ledgerhq/errors": "^6.18.0",
|
|
70
|
+
"@ledgerhq/live-env": "^2.2.0",
|
|
71
|
+
"@ledgerhq/live-network": "^1.4.0",
|
|
72
72
|
"@ledgerhq/logs": "^6.12.0",
|
|
73
73
|
"@ledgerhq/types-cryptoassets": "^7.15.0",
|
|
74
74
|
"@ledgerhq/types-live": "^6.50.0"
|
package/src/bridge/js.ts
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
makeSync,
|
|
6
6
|
} from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
7
7
|
import getAddressWrapper from "@ledgerhq/coin-framework/bridge/getAddressWrapper";
|
|
8
|
-
import {
|
|
8
|
+
import { makeGetAccountShape, postSync } from "../synchronisation";
|
|
9
9
|
import { assignFromAccountRaw, assignToAccountRaw } from "../serialization";
|
|
10
10
|
import { BitcoinAccount, Transaction, TransactionStatus } from "../types";
|
|
11
11
|
import { getTransactionStatus } from "../getTransactionStatus";
|
|
@@ -21,10 +21,10 @@ import { broadcast } from "../broadcast";
|
|
|
21
21
|
import { perCoinLogic } from "../logic";
|
|
22
22
|
import resolver from "../hw-getAddress";
|
|
23
23
|
|
|
24
|
-
function buildCurrencyBridge(signerContext: SignerContext
|
|
24
|
+
function buildCurrencyBridge(signerContext: SignerContext) {
|
|
25
25
|
const getAddress = resolver(signerContext);
|
|
26
26
|
const scanAccounts = makeScanAccounts<BitcoinAccount>({
|
|
27
|
-
getAccountShape: makeGetAccountShape(signerContext
|
|
27
|
+
getAccountShape: makeGetAccountShape(signerContext),
|
|
28
28
|
getAddressFn: getAddressWrapper(getAddress),
|
|
29
29
|
});
|
|
30
30
|
|
|
@@ -35,9 +35,9 @@ function buildCurrencyBridge(signerContext: SignerContext, perfLogger: PerfLogge
|
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
function buildAccountBridge(signerContext: SignerContext
|
|
38
|
+
function buildAccountBridge(signerContext: SignerContext) {
|
|
39
39
|
const sync = makeSync<Transaction, BitcoinAccount, TransactionStatus>({
|
|
40
|
-
getAccountShape: makeGetAccountShape(signerContext
|
|
40
|
+
getAccountShape: makeGetAccountShape(signerContext),
|
|
41
41
|
postSync,
|
|
42
42
|
});
|
|
43
43
|
|
|
@@ -79,19 +79,11 @@ function buildAccountBridge(signerContext: SignerContext, perfLogger: PerfLogger
|
|
|
79
79
|
};
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
export
|
|
83
|
-
startSpan: StartSpan;
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
export function createBridges(
|
|
87
|
-
signerContext: SignerContext,
|
|
88
|
-
perfLogger: PerfLogger,
|
|
89
|
-
coinConfig: CoinConfig,
|
|
90
|
-
) {
|
|
82
|
+
export function createBridges(signerContext: SignerContext, coinConfig: CoinConfig) {
|
|
91
83
|
setCoinConfig(coinConfig);
|
|
92
84
|
|
|
93
85
|
return {
|
|
94
|
-
currencyBridge: buildCurrencyBridge(signerContext
|
|
95
|
-
accountBridge: buildAccountBridge(signerContext
|
|
86
|
+
currencyBridge: buildCurrencyBridge(signerContext),
|
|
87
|
+
accountBridge: buildAccountBridge(signerContext),
|
|
96
88
|
};
|
|
97
89
|
}
|
|
@@ -22,7 +22,7 @@ export const getTransactionStatus: AccountBridge<
|
|
|
22
22
|
Transaction,
|
|
23
23
|
Account,
|
|
24
24
|
TransactionStatus
|
|
25
|
-
>["getTransactionStatus"] = async (account
|
|
25
|
+
>["getTransactionStatus"] = async (account, transaction) => {
|
|
26
26
|
const errors: Record<string, Error> = {};
|
|
27
27
|
const warnings: Record<string, Error> = {};
|
|
28
28
|
const useAllAmount = !!transaction.useAllAmount;
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import { emptyHistoryCache } from "@ledgerhq/coin-framework/account/index";
|
|
1
3
|
import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
4
|
+
import { listCryptoCurrencies } from "@ledgerhq/cryptoassets/index";
|
|
2
5
|
import { signMessage } from "./hw-signMessage";
|
|
3
6
|
import { BitcoinSigner } from "./signer";
|
|
4
|
-
import {
|
|
7
|
+
import { BitcoinAccount, BitcoinResources } from "./types";
|
|
5
8
|
|
|
6
9
|
describe("signMessage", () => {
|
|
7
10
|
it("returns a base64 format string", async () => {
|
|
@@ -40,3 +43,40 @@ describe("signMessage", () => {
|
|
|
40
43
|
});
|
|
41
44
|
});
|
|
42
45
|
});
|
|
46
|
+
|
|
47
|
+
function createFixtureAccount(account?: Partial<BitcoinAccount>): BitcoinAccount {
|
|
48
|
+
const currency = listCryptoCurrencies(true).find(c => c.id === "bitcoin")!;
|
|
49
|
+
|
|
50
|
+
const bitcoinResources: BitcoinResources = account?.bitcoinResources || {
|
|
51
|
+
utxos: [],
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const freshAddress = {
|
|
55
|
+
address: "1fMK6i7CMDES1GNGDEMX5ddDaxbkjWPw1M",
|
|
56
|
+
derivationPath: "derivation_path",
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
type: "Account",
|
|
61
|
+
id: "E0A538D5-5EE7-4E37-BB57-F373B08B8580",
|
|
62
|
+
seedIdentifier: "FD5EAFE3-8C7F-4565-ADFA-2A1A2067322A",
|
|
63
|
+
derivationMode: "",
|
|
64
|
+
index: 0,
|
|
65
|
+
freshAddress: freshAddress.address,
|
|
66
|
+
freshAddressPath: freshAddress.derivationPath,
|
|
67
|
+
used: true,
|
|
68
|
+
balance: account?.balance || new BigNumber(0),
|
|
69
|
+
spendableBalance: account?.spendableBalance || new BigNumber(0),
|
|
70
|
+
creationDate: new Date(),
|
|
71
|
+
blockHeight: 100_000,
|
|
72
|
+
currency,
|
|
73
|
+
operationsCount: 0,
|
|
74
|
+
operations: [],
|
|
75
|
+
pendingOperations: [],
|
|
76
|
+
lastSyncDate: new Date(),
|
|
77
|
+
balanceHistoryCache: emptyHistoryCache,
|
|
78
|
+
swapHistory: [],
|
|
79
|
+
|
|
80
|
+
bitcoinResources,
|
|
81
|
+
};
|
|
82
|
+
}
|
package/src/synchronisation.ts
CHANGED
|
@@ -71,23 +71,8 @@ const deduplicateOperations = (operations: (Operation | undefined)[]): Operation
|
|
|
71
71
|
return out;
|
|
72
72
|
};
|
|
73
73
|
|
|
74
|
-
|
|
75
|
-
export type StartSpan = (
|
|
76
|
-
op: string,
|
|
77
|
-
description?: string,
|
|
78
|
-
rest?: {
|
|
79
|
-
tags?: any;
|
|
80
|
-
data?: any;
|
|
81
|
-
},
|
|
82
|
-
) => {
|
|
83
|
-
finish: () => void;
|
|
84
|
-
};
|
|
85
|
-
export function makeGetAccountShape(
|
|
86
|
-
signerContext: SignerContext,
|
|
87
|
-
startSpan: StartSpan,
|
|
88
|
-
): GetAccountShape<BitcoinAccount> {
|
|
74
|
+
export function makeGetAccountShape(signerContext: SignerContext): GetAccountShape<BitcoinAccount> {
|
|
89
75
|
return async info => {
|
|
90
|
-
let span;
|
|
91
76
|
const { currency, index, derivationPath, derivationMode, initialAccount, deviceId } = info;
|
|
92
77
|
// In case we get a full derivation path, extract the seed identification part
|
|
93
78
|
// 44'/0'/0'/0/0 --> 44'/0'
|
|
@@ -115,7 +100,6 @@ export function makeGetAccountShape(
|
|
|
115
100
|
const walletNetwork = toWalletNetwork(currency.id);
|
|
116
101
|
const walletDerivationMode = toWalletDerivationMode(derivationMode);
|
|
117
102
|
|
|
118
|
-
span = startSpan("sync", "generateAccount");
|
|
119
103
|
const walletAccount =
|
|
120
104
|
initialAccount?.bitcoinResources?.walletAccount ||
|
|
121
105
|
(await wallet.generateAccount(
|
|
@@ -129,7 +113,6 @@ export function makeGetAccountShape(
|
|
|
129
113
|
},
|
|
130
114
|
currency,
|
|
131
115
|
));
|
|
132
|
-
span.finish();
|
|
133
116
|
|
|
134
117
|
const oldOperations = initialAccount?.operations || [];
|
|
135
118
|
const currentBlock = await walletAccount.xpub.explorer.getCurrentBlock();
|
|
@@ -138,39 +121,27 @@ export function makeGetAccountShape(
|
|
|
138
121
|
await wallet.syncAccount(walletAccount, blockHeight);
|
|
139
122
|
|
|
140
123
|
const balance = await wallet.getAccountBalance(walletAccount);
|
|
141
|
-
span = startSpan("sync", "getAccountTransactions");
|
|
142
124
|
const { txs: transactions } = await wallet.getAccountTransactions(walletAccount);
|
|
143
|
-
span.finish();
|
|
144
125
|
|
|
145
|
-
span = startSpan("sync", "getXpubAddresses");
|
|
146
126
|
const accountAddresses: Set<string> = new Set<string>();
|
|
147
127
|
const accountAddressesWithInfo = await walletAccount.xpub.getXpubAddresses();
|
|
148
128
|
accountAddressesWithInfo.forEach(a => accountAddresses.add(a.address));
|
|
149
|
-
span.finish();
|
|
150
129
|
|
|
151
|
-
span = startSpan("sync", "getUniquesAddresses");
|
|
152
130
|
const changeAddresses: Set<string> = new Set<string>();
|
|
153
131
|
const changeAddressesWithInfo = await walletAccount.xpub.storage.getUniquesAddresses({
|
|
154
132
|
account: 1,
|
|
155
133
|
});
|
|
156
134
|
changeAddressesWithInfo.forEach(a => changeAddresses.add(a.address));
|
|
157
|
-
span.finish();
|
|
158
135
|
|
|
159
|
-
span = startSpan("sync", "mapTxToOperations");
|
|
160
136
|
const newOperations = transactions
|
|
161
137
|
?.map(tx => mapTxToOperations(tx, currency.id, accountId, accountAddresses, changeAddresses))
|
|
162
138
|
.flat();
|
|
163
|
-
span.finish();
|
|
164
139
|
|
|
165
|
-
span = startSpan("sync", "unify operations");
|
|
166
140
|
const newUniqueOperations = deduplicateOperations(newOperations);
|
|
167
141
|
const operations = mergeOps(oldOperations, newUniqueOperations);
|
|
168
|
-
span.finish();
|
|
169
142
|
|
|
170
|
-
span = startSpan("sync", "gather utxos");
|
|
171
143
|
const rawUtxos = await wallet.getAccountUnspentUtxos(walletAccount);
|
|
172
144
|
const utxos = rawUtxos.map(utxo => fromWalletUtxo(utxo, changeAddresses));
|
|
173
|
-
span.finish();
|
|
174
145
|
|
|
175
146
|
return {
|
|
176
147
|
id: accountId,
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
2
|
-
import { BitcoinAccount, NetworkInfoRaw } from "../../types";
|
|
3
|
-
import { BitcoinSigner } from "../../signer";
|
|
4
|
-
export declare const networkInfo: NetworkInfoRaw;
|
|
5
|
-
export declare function createFixtureAccount(account?: Partial<BitcoinAccount>): BitcoinAccount;
|
|
6
|
-
export declare const mockXpubPubKey: {
|
|
7
|
-
xpub: string[];
|
|
8
|
-
pubKey: {
|
|
9
|
-
publicKey: string;
|
|
10
|
-
bitcoinAddress: string;
|
|
11
|
-
chainCode: string;
|
|
12
|
-
}[];
|
|
13
|
-
};
|
|
14
|
-
export declare const mockSigner: BitcoinSigner;
|
|
15
|
-
export declare const mockSignerContext: <T>(_deviceId: string, _crypto: CryptoCurrency, fn: (signer: BitcoinSigner) => Promise<T>) => Promise<T>;
|
|
16
|
-
//# sourceMappingURL=common.fixtures.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"common.fixtures.d.ts","sourceRoot":"","sources":["../../../src/__tests__/fixtures/common.fixtures.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAoB,cAAc,EAAE,MAAM,aAAa,CAAC;AAC/E,OAAO,EAIL,aAAa,EAId,MAAM,cAAc,CAAC;AAEtB,eAAO,MAAM,WAAW,EAAE,cAsBzB,CAAC;AAEF,wBAAgB,oBAAoB,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,GAAG,cAAc,CAmCtF;AAED,eAAO,MAAM,cAAc;;;;;;;CAY1B,CAAC;AAEF,eAAO,MAAM,UAAU,EAAE,aAuCxB,CAAC;AAEF,eAAO,MAAM,iBAAiB,iBACjB,MAAM,WACR,cAAc,eACV,aAAa,KAAK,QAAQ,CAAC,CAAC,KACxC,QAAQ,CAAC,CAuCR,CAAC"}
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.mockSignerContext = exports.mockSigner = exports.mockXpubPubKey = exports.createFixtureAccount = exports.networkInfo = void 0;
|
|
7
|
-
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
8
|
-
const currencies_1 = require("@ledgerhq/cryptoassets/currencies");
|
|
9
|
-
const index_1 = require("@ledgerhq/coin-framework/account/index");
|
|
10
|
-
exports.networkInfo = {
|
|
11
|
-
family: "bitcoin",
|
|
12
|
-
feeItems: {
|
|
13
|
-
items: [
|
|
14
|
-
{
|
|
15
|
-
key: "0",
|
|
16
|
-
speed: "high",
|
|
17
|
-
feePerByte: "3",
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
key: "1",
|
|
21
|
-
speed: "standard",
|
|
22
|
-
feePerByte: "2",
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
key: "2",
|
|
26
|
-
speed: "low",
|
|
27
|
-
feePerByte: "1",
|
|
28
|
-
},
|
|
29
|
-
],
|
|
30
|
-
defaultFeePerByte: "1",
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
function createFixtureAccount(account) {
|
|
34
|
-
const currency = (0, currencies_1.listCryptoCurrencies)(true).find(c => c.id === "bitcoin");
|
|
35
|
-
const bitcoinResources = (account === null || account === void 0 ? void 0 : account.bitcoinResources) || {
|
|
36
|
-
utxos: [],
|
|
37
|
-
};
|
|
38
|
-
const freshAddress = {
|
|
39
|
-
address: "1fMK6i7CMDES1GNGDEMX5ddDaxbkjWPw1M",
|
|
40
|
-
derivationPath: "derivation_path",
|
|
41
|
-
};
|
|
42
|
-
return {
|
|
43
|
-
type: "Account",
|
|
44
|
-
id: "E0A538D5-5EE7-4E37-BB57-F373B08B8580",
|
|
45
|
-
seedIdentifier: "FD5EAFE3-8C7F-4565-ADFA-2A1A2067322A",
|
|
46
|
-
derivationMode: "",
|
|
47
|
-
index: 0,
|
|
48
|
-
freshAddress: freshAddress.address,
|
|
49
|
-
freshAddressPath: freshAddress.derivationPath,
|
|
50
|
-
used: true,
|
|
51
|
-
balance: (account === null || account === void 0 ? void 0 : account.balance) || new bignumber_js_1.default(0),
|
|
52
|
-
spendableBalance: (account === null || account === void 0 ? void 0 : account.spendableBalance) || new bignumber_js_1.default(0),
|
|
53
|
-
creationDate: new Date(),
|
|
54
|
-
blockHeight: 100000,
|
|
55
|
-
currency,
|
|
56
|
-
operationsCount: 0,
|
|
57
|
-
operations: [],
|
|
58
|
-
pendingOperations: [],
|
|
59
|
-
lastSyncDate: new Date(),
|
|
60
|
-
balanceHistoryCache: index_1.emptyHistoryCache,
|
|
61
|
-
swapHistory: [],
|
|
62
|
-
bitcoinResources,
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
exports.createFixtureAccount = createFixtureAccount;
|
|
66
|
-
exports.mockXpubPubKey = {
|
|
67
|
-
xpub: [
|
|
68
|
-
"xpub6DEHKg8fgKcb5iYGPLtpBYD9gm7nvym3wwhHVnH3TtogvJGTcApj71K8iTpL7CzdZWAxwyjkZEFUrnLK24zKqgj3EVH7Vg1CD1ujibwiHuy",
|
|
69
|
-
],
|
|
70
|
-
pubKey: [
|
|
71
|
-
{
|
|
72
|
-
publicKey: "xpub6DEHKg8fgKcb5iYGPLtpBYD9gm7nvym3wwhHVnH3TtogvJGTcApj71K8iTpL7CzdZWAxwyjkZEFUrnLK24zKqgj3EVH7Vg1CD1ujibwiHuy",
|
|
73
|
-
bitcoinAddress: "bc1qhh568mfmwu7ymvwhu5e4mttpfg4ehxfpvhjs64",
|
|
74
|
-
chainCode: "",
|
|
75
|
-
},
|
|
76
|
-
],
|
|
77
|
-
};
|
|
78
|
-
exports.mockSigner = {
|
|
79
|
-
getWalletXpub: (_arg) => Promise.resolve(""),
|
|
80
|
-
getWalletPublicKey: (_path, _opts) => {
|
|
81
|
-
return Promise.resolve({
|
|
82
|
-
publicKey: "",
|
|
83
|
-
bitcoinAddress: "",
|
|
84
|
-
chainCode: "",
|
|
85
|
-
});
|
|
86
|
-
},
|
|
87
|
-
signMessage: (_path, _messageHex) => Promise.resolve({
|
|
88
|
-
v: 0,
|
|
89
|
-
r: "123",
|
|
90
|
-
s: "456",
|
|
91
|
-
}),
|
|
92
|
-
splitTransaction: (_transactionHex, _isSegwitSupported, _hasExtraData, _additionals) => ({
|
|
93
|
-
version: Buffer.from(""),
|
|
94
|
-
inputs: [
|
|
95
|
-
{
|
|
96
|
-
prevout: Buffer.from(""),
|
|
97
|
-
script: Buffer.from(""),
|
|
98
|
-
sequence: Buffer.from(""),
|
|
99
|
-
},
|
|
100
|
-
],
|
|
101
|
-
}),
|
|
102
|
-
createPaymentTransaction: (_arg) => Promise.resolve("createPaymentTransactionReturn"),
|
|
103
|
-
};
|
|
104
|
-
const mockSignerContext = (_deviceId, _crypto, fn) => fn({
|
|
105
|
-
getWalletXpub: (_arg) => Promise.resolve(""),
|
|
106
|
-
getWalletPublicKey: (_path, _opts) => {
|
|
107
|
-
return Promise.resolve({
|
|
108
|
-
publicKey: "",
|
|
109
|
-
bitcoinAddress: "",
|
|
110
|
-
chainCode: "",
|
|
111
|
-
});
|
|
112
|
-
},
|
|
113
|
-
signMessage: (_path, _messageHex) => Promise.resolve({
|
|
114
|
-
v: 0,
|
|
115
|
-
r: "123",
|
|
116
|
-
s: "456",
|
|
117
|
-
}),
|
|
118
|
-
splitTransaction: (_transactionHex, _isSegwitSupported, _hasExtraData, _additionals) => ({
|
|
119
|
-
version: Buffer.from(""),
|
|
120
|
-
inputs: [
|
|
121
|
-
{
|
|
122
|
-
prevout: Buffer.from(""),
|
|
123
|
-
script: Buffer.from(""),
|
|
124
|
-
sequence: Buffer.from(""),
|
|
125
|
-
},
|
|
126
|
-
],
|
|
127
|
-
}),
|
|
128
|
-
createPaymentTransaction: (_arg) => Promise.resolve(""),
|
|
129
|
-
});
|
|
130
|
-
exports.mockSignerContext = mockSignerContext;
|
|
131
|
-
//# sourceMappingURL=common.fixtures.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"common.fixtures.js","sourceRoot":"","sources":["../../../src/__tests__/fixtures/common.fixtures.ts"],"names":[],"mappings":";;;;;;AAAA,gEAAqC;AACrC,kEAAyE;AACzE,kEAA2E;AAa9D,QAAA,WAAW,GAAmB;IACzC,MAAM,EAAE,SAAS;IACjB,QAAQ,EAAE;QACR,KAAK,EAAE;YACL;gBACE,GAAG,EAAE,GAAG;gBACR,KAAK,EAAE,MAAM;gBACb,UAAU,EAAE,GAAG;aAChB;YACD;gBACE,GAAG,EAAE,GAAG;gBACR,KAAK,EAAE,UAAU;gBACjB,UAAU,EAAE,GAAG;aAChB;YACD;gBACE,GAAG,EAAE,GAAG;gBACR,KAAK,EAAE,KAAK;gBACZ,UAAU,EAAE,GAAG;aAChB;SACF;QACD,iBAAiB,EAAE,GAAG;KACvB;CACF,CAAC;AAEF,SAAgB,oBAAoB,CAAC,OAAiC;IACpE,MAAM,QAAQ,GAAG,IAAA,iCAAoB,EAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,SAAS,CAAE,CAAC;IAE3E,MAAM,gBAAgB,GAAqB,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,gBAAgB,KAAI;QACtE,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ACJ,CAAC,EAAE,KAAK;QACR,CAAC,EAAE,KAAK;KACT,CAAC;IACJ,gBAAgB,EAAE,CAChB,eAAuB,EACvB,kBAA8C,EAC9C,aAAyC,EACzC,YAA8C,EAC3B,EAAE,CAAC,CAAC;QACvB,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;QACxB,MAAM,EAAE;YACN;gBACE,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;gBACxB,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;gBACvB,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;aAC1B;SACF;KACF,CAAC;IACF,wBAAwB,EAAE,CAAC,IAAuB,EAAmB,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;CAC5F,CAAC,CAAC;AA3CQ,QAAA,iBAAiB,qBA2CzB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"buildTransaction.unit.test.d.ts","sourceRoot":"","sources":["../../../src/__tests__/unit/buildTransaction.unit.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const errors_1 = require("@ledgerhq/errors");
|
|
16
|
-
const types_1 = require("../../types");
|
|
17
|
-
const wallet_btc_1 = __importDefault(require("../../wallet-btc"));
|
|
18
|
-
const transaction_1 = require("../../transaction");
|
|
19
|
-
const buildTransaction_1 = require("../../buildTransaction");
|
|
20
|
-
const common_fixtures_1 = require("../fixtures/common.fixtures");
|
|
21
|
-
jest.mock("../../wallet-btc", () => (Object.assign(Object.assign({}, jest.requireActual("../../wallet-btc")), { getWalletAccount: jest.fn().mockReturnValue({
|
|
22
|
-
xpub: {
|
|
23
|
-
crypto: "bitcoin",
|
|
24
|
-
},
|
|
25
|
-
}) })));
|
|
26
|
-
describe("buildTransaction", () => {
|
|
27
|
-
const mockAccount = (0, common_fixtures_1.createFixtureAccount)();
|
|
28
|
-
const maxSpendable = 100000;
|
|
29
|
-
const txInfo = {
|
|
30
|
-
inputs: [],
|
|
31
|
-
outputs: [],
|
|
32
|
-
fee: 0,
|
|
33
|
-
associatedDerivations: [],
|
|
34
|
-
changeAddress: { address: "change-address", account: 1, index: 1 },
|
|
35
|
-
};
|
|
36
|
-
beforeEach(() => {
|
|
37
|
-
jest.clearAllMocks();
|
|
38
|
-
wallet_btc_1.default.estimateAccountMaxSpendable = jest.fn().mockResolvedValue(maxSpendable);
|
|
39
|
-
wallet_btc_1.default.buildAccountTx = jest.fn().mockResolvedValue(txInfo);
|
|
40
|
-
});
|
|
41
|
-
it("should throw FeeNotLoaded if feePerByte is not provided", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
42
|
-
const transaction = (0, transaction_1.fromTransactionRaw)({
|
|
43
|
-
family: "bitcoin",
|
|
44
|
-
recipient: "1Cz2ZXb6Y6AacXJTpo4RBjQMLEmscuxD8e",
|
|
45
|
-
amount: "999",
|
|
46
|
-
feePerByte: null,
|
|
47
|
-
networkInfo: common_fixtures_1.networkInfo,
|
|
48
|
-
rbf: false,
|
|
49
|
-
utxoStrategy: {
|
|
50
|
-
strategy: types_1.bitcoinPickingStrategy.MERGE_OUTPUTS,
|
|
51
|
-
excludeUTXOs: [],
|
|
52
|
-
},
|
|
53
|
-
});
|
|
54
|
-
yield expect((0, buildTransaction_1.buildTransaction)(mockAccount, transaction)).rejects.toThrow(errors_1.FeeNotLoaded);
|
|
55
|
-
}));
|
|
56
|
-
it("should call getWalletAccount with the provided account", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
57
|
-
const transaction = (0, transaction_1.fromTransactionRaw)({
|
|
58
|
-
family: "bitcoin",
|
|
59
|
-
recipient: "1Cz2ZXb6Y6AacXJTpo4RBjQMLEmscuxD8e",
|
|
60
|
-
amount: "999",
|
|
61
|
-
feePerByte: "1",
|
|
62
|
-
networkInfo: common_fixtures_1.networkInfo,
|
|
63
|
-
rbf: false,
|
|
64
|
-
utxoStrategy: {
|
|
65
|
-
strategy: types_1.bitcoinPickingStrategy.MERGE_OUTPUTS,
|
|
66
|
-
excludeUTXOs: [],
|
|
67
|
-
},
|
|
68
|
-
});
|
|
69
|
-
const res = yield (0, buildTransaction_1.buildTransaction)(mockAccount, transaction);
|
|
70
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
71
|
-
expect(require("../../wallet-btc").getWalletAccount).toHaveBeenCalledWith(mockAccount);
|
|
72
|
-
expect(res).toEqual(txInfo);
|
|
73
|
-
}));
|
|
74
|
-
});
|
|
75
|
-
//# sourceMappingURL=buildTransaction.unit.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"buildTransaction.unit.test.js","sourceRoot":"","sources":["../../../src/__tests__/unit/buildTransaction.unit.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,6CAAgD;AAEhD,uCAAqD;AACrD,kEAA2D;AAC3D,mDAAuD;AACvD,6DAA0D;AAE1D,iEAAgF;AAEhF,IAAI,CAAC,IAAI,CAAC,kBAAkB,EAAE,GAAG,EAAE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EAAE,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,qBAAY,CAAC,CAAC;IACzF,CAAC,CAAA,CAAC,CAAC;IAEH,EAAE,CAAC,wDAAwD,EAAE,GAAS,EAAE;QACtE,MAAM,WAAW,GAAG,IAAA,gCAAkB,EAAC;YACrC,MAAM,EAAE,SAAS;YACjB,SAAS,EAAE,oCAAoC;YAC/C,MAAM,EAAE,KAAK;YACb,UAAU,EAAE,GAAG;YACf,WAAW,EAAX,6BAAW;YACX,GAAG,EAAE,KAAK;YACV,YAAY,EAAE;gBACZ,QAAQ,EAAE,8BAAsB,CAAC,aAAa;gBAC9C,YAAY,EAAE,EAAE;aACjB;SACF,CAAC,CAAC;QAEH,MAAM,GAAG,GAAG,MAAM,IAAA,mCAAgB,EAAC,WAAW,EAAE,WAAW,CAAC,CAAC;QAE7D,8DAA8D;QAC9D,MAAM,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC,gBAAgB,CAAC,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAC;QACvF,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAC9B,CAAC,CAAA,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"synchronisation.unit.test.d.ts","sourceRoot":"","sources":["../../../src/__tests__/unit/synchronisation.unit.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const currencies_1 = require("@ledgerhq/cryptoassets/currencies");
|
|
13
|
-
const synchronisation_1 = require("../../synchronisation");
|
|
14
|
-
const common_fixtures_1 = require("../fixtures/common.fixtures");
|
|
15
|
-
const mockStartSpan = jest.fn().mockReturnValue({
|
|
16
|
-
finish: jest.fn(),
|
|
17
|
-
});
|
|
18
|
-
describe("synchronisation", () => {
|
|
19
|
-
it("should return a function", () => {
|
|
20
|
-
const result = (0, synchronisation_1.makeGetAccountShape)(common_fixtures_1.mockSignerContext, mockStartSpan);
|
|
21
|
-
expect(typeof result).toBe("function");
|
|
22
|
-
});
|
|
23
|
-
it("should return an account shape with the correct properties", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
-
const getAccountShape = (0, synchronisation_1.makeGetAccountShape)(common_fixtures_1.mockSignerContext, mockStartSpan);
|
|
25
|
-
const mockAccount = (0, common_fixtures_1.createFixtureAccount)();
|
|
26
|
-
mockAccount.id =
|
|
27
|
-
"js:2:bitcoin:xpub6DM4oxVnZiePFvQMu1RJLQwWUzZQP3UNaLqrGcbJQkAJZYdiRoRivHULWoYN3zBYU4mJRpM3WrGaqo1kS8Q2XFfd9E3QEc9P3MKHwbHz9LB:native_segwit";
|
|
28
|
-
const result = yield getAccountShape({
|
|
29
|
-
currency: (0, currencies_1.getCryptoCurrencyById)("bitcoin"),
|
|
30
|
-
address: "0x123",
|
|
31
|
-
index: 1,
|
|
32
|
-
derivationPath: "m/44'/0'/0'/0/1",
|
|
33
|
-
derivationMode: "taproot",
|
|
34
|
-
initialAccount: mockAccount,
|
|
35
|
-
}, { paginationConfig: {} });
|
|
36
|
-
expect(result).toMatchObject({
|
|
37
|
-
bitcoinResources: {
|
|
38
|
-
utxos: [],
|
|
39
|
-
walletAccount: {
|
|
40
|
-
params: {
|
|
41
|
-
currency: "bitcoin",
|
|
42
|
-
derivationMode: "Taproot",
|
|
43
|
-
index: 1,
|
|
44
|
-
network: "mainnet",
|
|
45
|
-
path: "m/44'",
|
|
46
|
-
xpub: "xpub6DM4oxVnZiePFvQMu1RJLQwWUzZQP3UNaLqrGcbJQkAJZYdiRoRivHULWoYN3zBYU4mJRpM3WrGaqo1kS8Q2XFfd9E3QEc9P3MKHwbHz9LB",
|
|
47
|
-
},
|
|
48
|
-
xpub: {
|
|
49
|
-
GAP: 20,
|
|
50
|
-
OUTPUT_VALUE_MAX: 9007199254740991,
|
|
51
|
-
derivationMode: "Taproot",
|
|
52
|
-
explorer: { baseUrl: "https://explorers.api.live.ledger.com/blockchain/v4/btc" },
|
|
53
|
-
freshAddress: "bc1pusjmg6xjpym8t8rvdw5gyx2mxvqj0l439acqzy2ssv546k857svqdnth09",
|
|
54
|
-
freshAddressIndex: 0,
|
|
55
|
-
txsSyncArraySize: 1000,
|
|
56
|
-
xpub: "xpub6DM4oxVnZiePFvQMu1RJLQwWUzZQP3UNaLqrGcbJQkAJZYdiRoRivHULWoYN3zBYU4mJRpM3WrGaqo1kS8Q2XFfd9E3QEc9P3MKHwbHz9LB",
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
freshAddress: "bc1pusjmg6xjpym8t8rvdw5gyx2mxvqj0l439acqzy2ssv546k857svqdnth09",
|
|
61
|
-
freshAddressPath: "m/44'/1'/0/0",
|
|
62
|
-
id: "js:2:bitcoin:xpub6DM4oxVnZiePFvQMu1RJLQwWUzZQP3UNaLqrGcbJQkAJZYdiRoRivHULWoYN3zBYU4mJRpM3WrGaqo1kS8Q2XFfd9E3QEc9P3MKHwbHz9LB:taproot",
|
|
63
|
-
operations: [],
|
|
64
|
-
operationsCount: 0,
|
|
65
|
-
xpub: "xpub6DM4oxVnZiePFvQMu1RJLQwWUzZQP3UNaLqrGcbJQkAJZYdiRoRivHULWoYN3zBYU4mJRpM3WrGaqo1kS8Q2XFfd9E3QEc9P3MKHwbHz9LB",
|
|
66
|
-
});
|
|
67
|
-
}));
|
|
68
|
-
});
|
|
69
|
-
//# sourceMappingURL=synchronisation.unit.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"synchronisation.unit.test.js","sourceRoot":"","sources":["../../../src/__tests__/unit/synchronisation.unit.test.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,kEAA0E;AAC1E,2DAA4D;AAE5D,iEAAsF;AAEtF,MAAM,aAAa,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,eAAe,CAAC;IAC9C,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE;CAClB,CAAC,CAAC;AACH,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,EAAE,CAAC,0BAA0B,EAAE,GAAG,EAAE;QAClC,MAAM,MAAM,GAAG,IAAA,qCAAmB,EAAC,mCAAiB,EAAE,aAAa,CAAC,CAAC;QACrE,MAAM,CAAC,OAAO,MAAM,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACzC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,4DAA4D,EAAE,GAAS,EAAE;QAC1E,MAAM,eAAe,GAAG,IAAA,qCAAmB,EAAC,mCAAiB,EAAE,aAAa,CAAC,CAAC;QAC9E,MAAM,WAAW,GAAG,IAAA,sCAAoB,GAAE,CAAC;QAC3C,WAAW,CAAC,EAAE;YACZ,4IAA4I,CAAC;QAC/I,MAAM,MAAM,GAAG,MAAM,eAAe,CAClC;YACE,QAAQ,EAAE,IAAA,kCAAqB,EAAC,SAAS,CAAC;YAC1C,OAAO,EAAE,OAAO;YAChB,KAAK,EAAE,CAAC;YACR,cAAc,EAAE,iBAAiB;YACjC,cAAc,EAAE,SAAS;YACzB,cAAc,EAAE,WAAW;SAC5B,EACD,EAAE,gBAAgB,EAAE,EAAE,EAAE,CACzB,CAAC;QACF,MAAM,CAAC,MAAM,CAAC,CAAC,aAAa,CAAC;YAC3B,gBAAgB,EAAE;gBAChB,KAAK,EAAE,EAAE;gBACT,aAAa,EAAE;oBACb,MAAM,EAAE;wBACN,QAAQ,EAAE,SAAS;wBACnB,cAAc,EAAE,SAAS;wBACzB,KAAK,EAAE,CAAC;wBACR,OAAO,EAAE,SAAS;wBAClB,IAAI,EAAE,OAAO;wBACb,IAAI,EAAE,iHAAiH;qBACxH;oBACD,IAAI,EAAE;wBACJ,GAAG,EAAE,EAAE;wBACP,gBAAgB,EAAE,gBAAgB;wBAClC,cAAc,EAAE,SAAS;wBACzB,QAAQ,EAAE,EAAE,OAAO,EAAE,yDAAyD,EAAE;wBAChF,YAAY,EAAE,gEAAgE;wBAC9E,iBAAiB,EAAE,CAAC;wBACpB,gBAAgB,EAAE,IAAI;wBACtB,IAAI,EAAE,iHAAiH;qBACxH;iBACF;aACF;YACD,YAAY,EAAE,gEAAgE;YAC9E,gBAAgB,EAAE,cAAc;YAChC,EAAE,EAAE,sIAAsI;YAC1I,UAAU,EAAE,EAAE;YACd,eAAe,EAAE,CAAC;YAClB,IAAI,EAAE,iHAAiH;SACxH,CAAC,CAAC;IACL,CAAC,CAAA,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/// <reference types="jest" />
|
|
2
|
-
import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
3
|
-
import { Account } from "../../account";
|
|
4
|
-
import { ICrypto } from "../../crypto/types";
|
|
5
|
-
import { IStorage } from "../../storage/types";
|
|
6
|
-
export declare const mockCrypto: jest.Mocked<ICrypto>;
|
|
7
|
-
export declare const mockCryptoCurrency: CryptoCurrency;
|
|
8
|
-
export declare const getMockAccount: (derivationMode: string) => Account;
|
|
9
|
-
export declare const mockStorage: jest.Mocked<IStorage>;
|
|
10
|
-
//# sourceMappingURL=common.fixtures.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"common.fixtures.d.ts","sourceRoot":"","sources":["../../../../src/wallet-btc/__tests__/fixtures/common.fixtures.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAG9D,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAI7C,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAE/C,eAAO,MAAM,UAAU,sBAOa,CAAC;AAErC,eAAO,MAAM,kBAAkB,gBAwBZ,CAAC;AAEpB,eAAO,MAAM,cAAc,mBAAoB,MAAM,YAqBpD,CAAC;AAEF,eAAO,MAAM,WAAW,uBAiBa,CAAC"}
|