Coder Social home page Coder Social logo

QR support about bankid HOT 5 CLOSED

swimand avatar swimand commented on August 25, 2024
QR support

from bankid.

Comments (5)

a7ul avatar a7ul commented on August 25, 2024 2

Hi @swimand
You could use the following code snippet at your end to generate qr code

import { createHmac } from "node:crypto";

type QrCache = {
  startTime: number;
  qrStartToken: string;
  qrStartSecret: string;
};
const cache = new Map<string, QrCache>();
/**
 * get the first animated qr and store important values in cache
 **/
async function startQr(
  qrStartSecret: string,
  qrStartToken: string,
  orderRef: string
) {
  const now = Date.now();
  const qrStore = { startTime: now, qrStartSecret, qrStartToken };
  cache.set(orderRef, qrStore);
  return this.generateQr({ ...qrStore, time: 0 });
}

/**
 * generate next animated qr based on time and values in cache
 **/
async function nextQr(orderRef: string) {
  const qr =  cache.get(orderRef);
  if (!qr) {
    return;
  }
  const qrTime = parseInt(`${(Date.now() - qr.startTime) / 1000}`, 10);
  return generateQr(qr.qrStartSecret, qr.qrStartToken, qrTime);
}

function generateQr(qrStartSecret: string, qrStartToken: string, time: number) {
  const qrAuthCode = createHmac("sha256", qrStartSecret)
    .update(`${time}`)
    .digest("hex");
  return `bankid.${qrStartToken}.${time}.${qrAuthCode}`;
}

Here
first you would call startQr and subsequently call nextQr

The support for this doesnt exist today in the library but if you have time feel free to raise a PR

from bankid.

swimand avatar swimand commented on August 25, 2024

Brilliant, thank you for the code snippet! Will definitely help en QR code generation 👍

from bankid.

trycoon avatar trycoon commented on August 25, 2024

The deadline for mandatory QR-code is drawing near, is there a complete example showing show to implement a full BankdID integration using QR-code? Or is the above code the most complete we have?
Thanks for all your work!

from bankid.

swimand avatar swimand commented on August 25, 2024

I generated a QR code on the FE instead, so i simply send the data and the other necessary items there.
I am using this library to generate the image:

https://www.npmjs.com/package/qrcode

from bankid.

fredrik avatar fredrik commented on August 25, 2024

The work on the v6 client (#57) includes a QrGenerator class (see src/qrgenerator.ts). I believe that qualifies as "QR support" and is enough to close this issue.

from bankid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.