Skip to content

Commit

Permalink
Start adding BitstringStatusList support.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlongley committed Feb 24, 2024
1 parent ad13455 commit 18c5112
Show file tree
Hide file tree
Showing 10 changed files with 177 additions and 48 deletions.
2 changes: 1 addition & 1 deletion lib/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ async function _createOrRefreshStatusList({
}
}

// FIXME: check available storage via meter before allowing operation
// TODO: check available storage via meter before allowing operation
try {
const {config} = req.serviceObject;
const statusListId = _getStatusListId({req});
Expand Down
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ bedrock.events.on('bedrock.init', async () => {

async function usageAggregator({meter, signal, service} = {}) {
const {id: meterId} = meter;
// FIXME: add SLCs storage
// TODO: add SLCs storage
return service.configStorage.getUsage({meterId, signal});
}
17 changes: 13 additions & 4 deletions lib/issue.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,24 @@
*/
import {getZcapClient} from './helpers.js';

const CREDENTIALS_CONTEXT_V1_URL = 'https://www.w3.org/2018/credentials/v1';

export async function issue({config, credential, updateValidity = true} = {}) {
if(updateValidity) {
// express date without milliseconds
const date = new Date();
// TODO: use `validFrom` and `validUntil` for v2 VCs
credential.issuanceDate = `${date.toISOString().slice(0, -5)}Z`;
// FIXME: get validity period via status instance config
const validFrom = `${date.toISOString().slice(0, -5)}Z`;
date.setDate(date.getDate() + 1);
credential.expirationDate = `${date.toISOString().slice(0, -5)}Z`;
const validUntil = `${date.toISOString().slice(0, -5)}Z`;

if(credential['@context'].includes(CREDENTIALS_CONTEXT_V1_URL)) {
credential.issuanceDate = validFrom;
credential.expirationDate = validUntil;
} else {
credential.validFrom = validFrom;
credential.validFrom = validFrom;
}

// delete existing proof
delete credential.proof;
}
Expand Down
34 changes: 21 additions & 13 deletions lib/slcs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
*/
import * as bedrock from '@bedrock/core';
import * as database from '@bedrock/mongodb';
// FIXME: add bitstring status list support
// import {
// createBitstringStatusList,
// createBitstringStatusListCredential
// } from '@digitalbazaar/vc-bitstring-status-list';
import {
createList,
createCredential as createListCredential
} from '@digitalbazaar/vc-bitstring-status-list';
import {
createList as createList2021,
createCredential as createSlc
createCredential as createList2021Credential
} from '@digitalbazaar/vc-status-list';
import assert from 'assert-plus';
import {issue} from './issue.js';
Expand Down Expand Up @@ -84,11 +83,19 @@ export async function create({
}
});
}
// FIXME: implement `BitstringStatusList`
// assume `StatusList2021`
const list = await createList2021({length});
// FIXME: handle `statusPurpose` as an array (not just a single value)
let credential = await createSlc({id: credentialId, list, statusPurpose});
let credential;
if(type === 'BitstringStatusList') {
const list = await createList({length});
credential = await createListCredential({
id: credentialId, list, statusPurpose
});
} else {
// `type` must be `StatusList2021`
const list = await createList2021({length});
credential = await createList2021Credential({
id: credentialId, list, statusPurpose
});
}
credential.name = 'Status List Credential';
credential.description =
`This credential expresses status information for some ` +
Expand Down Expand Up @@ -196,8 +203,9 @@ export async function getFresh({config, statusListId} = {}) {
// any refreshed VC is still valid once returned to the client
const now = new Date();
now.setTime(now.getTime() + 1000 * 60);
// FIXME: support v2 VCs w/`validUntil`
const validUntil = new Date(record.credential.expirationDate);
const validUntil = new Date(
record.credential.validUntil ||
record.credential.expirationDate);
if(now <= validUntil) {
// SLC not expired
return {credential: record.credential};
Expand Down
15 changes: 9 additions & 6 deletions lib/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ import * as bedrock from '@bedrock/core';
import * as mappings from './mappings.js';
import * as slcs from './slcs.js';
import assert from 'assert-plus';
// FIXME: add bitstring status list support
// import {
// decodeBitstringStatusList
// } from '@digitalbazaar/vc-bitstring-status-list';
import {decodeList} from '@digitalbazaar/vc-status-list';
import {decodeList} from '@digitalbazaar/vc-bitstring-status-list';
import {decodeList as decodeList2021} from '@digitalbazaar/vc-status-list';
import {issue} from './issue.js';
import {LIST_TYPE_TO_ENTRY_TYPE} from './constants.js';

Expand Down Expand Up @@ -135,7 +132,13 @@ export async function setStatus({
// check if `credential` status is already set, if so, done
let {credential: slc} = record;
const {credentialSubject: {encodedList}} = slc;
const list = await decodeList({encodedList});
let list;
if(slc.type.includes('BitstringStatusListCredential')) {
list = await decodeList({encodedList});
} else {
// type must be `StatusListCredential`
list = await decodeList2021({encodedList});
}
if(list.getStatus(bitstringIndex) === status) {
return;
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"@digitalbazaar/ed25519-signature-2020": "^5.2.0",
"@digitalbazaar/ezcap": "^4.1.0",
"@digitalbazaar/lru-memoize": "^3.0.0",
"@digitalbazaar/vc-bitstring-status-list": "digitalbazaar/vc-bitstring-status-list#main",
"@digitalbazaar/vc-status-list": "^7.0.0",
"assert-plus": "^1.0.0",
"bnid": "^3.0.0",
Expand Down
2 changes: 0 additions & 2 deletions schemas/bedrock-vc-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import {MAX_LIST_SIZE} from '../lib/constants.js';
const indexAllocator = {
// an ID (URL) referring to an index allocator
type: 'string',
// FIXME: pull in schema from bedrock-validation that uses
// `uri` pattern from ajv-formats once available
pattern: '^(.+):(.+)$'
};

Expand Down
Loading

0 comments on commit 18c5112

Please sign in to comment.