How to use the @colony/purser-core/normalizers.hexSequenceNormalizer 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
{},
        {
          /*
           * We could really do with some BN.js flow types declarations :(
           */
          gasPrice: hexSequenceNormalizer(
            /*
             * @TODO Add `bigNumber` `toHexString` wrapper method
             *
             * Flow confuses bigNumber's `toString` with the String object
             * prototype `toString` method
             */
            /* $FlowFixMe */
            multipleOfTwoHexValueNormalizer(gasPrice.toString(16)),
          ),
          gasLimit: hexSequenceNormalizer(
            /*
             * @TODO Add `bigNumber` `toHexString` wrapper method
             *
             * Flow confuses bigNumber's `toString` with the String object
             * prototype `toString` method
             */
            /* $FlowFixMe */
            multipleOfTwoHexValueNormalizer(gasLimit.toString(16)),
          ),
          /*
           * Nonces needs to be sent in as a hex string, and to be padded as a multiple of two.
           * Eg: '3' to be '03', `12c` to be `012c`
           */
          nonce: hexSequenceNormalizer(
            /*
             * @TODO Add `bigNumber` `toHexString` wrapper method
github JoinColony / purser / modules / node_modules / @colony / purser-trezor / staticMethods.js View on Github external
* prototype `toString` method
       */
      /* $FlowFixMe */
      nonce: multipleOfTwoHexValueNormalizer(nonce.toString(16)),
      /*
       * @TODO Add `bigNumber` `toHexString` wrapper method
       *
       * Flow confuses bigNumber's `toString` with the String object
       * 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:
github JoinColony / purser / modules / node_modules / @colony / purser-ledger / staticMethods.js View on Github external
*/
            /* $FlowFixMe */
            multipleOfTwoHexValueNormalizer(value.toString(16)),
          ),
          data: hexSequenceNormalizer(inputData),
          /*
           * The transaction object needs to be seeded with the (R) and (S) signature components with
           * empty data, and the Reco(V)ery param as the chain id (all, im hex string format).
           *
           * See this issue for context:
           * https://github.com/LedgerHQ/ledgerjs/issues/43
           */
          r: hexSequenceNormalizer(
            multipleOfTwoHexValueNormalizer(String(SIGNATURE.R)),
          ),
          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),
github JoinColony / purser / modules / node_modules / @colony / purser-trezor / staticMethods.js View on Github external
),
      gasLimit: hexSequenceNormalizer(
        /*
         * @TODO Add `bigNumber` `toHexString` wrapper method
         *
         * Flow confuses bigNumber's `toString` with the String object
         * prototype `toString` method
         */
        /* $FlowFixMe */
        multipleOfTwoHexValueNormalizer(gasLimit.toString(16)),
      ),
      /*
       * Nonces needs to be sent in as a hex string, and to be padded as a multiple of two.
       * Eg: '3' to be '03', `12c` to be `012c`
       */
      nonce: hexSequenceNormalizer(
        /*
         * @TODO Add `bigNumber` `toHexString` wrapper method
         *
         * Flow confuses bigNumber's `toString` with the String object
         * prototype `toString` method
         */
        /* $FlowFixMe */
        multipleOfTwoHexValueNormalizer(nonce.toString(16)),
      ),
      value: hexSequenceNormalizer(
        /*
         * @TODO Add `bigNumber` `toHexString` wrapper method
         *
         * Flow confuses bigNumber's `toString` with the String object
         * prototype `toString` method
         */
github JoinColony / purser / modules / node_modules / @colony / purser-trezor / staticMethods.js View on Github external
* We also normalize it first (but for some reason Flow doesn't pick up
         * the default value value of `path` and assumes it's undefined -- it can be,
         * but it will not pass the validator)
         */
        path: fromString(
          derivationPathNormalizer(derivationPath),
          true,
        ).toPathArray(),
        // $FlowFixMe need Buffer types
        message: Buffer.from(toSign).toString(HEX_HASH_TYPE),
      }),
    });
    /*
     * Add the hex `0x` prefix
     */
    return hexSequenceNormalizer(signedMessage);
  } catch (caughtError) {
    /*
     * If the user cancels signing the message we still throw,
     * but we customize the message
     */
    if (caughtError.message === STD_ERRORS.CANCEL_TX_SIGN) {
      throw new Error(messages.userSignTxCancel);
    }
    /*
     * But throw otherwise, so we can see what's going on
     */
    throw new Error(
      `${messages.userSignTxGenericError}: message: (${message}) ${
        caughtError.message
      }`,
    );
github JoinColony / purser / modules / node_modules / @colony / purser-metamask / staticMethods.js View on Github external
* but we customize the message
         */
        if (error.message.includes(STD_ERRORS.CANCEL_MSG_SIGN)) {
          throw new Error(messages.cancelMessageSign);
        }
        throw new Error(error.message);
      }

      /*
       * Validate that the signature is in the correct format
       */
      hexSequenceValidator(messageSignature);
      /*
       * Add the `0x` prefix to the message's signature
       */
      const normalizedSignature: string = hexSequenceNormalizer(
        messageSignature,
      );
      return resolve(normalizedSignature);
    } catch (caughtError) {
      return reject(caughtError);
    }
  };
