From 87450cb656232f09bf7956b81006fd6a3ff45c62 Mon Sep 17 00:00:00 2001 From: Il Harper Date: Wed, 6 Mar 2024 13:19:54 +0800 Subject: [PATCH] chore: add dti script --- scripts/dti.cts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 scripts/dti.cts diff --git a/scripts/dti.cts b/scripts/dti.cts new file mode 100644 index 0000000..63c91e2 --- /dev/null +++ b/scripts/dti.cts @@ -0,0 +1,23 @@ +import type { Buffer } from 'node:buffer' +import { verify } from 'node:crypto' +import { readFile } from 'node:fs/promises' +import { resolve } from 'node:path' +import { argv } from 'node:process' + +const checkScript = (key: Buffer, rawFile: Buffer) => + new Promise((res, rej) => { + const partSig = rawFile.subarray(0, 1024) + const partData = rawFile.subarray(1024) + + verify('sha256', partData, key, partSig, (e, r) => + e ? rej(e) : r ? res(partData) : rej(new Error('Check failed.')), + ) + }) + +void (async () => { + const key = await readFile( + resolve(__dirname, '../packages/docs/static/ti.pub'), + ) + const rawFile = await readFile(argv[2]!) + await checkScript(key, rawFile) +})()