@xchainjs/xchain-bitcoin 0.23.4 → 0.23.7
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/README.md +6 -6
- package/lib/client.d.ts +2 -42
- package/lib/clientKeystore.d.ts +48 -0
- package/lib/clientLedger.d.ts +21 -0
- package/lib/const.d.ts +2 -1
- package/lib/index.d.ts +3 -1
- package/lib/index.esm.js +17930 -116
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +17935 -116
- package/lib/index.js.map +1 -1
- package/package.json +9 -5
package/README.md
CHANGED
|
@@ -99,20 +99,20 @@ import { SochainNetwork, SochainProvider } from '@xchainjs/xchain-utxo-provider
|
|
|
99
99
|
import { Network, UtxoClientParams } from '@xchainjs/xchain-client'
|
|
100
100
|
|
|
101
101
|
// override with your API key
|
|
102
|
-
SochainDataProviders[Network.Mainnet].apiKey = '
|
|
102
|
+
SochainDataProviders[Network.Mainnet].apiKey = 'YOUR_SOCHAIN_API_KEY'
|
|
103
103
|
|
|
104
104
|
// or set in env variables so default config can access.
|
|
105
|
-
`SOCHAIN_API_KEY={
|
|
106
|
-
`BLOCKCYPHER_API_KEY={
|
|
105
|
+
`SOCHAIN_API_KEY={YOUR_SOCHAIN_API_KEY}`
|
|
106
|
+
`BLOCKCYPHER_API_KEY={YOUR_BLOCKCYPHER_API_KEY}`
|
|
107
107
|
//Default config can access.
|
|
108
|
-
process.env
|
|
109
|
-
process.env
|
|
108
|
+
process.env.BLOCKCYPHER_API_KEY
|
|
109
|
+
process.env.SOCHAIN_API_KEY
|
|
110
110
|
|
|
111
111
|
//overridde the default init params with your onfig
|
|
112
112
|
const initParams: UtxoClientParams = {
|
|
113
113
|
...defaultBTCParams,
|
|
114
114
|
dataProviders: [SochainDataProviders, BlockcypherDataProviders]// use sochain first and blockcypher as fallback
|
|
115
|
-
phrase: process.env.
|
|
115
|
+
phrase: process.env.PHRASE,
|
|
116
116
|
}
|
|
117
117
|
const btcClient = new Client(sochainParams)
|
|
118
118
|
|
package/lib/client.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { AssetInfo, FeeRate, PreparedTx,
|
|
2
|
+
import { AssetInfo, FeeRate, PreparedTx, TxParams, UTXO, UTXOClient, UtxoClientParams } from '@xchainjs/xchain-client';
|
|
3
3
|
import { Address } from '@xchainjs/xchain-util';
|
|
4
4
|
import * as Bitcoin from 'bitcoinjs-lib';
|
|
5
5
|
export declare const defaultBTCParams: UtxoClientParams;
|
|
6
6
|
/**
|
|
7
7
|
* Custom Bitcoin client
|
|
8
8
|
*/
|
|
9
|
-
declare class Client extends UTXOClient {
|
|
9
|
+
declare abstract class Client extends UTXOClient {
|
|
10
10
|
/**
|
|
11
11
|
* Constructor
|
|
12
12
|
* Client is initialised with network type
|
|
@@ -14,39 +14,11 @@ declare class Client extends UTXOClient {
|
|
|
14
14
|
* @param {UtxoClientParams} params
|
|
15
15
|
*/
|
|
16
16
|
constructor(params?: UtxoClientParams);
|
|
17
|
-
/**
|
|
18
|
-
* @deprecated this function eventually will be removed use getAddressAsync instead
|
|
19
|
-
*/
|
|
20
|
-
getAddress(index?: number): Address;
|
|
21
|
-
/**
|
|
22
|
-
* Get the current address.
|
|
23
|
-
*
|
|
24
|
-
* Generates a network-specific key-pair by first converting the buffer to a Wallet-Import-Format (WIF)
|
|
25
|
-
* The address is then decoded into type P2WPKH and returned.
|
|
26
|
-
*
|
|
27
|
-
* @returns {Address} The current address.
|
|
28
|
-
*
|
|
29
|
-
* @throws {"Phrase must be provided"} Thrown if phrase has not been set before.
|
|
30
|
-
* @throws {"Address not defined"} Thrown if failed creating account from phrase.
|
|
31
|
-
*/
|
|
32
|
-
getAddressAsync(index?: number): Promise<string>;
|
|
33
17
|
/**
|
|
34
18
|
*
|
|
35
19
|
* @returns BTC asset info
|
|
36
20
|
*/
|
|
37
21
|
getAssetInfo(): AssetInfo;
|
|
38
|
-
/**
|
|
39
|
-
* @private
|
|
40
|
-
* Get private key.
|
|
41
|
-
*
|
|
42
|
-
* Private function to get keyPair from the this.phrase
|
|
43
|
-
*
|
|
44
|
-
* @param {string} phrase The phrase to be used for generating privkey
|
|
45
|
-
* @returns {ECPairInterface} The privkey generated from the given phrase
|
|
46
|
-
*
|
|
47
|
-
* @throws {"Could not get private key from phrase"} Throws an error if failed creating BTC keys from the given phrase
|
|
48
|
-
* */
|
|
49
|
-
private getBtcKeys;
|
|
50
22
|
/**
|
|
51
23
|
* Validate the given address.
|
|
52
24
|
*
|
|
@@ -54,7 +26,6 @@ declare class Client extends UTXOClient {
|
|
|
54
26
|
* @returns {boolean} `true` or `false`
|
|
55
27
|
*/
|
|
56
28
|
validateAddress(address: string): boolean;
|
|
57
|
-
protected getSuggestedFeeRate(): Promise<FeeRate>;
|
|
58
29
|
/**
|
|
59
30
|
* Compile memo.
|
|
60
31
|
*
|
|
@@ -71,17 +42,6 @@ declare class Client extends UTXOClient {
|
|
|
71
42
|
* @returns {number} The fee amount.
|
|
72
43
|
*/
|
|
73
44
|
protected getFeeFromUtxos(inputs: UTXO[], feeRate: FeeRate, data?: Buffer | null): number;
|
|
74
|
-
/**
|
|
75
|
-
* Transfer BTC.
|
|
76
|
-
*
|
|
77
|
-
* @param {TxParams&FeeRate} params The transfer options.
|
|
78
|
-
* @returns {TxHash} The transaction hash.
|
|
79
|
-
*
|
|
80
|
-
* @throws {"memo too long"} Thrown if memo longer than 80 chars.
|
|
81
|
-
*/
|
|
82
|
-
transfer(params: TxParams & {
|
|
83
|
-
feeRate?: FeeRate;
|
|
84
|
-
}): Promise<TxHash>;
|
|
85
45
|
/**
|
|
86
46
|
*
|
|
87
47
|
* @param param0
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { FeeRate, TxHash, TxParams } from '@xchainjs/xchain-client';
|
|
2
|
+
import { Address } from '@xchainjs/xchain-util';
|
|
3
|
+
import { Client } from './client';
|
|
4
|
+
/**
|
|
5
|
+
* Custom Bitcoin client
|
|
6
|
+
*/
|
|
7
|
+
declare class ClientKeystore extends Client {
|
|
8
|
+
/**
|
|
9
|
+
* @deprecated this function eventually will be removed use getAddressAsync instead
|
|
10
|
+
*/
|
|
11
|
+
getAddress(index?: number): Address;
|
|
12
|
+
/**
|
|
13
|
+
* Get the current address.
|
|
14
|
+
*
|
|
15
|
+
* Generates a network-specific key-pair by first converting the buffer to a Wallet-Import-Format (WIF)
|
|
16
|
+
* The address is then decoded into type P2WPKH and returned.
|
|
17
|
+
*
|
|
18
|
+
* @returns {Address} The current address.
|
|
19
|
+
*
|
|
20
|
+
* @throws {"Phrase must be provided"} Thrown if phrase has not been set before.
|
|
21
|
+
* @throws {"Address not defined"} Thrown if failed creating account from phrase.
|
|
22
|
+
*/
|
|
23
|
+
getAddressAsync(index?: number): Promise<string>;
|
|
24
|
+
/**
|
|
25
|
+
* @private
|
|
26
|
+
* Get private key.
|
|
27
|
+
*
|
|
28
|
+
* Private function to get keyPair from the this.phrase
|
|
29
|
+
*
|
|
30
|
+
* @param {string} phrase The phrase to be used for generating privkey
|
|
31
|
+
* @returns {ECPairInterface} The privkey generated from the given phrase
|
|
32
|
+
*
|
|
33
|
+
* @throws {"Could not get private key from phrase"} Throws an error if failed creating BTC keys from the given phrase
|
|
34
|
+
* */
|
|
35
|
+
private getBtcKeys;
|
|
36
|
+
/**
|
|
37
|
+
* Transfer BTC.
|
|
38
|
+
*
|
|
39
|
+
* @param {TxParams&FeeRate} params The transfer options.
|
|
40
|
+
* @returns {TxHash} The transaction hash.
|
|
41
|
+
*
|
|
42
|
+
* @throws {"memo too long"} Thrown if memo longer than 80 chars.
|
|
43
|
+
*/
|
|
44
|
+
transfer(params: TxParams & {
|
|
45
|
+
feeRate?: FeeRate;
|
|
46
|
+
}): Promise<TxHash>;
|
|
47
|
+
}
|
|
48
|
+
export { ClientKeystore };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import AppBtc from '@ledgerhq/hw-app-btc';
|
|
2
|
+
import { FeeRate, TxHash, TxParams, UtxoClientParams } from '@xchainjs/xchain-client';
|
|
3
|
+
import { Address } from '@xchainjs/xchain-util';
|
|
4
|
+
import { Client } from './client';
|
|
5
|
+
/**
|
|
6
|
+
* Custom Ledger Bitcoin client
|
|
7
|
+
*/
|
|
8
|
+
declare class ClientLedger extends Client {
|
|
9
|
+
private transport;
|
|
10
|
+
private app;
|
|
11
|
+
constructor(params: UtxoClientParams & {
|
|
12
|
+
transport: any;
|
|
13
|
+
});
|
|
14
|
+
getApp(): Promise<AppBtc>;
|
|
15
|
+
getAddress(): string;
|
|
16
|
+
getAddressAsync(index?: number): Promise<Address>;
|
|
17
|
+
transfer(params: TxParams & {
|
|
18
|
+
feeRate?: FeeRate;
|
|
19
|
+
}): Promise<TxHash>;
|
|
20
|
+
}
|
|
21
|
+
export { ClientLedger };
|
package/lib/const.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { Asset } from '@xchainjs/xchain-util';
|
|
|
8
8
|
export declare const MIN_TX_FEE = 1000;
|
|
9
9
|
export declare const BTC_DECIMAL = 8;
|
|
10
10
|
export declare const LOWER_FEE_BOUND = 1;
|
|
11
|
-
export declare const UPPER_FEE_BOUND =
|
|
11
|
+
export declare const UPPER_FEE_BOUND = 1000;
|
|
12
12
|
export declare const BTC_SYMBOL = "\u20BF";
|
|
13
13
|
export declare const BTC_SATOSHI_SYMBOL = "\u26A1";
|
|
14
14
|
/**
|
|
@@ -31,3 +31,4 @@ export declare const blockstreamExplorerProviders: {
|
|
|
31
31
|
export declare const SochainDataProviders: UtxoOnlineDataProviders;
|
|
32
32
|
export declare const HaskoinDataProviders: UtxoOnlineDataProviders;
|
|
33
33
|
export declare const BlockcypherDataProviders: UtxoOnlineDataProviders;
|
|
34
|
+
export declare const BitgoProviders: UtxoOnlineDataProviders;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export * from './types';
|
|
2
|
-
export
|
|
2
|
+
export { ClientKeystore as Client } from './clientKeystore';
|
|
3
|
+
export { ClientLedger } from './clientLedger';
|
|
4
|
+
export { defaultBTCParams } from './client';
|
|
3
5
|
export * from './const';
|
|
4
6
|
export { getPrefix, validateAddress } from './utils';
|