custom-plc-op.ts
edited
1import {P256PrivateKey, parsePrivateMultikey} from 'npm:@atcute/crypto';
2import * as CBOR from 'npm:@atcute/cbor';
3import {fromBase16, toBase64Url} from 'npm:@atcute/multibase';
4
5// use ur own private key
6const PRIVKEY = "<YOUR KEY HERE>";
7
8// shamelessly stolen from pds moover
9const HEX_REGEX = /^[0-9a-f]+$/i;
10const MULTIKEY_REGEX = /^z[a-km-zA-HJ-NP-Z1-9]+$/;
11const KEYPAIR = HEX_REGEX.test(PRIVKEY) ? (await P256PrivateKey.importRaw(fromBase16(PRIVKEY))) : (
12 MULTIKEY_REGEX.test(PRIVKEY) ? (await P256PrivateKey.importRaw(parsePrivateMultikey(PRIVKEY).privateKeyBytes)) : (() => {throw "could not parse key; shits malformed lol"})()
13);
14
15const OP = {
16 type: "plc_operation",
17 // make sure to replace prev with your previous op cid (plc.directory/did/log/audit, latest op)
18 prev: "bafyreicolpsmfigl72pqrfyiiyaqawhqe5d3waa3bhvk37hbevxfwtyvoe",
19
20 // get this data from your current doc + whatever else you want to include. ex:
21 rotationKeys: [
22 "did:key:zDnaeQm8B5eH4c6aJ5ZAbWMNCsRerrjnZZVau1dKucaosW2S4",
23 "did:key:zQ3shfC9s6jzyvt8155tUwSRG55sGzynT1uLWsnmFrE4bTMFM",
24 ],
25
26 verificationMethods: {
27 atproto: "did:key:zQ3sham9NEsqzb7RPQ18YgoFT9rTHUd7UVEhH2usxwtb39398",
28 },
29
30 alsoKnownAs: ["at://vielle.dev", "at://afterlifepro.neocities.org"],
31
32 services: {
33 atproto_pds: {
34 type: "AtprotoPersonalDataServer",
35 endpoint: "https://katproto.girlonthemoon.xyz",
36 },
37 self: {
38 type: "PersonalWebbedSite",
39 endpoint: "https://vielle.dev",
40 },
41 },
42};
43
44// sign the operation
45const OPBYTES = CBOR.encode(OP)
46const SIGBYTES = await KEYPAIR.sign(OPBYTES)
47const SIG = toBase64Url(SIGBYTES)
48const SIGNEDOP = {...OP, sig: SIG}
49
50console.log(JSON.stringify(SIGNEDOP))
51
52// final step: post this to plc.directory/did (better to use pds via `goat account plc submit file_with_signed_op.json`)