How to use the eth-sig-util.personalSign 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('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')
    })
github MetaMask / eth-hd-keyring / test / index.js View on Github external
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)
github AudiusProject / audius-protocol / libs / src / services / web3Manager / index.js View on Github external
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 })
  }
github unlock-protocol / unlock / unlock-js / src / unlockProvider.js View on Github external
personal_sign([data, _]) {
    const privateKey = toBuffer(this.wallet.privateKey)
    return sigUtil.personalSign(privateKey, { data })
  }
github airswap / airswap-protocols / utils / order-utils / src / signatures.js View on Github external
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) {
github OpenZeppelin / openzeppelin-gsn-provider / src / PrivateKeyProvider.js View on Github external
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 });
  }
github MetaMask / web3-provider-engine / subproviders / hooked-wallet-ethtx.js View on Github external
opts.getPrivateKey(msgParams.from, function(err, privateKey) {
      if (err) return cb(err)
      const serialized = sigUtil.personalSign(privateKey, msgParams)
      cb(null, serialized)
    })
  }
github MuzikaFoundation / muzika-platform / projects / studio-renderer / src / modules / wallet / pages / sign-personal-message / sign-personal-message.component.ts View on Github external
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}));
    }
  }
github meth / eth-hd-wallet / src / index.js View on Github external
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 }))
  }
github MetaMask / eth-simple-keyring / index.js View on Github external
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)
  }