speakeasyjs / speakeasy

**NOT MAINTAINED** Two-factor authentication for Node.js. One-time passcode generator (HOTP/TOTP) with support for Google Authenticator.
MIT License
2.69k stars 228 forks source link

Updated Typescript Typings #90

Closed jineshshah36 closed 2 years ago

jineshshah36 commented 7 years ago

I have put together an updated typescript typings file, but I'm not quite sure how to provide/include it. I'll include it here. If there is a way to add it, please let me know. Otherwise, feel free to use this.

declare module "speakeasy" {
  export = speakeasy

  interface SharedOptions {
    encoding?: string
    algorithm?: string
  }

  interface DigestOptions extends SharedOptions {
    secret: string
    counter: number
  }

  interface HOTPOptions extends SharedOptions {
    secret: string
    counter: number
    digest?: Buffer
    digits?: number
  }

  interface HOTPVerifyOptions extends SharedOptions {
    secret: string
    token: string
    counter: number
    digits?: number
    window?: number
  }

  interface TOTPOptions extends SharedOptions {
    secret: string
    time?: number
    step?: number
    epoch?: number
    counter?: number
    digits?: number
  }

  interface TOTPVerifyOptions extends SharedOptions {
    secret: string
    token: string
    time?: number
    step?: number
    epoch?: number
    counter?: number
    digits?: number
    window?: number
  }

  interface GenerateSecretOptions {
    length?: number
    symbols?: boolean
    otpauth_url?: boolean
    name?: string
    issuer?: string
  }

  interface GeneratedSecret {
    ascii: string
    hex: string
    base32: string
    qr_code_ascii: string
    qr_code_hex: string
    qr_code_base32: string
    google_auth_qr: string
    otpauth_url: string
  }

  interface OTPAuthURLOptions extends SharedOptions {
    secret: string
    label: string
    type?: string
    counter?: number
    issuer?: string
    digits?: number
    period?: number
  }

  interface Speakeasy {
    digest: (options: DigestOptions) => Buffer
    hotp: {
      (options: HOTPOptions): string,
      verifyDelta: (options: HOTPVerifyOptions) => boolean,
      verify: (options: HOTPVerifyOptions) => boolean,
    }
    totp: {
      (options: TOTPOptions): string
      verifyDelta: (options: TOTPVerifyOptions) => boolean,
      verify: (options: TOTPVerifyOptions) => boolean,
    }
    generateSecret: (options?: GenerateSecretOptions) => GeneratedSecret
    generateSecretASCII: (length?: number, symbols?: boolean) => string
    otpauthURL: (options: OTPAuthURLOptions) => string
  }

  const speakeasy: Speakeasy
}
jakelee8 commented 7 years ago

Thanks for the contribution!

We're working on an Object-Oriented Typescript rewrite of Speakeasy at https://github.com/speakeasyjs/libotp

It's a work in progress and we would love your contributions there as well.

jineshshah36 commented 7 years ago

Good to know, I'll take a look