@atomicfinance/client 3.5.3 → 3.6.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.
@@ -1 +0,0 @@
1
-
package/CHANGELOG.md CHANGED
@@ -1,5 +1,35 @@
1
1
  # @atomicfinance/client
2
2
 
3
+ ## 3.6.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 3c85279: Upgrade bitcoinjs-lib v6 with ECPair migration
8
+ - Updated dependencies [3c85279]
9
+ - @atomicfinance/bitcoin-utils@3.6.1
10
+ - @atomicfinance/errors@3.6.1
11
+ - @atomicfinance/provider@3.6.1
12
+ - @atomicfinance/types@3.6.1
13
+
14
+ ## 3.6.0
15
+
16
+ ### Minor Changes
17
+
18
+ - cbf35c5: - **BREAKING CHANGE**: Migrated from `@node-lightning` packages to `@node-dlc` packages
19
+ - Updated all imports from `@node-lightning/*` to `@node-dlc/*`
20
+ - Update @node-dlc 0.24.0 and Node 18+
21
+ - Upgraded Node.js requirement to v18+
22
+ - Updated cfd-dlc-js to v0.0.51 and cfd-js to v0.3.13
23
+ - Removed unused dependencies: lerna, mocha-webpack
24
+
25
+ ### Patch Changes
26
+
27
+ - Updated dependencies [cbf35c5]
28
+ - @atomicfinance/types@3.6.0
29
+ - @atomicfinance/bitcoin-utils@3.6.0
30
+ - @atomicfinance/errors@3.6.0
31
+ - @atomicfinance/provider@3.6.0
32
+
3
33
  ## 3.5.3
4
34
 
5
35
  ### Patch Changes
package/dist/Dlc.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { AddSignaturesToRefundTxRequest, AddSignaturesToRefundTxResponse, AddSignatureToFundTransactionRequest, AddSignatureToFundTransactionResponse, BatchAcceptDlcOfferResponse, BatchSignDlcAcceptResponse, CreateCetAdaptorSignatureRequest, CreateCetAdaptorSignatureResponse, CreateCetAdaptorSignaturesRequest, CreateCetAdaptorSignaturesResponse, CreateCetRequest, CreateCetResponse, CreateDlcTransactionsRequest, CreateDlcTransactionsResponse, CreateDlcTxsResponse, CreateFundTransactionRequest, CreateFundTransactionResponse, CreateRefundTransactionRequest, CreateRefundTransactionResponse, DlcProvider, GetRawFundTxSignatureRequest, GetRawFundTxSignatureResponse, GetRawRefundTxSignatureRequest, GetRawRefundTxSignatureResponse, Input, SignCetRequest, SignCetResponse, SignFundTransactionRequest, SignFundTransactionResponse, VerifyCetAdaptorSignatureRequest, VerifyCetAdaptorSignatureResponse, VerifyCetAdaptorSignaturesRequest, VerifyCetAdaptorSignaturesResponse, VerifyFundTxSignatureRequest, VerifyFundTxSignatureResponse, VerifyRefundTxSignatureRequest, VerifyRefundTxSignatureResponse } from '@atomicfinance/types';
2
+ import { Tx } from '@node-dlc/bitcoin';
2
3
  import { ContractInfo, DlcAccept, DlcClose, DlcCloseMetadata, DlcOffer, DlcSign, DlcTransactions, FundingInput, OracleAttestationV0 } from '@node-dlc/messaging';
