Skip to main content

tidecoin_node_parity/
ffi.rs

1// SPDX-License-Identifier: CC0-1.0
2
3use core::ffi::{c_char, c_int};
4
5unsafe extern "C" {
6    /// Verifies a single transaction input against the Tidecoin node interpreter.
7    pub fn tidecoin_node_verify_tx_input(
8        tx_hex: *const c_char,
9        input_index: usize,
10        prev_script: *const u8,
11        prev_script_len: usize,
12        amount: i64,
13        flags: u32,
14        script_error_out: *mut c_int,
15    ) -> c_int;
16
17    /// Runs Tidecoin node `CheckTransaction` on a serialized transaction.
18    pub fn tidecoin_node_check_transaction(tx_hex: *const c_char) -> c_int;
19
20    /// Runs Tidecoin node scrypt-1024-1-1-256 over a pure 80-byte header.
21    pub fn tidecoin_node_scrypt_pow_hash(
22        header: *const u8,
23        header_len: usize,
24        out: *mut u8,
25        out_len: usize,
26    ) -> c_int;
27
28    /// Runs Tidecoin node yespower over a pure 80-byte header.
29    pub fn tidecoin_node_yespower_pow_hash(
30        header: *const u8,
31        header_len: usize,
32        out: *mut u8,
33        out_len: usize,
34    ) -> c_int;
35
36    /// Runs Tidecoin node-equivalent header PoW validation, including AuxPoW context.
37    pub fn tidecoin_node_has_valid_header_pow(
38        header_hex: *const c_char,
39        network: c_int,
40        has_height: c_int,
41        height: c_int,
42    ) -> c_int;
43
44    /// Runs Tidecoin node-equivalent context-free block sanity validation.
45    pub fn tidecoin_node_check_block(
46        block_hex: *const c_char,
47        network: c_int,
48        check_pow: c_int,
49        check_merkle_root: c_int,
50    ) -> c_int;
51
52    /// Runs Tidecoin node-equivalent UTXO-independent contextual block validation.
53    pub fn tidecoin_node_check_contextual_block(
54        block_hex: *const c_char,
55        network: c_int,
56        height: c_int,
57        lock_time_cutoff: i64,
58        enforce_bip34_height: c_int,
59        expect_witness_commitment: c_int,
60    ) -> c_int;
61
62    /// Runs Tidecoin node-equivalent permitted difficulty transition checks.
63    pub fn tidecoin_node_permitted_difficulty_transition(
64        network: c_int,
65        height: i64,
66        old_nbits: u32,
67        new_nbits: u32,
68    ) -> c_int;
69
70    /// Returns the Tidecoin node block subsidy for a network and height.
71    pub fn tidecoin_node_block_subsidy(network: c_int, height: c_int) -> i64;
72
73    /// Runs Tidecoin node `pq::VSizeP2WPKHInput`.
74    pub fn tidecoin_node_pq_p2wpkh_input_vsize(sig_len: usize, pubkey_len: usize) -> i64;
75
76    /// Runs Tidecoin node `pq::VSizeP2SH_P2WPKHInput`.
77    pub fn tidecoin_node_pq_p2sh_p2wpkh_input_vsize(sig_len: usize, pubkey_len: usize) -> i64;
78
79    /// Deterministically generates a PQ keypair from a raw seed using the Tidecoin node.
80    pub fn tidecoin_node_pq_keygen_from_seed(
81        scheme_prefix: u8,
82        seed: *const u8,
83        seed_len: usize,
84        pk_out: *mut u8,
85        pk_len: usize,
86        sk_out: *mut u8,
87        sk_len: usize,
88    ) -> c_int;
89
90    /// Deterministically generates a PQHD keypair from a stream key using the Tidecoin node.
91    pub fn tidecoin_node_pqhd_keygen_from_stream_key(
92        scheme_prefix: u8,
93        stream_key: *const u8,
94        stream_key_len: usize,
95        pk_out: *mut u8,
96        pk_len: usize,
97        sk_out: *mut u8,
98        sk_len: usize,
99    ) -> c_int;
100
101    /// Computes a PQ public key from a secret key using the Tidecoin node.
102    pub fn tidecoin_node_pq_compute_public_key(
103        scheme_prefix: u8,
104        sk: *const u8,
105        sk_len: usize,
106        pk_out: *mut u8,
107        pk_len: usize,
108    ) -> c_int;
109
110    /// Signs a message using the Tidecoin node PQ API.
111    pub fn tidecoin_node_pq_sign_message(
112        scheme_prefix: u8,
113        msg: *const u8,
114        msg_len: usize,
115        sk: *const u8,
116        sk_len: usize,
117        legacy_mode: c_int,
118        sig_out: *mut u8,
119        sig_len: *mut usize,
120    ) -> c_int;
121
122    /// Verifies a message signature using the Tidecoin node PQ API.
123    pub fn tidecoin_node_pq_verify_message(
124        scheme_prefix: u8,
125        msg: *const u8,
126        msg_len: usize,
127        sig: *const u8,
128        sig_len: usize,
129        pk: *const u8,
130        pk_len: usize,
131        legacy_mode: c_int,
132    ) -> c_int;
133
134    /// Deterministically generates an ML-KEM-512 keypair using the Tidecoin node.
135    pub fn tidecoin_node_mlkem512_keypair_from_coins(
136        coins: *const u8,
137        coins_len: usize,
138        pk_out: *mut u8,
139        pk_len: usize,
140        sk_out: *mut u8,
141        sk_len: usize,
142    ) -> c_int;
143
144    /// Deterministically encapsulates an ML-KEM-512 shared secret using the Tidecoin node.
145    pub fn tidecoin_node_mlkem512_encaps_deterministic(
146        pk: *const u8,
147        pk_len: usize,
148        coins: *const u8,
149        coins_len: usize,
150        ct_out: *mut u8,
151        ct_len: usize,
152        ss_out: *mut u8,
153        ss_len: usize,
154    ) -> c_int;
155
156    /// Decapsulates an ML-KEM-512 ciphertext using the Tidecoin node.
157    pub fn tidecoin_node_mlkem512_decaps(
158        ct: *const u8,
159        ct_len: usize,
160        sk: *const u8,
161        sk_len: usize,
162        ss_out: *mut u8,
163        ss_len: usize,
164    ) -> c_int;
165
166    /// Parses script assembly text using Tidecoin node helpers.
167    pub fn tidecoin_node_parse_script_asm(
168        script_asm: *const c_char,
169        out: *mut u8,
170        out_len: *mut usize,
171    ) -> c_int;
172
173    /// Verifies an isolated script test case against the Tidecoin node interpreter.
174    pub fn tidecoin_node_verify_script_case(
175        script_sig: *const u8,
176        script_sig_len: usize,
177        script_pubkey: *const u8,
178        script_pubkey_len: usize,
179        witness_items: *const *const u8,
180        witness_lens: *const usize,
181        witness_count: usize,
182        amount: i64,
183        flags: u32,
184        script_error_out: *mut c_int,
185    ) -> c_int;
186}