mirror of
https://github.com/status-im/status-js-api.git
synced 2025-02-17 03:48:07 +00:00
update payload creation
This commit is contained in:
parent
6b04c467f1
commit
af8f6e0dca
67
src/index.js
67
src/index.js
@ -6,28 +6,25 @@ const TTL = 10;
|
|||||||
const POW_TARGET = 0.002;
|
const POW_TARGET = 0.002;
|
||||||
const CHANNEL = Web3.utils.sha3("status").slice(0, 10);
|
const CHANNEL = Web3.utils.sha3("status").slice(0, 10);
|
||||||
|
|
||||||
function createStatusPayload(
|
function createStatusPayload() {
|
||||||
{
|
let tag = '~#c4';
|
||||||
tag = '~#c4',
|
let content = 'Hello everyone';
|
||||||
content = 'Hello everyone',
|
let messageType = '~:public-group-user-message';
|
||||||
messageType = '~:public-group-user-message',
|
let clockValue = (new Date().getTime()) * 100;
|
||||||
clockValue = (new Date().getTime()) * 100,
|
let contentType = 'text/plain';
|
||||||
contentType = 'text/plain',
|
let timestamp = new Date().getTime();
|
||||||
timestamp = new Date().getTime(),
|
return asciiToHex(
|
||||||
} = {},
|
JSON.stringify([
|
||||||
) {
|
tag,
|
||||||
return asciiToHex(
|
[
|
||||||
JSON.stringify([
|
content,
|
||||||
tag,
|
contentType,
|
||||||
[
|
messageType,
|
||||||
content,
|
clockValue,
|
||||||
contentType,
|
timestamp,
|
||||||
messageType,
|
],
|
||||||
clockValue,
|
]),
|
||||||
timestamp,
|
);
|
||||||
],
|
|
||||||
]),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
@ -35,7 +32,7 @@ function createStatusPayload(
|
|||||||
let web3 = new Web3();
|
let web3 = new Web3();
|
||||||
web3.setProvider(new Web3.providers.WebsocketProvider('ws://localhost:8546', {headers: {Origin: "http://localhost:8080"}}));
|
web3.setProvider(new Web3.providers.WebsocketProvider('ws://localhost:8546', {headers: {Origin: "http://localhost:8080"}}));
|
||||||
|
|
||||||
await web3.shh.setMinPoW(POW_TARGET);
|
await web3.shh.setMinPoW(POW_TARGET);
|
||||||
|
|
||||||
let keys = {};
|
let keys = {};
|
||||||
|
|
||||||
@ -45,30 +42,30 @@ function createStatusPayload(
|
|||||||
console.dir("keys generated");
|
console.dir("keys generated");
|
||||||
console.dir(keys);
|
console.dir(keys);
|
||||||
|
|
||||||
subscription = web3.shh.subscribe("messages", {
|
subscription = web3.shh.subscribe("messages", {
|
||||||
minPow: POW_TARGET,
|
minPow: POW_TARGET,
|
||||||
symKeyID: keys.symKeyID,
|
symKeyID: keys.symKeyID,
|
||||||
topics: [CHANNEL]
|
topics: [CHANNEL]
|
||||||
}).on('data', (data) => {
|
}).on('data', (data) => {
|
||||||
console.dir("message received!");
|
console.dir("message received!");
|
||||||
console.dir(data);
|
console.dir(data);
|
||||||
}).on('error', () => {
|
}).on('error', () => {
|
||||||
console.dir("error receiving message");
|
console.dir("error receiving message");
|
||||||
});
|
});
|
||||||
|
|
||||||
web3.shh.post({
|
web3.shh.post({
|
||||||
symKeyID: keys.symKeyID, // encrypts using the sym key ID
|
symKeyID: keys.symKeyID, // encrypts using the sym key ID
|
||||||
sig: keys.sig, // signs the message using the keyPair ID
|
sig: keys.sig, // signs the message using the keyPair ID
|
||||||
ttl: TTL,
|
ttl: TTL,
|
||||||
topic: CHANNEL,
|
topic: CHANNEL,
|
||||||
payload: createStatusPayload("hello there"),
|
payload: createStatusPayload(),
|
||||||
powTime: POW_TIME,
|
powTime: POW_TIME,
|
||||||
powTarget: POW_TARGET
|
powTarget: POW_TARGET
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
console.dir('message sent!');
|
console.dir('message sent!');
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
console.dir("error sending message");
|
console.dir("error sending message");
|
||||||
console.dir(e);
|
console.dir(e);
|
||||||
});
|
});
|
||||||
|
|
||||||
})()
|
})()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user