1use wasm_bindgen::prelude::*;
2
3#[wasm_bindgen(js_namespace = ["window", "keplr"])]
4extern "C" {
5 #[wasm_bindgen(thread_local, js_namespace = window, js_name = keplr)]
6 pub static KEPLR: JsValue;
7
8 #[wasm_bindgen(js_name = ping, catch)]
9 pub async fn ping() -> Result<(), JsValue>;
10
11 #[wasm_bindgen(js_name = enable, catch)]
12 pub async fn enable(chain_ids: Vec<String>) -> Result<(), JsValue>;
13
14 #[wasm_bindgen(js_name = disable)]
15 pub fn disable(chain_id: &str);
16
17 #[wasm_bindgen(js_name = disableOrigin)]
18 pub fn disable_origin();
19
20 #[wasm_bindgen(js_name = experimentalSuggestChain, catch)]
21 pub async fn suggest_chain(chainInfo: JsValue) -> Result<(), JsValue>;
22
23 #[wasm_bindgen(js_name = getChainInfoWithoutEndpoints)]
24 pub async fn get_chain_info(chain_id: &str) -> JsValue;
25
26 #[wasm_bindgen(js_name = getKey, catch)]
27 pub async fn get_key(chain_id: &str) -> Result<JsValue, JsValue>;
28
29 #[wasm_bindgen(js_name = getKeysSettled, catch)]
30 pub async fn get_keys_settled(chain_ids: Vec<String>) -> Result<JsValue, JsValue>;
31
32 #[wasm_bindgen(js_name = getOfflineSigner)]
33 pub fn get_offline_signer(chain_id: &str) -> KeplrOfflineSigner;
34
35 #[wasm_bindgen(js_name = getOfflineSignerOnlyAmino)]
36 pub fn get_offline_signer_only_amino(chain_id: &str) -> KeplrOfflineSignerOnlyAmino;
37
38 #[wasm_bindgen(js_name = getOfflineSignerAuto)]
39 pub async fn get_offline_signer_auto(chain_id: &str) -> JsValue;
40
41 #[wasm_bindgen(js_name = getEnigmaUtils)]
42 pub fn get_enigma_utils(chain_id: &str) -> EnigmaUtils;
43
44 #[wasm_bindgen(js_name = suggestToken, catch)]
45 pub async fn suggest_token(
46 chainId: &str,
47 contract_address: &str,
48 viewing_key: Option<&str>,
49 ) -> Result<(), JsValue>;
50
51 #[wasm_bindgen(js_name = getSecret20ViewingKey, catch)]
52 pub async fn get_secret_20_viewing_key(
53 chain_id: &str,
54 contract_address: &str,
55 ) -> Result<JsValue, JsValue>;
56
57 #[wasm_bindgen(js_name = sendTx, catch)]
58 pub async fn sendTx(chainId: &str, tx: &[u8], mode: &str) -> Result<JsValue, JsValue>;
59}
60
61#[wasm_bindgen(js_namespace = ["window", "keplr"])]
62extern "C" {
63 pub type KeplrOfflineSigner;
64
65 #[wasm_bindgen(method, js_name = chainId, getter)]
66 pub fn chain_id(this: &KeplrOfflineSigner) -> JsValue;
67
68 #[wasm_bindgen(method, js_name = getAccounts, catch)]
69 pub async fn get_accounts(this: &KeplrOfflineSigner) -> Result<JsValue, JsValue>;
70
71 #[wasm_bindgen(method, js_name = signAmino, catch)]
72 pub async fn sign_amino(
73 this: &KeplrOfflineSigner,
74 signerAddress: String,
75 signDoc: JsValue, ) -> Result<JsValue, JsValue>; #[wasm_bindgen(method, js_name = signDirect, catch)]
79 pub async fn sign_direct(
80 this: &KeplrOfflineSigner,
81 signerAddress: String,
82 signDoc: JsValue, ) -> Result<JsValue, JsValue>; }
85
86impl std::fmt::Debug for KeplrOfflineSigner {
87 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
88 write!(f, "KeplrOfflineSigner: {:?}", self)
89 }
90}
91
92#[wasm_bindgen(js_namespace = ["window", "keplr"])]
93extern "C" {
94 pub type KeplrOfflineSignerOnlyAmino;
95
96 #[wasm_bindgen(method, js_name = chainId, getter)]
97 pub fn chain_id(this: &KeplrOfflineSignerOnlyAmino) -> JsValue;
98
99 #[wasm_bindgen(method, js_name = getAccounts, catch)]
100 pub async fn get_accounts(this: &KeplrOfflineSignerOnlyAmino) -> Result<JsValue, JsValue>;
101
102 #[wasm_bindgen(method, js_name = signAmino, catch)]
103 pub async fn sign_amino(
104 this: &KeplrOfflineSignerOnlyAmino,
105 signerAddress: String,
106 signDoc: JsValue, ) -> Result<JsValue, JsValue>; }
109
110impl std::fmt::Debug for KeplrOfflineSignerOnlyAmino {
111 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
112 write!(f, "KeplrOfflineSignerOnlyAmino: {:?}", self)
113 }
114}
115
116#[wasm_bindgen(js_namespace = ["window", "keplr"])]
117extern "C" {
118 pub type EnigmaUtils;
119
120 #[wasm_bindgen(method, js_name = chainId, getter)]
121 pub fn chain_id(this: &EnigmaUtils) -> JsValue;
122
123 #[wasm_bindgen(method, js_name = decrypt, catch)]
124 pub async fn decrypt(
125 this: &EnigmaUtils,
126 ciphertext: &[u8],
127 nonce: &[u8],
128 ) -> Result<JsValue, JsValue>;
129
130 #[wasm_bindgen(method, js_name = encrypt, catch)]
131 pub async fn encrypt(
132 this: &EnigmaUtils,
133 contract_code_hash: String,
134 msg: JsValue,
135 ) -> Result<JsValue, JsValue>;
136
137 #[wasm_bindgen(method, js_name = getPubkey)]
138 pub async fn get_pubkey(this: &EnigmaUtils) -> JsValue;
139
140 #[wasm_bindgen(method, js_name = getTxEncryptionKey)]
141 pub async fn get_tx_encryption_key(this: &EnigmaUtils, nonce: &[u8]) -> JsValue;
142}
143
144impl std::fmt::Debug for EnigmaUtils {
145 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
146 write!(f, "EnigmaUtils: {:?}", self)
147 }
148}
149
150#[wasm_bindgen(js_namespace = ["window", "keplr"])]
153extern "C" {
154 #[wasm_bindgen(js_name = enigmaEncrypt)]
155 pub async fn enigma_encrypt(chain_id: &str, code_hash: &str, msg: JsValue) -> JsValue;
156
157 #[wasm_bindgen(js_name = enigmaDecrypt)]
158 pub async fn enigma_decrypt(chain_id: &str, ciphertext: &[u8], nonce: &[u8]) -> JsValue;
159
160 #[wasm_bindgen(js_name = getEnigmaPubKey)]
161 pub async fn get_enigma_pub_key(chain_id: &str) -> JsValue;
162
163 #[wasm_bindgen(js_name = getEnigmaTxEncryptionKey)]
164 pub async fn get_enigma_tx_encryption_key(chain_id: &str, nonce: &[u8]) -> JsValue;
165}