feat(dubp):add methods getLegacyPublicKey & signLegacy for legacy wallet
legacy wallet is a wallet generated with deprecated (salt+password) process
This commit is contained in:
parent
a4f78f8be8
commit
2b104686b8
|
@ -0,0 +1,32 @@
|
|||
// 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::*;
|
||||
use dup_crypto::keys::ed25519::{KeyPairFromSaltedPasswordGenerator, SaltedPassword};
|
||||
|
||||
pub(super) fn get_pubkey(salt: &str, password: &str) -> String {
|
||||
KeyPairFromSaltedPasswordGenerator::with_default_parameters()
|
||||
.generate(SaltedPassword::new(salt.to_owned(), password.to_owned()))
|
||||
.public_key()
|
||||
.to_base58()
|
||||
}
|
||||
|
||||
pub(super) fn sign(salt: &str, password: &str, msg: &str) -> String {
|
||||
KeyPairFromSaltedPasswordGenerator::with_default_parameters()
|
||||
.generate(SaltedPassword::new(salt.to_owned(), password.to_owned()))
|
||||
.generate_signator()
|
||||
.sign(msg.as_bytes())
|
||||
.to_base64()
|
||||
}
|
|
@ -19,6 +19,7 @@ mod r#async;
|
|||
mod dewif;
|
||||
mod error;
|
||||
mod inputs;
|
||||
mod legacy;
|
||||
mod mnemonic;
|
||||
mod secret_code;
|
||||
|
||||
|
@ -145,6 +146,23 @@ pub extern "C" fn get_dewif_pubkey(
|
|||
)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn get_legacy_pubkey(
|
||||
port: i64,
|
||||
salt: *const raw::c_char,
|
||||
password: *const raw::c_char,
|
||||
) {
|
||||
exec_async(
|
||||
port,
|
||||
|| {
|
||||
let salt = char_ptr_to_str(salt)?;
|
||||
let password = char_ptr_to_str(password)?;
|
||||
Ok((salt, password))
|
||||
},
|
||||
|(salt, password)| Ok::<_, DubpError>(legacy::get_pubkey(salt, password)),
|
||||
)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn mnemonic_to_pubkey(
|
||||
port: i64,
|
||||
|
@ -183,6 +201,25 @@ pub extern "C" fn sign(
|
|||
)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn sign_legacy(
|
||||
port: i64,
|
||||
salt: *const raw::c_char,
|
||||
password: *const raw::c_char,
|
||||
msg: *const raw::c_char,
|
||||
) {
|
||||
exec_async(
|
||||
port,
|
||||
|| {
|
||||
let salt = char_ptr_to_str(salt)?;
|
||||
let password = char_ptr_to_str(password)?;
|
||||
let msg = char_ptr_to_str(msg)?;
|
||||
Ok((salt, password, msg))
|
||||
},
|
||||
|(salt, password, msg)| Ok::<_, DubpError>(legacy::sign(salt, password, msg)),
|
||||
)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn sign_several(
|
||||
port: i64,
|
||||
|
|
|
@ -120,7 +120,20 @@ class DubpRust {
|
|||
return Future.value(NewWallet._(newWallet[0], newWallet[1], newWallet[2]));
|
||||
}
|
||||
|
||||
/// Get pulblic key (in base 58) of `dewif` keypair.
|
||||
/// Get public key (in base 58) of legacy wallet (password + salt)
|
||||
static Future<String> getLegacyPublicKey({String password, String salt}) {
|
||||
final completer = Completer<String>();
|
||||
final sendPort =
|
||||
singleCompletePort<String, String>(completer, callback: _handleErr);
|
||||
native.get_legacy_pubkey(
|
||||
sendPort.nativePort,
|
||||
Utf8.toUtf8(password),
|
||||
Utf8.toUtf8(salt),
|
||||
);
|
||||
return completer.future;
|
||||
}
|
||||
|
||||
/// Get public key (in base 58) of `dewif` keypair.
|
||||
static Future<String> getDewifPublicKey(
|
||||
{String currency = "g1", String dewif, String pin}) async {
|
||||
final completer = Completer<String>();
|
||||
|
@ -153,6 +166,21 @@ class DubpRust {
|
|||
return completer.future;
|
||||
}
|
||||
|
||||
/// Sign the message `message` with legacy wallet (password + salt)
|
||||
static Future<String> signLegacy(
|
||||
{String password, String salt, String message}) {
|
||||
final completer = Completer<String>();
|
||||
final sendPort =
|
||||
singleCompletePort<String, String>(completer, callback: _handleErr);
|
||||
native.sign_legacy(
|
||||
sendPort.nativePort,
|
||||
Utf8.toUtf8(password),
|
||||
Utf8.toUtf8(salt),
|
||||
Utf8.toUtf8(message),
|
||||
);
|
||||
return completer.future;
|
||||
}
|
||||
|
||||
/// Sign several messages `messages` with `dewif` keypair encryted in DEWIF
|
||||
/// format.
|
||||
///
|
||||
|
|
Loading…
Reference in New Issue