A TypeScript/JavaScript API client for Diskuto REST API.
Here's an example from this blog post of how to fetch and validate an Item
using this API client:
#!/usr/bin/env -S deno run --check -EN
const baseUrl = `https://blog.nfnitloop.com`
const userID = `A719rvsCkuN2SC5W2vz5hypDE2SpevNTUsEXrVFe9XQ7`
const signature = `4sVxU7pVvUenEdG41BYJDZJfDBZBjBkLSF7dcGzpGMgtVLbZjTh6w5LzC4Rwjkk5SNyn57o3cfsvEbsZJkFELaW3`
// Given these three things, we can validate that the content on the page
// was in fact created by that user, and has not been modified.
import {Client, Signature, UserID} from "jsr:@diskuto/[email protected]"
const client = new Client({baseUrl})
const bytes = await client.getItemBytes(userID, signature)
if (bytes == null) {
throw new Error(`No such item on this server.`)
}
// Some helper types for working with cryptography:
const uid = UserID.fromString(userID)
const sig = Signature.fromString(signature)
const valid = await sig.isValid(uid, bytes)
if (!valid) {
throw new Error(`Invalid signature!`)
}
// OK, we have a valid signature for ... some bytes. But is that what's on the page?
// We'll need to inspect the contents of those bytes to verify that the server isn't
// misrepresenting them:
import { fromBinary, ItemSchema } from "jsr:@diskuto/client/types";
const item = fromBinary(ItemSchema, bytes)
console.log(item)