mirror of
https://github.com/Qortal/qortal-ui.git
synced 2025-07-26 11:41:24 +00:00
build
config
img
qortal-ui-core
qortal-ui-crypto
api
bitcoin
deps
transactions
arbitrary
signArbitrary.js
chat
groups
names
reward-share
trade-portal
AirdropTransaction.js
DelegationTransaction.js
MessageTransaction.js
PaymentTransaction.js
PublicizeTransaction.js
TransactionBase.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
package.json
qortal-ui-plugins
scripts
snap
.editorconfig
.gitattributes
.gitignore
.travis.yml
CONTRIBUTING.md
LICENSE
README.md
build-setup.js
build.bat
build.js
build.sh
electron-builder.yml
electron.js
install-dependencies.sh
package.json
push-updates-with-travis-build.sh
run_server.bat
server.js
set-up-snap.sh
update-package-json.js
watch-inline.js
watch.js
40 lines
1.4 KiB
JavaScript
40 lines
1.4 KiB
JavaScript
import nacl from '../../deps/nacl-fast.js'
|
|
import utils from '../../deps/utils.js'
|
|
import Base58 from '../../deps/Base58.js'
|
|
|
|
|
|
const signArbitrary = (arbitraryBytesBase58, arbitraryBytesForSigningBase58, nonce, keyPair) => {
|
|
|
|
if (!arbitraryBytesBase58) {
|
|
throw new Error('ArbitraryBytesBase58 not defined')
|
|
}
|
|
|
|
if (!nonce) {
|
|
throw new Error('Nonce not defined')
|
|
}
|
|
|
|
if (!keyPair) {
|
|
throw new Error('keyPair not defined')
|
|
}
|
|
|
|
const arbitraryBytes = Base58.decode(arbitraryBytesBase58)
|
|
const _arbitraryBytesBuffer = Object.keys(arbitraryBytes).map(function (key) { return arbitraryBytes[key]; });
|
|
const arbitraryBytesBuffer = new Uint8Array(_arbitraryBytesBuffer)
|
|
|
|
const arbitraryBytesForSigning = Base58.decode(arbitraryBytesForSigningBase58)
|
|
const _arbitraryBytesForSigningBuffer = Object.keys(arbitraryBytesForSigning).map(function (key) { return arbitraryBytesForSigning[key]; });
|
|
const arbitraryBytesForSigningBuffer = new Uint8Array(_arbitraryBytesForSigningBuffer)
|
|
|
|
const _nonce = utils.int32ToBytes(nonce)
|
|
arbitraryBytesBuffer.set(_nonce, 112)
|
|
arbitraryBytesForSigningBuffer.set(_nonce, 112)
|
|
|
|
const signature = nacl.sign.detached(arbitraryBytesForSigningBuffer, keyPair.privateKey)
|
|
|
|
const signedBytes = utils.appendBuffer(arbitraryBytesBuffer, signature)
|
|
|
|
return signedBytes
|
|
}
|
|
|
|
export default signArbitrary
|