From 0f99dbb97dfd8ce606a81e143d6242c7e0f3251a Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 8 Mar 2018 13:25:48 +0100 Subject: [PATCH 1/2] [steam-totp] Add types --- types/steam-totp/index.d.ts | 68 ++++++++++++++++++++++++++++ types/steam-totp/steam-totp-tests.ts | 3 ++ types/steam-totp/tsconfig.json | 23 ++++++++++ types/steam-totp/tslint.json | 1 + 4 files changed, 95 insertions(+) create mode 100644 types/steam-totp/index.d.ts create mode 100644 types/steam-totp/steam-totp-tests.ts create mode 100644 types/steam-totp/tsconfig.json create mode 100644 types/steam-totp/tslint.json diff --git a/types/steam-totp/index.d.ts b/types/steam-totp/index.d.ts new file mode 100644 index 0000000000..e405ef7ea1 --- /dev/null +++ b/types/steam-totp/index.d.ts @@ -0,0 +1,68 @@ +// Type definitions for steam-totp 2.0 +// Project: https://github.com/DoctorMcKay/node-steam-totp +// Definitions by: Max Uetrecht +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +export type TimeOffsetFunction = () => number; + +/** + * Returns the current local Unix time + * @param [timeOffset=0] - This many seconds will be added to the returned time + * @returns the current local Unix time + */ +export function time(timeOffset?: number): number; + +/** + * Generate a Steam-style TOTP authentication code. + * @param secret - Your TOTP shared_secret as a Buffer, hex, or base64 + * @param [timeOffset=0] - If you know how far off your clock is from the Steam servers, put the offset here in seconds + * @returns the generated auth code + */ +export function generateAuthCode(secret: string, timeOffset: number | TimeOffsetFunction): string; + +/** + * Generate a Steam-style TOTP authentication code. + * @param secret - Your TOTP shared_secret as a Buffer, hex, or base64 + * @param [timeOffset=0] - If you know how far off your clock is from the Steam servers, put the offset here in seconds + * @returns the generated auth code + */ +export function getAuthCode(secret: string, timeOffset: number | TimeOffsetFunction): string; + +/** + * Generate a base64 confirmation key for use with mobile trade confirmations. The key can only be used once. + * @param identitySecret - The identity_secret that you received when enabling two-factor authentication + * @param time - The Unix time for which you are generating this secret. Generally should be the current time. + * @param tag - The tag which identifies what this request (and therefore key) will be for. + * "conf" to load the confirmations page, "details" to load details about a trade, "allow" to confirm a trade, "cancel" to cancel it. + * @returns the generated confirmation key + */ +export function generateConfirmationKey(identitySecret: Buffer | string, time: number, tag: string): string; + +/** + * Generate a base64 confirmation key for use with mobile trade confirmations. The key can only be used once. + * @param identitySecret - The identity_secret that you received when enabling two-factor authentication + * @param time - The Unix time for which you are generating this secret. Generally should be the current time. + * @param tag - The tag which identifies what this request (and therefore key) will be for. + * "conf" to load the confirmations page, "details" to load details about a trade, "allow" to confirm a trade, "cancel" to cancel it. + * @returns the generated confirmation key + */ +export function getConfirmationKey(identitySecret: Buffer | string, time: number, tag: string): string; + +export type Callback = (error: Error, offset?: number, elapsedTime?: number) => void; + +/** + * Requests the time offset from the Steam API. + * @param callback - The result of the steam api request + * @param [timeOffset=0] - If you know how far off your clock is from the Steam servers, put the offset here in seconds + * @returns the time offset + */ +export function getTimeOffset(callback: Callback): void; + +/** + * Get a standardized device ID based on your SteamID. + * @param steamID - Your SteamID, either as a string or as an object which has a toString() method that returns the SteamID + * @returns the device ID + */ +export function getDeviceID(steamID: string | object): string; diff --git a/types/steam-totp/steam-totp-tests.ts b/types/steam-totp/steam-totp-tests.ts new file mode 100644 index 0000000000..57702ccaaa --- /dev/null +++ b/types/steam-totp/steam-totp-tests.ts @@ -0,0 +1,3 @@ +import steamTotp = require('steam-totp'); + +const time: number = steamTotp.time(); diff --git a/types/steam-totp/tsconfig.json b/types/steam-totp/tsconfig.json new file mode 100644 index 0000000000..01223cacba --- /dev/null +++ b/types/steam-totp/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "steam-totp-tests.ts" + ] +} diff --git a/types/steam-totp/tslint.json b/types/steam-totp/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/steam-totp/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From b4f8c54fa3f99d8808d60cf24bfa79cb4bf4c940 Mon Sep 17 00:00:00 2001 From: Silas Rech Date: Thu, 8 Mar 2018 16:28:17 +0100 Subject: [PATCH 2/2] Fix CI --- types/steam-totp/index.d.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/types/steam-totp/index.d.ts b/types/steam-totp/index.d.ts index e405ef7ea1..a3ff963428 100644 --- a/types/steam-totp/index.d.ts +++ b/types/steam-totp/index.d.ts @@ -2,6 +2,7 @@ // Project: https://github.com/DoctorMcKay/node-steam-totp // Definitions by: Max Uetrecht // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 /// @@ -50,15 +51,13 @@ export function generateConfirmationKey(identitySecret: Buffer | string, time: n */ export function getConfirmationKey(identitySecret: Buffer | string, time: number, tag: string): string; -export type Callback = (error: Error, offset?: number, elapsedTime?: number) => void; - /** * Requests the time offset from the Steam API. * @param callback - The result of the steam api request * @param [timeOffset=0] - If you know how far off your clock is from the Steam servers, put the offset here in seconds * @returns the time offset */ -export function getTimeOffset(callback: Callback): void; +export function getTimeOffset(callback: (error: Error, offset?: number, elapsedTime?: number) => void): void; /** * Get a standardized device ID based on your SteamID.