import { k12 } from '@noble/hashes/sha3-addons'; import { publicKeyStringToBytes } from './AddressHelper'; export type BuildTransactionArgs = { targetTick: number, fromPublicKey: Buffer toAddress: string, amount: string, signature?: Buffer, } export function buildTransactionHelper(args: BuildTransactionArgs): Buffer{ // sender const sourcePublicKey = new Uint8Array(args.fromPublicKey); const destPublicKey = publicKeyStringToBytes(args.toAddress).slice(0, 32); const tx = new Uint8Array(144).fill(0); //TRANSACTION_SIZE const txView = new DataView(tx.buffer); // sourcePublicKey byte[] // 32 let offset = 0; let i = 0; let PUBLIC_KEY_LENGTH = 32; for (i = 0; i < PUBLIC_KEY_LENGTH; i++) { tx[i] = sourcePublicKey[i]; } offset = i; for (i = 0; i < PUBLIC_KEY_LENGTH; i++) { tx[offset + i] = destPublicKey[i]; } offset += i; txView.setBigInt64(offset, BigInt(args.amount), true); offset += 8; txView.setUint32(offset, args.targetTick, true); offset += 4; txView.setUint16(offset, 0, true); offset += 2; txView.setUint16(offset, 0, true); offset += 2; const toSign = tx.slice(0, offset); if(args.signature === undefined){ return Buffer.from(toSign); } const signedtx = new Uint8Array(args.signature); tx.set(signedtx, offset); offset += 64 //SIGNATURE_LENGTH; return Buffer.from(tx); } export function getHolaParameters_LINKHelper(args: BuildTransactionArgs): {blk: any[]} { let tx = buildTransactionHelper(args); let digest = Buffer.from(k12(tx)); let blkData = []; blkData.push(digest); return {blk: blkData}; }