@atomicfinance/client 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.
package/dist/Wallet.d.ts CHANGED
@@ -1,14 +1,69 @@
1
- import { CreateMultisigResponse, Input, Output } from '@atomicfinance/types';
1
+ import { Address, CreateMultisigResponse, Input, Output, WalletProvider } from '@atomicfinance/types';
2
2
  import { Transaction } from 'bitcoinjs-lib';
3
- export default class Wallet {
3
+ export default class Wallet implements WalletProvider {
4
4
  client: any;
5
5
  constructor(client: any);
6
+ /**
7
+ * Get addresses/accounts of the user.
8
+ * @param {number} [startingIndex] - Index to start
9
+ * @param {number} [numAddresses] - Number of addresses to retrieve
10
+ * @param {boolean} [change] - True for change addresses
11
+ * @return {Promise<Address[], InvalidProviderResponseError>} Resolves with a list
12
+ * of addresses.
13
+ * Rejects with InvalidProviderResponseError if provider's response is invalid.
14
+ */
15
+ getAddresses(startingIndex?: number, numAddresses?: number, change?: boolean): Promise<Address[]>;
16
+ /**
17
+ * Get used addresses/accounts of the user.
18
+ * @param {number} [numAddressPerCall] - Number of addresses to retrieve per call
19
+ * @return {Promise<Address[], InvalidProviderResponseError>} Resolves with a list
20
+ * of addresses.
21
+ * Rejects with InvalidProviderResponseError if provider's response is invalid.
22
+ */
23
+ getUsedAddresses(numAddressPerCall?: number): Promise<Address[]>;
24
+ /**
25
+ * Get unused address/account of the user.
26
+ * @param {boolean} [change] - True for change addresses
27
+ * @param {number} [numAddressPerCall] - Number of addresses to retrieve per call
28
+ * @return {Promise<Address, InvalidProviderResponseError>} Resolves with a address
29
+ * object.
30
+ * Rejects with InvalidProviderResponseError if provider's response is invalid.
31
+ */
32
+ getUnusedAddress(change?: boolean, numAddressPerCall?: number): Promise<Address>;
33
+ /**
34
+ * Sign a message.
35
+ * @param {!string} message - Message to be signed.
36
+ * @param {!string} from - The address from which the message is signed.
37
+ * @return {Promise<string>} Resolves with a signed message.
38
+ */
39
+ signMessage(message: string, from: string): Promise<string>;
40
+ /**
41
+ * Retrieve the network connected to by the wallet
42
+ * @return {Promise<any>} Resolves with the network object
43
+ */
44
+ getConnectedNetwork(): Promise<any>;
45
+ /**
46
+ * Retrieve the availability status of the wallet
47
+ * @return {Promise<Boolean>} True if the wallet is available to use
48
+ */
49
+ isWalletAvailable(): Promise<boolean>;
50
+ /**
51
+ * Flag indicating if the wallet allows apps to update transaction fees
52
+ * @return {Promise<Boolean>} True if wallet accepts fee updating
53
+ */
54
+ get canUpdateFee(): boolean;
55
+ /**
56
+ * Retrieve the private key for the account
57
+ * @return {Promise<string>} Resolves with the key as a string
58
+ */
59
+ exportPrivateKey(): Promise<string>;
60
+ findAddress(addresses: string[]): any;
61
+ setUnusedAddressesBlacklist(unusedAddressesBlacklist: any): any;
62
+ getUnusedAddressesBlacklist(): any;
6
63
  createMultisig(m: number, pubkeys: string[]): CreateMultisigResponse;
7
64
  buildMultisigPSBT(m: number, pubkeys: string[], inputs: Input[], outputs: Output[]): string;
8
65
  walletProcessPSBT(psbtString: string): Promise<string>;
9
66
  finalizePSBT(psbtString: string): Transaction;
10
67
  buildSweepTransactionWithSetOutputs(externalChangeAddress: string, feePerByte: number, outputs: Output[], fixedInputs: Input[]): Promise<any>;
11
68
  sendSweepTransactionWithSetOutputs(externalChangeAddress: string, feePerByte: number, outputs: Output[], fixedInputs: Input[]): Promise<any>;
12
- getUnusedAddress(change?: boolean, numAddressPerCall?: number): Promise<any>;
13
- quickFindAddress(addresses: string[]): Promise<any>;
14
69
  }
package/dist/Wallet.js CHANGED
@@ -1,9 +1,101 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const errors_1 = require("@atomicfinance/errors");
4
+ const lodash_1 = require("lodash");
3
5
  class Wallet {
4
6
  constructor(client) {
5
7
  this.client = client;
6
8
  }
9
+ /**
10
+ * Get addresses/accounts of the user.
11
+ * @param {number} [startingIndex] - Index to start
12
+ * @param {number} [numAddresses] - Number of addresses to retrieve
13
+ * @param {boolean} [change] - True for change addresses
14
+ * @return {Promise<Address[], InvalidProviderResponseError>} Resolves with a list
15
+ * of addresses.
16
+ * Rejects with InvalidProviderResponseError if provider's response is invalid.
17
+ */
18
+ async getAddresses(startingIndex, numAddresses, change) {
19
+ const addresses = await this.client.getMethod('getAddresses')(startingIndex, numAddresses, change);
20
+ if (!lodash_1.isArray(addresses)) {
21
+ throw new errors_1.InvalidProviderResponseError('Provider returned an invalid response');
22
+ }
23
+ return addresses;
24
+ }
25
+ /**
26
+ * Get used addresses/accounts of the user.
27
+ * @param {number} [numAddressPerCall] - Number of addresses to retrieve per call
28
+ * @return {Promise<Address[], InvalidProviderResponseError>} Resolves with a list
29
+ * of addresses.
30
+ * Rejects with InvalidProviderResponseError if provider's response is invalid.
31
+ */
32
+ async getUsedAddresses(numAddressPerCall) {
33
+ return this.client.getMethod('getUsedAddresses')(numAddressPerCall);
34
+ }
35
+ /**
36
+ * Get unused address/account of the user.
37
+ * @param {boolean} [change] - True for change addresses
38
+ * @param {number} [numAddressPerCall] - Number of addresses to retrieve per call
39
+ * @return {Promise<Address, InvalidProviderResponseError>} Resolves with a address
40
+ * object.
41
+ * Rejects with InvalidProviderResponseError if provider's response is invalid.
42
+ */
43
+ async getUnusedAddress(change, numAddressPerCall) {
44
+ return this.client.getMethod('getUnusedAddress')(change, numAddressPerCall);
45
+ }
46
+ /**
47
+ * Sign a message.
48
+ * @param {!string} message - Message to be signed.
49
+ * @param {!string} from - The address from which the message is signed.
50
+ * @return {Promise<string>} Resolves with a signed message.
51
+ */
52
+ async signMessage(message, from) {
53
+ return this.client.getMethod('signMessage')(message, from);
54
+ }
55
+ /**
56
+ * Retrieve the network connected to by the wallet
57
+ * @return {Promise<any>} Resolves with the network object
58
+ */
59
+ async getConnectedNetwork() {
60
+ return this.client.getMethod('getConnectedNetwork')();
61
+ }
62
+ /**
63
+ * Retrieve the availability status of the wallet
64
+ * @return {Promise<Boolean>} True if the wallet is available to use
65
+ */
66
+ async isWalletAvailable() {
67
+ return this.client.getMethod('isWalletAvailable')();
68
+ }
69
+ /**
70
+ * Flag indicating if the wallet allows apps to update transaction fees
71
+ * @return {Promise<Boolean>} True if wallet accepts fee updating
72
+ */
73
+ get canUpdateFee() {
74
+ try {
75
+ return this.client.getMethod('canUpdateFee')();
76
+ }
77
+ catch (e) {
78
+ if (!(e instanceof errors_1.UnimplementedMethodError))
79
+ throw e;
80
+ }
81
+ return true;
82
+ }
83
+ /**
84
+ * Retrieve the private key for the account
85
+ * @return {Promise<string>} Resolves with the key as a string
86
+ */
87
+ exportPrivateKey() {
88
+ return this.client.getMethod('exportPrivateKey')();
89
+ }
90
+ findAddress(addresses) {
91
+ return this.client.getMethod('findAddress')(addresses);
92
+ }
93
+ setUnusedAddressesBlacklist(unusedAddressesBlacklist) {
94
+ return this.client.getMethod('setUnusedAddressesBlacklist')(unusedAddressesBlacklist);
95
+ }
96
+ getUnusedAddressesBlacklist() {
97
+ return this.client.getMethod('getUnusedAddressesBlacklist')();
98
+ }
7
99
  createMultisig(m, pubkeys) {
8
100
  return this.client.getMethod('createMultisig')(m, pubkeys);
9
101
  }
@@ -22,12 +114,6 @@ class Wallet {
22
114
  async sendSweepTransactionWithSetOutputs(externalChangeAddress, feePerByte, outputs, fixedInputs) {
23
115
  return this.client.getMethod('sendSweepTransactionWithSetOutputs')(externalChangeAddress, feePerByte, outputs, fixedInputs);
24
116
  }
25
- async getUnusedAddress(change = false, numAddressPerCall = 100) {
26
- return this.client.getMethod('getUnusedAddress')(change, numAddressPerCall);
27
- }
28
- async quickFindAddress(addresses) {
29
- return this.client.getMethod('quickFindAddress')(addresses);
30
- }
31
117
  }
32
118
  exports.default = Wallet;
33
119
  //# sourceMappingURL=Wallet.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Wallet.js","sourceRoot":"","sources":["../lib/Wallet.ts"],"names":[],"mappings":";;AAGA,MAAqB,MAAM;IAGzB,YAAY,MAAW;QACrB,IAAI,CAAC,MAAM,GAAG,M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C,CAC/C,CAAC,EACD,OAAO,EACP,MAAM,EACN,OAAO,CACR,CAAC;IACJ,CAAC;IAED,iBAAiB,CAAC,UAAkB;QAClC,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,mBAAmB,CAAC,CAAC,UAAU,CAAC,CAAC;IAChE,CAAC;IAED,YAAY,CAAC,UAAkB;QAC7B,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,UAAU,CAAC,CAAC;IAC3D,CAAC;IAED,KAAK,CAAC,mCAAmC,CACvC,qBAA6B,EAC7B,UAAkB,EAClB,OAAiB,EACjB,WAAoB;QAEpB,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,qCAAqC,CAAC,CACjE,qBAAqB,EACrB,UAAU,EACV,OAAO,EACP,WAAW,CACZ,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,kCAAkC,CACtC,qBAA6B,EAC7B,UAAkB,EAClB,OAAiB,EACjB,WAAoB;QAEpB,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,oCAAoC,CAAC,CAChE,qBAAqB,EACrB,UAAU,EACV,OAAO,EACP,WAAW,CACZ,CAAC;IACJ,CAAC;CACF;AAhLD,yBAgLC"}
@@ -0,0 +1,45 @@
1
+ {
2
+ "$id": "https://dev.liquality.com/schema/block.json",
3
+ "title": "Block",
4
+ "description": "Blockchain block",
5
+ "type": "object",
6
+ "required": ["number", "hash", "timestamp", "size"],
7
+ "properties": {
8
+ "hash": {
9
+ "type": "string",
10
+ "title": "Hash"
11
+ },
12
+ "number": {
13
+ "type": "number",
14
+ "title": "Number",
15
+ "minimum": 0
16
+ },
17
+ "timestamp": {
18
+ "type": "number",
19
+ "title": "Timestamp",
20
+ "minimum": 0
21
+ },
22
+ "difficulty": {
23
+ "type": "number",
24
+ "title": "Difficulty",
25
+ "minLength": 1
26
+ },
27
+ "size": {
28
+ "type": "number",
29
+ "title": "Size",
30
+ "minimum": 0
31
+ },
32
+ "parentHash": {
33
+ "type": "string",
34
+ "title": "Parent Hash"
35
+ },
36
+ "nonce": {
37
+ "type": "number",
38
+ "title": "Nonce",
39
+ "minimum": 0
40
+ },
41
+ "_raw": {
42
+ "type": "object"
43
+ }
44
+ }
45
+ }
@@ -0,0 +1,45 @@
1
+ {
2
+ "$id": "https://dev.liquality.com/schema/transaction.json",
3
+ "title": "Transaction",
4
+ "description": "Blockchain transaction",
5
+ "type": "object",
6
+ "required": ["hash", "value"],
7
+ "properties": {
8
+ "blockHash": {
9
+ "type": "string",
10
+ "title": "Block Hash"
11
+ },
12
+ "blockNumber": {
13
+ "type": "number",
14
+ "title": "Block Number",
15
+ "minimum": 0
16
+ },
17
+ "hash": {
18
+ "type": "string",
19
+ "title": "Transaction Hash"
20
+ },
21
+ "value": {
22
+ "type": "number",
23
+ "title": "Value",
24
+ "minimum": 0
25
+ },
26
+ "confirmations": {
27
+ "type": "number",
28
+ "title": "Confirmations",
29
+ "minimum": 0
30
+ },
31
+ "feePrice": {
32
+ "type": "number",
33
+ "title": "Fee Price",
34
+ "minimum": 0
35
+ },
36
+ "fee": {
37
+ "type": "number",
38
+ "title": "Fee",
39
+ "minimum": 0
40
+ },
41
+ "_raw": {
42
+ "type": "object"
43
+ }
44
+ }
45
+ }
@@ -0,0 +1,3 @@
1
+ import Block from './Block.json';
2
+ import Transaction from './Transaction.json';
3
+ export { Block, Transaction };
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Transaction = exports.Block = void 0;
7
+ const Block_json_1 = __importDefault(require("./Block.json"));
8
+ exports.Block = Block_json_1.default;
9
+ const Transaction_json_1 = __importDefault(require("./Transaction.json"));
10
+ exports.Transaction = Transaction_json_1.default;
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/schema/index.ts"],"names":[],"mappings":";;;;;;AAAA,8DAAiC;AAGxB,gBAHF,oBAAK,CAGE;AAFd,0EAA6C;AAE7B,sBAFT,0BAAW,CAES"}
package/lib/Cfd.ts CHANGED
@@ -15,6 +15,7 @@ import {
15
15
  BlindRawTransactionResponse,
16
16
  CalculateEcSignatureRequest,
17
17
  CalculateEcSignatureResponse,
18
+ CfdProvider,
18
19
  ConvertAesRequest,
19
20
  ConvertAesResponse,
20
21
  ConvertEntropyToMnemonicRequest,
@@ -138,7 +139,7 @@ import {
138
139
  VerifySignResponse,
139
140
  } from '@atomicfinance/types';
140
141
 
141
- export default class Cfd {
142
+ export default class Cfd implements CfdProvider {
142
143
  client: any;
143
144
 
144
145
  constructor(client: any) {
package/lib/Chain.ts ADDED
@@ -0,0 +1,173 @@
1
+ import { InvalidProviderResponseError } from '@atomicfinance/errors';
2
+ import {
3
+ Address,
4
+ BigNumber,
5
+ Block,
6
+ ChainProvider,
7
+ FeeDetails,
8
+ FeeProvider,
9
+ SendOptions,
10
+ Transaction,
11
+ } from '@atomicfinance/types';
12
+ import { isBoolean, isNumber, isObject, isString } from 'lodash';
13
+
14
+ export default class Chain implements ChainProvider, FeeProvider {
15
+ client: any;
16
+
17
+ constructor(client: any) {
18
+ this.client = client;
19
+ }
20
+
21
+ /** @inheritdoc */
22
+ async generateBlock(numberOfBlocks: number): Promise<void> {
23
+ if (!isNumber(numberOfBlocks)) {
24
+ throw new TypeError('First argument should be a number');
25
+ }
26
+
27
+ return this.client.getMethod('generateBlock')(numberOfBlocks);
28
+ }
29
+
30
+ /** @inheritdoc */
31
+ async getBlockByHash(blockHash: string, includeTx = false): Promise<Block> {
32
+ if (!isString(blockHash)) {
33
+ throw new TypeError('Block hash should be a string');
34
+ }
35
+
36
+ if (!isBoolean(includeTx)) {
37
+ throw new TypeError('Second parameter should be boolean');
38
+ }
39
+
40
+ const block = await this.client.getMethod('getBlockByHash')(
41
+ blockHash,
42
+ includeTx,
43
+ );
44
+ this.client.assertValidBlock(block);
45
+ return block;
46
+ }
47
+
48
+ /** @inheritdoc */
49
+ async getBlockByNumber(
50
+ blockNumber: number,
51
+ includeTx = false,
52
+ ): Promise<Block> {
53
+ if (!isNumber(blockNumber)) {
54
+ throw new TypeError('Invalid Block number');
55
+ }
56
+
57
+ if (!isBoolean(includeTx)) {
58
+ throw new TypeError('Second parameter should be boolean');
59
+ }
60
+
61
+ const block = await this.client.getMethod('getBlockByNumber')(
62
+ blockNumber,
63
+ includeTx,
64
+ );
65
+ this.client.assertValidBlock(block);
66
+ return block;
67
+ }
68
+
69
+ /** @inheritdoc */
70
+ async getBlockHeight(): Promise<number> {
71
+ const blockHeight = await this.client.getMethod('getBlockHeight')();
72
+
73
+ if (!isNumber(blockHeight)) {
74
+ throw new InvalidProviderResponseError(
75
+ 'Provider returned an invalid block height',
76
+ );
77
+ }
78
+
79
+ return blockHeight;
80
+ }
81
+
82
+ /** @inheritdoc */
83
+ async getTransactionByHash(txHash: string): Promise<Transaction> {
84
+ if (!isString(txHash)) {
85
+ throw new TypeError('Transaction hash should be a string');
86
+ }
87
+
88
+ const transaction = await this.client.getMethod('getTransactionByHash')(
89
+ txHash,
90
+ );
91
+ if (transaction) {
92
+ this.client.assertValidTransaction(transaction);
93
+ }
94
+
95
+ return transaction;
96
+ }
97
+
98
+ /** @inheritdoc */
99
+ async getBalance(addresses: (string | Address)[]): Promise<BigNumber> {
100
+ const balance = await this.client.getMethod('getBalance')(addresses);
101
+
102
+ if (!BigNumber.isBigNumber(balance)) {
103
+ throw new InvalidProviderResponseError(
104
+ 'Provider returned an invalid response',
105
+ );
106
+ }
107
+
108
+ return balance;
109
+ }
110
+
111
+ /** @inheritdoc */
112
+ async sendTransaction(options: SendOptions): Promise<Transaction> {
113
+ const transaction = await this.client.getMethod('sendTransaction')(options);
114
+ this.client.assertValidTransaction(transaction);
115
+ return transaction;
116
+ }
117
+
118
+ /** @inheritdoc */
119
+ async sendSweepTransaction(
120
+ address: Address | string,
121
+ fee?: number,
122
+ ): Promise<Transaction> {
123
+ return this.client.getMethod('sendSweepTransaction')(address, fee);
124
+ }
125
+
126
+ /** @inheritdoc */
127
+ async updateTransactionFee(
128
+ tx: string | Transaction,
129
+ newFee: number,
130
+ ): Promise<Transaction> {
131
+ if (isObject(tx)) {
132
+ this.client.assertValidTransaction(tx);
133
+ } else {
134
+ if (!isString(tx)) {
135
+ throw new TypeError('Transaction should be a string or object');
136
+ }
137
+ }
138
+
139
+ const transaction = await this.client.getMethod('updateTransactionFee')(
140
+ tx,
141
+ newFee,
142
+ );
143
+ this.client.assertValidTransaction(transaction);
144
+ return transaction;
145
+ }
146
+
147
+ /** @inheritdoc */
148
+ async sendBatchTransaction(
149
+ transactions: SendOptions[],
150
+ ): Promise<Transaction> {
151
+ return this.client.getMethod('sendBatchTransaction')(transactions);
152
+ }
153
+
154
+ /** @inheritdoc */
155
+ async sendRawTransaction(rawTransaction: string): Promise<string> {
156
+ const txHash = await this.client.getMethod('sendRawTransaction')(
157
+ rawTransaction,
158
+ );
159
+
160
+ if (!isString(txHash)) {
161
+ throw new InvalidProviderResponseError(
162
+ 'sendRawTransaction method should return a transaction id string',
163
+ );
164
+ }
165
+
166
+ return txHash;
167
+ }
168
+
169
+ /** @inheritdoc */
170
+ async getFees(): Promise<FeeDetails> {
171
+ return this.client.getMethod('getFees')();
172
+ }
173
+ }