feat(dubp): add methods checkPublicKey & computeChecksum
This commit is contained in:
parent
ac52d731e9
commit
61289f3422
|
@ -268,9 +268,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dup-crypto"
|
name = "dup-crypto"
|
||||||
version = "0.45.0"
|
version = "0.46.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "58a3b88cbd886b092a7e6c58608d87744706e0fc66a48eaf452c297e5aac3802"
|
checksum = "97b1ebfa9edbb53cd4434f01877fcd74fb2416b93a217754d2daecbeecad67eb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aes",
|
"aes",
|
||||||
"arrayvec",
|
"arrayvec",
|
||||||
|
|
|
@ -11,7 +11,7 @@ crate-type = ["rlib"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
allo-isolate = "0.1.6"
|
allo-isolate = "0.1.6"
|
||||||
dup-crypto = { version = "0.45.0", features = ["bip32-ed25519", "dewif", "mnemonic", "mnemonic_french", "scrypt"] }
|
dup-crypto = { version = "0.46.0", features = ["bip32-ed25519", "dewif", "mnemonic", "mnemonic_french", "scrypt"] }
|
||||||
fast-threadpool = { version = "0.3.0", default-features = false }
|
fast-threadpool = { version = "0.3.0", default-features = false }
|
||||||
once_cell = { version = "1.3.1", default-features = false, features = ["std"] }
|
once_cell = { version = "1.3.1", default-features = false, features = ["std"] }
|
||||||
parking_lot = "0.11.1"
|
parking_lot = "0.11.1"
|
||||||
|
|
|
@ -31,6 +31,8 @@ pub(crate) enum DubpError {
|
||||||
#[error("{0}")]
|
#[error("{0}")]
|
||||||
InvalidAccountIndex(InvalidAccountIndex),
|
InvalidAccountIndex(InvalidAccountIndex),
|
||||||
#[error("{0}")]
|
#[error("{0}")]
|
||||||
|
InvalidPubkey(PublicKeyFromStrErr),
|
||||||
|
#[error("{0}")]
|
||||||
InvalidU31(U31Error),
|
InvalidU31(U31Error),
|
||||||
#[error("Invalid secret code type")]
|
#[error("Invalid secret code type")]
|
||||||
InvalidSecretCodeType,
|
InvalidSecretCodeType,
|
||||||
|
|
|
@ -21,6 +21,7 @@ mod error;
|
||||||
mod inputs;
|
mod inputs;
|
||||||
mod legacy;
|
mod legacy;
|
||||||
mod mnemonic;
|
mod mnemonic;
|
||||||
|
mod pubkey;
|
||||||
mod secret_code;
|
mod secret_code;
|
||||||
|
|
||||||
use crate::error::{DartRes, DubpError};
|
use crate::error::{DartRes, DubpError};
|
||||||
|
@ -35,8 +36,8 @@ use dup_crypto::{
|
||||||
ed25519::bip32::{
|
ed25519::bip32::{
|
||||||
ChainCode, InvalidAccountIndex, KeyPair, PrivateDerivationPath, PublicKeyWithChainCode,
|
ChainCode, InvalidAccountIndex, KeyPair, PrivateDerivationPath, PublicKeyWithChainCode,
|
||||||
},
|
},
|
||||||
ed25519::{KeyPairFromSeed32Generator, PublicKey},
|
ed25519::{KeyPairFromSeed32Generator, PublicKey, PublicKeyFromStrErr},
|
||||||
KeyPair as _, KeyPairEnum, Signator as _, Signature as _,
|
KeyPair as _, KeyPairEnum, PublicKey as _, Signator as _, Signature as _,
|
||||||
},
|
},
|
||||||
mnemonic::{Language, Mnemonic, MnemonicType},
|
mnemonic::{Language, Mnemonic, MnemonicType},
|
||||||
utils::{U31Error, U31},
|
utils::{U31Error, U31},
|
||||||
|
@ -84,6 +85,20 @@ pub extern "C" fn change_dewif_secret_code(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
pub extern "C" fn check_pubkey(port: i64, pubkey: *const raw::c_char) {
|
||||||
|
exec_async(port, || Ok(char_ptr_to_str(pubkey)?), pubkey::check_pubkey)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn compute_checksum(port: i64, pubkey: *const raw::c_char) {
|
||||||
|
exec_async(
|
||||||
|
port,
|
||||||
|
|| Ok(char_ptr_to_str(pubkey)?),
|
||||||
|
pubkey::compute_checksum,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
pub extern "C" fn gen_dewif(
|
pub extern "C" fn gen_dewif(
|
||||||
port: i64,
|
port: i64,
|
||||||
currency: *const raw::c_char,
|
currency: *const raw::c_char,
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
// Copyright (C) 2020 Éloïs SANCHEZ.
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Affero General Public License as
|
||||||
|
// published by the Free Software Foundation, either version 3 of the
|
||||||
|
// License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Affero General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
use crate::*;
|
||||||
|
|
||||||
|
pub(crate) fn check_pubkey(pubkey: &str) -> Result<(), DubpError> {
|
||||||
|
PublicKey::from_base58_with_checksum_opt(pubkey).map_err(DubpError::InvalidPubkey)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn compute_checksum(pubkey: &str) -> Result<String, DubpError> {
|
||||||
|
Ok(PublicKey::from_base58(pubkey)
|
||||||
|
.map_err(|e| DubpError::InvalidPubkey(PublicKeyFromStrErr::BaseConversionError(e)))?
|
||||||
|
.checksum())
|
||||||
|
}
|
|
@ -102,6 +102,30 @@ class DubpRust {
|
||||||
return Future.value(NewWallet._(newWallet[0], newWallet[1]));
|
return Future.value(NewWallet._(newWallet[0], newWallet[1]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Check validity of a base58 public key with its checksum
|
||||||
|
static Future<void> checkPublicKey({String pubkey}) {
|
||||||
|
final completer = Completer<void>();
|
||||||
|
final sendPort =
|
||||||
|
singleCompletePort<void, String>(completer, callback: _handleErrVoid);
|
||||||
|
native.check_pubkey(
|
||||||
|
sendPort.nativePort,
|
||||||
|
Utf8.toUtf8(pubkey),
|
||||||
|
);
|
||||||
|
return completer.future;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Compute public key checksum
|
||||||
|
static Future<String> computeChecksum({String pubkey}) {
|
||||||
|
final completer = Completer<String>();
|
||||||
|
final sendPort =
|
||||||
|
singleCompletePort<String, String>(completer, callback: _handleErr);
|
||||||
|
native.compute_checksum(
|
||||||
|
sendPort.nativePort,
|
||||||
|
Utf8.toUtf8(pubkey),
|
||||||
|
);
|
||||||
|
return completer.future;
|
||||||
|
}
|
||||||
|
|
||||||
/// Generate a random mnemonic
|
/// Generate a random mnemonic
|
||||||
static Future<String> genMnemonic({Language language = Language.english}) {
|
static Future<String> genMnemonic({Language language = Language.english}) {
|
||||||
final completer = Completer<String>();
|
final completer = Completer<String>();
|
||||||
|
|
Loading…
Reference in New Issue