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

add support for DIDs that specify a port #42

Merged
merged 2 commits into from
Sep 1, 2020
Merged
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
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# NEXT

## New Features

- Proper handling of did:web identifiers including ports: `did:web:example.com%3A1234`

## Bug Fixes

None

## Breaking Changes

None

# 3.1.1

## New Features
Expand Down
8 changes: 5 additions & 3 deletions src/proofPoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -687,11 +687,13 @@ class ProofPointRegistry {
const parts = did.split(":");
if (parts.length === 3) {
// did:web:<x>
return `https://${parts[2]}/.well-known/did.json`;
const hostname = decodeURIComponent(parts[2]);
return `https://${hostname}/.well-known/did.json`;
} else {
// did:web:<a>:<b>:...:<z>
const path = parts.slice(2).join("/");
return `https://${path}/did.json`;
const hostname = decodeURIComponent(parts[2]);
const path = parts.slice(3).join("/");
return `https://${hostname}/${path}/did.json`;
}
}

Expand Down
56 changes: 55 additions & 1 deletion test/proofPoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,37 @@ contract("ProofPoints", () => {
"type": "Secp256k1SignatureAuthentication2018",
"publicKey": "did:web:example.com:subpath#owner"
}]
}`
}`,
"https://example.com:1234/.well-known/did.json": `
{
"@context": "https://w3id.org/did/v1",
"id": "did:web:example.com%3A1234",
"publicKey": [{
"id": "did:web:example.com%3A1234#owner",
"type": "Secp256k1VerificationKey2018",
"owner": "did:web:example.com%3A1234",
"ethereumAddress": "${admin}"
}],
"authentication": [{
"type": "Secp256k1SignatureAuthentication2018",
"publicKey": "did:web:example.com%3A1234#owner"
}]
}`,
"https://example.com:1234/subpath/did.json": `
{
"@context": "https://w3id.org/did/v1",
"id": "did:web:example.com%3A1234:subpath",
"publicKey": [{
"id": "did:web:example.com%3A1234:subpath#owner",
"type": "Secp256k1VerificationKey2018",
"owner": "did:web:example.com%3A1234:subpath",
"ethereumAddress": "${admin}"
}],
"authentication": [{
"type": "Secp256k1SignatureAuthentication2018",
"publicKey": "did:web:example.com%3A1234:subpath#owner"
}]
}`,
});

subject = await ProofPointRegistry.deploy(
Expand Down Expand Up @@ -354,6 +384,30 @@ contract("ProofPoints", () => {
expect(isValid).to.be.true;
});

it("did:web issuer port", async () => {
const result = await subject.issue(
type,
"did:web:example.com%3A1234",
content
);
expect(result.proofPointObject.issuer).to.eq("did:web:example.com%3A1234");
const { isValid } = await subject.validate(result.proofPointObject);
expect(isValid).to.be.true;
});

it("did:web issuer port and subpath", async () => {
const result = await subject.issue(
type,
"did:web:example.com%3A1234:subpath",
content
);
expect(result.proofPointObject.issuer).to.eq(
"did:web:example.com%3A1234:subpath"
);
const { isValid } = await subject.validate(result.proofPointObject);
expect(isValid).to.be.true;
});

it("did:web issuer wrong context", async () => {
httpClient._responses["https://example.com/.well-known/did.json"] = `{
"@context": "wrongContext",
Expand Down