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
use super::*;
#[wasm_bindgen(js_name = Signature)]
#[derive(Clone, Debug)]
pub struct JsMSignature {
inner: MSignature,
}
#[wasm_bindgen(js_class = Signature)]
impl JsMSignature {
#[wasm_bindgen(constructor)]
pub fn new(sign_str: &str) -> Result<JsMSignature, JsValue> {
let inner: MSignature = sign_str.parse().map_err_to_js()?;
Ok(Self { inner })
}
#[wasm_bindgen(js_name = fromSecp)]
pub fn from_secp(secp: &JsSecpSignature) -> Self {
let inner = MSignature::from(secp.inner().clone());
Self { inner }
}
#[wasm_bindgen]
pub fn prefix() -> String {
MSignature::PREFIX.to_string()
}
#[wasm_bindgen(js_name=toString)]
pub fn stringify(&self) -> String {
self.inner.to_string()
}
}
impl From<MSignature> for JsMSignature {
fn from(inner: MSignature) -> Self {
Self { inner }
}
}
impl Wraps<MSignature> for JsMSignature {
fn inner(&self) -> &MSignature {
&self.inner
}
}
#[wasm_bindgen(js_name = SecpSignature)]
#[derive(Clone, Debug)]
pub struct JsSecpSignature {
inner: SecpSignature,
}
#[wasm_bindgen(js_class = SecpSignature)]
impl JsSecpSignature {
#[wasm_bindgen(js_name = fromDer)]
pub fn from_der(bytes: &[u8]) -> Result<JsSecpSignature, JsValue> {
let inner = SecpSignature::from_der(bytes).map_err_to_js()?;
Ok(Self { inner })
}
#[wasm_bindgen(js_name = toDer)]
pub fn to_der(&self) -> Vec<u8> {
self.inner.to_der()
}
#[wasm_bindgen(js_name=toString)]
pub fn stringify(&self) -> String {
self.inner.to_string()
}
}
impl From<SecpSignature> for JsSecpSignature {
fn from(inner: SecpSignature) -> Self {
Self { inner }
}
}
impl Wraps<SecpSignature> for JsSecpSignature {
fn inner(&self) -> &SecpSignature {
&self.inner
}
}