Esempio n. 1
0
    async def asyncSetUp(self) -> None:
        self.account = Account.from_key(self.private_key)
        ethereum_signer = EthereumSignerWeb3(account=self.account)
        self.library = ZkSyncLibrary()

        w3 = Web3(
            HTTPProvider(
                endpoint_uri=
                "https://rinkeby.infura.io/v3/bcf42e619a704151a1b0d95a35cb2e62"
            ))
        provider = ZkSyncProviderV01(provider=HttpJsonRPCTransport(
            network=rinkeby))
        address = await provider.get_contract_address()
        self.zksync = ZkSync(account=self.account,
                             web3=w3,
                             zksync_contract_address=address.main_contract)

        ethereum_provider = EthereumProvider(w3, self.zksync)
        signer = ZkSyncSigner.from_account(self.account, self.library,
                                           rinkeby.chain_id)

        self.wallet = Wallet(ethereum_provider=ethereum_provider,
                             zk_signer=signer,
                             eth_signer=ethereum_signer,
                             provider=provider)
Esempio n. 2
0
def derive_private_key(library: ZkSyncLibrary, message: str,
                       account: BaseAccount, chain_id: ChainId):
    if chain_id != ChainId.MAINNET:
        message = f"{message}\nChain ID: {chain_id}."
    signable_message = encode_defunct(message.encode())
    signature = account.sign_message(signable_message)
    private_key = library.private_key_from_seed(signature.signature)
    return private_key
Esempio n. 3
0
class TestZkSyncLibrary(TestCase):
    def setUp(self):
        self.library = ZkSyncLibrary()

    def test_public_key_hash_from_seed(self):
        seed = b"1" * 32
        key = self.library.private_key_from_seed(seed)
        assert key != seed
        pub_key = self.library.get_public_key(key)
        assert pub_key != key
        pub_key_hash = self.library.get_pubkey_hash(pub_key)
        assert pub_key != pub_key_hash

    def test_sign(self):
        seed = bytes.fromhex("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f")
        message = bytes.fromhex(
            "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f")
        key = self.library.private_key_from_seed(seed)
        signature = self.library.sign(key, message)
        pub_key = self.library.get_public_key(key)

        assert key.hex() == "0552a69519d1f3043611126c13489ff4a2a867a1c667b1d9d9031cd27fdcff5a"
        assert signature.hex() == "5462c3083d92b832d540c9068eed0a0450520f6dd2e4ab169de1a46585b394a4292896a2ebca3c0378378963a6bc1710b64c573598e73de3a33d6cec2f5d7403"
        assert pub_key.hex() == "17f3708f5e2b2c39c640def0cf0010fd9dd9219650e389114ea9da47f5874184"
        assert signature != message
Esempio n. 4
0
async def get_wallet():
    # Load crypto library
    library = ZkSyncLibrary()

    # Create Zksync Provider
    zk_provider = ZkSyncProviderV01(provider=HttpJsonRPCTransport(
        network=network.rinkeby))

    # Load contract addresses from server
    contracts = await zk_provider.get_contract_address()

    pprint(contracts)
    contracts.main_contract
    print(contracts.main_contract)

    # Setup web3 account
    account = Account.from_key("")
    pprint(account)
    addr = account.address
    print(addr)

    # Create EthereumSigner
    eth_signer = EthereumSignerWeb3(account=account)

    # Setup web3
    w3 = Web3(HTTPProvider(endpoint_uri=""))

    # Setup zksync contract interactor
    zksync = ZkSync(account=account,
                    web3=w3,
                    zksync_contract_address=contracts.main_contract)

    # Create ethereum provider for interacting with ethereum node
    eth_provider = EthereumProvider(w3, zksync)

    # Initialize zksync signer, all creating options were described earlier
    zk_signer = ZkSyncSigner.from_account(account, library,
                                          network.rinkeby.chain_id)
Esempio n. 5
0
 async def asyncSetUp(self):
     self.library = ZkSyncLibrary()
     self.wallet = await self.get_wallet(self.private_key)
     self.wallets = [await self.get_wallet(key) for key in self.private_keys]
Esempio n. 6
0
 def setUp(self):
     self.library = ZkSyncLibrary()
Esempio n. 7
0
 def from_seed(cls, library: ZkSyncLibrary, seed: bytes):
     private_key = library.private_key_from_seed(seed)
     return cls(
         library=library,
         private_key=private_key,
     )