@ethersproject/wallet#verifyMessage TypeScript Examples

The following examples show how to use @ethersproject/wallet#verifyMessage. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: signer.test.ts    From bodhi.js with Apache License 2.0 6 votes vote down vote up
describe('eth_accounts', () => {
  const signer = new Wallet('0x5a214c9bcb10dfe58af9b349cad6f4564cd6f10d880bdfcf780e5812c3cbc855');
  const provider = EvmRpcProvider.from(endpoint);

  const bridge = new Eip1193Bridge(provider, signer as any);

  it('returns accounts', async () => {
    const result = await bridge.send('eth_accounts');

    expect(result).deep.equal(['0x57a2423D1A30D90cECeC14c3844d88983F70659f']);
  });

  it('sign message', async () => {
    let err: any = {};
    try {
      await bridge.send('eth_sign', ['0xb00cB924ae22b2BBb15E10c17258D6a2af980421', '123']);
    } catch (error) {
      err = error;
    }

    expect(err?.message).equal('account mismatch or account not found');

    const result = await bridge.send('eth_sign', ['0x57a2423D1A30D90cECeC14c3844d88983F70659f', '123']);
    expect(verifyMessage('123', result)).equal('0x57a2423D1A30D90cECeC14c3844d88983F70659f');
  });

  after(() => {
    provider.disconnect();
  });
});
Example #2
Source File: index.ts    From nouns-monorepo with GNU General Public License v3.0 6 votes vote down vote up
handler: Handler = async (event, context) => {
  const checkResult = invalidBodyCheck(event.body);
  if (checkResult) {
    return {
      statusCode: 400,
      body: JSON.stringify(checkResult),
    };
  }
  const { message, signature, signer } = JSON.parse(event.body);
  const recoveredAddress = verifyMessage(message, signature);
  const validSignature = bigNumbersEqual(signer, recoveredAddress);

  // check for ownership and delegation
  let participantData = {};
  if (event.queryStringParameters.fetchParticipation && validSignature) {
    const normalizedNouns = await nounsQuery();
    participantData = {
      isNounDelegate: isNounDelegate(signer, normalizedNouns),
      isNounOwner: isNounOwner(signer, normalizedNouns),
    };
  }

  return {
    statusCode: 200,
    headers: {
      'Content-Type': 'application/json',
      ...sharedResponseHeaders,
    },
    body: JSON.stringify({
      message,
      signature,
      providedSigner: signer,
      recoveredAddress,
      validSignature,
      ...participantData,
    }),
  };
}