aeternity / aepp-sdk-go

Golang SDK to interact with the Æternity blockchain
ISC License
18 stars 10 forks source link

How to create ae acount using 12 mnemonics ? #131

Closed Jinxiansen closed 4 years ago

Jinxiansen commented 5 years ago

I only found the account created by the private key or keystore in aepp sdk go, but I didn't find the way to pass the mnemonic. How do I create an ae account with 12 mnemonics? 🤫

English is not my native language; please excuse typing errors.

randomshinichi commented 5 years ago

Hi there, mnemonic seed support hasn't been implemented yet (see #17)

Jinxiansen commented 5 years ago

@randomshinichi How long does it take to support this?

Jinxiansen commented 5 years ago

We need to support ae account in our Golang project, but we have not found a valid solution to create ae account with mnemonics. 😣

noandrea commented 5 years ago

@randomshinichi let's prioritise #17

Jinxiansen commented 5 years ago

@noandrea Thank you very much! 🍺 I found the mnemonic import method for the C++ language version here . I don't know if it helps you.

There is also a way to construct the ae transaction signature here .

randomshinichi commented 5 years ago

@Jinxiansen hi there, I looked into it today. I should have the feature in 5-7 working days. Please hold tight until then :)

Jinxiansen commented 5 years ago

@randomshinichi Good, thank you very much! 🍺🍺🍺

Jinxiansen commented 5 years ago

@randomshinichi @noandrea Hello, how long does it take for the mnemonic to create a wallet? It’s Friday tomorrow! 🥰

randomshinichi commented 5 years ago

@Jinxiansen I can now parse a mnemonic. The problem is getting to an equivalent address from that, which means HD wallet support. So far I have AEX-10 (HD Wallet support) working as a proof of concept, but it needs to be properly implemented with unittests etc.

Jinxiansen commented 5 years ago

@randomshinichi alright, thank you very much! How long does it take?

randomshinichi commented 5 years ago

@Jinxiansen I'll make another branch so you can follow the progress there. It will be released as part of 7.0.0 on Friday.

Jinxiansen commented 5 years ago

@randomshinichi Ok, that's great ! Thank you very much !🥰

randomshinichi commented 5 years ago

@Jinxiansen The branch is feature/hdwallet.

Jinxiansen commented 5 years ago

Okay!thanks!😀😀

------------------ Original ------------------ From: Allen Wang notifications@github.com Date: Wed,Nov 6,2019 1:37 AM To: aeternity/aepp-sdk-go aepp-sdk-go@noreply.github.com Cc: 晋先森 hi@jinxiansen.com, Mention mention@noreply.github.com Subject: Re: [aeternity/aepp-sdk-go] How to create ae acount using 12 mnemonics ? (#131)

@Jinxiansen The branch is feature/hdwallet.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

randomshinichi commented 5 years ago

@Jinxiansen It's basically done at this point, but the interface may not be the most convenient for you right now. So I want to ask - how would you typically use the hd wallet functionality? Would you need create many subaccounts at once, or keep the master account in memory, or do you just need it to get a particular subaccount and nothing else?

Jinxiansen commented 5 years ago

@randomshinichi

Hello! Our project is an application that collects multiple blockchain currencies. A mnemonic is used to generate the private key and address corresponding to multiple currencies. At the time of payment, the transaction is signed according to the private key obtained by the user password.

So we need to create the private key and address of the AE coin through the mnemonic.

Jinxiansen commented 5 years ago

@randomshinichi Hello, how is the progress now?

randomshinichi commented 5 years ago

@Jinxiansen I am making a release today. Just realized it probably isn't good to make a new release on a Friday ;)

Jinxiansen commented 5 years ago

@randomshinichi

Hey, look forward to your release! This has been waiting for half a month! A little anxious..🍺🍺🍺

Jinxiansen commented 5 years ago

@randomshinichi Thanks for your help, I used the code of the hdwallet branch to basically implement the process of importing the wallet via the mnemonic/private key, as well as the method of trading the signature. thank you very much!

Import wallet

func (c *ae) GetWalletAccount() *WalletAccount {
    mnemonic := c.GetKey().Mnemonic
    seedBytes, err := account.ParseMnemonic(mnemonic)
    if err != nil {
        return &WalletAccount{Res: 0, ErrMsg: err.Error()}
    }

    path := "m/44'/457'/0'/0'/0'"
    key, err := account.DerivePathFromSeed(seedBytes, path)
    if err != nil {
        return &WalletAccount{Res: 0, ErrMsg: err.Error()}
    }

    acc, err := account.BIP32KeyToAeKey(key)
    if err != nil {
        return &WalletAccount{Res: 0, ErrMsg: err.Error()}
    }

    privStr := acc.SigningKeyToHexString()

    return &WalletAccount{
        Res:        1,
        PrivateKey: privStr,
        Address:    acc.Address,
        PublicKey:  acc.Address,
    }
}

Sign

func (c *ae) SignRawTransaction(signIn *SignInput) (*SignResult, error) {

    var params AEPPParams
    err := json.Unmarshal(signIn.Params, &params)
    if err != nil {
        fmt.Println("Parse Error: ", err)
        return nil, err
    }

    tx := transactions.NewSpendTx(signIn.SrcAddr,
        signIn.DestAddr,
        big.NewInt(signIn.Amount),
        big.NewInt(signIn.Fee),
        []byte(signIn.Memo),
        uint64(params.TTL),
        uint64(params.TTL))

    txJSON, err := tx.JSON()
    fmt.Println("AE JSON: ", txJSON)

    gotTx, err := transactions.SerializeTx(tx)
    if err != nil {
        fmt.Println("Error: ", err)
        return nil, err
    }

    return &SignResult{Res: 1, RawTX: gotTx}, nil
}
randomshinichi commented 5 years ago

As implemented in v7 release (feature/hdwallet will be deleted soon) To make things foolproof, DerivePathFromSeed does not let you specify the full path. m/44'/457'/0'/0'/0'

key, err := account.DerivePathFromSeed(seedBytes, 0, 0)

Also you may find this function in package transactions useful:

signedTx, hash, signature, err := transactions.SignHashTx(signingAccount, tx, networkID)
Jinxiansen commented 4 years ago

oh! I am looking forward to the release of the new version. I will modify it then.