4 个版本
| 0.1.3 | 2019 年 10 月 21 日 |
|---|---|
| 0.1.2 | 2019 年 10 月 16 日 |
| 0.1.1 | 2019 年 10 月 14 日 |
| 0.1.0 | 2019 年 10 月 12 日 |
#16 in #forge
用于 2 crates
51KB
1K SLoC
简介
forge_wallet 由 Rust 实现。基于 forge_crypter,forge_hasher,forge_signer,forge_did。
该包提供了一些帮助函数,以帮助用户创建钱包。
结构体 Wallet
pub struct Wallet {
pub w_type: WalletType,
pub sk: Vec<u8>,
pub pk: Vec<u8>,
pub address: String,
}
API
create_default_wallet() -> 结果<Wallet>from_wallet_type(w_type: &WalletType) -> 结果<Wallet>from_address(addr: &str) -> 结果<Wallet>from_pk(pk: &[u8],w_type: &WalletType) -> 结果<Wallet>from_sk(sk: &[u8],w_type: &WalletType) -> 结果<Wallet>from_json(j:Value) -> 结果<Wallet>to_json(&self) -> 结果<Value>verify(&self,message: &[u8],signature: &[u8]) -> 结果<bool>hash(&self,message: &[u8]) -> 结果<Vec<u8>>sign(&self,message: &[u8]) -> 结果<Vec<u8>>format_wallet(&mut self) -> 结果<()>is_valid(wallet: &Wallet) -> bool
用法
let wallet_type = WalletType {
role_type: Some(RoleType::Application),
key_type: Some(KeyType::Ed25519),
hash_type: Some(HashType::Sha3),
};
let wallet = from_wallet_type(&wallet_type)?;
assert_eq!(wallet, from_sk(&wallet.sk, &wallet_type)?);
let message = b"hello rust";
let signature = wallet.sign(message)?;
assert!(wallet.verify(message, &signature))?;
依赖
~7.5MB
~110K SLoC