gecko/packages/dubp_rs/README.md

195 lines
4.6 KiB
Markdown
Raw Normal View History

2021-01-04 17:08:17 +01:00
# dubp
Flutter package that bind [dubp-rs-libs] Rust crates.
## Setup
### Prerequisites
* Android SDK
2021-01-04 18:51:37 +01:00
* Android **N**DK (**Native** Development Kit)
* Rust and cargo
* Cargo plugin cargo-make: `cargo install cargo-make`
* LLVM/Clang (see dedicated section below)
2021-01-04 18:51:37 +01:00
You must indicate where the SDK and NDK are located via the `ANDROID_SDK_ROOT` and `ANDROID_NDK_HOME` environment variables.
For example:
export ANDROID_SDK_ROOT="/home/user/dev/android_sdk"
export ANDROID_NDK_HOME="/home/user/dev/android_sdk/ndk/22.0.7026061"
You will also need to add targets for all Android architectures:
```sh
rustup target add aarch64-linux-android armv7-linux-androideabi x86_64-linux-android i686-linux-android
```
If you develop on mac, you can also add targets for iOS:
```sh
rustup target add aarch64-apple-ios x86_64-apple-ios
```
### LLVM/Clang
The project use [`dart-bindgen`](https://github.com/sunshine-protocol/dart-bindgen) which requires LLVM/Clang. Install LLVM (10+) in the following way:
#### ubuntu/linux
1. Install libclangdev - `sudo apt-get install libclang-dev`.
#### Windows
1. Install Visual Studio with C++ development support.
2. Install [LLVM](https://releases.llvm.org/download.html) or `winget install -e --id LLVM.LLVM`.
#### MacOS
1. Install Xcode.
2. Install LLVM - `brew install llvm`.
## Compile
### For development
**To reduce the compilation time of the Rust code** during your development, you can **compile only for the target corresponding to your android emulator**. Here is how to do it **depending on the architecture of your emulator**:
* 32bit emulator (`x86`/`i686` architecture)
```sh
2021-01-09 23:46:54 +01:00
cargo bd
```
* 64bit emulator (`x86_64` architecture)
```sh
cargo make android-dev
```
### For release
In the Root of the project simply run:
```sh
2021-01-09 23:46:54 +01:00
cargo br
```
WARNING: This will take a lot of time because the Rust code will have to be recompiled for each different architecture, 4 times for android and 2 times for iOS!
2021-01-04 17:08:17 +01:00
## Use
You must execute this instruction at startup of your application:
```dart
DubpRust.setup();
```
### Generate a random Mnemonic
#### Function signature
```dart
static Future<String> DubpRust.genMnemonic({Language language = Language.english});
2021-01-04 17:08:17 +01:00
```
#### Usage example
```dart
String mnemonic = await DubpRust.genMnemonic();
```
You can choose a language (english by default):
2021-01-04 17:08:17 +01:00
```dart
String mnemonic = await DubpRust.genMnemonic(language: Language.french);
2021-01-04 17:08:17 +01:00
```
### Generate a wallet
#### Function signature
```dart
static Future<NewWallet> genWalletFromMnemonic({
String currency = "g1",
Language language = Language.english,
2021-01-04 17:08:17 +01:00
String mnemonic,
2021-01-09 23:46:54 +01:00
SecretCodeType secretCodeType = SecretCodeType.letters
2021-01-04 17:08:17 +01:00
});
```
If the mnemonic is not in english, you must indicate the language of the mnemonic (necessary for the verification of its validity).
2021-01-04 17:08:17 +01:00
If the wallet to be generated is not dedicated to the Ğ1 currency, you must indicate the currency for which this wallet will be used.
#### Usage example
```dart
NewWallet new_wallet = await DubpRust.genWalletFromMnemonic(
language: Language.english,
2021-01-04 17:08:17 +01:00
mnemonic: "tongue cute mail fossil great frozen same social weasel impact brush kind"
);
```
2021-01-09 23:46:54 +01:00
You can choose a different secret code type:
2021-01-04 17:08:17 +01:00
```dart
NewWallet new_wallet = await DubpRust.genWalletFromMnemonic(
language: Language.english,
2021-01-04 17:08:17 +01:00
mnemonic: "tongue cute mail fossil great frozen same social weasel impact brush kind",
2021-01-09 23:46:54 +01:00
secretCodeType: SecretCodeType.digits
2021-01-04 17:08:17 +01:00
);
```
### Sign a message
#### Function signature
```dart
static Future<String> sign({
String currency = "g1",
String dewif,
String pin,
String message
});
```
If the wallet is not dedicated to the Ğ1 currency, you must indicate the currency.
#### Usage example
```dart
String signature = await DubpRust.sign(
dewif: "AAAAARAAAAGfFDAs+jVZYkfhBlHZZ2fEQIvBqnG16g5+02cY18wSOjW0cUg2JV3SUTJYN2CrbQeRDwGazWnzSFBphchMmiL0",
pin: "CDJ4UB",
message: "toto"
);
```
2021-01-09 23:46:54 +01:00
### Change secret code
2021-01-04 17:08:17 +01:00
2021-01-09 23:46:54 +01:00
You can change the secret code that encrypts the [DEWIF].
2021-01-04 17:08:17 +01:00
#### Function signature
```dart
static Future<NewWallet> changeDewifPin({
String currency = "g1",
String dewif,
String oldPin,
2021-01-09 23:46:54 +01:00
SecretCodeType secretCodeType = SecretCodeType.letters
2021-01-04 17:08:17 +01:00
});
```
If the wallet is not dedicated to the Ğ1 currency, you must indicate the currency.
#### Usage example
```dart
NewWallet new_wallet = await DubpRust.changeDewifPin(
dewif: "AAAAARAAAAGfFDAs+jVZYkfhBlHZZ2fEQIvBqnG16g5+02cY18wSOjW0cUg2JV3SUTJYN2CrbQeRDwGazWnzSFBphchMmiL0",
2021-01-09 23:46:54 +01:00
oldPin: "CDJAUB",
2021-01-04 17:08:17 +01:00
);
```
[dubp-rs-libs]: https://git.duniter.org/libs/dubp-rs-libs
[DEWIF]: https://git.duniter.org/documents/rfcs/blob/dewif/rfc/0013_Duniter_Encrypted_Wallet_Import_Format.md