Skip to content

Commit

Permalink
fix: incorrect decoding for share codes ending with "AA"
Browse files Browse the repository at this point in the history
  • Loading branch information
akiver committed Mar 15, 2020
1 parent ba8fad3 commit d06a17c
Show file tree
Hide file tree
Showing 9 changed files with 3,561 additions and 36 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/compile-and-tests-on-push.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: CI

on: [push, pull_request]

jobs:
compile_and_test:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [12.x]

steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: yarn install
run: yarn
- name: TSC compile
run: yarn tsc
- name: Tests
run: yarn test
10 changes: 7 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
# Changelog

##### 1.3.0

- Fix incorrect decoding for share codes ending with "AA"

##### 1.2.0

* Fix possible incorrect decoding [#12](https://github.com/akiver/csgo-sharecode/issues/12)
- Fix possible incorrect decoding [#12](https://github.com/akiver/csgo-sharecode/issues/12)

##### 1.1.0

* Fix possible incorrect share code string detection
* TypeScript support
- Fix possible incorrect share code string detection
- TypeScript support

##### 1.0.0

Expand Down
66 changes: 66 additions & 0 deletions index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { decode, encode } from '.'

const samples = [
{
string: 'CSGO-L9spZ-ihuov-cyhtE-kxbqa-FkBAA',
value: {
matchId: { low: 512, high: 791708164 },
reservationId: { low: 387, high: 791709731 },
tvPort: 9725,
},
},
{
string: 'CSGO-GADqf-jjyJ8-cSP2r-smZRo-TO2xK',
value: {
matchId: { low: -2147483492, high: 752192506 },
reservationId: { low: 143, high: 752193760 },
tvPort: 55788,
},
},
{
string: 'CSGO-bPQEz-PrYTq-u5w8E-ZbUy7-ZeQ3A',
value: {
matchId: { low: 526, high: 774257071 },
reservationId: { low: -2147483132, high: 774257428 },
tvPort: 240,
},
},
{
string: 'CSGO-wBrm6-7fkM6-AzBC5-u6GmR-iHLHA',
value: {
matchId: { low: -2147483646, high: 768860983 },
reservationId: { low: 370, high: 768863030 },
tvPort: 3085,
},
},
{
string: 'CSGO-TKDTJ-YrAXs-sDNfL-HOuKO-i84VH',
value: {
matchId: { low: -2147483275, high: 792148141 },
reservationId: { low: 557, high: 792148244 },
tvPort: 61630,
},
},
{
string: 'CSGO-p4X9o-3Mfut-tpe5y-J8K6f-mj5ZJ',
value: {
matchId: { low: -2147483258, high: 792147941 },
reservationId: { low: -2147483028, high: 792148544 },
tvPort: 14119,
},
},
]

it('should decode', () => {
samples.forEach(({ string, value }) => {
expect(decode(string)).toEqual(value)
})
})

it('should encode', () => {
samples.forEach(({ string, value }) => {
expect(encode(value.matchId, value.reservationId, value.tvPort)).toEqual(
string
)
})
})
5 changes: 1 addition & 4 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ function bytesToHex(bytes: number[]) {
* Convert a BigNumber into a byte array.
*/
function bigNumberToByteArray(big: BigNumber) {
let str = big.toString(16)
if (str.length % 2 > 0) {
str = '0' + str
}
const str = big.toString(16).padStart(36, '0')
const bytes = []
for (let i = 0; i < str.length; i += 2) {
bytes.push(parseInt(str.slice(i, i + 2), 16))
Expand Down
4 changes: 4 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
}
14 changes: 10 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,23 @@
"scripts": {
"build": "tsc",
"dev": "tsc --watch",
"prettier": "prettier --write \"{index,example}.{ts,js}\"",
"format": "prettier --write *.{ts,js,json}",
"test": "jest",
"tw": "yarn test --watch",
"tsc": "tsc --noEmit"
},
"dependencies": {
"bignumber.js": "^9.0.0"
},
"engines": {
"node": ">=4.0.0"
"node": ">=8.0.0"
},
"devDependencies": {
"prettier": "1.18.2",
"typescript": "3.6.2"
"@types/jest": "^25.1.4",
"@types/node": "^13.9.1",
"jest": "^25.1.0",
"prettier": "1.19.1",
"ts-jest": "^25.2.1",
"typescript": "3.8.3"
}
}
4 changes: 1 addition & 3 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{
"extends": [
"config:base"
]
"extends": ["config:base"]
}
26 changes: 12 additions & 14 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
{
"compilerOptions": {
"declaration": true,
"lib": ["es5", "es6"],
"noImplicitAny": true,
"noUnusedLocals": true,
"outDir": "./dist",
"sourceMap": true,
"strictNullChecks": true,
"target": "es5",
},
"files": [
"index.ts",
]
}
"compilerOptions": {
"declaration": true,
"lib": ["es5", "es6"],
"noImplicitAny": true,
"noUnusedLocals": true,
"outDir": "./dist",
"sourceMap": true,
"strict": true,
"target": "es5"
},
"files": ["index.ts"]
}
Loading

0 comments on commit d06a17c

Please sign in to comment.