How to use the eth-sig-util.recoverTypedSignature 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 crossbario / autobahn-js / test / xbr / test_typed.js View on Github external
//data = data2;

// eth_util.toBuffer

//var msg_hash = eth_sig_utils.typedSignatureHash(data.message);
//console.log("MSGHASH", msg_hash);

var msg_hash = utils.hashStruct(data.primaryType, data.message, data.types);
console.log('MSG_HASH = ', eth_util.bufferToHex(msg_hash));

var msg_sig = eth_sig_utils.signTypedData(key, {data: data})
console.log("Ok, signed typed data using " + account.address)
console.log("SIGNATURE = " + msg_sig);

var signer = eth_sig_utils.recoverTypedSignature({data: data, sig: msg_sig});
signer = w3_utils.toChecksumAddress(signer);

if (signer === account.address) {
    console.log("Ok, verified signature was signed by " + signer);
} else {
    console.log("ERROR: signature verification failed");
}

// const typedData = {
// types: {
//     EIP712Domain: [
//         { name: 'name', type: 'string' },
//         { name: 'version', type: 'string' },
//         { name: 'chainId', type: 'uint256' },
//         { name: 'verifyingContract', type: 'address' },
//     ],
github crossbario / autobahn-js / test / xbr / eip712 / sign-cli.js View on Github external
'amount': new BigNumber('35000000000000000000'),
        'balance': 2000,
    },
}

//console.log(data);

//var key = eth_util.toBuffer(buyer_key_bytes);
var key = eth_util.toBuffer(buyer_key);

// eth_util.toBuffer
var sig = eth_sig_utils.signTypedData(key, {data: data})
console.log("Ok, signed typed data using " + account.address)
console.log("SIGNATURE = " + sig);

var signer = eth_sig_utils.recoverTypedSignature({data, sig});
signer = w3_utils.toChecksumAddress(signer);

if (signer === account.address) {
    console.log("Ok, verified signature was signed by " + signer);
} else {
    console.log("ERROR: signature verification failed");
}
github OriginProtocol / origin / origin-js / src / resources / marketplace.js View on Github external
async verifyListingSignature(listing, signer) {
    // grab the raw ipfs hash
    const ipfs_response = await this.ipfsService.loadFile(listing.ipfs.hash)
    const ipfs_data = await ipfs_response.json()
    const signature = ipfs_data.signature
    delete ipfs_data.signature
    listing.raw_ipfs_hash = this.contractService.web3.utils.sha3(stringify(ipfs_data))
    const signData = await this.contractService.getSignListingData(listing)
    const recoveredAddress =  recoverTypedSignature({ data: signData, sig: signature })
    delete listing.raw_ipfs_hash

    if (recoveredAddress == signer.toLowerCase()) {
      return true
    }
    console.log('Signature verification failed:', signData, ' recovered address:', recoveredAddress, ' signer:', signer)
  }
github MetaMask / eth-simple-keyring / test / index.js View on Github external
it('returns the expected value', async () => {
      const typedData = {
        types: {
          EIP712Domain: []
        },
        domain: {},
        primaryType: 'EIP712Domain',
        message: {}
      }

      await keyring.deserialize([privKeyHex])
      const sig = await keyring.signTypedData_v4(address, typedData)
      const restored = sigUtil.recoverTypedSignature({ data: typedData, sig: sig })
      assert.equal(restored, address, 'recovered address')
    })
  })
github MetaMask / eth-simple-keyring / test / index.js View on Github external
it('returns the expected value', async () => {
      const typedData = {"data":{"types":{"EIP712Domain":[{"name":"name","type":"string"},{"name":"version","type":"string"},{"name":"chainId","type":"uint256"},{"name":"verifyingContract","type":"address"}],"Person":[{"name":"name","type":"string"},{"name":"wallet","type":"address"}],"Mail":[{"name":"from","type":"Person"},{"name":"to","type":"Person"},{"name":"contents","type":"string"}]},"primaryType":"Mail","domain":{"name":"Ether Mail","version":"1","chainId":1,"verifyingContract":"0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"},"message":{"from":{"name":"Cow","wallet":"0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826"},"to":{"name":"Bob","wallet":"0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB"},"contents":"Hello, Bob!"}}}

      await keyring.deserialize([privKeyHex])
      const addresses = await keyring.getAccounts()
      const address = addresses[0]
      const sig = await keyring.signTypedData_v3(address, typedData.data)
      assert.equal(sig, expectedSig, 'verified signature')
      const signedData = Object.create(typedData)
      signedData.sig = sig
      const restored = sigUtil.recoverTypedSignature(signedData)
      assert.equal(restored, address, 'recovered address')
    })
  })
github MetaMask / eth-hd-keyring / test / index.js View on Github external
types: {
          EIP712Domain: []
        },
        domain: {},
        primaryType: 'EIP712Domain',
        message: {}
      }

      await keyring.deserialize({
        mnemonic: sampleMnemonic,
        numberOfAccounts: 1,
      })
      const addresses = await keyring.getAccounts()
      const address = addresses[0]
      const sig = await keyring.signTypedData_v3(address, typedData)
      const restored = sigUtil.recoverTypedSignature({ data: typedData, sig: sig })
      assert.equal(restored, address, 'recovered address')
    })
  })
github unlock-protocol / unlock / locksmith / src / middlewares / signatureValidationMiddleware.ts View on Github external
const extractTypeDataSignee = (header: string, body: any) => {
    const decodedSignature = Base64.decode(header)

    try {
      return sigUtil.recoverTypedSignature({
        data: body,
        sig: decodedSignature,
      })
    } catch {
      return null
    }
  }
github crossbario / autobahn-js / packages / autobahn-xbr / lib / eip712.js View on Github external
function recover_eip712_signer (channel_adr, channel_seq, balance, is_final, signature) {
    const msg = _create_eip712_data(verifying_adr, channel_adr, channel_seq, balance, is_final);
    const signer = eth_sig_utils.recoverTypedSignature({msg, signature});
    return w3_utils.toChecksumAddress(signer);
}
github pelith / express-eauth / lib / Eauth.js View on Github external
confirmTypedDataSignMessage(message, signature) {
    const typedData = [{
      type: 'string',
      name: 'banner',
      value: this.options.banner
    }, {
      type: 'string',
      name: 'message',
      value: this.options.prefix + message,
    }]

    const recoveredAddress = sigUtil.recoverTypedSignature({
      data: typedData,
      sig: signature
    })

    const storedMessage = cache.get(recoveredAddress.toLowerCase())

    if (storedMessage === message) {
      cache.del(recoveredAddress.toLowerCase())
      return recoveredAddress
    }

    return false
  }
}