This library acts like a Wallet API Service
by exposing an unified interface which receives and outputs protobuf messages.
The project structure is managed using a crate workspace, comprised by different crates:
Crate | Description | Dev Status | Audit Status |
---|---|---|---|
cli | The CLI of the library | Not implemented | N/A |
interface | The entry of the library, provides request function as the only entrance |
Done | Not Audited |
crypto | The collections of cryptography implementation used by other crates | Done | Not Audited |
wallet | The common structs and methods of the wallet | Done | Not Audited |
chain-common | The common structs and interface of all chain implementation, including the proto definition files | Done | Not Audited |
chain/* | The specific implementation of each chain, only Ethereum supported for now | Done | Not Audited |
package | The npm library wrapper | Done | N/A |
target-wasm | The exposed interface for WebAssembly | Done | Not Audited |
target-mobile | The exposed interface for iOS & Android | Done | Not Audited |
The definition of supported requests and corresponding responses could be found from the proto definition files Api.proto
and Response.proto
in the chain-common/proto
directory.
To send API requests
to this library, you need to call the request(&[u8]) -> Vec<u8>
by sending protobuf encoded requests,
then decode the response using protobuf to get the actual returned value.
- Make sure crates
cargo-lipo
have been installded. rust-std
s foraarch64-apple-ios
,aarch64-apple-ios-sim
andx86_64-apple-ios
are downloaded (can be downloaded by excutingrustup target add x86_64-apple-ios
,rustup target add aarch64-apple-ios-sim
orrustup target add aarch64-apple-ios
).- Install
swift-protobuf
viabrew install swift-protobuf
.
- Execute
sh build_iOS_lib.sh
underscripts
directory. - Add the generated
proto
,MaskWalletCoreMobile.h
andlibmask_wallet_core_mobile.a
inoutput/ios
directory to your iOS project.
Excute sh build-xcframework.sh
in targe-mobile/iOS
directory, MaskWalletCoreMobile.xcframework
and Protos
will be generated.
In development
-
Add chain and coin info to
interface/resource/coin.json
. -
Add a new crate under
chain
, e.g. to add a new chain named "mask", executecargo new mask --lib
inchain
directory. -
Implement
chain_common::entry::Entry
trait in the new added chain crate. -
Add new enum value to
enum Coin
inchain-common/proto/Param.proto
. -
Add the newly added chain to following location in
chain-common/src/coin.rs
.
impl ToString for CoinType {
fn to_string(&self) -> String {
match self {
CoinType::Ethereum => "ethereum".to_owned(),
CoinType::Polkadot => "polkadot".to_owned(),
// Add the new chain here to return the `id`
}
}
}
- Add the newly added chain
Entry
towallet/src/coin_dispatcher.rs
as following.
pub fn get_entry(coin: &Coin) -> Result<Box<dyn Entry>, Error> {
let coin_proto_type = ProtoCoinType::from_str(&coin.name)?;
match coin_proto_type {
ProtoCoinType::Ethereum => Ok(Box::new(EthereumEntry {})),
_ => Err(Error::ChainError(ChainError::NotSupportedCoin)),
}
}
!!IMPORTANT: Please notice that you could not build WebAssembly of this library on MacOSzdue to this issue of compiling Secp256k1 Wasm on mac.
To build the wasm using wasm-pack
on Ubuntu, please ensure you are using Ubuntu 20.04, not Ubuntu 18.
Following below steps to install all the required dependencies.
sudo apt update
sudo apt install cmake
sudo apt install pkg-config libssl-dev clang
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source ~/.cargo/env
cargo install wasm-pack
After successfully installing all dependencies, build the WebAssembly wasm by simply running:
wasm-pack build target-wasm --target web