Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should signPersonalMessage with the expected key when passed a withAppKeyOrigin', async function () {
const address = testAccount.address
const message = '0x68656c6c6f20776f726c64'
const privateKeyHex = '4fbe006f0e9c2374f53eb1aef1b6970d20206c61ea05ad9591ef42176eb842c0'
const privateKeyBuffer = new Buffer(privateKeyHex, 'hex')
const expectedSig = sigUtil.personalSign(privateKeyBuffer, { data: message })
const keyring = new SimpleKeyring([testAccount.key])
const sig = await keyring.signPersonalMessage(address, message, {
withAppKeyOrigin: 'someapp.origin.io',
})
assert.equal(expectedSig, sig, 'sign with app key generated private key')
})
it('should signPersonalMessage with the expected key when passed a withAppKeyOrigin', function (done) {
const address = firstAcct
const message = '0x68656c6c6f20776f726c64'
const privateKeyBuffer = Buffer.from('8e82d2d74c50e5c8460f771d38a560ebe1151a9134c65a7e92b28ad0cfae7151', 'hex')
const expectedSig = sigUtil.personalSign(privateKeyBuffer, { data: message })
keyring.deserialize({
mnemonic: sampleMnemonic,
numberOfAccounts: 1,
})
.then(() => {
return keyring.signPersonalMessage(address, message, {
withAppKeyOrigin: 'someapp.origin.io',
})
})
.then((sig) => {
assert.equal(sig, expectedSig, 'signed with app key')
done()
})
.catch((reason) => {
assert(!reason, reason.message)
async sign (data) {
const account = this.getWalletAddress()
if (this.useExternalWeb3) {
if (this.isServer) {
return this.web3.eth.sign(this.web3.utils.fromUtf8(data), account)
} else {
return this.web3.eth.personal.sign(this.web3.utils.fromUtf8(data), account)
}
}
return sigUtil.personalSign(this.getOwnerWalletPrivateKey(), { data })
}
personal_sign([data, _]) {
const privateKey = toBuffer(this.wallet.privateKey)
return sigUtil.personalSign(privateKey, { data })
}
getPersonalSignature(order, privateKey, verifyingContract) {
const orderHash = hashes.getOrderHash(order, verifyingContract)
const sig = sigUtil.personalSign(privateKey, {
data: orderHash,
})
const { v, r, s } = ethUtil.fromRpcSig(sig)
return {
signatory: `0x${ethUtil
.privateToAddress(privateKey)
.toString('hex')}`.toLowerCase(),
validator: verifyingContract.toLowerCase(),
version: signatures.PERSONAL_SIGN,
v,
r,
s,
}
},
getTypedDataSignature(order, privateKey, verifyingContract) {
async personalSign(signer, data) {
this._validateSigner(signer);
if (!data) throw new Error('Data to sign cannot be null');
return sigUtil.personalSign(this.wallet.getPrivateKey(), { data });
}
opts.getPrivateKey(msgParams.from, function(err, privateKey) {
if (err) return cb(err)
const serialized = sigUtil.personalSign(privateKey, msgParams)
cb(null, serialized)
})
}
sign() {
try {
const privateKey = this.walletStorage.privateKeyOf(this.currentMsg.from);
const serialized = sigUtil.personalSign(privateKey, this.currentMsg);
this.walletStorage.receiveSignMessageEvent(Object.assign(this.currentEvent, {data: serialized}));
} catch (e) {
this.walletStorage.receiveSignMessageEvent(Object.assign(this.currentEvent, {error: e}));
}
}
sign ({ address, data }) {
address = normalizeAddress(address)
const { wallet } = this._children.find(({ address: a }) => address === a) || {}
if (!wallet) {
throw new Error('Invalid address')
}
return addHexPrefix(EthSigUtil.personalSign(wallet.getPrivateKey(), { data }))
}
signPersonalMessage (address, msgHex, opts = {}) {
const privKey = this.getPrivateKeyFor(address, opts);
const privKeyBuffer = new Buffer(privKey, 'hex')
const sig = sigUtil.personalSign(privKeyBuffer, { data: msgHex })
return Promise.resolve(sig)
}