Skip to content

Commit

Permalink
minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
beesaferoot committed Nov 5, 2024
1 parent 9be8346 commit 9a5a515
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
3 changes: 1 addition & 2 deletions src/encoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class OpenPAYGOTokenEncoder {
let currentToken = sharedExtended.putBaseInToken(startingCode, tokenBase)
const newCount = this.#getNewCount(count, mode)

for (let i = 0; i < newCount; i++) {
for (let i = 0; i < newCount - 2; i++) {
currentToken = sharedExtended.genNextToken(currentToken, key)
}
let finalToken = sharedExtended.putBaseInToken(currentToken, tokenBase)
Expand All @@ -138,7 +138,6 @@ class OpenPAYGOTokenEncoder {
}

#encodeBaseExtended(baseCode, value) {
BigInt(value) + BigInt(baseCode)
baseCode = BigInt(baseCode)
value = BigInt(value)
if (value + baseCode > 999999n) {
Expand Down
1 change: 0 additions & 1 deletion src/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class OpenPAYGOTokenShared {
let hash = this.genHash({
key: key,
msg: duplicatedToken,
asByte: true,
})

return this.convertHash2Token(hash)
Expand Down
28 changes: 15 additions & 13 deletions test/encoder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,23 @@ const shared = require("../src/token").OpenPAYGOTokenShared
describe("OpenPAYGOTokenEncoder test", () => {
test("generateToken", () => {
const encoder = new Encoder()

sample.forEach((s) => {
const data = s
const useExtended = data.value_raw > shared.MAX_ACTIVATION_VALUE
const { finalToken } = encoder.generateToken({
tokenType: data.token_type,
secretKeyHex: data.key,
count: data.token_count,
startingCode: data.starting_code,
restrictDigitSet: data.restricted_digit_set,
value: data.value_raw,
extendToken: useExtended,
})

expect(finalToken).toBe(data.token)
try {
const { finalToken } = encoder.generateToken({
tokenType: data.token_type,
secretKeyHex: data.key,
count: data.token_count,
startingCode: data.starting_code,
restrictDigitSet: data.restricted_digit_set,
value: data.value_raw,
extendToken: data.extended_token,
})
expect(finalToken).toBe(data.token)
} catch (err) {
expect(data.extended_token).toBe(false)
expect(data.value_raw > shared.MAX_ACTIVATION_VALUE).toBe(true)
}
})
})
})

0 comments on commit 9a5a515

Please sign in to comment.