@avalabs/core-wallets-sdk 2.8.0-alpha.197
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/LICENSE +9 -0
- package/README.md +9 -0
- package/dist/index.d.ts +1794 -0
- package/dist/index.js +1 -0
- package/esm/Avalanche/index.d.ts +41 -0
- package/esm/Avalanche/index.js +1 -0
- package/esm/Avalanche/models.d.ts +173 -0
- package/esm/Avalanche/models.js +1 -0
- package/esm/Avalanche/providers/AbstractProvider.d.ts +39 -0
- package/esm/Avalanche/providers/AbstractProvider.js +1 -0
- package/esm/Avalanche/providers/JsonRpcProvider.d.ts +11 -0
- package/esm/Avalanche/providers/JsonRpcProvider.js +1 -0
- package/esm/Avalanche/providers/constants.d.ts +12 -0
- package/esm/Avalanche/providers/constants.js +1 -0
- package/esm/Avalanche/utils/addSignaturesToAvalancheTx.d.ts +16 -0
- package/esm/Avalanche/utils/addSignaturesToAvalancheTx.js +1 -0
- package/esm/Avalanche/utils/convertGlacierUtxo.d.ts +7 -0
- package/esm/Avalanche/utils/convertGlacierUtxo.js +1 -0
- package/esm/Avalanche/utils/createAvalancheEvmUnsignedTx.d.ts +11 -0
- package/esm/Avalanche/utils/createAvalancheEvmUnsignedTx.js +1 -0
- package/esm/Avalanche/utils/createAvalancheUnsignedTx.d.ts +13 -0
- package/esm/Avalanche/utils/createAvalancheUnsignedTx.js +1 -0
- package/esm/Avalanche/utils/digestMessage.d.ts +3 -0
- package/esm/Avalanche/utils/digestMessage.js +1 -0
- package/esm/Avalanche/utils/getAddressFromXpub.d.ts +14 -0
- package/esm/Avalanche/utils/getAddressFromXpub.js +1 -0
- package/esm/Avalanche/utils/getAddressPublicKeyFromXpub.d.ts +9 -0
- package/esm/Avalanche/utils/getAddressPublicKeyFromXpub.js +1 -0
- package/esm/Avalanche/utils/getAllUTXOs.d.ts +17 -0
- package/esm/Avalanche/utils/getAllUTXOs.js +1 -0
- package/esm/Avalanche/utils/getAssetBalance.d.ts +29 -0
- package/esm/Avalanche/utils/getAssetBalance.js +1 -0
- package/esm/Avalanche/utils/getChainAliasByChainId.js +1 -0
- package/esm/Avalanche/utils/getPchainUnixNow.d.ts +6 -0
- package/esm/Avalanche/utils/getPchainUnixNow.js +1 -0
- package/esm/Avalanche/utils/getStakeForAddresses.d.ts +5 -0
- package/esm/Avalanche/utils/getStakeForAddresses.js +1 -0
- package/esm/Avalanche/utils/getStakedAssetBalance.d.ts +16 -0
- package/esm/Avalanche/utils/getStakedAssetBalance.js +1 -0
- package/esm/Avalanche/utils/getTxOutputAddresses.js +1 -0
- package/esm/Avalanche/utils/getUnixNow.d.ts +6 -0
- package/esm/Avalanche/utils/getUnixNow.js +1 -0
- package/esm/Avalanche/utils/getUtxoInfo.d.ts +13 -0
- package/esm/Avalanche/utils/getUtxoInfo.js +1 -0
- package/esm/Avalanche/utils/getUtxosByTxFromGlacier.d.ts +13 -0
- package/esm/Avalanche/utils/getUtxosByTxFromGlacier.js +1 -0
- package/esm/Avalanche/utils/getVmByChainAlias.d.ts +3 -0
- package/esm/Avalanche/utils/getVmByChainAlias.js +1 -0
- package/esm/Avalanche/utils/getXpubFromMnemonic.d.ts +7 -0
- package/esm/Avalanche/utils/getXpubFromMnemonic.js +1 -0
- package/esm/Avalanche/utils/handleSubnetAuth.js +1 -0
- package/esm/Avalanche/utils/isBech32Address.d.ts +8 -0
- package/esm/Avalanche/utils/isBech32Address.js +1 -0
- package/esm/Avalanche/utils/parseAvalancheTx.d.ts +10 -0
- package/esm/Avalanche/utils/parseAvalancheTx.js +1 -0
- package/esm/Avalanche/utils/parsers/index.js +1 -0
- package/esm/Avalanche/utils/parsers/parseAddDelegatorTx.js +1 -0
- package/esm/Avalanche/utils/parsers/parseAddPermissionlessDelegatorTx.js +1 -0
- package/esm/Avalanche/utils/parsers/parseAddPermissionlessValidatorTx.js +1 -0
- package/esm/Avalanche/utils/parsers/parseAddSubnetValidorTx.js +1 -0
- package/esm/Avalanche/utils/parsers/parseAddValidatorTx.js +1 -0
- package/esm/Avalanche/utils/parsers/parseBaseTx.js +1 -0
- package/esm/Avalanche/utils/parsers/parseCreateChainTx.js +1 -0
- package/esm/Avalanche/utils/parsers/parseCreateSubnetTx.js +1 -0
- package/esm/Avalanche/utils/parsers/parseExportTx.js +1 -0
- package/esm/Avalanche/utils/parsers/parseImportTx.js +1 -0
- package/esm/Avalanche/utils/parsers/parseRemoveSubnetValidatorTx.js +1 -0
- package/esm/Avalanche/utils/parsers/parseTransferSubnetOwnershipTx.js +1 -0
- package/esm/Avalanche/utils/parsers/parseTransformSubnetTx.js +1 -0
- package/esm/Avalanche/utils/parsers/utils/chainIdToVm.js +1 -0
- package/esm/Avalanche/utils/parsers/utils/getTransferableAmount.js +1 -0
- package/esm/Avalanche/utils/populateCredential.d.ts +9 -0
- package/esm/Avalanche/utils/populateCredential.js +1 -0
- package/esm/Avalanche/utils/signedTxToHex.d.ts +5 -0
- package/esm/Avalanche/utils/signedTxToHex.js +1 -0
- package/esm/Avalanche/utils/sortUTXOs.d.ts +14 -0
- package/esm/Avalanche/utils/sortUTXOs.js +1 -0
- package/esm/Avalanche/utils/txSizeLimits.d.ts +34 -0
- package/esm/Avalanche/utils/txSizeLimits.js +1 -0
- package/esm/Avalanche/utils/verifyDerivationPath.d.ts +7 -0
- package/esm/Avalanche/utils/verifyDerivationPath.js +1 -0
- package/esm/Avalanche/wallets/AddressWallet.d.ts +45 -0
- package/esm/Avalanche/wallets/AddressWallet.js +1 -0
- package/esm/Avalanche/wallets/SimpleSigner.d.ts +62 -0
- package/esm/Avalanche/wallets/SimpleSigner.js +1 -0
- package/esm/Avalanche/wallets/StaticSigner.d.ts +39 -0
- package/esm/Avalanche/wallets/StaticSigner.js +1 -0
- package/esm/Avalanche/wallets/WalletAbstract.d.ts +131 -0
- package/esm/Avalanche/wallets/WalletAbstract.js +1 -0
- package/esm/Avalanche/wallets/WalletVoid.d.ts +40 -0
- package/esm/Avalanche/wallets/WalletVoid.js +1 -0
- package/esm/Avalanche/wallets/ledger/LedgerSigner.d.ts +49 -0
- package/esm/Avalanche/wallets/ledger/LedgerSigner.js +1 -0
- package/esm/Avalanche/wallets/ledger/SimpleLedgerSigner.d.ts +32 -0
- package/esm/Avalanche/wallets/ledger/SimpleLedgerSigner.js +1 -0
- package/esm/Avalanche/wallets/ledger/ZondaxProvider.js +1 -0
- package/esm/Avalanche/wallets/ledger/constants.js +1 -0
- package/esm/Avalanche/wallets/ledger/getLedgerProvider.d.ts +10 -0
- package/esm/Avalanche/wallets/ledger/getLedgerProvider.js +1 -0
- package/esm/Avalanche/wallets/ledger/isObsidianApp.d.ts +5 -0
- package/esm/Avalanche/wallets/ledger/isObsidianApp.js +1 -0
- package/esm/Avalanche/wallets/ledger/models.d.ts +37 -0
- package/esm/Avalanche/wallets/legacy/LedgerWallet.d.ts +41 -0
- package/esm/Avalanche/wallets/legacy/LedgerWallet.js +1 -0
- package/esm/Avalanche/wallets/legacy/MnemonicWallet.d.ts +30 -0
- package/esm/Avalanche/wallets/legacy/MnemonicWallet.js +1 -0
- package/esm/Avalanche/wallets/legacy/MnemonicWalletVoid.d.ts +83 -0
- package/esm/Avalanche/wallets/legacy/MnemonicWalletVoid.js +1 -0
- package/esm/Avalanche/wallets/models.d.ts +35 -0
- package/esm/BitcoinVM/models.d.ts +77 -0
- package/esm/BitcoinVM/providers/BitcoinProvider.d.ts +42 -0
- package/esm/BitcoinVM/providers/BitcoinProvider.js +1 -0
- package/esm/BitcoinVM/providers/BitcoinProviderAbstract.d.ts +63 -0
- package/esm/BitcoinVM/providers/BitcoinProviderAbstract.js +1 -0
- package/esm/BitcoinVM/providers/models.js +1 -0
- package/esm/BitcoinVM/providers/utils/parseAddressFullTx.js +1 -0
- package/esm/BitcoinVM/utils/addEncodedSigToPsbt.d.ts +5 -0
- package/esm/BitcoinVM/utils/addEncodedSigToPsbt.js +1 -0
- package/esm/BitcoinVM/utils/createPSBTV2.d.ts +10 -0
- package/esm/BitcoinVM/utils/createPSBTV2.js +1 -0
- package/esm/BitcoinVM/utils/createPsbt.d.ts +12 -0
- package/esm/BitcoinVM/utils/createPsbt.js +1 -0
- package/esm/BitcoinVM/utils/createTransferTx.d.ts +20 -0
- package/esm/BitcoinVM/utils/createTransferTx.js +1 -0
- package/esm/BitcoinVM/utils/createWalletPolicy.d.ts +5 -0
- package/esm/BitcoinVM/utils/createWalletPolicy.js +1 -0
- package/esm/BitcoinVM/utils/filterDuplicateUTXOs.js +1 -0
- package/esm/BitcoinVM/utils/formatAddressForNetworkBech32.d.ts +10 -0
- package/esm/BitcoinVM/utils/formatAddressForNetworkBech32.js +1 -0
- package/esm/BitcoinVM/utils/getBech32Address.d.ts +10 -0
- package/esm/BitcoinVM/utils/getBech32Address.js +1 -0
- package/esm/BitcoinVM/utils/getBech32AddressFromXPub.d.ts +11 -0
- package/esm/BitcoinVM/utils/getBech32AddressFromXPub.js +1 -0
- package/esm/BitcoinVM/utils/getMaxTransferAmount.d.ts +13 -0
- package/esm/BitcoinVM/utils/getMaxTransferAmount.js +1 -0
- package/esm/BitcoinVM/utils/getTransferTxDetails.d.ts +17 -0
- package/esm/BitcoinVM/utils/getTransferTxDetails.js +1 -0
- package/esm/BitcoinVM/utils/psbt2ToPsbt0.d.ts +15 -0
- package/esm/BitcoinVM/utils/psbt2ToPsbt0.js +1 -0
- package/esm/BitcoinVM/utils/selectUtxos.d.ts +22 -0
- package/esm/BitcoinVM/utils/selectUtxos.js +1 -0
- package/esm/BitcoinVM/utils/sumUTXOs.js +1 -0
- package/esm/BitcoinVM/wallets/BitcoinWallet.d.ts +44 -0
- package/esm/BitcoinVM/wallets/BitcoinWallet.js +1 -0
- package/esm/BitcoinVM/wallets/BitcoinWalletAbstract.d.ts +72 -0
- package/esm/BitcoinVM/wallets/BitcoinWalletAbstract.js +1 -0
- package/esm/BitcoinVM/wallets/BitcoinWalletLedger.d.ts +34 -0
- package/esm/BitcoinVM/wallets/BitcoinWalletLedger.js +1 -0
- package/esm/BitcoinVM/wallets/BitcoinWalletVoid.d.ts +12 -0
- package/esm/BitcoinVM/wallets/BitcoinWalletVoid.js +1 -0
- package/esm/BitcoinVM/wallets/models.d.ts +8 -0
- package/esm/EVM/LedgerSigner.d.ts +23 -0
- package/esm/EVM/LedgerSigner.js +1 -0
- package/esm/EVM/constants.d.ts +8 -0
- package/esm/EVM/constants.js +1 -0
- package/esm/EVM/utils/blockPolling.d.ts +12 -0
- package/esm/EVM/utils/blockPolling.js +1 -0
- package/esm/EVM/utils/getAddressFromXPub.d.ts +9 -0
- package/esm/EVM/utils/getAddressFromXPub.js +1 -0
- package/esm/EVM/utils/getAddressPrivateKeyFromXPriv.d.ts +9 -0
- package/esm/EVM/utils/getAddressPrivateKeyFromXPriv.js +1 -0
- package/esm/EVM/utils/getAddressPublicKeyFromXPub.d.ts +9 -0
- package/esm/EVM/utils/getAddressPublicKeyFromXPub.js +1 -0
- package/esm/EVM/utils/getAppEth.d.ts +10 -0
- package/esm/EVM/utils/getAppEth.js +1 -0
- package/esm/EVM/utils/getBtcAddressFromPubKey.d.ts +10 -0
- package/esm/EVM/utils/getBtcAddressFromPubKey.js +1 -0
- package/esm/EVM/utils/getEvmAddressFromPubKey.d.ts +3 -0
- package/esm/EVM/utils/getEvmAddressFromPubKey.js +1 -0
- package/esm/EVM/utils/getVoidSigner.d.ts +10 -0
- package/esm/EVM/utils/getVoidSigner.js +1 -0
- package/esm/EVM/utils/getWalletFromMnemonic.d.ts +13 -0
- package/esm/EVM/utils/getWalletFromMnemonic.js +1 -0
- package/esm/EVM/utils/getXpubFromMnemonic.d.ts +7 -0
- package/esm/EVM/utils/getXpubFromMnemonic.js +1 -0
- package/esm/EVM/utils/jsonRpcBatchProvider.d.ts +31 -0
- package/esm/EVM/utils/jsonRpcBatchProvider.js +1 -0
- package/esm/EVM/utils/multicallABI.js +1 -0
- package/esm/index.d.ts +43 -0
- package/esm/index.js +1 -0
- package/esm/utils/binarySearch.js +1 -0
- package/esm/utils/getAddressDerivationPath.d.ts +11 -0
- package/esm/utils/getAddressDerivationPath.js +1 -0
- package/esm/utils/getLedgerAppInfo.d.ts +13 -0
- package/esm/utils/getLedgerAppInfo.js +1 -0
- package/esm/utils/getLedgerExtendedPublicKey.d.ts +12 -0
- package/esm/utils/getLedgerExtendedPublicKey.js +1 -0
- package/esm/utils/getPubKeyFromTransport.d.ts +7 -0
- package/esm/utils/getPubKeyFromTransport.js +1 -0
- package/esm/utils/getPublicKeyFromPrivateKey.d.ts +8 -0
- package/esm/utils/getPublicKeyFromPrivateKey.js +1 -0
- package/esm/utils/omitUndefinedKeys.d.ts +3 -0
- package/esm/utils/omitUndefinedKeys.js +1 -0
- package/esm/utils/openLedgerApp.d.ts +9 -0
- package/esm/utils/openLedgerApp.js +1 -0
- package/esm/utils/quitLedgerApp.d.ts +10 -0
- package/esm/utils/quitLedgerApp.js +1 -0
- package/package.json +58 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Transaction } from '@ledgerhq/hw-app-btc/lib/types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Custom Bitcoin UTXO interface.
|
|
5
|
+
*/
|
|
6
|
+
interface BitcoinInputUTXO {
|
|
7
|
+
txHash: string;
|
|
8
|
+
txHex?: string;
|
|
9
|
+
index: number;
|
|
10
|
+
value: number;
|
|
11
|
+
script: string;
|
|
12
|
+
blockHeight: number;
|
|
13
|
+
confirmations: number;
|
|
14
|
+
confirmedTime?: string;
|
|
15
|
+
}
|
|
16
|
+
interface BitcoinInputUTXOWithOptionalScript extends Omit<BitcoinInputUTXO, 'script'> {
|
|
17
|
+
script?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Used for defining outputs when creating a transaction.
|
|
21
|
+
*/
|
|
22
|
+
interface BitcoinOutputUTXO {
|
|
23
|
+
address: string;
|
|
24
|
+
value: number;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Ledger needs UTXOs organized like this when signing.
|
|
28
|
+
*/
|
|
29
|
+
type BitcoinLedgerInputUTXO = [
|
|
30
|
+
tx: Transaction,
|
|
31
|
+
outputIndex: number,
|
|
32
|
+
script: string | null | undefined,
|
|
33
|
+
sequence: number | null | undefined
|
|
34
|
+
];
|
|
35
|
+
/**
|
|
36
|
+
* An interface to simplify historic BTC transactions.
|
|
37
|
+
*/
|
|
38
|
+
interface BitcoinHistoryTx {
|
|
39
|
+
hash: string;
|
|
40
|
+
isSender: boolean;
|
|
41
|
+
addresses: string[];
|
|
42
|
+
fee: number;
|
|
43
|
+
block: number;
|
|
44
|
+
amount: number;
|
|
45
|
+
confirmations: number;
|
|
46
|
+
containsMultisig: boolean;
|
|
47
|
+
receivedTime: number;
|
|
48
|
+
confirmedTime?: number;
|
|
49
|
+
}
|
|
50
|
+
interface BitcoinTx {
|
|
51
|
+
hash: string;
|
|
52
|
+
fees: number;
|
|
53
|
+
block: number;
|
|
54
|
+
amount: number;
|
|
55
|
+
confirmations: number;
|
|
56
|
+
blockTime: number;
|
|
57
|
+
addresses: string[];
|
|
58
|
+
inputs: {
|
|
59
|
+
txid: string;
|
|
60
|
+
vout: number;
|
|
61
|
+
sequence: number;
|
|
62
|
+
n: number;
|
|
63
|
+
addresses: string[];
|
|
64
|
+
isAddress: boolean;
|
|
65
|
+
value: number;
|
|
66
|
+
}[];
|
|
67
|
+
outputs: {
|
|
68
|
+
addresses: string[];
|
|
69
|
+
value: number;
|
|
70
|
+
n: number;
|
|
71
|
+
spent: boolean;
|
|
72
|
+
hex: string;
|
|
73
|
+
isAddress: boolean;
|
|
74
|
+
}[];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export { BitcoinHistoryTx, BitcoinInputUTXO, BitcoinInputUTXOWithOptionalScript, BitcoinLedgerInputUTXO, BitcoinOutputUTXO, BitcoinTx };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { BitcoinProviderAbstract } from './BitcoinProviderAbstract.js';
|
|
2
|
+
import { Network } from 'bitcoinjs-lib';
|
|
3
|
+
import { BitcoinInputUTXOWithOptionalScript, BitcoinInputUTXO, BitcoinTx, BitcoinHistoryTx } from '../models.js';
|
|
4
|
+
|
|
5
|
+
declare class BitcoinProvider extends BitcoinProviderAbstract {
|
|
6
|
+
#private;
|
|
7
|
+
private readonly isMainnet;
|
|
8
|
+
private readonly extraParams?;
|
|
9
|
+
constructor(isMainnet?: boolean, apiKey?: string, explorerUrl?: string, nodeUrl?: string, extraParams?: Record<string, string> | undefined);
|
|
10
|
+
getTxHex(txHash: string): Promise<string>;
|
|
11
|
+
getUTXOs(address: string, withScripts?: boolean): Promise<{
|
|
12
|
+
confirmed: BitcoinInputUTXOWithOptionalScript[];
|
|
13
|
+
unconfirmed: BitcoinInputUTXOWithOptionalScript[];
|
|
14
|
+
}>;
|
|
15
|
+
getScriptsForUtxos(utxos: BitcoinInputUTXOWithOptionalScript[]): Promise<BitcoinInputUTXO[]>;
|
|
16
|
+
private _parseUtxo;
|
|
17
|
+
getBalances(address: string): Promise<{
|
|
18
|
+
available: bigint;
|
|
19
|
+
pending: bigint;
|
|
20
|
+
final: bigint;
|
|
21
|
+
}>;
|
|
22
|
+
getChainHeight(): Promise<number>;
|
|
23
|
+
getFeeRates(): Promise<{
|
|
24
|
+
low: number;
|
|
25
|
+
medium: number;
|
|
26
|
+
high: number;
|
|
27
|
+
}>;
|
|
28
|
+
getNetwork(): Network;
|
|
29
|
+
issueRawTx(tx: string): Promise<string>;
|
|
30
|
+
getTransaction(hash: string): Promise<BitcoinTx>;
|
|
31
|
+
/**
|
|
32
|
+
* Returns the last 25 transactions
|
|
33
|
+
*/
|
|
34
|
+
getTxHistory(address: string): Promise<BitcoinHistoryTx[]>;
|
|
35
|
+
waitForTx(txHash: string, { maxAttempts, attempt, pollInterval, }?: {
|
|
36
|
+
maxAttempts?: number;
|
|
37
|
+
attempt?: number;
|
|
38
|
+
pollInterval?: number;
|
|
39
|
+
}): Promise<BitcoinTx>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export { BitcoinProvider };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{BitcoinProviderAbstract as t}from"./BitcoinProviderAbstract.js";import{networks as e}from"bitcoinjs-lib";import{HttpClient as a}from"@avalabs/core-utils-sdk";import{URL_EXPLORER_MAINNET as s,URL_EXPLORER_TESTNET as r,URL_NODE_MAINNET as i,URL_NODE_TESTNET as n}from"./models.js";import{parseAddressFullTx as o}from"./utils/parseAddressFullTx.js";class l extends t{constructor(t=!0,e,o,l,m){super(),this.isMainnet=t,this.extraParams=m;const c=e?{headers:{"api-key":e}}:{},p=t?s:r;this.#t=new a(o||p,c);const u=t?i:n;this.#e=new a(l||u,c)}#t;#e;async#a(t){return this.isMainnet?(await Promise.all(t.map((t=>this.#e.post("",t,{},this.extraParams))))).flat():this.#e.post("",t,{},this.extraParams)}async getTxHex(t){return(await this.#t.post(`/api/v2/tx/${t}`,{},{},this.extraParams)).hex}async getUTXOs(t,e=!0){const a=await this.#t.post(`/api/v2/utxo/${t}`,{},{},this.extraParams);if(!a?.length)return{confirmed:[],unconfirmed:[]};const s=a.map(this._parseUtxo),r=t=>({confirmed:t.filter((t=>t.confirmations>0)),unconfirmed:t.filter((t=>0===t.confirmations))});if(!e)return r(s);return r(await this.getScriptsForUtxos(s))}async getScriptsForUtxos(t){const[e,a]=t.reduce((([t,e],a)=>a.script?[[...t,a],e]:[t,[...e,a]]),[[],[]]),s=a.map(((t,e)=>({jsonrpc:"2.0",method:"gettxout",params:[t.txHash,t.index],id:`${e}`}))),r=s.length?(await this.#a(s)).sort(((t,e)=>Number(t.id)-Number(e.id))):[];return[...e,...a.map(((t,e)=>({...t,script:r[e]?.result?.scriptPubKey.hex})))]}_parseUtxo(t){return{...t,txHash:t.txid,index:t.vout,value:Number(t.value),blockHeight:t.height,script:t.script,confirmations:t.confirmations}}async getBalances(t){const e=await this.#t.post(`/api/v2/address/${t}`,{},{},this.extraParams);return{available:BigInt(e.balance),pending:BigInt(e.unconfirmedBalance),final:BigInt(e.balance)+BigInt(e.unconfirmedBalance)}}async getChainHeight(){return(await this.#e.post("",{jsonrpc:"2.0",id:"nownodes",method:"getblockcount",params:[]},{},this.extraParams)).result}async getFeeRates(){const t={jsonrpc:"2.0",method:"estimatesmartfee"},e=await this.#a([{...t,id:"1",params:[1]},{...t,id:"2",params:[3]},{...t,id:"3",params:[7]}]).then((t=>t.sort(((t,e)=>Number(t.id)-Number(e.id))).map((t=>1e8*(t.result?.feerate??0)))));return{high:Math.round(e[0]/1024)||1,medium:Math.round(e[1]/1024)||1,low:Math.floor(e[2]/1024)||1}}getNetwork(){return this.isMainnet?e.bitcoin:e.testnet}async issueRawTx(t){return await this.#e.post("",{jsonrpc:"2.0",id:"nownodes",method:"sendrawtransaction",params:[t]},{},this.extraParams).then((t=>t.result))}async getTransaction(t){const e=await this.#t.post(`/api/v2/tx/${t}`,{},{},this.extraParams);return{block:e.blockHeight,fees:Number(e.fees),confirmations:e.confirmations,amount:Number(e.value),hash:e.txid,addresses:Array.from(new Set([...e.vin.map((t=>t.addresses||[])).flat(),...e.vout.map((t=>t.addresses||[])).flat()])),blockTime:e.blockTime,inputs:[...e.vin.map((t=>({...t,value:Number(t.value)})))],outputs:[...e.vout.map((t=>({...t,value:Number(t.value)})))]}}async getTxHistory(t){const e=await this.#t.post(`/api/v2/address/${t}`,{},{},this.extraParams);return await Promise.allSettled(e.txids?.slice(0,25).map((async e=>{try{const a=await this.#t.post(`/api/v2/tx/${e}`,{},{},this.extraParams);return o(t,a)}catch(t){console.log(`Unable to parse full tx ${e}.`)}}))).then((t=>t.map((t=>"fulfilled"===t.status&&t.value?t.value:void 0)).filter((t=>void 0!==t))))}async waitForTx(t,{maxAttempts:e=20,attempt:a=1,pollInterval:s=500}={}){try{return await this.getTransaction(t)}catch(r){if(a>=e)throw r;return await new Promise((t=>setTimeout(t,s))),this.waitForTx(t,{maxAttempts:e,attempt:a+1,pollInterval:s})}}}export{l as BitcoinProvider};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Network } from 'bitcoinjs-lib';
|
|
2
|
+
import { BitcoinInputUTXOWithOptionalScript, BitcoinTx } from '../models.js';
|
|
3
|
+
|
|
4
|
+
declare abstract class BitcoinProviderAbstract {
|
|
5
|
+
/**
|
|
6
|
+
* Returns the UTXOs owned by the given address.
|
|
7
|
+
* @param address
|
|
8
|
+
*/
|
|
9
|
+
abstract getUTXOs(address: string, withScripts: boolean): Promise<{
|
|
10
|
+
confirmed: BitcoinInputUTXOWithOptionalScript[];
|
|
11
|
+
unconfirmed: BitcoinInputUTXOWithOptionalScript[];
|
|
12
|
+
}>;
|
|
13
|
+
/**
|
|
14
|
+
* Returns the connected network.
|
|
15
|
+
*/
|
|
16
|
+
abstract getNetwork(): Network;
|
|
17
|
+
/**
|
|
18
|
+
* Get the current chain height.
|
|
19
|
+
*/
|
|
20
|
+
abstract getChainHeight(): Promise<number>;
|
|
21
|
+
/**
|
|
22
|
+
* Returns the available balance for the user in satoshis.
|
|
23
|
+
*/
|
|
24
|
+
abstract getBalances(address: string): Promise<{
|
|
25
|
+
available: bigint;
|
|
26
|
+
pending: bigint;
|
|
27
|
+
final: bigint;
|
|
28
|
+
}>;
|
|
29
|
+
/**
|
|
30
|
+
* Returns available (confirmed) UTXOs and their total balance for the given address.
|
|
31
|
+
* @address Address to get UTXOs of.
|
|
32
|
+
*/
|
|
33
|
+
getUtxoBalance(address: string, withScripts?: boolean): Promise<{
|
|
34
|
+
balance: number;
|
|
35
|
+
balanceUnconfirmed: number;
|
|
36
|
+
utxos: BitcoinInputUTXOWithOptionalScript[];
|
|
37
|
+
utxosUnconfirmed: BitcoinInputUTXOWithOptionalScript[];
|
|
38
|
+
}>;
|
|
39
|
+
/**
|
|
40
|
+
* Given a transaction hash, return the base information of the transaction
|
|
41
|
+
*/
|
|
42
|
+
abstract getTransaction(hash: string): Promise<BitcoinTx>;
|
|
43
|
+
/**
|
|
44
|
+
* Given a transaction hash, return the whole transaction in hex format.
|
|
45
|
+
* @param txHash
|
|
46
|
+
*/
|
|
47
|
+
abstract getTxHex(txHash: string): Promise<string>;
|
|
48
|
+
/**
|
|
49
|
+
* Issues the given transaction to the bitcoin network
|
|
50
|
+
* @param tx
|
|
51
|
+
*/
|
|
52
|
+
abstract issueRawTx(tx: string): Promise<string>;
|
|
53
|
+
/**
|
|
54
|
+
* Returns the suggested fee rate in satoshis per byte.
|
|
55
|
+
*/
|
|
56
|
+
abstract getFeeRates(): Promise<{
|
|
57
|
+
high: number;
|
|
58
|
+
medium: number;
|
|
59
|
+
low: number;
|
|
60
|
+
}>;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export { BitcoinProviderAbstract };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{sumUTXOs as n}from"../utils/sumUTXOs.js";class e{async getUtxoBalance(e,o=!0){const c=await this.getUTXOs(e,o);return{balance:n(c.confirmed),balanceUnconfirmed:n(c.unconfirmed),utxos:c.confirmed,utxosUnconfirmed:c.unconfirmed}}}export{e as BitcoinProviderAbstract};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const t="https://btc.nownodes.io",o="https://btcbook.nownodes.io",n="https://btc-testnet.nownodes.io",s="https://btcbook-testnet.nownodes.io";export{o as URL_EXPLORER_MAINNET,s as URL_EXPLORER_TESTNET,t as URL_NODE_MAINNET,n as URL_NODE_TESTNET};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(e,s){const i=s.vin.filter((s=>s.addresses?.includes(e))),n=s.vout.filter((s=>s.addresses?.includes(e))),t=s.vin.filter((s=>!s.addresses?.includes(e))),d=s.vout.filter((s=>!s.addresses?.includes(e))),r=i.reduce(((e,s)=>e+BigInt(s.value)),0n),l=n.reduce(((e,s)=>e+BigInt(s.value)),0n),a=r>l;let o=l-r;a&&(o+=BigInt(s.fees));const c=t.map((e=>e.addresses||[])).flat(),f=d.map((e=>e.addresses||[])).flat(),u=a?f:c,m=u.filter(((e,s)=>u.indexOf(e)===s)),v=n.filter((e=>(e.addresses?.length||0)>1)).length>0;return{addresses:m,isSender:a,block:s.blockHeight,fee:Number(s.fees),confirmations:s.confirmations,amount:Number(o),hash:s.txid,containsMultisig:v,receivedTime:s.blockTime,confirmedTime:s.confirmations>0?s.blockTime:void 0}}export{e as parseAddressFullTx};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function t(t,n,p,u){const a=[{pubkey:n,signature:t}];p.updateInput(u,{partialSig:a})}export{t as addEncodedSigToPsbt};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BitcoinInputUTXO, BitcoinOutputUTXO } from '../models.js';
|
|
2
|
+
import { Network } from 'bitcoinjs-lib';
|
|
3
|
+
import { PsbtV2 } from 'ledger-bitcoin';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Used with the new BTC Ledger app.
|
|
7
|
+
*/
|
|
8
|
+
declare function createPSBTV2(ins: BitcoinInputUTXO[], outs: BitcoinOutputUTXO[], network: Network, masterFingerprint: Buffer, signerPubkey: Buffer, signerPath: string): PsbtV2;
|
|
9
|
+
|
|
10
|
+
export { createPSBTV2 };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{address as t}from"bitcoinjs-lib";import{PsbtV2 as e}from"ledger-bitcoin";import{pathStringToArray as o}from"@ledgerhq/hw-app-btc/lib/bip32";function r(r,n,s,u,i,p){const x=new e;return x.setGlobalPsbtVersion(2),x.setGlobalTxVersion(2),x.setGlobalInputCount(r.length),x.setGlobalOutputCount(n.length),r.forEach(((t,e)=>{if(!t.txHex)throw new Error("Input tx hex is not given");x.setInputPreviousTxId(e,Buffer.from(t.txHash,"hex").reverse()),x.setInputOutputIndex(e,t.index),x.setInputNonWitnessUtxo(e,Buffer.from(t.txHex,"hex")),x.setInputWitnessUtxo(e,t.value,Buffer.from(t.script,"hex")),x.setInputBip32Derivation(e,i,u,o(p))})),n.forEach(((e,o)=>{const r=t.toOutputScript(e.address,s);x.setOutputAmount(o,e.value),x.setOutputScript(o,r)})),x}export{r as createPSBTV2};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Network, Psbt } from 'bitcoinjs-lib';
|
|
2
|
+
import { BitcoinInputUTXO, BitcoinOutputUTXO } from '../models.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Create an unsigned transaction.
|
|
6
|
+
* @param inputs The input UTXOs for the transaction.
|
|
7
|
+
* @param outputs The output UTXOs for the transaction.
|
|
8
|
+
* @param provider The provider for the tx network.
|
|
9
|
+
*/
|
|
10
|
+
declare function createPsbt(inputs: BitcoinInputUTXO[], outputs: BitcoinOutputUTXO[], network: Network): Psbt;
|
|
11
|
+
|
|
12
|
+
export { createPsbt };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Psbt as e}from"bitcoinjs-lib";function t(t,r,a){const s=new e({network:a});return t.forEach((e=>{s.addInput({hash:e.txHash,index:e.index,witnessUtxo:{script:Buffer.from(e.script,"hex"),value:e.value}})})),r.forEach((e=>{s.addOutput({value:e.value,address:e.address})})),s}export{t as createPsbt};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { BitcoinInputUTXO, BitcoinOutputUTXO } from '../models.js';
|
|
2
|
+
import { Network, Psbt } from 'bitcoinjs-lib';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Create an unsigned bitcoin transfer transaction.
|
|
6
|
+
* @param to Destination address.
|
|
7
|
+
* @param changeAddress Change address.
|
|
8
|
+
* @param amount Amount to send.
|
|
9
|
+
* @param feeRate Satoshis per byte.
|
|
10
|
+
* @param sourceUtxos UTXOs to construct the transaction from.
|
|
11
|
+
* @param network The network the transaction will be on.
|
|
12
|
+
*/
|
|
13
|
+
declare function createTransferTx(to: string, changeAddress: string, amount: number, feeRate: number, sourceUtxos: BitcoinInputUTXO[], network: Network): {
|
|
14
|
+
fee: number;
|
|
15
|
+
inputs?: BitcoinInputUTXO[];
|
|
16
|
+
outputs?: BitcoinOutputUTXO[];
|
|
17
|
+
psbt?: Psbt;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export { createTransferTx };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createPsbt as t}from"./createPsbt.js";import{selectUtxos as e}from"./selectUtxos.js";import{filterDuplicateUTXOs as o}from"./filterDuplicateUTXOs.js";function s(s,r,n,c,i,p){const u=o(i),f=e(s,r,n,c,u);return f.inputs?{...f,psbt:t(f.inputs,f.outputs,p)}:(console.log("Unable to construct transaction, fee needed: ",f.fee),f)}export{s as createTransferTx};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{DefaultWalletPolicy as e,WalletPolicy as n}from"ledger-bitcoin";function o(o,r,t,i){const p=new e("wpkh(@0/**)",`[${o}/44'/60'/${r}']${t}`);return new n(i,"wpkh(@0/**)",p.keys)}export{o as createWalletPolicy};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function t(t){const n=[];return t.filter((t=>{const r=t.txHash+t.index.toString();return!n.includes(r)&&(n.push(r),!0)}))}export{t as filterDuplicateUTXOs};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Network } from 'bitcoinjs-lib';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Format the given address for the given network
|
|
5
|
+
* @param address Bech32 address to format
|
|
6
|
+
* @param network Network the new bech32 address will belong to
|
|
7
|
+
*/
|
|
8
|
+
declare function formatAddressForNetworkBech32(address: string, network: Network): string;
|
|
9
|
+
|
|
10
|
+
export { formatAddressForNetworkBech32 };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{address as o}from"bitcoinjs-lib";function t(t,r){const c=o.fromBech32(t);return o.toBech32(c.data,c.version,r.bech32)}export{t as formatAddressForNetworkBech32};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{payments as r}from"bitcoinjs-lib";function o(o,t){return r.p2wpkh({pubkey:o,network:t}).address}export{o as getBech32Address};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Network } from 'bitcoinjs-lib';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Return the Bech32 address of the given address index from an xpub.
|
|
5
|
+
* @param xpub The extended public key of `m/44'/60'/0'`
|
|
6
|
+
* @param accountIndex The target address index.
|
|
7
|
+
* @param network Which network should the address be on.
|
|
8
|
+
*/
|
|
9
|
+
declare function getBech32AddressFromXPub(xpub: string, accountIndex: number, network: Network): string;
|
|
10
|
+
|
|
11
|
+
export { getBech32AddressFromXPub };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"@ledgerhq/hw-app-eth";import"ethers";import"@avalabs/avalanchejs";import"hdkey";import"buffer";import"@openzeppelin/contracts/build/contracts/ERC20.json";import"bip32";import{getAddressPublicKeyFromXPub as t}from"../../EVM/utils/getAddressPublicKeyFromXPub.js";import"bip39";import{getBech32Address as r}from"./getBech32Address.js";import"@avalabs/core-utils-sdk";import"@ledgerhq/hw-transport";import"@metamask/eth-sig-util";function o(o,e,i){const p=t(o,e);return r(p,i)}export{o as getBech32AddressFromXPub};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BitcoinInputUTXOWithOptionalScript } from '../models.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Calculate the maximum amount that can be sent in satoshis using the given UTXO set and parameters.
|
|
5
|
+
* @param ins UTXOs that can be consumed.
|
|
6
|
+
* @param to Destination address.
|
|
7
|
+
* @param changeAddress Change address.
|
|
8
|
+
* @param feeRate Fee rate in satoshis per byte.
|
|
9
|
+
* @returns Maximum transferable amount in satoshis.
|
|
10
|
+
*/
|
|
11
|
+
declare function getMaxTransferAmount(ins: BitcoinInputUTXOWithOptionalScript[], to: string, changeAddress: string, feeRate: number): number;
|
|
12
|
+
|
|
13
|
+
export { getMaxTransferAmount };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{selectUtxos as t}from"./selectUtxos.js";import{sumUTXOs as o}from"./sumUTXOs.js";function r(r,s,e,n){const f=o(r);if(!f)return 0;const{fee:m}=t(s,e,f,n,r);return f-m}export{r as getMaxTransferAmount};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BitcoinInputUTXO, BitcoinInputUTXOWithOptionalScript, BitcoinOutputUTXO } from '../models.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Create an unsigned bitcoin transfer transaction.
|
|
5
|
+
* @param to Destination address.
|
|
6
|
+
* @param changeAddress Change address.
|
|
7
|
+
* @param amount Amount to send.
|
|
8
|
+
* @param feeRate Satoshis per byte.
|
|
9
|
+
* @param sourceUtxos UTXOs to construct the transaction from.
|
|
10
|
+
*/
|
|
11
|
+
declare function getTransferTxDetails<InputUtxo extends BitcoinInputUTXO | BitcoinInputUTXOWithOptionalScript = BitcoinInputUTXO>(to: string, changeAddress: string, amount: number, feeRate: number, sourceUtxos: InputUtxo[]): {
|
|
12
|
+
fee: number;
|
|
13
|
+
inputs?: InputUtxo[];
|
|
14
|
+
outputs?: BitcoinOutputUTXO[];
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export { getTransferTxDetails };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{selectUtxos as t}from"./selectUtxos.js";import{filterDuplicateUTXOs as e}from"./filterDuplicateUTXOs.js";function o(o,n,r,s,c){const i=e(c),f=t(o,n,r,s,i);return f.inputs||console.log("Unable to construct transaction, fee needed: ",f.fee),f}export{o as getTransferTxDetails};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { PsbtV2 } from 'ledger-bitcoin';
|
|
2
|
+
import { Network, Psbt } from 'bitcoinjs-lib';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Convert the given PSBTV2 object to bitcoinjs PSBT object. This is not a full feature
|
|
6
|
+
* conversion and only focuses on P2WPKH input conversion, which are the input types supported by
|
|
7
|
+
* the core wallets.
|
|
8
|
+
* @param psbt2
|
|
9
|
+
* @param network
|
|
10
|
+
* @param signerPub
|
|
11
|
+
* @param signerPath
|
|
12
|
+
*/
|
|
13
|
+
declare function psbt2ToPsbt0(psbt2: PsbtV2, network: Network, signerPub: Buffer, signerPath: string): Psbt;
|
|
14
|
+
|
|
15
|
+
export { psbt2ToPsbt0 };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Psbt as t,address as n}from"bitcoinjs-lib";function e(e,u,i,o){const p=new t({network:u}),r=e.getGlobalInputCount(),s=e.getGlobalOutputCount();for(let t=0;t<r;t++){const n=e.getInputWitnessUtxo(t),u=e.getInputBip32Derivation(t,i);p.addInput({nonWitnessUtxo:e.getInputNonWitnessUtxo(t),witnessUtxo:n?{value:n.amount,script:n.scriptPubKey}:void 0,hash:e.getInputPreviousTxid(t),index:e.getInputOutputIndex(t),bip32Derivation:u?[{path:o,pubkey:i,masterFingerprint:u.masterFingerprint}]:void 0})}for(let t=0;t<s;t++)p.addOutput({value:e.getOutputAmount(t),address:n.fromOutputScript(e.getOutputScript(t),u)});return p}export{e as psbt2ToPsbt0};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { BitcoinInputUTXO, BitcoinInputUTXOWithOptionalScript, BitcoinOutputUTXO } from '../models.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Uses coinselect to select the input and output utxos for the given information.
|
|
5
|
+
* Returns undefined if the transaction can not be completed.
|
|
6
|
+
* @param to Destination address.
|
|
7
|
+
* @param changeAddress Change address.
|
|
8
|
+
* @param amount Amount to send in satoshis.
|
|
9
|
+
* @param feeRate Satoshis per byte.
|
|
10
|
+
* @param sourceUtxos UTXOs to pick from to construct the transaction.
|
|
11
|
+
*/
|
|
12
|
+
declare function selectUtxos<InputUtxo extends BitcoinInputUTXO | BitcoinInputUTXOWithOptionalScript = BitcoinInputUTXO>(to: string, changeAddress: string, amount: number, feeRate: number, sourceUtxos: InputUtxo[]): {
|
|
13
|
+
fee: any;
|
|
14
|
+
inputs?: undefined;
|
|
15
|
+
outputs?: undefined;
|
|
16
|
+
} | {
|
|
17
|
+
inputs: InputUtxo[];
|
|
18
|
+
outputs: BitcoinOutputUTXO[];
|
|
19
|
+
fee: any;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export { selectUtxos };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"coinselect";function t(t,u,s,n,o){const r=[{address:t,value:s}],{inputs:p,outputs:f,fee:i}=e(o,r,n);if(!p||!f)return{fee:i};const a=[f[0]],c=f[1];return c&&a.push({address:u,value:c.value}),{inputs:p,outputs:a,fee:i}}export{t as selectUtxos};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(e){return e.reduce(((e,r)=>e+r.value),0)}export{e as sumUTXOs};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import * as bitcoinjs_lib from 'bitcoinjs-lib';
|
|
2
|
+
import { ECPairInterface, Psbt } from 'bitcoinjs-lib';
|
|
3
|
+
import { BitcoinProviderAbstract } from '../providers/BitcoinProviderAbstract.js';
|
|
4
|
+
import { BitcoinWalletAbstract } from './BitcoinWalletAbstract.js';
|
|
5
|
+
import { BitcoinInputUTXO, BitcoinOutputUTXO } from '../models.js';
|
|
6
|
+
import { HDNodeWallet } from 'ethers';
|
|
7
|
+
import { DerivationPath } from '../../EVM/constants.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A wallet instance for the given private key. Can sign transactions.
|
|
11
|
+
*/
|
|
12
|
+
declare class BitcoinWallet extends BitcoinWalletAbstract {
|
|
13
|
+
keypair: ECPairInterface;
|
|
14
|
+
constructor(privKey: Buffer, provider: BitcoinProviderAbstract);
|
|
15
|
+
/**
|
|
16
|
+
*
|
|
17
|
+
* @param mnemonic The mnemonic phrase to derive the wallet from.
|
|
18
|
+
* @param accountIndex Used when deriving the private key from mnemonic. The path used is `m/44'/60'/0'/0/n` where `n` is the account index.
|
|
19
|
+
* @param provider
|
|
20
|
+
* @param derivationSpec Sets how account paths are generated. BIP44 (Default) or LedgerLive.
|
|
21
|
+
*/
|
|
22
|
+
static fromMnemonic(mnemonic: string, accountIndex: number, provider: BitcoinProviderAbstract, derivationSpec?: DerivationPath): Promise<BitcoinWallet>;
|
|
23
|
+
/**
|
|
24
|
+
* Create a transaction from the given inputs and outputs, and sign it.
|
|
25
|
+
* @remarks Signs all inputs.
|
|
26
|
+
* @param ins Array of input UTXOs to consume
|
|
27
|
+
* @param outs Array of output UTXOs to create.
|
|
28
|
+
*/
|
|
29
|
+
signTx(ins: BitcoinInputUTXO[], outs: BitcoinOutputUTXO[]): Promise<bitcoinjs_lib.Transaction>;
|
|
30
|
+
/**
|
|
31
|
+
* Create a bitcoin wallet using the private key of an Ethers wallet.
|
|
32
|
+
* @param wallet An Ethers wallet instance that has a private key.
|
|
33
|
+
* @param prov Bitcoin provider.
|
|
34
|
+
*/
|
|
35
|
+
static fromEthersWallet(wallet: HDNodeWallet, prov: BitcoinProviderAbstract): BitcoinWallet;
|
|
36
|
+
/**
|
|
37
|
+
* Sings a given PSBT and returns the transaction.
|
|
38
|
+
* @remarks Signs all inputs.
|
|
39
|
+
* @param tx
|
|
40
|
+
*/
|
|
41
|
+
signPsbt(tx: Psbt): bitcoinjs_lib.Transaction;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export { BitcoinWallet };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{ECPair as t}from"bitcoinjs-lib";import{BitcoinWalletAbstract as r}from"./BitcoinWalletAbstract.js";import{createPsbt as e}from"../utils/createPsbt.js";import"coinselect";import"@ledgerhq/hw-app-eth";import"ethers";import{getAddressDerivationPath as i}from"../../utils/getAddressDerivationPath.js";import"@avalabs/avalanchejs";import"hdkey";import"buffer";import{DerivationPath as o}from"../../EVM/constants.js";import"@openzeppelin/contracts/build/contracts/ERC20.json";import{fromSeed as s}from"bip32";import{validateMnemonic as n,mnemonicToSeed as a}from"bip39";import"@avalabs/core-utils-sdk";import"@ledgerhq/hw-transport";import"@metamask/eth-sig-util";import"ledger-bitcoin";import"@ledgerhq/hw-app-btc/lib/bip32";class p extends r{keypair;constructor(r,e){const i=t.fromPrivateKey(r);super(i.publicKey,e),this.keypair=i}static async fromMnemonic(t,r,e,m=o.BIP44){if(r<0)throw new Error("Account index must be >= 0");if(!n(t))throw new Error("Invalid mnemonic phrase.");const l=await a(t),c=s(l),h=i(r,m,"EVM"),f=c.derivePath(h);if(!f.privateKey)throw new Error("Unable to derive private key from the given mnemonic.");return new p(f.privateKey,e)}signTx(t,r){const i=e(t,r,this.provider.getNetwork());return Promise.resolve(this.signPsbt(i))}static fromEthersWallet(t,r){const e=t.privateKey;if(!e)throw new Error("Unable to get private key from ethers wallet.");const i=Buffer.from(e.substring(2),"hex");return new p(i,r)}signPsbt(t){return t.signAllInputs(this.keypair),t.validateSignaturesOfAllInputs(),t.finalizeAllInputs(),t.extractTransaction()}}export{p as BitcoinWallet};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import * as bitcoinjs_lib from 'bitcoinjs-lib';
|
|
2
|
+
import { ECPairInterface, Transaction } from 'bitcoinjs-lib';
|
|
3
|
+
import { BitcoinInputUTXO, BitcoinOutputUTXO, BitcoinInputUTXOWithOptionalScript } from '../models.js';
|
|
4
|
+
import { BitcoinProviderAbstract } from '../providers/BitcoinProviderAbstract.js';
|
|
5
|
+
|
|
6
|
+
declare abstract class BitcoinWalletAbstract {
|
|
7
|
+
protected pubkey: Buffer;
|
|
8
|
+
protected provider: BitcoinProviderAbstract;
|
|
9
|
+
ecPair: ECPairInterface;
|
|
10
|
+
abstract signTx(ins: BitcoinInputUTXO[], outs: BitcoinOutputUTXO[]): Promise<Transaction>;
|
|
11
|
+
/**
|
|
12
|
+
* Return legacy P2PKH address.
|
|
13
|
+
*/
|
|
14
|
+
getAddressP2PKH(): string | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Get the Bech32 address.
|
|
17
|
+
* @link https://allprivatekeys.com/bitcoin-address-format
|
|
18
|
+
*/
|
|
19
|
+
getAddressBech32(): string;
|
|
20
|
+
protected constructor(pubkey: Buffer, provider: BitcoinProviderAbstract);
|
|
21
|
+
/**
|
|
22
|
+
* Returns the UTXOs owned by this address
|
|
23
|
+
*/
|
|
24
|
+
getUTXOs(): Promise<{
|
|
25
|
+
confirmed: BitcoinInputUTXOWithOptionalScript[];
|
|
26
|
+
unconfirmed: BitcoinInputUTXOWithOptionalScript[];
|
|
27
|
+
}>;
|
|
28
|
+
/**
|
|
29
|
+
* Returns the available balance in satoshis.
|
|
30
|
+
* @remarks Returned balances might not match the sum of available UTXOs if the wallet has pending transactions.
|
|
31
|
+
* Use `getUTXOBalance` to get the balance from available UTXOs.
|
|
32
|
+
*/
|
|
33
|
+
getBalances(): Promise<{
|
|
34
|
+
available: bigint;
|
|
35
|
+
pending: bigint;
|
|
36
|
+
final: bigint;
|
|
37
|
+
}>;
|
|
38
|
+
/**
|
|
39
|
+
* Returns available UTXOs and their total balance.
|
|
40
|
+
*/
|
|
41
|
+
getUtxoBalance(): Promise<{
|
|
42
|
+
balance: number;
|
|
43
|
+
balanceUnconfirmed: number;
|
|
44
|
+
utxos: BitcoinInputUTXOWithOptionalScript[];
|
|
45
|
+
utxosUnconfirmed: BitcoinInputUTXOWithOptionalScript[];
|
|
46
|
+
}>;
|
|
47
|
+
/**
|
|
48
|
+
* Connects the wallet to the given provider.
|
|
49
|
+
* @param provider
|
|
50
|
+
*/
|
|
51
|
+
connect(provider: BitcoinProviderAbstract): void;
|
|
52
|
+
/**
|
|
53
|
+
* Returns the current connected provider.
|
|
54
|
+
*/
|
|
55
|
+
getProvider(): BitcoinProviderAbstract;
|
|
56
|
+
getPublicKey(): Buffer;
|
|
57
|
+
/**
|
|
58
|
+
* Create an unsigned transaction. Change will be returned to this wallet.
|
|
59
|
+
* @param to
|
|
60
|
+
* @param amount
|
|
61
|
+
* @param feeRate
|
|
62
|
+
* @param sourceUTXOs
|
|
63
|
+
*/
|
|
64
|
+
createTransferTx(to: string, amount: number, feeRate: number, sourceUTXOs: BitcoinInputUTXO[]): {
|
|
65
|
+
fee: number;
|
|
66
|
+
inputs?: BitcoinInputUTXO[] | undefined;
|
|
67
|
+
outputs?: BitcoinOutputUTXO[] | undefined;
|
|
68
|
+
psbt?: bitcoinjs_lib.Psbt | undefined;
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export { BitcoinWalletAbstract };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{ECPair as e,payments as r}from"bitcoinjs-lib";import{createTransferTx as t}from"../utils/createTransferTx.js";import{getBech32Address as s}from"../utils/getBech32Address.js";class i{constructor(r,t){this.pubkey=r,this.provider=t;try{this.ecPair=e.fromPublicKey(r)}catch(e){throw new Error("Not a valid public key.")}}ecPair;getAddressP2PKH(){return r.p2pkh({pubkey:this.ecPair.publicKey,network:this.provider.getNetwork()}).address}getAddressBech32(){return s(this.ecPair.publicKey,this.provider.getNetwork())}async getUTXOs(){return this.provider.getUTXOs(this.getAddressBech32(),!0)}async getBalances(){return this.provider.getBalances(this.getAddressBech32())}async getUtxoBalance(){return this.provider.getUtxoBalance(this.getAddressBech32())}connect(e){this.provider=e}getProvider(){return this.provider}getPublicKey(){return this.ecPair.publicKey}createTransferTx(e,r,s,i){const c=this.getAddressBech32();return t(e,c,r,s,i,this.provider.getNetwork())}}export{i as BitcoinWalletAbstract};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import * as bitcoinjs_lib from 'bitcoinjs-lib';
|
|
2
|
+
import { BitcoinProviderAbstract } from '../providers/BitcoinProviderAbstract.js';
|
|
3
|
+
import { BitcoinWalletAbstract } from './BitcoinWalletAbstract.js';
|
|
4
|
+
import Transport from '@ledgerhq/hw-transport';
|
|
5
|
+
import { BitcoinInputUTXO, BitcoinOutputUTXO } from '../models.js';
|
|
6
|
+
import { WalletPolicyDetails } from './models.js';
|
|
7
|
+
|
|
8
|
+
declare class BitcoinLedgerWallet extends BitcoinWalletAbstract {
|
|
9
|
+
private derivationPath;
|
|
10
|
+
protected transport: Transport;
|
|
11
|
+
private walletPolicyDetails;
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* @param publicKey Public key of the address
|
|
15
|
+
* @param derivationPath BIP44 derivation path of the publickey/address
|
|
16
|
+
* @param provider
|
|
17
|
+
* @param transport Ledger transport instance.
|
|
18
|
+
*/
|
|
19
|
+
constructor(publicKey: Buffer, derivationPath: string, provider: BitcoinProviderAbstract, transport: Transport, walletPolicyDetails: WalletPolicyDetails);
|
|
20
|
+
/**
|
|
21
|
+
* Update the ledger transport used by this wallet.
|
|
22
|
+
* @param t
|
|
23
|
+
*/
|
|
24
|
+
setTransport(t: Transport): void;
|
|
25
|
+
/**
|
|
26
|
+
* Creates a transaction with the given inputs & outputs and signs using the ledger.
|
|
27
|
+
* @param ins Input UTXOs for this transaction. Must be P2WPKH.
|
|
28
|
+
* @param outs Output UTXOs for this transaction.
|
|
29
|
+
* @param ledgerConfig
|
|
30
|
+
*/
|
|
31
|
+
signTx(ins: BitcoinInputUTXO[], outs: BitcoinOutputUTXO[]): Promise<bitcoinjs_lib.Transaction>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { BitcoinLedgerWallet };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{BitcoinWalletAbstract as t}from"./BitcoinWalletAbstract.js";import i from"ledger-bitcoin";import"bitcoinjs-lib";import"coinselect";import"@ledgerhq/hw-app-eth";import"ethers";import"@avalabs/avalanchejs";import"hdkey";import"buffer";import"@openzeppelin/contracts/build/contracts/ERC20.json";import"bip32";import"bip39";import"@avalabs/core-utils-sdk";import"@ledgerhq/hw-transport";import"@metamask/eth-sig-util";import{createPSBTV2 as r}from"../utils/createPSBTV2.js";import{psbt2ToPsbt0 as e}from"../utils/psbt2ToPsbt0.js";class s extends t{constructor(t,i,r,e,s){super(t,r),this.derivationPath=i,this.transport=e,this.walletPolicyDetails=s}setTransport(t){this.transport=t}async signTx(t,s){const a=function(t){return new i(t)}(this.transport),o=this.ecPair.publicKey,n=this.provider.getNetwork(),p=await a.getMasterFingerprint(),l=r(t,s,n,Buffer.from(p,"hex"),o,this.derivationPath),{policy:c,hmac:h}=this.walletPolicyDetails,m=await a.signPsbt(l,c,h),u=e(l,n,o,this.derivationPath);if(m.forEach((t=>{const[i,r]=t;u.updateInput(i,{partialSig:[{signature:r.signature,pubkey:r.pubkey}]})})),!u.validateSignaturesOfAllInputs())throw new Error("Failed to validate signatures");return u.finalizeAllInputs(),u.extractTransaction()}}export{s as BitcoinLedgerWallet};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BitcoinWalletAbstract } from './BitcoinWalletAbstract.js';
|
|
2
|
+
import { BitcoinProviderAbstract } from '../providers/BitcoinProviderAbstract.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A wallet class for readonly wallet instances.
|
|
6
|
+
*/
|
|
7
|
+
declare class BitcoinWalletVoid extends BitcoinWalletAbstract {
|
|
8
|
+
constructor(publicKey: Buffer, provider: BitcoinProviderAbstract);
|
|
9
|
+
signTx(tx: any): any;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export { BitcoinWalletVoid };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{BitcoinWalletAbstract as t}from"./BitcoinWalletAbstract.js";class r extends t{constructor(t,r){super(t,r)}signTx(t){throw new Error("Void wallets can not sign.")}}export{r as BitcoinWalletVoid};
|