mirror of
https://github.com/Qortal/qortal-ui.git
synced 2025-07-26 11:41:24 +00:00
build
config
core
crypto
api
bitcoin
deps
transactions
arbitrary
chat
ChatBase.js
ChatTransaction.js
GroupChatTransaction.js
decryptChatMessage.js
signChat.js
groups
names
polls
reward-share
trade-portal
AirdropTransaction.js
DelegationTransaction.js
DeployAtTransaction.js
MessageTransaction.js
PaymentTransaction.js
PublicizeTransaction.js
TransactionBase.js
TransferPrivsTransaction.js
arbitraryV3.js
processTransaction.js
registerName_dnsthing.js
transactions.js
utils
wallet
PhraseWallet.js
api.js
constants.js
createTransaction.js
createWallet.js
decryptStoredWallet.js
fetch-request.js
kdf.js
registerUsername.js
storeWallet.js
tradeRequest.js
api.js
api_deps.js
config.js
img
lib
locales
plugins
scripts
snap
splash
.editorconfig
.gitattributes
.gitignore
CONTRIBUTING.md
LICENSE
README.md
build-setup.js
build.bat
build.js
build.sh
electron-builder.yml
electron.js
package-lock.json
package.json
run_server.bat
server.js
set-up-snap.sh
watch-inline.js
watch.js
40 lines
985 B
JavaScript
40 lines
985 B
JavaScript
import nacl from '../../deps/nacl-fast'
|
|
import utils from '../../deps/utils'
|
|
|
|
const signChat = (chatBytes, nonce, keyPair) => {
|
|
|
|
if (!chatBytes) {
|
|
throw new Error('Chat Bytes not defined')
|
|
}
|
|
|
|
if (!nonce) {
|
|
throw new Error('Nonce not defined')
|
|
}
|
|
|
|
if (!keyPair) {
|
|
throw new Error('keyPair not defined')
|
|
}
|
|
|
|
const _nonce = utils.int32ToBytes(nonce)
|
|
|
|
if (chatBytes.length === undefined) {
|
|
const _chatBytesBuffer = Object.keys(chatBytes).map(function (key) { return chatBytes[key]; })
|
|
|
|
const chatBytesBuffer = new Uint8Array(_chatBytesBuffer)
|
|
chatBytesBuffer.set(_nonce, 112)
|
|
|
|
const signature = nacl.sign.detached(chatBytesBuffer, keyPair.privateKey)
|
|
|
|
return utils.appendBuffer(chatBytesBuffer, signature)
|
|
} else {
|
|
const chatBytesBuffer = new Uint8Array(chatBytes)
|
|
chatBytesBuffer.set(_nonce, 112)
|
|
|
|
const signature = nacl.sign.detached(chatBytesBuffer, keyPair.privateKey)
|
|
|
|
return utils.appendBuffer(chatBytesBuffer, signature)
|
|
}
|
|
}
|
|
|
|
export default signChat
|