Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async messageReceived(data, pub, selfAuthored) {
if (this.onMessage) {
const decrypted = await Gun.SEA.decrypt(data, (await this.getSecret(pub)));
if (typeof decrypted !== `object`) {
// console.log(`chat data received`, decrypted);
return;
}
this.onMessage(decrypted, {selfAuthored});
} else {
// console.log(`chat message received`, decrypted);
}
}
static verify(msg, pubKey) {
return Gun.SEA.verify(msg.slice(1), pubKey);
}
}
static async getOurSecretChatId(gun, pub, pair) {
const epub = await gun.user(pub).get(`epub`).once().then();
const secret = await Gun.SEA.secret(epub, pair);
return Gun.SEA.work(secret + pub, null, null, {name: 'SHA-256'});
}
static async getTheirSecretChatId(gun, pub, pair) {
const epub = await gun.user(pub).get(`epub`).once().then();
const secret = await Gun.SEA.secret(epub, pair);
return Gun.SEA.work(secret + pair.pub, null, null, {name: 'SHA-256'});
}
static async getOurSecretChatId(gun, pub, pair) {
const epub = await gun.user(pub).get(`epub`).once().then();
const secret = await Gun.SEA.secret(epub, pair);
return Gun.SEA.work(secret + pub, null, null, {name: 'SHA-256'});
}
async getSecret(pub) {
if (!this.secrets[pub]) {
const epub = await this.gun.user(pub).get(`epub`).once().then();
this.secrets[pub] = await Gun.SEA.secret(epub, this.key);
}
return this.secrets[pub];
}