xrp-tx 0.2.0 โ 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +121 -0
- package/package.json +1 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jonathan Dobson
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# xrp-tx
|
|
2
|
+
|
|
3
|
+
A standalone, zero-dependency, class-based transaction builder for the XRP Ledger.
|
|
4
|
+
|
|
5
|
+
`xrp-tx` is designed to provide a premium developer experience for constructing, validating, and manipulating XRPL transactions. It replaces the legacy union-of-interfaces pattern with a robust class hierarchy, enabling inherited properties, logical grouping, and strict runtime validation.
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/xrp-tx)
|
|
8
|
+
[](https://opensource.org/licenses/MIT)
|
|
9
|
+
|
|
10
|
+
## Features
|
|
11
|
+
|
|
12
|
+
- **๐ Zero Dependencies:** No reliance on `xrpl.js`, `ripple-binary-codec`, or any other runtime libraries.
|
|
13
|
+
- **๐๏ธ Class-Based API:** 71+ transaction types implemented as concrete classes.
|
|
14
|
+
- **๐ก๏ธ Strict Type Safety:** Built from the ground up for TypeScript, supporting `exactOptionalPropertyTypes`.
|
|
15
|
+
- **๐งช Built-in Validation:** Every transaction class includes a `validate()` method for ledger-compliant checks.
|
|
16
|
+
- **๐ Immutable Updates:** Use the `.with()` pattern to create modified copies of transactions without side effects.
|
|
17
|
+
- **๐ Registry Pattern:** Easily instantiate transactions from JSON using the central registry or factory methods.
|
|
18
|
+
- **๐ค XRPL.js Compatible:** `toJSON()` output matches the exact shape required by `xrpl.js` and the XRPL ledger.
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install xrp-tx
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Quick Start
|
|
27
|
+
|
|
28
|
+
### Creating a Transaction
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
import { Transaction, PaymentTx } from 'xrp-tx';
|
|
32
|
+
|
|
33
|
+
// Option 1: Using the convenience factory
|
|
34
|
+
const tx = Transaction.payment({
|
|
35
|
+
Account: 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh',
|
|
36
|
+
Destination: 'rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe',
|
|
37
|
+
Amount: '1000000', // 1 XRP in drops
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// Option 2: Using the concrete class
|
|
41
|
+
const payment = new PaymentTx({
|
|
42
|
+
Account: 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh',
|
|
43
|
+
Destination: 'rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe',
|
|
44
|
+
Amount: '1000000',
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// Validation
|
|
48
|
+
payment.validate(); // Throws ValidationError if invalid
|
|
49
|
+
|
|
50
|
+
// Serialization
|
|
51
|
+
const json = payment.toJSON();
|
|
52
|
+
console.log(json);
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Immutable Updates with `.with()`
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
const tx1 = Transaction.payment({
|
|
59
|
+
Account: 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh',
|
|
60
|
+
Destination: 'rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe',
|
|
61
|
+
Amount: '1000000',
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// Create a new transaction with a Fee and Sequence
|
|
65
|
+
const tx2 = tx1.with({
|
|
66
|
+
Fee: '12',
|
|
67
|
+
Sequence: 42,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
console.log(tx2.Fee); // '12'
|
|
71
|
+
console.log(tx1.Fee); // undefined (tx1 remains unchanged)
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Dynamic Instantiation from JSON
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
import { Transaction } from 'xrp-tx';
|
|
78
|
+
|
|
79
|
+
const blob = {
|
|
80
|
+
TransactionType: 'AccountSet',
|
|
81
|
+
Account: 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh',
|
|
82
|
+
SetFlag: 8,
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const tx = Transaction.create(blob.TransactionType, blob);
|
|
86
|
+
// tx is an instance of AccountSetTx
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Supported Transaction Types (71)
|
|
90
|
+
|
|
91
|
+
`xrp-tx` provides 100% coverage for standard and experimental XRPL transaction types, including:
|
|
92
|
+
|
|
93
|
+
- **Core:** `Payment`, `AccountSet`, `TrustSet`, `OfferCreate`, `OfferCancel`, `Check*`, `Escrow*`, `SignerListSet`, etc.
|
|
94
|
+
- **NFTs:** `NFTokenMint`, `NFTokenBurn`, `NFTokenCreateOffer`, `NFTokenAcceptOffer`, etc.
|
|
95
|
+
- **AMM:** `AMMCreate`, `AMMDeposit`, `AMMWithdraw`, `AMMVote`, `AMMBid`, etc.
|
|
96
|
+
- **MPT:** `MPTokenIssuanceCreate`, `MPTokenAuthorize`, etc.
|
|
97
|
+
- **Sidechains:** `XChainCreateBridge`, `XChainCommit`, `XChainClaim`, etc.
|
|
98
|
+
- **Niche:** `Vault*`, `Loan*`, `Oracle*`, `Credential*`, `DID*`, `Batch`, etc.
|
|
99
|
+
|
|
100
|
+
## Why use xrp-tx?
|
|
101
|
+
|
|
102
|
+
Modern XRPL development often requires high-fidelity transaction construction without the overhead of a full ledger library. `xrp-tx` is ideal for:
|
|
103
|
+
|
|
104
|
+
1. **Lightweight Clients:** Perfect for mobile apps or edge functions where bundle size matters.
|
|
105
|
+
2. **Transaction Builders:** Provides a clean UI-to-JSON mapping with instant validation.
|
|
106
|
+
3. **Backend Services:** Robust, typed transaction generation for high-throughput environments.
|
|
107
|
+
4. **Tooling:** A solid foundation for explorers, wallets, and signing tools.
|
|
108
|
+
|
|
109
|
+
## Architecture
|
|
110
|
+
|
|
111
|
+
The library uses a structured hierarchy to maximize code reuse and provide logical groupings:
|
|
112
|
+
|
|
113
|
+
- `Transaction` (Abstract Base)
|
|
114
|
+
- `AccountTransaction` (Shared account logic)
|
|
115
|
+
- `PaymentTransaction` (Shared value transfer logic)
|
|
116
|
+
- `TokenTransaction` (NFT/MPT/TrustSet logic)
|
|
117
|
+
- `AMMTransaction` / `XChainTransaction` / etc.
|
|
118
|
+
|
|
119
|
+
## License
|
|
120
|
+
|
|
121
|
+
MIT
|