encodeKey method
String
encodeKey(
- List<
int> pubKey, { - XlmAddrTypes addrType = XlmAddrTypes.pubKey,
- BigInt? muxedId,
override
Encode a Stellar (XLM) public key as a Stellar address.
Implementation
@override
String encodeKey(
List<int> pubKey, {
XlmAddrTypes addrType = XlmAddrTypes.pubKey,
BigInt? muxedId,
}) {
if (pubKey.length ==
Ed25519KeysConst.pubKeyByteLen + Ed25519KeysConst.pubKeyPrefix.length) {
pubKey = pubKey.sublist(1);
}
AddrDecUtils.validateBytesLength(pubKey, Ed25519KeysConst.pubKeyByteLen);
if (addrType == XlmAddrTypes.pubKey) {
AddrKeyValidator.validateAndGetEd25519Key(pubKey);
} else if (addrType == XlmAddrTypes.privKey) {
Ed25519PrivateKey.fromBytes(pubKey);
}
if (addrType == XlmAddrTypes.muxed) {
if (muxedId == null ||
muxedId > BinaryOps.maxU64 ||
muxedId < BigInt.zero) {
throw AddressConverterException.missingOrInvalidAddressArguments(
reason: "muxedId is required for a muxed address.",
);
}
final idBytes = BigintUtils.toBytes(
muxedId,
length: XlmAddrConst.muxedIdLength,
);
pubKey = [...pubKey, ...idBytes];
}
final List<int> payloadBytes = [addrType.value, ...pubKey];
final List<int> checksumBytes = _XlmAddrUtils.computeChecksum(payloadBytes);
return Base32Encoder.encodeNoPaddingBytes([
...payloadBytes,
...checksumBytes,
]);
}