Skip to content

Commit

Permalink
Add support for typeTable and registryEntryId.
Browse files Browse the repository at this point in the history
Adds support for newer `@digitalbazaar/cbrold` `encode()` and `decode()`
API options.
  • Loading branch information
davidlehn committed Oct 16, 2024
1 parent 44f1c40 commit 2e93c4b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
16 changes: 12 additions & 4 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check warning on line 29 in lib/util.js

View workflow job for this annotation

GitHub Actions / lint (20.x)

Invalid JSDoc @param "options.registryEntryId" type "Number"; prefer: "number"
* 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.
Expand All @@ -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(
Expand All @@ -52,6 +57,8 @@ export async function toQrCode({
cborldBytes = await cborld.encode({
jsonldDocument,
documentLoader,
registryEntryId,
typeTable,
appContextMap,
// to debug, set diagnose: console.log
diagnose
Expand Down Expand Up @@ -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.');
Expand Down Expand Up @@ -107,6 +114,7 @@ export async function fromQrCode({
const jsonldDocument = await cborld.decode({
cborldBytes,
documentLoader,
typeTable,
appContextMap,
// to debug, set diagnose: console.log
diagnose
Expand Down
17 changes: 9 additions & 8 deletions lib/vpqr.js
Original file line number Diff line number Diff line change
Expand Up @@ -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};
}

0 comments on commit 2e93c4b

Please sign in to comment.