Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create wallet API endpoint #6

Open
olemis opened this issue Feb 21, 2019 · 2 comments
Open

Create wallet API endpoint #6

olemis opened this issue Feb 21, 2019 · 2 comments

Comments

@olemis
Copy link
Contributor

olemis commented Feb 21, 2019

Implement [POST] api/wallets

Should create a new wallet (address) in the blockchain.

Response:

{
 // Private key, which will be used to
 // sign transactions by the [POST] /api/sign
“privateKey”: ”string”,
 // Address which identifies the wallet in the blockchain
“publicAddress”: “string”,
 // Any non security sensitive data associated with
 // wallet. This context will be passed to
 // [POST] /api/transactions/*. 
 // Can be empty.
 “addressContext”: “string”
}

Python implementation

def create_wallet():
    """
    Create the wallet in blockchain
    """

    # generate CSRF token
    CSRF_token = app.session.get(form_url(app_config.SKYCOIN_NODE_URL, "/api/v1/csrf")).json()

    if not CSRF_token or "csrf_token" not in CSRF_token:
        return {"status": 500, "error": "Unknown server error"}

    # generate new seed
    new_seed = app.session.get(
        form_url(app_config.SKYCOIN_NODE_URL, "/api/v1/wallet/newSeed?entropy=128"),
        headers={'X-CSRF-Token': CSRF_token['csrf_token']}).json()

    if not new_seed or "seed" not in new_seed:
        return {"status": 500, "error": "Unknown server error"}

    # create the wallet from seed
    resp = app.session.post(form_url(app_config.SKYCOIN_NODE_URL, "/api/v1/wallet/create"),
                         {"seed": new_seed["seed"],
                             "label": app_config.WALLET_LABEL, "scan": "10"},
                         headers={'X-CSRF-Token': CSRF_token['csrf_token']})

    if not resp:
        return {"status": 500, "error": "Unknown server error"}

    if resp.status_code != 200:
        return {"status": 500, "error": "Unknown server error"}

    new_wallet = resp.json()

    if not new_wallet or "entries" not in new_wallet:
        return {"status": 500, "error": "Unknown server error"}

    seed = new_seed['seed']
    pubkey = skycoin.cipher_PubKey()
    seckey = skycoin.cipher_SecKey()
    error = skycoin.SKY_cipher_GenerateDeterministicKeyPair(
            seed.encode(), pubkey, seckey)
    if error != 0:
        return {"status": 500, "error": "Unknown server error"}

    return {
        "privateKey": binascii.hexlify(bytearray(seckey.toStr())).decode('ascii'),
        "publicAddress": new_wallet["entries"][0]["address"],
        "addressContext": new_wallet['meta']['filename']
    }
@adriantpaez
Copy link

Please check this mismatch:

    return {
        "privateKey": binascii.hexlify(bytearray(seckey.toStr())).decode('ascii'),
        "publicAddress": new_wallet["entries"][0]["address"],
        "addressContext": new_wallet['meta']['filename']
    }

and

{
 // Private key, which will be used to
 // sign transactions by the [ POST] /api/sign
 “privateKey”: ”string”,
 // Address which identifies the wallet in the blockchain
 “publicAddress”: “string”
}

@olemis
Copy link
Contributor Author

olemis commented Feb 24, 2019

@AdrianPaez description updated accordingly .

adriantpaez pushed a commit to uhsimelo/skyxcommons that referenced this issue Feb 27, 2019
adriantpaez added a commit to uhsimelo/skyxcommons that referenced this issue Mar 4, 2019
@adriantpaez adriantpaez removed their assignment Nov 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants