@ethersproject/bytes#Bytes TypeScript Examples

The following examples show how to use @ethersproject/bytes#Bytes. 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: utils.ts    From evm-provider.js with Apache License 2.0 7 votes vote down vote up
export function createClaimEvmSignature(substrateAddress: string): Bytes {
  const publicKeySubstrate = decodeAddress(substrateAddress);
  let message: Bytes | string =
    'reef evm:' + Buffer.from(publicKeySubstrate).toString('hex');

  if (typeof message === 'string') {
    message = toUtf8Bytes(message);
  }

  return message;
}
Example #2
Source File: Signer.ts    From bodhi.js with Apache License 2.0 6 votes vote down vote up
/**
   *
   * @param message The message to sign
   * @returns A promise that resolves to the signed hash of the message
   */
  async signMessage(message: Bytes | string): Promise<string> {
    const evmAddress = await this.queryEvmAddress();
    return this._signMessage(evmAddress, message);
  }
Example #3
Source File: Signer.ts    From bodhi.js with Apache License 2.0 6 votes vote down vote up
async _signMessage(evmAddress: string, message: Bytes | string): Promise<string> {
    if (!evmAddress) {
      return logger.throwError('No binding evm address');
    }
    const messagePrefix = '\x19Ethereum Signed Message:\n';
    if (typeof message === 'string') {
      message = toUtf8Bytes(message);
    }
    const msg = u8aToHex(concat([toUtf8Bytes(messagePrefix), toUtf8Bytes(String(message.length)), message]));

    if (!this.signingKey.signRaw) {
      return logger.throwError('Need to implement signRaw method');
    }

    const result = await this.signingKey.signRaw({
      address: evmAddress,
      data: msg,
      type: 'bytes'
    });

    return joinSignature(result.signature);
  }
Example #4
Source File: Signer.ts    From evm-provider.js with Apache License 2.0 6 votes vote down vote up
/**
   *
   * @param message The message to sign
   * @returns A promise that resolves to the signed hash of the message
   */
  async signMessage(message: Bytes | string): Promise<string> {
    const evmAddress = await this.queryEvmAddress();
    return this._signMessage(evmAddress, message);
  }
Example #5
Source File: Signer.ts    From evm-provider.js with Apache License 2.0 6 votes vote down vote up
async _signMessage(
    evmAddress: string,
    message: Bytes | string
  ): Promise<string> {
    if (!evmAddress) {
      return logger.throwError('No binding evm address');
    }
    const messagePrefix = '\x19Ethereum Signed Message:\n';
    if (typeof message === 'string') {
      message = toUtf8Bytes(message);
    }
    const msg = u8aToHex(
      concat([
        toUtf8Bytes(messagePrefix),
        toUtf8Bytes(String(message.length)),
        message
      ])
    );

    if (!this.signingKey.signRaw) {
      return logger.throwError('Need to implement signRaw method');
    }

    const result = await this.signingKey.signRaw({
      address: evmAddress,
      data: msg,
      type: 'bytes'
    });

    return joinSignature(result.signature);
  }
Example #6
Source File: adapter.ts    From cloud-cryptographic-wallet with MIT License 5 votes vote down vote up
async signMessage(message: Bytes | string): Promise<string> {
    const digest = hashMessage(message);
    const signature = await this.signer.sign(
      Buffer.from(digest.slice(2), "hex")
    );

    return signature.toString();
  }
Example #7
Source File: kms-ethers-signer.ts    From cloud-cryptographic-wallet with MIT License 5 votes vote down vote up
async signMessage(message: Bytes | string): Promise<string> {
    return this.adapter.signMessage(message);
  }
Example #8
Source File: index.ts    From ccip-read with MIT License 5 votes vote down vote up
signMessage(message: string | Bytes): Promise<string> {
    return this.parent.signMessage(message);
  }