Merge pull request #129 from waku-org/proof-size

This commit is contained in:
fryorcraken.eth 2022-10-06 11:15:28 +11:00 committed by GitHub
commit d2b024a27b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 24 deletions

View File

@ -53,7 +53,6 @@
<br/> <br/>
<label for='nick-input'>Your nickname</label> <label for='nick-input'>Your nickname</label>
<input id='nick-input' placeholder='Choose a nickname' type='text'> <input id='nick-input' placeholder='Choose a nickname' type='text'>
<button disabled id='set-nick' type='button'>Set nickname</button>
<br/> <br/>
<label for='textInput'>Message text</label> <label for='textInput'>Message text</label>
@ -115,7 +114,6 @@
const dialButton = document.getElementById('dial') const dialButton = document.getElementById('dial')
const nicknameInput = document.getElementById('nick-input') const nicknameInput = document.getElementById('nick-input')
const setNickButton = document.getElementById('set-nick')
const textInput = document.getElementById('textInput'); const textInput = document.getElementById('textInput');
const sendButton = document.getElementById('sendButton'); const sendButton = document.getElementById('sendButton');
@ -123,7 +121,7 @@
const messagesDiv = document.getElementById('messages') const messagesDiv = document.getElementById('messages')
let membershipId, membershipKey, encoder, node, nodeConnected, nick, rlnInstance; let membershipId, membershipKey, encoder, node, nodeConnected, rlnInstance;
let retrievedRLNEvents = false; let retrievedRLNEvents = false;
const rlnInstancePromise = create(); const rlnInstancePromise = create();
@ -134,9 +132,6 @@
rlnInstance = _rlnInstance rlnInstance = _rlnInstance
statusSpan.innerText = 'WASM Blob download in progress... done!' statusSpan.innerText = 'WASM Blob download in progress... done!'
updateFields() updateFields()
setTimeout(() => {
statusSpan.innerText = ''
}, 5000)
}) })
const ContentTopic = "/toy-chat/2/luzhou/proto"; const ContentTopic = "/toy-chat/2/luzhou/proto";
@ -172,12 +167,10 @@
&& identityKeyInput.value && identityKeyInput.value
&& commitmentKeyInput.value); && commitmentKeyInput.value);
const readyToSend = (membershipKey && membershipId && nodeConnected && nick) const readyToSend = (membershipKey && membershipId && nodeConnected && nicknameInput.value)
textInput.disabled = !readyToSend; textInput.disabled = !readyToSend;
sendButton.disabled = !readyToSend; sendButton.disabled = !readyToSend;
setNickButton.disabled = !nicknameInput.value;
dialButton.disabled = !(node && node.isStarted() && retrievedRLNEvents) dialButton.disabled = !(node && node.isStarted() && retrievedRLNEvents)
retrieveRLNDetailsButton.disabled = !rlnInstance && !retrievedRLNEvents; retrieveRLNDetailsButton.disabled = !rlnInstance && !retrievedRLNEvents;
@ -311,10 +304,6 @@
// Waku // Waku
nicknameInput.onchange = updateFields nicknameInput.onchange = updateFields
setNickButton.onclick = () => {
nick = nicknameInput.value;
updateFields()
}
let messages = []; let messages = [];
@ -324,15 +313,22 @@
messagesDiv.innerHTML += `<li>${msg.msg} - [epoch: ${msg.epoch}, proof: ${msg.proofState} ]</li>` messagesDiv.innerHTML += `<li>${msg.msg} - [epoch: ${msg.epoch}, proof: ${msg.proofState} ]</li>`
if (msg.proofState === "verifying...") { if (msg.proofState === "verifying...") {
console.log("Verifying proof") try {
const res = msg.verify() console.log("Verifying proof")
console.log("proof verified!", res) console.time("proof_verify_timer")
if (res === undefined) { const res = msg.verify()
msg.proofState = "no proof attached" console.time("proof_verify_timer")
} else if (res) { console.log("proof verified!", res)
msg.proofState = "verified." if (res === undefined) {
} else { msg.proofState = "no proof attached"
msg.proofState = "invalid!" } else if (res) {
msg.proofState = "verified."
} else {
msg.proofState = "invalid!"
}
} catch (e) {
msg.proofState = "Error encountered, check console"
console.error("Error verifying proof:", e)
} }
updateMessages() updateMessages()
} }
@ -346,9 +342,10 @@
time.setTime(Number(timestamp)); time.setTime(Number(timestamp));
let proofState, verify; let proofState, verify;
if (typeof wakuMessage.verify === "undefined") { if (typeof wakuMessage.rateLimitProof === "undefined") {
proofState = "no proof attached"; proofState = "no proof attached";
} else { } else {
console.log("Proof received:", wakuMessage.rateLimitProof)
verify = wakuMessage.verify.bind(wakuMessage); verify = wakuMessage.verify.bind(wakuMessage);
proofState = "verifying..."; proofState = "verifying...";
} }
@ -389,12 +386,13 @@
await node.filter.subscribe([decoder], callback) await node.filter.subscribe([decoder], callback)
statusDiv.innerHTML = '<p>Waku node subscribed.</p>'; statusDiv.innerHTML = '<p>Waku node subscribed.</p>';
nodeConnected = true; nodeConnected = true;
updateFields()
} }
sendButton.onclick = async () => { sendButton.onclick = async () => {
const text = utils.utf8ToBytes(textInput.value); const text = utils.utf8ToBytes(textInput.value);
const timestamp = new Date(); const timestamp = new Date();
const msg = ProtoChatMessage.create({text, nick, timestamp: timestamp.valueOf()}); const msg = ProtoChatMessage.create({text, nick: nicknameInput.value, timestamp: timestamp.valueOf()});
const payload = ProtoChatMessage.encode(msg).finish(); const payload = ProtoChatMessage.encode(msg).finish();
console.log("Sending message with proof...") console.log("Sending message with proof...")
sendingStatusSpan.innerText = 'sending...' sendingStatusSpan.innerText = 'sending...'