function encode(signature, hashType) {
  v.parse(
    v.object({
      signature: NBufferSchemaFactory(64),
      hashType: UInt8Schema,
    }),
    { signature, hashType },
  );
  if (!isDefinedHashType(hashType)) {
    throw new Error('Invalid hashType ' + hashType);
  }
  const hashTypeBuffer = new Uint8Array(1);
  tools.writeUInt8(hashTypeBuffer, 0, hashType);
  const r = toDER(signature.slice(0, 32));
  const s = toDER(signature.slice(32, 64));
  return tools.concat([bip66.encode(r, s), hashTypeBuffer]);
}
Encodes a signature and hash type into a buffer.
@param signature - The signature to encode.
@param hashType - The hash type to encode.
@returns The encoded buffer.
@throws Error if the hashType is invalid.