Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: stringify for normalization json-pointer for JSON string data #10

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 21 additions & 18 deletions src/MerkleDisclosureProof2021.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
});
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -175,6 +177,7 @@ export class MerkleDisclosureProof2021 {
proof: { ...proof },
};

delete documentWithProof.proof['@context'];
delete documentWithProof.proof.proofs;
delete documentWithProof.proof.jws;

Expand All @@ -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 };
Expand Down Expand Up @@ -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,
// },
// });
}
}
4 changes: 3 additions & 1 deletion src/merkle/normalization/json-pointer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down