@atomicfinance/types 2.5.1 → 3.0.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.
Files changed (51) hide show
  1. package/.turbo/turbo-build.log +1 -2
  2. package/.turbo/turbo-lint.log +1 -0
  3. package/.turbo/turbo-lint:fix.log +45 -0
  4. package/.turbo/turbo-test.log +1 -3
  5. package/CHANGELOG.md +6 -0
  6. package/dist/address.d.ts +10 -0
  7. package/dist/address.js +11 -0
  8. package/dist/address.js.map +1 -0
  9. package/dist/bitcoin.d.ts +66 -0
  10. package/dist/bitcoin.js +16 -0
  11. package/dist/bitcoin.js.map +1 -0
  12. package/dist/block.d.ts +10 -0
  13. package/dist/{financewallet.js → block.js} +1 -1
  14. package/dist/block.js.map +1 -0
  15. package/dist/chain.d.ts +107 -0
  16. package/dist/chain.js +3 -0
  17. package/dist/chain.js.map +1 -0
  18. package/dist/fees.d.ts +17 -0
  19. package/dist/fees.js +3 -0
  20. package/dist/fees.js.map +1 -0
  21. package/dist/index.d.ts +13 -9
  22. package/dist/index.js +23 -2
  23. package/dist/index.js.map +1 -1
  24. package/dist/jsonrpc.d.ts +72 -0
  25. package/dist/jsonrpc.js +3 -0
  26. package/dist/jsonrpc.js.map +1 -0
  27. package/dist/models/Input.d.ts +8 -8
  28. package/dist/models/Input.js +7 -7
  29. package/dist/models/Input.js.map +1 -1
  30. package/dist/network.d.ts +5 -0
  31. package/dist/network.js +3 -0
  32. package/dist/network.js.map +1 -0
  33. package/dist/transaction.d.ts +17 -0
  34. package/dist/transaction.js +10 -0
  35. package/dist/transaction.js.map +1 -0
  36. package/dist/wallet.d.ts +78 -0
  37. package/lib/address.ts +13 -0
  38. package/lib/bitcoin.ts +72 -0
  39. package/lib/block.ts +18 -0
  40. package/lib/chain.ts +126 -0
  41. package/lib/fees.ts +21 -0
  42. package/lib/index.ts +31 -9
  43. package/lib/jsonrpc.ts +81 -0
  44. package/lib/models/Input.ts +8 -9
  45. package/lib/network.ts +5 -0
  46. package/lib/transaction.ts +28 -0
  47. package/lib/wallet.ts +109 -0
  48. package/package.json +3 -5
  49. package/dist/financewallet.d.ts +0 -11
  50. package/dist/financewallet.js.map +0 -1
  51. package/lib/financewallet.ts +0 -31
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TxStatus = void 0;
4
+ var TxStatus;
5
+ (function (TxStatus) {
6
+ TxStatus["Pending"] = "PENDING";
7
+ TxStatus["Failed"] = "FAILED";
8
+ TxStatus["Success"] = "SUCCESS";
9
+ })(TxStatus = exports.TxStatus || (exports.TxStatus = {}));
10
+ //# sourceMappingURL=transaction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction.js","sourceRoot":"","sources":["../lib/transaction.ts"],"names":[],"mappings":";;;AAuBA,IAAY,QAIX;AAJD,WAAY,QAAQ;IAClB,+BAAmB,CAAA;IACnB,6BAAiB,CAAA;IACjB,+BAAmB,CAAA;AACrB,CAAC,EAJW,QAAQ,GAAR,gBAAQ,KAAR,gBAAQ,QAInB"}
package/dist/wallet.d.ts CHANGED
@@ -1,5 +1,83 @@
1
+ import { Address } from './address';
2
+ import Input from './models/Input';
3
+ import Output from './models/Output';
1
4
  export interface finalizePSBTResponse {
2
5
  psbt: string;
3
6
  hex?: string;
4
7
  complete: boolean;
5
8
  }
