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

starting from scratch #71

Open
deepakagrawal121 opened this issue Jul 6, 2015 · 2 comments
Open

starting from scratch #71

deepakagrawal121 opened this issue Jul 6, 2015 · 2 comments

Comments

@deepakagrawal121
Copy link

Please create an example to start with scratch.
Means create wallet and a address for that wallet.

@sublimator
Copy link
Contributor

package com.ripple.utils.cli;

import com.ripple.config.Config;
import com.ripple.core.coretypes.AccountID;
import com.ripple.crypto.ecdsa.IKeyPair;
import com.ripple.crypto.ecdsa.Seed;

import java.io.IOException;
import java.security.SecureRandom;
import java.util.Arrays;

public class GenerateWallet {
    static {
        Config.initBouncy();
    }
    static SecureRandom random = new SecureRandom();

    public static void main(String[] args) throws IOException {
        Seed seed = new Seed(randomSeed());
        // The keyPair
        IKeyPair key = seed.keyPair();
        // The AccountID
        AccountID accountID = AccountID.fromKeyPair(key);
        // Base58 encoded seed
        String secret = seed.toString();

        System.out.println("account-id/address: " + accountID);
        System.out.println("secret/master-seed: " + secret);

        assert Arrays.equals(seed.bytes(), Seed.fromBase58(secret).bytes());
    }

    private static byte[] randomSeed() {
        byte[] seedBytes = new byte[16];
        random.nextBytes(seedBytes);
        return seedBytes;
    }
}

@sublimator
Copy link
Contributor

A wallet is created from 128 bits of seed entropy, by doing some elliptic curve math, ultimately ending up with a 256 bit scalar secret, with a corresponding public key point. This public key is byte encoded in a canonical form, then hashed to create a 160 bit account id. That is encoded using base58. The 160 bit value is referred to as an account-id or address.

The 128 bit seed value is referred to as the secret or master seed.

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