@bennyblader/ddk-rn 0.2.4 → 0.2.5

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.
@@ -0,0 +1,31 @@
1
+ [package]
2
+ name = "ddk_ffi"
3
+ version = "0.2.4"
4
+ edition = "2021"
5
+ license = "MIT"
6
+ description = "rust-dlc language bindings"
7
+ repository = "https://github.com/bennyhodl/ddk-ffi"
8
+ homepage = "https://github.com/bennyhodl/ddk-ffi"
9
+ readme = "README.md"
10
+
11
+ [lib]
12
+ name = "ddk_ffi"
13
+ crate-type = ["cdylib", "staticlib", "rlib"]
14
+
15
+ [dependencies]
16
+ uniffi = { version = "0.29.4", features = ["cli"] }
17
+ # dlc = { path = "../../../ernest/dlcdevkit/dlc", features = ["use-serde"] }
18
+ dlc = { git = "https://github.com/bennyhodl/dlcdevkit.git", branch = "deterministic-contract-keys", features = ["use-serde"] }
19
+ bitcoin = "0.32.7"
20
+ thiserror = "2.0.12"
21
+ secp256k1-zkp = "0.11.0"
22
+
23
+ [build-dependencies]
24
+ uniffi = { version = "0.29.4", features = ["build"] }
25
+
26
+ [package.metadata.uniffi]
27
+ udl_file = "src/ddk_ffi.udl"
28
+
29
+ [[bin]]
30
+ name = "uniffi-bindgen"
31
+ path = "src/uniffi-bindgen.rs"
@@ -0,0 +1,3 @@
1
+ fn main() {
2
+ uniffi::generate_scaffolding("src/ddk_ffi.udl").unwrap();
3
+ }
@@ -0,0 +1,10 @@
1
+ [toolchain]
2
+ channel = "stable"
3
+ targets = [
4
+ "aarch64-apple-ios",
5
+ "aarch64-apple-ios-sim",
6
+ "aarch64-linux-android",
7
+ "armv7-linux-androideabi",
8
+ "i686-linux-android",
9
+ "x86_64-linux-android"
10
+ ]
@@ -0,0 +1,243 @@
1
+ // Creates a set of DLC transactions (fund, CETs, refund)
2
+ [Throws=DLCError]
3
+ DlcTransactions create_dlc_transactions(
4
+ PartyParams offer_params,
5
+ PartyParams accept_params,
6
+ sequence<Payout> payouts,
7
+ u32 refund_lock_time,
8
+ u64 fee_rate_per_vb,
9
+ u32 fund_lock_time,
10
+ u32 cet_lock_time,
11
+ u64 fund_output_serial_id
12
+ );
13
+
14
+ // Creates a single Contract Execution Transaction
15
+ [Throws=DLCError]
16
+ Transaction create_cet(
17
+ TxOutput local_output,
18
+ TxOutput remote_output,
19
+ string fund_tx_id,
20
+ u32 fund_vout,
21
+ u32 lock_time,
22
+ u64 local_serial_id,
23
+ u64 remote_serial_id
24
+ );
25
+
26
+ // Creates multiple CETs for different outcomes
27
+ [Throws=DLCError]
28
+ sequence<Transaction> create_cets(
29
+ string fund_tx_id,
30
+ u32 fund_vout,
31
+ sequence<u8> local_final_script_pubkey,
32
+ sequence<u8> remote_final_script_pubkey,
33
+ sequence<DlcOutcome> outcomes,
34
+ u32 lock_time,
35
+ u64 local_serial_id,
36
+ u64 remote_serial_id
37
+ );
38
+
39
+ // Creates the funding transaction locking script (2-of-2 multisig)
40
+ [Throws=DLCError]
41
+ sequence<u8> create_fund_tx_locking_script(
42
+ sequence<u8> local_fund_pubkey,
43
+ sequence<u8> remote_fund_pubkey
44
+ );
45
+
46
+ // Creates a funding transaction
47
+ [Throws=DLCError]
48
+ Transaction create_fund_transaction(
49
+ sequence<u8> local_fund_pubkey,
50
+ sequence<u8> remote_fund_pubkey,
51
+ u64 output_amount,
52
+ sequence<TxInputInfo> local_inputs,
53
+ TxOutput local_change_output,
54
+ sequence<TxInputInfo> remote_inputs,
55
+ TxOutput remote_change_output,
56
+ string? option_dest,
57
+ u64 option_premium,
58
+ u32 lock_time,
59
+ u64 local_serial_id,
60
+ u64 remote_serial_id,
61
+ u64 fund_output_serial_id
62
+ );
63
+
64
+ // Creates a refund transaction
65
+ [Throws=DLCError]
66
+ Transaction create_refund_transaction(
67
+ sequence<u8> local_final_script_pubkey,
68
+ sequence<u8> remote_final_script_pubkey,
69
+ u64 local_amount,
70
+ u64 remote_amount,
71
+ u32 lock_time,
72
+ string fund_tx_id,
73
+ u32 fund_vout
74
+ );
75
+
76
+ // Signs a funding transaction input
77
+ [Throws=DLCError]
78
+ void sign_fund_transaction_input(
79
+ Transaction fund_transaction,
80
+ sequence<u8> privkey,
81
+ string prev_tx_id,
82
+ u32 prev_tx_vout,
83
+ u64 value
84
+ );
85
+
86
+ // Adds a signature to a funding transaction
87
+ [Throws=DLCError]
88
+ void add_signature_to_fund_transaction(
89
+ Transaction fund_transaction,
90
+ sequence<u8> signature,
91
+ sequence<u8> pubkey,
92
+ string prev_tx_id,
93
+ u32 prev_tx_vout
94
+ );
95
+
96
+ // Verifies a funding transaction signature
97
+ [Throws=DLCError]
98
+ boolean verify_fund_tx_signature(
99
+ Transaction fund_tx,
100
+ sequence<u8> signature,
101
+ sequence<u8> pubkey,
102
+ string txid,
103
+ u32 vout,
104
+ u64 input_amount
105
+ );
106
+
107
+ // Creates a CET adaptor signature
108
+ [Throws=DLCError]
109
+ AdaptorSignature create_cet_adaptor_signature(
110
+ Transaction cet,
111
+ sequence<u8> oracle_pubkey,
112
+ sequence<sequence<u8>> oracle_r_values,
113
+ sequence<u8> funding_privkey,
114
+ sequence<u8> funding_script_pubkey,
115
+ u64 total_collateral,
116
+ sequence<sequence<u8>> messages
117
+ );
118
+
119
+ // Creates multiple CET adaptor signatures
120
+ [Throws=DLCError]
121
+ sequence<AdaptorSignature> create_cet_adaptor_signatures(
122
+ sequence<Transaction> cets,
123
+ sequence<u8> oracle_pubkey,
124
+ sequence<sequence<u8>> oracle_r_values,
125
+ sequence<u8> funding_privkey,
126
+ sequence<u8> funding_script_pubkey,
127
+ u64 total_collateral,
128
+ sequence<sequence<sequence<u8>>> messages
129
+ );
130
+
131
+ // Verifies a CET adaptor signature
132
+ [Throws=DLCError]
133
+ boolean verify_cet_adaptor_signature(
134
+ AdaptorSignature adaptor_sig,
135
+ Transaction cet,
136
+ sequence<u8> pubkey,
137
+ sequence<u8> oracle_pubkey,
138
+ sequence<sequence<u8>> oracle_r_values,
139
+ sequence<u8> funding_script_pubkey,
140
+ u64 total_collateral,
141
+ sequence<sequence<u8>> messages
142
+ );
143
+
144
+ // Verifies multiple CET adaptor signatures
145
+ [Throws=DLCError]
146
+ boolean verify_cet_adaptor_signatures(
147
+ sequence<Transaction> cets,
148
+ sequence<AdaptorSignature> adaptor_sigs,
149
+ sequence<sequence<sequence<u8>>> messages,
150
+ sequence<u8> pubkey,
151
+ sequence<u8> oracle_pubkey,
152
+ sequence<sequence<u8>> oracle_r_values,
153
+ sequence<u8> funding_script_pubkey,
154
+ u64 total_collateral
155
+ );
156
+
157
+ // Signs a CET with oracle signatures
158
+ [Throws=DLCError]
159
+ void sign_cet(
160
+ Transaction cet,
161
+ AdaptorSignature adaptor_sig,
162
+ sequence<sequence<u8>> oracle_signatures,
163
+ sequence<u8> funding_privkey,
164
+ sequence<u8> funding_script_pubkey,
165
+ string fund_tx_id,
166
+ u32 fund_vout,
167
+ u64 fund_amount
168
+ );
169
+
170
+ // Gets raw funding transaction input signature
171
+ [Throws=DLCError]
172
+ sequence<u8> get_raw_funding_transaction_input_signature(
173
+ Transaction funding_transaction,
174
+ sequence<u8> privkey,
175
+ string prev_tx_id,
176
+ u32 prev_tx_vout,
177
+ u64 value
178
+ );
179
+
180
+ // Adds signatures for multisig input
181
+ [Throws=DLCError]
182
+ void add_signatures_for_multisig_input(
183
+ Transaction transaction,
184
+ string prev_tx_id,
185
+ u32 prev_tx_vout,
186
+ sequence<u8> multisig_script,
187
+ sequence<sequence<u8>> signatures
188
+ );
189
+
190
+ // Adds signatures to refund transaction
191
+ [Throws=DLCError]
192
+ void add_signatures_to_refund_tx(
193
+ Transaction refund_tx,
194
+ sequence<u8> fund_lockscript,
195
+ sequence<sequence<u8>> signatures,
196
+ string fund_tx_id,
197
+ u32 fund_tx_vout
198
+ );
199
+
200
+ // Gets raw refund transaction signature
201
+ [Throws=DLCError]
202
+ sequence<u8> get_raw_refund_tx_signature(
203
+ Transaction refund_tx,
204
+ sequence<u8> privkey,
205
+ sequence<u8> fund_lockscript,
206
+ u64 input_amount,
207
+ string fund_tx_id,
208
+ u32 fund_tx_vout
209
+ );
210
+
211
+ // Verifies refund transaction signature
212
+ [Throws=DLCError]
213
+ boolean verify_refund_tx_signature(
214
+ Transaction refund_tx,
215
+ sequence<u8> signature,
216
+ sequence<u8> pubkey,
217
+ sequence<u8> lock_script,
218
+ u64 input_amount,
219
+ string fund_txid,
220
+ u32 fund_vout
221
+ );
222
+
223
+ // Utility: Calculate total input virtual size
224
+ u32 get_total_input_vsize(sequence<TxInput> inputs);
225
+
226
+ // Utility: Check if output is dust
227
+ boolean is_dust_output(TxOutput output);
228
+
229
+ // Utility: Get change output and fees for a party
230
+ [Throws=DLCError]
231
+ ChangeOutputAndFees get_change_output_and_fees(
232
+ PartyParams params,
233
+ u64 fee_rate,
234
+ u64? extra_fee
235
+ );
236
+
237
+ // Compute adaptor point from messages and oracle info
238
+ [Throws=DLCError]
239
+ sequence<u8> compute_adaptor_point(
240
+ sequence<sequence<u8>> messages,
241
+ sequence<sequence<u8>> r_values,
242
+ sequence<u8> oracle_pubkey
243
+ );
@@ -0,0 +1,230 @@
1
+ namespace ddk_ffi {
2
+ string version();
3
+ string plz_work();
4
+
5
+ // DLC Transaction Creation Functions
6
+ [Throws=DLCError]
7
+ sequence<u8> create_fund_tx_locking_script(
8
+ sequence<u8> local_fund_pubkey,
9
+ sequence<u8> remote_fund_pubkey
10
+ );
11
+
12
+ [Throws=DLCError]
13
+ DlcTransactions create_dlc_transactions(
14
+ sequence<DlcOutcome> outcomes,
15
+ PartyParams local_params,
16
+ PartyParams remote_params,
17
+ u32 refund_locktime,
18
+ u64 fee_rate,
19
+ u32 fund_lock_time,
20
+ u32 cet_lock_time,
21
+ u64 fund_output_serial_id
22
+ );
23
+
24
+ [Throws=DLCError]
25
+ DlcTransactions create_spliced_dlc_transactions(
26
+ sequence<DlcOutcome> outcomes,
27
+ PartyParams local_params,
28
+ PartyParams remote_params,
29
+ u32 refund_locktime,
30
+ u64 fee_rate,
31
+ u32 fund_lock_time,
32
+ u32 cet_lock_time,
33
+ u64 fund_output_serial_id
34
+ );
35
+
36
+ [Throws=DLCError]
37
+ Transaction create_cet(
38
+ TxOutput local_output,
39
+ u64 local_payout_serial_id,
40
+ TxOutput remote_output,
41
+ u64 remote_payout_serial_id,
42
+ string fund_tx_id,
43
+ u32 fund_vout,
44
+ u32 lock_time
45
+ );
46
+
47
+ [Throws=DLCError]
48
+ sequence<Transaction> create_cets(
49
+ string fund_tx_id,
50
+ u32 fund_vout,
51
+ sequence<u8> local_final_script_pubkey,
52
+ sequence<u8> remote_final_script_pubkey,
53
+ sequence<DlcOutcome> outcomes,
54
+ u32 lock_time,
55
+ u64 local_serial_id,
56
+ u64 remote_serial_id
57
+ );
58
+
59
+ [Throws=DLCError]
60
+ Transaction create_refund_transaction(
61
+ sequence<u8> local_final_script_pubkey,
62
+ sequence<u8> remote_final_script_pubkey,
63
+ u64 local_amount,
64
+ u64 remote_amount,
65
+ u32 lock_time,
66
+ string fund_tx_id,
67
+ u32 fund_vout
68
+ );
69
+
70
+ // Utility Functions
71
+ boolean is_dust_output(TxOutput output);
72
+
73
+ [Throws=DLCError]
74
+ ChangeOutputAndFees get_change_output_and_fees(
75
+ PartyParams params,
76
+ u64 fee_rate
77
+ );
78
+
79
+ u32 get_total_input_vsize(sequence<TxInputInfo> inputs);
80
+
81
+ [Throws=DLCError]
82
+ boolean verify_fund_tx_signature(
83
+ Transaction fund_tx,
84
+ sequence<u8> signature,
85
+ sequence<u8> pubkey,
86
+ string txid,
87
+ u32 vout,
88
+ u64 input_amount
89
+ );
90
+
91
+ // Signing Functions
92
+ [Throws=DLCError]
93
+ sequence<u8> get_raw_funding_transaction_input_signature(
94
+ Transaction funding_transaction,
95
+ sequence<u8> privkey,
96
+ string prev_tx_id,
97
+ u32 prev_tx_vout,
98
+ u64 value
99
+ );
100
+
101
+ [Throws=DLCError]
102
+ Transaction sign_fund_transaction_input(
103
+ Transaction fund_transaction,
104
+ sequence<u8> privkey,
105
+ string prev_tx_id,
106
+ u32 prev_tx_vout,
107
+ u64 value
108
+ );
109
+
110
+ // Adaptor Signature Functions
111
+ [Throws=DLCError]
112
+ AdaptorSignature create_cet_adaptor_signature_from_oracle_info(
113
+ Transaction cet,
114
+ OracleInfo oracle_info,
115
+ sequence<u8> funding_sk,
116
+ sequence<u8> funding_script_pubkey,
117
+ u64 total_collateral,
118
+ sequence<sequence<u8>> msgs
119
+ );
120
+ };
121
+
122
+ // Transaction representation
123
+ dictionary Transaction {
124
+ i32 version;
125
+ u32 lock_time;
126
+ sequence<TxInput> inputs;
127
+ sequence<TxOutput> outputs;
128
+ sequence<u8> raw_bytes;
129
+ };
130
+
131
+ // Transaction input
132
+ dictionary TxInput {
133
+ string txid;
134
+ u32 vout;
135
+ sequence<u8> script_sig;
136
+ u32 sequence;
137
+ sequence<sequence<u8>> witness;
138
+ };
139
+
140
+ // Transaction output
141
+ dictionary TxOutput {
142
+ u64 value;
143
+ sequence<u8> script_pubkey;
144
+ };
145
+
146
+ // Input information for funding
147
+ dictionary TxInputInfo {
148
+ string txid;
149
+ u32 vout;
150
+ sequence<u8> script_sig;
151
+ u32 max_witness_length;
152
+ u64 serial_id;
153
+ };
154
+
155
+ // DLC outcome with payouts
156
+ dictionary DlcOutcome {
157
+ u64 local_payout;
158
+ u64 remote_payout;
159
+ };
160
+
161
+ // Payout for offer and accept parties
162
+ dictionary Payout {
163
+ u64 offer;
164
+ u64 accept;
165
+ };
166
+
167
+ // Parameters for a party in the DLC
168
+ dictionary PartyParams {
169
+ sequence<u8> fund_pubkey;
170
+ sequence<u8> change_script_pubkey;
171
+ u64 change_serial_id;
172
+ sequence<u8> payout_script_pubkey;
173
+ u64 payout_serial_id;
174
+ sequence<TxInputInfo> inputs;
175
+ u64 input_amount;
176
+ u64 collateral;
177
+ sequence<DlcInputInfo> dlc_inputs;
178
+ };
179
+
180
+ dictionary DlcInputInfo {
181
+ Transaction fund_tx;
182
+ u32 fund_vout;
183
+ sequence<u8> local_fund_pubkey;
184
+ sequence<u8> remote_fund_pubkey;
185
+ u64 fund_amount;
186
+ u32 max_witness_len;
187
+ u64 input_serial_id;
188
+ sequence<u8> contract_id;
189
+ };
190
+
191
+ // Container for all DLC transactions
192
+ dictionary DlcTransactions {
193
+ Transaction fund;
194
+ sequence<Transaction> cets;
195
+ Transaction refund;
196
+ sequence<u8> funding_script_pubkey;
197
+ };
198
+
199
+ // Adaptor signature with proof
200
+ dictionary AdaptorSignature {
201
+ sequence<u8> signature;
202
+ sequence<u8> proof;
203
+ };
204
+
205
+ // Change output and fees result
206
+ dictionary ChangeOutputAndFees {
207
+ TxOutput change_output;
208
+ u64 fund_fee;
209
+ u64 cet_fee;
210
+ };
211
+
212
+ // Oracle information
213
+ dictionary OracleInfo {
214
+ sequence<u8> public_key;
215
+ sequence<sequence<u8>> nonces;
216
+ };
217
+
218
+ // Error types for DLC operations
219
+ [Error]
220
+ enum DLCError {
221
+ "InvalidSignature",
222
+ "InvalidPublicKey",
223
+ "InvalidTransaction",
224
+ "InsufficientFunds",
225
+ "InvalidArgument",
226
+ "SerializationError",
227
+ "Secp256k1Error",
228
+ "MiniscriptError",
229
+ "NetworkError",
230
+ };