pub type CryptoService = WasmInstance;Aliased Type§
pub struct CryptoService {Show 13 fields
pub memory: Memory,
pub alloc: Func,
pub free: Func,
pub public_key: Func,
pub convert: Func,
pub unconvert: Func,
pub verify: Func,
pub verify_eip155: Func,
pub recover_v: Func,
pub address_eth: Func,
pub address_cosmos: Func,
pub store: Store<()>,
pub instance: Instance,
}Fields§
§memory: Memory§alloc: Func§free: Func§public_key: Func§convert: Func§unconvert: Func§verify: Func§verify_eip155: Func§recover_v: Func§address_eth: Func§address_cosmos: Func§store: Store<()>§instance: InstanceImplementations§
Source§impl CryptoService
impl CryptoService
Sourcepub fn new(loader: &Arc<WasmLoader>) -> Result<Self, Box<dyn Error>>
pub fn new(loader: &Arc<WasmLoader>) -> Result<Self, Box<dyn Error>>
Creates a new CryptoService by instantiating a WASM module from the given loader.
§Errors
Returns an error if the WASM module instantiation fails.
Sourcepub fn address_eth(
&mut self,
public_key: &str,
) -> Result<String, Box<dyn Error>>
pub fn address_eth( &mut self, public_key: &str, ) -> Result<String, Box<dyn Error>>
§Arguments
public_key- The public key as a string.
§Returns
A Result containing the Ethereum address as a hexadecimal string (with 0x prefix) if successful,
or an error if the WASM invocation fails.
§Errors
Returns an error if the WASM function cannot be typed or invoked correctly, or if the WASM function returns an error string.
Sourcepub fn address_cosmos(
&mut self,
public_key: &str,
hrp: &str,
) -> Result<String, Box<dyn Error>>
pub fn address_cosmos( &mut self, public_key: &str, hrp: &str, ) -> Result<String, Box<dyn Error>>
§Arguments
public_key- The compressed secp256k1 public key as a hex string (33 bytes, starts with 0x02 or 0x03).hrp- The desired Bech32 HRP prefix (e.g., “cosmos”, “osmo”). If empty or invalid, defaults to"cosmos".
§Returns
A Result containing the Cosmos address as a Bech32m string if successful,
or an error if the WASM invocation fails.
§Errors
Returns an error if the WASM function cannot be typed or invoked correctly, or if the WASM function returns an error string.
Sourcepub fn verify(
&mut self,
message: &str,
signature: &str,
public_key: &str,
) -> Result<bool, Box<dyn Error>>
pub fn verify( &mut self, message: &str, signature: &str, public_key: &str, ) -> Result<bool, Box<dyn Error>>
Verifies a message signature using a public key via the WASM module.
§Arguments
message- The original message.signature- The signature to verify.public_key- The public key used for verification.
§Returns
Ok(true) if the signature is valid, Ok(false) if invalid, or an error on failure.
§Errors
Returns an error if memory allocation or WASM function invocation fails.
Sourcepub fn recover_v(
&mut self,
message: &str,
signature: &str,
public_key: &str,
eth_chain_id: Option<u8>,
) -> Result<String, Box<dyn Error>>
pub fn recover_v( &mut self, message: &str, signature: &str, public_key: &str, eth_chain_id: Option<u8>, ) -> Result<String, Box<dyn Error>>
Recovers the Ethereum-compatible recovery ID v (as a hex string) from a signature and public key via the WASM module.
§Arguments
message- The original message hash as a hex string (64 characters).signature- The signature without the recovery ID (r + s) as a hex string (128 characters).public_key- The compressed public key as a hex string (66 characters).
§Returns
Returns Ok(String) containing the recovered v value in hex (e.g., "1b") if successful,
or an error string from the WASM module if recovery fails.
§Errors
Returns an error if memory allocation fails, the WASM function invocation fails, or if the returned pointer is null or the returned string is invalid UTF-8.
Sourcepub fn verify_eip155(
&mut self,
message_hash: &str,
signature: &str,
public_key: &str,
) -> Result<bool, Box<dyn Error>>
pub fn verify_eip155( &mut self, message_hash: &str, signature: &str, public_key: &str, ) -> Result<bool, Box<dyn Error>>
Verifies an Ethereum EIP-155 message signature using a public key via the WASM module.
§Arguments
message_hash- The 32-byte hex-encoded hash of the original message.signature- The 65-byte signature (r[32] + s[32] + v[1]), hex-encoded.public_key- The compressed 33-byte public key, hex-encoded.
§Returns
Ok(true) if the signature is valid, Ok(false) if invalid, or an error on failure.
§Errors
Returns an error if memory allocation or WASM function invocation fails.