mirror of
https://github.com/selfxyz/self.git
synced 2026-04-05 03:00:53 -04:00
add qrcode generation to sdk, refactor apptypes import
This commit is contained in:
28
sdk/QRCodeGenerator.ts
Normal file
28
sdk/QRCodeGenerator.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import QRCode from 'easyqrcodejs';
|
||||
import { AppType } from "../common/src/utils/appType";
|
||||
|
||||
export class QRCodeGenerator {
|
||||
static async generateQRCode(appType: AppType, size: number = 256): Promise<QRCode> {
|
||||
const qrData = this.serializeAppType(appType);
|
||||
const options = {
|
||||
text: qrData,
|
||||
width: size,
|
||||
height: size,
|
||||
};
|
||||
const element = document.createElement('div'); // Create a div element to hold the QR code
|
||||
const qrcode = new QRCode(element, options);
|
||||
return qrcode; // Return the QRCode instance
|
||||
}
|
||||
|
||||
private static serializeAppType(appType: AppType): string {
|
||||
const serializableData = {
|
||||
id: appType.id,
|
||||
name: appType.name,
|
||||
disclosureOptions: appType.disclosureOptions,
|
||||
scope: appType.scope,
|
||||
circuit: appType.circuit,
|
||||
};
|
||||
|
||||
return JSON.stringify(serializableData);
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@
|
||||
"@zk-kit/lean-imt": "^2.0.1",
|
||||
"chai-as-promised": "^7.1.1",
|
||||
"dotenv": "^16.4.5",
|
||||
"easyqrcodejs": "^4.6.1",
|
||||
"ethers": "^6.13.0",
|
||||
"fs": "^0.0.1-security",
|
||||
"js-sha1": "^0.7.0",
|
||||
@@ -51,4 +52,4 @@
|
||||
"common",
|
||||
"circuits/**/*.json"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user