You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1.8 KiB
35 lines
1.8 KiB
#!/usr/bin/env node
|
|
// Writes, as JSON, tlock ciphertexts made by the TypeScript library of this
|
|
// repository, for scripts/tlock-go-vectors.go to open with the Go reference
|
|
// (plan of phase 2, section 8, points 4 and 5):
|
|
//
|
|
// - IBE: a random 16-byte file key encrypted with encryptOnG2RFC9380 for
|
|
// rounds 1000 and 1001 of Quicknet, as the tlock stanza body U || V || W;
|
|
// - age: an age file whose only stanza timeRecipient wrote, through the
|
|
// Encrypter of age-encryption, for rounds 1000 and 1001.
|
|
//
|
|
// The randomness makes every run different: the output is generated once and
|
|
// frozen, with the verdicts of Go, in src/lib/dkc/testing/tlock-vectors.json.
|
|
// Node runs the TypeScript sources directly (type stripping, Node 22.6+):
|
|
//
|
|
// node scripts/tlock-ts-samples.mjs > ts-samples.json
|
|
|
|
import { Encrypter } from 'age-encryption';
|
|
import { ciphertextToBody, encryptOnG2RFC9380, roundIdentity } from '../src/lib/dkc/ibe.ts';
|
|
import { quicknet } from '../src/lib/dkc/profile.ts';
|
|
import { timeRecipient } from '../src/lib/dkc/tlock.ts';
|
|
|
|
const hex = (b) => Buffer.from(b).toString('hex');
|
|
const p = quicknet();
|
|
const samples = [];
|
|
for (const round of [1000, 1001]) {
|
|
const fileKey = crypto.getRandomValues(new Uint8Array(16));
|
|
const body = ciphertextToBody(encryptOnG2RFC9380(p.publicKey, roundIdentity(round), fileKey));
|
|
samples.push({ name: `IBE, round ${round}`, kind: 'ibe', round, file_key: hex(fileKey), body: hex(body) });
|
|
const e = new Encrypter();
|
|
e.addRecipient(timeRecipient(p, round));
|
|
const plaintext = new TextEncoder().encode(`DateKeys: sealed by the TypeScript library for round ${round}`);
|
|
samples.push({ name: `age file, round ${round}`, kind: 'age', round, plaintext: hex(plaintext), file: hex(await e.encrypt(plaintext)) });
|
|
}
|
|
process.stdout.write(`${JSON.stringify({ generator: 'scripts/tlock-ts-samples.mjs', samples }, null, 1)}\n`);
|