diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a2b0909..9f25f8d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -6,17 +6,17 @@ on: - 'master' jobs: build-test-publish: - runs-on: ubuntu-18.04 + runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 token: ${{ secrets.GH_TOKEN }} - name: "Setup node with cache" - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: - node-version: 14 + node-version: 18 cache: 'yarn' - run: yarn install --frozen-lockfile @@ -24,12 +24,12 @@ jobs: - name: "Setup git coordinates" run: | - git config user.name uport-automation-bot - git config user.email devops@uport.me + git config user.name ${{ secrets.GH_USER }} + git config user.email ${{ secrets.GH_EMAIL }} - name: "Run semantic-release" env: GH_TOKEN: ${{secrets.GH_TOKEN}} NPM_TOKEN: ${{secrets.NPM_TOKEN}} - if: github.ref == 'refs/heads/master' + if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/alpha' run: yarn run release diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d06fb54..9751de6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,16 +2,19 @@ name: Build and Test NODE on: [pull_request, workflow_dispatch, push] jobs: build-test: - runs-on: ubuntu-18.04 + runs-on: ubuntu-22.04 + strategy: + matrix: + version: [ 18 ] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 - name: "Setup node with cache" - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: - node-version: 14 + node-version: ${{ matrix.version }} cache: 'yarn' - run: yarn install --frozen-lockfile @@ -23,3 +26,4 @@ jobs: uses: codecov/codecov-action@v3 with: fail_ci_if_error: true + token: ${{ secrets.CODECOV_TOKEN }} diff --git a/example/react-app/package.json b/example/react-app/package.json index 080a7b9..667dd6b 100644 --- a/example/react-app/package.json +++ b/example/react-app/package.json @@ -3,7 +3,7 @@ "version": "0.1.0", "private": true, "dependencies": { - "did-resolver": "4.0.1", + "did-resolver": "4.1.0", "peer-did-resolver": "../../", "react": "18.2.0", "react-dom": "18.2.0", diff --git a/package.json b/package.json index 76db693..007346b 100644 --- a/package.json +++ b/package.json @@ -22,8 +22,8 @@ "url": "git@github.com:veramolabs/peer-did-resolver.git" }, "dependencies": { - "@aviarytech/did-peer": "^0.0.19", - "did-resolver": "^4.0.0" + "@aviarytech/did-peer": "^0.0.22", + "did-resolver": "^4.1.0" }, "scripts": { "test": "jest", diff --git a/src/__tests__/resolver.test.ts b/src/__tests__/resolver.test.ts index 6f61169..9baaefc 100644 --- a/src/__tests__/resolver.test.ts +++ b/src/__tests__/resolver.test.ts @@ -1,69 +1,103 @@ -import { Resolver, DIDDocument, Resolvable } from 'did-resolver' +import { DIDDocument, Resolvable, Resolver } from 'did-resolver' import { getResolver } from '../resolver' -describe('web did resolver', () => { - const did: string = - 'did:peer:2.Ez6LSpSrLxbAhg2SHwKk7kwpsH7DM7QjFS5iK6qP87eViohud.Vz6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludDEiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5MSJdLCJhIjpbImRpZGNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ' - - const validResponse: DIDDocument = { - '@context': [ - 'https://www.w3.org/ns/did/v1', - 'https://w3id.org/security/suites/ed25519-2020/v1', - 'https://w3id.org/security/suites/x25519-2020/v1', - ], - id: 'did:peer:2.Ez6LSpSrLxbAhg2SHwKk7kwpsH7DM7QjFS5iK6qP87eViohud.Vz6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludDEiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5MSJdLCJhIjpbImRpZGNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ', - verificationMethod: [ - { - id: 'did:peer:2.Ez6LSpSrLxbAhg2SHwKk7kwpsH7DM7QjFS5iK6qP87eViohud.Vz6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludDEiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5MSJdLCJhIjpbImRpZGNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ#6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V', - type: 'Ed25519VerificationKey2020', - controller: - 'did:peer:2.Ez6LSpSrLxbAhg2SHwKk7kwpsH7DM7QjFS5iK6qP87eViohud.Vz6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludDEiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5MSJdLCJhIjpbImRpZGNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ', - publicKeyMultibase: 'z6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V', - }, - { - id: 'did:peer:2.Ez6LSpSrLxbAhg2SHwKk7kwpsH7DM7QjFS5iK6qP87eViohud.Vz6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludDEiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5MSJdLCJhIjpbImRpZGNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ#6LSpSrLxbAhg2SHwKk7kwpsH7DM7QjFS5iK6qP87eViohud', - type: 'X25519KeyAgreementKey2020', - controller: - 'did:peer:2.Ez6LSpSrLxbAhg2SHwKk7kwpsH7DM7QjFS5iK6qP87eViohud.Vz6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludDEiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5MSJdLCJhIjpbImRpZGNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ', - publicKeyMultibase: 'z6LSpSrLxbAhg2SHwKk7kwpsH7DM7QjFS5iK6qP87eViohud', - }, - ], - authentication: [ - 'did:peer:2.Ez6LSpSrLxbAhg2SHwKk7kwpsH7DM7QjFS5iK6qP87eViohud.Vz6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludDEiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5MSJdLCJhIjpbImRpZGNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ#6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V', - ], - assertionMethod: [ - 'did:peer:2.Ez6LSpSrLxbAhg2SHwKk7kwpsH7DM7QjFS5iK6qP87eViohud.Vz6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludDEiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5MSJdLCJhIjpbImRpZGNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ#6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V', - ], - keyAgreement: [ - 'did:peer:2.Ez6LSpSrLxbAhg2SHwKk7kwpsH7DM7QjFS5iK6qP87eViohud.Vz6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludDEiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5MSJdLCJhIjpbImRpZGNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ#6LSpSrLxbAhg2SHwKk7kwpsH7DM7QjFS5iK6qP87eViohud', - ], - capabilityInvocation: [ - 'did:peer:2.Ez6LSpSrLxbAhg2SHwKk7kwpsH7DM7QjFS5iK6qP87eViohud.Vz6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludDEiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5MSJdLCJhIjpbImRpZGNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ#6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V', - ], - capabilityDelegation: [ - 'did:peer:2.Ez6LSpSrLxbAhg2SHwKk7kwpsH7DM7QjFS5iK6qP87eViohud.Vz6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludDEiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5MSJdLCJhIjpbImRpZGNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ#6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V', - ], - service: [ - { - id: '#didcommmessaging-0', - type: 'DIDCommMessaging', - serviceEndpoint: 'https://example.com/endpoint1', - routingKeys: ['did:example:somemediator#somekey1'], - accept: ['didcomm/v2', 'didcomm/aip2;env=rfc587'], - }, - ], - } - +describe('did:peer resolver', () => { let didResolver: Resolvable beforeAll(async () => { didResolver = new Resolver(getResolver()) }) - it('resolves document', async () => { + it('resolves simple document with num_algo=0', async () => { + expect.assertions(2) + const did = 'did:peer:0z6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V' + const result = await didResolver.resolve(did) + expect(result.didDocument).toEqual({ + '@context': ['https://www.w3.org/ns/did/v1', 'https://w3id.org/security/suites/ed25519-2020/v1'], + id: did, + verificationMethod: [ + { + id: 'did:peer:0z6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V#6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V', + type: 'Ed25519VerificationKey2020', + controller: 'did:peer:0z6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V', + publicKeyMultibase: 'z6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V', + }, + ], + authentication: [ + 'did:peer:0z6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V#6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V', + ], + assertionMethod: [ + 'did:peer:0z6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V#6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V', + ], + capabilityInvocation: [ + 'did:peer:0z6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V#6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V', + ], + capabilityDelegation: [ + 'did:peer:0z6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V#6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V', + ], + }) + expect(result.didResolutionMetadata.contentType).toEqual('application/did+ld+json') + }) + + it('resolves simple document with num_algo=2', async () => { + expect.assertions(2) + const did = + 'did:peer:2.Ez6LSpSrLxbAhg2SHwKk7kwpsH7DM7QjFS5iK6qP87eViohud.Vz6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludDEiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5MSJdLCJhIjpbImRpZGNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ' + const result = await didResolver.resolve(did) + expect(result.didDocument).toEqual({ + '@context': ['https://www.w3.org/ns/did/v1', 'https://w3id.org/security/multikey/v1', { '@base': did }], + id: did, + verificationMethod: [ + { + id: '#key-2', + type: 'Multikey', + controller: did, + publicKeyMultibase: 'z6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V', + }, + { + id: '#key-1', + type: 'Multikey', + controller: did, + publicKeyMultibase: 'z6LSpSrLxbAhg2SHwKk7kwpsH7DM7QjFS5iK6qP87eViohud', + }, + ], + keyAgreement: ['#key-1'], + authentication: ['#key-2'], + assertionMethod: ['#key-2'], + service: [ + { + id: '#service', + type: 'DIDCommMessaging', + serviceEndpoint: 'https://example.com/endpoint1', + routingKeys: ['did:example:somemediator#somekey1'], + accept: ['didcomm/v2', 'didcomm/aip2;env=rfc587'], + }, + ], + }) + expect(result.didResolutionMetadata.contentType).toEqual('application/did+ld+json') + }) + + it('resolves document with num_algo=2 and multiple service endpoints', async () => { expect.assertions(2) + const did = + 'did:peer:2.Ez6LSpSrLxbAhg2SHwKk7kwpsH7DM7QjFS5iK6qP87eViohud.Vz6MkqRYqQiSgvZQdnBytw86Qbs2ZWUkGv22od935YF4s8M7V.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludDEiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5MSJdLCJhIjpbImRpZGNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbS9lbmRwb2ludDIiLCJyIjpbImRpZDpleGFtcGxlOnNvbWVtZWRpYXRvciNzb21la2V5MiJdLCJhIjpbImRpZGNvbW0vdjIiLCJkaWRjb21tL2FpcDI7ZW52PXJmYzU4NyJdfQ' const result = await didResolver.resolve(did) - expect(result.didDocument).toEqual(validResponse) + expect(result.didDocument.service).toEqual([ + { + id: '#service', + type: 'DIDCommMessaging', + serviceEndpoint: 'https://example.com/endpoint1', + routingKeys: ['did:example:somemediator#somekey1'], + accept: ['didcomm/v2', 'didcomm/aip2;env=rfc587'], + }, + { + id: '#service-1', + type: 'DIDCommMessaging', + serviceEndpoint: 'https://example.com/endpoint2', + routingKeys: ['did:example:somemediator#somekey2'], + accept: ['didcomm/v2', 'didcomm/aip2;env=rfc587'], + }, + ]) expect(result.didResolutionMetadata.contentType).toEqual('application/did+ld+json') }) }) diff --git a/src/resolver.ts b/src/resolver.ts index ec9c668..12df27d 100644 --- a/src/resolver.ts +++ b/src/resolver.ts @@ -32,8 +32,7 @@ export function getResolver(): Record { break } - // TODO: this excludes the use of query params - const docIdMatchesDid = didDocument?.id === did + const docIdMatchesDid = didDocument?.id === parsed.did if (!docIdMatchesDid) { err = 'resolver_error: DID document id does not match requested did' // break // uncomment this when adding more checks diff --git a/tsconfig.json b/tsconfig.json index 4706bcd..cd6a6d0 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,6 @@ { "compilerOptions": { - "target": "ES2018", + "target": "ES2022", "module": "esnext", "lib": [ "dom", diff --git a/yarn.lock b/yarn.lock index 2b2c698..8e48ccc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10,10 +10,10 @@ "@jridgewell/gen-mapping" "^0.1.0" "@jridgewell/trace-mapping" "^0.3.9" -"@aviarytech/did-peer@^0.0.19": - version "0.0.19" - resolved "https://registry.yarnpkg.com/@aviarytech/did-peer/-/did-peer-0.0.19.tgz#5ac20d37d762f05be7a502826cb0fbb6cd319180" - integrity sha512-koSwVi++RIVWgYoNHHFZ95ouVqCNlLvqDfJfThOwExkZ2YSoRW/EFXeXFe33Gm7wR9gwTgoZXgi71hHO9d5RVQ== +"@aviarytech/did-peer@^0.0.22": + version "0.0.22" + resolved "https://registry.yarnpkg.com/@aviarytech/did-peer/-/did-peer-0.0.22.tgz#d0c15062c37fc6bf2720d31dbbf9eb23e09c2435" + integrity sha512-BdA7L9wpYNLf1c3d0yB92aoj1AUWE10p408VZ4IJXfavb/oNxALZRRRJTcvMdrd5P2XXQsP5+x4bXfO24iRURg== dependencies: buffer "^6.0.3" @@ -3984,13 +3984,6 @@ cosmiconfig@^7.0.0: path-type "^4.0.0" yaml "^1.10.0" -cross-fetch@^3.1.5: - version "3.1.5" - resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-3.1.5.tgz#e1389f44d9e7ba767907f7af8454787952ab534f" - integrity sha512-lvb1SBsI0Z7GDwmuid+mU3kWVBwTVUbe7S0H52yaaAdQOXq2YktTCZdlAcNKFzE6QtRz0snpw9bNiPeOIkkQvw== - dependencies: - node-fetch "2.6.7" - cross-spawn@^7.0.2, cross-spawn@^7.0.3: version "7.0.3" resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6" @@ -4207,10 +4200,10 @@ dezalgo@^1.0.0: asap "^2.0.0" wrappy "1" -did-resolver@^4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/did-resolver/-/did-resolver-4.0.0.tgz#fc8f657b4cd7f44c2921051fb046599fbe7d4b31" - integrity sha512-/roxrDr9EnAmLs+s9T+8+gcpilMo+IkeytcsGO7dcxvTmVJ+0Rt60HtV8o0UXHhGBo0Q+paMH/0ffXz1rqGFYg== +did-resolver@^4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/did-resolver/-/did-resolver-4.1.0.tgz#740852083c4fd5bf9729d528eca5d105aff45eb6" + integrity sha512-S6fWHvCXkZg2IhS4RcVHxwuyVejPR7c+a4Go0xbQ9ps5kILa8viiYQgrM4gfTyeTjJ0ekgJH9gk/BawTpmkbZA== diff-sequences@^29.0.0: version "29.0.0" @@ -6719,7 +6712,7 @@ node-emoji@^1.11.0: dependencies: lodash "^4.17.21" -node-fetch@2.6.7, node-fetch@^2.6.7: +node-fetch@^2.6.7: version "2.6.7" resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad" integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==