Qortal UI - Main Code Repository A User Interface for the Qortal Blockchain Project. Truly decentralized web hosting, application hosting, communications, data storage, and full infrastructure for the future global decentralized digital world.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.0 KiB

3 years ago
import nacl from '../../deps/nacl-fast.js'
import utils from '../../deps/utils.js'
const signChat = (chatBytes, nonce, keyPair) => {
if (!chatBytes) {
throw new Error('Chat Bytes not defined')
}
3 years ago
if (!nonce) {
throw new Error('Nonce not defined')
}
3 years ago
if (!keyPair) {
throw new Error('keyPair not defined')
}
3 years ago
const _nonce = utils.int32ToBytes(nonce)
3 years ago
if (chatBytes.length === undefined) {
const _chatBytesBuffer = Object.keys(chatBytes).map(function (key) { return chatBytes[key]; })
3 years ago
const chatBytesBuffer = new Uint8Array(_chatBytesBuffer)
chatBytesBuffer.set(_nonce, 112)
3 years ago
const signature = nacl.sign.detached(chatBytesBuffer, keyPair.privateKey)
3 years ago
const signedBytes = utils.appendBuffer(chatBytesBuffer, signature)
3 years ago
return signedBytes
} else {
const chatBytesBuffer = new Uint8Array(chatBytes)
chatBytesBuffer.set(_nonce, 112)
3 years ago
const signature = nacl.sign.detached(chatBytesBuffer, keyPair.privateKey)
3 years ago
const signedBytes = utils.appendBuffer(chatBytesBuffer, signature)
3 years ago
return signedBytes
}
3 years ago
}
export default signChat