aboutsummaryrefslogtreecommitdiffstats
path: root/install.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2022-01-11 08:31:45 -0800
committerGitHub <[email protected]>2022-01-11 08:31:45 -0800
commit81d980497d416aa01ea127aa09eb0fdb8242a0d4 (patch)
treefe6bc24fd4f2adc1ae0f489c427dc9588998f750 /install.js
parentad486f7828880c51a81958b14830da4f9c96e61f (diff)
parent1e6ef564799abd41cbe72014274604dbdf19cbd7 (diff)
downloadcoinos-server-81d980497d416aa01ea127aa09eb0fdb8242a0d4.tar.gz
coinos-server-81d980497d416aa01ea127aa09eb0fdb8242a0d4.zip
Merge pull request #34 from coinos/setup-updates
Setup updates
Diffstat (limited to 'install.js')
0 files changed, 0 insertions, 0 deletions
eyword.Namespace */ .highlight .kp { color: #080 } /* Keyword.Pseudo */ .highlight .kr { color: #080; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #00D; font-weight: bold } /* Literal.Number */ .highlight .s { color: #D20; background-color: #FFF0F0 } /* Literal.String */ .highlight .na { color: #369 } /* Name.Attribute */ .highlight .nb { color: #038 } /* Name.Builtin */ .highlight .nc { color: #B06; font-weight: bold } /* Name.Class */ .highlight .no { color: #036; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555 } /* Name.Decorator */ .highlight .ne { color: #B06; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #06B; font-weight: bold } /* Name.Function */ .highlight .nl { color: #369; font-style: italic } /* Name.Label */ .highlight .nn { color: #B06; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #369; font-weight: bold } /* Name.Property */ .highlight .nt { color: #B06; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #369 } /* Name.Variable */ .highlight .ow { color: #080 } /* Operator.Word */ .highlight .w { color: #BBB } /* Text.Whitespace */ .highlight .mb { color: #00D; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #00D; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #00D; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #00D; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #00D; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #D20; background-color: #FFF0F0 } /* Literal.String.Affix */ .highlight .sb { color: #D20; background-color: #FFF0F0 } /* Literal.String.Backtick */ .highlight .sc { color: #D20; background-color: #FFF0F0 } /* Literal.String.Char */ .highlight .dl { color: #D20; background-color: #FFF0F0 } /* Literal.String.Delimiter */ .highlight .sd { color: #D20; background-color: #FFF0F0 } /* Literal.String.Doc */ .highlight .s2 { color: #D20; background-color: #FFF0F0 } /* Literal.String.Double */ .highlight .se { color: #04D; background-color: #FFF0F0 } /* Literal.String.Escape */ .highlight .sh { color: #D20; background-color: #FFF0F0 } /* Literal.String.Heredoc */ .highlight .si { color: #33B; background-color: #FFF0F0 } /* Literal.String.Interpol */ .highlight .sx { color: #2B2; background-color: #F0FFF0 } /* Literal.String.Other */ .highlight .sr { color: #080; background-color: #FFF0FF } /* Literal.String.Regex */ .highlight .s1 { color: #D20; background-color: #FFF0F0 } /* Literal.String.Single */ .highlight .ss { color: #A60; background-color: #FFF0F0 } /* Literal.String.Symbol */ .highlight .bp { color: #038 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #06B; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #369 } /* Name.Variable.Class */ .highlight .vg { color: #D70 } /* Name.Variable.Global */ .highlight .vi { color: #33B } /* Name.Variable.Instance */ .highlight .vm { color: #369 } /* Name.Variable.Magic */ .highlight .il { color: #00D; font-weight: bold } /* Literal.Number.Integer.Long */
// One-time genesis for a Concord community (CORD-02 §1): publishes the two
// owner-signed editions (community metadata + #general) and the owner's Join,
// then prints the join material to embed in the app.
//
//   bun run tools/concord-genesis.js <owner-privkey-hex> <name> <relay> [relay...]

import { bytesToHex, hexToBytes } from "@noble/hashes/utils";
import { getPublicKey } from "nostr-tools/pure";
import { Relay, useWebSocketImplementation } from "nostr-tools/relay";
import WebSocket from "ws";
import {
  communityId,
  controlKey,
  guestbookKey,
  makeEdition,
  wrapRumor,
  msTags,
} from "../src/concord.js";

try { useWebSocketImplementation(WebSocket); } catch {}

let [skHex, name, ...relays] = process.argv.slice(2);
if (!skHex || !name || !relays.length) {
  console.error("usage: bun run tools/concord-genesis.js <owner-privkey-hex> <name> <relay...>");
  process.exit(1);
}

let ownerSk = hexToBytes(skHex);
let owner = getPublicKey(ownerSk);
let ownerSalt = bytesToHex(crypto.getRandomValues(new Uint8Array(32)));
let communityRoot = crypto.getRandomValues(new Uint8Array(32));
let cid = communityId(owner, ownerSalt);
let generalId = bytesToHex(crypto.getRandomValues(new Uint8Array(32)));

let control = controlKey(communityRoot, cid, 0);
let guestbook = guestbookKey(communityRoot, cid, 0);

let now = Date.now();
let metadata = makeEdition(
  { vsk: 0, eid: cid, version: 1, content: JSON.stringify({ name, relays }) },
  now
);
let general = makeEdition(
  { vsk: 2, eid: generalId, version: 1, content: JSON.stringify({ name: "general", private: false }) },
  now + 1
);
let { created_at, ms } = msTags(now + 2);
let join = { kind: 3306, content: "join", tags: [ms], created_at };

let events = [
  await wrapRumor({ ...metadata, pubkey: owner }, ownerSk, control, { plaintext: true }),
  await wrapRumor({ ...general, pubkey: owner }, ownerSk, control, { plaintext: true }),
  await wrapRumor({ ...join, pubkey: owner }, ownerSk, guestbook),
];

for (let url of relays) {
  try {
    let r = await Relay.connect(url);
    for (let e of events) await r.publish(e);
    r.close();
    console.error(`published ${events.length} events to ${url}`);
  } catch (e) {
    console.error(`FAILED ${url}: ${e.message ?? e}`);
  }
}

// Join material (CORD-02 §8) — the bundle's membership subset. Contains the
// community_root: embedding it in the app makes every app user a member.
console.log(
  JSON.stringify(
    {
      community_id: cid,
      owner,
      owner_salt: ownerSalt,
      community_root: bytesToHex(communityRoot),
      root_epoch: 0,
      channels: [{ id: generalId, name: "general" }],
      relays,
      name,
    },
    null,
    2
  )
);
process.exit(0);