v0.1.0
This commit is contained in:
parent
5cc9b740bc
commit
a3cb913c51
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
node_modules/
|
||||
dist/
|
||||
dist/
|
||||
/yarn-error.log
|
||||
|
||||
53
index.ts
Normal file
53
index.ts
Normal file
@ -0,0 +1,53 @@
|
||||
import { randomBytes, createHash } from 'crypto'
|
||||
import bigInt from 'big-integer'
|
||||
|
||||
export const hex2bin = (s: String) => {
|
||||
const ret = []
|
||||
for (let i = 0, l = s.length; i < l; i += 2) {
|
||||
const c = parseInt(s.substr(i, 1), 16)
|
||||
const k = parseInt(s.substr(i + 1, 1), 16)
|
||||
if (isNaN(c) || isNaN(k)) return false
|
||||
ret.push((c << 4) | k)
|
||||
}
|
||||
return String.fromCharCode.apply(String, ret)
|
||||
}
|
||||
|
||||
export const bin2hex = (s: String) => {
|
||||
let result = ''
|
||||
for (let i = 0, l = s.length; i < l; i++) {
|
||||
const n = s.charCodeAt(i).toString(16)
|
||||
result += n.length < 2 ? '0' + n : n
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
export const reverseHex = (string: String) => {
|
||||
const bytes = []
|
||||
for (let i = 0, length = string.length; i < length; i += 2) {
|
||||
bytes.push(string.substr(i, 2))
|
||||
}
|
||||
return bytes.reverse().join('')
|
||||
}
|
||||
|
||||
export const register = (
|
||||
username: String,
|
||||
password: String,
|
||||
gHex = '07',
|
||||
NHex = '894B645E89E1535BBDAD5B8B290650530801B18EBFBF5E8FAB3C82872A3E9BB7'
|
||||
) => {
|
||||
const g = bigInt(gHex, 16)
|
||||
const N = bigInt(NHex, 16)
|
||||
const saltDB = bin2hex(randomBytes(32).toString('binary'))
|
||||
const salt = hex2bin(reverseHex(saltDB))
|
||||
const identity = createHash('sha1')
|
||||
.update((username + ':' + password).toUpperCase())
|
||||
.digest('latin1')
|
||||
const sha = reverseHex(
|
||||
createHash('sha1')
|
||||
.update(salt + identity, 'latin1')
|
||||
.digest('hex')
|
||||
)
|
||||
const privateKey = bigInt(sha, 16)
|
||||
const verifier = g.modPow(privateKey, N).toString(16)
|
||||
return { salt: saltDB, verifier }
|
||||
}
|
||||
@ -4,10 +4,15 @@
|
||||
"description": "SRP implementation for WoW Server authentication in Typescript",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"prepublish": "tsc",
|
||||
"repository": "git@github.com:Mojotrollz/js-wowemu-auth.git",
|
||||
"author": "Ulf Gebhardt <ulf.gebhardt@webcraft-media.de>",
|
||||
"license": "GPL-2.0-only",
|
||||
"dependencies": {
|
||||
"big-integer": "^1.6.48"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "14.14.11",
|
||||
"typescript": "^4.1.3"
|
||||
}
|
||||
}
|
||||
|
||||
10
yarn.lock
10
yarn.lock
@ -2,6 +2,16 @@
|
||||
# yarn lockfile v1
|
||||
|
||||
|
||||
"@types/node@14.14.11":
|
||||
version "14.14.11"
|
||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.11.tgz#fc25a4248a5e8d0837019b1d170146d07334abe0"
|
||||
integrity sha512-BJ97wAUuU3NUiUCp44xzUFquQEvnk1wu7q4CMEUYKJWjdkr0YWYDsm4RFtAvxYsNjLsKcrFt6RvK8r+mnzMbEQ==
|
||||
|
||||
big-integer@^1.6.48:
|
||||
version "1.6.48"
|
||||
resolved "https://registry.yarnpkg.com/big-integer/-/big-integer-1.6.48.tgz#8fd88bd1632cba4a1c8c3e3d7159f08bb95b4b9e"
|
||||
integrity sha512-j51egjPa7/i+RdiRuJbPdJ2FIUYYPhvYLjzoYbcMMm62ooO6F94fETG4MTs46zPAF9Brs04OajboA/qTGuz78w==
|
||||
|
||||
typescript@^4.1.3:
|
||||
version "4.1.3"
|
||||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.1.3.tgz#519d582bd94cba0cf8934c7d8e8467e473f53bb7"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user