Using symkey as a public channel
This commit is contained in:
parent
4a59f582a9
commit
cae1b967ee
|
@ -6,7 +6,7 @@
|
|||
},
|
||||
|
||||
"whisper": {
|
||||
"privateKey": "0x1d8ef80c9933e20fa9720bf82f3ad481c6be9e44920932c008bb76655a211add",
|
||||
"symKey": "0xd0d905c1c62b810b787141430417caf2b3f54cffadb395b7bb39fdeb8f17266b",
|
||||
"protocol": "ws",
|
||||
"host": "localhost",
|
||||
"port": 8546,
|
||||
|
|
|
@ -7,9 +7,10 @@ const erc20ABI = require('../abi/ERC20.json');
|
|||
|
||||
console.info("Starting...")
|
||||
|
||||
// TODO A node should call an API (probably from a status node) to register itself as a
|
||||
// token gas relayer.
|
||||
|
||||
async function start(){
|
||||
|
||||
|
||||
for(token in config.tokens){
|
||||
if(config.tokens[token].pricePlugin !== undefined){
|
||||
let PricePlugin = require(config.tokens[token].pricePlugin);
|
||||
|
@ -71,25 +72,31 @@ const shhOptions = {
|
|||
};
|
||||
|
||||
let kId;
|
||||
|
||||
let symKId;
|
||||
// Listening to whisper
|
||||
web3.shh.addPrivateKey(config.whisper.privateKey)
|
||||
.then((keyId) => {
|
||||
shhOptions.privateKeyID = keyId;
|
||||
|
||||
web3.shh.addSymKey(config.whisper.symKey)
|
||||
.then(symKeyId => {
|
||||
symKId = symKeyId;
|
||||
return web3.shh.newKeyPair();
|
||||
})
|
||||
.then(keyId => {
|
||||
shhOptions.symKeyId = symKId;
|
||||
|
||||
kId = keyId;
|
||||
|
||||
web3.shh.getPublicKey(keyId).then(pk => {
|
||||
console.info(`Public Key: ${pk}`);
|
||||
console.info(`Sym Key: ${config.whisper.symKey}`);
|
||||
console.info("Topics Available:");
|
||||
|
||||
config.topics = [];
|
||||
for(let contractName in config.contracts) {
|
||||
console.info("- %s: %s [%s]", config.contracts[contractName].name, contractName, Object.keys(config.contracts[contractName].allowedFunctions).join(', '));
|
||||
shhOptions.topics = [contractName];
|
||||
web3.shh.subscribe('messages', shhOptions, processMessages);
|
||||
}
|
||||
});
|
||||
|
||||
console.info("Started.");
|
||||
console.info("Listening for messages...")
|
||||
web3.shh.subscribe('messages', shhOptions, processMessages);
|
||||
});
|
||||
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
|
||||
<title>Send whisper message</title>
|
||||
<title>Send whisper message to node</title>
|
||||
<style type="text/css">
|
||||
h4 small {
|
||||
color: #c3c3c3;
|
||||
|
@ -25,15 +25,15 @@
|
|||
</ul>
|
||||
<form novalidate>
|
||||
<div class="mb-3">
|
||||
<label for="publicKey">Public Key</label>
|
||||
<label for="sKey">Symkey</label>
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text">0x</span>
|
||||
</div>
|
||||
<input type="text" class="form-control" id="publicKey" placeholder="Public Key" required>
|
||||
<input type="text" class="form-control" id="sKey" placeholder="Public Key" required value="0xd0d905c1c62b810b787141430417caf2b3f54cffadb395b7bb39fdeb8f17266b">
|
||||
</div>
|
||||
<div class="invalid-feedback publicKey" style="width: 100%;">
|
||||
Invalid Public Key
|
||||
<div class="invalid-feedback sKey" style="width: 100%;">
|
||||
Invalid Sym Key
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
|
|
|
@ -42,7 +42,7 @@ $(function(){
|
|||
|
||||
$('p.result').text('');
|
||||
|
||||
let publicKey = add0x($("#publicKey"));
|
||||
let sKey = add0x($("#sKey"));
|
||||
let msgTopic = add0x($('#topic'));
|
||||
let msgPayload = add0x($('#payload'));
|
||||
let timeToLive = $('#ttl').val();
|
||||
|
@ -52,9 +52,9 @@ $(function(){
|
|||
$('.invalid-feedback').hide();
|
||||
$('.is-invalid').removeClass('is-invalid');
|
||||
|
||||
if(!/^0x[0-9a-f]{130}$/i.test(publicKey)){
|
||||
$('#publicKey').addClass('is-invalid');
|
||||
$('.invalid-feedback.publicKey').show();
|
||||
if(!/^0x[0-9a-f]{64}$/i.test(sKey)){
|
||||
$('#sKey').addClass('is-invalid');
|
||||
$('.invalid-feedback.sKey').show();
|
||||
}
|
||||
|
||||
if(!/^0x[0-9a-f]{8}$/i.test(msgTopic)){
|
||||
|
@ -85,12 +85,16 @@ $(function(){
|
|||
|
||||
if($('.is-invalid').length > 0) return;
|
||||
|
||||
console.log(`%c await web3.shh.post({pubKey: "${publicKey}", sig: signature, ttl: ${timeToLive}, powTarget: ${powTarget}, powTime: ${powTime}, topic: "${msgTopic}", payload: "${msgPayload}"})`, 'font-weight: bold');
|
||||
console.log(`%c await web3.shh.post({symKeyID: "${sKey}", sig: signature, ttl: ${timeToLive}, powTarget: ${powTarget}, powTime: ${powTime}, topic: "${msgTopic}", payload: "${msgPayload}"})`, 'font-weight: bold');
|
||||
|
||||
let identity;
|
||||
|
||||
|
||||
web3.shh.post({ pubKey: publicKey,
|
||||
let _symKeyId = await web3.shh.addSymKey(sKey);
|
||||
|
||||
|
||||
web3.shh.post({
|
||||
symKeyID: _symKeyId,
|
||||
sig: keyPair,
|
||||
ttl: parseInt(timeToLive),
|
||||
powTarget: parseFloat(powTarget),
|
||||
|
|
Loading…
Reference in New Issue