@atomicfinance/types 4.0.2 → 4.1.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/lib/ddk.ts ADDED
@@ -0,0 +1,430 @@
1
+ /* auto-generated by NAPI-RS */
2
+
3
+ export interface AdaptorSignature {
4
+ signature: Buffer;
5
+ proof: Buffer;
6
+ }
7
+
8
+ export interface ChangeOutputAndFees {
9
+ changeOutput: TxOutput;
10
+ fundFee: bigint;
11
+ cetFee: bigint;
12
+ }
13
+
14
+ export interface DdkDlcInputInfo {
15
+ fundTx: DdkTransaction;
16
+ fundVout: number;
17
+ localFundPubkey: Buffer;
18
+ remoteFundPubkey: Buffer;
19
+ fundAmount: bigint;
20
+ maxWitnessLen: number;
21
+ inputSerialId: bigint;
22
+ contractId: Buffer;
23
+ }
24
+
25
+ export interface DlcOutcome {
26
+ localPayout: bigint;
27
+ remotePayout: bigint;
28
+ }
29
+
30
+ export interface DdkDlcTransactions {
31
+ fund: DdkTransaction;
32
+ cets: Array<DdkTransaction>;
33
+ refund: DdkTransaction;
34
+ fundingScriptPubkey: Buffer;
35
+ }
36
+
37
+ export interface DdkOracleInfo {
38
+ publicKey: Buffer;
39
+ nonces: Array<Buffer>;
40
+ }
41
+
42
+ export interface PartyParams {
43
+ fundPubkey: Buffer;
44
+ changeScriptPubkey: Buffer;
45
+ changeSerialId: bigint;
46
+ payoutScriptPubkey: Buffer;
47
+ payoutSerialId: bigint;
48
+ inputs: Array<TxInputInfo>;
49
+ inputAmount: bigint;
50
+ collateral: bigint;
51
+ dlcInputs: Array<DdkDlcInputInfo>;
52
+ }
53
+
54
+ export interface Payout {
55
+ offer: bigint;
56
+ accept: bigint;
57
+ }
58
+
59
+ export interface DdkTransaction {
60
+ version: number;
61
+ lockTime: number;
62
+ inputs: Array<TxInput>;
63
+ outputs: Array<TxOutput>;
64
+ rawBytes: Buffer;
65
+ }
66
+
67
+ export interface TxInput {
68
+ txid: string;
69
+ vout: number;
70
+ scriptSig: Buffer;
71
+ sequence: number;
72
+ witness: Array<Buffer>;
73
+ }
74
+
75
+ export interface TxInputInfo {
76
+ txid: string;
77
+ vout: number;
78
+ scriptSig: Buffer;
79
+ maxWitnessLength: number;
80
+ serialId: bigint;
81
+ }
82
+
83
+ export interface TxOutput {
84
+ value: bigint;
85
+ scriptPubkey: Buffer;
86
+ }
87
+
88
+ // Main DDK interface that any implementation must provide
89
+ export interface DdkInterface {
90
+ createCet(
91
+ localOutput: TxOutput,
92
+ localPayoutSerialId: bigint,
93
+ remoteOutput: TxOutput,
94
+ remotePayoutSerialId: bigint,
95
+ fundTxId: string,
96
+ fundVout: number,
97
+ lockTime: number,
98
+ ): DdkTransaction;
99
+
100
+ createCetAdaptorSignatureFromOracleInfo(
101
+ cet: DdkTransaction,
102
+ oracleInfo: DdkOracleInfo,
103
+ fundingSk: Buffer,
104
+ fundingScriptPubkey: Buffer,
105
+ totalCollateral: bigint,
106
+ msgs: Array<Buffer>,
107
+ ): AdaptorSignature;
108
+
109
+ createCetAdaptorSigsFromOracleInfo(
110
+ cets: Array<DdkTransaction>,
111
+ oracleInfo: Array<DdkOracleInfo>,
112
+ fundingSecretKey: Buffer,
113
+ fundingScriptPubkey: Buffer,
114
+ fundOutputValue: bigint,
115
+ msgs: Array<Array<Array<Buffer>>>,
116
+ ): Array<AdaptorSignature>;
117
+
118
+ verifyCetAdaptorSigFromOracleInfo(
119
+ adaptorSig: AdaptorSignature,
120
+ cet: DdkTransaction,
121
+ oracleInfo: Array<DdkOracleInfo>,
122
+ pubkey: Buffer,
123
+ fundingScriptPubkey: Buffer,
124
+ totalCollateral: bigint,
125
+ msgs: Array<Array<Buffer>>,
126
+ ): boolean;
127
+
128
+ verifyCetAdaptorSigsFromOracleInfo(
129
+ adaptorSigs: Array<AdaptorSignature>,
130
+ cets: Array<DdkTransaction>,
131
+ oracleInfo: Array<DdkOracleInfo>,
132
+ pubkey: Buffer,
133
+ fundingScriptPubkey: Buffer,
134
+ totalCollateral: bigint,
135
+ msgs: Array<Array<Array<Buffer>>>,
136
+ ): boolean;
137
+
138
+ createCets(
139
+ fundTxId: string,
140
+ fundVout: number,
141
+ localFinalScriptPubkey: Buffer,
142
+ remoteFinalScriptPubkey: Buffer,
143
+ outcomes: Array<Payout>,
144
+ lockTime: number,
145
+ localSerialId: bigint,
146
+ remoteSerialId: bigint,
147
+ ): Array<DdkTransaction>;
148
+
149
+ createDlcTransactions(
150
+ outcomes: Array<Payout>,
151
+ localParams: PartyParams,
152
+ remoteParams: PartyParams,
153
+ refundLocktime: number,
154
+ feeRate: bigint,
155
+ fundLockTime: number,
156
+ cetLockTime: number,
157
+ fundOutputSerialId: bigint,
158
+ ): DdkDlcTransactions;
159
+
160
+ createFundTxLockingScript(
161
+ localFundPubkey: Buffer,
162
+ remoteFundPubkey: Buffer,
163
+ ): Buffer;
164
+
165
+ createRefundTransaction(
166
+ localFinalScriptPubkey: Buffer,
167
+ remoteFinalScriptPubkey: Buffer,
168
+ localAmount: bigint,
169
+ remoteAmount: bigint,
170
+ lockTime: number,
171
+ fundTxId: string,
172
+ fundVout: number,
173
+ ): DdkTransaction;
174
+
175
+ createSplicedDlcTransactions(
176
+ outcomes: Array<Payout>,
177
+ localParams: PartyParams,
178
+ remoteParams: PartyParams,
179
+ refundLocktime: number,
180
+ feeRate: bigint,
181
+ fundLockTime: number,
182
+ cetLockTime: number,
183
+ fundOutputSerialId: bigint,
184
+ ): DdkDlcTransactions;
185
+
186
+ getChangeOutputAndFees(
187
+ params: PartyParams,
188
+ feeRate: bigint,
189
+ ): ChangeOutputAndFees;
190
+
191
+ getRawFundingTransactionInputSignature(
192
+ fundingTransaction: DdkTransaction,
193
+ privkey: Buffer,
194
+ prevTxId: string,
195
+ prevTxVout: number,
196
+ value: bigint,
197
+ ): Buffer;
198
+
199
+ getTotalInputVsize(inputs: Array<TxInputInfo>): number;
200
+
201
+ isDustOutput(output: TxOutput): boolean;
202
+
203
+ signFundTransactionInput(
204
+ fundTransaction: DdkTransaction,
205
+ privkey: Buffer,
206
+ prevTxId: string,
207
+ prevTxVout: number,
208
+ value: bigint,
209
+ ): DdkTransaction;
210
+
211
+ verifyFundTxSignature(
212
+ fundTx: DdkTransaction,
213
+ signature: Buffer,
214
+ pubkey: Buffer,
215
+ txid: string,
216
+ vout: number,
217
+ inputAmount: bigint,
218
+ ): boolean;
219
+
220
+ signCet(
221
+ cet: DdkTransaction,
222
+ adaptorSignature: Buffer,
223
+ oracleSignatures: Array<Buffer>,
224
+ fundingSecretKey: Buffer,
225
+ otherPubkey: Buffer,
226
+ fundingScriptPubkey: Buffer,
227
+ fundOutputValue: bigint,
228
+ ): DdkTransaction;
229
+
230
+ convertMnemonicToSeed(mnemonic: string, passphrase?: string | null): Buffer;
231
+
232
+ createXprivFromParentPath(
233
+ xpriv: Buffer,
234
+ baseDerivationPath: string,
235
+ network: string,
236
+ path: string,
237
+ ): Buffer;
238
+
239
+ getXpubFromXpriv(xpriv: Buffer, network: string): Buffer;
240
+
241
+ version(): string;
242
+
243
+ addSignatureToTransaction(
244
+ tx: DdkTransaction,
245
+ signature: Buffer,
246
+ pubkey: Buffer,
247
+ inputIndex: number,
248
+ ): DdkTransaction;
249
+
250
+ signMultiSigInput(
251
+ tx: DdkTransaction,
252
+ dlcInput: DdkDlcInputInfo,
253
+ localPrivkey: Buffer,
254
+ remoteSignature: Buffer,
255
+ ): DdkTransaction;
256
+ }
257
+
258
+ // Legacy function declarations for backward compatibility
259
+ export declare function createCet(
260
+ localOutput: TxOutput,
261
+ localPayoutSerialId: bigint,
262
+ remoteOutput: TxOutput,
263
+ remotePayoutSerialId: bigint,
264
+ fundTxId: string,
265
+ fundVout: number,
266
+ lockTime: number,
267
+ ): DdkTransaction;
268
+
269
+ export declare function createCetAdaptorSignatureFromOracleInfo(
270
+ cet: DdkTransaction,
271
+ oracleInfo: DdkOracleInfo,
272
+ fundingSk: Buffer,
273
+ fundingScriptPubkey: Buffer,
274
+ totalCollateral: bigint,
275
+ msgs: Array<Buffer>,
276
+ ): AdaptorSignature;
277
+
278
+ export declare function createCetAdaptorSigsFromOracleInfo(
279
+ cets: Array<DdkTransaction>,
280
+ oracleInfo: Array<DdkOracleInfo>,
281
+ fundingSecretKey: Buffer,
282
+ fundingScriptPubkey: Buffer,
283
+ fundOutputValue: bigint,
284
+ msgs: Array<Array<Array<Buffer>>>,
285
+ ): Array<AdaptorSignature>;
286
+
287
+ export declare function verifyCetAdaptorSigFromOracleInfo(
288
+ adaptorSig: AdaptorSignature,
289
+ cet: DdkTransaction,
290
+ oracleInfo: Array<DdkOracleInfo>,
291
+ pubkey: Buffer,
292
+ fundingScriptPubkey: Buffer,
293
+ totalCollateral: bigint,
294
+ msgs: Array<Array<Buffer>>,
295
+ ): boolean;
296
+
297
+ export declare function verifyCetAdaptorSigsFromOracleInfo(
298
+ adaptorSigs: Array<AdaptorSignature>,
299
+ cets: Array<DdkTransaction>,
300
+ oracleInfo: Array<DdkOracleInfo>,
301
+ pubkey: Buffer,
302
+ fundingScriptPubkey: Buffer,
303
+ totalCollateral: bigint,
304
+ msgs: Array<Array<Array<Buffer>>>,
305
+ ): boolean;
306
+
307
+ export declare function createCets(
308
+ fundTxId: string,
309
+ fundVout: number,
310
+ localFinalScriptPubkey: Buffer,
311
+ remoteFinalScriptPubkey: Buffer,
312
+ outcomes: Array<Payout>,
313
+ lockTime: number,
314
+ localSerialId: bigint,
315
+ remoteSerialId: bigint,
316
+ ): Array<DdkTransaction>;
317
+
318
+ export declare function createDlcTransactions(
319
+ outcomes: Array<Payout>,
320
+ localParams: PartyParams,
321
+ remoteParams: PartyParams,
322
+ refundLocktime: number,
323
+ feeRate: bigint,
324
+ fundLockTime: number,
325
+ cetLockTime: number,
326
+ fundOutputSerialId: bigint,
327
+ ): DdkDlcTransactions;
328
+
329
+ export declare function createFundTxLockingScript(
330
+ localFundPubkey: Buffer,
331
+ remoteFundPubkey: Buffer,
332
+ ): Buffer;
333
+
334
+ export declare function createRefundTransaction(
335
+ localFinalScriptPubkey: Buffer,
336
+ remoteFinalScriptPubkey: Buffer,
337
+ localAmount: bigint,
338
+ remoteAmount: bigint,
339
+ lockTime: number,
340
+ fundTxId: string,
341
+ fundVout: number,
342
+ ): DdkTransaction;
343
+
344
+ export declare function createSplicedDlcTransactions(
345
+ outcomes: Array<Payout>,
346
+ localParams: PartyParams,
347
+ remoteParams: PartyParams,
348
+ refundLocktime: number,
349
+ feeRate: bigint,
350
+ fundLockTime: number,
351
+ cetLockTime: number,
352
+ fundOutputSerialId: bigint,
353
+ ): DdkDlcTransactions;
354
+
355
+ export declare function getChangeOutputAndFees(
356
+ params: PartyParams,
357
+ feeRate: bigint,
358
+ ): ChangeOutputAndFees;
359
+
360
+ export declare function getRawFundingTransactionInputSignature(
361
+ fundingTransaction: DdkTransaction,
362
+ privkey: Buffer,
363
+ prevTxId: string,
364
+ prevTxVout: number,
365
+ value: bigint,
366
+ ): Buffer;
367
+
368
+ export declare function getTotalInputVsize(inputs: Array<TxInputInfo>): number;
369
+
370
+ export declare function isDustOutput(output: TxOutput): boolean;
371
+
372
+ export declare function signFundTransactionInput(
373
+ fundTransaction: DdkTransaction,
374
+ privkey: Buffer,
375
+ prevTxId: string,
376
+ prevTxVout: number,
377
+ value: bigint,
378
+ ): DdkTransaction;
379
+
380
+ export declare function verifyFundTxSignature(
381
+ fundTx: DdkTransaction,
382
+ signature: Buffer,
383
+ pubkey: Buffer,
384
+ txid: string,
385
+ vout: number,
386
+ inputAmount: bigint,
387
+ ): boolean;
388
+
389
+ export declare function version(): string;
390
+
391
+ export declare function signCet(
392
+ cet: DdkTransaction,
393
+ adaptorSignature: Buffer,
394
+ oracleSignatures: Array<Buffer>,
395
+ fundingSecretKey: Buffer,
396
+ otherPubkey: Buffer,
397
+ fundingScriptPubkey: Buffer,
398
+ fundOutputValue: bigint,
399
+ ): DdkTransaction;
400
+
401
+ export declare function convertMnemonicToSeed(
402
+ mnemonic: string,
403
+ passphrase?: string | null,
404
+ ): Buffer;
405
+
406
+ export declare function createXprivFromParentPath(
407
+ xpriv: Buffer,
408
+ baseDerivationPath: string,
409
+ network: string,
410
+ path: string,
411
+ ): Buffer;
412
+
413
+ export declare function getXpubFromXpriv(
414
+ xpriv: Buffer,
415
+ network: string,
416
+ ): Buffer;
417
+
418
+ export declare function addSignatureToTransaction(
419
+ tx: DdkTransaction,
420
+ signature: Buffer,
421
+ pubkey: Buffer,
422
+ inputIndex: number,
423
+ ): DdkTransaction;
424
+
425
+ export declare function signMultiSigInput(
426
+ tx: DdkTransaction,
427
+ dlcInput: DdkDlcInputInfo,
428
+ localPrivkey: Buffer,
429
+ remoteSignature: Buffer,
430
+ ): DdkTransaction;
package/lib/dlc.ts CHANGED
@@ -1,6 +1,3 @@
1
- /* eslint-disable max-len */
2
- /* eslint-disable indent */
3
-
4
1
  import { Tx } from '@node-dlc/bitcoin';
