mirror of
https://github.com/Qortal/qortal-ui.git
synced 2025-03-27 15:55:55 +00:00
fix public key in webworker
This commit is contained in:
parent
61f92f454c
commit
45276f8fd0
@ -2682,7 +2682,7 @@ class ChatPage extends LitElement {
|
|||||||
|
|
||||||
let decodeMsgs = []
|
let decodeMsgs = []
|
||||||
|
|
||||||
try {
|
|
||||||
await new Promise((res, rej) => {
|
await new Promise((res, rej) => {
|
||||||
console.log('this.webWorkerDecodeMessages2.', this.webWorkerDecodeMessages)
|
console.log('this.webWorkerDecodeMessages2.', this.webWorkerDecodeMessages)
|
||||||
this.webWorkerDecodeMessages.postMessage({messages: getInitialMessages, isReceipient: this.isReceipient, _publicKey: this._publicKey, privateKey: window.parent.reduxStore.getState().app.selectedAddress.keyPair.privateKey });
|
this.webWorkerDecodeMessages.postMessage({messages: getInitialMessages, isReceipient: this.isReceipient, _publicKey: this._publicKey, privateKey: window.parent.reduxStore.getState().app.selectedAddress.keyPair.privateKey });
|
||||||
@ -2699,10 +2699,7 @@ class ChatPage extends LitElement {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
} catch (error) {
|
console.log({decodeMsgs})
|
||||||
console.log({error})
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
queue.push(() => replaceMessagesEdited({
|
queue.push(() => replaceMessagesEdited({
|
||||||
decodedMessages: decodeMsgs,
|
decodedMessages: decodeMsgs,
|
||||||
@ -2713,10 +2710,7 @@ class ChatPage extends LitElement {
|
|||||||
addToUpdateMessageHashmap: this.addToUpdateMessageHashmap
|
addToUpdateMessageHashmap: this.addToUpdateMessageHashmap
|
||||||
}));
|
}));
|
||||||
let list = [...decodeMsgs, ...this.messagesRendered.slice(0,80)]
|
let list = [...decodeMsgs, ...this.messagesRendered.slice(0,80)]
|
||||||
// this.messagesRendered = [...decodeMsgs, ...this.messagesRendered.slice(0,80)].sort(function (a, b) {
|
|
||||||
// return a.timestamp
|
|
||||||
// - b.timestamp
|
|
||||||
// })
|
|
||||||
await new Promise((res, rej) => {
|
await new Promise((res, rej) => {
|
||||||
|
|
||||||
this.webWorkerSortMessages.postMessage({list});
|
this.webWorkerSortMessages.postMessage({list});
|
||||||
@ -2911,18 +2905,37 @@ viewElement.scrollTop = originalScrollTop + heightDifference;
|
|||||||
|
|
||||||
async processMessages(messages, isInitial) {
|
async processMessages(messages, isInitial) {
|
||||||
const isReceipient = this.chatId.includes('direct')
|
const isReceipient = this.chatId.includes('direct')
|
||||||
const decodedMessages = messages.map((eachMessage) => {
|
// const decodedMessages = messages.map((eachMessage) => {
|
||||||
|
|
||||||
if (eachMessage.isText === true) {
|
// if (eachMessage.isText === true) {
|
||||||
this.messageSignature = eachMessage.signature
|
// this.messageSignature = eachMessage.signature
|
||||||
let _eachMessage = this.decodeMessage(eachMessage)
|
// let _eachMessage = this.decodeMessage(eachMessage)
|
||||||
return _eachMessage
|
// return _eachMessage
|
||||||
} else {
|
// } else {
|
||||||
this.messageSignature = eachMessage.signature
|
// this.messageSignature = eachMessage.signature
|
||||||
let _eachMessage = this.decodeMessage(eachMessage)
|
// let _eachMessage = this.decodeMessage(eachMessage)
|
||||||
return _eachMessage
|
// return _eachMessage
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
|
||||||
|
let decodedMessages = []
|
||||||
|
console.log({messages: messages, isReceipient: this.isReceipient, _publicKey: this._publicKey, privateKey: window.parent.reduxStore.getState().app.selectedAddress.keyPair.privateKey})
|
||||||
|
|
||||||
|
await new Promise((res, rej) => {
|
||||||
|
this.webWorkerDecodeMessages.postMessage({messages: messages, isReceipient: this.isReceipient, _publicKey: this._publicKey, privateKey: window.parent.reduxStore.getState().app.selectedAddress.keyPair.privateKey });
|
||||||
|
|
||||||
|
this.webWorkerDecodeMessages.onmessage = e => {
|
||||||
|
decodedMessages = e.data
|
||||||
|
res()
|
||||||
|
|
||||||
}
|
}
|
||||||
})
|
this.webWorkerDecodeMessages.onerror = e => {
|
||||||
|
console.log('e',e)
|
||||||
|
rej()
|
||||||
|
|
||||||
|
}
|
||||||
|
})
|
||||||
|
console.log('process', decodedMessages)
|
||||||
if (isInitial) {
|
if (isInitial) {
|
||||||
this.chatEditorPlaceholder = await this.renderPlaceholder()
|
this.chatEditorPlaceholder = await this.renderPlaceholder()
|
||||||
|
|
||||||
|
@ -2465,6 +2465,7 @@ class Base58 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
decode(string) {
|
decode(string) {
|
||||||
|
console.log({string})
|
||||||
if (string.length === 0) {
|
if (string.length === 0) {
|
||||||
return new Uint8Array(0);
|
return new Uint8Array(0);
|
||||||
}
|
}
|
||||||
@ -2644,6 +2645,16 @@ class Curve25519 {
|
|||||||
this.pack25519(d, b);
|
this.pack25519(d, b);
|
||||||
return this.crypto_verify_32(c, 0, d, 0);
|
return this.crypto_verify_32(c, 0, d, 0);
|
||||||
}
|
}
|
||||||
|
par25519(a) {
|
||||||
|
var d = new Uint8Array(32);
|
||||||
|
this.pack25519(d, a);
|
||||||
|
return d[0] & 1;
|
||||||
|
}
|
||||||
|
unpack25519(o, n) {
|
||||||
|
var i;
|
||||||
|
for (i = 0; i < 16; i++) o[i] = n[2*i] + (n[2*i+1] << 8);
|
||||||
|
o[15] &= 0x7fff;
|
||||||
|
}
|
||||||
|
|
||||||
crypto_verify_32(x, xi, y, yi) {
|
crypto_verify_32(x, xi, y, yi) {
|
||||||
return this.vn(x, xi, y, yi, 32);
|
return this.vn(x, xi, y, yi, 32);
|
||||||
@ -2757,6 +2768,12 @@ export const decryptChatMessageBase64 = (
|
|||||||
recipientPublicKey,
|
recipientPublicKey,
|
||||||
lastReference
|
lastReference
|
||||||
) => {
|
) => {
|
||||||
|
console.log('1', {
|
||||||
|
encryptedMessage,
|
||||||
|
privateKey,
|
||||||
|
recipientPublicKey,
|
||||||
|
lastReference
|
||||||
|
})
|
||||||
let _encryptedMessage = atob(encryptedMessage);
|
let _encryptedMessage = atob(encryptedMessage);
|
||||||
const binaryLength = _encryptedMessage.length;
|
const binaryLength = _encryptedMessage.length;
|
||||||
const bytes = new Uint8Array(binaryLength);
|
const bytes = new Uint8Array(binaryLength);
|
||||||
@ -2765,12 +2782,21 @@ export const decryptChatMessageBase64 = (
|
|||||||
bytes[i] = _encryptedMessage.charCodeAt(i);
|
bytes[i] = _encryptedMessage.charCodeAt(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
const _base58RecipientPublicKey =
|
let _base58RecipientPublic = recipientPublicKey
|
||||||
recipientPublicKey instanceof Uint8Array
|
|
||||||
? base58Instant.encode(recipientPublicKey)
|
|
||||||
: recipientPublicKey;
|
|
||||||
const _recipientPublicKey = base58Instant.decode(_base58RecipientPublicKey);
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
_base58RecipientPublic = recipientPublicKey.key
|
||||||
|
} catch (error) {
|
||||||
|
_base58RecipientPublic = recipientPublicKey
|
||||||
|
}
|
||||||
|
|
||||||
|
const _base58RecipientPublicKey =
|
||||||
|
_base58RecipientPublic instanceof Uint8Array
|
||||||
|
? base58Instant.encode(_base58RecipientPublic)
|
||||||
|
: _base58RecipientPublic;
|
||||||
|
console.log({_base58RecipientPublicKey})
|
||||||
|
const _recipientPublicKey = base58Instant.decode(_base58RecipientPublicKey);
|
||||||
|
console.log({_recipientPublicKey})
|
||||||
const _lastReference =
|
const _lastReference =
|
||||||
lastReference instanceof Uint8Array
|
lastReference instanceof Uint8Array
|
||||||
? lastReference
|
? lastReference
|
||||||
@ -2825,6 +2851,7 @@ const decodeMessage = (
|
|||||||
_publicKeyVar.hasPubKey === true &&
|
_publicKeyVar.hasPubKey === true &&
|
||||||
encodedMessageObj.data
|
encodedMessageObj.data
|
||||||
) {
|
) {
|
||||||
|
console.log('hello encrypt')
|
||||||
let decodedMessage = decryptChatMessageBase64(
|
let decodedMessage = decryptChatMessageBase64(
|
||||||
encodedMessageObj.data,
|
encodedMessageObj.data,
|
||||||
privateKey,
|
privateKey,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user