Skip to content

Commit

Permalink
Added getDeviceID
Browse files Browse the repository at this point in the history
  • Loading branch information
DoctorMcKay committed Jan 18, 2016
1 parent b0f8502 commit 2bc5ce5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,21 @@ Queries the Steam servers for their time, then subtracts our local time from it
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)
- `steamID` - Your SteamID as a string or an object (such as a `SteamID` object) which has a `toString()` method that returns the SteamID as a 64-bit integer string.

**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. SHA-1 hash it and encode the resulting hash as a lowercase hex value
3. Truncate the hash to 32 characters
4. Insert dashes such that the resulting value has 5 groups of hexadecimal values containing 8, 4, 4, 4, and 12 characters, respectively
5. Prepend "android:" to the resulting value
10 changes: 10 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,16 @@ exports.getTimeOffset = function(callback) {
req.end();
};

/**
* Get a standardized device ID based on your SteamID.
* @param {string|object} steamID - Your SteamID, either as a string or as an object which has a toString() method that returns the SteamID
* @returns {string}
*/
exports.getDeviceID = function(steamID) {
return "android:" + Crypto.createHash('sha1').update(steamID.toString()).digest('hex')
.replace(/^([a-z0-9]{8})([a-z0-9]{4})([a-z0-9]{4})([a-z0-9]{4})([a-z0-9]{12}).*$/, '$1-$2-$3-$4-$5');
};

function bufferizeSecret(secret) {
if(typeof secret === 'string') {
// Check if it's hex
Expand Down

0 comments on commit 2bc5ce5

Please sign in to comment.