Skip to content

Commit

Permalink
fix review suggests
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-zkp committed Nov 28, 2023
1 parent 3947632 commit 1cb1644
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
13 changes: 6 additions & 7 deletions interface/src/json_rpc_signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,14 @@ impl JsonRpcSigner {
}

pub async fn init_zklink_signer(&mut self, signature: Option<String>) -> Result<(), SignError> {
let signature = if let Some(s) = signature {
PackedEthSignature::from_hex(&s)?
let zklink_signer = if let Some(s) = signature {
let signature = PackedEthSignature::from_hex(&s)?;
let seed = signature.serialize_packed();
ZkLinkSigner::new_from_seed(&seed)?
} else {
self.eth_signer
.sign_message(ZkLinkSigner::SIGN_MESSAGE.as_bytes())
.await?
ZkLinkSigner::new_from_eth_rpc_signer(&self.eth_signer).await?
};
let seed = signature.serialize_packed();
self.zklink_signer = ZkLinkSigner::new_from_seed(&seed)?;
self.zklink_signer = zklink_signer;
Ok(())
}

Expand Down
17 changes: 15 additions & 2 deletions signers/src/zklink_signer/pk_signer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::error::ZkSignerError as Error;
use super::{JUBJUB_PARAMS, RESCUE_PARAMS};
use crate::eth_signer::pk_signer::EthSigner;

use crate::eth_signer::H256;
use crate::zklink_signer::public_key::PackedPublicKey;
use crate::zklink_signer::signature::{PackedSignature, ZkLinkSignature};
Expand All @@ -13,6 +13,10 @@ use franklin_crypto::eddsa::{PrivateKey as FLPrivateKey, PrivateKey, PublicKey,
use sha2::{Digest, Sha256};
use std::fmt;

#[cfg(feature = "web")]
use crate::eth_signer::json_rpc_signer::JsonRpcSigner;
use crate::eth_signer::pk_signer::EthSigner;

pub struct ZkLinkSigner(EddsaPrivKey<Engine>);

impl Clone for ZkLinkSigner {
Expand Down Expand Up @@ -47,7 +51,7 @@ pub fn sha256_bytes(input: &[u8]) -> Vec<u8> {
}

impl ZkLinkSigner {
pub const SIGN_MESSAGE: &'static str =
const SIGN_MESSAGE: &'static str =
"Sign this message to create a key to interact with zkLink's layer2 services.\nNOTE: This application is powered by zkLink protocol.\n\nOnly sign this message for a trusted client!";
pub fn new() -> Result<Self, Error> {
let eth_pk = H256::random();
Expand Down Expand Up @@ -94,6 +98,15 @@ impl ZkLinkSigner {
Self::new_from_seed(&seed)
}

#[cfg(feature = "web")]
pub async fn new_from_eth_rpc_signer(eth_signer: &JsonRpcSigner) -> Result<Self, Error> {
let signature = eth_signer
.sign_message(Self::SIGN_MESSAGE.as_bytes())
.await?;
let seed = signature.serialize_packed();
Self::new_from_seed(&seed)
}

pub fn new_from_bytes(bytes: &[u8]) -> Result<Self, Error> {
let mut fs_repr = FsRepr::default();
fs_repr
Expand Down

0 comments on commit 1cb1644

Please sign in to comment.