1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
// Copyright (C) 2019-2023 Aleo Systems Inc.
// This file is part of the Aleo SDK library.

// The Aleo SDK library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// The Aleo SDK library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with the Aleo SDK library. If not, see <https://www.gnu.org/licenses/>.

use super::*;

#[wasm_bindgen]
impl VerifyingKey {
    /// Returns the verifying key for the bond_public function
    ///
    /// @returns {VerifyingKey} Verifying key for the bond_public function
    #[wasm_bindgen(js_name = "bondPublicVerifier")]
    pub fn bond_public_verifier() -> VerifyingKey {
        VerifyingKey::from_bytes(&snarkvm_parameters::testnet3::BondPublicVerifier::load_bytes().unwrap()).unwrap()
    }

    /// Returns the verifying key for the claim_delegator function
    ///
    /// @returns {VerifyingKey} Verifying key for the claim_unbond_public function
    #[wasm_bindgen(js_name = "claimUnbondPublicVerifier")]
    pub fn claim_unbond_public_verifier() -> VerifyingKey {
        VerifyingKey::from_bytes(&snarkvm_parameters::testnet3::ClaimUnbondPublicVerifier::load_bytes().unwrap())
            .unwrap()
    }

    /// Returns the verifying key for the fee_private function
    ///
    /// @returns {VerifyingKey} Verifying key for the fee_private function
    #[wasm_bindgen(js_name = "feePrivateVerifier")]
    pub fn fee_private_verifier() -> VerifyingKey {
        VerifyingKey::from_bytes(&snarkvm_parameters::testnet3::FeePrivateVerifier::load_bytes().unwrap()).unwrap()
    }

    /// Returns the verifying key for the fee_public function
    ///
    /// @returns {VerifyingKey} Verifying key for the fee_public function
    #[wasm_bindgen(js_name = "feePublicVerifier")]
    pub fn fee_public_verifier() -> VerifyingKey {
        VerifyingKey::from_bytes(&snarkvm_parameters::testnet3::FeePublicVerifier::load_bytes().unwrap()).unwrap()
    }

    /// Returns the verifying key for the inclusion function
    ///
    /// @returns {VerifyingKey} Verifying key for the inclusion function
    #[wasm_bindgen(js_name = "inclusionVerifier")]
    pub fn inclusion_verifier() -> VerifyingKey {
        VerifyingKey::from_bytes(&snarkvm_parameters::testnet3::InclusionVerifier::load_bytes().unwrap()).unwrap()
    }

    /// Returns the verifying key for the join function
    ///
    /// @returns {VerifyingKey} Verifying key for the join function
    #[wasm_bindgen(js_name = "joinVerifier")]
    pub fn join_verifier() -> VerifyingKey {
        VerifyingKey::from_bytes(&snarkvm_parameters::testnet3::JoinVerifier::load_bytes().unwrap()).unwrap()
    }

    /// Returns the verifying key for the set_validator_state function
    ///
    /// @returns {VerifyingKey} Verifying key for the set_validator_state function
    #[wasm_bindgen(js_name = "setValidatorStateVerifier")]
    pub fn set_validator_state_verifier() -> VerifyingKey {
        VerifyingKey::from_bytes(&snarkvm_parameters::testnet3::SetValidatorStateVerifier::load_bytes().unwrap())
            .unwrap()
    }

    /// Returns the verifying key for the split function
    ///
    /// @returns {VerifyingKey} Verifying key for the split function
    #[wasm_bindgen(js_name = "splitVerifier")]
    pub fn split_verifier() -> VerifyingKey {
        VerifyingKey::from_bytes(&snarkvm_parameters::testnet3::SplitVerifier::load_bytes().unwrap()).unwrap()
    }

    /// Returns the verifying key for the transfer_private function
    ///
    /// @returns {VerifyingKey} Verifying key for the transfer_private function
    #[wasm_bindgen(js_name = "transferPrivateVerifier")]
    pub fn transfer_private_verifier() -> VerifyingKey {
        VerifyingKey::from_bytes(&snarkvm_parameters::testnet3::TransferPrivateVerifier::load_bytes().unwrap()).unwrap()
    }

    /// Returns the verifying key for the transfer_private_to_public function
    ///
    /// @returns {VerifyingKey} Verifying key for the transfer_private_to_public function
    #[wasm_bindgen(js_name = "transferPrivateToPublicVerifier")]
    pub fn transfer_private_to_public_verifier() -> VerifyingKey {
        VerifyingKey::from_bytes(&snarkvm_parameters::testnet3::TransferPrivateToPublicVerifier::load_bytes().unwrap())
            .unwrap()
    }

