Skip to content

Commit

Permalink
Revert "fix integration test bug fix(fix #149) (#150)" (#153)
Browse files Browse the repository at this point in the history
This reverts commit 834f0bf.
  • Loading branch information
Fred0327 authored Dec 22, 2023
1 parent 834f0bf commit b3307b7
Show file tree
Hide file tree
Showing 30 changed files with 62 additions and 249 deletions.
2 changes: 1 addition & 1 deletion binding_tests/interface_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ func TestSignWithdraw(t *testing.T) {
fmt.Printf("zklink tx: %s\n", zklinkTx)

// test signer
signer, err := sdk.NewSigner(s, sdk.L1SignerTypeEth{});
signer, err := sdk.NewSigner(s, sdk.L1TypeEth);
assert.Nil(t, err)
tx_signature, err := signer.SignWithdraw(tx, l2SourceTokenSymbol,nil,nil)
assert.Nil(t, err)
Expand Down
8 changes: 1 addition & 7 deletions bindings/sdk/src/ffi.udl
Original file line number Diff line number Diff line change
Expand Up @@ -596,15 +596,9 @@ enum L1Type {
"Starknet",
};

[Enum]
interface L1SignerType {
Eth();
Starknet(string chain_id,string address);
};

interface Signer {
[Throws=SignError]
constructor([ByRef] string private_key, L1SignerType l1_type);
constructor([ByRef] string private_key, L1Type l1_type);
[Throws=SignError]
TxSignature sign_change_pubkey_with_create2data_auth(ChangePubKey tx, Create2Data crate2data);
[Throws=SignError]
Expand Down
1 change: 0 additions & 1 deletion bindings/sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ use zklink_sdk_interface::error::SignError;
use zklink_sdk_interface::sign_change_pubkey::{
create_signed_change_pubkey, eth_signature_of_change_pubkey,
};
use zklink_sdk_interface::signer::L1SignerType;
use zklink_sdk_interface::signer::{L1Type, Signer};
use zklink_sdk_interface::ChangePubKeyAuthRequest;

Expand Down
33 changes: 10 additions & 23 deletions bindings/wasm/src/json_rpc_signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ pub struct JsonRpcSigner {
inner: InterfaceJsonRpcSigner,
}

//#[wasm_bindgen(constructor)]
#[wasm_bindgen(js_name=newRpcSignerWithProvider)]
pub fn new_with_provider(provider: Provider) -> Result<JsonRpcSigner, JsValue> {
let inner = InterfaceJsonRpcSigner::new(JsonRpcProvider::Provider(provider), None, None)?;
Ok(JsonRpcSigner { inner })
}

//#[wasm_bindgen(constructor)]
#[wasm_bindgen(js_name=newRpcSignerWithSigner)]
pub fn new_with_signer(
signer: Signer,
Expand All @@ -52,18 +54,15 @@ impl JsonRpcSigner {
Ok(self.inner.init_zklink_signer(signature).await?)
}

#[wasm_bindgen(js_name = pubkeyHash)]
pub fn pub_key_hash(&self) -> String {
self.inner.pub_key_hash()
}

#[wasm_bindgen(js_name=signChangePubkeyWithOnchain)]
pub fn sign_change_pubkey_with_onchain(&self, tx: ChangePubKey) -> Result<JsValue, JsValue> {
#[wasm_bindgen(js_name = signTransfer)]
pub async fn sign_transfer(
&self,
tx: Transfer,
token_symbol: &str,
) -> Result<JsValue, JsValue> {
let inner_tx = tx.json_value()?;
let change_pubkey: TxChangePubKey = serde_wasm_bindgen::from_value(inner_tx)?;
let signature = self
.inner
.sign_change_pubkey_with_onchain_auth_data(change_pubkey)?;
let transfer: TxTransfer = serde_wasm_bindgen::from_value(inner_tx)?;
let signature = self.inner.sign_transfer(transfer, token_symbol).await?;
Ok(serde_wasm_bindgen::to_value(&signature)?)
}

Expand Down Expand Up @@ -97,18 +96,6 @@ impl JsonRpcSigner {
Ok(serde_wasm_bindgen::to_value(&signature)?)
}

#[wasm_bindgen(js_name = signTransfer)]
pub async fn sign_transfer(
&self,
tx: Transfer,
token_symbol: &str,
) -> Result<JsValue, JsValue> {
let inner_tx = tx.json_value()?;
let transfer: TxTransfer = serde_wasm_bindgen::from_value(inner_tx)?;
let signature = self.inner.sign_transfer(transfer, token_symbol).await?;
Ok(serde_wasm_bindgen::to_value(&signature)?)
}

#[wasm_bindgen(js_name=createSignedOrder)]
pub fn create_signed_order(&self, order: Order) -> Result<JsValue, JsValue> {
let inner_order = order.json_value()?;
Expand Down
30 changes: 12 additions & 18 deletions bindings/wasm/src/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::tx_types::transfer::Transfer;
use crate::tx_types::withdraw::Withdraw;
use wasm_bindgen::prelude::wasm_bindgen;
use wasm_bindgen::JsValue;
use zklink_sdk_interface::signer::L1SignerType;
use zklink_sdk_interface::signer::L1Type as InnerL1Type;
use zklink_sdk_interface::signer::Signer as InterfaceSigner;
use zklink_sdk_types::tx_type::change_pubkey::ChangePubKey as TxChangePubKey;
use zklink_sdk_types::tx_type::change_pubkey::Create2Data as ChangePubKeyCreate2Data;
Expand Down Expand Up @@ -38,26 +38,20 @@ pub enum L1Type {
Starknet,
}

impl From<L1Type> for InnerL1Type {
fn from(value: L1Type) -> InnerL1Type {
match value {
L1Type::Eth => InnerL1Type::Eth,
L1Type::Starknet => InnerL1Type::Starknet,
}
}
}

#[wasm_bindgen]
impl Signer {
#[wasm_bindgen(constructor)]
pub fn new(
private_key: &str,
l1_type: L1Type,
starknet_chain_id: Option<String>,
starknet_addr: Option<String>,
) -> Result<Signer, JsValue> {
let l1_signer_type = match l1_type {
L1Type::Eth => L1SignerType::Eth {
net: "eth".to_string(),
},
L1Type::Starknet => L1SignerType::Starknet {
net: "starknet".to_string(),
chain_id: starknet_chain_id.unwrap(),
address: starknet_addr.unwrap(),
},
};
let inner = InterfaceSigner::new(private_key, l1_signer_type)?;
pub fn new(private_key: &str, l1_type: L1Type) -> Result<Signer, JsValue> {
let inner = InterfaceSigner::new(private_key, l1_type.into())?;
Ok(Signer { inner })
}

Expand Down
2 changes: 1 addition & 1 deletion examples/Golang/10_update_global_var.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func HighLevelUpdateGlobalVar() {
}

tx := sdk.NewUpdateGlobalVar(builder)
signer, err := sdk.NewSigner(privateKey, sdk.L1SignerTypeEth{})
signer, err := sdk.NewSigner(privateKey, sdk.L1TypeEth)
if err != nil {
return
}
Expand Down
2 changes: 1 addition & 1 deletion examples/Golang/1_change_pubkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func HighLevelChangePubkeyEcdsa() {
timeStamp,
}
tx := sdk.NewChangePubKey(builder)
signer, err := sdk.NewSigner(privateKey, sdk.L1SignerTypeEth{})
signer, err := sdk.NewSigner(privateKey, sdk.L1TypeEth)
if err != nil {
return
}
Expand Down
2 changes: 1 addition & 1 deletion examples/Golang/2_withdraw.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func HighLevelWithdraw() {
Timestamp: timestamp,
}
tx := sdk.NewWithdraw(builder)
signer, err := sdk.NewSigner(privateKey, sdk.L1SignerTypeEth{})
signer, err := sdk.NewSigner(privateKey, sdk.L1TypeEth)
if err != nil {
return
}
Expand Down
2 changes: 1 addition & 1 deletion examples/Golang/3_transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func HighLevelTransfer() {
}
tokenSymbol := "DAI"
tx := sdk.NewTransfer(builder)
signer, err := sdk.NewSigner(privateKey, sdk.L1SignerTypeEth{})
signer, err := sdk.NewSigner(privateKey, sdk.L1TypeEth)
if err != nil {
return
}
Expand Down
2 changes: 1 addition & 1 deletion examples/Golang/4_forced_exit.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func HighLevelForcedExit() {
Timestamp: sdk.TimeStamp(1693472232),
}
tx := sdk.NewForcedExit(builder)
signer, err := sdk.NewSigner(privateKey, sdk.L1SignerTypeEth{})
signer, err := sdk.NewSigner(privateKey, sdk.L1TypeEth)
if err != nil {
return
}
Expand Down
2 changes: 1 addition & 1 deletion examples/Golang/5_order_matching.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func HighLevelOrderMatching() {
*big.NewInt(5479779),
}
tx := sdk.NewOrderMatching(builder)
signer, err := sdk.NewSigner(privateKey, sdk.L1SignerTypeEth{})
signer, err := sdk.NewSigner(privateKey, sdk.L1TypeEth)
if err != nil {
return
}
Expand Down
2 changes: 1 addition & 1 deletion examples/Golang/6_contract_matching.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func HighLevelContractMatching() {
}

tx := sdk.NewContractMatching(builder)
signer, err := sdk.NewSigner(privateKey, sdk.L1SignerTypeEth{})
signer, err := sdk.NewSigner(privateKey, sdk.L1TypeEth)
if err != nil {
return
}
Expand Down
2 changes: 1 addition & 1 deletion examples/Golang/7_auto_deleveraging.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func HighLevelAutoDeleveraging() {
sdk.TokenId(18),
}
tx := sdk.NewAutoDeleveraging(builder)
signer, err := sdk.NewSigner(privateKey, sdk.L1SignerTypeEth{})
signer, err := sdk.NewSigner(privateKey, sdk.L1TypeEth)
if err != nil {
return
}
Expand Down
2 changes: 1 addition & 1 deletion examples/Golang/8_funding.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func HighLevelFunding() {
sdk.TokenId(17),
}
tx := sdk.NewFunding(builder)
signer, err := sdk.NewSigner(privateKey, sdk.L1SignerTypeEth{})
signer, err := sdk.NewSigner(privateKey, sdk.L1TypeEth)
if err != nil {
return
}
Expand Down
2 changes: 1 addition & 1 deletion examples/Golang/9_liquidation.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func HighLevelLiquidation() {
}

tx := sdk.NewLiquidation(builder)
signer, err := sdk.NewSigner(privateKey, sdk.L1SignerTypeEth{})
signer, err := sdk.NewSigner(privateKey, sdk.L1TypeEth)
if err != nil {
return
}
Expand Down
5 changes: 3 additions & 2 deletions examples/Javascript/js-example/1_change_pubkey.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import init, * as wasm from "./web-dist/zklink-sdk-web.js";
import { ethers } from "https://cdn-cors.ethers.io/lib/ethers-5.5.4.esm.min.js";

async function testEcdsaAuth() {
await init();
Expand All @@ -18,7 +19,7 @@ async function testEcdsaAuth() {
const provider = window.bitkeep && window.bitkeep.ethereum;
await provider.request({ method: 'eth_requestAccounts' });

const signer = new wasm.newRpcSignerWithProvider(provider);
const signer = new wasm.newW(provider);

// use cached ethereum signature to init zklink signer
//const signature = "0x1111111111";
Expand Down Expand Up @@ -55,7 +56,7 @@ async function testCreate2() {
let tx = wasm.newChangePubkey(tx_builder);
const provider = window.bitkeep && window.bitkeep.ethereum;
await provider.request({ method: 'eth_requestAccounts' });
const signer = new wasm.newRpcSignerWithProvider(provider);
const signer = new wasm.JsonRpcSigner(provider);
await signer.initZklinkSigner(null);
console.log(signer);

Expand Down
2 changes: 1 addition & 1 deletion examples/Javascript/js-example/2_transfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ async function testEvmChains() {
let transfer = wasm.newTransfer(tx_builder);
const provider = window.bitkeep && window.bitkeep.ethereum;
await provider.request({ method: 'eth_requestAccounts' });
const signer = new wasm.newRpcSignerWithProvider(provider);
const signer = new wasm.JsonRpcSigner(provider);
await signer.initZklinkSigner(null);
console.log(signer);

Expand Down
2 changes: 1 addition & 1 deletion examples/Javascript/js-example/3_order_matching.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ async function main() {
try {
const provider = window.bitkeep && window.bitkeep.ethereum;
await provider.request({ method: 'eth_requestAccounts' });
const signer = new wasm.newRpcSignerWithProvider(provider);
const signer = new wasm.JsonRpcSigner(provider);
await signer.initZklinkSigner(null);
console.log(signer);

Expand Down
2 changes: 1 addition & 1 deletion examples/Javascript/js-example/4_withdraw.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ async function main() {
let withdraw = wasm.newWithdraw(tx_builder);
const provider = window.bitkeep && window.bitkeep.ethereum;
await provider.request({ method: 'eth_requestAccounts' });
const signer = new wasm.newRpcSignerWithProvider(provider);
const signer = new wasm.JsonRpcSigner(provider);
await signer.initZklinkSigner(null);
console.log(signer);

Expand Down
2 changes: 1 addition & 1 deletion examples/Javascript/js-example/5_forced_exit.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ async function main() {
let forced_exit = wasm.newForcedExit(tx_builder);
const provider = window.bitkeep && window.bitkeep.ethereum;
await provider.request({ method: 'eth_requestAccounts' });
const signer = new wasm.newRpcSignerWithProvider(provider);
const signer = new wasm.JsonRpcSigner(provider);
await signer.initZklinkSigner(null);
console.log(signer);
let signature = signer.signForcedExit(forced_exit)
Expand Down
46 changes: 0 additions & 46 deletions examples/Javascript/js-example/7_deposit.js

This file was deleted.

Loading

0 comments on commit b3307b7

Please sign in to comment.