What is ripple-keypairs?
The ripple-keypairs npm package is a library for generating and managing cryptographic key pairs used in the Ripple (XRP) ecosystem. It provides functionalities for creating keys, deriving addresses, and signing/verifying messages, which are essential for interacting with the Ripple network.
What are ripple-keypairs's main functionalities?
Generate a new key pair
This feature allows you to generate a new cryptographic key pair consisting of a public and private key. The code sample demonstrates how to use the `generateKeypair` function to create a new key pair.
const rippleKeypairs = require('ripple-keypairs');
const keypair = rippleKeypairs.generateKeypair();
console.log(keypair);
Derive address from public key
This feature allows you to derive a Ripple address from a given public key. The code sample shows how to use the `deriveAddress` function to obtain the address associated with a public key.
const rippleKeypairs = require('ripple-keypairs');
const publicKey = 'yourPublicKeyHere';
const address = rippleKeypairs.deriveAddress(publicKey);
console.log(address);
Sign a message
This feature enables you to sign a message using a private key. The code sample demonstrates how to use the `sign` function to create a cryptographic signature for a message.
const rippleKeypairs = require('ripple-keypairs');
const privateKey = 'yourPrivateKeyHere';
const message = 'yourMessageHere';
const signature = rippleKeypairs.sign(message, privateKey);
console.log(signature);
Verify a signature
This feature allows you to verify a signature using a public key. The code sample shows how to use the `verify` function to check if a signature is valid for a given message and public key.
const rippleKeypairs = require('ripple-keypairs');
const message = 'yourMessageHere';
const signature = 'yourSignatureHere';
const publicKey = 'yourPublicKeyHere';
const isValid = rippleKeypairs.verify(message, signature, publicKey);
console.log(isValid);
Other packages similar to ripple-keypairs
ripple-lib
ripple-lib is a comprehensive library for interacting with the Ripple network. It includes functionalities for key pair generation, signing, and verifying, similar to ripple-keypairs, but also provides additional features for connecting to the Ripple network, submitting transactions, and more. It is a more extensive library compared to ripple-keypairs, which focuses specifically on key management.
stellar-sdk
stellar-sdk is a library for interacting with the Stellar network, which is similar to Ripple. It provides functionalities for key pair generation, signing, and verifying, akin to ripple-keypairs, but is tailored for the Stellar ecosystem. While it serves a different blockchain, the cryptographic principles are similar, making it a comparable tool for developers working with Stellar.
ripple-keypairs
An implementation of XRP Ledger keypairs & wallet generation using
elliptic which supports rfc6979 and
eddsa deterministic signatures.
API Methods
generateSeed({entropy?: Array<integer>, algorithm?: string}) -> string
Generate a seed that can be used to generate keypairs. Entropy can be provided as an array of bytes expressed as integers in the range 0-255. If provided, it must be 16 bytes long (additional bytes are ignored). If not provided, entropy will be automatically generated. The "algorithm" defaults to "ecdsa-secp256k1", but can also be set to "ed25519". The result is a seed encoded in base58, starting with "s".
deriveKeypair(seed: string) -> {privateKey: string, publicKey: string}
Derive a public and private key from a seed. The keys are represented as 33-byte hexadecimal strings.
sign(messageHex: string, privateKey: string) -> string
Sign an arbitrary hex-encoded message with a private key. Returns the signature as a hexadecimal string.
verify(messageHex: string, signature: string, publicKey: string) -> boolean
Verify a signature for a given hex-encoded message and public key. Returns true if the signature is valid, false otherwise.
deriveAddress(publicKey: string) -> string
Derive an XRP Ledger classic address from a public key.
deriveNodeAddress(publicKey: string) -> string
Derive a node address from a public key.
Generate a random XRP Ledger address
const seed = generateSeed();
const keypair = deriveKeypair(seed);
const address = deriveAddress(keypair.publicKey);