Show / Hide Table of Contents

Class XrplKeypairs

Inheritance
object
XrplKeypairs
Namespace: Xrpl.Keypairs
Assembly: Xrpl.Keypairs.dll
Syntax
public static class XrplKeypairs

Methods

| Edit this page View Source

DeriveAddress(string)

Declaration
public static string DeriveAddress(string publicKey)
Parameters
Type Name Description
string publicKey
Returns
Type Description
string
| Edit this page View Source

DeriveAddressFromBytes(byte[])

Declaration
public static string DeriveAddressFromBytes(byte[] publicKeyBytes)
Parameters
Type Name Description
byte[] publicKeyBytes
Returns
Type Description
string
| Edit this page View Source

DeriveKeyBytes(ReadOnlySpan<byte>, string)

Derives an account's key pair from 16 bytes of entropy without encoding a seed string: the keys DeriveKeypair(string, string?, bool, int) derives from the seed that GenerateSeed(byte[]?, string) makes of the same entropy.

Declaration
public static (byte[] PrivateKey, byte[] PublicKey) DeriveKeyBytes(ReadOnlySpan<byte> entropy, string algorithm)
Parameters
Type Name Description
ReadOnlySpan<byte> entropy

The 16 bytes of seed entropy.

string algorithm

ed25519 or secp256k1.

Returns
Type Description
(byte[] PrivateKey, byte[] PublicKey)

The 33-byte private key in the XRPL form Sign(ReadOnlySpan<byte>, ReadOnlySpan<byte>) takes, and the 33-byte public key. The caller owns the private key array and should clear it.

Exceptions
Type Condition
ArgumentException

The entropy is not 16 bytes, or the algorithm is unknown.

| Edit this page View Source

DeriveKeypair(string, string?, bool, int)

Declaration
public static IXrplKeyPair DeriveKeypair(string seed, string? algorithm = null, bool validator = false, int index = 0)
Parameters
Type Name Description
string seed
string algorithm
bool validator
int index
Returns
Type Description
IXrplKeyPair
| Edit this page View Source

DerivePublicKey(ReadOnlySpan<byte>)

Derives the public key of a private key held as bytes.

Declaration
public static byte[] DerivePublicKey(ReadOnlySpan<byte> privateKey)
Parameters
Type Name Description
ReadOnlySpan<byte> privateKey

The 33-byte XRPL form of the key, as Sign(ReadOnlySpan<byte>, ReadOnlySpan<byte>) takes it.

Returns
Type Description
byte[]

The 33-byte public key: 0xED and the Ed25519 key, or a compressed secp256k1 point.

Exceptions
Type Condition
ArgumentException

The key is not 33 bytes, has an unknown prefix, or is a secp256k1 scalar of zero or not below the curve order.

| Edit this page View Source

DerivePublicKeyFromPrivateKey(string)

Derives the public key of a private key given as hex: ED and 32 bytes for Ed25519, otherwise a secp256k1 scalar (the 33-byte 00-prefixed form or the raw 32 bytes of a BIP-39 key).

Declaration
public static string DerivePublicKeyFromPrivateKey(string privateKey)
Parameters
Type Name Description
string privateKey

The private key, hex.

Returns
Type Description
string

The 33-byte public key, upper-case hex.

Exceptions
Type Condition
FormatException

privateKey is not hex.

ArgumentException

A secp256k1 key is zero, not below the curve order, or longer than 32 significant bytes.

| Edit this page View Source

FromRandom()

Generate random seed bytes for new account

Declaration
public static byte[] FromRandom()
Returns
Type Description
byte[]

byte seed array

| Edit this page View Source

GenerateSeed(byte[]?, string)

generate string seed from bytes array, if null - random

Declaration
public static string GenerateSeed(byte[]? entropy = null, string algorithm = "secp256k1")
Parameters
Type Name Description
byte[] entropy

seed byte array

string algorithm

seed algorithm, base - secp256k1

Returns
Type Description
string
| Edit this page View Source

GetAlgorithmFromKey(string)

get seed algorithm from seed key

Declaration
public static string GetAlgorithmFromKey(string key)
Parameters
Type Name Description
string key

seed key

Returns
Type Description
string
| Edit this page View Source

Sign(byte[], string)

Sing message

Declaration
public static string Sign(byte[] message, string privateKey)
Parameters
Type Name Description
byte[] message

byte array

string privateKey

private key

Returns
Type Description
string
| Edit this page View Source

Sign(ReadOnlySpan<byte>, ReadOnlySpan<byte>)

Signs message with a private key held as bytes, so the caller can wipe it after use; produces the same signature as Sign(byte[], string).

Declaration
public static byte[] Sign(ReadOnlySpan<byte> message, ReadOnlySpan<byte> privateKey)
Parameters
Type Name Description
ReadOnlySpan<byte> message

The message bytes; for secp256k1 the SHA-512Half of it is signed.

ReadOnlySpan<byte> privateKey

The 33-byte XRPL form of the key: 0xED followed by the 32-byte Ed25519 seed, or 0x00 followed by the 32-byte secp256k1 scalar.

Returns
Type Description
byte[]

The signature: 64 bytes for Ed25519, DER for secp256k1.

Remarks

Every buffer this method allocates for key material, the Ed25519 expanded key included, is cleared before it returns. secp256k1 signs on NBitcoin.Secp256k1, a port of libsecp256k1: the scalar and the RFC 6979 nonce are value types, cleared once the signature is made, never a heap BigInteger. A secp256k1 scalar of zero is refused, so a buffer the caller has already cleared (33 zero bytes, whose 0x00 prefix reads as secp256k1) never signs. What stays outside the SDK's reach is the state the hash implementations keep, including the HMAC-SHA256 that RFC 6979 runs.

Exceptions
Type Condition
ArgumentException

The key is not 33 bytes, has an unknown prefix, or is a secp256k1 scalar of zero or not below the curve order.

| Edit this page View Source

Sign(string, string)

Sing message

Declaration
public static string Sign(string HexMessage, string privateKey)
Parameters
Type Name Description
string HexMessage

Hex Message

string privateKey

private key

Returns
Type Description
string
| Edit this page View Source

Verify(byte[], string, string)

Declaration
public static bool Verify(byte[] message, string signature, string publicKey)
Parameters
Type Name Description
byte[] message
string signature
string publicKey
Returns
Type Description
bool
| Edit this page View Source

Verify(string, string, string)

Declaration
public static bool Verify(string HexMessage, string signature, string publicKey)
Parameters
Type Name Description
string HexMessage
string signature
string publicKey
Returns
Type Description
bool
  • Edit this page
  • View Source
In this article
Back to top Generated by DocFX