Skip to content

Commit

Permalink
Update README.md to fix example
Browse files Browse the repository at this point in the history
  • Loading branch information
sappenin committed Nov 3, 2023
1 parent 7f40733 commit d8a68d4
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,17 @@ 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.KeyPair;
import org.xrpl.xrpl4j.crypto.keys.PrivateKey;
import org.xrpl.xrpl4j.crypto.keys.PublicKey;
import org.xrpl.xrpl4j.crypto.keys.Seed;
import org.xrpl.xrpl4j.model.transactions.Address;

...

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.
Seed seed = Seed.ed25519Seed(); // <-- Generates a random seed.
KeyPair keyPair = seed.deriveKeyPair(); // <-- Derive a KeyPair from the seed.
PrivateKey privateKey = keyPair.privateKey(); // <-- Derive a privateKey from the KeyPair.
PublicKey publicKey = keyPair.publicKey(); // <-- Derive a publicKey from the KeyPair.
Address address = publicKey.deriveAddress(); // <-- Derive an address from the publicKey
```

#### Private Key References (`PrivateKeyReference`)
Expand Down Expand Up @@ -183,23 +183,24 @@ 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.client.XrplClient;
import org.xrpl.xrpl4j.crypto.keys.PrivateKey;
import org.xrpl.xrpl4j.crypto.keys.Seed;
import org.xrpl.xrpl4j.crypto.signing.SignatureService;
import org.xrpl.xrpl4j.crypto.signing.SingleSignedTransaction;
import org.xrpl.xrpl4j.model.client.transactions.SubmitResult;
import org.xrpl.xrpl4j.model.transactions.Address;
import org.xrpl.xrpl4j.crypto.core.signing.SignatureService;

import org.xrpl.xrpl4j.crypto.signing.bc.BcSignatureService;
import org.xrpl.xrpl4j.model.transactions.Payment;

// Construct a SignatureService that uses in-memory Keys (see SignatureService.java for alternatives).
SignatureService signatureService = new BcSignatureService();

// Sender (using ed25519 key)
Seed senderSeed = Seed.ed255519Seed();
PrivateKey senderPrivateKey = senderSeed.derivePrivateKey();
PublicKey senderPublicKey = senderPrivateKey.derivePublicKey();
Address senderAddress = senderPublicKey.deriveAddress();

Seed seed = Seed.ed25519Seed(); // <-- Generates a random seed.
PrivateKey senderPrivateKey = seed.deriveKeyPair().privateKey();

// Receiver (using secp256k1 key)
Address receiverAddress = Address.of("r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59");

Expand All @@ -208,15 +209,15 @@ Payment payment = ...; // See V3 ITs for examples.

SingleSignedTransaction<Payment> signedTransaction = signatureService.sign(sourcePrivateKey,payment);
SubmitResult<Payment> result = xrplClient.submit(signedTransaction);
assertThat(result.result()).isEqualTo("tesSUCCESS");
assert result.engineResult().equals("tesSUCCESS");
```

### Codecs
This library relies upon two important sub-modules called Codecs (One for the XRPL binary encoding, and one for XRPL
canonical JSON encoding). Read more about each here:

- [Binary Codec](https://github.com/XRPLF/xrpl4j/tree/main/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/codec/binary/README.md)
- [Address Coded](https://github.com/XRPLF/xrpl4j/tree/main/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/codec/addresses/README.md)
- [Address Codec](https://github.com/XRPLF/xrpl4j/tree/main/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/codec/addresses/README.md)

## Development

Expand Down

0 comments on commit d8a68d4

Please sign in to comment.