add qrcode generation to sdk, refactor apptypes import

This commit is contained in:
turnoffthiscomputer
2024-07-26 08:59:09 +02:00
parent 7a45263b04
commit 03cbec29ba
11 changed files with 39 additions and 10 deletions

28
sdk/QRCodeGenerator.ts Normal file
View 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);
}
}

View File

@@ -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"
]
}
}