mirror of
https://github.com/status-im/js-waku-examples.git
synced 2025-01-12 23:14:32 +00:00
add some info, plans etc
This commit is contained in:
parent
b923d852a4
commit
a9f4b15353
@ -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
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user