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();
|
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
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user