add amusement ic access code encode/decode

This commit is contained in:
ppc
2025-01-14 23:29:52 +00:00
parent 9324b30e7b
commit e83287c7b7
12 changed files with 387 additions and 158 deletions
File diff suppressed because one or more lines are too long
+6 -17
View File
@@ -1,23 +1,12 @@
import {encodeAccessCode} from "./card-encoding";
export const CARD_ID_REGEX = /^(?:[0-9]{4} ?){5}$/i;
export const AMNET_COMPANY_ID = 597;
export function generateCardNumber(): string {
let cardId = '';
while (true) {
// don't start with a 3
const firstDigit = Math.floor(Math.random() * 10);
if (firstDigit !== 3) {
cardId = firstDigit.toString();
break;
}
}
for (let i = 0; i < 19; i++) {
cardId += Math.floor(Math.random() * 10).toString();
}
return cardId;
// serial between 5000 and 99999999999
const serial = Math.floor(Math.random() * 99999994999) + 5000;
return encodeAccessCode(AMNET_COMPANY_ID, serial, 0);
}
/**
+3 -1
View File
@@ -1,3 +1,5 @@
export * from './api';
export * from './card';
export * from './gameIds';
export * from './gameIds';
export {decodeAccessCode as DecodeAMAccessCode, encodeAccessCode as EncodeAMAccessCode} from './card-encoding';