XrpSigner.fromKeyBytes constructor
XrpSigner.fromKeyBytes(
- List<
int> keyBytes, - EllipticCurveTypes curve
Factory method to create an XrpSigner instance from key bytes and curve type.
This factory method takes a list of key bytes keyBytes
and an EllipticCurveTypes curve
as input and returns a new XrpSigner instance based on the specified curve type and key bytes.
keyBytes
The bytes representing the private key.
curve
The elliptic curve type of the private key.
returns An instance of XrpSigner initialized with the provided key bytes and curve type.
Implementation
factory XrpSigner.fromKeyBytes(List<int> keyBytes, EllipticCurveTypes curve) {
switch (curve) {
case EllipticCurveTypes.ed25519:
// Create an EDDSA private key from the key bytes using the ED25519 curve.
final signingKey = EDDSAPrivateKey(
_XrpSignerConst.ed25519Generator, keyBytes, () => SHA512());
return XrpSigner._(signingKey, null);
case EllipticCurveTypes.secp256k1:
// Create an ECDSA private key from the key bytes using the SECP256K1 curve.
final signingKey =
ECDSAPrivateKey.fromBytes(keyBytes, _XrpSignerConst.secp256);
return XrpSigner._(null, EcdsaSigningKey(signingKey));
default:
// Throw an error if the curve type is not supported.
throw MessageException(
"xrp signer support ${EllipticCurveTypes.secp256k1.name} or ${EllipticCurveTypes.ed25519} private key");
}
}