pkp-xrpl
is a modified version of the Wallet from xrpl.js
, designed specifically to work with PKP (Programmable Key Pair) wallets on the XRP Ledger (XRPL). It provides seamless integration between Lit Protocol's PKP system and XRPL transactions.
- Create and manage XRPL wallets using Lit Protocol's PKP system
- Sign XRPL transactions securely with PKP
- Support for both classic and X-addresses
- Seamless integration with
xrpl.js
library
Install pkp-xrpl
and its peer dependency xrpl
using npm, yarn, or pnpm:
npm install pkp-xrpl xrpl @lit-protocol/lit-node-client
# or
yarn add pkp-xrpl xrpl @lit-protocol/lit-node-client
# or
pnpm add pkp-xrpl xrpl @lit-protocol/lit-node-client
Here's a basic example of how to use pkp-xrpl
:
import { PKPXrplWallet } from 'pkp-xrpl';
import { LitNodeClient } from '@lit-protocol/lit-node-client';
import { Client } from 'xrpl';
async function main() {
// Initialize Lit Node Client
const litNodeClient = new LitNodeClient({ litNetwork: 'datil-dev' });
await litNodeClient.connect();
// Create PKPXrplWallet instance
const pkpWallet = new PKPXrplWallet({
controllerSessionSigs: sessionSigs, // Obtained from Lit login process
pkpPubKey: pkpPubKey, // Obtained from Lit login process
litNodeClient,
});
// Initialize the wallet
await pkpWallet.init();
console.log('Wallet classic address:', pkpWallet.classicAddress);
console.log('Wallet X-address:', pkpWallet.getXAddress());
// Connect to XRPL
const client = new Client('wss://s.altnet.rippletest.net:51233');
await client.connect();
// Now you can use pkpWallet and client for XRPL transactions
}
main().catch(console.error);
The main class for interacting with XRPL using a PKP wallet.
new PKPXrplWallet({
controllerSessionSigs: SessionSigs;
pkpPubKey: string;
litNodeClient: LitNodeClient;
})
publicKey: string
- The compressed public key of the PKP.classicAddress: string
- The classic address derived from the public key.address: string
- Alias forclassicAddress
.
init(): Promise<void>
- Initializes the wallet. This method is analogous toLitNodeClient.connect()
. Eitherinit()
orLitNodeClient.connect()
must be called before using other methodssign(transaction: Transaction, multisign?: boolean | string, definitions?: XrplDefinitions): Promise<{ tx_blob: string; hash: string }>
- Signs a transaction.getXAddress(tag?: number | false, isTestnet?: boolean): string
- Gets an X-address for the wallet.getAddress(): Promise<string>
- Returns the classic address of the wallet.runLitAction(toSign: Uint8Array, sigName: string): Promise<any>
- Runs a Lit Action to sign data.runSign(toSign: Uint8Array): Promise<SigResponse>
- Signs data using the PKP.
import { PKPXrplWallet } from 'pkp-xrpl';
import { Client, xrpToDrops } from 'xrpl';
async function sendPayment(pkpWallet: PKPXrplWallet, destination: string, amount: string) {
const client = new Client('wss://s.altnet.rippletest.net:51233');
await client.connect();
const prepared = await client.autofill({
TransactionType: 'Payment',
Account: pkpWallet.address,
Amount: xrpToDrops(amount),
Destination: destination,
});
const signed = await pkpWallet.sign(prepared);
const result = await client.submitAndWait(signed.tx_blob);
console.log('Transaction result:', result.result.meta.TransactionResult);
await client.disconnect();
}
// Usage
sendPayment(pkpWallet, 'rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe', '10').catch(console.error);
const xAddress = pkpWallet.getXAddress(12345, true); // With tag 12345, testnet
console.log('X-address:', xAddress);
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/something
) - Commit your changes (
git commit -m 'feat: add something'
) - Push to the branch (
git push origin feature/something
) - Open a Pull Request
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.