    /// Returns the verifying key for the transfer_public function
    ///
    /// @returns {VerifyingKey} Verifying key for the transfer_public function
    #[wasm_bindgen(js_name = "transferPublicVerifier")]
    pub fn transfer_public_verifier() -> VerifyingKey {
        VerifyingKey::from_bytes(&snarkvm_parameters::testnet3::TransferPublicVerifier::load_bytes().unwrap()).unwrap()
    }

    /// Returns the verifying key for the transfer_public_to_private function
    ///
    /// @returns {VerifyingKey} Verifying key for the transfer_public_to_private function
    #[wasm_bindgen(js_name = "transferPublicToPrivateVerifier")]
    pub fn transfer_public_to_private_verifier() -> VerifyingKey {
        VerifyingKey::from_bytes(&snarkvm_parameters::testnet3::TransferPublicToPrivateVerifier::load_bytes().unwrap())
            .unwrap()
    }

    /// Returns the verifying key for the unbond_delegator_as_delegator function
    ///
    /// @returns {VerifyingKey} Verifying key for the unbond_delegator_as_delegator function
    #[wasm_bindgen(js_name = "unbondDelegatorAsValidatorVerifier")]
    pub fn unbond_delegator_as_validator_verifier() -> VerifyingKey {
        VerifyingKey::from_bytes(
            &snarkvm_parameters::testnet3::UnbondDelegatorAsValidatorVerifier::load_bytes().unwrap(),
        )
        .unwrap()
    }

    /// Returns the verifying key for the unbond_delegator_as_delegator function
    ///
    /// @returns {VerifyingKey} Verifying key for the unbond_delegator_as_delegator function
    #[wasm_bindgen(js_name = "unbondPublicVerifier")]
    pub fn unbond_public_verifier() -> VerifyingKey {
        VerifyingKey::from_bytes(&snarkvm_parameters::testnet3::UnbondPublicVerifier::load_bytes().unwrap()).unwrap()
    }

    /// Returns the verifying key for the bond_public function
    ///
    /// @returns {VerifyingKey} Verifying key for the bond_public function
    #[wasm_bindgen(js_name = "isBondPublicVerifier")]
    pub fn is_bond_public_verifier(&self) -> bool {
        self == &VerifyingKey::from_bytes(&snarkvm_parameters::testnet3::BondPublicVerifier::load_bytes().unwrap())
            .unwrap()
    }

    /// Verifies the verifying key is for the claim_delegator function
    ///
    /// @returns {bool}
    #[wasm_bindgen(js_name = "isClaimUnbondPublicVerifier")]
    pub fn is_claim_unbond_public_verifier(&self) -> bool {
        self == &VerifyingKey::from_bytes(
            &snarkvm_parameters::testnet3::ClaimUnbondPublicVerifier::load_bytes().unwrap(),
        )
        .unwrap()
    }

    /// Verifies the verifying key is for the fee_private function
    ///
    /// @returns {bool}
    #[wasm_bindgen(js_name = "isFeePrivateVerifier")]
    pub fn is_fee_private_verifier(&self) -> bool {
        self == &VerifyingKey::from_bytes(&snarkvm_parameters::testnet3::FeePrivateVerifier::load_bytes().unwrap())
            .unwrap()
    }

    /// Verifies the verifying key is for the fee_public function
    ///
    /// @returns {bool}
    #[wasm_bindgen(js_name = "isFeePublicVerifier")]
    pub fn is_fee_public_verifier(&self) -> bool {
        self == &VerifyingKey::from_bytes(&snarkvm_parameters::testnet3::FeePublicVerifier::load_bytes().unwrap())
            .unwrap()
    }

    /// Verifies the verifying key is for the inclusion function
    ///
    /// @returns {bool}
    #[wasm_bindgen(js_name = "isInclusionVerifier")]
    pub fn is_inclusion_verifier(&self) -> bool {
        self == &VerifyingKey::from_bytes(&snarkvm_parameters::testnet3::InclusionVerifier::load_bytes().unwrap())
            .unwrap()
    }

    /// Verifies the verifying key is for the join function
    ///
    /// @returns {bool}
    #[wasm_bindgen(js_name = "isJoinVerifier")]
    pub fn is_join_verifier(&self) -> bool {
        self == &VerifyingKey::from_bytes(&snarkvm_parameters::testnet3::JoinVerifier::load_bytes().unwrap()).unwrap()
    }

    /// Verifies the verifying key is for the set_validator_state function
    ///
    /// @returns {bool}
    #[wasm_bindgen(js_name = "isSetValidatorStateVerifier")]
    pub fn is_set_validator_state_verifier(&self) -> bool {
        self == &VerifyingKey::from_bytes(
            &snarkvm_parameters::testnet3::SetValidatorStateVerifier::load_bytes().unwrap(),
        )
        .unwrap()
    }

    /// Verifies the verifying key is for the split function
    ///
    /// @returns {bool}
    #[wasm_bindgen(js_name = "isSplitVerifier")]
    pub fn is_split_verifier(&self) -> bool {
        self == &VerifyingKey::from_bytes(&snarkvm_parameters::testnet3::SplitVerifier::load_bytes().unwrap()).unwrap()
    }

