Skip to content

Commit

Permalink
Merge pull request #62 from yeojz/fix/typescript
Browse files Browse the repository at this point in the history
fix: typescript install and optional dep
  • Loading branch information
yeojz committed Jun 11, 2018
2 parents badc958 + 8ecf157 commit 14da1bc
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 66 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
[![Coverage Status][coveralls-badge]][coveralls-link]
[![npm downloads][npm-downloads-badge]][npm-link]
[![PRs Welcome][pr-welcome-badge]][pr-welcome-link]
[![Support Project][donate-badge]][donate-link]

<img width="150" src="https://yeojz.github.io/otplib/otplib.png" />

Expand All @@ -25,9 +24,10 @@
- [Core](#core)
- [Other Bundles](#other-bundles)
- [Notes](#notes)
- [TypeScript Support](#typescript-support)
- [Setting Custom Options](#setting-custom-options)
- [Available Options](#available-options)
- [Seed / secret length](#seed-secret-length)
- [Seed / secret length](#seed---secret-length)
- [Google Authenticator](#google-authenticator)
- [Difference between Authenticator and TOTP](#difference-between-authenticator-and-totp)
- [Base32 Keys and RFC3548](#base32-keys-and-rfc3548)
Expand Down Expand Up @@ -227,6 +227,10 @@ For more information about the functions, check out the [documentation][project-

## Notes

### TypeScript Support

As of `v10.0.0`, TypeScript definition files are included within the package.

### Setting Custom Options

All instantiated classes will have their options inherited from their respective options
Expand Down Expand Up @@ -330,10 +334,13 @@ qrcode.toDataURL(otpauth, (err, imageUrl) => {

Check out: [CONTRIBUTING.md][pr-welcome-link]

[![Support Project][coffee-badge]][coffee-link]

## License

`otplib` is [MIT licensed](./LICENSE)


[npm-badge]: https://img.shields.io/npm/v/otplib.svg?style=flat-square
[npm-link]: https://www.npmjs.com/package/otplib
[npm-next-badge]: https://img.shields.io/npm/v/otplib/next.svg?style=flat-square
Expand All @@ -356,3 +363,5 @@ Check out: [CONTRIBUTING.md][pr-welcome-link]
[rfc-6238-wiki]: http://en.wikipedia.org/wiki/Time-based_One-time_Password_Algorithm
[donate-badge]: https://img.shields.io/badge/donate-%3C3-red.svg?longCache=true&style=flat-square
[donate-link]: https://www.paypal.me/yeojz
[coffee-badge]: https://img.shields.io/badge/%E2%98%95%EF%B8%8F%20%20-buy%20me%20a%20coffee-orange.svg?longCache=true&style=flat-square
[coffee-link]: https://ko-fi.com/geraldyeo
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@
"dependencies": {
"thirty-two": "1.0.2"
},
"optionalDependencies": {
"@types/node": "latest",
"typescript": "next"
},
"jest": {
"coverageDirectory": "./coverage/",
"coveragePathIgnorePatterns": [
Expand Down
64 changes: 64 additions & 0 deletions packages/types-ts/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,67 @@
type CreateHmacSecretFunction = (secret: string, options: any) => Buffer;

interface HOTPOptions {
algorithm?: string;
createHmacSecret?: CreateHmacSecretFunction;
crypto?: any;
digits?: number;
encoding?: string;
}

interface HOTPVerifyOptions {
token?: string;
secret?: string;
counter?: number;
}

interface TOTPOptions extends HOTPOptions {
epoch?: any;
step?: number;
window?: number | number[];
}

interface TOTPVerifyOptions {
token?: string;
secret?: string;
}

declare class HOTP {
HOTP: typeof HOTP;
getClass(): typeof HOTP;

options: HOTPOptions;
optionsAll: HOTPOptions;
resetOptions(): this;
generate(secret: string, counter: number): string;
check(token: string, secret: string, counter: number): boolean;
verify(opts: HOTPVerifyOptions): boolean;
}

declare class TOTP extends HOTP {
TOTP: typeof TOTP;
getClass(): typeof TOTP;

options: TOTPOptions;
optionsAll: TOTPOptions;
generate(secret: string): string;
check(token: string, secret: string): boolean;
checkDelta(token: string, secret: string): number | null;
verify(opts: TOTPVerifyOptions): boolean;
}

declare class Authenticator extends TOTP {
Authenticator: typeof Authenticator;
getClass(): typeof Authenticator;

check(token: string, secret: string): boolean;
checkDelta(token: string, secret: string): number | null;
decode(encodedKey: string): string;
encode(secret: string): string;
generate(secret: string): string;
generateSecret(len?: number): string;
keyuri(user: string, service: string, secret: string): string;
}

declare module 'otplib' {
const authenticator: Authenticator;
const hotp: HOTP;
Expand Down
63 changes: 0 additions & 63 deletions packages/types-ts/types.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion scripts/build-types.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
cp packages/types-ts/index.d.ts dist/index.d.ts
cp packages/types-ts/types.d.ts dist/types.d.ts

0 comments on commit 14da1bc

Please sign in to comment.