Ed25519ProgramLayout.fromBuffer constructor

Ed25519ProgramLayout.fromBuffer(
  1. List<int> data
)

Constructs the layout from raw bytes.

Implementation

factory Ed25519ProgramLayout.fromBuffer(List<int> data) {
  final decode =
      ProgramLayout.decodeAndValidateStruct(layout: _layout, bytes: data);
  final int publicKeyOffset = decode["publicKeyOffset"];
  final int signatureOffset = decode["signatureOffset"];
  final int messageOffset = decode["messageDataOffset"];
  final int messageSize = decode["messageDataSize"];
  final pubKey = data.sublist(
      publicKeyOffset, publicKeyOffset + Ed25519KeysConst.pubKeyByteLen);
  final signature = data.sublist(
      signatureOffset, signatureOffset + SolanaSignerConst.signatureLen);
  final message = data.sublist(messageOffset, messageOffset + messageSize);
  return Ed25519ProgramLayout._(
    numSignatures: decode["numSignatures"],
    padding: decode["padding"],
    signatureOffset: signatureOffset,
    signatureInstructionIndex: decode["signatureInstructionIndex"],
    publicKeyOffset: publicKeyOffset,
    publicKeyInstructionIndex: decode["publicKeyInstructionIndex"],
    messageDataOffset: messageOffset,
    messageDataSize: messageSize,
    messageInstructionIndex: decode["messageInstructionIndex"],
    message: message,
    publicKey: SolanaPublicKey.fromBytes(pubKey),
    signature: signature,
  );
}