Skip to main content

recover

Callable

  • recover(data: string | SignatureObject, signatureOrV?: string, prefixedOrR?: string | boolean, s?: string, prefixed?: boolean): string

  • Recovers the Ethereum address which was used to sign the given data


    Parameters

    • data: string | SignatureObject

      Either a signed message, hash, or the signatureObject

    • optionalsignatureOrV: string

      signature or V

    • optionalprefixedOrR: string | boolean

      prefixed or R

    • optionals: string

      S value in signature

    • optionalprefixed: boolean

      (default: false) If the last parameter is true, the given message will NOT automatically be prefixed with "\\x19Ethereum Signed Message:\\n" + message.length + message, and assumed to be already prefixed and hashed.

    Returns string

    The Ethereum address used to sign this data

    const data = 'Some data';
    const sigObj = web3.eth.accounts.sign(data, '0xbe6383dad004f233317e46ddb46ad31b16064d14447a95cc1d8c8d4bc61c3728')

    > {
    message: 'Some data',
    messageHash: '0x1da44b586eb0729ff70a73c326926f6ed5a25f5b056e7f47fbc6e58d86871655',
    v: '0x1b',
    r: '0xa8037a6116c176a25e6fc224947fde9e79a2deaa0dd8b67b366fbdfdbffc01f9',
    s: '0x53e41351267b20d4a89ebfe9c8f03c04de9b345add4a52f15bd026b63c8fb150',
    signature: '0xa8037a6116c176a25e6fc224947fde9e79a2deaa0dd8b67b366fbdfdbffc01f953e41351267b20d4a89ebfe9c8f03c04de9b345add4a52f15bd026b63c8fb1501b'
    }

    // now recover
    web3.eth.accounts.recover(data, sigObj.v, sigObj.r, sigObj.s)

    > 0xEB014f8c8B418Db6b45774c326A0E64C78914dC0