Skip to content

Commit

Permalink
add decodeSl helper function
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 2e2f99e commit 48ace60
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
27 changes: 17 additions & 10 deletions tests/10-issue.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import * as sl from '@digitalbazaar/vc-status-list';
import chai, {assert} from 'chai';
import {getSlc, issueVc} from './helpers.js';
import {getSlc, issueVc, decodeSl} from './helpers.js';

Check failure on line 6 in tests/10-issue.js

View workflow job for this annotation

GitHub Actions / lint (20.x)

Member 'decodeSl' of the import declaration should be sorted alphabetically

Check failure on line 6 in tests/10-issue.js

View workflow job for this annotation

GitHub Actions / lint (20.x)

'decodeSl' is defined but never used
import {testCredential, testSlCredential} from './assertions.js';
import {filterByTag} from 'vc-test-suite-implementations';

Expand Down Expand Up @@ -434,11 +434,11 @@ describe('Issuers - BitstringStatusList',
const credentialSubject =
statusListCredential.credentialSubject;
const {encodedList} = credentialSubject;
// Uncompress encodedList
const decoded = await sl.decodeList({encodedList});
should.exist(decoded,
'Expected encodedList to be a Multibase-encoded base64url' +
'representation of a GZIP-compressed bitstring.');
await sl.decodeList({encodedList});
encodedList[0].should.equal('u',
'Expected encodedList to be a Multibase-encoded ' +
'base64url value.'
);
}
}
);
Expand All @@ -449,9 +449,7 @@ describe('Issuers - BitstringStatusList',
const credentialSubject =
statusListCredential.credentialSubject;
const {encodedList} = credentialSubject;
// Uncompress encodedList
const decoded = await sl.decodeList({encodedList});
should.exist(decoded);
// decoded size should be 16kb
const decodedSize = (decoded.length / 8) / 1024;
decodedSize.should.be.gte(16,
Expand All @@ -468,14 +466,23 @@ describe('Issuers - BitstringStatusList',
'bit in the bitstring.',
async function() {
this.test.link = 'https://www.w3.org/TR/vc-bitstring-status-list/#:~:text=The%20bitstring%20MUST,Bitstring%20Encoding.';
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);
decoded.bitstring.bits[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(0);
decoded.bitstring.bits.length - 1].should.be.equal(
decoded.bitstring.bits.length - 1,
'Expected the last index of the statusList to have ' +
'the value of the bitstring length minus 1.'
);
}
}
);
Expand Down
19 changes: 19 additions & 0 deletions tests/helpers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*!
* Copyright (c) 2022-2023 Digital Bazaar, Inc. All rights reserved.
*/
import * as sl from '@digitalbazaar/vc-status-list';
import chai from 'chai';
import {createRequire} from 'node:module';
import {decodeList} from '@digitalbazaar/vc-status-list';
Expand Down Expand Up @@ -105,3 +106,21 @@ export async function updateStatus({
status.should.equal(true);
return vc;
}

export async function decodeSl({
encodedList
}) {
let decoded;
let error;
console.log(encodedList);
try {
// Uncompress encodedList
decoded = await sl.decodedList({encodedList});
} catch(e) {
error = e;
}
should.not.exist(error,
'Expected encodedList to be a Multibase-encoded base64url' +
'representation of a GZIP-compressed bitstring.');
return decoded;
}

0 comments on commit 48ace60

Please sign in to comment.