9
+ export interface WalletProvider {
10
+ /**
11
+ * Get addresses/accounts of the user.
12
+ * @param {number} [startingIndex] - Index to start
13
+ * @param {number} [numAddresses] - Number of addresses to retrieve
14
+ * @param {boolean} [change] - True for change addresses
15
+ * @return {Promise<Address[], InvalidProviderResponseError>} Resolves with a list
16
+ * of addresses.
17
+ * Rejects with InvalidProviderResponseError if provider's response is invalid.
18
+ */
19
+ getAddresses(startingIndex?: number, numAddresses?: number, change?: boolean): Promise<Address[]>;
20
+ /**
21
+ * Get used addresses/accounts of the user.
22
+ * @param {number} [numAddressPerCall] - Number of addresses to retrieve per call
23
+ * @return {Promise<Address[], InvalidProviderResponseError>} Resolves with a list
24
+ * of addresses.
25
+ * Rejects with InvalidProviderResponseError if provider's response is invalid.
26
+ */
27
+ getUsedAddresses(numAddressPerCall?: number): Promise<Address[]>;
28
+ /**
29
+ * findAddress is an optimized version of upstream CAL's findAddress.
30
+ *
31
+ * It searches through both change and non-change addresses (if change arg is not provided) each iteration.
32
+ *
33
+ * This is in contrast to the original findAddress function which searches
34
+ * through all non-change addresses before moving on to change addresses.
35
+ *
36
+ * @param addresses
37
+ * @returns {Promise<Address>}
38
+ */
39
+ findAddress(addresses: string[]): Promise<Address>;
40
+ /**
41
+ * Get unused address/account of the user.
42
+ * @param {boolean} [change] - True for change addresses
43
+ * @param {number} [numAddressPerCall] - Number of addresses to retrieve per call
44
+ * @return {Promise<Address, InvalidProviderResponseError>} Resolves with a address
45
+ * object.
46
+ * Rejects with InvalidProviderResponseError if provider's response is invalid.
47
+ */
48
+ getUnusedAddress(change?: boolean, numAddressPerCall?: number): Promise<Address>;
49
+ /**
50
+ * Sign a message.
51
+ * @param {!string} message - Message to be signed.
52
+ * @param {!string} from - The address from which the message is signed.
53
+ * @return {Promise<string>} Resolves with a signed message.
54
+ */
55
+ signMessage(message: string, from: string): Promise<string>;
56
+ /**
57
+ * Retrieve the network connected to by the wallet
58
+ * @return {Promise<any>} Resolves with the network object
59
+ */
60
+ getConnectedNetwork(): Promise<any>;
61
+ /**
62
+ * Retrieve the availability status of the wallet
63
+ * @return {Promise<Boolean>} True if the wallet is available to use
64
+ */
65
+ isWalletAvailable(): Promise<boolean>;
66
+ /**
67
+ * Flag indicating if the wallet allows apps to update transaction fees
68
+ * @return {Promise<Boolean>} True if wallet accepts fee updating
69
+ */
70
+ canUpdateFee?: boolean | (() => boolean);
71
+ /**
72
+ * Exports the private key for the account
73
+ * for BTC, https://en.bitcoin.it/wiki/Wallet_import_format
74
+ * for ETH, the privateKey
75
+ * for NEAR, the secretKey
76
+ * @return {Promise<string>} Resolves with the key as a string
77
+ */
78
+ exportPrivateKey?: () => Promise<string>;
79
+ buildSweepTransactionWithSetOutputs(externalChangeAddress: string, feePerByte: number, _outputs: Output[], fixedInputs: Input[]): any;
80
+ getUnusedAddressesBlacklist(): any;
81
+ setUnusedAddressesBlacklist(unusedAddressesBlacklist: any): any;
82
+ sendSweepTransactionWithSetOutputs(externalChangeAddress: string, feePerByte: number, _outputs: Output[], fixedInputs: Input[]): any;
83
+ }
package/lib/address.ts ADDED
@@ -0,0 +1,13 @@
1
+ export class Address {
2
+ address: string;
3
+ derivationPath?: string;
4
+ publicKey?: string;
5
+
6
+ constructor(fields?: {
7
+ address: string;
8
+ derivationPath?: string;
9
+ publicKey?: string;
10
+ }) {
11
+ if (fields) Object.assign(this, fields);
12
+ }
13
+ }
package/lib/bitcoin.ts ADDED
@@ -0,0 +1,72 @@
1
+ export interface OutputTarget {
2
+ address?: string;
3
+ script?: Buffer;
4
+ value: number;
5
+ }
6
+
7
+ export interface ScriptPubKey {
8
+ asm: string;
9
+ hex: string;
10
+ reqSigs: number;
11
+ type: string;
12
+ addresses: string[];
13
+ }
14
+
15
+ export interface Output {
16
+ value: number;
17
+ n: number;
18
+ scriptPubKey: ScriptPubKey;
19
+ }
20
+
21
+ export interface Input {
22
+ txid: string;
23
+ vout: number;
24
+ scriptSig: {
25
+ asm: string;
26
+ hex: string;
27
+ };
28
+ txinwitness: string[];
29
+ sequence: number;
30
+ coinbase?: string;
31
+ }
32
+
33
+ export interface Transaction {
34
+ txid: string;
35
+ hash: string;
36
+ version: number;
37
+ locktime: number;
38
+ size: number;
39
+ vsize: number;
40
+ weight: number;
41
+ vin: Input[];
42
+ vout: Output[];
43
+ confirmations?: number;
44
+ hex: string;
45
+ }
46
+
47
+ export interface UTXO {
48
+ txid: string;
49
+ vout: number;
50
+ value: number;
51
+ address: string;
52
+ derivationPath?: string;
53
+ }
54
+
55
+ export enum AddressType {
56
+ LEGACY = 'legacy',
57
+ P2SH_SEGWIT = 'p2sh-segwit',
58
+ BECH32 = 'bech32',
59
+ }
60
+
61
+ export enum SwapMode {
62
+ P2SH = 'p2sh',
63
+ P2SH_SEGWIT = 'p2shSegwit',
64
+ P2WSH = 'p2wsh',
65
+ }
66
+
67
+ export type AddressTxCounts = { [index: string]: number };
68
+
69
+ export interface PsbtInputTarget {
70
+ index: number;
71
+ derivationPath: string;
72
+ }
package/lib/block.ts ADDED
@@ -0,0 +1,18 @@
1
+ export interface Block<TransactionType = any> {
2
+ // Block number
3
+ number: number;
4
+ // Block hash
5
+ hash: string;
6
+ // Block timestamp in seconds
7
+ timestamp: number;
8
+ // The size of this block in bytes
9
+ size: number;
10
+ // Hash of the parent block
11
+ parentHash: string;
12
+ // The difficulty field
13
+ difficulty?: number;
14
+ // Nonce
15
+ nonce?: number;
16
+ // List of transactions
17
+ transactions?: TransactionType[];
18
+ }
package/lib/chain.ts ADDED
@@ -0,0 +1,126 @@
1
+ import BigNumber from 'bignumber.js';
2
+
3
+ import { Address } from './address';
4
+ import { Block } from './block';
5
+ import { Transaction } from './transaction';
6
+
7
+ export interface SendOptions {
8
+ to: Address | string;
9
+ value: BigNumber;
10
+ data?: string;
11
+ fee?: number;
12
+ }
13
+
14
+ export interface ChainProvider {
15
+ /**
16
+ * Generate a block
17
+ * @param {!number} numberOfBlocks - Number of blocks to be generated
18
+ * @return {<Promise>}
19
+ */
20
+ generateBlock(numberOfBlocks: number): Promise<void>;
21
+
22
+ /**
23
+ * Get a block given its hash.
24
+ * @param {!string} blockHash - A hexadecimal string that represents the
25
+ * *hash* of the desired block.
26
+ * @param {boolean} [includeTx=false] - If true, fetches transactions in the block.
27
+ * @return {Promise<Block, TypeError|InvalidProviderResponseError>}
28
+ * Resolves with a Block with the same hash as the given input.
29
+ * If `includeTx` is true, the transaction property is an array of Transactions;
30
+ * otherwise, it is a list of transaction hashes.
31
+ * Rejects with TypeError if input is invalid.
32
+ * Rejects with InvalidProviderResponseError if provider's response is invalid.
33
+ */
34
+ getBlockByHash(blockHash: string, includeTx?: boolean): Promise<Block>;
35
+
36
+ /**
37
+ * Get a block given its number.
38
+ * @param {!number} blockNumber - The number of the desired block.
39
+ * @param {boolean} [includeTx=false] - If true, fetches transaction in the block.
40
+ * @return {Promise<Block, TypeError|InvalidProviderResponseError>}
41
+ * Resolves with a Block with the same number as the given input.
42
+ * If `includeTx` is true, the transaction property is an array of Transactions;
43
+ * otherwise, it is a list of transaction hashes.
44
+ * Rejects with TypeError if input is invalid.
45
+ * Rejects with InvalidProviderResponseError if provider's response is invalid.
46
+ */
47
+ getBlockByNumber(blockNumber: number, includeTx?: boolean): Promise<Block>;
48
+
49
+ /**
50
+ * Get current block height of the chain.
51
+ * @return {Promise<number, InvalidProviderResponseError>} Resolves with
52
+ * chain height.
53
+ * Rejects with InvalidProviderResponseError if provider's response is invalid.
54
+ */
55
+ getBlockHeight(): Promise<number>;
56
+
57
+ /**
58
+ * Get a transaction given its hash.
59
+ * @param {!string} txHash - A hexadecimal string that represents the *hash* of the
60
+ * desired transaction.
61
+ * @return {Promise<Transaction, TypeError|InvalidProviderResponseError>}
62
+ * Resolves with a Transaction with the same hash as the given input.
63
+ * Rejects with TypeError if input is invalid.
64
+ * Rejects with InvalidProviderResponseError if provider's response is invalid.
65
+ */
66
+ getTransactionByHash(txHash: string): Promise<Transaction>;
67
+
68
+ /**
69
+ * Get the balance of an account given its addresses.
70
+ * @param {(string | Address)[]} addresses - A list of addresses.
71
+ * @return {Promise<BigNumber, InvalidProviderResponseError>} If addresses is given,
72
+ * returns the cumulative balance of the given addresses. Otherwise returns the balance
73
+ * of the addresses that the signing provider controls.
74
+ * Rejects with InvalidProviderResponseError if provider's response is invalid.
75
+ */
76
+ getBalance(addresses: (Address | string)[]): Promise<BigNumber>;
77
+
78
+ /**
79
+ * Create, sign & broadcast a transaction.
80
+ * @param {!string} to - Recepient address.
81
+ * @param {!number} value - Value of transaction.
82
+ * @param {!string} data - Data to be passed to the transaction.
83
+ * @param {!Fee} [fee] - Fee price in native unit (e.g. sat/b, wei)
84
+ * @return {Promise<Transaction>} Resolves with a signed transaction.
85
+ */
86
+ sendTransaction(options: SendOptions): Promise<Transaction>;
87
+
88
+ /**
89
+ * Create, sign & broadcast a sweep transaction.
90
+ * @param {!string} address - External address.
91
+ * @param {Fee} [fee] - Fee price in native unit (e.g. sat/b, wei)
92
+ * @return {Promise<Transaction>} Resolves with a signed transaction.
93
+ */
94
+ sendSweepTransaction(
95
+ address: Address | string,
96
+ fee?: number,
97
+ ): Promise<Transaction>;
98
+
99
+ /**
100
+ * Update the fee of a transaction.
101
+ * @param {(string|Transaction)} tx - Transaction object or hash of the transaction to update
102
+ * @param {!Fee} newFee - New fee price in native unit (e.g. sat/b, wei)
103
+ * @return {Promise<Transaction>} Resolves with the new transaction
104
+ */
105
+ updateTransactionFee(
106
+ tx: string | Transaction,
107
+ newFee: number,
108
+ ): Promise<Transaction>;
109
+
110
+ /**
111
+ * Create, sign & broad a transaction with multiple outputs.
112
+ * @param {string[]} transactions - to, value, data
113
+ * @return {Promise<Transaction>} Resolves with a signed transaction.
114
+ */
115
+ sendBatchTransaction(transactions: SendOptions[]): Promise<Transaction>;
116
+
117
+ /**
118
+ * Broadcast a signed transaction to the network.
119
+ * @param {!string} rawTransaction - A raw transaction usually in the form of a
120
+ * hexadecimal string that represents the serialized transaction.
121
+ * @return {Promise<string, InvalidProviderResponseError>} Resolves with an
122
+ * identifier for the broadcasted transaction.
123
+ * Rejects with InvalidProviderResponseError if provider's response is invalid.
124
+ */
125
+ sendRawTransaction(rawTransaction: string): Promise<string>;
126
+ }
package/lib/fees.ts ADDED
@@ -0,0 +1,21 @@
1
+ export interface FeeDetail {
2
+ // Fee price
3
+ fee: number;
4
+ // Estimated time to confirmation
5
+ wait?: number;
6
+ }
7
+
8
+ export interface FeeDetails {
9
+ slow: FeeDetail;
10
+ average: FeeDetail;
11
+ fast: FeeDetail;
12
+ }
13
+
14
+ export interface FeeProvider {
15
+ /**
16
+ * @return {Promise<FeeDetails>} Resolves with an
17
+ * identifier for the broadcasted transaction.
18
+ * Rejects with InvalidProviderResponseError if provider's response is invalid.
19
+ */
20
+ getFees(): Promise<FeeDetails>;
21
+ }
package/lib/index.ts CHANGED
@@ -1,11 +1,18 @@
1
- import { Provider } from '@liquality/provider';
2
- import { ChainProvider, SwapProvider, WalletProvider } from '@liquality/types';
1
+ import BigNumber from 'bignumber.js';
3
2
 
