Skip to content

Commit

Permalink
chore: add dti script
Browse files Browse the repository at this point in the history
  • Loading branch information
ilharp committed Mar 6, 2024
1 parent cdce410 commit 87450cb
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions scripts/dti.cts
Original file line number Diff line number Diff line change
@@ -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<Buffer>((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)
})()

0 comments on commit 87450cb

Please sign in to comment.