Open deepakagrawal121 opened 9 years ago
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;
}
}
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
.
Please create an example to start with scratch. Means create wallet and a address for that wallet.