Skip to content

Commit

Permalink
Test vectors for did:web resolution (#67)
Browse files Browse the repository at this point in the history
* WIP

* Add did:jwk resolve vectors

* add example structure

* Mention vectors in readme

* linting

* More detail in vector structure

* linting

* Added did:web resolution test vectors

* Added required metadata

* Update index.html

* Some additional goodies

* Merge snafu

* Fix the build

* Added error cases.

---------

Co-authored-by: Phoebe Lew <[email protected]>
  • Loading branch information
andresuribe87 and phoebe-lew authored Nov 27, 2023
1 parent c7c1f35 commit 5385c51
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 3 deletions.
16 changes: 14 additions & 2 deletions scripts/test-vector-validation/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ const validate = ajv.compile(vectorsSchema)
function validateTestVectors() {
const entries = fs.readdirSync(vectorsDir, { withFileTypes: true })

function validateDescriptions(testData) {
// accumulate duplicates inside a map
const descriptions = new Set()
for (const vector of testData.vectors) {
if (descriptions.has(vector.description)) {
console.log("Duplicate description found: \"" + vector.description + "\". Descriptions are meant to be unique.")
process.exit(1)
}
descriptions.add(vector.description)
}
}

for (const entry of entries) {
if (!entry.isDirectory()) {
continue
Expand All @@ -35,9 +47,9 @@ function validateTestVectors() {
if (!validate(testData)) {
console.log(`Validation failed for ${filePath}:`, validate.errors)
process.exit(1)
} else {
console.log(`Validation passed for ${filePath}`)
}
validateDescriptions(testData)
console.log(`Validation passed for ${filePath}`)
}
}
}
Expand Down
1 change: 1 addition & 0 deletions scripts/test-vector-validation/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test-harness/sdks/web5-kt/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ repositories {
mavenCentral()
maven(url = "https://jitpack.io")
maven(url = "https://repo.danubetech.com/repository/maven-public/")
maven(url = "https://repository.jboss.org/nexus/content/repositories/thirdparty-releases/")
}

dependencies {
Expand Down
92 changes: 92 additions & 0 deletions web5-test-vectors/did-web/resolve.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
{
"description": "did:web resolution",
"vectors": [
{
"description": "resolves to a well known URL",
"input": {
"didUri": "did:web:example.com",
"mockServer": {
"https://example.com/.well-known/did.json": {
"id": "did:web:example.com"
}
}
},
"output": {
"didResolutionMetadata": {},
"didDocument": {
"id": "did:web:example.com"
}
}
},
{
"description": "resolves to a URL with a path",
"input": {
"didUri": "did:web:w3c-ccg.github.io:user:alice",
"mockServer": {
"https://w3c-ccg.github.io/user/alice/did.json": {
"id": "did:web:w3c-ccg.github.io:user:alice"
}
}
},
"output": {
"didResolutionMetadata": {},
"didDocument": {
"id": "did:web:w3c-ccg.github.io:user:alice"
}
}
},
{
"description": "resolves to a URL with a path and a port",
"input": {
"didUri": "did:web:example.com%3A3000:user:alice",
"mockServer": {
"https://example.com:3000/user/alice/did.json": {
"id": "did:web:example.com%3A3000:user:alice"
}
}
},
"output": {
"didResolutionMetadata": {},
"didDocument": {
"id": "did:web:example.com%3A3000:user:alice"
}
}
},
{
"description": "methodNotSupported error returned when did method is not web",
"input": {
"didUri": "did:dht:gb46emk73wkenrut43ii67a3o5qctojcaucebth7r83pst6yeh8o"
},
"output": {
"didResolutionMetadata": {
"error": "methodNotSupported"
}
},
"errors": true
},
{
"description": "notFound error returned when domain does not exist",
"input": {
"didUri": "did:web:doesnotexist.com"
},
"output": {
"didResolutionMetadata": {
"error": "notFound"
}
},
"errors": true
},
{
"description": "invalidDid error returned for domain name with invalid character",
"input": {
"didUri": "did:web:invalidcharø.com"
},
"output": {
"didResolutionMetadata": {
"error": "invalidDid"
}
},
"errors": true
}
]
}
2 changes: 2 additions & 0 deletions web5-test-vectors/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ <h2>DIDs</h2>
href="https://tbd54566975.github.io/sdk-development/web5-test-vectors/did-jwk/resolve.json"
class="href">did:jwk resolve</a>
</li>
<li><a class="did-web-resolve" href="https://tbd54566975.github.io/sdk-development/web5-test-vectors/did-web/resolve.json" class="href">did:web resolve</a>
</li>
</ul>
</div>

Expand Down
3 changes: 2 additions & 1 deletion web5-test-vectors/vectors.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"default": false,
"description": "Indicates whether the test vector is expected to produce an error. Defaults to false if not present."
}
}
},
"additionalProperties": false
}
}
}
Expand Down

0 comments on commit 5385c51

Please sign in to comment.