5
2
  import {
6
3
  CetAdaptorSignatures,
@@ -335,9 +332,6 @@ interface PayoutGroup {
335
332
  groups: number[][];
336
333
  }
337
334
 
338
- /* eslint-disable max-len */
339
- /* eslint-disable indent */
340
-
341
335
  export interface AdaptorPair {
342
336
  signature: string;
343
337
  proof: string;
package/lib/index.ts CHANGED
@@ -34,6 +34,7 @@ interface IClient {
34
34
  export * from './cfd';
35
35
  export * from './common';
36
36
  export * from './dlc';
37
+ export * from './ddk';
37
38
  export { default as Amount } from './models/Amount';
38
39
  export {
39
40
  default as Input,
package/lib/jsonrpc.ts CHANGED
@@ -48,16 +48,6 @@ export interface AddressInfo {
48
48
 
49
49
  export type AddressGrouping = string[][];
50
50
 
51
- export interface ReceivedByAddress {
52
- involvesWatchonly: boolean;
53
- address: string;
54
- account: string;
55
- amount: number;
56
- confirmations: number;
57
- label: string;
58
- txids: string[];
59
- }
60
-
61
51
  export interface Block {
62
52
  hash: string;
63
53
  confirmations: number;
@@ -76,6 +76,7 @@ export default class Input {
76
76
  inputSerialId: this.inputSerialId,
77
77
  toJSON: Utxo.prototype.toJSON,
78
78
  toInput: Utxo.prototype.toInput,
79
+ toTxInputInfo: Utxo.prototype.toTxInputInfo,
79
80
  };
80
81
  }
81
82
 
@@ -1,3 +1,4 @@
1
+ import { TxInputInfo } from '../ddk';
1
2
  import Amount, { AmountJSON } from './Amount';
2
3
  import Input from './Input';
3
4
 
@@ -37,6 +38,16 @@ export default class Utxo {
37
38
  );
38
39
  }
39
40
 
41
+ public toTxInputInfo(): TxInputInfo {
42
+ return {
43
+ txid: this.txid,
44
+ vout: this.vout,
45
+ scriptSig: Buffer.alloc(0),
46
+ maxWitnessLength: this.maxWitnessLength,
47
+ serialId: this.inputSerialId ? BigInt(this.inputSerialId) : undefined,
48
+ };
49
+ }
50
+
40
51
  public toJSON(): UtxoJSON {
41
52
  return Object.assign({}, this, {
42
53
  txid: this.txid,
package/package.json CHANGED
@@ -1,19 +1,12 @@
1
1
  {
2
2
  "name": "@atomicfinance/types",
3
3
  "umdName": "Types",
4
- "version": "4.0.2",
4
+ "version": "4.1.0",
5
5
  "description": "Bitcoin Abstraction Layer Types",
6
6
  "author": "Atomic Finance <info@atomic.finance>",
7
7
  "homepage": "",
8
8
  "license": "ISC",
9
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
10
  "dependencies": {
18
11
  "@node-dlc/bitcoin": "1.1.0",
19
12
  "@node-dlc/messaging": "1.1.0",
@@ -22,9 +15,15 @@
22
15
  },
23
16
  "devDependencies": {
24
17
  "@types/lodash": "^4.14.160",
25
- "@types/node": "16.10.3"
18
+ "@types/node": "20.19.10"
26
19
  },
27
20
  "publishConfig": {
28
21
  "access": "public"
22
+ },
23
+ "scripts": {
24
+ "build": "../../node_modules/.bin/tsc --project tsconfig.json",
25
+ "test": "pnpm run build",
26
+ "lint": "../../node_modules/.bin/eslint .",
27
+ "lint:fix": "../../node_modules/.bin/eslint --fix ."
29
28
  }
30
- }
29
+ }