From 167aa36cee12ac3ae9f40f16a51d63e74c2c10f4 Mon Sep 17 00:00:00 2001 From: Try-Parser Date: Sun, 22 Oct 2023 20:33:13 +0800 Subject: [PATCH 1/4] Update README.md Update Sample code in readme removing .core package into direct crypto package --- README.md | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 79c5ae818..a6b87acc9 100644 --- a/README.md +++ b/README.md @@ -141,17 +141,24 @@ For use-cases that require private keys to exist inside the running JVM, the fol generate a keypair, and also how to derive an XRPL address from there: ```java -import org.xrpl.xrpl4j.crypto.core.keys.Seed; -import org.xrpl.xrpl4j.crypto.core.keys.PrivateKey; -import org.xrpl.xrpl4j.crypto.core.keys.PublicKey; +import org.xrpl.xrpl4j.crypto.keys.Seed; +import org.xrpl.xrpl4j.crypto.keys.KeyPair; +import org.xrpl.xrpl4j.crypto.keys.PrivateKey; +import org.xrpl.xrpl4j.crypto.keys.PublicKey; import org.xrpl.xrpl4j.model.transactions.Address; - +import org.xrpl.xrpl4j.model.transactions.XAddress; +import org.xrpl.xrpl4j.codec.addresses.AddressCodec; ... +Seed seed = Seed.ed25519Seed(); // <-- Generates a random seed. -Seed seed = Seed.ed255519Seed(); // <-- Generates a random seed. -PrivateKey privateKey = seed.derivePrivateKey(); // <-- Derive a private key from the seed. -PublicKey publicKey = privateKey.derivePublicKey(); // <-- Derive a public key from the private key. -Address address = publicKey.deriveAddress(); // <-- Derive an address from the public key. +KeyPair pair = seed.deriveKeyPair(); // <-- Derive a key pair from seed; +PublicKey pubKey = pair.publicKey(); // <-- Public key from KeyPair +PrivateKey privKey = pair.privateKey() // <-- Private key from KeyPair + +// Classic Addresss +Address classicAddress = pubKey.deriveAddress(); +// Derive the Classic and X-Addresses from testWallet +XAddress xAddress = AddressCodec.getInstance().classicAddressToXAddress(classicAddress, true) ``` #### Private Key References (`PrivateKeyReference`) @@ -183,12 +190,13 @@ The following example illustrates how to construct a payment transaction, sign i then submit that transaction to the XRP Ledger for processing and validation: ```java -import org.xrpl.xrpl4j.crypto.core.keys.Seed; -import org.xrpl.xrpl4j.crypto.core.keys.KeyPair; -import org.xrpl.xrpl4j.crypto.core.keys.PrivateKey; -import org.xrpl.xrpl4j.crypto.core.keys.PublicKey; +import org.xrpl.xrpl4j.crypto.keys.Seed; +import org.xrpl.xrpl4j.crypto.keys.KeyPair; +import org.xrpl.xrpl4j.crypto.keys.PrivateKey; +import org.xrpl.xrpl4j.crypto.keys.PublicKey; import org.xrpl.xrpl4j.model.transactions.Address; -import org.xrpl.xrpl4j.crypto.core.signing.SignatureService; + +import org.xrpl.xrpl4j.crypto.signing.SignatureService; import org.xrpl.xrpl4j.crypto.signing.bc.BcSignatureService; // Construct a SignatureService that uses in-memory Keys (see SignatureService.java for alternatives). @@ -200,6 +208,11 @@ PrivateKey senderPrivateKey = senderSeed.derivePrivateKey(); PublicKey senderPublicKey = senderPrivateKey.derivePublicKey(); Address senderAddress = senderPublicKey.deriveAddress(); +KeyPair pair = Seed.ed25519Seed().deriveKeyPair(); // <-- Generate Key Pair from random seed; +PublicKey pubKey = pair.publicKey(); // <-- Public key from KeyPair +PrivateKey privKey = pair.privateKey() // <-- Private key from KeyPair +Address classicAddress = pubKey.deriveAddress(); + // Receiver (using secp256k1 key) Address receiverAddress = Address.of("r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59"); From ac50b25c4bfa2a95eefaa96e4157d1a97b71913a Mon Sep 17 00:00:00 2001 From: Try-Parser Date: Mon, 23 Oct 2023 22:44:20 +0800 Subject: [PATCH 2/4] Update README.md Co-authored-by: nkramer44 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a6b87acc9..ffc45813e 100644 --- a/README.md +++ b/README.md @@ -152,8 +152,8 @@ import org.xrpl.xrpl4j.codec.addresses.AddressCodec; Seed seed = Seed.ed25519Seed(); // <-- Generates a random seed. KeyPair pair = seed.deriveKeyPair(); // <-- Derive a key pair from seed; -PublicKey pubKey = pair.publicKey(); // <-- Public key from KeyPair -PrivateKey privKey = pair.privateKey() // <-- Private key from KeyPair +PublicKey publicKey = pair.publicKey(); // <-- Public key from KeyPair +PrivateKey privateKey = pair.privateKey() // <-- Private key from KeyPair // Classic Addresss Address classicAddress = pubKey.deriveAddress(); From 5a44330558300fbe457b0ff246916526432b770f Mon Sep 17 00:00:00 2001 From: Try-Parser Date: Mon, 23 Oct 2023 22:44:27 +0800 Subject: [PATCH 3/4] Update README.md Co-authored-by: nkramer44 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ffc45813e..a2ac081a3 100644 --- a/README.md +++ b/README.md @@ -155,7 +155,7 @@ KeyPair pair = seed.deriveKeyPair(); // <-- Derive a key pair from seed; PublicKey publicKey = pair.publicKey(); // <-- Public key from KeyPair PrivateKey privateKey = pair.privateKey() // <-- Private key from KeyPair -// Classic Addresss +// Classic Address Address classicAddress = pubKey.deriveAddress(); // Derive the Classic and X-Addresses from testWallet XAddress xAddress = AddressCodec.getInstance().classicAddressToXAddress(classicAddress, true) From 22b1f7540c69def4019cd54a1d595aab646cb23e Mon Sep 17 00:00:00 2001 From: Try-Parser Date: Mon, 23 Oct 2023 22:44:35 +0800 Subject: [PATCH 4/4] Update README.md Co-authored-by: nkramer44 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a2ac081a3..72c9e47c1 100644 --- a/README.md +++ b/README.md @@ -156,7 +156,7 @@ PublicKey publicKey = pair.publicKey(); // <-- Public key from KeyPair PrivateKey privateKey = pair.privateKey() // <-- Private key from KeyPair // Classic Address -Address classicAddress = pubKey.deriveAddress(); +Address classicAddress = publicKey.deriveAddress(); // Derive the Classic and X-Addresses from testWallet XAddress xAddress = AddressCodec.getInstance().classicAddressToXAddress(classicAddress, true) ```