How to use the eth-sig-util.encrypt function in eth-sig-util

To help you get started, we’ve selected a few eth-sig-util examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github MetaMask / eth-simple-keyring / test / index.js View on Github external
it('returns the expected value', async () => {
      const address = '0xbe93f9bacbcffc8ee6663f2647917ed7a20a57bb'
      const privateKey = new Buffer('6969696969696969696969696969696969696969696969696969696969696969', 'hex')
      const privKeyHex = ethUtil.bufferToHex(privateKey)
      const message = 'Hello world!'
      const encryptedMessage = sigUtil.encrypt(sigUtil.getEncryptionPublicKey(privateKey), {'data': message}, 'x25519-xsalsa20-poly1305')

      await keyring.deserialize([privKeyHex])
      const decryptedMessage = await keyring.decryptMessage(address, encryptedMessage)
      assert.equal(message, decryptedMessage, 'signature matches')
    })
  })