add some info, plans etc

This commit is contained in:
Sasha 2023-10-23 22:44:46 +02:00
parent b923d852a4
commit a9f4b15353
No known key found for this signature in database
2 changed files with 62 additions and 21 deletions

View File

@ -15,11 +15,25 @@ async function run() {
const waku = await Waku.create(); const waku = await Waku.create();
window.waku = waku; window.waku = waku;
window.createForm = (id) => { // window.createForm = (id) => {
return waku.createForm({ id, scheme: "" }); // return waku.createForm({ id, scheme: "" });
}; // };
window.fetchForm = (id) => { // window.fetchForm = (id) => {
return waku.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
} }

View File

@ -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 { import {
createDecoder, createDecoder,
createEncoder, createEncoder,
@ -7,7 +40,7 @@ import {
import { enrTree, wakuDnsDiscovery } from "@waku/dns-discovery"; import { enrTree, wakuDnsDiscovery } from "@waku/dns-discovery";
import * as utils from "@waku/utils/bytes"; import * as utils from "@waku/utils/bytes";
const VERSION = `0.0.00001`; const VERSION = `0.0.1-rc-1`;
export class Waku { export class Waku {
constructor(node) { constructor(node) {
@ -20,9 +53,9 @@ export class Waku {
libp2p: { libp2p: {
peerDiscovery: [ peerDiscovery: [
wakuDnsDiscovery([enrTree["PROD"]], { wakuDnsDiscovery([enrTree["PROD"]], {
lightPush: 1, lightPush: 6,
store: 1, store: 6,
filter: 1, filter: 6,
}), }),
], ],
}, },
@ -32,27 +65,21 @@ export class Waku {
return new Waku(node); return new Waku(node);
} }
fetchForm(id) {
return Form.fetch(this.node, id);
}
createForm({ id, scheme }) {
return Form.create(this.node, { id, scheme });
}
} }
class Form { class Form {
constructor(id, waku) { constructor({ pubKey, privateKey, waku }) {
this.waku = waku; this.waku = waku;
this.history = []; this.history = [];
this.contentTopic = `/free-form/${VERSION}/definition:${id}/proto`; this.pubKey = pubKey;
this.privateKey = privateKey;
this.decoder = createDecoder(this.contentTopic); this.decoder = createDecoder(this.contentTopic);
this.contentTopic = `/free-form/${VERSION}/definition/proto`;
this.encoder = createEncoder({ contentTopic: this.contentTopic }); this.encoder = createEncoder({ contentTopic: this.contentTopic });
} }
// Initiates new form // Initiates new form
static async create(waku, { id, scheme }) { static async create(waku, { scheme }) {
const form = new Form(id, waku); const form = new Form(id, waku);
await form.createNew({ scheme }); await form.createNew({ scheme });
return form; return form;