Skip to content

Commit

Permalink
Support validating proof with domain expressed as an array.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlongley committed Dec 15, 2024
1 parent 8b7beb0 commit 2cf5922
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# jsonld-signatures ChangeLog

## 11.4.0 - 2024-12-dd

### Added
- Add support for validating proof with `domain` expressed as an array.

## 11.3.2 - 2024-11-06

### Fixed
Expand Down
17 changes: 13 additions & 4 deletions lib/purposes/AuthenticationProofPurpose.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,23 @@ module.exports = class AuthenticationProofPurpose extends
try {
// check challenge
if(proof.challenge !== this.challenge) {
throw new Error('The challenge is not as expected; ' +
throw new Error(
'The challenge is not as expected; ' +
`challenge="${proof.challenge}", expected="${this.challenge}"`);
}

// check domain
if(this.domain !== undefined && proof.domain !== this.domain) {
throw new Error('The domain is not as expected; ' +
`domain="${proof.domain}", expected="${this.domain}"`);
if(this.domain !== undefined) {
// `proof.domain` must equal `this.domain` OR if `proof.domain` is
// an array, the array must include `this.domain` as an element
const {domain} = proof;
if(!(domain === this.domain ||
(Array.isArray(domain) && domain.includes(this.domain)))) {
throw new Error(
'The domain is not as expected; ' +
`domain=${JSON.stringify(domain)}, ` +
`expected=${JSON.stringify(this.domain)}`);
}
}

return super.validate(
Expand Down

0 comments on commit 2cf5922

Please sign in to comment.