-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update ekaterinburg-rf backend API (#96)
* Update ekaterinburg-rf backend API * Move getRequestToken to separate token
- Loading branch information
1 parent
a92fab6
commit 40eda84
Showing
4 changed files
with
51 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
let lastTimestamp = 0; | ||
|
||
export function getCurrentTimestamp() { | ||
let timestamp = Math.floor((new Date).getTime() / 1000); | ||
|
||
if (timestamp <= lastTimestamp) { | ||
timestamp++; | ||
} | ||
|
||
lastTimestamp = timestamp; | ||
return timestamp; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import crypto from 'crypto'; | ||
import type { JsonRpcMethods } from "../model/ekaterinburg-rf/ekaterinburg-rf.constants"; | ||
|
||
const EKATERINBURG_TOKEN = 'ekt'; | ||
|
||
export function getRequestToken(method: JsonRpcMethods, id: number, sid: string) { | ||
const token = `${method}~${EKATERINBURG_TOKEN}~${id}~${sid}`; | ||
const tokenEnc = crypto.createHash('sha1').update(token).digest('hex'); | ||
|
||
// transorm first and last 16 symbols into GUID | ||
const guid = | ||
tokenEnc.substr(0, 8) + | ||
'-' + | ||
tokenEnc.substr(8, 4) + | ||
'-' + | ||
tokenEnc.substr(12, 4) + | ||
'-' + | ||
tokenEnc.substr(24, 4) + | ||
'-' + | ||
tokenEnc.substr(28, 12); | ||
|
||
// turn 8 middle symbols into magic string | ||
const magic = tokenEnc.substr(16, 8); | ||
|
||
return { | ||
guid, | ||
magic | ||
}; | ||
} |