@xchainjs/xchain-doge 0.1.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/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ # v.0.1.0 (2022-01-15)
2
+
3
+ First release
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 THORChain
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,73 @@
1
+ # `@xchainjs/xchain-doge`
2
+
3
+ ## Modules
4
+
5
+ - `client` - Custom client for communicating with Doge using [BIP39](https://github.com/bitcoinjs/bip39) [bitcoinjs-lib](https://github.com/bitcoinjs/bitcoinjs-lib) and [WIF](https://github.com/bitcoinjs/wif)
6
+
7
+ ## Installation
8
+
9
+ ```
10
+ yarn add @xchainjs/xchain-doge
11
+ ```
12
+
13
+ Following peer dependencies have to be installed into your project. These are not included in `@xchainjs/xchain-doge`.
14
+
15
+ ```
16
+ yarn add @xchainjs/xchain-client @xchainjs/xchain-crypto @xchainjs/xchain-util axios bitcoinjs-lib coininfo wif
17
+ ```
18
+
19
+ ## Service Providers
20
+
21
+ This package uses the following service providers:
22
+
23
+ | Function | Service | Notes |
24
+ | --------------------------- | ----------- | -------------------------------------------------------------------------------- |
25
+ | Balances | Sochain | https://sochain.com/api#get-balance |
26
+ | Transaction history | Sochain | https://sochain.com/api#get-display-data-address, https://sochain.com/api#get-tx |
27
+ | Transaction details by hash | Sochain | https://sochain.com/api#get-tx |
28
+ | Transaction fees | BlockCypher | https://api.blockcypher.com/v1/doge/main |
29
+ | Transaction broadcast | BlockCypher | https://api.blockcypher.com/v1/doge/main/txs/push |
30
+ | Explorer | Blockchair | https://blockchair.com/dogecoin |
31
+
32
+ Sochain API rate limits: https://sochain.com/api#rate-limits (300 requests/minute)
33
+
34
+ BlockCypher API rate limits: https://api.blockcypher.com/v1/doge/main (5 requests/second)
35
+
36
+ ## Usage
37
+
38
+ Initialize client and use class methods:
39
+
40
+ ```
41
+ import { Client, Network } from '../src/client'
42
+
43
+ // Create a new client interface
44
+ const dogeClient = new Client({ network: Network.Testnet })
45
+
46
+ // Set phrase
47
+ dogeClient.setPhrase('phrase here')
48
+
49
+ // Get address
50
+ const address = dogeClient.getAddress()
51
+
52
+ // Get balance
53
+ const balance = await dogeClient.getBalance()
54
+
55
+ // Transfer with feeRate
56
+ const txid = await dogeClient.transfer({ asset: AssetDoge, recipient: 'recipient address here', amount: baseAmount(100, DOGE_DECIMAL), feeRate: 1 })
57
+
58
+ // Transfer with default feeRate (default is `fast`)
59
+ const txid = await dogeClient.transfer({ asset: AssetDoge, recipient: 'recipient address here', amount: baseAmount(100, DOGE_DECIMAL) })
60
+
61
+ // Get fee estimations
62
+ const { fast, fastest, average } = await dogeClient.getFees()
63
+
64
+ // Get feeRate estimations
65
+ const { fast, fastest, average } = await dogeClient.getFeeRates()
66
+
67
+ // Search transactions
68
+ const transactions = await dogeClient.getTransactions({ address: 'address here', limit: 4 })
69
+
70
+ // Get a transaction with a given txId/hash
71
+ const txData = await dogeClient.getTransactionData('b660ee07167cfa32681e2623f3a29dc64a089cabd9a3a07dd17f9028ac956eb8')
72
+
73
+ ```
@@ -0,0 +1,13 @@
1
+ import { Network } from '@xchainjs/xchain-client/lib';
2
+ /**
3
+ * Get Dogecoin suggested transaction fee.
4
+ *
5
+ * @returns {number} The Dogecoin suggested transaction fee per bytes in sat.
6
+ */
7
+ export declare const getSuggestedTxFee: ({ blockcypherUrl }: {
8
+ blockcypherUrl: string;
9
+ }) => Promise<number>;
10
+ export declare const getSendTxUrl: ({ blockcypherUrl, network }: {
11
+ blockcypherUrl: string;
12
+ network: Network;
13
+ }) => string;
@@ -0,0 +1,121 @@
1
+ import { Address, Balance, Fee, FeeRate, Tx, TxHash, TxHistoryParams, TxParams, TxsPage, UTXOClient, XChainClientParams } from '@xchainjs/xchain-client';
2
+ export declare type DogecoinClientParams = XChainClientParams & {
3
+ sochainUrl?: string;
4
+ nodeUrl?: string;
5
+ blockcypherUrl?: string;
6
+ };
7
+ /**
8
+ * Custom Dogecoin client
9
+ */
10
+ declare class Client extends UTXOClient {
11
+ private sochainUrl;
12
+ private blockcypherUrl;
13
+ nodeUrl: string | undefined;
14
+ /**
15
+ * Constructor
16
+ * Client is initialised with network type
17
+ * Pass strict null as nodeAuth to disable auth for node json rpc
18
+ *
19
+ * @param {DogecoinClientParams} params
20
+ */
21
+ constructor({ network, sochainUrl, blockcypherUrl, phrase, nodeUrl, rootDerivationPaths, }: DogecoinClientParams);
22
+ /**
23
+ * Set/Update the sochain url.
24
+ *
25
+ * @param {string} url The new sochain url.
26
+ * @returns {void}
27
+ */
28
+ setSochainUrl(url: string): void;
29
+ /**
30
+ * Set/Update the blockcypher url.
31
+ *
32
+ * @param {string} url The new blockcypher url.
33
+ * @returns {void}
34
+ */
35
+ setBlockcypherUrl(url: string): void;
36
+ /**
37
+ * Get the explorer url.
38
+ *
39
+ * @returns {string} The explorer url based on the network.
40
+ */
41
+ getExplorerUrl(): string;
42
+ /**
43
+ * Get the explorer url for the given address.
44
+ *
45
+ * @param {Address} address
46
+ * @returns {string} The explorer url for the given address based on the network.
47
+ */
48
+ getExplorerAddressUrl(address: Address): string;
49
+ /**
50
+ * Get the explorer url for the given transaction id.
51
+ *
52
+ * @param {string} txID The transaction id
53
+ * @returns {string} The explorer url for the given transaction id based on the network.
54
+ */
55
+ getExplorerTxUrl(txID: string): string;
56
+ /**
57
+ * Get the current address.
58
+ *
59
+ * Generates a network-specific key-pair by first converting the buffer to a Wallet-Import-Format (WIF)
60
+ * The address is then decoded into type P2WPKH and returned.
61
+ *
62
+ * @returns {Address} The current address.
63
+ *
64
+ * @throws {"Phrase must be provided"} Thrown if phrase has not been set before.
65
+ * @throws {"Address not defined"} Thrown if failed creating account from phrase.
66
+ */
67
+ getAddress(index?: number): Address;
68
+ /**
69
+ * @private
70
+ * Get private key.
71
+ *
72
+ * Private function to get keyPair from the this.phrase
73
+ *
74
+ * @param {string} phrase The phrase to be used for generating privkey
75
+ * @returns {ECPairInterface} The privkey generated from the given phrase
76
+ *
77
+ * @throws {"Could not get private key from phrase"} Throws an error if failed creating Doge keys from the given phrase
78
+ * */
79
+ private getDogeKeys;
80
+ /**
81
+ * Validate the given address.
82
+ *
83
+ * @param {Address} address
84
+ * @returns {boolean} `true` or `false`
85
+ */
86
+ validateAddress(address: string): boolean;
87
+ /**
88
+ * Get the Doge balance of a given address.
89
+ *
90
+ * @param {Address} address By default, it will return the balance of the current wallet. (optional)
91
+ * @returns {Balance[]} The Doge balance of the address.
92
+ */
93
+ getBalance(address: Address): Promise<Balance[]>;
94
+ /**
95
+ * Get transaction history of a given address with pagination options.
96
+ * By default it will return the transaction history of the current wallet.
97
+ *
98
+ * @param {TxHistoryParams} params The options to get transaction history. (optional)
99
+ * @returns {TxsPage} The transaction history.
100
+ */
101
+ getTransactions(params?: TxHistoryParams): Promise<TxsPage>;
102
+ /**
103
+ * Get the transaction details of a given transaction id.
104
+ *
105
+ * @param {string} txId The transaction id.
106
+ * @returns {Tx} The transaction details of the given transaction id.
107
+ */
108
+ getTransactionData(txId: string): Promise<Tx>;
109
+ protected getSuggestedFeeRate(): Promise<FeeRate>;
110
+ protected calcFee(feeRate: FeeRate, memo?: string): Promise<Fee>;
111
+ /**
112
+ * Transfer Doge.
113
+ *
114
+ * @param {TxParams&FeeRate} params The transfer options.
115
+ * @returns {TxHash} The transaction hash.
116
+ */
117
+ transfer(params: TxParams & {
118
+ feeRate?: FeeRate;
119
+ }): Promise<TxHash>;
120
+ }
121
+ export { Client };
package/lib/const.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Minimum transaction fee
3
+ * 100000 satoshi/kB (similar to current `minrelaytxfee`)
4
+ * @see https://github.com/dogecoin/dogecoin/blob/master/src/validation.h#L58
5
+ */
6
+ export declare const MIN_TX_FEE = 100000;
7
+ export declare const DOGE_DECIMAL = 8;
package/lib/index.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ export * from './types';
2
+ export * from './client';
3
+ export * from './const';
4
+ export { broadcastTx, getDefaultFees, getDefaultFeesWithRates, validateAddress, calcFee, scanUTXOs } from './utils';
5
+ export { createTxInfo } from './ledger';