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.

39 lines
1.3 KiB

3 years ago
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')
}
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 arbitraryBytes = Base58.decode(arbitraryBytesBase58)
const _arbitraryBytesBuffer = Object.keys(arbitraryBytes).map(function (key) { return arbitraryBytes[key]; })
const arbitraryBytesBuffer = new Uint8Array(_arbitraryBytesBuffer)
3 years ago
const arbitraryBytesForSigning = Base58.decode(arbitraryBytesForSigningBase58)
const _arbitraryBytesForSigningBuffer = Object.keys(arbitraryBytesForSigning).map(function (key) { return arbitraryBytesForSigning[key]; })
const arbitraryBytesForSigningBuffer = new Uint8Array(_arbitraryBytesForSigningBuffer)
3 years ago
const _nonce = utils.int32ToBytes(nonce)
arbitraryBytesBuffer.set(_nonce, 112)
arbitraryBytesForSigningBuffer.set(_nonce, 112)
3 years ago
const signature = nacl.sign.detached(arbitraryBytesForSigningBuffer, keyPair.privateKey)
3 years ago
const signedBytes = utils.appendBuffer(arbitraryBytesBuffer, signature)
3 years ago
return signedBytes
3 years ago
}
export default signArbitrary