How to use the @colony/purser-core/helpers.messageOrDataValidator 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-trezor / staticMethods.js View on Github external
export const signMessage = async ({
  derivationPath,
  message,
  messageData,
}: Object = {}): Promise => {
  /*
   * Validate input values: derivationPath and message
   */
  derivationPathValidator(derivationPath);
  const toSign = messageOrDataValidator({ message, messageData });
  warning(messages.messageSignatureOnlyTrezor);
  try {
    const { signature: signedMessage = '' } = await payloadListener({
      payload: Object.assign({}, PAYLOAD_SIGNMSG, {
        /*
         * Path needs to be sent in as an derivation path array
         *
         * 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
github JoinColony / purser / modules / node_modules / @colony / purser-ledger / staticMethods.js View on Github external
export const signMessage = async ({
  derivationPath,
  message,
  messageData,
}: Object = {}): Promise => {
  /*
   * Validate input values: derivationPath and message
   */
  derivationPathValidator(derivationPath);
  const toSign = messageOrDataValidator({ message, messageData });
  try {
    const ledger: LedgerInstanceType = await ledgerConnection();
    /*
     * Sign the message object via your Ledger Wallet
     *
     * We also warn the user here, since the device will need confirmation, but only in dev mode.
     */
    warning(messages.userSignMessageInteractionWarning);
    const {
      r: rSignatureComponent,
      s: sSignatureComponent,
      v: recoveryParameter,
      /*
       * Flow bugs out here claiming the `r` property is not available on the return object.
       */
      /* $FlowFixMe */
github JoinColony / purser / modules / node_modules / @colony / purser-metamask / staticMethods.js View on Github external
export const signMessage = async ({
  currentAddress,
  message,
  messageData,
}: Object = {}): Promise => {
  addressValidator(currentAddress);
  const toSign = messageOrDataValidator({ message, messageData });
  /*
   * We must check for the Metamask injected in-page proxy every time we
   * try to access it. This is because something can change it from the time
   * of last detection until now.
   */
  return methodCaller(
    /*
     * @TODO Move into own (non-anonymous) method
     * This way we could better test it
     */
    () =>
      new Promise((resolve, reject) => {
        /*
         * Sign the message. This will prompt the user via Metamask's UI
         */
        signMessageMethodLink(
github JoinColony / purser / modules / node_modules / @colony / purser-software / staticMethods.js View on Github external
export const signMessage = async (
  { message, messageData, callback }: Object = {},
): Promise => {
  /*
   * Validate input value
   */
  const toSign = messageOrDataValidator({ message, messageData });
  try {
    const messageSignature: string = await callback(toSign);
    /*
     * Normalize the message signature
     */
    return hexSequenceNormalizer(messageSignature);
  } catch (caughtError) {
    throw new Error(
      `${messages.cannotSignMessage}: ${message} Error: ${caughtError.message}`,
    );
  }
};