Skip to content

Commit

Permalink
helper function and better encodedList tests
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick <[email protected]>
  • Loading branch information
PatStLouis committed Aug 12, 2024
1 parent 48ace60 commit 850f249
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 26 deletions.
32 changes: 12 additions & 20 deletions tests/10-issue.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*!
* Copyright (c) 2022-2023 Digital Bazaar, Inc. All rights reserved.
*/
import * as sl from '@digitalbazaar/vc-status-list';
// import * as sl from '@digitalbazaar/vc-status-list';
import chai, {assert} from 'chai';
import {getSlc, issueVc, decodeSl} from './helpers.js';
import {decodeSl, getSlc, issueVc} from './helpers.js';
import {testCredential, testSlCredential} from './assertions.js';
import {filterByTag} from 'vc-test-suite-implementations';

Expand Down Expand Up @@ -434,24 +434,18 @@ describe('Issuers - BitstringStatusList',
const credentialSubject =
statusListCredential.credentialSubject;
const {encodedList} = credentialSubject;
await sl.decodeList({encodedList});
encodedList[0].should.equal('u',
'Expected encodedList to be a Multibase-encoded ' +
'base64url value.'
);
await decodeSl({encodedList});
}
}
);
it('The uncompressed bitstring MUST be at least 16KB in size.',
async function() {
this.test.link = 'https://www.w3.org/TR/vc-bitstring-status-list/#:~:text=The%20uncompressed%20bitstring%20MUST%20be%20at%20least%2016KB%20in%20size.';
for(statusListCredential of statusListCredentials) {
const credentialSubject =
statusListCredential.credentialSubject;
const {encodedList} = credentialSubject;
const decoded = await sl.decodeList({encodedList});
const {encodedList} = statusListCredential.credentialSubject;
const decoded = await decodeSl({encodedList});
// decoded size should be 16kb
const decodedSize = (decoded.length / 8) / 1024;
const decodedSize = (decoded.length / 100);
decodedSize.should.be.gte(16,
'Expected bitstring to be at least 16KB in size.'
);
Expand All @@ -469,17 +463,15 @@ describe('Issuers - BitstringStatusList',
this.test.cell.skipMessage = 'Test needs to be validated.';
this.skip();
for(statusListCredential of statusListCredentials) {
const credentialSubject =
statusListCredential.credentialSubject;
const {encodedList} = credentialSubject;
const decoded = await sl.decodeList({encodedList});
decoded.bitstring.bits[0].should.be.equal(0,
const {encodedList} = statusListCredential.credentialSubject;
const decoded = await decodeSl({encodedList});
decoded[0].should.be.equal(0,
'Expected the first index of the statusList to have ' +
'the value 0.'
);
decoded.bitstring.bits[
decoded.bitstring.bits.length - 1].should.be.equal(
decoded.bitstring.bits.length - 1,
decoded[
decoded.length - 1].should.be.equal(
decoded.length - 1,
'Expected the last index of the statusList to have ' +
'the value of the bitstring length minus 1.'
);
Expand Down
15 changes: 9 additions & 6 deletions tests/helpers.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
/*!
* Copyright (c) 2022-2023 Digital Bazaar, Inc. All rights reserved.
*/
import * as sl from '@digitalbazaar/vc-status-list';
import * as base64url from 'base64url-universal';
// import * as sl from '@digitalbazaar/vc-status-list';
import chai from 'chai';
import {createRequire} from 'node:module';
import {decodeList} from '@digitalbazaar/vc-status-list';
import {documentLoader} from './documentLoader.js';
import {httpClient} from '@digitalbazaar/http-client';
import https from 'https';
import {klona} from 'klona';
import {ungzip} from 'pako';
import {v4 as uuidv4} from 'uuid';
const require = createRequire(import.meta.url);
const validVc = require('./validVc.json');
Expand Down Expand Up @@ -107,15 +109,16 @@ export async function updateStatus({
return vc;
}

export async function decodeSl({
encodedList
}) {
export async function decodeSl({encodedList}) {
encodedList[0].should.equal('u',
'Expected encodedList to be a Multibase-encoded ' +
'base64url value.'
);
let decoded;
let error;
console.log(encodedList);
try {
// Uncompress encodedList
decoded = await sl.decodedList({encodedList});
decoded = ungzip(base64url.decode(encodedList.substring(1)));
} catch(e) {
error = e;
}
Expand Down

0 comments on commit 850f249

Please sign in to comment.