Skip to content

feature: can I add IsMnemonic validation #1509

@Hathoriel

Description

@Hathoriel

Description

I would like to add mnemonic validation

Proposed solution

import BigNumber from 'bignumber.js'

export const IsMnemonic = (validationOptions?: ValidationOptions) =>
  function (object: Object, propertyName: string) {
    registerDecorator({
      name: 'isMnemonic',
      target: object.constructor,
      propertyName: propertyName,
      options: {
        message: 'Mnemonic must contains between 12 and 24 words. Remove white spaces at end and start from your mnemonic.',
        ...validationOptions,
      },
      validator: {
        validate(value: any) {
          const bigNumberValue = new BigNumber(value.split(' ').length)
          return bigNumberValue.lte(24) && bigNumberValue.gte(12)
        },
      },
    })
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    flag: needs discussionIssues which needs discussion before implementation.type: featureIssues related to new features.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions