quantadex / distributed_quanta_bridge

The distributed version of the quanta bridge
1 stars 0 forks source link

Feature request: Get ETH crosschain address easier #40

Closed quocble closed 5 years ago

quocble commented 5 years ago

Motivation

Most users don't have metamask so they can't create an ethereum address, let's make it easier for them. This is the stats showing them click on disabled button.

image

Scope

Retain the old functionality of forwarding contract which is more secure, while supporting this new feature.

Design

Using Bip32, we can generate many public private key pairs using a single secret using derivation path.

GenerateBip32Key(bip32secret, index) cc6841e10dc631251437492690da13a8f73527c5

Let's use the user's account ID 1.2.X (X = accountID) as the index.

We will generate this and add the public key to the generated address.

On receiving of the funds, we detect whether the address is smart contract by looking for an code. https://ethereum.stackexchange.com/questions/28521/how-to-detect-if-an-address-is-a-contract

Then flush all the coins to the trust contract.

To flush from account, we have to look at the account balance, transfer the funds, signed with the key that we generated. The amount + fee should be precisely equal to the balance.

This is the javascript/webjs equivalent:

    const privateKey = ""
    const gas = web3.toWei("1", "gwei")

    web3.eth.getBalance(acc, (err, balance) => {
        console.log("balance", balance)
        const amount = balance - gas
        var raw = {
            "from": acc,
            "to": mainAcc,
            "value": web3.toHex(amount),
            "gas": web3.toHex(gas),
            "chainId": 1
        };

        web3.eth.accounts.signTransaction(raw, (e,x)=>{}).then(signed=>{
            console.log(raw, signed)

            callback()
        })

    });

Conforming to interfaces:

Use GenerateMultisig interface to generate the address

Use FlushCoin(forwarder string, address string) error to flush the coins (and detecting smart contract or not)

Links

  1. https://goethereumbook.org/transfer-eth/