How to use the eth-sig-util.signTypedData 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 dreamteam-gg / smart-contracts / test / token / DreamTeamToken.js View on Github external
value = 4 * 10 ** decimals;
            from = newAccount.address;
            // to = strangerAccount;
            // from = account1;
            to = web3m.eth.accounts.create().address;
            delegate = dreamTeamAccount;
            fee = 2 * 10 ** decimals - 1;
            deadline = (await web3m.eth.getBlock(`latest`)).timestamp + 60 * 60 * 24 * 7; // +7 days
            usedSigId = sigId++;
            const dataToSign = getTypedDataToSign();
            await token.transfer(from, 4 * (value + fee), { from: dreamTeamAccount });
            const balanceFrom = +(await token.balanceOf.call(from));
            assert.equal(balanceFrom, 4 * (value + fee), "Account balance must be refilled");
            const balanceTo = +(await token.balanceOf.call(to));
            const balanceDelegate = +(await token.balanceOf.call(delegate));
            signature = sigUtils.signTypedData(
                Buffer.from(newAccount.privateKey.slice(2), "hex"),
                { data: dataToSign }
            );
            const tx = await token.transferViaSignature(
                from, to, value, fee, delegate, deadline, usedSigId, signature, SIG_STANDARD_TYPED, { from: delegate }
            );
            infoLog(`TX (transferViaSignature) gas usage: ${ getUsedGas(tx) }`);
            assert.equal(+(await token.balanceOf(from)), balanceFrom - value - fee, "Must subtract balance");
            assert.equal(+(await token.balanceOf(to)), balanceTo + value, "Must add balance to recipient");
            assert.equal(+(await token.balanceOf(delegate)), balanceDelegate + fee, "Must pay fee to delegate");

        });
github pixowl / thesandbox-contracts / test / asset / signed_auctions.js View on Github external
function getSignature() {
            return ethSigUtil.signTypedData(privateKey, {
                data: {
                types: {
                    EIP712Domain: domainType,
                    Auction: auctionType
                },
                domain: getDomainData(),
                primaryType: 'Auction',
                message: getAuctionData()
                }
            });
        }
github pixowl / thesandbox-contracts / test / sand-utils.js View on Github external
verifyingContract: contractAddress
    },
    message: {
      from: from || signingAcount.address,
      to,
      amount,
      data,
      nonce,
      gasPrice,
      txGas,
      gasLimit,
      tokenGasPrice,
      relayer
    }
  };
  return sigUtil.signTypedData(privateKeyAsBuffer, {data: data712});
}
github unlock-protocol / unlock / unlock-js / src / unlockProvider.js View on Github external
signData(data) {
    const privateKey = toBuffer(this.wallet.privateKey)
    const sig = sigUtil.signTypedData(privateKey, { data })
    return {
      data,
      sig,
    }
  }
github unlock-protocol / unlock / locksmith / scripts / metadataUpload / metadata_upload.ts View on Github external
function generateSignature(privateKey: string, data: any) {
  let pk = ethJsUtil.toBuffer(privateKey)

  return sigUtil.signTypedData(pk, {
    data,
  })
}
github OpenZeppelin / openzeppelin-gsn-provider / src / PrivateKeyProvider.js View on Github external
async ethSignTypedData(signer, data) {
    this._validateSigner(signer);
    if (!data) throw new Error('Data to sign cannot be null');
    return sigUtil.signTypedData(this.wallet.getPrivateKey(), { data });
  }
github unlock-protocol / unlock / locksmith / scripts / metadataUpload / user_metadata_upload.ts View on Github external
function generateSignature(privateKey: string, data: any) {
  let pk = ethJsUtil.toBuffer(privateKey)

  return sigUtil.signTypedData(pk, {
    data,
  })
}