diff --git a/examples/generate-pay-qr-code.ts b/examples/generate-pay-qr-code.ts index d66f193..a1d04b0 100644 --- a/examples/generate-pay-qr-code.ts +++ b/examples/generate-pay-qr-code.ts @@ -1,5 +1,5 @@ import * as izly from "../src"; -import { read } from "./_persisted-session"; +import { persist, read } from "./_persisted-session"; import { toString as qrcode } from "qrcode"; void async function main () { @@ -10,4 +10,6 @@ void async function main () { qrcode(data, { type: "utf8" }, (_, qr) => { console.log(qr); }); + + await persist(identification); }(); diff --git a/src/api/private/otp.ts b/src/api/private/otp.ts index d429a17..c01f671 100644 --- a/src/api/private/otp.ts +++ b/src/api/private/otp.ts @@ -1,8 +1,8 @@ -import { base64, base64url } from "@scure/base"; +import { base64urlnopad } from "@scure/base"; import { packBigEndian } from "~/core/pack"; import { hashWithHMAC } from "~/core/hmac"; export const otp = (seed: string, counter: number): string => { const packedCounter = packBigEndian(counter); - return base64url.encode(hashWithHMAC(packedCounter, base64.decode(seed))); + return base64urlnopad.encode(hashWithHMAC(packedCounter, base64urlnopad.decode(seed))); }; diff --git a/src/api/qr-pay.ts b/src/api/qr-pay.ts index b140446..07ab62b 100644 --- a/src/api/qr-pay.ts +++ b/src/api/qr-pay.ts @@ -31,7 +31,7 @@ const signWithPrivateKey = (textToSign: string, pem: string): Uint8Array => { */ export const qrPay = (identification: Identification): string => { // Replicate `SimpleDateFormat("yyyy-MM-dd HH:mm:ss")` - const dateFormatter = new Intl.DateTimeFormat("en-CA", { timeZone: "UTC", year: "numeric", month: "2-digit", day: "2-digit", hour12: false, second: "2-digit", minute: "2-digit", hour: "2-digit" }); + const dateFormatter = new Intl.DateTimeFormat("fr-CA", { timeZone: "UTC", year: "numeric", month: "2-digit", day: "2-digit", hour12: false, second: "2-digit", minute: "2-digit", hour: "2-digit" }); const dateNowFormatted = dateFormatter.format(new Date()).replace(",", ""); let hotpCode = otp(identification.seed, identification.refreshCount); @@ -45,5 +45,7 @@ export const qrPay = (identification: Identification): string => { content = content + ";" + bytesToHex(hashWithHMAC(`${content}+${identification.nsse}`, hmacKey)) + ";"; const signed = signWithPrivateKey(content, privateKey); - return base64.encode(signed); + content += base64.encode(signed); + + return content; };