Skip to content

Commit 98b3f5d

Browse files
Merge branch 'v0.1.x'
2 parents c42a105 + eea36a1 commit 98b3f5d

27 files changed

+2123
-18
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [v0.1.6]
99

10+
### Added
11+
12+
#### xrpl
13+
14+
- Configurable timeout for the RPC client. New default timeout of 5 seconds instead of 1 second.
15+
1016
### Fixed
1117

1218
#### xrpl
1319

1420
- Updates some fields in AccountSet and Payment related transactions to a pointer to allow 0 or "" values. For example:
21+
1522
- `DestinationTag`
1623
- `TickSize`
1724
- `Domain`
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
---
22
sidebar_position: 4
3-
---
3+
---
File renamed without changes.

docs/docs/installation.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
sidebar_position: 2
3+
---
4+
5+
# Installation
6+
7+
On this page, you'll learn how to set up `xrpl-go` SDK in your project, to start interacting with the XRP Ledger.
8+
9+
## Prerequisites
10+
11+
Before installing, you need to have Go installed on your machine. You can download it from the [official website](https://go.dev/doc/install).
12+
13+
The minimum version of Go required to use `xrpl-go` is:
14+
15+
| Software | Version |
16+
|------------|---------|
17+
| Go | >= 1.22 |
18+
| Go toolchain | >= 1.22.5 |
19+
20+
## Download package
21+
22+
Once you have Go installed and you have a Go workspace, you can download the package with the following command:
23+
24+
```bash
25+
go get github.com/Peersyst/xrpl-go
26+
```
27+
28+
By running this command, the latest version of the `xrpl-go` package will be downloaded and added to your Go workspace.
29+
30+
## Import and start using the SDK
31+
32+
Once you have the package downloaded, you can import any `xrpl-go` package in your project and start working with it.
33+
The following example shows how to import the `xrpl` package and create a new WebSocket client to connect to the XRPL testnet chain:
34+
35+
```go
36+
package main
37+
38+
import (
39+
"fmt"
40+
41+
"github.com/Peersyst/xrpl-go/xrpl/faucet"
42+
"github.com/Peersyst/xrpl-go/xrpl/websocket"
43+
)
44+
45+
func main() {
46+
client := websocket.NewClient(
47+
websocket.NewClientConfig().
48+
WithHost("wss://s.altnet.rippletest.net:51233").
49+
WithFaucetProvider(faucet.NewTestnetFaucetProvider()),
50+
)
51+
defer client.Disconnect()
52+
53+
if err := client.Connect(); err != nil {
54+
fmt.Println(err)
55+
return
56+
}
57+
}
58+
```
59+
60+
## Next steps
61+
62+
Now that you have the `xrpl-go` package downloaded and imported in your project, you can start interacting with the XRP Ledger.
63+
64+
To learn more about the `xrpl-go` packages, you can find the documentation for each package in the [packages](/docs/category/packages) category.

docs/docs/intro.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,21 @@ sidebar_position: 1
44

55
# Introduction
66

7-
Here you can find the documentation for the packages of the XRPL Go project.
7+
This documentation englobes the `xrpl-go` project, a Go SDK for interacting with the XRP Ledger.
8+
9+
## What is the XRP Ledger?
10+
11+
The XRP Ledger (XRPL) is a decentralized, open-source blockchain optimized for fast, low-cost transactions and financial applications. It enables tokenization and seamless cross-border payments without intermediaries.
12+
13+
To learn more about the XRP Ledger, you can visit the [official website](https://xrpl.org/).
14+
15+
## What is xrpl-go?
16+
17+
The [`xrpl-go`](https://github.com/Peersyst/xrpl-go) project is an SDK written in Go for interacting with the XRP Ledger. It provides a set of tools and libraries for building applications on the XRP Ledger.
18+
19+
The SDK can be split into the following packages:
20+
21+
- [`binary-codec`](packages/binary-codec.md): A package for encoding and decoding XRPL binary messages, objects and transactions.
22+
- [`address-codec`](packages/address-codec.md): A package for encoding and decoding XRPL addresses.
23+
- [`keypairs`](packages/keypairs.md): A package for generating and managing cryptographic keypairs.
24+
- [`xrpl`](packages/xrpl.md): The biggest package of the SDK. It contains clients, types, transactions, and utils to interact with the XRP Ledger.

docs/docs/keypairs.md

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
---
2+
sidebar_position: 5
3+
---
4+
5+
# keypairs
6+
7+
## Introduction
8+
9+
The keypairs package provides a set of functions for generating and managing cryptographic keypairs. It includes functionality for creating new keypairs, deriving public keys from private keys, and verifying signatures.
10+
11+
This package is used internally by the [`xrpl`](./xrpl.md) package to expose a `Wallet`[Afegir link] interface for easier wallet management. Nevertheless, it can be used independently from the [`xrpl`](./xrpl.md) package for cryptographic operations.
12+
13+
## Key components
14+
15+
This package works with the following key components from the XRP Ledger:
16+
17+
- **Seed**: A base58-encoded string that represents a keypair.
18+
- **Keypair**: A pair of a private and public key.
19+
- **Address**: A base58-encoded string that represents an account.
20+
21+
To learn more about these components, you can check the [official documentation](https://xrpl.org/docs/concepts/accounts/cryptographic-keys).
22+
23+
## Supported algorithms
24+
25+
Cryptographic algorithms supported by this package are:
26+
27+
- ed25519
28+
- secp256k1
29+
30+
Every function in the package that requires a cryptographic algorithm will accept any type that satisfies the `KeypairCryptoAlg` interface. So, if desired, you can implement your own algorithm and use it in this package.
31+
32+
However, the library already exports both algorithm getters that satisfy the `KeypairCryptoAlg` and `NodeDerivationCryptoAlg` interfaces. They're available under the package `github.com/Peersyst/xrpl-go/pkg/crypto`, which exports both algorithm getters that satisfy the `KeypairCryptoAlg`, `NodeDerivationCryptoAlg` interfaces.
33+
34+
### crypto package
35+
36+
The `crypto` package exports the following algorithm getters that satisfy the `KeypairCryptoAlg`, `NodeDerivationCryptoAlg` interfaces:
37+
38+
- `ED25519()`
39+
- `SECP256K1()`
40+
41+
You can use them to generate a seed or derive a keypair as the following example shows:
42+
43+
```go
44+
seed, err := keypairs.GenerateSeed("", crypto.SECP256K1(), random.NewRandomizer())
45+
```
46+
47+
## API
48+
49+
These are the functions available in this package:
50+
51+
```go
52+
// Key generation
53+
func GenerateSeed(entropy string, alg interfaces.KeypairCryptoAlg, r interfaces.Randomizer) (string, error)
54+
func DeriveKeypair(seed string, validator bool) (private, public string, err error)
55+
func DeriveClassicAddress(pubKey string) (string, error)
56+
func DeriveNodeAddress(pubKey string, alg interfaces.NodeDerivationCryptoAlg) (string, error)
57+
58+
// Signing
59+
func Sign(msg, privKey string) (string, error)
60+
func Validate(msg, pubKey, sig string) (bool, error)
61+
```
62+
63+
They can be split into two groups:
64+
65+
- Key generation: Functions that generate seeds and addresses.
66+
- Signing: Functions that sign and validate messages.
67+
68+
### Key generation
69+
70+
#### GenerateSeed
71+
72+
```go
73+
func GenerateSeed(entropy string, alg interfaces.KeypairCryptoAlg, r interfaces.Randomizer) (string, error)
74+
```
75+
76+
Generate a seed that can be used to generate keypairs. You can specify the entropy, of the seed or let the function generate a random one (by passing an empty string as entropy and providing a randomizer) and use one of the [supported algorithms][afegir link] the provided algorithm to generate the seed. The result is a base58-encoded seed, which starts with the character `s`.
77+
78+
:::info
79+
80+
A randomizer satisfies the `Randomizer` interface. The `random` package exports a `NewRandomizer` function that returns a new randomizer.
81+
82+
:::
83+
84+
#### DeriveKeypair
85+
86+
```go
87+
func DeriveKeypair(seed string, validator bool) (private, public string, err error)
88+
```
89+
90+
Derives a keypair (private and public keys) from a seed. If the `validator` parameter is `true`, the keypair will be a validator keypair; otherwise, it will be a user keypair. The result for both the private and public keys is a 33-byte hexadecimal string.
91+
92+
93+
#### DeriveClassicAddress
94+
95+
```go
96+
func DeriveClassicAddress(pubKey string) (string, error)
97+
```
98+
99+
After deriving a keypair, you can derive the classic address from the public key. The result is a base58 encoded address, which starts with the character `r`. If you're interested in X-Address derivation, [`address-codec`](./address-codec.md) package contains functions to encode and decode X-Addresses from and to classic addresses.
100+
101+
#### DeriveNodeAddress
102+
103+
```go
104+
func DeriveNodeAddress(pubKey string, alg interfaces.NodeDerivationCryptoAlg) (string, error)
105+
```
106+
107+
Derives a node address from a public key. The result is a base58-encoded address, which starts with the character `n`.
108+
109+
### Signing
110+
111+
#### Sign
112+
113+
```go
114+
func Sign(msg, privKey string) (string, error)
115+
```
116+
117+
Signs the provided message with the provided private key. To be able to sign a message, the private key must be a valid keypair and the message must be hex-encoded. The result is a hexadecimal string that represents the signature of the message. To verify the signature, you can use the `Validate` function.
118+
119+
#### Validate
120+
121+
```go
122+
func Validate(msg, pubKey, sig string) (bool, error)
123+
```
124+
125+
Verifies a signature of a message. To be able to verify a signature, the public key must be valid, and the message and the signature must be hex-encoded. The result is a boolean value that indicates if the signature is valid or not.
126+
127+
## Guides
128+
129+
### How to generate a new random keypair
130+
131+
This example generates a new keypair using the `SECP256K1` algorithm and a random entropy. It then derives a keypair from the seed and derives the classic address from the public key.
132+
133+
```go
134+
package main
135+
136+
import (
137+
"fmt"
138+
"log"
139+
140+
"github.com/Peersyst/xrpl-go/keypairs"
141+
"github.com/Peersyst/xrpl-go/pkg/crypto"
142+
"github.com/Peersyst/xrpl-go/pkg/random"
143+
)
144+
145+
func main() {
146+
seed, err := keypairs.GenerateSeed("", crypto.SECP256K1(), random.NewRandomizer())
147+
if err != nil {
148+
log.Fatal(err)
149+
}
150+
151+
privK, pubK, err := keypairs.DeriveKeypair(seed, false)
152+
if err != nil {
153+
log.Fatal(err)
154+
}
155+
156+
addr, err := keypairs.DeriveClassicAddress(pubK)
157+
if err != nil {
158+
log.Fatal(err)
159+
}
160+
161+
fmt.Println("Seed: ", seed)
162+
fmt.Println("Private Key: ", privK)
163+
fmt.Println("Public Key: ", pubK)
164+
fmt.Println("Address: ", addr)
165+
}
166+
```
167+
168+
169+
### How to generate a new keypair from entropy
170+
171+
This example generates a new keypair using the `ED25519` algorithm and a provided entropy. Then, it derives the keypair and the address as the previous example.
172+
173+
```go
174+
package main
175+
176+
import (
177+
"fmt"
178+
"log"
179+
180+
"github.com/Peersyst/xrpl-go/keypairs"
181+
"github.com/Peersyst/xrpl-go/pkg/crypto"
182+
)
183+
184+
func main() {
185+
seed, err := keypairs.GenerateSeed("ThisIsMyCustomEntropy", crypto.ED25519(), nil)
186+
if err != nil {
187+
log.Fatal(err)
188+
}
189+
190+
privK, pubK, err := keypairs.DeriveKeypair(seed, false)
191+
if err != nil {
192+
log.Fatal(err)
193+
}
194+
195+
addr, err := keypairs.DeriveClassicAddress(pubK)
196+
197+
fmt.Println("Seed: ", seed)
198+
fmt.Println("Private Key: ", privK)
199+
fmt.Println("Public Key: ", pubK)
200+
fmt.Println("Address: ", addr)
201+
}
202+
```

docs/docs/packages/_category_.json

Lines changed: 0 additions & 8 deletions
This file was deleted.

docs/docs/packages/address-codec.md

Lines changed: 0 additions & 4 deletions
This file was deleted.

docs/docs/packages/binary-codec.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

docs/docs/xrpl/_category_.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"label": "xrpl",
3+
"position": 6,
4+
"link": {
5+
"description": "Here you can find the documentation for the xrpl package, including its subpackages."
6+
}
7+
}

0 commit comments

Comments
 (0)