Ed25519ProgramLayout.fromPublicKey constructor

Ed25519ProgramLayout.fromPublicKey({
  1. required SolanaPublicKey publicKey,
  2. required List<int> message,
  3. required List<int> signature,
  4. int? instructionIndex,
})

Create an ed25519 instruction with a public key and signature. the signature must be a buffer of 64 bytes.

Implementation

factory Ed25519ProgramLayout.fromPublicKey({
  required SolanaPublicKey publicKey,
  required List<int> message,
  required List<int> signature,
  int? instructionIndex,
}) {
  if (signature.length != Ed25519ProgramConst.signatureLen) {
    throw SolanaPluginException("invalid signature length.", details: {
      "Excepted": Ed25519ProgramConst.signatureLen,
      "length": signature.length
    });
  }
  final int index = instructionIndex ?? mask16;
  final publicKeyOffset = _layout.span;
  final signatureOffset = publicKeyOffset + publicKey.toBytes(false).length;
  final messageDataOffset = signatureOffset + signature.length;

  return Ed25519ProgramLayout._(
    numSignatures: 1,
    padding: 0,
    signatureOffset: signatureOffset,
    signatureInstructionIndex: index,
    publicKeyOffset: publicKeyOffset,
    publicKeyInstructionIndex: index,
    messageDataOffset: messageDataOffset,
    messageDataSize: message.length,
    messageInstructionIndex: index,
    publicKey: publicKey,
    message: message,
    signature: signature,
  );
}