ethereumjs-util#stripHexPrefix TypeScript Examples

The following examples show how to use ethereumjs-util#stripHexPrefix. 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: ethsign.page.ts    From Elastos.Essentials.App with MIT License 6 votes vote down vote up
async confirmSign(): Promise<void> {
    const payPassword = await this.authService.getWalletPassword(this.networkWallet.masterWallet.id, true, true);
    if (payPassword === null) { // cancelled by user
      await this.cancelOperation();
      return;
    }

    let privateKeyHexNoprefix = await this.walletManager.spvBridge.exportETHSCPrivateKey(jsToSpvWalletId(this.networkWallet.masterWallet.id), this.evmSubWallet.id, payPassword);

    let privateKey = Buffer.from(privateKeyHexNoprefix, "hex");

    // Implementation taken from Metamask unsafe signing:
    // https://github.com/MetaMask/eth-simple-keyring/blob/main/index.js
    try {
      const message = stripHexPrefix(this.payloadToBeSigned);
      const msgSig = ecsign(Buffer.from(message, 'hex'), privateKey);
      const rawMsgSig = toRpcSig(msgSig.v, msgSig.r, msgSig.s);

      void this.sendIntentResponse({
        signedData: rawMsgSig
      }, this.receivedIntent.intentId);
    }
    catch (e) {
      // Sign method can throw exception in case some provided content has an invalid format
      // i.e.: array value, with "address" type. In such case, we fail silently.
      Logger.warn('wallet', 'eth_sign intent error:', e)
      await this.sendIntentResponse(
        { data: null },
        this.receivedIntent.intentId
      );
    }
  }
Example #2
Source File: prepare-fee-for-exchange-wrapper.ts    From ethereum-sdk with MIT License 5 votes vote down vote up
export function prepareForExchangeWrapperFees(fees: Part[]): string[] {
	return fees.map(fee => {
		const addr = stripHexPrefix(fee.account)
		const preparedFee = new BN(fee.value, 10).toString(16).padStart(24, "0")
		return new BN(preparedFee + addr, 16).toString(10)
	})
}