@atomicfinance/client 2.2.3

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/lib/Dlc.ts ADDED
@@ -0,0 +1,421 @@
1
+ import {
2
+ AddSignaturesToRefundTxRequest,
3
+ AddSignaturesToRefundTxResponse,
4
+ AddSignatureToFundTransactionRequest,
5
+ AddSignatureToFundTransactionResponse,
6
+ CreateCetAdaptorSignatureRequest,
7
+ CreateCetAdaptorSignatureResponse,
8
+ CreateCetAdaptorSignaturesRequest,
9
+ CreateCetAdaptorSignaturesResponse,
10
+ CreateCetRequest,
11
+ CreateCetResponse,
12
+ CreateDlcTransactionsRequest,
13
+ CreateDlcTransactionsResponse,
14
+ CreateFundTransactionRequest,
15
+ CreateFundTransactionResponse,
16
+ CreateRefundTransactionRequest,
17
+ CreateRefundTransactionResponse,
18
+ GetRawFundTxSignatureRequest,
19
+ GetRawFundTxSignatureResponse,
20
+ GetRawRefundTxSignatureRequest,
21
+ GetRawRefundTxSignatureResponse,
22
+ Input,
23
+ SignCetRequest,
24
+ SignCetResponse,
25
+ SignFundTransactionRequest,
26
+ SignFundTransactionResponse,
27
+ VerifyCetAdaptorSignatureRequest,
28
+ VerifyCetAdaptorSignatureResponse,
29
+ VerifyCetAdaptorSignaturesRequest,
30
+ VerifyCetAdaptorSignaturesResponse,
31
+ VerifyFundTxSignatureRequest,
32
+ VerifyFundTxSignatureResponse,
33
+ VerifyRefundTxSignatureRequest,
34
+ VerifyRefundTxSignatureResponse,
35
+ } from '@atomicfinance/types';
36
+ import {
37
+ ContractInfo,
38
+ DlcAccept,
39
+ DlcClose,
40
+ DlcOffer,
41
+ DlcSign,
42
+ DlcTransactions,
43
+ FundingInput,
44
+ OracleAttestationV0,
45
+ } from '@node-dlc/messaging';
46
+ import { Tx } from '@node-lightning/bitcoin';
47
+
48
+ export default class Dlc {
49
+ client: any;
50
+
51
+ constructor(client: any) {
52
+ this.client = client;
53
+ }
54
+
55
+ /**
56
+ * Check whether wallet is offerer of DlcOffer or DlcAccept
57
+ * @param dlcOffer Dlc Offer Message
58
+ * @param dlcAccept Dlc Accept Message
59
+ * @returns {Promise<boolean>}
60
+ */
61
+ async isOfferer(dlcOffer: DlcOffer, dlcAccept: DlcAccept): Promise<boolean> {
62
+ return this.client.getMethod('isOfferer')(dlcOffer, dlcAccept);
63
+ }
64
+
65
+ /**
66
+ * Create DLC Offer Message
67
+ * @param contractInfo ContractInfo TLV (V0 or V1)
68
+ * @param offerCollateralSatoshis Amount DLC Initiator is putting into the contract
69
+ * @param feeRatePerVb Fee rate in satoshi per virtual byte that both sides use to compute fees in funding tx
70
+ * @param cetLocktime The nLockTime to be put on CETs
71
+ * @param refundLocktime The nLockTime to be put on the refund transaction
72
+ * @returns {Promise<DlcOffer>}
73
+ */
74
+ async createDlcOffer(
75
+ contractInfo: ContractInfo,
76
+ offerCollateralSatoshis: bigint,
77
+ feeRatePerVb: bigint,
78
+ cetLocktime: number,
79
+ refundLocktime: number,
80
+ fixedInputs?: IInput[],
81
+ ): Promise<DlcOffer> {
82
+ return this.client.getMethod('createDlcOffer')(
83
+ contractInfo,
84
+ offerCollateralSatoshis,
85
+ feeRatePerVb,
86
+ cetLocktime,
87
+ refundLocktime,
88
+ fixedInputs,
89
+ );
90
+ }
91
+
92
+ /**
93
+ * Accept DLC Offer
94
+ * @param dlcOffer Dlc Offer Message
95
+ * @param fixedInputs Optional inputs to use for Funding Inputs
96
+ * @returns {Promise<AcceptDlcOfferResponse}
97
+ */
98
+ async acceptDlcOffer(
99
+ dlcOffer: DlcOffer,
100
+ fixedInputs?: IInput[],
101
+ ): Promise<AcceptDlcOfferResponse> {
102
+ return this.client.getMethod('acceptDlcOffer')(dlcOffer, fixedInputs);
103
+ }
104
+
105
+ /**
106
+ * Sign Dlc Accept Message
107
+ * @param dlcOffer Dlc Offer Message
108
+ * @param dlcAccept Dlc Accept Message
109
+ * @returns {Promise<SignDlcAcceptResponse}
110
+ */
111
+ async signDlcAccept(
112
+ dlcOffer: DlcOffer,
113
+ dlcAccept: DlcAccept,
114
+ ): Promise<SignDlcAcceptResponse> {
115
+ return this.client.getMethod('signDlcAccept')(dlcOffer, dlcAccept);
116
+ }
117
+
118
+ /**
119
+ * Finalize Dlc Sign
120
+ * @param dlcOffer Dlc Offer Message
121
+ * @param dlcAccept Dlc Accept Message
122
+ * @param dlcSign Dlc Sign Message
123
+ * @param dlcTxs Dlc Transactions Message
124
+ * @returns {Promise<Tx>}
125
+ */
126
+ async finalizeDlcSign(
127
+ dlcOffer: DlcOffer,
128
+ dlcAccept: DlcAccept,
129
+ dlcSign: DlcSign,
130
+ dlcTxs: DlcTransactions,
131
+ ): Promise<Tx> {
132
+ return this.client.getMethod('finalizeDlcSign')(
133
+ dlcOffer,
134
+ dlcAccept,
135
+ dlcSign,
136
+ dlcTxs,
137
+ );
138
+ }
139
+
140
+ /**
141
+ * Execute DLC
142
+ * @param dlcOffer Dlc Offer Message
143
+ * @param dlcAccept Dlc Accept Message
144
+ * @param dlcSign Dlc Sign Message
145
+ * @param dlcTxs Dlc Transactions Message
146
+ * @param oracleAttestation Oracle Attestations TLV (V0)
147
+ * @param isOfferer Whether party is Dlc Offerer
148
+ * @returns {Promise<Tx>}
149
+ */
150
+ async execute(
151
+ dlcOffer: DlcOffer,
152
+ dlcAccept: DlcAccept,
153
+ dlcSign: DlcSign,
154
+ dlcTxs: DlcTransactions,
155
+ oracleAttestation: OracleAttestationV0,
156
+ isOfferer?: boolean,
157
+ ): Promise<Tx> {
158
+ return this.client.getMethod('execute')(
159
+ dlcOffer,
160
+ dlcAccept,
161
+ dlcSign,
162
+ dlcTxs,
163
+ oracleAttestation,
164
+ isOfferer,
165
+ );
166
+ }
167
+
168
+ /**
169
+ * Refund DLC
170
+ * @param dlcOffer Dlc Offer Message
171
+ * @param dlcAccept Dlc Accept Message
172
+ * @param dlcSign Dlc Sign Message
173
+ * @param dlcTxs Dlc Transactions message
174
+ * @returns {Promise<Tx>}
175
+ */
176
+ async refund(
177
+ dlcOffer: DlcOffer,
178
+ dlcAccept: DlcAccept,
179
+ dlcSign: DlcSign,
180
+ dlcTxs: DlcTransactions,
181
+ ): Promise<Tx> {
182
+ return this.client.getMethod('refund')(
183
+ dlcOffer,
184
+ dlcAccept,
185
+ dlcSign,
186
+ dlcTxs,
187
+ );
188
+ }
189
+
190
+ /**
191
+ * Generate DlcClose messagetype for closing DLC with Mutual Consent
192
+ * @param dlcOffer DlcOffer TLV (V0)
193
+ * @param dlcAccept DlcAccept TLV (V0)
194
+ * @param dlcTxs DlcTransactions TLV (V0)
195
+ * @param initiatorPayoutSatoshis Amount initiator expects as a payout
196
+ * @param isOfferer Whether offerer or not
197
+ * @param inputs Optionally specified closing inputs
198
+ * @returns {Promise<DlcClose>}
199
+ */
200
+ async createDlcClose(
201
+ dlcOffer: DlcOffer,
202
+ dlcAccept: DlcAccept,
203
+ dlcTxs: DlcTransactions,
204
+ initiatorPayoutSatoshis: bigint,
205
+ isOfferer?: boolean,
206
+ inputs?: Input[],
207
+ ): Promise<DlcClose> {
208
+ return this.client.getMethod('createDlcClose')(
209
+ dlcOffer,
210
+ dlcAccept,
211
+ dlcTxs,
212
+ initiatorPayoutSatoshis,
213
+ isOfferer,
214
+ inputs,
215
+ );
216
+ }
217
+
218
+ /**
219
+ * Generate multiple DlcClose messagetypes for closing DLC with Mutual Consent
220
+ * @param dlcOffer DlcOffer TLV (V0)
221
+ * @param dlcAccept DlcAccept TLV (V0)
222
+ * @param dlcTxs DlcTransactions TLV (V0)
223
+ * @param initiatorPayouts Array of amounts initiator expects as payouts
224
+ * @param isOfferer Whether offerer or not
225
+ * @param inputs Optionally specified closing inputs
226
+ * @returns {Promise<DlcClose[]>}
227
+ */
228
+ async createBatchDlcClose(
229
+ dlcOffer: DlcOffer,
230
+ dlcAccept: DlcAccept,
231
+ dlcTxs: DlcTransactions,
232
+ initiatorPayouts: bigint[],
233
+ isOfferer?: boolean,
234
+ inputs?: Input[],
235
+ ): Promise<DlcClose[]> {
236
+ return this.client.getMethod('createBatchDlcClose')(
237
+ dlcOffer,
238
+ dlcAccept,
239
+ dlcTxs,
240
+ initiatorPayouts,
241
+ isOfferer,
242
+ inputs,
243
+ );
244
+ }
245
+
246
+ /**
247
+ * Verify multiple DlcClose messagetypes for closing DLC with Mutual Consent
248
+ * @param dlcOffer DlcOffer TLV (V0)
249
+ * @param dlcAccept DlcAccept TLV (V0)
250
+ * @param dlcTxs DlcTransactions TLV (V0)
251
+ * @param dlcCloses DlcClose[] TLV (V0)
252
+ * @param isOfferer Whether offerer or not
253
+ * @returns {Promise<void>}
254
+ */
255
+ async verifyBatchDlcClose(
256
+ dlcOffer: DlcOffer,
257
+ dlcAccept: DlcAccept,
258
+ dlcTxs: DlcTransactions,
259
+ dlcCloses: DlcClose[],
260
+ isOfferer?: boolean,
261
+ ): Promise<void> {
262
+ return this.client.getMethod('verifyBatchDlcClose')(
263
+ dlcOffer,
264
+ dlcAccept,
265
+ dlcTxs,
266
+ dlcCloses,
267
+ isOfferer,
268
+ );
269
+ }
270
+
271
+ /**
272
+ * Finalize Dlc Close
273
+ * @param dlcOffer Dlc Offer Message
274
+ * @param dlcAccept Dlc Accept Message
275
+ * @param dlcClose Dlc Close Message
276
+ * @param dlcTxs Dlc Transactions Message
277
+ * @returns {Promise<string>}
278
+ */
279
+ finalizeDlcClose(
280
+ dlcOffer: DlcOffer,
281
+ dlcAccept: DlcAccept,
282
+ dlcClose: DlcClose,
283
+ dlcTxs: DlcTransactions,
284
+ ): Promise<string> {
285
+ return this.client.getMethod('finalizeDlcClose')(
286
+ dlcOffer,
287
+ dlcAccept,
288
+ dlcClose,
289
+ dlcTxs,
290
+ );
291
+ }
292
+
293
+ async AddSignatureToFundTransaction(
294
+ jsonObject: AddSignatureToFundTransactionRequest,
295
+ ): Promise<AddSignatureToFundTransactionResponse> {
296
+ return this.client.getMethod('AddSignatureToFundTransaction')(jsonObject);
297
+ }
298
+
299
+ async CreateCetAdaptorSignature(
300
+ jsonObject: CreateCetAdaptorSignatureRequest,
301
+ ): Promise<CreateCetAdaptorSignatureResponse> {
302
+ return this.client.getMethod('CreateCetAdaptorSignature')(jsonObject);
303
+ }
304
+
305
+ async CreateCetAdaptorSignatures(
306
+ jsonObject: CreateCetAdaptorSignaturesRequest,
307
+ ): Promise<CreateCetAdaptorSignaturesResponse> {
308
+ return this.client.getMethod('CreateCetAdaptorSignatures')(jsonObject);
309
+ }
310
+
311
+ async AddSignaturesToRefundTx(
312
+ jsonObject: AddSignaturesToRefundTxRequest,
313
+ ): Promise<AddSignaturesToRefundTxResponse> {
314
+ return this.client.getMethod('AddSignaturesToRefundTx')(jsonObject);
315
+ }
316
+
317
+ async CreateCet(jsonObject: CreateCetRequest): Promise<CreateCetResponse> {
318
+ return this.client.getMethod('CreateCet')(jsonObject);
319
+ }
320
+
321
+ async CreateDlcTransactions(
322
+ jsonObject: CreateDlcTransactionsRequest,
323
+ ): Promise<CreateDlcTransactionsResponse> {
324
+ return this.client.getMethod('CreateDlcTransactions')(jsonObject);
325
+ }
326
+
327
+ async CreateFundTransaction(
328
+ jsonObject: CreateFundTransactionRequest,
329
+ ): Promise<CreateFundTransactionResponse> {
330
+ return this.client.getMethod('CreateFundTransaction')(jsonObject);
331
+ }
332
+
333
+ async CreateRefundTransaction(
334
+ jsonObject: CreateRefundTransactionRequest,
335
+ ): Promise<CreateRefundTransactionResponse> {
336
+ return this.client.getMethod('CreateRefundTransaction')(jsonObject);
337
+ }
338
+
339
+ async GetRawFundTxSignature(
340
+ jsonObject: GetRawFundTxSignatureRequest,
341
+ ): Promise<GetRawFundTxSignatureResponse> {
342
+ return this.client.getMethod('GetRawFundTxSignature')(jsonObject);
343
+ }
344
+
345
+ async GetRawRefundTxSignature(
346
+ jsonObject: GetRawRefundTxSignatureRequest,
347
+ ): Promise<GetRawRefundTxSignatureResponse> {
348
+ return this.client.getMethod('GetRawRefundTxSignature')(jsonObject);
349
+ }
350
+
351
+ async SignCetRequest(jsonObject: SignCetRequest): Promise<SignCetResponse> {
352
+ return this.client.getMethod('SignCetRequest')(jsonObject);
353
+ }
354
+
355
+ async SignFundTransaction(
356
+ jsonObject: SignFundTransactionRequest,
357
+ ): Promise<SignFundTransactionResponse> {
358
+ return this.client.getMethod('SignFundTransaction')(jsonObject);
359
+ }
360
+
361
+ async VerifyCetAdaptorSignature(
362
+ jsonObject: VerifyCetAdaptorSignatureRequest,
363
+ ): Promise<VerifyCetAdaptorSignatureResponse> {
364
+ return this.client.getMethod('VerifyCetAdaptorSignature')(jsonObject);
365
+ }
366
+
367
+ async VerifyCetAdaptorSignaturesRequest(
368
+ jsonObject: VerifyCetAdaptorSignaturesRequest,
369
+ ): Promise<VerifyCetAdaptorSignaturesResponse> {
370
+ return this.client.getMethod('VerifyCetAdaptorSignatures')(jsonObject);
371
+ }
372
+
373
+ async VerifyFundTxSignature(
374
+ jsonObject: VerifyFundTxSignatureRequest,
375
+ ): Promise<VerifyFundTxSignatureResponse> {
376
+ return this.client.getMethod('VerifyFundTxSignature')(jsonObject);
377
+ }
378
+
379
+ async VerifyRefundTxSignature(
380
+ jsonObject: VerifyRefundTxSignatureRequest,
381
+ ): Promise<VerifyRefundTxSignatureResponse> {
382
+ return this.client.getMethod('VerifyRefundTxSignature')(jsonObject);
383
+ }
384
+
385
+ async fundingInputToInput(_input: FundingInput): Promise<IInput> {
386
+ return this.client.getMethod('fundingInputToInput')(_input);
387
+ }
388
+
389
+ async inputToFundingInput(input: IInput): Promise<FundingInput> {
390
+ return this.client.getMethod('inputToFundingInput')(input);
391
+ }
392
+ }
393
+
394
+ export interface AcceptDlcOfferResponse {
395
+ dlcAccept: DlcAccept;
396
+ dlcTransactions: DlcTransactions;
397
+ }
398
+
399
+ export interface SignDlcAcceptResponse {
400
+ dlcSign: DlcSign;
401
+ dlcTransactions: DlcTransactions;
402
+ }
403
+
404
+ export interface IInput {
405
+ txid: string;
406
+ vout: number;
407
+ address: string;
408
+ amount: number; // in BTC
409
+ value: number; // in sats
410
+ derivationPath?: string;
411
+ maxWitnessLength?: number;
412
+ redeemScript?: string;
413
+ inputSerialId?: bigint;
414
+ scriptPubKey?: string;
415
+ label?: string;
416
+ confirmations?: number;
417
+ spendable?: boolean;
418
+ solvable?: boolean;
419
+ safe?: boolean;
420
+ toUtxo: any;
421
+ }
package/lib/Wallet.ts ADDED
@@ -0,0 +1,72 @@
1
+ import { CreateMultisigResponse, Input, Output } from '@atomicfinance/types';
2
+ import { Transaction } from 'bitcoinjs-lib';
3
+
4
+ export default class Wallet {
5
+ client: any;
6
+
7
+ constructor(client: any) {
8
+ this.client = client;
9
+ }
10
+
11
+ createMultisig(m: number, pubkeys: string[]): CreateMultisigResponse {
12
+ return this.client.getMethod('createMultisig')(m, pubkeys);
13
+ }
14
+
15
+ buildMultisigPSBT(
16
+ m: number,
17
+ pubkeys: string[],
18
+ inputs: Input[],
19
+ outputs: Output[],
20
+ ): string {
21
+ return this.client.getMethod('buildMultisigPSBT')(
22
+ m,
23
+ pubkeys,
24
+ inputs,
25
+ outputs,
26
+ );
27
+ }
28
+
29
+ walletProcessPSBT(psbtString: string): Promise<string> {
30
+ return this.client.getMethod('walletProcessPSBT')(psbtString);
31
+ }
32
+
33
+ finalizePSBT(psbtString: string): Transaction {
34
+ return this.client.getMethod('finalizePSBT')(psbtString);
35
+ }
36
+
37
+ async buildSweepTransactionWithSetOutputs(
38
+ externalChangeAddress: string,
39
+ feePerByte: number,
40
+ outputs: Output[],
41
+ fixedInputs: Input[],
42
+ ) {
43
+ return this.client.getMethod('buildSweepTransactionWithSetOutputs')(
44
+ externalChangeAddress,
45
+ feePerByte,
46
+ outputs,
47
+ fixedInputs,
48
+ );
49
+ }
50
+
51
+ async sendSweepTransactionWithSetOutputs(
52
+ externalChangeAddress: string,
53
+ feePerByte: number,
54
+ outputs: Output[],
55
+ fixedInputs: Input[],
56
+ ) {
57
+ return this.client.getMethod('sendSweepTransactionWithSetOutputs')(
58
+ externalChangeAddress,
59
+ feePerByte,
60
+ outputs,
61
+ fixedInputs,
62
+ );
63
+ }
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
+ }
package/lib/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { default as Client } from './Client';
2
+ export { default } from './Client';
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@atomicfinance/client",
3
+ "umdName": "Client",
4
+ "version": "2.2.3",
5
+ "description": "CAL Finance Client Provider",
6
+ "author": "Atomic Finance <info@atomic.finance>",
7
+ "homepage": "",
8
+ "license": "ISC",
9
+ "main": "dist/index.js",
10
+ "scripts": {
11
+ "build": "../../node_modules/.bin/tsc --project tsconfig.json",
12
+ "prepublishOnly": "yarn run build",
13
+ "test": "yarn run build",
14
+ "lint": "../../node_modules/.bin/eslint --ignore-path ../../.eslintignore -c ../../.eslintrc.js .",
15
+ "lint:fix": "../../node_modules/.bin/eslint --fix --ignore-path ../../.eslintignore -c ../../.eslintrc.js ."
16
+ },
17
+ "dependencies": {
18
+ "@atomicfinance/provider": "^2.2.3",
19
+ "@atomicfinance/types": "^2.2.3",
20
+ "@liquality/client": "1.1.5",
21
+ "@liquality/errors": "1.1.5",
22
+ "@liquality/provider": "1.1.5",
23
+ "@node-dlc/messaging": "0.10.3",
24
+ "@node-lightning/bitcoin": "0.22.1",
25
+ "lodash": "^4.17.20"
26
+ },
27
+ "devDependencies": {
28
+ "@types/lodash": "^4.14.160",
29
+ "@types/node": "^14.0.13"
30
+ },
31
+ "publishConfig": {
32
+ "access": "public"
33
+ },
34
+ "gitHead": "205d2d24dde632ae2bd931dbf297f78f2919fcc4"
35
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist",
5
+ },
6
+ "include": ["./lib"],
7
+ }