How to use the @colony/purser-core/normalizers.addressNormalizer function in @colony/purser-core

To help you get started, we’ve selected a few @colony/purser-core 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 JoinColony / purser / modules / node_modules / @colony / purser-ledger / staticMethods.js View on Github external
),
          s: hexSequenceNormalizer(
            multipleOfTwoHexValueNormalizer(String(SIGNATURE.S)),
          ),
          v: hexSequenceNormalizer(
            /*
             * @TODO Add `bigNumber` `toHexString` wrapper method
             *
             * Flow confuses bigNumber's `toString` with the String object
             * prototype `toString` method
             */
            /* $FlowFixMe */
            multipleOfTwoHexValueNormalizer(chainId.toString(16)),
          ),
        },
        to ? { to: addressNormalizer(to) } : {},
      ),
      getChainDefinition(chainId),
    );
    /*
     * Sign the transaction object via your Ledger Wallet
     *
     * We also warn the user here, since the device will need confirmation, but only in dev mode.
     */
    warning(messages.userSignInteractionWarning);
    const {
      r: rSignatureComponent,
      s: sSignatureComponent,
      v: recoveryParameter,
    } = await ledger.signTransaction(
      derivationPathNormalizer(derivationPath),
      unsignedTransaction.serialize().toString(HEX_HASH_TYPE),
github JoinColony / purser / modules / node_modules / @colony / purser-trezor / staticMethods.js View on Github external
* prototype `toString` method
       */
      /* $FlowFixMe */
      value: multipleOfTwoHexValueNormalizer(value.toString(16)),
      /*
       * Trezor service requires the prefix from the input data to be stripped
       */
      data: hexSequenceNormalizer(inputData, false),
    },
    /*
     * Only send (and normalize) the destingation address if one was
     * provided in the initial transaction object.
     *
     * Trezor service requires the prefix from the address to be stripped
     */
    to ? { to: addressNormalizer(to, false) } : {},
  );
  /*
   * We need to catch the cancelled error since it's part of a normal user workflow
   */
  try {
    /*
     * See fundamentals of Elliptic Curve Digital Signature Algorithm (ECDSA) to
     * get an general idea of where the three components come from:
     * https://en.wikipedia.org/wiki/Elliptic_Curve_Digital_Signature_Algorithm
     *
     * Also, see EIP-155 for the 27 and 28 magic numbers expected in the recovery
     * parameter:
     * https://github.com/ethereum/EIPs/blob/master/EIPS/eip-155.md
     *
     * Now, trezor will give you the recovery paramenter already encoded, but if you
     * want to derive the magic numbers again:
github JoinColony / purser / modules / node_modules / @colony / purser-metamask / staticMethods.js View on Github external
}

      /*
       * Validate that the recovered address is correct
       */
      addressValidator(recoveredAddress);
      /*
       * Add the `0x` prefix to the recovered address
       */
      const normalizedRecoveredAddress: string = addressNormalizer(
        recoveredAddress,
      );
      /*
       * Add the `0x` prefix to the current address
       */
      const normalizedCurrentAddress: string = addressNormalizer(
        currentAddress,
      );
      return resolve(
        normalizedRecoveredAddress === normalizedCurrentAddress,
      );
    } catch (caughtError) {
      return reject(caughtError);
    }
  };
github JoinColony / purser / modules / node_modules / @colony / purser-trezor / staticMethods.js View on Github external
*/
  addressValidator(address);
  /*
   * Validate the rest of the pros using the core helper
   */
  const { message, signature } = messageVerificationObjectValidator(
    signatureMessage,
  );
  warning(messages.messageSignatureOnlyTrezor);
  try {
    const { success: isMessageValid } = await payloadListener({
      payload: Object.assign({}, PAYLOAD_VERIFYMSG, {
        /*
         * Trezor service requires the prefix from the address to be stripped
         */
        address: addressNormalizer(address, false),
        message,
        /*
         * Trezor service requires the prefix from the signature to be stripped
         */
        signature: hexSequenceNormalizer(signature, false),
      }),
    });
    return isMessageValid;
  } catch (caughtError) {
    warning(
      `${
        messages.messageSignatureInvalid
      }: message (${message}), signature (${signature})`,
    );
    return false;
  }
github JoinColony / purser / modules / node_modules / @colony / purser-metamask / staticMethods.js View on Github external
*/
              value: value.toString(),
              gas: gasLimit.toString(),
              gasPrice: gasPrice.toString(),
              data: hexSequenceNormalizer(inputData),
              chainId,
              /*
               * Most likely this value is `undefined`, but that is good (see above)
               */
              nonce: manualNonce,
            },
            /*
             * Only send (and normalize) the destination address if one was
             * provided in the initial transaction object.
             */
            to ? { to: addressNormalizer(to) } : {},
          ),
          signTransactionCallback(chainId, resolve, reject),
        ),
      ),
github JoinColony / purser / modules / node_modules / @colony / purser-software / staticMethods.js View on Github external
* Ethers needs it's own "proprietary" version of bignumber to work.
           */
          gasLimit: bigNumberify(gasLimit.toString()),
          chainId,
          nonce,
          /*
           * Ethers needs it's own "proprietary" version of bignumber to work.
           */
          value: bigNumberify(value.toString()),
          data: hexSequenceNormalizer(inputData),
        },
        /*
         * Only send (and normalize) the destination address if one was
         * provided in the initial transaction object.
         */
        to ? { to: addressNormalizer(to) } : {},
      ),
    );
    return hexSequenceNormalizer(signedTransaction);
  } catch (caughtError) {
    throw new Error(
      `${messages.cannotSign} ${objectToErrorString({
        gasPrice,
        gasLimit,
        chainId,
        nonce,
        to,
        value,
        inputData,
      })} Error: ${caughtError.message}`,
    );
  }
github JoinColony / purser / modules / node_modules / @colony / purser-metamask / staticMethods.js View on Github external
new Promise((resolve, reject) =>
        signTransactionMethodLink(
          Object.assign(
            {},
            {
              from: addressNormalizer(from),
              /*
              * We don't need to normalize these three values since Metamask accepts
              * number values directly, so we don't need to convert them to hex
              */
              value: value.toString(),
              gas: gasLimit.toString(),
              gasPrice: gasPrice.toString(),
              data: hexSequenceNormalizer(inputData),
              chainId,
              /*
               * Most likely this value is `undefined`, but that is good (see above)
               */
              nonce: manualNonce,
            },
            /*
             * Only send (and normalize) the destination address if one was
github JoinColony / purser / modules / node_modules / @colony / purser-metamask / staticMethods.js View on Github external
(error: Error, recoveredAddress: string) => {
    try {
      if (error) {
        throw new Error(error.message);
      }

      /*
       * Validate that the recovered address is correct
       */
      addressValidator(recoveredAddress);
      /*
       * Add the `0x` prefix to the recovered address
       */
      const normalizedRecoveredAddress: string = addressNormalizer(
        recoveredAddress,
      );
      /*
       * Add the `0x` prefix to the current address
       */
      const normalizedCurrentAddress: string = addressNormalizer(
        currentAddress,
      );
      return resolve(
        normalizedRecoveredAddress === normalizedCurrentAddress,
      );
    } catch (caughtError) {
      return reject(caughtError);
    }
  };