import { Buffer } from 'node:buffer'; import { createHash, generateKeyPairSync, sign } from 'node:crypto'; export function signedFixture(bytes) { const { publicKey, privateKey } = generateKeyPairSync('ed25519'); const keyId = Buffer.alloc(8, 7); const key = Buffer.concat([ Buffer.from('Ed'), keyId, publicKey.export({ type: 'spki', format: 'der' }).subarray(-32), ]); const signature = sign( null, createHash('blake2b512').update(bytes).digest(), privateKey, ); const trusted = 'timestamp:123456'; const globalSignature = sign( null, Buffer.concat([signature, Buffer.from(trusted)]), privateKey, ); return { publicKey: Buffer.from( `untrusted comment: test\n${key.toString('base64')}\n`, ).toString('base64'), signature: Buffer.from( `untrusted comment: test\n${Buffer.concat([Buffer.from('ED'), keyId, signature]).toString('base64')}\ntrusted comment: ${trusted}\n${globalSignature.toString('base64')}\n`, ).toString('base64'), }; }