@ledgerhq/coin-bitcoin 0.29.0-nightly.20260115024415 → 0.29.0-nightly.20260116124336
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 +12 -10
- package/lib/bridge/js.d.ts +1 -1
- package/lib/bridge/js.d.ts.map +1 -1
- package/lib/bridge/js.js +2 -3
- package/lib/bridge/js.js.map +1 -1
- package/lib/buildOptimisticOperation.d.ts +13 -0
- package/lib/buildOptimisticOperation.d.ts.map +1 -0
- package/lib/buildOptimisticOperation.js +20 -0
- package/lib/buildOptimisticOperation.js.map +1 -0
- package/lib/explorer.d.ts.map +1 -1
- package/lib/explorer.js +0 -7
- package/lib/explorer.js.map +1 -1
- package/lib/observable.d.ts +4 -0
- package/lib/observable.d.ts.map +1 -0
- package/lib/observable.js +9 -0
- package/lib/observable.js.map +1 -0
- package/lib/psbtFees.d.ts +9 -0
- package/lib/psbtFees.d.ts.map +1 -0
- package/lib/psbtFees.js +73 -0
- package/lib/psbtFees.js.map +1 -0
- package/lib/signOperation.d.ts.map +1 -1
- package/lib/signOperation.js +94 -99
- package/lib/signOperation.js.map +1 -1
- package/lib/signRawOperation.d.ts +6 -0
- package/lib/signRawOperation.d.ts.map +1 -0
- package/lib/signRawOperation.js +70 -0
- package/lib/signRawOperation.js.map +1 -0
- package/lib/signer.d.ts +15 -0
- package/lib/signer.d.ts.map +1 -1
- package/lib/types.d.ts +2 -0
- package/lib/types.d.ts.map +1 -1
- package/lib-es/bridge/js.d.ts +1 -1
- package/lib-es/bridge/js.d.ts.map +1 -1
- package/lib-es/bridge/js.js +2 -3
- package/lib-es/bridge/js.js.map +1 -1
- package/lib-es/buildOptimisticOperation.d.ts +13 -0
- package/lib-es/buildOptimisticOperation.d.ts.map +1 -0
- package/lib-es/buildOptimisticOperation.js +16 -0
- package/lib-es/buildOptimisticOperation.js.map +1 -0
- package/lib-es/explorer.d.ts.map +1 -1
- package/lib-es/explorer.js +0 -7
- package/lib-es/explorer.js.map +1 -1
- package/lib-es/observable.d.ts +4 -0
- package/lib-es/observable.d.ts.map +1 -0
- package/lib-es/observable.js +5 -0
- package/lib-es/observable.js.map +1 -0
- package/lib-es/psbtFees.d.ts +9 -0
- package/lib-es/psbtFees.d.ts.map +1 -0
- package/lib-es/psbtFees.js +69 -0
- package/lib-es/psbtFees.js.map +1 -0
- package/lib-es/signOperation.d.ts.map +1 -1
- package/lib-es/signOperation.js +94 -99
- package/lib-es/signOperation.js.map +1 -1
- package/lib-es/signRawOperation.d.ts +6 -0
- package/lib-es/signRawOperation.d.ts.map +1 -0
- package/lib-es/signRawOperation.js +66 -0
- package/lib-es/signRawOperation.js.map +1 -0
- package/lib-es/signer.d.ts +15 -0
- package/lib-es/signer.d.ts.map +1 -1
- package/lib-es/types.d.ts +2 -0
- package/lib-es/types.d.ts.map +1 -1
- package/package.json +13 -12
- package/src/__tests__/fixtures/common.fixtures.ts +6 -0
- package/src/__tests__/unit/psbtFees.fromFixture.unit.test.ts +31 -0
- package/src/__tests__/unit/signOperation.test.ts +226 -0
- package/src/__tests__/unit/signRawOperation.test.ts +188 -0
- package/src/bridge/js.test.ts +30 -0
- package/src/bridge/js.ts +2 -3
- package/src/buildOptimisticOperation.ts +34 -0
- package/src/explorer.ts +0 -8
- package/src/hw-signMessage.test.ts +1 -0
- package/src/observable.ts +12 -0
- package/src/observable.unit.test.ts +27 -0
- package/src/psbtFees.ts +77 -0
- package/src/signOperation.ts +140 -126
- package/src/signRawOperation.ts +104 -0
- package/src/signer.ts +13 -0
- package/src/types.ts +2 -0
- package/src/wallet-btc/__tests__/fixtures/common.fixtures.ts +64 -1
- package/src/wallet-btc/__tests__/wallet.integration.test.ts +1 -1
- package/src/wallet-btc/__tests__/xpub.txs.dogecoin.integration.test.ts +1 -1
- package/src/wallet-btc/__tests__/xpub.txs.zcash.integration.test.ts +1 -1
- package/tsconfig.json +3 -12
- package/lib/descriptor.d.ts +0 -19
- package/lib/descriptor.d.ts.map +0 -1
- package/lib/descriptor.js +0 -127
- package/lib/descriptor.js.map +0 -1
- package/lib/mockBtcSigner.d.ts +0 -20
- package/lib/mockBtcSigner.d.ts.map +0 -1
- package/lib/mockBtcSigner.js +0 -50
- package/lib/mockBtcSigner.js.map +0 -1
- package/lib-es/descriptor.d.ts +0 -19
- package/lib-es/descriptor.d.ts.map +0 -1
- package/lib-es/descriptor.js +0 -118
- package/lib-es/descriptor.js.map +0 -1
- package/lib-es/mockBtcSigner.d.ts +0 -20
- package/lib-es/mockBtcSigner.d.ts.map +0 -1
- package/lib-es/mockBtcSigner.js +0 -45
- package/lib-es/mockBtcSigner.js.map +0 -1
- package/src/descriptor.test.ts +0 -76
- package/src/descriptor.ts +0 -204
- package/src/mockBtcSigner.ts +0 -65
package/src/descriptor.ts
DELETED
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
import { Observable, from, of, EMPTY } from "rxjs";
|
|
2
|
-
import { concatMap } from "rxjs/operators";
|
|
3
|
-
import invariant from "invariant";
|
|
4
|
-
import bs58 from "bs58";
|
|
5
|
-
import type {
|
|
6
|
-
GetAddressOptions,
|
|
7
|
-
StepAddressInput,
|
|
8
|
-
Result,
|
|
9
|
-
} from "@ledgerhq/coin-framework/derivation";
|
|
10
|
-
import { hash256, hash160 } from "./crypto-util";
|
|
11
|
-
import {
|
|
12
|
-
walletDerivation,
|
|
13
|
-
getDerivationModesForCurrency,
|
|
14
|
-
runAccountDerivationScheme,
|
|
15
|
-
getDerivationScheme,
|
|
16
|
-
} from "@ledgerhq/coin-framework/derivation";
|
|
17
|
-
import getAddress from "./hw-getAddress";
|
|
18
|
-
import type { Account, DerivationMode } from "@ledgerhq/types-live";
|
|
19
|
-
import type { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
20
|
-
import { decodeAccountId } from "@ledgerhq/coin-framework/account/index";
|
|
21
|
-
import { SignerContext } from "./signer";
|
|
22
|
-
|
|
23
|
-
export type AccountDescriptor = {
|
|
24
|
-
internal: string;
|
|
25
|
-
external: string;
|
|
26
|
-
};
|
|
27
|
-
const perDerivation: Partial<
|
|
28
|
-
Record<DerivationMode, ((arg0: string) => string) | null | undefined>
|
|
29
|
-
> = {
|
|
30
|
-
"": fragment => `pkh(${fragment})`,
|
|
31
|
-
segwit: fragment => `sh(wpkh(${fragment}))`,
|
|
32
|
-
native_segwit: fragment => `wpkh(${fragment})`,
|
|
33
|
-
taproot: fragment => `tr(${fragment})`,
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
function makeFingerprint(compressedPubKey: Buffer) {
|
|
37
|
-
return hash160(compressedPubKey).slice(0, 4);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function makeDescriptor({
|
|
41
|
-
currency,
|
|
42
|
-
index,
|
|
43
|
-
derivationMode,
|
|
44
|
-
fingerprint,
|
|
45
|
-
xpub,
|
|
46
|
-
}: {
|
|
47
|
-
currency: CryptoCurrency;
|
|
48
|
-
index: number;
|
|
49
|
-
derivationMode: DerivationMode;
|
|
50
|
-
fingerprint: Buffer;
|
|
51
|
-
xpub: string;
|
|
52
|
-
}) {
|
|
53
|
-
const tmpl = perDerivation[derivationMode];
|
|
54
|
-
if (!tmpl || !xpub) return;
|
|
55
|
-
const keyOrigin = fingerprint.toString("hex");
|
|
56
|
-
const scheme = getDerivationScheme({
|
|
57
|
-
currency,
|
|
58
|
-
derivationMode,
|
|
59
|
-
});
|
|
60
|
-
const accountPath = runAccountDerivationScheme(scheme, currency, {
|
|
61
|
-
account: index,
|
|
62
|
-
});
|
|
63
|
-
return {
|
|
64
|
-
external: tmpl(`[${keyOrigin}/${accountPath}]${xpub}/0/*`),
|
|
65
|
-
internal: tmpl(`[${keyOrigin}/${accountPath}]${xpub}/1/*`),
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export function inferDescriptorFromAccount(account: Account): AccountDescriptor | null | undefined {
|
|
70
|
-
if (account.currency.family !== "bitcoin") return;
|
|
71
|
-
const { id, derivationMode, seedIdentifier, currency, index } = account;
|
|
72
|
-
const xpub = decodeAccountId(id).xpubOrAddress;
|
|
73
|
-
const fingerprint = makeFingerprint(compressPublicKeySECP256(Buffer.from(seedIdentifier, "hex")));
|
|
74
|
-
return makeDescriptor({
|
|
75
|
-
derivationMode,
|
|
76
|
-
currency,
|
|
77
|
-
fingerprint,
|
|
78
|
-
xpub,
|
|
79
|
-
index,
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function asBufferUInt32BE(n: number) {
|
|
84
|
-
const buf = Buffer.allocUnsafe(4);
|
|
85
|
-
buf.writeUInt32BE(n, 0);
|
|
86
|
-
return buf;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const compressPublicKeySECP256 = (publicKey: Buffer) =>
|
|
90
|
-
Buffer.concat([Buffer.from([0x02 + (publicKey[64] & 0x01)]), publicKey.slice(1, 33)]);
|
|
91
|
-
|
|
92
|
-
function makeXpub({
|
|
93
|
-
version,
|
|
94
|
-
depth,
|
|
95
|
-
parentFingerprint,
|
|
96
|
-
index,
|
|
97
|
-
chainCode,
|
|
98
|
-
pubKey,
|
|
99
|
-
}: {
|
|
100
|
-
version: number;
|
|
101
|
-
depth: number;
|
|
102
|
-
parentFingerprint: Buffer;
|
|
103
|
-
index: number;
|
|
104
|
-
chainCode: Buffer;
|
|
105
|
-
pubKey: Buffer;
|
|
106
|
-
}) {
|
|
107
|
-
const indexBuffer = asBufferUInt32BE(index);
|
|
108
|
-
indexBuffer[0] |= 0x80;
|
|
109
|
-
const extendedKeyBytes = Buffer.concat([
|
|
110
|
-
asBufferUInt32BE(version),
|
|
111
|
-
Buffer.from([depth]),
|
|
112
|
-
parentFingerprint,
|
|
113
|
-
indexBuffer,
|
|
114
|
-
chainCode,
|
|
115
|
-
pubKey,
|
|
116
|
-
]);
|
|
117
|
-
const checksum = hash256(extendedKeyBytes).slice(0, 4);
|
|
118
|
-
return bs58.encode(Buffer.concat([extendedKeyBytes, checksum]));
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export function inferDescriptorFromDeviceInfo({
|
|
122
|
-
derivationMode,
|
|
123
|
-
currency,
|
|
124
|
-
index,
|
|
125
|
-
parentDerivation,
|
|
126
|
-
accountDerivation,
|
|
127
|
-
}: {
|
|
128
|
-
derivationMode: DerivationMode;
|
|
129
|
-
currency: CryptoCurrency;
|
|
130
|
-
index: number;
|
|
131
|
-
parentDerivation: Result;
|
|
132
|
-
accountDerivation: Result;
|
|
133
|
-
}): AccountDescriptor | null | undefined {
|
|
134
|
-
invariant(currency.bitcoinLikeInfo, "bitcoin currency expected");
|
|
135
|
-
const { bitcoinLikeInfo } = currency;
|
|
136
|
-
const { XPUBVersion } = bitcoinLikeInfo as {
|
|
137
|
-
P2PKH: number;
|
|
138
|
-
P2SH: number;
|
|
139
|
-
XPUBVersion?: number;
|
|
140
|
-
};
|
|
141
|
-
invariant(XPUBVersion, "unsupported bitcoin fork %s", currency.id);
|
|
142
|
-
const { chainCode } = accountDerivation;
|
|
143
|
-
invariant(chainCode, "chainCode is required");
|
|
144
|
-
const fingerprint = makeFingerprint(
|
|
145
|
-
compressPublicKeySECP256(Buffer.from(parentDerivation.publicKey, "hex")),
|
|
146
|
-
);
|
|
147
|
-
const xpub = makeXpub({
|
|
148
|
-
version: XPUBVersion,
|
|
149
|
-
depth: 3,
|
|
150
|
-
parentFingerprint: fingerprint,
|
|
151
|
-
index,
|
|
152
|
-
chainCode: Buffer.from(chainCode as string, "hex"),
|
|
153
|
-
pubKey: compressPublicKeySECP256(Buffer.from(accountDerivation.publicKey, "hex")),
|
|
154
|
-
});
|
|
155
|
-
return makeDescriptor({
|
|
156
|
-
derivationMode,
|
|
157
|
-
currency,
|
|
158
|
-
fingerprint,
|
|
159
|
-
xpub,
|
|
160
|
-
index,
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
export function scanDescriptors(
|
|
164
|
-
deviceId: string,
|
|
165
|
-
currency: CryptoCurrency,
|
|
166
|
-
signerContext: SignerContext,
|
|
167
|
-
limit = 10,
|
|
168
|
-
): Observable<AccountDescriptor> {
|
|
169
|
-
const derivateAddress = (opts: GetAddressOptions) =>
|
|
170
|
-
from(getAddress(signerContext)(deviceId, opts));
|
|
171
|
-
|
|
172
|
-
function stepAddress({
|
|
173
|
-
index,
|
|
174
|
-
accountDerivation,
|
|
175
|
-
parentDerivation,
|
|
176
|
-
derivationMode,
|
|
177
|
-
}: StepAddressInput) {
|
|
178
|
-
const result = inferDescriptorFromDeviceInfo({
|
|
179
|
-
derivationMode,
|
|
180
|
-
currency,
|
|
181
|
-
index,
|
|
182
|
-
parentDerivation,
|
|
183
|
-
accountDerivation,
|
|
184
|
-
});
|
|
185
|
-
return !result
|
|
186
|
-
? EMPTY
|
|
187
|
-
: of({
|
|
188
|
-
result,
|
|
189
|
-
complete: index >= limit,
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
return from(getDerivationModesForCurrency(currency)).pipe(
|
|
194
|
-
concatMap(derivationMode =>
|
|
195
|
-
walletDerivation({
|
|
196
|
-
currency,
|
|
197
|
-
derivationMode,
|
|
198
|
-
derivateAddress,
|
|
199
|
-
stepAddress,
|
|
200
|
-
shouldDerivesOnAccount: true,
|
|
201
|
-
}),
|
|
202
|
-
),
|
|
203
|
-
);
|
|
204
|
-
}
|
package/src/mockBtcSigner.ts
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import hash from "object-hash";
|
|
2
|
-
import type {
|
|
3
|
-
AddressFormat,
|
|
4
|
-
BitcoinSignature,
|
|
5
|
-
BitcoinSigner,
|
|
6
|
-
BitcoinXPub,
|
|
7
|
-
CreateTransaction,
|
|
8
|
-
SignerTransaction,
|
|
9
|
-
} from "./signer";
|
|
10
|
-
|
|
11
|
-
class MockBtcSigner implements BitcoinSigner {
|
|
12
|
-
// eslint-disable-next-line class-methods-use-this
|
|
13
|
-
async getWalletPublicKey(
|
|
14
|
-
path: string,
|
|
15
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
16
|
-
_opts: { verify?: boolean; format?: AddressFormat },
|
|
17
|
-
) {
|
|
18
|
-
switch (path) {
|
|
19
|
-
case "44'/0'":
|
|
20
|
-
return {
|
|
21
|
-
publicKey:
|
|
22
|
-
"04c621f37493d99f39ca12fb02ba7fe1687b1650b875dcb6733f386a98958e6556fc95dcecb6ac41af0a5296965751b1598aa475a537474bab5b316fcdc1196568",
|
|
23
|
-
chainCode: "a45d311c31a80bf06cc38d8ed7934bd1e8a7b2d48b2868a70258a86e094bacfb",
|
|
24
|
-
bitcoinAddress: "1BKWjmA9swxRKMH9NgXpSz8YZfVMnWWU9D",
|
|
25
|
-
};
|
|
26
|
-
break;
|
|
27
|
-
case "44'/0'/0'":
|
|
28
|
-
return {
|
|
29
|
-
publicKey:
|
|
30
|
-
"04d52d1ad9311c5a3d542fa652fbd7d7b0be70109e329d359704d9f2946f8eb52a829c23f8b980c5f7b6c51bf446b21f3dc80c865095243c9215dbf9f3cb6403b8",
|
|
31
|
-
chainCode: "0bd3e45edca4d8a466f523a2c4094c412d25c36d5298b2d3a29938151a8d37fe",
|
|
32
|
-
bitcoinAddress: "1FHa4cuKdea21ByTngP9vz3KYDqqQe9SsA",
|
|
33
|
-
};
|
|
34
|
-
break;
|
|
35
|
-
default:
|
|
36
|
-
throw new Error("not supported");
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
async createPaymentTransaction(arg: CreateTransaction) {
|
|
41
|
-
return hash(arg);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
getWalletXpub(_arg: { path: string; xpubVersion: number }): Promise<BitcoinXPub> {
|
|
45
|
-
return Promise.reject();
|
|
46
|
-
}
|
|
47
|
-
signMessage(_path: string, _messageHex: string): Promise<BitcoinSignature> {
|
|
48
|
-
return Promise.reject();
|
|
49
|
-
}
|
|
50
|
-
splitTransaction(
|
|
51
|
-
_transactionHex: string,
|
|
52
|
-
_isSegwitSupported: boolean | null | undefined,
|
|
53
|
-
_hasExtraData: boolean | null | undefined,
|
|
54
|
-
_additionals: Array<string> | null | undefined,
|
|
55
|
-
): SignerTransaction {
|
|
56
|
-
// Stub
|
|
57
|
-
return {
|
|
58
|
-
version: Buffer.from(""),
|
|
59
|
-
inputs: [],
|
|
60
|
-
outputs: [],
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export default MockBtcSigner;
|