From 376d345855e737f016303e8a2926ba57e94a8a18 Mon Sep 17 00:00:00 2001 From: Nam Hoang Date: Sun, 12 Nov 2023 11:45:32 +0700 Subject: [PATCH 1/2] fix: stringify for normalization json-pointer for JSON string data Signed-off-by: Nam Hoang --- src/merkle/normalization/json-pointer.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/merkle/normalization/json-pointer.ts b/src/merkle/normalization/json-pointer.ts index 0d31689..e9c2881 100644 --- a/src/merkle/normalization/json-pointer.ts +++ b/src/merkle/normalization/json-pointer.ts @@ -3,7 +3,9 @@ import pointer from 'json-pointer'; const objectToMessages = (obj: any) => { const dict = pointer.dict(obj); const messages = Object.keys(dict).map(key => { - return `{"${key}": "${dict[key]}"}`; + const messageObj: { [k: string]: any } = {}; + messageObj[key] = dict[key]; + return JSON.stringify(messageObj); }); return messages; }; From cd711b9bf777fa4dc00f7190f9fd05d306875f36 Mon Sep 17 00:00:00 2001 From: Nam Hoang Date: Wed, 22 Nov 2023 14:41:35 +0700 Subject: [PATCH 2/2] refactor: use full json web key Signed-off-by: Nam Hoang --- src/MerkleDisclosureProof2021.ts | 39 +++++++++++++++++--------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/src/MerkleDisclosureProof2021.ts b/src/MerkleDisclosureProof2021.ts index 68e3f64..bbc4bcf 100644 --- a/src/MerkleDisclosureProof2021.ts +++ b/src/MerkleDisclosureProof2021.ts @@ -85,14 +85,14 @@ export class MerkleDisclosureProof2021 { proof.rootNonce = merkleProof.rootNonce; // produce compact jws - const k = await (this.key as any).useJwa({ - detached: false, - header: { - // we don't need this here, but we will need it when multi message JWS is possible. - // kid: this.key.id, - }, - }); - const signer = k.signer(); + // const k = await (this.key as any).useJwa({ + // detached: true, + // header: { + // // we don't need this here, but we will need it when multi message JWS is possible. + // // kid: this.key.id, + // }, + // }); + const signer = this.key.signer(); const signature = await signer.sign({ data: Buffer.from(merkleProof.root, 'hex').toString('base64'), }); @@ -144,7 +144,9 @@ export class MerkleDisclosureProof2021 { return result; } - async verifyProof(options: any): Promise<{ verified: boolean; error?: any }> { + async verifyProof( + options: any + ): Promise<{ verified: boolean; verificationMethod?: any; error?: any }> { const { document, proof, documentLoader } = options; const key = await this.getVerificationMethod({ @@ -175,6 +177,7 @@ export class MerkleDisclosureProof2021 { proof: { ...proof }, }; + delete documentWithProof.proof['@context']; delete documentWithProof.proof.proofs; delete documentWithProof.proof.jws; @@ -191,7 +194,7 @@ export class MerkleDisclosureProof2021 { ...(normalizationOptions as any)[normalization], } ); - return isMerkProofValid; + return { ...isMerkProofValid, verificationMethod: key }; } catch (e) { // console.warn(e); return { verified: false }; @@ -250,13 +253,13 @@ export class MerkleDisclosureProof2021 { return framed; } - const key: any = await JsonWebKey.from(framed); - return key.useJwa({ - detached: false, - header: { - // we don't need this here, but we will need it when multi message JWS is possible. - // kid: this.key.id, - }, - }); + return JsonWebKey.from(framed, { detached: false }); + // return key.useJwa({ + // detached: true, + // header: { + // // we don't need this here, but we will need it when multi message JWS is possible. + // // kid: this.key.id, + // }, + // }); } }