-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo.js
44 lines (35 loc) · 1.3 KB
/
demo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import Hypercore from "hypercore";
import Hyperbee from "hyperbee";
import { dbPut, setSigningKey } from "./src/dbPut.js";
import { keyFromPem } from "./src/signAttestation.js";
// Set up Hypercore and Hyperbee
const core = new Hypercore("./demo.hypercore");
await core.ready();
const db = new Hyperbee(core, {
keyEncoding: "utf-8", // for demo
valueEncoding: "binary",
});
// Set signing key
setSigningKey(await keyFromPem("./demokey.pem"));
// Attestation data
const waczCID = "bafybeifgkpgb7yqgjnovszaio7tzetmdfmigylr24hg6a76wnjxcnhkx54";
const attribute = "description";
const value =
"Web archive [ https://t.me/place_kh, https://t.me/place_kh/7848, https://t.me/s/place_kh/7848 ] captured using Browsertrix on 2022-06-07";
console.log(`CID: ${waczCID}`);
console.log(`Attribute: ${attribute}`);
console.log(`Value: ${value}`);
// Add attestation, sign, timestamp, and encrypt as needed.
console.log("Storing...");
await dbPut(db, waczCID, attribute, value, false);
console.log("Done");
// Encrypted value
//
// 32 byte DEMO encryption key that is reused in demo-get.js
const key = Buffer.from(
"QHle+CRiaq8iv1fP9xopZGbO6F7F8926TpSOrReQJ1Q=",
"base64"
);
console.log("Storing encrypted attribute 'secret-stuff'");
await dbPut(db, waczCID, "secret-stuff", [123, "secret value"], key);
console.log("Done");