forked from Qortal/qortal-ui
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.
38 lines
1.0 KiB
38 lines
1.0 KiB
import Base58 from '../../../deps/Base58.js' |
|
import nacl from '../../../deps/nacl-fast.js' |
|
import utils from '../../../deps/utils.js' |
|
|
|
|
|
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) |
|
|
|
const signedBytes = utils.appendBuffer(txnBuffer, signature) |
|
|
|
return signedBytes |
|
} else { |
|
|
|
const signature = nacl.sign.detached(txnBuffer, keyPair.privateKey) |
|
|
|
const signedBytes = utils.appendBuffer(txnBuffer, signature) |
|
|
|
return signedBytes |
|
} |
|
} |
|
|
|
export default signTradeBotTransaction
|
|
|