Skip to main content

keymaster_multisig/
types.rs

1use serde::{Deserialize, Serialize};
2use wasm_bindgen::prelude::*;
3
4#[wasm_bindgen]
5#[derive(Serialize, Deserialize, Clone, Debug)]
6pub struct PublicKey {
7    #[wasm_bindgen(skip)]
8    pub key: Vec<u8>,
9}
10
11#[wasm_bindgen]
12impl PublicKey {
13    #[wasm_bindgen(constructor)]
14    pub fn new(key: Vec<u8>) -> PublicKey {
15        PublicKey { key }
16    }
17
18    pub fn to_bytes(&self) -> Vec<u8> {
19        self.key.clone()
20    }
21}
22
23#[wasm_bindgen]
24#[derive(Serialize, Deserialize, Clone, Debug)]
25pub struct PrivateKey {
26    #[wasm_bindgen(skip)]
27    pub key: Vec<u8>,
28}
29
30#[wasm_bindgen]
31impl PrivateKey {
32    #[wasm_bindgen(constructor)]
33    pub fn new(key: Vec<u8>) -> PrivateKey {
34        PrivateKey { key }
35    }
36
37    pub fn to_bytes(&self) -> Vec<u8> {
38        self.key.clone()
39    }
40}
41
42#[wasm_bindgen]
43#[derive(Serialize, Deserialize, Debug)]
44pub struct TransactionInput {
45    #[wasm_bindgen(skip)]
46    pub source_txid: String,
47    pub source_output_index: u32,
48    pub sequence: u32,
49}
50
51#[wasm_bindgen]
52impl TransactionInput {
53    #[wasm_bindgen(constructor)]
54    pub fn new(source_txid: String, source_output_index: u32, sequence: u32) -> TransactionInput {
55        TransactionInput {
56            source_txid,
57            source_output_index,
58            sequence,
59        }
60    }
61}
62
63#[wasm_bindgen]
64#[derive(Serialize, Deserialize, Debug)]
65pub struct TransactionOutput {
66    pub satoshis: u64,
67    #[wasm_bindgen(skip)]
68    pub locking_script: Vec<u8>,
69}
70
71#[wasm_bindgen]
72impl TransactionOutput {
73    #[wasm_bindgen(constructor)]
74    pub fn new(satoshis: u64, locking_script: Vec<u8>) -> TransactionOutput {
75        TransactionOutput {
76            satoshis,
77            locking_script,
78        }
79    }
80}
81
82#[wasm_bindgen]
83#[derive(Serialize, Deserialize, Debug)]
84pub struct Transaction {
85    pub version: u32,
86    #[wasm_bindgen(skip)]
87    pub inputs: Vec<TransactionInput>,
88    #[wasm_bindgen(skip)]
89    pub outputs: Vec<TransactionOutput>,
90    pub lock_time: u32,
91}
92
93#[wasm_bindgen]
94impl Transaction {
95    #[wasm_bindgen(constructor)]
96    pub fn new(
97        version: u32,
98        inputs: Vec<TransactionInput>,
99        outputs: Vec<TransactionOutput>,
100        lock_time: u32,
101    ) -> Transaction {
102        Transaction {
103            version,
104            inputs,
105            outputs,
106            lock_time,
107        }
108    }
109}
110
111#[derive(Serialize, Deserialize, Debug)]
112pub struct MultisigConfig {
113    pub public_keys: Vec<PublicKey>,
114    pub m: usize,
115    pub sig_hash_type: u8,
116}
117
118#[derive(Serialize, Deserialize, Debug)]
119pub struct Signature {
120    pub r: Vec<u8>,
121    pub s: Vec<u8>,
122    pub sighash_type: u8,
123}