@atomicfinance/client 2.5.0 → 3.0.1
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/.turbo/turbo-build.log +1 -0
- package/.turbo/turbo-test.log +1 -0
- package/CHANGELOG.md +31 -0
- package/dist/Cfd.d.ts +2 -2
- package/dist/Cfd.js +8 -11
- package/dist/Cfd.js.map +1 -1
- package/dist/Chain.d.ts +29 -0
- package/dist/Chain.js +110 -0
- package/dist/Chain.js.map +1 -0
- package/dist/Client.d.ts +44 -7
- package/dist/Client.js +120 -32
- package/dist/Client.js.map +1 -1
- package/dist/Dlc.d.ts +5 -2
- package/dist/Dlc.js +113 -95
- package/dist/Dlc.js.map +1 -1
- package/dist/Wallet.d.ts +59 -4
- package/dist/Wallet.js +100 -17
- package/dist/Wallet.js.map +1 -1
- package/dist/index.d.ts +0 -0
- package/dist/index.js +11 -23
- package/dist/index.js.map +0 -0
- package/dist/schema/Block.json +45 -0
- package/dist/schema/Transaction.json +45 -0
- package/dist/schema/index.d.ts +3 -0
- package/dist/schema/index.js +11 -0
- package/dist/schema/index.js.map +1 -0
- package/lib/Cfd.ts +2 -1
- package/lib/Chain.ts +173 -0
- package/lib/Client.ts +153 -11
- package/lib/Dlc.ts +24 -1
- package/lib/Wallet.ts +129 -10
- package/lib/schema/Block.json +45 -0
- package/lib/schema/Transaction.json +45 -0
- package/lib/schema/index.ts +4 -0
- package/package.json +9 -11
- package/LICENSE +0 -674
- package/README.md +0 -11
|
@@ -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,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
|
+
}
|
package/lib/Client.ts
CHANGED
|
@@ -1,36 +1,178 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {
|
|
2
|
+
DuplicateProviderError,
|
|
3
|
+
InvalidProviderError,
|
|
4
|
+
InvalidProviderResponseError,
|
|
5
|
+
NoProviderError,
|
|
6
|
+
UnimplementedMethodError,
|
|
7
|
+
UnsupportedMethodError,
|
|
8
|
+
} from '@atomicfinance/errors';
|
|
9
|
+
import Provider from '@atomicfinance/provider';
|
|
10
|
+
import { Block, IClient, Transaction } from '@atomicfinance/types';
|
|
11
|
+
import Ajv from 'ajv';
|
|
12
|
+
import { find, findLast, findLastIndex, isFunction } from 'lodash';
|
|
4
13
|
|
|
5
14
|
import Cfd from './Cfd';
|
|
15
|
+
import Chain from './Chain';
|
|
6
16
|
import Dlc from './Dlc';
|
|
17
|
+
import {
|
|
18
|
+
Block as BlockSchema,
|
|
19
|
+
Transaction as TransactionSchema,
|
|
20
|
+
} from './schema';
|
|
7
21
|
import Wallet from './Wallet';
|
|
8
22
|
|
|
9
|
-
export default class
|
|
23
|
+
export default class Client implements IClient {
|
|
24
|
+
_providers: Provider[];
|
|
10
25
|
version: string;
|
|
26
|
+
|
|
27
|
+
validateTransaction: Ajv.ValidateFunction;
|
|
28
|
+
validateBlock: Ajv.ValidateFunction;
|
|
29
|
+
|
|
11
30
|
_dlc: Dlc;
|
|
12
31
|
_cfd: Cfd;
|
|
13
|
-
|
|
32
|
+
_wallet: Wallet;
|
|
33
|
+
_chain: Chain;
|
|
14
34
|
identifier: string;
|
|
15
35
|
|
|
16
36
|
/**
|
|
17
37
|
* Client
|
|
18
38
|
*/
|
|
19
|
-
constructor(provider?: Provider
|
|
20
|
-
super(provider, version);
|
|
21
|
-
|
|
39
|
+
constructor(provider?: Provider, version?: string) {
|
|
22
40
|
/**
|
|
23
41
|
* @type {Array}
|
|
24
42
|
*/
|
|
25
43
|
this._providers = [];
|
|
26
44
|
|
|
45
|
+
/**
|
|
46
|
+
* @type {string}
|
|
47
|
+
*/
|
|
48
|
+
this.version = version;
|
|
49
|
+
|
|
50
|
+
if (provider) {
|
|
51
|
+
this.addProvider(provider);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const ajv = new Ajv();
|
|
55
|
+
this.validateTransaction = ajv.compile(TransactionSchema);
|
|
56
|
+
this.validateBlock = ajv.compile(BlockSchema);
|
|
57
|
+
|
|
58
|
+
this._chain = new Chain(this);
|
|
27
59
|
this._dlc = new Dlc(this);
|
|
28
60
|
this._cfd = new Cfd(this);
|
|
29
|
-
this.
|
|
61
|
+
this._wallet = new Wallet(this);
|
|
30
62
|
|
|
31
63
|
this.identifier = 'Client';
|
|
32
64
|
}
|
|
33
65
|
|
|
66
|
+
/**
|
|
67
|
+
* Add a provider
|
|
68
|
+
* @param {!Provider} provider - The provider instance or RPC connection string
|
|
69
|
+
* @return {Client} Returns instance of Client
|
|
70
|
+
* @throws {InvalidProviderError} When invalid provider is provider
|
|
71
|
+
* @throws {DuplicateProviderError} When same provider is added again
|
|
72
|
+
*/
|
|
73
|
+
addProvider(provider: Provider) {
|
|
74
|
+
if (!isFunction(provider.setClient)) {
|
|
75
|
+
throw new InvalidProviderError('Provider should have "setClient" method');
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const duplicate = find(
|
|
79
|
+
this._providers,
|
|
80
|
+
(_provider) => provider.constructor === _provider.constructor,
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
if (duplicate) {
|
|
84
|
+
throw new DuplicateProviderError('Duplicate provider');
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
provider.setClient(this);
|
|
88
|
+
this._providers.push(provider);
|
|
89
|
+
|
|
90
|
+
return this;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Check the availability of a method.
|
|
95
|
+
* @param {!string} method - Name of the method to look for in the provider stack
|
|
96
|
+
* @param {boolean|object} [requestor=false] - If provided, it returns providers only
|
|
97
|
+
* above the requestor in the stack.
|
|
98
|
+
* @return {Provider} Returns a provider instance associated with the requested method
|
|
99
|
+
* @throws {NoProviderError} When no provider is available in the stack.
|
|
100
|
+
* @throws {UnimplementedMethodError} When the requested method is not provided
|
|
101
|
+
* by any provider above requestor in the provider stack
|
|
102
|
+
* @throws {UnsupportedMethodError} When requested method is not supported by
|
|
103
|
+
* version specified
|
|
104
|
+
*/
|
|
105
|
+
getProviderForMethod(method: string, requestor = false) {
|
|
106
|
+
if (this._providers.length === 0) {
|
|
107
|
+
throw new NoProviderError(
|
|
108
|
+
'No provider provided. Add a provider to the client',
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
let indexOfRequestor = requestor
|
|
113
|
+
? findLastIndex(
|
|
114
|
+
this._providers,
|
|
115
|
+
(provider) => requestor.constructor === provider.constructor,
|
|
116
|
+
)
|
|
117
|
+
: this._providers.length;
|
|
118
|
+
|
|
119
|
+
if (indexOfRequestor === -1) indexOfRequestor = 0;
|
|
120
|
+
|
|
121
|
+
const provider = findLast(
|
|
122
|
+
this._providers,
|
|
123
|
+
(provider) => isFunction((<any>provider)[method]),
|
|
124
|
+
indexOfRequestor - 1,
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
if (provider == null) {
|
|
128
|
+
throw new UnimplementedMethodError(`Unimplemented method "${method}"`);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (isFunction((<any>provider)._checkMethodVersionSupport)) {
|
|
132
|
+
if (!(<any>provider)._checkMethodVersionSupport(method, this.version)) {
|
|
133
|
+
throw new UnsupportedMethodError(
|
|
134
|
+
`Method "${method}" is not supported by version "${this.version}"`,
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return provider;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Helper method that returns method from a provider.
|
|
144
|
+
* @param {!string} method - Name of the method to look for in the provider stack
|
|
145
|
+
* @param {object} [requestor] - If provided, it returns method from providers only
|
|
146
|
+
* above the requestor in the stack.
|
|
147
|
+
* @return {function} Returns method from provider instance associated with the requested method
|
|
148
|
+
*/
|
|
149
|
+
getMethod(method: string, requestor?: any) {
|
|
150
|
+
const provider = this.getProviderForMethod(method, requestor);
|
|
151
|
+
return (<any>provider)[method].bind(provider);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
assertValidTransaction(transaction: Transaction) {
|
|
155
|
+
if (!this.validateTransaction(transaction)) {
|
|
156
|
+
const { errors } = this.validateTransaction;
|
|
157
|
+
throw new InvalidProviderResponseError(
|
|
158
|
+
`Provider returned an invalid transaction, "${errors[0].dataPath}" ${errors[0].message}`,
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
assertValidBlock(block: Block) {
|
|
164
|
+
if (!this.validateBlock(block)) {
|
|
165
|
+
const { errors } = this.validateBlock;
|
|
166
|
+
throw new InvalidProviderResponseError(
|
|
167
|
+
`Provider returned an invalid block, "${errors[0].dataPath}" ${errors[0].message}`,
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
get chain() {
|
|
173
|
+
return this._chain;
|
|
174
|
+
}
|
|
175
|
+
|
|
34
176
|
get dlc() {
|
|
35
177
|
return this._dlc;
|
|
36
178
|
}
|
|
@@ -39,7 +181,7 @@ export default class FinanceClient extends Client {
|
|
|
39
181
|
return this._cfd;
|
|
40
182
|
}
|
|
41
183
|
|
|
42
|
-
get
|
|
43
|
-
return this.
|
|
184
|
+
get wallet() {
|
|
185
|
+
return this._wallet;
|
|
44
186
|
}
|
|
45
187
|
}
|
package/lib/Dlc.ts
CHANGED
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
CreateFundTransactionResponse,
|
|
17
17
|
CreateRefundTransactionRequest,
|
|
18
18
|
CreateRefundTransactionResponse,
|
|
19
|
+
DlcProvider,
|
|
19
20
|
GetRawFundTxSignatureRequest,
|
|
20
21
|
GetRawFundTxSignatureResponse,
|
|
21
22
|
GetRawRefundTxSignatureRequest,
|
|
@@ -47,7 +48,7 @@ import {
|
|
|
47
48
|
} from '@node-dlc/messaging';
|
|
48
49
|
import { Tx } from '@node-lightning/bitcoin';
|
|
49
50
|
|
|
50
|
-
export default class Dlc {
|
|
51
|
+
export default class Dlc implements DlcProvider {
|
|
51
52
|
client: any;
|
|
52
53
|
|
|
53
54
|
constructor(client: any) {
|
|
@@ -391,6 +392,28 @@ export default class Dlc {
|
|
|
391
392
|
return this.client.getMethod('VerifyCetAdaptorSignature')(jsonObject);
|
|
392
393
|
}
|
|
393
394
|
|
|
395
|
+
async VerifyCetAdaptorSignatures(
|
|
396
|
+
jsonObject: VerifyCetAdaptorSignaturesRequest,
|
|
397
|
+
): Promise<VerifyCetAdaptorSignaturesResponse> {
|
|
398
|
+
return this.client.getMethod('VerifyCetAdaptorSignatures')(jsonObject);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
async GetInputsForAmount(
|
|
402
|
+
amount: bigint,
|
|
403
|
+
feeRatePerVb: bigint,
|
|
404
|
+
fixedInputs: Input[],
|
|
405
|
+
): Promise<Input[]> {
|
|
406
|
+
return this.client.getMethod('GetInputsForAmount')(
|
|
407
|
+
amount,
|
|
408
|
+
feeRatePerVb,
|
|
409
|
+
fixedInputs,
|
|
410
|
+
);
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
async SignCet(jsonObject: SignCetRequest): Promise<SignCetResponse> {
|
|
414
|
+
return this.client.getMethod('SignCet')(jsonObject);
|
|
415
|
+
}
|
|
416
|
+
|
|
394
417
|
async VerifyCetAdaptorSignaturesRequest(
|
|
395
418
|
jsonObject: VerifyCetAdaptorSignaturesRequest,
|
|
396
419
|
): Promise<VerifyCetAdaptorSignaturesResponse> {
|
package/lib/Wallet.ts
CHANGED
|
@@ -1,13 +1,140 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
InvalidProviderResponseError,
|
|
3
|
+
UnimplementedMethodError,
|
|
4
|
+
} from '@atomicfinance/errors';
|
|
5
|
+
import {
|
|
6
|
+
Address,
|
|
7
|
+
CreateMultisigResponse,
|
|
8
|
+
Input,
|
|
9
|
+
Output,
|
|
10
|
+
WalletProvider,
|
|
11
|
+
} from '@atomicfinance/types';
|
|
2
12
|
import { Transaction } from 'bitcoinjs-lib';
|
|
13
|
+
import { isArray } from 'lodash';
|
|
3
14
|
|
|
4
|
-
export default class Wallet {
|
|
15
|
+
export default class Wallet implements WalletProvider {
|
|
5
16
|
client: any;
|
|
6
17
|
|
|
7
18
|
constructor(client: any) {
|
|
8
19
|
this.client = client;
|
|
9
20
|
}
|
|
10
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Get addresses/accounts of the user.
|
|
24
|
+
* @param {number} [startingIndex] - Index to start
|
|
25
|
+
* @param {number} [numAddresses] - Number of addresses to retrieve
|
|
26
|
+
* @param {boolean} [change] - True for change addresses
|
|
27
|
+
* @return {Promise<Address[], InvalidProviderResponseError>} Resolves with a list
|
|
28
|
+
* of addresses.
|
|
29
|
+
* Rejects with InvalidProviderResponseError if provider's response is invalid.
|
|
30
|
+
*/
|
|
31
|
+
async getAddresses(
|
|
32
|
+
startingIndex?: number,
|
|
33
|
+
numAddresses?: number,
|
|
34
|
+
change?: boolean,
|
|
35
|
+
): Promise<Address[]> {
|
|
36
|
+
const addresses = await this.client.getMethod('getAddresses')(
|
|
37
|
+
startingIndex,
|
|
38
|
+
numAddresses,
|
|
39
|
+
change,
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
if (!isArray(addresses)) {
|
|
43
|
+
throw new InvalidProviderResponseError(
|
|
44
|
+
'Provider returned an invalid response',
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return addresses;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Get used addresses/accounts of the user.
|
|
53
|
+
* @param {number} [numAddressPerCall] - Number of addresses to retrieve per call
|
|
54
|
+
* @return {Promise<Address[], InvalidProviderResponseError>} Resolves with a list
|
|
55
|
+
* of addresses.
|
|
56
|
+
* Rejects with InvalidProviderResponseError if provider's response is invalid.
|
|
57
|
+
*/
|
|
58
|
+
async getUsedAddresses(numAddressPerCall?: number): Promise<Address[]> {
|
|
59
|
+
return this.client.getMethod('getUsedAddresses')(numAddressPerCall);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Get unused address/account of the user.
|
|
64
|
+
* @param {boolean} [change] - True for change addresses
|
|
65
|
+
* @param {number} [numAddressPerCall] - Number of addresses to retrieve per call
|
|
66
|
+
* @return {Promise<Address, InvalidProviderResponseError>} Resolves with a address
|
|
67
|
+
* object.
|
|
68
|
+
* Rejects with InvalidProviderResponseError if provider's response is invalid.
|
|
69
|
+
*/
|
|
70
|
+
async getUnusedAddress(
|
|
71
|
+
change?: boolean,
|
|
72
|
+
numAddressPerCall?: number,
|
|
73
|
+
): Promise<Address> {
|
|
74
|
+
return this.client.getMethod('getUnusedAddress')(change, numAddressPerCall);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Sign a message.
|
|
79
|
+
* @param {!string} message - Message to be signed.
|
|
80
|
+
* @param {!string} from - The address from which the message is signed.
|
|
81
|
+
* @return {Promise<string>} Resolves with a signed message.
|
|
82
|
+
*/
|
|
83
|
+
async signMessage(message: string, from: string): Promise<string> {
|
|
84
|
+
return this.client.getMethod('signMessage')(message, from);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Retrieve the network connected to by the wallet
|
|
89
|
+
* @return {Promise<any>} Resolves with the network object
|
|
90
|
+
*/
|
|
91
|
+
async getConnectedNetwork(): Promise<any> {
|
|
92
|
+
return this.client.getMethod('getConnectedNetwork')();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Retrieve the availability status of the wallet
|
|
97
|
+
* @return {Promise<Boolean>} True if the wallet is available to use
|
|
98
|
+
*/
|
|
99
|
+
async isWalletAvailable(): Promise<boolean> {
|
|
100
|
+
return this.client.getMethod('isWalletAvailable')();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Flag indicating if the wallet allows apps to update transaction fees
|
|
105
|
+
* @return {Promise<Boolean>} True if wallet accepts fee updating
|
|
106
|
+
*/
|
|
107
|
+
get canUpdateFee(): boolean {
|
|
108
|
+
try {
|
|
109
|
+
return this.client.getMethod('canUpdateFee')();
|
|
110
|
+
} catch (e) {
|
|
111
|
+
if (!(e instanceof UnimplementedMethodError)) throw e;
|
|
112
|
+
}
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Retrieve the private key for the account
|
|
118
|
+
* @return {Promise<string>} Resolves with the key as a string
|
|
119
|
+
*/
|
|
120
|
+
exportPrivateKey(): Promise<string> {
|
|
121
|
+
return this.client.getMethod('exportPrivateKey')();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
findAddress(addresses: string[]) {
|
|
125
|
+
return this.client.getMethod('findAddress')(addresses);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
setUnusedAddressesBlacklist(unusedAddressesBlacklist: any) {
|
|
129
|
+
return this.client.getMethod('setUnusedAddressesBlacklist')(
|
|
130
|
+
unusedAddressesBlacklist,
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
getUnusedAddressesBlacklist() {
|
|
135
|
+
return this.client.getMethod('getUnusedAddressesBlacklist')();
|
|
136
|
+
}
|
|
137
|
+
|
|
11
138
|
createMultisig(m: number, pubkeys: string[]): CreateMultisigResponse {
|
|
12
139
|
return this.client.getMethod('createMultisig')(m, pubkeys);
|
|
13
140
|
}
|
|
@@ -61,12 +188,4 @@ export default class Wallet {
|
|
|
61
188
|
fixedInputs,
|
|
62
189
|
);
|
|
63
190
|
}
|
|
64
|
-
|
|
65
|
-
async getUnusedAddress(change = false, numAddressPerCall = 100) {
|
|
66
|
-
return this.client.getMethod('getUnusedAddress')(change, numAddressPerCall);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
async quickFindAddress(addresses: string[]) {
|
|
70
|
-
return this.client.getMethod('quickFindAddress')(addresses);
|
|
71
|
-
}
|
|
72
191
|
}
|