use alloc::borrow::Cow;
use alloc::vec::Vec;
use ink::ChainExtensionInstance;
use ink_lang as ink;
pub use http_request::{HttpRequest, HttpResponse};
pub use signing::{PublicKeyForArgs, SigType, SignArgs, VerifyArgs};
mod http_request;
pub mod signing;
#[cfg(feature = "std")]
pub mod test;
#[derive(scale::Encode, scale::Decode, Debug)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub struct StorageQuotaExceeded;
#[derive(scale::Encode, scale::Decode)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub enum ErrorCode {}
impl ink_env::chain_extension::FromStatusCode for ErrorCode {
fn from_status_code(status_code: u32) -> Result<(), Self> {
match status_code {
0 => Ok(()),
_ => panic!("encountered unknown status code"),
}
}
}
#[pink_extension_macro::chain_extension]
pub trait PinkExt {
type ErrorCode = ErrorCode;
#[ink(extension = 0xff000001, handle_status = false, returns_result = false)]
fn http_request(request: HttpRequest) -> HttpResponse;
#[ink(extension = 0xff000002, handle_status = false, returns_result = false)]
fn sign(args: SignArgs) -> Vec<u8>;
#[ink(extension = 0xff000003, handle_status = false, returns_result = false)]
fn verify(args: VerifyArgs) -> bool;
#[ink(extension = 0xff000004, handle_status = false, returns_result = false)]
fn derive_sr25519_key(salt: Cow<[u8]>) -> Vec<u8>;
#[ink(extension = 0xff000005, handle_status = false, returns_result = false)]
fn get_public_key(args: PublicKeyForArgs) -> Vec<u8>;
#[ink(extension = 0xff000006, handle_status = false, returns_result = false)]
fn cache_set(key: &[u8], value: &[u8]) -> Result<(), StorageQuotaExceeded>;
#[ink(extension = 0xff000007, handle_status = false, returns_result = false)]
fn cache_set_expire(key: &[u8], expire: u64) -> ();
#[ink(extension = 0xff000008, handle_status = false, returns_result = false)]
fn cache_get(key: &[u8]) -> Option<Vec<u8>>;
#[ink(extension = 0xff000009, handle_status = false, returns_result = false)]
fn cache_remove(args: &[u8]) -> Option<Vec<u8>>;
#[ink(extension = 0xff00000a, handle_status = false, returns_result = false)]
fn log(level: u8, message: &str);
#[ink(extension = 0xff00000b, handle_status = false, returns_result = false)]
fn getrandom(length: u8) -> Vec<u8>;
}
pub fn pink_extension_instance() -> <PinkExt as ChainExtensionInstance>::Instance {
<PinkExt as ChainExtensionInstance>::instantiate()
}