Class XrplKeypairs
Inheritance
Namespace: Xrpl.Keypairs
Assembly: Xrpl.Keypairs.dll
Syntax
public static class XrplKeypairs
Methods
| Edit this page View SourceDeriveAddress(string)
Declaration
public static string DeriveAddress(string publicKey)
Parameters
| Type | Name | Description |
|---|---|---|
| string | publicKey |
Returns
| Type | Description |
|---|---|
| string |
DeriveAddressFromBytes(byte[])
Declaration
public static string DeriveAddressFromBytes(byte[] publicKeyBytes)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | publicKeyBytes |
Returns
| Type | Description |
|---|---|
| string |
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 |
|
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. |
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 |
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: |
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. |
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 |
|
| ArgumentException | A secp256k1 key is zero, not below the curve order, or longer than 32 significant bytes. |
FromRandom()
Generate random seed bytes for new account
Declaration
public static byte[] FromRandom()
Returns
| Type | Description |
|---|---|
| byte[] | byte seed array |
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 |
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 |
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 |
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: |
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. |
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 |
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 |
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 |