    /// Verifies the verifying key is for the transfer_private function
    ///
    /// @returns {bool}
    #[wasm_bindgen(js_name = "isTransferPrivateVerifier")]
    pub fn is_transfer_private_verifier(&self) -> bool {
        self == &VerifyingKey::from_bytes(&snarkvm_parameters::testnet3::TransferPrivateVerifier::load_bytes().unwrap())
            .unwrap()
    }

    /// Verifies the verifying key is for the transfer_private_to_public function
    ///
    /// @returns {bool}
    #[wasm_bindgen(js_name = "isTransferPrivateToPublicVerifier")]
    pub fn is_transfer_private_to_public_verifier(&self) -> bool {
        self == &VerifyingKey::from_bytes(
            &snarkvm_parameters::testnet3::TransferPrivateToPublicVerifier::load_bytes().unwrap(),
        )
        .unwrap()
    }

    /// Verifies the verifying key is for the transfer_public function
    ///
    /// @returns {bool}
    #[wasm_bindgen(js_name = "isTransferPublicVerifier")]
    pub fn is_transfer_public_verifier(&self) -> bool {
        self == &VerifyingKey::from_bytes(&snarkvm_parameters::testnet3::TransferPublicVerifier::load_bytes().unwrap())
            .unwrap()
    }

    /// Verifies the verifying key is for the transfer_public_to_private function
    ///
    /// @returns {bool}
    #[wasm_bindgen(js_name = "isTransferPublicToPrivateVerifier")]
    pub fn is_transfer_public_to_private_verifier(&self) -> bool {
        self == &VerifyingKey::from_bytes(
            &snarkvm_parameters::testnet3::TransferPublicToPrivateVerifier::load_bytes().unwrap(),
        )
        .unwrap()
    }

    /// Verifies the verifying key is for the unbond_delegator_as_delegator function
    ///
    /// @returns {bool}
    #[wasm_bindgen(js_name = "isUnbondDelegatorAsValidatorVerifier")]
    pub fn is_unbond_delegator_as_validator_verifier(&self) -> bool {
        self == &VerifyingKey::from_bytes(
            &snarkvm_parameters::testnet3::UnbondDelegatorAsValidatorVerifier::load_bytes().unwrap(),
        )
        .unwrap()
    }

    /// Verifies the verifying key is for the unbond_public function
    ///
    /// @returns {bool}
    #[wasm_bindgen(js_name = "isUnbondPublicVerifier")]
    pub fn is_unbond_public_verifier(&self) -> bool {
        self == &VerifyingKey::from_bytes(&snarkvm_parameters::testnet3::UnbondPublicVerifier::load_bytes().unwrap())
            .unwrap()
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use wasm_bindgen_test::*;

    #[wasm_bindgen_test]
    fn test_key_loading() {
        let bond_public = VerifyingKey::bond_public_verifier();
        assert!(bond_public.is_bond_public_verifier());
        let claim_unbond_public = VerifyingKey::claim_unbond_public_verifier();
        assert!(claim_unbond_public.is_claim_unbond_public_verifier());
        let fee_private = VerifyingKey::fee_private_verifier();
        assert!(fee_private.is_fee_private_verifier());
        let fee_public = VerifyingKey::fee_public_verifier();
        assert!(fee_public.is_fee_public_verifier());
        let inclusion = VerifyingKey::inclusion_verifier();
        assert!(inclusion.is_inclusion_verifier());
        let join = VerifyingKey::join_verifier();
        assert!(join.is_join_verifier());
        let set_validator_state = VerifyingKey::set_validator_state_verifier();
        assert!(set_validator_state.is_set_validator_state_verifier());
        let split = VerifyingKey::split_verifier();
        assert!(split.is_split_verifier());
        let transfer_private = VerifyingKey::transfer_private_verifier();
        assert!(transfer_private.is_transfer_private_verifier());
        let transfer_private_to_public = VerifyingKey::transfer_private_to_public_verifier();
        assert!(transfer_private_to_public.is_transfer_private_to_public_verifier());
        let transfer_public = VerifyingKey::transfer_public_verifier();
        assert!(transfer_public.is_transfer_public_verifier());
        let transfer_public_to_private = VerifyingKey::transfer_public_to_private_verifier();
        assert!(transfer_public_to_private.is_transfer_public_to_private_verifier());
        let unbond_delegator_as_validator = VerifyingKey::unbond_delegator_as_validator_verifier();
        assert!(unbond_delegator_as_validator.is_unbond_delegator_as_validator_verifier());
        let unbond_public = VerifyingKey::unbond_public_verifier();
        assert!(unbond_public.is_unbond_public_verifier());
    }
}