diff --git a/native/dubp_rs/src/legacy.rs b/native/dubp_rs/src/legacy.rs
new file mode 100644
index 0000000..b5d649b
--- /dev/null
+++ b/native/dubp_rs/src/legacy.rs
@@ -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 .
+
+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()
+}
diff --git a/native/dubp_rs/src/lib.rs b/native/dubp_rs/src/lib.rs
index b701806..7530a96 100644
--- a/native/dubp_rs/src/lib.rs
+++ b/native/dubp_rs/src/lib.rs
@@ -19,6 +19,7 @@ mod r#async;
mod dewif;
mod error;
mod inputs;
+mod legacy;
mod mnemonic;
mod secret_code;
@@ -146,6 +147,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,
language: u32,
@@ -184,6 +202,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,
currency: *const raw::c_char,
diff --git a/packages/dubp_rs/lib/dubp.dart b/packages/dubp_rs/lib/dubp.dart
index 1a7f3d7..6332ea3 100644
--- a/packages/dubp_rs/lib/dubp.dart
+++ b/packages/dubp_rs/lib/dubp.dart
@@ -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 getLegacyPublicKey({String password, String salt}) {
+ final completer = Completer();
+ final sendPort =
+ singleCompletePort(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 getDewifPublicKey(
{String currency = "g1", String dewif, String pin}) async {
final completer = Completer();
@@ -153,6 +166,21 @@ class DubpRust {
return completer.future;
}
+ /// Sign the message `message` with legacy wallet (password + salt)
+ static Future signLegacy(
+ {String password, String salt, String message}) {
+ final completer = Completer();
+ final sendPort =
+ singleCompletePort(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.
///