From fab066becaaeae561b79351f6245f04d3beb5331 Mon Sep 17 00:00:00 2001 From: Aayush Kapoor Date: Wed, 10 Jan 2018 23:44:56 +0530 Subject: [PATCH] speakeasy: Update definition for missing functions (#22717) * Update speakeasy.d.ts for missing functions * Update tests for speakeasy * Fix namespace export for speakeasy * Update speakeasy to remove UMD definition --- types/speakeasy/index.d.ts | 77 ++++++++++++++++++++---------- types/speakeasy/speakeasy-tests.ts | 10 +++- 2 files changed, 60 insertions(+), 27 deletions(-) diff --git a/types/speakeasy/index.d.ts b/types/speakeasy/index.d.ts index 4e281f996f..06d79ea6aa 100644 --- a/types/speakeasy/index.d.ts +++ b/types/speakeasy/index.d.ts @@ -1,8 +1,13 @@ // Type definitions for speakeasy v2.0.0 -// Project: https://github.com/markbao/speakeasy -// Definitions by: Lucas Woo , Alexander Batukhtin +// Project: https://github.com/speakeasyjs/speakeasy +// Definitions by: Lucas Woo , Alexander Batukhtin , Aayush Kapoor // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +interface SharedOptions { + encoding?: string; + algorithm?: string; +} + interface Key { ascii: string; base32: string; @@ -14,11 +19,9 @@ interface Key { otpauth_url?: string; } -interface DigestOptions { +interface DigestOptions extends SharedOptions { secret: string; counter: string; - encoding?: string; - algorithm?: string; key?: string; } @@ -39,56 +42,78 @@ interface GenerateSecretOptions { symbols?: boolean; } -interface TotpOptions { +interface TotpOptions extends SharedOptions { key?: string; step?: number; time?: number; initial_time?: number; length?: number; - encoding?: string; counter?: number; epoch?: number; secret?: string; digits?: number; digest?: () => string; - algorithm?: string; } -interface HotpOptions { +interface TotpVerifyOptions extends SharedOptions { + secret: string; + token: string; + time?: number; + step?: number; + epoch?: number; + counter?: number; + digits?: number; + window?: number; +} + +interface HotpOptions extends SharedOptions { key: string; counter: number; length?: number; - encoding?: string; digits?: number; digest?: () => string; } -interface OtpauthURLOptions { +interface HotpVerifyOptions extends SharedOptions { + secret: string; + token: string; + counter: number; + digits?: number; + window?: number; +} + +interface OtpauthURLOptions extends SharedOptions { secret: string; label: string; issuer?: any; type?: string; counter?: number; - algorithm?: string; digits?: number; period?: number; - encoding?: string; } -export declare function digest(options: DigestOptions): string; +interface Hotp { + (options: HotpOptions): string; + verifyDelta: (options: HotpVerifyOptions) => boolean; + verify: (options: HotpVerifyOptions) => boolean; +} -export declare function generate_key(options: GenerateOptions): Key; +interface Totp { + (options: TotpOptions): string; + verifyDelta: (options: TotpVerifyOptions) => boolean; + verify: (options: TotpVerifyOptions) => boolean; +} -export declare function generateSecret(options: GenerateSecretOptions): Key; - -export declare function generateSecretASCII(length?: number, symbols?: boolean): string; - -export declare function otpauthURL(options: OtpauthURLOptions): string; - -export declare function hotp(options: HotpOptions): string; - -export declare function counter(options: HotpOptions): string; - -export declare function totp(options: TotpOptions): string; +export declare const hotp: Hotp; +export declare const totp: Totp; export declare function time(options: TotpOptions): string; +export declare function counter(options: HotpOptions): string; +export declare function digest(options: DigestOptions): string; +export declare function generate_key(options: GenerateOptions): Key; +export declare function generateSecret(options?: GenerateSecretOptions): Key; +export declare function generateSecretASCII( + length?: number, + symbols?: boolean +): string; +export declare function otpauthURL(options: OtpauthURLOptions): string; diff --git a/types/speakeasy/speakeasy-tests.ts b/types/speakeasy/speakeasy-tests.ts index ae1ed061da..c807e568a3 100644 --- a/types/speakeasy/speakeasy-tests.ts +++ b/types/speakeasy/speakeasy-tests.ts @@ -37,4 +37,12 @@ speakeasy.generateSecretASCII(5, true); speakeasy.otpauthURL({ secret: 'otpauthURLSecret', label: 'otpauthURLLength' -}); \ No newline at end of file +}); + +speakeasy.totp.verify({secret: "secret", token: "123456"}) + +speakeasy.totp.verifyDelta({secret: "secret", token: "123456"}) + +speakeasy.hotp.verify({secret: "secret", token: "123456", counter: 123}) + +speakeasy.hotp.verifyDelta({secret: "secret", token: "123456", counter: 123})