@bennyblader/ddk-ts 0.1.5 → 0.1.8
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/ddk-ts.darwin-arm64.node +0 -0
- package/ddk-ts.node +0 -0
- package/index.d.ts +114 -0
- package/index.js +46 -46
- package/package.json +6 -4
- package/src/conversions.rs +0 -268
- package/src/lib.rs +0 -285
- package/src/types.rs +0 -111
|
Binary file
|
package/ddk-ts.node
ADDED
|
Binary file
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/* auto-generated by NAPI-RS */
|
|
2
|
+
/* eslint-disable */
|
|
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 declare function createCet(localOutput: TxOutput, localPayoutSerialId: bigint, remoteOutput: TxOutput, remotePayoutSerialId: bigint, fundTxId: string, fundVout: number, lockTime: number): Transaction
|
|
15
|
+
|
|
16
|
+
export declare function createCetAdaptorSignatureFromOracleInfo(cet: Transaction, oracleInfo: OracleInfo, fundingSk: Buffer, fundingScriptPubkey: Buffer, totalCollateral: bigint, msgs: Array<Buffer>): AdaptorSignature
|
|
17
|
+
|
|
18
|
+
export declare function createCets(fundTxId: string, fundVout: number, localFinalScriptPubkey: Buffer, remoteFinalScriptPubkey: Buffer, outcomes: Array<DlcOutcome>, lockTime: number, localSerialId: bigint, remoteSerialId: bigint): Array<Transaction>
|
|
19
|
+
|
|
20
|
+
export declare function createDlcTransactions(outcomes: Array<DlcOutcome>, localParams: PartyParams, remoteParams: PartyParams, refundLocktime: number, feeRate: bigint, fundLockTime: number, cetLockTime: number, fundOutputSerialId: bigint): DlcTransactions
|
|
21
|
+
|
|
22
|
+
export declare function createFundTxLockingScript(localFundPubkey: Buffer, remoteFundPubkey: Buffer): Buffer
|
|
23
|
+
|
|
24
|
+
export declare function createRefundTransaction(localFinalScriptPubkey: Buffer, remoteFinalScriptPubkey: Buffer, localAmount: bigint, remoteAmount: bigint, lockTime: number, fundTxId: string, fundVout: number): Transaction
|
|
25
|
+
|
|
26
|
+
export declare function createSplicedDlcTransactions(outcomes: Array<DlcOutcome>, localParams: PartyParams, remoteParams: PartyParams, refundLocktime: number, feeRate: bigint, fundLockTime: number, cetLockTime: number, fundOutputSerialId: bigint): DlcTransactions
|
|
27
|
+
|
|
28
|
+
export interface DlcInputInfo {
|
|
29
|
+
fundTx: Transaction
|
|
30
|
+
fundVout: number
|
|
31
|
+
localFundPubkey: Buffer
|
|
32
|
+
remoteFundPubkey: Buffer
|
|
33
|
+
fundAmount: bigint
|
|
34
|
+
maxWitnessLen: number
|
|
35
|
+
inputSerialId: bigint
|
|
36
|
+
contractId: Buffer
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface DlcOutcome {
|
|
40
|
+
localPayout: bigint
|
|
41
|
+
remotePayout: bigint
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface DlcTransactions {
|
|
45
|
+
fund: Transaction
|
|
46
|
+
cets: Array<Transaction>
|
|
47
|
+
refund: Transaction
|
|
48
|
+
fundingScriptPubkey: Buffer
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export declare function getChangeOutputAndFees(params: PartyParams, feeRate: bigint): ChangeOutputAndFees
|
|
52
|
+
|
|
53
|
+
export declare function getRawFundingTransactionInputSignature(fundingTransaction: Transaction, privkey: Buffer, prevTxId: string, prevTxVout: number, value: bigint): Buffer
|
|
54
|
+
|
|
55
|
+
export declare function getTotalInputVsize(inputs: Array<TxInputInfo>): number
|
|
56
|
+
|
|
57
|
+
export declare function isDustOutput(output: TxOutput): boolean
|
|
58
|
+
|
|
59
|
+
export interface OracleInfo {
|
|
60
|
+
publicKey: Buffer
|
|
61
|
+
nonces: Array<Buffer>
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface PartyParams {
|
|
65
|
+
fundPubkey: Buffer
|
|
66
|
+
changeScriptPubkey: Buffer
|
|
67
|
+
changeSerialId: bigint
|
|
68
|
+
payoutScriptPubkey: Buffer
|
|
69
|
+
payoutSerialId: bigint
|
|
70
|
+
inputs: Array<TxInputInfo>
|
|
71
|
+
inputAmount: bigint
|
|
72
|
+
collateral: bigint
|
|
73
|
+
dlcInputs: Array<DlcInputInfo>
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface Payout {
|
|
77
|
+
offer: bigint
|
|
78
|
+
accept: bigint
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export declare function signFundTransactionInput(fundTransaction: Transaction, privkey: Buffer, prevTxId: string, prevTxVout: number, value: bigint): Transaction
|
|
82
|
+
|
|
83
|
+
export interface Transaction {
|
|
84
|
+
version: number
|
|
85
|
+
lockTime: number
|
|
86
|
+
inputs: Array<TxInput>
|
|
87
|
+
outputs: Array<TxOutput>
|
|
88
|
+
rawBytes: Buffer
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export interface TxInput {
|
|
92
|
+
txid: string
|
|
93
|
+
vout: number
|
|
94
|
+
scriptSig: Buffer
|
|
95
|
+
sequence: number
|
|
96
|
+
witness: Array<Buffer>
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export interface TxInputInfo {
|
|
100
|
+
txid: string
|
|
101
|
+
vout: number
|
|
102
|
+
scriptSig: Buffer
|
|
103
|
+
maxWitnessLength: number
|
|
104
|
+
serialId: bigint
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface TxOutput {
|
|
108
|
+
value: bigint
|
|
109
|
+
scriptPubkey: Buffer
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export declare function verifyFundTxSignature(fundTx: Transaction, signature: Buffer, pubkey: Buffer, txid: string, vout: number, inputAmount: bigint): boolean
|
|
113
|
+
|
|
114
|
+
export declare function version(): string
|
package/index.js
CHANGED
|
@@ -80,8 +80,8 @@ function requireNative() {
|
|
|
80
80
|
try {
|
|
81
81
|
const binding = require('@bennyblader/ddk-ts-android-arm64')
|
|
82
82
|
const bindingPackageVersion = require('@bennyblader/ddk-ts-android-arm64/package.json').version
|
|
83
|
-
if (bindingPackageVersion !== '0.1.
|
|
84
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
83
|
+
if (bindingPackageVersion !== '0.1.8' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
84
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.8 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
85
85
|
}
|
|
86
86
|
return binding
|
|
87
87
|
} catch (e) {
|
|
@@ -96,8 +96,8 @@ function requireNative() {
|
|
|
96
96
|
try {
|
|
97
97
|
const binding = require('@bennyblader/ddk-ts-android-arm-eabi')
|
|
98
98
|
const bindingPackageVersion = require('@bennyblader/ddk-ts-android-arm-eabi/package.json').version
|
|
99
|
-
if (bindingPackageVersion !== '0.1.
|
|
100
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
99
|
+
if (bindingPackageVersion !== '0.1.8' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
100
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.8 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
101
101
|
}
|
|
102
102
|
return binding
|
|
103
103
|
} catch (e) {
|
|
@@ -116,8 +116,8 @@ function requireNative() {
|
|
|
116
116
|
try {
|
|
117
117
|
const binding = require('@bennyblader/ddk-ts-win32-x64-msvc')
|
|
118
118
|
const bindingPackageVersion = require('@bennyblader/ddk-ts-win32-x64-msvc/package.json').version
|
|
119
|
-
if (bindingPackageVersion !== '0.1.
|
|
120
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
119
|
+
if (bindingPackageVersion !== '0.1.8' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
120
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.8 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
121
121
|
}
|
|
122
122
|
return binding
|
|
123
123
|
} catch (e) {
|
|
@@ -132,8 +132,8 @@ function requireNative() {
|
|
|
132
132
|
try {
|
|
133
133
|
const binding = require('@bennyblader/ddk-ts-win32-ia32-msvc')
|
|
134
134
|
const bindingPackageVersion = require('@bennyblader/ddk-ts-win32-ia32-msvc/package.json').version
|
|
135
|
-
if (bindingPackageVersion !== '0.1.
|
|
136
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
135
|
+
if (bindingPackageVersion !== '0.1.8' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
136
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.8 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
137
137
|
}
|
|
138
138
|
return binding
|
|
139
139
|
} catch (e) {
|
|
@@ -148,8 +148,8 @@ function requireNative() {
|
|
|
148
148
|
try {
|
|
149
149
|
const binding = require('@bennyblader/ddk-ts-win32-arm64-msvc')
|
|
150
150
|
const bindingPackageVersion = require('@bennyblader/ddk-ts-win32-arm64-msvc/package.json').version
|
|
151
|
-
if (bindingPackageVersion !== '0.1.
|
|
152
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
151
|
+
if (bindingPackageVersion !== '0.1.8' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
152
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.8 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
153
153
|
}
|
|
154
154
|
return binding
|
|
155
155
|
} catch (e) {
|
|
@@ -167,8 +167,8 @@ function requireNative() {
|
|
|
167
167
|
try {
|
|
168
168
|
const binding = require('@bennyblader/ddk-ts-darwin-universal')
|
|
169
169
|
const bindingPackageVersion = require('@bennyblader/ddk-ts-darwin-universal/package.json').version
|
|
170
|
-
if (bindingPackageVersion !== '0.1.
|
|
171
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
170
|
+
if (bindingPackageVersion !== '0.1.8' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
171
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.8 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
172
172
|
}
|
|
173
173
|
return binding
|
|
174
174
|
} catch (e) {
|
|
@@ -183,8 +183,8 @@ function requireNative() {
|
|
|
183
183
|
try {
|
|
184
184
|
const binding = require('@bennyblader/ddk-ts-darwin-x64')
|
|
185
185
|
const bindingPackageVersion = require('@bennyblader/ddk-ts-darwin-x64/package.json').version
|
|
186
|
-
if (bindingPackageVersion !== '0.1.
|
|
187
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
186
|
+
if (bindingPackageVersion !== '0.1.8' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
187
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.8 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
188
188
|
}
|
|
189
189
|
return binding
|
|
190
190
|
} catch (e) {
|
|
@@ -199,8 +199,8 @@ function requireNative() {
|
|
|
199
199
|
try {
|
|
200
200
|
const binding = require('@bennyblader/ddk-ts-darwin-arm64')
|
|
201
201
|
const bindingPackageVersion = require('@bennyblader/ddk-ts-darwin-arm64/package.json').version
|
|
202
|
-
if (bindingPackageVersion !== '0.1.
|
|
203
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
202
|
+
if (bindingPackageVersion !== '0.1.8' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
203
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.8 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
204
204
|
}
|
|
205
205
|
return binding
|
|
206
206
|
} catch (e) {
|
|
@@ -219,8 +219,8 @@ function requireNative() {
|
|
|
219
219
|
try {
|
|
220
220
|
const binding = require('@bennyblader/ddk-ts-freebsd-x64')
|
|
221
221
|
const bindingPackageVersion = require('@bennyblader/ddk-ts-freebsd-x64/package.json').version
|
|
222
|
-
if (bindingPackageVersion !== '0.1.
|
|
223
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
222
|
+
if (bindingPackageVersion !== '0.1.8' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
223
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.8 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
224
224
|
}
|
|
225
225
|
return binding
|
|
226
226
|
} catch (e) {
|
|
@@ -235,8 +235,8 @@ function requireNative() {
|
|
|
235
235
|
try {
|
|
236
236
|
const binding = require('@bennyblader/ddk-ts-freebsd-arm64')
|
|
237
237
|
const bindingPackageVersion = require('@bennyblader/ddk-ts-freebsd-arm64/package.json').version
|
|
238
|
-
if (bindingPackageVersion !== '0.1.
|
|
239
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
238
|
+
if (bindingPackageVersion !== '0.1.8' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
239
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.8 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
240
240
|
}
|
|
241
241
|
return binding
|
|
242
242
|
} catch (e) {
|
|
@@ -256,8 +256,8 @@ function requireNative() {
|
|
|
256
256
|
try {
|
|
257
257
|
const binding = require('@bennyblader/ddk-ts-linux-x64-musl')
|
|
258
258
|
const bindingPackageVersion = require('@bennyblader/ddk-ts-linux-x64-musl/package.json').version
|
|
259
|
-
if (bindingPackageVersion !== '0.1.
|
|
260
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
259
|
+
if (bindingPackageVersion !== '0.1.8' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
260
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.8 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
261
261
|
}
|
|
262
262
|
return binding
|
|
263
263
|
} catch (e) {
|
|
@@ -272,8 +272,8 @@ function requireNative() {
|
|
|
272
272
|
try {
|
|
273
273
|
const binding = require('@bennyblader/ddk-ts-linux-x64-gnu')
|
|
274
274
|
const bindingPackageVersion = require('@bennyblader/ddk-ts-linux-x64-gnu/package.json').version
|
|
275
|
-
if (bindingPackageVersion !== '0.1.
|
|
276
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
275
|
+
if (bindingPackageVersion !== '0.1.8' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
276
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.8 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
277
277
|
}
|
|
278
278
|
return binding
|
|
279
279
|
} catch (e) {
|
|
@@ -290,8 +290,8 @@ function requireNative() {
|
|
|
290
290
|
try {
|
|
291
291
|
const binding = require('@bennyblader/ddk-ts-linux-arm64-musl')
|
|
292
292
|
const bindingPackageVersion = require('@bennyblader/ddk-ts-linux-arm64-musl/package.json').version
|
|
293
|
-
if (bindingPackageVersion !== '0.1.
|
|
294
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
293
|
+
if (bindingPackageVersion !== '0.1.8' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
294
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.8 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
295
295
|
}
|
|
296
296
|
return binding
|
|
297
297
|
} catch (e) {
|
|
@@ -306,8 +306,8 @@ function requireNative() {
|
|
|
306
306
|
try {
|
|
307
307
|
const binding = require('@bennyblader/ddk-ts-linux-arm64-gnu')
|
|
308
308
|
const bindingPackageVersion = require('@bennyblader/ddk-ts-linux-arm64-gnu/package.json').version
|
|
309
|
-
if (bindingPackageVersion !== '0.1.
|
|
310
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
309
|
+
if (bindingPackageVersion !== '0.1.8' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
310
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.8 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
311
311
|
}
|
|
312
312
|
return binding
|
|
313
313
|
} catch (e) {
|
|
@@ -324,8 +324,8 @@ function requireNative() {
|
|
|
324
324
|
try {
|
|
325
325
|
const binding = require('@bennyblader/ddk-ts-linux-arm-musleabihf')
|
|
326
326
|
const bindingPackageVersion = require('@bennyblader/ddk-ts-linux-arm-musleabihf/package.json').version
|
|
327
|
-
if (bindingPackageVersion !== '0.1.
|
|
328
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
327
|
+
if (bindingPackageVersion !== '0.1.8' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
328
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.8 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
329
329
|
}
|
|
330
330
|
return binding
|
|
331
331
|
} catch (e) {
|
|
@@ -340,8 +340,8 @@ function requireNative() {
|
|
|
340
340
|
try {
|
|
341
341
|
const binding = require('@bennyblader/ddk-ts-linux-arm-gnueabihf')
|
|
342
342
|
const bindingPackageVersion = require('@bennyblader/ddk-ts-linux-arm-gnueabihf/package.json').version
|
|
343
|
-
if (bindingPackageVersion !== '0.1.
|
|
344
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
343
|
+
if (bindingPackageVersion !== '0.1.8' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
344
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.8 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
345
345
|
}
|
|
346
346
|
return binding
|
|
347
347
|
} catch (e) {
|
|
@@ -358,8 +358,8 @@ function requireNative() {
|
|
|
358
358
|
try {
|
|
359
359
|
const binding = require('@bennyblader/ddk-ts-linux-riscv64-musl')
|
|
360
360
|
const bindingPackageVersion = require('@bennyblader/ddk-ts-linux-riscv64-musl/package.json').version
|
|
361
|
-
if (bindingPackageVersion !== '0.1.
|
|
362
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
361
|
+
if (bindingPackageVersion !== '0.1.8' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
362
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.8 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
363
363
|
}
|
|
364
364
|
return binding
|
|
365
365
|
} catch (e) {
|
|
@@ -374,8 +374,8 @@ function requireNative() {
|
|
|
374
374
|
try {
|
|
375
375
|
const binding = require('@bennyblader/ddk-ts-linux-riscv64-gnu')
|
|
376
376
|
const bindingPackageVersion = require('@bennyblader/ddk-ts-linux-riscv64-gnu/package.json').version
|
|
377
|
-
if (bindingPackageVersion !== '0.1.
|
|
378
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
377
|
+
if (bindingPackageVersion !== '0.1.8' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
378
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.8 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
379
379
|
}
|
|
380
380
|
return binding
|
|
381
381
|
} catch (e) {
|
|
@@ -391,8 +391,8 @@ function requireNative() {
|
|
|
391
391
|
try {
|
|
392
392
|
const binding = require('@bennyblader/ddk-ts-linux-ppc64-gnu')
|
|
393
393
|
const bindingPackageVersion = require('@bennyblader/ddk-ts-linux-ppc64-gnu/package.json').version
|
|
394
|
-
if (bindingPackageVersion !== '0.1.
|
|
395
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
394
|
+
if (bindingPackageVersion !== '0.1.8' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
395
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.8 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
396
396
|
}
|
|
397
397
|
return binding
|
|
398
398
|
} catch (e) {
|
|
@@ -407,8 +407,8 @@ function requireNative() {
|
|
|
407
407
|
try {
|
|
408
408
|
const binding = require('@bennyblader/ddk-ts-linux-s390x-gnu')
|
|
409
409
|
const bindingPackageVersion = require('@bennyblader/ddk-ts-linux-s390x-gnu/package.json').version
|
|
410
|
-
if (bindingPackageVersion !== '0.1.
|
|
411
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
410
|
+
if (bindingPackageVersion !== '0.1.8' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
411
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.8 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
412
412
|
}
|
|
413
413
|
return binding
|
|
414
414
|
} catch (e) {
|
|
@@ -427,8 +427,8 @@ function requireNative() {
|
|
|
427
427
|
try {
|
|
428
428
|
const binding = require('@bennyblader/ddk-ts-openharmony-arm64')
|
|
429
429
|
const bindingPackageVersion = require('@bennyblader/ddk-ts-openharmony-arm64/package.json').version
|
|
430
|
-
if (bindingPackageVersion !== '0.1.
|
|
431
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
430
|
+
if (bindingPackageVersion !== '0.1.8' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
431
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.8 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
432
432
|
}
|
|
433
433
|
return binding
|
|
434
434
|
} catch (e) {
|
|
@@ -443,8 +443,8 @@ function requireNative() {
|
|
|
443
443
|
try {
|
|
444
444
|
const binding = require('@bennyblader/ddk-ts-openharmony-x64')
|
|
445
445
|
const bindingPackageVersion = require('@bennyblader/ddk-ts-openharmony-x64/package.json').version
|
|
446
|
-
if (bindingPackageVersion !== '0.1.
|
|
447
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
446
|
+
if (bindingPackageVersion !== '0.1.8' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
447
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.8 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
448
448
|
}
|
|
449
449
|
return binding
|
|
450
450
|
} catch (e) {
|
|
@@ -459,8 +459,8 @@ function requireNative() {
|
|
|
459
459
|
try {
|
|
460
460
|
const binding = require('@bennyblader/ddk-ts-openharmony-arm')
|
|
461
461
|
const bindingPackageVersion = require('@bennyblader/ddk-ts-openharmony-arm/package.json').version
|
|
462
|
-
if (bindingPackageVersion !== '0.1.
|
|
463
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
462
|
+
if (bindingPackageVersion !== '0.1.8' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
463
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.8 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
464
464
|
}
|
|
465
465
|
return binding
|
|
466
466
|
} catch (e) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bennyblader/ddk-ts",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "dlcdevkit typescript bindings",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": "https://github.com/bennyblader/ddk-ffi",
|
|
@@ -13,7 +13,9 @@
|
|
|
13
13
|
"dlcdevkit"
|
|
14
14
|
],
|
|
15
15
|
"files": [
|
|
16
|
-
"
|
|
16
|
+
"index.js",
|
|
17
|
+
"index.d.ts",
|
|
18
|
+
"*.node"
|
|
17
19
|
],
|
|
18
20
|
"napi": {
|
|
19
21
|
"binaryName": "ddk-ts",
|
|
@@ -89,7 +91,7 @@
|
|
|
89
91
|
],
|
|
90
92
|
"packageManager": "yarn@4.9.2",
|
|
91
93
|
"optionalDependencies": {
|
|
92
|
-
"@bennyblader/ddk-ts-darwin-arm64": "0.1.
|
|
93
|
-
"@bennyblader/ddk-ts-linux-x64-gnu": "0.1.
|
|
94
|
+
"@bennyblader/ddk-ts-darwin-arm64": "0.1.8",
|
|
95
|
+
"@bennyblader/ddk-ts-linux-x64-gnu": "0.1.8"
|
|
94
96
|
}
|
|
95
97
|
}
|
package/src/conversions.rs
DELETED
|
@@ -1,268 +0,0 @@
|
|
|
1
|
-
use crate::types::*;
|
|
2
|
-
use napi::bindgen_prelude::*;
|
|
3
|
-
|
|
4
|
-
// Helper function to convert BigInt to u64 safely
|
|
5
|
-
pub fn bigint_to_u64(bi: &BigInt) -> Result<u64> {
|
|
6
|
-
let (sign_bit, value, _lossless) = bi.get_u64();
|
|
7
|
-
if sign_bit {
|
|
8
|
-
return Err(Error::from_reason("BigInt value is negative"));
|
|
9
|
-
}
|
|
10
|
-
Ok(value)
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
// Helper function to convert Vec<u8> to Buffer
|
|
14
|
-
pub fn vec_to_buffer(vec: Vec<u8>) -> Buffer {
|
|
15
|
-
Buffer::from(vec)
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// Helper function to convert Buffer to Vec<u8>
|
|
19
|
-
pub fn buffer_to_vec(buffer: &Buffer) -> Vec<u8> {
|
|
20
|
-
buffer.to_vec()
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// Convert ddk_ffi Transaction to NAPI Transaction
|
|
24
|
-
impl From<ddk_ffi::Transaction> for Transaction {
|
|
25
|
-
fn from(tx: ddk_ffi::Transaction) -> Self {
|
|
26
|
-
Transaction {
|
|
27
|
-
version: tx.version,
|
|
28
|
-
lock_time: tx.lock_time,
|
|
29
|
-
inputs: tx.inputs.into_iter().map(Into::into).collect(),
|
|
30
|
-
outputs: tx.outputs.into_iter().map(Into::into).collect(),
|
|
31
|
-
raw_bytes: Buffer::from(tx.raw_bytes),
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// Convert NAPI Transaction to ddk_ffi Transaction
|
|
37
|
-
impl TryFrom<Transaction> for ddk_ffi::Transaction {
|
|
38
|
-
type Error = napi::Error;
|
|
39
|
-
|
|
40
|
-
fn try_from(tx: Transaction) -> Result<Self> {
|
|
41
|
-
let outputs: Result<Vec<_>> = tx.outputs.into_iter().map(TryInto::try_into).collect();
|
|
42
|
-
Ok(ddk_ffi::Transaction {
|
|
43
|
-
version: tx.version,
|
|
44
|
-
lock_time: tx.lock_time,
|
|
45
|
-
inputs: tx.inputs.into_iter().map(Into::into).collect(),
|
|
46
|
-
outputs: outputs?,
|
|
47
|
-
raw_bytes: tx.raw_bytes.to_vec(),
|
|
48
|
-
})
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Convert NAPI TxInput to ddk_ffi TxInput
|
|
53
|
-
impl From<TxInput> for ddk_ffi::TxInput {
|
|
54
|
-
fn from(input: TxInput) -> Self {
|
|
55
|
-
ddk_ffi::TxInput {
|
|
56
|
-
txid: input.txid,
|
|
57
|
-
vout: input.vout,
|
|
58
|
-
script_sig: input.script_sig.to_vec(),
|
|
59
|
-
sequence: input.sequence,
|
|
60
|
-
witness: input.witness.into_iter().map(|w| w.to_vec()).collect(),
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Convert ddk_ffi TxInput to NAPI TxInput
|
|
66
|
-
impl From<ddk_ffi::TxInput> for TxInput {
|
|
67
|
-
fn from(input: ddk_ffi::TxInput) -> Self {
|
|
68
|
-
TxInput {
|
|
69
|
-
txid: input.txid,
|
|
70
|
-
vout: input.vout,
|
|
71
|
-
script_sig: Buffer::from(input.script_sig),
|
|
72
|
-
sequence: input.sequence,
|
|
73
|
-
witness: input.witness.into_iter().map(Buffer::from).collect(),
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// Convert NAPI TxOutput to ddk_ffi TxOutput
|
|
79
|
-
impl TryFrom<TxOutput> for ddk_ffi::TxOutput {
|
|
80
|
-
type Error = napi::Error;
|
|
81
|
-
|
|
82
|
-
fn try_from(output: TxOutput) -> Result<Self> {
|
|
83
|
-
Ok(ddk_ffi::TxOutput {
|
|
84
|
-
value: bigint_to_u64(&output.value)?,
|
|
85
|
-
script_pubkey: output.script_pubkey.to_vec(),
|
|
86
|
-
})
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// Convert ddk_ffi TxOutput to NAPI TxOutput
|
|
91
|
-
impl From<ddk_ffi::TxOutput> for TxOutput {
|
|
92
|
-
fn from(output: ddk_ffi::TxOutput) -> Self {
|
|
93
|
-
TxOutput {
|
|
94
|
-
value: BigInt::from(output.value),
|
|
95
|
-
script_pubkey: Buffer::from(output.script_pubkey),
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// Convert NAPI TxInputInfo to ddk_ffi TxInputInfo
|
|
101
|
-
impl TryFrom<TxInputInfo> for ddk_ffi::TxInputInfo {
|
|
102
|
-
type Error = napi::Error;
|
|
103
|
-
|
|
104
|
-
fn try_from(info: TxInputInfo) -> Result<Self> {
|
|
105
|
-
Ok(ddk_ffi::TxInputInfo {
|
|
106
|
-
txid: info.txid,
|
|
107
|
-
vout: info.vout,
|
|
108
|
-
script_sig: info.script_sig.to_vec(),
|
|
109
|
-
max_witness_length: info.max_witness_length,
|
|
110
|
-
serial_id: bigint_to_u64(&info.serial_id)?,
|
|
111
|
-
})
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// Convert ddk_ffi TxInputInfo to NAPI TxInputInfo
|
|
116
|
-
impl From<ddk_ffi::TxInputInfo> for TxInputInfo {
|
|
117
|
-
fn from(info: ddk_ffi::TxInputInfo) -> Self {
|
|
118
|
-
TxInputInfo {
|
|
119
|
-
txid: info.txid,
|
|
120
|
-
vout: info.vout,
|
|
121
|
-
script_sig: Buffer::from(info.script_sig),
|
|
122
|
-
max_witness_length: info.max_witness_length,
|
|
123
|
-
serial_id: BigInt::from(info.serial_id),
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// Convert NAPI DlcOutcome to ddk_ffi DlcOutcome
|
|
129
|
-
impl TryFrom<DlcOutcome> for ddk_ffi::DlcOutcome {
|
|
130
|
-
type Error = napi::Error;
|
|
131
|
-
|
|
132
|
-
fn try_from(outcome: DlcOutcome) -> Result<Self> {
|
|
133
|
-
Ok(ddk_ffi::DlcOutcome {
|
|
134
|
-
local_payout: bigint_to_u64(&outcome.local_payout)?,
|
|
135
|
-
remote_payout: bigint_to_u64(&outcome.remote_payout)?,
|
|
136
|
-
})
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
// Convert ddk_ffi DlcOutcome to NAPI DlcOutcome
|
|
141
|
-
impl From<ddk_ffi::DlcOutcome> for DlcOutcome {
|
|
142
|
-
fn from(outcome: ddk_ffi::DlcOutcome) -> Self {
|
|
143
|
-
DlcOutcome {
|
|
144
|
-
local_payout: BigInt::from(outcome.local_payout),
|
|
145
|
-
remote_payout: BigInt::from(outcome.remote_payout),
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// Convert NAPI DlcInputInfo to ddk_ffi DlcInputInfo
|
|
151
|
-
impl TryFrom<DlcInputInfo> for ddk_ffi::DlcInputInfo {
|
|
152
|
-
type Error = napi::Error;
|
|
153
|
-
|
|
154
|
-
fn try_from(info: DlcInputInfo) -> Result<Self> {
|
|
155
|
-
Ok(ddk_ffi::DlcInputInfo {
|
|
156
|
-
fund_tx: info.fund_tx.try_into()?,
|
|
157
|
-
fund_vout: info.fund_vout,
|
|
158
|
-
local_fund_pubkey: info.local_fund_pubkey.to_vec(),
|
|
159
|
-
remote_fund_pubkey: info.remote_fund_pubkey.to_vec(),
|
|
160
|
-
fund_amount: bigint_to_u64(&info.fund_amount)?,
|
|
161
|
-
max_witness_len: info.max_witness_len,
|
|
162
|
-
input_serial_id: bigint_to_u64(&info.input_serial_id)?,
|
|
163
|
-
contract_id: info.contract_id.to_vec(),
|
|
164
|
-
})
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
// Convert ddk_ffi DlcInputInfo to NAPI DlcInputInfo
|
|
169
|
-
impl From<ddk_ffi::DlcInputInfo> for DlcInputInfo {
|
|
170
|
-
fn from(info: ddk_ffi::DlcInputInfo) -> Self {
|
|
171
|
-
DlcInputInfo {
|
|
172
|
-
fund_tx: info.fund_tx.into(),
|
|
173
|
-
fund_vout: info.fund_vout,
|
|
174
|
-
local_fund_pubkey: Buffer::from(info.local_fund_pubkey),
|
|
175
|
-
remote_fund_pubkey: Buffer::from(info.remote_fund_pubkey),
|
|
176
|
-
fund_amount: BigInt::from(info.fund_amount),
|
|
177
|
-
max_witness_len: info.max_witness_len,
|
|
178
|
-
input_serial_id: BigInt::from(info.input_serial_id),
|
|
179
|
-
contract_id: Buffer::from(info.contract_id),
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
// Convert NAPI PartyParams to ddk_ffi PartyParams
|
|
185
|
-
impl TryFrom<PartyParams> for ddk_ffi::PartyParams {
|
|
186
|
-
type Error = napi::Error;
|
|
187
|
-
|
|
188
|
-
fn try_from(params: PartyParams) -> Result<Self> {
|
|
189
|
-
let inputs: Result<Vec<_>> = params.inputs.into_iter().map(TryInto::try_into).collect();
|
|
190
|
-
let dlc_inputs: Result<Vec<_>> = params
|
|
191
|
-
.dlc_inputs
|
|
192
|
-
.into_iter()
|
|
193
|
-
.map(TryInto::try_into)
|
|
194
|
-
.collect();
|
|
195
|
-
|
|
196
|
-
Ok(ddk_ffi::PartyParams {
|
|
197
|
-
fund_pubkey: params.fund_pubkey.to_vec(),
|
|
198
|
-
change_script_pubkey: params.change_script_pubkey.to_vec(),
|
|
199
|
-
change_serial_id: bigint_to_u64(¶ms.change_serial_id)?,
|
|
200
|
-
payout_script_pubkey: params.payout_script_pubkey.to_vec(),
|
|
201
|
-
payout_serial_id: bigint_to_u64(¶ms.payout_serial_id)?,
|
|
202
|
-
inputs: inputs?,
|
|
203
|
-
input_amount: bigint_to_u64(¶ms.input_amount)?,
|
|
204
|
-
collateral: bigint_to_u64(¶ms.collateral)?,
|
|
205
|
-
dlc_inputs: dlc_inputs?,
|
|
206
|
-
})
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
// Convert ddk_ffi PartyParams to NAPI PartyParams
|
|
211
|
-
impl From<ddk_ffi::PartyParams> for PartyParams {
|
|
212
|
-
fn from(params: ddk_ffi::PartyParams) -> Self {
|
|
213
|
-
PartyParams {
|
|
214
|
-
fund_pubkey: Buffer::from(params.fund_pubkey),
|
|
215
|
-
change_script_pubkey: Buffer::from(params.change_script_pubkey),
|
|
216
|
-
change_serial_id: BigInt::from(params.change_serial_id),
|
|
217
|
-
payout_script_pubkey: Buffer::from(params.payout_script_pubkey),
|
|
218
|
-
payout_serial_id: BigInt::from(params.payout_serial_id),
|
|
219
|
-
inputs: params.inputs.into_iter().map(Into::into).collect(),
|
|
220
|
-
input_amount: BigInt::from(params.input_amount),
|
|
221
|
-
collateral: BigInt::from(params.collateral),
|
|
222
|
-
dlc_inputs: params.dlc_inputs.into_iter().map(Into::into).collect(),
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
// Convert ddk_ffi DlcTransactions to NAPI DlcTransactions
|
|
228
|
-
impl From<ddk_ffi::DlcTransactions> for DlcTransactions {
|
|
229
|
-
fn from(txs: ddk_ffi::DlcTransactions) -> Self {
|
|
230
|
-
DlcTransactions {
|
|
231
|
-
fund: txs.fund.into(),
|
|
232
|
-
cets: txs.cets.into_iter().map(Into::into).collect(),
|
|
233
|
-
refund: txs.refund.into(),
|
|
234
|
-
funding_script_pubkey: Buffer::from(txs.funding_script_pubkey),
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
// Convert ddk_ffi ChangeOutputAndFees to NAPI ChangeOutputAndFees
|
|
240
|
-
impl From<ddk_ffi::ChangeOutputAndFees> for ChangeOutputAndFees {
|
|
241
|
-
fn from(fees: ddk_ffi::ChangeOutputAndFees) -> Self {
|
|
242
|
-
ChangeOutputAndFees {
|
|
243
|
-
change_output: fees.change_output.into(),
|
|
244
|
-
fund_fee: BigInt::from(fees.fund_fee),
|
|
245
|
-
cet_fee: BigInt::from(fees.cet_fee),
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
// Convert NAPI OracleInfo to ddk_ffi OracleInfo
|
|
251
|
-
impl From<OracleInfo> for ddk_ffi::OracleInfo {
|
|
252
|
-
fn from(info: OracleInfo) -> Self {
|
|
253
|
-
ddk_ffi::OracleInfo {
|
|
254
|
-
public_key: info.public_key.to_vec(),
|
|
255
|
-
nonces: info.nonces.into_iter().map(|n| n.to_vec()).collect(),
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
// Convert ddk_ffi AdaptorSignature to NAPI AdaptorSignature
|
|
261
|
-
impl From<ddk_ffi::AdaptorSignature> for AdaptorSignature {
|
|
262
|
-
fn from(sig: ddk_ffi::AdaptorSignature) -> Self {
|
|
263
|
-
AdaptorSignature {
|
|
264
|
-
signature: Buffer::from(sig.signature),
|
|
265
|
-
proof: Buffer::from(sig.proof),
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
}
|
package/src/lib.rs
DELETED
|
@@ -1,285 +0,0 @@
|
|
|
1
|
-
#![deny(clippy::all)]
|
|
2
|
-
|
|
3
|
-
pub mod conversions;
|
|
4
|
-
mod types;
|
|
5
|
-
|
|
6
|
-
use conversions::*;
|
|
7
|
-
use napi::bindgen_prelude::*;
|
|
8
|
-
use napi_derive::napi;
|
|
9
|
-
use types::*;
|
|
10
|
-
|
|
11
|
-
// Import ddk_ffi crate
|
|
12
|
-
extern crate ddk_ffi;
|
|
13
|
-
|
|
14
|
-
#[napi]
|
|
15
|
-
pub fn version() -> String {
|
|
16
|
-
ddk_ffi::version()
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
#[napi]
|
|
20
|
-
pub fn create_fund_tx_locking_script(
|
|
21
|
-
local_fund_pubkey: Buffer,
|
|
22
|
-
remote_fund_pubkey: Buffer,
|
|
23
|
-
) -> Result<Buffer> {
|
|
24
|
-
let local_pubkey = buffer_to_vec(&local_fund_pubkey);
|
|
25
|
-
let remote_pubkey = buffer_to_vec(&remote_fund_pubkey);
|
|
26
|
-
|
|
27
|
-
let result = ddk_ffi::create_fund_tx_locking_script(local_pubkey, remote_pubkey)
|
|
28
|
-
.map_err(|e| Error::from_reason(format!("{:?}", e)))?;
|
|
29
|
-
|
|
30
|
-
Ok(vec_to_buffer(result))
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
#[napi]
|
|
34
|
-
pub fn create_dlc_transactions(
|
|
35
|
-
outcomes: Vec<DlcOutcome>,
|
|
36
|
-
local_params: PartyParams,
|
|
37
|
-
remote_params: PartyParams,
|
|
38
|
-
refund_locktime: u32,
|
|
39
|
-
fee_rate: BigInt,
|
|
40
|
-
fund_lock_time: u32,
|
|
41
|
-
cet_lock_time: u32,
|
|
42
|
-
fund_output_serial_id: BigInt,
|
|
43
|
-
) -> Result<DlcTransactions> {
|
|
44
|
-
let ffi_outcomes: Result<Vec<ddk_ffi::DlcOutcome>> =
|
|
45
|
-
outcomes.into_iter().map(TryInto::try_into).collect();
|
|
46
|
-
|
|
47
|
-
let ffi_local_params = local_params.try_into()?;
|
|
48
|
-
let ffi_remote_params = remote_params.try_into()?;
|
|
49
|
-
|
|
50
|
-
let result = ddk_ffi::create_dlc_transactions(
|
|
51
|
-
ffi_outcomes?,
|
|
52
|
-
ffi_local_params,
|
|
53
|
-
ffi_remote_params,
|
|
54
|
-
refund_locktime,
|
|
55
|
-
bigint_to_u64(&fee_rate)?,
|
|
56
|
-
fund_lock_time,
|
|
57
|
-
cet_lock_time,
|
|
58
|
-
bigint_to_u64(&fund_output_serial_id)?,
|
|
59
|
-
)
|
|
60
|
-
.map_err(|e| Error::from_reason(format!("{:?}", e)))?;
|
|
61
|
-
|
|
62
|
-
Ok(result.into())
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
#[napi]
|
|
66
|
-
pub fn create_spliced_dlc_transactions(
|
|
67
|
-
outcomes: Vec<DlcOutcome>,
|
|
68
|
-
local_params: PartyParams,
|
|
69
|
-
remote_params: PartyParams,
|
|
70
|
-
refund_locktime: u32,
|
|
71
|
-
fee_rate: BigInt,
|
|
72
|
-
fund_lock_time: u32,
|
|
73
|
-
cet_lock_time: u32,
|
|
74
|
-
fund_output_serial_id: BigInt,
|
|
75
|
-
) -> Result<DlcTransactions> {
|
|
76
|
-
let ffi_outcomes: Result<Vec<ddk_ffi::DlcOutcome>> =
|
|
77
|
-
outcomes.into_iter().map(TryInto::try_into).collect();
|
|
78
|
-
|
|
79
|
-
let ffi_local_params = local_params.try_into()?;
|
|
80
|
-
let ffi_remote_params = remote_params.try_into()?;
|
|
81
|
-
|
|
82
|
-
let result = ddk_ffi::create_spliced_dlc_transactions(
|
|
83
|
-
ffi_outcomes?,
|
|
84
|
-
ffi_local_params,
|
|
85
|
-
ffi_remote_params,
|
|
86
|
-
refund_locktime,
|
|
87
|
-
bigint_to_u64(&fee_rate)?,
|
|
88
|
-
fund_lock_time,
|
|
89
|
-
cet_lock_time,
|
|
90
|
-
bigint_to_u64(&fund_output_serial_id)?,
|
|
91
|
-
)
|
|
92
|
-
.map_err(|e| Error::from_reason(format!("{:?}", e)))?;
|
|
93
|
-
|
|
94
|
-
Ok(result.into())
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
#[napi]
|
|
98
|
-
pub fn create_cet(
|
|
99
|
-
local_output: TxOutput,
|
|
100
|
-
local_payout_serial_id: BigInt,
|
|
101
|
-
remote_output: TxOutput,
|
|
102
|
-
remote_payout_serial_id: BigInt,
|
|
103
|
-
fund_tx_id: String,
|
|
104
|
-
fund_vout: u32,
|
|
105
|
-
lock_time: u32,
|
|
106
|
-
) -> Result<Transaction> {
|
|
107
|
-
let result = ddk_ffi::create_cet(
|
|
108
|
-
local_output.try_into()?,
|
|
109
|
-
bigint_to_u64(&local_payout_serial_id)?,
|
|
110
|
-
remote_output.try_into()?,
|
|
111
|
-
bigint_to_u64(&remote_payout_serial_id)?,
|
|
112
|
-
fund_tx_id,
|
|
113
|
-
fund_vout,
|
|
114
|
-
lock_time,
|
|
115
|
-
)
|
|
116
|
-
.map_err(|e| Error::from_reason(format!("{:?}", e)))?;
|
|
117
|
-
|
|
118
|
-
Ok(result.into())
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
#[napi]
|
|
122
|
-
pub fn create_cets(
|
|
123
|
-
fund_tx_id: String,
|
|
124
|
-
fund_vout: u32,
|
|
125
|
-
local_final_script_pubkey: Buffer,
|
|
126
|
-
remote_final_script_pubkey: Buffer,
|
|
127
|
-
outcomes: Vec<DlcOutcome>,
|
|
128
|
-
lock_time: u32,
|
|
129
|
-
local_serial_id: BigInt,
|
|
130
|
-
remote_serial_id: BigInt,
|
|
131
|
-
) -> Result<Vec<Transaction>> {
|
|
132
|
-
let ffi_outcomes: Result<Vec<ddk_ffi::DlcOutcome>> =
|
|
133
|
-
outcomes.into_iter().map(TryInto::try_into).collect();
|
|
134
|
-
|
|
135
|
-
let result = ddk_ffi::create_cets(
|
|
136
|
-
fund_tx_id,
|
|
137
|
-
fund_vout,
|
|
138
|
-
buffer_to_vec(&local_final_script_pubkey),
|
|
139
|
-
buffer_to_vec(&remote_final_script_pubkey),
|
|
140
|
-
ffi_outcomes?,
|
|
141
|
-
lock_time,
|
|
142
|
-
bigint_to_u64(&local_serial_id)?,
|
|
143
|
-
bigint_to_u64(&remote_serial_id)?,
|
|
144
|
-
)
|
|
145
|
-
.map_err(|e| Error::from_reason(format!("{:?}", e)))?;
|
|
146
|
-
|
|
147
|
-
Ok(result.into_iter().map(Into::into).collect())
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
#[napi]
|
|
151
|
-
pub fn create_refund_transaction(
|
|
152
|
-
local_final_script_pubkey: Buffer,
|
|
153
|
-
remote_final_script_pubkey: Buffer,
|
|
154
|
-
local_amount: BigInt,
|
|
155
|
-
remote_amount: BigInt,
|
|
156
|
-
lock_time: u32,
|
|
157
|
-
fund_tx_id: String,
|
|
158
|
-
fund_vout: u32,
|
|
159
|
-
) -> Result<Transaction> {
|
|
160
|
-
let result = ddk_ffi::create_refund_transaction(
|
|
161
|
-
buffer_to_vec(&local_final_script_pubkey),
|
|
162
|
-
buffer_to_vec(&remote_final_script_pubkey),
|
|
163
|
-
bigint_to_u64(&local_amount)?,
|
|
164
|
-
bigint_to_u64(&remote_amount)?,
|
|
165
|
-
lock_time,
|
|
166
|
-
fund_tx_id,
|
|
167
|
-
fund_vout,
|
|
168
|
-
)
|
|
169
|
-
.map_err(|e| Error::from_reason(format!("{:?}", e)))?;
|
|
170
|
-
|
|
171
|
-
Ok(result.into())
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
#[napi]
|
|
175
|
-
pub fn is_dust_output(output: TxOutput) -> Result<bool> {
|
|
176
|
-
eprintln!("is_dust_output called with value: {:?}", output.value);
|
|
177
|
-
let ffi_output = output.try_into()?;
|
|
178
|
-
Ok(ddk_ffi::is_dust_output(ffi_output))
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
#[napi]
|
|
182
|
-
pub fn get_change_output_and_fees(
|
|
183
|
-
params: PartyParams,
|
|
184
|
-
fee_rate: BigInt,
|
|
185
|
-
) -> Result<ChangeOutputAndFees> {
|
|
186
|
-
let result = ddk_ffi::get_change_output_and_fees(params.try_into()?, bigint_to_u64(&fee_rate)?)
|
|
187
|
-
.map_err(|e| Error::from_reason(format!("{:?}", e)))?;
|
|
188
|
-
|
|
189
|
-
Ok(result.into())
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
#[napi]
|
|
193
|
-
pub fn get_total_input_vsize(inputs: Vec<TxInputInfo>) -> Result<u32> {
|
|
194
|
-
let ffi_inputs: Result<Vec<ddk_ffi::TxInputInfo>> =
|
|
195
|
-
inputs.into_iter().map(TryInto::try_into).collect();
|
|
196
|
-
|
|
197
|
-
Ok(ddk_ffi::get_total_input_vsize(ffi_inputs?))
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
#[napi]
|
|
201
|
-
pub fn verify_fund_tx_signature(
|
|
202
|
-
fund_tx: Transaction,
|
|
203
|
-
signature: Buffer,
|
|
204
|
-
pubkey: Buffer,
|
|
205
|
-
txid: String,
|
|
206
|
-
vout: u32,
|
|
207
|
-
input_amount: BigInt,
|
|
208
|
-
) -> Result<bool> {
|
|
209
|
-
let result = ddk_ffi::verify_fund_tx_signature(
|
|
210
|
-
fund_tx.try_into()?,
|
|
211
|
-
buffer_to_vec(&signature),
|
|
212
|
-
buffer_to_vec(&pubkey),
|
|
213
|
-
txid,
|
|
214
|
-
vout,
|
|
215
|
-
bigint_to_u64(&input_amount)?,
|
|
216
|
-
)
|
|
217
|
-
.map_err(|e| Error::from_reason(format!("{:?}", e)))?;
|
|
218
|
-
|
|
219
|
-
Ok(result)
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
#[napi]
|
|
223
|
-
pub fn get_raw_funding_transaction_input_signature(
|
|
224
|
-
funding_transaction: Transaction,
|
|
225
|
-
privkey: Buffer,
|
|
226
|
-
prev_tx_id: String,
|
|
227
|
-
prev_tx_vout: u32,
|
|
228
|
-
value: BigInt,
|
|
229
|
-
) -> Result<Buffer> {
|
|
230
|
-
let result = ddk_ffi::get_raw_funding_transaction_input_signature(
|
|
231
|
-
funding_transaction.try_into()?,
|
|
232
|
-
buffer_to_vec(&privkey),
|
|
233
|
-
prev_tx_id,
|
|
234
|
-
prev_tx_vout,
|
|
235
|
-
bigint_to_u64(&value)?,
|
|
236
|
-
)
|
|
237
|
-
.map_err(|e| Error::from_reason(format!("{:?}", e)))?;
|
|
238
|
-
|
|
239
|
-
Ok(vec_to_buffer(result))
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
#[napi]
|
|
243
|
-
pub fn sign_fund_transaction_input(
|
|
244
|
-
fund_transaction: Transaction,
|
|
245
|
-
privkey: Buffer,
|
|
246
|
-
prev_tx_id: String,
|
|
247
|
-
prev_tx_vout: u32,
|
|
248
|
-
value: BigInt,
|
|
249
|
-
) -> Result<Transaction> {
|
|
250
|
-
let result = ddk_ffi::sign_fund_transaction_input(
|
|
251
|
-
fund_transaction.try_into()?,
|
|
252
|
-
buffer_to_vec(&privkey),
|
|
253
|
-
prev_tx_id,
|
|
254
|
-
prev_tx_vout,
|
|
255
|
-
bigint_to_u64(&value)?,
|
|
256
|
-
)
|
|
257
|
-
.map_err(|e| Error::from_reason(format!("{:?}", e)))?;
|
|
258
|
-
|
|
259
|
-
Ok(result.into())
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
#[napi]
|
|
263
|
-
pub fn create_cet_adaptor_signature_from_oracle_info(
|
|
264
|
-
cet: Transaction,
|
|
265
|
-
oracle_info: OracleInfo,
|
|
266
|
-
funding_sk: Buffer,
|
|
267
|
-
funding_script_pubkey: Buffer,
|
|
268
|
-
total_collateral: BigInt,
|
|
269
|
-
msgs: Vec<Buffer>,
|
|
270
|
-
) -> Result<AdaptorSignature> {
|
|
271
|
-
let ffi_oracle_info = oracle_info.into();
|
|
272
|
-
let ffi_msgs: Vec<Vec<u8>> = msgs.iter().map(buffer_to_vec).collect();
|
|
273
|
-
|
|
274
|
-
let result = ddk_ffi::create_cet_adaptor_signature_from_oracle_info(
|
|
275
|
-
cet.try_into()?,
|
|
276
|
-
ffi_oracle_info,
|
|
277
|
-
buffer_to_vec(&funding_sk),
|
|
278
|
-
buffer_to_vec(&funding_script_pubkey),
|
|
279
|
-
bigint_to_u64(&total_collateral)?,
|
|
280
|
-
ffi_msgs,
|
|
281
|
-
)
|
|
282
|
-
.map_err(|e| Error::from_reason(format!("{:?}", e)))?;
|
|
283
|
-
|
|
284
|
-
Ok(result.into())
|
|
285
|
-
}
|
package/src/types.rs
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
use napi::bindgen_prelude::*;
|
|
2
|
-
use napi_derive::napi;
|
|
3
|
-
|
|
4
|
-
// Transaction representation - matches UDL exactly
|
|
5
|
-
#[napi(object)]
|
|
6
|
-
pub struct Transaction {
|
|
7
|
-
pub version: i32,
|
|
8
|
-
pub lock_time: u32,
|
|
9
|
-
pub inputs: Vec<TxInput>,
|
|
10
|
-
pub outputs: Vec<TxOutput>,
|
|
11
|
-
pub raw_bytes: Buffer,
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
// Transaction input - matches UDL exactly
|
|
15
|
-
#[napi(object)]
|
|
16
|
-
pub struct TxInput {
|
|
17
|
-
pub txid: String,
|
|
18
|
-
pub vout: u32,
|
|
19
|
-
pub script_sig: Buffer,
|
|
20
|
-
pub sequence: u32,
|
|
21
|
-
pub witness: Vec<Buffer>,
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// Transaction output - matches UDL exactly
|
|
25
|
-
#[napi(object)]
|
|
26
|
-
pub struct TxOutput {
|
|
27
|
-
pub value: BigInt,
|
|
28
|
-
pub script_pubkey: Buffer,
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Input information for funding - matches UDL exactly
|
|
32
|
-
#[napi(object)]
|
|
33
|
-
pub struct TxInputInfo {
|
|
34
|
-
pub txid: String,
|
|
35
|
-
pub vout: u32,
|
|
36
|
-
pub script_sig: Buffer,
|
|
37
|
-
pub max_witness_length: u32,
|
|
38
|
-
pub serial_id: BigInt,
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// DLC outcome with payouts - matches UDL exactly
|
|
42
|
-
#[napi(object)]
|
|
43
|
-
pub struct DlcOutcome {
|
|
44
|
-
pub local_payout: BigInt,
|
|
45
|
-
pub remote_payout: BigInt,
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// Payout for offer and accept parties - matches UDL exactly
|
|
49
|
-
#[napi(object)]
|
|
50
|
-
pub struct Payout {
|
|
51
|
-
pub offer: BigInt,
|
|
52
|
-
pub accept: BigInt,
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// DLC input information - matches UDL exactly
|
|
56
|
-
#[napi(object)]
|
|
57
|
-
pub struct DlcInputInfo {
|
|
58
|
-
pub fund_tx: Transaction,
|
|
59
|
-
pub fund_vout: u32,
|
|
60
|
-
pub local_fund_pubkey: Buffer,
|
|
61
|
-
pub remote_fund_pubkey: Buffer,
|
|
62
|
-
pub fund_amount: BigInt,
|
|
63
|
-
pub max_witness_len: u32,
|
|
64
|
-
pub input_serial_id: BigInt,
|
|
65
|
-
pub contract_id: Buffer,
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// Parameters for a party in the DLC - matches UDL exactly
|
|
69
|
-
#[napi(object)]
|
|
70
|
-
pub struct PartyParams {
|
|
71
|
-
pub fund_pubkey: Buffer,
|
|
72
|
-
pub change_script_pubkey: Buffer,
|
|
73
|
-
pub change_serial_id: BigInt,
|
|
74
|
-
pub payout_script_pubkey: Buffer,
|
|
75
|
-
pub payout_serial_id: BigInt,
|
|
76
|
-
pub inputs: Vec<TxInputInfo>,
|
|
77
|
-
pub input_amount: BigInt,
|
|
78
|
-
pub collateral: BigInt,
|
|
79
|
-
pub dlc_inputs: Vec<DlcInputInfo>,
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// Container for all DLC transactions - matches UDL exactly
|
|
83
|
-
#[napi(object)]
|
|
84
|
-
pub struct DlcTransactions {
|
|
85
|
-
pub fund: Transaction,
|
|
86
|
-
pub cets: Vec<Transaction>,
|
|
87
|
-
pub refund: Transaction,
|
|
88
|
-
pub funding_script_pubkey: Buffer,
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// Adaptor signature with proof - matches UDL exactly
|
|
92
|
-
#[napi(object)]
|
|
93
|
-
pub struct AdaptorSignature {
|
|
94
|
-
pub signature: Buffer,
|
|
95
|
-
pub proof: Buffer,
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// Change output and fees result - matches UDL exactly
|
|
99
|
-
#[napi(object)]
|
|
100
|
-
pub struct ChangeOutputAndFees {
|
|
101
|
-
pub change_output: TxOutput,
|
|
102
|
-
pub fund_fee: BigInt,
|
|
103
|
-
pub cet_fee: BigInt,
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// Oracle information - matches UDL exactly
|
|
107
|
-
#[napi(object)]
|
|
108
|
-
pub struct OracleInfo {
|
|
109
|
-
pub public_key: Buffer,
|
|
110
|
-
pub nonces: Vec<Buffer>,
|
|
111
|
-
}
|