ripple-unmaintained / ripple-lib-java

Java version of ripple-lib (work in progress)
ISC License
126 stars 109 forks source link

Generate address? #82

Open TommyYehCool opened 7 years ago

TommyYehCool commented 7 years ago

I saw the page RippleAPI has generateAddress.

Has somebody know how to do it by ripple-lib-java ?

sublimator commented 7 years ago

You can do it, though the API is not as clean.

I'll send you a snippet later on, busy atm, feel free to bump in 24 hrs if no response

sublimator commented 7 years ago

But for now, mess around with the Seed/IKeyPair/AccountID classes :)

TommyYehCool commented 7 years ago

Hi do you have example that I can reference?

sublimator commented 7 years ago
public class GenerateAddress {
    public static void main(String[] args) {
        Config.initBouncy();
        SecureRandom random = new SecureRandom();
        byte[] seedBytes = new byte[16];
        random.nextBytes(seedBytes);
        Seed seed = new Seed(seedBytes);
        IKeyPair iKeyPair = seed.keyPair();
        byte[] pub160Hash = iKeyPair.pub160Hash();
        AccountID accountID = AccountID.fromBytes(pub160Hash);
        System.out.println("secret= " + seed +  ", address=" + accountID);
    }
}