Skip to content

Commit

Permalink
Removing duplicated elements on the RAW field of the verificationResult
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorpamplona committed Jan 18, 2022
1 parent 967ecc7 commit 36c2cb8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
16 changes: 10 additions & 6 deletions lib/shc.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,21 @@ export async function sign(payload, privateKey) {
function jwsParse(token) {
let [headerEnc, bodyEnc, signatureEnc] = token.split(".");
const headerRaw = base64url.decode(headerEnc);
const signature = base64url.decode(signatureEnc);
const signatureRaw = base64url.decode(signatureEnc);
const bodyRaw = base64url.toBuffer(bodyEnc);
return { headerRaw, bodyRaw, signature };
return { headerRaw, bodyRaw, signatureRaw };
}

function jwsInflate(jwsRaw) {
jwsRaw.header = JSON.parse(jwsRaw.headerRaw)
if (jwsRaw.header.zip == 'DEF') {
jwsRaw.body = JSON.parse(Buffer.from(pako.inflateRaw(jwsRaw.bodyRaw)).toString());
let header = JSON.parse(jwsRaw.headerRaw)
let body = {}
if (header.zip == 'DEF') {
body = JSON.parse(Buffer.from(pako.inflateRaw(jwsRaw.bodyRaw)).toString());
} else {
body = JSON.parse(Buffer.from(jwsRaw.bodyRaw).toString());
}
return jwsRaw;
let signature = base64url.encode(jwsRaw.signatureRaw);
return { header, body, signature };
}

export async function verify(jws, publicKeyArray) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pathcheck/shc-sdk",
"version": "0.0.9",
"version": "0.0.10",
"description": "Verifiable QR SDK for Smart Health Cards",
"scripts": {
"test": "mocha",
Expand Down
6 changes: 3 additions & 3 deletions test/sign-verify.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,9 @@ describe('Testing SmartCard Examples', function() {
expect(unpacked).to.eql(EXAMPLE1_SIGNED);
});
it('should unpack and verify example 2', async function() {
const json = await unpackAndVerify(EXAMPLE2_PACKED);
expect(json.contents).to.eql(EXAMPLE2_OBJECT);
expect(json.issuer).to.eql({
const result = await unpackAndVerify(EXAMPLE2_PACKED);
expect(result.contents).to.eql(EXAMPLE2_OBJECT);
expect(result.issuer).to.eql({
displayName: { en: 'Untrusted Issuer: spec.smarthealth.cards/examples/issuer' },
entityType: 'issuer',
status: 'untrusted',
Expand Down

0 comments on commit 36c2cb8

Please sign in to comment.