3
- import { Tx } from '@node-lightning/bitcoin';
4
4
  export default class Dlc implements DlcProvider {
5
5
  client: any;
6
6
  constructor(client: any);
package/lib/Dlc.ts CHANGED
@@ -37,6 +37,7 @@ import {
37
37
  VerifyRefundTxSignatureRequest,
38
38
  VerifyRefundTxSignatureResponse,
39
39
  } from '@atomicfinance/types';
40
+ import { Tx } from '@node-dlc/bitcoin';
40
41
  import {
41
42
  ContractInfo,
42
43
  DlcAccept,
@@ -48,7 +49,6 @@ import {
48
49
  FundingInput,
49
50
  OracleAttestationV0,
50
51
  } from '@node-dlc/messaging';
51
- import { Tx } from '@node-lightning/bitcoin';
52
52
 
53
53
  export default class Dlc implements DlcProvider {
54
54
  client: any;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@atomicfinance/client",
3
3
  "umdName": "Client",
4
- "version": "3.5.3",
4
+ "version": "3.6.1",
5
5
  "description": "Bitcoin Abstraction Layer Provider",
6
6
  "author": "Atomic Finance <info@atomic.finance>",
7
7
  "homepage": "",
@@ -15,12 +15,12 @@
15
15
  "lint:fix": "../../node_modules/.bin/eslint --fix --ignore-path ../../.eslintignore -c ../../.eslintrc.js ."
16
16
  },
17
17
  "dependencies": {
18
- "@atomicfinance/bitcoin-utils": "^3.5.3",
19
- "@atomicfinance/errors": "^3.5.3",
20
- "@atomicfinance/provider": "^3.5.3",
21
- "@atomicfinance/types": "^3.5.3",
22
- "@node-dlc/messaging": "0.23.6",
23
- "@node-lightning/bitcoin": "0.26.1",
18
+ "@atomicfinance/bitcoin-utils": "^3.6.1",
19
+ "@atomicfinance/errors": "^3.6.1",
20
+ "@atomicfinance/provider": "^3.6.1",
21
+ "@atomicfinance/types": "^3.6.1",
22
+ "@node-dlc/bitcoin": "0.24.0",
23
+ "@node-dlc/messaging": "0.24.0",
24
24
  "ajv": "^6.10.0",
25
25
  "lodash": "^4.17.20"
26
26
  },
package/lib/Cfd.js DELETED
@@ -1,216 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class Cfd {
4
- constructor(client) {
5
- this.client = client;
6
- }
7
- async AddMultisigSign(jsonObject) {
8
- return this.client.getMethod('AddMultisigSign')(jsonObject);
9
- }
10
- async AddPubkeyHashSign(jsonObject) {
11
- return this.client.getMethod('AddPubkeyHashSign')(jsonObject);
12
- }
13
- async AddRawTransaction(jsonObject) {
14
- return this.client.getMethod('AddRawTransaction')(jsonObject);
15
- }
16
- async AddScriptHashSign(jsonObject) {
17
- return this.client.getMethod('AddScriptHashSign')(jsonObject);
18
- }
19
- async AddSign(jsonObject) {
20
- return this.client.getMethod('AddSign')(jsonObject);
21
- }
22
- async AppendDescriptorChecksum(jsonObject) {
23
- return this.client.getMethod('AppendDescriptorChecksum')(jsonObject);
24
- }
25
- async BlindRawTransaction(jsonObject) {
26
- return this.client.getMethod('BlindRawTransaction')(jsonObject);
27
- }
28
- async CalculateEcSignature(jsonObject) {
29
- return this.client.getMethod('CalculateEcSignature')(jsonObject);
30
- }
31
- async ConvertAes(jsonObject) {
32
- return this.client.getMethod('ConvertAes')(jsonObject);
33
- }
34
- async ConvertEntropyToMnemonic(jsonObject) {
35
- return this.client.getMethod('ConvertEntropyToMnemonic')(jsonObject);
36
- }
37
- async ConvertMnemonicToSeed(jsonObject) {
38
- return this.client.getMethod('ConvertMnemonicToSeed')(jsonObject);
39
- }
40
- async CreateAddress(jsonObject) {
41
- return this.client.getMethod('CreateAddress')(jsonObject);
42
- }
43
- async CreateDescriptor(jsonObject) {
44
- return this.client.getMethod('CreateDescriptor')(jsonObject);
45
- }
46
- async CreateExtkey(jsonObject) {
47
- return this.client.getMethod('CreateExtkey')(jsonObject);
48
- }
49
- async CreateExtkeyFromParent(jsonObject) {
50
- return this.client.getMethod('CreateExtkeyFromParent')(jsonObject);
51
- }
52
- async CreateExtkeyFromParentKey(jsonObject) {
53
- return this.client.getMethod('CreateExtkeyFromParentKey')(jsonObject);
54
- }
55
- async CreateExtkeyFromParentPath(jsonObject) {
56
- return this.client.getMethod('CreateExtkeyFromParentPath')(jsonObject);
57
- }
58
- async CreateExtkeyFromSeed(jsonObject) {
59
- return this.client.getMethod('CreateExtkeyFromSeed')(jsonObject);
60
- }
61
- async CreateExtPubkey(jsonObject) {
62
- return this.client.getMethod('CreateExtPubkey')(jsonObject);
63
- }
64
- async CreateKeyPair(jsonObject) {
65
- return this.client.getMethod('CreateKeyPair')(jsonObject);
66
- }
67
- async CreateMultisigScriptSig(jsonObject) {
68
- return this.client.getMethod('CreateMultisigScriptSig')(jsonObject);
69
- }
70
- async CreateScript(jsonObject) {
71
- return this.client.getMethod('CreateScript')(jsonObject);
72
- }
73
- async DecodeBase58(jsonObject) {
74
- return this.client.getMethod('DecodeBase58')(jsonObject);
75
- }
76
- async DecodeDerSignatureToRaw(jsonObject) {
77
- return this.client.getMethod('DecodeDerSignatureToRaw')(jsonObject);
78
- }
79
- async DecodeRawTransaction(jsonObject) {
80
- return this.client.getMethod('DecodeRawTransaction')(jsonObject);
81
- }
82
- async ElementsAddRawTransaction(jsonObject) {
83
- return this.client.getMethod('ElementsAddRawTransaction')(jsonObject);
84
- }
85
- async CreateDestroyAmount(jsonObject) {
86
- return this.client.getMethod('CreateDestroyAmount')(jsonObject);
87
- }
88
- async CreatePegInAddress(jsonObject) {
89
- return this.client.getMethod('CreatePegInAddress')(jsonObject);
90
- }
91
- async CreateRawPegin(jsonObject) {
92
- return this.client.getMethod('CreateRawPegin')(jsonObject);
93
- }
94
- async CreateRawPegout(jsonObject) {
95
- return this.client.getMethod('CreateRawPegout')(jsonObject);
96
- }
97
- async ElementsCreateRawTransaction(jsonObject) {
98
- return this.client.getMethod('ElementsCreateRawTransaction')(jsonObject);
99
- }
100
- async ElementsDecodeRawTransaction(jsonObject) {
101
- return this.client.getMethod('ElementsDecodeRawTransaction')(jsonObject);
102
- }
103
- async GetConfidentialAddress(jsonObject) {
104
- return this.client.getMethod('GetConfidentialAddress')(jsonObject);
105
- }
106
- async GetUnblindedAddress(jsonObject) {
107
- return this.client.getMethod('GetUnblindedAddress')(jsonObject);
108
- }
109
- async SetRawIssueAsset(jsonObject) {
110
- return this.client.getMethod('SetRawIssueAsset')(jsonObject);
111
- }
112
- async SetRawReissueAsset(jsonObject) {
113
- return this.client.getMethod('SetRawReissueAsset')(jsonObject);
114
- }
115
- async UnblindRawTransaction(jsonObject) {
116
- return this.client.getMethod('UnblindRawTransaction')(jsonObject);
117
- }
118
- async EncodeBase58(jsonObject) {
119
- return this.client.getMethod('EncodeBase58')(jsonObject);
120
- }
121
- async EncodeSignatureByDer(jsonObject) {
122
- return this.client.getMethod('EncodeSignatureByDer')(jsonObject);
123
- }
124
- async EstimateFee(jsonObject) {
125
- return this.client.getMethod('EstimateFee')(jsonObject);
126
- }
127
- async FundRawTransaction(jsonObject) {
128
- return this.client.getMethod('FundRawTransaction')(jsonObject);
129
- }
130
- async GetAddressInfo(jsonObject) {
131
- return this.client.getMethod('GetAddressInfo')(jsonObject);
132
- }
133
- async GetAddressesFromMultisig(jsonObject) {
134
- return this.client.getMethod('GetAddressesFromMultisig')(jsonObject);
135
- }
136
- async GetCommitment(jsonObject) {
137
- return this.client.getMethod('GetCommitment')(jsonObject);
138
- }
139
- async GetCompressedPubkey(jsonObject) {
140
- return this.client.getMethod('GetCompressedPubkey')(jsonObject);
141
- }
142
- async GetDefaultBlindingKey(jsonObject) {
143
- return this.client.getMethod('GetDefaultBlindingKey')(jsonObject);
144
- }
145
- async GetExtkeyInfo(jsonObject) {
146
- return this.client.getMethod('GetExtkeyInfo')(jsonObject);
147
- }
148
- async GetIssuanceBlindingKey(jsonObject) {
149
- return this.client.getMethod('GetIssuanceBlindingKey')(jsonObject);
150
- }
151
- async GetMnemonicWordlist(jsonObject) {
152
- return this.client.getMethod('GetMnemonicWordlist')(jsonObject);
153
- }
154
- async GetPrivkeyFromExtkey(jsonObject) {
155
- return this.client.getMethod('GetPrivkeyFromExtkey')(jsonObject);
156
- }
157
- async GetPrivkeyFromWif(jsonObject) {
158
- return this.client.getMethod('GetPrivkeyFromWif')(jsonObject);
159
- }
160
- async GetPrivkeyWif(jsonObject) {
161
- return this.client.getMethod('GetPrivkeyWif')(jsonObject);
162
- }
163
- async GetPubkeyFromExtkey(jsonObject) {
164
- return this.client.getMethod('GetPubkeyFromExtkey')(jsonObject);
165
- }
166
- async GetPubkeyFromPrivkey(jsonObject) {
167
- return this.client.getMethod('GetPubkeyFromPrivkey')(jsonObject);
168
- }
169
- async GetWitnessStackNum(jsonObject) {
170
- return this.client.getMethod('GetWitnessStackNum')(jsonObject);
171
- }
172
- async CreateMultisig(jsonObject) {
173
- return this.client.getMethod('CreateMultisig')(jsonObject);
174
- }
175
- async ParseDescriptor(jsonObject) {
176
- return this.client.getMethod('ParseDescriptor')(jsonObject);
177
- }
178
- async ParseScript(jsonObject) {
179
- return this.client.getMethod('ParseScript')(jsonObject);
180
- }
181
- async SelectUtxos(jsonObject) {
182
- return this.client.getMethod('SelectUtxos')(jsonObject);
183
- }
184
- async SerializeLedgerFormat(jsonObject) {
185
- return this.client.getMethod('SerializeLedgerFormat')(jsonObject);
186
- }
187
- async CreateSignatureHash(jsonObject) {
188
- return this.client.getMethod('CreateSignatureHash')(jsonObject);
189
- }
190
- async CreateElementsSignatureHash(jsonObject) {
191
- return this.client.getMethod('CreateElementsSignatureHash')(jsonObject);
192
- }
193
- async SignWithPrivkey(jsonObject) {
194
- return this.client.getMethod('SignWithPrivkey')(jsonObject);
195
- }
196
- async GetSupportedFunction() {
197
- return this.client.getMethod('GetSupportedFunction')();
198
- }
199
- async CreateRawTransaction(jsonObject) {
200
- return this.client.getMethod('CreateRawTransaction')(jsonObject);
201
- }
202
- async UpdateTxOutAmount(jsonObject) {
203
- return this.client.getMethod('UpdateTxOutAmount')(jsonObject);
204
- }
205
- async UpdateWitnessStack(jsonObject) {
206
- return this.client.getMethod('UpdateWitnessStack')(jsonObject);
207
- }
208
- async VerifySign(jsonObject) {
209
- return this.client.getMethod('VerifySign')(jsonObject);
210
- }
211
- async VerifySignature(jsonObject) {
212
- return this.client.getMethod('VerifySignature')(jsonObject);
213
- }
214
- }
215
- exports.default = Cfd;
216
- //# sourceMappingURL=Cfd.js.map
package/lib/Chain.js DELETED
@@ -1,110 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const errors_1 = require("@atomicfinance/errors");
4
- const types_1 = require("@atomicfinance/types");
5
- const lodash_1 = require("lodash");
6
- class Chain {
7
- constructor(client) {
8
- this.client = client;
9
- }
10
- /** @inheritdoc */
11
- async generateBlock(numberOfBlocks) {
12
- if (!(0, lodash_1.isNumber)(numberOfBlocks)) {
13
- throw new TypeError('First argument should be a number');
14
- }
15
- return this.client.getMethod('generateBlock')(numberOfBlocks);
16
- }
17
- /** @inheritdoc */
18
- async getBlockByHash(blockHash, includeTx = false) {
19
- if (!(0, lodash_1.isString)(blockHash)) {
20
- throw new TypeError('Block hash should be a string');
21
- }
22
- if (!(0, lodash_1.isBoolean)(includeTx)) {
23
- throw new TypeError('Second parameter should be boolean');
24
- }
25
- const block = await this.client.getMethod('getBlockByHash')(blockHash, includeTx);
26
- this.client.assertValidBlock(block);
27
- return block;
28
- }
29
- /** @inheritdoc */
30
- async getBlockByNumber(blockNumber, includeTx = false) {
31
- if (!(0, lodash_1.isNumber)(blockNumber)) {
32
- throw new TypeError('Invalid Block number');
33
- }
34
- if (!(0, lodash_1.isBoolean)(includeTx)) {
35
- throw new TypeError('Second parameter should be boolean');
36
- }
37
- const block = await this.client.getMethod('getBlockByNumber')(blockNumber, includeTx);
38
- this.client.assertValidBlock(block);
39
- return block;
40
- }
41
- /** @inheritdoc */
42
- async getBlockHeight() {
43
- const blockHeight = await this.client.getMethod('getBlockHeight')();
44
- if (!(0, lodash_1.isNumber)(blockHeight)) {
45
- throw new errors_1.InvalidProviderResponseError('Provider returned an invalid block height');
46
- }
47
- return blockHeight;
48
- }
49
- /** @inheritdoc */
50
- async getTransactionByHash(txHash) {
51
- if (!(0, lodash_1.isString)(txHash)) {
52
- throw new TypeError('Transaction hash should be a string');
53
- }
54
- const transaction = await this.client.getMethod('getTransactionByHash')(txHash);
55
- if (transaction) {
56
- this.client.assertValidTransaction(transaction);
57
- }
58
- return transaction;
59
- }
60
- /** @inheritdoc */
61
- async getBalance(addresses) {
62
- const balance = await this.client.getMethod('getBalance')(addresses);
63
- if (!types_1.BigNumber.isBigNumber(balance)) {
64
- throw new errors_1.InvalidProviderResponseError('Provider returned an invalid response');
65
- }
66
- return balance;
67
- }
68
- /** @inheritdoc */
69
- async sendTransaction(options) {
70
- const transaction = await this.client.getMethod('sendTransaction')(options);
71
- this.client.assertValidTransaction(transaction);
72
- return transaction;
73
- }
74
- /** @inheritdoc */
75
- async sendSweepTransaction(address, fee) {
76
- return this.client.getMethod('sendSweepTransaction')(address, fee);
77
- }
78
- /** @inheritdoc */
79
- async updateTransactionFee(tx, newFee) {
80
- if ((0, lodash_1.isObject)(tx)) {
81
- this.client.assertValidTransaction(tx);
82
- }
83
- else {
84
- if (!(0, lodash_1.isString)(tx)) {
85
- throw new TypeError('Transaction should be a string or object');
86
- }
87
- }
88
- const transaction = await this.client.getMethod('updateTransactionFee')(tx, newFee);
89
- this.client.assertValidTransaction(transaction);
90
- return transaction;
91
- }
92
- /** @inheritdoc */
93
- async sendBatchTransaction(transactions) {
94
- return this.client.getMethod('sendBatchTransaction')(transactions);
95
- }
96
- /** @inheritdoc */
97
- async sendRawTransaction(rawTransaction) {
98
- const txHash = await this.client.getMethod('sendRawTransaction')(rawTransaction);
99
- if (!(0, lodash_1.isString)(txHash)) {
100
- throw new errors_1.InvalidProviderResponseError('sendRawTransaction method should return a transaction id string');
101
- }
102
- return txHash;
103
- }
104
- /** @inheritdoc */
105
- async getFees() {
106
- return this.client.getMethod('getFees')();
107
- }
108
- }
109
- exports.default = Chain;
110
- //# sourceMappingURL=Chain.js.map
package/lib/Client.js DELETED
@@ -1,127 +0,0 @@
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
- const errors_1 = require("@atomicfinance/errors");
7
- const ajv_1 = __importDefault(require("ajv"));
8
- const lodash_1 = require("lodash");
9
- const Cfd_1 = __importDefault(require("./Cfd"));
10
- const Chain_1 = __importDefault(require("./Chain"));
11
- const Dlc_1 = __importDefault(require("./Dlc"));
12
- const schema_1 = require("./schema");
13
- const Wallet_1 = __importDefault(require("./Wallet"));
14
- class Client {
15
- /**
16
- * Client
17
- */
18
- constructor(provider, version) {
19
- /**
20
- * @type {Array}
21
- */
22
- this._providers = [];
23
- /**
24
- * @type {string}
25
- */
26
- this.version = version;
27
- if (provider) {
28
- this.addProvider(provider);
29
- }
30
- const ajv = new ajv_1.default();
31
- this.validateTransaction = ajv.compile(schema_1.Transaction);
32
- this.validateBlock = ajv.compile(schema_1.Block);
33
- this._chain = new Chain_1.default(this);
34
- this._dlc = new Dlc_1.default(this);
35
- this._cfd = new Cfd_1.default(this);
36
- this._wallet = new Wallet_1.default(this);
37
- this.identifier = 'Client';
38
- }
39
- /**
40
- * Add a provider
41
- * @param {!Provider} provider - The provider instance or RPC connection string
42
- * @return {Client} Returns instance of Client
43
- * @throws {InvalidProviderError} When invalid provider is provider
44
- * @throws {DuplicateProviderError} When same provider is added again
45
- */
46
- addProvider(provider) {
47
- if (!(0, lodash_1.isFunction)(provider.setClient)) {
48
- throw new errors_1.InvalidProviderError('Provider should have "setClient" method');
49
- }
50
- const duplicate = (0, lodash_1.find)(this._providers, (_provider) => provider.constructor === _provider.constructor);
51
- if (duplicate) {
52
- throw new errors_1.DuplicateProviderError('Duplicate provider');
53
- }
54
- provider.setClient(this);
55
- this._providers.push(provider);
56
- return this;
57
- }
58
- /**
59
- * Check the availability of a method.
60
- * @param {!string} method - Name of the method to look for in the provider stack
61
- * @param {boolean|object} [requestor=false] - If provided, it returns providers only
62
- * above the requestor in the stack.
63
- * @return {Provider} Returns a provider instance associated with the requested method
64
- * @throws {NoProviderError} When no provider is available in the stack.
65
- * @throws {UnimplementedMethodError} When the requested method is not provided
66
- * by any provider above requestor in the provider stack
67
- * @throws {UnsupportedMethodError} When requested method is not supported by
68
- * version specified
69
- */
70
- getProviderForMethod(method, requestor = false) {
71
- if (this._providers.length === 0) {
72
- throw new errors_1.NoProviderError('No provider provided. Add a provider to the client');
73
- }
74
- let indexOfRequestor = requestor
75
- ? (0, lodash_1.findLastIndex)(this._providers, (provider) => requestor.constructor === provider.constructor)
76
- : this._providers.length;
77
- if (indexOfRequestor === -1)
78
- indexOfRequestor = 0;
79
- const provider = (0, lodash_1.findLast)(this._providers, (provider) => (0, lodash_1.isFunction)(provider[method]), indexOfRequestor - 1);
80
- if (provider == null) {
81
- throw new errors_1.UnimplementedMethodError(`Unimplemented method "${method}"`);
82
- }
83
- if ((0, lodash_1.isFunction)(provider._checkMethodVersionSupport)) {
84
- if (!provider._checkMethodVersionSupport(method, this.version)) {
85
- throw new errors_1.UnsupportedMethodError(`Method "${method}" is not supported by version "${this.version}"`);
86
- }
87
- }
88
- return provider;
89
- }
90
- /**
91
- * Helper method that returns method from a provider.
92
- * @param {!string} method - Name of the method to look for in the provider stack
93
- * @param {object} [requestor] - If provided, it returns method from providers only
94
- * above the requestor in the stack.
95
- * @return {function} Returns method from provider instance associated with the requested method
96
- */
97
- getMethod(method, requestor) {
98
- const provider = this.getProviderForMethod(method, requestor);
99
- return provider[method].bind(provider);
100
- }
101
- assertValidTransaction(transaction) {
102
- if (!this.validateTransaction(transaction)) {
103
- const { errors } = this.validateTransaction;
104
- throw new errors_1.InvalidProviderResponseError(`Provider returned an invalid transaction, "${errors[0].dataPath}" ${errors[0].message}`);
105
- }
106
- }
107
- assertValidBlock(block) {
108
- if (!this.validateBlock(block)) {
109
- const { errors } = this.validateBlock;
110
- throw new errors_1.InvalidProviderResponseError(`Provider returned an invalid block, "${errors[0].dataPath}" ${errors[0].message}`);
111
- }
112
- }
113
- get chain() {
114
- return this._chain;
115
- }
116
- get dlc() {
117
- return this._dlc;
118
- }
119
- get cfd() {
120
- return this._cfd;
121
- }
122
- get wallet() {
123
- return this._wallet;
124
- }
125
- }
126
- exports.default = Client;
127
- //# sourceMappingURL=Client.js.map
package/lib/Dlc.js DELETED
@@ -1,231 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class Dlc {
4
- constructor(client) {
5
- this.client = client;
6
- }
7
- /**
8
- * Check whether wallet is offerer of DlcOffer or DlcAccept
9
- * @param dlcOffer Dlc Offer Message
10
- * @param dlcAccept Dlc Accept Message
11
- * @returns {Promise<boolean>}
12
- */
13
- async isOfferer(dlcOffer, dlcAccept) {
14
- return this.client.getMethod('isOfferer')(dlcOffer, dlcAccept);
15
- }
16
- /**
17
- * Create DlcTxs object from DlcOffer and DlcAccept
18
- * @param dlcOffer Dlc Offer Message
19
- * @param dlcAccept Dlc Accept Message
20
- * @returns {Promise<CreateDlcTxsResponse>}
21
- */
22
- async createDlcTxs(dlcOffer, dlcAccept) {
23
- return this.client.getMethod('createDlcTxs')(dlcOffer, dlcAccept);
24
- }
25
- /**
26
- * Create DLC Offer Message
27
- * @param contractInfo ContractInfo TLV (V0 or V1)
28
- * @param offerCollateralSatoshis Amount DLC Initiator is putting into the contract
29
- * @param feeRatePerVb Fee rate in satoshi per virtual byte that both sides use to compute fees in funding tx
30
- * @param cetLocktime The nLockTime to be put on CETs
31
- * @param refundLocktime The nLockTime to be put on the refund transaction
32
- * @returns {Promise<DlcOffer>}
33
- */
34
- async createDlcOffer(contractInfo, offerCollateralSatoshis, feeRatePerVb, cetLocktime, refundLocktime, fixedInputs) {
35
- return this.client.getMethod('createDlcOffer')(contractInfo, offerCollateralSatoshis, feeRatePerVb, cetLocktime, refundLocktime, fixedInputs);
36
- }
37
- async batchCreateDlcOffer(contractInfos, offerCollaterals, feeRatePerVb, cetLocktime, refundLocktimes, fixedInputs) {
38
- return this.client.getMethod('batchCreateDlcOffer')(contractInfos, offerCollaterals, feeRatePerVb, cetLocktime, refundLocktimes, fixedInputs);
39
- }
40
- /**
41
- * Accept DLC Offer
42
- * @param dlcOffer Dlc Offer Message
43
- * @param fixedInputs Optional inputs to use for Funding Inputs
44
- * @returns {Promise<AcceptDlcOfferResponse}
45
- */
46
- async acceptDlcOffer(dlcOffer, fixedInputs) {
47
- return this.client.getMethod('acceptDlcOffer')(dlcOffer, fixedInputs);
48
- }
49
- /**
50
- * Accept DLC Offer
51
- * @param dlcOffers Dlc Offer Messages
52
- * @param fixedInputs Optional inputs to use for Funding Inputs
53
- * @returns {Promise<BatchAcceptDlcOfferResponse}
54
- */
55
- async batchAcceptDlcOffer(dlcOffers, fixedInputs) {
56
- return this.client.getMethod('batchAcceptDlcOffer')(dlcOffers, fixedInputs);
57
- }
58
- /**
59
- * Sign Dlc Accept Message
60
- * @param dlcOffer Dlc Offer Message
61
- * @param dlcAccept Dlc Accept Message
62
- * @returns {Promise<SignDlcAcceptResponse}
63
- */
64
- async signDlcAccept(dlcOffer, dlcAccept) {
65
- return this.client.getMethod('signDlcAccept')(dlcOffer, dlcAccept);
66
- }
67
- /**
68
- * Batch Sign Dlc Accept Messages
69
- * @param dlcOffers Dlc Offer Messages
70
- * @param dlcAccepts Dlc Accept Messages
71
- * @returns {Promise<BatchSignDlcAcceptResponse}
72
- */
73
- async batchSignDlcAccept(dlcOffers, dlcAccepts) {
74
- return this.client.getMethod('batchSignDlcAccept')(dlcOffers, dlcAccepts);
75
- }
76
- /**
77
- * Finalize Dlc Sign
78
- * @param dlcOffer Dlc Offer Message
79
- * @param dlcAccept Dlc Accept Message
80
- * @param dlcSign Dlc Sign Message
81
- * @param dlcTxs Dlc Transactions Message
82
- * @returns {Promise<Tx>}
83
- */
84
- async finalizeDlcSign(dlcOffer, dlcAccept, dlcSign, dlcTxs) {
85
- return this.client.getMethod('finalizeDlcSign')(dlcOffer, dlcAccept, dlcSign, dlcTxs);
86
- }
87
- async batchFinalizeDlcSign(dlcOffers, dlcAccepts, dlcSigns, dlcTxsList) {
88
- return this.client.getMethod('batchFinalizeDlcSign')(dlcOffers, dlcAccepts, dlcSigns, dlcTxsList);
89
- }
90
- /**
91
- * Execute DLC
92
- * @param dlcOffer Dlc Offer Message
93
- * @param dlcAccept Dlc Accept Message
94
- * @param dlcSign Dlc Sign Message
95
- * @param dlcTxs Dlc Transactions Message
96
- * @param oracleAttestation Oracle Attestations TLV (V0)
97
- * @param isOfferer Whether party is Dlc Offerer
98
- * @returns {Promise<Tx>}
99
- */
100
- async execute(dlcOffer, dlcAccept, dlcSign, dlcTxs, oracleAttestation, isOfferer) {
101
- return this.client.getMethod('execute')(dlcOffer, dlcAccept, dlcSign, dlcTxs, oracleAttestation, isOfferer);
102
- }
103
- /**
104
- * Refund DLC
105
- * @param dlcOffer Dlc Offer Message
106
- * @param dlcAccept Dlc Accept Message
107
- * @param dlcSign Dlc Sign Message
108
- * @param dlcTxs Dlc Transactions message
109
- * @returns {Promise<Tx>}
110
- */
111
- async refund(dlcOffer, dlcAccept, dlcSign, dlcTxs) {
112
- return this.client.getMethod('refund')(dlcOffer, dlcAccept, dlcSign, dlcTxs);
113
- }
114
- /**
115
- * Generate DlcClose messagetype for closing DLC with Mutual Consent
116
- * @param dlcOffer DlcOffer TLV (V0)
117
- * @param dlcAccept DlcAccept TLV (V0)
118
- * @param dlcTxs DlcTransactions TLV (V0)
119
- * @param initiatorPayoutSatoshis Amount initiator expects as a payout
120
- * @param isOfferer Whether offerer or not
121
- * @param inputs Optionally specified closing inputs
122
- * @returns {Promise<DlcClose>}
123
- */
124
- async createDlcClose(dlcOffer, dlcAccept, dlcTxs, initiatorPayoutSatoshis, isOfferer, inputs) {
125
- return this.client.getMethod('createDlcClose')(dlcOffer, dlcAccept, dlcTxs, initiatorPayoutSatoshis, isOfferer, inputs);
126
- }
127
- /**
128
- * Generate multiple DlcClose messagetypes for closing DLC with Mutual Consent
129
- * @param dlcOffer DlcOffer TLV (V0)
130
- * @param dlcAccept DlcAccept TLV (V0)
131
- * @param dlcTxs DlcTransactions TLV (V0)
132
- * @param initiatorPayouts Array of amounts initiator expects as payouts
133
- * @param isOfferer Whether offerer or not
134
- * @param inputs Optionally specified closing inputs
135
- * @returns {Promise<DlcClose[]>}
136
- */
137
- async createBatchDlcClose(dlcOffer, dlcAccept, dlcTxs, initiatorPayouts, isOfferer, inputs) {
138
- return this.client.getMethod('createBatchDlcClose')(dlcOffer, dlcAccept, dlcTxs, initiatorPayouts, isOfferer, inputs);
139
- }
140
- async verifyBatchDlcCloseUsingMetadata(dlcCloseMetadata, _dlcCloses, isOfferer) {
141
- return this.client.getMethod('verifyBatchDlcCloseUsingMetadata')(dlcCloseMetadata, _dlcCloses, isOfferer);
142
- }
143
- /**
144
- * Verify multiple DlcClose messagetypes for closing DLC with Mutual Consent
145
- * @param dlcOffer DlcOffer TLV (V0)
146
- * @param dlcAccept DlcAccept TLV (V0)
147
- * @param dlcTxs DlcTransactions TLV (V0)
148
- * @param dlcCloses DlcClose[] TLV (V0)
149
- * @param isOfferer Whether offerer or not
150
- * @returns {Promise<void>}
151
- */
152
- async verifyBatchDlcClose(dlcOffer, dlcAccept, dlcTxs, dlcCloses, isOfferer) {
153
- return this.client.getMethod('verifyBatchDlcClose')(dlcOffer, dlcAccept, dlcTxs, dlcCloses, isOfferer);
154
- }
155
- /**
156
- * Finalize Dlc Close
157
- * @param dlcOffer Dlc Offer Message
158
- * @param dlcAccept Dlc Accept Message
159
- * @param dlcClose Dlc Close Message
160
- * @param dlcTxs Dlc Transactions Message
161
- * @returns {Promise<string>}
162
- */
163
- finalizeDlcClose(dlcOffer, dlcAccept, dlcClose, dlcTxs) {
164
- return this.client.getMethod('finalizeDlcClose')(dlcOffer, dlcAccept, dlcClose, dlcTxs);
165
- }
166
- async AddSignatureToFundTransaction(jsonObject) {
167
- return this.client.getMethod('AddSignatureToFundTransaction')(jsonObject);
168
- }
169
- async CreateCetAdaptorSignature(jsonObject) {
170
- return this.client.getMethod('CreateCetAdaptorSignature')(jsonObject);
171
- }
172
- async CreateCetAdaptorSignatures(jsonObject) {
173
- return this.client.getMethod('CreateCetAdaptorSignatures')(jsonObject);
174
- }
175
- async AddSignaturesToRefundTx(jsonObject) {
176
- return this.client.getMethod('AddSignaturesToRefundTx')(jsonObject);
177
- }
178
- async CreateCet(jsonObject) {
179
- return this.client.getMethod('CreateCet')(jsonObject);
180
- }
181
- async CreateDlcTransactions(jsonObject) {
182
- return this.client.getMethod('CreateDlcTransactions')(jsonObject);
183
- }
184
- async CreateFundTransaction(jsonObject) {
185
- return this.client.getMethod('CreateFundTransaction')(jsonObject);
186
- }
187
- async CreateRefundTransaction(jsonObject) {
188
- return this.client.getMethod('CreateRefundTransaction')(jsonObject);
189
- }
190
- async GetRawFundTxSignature(jsonObject) {
191
- return this.client.getMethod('GetRawFundTxSignature')(jsonObject);
192
- }
193
- async GetRawRefundTxSignature(jsonObject) {
194
- return this.client.getMethod('GetRawRefundTxSignature')(jsonObject);
195
- }
196
- async SignCetRequest(jsonObject) {
197
- return this.client.getMethod('SignCetRequest')(jsonObject);
198
- }
199
- async SignFundTransaction(jsonObject) {
200
- return this.client.getMethod('SignFundTransaction')(jsonObject);
201
- }
202
- async VerifyCetAdaptorSignature(jsonObject) {
203
- return this.client.getMethod('VerifyCetAdaptorSignature')(jsonObject);
204
- }
205
- async VerifyCetAdaptorSignatures(jsonObject) {
206
- return this.client.getMethod('VerifyCetAdaptorSignatures')(jsonObject);
207
- }
208
- async GetInputsForAmount(amounts, feeRatePerVb, fixedInputs) {
209
- return this.client.getMethod('GetInputsForAmount')(amounts, feeRatePerVb, fixedInputs);
210
- }
211
- async SignCet(jsonObject) {
212
- return this.client.getMethod('SignCet')(jsonObject);
213
- }
214
- async VerifyCetAdaptorSignaturesRequest(jsonObject) {
215
- return this.client.getMethod('VerifyCetAdaptorSignatures')(jsonObject);
216
- }
217
- async VerifyFundTxSignature(jsonObject) {
218
- return this.client.getMethod('VerifyFundTxSignature')(jsonObject);
219
- }
220
- async VerifyRefundTxSignature(jsonObject) {
221
- return this.client.getMethod('VerifyRefundTxSignature')(jsonObject);
222
- }
223
- async fundingInputToInput(_input) {
224
- return this.client.getMethod('fundingInputToInput')(_input);
225
- }
226
- async inputToFundingInput(input) {
227
- return this.client.getMethod('inputToFundingInput')(input);
228
- }
229
- }
230
- exports.default = Dlc;
231
- //# sourceMappingURL=Dlc.js.map
package/lib/Wallet.js DELETED
@@ -1,125 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const errors_1 = require("@atomicfinance/errors");
4
- const lodash_1 = require("lodash");
5
- class Wallet {
6
- constructor(client) {
7
- this.client = client;
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 (!(0, 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
- async findAddress(addresses, change = null) {
91
- return this.client.getMethod('findAddress')(addresses, change);
92
- }
93
- setUnusedAddressesBlacklist(unusedAddressesBlacklist) {
94
- return this.client.getMethod('setUnusedAddressesBlacklist')(unusedAddressesBlacklist);
95
- }
96
- getUnusedAddressesBlacklist() {
97
- return this.client.getMethod('getUnusedAddressesBlacklist')();
98
- }
99
- createMultisig(m, pubkeys) {
100
- return this.client.getMethod('createMultisig')(m, pubkeys);
101
- }
102
- buildMultisigPSBT(m, pubkeys, inputs, outputs) {
103
- return this.client.getMethod('buildMultisigPSBT')(m, pubkeys, inputs, outputs);
104
- }
105
- walletProcessPSBT(psbtString) {
106
- return this.client.getMethod('walletProcessPSBT')(psbtString);
107
- }
108
- finalizePSBT(psbtString) {
109
- return this.client.getMethod('finalizePSBT')(psbtString);
110
- }
111
- async buildSweepTransactionWithSetOutputs(externalChangeAddress, feePerByte, outputs, fixedInputs) {
112
- return this.client.getMethod('buildSweepTransactionWithSetOutputs')(externalChangeAddress, feePerByte, outputs, fixedInputs);
113
- }
114
- async sendSweepTransactionWithSetOutputs(externalChangeAddress, feePerByte, outputs, fixedInputs) {
115
- return this.client.getMethod('sendSweepTransactionWithSetOutputs')(externalChangeAddress, feePerByte, outputs, fixedInputs);
116
- }
117
- async getInputsForAmount(_targets, feePerByte, fixedInputs = [], numAddressPerCall = 100, sweep = false) {
118
- return this.client.getMethod('getInputsForAmount')(_targets, feePerByte, fixedInputs, numAddressPerCall, sweep);
119
- }
120
- async getInputsForDualFunding(collaterals, feePerByte, fixedInputs = [], numAddressPerCall = 100) {
121
- return this.client.getMethod('getInputsForDualFunding')(collaterals, feePerByte, fixedInputs, numAddressPerCall);
122
- }
123
- }
124
- exports.default = Wallet;
125
- //# sourceMappingURL=Wallet.js.map
package/lib/index.js DELETED
@@ -1,11 +0,0 @@
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.default = exports.Client = void 0;
7
- var Client_1 = require("./Client");
8
- Object.defineProperty(exports, "Client", { enumerable: true, get: function () { return __importDefault(Client_1).default; } });
9
- var Client_2 = require("./Client");
10
- Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(Client_2).default; } });
11
- //# sourceMappingURL=index.js.map