3
+ import { Address } from './address';
4
+ import * as bitcoin from './bitcoin';
5
+ import { Block } from './block';
4
6
  import { CfdProvider } from './cfd';
7
+ import { ChainProvider, SendOptions } from './chain';
5
8
  import { DlcProvider } from './dlc';
6
- import { FinanceWalletProvider } from './financewallet';
9
+ import { FeeDetail, FeeDetails, FeeProvider } from './fees';
10
+ import * as BitcoinJsonRpcTypes from './jsonrpc';
11
+ import { Network } from './network';
12
+ import { Transaction, TxStatus } from './transaction';
13
+ import { WalletProvider } from './wallet';
7
14
 
8
- interface IFinanceClient {
15
+ interface IClient {
9
16
  /**
10
17
  * Helper method that returns method from a provider.
11
18
  * @param {!string} method - Name of the method to look for in the provider stack
@@ -14,20 +21,17 @@ interface IFinanceClient {
14
21
  * @return {function} Returns method from provider instance associated with the requested method
15
22
  */
16
23
  getMethod(method: string, requestor?: any): () => any;
17
- getProviderForMethod(method: string, requestor?: boolean): Provider;
24
+ getProviderForMethod(method: string, requestor?: boolean): any;
18
25
 
19
26
  chain: ChainProvider;
20
- swap: SwapProvider;
21
27
  wallet: WalletProvider;
22
28
  cfd: CfdProvider;
23
29
  dlc: DlcProvider;
24
- financewallet: FinanceWalletProvider;
25
30
  }
26
31
 
27
32
  export * from './cfd';
28
33
  export * from './common';
29
34
  export * from './dlc';
30
- export * from './financewallet';
31
35
  export { default as Amount } from './models/Amount';
32
36
  export { default as Input } from './models/Input';
33
37
  export { default as OracleInfo } from './models/OracleInfo';
@@ -35,4 +39,22 @@ export { default as Outcome } from './models/Outcome';
35
39
  export { default as Output } from './models/Output';
36
40
  export { default as Utxo } from './models/Utxo';
37
41
  export * from './wallet';
38
- export { IFinanceClient, CfdProvider, DlcProvider, FinanceWalletProvider };
42
+ export {
43
+ BigNumber,
44
+ IClient,
45
+ CfdProvider,
46
+ DlcProvider,
47
+ ChainProvider,
48
+ WalletProvider,
49
+ Address,
50
+ SendOptions,
51
+ Block,
52
+ Transaction,
53
+ TxStatus,
54
+ FeeDetails,
55
+ FeeDetail,
56
+ FeeProvider,
57
+ Network,
58
+ BitcoinJsonRpcTypes,
59
+ bitcoin,
60
+ };
package/lib/jsonrpc.ts ADDED
@@ -0,0 +1,81 @@
1
+ import { Transaction } from './bitcoin';
2
+
3
+ export interface UTXO {
4
+ txid: string;
5
+ vout: number;
6
+ address: string;
7
+ label: string;
8
+ scriptPubKey: string;
9
+ amount: number;
10
+ confirmations: number;
11
+ redeemScript: string;
12
+ witnessScript: string;
13
+ spendable: boolean;
14
+ solvable: boolean;
15
+ desc: string;
16
+ safe: boolean;
17
+ }
18
+
19
+ export interface ReceivedByAddress {
20
+ involvesWatchOnly: boolean;
21
+ address: string;
22
+ account: string;
23
+ amount: number;
24
+ cofirmations: number;
25
+ label: string;
26
+ txids: string[];
27
+ }
28
+
29
+ export interface MinedTransaction extends Transaction {
30
+ blockhash: string;
31
+ confirmations: number;
32
+ blocktime: number;
33
+ number: number;
34
+ }
35
+
36
+ export interface FundRawResponse {
37
+ hex: string;
38
+ fee: number;
39
+ changepos: number;
40
+ }
41
+
42
+ export interface AddressInfo {
43
+ iswatchonly: boolean;
44
+ pubkey: string;
45
+ hdkeypath: string;
46
+ // ...
47
+ }
48
+
49
+ export type AddressGrouping = string[][];
50
+
51
+ export interface ReceivedByAddress {
52
+ involvesWatchonly: boolean;
53
+ address: string;
54
+ account: string;
55
+ amount: number;
56
+ confirmations: number;
57
+ label: string;
58
+ txids: string[];
59
+ }
60
+
61
+ export interface Block {
62
+ hash: string;
63
+ confirmations: number;
64
+ size: number;
65
+ strippedSize: number;
66
+ weight: number;
67
+ height: number;
68
+ version: number;
69
+ versionHex: string;
70
+ merkleroot: string;
71
+ tx: string[];
72
+ time: number;
73
+ mediantime: number;
74
+ nonce: number;
75
+ bits: string;
76
+ difficulty: number;
77
+ chainwork: string;
78
+ nTx: number;
79
+ previousblockhash: string;
80
+ nextblockhash?: string;
81
+ }
@@ -1,21 +1,20 @@
1
- import { bitcoin as bT } from '@liquality/types';
2
-
1
+ import * as bT from '../bitcoin';
3
2
  import Amount from './Amount';
4
3
  import Utxo from './Utxo';
5
4
 
6
5
  /**
7
- * Class for interfacing with inputs/utxos in Liquality ChainAbstractionLayer
8
- * https://github.com/liquality/chainabstractionlayer
6
+ * Class for interfacing with inputs/utxos in Liquality Chainify
7
+ * https://github.com/liquality/chainify
9
8
  *
10
9
  * These inputs can have different fields for value
11
- * satoshis (sats): https://github.com/liquality/chainabstractionlayer/blob/dev/packages/bitcoin-esplora-api-provider/lib/BitcoinEsploraApiProvider.js#L65
12
- * amount (btc): https://github.com/liquality/chainabstractionlayer/blob/dev/packages/bitcoin-esplora-api-provider/lib/BitcoinEsploraApiProvider.js#L74
13
- * value (sats): https://github.com/liquality/chainabstractionlayer/blob/dev/packages/bitcoin-wallet-provider/lib/BitcoinWalletProvider.js#L331
10
+ * satoshis (sats): https://github.com/liquality/chainify/blob/dev/packages/bitcoin-esplora-api-provider/lib/BitcoinEsploraApiProvider.js#L65
11
+ * amount (btc): https://github.com/liquality/chainify/blob/dev/packages/bitcoin-esplora-api-provider/lib/BitcoinEsploraApiProvider.js#L74
12
+ * value (sats): https://github.com/liquality/chainify/blob/dev/packages/bitcoin-wallet-provider/lib/BitcoinWalletProvider.js#L331
14
13
  *
15
14
  * This will be fixed once typescript branch is merged:
16
- * https://github.com/liquality/chainabstractionlayer/tree/typescript
15
+ * https://github.com/liquality/chainify/tree/typescript
17
16
  * satoshis and amount will not be necessary, only value
18
- * https://github.com/liquality/chainabstractionlayer/blob/typescript/packages/types/lib/bitcoin.ts#L46
17
+ * https://github.com/liquality/chainify/blob/typescript/packages/types/lib/bitcoin.ts#L46
19
18
  */
20
19
  export default class Input {
21
20
  constructor(
package/lib/network.ts ADDED
@@ -0,0 +1,5 @@
1
+ export interface Network {
2
+ name: string;
3
+ coinType: string;
4
+ isTestnet: boolean;
5
+ }
@@ -0,0 +1,28 @@
1
+ export interface Transaction<T = any> {
2
+ // Transaction hash
3
+ hash: string;
4
+ // The value of the transaction
5
+ value: number;
6
+ // transaction status
7
+ status?: TxStatus;
8
+ // Hash of the block containing the transaction
9
+ blockHash?: string;
10
+ // The block number containing the trnasaction
11
+ blockNumber?: number;
12
+ // The number of confirmations of the transaction
13
+ confirmations?: number;
14
+ // The price per unit of fee
15
+ feePrice?: number;
16
+ // The total fee paid for the transaction
17
+ fee?: number;
18
+ // Secret of a HTLC
19
+ secret?: string;
20
+ // The raw transaction object
21
+ _raw: T;
22
+ }
23
+
24
+ export enum TxStatus {
25
+ Pending = 'PENDING',
26
+ Failed = 'FAILED',
27
+ Success = 'SUCCESS',
28
+ }
package/lib/wallet.ts CHANGED
@@ -1,5 +1,114 @@
1
+ import { Address } from './address';
2
+ import Input from './models/Input';
3
+ import Output from './models/Output';
4
+
1
5
  export interface finalizePSBTResponse {
2
6
  psbt: string;
3
7
  hex?: string;
4
8
  complete: boolean;
5
9
  }
10
+
11
+ export interface WalletProvider {
12
+ /**
13
+ * Get addresses/accounts of the user.
14
+ * @param {number} [startingIndex] - Index to start
15
+ * @param {number} [numAddresses] - Number of addresses to retrieve
16
+ * @param {boolean} [change] - True for change addresses
17
+ * @return {Promise<Address[], InvalidProviderResponseError>} Resolves with a list
18
+ * of addresses.
19
+ * Rejects with InvalidProviderResponseError if provider's response is invalid.
20
+ */
21
+ getAddresses(
22
+ startingIndex?: number,
23
+ numAddresses?: number,
24
+ change?: boolean,
25
+ ): Promise<Address[]>;
26
+
27
+ /**
28
+ * Get used addresses/accounts of the user.
29
+ * @param {number} [numAddressPerCall] - Number of addresses to retrieve per call
30
+ * @return {Promise<Address[], InvalidProviderResponseError>} Resolves with a list
31
+ * of addresses.
32
+ * Rejects with InvalidProviderResponseError if provider's response is invalid.
33
+ */
34
+ getUsedAddresses(numAddressPerCall?: number): Promise<Address[]>;
35
+
36
+ /**
37
+ * findAddress is an optimized version of upstream CAL's findAddress.
38
+ *
39
+ * It searches through both change and non-change addresses (if change arg is not provided) each iteration.
40
+ *
41
+ * This is in contrast to the original findAddress function which searches
42
+ * through all non-change addresses before moving on to change addresses.
43
+ *
44
+ * @param addresses
45
+ * @returns {Promise<Address>}
46
+ */
47
+ findAddress(addresses: string[]): Promise<Address>;
48
+
49
+ /**
50
+ * Get unused address/account of the user.
51
+ * @param {boolean} [change] - True for change addresses
52
+ * @param {number} [numAddressPerCall] - Number of addresses to retrieve per call
53
+ * @return {Promise<Address, InvalidProviderResponseError>} Resolves with a address
54
+ * object.
55
+ * Rejects with InvalidProviderResponseError if provider's response is invalid.
56
+ */
57
+ getUnusedAddress(
58
+ change?: boolean,
59
+ numAddressPerCall?: number,
60
+ ): Promise<Address>;
61
+
62
+ /**
63
+ * Sign a message.
64
+ * @param {!string} message - Message to be signed.
65
+ * @param {!string} from - The address from which the message is signed.
66
+ * @return {Promise<string>} Resolves with a signed message.
67
+ */
68
+ signMessage(message: string, from: string): Promise<string>;
69
+
70
+ /**
71
+ * Retrieve the network connected to by the wallet
72
+ * @return {Promise<any>} Resolves with the network object
73
+ */
74
+ getConnectedNetwork(): Promise<any>;
75
+
76
+ /**
77
+ * Retrieve the availability status of the wallet
78
+ * @return {Promise<Boolean>} True if the wallet is available to use
79
+ */
80
+ isWalletAvailable(): Promise<boolean>;
81
+
82
+ /**
83
+ * Flag indicating if the wallet allows apps to update transaction fees
84
+ * @return {Promise<Boolean>} True if wallet accepts fee updating
85
+ */
86
+ canUpdateFee?: boolean | (() => boolean);
87
+
88
+ /**
89
+ * Exports the private key for the account
90
+ * for BTC, https://en.bitcoin.it/wiki/Wallet_import_format
91
+ * for ETH, the privateKey
92
+ * for NEAR, the secretKey
93
+ * @return {Promise<string>} Resolves with the key as a string
94
+ */
95
+ exportPrivateKey?: () => Promise<string>;
96
+
97
+ buildSweepTransactionWithSetOutputs(
98
+ externalChangeAddress: string,
99
+ feePerByte: number,
100
+ _outputs: Output[],
101
+ fixedInputs: Input[],
102
+ );
103
+
104
+ getUnusedAddressesBlacklist();
105
+
106
+ setUnusedAddressesBlacklist(unusedAddressesBlacklist);
107
+
108
+ sendSweepTransactionWithSetOutputs(
109
+ externalChangeAddress: string,
110
+ feePerByte: number,
111
+ _outputs: Output[],
112
+ fixedInputs: Input[],
113
+ );
114
+ }