4
1
mirror of https://github.com/Qortal/qortal-ui.git synced 2025-02-21 22:55:48 +00:00
qortal-ui/crypto/api/transactions/trade-portal/tradebot/signTradeBotTransaction.js
AlphaX-Projects fa29ff4c43 Update UI
Refactor and added new functioms
2024-05-08 13:16:23 +02:00

28 lines
874 B
JavaScript

import Base58 from '../../../deps/Base58'
import nacl from '../../../deps/nacl-fast'
import utils from '../../../deps/utils'
const signTradeBotTransaction = (unsignedTxn, keyPair) => {
if (!unsignedTxn) {
throw new Error('Unsigned Transaction Bytes not defined')
}
if (!keyPair) {
throw new Error('keyPair not defined')
}
const txnBuffer = Base58.decode(unsignedTxn)
if (keyPair.privateKey.length === undefined) {
const _privateKey = Object.keys(keyPair.privateKey).map(function (key) { return keyPair.privateKey[key]; })
const privateKey = new Uint8Array(_privateKey)
const signature = nacl.sign.detached(txnBuffer, privateKey)
return utils.appendBuffer(txnBuffer, signature)
} else {
const signature = nacl.sign.detached(txnBuffer, keyPair.privateKey)
return utils.appendBuffer(txnBuffer, signature)
}
}
export default signTradeBotTransaction