diff --git a/CHANGELOG.md b/CHANGELOG.md index 2505abe..349dccd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # @digitalbazaar/vpqr Changelog +## 5.1.0 - 2024-xx-xx + +### Changed +- Add support for `@digitalbazaar/cborld` `typeTable` and `registryEntryId` + options. + ## 5.0.0 - 2024-08-29 ### Added diff --git a/lib/util.js b/lib/util.js index 26c7c94..56a83a3 100644 --- a/lib/util.js +++ b/lib/util.js @@ -26,6 +26,10 @@ const BASE_45_MULTIBASE_PREFIX = 'R'; * @param {object} [options.jsonldDocument] - Document to encode. * @param {object} [options.cborldBytes] - CBOR-LD bytes to encode. * @param {object} [options.documentLoader] - Loader for jsonldDocument. + * @param {Number} [options.registryEntryId] - CBOR-LD type table registry + * entry id. + * @param {Map} [options.typeTable] - CBOR-LD type table for associated + * registryEntryId. * @param {object} [options.appContextMap] - CBOR-LD app context map. * @param {object} [options.moduleSize] - Output image QR Code module size. * @param {object} [options.margin] - Output image margin size. @@ -39,9 +43,10 @@ const BASE_45_MULTIBASE_PREFIX = 'R'; * @returns {object} The QR code properties. */ export async function toQrCode({ - header, jsonldDocument, cborldBytes, documentLoader, appContextMap, - moduleSize, margin, qrMultibaseEncoding = BASE_45_MULTIBASE_PREFIX, - qrErrorCorrectionLevel = 'L', qrVersion = 0, diagnose + header, jsonldDocument, cborldBytes, documentLoader, registryEntryId, + typeTable, appContextMap, moduleSize, margin, + qrMultibaseEncoding = BASE_45_MULTIBASE_PREFIX, qrErrorCorrectionLevel = 'L', + qrVersion = 0, diagnose } = {}) { if(jsonldDocument && cborldBytes) { throw new Error( @@ -52,6 +57,8 @@ export async function toQrCode({ cborldBytes = await cborld.encode({ jsonldDocument, documentLoader, + registryEntryId, + typeTable, appContextMap, // to debug, set diagnose: console.log diagnose @@ -79,7 +86,7 @@ export async function toQrCode({ export async function fromQrCode({ expectedHeader = '', text, decodeCborld = true, documentLoader, - appContextMap, diagnose + typeTable, appContextMap, diagnose } = {}) { if(!(text && text.startsWith(expectedHeader))) { throw TypeError('Unsupported QR format.'); @@ -107,6 +114,7 @@ export async function fromQrCode({ const jsonldDocument = await cborld.decode({ cborldBytes, documentLoader, + typeTable, appContextMap, // to debug, set diagnose: console.log diagnose diff --git a/lib/vpqr.js b/lib/vpqr.js index 8f015bb..34a7392 100644 --- a/lib/vpqr.js +++ b/lib/vpqr.js @@ -7,24 +7,25 @@ const VP_QR_VERSION = 'VP1'; const HEADER = VP_QR_VERSION + '-'; export async function toQrCode({ - vp, documentLoader, appContextMap, moduleSize, margin, qrMultibaseEncoding, - qrErrorCorrectionLevel, qrVersion, diagnose + vp, documentLoader, registryEntryId, typeTable, appContextMap, moduleSize, + margin, qrMultibaseEncoding, qrErrorCorrectionLevel, qrVersion, diagnose } = {}) { return util.toQrCode({ - header: HEADER, jsonldDocument: vp, documentLoader, appContextMap, - qrMultibaseEncoding, qrErrorCorrectionLevel, qrVersion, moduleSize, margin, - diagnose + header: HEADER, jsonldDocument: vp, documentLoader, registryEntryId, + typeTable, appContextMap, qrMultibaseEncoding, qrErrorCorrectionLevel, + qrVersion, moduleSize, margin, diagnose }); } export async function fromQrCode({ - text, documentLoader, appContextMap, diagnose + text, documentLoader, typeTable, appContextMap, diagnose } = {}) { const expectedHeader = HEADER; if(!(text && text.startsWith(expectedHeader))) { throw TypeError('Unsupported VP QR format.'); } - const {jsonldDocument} = await util.fromQrCode( - {expectedHeader, text, documentLoader, appContextMap, diagnose}); + const {jsonldDocument} = await util.fromQrCode({ + expectedHeader, text, documentLoader, typeTable, appContextMap, diagnose + }); return {vp: jsonldDocument}; }