Home

Awesome

Steam TOTP

npm version npm downloads license paypal

This lightweight module generates Steam-style 5-digit alphanumeric two-factor authentication codes given a shared secret.

As of v2.0.0, Node.js v6.0.0 or later is REQUIRED. This LTS Node.js release will be supported by this module for the duration of Node's LTS support.

Usage is simple:

var SteamTotp = require('steam-totp');
var code = SteamTotp.generateAuthCode('cnOgv/KdpLoP6Nbh0GMkXkPXALQ=');

Read more about Steam's 2FA and trade confirmations.

time([timeOffset])

v1.2.0 or later is required to use this function

Simply returns the current local time in Unix time. This is just Math.floor(Date.now() / 1000) + timeOffset.

getAuthCode(secret[, timeOffset][, callback])

v1.4.0 or later is required to use callback.

Returns your current 5-character alphanumeric TOTP code as a string (if no callback is provided) or queries the current time from the Steam servers and returns the code in the callback (if the callback was provided).

Note: You should use your shared_secret for this function.

Alias: generateAuthCode(secret[, timeOffset][, callback])

getConfirmationKey(identitySecret, time, tag)

v1.1.0 or later is required to use this function

Returns a string containing your base64 confirmation key for use with the mobile confirmations web page.

Note: You should use your identity_secret for this function.

Alias: generateConfirmationKey(identitySecret, time, tag)

getTimeOffset(callback)

v1.2.0 or later is required to use this function

Queries the Steam servers for their time, then subtracts our local time from it to get our offset.

The offset is how many seconds we are behind Steam. Therefore, add this number to our local time to get Steam time.

You can pass this value to time() or to getAuthCode() as-is with no math involved.

getDeviceID(steamID)

v1.3.0 or later is required to use this function

Returns a standardized device ID in the same format as Android device IDs from Valve's official mobile app. Steam will likely soon stop allowing you to send a different device ID each time you load the page, instead requiring you to consistently use the same device ID. If you use this function's algorithm everywhere you use a confirmation device ID, then your experience should be fine.

The algorithm used is:

  1. Convert the SteamID to a string
  2. Append the value of the STEAM_TOTP_SALT environment variable to the SteamID, if it's set
  3. SHA-1 hash it and encode the resulting hash as a lowercase hex value
  4. Truncate the hash to 32 characters
  5. Insert dashes such that the resulting value has 5 groups of hexadecimal values containing 8, 4, 4, 4, and 12 characters, respectively
  6. Prepend "android:" to the resulting value

Note: STEAM_TOTP_SALT was added to the v1 branch in v1.5.0 and to the v2 branch in v2.1.0.