From 868680c3f81eacfcb11e0b765e72cba01c6c1d93 Mon Sep 17 00:00:00 2001 From: Lukasz Klimek <842586+lklimek@users.noreply.github.com> Date: Wed, 8 Nov 2023 18:19:47 +0100 Subject: [PATCH] feat: wallet prototype --- Cargo.lock | 1 + packages/rs-sdk/Cargo.toml | 2 +- packages/rs-sdk/src/lib.rs | 1 + packages/rs-sdk/src/wallet.rs | 77 +++++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 packages/rs-sdk/src/wallet.rs diff --git a/Cargo.lock b/Cargo.lock index b863ef8dee3..2f6a301c0d0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1052,6 +1052,7 @@ dependencies = [ "rs-dapi-client", "serde", "serde_json", + "simple-signer", "thiserror", "tokio", "tracing", diff --git a/packages/rs-sdk/Cargo.toml b/packages/rs-sdk/Cargo.toml index cd7ae4e9b30..163d25e3330 100644 --- a/packages/rs-sdk/Cargo.toml +++ b/packages/rs-sdk/Cargo.toml @@ -17,7 +17,7 @@ drive = { path = "../rs-drive", default-features = false, features = [ ] } drive-proof-verifier = { path = "../rs-drive-proof-verifier" } dapi-grpc-macros = { path = "../rs-dapi-grpc-macros" } - +simple-signer = { path = "../simple-signer" } bincode = { version = "2.0.0-rc.3", features = ["serde"], optional = true } thiserror = "1.0.47" tokio = { version = "1.32.0", features = ["macros"] } diff --git a/packages/rs-sdk/src/lib.rs b/packages/rs-sdk/src/lib.rs index 94338720d77..0a4348f625f 100644 --- a/packages/rs-sdk/src/lib.rs +++ b/packages/rs-sdk/src/lib.rs @@ -64,6 +64,7 @@ pub mod error; pub mod mock; pub mod platform; pub mod sdk; +pub mod wallet; pub use error::Error; pub use sdk::{Sdk, SdkBuilder}; diff --git a/packages/rs-sdk/src/wallet.rs b/packages/rs-sdk/src/wallet.rs new file mode 100644 index 00000000000..98f14f16493 --- /dev/null +++ b/packages/rs-sdk/src/wallet.rs @@ -0,0 +1,77 @@ +//! Wallet for managing keys assets in Dash Core and Platform. + +use dashcore_rpc::dashcore::address::NetworkUnchecked; +use dashcore_rpc::dashcore::Address; +use dashcore_rpc::json; +use dpp::bls_signatures::PrivateKey; +pub use dpp::identity::signer::Signer; +use dpp::prelude::AssetLockProof; +use rs_dapi_client::transport::CoreGrpcClient; +use simple_signer::signer::SimpleSigner; + +use crate::{core_client::CoreClient, Error, Sdk}; + +/// Default wallet implementation for Dash Platform SDK. +/// +/// This wallet uses Dash Core wallet RPC client to manage Core keys, and [Signer] instance to manage Platform keys. +/// +pub struct Wallet { + core_wallet: CoreWallet, + platform_wallet: SimpleSigner, +} + +impl Wallet { + /// Create new wallet. + /// + /// Create new wallet using dash core wallet RPC client to manage Core keys, and Signer instance to manage Platform keys. + /// + /// # Arguments + /// + /// * `core` - Dash Core RPC client [CoreClient]. Should be owned by [Sdk]. + /// * `signer` - [Signer] instance, for example [simple_signer::signer::SimpleSigner]. + /// Should be owned by [Sdk]. + pub(crate) fn new_with_clients( + core_client: CoreClient, + signer: SimpleSigner, + ) -> Self { + Self { + core_wallet: CoreWallet { core_client }, + platform_wallet: signer, + } + } + + /// Return Core wallet client. + pub(crate) fn core<'a>(&'a self) -> &'a CoreWallet { + &self.core_wallet + } + + /// Return Platform wallet client. + pub(crate) fn platform<'a>(&'a self) -> &'a SimpleSigner { + &self.platform_wallet + } +} + +pub(crate) struct CoreWallet { + core_client: CoreClient, +} +impl CoreWallet { + /// Create new asset lock transaction that locks some amount of Dash to be used in Platform. + /// + /// # Arguments + /// + /// * `amount` - Amount of Dash to lock. + /// + /// # Returns + /// + /// * `AssetLockProof` - Asset lock proof. + /// * `PrivateKey` - One-time private key used to use locked Dash in Platform. + /// This key should be used to sign Platform transactions. + pub(crate) async fn lock_assets( + &self, + sdk: &Sdk, + amount: u64, + ) -> Result<(AssetLockProof, PrivateKey), Error> { + let change = self.core_client.change_address(); + todo!("implement asset lock tx") + } +}