From a9f4b15353bb669c395b41b03b583aab11cd3607 Mon Sep 17 00:00:00 2001 From: Sasha Date: Mon, 23 Oct 2023 22:44:46 +0200 Subject: [PATCH] add some info, plans etc --- examples/free-forms/tmp/index.js | 26 +++++++++++---- examples/free-forms/tmp/waku.js | 57 +++++++++++++++++++++++--------- 2 files changed, 62 insertions(+), 21 deletions(-) diff --git a/examples/free-forms/tmp/index.js b/examples/free-forms/tmp/index.js index 9e5df8a..3ff645d 100644 --- a/examples/free-forms/tmp/index.js +++ b/examples/free-forms/tmp/index.js @@ -15,11 +15,25 @@ async function run() { const waku = await Waku.create(); window.waku = waku; - window.createForm = (id) => { - return waku.createForm({ id, scheme: "" }); - }; + // window.createForm = (id) => { + // return waku.createForm({ id, scheme: "" }); + // }; - window.fetchForm = (id) => { - return waku.fetchForm(id); - }; + // window.fetchForm = (id) => { + // return waku.fetchForm(id); + // }; + + // const password = "password"; + // const localHistory = decryptLocalStorage(password); + // const fromController = new Forms(localHistory); + + // fromController.createForm(scheme); + // const form = fromController.getForm(id); + // form.update(newScheme); // throws if don't have pubkey/private key + + // const form = fromController.getForm(id); + // form.answer(answers); + + // encryptToLocalStorage(password, fromController.toString()); + // encrypt and send to waku } diff --git a/examples/free-forms/tmp/waku.js b/examples/free-forms/tmp/waku.js index 3d85f44..01db15e 100644 --- a/examples/free-forms/tmp/waku.js +++ b/examples/free-forms/tmp/waku.js @@ -1,3 +1,36 @@ +/* +to crate form: +-> generate pubkey/private key (maybe derived from wallet) +-> create scheme +-> sign scheme and send +creating form { + id(pubkey), + scheme: { nonce, scheme }, + signature: "", +} + +updating form { + id(pubkey), + nonce: 0, + scheme: { nonce, scheme }, + signature: "", +} + +fetching form: +-> get form by pubkey +-> is signature valid +-> encrypt answers +-> send update + +answering form { + id(pubkey), + answers: encrypted({ nonce, answers }), +} + +reading answers: +-> is possible to decrypt +-> +*/ import { createDecoder, createEncoder, @@ -7,7 +40,7 @@ import { import { enrTree, wakuDnsDiscovery } from "@waku/dns-discovery"; import * as utils from "@waku/utils/bytes"; -const VERSION = `0.0.00001`; +const VERSION = `0.0.1-rc-1`; export class Waku { constructor(node) { @@ -20,9 +53,9 @@ export class Waku { libp2p: { peerDiscovery: [ wakuDnsDiscovery([enrTree["PROD"]], { - lightPush: 1, - store: 1, - filter: 1, + lightPush: 6, + store: 6, + filter: 6, }), ], }, @@ -32,27 +65,21 @@ export class Waku { return new Waku(node); } - - fetchForm(id) { - return Form.fetch(this.node, id); - } - - createForm({ id, scheme }) { - return Form.create(this.node, { id, scheme }); - } } class Form { - constructor(id, waku) { + constructor({ pubKey, privateKey, waku }) { this.waku = waku; this.history = []; - this.contentTopic = `/free-form/${VERSION}/definition:${id}/proto`; + this.pubKey = pubKey; + this.privateKey = privateKey; this.decoder = createDecoder(this.contentTopic); + this.contentTopic = `/free-form/${VERSION}/definition/proto`; this.encoder = createEncoder({ contentTopic: this.contentTopic }); } // Initiates new form - static async create(waku, { id, scheme }) { + static async create(waku, { scheme }) { const form = new Form(id, waku); await form.createNew({ scheme }); return form;