@leather.io/bitcoin 0.14.2 → 0.16.0
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 +6 -6
- package/CHANGELOG.md +27 -0
- package/dist/index.d.ts +22 -4
- package/dist/index.js +129 -52
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
- package/src/bitcoin-signer.ts +2 -2
- package/src/bitcoin.utils.spec.ts +80 -0
- package/src/bitcoin.utils.ts +44 -2
- package/src/index.ts +1 -0
- package/src/lookup-derivation-by-address.spec.ts +71 -0
- package/src/lookup-derivation-by-address.ts +77 -0
- package/src/p2wpkh-address-gen.ts +4 -2
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @leather.io/bitcoin@0.
|
|
2
|
+
> @leather.io/bitcoin@0.16.0 build /home/runner/work/mono/mono/packages/bitcoin
|
|
3
3
|
> tsup
|
|
4
4
|
|
|
5
5
|
CLI Building entry: src/index.ts
|
|
@@ -8,9 +8,9 @@ CLI tsup v8.1.0
|
|
|
8
8
|
CLI Using tsup config: /home/runner/work/mono/mono/packages/bitcoin/tsup.config.ts
|
|
9
9
|
CLI Target: es2022
|
|
10
10
|
ESM Build start
|
|
11
|
-
ESM dist/index.js
|
|
12
|
-
ESM dist/index.js.map
|
|
13
|
-
ESM ⚡️ Build success in
|
|
11
|
+
ESM dist/index.js 25.37 KB
|
|
12
|
+
ESM dist/index.js.map 49.31 KB
|
|
13
|
+
ESM ⚡️ Build success in 39ms
|
|
14
14
|
DTS Build start
|
|
15
|
-
DTS ⚡️ Build success in
|
|
16
|
-
DTS dist/index.d.ts
|
|
15
|
+
DTS ⚡️ Build success in 4106ms
|
|
16
|
+
DTS dist/index.d.ts 16.04 KB
|
package/CHANGELOG.md
CHANGED
|
@@ -248,6 +248,33 @@
|
|
|
248
248
|
* devDependencies
|
|
249
249
|
* @leather.io/rpc bumped to 2.1.13
|
|
250
250
|
|
|
251
|
+
## [0.16.0](https://github.com/leather-io/mono/compare/@leather.io/bitcoin-v0.15.0...@leather.io/bitcoin-v0.16.0) (2024-11-05)
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
### Features
|
|
255
|
+
|
|
256
|
+
* upgrade stacks/transactions to v6.17 for non-seq multisig support ([4433cb2](https://github.com/leather-io/mono/commit/4433cb2ced8e00999fedfcdd00120f1e240800de))
|
|
257
|
+
|
|
258
|
+
## [0.15.0](https://github.com/leather-io/mono/compare/@leather.io/bitcoin-v0.14.2...@leather.io/bitcoin-v0.15.0) (2024-10-30)
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
### Features
|
|
262
|
+
|
|
263
|
+
* **bitcoin:** recursive address look up helper ([7f3d11c](https://github.com/leather-io/mono/commit/7f3d11c9e62c11492b9a88b18b7011d9cd6b4a98))
|
|
264
|
+
* integrate bitcoin balances ([0023ac5](https://github.com/leather-io/mono/commit/0023ac5bfd81fb721dc8fb3603194929db8a814c))
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
### Dependencies
|
|
268
|
+
|
|
269
|
+
* The following workspace dependencies were updated
|
|
270
|
+
* dependencies
|
|
271
|
+
* @leather.io/constants bumped to 0.13.0
|
|
272
|
+
* @leather.io/crypto bumped to 1.6.7
|
|
273
|
+
* @leather.io/models bumped to 0.18.3
|
|
274
|
+
* @leather.io/utils bumped to 0.16.7
|
|
275
|
+
* devDependencies
|
|
276
|
+
* @leather.io/rpc bumped to 2.1.14
|
|
277
|
+
|
|
251
278
|
## [0.14.0](https://github.com/leather-io/mono/compare/@leather.io/bitcoin-v0.13.3...@leather.io/bitcoin-v0.14.0) (2024-10-17)
|
|
252
279
|
|
|
253
280
|
|
package/dist/index.d.ts
CHANGED
|
@@ -114,12 +114,13 @@ declare function getInputPaymentType(input: TransactionInput, network: BitcoinNe
|
|
|
114
114
|
declare function lookUpLedgerKeysByPath(getDerivationPath: (network: BitcoinNetworkModes, accountIndex: number) => string): (ledgerKeyMap: Record<string, {
|
|
115
115
|
policy: string;
|
|
116
116
|
} | undefined>, network: BitcoinNetworkModes) => (accountIndex: number) => BitcoinAccount | undefined;
|
|
117
|
-
interface
|
|
117
|
+
interface GetAddressArgs {
|
|
118
118
|
index: number;
|
|
119
119
|
keychain?: HDKey;
|
|
120
120
|
network: BitcoinNetworkModes;
|
|
121
121
|
}
|
|
122
|
-
declare function getTaprootAddress({ index, keychain, network }:
|
|
122
|
+
declare function getTaprootAddress({ index, keychain, network }: GetAddressArgs): string;
|
|
123
|
+
declare function getNativeSegwitAddress({ index, keychain, network }: GetAddressArgs): string;
|
|
123
124
|
/**
|
|
124
125
|
* @deprecated
|
|
125
126
|
* Use `deriveRootBip32Keychain` in `@leather.io/crypto` instead
|
|
@@ -127,6 +128,8 @@ declare function getTaprootAddress({ index, keychain, network }: GetTaprootAddre
|
|
|
127
128
|
declare function mnemonicToRootNode(secretKey: string): HDKey;
|
|
128
129
|
declare function getPsbtTxInputs(psbtTx: btc.Transaction): TransactionInput[];
|
|
129
130
|
declare function getPsbtTxOutputs(psbtTx: btc.Transaction): TransactionOutput[];
|
|
131
|
+
declare function inferNetworkFromAddress(address: string): BitcoinNetworkModes;
|
|
132
|
+
declare function inferPaymentTypeFromAddress(address: string): SupportedPaymentType;
|
|
130
133
|
|
|
131
134
|
type AllowedSighashTypes = SignatureHash | SigHash;
|
|
132
135
|
interface BitcoinAccountKeychain {
|
|
@@ -257,7 +260,7 @@ declare function makeNativeSegwitAddressIndexDerivationPath(network: BitcoinNetw
|
|
|
257
260
|
/** @deprecated Use makeNativeSegwitAddressIndexDerivationPath */
|
|
258
261
|
declare const getNativeSegwitAddressIndexDerivationPath: typeof makeNativeSegwitAddressIndexDerivationPath;
|
|
259
262
|
declare function deriveNativeSegwitAccountFromRootKeychain(keychain: HDKey, network: BitcoinNetworkModes): (accountIndex: number) => BitcoinAccount;
|
|
260
|
-
declare function
|
|
263
|
+
declare function getNativeSegwitPaymentFromAddressIndex(keychain: HDKey, network: BitcoinNetworkModes): _scure_btc_signer_payment.P2Ret;
|
|
261
264
|
interface DeriveNativeSegwitReceiveAddressIndexArgs {
|
|
262
265
|
keychain: HDKey;
|
|
263
266
|
network: BitcoinNetworkModes;
|
|
@@ -284,4 +287,19 @@ declare function makePayToScriptHashAddressBytes(keyHash: Uint8Array): Uint8Arra
|
|
|
284
287
|
declare function makePayToScriptHashAddress(addressBytes: Uint8Array, network: NetworkModes): string;
|
|
285
288
|
declare function publicKeyToPayToScriptHashAddress(publicKey: Uint8Array, network: NetworkModes): string;
|
|
286
289
|
|
|
287
|
-
|
|
290
|
+
interface LookUpDerivationByAddressArgs {
|
|
291
|
+
taprootXpub: string;
|
|
292
|
+
nativeSegwitXpub: string;
|
|
293
|
+
iterationLimit: number;
|
|
294
|
+
}
|
|
295
|
+
declare function lookupDerivationByAddress(args: LookUpDerivationByAddressArgs): (address: string) => {
|
|
296
|
+
readonly status: "success";
|
|
297
|
+
readonly duration: number;
|
|
298
|
+
readonly path: string;
|
|
299
|
+
} | {
|
|
300
|
+
readonly status: "failure";
|
|
301
|
+
readonly duration?: undefined;
|
|
302
|
+
readonly path?: undefined;
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
export { type AllowedSighashTypes, type BitcoinAccount, type BitcoinAccountKeychain, type BitcoinNativeSegwitPayer, type BitcoinPayer, type BitcoinPayerBase, type BitcoinPayerInfo, type BitcoinSigner, type BitcoinTaprootPayer, type BtcSignerDefaultBip32Derivation, type BtcSignerLibPaymentTypeIdentifers, type BtcSignerNetwork, type BtcSignerTapBip32Derivation, type PaymentTypeMap, type SupportedPaymentType, type SupportedPaymentTypeMap, type WithDerivePayer, bip322TransactionToSignValues, bitcoinNetworkModeToCoreNetworkMode, bitcoinNetworkToCoreNetworkMap, btcSignerLibPaymentTypeToPaymentTypeMap, coinTypeMap, createNativeSegwitBitcoinJsSigner, createTaprootBitcoinJsSigner, createToSpendTx, createWalletIdDecoratedPath, decodeBitcoinTx, decodeCompressedWifPrivateKey, deriveAddressIndexKeychainFromAccount, deriveAddressIndexZeroFromAccount, deriveBitcoinPayerFromAccount, deriveBtcBip49SeedFromMnemonic, deriveNativeSegwitAccountFromRootKeychain, deriveNativeSegwitReceiveAddressIndexZero, deriveRootBtcKeychain, deriveTaprootAccount, deriveTaprootReceiveAddressIndexZero, ecPairFromPrivateKey, ecdsaPublicKeyLength, ecdsaPublicKeyToSchnorr, encodeMessageWitnessData, extractExtendedPublicKeyFromPolicy, extractRequiredKeyOrigins, getAddressFromOutScript, getBitcoinCoinTypeIndexByNetwork, getBitcoinInputAddress, getBitcoinJsLibNetworkConfigByMode, getBtcSignerLibNetworkConfigByMode, getHdKeyVersionsFromNetwork, getInputPaymentType, getNativeSegwitAccountDerivationPath, getNativeSegwitAddress, getNativeSegwitAddressIndexDerivationPath, getNativeSegwitPaymentFromAddressIndex, getPsbtTxInputs, getPsbtTxOutputs, getTaprootAccountDerivationPath, getTaprootAddress, getTaprootAddressIndexDerivationPath, getTaprootPayment, getTaprootPaymentFromAddressIndex, hashBip322Message, inferNetworkFromAddress, inferNetworkFromPath, inferPaymentTypeFromAddress, inferPaymentTypeFromPath, initBitcoinAccount, initializeBitcoinAccountKeychainFromDescriptor, isBtcSignerLibPaymentType, isSupportedMessageSigningPaymentType, lookUpLedgerKeysByPath, lookupDerivationByAddress, makeNativeSegwitAccountDerivationPath, makeNativeSegwitAddressIndexDerivationPath, makePayToScriptHashAddress, makePayToScriptHashAddressBytes, makePayToScriptHashKeyHash, makeTaprootAccountDerivationPath, makeTaprootAddressIndexDerivationPath, mnemonicToRootNode, parseKnownPaymentType, payToScriptHashTestnetPrefix, payerToBip32Derivation, payerToTapBip32Derivation, paymentTypeMap, publicKeyToPayToScriptHashAddress, serializeKeyOrigin, signBip322MessageSimple, toXOnly, tweakSigner, whenBitcoinNetwork, whenPaymentType, whenSupportedPaymentType };
|
package/dist/index.js
CHANGED
|
@@ -11,9 +11,9 @@ import { isString } from "@leather.io/utils";
|
|
|
11
11
|
import { hexToBytes } from "@noble/hashes/utils";
|
|
12
12
|
import { HDKey } from "@scure/bip32";
|
|
13
13
|
import { mnemonicToSeedSync } from "@scure/bip39";
|
|
14
|
-
import * as
|
|
14
|
+
import * as btc3 from "@scure/btc-signer";
|
|
15
15
|
import {
|
|
16
|
-
DerivationPathDepth as
|
|
16
|
+
DerivationPathDepth as DerivationPathDepth3,
|
|
17
17
|
extractAccountIndexFromPath,
|
|
18
18
|
extractPurposeFromPath
|
|
19
19
|
} from "@leather.io/crypto";
|
|
@@ -106,6 +106,44 @@ function deriveTaprootReceiveAddressIndexZero({
|
|
|
106
106
|
};
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
+
// src/p2wpkh-address-gen.ts
|
|
110
|
+
import * as btc2 from "@scure/btc-signer";
|
|
111
|
+
import { DerivationPathDepth as DerivationPathDepth2 } from "@leather.io/crypto";
|
|
112
|
+
function makeNativeSegwitAccountDerivationPath(network, accountIndex) {
|
|
113
|
+
return `m/84'/${getBitcoinCoinTypeIndexByNetwork(network)}'/${accountIndex}'`;
|
|
114
|
+
}
|
|
115
|
+
var getNativeSegwitAccountDerivationPath = makeNativeSegwitAccountDerivationPath;
|
|
116
|
+
function makeNativeSegwitAddressIndexDerivationPath(network, accountIndex, addressIndex) {
|
|
117
|
+
return makeNativeSegwitAccountDerivationPath(network, accountIndex) + `/0/${addressIndex}`;
|
|
118
|
+
}
|
|
119
|
+
var getNativeSegwitAddressIndexDerivationPath = makeNativeSegwitAddressIndexDerivationPath;
|
|
120
|
+
function deriveNativeSegwitAccountFromRootKeychain(keychain, network) {
|
|
121
|
+
if (keychain.depth !== DerivationPathDepth2.Root) throw new Error("Keychain passed is not a root");
|
|
122
|
+
return (accountIndex) => ({
|
|
123
|
+
type: "p2wpkh",
|
|
124
|
+
network,
|
|
125
|
+
accountIndex,
|
|
126
|
+
derivationPath: makeNativeSegwitAccountDerivationPath(network, accountIndex),
|
|
127
|
+
keychain: keychain.derive(makeNativeSegwitAccountDerivationPath(network, accountIndex))
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
function getNativeSegwitPaymentFromAddressIndex(keychain, network) {
|
|
131
|
+
if (keychain.depth !== DerivationPathDepth2.AddressIndex)
|
|
132
|
+
throw new Error("Keychain passed is not an address index");
|
|
133
|
+
if (!keychain.publicKey) throw new Error("Keychain does not have a public key");
|
|
134
|
+
return btc2.p2wpkh(keychain.publicKey, getBtcSignerLibNetworkConfigByMode(network));
|
|
135
|
+
}
|
|
136
|
+
function deriveNativeSegwitReceiveAddressIndexZero({
|
|
137
|
+
keychain,
|
|
138
|
+
network
|
|
139
|
+
}) {
|
|
140
|
+
const zeroAddressIndex = deriveAddressIndexZeroFromAccount(keychain);
|
|
141
|
+
return {
|
|
142
|
+
keychain: zeroAddressIndex,
|
|
143
|
+
payment: getNativeSegwitPaymentFromAddressIndex(zeroAddressIndex, network)
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
109
147
|
// src/bitcoin.utils.ts
|
|
110
148
|
function initBitcoinAccount(derivationPath, policy) {
|
|
111
149
|
const xpub = extractExtendedPublicKeyFromPolicy(policy);
|
|
@@ -138,7 +176,7 @@ function getBitcoinCoinTypeIndexByNetwork(network) {
|
|
|
138
176
|
return coinTypeMap[bitcoinNetworkModeToCoreNetworkMode(network)];
|
|
139
177
|
}
|
|
140
178
|
function deriveAddressIndexKeychainFromAccount(keychain) {
|
|
141
|
-
if (keychain.depth !==
|
|
179
|
+
if (keychain.depth !== DerivationPathDepth3.Account)
|
|
142
180
|
throw new Error("Keychain passed is not an account");
|
|
143
181
|
return (index) => keychain.deriveChild(0).deriveChild(index);
|
|
144
182
|
}
|
|
@@ -152,28 +190,28 @@ function ecdsaPublicKeyToSchnorr(pubKey) {
|
|
|
152
190
|
}
|
|
153
191
|
var toXOnly = (pubKey) => pubKey.length === 32 ? pubKey : pubKey.subarray(1, 33);
|
|
154
192
|
function decodeBitcoinTx(tx) {
|
|
155
|
-
return
|
|
193
|
+
return btc3.RawTx.decode(hexToBytes(tx));
|
|
156
194
|
}
|
|
157
195
|
function getAddressFromOutScript(script2, bitcoinNetwork) {
|
|
158
|
-
const outputScript =
|
|
196
|
+
const outputScript = btc3.OutScript.decode(script2);
|
|
159
197
|
switch (outputScript.type) {
|
|
160
198
|
case "pkh":
|
|
161
199
|
case "sh":
|
|
162
200
|
case "wpkh":
|
|
163
201
|
case "wsh":
|
|
164
|
-
return
|
|
202
|
+
return btc3.Address(bitcoinNetwork).encode({
|
|
165
203
|
type: outputScript.type,
|
|
166
204
|
hash: outputScript.hash
|
|
167
205
|
});
|
|
168
206
|
case "tr":
|
|
169
|
-
return
|
|
207
|
+
return btc3.Address(bitcoinNetwork).encode({
|
|
170
208
|
type: outputScript.type,
|
|
171
209
|
pubkey: outputScript.pubkey
|
|
172
210
|
});
|
|
173
211
|
case "ms":
|
|
174
|
-
return
|
|
212
|
+
return btc3.p2ms(outputScript.m, outputScript.pubkeys).address ?? "";
|
|
175
213
|
case "pk":
|
|
176
|
-
return
|
|
214
|
+
return btc3.p2pk(outputScript.pubkey, bitcoinNetwork).address ?? "";
|
|
177
215
|
case "unknown":
|
|
178
216
|
return "unknown";
|
|
179
217
|
case "tr_ms":
|
|
@@ -264,7 +302,7 @@ function lookUpLedgerKeysByPath(getDerivationPath) {
|
|
|
264
302
|
}
|
|
265
303
|
function getTaprootAddress({ index, keychain, network }) {
|
|
266
304
|
if (!keychain) throw new Error("Expected keychain to be provided");
|
|
267
|
-
if (keychain.depth !==
|
|
305
|
+
if (keychain.depth !== DerivationPathDepth3.Account)
|
|
268
306
|
throw new Error("Expects keychain to be on the account index");
|
|
269
307
|
const addressIndex = deriveAddressIndexKeychainFromAccount(keychain)(index);
|
|
270
308
|
if (!addressIndex.publicKey) throw new Error("Expected publicKey to be defined");
|
|
@@ -272,6 +310,16 @@ function getTaprootAddress({ index, keychain, network }) {
|
|
|
272
310
|
if (!payment.address) throw new Error("Expected address to be defined");
|
|
273
311
|
return payment.address;
|
|
274
312
|
}
|
|
313
|
+
function getNativeSegwitAddress({ index, keychain, network }) {
|
|
314
|
+
if (!keychain) throw new Error("Expected keychain to be provided");
|
|
315
|
+
if (keychain.depth !== DerivationPathDepth3.Account)
|
|
316
|
+
throw new Error("Expects keychain to be on the account index");
|
|
317
|
+
const addressIndex = deriveAddressIndexKeychainFromAccount(keychain)(index);
|
|
318
|
+
if (!addressIndex.publicKey) throw new Error("Expected publicKey to be defined");
|
|
319
|
+
const payment = getNativeSegwitPaymentFromAddressIndex(addressIndex, network);
|
|
320
|
+
if (!payment.address) throw new Error("Expected address to be defined");
|
|
321
|
+
return payment.address;
|
|
322
|
+
}
|
|
275
323
|
function mnemonicToRootNode(secretKey) {
|
|
276
324
|
const seed = mnemonicToSeedSync(secretKey);
|
|
277
325
|
return HDKey.fromMasterSeed(seed);
|
|
@@ -288,6 +336,23 @@ function getPsbtTxOutputs(psbtTx) {
|
|
|
288
336
|
for (let i = 0; i < outputsLength; i++) outputs.push(psbtTx.getOutput(i));
|
|
289
337
|
return outputs;
|
|
290
338
|
}
|
|
339
|
+
function inferNetworkFromAddress(address2) {
|
|
340
|
+
if (address2.startsWith("bc1")) return "mainnet";
|
|
341
|
+
if (address2.startsWith("tb1")) return "testnet";
|
|
342
|
+
if (address2.startsWith("bcrt1")) return "regtest";
|
|
343
|
+
const firstChar = address2[0];
|
|
344
|
+
if (firstChar === "1" || firstChar === "3") return "mainnet";
|
|
345
|
+
if (firstChar === "m" || firstChar === "n") return "testnet";
|
|
346
|
+
if (firstChar === "2") return "testnet";
|
|
347
|
+
throw new Error("Invalid or unsupported Bitcoin address format");
|
|
348
|
+
}
|
|
349
|
+
function inferPaymentTypeFromAddress(address2) {
|
|
350
|
+
if (address2.startsWith("bc1q") || address2.startsWith("tb1q") || address2.startsWith("bcrt1q"))
|
|
351
|
+
return "p2wpkh";
|
|
352
|
+
if (address2.startsWith("bc1p") || address2.startsWith("tb1p") || address2.startsWith("bcrt1p"))
|
|
353
|
+
return "p2tr";
|
|
354
|
+
throw new Error("Unable to infer payment type from address");
|
|
355
|
+
}
|
|
291
356
|
|
|
292
357
|
// src/bip322/bip322-utils.ts
|
|
293
358
|
var bip322MessageTag = "BIP0322-signed-message";
|
|
@@ -411,46 +476,6 @@ import {
|
|
|
411
476
|
keyOriginToDerivationPath
|
|
412
477
|
} from "@leather.io/crypto";
|
|
413
478
|
import { hexToNumber, toHexString } from "@leather.io/utils";
|
|
414
|
-
|
|
415
|
-
// src/p2wpkh-address-gen.ts
|
|
416
|
-
import * as btc3 from "@scure/btc-signer";
|
|
417
|
-
import { DerivationPathDepth as DerivationPathDepth3 } from "@leather.io/crypto";
|
|
418
|
-
function makeNativeSegwitAccountDerivationPath(network, accountIndex) {
|
|
419
|
-
return `m/84'/${getBitcoinCoinTypeIndexByNetwork(network)}'/${accountIndex}'`;
|
|
420
|
-
}
|
|
421
|
-
var getNativeSegwitAccountDerivationPath = makeNativeSegwitAccountDerivationPath;
|
|
422
|
-
function makeNativeSegwitAddressIndexDerivationPath(network, accountIndex, addressIndex) {
|
|
423
|
-
return makeNativeSegwitAccountDerivationPath(network, accountIndex) + `/0/${addressIndex}`;
|
|
424
|
-
}
|
|
425
|
-
var getNativeSegwitAddressIndexDerivationPath = makeNativeSegwitAddressIndexDerivationPath;
|
|
426
|
-
function deriveNativeSegwitAccountFromRootKeychain(keychain, network) {
|
|
427
|
-
if (keychain.depth !== DerivationPathDepth3.Root) throw new Error("Keychain passed is not a root");
|
|
428
|
-
return (accountIndex) => ({
|
|
429
|
-
type: "p2wpkh",
|
|
430
|
-
network,
|
|
431
|
-
accountIndex,
|
|
432
|
-
derivationPath: makeNativeSegwitAccountDerivationPath(network, accountIndex),
|
|
433
|
-
keychain: keychain.derive(makeNativeSegwitAccountDerivationPath(network, accountIndex))
|
|
434
|
-
});
|
|
435
|
-
}
|
|
436
|
-
function getNativeSegWitPaymentFromAddressIndex(keychain, network) {
|
|
437
|
-
if (keychain.depth !== DerivationPathDepth3.AddressIndex)
|
|
438
|
-
throw new Error("Keychain passed is not an address index");
|
|
439
|
-
if (!keychain.publicKey) throw new Error("Keychain does not have a public key");
|
|
440
|
-
return btc3.p2wpkh(keychain.publicKey, getBtcSignerLibNetworkConfigByMode(network));
|
|
441
|
-
}
|
|
442
|
-
function deriveNativeSegwitReceiveAddressIndexZero({
|
|
443
|
-
keychain,
|
|
444
|
-
network
|
|
445
|
-
}) {
|
|
446
|
-
const zeroAddressIndex = deriveAddressIndexZeroFromAccount(keychain);
|
|
447
|
-
return {
|
|
448
|
-
keychain: zeroAddressIndex,
|
|
449
|
-
payment: getNativeSegWitPaymentFromAddressIndex(zeroAddressIndex, network)
|
|
450
|
-
};
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
// src/bitcoin-signer.ts
|
|
454
479
|
function initializeBitcoinAccountKeychainFromDescriptor(descriptor) {
|
|
455
480
|
const { fingerprint, keyOrigin } = decomposeDescriptor(descriptor);
|
|
456
481
|
return {
|
|
@@ -471,7 +496,7 @@ function deriveBitcoinPayerFromAccount(descriptor, network) {
|
|
|
471
496
|
const childKeychain = accountKeychain.deriveChild(receive).deriveChild(addressIndex);
|
|
472
497
|
const derivePayerFromAccount = whenSupportedPaymentType(paymentType)({
|
|
473
498
|
p2tr: getTaprootPaymentFromAddressIndex,
|
|
474
|
-
p2wpkh:
|
|
499
|
+
p2wpkh: getNativeSegwitPaymentFromAddressIndex
|
|
475
500
|
});
|
|
476
501
|
const payment = derivePayerFromAccount(childKeychain, network);
|
|
477
502
|
return {
|
|
@@ -565,6 +590,54 @@ function publicKeyToPayToScriptHashAddress(publicKey, network) {
|
|
|
565
590
|
const addrBytes = makePayToScriptHashAddressBytes(hash);
|
|
566
591
|
return makePayToScriptHashAddress(addrBytes, network);
|
|
567
592
|
}
|
|
593
|
+
|
|
594
|
+
// src/lookup-derivation-by-address.ts
|
|
595
|
+
import { HARDENED_OFFSET as HARDENED_OFFSET2, HDKey as HDKey3 } from "@scure/bip32";
|
|
596
|
+
import { createCounter } from "@leather.io/utils";
|
|
597
|
+
function lookupDerivationByAddress(args) {
|
|
598
|
+
const { taprootXpub, nativeSegwitXpub, iterationLimit } = args;
|
|
599
|
+
const taprootKeychain = HDKey3.fromExtendedKey(taprootXpub);
|
|
600
|
+
const nativeSegwitKeychain = HDKey3.fromExtendedKey(nativeSegwitXpub);
|
|
601
|
+
return (address2) => {
|
|
602
|
+
const network = inferNetworkFromAddress(address2);
|
|
603
|
+
const paymentType = inferPaymentTypeFromAddress(address2);
|
|
604
|
+
const accountIndex = whenSupportedPaymentType(paymentType)({
|
|
605
|
+
p2tr: taprootKeychain.index - HARDENED_OFFSET2,
|
|
606
|
+
p2wpkh: nativeSegwitKeychain.index - HARDENED_OFFSET2
|
|
607
|
+
});
|
|
608
|
+
function getTaprootAddressAtIndex(index) {
|
|
609
|
+
return getTaprootAddress({ index, keychain: taprootKeychain, network });
|
|
610
|
+
}
|
|
611
|
+
function getNativeSegwitAddressAtIndex(index) {
|
|
612
|
+
return getNativeSegwitAddress({ index, keychain: nativeSegwitKeychain, network });
|
|
613
|
+
}
|
|
614
|
+
const paymentFn = whenSupportedPaymentType(paymentType)({
|
|
615
|
+
p2tr: getTaprootAddressAtIndex,
|
|
616
|
+
p2wpkh: getNativeSegwitAddressAtIndex
|
|
617
|
+
});
|
|
618
|
+
const derivationPathFn = whenSupportedPaymentType(paymentType)({
|
|
619
|
+
p2tr: makeTaprootAddressIndexDerivationPath,
|
|
620
|
+
p2wpkh: makeNativeSegwitAddressIndexDerivationPath
|
|
621
|
+
});
|
|
622
|
+
const count = createCounter();
|
|
623
|
+
const t0 = performance.now();
|
|
624
|
+
while (count.getValue() <= iterationLimit) {
|
|
625
|
+
const currentIndex = count.getValue();
|
|
626
|
+
const addressToCheck = paymentFn(currentIndex);
|
|
627
|
+
if (addressToCheck !== address2) {
|
|
628
|
+
count.increment();
|
|
629
|
+
continue;
|
|
630
|
+
}
|
|
631
|
+
const t1 = performance.now();
|
|
632
|
+
return {
|
|
633
|
+
status: "success",
|
|
634
|
+
duration: t1 - t0,
|
|
635
|
+
path: derivationPathFn(network, accountIndex, currentIndex)
|
|
636
|
+
};
|
|
637
|
+
}
|
|
638
|
+
return { status: "failure" };
|
|
639
|
+
};
|
|
640
|
+
}
|
|
568
641
|
export {
|
|
569
642
|
bip322TransactionToSignValues,
|
|
570
643
|
bitcoinNetworkModeToCoreNetworkMode,
|
|
@@ -599,9 +672,10 @@ export {
|
|
|
599
672
|
getBtcSignerLibNetworkConfigByMode,
|
|
600
673
|
getHdKeyVersionsFromNetwork,
|
|
601
674
|
getInputPaymentType,
|
|
602
|
-
getNativeSegWitPaymentFromAddressIndex,
|
|
603
675
|
getNativeSegwitAccountDerivationPath,
|
|
676
|
+
getNativeSegwitAddress,
|
|
604
677
|
getNativeSegwitAddressIndexDerivationPath,
|
|
678
|
+
getNativeSegwitPaymentFromAddressIndex,
|
|
605
679
|
getPsbtTxInputs,
|
|
606
680
|
getPsbtTxOutputs,
|
|
607
681
|
getTaprootAccountDerivationPath,
|
|
@@ -610,13 +684,16 @@ export {
|
|
|
610
684
|
getTaprootPayment,
|
|
611
685
|
getTaprootPaymentFromAddressIndex,
|
|
612
686
|
hashBip322Message,
|
|
687
|
+
inferNetworkFromAddress,
|
|
613
688
|
inferNetworkFromPath,
|
|
689
|
+
inferPaymentTypeFromAddress,
|
|
614
690
|
inferPaymentTypeFromPath,
|
|
615
691
|
initBitcoinAccount,
|
|
616
692
|
initializeBitcoinAccountKeychainFromDescriptor,
|
|
617
693
|
isBtcSignerLibPaymentType,
|
|
618
694
|
isSupportedMessageSigningPaymentType,
|
|
619
695
|
lookUpLedgerKeysByPath,
|
|
696
|
+
lookupDerivationByAddress,
|
|
620
697
|
makeNativeSegwitAccountDerivationPath,
|
|
621
698
|
makeNativeSegwitAddressIndexDerivationPath,
|
|
622
699
|
makePayToScriptHashAddress,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/bip322/bip322-utils.ts","../src/bitcoin.utils.ts","../src/bitcoin.network.ts","../src/p2tr-address-gen.ts","../src/bip322/sign-message-bip322-bitcoinjs.ts","../src/bitcoin-signer.ts","../src/p2wpkh-address-gen.ts","../src/p2wsh-p2sh-address-gen.ts"],"sourcesContent":["import ecc from '@bitcoinerlab/secp256k1';\nimport { sha256 } from '@noble/hashes/sha256';\nimport { hexToBytes, utf8ToBytes } from '@stacks/common';\nimport * as bitcoin from 'bitcoinjs-lib';\nimport { ECPairFactory } from 'ecpair';\nimport { encode } from 'varuint-bitcoin';\n\nimport { PaymentTypes } from '@leather.io/rpc';\nimport { isString } from '@leather.io/utils';\n\nimport { toXOnly } from '../bitcoin.utils';\n\nconst bip322MessageTag = 'BIP0322-signed-message';\n\nconst ECPair = ECPairFactory(ecc);\nbitcoin.initEccLib(ecc);\n\nexport function ecPairFromPrivateKey(key: Uint8Array) {\n return ECPair.fromPrivateKey(Buffer.from(key));\n}\n\n// See tagged hashes section of BIP-340\n// https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki#design\nconst messageTagHash = Uint8Array.from([\n ...sha256(utf8ToBytes(bip322MessageTag)),\n ...sha256(utf8ToBytes(bip322MessageTag)),\n]);\n\nexport function hashBip322Message(message: Uint8Array | string) {\n return sha256(\n Uint8Array.from([...messageTagHash, ...(isString(message) ? utf8ToBytes(message) : message)])\n );\n}\n\nexport const bip322TransactionToSignValues = {\n prevoutHash: hexToBytes('0000000000000000000000000000000000000000000000000000000000000000'),\n prevoutIndex: 0xffffffff,\n sequence: 0,\n};\n\nfunction encodeVarString(b: Buffer) {\n return Buffer.concat([encode(b.byteLength), b]);\n}\n\nconst supportedMessageSigningPaymentTypes: PaymentTypes[] = ['p2wpkh', 'p2tr'];\n\nexport function isSupportedMessageSigningPaymentType(paymentType: string) {\n return supportedMessageSigningPaymentTypes.includes(paymentType as PaymentTypes);\n}\n\n/**\n * Encode witness data for a BIP322 message\n * TODO: Refactor to remove `Buffer` use\n */\nexport function encodeMessageWitnessData(witnessArray: Buffer[]) {\n const len = encode(witnessArray.length);\n return Buffer.concat([len, ...witnessArray.map(witness => encodeVarString(witness))]);\n}\n\nfunction tapTweakHash(pubKey: Buffer, h: Buffer | undefined): Buffer {\n return bitcoin.crypto.taggedHash('TapTweak', Buffer.concat(h ? [pubKey, h] : [pubKey]));\n}\n\nexport function tweakSigner(signer: bitcoin.Signer, opts: any = {}): bitcoin.Signer {\n // @ts-expect-error privateKey exists on signer\n let privateKey: Uint8Array | undefined = signer.privateKey!;\n if (!privateKey) {\n throw new Error('Private key is required for tweaking signer!');\n }\n if (signer.publicKey[0] === 3) {\n privateKey = ecc.privateNegate(privateKey);\n }\n\n const tweakedPrivateKey = ecc.privateAdd(\n privateKey,\n tapTweakHash(toXOnly(signer.publicKey), opts.tweakHash)\n );\n if (!tweakedPrivateKey) {\n throw new Error('Invalid tweaked private key!');\n }\n\n return ECPair.fromPrivateKey(Buffer.from(tweakedPrivateKey), {\n network: opts.network,\n });\n}\n","import { hexToBytes } from '@noble/hashes/utils';\nimport { HDKey, Versions } from '@scure/bip32';\nimport { mnemonicToSeedSync } from '@scure/bip39';\nimport * as btc from '@scure/btc-signer';\nimport { TransactionInput, TransactionOutput } from '@scure/btc-signer/psbt';\n\nimport {\n DerivationPathDepth,\n extractAccountIndexFromPath,\n extractPurposeFromPath,\n} from '@leather.io/crypto';\nimport { BitcoinNetworkModes, NetworkModes } from '@leather.io/models';\nimport type { PaymentTypes } from '@leather.io/rpc';\nimport { defaultWalletKeyId, isDefined, whenNetwork } from '@leather.io/utils';\n\nimport { BtcSignerNetwork, getBtcSignerLibNetworkConfigByMode } from './bitcoin.network';\nimport { getTaprootPayment } from './p2tr-address-gen';\n\nexport interface BitcoinAccount {\n type: PaymentTypes;\n derivationPath: string;\n keychain: HDKey;\n accountIndex: number;\n network: BitcoinNetworkModes;\n}\nexport function initBitcoinAccount(derivationPath: string, policy: string): BitcoinAccount {\n const xpub = extractExtendedPublicKeyFromPolicy(policy);\n const network = inferNetworkFromPath(derivationPath);\n return {\n keychain: HDKey.fromExtendedKey(xpub, getHdKeyVersionsFromNetwork(network)),\n network,\n derivationPath,\n type: inferPaymentTypeFromPath(derivationPath),\n accountIndex: extractAccountIndexFromPath(derivationPath),\n };\n}\n\n/**\n * Represents a map of `BitcoinNetworkModes` to `NetworkModes`. While Bitcoin\n * has a number of networks, its often only necessary to consider the higher\n * level concept of mainnet and testnet\n */\nexport const bitcoinNetworkToCoreNetworkMap: Record<BitcoinNetworkModes, NetworkModes> = {\n mainnet: 'mainnet',\n testnet: 'testnet',\n regtest: 'testnet',\n signet: 'testnet',\n};\nexport function bitcoinNetworkModeToCoreNetworkMode(mode: BitcoinNetworkModes) {\n return bitcoinNetworkToCoreNetworkMap[mode];\n}\n\ntype BitcoinNetworkMap<T> = Record<BitcoinNetworkModes, T>;\n\nexport function whenBitcoinNetwork(mode: BitcoinNetworkModes) {\n return <T extends BitcoinNetworkMap<unknown>>(networkMap: T) =>\n networkMap[mode] as T[BitcoinNetworkModes];\n}\n\n/**\n * Map representing the \"Coin Type\" section of a derivation path.\n * Consider example below, Coin type is one, thus testnet\n * @example\n * `m/86'/1'/0'/0/0`\n */\nexport const coinTypeMap: Record<NetworkModes, 0 | 1> = {\n mainnet: 0,\n testnet: 1,\n};\n\nexport function getBitcoinCoinTypeIndexByNetwork(network: BitcoinNetworkModes) {\n return coinTypeMap[bitcoinNetworkModeToCoreNetworkMode(network)];\n}\n\nexport function deriveAddressIndexKeychainFromAccount(keychain: HDKey) {\n if (keychain.depth !== DerivationPathDepth.Account)\n throw new Error('Keychain passed is not an account');\n\n return (index: number) => keychain.deriveChild(0).deriveChild(index);\n}\n\nexport function deriveAddressIndexZeroFromAccount(keychain: HDKey) {\n return deriveAddressIndexKeychainFromAccount(keychain)(0);\n}\n\nexport const ecdsaPublicKeyLength = 33;\n\nexport function ecdsaPublicKeyToSchnorr(pubKey: Uint8Array) {\n if (pubKey.byteLength !== ecdsaPublicKeyLength) throw new Error('Invalid public key length');\n return pubKey.slice(1);\n}\n\n// Basically same as above, to remove\nexport const toXOnly = (pubKey: Buffer) => (pubKey.length === 32 ? pubKey : pubKey.subarray(1, 33));\n\nexport function decodeBitcoinTx(tx: string): ReturnType<typeof btc.RawTx.decode> {\n return btc.RawTx.decode(hexToBytes(tx));\n}\n\nexport function getAddressFromOutScript(script: Uint8Array, bitcoinNetwork: BtcSignerNetwork) {\n const outputScript = btc.OutScript.decode(script);\n\n switch (outputScript.type) {\n case 'pkh':\n case 'sh':\n case 'wpkh':\n case 'wsh':\n return btc.Address(bitcoinNetwork).encode({\n type: outputScript.type,\n hash: outputScript.hash,\n });\n case 'tr':\n return btc.Address(bitcoinNetwork).encode({\n type: outputScript.type,\n pubkey: outputScript.pubkey,\n });\n case 'ms':\n return btc.p2ms(outputScript.m, outputScript.pubkeys).address ?? '';\n case 'pk':\n return btc.p2pk(outputScript.pubkey, bitcoinNetwork).address ?? '';\n case 'unknown':\n return 'unknown';\n case 'tr_ms':\n case 'tr_ns':\n default:\n return '';\n }\n}\n\n/**\n * Payment type identifiers, as described by `@scure/btc-signer` library\n */\nexport type BtcSignerLibPaymentTypeIdentifers = 'wpkh' | 'wsh' | 'tr' | 'pkh' | 'sh';\n\nexport const paymentTypeMap: Record<BtcSignerLibPaymentTypeIdentifers, PaymentTypes> = {\n wpkh: 'p2wpkh',\n wsh: 'p2wpkh-p2sh',\n tr: 'p2tr',\n pkh: 'p2pkh',\n sh: 'p2sh',\n};\n\nexport function btcSignerLibPaymentTypeToPaymentTypeMap(\n payment: BtcSignerLibPaymentTypeIdentifers\n) {\n return paymentTypeMap[payment];\n}\n\nexport function isBtcSignerLibPaymentType(\n payment: string\n): payment is BtcSignerLibPaymentTypeIdentifers {\n return payment in paymentTypeMap;\n}\n\nexport function parseKnownPaymentType(payment: BtcSignerLibPaymentTypeIdentifers | PaymentTypes) {\n return isBtcSignerLibPaymentType(payment)\n ? btcSignerLibPaymentTypeToPaymentTypeMap(payment)\n : payment;\n}\n\nexport type PaymentTypeMap<T> = Record<PaymentTypes, T>;\nexport function whenPaymentType(mode: PaymentTypes | BtcSignerLibPaymentTypeIdentifers) {\n return <T extends unknown>(paymentMap: PaymentTypeMap<T>): T =>\n paymentMap[parseKnownPaymentType(mode)];\n}\n\nexport type SupportedPaymentType = 'p2wpkh' | 'p2tr';\nexport type SupportedPaymentTypeMap<T> = Record<SupportedPaymentType, T>;\nexport function whenSupportedPaymentType(mode: SupportedPaymentType) {\n return <T>(paymentMap: SupportedPaymentTypeMap<T>): T => paymentMap[mode];\n}\n\n/**\n * Infers the Bitcoin payment type from the derivation path.\n * Below we see path has 86 in it, per convention, this refers to taproot payments\n * @example\n * `m/86'/1'/0'/0/0`\n */\nexport function inferPaymentTypeFromPath(path: string): PaymentTypes {\n const purpose = extractPurposeFromPath(path);\n switch (purpose) {\n case 84:\n return 'p2wpkh';\n case 86:\n return 'p2tr';\n case 44:\n return 'p2pkh';\n default:\n throw new Error(`Unable to infer payment type from purpose=${purpose}`);\n }\n}\n\nexport function inferNetworkFromPath(path: string): NetworkModes {\n return path.split('/')[2].startsWith('0') ? 'mainnet' : 'testnet';\n}\n\nexport function extractExtendedPublicKeyFromPolicy(policy: string) {\n return policy.split(']')[1];\n}\n\nexport function createWalletIdDecoratedPath(policy: string, walletId: string) {\n return policy.split(']')[0].replace('[', '').replace('m', walletId);\n}\n\n// Primarily used to get the correct `Version` when passing Ledger Bitcoin\n// extended public keys to the HDKey constructor\nexport function getHdKeyVersionsFromNetwork(network: NetworkModes) {\n return whenNetwork(network)({\n mainnet: undefined,\n testnet: {\n private: 0x00000000,\n public: 0x043587cf,\n } as Versions,\n });\n}\n\nexport function getBitcoinInputAddress(input: TransactionInput, bitcoinNetwork: BtcSignerNetwork) {\n if (isDefined(input.witnessUtxo))\n return getAddressFromOutScript(input.witnessUtxo.script, bitcoinNetwork);\n if (isDefined(input.nonWitnessUtxo) && isDefined(input.index))\n return getAddressFromOutScript(\n input.nonWitnessUtxo.outputs[input.index]?.script,\n bitcoinNetwork\n );\n return '';\n}\n\nexport function getInputPaymentType(\n input: TransactionInput,\n network: BitcoinNetworkModes\n): PaymentTypes {\n const address = getBitcoinInputAddress(input, getBtcSignerLibNetworkConfigByMode(network));\n if (address === '') throw new Error('Input address cannot be empty');\n if (address.startsWith('bc1p') || address.startsWith('tb1p') || address.startsWith('bcrt1p'))\n return 'p2tr';\n if (address.startsWith('bc1q') || address.startsWith('tb1q') || address.startsWith('bcrt1q'))\n return 'p2wpkh';\n throw new Error('Unable to infer payment type from input address');\n}\n\n// Ledger wallets are keyed by their derivation path. To reuse the look up logic\n// between payment types, this factory fn accepts a fn that generates the path\nexport function lookUpLedgerKeysByPath(\n getDerivationPath: (network: BitcoinNetworkModes, accountIndex: number) => string\n) {\n return (\n ledgerKeyMap: Record<string, { policy: string } | undefined>,\n network: BitcoinNetworkModes\n ) =>\n (accountIndex: number) => {\n const path = getDerivationPath(network, accountIndex);\n // Single wallet mode, hardcoded default walletId\n const account = ledgerKeyMap[path.replace('m', defaultWalletKeyId)];\n if (!account) return;\n return initBitcoinAccount(path, account.policy);\n };\n}\n\nexport interface GetTaprootAddressArgs {\n index: number;\n keychain?: HDKey;\n network: BitcoinNetworkModes;\n}\nexport function getTaprootAddress({ index, keychain, network }: GetTaprootAddressArgs) {\n if (!keychain) throw new Error('Expected keychain to be provided');\n\n if (keychain.depth !== DerivationPathDepth.Account)\n throw new Error('Expects keychain to be on the account index');\n\n const addressIndex = deriveAddressIndexKeychainFromAccount(keychain)(index);\n\n if (!addressIndex.publicKey) throw new Error('Expected publicKey to be defined');\n\n const payment = getTaprootPayment(addressIndex.publicKey, network);\n\n if (!payment.address) throw new Error('Expected address to be defined');\n return payment.address;\n}\n\n/**\n * @deprecated\n * Use `deriveRootBip32Keychain` in `@leather.io/crypto` instead\n */\nexport function mnemonicToRootNode(secretKey: string) {\n const seed = mnemonicToSeedSync(secretKey);\n return HDKey.fromMasterSeed(seed);\n}\n\nexport function getPsbtTxInputs(psbtTx: btc.Transaction): TransactionInput[] {\n const inputsLength = psbtTx.inputsLength;\n const inputs: TransactionInput[] = [];\n for (let i = 0; i < inputsLength; i++) inputs.push(psbtTx.getInput(i));\n return inputs;\n}\n\nexport function getPsbtTxOutputs(psbtTx: btc.Transaction): TransactionOutput[] {\n const outputsLength = psbtTx.outputsLength;\n const outputs: TransactionOutput[] = [];\n for (let i = 0; i < outputsLength; i++) outputs.push(psbtTx.getOutput(i));\n return outputs;\n}\n","import * as bitcoinJs from 'bitcoinjs-lib';\n\nimport { BitcoinNetworkModes } from '@leather.io/models';\n\n// See this PR https://github.com/paulmillr/@scure/btc-signer/pull/15\n// Atttempting to add these directly to the library\nexport interface BtcSignerNetwork {\n bech32: string;\n pubKeyHash: number;\n scriptHash: number;\n wif: number;\n}\n\nconst bitcoinMainnet: BtcSignerNetwork = {\n bech32: 'bc',\n pubKeyHash: 0x00,\n scriptHash: 0x05,\n wif: 0x80,\n};\n\nconst bitcoinTestnet: BtcSignerNetwork = {\n bech32: 'tb',\n pubKeyHash: 0x6f,\n scriptHash: 0xc4,\n wif: 0xef,\n};\n\nconst bitcoinRegtest: BtcSignerNetwork = {\n bech32: 'bcrt',\n pubKeyHash: 0x6f,\n scriptHash: 0xc4,\n wif: 0xef,\n};\n\nconst btcSignerLibNetworks: Record<BitcoinNetworkModes, BtcSignerNetwork> = {\n mainnet: bitcoinMainnet,\n testnet: bitcoinTestnet,\n regtest: bitcoinRegtest,\n // Signet originally was going to have its own prefix but authors decided to\n // copy testnet\n signet: bitcoinTestnet,\n};\n\nexport function getBtcSignerLibNetworkConfigByMode(network: BitcoinNetworkModes) {\n return btcSignerLibNetworks[network];\n}\n\nconst bitcoinJsLibNetworks: Record<BitcoinNetworkModes, bitcoinJs.Network> = {\n mainnet: bitcoinJs.networks.bitcoin,\n testnet: bitcoinJs.networks.testnet,\n regtest: bitcoinJs.networks.regtest,\n signet: bitcoinJs.networks.testnet,\n};\n\nexport function getBitcoinJsLibNetworkConfigByMode(network: BitcoinNetworkModes) {\n return bitcoinJsLibNetworks[network];\n}\n","import { HDKey } from '@scure/bip32';\nimport * as btc from '@scure/btc-signer';\n\nimport { DerivationPathDepth } from '@leather.io/crypto';\nimport { BitcoinNetworkModes } from '@leather.io/models';\n\nimport { getBtcSignerLibNetworkConfigByMode } from './bitcoin.network';\nimport {\n BitcoinAccount,\n deriveAddressIndexZeroFromAccount,\n ecdsaPublicKeyToSchnorr,\n getBitcoinCoinTypeIndexByNetwork,\n} from './bitcoin.utils';\n\nexport function makeTaprootAccountDerivationPath(\n network: BitcoinNetworkModes,\n accountIndex: number\n) {\n return `m/86'/${getBitcoinCoinTypeIndexByNetwork(network)}'/${accountIndex}'`;\n}\n/** @deprecated Use makeTaprootAccountDerivationPath */\nexport const getTaprootAccountDerivationPath = makeTaprootAccountDerivationPath;\n\nexport function makeTaprootAddressIndexDerivationPath(\n network: BitcoinNetworkModes,\n accountIndex: number,\n addressIndex: number\n) {\n return makeTaprootAccountDerivationPath(network, accountIndex) + `/0/${addressIndex}`;\n}\n/** @deprecated Use makeTaprootAddressIndexDerivationPath */\nexport const getTaprootAddressIndexDerivationPath = makeTaprootAddressIndexDerivationPath;\n\nexport function deriveTaprootAccount(keychain: HDKey, network: BitcoinNetworkModes) {\n if (keychain.depth !== DerivationPathDepth.Root)\n throw new Error('Keychain passed is not an account');\n\n return (accountIndex: number): BitcoinAccount => ({\n type: 'p2tr',\n network,\n accountIndex,\n derivationPath: makeTaprootAccountDerivationPath(network, accountIndex),\n keychain: keychain.derive(makeTaprootAccountDerivationPath(network, accountIndex)),\n });\n}\n\nexport function getTaprootPayment(publicKey: Uint8Array, network: BitcoinNetworkModes) {\n return btc.p2tr(\n ecdsaPublicKeyToSchnorr(publicKey),\n undefined,\n getBtcSignerLibNetworkConfigByMode(network)\n );\n}\n\nexport function getTaprootPaymentFromAddressIndex(keychain: HDKey, network: BitcoinNetworkModes) {\n if (keychain.depth !== DerivationPathDepth.AddressIndex)\n throw new Error('Keychain passed is not an address index');\n\n if (!keychain.publicKey) throw new Error('Keychain has no public key');\n\n return getTaprootPayment(keychain.publicKey, network);\n}\n\ninterface DeriveTaprootReceiveAddressIndexArgs {\n keychain: HDKey;\n network: BitcoinNetworkModes;\n}\nexport function deriveTaprootReceiveAddressIndexZero({\n keychain,\n network,\n}: DeriveTaprootReceiveAddressIndexArgs) {\n const zeroAddressIndex = deriveAddressIndexZeroFromAccount(keychain);\n return {\n keychain: zeroAddressIndex,\n payment: getTaprootPaymentFromAddressIndex(zeroAddressIndex, network),\n };\n}\n","import { base64 } from '@scure/base';\nimport * as btc from '@scure/btc-signer';\nimport * as bitcoin from 'bitcoinjs-lib';\n\nimport { BitcoinNetworkModes } from '@leather.io/models';\n\nimport { getBitcoinJsLibNetworkConfigByMode } from '../bitcoin.network';\nimport {\n bip322TransactionToSignValues,\n ecPairFromPrivateKey,\n encodeMessageWitnessData,\n hashBip322Message,\n tweakSigner,\n} from './bip322-utils';\n\nexport function createNativeSegwitBitcoinJsSigner(privateKey: Buffer) {\n return ecPairFromPrivateKey(privateKey);\n}\n\nexport function createTaprootBitcoinJsSigner(privateKey: Buffer) {\n return tweakSigner(ecPairFromPrivateKey(privateKey));\n}\n\nexport function createToSpendTx(address: string, message: string, network: BitcoinNetworkModes) {\n const { prevoutHash, prevoutIndex, sequence } = bip322TransactionToSignValues;\n\n const script = bitcoin.address.toOutputScript(\n address,\n getBitcoinJsLibNetworkConfigByMode(network)\n );\n\n const hash = hashBip322Message(message);\n const commands = [0, Buffer.from(hash)];\n const scriptSig = bitcoin.script.compile(commands);\n\n const virtualToSpend = new bitcoin.Transaction();\n virtualToSpend.version = 0;\n virtualToSpend.addInput(Buffer.from(prevoutHash), prevoutIndex, sequence, scriptSig);\n virtualToSpend.addOutput(script, 0);\n return { virtualToSpend, script };\n}\n\nfunction createToSignTx(toSpendTxHex: Buffer, script: Buffer, network: BitcoinNetworkModes) {\n const virtualToSign = new bitcoin.Psbt({ network: getBitcoinJsLibNetworkConfigByMode(network) });\n virtualToSign.setVersion(0);\n const prevTxHash = toSpendTxHex;\n const prevOutIndex = 0;\n const toSignScriptSig = bitcoin.script.compile([bitcoin.script.OPS.OP_RETURN]);\n\n virtualToSign.addInput({\n hash: prevTxHash,\n index: prevOutIndex,\n sequence: 0,\n witnessUtxo: { script, value: 0 },\n });\n\n virtualToSign.addOutput({ script: toSignScriptSig, value: 0 });\n return virtualToSign;\n}\n\ninterface SignBip322MessageSimple {\n address: string;\n message: string;\n network: BitcoinNetworkModes;\n signPsbt(psbt: bitcoin.Psbt): Promise<btc.Transaction>;\n}\nexport async function signBip322MessageSimple(args: SignBip322MessageSimple) {\n const { address, message, network, signPsbt } = args;\n\n const { virtualToSpend, script } = createToSpendTx(address, message, network);\n\n const virtualToSign = createToSignTx(virtualToSpend.getHash(), script, network);\n\n const signedTx = await signPsbt(virtualToSign);\n\n const asBitcoinJsTransaction = bitcoin.Psbt.fromBuffer(Buffer.from(signedTx.toPSBT()));\n\n asBitcoinJsTransaction.finalizeInput(0);\n\n // sign the tx\n // section 5.1\n // github.com/LegReq/bip0322-signatures/blob/master/BIP0322_signing.ipynb\n const toSignTx = asBitcoinJsTransaction.extractTransaction();\n\n const result = encodeMessageWitnessData(toSignTx.ins[0].witness);\n\n return {\n virtualToSpend,\n virtualToSign: toSignTx,\n unencodedSig: result,\n signature: base64.encode(result),\n };\n}\n","import { HARDENED_OFFSET, HDKey } from '@scure/bip32';\nimport * as btc from '@scure/btc-signer';\nimport { P2Ret, P2TROut } from '@scure/btc-signer/payment';\nimport { SigHash } from '@scure/btc-signer/transaction';\n\nimport {\n DerivationPathDepth,\n appendAddressIndexToPath,\n decomposeDescriptor,\n deriveKeychainFromXpub,\n keyOriginToDerivationPath,\n} from '@leather.io/crypto';\nimport type { BitcoinNetworkModes } from '@leather.io/models';\nimport { PaymentTypes, SignatureHash } from '@leather.io/rpc';\nimport { hexToNumber, toHexString } from '@leather.io/utils';\n\nimport {\n SupportedPaymentType,\n ecdsaPublicKeyToSchnorr,\n extractExtendedPublicKeyFromPolicy,\n inferPaymentTypeFromPath,\n whenSupportedPaymentType,\n} from './bitcoin.utils';\nimport { getTaprootPaymentFromAddressIndex } from './p2tr-address-gen';\nimport { getNativeSegWitPaymentFromAddressIndex } from './p2wpkh-address-gen';\n\nexport type AllowedSighashTypes = SignatureHash | SigHash;\n\nexport interface BitcoinAccountKeychain {\n descriptor: string;\n masterKeyFingerprint: string;\n keyOrigin: string;\n keychain: HDKey;\n xpub: string;\n}\n\nexport type WithDerivePayer<T, P> = T & { derivePayer: (args: BitcoinPayerInfo) => P };\n\nexport interface BitcoinSigner<Payment> {\n network: BitcoinNetworkModes;\n payment: Payment;\n keychain: HDKey;\n derivationPath: string;\n address: string;\n publicKey: Uint8Array;\n sign(tx: btc.Transaction): void;\n signIndex(tx: btc.Transaction, index: number, allowedSighash?: AllowedSighashTypes[]): void;\n}\n\nexport interface BitcoinPayerBase {\n paymentType: PaymentTypes;\n network: BitcoinNetworkModes;\n address: string;\n keyOrigin: string;\n masterKeyFingerprint: string;\n publicKey: Uint8Array;\n}\n\nexport interface BitcoinNativeSegwitPayer extends BitcoinPayerBase {\n paymentType: 'p2wpkh';\n payment: P2Ret;\n}\n\nexport interface BitcoinTaprootPayer extends BitcoinPayerBase {\n paymentType: 'p2tr';\n payment: P2TROut;\n}\n\nexport type BitcoinPayer = BitcoinNativeSegwitPayer | BitcoinTaprootPayer;\n\nexport function initializeBitcoinAccountKeychainFromDescriptor(\n descriptor: string\n): BitcoinAccountKeychain {\n const { fingerprint, keyOrigin } = decomposeDescriptor(descriptor);\n return {\n descriptor,\n xpub: extractExtendedPublicKeyFromPolicy(descriptor),\n keyOrigin,\n masterKeyFingerprint: fingerprint,\n keychain: deriveKeychainFromXpub(extractExtendedPublicKeyFromPolicy(descriptor)),\n };\n}\n\nexport interface BitcoinPayerInfo {\n receive?: number;\n addressIndex: number;\n}\nexport function deriveBitcoinPayerFromAccount(descriptor: string, network: BitcoinNetworkModes) {\n const { fingerprint, keyOrigin } = decomposeDescriptor(descriptor);\n const accountKeychain = deriveKeychainFromXpub(extractExtendedPublicKeyFromPolicy(descriptor));\n const paymentType = inferPaymentTypeFromPath(keyOrigin) as SupportedPaymentType;\n\n if (accountKeychain.depth !== DerivationPathDepth.Account)\n throw new Error('Keychain passed is not an account');\n\n return ({ receive = 0, addressIndex }: BitcoinPayerInfo) => {\n const childKeychain = accountKeychain.deriveChild(receive).deriveChild(addressIndex);\n\n const derivePayerFromAccount = whenSupportedPaymentType(paymentType)({\n p2tr: getTaprootPaymentFromAddressIndex,\n p2wpkh: getNativeSegWitPaymentFromAddressIndex,\n });\n\n const payment = derivePayerFromAccount(childKeychain, network);\n\n return {\n keyOrigin: appendAddressIndexToPath(keyOrigin, 0),\n masterKeyFingerprint: fingerprint,\n paymentType,\n network,\n payment,\n get address() {\n if (!payment.address) throw new Error('Payment address could not be derived');\n return payment.address;\n },\n get publicKey() {\n if (!childKeychain.publicKey) throw new Error('Public key could not be derived');\n return childKeychain.publicKey;\n },\n };\n };\n}\n\ninterface BtcSignerDerivationPath {\n fingerprint: number;\n path: number[];\n}\nexport type BtcSignerDefaultBip32Derivation = [Uint8Array, BtcSignerDerivationPath];\nexport type BtcSignerTapBip32Derivation = [\n Uint8Array,\n { hashes: Uint8Array[]; der: BtcSignerDerivationPath },\n];\n\ntype BtcSignerBip32Derivation = BtcSignerDefaultBip32Derivation | BtcSignerTapBip32Derivation;\n\ntype PayerToBip32DerivationArgs = Pick<\n BitcoinPayer,\n 'masterKeyFingerprint' | 'keyOrigin' | 'publicKey'\n>;\n\n/**\n * @example\n * ```ts\n * tx.addInput({\n * ...input,\n * bip32Derivation: [payerToBip32Derivation(payer)],\n * })\n * ```\n */\nexport function payerToBip32Derivation(\n args: PayerToBip32DerivationArgs\n): BtcSignerDefaultBip32Derivation {\n return [\n args.publicKey,\n {\n fingerprint: hexToNumber(args.masterKeyFingerprint),\n path: btc.bip32Path(keyOriginToDerivationPath(args.keyOrigin)),\n },\n ];\n}\n\n/**\n * @example\n * ```ts\n * tx.addInput({\n * ...input,\n * tapBip32Derivation: [payerToTapBip32Derivation(payer)],\n * })\n * ```\n */\nexport function payerToTapBip32Derivation(\n args: PayerToBip32DerivationArgs\n): BtcSignerTapBip32Derivation {\n return [\n // TODO: @kyranjamie to default to schnoor when TR so conversion isn't\n // necessary here?\n ecdsaPublicKeyToSchnorr(args.publicKey),\n {\n hashes: [],\n der: {\n fingerprint: hexToNumber(args.masterKeyFingerprint),\n path: btc.bip32Path(keyOriginToDerivationPath(args.keyOrigin)),\n },\n },\n ];\n}\n\n/**\n * @description\n * Turns key format from @scure/btc-signer lib back into key origin string\n * @example\n * ```ts\n * const [inputOne] = getPsbtTxInputs(tx);\n * const keyOrigin = serializeKeyOrigin(inputOne.bip32Derivation[0][1]);\n * ```\n */\nexport function serializeKeyOrigin({ fingerprint, path }: BtcSignerDerivationPath) {\n const values = path.map(num => (num >= HARDENED_OFFSET ? num - HARDENED_OFFSET + \"'\" : num));\n return `${toHexString(fingerprint)}/${values.join('/')}`;\n}\n\n/**\n * @description\n * Of a given set of a `tx.input`s bip32 derivation paths from\n * `@scure/btc-signer`, serialize the paths back to the string format used\n * internally\n */\nexport function extractRequiredKeyOrigins(derivation: BtcSignerBip32Derivation[]) {\n return derivation.map(([_pubkey, path]) =>\n serializeKeyOrigin('hashes' in path ? path.der : path)\n );\n}\n","import { HDKey } from '@scure/bip32';\nimport * as btc from '@scure/btc-signer';\n\nimport { DerivationPathDepth } from '@leather.io/crypto';\nimport { BitcoinNetworkModes } from '@leather.io/models';\n\nimport { getBtcSignerLibNetworkConfigByMode } from './bitcoin.network';\nimport {\n BitcoinAccount,\n deriveAddressIndexZeroFromAccount,\n getBitcoinCoinTypeIndexByNetwork,\n} from './bitcoin.utils';\n\nexport function makeNativeSegwitAccountDerivationPath(\n network: BitcoinNetworkModes,\n accountIndex: number\n) {\n return `m/84'/${getBitcoinCoinTypeIndexByNetwork(network)}'/${accountIndex}'`;\n}\n/** @deprecated Use makeNativeSegwitAccountDerivationPath */\nexport const getNativeSegwitAccountDerivationPath = makeNativeSegwitAccountDerivationPath;\n\nexport function makeNativeSegwitAddressIndexDerivationPath(\n network: BitcoinNetworkModes,\n accountIndex: number,\n addressIndex: number\n) {\n return makeNativeSegwitAccountDerivationPath(network, accountIndex) + `/0/${addressIndex}`;\n}\n/** @deprecated Use makeNativeSegwitAddressIndexDerivationPath */\nexport const getNativeSegwitAddressIndexDerivationPath = makeNativeSegwitAddressIndexDerivationPath;\n\nexport function deriveNativeSegwitAccountFromRootKeychain(\n keychain: HDKey,\n network: BitcoinNetworkModes\n) {\n if (keychain.depth !== DerivationPathDepth.Root) throw new Error('Keychain passed is not a root');\n return (accountIndex: number): BitcoinAccount => ({\n type: 'p2wpkh',\n network,\n accountIndex,\n derivationPath: makeNativeSegwitAccountDerivationPath(network, accountIndex),\n keychain: keychain.derive(makeNativeSegwitAccountDerivationPath(network, accountIndex)),\n });\n}\n\nexport function getNativeSegWitPaymentFromAddressIndex(\n keychain: HDKey,\n network: BitcoinNetworkModes\n) {\n if (keychain.depth !== DerivationPathDepth.AddressIndex)\n throw new Error('Keychain passed is not an address index');\n\n if (!keychain.publicKey) throw new Error('Keychain does not have a public key');\n\n return btc.p2wpkh(keychain.publicKey, getBtcSignerLibNetworkConfigByMode(network));\n}\n\ninterface DeriveNativeSegwitReceiveAddressIndexArgs {\n keychain: HDKey;\n network: BitcoinNetworkModes;\n}\nexport function deriveNativeSegwitReceiveAddressIndexZero({\n keychain,\n network,\n}: DeriveNativeSegwitReceiveAddressIndexArgs) {\n const zeroAddressIndex = deriveAddressIndexZeroFromAccount(keychain);\n return {\n keychain: zeroAddressIndex,\n payment: getNativeSegWitPaymentFromAddressIndex(zeroAddressIndex, network),\n };\n}\n","import { ripemd160 } from '@noble/hashes/ripemd160';\nimport { sha256 } from '@noble/hashes/sha256';\nimport { base58check } from '@scure/base';\n\nimport { deriveBip39SeedFromMnemonic, deriveRootBip32Keychain } from '@leather.io/crypto';\nimport { NetworkModes } from '@leather.io/models';\n\n/**\n * @deprecated\n * Use `deriveBip39MnemonicFromSeed` from `@leather.io/crypto`\n */\nexport const deriveBtcBip49SeedFromMnemonic = deriveBip39SeedFromMnemonic;\n\n/**\n * @deprecated\n * Use `deriveRootBip32Keychain` from `@leather.io/crypto`\n */\nexport const deriveRootBtcKeychain = deriveRootBip32Keychain;\n\nexport function decodeCompressedWifPrivateKey(key: string) {\n // https://en.bitcoinwiki.org/wiki/Wallet_import_format\n // Decode Compressed WIF format private key\n const compressedWifFormatPrivateKey = base58check(sha256).decode(key);\n // Drop leading network byte, trailing public key SEC format byte\n return compressedWifFormatPrivateKey.slice(1, compressedWifFormatPrivateKey.length - 1);\n}\n\n// https://en.bitcoin.it/wiki/List_of_address_prefixes\nconst payToScriptHashMainnetPrefix = 0x05;\nexport const payToScriptHashTestnetPrefix = 0xc4;\n\nconst payToScriptHashPrefixMap: Record<NetworkModes, number> = {\n mainnet: payToScriptHashMainnetPrefix,\n testnet: payToScriptHashTestnetPrefix,\n};\n\nfunction hash160(input: Uint8Array) {\n return ripemd160(sha256(input));\n}\n\nexport function makePayToScriptHashKeyHash(publicKey: Uint8Array) {\n return hash160(publicKey);\n}\n\nexport function makePayToScriptHashAddressBytes(keyHash: Uint8Array) {\n const redeemScript = Uint8Array.from([\n ...Uint8Array.of(0x00),\n ...Uint8Array.of(keyHash.length),\n ...keyHash,\n ]);\n return hash160(redeemScript);\n}\n\nexport function makePayToScriptHashAddress(addressBytes: Uint8Array, network: NetworkModes) {\n const networkByte = payToScriptHashPrefixMap[network];\n const addressWithPrefix = Uint8Array.from([networkByte, ...addressBytes]);\n return base58check(sha256).encode(addressWithPrefix);\n}\n\nexport function publicKeyToPayToScriptHashAddress(publicKey: Uint8Array, network: NetworkModes) {\n const hash = makePayToScriptHashKeyHash(publicKey);\n const addrBytes = makePayToScriptHashAddressBytes(hash);\n return makePayToScriptHashAddress(addrBytes, network);\n}\n"],"mappings":";AAA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I;AAAA,IACrB,GAAG,WAAW,GAAG,QAAQ,MAAM;AAAA,IAC/B,GAAG;AAAA,EACL,CAAC;AACD,SAAO,QAAQ,YAAY;AAC7B;AAEO,SAAS,2BAA2B,cAA0B,SAAuB;AAC1F,QAAM,cAAc,yBAAyB,OAAO;AACpD,QAAM,oBAAoB,WAAW,KAAK,CAAC,aAAa,GAAG,YAAY,CAAC;AACxE,SAAO,YAAYA,OAAM,EAAE,OAAO,iBAAiB;AACrD;AAEO,SAAS,kCAAkC,WAAuB,SAAuB;AAC9F,QAAM,OAAO,2BAA2B,SAAS;AACjD,QAAM,YAAY,gCAAgC,IAAI;AACtD,SAAO,2BAA2B,WAAW,OAAO;AACtD;","names":["hexToBytes","btc","DerivationPathDepth","DerivationPathDepth","script","address","hexToBytes","bitcoin","address","script","btc","DerivationPathDepth","btc","DerivationPathDepth","DerivationPathDepth","DerivationPathDepth","sha256"]}
|
|
1
|
+
{"version":3,"sources":["../src/bip322/bip322-utils.ts","../src/bitcoin.utils.ts","../src/bitcoin.network.ts","../src/p2tr-address-gen.ts","../src/p2wpkh-address-gen.ts","../src/bip322/sign-message-bip322-bitcoinjs.ts","../src/bitcoin-signer.ts","../src/p2wsh-p2sh-address-gen.ts","../src/lookup-derivation-by-address.ts"],"sourcesContent":["import ecc from '@bitcoinerlab/secp256k1';\nimport { sha256 } from '@noble/hashes/sha256';\nimport { hexToBytes, utf8ToBytes } from '@stacks/common';\nimport * as bitcoin from 'bitcoinjs-lib';\nimport { ECPairFactory } from 'ecpair';\nimport { encode } from 'varuint-bitcoin';\n\nimport { PaymentTypes } from '@leather.io/rpc';\nimport { isString } from '@leather.io/utils';\n\nimport { toXOnly } from '../bitcoin.utils';\n\nconst bip322MessageTag = 'BIP0322-signed-message';\n\nconst ECPair = ECPairFactory(ecc);\nbitcoin.initEccLib(ecc);\n\nexport function ecPairFromPrivateKey(key: Uint8Array) {\n return ECPair.fromPrivateKey(Buffer.from(key));\n}\n\n// See tagged hashes section of BIP-340\n// https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki#design\nconst messageTagHash = Uint8Array.from([\n ...sha256(utf8ToBytes(bip322MessageTag)),\n ...sha256(utf8ToBytes(bip322MessageTag)),\n]);\n\nexport function hashBip322Message(message: Uint8Array | string) {\n return sha256(\n Uint8Array.from([...messageTagHash, ...(isString(message) ? utf8ToBytes(message) : message)])\n );\n}\n\nexport const bip322TransactionToSignValues = {\n prevoutHash: hexToBytes('0000000000000000000000000000000000000000000000000000000000000000'),\n prevoutIndex: 0xffffffff,\n sequence: 0,\n};\n\nfunction encodeVarString(b: Buffer) {\n return Buffer.concat([encode(b.byteLength), b]);\n}\n\nconst supportedMessageSigningPaymentTypes: PaymentTypes[] = ['p2wpkh', 'p2tr'];\n\nexport function isSupportedMessageSigningPaymentType(paymentType: string) {\n return supportedMessageSigningPaymentTypes.includes(paymentType as PaymentTypes);\n}\n\n/**\n * Encode witness data for a BIP322 message\n * TODO: Refactor to remove `Buffer` use\n */\nexport function encodeMessageWitnessData(witnessArray: Buffer[]) {\n const len = encode(witnessArray.length);\n return Buffer.concat([len, ...witnessArray.map(witness => encodeVarString(witness))]);\n}\n\nfunction tapTweakHash(pubKey: Buffer, h: Buffer | undefined): Buffer {\n return bitcoin.crypto.taggedHash('TapTweak', Buffer.concat(h ? [pubKey, h] : [pubKey]));\n}\n\nexport function tweakSigner(signer: bitcoin.Signer, opts: any = {}): bitcoin.Signer {\n // @ts-expect-error privateKey exists on signer\n let privateKey: Uint8Array | undefined = signer.privateKey!;\n if (!privateKey) {\n throw new Error('Private key is required for tweaking signer!');\n }\n if (signer.publicKey[0] === 3) {\n privateKey = ecc.privateNegate(privateKey);\n }\n\n const tweakedPrivateKey = ecc.privateAdd(\n privateKey,\n tapTweakHash(toXOnly(signer.publicKey), opts.tweakHash)\n );\n if (!tweakedPrivateKey) {\n throw new Error('Invalid tweaked private key!');\n }\n\n return ECPair.fromPrivateKey(Buffer.from(tweakedPrivateKey), {\n network: opts.network,\n });\n}\n","import { hexToBytes } from '@noble/hashes/utils';\nimport { HDKey, Versions } from '@scure/bip32';\nimport { mnemonicToSeedSync } from '@scure/bip39';\nimport * as btc from '@scure/btc-signer';\nimport { TransactionInput, TransactionOutput } from '@scure/btc-signer/psbt';\n\nimport {\n DerivationPathDepth,\n extractAccountIndexFromPath,\n extractPurposeFromPath,\n} from '@leather.io/crypto';\nimport { BitcoinNetworkModes, NetworkModes } from '@leather.io/models';\nimport type { PaymentTypes } from '@leather.io/rpc';\nimport { defaultWalletKeyId, isDefined, whenNetwork } from '@leather.io/utils';\n\nimport { BtcSignerNetwork, getBtcSignerLibNetworkConfigByMode } from './bitcoin.network';\nimport { getTaprootPayment } from './p2tr-address-gen';\nimport { getNativeSegwitPaymentFromAddressIndex } from './p2wpkh-address-gen';\n\nexport interface BitcoinAccount {\n type: PaymentTypes;\n derivationPath: string;\n keychain: HDKey;\n accountIndex: number;\n network: BitcoinNetworkModes;\n}\nexport function initBitcoinAccount(derivationPath: string, policy: string): BitcoinAccount {\n const xpub = extractExtendedPublicKeyFromPolicy(policy);\n const network = inferNetworkFromPath(derivationPath);\n return {\n keychain: HDKey.fromExtendedKey(xpub, getHdKeyVersionsFromNetwork(network)),\n network,\n derivationPath,\n type: inferPaymentTypeFromPath(derivationPath),\n accountIndex: extractAccountIndexFromPath(derivationPath),\n };\n}\n\n/**\n * Represents a map of `BitcoinNetworkModes` to `NetworkModes`. While Bitcoin\n * has a number of networks, its often only necessary to consider the higher\n * level concept of mainnet and testnet\n */\nexport const bitcoinNetworkToCoreNetworkMap: Record<BitcoinNetworkModes, NetworkModes> = {\n mainnet: 'mainnet',\n testnet: 'testnet',\n regtest: 'testnet',\n signet: 'testnet',\n};\nexport function bitcoinNetworkModeToCoreNetworkMode(mode: BitcoinNetworkModes) {\n return bitcoinNetworkToCoreNetworkMap[mode];\n}\n\ntype BitcoinNetworkMap<T> = Record<BitcoinNetworkModes, T>;\n\nexport function whenBitcoinNetwork(mode: BitcoinNetworkModes) {\n return <T extends BitcoinNetworkMap<unknown>>(networkMap: T) =>\n networkMap[mode] as T[BitcoinNetworkModes];\n}\n\n/**\n * Map representing the \"Coin Type\" section of a derivation path.\n * Consider example below, Coin type is one, thus testnet\n * @example\n * `m/86'/1'/0'/0/0`\n */\nexport const coinTypeMap: Record<NetworkModes, 0 | 1> = {\n mainnet: 0,\n testnet: 1,\n};\n\nexport function getBitcoinCoinTypeIndexByNetwork(network: BitcoinNetworkModes) {\n return coinTypeMap[bitcoinNetworkModeToCoreNetworkMode(network)];\n}\n\nexport function deriveAddressIndexKeychainFromAccount(keychain: HDKey) {\n if (keychain.depth !== DerivationPathDepth.Account)\n throw new Error('Keychain passed is not an account');\n\n return (index: number) => keychain.deriveChild(0).deriveChild(index);\n}\n\nexport function deriveAddressIndexZeroFromAccount(keychain: HDKey) {\n return deriveAddressIndexKeychainFromAccount(keychain)(0);\n}\n\nexport const ecdsaPublicKeyLength = 33;\n\nexport function ecdsaPublicKeyToSchnorr(pubKey: Uint8Array) {\n if (pubKey.byteLength !== ecdsaPublicKeyLength) throw new Error('Invalid public key length');\n return pubKey.slice(1);\n}\n\n// Basically same as above, to remove\nexport const toXOnly = (pubKey: Buffer) => (pubKey.length === 32 ? pubKey : pubKey.subarray(1, 33));\n\nexport function decodeBitcoinTx(tx: string): ReturnType<typeof btc.RawTx.decode> {\n return btc.RawTx.decode(hexToBytes(tx));\n}\n\nexport function getAddressFromOutScript(script: Uint8Array, bitcoinNetwork: BtcSignerNetwork) {\n const outputScript = btc.OutScript.decode(script);\n\n switch (outputScript.type) {\n case 'pkh':\n case 'sh':\n case 'wpkh':\n case 'wsh':\n return btc.Address(bitcoinNetwork).encode({\n type: outputScript.type,\n hash: outputScript.hash,\n });\n case 'tr':\n return btc.Address(bitcoinNetwork).encode({\n type: outputScript.type,\n pubkey: outputScript.pubkey,\n });\n case 'ms':\n return btc.p2ms(outputScript.m, outputScript.pubkeys).address ?? '';\n case 'pk':\n return btc.p2pk(outputScript.pubkey, bitcoinNetwork).address ?? '';\n case 'unknown':\n return 'unknown';\n case 'tr_ms':\n case 'tr_ns':\n default:\n return '';\n }\n}\n\n/**\n * Payment type identifiers, as described by `@scure/btc-signer` library\n */\nexport type BtcSignerLibPaymentTypeIdentifers = 'wpkh' | 'wsh' | 'tr' | 'pkh' | 'sh';\n\nexport const paymentTypeMap: Record<BtcSignerLibPaymentTypeIdentifers, PaymentTypes> = {\n wpkh: 'p2wpkh',\n wsh: 'p2wpkh-p2sh',\n tr: 'p2tr',\n pkh: 'p2pkh',\n sh: 'p2sh',\n};\n\nexport function btcSignerLibPaymentTypeToPaymentTypeMap(\n payment: BtcSignerLibPaymentTypeIdentifers\n) {\n return paymentTypeMap[payment];\n}\n\nexport function isBtcSignerLibPaymentType(\n payment: string\n): payment is BtcSignerLibPaymentTypeIdentifers {\n return payment in paymentTypeMap;\n}\n\nexport function parseKnownPaymentType(payment: BtcSignerLibPaymentTypeIdentifers | PaymentTypes) {\n return isBtcSignerLibPaymentType(payment)\n ? btcSignerLibPaymentTypeToPaymentTypeMap(payment)\n : payment;\n}\n\nexport type PaymentTypeMap<T> = Record<PaymentTypes, T>;\nexport function whenPaymentType(mode: PaymentTypes | BtcSignerLibPaymentTypeIdentifers) {\n return <T extends unknown>(paymentMap: PaymentTypeMap<T>): T =>\n paymentMap[parseKnownPaymentType(mode)];\n}\n\nexport type SupportedPaymentType = 'p2wpkh' | 'p2tr';\nexport type SupportedPaymentTypeMap<T> = Record<SupportedPaymentType, T>;\nexport function whenSupportedPaymentType(mode: SupportedPaymentType) {\n return <T>(paymentMap: SupportedPaymentTypeMap<T>): T => paymentMap[mode];\n}\n\n/**\n * Infers the Bitcoin payment type from the derivation path.\n * Below we see path has 86 in it, per convention, this refers to taproot payments\n * @example\n * `m/86'/1'/0'/0/0`\n */\nexport function inferPaymentTypeFromPath(path: string): PaymentTypes {\n const purpose = extractPurposeFromPath(path);\n switch (purpose) {\n case 84:\n return 'p2wpkh';\n case 86:\n return 'p2tr';\n case 44:\n return 'p2pkh';\n default:\n throw new Error(`Unable to infer payment type from purpose=${purpose}`);\n }\n}\n\nexport function inferNetworkFromPath(path: string): NetworkModes {\n return path.split('/')[2].startsWith('0') ? 'mainnet' : 'testnet';\n}\n\nexport function extractExtendedPublicKeyFromPolicy(policy: string) {\n return policy.split(']')[1];\n}\n\nexport function createWalletIdDecoratedPath(policy: string, walletId: string) {\n return policy.split(']')[0].replace('[', '').replace('m', walletId);\n}\n\n// Primarily used to get the correct `Version` when passing Ledger Bitcoin\n// extended public keys to the HDKey constructor\nexport function getHdKeyVersionsFromNetwork(network: NetworkModes) {\n return whenNetwork(network)({\n mainnet: undefined,\n testnet: {\n private: 0x00000000,\n public: 0x043587cf,\n } as Versions,\n });\n}\n\nexport function getBitcoinInputAddress(input: TransactionInput, bitcoinNetwork: BtcSignerNetwork) {\n if (isDefined(input.witnessUtxo))\n return getAddressFromOutScript(input.witnessUtxo.script, bitcoinNetwork);\n if (isDefined(input.nonWitnessUtxo) && isDefined(input.index))\n return getAddressFromOutScript(\n input.nonWitnessUtxo.outputs[input.index]?.script,\n bitcoinNetwork\n );\n return '';\n}\n\nexport function getInputPaymentType(\n input: TransactionInput,\n network: BitcoinNetworkModes\n): PaymentTypes {\n const address = getBitcoinInputAddress(input, getBtcSignerLibNetworkConfigByMode(network));\n if (address === '') throw new Error('Input address cannot be empty');\n if (address.startsWith('bc1p') || address.startsWith('tb1p') || address.startsWith('bcrt1p'))\n return 'p2tr';\n if (address.startsWith('bc1q') || address.startsWith('tb1q') || address.startsWith('bcrt1q'))\n return 'p2wpkh';\n throw new Error('Unable to infer payment type from input address');\n}\n\n// Ledger wallets are keyed by their derivation path. To reuse the look up logic\n// between payment types, this factory fn accepts a fn that generates the path\nexport function lookUpLedgerKeysByPath(\n getDerivationPath: (network: BitcoinNetworkModes, accountIndex: number) => string\n) {\n return (\n ledgerKeyMap: Record<string, { policy: string } | undefined>,\n network: BitcoinNetworkModes\n ) =>\n (accountIndex: number) => {\n const path = getDerivationPath(network, accountIndex);\n // Single wallet mode, hardcoded default walletId\n const account = ledgerKeyMap[path.replace('m', defaultWalletKeyId)];\n if (!account) return;\n return initBitcoinAccount(path, account.policy);\n };\n}\n\ninterface GetAddressArgs {\n index: number;\n keychain?: HDKey;\n network: BitcoinNetworkModes;\n}\n\nexport function getTaprootAddress({ index, keychain, network }: GetAddressArgs) {\n if (!keychain) throw new Error('Expected keychain to be provided');\n\n if (keychain.depth !== DerivationPathDepth.Account)\n throw new Error('Expects keychain to be on the account index');\n\n const addressIndex = deriveAddressIndexKeychainFromAccount(keychain)(index);\n\n if (!addressIndex.publicKey) throw new Error('Expected publicKey to be defined');\n\n const payment = getTaprootPayment(addressIndex.publicKey, network);\n\n if (!payment.address) throw new Error('Expected address to be defined');\n return payment.address;\n}\n\nexport function getNativeSegwitAddress({ index, keychain, network }: GetAddressArgs) {\n if (!keychain) throw new Error('Expected keychain to be provided');\n\n if (keychain.depth !== DerivationPathDepth.Account)\n throw new Error('Expects keychain to be on the account index');\n\n const addressIndex = deriveAddressIndexKeychainFromAccount(keychain)(index);\n\n if (!addressIndex.publicKey) throw new Error('Expected publicKey to be defined');\n\n const payment = getNativeSegwitPaymentFromAddressIndex(addressIndex, network);\n\n if (!payment.address) throw new Error('Expected address to be defined');\n return payment.address;\n}\n\n/**\n * @deprecated\n * Use `deriveRootBip32Keychain` in `@leather.io/crypto` instead\n */\nexport function mnemonicToRootNode(secretKey: string) {\n const seed = mnemonicToSeedSync(secretKey);\n return HDKey.fromMasterSeed(seed);\n}\n\nexport function getPsbtTxInputs(psbtTx: btc.Transaction): TransactionInput[] {\n const inputsLength = psbtTx.inputsLength;\n const inputs: TransactionInput[] = [];\n for (let i = 0; i < inputsLength; i++) inputs.push(psbtTx.getInput(i));\n return inputs;\n}\n\nexport function getPsbtTxOutputs(psbtTx: btc.Transaction): TransactionOutput[] {\n const outputsLength = psbtTx.outputsLength;\n const outputs: TransactionOutput[] = [];\n for (let i = 0; i < outputsLength; i++) outputs.push(psbtTx.getOutput(i));\n return outputs;\n}\n\nexport function inferNetworkFromAddress(address: string): BitcoinNetworkModes {\n if (address.startsWith('bc1')) return 'mainnet';\n if (address.startsWith('tb1')) return 'testnet';\n if (address.startsWith('bcrt1')) return 'regtest';\n\n const firstChar = address[0];\n\n if (firstChar === '1' || firstChar === '3') return 'mainnet';\n if (firstChar === 'm' || firstChar === 'n') return 'testnet';\n if (firstChar === '2') return 'testnet';\n\n throw new Error('Invalid or unsupported Bitcoin address format');\n}\n\nexport function inferPaymentTypeFromAddress(address: string): SupportedPaymentType {\n if (address.startsWith('bc1q') || address.startsWith('tb1q') || address.startsWith('bcrt1q'))\n return 'p2wpkh';\n\n if (address.startsWith('bc1p') || address.startsWith('tb1p') || address.startsWith('bcrt1p'))\n return 'p2tr';\n\n throw new Error('Unable to infer payment type from address');\n}\n","import * as bitcoinJs from 'bitcoinjs-lib';\n\nimport { BitcoinNetworkModes } from '@leather.io/models';\n\n// See this PR https://github.com/paulmillr/@scure/btc-signer/pull/15\n// Atttempting to add these directly to the library\nexport interface BtcSignerNetwork {\n bech32: string;\n pubKeyHash: number;\n scriptHash: number;\n wif: number;\n}\n\nconst bitcoinMainnet: BtcSignerNetwork = {\n bech32: 'bc',\n pubKeyHash: 0x00,\n scriptHash: 0x05,\n wif: 0x80,\n};\n\nconst bitcoinTestnet: BtcSignerNetwork = {\n bech32: 'tb',\n pubKeyHash: 0x6f,\n scriptHash: 0xc4,\n wif: 0xef,\n};\n\nconst bitcoinRegtest: BtcSignerNetwork = {\n bech32: 'bcrt',\n pubKeyHash: 0x6f,\n scriptHash: 0xc4,\n wif: 0xef,\n};\n\nconst btcSignerLibNetworks: Record<BitcoinNetworkModes, BtcSignerNetwork> = {\n mainnet: bitcoinMainnet,\n testnet: bitcoinTestnet,\n regtest: bitcoinRegtest,\n // Signet originally was going to have its own prefix but authors decided to\n // copy testnet\n signet: bitcoinTestnet,\n};\n\nexport function getBtcSignerLibNetworkConfigByMode(network: BitcoinNetworkModes) {\n return btcSignerLibNetworks[network];\n}\n\nconst bitcoinJsLibNetworks: Record<BitcoinNetworkModes, bitcoinJs.Network> = {\n mainnet: bitcoinJs.networks.bitcoin,\n testnet: bitcoinJs.networks.testnet,\n regtest: bitcoinJs.networks.regtest,\n signet: bitcoinJs.networks.testnet,\n};\n\nexport function getBitcoinJsLibNetworkConfigByMode(network: BitcoinNetworkModes) {\n return bitcoinJsLibNetworks[network];\n}\n","import { HDKey } from '@scure/bip32';\nimport * as btc from '@scure/btc-signer';\n\nimport { DerivationPathDepth } from '@leather.io/crypto';\nimport { BitcoinNetworkModes } from '@leather.io/models';\n\nimport { getBtcSignerLibNetworkConfigByMode } from './bitcoin.network';\nimport {\n BitcoinAccount,\n deriveAddressIndexZeroFromAccount,\n ecdsaPublicKeyToSchnorr,\n getBitcoinCoinTypeIndexByNetwork,\n} from './bitcoin.utils';\n\nexport function makeTaprootAccountDerivationPath(\n network: BitcoinNetworkModes,\n accountIndex: number\n) {\n return `m/86'/${getBitcoinCoinTypeIndexByNetwork(network)}'/${accountIndex}'`;\n}\n/** @deprecated Use makeTaprootAccountDerivationPath */\nexport const getTaprootAccountDerivationPath = makeTaprootAccountDerivationPath;\n\nexport function makeTaprootAddressIndexDerivationPath(\n network: BitcoinNetworkModes,\n accountIndex: number,\n addressIndex: number\n) {\n return makeTaprootAccountDerivationPath(network, accountIndex) + `/0/${addressIndex}`;\n}\n/** @deprecated Use makeTaprootAddressIndexDerivationPath */\nexport const getTaprootAddressIndexDerivationPath = makeTaprootAddressIndexDerivationPath;\n\nexport function deriveTaprootAccount(keychain: HDKey, network: BitcoinNetworkModes) {\n if (keychain.depth !== DerivationPathDepth.Root)\n throw new Error('Keychain passed is not an account');\n\n return (accountIndex: number): BitcoinAccount => ({\n type: 'p2tr',\n network,\n accountIndex,\n derivationPath: makeTaprootAccountDerivationPath(network, accountIndex),\n keychain: keychain.derive(makeTaprootAccountDerivationPath(network, accountIndex)),\n });\n}\n\nexport function getTaprootPayment(publicKey: Uint8Array, network: BitcoinNetworkModes) {\n return btc.p2tr(\n ecdsaPublicKeyToSchnorr(publicKey),\n undefined,\n getBtcSignerLibNetworkConfigByMode(network)\n );\n}\n\nexport function getTaprootPaymentFromAddressIndex(keychain: HDKey, network: BitcoinNetworkModes) {\n if (keychain.depth !== DerivationPathDepth.AddressIndex)\n throw new Error('Keychain passed is not an address index');\n\n if (!keychain.publicKey) throw new Error('Keychain has no public key');\n\n return getTaprootPayment(keychain.publicKey, network);\n}\n\ninterface DeriveTaprootReceiveAddressIndexArgs {\n keychain: HDKey;\n network: BitcoinNetworkModes;\n}\nexport function deriveTaprootReceiveAddressIndexZero({\n keychain,\n network,\n}: DeriveTaprootReceiveAddressIndexArgs) {\n const zeroAddressIndex = deriveAddressIndexZeroFromAccount(keychain);\n return {\n keychain: zeroAddressIndex,\n payment: getTaprootPaymentFromAddressIndex(zeroAddressIndex, network),\n };\n}\n","import { HDKey } from '@scure/bip32';\nimport * as btc from '@scure/btc-signer';\n\nimport { DerivationPathDepth } from '@leather.io/crypto';\nimport { BitcoinNetworkModes } from '@leather.io/models';\n\nimport { getBtcSignerLibNetworkConfigByMode } from './bitcoin.network';\nimport {\n BitcoinAccount,\n deriveAddressIndexZeroFromAccount,\n getBitcoinCoinTypeIndexByNetwork,\n} from './bitcoin.utils';\n\nexport function makeNativeSegwitAccountDerivationPath(\n network: BitcoinNetworkModes,\n accountIndex: number\n) {\n return `m/84'/${getBitcoinCoinTypeIndexByNetwork(network)}'/${accountIndex}'`;\n}\n\n/** @deprecated Use makeNativeSegwitAccountDerivationPath */\nexport const getNativeSegwitAccountDerivationPath = makeNativeSegwitAccountDerivationPath;\n\nexport function makeNativeSegwitAddressIndexDerivationPath(\n network: BitcoinNetworkModes,\n accountIndex: number,\n addressIndex: number\n) {\n return makeNativeSegwitAccountDerivationPath(network, accountIndex) + `/0/${addressIndex}`;\n}\n\n/** @deprecated Use makeNativeSegwitAddressIndexDerivationPath */\nexport const getNativeSegwitAddressIndexDerivationPath = makeNativeSegwitAddressIndexDerivationPath;\n\nexport function deriveNativeSegwitAccountFromRootKeychain(\n keychain: HDKey,\n network: BitcoinNetworkModes\n) {\n if (keychain.depth !== DerivationPathDepth.Root) throw new Error('Keychain passed is not a root');\n return (accountIndex: number): BitcoinAccount => ({\n type: 'p2wpkh',\n network,\n accountIndex,\n derivationPath: makeNativeSegwitAccountDerivationPath(network, accountIndex),\n keychain: keychain.derive(makeNativeSegwitAccountDerivationPath(network, accountIndex)),\n });\n}\n\nexport function getNativeSegwitPaymentFromAddressIndex(\n keychain: HDKey,\n network: BitcoinNetworkModes\n) {\n if (keychain.depth !== DerivationPathDepth.AddressIndex)\n throw new Error('Keychain passed is not an address index');\n\n if (!keychain.publicKey) throw new Error('Keychain does not have a public key');\n\n return btc.p2wpkh(keychain.publicKey, getBtcSignerLibNetworkConfigByMode(network));\n}\n\ninterface DeriveNativeSegwitReceiveAddressIndexArgs {\n keychain: HDKey;\n network: BitcoinNetworkModes;\n}\nexport function deriveNativeSegwitReceiveAddressIndexZero({\n keychain,\n network,\n}: DeriveNativeSegwitReceiveAddressIndexArgs) {\n const zeroAddressIndex = deriveAddressIndexZeroFromAccount(keychain);\n return {\n keychain: zeroAddressIndex,\n payment: getNativeSegwitPaymentFromAddressIndex(zeroAddressIndex, network),\n };\n}\n","import { base64 } from '@scure/base';\nimport * as btc from '@scure/btc-signer';\nimport * as bitcoin from 'bitcoinjs-lib';\n\nimport { BitcoinNetworkModes } from '@leather.io/models';\n\nimport { getBitcoinJsLibNetworkConfigByMode } from '../bitcoin.network';\nimport {\n bip322TransactionToSignValues,\n ecPairFromPrivateKey,\n encodeMessageWitnessData,\n hashBip322Message,\n tweakSigner,\n} from './bip322-utils';\n\nexport function createNativeSegwitBitcoinJsSigner(privateKey: Buffer) {\n return ecPairFromPrivateKey(privateKey);\n}\n\nexport function createTaprootBitcoinJsSigner(privateKey: Buffer) {\n return tweakSigner(ecPairFromPrivateKey(privateKey));\n}\n\nexport function createToSpendTx(address: string, message: string, network: BitcoinNetworkModes) {\n const { prevoutHash, prevoutIndex, sequence } = bip322TransactionToSignValues;\n\n const script = bitcoin.address.toOutputScript(\n address,\n getBitcoinJsLibNetworkConfigByMode(network)\n );\n\n const hash = hashBip322Message(message);\n const commands = [0, Buffer.from(hash)];\n const scriptSig = bitcoin.script.compile(commands);\n\n const virtualToSpend = new bitcoin.Transaction();\n virtualToSpend.version = 0;\n virtualToSpend.addInput(Buffer.from(prevoutHash), prevoutIndex, sequence, scriptSig);\n virtualToSpend.addOutput(script, 0);\n return { virtualToSpend, script };\n}\n\nfunction createToSignTx(toSpendTxHex: Buffer, script: Buffer, network: BitcoinNetworkModes) {\n const virtualToSign = new bitcoin.Psbt({ network: getBitcoinJsLibNetworkConfigByMode(network) });\n virtualToSign.setVersion(0);\n const prevTxHash = toSpendTxHex;\n const prevOutIndex = 0;\n const toSignScriptSig = bitcoin.script.compile([bitcoin.script.OPS.OP_RETURN]);\n\n virtualToSign.addInput({\n hash: prevTxHash,\n index: prevOutIndex,\n sequence: 0,\n witnessUtxo: { script, value: 0 },\n });\n\n virtualToSign.addOutput({ script: toSignScriptSig, value: 0 });\n return virtualToSign;\n}\n\ninterface SignBip322MessageSimple {\n address: string;\n message: string;\n network: BitcoinNetworkModes;\n signPsbt(psbt: bitcoin.Psbt): Promise<btc.Transaction>;\n}\nexport async function signBip322MessageSimple(args: SignBip322MessageSimple) {\n const { address, message, network, signPsbt } = args;\n\n const { virtualToSpend, script } = createToSpendTx(address, message, network);\n\n const virtualToSign = createToSignTx(virtualToSpend.getHash(), script, network);\n\n const signedTx = await signPsbt(virtualToSign);\n\n const asBitcoinJsTransaction = bitcoin.Psbt.fromBuffer(Buffer.from(signedTx.toPSBT()));\n\n asBitcoinJsTransaction.finalizeInput(0);\n\n // sign the tx\n // section 5.1\n // github.com/LegReq/bip0322-signatures/blob/master/BIP0322_signing.ipynb\n const toSignTx = asBitcoinJsTransaction.extractTransaction();\n\n const result = encodeMessageWitnessData(toSignTx.ins[0].witness);\n\n return {\n virtualToSpend,\n virtualToSign: toSignTx,\n unencodedSig: result,\n signature: base64.encode(result),\n };\n}\n","import { HARDENED_OFFSET, HDKey } from '@scure/bip32';\nimport * as btc from '@scure/btc-signer';\nimport { P2Ret, P2TROut } from '@scure/btc-signer/payment';\nimport { SigHash } from '@scure/btc-signer/transaction';\n\nimport {\n DerivationPathDepth,\n appendAddressIndexToPath,\n decomposeDescriptor,\n deriveKeychainFromXpub,\n keyOriginToDerivationPath,\n} from '@leather.io/crypto';\nimport type { BitcoinNetworkModes } from '@leather.io/models';\nimport { PaymentTypes, SignatureHash } from '@leather.io/rpc';\nimport { hexToNumber, toHexString } from '@leather.io/utils';\n\nimport {\n SupportedPaymentType,\n ecdsaPublicKeyToSchnorr,\n extractExtendedPublicKeyFromPolicy,\n inferPaymentTypeFromPath,\n whenSupportedPaymentType,\n} from './bitcoin.utils';\nimport { getTaprootPaymentFromAddressIndex } from './p2tr-address-gen';\nimport { getNativeSegwitPaymentFromAddressIndex } from './p2wpkh-address-gen';\n\nexport type AllowedSighashTypes = SignatureHash | SigHash;\n\nexport interface BitcoinAccountKeychain {\n descriptor: string;\n masterKeyFingerprint: string;\n keyOrigin: string;\n keychain: HDKey;\n xpub: string;\n}\n\nexport type WithDerivePayer<T, P> = T & { derivePayer: (args: BitcoinPayerInfo) => P };\n\nexport interface BitcoinSigner<Payment> {\n network: BitcoinNetworkModes;\n payment: Payment;\n keychain: HDKey;\n derivationPath: string;\n address: string;\n publicKey: Uint8Array;\n sign(tx: btc.Transaction): void;\n signIndex(tx: btc.Transaction, index: number, allowedSighash?: AllowedSighashTypes[]): void;\n}\n\nexport interface BitcoinPayerBase {\n paymentType: PaymentTypes;\n network: BitcoinNetworkModes;\n address: string;\n keyOrigin: string;\n masterKeyFingerprint: string;\n publicKey: Uint8Array;\n}\n\nexport interface BitcoinNativeSegwitPayer extends BitcoinPayerBase {\n paymentType: 'p2wpkh';\n payment: P2Ret;\n}\n\nexport interface BitcoinTaprootPayer extends BitcoinPayerBase {\n paymentType: 'p2tr';\n payment: P2TROut;\n}\n\nexport type BitcoinPayer = BitcoinNativeSegwitPayer | BitcoinTaprootPayer;\n\nexport function initializeBitcoinAccountKeychainFromDescriptor(\n descriptor: string\n): BitcoinAccountKeychain {\n const { fingerprint, keyOrigin } = decomposeDescriptor(descriptor);\n return {\n descriptor,\n xpub: extractExtendedPublicKeyFromPolicy(descriptor),\n keyOrigin,\n masterKeyFingerprint: fingerprint,\n keychain: deriveKeychainFromXpub(extractExtendedPublicKeyFromPolicy(descriptor)),\n };\n}\n\nexport interface BitcoinPayerInfo {\n receive?: number;\n addressIndex: number;\n}\nexport function deriveBitcoinPayerFromAccount(descriptor: string, network: BitcoinNetworkModes) {\n const { fingerprint, keyOrigin } = decomposeDescriptor(descriptor);\n const accountKeychain = deriveKeychainFromXpub(extractExtendedPublicKeyFromPolicy(descriptor));\n const paymentType = inferPaymentTypeFromPath(keyOrigin) as SupportedPaymentType;\n\n if (accountKeychain.depth !== DerivationPathDepth.Account)\n throw new Error('Keychain passed is not an account');\n\n return ({ receive = 0, addressIndex }: BitcoinPayerInfo) => {\n const childKeychain = accountKeychain.deriveChild(receive).deriveChild(addressIndex);\n\n const derivePayerFromAccount = whenSupportedPaymentType(paymentType)({\n p2tr: getTaprootPaymentFromAddressIndex,\n p2wpkh: getNativeSegwitPaymentFromAddressIndex,\n });\n\n const payment = derivePayerFromAccount(childKeychain, network);\n\n return {\n keyOrigin: appendAddressIndexToPath(keyOrigin, 0),\n masterKeyFingerprint: fingerprint,\n paymentType,\n network,\n payment,\n get address() {\n if (!payment.address) throw new Error('Payment address could not be derived');\n return payment.address;\n },\n get publicKey() {\n if (!childKeychain.publicKey) throw new Error('Public key could not be derived');\n return childKeychain.publicKey;\n },\n };\n };\n}\n\ninterface BtcSignerDerivationPath {\n fingerprint: number;\n path: number[];\n}\nexport type BtcSignerDefaultBip32Derivation = [Uint8Array, BtcSignerDerivationPath];\nexport type BtcSignerTapBip32Derivation = [\n Uint8Array,\n { hashes: Uint8Array[]; der: BtcSignerDerivationPath },\n];\n\ntype BtcSignerBip32Derivation = BtcSignerDefaultBip32Derivation | BtcSignerTapBip32Derivation;\n\ntype PayerToBip32DerivationArgs = Pick<\n BitcoinPayer,\n 'masterKeyFingerprint' | 'keyOrigin' | 'publicKey'\n>;\n\n/**\n * @example\n * ```ts\n * tx.addInput({\n * ...input,\n * bip32Derivation: [payerToBip32Derivation(payer)],\n * })\n * ```\n */\nexport function payerToBip32Derivation(\n args: PayerToBip32DerivationArgs\n): BtcSignerDefaultBip32Derivation {\n return [\n args.publicKey,\n {\n fingerprint: hexToNumber(args.masterKeyFingerprint),\n path: btc.bip32Path(keyOriginToDerivationPath(args.keyOrigin)),\n },\n ];\n}\n\n/**\n * @example\n * ```ts\n * tx.addInput({\n * ...input,\n * tapBip32Derivation: [payerToTapBip32Derivation(payer)],\n * })\n * ```\n */\nexport function payerToTapBip32Derivation(\n args: PayerToBip32DerivationArgs\n): BtcSignerTapBip32Derivation {\n return [\n // TODO: @kyranjamie to default to schnoor when TR so conversion isn't\n // necessary here?\n ecdsaPublicKeyToSchnorr(args.publicKey),\n {\n hashes: [],\n der: {\n fingerprint: hexToNumber(args.masterKeyFingerprint),\n path: btc.bip32Path(keyOriginToDerivationPath(args.keyOrigin)),\n },\n },\n ];\n}\n\n/**\n * @description\n * Turns key format from @scure/btc-signer lib back into key origin string\n * @example\n * ```ts\n * const [inputOne] = getPsbtTxInputs(tx);\n * const keyOrigin = serializeKeyOrigin(inputOne.bip32Derivation[0][1]);\n * ```\n */\nexport function serializeKeyOrigin({ fingerprint, path }: BtcSignerDerivationPath) {\n const values = path.map(num => (num >= HARDENED_OFFSET ? num - HARDENED_OFFSET + \"'\" : num));\n return `${toHexString(fingerprint)}/${values.join('/')}`;\n}\n\n/**\n * @description\n * Of a given set of a `tx.input`s bip32 derivation paths from\n * `@scure/btc-signer`, serialize the paths back to the string format used\n * internally\n */\nexport function extractRequiredKeyOrigins(derivation: BtcSignerBip32Derivation[]) {\n return derivation.map(([_pubkey, path]) =>\n serializeKeyOrigin('hashes' in path ? path.der : path)\n );\n}\n","import { ripemd160 } from '@noble/hashes/ripemd160';\nimport { sha256 } from '@noble/hashes/sha256';\nimport { base58check } from '@scure/base';\n\nimport { deriveBip39SeedFromMnemonic, deriveRootBip32Keychain } from '@leather.io/crypto';\nimport { NetworkModes } from '@leather.io/models';\n\n/**\n * @deprecated\n * Use `deriveBip39MnemonicFromSeed` from `@leather.io/crypto`\n */\nexport const deriveBtcBip49SeedFromMnemonic = deriveBip39SeedFromMnemonic;\n\n/**\n * @deprecated\n * Use `deriveRootBip32Keychain` from `@leather.io/crypto`\n */\nexport const deriveRootBtcKeychain = deriveRootBip32Keychain;\n\nexport function decodeCompressedWifPrivateKey(key: string) {\n // https://en.bitcoinwiki.org/wiki/Wallet_import_format\n // Decode Compressed WIF format private key\n const compressedWifFormatPrivateKey = base58check(sha256).decode(key);\n // Drop leading network byte, trailing public key SEC format byte\n return compressedWifFormatPrivateKey.slice(1, compressedWifFormatPrivateKey.length - 1);\n}\n\n// https://en.bitcoin.it/wiki/List_of_address_prefixes\nconst payToScriptHashMainnetPrefix = 0x05;\nexport const payToScriptHashTestnetPrefix = 0xc4;\n\nconst payToScriptHashPrefixMap: Record<NetworkModes, number> = {\n mainnet: payToScriptHashMainnetPrefix,\n testnet: payToScriptHashTestnetPrefix,\n};\n\nfunction hash160(input: Uint8Array) {\n return ripemd160(sha256(input));\n}\n\nexport function makePayToScriptHashKeyHash(publicKey: Uint8Array) {\n return hash160(publicKey);\n}\n\nexport function makePayToScriptHashAddressBytes(keyHash: Uint8Array) {\n const redeemScript = Uint8Array.from([\n ...Uint8Array.of(0x00),\n ...Uint8Array.of(keyHash.length),\n ...keyHash,\n ]);\n return hash160(redeemScript);\n}\n\nexport function makePayToScriptHashAddress(addressBytes: Uint8Array, network: NetworkModes) {\n const networkByte = payToScriptHashPrefixMap[network];\n const addressWithPrefix = Uint8Array.from([networkByte, ...addressBytes]);\n return base58check(sha256).encode(addressWithPrefix);\n}\n\nexport function publicKeyToPayToScriptHashAddress(publicKey: Uint8Array, network: NetworkModes) {\n const hash = makePayToScriptHashKeyHash(publicKey);\n const addrBytes = makePayToScriptHashAddressBytes(hash);\n return makePayToScriptHashAddress(addrBytes, network);\n}\n","import { HARDENED_OFFSET, HDKey } from '@scure/bip32';\n\nimport { createCounter } from '@leather.io/utils';\n\nimport {\n getNativeSegwitAddress,\n getTaprootAddress,\n inferNetworkFromAddress,\n inferPaymentTypeFromAddress,\n whenSupportedPaymentType,\n} from './bitcoin.utils';\nimport { makeTaprootAddressIndexDerivationPath } from './p2tr-address-gen';\nimport { makeNativeSegwitAddressIndexDerivationPath } from './p2wpkh-address-gen';\n\ninterface LookUpDerivationByAddressArgs {\n taprootXpub: string;\n nativeSegwitXpub: string;\n iterationLimit: number;\n}\nexport function lookupDerivationByAddress(args: LookUpDerivationByAddressArgs) {\n const { taprootXpub, nativeSegwitXpub, iterationLimit } = args;\n\n const taprootKeychain = HDKey.fromExtendedKey(taprootXpub);\n const nativeSegwitKeychain = HDKey.fromExtendedKey(nativeSegwitXpub);\n\n return (address: string) => {\n const network = inferNetworkFromAddress(address);\n const paymentType = inferPaymentTypeFromAddress(address);\n\n const accountIndex = whenSupportedPaymentType(paymentType)({\n p2tr: taprootKeychain.index - HARDENED_OFFSET,\n p2wpkh: nativeSegwitKeychain.index - HARDENED_OFFSET,\n });\n\n function getTaprootAddressAtIndex(index: number) {\n return getTaprootAddress({ index, keychain: taprootKeychain, network });\n }\n\n function getNativeSegwitAddressAtIndex(index: number) {\n return getNativeSegwitAddress({ index, keychain: nativeSegwitKeychain, network });\n }\n\n const paymentFn = whenSupportedPaymentType(paymentType)({\n p2tr: getTaprootAddressAtIndex,\n p2wpkh: getNativeSegwitAddressAtIndex,\n });\n\n const derivationPathFn = whenSupportedPaymentType(paymentType)({\n p2tr: makeTaprootAddressIndexDerivationPath,\n p2wpkh: makeNativeSegwitAddressIndexDerivationPath,\n });\n\n const count = createCounter();\n const t0 = performance.now();\n\n while (count.getValue() <= iterationLimit) {\n const currentIndex = count.getValue();\n\n const addressToCheck = paymentFn(currentIndex);\n\n if (addressToCheck !== address) {\n count.increment();\n continue;\n }\n\n const t1 = performance.now();\n\n return {\n status: 'success',\n duration: t1 - t0,\n path: derivationPathFn(network, accountIndex, currentIndex),\n } as const;\n }\n\n return { status: 'failure' } as const;\n };\n}\n"],"mappings":";AAAA,OAAO,SAAS;AAChB,SAAS,cAAc;AACvB,SAAS,cAAAA,aAAY,mBAAmB;AACxC,YAAY,aAAa;AACzB,SAAS,qBAAqB;AAC9B,SAAS,cAAc;AAGvB,SAAS,gBAAgB;;;ACRzB,SAAS,kBAAkB;AAC3B,SAAS,aAAuB;AAChC,SAAS,0BAA0B;AACnC,YAAYC,UAAS;AAGrB;AAAA,EACE,uBAAAC;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGP,SAAS,oBAAoB,WAAW,mBAAmB;;;ACb3D,YAAY,eAAe;AAa3B,IAAM,iBAAmC;AAAA,EACvC,QAAQ;AAAA,EACR,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,KAAK;AACP;AAEA,IAAM,iBAAmC;AAAA,EACvC,QAAQ;AAAA,EACR,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,KAAK;AACP;AAEA,IAAM,iBAAmC;AAAA,EACvC,QAAQ;AAAA,EACR,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,KAAK;AACP;AAEA,IAAM,uBAAsE;AAAA,EAC1E,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AAAA;AAAA;AAAA,EAGT,QAAQ;AACV;AAEO,SAAS,mCAAmC,SAA8B;AAC/E,SAAO,qBAAqB,OAAO;AACrC;AAEA,IAAM,uBAAuE;AAAA,EAC3E,SAAmB,mBAAS;AAAA,EAC5B,SAAmB,mBAAS;AAAA,EAC5B,SAAmB,mBAAS;AAA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ACtD,MAAM;AAAA,MACN,QAAQ;AAAA,IACV,CAAC;AAED,UAAM,mBAAmB,yBAAyB,WAAW,EAAE;AAAA,MAC7D,MAAM;AAAA,MACN,QAAQ;AAAA,IACV,CAAC;AAED,UAAM,QAAQ,cAAc;AAC5B,UAAM,KAAK,YAAY,IAAI;AAE3B,WAAO,MAAM,SAAS,KAAK,gBAAgB;AACzC,YAAM,eAAe,MAAM,SAAS;AAEpC,YAAM,iBAAiB,UAAU,YAAY;AAE7C,UAAI,mBAAmBD,UAAS;AAC9B,cAAM,UAAU;AAChB;AAAA,MACF;AAEA,YAAM,KAAK,YAAY,IAAI;AAE3B,aAAO;AAAA,QACL,QAAQ;AAAA,QACR,UAAU,KAAK;AAAA,QACf,MAAM,iBAAiB,SAAS,cAAc,YAAY;AAAA,MAC5D;AAAA,IACF;AAEA,WAAO,EAAE,QAAQ,UAAU;AAAA,EAC7B;AACF;","names":["hexToBytes","btc","DerivationPathDepth","btc","DerivationPathDepth","DerivationPathDepth","DerivationPathDepth","script","address","hexToBytes","bitcoin","address","script","btc","DerivationPathDepth","DerivationPathDepth","sha256","HARDENED_OFFSET","HDKey","HDKey","address","HARDENED_OFFSET"]}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@leather.io/bitcoin",
|
|
3
3
|
"author": "Leather.io contact@leather.io",
|
|
4
4
|
"description": "Shared bitcoin utilities",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.16.0",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/leather.io/mono/tree/dev/packages/bitcoin",
|
|
8
8
|
"repository": {
|
|
@@ -24,16 +24,16 @@
|
|
|
24
24
|
"@scure/bip39": "1.4.0",
|
|
25
25
|
"@scure/btc-signer": "1.4.0",
|
|
26
26
|
"@stacks/common": "6.13.0",
|
|
27
|
-
"@stacks/transactions": "6.
|
|
27
|
+
"@stacks/transactions": "6.17.0",
|
|
28
28
|
"bip32": "4.0.0",
|
|
29
29
|
"bitcoinjs-lib": "6.1.5",
|
|
30
30
|
"ecpair": "2.1.0",
|
|
31
31
|
"just-memoize": "2.2.0",
|
|
32
32
|
"varuint-bitcoin": "1.1.2",
|
|
33
|
-
"@leather.io/constants": "0.
|
|
34
|
-
"@leather.io/
|
|
35
|
-
"@leather.io/
|
|
36
|
-
"@leather.io/utils": "0.16.
|
|
33
|
+
"@leather.io/constants": "0.13.0",
|
|
34
|
+
"@leather.io/models": "0.18.3",
|
|
35
|
+
"@leather.io/crypto": "1.6.7",
|
|
36
|
+
"@leather.io/utils": "0.16.7"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"eslint": "8.53.0",
|
|
@@ -43,9 +43,9 @@
|
|
|
43
43
|
"typescript": "5.5.4",
|
|
44
44
|
"vitest": "2.0.5",
|
|
45
45
|
"@leather.io/eslint-config": "0.7.0",
|
|
46
|
-
"@leather.io/rpc": "2.1.13",
|
|
47
46
|
"@leather.io/prettier-config": "0.6.0",
|
|
48
|
-
"@leather.io/tsconfig-config": "0.6.0"
|
|
47
|
+
"@leather.io/tsconfig-config": "0.6.0",
|
|
48
|
+
"@leather.io/rpc": "2.1.14"
|
|
49
49
|
},
|
|
50
50
|
"keywords": [
|
|
51
51
|
"bitcoin",
|
package/src/bitcoin-signer.ts
CHANGED
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
whenSupportedPaymentType,
|
|
23
23
|
} from './bitcoin.utils';
|
|
24
24
|
import { getTaprootPaymentFromAddressIndex } from './p2tr-address-gen';
|
|
25
|
-
import {
|
|
25
|
+
import { getNativeSegwitPaymentFromAddressIndex } from './p2wpkh-address-gen';
|
|
26
26
|
|
|
27
27
|
export type AllowedSighashTypes = SignatureHash | SigHash;
|
|
28
28
|
|
|
@@ -98,7 +98,7 @@ export function deriveBitcoinPayerFromAccount(descriptor: string, network: Bitco
|
|
|
98
98
|
|
|
99
99
|
const derivePayerFromAccount = whenSupportedPaymentType(paymentType)({
|
|
100
100
|
p2tr: getTaprootPaymentFromAddressIndex,
|
|
101
|
-
p2wpkh:
|
|
101
|
+
p2wpkh: getNativeSegwitPaymentFromAddressIndex,
|
|
102
102
|
});
|
|
103
103
|
|
|
104
104
|
const payment = derivePayerFromAccount(childKeychain, network);
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { inferNetworkFromAddress, inferPaymentTypeFromAddress } from './bitcoin.utils';
|
|
4
|
+
|
|
5
|
+
describe(inferNetworkFromAddress.name, () => {
|
|
6
|
+
it('should return "mainnet" for P2PKH mainnet addresses', () => {
|
|
7
|
+
const mainnetAddress = '1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa';
|
|
8
|
+
expect(inferNetworkFromAddress(mainnetAddress)).toBe('mainnet');
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('should return "mainnet" for P2SH mainnet addresses', () => {
|
|
12
|
+
const mainnetP2SHAddress = '3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy';
|
|
13
|
+
expect(inferNetworkFromAddress(mainnetP2SHAddress)).toBe('mainnet');
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('should return "mainnet" for Bech32 mainnet addresses', () => {
|
|
17
|
+
const mainnetBech32Address = 'bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kygt080';
|
|
18
|
+
expect(inferNetworkFromAddress(mainnetBech32Address)).toBe('mainnet');
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('should return "testnet" for P2PKH testnet addresses', () => {
|
|
22
|
+
const testnetP2PKHAddress = 'mipcBbFg9gMiCh81Kj8tqqdgoZub1ZJRfn';
|
|
23
|
+
expect(inferNetworkFromAddress(testnetP2PKHAddress)).toBe('testnet');
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('should return "testnet" for P2SH testnet addresses', () => {
|
|
27
|
+
const testnetP2SHAddress = '2NBFNJTktNa7GZusGbDbGKRZTxdK9VVez3n';
|
|
28
|
+
expect(inferNetworkFromAddress(testnetP2SHAddress)).toBe('testnet');
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('should return "testnet" for Bech32 testnet addresses', () => {
|
|
32
|
+
const testnetBech32Address = 'tb1qxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyz';
|
|
33
|
+
expect(inferNetworkFromAddress(testnetBech32Address)).toBe('testnet');
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('should return "regtest" for Bech32 regtest addresses', () => {
|
|
37
|
+
const regtestBech32Address = 'bcrt1qxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyz';
|
|
38
|
+
expect(inferNetworkFromAddress(regtestBech32Address)).toBe('regtest');
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('should throw an error for invalid addresses', () => {
|
|
42
|
+
const invalidAddress = 'invalidAddress';
|
|
43
|
+
expect(() => inferNetworkFromAddress(invalidAddress)).toThrow(
|
|
44
|
+
'Invalid or unsupported Bitcoin address format'
|
|
45
|
+
);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
// Assuming the function is in a file named bitcoinLib.ts
|
|
49
|
+
|
|
50
|
+
describe(inferPaymentTypeFromAddress.name, () => {
|
|
51
|
+
it('should return p2wpkh for mainnet P2WPKH address', () => {
|
|
52
|
+
const address = 'bc1qxyzabc123'; // Example P2WPKH mainnet address
|
|
53
|
+
expect(inferPaymentTypeFromAddress(address)).toBe('p2wpkh');
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('should return p2tr for mainnet P2TR address', () => {
|
|
57
|
+
const address = 'bc1pxyzabc123'; // Example P2TR mainnet address
|
|
58
|
+
expect(inferPaymentTypeFromAddress(address)).toBe('p2tr');
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('should return p2wpkh for testnet P2WPKH address', () => {
|
|
62
|
+
const address = 'tb1qxyzabc123'; // Example P2WPKH testnet address
|
|
63
|
+
expect(inferPaymentTypeFromAddress(address)).toBe('p2wpkh');
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('should return p2tr for testnet P2TR address', () => {
|
|
67
|
+
const address = 'tb1pxyzabc123'; // Example P2TR testnet address
|
|
68
|
+
expect(inferPaymentTypeFromAddress(address)).toBe('p2tr');
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('should return p2wpkh for regtest P2WPKH address', () => {
|
|
72
|
+
const address = 'bcrt1qxyzabc123'; // Example P2WPKH regtest address
|
|
73
|
+
expect(inferPaymentTypeFromAddress(address)).toBe('p2wpkh');
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('should return p2tr for regtest P2TR address', () => {
|
|
77
|
+
const address = 'bcrt1pxyzabc123'; // Example P2TR regtest address
|
|
78
|
+
expect(inferPaymentTypeFromAddress(address)).toBe('p2tr');
|
|
79
|
+
});
|
|
80
|
+
});
|
package/src/bitcoin.utils.ts
CHANGED
|
@@ -15,6 +15,7 @@ import { defaultWalletKeyId, isDefined, whenNetwork } from '@leather.io/utils';
|
|
|
15
15
|
|
|
16
16
|
import { BtcSignerNetwork, getBtcSignerLibNetworkConfigByMode } from './bitcoin.network';
|
|
17
17
|
import { getTaprootPayment } from './p2tr-address-gen';
|
|
18
|
+
import { getNativeSegwitPaymentFromAddressIndex } from './p2wpkh-address-gen';
|
|
18
19
|
|
|
19
20
|
export interface BitcoinAccount {
|
|
20
21
|
type: PaymentTypes;
|
|
@@ -256,12 +257,13 @@ export function lookUpLedgerKeysByPath(
|
|
|
256
257
|
};
|
|
257
258
|
}
|
|
258
259
|
|
|
259
|
-
|
|
260
|
+
interface GetAddressArgs {
|
|
260
261
|
index: number;
|
|
261
262
|
keychain?: HDKey;
|
|
262
263
|
network: BitcoinNetworkModes;
|
|
263
264
|
}
|
|
264
|
-
|
|
265
|
+
|
|
266
|
+
export function getTaprootAddress({ index, keychain, network }: GetAddressArgs) {
|
|
265
267
|
if (!keychain) throw new Error('Expected keychain to be provided');
|
|
266
268
|
|
|
267
269
|
if (keychain.depth !== DerivationPathDepth.Account)
|
|
@@ -277,6 +279,22 @@ export function getTaprootAddress({ index, keychain, network }: GetTaprootAddres
|
|
|
277
279
|
return payment.address;
|
|
278
280
|
}
|
|
279
281
|
|
|
282
|
+
export function getNativeSegwitAddress({ index, keychain, network }: GetAddressArgs) {
|
|
283
|
+
if (!keychain) throw new Error('Expected keychain to be provided');
|
|
284
|
+
|
|
285
|
+
if (keychain.depth !== DerivationPathDepth.Account)
|
|
286
|
+
throw new Error('Expects keychain to be on the account index');
|
|
287
|
+
|
|
288
|
+
const addressIndex = deriveAddressIndexKeychainFromAccount(keychain)(index);
|
|
289
|
+
|
|
290
|
+
if (!addressIndex.publicKey) throw new Error('Expected publicKey to be defined');
|
|
291
|
+
|
|
292
|
+
const payment = getNativeSegwitPaymentFromAddressIndex(addressIndex, network);
|
|
293
|
+
|
|
294
|
+
if (!payment.address) throw new Error('Expected address to be defined');
|
|
295
|
+
return payment.address;
|
|
296
|
+
}
|
|
297
|
+
|
|
280
298
|
/**
|
|
281
299
|
* @deprecated
|
|
282
300
|
* Use `deriveRootBip32Keychain` in `@leather.io/crypto` instead
|
|
@@ -299,3 +317,27 @@ export function getPsbtTxOutputs(psbtTx: btc.Transaction): TransactionOutput[] {
|
|
|
299
317
|
for (let i = 0; i < outputsLength; i++) outputs.push(psbtTx.getOutput(i));
|
|
300
318
|
return outputs;
|
|
301
319
|
}
|
|
320
|
+
|
|
321
|
+
export function inferNetworkFromAddress(address: string): BitcoinNetworkModes {
|
|
322
|
+
if (address.startsWith('bc1')) return 'mainnet';
|
|
323
|
+
if (address.startsWith('tb1')) return 'testnet';
|
|
324
|
+
if (address.startsWith('bcrt1')) return 'regtest';
|
|
325
|
+
|
|
326
|
+
const firstChar = address[0];
|
|
327
|
+
|
|
328
|
+
if (firstChar === '1' || firstChar === '3') return 'mainnet';
|
|
329
|
+
if (firstChar === 'm' || firstChar === 'n') return 'testnet';
|
|
330
|
+
if (firstChar === '2') return 'testnet';
|
|
331
|
+
|
|
332
|
+
throw new Error('Invalid or unsupported Bitcoin address format');
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
export function inferPaymentTypeFromAddress(address: string): SupportedPaymentType {
|
|
336
|
+
if (address.startsWith('bc1q') || address.startsWith('tb1q') || address.startsWith('bcrt1q'))
|
|
337
|
+
return 'p2wpkh';
|
|
338
|
+
|
|
339
|
+
if (address.startsWith('bc1p') || address.startsWith('tb1p') || address.startsWith('bcrt1p'))
|
|
340
|
+
return 'p2tr';
|
|
341
|
+
|
|
342
|
+
throw new Error('Unable to infer payment type from address');
|
|
343
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { deriveRootKeychainFromMnemonic } from '@leather.io/crypto';
|
|
2
|
+
|
|
3
|
+
import { testMnemonic } from '../../../config/test-helpers';
|
|
4
|
+
import { lookupDerivationByAddress } from './lookup-derivation-by-address';
|
|
5
|
+
import { deriveTaprootAccount } from './p2tr-address-gen';
|
|
6
|
+
import { deriveNativeSegwitAccountFromRootKeychain } from './p2wpkh-address-gen';
|
|
7
|
+
|
|
8
|
+
describe(lookupDerivationByAddress.name, async () => {
|
|
9
|
+
const rootKeychain = await deriveRootKeychainFromMnemonic(testMnemonic);
|
|
10
|
+
|
|
11
|
+
const taprootKeychain = deriveTaprootAccount(rootKeychain, 'mainnet');
|
|
12
|
+
const nativeSegwitKeychain = deriveNativeSegwitAccountFromRootKeychain(rootKeychain, 'mainnet');
|
|
13
|
+
|
|
14
|
+
describe('Account zero', () => {
|
|
15
|
+
const firstTaprootAccountKeychain = taprootKeychain(0);
|
|
16
|
+
const firstNativeSegwitAccountKeychain = nativeSegwitKeychain(0);
|
|
17
|
+
|
|
18
|
+
const testSpecs = [
|
|
19
|
+
['bc1qzq7wjutswcp4r606tm0uxz9f9u3xx7cumxjeec', `m/84'/0'/0'/0/0`],
|
|
20
|
+
['bc1qp97df35dn0qqpe6q8xdzvzneqz9eljqh5zywgh', `m/84'/0'/0'/0/1`],
|
|
21
|
+
['bc1q8mkefvrphuetcn5g7katv88qnghl3tu9ztcs03', `m/84'/0'/0'/0/2`],
|
|
22
|
+
['bc1qpu0qy667fsmmn5ewwa6m3cf34htyjh8fn5hyhz', `m/84'/0'/0'/0/3`],
|
|
23
|
+
['bc1qnpyy7pnlxq4rxjzzfzvu9yfqdrtljl49x494fe', `m/84'/0'/0'/0/10`],
|
|
24
|
+
['bc1qgdk3qzr6h3z0krvgfvqr7rjyh36w8l30rp3ed3', `m/84'/0'/0'/0/20`],
|
|
25
|
+
['bc1q3ye9a8fgztr5yz0ze5sd83t3yr34p8ge2p0cuu', `m/84'/0'/0'/0/99`],
|
|
26
|
+
|
|
27
|
+
['bc1p0svqqvsaxtu5te5nxpq8qa9xg89rrenfg4xxvkhlqcu7hhrwzl9qgr0dya', `m/86'/0'/0'/0/0`],
|
|
28
|
+
['bc1p6jqgn9flqa6wne3tdnrs74qtay08s65j6ssytnm5n2qha8mg074q9quds8', `m/86'/0'/0'/0/1`],
|
|
29
|
+
['bc1pjx8encydxcr76dncd2j3vwsl46ta37y5gmmtlav6w0958ng8te7ssucq9r', `m/86'/0'/0'/0/2`],
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
test.each(testSpecs)('test address %s at index %s', (address, path) => {
|
|
33
|
+
const lookup = lookupDerivationByAddress({
|
|
34
|
+
taprootXpub: firstTaprootAccountKeychain.keychain.publicExtendedKey,
|
|
35
|
+
nativeSegwitXpub: firstNativeSegwitAccountKeychain.keychain.publicExtendedKey,
|
|
36
|
+
iterationLimit: 100,
|
|
37
|
+
});
|
|
38
|
+
expect(lookup(address).path).toEqual(path);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
describe('Account one and above', () => {
|
|
43
|
+
const firstTaprootAccountKeychain = taprootKeychain(1);
|
|
44
|
+
const firstNativeSegwitAccountKeychain = nativeSegwitKeychain(1);
|
|
45
|
+
|
|
46
|
+
test('that it finds the correct address', () => {
|
|
47
|
+
const lookup = lookupDerivationByAddress({
|
|
48
|
+
taprootXpub: firstTaprootAccountKeychain.keychain.publicExtendedKey,
|
|
49
|
+
nativeSegwitXpub: firstNativeSegwitAccountKeychain.keychain.publicExtendedKey,
|
|
50
|
+
iterationLimit: 10,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
expect(lookup('bc1qvgtk702cayady9wvkhvs5jn8c2ldurhazx9nzf').path).toBe(`m/84'/0'/1'/0/0`);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe('Failure case', () => {
|
|
58
|
+
const firstTaprootAccountKeychain = taprootKeychain(1);
|
|
59
|
+
const firstNativeSegwitAccountKeychain = nativeSegwitKeychain(1);
|
|
60
|
+
|
|
61
|
+
test('that it finds the correct address', () => {
|
|
62
|
+
const lookup = lookupDerivationByAddress({
|
|
63
|
+
taprootXpub: firstTaprootAccountKeychain.keychain.publicExtendedKey,
|
|
64
|
+
nativeSegwitXpub: firstNativeSegwitAccountKeychain.keychain.publicExtendedKey,
|
|
65
|
+
iterationLimit: 10,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
expect(lookup('bc1qvgsomefakeaddressitwontfind').status).toBe('failure');
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
});
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { HARDENED_OFFSET, HDKey } from '@scure/bip32';
|
|
2
|
+
|
|
3
|
+
import { createCounter } from '@leather.io/utils';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
getNativeSegwitAddress,
|
|
7
|
+
getTaprootAddress,
|
|
8
|
+
inferNetworkFromAddress,
|
|
9
|
+
inferPaymentTypeFromAddress,
|
|
10
|
+
whenSupportedPaymentType,
|
|
11
|
+
} from './bitcoin.utils';
|
|
12
|
+
import { makeTaprootAddressIndexDerivationPath } from './p2tr-address-gen';
|
|
13
|
+
import { makeNativeSegwitAddressIndexDerivationPath } from './p2wpkh-address-gen';
|
|
14
|
+
|
|
15
|
+
interface LookUpDerivationByAddressArgs {
|
|
16
|
+
taprootXpub: string;
|
|
17
|
+
nativeSegwitXpub: string;
|
|
18
|
+
iterationLimit: number;
|
|
19
|
+
}
|
|
20
|
+
export function lookupDerivationByAddress(args: LookUpDerivationByAddressArgs) {
|
|
21
|
+
const { taprootXpub, nativeSegwitXpub, iterationLimit } = args;
|
|
22
|
+
|
|
23
|
+
const taprootKeychain = HDKey.fromExtendedKey(taprootXpub);
|
|
24
|
+
const nativeSegwitKeychain = HDKey.fromExtendedKey(nativeSegwitXpub);
|
|
25
|
+
|
|
26
|
+
return (address: string) => {
|
|
27
|
+
const network = inferNetworkFromAddress(address);
|
|
28
|
+
const paymentType = inferPaymentTypeFromAddress(address);
|
|
29
|
+
|
|
30
|
+
const accountIndex = whenSupportedPaymentType(paymentType)({
|
|
31
|
+
p2tr: taprootKeychain.index - HARDENED_OFFSET,
|
|
32
|
+
p2wpkh: nativeSegwitKeychain.index - HARDENED_OFFSET,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
function getTaprootAddressAtIndex(index: number) {
|
|
36
|
+
return getTaprootAddress({ index, keychain: taprootKeychain, network });
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function getNativeSegwitAddressAtIndex(index: number) {
|
|
40
|
+
return getNativeSegwitAddress({ index, keychain: nativeSegwitKeychain, network });
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const paymentFn = whenSupportedPaymentType(paymentType)({
|
|
44
|
+
p2tr: getTaprootAddressAtIndex,
|
|
45
|
+
p2wpkh: getNativeSegwitAddressAtIndex,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const derivationPathFn = whenSupportedPaymentType(paymentType)({
|
|
49
|
+
p2tr: makeTaprootAddressIndexDerivationPath,
|
|
50
|
+
p2wpkh: makeNativeSegwitAddressIndexDerivationPath,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const count = createCounter();
|
|
54
|
+
const t0 = performance.now();
|
|
55
|
+
|
|
56
|
+
while (count.getValue() <= iterationLimit) {
|
|
57
|
+
const currentIndex = count.getValue();
|
|
58
|
+
|
|
59
|
+
const addressToCheck = paymentFn(currentIndex);
|
|
60
|
+
|
|
61
|
+
if (addressToCheck !== address) {
|
|
62
|
+
count.increment();
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const t1 = performance.now();
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
status: 'success',
|
|
70
|
+
duration: t1 - t0,
|
|
71
|
+
path: derivationPathFn(network, accountIndex, currentIndex),
|
|
72
|
+
} as const;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return { status: 'failure' } as const;
|
|
76
|
+
};
|
|
77
|
+
}
|
|
@@ -17,6 +17,7 @@ export function makeNativeSegwitAccountDerivationPath(
|
|
|
17
17
|
) {
|
|
18
18
|
return `m/84'/${getBitcoinCoinTypeIndexByNetwork(network)}'/${accountIndex}'`;
|
|
19
19
|
}
|
|
20
|
+
|
|
20
21
|
/** @deprecated Use makeNativeSegwitAccountDerivationPath */
|
|
21
22
|
export const getNativeSegwitAccountDerivationPath = makeNativeSegwitAccountDerivationPath;
|
|
22
23
|
|
|
@@ -27,6 +28,7 @@ export function makeNativeSegwitAddressIndexDerivationPath(
|
|
|
27
28
|
) {
|
|
28
29
|
return makeNativeSegwitAccountDerivationPath(network, accountIndex) + `/0/${addressIndex}`;
|
|
29
30
|
}
|
|
31
|
+
|
|
30
32
|
/** @deprecated Use makeNativeSegwitAddressIndexDerivationPath */
|
|
31
33
|
export const getNativeSegwitAddressIndexDerivationPath = makeNativeSegwitAddressIndexDerivationPath;
|
|
32
34
|
|
|
@@ -44,7 +46,7 @@ export function deriveNativeSegwitAccountFromRootKeychain(
|
|
|
44
46
|
});
|
|
45
47
|
}
|
|
46
48
|
|
|
47
|
-
export function
|
|
49
|
+
export function getNativeSegwitPaymentFromAddressIndex(
|
|
48
50
|
keychain: HDKey,
|
|
49
51
|
network: BitcoinNetworkModes
|
|
50
52
|
) {
|
|
@@ -67,6 +69,6 @@ export function deriveNativeSegwitReceiveAddressIndexZero({
|
|
|
67
69
|
const zeroAddressIndex = deriveAddressIndexZeroFromAccount(keychain);
|
|
68
70
|
return {
|
|
69
71
|
keychain: zeroAddressIndex,
|
|
70
|
-
payment:
|
|
72
|
+
payment: getNativeSegwitPaymentFromAddressIndex(zeroAddressIndex, network),
|
|
71
73
|
};
|
|
72
74
|
}
|