github JoinColony / purser / modules / node_modules / @colony / purser-metamask / class.js View on Github external
(error: Error, signature: string) => {
              try {
                /*
                 * Validate that the signature is in the correct format
                 */
                hexSequenceValidator(signature);
                const recoveredPublicKey: string = recoverPublicKeyHelper({
                  message: PUBLICKEY_RECOVERY_MESSAGE,
                  signature,
                });
                /*
                 * Add the `0x` prefix to the recovered public key
                 */
                const normalizedPublicKey: string = hexSequenceNormalizer(
                  recoveredPublicKey,
                );
                /*
                 * Also set the internal public key
                 */
                internalPublicKey = normalizedPublicKey;
                return resolve(normalizedPublicKey);
              } catch (caughtError) {
                /*
                 * Don't throw an Error if the user just cancels signing the message.
                 * This is normal UX, not an exception
                 */
                if (error.message.includes(STD_ERRORS.CANCEL_MSG_SIGN)) {
                  return warning(staticMethodsMessages.cancelMessageSign);
                }
                throw new Error(error.message);
github JoinColony / purser / modules / node_modules / @colony / purser-software / class.js View on Github external
return (async () => {
      const privateKey: string = await this.privateKey;
      const reversedPublicKey: string = privateToPublic(privateKey).toString(
        HEX_HASH_TYPE,
      );
      /*
       * Validate the reversed public key
       */
      hexSequenceValidator(reversedPublicKey);
      /*
       * Then normalize it to ensure it has the `0x` prefix
       */
      const normalizedPublicKey: string = hexSequenceNormalizer(
        reversedPublicKey,
      );
      /*
       * Memoizing the getter
       *
       * While this is not an expensive operation, it's still a good idea
       * to memoize it so it returns a tiny bit faster.
       */
      Object.defineProperty(
        (this: any),
        'publicKey',
        Object.assign({}, GETTERS, {
          value: Promise.resolve(normalizedPublicKey),
        }),
      );
      return normalizedPublicKey;
github JoinColony / purser / modules / node_modules / @colony / purser-trezor / staticMethods.js View on Github external
*
     * recoveryParam - 35 - (chainId * 2)
     *
     * If the result is odd, then V is 27, if it's even, it's 28
     */
    const {
      r: rSignatureComponent,
      s: sSignatureComponent,
      v: recoveryParameter,
    }: Object = await payloadListener({ payload: modifiedPayloadObject });
    /*
     * Add the signature values to the unsigned trasaction
     */
    unsignedTransaction.r = hexSequenceNormalizer(rSignatureComponent);
    unsignedTransaction.s = hexSequenceNormalizer(sSignatureComponent);
    unsignedTransaction.v = hexSequenceNormalizer(
      bigNumber(recoveryParameter).toString(16),
    );
    return hexSequenceNormalizer(
      unsignedTransaction.serialize().toString(HEX_HASH_TYPE),
    );
  } catch (caughtError) {
    /*
     * If the user cancels signing the transaction we still throw,
     * but we customize the message.
     */
    if (caughtError.message === STD_ERRORS.CANCEL_TX_SIGN) {
      throw new Error(messages.userSignTxCancel);
    }
    /*
     * But throw otherwise, so we can see what's going on
     */
github JoinColony / purser / modules / node_modules / @colony / purser-metamask / staticMethods.js View on Github external
data: signedData,
          gasLimit: new BigNumber(gas),
          gasPrice: new BigNumber(signedGasPrice),
          nonce: new BigNumber(nonce),
          r,
          s,
          to: signedTo,
          v,
          value: new BigNumber(signedValue),
        },
        getChainDefinition(chainId),
      );
      const serializedSignedTransaction = signedTransaction
        .serialize()
        .toString(HEX_HASH_TYPE);
      const normalizedSignedTransaction = hexSequenceNormalizer(
        serializedSignedTransaction,
      );
      return resolve(normalizedSignedTransaction);
    } catch (caughtError) {
      return reject(caughtError);
    }
  };