{"id":22609042,"url":"https://github.com/bitfinexcom/dazaar-guild","last_synced_at":"2026-01-23T17:36:01.750Z","repository":{"id":54175549,"uuid":"336830111","full_name":"bitfinexcom/dazaar-guild","owner":"bitfinexcom","description":null,"archived":false,"fork":false,"pushed_at":"2021-03-05T08:01:35.000Z","size":10,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-25T04:16:57.305Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bitfinexcom.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-02-07T16:14:00.000Z","updated_at":"2021-05-19T04:43:02.000Z","dependencies_parsed_at":"2022-08-13T08:20:48.584Z","dependency_job_id":null,"html_url":"https://github.com/bitfinexcom/dazaar-guild","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitfinexcom%2Fdazaar-guild","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitfinexcom%2Fdazaar-guild/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitfinexcom%2Fdazaar-guild/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitfinexcom%2Fdazaar-guild/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bitfinexcom","download_url":"https://codeload.github.com/bitfinexcom/dazaar-guild/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248351881,"owners_count":21089357,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-08T15:10:42.594Z","updated_at":"2026-01-23T17:35:56.728Z","avatar_url":"https://github.com/bitfinexcom.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dazaar-guild\n\n![Dazaar logo](docs/logo.png)\n\n\u003e Socket, RPC API patterns for a decentralized web based on Dazaar \n\n```\nnpm install dazaar-guild\n```\n\nLearn more about Dazaar in our [intro blogpost](https://blog.dazaar.com/2020/09/12/introducing-dazaar/) and [whitepaper](./docs/whitepaper.md).\n\n## Usage\n\nSetup server side\n\n```js\nconst { Bastion, Priv } = require('dazaar-guild')\n\nconst bastion = new Bastion({\n  dir: './data',\n  customValidate: (key, cb) =\u003e {\n    console.log('bastion: validationRequest for', key.toString('hex'))\n    cb(null)\n  }\n})\n\nconst MEM = {}\n\nbastion.on('prv_auth', data =\u003e {\n  if (MEM[data.cliPubHex]) {\n    console.error('cli already active', cliPubHex)\n    return\n  }\n\n  MEM[data.cliPubHex] = true\n  priv.servePriv({\n    cliPubHex: data.cliPubHex\n  }, () =\u003e {\n  data.confirm()\n  })\n})\n\nbastion.on('message', p =\u003e {\n  if (p.data === 'hello') {\n    p.reply('world')\n  }\n})\n\nbastion.start()\n\nconst priv = new Priv({\n  dir: './data',\n  customValidate: (key, cb) =\u003e {\n    console.log('priv: validationRequest for', key.toString('hex'))\n    cb(null)\n  }\n})\n\npriv.on('message', p =\u003e {\n  if (p.data === 'hello') {\n    p.reply('world (priv)')\n  }\n})\n```\n\nAnd then client side\n\n```js\nconst { Client } = require('dazaar-guild')\n\nconst client = new Client({\n  bastionKey: process.argv[2]\n}, {\n})\n\nclient.start()\n\nclient.on('message', p =\u003e {\n  console.log('received pub message', p)\n})\n\nclient.on('pub_connected', () =\u003e {\n  client.bcastPub('message', 'hello')\n  client.auth()\n})\n\nclient.on('auth', msg =\u003e {\n  console.log('received authentication handshake')\n  client.connectPriv(msg)\n})\n\nclient.on('prv_message', p =\u003e {\n  console.log('received prv message', p)\n})\n\nclient.on('prv_connected', () =\u003e {\n  setTimeout(() =\u003e {\n    client.bcastPriv('message', 'hello')\n  }, 500)\n  console.log('connected priv')\n})\n```\n\n## API\n\n#### `const bastion = Bastion(opts)`\n\nCreate a public Dazaar-Bastion instance.\n`Bastion` inherits from EventEmitter.\n\nOptions include:\n\n```js\n{\n  dir: ..., // data directory for hypercore storage\n  customValidate: (key, cb) // custom client validation logic (ideal for whitelisting, ...)\n}\n```\n\n\n#### `bastion.on('prv_auth', data =\u003e {...})`\n\nGet notified on new client authentication request.\n\nData include:\n\n```js\n{\n  cliPubHex: ..., // hex of pub key of connecting client\n}\n```\n\n#### `bastion.on('message', data =\u003e {...})`\n\nGeneric message received from client, useful for chatter and build low level complex patterns (ie. RPC)\n\nData include:\n\n```js\n{\n  data: ..., // incoming data\n  reply: ..., // function to reply back to the client\n}\n```\n\n#### `const priv = Priv(opts)`\n\nCreate a private Dazaar instance, dedicated to a single client.\n`Priv` inherits from EventEmitter.\n\nOptions include:\n\n```js\n{\n  dir: ..., // data directory for hypercore storage\n  customValidate: (key, cb) // custom client validation logic (ideal for whitelisting, ...)\n}\n```\n\n#### `priv.on('message', data =\u003e {...})`\n\nGeneric message received from client, useful for chatter and build low level complex patterns (ie. RPC)\n\nData include:\n\n```js\n{\n  data: ..., // incoming data\n  reply: ..., // function to reply back to the client\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitfinexcom%2Fdazaar-guild","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbitfinexcom%2Fdazaar-guild","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitfinexcom%2Fdazaar-guild/lists"}