Skip to content

Commit 36c2cb8

Browse files
committed
Removing duplicated elements on the RAW field of the verificationResult
1 parent 967ecc7 commit 36c2cb8

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

lib/shc.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,21 @@ export async function sign(payload, privateKey) {
5454
function jwsParse(token) {
5555
let [headerEnc, bodyEnc, signatureEnc] = token.split(".");
5656
const headerRaw = base64url.decode(headerEnc);
57-
const signature = base64url.decode(signatureEnc);
57+
const signatureRaw = base64url.decode(signatureEnc);
5858
const bodyRaw = base64url.toBuffer(bodyEnc);
59-
return { headerRaw, bodyRaw, signature };
59+
return { headerRaw, bodyRaw, signatureRaw };
6060
}
6161

6262
function jwsInflate(jwsRaw) {
63-
jwsRaw.header = JSON.parse(jwsRaw.headerRaw)
64-
if (jwsRaw.header.zip == 'DEF') {
65-
jwsRaw.body = JSON.parse(Buffer.from(pako.inflateRaw(jwsRaw.bodyRaw)).toString());
63+
let header = JSON.parse(jwsRaw.headerRaw)
64+
let body = {}
65+
if (header.zip == 'DEF') {
66+
body = JSON.parse(Buffer.from(pako.inflateRaw(jwsRaw.bodyRaw)).toString());
67+
} else {
68+
body = JSON.parse(Buffer.from(jwsRaw.bodyRaw).toString());
6669
}
67-
return jwsRaw;
70+
let signature = base64url.encode(jwsRaw.signatureRaw);
71+
return { header, body, signature };
6872
}
6973

7074
export async function verify(jws, publicKeyArray) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pathcheck/shc-sdk",
3-
"version": "0.0.9",
3+
"version": "0.0.10",
44
"description": "Verifiable QR SDK for Smart Health Cards",
55
"scripts": {
66
"test": "mocha",

test/sign-verify.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,9 @@ describe('Testing SmartCard Examples', function() {
261261
expect(unpacked).to.eql(EXAMPLE1_SIGNED);
262262
});
263263
it('should unpack and verify example 2', async function() {
264-
const json = await unpackAndVerify(EXAMPLE2_PACKED);
265-
expect(json.contents).to.eql(EXAMPLE2_OBJECT);
266-
expect(json.issuer).to.eql({
264+
const result = await unpackAndVerify(EXAMPLE2_PACKED);
265+
expect(result.contents).to.eql(EXAMPLE2_OBJECT);
266+
expect(result.issuer).to.eql({
267267
displayName: { en: 'Untrusted Issuer: spec.smarthealth.cards/examples/issuer' },
268268
entityType: 'issuer',
269269
status: 'untrusted',

0 commit comments

Comments
 (0)