diff --git a/.eslintrc.cjs b/.eslintrc.cjs index c17e943e3..864452f7d 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -15,7 +15,7 @@ module.exports = { }, 'ignorePatterns': [ 'dist', - '__tests__' + '**/tests/compiled' ], rules: { 'key-spacing': [ diff --git a/.github/workflows/alpha-npm.yml b/.github/workflows/alpha-npm.yml index a9ce82365..189bc5ff1 100644 --- a/.github/workflows/alpha-npm.yml +++ b/.github/workflows/alpha-npm.yml @@ -23,13 +23,15 @@ jobs: matrix: package: [ + "agent", + "api", "common", + "credentials", "crypto", "dids", - "web5", - "web5-agent", - "web5-proxy-agent", - "web5-user-agent", + "identity-agent", + "proxy-agent", + "user-agent", ] steps: @@ -79,7 +81,7 @@ jobs: - name: Build all workspace packages run: npm run build - - name: Publish @tbd54566975/${{ matrix.package }}@${{ env.ALPHA_VERSION }} + - name: Publish @web5/${{ matrix.package }}@${{ env.ALPHA_VERSION }} env: NODE_AUTH_TOKEN: ${{secrets.npm_token}} run: | diff --git a/.github/workflows/release-npm.yml b/.github/workflows/release-npm.yml index 92c825a28..2fd864d67 100644 --- a/.github/workflows/release-npm.yml +++ b/.github/workflows/release-npm.yml @@ -24,13 +24,15 @@ jobs: matrix: package: [ + "agent", + "api", "common", + "credentials", "crypto", "dids", - "web5", - "web5-agent", - "web5-proxy-agent", - "web5-user-agent", + "identity-agent", + "proxy-agent", + "user-agent", ] steps: @@ -62,7 +64,7 @@ jobs: cd packages/${{ matrix.package }} # Fetch the published version on NPMjs.com. - PUBLISHED_VERSION=$(npm view @tbd54566975/${{ matrix.package }} version 2>/dev/null || echo "0.0.0") + PUBLISHED_VERSION=$(npm view @web5/${{ matrix.package }} version 2>/dev/null || echo "0.0.0") echo "Published Version: $PUBLISHED_VERSION" # Fetch the version in the GitHub repo's package.json file. @@ -73,10 +75,10 @@ jobs: # Compare the repo and NPMjs.com package versions. IS_GREATER=$(semver --range ">$PUBLISHED_VERSION" $REPO_VERSION || true) if [ -n "$IS_GREATER" ] ; then - echo "@tbd54566975/${{ matrix.package }}@$REPO_VERSION is latest" + echo "@web5/${{ matrix.package }}@$REPO_VERSION is latest" echo "IS_LATEST=true" >> $GITHUB_ENV else - echo "@tbd54566975/${{ matrix.package }}@$REPO_VERSION is already published or repo version is lower" + echo "@web5/${{ matrix.package }}@$REPO_VERSION is already published or repo version is lower" echo "IS_LATEST=false" >> $GITHUB_ENV fi shell: bash @@ -89,7 +91,7 @@ jobs: if: env.IS_LATEST == 'true' run: npm run build - - name: Publish @tbd54566975/${{ matrix.package }}@${{ env.REPO_VERSION }} + - name: Publish @web5/${{ matrix.package }}@${{ env.REPO_VERSION }} if: env.IS_LATEST == 'true' env: NODE_AUTH_TOKEN: ${{secrets.npm_token}} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 92d30f9a3..6454c9c23 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -172,7 +172,7 @@ After one or more PRs have been approved and merged by project maintainers, a Gi version tag. The act of creating the GitHub release triggers automated publication of the package to the [NPM Registry](https://npmjs.com) which will be tagged as _latest_. -The next time someone runs `npm install @tbd54566975/` the newly published release will be installed. +The next time someone runs `npm install @web5/` the newly published release will be installed. #### Alpha Releases @@ -198,5 +198,5 @@ the [NPM Registry](https://npmjs.com) within a few minutes. > **Note** > Alpha version will never be tagged as _latest_. -To install an `alpha` tagged release use either the `npm install @tbd54566975/@alpha` or -`npm install @tbd5456975/@x.y.z-alpha-YYYYMMDD-commithash` syntax. +To install an `alpha` tagged release use either the `npm install @web5/@alpha` or +`npm install @web5/@x.y.z-alpha-YYYYMMDD-commithash` syntax. diff --git a/README.md b/README.md index bc8ac7471..4a22e28ca 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ # Web5 JS SDK -[![NPM](https://img.shields.io/npm/v/@tbd54566975/web5.svg?style=flat-square&logo=npm&logoColor=FFFFFF&color=FFEC19&santize=true)](https://www.npmjs.com/package/@tbd54566975/web5) +[![NPM](https://img.shields.io/npm/v/@web5/api.svg?style=flat-square&logo=npm&logoColor=FFFFFF&color=FFEC19&santize=true)](https://www.npmjs.com/package/@web5/api) [![Build Status](https://img.shields.io/github/actions/workflow/status/TBD54566975/web5-js/tests-ci.yml?branch=main&logo=github&label=ci&logoColor=FFFFFF&style=flat-square)](https://github.com/TBD54566975/web5-js/actions/workflows/tests-ci.yml) -[![Coverage](https://img.shields.io/codecov/c/gh/frankhinek/test-web5-js/main?logo=codecov&logoColor=FFFFFF&style=flat-square&token=YI87CKF1LI)](https://codecov.io/github/TBD54566975/web5-js) -[![License](https://img.shields.io/npm/l/@tbd54566975/web5.svg?style=flat-square&color=24f2ff&logo=apache&logoColor=FFFFFF&santize=true)](https://github.com/TBD54566975/web5-js/blob/main/LICENSE) +[![Coverage](https://img.shields.io/codecov/c/gh/TBD54566975/web5-js/main?logo=codecov&logoColor=FFFFFF&style=flat-square&token=YI87CKF1LI)](https://codecov.io/github/TBD54566975/web5-js) +[![License](https://img.shields.io/npm/l/@web5/api.svg?style=flat-square&color=24f2ff&logo=apache&logoColor=FFFFFF&santize=true)](https://github.com/TBD54566975/web5-js/blob/main/LICENSE) [![Chat](https://img.shields.io/badge/chat-on%20discord-7289da.svg?style=flat-square&color=9a1aff&logo=discord&logoColor=FFFFFF&sanitize=true)](https://discord.com/channels/937858703112155166/969272658501976117) Making developing with Web5 components at least 5 times easier to work with. @@ -46,17 +46,17 @@ possible. _NPM_ ```yaml -npm install @tbd54566975/web5 +npm install @web5/api ``` _CDNs_ ```yaml -https://unpkg.com/@tbd54566975/web5@0.7.11/dist/browser.js +https://unpkg.com/@web5/api@0.8.1/dist/browser.js ``` ```yaml -https://cdn.jsdelivr.net/npm/@tbd54566975/web5@0.7.11/dist/browser.mjs +https://cdn.jsdelivr.net/npm/@web5/api@0.8.1/dist/browser.mjs ``` ## Usage @@ -64,7 +64,7 @@ https://cdn.jsdelivr.net/npm/@tbd54566975/web5@0.7.11/dist/browser.mjs ### Importing the SDK ```javascript -import { Web5 } from "@tbd54566975/web5"; +import { Web5 } from "@web5/api"; ``` or diff --git a/codecov.yml b/codecov.yml index b8264a083..4eeee39d5 100644 --- a/codecov.yml +++ b/codecov.yml @@ -8,9 +8,13 @@ component_management: target: auto # auto compares coverage to the previous base commit threshold: 5% # allows a 5% drop from the previous base commit coverage - type: patch - target: 100 # every PR opened should strive for full test coverage + target: 90 # every PR opened should strive for at least 90% coverage individual_components: + - component_id: package-api + name: api + paths: ["packages/api/**"] + - component_id: package_common name: common paths: ["packages/common/**"] @@ -27,21 +31,21 @@ component_management: name: dids paths: ["packages/dids/**"] - - component_id: package-web5 - name: web5 - paths: ["packages/web5/**"] + - component_id: package-agent + name: agent + paths: ["packages/agent/**"] - - component_id: package-web5-agent - name: web5-agent - paths: ["packages/web5-agent/**"] + - component_id: package-identity-agent + name: identity-agent + paths: ["packages/identity-agent/**"] - - component_id: package-web5-proxy-agent - name: web5-proxy-agent - paths: ["packages/web5-proxy-agent/**"] + - component_id: package-proxy-agent + name: proxy-agent + paths: ["packages/proxy-agent/**"] - - component_id: package-web5-user-agent - name: web5-user-agent - paths: ["packages/web5-user-agent/**"] + - component_id: package-user-agent + name: user-agent + paths: ["packages/user-agent/**"] coverage: status: diff --git a/package-lock.json b/package-lock.json index 3260e6aa5..6b72ba037 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,7912 +1,7950 @@ { - "name": "web5-js", - "lockfileVersion": 3, - "requires": true, - "packages": { - "": { - "workspaces": [ - "packages/common", - "packages/crypto", - "packages/web5-agent", - "packages/dids", - "packages/credentials", - "packages/web5-user-agent", - "packages/web5-proxy-agent", - "packages/web5" - ] - }, - "node_modules/@aashutoshrathi/word-wrap": { - "version": "1.2.6", - "resolved": "https://registry.npmjs.org/@aashutoshrathi/word-wrap/-/word-wrap-1.2.6.tgz", - "integrity": "sha512-1Yjs2SvM8TflER/OD3cOjhWWOZb58A2t7wpE2S9XfBYTiIl+XFhQG2bjy4Pu1I+EAlCNUzRDYDdFwFYUKvXcIA==", - "dev": true, - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/@assemblyscript/loader": { - "version": "0.9.4", - "resolved": "https://registry.npmjs.org/@assemblyscript/loader/-/loader-0.9.4.tgz", - "integrity": "sha512-HazVq9zwTVwGmqdwYzu7WyQ6FQVZ7SwET0KKQuKm55jD0IfUpZgN0OPIiZG3zV1iSrVYcN0bdwLRXI/VNCYsUA==" - }, - "node_modules/@bcoe/v8-coverage": { - "version": "0.2.3", - "resolved": "https://registry.npmjs.org/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz", - "integrity": "sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==", - "dev": true - }, - "node_modules/@colors/colors": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/@colors/colors/-/colors-1.5.0.tgz", - "integrity": "sha512-ooWCrlZP11i8GImSjTHYHLkvFDP48nS4+204nGb1RiX/WXYHmJA2III9/e2DWVabCESdW7hBAEzHRqUn9OUVvQ==", - "dev": true, - "engines": { - "node": ">=0.1.90" - } - }, - "node_modules/@decentralized-identity/ion-pow-sdk": { - "version": "1.0.17", - "resolved": "https://registry.npmjs.org/@decentralized-identity/ion-pow-sdk/-/ion-pow-sdk-1.0.17.tgz", - "integrity": "sha512-vk7DTDM8aKDbFyu1ad/qkoRrGL4q+KvNeL/FNZXhkWPaDhVExBN/qGEoRLf1YSfFe+myto3+4RYTPut+riiqnw==", - "dependencies": { - "buffer": "6.0.3", - "cross-fetch": "3.1.5", - "hash-wasm": "4.9.0" - } - }, - "node_modules/@decentralized-identity/ion-pow-sdk/node_modules/cross-fetch": { - "version": "3.1.5", - "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.5.tgz", - "integrity": "sha512-lvb1SBsI0Z7GDwmuid+mU3kWVBwTVUbe7S0H52yaaAdQOXq2YktTCZdlAcNKFzE6QtRz0snpw9bNiPeOIkkQvw==", - "dependencies": { - "node-fetch": "2.6.7" - } - }, - "node_modules/@decentralized-identity/ion-pow-sdk/node_modules/node-fetch": { - "version": "2.6.7", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz", - "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==", - "dependencies": { - "whatwg-url": "^5.0.0" - }, - "engines": { - "node": "4.x || >=6.0.0" - }, - "peerDependencies": { - "encoding": "^0.1.0" - }, - "peerDependenciesMeta": { - "encoding": { - "optional": true - } - } - }, - "node_modules/@decentralized-identity/ion-sdk": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/@decentralized-identity/ion-sdk/-/ion-sdk-1.0.1.tgz", - "integrity": "sha512-+P+DXcRSFjsEsI5KIqUmVjpzgUT28B2lWpTO+IxiBcfibAN/1Sg20NebGTO/+serz2CnSZf95N2a1OZ6eXypGQ==", - "dependencies": { - "@noble/ed25519": "^2.0.0", - "@noble/secp256k1": "^2.0.0", - "canonicalize": "^2.0.0", - "multiformats": "^12.0.1", - "multihashes": "^4.0.3", - "uri-js": "^4.4.1" - } - }, - "node_modules/@decentralized-identity/ion-sdk/node_modules/multiformats": { - "version": "12.0.1", - "resolved": "https://registry.npmjs.org/multiformats/-/multiformats-12.0.1.tgz", - "integrity": "sha512-s01wijBJoDUqESWSzePY0lvTw7J3PVO9x2Cc6ASI5AMZM2Gnhh7BC17+nlFhHKU7dDzaCaRfb+NiqNzOsgPUoQ==", - "engines": { - "node": ">=16.0.0", - "npm": ">=7.0.0" - } - }, - "node_modules/@decentralized-identity/ion-tools": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/@decentralized-identity/ion-tools/-/ion-tools-1.1.4.tgz", - "integrity": "sha512-/ouKiDXM8nRVsXJ6CbN0sY+SUj6PGv6LRAQitxEOj1NlKEDkMD+ZqkAeM+Ar/IHEW9PdsE2Wc+WQAsesQesbwg==", - "dependencies": { - "@decentralized-identity/ion-pow-sdk": "^1.0.17", - "@decentralized-identity/ion-sdk": "^1.0.1", - "@noble/ed25519": "^2.0.0", - "@noble/secp256k1": "^2.0.0", - "chai": "^4.3.7", - "cross-fetch": "4.0.0", - "multiformats": "^12.0.1" - }, - "engines": { - "node": ">= 18" - } - }, - "node_modules/@decentralized-identity/ion-tools/node_modules/multiformats": { - "version": "12.0.1", - "resolved": "https://registry.npmjs.org/multiformats/-/multiformats-12.0.1.tgz", - "integrity": "sha512-s01wijBJoDUqESWSzePY0lvTw7J3PVO9x2Cc6ASI5AMZM2Gnhh7BC17+nlFhHKU7dDzaCaRfb+NiqNzOsgPUoQ==", - "engines": { - "node": ">=16.0.0", - "npm": ">=7.0.0" - } - }, - "node_modules/@esbuild/android-arm": { - "version": "0.16.17", - "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.16.17.tgz", - "integrity": "sha512-N9x1CMXVhtWEAMS7pNNONyA14f71VPQN9Cnavj1XQh6T7bskqiLLrSca4O0Vr8Wdcga943eThxnVp3JLnBMYtw==", - "cpu": [ - "arm" - ], - "dev": true, - "optional": true, - "os": [ - "android" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/android-arm64": { - "version": "0.16.17", - "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.16.17.tgz", - "integrity": "sha512-MIGl6p5sc3RDTLLkYL1MyL8BMRN4tLMRCn+yRJJmEDvYZ2M7tmAf80hx1kbNEUX2KJ50RRtxZ4JHLvCfuB6kBg==", - "cpu": [ - "arm64" - ], - "dev": true, - "optional": true, - "os": [ - "android" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/android-x64": { - "version": "0.16.17", - "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.16.17.tgz", - "integrity": "sha512-a3kTv3m0Ghh4z1DaFEuEDfz3OLONKuFvI4Xqczqx4BqLyuFaFkuaG4j2MtA6fuWEFeC5x9IvqnX7drmRq/fyAQ==", - "cpu": [ - "x64" - ], - "dev": true, - "optional": true, - "os": [ - "android" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/darwin-arm64": { - "version": "0.16.17", - "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.16.17.tgz", - "integrity": "sha512-/2agbUEfmxWHi9ARTX6OQ/KgXnOWfsNlTeLcoV7HSuSTv63E4DqtAc+2XqGw1KHxKMHGZgbVCZge7HXWX9Vn+w==", - "cpu": [ - "arm64" - ], - "dev": true, - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/darwin-x64": { - "version": "0.16.17", - "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.16.17.tgz", - "integrity": "sha512-2By45OBHulkd9Svy5IOCZt376Aa2oOkiE9QWUK9fe6Tb+WDr8hXL3dpqi+DeLiMed8tVXspzsTAvd0jUl96wmg==", - "cpu": [ - "x64" - ], - "dev": true, - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/freebsd-arm64": { - "version": "0.16.17", - "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.16.17.tgz", - "integrity": "sha512-mt+cxZe1tVx489VTb4mBAOo2aKSnJ33L9fr25JXpqQqzbUIw/yzIzi+NHwAXK2qYV1lEFp4OoVeThGjUbmWmdw==", - "cpu": [ - "arm64" - ], - "dev": true, - "optional": true, - "os": [ - "freebsd" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/freebsd-x64": { - "version": "0.16.17", - "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.16.17.tgz", - "integrity": "sha512-8ScTdNJl5idAKjH8zGAsN7RuWcyHG3BAvMNpKOBaqqR7EbUhhVHOqXRdL7oZvz8WNHL2pr5+eIT5c65kA6NHug==", - "cpu": [ - "x64" - ], - "dev": true, - "optional": true, - "os": [ - "freebsd" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/linux-arm": { - "version": "0.16.17", - "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.16.17.tgz", - "integrity": "sha512-iihzrWbD4gIT7j3caMzKb/RsFFHCwqqbrbH9SqUSRrdXkXaygSZCZg1FybsZz57Ju7N/SHEgPyaR0LZ8Zbe9gQ==", - "cpu": [ - "arm" - ], - "dev": true, - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/linux-arm64": { - "version": "0.16.17", - "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.16.17.tgz", - "integrity": "sha512-7S8gJnSlqKGVJunnMCrXHU9Q8Q/tQIxk/xL8BqAP64wchPCTzuM6W3Ra8cIa1HIflAvDnNOt2jaL17vaW+1V0g==", - "cpu": [ - "arm64" - ], - "dev": true, - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/linux-ia32": { - "version": "0.16.17", - "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.16.17.tgz", - "integrity": "sha512-kiX69+wcPAdgl3Lonh1VI7MBr16nktEvOfViszBSxygRQqSpzv7BffMKRPMFwzeJGPxcio0pdD3kYQGpqQ2SSg==", - "cpu": [ - "ia32" - ], - "dev": true, - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/linux-loong64": { - "version": "0.16.17", - "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.16.17.tgz", - "integrity": "sha512-dTzNnQwembNDhd654cA4QhbS9uDdXC3TKqMJjgOWsC0yNCbpzfWoXdZvp0mY7HU6nzk5E0zpRGGx3qoQg8T2DQ==", - "cpu": [ - "loong64" - ], - "dev": true, - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/linux-mips64el": { - "version": "0.16.17", - "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.16.17.tgz", - "integrity": "sha512-ezbDkp2nDl0PfIUn0CsQ30kxfcLTlcx4Foz2kYv8qdC6ia2oX5Q3E/8m6lq84Dj/6b0FrkgD582fJMIfHhJfSw==", - "cpu": [ - "mips64el" - ], - "dev": true, - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/linux-ppc64": { - "version": "0.16.17", - "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.16.17.tgz", - "integrity": "sha512-dzS678gYD1lJsW73zrFhDApLVdM3cUF2MvAa1D8K8KtcSKdLBPP4zZSLy6LFZ0jYqQdQ29bjAHJDgz0rVbLB3g==", - "cpu": [ - "ppc64" - ], - "dev": true, - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/linux-riscv64": { - "version": "0.16.17", - "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.16.17.tgz", - "integrity": "sha512-ylNlVsxuFjZK8DQtNUwiMskh6nT0vI7kYl/4fZgV1llP5d6+HIeL/vmmm3jpuoo8+NuXjQVZxmKuhDApK0/cKw==", - "cpu": [ - "riscv64" - ], - "dev": true, - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/linux-s390x": { - "version": "0.16.17", - "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.16.17.tgz", - "integrity": "sha512-gzy7nUTO4UA4oZ2wAMXPNBGTzZFP7mss3aKR2hH+/4UUkCOyqmjXiKpzGrY2TlEUhbbejzXVKKGazYcQTZWA/w==", - "cpu": [ - "s390x" - ], - "dev": true, - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/linux-x64": { - "version": "0.16.17", - "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.16.17.tgz", - "integrity": "sha512-mdPjPxfnmoqhgpiEArqi4egmBAMYvaObgn4poorpUaqmvzzbvqbowRllQ+ZgzGVMGKaPkqUmPDOOFQRUFDmeUw==", - "cpu": [ - "x64" - ], - "dev": true, - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/netbsd-x64": { - "version": "0.16.17", - "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.16.17.tgz", - "integrity": "sha512-/PzmzD/zyAeTUsduZa32bn0ORug+Jd1EGGAUJvqfeixoEISYpGnAezN6lnJoskauoai0Jrs+XSyvDhppCPoKOA==", - "cpu": [ - "x64" - ], - "dev": true, - "optional": true, - "os": [ - "netbsd" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/openbsd-x64": { - "version": "0.16.17", - "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.16.17.tgz", - "integrity": "sha512-2yaWJhvxGEz2RiftSk0UObqJa/b+rIAjnODJgv2GbGGpRwAfpgzyrg1WLK8rqA24mfZa9GvpjLcBBg8JHkoodg==", - "cpu": [ - "x64" - ], - "dev": true, - "optional": true, - "os": [ - "openbsd" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/sunos-x64": { - "version": "0.16.17", - "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.16.17.tgz", - "integrity": "sha512-xtVUiev38tN0R3g8VhRfN7Zl42YCJvyBhRKw1RJjwE1d2emWTVToPLNEQj/5Qxc6lVFATDiy6LjVHYhIPrLxzw==", - "cpu": [ - "x64" - ], - "dev": true, - "optional": true, - "os": [ - "sunos" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/win32-arm64": { - "version": "0.16.17", - "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.16.17.tgz", - "integrity": "sha512-ga8+JqBDHY4b6fQAmOgtJJue36scANy4l/rL97W+0wYmijhxKetzZdKOJI7olaBaMhWt8Pac2McJdZLxXWUEQw==", - "cpu": [ - "arm64" - ], - "dev": true, - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/win32-ia32": { - "version": "0.16.17", - "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.16.17.tgz", - "integrity": "sha512-WnsKaf46uSSF/sZhwnqE4L/F89AYNMiD4YtEcYekBt9Q7nj0DiId2XH2Ng2PHM54qi5oPrQ8luuzGszqi/veig==", - "cpu": [ - "ia32" - ], - "dev": true, - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/win32-x64": { - "version": "0.16.17", - "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.16.17.tgz", - "integrity": "sha512-y+EHuSchhL7FjHgvQL/0fnnFmO4T1bhvWANX6gcnqTjtnKWbTvUMCpGnv2+t+31d7RzyEAYAd4u2fnIhHL6N/Q==", - "cpu": [ - "x64" - ], - "dev": true, - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@eslint-community/eslint-utils": { - "version": "4.4.0", - "resolved": "https://registry.npmjs.org/@eslint-community/eslint-utils/-/eslint-utils-4.4.0.tgz", - "integrity": "sha512-1/sA4dwrzBAyeUoQ6oxahHKmrZvsnLCg4RfxW3ZFGGmQkSNQPFNLV9CUEFQP1x9EYXHTo5p6xdhZM1Ne9p/AfA==", - "dev": true, - "dependencies": { - "eslint-visitor-keys": "^3.3.0" - }, - "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - }, - "peerDependencies": { - "eslint": "^6.0.0 || ^7.0.0 || >=8.0.0" - } - }, - "node_modules/@eslint-community/regexpp": { - "version": "4.6.2", - "resolved": "https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.6.2.tgz", - "integrity": "sha512-pPTNuaAG3QMH+buKyBIGJs3g/S5y0caxw0ygM3YyE6yJFySwiGGSzA+mM3KJ8QQvzeLh3blwgSonkFjgQdxzMw==", - "dev": true, - "engines": { - "node": "^12.0.0 || ^14.0.0 || >=16.0.0" - } - }, - "node_modules/@eslint/eslintrc": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-2.1.1.tgz", - "integrity": "sha512-9t7ZA7NGGK8ckelF0PQCfcxIUzs1Md5rrO6U/c+FIQNanea5UZC0wqKXH4vHBccmu4ZJgZ2idtPeW7+Q2npOEA==", - "dev": true, - "dependencies": { - "ajv": "^6.12.4", - "debug": "^4.3.2", - "espree": "^9.6.0", - "globals": "^13.19.0", - "ignore": "^5.2.0", - "import-fresh": "^3.2.1", - "js-yaml": "^4.1.0", - "minimatch": "^3.1.2", - "strip-json-comments": "^3.1.1" - }, - "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - }, - "funding": { - "url": "https://opencollective.com/eslint" - } - }, - "node_modules/@eslint/eslintrc/node_modules/ajv": { - "version": "6.12.6", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", - "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", - "dev": true, - "dependencies": { - "fast-deep-equal": "^3.1.1", - "fast-json-stable-stringify": "^2.0.0", - "json-schema-traverse": "^0.4.1", - "uri-js": "^4.2.2" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/epoberezkin" - } - }, - "node_modules/@eslint/eslintrc/node_modules/json-schema-traverse": { - "version": "0.4.1", - "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", - "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", - "dev": true - }, - "node_modules/@eslint/js": { - "version": "8.39.0", - "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.39.0.tgz", - "integrity": "sha512-kf9RB0Fg7NZfap83B3QOqOGg9QmD9yBudqQXzzOtn3i4y7ZUXe5ONeW34Gwi+TxhH4mvj72R1Zc300KUMa9Bng==", - "dev": true, - "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - } - }, - "node_modules/@faker-js/faker": { - "version": "8.0.1", - "resolved": "https://registry.npmjs.org/@faker-js/faker/-/faker-8.0.1.tgz", - "integrity": "sha512-kbh5MenpTN9U0B4QcOI1NoTPlZHniSYQ3BHbhAnPjJGAmmFqxoxTE4sGdpy7ZOO9038DPGCuhXyMkjOr05uVwA==", - "dev": true, - "funding": [ - { - "type": "opencollective", - "url": "https://opencollective.com/fakerjs" - } - ], - "engines": { - "node": "^14.17.0 || ^16.13.0 || >=18.0.0", - "npm": ">=6.14.13" - } - }, - "node_modules/@humanwhocodes/config-array": { - "version": "0.11.10", - "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.10.tgz", - "integrity": "sha512-KVVjQmNUepDVGXNuoRRdmmEjruj0KfiGSbS8LVc12LMsWDQzRXJ0qdhN8L8uUigKpfEHRhlaQFY0ib1tnUbNeQ==", - "dev": true, - "dependencies": { - "@humanwhocodes/object-schema": "^1.2.1", - "debug": "^4.1.1", - "minimatch": "^3.0.5" - }, - "engines": { - "node": ">=10.10.0" - } - }, - "node_modules/@humanwhocodes/module-importer": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/@humanwhocodes/module-importer/-/module-importer-1.0.1.tgz", - "integrity": "sha512-bxveV4V8v5Yb4ncFTT3rPSgZBOpCkjfK0y4oVVVJwIuDVBRMDXrPyXRL988i5ap9m9bnyEEjWfm5WkBmtffLfA==", - "dev": true, - "engines": { - "node": ">=12.22" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/nzakas" - } - }, - "node_modules/@humanwhocodes/object-schema": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-1.2.1.tgz", - "integrity": "sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==", - "dev": true - }, - "node_modules/@ipld/dag-cbor": { - "version": "9.0.3", - "resolved": "https://registry.npmjs.org/@ipld/dag-cbor/-/dag-cbor-9.0.3.tgz", - "integrity": "sha512-A2UFccS0+sARK9xwXiVZIaWbLbPxLGP3UZOjBeOMWfDY04SXi8h1+t4rHBzOlKYF/yWNm3RbFLyclWO7hZcy4g==", - "dependencies": { - "cborg": "^2.0.1", - "multiformats": "^12.0.1" - }, - "engines": { - "node": ">=16.0.0", - "npm": ">=7.0.0" - } - }, - "node_modules/@ipld/dag-cbor/node_modules/multiformats": { - "version": "12.0.1", - "resolved": "https://registry.npmjs.org/multiformats/-/multiformats-12.0.1.tgz", - "integrity": "sha512-s01wijBJoDUqESWSzePY0lvTw7J3PVO9x2Cc6ASI5AMZM2Gnhh7BC17+nlFhHKU7dDzaCaRfb+NiqNzOsgPUoQ==", - "engines": { - "node": ">=16.0.0", - "npm": ">=7.0.0" - } - }, - "node_modules/@ipld/dag-pb": { - "version": "4.0.4", - "resolved": "https://registry.npmjs.org/@ipld/dag-pb/-/dag-pb-4.0.4.tgz", - "integrity": "sha512-lX0c6ZAwD8ZKtjbawxotP8XNyR6z7/NIk7wXuhDlFT4MrNo/AOefZEUWjAw8CGz3EG3mau4P66VpsZwToVLHDg==", - "dependencies": { - "multiformats": "^12.0.1" - }, - "engines": { - "node": ">=16.0.0", - "npm": ">=7.0.0" - } - }, - "node_modules/@ipld/dag-pb/node_modules/multiformats": { - "version": "12.0.1", - "resolved": "https://registry.npmjs.org/multiformats/-/multiformats-12.0.1.tgz", - "integrity": "sha512-s01wijBJoDUqESWSzePY0lvTw7J3PVO9x2Cc6ASI5AMZM2Gnhh7BC17+nlFhHKU7dDzaCaRfb+NiqNzOsgPUoQ==", - "engines": { - "node": ">=16.0.0", - "npm": ">=7.0.0" - } - }, - "node_modules/@istanbuljs/schema": { - "version": "0.1.3", - "resolved": "https://registry.npmjs.org/@istanbuljs/schema/-/schema-0.1.3.tgz", - "integrity": "sha512-ZXRY4jNvVgSVQ8DL3LTcakaAtXwTVUxE81hslsyD2AtoXW/wVob10HkOJ1X/pAlcI7D+2YoZKg5do8G/w6RYgA==", - "dev": true, - "engines": { - "node": ">=8" - } - }, - "node_modules/@jridgewell/gen-mapping": { - "version": "0.3.3", - "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.3.tgz", - "integrity": "sha512-HLhSWOLRi875zjjMG/r+Nv0oCW8umGb0BgEhyX3dDX3egwZtB8PqLnjz3yedt8R5StBrzcg4aBpnh8UA9D1BoQ==", - "dev": true, - "peer": true, - "dependencies": { - "@jridgewell/set-array": "^1.0.1", - "@jridgewell/sourcemap-codec": "^1.4.10", - "@jridgewell/trace-mapping": "^0.3.9" - }, - "engines": { - "node": ">=6.0.0" - } - }, - "node_modules/@jridgewell/resolve-uri": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.0.tgz", - "integrity": "sha512-F2msla3tad+Mfht5cJq7LSXcdudKTWCVYUgw6pLFOOHSTtZlj6SWNYAp+AhuqLmWdBO2X5hPrLcu8cVP8fy28w==", - "dev": true, - "engines": { - "node": ">=6.0.0" - } - }, - "node_modules/@jridgewell/set-array": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@jridgewell/set-array/-/set-array-1.1.2.tgz", - "integrity": "sha512-xnkseuNADM0gt2bs+BvhO0p78Mk762YnZdsuzFV018NoG1Sj1SCQvpSqa7XUaTam5vAGasABV9qXASMKnFMwMw==", - "dev": true, - "peer": true, - "engines": { - "node": ">=6.0.0" - } - }, - "node_modules/@jridgewell/source-map": { - "version": "0.3.5", - "resolved": "https://registry.npmjs.org/@jridgewell/source-map/-/source-map-0.3.5.tgz", - "integrity": "sha512-UTYAUj/wviwdsMfzoSJspJxbkH5o1snzwX0//0ENX1u/55kkZZkcTZP6u9bwKGkv+dkk9at4m1Cpt0uY80kcpQ==", - "dev": true, - "peer": true, - "dependencies": { - "@jridgewell/gen-mapping": "^0.3.0", - "@jridgewell/trace-mapping": "^0.3.9" - } - }, - "node_modules/@jridgewell/sourcemap-codec": { - "version": "1.4.14", - "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.14.tgz", - "integrity": "sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw==", - "dev": true - }, - "node_modules/@jridgewell/trace-mapping": { - "version": "0.3.18", - "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.18.tgz", - "integrity": "sha512-w+niJYzMHdd7USdiH2U6869nqhD2nbfZXND5Yp93qIbEmnDNk7PD48o+YchRVpzMU7M6jVCbenTR7PA1FLQ9pA==", - "dev": true, - "dependencies": { - "@jridgewell/resolve-uri": "3.1.0", - "@jridgewell/sourcemap-codec": "1.4.14" - } - }, - "node_modules/@js-temporal/polyfill": { - "version": "0.4.4", - "resolved": "https://registry.npmjs.org/@js-temporal/polyfill/-/polyfill-0.4.4.tgz", - "integrity": "sha512-2X6bvghJ/JAoZO52lbgyAPFj8uCflhTo2g7nkFzEQdXd/D8rEeD4HtmTEpmtGCva260fcd66YNXBOYdnmHqSOg==", - "dependencies": { - "jsbi": "^4.3.0", - "tslib": "^2.4.1" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/@multiformats/base-x": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/@multiformats/base-x/-/base-x-4.0.1.tgz", - "integrity": "sha512-eMk0b9ReBbV23xXU693TAIrLyeO5iTgBZGSJfpqriG8UkYvr/hC9u9pyMlAakDNHWmbhMZCDs6KQO0jzKD8OTw==" - }, - "node_modules/@multiformats/murmur3": { - "version": "2.1.5", - "resolved": "https://registry.npmjs.org/@multiformats/murmur3/-/murmur3-2.1.5.tgz", - "integrity": "sha512-etjrdN/gJ1PhIg3vv+4QypYgXsqBQCfTFEMzSclz3t1YwLSnd9i8R1nL50CIznUraVlsKzbcH/xCB9dC0XbFow==", - "dependencies": { - "multiformats": "^12.0.1", - "murmurhash3js-revisited": "^3.0.0" - }, - "engines": { - "node": ">=16.0.0", - "npm": ">=7.0.0" - } - }, - "node_modules/@multiformats/murmur3/node_modules/multiformats": { - "version": "12.0.1", - "resolved": "https://registry.npmjs.org/multiformats/-/multiformats-12.0.1.tgz", - "integrity": "sha512-s01wijBJoDUqESWSzePY0lvTw7J3PVO9x2Cc6ASI5AMZM2Gnhh7BC17+nlFhHKU7dDzaCaRfb+NiqNzOsgPUoQ==", - "engines": { - "node": ">=16.0.0", - "npm": ">=7.0.0" - } - }, - "node_modules/@noble/ciphers": { - "version": "0.1.3", - "resolved": "https://registry.npmjs.org/@noble/ciphers/-/ciphers-0.1.3.tgz", - "integrity": "sha512-L75KBG/jf6YNxSvV0w0tsC8OIOsLh9sk6mqLUNZ+3/UhDBrAHQAvTTspwMoBlB84ymupIhq+E9QOhr6H1g/xog==", - "funding": { - "url": "https://paulmillr.com/funding/" - } - }, - "node_modules/@noble/curves": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/@noble/curves/-/curves-1.1.0.tgz", - "integrity": "sha512-091oBExgENk/kGj3AZmtBDMpxQPDtxQABR2B9lb1JbVTs6ytdzZNwvhxQ4MWasRNEzlbEH8jCWFCwhF/Obj5AA==", - "dependencies": { - "@noble/hashes": "1.3.1" - }, - "funding": { - "url": "https://paulmillr.com/funding/" - } - }, - "node_modules/@noble/ed25519": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@noble/ed25519/-/ed25519-2.0.0.tgz", - "integrity": "sha512-/extjhkwFupyopDrt80OMWKdLgP429qLZj+z6sYJz90rF2Iz0gjZh2ArMKPImUl13Kx+0EXI2hN9T/KJV0/Zng==", - "funding": [ - { - "type": "individual", - "url": "https://paulmillr.com/funding/" - } - ] - }, - "node_modules/@noble/hashes": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.1.tgz", - "integrity": "sha512-EbqwksQwz9xDRGfDST86whPBgM65E0OH/pCgqW0GBVzO22bNE+NuIbeTb714+IfSjU3aRk47EUvXIb5bTsenKA==", - "engines": { - "node": ">= 16" - }, - "funding": { - "url": "https://paulmillr.com/funding/" - } - }, - "node_modules/@noble/secp256k1": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@noble/secp256k1/-/secp256k1-2.0.0.tgz", - "integrity": "sha512-rUGBd95e2a45rlmFTqQJYEFA4/gdIARFfuTuTqLglz0PZ6AKyzyXsEZZq7UZn8hZsvaBgpCzKKBJizT2cJERXw==", - "funding": [ - { - "type": "individual", - "url": "https://paulmillr.com/funding/" - } - ] - }, - "node_modules/@nodelib/fs.scandir": { - "version": "2.1.5", - "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", - "integrity": "sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==", - "dev": true, - "dependencies": { - "@nodelib/fs.stat": "2.0.5", - "run-parallel": "^1.1.9" - }, - "engines": { - "node": ">= 8" - } - }, - "node_modules/@nodelib/fs.stat": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/@nodelib/fs.stat/-/fs.stat-2.0.5.tgz", - "integrity": "sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A==", - "dev": true, - "engines": { - "node": ">= 8" - } - }, - "node_modules/@nodelib/fs.walk": { - "version": "1.2.8", - "resolved": "https://registry.npmjs.org/@nodelib/fs.walk/-/fs.walk-1.2.8.tgz", - "integrity": "sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==", - "dev": true, - "dependencies": { - "@nodelib/fs.scandir": "2.1.5", - "fastq": "^1.6.0" - }, - "engines": { - "node": ">= 8" - } - }, - "node_modules/@protobufjs/aspromise": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@protobufjs/aspromise/-/aspromise-1.1.2.tgz", - "integrity": "sha512-j+gKExEuLmKwvz3OgROXtrJ2UG2x8Ch2YZUxahh+s1F2HZ+wAceUNLkvy6zKCPVRkU++ZWQrdxsUeQXmcg4uoQ==" - }, - "node_modules/@protobufjs/base64": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@protobufjs/base64/-/base64-1.1.2.tgz", - "integrity": "sha512-AZkcAA5vnN/v4PDqKyMR5lx7hZttPDgClv83E//FMNhR2TMcLUhfRUBHCmSl0oi9zMgDDqRUJkSxO3wm85+XLg==" - }, - "node_modules/@protobufjs/codegen": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/@protobufjs/codegen/-/codegen-2.0.4.tgz", - "integrity": "sha512-YyFaikqM5sH0ziFZCN3xDC7zeGaB/d0IUb9CATugHWbd1FRFwWwt4ld4OYMPWu5a3Xe01mGAULCdqhMlPl29Jg==" - }, - "node_modules/@protobufjs/eventemitter": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/@protobufjs/eventemitter/-/eventemitter-1.1.0.tgz", - "integrity": "sha512-j9ednRT81vYJ9OfVuXG6ERSTdEL1xVsNgqpkxMsbIabzSo3goCjDIveeGv5d03om39ML71RdmrGNjG5SReBP/Q==" - }, - "node_modules/@protobufjs/fetch": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/@protobufjs/fetch/-/fetch-1.1.0.tgz", - "integrity": "sha512-lljVXpqXebpsijW71PZaCYeIcE5on1w5DlQy5WH6GLbFryLUrBD4932W/E2BSpfRJWseIL4v/KPgBFxDOIdKpQ==", - "dependencies": { - "@protobufjs/aspromise": "^1.1.1", - "@protobufjs/inquire": "^1.1.0" - } - }, - "node_modules/@protobufjs/float": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/@protobufjs/float/-/float-1.0.2.tgz", - "integrity": "sha512-Ddb+kVXlXst9d+R9PfTIxh1EdNkgoRe5tOX6t01f1lYWOvJnSPDBlG241QLzcyPdoNTsblLUdujGSE4RzrTZGQ==" - }, - "node_modules/@protobufjs/inquire": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/@protobufjs/inquire/-/inquire-1.1.0.tgz", - "integrity": "sha512-kdSefcPdruJiFMVSbn801t4vFK7KB/5gd2fYvrxhuJYg8ILrmn9SKSX2tZdV6V+ksulWqS7aXjBcRXl3wHoD9Q==" - }, - "node_modules/@protobufjs/path": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@protobufjs/path/-/path-1.1.2.tgz", - "integrity": "sha512-6JOcJ5Tm08dOHAbdR3GrvP+yUUfkjG5ePsHYczMFLq3ZmMkAD98cDgcT2iA1lJ9NVwFd4tH/iSSoe44YWkltEA==" - }, - "node_modules/@protobufjs/pool": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/@protobufjs/pool/-/pool-1.1.0.tgz", - "integrity": "sha512-0kELaGSIDBKvcgS4zkjz1PeddatrjYcmMWOlAuAPwAeccUrPHdUqo/J6LiymHHEiJT5NrF1UVwxY14f+fy4WQw==" - }, - "node_modules/@protobufjs/utf8": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/@protobufjs/utf8/-/utf8-1.1.0.tgz", - "integrity": "sha512-Vvn3zZrhQZkkBE8LSuW3em98c0FwgO4nxzv6OdSxPKJIEKY2bGbHn+mhGIPerzI4twdxaP8/0+06HBpwf345Lw==" - }, - "node_modules/@sinonjs/commons": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-3.0.0.tgz", - "integrity": "sha512-jXBtWAF4vmdNmZgD5FoKsVLv3rPgDnLgPbU84LIJ3otV44vJlDRokVng5v8NFJdCf/da9legHcKaRuZs4L7faA==", - "dev": true, - "dependencies": { - "type-detect": "4.0.8" - } - }, - "node_modules/@sinonjs/fake-timers": { - "version": "10.3.0", - "resolved": "https://registry.npmjs.org/@sinonjs/fake-timers/-/fake-timers-10.3.0.tgz", - "integrity": "sha512-V4BG07kuYSUkTCSBHG8G8TNhM+F19jXFWnQtzj+we8DrkpSBCee9Z3Ms8yiGer/dlmhe35/Xdgyo3/0rQKg7YA==", - "dev": true, - "dependencies": { - "@sinonjs/commons": "^3.0.0" - } - }, - "node_modules/@sinonjs/samsam": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-7.0.1.tgz", - "integrity": "sha512-zsAk2Jkiq89mhZovB2LLOdTCxJF4hqqTToGP0ASWlhp4I1hqOjcfmZGafXntCN7MDC6yySH0mFHrYtHceOeLmw==", - "dev": true, - "dependencies": { - "@sinonjs/commons": "^2.0.0", - "lodash.get": "^4.4.2", - "type-detect": "^4.0.8" - } - }, - "node_modules/@sinonjs/samsam/node_modules/@sinonjs/commons": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-2.0.0.tgz", - "integrity": "sha512-uLa0j859mMrg2slwQYdO/AkrOfmH+X6LTVmNTS9CqexuE2IvVORIkSpJLqePAbEnKJ77aMmCwr1NUZ57120Xcg==", - "dev": true, - "dependencies": { - "type-detect": "4.0.8" - } - }, - "node_modules/@sinonjs/text-encoding": { - "version": "0.7.2", - "resolved": "https://registry.npmjs.org/@sinonjs/text-encoding/-/text-encoding-0.7.2.tgz", - "integrity": "sha512-sXXKG+uL9IrKqViTtao2Ws6dy0znu9sOaP1di/jKGW1M6VssO8vlpXCQcpZ+jisQ1tTFAC5Jo/EOzFbggBagFQ==", - "dev": true - }, - "node_modules/@socket.io/component-emitter": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/@socket.io/component-emitter/-/component-emitter-3.1.0.tgz", - "integrity": "sha512-+9jVqKhRSpsc591z5vX+X5Yyw+he/HCB4iQ/RYxw35CEPaY1gnsNE43nf9n9AaYjAQrTiI/mOwKUKdUs9vf7Xg==", - "dev": true - }, - "node_modules/@tbd54566975/common": { - "resolved": "packages/common", - "link": true - }, - "node_modules/@tbd54566975/credentials": { - "resolved": "packages/credentials", - "link": true - }, - "node_modules/@tbd54566975/crypto": { - "resolved": "packages/crypto", - "link": true - }, - "node_modules/@tbd54566975/dids": { - "resolved": "packages/dids", - "link": true - }, - "node_modules/@tbd54566975/dwn-sdk-js": { - "version": "0.2.1", - "resolved": "https://registry.npmjs.org/@tbd54566975/dwn-sdk-js/-/dwn-sdk-js-0.2.1.tgz", - "integrity": "sha512-7rFi0zvpt0F/6E2Pow5+iCnf35YGIUneI9U4J43A8NfP0Gh5S2eJkApvhrPOyt50Xq2MerFR9F5E3BE2E0jJRQ==", - "dependencies": { - "@ipld/dag-cbor": "9.0.3", - "@js-temporal/polyfill": "0.4.4", - "@noble/ed25519": "2.0.0", - "@noble/secp256k1": "2.0.0", - "abstract-level": "1.0.3", - "ajv": "8.12.0", - "blockstore-core": "4.2.0", - "cross-fetch": "4.0.0", - "eciesjs": "0.4.0", - "flat": "5.0.2", - "interface-blockstore": "5.2.3", - "interface-store": "5.1.2", - "ipfs-unixfs-exporter": "13.1.5", - "ipfs-unixfs-importer": "15.1.5", - "level": "8.0.0", - "lodash": "4.17.21", - "lru-cache": "9.1.2", - "ms": "2.1.3", - "multiformats": "11.0.2", - "randombytes": "2.1.0", - "readable-stream": "4.4.0", - "ulid": "2.3.0", - "uuid": "8.3.2", - "varint": "6.0.0" - }, - "engines": { - "node": ">= 18" - } - }, - "node_modules/@tbd54566975/dwn-sdk-js/node_modules/uuid": { - "version": "8.3.2", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", - "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", - "bin": { - "uuid": "dist/bin/uuid" - } - }, - "node_modules/@tbd54566975/web5": { - "resolved": "packages/web5", - "link": true - }, - "node_modules/@tbd54566975/web5-agent": { - "resolved": "packages/web5-agent", - "link": true - }, - "node_modules/@tbd54566975/web5-proxy-agent": { - "resolved": "packages/web5-proxy-agent", - "link": true - }, - "node_modules/@tbd54566975/web5-user-agent": { - "resolved": "packages/web5-user-agent", - "link": true - }, - "node_modules/@types/chai": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.3.0.tgz", - "integrity": "sha512-/ceqdqeRraGolFTcfoXNiqjyQhZzbINDngeoAq9GoHa8PPK1yNzTaxWjA6BFWp5Ua9JpXEMSS4s5i9tS0hOJtw==", - "dev": true - }, - "node_modules/@types/chai-as-promised": { - "version": "7.1.5", - "resolved": "https://registry.npmjs.org/@types/chai-as-promised/-/chai-as-promised-7.1.5.tgz", - "integrity": "sha512-jStwss93SITGBwt/niYrkf2C+/1KTeZCZl1LaeezTlqppAKeoQC7jxyqYuP72sxBGKCIbw7oHgbYssIRzT5FCQ==", - "dev": true, - "dependencies": { - "@types/chai": "*" - } - }, - "node_modules/@types/cookie": { - "version": "0.4.1", - "resolved": "https://registry.npmjs.org/@types/cookie/-/cookie-0.4.1.tgz", - "integrity": "sha512-XW/Aa8APYr6jSVVA1y/DEIZX0/GMKLEVekNG727R8cs56ahETkRAy/3DR7+fJyh7oUgGwNQaRfXCun0+KbWY7Q==", - "dev": true - }, - "node_modules/@types/cors": { - "version": "2.8.13", - "resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.13.tgz", - "integrity": "sha512-RG8AStHlUiV5ysZQKq97copd2UmVYw3/pRMLefISZ3S1hK104Cwm7iLQ3fTKx+lsUH2CE8FlLaYeEA2LSeqYUA==", - "dev": true, - "dependencies": { - "@types/node": "*" - } - }, - "node_modules/@types/ed2curve": { - "version": "0.2.2", - "resolved": "https://registry.npmjs.org/@types/ed2curve/-/ed2curve-0.2.2.tgz", - "integrity": "sha512-G1sTX5xo91ydevQPINbL2nfgVAj/s1ZiqZxC8OCWduwu+edoNGUm5JXtTkg9F3LsBZbRI46/0HES4CPUE2wc9g==", - "dev": true, - "dependencies": { - "tweetnacl": "^1.0.0" - } - }, - "node_modules/@types/eslint": { - "version": "8.37.0", - "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-8.37.0.tgz", - "integrity": "sha512-Piet7dG2JBuDIfohBngQ3rCt7MgO9xCO4xIMKxBThCq5PNRB91IjlJ10eJVwfoNtvTErmxLzwBZ7rHZtbOMmFQ==", - "dev": true, - "dependencies": { - "@types/estree": "*", - "@types/json-schema": "*" - } - }, - "node_modules/@types/eslint-scope": { - "version": "3.7.4", - "resolved": "https://registry.npmjs.org/@types/eslint-scope/-/eslint-scope-3.7.4.tgz", - "integrity": "sha512-9K4zoImiZc3HlIp6AVUDE4CWYx22a+lhSZMYNpbjW04+YF0KWj4pJXnEMjdnFTiQibFFmElcsasJXDbdI/EPhA==", - "dev": true, - "peer": true, - "dependencies": { - "@types/eslint": "*", - "@types/estree": "*" - } - }, - "node_modules/@types/estree": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.1.tgz", - "integrity": "sha512-LG4opVs2ANWZ1TJoKc937iMmNstM/d0ae1vNbnBvBhqCSezgVUOzcLCqbI5elV8Vy6WKwKjaqR+zO9VKirBBCA==", - "dev": true - }, - "node_modules/@types/flat": { - "version": "5.0.2", - "resolved": "https://registry.npmjs.org/@types/flat/-/flat-5.0.2.tgz", - "integrity": "sha512-3zsplnP2djeps5P9OyarTxwRpMLoe5Ash8aL9iprw0JxB+FAHjY+ifn4yZUuW4/9hqtnmor6uvjSRzJhiVbrEQ==", - "dev": true - }, - "node_modules/@types/istanbul-lib-coverage": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.4.tgz", - "integrity": "sha512-z/QT1XN4K4KYuslS23k62yDIDLwLFkzxOuMplDtObz0+y7VqJCaO2o+SPwHCvLFZh7xazvvoor2tA/hPz9ee7g==", - "dev": true - }, - "node_modules/@types/json-schema": { - "version": "7.0.12", - "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.12.tgz", - "integrity": "sha512-Hr5Jfhc9eYOQNPYO5WLDq/n4jqijdHNlDXjuAQkkt+mWdQR+XJToOHrsD4cPaMXpn6KO7y2+wM8AZEs8VpBLVA==", - "dev": true - }, - "node_modules/@types/mocha": { - "version": "10.0.1", - "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-10.0.1.tgz", - "integrity": "sha512-/fvYntiO1GeICvqbQ3doGDIP97vWmvFt83GKguJ6prmQM2iXZfFcq6YE8KteFyRtX2/h5Hf91BYvPodJKFYv5Q==", - "dev": true - }, - "node_modules/@types/ms": { - "version": "0.7.31", - "resolved": "https://registry.npmjs.org/@types/ms/-/ms-0.7.31.tgz", - "integrity": "sha512-iiUgKzV9AuaEkZqkOLDIvlQiL6ltuZd9tGcW3gwpnX8JbuiuhFlEGmmFXEXkN50Cvq7Os88IY2v0dkDqXYWVgA==", - "dev": true - }, - "node_modules/@types/node": { - "version": "20.4.7", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.4.7.tgz", - "integrity": "sha512-bUBrPjEry2QUTsnuEjzjbS7voGWCc30W0qzgMf90GPeDGFRakvrz47ju+oqDAKCXLUCe39u57/ORMl/O/04/9g==" - }, - "node_modules/@types/readable-stream": { - "version": "2.3.15", - "resolved": "https://registry.npmjs.org/@types/readable-stream/-/readable-stream-2.3.15.tgz", - "integrity": "sha512-oM5JSKQCcICF1wvGgmecmHldZ48OZamtMxcGGVICOJA8o8cahXC1zEVAif8iwoc5j8etxFaRFnf095+CDsuoFQ==", - "dev": true, - "dependencies": { - "@types/node": "*", - "safe-buffer": "~5.1.1" - } - }, - "node_modules/@types/semver": { - "version": "7.5.0", - "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.5.0.tgz", - "integrity": "sha512-G8hZ6XJiHnuhQKR7ZmysCeJWE08o8T0AXtk5darsCaTVsYZhhgUrq53jizaR2FvsoeCwJhlmwTjkXBY5Pn/ZHw==", - "dev": true - }, - "node_modules/@types/sinon": { - "version": "10.0.15", - "resolved": "https://registry.npmjs.org/@types/sinon/-/sinon-10.0.15.tgz", - "integrity": "sha512-3lrFNQG0Kr2LDzvjyjB6AMJk4ge+8iYhQfdnSwIwlG88FUOV43kPcQqDZkDa/h3WSZy6i8Fr0BSjfQtB1B3xuQ==", - "dev": true, - "dependencies": { - "@types/sinonjs__fake-timers": "*" - } - }, - "node_modules/@types/sinonjs__fake-timers": { - "version": "8.1.2", - "resolved": "https://registry.npmjs.org/@types/sinonjs__fake-timers/-/sinonjs__fake-timers-8.1.2.tgz", - "integrity": "sha512-9GcLXF0/v3t80caGs5p2rRfkB+a8VBGLJZVih6CNFkx8IZ994wiKKLSRs9nuFwk1HevWs/1mnUmkApGrSGsShA==", - "dev": true - }, - "node_modules/@types/uuid": { - "version": "9.0.1", - "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-9.0.1.tgz", - "integrity": "sha512-rFT3ak0/2trgvp4yYZo5iKFEPsET7vKydKF+VRCxlQ9bpheehyAJH89dAkaLEq/j/RZXJIqcgsmPJKUP1Z28HA==", - "dev": true - }, - "node_modules/@typescript-eslint/eslint-plugin": { - "version": "5.59.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.59.0.tgz", - "integrity": "sha512-p0QgrEyrxAWBecR56gyn3wkG15TJdI//eetInP3zYRewDh0XS+DhB3VUAd3QqvziFsfaQIoIuZMxZRB7vXYaYw==", - "dev": true, - "dependencies": { - "@eslint-community/regexpp": "^4.4.0", - "@typescript-eslint/scope-manager": "5.59.0", - "@typescript-eslint/type-utils": "5.59.0", - "@typescript-eslint/utils": "5.59.0", - "debug": "^4.3.4", - "grapheme-splitter": "^1.0.4", - "ignore": "^5.2.0", - "natural-compare-lite": "^1.4.0", - "semver": "^7.3.7", - "tsutils": "^3.21.0" - }, - "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - }, - "peerDependencies": { - "@typescript-eslint/parser": "^5.0.0", - "eslint": "^6.0.0 || ^7.0.0 || ^8.0.0" - }, - "peerDependenciesMeta": { - "typescript": { - "optional": true - } - } - }, - "node_modules/@typescript-eslint/parser": { - "version": "5.59.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.59.0.tgz", - "integrity": "sha512-qK9TZ70eJtjojSUMrrEwA9ZDQ4N0e/AuoOIgXuNBorXYcBDk397D2r5MIe1B3cok/oCtdNC5j+lUUpVB+Dpb+w==", - "dev": true, - "dependencies": { - "@typescript-eslint/scope-manager": "5.59.0", - "@typescript-eslint/types": "5.59.0", - "@typescript-eslint/typescript-estree": "5.59.0", - "debug": "^4.3.4" - }, - "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - }, - "peerDependencies": { - "eslint": "^6.0.0 || ^7.0.0 || ^8.0.0" - }, - "peerDependenciesMeta": { - "typescript": { - "optional": true - } - } - }, - "node_modules/@typescript-eslint/scope-manager": { - "version": "5.59.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.59.0.tgz", - "integrity": "sha512-tsoldKaMh7izN6BvkK6zRMINj4Z2d6gGhO2UsI8zGZY3XhLq1DndP3Ycjhi1JwdwPRwtLMW4EFPgpuKhbCGOvQ==", - "dev": true, - "dependencies": { - "@typescript-eslint/types": "5.59.0", - "@typescript-eslint/visitor-keys": "5.59.0" - }, - "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - } - }, - "node_modules/@typescript-eslint/type-utils": { - "version": "5.59.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-5.59.0.tgz", - "integrity": "sha512-d/B6VSWnZwu70kcKQSCqjcXpVH+7ABKH8P1KNn4K7j5PXXuycZTPXF44Nui0TEm6rbWGi8kc78xRgOC4n7xFgA==", - "dev": true, - "dependencies": { - "@typescript-eslint/typescript-estree": "5.59.0", - "@typescript-eslint/utils": "5.59.0", - "debug": "^4.3.4", - "tsutils": "^3.21.0" - }, - "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - }, - "peerDependencies": { - "eslint": "*" - }, - "peerDependenciesMeta": { - "typescript": { - "optional": true - } - } - }, - "node_modules/@typescript-eslint/types": { - "version": "5.59.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.59.0.tgz", - "integrity": "sha512-yR2h1NotF23xFFYKHZs17QJnB51J/s+ud4PYU4MqdZbzeNxpgUr05+dNeCN/bb6raslHvGdd6BFCkVhpPk/ZeA==", - "dev": true, - "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - } - }, - "node_modules/@typescript-eslint/typescript-estree": { - "version": "5.59.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.59.0.tgz", - "integrity": "sha512-sUNnktjmI8DyGzPdZ8dRwW741zopGxltGs/SAPgGL/AAgDpiLsCFLcMNSpbfXfmnNeHmK9h3wGmCkGRGAoUZAg==", - "dev": true, - "dependencies": { - "@typescript-eslint/types": "5.59.0", - "@typescript-eslint/visitor-keys": "5.59.0", - "debug": "^4.3.4", - "globby": "^11.1.0", - "is-glob": "^4.0.3", - "semver": "^7.3.7", - "tsutils": "^3.21.0" - }, - "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - }, - "peerDependenciesMeta": { - "typescript": { - "optional": true - } - } - }, - "node_modules/@typescript-eslint/utils": { - "version": "5.59.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.59.0.tgz", - "integrity": "sha512-GGLFd+86drlHSvPgN/el6dRQNYYGOvRSDVydsUaQluwIW3HvbXuxyuD5JETvBt/9qGYe+lOrDk6gRrWOHb/FvA==", - "dev": true, - "dependencies": { - "@eslint-community/eslint-utils": "^4.2.0", - "@types/json-schema": "^7.0.9", - "@types/semver": "^7.3.12", - "@typescript-eslint/scope-manager": "5.59.0", - "@typescript-eslint/types": "5.59.0", - "@typescript-eslint/typescript-estree": "5.59.0", - "eslint-scope": "^5.1.1", - "semver": "^7.3.7" - }, - "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - }, - "peerDependencies": { - "eslint": "^6.0.0 || ^7.0.0 || ^8.0.0" - } - }, - "node_modules/@typescript-eslint/visitor-keys": { - "version": "5.59.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.59.0.tgz", - "integrity": "sha512-qZ3iXxQhanchCeaExlKPV3gDQFxMUmU35xfd5eCXB6+kUw1TUAbIy2n7QIrwz9s98DQLzNWyHp61fY0da4ZcbA==", - "dev": true, - "dependencies": { - "@typescript-eslint/types": "5.59.0", - "eslint-visitor-keys": "^3.3.0" - }, - "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - } - }, - "node_modules/@webassemblyjs/ast": { - "version": "1.11.6", - "resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.11.6.tgz", - "integrity": "sha512-IN1xI7PwOvLPgjcf180gC1bqn3q/QaOCwYUahIOhbYUu8KA/3tw2RT/T0Gidi1l7Hhj5D/INhJxiICObqpMu4Q==", - "dev": true, - "peer": true, - "dependencies": { - "@webassemblyjs/helper-numbers": "1.11.6", - "@webassemblyjs/helper-wasm-bytecode": "1.11.6" - } - }, - "node_modules/@webassemblyjs/floating-point-hex-parser": { - "version": "1.11.6", - "resolved": "https://registry.npmjs.org/@webassemblyjs/floating-point-hex-parser/-/floating-point-hex-parser-1.11.6.tgz", - "integrity": "sha512-ejAj9hfRJ2XMsNHk/v6Fu2dGS+i4UaXBXGemOfQ/JfQ6mdQg/WXtwleQRLLS4OvfDhv8rYnVwH27YJLMyYsxhw==", - "dev": true, - "peer": true - }, - "node_modules/@webassemblyjs/helper-api-error": { - "version": "1.11.6", - "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-api-error/-/helper-api-error-1.11.6.tgz", - "integrity": "sha512-o0YkoP4pVu4rN8aTJgAyj9hC2Sv5UlkzCHhxqWj8butaLvnpdc2jOwh4ewE6CX0txSfLn/UYaV/pheS2Txg//Q==", - "dev": true, - "peer": true - }, - "node_modules/@webassemblyjs/helper-buffer": { - "version": "1.11.6", - "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-buffer/-/helper-buffer-1.11.6.tgz", - "integrity": "sha512-z3nFzdcp1mb8nEOFFk8DrYLpHvhKC3grJD2ardfKOzmbmJvEf/tPIqCY+sNcwZIY8ZD7IkB2l7/pqhUhqm7hLA==", - "dev": true, - "peer": true - }, - "node_modules/@webassemblyjs/helper-numbers": { - "version": "1.11.6", - "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-numbers/-/helper-numbers-1.11.6.tgz", - "integrity": "sha512-vUIhZ8LZoIWHBohiEObxVm6hwP034jwmc9kuq5GdHZH0wiLVLIPcMCdpJzG4C11cHoQ25TFIQj9kaVADVX7N3g==", - "dev": true, - "peer": true, - "dependencies": { - "@webassemblyjs/floating-point-hex-parser": "1.11.6", - "@webassemblyjs/helper-api-error": "1.11.6", - "@xtuc/long": "4.2.2" - } - }, - "node_modules/@webassemblyjs/helper-wasm-bytecode": { - "version": "1.11.6", - "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-wasm-bytecode/-/helper-wasm-bytecode-1.11.6.tgz", - "integrity": "sha512-sFFHKwcmBprO9e7Icf0+gddyWYDViL8bpPjJJl0WHxCdETktXdmtWLGVzoHbqUcY4Be1LkNfwTmXOJUFZYSJdA==", - "dev": true, - "peer": true - }, - "node_modules/@webassemblyjs/helper-wasm-section": { - "version": "1.11.6", - "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-wasm-section/-/helper-wasm-section-1.11.6.tgz", - "integrity": "sha512-LPpZbSOwTpEC2cgn4hTydySy1Ke+XEu+ETXuoyvuyezHO3Kjdu90KK95Sh9xTbmjrCsUwvWwCOQQNta37VrS9g==", - "dev": true, - "peer": true, - "dependencies": { - "@webassemblyjs/ast": "1.11.6", - "@webassemblyjs/helper-buffer": "1.11.6", - "@webassemblyjs/helper-wasm-bytecode": "1.11.6", - "@webassemblyjs/wasm-gen": "1.11.6" - } - }, - "node_modules/@webassemblyjs/ieee754": { - "version": "1.11.6", - "resolved": "https://registry.npmjs.org/@webassemblyjs/ieee754/-/ieee754-1.11.6.tgz", - "integrity": "sha512-LM4p2csPNvbij6U1f19v6WR56QZ8JcHg3QIJTlSwzFcmx6WSORicYj6I63f9yU1kEUtrpG+kjkiIAkevHpDXrg==", - "dev": true, - "peer": true, - "dependencies": { - "@xtuc/ieee754": "^1.2.0" - } - }, - "node_modules/@webassemblyjs/leb128": { - "version": "1.11.6", - "resolved": "https://registry.npmjs.org/@webassemblyjs/leb128/-/leb128-1.11.6.tgz", - "integrity": "sha512-m7a0FhE67DQXgouf1tbN5XQcdWoNgaAuoULHIfGFIEVKA6tu/edls6XnIlkmS6FrXAquJRPni3ZZKjw6FSPjPQ==", - "dev": true, - "peer": true, - "dependencies": { - "@xtuc/long": "4.2.2" - } - }, - "node_modules/@webassemblyjs/utf8": { - "version": "1.11.6", - "resolved": "https://registry.npmjs.org/@webassemblyjs/utf8/-/utf8-1.11.6.tgz", - "integrity": "sha512-vtXf2wTQ3+up9Zsg8sa2yWiQpzSsMyXj0qViVP6xKGCUT8p8YJ6HqI7l5eCnWx1T/FYdsv07HQs2wTFbbof/RA==", - "dev": true, - "peer": true - }, - "node_modules/@webassemblyjs/wasm-edit": { - "version": "1.11.6", - "resolved": "https://registry.npmjs.org/@webassemblyjs/wasm-edit/-/wasm-edit-1.11.6.tgz", - "integrity": "sha512-Ybn2I6fnfIGuCR+Faaz7YcvtBKxvoLV3Lebn1tM4o/IAJzmi9AWYIPWpyBfU8cC+JxAO57bk4+zdsTjJR+VTOw==", - "dev": true, - "peer": true, - "dependencies": { - "@webassemblyjs/ast": "1.11.6", - "@webassemblyjs/helper-buffer": "1.11.6", - "@webassemblyjs/helper-wasm-bytecode": "1.11.6", - "@webassemblyjs/helper-wasm-section": "1.11.6", - "@webassemblyjs/wasm-gen": "1.11.6", - "@webassemblyjs/wasm-opt": "1.11.6", - "@webassemblyjs/wasm-parser": "1.11.6", - "@webassemblyjs/wast-printer": "1.11.6" - } - }, - "node_modules/@webassemblyjs/wasm-gen": { - "version": "1.11.6", - "resolved": "https://registry.npmjs.org/@webassemblyjs/wasm-gen/-/wasm-gen-1.11.6.tgz", - "integrity": "sha512-3XOqkZP/y6B4F0PBAXvI1/bky7GryoogUtfwExeP/v7Nzwo1QLcq5oQmpKlftZLbT+ERUOAZVQjuNVak6UXjPA==", - "dev": true, - "peer": true, - "dependencies": { - "@webassemblyjs/ast": "1.11.6", - "@webassemblyjs/helper-wasm-bytecode": "1.11.6", - "@webassemblyjs/ieee754": "1.11.6", - "@webassemblyjs/leb128": "1.11.6", - "@webassemblyjs/utf8": "1.11.6" - } - }, - "node_modules/@webassemblyjs/wasm-opt": { - "version": "1.11.6", - "resolved": "https://registry.npmjs.org/@webassemblyjs/wasm-opt/-/wasm-opt-1.11.6.tgz", - "integrity": "sha512-cOrKuLRE7PCe6AsOVl7WasYf3wbSo4CeOk6PkrjS7g57MFfVUF9u6ysQBBODX0LdgSvQqRiGz3CXvIDKcPNy4g==", - "dev": true, - "peer": true, - "dependencies": { - "@webassemblyjs/ast": "1.11.6", - "@webassemblyjs/helper-buffer": "1.11.6", - "@webassemblyjs/wasm-gen": "1.11.6", - "@webassemblyjs/wasm-parser": "1.11.6" - } - }, - "node_modules/@webassemblyjs/wasm-parser": { - "version": "1.11.6", - "resolved": "https://registry.npmjs.org/@webassemblyjs/wasm-parser/-/wasm-parser-1.11.6.tgz", - "integrity": "sha512-6ZwPeGzMJM3Dqp3hCsLgESxBGtT/OeCvCZ4TA1JUPYgmhAx38tTPR9JaKy0S5H3evQpO/h2uWs2j6Yc/fjkpTQ==", - "dev": true, - "peer": true, - "dependencies": { - "@webassemblyjs/ast": "1.11.6", - "@webassemblyjs/helper-api-error": "1.11.6", - "@webassemblyjs/helper-wasm-bytecode": "1.11.6", - "@webassemblyjs/ieee754": "1.11.6", - "@webassemblyjs/leb128": "1.11.6", - "@webassemblyjs/utf8": "1.11.6" - } - }, - "node_modules/@webassemblyjs/wast-printer": { - "version": "1.11.6", - "resolved": "https://registry.npmjs.org/@webassemblyjs/wast-printer/-/wast-printer-1.11.6.tgz", - "integrity": "sha512-JM7AhRcE+yW2GWYaKeHL5vt4xqee5N2WcezptmgyhNS+ScggqcT1OtXykhAb13Sn5Yas0j2uv9tHgrjwvzAP4A==", - "dev": true, - "peer": true, - "dependencies": { - "@webassemblyjs/ast": "1.11.6", - "@xtuc/long": "4.2.2" - } - }, - "node_modules/@xtuc/ieee754": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/@xtuc/ieee754/-/ieee754-1.2.0.tgz", - "integrity": "sha512-DX8nKgqcGwsc0eJSqYt5lwP4DH5FlHnmuWWBRy7X0NcaGR0ZtuyeESgMwTYVEtxmsNGY+qit4QYT/MIYTOTPeA==", - "dev": true, - "peer": true - }, - "node_modules/@xtuc/long": { - "version": "4.2.2", - "resolved": "https://registry.npmjs.org/@xtuc/long/-/long-4.2.2.tgz", - "integrity": "sha512-NuHqBY1PB/D8xU6s/thBgOAiAP7HOYDQ32+BFZILJ8ivkUkAHQnWfn6WhL79Owj1qmUnoN/YPhktdIoucipkAQ==", - "dev": true, - "peer": true - }, - "node_modules/abab": { - "version": "2.0.6", - "resolved": "https://registry.npmjs.org/abab/-/abab-2.0.6.tgz", - "integrity": "sha512-j2afSsaIENvHZN2B8GOpF566vZ5WVk5opAiMTvWgaQT8DkbOqsTfvNAvHoRGU2zzP8cPoqys+xHTRDWW8L+/BA==", - "dev": true - }, - "node_modules/abort-controller": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz", - "integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==", - "dependencies": { - "event-target-shim": "^5.0.0" - }, - "engines": { - "node": ">=6.5" - } - }, - "node_modules/abstract-level": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/abstract-level/-/abstract-level-1.0.3.tgz", - "integrity": "sha512-t6jv+xHy+VYwc4xqZMn2Pa9DjcdzvzZmQGRjTFc8spIbRGHgBrEKbPq+rYXc7CCo0lxgYvSgKVg9qZAhpVQSjA==", - "dependencies": { - "buffer": "^6.0.3", - "catering": "^2.1.0", - "is-buffer": "^2.0.5", - "level-supports": "^4.0.0", - "level-transcoder": "^1.0.1", - "module-error": "^1.0.1", - "queue-microtask": "^1.2.3" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/accepts": { - "version": "1.3.8", - "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", - "integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==", - "dev": true, - "dependencies": { - "mime-types": "~2.1.34", - "negotiator": "0.6.3" - }, - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/acorn": { - "version": "8.10.0", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.10.0.tgz", - "integrity": "sha512-F0SAmZ8iUtS//m8DmCTA0jlh6TDKkHQyK6xc6V4KDTyZKA9dnvX9/3sRTVQrWm79glUAZbnmmNcdYwUIHWVybw==", - "dev": true, - "bin": { - "acorn": "bin/acorn" - }, - "engines": { - "node": ">=0.4.0" - } - }, - "node_modules/acorn-import-assertions": { - "version": "1.9.0", - "resolved": "https://registry.npmjs.org/acorn-import-assertions/-/acorn-import-assertions-1.9.0.tgz", - "integrity": "sha512-cmMwop9x+8KFhxvKrKfPYmN6/pKTYYHBqLa0DfvVZcKMJWNyWLnaqND7dx/qn66R7ewM1UX5XMaDVP5wlVTaVA==", - "dev": true, - "peer": true, - "peerDependencies": { - "acorn": "^8" - } - }, - "node_modules/acorn-jsx": { - "version": "5.3.2", - "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.2.tgz", - "integrity": "sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==", - "dev": true, - "peerDependencies": { - "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" - } - }, - "node_modules/ajv": { - "version": "8.12.0", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.12.0.tgz", - "integrity": "sha512-sRu1kpcO9yLtYxBKvqfTeh9KzZEwO3STyX1HT+4CaDzC6HpTGYhIhPIzj9XuKU7KYDwnaeh5hcOwjy1QuJzBPA==", - "dependencies": { - "fast-deep-equal": "^3.1.1", - "json-schema-traverse": "^1.0.0", - "require-from-string": "^2.0.2", - "uri-js": "^4.2.2" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/epoberezkin" - } - }, - "node_modules/ansi-colors": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.1.tgz", - "integrity": "sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA==", - "dev": true, - "engines": { - "node": ">=6" - } - }, - "node_modules/ansi-regex": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", - "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", - "dev": true, - "engines": { - "node": ">=8" - } - }, - "node_modules/ansi-styles": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", - "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", - "dev": true, - "dependencies": { - "color-convert": "^2.0.1" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/chalk/ansi-styles?sponsor=1" - } - }, - "node_modules/anymatch": { - "version": "3.1.3", - "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz", - "integrity": "sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==", - "dev": true, - "dependencies": { - "normalize-path": "^3.0.0", - "picomatch": "^2.0.4" - }, - "engines": { - "node": ">= 8" - } - }, - "node_modules/argparse": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", - "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", - "dev": true - }, - "node_modules/array-union": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/array-union/-/array-union-2.1.0.tgz", - "integrity": "sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==", - "dev": true, - "engines": { - "node": ">=8" - } - }, - "node_modules/asn1.js": { - "version": "5.4.1", - "resolved": "https://registry.npmjs.org/asn1.js/-/asn1.js-5.4.1.tgz", - "integrity": "sha512-+I//4cYPccV8LdmBLiX8CYvf9Sp3vQsrqu2QNXRcrbiWvcx/UdlFiqUJJzxRQxgsZmvhXhn4cSKeSmoFjVdupA==", - "dev": true, - "dependencies": { - "bn.js": "^4.0.0", - "inherits": "^2.0.1", - "minimalistic-assert": "^1.0.0", - "safer-buffer": "^2.1.0" - } - }, - "node_modules/asn1.js/node_modules/bn.js": { - "version": "4.12.0", - "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.12.0.tgz", - "integrity": "sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA==", - "dev": true - }, - "node_modules/assert": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/assert/-/assert-2.0.0.tgz", - "integrity": "sha512-se5Cd+js9dXJnu6Ag2JFc00t+HmHOen+8Q+L7O9zI0PqQXr20uk2J0XQqMxZEeo5U50o8Nvmmx7dZrl+Ufr35A==", - "dev": true, - "dependencies": { - "es6-object-assign": "^1.1.0", - "is-nan": "^1.2.1", - "object-is": "^1.0.1", - "util": "^0.12.0" - } - }, - "node_modules/assertion-error": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz", - "integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==", - "engines": { - "node": "*" - } - }, - "node_modules/available-typed-arrays": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.5.tgz", - "integrity": "sha512-DMD0KiN46eipeziST1LPP/STfDU0sufISXmjSgvVsoU2tqxctQeASejWcfNtxYKqETM1UxQ8sp2OrSBWpHY6sw==", - "dev": true, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/balanced-match": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", - "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", - "dev": true - }, - "node_modules/base64-js": { - "version": "1.5.1", - "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", - "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ] - }, - "node_modules/base64id": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/base64id/-/base64id-2.0.0.tgz", - "integrity": "sha512-lGe34o6EHj9y3Kts9R4ZYs/Gr+6N7MCaMlIFA3F1R2O5/m7K06AxfSeO5530PEERE6/WyEg3lsuyw4GHlPZHog==", - "dev": true, - "engines": { - "node": "^4.5.0 || >= 5.9" - } - }, - "node_modules/binary-extensions": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz", - "integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==", - "dev": true, - "engines": { - "node": ">=8" - } - }, - "node_modules/bl": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/bl/-/bl-5.1.0.tgz", - "integrity": "sha512-tv1ZJHLfTDnXE6tMHv73YgSJaWR2AFuPwMntBe7XL/GBFHnT0CLnsHMogfk5+GzCDC5ZWarSCYaIGATZt9dNsQ==", - "dependencies": { - "buffer": "^6.0.3", - "inherits": "^2.0.4", - "readable-stream": "^3.4.0" - } - }, - "node_modules/bl/node_modules/readable-stream": { - "version": "3.6.2", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", - "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", - "dependencies": { - "inherits": "^2.0.3", - "string_decoder": "^1.1.1", - "util-deprecate": "^1.0.1" - }, - "engines": { - "node": ">= 6" - } - }, - "node_modules/blockstore-core": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/blockstore-core/-/blockstore-core-4.2.0.tgz", - "integrity": "sha512-F8BCobc75D+9/+hUD+5cixbU6zmZA+lBgNiuBkNlJqRgmAaBBvLOQF6Ad9Jei0Nvmy2a1jaF4CiN76W1apIghA==", - "dependencies": { - "err-code": "^3.0.1", - "interface-blockstore": "^5.0.0", - "interface-store": "^5.0.0", - "multiformats": "^11.0.2" - }, - "engines": { - "node": ">=16.0.0", - "npm": ">=7.0.0" - } - }, - "node_modules/bn.js": { - "version": "5.2.1", - "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-5.2.1.tgz", - "integrity": "sha512-eXRvHzWyYPBuB4NBy0cmYQjGitUrtqwbvlzP3G6VFnNRbsZQIxQ10PbKKHt8gZ/HW/D/747aDl+QkDqg3KQLMQ==", - "dev": true - }, - "node_modules/body-parser": { - "version": "1.20.2", - "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.2.tgz", - "integrity": "sha512-ml9pReCu3M61kGlqoTm2umSXTlRTuGTx0bfYj+uIUKKYycG5NtSbeetV3faSU6R7ajOPw0g/J1PvK4qNy7s5bA==", - "dev": true, - "dependencies": { - "bytes": "3.1.2", - "content-type": "~1.0.5", - "debug": "2.6.9", - "depd": "2.0.0", - "destroy": "1.2.0", - "http-errors": "2.0.0", - "iconv-lite": "0.4.24", - "on-finished": "2.4.1", - "qs": "6.11.0", - "raw-body": "2.5.2", - "type-is": "~1.6.18", - "unpipe": "1.0.0" - }, - "engines": { - "node": ">= 0.8", - "npm": "1.2.8000 || >= 1.4.16" - } - }, - "node_modules/body-parser/node_modules/debug": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", - "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", - "dev": true, - "dependencies": { - "ms": "2.0.0" - } - }, - "node_modules/body-parser/node_modules/ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", - "dev": true - }, - "node_modules/brace-expansion": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", - "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "dev": true, - "dependencies": { - "balanced-match": "^1.0.0", - "concat-map": "0.0.1" - } - }, - "node_modules/braces": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", - "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", - "dev": true, - "dependencies": { - "fill-range": "^7.0.1" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/brorand": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/brorand/-/brorand-1.1.0.tgz", - "integrity": "sha512-cKV8tMCEpQs4hK/ik71d6LrPOnpkpGBR0wzxqr68g2m/LB2GxVYQroAjMJZRVM1Y4BCjCKc3vAamxSzOY2RP+w==", - "dev": true - }, - "node_modules/browser-level": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/browser-level/-/browser-level-1.0.1.tgz", - "integrity": "sha512-XECYKJ+Dbzw0lbydyQuJzwNXtOpbMSq737qxJN11sIRTErOMShvDpbzTlgju7orJKvx4epULolZAuJGLzCmWRQ==", - "dependencies": { - "abstract-level": "^1.0.2", - "catering": "^2.1.1", - "module-error": "^1.0.2", - "run-parallel-limit": "^1.1.0" - } - }, - "node_modules/browser-resolve": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/browser-resolve/-/browser-resolve-2.0.0.tgz", - "integrity": "sha512-7sWsQlYL2rGLy2IWm8WL8DCTJvYLc/qlOnsakDac87SOoCd16WLsaAMdCiAqsTNHIe+SXfaqyxyo6THoWqs8WQ==", - "dev": true, - "dependencies": { - "resolve": "^1.17.0" - } - }, - "node_modules/browser-stdout": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.1.tgz", - "integrity": "sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw==", - "dev": true - }, - "node_modules/browserify-aes": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/browserify-aes/-/browserify-aes-1.2.0.tgz", - "integrity": "sha512-+7CHXqGuspUn/Sl5aO7Ea0xWGAtETPXNSAjHo48JfLdPWcMng33Xe4znFvQweqc/uzk5zSOI3H52CYnjCfb5hA==", - "dev": true, - "dependencies": { - "buffer-xor": "^1.0.3", - "cipher-base": "^1.0.0", - "create-hash": "^1.1.0", - "evp_bytestokey": "^1.0.3", - "inherits": "^2.0.1", - "safe-buffer": "^5.0.1" - } - }, - "node_modules/browserify-cipher": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/browserify-cipher/-/browserify-cipher-1.0.1.tgz", - "integrity": "sha512-sPhkz0ARKbf4rRQt2hTpAHqn47X3llLkUGn+xEJzLjwY8LRs2p0v7ljvI5EyoRO/mexrNunNECisZs+gw2zz1w==", - "dev": true, - "dependencies": { - "browserify-aes": "^1.0.4", - "browserify-des": "^1.0.0", - "evp_bytestokey": "^1.0.0" - } - }, - "node_modules/browserify-des": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/browserify-des/-/browserify-des-1.0.2.tgz", - "integrity": "sha512-BioO1xf3hFwz4kc6iBhI3ieDFompMhrMlnDFC4/0/vd5MokpuAc3R+LYbwTA9A5Yc9pq9UYPqffKpW2ObuwX5A==", - "dev": true, - "dependencies": { - "cipher-base": "^1.0.1", - "des.js": "^1.0.0", - "inherits": "^2.0.1", - "safe-buffer": "^5.1.2" - } - }, - "node_modules/browserify-rsa": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/browserify-rsa/-/browserify-rsa-4.1.0.tgz", - "integrity": "sha512-AdEER0Hkspgno2aR97SAf6vi0y0k8NuOpGnVH3O99rcA5Q6sh8QxcngtHuJ6uXwnfAXNM4Gn1Gb7/MV1+Ymbog==", - "dev": true, - "dependencies": { - "bn.js": "^5.0.0", - "randombytes": "^2.0.1" - } - }, - "node_modules/browserify-sign": { - "version": "4.2.1", - "resolved": "https://registry.npmjs.org/browserify-sign/-/browserify-sign-4.2.1.tgz", - "integrity": "sha512-/vrA5fguVAKKAVTNJjgSm1tRQDHUU6DbwO9IROu/0WAzC8PKhucDSh18J0RMvVeHAn5puMd+QHC2erPRNf8lmg==", - "dev": true, - "dependencies": { - "bn.js": "^5.1.1", - "browserify-rsa": "^4.0.1", - "create-hash": "^1.2.0", - "create-hmac": "^1.1.7", - "elliptic": "^6.5.3", - "inherits": "^2.0.4", - "parse-asn1": "^5.1.5", - "readable-stream": "^3.6.0", - "safe-buffer": "^5.2.0" - } - }, - "node_modules/browserify-sign/node_modules/readable-stream": { - "version": "3.6.2", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", - "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", - "dev": true, - "dependencies": { - "inherits": "^2.0.3", - "string_decoder": "^1.1.1", - "util-deprecate": "^1.0.1" - }, - "engines": { - "node": ">= 6" - } - }, - "node_modules/browserify-sign/node_modules/safe-buffer": { - "version": "5.2.1", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", - "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", - "dev": true, - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ] - }, - "node_modules/browserify-zlib": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/browserify-zlib/-/browserify-zlib-0.2.0.tgz", - "integrity": "sha512-Z942RysHXmJrhqk88FmKBVq/v5tqmSkDz7p54G/MGyjMnCFFnC79XWNbg+Vta8W6Wb2qtSZTSxIGkJrRpCFEiA==", - "dev": true, - "dependencies": { - "pako": "~1.0.5" - } - }, - "node_modules/browserslist": { - "version": "4.21.10", - "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.21.10.tgz", - "integrity": "sha512-bipEBdZfVH5/pwrvqc+Ub0kUPVfGUhlKxbvfD+z1BDnPEO/X98ruXGA1WP5ASpAFKan7Qr6j736IacbZQuAlKQ==", - "dev": true, - "funding": [ - { - "type": "opencollective", - "url": "https://opencollective.com/browserslist" - }, - { - "type": "tidelift", - "url": "https://tidelift.com/funding/github/npm/browserslist" - }, - { - "type": "github", - "url": "https://github.com/sponsors/ai" - } - ], - "peer": true, - "dependencies": { - "caniuse-lite": "^1.0.30001517", - "electron-to-chromium": "^1.4.477", - "node-releases": "^2.0.13", - "update-browserslist-db": "^1.0.11" - }, - "bin": { - "browserslist": "cli.js" - }, - "engines": { - "node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7" - } - }, - "node_modules/buffer": { - "version": "6.0.3", - "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", - "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ], - "dependencies": { - "base64-js": "^1.3.1", - "ieee754": "^1.2.1" - } - }, - "node_modules/buffer-from": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", - "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==", - "dev": true, - "peer": true - }, - "node_modules/buffer-xor": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/buffer-xor/-/buffer-xor-1.0.3.tgz", - "integrity": "sha512-571s0T7nZWK6vB67HI5dyUF7wXiNcfaPPPTl6zYCNApANjIvYJTg7hlud/+cJpdAhS7dVzqMLmfhfHR3rAcOjQ==", - "dev": true - }, - "node_modules/builtin-status-codes": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/builtin-status-codes/-/builtin-status-codes-3.0.0.tgz", - "integrity": "sha512-HpGFw18DgFWlncDfjTa2rcQ4W88O1mC8e8yZ2AvQY5KDaktSTwo+KRf6nHK6FRI5FyRyb/5T6+TSxfP7QyGsmQ==", - "dev": true - }, - "node_modules/bytes": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", - "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==", - "dev": true, - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/c8": { - "version": "8.0.0", - "resolved": "https://registry.npmjs.org/c8/-/c8-8.0.0.tgz", - "integrity": "sha512-XHA5vSfCLglAc0Xt8eLBZMv19lgiBSjnb1FLAQgnwkuhJYEonpilhEB4Ea3jPAbm0FhD6VVJrc0z73jPe7JyGQ==", - "dev": true, - "dependencies": { - "@bcoe/v8-coverage": "^0.2.3", - "@istanbuljs/schema": "^0.1.3", - "find-up": "^5.0.0", - "foreground-child": "^2.0.0", - "istanbul-lib-coverage": "^3.2.0", - "istanbul-lib-report": "^3.0.0", - "istanbul-reports": "^3.1.4", - "rimraf": "^3.0.2", - "test-exclude": "^6.0.0", - "v8-to-istanbul": "^9.0.0", - "yargs": "^16.2.0", - "yargs-parser": "^20.2.9" - }, - "bin": { - "c8": "bin/c8.js" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/c8/node_modules/rimraf": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", - "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", - "dev": true, - "dependencies": { - "glob": "^7.1.3" - }, - "bin": { - "rimraf": "bin.js" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, - "node_modules/call-bind": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz", - "integrity": "sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==", - "dev": true, - "dependencies": { - "function-bind": "^1.1.1", - "get-intrinsic": "^1.0.2" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/callsites": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", - "integrity": "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==", - "dev": true, - "engines": { - "node": ">=6" - } - }, - "node_modules/camelcase": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-6.3.0.tgz", - "integrity": "sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==", - "dev": true, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/caniuse-lite": { - "version": "1.0.30001519", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001519.tgz", - "integrity": "sha512-0QHgqR+Jv4bxHMp8kZ1Kn8CH55OikjKJ6JmKkZYP1F3D7w+lnFXF70nG5eNfsZS89jadi5Ywy5UCSKLAglIRkg==", - "dev": true, - "funding": [ - { - "type": "opencollective", - "url": "https://opencollective.com/browserslist" - }, - { - "type": "tidelift", - "url": "https://tidelift.com/funding/github/npm/caniuse-lite" - }, - { - "type": "github", - "url": "https://github.com/sponsors/ai" - } - ], - "peer": true - }, - "node_modules/canonicalize": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/canonicalize/-/canonicalize-2.0.0.tgz", - "integrity": "sha512-ulDEYPv7asdKvqahuAY35c1selLdzDwHqugK92hfkzvlDCwXRRelDkR+Er33md/PtnpqHemgkuDPanZ4fiYZ8w==" - }, - "node_modules/catering": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/catering/-/catering-2.1.1.tgz", - "integrity": "sha512-K7Qy8O9p76sL3/3m7/zLKbRkyOlSZAgzEaLhyj2mXS8PsCud2Eo4hAb8aLtZqHh0QGqLcb9dlJSu6lHRVENm1w==", - "engines": { - "node": ">=6" - } - }, - "node_modules/cborg": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/cborg/-/cborg-2.0.3.tgz", - "integrity": "sha512-f1IbyqgRLQK4ruNM+V3WikfYfXQg/f/zC1oneOw1P7F/Dn2OJX6MaXIdei3JMpz361IjY7OENBKcE53nkJFVCQ==", - "bin": { - "cborg": "cli.js" - } - }, - "node_modules/chai": { - "version": "4.3.7", - "resolved": "https://registry.npmjs.org/chai/-/chai-4.3.7.tgz", - "integrity": "sha512-HLnAzZ2iupm25PlN0xFreAlBA5zaBSv3og0DdeGA4Ar6h6rJ3A0rolRUKJhSF2V10GZKDgWF/VmAEsNWjCRB+A==", - "dependencies": { - "assertion-error": "^1.1.0", - "check-error": "^1.0.2", - "deep-eql": "^4.1.2", - "get-func-name": "^2.0.0", - "loupe": "^2.3.1", - "pathval": "^1.1.1", - "type-detect": "^4.0.5" - }, - "engines": { - "node": ">=4" - } - }, - "node_modules/chai-as-promised": { - "version": "7.1.1", - "resolved": "https://registry.npmjs.org/chai-as-promised/-/chai-as-promised-7.1.1.tgz", - "integrity": "sha512-azL6xMoi+uxu6z4rhWQ1jbdUhOMhis2PvscD/xjLqNMkv3BPPp2JyyuTHOrf9BOosGpNQ11v6BKv/g57RXbiaA==", - "dev": true, - "dependencies": { - "check-error": "^1.0.2" - }, - "peerDependencies": { - "chai": ">= 2.1.2 < 5" - } - }, - "node_modules/chalk": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", - "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", - "dev": true, - "dependencies": { - "ansi-styles": "^4.1.0", - "supports-color": "^7.1.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/chalk/chalk?sponsor=1" - } - }, - "node_modules/check-error": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.2.tgz", - "integrity": "sha512-BrgHpW9NURQgzoNyjfq0Wu6VFO6D7IZEmJNdtgNqpzGG8RuNFHt2jQxWlAs4HMe119chBnv+34syEZtc6IhLtA==", - "engines": { - "node": "*" - } - }, - "node_modules/chokidar": { - "version": "3.5.3", - "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz", - "integrity": "sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==", - "dev": true, - "funding": [ - { - "type": "individual", - "url": "https://paulmillr.com/funding/" - } - ], - "dependencies": { - "anymatch": "~3.1.2", - "braces": "~3.0.2", - "glob-parent": "~5.1.2", - "is-binary-path": "~2.1.0", - "is-glob": "~4.0.1", - "normalize-path": "~3.0.0", - "readdirp": "~3.6.0" - }, - "engines": { - "node": ">= 8.10.0" - }, - "optionalDependencies": { - "fsevents": "~2.3.2" - } - }, - "node_modules/chokidar/node_modules/glob-parent": { - "version": "5.1.2", - "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", - "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", - "dev": true, - "dependencies": { - "is-glob": "^4.0.1" - }, - "engines": { - "node": ">= 6" - } - }, - "node_modules/chrome-trace-event": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/chrome-trace-event/-/chrome-trace-event-1.0.3.tgz", - "integrity": "sha512-p3KULyQg4S7NIHixdwbGX+nFHkoBiA4YQmyWtjb8XngSKV124nJmRysgAeujbUVb15vh+RvFUfCPqU7rXk+hZg==", - "dev": true, - "peer": true, - "engines": { - "node": ">=6.0" - } - }, - "node_modules/ci-info": { - "version": "3.8.0", - "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-3.8.0.tgz", - "integrity": "sha512-eXTggHWSooYhq49F2opQhuHWgzucfF2YgODK4e1566GQs5BIfP30B0oenwBJHfWxAs2fyPB1s7Mg949zLf61Yw==", - "dev": true, - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/sibiraj-s" - } - ], - "engines": { - "node": ">=8" - } - }, - "node_modules/cipher-base": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/cipher-base/-/cipher-base-1.0.4.tgz", - "integrity": "sha512-Kkht5ye6ZGmwv40uUDZztayT2ThLQGfnj/T71N/XzeZeo3nf8foyW7zGTsPYkEya3m5f3cAypH+qe7YOrM1U2Q==", - "dev": true, - "dependencies": { - "inherits": "^2.0.1", - "safe-buffer": "^5.0.1" - } - }, - "node_modules/classic-level": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/classic-level/-/classic-level-1.3.0.tgz", - "integrity": "sha512-iwFAJQYtqRTRM0F6L8h4JCt00ZSGdOyqh7yVrhhjrOpFhmBjNlRUey64MCiyo6UmQHMJ+No3c81nujPv+n9yrg==", - "hasInstallScript": true, - "dependencies": { - "abstract-level": "^1.0.2", - "catering": "^2.1.0", - "module-error": "^1.0.1", - "napi-macros": "^2.2.2", - "node-gyp-build": "^4.3.0" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/cliui": { - "version": "7.0.4", - "resolved": "https://registry.npmjs.org/cliui/-/cliui-7.0.4.tgz", - "integrity": "sha512-OcRE68cOsVMXp1Yvonl/fzkQOyjLSu/8bhPDfQt0e0/Eb283TKP20Fs2MqoPsr9SwA595rRCA+QMzYc9nBP+JQ==", - "dev": true, - "dependencies": { - "string-width": "^4.2.0", - "strip-ansi": "^6.0.0", - "wrap-ansi": "^7.0.0" - } - }, - "node_modules/color-convert": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", - "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "dev": true, - "dependencies": { - "color-name": "~1.1.4" - }, - "engines": { - "node": ">=7.0.0" - } - }, - "node_modules/color-name": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", - "dev": true - }, - "node_modules/commander": { - "version": "2.20.3", - "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", - "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", - "dev": true, - "peer": true - }, - "node_modules/concat-map": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==", - "dev": true - }, - "node_modules/connect": { - "version": "3.7.0", - "resolved": "https://registry.npmjs.org/connect/-/connect-3.7.0.tgz", - "integrity": "sha512-ZqRXc+tZukToSNmh5C2iWMSoV3X1YUcPbqEM4DkEG5tNQXrQUZCNVGGv3IuicnkMtPfGf3Xtp8WCXs295iQ1pQ==", - "dev": true, - "dependencies": { - "debug": "2.6.9", - "finalhandler": "1.1.2", - "parseurl": "~1.3.3", - "utils-merge": "1.0.1" - }, - "engines": { - "node": ">= 0.10.0" - } - }, - "node_modules/connect/node_modules/debug": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", - "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", - "dev": true, - "dependencies": { - "ms": "2.0.0" - } - }, - "node_modules/connect/node_modules/ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", - "dev": true - }, - "node_modules/console-browserify": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/console-browserify/-/console-browserify-1.2.0.tgz", - "integrity": "sha512-ZMkYO/LkF17QvCPqM0gxw8yUzigAOZOSWSHg91FH6orS7vcEj5dVZTidN2fQ14yBSdg97RqhSNwLUXInd52OTA==", - "dev": true - }, - "node_modules/constants-browserify": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/constants-browserify/-/constants-browserify-1.0.0.tgz", - "integrity": "sha512-xFxOwqIzR/e1k1gLiWEophSCMqXcwVHIH7akf7b/vxcUeGunlj3hvZaaqxwHsTgn+IndtkQJgSztIDWeumWJDQ==", - "dev": true - }, - "node_modules/content-type": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz", - "integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==", - "dev": true, - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/convert-source-map": { - "version": "1.9.0", - "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.9.0.tgz", - "integrity": "sha512-ASFBup0Mz1uyiIjANan1jzLQami9z1PoYSZCiiYW2FczPbenXc45FZdBZLzOT+r6+iciuEModtmCti+hjaAk0A==", - "dev": true - }, - "node_modules/cookie": { - "version": "0.4.2", - "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.2.tgz", - "integrity": "sha512-aSWTXFzaKWkvHO1Ny/s+ePFpvKsPnjc551iI41v3ny/ow6tBG5Vd+FuqGNhh1LxOmVzOlGUriIlOaokOvhaStA==", - "dev": true, - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/cors": { - "version": "2.8.5", - "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz", - "integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==", - "dev": true, - "dependencies": { - "object-assign": "^4", - "vary": "^1" - }, - "engines": { - "node": ">= 0.10" - } - }, - "node_modules/create-ecdh": { - "version": "4.0.4", - "resolved": "https://registry.npmjs.org/create-ecdh/-/create-ecdh-4.0.4.tgz", - "integrity": "sha512-mf+TCx8wWc9VpuxfP2ht0iSISLZnt0JgWlrOKZiNqyUZWnjIaCIVNQArMHnCZKfEYRg6IM7A+NeJoN8gf/Ws0A==", - "dev": true, - "dependencies": { - "bn.js": "^4.1.0", - "elliptic": "^6.5.3" - } - }, - "node_modules/create-ecdh/node_modules/bn.js": { - "version": "4.12.0", - "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.12.0.tgz", - "integrity": "sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA==", - "dev": true - }, - "node_modules/create-hash": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/create-hash/-/create-hash-1.2.0.tgz", - "integrity": "sha512-z00bCGNHDG8mHAkP7CtT1qVu+bFQUPjYq/4Iv3C3kWjTFV10zIjfSoeqXo9Asws8gwSHDGj/hl2u4OGIjapeCg==", - "dev": true, - "dependencies": { - "cipher-base": "^1.0.1", - "inherits": "^2.0.1", - "md5.js": "^1.3.4", - "ripemd160": "^2.0.1", - "sha.js": "^2.4.0" - } - }, - "node_modules/create-hmac": { - "version": "1.1.7", - "resolved": "https://registry.npmjs.org/create-hmac/-/create-hmac-1.1.7.tgz", - "integrity": "sha512-MJG9liiZ+ogc4TzUwuvbER1JRdgvUFSB5+VR/g5h82fGaIRWMWddtKBHi7/sVhfjQZ6SehlyhvQYrcYkaUIpLg==", - "dev": true, - "dependencies": { - "cipher-base": "^1.0.3", - "create-hash": "^1.1.0", - "inherits": "^2.0.1", - "ripemd160": "^2.0.0", - "safe-buffer": "^5.0.1", - "sha.js": "^2.4.8" - } - }, - "node_modules/create-require": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", - "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", - "dev": true - }, - "node_modules/cross-fetch": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-4.0.0.tgz", - "integrity": "sha512-e4a5N8lVvuLgAWgnCrLr2PP0YyDOTHa9H/Rj54dirp61qXnNq46m82bRhNqIA5VccJtWBvPTFRV3TtvHUKPB1g==", - "dependencies": { - "node-fetch": "^2.6.12" - } - }, - "node_modules/cross-spawn": { - "version": "7.0.3", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", - "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", - "dev": true, - "dependencies": { - "path-key": "^3.1.0", - "shebang-command": "^2.0.0", - "which": "^2.0.1" - }, - "engines": { - "node": ">= 8" - } - }, - "node_modules/crypto-browserify": { - "version": "3.12.0", - "resolved": "https://registry.npmjs.org/crypto-browserify/-/crypto-browserify-3.12.0.tgz", - "integrity": "sha512-fz4spIh+znjO2VjL+IdhEpRJ3YN6sMzITSBijk6FK2UvTqruSQW+/cCZTSNsMiZNvUeq0CqurF+dAbyiGOY6Wg==", - "dev": true, - "dependencies": { - "browserify-cipher": "^1.0.0", - "browserify-sign": "^4.0.0", - "create-ecdh": "^4.0.0", - "create-hash": "^1.1.0", - "create-hmac": "^1.1.0", - "diffie-hellman": "^5.0.0", - "inherits": "^2.0.1", - "pbkdf2": "^3.0.3", - "public-encrypt": "^4.0.0", - "randombytes": "^2.0.0", - "randomfill": "^1.0.3" - }, - "engines": { - "node": "*" - } - }, - "node_modules/custom-event": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/custom-event/-/custom-event-1.0.1.tgz", - "integrity": "sha512-GAj5FOq0Hd+RsCGVJxZuKaIDXDf3h6GQoNEjFgbLLI/trgtavwUbSnZ5pVfg27DVCaWjIohryS0JFwIJyT2cMg==", - "dev": true - }, - "node_modules/date-format": { - "version": "4.0.14", - "resolved": "https://registry.npmjs.org/date-format/-/date-format-4.0.14.tgz", - "integrity": "sha512-39BOQLs9ZjKh0/patS9nrT8wc3ioX3/eA/zgbKNopnF2wCqJEoxywwwElATYvRsXdnOxA/OQeQoFZ3rFjVajhg==", - "dev": true, - "engines": { - "node": ">=4.0" - } - }, - "node_modules/debug": { - "version": "4.3.4", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", - "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", - "dependencies": { - "ms": "2.1.2" - }, - "engines": { - "node": ">=6.0" - }, - "peerDependenciesMeta": { - "supports-color": { - "optional": true - } - } - }, - "node_modules/debug/node_modules/ms": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" - }, - "node_modules/decamelize": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-4.0.0.tgz", - "integrity": "sha512-9iE1PgSik9HeIIw2JO94IidnE3eBoQrFJ3w7sFuzSX4DpmZ3v5sZpUiV5Swcf6mQEF+Y0ru8Neo+p+nyh2J+hQ==", - "dev": true, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/deep-eql": { - "version": "4.1.3", - "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-4.1.3.tgz", - "integrity": "sha512-WaEtAOpRA1MQ0eohqZjpGD8zdI0Ovsm8mmFhaDN8dvDZzyoUMcYDnf5Y6iu7HTXxf8JDS23qWa4a+hKCDyOPzw==", - "dependencies": { - "type-detect": "^4.0.0" - }, - "engines": { - "node": ">=6" - } - }, - "node_modules/deep-is": { - "version": "0.1.4", - "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz", - "integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==", - "dev": true - }, - "node_modules/define-properties": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.2.0.tgz", - "integrity": "sha512-xvqAVKGfT1+UAvPwKTVw/njhdQ8ZhXK4lI0bCIuCMrp2up9nPnaDftrLtmpTazqd1o+UY4zgzU+avtMbDP+ldA==", - "dev": true, - "dependencies": { - "has-property-descriptors": "^1.0.0", - "object-keys": "^1.1.1" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/depd": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", - "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==", - "dev": true, - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/des.js": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/des.js/-/des.js-1.1.0.tgz", - "integrity": "sha512-r17GxjhUCjSRy8aiJpr8/UadFIzMzJGexI3Nmz4ADi9LYSFx4gTBp80+NaX/YsXWWLhpZ7v/v/ubEc/bCNfKwg==", - "dev": true, - "dependencies": { - "inherits": "^2.0.1", - "minimalistic-assert": "^1.0.0" - } - }, - "node_modules/destroy": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz", - "integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==", - "dev": true, - "engines": { - "node": ">= 0.8", - "npm": "1.2.8000 || >= 1.4.16" - } - }, - "node_modules/di": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/di/-/di-0.0.1.tgz", - "integrity": "sha512-uJaamHkagcZtHPqCIHZxnFrXlunQXgBOsZSUOWwFw31QJCAbyTBoHMW75YOTur5ZNx8pIeAKgf6GWIgaqqiLhA==", - "dev": true - }, - "node_modules/diff": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/diff/-/diff-5.0.0.tgz", - "integrity": "sha512-/VTCrvm5Z0JGty/BWHljh+BAiw3IK+2j87NGMu8Nwc/f48WoDAC395uomO9ZD117ZOBaHmkX1oyLvkVM/aIT3w==", - "dev": true, - "engines": { - "node": ">=0.3.1" - } - }, - "node_modules/diffie-hellman": { - "version": "5.0.3", - "resolved": "https://registry.npmjs.org/diffie-hellman/-/diffie-hellman-5.0.3.tgz", - "integrity": "sha512-kqag/Nl+f3GwyK25fhUMYj81BUOrZ9IuJsjIcDE5icNM9FJHAVm3VcUDxdLPoQtTuUylWm6ZIknYJwwaPxsUzg==", - "dev": true, - "dependencies": { - "bn.js": "^4.1.0", - "miller-rabin": "^4.0.0", - "randombytes": "^2.0.0" - } - }, - "node_modules/diffie-hellman/node_modules/bn.js": { - "version": "4.12.0", - "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.12.0.tgz", - "integrity": "sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA==", - "dev": true - }, - "node_modules/dir-glob": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz", - "integrity": "sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==", - "dev": true, - "dependencies": { - "path-type": "^4.0.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/doctrine": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", - "integrity": "sha512-yS+Q5i3hBf7GBkd4KG8a7eBNNWNGLTaEwwYWUijIYM7zrlYDM0BFXHjjPWlWZ1Rg7UaddZeIDmi9jF3HmqiQ2w==", - "dev": true, - "dependencies": { - "esutils": "^2.0.2" - }, - "engines": { - "node": ">=6.0.0" - } - }, - "node_modules/dom-serialize": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/dom-serialize/-/dom-serialize-2.2.1.tgz", - "integrity": "sha512-Yra4DbvoW7/Z6LBN560ZwXMjoNOSAN2wRsKFGc4iBeso+mpIA6qj1vfdf9HpMaKAqG6wXTy+1SYEzmNpKXOSsQ==", - "dev": true, - "dependencies": { - "custom-event": "~1.0.0", - "ent": "~2.2.0", - "extend": "^3.0.0", - "void-elements": "^2.0.0" - } - }, - "node_modules/domain-browser": { - "version": "4.22.0", - "resolved": "https://registry.npmjs.org/domain-browser/-/domain-browser-4.22.0.tgz", - "integrity": "sha512-IGBwjF7tNk3cwypFNH/7bfzBcgSCbaMOD3GsaY1AU/JRrnHnYgEM0+9kQt52iZxjNsjBtJYtao146V+f8jFZNw==", - "dev": true, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://bevry.me/fund" - } - }, - "node_modules/eciesjs": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/eciesjs/-/eciesjs-0.4.0.tgz", - "integrity": "sha512-z4dEeaH16xxYVgtxJ8YVwpifH4Keg4gyp5F451mnDNwbAN3MgL5jcoEQGpqJrapv/zW8KwDnXG21Dw5B0hqvmw==", - "dependencies": { - "@noble/curves": "^1.1.0" - } - }, - "node_modules/ed2curve": { - "version": "0.3.0", - "resolved": "https://registry.npmjs.org/ed2curve/-/ed2curve-0.3.0.tgz", - "integrity": "sha512-8w2fmmq3hv9rCrcI7g9hms2pMunQr1JINfcjwR9tAyZqhtyaMN991lF/ZfHfr5tzZQ8c7y7aBgZbjfbd0fjFwQ==", - "dependencies": { - "tweetnacl": "1.x.x" - } - }, - "node_modules/ee-first": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", - "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==", - "dev": true - }, - "node_modules/electron-to-chromium": { - "version": "1.4.485", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.485.tgz", - "integrity": "sha512-1ndQ5IBNEnFirPwvyud69GHL+31FkE09gH/CJ6m3KCbkx3i0EVOrjwz4UNxRmN9H8OVHbC6vMRZGN1yCvjSs9w==", - "dev": true, - "peer": true - }, - "node_modules/elliptic": { - "version": "6.5.4", - "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.4.tgz", - "integrity": "sha512-iLhC6ULemrljPZb+QutR5TQGB+pdW6KGD5RSegS+8sorOZT+rdQFbsQFJgvN3eRqNALqJer4oQ16YvJHlU8hzQ==", - "dev": true, - "dependencies": { - "bn.js": "^4.11.9", - "brorand": "^1.1.0", - "hash.js": "^1.0.0", - "hmac-drbg": "^1.0.1", - "inherits": "^2.0.4", - "minimalistic-assert": "^1.0.1", - "minimalistic-crypto-utils": "^1.0.1" - } - }, - "node_modules/elliptic/node_modules/bn.js": { - "version": "4.12.0", - "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.12.0.tgz", - "integrity": "sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA==", - "dev": true - }, - "node_modules/emoji-regex": { - "version": "8.0.0", - "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", - "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", - "dev": true - }, - "node_modules/encodeurl": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", - "integrity": "sha512-TPJXq8JqFaVYm2CWmPvnP2Iyo4ZSM7/QKcSmuMLDObfpH5fi7RUGmd/rTDf+rut/saiDiQEeVTNgAmJEdAOx0w==", - "dev": true, - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/engine.io": { - "version": "6.5.2", - "resolved": "https://registry.npmjs.org/engine.io/-/engine.io-6.5.2.tgz", - "integrity": "sha512-IXsMcGpw/xRfjra46sVZVHiSWo/nJ/3g1337q9KNXtS6YRzbW5yIzTCb9DjhrBe7r3GZQR0I4+nq+4ODk5g/cA==", - "dev": true, - "dependencies": { - "@types/cookie": "^0.4.1", - "@types/cors": "^2.8.12", - "@types/node": ">=10.0.0", - "accepts": "~1.3.4", - "base64id": "2.0.0", - "cookie": "~0.4.1", - "cors": "~2.8.5", - "debug": "~4.3.1", - "engine.io-parser": "~5.2.1", - "ws": "~8.11.0" - }, - "engines": { - "node": ">=10.2.0" - } - }, - "node_modules/engine.io-parser": { - "version": "5.2.1", - "resolved": "https://registry.npmjs.org/engine.io-parser/-/engine.io-parser-5.2.1.tgz", - "integrity": "sha512-9JktcM3u18nU9N2Lz3bWeBgxVgOKpw7yhRaoxQA3FUDZzzw+9WlA6p4G4u0RixNkg14fH7EfEc/RhpurtiROTQ==", - "dev": true, - "engines": { - "node": ">=10.0.0" - } - }, - "node_modules/enhanced-resolve": { - "version": "5.15.0", - "resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.15.0.tgz", - "integrity": "sha512-LXYT42KJ7lpIKECr2mAXIaMldcNCh/7E0KBKOu4KSfkHmP+mZmSs+8V5gBAqisWBy0OO4W5Oyys0GO1Y8KtdKg==", - "dev": true, - "peer": true, - "dependencies": { - "graceful-fs": "^4.2.4", - "tapable": "^2.2.0" - }, - "engines": { - "node": ">=10.13.0" - } - }, - "node_modules/ent": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/ent/-/ent-2.2.0.tgz", - "integrity": "sha512-GHrMyVZQWvTIdDtpiEXdHZnFQKzeO09apj8Cbl4pKWy4i0Oprcq17usfDt5aO63swf0JOeMWjWQE/LzgSRuWpA==", - "dev": true - }, - "node_modules/err-code": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/err-code/-/err-code-3.0.1.tgz", - "integrity": "sha512-GiaH0KJUewYok+eeY05IIgjtAe4Yltygk9Wqp1V5yVWLdhf0hYZchRjNIT9bb0mSwRcIusT3cx7PJUf3zEIfUA==" - }, - "node_modules/es-module-lexer": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-1.3.0.tgz", - "integrity": "sha512-vZK7T0N2CBmBOixhmjdqx2gWVbFZ4DXZ/NyRMZVlJXPa7CyFS+/a4QQsDGDQy9ZfEzxFuNEsMLeQJnKP2p5/JA==", - "dev": true, - "peer": true - }, - "node_modules/es6-object-assign": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/es6-object-assign/-/es6-object-assign-1.1.0.tgz", - "integrity": "sha512-MEl9uirslVwqQU369iHNWZXsI8yaZYGg/D65aOgZkeyFJwHYSxilf7rQzXKI7DdDuBPrBXbfk3sl9hJhmd5AUw==", - "dev": true - }, - "node_modules/esbuild": { - "version": "0.16.17", - "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.16.17.tgz", - "integrity": "sha512-G8LEkV0XzDMNwXKgM0Jwu3nY3lSTwSGY6XbxM9cr9+s0T/qSV1q1JVPBGzm3dcjhCic9+emZDmMffkwgPeOeLg==", - "dev": true, - "hasInstallScript": true, - "bin": { - "esbuild": "bin/esbuild" - }, - "engines": { - "node": ">=12" - }, - "optionalDependencies": { - "@esbuild/android-arm": "0.16.17", - "@esbuild/android-arm64": "0.16.17", - "@esbuild/android-x64": "0.16.17", - "@esbuild/darwin-arm64": "0.16.17", - "@esbuild/darwin-x64": "0.16.17", - "@esbuild/freebsd-arm64": "0.16.17", - "@esbuild/freebsd-x64": "0.16.17", - "@esbuild/linux-arm": "0.16.17", - "@esbuild/linux-arm64": "0.16.17", - "@esbuild/linux-ia32": "0.16.17", - "@esbuild/linux-loong64": "0.16.17", - "@esbuild/linux-mips64el": "0.16.17", - "@esbuild/linux-ppc64": "0.16.17", - "@esbuild/linux-riscv64": "0.16.17", - "@esbuild/linux-s390x": "0.16.17", - "@esbuild/linux-x64": "0.16.17", - "@esbuild/netbsd-x64": "0.16.17", - "@esbuild/openbsd-x64": "0.16.17", - "@esbuild/sunos-x64": "0.16.17", - "@esbuild/win32-arm64": "0.16.17", - "@esbuild/win32-ia32": "0.16.17", - "@esbuild/win32-x64": "0.16.17" - } - }, - "node_modules/escalade": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz", - "integrity": "sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==", - "dev": true, - "engines": { - "node": ">=6" - } - }, - "node_modules/escape-html": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", - "integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==", - "dev": true - }, - "node_modules/escape-string-regexp": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", - "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", - "dev": true, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/eslint": { - "version": "8.39.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.39.0.tgz", - "integrity": "sha512-mwiok6cy7KTW7rBpo05k6+p4YVZByLNjAZ/ACB9DRCu4YDRwjXI01tWHp6KAUWelsBetTxKK/2sHB0vdS8Z2Og==", - "dev": true, - "dependencies": { - "@eslint-community/eslint-utils": "^4.2.0", - "@eslint-community/regexpp": "^4.4.0", - "@eslint/eslintrc": "^2.0.2", - "@eslint/js": "8.39.0", - "@humanwhocodes/config-array": "^0.11.8", - "@humanwhocodes/module-importer": "^1.0.1", - "@nodelib/fs.walk": "^1.2.8", - "ajv": "^6.10.0", - "chalk": "^4.0.0", - "cross-spawn": "^7.0.2", - "debug": "^4.3.2", - "doctrine": "^3.0.0", - "escape-string-regexp": "^4.0.0", - "eslint-scope": "^7.2.0", - "eslint-visitor-keys": "^3.4.0", - "espree": "^9.5.1", - "esquery": "^1.4.2", - "esutils": "^2.0.2", - "fast-deep-equal": "^3.1.3", - "file-entry-cache": "^6.0.1", - "find-up": "^5.0.0", - "glob-parent": "^6.0.2", - "globals": "^13.19.0", - "grapheme-splitter": "^1.0.4", - "ignore": "^5.2.0", - "import-fresh": "^3.0.0", - "imurmurhash": "^0.1.4", - "is-glob": "^4.0.0", - "is-path-inside": "^3.0.3", - "js-sdsl": "^4.1.4", - "js-yaml": "^4.1.0", - "json-stable-stringify-without-jsonify": "^1.0.1", - "levn": "^0.4.1", - "lodash.merge": "^4.6.2", - "minimatch": "^3.1.2", - "natural-compare": "^1.4.0", - "optionator": "^0.9.1", - "strip-ansi": "^6.0.1", - "strip-json-comments": "^3.1.0", - "text-table": "^0.2.0" - }, - "bin": { - "eslint": "bin/eslint.js" - }, - "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - }, - "funding": { - "url": "https://opencollective.com/eslint" - } - }, - "node_modules/eslint-plugin-mocha": { - "version": "10.1.0", - "resolved": "https://registry.npmjs.org/eslint-plugin-mocha/-/eslint-plugin-mocha-10.1.0.tgz", - "integrity": "sha512-xLqqWUF17llsogVOC+8C6/jvQ+4IoOREbN7ZCHuOHuD6cT5cDD4h7f2LgsZuzMAiwswWE21tO7ExaknHVDrSkw==", - "dev": true, - "dependencies": { - "eslint-utils": "^3.0.0", - "rambda": "^7.1.0" - }, - "engines": { - "node": ">=14.0.0" - }, - "peerDependencies": { - "eslint": ">=7.0.0" - } - }, - "node_modules/eslint-scope": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz", - "integrity": "sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw==", - "dev": true, - "dependencies": { - "esrecurse": "^4.3.0", - "estraverse": "^4.1.1" - }, - "engines": { - "node": ">=8.0.0" - } - }, - "node_modules/eslint-utils": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-3.0.0.tgz", - "integrity": "sha512-uuQC43IGctw68pJA1RgbQS8/NP7rch6Cwd4j3ZBtgo4/8Flj4eGE7ZYSZRN3iq5pVUv6GPdW5Z1RFleo84uLDA==", - "dev": true, - "dependencies": { - "eslint-visitor-keys": "^2.0.0" - }, - "engines": { - "node": "^10.0.0 || ^12.0.0 || >= 14.0.0" - }, - "funding": { - "url": "https://github.com/sponsors/mysticatea" - }, - "peerDependencies": { - "eslint": ">=5" - } - }, - "node_modules/eslint-utils/node_modules/eslint-visitor-keys": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-2.1.0.tgz", - "integrity": "sha512-0rSmRBzXgDzIsD6mGdJgevzgezI534Cer5L/vyMX0kHzT/jiB43jRhd9YUlMGYLQy2zprNmoT8qasCGtY+QaKw==", - "dev": true, - "engines": { - "node": ">=10" - } - }, - "node_modules/eslint-visitor-keys": { - "version": "3.4.2", - "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.4.2.tgz", - "integrity": "sha512-8drBzUEyZ2llkpCA67iYrgEssKDUu68V8ChqqOfFupIaG/LCVPUT+CoGJpT77zJprs4T/W7p07LP7zAIMuweVw==", - "dev": true, - "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - }, - "funding": { - "url": "https://opencollective.com/eslint" - } - }, - "node_modules/eslint/node_modules/ajv": { - "version": "6.12.6", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", - "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", - "dev": true, - "dependencies": { - "fast-deep-equal": "^3.1.1", - "fast-json-stable-stringify": "^2.0.0", - "json-schema-traverse": "^0.4.1", - "uri-js": "^4.2.2" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/epoberezkin" - } - }, - "node_modules/eslint/node_modules/eslint-scope": { - "version": "7.2.2", - "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-7.2.2.tgz", - "integrity": "sha512-dOt21O7lTMhDM+X9mB4GX+DZrZtCUJPL/wlcTqxyrx5IvO0IYtILdtrQGQp+8n5S0gwSVmOf9NQrjMOgfQZlIg==", - "dev": true, - "dependencies": { - "esrecurse": "^4.3.0", - "estraverse": "^5.2.0" - }, - "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - }, - "funding": { - "url": "https://opencollective.com/eslint" - } - }, - "node_modules/eslint/node_modules/estraverse": { - "version": "5.3.0", - "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.3.0.tgz", - "integrity": "sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==", - "dev": true, - "engines": { - "node": ">=4.0" - } - }, - "node_modules/eslint/node_modules/json-schema-traverse": { - "version": "0.4.1", - "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", - "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", - "dev": true - }, - "node_modules/espree": { - "version": "9.6.1", - "resolved": "https://registry.npmjs.org/espree/-/espree-9.6.1.tgz", - "integrity": "sha512-oruZaFkjorTpF32kDSI5/75ViwGeZginGGy2NoOSg3Q9bnwlnmDm4HLnkl0RE3n+njDXR037aY1+x58Z/zFdwQ==", - "dev": true, - "dependencies": { - "acorn": "^8.9.0", - "acorn-jsx": "^5.3.2", - "eslint-visitor-keys": "^3.4.1" - }, - "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - }, - "funding": { - "url": "https://opencollective.com/eslint" - } - }, - "node_modules/esquery": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.5.0.tgz", - "integrity": "sha512-YQLXUplAwJgCydQ78IMJywZCceoqk1oH01OERdSAJc/7U2AylwjhSCLDEtqwg811idIS/9fIU5GjG73IgjKMVg==", - "dev": true, - "dependencies": { - "estraverse": "^5.1.0" - }, - "engines": { - "node": ">=0.10" - } - }, - "node_modules/esquery/node_modules/estraverse": { - "version": "5.3.0", - "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.3.0.tgz", - "integrity": "sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==", - "dev": true, - "engines": { - "node": ">=4.0" - } - }, - "node_modules/esrecurse": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.3.0.tgz", - "integrity": "sha512-KmfKL3b6G+RXvP8N1vr3Tq1kL/oCFgn2NYXEtqP8/L3pKapUA4G8cFVaoF3SU323CD4XypR/ffioHmkti6/Tag==", - "dev": true, - "dependencies": { - "estraverse": "^5.2.0" - }, - "engines": { - "node": ">=4.0" - } - }, - "node_modules/esrecurse/node_modules/estraverse": { - "version": "5.3.0", - "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.3.0.tgz", - "integrity": "sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==", - "dev": true, - "engines": { - "node": ">=4.0" - } - }, - "node_modules/estraverse": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.3.0.tgz", - "integrity": "sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw==", - "dev": true, - "engines": { - "node": ">=4.0" - } - }, - "node_modules/esutils": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", - "integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==", - "dev": true, - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/event-target-shim": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz", - "integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==", - "engines": { - "node": ">=6" - } - }, - "node_modules/eventemitter3": { - "version": "4.0.7", - "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.7.tgz", - "integrity": "sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw==" - }, - "node_modules/events": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/events/-/events-3.3.0.tgz", - "integrity": "sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==", - "engines": { - "node": ">=0.8.x" - } - }, - "node_modules/evp_bytestokey": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/evp_bytestokey/-/evp_bytestokey-1.0.3.tgz", - "integrity": "sha512-/f2Go4TognH/KvCISP7OUsHn85hT9nUkxxA9BEWxFn+Oj9o8ZNLm/40hdlgSLyuOimsrTKLUMEorQexp/aPQeA==", - "dev": true, - "dependencies": { - "md5.js": "^1.3.4", - "safe-buffer": "^5.1.1" - } - }, - "node_modules/extend": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz", - "integrity": "sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==", - "dev": true - }, - "node_modules/fast-deep-equal": { - "version": "3.1.3", - "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", - "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==" - }, - "node_modules/fast-glob": { - "version": "3.3.1", - "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.1.tgz", - "integrity": "sha512-kNFPyjhh5cKjrUltxs+wFx+ZkbRaxxmZ+X0ZU31SOsxCEtP9VPgtq2teZw1DebupL5GmDaNQ6yKMMVcM41iqDg==", - "dev": true, - "dependencies": { - "@nodelib/fs.stat": "^2.0.2", - "@nodelib/fs.walk": "^1.2.3", - "glob-parent": "^5.1.2", - "merge2": "^1.3.0", - "micromatch": "^4.0.4" - }, - "engines": { - "node": ">=8.6.0" - } - }, - "node_modules/fast-glob/node_modules/glob-parent": { - "version": "5.1.2", - "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", - "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", - "dev": true, - "dependencies": { - "is-glob": "^4.0.1" - }, - "engines": { - "node": ">= 6" - } - }, - "node_modules/fast-json-stable-stringify": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", - "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==", - "dev": true - }, - "node_modules/fast-levenshtein": { - "version": "2.0.6", - "resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz", - "integrity": "sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==", - "dev": true - }, - "node_modules/fastq": { - "version": "1.15.0", - "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.15.0.tgz", - "integrity": "sha512-wBrocU2LCXXa+lWBt8RoIRD89Fi8OdABODa/kEnyeyjS5aZO5/GNvI5sEINADqP/h8M29UHTHUb53sUu5Ihqdw==", - "dev": true, - "dependencies": { - "reusify": "^1.0.4" - } - }, - "node_modules/file-entry-cache": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.1.tgz", - "integrity": "sha512-7Gps/XWymbLk2QLYK4NzpMOrYjMhdIxXuIvy2QBsLE6ljuodKvdkWs/cpyJJ3CVIVpH0Oi1Hvg1ovbMzLdFBBg==", - "dev": true, - "dependencies": { - "flat-cache": "^3.0.4" - }, - "engines": { - "node": "^10.12.0 || >=12.0.0" - } - }, - "node_modules/fill-range": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", - "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", - "dev": true, - "dependencies": { - "to-regex-range": "^5.0.1" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/finalhandler": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.2.tgz", - "integrity": "sha512-aAWcW57uxVNrQZqFXjITpW3sIUQmHGG3qSb9mUah9MgMC4NeWhNOlNjXEYq3HjRAvL6arUviZGGJsBg6z0zsWA==", - "dev": true, - "dependencies": { - "debug": "2.6.9", - "encodeurl": "~1.0.2", - "escape-html": "~1.0.3", - "on-finished": "~2.3.0", - "parseurl": "~1.3.3", - "statuses": "~1.5.0", - "unpipe": "~1.0.0" - }, - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/finalhandler/node_modules/debug": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", - "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", - "dev": true, - "dependencies": { - "ms": "2.0.0" - } - }, - "node_modules/finalhandler/node_modules/ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", - "dev": true - }, - "node_modules/finalhandler/node_modules/on-finished": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", - "integrity": "sha512-ikqdkGAAyf/X/gPhXGvfgAytDZtDbr+bkNUJ0N9h5MI/dmdgCs3l6hoHrcUv41sRKew3jIwrp4qQDXiK99Utww==", - "dev": true, - "dependencies": { - "ee-first": "1.1.1" - }, - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/find-up": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/find-up/-/find-up-5.0.0.tgz", - "integrity": "sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng==", - "dev": true, - "dependencies": { - "locate-path": "^6.0.0", - "path-exists": "^4.0.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/flat": { - "version": "5.0.2", - "resolved": "https://registry.npmjs.org/flat/-/flat-5.0.2.tgz", - "integrity": "sha512-b6suED+5/3rTpUBdG1gupIl8MPFCAMA0QXwmljLhvCUKcUvdE4gWky9zpuGCcXHOsz4J9wPGNWq6OKpmIzz3hQ==", - "bin": { - "flat": "cli.js" - } - }, - "node_modules/flat-cache": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-3.0.4.tgz", - "integrity": "sha512-dm9s5Pw7Jc0GvMYbshN6zchCA9RgQlzzEZX3vylR9IqFfS8XciblUXOKfW6SiuJ0e13eDYZoZV5wdrev7P3Nwg==", - "dev": true, - "dependencies": { - "flatted": "^3.1.0", - "rimraf": "^3.0.2" - }, - "engines": { - "node": "^10.12.0 || >=12.0.0" - } - }, - "node_modules/flat-cache/node_modules/rimraf": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", - "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", - "dev": true, - "dependencies": { - "glob": "^7.1.3" - }, - "bin": { - "rimraf": "bin.js" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, - "node_modules/flatted": { - "version": "3.2.7", - "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.2.7.tgz", - "integrity": "sha512-5nqDSxl8nn5BSNxyR3n4I6eDmbolI6WT+QqR547RwxQapgjQBmtktdP+HTBb/a/zLsbzERTONyUB5pefh5TtjQ==", - "dev": true - }, - "node_modules/follow-redirects": { - "version": "1.15.2", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz", - "integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==", - "dev": true, - "funding": [ - { - "type": "individual", - "url": "https://github.com/sponsors/RubenVerborgh" - } - ], - "engines": { - "node": ">=4.0" - }, - "peerDependenciesMeta": { - "debug": { - "optional": true - } - } - }, - "node_modules/for-each": { - "version": "0.3.3", - "resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz", - "integrity": "sha512-jqYfLp7mo9vIyQf8ykW2v7A+2N4QjeCeI5+Dz9XraiO1ign81wjiH7Fb9vSOWvQfNtmSa4H2RoQTrrXivdUZmw==", - "dev": true, - "dependencies": { - "is-callable": "^1.1.3" - } - }, - "node_modules/foreground-child": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-2.0.0.tgz", - "integrity": "sha512-dCIq9FpEcyQyXKCkyzmlPTFNgrCzPudOe+mhvJU5zAtlBnGVy2yKxtfsxK2tQBThwq225jcvBjpw1Gr40uzZCA==", - "dev": true, - "dependencies": { - "cross-spawn": "^7.0.0", - "signal-exit": "^3.0.2" - }, - "engines": { - "node": ">=8.0.0" - } - }, - "node_modules/fs-extra": { - "version": "8.1.0", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz", - "integrity": "sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==", - "dev": true, - "dependencies": { - "graceful-fs": "^4.2.0", - "jsonfile": "^4.0.0", - "universalify": "^0.1.0" - }, - "engines": { - "node": ">=6 <7 || >=8" - } - }, - "node_modules/fs.realpath": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==", - "dev": true - }, - "node_modules/fsevents": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", - "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", - "dev": true, - "hasInstallScript": true, - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": "^8.16.0 || ^10.6.0 || >=11.0.0" - } - }, - "node_modules/function-bind": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", - "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", - "dev": true - }, - "node_modules/get-caller-file": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", - "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==", - "dev": true, - "engines": { - "node": "6.* || 8.* || >= 10.*" - } - }, - "node_modules/get-func-name": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.0.tgz", - "integrity": "sha512-Hm0ixYtaSZ/V7C8FJrtZIuBBI+iSgL+1Aq82zSu8VQNB4S3Gk8e7Qs3VwBDJAhmRZcFqkl3tQu36g/Foh5I5ig==", - "engines": { - "node": "*" - } - }, - "node_modules/get-intrinsic": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.1.tgz", - "integrity": "sha512-2DcsyfABl+gVHEfCOaTrWgyt+tb6MSEGmKq+kI5HwLbIYgjgmMcV8KQ41uaKz1xxUcn9tJtgFbQUEVcEbd0FYw==", - "dev": true, - "dependencies": { - "function-bind": "^1.1.1", - "has": "^1.0.3", - "has-proto": "^1.0.1", - "has-symbols": "^1.0.3" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/glob": { - "version": "7.2.3", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", - "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", - "dev": true, - "dependencies": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^3.1.1", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" - }, - "engines": { - "node": "*" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, - "node_modules/glob-parent": { - "version": "6.0.2", - "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-6.0.2.tgz", - "integrity": "sha512-XxwI8EOhVQgWp6iDL+3b0r86f4d6AX6zSU55HfB4ydCEuXLXc5FcYeOu+nnGftS4TEju/11rt4KJPTMgbfmv4A==", - "dev": true, - "dependencies": { - "is-glob": "^4.0.3" - }, - "engines": { - "node": ">=10.13.0" - } - }, - "node_modules/glob-to-regexp": { - "version": "0.4.1", - "resolved": "https://registry.npmjs.org/glob-to-regexp/-/glob-to-regexp-0.4.1.tgz", - "integrity": "sha512-lkX1HJXwyMcprw/5YUZc2s7DrpAiHB21/V+E1rHUrVNokkvB6bqMzT0VfV6/86ZNabt1k14YOIaT7nDvOX3Iiw==", - "dev": true, - "peer": true - }, - "node_modules/globals": { - "version": "13.20.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-13.20.0.tgz", - "integrity": "sha512-Qg5QtVkCy/kv3FUSlu4ukeZDVf9ee0iXLAUYX13gbR17bnejFTzr4iS9bY7kwCf1NztRNm1t91fjOiyx4CSwPQ==", - "dev": true, - "dependencies": { - "type-fest": "^0.20.2" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/globby": { - "version": "11.1.0", - "resolved": "https://registry.npmjs.org/globby/-/globby-11.1.0.tgz", - "integrity": "sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==", - "dev": true, - "dependencies": { - "array-union": "^2.1.0", - "dir-glob": "^3.0.1", - "fast-glob": "^3.2.9", - "ignore": "^5.2.0", - "merge2": "^1.4.1", - "slash": "^3.0.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/gopd": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz", - "integrity": "sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==", - "dev": true, - "dependencies": { - "get-intrinsic": "^1.1.3" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/graceful-fs": { - "version": "4.2.11", - "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", - "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==", - "dev": true - }, - "node_modules/grapheme-splitter": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/grapheme-splitter/-/grapheme-splitter-1.0.4.tgz", - "integrity": "sha512-bzh50DW9kTPM00T8y4o8vQg89Di9oLJVLW/KaOGIXJWP/iqCN6WKYkbNOF04vFLJhwcpYUh9ydh/+5vpOqV4YQ==", - "dev": true - }, - "node_modules/hamt-sharding": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/hamt-sharding/-/hamt-sharding-3.0.2.tgz", - "integrity": "sha512-f0DzBD2tSmLFdFsLAvOflIBqFPjerbA7BfmwO8mVho/5hXwgyyYhv+ijIzidQf/DpDX3bRjAQvhGoBFj+DBvPw==", - "dependencies": { - "sparse-array": "^1.3.1", - "uint8arrays": "^4.0.2" - }, - "engines": { - "node": ">=16.0.0", - "npm": ">=7.0.0" - } - }, - "node_modules/has": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", - "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", - "dev": true, - "dependencies": { - "function-bind": "^1.1.1" - }, - "engines": { - "node": ">= 0.4.0" - } - }, - "node_modules/has-flag": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", - "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", - "dev": true, - "engines": { - "node": ">=8" - } - }, - "node_modules/has-property-descriptors": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.0.tgz", - "integrity": "sha512-62DVLZGoiEBDHQyqG4w9xCuZ7eJEwNmJRWw2VY84Oedb7WFcA27fiEVe8oUQx9hAUJ4ekurquucTGwsyO1XGdQ==", - "dev": true, - "dependencies": { - "get-intrinsic": "^1.1.1" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/has-proto": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/has-proto/-/has-proto-1.0.1.tgz", - "integrity": "sha512-7qE+iP+O+bgF9clE5+UoBFzE65mlBiVj3tKCrlNQ0Ogwm0BjpT/gK4SlLYDMybDh5I3TCTKnPPa0oMG7JDYrhg==", - "dev": true, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/has-symbols": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", - "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==", - "dev": true, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/has-tostringtag": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.0.tgz", - "integrity": "sha512-kFjcSNhnlGV1kyoGk7OXKSawH5JOb/LzUc5w9B02hOTO0dfFRjbHQKvg1d6cf3HbeUmtU9VbbV3qzZ2Teh97WQ==", - "dev": true, - "dependencies": { - "has-symbols": "^1.0.2" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/hash-base": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/hash-base/-/hash-base-3.1.0.tgz", - "integrity": "sha512-1nmYp/rhMDiE7AYkDw+lLwlAzz0AntGIe51F3RfFfEqyQ3feY2eI/NcwC6umIQVOASPMsWJLJScWKSSvzL9IVA==", - "dev": true, - "dependencies": { - "inherits": "^2.0.4", - "readable-stream": "^3.6.0", - "safe-buffer": "^5.2.0" - }, - "engines": { - "node": ">=4" - } - }, - "node_modules/hash-base/node_modules/readable-stream": { - "version": "3.6.2", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", - "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", - "dev": true, - "dependencies": { - "inherits": "^2.0.3", - "string_decoder": "^1.1.1", - "util-deprecate": "^1.0.1" - }, - "engines": { - "node": ">= 6" - } - }, - "node_modules/hash-base/node_modules/safe-buffer": { - "version": "5.2.1", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", - "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", - "dev": true, - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ] - }, - "node_modules/hash-wasm": { - "version": "4.9.0", - "resolved": "https://registry.npmjs.org/hash-wasm/-/hash-wasm-4.9.0.tgz", - "integrity": "sha512-7SW7ejyfnRxuOc7ptQHSf4LDoZaWOivfzqw+5rpcQku0nHfmicPKE51ra9BiRLAmT8+gGLestr1XroUkqdjL6w==" - }, - "node_modules/hash.js": { - "version": "1.1.7", - "resolved": "https://registry.npmjs.org/hash.js/-/hash.js-1.1.7.tgz", - "integrity": "sha512-taOaskGt4z4SOANNseOviYDvjEJinIkRgmp7LbKP2YTTmVxWBl87s/uzK9r+44BclBSp2X7K1hqeNfz9JbBeXA==", - "dev": true, - "dependencies": { - "inherits": "^2.0.3", - "minimalistic-assert": "^1.0.1" - } - }, - "node_modules/he": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz", - "integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==", - "dev": true, - "bin": { - "he": "bin/he" - } - }, - "node_modules/hmac-drbg": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/hmac-drbg/-/hmac-drbg-1.0.1.tgz", - "integrity": "sha512-Tti3gMqLdZfhOQY1Mzf/AanLiqh1WTiJgEj26ZuYQ9fbkLomzGchCws4FyrSd4VkpBfiNhaE1On+lOz894jvXg==", - "dev": true, - "dependencies": { - "hash.js": "^1.0.3", - "minimalistic-assert": "^1.0.0", - "minimalistic-crypto-utils": "^1.0.1" - } - }, - "node_modules/html-escaper": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/html-escaper/-/html-escaper-2.0.2.tgz", - "integrity": "sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==", - "dev": true - }, - "node_modules/http-errors": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.0.tgz", - "integrity": "sha512-FtwrG/euBzaEjYeRqOgly7G0qviiXoJWnvEH2Z1plBdXgbyjv34pHTSb9zoeHMyDy33+DWy5Wt9Wo+TURtOYSQ==", - "dev": true, - "dependencies": { - "depd": "2.0.0", - "inherits": "2.0.4", - "setprototypeof": "1.2.0", - "statuses": "2.0.1", - "toidentifier": "1.0.1" - }, - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/http-errors/node_modules/statuses": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz", - "integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==", - "dev": true, - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/http-proxy": { - "version": "1.18.1", - "resolved": "https://registry.npmjs.org/http-proxy/-/http-proxy-1.18.1.tgz", - "integrity": "sha512-7mz/721AbnJwIVbnaSv1Cz3Am0ZLT/UBwkC92VlxhXv/k/BBQfM2fXElQNC27BVGr0uwUpplYPQM9LnaBMR5NQ==", - "dev": true, - "dependencies": { - "eventemitter3": "^4.0.0", - "follow-redirects": "^1.0.0", - "requires-port": "^1.0.0" - }, - "engines": { - "node": ">=8.0.0" - } - }, - "node_modules/https-browserify": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/https-browserify/-/https-browserify-1.0.0.tgz", - "integrity": "sha512-J+FkSdyD+0mA0N+81tMotaRMfSL9SGi+xpD3T6YApKsc3bGSXJlfXri3VyFOeYkfLRQisDk1W+jIFFKBeUBbBg==", - "dev": true - }, - "node_modules/iconv-lite": { - "version": "0.4.24", - "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", - "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", - "dev": true, - "dependencies": { - "safer-buffer": ">= 2.1.2 < 3" - }, - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/ieee754": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", - "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ] - }, - "node_modules/ignore": { - "version": "5.2.4", - "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.2.4.tgz", - "integrity": "sha512-MAb38BcSbH0eHNBxn7ql2NH/kX33OkB3lZ1BNdh7ENeRChHTYsTvWrMubiIAMNS2llXEEgZ1MUOBtXChP3kaFQ==", - "dev": true, - "engines": { - "node": ">= 4" - } - }, - "node_modules/import-fresh": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.3.0.tgz", - "integrity": "sha512-veYYhQa+D1QBKznvhUHxb8faxlrwUnxseDAbAp457E0wLNio2bOSKnjYDhMj+YiAq61xrMGhQk9iXVk5FzgQMw==", - "dev": true, - "dependencies": { - "parent-module": "^1.0.0", - "resolve-from": "^4.0.0" - }, - "engines": { - "node": ">=6" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/imurmurhash": { - "version": "0.1.4", - "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", - "integrity": "sha512-JmXMZ6wuvDmLiHEml9ykzqO6lwFbof0GG4IkcGaENdCRDDmMVnny7s5HsIgHCbaq0w2MyPhDqkhTUgS2LU2PHA==", - "dev": true, - "engines": { - "node": ">=0.8.19" - } - }, - "node_modules/inflight": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", - "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==", - "dev": true, - "dependencies": { - "once": "^1.3.0", - "wrappy": "1" - } - }, - "node_modules/inherits": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", - "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" - }, - "node_modules/interface-blockstore": { - "version": "5.2.3", - "resolved": "https://registry.npmjs.org/interface-blockstore/-/interface-blockstore-5.2.3.tgz", - "integrity": "sha512-15cN+ZFdcVXdXo6I/SrSzFDsuJyDTyEI52XuvXQlR/G5fe3cK8p0tvVjfu5diRQH1XqNgmJEdMPixyt0xgjtvQ==", - "dependencies": { - "interface-store": "^5.0.0", - "multiformats": "^11.0.2" - }, - "engines": { - "node": ">=16.0.0", - "npm": ">=7.0.0" - } - }, - "node_modules/interface-store": { - "version": "5.1.2", - "resolved": "https://registry.npmjs.org/interface-store/-/interface-store-5.1.2.tgz", - "integrity": "sha512-q2sLoqC+UdaWnjwGyghsH0jwqqVk226lsG207e3QwPB8sAZYmYIWUnJwJH3JjFNNRV9e6CUTmm+gDO0Xg4KRiw==", - "engines": { - "node": ">=16.0.0", - "npm": ">=7.0.0" - } - }, - "node_modules/ipfs-unixfs": { - "version": "11.0.1", - "resolved": "https://registry.npmjs.org/ipfs-unixfs/-/ipfs-unixfs-11.0.1.tgz", - "integrity": "sha512-SD9dqn14bfgMfkPstsR/2Av3zCzYMj2ntQJab4HZucgX4nNV6K7guZh4Hf3kiL8ONff1Ogft1ekFU083DIKEdQ==", - "dependencies": { - "err-code": "^3.0.1", - "protons-runtime": "^5.0.0", - "uint8arraylist": "^2.4.3" - }, - "engines": { - "node": ">=16.0.0", - "npm": ">=7.0.0" - } - }, - "node_modules/ipfs-unixfs-exporter": { - "version": "13.1.5", - "resolved": "https://registry.npmjs.org/ipfs-unixfs-exporter/-/ipfs-unixfs-exporter-13.1.5.tgz", - "integrity": "sha512-O5aMawsHoe4DaYk5FFil2EPrNOaU3pkHC6qUR5JMnW7es93W3b/RjJoO7AyDL1rpb+M3K0oRu86Yc5wLNQQ8jg==", - "dependencies": { - "@ipld/dag-cbor": "^9.0.0", - "@ipld/dag-pb": "^4.0.0", - "@multiformats/murmur3": "^2.0.0", - "err-code": "^3.0.1", - "hamt-sharding": "^3.0.0", - "interface-blockstore": "^5.0.0", - "ipfs-unixfs": "^11.0.0", - "it-filter": "^3.0.2", - "it-last": "^3.0.2", - "it-map": "^3.0.3", - "it-parallel": "^3.0.0", - "it-pipe": "^3.0.1", - "it-pushable": "^3.1.0", - "multiformats": "^11.0.0", - "p-queue": "^7.3.0", - "progress-events": "^1.0.0", - "uint8arrays": "^4.0.2" - }, - "engines": { - "node": ">=16.0.0", - "npm": ">=7.0.0" - } - }, - "node_modules/ipfs-unixfs-importer": { - "version": "15.1.5", - "resolved": "https://registry.npmjs.org/ipfs-unixfs-importer/-/ipfs-unixfs-importer-15.1.5.tgz", - "integrity": "sha512-TXaOI0M5KNpq2+qLw8AIYd0Lnc0gWTKCBqUd9eErBUwaP3Fna4qauF+JX9Rj2UrwaOvG/1xbF8Vm+92eOcKWMA==", - "dependencies": { - "@ipld/dag-pb": "^4.0.0", - "@multiformats/murmur3": "^2.0.0", - "err-code": "^3.0.1", - "hamt-sharding": "^3.0.0", - "interface-blockstore": "^5.0.0", - "interface-store": "^5.0.1", - "ipfs-unixfs": "^11.0.0", - "it-all": "^3.0.2", - "it-batch": "^3.0.2", - "it-first": "^3.0.2", - "it-parallel-batch": "^3.0.1", - "multiformats": "^11.0.0", - "progress-events": "^1.0.0", - "rabin-wasm": "^0.1.4", - "uint8arraylist": "^2.4.3", - "uint8arrays": "^4.0.2" - }, - "engines": { - "node": ">=16.0.0", - "npm": ">=7.0.0" - } - }, - "node_modules/is-arguments": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/is-arguments/-/is-arguments-1.1.1.tgz", - "integrity": "sha512-8Q7EARjzEnKpt/PCD7e1cgUS0a6X8u5tdSiMqXhojOdoV9TsMsiO+9VLC5vAmO8N7/GmXn7yjR8qnA6bVAEzfA==", - "dev": true, - "dependencies": { - "call-bind": "^1.0.2", - "has-tostringtag": "^1.0.0" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/is-binary-path": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", - "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", - "dev": true, - "dependencies": { - "binary-extensions": "^2.0.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/is-buffer": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.5.tgz", - "integrity": "sha512-i2R6zNFDwgEHJyQUtJEk0XFi1i0dPFn/oqjK3/vPCcDeJvW5NQ83V8QbicfF1SupOaB0h8ntgBC2YiE7dfyctQ==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ], - "engines": { - "node": ">=4" - } - }, - "node_modules/is-callable": { - "version": "1.2.7", - "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.7.tgz", - "integrity": "sha512-1BC0BVFhS/p0qtw6enp8e+8OD0UrK0oFLztSjNzhcKA3WDuJxxAPXzPuPtKkjEY9UUoEWlX/8fgKeu2S8i9JTA==", - "dev": true, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/is-ci": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/is-ci/-/is-ci-3.0.1.tgz", - "integrity": "sha512-ZYvCgrefwqoQ6yTyYUbQu64HsITZ3NfKX1lzaEYdkTDcfKzzCI/wthRRYKkdjHKFVgNiXKAKm65Zo1pk2as/QQ==", - "dev": true, - "dependencies": { - "ci-info": "^3.2.0" - }, - "bin": { - "is-ci": "bin.js" - } - }, - "node_modules/is-core-module": { - "version": "2.12.1", - "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.12.1.tgz", - "integrity": "sha512-Q4ZuBAe2FUsKtyQJoQHlvP8OvBERxO3jEmy1I7hcRXcJBGGHFh/aJBswbXuS9sgrDH2QUO8ilkwNPHvHMd8clg==", - "dev": true, - "dependencies": { - "has": "^1.0.3" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/is-docker": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/is-docker/-/is-docker-2.2.1.tgz", - "integrity": "sha512-F+i2BKsFrH66iaUFc0woD8sLy8getkwTwtOBjvs56Cx4CgJDeKQeqfz8wAYiSb8JOprWhHH5p77PbmYCvvUuXQ==", - "dev": true, - "bin": { - "is-docker": "cli.js" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/is-extglob": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", - "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==", - "dev": true, - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/is-fullwidth-code-point": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", - "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", - "dev": true, - "engines": { - "node": ">=8" - } - }, - "node_modules/is-generator-function": { - "version": "1.0.10", - "resolved": "https://registry.npmjs.org/is-generator-function/-/is-generator-function-1.0.10.tgz", - "integrity": "sha512-jsEjy9l3yiXEQ+PsXdmBwEPcOxaXWLspKdplFUVI9vq1iZgIekeC0L167qeu86czQaxed3q/Uzuw0swL0irL8A==", - "dev": true, - "dependencies": { - "has-tostringtag": "^1.0.0" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/is-glob": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", - "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", - "dev": true, - "dependencies": { - "is-extglob": "^2.1.1" - }, - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/is-nan": { - "version": "1.3.2", - "resolved": "https://registry.npmjs.org/is-nan/-/is-nan-1.3.2.tgz", - "integrity": "sha512-E+zBKpQ2t6MEo1VsonYmluk9NxGrbzpeeLC2xIViuO2EjU2xsXsBPwTr3Ykv9l08UYEVEdWeRZNouaZqF6RN0w==", - "dev": true, - "dependencies": { - "call-bind": "^1.0.0", - "define-properties": "^1.1.3" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/is-number": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", - "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", - "dev": true, - "engines": { - "node": ">=0.12.0" - } - }, - "node_modules/is-path-inside": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/is-path-inside/-/is-path-inside-3.0.3.tgz", - "integrity": "sha512-Fd4gABb+ycGAmKou8eMftCupSir5lRxqf4aD/vd0cD2qc4HL07OjCeuHMr8Ro4CoMaeCKDB0/ECBOVWjTwUvPQ==", - "dev": true, - "engines": { - "node": ">=8" - } - }, - "node_modules/is-plain-obj": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-2.1.0.tgz", - "integrity": "sha512-YWnfyRwxL/+SsrWYfOpUtz5b3YD+nyfkHvjbcanzk8zgyO4ASD67uVMRt8k5bM4lLMDnXfriRhOpemw+NfT1eA==", - "dev": true, - "engines": { - "node": ">=8" - } - }, - "node_modules/is-typed-array": { - "version": "1.1.12", - "resolved": "https://registry.npmjs.org/is-typed-array/-/is-typed-array-1.1.12.tgz", - "integrity": "sha512-Z14TF2JNG8Lss5/HMqt0//T9JeHXttXy5pH/DBU4vi98ozO2btxzq9MwYDZYnKwU8nRsz/+GVFVRDq3DkVuSPg==", - "dev": true, - "dependencies": { - "which-typed-array": "^1.1.11" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/is-unicode-supported": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/is-unicode-supported/-/is-unicode-supported-0.1.0.tgz", - "integrity": "sha512-knxG2q4UC3u8stRGyAVJCOdxFmv5DZiRcdlIaAQXAbSfJya+OhopNotLQrstBhququ4ZpuKbDc/8S6mgXgPFPw==", - "dev": true, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/is-wsl": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/is-wsl/-/is-wsl-2.2.0.tgz", - "integrity": "sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww==", - "dev": true, - "dependencies": { - "is-docker": "^2.0.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/isarray": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", - "integrity": "sha512-D2S+3GLxWH+uhrNEcoh/fnmYeP8E8/zHl644d/jdA0g2uyXvy3sb0qxotE+ne0LtccHknQzWwZEzhak7oJ0COQ==", - "dev": true - }, - "node_modules/isbinaryfile": { - "version": "4.0.10", - "resolved": "https://registry.npmjs.org/isbinaryfile/-/isbinaryfile-4.0.10.tgz", - "integrity": "sha512-iHrqe5shvBUcFbmZq9zOQHBoeOhZJu6RQGrDpBgenUm/Am+F3JM2MgQj+rK3Z601fzrL5gLZWtAPH2OBaSVcyw==", - "dev": true, - "engines": { - "node": ">= 8.0.0" - }, - "funding": { - "url": "https://github.com/sponsors/gjtorikian/" - } - }, - "node_modules/isexe": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", - "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", - "dev": true - }, - "node_modules/isomorphic-timers-promises": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/isomorphic-timers-promises/-/isomorphic-timers-promises-1.0.1.tgz", - "integrity": "sha512-u4sej9B1LPSxTGKB/HiuzvEQnXH0ECYkSVQU39koSwmFAxhlEAFl9RdTvLv4TOTQUgBS5O3O5fwUxk6byBZ+IQ==", - "dev": true, - "engines": { - "node": ">=10" - } - }, - "node_modules/istanbul-lib-coverage": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/istanbul-lib-coverage/-/istanbul-lib-coverage-3.2.0.tgz", - "integrity": "sha512-eOeJ5BHCmHYvQK7xt9GkdHuzuCGS1Y6g9Gvnx3Ym33fz/HpLRYxiS0wHNr+m/MBC8B647Xt608vCDEvhl9c6Mw==", - "dev": true, - "engines": { - "node": ">=8" - } - }, - "node_modules/istanbul-lib-report": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/istanbul-lib-report/-/istanbul-lib-report-3.0.1.tgz", - "integrity": "sha512-GCfE1mtsHGOELCU8e/Z7YWzpmybrx/+dSTfLrvY8qRmaY6zXTKWn6WQIjaAFw069icm6GVMNkgu0NzI4iPZUNw==", - "dev": true, - "dependencies": { - "istanbul-lib-coverage": "^3.0.0", - "make-dir": "^4.0.0", - "supports-color": "^7.1.0" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/istanbul-reports": { - "version": "3.1.6", - "resolved": "https://registry.npmjs.org/istanbul-reports/-/istanbul-reports-3.1.6.tgz", - "integrity": "sha512-TLgnMkKg3iTDsQ9PbPTdpfAK2DzjF9mqUG7RMgcQl8oFjad8ob4laGxv5XV5U9MAfx8D6tSJiUyuAwzLicaxlg==", - "dev": true, - "dependencies": { - "html-escaper": "^2.0.0", - "istanbul-lib-report": "^3.0.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/it-all": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/it-all/-/it-all-3.0.2.tgz", - "integrity": "sha512-ujqWETXhsDbF6C+6X6fvRw5ohlowRoy/o/h9BC8D+R3JQ13oLQ153w9gSWkWupOY7omZFQbJiAL1aJo5Gwe2yw==", - "engines": { - "node": ">=16.0.0", - "npm": ">=7.0.0" - } - }, - "node_modules/it-batch": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/it-batch/-/it-batch-3.0.2.tgz", - "integrity": "sha512-Ypepz/vCxNFOvFkUPFvoxGb8WzqainzhflRaJahp1MBo3Y42ICdrgR3xIwOFE6WAgO+UWUM0zeMlbUStsW9AIQ==", - "engines": { - "node": ">=16.0.0", - "npm": ">=7.0.0" - } - }, - "node_modules/it-filter": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/it-filter/-/it-filter-3.0.2.tgz", - "integrity": "sha512-Hhzp5anX7tmKOBqTPasBYTPlq7l4Xk4lMBfLB5GfKZnL9WCc6pr8M9Waud4nHh3s9neb4xwDWk7KQsEapgWyJw==", - "dependencies": { - "it-peekable": "^3.0.0" - }, - "engines": { - "node": ">=16.0.0", - "npm": ">=7.0.0" - } - }, - "node_modules/it-first": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/it-first/-/it-first-3.0.2.tgz", - "integrity": "sha512-QPLAM2BOkait/o6W25HvP0XTEv+Os3Ce4wET//ADNaPv+WYAHWfQwJuMu5FB8X066hA1F7LEMnULvTpE7/4yQw==", - "engines": { - "node": ">=16.0.0", - "npm": ">=7.0.0" - } - }, - "node_modules/it-last": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/it-last/-/it-last-3.0.2.tgz", - "integrity": "sha512-aWoA5moJ7XSKe7+YuutBKhySroDDWkfjpo+UknekPh1M5YYdK4YNSPDarR+7o/NqRwzazwgzCi2UZzU0oqsprQ==", - "engines": { - "node": ">=16.0.0", - "npm": ">=7.0.0" - } - }, - "node_modules/it-map": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/it-map/-/it-map-3.0.3.tgz", - "integrity": "sha512-Yf89GJYeYUZb2NZzWkvFHm3IBXlxro74i2vGRmpf8BYau3BhlaS37ieDenJEdYzkTGJhL/EbM1jPPw/KGVVVIw==", - "dependencies": { - "it-peekable": "^3.0.0" - }, - "engines": { - "node": ">=16.0.0", - "npm": ">=7.0.0" - } - }, - "node_modules/it-merge": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/it-merge/-/it-merge-3.0.1.tgz", - "integrity": "sha512-I6hjU1ABO+k3xY1H6JtCSDXvUME88pxIXSgKeT4WI5rPYbQzpr98ldacVuG95WbjaJxKl6Qot6lUdxduLBQPHA==", - "dependencies": { - "it-pushable": "^3.1.0" - }, - "engines": { - "node": ">=16.0.0", - "npm": ">=7.0.0" - } - }, - "node_modules/it-parallel": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/it-parallel/-/it-parallel-3.0.3.tgz", - "integrity": "sha512-Q5KmdvERHCOLDcgKqrzQ+yiMCdG6H9h7ZL3Zjx/Tx9xhZy8txSKoy+EiCgWZFs0rfYvxJhk6UkOpKLzJ1zM9ZA==", - "dependencies": { - "p-defer": "^4.0.0" - }, - "engines": { - "node": ">=16.0.0", - "npm": ">=7.0.0" - } - }, - "node_modules/it-parallel-batch": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/it-parallel-batch/-/it-parallel-batch-3.0.1.tgz", - "integrity": "sha512-4KTvYVYpCdrYUrAHSeH6o5hnHuDVHWzB8TztV/hdckUZzZIjbax4kVblmnzoYREX8Huj5+50irBu7b+c8jyKQg==", - "dependencies": { - "it-batch": "^3.0.0" - }, - "engines": { - "node": ">=16.0.0", - "npm": ">=7.0.0" - } - }, - "node_modules/it-peekable": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/it-peekable/-/it-peekable-3.0.1.tgz", - "integrity": "sha512-5zBfkf6e+YoxxWV0YDXMwdQKnc7eeTX6xo3WYPm/8dIoctIiDnddInRWOW+83W/8/76sbnpWqqsO4gSyXandeQ==", - "engines": { - "node": ">=16.0.0", - "npm": ">=7.0.0" - } - }, - "node_modules/it-pipe": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/it-pipe/-/it-pipe-3.0.1.tgz", - "integrity": "sha512-sIoNrQl1qSRg2seYSBH/3QxWhJFn9PKYvOf/bHdtCBF0bnghey44VyASsWzn5dAx0DCDDABq1hZIuzKmtBZmKA==", - "dependencies": { - "it-merge": "^3.0.0", - "it-pushable": "^3.1.2", - "it-stream-types": "^2.0.1" - }, - "engines": { - "node": ">=16.0.0", - "npm": ">=7.0.0" - } - }, - "node_modules/it-pushable": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/it-pushable/-/it-pushable-3.2.1.tgz", - "integrity": "sha512-sLFz2Q0oyDCJpTciZog7ipP4vSftfPy3e6JnH6YyztRa1XqkpGQaafK3Jw/JlfEBtCXfnX9uVfcpu3xpSAqCVQ==", - "dependencies": { - "p-defer": "^4.0.0" - }, - "engines": { - "node": ">=16.0.0", - "npm": ">=7.0.0" - } - }, - "node_modules/it-stream-types": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/it-stream-types/-/it-stream-types-2.0.1.tgz", - "integrity": "sha512-6DmOs5r7ERDbvS4q8yLKENcj6Yecr7QQTqWApbZdfAUTEC947d+PEha7PCqhm//9oxaLYL7TWRekwhoXl2s6fg==", - "engines": { - "node": ">=16.0.0", - "npm": ">=7.0.0" - } - }, - "node_modules/jest-worker": { - "version": "27.5.1", - "resolved": "https://registry.npmjs.org/jest-worker/-/jest-worker-27.5.1.tgz", - "integrity": "sha512-7vuh85V5cdDofPyxn58nrPjBktZo0u9x1g8WtjQol+jZDaE+fhN+cIvTj11GndBnMnyfrUOG1sZQxCdjKh+DKg==", - "dev": true, - "peer": true, - "dependencies": { - "@types/node": "*", - "merge-stream": "^2.0.0", - "supports-color": "^8.0.0" - }, - "engines": { - "node": ">= 10.13.0" - } - }, - "node_modules/jest-worker/node_modules/supports-color": { - "version": "8.1.1", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz", - "integrity": "sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==", - "dev": true, - "peer": true, - "dependencies": { - "has-flag": "^4.0.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/chalk/supports-color?sponsor=1" - } - }, - "node_modules/js-sdsl": { - "version": "4.4.2", - "resolved": "https://registry.npmjs.org/js-sdsl/-/js-sdsl-4.4.2.tgz", - "integrity": "sha512-dwXFwByc/ajSV6m5bcKAPwe4yDDF6D614pxmIi5odytzxRlwqF6nwoiCek80Ixc7Cvma5awClxrzFtxCQvcM8w==", - "dev": true, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/js-sdsl" - } - }, - "node_modules/js-yaml": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", - "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", - "dev": true, - "dependencies": { - "argparse": "^2.0.1" - }, - "bin": { - "js-yaml": "bin/js-yaml.js" - } - }, - "node_modules/jsbi": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/jsbi/-/jsbi-4.3.0.tgz", - "integrity": "sha512-SnZNcinB4RIcnEyZqFPdGPVgrg2AcnykiBy0sHVJQKHYeaLUvi3Exj+iaPpLnFVkDPZIV4U0yvgC9/R4uEAZ9g==" - }, - "node_modules/json-parse-even-better-errors": { - "version": "2.3.1", - "resolved": "https://registry.npmjs.org/json-parse-even-better-errors/-/json-parse-even-better-errors-2.3.1.tgz", - "integrity": "sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w==", - "dev": true, - "peer": true - }, - "node_modules/json-schema-traverse": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", - "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==" - }, - "node_modules/json-stable-stringify-without-jsonify": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz", - "integrity": "sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==", - "dev": true - }, - "node_modules/jsonfile": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", - "integrity": "sha512-m6F1R3z8jjlf2imQHS2Qez5sjKWQzbuuhuJ/FKYFRZvPE3PuHcSMVZzfsLhGVOkfd20obL5SWEBew5ShlquNxg==", - "dev": true, - "optionalDependencies": { - "graceful-fs": "^4.1.6" - } - }, - "node_modules/just-extend": { - "version": "4.2.1", - "resolved": "https://registry.npmjs.org/just-extend/-/just-extend-4.2.1.tgz", - "integrity": "sha512-g3UB796vUFIY90VIv/WX3L2c8CS2MdWUww3CNrYmqza1Fg0DURc2K/O4YrnklBdQarSJ/y8JnJYDGc+1iumQjg==", - "dev": true - }, - "node_modules/karma": { - "version": "6.4.1", - "resolved": "https://registry.npmjs.org/karma/-/karma-6.4.1.tgz", - "integrity": "sha512-Cj57NKOskK7wtFWSlMvZf459iX+kpYIPXmkNUzP2WAFcA7nhr/ALn5R7sw3w+1udFDcpMx/tuB8d5amgm3ijaA==", - "dev": true, - "dependencies": { - "@colors/colors": "1.5.0", - "body-parser": "^1.19.0", - "braces": "^3.0.2", - "chokidar": "^3.5.1", - "connect": "^3.7.0", - "di": "^0.0.1", - "dom-serialize": "^2.2.1", - "glob": "^7.1.7", - "graceful-fs": "^4.2.6", - "http-proxy": "^1.18.1", - "isbinaryfile": "^4.0.8", - "lodash": "^4.17.21", - "log4js": "^6.4.1", - "mime": "^2.5.2", - "minimatch": "^3.0.4", - "mkdirp": "^0.5.5", - "qjobs": "^1.2.0", - "range-parser": "^1.2.1", - "rimraf": "^3.0.2", - "socket.io": "^4.4.1", - "source-map": "^0.6.1", - "tmp": "^0.2.1", - "ua-parser-js": "^0.7.30", - "yargs": "^16.1.1" - }, - "bin": { - "karma": "bin/karma" - }, - "engines": { - "node": ">= 10" - } - }, - "node_modules/karma-chai": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/karma-chai/-/karma-chai-0.1.0.tgz", - "integrity": "sha512-mqKCkHwzPMhgTYca10S90aCEX9+HjVjjrBFAsw36Zj7BlQNbokXXCAe6Ji04VUMsxcY5RLP7YphpfO06XOubdg==", - "dev": true, - "peerDependencies": { - "chai": "*", - "karma": ">=0.10.9" - } - }, - "node_modules/karma-chrome-launcher": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/karma-chrome-launcher/-/karma-chrome-launcher-3.1.1.tgz", - "integrity": "sha512-hsIglcq1vtboGPAN+DGCISCFOxW+ZVnIqhDQcCMqqCp+4dmJ0Qpq5QAjkbA0X2L9Mi6OBkHi2Srrbmm7pUKkzQ==", - "dev": true, - "dependencies": { - "which": "^1.2.1" - } - }, - "node_modules/karma-chrome-launcher/node_modules/which": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", - "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==", - "dev": true, - "dependencies": { - "isexe": "^2.0.0" - }, - "bin": { - "which": "bin/which" - } - }, - "node_modules/karma-esbuild": { - "version": "2.2.5", - "resolved": "https://registry.npmjs.org/karma-esbuild/-/karma-esbuild-2.2.5.tgz", - "integrity": "sha512-+NiRmZhUm/MqOsL1cAu8+RmiOMvIxWDaeYDLBB5upxHF9Hh3Og8YH43EAmDan40pxt2FKDcOjupgqIe4Tx2szQ==", - "dev": true, - "dependencies": { - "chokidar": "^3.5.1", - "source-map": "0.6.1" - }, - "peerDependencies": { - "esbuild": ">=0.8.45" - } - }, - "node_modules/karma-firefox-launcher": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/karma-firefox-launcher/-/karma-firefox-launcher-2.1.2.tgz", - "integrity": "sha512-VV9xDQU1QIboTrjtGVD4NCfzIH7n01ZXqy/qpBhnOeGVOkG5JYPEm8kuSd7psHE6WouZaQ9Ool92g8LFweSNMA==", - "dev": true, - "dependencies": { - "is-wsl": "^2.2.0", - "which": "^2.0.1" - } - }, - "node_modules/karma-mocha": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/karma-mocha/-/karma-mocha-2.0.1.tgz", - "integrity": "sha512-Tzd5HBjm8his2OA4bouAsATYEpZrp9vC7z5E5j4C5Of5Rrs1jY67RAwXNcVmd/Bnk1wgvQRou0zGVLey44G4tQ==", - "dev": true, - "dependencies": { - "minimist": "^1.2.3" - } - }, - "node_modules/karma-mocha-reporter": { - "version": "2.2.5", - "resolved": "https://registry.npmjs.org/karma-mocha-reporter/-/karma-mocha-reporter-2.2.5.tgz", - "integrity": "sha512-Hr6nhkIp0GIJJrvzY8JFeHpQZNseuIakGac4bpw8K1+5F0tLb6l7uvXRa8mt2Z+NVwYgCct4QAfp2R2QP6o00w==", - "dev": true, - "dependencies": { - "chalk": "^2.1.0", - "log-symbols": "^2.1.0", - "strip-ansi": "^4.0.0" - }, - "peerDependencies": { - "karma": ">=0.13" - } - }, - "node_modules/karma-mocha-reporter/node_modules/ansi-regex": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.1.tgz", - "integrity": "sha512-+O9Jct8wf++lXxxFc4hc8LsjaSq0HFzzL7cVsw8pRDIPdjKD2mT4ytDZlLuSBZ4cLKZFXIrMGO7DbQCtMJJMKw==", - "dev": true, - "engines": { - "node": ">=4" - } - }, - "node_modules/karma-mocha-reporter/node_modules/ansi-styles": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", - "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", - "dev": true, - "dependencies": { - "color-convert": "^1.9.0" - }, - "engines": { - "node": ">=4" - } - }, - "node_modules/karma-mocha-reporter/node_modules/chalk": { - "version": "2.4.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", - "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", - "dev": true, - "dependencies": { - "ansi-styles": "^3.2.1", - "escape-string-regexp": "^1.0.5", - "supports-color": "^5.3.0" - }, - "engines": { - "node": ">=4" - } - }, - "node_modules/karma-mocha-reporter/node_modules/color-convert": { - "version": "1.9.3", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", - "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", - "dev": true, - "dependencies": { - "color-name": "1.1.3" - } - }, - "node_modules/karma-mocha-reporter/node_modules/color-name": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", - "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==", - "dev": true - }, - "node_modules/karma-mocha-reporter/node_modules/escape-string-regexp": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", - "integrity": "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==", - "dev": true, - "engines": { - "node": ">=0.8.0" - } - }, - "node_modules/karma-mocha-reporter/node_modules/has-flag": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", - "integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==", - "dev": true, - "engines": { - "node": ">=4" - } - }, - "node_modules/karma-mocha-reporter/node_modules/strip-ansi": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", - "integrity": "sha512-4XaJ2zQdCzROZDivEVIDPkcQn8LMFSa8kj8Gxb/Lnwzv9A8VctNZ+lfivC/sV3ivW8ElJTERXZoPBRrZKkNKow==", - "dev": true, - "dependencies": { - "ansi-regex": "^3.0.0" - }, - "engines": { - "node": ">=4" - } - }, - "node_modules/karma-mocha-reporter/node_modules/supports-color": { - "version": "5.5.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", - "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", - "dev": true, - "dependencies": { - "has-flag": "^3.0.0" - }, - "engines": { - "node": ">=4" - } - }, - "node_modules/karma-webkit-launcher": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/karma-webkit-launcher/-/karma-webkit-launcher-2.1.0.tgz", - "integrity": "sha512-S5eqhH0DIcuJFi27nC6eBxZ3MTrPnYybPthDU2Q8dfG0yFrXx8FqNDKSbRZsFFvAKJ55QVtYH1bbArd3ddI5Sg==", - "dev": true, - "dependencies": { - "is-ci": "^3.0.1", - "uuid": "^9.0.0" - }, - "peerDependenciesMeta": { - "playwright": { - "optional": true - } - } - }, - "node_modules/karma/node_modules/rimraf": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", - "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", - "dev": true, - "dependencies": { - "glob": "^7.1.3" - }, - "bin": { - "rimraf": "bin.js" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, - "node_modules/level": { - "version": "8.0.0", - "resolved": "https://registry.npmjs.org/level/-/level-8.0.0.tgz", - "integrity": "sha512-ypf0jjAk2BWI33yzEaaotpq7fkOPALKAgDBxggO6Q9HGX2MRXn0wbP1Jn/tJv1gtL867+YOjOB49WaUF3UoJNQ==", - "dependencies": { - "browser-level": "^1.0.1", - "classic-level": "^1.2.0" - }, - "engines": { - "node": ">=12" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/level" - } - }, - "node_modules/level-supports": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/level-supports/-/level-supports-4.0.1.tgz", - "integrity": "sha512-PbXpve8rKeNcZ9C1mUicC9auIYFyGpkV9/i6g76tLgANwWhtG2v7I4xNBUlkn3lE2/dZF3Pi0ygYGtLc4RXXdA==", - "engines": { - "node": ">=12" - } - }, - "node_modules/level-transcoder": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/level-transcoder/-/level-transcoder-1.0.1.tgz", - "integrity": "sha512-t7bFwFtsQeD8cl8NIoQ2iwxA0CL/9IFw7/9gAjOonH0PWTTiRfY7Hq+Ejbsxh86tXobDQ6IOiddjNYIfOBs06w==", - "dependencies": { - "buffer": "^6.0.3", - "module-error": "^1.0.1" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/levn": { - "version": "0.4.1", - "resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz", - "integrity": "sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==", - "dev": true, - "dependencies": { - "prelude-ls": "^1.2.1", - "type-check": "~0.4.0" - }, - "engines": { - "node": ">= 0.8.0" - } - }, - "node_modules/loader-runner": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/loader-runner/-/loader-runner-4.3.0.tgz", - "integrity": "sha512-3R/1M+yS3j5ou80Me59j7F9IMs4PXs3VqRrm0TU3AbKPxlmpoY1TNscJV/oGJXo8qCatFGTfDbY6W6ipGOYXfg==", - "dev": true, - "peer": true, - "engines": { - "node": ">=6.11.5" - } - }, - "node_modules/locate-path": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz", - "integrity": "sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==", - "dev": true, - "dependencies": { - "p-locate": "^5.0.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/lodash": { - "version": "4.17.21", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", - "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" - }, - "node_modules/lodash.get": { - "version": "4.4.2", - "resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz", - "integrity": "sha512-z+Uw/vLuy6gQe8cfaFWD7p0wVv8fJl3mbzXh33RS+0oW2wvUqiRXiQ69gLWSLpgB5/6sU+r6BlQR0MBILadqTQ==", - "dev": true - }, - "node_modules/lodash.merge": { - "version": "4.6.2", - "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", - "integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==", - "dev": true - }, - "node_modules/log-symbols": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-2.2.0.tgz", - "integrity": "sha512-VeIAFslyIerEJLXHziedo2basKbMKtTw3vfn5IzG0XTjhAVEJyNHnL2p7vc+wBDSdQuUpNw3M2u6xb9QsAY5Eg==", - "dev": true, - "dependencies": { - "chalk": "^2.0.1" - }, - "engines": { - "node": ">=4" - } - }, - "node_modules/log-symbols/node_modules/ansi-styles": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", - "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", - "dev": true, - "dependencies": { - "color-convert": "^1.9.0" - }, - "engines": { - "node": ">=4" - } - }, - "node_modules/log-symbols/node_modules/chalk": { - "version": "2.4.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", - "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", - "dev": true, - "dependencies": { - "ansi-styles": "^3.2.1", - "escape-string-regexp": "^1.0.5", - "supports-color": "^5.3.0" - }, - "engines": { - "node": ">=4" - } - }, - "node_modules/log-symbols/node_modules/color-convert": { - "version": "1.9.3", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", - "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", - "dev": true, - "dependencies": { - "color-name": "1.1.3" - } - }, - "node_modules/log-symbols/node_modules/color-name": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", - "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==", - "dev": true - }, - "node_modules/log-symbols/node_modules/escape-string-regexp": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", - "integrity": "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==", - "dev": true, - "engines": { - "node": ">=0.8.0" - } - }, - "node_modules/log-symbols/node_modules/has-flag": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", - "integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==", - "dev": true, - "engines": { - "node": ">=4" - } - }, - "node_modules/log-symbols/node_modules/supports-color": { - "version": "5.5.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", - "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", - "dev": true, - "dependencies": { - "has-flag": "^3.0.0" - }, - "engines": { - "node": ">=4" - } - }, - "node_modules/log4js": { - "version": "6.9.1", - "resolved": "https://registry.npmjs.org/log4js/-/log4js-6.9.1.tgz", - "integrity": "sha512-1somDdy9sChrr9/f4UlzhdaGfDR2c/SaD2a4T7qEkG4jTS57/B3qmnjLYePwQ8cqWnUHZI0iAKxMBpCZICiZ2g==", - "dev": true, - "dependencies": { - "date-format": "^4.0.14", - "debug": "^4.3.4", - "flatted": "^3.2.7", - "rfdc": "^1.3.0", - "streamroller": "^3.1.5" - }, - "engines": { - "node": ">=8.0" - } - }, - "node_modules/long": { - "version": "5.2.3", - "resolved": "https://registry.npmjs.org/long/-/long-5.2.3.tgz", - "integrity": "sha512-lcHwpNoggQTObv5apGNCTdJrO69eHOZMi4BNC+rTLER8iHAqGrUVeLh/irVIM7zTw2bOXA8T6uNPeujwOLg/2Q==" - }, - "node_modules/loupe": { - "version": "2.3.6", - "resolved": "https://registry.npmjs.org/loupe/-/loupe-2.3.6.tgz", - "integrity": "sha512-RaPMZKiMy8/JruncMU5Bt6na1eftNoo++R4Y+N2FrxkDVTrGvcyzFTsaGif4QTeKESheMGegbhw6iUAq+5A8zA==", - "dependencies": { - "get-func-name": "^2.0.0" - } - }, - "node_modules/lru-cache": { - "version": "9.1.2", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-9.1.2.tgz", - "integrity": "sha512-ERJq3FOzJTxBbFjZ7iDs+NiK4VI9Wz+RdrrAB8dio1oV+YvdPzUEE4QNiT2VD51DkIbCYRUUzCRkssXCHqSnKQ==", - "engines": { - "node": "14 || >=16.14" - } - }, - "node_modules/make-dir": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-4.0.0.tgz", - "integrity": "sha512-hXdUTZYIVOt1Ex//jAQi+wTZZpUpwBj/0QsOzqegb3rGMMeJiSEu5xLHnYfBrRV4RH2+OCSOO95Is/7x1WJ4bw==", - "dev": true, - "dependencies": { - "semver": "^7.5.3" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/md5.js": { - "version": "1.3.5", - "resolved": "https://registry.npmjs.org/md5.js/-/md5.js-1.3.5.tgz", - "integrity": "sha512-xitP+WxNPcTTOgnTJcrhM0xvdPepipPSf3I8EIpGKeFLjt3PlJLIDG3u8EX53ZIubkb+5U2+3rELYpEhHhzdkg==", - "dev": true, - "dependencies": { - "hash-base": "^3.0.0", - "inherits": "^2.0.1", - "safe-buffer": "^5.1.2" - } - }, - "node_modules/media-typer": { - "version": "0.3.0", - "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", - "integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==", - "dev": true, - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/merge-stream": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz", - "integrity": "sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==", - "dev": true, - "peer": true - }, - "node_modules/merge2": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz", - "integrity": "sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==", - "dev": true, - "engines": { - "node": ">= 8" - } - }, - "node_modules/micromatch": { - "version": "4.0.5", - "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.5.tgz", - "integrity": "sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==", - "dev": true, - "dependencies": { - "braces": "^3.0.2", - "picomatch": "^2.3.1" - }, - "engines": { - "node": ">=8.6" - } - }, - "node_modules/miller-rabin": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/miller-rabin/-/miller-rabin-4.0.1.tgz", - "integrity": "sha512-115fLhvZVqWwHPbClyntxEVfVDfl9DLLTuJvq3g2O/Oxi8AiNouAHvDSzHS0viUJc+V5vm3eq91Xwqn9dp4jRA==", - "dev": true, - "dependencies": { - "bn.js": "^4.0.0", - "brorand": "^1.0.1" - }, - "bin": { - "miller-rabin": "bin/miller-rabin" - } - }, - "node_modules/miller-rabin/node_modules/bn.js": { - "version": "4.12.0", - "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.12.0.tgz", - "integrity": "sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA==", - "dev": true - }, - "node_modules/mime": { - "version": "2.6.0", - "resolved": "https://registry.npmjs.org/mime/-/mime-2.6.0.tgz", - "integrity": "sha512-USPkMeET31rOMiarsBNIHZKLGgvKc/LrjofAnBlOttf5ajRvqiRA8QsenbcooctK6d6Ts6aqZXBA+XbkKthiQg==", - "dev": true, - "bin": { - "mime": "cli.js" - }, - "engines": { - "node": ">=4.0.0" - } - }, - "node_modules/mime-db": { - "version": "1.52.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", - "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", - "dev": true, - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/mime-types": { - "version": "2.1.35", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", - "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", - "dev": true, - "dependencies": { - "mime-db": "1.52.0" - }, - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/minimalistic-assert": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/minimalistic-assert/-/minimalistic-assert-1.0.1.tgz", - "integrity": "sha512-UtJcAD4yEaGtjPezWuO9wC4nwUnVH/8/Im3yEHQP4b67cXlD/Qr9hdITCU1xDbSEXg2XKNaP8jsReV7vQd00/A==", - "dev": true - }, - "node_modules/minimalistic-crypto-utils": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/minimalistic-crypto-utils/-/minimalistic-crypto-utils-1.0.1.tgz", - "integrity": "sha512-JIYlbt6g8i5jKfJ3xz7rF0LXmv2TkDxBLUkiBeZ7bAx4GnnNMr8xFpGnOxn6GhTEHx3SjRrZEoU+j04prX1ktg==", - "dev": true - }, - "node_modules/minimatch": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", - "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", - "dev": true, - "dependencies": { - "brace-expansion": "^1.1.7" - }, - "engines": { - "node": "*" - } - }, - "node_modules/minimist": { - "version": "1.2.8", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", - "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/minipass": { - "version": "4.2.8", - "resolved": "https://registry.npmjs.org/minipass/-/minipass-4.2.8.tgz", - "integrity": "sha512-fNzuVyifolSLFL4NzpF+wEF4qrgqaaKX0haXPQEdQ7NKAN+WecoKMHV09YcuL/DHxrUsYQOK3MiuDf7Ip2OXfQ==", - "dev": true, - "engines": { - "node": ">=8" - } - }, - "node_modules/mkdirp": { - "version": "0.5.6", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz", - "integrity": "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==", - "dev": true, - "dependencies": { - "minimist": "^1.2.6" - }, - "bin": { - "mkdirp": "bin/cmd.js" - } - }, - "node_modules/mocha": { - "version": "10.2.0", - "resolved": "https://registry.npmjs.org/mocha/-/mocha-10.2.0.tgz", - "integrity": "sha512-IDY7fl/BecMwFHzoqF2sg/SHHANeBoMMXFlS9r0OXKDssYE1M5O43wUY/9BVPeIvfH2zmEbBfseqN9gBQZzXkg==", - "dev": true, - "dependencies": { - "ansi-colors": "4.1.1", - "browser-stdout": "1.3.1", - "chokidar": "3.5.3", - "debug": "4.3.4", - "diff": "5.0.0", - "escape-string-regexp": "4.0.0", - "find-up": "5.0.0", - "glob": "7.2.0", - "he": "1.2.0", - "js-yaml": "4.1.0", - "log-symbols": "4.1.0", - "minimatch": "5.0.1", - "ms": "2.1.3", - "nanoid": "3.3.3", - "serialize-javascript": "6.0.0", - "strip-json-comments": "3.1.1", - "supports-color": "8.1.1", - "workerpool": "6.2.1", - "yargs": "16.2.0", - "yargs-parser": "20.2.4", - "yargs-unparser": "2.0.0" - }, - "bin": { - "_mocha": "bin/_mocha", - "mocha": "bin/mocha.js" - }, - "engines": { - "node": ">= 14.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/mochajs" - } - }, - "node_modules/mocha/node_modules/glob": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.0.tgz", - "integrity": "sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q==", - "dev": true, - "dependencies": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^3.0.4", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" - }, - "engines": { - "node": "*" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, - "node_modules/mocha/node_modules/glob/node_modules/minimatch": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", - "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", - "dev": true, - "dependencies": { - "brace-expansion": "^1.1.7" - }, - "engines": { - "node": "*" - } - }, - "node_modules/mocha/node_modules/log-symbols": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-4.1.0.tgz", - "integrity": "sha512-8XPvpAA8uyhfteu8pIvQxpJZ7SYYdpUivZpGy6sFsBuKRY/7rQGavedeB8aK+Zkyq6upMFVL/9AW6vOYzfRyLg==", - "dev": true, - "dependencies": { - "chalk": "^4.1.0", - "is-unicode-supported": "^0.1.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/mocha/node_modules/minimatch": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.0.1.tgz", - "integrity": "sha512-nLDxIFRyhDblz3qMuq+SoRZED4+miJ/G+tdDrjkkkRnjAsBexeGpgjLEQ0blJy7rHhR2b93rhQY4SvyWu9v03g==", - "dev": true, - "dependencies": { - "brace-expansion": "^2.0.1" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/mocha/node_modules/minimatch/node_modules/brace-expansion": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", - "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", - "dev": true, - "dependencies": { - "balanced-match": "^1.0.0" - } - }, - "node_modules/mocha/node_modules/supports-color": { - "version": "8.1.1", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz", - "integrity": "sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==", - "dev": true, - "dependencies": { - "has-flag": "^4.0.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/chalk/supports-color?sponsor=1" - } - }, - "node_modules/mocha/node_modules/yargs-parser": { - "version": "20.2.4", - "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-20.2.4.tgz", - "integrity": "sha512-WOkpgNhPTlE73h4VFAFsOnomJVaovO8VqLDzy5saChRBFQFBoMYirowyW+Q9HB4HFF4Z7VZTiG3iSzJJA29yRA==", - "dev": true, - "engines": { - "node": ">=10" - } - }, - "node_modules/module-error": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/module-error/-/module-error-1.0.2.tgz", - "integrity": "sha512-0yuvsqSCv8LbaOKhnsQ/T5JhyFlCYLPXK3U2sgV10zoKQwzs/MyfuQUOZQ1V/6OCOJsK/TRgNVrPuPDqtdMFtA==", - "engines": { - "node": ">=10" - } - }, - "node_modules/ms": { - "version": "2.1.3", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", - "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" - }, - "node_modules/multibase": { - "version": "4.0.6", - "resolved": "https://registry.npmjs.org/multibase/-/multibase-4.0.6.tgz", - "integrity": "sha512-x23pDe5+svdLz/k5JPGCVdfn7Q5mZVMBETiC+ORfO+sor9Sgs0smJzAjfTbM5tckeCqnaUuMYoz+k3RXMmJClQ==", - "deprecated": "This module has been superseded by the multiformats module", - "dependencies": { - "@multiformats/base-x": "^4.0.1" - }, - "engines": { - "node": ">=12.0.0", - "npm": ">=6.0.0" - } - }, - "node_modules/multiformats": { - "version": "11.0.2", - "resolved": "https://registry.npmjs.org/multiformats/-/multiformats-11.0.2.tgz", - "integrity": "sha512-b5mYMkOkARIuVZCpvijFj9a6m5wMVLC7cf/jIPd5D/ARDOfLC5+IFkbgDXQgcU2goIsTD/O9NY4DI/Mt4OGvlg==", - "engines": { - "node": ">=16.0.0", - "npm": ">=7.0.0" - } - }, - "node_modules/multihashes": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/multihashes/-/multihashes-4.0.3.tgz", - "integrity": "sha512-0AhMH7Iu95XjDLxIeuCOOE4t9+vQZsACyKZ9Fxw2pcsRmlX4iCn1mby0hS0bb+nQOVpdQYWPpnyusw4da5RPhA==", - "dependencies": { - "multibase": "^4.0.1", - "uint8arrays": "^3.0.0", - "varint": "^5.0.2" - }, - "engines": { - "node": ">=12.0.0", - "npm": ">=6.0.0" - } - }, - "node_modules/multihashes/node_modules/multiformats": { - "version": "9.9.0", - "resolved": "https://registry.npmjs.org/multiformats/-/multiformats-9.9.0.tgz", - "integrity": "sha512-HoMUjhH9T8DDBNT+6xzkrd9ga/XiBI4xLr58LJACwK6G3HTOPeMz4nB4KJs33L2BelrIJa7P0VuNaVF3hMYfjg==" - }, - "node_modules/multihashes/node_modules/uint8arrays": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/uint8arrays/-/uint8arrays-3.1.1.tgz", - "integrity": "sha512-+QJa8QRnbdXVpHYjLoTpJIdCTiw9Ir62nocClWuXIq2JIh4Uta0cQsTSpFL678p2CN8B+XSApwcU+pQEqVpKWg==", - "dependencies": { - "multiformats": "^9.4.2" - } - }, - "node_modules/multihashes/node_modules/varint": { - "version": "5.0.2", - "resolved": "https://registry.npmjs.org/varint/-/varint-5.0.2.tgz", - "integrity": "sha512-lKxKYG6H03yCZUpAGOPOsMcGxd1RHCu1iKvEHYDPmTyq2HueGhD73ssNBqqQWfvYs04G9iUFRvmAVLW20Jw6ow==" - }, - "node_modules/murmurhash3js-revisited": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/murmurhash3js-revisited/-/murmurhash3js-revisited-3.0.0.tgz", - "integrity": "sha512-/sF3ee6zvScXMb1XFJ8gDsSnY+X8PbOyjIuBhtgis10W2Jx4ZjIhikUCIF9c4gpJxVnQIsPAFrSwTCuAjicP6g==", - "engines": { - "node": ">=8.0.0" - } - }, - "node_modules/nanoid": { - "version": "3.3.3", - "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.3.tgz", - "integrity": "sha512-p1sjXuopFs0xg+fPASzQ28agW1oHD7xDsd9Xkf3T15H3c/cifrFHVwrh74PdoklAPi+i7MdRsE47vm2r6JoB+w==", - "dev": true, - "bin": { - "nanoid": "bin/nanoid.cjs" - }, - "engines": { - "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" - } - }, - "node_modules/napi-macros": { - "version": "2.2.2", - "resolved": "https://registry.npmjs.org/napi-macros/-/napi-macros-2.2.2.tgz", - "integrity": "sha512-hmEVtAGYzVQpCKdbQea4skABsdXW4RUh5t5mJ2zzqowJS2OyXZTU1KhDVFhx+NlWZ4ap9mqR9TcDO3LTTttd+g==" - }, - "node_modules/natural-compare": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", - "integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==", - "dev": true - }, - "node_modules/natural-compare-lite": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/natural-compare-lite/-/natural-compare-lite-1.4.0.tgz", - "integrity": "sha512-Tj+HTDSJJKaZnfiuw+iaF9skdPpTo2GtEly5JHnWV/hfv2Qj/9RKsGISQtLh2ox3l5EAGw487hnBee0sIJ6v2g==", - "dev": true - }, - "node_modules/negotiator": { - "version": "0.6.3", - "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", - "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==", - "dev": true, - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/neo-async": { - "version": "2.6.2", - "resolved": "https://registry.npmjs.org/neo-async/-/neo-async-2.6.2.tgz", - "integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==", - "dev": true, - "peer": true - }, - "node_modules/nise": { - "version": "5.1.4", - "resolved": "https://registry.npmjs.org/nise/-/nise-5.1.4.tgz", - "integrity": "sha512-8+Ib8rRJ4L0o3kfmyVCL7gzrohyDe0cMFTBa2d364yIrEGMEoetznKJx899YxjybU6bL9SQkYPSBBs1gyYs8Xg==", - "dev": true, - "dependencies": { - "@sinonjs/commons": "^2.0.0", - "@sinonjs/fake-timers": "^10.0.2", - "@sinonjs/text-encoding": "^0.7.1", - "just-extend": "^4.0.2", - "path-to-regexp": "^1.7.0" - } - }, - "node_modules/nise/node_modules/@sinonjs/commons": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-2.0.0.tgz", - "integrity": "sha512-uLa0j859mMrg2slwQYdO/AkrOfmH+X6LTVmNTS9CqexuE2IvVORIkSpJLqePAbEnKJ77aMmCwr1NUZ57120Xcg==", - "dev": true, - "dependencies": { - "type-detect": "4.0.8" - } - }, - "node_modules/node-fetch": { - "version": "2.6.12", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.12.tgz", - "integrity": "sha512-C/fGU2E8ToujUivIO0H+tpQ6HWo4eEmchoPIoXtxCrVghxdKq+QOHqEZW7tuP3KlV3bC8FRMO5nMCC7Zm1VP6g==", - "dependencies": { - "whatwg-url": "^5.0.0" - }, - "engines": { - "node": "4.x || >=6.0.0" - }, - "peerDependencies": { - "encoding": "^0.1.0" - }, - "peerDependenciesMeta": { - "encoding": { - "optional": true - } - } - }, - "node_modules/node-gyp-build": { - "version": "4.6.0", - "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.6.0.tgz", - "integrity": "sha512-NTZVKn9IylLwUzaKjkas1e4u2DLNcV4rdYagA4PWdPwW87Bi7z+BznyKSRwS/761tV/lzCGXplWsiaMjLqP2zQ==", - "bin": { - "node-gyp-build": "bin.js", - "node-gyp-build-optional": "optional.js", - "node-gyp-build-test": "build-test.js" - } - }, - "node_modules/node-releases": { - "version": "2.0.13", - "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.13.tgz", - "integrity": "sha512-uYr7J37ae/ORWdZeQ1xxMJe3NtdmqMC/JZK+geofDrkLUApKRHPd18/TxtBOJ4A0/+uUIliorNrfYV6s1b02eQ==", - "dev": true, - "peer": true - }, - "node_modules/node-stdlib-browser": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/node-stdlib-browser/-/node-stdlib-browser-1.2.0.tgz", - "integrity": "sha512-VSjFxUhRhkyed8AtLwSCkMrJRfQ3e2lGtG3sP6FEgaLKBBbxM/dLfjRe1+iLhjvyLFW3tBQ8+c0pcOtXGbAZJg==", - "dev": true, - "dependencies": { - "assert": "^2.0.0", - "browser-resolve": "^2.0.0", - "browserify-zlib": "^0.2.0", - "buffer": "^5.7.1", - "console-browserify": "^1.1.0", - "constants-browserify": "^1.0.0", - "create-require": "^1.1.1", - "crypto-browserify": "^3.11.0", - "domain-browser": "^4.22.0", - "events": "^3.0.0", - "https-browserify": "^1.0.0", - "isomorphic-timers-promises": "^1.0.1", - "os-browserify": "^0.3.0", - "path-browserify": "^1.0.1", - "pkg-dir": "^5.0.0", - "process": "^0.11.10", - "punycode": "^1.4.1", - "querystring-es3": "^0.2.1", - "readable-stream": "^3.6.0", - "stream-browserify": "^3.0.0", - "stream-http": "^3.2.0", - "string_decoder": "^1.0.0", - "timers-browserify": "^2.0.4", - "tty-browserify": "0.0.1", - "url": "^0.11.0", - "util": "^0.12.4", - "vm-browserify": "^1.0.1" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/node-stdlib-browser/node_modules/buffer": { - "version": "5.7.1", - "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz", - "integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==", - "dev": true, - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ], - "dependencies": { - "base64-js": "^1.3.1", - "ieee754": "^1.1.13" - } - }, - "node_modules/node-stdlib-browser/node_modules/readable-stream": { - "version": "3.6.2", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", - "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", - "dev": true, - "dependencies": { - "inherits": "^2.0.3", - "string_decoder": "^1.1.1", - "util-deprecate": "^1.0.1" - }, - "engines": { - "node": ">= 6" - } - }, - "node_modules/normalize-path": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", - "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", - "dev": true, - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/object-assign": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", - "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", - "dev": true, - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/object-inspect": { - "version": "1.12.3", - "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.3.tgz", - "integrity": "sha512-geUvdk7c+eizMNUDkRpW1wJwgfOiOeHbxBR/hLXK1aT6zmVSO0jsQcs7fj6MGw89jC/cjGfLcNOrtMYtGqm81g==", - "dev": true, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/object-is": { - "version": "1.1.5", - "resolved": "https://registry.npmjs.org/object-is/-/object-is-1.1.5.tgz", - "integrity": "sha512-3cyDsyHgtmi7I7DfSSI2LDp6SK2lwvtbg0p0R1e0RvTqF5ceGx+K2dfSjm1bKDMVCFEDAQvy+o8c6a7VujOddw==", - "dev": true, - "dependencies": { - "call-bind": "^1.0.2", - "define-properties": "^1.1.3" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/object-keys": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz", - "integrity": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==", - "dev": true, - "engines": { - "node": ">= 0.4" - } - }, - "node_modules/on-finished": { - "version": "2.4.1", - "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz", - "integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==", - "dev": true, - "dependencies": { - "ee-first": "1.1.1" - }, - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/once": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", - "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", - "dev": true, - "dependencies": { - "wrappy": "1" - } - }, - "node_modules/optionator": { - "version": "0.9.3", - "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.3.tgz", - "integrity": "sha512-JjCoypp+jKn1ttEFExxhetCKeJt9zhAgAve5FXHixTvFDW/5aEktX9bufBKLRRMdU7bNtpLfcGu94B3cdEJgjg==", - "dev": true, - "dependencies": { - "@aashutoshrathi/word-wrap": "^1.2.3", - "deep-is": "^0.1.3", - "fast-levenshtein": "^2.0.6", - "levn": "^0.4.1", - "prelude-ls": "^1.2.1", - "type-check": "^0.4.0" - }, - "engines": { - "node": ">= 0.8.0" - } - }, - "node_modules/os-browserify": { - "version": "0.3.0", - "resolved": "https://registry.npmjs.org/os-browserify/-/os-browserify-0.3.0.tgz", - "integrity": "sha512-gjcpUc3clBf9+210TRaDWbf+rZZZEshZ+DlXMRCeAjp0xhTrnQsKHypIy1J3d5hKdUzj69t708EHtU8P6bUn0A==", - "dev": true - }, - "node_modules/p-defer": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/p-defer/-/p-defer-4.0.0.tgz", - "integrity": "sha512-Vb3QRvQ0Y5XnF40ZUWW7JfLogicVh/EnA5gBIvKDJoYpeI82+1E3AlB9yOcKFS0AhHrWVnAQO39fbR0G99IVEQ==", - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/p-limit": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", - "integrity": "sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==", - "dev": true, - "dependencies": { - "yocto-queue": "^0.1.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/p-locate": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-5.0.0.tgz", - "integrity": "sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw==", - "dev": true, - "dependencies": { - "p-limit": "^3.0.2" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/p-queue": { - "version": "7.3.4", - "resolved": "https://registry.npmjs.org/p-queue/-/p-queue-7.3.4.tgz", - "integrity": "sha512-esox8CWt0j9EZECFvkFl2WNPat8LN4t7WWeXq73D9ha0V96qPRufApZi4ZhPwXAln1uVVal429HVVKPa2X0yQg==", - "dependencies": { - "eventemitter3": "^4.0.7", - "p-timeout": "^5.0.2" - }, - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/p-timeout": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/p-timeout/-/p-timeout-5.1.0.tgz", - "integrity": "sha512-auFDyzzzGZZZdHz3BtET9VEz0SE/uMEAx7uWfGPucfzEwwe/xH0iVeZibQmANYE/hp9T2+UUZT5m+BKyrDp3Ew==", - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/pako": { - "version": "1.0.11", - "resolved": "https://registry.npmjs.org/pako/-/pako-1.0.11.tgz", - "integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==", - "dev": true - }, - "node_modules/parent-module": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", - "integrity": "sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==", - "dev": true, - "dependencies": { - "callsites": "^3.0.0" - }, - "engines": { - "node": ">=6" - } - }, - "node_modules/parse-asn1": { - "version": "5.1.6", - "resolved": "https://registry.npmjs.org/parse-asn1/-/parse-asn1-5.1.6.tgz", - "integrity": "sha512-RnZRo1EPU6JBnra2vGHj0yhp6ebyjBZpmUCLHWiFhxlzvBCCpAuZ7elsBp1PVAbQN0/04VD/19rfzlBSwLstMw==", - "dev": true, - "dependencies": { - "asn1.js": "^5.2.0", - "browserify-aes": "^1.0.0", - "evp_bytestokey": "^1.0.0", - "pbkdf2": "^3.0.3", - "safe-buffer": "^5.1.1" - } - }, - "node_modules/parseurl": { - "version": "1.3.3", - "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", - "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==", - "dev": true, - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/path-browserify": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/path-browserify/-/path-browserify-1.0.1.tgz", - "integrity": "sha512-b7uo2UCUOYZcnF/3ID0lulOJi/bafxa1xPe7ZPsammBSpjSWQkjNxlt635YGS2MiR9GjvuXCtz2emr3jbsz98g==", - "dev": true - }, - "node_modules/path-exists": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", - "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", - "dev": true, - "engines": { - "node": ">=8" - } - }, - "node_modules/path-is-absolute": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==", - "dev": true, - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/path-key": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", - "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", - "dev": true, - "engines": { - "node": ">=8" - } - }, - "node_modules/path-parse": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", - "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==", - "dev": true - }, - "node_modules/path-scurry": { - "version": "1.10.1", - "resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-1.10.1.tgz", - "integrity": "sha512-MkhCqzzBEpPvxxQ71Md0b1Kk51W01lrYvlMzSUaIzNsODdd7mqhiimSZlr+VegAz5Z6Vzt9Xg2ttE//XBhH3EQ==", - "dev": true, - "dependencies": { - "lru-cache": "^9.1.1 || ^10.0.0", - "minipass": "^5.0.0 || ^6.0.2 || ^7.0.0" - }, - "engines": { - "node": ">=16 || 14 >=14.17" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, - "node_modules/path-scurry/node_modules/minipass": { - "version": "7.0.2", - "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.0.2.tgz", - "integrity": "sha512-eL79dXrE1q9dBbDCLg7xfn/vl7MS4F1gvJAgjJrQli/jbQWdUttuVawphqpffoIYfRdq78LHx6GP4bU/EQ2ATA==", - "dev": true, - "engines": { - "node": ">=16 || 14 >=14.17" - } - }, - "node_modules/path-to-regexp": { - "version": "1.8.0", - "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-1.8.0.tgz", - "integrity": "sha512-n43JRhlUKUAlibEJhPeir1ncUID16QnEjNpwzNdO3Lm4ywrBpBZ5oLD0I6br9evr1Y9JTqwRtAh7JLoOzAQdVA==", - "dev": true, - "dependencies": { - "isarray": "0.0.1" - } - }, - "node_modules/path-type": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz", - "integrity": "sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==", - "dev": true, - "engines": { - "node": ">=8" - } - }, - "node_modules/pathval": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.1.tgz", - "integrity": "sha512-Dp6zGqpTdETdR63lehJYPeIOqpiNBNtc7BpWSLrOje7UaIsE5aY92r/AunQA7rsXvet3lrJ3JnZX29UPTKXyKQ==", - "engines": { - "node": "*" - } - }, - "node_modules/pbkdf2": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/pbkdf2/-/pbkdf2-3.1.2.tgz", - "integrity": "sha512-iuh7L6jA7JEGu2WxDwtQP1ddOpaJNC4KlDEFfdQajSGgGPNi4OyDc2R7QnbY2bR9QjBVGwgvTdNJZoE7RaxUMA==", - "dev": true, - "dependencies": { - "create-hash": "^1.1.2", - "create-hmac": "^1.1.4", - "ripemd160": "^2.0.1", - "safe-buffer": "^5.0.1", - "sha.js": "^2.4.8" - }, - "engines": { - "node": ">=0.12" - } - }, - "node_modules/picocolors": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz", - "integrity": "sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==", - "dev": true, - "peer": true - }, - "node_modules/picomatch": { - "version": "2.3.1", - "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", - "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", - "dev": true, - "engines": { - "node": ">=8.6" - }, - "funding": { - "url": "https://github.com/sponsors/jonschlinkert" - } - }, - "node_modules/pkg-dir": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-5.0.0.tgz", - "integrity": "sha512-NPE8TDbzl/3YQYY7CSS228s3g2ollTFnc+Qi3tqmqJp9Vg2ovUpixcJEo2HJScN2Ez+kEaal6y70c0ehqJBJeA==", - "dev": true, - "dependencies": { - "find-up": "^5.0.0" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/playwright": { - "version": "1.36.2", - "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.36.2.tgz", - "integrity": "sha512-4Fmlq3KWsl85Bl4InJw1NC21aeQV0iSZuFvTDcy1F8zVmXmgQRe89GxF8zMSRt/KIS+2tUolak7EXVl9aC+JdA==", - "dev": true, - "hasInstallScript": true, - "dependencies": { - "playwright-core": "1.36.2" - }, - "bin": { - "playwright": "cli.js" - }, - "engines": { - "node": ">=16" - } - }, - "node_modules/playwright-core": { - "version": "1.36.2", - "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.36.2.tgz", - "integrity": "sha512-sQYZt31dwkqxOrP7xy2ggDfEzUxM1lodjhsQ3NMMv5uGTRDsLxU0e4xf4wwMkF2gplIxf17QMBCodSFgm6bFVQ==", - "dev": true, - "bin": { - "playwright-core": "cli.js" - }, - "engines": { - "node": ">=16" - } - }, - "node_modules/prelude-ls": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", - "integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==", - "dev": true, - "engines": { - "node": ">= 0.8.0" - } - }, - "node_modules/process": { - "version": "0.11.10", - "resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz", - "integrity": "sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A==", - "engines": { - "node": ">= 0.6.0" - } - }, - "node_modules/progress-events": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/progress-events/-/progress-events-1.0.0.tgz", - "integrity": "sha512-zIB6QDrSbPfRg+33FZalluFIowkbV5Xh1xSuetjG+rlC5he6u2dc6VQJ0TbMdlN3R1RHdpOqxEFMKTnQ+itUwA==", - "engines": { - "node": ">=16.0.0", - "npm": ">=7.0.0" - } - }, - "node_modules/protobufjs": { - "version": "7.2.4", - "resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-7.2.4.tgz", - "integrity": "sha512-AT+RJgD2sH8phPmCf7OUZR8xGdcJRga4+1cOaXJ64hvcSkVhNcRHOwIxUatPH15+nj59WAGTDv3LSGZPEQbJaQ==", - "hasInstallScript": true, - "dependencies": { - "@protobufjs/aspromise": "^1.1.2", - "@protobufjs/base64": "^1.1.2", - "@protobufjs/codegen": "^2.0.4", - "@protobufjs/eventemitter": "^1.1.0", - "@protobufjs/fetch": "^1.1.0", - "@protobufjs/float": "^1.0.2", - "@protobufjs/inquire": "^1.1.0", - "@protobufjs/path": "^1.1.2", - "@protobufjs/pool": "^1.1.0", - "@protobufjs/utf8": "^1.1.0", - "@types/node": ">=13.7.0", - "long": "^5.0.0" - }, - "engines": { - "node": ">=12.0.0" - } - }, - "node_modules/protons-runtime": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/protons-runtime/-/protons-runtime-5.0.1.tgz", - "integrity": "sha512-AwyAA3pQ4Ka4tEBMdIjLi/cRdpb322f7sgv3NruVq9yguLggzwu5eeLe1HuRPFYlI4UsVN/QK/AQXjLPVLCzTA==", - "dependencies": { - "protobufjs": "^7.0.0", - "uint8arraylist": "^2.4.3" - }, - "peerDependencies": { - "uint8arraylist": "^2.3.2" - } - }, - "node_modules/public-encrypt": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/public-encrypt/-/public-encrypt-4.0.3.tgz", - "integrity": "sha512-zVpa8oKZSz5bTMTFClc1fQOnyyEzpl5ozpi1B5YcvBrdohMjH2rfsBtyXcuNuwjsDIXmBYlF2N5FlJYhR29t8Q==", - "dev": true, - "dependencies": { - "bn.js": "^4.1.0", - "browserify-rsa": "^4.0.0", - "create-hash": "^1.1.0", - "parse-asn1": "^5.0.0", - "randombytes": "^2.0.1", - "safe-buffer": "^5.1.2" - } - }, - "node_modules/public-encrypt/node_modules/bn.js": { - "version": "4.12.0", - "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.12.0.tgz", - "integrity": "sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA==", - "dev": true - }, - "node_modules/punycode": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz", - "integrity": "sha512-jmYNElW7yvO7TV33CjSmvSiE2yco3bV2czu/OzDKdMNVZQWfxCblURLhf+47syQRBntjfLdd/H0egrzIG+oaFQ==", - "dev": true - }, - "node_modules/qjobs": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/qjobs/-/qjobs-1.2.0.tgz", - "integrity": "sha512-8YOJEHtxpySA3fFDyCRxA+UUV+fA+rTWnuWvylOK/NCjhY+b4ocCtmu8TtsWb+mYeU+GCHf/S66KZF/AsteKHg==", - "dev": true, - "engines": { - "node": ">=0.9" - } - }, - "node_modules/qs": { - "version": "6.11.0", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz", - "integrity": "sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==", - "dev": true, - "dependencies": { - "side-channel": "^1.0.4" - }, - "engines": { - "node": ">=0.6" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/querystring-es3": { - "version": "0.2.1", - "resolved": "https://registry.npmjs.org/querystring-es3/-/querystring-es3-0.2.1.tgz", - "integrity": "sha512-773xhDQnZBMFobEiztv8LIl70ch5MSF/jUQVlhwFyBILqq96anmoctVIYz+ZRp0qbCKATTn6ev02M3r7Ga5vqA==", - "dev": true, - "engines": { - "node": ">=0.4.x" - } - }, - "node_modules/queue-microtask": { - "version": "1.2.3", - "resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz", - "integrity": "sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ] - }, - "node_modules/rabin-wasm": { - "version": "0.1.5", - "resolved": "https://registry.npmjs.org/rabin-wasm/-/rabin-wasm-0.1.5.tgz", - "integrity": "sha512-uWgQTo7pim1Rnj5TuWcCewRDTf0PEFTSlaUjWP4eY9EbLV9em08v89oCz/WO+wRxpYuO36XEHp4wgYQnAgOHzA==", - "dependencies": { - "@assemblyscript/loader": "^0.9.4", - "bl": "^5.0.0", - "debug": "^4.3.1", - "minimist": "^1.2.5", - "node-fetch": "^2.6.1", - "readable-stream": "^3.6.0" - }, - "bin": { - "rabin-wasm": "cli/bin.js" - } - }, - "node_modules/rabin-wasm/node_modules/readable-stream": { - "version": "3.6.2", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", - "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", - "dependencies": { - "inherits": "^2.0.3", - "string_decoder": "^1.1.1", - "util-deprecate": "^1.0.1" - }, - "engines": { - "node": ">= 6" - } - }, - "node_modules/rambda": { - "version": "7.5.0", - "resolved": "https://registry.npmjs.org/rambda/-/rambda-7.5.0.tgz", - "integrity": "sha512-y/M9weqWAH4iopRd7EHDEQQvpFPHj1AA3oHozE9tfITHUtTR7Z9PSlIRRG2l1GuW7sefC1cXFfIcF+cgnShdBA==", - "dev": true - }, - "node_modules/randombytes": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz", - "integrity": "sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ==", - "dependencies": { - "safe-buffer": "^5.1.0" - } - }, - "node_modules/randomfill": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/randomfill/-/randomfill-1.0.4.tgz", - "integrity": "sha512-87lcbR8+MhcWcUiQ+9e+Rwx8MyR2P7qnt15ynUlbm3TU/fjbgz4GsvfSUDTemtCCtVCqb4ZcEFlyPNTh9bBTLw==", - "dev": true, - "dependencies": { - "randombytes": "^2.0.5", - "safe-buffer": "^5.1.0" - } - }, - "node_modules/range-parser": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", - "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==", - "dev": true, - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/raw-body": { - "version": "2.5.2", - "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.2.tgz", - "integrity": "sha512-8zGqypfENjCIqGhgXToC8aB2r7YrBX+AQAfIPs/Mlk+BtPTztOvTS01NRW/3Eh60J+a48lt8qsCzirQ6loCVfA==", - "dev": true, - "dependencies": { - "bytes": "3.1.2", - "http-errors": "2.0.0", - "iconv-lite": "0.4.24", - "unpipe": "1.0.0" - }, - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/readable-stream": { - "version": "4.4.0", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-4.4.0.tgz", - "integrity": "sha512-kDMOq0qLtxV9f/SQv522h8cxZBqNZXuXNyjyezmfAAuribMyVXziljpQ/uQhfE1XLg2/TLTW2DsnoE4VAi/krg==", - "dependencies": { - "abort-controller": "^3.0.0", - "buffer": "^6.0.3", - "events": "^3.3.0", - "process": "^0.11.10" - }, - "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - } - }, - "node_modules/readable-web-to-node-stream": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/readable-web-to-node-stream/-/readable-web-to-node-stream-3.0.2.tgz", - "integrity": "sha512-ePeK6cc1EcKLEhJFt/AebMCLL+GgSKhuygrZ/GLaKZYEecIgIECf4UaUuaByiGtzckwR4ain9VzUh95T1exYGw==", - "dependencies": { - "readable-stream": "^3.6.0" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/Borewit" - } - }, - "node_modules/readable-web-to-node-stream/node_modules/readable-stream": { - "version": "3.6.2", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", - "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", - "dependencies": { - "inherits": "^2.0.3", - "string_decoder": "^1.1.1", - "util-deprecate": "^1.0.1" - }, - "engines": { - "node": ">= 6" - } - }, - "node_modules/readdirp": { - "version": "3.6.0", - "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", - "integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==", - "dev": true, - "dependencies": { - "picomatch": "^2.2.1" - }, - "engines": { - "node": ">=8.10.0" - } - }, - "node_modules/require-directory": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", - "integrity": "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==", - "dev": true, - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/require-from-string": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz", - "integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==", - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/requires-port": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz", - "integrity": "sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ==", - "dev": true - }, - "node_modules/resolve": { - "version": "1.22.2", - "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.2.tgz", - "integrity": "sha512-Sb+mjNHOULsBv818T40qSPeRiuWLyaGMa5ewydRLFimneixmVy2zdivRl+AF6jaYPC8ERxGDmFSiqui6SfPd+g==", - "dev": true, - "dependencies": { - "is-core-module": "^2.11.0", - "path-parse": "^1.0.7", - "supports-preserve-symlinks-flag": "^1.0.0" - }, - "bin": { - "resolve": "bin/resolve" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/resolve-from": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", - "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==", - "dev": true, - "engines": { - "node": ">=4" - } - }, - "node_modules/reusify": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/reusify/-/reusify-1.0.4.tgz", - "integrity": "sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==", - "dev": true, - "engines": { - "iojs": ">=1.0.0", - "node": ">=0.10.0" - } - }, - "node_modules/rfdc": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/rfdc/-/rfdc-1.3.0.tgz", - "integrity": "sha512-V2hovdzFbOi77/WajaSMXk2OLm+xNIeQdMMuB7icj7bk6zi2F8GGAxigcnDFpJHbNyNcgyJDiP+8nOrY5cZGrA==", - "dev": true - }, - "node_modules/rimraf": { - "version": "4.4.0", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-4.4.0.tgz", - "integrity": "sha512-X36S+qpCUR0HjXlkDe4NAOhS//aHH0Z+h8Ckf2auGJk3PTnx5rLmrHkwNdbVQuCSUhOyFrlRvFEllZOYE+yZGQ==", - "dev": true, - "dependencies": { - "glob": "^9.2.0" - }, - "bin": { - "rimraf": "dist/cjs/src/bin.js" - }, - "engines": { - "node": ">=14" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, - "node_modules/rimraf/node_modules/brace-expansion": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", - "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", - "dev": true, - "dependencies": { - "balanced-match": "^1.0.0" - } - }, - "node_modules/rimraf/node_modules/glob": { - "version": "9.3.5", - "resolved": "https://registry.npmjs.org/glob/-/glob-9.3.5.tgz", - "integrity": "sha512-e1LleDykUz2Iu+MTYdkSsuWX8lvAjAcs0Xef0lNIu0S2wOAzuTxCJtcd9S3cijlwYF18EsU3rzb8jPVobxDh9Q==", - "dev": true, - "dependencies": { - "fs.realpath": "^1.0.0", - "minimatch": "^8.0.2", - "minipass": "^4.2.4", - "path-scurry": "^1.6.1" - }, - "engines": { - "node": ">=16 || 14 >=14.17" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, - "node_modules/rimraf/node_modules/minimatch": { - "version": "8.0.4", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-8.0.4.tgz", - "integrity": "sha512-W0Wvr9HyFXZRGIDgCicunpQ299OKXs9RgZfaukz4qAW/pJhcpUfupc9c+OObPOFueNy8VSrZgEmDtk6Kh4WzDA==", - "dev": true, - "dependencies": { - "brace-expansion": "^2.0.1" - }, - "engines": { - "node": ">=16 || 14 >=14.17" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, - "node_modules/ripemd160": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/ripemd160/-/ripemd160-2.0.2.tgz", - "integrity": "sha512-ii4iagi25WusVoiC4B4lq7pbXfAp3D9v5CwfkY33vffw2+pkDjY1D8GaN7spsxvCSx8dkPqOZCEZyfxcmJG2IA==", - "dev": true, - "dependencies": { - "hash-base": "^3.0.0", - "inherits": "^2.0.1" - } - }, - "node_modules/run-parallel": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", - "integrity": "sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==", - "dev": true, - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ], - "dependencies": { - "queue-microtask": "^1.2.2" - } - }, - "node_modules/run-parallel-limit": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/run-parallel-limit/-/run-parallel-limit-1.1.0.tgz", - "integrity": "sha512-jJA7irRNM91jaKc3Hcl1npHsFLOXOoTkPCUL1JEa1R82O2miplXXRaGdjW/KM/98YQWDhJLiSs793CnXfblJUw==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ], - "dependencies": { - "queue-microtask": "^1.2.2" - } - }, - "node_modules/safe-buffer": { - "version": "5.1.2", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", - "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" - }, - "node_modules/safer-buffer": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", - "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", - "dev": true - }, - "node_modules/schema-utils": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/schema-utils/-/schema-utils-3.3.0.tgz", - "integrity": "sha512-pN/yOAvcC+5rQ5nERGuwrjLlYvLTbCibnZ1I7B1LaiAz9BRBlE9GMgE/eqV30P7aJQUf7Ddimy/RsbYO/GrVGg==", - "dev": true, - "peer": true, - "dependencies": { - "@types/json-schema": "^7.0.8", - "ajv": "^6.12.5", - "ajv-keywords": "^3.5.2" - }, - "engines": { - "node": ">= 10.13.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/webpack" - } - }, - "node_modules/schema-utils/node_modules/ajv": { - "version": "6.12.6", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", - "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", - "dev": true, - "peer": true, - "dependencies": { - "fast-deep-equal": "^3.1.1", - "fast-json-stable-stringify": "^2.0.0", - "json-schema-traverse": "^0.4.1", - "uri-js": "^4.2.2" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/epoberezkin" - } - }, - "node_modules/schema-utils/node_modules/ajv-keywords": { - "version": "3.5.2", - "resolved": "https://registry.npmjs.org/ajv-keywords/-/ajv-keywords-3.5.2.tgz", - "integrity": "sha512-5p6WTN0DdTGVQk6VjcEju19IgaHudalcfabD7yhDGeA6bcQnmL+CpveLJq/3hvfwd1aof6L386Ougkx6RfyMIQ==", - "dev": true, - "peer": true, - "peerDependencies": { - "ajv": "^6.9.1" - } - }, - "node_modules/schema-utils/node_modules/json-schema-traverse": { - "version": "0.4.1", - "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", - "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", - "dev": true, - "peer": true - }, - "node_modules/semver": { - "version": "7.5.4", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", - "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", - "dev": true, - "dependencies": { - "lru-cache": "^6.0.0" - }, - "bin": { - "semver": "bin/semver.js" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/semver/node_modules/lru-cache": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", - "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", - "dev": true, - "dependencies": { - "yallist": "^4.0.0" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/serialize-javascript": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-6.0.0.tgz", - "integrity": "sha512-Qr3TosvguFt8ePWqsvRfrKyQXIiW+nGbYpy8XK24NQHE83caxWt+mIymTT19DGFbNWNLfEwsrkSmN64lVWB9ag==", - "dev": true, - "dependencies": { - "randombytes": "^2.1.0" - } - }, - "node_modules/setimmediate": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz", - "integrity": "sha512-MATJdZp8sLqDl/68LfQmbP8zKPLQNV6BIZoIgrscFDQ+RsvK/BxeDQOgyxKKoh0y/8h3BqVFnCqQ/gd+reiIXA==", - "dev": true - }, - "node_modules/setprototypeof": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", - "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==", - "dev": true - }, - "node_modules/sha.js": { - "version": "2.4.11", - "resolved": "https://registry.npmjs.org/sha.js/-/sha.js-2.4.11.tgz", - "integrity": "sha512-QMEp5B7cftE7APOjk5Y6xgrbWu+WkLVQwk8JNjZ8nKRciZaByEW6MubieAiToS7+dwvrjGhH8jRXz3MVd0AYqQ==", - "dev": true, - "dependencies": { - "inherits": "^2.0.1", - "safe-buffer": "^5.0.1" - }, - "bin": { - "sha.js": "bin.js" - } - }, - "node_modules/shebang-command": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", - "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", - "dev": true, - "dependencies": { - "shebang-regex": "^3.0.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/shebang-regex": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", - "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", - "dev": true, - "engines": { - "node": ">=8" - } - }, - "node_modules/side-channel": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz", - "integrity": "sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==", - "dev": true, - "dependencies": { - "call-bind": "^1.0.0", - "get-intrinsic": "^1.0.2", - "object-inspect": "^1.9.0" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/signal-exit": { - "version": "3.0.7", - "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", - "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==", - "dev": true - }, - "node_modules/sinon": { - "version": "15.0.2", - "resolved": "https://registry.npmjs.org/sinon/-/sinon-15.0.2.tgz", - "integrity": "sha512-PCVP63XZkg0/LOqQH5rEU4LILuvTFMb5tNxTHfs6VUMNnZz2XrnGSTZbAGITjzwQWbl/Bl/8hi4G3zZWjyBwHg==", - "dev": true, - "dependencies": { - "@sinonjs/commons": "^3.0.0", - "@sinonjs/fake-timers": "^10.0.2", - "@sinonjs/samsam": "^7.0.1", - "diff": "^5.1.0", - "nise": "^5.1.4", - "supports-color": "^7.2.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/sinon" - } - }, - "node_modules/sinon/node_modules/diff": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/diff/-/diff-5.1.0.tgz", - "integrity": "sha512-D+mk+qE8VC/PAUrlAU34N+VfXev0ghe5ywmpqrawphmVZc1bEfn56uo9qpyGp1p4xpzOHkSW4ztBd6L7Xx4ACw==", - "dev": true, - "engines": { - "node": ">=0.3.1" - } - }, - "node_modules/slash": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", - "integrity": "sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==", - "dev": true, - "engines": { - "node": ">=8" - } - }, - "node_modules/socket.io": { - "version": "4.7.2", - "resolved": "https://registry.npmjs.org/socket.io/-/socket.io-4.7.2.tgz", - "integrity": "sha512-bvKVS29/I5fl2FGLNHuXlQaUH/BlzX1IN6S+NKLNZpBsPZIDH+90eQmCs2Railn4YUiww4SzUedJ6+uzwFnKLw==", - "dev": true, - "dependencies": { - "accepts": "~1.3.4", - "base64id": "~2.0.0", - "cors": "~2.8.5", - "debug": "~4.3.2", - "engine.io": "~6.5.2", - "socket.io-adapter": "~2.5.2", - "socket.io-parser": "~4.2.4" - }, - "engines": { - "node": ">=10.2.0" - } - }, - "node_modules/socket.io-adapter": { - "version": "2.5.2", - "resolved": "https://registry.npmjs.org/socket.io-adapter/-/socket.io-adapter-2.5.2.tgz", - "integrity": "sha512-87C3LO/NOMc+eMcpcxUBebGjkpMDkNBS9tf7KJqcDsmL936EChtVva71Dw2q4tQcuVC+hAUy4an2NO/sYXmwRA==", - "dev": true, - "dependencies": { - "ws": "~8.11.0" - } - }, - "node_modules/socket.io-parser": { - "version": "4.2.4", - "resolved": "https://registry.npmjs.org/socket.io-parser/-/socket.io-parser-4.2.4.tgz", - "integrity": "sha512-/GbIKmo8ioc+NIWIhwdecY0ge+qVBSMdgxGygevmdHj24bsfgtCmcUUcQ5ZzcylGFHsN3k4HB4Cgkl96KVnuew==", - "dev": true, - "dependencies": { - "@socket.io/component-emitter": "~3.1.0", - "debug": "~4.3.1" - }, - "engines": { - "node": ">=10.0.0" - } - }, - "node_modules/source-map": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", - "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", - "dev": true, - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/source-map-js": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.0.2.tgz", - "integrity": "sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw==", - "dev": true, - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/source-map-loader": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/source-map-loader/-/source-map-loader-4.0.1.tgz", - "integrity": "sha512-oqXpzDIByKONVY8g1NUPOTQhe0UTU5bWUl32GSkqK2LjJj0HmwTMVKxcUip0RgAYhY1mqgOxjbQM48a0mmeNfA==", - "dev": true, - "dependencies": { - "abab": "^2.0.6", - "iconv-lite": "^0.6.3", - "source-map-js": "^1.0.2" - }, - "engines": { - "node": ">= 14.15.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/webpack" - }, - "peerDependencies": { - "webpack": "^5.72.1" - } - }, - "node_modules/source-map-loader/node_modules/iconv-lite": { - "version": "0.6.3", - "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", - "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", - "dev": true, - "dependencies": { - "safer-buffer": ">= 2.1.2 < 3.0.0" - }, - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/source-map-support": { - "version": "0.5.21", - "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.21.tgz", - "integrity": "sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==", - "dev": true, - "peer": true, - "dependencies": { - "buffer-from": "^1.0.0", - "source-map": "^0.6.0" - } - }, - "node_modules/sparse-array": { - "version": "1.3.2", - "resolved": "https://registry.npmjs.org/sparse-array/-/sparse-array-1.3.2.tgz", - "integrity": "sha512-ZT711fePGn3+kQyLuv1fpd3rNSkNF8vd5Kv2D+qnOANeyKs3fx6bUMGWRPvgTTcYV64QMqZKZwcuaQSP3AZ0tg==" - }, - "node_modules/statuses": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz", - "integrity": "sha512-OpZ3zP+jT1PI7I8nemJX4AKmAX070ZkYPVWV/AaKTJl+tXCTGyVdC1a4SL8RUQYEwk/f34ZX8UTykN68FwrqAA==", - "dev": true, - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/stream-browserify": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/stream-browserify/-/stream-browserify-3.0.0.tgz", - "integrity": "sha512-H73RAHsVBapbim0tU2JwwOiXUj+fikfiaoYAKHF3VJfA0pe2BCzkhAHBlLG6REzE+2WNZcxOXjK7lkso+9euLA==", - "dev": true, - "dependencies": { - "inherits": "~2.0.4", - "readable-stream": "^3.5.0" - } - }, - "node_modules/stream-browserify/node_modules/readable-stream": { - "version": "3.6.2", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", - "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", - "dev": true, - "dependencies": { - "inherits": "^2.0.3", - "string_decoder": "^1.1.1", - "util-deprecate": "^1.0.1" - }, - "engines": { - "node": ">= 6" - } - }, - "node_modules/stream-http": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/stream-http/-/stream-http-3.2.0.tgz", - "integrity": "sha512-Oq1bLqisTyK3TSCXpPbT4sdeYNdmyZJv1LxpEm2vu1ZhK89kSE5YXwZc3cWk0MagGaKriBh9mCFbVGtO+vY29A==", - "dev": true, - "dependencies": { - "builtin-status-codes": "^3.0.0", - "inherits": "^2.0.4", - "readable-stream": "^3.6.0", - "xtend": "^4.0.2" - } - }, - "node_modules/stream-http/node_modules/readable-stream": { - "version": "3.6.2", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", - "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", - "dev": true, - "dependencies": { - "inherits": "^2.0.3", - "string_decoder": "^1.1.1", - "util-deprecate": "^1.0.1" - }, - "engines": { - "node": ">= 6" - } - }, - "node_modules/streamroller": { - "version": "3.1.5", - "resolved": "https://registry.npmjs.org/streamroller/-/streamroller-3.1.5.tgz", - "integrity": "sha512-KFxaM7XT+irxvdqSP1LGLgNWbYN7ay5owZ3r/8t77p+EtSUAfUgtl7be3xtqtOmGUl9K9YPO2ca8133RlTjvKw==", - "dev": true, - "dependencies": { - "date-format": "^4.0.14", - "debug": "^4.3.4", - "fs-extra": "^8.1.0" - }, - "engines": { - "node": ">=8.0" - } - }, - "node_modules/string_decoder": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", - "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", - "dependencies": { - "safe-buffer": "~5.2.0" - } - }, - "node_modules/string_decoder/node_modules/safe-buffer": { - "version": "5.2.1", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", - "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ] - }, - "node_modules/string-width": { - "version": "4.2.3", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", - "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", - "dev": true, - "dependencies": { - "emoji-regex": "^8.0.0", - "is-fullwidth-code-point": "^3.0.0", - "strip-ansi": "^6.0.1" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/strip-ansi": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", - "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", - "dev": true, - "dependencies": { - "ansi-regex": "^5.0.1" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/strip-json-comments": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", - "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==", - "dev": true, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/supports-color": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", - "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", - "dev": true, - "dependencies": { - "has-flag": "^4.0.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/supports-preserve-symlinks-flag": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz", - "integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==", - "dev": true, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/tapable": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/tapable/-/tapable-2.2.1.tgz", - "integrity": "sha512-GNzQvQTOIP6RyTfE2Qxb8ZVlNmw0n88vp1szwWRimP02mnTsx3Wtn5qRdqY9w2XduFNUgvOwhNnQsjwCp+kqaQ==", - "dev": true, - "peer": true, - "engines": { - "node": ">=6" - } - }, - "node_modules/terser": { - "version": "5.19.2", - "resolved": "https://registry.npmjs.org/terser/-/terser-5.19.2.tgz", - "integrity": "sha512-qC5+dmecKJA4cpYxRa5aVkKehYsQKc+AHeKl0Oe62aYjBL8ZA33tTljktDHJSaxxMnbI5ZYw+o/S2DxxLu8OfA==", - "dev": true, - "peer": true, - "dependencies": { - "@jridgewell/source-map": "^0.3.3", - "acorn": "^8.8.2", - "commander": "^2.20.0", - "source-map-support": "~0.5.20" - }, - "bin": { - "terser": "bin/terser" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/terser-webpack-plugin": { - "version": "5.3.9", - "resolved": "https://registry.npmjs.org/terser-webpack-plugin/-/terser-webpack-plugin-5.3.9.tgz", - "integrity": "sha512-ZuXsqE07EcggTWQjXUj+Aot/OMcD0bMKGgF63f7UxYcu5/AJF53aIpK1YoP5xR9l6s/Hy2b+t1AM0bLNPRuhwA==", - "dev": true, - "peer": true, - "dependencies": { - "@jridgewell/trace-mapping": "^0.3.17", - "jest-worker": "^27.4.5", - "schema-utils": "^3.1.1", - "serialize-javascript": "^6.0.1", - "terser": "^5.16.8" - }, - "engines": { - "node": ">= 10.13.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/webpack" - }, - "peerDependencies": { - "webpack": "^5.1.0" - }, - "peerDependenciesMeta": { - "@swc/core": { - "optional": true - }, - "esbuild": { - "optional": true - }, - "uglify-js": { - "optional": true - } - } - }, - "node_modules/terser-webpack-plugin/node_modules/serialize-javascript": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-6.0.1.tgz", - "integrity": "sha512-owoXEFjWRllis8/M1Q+Cw5k8ZH40e3zhp/ovX+Xr/vi1qj6QesbyXXViFbpNvWvPNAD62SutwEXavefrLJWj7w==", - "dev": true, - "peer": true, - "dependencies": { - "randombytes": "^2.1.0" - } - }, - "node_modules/test-exclude": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/test-exclude/-/test-exclude-6.0.0.tgz", - "integrity": "sha512-cAGWPIyOHU6zlmg88jwm7VRyXnMN7iV68OGAbYDk/Mh/xC/pzVPlQtY6ngoIH/5/tciuhGfvESU8GrHrcxD56w==", - "dev": true, - "dependencies": { - "@istanbuljs/schema": "^0.1.2", - "glob": "^7.1.4", - "minimatch": "^3.0.4" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/text-table": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", - "integrity": "sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==", - "dev": true - }, - "node_modules/timers-browserify": { - "version": "2.0.12", - "resolved": "https://registry.npmjs.org/timers-browserify/-/timers-browserify-2.0.12.tgz", - "integrity": "sha512-9phl76Cqm6FhSX9Xe1ZUAMLtm1BLkKj2Qd5ApyWkXzsMRaA7dgr81kf4wJmQf/hAvg8EEyJxDo3du/0KlhPiKQ==", - "dev": true, - "dependencies": { - "setimmediate": "^1.0.4" - }, - "engines": { - "node": ">=0.6.0" - } - }, - "node_modules/tmp": { - "version": "0.2.1", - "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.1.tgz", - "integrity": "sha512-76SUhtfqR2Ijn+xllcI5P1oyannHNHByD80W1q447gU3mp9G9PSpGdWmjUOHRDPiHYacIk66W7ubDTuPF3BEtQ==", - "dev": true, - "dependencies": { - "rimraf": "^3.0.0" - }, - "engines": { - "node": ">=8.17.0" - } - }, - "node_modules/tmp/node_modules/rimraf": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", - "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", - "dev": true, - "dependencies": { - "glob": "^7.1.3" - }, - "bin": { - "rimraf": "bin.js" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, - "node_modules/to-regex-range": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", - "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", - "dev": true, - "dependencies": { - "is-number": "^7.0.0" - }, - "engines": { - "node": ">=8.0" - } - }, - "node_modules/toidentifier": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", - "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==", - "dev": true, - "engines": { - "node": ">=0.6" - } - }, - "node_modules/tr46": { - "version": "0.0.3", - "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", - "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" - }, - "node_modules/tslib": { - "version": "2.6.1", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.1.tgz", - "integrity": "sha512-t0hLfiEKfMUoqhG+U1oid7Pva4bbDPHYfJNiB7BiIjRkj1pyC++4N3huJfqY6aRH6VTB0rvtzQwjM4K6qpfOig==" - }, - "node_modules/tsutils": { - "version": "3.21.0", - "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.21.0.tgz", - "integrity": "sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==", - "dev": true, - "dependencies": { - "tslib": "^1.8.1" - }, - "engines": { - "node": ">= 6" - }, - "peerDependencies": { - "typescript": ">=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta" - } - }, - "node_modules/tsutils/node_modules/tslib": { - "version": "1.14.1", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", - "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==", - "dev": true - }, - "node_modules/tty-browserify": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/tty-browserify/-/tty-browserify-0.0.1.tgz", - "integrity": "sha512-C3TaO7K81YvjCgQH9Q1S3R3P3BtN3RIM8n+OvX4il1K1zgE8ZhI0op7kClgkxtutIE8hQrcrHBXvIheqKUUCxw==", - "dev": true - }, - "node_modules/tweetnacl": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz", - "integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==" - }, - "node_modules/type-check": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", - "integrity": "sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==", - "dev": true, - "dependencies": { - "prelude-ls": "^1.2.1" - }, - "engines": { - "node": ">= 0.8.0" - } - }, - "node_modules/type-detect": { - "version": "4.0.8", - "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", - "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==", - "engines": { - "node": ">=4" - } - }, - "node_modules/type-fest": { - "version": "0.20.2", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz", - "integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==", - "dev": true, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/type-is": { - "version": "1.6.18", - "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", - "integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==", - "dev": true, - "dependencies": { - "media-typer": "0.3.0", - "mime-types": "~2.1.24" - }, - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/typescript": { - "version": "5.1.6", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.1.6.tgz", - "integrity": "sha512-zaWCozRZ6DLEWAWFrVDz1H6FVXzUSfTy5FUMWsQlU8Ym5JP9eO4xkTIROFCQvhQf61z6O/G6ugw3SgAnvvm+HA==", - "dev": true, - "bin": { - "tsc": "bin/tsc", - "tsserver": "bin/tsserver" - }, - "engines": { - "node": ">=14.17" - } - }, - "node_modules/ua-parser-js": { - "version": "0.7.35", - "resolved": "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-0.7.35.tgz", - "integrity": "sha512-veRf7dawaj9xaWEu9HoTVn5Pggtc/qj+kqTOFvNiN1l0YdxwC1kvel57UCjThjGa3BHBihE8/UJAHI+uQHmd/g==", - "dev": true, - "funding": [ - { - "type": "opencollective", - "url": "https://opencollective.com/ua-parser-js" - }, - { - "type": "paypal", - "url": "https://paypal.me/faisalman" - } - ], - "engines": { - "node": "*" - } - }, - "node_modules/uint8arraylist": { - "version": "2.4.3", - "resolved": "https://registry.npmjs.org/uint8arraylist/-/uint8arraylist-2.4.3.tgz", - "integrity": "sha512-oEVZr4/GrH87K0kjNce6z8pSCzLEPqHNLNR5sj8cJOySrTP8Vb/pMIbZKLJGhQKxm1TiZ31atNrpn820Pyqpow==", - "dependencies": { - "uint8arrays": "^4.0.2" - }, - "engines": { - "node": ">=16.0.0", - "npm": ">=7.0.0" - } - }, - "node_modules/uint8arrays": { - "version": "4.0.6", - "resolved": "https://registry.npmjs.org/uint8arrays/-/uint8arrays-4.0.6.tgz", - "integrity": "sha512-4ZesjQhqOU2Ip6GPReIwN60wRxIupavL8T0Iy36BBHr2qyMrNxsPJvr7vpS4eFt8F8kSguWUPad6ZM9izs/vyw==", - "dependencies": { - "multiformats": "^12.0.1" - } - }, - "node_modules/uint8arrays/node_modules/multiformats": { - "version": "12.0.1", - "resolved": "https://registry.npmjs.org/multiformats/-/multiformats-12.0.1.tgz", - "integrity": "sha512-s01wijBJoDUqESWSzePY0lvTw7J3PVO9x2Cc6ASI5AMZM2Gnhh7BC17+nlFhHKU7dDzaCaRfb+NiqNzOsgPUoQ==", - "engines": { - "node": ">=16.0.0", - "npm": ">=7.0.0" - } - }, - "node_modules/ulid": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/ulid/-/ulid-2.3.0.tgz", - "integrity": "sha512-keqHubrlpvT6G2wH0OEfSW4mquYRcbe/J8NMmveoQOjUqmo+hXtO+ORCpWhdbZ7k72UtY61BL7haGxW6enBnjw==", - "bin": { - "ulid": "bin/cli.js" - } - }, - "node_modules/universalify": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", - "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==", - "dev": true, - "engines": { - "node": ">= 4.0.0" - } - }, - "node_modules/unpipe": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", - "integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==", - "dev": true, - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/update-browserslist-db": { - "version": "1.0.11", - "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.0.11.tgz", - "integrity": "sha512-dCwEFf0/oT85M1fHBg4F0jtLwJrutGoHSQXCh7u4o2t1drG+c0a9Flnqww6XUKSfQMPpJBRjU8d4RXB09qtvaA==", - "dev": true, - "funding": [ - { - "type": "opencollective", - "url": "https://opencollective.com/browserslist" - }, - { - "type": "tidelift", - "url": "https://tidelift.com/funding/github/npm/browserslist" - }, - { - "type": "github", - "url": "https://github.com/sponsors/ai" - } - ], - "peer": true, - "dependencies": { - "escalade": "^3.1.1", - "picocolors": "^1.0.0" - }, - "bin": { - "update-browserslist-db": "cli.js" - }, - "peerDependencies": { - "browserslist": ">= 4.21.0" - } - }, - "node_modules/uri-js": { - "version": "4.4.1", - "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", - "integrity": "sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==", - "dependencies": { - "punycode": "^2.1.0" - } - }, - "node_modules/uri-js/node_modules/punycode": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.0.tgz", - "integrity": "sha512-rRV+zQD8tVFys26lAGR9WUuS4iUAngJScM+ZRSKtvl5tKeZ2t5bvdNFdNHBW9FWR4guGHlgmsZ1G7BSm2wTbuA==", - "engines": { - "node": ">=6" - } - }, - "node_modules/url": { - "version": "0.11.1", - "resolved": "https://registry.npmjs.org/url/-/url-0.11.1.tgz", - "integrity": "sha512-rWS3H04/+mzzJkv0eZ7vEDGiQbgquI1fGfOad6zKvgYQi1SzMmhl7c/DdRGxhaWrVH6z0qWITo8rpnxK/RfEhA==", - "dev": true, - "dependencies": { - "punycode": "^1.4.1", - "qs": "^6.11.0" - } - }, - "node_modules/util": { - "version": "0.12.5", - "resolved": "https://registry.npmjs.org/util/-/util-0.12.5.tgz", - "integrity": "sha512-kZf/K6hEIrWHI6XqOFUiiMa+79wE/D8Q+NCNAWclkyg3b4d2k7s0QGepNjiABc+aR3N1PAyHL7p6UcLY6LmrnA==", - "dev": true, - "dependencies": { - "inherits": "^2.0.3", - "is-arguments": "^1.0.4", - "is-generator-function": "^1.0.7", - "is-typed-array": "^1.1.3", - "which-typed-array": "^1.1.2" - } - }, - "node_modules/util-deprecate": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", - "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==" - }, - "node_modules/utils-merge": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", - "integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==", - "dev": true, - "engines": { - "node": ">= 0.4.0" - } - }, - "node_modules/uuid": { - "version": "9.0.0", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.0.tgz", - "integrity": "sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg==", - "bin": { - "uuid": "dist/bin/uuid" - } - }, - "node_modules/v8-to-istanbul": { - "version": "9.1.0", - "resolved": "https://registry.npmjs.org/v8-to-istanbul/-/v8-to-istanbul-9.1.0.tgz", - "integrity": "sha512-6z3GW9x8G1gd+JIIgQQQxXuiJtCXeAjp6RaPEPLv62mH3iPHPxV6W3robxtCzNErRo6ZwTmzWhsbNvjyEBKzKA==", - "dev": true, - "dependencies": { - "@jridgewell/trace-mapping": "^0.3.12", - "@types/istanbul-lib-coverage": "^2.0.1", - "convert-source-map": "^1.6.0" - }, - "engines": { - "node": ">=10.12.0" - } - }, - "node_modules/varint": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/varint/-/varint-6.0.0.tgz", - "integrity": "sha512-cXEIW6cfr15lFv563k4GuVuW/fiwjknytD37jIOLSdSWuOI6WnO/oKwmP2FQTU2l01LP8/M5TSAJpzUaGe3uWg==" - }, - "node_modules/vary": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", - "integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==", - "dev": true, - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/vm-browserify": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/vm-browserify/-/vm-browserify-1.1.2.tgz", - "integrity": "sha512-2ham8XPWTONajOR0ohOKOHXkm3+gaBmGut3SRuu75xLd/RRaY6vqgh8NBYYk7+RW3u5AtzPQZG8F10LHkl0lAQ==", - "dev": true - }, - "node_modules/void-elements": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/void-elements/-/void-elements-2.0.1.tgz", - "integrity": "sha512-qZKX4RnBzH2ugr8Lxa7x+0V6XD9Sb/ouARtiasEQCHB1EVU4NXtmHsDDrx1dO4ne5fc3J6EW05BP1Dl0z0iung==", - "dev": true, - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/watchpack": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/watchpack/-/watchpack-2.4.0.tgz", - "integrity": "sha512-Lcvm7MGST/4fup+ifyKi2hjyIAwcdI4HRgtvTpIUxBRhB+RFtUh8XtDOxUfctVCnhVi+QQj49i91OyvzkJl6cg==", - "dev": true, - "peer": true, - "dependencies": { - "glob-to-regexp": "^0.4.1", - "graceful-fs": "^4.1.2" - }, - "engines": { - "node": ">=10.13.0" - } - }, - "node_modules/webidl-conversions": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", - "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==" - }, - "node_modules/webpack": { - "version": "5.88.2", - "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.88.2.tgz", - "integrity": "sha512-JmcgNZ1iKj+aiR0OvTYtWQqJwq37Pf683dY9bVORwVbUrDhLhdn/PlO2sHsFHPkj7sHNQF3JwaAkp49V+Sq1tQ==", - "dev": true, - "peer": true, - "dependencies": { - "@types/eslint-scope": "^3.7.3", - "@types/estree": "^1.0.0", - "@webassemblyjs/ast": "^1.11.5", - "@webassemblyjs/wasm-edit": "^1.11.5", - "@webassemblyjs/wasm-parser": "^1.11.5", - "acorn": "^8.7.1", - "acorn-import-assertions": "^1.9.0", - "browserslist": "^4.14.5", - "chrome-trace-event": "^1.0.2", - "enhanced-resolve": "^5.15.0", - "es-module-lexer": "^1.2.1", - "eslint-scope": "5.1.1", - "events": "^3.2.0", - "glob-to-regexp": "^0.4.1", - "graceful-fs": "^4.2.9", - "json-parse-even-better-errors": "^2.3.1", - "loader-runner": "^4.2.0", - "mime-types": "^2.1.27", - "neo-async": "^2.6.2", - "schema-utils": "^3.2.0", - "tapable": "^2.1.1", - "terser-webpack-plugin": "^5.3.7", - "watchpack": "^2.4.0", - "webpack-sources": "^3.2.3" - }, - "bin": { - "webpack": "bin/webpack.js" - }, - "engines": { - "node": ">=10.13.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/webpack" - }, - "peerDependenciesMeta": { - "webpack-cli": { - "optional": true - } - } - }, - "node_modules/webpack-sources": { - "version": "3.2.3", - "resolved": "https://registry.npmjs.org/webpack-sources/-/webpack-sources-3.2.3.tgz", - "integrity": "sha512-/DyMEOrDgLKKIG0fmvtz+4dUX/3Ghozwgm6iPp8KRhvn+eQf9+Q7GWxVNMk3+uCPWfdXYC4ExGBckIXdFEfH1w==", - "dev": true, - "peer": true, - "engines": { - "node": ">=10.13.0" - } - }, - "node_modules/whatwg-url": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", - "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", - "dependencies": { - "tr46": "~0.0.3", - "webidl-conversions": "^3.0.0" - } - }, - "node_modules/which": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", - "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", - "dev": true, - "dependencies": { - "isexe": "^2.0.0" - }, - "bin": { - "node-which": "bin/node-which" - }, - "engines": { - "node": ">= 8" - } - }, - "node_modules/which-typed-array": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/which-typed-array/-/which-typed-array-1.1.11.tgz", - "integrity": "sha512-qe9UWWpkeG5yzZ0tNYxDmd7vo58HDBc39mZ0xWWpolAGADdFOzkfamWLDxkOWcvHQKVmdTyQdLD4NOfjLWTKew==", - "dev": true, - "dependencies": { - "available-typed-arrays": "^1.0.5", - "call-bind": "^1.0.2", - "for-each": "^0.3.3", - "gopd": "^1.0.1", - "has-tostringtag": "^1.0.0" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/workerpool": { - "version": "6.2.1", - "resolved": "https://registry.npmjs.org/workerpool/-/workerpool-6.2.1.tgz", - "integrity": "sha512-ILEIE97kDZvF9Wb9f6h5aXK4swSlKGUcOEGiIYb2OOu/IrDU9iwj0fD//SsA6E5ibwJxpEvhullJY4Sl4GcpAw==", - "dev": true - }, - "node_modules/wrap-ansi": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", - "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", - "dev": true, - "dependencies": { - "ansi-styles": "^4.0.0", - "string-width": "^4.1.0", - "strip-ansi": "^6.0.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/chalk/wrap-ansi?sponsor=1" - } - }, - "node_modules/wrappy": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", - "dev": true - }, - "node_modules/ws": { - "version": "8.11.0", - "resolved": "https://registry.npmjs.org/ws/-/ws-8.11.0.tgz", - "integrity": "sha512-HPG3wQd9sNQoT9xHyNCXoDUa+Xw/VevmY9FoHyQ+g+rrMn4j6FB4np7Z0OhdTgjx6MgQLK7jwSy1YecU1+4Asg==", - "dev": true, - "engines": { - "node": ">=10.0.0" - }, - "peerDependencies": { - "bufferutil": "^4.0.1", - "utf-8-validate": "^5.0.2" - }, - "peerDependenciesMeta": { - "bufferutil": { - "optional": true - }, - "utf-8-validate": { - "optional": true - } - } - }, - "node_modules/xtend": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", - "integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==", - "dev": true, - "engines": { - "node": ">=0.4" - } - }, - "node_modules/y18n": { - "version": "5.0.8", - "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", - "integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==", - "dev": true, - "engines": { - "node": ">=10" - } - }, - "node_modules/yallist": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", - "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", - "dev": true - }, - "node_modules/yargs": { - "version": "16.2.0", - "resolved": "https://registry.npmjs.org/yargs/-/yargs-16.2.0.tgz", - "integrity": "sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw==", - "dev": true, - "dependencies": { - "cliui": "^7.0.2", - "escalade": "^3.1.1", - "get-caller-file": "^2.0.5", - "require-directory": "^2.1.1", - "string-width": "^4.2.0", - "y18n": "^5.0.5", - "yargs-parser": "^20.2.2" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/yargs-parser": { - "version": "20.2.9", - "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-20.2.9.tgz", - "integrity": "sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w==", - "dev": true, - "engines": { - "node": ">=10" - } - }, - "node_modules/yargs-unparser": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/yargs-unparser/-/yargs-unparser-2.0.0.tgz", - "integrity": "sha512-7pRTIA9Qc1caZ0bZ6RYRGbHJthJWuakf+WmHK0rVeLkNrrGhfoabBNdue6kdINI6r4if7ocq9aD/n7xwKOdzOA==", - "dev": true, - "dependencies": { - "camelcase": "^6.0.0", - "decamelize": "^4.0.0", - "flat": "^5.0.2", - "is-plain-obj": "^2.1.0" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/yocto-queue": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", - "integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==", - "dev": true, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "packages/common": { - "name": "@tbd54566975/common", - "version": "0.8.0", - "license": "Apache-2.0", - "dependencies": { - "multiformats": "11.0.2" - }, - "devDependencies": { - "@types/chai": "4.3.0", - "@types/eslint": "8.37.0", - "@types/mocha": "10.0.1", - "@typescript-eslint/eslint-plugin": "5.59.0", - "@typescript-eslint/parser": "5.59.0", - "c8": "8.0.0", - "chai": "4.3.7", - "esbuild": "0.16.17", - "eslint": "8.39.0", - "eslint-plugin-mocha": "10.1.0", - "karma": "6.4.1", - "karma-chai": "0.1.0", - "karma-chrome-launcher": "3.1.1", - "karma-esbuild": "2.2.5", - "karma-firefox-launcher": "2.1.2", - "karma-mocha": "2.0.1", - "karma-mocha-reporter": "2.2.5", - "karma-webkit-launcher": "2.1.0", - "mocha": "10.2.0", - "playwright": "1.36.2", - "rimraf": "4.4.0", - "typescript": "5.1.6" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "packages/credentials": { - "name": "@tbd54566975/credentials", - "version": "0.8.0", - "license": "Apache-2.0", - "devDependencies": { - "@types/chai": "4.3.0", - "@types/eslint": "8.37.0", - "@types/mocha": "10.0.1", - "@typescript-eslint/eslint-plugin": "5.59.0", - "@typescript-eslint/parser": "5.59.0", - "c8": "8.0.0", - "chai": "4.3.7", - "esbuild": "0.16.17", - "eslint": "8.39.0", - "eslint-plugin-mocha": "10.1.0", - "karma": "6.4.1", - "karma-chai": "0.1.0", - "karma-chrome-launcher": "3.1.1", - "karma-esbuild": "2.2.5", - "karma-firefox-launcher": "2.1.2", - "karma-mocha": "2.0.1", - "karma-mocha-reporter": "2.2.5", - "karma-webkit-launcher": "2.1.0", - "mocha": "10.2.0", - "playwright": "1.36.2", - "rimraf": "4.4.0", - "typescript": "5.1.6" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "packages/crypto": { - "name": "@tbd54566975/crypto", - "version": "0.8.0", - "license": "Apache-2.0", - "dependencies": { - "@noble/ciphers": "0.1.3", - "@noble/curves": "1.1.0", - "@noble/hashes": "1.3.1", - "@tbd54566975/common": "0.8.0", - "ed2curve": "0.3.0" - }, - "devDependencies": { - "@types/chai": "4.3.0", - "@types/chai-as-promised": "7.1.5", - "@types/ed2curve": "0.2.2", - "@types/eslint": "8.37.0", - "@types/mocha": "10.0.1", - "@types/sinon": "10.0.15", - "@types/uuid": "9.0.1", - "@typescript-eslint/eslint-plugin": "5.59.0", - "@typescript-eslint/parser": "5.59.0", - "c8": "8.0.0", - "chai": "4.3.7", - "chai-as-promised": "7.1.1", - "esbuild": "0.16.17", - "eslint": "8.39.0", - "eslint-plugin-mocha": "10.1.0", - "karma": "6.4.1", - "karma-chai": "0.1.0", - "karma-chrome-launcher": "3.1.1", - "karma-esbuild": "2.2.5", - "karma-firefox-launcher": "2.1.2", - "karma-mocha": "2.0.1", - "karma-mocha-reporter": "2.2.5", - "karma-webkit-launcher": "2.1.0", - "mocha": "10.2.0", - "playwright": "1.36.2", - "rimraf": "4.4.0", - "sinon": "15.0.2", - "source-map-loader": "4.0.1", - "typescript": "5.1.6" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "packages/dids": { - "name": "@tbd54566975/dids", - "version": "0.8.0", - "license": "Apache-2.0", - "dependencies": { - "@decentralized-identity/ion-tools": "1.1.4", - "@tbd54566975/common": "0.8.0", - "@tbd54566975/crypto": "0.8.0", - "@tbd54566975/dwn-sdk-js": "0.2.1", - "cross-fetch": "4.0.0" - }, - "devDependencies": { - "@types/chai": "4.3.0", - "@types/chai-as-promised": "7.1.5", - "@types/eslint": "8.37.0", - "@types/mocha": "10.0.1", - "@types/sinon": "10.0.15", - "@typescript-eslint/eslint-plugin": "5.59.0", - "@typescript-eslint/parser": "5.59.0", - "c8": "8.0.0", - "chai": "4.3.7", - "chai-as-promised": "7.1.1", - "esbuild": "0.16.17", - "eslint": "8.39.0", - "eslint-plugin-mocha": "10.1.0", - "karma": "6.4.1", - "karma-chai": "0.1.0", - "karma-chrome-launcher": "3.1.1", - "karma-esbuild": "2.2.5", - "karma-firefox-launcher": "2.1.2", - "karma-mocha": "2.0.1", - "karma-mocha-reporter": "2.2.5", - "karma-webkit-launcher": "2.1.0", - "mocha": "10.2.0", - "node-stdlib-browser": "1.2.0", - "playwright": "1.36.2", - "rimraf": "4.4.0", - "sinon": "15.0.2", - "source-map-loader": "4.0.1", - "typescript": "5.1.6" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "packages/web5": { - "name": "@tbd54566975/web5", - "version": "0.8.0", - "license": "Apache-2.0", - "dependencies": { - "@decentralized-identity/ion-tools": "1.1.4", - "@tbd54566975/crypto": "0.8.0", - "@tbd54566975/dids": "0.8.0", - "@tbd54566975/dwn-sdk-js": "0.2.1", - "@tbd54566975/web5-agent": "0.8.0", - "@tbd54566975/web5-proxy-agent": "0.8.0", - "@tbd54566975/web5-user-agent": "0.8.0", - "level": "8.0.0", - "ms": "2.1.3", - "readable-web-to-node-stream": "3.0.2" - }, - "devDependencies": { - "@types/chai": "4.3.0", - "@types/chai-as-promised": "7.1.5", - "@types/eslint": "8.37.0", - "@types/mocha": "10.0.1", - "@types/ms": "0.7.31", - "@types/readable-stream": "2.3.15", - "@types/sinon": "10.0.15", - "@typescript-eslint/eslint-plugin": "5.59.0", - "@typescript-eslint/parser": "5.59.0", - "c8": "8.0.0", - "chai": "4.3.7", - "chai-as-promised": "7.1.1", - "esbuild": "0.16.17", - "eslint": "8.39.0", - "eslint-plugin-mocha": "10.1.0", - "karma": "6.4.1", - "karma-chai": "0.1.0", - "karma-chrome-launcher": "3.1.1", - "karma-esbuild": "2.2.5", - "karma-firefox-launcher": "2.1.2", - "karma-mocha": "2.0.1", - "karma-mocha-reporter": "2.2.5", - "karma-webkit-launcher": "2.1.0", - "mocha": "10.2.0", - "node-stdlib-browser": "1.2.0", - "playwright": "1.36.2", - "rimraf": "4.4.0", - "sinon": "15.0.2", - "source-map-loader": "4.0.1", - "typescript": "5.1.6" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "packages/web5-agent": { - "name": "@tbd54566975/web5-agent", - "version": "0.8.0", - "license": "Apache-2.0", - "dependencies": { - "@tbd54566975/dwn-sdk-js": "0.2.1", - "readable-stream": "4.4.0" - }, - "devDependencies": { - "@types/chai": "4.3.0", - "@types/chai-as-promised": "7.1.5", - "@types/eslint": "8.37.0", - "@types/mocha": "10.0.1", - "@types/readable-stream": "2.3.15", - "@types/sinon": "10.0.15", - "@typescript-eslint/eslint-plugin": "5.59.0", - "@typescript-eslint/parser": "5.59.0", - "c8": "8.0.0", - "chai": "4.3.7", - "chai-as-promised": "7.1.1", - "esbuild": "0.16.17", - "eslint": "8.39.0", - "eslint-plugin-mocha": "10.1.0", - "karma": "6.4.1", - "karma-chai": "0.1.0", - "karma-chrome-launcher": "3.1.1", - "karma-esbuild": "2.2.5", - "karma-firefox-launcher": "2.1.2", - "karma-mocha": "2.0.1", - "karma-mocha-reporter": "2.2.5", - "karma-webkit-launcher": "2.1.0", - "mocha": "10.2.0", - "playwright": "1.36.2", - "rimraf": "4.4.0", - "sinon": "15.0.2", - "source-map-loader": "4.0.1", - "typescript": "5.1.6" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "packages/web5-proxy-agent": { - "name": "@tbd54566975/web5-proxy-agent", - "version": "0.8.0", - "license": "Apache-2.0", - "dependencies": { - "@tbd54566975/web5-agent": "0.8.0" - }, - "devDependencies": { - "@types/chai": "4.3.0", - "@types/chai-as-promised": "7.1.5", - "@types/ed2curve": "0.2.2", - "@types/eslint": "8.37.0", - "@types/mocha": "10.0.1", - "@types/sinon": "10.0.15", - "@typescript-eslint/eslint-plugin": "5.59.0", - "@typescript-eslint/parser": "5.59.0", - "c8": "8.0.0", - "chai": "4.3.7", - "chai-as-promised": "7.1.1", - "esbuild": "0.16.17", - "eslint": "8.39.0", - "eslint-plugin-mocha": "10.1.0", - "karma": "6.4.1", - "karma-chai": "0.1.0", - "karma-chrome-launcher": "3.1.1", - "karma-esbuild": "2.2.5", - "karma-firefox-launcher": "2.1.2", - "karma-mocha": "2.0.1", - "karma-mocha-reporter": "2.2.5", - "karma-webkit-launcher": "2.1.0", - "mocha": "10.2.0", - "playwright": "1.36.2", - "rimraf": "4.4.0", - "sinon": "15.0.2", - "source-map-loader": "4.0.1", - "typescript": "5.1.6" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "packages/web5-user-agent": { - "name": "@tbd54566975/web5-user-agent", - "version": "0.8.0", - "license": "Apache-2.0", - "dependencies": { - "@decentralized-identity/ion-tools": "1.1.4", - "@tbd54566975/dids": "0.8.0", - "@tbd54566975/dwn-sdk-js": "0.2.1", - "@tbd54566975/web5-agent": "0.8.0", - "abstract-level": "1.0.3", - "cross-fetch": "4.0.0", - "flat": "5.0.2", - "level": "8.0.0", - "readable-web-to-node-stream": "3.0.2", - "uuid": "9.0.0" - }, - "devDependencies": { - "@faker-js/faker": "8.0.1", - "@types/chai": "4.3.0", - "@types/chai-as-promised": "7.1.5", - "@types/flat": "5.0.2", - "@types/mocha": "10.0.1", - "@types/readable-stream": "2.3.15", - "@types/sinon": "10.0.15", - "@typescript-eslint/eslint-plugin": "5.59.0", - "@typescript-eslint/parser": "5.59.0", - "c8": "8.0.0", - "chai": "4.3.7", - "chai-as-promised": "7.1.1", - "esbuild": "0.16.17", - "eslint": "8.39.0", - "eslint-plugin-mocha": "10.1.0", - "karma": "6.4.1", - "karma-chai": "0.1.0", - "karma-chrome-launcher": "3.1.1", - "karma-esbuild": "2.2.5", - "karma-firefox-launcher": "2.1.2", - "karma-mocha": "2.0.1", - "karma-mocha-reporter": "2.2.5", - "karma-webkit-launcher": "2.1.0", - "mocha": "10.2.0", - "node-stdlib-browser": "1.2.0", - "playwright": "1.36.2", - "rimraf": "4.4.0", - "sinon": "15.0.2", - "source-map-loader": "4.0.1", - "typescript": "5.1.6" - }, - "engines": { - "node": ">=18.0.0" - } + "name": "web5-js", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "workspaces": [ + "packages/common", + "packages/crypto", + "packages/dids", + "packages/credentials", + "packages/agent", + "packages/user-agent", + "packages/proxy-agent", + "packages/api", + "packages/identity-agent", + "packages/bonanza" + ] + }, + "node_modules/@aashutoshrathi/word-wrap": { + "version": "1.2.6", + "resolved": "https://registry.npmjs.org/@aashutoshrathi/word-wrap/-/word-wrap-1.2.6.tgz", + "integrity": "sha512-1Yjs2SvM8TflER/OD3cOjhWWOZb58A2t7wpE2S9XfBYTiIl+XFhQG2bjy4Pu1I+EAlCNUzRDYDdFwFYUKvXcIA==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/@assemblyscript/loader": { + "version": "0.9.4", + "resolved": "https://registry.npmjs.org/@assemblyscript/loader/-/loader-0.9.4.tgz", + "integrity": "sha512-HazVq9zwTVwGmqdwYzu7WyQ6FQVZ7SwET0KKQuKm55jD0IfUpZgN0OPIiZG3zV1iSrVYcN0bdwLRXI/VNCYsUA==" + }, + "node_modules/@bcoe/v8-coverage": { + "version": "0.2.3", + "resolved": "https://registry.npmjs.org/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz", + "integrity": "sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==", + "dev": true + }, + "node_modules/@colors/colors": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/@colors/colors/-/colors-1.5.0.tgz", + "integrity": "sha512-ooWCrlZP11i8GImSjTHYHLkvFDP48nS4+204nGb1RiX/WXYHmJA2III9/e2DWVabCESdW7hBAEzHRqUn9OUVvQ==", + "dev": true, + "engines": { + "node": ">=0.1.90" + } + }, + "node_modules/@decentralized-identity/ion-pow-sdk": { + "version": "1.0.17", + "resolved": "https://registry.npmjs.org/@decentralized-identity/ion-pow-sdk/-/ion-pow-sdk-1.0.17.tgz", + "integrity": "sha512-vk7DTDM8aKDbFyu1ad/qkoRrGL4q+KvNeL/FNZXhkWPaDhVExBN/qGEoRLf1YSfFe+myto3+4RYTPut+riiqnw==", + "dependencies": { + "buffer": "6.0.3", + "cross-fetch": "3.1.5", + "hash-wasm": "4.9.0" + } + }, + "node_modules/@decentralized-identity/ion-sdk": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@decentralized-identity/ion-sdk/-/ion-sdk-1.0.1.tgz", + "integrity": "sha512-+P+DXcRSFjsEsI5KIqUmVjpzgUT28B2lWpTO+IxiBcfibAN/1Sg20NebGTO/+serz2CnSZf95N2a1OZ6eXypGQ==", + "dependencies": { + "@noble/ed25519": "^2.0.0", + "@noble/secp256k1": "^2.0.0", + "canonicalize": "^2.0.0", + "multiformats": "^12.0.1", + "multihashes": "^4.0.3", + "uri-js": "^4.4.1" + } + }, + "node_modules/@decentralized-identity/ion-sdk/node_modules/multiformats": { + "version": "12.0.1", + "resolved": "https://registry.npmjs.org/multiformats/-/multiformats-12.0.1.tgz", + "integrity": "sha512-s01wijBJoDUqESWSzePY0lvTw7J3PVO9x2Cc6ASI5AMZM2Gnhh7BC17+nlFhHKU7dDzaCaRfb+NiqNzOsgPUoQ==", + "engines": { + "node": ">=16.0.0", + "npm": ">=7.0.0" + } + }, + "node_modules/@esbuild/android-arm": { + "version": "0.16.17", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.16.17.tgz", + "integrity": "sha512-N9x1CMXVhtWEAMS7pNNONyA14f71VPQN9Cnavj1XQh6T7bskqiLLrSca4O0Vr8Wdcga943eThxnVp3JLnBMYtw==", + "cpu": [ + "arm" + ], + "dev": true, + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/android-arm64": { + "version": "0.16.17", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.16.17.tgz", + "integrity": "sha512-MIGl6p5sc3RDTLLkYL1MyL8BMRN4tLMRCn+yRJJmEDvYZ2M7tmAf80hx1kbNEUX2KJ50RRtxZ4JHLvCfuB6kBg==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/android-x64": { + "version": "0.16.17", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.16.17.tgz", + "integrity": "sha512-a3kTv3m0Ghh4z1DaFEuEDfz3OLONKuFvI4Xqczqx4BqLyuFaFkuaG4j2MtA6fuWEFeC5x9IvqnX7drmRq/fyAQ==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/darwin-arm64": { + "version": "0.16.17", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.16.17.tgz", + "integrity": "sha512-/2agbUEfmxWHi9ARTX6OQ/KgXnOWfsNlTeLcoV7HSuSTv63E4DqtAc+2XqGw1KHxKMHGZgbVCZge7HXWX9Vn+w==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/darwin-x64": { + "version": "0.16.17", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.16.17.tgz", + "integrity": "sha512-2By45OBHulkd9Svy5IOCZt376Aa2oOkiE9QWUK9fe6Tb+WDr8hXL3dpqi+DeLiMed8tVXspzsTAvd0jUl96wmg==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/freebsd-arm64": { + "version": "0.16.17", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.16.17.tgz", + "integrity": "sha512-mt+cxZe1tVx489VTb4mBAOo2aKSnJ33L9fr25JXpqQqzbUIw/yzIzi+NHwAXK2qYV1lEFp4OoVeThGjUbmWmdw==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/freebsd-x64": { + "version": "0.16.17", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.16.17.tgz", + "integrity": "sha512-8ScTdNJl5idAKjH8zGAsN7RuWcyHG3BAvMNpKOBaqqR7EbUhhVHOqXRdL7oZvz8WNHL2pr5+eIT5c65kA6NHug==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-arm": { + "version": "0.16.17", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.16.17.tgz", + "integrity": "sha512-iihzrWbD4gIT7j3caMzKb/RsFFHCwqqbrbH9SqUSRrdXkXaygSZCZg1FybsZz57Ju7N/SHEgPyaR0LZ8Zbe9gQ==", + "cpu": [ + "arm" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-arm64": { + "version": "0.16.17", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.16.17.tgz", + "integrity": "sha512-7S8gJnSlqKGVJunnMCrXHU9Q8Q/tQIxk/xL8BqAP64wchPCTzuM6W3Ra8cIa1HIflAvDnNOt2jaL17vaW+1V0g==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-ia32": { + "version": "0.16.17", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.16.17.tgz", + "integrity": "sha512-kiX69+wcPAdgl3Lonh1VI7MBr16nktEvOfViszBSxygRQqSpzv7BffMKRPMFwzeJGPxcio0pdD3kYQGpqQ2SSg==", + "cpu": [ + "ia32" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-loong64": { + "version": "0.16.17", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.16.17.tgz", + "integrity": "sha512-dTzNnQwembNDhd654cA4QhbS9uDdXC3TKqMJjgOWsC0yNCbpzfWoXdZvp0mY7HU6nzk5E0zpRGGx3qoQg8T2DQ==", + "cpu": [ + "loong64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-mips64el": { + "version": "0.16.17", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.16.17.tgz", + "integrity": "sha512-ezbDkp2nDl0PfIUn0CsQ30kxfcLTlcx4Foz2kYv8qdC6ia2oX5Q3E/8m6lq84Dj/6b0FrkgD582fJMIfHhJfSw==", + "cpu": [ + "mips64el" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-ppc64": { + "version": "0.16.17", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.16.17.tgz", + "integrity": "sha512-dzS678gYD1lJsW73zrFhDApLVdM3cUF2MvAa1D8K8KtcSKdLBPP4zZSLy6LFZ0jYqQdQ29bjAHJDgz0rVbLB3g==", + "cpu": [ + "ppc64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-riscv64": { + "version": "0.16.17", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.16.17.tgz", + "integrity": "sha512-ylNlVsxuFjZK8DQtNUwiMskh6nT0vI7kYl/4fZgV1llP5d6+HIeL/vmmm3jpuoo8+NuXjQVZxmKuhDApK0/cKw==", + "cpu": [ + "riscv64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-s390x": { + "version": "0.16.17", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.16.17.tgz", + "integrity": "sha512-gzy7nUTO4UA4oZ2wAMXPNBGTzZFP7mss3aKR2hH+/4UUkCOyqmjXiKpzGrY2TlEUhbbejzXVKKGazYcQTZWA/w==", + "cpu": [ + "s390x" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-x64": { + "version": "0.16.17", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.16.17.tgz", + "integrity": "sha512-mdPjPxfnmoqhgpiEArqi4egmBAMYvaObgn4poorpUaqmvzzbvqbowRllQ+ZgzGVMGKaPkqUmPDOOFQRUFDmeUw==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/netbsd-x64": { + "version": "0.16.17", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.16.17.tgz", + "integrity": "sha512-/PzmzD/zyAeTUsduZa32bn0ORug+Jd1EGGAUJvqfeixoEISYpGnAezN6lnJoskauoai0Jrs+XSyvDhppCPoKOA==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/openbsd-x64": { + "version": "0.16.17", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.16.17.tgz", + "integrity": "sha512-2yaWJhvxGEz2RiftSk0UObqJa/b+rIAjnODJgv2GbGGpRwAfpgzyrg1WLK8rqA24mfZa9GvpjLcBBg8JHkoodg==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/sunos-x64": { + "version": "0.16.17", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.16.17.tgz", + "integrity": "sha512-xtVUiev38tN0R3g8VhRfN7Zl42YCJvyBhRKw1RJjwE1d2emWTVToPLNEQj/5Qxc6lVFATDiy6LjVHYhIPrLxzw==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "sunos" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/win32-arm64": { + "version": "0.16.17", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.16.17.tgz", + "integrity": "sha512-ga8+JqBDHY4b6fQAmOgtJJue36scANy4l/rL97W+0wYmijhxKetzZdKOJI7olaBaMhWt8Pac2McJdZLxXWUEQw==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/win32-ia32": { + "version": "0.16.17", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.16.17.tgz", + "integrity": "sha512-WnsKaf46uSSF/sZhwnqE4L/F89AYNMiD4YtEcYekBt9Q7nj0DiId2XH2Ng2PHM54qi5oPrQ8luuzGszqi/veig==", + "cpu": [ + "ia32" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/win32-x64": { + "version": "0.16.17", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.16.17.tgz", + "integrity": "sha512-y+EHuSchhL7FjHgvQL/0fnnFmO4T1bhvWANX6gcnqTjtnKWbTvUMCpGnv2+t+31d7RzyEAYAd4u2fnIhHL6N/Q==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@eslint-community/eslint-utils": { + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/@eslint-community/eslint-utils/-/eslint-utils-4.4.0.tgz", + "integrity": "sha512-1/sA4dwrzBAyeUoQ6oxahHKmrZvsnLCg4RfxW3ZFGGmQkSNQPFNLV9CUEFQP1x9EYXHTo5p6xdhZM1Ne9p/AfA==", + "dev": true, + "dependencies": { + "eslint-visitor-keys": "^3.3.0" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "peerDependencies": { + "eslint": "^6.0.0 || ^7.0.0 || >=8.0.0" + } + }, + "node_modules/@eslint-community/regexpp": { + "version": "4.6.2", + "resolved": "https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.6.2.tgz", + "integrity": "sha512-pPTNuaAG3QMH+buKyBIGJs3g/S5y0caxw0ygM3YyE6yJFySwiGGSzA+mM3KJ8QQvzeLh3blwgSonkFjgQdxzMw==", + "dev": true, + "engines": { + "node": "^12.0.0 || ^14.0.0 || >=16.0.0" + } + }, + "node_modules/@eslint/eslintrc": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-2.1.2.tgz", + "integrity": "sha512-+wvgpDsrB1YqAMdEUCcnTlpfVBH7Vqn6A/NT3D8WVXFIaKMlErPIZT3oCIAVCOtarRpMtelZLqJeU3t7WY6X6g==", + "dev": true, + "dependencies": { + "ajv": "^6.12.4", + "debug": "^4.3.2", + "espree": "^9.6.0", + "globals": "^13.19.0", + "ignore": "^5.2.0", + "import-fresh": "^3.2.1", + "js-yaml": "^4.1.0", + "minimatch": "^3.1.2", + "strip-json-comments": "^3.1.1" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, + "node_modules/@eslint/eslintrc/node_modules/ajv": { + "version": "6.12.6", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", + "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", + "dev": true, + "dependencies": { + "fast-deep-equal": "^3.1.1", + "fast-json-stable-stringify": "^2.0.0", + "json-schema-traverse": "^0.4.1", + "uri-js": "^4.2.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, + "node_modules/@eslint/eslintrc/node_modules/json-schema-traverse": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", + "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", + "dev": true + }, + "node_modules/@eslint/js": { + "version": "8.47.0", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.47.0.tgz", + "integrity": "sha512-P6omY1zv5MItm93kLM8s2vr1HICJH8v0dvddDhysbIuZ+vcjOHg5Zbkf1mTkcmi2JA9oBG2anOkRnW8WJTS8Og==", + "dev": true, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + } + }, + "node_modules/@humanwhocodes/config-array": { + "version": "0.11.10", + "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.10.tgz", + "integrity": "sha512-KVVjQmNUepDVGXNuoRRdmmEjruj0KfiGSbS8LVc12LMsWDQzRXJ0qdhN8L8uUigKpfEHRhlaQFY0ib1tnUbNeQ==", + "dev": true, + "dependencies": { + "@humanwhocodes/object-schema": "^1.2.1", + "debug": "^4.1.1", + "minimatch": "^3.0.5" + }, + "engines": { + "node": ">=10.10.0" + } + }, + "node_modules/@humanwhocodes/module-importer": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@humanwhocodes/module-importer/-/module-importer-1.0.1.tgz", + "integrity": "sha512-bxveV4V8v5Yb4ncFTT3rPSgZBOpCkjfK0y4oVVVJwIuDVBRMDXrPyXRL988i5ap9m9bnyEEjWfm5WkBmtffLfA==", + "dev": true, + "engines": { + "node": ">=12.22" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/nzakas" + } + }, + "node_modules/@humanwhocodes/object-schema": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-1.2.1.tgz", + "integrity": "sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==", + "dev": true + }, + "node_modules/@ipld/dag-cbor": { + "version": "9.0.3", + "resolved": "https://registry.npmjs.org/@ipld/dag-cbor/-/dag-cbor-9.0.3.tgz", + "integrity": "sha512-A2UFccS0+sARK9xwXiVZIaWbLbPxLGP3UZOjBeOMWfDY04SXi8h1+t4rHBzOlKYF/yWNm3RbFLyclWO7hZcy4g==", + "dependencies": { + "cborg": "^2.0.1", + "multiformats": "^12.0.1" + }, + "engines": { + "node": ">=16.0.0", + "npm": ">=7.0.0" + } + }, + "node_modules/@ipld/dag-cbor/node_modules/multiformats": { + "version": "12.0.1", + "resolved": "https://registry.npmjs.org/multiformats/-/multiformats-12.0.1.tgz", + "integrity": "sha512-s01wijBJoDUqESWSzePY0lvTw7J3PVO9x2Cc6ASI5AMZM2Gnhh7BC17+nlFhHKU7dDzaCaRfb+NiqNzOsgPUoQ==", + "engines": { + "node": ">=16.0.0", + "npm": ">=7.0.0" + } + }, + "node_modules/@ipld/dag-pb": { + "version": "4.0.5", + "resolved": "https://registry.npmjs.org/@ipld/dag-pb/-/dag-pb-4.0.5.tgz", + "integrity": "sha512-El2Jhmv6bWuakhvnw1dl6xOhqLeVhlY8DIAJ06NtZRAoDcOzeGzvOtPzMCszVgCT0EQz+LOctyfgQ5Oszba19A==", + "dependencies": { + "multiformats": "^12.0.1" + }, + "engines": { + "node": ">=16.0.0", + "npm": ">=7.0.0" + } + }, + "node_modules/@ipld/dag-pb/node_modules/multiformats": { + "version": "12.0.1", + "resolved": "https://registry.npmjs.org/multiformats/-/multiformats-12.0.1.tgz", + "integrity": "sha512-s01wijBJoDUqESWSzePY0lvTw7J3PVO9x2Cc6ASI5AMZM2Gnhh7BC17+nlFhHKU7dDzaCaRfb+NiqNzOsgPUoQ==", + "engines": { + "node": ">=16.0.0", + "npm": ">=7.0.0" + } + }, + "node_modules/@istanbuljs/schema": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/@istanbuljs/schema/-/schema-0.1.3.tgz", + "integrity": "sha512-ZXRY4jNvVgSVQ8DL3LTcakaAtXwTVUxE81hslsyD2AtoXW/wVob10HkOJ1X/pAlcI7D+2YoZKg5do8G/w6RYgA==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/@jridgewell/gen-mapping": { + "version": "0.3.3", + "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.3.tgz", + "integrity": "sha512-HLhSWOLRi875zjjMG/r+Nv0oCW8umGb0BgEhyX3dDX3egwZtB8PqLnjz3yedt8R5StBrzcg4aBpnh8UA9D1BoQ==", + "dev": true, + "peer": true, + "dependencies": { + "@jridgewell/set-array": "^1.0.1", + "@jridgewell/sourcemap-codec": "^1.4.10", + "@jridgewell/trace-mapping": "^0.3.9" + }, + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@jridgewell/resolve-uri": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.1.tgz", + "integrity": "sha512-dSYZh7HhCDtCKm4QakX0xFpsRDqjjtZf/kjI/v3T3Nwt5r8/qz/M19F9ySyOqU94SXBmeG9ttTul+YnR4LOxFA==", + "dev": true, + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@jridgewell/set-array": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@jridgewell/set-array/-/set-array-1.1.2.tgz", + "integrity": "sha512-xnkseuNADM0gt2bs+BvhO0p78Mk762YnZdsuzFV018NoG1Sj1SCQvpSqa7XUaTam5vAGasABV9qXASMKnFMwMw==", + "dev": true, + "peer": true, + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@jridgewell/source-map": { + "version": "0.3.5", + "resolved": "https://registry.npmjs.org/@jridgewell/source-map/-/source-map-0.3.5.tgz", + "integrity": "sha512-UTYAUj/wviwdsMfzoSJspJxbkH5o1snzwX0//0ENX1u/55kkZZkcTZP6u9bwKGkv+dkk9at4m1Cpt0uY80kcpQ==", + "dev": true, + "peer": true, + "dependencies": { + "@jridgewell/gen-mapping": "^0.3.0", + "@jridgewell/trace-mapping": "^0.3.9" + } + }, + "node_modules/@jridgewell/sourcemap-codec": { + "version": "1.4.15", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.15.tgz", + "integrity": "sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==", + "dev": true + }, + "node_modules/@jridgewell/trace-mapping": { + "version": "0.3.19", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.19.tgz", + "integrity": "sha512-kf37QtfW+Hwx/buWGMPcR60iF9ziHa6r/CZJIHbmcm4+0qrXiVdxegAH0F6yddEVQ7zdkjcGCgCzUu+BcbhQxw==", + "dev": true, + "dependencies": { + "@jridgewell/resolve-uri": "^3.1.0", + "@jridgewell/sourcemap-codec": "^1.4.14" + } + }, + "node_modules/@js-temporal/polyfill": { + "version": "0.4.4", + "resolved": "https://registry.npmjs.org/@js-temporal/polyfill/-/polyfill-0.4.4.tgz", + "integrity": "sha512-2X6bvghJ/JAoZO52lbgyAPFj8uCflhTo2g7nkFzEQdXd/D8rEeD4HtmTEpmtGCva260fcd66YNXBOYdnmHqSOg==", + "dependencies": { + "jsbi": "^4.3.0", + "tslib": "^2.4.1" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/@multiformats/base-x": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/@multiformats/base-x/-/base-x-4.0.1.tgz", + "integrity": "sha512-eMk0b9ReBbV23xXU693TAIrLyeO5iTgBZGSJfpqriG8UkYvr/hC9u9pyMlAakDNHWmbhMZCDs6KQO0jzKD8OTw==" + }, + "node_modules/@multiformats/murmur3": { + "version": "2.1.6", + "resolved": "https://registry.npmjs.org/@multiformats/murmur3/-/murmur3-2.1.6.tgz", + "integrity": "sha512-kpJDN+o8B0gJaaqbdV/spIVPj35hqew4rEw8VzPmcITsLpHSgP8pJDeaVaGGVeX/UM8n4IGctLCxw7PBfVks+A==", + "dependencies": { + "multiformats": "^12.0.1", + "murmurhash3js-revisited": "^3.0.0" + }, + "engines": { + "node": ">=16.0.0", + "npm": ">=7.0.0" + } + }, + "node_modules/@multiformats/murmur3/node_modules/multiformats": { + "version": "12.0.1", + "resolved": "https://registry.npmjs.org/multiformats/-/multiformats-12.0.1.tgz", + "integrity": "sha512-s01wijBJoDUqESWSzePY0lvTw7J3PVO9x2Cc6ASI5AMZM2Gnhh7BC17+nlFhHKU7dDzaCaRfb+NiqNzOsgPUoQ==", + "engines": { + "node": ">=16.0.0", + "npm": ">=7.0.0" + } + }, + "node_modules/@noble/ciphers": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/@noble/ciphers/-/ciphers-0.1.4.tgz", + "integrity": "sha512-d3ZR8vGSpy3v/nllS+bD/OMN5UZqusWiQqkyj7AwzTnhXFH72pF5oB4Ach6DQ50g5kXxC28LdaYBEpsyv9KOUQ==", + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, + "node_modules/@noble/curves": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@noble/curves/-/curves-1.1.0.tgz", + "integrity": "sha512-091oBExgENk/kGj3AZmtBDMpxQPDtxQABR2B9lb1JbVTs6ytdzZNwvhxQ4MWasRNEzlbEH8jCWFCwhF/Obj5AA==", + "dependencies": { + "@noble/hashes": "1.3.1" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, + "node_modules/@noble/ed25519": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@noble/ed25519/-/ed25519-2.0.0.tgz", + "integrity": "sha512-/extjhkwFupyopDrt80OMWKdLgP429qLZj+z6sYJz90rF2Iz0gjZh2ArMKPImUl13Kx+0EXI2hN9T/KJV0/Zng==", + "funding": [ + { + "type": "individual", + "url": "https://paulmillr.com/funding/" + } + ] + }, + "node_modules/@noble/hashes": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.1.tgz", + "integrity": "sha512-EbqwksQwz9xDRGfDST86whPBgM65E0OH/pCgqW0GBVzO22bNE+NuIbeTb714+IfSjU3aRk47EUvXIb5bTsenKA==", + "engines": { + "node": ">= 16" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, + "node_modules/@noble/secp256k1": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@noble/secp256k1/-/secp256k1-2.0.0.tgz", + "integrity": "sha512-rUGBd95e2a45rlmFTqQJYEFA4/gdIARFfuTuTqLglz0PZ6AKyzyXsEZZq7UZn8hZsvaBgpCzKKBJizT2cJERXw==", + "funding": [ + { + "type": "individual", + "url": "https://paulmillr.com/funding/" + } + ] + }, + "node_modules/@nodelib/fs.scandir": { + "version": "2.1.5", + "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", + "integrity": "sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==", + "dev": true, + "dependencies": { + "@nodelib/fs.stat": "2.0.5", + "run-parallel": "^1.1.9" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/@nodelib/fs.stat": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/@nodelib/fs.stat/-/fs.stat-2.0.5.tgz", + "integrity": "sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A==", + "dev": true, + "engines": { + "node": ">= 8" + } + }, + "node_modules/@nodelib/fs.walk": { + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/@nodelib/fs.walk/-/fs.walk-1.2.8.tgz", + "integrity": "sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==", + "dev": true, + "dependencies": { + "@nodelib/fs.scandir": "2.1.5", + "fastq": "^1.6.0" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/@playwright/test": { + "version": "1.36.2", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.36.2.tgz", + "integrity": "sha512-2rVZeyPRjxfPH6J0oGJqE8YxiM1IBRyM8hyrXYK7eSiAqmbNhxwcLa7dZ7fy9Kj26V7FYia5fh9XJRq4Dqme+g==", + "dev": true, + "dependencies": { + "@types/node": "*", + "playwright-core": "1.36.2" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=16" + }, + "optionalDependencies": { + "fsevents": "2.3.2" + } + }, + "node_modules/@protobufjs/aspromise": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@protobufjs/aspromise/-/aspromise-1.1.2.tgz", + "integrity": "sha512-j+gKExEuLmKwvz3OgROXtrJ2UG2x8Ch2YZUxahh+s1F2HZ+wAceUNLkvy6zKCPVRkU++ZWQrdxsUeQXmcg4uoQ==" + }, + "node_modules/@protobufjs/base64": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@protobufjs/base64/-/base64-1.1.2.tgz", + "integrity": "sha512-AZkcAA5vnN/v4PDqKyMR5lx7hZttPDgClv83E//FMNhR2TMcLUhfRUBHCmSl0oi9zMgDDqRUJkSxO3wm85+XLg==" + }, + "node_modules/@protobufjs/codegen": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/@protobufjs/codegen/-/codegen-2.0.4.tgz", + "integrity": "sha512-YyFaikqM5sH0ziFZCN3xDC7zeGaB/d0IUb9CATugHWbd1FRFwWwt4ld4OYMPWu5a3Xe01mGAULCdqhMlPl29Jg==" + }, + "node_modules/@protobufjs/eventemitter": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@protobufjs/eventemitter/-/eventemitter-1.1.0.tgz", + "integrity": "sha512-j9ednRT81vYJ9OfVuXG6ERSTdEL1xVsNgqpkxMsbIabzSo3goCjDIveeGv5d03om39ML71RdmrGNjG5SReBP/Q==" + }, + "node_modules/@protobufjs/fetch": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@protobufjs/fetch/-/fetch-1.1.0.tgz", + "integrity": "sha512-lljVXpqXebpsijW71PZaCYeIcE5on1w5DlQy5WH6GLbFryLUrBD4932W/E2BSpfRJWseIL4v/KPgBFxDOIdKpQ==", + "dependencies": { + "@protobufjs/aspromise": "^1.1.1", + "@protobufjs/inquire": "^1.1.0" + } + }, + "node_modules/@protobufjs/float": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@protobufjs/float/-/float-1.0.2.tgz", + "integrity": "sha512-Ddb+kVXlXst9d+R9PfTIxh1EdNkgoRe5tOX6t01f1lYWOvJnSPDBlG241QLzcyPdoNTsblLUdujGSE4RzrTZGQ==" + }, + "node_modules/@protobufjs/inquire": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@protobufjs/inquire/-/inquire-1.1.0.tgz", + "integrity": "sha512-kdSefcPdruJiFMVSbn801t4vFK7KB/5gd2fYvrxhuJYg8ILrmn9SKSX2tZdV6V+ksulWqS7aXjBcRXl3wHoD9Q==" + }, + "node_modules/@protobufjs/path": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@protobufjs/path/-/path-1.1.2.tgz", + "integrity": "sha512-6JOcJ5Tm08dOHAbdR3GrvP+yUUfkjG5ePsHYczMFLq3ZmMkAD98cDgcT2iA1lJ9NVwFd4tH/iSSoe44YWkltEA==" + }, + "node_modules/@protobufjs/pool": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@protobufjs/pool/-/pool-1.1.0.tgz", + "integrity": "sha512-0kELaGSIDBKvcgS4zkjz1PeddatrjYcmMWOlAuAPwAeccUrPHdUqo/J6LiymHHEiJT5NrF1UVwxY14f+fy4WQw==" + }, + "node_modules/@protobufjs/utf8": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@protobufjs/utf8/-/utf8-1.1.0.tgz", + "integrity": "sha512-Vvn3zZrhQZkkBE8LSuW3em98c0FwgO4nxzv6OdSxPKJIEKY2bGbHn+mhGIPerzI4twdxaP8/0+06HBpwf345Lw==" + }, + "node_modules/@sinonjs/commons": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-3.0.0.tgz", + "integrity": "sha512-jXBtWAF4vmdNmZgD5FoKsVLv3rPgDnLgPbU84LIJ3otV44vJlDRokVng5v8NFJdCf/da9legHcKaRuZs4L7faA==", + "dev": true, + "dependencies": { + "type-detect": "4.0.8" + } + }, + "node_modules/@sinonjs/fake-timers": { + "version": "10.3.0", + "resolved": "https://registry.npmjs.org/@sinonjs/fake-timers/-/fake-timers-10.3.0.tgz", + "integrity": "sha512-V4BG07kuYSUkTCSBHG8G8TNhM+F19jXFWnQtzj+we8DrkpSBCee9Z3Ms8yiGer/dlmhe35/Xdgyo3/0rQKg7YA==", + "dev": true, + "dependencies": { + "@sinonjs/commons": "^3.0.0" + } + }, + "node_modules/@sinonjs/samsam": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-7.0.1.tgz", + "integrity": "sha512-zsAk2Jkiq89mhZovB2LLOdTCxJF4hqqTToGP0ASWlhp4I1hqOjcfmZGafXntCN7MDC6yySH0mFHrYtHceOeLmw==", + "dev": true, + "dependencies": { + "@sinonjs/commons": "^2.0.0", + "lodash.get": "^4.4.2", + "type-detect": "^4.0.8" + } + }, + "node_modules/@sinonjs/samsam/node_modules/@sinonjs/commons": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-2.0.0.tgz", + "integrity": "sha512-uLa0j859mMrg2slwQYdO/AkrOfmH+X6LTVmNTS9CqexuE2IvVORIkSpJLqePAbEnKJ77aMmCwr1NUZ57120Xcg==", + "dev": true, + "dependencies": { + "type-detect": "4.0.8" + } + }, + "node_modules/@sinonjs/text-encoding": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/@sinonjs/text-encoding/-/text-encoding-0.7.2.tgz", + "integrity": "sha512-sXXKG+uL9IrKqViTtao2Ws6dy0znu9sOaP1di/jKGW1M6VssO8vlpXCQcpZ+jisQ1tTFAC5Jo/EOzFbggBagFQ==", + "dev": true + }, + "node_modules/@socket.io/component-emitter": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@socket.io/component-emitter/-/component-emitter-3.1.0.tgz", + "integrity": "sha512-+9jVqKhRSpsc591z5vX+X5Yyw+he/HCB4iQ/RYxw35CEPaY1gnsNE43nf9n9AaYjAQrTiI/mOwKUKdUs9vf7Xg==", + "dev": true + }, + "node_modules/@tbd54566975/dwn-sdk-js": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/@tbd54566975/dwn-sdk-js/-/dwn-sdk-js-0.2.1.tgz", + "integrity": "sha512-7rFi0zvpt0F/6E2Pow5+iCnf35YGIUneI9U4J43A8NfP0Gh5S2eJkApvhrPOyt50Xq2MerFR9F5E3BE2E0jJRQ==", + "dependencies": { + "@ipld/dag-cbor": "9.0.3", + "@js-temporal/polyfill": "0.4.4", + "@noble/ed25519": "2.0.0", + "@noble/secp256k1": "2.0.0", + "abstract-level": "1.0.3", + "ajv": "8.12.0", + "blockstore-core": "4.2.0", + "cross-fetch": "4.0.0", + "eciesjs": "0.4.0", + "flat": "5.0.2", + "interface-blockstore": "5.2.3", + "interface-store": "5.1.2", + "ipfs-unixfs-exporter": "13.1.5", + "ipfs-unixfs-importer": "15.1.5", + "level": "8.0.0", + "lodash": "4.17.21", + "lru-cache": "9.1.2", + "ms": "2.1.3", + "multiformats": "11.0.2", + "randombytes": "2.1.0", + "readable-stream": "4.4.0", + "ulid": "2.3.0", + "uuid": "8.3.2", + "varint": "6.0.0" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/@tbd54566975/dwn-sdk-js/node_modules/cross-fetch": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-4.0.0.tgz", + "integrity": "sha512-e4a5N8lVvuLgAWgnCrLr2PP0YyDOTHa9H/Rj54dirp61qXnNq46m82bRhNqIA5VccJtWBvPTFRV3TtvHUKPB1g==", + "dependencies": { + "node-fetch": "^2.6.12" + } + }, + "node_modules/@tbd54566975/dwn-sdk-js/node_modules/node-fetch": { + "version": "2.6.13", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.13.tgz", + "integrity": "sha512-StxNAxh15zr77QvvkmveSQ8uCQ4+v5FkvNTj0OESmiHu+VRi/gXArXtkWMElOsOUNLtUEvI4yS+rdtOHZTwlQA==", + "dependencies": { + "whatwg-url": "^5.0.0" + }, + "engines": { + "node": "4.x || >=6.0.0" + }, + "peerDependencies": { + "encoding": "^0.1.0" + }, + "peerDependenciesMeta": { + "encoding": { + "optional": true + } + } + }, + "node_modules/@tbd54566975/dwn-sdk-js/node_modules/readable-stream": { + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-4.4.0.tgz", + "integrity": "sha512-kDMOq0qLtxV9f/SQv522h8cxZBqNZXuXNyjyezmfAAuribMyVXziljpQ/uQhfE1XLg2/TLTW2DsnoE4VAi/krg==", + "dependencies": { + "abort-controller": "^3.0.0", + "buffer": "^6.0.3", + "events": "^3.3.0", + "process": "^0.11.10" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + } + }, + "node_modules/@types/chai": { + "version": "4.3.5", + "resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.3.5.tgz", + "integrity": "sha512-mEo1sAde+UCE6b2hxn332f1g1E8WfYRu6p5SvTKr2ZKC1f7gFJXk4h5PyGP9Dt6gCaG8y8XhwnXWC6Iy2cmBng==", + "dev": true + }, + "node_modules/@types/chai-as-promised": { + "version": "7.1.5", + "resolved": "https://registry.npmjs.org/@types/chai-as-promised/-/chai-as-promised-7.1.5.tgz", + "integrity": "sha512-jStwss93SITGBwt/niYrkf2C+/1KTeZCZl1LaeezTlqppAKeoQC7jxyqYuP72sxBGKCIbw7oHgbYssIRzT5FCQ==", + "dev": true, + "dependencies": { + "@types/chai": "*" + } + }, + "node_modules/@types/cookie": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/@types/cookie/-/cookie-0.4.1.tgz", + "integrity": "sha512-XW/Aa8APYr6jSVVA1y/DEIZX0/GMKLEVekNG727R8cs56ahETkRAy/3DR7+fJyh7oUgGwNQaRfXCun0+KbWY7Q==", + "dev": true + }, + "node_modules/@types/cors": { + "version": "2.8.13", + "resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.13.tgz", + "integrity": "sha512-RG8AStHlUiV5ysZQKq97copd2UmVYw3/pRMLefISZ3S1hK104Cwm7iLQ3fTKx+lsUH2CE8FlLaYeEA2LSeqYUA==", + "dev": true, + "dependencies": { + "@types/node": "*" + } + }, + "node_modules/@types/ed2curve": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/@types/ed2curve/-/ed2curve-0.2.2.tgz", + "integrity": "sha512-G1sTX5xo91ydevQPINbL2nfgVAj/s1ZiqZxC8OCWduwu+edoNGUm5JXtTkg9F3LsBZbRI46/0HES4CPUE2wc9g==", + "dev": true, + "dependencies": { + "tweetnacl": "^1.0.0" + } + }, + "node_modules/@types/eslint": { + "version": "8.44.2", + "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-8.44.2.tgz", + "integrity": "sha512-sdPRb9K6iL5XZOmBubg8yiFp5yS/JdUDQsq5e6h95km91MCYMuvp7mh1fjPEYUhvHepKpZOjnEaMBR4PxjWDzg==", + "dev": true, + "dependencies": { + "@types/estree": "*", + "@types/json-schema": "*" + } + }, + "node_modules/@types/eslint-scope": { + "version": "3.7.4", + "resolved": "https://registry.npmjs.org/@types/eslint-scope/-/eslint-scope-3.7.4.tgz", + "integrity": "sha512-9K4zoImiZc3HlIp6AVUDE4CWYx22a+lhSZMYNpbjW04+YF0KWj4pJXnEMjdnFTiQibFFmElcsasJXDbdI/EPhA==", + "dev": true, + "peer": true, + "dependencies": { + "@types/eslint": "*", + "@types/estree": "*" + } + }, + "node_modules/@types/estree": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.1.tgz", + "integrity": "sha512-LG4opVs2ANWZ1TJoKc937iMmNstM/d0ae1vNbnBvBhqCSezgVUOzcLCqbI5elV8Vy6WKwKjaqR+zO9VKirBBCA==", + "dev": true + }, + "node_modules/@types/istanbul-lib-coverage": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.4.tgz", + "integrity": "sha512-z/QT1XN4K4KYuslS23k62yDIDLwLFkzxOuMplDtObz0+y7VqJCaO2o+SPwHCvLFZh7xazvvoor2tA/hPz9ee7g==", + "dev": true + }, + "node_modules/@types/json-schema": { + "version": "7.0.12", + "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.12.tgz", + "integrity": "sha512-Hr5Jfhc9eYOQNPYO5WLDq/n4jqijdHNlDXjuAQkkt+mWdQR+XJToOHrsD4cPaMXpn6KO7y2+wM8AZEs8VpBLVA==", + "dev": true + }, + "node_modules/@types/mocha": { + "version": "10.0.1", + "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-10.0.1.tgz", + "integrity": "sha512-/fvYntiO1GeICvqbQ3doGDIP97vWmvFt83GKguJ6prmQM2iXZfFcq6YE8KteFyRtX2/h5Hf91BYvPodJKFYv5Q==", + "dev": true + }, + "node_modules/@types/ms": { + "version": "0.7.31", + "resolved": "https://registry.npmjs.org/@types/ms/-/ms-0.7.31.tgz", + "integrity": "sha512-iiUgKzV9AuaEkZqkOLDIvlQiL6ltuZd9tGcW3gwpnX8JbuiuhFlEGmmFXEXkN50Cvq7Os88IY2v0dkDqXYWVgA==", + "dev": true + }, + "node_modules/@types/node": { + "version": "20.5.1", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.5.1.tgz", + "integrity": "sha512-4tT2UrL5LBqDwoed9wZ6N3umC4Yhz3W3FloMmiiG4JwmUJWpie0c7lcnUNd4gtMKuDEO4wRVS8B6Xa0uMRsMKg==" + }, + "node_modules/@types/readable-stream": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/@types/readable-stream/-/readable-stream-4.0.0.tgz", + "integrity": "sha512-s6YqDV111kwuFsT9SwFC+FmZ5n1SEp4H9DXGg6Zqag0lPGeEvBGP9UaLJYpX4cxY7fAFnx2avy1QVvft0LLb7g==", + "dev": true, + "dependencies": { + "@types/node": "*", + "safe-buffer": "~5.1.1" + } + }, + "node_modules/@types/semver": { + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.5.0.tgz", + "integrity": "sha512-G8hZ6XJiHnuhQKR7ZmysCeJWE08o8T0AXtk5darsCaTVsYZhhgUrq53jizaR2FvsoeCwJhlmwTjkXBY5Pn/ZHw==", + "dev": true + }, + "node_modules/@types/sinon": { + "version": "10.0.15", + "resolved": "https://registry.npmjs.org/@types/sinon/-/sinon-10.0.15.tgz", + "integrity": "sha512-3lrFNQG0Kr2LDzvjyjB6AMJk4ge+8iYhQfdnSwIwlG88FUOV43kPcQqDZkDa/h3WSZy6i8Fr0BSjfQtB1B3xuQ==", + "dev": true, + "dependencies": { + "@types/sinonjs__fake-timers": "*" + } + }, + "node_modules/@types/sinonjs__fake-timers": { + "version": "8.1.2", + "resolved": "https://registry.npmjs.org/@types/sinonjs__fake-timers/-/sinonjs__fake-timers-8.1.2.tgz", + "integrity": "sha512-9GcLXF0/v3t80caGs5p2rRfkB+a8VBGLJZVih6CNFkx8IZ994wiKKLSRs9nuFwk1HevWs/1mnUmkApGrSGsShA==", + "dev": true + }, + "node_modules/@types/uuid": { + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-9.0.1.tgz", + "integrity": "sha512-rFT3ak0/2trgvp4yYZo5iKFEPsET7vKydKF+VRCxlQ9bpheehyAJH89dAkaLEq/j/RZXJIqcgsmPJKUP1Z28HA==", + "dev": true + }, + "node_modules/@typescript-eslint/eslint-plugin": { + "version": "6.4.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-6.4.0.tgz", + "integrity": "sha512-62o2Hmc7Gs3p8SLfbXcipjWAa6qk2wZGChXG2JbBtYpwSRmti/9KHLqfbLs9uDigOexG+3PaQ9G2g3201FWLKg==", + "dev": true, + "dependencies": { + "@eslint-community/regexpp": "^4.5.1", + "@typescript-eslint/scope-manager": "6.4.0", + "@typescript-eslint/type-utils": "6.4.0", + "@typescript-eslint/utils": "6.4.0", + "@typescript-eslint/visitor-keys": "6.4.0", + "debug": "^4.3.4", + "graphemer": "^1.4.0", + "ignore": "^5.2.4", + "natural-compare": "^1.4.0", + "semver": "^7.5.4", + "ts-api-utils": "^1.0.1" + }, + "engines": { + "node": "^16.0.0 || >=18.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "@typescript-eslint/parser": "^6.0.0 || ^6.0.0-alpha", + "eslint": "^7.0.0 || ^8.0.0" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, + "node_modules/@typescript-eslint/parser": { + "version": "6.4.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-6.4.0.tgz", + "integrity": "sha512-I1Ah1irl033uxjxO9Xql7+biL3YD7w9IU8zF+xlzD/YxY6a4b7DYA08PXUUCbm2sEljwJF6ERFy2kTGAGcNilg==", + "dev": true, + "dependencies": { + "@typescript-eslint/scope-manager": "6.4.0", + "@typescript-eslint/types": "6.4.0", + "@typescript-eslint/typescript-estree": "6.4.0", + "@typescript-eslint/visitor-keys": "6.4.0", + "debug": "^4.3.4" + }, + "engines": { + "node": "^16.0.0 || >=18.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "eslint": "^7.0.0 || ^8.0.0" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, + "node_modules/@typescript-eslint/scope-manager": { + "version": "6.4.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-6.4.0.tgz", + "integrity": "sha512-TUS7vaKkPWDVvl7GDNHFQMsMruD+zhkd3SdVW0d7b+7Zo+bd/hXJQ8nsiUZMi1jloWo6c9qt3B7Sqo+flC1nig==", + "dev": true, + "dependencies": { + "@typescript-eslint/types": "6.4.0", + "@typescript-eslint/visitor-keys": "6.4.0" + }, + "engines": { + "node": "^16.0.0 || >=18.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, + "node_modules/@typescript-eslint/type-utils": { + "version": "6.4.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-6.4.0.tgz", + "integrity": "sha512-TvqrUFFyGY0cX3WgDHcdl2/mMCWCDv/0thTtx/ODMY1QhEiyFtv/OlLaNIiYLwRpAxAtOLOY9SUf1H3Q3dlwAg==", + "dev": true, + "dependencies": { + "@typescript-eslint/typescript-estree": "6.4.0", + "@typescript-eslint/utils": "6.4.0", + "debug": "^4.3.4", + "ts-api-utils": "^1.0.1" + }, + "engines": { + "node": "^16.0.0 || >=18.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "eslint": "^7.0.0 || ^8.0.0" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, + "node_modules/@typescript-eslint/types": { + "version": "6.4.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-6.4.0.tgz", + "integrity": "sha512-+FV9kVFrS7w78YtzkIsNSoYsnOtrYVnKWSTVXoL1761CsCRv5wpDOINgsXpxD67YCLZtVQekDDyaxfjVWUJmmg==", + "dev": true, + "engines": { + "node": "^16.0.0 || >=18.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, + "node_modules/@typescript-eslint/typescript-estree": { + "version": "6.4.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-6.4.0.tgz", + "integrity": "sha512-iDPJArf/K2sxvjOR6skeUCNgHR/tCQXBsa+ee1/clRKr3olZjZ/dSkXPZjG6YkPtnW6p5D1egeEPMCW6Gn4yLA==", + "dev": true, + "dependencies": { + "@typescript-eslint/types": "6.4.0", + "@typescript-eslint/visitor-keys": "6.4.0", + "debug": "^4.3.4", + "globby": "^11.1.0", + "is-glob": "^4.0.3", + "semver": "^7.5.4", + "ts-api-utils": "^1.0.1" + }, + "engines": { + "node": "^16.0.0 || >=18.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, + "node_modules/@typescript-eslint/utils": { + "version": "6.4.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-6.4.0.tgz", + "integrity": "sha512-BvvwryBQpECPGo8PwF/y/q+yacg8Hn/2XS+DqL/oRsOPK+RPt29h5Ui5dqOKHDlbXrAeHUTnyG3wZA0KTDxRZw==", + "dev": true, + "dependencies": { + "@eslint-community/eslint-utils": "^4.4.0", + "@types/json-schema": "^7.0.12", + "@types/semver": "^7.5.0", + "@typescript-eslint/scope-manager": "6.4.0", + "@typescript-eslint/types": "6.4.0", + "@typescript-eslint/typescript-estree": "6.4.0", + "semver": "^7.5.4" + }, + "engines": { + "node": "^16.0.0 || >=18.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "eslint": "^7.0.0 || ^8.0.0" + } + }, + "node_modules/@typescript-eslint/visitor-keys": { + "version": "6.4.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-6.4.0.tgz", + "integrity": "sha512-yJSfyT+uJm+JRDWYRYdCm2i+pmvXJSMtPR9Cq5/XQs4QIgNoLcoRtDdzsLbLsFM/c6um6ohQkg/MLxWvoIndJA==", + "dev": true, + "dependencies": { + "@typescript-eslint/types": "6.4.0", + "eslint-visitor-keys": "^3.4.1" + }, + "engines": { + "node": "^16.0.0 || >=18.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, + "node_modules/@web5/agent": { + "resolved": "packages/agent", + "link": true + }, + "node_modules/@web5/api": { + "resolved": "packages/api", + "link": true + }, + "node_modules/@web5/common": { + "resolved": "packages/common", + "link": true + }, + "node_modules/@web5/credentials": { + "resolved": "packages/credentials", + "link": true + }, + "node_modules/@web5/crypto": { + "resolved": "packages/crypto", + "link": true + }, + "node_modules/@web5/dids": { + "resolved": "packages/dids", + "link": true + }, + "node_modules/@web5/identity-agent": { + "resolved": "packages/identity-agent", + "link": true + }, + "node_modules/@web5/proxy-agent": { + "resolved": "packages/proxy-agent", + "link": true + }, + "node_modules/@web5/user-agent": { + "resolved": "packages/user-agent", + "link": true + }, + "node_modules/@webassemblyjs/ast": { + "version": "1.11.6", + "resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.11.6.tgz", + "integrity": "sha512-IN1xI7PwOvLPgjcf180gC1bqn3q/QaOCwYUahIOhbYUu8KA/3tw2RT/T0Gidi1l7Hhj5D/INhJxiICObqpMu4Q==", + "dev": true, + "peer": true, + "dependencies": { + "@webassemblyjs/helper-numbers": "1.11.6", + "@webassemblyjs/helper-wasm-bytecode": "1.11.6" + } + }, + "node_modules/@webassemblyjs/floating-point-hex-parser": { + "version": "1.11.6", + "resolved": "https://registry.npmjs.org/@webassemblyjs/floating-point-hex-parser/-/floating-point-hex-parser-1.11.6.tgz", + "integrity": "sha512-ejAj9hfRJ2XMsNHk/v6Fu2dGS+i4UaXBXGemOfQ/JfQ6mdQg/WXtwleQRLLS4OvfDhv8rYnVwH27YJLMyYsxhw==", + "dev": true, + "peer": true + }, + "node_modules/@webassemblyjs/helper-api-error": { + "version": "1.11.6", + "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-api-error/-/helper-api-error-1.11.6.tgz", + "integrity": "sha512-o0YkoP4pVu4rN8aTJgAyj9hC2Sv5UlkzCHhxqWj8butaLvnpdc2jOwh4ewE6CX0txSfLn/UYaV/pheS2Txg//Q==", + "dev": true, + "peer": true + }, + "node_modules/@webassemblyjs/helper-buffer": { + "version": "1.11.6", + "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-buffer/-/helper-buffer-1.11.6.tgz", + "integrity": "sha512-z3nFzdcp1mb8nEOFFk8DrYLpHvhKC3grJD2ardfKOzmbmJvEf/tPIqCY+sNcwZIY8ZD7IkB2l7/pqhUhqm7hLA==", + "dev": true, + "peer": true + }, + "node_modules/@webassemblyjs/helper-numbers": { + "version": "1.11.6", + "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-numbers/-/helper-numbers-1.11.6.tgz", + "integrity": "sha512-vUIhZ8LZoIWHBohiEObxVm6hwP034jwmc9kuq5GdHZH0wiLVLIPcMCdpJzG4C11cHoQ25TFIQj9kaVADVX7N3g==", + "dev": true, + "peer": true, + "dependencies": { + "@webassemblyjs/floating-point-hex-parser": "1.11.6", + "@webassemblyjs/helper-api-error": "1.11.6", + "@xtuc/long": "4.2.2" + } + }, + "node_modules/@webassemblyjs/helper-wasm-bytecode": { + "version": "1.11.6", + "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-wasm-bytecode/-/helper-wasm-bytecode-1.11.6.tgz", + "integrity": "sha512-sFFHKwcmBprO9e7Icf0+gddyWYDViL8bpPjJJl0WHxCdETktXdmtWLGVzoHbqUcY4Be1LkNfwTmXOJUFZYSJdA==", + "dev": true, + "peer": true + }, + "node_modules/@webassemblyjs/helper-wasm-section": { + "version": "1.11.6", + "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-wasm-section/-/helper-wasm-section-1.11.6.tgz", + "integrity": "sha512-LPpZbSOwTpEC2cgn4hTydySy1Ke+XEu+ETXuoyvuyezHO3Kjdu90KK95Sh9xTbmjrCsUwvWwCOQQNta37VrS9g==", + "dev": true, + "peer": true, + "dependencies": { + "@webassemblyjs/ast": "1.11.6", + "@webassemblyjs/helper-buffer": "1.11.6", + "@webassemblyjs/helper-wasm-bytecode": "1.11.6", + "@webassemblyjs/wasm-gen": "1.11.6" + } + }, + "node_modules/@webassemblyjs/ieee754": { + "version": "1.11.6", + "resolved": "https://registry.npmjs.org/@webassemblyjs/ieee754/-/ieee754-1.11.6.tgz", + "integrity": "sha512-LM4p2csPNvbij6U1f19v6WR56QZ8JcHg3QIJTlSwzFcmx6WSORicYj6I63f9yU1kEUtrpG+kjkiIAkevHpDXrg==", + "dev": true, + "peer": true, + "dependencies": { + "@xtuc/ieee754": "^1.2.0" + } + }, + "node_modules/@webassemblyjs/leb128": { + "version": "1.11.6", + "resolved": "https://registry.npmjs.org/@webassemblyjs/leb128/-/leb128-1.11.6.tgz", + "integrity": "sha512-m7a0FhE67DQXgouf1tbN5XQcdWoNgaAuoULHIfGFIEVKA6tu/edls6XnIlkmS6FrXAquJRPni3ZZKjw6FSPjPQ==", + "dev": true, + "peer": true, + "dependencies": { + "@xtuc/long": "4.2.2" + } + }, + "node_modules/@webassemblyjs/utf8": { + "version": "1.11.6", + "resolved": "https://registry.npmjs.org/@webassemblyjs/utf8/-/utf8-1.11.6.tgz", + "integrity": "sha512-vtXf2wTQ3+up9Zsg8sa2yWiQpzSsMyXj0qViVP6xKGCUT8p8YJ6HqI7l5eCnWx1T/FYdsv07HQs2wTFbbof/RA==", + "dev": true, + "peer": true + }, + "node_modules/@webassemblyjs/wasm-edit": { + "version": "1.11.6", + "resolved": "https://registry.npmjs.org/@webassemblyjs/wasm-edit/-/wasm-edit-1.11.6.tgz", + "integrity": "sha512-Ybn2I6fnfIGuCR+Faaz7YcvtBKxvoLV3Lebn1tM4o/IAJzmi9AWYIPWpyBfU8cC+JxAO57bk4+zdsTjJR+VTOw==", + "dev": true, + "peer": true, + "dependencies": { + "@webassemblyjs/ast": "1.11.6", + "@webassemblyjs/helper-buffer": "1.11.6", + "@webassemblyjs/helper-wasm-bytecode": "1.11.6", + "@webassemblyjs/helper-wasm-section": "1.11.6", + "@webassemblyjs/wasm-gen": "1.11.6", + "@webassemblyjs/wasm-opt": "1.11.6", + "@webassemblyjs/wasm-parser": "1.11.6", + "@webassemblyjs/wast-printer": "1.11.6" + } + }, + "node_modules/@webassemblyjs/wasm-gen": { + "version": "1.11.6", + "resolved": "https://registry.npmjs.org/@webassemblyjs/wasm-gen/-/wasm-gen-1.11.6.tgz", + "integrity": "sha512-3XOqkZP/y6B4F0PBAXvI1/bky7GryoogUtfwExeP/v7Nzwo1QLcq5oQmpKlftZLbT+ERUOAZVQjuNVak6UXjPA==", + "dev": true, + "peer": true, + "dependencies": { + "@webassemblyjs/ast": "1.11.6", + "@webassemblyjs/helper-wasm-bytecode": "1.11.6", + "@webassemblyjs/ieee754": "1.11.6", + "@webassemblyjs/leb128": "1.11.6", + "@webassemblyjs/utf8": "1.11.6" + } + }, + "node_modules/@webassemblyjs/wasm-opt": { + "version": "1.11.6", + "resolved": "https://registry.npmjs.org/@webassemblyjs/wasm-opt/-/wasm-opt-1.11.6.tgz", + "integrity": "sha512-cOrKuLRE7PCe6AsOVl7WasYf3wbSo4CeOk6PkrjS7g57MFfVUF9u6ysQBBODX0LdgSvQqRiGz3CXvIDKcPNy4g==", + "dev": true, + "peer": true, + "dependencies": { + "@webassemblyjs/ast": "1.11.6", + "@webassemblyjs/helper-buffer": "1.11.6", + "@webassemblyjs/wasm-gen": "1.11.6", + "@webassemblyjs/wasm-parser": "1.11.6" + } + }, + "node_modules/@webassemblyjs/wasm-parser": { + "version": "1.11.6", + "resolved": "https://registry.npmjs.org/@webassemblyjs/wasm-parser/-/wasm-parser-1.11.6.tgz", + "integrity": "sha512-6ZwPeGzMJM3Dqp3hCsLgESxBGtT/OeCvCZ4TA1JUPYgmhAx38tTPR9JaKy0S5H3evQpO/h2uWs2j6Yc/fjkpTQ==", + "dev": true, + "peer": true, + "dependencies": { + "@webassemblyjs/ast": "1.11.6", + "@webassemblyjs/helper-api-error": "1.11.6", + "@webassemblyjs/helper-wasm-bytecode": "1.11.6", + "@webassemblyjs/ieee754": "1.11.6", + "@webassemblyjs/leb128": "1.11.6", + "@webassemblyjs/utf8": "1.11.6" + } + }, + "node_modules/@webassemblyjs/wast-printer": { + "version": "1.11.6", + "resolved": "https://registry.npmjs.org/@webassemblyjs/wast-printer/-/wast-printer-1.11.6.tgz", + "integrity": "sha512-JM7AhRcE+yW2GWYaKeHL5vt4xqee5N2WcezptmgyhNS+ScggqcT1OtXykhAb13Sn5Yas0j2uv9tHgrjwvzAP4A==", + "dev": true, + "peer": true, + "dependencies": { + "@webassemblyjs/ast": "1.11.6", + "@xtuc/long": "4.2.2" + } + }, + "node_modules/@xtuc/ieee754": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@xtuc/ieee754/-/ieee754-1.2.0.tgz", + "integrity": "sha512-DX8nKgqcGwsc0eJSqYt5lwP4DH5FlHnmuWWBRy7X0NcaGR0ZtuyeESgMwTYVEtxmsNGY+qit4QYT/MIYTOTPeA==", + "dev": true, + "peer": true + }, + "node_modules/@xtuc/long": { + "version": "4.2.2", + "resolved": "https://registry.npmjs.org/@xtuc/long/-/long-4.2.2.tgz", + "integrity": "sha512-NuHqBY1PB/D8xU6s/thBgOAiAP7HOYDQ32+BFZILJ8ivkUkAHQnWfn6WhL79Owj1qmUnoN/YPhktdIoucipkAQ==", + "dev": true, + "peer": true + }, + "node_modules/abab": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/abab/-/abab-2.0.6.tgz", + "integrity": "sha512-j2afSsaIENvHZN2B8GOpF566vZ5WVk5opAiMTvWgaQT8DkbOqsTfvNAvHoRGU2zzP8cPoqys+xHTRDWW8L+/BA==", + "dev": true + }, + "node_modules/abort-controller": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz", + "integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==", + "dependencies": { + "event-target-shim": "^5.0.0" + }, + "engines": { + "node": ">=6.5" + } + }, + "node_modules/abstract-level": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/abstract-level/-/abstract-level-1.0.3.tgz", + "integrity": "sha512-t6jv+xHy+VYwc4xqZMn2Pa9DjcdzvzZmQGRjTFc8spIbRGHgBrEKbPq+rYXc7CCo0lxgYvSgKVg9qZAhpVQSjA==", + "dependencies": { + "buffer": "^6.0.3", + "catering": "^2.1.0", + "is-buffer": "^2.0.5", + "level-supports": "^4.0.0", + "level-transcoder": "^1.0.1", + "module-error": "^1.0.1", + "queue-microtask": "^1.2.3" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/accepts": { + "version": "1.3.8", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", + "integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==", + "dev": true, + "dependencies": { + "mime-types": "~2.1.34", + "negotiator": "0.6.3" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/acorn": { + "version": "8.10.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.10.0.tgz", + "integrity": "sha512-F0SAmZ8iUtS//m8DmCTA0jlh6TDKkHQyK6xc6V4KDTyZKA9dnvX9/3sRTVQrWm79glUAZbnmmNcdYwUIHWVybw==", + "dev": true, + "bin": { + "acorn": "bin/acorn" + }, + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/acorn-import-assertions": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/acorn-import-assertions/-/acorn-import-assertions-1.9.0.tgz", + "integrity": "sha512-cmMwop9x+8KFhxvKrKfPYmN6/pKTYYHBqLa0DfvVZcKMJWNyWLnaqND7dx/qn66R7ewM1UX5XMaDVP5wlVTaVA==", + "dev": true, + "peer": true, + "peerDependencies": { + "acorn": "^8" + } + }, + "node_modules/acorn-jsx": { + "version": "5.3.2", + "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.2.tgz", + "integrity": "sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==", + "dev": true, + "peerDependencies": { + "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" + } + }, + "node_modules/ajv": { + "version": "8.12.0", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.12.0.tgz", + "integrity": "sha512-sRu1kpcO9yLtYxBKvqfTeh9KzZEwO3STyX1HT+4CaDzC6HpTGYhIhPIzj9XuKU7KYDwnaeh5hcOwjy1QuJzBPA==", + "dependencies": { + "fast-deep-equal": "^3.1.1", + "json-schema-traverse": "^1.0.0", + "require-from-string": "^2.0.2", + "uri-js": "^4.2.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, + "node_modules/ansi-colors": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.1.tgz", + "integrity": "sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA==", + "dev": true, + "engines": { + "node": ">=6" + } + }, + "node_modules/ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dev": true, + "dependencies": { + "color-convert": "^2.0.1" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/anymatch": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz", + "integrity": "sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==", + "dev": true, + "dependencies": { + "normalize-path": "^3.0.0", + "picomatch": "^2.0.4" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/argparse": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", + "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", + "dev": true + }, + "node_modules/array-union": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/array-union/-/array-union-2.1.0.tgz", + "integrity": "sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/asn1.js": { + "version": "5.4.1", + "resolved": "https://registry.npmjs.org/asn1.js/-/asn1.js-5.4.1.tgz", + "integrity": "sha512-+I//4cYPccV8LdmBLiX8CYvf9Sp3vQsrqu2QNXRcrbiWvcx/UdlFiqUJJzxRQxgsZmvhXhn4cSKeSmoFjVdupA==", + "dev": true, + "dependencies": { + "bn.js": "^4.0.0", + "inherits": "^2.0.1", + "minimalistic-assert": "^1.0.0", + "safer-buffer": "^2.1.0" + } + }, + "node_modules/asn1.js/node_modules/bn.js": { + "version": "4.12.0", + "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.12.0.tgz", + "integrity": "sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA==", + "dev": true + }, + "node_modules/assert": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/assert/-/assert-2.0.0.tgz", + "integrity": "sha512-se5Cd+js9dXJnu6Ag2JFc00t+HmHOen+8Q+L7O9zI0PqQXr20uk2J0XQqMxZEeo5U50o8Nvmmx7dZrl+Ufr35A==", + "dev": true, + "dependencies": { + "es6-object-assign": "^1.1.0", + "is-nan": "^1.2.1", + "object-is": "^1.0.1", + "util": "^0.12.0" + } + }, + "node_modules/assertion-error": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz", + "integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==", + "dev": true, + "engines": { + "node": "*" + } + }, + "node_modules/available-typed-arrays": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.5.tgz", + "integrity": "sha512-DMD0KiN46eipeziST1LPP/STfDU0sufISXmjSgvVsoU2tqxctQeASejWcfNtxYKqETM1UxQ8sp2OrSBWpHY6sw==", + "dev": true, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/balanced-match": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", + "dev": true + }, + "node_modules/base64-js": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", + "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ] + }, + "node_modules/base64id": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/base64id/-/base64id-2.0.0.tgz", + "integrity": "sha512-lGe34o6EHj9y3Kts9R4ZYs/Gr+6N7MCaMlIFA3F1R2O5/m7K06AxfSeO5530PEERE6/WyEg3lsuyw4GHlPZHog==", + "dev": true, + "engines": { + "node": "^4.5.0 || >= 5.9" + } + }, + "node_modules/binary-extensions": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz", + "integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/bl": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/bl/-/bl-5.1.0.tgz", + "integrity": "sha512-tv1ZJHLfTDnXE6tMHv73YgSJaWR2AFuPwMntBe7XL/GBFHnT0CLnsHMogfk5+GzCDC5ZWarSCYaIGATZt9dNsQ==", + "dependencies": { + "buffer": "^6.0.3", + "inherits": "^2.0.4", + "readable-stream": "^3.4.0" + } + }, + "node_modules/bl/node_modules/readable-stream": { + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", + "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", + "dependencies": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/blockstore-core": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/blockstore-core/-/blockstore-core-4.2.0.tgz", + "integrity": "sha512-F8BCobc75D+9/+hUD+5cixbU6zmZA+lBgNiuBkNlJqRgmAaBBvLOQF6Ad9Jei0Nvmy2a1jaF4CiN76W1apIghA==", + "dependencies": { + "err-code": "^3.0.1", + "interface-blockstore": "^5.0.0", + "interface-store": "^5.0.0", + "multiformats": "^11.0.2" + }, + "engines": { + "node": ">=16.0.0", + "npm": ">=7.0.0" + } + }, + "node_modules/bn.js": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-5.2.1.tgz", + "integrity": "sha512-eXRvHzWyYPBuB4NBy0cmYQjGitUrtqwbvlzP3G6VFnNRbsZQIxQ10PbKKHt8gZ/HW/D/747aDl+QkDqg3KQLMQ==", + "dev": true + }, + "node_modules/body-parser": { + "version": "1.20.2", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.2.tgz", + "integrity": "sha512-ml9pReCu3M61kGlqoTm2umSXTlRTuGTx0bfYj+uIUKKYycG5NtSbeetV3faSU6R7ajOPw0g/J1PvK4qNy7s5bA==", + "dev": true, + "dependencies": { + "bytes": "3.1.2", + "content-type": "~1.0.5", + "debug": "2.6.9", + "depd": "2.0.0", + "destroy": "1.2.0", + "http-errors": "2.0.0", + "iconv-lite": "0.4.24", + "on-finished": "2.4.1", + "qs": "6.11.0", + "raw-body": "2.5.2", + "type-is": "~1.6.18", + "unpipe": "1.0.0" + }, + "engines": { + "node": ">= 0.8", + "npm": "1.2.8000 || >= 1.4.16" + } + }, + "node_modules/body-parser/node_modules/debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "dev": true, + "dependencies": { + "ms": "2.0.0" + } + }, + "node_modules/body-parser/node_modules/ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", + "dev": true + }, + "node_modules/bonanza": { + "resolved": "packages/bonanza", + "link": true + }, + "node_modules/brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dev": true, + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "node_modules/braces": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", + "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "dev": true, + "dependencies": { + "fill-range": "^7.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/brorand": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/brorand/-/brorand-1.1.0.tgz", + "integrity": "sha512-cKV8tMCEpQs4hK/ik71d6LrPOnpkpGBR0wzxqr68g2m/LB2GxVYQroAjMJZRVM1Y4BCjCKc3vAamxSzOY2RP+w==", + "dev": true + }, + "node_modules/browser-level": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/browser-level/-/browser-level-1.0.1.tgz", + "integrity": "sha512-XECYKJ+Dbzw0lbydyQuJzwNXtOpbMSq737qxJN11sIRTErOMShvDpbzTlgju7orJKvx4epULolZAuJGLzCmWRQ==", + "dependencies": { + "abstract-level": "^1.0.2", + "catering": "^2.1.1", + "module-error": "^1.0.2", + "run-parallel-limit": "^1.1.0" + } + }, + "node_modules/browser-resolve": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/browser-resolve/-/browser-resolve-2.0.0.tgz", + "integrity": "sha512-7sWsQlYL2rGLy2IWm8WL8DCTJvYLc/qlOnsakDac87SOoCd16WLsaAMdCiAqsTNHIe+SXfaqyxyo6THoWqs8WQ==", + "dev": true, + "dependencies": { + "resolve": "^1.17.0" + } + }, + "node_modules/browser-stdout": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.1.tgz", + "integrity": "sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw==", + "dev": true + }, + "node_modules/browserify-aes": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/browserify-aes/-/browserify-aes-1.2.0.tgz", + "integrity": "sha512-+7CHXqGuspUn/Sl5aO7Ea0xWGAtETPXNSAjHo48JfLdPWcMng33Xe4znFvQweqc/uzk5zSOI3H52CYnjCfb5hA==", + "dev": true, + "dependencies": { + "buffer-xor": "^1.0.3", + "cipher-base": "^1.0.0", + "create-hash": "^1.1.0", + "evp_bytestokey": "^1.0.3", + "inherits": "^2.0.1", + "safe-buffer": "^5.0.1" + } + }, + "node_modules/browserify-cipher": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/browserify-cipher/-/browserify-cipher-1.0.1.tgz", + "integrity": "sha512-sPhkz0ARKbf4rRQt2hTpAHqn47X3llLkUGn+xEJzLjwY8LRs2p0v7ljvI5EyoRO/mexrNunNECisZs+gw2zz1w==", + "dev": true, + "dependencies": { + "browserify-aes": "^1.0.4", + "browserify-des": "^1.0.0", + "evp_bytestokey": "^1.0.0" + } + }, + "node_modules/browserify-des": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/browserify-des/-/browserify-des-1.0.2.tgz", + "integrity": "sha512-BioO1xf3hFwz4kc6iBhI3ieDFompMhrMlnDFC4/0/vd5MokpuAc3R+LYbwTA9A5Yc9pq9UYPqffKpW2ObuwX5A==", + "dev": true, + "dependencies": { + "cipher-base": "^1.0.1", + "des.js": "^1.0.0", + "inherits": "^2.0.1", + "safe-buffer": "^5.1.2" + } + }, + "node_modules/browserify-rsa": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/browserify-rsa/-/browserify-rsa-4.1.0.tgz", + "integrity": "sha512-AdEER0Hkspgno2aR97SAf6vi0y0k8NuOpGnVH3O99rcA5Q6sh8QxcngtHuJ6uXwnfAXNM4Gn1Gb7/MV1+Ymbog==", + "dev": true, + "dependencies": { + "bn.js": "^5.0.0", + "randombytes": "^2.0.1" + } + }, + "node_modules/browserify-sign": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/browserify-sign/-/browserify-sign-4.2.1.tgz", + "integrity": "sha512-/vrA5fguVAKKAVTNJjgSm1tRQDHUU6DbwO9IROu/0WAzC8PKhucDSh18J0RMvVeHAn5puMd+QHC2erPRNf8lmg==", + "dev": true, + "dependencies": { + "bn.js": "^5.1.1", + "browserify-rsa": "^4.0.1", + "create-hash": "^1.2.0", + "create-hmac": "^1.1.7", + "elliptic": "^6.5.3", + "inherits": "^2.0.4", + "parse-asn1": "^5.1.5", + "readable-stream": "^3.6.0", + "safe-buffer": "^5.2.0" + } + }, + "node_modules/browserify-sign/node_modules/readable-stream": { + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", + "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", + "dev": true, + "dependencies": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/browserify-sign/node_modules/safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ] + }, + "node_modules/browserify-zlib": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/browserify-zlib/-/browserify-zlib-0.2.0.tgz", + "integrity": "sha512-Z942RysHXmJrhqk88FmKBVq/v5tqmSkDz7p54G/MGyjMnCFFnC79XWNbg+Vta8W6Wb2qtSZTSxIGkJrRpCFEiA==", + "dev": true, + "dependencies": { + "pako": "~1.0.5" + } + }, + "node_modules/browserslist": { + "version": "4.21.10", + "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.21.10.tgz", + "integrity": "sha512-bipEBdZfVH5/pwrvqc+Ub0kUPVfGUhlKxbvfD+z1BDnPEO/X98ruXGA1WP5ASpAFKan7Qr6j736IacbZQuAlKQ==", + "dev": true, + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/browserslist" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/browserslist" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "peer": true, + "dependencies": { + "caniuse-lite": "^1.0.30001517", + "electron-to-chromium": "^1.4.477", + "node-releases": "^2.0.13", + "update-browserslist-db": "^1.0.11" + }, + "bin": { + "browserslist": "cli.js" + }, + "engines": { + "node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7" + } + }, + "node_modules/buffer": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", + "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "dependencies": { + "base64-js": "^1.3.1", + "ieee754": "^1.2.1" + } + }, + "node_modules/buffer-from": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", + "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==", + "dev": true, + "peer": true + }, + "node_modules/buffer-xor": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/buffer-xor/-/buffer-xor-1.0.3.tgz", + "integrity": "sha512-571s0T7nZWK6vB67HI5dyUF7wXiNcfaPPPTl6zYCNApANjIvYJTg7hlud/+cJpdAhS7dVzqMLmfhfHR3rAcOjQ==", + "dev": true + }, + "node_modules/builtin-status-codes": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/builtin-status-codes/-/builtin-status-codes-3.0.0.tgz", + "integrity": "sha512-HpGFw18DgFWlncDfjTa2rcQ4W88O1mC8e8yZ2AvQY5KDaktSTwo+KRf6nHK6FRI5FyRyb/5T6+TSxfP7QyGsmQ==", + "dev": true + }, + "node_modules/bytes": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", + "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==", + "dev": true, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/c8": { + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/c8/-/c8-8.0.1.tgz", + "integrity": "sha512-EINpopxZNH1mETuI0DzRA4MZpAUH+IFiRhnmFD3vFr3vdrgxqi3VfE3KL0AIL+zDq8rC9bZqwM/VDmmoe04y7w==", + "dev": true, + "dependencies": { + "@bcoe/v8-coverage": "^0.2.3", + "@istanbuljs/schema": "^0.1.3", + "find-up": "^5.0.0", + "foreground-child": "^2.0.0", + "istanbul-lib-coverage": "^3.2.0", + "istanbul-lib-report": "^3.0.1", + "istanbul-reports": "^3.1.6", + "rimraf": "^3.0.2", + "test-exclude": "^6.0.0", + "v8-to-istanbul": "^9.0.0", + "yargs": "^17.7.2", + "yargs-parser": "^21.1.1" + }, + "bin": { + "c8": "bin/c8.js" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/c8/node_modules/rimraf": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", + "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", + "dev": true, + "dependencies": { + "glob": "^7.1.3" + }, + "bin": { + "rimraf": "bin.js" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/call-bind": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz", + "integrity": "sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==", + "dev": true, + "dependencies": { + "function-bind": "^1.1.1", + "get-intrinsic": "^1.0.2" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/callsites": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", + "integrity": "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==", + "dev": true, + "engines": { + "node": ">=6" + } + }, + "node_modules/camelcase": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-6.3.0.tgz", + "integrity": "sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==", + "dev": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/caniuse-lite": { + "version": "1.0.30001521", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001521.tgz", + "integrity": "sha512-fnx1grfpEOvDGH+V17eccmNjucGUnCbP6KL+l5KqBIerp26WK/+RQ7CIDE37KGJjaPyqWXXlFUyKiWmvdNNKmQ==", + "dev": true, + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/browserslist" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/caniuse-lite" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "peer": true + }, + "node_modules/canonicalize": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/canonicalize/-/canonicalize-2.0.0.tgz", + "integrity": "sha512-ulDEYPv7asdKvqahuAY35c1selLdzDwHqugK92hfkzvlDCwXRRelDkR+Er33md/PtnpqHemgkuDPanZ4fiYZ8w==" + }, + "node_modules/catering": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/catering/-/catering-2.1.1.tgz", + "integrity": "sha512-K7Qy8O9p76sL3/3m7/zLKbRkyOlSZAgzEaLhyj2mXS8PsCud2Eo4hAb8aLtZqHh0QGqLcb9dlJSu6lHRVENm1w==", + "engines": { + "node": ">=6" + } + }, + "node_modules/cborg": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/cborg/-/cborg-2.0.4.tgz", + "integrity": "sha512-QradkXyNBLIyg1XNxcoXqUG4stcOhfuR1uexq+qNzL+EvFV5TXvN+c+LCh5XXxTv2fjBIkNB+3I6IO17EnKuKg==", + "bin": { + "cborg": "cli.js" + } + }, + "node_modules/chai": { + "version": "4.3.7", + "resolved": "https://registry.npmjs.org/chai/-/chai-4.3.7.tgz", + "integrity": "sha512-HLnAzZ2iupm25PlN0xFreAlBA5zaBSv3og0DdeGA4Ar6h6rJ3A0rolRUKJhSF2V10GZKDgWF/VmAEsNWjCRB+A==", + "dev": true, + "dependencies": { + "assertion-error": "^1.1.0", + "check-error": "^1.0.2", + "deep-eql": "^4.1.2", + "get-func-name": "^2.0.0", + "loupe": "^2.3.1", + "pathval": "^1.1.1", + "type-detect": "^4.0.5" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/chai-as-promised": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/chai-as-promised/-/chai-as-promised-7.1.1.tgz", + "integrity": "sha512-azL6xMoi+uxu6z4rhWQ1jbdUhOMhis2PvscD/xjLqNMkv3BPPp2JyyuTHOrf9BOosGpNQ11v6BKv/g57RXbiaA==", + "dev": true, + "dependencies": { + "check-error": "^1.0.2" + }, + "peerDependencies": { + "chai": ">= 2.1.2 < 5" + } + }, + "node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, + "node_modules/check-error": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.2.tgz", + "integrity": "sha512-BrgHpW9NURQgzoNyjfq0Wu6VFO6D7IZEmJNdtgNqpzGG8RuNFHt2jQxWlAs4HMe119chBnv+34syEZtc6IhLtA==", + "dev": true, + "engines": { + "node": "*" + } + }, + "node_modules/chokidar": { + "version": "3.5.3", + "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz", + "integrity": "sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==", + "dev": true, + "funding": [ + { + "type": "individual", + "url": "https://paulmillr.com/funding/" + } + ], + "dependencies": { + "anymatch": "~3.1.2", + "braces": "~3.0.2", + "glob-parent": "~5.1.2", + "is-binary-path": "~2.1.0", + "is-glob": "~4.0.1", + "normalize-path": "~3.0.0", + "readdirp": "~3.6.0" + }, + "engines": { + "node": ">= 8.10.0" + }, + "optionalDependencies": { + "fsevents": "~2.3.2" + } + }, + "node_modules/chokidar/node_modules/glob-parent": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", + "dev": true, + "dependencies": { + "is-glob": "^4.0.1" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/chrome-trace-event": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/chrome-trace-event/-/chrome-trace-event-1.0.3.tgz", + "integrity": "sha512-p3KULyQg4S7NIHixdwbGX+nFHkoBiA4YQmyWtjb8XngSKV124nJmRysgAeujbUVb15vh+RvFUfCPqU7rXk+hZg==", + "dev": true, + "peer": true, + "engines": { + "node": ">=6.0" + } + }, + "node_modules/ci-info": { + "version": "3.8.0", + "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-3.8.0.tgz", + "integrity": "sha512-eXTggHWSooYhq49F2opQhuHWgzucfF2YgODK4e1566GQs5BIfP30B0oenwBJHfWxAs2fyPB1s7Mg949zLf61Yw==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/sibiraj-s" + } + ], + "engines": { + "node": ">=8" + } + }, + "node_modules/cipher-base": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/cipher-base/-/cipher-base-1.0.4.tgz", + "integrity": "sha512-Kkht5ye6ZGmwv40uUDZztayT2ThLQGfnj/T71N/XzeZeo3nf8foyW7zGTsPYkEya3m5f3cAypH+qe7YOrM1U2Q==", + "dev": true, + "dependencies": { + "inherits": "^2.0.1", + "safe-buffer": "^5.0.1" + } + }, + "node_modules/classic-level": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/classic-level/-/classic-level-1.3.0.tgz", + "integrity": "sha512-iwFAJQYtqRTRM0F6L8h4JCt00ZSGdOyqh7yVrhhjrOpFhmBjNlRUey64MCiyo6UmQHMJ+No3c81nujPv+n9yrg==", + "hasInstallScript": true, + "dependencies": { + "abstract-level": "^1.0.2", + "catering": "^2.1.0", + "module-error": "^1.0.1", + "napi-macros": "^2.2.2", + "node-gyp-build": "^4.3.0" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/cliui": { + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz", + "integrity": "sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==", + "dev": true, + "dependencies": { + "string-width": "^4.2.0", + "strip-ansi": "^6.0.1", + "wrap-ansi": "^7.0.0" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, + "dependencies": { + "color-name": "~1.1.4" + }, + "engines": { + "node": ">=7.0.0" + } + }, + "node_modules/color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true + }, + "node_modules/commander": { + "version": "2.20.3", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", + "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", + "dev": true, + "peer": true + }, + "node_modules/concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==", + "dev": true + }, + "node_modules/connect": { + "version": "3.7.0", + "resolved": "https://registry.npmjs.org/connect/-/connect-3.7.0.tgz", + "integrity": "sha512-ZqRXc+tZukToSNmh5C2iWMSoV3X1YUcPbqEM4DkEG5tNQXrQUZCNVGGv3IuicnkMtPfGf3Xtp8WCXs295iQ1pQ==", + "dev": true, + "dependencies": { + "debug": "2.6.9", + "finalhandler": "1.1.2", + "parseurl": "~1.3.3", + "utils-merge": "1.0.1" + }, + "engines": { + "node": ">= 0.10.0" + } + }, + "node_modules/connect/node_modules/debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "dev": true, + "dependencies": { + "ms": "2.0.0" + } + }, + "node_modules/connect/node_modules/ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", + "dev": true + }, + "node_modules/console-browserify": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/console-browserify/-/console-browserify-1.2.0.tgz", + "integrity": "sha512-ZMkYO/LkF17QvCPqM0gxw8yUzigAOZOSWSHg91FH6orS7vcEj5dVZTidN2fQ14yBSdg97RqhSNwLUXInd52OTA==", + "dev": true + }, + "node_modules/constants-browserify": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/constants-browserify/-/constants-browserify-1.0.0.tgz", + "integrity": "sha512-xFxOwqIzR/e1k1gLiWEophSCMqXcwVHIH7akf7b/vxcUeGunlj3hvZaaqxwHsTgn+IndtkQJgSztIDWeumWJDQ==", + "dev": true + }, + "node_modules/content-type": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz", + "integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==", + "dev": true, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/convert-source-map": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.9.0.tgz", + "integrity": "sha512-ASFBup0Mz1uyiIjANan1jzLQami9z1PoYSZCiiYW2FczPbenXc45FZdBZLzOT+r6+iciuEModtmCti+hjaAk0A==", + "dev": true + }, + "node_modules/cookie": { + "version": "0.4.2", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.2.tgz", + "integrity": "sha512-aSWTXFzaKWkvHO1Ny/s+ePFpvKsPnjc551iI41v3ny/ow6tBG5Vd+FuqGNhh1LxOmVzOlGUriIlOaokOvhaStA==", + "dev": true, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cors": { + "version": "2.8.5", + "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz", + "integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==", + "dev": true, + "dependencies": { + "object-assign": "^4", + "vary": "^1" + }, + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/create-ecdh": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/create-ecdh/-/create-ecdh-4.0.4.tgz", + "integrity": "sha512-mf+TCx8wWc9VpuxfP2ht0iSISLZnt0JgWlrOKZiNqyUZWnjIaCIVNQArMHnCZKfEYRg6IM7A+NeJoN8gf/Ws0A==", + "dev": true, + "dependencies": { + "bn.js": "^4.1.0", + "elliptic": "^6.5.3" + } + }, + "node_modules/create-ecdh/node_modules/bn.js": { + "version": "4.12.0", + "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.12.0.tgz", + "integrity": "sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA==", + "dev": true + }, + "node_modules/create-hash": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/create-hash/-/create-hash-1.2.0.tgz", + "integrity": "sha512-z00bCGNHDG8mHAkP7CtT1qVu+bFQUPjYq/4Iv3C3kWjTFV10zIjfSoeqXo9Asws8gwSHDGj/hl2u4OGIjapeCg==", + "dev": true, + "dependencies": { + "cipher-base": "^1.0.1", + "inherits": "^2.0.1", + "md5.js": "^1.3.4", + "ripemd160": "^2.0.1", + "sha.js": "^2.4.0" + } + }, + "node_modules/create-hmac": { + "version": "1.1.7", + "resolved": "https://registry.npmjs.org/create-hmac/-/create-hmac-1.1.7.tgz", + "integrity": "sha512-MJG9liiZ+ogc4TzUwuvbER1JRdgvUFSB5+VR/g5h82fGaIRWMWddtKBHi7/sVhfjQZ6SehlyhvQYrcYkaUIpLg==", + "dev": true, + "dependencies": { + "cipher-base": "^1.0.3", + "create-hash": "^1.1.0", + "inherits": "^2.0.1", + "ripemd160": "^2.0.0", + "safe-buffer": "^5.0.1", + "sha.js": "^2.4.8" + } + }, + "node_modules/create-require": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", + "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", + "dev": true + }, + "node_modules/cross-fetch": { + "version": "3.1.5", + "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.5.tgz", + "integrity": "sha512-lvb1SBsI0Z7GDwmuid+mU3kWVBwTVUbe7S0H52yaaAdQOXq2YktTCZdlAcNKFzE6QtRz0snpw9bNiPeOIkkQvw==", + "dependencies": { + "node-fetch": "2.6.7" + } + }, + "node_modules/cross-spawn": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", + "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", + "dev": true, + "dependencies": { + "path-key": "^3.1.0", + "shebang-command": "^2.0.0", + "which": "^2.0.1" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/crypto-browserify": { + "version": "3.12.0", + "resolved": "https://registry.npmjs.org/crypto-browserify/-/crypto-browserify-3.12.0.tgz", + "integrity": "sha512-fz4spIh+znjO2VjL+IdhEpRJ3YN6sMzITSBijk6FK2UvTqruSQW+/cCZTSNsMiZNvUeq0CqurF+dAbyiGOY6Wg==", + "dev": true, + "dependencies": { + "browserify-cipher": "^1.0.0", + "browserify-sign": "^4.0.0", + "create-ecdh": "^4.0.0", + "create-hash": "^1.1.0", + "create-hmac": "^1.1.0", + "diffie-hellman": "^5.0.0", + "inherits": "^2.0.1", + "pbkdf2": "^3.0.3", + "public-encrypt": "^4.0.0", + "randombytes": "^2.0.0", + "randomfill": "^1.0.3" + }, + "engines": { + "node": "*" + } + }, + "node_modules/custom-event": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/custom-event/-/custom-event-1.0.1.tgz", + "integrity": "sha512-GAj5FOq0Hd+RsCGVJxZuKaIDXDf3h6GQoNEjFgbLLI/trgtavwUbSnZ5pVfg27DVCaWjIohryS0JFwIJyT2cMg==", + "dev": true + }, + "node_modules/date-format": { + "version": "4.0.14", + "resolved": "https://registry.npmjs.org/date-format/-/date-format-4.0.14.tgz", + "integrity": "sha512-39BOQLs9ZjKh0/patS9nrT8wc3ioX3/eA/zgbKNopnF2wCqJEoxywwwElATYvRsXdnOxA/OQeQoFZ3rFjVajhg==", + "dev": true, + "engines": { + "node": ">=4.0" + } + }, + "node_modules/debug": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "dependencies": { + "ms": "2.1.2" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/debug/node_modules/ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" + }, + "node_modules/decamelize": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-4.0.0.tgz", + "integrity": "sha512-9iE1PgSik9HeIIw2JO94IidnE3eBoQrFJ3w7sFuzSX4DpmZ3v5sZpUiV5Swcf6mQEF+Y0ru8Neo+p+nyh2J+hQ==", + "dev": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/deep-eql": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-4.1.3.tgz", + "integrity": "sha512-WaEtAOpRA1MQ0eohqZjpGD8zdI0Ovsm8mmFhaDN8dvDZzyoUMcYDnf5Y6iu7HTXxf8JDS23qWa4a+hKCDyOPzw==", + "dev": true, + "dependencies": { + "type-detect": "^4.0.0" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/deep-is": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz", + "integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==", + "dev": true + }, + "node_modules/define-properties": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.2.0.tgz", + "integrity": "sha512-xvqAVKGfT1+UAvPwKTVw/njhdQ8ZhXK4lI0bCIuCMrp2up9nPnaDftrLtmpTazqd1o+UY4zgzU+avtMbDP+ldA==", + "dev": true, + "dependencies": { + "has-property-descriptors": "^1.0.0", + "object-keys": "^1.1.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/depd": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", + "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==", + "dev": true, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/des.js": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/des.js/-/des.js-1.1.0.tgz", + "integrity": "sha512-r17GxjhUCjSRy8aiJpr8/UadFIzMzJGexI3Nmz4ADi9LYSFx4gTBp80+NaX/YsXWWLhpZ7v/v/ubEc/bCNfKwg==", + "dev": true, + "dependencies": { + "inherits": "^2.0.1", + "minimalistic-assert": "^1.0.0" + } + }, + "node_modules/destroy": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz", + "integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==", + "dev": true, + "engines": { + "node": ">= 0.8", + "npm": "1.2.8000 || >= 1.4.16" + } + }, + "node_modules/di": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/di/-/di-0.0.1.tgz", + "integrity": "sha512-uJaamHkagcZtHPqCIHZxnFrXlunQXgBOsZSUOWwFw31QJCAbyTBoHMW75YOTur5ZNx8pIeAKgf6GWIgaqqiLhA==", + "dev": true + }, + "node_modules/did-resolver": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/did-resolver/-/did-resolver-4.1.0.tgz", + "integrity": "sha512-S6fWHvCXkZg2IhS4RcVHxwuyVejPR7c+a4Go0xbQ9ps5kILa8viiYQgrM4gfTyeTjJ0ekgJH9gk/BawTpmkbZA==" + }, + "node_modules/diff": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/diff/-/diff-5.0.0.tgz", + "integrity": "sha512-/VTCrvm5Z0JGty/BWHljh+BAiw3IK+2j87NGMu8Nwc/f48WoDAC395uomO9ZD117ZOBaHmkX1oyLvkVM/aIT3w==", + "dev": true, + "engines": { + "node": ">=0.3.1" + } + }, + "node_modules/diffie-hellman": { + "version": "5.0.3", + "resolved": "https://registry.npmjs.org/diffie-hellman/-/diffie-hellman-5.0.3.tgz", + "integrity": "sha512-kqag/Nl+f3GwyK25fhUMYj81BUOrZ9IuJsjIcDE5icNM9FJHAVm3VcUDxdLPoQtTuUylWm6ZIknYJwwaPxsUzg==", + "dev": true, + "dependencies": { + "bn.js": "^4.1.0", + "miller-rabin": "^4.0.0", + "randombytes": "^2.0.0" + } + }, + "node_modules/diffie-hellman/node_modules/bn.js": { + "version": "4.12.0", + "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.12.0.tgz", + "integrity": "sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA==", + "dev": true + }, + "node_modules/dir-glob": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz", + "integrity": "sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==", + "dev": true, + "dependencies": { + "path-type": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/doctrine": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", + "integrity": "sha512-yS+Q5i3hBf7GBkd4KG8a7eBNNWNGLTaEwwYWUijIYM7zrlYDM0BFXHjjPWlWZ1Rg7UaddZeIDmi9jF3HmqiQ2w==", + "dev": true, + "dependencies": { + "esutils": "^2.0.2" + }, + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/dom-serialize": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/dom-serialize/-/dom-serialize-2.2.1.tgz", + "integrity": "sha512-Yra4DbvoW7/Z6LBN560ZwXMjoNOSAN2wRsKFGc4iBeso+mpIA6qj1vfdf9HpMaKAqG6wXTy+1SYEzmNpKXOSsQ==", + "dev": true, + "dependencies": { + "custom-event": "~1.0.0", + "ent": "~2.2.0", + "extend": "^3.0.0", + "void-elements": "^2.0.0" + } + }, + "node_modules/domain-browser": { + "version": "4.22.0", + "resolved": "https://registry.npmjs.org/domain-browser/-/domain-browser-4.22.0.tgz", + "integrity": "sha512-IGBwjF7tNk3cwypFNH/7bfzBcgSCbaMOD3GsaY1AU/JRrnHnYgEM0+9kQt52iZxjNsjBtJYtao146V+f8jFZNw==", + "dev": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://bevry.me/fund" + } + }, + "node_modules/eciesjs": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/eciesjs/-/eciesjs-0.4.0.tgz", + "integrity": "sha512-z4dEeaH16xxYVgtxJ8YVwpifH4Keg4gyp5F451mnDNwbAN3MgL5jcoEQGpqJrapv/zW8KwDnXG21Dw5B0hqvmw==", + "dependencies": { + "@noble/curves": "^1.1.0" + } + }, + "node_modules/ee-first": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", + "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==", + "dev": true + }, + "node_modules/electron-to-chromium": { + "version": "1.4.496", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.496.tgz", + "integrity": "sha512-qeXC3Zbykq44RCrBa4kr8v/dWzYJA8rAwpyh9Qd+NKWoJfjG5vvJqy9XOJ9H4P/lqulZBCgUWAYi+FeK5AuJ8g==", + "dev": true, + "peer": true + }, + "node_modules/elliptic": { + "version": "6.5.4", + "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.4.tgz", + "integrity": "sha512-iLhC6ULemrljPZb+QutR5TQGB+pdW6KGD5RSegS+8sorOZT+rdQFbsQFJgvN3eRqNALqJer4oQ16YvJHlU8hzQ==", + "dev": true, + "dependencies": { + "bn.js": "^4.11.9", + "brorand": "^1.1.0", + "hash.js": "^1.0.0", + "hmac-drbg": "^1.0.1", + "inherits": "^2.0.4", + "minimalistic-assert": "^1.0.1", + "minimalistic-crypto-utils": "^1.0.1" + } + }, + "node_modules/elliptic/node_modules/bn.js": { + "version": "4.12.0", + "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.12.0.tgz", + "integrity": "sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA==", + "dev": true + }, + "node_modules/emoji-regex": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", + "dev": true + }, + "node_modules/encodeurl": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", + "integrity": "sha512-TPJXq8JqFaVYm2CWmPvnP2Iyo4ZSM7/QKcSmuMLDObfpH5fi7RUGmd/rTDf+rut/saiDiQEeVTNgAmJEdAOx0w==", + "dev": true, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/engine.io": { + "version": "6.5.2", + "resolved": "https://registry.npmjs.org/engine.io/-/engine.io-6.5.2.tgz", + "integrity": "sha512-IXsMcGpw/xRfjra46sVZVHiSWo/nJ/3g1337q9KNXtS6YRzbW5yIzTCb9DjhrBe7r3GZQR0I4+nq+4ODk5g/cA==", + "dev": true, + "dependencies": { + "@types/cookie": "^0.4.1", + "@types/cors": "^2.8.12", + "@types/node": ">=10.0.0", + "accepts": "~1.3.4", + "base64id": "2.0.0", + "cookie": "~0.4.1", + "cors": "~2.8.5", + "debug": "~4.3.1", + "engine.io-parser": "~5.2.1", + "ws": "~8.11.0" + }, + "engines": { + "node": ">=10.2.0" + } + }, + "node_modules/engine.io-parser": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/engine.io-parser/-/engine.io-parser-5.2.1.tgz", + "integrity": "sha512-9JktcM3u18nU9N2Lz3bWeBgxVgOKpw7yhRaoxQA3FUDZzzw+9WlA6p4G4u0RixNkg14fH7EfEc/RhpurtiROTQ==", + "dev": true, + "engines": { + "node": ">=10.0.0" + } + }, + "node_modules/enhanced-resolve": { + "version": "5.15.0", + "resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.15.0.tgz", + "integrity": "sha512-LXYT42KJ7lpIKECr2mAXIaMldcNCh/7E0KBKOu4KSfkHmP+mZmSs+8V5gBAqisWBy0OO4W5Oyys0GO1Y8KtdKg==", + "dev": true, + "peer": true, + "dependencies": { + "graceful-fs": "^4.2.4", + "tapable": "^2.2.0" + }, + "engines": { + "node": ">=10.13.0" + } + }, + "node_modules/ent": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/ent/-/ent-2.2.0.tgz", + "integrity": "sha512-GHrMyVZQWvTIdDtpiEXdHZnFQKzeO09apj8Cbl4pKWy4i0Oprcq17usfDt5aO63swf0JOeMWjWQE/LzgSRuWpA==", + "dev": true + }, + "node_modules/err-code": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/err-code/-/err-code-3.0.1.tgz", + "integrity": "sha512-GiaH0KJUewYok+eeY05IIgjtAe4Yltygk9Wqp1V5yVWLdhf0hYZchRjNIT9bb0mSwRcIusT3cx7PJUf3zEIfUA==" + }, + "node_modules/es-module-lexer": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-1.3.0.tgz", + "integrity": "sha512-vZK7T0N2CBmBOixhmjdqx2gWVbFZ4DXZ/NyRMZVlJXPa7CyFS+/a4QQsDGDQy9ZfEzxFuNEsMLeQJnKP2p5/JA==", + "dev": true, + "peer": true + }, + "node_modules/es6-object-assign": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/es6-object-assign/-/es6-object-assign-1.1.0.tgz", + "integrity": "sha512-MEl9uirslVwqQU369iHNWZXsI8yaZYGg/D65aOgZkeyFJwHYSxilf7rQzXKI7DdDuBPrBXbfk3sl9hJhmd5AUw==", + "dev": true + }, + "node_modules/esbuild": { + "version": "0.16.17", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.16.17.tgz", + "integrity": "sha512-G8LEkV0XzDMNwXKgM0Jwu3nY3lSTwSGY6XbxM9cr9+s0T/qSV1q1JVPBGzm3dcjhCic9+emZDmMffkwgPeOeLg==", + "dev": true, + "hasInstallScript": true, + "bin": { + "esbuild": "bin/esbuild" + }, + "engines": { + "node": ">=12" + }, + "optionalDependencies": { + "@esbuild/android-arm": "0.16.17", + "@esbuild/android-arm64": "0.16.17", + "@esbuild/android-x64": "0.16.17", + "@esbuild/darwin-arm64": "0.16.17", + "@esbuild/darwin-x64": "0.16.17", + "@esbuild/freebsd-arm64": "0.16.17", + "@esbuild/freebsd-x64": "0.16.17", + "@esbuild/linux-arm": "0.16.17", + "@esbuild/linux-arm64": "0.16.17", + "@esbuild/linux-ia32": "0.16.17", + "@esbuild/linux-loong64": "0.16.17", + "@esbuild/linux-mips64el": "0.16.17", + "@esbuild/linux-ppc64": "0.16.17", + "@esbuild/linux-riscv64": "0.16.17", + "@esbuild/linux-s390x": "0.16.17", + "@esbuild/linux-x64": "0.16.17", + "@esbuild/netbsd-x64": "0.16.17", + "@esbuild/openbsd-x64": "0.16.17", + "@esbuild/sunos-x64": "0.16.17", + "@esbuild/win32-arm64": "0.16.17", + "@esbuild/win32-ia32": "0.16.17", + "@esbuild/win32-x64": "0.16.17" + } + }, + "node_modules/escalade": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz", + "integrity": "sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==", + "dev": true, + "engines": { + "node": ">=6" + } + }, + "node_modules/escape-html": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", + "integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==", + "dev": true + }, + "node_modules/escape-string-regexp": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", + "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", + "dev": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/eslint": { + "version": "8.47.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.47.0.tgz", + "integrity": "sha512-spUQWrdPt+pRVP1TTJLmfRNJJHHZryFmptzcafwSvHsceV81djHOdnEeDmkdotZyLNjDhrOasNK8nikkoG1O8Q==", + "dev": true, + "dependencies": { + "@eslint-community/eslint-utils": "^4.2.0", + "@eslint-community/regexpp": "^4.6.1", + "@eslint/eslintrc": "^2.1.2", + "@eslint/js": "^8.47.0", + "@humanwhocodes/config-array": "^0.11.10", + "@humanwhocodes/module-importer": "^1.0.1", + "@nodelib/fs.walk": "^1.2.8", + "ajv": "^6.12.4", + "chalk": "^4.0.0", + "cross-spawn": "^7.0.2", + "debug": "^4.3.2", + "doctrine": "^3.0.0", + "escape-string-regexp": "^4.0.0", + "eslint-scope": "^7.2.2", + "eslint-visitor-keys": "^3.4.3", + "espree": "^9.6.1", + "esquery": "^1.4.2", + "esutils": "^2.0.2", + "fast-deep-equal": "^3.1.3", + "file-entry-cache": "^6.0.1", + "find-up": "^5.0.0", + "glob-parent": "^6.0.2", + "globals": "^13.19.0", + "graphemer": "^1.4.0", + "ignore": "^5.2.0", + "imurmurhash": "^0.1.4", + "is-glob": "^4.0.0", + "is-path-inside": "^3.0.3", + "js-yaml": "^4.1.0", + "json-stable-stringify-without-jsonify": "^1.0.1", + "levn": "^0.4.1", + "lodash.merge": "^4.6.2", + "minimatch": "^3.1.2", + "natural-compare": "^1.4.0", + "optionator": "^0.9.3", + "strip-ansi": "^6.0.1", + "text-table": "^0.2.0" + }, + "bin": { + "eslint": "bin/eslint.js" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, + "node_modules/eslint-plugin-mocha": { + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-mocha/-/eslint-plugin-mocha-10.1.0.tgz", + "integrity": "sha512-xLqqWUF17llsogVOC+8C6/jvQ+4IoOREbN7ZCHuOHuD6cT5cDD4h7f2LgsZuzMAiwswWE21tO7ExaknHVDrSkw==", + "dev": true, + "dependencies": { + "eslint-utils": "^3.0.0", + "rambda": "^7.1.0" + }, + "engines": { + "node": ">=14.0.0" + }, + "peerDependencies": { + "eslint": ">=7.0.0" + } + }, + "node_modules/eslint-scope": { + "version": "7.2.2", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-7.2.2.tgz", + "integrity": "sha512-dOt21O7lTMhDM+X9mB4GX+DZrZtCUJPL/wlcTqxyrx5IvO0IYtILdtrQGQp+8n5S0gwSVmOf9NQrjMOgfQZlIg==", + "dev": true, + "dependencies": { + "esrecurse": "^4.3.0", + "estraverse": "^5.2.0" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, + "node_modules/eslint-utils": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-3.0.0.tgz", + "integrity": "sha512-uuQC43IGctw68pJA1RgbQS8/NP7rch6Cwd4j3ZBtgo4/8Flj4eGE7ZYSZRN3iq5pVUv6GPdW5Z1RFleo84uLDA==", + "dev": true, + "dependencies": { + "eslint-visitor-keys": "^2.0.0" + }, + "engines": { + "node": "^10.0.0 || ^12.0.0 || >= 14.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/mysticatea" + }, + "peerDependencies": { + "eslint": ">=5" + } + }, + "node_modules/eslint-utils/node_modules/eslint-visitor-keys": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-2.1.0.tgz", + "integrity": "sha512-0rSmRBzXgDzIsD6mGdJgevzgezI534Cer5L/vyMX0kHzT/jiB43jRhd9YUlMGYLQy2zprNmoT8qasCGtY+QaKw==", + "dev": true, + "engines": { + "node": ">=10" + } + }, + "node_modules/eslint-visitor-keys": { + "version": "3.4.3", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.4.3.tgz", + "integrity": "sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag==", + "dev": true, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, + "node_modules/eslint/node_modules/ajv": { + "version": "6.12.6", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", + "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", + "dev": true, + "dependencies": { + "fast-deep-equal": "^3.1.1", + "fast-json-stable-stringify": "^2.0.0", + "json-schema-traverse": "^0.4.1", + "uri-js": "^4.2.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, + "node_modules/eslint/node_modules/json-schema-traverse": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", + "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", + "dev": true + }, + "node_modules/espree": { + "version": "9.6.1", + "resolved": "https://registry.npmjs.org/espree/-/espree-9.6.1.tgz", + "integrity": "sha512-oruZaFkjorTpF32kDSI5/75ViwGeZginGGy2NoOSg3Q9bnwlnmDm4HLnkl0RE3n+njDXR037aY1+x58Z/zFdwQ==", + "dev": true, + "dependencies": { + "acorn": "^8.9.0", + "acorn-jsx": "^5.3.2", + "eslint-visitor-keys": "^3.4.1" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, + "node_modules/esquery": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.5.0.tgz", + "integrity": "sha512-YQLXUplAwJgCydQ78IMJywZCceoqk1oH01OERdSAJc/7U2AylwjhSCLDEtqwg811idIS/9fIU5GjG73IgjKMVg==", + "dev": true, + "dependencies": { + "estraverse": "^5.1.0" + }, + "engines": { + "node": ">=0.10" + } + }, + "node_modules/esrecurse": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.3.0.tgz", + "integrity": "sha512-KmfKL3b6G+RXvP8N1vr3Tq1kL/oCFgn2NYXEtqP8/L3pKapUA4G8cFVaoF3SU323CD4XypR/ffioHmkti6/Tag==", + "dev": true, + "dependencies": { + "estraverse": "^5.2.0" + }, + "engines": { + "node": ">=4.0" + } + }, + "node_modules/estraverse": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.3.0.tgz", + "integrity": "sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==", + "dev": true, + "engines": { + "node": ">=4.0" + } + }, + "node_modules/esutils": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", + "integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/event-target-shim": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz", + "integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==", + "engines": { + "node": ">=6" + } + }, + "node_modules/eventemitter3": { + "version": "4.0.7", + "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.7.tgz", + "integrity": "sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw==" + }, + "node_modules/events": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/events/-/events-3.3.0.tgz", + "integrity": "sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==", + "engines": { + "node": ">=0.8.x" + } + }, + "node_modules/evp_bytestokey": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/evp_bytestokey/-/evp_bytestokey-1.0.3.tgz", + "integrity": "sha512-/f2Go4TognH/KvCISP7OUsHn85hT9nUkxxA9BEWxFn+Oj9o8ZNLm/40hdlgSLyuOimsrTKLUMEorQexp/aPQeA==", + "dev": true, + "dependencies": { + "md5.js": "^1.3.4", + "safe-buffer": "^5.1.1" + } + }, + "node_modules/extend": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz", + "integrity": "sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==", + "dev": true + }, + "node_modules/fast-deep-equal": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", + "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==" + }, + "node_modules/fast-glob": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.1.tgz", + "integrity": "sha512-kNFPyjhh5cKjrUltxs+wFx+ZkbRaxxmZ+X0ZU31SOsxCEtP9VPgtq2teZw1DebupL5GmDaNQ6yKMMVcM41iqDg==", + "dev": true, + "dependencies": { + "@nodelib/fs.stat": "^2.0.2", + "@nodelib/fs.walk": "^1.2.3", + "glob-parent": "^5.1.2", + "merge2": "^1.3.0", + "micromatch": "^4.0.4" + }, + "engines": { + "node": ">=8.6.0" + } + }, + "node_modules/fast-glob/node_modules/glob-parent": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", + "dev": true, + "dependencies": { + "is-glob": "^4.0.1" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/fast-json-stable-stringify": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", + "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==", + "dev": true + }, + "node_modules/fast-levenshtein": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz", + "integrity": "sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==", + "dev": true + }, + "node_modules/fastq": { + "version": "1.15.0", + "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.15.0.tgz", + "integrity": "sha512-wBrocU2LCXXa+lWBt8RoIRD89Fi8OdABODa/kEnyeyjS5aZO5/GNvI5sEINADqP/h8M29UHTHUb53sUu5Ihqdw==", + "dev": true, + "dependencies": { + "reusify": "^1.0.4" + } + }, + "node_modules/file-entry-cache": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.1.tgz", + "integrity": "sha512-7Gps/XWymbLk2QLYK4NzpMOrYjMhdIxXuIvy2QBsLE6ljuodKvdkWs/cpyJJ3CVIVpH0Oi1Hvg1ovbMzLdFBBg==", + "dev": true, + "dependencies": { + "flat-cache": "^3.0.4" + }, + "engines": { + "node": "^10.12.0 || >=12.0.0" + } + }, + "node_modules/fill-range": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", + "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "dev": true, + "dependencies": { + "to-regex-range": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/finalhandler": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.2.tgz", + "integrity": "sha512-aAWcW57uxVNrQZqFXjITpW3sIUQmHGG3qSb9mUah9MgMC4NeWhNOlNjXEYq3HjRAvL6arUviZGGJsBg6z0zsWA==", + "dev": true, + "dependencies": { + "debug": "2.6.9", + "encodeurl": "~1.0.2", + "escape-html": "~1.0.3", + "on-finished": "~2.3.0", + "parseurl": "~1.3.3", + "statuses": "~1.5.0", + "unpipe": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/finalhandler/node_modules/debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "dev": true, + "dependencies": { + "ms": "2.0.0" + } + }, + "node_modules/finalhandler/node_modules/ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", + "dev": true + }, + "node_modules/finalhandler/node_modules/on-finished": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", + "integrity": "sha512-ikqdkGAAyf/X/gPhXGvfgAytDZtDbr+bkNUJ0N9h5MI/dmdgCs3l6hoHrcUv41sRKew3jIwrp4qQDXiK99Utww==", + "dev": true, + "dependencies": { + "ee-first": "1.1.1" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/find-up": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-5.0.0.tgz", + "integrity": "sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng==", + "dev": true, + "dependencies": { + "locate-path": "^6.0.0", + "path-exists": "^4.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/flat": { + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/flat/-/flat-5.0.2.tgz", + "integrity": "sha512-b6suED+5/3rTpUBdG1gupIl8MPFCAMA0QXwmljLhvCUKcUvdE4gWky9zpuGCcXHOsz4J9wPGNWq6OKpmIzz3hQ==", + "bin": { + "flat": "cli.js" + } + }, + "node_modules/flat-cache": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-3.0.4.tgz", + "integrity": "sha512-dm9s5Pw7Jc0GvMYbshN6zchCA9RgQlzzEZX3vylR9IqFfS8XciblUXOKfW6SiuJ0e13eDYZoZV5wdrev7P3Nwg==", + "dev": true, + "dependencies": { + "flatted": "^3.1.0", + "rimraf": "^3.0.2" + }, + "engines": { + "node": "^10.12.0 || >=12.0.0" + } + }, + "node_modules/flat-cache/node_modules/rimraf": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", + "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", + "dev": true, + "dependencies": { + "glob": "^7.1.3" + }, + "bin": { + "rimraf": "bin.js" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/flatted": { + "version": "3.2.7", + "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.2.7.tgz", + "integrity": "sha512-5nqDSxl8nn5BSNxyR3n4I6eDmbolI6WT+QqR547RwxQapgjQBmtktdP+HTBb/a/zLsbzERTONyUB5pefh5TtjQ==", + "dev": true + }, + "node_modules/follow-redirects": { + "version": "1.15.2", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz", + "integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==", + "dev": true, + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, + "node_modules/for-each": { + "version": "0.3.3", + "resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz", + "integrity": "sha512-jqYfLp7mo9vIyQf8ykW2v7A+2N4QjeCeI5+Dz9XraiO1ign81wjiH7Fb9vSOWvQfNtmSa4H2RoQTrrXivdUZmw==", + "dev": true, + "dependencies": { + "is-callable": "^1.1.3" + } + }, + "node_modules/foreground-child": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-2.0.0.tgz", + "integrity": "sha512-dCIq9FpEcyQyXKCkyzmlPTFNgrCzPudOe+mhvJU5zAtlBnGVy2yKxtfsxK2tQBThwq225jcvBjpw1Gr40uzZCA==", + "dev": true, + "dependencies": { + "cross-spawn": "^7.0.0", + "signal-exit": "^3.0.2" + }, + "engines": { + "node": ">=8.0.0" + } + }, + "node_modules/fs-extra": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz", + "integrity": "sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==", + "dev": true, + "dependencies": { + "graceful-fs": "^4.2.0", + "jsonfile": "^4.0.0", + "universalify": "^0.1.0" + }, + "engines": { + "node": ">=6 <7 || >=8" + } + }, + "node_modules/fs.realpath": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==", + "dev": true + }, + "node_modules/fsevents": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", + "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", + "dev": true, + "hasInstallScript": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, + "node_modules/function-bind": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", + "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", + "dev": true + }, + "node_modules/get-caller-file": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", + "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==", + "dev": true, + "engines": { + "node": "6.* || 8.* || >= 10.*" + } + }, + "node_modules/get-func-name": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.0.tgz", + "integrity": "sha512-Hm0ixYtaSZ/V7C8FJrtZIuBBI+iSgL+1Aq82zSu8VQNB4S3Gk8e7Qs3VwBDJAhmRZcFqkl3tQu36g/Foh5I5ig==", + "dev": true, + "engines": { + "node": "*" + } + }, + "node_modules/get-intrinsic": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.1.tgz", + "integrity": "sha512-2DcsyfABl+gVHEfCOaTrWgyt+tb6MSEGmKq+kI5HwLbIYgjgmMcV8KQ41uaKz1xxUcn9tJtgFbQUEVcEbd0FYw==", + "dev": true, + "dependencies": { + "function-bind": "^1.1.1", + "has": "^1.0.3", + "has-proto": "^1.0.1", + "has-symbols": "^1.0.3" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/glob": { + "version": "7.2.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", + "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", + "dev": true, + "dependencies": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.1.1", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + }, + "engines": { + "node": "*" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/glob-parent": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-6.0.2.tgz", + "integrity": "sha512-XxwI8EOhVQgWp6iDL+3b0r86f4d6AX6zSU55HfB4ydCEuXLXc5FcYeOu+nnGftS4TEju/11rt4KJPTMgbfmv4A==", + "dev": true, + "dependencies": { + "is-glob": "^4.0.3" + }, + "engines": { + "node": ">=10.13.0" + } + }, + "node_modules/glob-to-regexp": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/glob-to-regexp/-/glob-to-regexp-0.4.1.tgz", + "integrity": "sha512-lkX1HJXwyMcprw/5YUZc2s7DrpAiHB21/V+E1rHUrVNokkvB6bqMzT0VfV6/86ZNabt1k14YOIaT7nDvOX3Iiw==", + "dev": true, + "peer": true + }, + "node_modules/globals": { + "version": "13.21.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-13.21.0.tgz", + "integrity": "sha512-ybyme3s4yy/t/3s35bewwXKOf7cvzfreG2lH0lZl0JB7I4GxRP2ghxOK/Nb9EkRXdbBXZLfq/p/0W2JUONB/Gg==", + "dev": true, + "dependencies": { + "type-fest": "^0.20.2" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/globby": { + "version": "11.1.0", + "resolved": "https://registry.npmjs.org/globby/-/globby-11.1.0.tgz", + "integrity": "sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==", + "dev": true, + "dependencies": { + "array-union": "^2.1.0", + "dir-glob": "^3.0.1", + "fast-glob": "^3.2.9", + "ignore": "^5.2.0", + "merge2": "^1.4.1", + "slash": "^3.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/gopd": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz", + "integrity": "sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==", + "dev": true, + "dependencies": { + "get-intrinsic": "^1.1.3" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/graceful-fs": { + "version": "4.2.11", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", + "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==", + "dev": true + }, + "node_modules/graphemer": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/graphemer/-/graphemer-1.4.0.tgz", + "integrity": "sha512-EtKwoO6kxCL9WO5xipiHTZlSzBm7WLT627TqC/uVRd0HKmq8NXyebnNYxDoBi7wt8eTWrUrKXCOVaFq9x1kgag==", + "dev": true + }, + "node_modules/hamt-sharding": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/hamt-sharding/-/hamt-sharding-3.0.2.tgz", + "integrity": "sha512-f0DzBD2tSmLFdFsLAvOflIBqFPjerbA7BfmwO8mVho/5hXwgyyYhv+ijIzidQf/DpDX3bRjAQvhGoBFj+DBvPw==", + "dependencies": { + "sparse-array": "^1.3.1", + "uint8arrays": "^4.0.2" + }, + "engines": { + "node": ">=16.0.0", + "npm": ">=7.0.0" + } + }, + "node_modules/has": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", + "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", + "dev": true, + "dependencies": { + "function-bind": "^1.1.1" + }, + "engines": { + "node": ">= 0.4.0" + } + }, + "node_modules/has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/has-property-descriptors": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.0.tgz", + "integrity": "sha512-62DVLZGoiEBDHQyqG4w9xCuZ7eJEwNmJRWw2VY84Oedb7WFcA27fiEVe8oUQx9hAUJ4ekurquucTGwsyO1XGdQ==", + "dev": true, + "dependencies": { + "get-intrinsic": "^1.1.1" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/has-proto/-/has-proto-1.0.1.tgz", + "integrity": "sha512-7qE+iP+O+bgF9clE5+UoBFzE65mlBiVj3tKCrlNQ0Ogwm0BjpT/gK4SlLYDMybDh5I3TCTKnPPa0oMG7JDYrhg==", + "dev": true, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-symbols": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", + "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==", + "dev": true, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-tostringtag": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.0.tgz", + "integrity": "sha512-kFjcSNhnlGV1kyoGk7OXKSawH5JOb/LzUc5w9B02hOTO0dfFRjbHQKvg1d6cf3HbeUmtU9VbbV3qzZ2Teh97WQ==", + "dev": true, + "dependencies": { + "has-symbols": "^1.0.2" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/hash-base": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/hash-base/-/hash-base-3.1.0.tgz", + "integrity": "sha512-1nmYp/rhMDiE7AYkDw+lLwlAzz0AntGIe51F3RfFfEqyQ3feY2eI/NcwC6umIQVOASPMsWJLJScWKSSvzL9IVA==", + "dev": true, + "dependencies": { + "inherits": "^2.0.4", + "readable-stream": "^3.6.0", + "safe-buffer": "^5.2.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/hash-base/node_modules/readable-stream": { + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", + "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", + "dev": true, + "dependencies": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/hash-base/node_modules/safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ] + }, + "node_modules/hash-wasm": { + "version": "4.9.0", + "resolved": "https://registry.npmjs.org/hash-wasm/-/hash-wasm-4.9.0.tgz", + "integrity": "sha512-7SW7ejyfnRxuOc7ptQHSf4LDoZaWOivfzqw+5rpcQku0nHfmicPKE51ra9BiRLAmT8+gGLestr1XroUkqdjL6w==" + }, + "node_modules/hash.js": { + "version": "1.1.7", + "resolved": "https://registry.npmjs.org/hash.js/-/hash.js-1.1.7.tgz", + "integrity": "sha512-taOaskGt4z4SOANNseOviYDvjEJinIkRgmp7LbKP2YTTmVxWBl87s/uzK9r+44BclBSp2X7K1hqeNfz9JbBeXA==", + "dev": true, + "dependencies": { + "inherits": "^2.0.3", + "minimalistic-assert": "^1.0.1" + } + }, + "node_modules/he": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz", + "integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==", + "dev": true, + "bin": { + "he": "bin/he" + } + }, + "node_modules/hmac-drbg": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/hmac-drbg/-/hmac-drbg-1.0.1.tgz", + "integrity": "sha512-Tti3gMqLdZfhOQY1Mzf/AanLiqh1WTiJgEj26ZuYQ9fbkLomzGchCws4FyrSd4VkpBfiNhaE1On+lOz894jvXg==", + "dev": true, + "dependencies": { + "hash.js": "^1.0.3", + "minimalistic-assert": "^1.0.0", + "minimalistic-crypto-utils": "^1.0.1" + } + }, + "node_modules/html-escaper": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/html-escaper/-/html-escaper-2.0.2.tgz", + "integrity": "sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==", + "dev": true + }, + "node_modules/http-errors": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.0.tgz", + "integrity": "sha512-FtwrG/euBzaEjYeRqOgly7G0qviiXoJWnvEH2Z1plBdXgbyjv34pHTSb9zoeHMyDy33+DWy5Wt9Wo+TURtOYSQ==", + "dev": true, + "dependencies": { + "depd": "2.0.0", + "inherits": "2.0.4", + "setprototypeof": "1.2.0", + "statuses": "2.0.1", + "toidentifier": "1.0.1" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/http-errors/node_modules/statuses": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz", + "integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==", + "dev": true, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/http-proxy": { + "version": "1.18.1", + "resolved": "https://registry.npmjs.org/http-proxy/-/http-proxy-1.18.1.tgz", + "integrity": "sha512-7mz/721AbnJwIVbnaSv1Cz3Am0ZLT/UBwkC92VlxhXv/k/BBQfM2fXElQNC27BVGr0uwUpplYPQM9LnaBMR5NQ==", + "dev": true, + "dependencies": { + "eventemitter3": "^4.0.0", + "follow-redirects": "^1.0.0", + "requires-port": "^1.0.0" + }, + "engines": { + "node": ">=8.0.0" + } + }, + "node_modules/https-browserify": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/https-browserify/-/https-browserify-1.0.0.tgz", + "integrity": "sha512-J+FkSdyD+0mA0N+81tMotaRMfSL9SGi+xpD3T6YApKsc3bGSXJlfXri3VyFOeYkfLRQisDk1W+jIFFKBeUBbBg==", + "dev": true + }, + "node_modules/iconv-lite": { + "version": "0.4.24", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", + "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", + "dev": true, + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/ieee754": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", + "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ] + }, + "node_modules/ignore": { + "version": "5.2.4", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.2.4.tgz", + "integrity": "sha512-MAb38BcSbH0eHNBxn7ql2NH/kX33OkB3lZ1BNdh7ENeRChHTYsTvWrMubiIAMNS2llXEEgZ1MUOBtXChP3kaFQ==", + "dev": true, + "engines": { + "node": ">= 4" + } + }, + "node_modules/import-fresh": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.3.0.tgz", + "integrity": "sha512-veYYhQa+D1QBKznvhUHxb8faxlrwUnxseDAbAp457E0wLNio2bOSKnjYDhMj+YiAq61xrMGhQk9iXVk5FzgQMw==", + "dev": true, + "dependencies": { + "parent-module": "^1.0.0", + "resolve-from": "^4.0.0" + }, + "engines": { + "node": ">=6" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/imurmurhash": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", + "integrity": "sha512-JmXMZ6wuvDmLiHEml9ykzqO6lwFbof0GG4IkcGaENdCRDDmMVnny7s5HsIgHCbaq0w2MyPhDqkhTUgS2LU2PHA==", + "dev": true, + "engines": { + "node": ">=0.8.19" + } + }, + "node_modules/inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==", + "dev": true, + "dependencies": { + "once": "^1.3.0", + "wrappy": "1" + } + }, + "node_modules/inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + }, + "node_modules/interface-blockstore": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/interface-blockstore/-/interface-blockstore-5.2.3.tgz", + "integrity": "sha512-15cN+ZFdcVXdXo6I/SrSzFDsuJyDTyEI52XuvXQlR/G5fe3cK8p0tvVjfu5diRQH1XqNgmJEdMPixyt0xgjtvQ==", + "dependencies": { + "interface-store": "^5.0.0", + "multiformats": "^11.0.2" + }, + "engines": { + "node": ">=16.0.0", + "npm": ">=7.0.0" + } + }, + "node_modules/interface-store": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/interface-store/-/interface-store-5.1.2.tgz", + "integrity": "sha512-q2sLoqC+UdaWnjwGyghsH0jwqqVk226lsG207e3QwPB8sAZYmYIWUnJwJH3JjFNNRV9e6CUTmm+gDO0Xg4KRiw==", + "engines": { + "node": ">=16.0.0", + "npm": ">=7.0.0" + } + }, + "node_modules/ipfs-unixfs": { + "version": "11.0.1", + "resolved": "https://registry.npmjs.org/ipfs-unixfs/-/ipfs-unixfs-11.0.1.tgz", + "integrity": "sha512-SD9dqn14bfgMfkPstsR/2Av3zCzYMj2ntQJab4HZucgX4nNV6K7guZh4Hf3kiL8ONff1Ogft1ekFU083DIKEdQ==", + "dependencies": { + "err-code": "^3.0.1", + "protons-runtime": "^5.0.0", + "uint8arraylist": "^2.4.3" + }, + "engines": { + "node": ">=16.0.0", + "npm": ">=7.0.0" + } + }, + "node_modules/ipfs-unixfs-exporter": { + "version": "13.1.5", + "resolved": "https://registry.npmjs.org/ipfs-unixfs-exporter/-/ipfs-unixfs-exporter-13.1.5.tgz", + "integrity": "sha512-O5aMawsHoe4DaYk5FFil2EPrNOaU3pkHC6qUR5JMnW7es93W3b/RjJoO7AyDL1rpb+M3K0oRu86Yc5wLNQQ8jg==", + "dependencies": { + "@ipld/dag-cbor": "^9.0.0", + "@ipld/dag-pb": "^4.0.0", + "@multiformats/murmur3": "^2.0.0", + "err-code": "^3.0.1", + "hamt-sharding": "^3.0.0", + "interface-blockstore": "^5.0.0", + "ipfs-unixfs": "^11.0.0", + "it-filter": "^3.0.2", + "it-last": "^3.0.2", + "it-map": "^3.0.3", + "it-parallel": "^3.0.0", + "it-pipe": "^3.0.1", + "it-pushable": "^3.1.0", + "multiformats": "^11.0.0", + "p-queue": "^7.3.0", + "progress-events": "^1.0.0", + "uint8arrays": "^4.0.2" + }, + "engines": { + "node": ">=16.0.0", + "npm": ">=7.0.0" + } + }, + "node_modules/ipfs-unixfs-importer": { + "version": "15.1.5", + "resolved": "https://registry.npmjs.org/ipfs-unixfs-importer/-/ipfs-unixfs-importer-15.1.5.tgz", + "integrity": "sha512-TXaOI0M5KNpq2+qLw8AIYd0Lnc0gWTKCBqUd9eErBUwaP3Fna4qauF+JX9Rj2UrwaOvG/1xbF8Vm+92eOcKWMA==", + "dependencies": { + "@ipld/dag-pb": "^4.0.0", + "@multiformats/murmur3": "^2.0.0", + "err-code": "^3.0.1", + "hamt-sharding": "^3.0.0", + "interface-blockstore": "^5.0.0", + "interface-store": "^5.0.1", + "ipfs-unixfs": "^11.0.0", + "it-all": "^3.0.2", + "it-batch": "^3.0.2", + "it-first": "^3.0.2", + "it-parallel-batch": "^3.0.1", + "multiformats": "^11.0.0", + "progress-events": "^1.0.0", + "rabin-wasm": "^0.1.4", + "uint8arraylist": "^2.4.3", + "uint8arrays": "^4.0.2" + }, + "engines": { + "node": ">=16.0.0", + "npm": ">=7.0.0" + } + }, + "node_modules/is-arguments": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/is-arguments/-/is-arguments-1.1.1.tgz", + "integrity": "sha512-8Q7EARjzEnKpt/PCD7e1cgUS0a6X8u5tdSiMqXhojOdoV9TsMsiO+9VLC5vAmO8N7/GmXn7yjR8qnA6bVAEzfA==", + "dev": true, + "dependencies": { + "call-bind": "^1.0.2", + "has-tostringtag": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/is-binary-path": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", + "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", + "dev": true, + "dependencies": { + "binary-extensions": "^2.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/is-buffer": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.5.tgz", + "integrity": "sha512-i2R6zNFDwgEHJyQUtJEk0XFi1i0dPFn/oqjK3/vPCcDeJvW5NQ83V8QbicfF1SupOaB0h8ntgBC2YiE7dfyctQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "engines": { + "node": ">=4" + } + }, + "node_modules/is-callable": { + "version": "1.2.7", + "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.7.tgz", + "integrity": "sha512-1BC0BVFhS/p0qtw6enp8e+8OD0UrK0oFLztSjNzhcKA3WDuJxxAPXzPuPtKkjEY9UUoEWlX/8fgKeu2S8i9JTA==", + "dev": true, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/is-ci": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/is-ci/-/is-ci-3.0.1.tgz", + "integrity": "sha512-ZYvCgrefwqoQ6yTyYUbQu64HsITZ3NfKX1lzaEYdkTDcfKzzCI/wthRRYKkdjHKFVgNiXKAKm65Zo1pk2as/QQ==", + "dev": true, + "dependencies": { + "ci-info": "^3.2.0" + }, + "bin": { + "is-ci": "bin.js" + } + }, + "node_modules/is-core-module": { + "version": "2.13.0", + "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.13.0.tgz", + "integrity": "sha512-Z7dk6Qo8pOCp3l4tsX2C5ZVas4V+UxwQodwZhLopL91TX8UyyHEXafPcyoeeWuLrwzHcr3igO78wNLwHJHsMCQ==", + "dev": true, + "dependencies": { + "has": "^1.0.3" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/is-docker": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/is-docker/-/is-docker-2.2.1.tgz", + "integrity": "sha512-F+i2BKsFrH66iaUFc0woD8sLy8getkwTwtOBjvs56Cx4CgJDeKQeqfz8wAYiSb8JOprWhHH5p77PbmYCvvUuXQ==", + "dev": true, + "bin": { + "is-docker": "cli.js" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/is-extglob": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", + "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/is-fullwidth-code-point": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/is-generator-function": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/is-generator-function/-/is-generator-function-1.0.10.tgz", + "integrity": "sha512-jsEjy9l3yiXEQ+PsXdmBwEPcOxaXWLspKdplFUVI9vq1iZgIekeC0L167qeu86czQaxed3q/Uzuw0swL0irL8A==", + "dev": true, + "dependencies": { + "has-tostringtag": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/is-glob": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", + "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", + "dev": true, + "dependencies": { + "is-extglob": "^2.1.1" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/is-nan": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/is-nan/-/is-nan-1.3.2.tgz", + "integrity": "sha512-E+zBKpQ2t6MEo1VsonYmluk9NxGrbzpeeLC2xIViuO2EjU2xsXsBPwTr3Ykv9l08UYEVEdWeRZNouaZqF6RN0w==", + "dev": true, + "dependencies": { + "call-bind": "^1.0.0", + "define-properties": "^1.1.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/is-number": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", + "dev": true, + "engines": { + "node": ">=0.12.0" + } + }, + "node_modules/is-path-inside": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/is-path-inside/-/is-path-inside-3.0.3.tgz", + "integrity": "sha512-Fd4gABb+ycGAmKou8eMftCupSir5lRxqf4aD/vd0cD2qc4HL07OjCeuHMr8Ro4CoMaeCKDB0/ECBOVWjTwUvPQ==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/is-plain-obj": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-2.1.0.tgz", + "integrity": "sha512-YWnfyRwxL/+SsrWYfOpUtz5b3YD+nyfkHvjbcanzk8zgyO4ASD67uVMRt8k5bM4lLMDnXfriRhOpemw+NfT1eA==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/is-typed-array": { + "version": "1.1.12", + "resolved": "https://registry.npmjs.org/is-typed-array/-/is-typed-array-1.1.12.tgz", + "integrity": "sha512-Z14TF2JNG8Lss5/HMqt0//T9JeHXttXy5pH/DBU4vi98ozO2btxzq9MwYDZYnKwU8nRsz/+GVFVRDq3DkVuSPg==", + "dev": true, + "dependencies": { + "which-typed-array": "^1.1.11" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/is-unicode-supported": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/is-unicode-supported/-/is-unicode-supported-0.1.0.tgz", + "integrity": "sha512-knxG2q4UC3u8stRGyAVJCOdxFmv5DZiRcdlIaAQXAbSfJya+OhopNotLQrstBhququ4ZpuKbDc/8S6mgXgPFPw==", + "dev": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/is-wsl": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/is-wsl/-/is-wsl-2.2.0.tgz", + "integrity": "sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww==", + "dev": true, + "dependencies": { + "is-docker": "^2.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/isarray": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", + "integrity": "sha512-D2S+3GLxWH+uhrNEcoh/fnmYeP8E8/zHl644d/jdA0g2uyXvy3sb0qxotE+ne0LtccHknQzWwZEzhak7oJ0COQ==", + "dev": true + }, + "node_modules/isbinaryfile": { + "version": "4.0.10", + "resolved": "https://registry.npmjs.org/isbinaryfile/-/isbinaryfile-4.0.10.tgz", + "integrity": "sha512-iHrqe5shvBUcFbmZq9zOQHBoeOhZJu6RQGrDpBgenUm/Am+F3JM2MgQj+rK3Z601fzrL5gLZWtAPH2OBaSVcyw==", + "dev": true, + "engines": { + "node": ">= 8.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/gjtorikian/" + } + }, + "node_modules/isexe": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", + "dev": true + }, + "node_modules/isomorphic-timers-promises": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/isomorphic-timers-promises/-/isomorphic-timers-promises-1.0.1.tgz", + "integrity": "sha512-u4sej9B1LPSxTGKB/HiuzvEQnXH0ECYkSVQU39koSwmFAxhlEAFl9RdTvLv4TOTQUgBS5O3O5fwUxk6byBZ+IQ==", + "dev": true, + "engines": { + "node": ">=10" + } + }, + "node_modules/istanbul-lib-coverage": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/istanbul-lib-coverage/-/istanbul-lib-coverage-3.2.0.tgz", + "integrity": "sha512-eOeJ5BHCmHYvQK7xt9GkdHuzuCGS1Y6g9Gvnx3Ym33fz/HpLRYxiS0wHNr+m/MBC8B647Xt608vCDEvhl9c6Mw==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/istanbul-lib-report": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/istanbul-lib-report/-/istanbul-lib-report-3.0.1.tgz", + "integrity": "sha512-GCfE1mtsHGOELCU8e/Z7YWzpmybrx/+dSTfLrvY8qRmaY6zXTKWn6WQIjaAFw069icm6GVMNkgu0NzI4iPZUNw==", + "dev": true, + "dependencies": { + "istanbul-lib-coverage": "^3.0.0", + "make-dir": "^4.0.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/istanbul-reports": { + "version": "3.1.6", + "resolved": "https://registry.npmjs.org/istanbul-reports/-/istanbul-reports-3.1.6.tgz", + "integrity": "sha512-TLgnMkKg3iTDsQ9PbPTdpfAK2DzjF9mqUG7RMgcQl8oFjad8ob4laGxv5XV5U9MAfx8D6tSJiUyuAwzLicaxlg==", + "dev": true, + "dependencies": { + "html-escaper": "^2.0.0", + "istanbul-lib-report": "^3.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/it-all": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/it-all/-/it-all-3.0.3.tgz", + "integrity": "sha512-LwEVD1d0b1O5mDwumnZk+80jSBn5sXDxQ41xiD6j6l2lRiWH6lBLdxXx1C6mlKrXQwRHzUQagOZUmqttDUwb0A==" + }, + "node_modules/it-batch": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/it-batch/-/it-batch-3.0.3.tgz", + "integrity": "sha512-KdKVGOZgYhxiHTMphzPKaiNL99yyUgeDoqRmSedbKJr05nP5RxtiIPWX+i1dLCADRjExbGtKfFsrogNgH0h9SA==" + }, + "node_modules/it-filter": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/it-filter/-/it-filter-3.0.3.tgz", + "integrity": "sha512-2zXUrJuuV6QHM21ahc8NqVUUxkLMVDWXBoUBcj9GCQLQez2OXmddTHN0r0F5B+TkNTpeL618yIgXi1HNPJOxow==", + "dependencies": { + "it-peekable": "^3.0.0" + } + }, + "node_modules/it-first": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/it-first/-/it-first-3.0.3.tgz", + "integrity": "sha512-RC8tplctsDpoBUljwsp1viiyaR5fPvMe+FgbbcU0sFjKkJa7iwbB4CCPhHtVYSdjsrREfr0QEotfQrBoGyt7Dw==" + }, + "node_modules/it-last": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/it-last/-/it-last-3.0.3.tgz", + "integrity": "sha512-veF0zWTMEJ466Otxz7jPbExiJGfJYTOiHYGfg8iGwKPIV558zIGZQJU1WNyjHfugFzAyfuFlIZKsXCCtCl8LgQ==" + }, + "node_modules/it-map": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/it-map/-/it-map-3.0.4.tgz", + "integrity": "sha512-h5zCxovJQ+mzJT75xP4GkJuFrJQ5l7IIdhZ6AOWaE02g5F7T1k1j4CB/uKSRR05LLLOi1LqG+7CrH9bi8GIXYA==", + "dependencies": { + "it-peekable": "^3.0.0" + } + }, + "node_modules/it-merge": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/it-merge/-/it-merge-3.0.2.tgz", + "integrity": "sha512-bMk2km8lTz+Rwv30hzDUdGIcqQkOemFJqmGT2wqQZ6/zHKCsYqdRunPrteCqHLV/nIVhUK8nZZkDA2eJ4MJZiA==", + "dependencies": { + "it-pushable": "^3.2.0" + } + }, + "node_modules/it-parallel": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/it-parallel/-/it-parallel-3.0.4.tgz", + "integrity": "sha512-fuA+SysGxbZc+Yl7EUvzQqZ8bNYQghZ0Mq9zA+fxMQ5eQYzatNg6oJk1y1PvPvNqLgKJMzEInpRO6PbLC3hGAg==", + "dependencies": { + "p-defer": "^4.0.0" + } + }, + "node_modules/it-parallel-batch": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/it-parallel-batch/-/it-parallel-batch-3.0.2.tgz", + "integrity": "sha512-8ci62F5gn5aS8/wEC0kvRKWCmenHlIi+R8waEF/SP1ImQhhkve9l4/DXEmoL7UeI5FqJktzkMzZwqDng0ZppKw==", + "dependencies": { + "it-batch": "^3.0.0" + } + }, + "node_modules/it-peekable": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/it-peekable/-/it-peekable-3.0.2.tgz", + "integrity": "sha512-nWwUdhNQ1CfAuoJmsaUotNMYUrfNIlY9gBA1jwWfWSu1I0mLY2brwreKHGOUptXLJUiG5pR04He0xYZMWBRiGA==" + }, + "node_modules/it-pipe": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/it-pipe/-/it-pipe-3.0.1.tgz", + "integrity": "sha512-sIoNrQl1qSRg2seYSBH/3QxWhJFn9PKYvOf/bHdtCBF0bnghey44VyASsWzn5dAx0DCDDABq1hZIuzKmtBZmKA==", + "dependencies": { + "it-merge": "^3.0.0", + "it-pushable": "^3.1.2", + "it-stream-types": "^2.0.1" + }, + "engines": { + "node": ">=16.0.0", + "npm": ">=7.0.0" + } + }, + "node_modules/it-pushable": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/it-pushable/-/it-pushable-3.2.1.tgz", + "integrity": "sha512-sLFz2Q0oyDCJpTciZog7ipP4vSftfPy3e6JnH6YyztRa1XqkpGQaafK3Jw/JlfEBtCXfnX9uVfcpu3xpSAqCVQ==", + "dependencies": { + "p-defer": "^4.0.0" + }, + "engines": { + "node": ">=16.0.0", + "npm": ">=7.0.0" + } + }, + "node_modules/it-stream-types": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/it-stream-types/-/it-stream-types-2.0.1.tgz", + "integrity": "sha512-6DmOs5r7ERDbvS4q8yLKENcj6Yecr7QQTqWApbZdfAUTEC947d+PEha7PCqhm//9oxaLYL7TWRekwhoXl2s6fg==", + "engines": { + "node": ">=16.0.0", + "npm": ">=7.0.0" + } + }, + "node_modules/jest-worker": { + "version": "27.5.1", + "resolved": "https://registry.npmjs.org/jest-worker/-/jest-worker-27.5.1.tgz", + "integrity": "sha512-7vuh85V5cdDofPyxn58nrPjBktZo0u9x1g8WtjQol+jZDaE+fhN+cIvTj11GndBnMnyfrUOG1sZQxCdjKh+DKg==", + "dev": true, + "peer": true, + "dependencies": { + "@types/node": "*", + "merge-stream": "^2.0.0", + "supports-color": "^8.0.0" + }, + "engines": { + "node": ">= 10.13.0" + } + }, + "node_modules/jest-worker/node_modules/supports-color": { + "version": "8.1.1", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz", + "integrity": "sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==", + "dev": true, + "peer": true, + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/supports-color?sponsor=1" + } + }, + "node_modules/js-yaml": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", + "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", + "dev": true, + "dependencies": { + "argparse": "^2.0.1" + }, + "bin": { + "js-yaml": "bin/js-yaml.js" + } + }, + "node_modules/jsbi": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/jsbi/-/jsbi-4.3.0.tgz", + "integrity": "sha512-SnZNcinB4RIcnEyZqFPdGPVgrg2AcnykiBy0sHVJQKHYeaLUvi3Exj+iaPpLnFVkDPZIV4U0yvgC9/R4uEAZ9g==" + }, + "node_modules/json-parse-even-better-errors": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/json-parse-even-better-errors/-/json-parse-even-better-errors-2.3.1.tgz", + "integrity": "sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w==", + "dev": true, + "peer": true + }, + "node_modules/json-schema-traverse": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", + "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==" + }, + "node_modules/json-stable-stringify-without-jsonify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz", + "integrity": "sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==", + "dev": true + }, + "node_modules/jsonfile": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", + "integrity": "sha512-m6F1R3z8jjlf2imQHS2Qez5sjKWQzbuuhuJ/FKYFRZvPE3PuHcSMVZzfsLhGVOkfd20obL5SWEBew5ShlquNxg==", + "dev": true, + "optionalDependencies": { + "graceful-fs": "^4.1.6" + } + }, + "node_modules/just-extend": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/just-extend/-/just-extend-4.2.1.tgz", + "integrity": "sha512-g3UB796vUFIY90VIv/WX3L2c8CS2MdWUww3CNrYmqza1Fg0DURc2K/O4YrnklBdQarSJ/y8JnJYDGc+1iumQjg==", + "dev": true + }, + "node_modules/karma": { + "version": "6.4.1", + "resolved": "https://registry.npmjs.org/karma/-/karma-6.4.1.tgz", + "integrity": "sha512-Cj57NKOskK7wtFWSlMvZf459iX+kpYIPXmkNUzP2WAFcA7nhr/ALn5R7sw3w+1udFDcpMx/tuB8d5amgm3ijaA==", + "dev": true, + "dependencies": { + "@colors/colors": "1.5.0", + "body-parser": "^1.19.0", + "braces": "^3.0.2", + "chokidar": "^3.5.1", + "connect": "^3.7.0", + "di": "^0.0.1", + "dom-serialize": "^2.2.1", + "glob": "^7.1.7", + "graceful-fs": "^4.2.6", + "http-proxy": "^1.18.1", + "isbinaryfile": "^4.0.8", + "lodash": "^4.17.21", + "log4js": "^6.4.1", + "mime": "^2.5.2", + "minimatch": "^3.0.4", + "mkdirp": "^0.5.5", + "qjobs": "^1.2.0", + "range-parser": "^1.2.1", + "rimraf": "^3.0.2", + "socket.io": "^4.4.1", + "source-map": "^0.6.1", + "tmp": "^0.2.1", + "ua-parser-js": "^0.7.30", + "yargs": "^16.1.1" + }, + "bin": { + "karma": "bin/karma" + }, + "engines": { + "node": ">= 10" + } + }, + "node_modules/karma-chai": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/karma-chai/-/karma-chai-0.1.0.tgz", + "integrity": "sha512-mqKCkHwzPMhgTYca10S90aCEX9+HjVjjrBFAsw36Zj7BlQNbokXXCAe6Ji04VUMsxcY5RLP7YphpfO06XOubdg==", + "dev": true, + "peerDependencies": { + "chai": "*", + "karma": ">=0.10.9" + } + }, + "node_modules/karma-chrome-launcher": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/karma-chrome-launcher/-/karma-chrome-launcher-3.1.1.tgz", + "integrity": "sha512-hsIglcq1vtboGPAN+DGCISCFOxW+ZVnIqhDQcCMqqCp+4dmJ0Qpq5QAjkbA0X2L9Mi6OBkHi2Srrbmm7pUKkzQ==", + "dev": true, + "dependencies": { + "which": "^1.2.1" + } + }, + "node_modules/karma-chrome-launcher/node_modules/which": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", + "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==", + "dev": true, + "dependencies": { + "isexe": "^2.0.0" + }, + "bin": { + "which": "bin/which" + } + }, + "node_modules/karma-esbuild": { + "version": "2.2.5", + "resolved": "https://registry.npmjs.org/karma-esbuild/-/karma-esbuild-2.2.5.tgz", + "integrity": "sha512-+NiRmZhUm/MqOsL1cAu8+RmiOMvIxWDaeYDLBB5upxHF9Hh3Og8YH43EAmDan40pxt2FKDcOjupgqIe4Tx2szQ==", + "dev": true, + "dependencies": { + "chokidar": "^3.5.1", + "source-map": "0.6.1" + }, + "peerDependencies": { + "esbuild": ">=0.8.45" + } + }, + "node_modules/karma-firefox-launcher": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/karma-firefox-launcher/-/karma-firefox-launcher-2.1.2.tgz", + "integrity": "sha512-VV9xDQU1QIboTrjtGVD4NCfzIH7n01ZXqy/qpBhnOeGVOkG5JYPEm8kuSd7psHE6WouZaQ9Ool92g8LFweSNMA==", + "dev": true, + "dependencies": { + "is-wsl": "^2.2.0", + "which": "^2.0.1" + } + }, + "node_modules/karma-mocha": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/karma-mocha/-/karma-mocha-2.0.1.tgz", + "integrity": "sha512-Tzd5HBjm8his2OA4bouAsATYEpZrp9vC7z5E5j4C5Of5Rrs1jY67RAwXNcVmd/Bnk1wgvQRou0zGVLey44G4tQ==", + "dev": true, + "dependencies": { + "minimist": "^1.2.3" + } + }, + "node_modules/karma-mocha-reporter": { + "version": "2.2.5", + "resolved": "https://registry.npmjs.org/karma-mocha-reporter/-/karma-mocha-reporter-2.2.5.tgz", + "integrity": "sha512-Hr6nhkIp0GIJJrvzY8JFeHpQZNseuIakGac4bpw8K1+5F0tLb6l7uvXRa8mt2Z+NVwYgCct4QAfp2R2QP6o00w==", + "dev": true, + "dependencies": { + "chalk": "^2.1.0", + "log-symbols": "^2.1.0", + "strip-ansi": "^4.0.0" + }, + "peerDependencies": { + "karma": ">=0.13" + } + }, + "node_modules/karma-mocha-reporter/node_modules/ansi-regex": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.1.tgz", + "integrity": "sha512-+O9Jct8wf++lXxxFc4hc8LsjaSq0HFzzL7cVsw8pRDIPdjKD2mT4ytDZlLuSBZ4cLKZFXIrMGO7DbQCtMJJMKw==", + "dev": true, + "engines": { + "node": ">=4" + } + }, + "node_modules/karma-mocha-reporter/node_modules/ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "dev": true, + "dependencies": { + "color-convert": "^1.9.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/karma-mocha-reporter/node_modules/chalk": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", + "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", + "dev": true, + "dependencies": { + "ansi-styles": "^3.2.1", + "escape-string-regexp": "^1.0.5", + "supports-color": "^5.3.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/karma-mocha-reporter/node_modules/color-convert": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", + "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", + "dev": true, + "dependencies": { + "color-name": "1.1.3" + } + }, + "node_modules/karma-mocha-reporter/node_modules/color-name": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", + "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==", + "dev": true + }, + "node_modules/karma-mocha-reporter/node_modules/escape-string-regexp": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", + "integrity": "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==", + "dev": true, + "engines": { + "node": ">=0.8.0" + } + }, + "node_modules/karma-mocha-reporter/node_modules/has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==", + "dev": true, + "engines": { + "node": ">=4" + } + }, + "node_modules/karma-mocha-reporter/node_modules/strip-ansi": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", + "integrity": "sha512-4XaJ2zQdCzROZDivEVIDPkcQn8LMFSa8kj8Gxb/Lnwzv9A8VctNZ+lfivC/sV3ivW8ElJTERXZoPBRrZKkNKow==", + "dev": true, + "dependencies": { + "ansi-regex": "^3.0.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/karma-mocha-reporter/node_modules/supports-color": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", + "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "dev": true, + "dependencies": { + "has-flag": "^3.0.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/karma-webkit-launcher": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/karma-webkit-launcher/-/karma-webkit-launcher-2.1.0.tgz", + "integrity": "sha512-S5eqhH0DIcuJFi27nC6eBxZ3MTrPnYybPthDU2Q8dfG0yFrXx8FqNDKSbRZsFFvAKJ55QVtYH1bbArd3ddI5Sg==", + "dev": true, + "dependencies": { + "is-ci": "^3.0.1", + "uuid": "^9.0.0" + }, + "peerDependenciesMeta": { + "playwright": { + "optional": true + } + } + }, + "node_modules/karma-webkit-launcher/node_modules/uuid": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.0.tgz", + "integrity": "sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg==", + "dev": true, + "bin": { + "uuid": "dist/bin/uuid" + } + }, + "node_modules/karma/node_modules/cliui": { + "version": "7.0.4", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-7.0.4.tgz", + "integrity": "sha512-OcRE68cOsVMXp1Yvonl/fzkQOyjLSu/8bhPDfQt0e0/Eb283TKP20Fs2MqoPsr9SwA595rRCA+QMzYc9nBP+JQ==", + "dev": true, + "dependencies": { + "string-width": "^4.2.0", + "strip-ansi": "^6.0.0", + "wrap-ansi": "^7.0.0" + } + }, + "node_modules/karma/node_modules/rimraf": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", + "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", + "dev": true, + "dependencies": { + "glob": "^7.1.3" + }, + "bin": { + "rimraf": "bin.js" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/karma/node_modules/yargs": { + "version": "16.2.0", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-16.2.0.tgz", + "integrity": "sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw==", + "dev": true, + "dependencies": { + "cliui": "^7.0.2", + "escalade": "^3.1.1", + "get-caller-file": "^2.0.5", + "require-directory": "^2.1.1", + "string-width": "^4.2.0", + "y18n": "^5.0.5", + "yargs-parser": "^20.2.2" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/karma/node_modules/yargs-parser": { + "version": "20.2.9", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-20.2.9.tgz", + "integrity": "sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w==", + "dev": true, + "engines": { + "node": ">=10" + } + }, + "node_modules/level": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/level/-/level-8.0.0.tgz", + "integrity": "sha512-ypf0jjAk2BWI33yzEaaotpq7fkOPALKAgDBxggO6Q9HGX2MRXn0wbP1Jn/tJv1gtL867+YOjOB49WaUF3UoJNQ==", + "dependencies": { + "browser-level": "^1.0.1", + "classic-level": "^1.2.0" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/level" + } + }, + "node_modules/level-supports": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/level-supports/-/level-supports-4.0.1.tgz", + "integrity": "sha512-PbXpve8rKeNcZ9C1mUicC9auIYFyGpkV9/i6g76tLgANwWhtG2v7I4xNBUlkn3lE2/dZF3Pi0ygYGtLc4RXXdA==", + "engines": { + "node": ">=12" + } + }, + "node_modules/level-transcoder": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/level-transcoder/-/level-transcoder-1.0.1.tgz", + "integrity": "sha512-t7bFwFtsQeD8cl8NIoQ2iwxA0CL/9IFw7/9gAjOonH0PWTTiRfY7Hq+Ejbsxh86tXobDQ6IOiddjNYIfOBs06w==", + "dependencies": { + "buffer": "^6.0.3", + "module-error": "^1.0.1" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/levn": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz", + "integrity": "sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==", + "dev": true, + "dependencies": { + "prelude-ls": "^1.2.1", + "type-check": "~0.4.0" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/loader-runner": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/loader-runner/-/loader-runner-4.3.0.tgz", + "integrity": "sha512-3R/1M+yS3j5ou80Me59j7F9IMs4PXs3VqRrm0TU3AbKPxlmpoY1TNscJV/oGJXo8qCatFGTfDbY6W6ipGOYXfg==", + "dev": true, + "peer": true, + "engines": { + "node": ">=6.11.5" + } + }, + "node_modules/locate-path": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz", + "integrity": "sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==", + "dev": true, + "dependencies": { + "p-locate": "^5.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/lodash": { + "version": "4.17.21", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" + }, + "node_modules/lodash.get": { + "version": "4.4.2", + "resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz", + "integrity": "sha512-z+Uw/vLuy6gQe8cfaFWD7p0wVv8fJl3mbzXh33RS+0oW2wvUqiRXiQ69gLWSLpgB5/6sU+r6BlQR0MBILadqTQ==", + "dev": true + }, + "node_modules/lodash.merge": { + "version": "4.6.2", + "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", + "integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==", + "dev": true + }, + "node_modules/log-symbols": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-2.2.0.tgz", + "integrity": "sha512-VeIAFslyIerEJLXHziedo2basKbMKtTw3vfn5IzG0XTjhAVEJyNHnL2p7vc+wBDSdQuUpNw3M2u6xb9QsAY5Eg==", + "dev": true, + "dependencies": { + "chalk": "^2.0.1" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/log-symbols/node_modules/ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "dev": true, + "dependencies": { + "color-convert": "^1.9.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/log-symbols/node_modules/chalk": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", + "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", + "dev": true, + "dependencies": { + "ansi-styles": "^3.2.1", + "escape-string-regexp": "^1.0.5", + "supports-color": "^5.3.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/log-symbols/node_modules/color-convert": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", + "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", + "dev": true, + "dependencies": { + "color-name": "1.1.3" + } + }, + "node_modules/log-symbols/node_modules/color-name": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", + "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==", + "dev": true + }, + "node_modules/log-symbols/node_modules/escape-string-regexp": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", + "integrity": "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==", + "dev": true, + "engines": { + "node": ">=0.8.0" + } + }, + "node_modules/log-symbols/node_modules/has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==", + "dev": true, + "engines": { + "node": ">=4" + } + }, + "node_modules/log-symbols/node_modules/supports-color": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", + "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "dev": true, + "dependencies": { + "has-flag": "^3.0.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/log4js": { + "version": "6.9.1", + "resolved": "https://registry.npmjs.org/log4js/-/log4js-6.9.1.tgz", + "integrity": "sha512-1somDdy9sChrr9/f4UlzhdaGfDR2c/SaD2a4T7qEkG4jTS57/B3qmnjLYePwQ8cqWnUHZI0iAKxMBpCZICiZ2g==", + "dev": true, + "dependencies": { + "date-format": "^4.0.14", + "debug": "^4.3.4", + "flatted": "^3.2.7", + "rfdc": "^1.3.0", + "streamroller": "^3.1.5" + }, + "engines": { + "node": ">=8.0" + } + }, + "node_modules/long": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/long/-/long-5.2.3.tgz", + "integrity": "sha512-lcHwpNoggQTObv5apGNCTdJrO69eHOZMi4BNC+rTLER8iHAqGrUVeLh/irVIM7zTw2bOXA8T6uNPeujwOLg/2Q==" + }, + "node_modules/loupe": { + "version": "2.3.6", + "resolved": "https://registry.npmjs.org/loupe/-/loupe-2.3.6.tgz", + "integrity": "sha512-RaPMZKiMy8/JruncMU5Bt6na1eftNoo++R4Y+N2FrxkDVTrGvcyzFTsaGif4QTeKESheMGegbhw6iUAq+5A8zA==", + "dev": true, + "dependencies": { + "get-func-name": "^2.0.0" + } + }, + "node_modules/lru-cache": { + "version": "9.1.2", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-9.1.2.tgz", + "integrity": "sha512-ERJq3FOzJTxBbFjZ7iDs+NiK4VI9Wz+RdrrAB8dio1oV+YvdPzUEE4QNiT2VD51DkIbCYRUUzCRkssXCHqSnKQ==", + "engines": { + "node": "14 || >=16.14" + } + }, + "node_modules/make-dir": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-4.0.0.tgz", + "integrity": "sha512-hXdUTZYIVOt1Ex//jAQi+wTZZpUpwBj/0QsOzqegb3rGMMeJiSEu5xLHnYfBrRV4RH2+OCSOO95Is/7x1WJ4bw==", + "dev": true, + "dependencies": { + "semver": "^7.5.3" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/md5.js": { + "version": "1.3.5", + "resolved": "https://registry.npmjs.org/md5.js/-/md5.js-1.3.5.tgz", + "integrity": "sha512-xitP+WxNPcTTOgnTJcrhM0xvdPepipPSf3I8EIpGKeFLjt3PlJLIDG3u8EX53ZIubkb+5U2+3rELYpEhHhzdkg==", + "dev": true, + "dependencies": { + "hash-base": "^3.0.0", + "inherits": "^2.0.1", + "safe-buffer": "^5.1.2" + } + }, + "node_modules/media-typer": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", + "integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==", + "dev": true, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/merge-stream": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz", + "integrity": "sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==", + "dev": true, + "peer": true + }, + "node_modules/merge2": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz", + "integrity": "sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==", + "dev": true, + "engines": { + "node": ">= 8" + } + }, + "node_modules/micromatch": { + "version": "4.0.5", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.5.tgz", + "integrity": "sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==", + "dev": true, + "dependencies": { + "braces": "^3.0.2", + "picomatch": "^2.3.1" + }, + "engines": { + "node": ">=8.6" + } + }, + "node_modules/miller-rabin": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/miller-rabin/-/miller-rabin-4.0.1.tgz", + "integrity": "sha512-115fLhvZVqWwHPbClyntxEVfVDfl9DLLTuJvq3g2O/Oxi8AiNouAHvDSzHS0viUJc+V5vm3eq91Xwqn9dp4jRA==", + "dev": true, + "dependencies": { + "bn.js": "^4.0.0", + "brorand": "^1.0.1" + }, + "bin": { + "miller-rabin": "bin/miller-rabin" + } + }, + "node_modules/miller-rabin/node_modules/bn.js": { + "version": "4.12.0", + "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.12.0.tgz", + "integrity": "sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA==", + "dev": true + }, + "node_modules/mime": { + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/mime/-/mime-2.6.0.tgz", + "integrity": "sha512-USPkMeET31rOMiarsBNIHZKLGgvKc/LrjofAnBlOttf5ajRvqiRA8QsenbcooctK6d6Ts6aqZXBA+XbkKthiQg==", + "dev": true, + "bin": { + "mime": "cli.js" + }, + "engines": { + "node": ">=4.0.0" + } + }, + "node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "dev": true, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "dev": true, + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/minimalistic-assert": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/minimalistic-assert/-/minimalistic-assert-1.0.1.tgz", + "integrity": "sha512-UtJcAD4yEaGtjPezWuO9wC4nwUnVH/8/Im3yEHQP4b67cXlD/Qr9hdITCU1xDbSEXg2XKNaP8jsReV7vQd00/A==", + "dev": true + }, + "node_modules/minimalistic-crypto-utils": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/minimalistic-crypto-utils/-/minimalistic-crypto-utils-1.0.1.tgz", + "integrity": "sha512-JIYlbt6g8i5jKfJ3xz7rF0LXmv2TkDxBLUkiBeZ7bAx4GnnNMr8xFpGnOxn6GhTEHx3SjRrZEoU+j04prX1ktg==", + "dev": true + }, + "node_modules/minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "dev": true, + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, + "node_modules/minimist": { + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", + "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/minipass": { + "version": "4.2.8", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-4.2.8.tgz", + "integrity": "sha512-fNzuVyifolSLFL4NzpF+wEF4qrgqaaKX0haXPQEdQ7NKAN+WecoKMHV09YcuL/DHxrUsYQOK3MiuDf7Ip2OXfQ==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/mkdirp": { + "version": "0.5.6", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz", + "integrity": "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==", + "dev": true, + "dependencies": { + "minimist": "^1.2.6" + }, + "bin": { + "mkdirp": "bin/cmd.js" + } + }, + "node_modules/mocha": { + "version": "10.2.0", + "resolved": "https://registry.npmjs.org/mocha/-/mocha-10.2.0.tgz", + "integrity": "sha512-IDY7fl/BecMwFHzoqF2sg/SHHANeBoMMXFlS9r0OXKDssYE1M5O43wUY/9BVPeIvfH2zmEbBfseqN9gBQZzXkg==", + "dev": true, + "dependencies": { + "ansi-colors": "4.1.1", + "browser-stdout": "1.3.1", + "chokidar": "3.5.3", + "debug": "4.3.4", + "diff": "5.0.0", + "escape-string-regexp": "4.0.0", + "find-up": "5.0.0", + "glob": "7.2.0", + "he": "1.2.0", + "js-yaml": "4.1.0", + "log-symbols": "4.1.0", + "minimatch": "5.0.1", + "ms": "2.1.3", + "nanoid": "3.3.3", + "serialize-javascript": "6.0.0", + "strip-json-comments": "3.1.1", + "supports-color": "8.1.1", + "workerpool": "6.2.1", + "yargs": "16.2.0", + "yargs-parser": "20.2.4", + "yargs-unparser": "2.0.0" + }, + "bin": { + "_mocha": "bin/_mocha", + "mocha": "bin/mocha.js" + }, + "engines": { + "node": ">= 14.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/mochajs" + } + }, + "node_modules/mocha/node_modules/cliui": { + "version": "7.0.4", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-7.0.4.tgz", + "integrity": "sha512-OcRE68cOsVMXp1Yvonl/fzkQOyjLSu/8bhPDfQt0e0/Eb283TKP20Fs2MqoPsr9SwA595rRCA+QMzYc9nBP+JQ==", + "dev": true, + "dependencies": { + "string-width": "^4.2.0", + "strip-ansi": "^6.0.0", + "wrap-ansi": "^7.0.0" + } + }, + "node_modules/mocha/node_modules/glob": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.0.tgz", + "integrity": "sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q==", + "dev": true, + "dependencies": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + }, + "engines": { + "node": "*" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/mocha/node_modules/glob/node_modules/minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "dev": true, + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, + "node_modules/mocha/node_modules/log-symbols": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-4.1.0.tgz", + "integrity": "sha512-8XPvpAA8uyhfteu8pIvQxpJZ7SYYdpUivZpGy6sFsBuKRY/7rQGavedeB8aK+Zkyq6upMFVL/9AW6vOYzfRyLg==", + "dev": true, + "dependencies": { + "chalk": "^4.1.0", + "is-unicode-supported": "^0.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/mocha/node_modules/minimatch": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.0.1.tgz", + "integrity": "sha512-nLDxIFRyhDblz3qMuq+SoRZED4+miJ/G+tdDrjkkkRnjAsBexeGpgjLEQ0blJy7rHhR2b93rhQY4SvyWu9v03g==", + "dev": true, + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/mocha/node_modules/minimatch/node_modules/brace-expansion": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "dev": true, + "dependencies": { + "balanced-match": "^1.0.0" + } + }, + "node_modules/mocha/node_modules/supports-color": { + "version": "8.1.1", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz", + "integrity": "sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==", + "dev": true, + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/supports-color?sponsor=1" + } + }, + "node_modules/mocha/node_modules/yargs": { + "version": "16.2.0", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-16.2.0.tgz", + "integrity": "sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw==", + "dev": true, + "dependencies": { + "cliui": "^7.0.2", + "escalade": "^3.1.1", + "get-caller-file": "^2.0.5", + "require-directory": "^2.1.1", + "string-width": "^4.2.0", + "y18n": "^5.0.5", + "yargs-parser": "^20.2.2" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/mocha/node_modules/yargs-parser": { + "version": "20.2.4", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-20.2.4.tgz", + "integrity": "sha512-WOkpgNhPTlE73h4VFAFsOnomJVaovO8VqLDzy5saChRBFQFBoMYirowyW+Q9HB4HFF4Z7VZTiG3iSzJJA29yRA==", + "dev": true, + "engines": { + "node": ">=10" + } + }, + "node_modules/module-error": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/module-error/-/module-error-1.0.2.tgz", + "integrity": "sha512-0yuvsqSCv8LbaOKhnsQ/T5JhyFlCYLPXK3U2sgV10zoKQwzs/MyfuQUOZQ1V/6OCOJsK/TRgNVrPuPDqtdMFtA==", + "engines": { + "node": ">=10" + } + }, + "node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" + }, + "node_modules/multibase": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/multibase/-/multibase-4.0.6.tgz", + "integrity": "sha512-x23pDe5+svdLz/k5JPGCVdfn7Q5mZVMBETiC+ORfO+sor9Sgs0smJzAjfTbM5tckeCqnaUuMYoz+k3RXMmJClQ==", + "deprecated": "This module has been superseded by the multiformats module", + "dependencies": { + "@multiformats/base-x": "^4.0.1" + }, + "engines": { + "node": ">=12.0.0", + "npm": ">=6.0.0" + } + }, + "node_modules/multiformats": { + "version": "11.0.2", + "resolved": "https://registry.npmjs.org/multiformats/-/multiformats-11.0.2.tgz", + "integrity": "sha512-b5mYMkOkARIuVZCpvijFj9a6m5wMVLC7cf/jIPd5D/ARDOfLC5+IFkbgDXQgcU2goIsTD/O9NY4DI/Mt4OGvlg==", + "engines": { + "node": ">=16.0.0", + "npm": ">=7.0.0" + } + }, + "node_modules/multihashes": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/multihashes/-/multihashes-4.0.3.tgz", + "integrity": "sha512-0AhMH7Iu95XjDLxIeuCOOE4t9+vQZsACyKZ9Fxw2pcsRmlX4iCn1mby0hS0bb+nQOVpdQYWPpnyusw4da5RPhA==", + "dependencies": { + "multibase": "^4.0.1", + "uint8arrays": "^3.0.0", + "varint": "^5.0.2" + }, + "engines": { + "node": ">=12.0.0", + "npm": ">=6.0.0" + } + }, + "node_modules/multihashes/node_modules/multiformats": { + "version": "9.9.0", + "resolved": "https://registry.npmjs.org/multiformats/-/multiformats-9.9.0.tgz", + "integrity": "sha512-HoMUjhH9T8DDBNT+6xzkrd9ga/XiBI4xLr58LJACwK6G3HTOPeMz4nB4KJs33L2BelrIJa7P0VuNaVF3hMYfjg==" + }, + "node_modules/multihashes/node_modules/uint8arrays": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/uint8arrays/-/uint8arrays-3.1.1.tgz", + "integrity": "sha512-+QJa8QRnbdXVpHYjLoTpJIdCTiw9Ir62nocClWuXIq2JIh4Uta0cQsTSpFL678p2CN8B+XSApwcU+pQEqVpKWg==", + "dependencies": { + "multiformats": "^9.4.2" + } + }, + "node_modules/multihashes/node_modules/varint": { + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/varint/-/varint-5.0.2.tgz", + "integrity": "sha512-lKxKYG6H03yCZUpAGOPOsMcGxd1RHCu1iKvEHYDPmTyq2HueGhD73ssNBqqQWfvYs04G9iUFRvmAVLW20Jw6ow==" + }, + "node_modules/murmurhash3js-revisited": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/murmurhash3js-revisited/-/murmurhash3js-revisited-3.0.0.tgz", + "integrity": "sha512-/sF3ee6zvScXMb1XFJ8gDsSnY+X8PbOyjIuBhtgis10W2Jx4ZjIhikUCIF9c4gpJxVnQIsPAFrSwTCuAjicP6g==", + "engines": { + "node": ">=8.0.0" + } + }, + "node_modules/nanoid": { + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.3.tgz", + "integrity": "sha512-p1sjXuopFs0xg+fPASzQ28agW1oHD7xDsd9Xkf3T15H3c/cifrFHVwrh74PdoklAPi+i7MdRsE47vm2r6JoB+w==", + "dev": true, + "bin": { + "nanoid": "bin/nanoid.cjs" + }, + "engines": { + "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" + } + }, + "node_modules/napi-macros": { + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/napi-macros/-/napi-macros-2.2.2.tgz", + "integrity": "sha512-hmEVtAGYzVQpCKdbQea4skABsdXW4RUh5t5mJ2zzqowJS2OyXZTU1KhDVFhx+NlWZ4ap9mqR9TcDO3LTTttd+g==" + }, + "node_modules/natural-compare": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", + "integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==", + "dev": true + }, + "node_modules/negotiator": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", + "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==", + "dev": true, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/neo-async": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/neo-async/-/neo-async-2.6.2.tgz", + "integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==", + "dev": true, + "peer": true + }, + "node_modules/nise": { + "version": "5.1.4", + "resolved": "https://registry.npmjs.org/nise/-/nise-5.1.4.tgz", + "integrity": "sha512-8+Ib8rRJ4L0o3kfmyVCL7gzrohyDe0cMFTBa2d364yIrEGMEoetznKJx899YxjybU6bL9SQkYPSBBs1gyYs8Xg==", + "dev": true, + "dependencies": { + "@sinonjs/commons": "^2.0.0", + "@sinonjs/fake-timers": "^10.0.2", + "@sinonjs/text-encoding": "^0.7.1", + "just-extend": "^4.0.2", + "path-to-regexp": "^1.7.0" + } + }, + "node_modules/nise/node_modules/@sinonjs/commons": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-2.0.0.tgz", + "integrity": "sha512-uLa0j859mMrg2slwQYdO/AkrOfmH+X6LTVmNTS9CqexuE2IvVORIkSpJLqePAbEnKJ77aMmCwr1NUZ57120Xcg==", + "dev": true, + "dependencies": { + "type-detect": "4.0.8" + } + }, + "node_modules/node-fetch": { + "version": "2.6.7", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz", + "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==", + "dependencies": { + "whatwg-url": "^5.0.0" + }, + "engines": { + "node": "4.x || >=6.0.0" + }, + "peerDependencies": { + "encoding": "^0.1.0" + }, + "peerDependenciesMeta": { + "encoding": { + "optional": true + } + } + }, + "node_modules/node-gyp-build": { + "version": "4.6.0", + "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.6.0.tgz", + "integrity": "sha512-NTZVKn9IylLwUzaKjkas1e4u2DLNcV4rdYagA4PWdPwW87Bi7z+BznyKSRwS/761tV/lzCGXplWsiaMjLqP2zQ==", + "bin": { + "node-gyp-build": "bin.js", + "node-gyp-build-optional": "optional.js", + "node-gyp-build-test": "build-test.js" + } + }, + "node_modules/node-releases": { + "version": "2.0.13", + "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.13.tgz", + "integrity": "sha512-uYr7J37ae/ORWdZeQ1xxMJe3NtdmqMC/JZK+geofDrkLUApKRHPd18/TxtBOJ4A0/+uUIliorNrfYV6s1b02eQ==", + "dev": true, + "peer": true + }, + "node_modules/node-stdlib-browser": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/node-stdlib-browser/-/node-stdlib-browser-1.2.0.tgz", + "integrity": "sha512-VSjFxUhRhkyed8AtLwSCkMrJRfQ3e2lGtG3sP6FEgaLKBBbxM/dLfjRe1+iLhjvyLFW3tBQ8+c0pcOtXGbAZJg==", + "dev": true, + "dependencies": { + "assert": "^2.0.0", + "browser-resolve": "^2.0.0", + "browserify-zlib": "^0.2.0", + "buffer": "^5.7.1", + "console-browserify": "^1.1.0", + "constants-browserify": "^1.0.0", + "create-require": "^1.1.1", + "crypto-browserify": "^3.11.0", + "domain-browser": "^4.22.0", + "events": "^3.0.0", + "https-browserify": "^1.0.0", + "isomorphic-timers-promises": "^1.0.1", + "os-browserify": "^0.3.0", + "path-browserify": "^1.0.1", + "pkg-dir": "^5.0.0", + "process": "^0.11.10", + "punycode": "^1.4.1", + "querystring-es3": "^0.2.1", + "readable-stream": "^3.6.0", + "stream-browserify": "^3.0.0", + "stream-http": "^3.2.0", + "string_decoder": "^1.0.0", + "timers-browserify": "^2.0.4", + "tty-browserify": "0.0.1", + "url": "^0.11.0", + "util": "^0.12.4", + "vm-browserify": "^1.0.1" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/node-stdlib-browser/node_modules/buffer": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz", + "integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "dependencies": { + "base64-js": "^1.3.1", + "ieee754": "^1.1.13" + } + }, + "node_modules/node-stdlib-browser/node_modules/readable-stream": { + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", + "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", + "dev": true, + "dependencies": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/normalize-path": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", + "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/object-inspect": { + "version": "1.12.3", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.3.tgz", + "integrity": "sha512-geUvdk7c+eizMNUDkRpW1wJwgfOiOeHbxBR/hLXK1aT6zmVSO0jsQcs7fj6MGw89jC/cjGfLcNOrtMYtGqm81g==", + "dev": true, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/object-is": { + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/object-is/-/object-is-1.1.5.tgz", + "integrity": "sha512-3cyDsyHgtmi7I7DfSSI2LDp6SK2lwvtbg0p0R1e0RvTqF5ceGx+K2dfSjm1bKDMVCFEDAQvy+o8c6a7VujOddw==", + "dev": true, + "dependencies": { + "call-bind": "^1.0.2", + "define-properties": "^1.1.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/object-keys": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz", + "integrity": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==", + "dev": true, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/on-finished": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz", + "integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==", + "dev": true, + "dependencies": { + "ee-first": "1.1.1" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", + "dev": true, + "dependencies": { + "wrappy": "1" + } + }, + "node_modules/optionator": { + "version": "0.9.3", + "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.3.tgz", + "integrity": "sha512-JjCoypp+jKn1ttEFExxhetCKeJt9zhAgAve5FXHixTvFDW/5aEktX9bufBKLRRMdU7bNtpLfcGu94B3cdEJgjg==", + "dev": true, + "dependencies": { + "@aashutoshrathi/word-wrap": "^1.2.3", + "deep-is": "^0.1.3", + "fast-levenshtein": "^2.0.6", + "levn": "^0.4.1", + "prelude-ls": "^1.2.1", + "type-check": "^0.4.0" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/os-browserify": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/os-browserify/-/os-browserify-0.3.0.tgz", + "integrity": "sha512-gjcpUc3clBf9+210TRaDWbf+rZZZEshZ+DlXMRCeAjp0xhTrnQsKHypIy1J3d5hKdUzj69t708EHtU8P6bUn0A==", + "dev": true + }, + "node_modules/p-defer": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/p-defer/-/p-defer-4.0.0.tgz", + "integrity": "sha512-Vb3QRvQ0Y5XnF40ZUWW7JfLogicVh/EnA5gBIvKDJoYpeI82+1E3AlB9yOcKFS0AhHrWVnAQO39fbR0G99IVEQ==", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/p-limit": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", + "integrity": "sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==", + "dev": true, + "dependencies": { + "yocto-queue": "^0.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/p-locate": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-5.0.0.tgz", + "integrity": "sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw==", + "dev": true, + "dependencies": { + "p-limit": "^3.0.2" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/p-queue": { + "version": "7.3.4", + "resolved": "https://registry.npmjs.org/p-queue/-/p-queue-7.3.4.tgz", + "integrity": "sha512-esox8CWt0j9EZECFvkFl2WNPat8LN4t7WWeXq73D9ha0V96qPRufApZi4ZhPwXAln1uVVal429HVVKPa2X0yQg==", + "dependencies": { + "eventemitter3": "^4.0.7", + "p-timeout": "^5.0.2" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/p-timeout": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/p-timeout/-/p-timeout-5.1.0.tgz", + "integrity": "sha512-auFDyzzzGZZZdHz3BtET9VEz0SE/uMEAx7uWfGPucfzEwwe/xH0iVeZibQmANYE/hp9T2+UUZT5m+BKyrDp3Ew==", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/pako": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/pako/-/pako-1.0.11.tgz", + "integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==", + "dev": true + }, + "node_modules/parent-module": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", + "integrity": "sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==", + "dev": true, + "dependencies": { + "callsites": "^3.0.0" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/parse-asn1": { + "version": "5.1.6", + "resolved": "https://registry.npmjs.org/parse-asn1/-/parse-asn1-5.1.6.tgz", + "integrity": "sha512-RnZRo1EPU6JBnra2vGHj0yhp6ebyjBZpmUCLHWiFhxlzvBCCpAuZ7elsBp1PVAbQN0/04VD/19rfzlBSwLstMw==", + "dev": true, + "dependencies": { + "asn1.js": "^5.2.0", + "browserify-aes": "^1.0.0", + "evp_bytestokey": "^1.0.0", + "pbkdf2": "^3.0.3", + "safe-buffer": "^5.1.1" + } + }, + "node_modules/parseurl": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", + "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==", + "dev": true, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/path-browserify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-browserify/-/path-browserify-1.0.1.tgz", + "integrity": "sha512-b7uo2UCUOYZcnF/3ID0lulOJi/bafxa1xPe7ZPsammBSpjSWQkjNxlt635YGS2MiR9GjvuXCtz2emr3jbsz98g==", + "dev": true + }, + "node_modules/path-exists": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", + "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/path-key": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", + "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/path-parse": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", + "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==", + "dev": true + }, + "node_modules/path-scurry": { + "version": "1.10.1", + "resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-1.10.1.tgz", + "integrity": "sha512-MkhCqzzBEpPvxxQ71Md0b1Kk51W01lrYvlMzSUaIzNsODdd7mqhiimSZlr+VegAz5Z6Vzt9Xg2ttE//XBhH3EQ==", + "dev": true, + "dependencies": { + "lru-cache": "^9.1.1 || ^10.0.0", + "minipass": "^5.0.0 || ^6.0.2 || ^7.0.0" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/path-scurry/node_modules/minipass": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.0.3.tgz", + "integrity": "sha512-LhbbwCfz3vsb12j/WkWQPZfKTsgqIe1Nf/ti1pKjYESGLHIVjWU96G9/ljLH4F9mWNVhlQOm0VySdAWzf05dpg==", + "dev": true, + "engines": { + "node": ">=16 || 14 >=14.17" + } + }, + "node_modules/path-to-regexp": { + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-1.8.0.tgz", + "integrity": "sha512-n43JRhlUKUAlibEJhPeir1ncUID16QnEjNpwzNdO3Lm4ywrBpBZ5oLD0I6br9evr1Y9JTqwRtAh7JLoOzAQdVA==", + "dev": true, + "dependencies": { + "isarray": "0.0.1" + } + }, + "node_modules/path-type": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz", + "integrity": "sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/pathval": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.1.tgz", + "integrity": "sha512-Dp6zGqpTdETdR63lehJYPeIOqpiNBNtc7BpWSLrOje7UaIsE5aY92r/AunQA7rsXvet3lrJ3JnZX29UPTKXyKQ==", + "dev": true, + "engines": { + "node": "*" + } + }, + "node_modules/pbkdf2": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/pbkdf2/-/pbkdf2-3.1.2.tgz", + "integrity": "sha512-iuh7L6jA7JEGu2WxDwtQP1ddOpaJNC4KlDEFfdQajSGgGPNi4OyDc2R7QnbY2bR9QjBVGwgvTdNJZoE7RaxUMA==", + "dev": true, + "dependencies": { + "create-hash": "^1.1.2", + "create-hmac": "^1.1.4", + "ripemd160": "^2.0.1", + "safe-buffer": "^5.0.1", + "sha.js": "^2.4.8" + }, + "engines": { + "node": ">=0.12" + } + }, + "node_modules/picocolors": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz", + "integrity": "sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==", + "dev": true, + "peer": true + }, + "node_modules/picomatch": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", + "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", + "dev": true, + "engines": { + "node": ">=8.6" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, + "node_modules/pkg-dir": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-5.0.0.tgz", + "integrity": "sha512-NPE8TDbzl/3YQYY7CSS228s3g2ollTFnc+Qi3tqmqJp9Vg2ovUpixcJEo2HJScN2Ez+kEaal6y70c0ehqJBJeA==", + "dev": true, + "dependencies": { + "find-up": "^5.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/playwright": { + "version": "1.36.2", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.36.2.tgz", + "integrity": "sha512-4Fmlq3KWsl85Bl4InJw1NC21aeQV0iSZuFvTDcy1F8zVmXmgQRe89GxF8zMSRt/KIS+2tUolak7EXVl9aC+JdA==", + "dev": true, + "hasInstallScript": true, + "dependencies": { + "playwright-core": "1.36.2" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=16" + } + }, + "node_modules/playwright-core": { + "version": "1.36.2", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.36.2.tgz", + "integrity": "sha512-sQYZt31dwkqxOrP7xy2ggDfEzUxM1lodjhsQ3NMMv5uGTRDsLxU0e4xf4wwMkF2gplIxf17QMBCodSFgm6bFVQ==", + "dev": true, + "bin": { + "playwright-core": "cli.js" + }, + "engines": { + "node": ">=16" + } + }, + "node_modules/prelude-ls": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", + "integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==", + "dev": true, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/process": { + "version": "0.11.10", + "resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz", + "integrity": "sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A==", + "engines": { + "node": ">= 0.6.0" + } + }, + "node_modules/progress-events": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/progress-events/-/progress-events-1.0.0.tgz", + "integrity": "sha512-zIB6QDrSbPfRg+33FZalluFIowkbV5Xh1xSuetjG+rlC5he6u2dc6VQJ0TbMdlN3R1RHdpOqxEFMKTnQ+itUwA==", + "engines": { + "node": ">=16.0.0", + "npm": ">=7.0.0" + } + }, + "node_modules/protobufjs": { + "version": "7.2.4", + "resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-7.2.4.tgz", + "integrity": "sha512-AT+RJgD2sH8phPmCf7OUZR8xGdcJRga4+1cOaXJ64hvcSkVhNcRHOwIxUatPH15+nj59WAGTDv3LSGZPEQbJaQ==", + "hasInstallScript": true, + "dependencies": { + "@protobufjs/aspromise": "^1.1.2", + "@protobufjs/base64": "^1.1.2", + "@protobufjs/codegen": "^2.0.4", + "@protobufjs/eventemitter": "^1.1.0", + "@protobufjs/fetch": "^1.1.0", + "@protobufjs/float": "^1.0.2", + "@protobufjs/inquire": "^1.1.0", + "@protobufjs/path": "^1.1.2", + "@protobufjs/pool": "^1.1.0", + "@protobufjs/utf8": "^1.1.0", + "@types/node": ">=13.7.0", + "long": "^5.0.0" + }, + "engines": { + "node": ">=12.0.0" + } + }, + "node_modules/protons-runtime": { + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/protons-runtime/-/protons-runtime-5.0.2.tgz", + "integrity": "sha512-eKppVrIS5dDh+Y61Yj4bDEOs2sQLQbQGIhr7EBiybPQhIMGBynzVXlYILPWl3Td1GDadobc8qevh5D+JwfG9bw==", + "dependencies": { + "protobufjs": "^7.0.0", + "uint8arraylist": "^2.4.3" + }, + "peerDependencies": { + "uint8arraylist": "^2.3.2" + } + }, + "node_modules/public-encrypt": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/public-encrypt/-/public-encrypt-4.0.3.tgz", + "integrity": "sha512-zVpa8oKZSz5bTMTFClc1fQOnyyEzpl5ozpi1B5YcvBrdohMjH2rfsBtyXcuNuwjsDIXmBYlF2N5FlJYhR29t8Q==", + "dev": true, + "dependencies": { + "bn.js": "^4.1.0", + "browserify-rsa": "^4.0.0", + "create-hash": "^1.1.0", + "parse-asn1": "^5.0.0", + "randombytes": "^2.0.1", + "safe-buffer": "^5.1.2" + } + }, + "node_modules/public-encrypt/node_modules/bn.js": { + "version": "4.12.0", + "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.12.0.tgz", + "integrity": "sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA==", + "dev": true + }, + "node_modules/punycode": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz", + "integrity": "sha512-jmYNElW7yvO7TV33CjSmvSiE2yco3bV2czu/OzDKdMNVZQWfxCblURLhf+47syQRBntjfLdd/H0egrzIG+oaFQ==", + "dev": true + }, + "node_modules/qjobs": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/qjobs/-/qjobs-1.2.0.tgz", + "integrity": "sha512-8YOJEHtxpySA3fFDyCRxA+UUV+fA+rTWnuWvylOK/NCjhY+b4ocCtmu8TtsWb+mYeU+GCHf/S66KZF/AsteKHg==", + "dev": true, + "engines": { + "node": ">=0.9" + } + }, + "node_modules/qs": { + "version": "6.11.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz", + "integrity": "sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==", + "dev": true, + "dependencies": { + "side-channel": "^1.0.4" + }, + "engines": { + "node": ">=0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/querystring-es3": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/querystring-es3/-/querystring-es3-0.2.1.tgz", + "integrity": "sha512-773xhDQnZBMFobEiztv8LIl70ch5MSF/jUQVlhwFyBILqq96anmoctVIYz+ZRp0qbCKATTn6ev02M3r7Ga5vqA==", + "dev": true, + "engines": { + "node": ">=0.4.x" + } + }, + "node_modules/queue-microtask": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz", + "integrity": "sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ] + }, + "node_modules/rabin-wasm": { + "version": "0.1.5", + "resolved": "https://registry.npmjs.org/rabin-wasm/-/rabin-wasm-0.1.5.tgz", + "integrity": "sha512-uWgQTo7pim1Rnj5TuWcCewRDTf0PEFTSlaUjWP4eY9EbLV9em08v89oCz/WO+wRxpYuO36XEHp4wgYQnAgOHzA==", + "dependencies": { + "@assemblyscript/loader": "^0.9.4", + "bl": "^5.0.0", + "debug": "^4.3.1", + "minimist": "^1.2.5", + "node-fetch": "^2.6.1", + "readable-stream": "^3.6.0" + }, + "bin": { + "rabin-wasm": "cli/bin.js" + } + }, + "node_modules/rabin-wasm/node_modules/readable-stream": { + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", + "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", + "dependencies": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/rambda": { + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/rambda/-/rambda-7.5.0.tgz", + "integrity": "sha512-y/M9weqWAH4iopRd7EHDEQQvpFPHj1AA3oHozE9tfITHUtTR7Z9PSlIRRG2l1GuW7sefC1cXFfIcF+cgnShdBA==", + "dev": true + }, + "node_modules/randombytes": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz", + "integrity": "sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ==", + "dependencies": { + "safe-buffer": "^5.1.0" + } + }, + "node_modules/randomfill": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/randomfill/-/randomfill-1.0.4.tgz", + "integrity": "sha512-87lcbR8+MhcWcUiQ+9e+Rwx8MyR2P7qnt15ynUlbm3TU/fjbgz4GsvfSUDTemtCCtVCqb4ZcEFlyPNTh9bBTLw==", + "dev": true, + "dependencies": { + "randombytes": "^2.0.5", + "safe-buffer": "^5.1.0" + } + }, + "node_modules/range-parser": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", + "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==", + "dev": true, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/raw-body": { + "version": "2.5.2", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.2.tgz", + "integrity": "sha512-8zGqypfENjCIqGhgXToC8aB2r7YrBX+AQAfIPs/Mlk+BtPTztOvTS01NRW/3Eh60J+a48lt8qsCzirQ6loCVfA==", + "dev": true, + "dependencies": { + "bytes": "3.1.2", + "http-errors": "2.0.0", + "iconv-lite": "0.4.24", + "unpipe": "1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/readable-stream": { + "version": "4.4.2", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-4.4.2.tgz", + "integrity": "sha512-Lk/fICSyIhodxy1IDK2HazkeGjSmezAWX2egdtJnYhtzKEsBPJowlI6F6LPb5tqIQILrMbx22S5o3GuJavPusA==", + "dependencies": { + "abort-controller": "^3.0.0", + "buffer": "^6.0.3", + "events": "^3.3.0", + "process": "^0.11.10", + "string_decoder": "^1.3.0" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + } + }, + "node_modules/readable-web-to-node-stream": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/readable-web-to-node-stream/-/readable-web-to-node-stream-3.0.2.tgz", + "integrity": "sha512-ePeK6cc1EcKLEhJFt/AebMCLL+GgSKhuygrZ/GLaKZYEecIgIECf4UaUuaByiGtzckwR4ain9VzUh95T1exYGw==", + "dependencies": { + "readable-stream": "^3.6.0" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/Borewit" + } + }, + "node_modules/readable-web-to-node-stream/node_modules/readable-stream": { + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", + "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", + "dependencies": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/readdirp": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", + "integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==", + "dev": true, + "dependencies": { + "picomatch": "^2.2.1" + }, + "engines": { + "node": ">=8.10.0" + } + }, + "node_modules/require-directory": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", + "integrity": "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/require-from-string": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz", + "integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/requires-port": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz", + "integrity": "sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ==", + "dev": true + }, + "node_modules/resolve": { + "version": "1.22.4", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.4.tgz", + "integrity": "sha512-PXNdCiPqDqeUou+w1C2eTQbNfxKSuMxqTCuvlmmMsk1NWHL5fRrhY6Pl0qEYYc6+QqGClco1Qj8XnjPego4wfg==", + "dev": true, + "dependencies": { + "is-core-module": "^2.13.0", + "path-parse": "^1.0.7", + "supports-preserve-symlinks-flag": "^1.0.0" + }, + "bin": { + "resolve": "bin/resolve" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/resolve-from": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", + "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==", + "dev": true, + "engines": { + "node": ">=4" + } + }, + "node_modules/reusify": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/reusify/-/reusify-1.0.4.tgz", + "integrity": "sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==", + "dev": true, + "engines": { + "iojs": ">=1.0.0", + "node": ">=0.10.0" + } + }, + "node_modules/rfdc": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/rfdc/-/rfdc-1.3.0.tgz", + "integrity": "sha512-V2hovdzFbOi77/WajaSMXk2OLm+xNIeQdMMuB7icj7bk6zi2F8GGAxigcnDFpJHbNyNcgyJDiP+8nOrY5cZGrA==", + "dev": true + }, + "node_modules/rimraf": { + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-4.4.0.tgz", + "integrity": "sha512-X36S+qpCUR0HjXlkDe4NAOhS//aHH0Z+h8Ckf2auGJk3PTnx5rLmrHkwNdbVQuCSUhOyFrlRvFEllZOYE+yZGQ==", + "dev": true, + "dependencies": { + "glob": "^9.2.0" + }, + "bin": { + "rimraf": "dist/cjs/src/bin.js" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/rimraf/node_modules/brace-expansion": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "dev": true, + "dependencies": { + "balanced-match": "^1.0.0" + } + }, + "node_modules/rimraf/node_modules/glob": { + "version": "9.3.5", + "resolved": "https://registry.npmjs.org/glob/-/glob-9.3.5.tgz", + "integrity": "sha512-e1LleDykUz2Iu+MTYdkSsuWX8lvAjAcs0Xef0lNIu0S2wOAzuTxCJtcd9S3cijlwYF18EsU3rzb8jPVobxDh9Q==", + "dev": true, + "dependencies": { + "fs.realpath": "^1.0.0", + "minimatch": "^8.0.2", + "minipass": "^4.2.4", + "path-scurry": "^1.6.1" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/rimraf/node_modules/minimatch": { + "version": "8.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-8.0.4.tgz", + "integrity": "sha512-W0Wvr9HyFXZRGIDgCicunpQ299OKXs9RgZfaukz4qAW/pJhcpUfupc9c+OObPOFueNy8VSrZgEmDtk6Kh4WzDA==", + "dev": true, + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/ripemd160": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/ripemd160/-/ripemd160-2.0.2.tgz", + "integrity": "sha512-ii4iagi25WusVoiC4B4lq7pbXfAp3D9v5CwfkY33vffw2+pkDjY1D8GaN7spsxvCSx8dkPqOZCEZyfxcmJG2IA==", + "dev": true, + "dependencies": { + "hash-base": "^3.0.0", + "inherits": "^2.0.1" + } + }, + "node_modules/run-parallel": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", + "integrity": "sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "dependencies": { + "queue-microtask": "^1.2.2" + } + }, + "node_modules/run-parallel-limit": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/run-parallel-limit/-/run-parallel-limit-1.1.0.tgz", + "integrity": "sha512-jJA7irRNM91jaKc3Hcl1npHsFLOXOoTkPCUL1JEa1R82O2miplXXRaGdjW/KM/98YQWDhJLiSs793CnXfblJUw==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "dependencies": { + "queue-microtask": "^1.2.2" + } + }, + "node_modules/safe-buffer": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" + }, + "node_modules/safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", + "dev": true + }, + "node_modules/schema-utils": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/schema-utils/-/schema-utils-3.3.0.tgz", + "integrity": "sha512-pN/yOAvcC+5rQ5nERGuwrjLlYvLTbCibnZ1I7B1LaiAz9BRBlE9GMgE/eqV30P7aJQUf7Ddimy/RsbYO/GrVGg==", + "dev": true, + "peer": true, + "dependencies": { + "@types/json-schema": "^7.0.8", + "ajv": "^6.12.5", + "ajv-keywords": "^3.5.2" + }, + "engines": { + "node": ">= 10.13.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/webpack" + } + }, + "node_modules/schema-utils/node_modules/ajv": { + "version": "6.12.6", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", + "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", + "dev": true, + "peer": true, + "dependencies": { + "fast-deep-equal": "^3.1.1", + "fast-json-stable-stringify": "^2.0.0", + "json-schema-traverse": "^0.4.1", + "uri-js": "^4.2.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, + "node_modules/schema-utils/node_modules/ajv-keywords": { + "version": "3.5.2", + "resolved": "https://registry.npmjs.org/ajv-keywords/-/ajv-keywords-3.5.2.tgz", + "integrity": "sha512-5p6WTN0DdTGVQk6VjcEju19IgaHudalcfabD7yhDGeA6bcQnmL+CpveLJq/3hvfwd1aof6L386Ougkx6RfyMIQ==", + "dev": true, + "peer": true, + "peerDependencies": { + "ajv": "^6.9.1" + } + }, + "node_modules/schema-utils/node_modules/json-schema-traverse": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", + "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", + "dev": true, + "peer": true + }, + "node_modules/semver": { + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", + "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", + "dev": true, + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/semver/node_modules/lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dev": true, + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/serialize-javascript": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-6.0.0.tgz", + "integrity": "sha512-Qr3TosvguFt8ePWqsvRfrKyQXIiW+nGbYpy8XK24NQHE83caxWt+mIymTT19DGFbNWNLfEwsrkSmN64lVWB9ag==", + "dev": true, + "dependencies": { + "randombytes": "^2.1.0" + } + }, + "node_modules/setimmediate": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz", + "integrity": "sha512-MATJdZp8sLqDl/68LfQmbP8zKPLQNV6BIZoIgrscFDQ+RsvK/BxeDQOgyxKKoh0y/8h3BqVFnCqQ/gd+reiIXA==", + "dev": true + }, + "node_modules/setprototypeof": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", + "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==", + "dev": true + }, + "node_modules/sha.js": { + "version": "2.4.11", + "resolved": "https://registry.npmjs.org/sha.js/-/sha.js-2.4.11.tgz", + "integrity": "sha512-QMEp5B7cftE7APOjk5Y6xgrbWu+WkLVQwk8JNjZ8nKRciZaByEW6MubieAiToS7+dwvrjGhH8jRXz3MVd0AYqQ==", + "dev": true, + "dependencies": { + "inherits": "^2.0.1", + "safe-buffer": "^5.0.1" + }, + "bin": { + "sha.js": "bin.js" + } + }, + "node_modules/shebang-command": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", + "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", + "dev": true, + "dependencies": { + "shebang-regex": "^3.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/shebang-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", + "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/side-channel": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz", + "integrity": "sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==", + "dev": true, + "dependencies": { + "call-bind": "^1.0.0", + "get-intrinsic": "^1.0.2", + "object-inspect": "^1.9.0" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/signal-exit": { + "version": "3.0.7", + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", + "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==", + "dev": true + }, + "node_modules/sinon": { + "version": "15.0.2", + "resolved": "https://registry.npmjs.org/sinon/-/sinon-15.0.2.tgz", + "integrity": "sha512-PCVP63XZkg0/LOqQH5rEU4LILuvTFMb5tNxTHfs6VUMNnZz2XrnGSTZbAGITjzwQWbl/Bl/8hi4G3zZWjyBwHg==", + "dev": true, + "dependencies": { + "@sinonjs/commons": "^3.0.0", + "@sinonjs/fake-timers": "^10.0.2", + "@sinonjs/samsam": "^7.0.1", + "diff": "^5.1.0", + "nise": "^5.1.4", + "supports-color": "^7.2.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/sinon" + } + }, + "node_modules/sinon/node_modules/diff": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/diff/-/diff-5.1.0.tgz", + "integrity": "sha512-D+mk+qE8VC/PAUrlAU34N+VfXev0ghe5ywmpqrawphmVZc1bEfn56uo9qpyGp1p4xpzOHkSW4ztBd6L7Xx4ACw==", + "dev": true, + "engines": { + "node": ">=0.3.1" + } + }, + "node_modules/slash": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", + "integrity": "sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/socket.io": { + "version": "4.7.2", + "resolved": "https://registry.npmjs.org/socket.io/-/socket.io-4.7.2.tgz", + "integrity": "sha512-bvKVS29/I5fl2FGLNHuXlQaUH/BlzX1IN6S+NKLNZpBsPZIDH+90eQmCs2Railn4YUiww4SzUedJ6+uzwFnKLw==", + "dev": true, + "dependencies": { + "accepts": "~1.3.4", + "base64id": "~2.0.0", + "cors": "~2.8.5", + "debug": "~4.3.2", + "engine.io": "~6.5.2", + "socket.io-adapter": "~2.5.2", + "socket.io-parser": "~4.2.4" + }, + "engines": { + "node": ">=10.2.0" + } + }, + "node_modules/socket.io-adapter": { + "version": "2.5.2", + "resolved": "https://registry.npmjs.org/socket.io-adapter/-/socket.io-adapter-2.5.2.tgz", + "integrity": "sha512-87C3LO/NOMc+eMcpcxUBebGjkpMDkNBS9tf7KJqcDsmL936EChtVva71Dw2q4tQcuVC+hAUy4an2NO/sYXmwRA==", + "dev": true, + "dependencies": { + "ws": "~8.11.0" + } + }, + "node_modules/socket.io-parser": { + "version": "4.2.4", + "resolved": "https://registry.npmjs.org/socket.io-parser/-/socket.io-parser-4.2.4.tgz", + "integrity": "sha512-/GbIKmo8ioc+NIWIhwdecY0ge+qVBSMdgxGygevmdHj24bsfgtCmcUUcQ5ZzcylGFHsN3k4HB4Cgkl96KVnuew==", + "dev": true, + "dependencies": { + "@socket.io/component-emitter": "~3.1.0", + "debug": "~4.3.1" + }, + "engines": { + "node": ">=10.0.0" + } + }, + "node_modules/source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/source-map-js": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.0.2.tgz", + "integrity": "sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/source-map-loader": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/source-map-loader/-/source-map-loader-4.0.1.tgz", + "integrity": "sha512-oqXpzDIByKONVY8g1NUPOTQhe0UTU5bWUl32GSkqK2LjJj0HmwTMVKxcUip0RgAYhY1mqgOxjbQM48a0mmeNfA==", + "dev": true, + "dependencies": { + "abab": "^2.0.6", + "iconv-lite": "^0.6.3", + "source-map-js": "^1.0.2" + }, + "engines": { + "node": ">= 14.15.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/webpack" + }, + "peerDependencies": { + "webpack": "^5.72.1" + } + }, + "node_modules/source-map-loader/node_modules/iconv-lite": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", + "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", + "dev": true, + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3.0.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/source-map-support": { + "version": "0.5.21", + "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.21.tgz", + "integrity": "sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==", + "dev": true, + "peer": true, + "dependencies": { + "buffer-from": "^1.0.0", + "source-map": "^0.6.0" + } + }, + "node_modules/sparse-array": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/sparse-array/-/sparse-array-1.3.2.tgz", + "integrity": "sha512-ZT711fePGn3+kQyLuv1fpd3rNSkNF8vd5Kv2D+qnOANeyKs3fx6bUMGWRPvgTTcYV64QMqZKZwcuaQSP3AZ0tg==" + }, + "node_modules/statuses": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz", + "integrity": "sha512-OpZ3zP+jT1PI7I8nemJX4AKmAX070ZkYPVWV/AaKTJl+tXCTGyVdC1a4SL8RUQYEwk/f34ZX8UTykN68FwrqAA==", + "dev": true, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/stream-browserify": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/stream-browserify/-/stream-browserify-3.0.0.tgz", + "integrity": "sha512-H73RAHsVBapbim0tU2JwwOiXUj+fikfiaoYAKHF3VJfA0pe2BCzkhAHBlLG6REzE+2WNZcxOXjK7lkso+9euLA==", + "dev": true, + "dependencies": { + "inherits": "~2.0.4", + "readable-stream": "^3.5.0" + } + }, + "node_modules/stream-browserify/node_modules/readable-stream": { + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", + "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", + "dev": true, + "dependencies": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/stream-http": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/stream-http/-/stream-http-3.2.0.tgz", + "integrity": "sha512-Oq1bLqisTyK3TSCXpPbT4sdeYNdmyZJv1LxpEm2vu1ZhK89kSE5YXwZc3cWk0MagGaKriBh9mCFbVGtO+vY29A==", + "dev": true, + "dependencies": { + "builtin-status-codes": "^3.0.0", + "inherits": "^2.0.4", + "readable-stream": "^3.6.0", + "xtend": "^4.0.2" + } + }, + "node_modules/stream-http/node_modules/readable-stream": { + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", + "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", + "dev": true, + "dependencies": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/streamroller": { + "version": "3.1.5", + "resolved": "https://registry.npmjs.org/streamroller/-/streamroller-3.1.5.tgz", + "integrity": "sha512-KFxaM7XT+irxvdqSP1LGLgNWbYN7ay5owZ3r/8t77p+EtSUAfUgtl7be3xtqtOmGUl9K9YPO2ca8133RlTjvKw==", + "dev": true, + "dependencies": { + "date-format": "^4.0.14", + "debug": "^4.3.4", + "fs-extra": "^8.1.0" + }, + "engines": { + "node": ">=8.0" + } + }, + "node_modules/string_decoder": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", + "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", + "dependencies": { + "safe-buffer": "~5.2.0" + } + }, + "node_modules/string_decoder/node_modules/safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ] + }, + "node_modules/string-width": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "dev": true, + "dependencies": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dev": true, + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/strip-json-comments": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", + "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==", + "dev": true, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dev": true, + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/supports-preserve-symlinks-flag": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz", + "integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==", + "dev": true, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/tapable": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/tapable/-/tapable-2.2.1.tgz", + "integrity": "sha512-GNzQvQTOIP6RyTfE2Qxb8ZVlNmw0n88vp1szwWRimP02mnTsx3Wtn5qRdqY9w2XduFNUgvOwhNnQsjwCp+kqaQ==", + "dev": true, + "peer": true, + "engines": { + "node": ">=6" + } + }, + "node_modules/terser": { + "version": "5.19.2", + "resolved": "https://registry.npmjs.org/terser/-/terser-5.19.2.tgz", + "integrity": "sha512-qC5+dmecKJA4cpYxRa5aVkKehYsQKc+AHeKl0Oe62aYjBL8ZA33tTljktDHJSaxxMnbI5ZYw+o/S2DxxLu8OfA==", + "dev": true, + "peer": true, + "dependencies": { + "@jridgewell/source-map": "^0.3.3", + "acorn": "^8.8.2", + "commander": "^2.20.0", + "source-map-support": "~0.5.20" + }, + "bin": { + "terser": "bin/terser" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/terser-webpack-plugin": { + "version": "5.3.9", + "resolved": "https://registry.npmjs.org/terser-webpack-plugin/-/terser-webpack-plugin-5.3.9.tgz", + "integrity": "sha512-ZuXsqE07EcggTWQjXUj+Aot/OMcD0bMKGgF63f7UxYcu5/AJF53aIpK1YoP5xR9l6s/Hy2b+t1AM0bLNPRuhwA==", + "dev": true, + "peer": true, + "dependencies": { + "@jridgewell/trace-mapping": "^0.3.17", + "jest-worker": "^27.4.5", + "schema-utils": "^3.1.1", + "serialize-javascript": "^6.0.1", + "terser": "^5.16.8" + }, + "engines": { + "node": ">= 10.13.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/webpack" + }, + "peerDependencies": { + "webpack": "^5.1.0" + }, + "peerDependenciesMeta": { + "@swc/core": { + "optional": true + }, + "esbuild": { + "optional": true + }, + "uglify-js": { + "optional": true + } + } + }, + "node_modules/terser-webpack-plugin/node_modules/serialize-javascript": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-6.0.1.tgz", + "integrity": "sha512-owoXEFjWRllis8/M1Q+Cw5k8ZH40e3zhp/ovX+Xr/vi1qj6QesbyXXViFbpNvWvPNAD62SutwEXavefrLJWj7w==", + "dev": true, + "peer": true, + "dependencies": { + "randombytes": "^2.1.0" + } + }, + "node_modules/test-exclude": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/test-exclude/-/test-exclude-6.0.0.tgz", + "integrity": "sha512-cAGWPIyOHU6zlmg88jwm7VRyXnMN7iV68OGAbYDk/Mh/xC/pzVPlQtY6ngoIH/5/tciuhGfvESU8GrHrcxD56w==", + "dev": true, + "dependencies": { + "@istanbuljs/schema": "^0.1.2", + "glob": "^7.1.4", + "minimatch": "^3.0.4" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/text-table": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", + "integrity": "sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==", + "dev": true + }, + "node_modules/timers-browserify": { + "version": "2.0.12", + "resolved": "https://registry.npmjs.org/timers-browserify/-/timers-browserify-2.0.12.tgz", + "integrity": "sha512-9phl76Cqm6FhSX9Xe1ZUAMLtm1BLkKj2Qd5ApyWkXzsMRaA7dgr81kf4wJmQf/hAvg8EEyJxDo3du/0KlhPiKQ==", + "dev": true, + "dependencies": { + "setimmediate": "^1.0.4" + }, + "engines": { + "node": ">=0.6.0" + } + }, + "node_modules/tmp": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.1.tgz", + "integrity": "sha512-76SUhtfqR2Ijn+xllcI5P1oyannHNHByD80W1q447gU3mp9G9PSpGdWmjUOHRDPiHYacIk66W7ubDTuPF3BEtQ==", + "dev": true, + "dependencies": { + "rimraf": "^3.0.0" + }, + "engines": { + "node": ">=8.17.0" + } + }, + "node_modules/tmp/node_modules/rimraf": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", + "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", + "dev": true, + "dependencies": { + "glob": "^7.1.3" + }, + "bin": { + "rimraf": "bin.js" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/to-regex-range": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", + "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", + "dev": true, + "dependencies": { + "is-number": "^7.0.0" + }, + "engines": { + "node": ">=8.0" + } + }, + "node_modules/toidentifier": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", + "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==", + "dev": true, + "engines": { + "node": ">=0.6" + } + }, + "node_modules/tr46": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", + "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" + }, + "node_modules/ts-api-utils": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/ts-api-utils/-/ts-api-utils-1.0.2.tgz", + "integrity": "sha512-Cbu4nIqnEdd+THNEsBdkolnOXhg0I8XteoHaEKgvsxpsbWda4IsUut2c187HxywQCvveojow0Dgw/amxtSKVkQ==", + "dev": true, + "engines": { + "node": ">=16.13.0" + }, + "peerDependencies": { + "typescript": ">=4.2.0" + } + }, + "node_modules/tslib": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz", + "integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==" + }, + "node_modules/tty-browserify": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/tty-browserify/-/tty-browserify-0.0.1.tgz", + "integrity": "sha512-C3TaO7K81YvjCgQH9Q1S3R3P3BtN3RIM8n+OvX4il1K1zgE8ZhI0op7kClgkxtutIE8hQrcrHBXvIheqKUUCxw==", + "dev": true + }, + "node_modules/tweetnacl": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz", + "integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==", + "dev": true + }, + "node_modules/type-check": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", + "integrity": "sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==", + "dev": true, + "dependencies": { + "prelude-ls": "^1.2.1" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/type-detect": { + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", + "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==", + "dev": true, + "engines": { + "node": ">=4" + } + }, + "node_modules/type-fest": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz", + "integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==", + "dev": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/type-is": { + "version": "1.6.18", + "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", + "integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==", + "dev": true, + "dependencies": { + "media-typer": "0.3.0", + "mime-types": "~2.1.24" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/typescript": { + "version": "5.1.6", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.1.6.tgz", + "integrity": "sha512-zaWCozRZ6DLEWAWFrVDz1H6FVXzUSfTy5FUMWsQlU8Ym5JP9eO4xkTIROFCQvhQf61z6O/G6ugw3SgAnvvm+HA==", + "dev": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, + "node_modules/ua-parser-js": { + "version": "0.7.35", + "resolved": "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-0.7.35.tgz", + "integrity": "sha512-veRf7dawaj9xaWEu9HoTVn5Pggtc/qj+kqTOFvNiN1l0YdxwC1kvel57UCjThjGa3BHBihE8/UJAHI+uQHmd/g==", + "dev": true, + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/ua-parser-js" + }, + { + "type": "paypal", + "url": "https://paypal.me/faisalman" + } + ], + "engines": { + "node": "*" + } + }, + "node_modules/uint8arraylist": { + "version": "2.4.3", + "resolved": "https://registry.npmjs.org/uint8arraylist/-/uint8arraylist-2.4.3.tgz", + "integrity": "sha512-oEVZr4/GrH87K0kjNce6z8pSCzLEPqHNLNR5sj8cJOySrTP8Vb/pMIbZKLJGhQKxm1TiZ31atNrpn820Pyqpow==", + "dependencies": { + "uint8arrays": "^4.0.2" + }, + "engines": { + "node": ">=16.0.0", + "npm": ">=7.0.0" + } + }, + "node_modules/uint8arrays": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/uint8arrays/-/uint8arrays-4.0.6.tgz", + "integrity": "sha512-4ZesjQhqOU2Ip6GPReIwN60wRxIupavL8T0Iy36BBHr2qyMrNxsPJvr7vpS4eFt8F8kSguWUPad6ZM9izs/vyw==", + "dependencies": { + "multiformats": "^12.0.1" + } + }, + "node_modules/uint8arrays/node_modules/multiformats": { + "version": "12.0.1", + "resolved": "https://registry.npmjs.org/multiformats/-/multiformats-12.0.1.tgz", + "integrity": "sha512-s01wijBJoDUqESWSzePY0lvTw7J3PVO9x2Cc6ASI5AMZM2Gnhh7BC17+nlFhHKU7dDzaCaRfb+NiqNzOsgPUoQ==", + "engines": { + "node": ">=16.0.0", + "npm": ">=7.0.0" + } + }, + "node_modules/ulid": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/ulid/-/ulid-2.3.0.tgz", + "integrity": "sha512-keqHubrlpvT6G2wH0OEfSW4mquYRcbe/J8NMmveoQOjUqmo+hXtO+ORCpWhdbZ7k72UtY61BL7haGxW6enBnjw==", + "bin": { + "ulid": "bin/cli.js" + } + }, + "node_modules/universalify": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", + "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==", + "dev": true, + "engines": { + "node": ">= 4.0.0" + } + }, + "node_modules/unpipe": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", + "integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==", + "dev": true, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/update-browserslist-db": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.0.11.tgz", + "integrity": "sha512-dCwEFf0/oT85M1fHBg4F0jtLwJrutGoHSQXCh7u4o2t1drG+c0a9Flnqww6XUKSfQMPpJBRjU8d4RXB09qtvaA==", + "dev": true, + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/browserslist" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/browserslist" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "peer": true, + "dependencies": { + "escalade": "^3.1.1", + "picocolors": "^1.0.0" + }, + "bin": { + "update-browserslist-db": "cli.js" + }, + "peerDependencies": { + "browserslist": ">= 4.21.0" + } + }, + "node_modules/uri-js": { + "version": "4.4.1", + "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", + "integrity": "sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==", + "dependencies": { + "punycode": "^2.1.0" + } + }, + "node_modules/uri-js/node_modules/punycode": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.0.tgz", + "integrity": "sha512-rRV+zQD8tVFys26lAGR9WUuS4iUAngJScM+ZRSKtvl5tKeZ2t5bvdNFdNHBW9FWR4guGHlgmsZ1G7BSm2wTbuA==", + "engines": { + "node": ">=6" + } + }, + "node_modules/url": { + "version": "0.11.1", + "resolved": "https://registry.npmjs.org/url/-/url-0.11.1.tgz", + "integrity": "sha512-rWS3H04/+mzzJkv0eZ7vEDGiQbgquI1fGfOad6zKvgYQi1SzMmhl7c/DdRGxhaWrVH6z0qWITo8rpnxK/RfEhA==", + "dev": true, + "dependencies": { + "punycode": "^1.4.1", + "qs": "^6.11.0" + } + }, + "node_modules/util": { + "version": "0.12.5", + "resolved": "https://registry.npmjs.org/util/-/util-0.12.5.tgz", + "integrity": "sha512-kZf/K6hEIrWHI6XqOFUiiMa+79wE/D8Q+NCNAWclkyg3b4d2k7s0QGepNjiABc+aR3N1PAyHL7p6UcLY6LmrnA==", + "dev": true, + "dependencies": { + "inherits": "^2.0.3", + "is-arguments": "^1.0.4", + "is-generator-function": "^1.0.7", + "is-typed-array": "^1.1.3", + "which-typed-array": "^1.1.2" + } + }, + "node_modules/util-deprecate": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", + "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==" + }, + "node_modules/utils-merge": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", + "integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==", + "dev": true, + "engines": { + "node": ">= 0.4.0" + } + }, + "node_modules/uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", + "bin": { + "uuid": "dist/bin/uuid" + } + }, + "node_modules/v8-to-istanbul": { + "version": "9.1.0", + "resolved": "https://registry.npmjs.org/v8-to-istanbul/-/v8-to-istanbul-9.1.0.tgz", + "integrity": "sha512-6z3GW9x8G1gd+JIIgQQQxXuiJtCXeAjp6RaPEPLv62mH3iPHPxV6W3robxtCzNErRo6ZwTmzWhsbNvjyEBKzKA==", + "dev": true, + "dependencies": { + "@jridgewell/trace-mapping": "^0.3.12", + "@types/istanbul-lib-coverage": "^2.0.1", + "convert-source-map": "^1.6.0" + }, + "engines": { + "node": ">=10.12.0" + } + }, + "node_modules/varint": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/varint/-/varint-6.0.0.tgz", + "integrity": "sha512-cXEIW6cfr15lFv563k4GuVuW/fiwjknytD37jIOLSdSWuOI6WnO/oKwmP2FQTU2l01LP8/M5TSAJpzUaGe3uWg==" + }, + "node_modules/vary": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", + "integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==", + "dev": true, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/vm-browserify": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/vm-browserify/-/vm-browserify-1.1.2.tgz", + "integrity": "sha512-2ham8XPWTONajOR0ohOKOHXkm3+gaBmGut3SRuu75xLd/RRaY6vqgh8NBYYk7+RW3u5AtzPQZG8F10LHkl0lAQ==", + "dev": true + }, + "node_modules/void-elements": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/void-elements/-/void-elements-2.0.1.tgz", + "integrity": "sha512-qZKX4RnBzH2ugr8Lxa7x+0V6XD9Sb/ouARtiasEQCHB1EVU4NXtmHsDDrx1dO4ne5fc3J6EW05BP1Dl0z0iung==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/watchpack": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/watchpack/-/watchpack-2.4.0.tgz", + "integrity": "sha512-Lcvm7MGST/4fup+ifyKi2hjyIAwcdI4HRgtvTpIUxBRhB+RFtUh8XtDOxUfctVCnhVi+QQj49i91OyvzkJl6cg==", + "dev": true, + "peer": true, + "dependencies": { + "glob-to-regexp": "^0.4.1", + "graceful-fs": "^4.1.2" + }, + "engines": { + "node": ">=10.13.0" + } + }, + "node_modules/webidl-conversions": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", + "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==" + }, + "node_modules/webpack": { + "version": "5.88.2", + "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.88.2.tgz", + "integrity": "sha512-JmcgNZ1iKj+aiR0OvTYtWQqJwq37Pf683dY9bVORwVbUrDhLhdn/PlO2sHsFHPkj7sHNQF3JwaAkp49V+Sq1tQ==", + "dev": true, + "peer": true, + "dependencies": { + "@types/eslint-scope": "^3.7.3", + "@types/estree": "^1.0.0", + "@webassemblyjs/ast": "^1.11.5", + "@webassemblyjs/wasm-edit": "^1.11.5", + "@webassemblyjs/wasm-parser": "^1.11.5", + "acorn": "^8.7.1", + "acorn-import-assertions": "^1.9.0", + "browserslist": "^4.14.5", + "chrome-trace-event": "^1.0.2", + "enhanced-resolve": "^5.15.0", + "es-module-lexer": "^1.2.1", + "eslint-scope": "5.1.1", + "events": "^3.2.0", + "glob-to-regexp": "^0.4.1", + "graceful-fs": "^4.2.9", + "json-parse-even-better-errors": "^2.3.1", + "loader-runner": "^4.2.0", + "mime-types": "^2.1.27", + "neo-async": "^2.6.2", + "schema-utils": "^3.2.0", + "tapable": "^2.1.1", + "terser-webpack-plugin": "^5.3.7", + "watchpack": "^2.4.0", + "webpack-sources": "^3.2.3" + }, + "bin": { + "webpack": "bin/webpack.js" + }, + "engines": { + "node": ">=10.13.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/webpack" + }, + "peerDependenciesMeta": { + "webpack-cli": { + "optional": true + } + } + }, + "node_modules/webpack-sources": { + "version": "3.2.3", + "resolved": "https://registry.npmjs.org/webpack-sources/-/webpack-sources-3.2.3.tgz", + "integrity": "sha512-/DyMEOrDgLKKIG0fmvtz+4dUX/3Ghozwgm6iPp8KRhvn+eQf9+Q7GWxVNMk3+uCPWfdXYC4ExGBckIXdFEfH1w==", + "dev": true, + "peer": true, + "engines": { + "node": ">=10.13.0" + } + }, + "node_modules/webpack/node_modules/eslint-scope": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz", + "integrity": "sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw==", + "dev": true, + "peer": true, + "dependencies": { + "esrecurse": "^4.3.0", + "estraverse": "^4.1.1" + }, + "engines": { + "node": ">=8.0.0" + } + }, + "node_modules/webpack/node_modules/estraverse": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.3.0.tgz", + "integrity": "sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw==", + "dev": true, + "peer": true, + "engines": { + "node": ">=4.0" + } + }, + "node_modules/whatwg-url": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", + "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", + "dependencies": { + "tr46": "~0.0.3", + "webidl-conversions": "^3.0.0" + } + }, + "node_modules/which": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "dev": true, + "dependencies": { + "isexe": "^2.0.0" + }, + "bin": { + "node-which": "bin/node-which" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/which-typed-array": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/which-typed-array/-/which-typed-array-1.1.11.tgz", + "integrity": "sha512-qe9UWWpkeG5yzZ0tNYxDmd7vo58HDBc39mZ0xWWpolAGADdFOzkfamWLDxkOWcvHQKVmdTyQdLD4NOfjLWTKew==", + "dev": true, + "dependencies": { + "available-typed-arrays": "^1.0.5", + "call-bind": "^1.0.2", + "for-each": "^0.3.3", + "gopd": "^1.0.1", + "has-tostringtag": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/workerpool": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/workerpool/-/workerpool-6.2.1.tgz", + "integrity": "sha512-ILEIE97kDZvF9Wb9f6h5aXK4swSlKGUcOEGiIYb2OOu/IrDU9iwj0fD//SsA6E5ibwJxpEvhullJY4Sl4GcpAw==", + "dev": true + }, + "node_modules/wrap-ansi": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", + "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" + } + }, + "node_modules/wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", + "dev": true + }, + "node_modules/ws": { + "version": "8.11.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.11.0.tgz", + "integrity": "sha512-HPG3wQd9sNQoT9xHyNCXoDUa+Xw/VevmY9FoHyQ+g+rrMn4j6FB4np7Z0OhdTgjx6MgQLK7jwSy1YecU1+4Asg==", + "dev": true, + "engines": { + "node": ">=10.0.0" + }, + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": "^5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true } + } + }, + "node_modules/xtend": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", + "integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==", + "dev": true, + "engines": { + "node": ">=0.4" + } + }, + "node_modules/y18n": { + "version": "5.0.8", + "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", + "integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==", + "dev": true, + "engines": { + "node": ">=10" + } + }, + "node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", + "dev": true + }, + "node_modules/yargs": { + "version": "17.7.2", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz", + "integrity": "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==", + "dev": true, + "dependencies": { + "cliui": "^8.0.1", + "escalade": "^3.1.1", + "get-caller-file": "^2.0.5", + "require-directory": "^2.1.1", + "string-width": "^4.2.3", + "y18n": "^5.0.5", + "yargs-parser": "^21.1.1" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/yargs-parser": { + "version": "21.1.1", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.1.1.tgz", + "integrity": "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==", + "dev": true, + "engines": { + "node": ">=12" + } + }, + "node_modules/yargs-unparser": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/yargs-unparser/-/yargs-unparser-2.0.0.tgz", + "integrity": "sha512-7pRTIA9Qc1caZ0bZ6RYRGbHJthJWuakf+WmHK0rVeLkNrrGhfoabBNdue6kdINI6r4if7ocq9aD/n7xwKOdzOA==", + "dev": true, + "dependencies": { + "camelcase": "^6.0.0", + "decamelize": "^4.0.0", + "flat": "^5.0.2", + "is-plain-obj": "^2.1.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/yocto-queue": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", + "integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==", + "dev": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "packages/agent": { + "name": "@web5/agent", + "version": "0.2.0", + "license": "Apache-2.0", + "dependencies": { + "@tbd54566975/dwn-sdk-js": "0.2.1", + "@web5/common": "0.2.0", + "@web5/crypto": "0.2.0", + "@web5/dids": "0.2.0", + "level": "8.0.0", + "readable-stream": "4.4.2", + "readable-web-to-node-stream": "3.0.2" + }, + "devDependencies": { + "@playwright/test": "1.36.2", + "@types/chai": "4.3.5", + "@types/chai-as-promised": "7.1.5", + "@types/eslint": "8.44.2", + "@types/mocha": "10.0.1", + "@types/readable-stream": "4.0.0", + "@typescript-eslint/eslint-plugin": "6.4.0", + "@typescript-eslint/parser": "6.4.0", + "c8": "8.0.1", + "chai": "4.3.7", + "chai-as-promised": "7.1.1", + "esbuild": "0.16.17", + "eslint": "8.47.0", + "eslint-plugin-mocha": "10.1.0", + "karma": "6.4.1", + "karma-chai": "0.1.0", + "karma-chrome-launcher": "3.1.1", + "karma-esbuild": "2.2.5", + "karma-firefox-launcher": "2.1.2", + "karma-mocha": "2.0.1", + "karma-mocha-reporter": "2.2.5", + "karma-webkit-launcher": "2.1.0", + "mocha": "10.2.0", + "node-stdlib-browser": "1.2.0", + "playwright": "1.36.2", + "rimraf": "4.4.0", + "typescript": "5.1.6" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "packages/api": { + "name": "@web5/api", + "version": "0.8.1", + "license": "Apache-2.0", + "dependencies": { + "@tbd54566975/dwn-sdk-js": "0.2.1", + "@web5/agent": "0.2.0", + "@web5/crypto": "0.2.0", + "@web5/dids": "0.2.0", + "@web5/user-agent": "0.2.0", + "level": "8.0.0", + "ms": "2.1.3", + "readable-stream": "4.4.2", + "readable-web-to-node-stream": "3.0.2" + }, + "devDependencies": { + "@playwright/test": "1.36.2", + "@types/chai": "4.3.5", + "@types/chai-as-promised": "7.1.5", + "@types/eslint": "8.44.2", + "@types/mocha": "10.0.1", + "@types/ms": "0.7.31", + "@types/readable-stream": "4.0.0", + "@types/sinon": "10.0.15", + "@typescript-eslint/eslint-plugin": "6.4.0", + "@typescript-eslint/parser": "6.4.0", + "c8": "8.0.1", + "chai": "4.3.7", + "chai-as-promised": "7.1.1", + "esbuild": "0.16.17", + "eslint": "8.47.0", + "eslint-plugin-mocha": "10.1.0", + "karma": "6.4.1", + "karma-chai": "0.1.0", + "karma-chrome-launcher": "3.1.1", + "karma-esbuild": "2.2.5", + "karma-firefox-launcher": "2.1.2", + "karma-mocha": "2.0.1", + "karma-mocha-reporter": "2.2.5", + "karma-webkit-launcher": "2.1.0", + "mocha": "10.2.0", + "node-stdlib-browser": "1.2.0", + "playwright": "1.36.2", + "rimraf": "4.4.0", + "sinon": "15.0.2", + "source-map-loader": "4.0.1", + "typescript": "5.1.6" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "packages/bonanza": { + "dependencies": { + "@noble/curves": "1.1.0", + "@web5/api": "0.8.1" + } + }, + "packages/common": { + "name": "@web5/common", + "version": "0.2.0", + "license": "Apache-2.0", + "dependencies": { + "level": "8.0.0", + "multiformats": "11.0.2" + }, + "devDependencies": { + "@playwright/test": "1.36.2", + "@types/chai": "4.3.5", + "@types/chai-as-promised": "7.1.5", + "@types/eslint": "8.44.2", + "@types/mocha": "10.0.1", + "@typescript-eslint/eslint-plugin": "6.4.0", + "@typescript-eslint/parser": "6.4.0", + "c8": "8.0.1", + "chai": "4.3.7", + "chai-as-promised": "7.1.1", + "esbuild": "0.16.17", + "eslint": "8.47.0", + "eslint-plugin-mocha": "10.1.0", + "karma": "6.4.1", + "karma-chai": "0.1.0", + "karma-chrome-launcher": "3.1.1", + "karma-esbuild": "2.2.5", + "karma-firefox-launcher": "2.1.2", + "karma-mocha": "2.0.1", + "karma-mocha-reporter": "2.2.5", + "karma-webkit-launcher": "2.1.0", + "mocha": "10.2.0", + "playwright": "1.36.2", + "rimraf": "4.4.0", + "typescript": "5.1.6" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "packages/credentials": { + "name": "@web5/credentials", + "version": "0.2.0", + "license": "Apache-2.0", + "devDependencies": { + "@playwright/test": "1.36.2", + "@types/chai": "4.3.5", + "@types/eslint": "8.44.2", + "@types/mocha": "10.0.1", + "@typescript-eslint/eslint-plugin": "6.4.0", + "@typescript-eslint/parser": "6.4.0", + "c8": "8.0.1", + "chai": "4.3.7", + "esbuild": "0.16.17", + "eslint": "8.47.0", + "eslint-plugin-mocha": "10.1.0", + "karma": "6.4.1", + "karma-chai": "0.1.0", + "karma-chrome-launcher": "3.1.1", + "karma-esbuild": "2.2.5", + "karma-firefox-launcher": "2.1.2", + "karma-mocha": "2.0.1", + "karma-mocha-reporter": "2.2.5", + "karma-webkit-launcher": "2.1.0", + "mocha": "10.2.0", + "playwright": "1.36.2", + "rimraf": "4.4.0", + "typescript": "5.1.6" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "packages/crypto": { + "name": "@web5/crypto", + "version": "0.2.0", + "license": "Apache-2.0", + "dependencies": { + "@noble/ciphers": "0.1.4", + "@noble/curves": "1.1.0", + "@noble/hashes": "1.3.1", + "@web5/common": "0.2.0" + }, + "devDependencies": { + "@playwright/test": "1.36.2", + "@types/chai": "4.3.5", + "@types/chai-as-promised": "7.1.5", + "@types/ed2curve": "0.2.2", + "@types/eslint": "8.44.2", + "@types/mocha": "10.0.1", + "@types/sinon": "10.0.15", + "@types/uuid": "9.0.1", + "@typescript-eslint/eslint-plugin": "6.4.0", + "@typescript-eslint/parser": "6.4.0", + "c8": "8.0.1", + "chai": "4.3.7", + "chai-as-promised": "7.1.1", + "esbuild": "0.16.17", + "eslint": "8.47.0", + "eslint-plugin-mocha": "10.1.0", + "karma": "6.4.1", + "karma-chai": "0.1.0", + "karma-chrome-launcher": "3.1.1", + "karma-esbuild": "2.2.5", + "karma-firefox-launcher": "2.1.2", + "karma-mocha": "2.0.1", + "karma-mocha-reporter": "2.2.5", + "karma-webkit-launcher": "2.1.0", + "mocha": "10.2.0", + "playwright": "1.36.2", + "rimraf": "4.4.0", + "sinon": "15.0.2", + "source-map-loader": "4.0.1", + "typescript": "5.1.6" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "packages/dids": { + "name": "@web5/dids", + "version": "0.2.0", + "license": "Apache-2.0", + "dependencies": { + "@decentralized-identity/ion-pow-sdk": "1.0.17", + "@decentralized-identity/ion-sdk": "1.0.1", + "@web5/common": "0.2.0", + "@web5/crypto": "0.2.0", + "canonicalize": "2.0.0", + "did-resolver": "4.1.0", + "level": "8.0.0" + }, + "devDependencies": { + "@playwright/test": "1.36.2", + "@types/chai": "4.3.5", + "@types/chai-as-promised": "7.1.5", + "@types/eslint": "8.44.2", + "@types/mocha": "10.0.1", + "@types/sinon": "10.0.15", + "@typescript-eslint/eslint-plugin": "6.4.0", + "@typescript-eslint/parser": "6.4.0", + "c8": "8.0.1", + "chai": "4.3.7", + "chai-as-promised": "7.1.1", + "esbuild": "0.16.17", + "eslint": "8.47.0", + "eslint-plugin-mocha": "10.1.0", + "karma": "6.4.1", + "karma-chai": "0.1.0", + "karma-chrome-launcher": "3.1.1", + "karma-esbuild": "2.2.5", + "karma-firefox-launcher": "2.1.2", + "karma-mocha": "2.0.1", + "karma-mocha-reporter": "2.2.5", + "karma-webkit-launcher": "2.1.0", + "mocha": "10.2.0", + "playwright": "1.36.2", + "rimraf": "4.4.0", + "sinon": "15.0.2", + "source-map-loader": "4.0.1", + "typescript": "5.1.6" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "packages/identity-agent": { + "name": "@web5/identity-agent", + "version": "0.2.0", + "license": "Apache-2.0", + "dependencies": { + "@web5/agent": "0.2.0", + "@web5/api": "0.8.1" + }, + "devDependencies": { + "@playwright/test": "1.36.2", + "@types/chai": "4.3.5", + "@types/chai-as-promised": "7.1.5", + "@types/eslint": "8.44.2", + "@types/mocha": "10.0.1", + "@typescript-eslint/eslint-plugin": "6.4.0", + "@typescript-eslint/parser": "6.4.0", + "c8": "8.0.1", + "chai": "4.3.7", + "chai-as-promised": "7.1.1", + "esbuild": "0.16.17", + "eslint": "8.47.0", + "eslint-plugin-mocha": "10.1.0", + "karma": "6.4.1", + "karma-chai": "0.1.0", + "karma-chrome-launcher": "3.1.1", + "karma-esbuild": "2.2.5", + "karma-firefox-launcher": "2.1.2", + "karma-mocha": "2.0.1", + "karma-mocha-reporter": "2.2.5", + "karma-webkit-launcher": "2.1.0", + "mocha": "10.2.0", + "node-stdlib-browser": "1.2.0", + "playwright": "1.36.2", + "rimraf": "4.4.0", + "typescript": "5.1.6" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "packages/proxy-agent": { + "name": "@web5/proxy-agent", + "version": "0.2.0", + "license": "Apache-2.0", + "dependencies": { + "@web5/agent": "0.2.0", + "@web5/common": "0.2.0", + "@web5/crypto": "0.2.0", + "@web5/dids": "0.2.0" + }, + "devDependencies": { + "@playwright/test": "1.36.2", + "@types/chai": "4.3.5", + "@types/chai-as-promised": "7.1.5", + "@types/eslint": "8.44.2", + "@types/mocha": "10.0.1", + "@typescript-eslint/eslint-plugin": "6.4.0", + "@typescript-eslint/parser": "6.4.0", + "c8": "8.0.1", + "chai": "4.3.7", + "chai-as-promised": "7.1.1", + "esbuild": "0.16.17", + "eslint": "8.47.0", + "eslint-plugin-mocha": "10.1.0", + "karma": "6.4.1", + "karma-chai": "0.1.0", + "karma-chrome-launcher": "3.1.1", + "karma-esbuild": "2.2.5", + "karma-firefox-launcher": "2.1.2", + "karma-mocha": "2.0.1", + "karma-mocha-reporter": "2.2.5", + "karma-webkit-launcher": "2.1.0", + "mocha": "10.2.0", + "node-stdlib-browser": "1.2.0", + "playwright": "1.36.2", + "rimraf": "4.4.0", + "typescript": "5.1.6" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "packages/user-agent": { + "name": "@web5/user-agent", + "version": "0.2.0", + "license": "Apache-2.0", + "dependencies": { + "@web5/agent": "0.2.0", + "@web5/common": "0.2.0", + "@web5/crypto": "0.2.0", + "@web5/dids": "0.2.0" + }, + "devDependencies": { + "@playwright/test": "1.36.2", + "@types/chai": "4.3.5", + "@types/chai-as-promised": "7.1.5", + "@types/eslint": "8.44.2", + "@types/mocha": "10.0.1", + "@typescript-eslint/eslint-plugin": "6.4.0", + "@typescript-eslint/parser": "6.4.0", + "c8": "8.0.1", + "chai": "4.3.7", + "chai-as-promised": "7.1.1", + "esbuild": "0.16.17", + "eslint": "8.47.0", + "eslint-plugin-mocha": "10.1.0", + "karma": "6.4.1", + "karma-chai": "0.1.0", + "karma-chrome-launcher": "3.1.1", + "karma-esbuild": "2.2.5", + "karma-firefox-launcher": "2.1.2", + "karma-mocha": "2.0.1", + "karma-mocha-reporter": "2.2.5", + "karma-webkit-launcher": "2.1.0", + "mocha": "10.2.0", + "node-stdlib-browser": "1.2.0", + "playwright": "1.36.2", + "rimraf": "4.4.0", + "typescript": "5.1.6" + }, + "engines": { + "node": ">=18.0.0" + } } + } } diff --git a/package.json b/package.json index f48b7308a..77bd76cb0 100644 --- a/package.json +++ b/package.json @@ -1,24 +1,18 @@ { - "workspaces": [ - "packages/common", - "packages/crypto", - "packages/web5-agent", - "packages/dids", - "packages/credentials", - "packages/web5-user-agent", - "packages/web5-proxy-agent", - "packages/web5" - ], - "scripts": { - "clean": "npx npkill -d $(pwd) -t node_modules && npx npkill -d $(pwd) -t dist", - "build": "npm run build --ws" - }, - "private": true, - "overrides": { - "c8": { - "istanbul-lib-report": { - "make-dir": "^4.0.0" - } - } - } -} \ No newline at end of file + "workspaces": [ + "packages/common", + "packages/crypto", + "packages/dids", + "packages/credentials", + "packages/agent", + "packages/user-agent", + "packages/proxy-agent", + "packages/api", + "packages/identity-agent" + ], + "scripts": { + "clean": "npx npkill -d $(pwd) -t node_modules && npx npkill -d $(pwd)/packages -t dist", + "build": "npm run build --ws" + }, + "private": true +} diff --git a/packages/web5-agent/.c8rc.json b/packages/agent/.c8rc.json similarity index 66% rename from packages/web5-agent/.c8rc.json rename to packages/agent/.c8rc.json index 1d1670b70..ab680f663 100644 --- a/packages/web5-agent/.c8rc.json +++ b/packages/agent/.c8rc.json @@ -5,12 +5,12 @@ ".js" ], "include": [ - "tests/compiled/**" + "tests/compiled/src/**" ], "exclude": [ - "tests/compiled/src/main.js", + "tests/compiled/src/index.js", "tests/compiled/src/types.js", - "tests/compiled/types/**" + "tests/compiled/src/types/**" ], "reporter": [ "cobertura", diff --git a/packages/web5-agent/.mocharc.json b/packages/agent/.mocharc.json similarity index 100% rename from packages/web5-agent/.mocharc.json rename to packages/agent/.mocharc.json diff --git a/packages/web5-agent/.vscode/launch.json b/packages/agent/.vscode/launch.json similarity index 100% rename from packages/web5-agent/.vscode/launch.json rename to packages/agent/.vscode/launch.json diff --git a/packages/web5-agent/.vscode/tasks.json b/packages/agent/.vscode/tasks.json similarity index 93% rename from packages/web5-agent/.vscode/tasks.json rename to packages/agent/.vscode/tasks.json index d40b145f8..fb5508769 100644 --- a/packages/web5-agent/.vscode/tasks.json +++ b/packages/agent/.vscode/tasks.json @@ -31,7 +31,7 @@ "type": "npm", "script": "build:tests:node", "options": { - "cwd": "${workspaceFolder:web5-agent}" + "cwd": "${workspaceFolder:agent}" } } ] diff --git a/packages/web5-user-agent/build/bundles.js b/packages/agent/build/bundles.js similarity index 92% rename from packages/web5-user-agent/build/bundles.js rename to packages/agent/build/bundles.js index c9119e67b..c29d47c0c 100644 --- a/packages/web5-user-agent/build/bundles.js +++ b/packages/agent/build/bundles.js @@ -11,6 +11,6 @@ esbuild.build({ esbuild.build({ ...browserConfig, format : 'iife', - globalName : 'Web5', + globalName : 'Web5Agent', outfile : 'dist/browser.js', }); \ No newline at end of file diff --git a/packages/web5-user-agent/build/esbuild-browser-config.cjs b/packages/agent/build/esbuild-browser-config.cjs similarity index 96% rename from packages/web5-user-agent/build/esbuild-browser-config.cjs rename to packages/agent/build/esbuild-browser-config.cjs index a3ddbd9f8..bd8bd99b1 100644 --- a/packages/web5-user-agent/build/esbuild-browser-config.cjs +++ b/packages/agent/build/esbuild-browser-config.cjs @@ -15,7 +15,7 @@ for (let lib in stdLibBrowser) { /** @type {import('esbuild').BuildOptions} */ module.exports = { - entryPoints : ['./src/main.ts'], + entryPoints : ['./src/index.ts'], bundle : true, format : 'esm', sourcemap : true, @@ -27,4 +27,4 @@ module.exports = { define : { 'global': 'globalThis', }, -}; +}; \ No newline at end of file diff --git a/packages/agent/karma.conf.cjs b/packages/agent/karma.conf.cjs new file mode 100644 index 000000000..6b7407b2c --- /dev/null +++ b/packages/agent/karma.conf.cjs @@ -0,0 +1,87 @@ +/* eslint-disable @typescript-eslint/no-var-requires */ +// Karma is what we're using to run our tests in browser environments +// Karma does not support .mjs + +// playwright acts as a safari executable on windows and mac +const playwright = require('@playwright/test'); +const esbuildBrowserConfig = require('./build/esbuild-browser-config.cjs'); + +// use playwright chrome exec path as run target for chromium tests +process.env.CHROME_BIN = playwright.chromium.executablePath(); + +// use playwright webkit exec path as run target for safari tests +process.env.WEBKIT_HEADLESS_BIN = playwright.webkit.executablePath(); + +// use playwright firefox exec path as run target for firefox tests +process.env.FIREFOX_BIN = playwright.firefox.executablePath(); + +module.exports = function (config) { + config.set({ + plugins: [ + 'karma-chrome-launcher', + 'karma-firefox-launcher', + 'karma-webkit-launcher', + 'karma-esbuild', + 'karma-mocha', + 'karma-mocha-reporter', + ], + + // frameworks to use + // available frameworks: https://www.npmjs.com/search?q=keywords:karma-adapter + frameworks: ['mocha'], + + client: { + // Increase Mocha's default timeout of 2 seconds to prevent timeouts during GitHub CI runs. + mocha: { + timeout: 10000 // 10 seconds + }, + // If an environment variable is defined, override the default test DWN URL. + testDwnUrl: process.env.TEST_DWN_URL, + }, + + // list of files / patterns to load in the browser + files: [ + { pattern: 'tests/**/*.spec.ts', watched: false }, + ], + + // preprocess matching files before serving them to the browser + // available preprocessors: https://www.npmjs.com/search?q=keywords:karma-preprocessor + preprocessors: { + 'tests/**/*.spec.ts': ['esbuild'], + }, + + esbuild: esbuildBrowserConfig, + + // list of files / patterns to exclude + exclude: [], + + // test results reporter to use + // available reporters: https://www.npmjs.com/search?q=keywords:karma-reporter + reporters: ['mocha'], + + // web server port + port: 9876, + + // enable / disable colors in the output (reporters and logs) + colors: true, + + // level of logging + // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || + // config.LOG_INFO || config.LOG_DEBUG + logLevel: config.LOG_INFO, + + concurrency: 1, + + // start these browsers + // available browser launchers: https://www.npmjs.com/search?q=keywords:karma-launcher + browsers: ['ChromeHeadless', 'FirefoxHeadless', 'WebkitHeadless'], + + // Continuous Integration mode + // if true, Karma captures browsers, runs the tests and exits + singleRun: true, + + // Increase browser timeouts to avoid DISCONNECTED messages during GitHub CI runs. + browserDisconnectTimeout : 10000, // default 2000 + browserDisconnectTolerance : 1, // default 0 + }); +}; diff --git a/packages/web5-user-agent/package.json b/packages/agent/package.json similarity index 67% rename from packages/web5-user-agent/package.json rename to packages/agent/package.json index f29474774..0d6bf8ff1 100644 --- a/packages/web5-user-agent/package.json +++ b/packages/agent/package.json @@ -1,13 +1,12 @@ { - "name": "@tbd54566975/web5-user-agent", - "version": "0.8.0", - "description": "Web5 User Agent", + "name": "@web5/agent", + "version": "0.2.0", "type": "module", - "main": "./dist/cjs/main.js", - "module": "./dist/esm/main.js", - "types": "./dist/types/main.d.ts", + "main": "./dist/cjs/index.js", + "module": "./dist/esm/index.js", + "types": "./dist/types/index.d.ts", "scripts": { - "clean": "rimraf dist tests/compiled", + "clean": "rimraf dist coverage tests/compiled", "build:esm": "rimraf dist/esm dist/types && npx tsc -p tsconfig.json", "build:cjs": "rimraf dist/cjs && tsc -p tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > ./dist/cjs/package.json", "build:browser": "rimraf dist/browser.mjs dist/browser.js && node build/bundles.js", @@ -18,12 +17,12 @@ "test:node": "npm run build:tests:node && c8 mocha", "test:browser": "karma start karma.conf.cjs" }, - "homepage": "https://github.com/TBD54566975/web5-js/tree/main/packages/web5-user-agent#readme", + "homepage": "https://github.com/TBD54566975/web5-js/tree/main/packages/agent#readme", "bugs": "https://github.com/TBD54566975/web5-js/issues", "repository": { "type": "git", "url": "git+https://github.com/TBD54566975/web5-js", - "directory": "packages/web5-user-agent" + "directory": "packages/agent" }, "license": "Apache-2.0", "contributors": [ @@ -46,17 +45,19 @@ ], "exports": { ".": { - "import": "./dist/esm/main.js", - "require": "./dist/cjs/main.js", - "types": "./dist/types/main.d.ts" + "types": "./dist/types/index.d.ts", + "import": "./dist/esm/index.js", + "require": "./dist/cjs/index.js" } }, - "react-native": "./dist/esm/main.js", + "react-native": "./dist/esm/index.js", "keywords": [ "decentralized", "decentralized-applications", "decentralized-identity", "decentralized-web", + "vcs", + "verifiable credentials", "web5" ], "publishConfig": { @@ -66,32 +67,28 @@ "node": ">=18.0.0" }, "dependencies": { - "@decentralized-identity/ion-tools": "1.1.4", - "@tbd54566975/dids": "0.8.0", "@tbd54566975/dwn-sdk-js": "0.2.1", - "@tbd54566975/web5-agent": "0.8.0", - "abstract-level": "1.0.3", - "cross-fetch": "4.0.0", - "flat": "5.0.2", + "@web5/common": "0.2.0", + "@web5/crypto": "0.2.0", + "@web5/dids": "0.2.0", "level": "8.0.0", - "readable-web-to-node-stream": "3.0.2", - "uuid": "9.0.0" + "readable-stream": "4.4.2", + "readable-web-to-node-stream": "3.0.2" }, "devDependencies": { - "@faker-js/faker": "8.0.1", - "@types/chai": "4.3.0", + "@playwright/test": "1.36.2", + "@types/chai": "4.3.5", "@types/chai-as-promised": "7.1.5", - "@types/flat": "5.0.2", + "@types/eslint": "8.44.2", "@types/mocha": "10.0.1", - "@types/readable-stream": "2.3.15", - "@types/sinon": "10.0.15", - "@typescript-eslint/eslint-plugin": "5.59.0", - "@typescript-eslint/parser": "5.59.0", - "c8": "8.0.0", + "@types/readable-stream": "4.0.0", + "@typescript-eslint/eslint-plugin": "6.4.0", + "@typescript-eslint/parser": "6.4.0", + "c8": "8.0.1", "chai": "4.3.7", "chai-as-promised": "7.1.1", "esbuild": "0.16.17", - "eslint": "8.39.0", + "eslint": "8.47.0", "eslint-plugin-mocha": "10.1.0", "karma": "6.4.1", "karma-chai": "0.1.0", @@ -105,8 +102,6 @@ "node-stdlib-browser": "1.2.0", "playwright": "1.36.2", "rimraf": "4.4.0", - "sinon": "15.0.2", - "source-map-loader": "4.0.1", "typescript": "5.1.6" } -} \ No newline at end of file +} diff --git a/packages/agent/src/app-data-store.ts b/packages/agent/src/app-data-store.ts new file mode 100644 index 000000000..dca19c401 --- /dev/null +++ b/packages/agent/src/app-data-store.ts @@ -0,0 +1,368 @@ +import type { DidKeySet } from '@web5/dids'; +import type { KeyValueStore } from '@web5/common'; +import type { JweHeaderParams, PublicKeyJwk, Web5Crypto } from '@web5/crypto'; + +import { DidKeyMethod } from '@web5/dids'; +import { hkdf } from '@noble/hashes/hkdf'; +import { sha256 } from '@noble/hashes/sha256'; +import { sha512 } from '@noble/hashes/sha512'; +import { randomBytes } from '@web5/crypto/utils'; +import { pbkdf2Async } from '@noble/hashes/pbkdf2'; +import { Convert, MemoryStore } from '@web5/common'; +import { CryptoKey, Jose, XChaCha20Poly1305 } from '@web5/crypto'; + +export type AppDataBackup = { + /** + * A timestamp to record when the backup was made. + */ + dateCreated: string; + + /** + * The size of the backup data. + */ + size: number; + + /** + * Encrypted vault contents. + */ + data: string; +} + +export type AppDataStatus = { + /** + * Boolean indicating whether the data was successful. + */ + initialized: boolean; + + /** + * The timestamp of the last backup. + */ + lastBackup: string | undefined; + + /** + * The timestamp of the last restore. + */ + lastRestore: string | undefined; +} + +export type AppData = { + [key: string]: any; +} + +export interface AppDataStore { + /** + * Returns a promise that resolves to a string, which is the App DID. + */ + getDid(): Promise + + /** + * Returns a promise that resolves to a CryptoKey object, which + * represents the public key associated with the App DID. + */ + getPublicKey(): Promise + + /** + * Returns a promise that resolves to a CryptoKey object, which + * represents the private key associated with the App DID. + */ + getPrivateKey(): Promise + + /** + * Returns a promise that resolves to a AppDataStatus object, which + * provides information about the current status of the AppData instance. + */ + getStatus(): Promise + + /** + * Initializes the AppDataStore and returns a Promise that resolves + * to a boolean indicating whether the operation was successful. + */ + initialize(options: { passphrase: string, keyPair: Web5Crypto.CryptoKeyPair }): Promise; + + /** + * Creates an encrypted backup of the current state of `AppData` and + * returns a Promise that resolves to an `AppDataBackup` object. + */ + backup(options: { passphrase: string }): Promise; + + /** + * Restores `AppData` to the state in the provided `AppDataBackup` object. + * It requires a passphrase to decrypt the backup and returns a Promise that + * resolves to a boolean indicating whether the restore was successful. + */ + restore(options: { backup: AppDataBackup, passphrase: string }): Promise; + + /** + * Locks the `AppDataStore`, secured by a passphrase + * that must be entered to unlock. + */ + lock(): Promise; + + /** + * Attempts to unlock the `AppDataStore` with the provided + * passphrase. It returns a Promise that resolves to a + * boolean indicating whether the unlock was successful. + */ + unlock(options: { passphrase: string }): Promise; + + /** + * Attempts to change the passphrase of the `AppDataStore`. + * It requires the old passphrase for verification and returns + * a Promise that resolves to a boolean indicating whether the + * passphrase change was successful. + */ + changePassphrase(options: { oldPassphrase: string, newPassphrase: string }): Promise; +} + +export type AppDataVaultOptions = { + keyDerivationWorkFactor?: number; + store?: KeyValueStore; +} + +export class AppDataVault implements AppDataStore { + private _keyDerivationWorkFactor: number; + private _store: KeyValueStore; + private _vaultUnlockKey = new Uint8Array(); + + constructor(options?: AppDataVaultOptions) { + this._keyDerivationWorkFactor = options?.keyDerivationWorkFactor ?? 650_000; + this._store = options?.store ?? new MemoryStore(); + } + + async backup(_options: { passphrase: string }): Promise { + throw new Error ('Not implemented'); + } + + async changePassphrase(_options: { oldPassphrase: string, newPassphrase: string }): Promise { + throw new Error ('Not implemented'); + } + + private async generateVaultUnlockKey(options: { + passphrase: string, + salt: Uint8Array + }): Promise { + const { passphrase, salt } = options; + + /** The salt value derived in Step 3 and the passphrase entered by the + * end-user are inputs to the PBKDF2 algorithm to derive a 32-byte secret + * key that will be referred to as the Vault Unlock Key (VUK). */ + const vaultUnlockKey = await pbkdf2Async( + sha512, // hash function + passphrase, // password + salt, // salt + { + c : this._keyDerivationWorkFactor, // key derivation work factor + dkLen : 32 // derived key length, in bytes + } + ); + + return vaultUnlockKey; + } + + async getDid(): Promise { + // Get the Vault Key Set JWE from the data store. + const vaultKeySet = await this._store.get('vaultKeySet'); + + // Decode the Base64 URL encoded JWE protected header. + let [protectedHeaderB64U] = vaultKeySet.split('.'); + const protectedHeader = Convert.base64Url(protectedHeaderB64U).toObject() as JweHeaderParams; + + // Extract the public key in JWK format. + const publicKeyJwk = protectedHeader.wrappedKey as PublicKeyJwk; + + // Expand the public key to a did:key identifier. + const keySet: DidKeySet = { verificationMethodKeys: [{ publicKeyJwk, relationships: ['authentication'] }]}; + const { did } = await DidKeyMethod.create({ keySet }); + + return did; + } + + async getPublicKey(): Promise { + // Get the Vault Key Set JWE from the data store. + const vaultKeySet = await this._store.get('vaultKeySet'); + + // Decode the Base64 URL encoded JWE protected header. + let [protectedHeaderB64U] = vaultKeySet.split('.'); + const protectedHeader = Convert.base64Url(protectedHeaderB64U).toObject() as JweHeaderParams; + + // Convert the public key in JWK format to crypto key. + const publicKeyJwk = protectedHeader.wrappedKey as PublicKeyJwk; + const cryptoKey = await Jose.jwkToCryptoKey({ key: publicKeyJwk }); + + return cryptoKey; + } + + async getPrivateKey(): Promise { + // Get the Vault Key Set JWE from the data store. + const vaultKeySet = await this._store.get('vaultKeySet'); + + // Decode the Base64 URL encoded JWE content. + let [protectedHeaderB64U, encryptedKeyB64U, nonceB64U, _, tagB64U] = vaultKeySet.split('.'); + const protectedHeader = Convert.base64Url(protectedHeaderB64U).toObject() as JweHeaderParams; + const encryptedKey = Convert.base64Url(encryptedKeyB64U).toUint8Array(); + const nonce = Convert.base64Url(nonceB64U).toUint8Array(); + const tag = Convert.base64Url(tagB64U).toUint8Array(); + + // Decrypt the Identity Agent's private key material. + const privateKeyMaterial = await XChaCha20Poly1305.decrypt({ + additionalData : Convert.object(protectedHeader).toUint8Array(), + data : encryptedKey, + key : this._vaultUnlockKey, + nonce : nonce, + tag : tag + }); + + // Get the public key. + const publicKey = await this.getPublicKey(); + + // Create a private crypto key based off the parameters of the public key. + const privateKey = new CryptoKey( + publicKey.algorithm, + publicKey.extractable, + privateKeyMaterial, + 'private', + ['sign'] + ); + + return privateKey; + } + + async getStatus(): Promise { + try { + const appDataStatus = await this._store.get('appDataStatus'); + return JSON.parse(appDataStatus); + } catch(error: any) { + return { + initialized : false, + lastBackup : undefined, + lastRestore : undefined + }; + } + } + + async initialize(options: { + keyPair: Web5Crypto.CryptoKeyPair, + passphrase: string + }): Promise { + const { keyPair, passphrase } = options; + + const appDataStatus = await this.getStatus(); + + // Throw if the data vault was previously initialized. + if (appDataStatus.initialized === true) { + throw new Error(`Operation 'initialize' failed. Data vault already initialized.`); + } + + /** A non-secret static info value is combined with the Identity Agent's + * public key as input to a Hash-based Key Derivation Function (HKDF) + * to derive a new 32-byte salt. */ + const publicKey = keyPair.publicKey.material; + const saltInput = hkdf( + sha256, // hash function + publicKey, // input keying material + undefined, // no salt because public key is already random + 'vault_unlock_salt', // non-secret application specific information + 32 // derived key length, in bytes + ); + + /** + * Per RFC 7518, the salt value used with PBES2 should be of the format + * (UTF8(Alg) || 0x00 || Salt Input), where Alg is the "alg" (algorithm) + * Header Parameter value. This reduces the potential for a precomputed + * dictionary attack (also known as a rainbow table attack). + * @see {@link https://www.rfc-editor.org/rfc/rfc7518.html#section-4.8.1.1 | RFC 7518, Section 4.8.1.1} + */ + const algorithm = Convert.string('PBES2-HS512+XC20PKW').toUint8Array(); + const salt = new Uint8Array([...algorithm, 0x00, ...saltInput]); + + /** + * Generate a vault unlock key (VUK), which will be used as a + * key encryption key (KEK) for wrapping the private key */ + this._vaultUnlockKey = await this.generateVaultUnlockKey({ passphrase, salt }); + + /** Convert the public crypto key to JWK format to store within the JWE. */ + const wrappedKey = await Jose.cryptoKeyToJwk({ key: keyPair.publicKey }); + + /** Construct the JWE header. */ + const protectedHeader: JweHeaderParams = { + alg : 'PBES2-HS512+XC20PKW', + crit : ['wrappedKey'], + enc : 'XC20P', + p2c : this._keyDerivationWorkFactor, + p2s : Convert.uint8Array(salt).toBase64Url(), + wrappedKey : wrappedKey + }; + + /** 6. Encrypt the Identity Agent's private key with the derived VUK + * using XChaCha20-Poly1305 */ + const nonce = randomBytes(24); + const privateKey = keyPair.privateKey.material; + const { + ciphertext: privateKeyCiphertext, + tag: privateKeyTag } = await XChaCha20Poly1305.encrypt({ + additionalData : Convert.object(protectedHeader).toUint8Array(), + data : privateKey, + key : this._vaultUnlockKey, + nonce : nonce + }); + + /** 7. Serialize the Identity Agent's vault key set to a compact JWE, which + * includes the VUK salt and encrypted VUK (nonce, tag, and ciphertext). */ + const vaultKeySet = + Convert.object(protectedHeader).toBase64Url() + '.' + + Convert.uint8Array(privateKeyCiphertext).toBase64Url() + '.' + + Convert.uint8Array(nonce).toBase64Url() + '.' + + Convert.string('unused').toBase64Url() + '.' + + Convert.uint8Array(privateKeyTag).toBase64Url(); + + /** Store the vault key set in the AppDataStore. */ + await this._store.set('vaultKeySet', vaultKeySet); + + /** Set the vault to initialized. */ + appDataStatus.initialized = true; + await this.setStatus(appDataStatus); + } + + async lock(): Promise { + this._vaultUnlockKey.fill(0); + this._vaultUnlockKey = new Uint8Array(); + } + + async restore(_options: { backup: AppDataBackup, passphrase: string }): Promise { + throw new Error ('Not implemented'); + } + + async setStatus(options: Partial): Promise { + // Get the current status values from the store, if any. + const appDataStatus = await this.getStatus(); + + // Update the status properties with new values specified, if any. + appDataStatus.initialized = options.initialized ?? appDataStatus.initialized; + appDataStatus.lastBackup = options.lastBackup ?? appDataStatus.lastBackup; + appDataStatus.lastRestore = options.lastRestore ?? appDataStatus.lastRestore; + + // Write the changes to the store. + await this._store.set('appDataStatus', JSON.stringify(appDataStatus)); + + return true; + } + + async unlock(options: { passphrase: string }): Promise { + const { passphrase } = options; + + // Get the vault key set from the store. + const vaultKeySet: string = await this._store.get('vaultKeySet'); + + // Decode the protected header. + let [protectedHeaderString] = vaultKeySet.split('.'); + const protectedHeader = Convert.base64Url(protectedHeaderString).toObject() as JweHeaderParams; + + // Derive the Vault Unlock Key (VUK). + if (protectedHeader.p2s !== undefined) { + const salt = Convert.base64Url(protectedHeader.p2s).toUint8Array(); + this._vaultUnlockKey = await this.generateVaultUnlockKey({ passphrase, salt }); + } + + return true; + } +} \ No newline at end of file diff --git a/packages/agent/src/did-manager.ts b/packages/agent/src/did-manager.ts new file mode 100644 index 000000000..b8130b0c7 --- /dev/null +++ b/packages/agent/src/did-manager.ts @@ -0,0 +1,371 @@ +import type { PublicKeyJwk, Web5Crypto } from '@web5/crypto'; +import type { + DidKeySet, + DidDocument, + DidMetadata, + PortableDid, + DidMethodApi, + DidIonCreateOptions, + DidKeyCreateOptions, +} from '@web5/dids'; + +import { Jose} from '@web5/crypto'; +import { utils } from '@web5/dids'; + +import type { Web5ManagedAgent } from './types/agent.js'; +import type { ManagedDidStore } from './store-managed-did.js'; + +import { DidStoreMemory } from './store-managed-did.js'; + +export type CreateDidMethodOptions = { + ion: DidIonCreateOptions; + key: DidKeyCreateOptions; +}; + +export type CreateDidOptions = CreateDidMethodOptions[M] & { + method: M; + alias?: string; + context?: string; + kms?: string; + metadata?: DidMetadata; +} + +export type ImportDidOptions = { + alias?: string; + context?: string; + did: PortableDid; + kms?: string; +} + +export interface ManagedDid extends PortableDid { + /** + * An alternate identifier used to identify the DID. + * This property can be used to associate a DID with an external identifier. + */ + alias?: string; + + /** + * DID Method name. + */ + method: string; +} + +export type DidManagerOptions = { + agent?: Web5ManagedAgent; + didMethods: DidMethodApi[]; + store?: ManagedDidStore; +} + +export type DidIonGenerateKeySetOptions = { /* empty */ } +export type DidKeyGenerateKeySetOptions = { /* empty */ } + +export type GenerateKeySetOptions = { + ion: DidIonGenerateKeySetOptions; + key: DidKeyGenerateKeySetOptions; +}; + +export class DidManager { + /** + * Holds the instance of a `Web5ManagedAgent` that represents the current + * execution context for the `KeyManager`. This agent is utilized + * to interact with other Web5 agent components. It's vital + * to ensure this instance is set to correctly contextualize + * operations within the broader Web5 agent framework. + */ + private _agent?: Web5ManagedAgent; + private _didMethods: Map = new Map(); + private _store: ManagedDidStore; + + constructor(options: DidManagerOptions) { + const { agent, didMethods, store } = options; + this._agent = agent; + this._store = store ?? new DidStoreMemory(); + + if (!didMethods) { + throw new TypeError(`DidManager: Required parameter missing: 'didMethods'`); + } + + for (const didMethod of didMethods) { + this._didMethods.set(didMethod.methodName, didMethod); + } + } + + /** + * Retrieves the `Web5ManagedAgent` execution context. + * If the `agent` instance proprety is undefined, it will throw an error. + * + * @returns The `Web5ManagedAgent` instance that represents the current execution + * context. + * + * @throws Will throw an error if the `agent` instance property is undefined. + */ + get agent(): Web5ManagedAgent { + if (this._agent === undefined) { + throw new Error('DidManager: Unable to determine agent execution context.'); + } + + return this._agent; + } + + set agent(agent: Web5ManagedAgent) { + this._agent = agent; + } + + async create(options: CreateDidOptions): Promise { + let { alias, keySet, kms, metadata, method, context, ...methodOptions } = options; + + // Get the DID method implementation. + const didMethod = this.getMethod(method); + + // If keySet not given, generate a DID method specific key set. + if (keySet?.verificationMethodKeys === undefined) { + keySet = await didMethod.generateKeySet(); + } + + /** Import key set to KeyManager, or if already in KeyManager, retrieve the + * public key. */ + keySet = await this.importOrGetKeySet({ keySet, kms }); + + // Create a DID. + const did = await didMethod.create({ ...methodOptions, keySet }); + + // Set the KeyManager alias for each key to the DID Document primary ID. + await this.updateKeySet({ + canonicalId : did.canonicalId, + didDocument : did.document, + keySet + }); + + // Merged given metadata and format as a ManagedDid. + const mergedMetadata = { ...metadata, ...did.metadata }; + const managedDid = { alias, method, ...did, metadata: mergedMetadata }; + + /** If context is undefined, then the DID will be stored under the + * tenant of the created DID. Otherwise, the DID record will + * be stored under the tenant of the specified context. */ + context ??= managedDid.did; + + // Store the ManagedDid in the store. + await this._store.importDid({ did: managedDid, agent: this.agent, context }); + + return managedDid; + } + + async getDefaultSigningKey(options: { + did: string + }): Promise { + const { did } = options; + + // Resolve the DID to a DID Document. + const { didDocument } = await this.agent.didResolver.resolve(did); + + // Get the DID method implementation. + const parsedDid = utils.parseDid({ didUrl: did }); + + if (!(didDocument && parsedDid)) { + throw new Error(`DidManager: Unable to resolve: ${did}`); + } + + const didMethod = this.getMethod(parsedDid.method); + + // Retrieve the DID method specific default signing key. + const verificationMethodId = await didMethod.getDefaultSigningKey({ didDocument }); + + return verificationMethodId; + } + + async get(options: { + didRef: string, + context?: string + }): Promise { + let did: ManagedDid | undefined; + const { context, didRef } = options; + + // Try to get DID by ID. + did = await this._store.getDid({ did: didRef, agent: this.agent, context }); + if (did) return did; + + // Try to find DID by alias. + did = await this._store.findDid({ alias: didRef, agent: this.agent, context }); + if (did) return did; + + return undefined; + } + + async import(options: ImportDidOptions): Promise { + let { alias, context, did, kms } = options; + + if (did.keySet === undefined) { + throw new Error(`Portable DID is missing required property: 'keySet'`); + } + + // Verify the DID method is supported. + const parsedDid = utils.parseDid({ didUrl: did.did }); + if (!parsedDid) { + throw new Error(`DidManager: Unable to resolve: ${did}`); + } + const { method } = parsedDid; + this.getMethod(method); + + /** Import key set to KeyManager, or if already in KeyManager, retrieve the + * public key. */ + const keySet = await this.importOrGetKeySet({ keySet: did.keySet, kms }); + + // Set the KeyManager alias for each key to the DID Document primary ID. + await this.updateKeySet({ + canonicalId : did.canonicalId, + didDocument : did.document, + keySet + }); + + // Format the PortableDid and given input as a ManagedDid. + const managedDid = { alias, method, ...did, keySet }; + + /** If context is undefined, then the DID will be stored under the + * tenant of the imported DID. Otherwise, the DID record will + * be stored under the tenant of the specified context. */ + context ??= managedDid.did; + + // Store the ManagedDid in the store. + await this._store.importDid({ did: managedDid, agent: this.agent, context }); + + return managedDid; + } + + /** + * Retrieves a `DidMethodApi` instance associated with a specific method + * name. This method uses the method name to access the `didMethods` map + * and returns the corresponding `DidMethodApi` instance. If a method + * name is provided that does not exist within the `didMethods` map, it + * will throw an error. + * + * @param methodName - A string representing the name of the method for + * which the corresponding `DidMethodApi` instance is to be retrieved. + * + * @returns The `DidMethodApi` instance that corresponds to the provided + * method name. If no `DidMethodApi` instance corresponds to the provided + * method name, an error is thrown. + * + * @throws Will throw an error if the provided method name does not + * correspond to any `DidMethodApi` instance within the `didMethods` map. + */ + private getMethod(methodName: string): DidMethodApi { + const didMethod = this._didMethods.get(methodName); + + if (didMethod === undefined) { + throw new Error(`The DID method '${methodName}' is not supported`); + } + + return didMethod; + } + + private async importOrGetKeySet(options: { + keySet: DidKeySet, + kms: string | undefined + }): Promise { + const { kms } = options; + + // Get the agent instance. + const agent = this.agent; + + // Make a deep copy of the key set to prevent side effects. + const keySet = structuredClone(options.keySet); + + for (let key of keySet.verificationMethodKeys!) { + /** + * The key has no `keyManagerId` value, indicating it is not present in + * the KeyManager store. Import each key into KeyManager. + */ + if (key.keyManagerId === undefined) { + if ('publicKeyJwk' in key && 'privateKeyJwk' in key + && key.publicKeyJwk && key.privateKeyJwk) { + // Import key pair to KeyManager. + const publicKey = await Jose.jwkToCryptoKey({ key: key.publicKeyJwk }); + const privateKey = await Jose.jwkToCryptoKey({ key: key.privateKeyJwk! }); + const importedKeyPair = await agent.keyManager.importKey({ + privateKey : { kms: kms, ...privateKey, material: privateKey.material }, + publicKey : { kms: kms, ...publicKey, material: publicKey.material } + }); + // Store the UUID assigned by KeyManager. + key.keyManagerId = importedKeyPair.privateKey.id; + // Delete the private key. + delete key.privateKeyJwk; + + } else if ('publicKeyJwk' in key && key.publicKeyJwk) { + // Import only public key. + const publicKey = await Jose.jwkToCryptoKey({ key: key.publicKeyJwk }); + const importedPublicKey = await agent.keyManager.importKey({ + kms: kms, ...publicKey, material: publicKey.material + }); + // Store the UUID assigned by KeyManager. + key.keyManagerId = importedPublicKey.id; + + } else { + throw new Error(`Required parameter(s) missing: 'publicKeyJwk', and optionally, 'privateKeyJwk`); + } + + /** + * The key does have a `keyManagerId` value so retrieve the public key + * from the KeyManager store. + */ + } else { + const keyOrKeyPair = await agent.keyManager.getKey({ keyRef: key.keyManagerId }); + if (!keyOrKeyPair) throw new Error(`Key with ID '${key.keyManagerId} not found.`); + const publicKey = 'publicKey' in keyOrKeyPair ? keyOrKeyPair.publicKey : keyOrKeyPair; + // Convert public key from CryptoKey to JWK format. + key.publicKeyJwk = await Jose.cryptoKeyToJwk({ key: publicKey as Web5Crypto.CryptoKey }) as PublicKeyJwk; + } + } + + return keySet; + } + + /** + * Set the KeyManager alias for each key to the DID primary ID. + * + * If defined, use the `canonicalId` as the primary ID for the + * DID subject. Otherwise, use the `id` property from the topmost + * map of the DID document. + * + * @see {@link https://www.w3.org/TR/did-core/#did-subject | DID Subject} + * @see {@link https://www.w3.org/TR/did-core/#dfn-canonicalid | DID Document Metadata} + */ + private async updateKeySet(options: { + canonicalId?: string, + didDocument: DidDocument, + keySet: DidKeySet + }) { + const { canonicalId, didDocument, keySet, } = options; + + // Get the agent instance. + const agent = this.agent; + + // DID primary ID is the canonicalId, if present, or the DID document `id`. + const didPrimaryId = canonicalId ?? didDocument.id; + + for (let keyPair of keySet.verificationMethodKeys!) { + /** Compute the multibase ID for the JWK in case the DID method uses + * publicKeyMultibase format. */ + const publicKeyMultibase = await Jose.jwkToMultibaseId({ key: keyPair.publicKeyJwk! }); + + // Find the verification method ID of the key in the DID document. + const methodId = utils.getVerificationMethodIds({ + didDocument, + publicKeyJwk: keyPair.publicKeyJwk, + publicKeyMultibase + }); + + if (!(methodId && methodId.includes('#'))) { + throw new Error('DidManager: Unable to update key set due to malformed verification method ID'); + } + + /** Construct the key alias given the DID's primary ID and the key's + * verification method ID. */ + const [, fragment] = methodId.split('#'); + const keyAlias = `${didPrimaryId}#${fragment}`; + + // Set the KeyManager alias to the method ID. + await agent.keyManager.updateKey({ keyRef: keyPair.keyManagerId!, alias: keyAlias }); + } + } +} \ No newline at end of file diff --git a/packages/agent/src/dwn-manager.ts b/packages/agent/src/dwn-manager.ts new file mode 100644 index 000000000..c0764dd37 --- /dev/null +++ b/packages/agent/src/dwn-manager.ts @@ -0,0 +1,535 @@ +import type { + GenericMessage, + SignatureInput, + MessagesGetReply, + RecordsReadReply, + UnionMessageReply, + EncryptionProperty, + RecordsWriteMessage, + RecordsWriteOptions, + PrivateJwk as DwnPrivateKeyJwk, +} from '@tbd54566975/dwn-sdk-js'; + +import { Jose } from '@web5/crypto'; +import { DidResolver } from '@web5/dids'; +import { Readable } from 'readable-stream'; +import * as didUtils from '@web5/dids/utils'; +import { Convert, removeUndefinedProperties } from '@web5/common'; + +import { + EventLogLevel, + DataStoreLevel, + MessageStoreLevel, +} from '@tbd54566975/dwn-sdk-js/stores'; +import { + Cid, + Dwn, + Message, + EventsGet, + DataStream, + RecordsRead, + MessagesGet, + RecordsWrite, + RecordsQuery, + DwnMethodName, + RecordsDelete, + ProtocolsQuery, + DwnInterfaceName, + ProtocolsConfigure, +} from '@tbd54566975/dwn-sdk-js'; + +import type { DwnRpcRequest, DwnResponse,ProcessDwnRequest, SendDwnRequest, Web5ManagedAgent } from './types/agent.js'; + +import { isManagedKeyPair } from './utils.js'; +import { blobToIsomorphicNodeReadable, webReadableToIsomorphicNodeReadable } from './utils.js'; + +export type GeneralJws = { + payload: string + signatures: SignatureEntry[] +}; + +export type SignatureEntry = { + protected: string + signature: string +}; + +export type RecordsWriteAuthorizationPayload = { + recordId: string; + contextId?: string; + descriptorCid: string; + attestationCid?: string; + encryptionCid?: string; +}; + +type DwnMessage = { + message: any; + data?: Blob; +} + +const dwnMessageCreators = { + [DwnInterfaceName.Events + DwnMethodName.Get] : EventsGet, + [DwnInterfaceName.Messages + DwnMethodName.Get] : MessagesGet, + [DwnInterfaceName.Records + DwnMethodName.Read] : RecordsRead, + [DwnInterfaceName.Records + DwnMethodName.Query] : RecordsQuery, + [DwnInterfaceName.Records + DwnMethodName.Write] : RecordsWrite, + [DwnInterfaceName.Records + DwnMethodName.Delete] : RecordsDelete, + [DwnInterfaceName.Protocols + DwnMethodName.Query] : ProtocolsQuery, + [DwnInterfaceName.Protocols + DwnMethodName.Configure] : ProtocolsConfigure, +}; + +export type DwnManagerOptions = { + agent?: Web5ManagedAgent; + dwn: Dwn; +} + +export type DwnManagerCreateOptions = { + agent?: Web5ManagedAgent; + dataPath?: string; + didResolver?: DidResolver; + dwn?: Dwn; +} + +export class DwnManager { + /** + * Holds the instance of a `Web5ManagedAgent` that represents the current + * execution context for the `KeyManager`. This agent is utilized + * to interact with other Web5 agent components. It's vital + * to ensure this instance is set to correctly contextualize + * operations within the broader Web5 agent framework. + */ + private _agent?: Web5ManagedAgent; + private _dwn: Dwn; + + constructor(options: DwnManagerOptions) { + this._agent = options.agent; + this._dwn = options.dwn; + } + + /** + * Retrieves the `Web5ManagedAgent` execution context. + * If the `agent` instance proprety is undefined, it will throw an error. + * + * @returns The `Web5ManagedAgent` instance that represents the current execution + * context. + * + * @throws Will throw an error if the `agent` instance property is undefined. + */ + get agent(): Web5ManagedAgent { + if (this._agent === undefined) { + throw new Error('DidManager: Unable to determine agent execution context.'); + } + + return this._agent; + } + + set agent(agent: Web5ManagedAgent) { + this._agent = agent; + } + + get dwn(): Dwn { + return this._dwn; + } + + public static async create(options?: DwnManagerCreateOptions) { + let { agent, dataPath, didResolver, dwn } = options ?? { }; + + dataPath ??= 'DATA/AGENT'; + + if (dwn === undefined) { + const dataStore = new DataStoreLevel({ + blockstoreLocation: `${dataPath}/DWN_DATASTORE` + }); + const eventLog = new EventLogLevel({ + location: `${dataPath}/DWN_EVENTLOG` + }); + const messageStore = new MessageStoreLevel(({ + blockstoreLocation : `${dataPath}/DWN_MESSAGESTORE`, + indexLocation : `${dataPath}/DWN_MESSAGEINDEX` + })); + + dwn = await Dwn.create({ + dataStore, + // @ts-expect-error because `dwn-sdk-js` expects its internal DidResolver implementation. + didResolver, + eventLog, + messageStore, + }); + } + + return new DwnManager({ agent, dwn }); + } + + public async processRequest(request: ProcessDwnRequest): Promise { + const { message, dataStream } = await this.constructDwnMessage({ request }); + + let reply: UnionMessageReply; + if (request.store !== false) { + reply = await this._dwn.processMessage(request.target, message, dataStream); + } else { + reply = { status: { code: 202, detail: 'Accepted' }}; + } + + return { + reply, + message : message, + messageCid : await Message.getCid(message) + }; + } + + public async sendRequest(request: SendDwnRequest): Promise { + const dwnRpcRequest: Partial = { targetDid: request.target }; + let messageData: Blob | Readable | ReadableStream | undefined; + + if ('messageCid' in request) { + const { message, data } = await this.getDwnMessage({ + author : request.author, + messageCid : request.messageCid, + messageType : request.messageType + }); + dwnRpcRequest.message = message; + messageData = data; + + } else { + const { message } = await this.constructDwnMessage({ request }); + dwnRpcRequest.message = message; + messageData = request.dataStream; + } + + if (messageData) { + dwnRpcRequest.data = messageData; + } + + const { didDocument, didResolutionMetadata } = await this.agent.didResolver.resolve(request.target); + if (!didDocument) { + const errorCode = `${didResolutionMetadata?.error}: ` ?? ''; + const defaultMessage = `Unable to resolve target DID: ${request.target}`; + const errorMessage = didResolutionMetadata?.errorMessage ?? defaultMessage; + throw new Error(`DwnManager: ${errorCode}${errorMessage}`); + } + + const [ service ] = didUtils.getServices({ didDocument, id: '#dwn' }); + if (!service) { + throw new Error(`DwnManager: DID Document of '${request.target}' has no service endpoints with ID '#dwn'`); + } + + if (!didUtils.isDwnServiceEndpoint(service.serviceEndpoint)) { + throw new Error(`DwnManager: Malformed '#dwn' service endpoint. Expected array of node addresses.`); + } + const dwnEndpointUrls = service.serviceEndpoint.nodes; + + let dwnReply; + let errorMessages = []; + + // try sending to author's publicly addressable dwn's until first request succeeds. + for (let dwnUrl of dwnEndpointUrls) { + dwnRpcRequest.dwnUrl = dwnUrl; + + try { + dwnReply = await this.agent.rpcClient.sendDwnRequest(dwnRpcRequest as DwnRpcRequest); + break; + } catch(error: unknown) { + const message = (error instanceof Error) ? error.message : 'Uknown error'; + errorMessages.push({ url: dwnUrl, message }); + } + } + + if (!dwnReply) { + throw new Error(JSON.stringify(errorMessages)); + } + + return { + message : dwnRpcRequest.message, + messageCid : await Message.getCid(dwnRpcRequest.message), + reply : dwnReply, + }; + } + + private async constructDwnMessage(options: { + request: ProcessDwnRequest + }) { + const { request } = options; + + let readableStream: Readable | undefined; + + // TODO: Consider refactoring to move data transformations imposed by fetch() limitations to the HTTP transport-related methods. + if (request.messageType === 'RecordsWrite') { + const messageOptions = request.messageOptions as RecordsWriteOptions; + + if (request.dataStream && !messageOptions.data) { + const { dataStream } = request; + let isomorphicNodeReadable: Readable; + + if (dataStream instanceof Blob) { + isomorphicNodeReadable = blobToIsomorphicNodeReadable(dataStream); + readableStream = blobToIsomorphicNodeReadable(dataStream); + + } else if (dataStream instanceof ReadableStream) { + const [ forCid, forProcessMessage ] = dataStream.tee(); + isomorphicNodeReadable = webReadableToIsomorphicNodeReadable(forCid); + readableStream = webReadableToIsomorphicNodeReadable(forProcessMessage); + } + + // @ts-ignore + messageOptions.dataCid = await Cid.computeDagPbCidFromStream(isomorphicNodeReadable); + // @ts-ignore + messageOptions.dataSize ??= isomorphicNodeReadable['bytesRead']; + } + } + + const signingKeyId = await this.getAuthorSigningKeyId({ did: request.author }); + + // ! TODO: Remove this once DWN SDK supports external signers. + const dwnSignatureInput = this.getTempSignatureInput({ signingKeyId }); + + // TODO: Figure out how to narrow this type. + const messageCreateInput = { + ...request.messageOptions, + authorizationSignatureInput: dwnSignatureInput + }; + + const messageCreator = dwnMessageCreators[request.messageType]; + + // ! TODO: START Remove this monkey patch (MP) as soon as the DWN SDK supports external signers. + // MP Step 1: Store the original methods. + const originalCreateAuthorization = RecordsWrite.createAuthorization; + const originalSignAsAuthorization = Message.signAsAuthorization; + // MP Step 2: Replace the methods. + RecordsWrite.createAuthorization = ( + recordId: string, + contextId: string | undefined, + descriptorCid: string, + attestation: GeneralJws | undefined, + encryption: EncryptionProperty | undefined, + ) => this.createAuthorization(recordId, contextId, descriptorCid, attestation, encryption, signingKeyId); + Message.signAsAuthorization = ( + descriptor: GenericMessage['descriptor'], + signatureInput: SignatureInput, + permissionsGrantId?: string, + ) => this.signAsAuthorization(descriptor, signingKeyId, permissionsGrantId); + // MP Step 3: Call the method that required monkey patching. + const dwnMessage = await messageCreator.create(messageCreateInput as any); + // MP Step 4: Restore the original methods. + RecordsWrite.createAuthorization = originalCreateAuthorization; + Message.signAsAuthorization = originalSignAsAuthorization; + // ! TODO: END Remove this monkey patch (MP) as soon as the DWN SDK supports external signers. + + return { message: dwnMessage.toJSON(), dataStream: readableStream }; + } + + private async getAuthorSigningKeyId(options: { + did: string + }): Promise { + const { did } = options; + + // Get the agent instance. + const agent = this.agent; + + // Get the method-specific default signing key. + const signingKeyId = await agent.didManager.getDefaultSigningKey({ did }); + + if (!signingKeyId) { + throw new Error (`DwnManager: Unable to determine signing key for author: '${did}'`); + } + + return signingKeyId; + } + + private async getDwnMessage(options: { + author: string, + messageType: string, + messageCid: string + }): Promise { + const { author, messageType, messageCid } = options; + + const signingKeyId = await this.getAuthorSigningKeyId({ did: author }); + + // ! TODO: START Remove this monkey patch (MP) as soon as the DWN SDK supports external signers. + const dwnSignatureInput = this.getTempSignatureInput({ signingKeyId }); + // MP Step 1: Store the original methods. + const originalSignAsAuthorization = Message.signAsAuthorization; + // MP Step 2: Replace the methods. + Message.signAsAuthorization = ( + descriptor: GenericMessage['descriptor'], + signatureInput: SignatureInput, + permissionsGrantId?: string, + ) => this.signAsAuthorization(descriptor, signingKeyId, permissionsGrantId); + // MP Step 3: Call the method that required monkey patching. + const messagesGet = await MessagesGet.create({ + authorizationSignatureInput : dwnSignatureInput, + messageCids : [messageCid] + }); + // MP Step 4: Restore the original methods. + Message.signAsAuthorization = originalSignAsAuthorization; + // ! TODO: END Remove this monkey patch (MP) as soon as the DWN SDK supports external signers. + + const result: MessagesGetReply = await this._dwn.processMessage(author, messagesGet.toJSON()); + + if (!(result.messages && result.messages.length === 1)) { + throw new Error('TODO: figure out error message'); + } + + const [ messageEntry ] = result.messages; + + let { message } = messageEntry; + if (!message) { + throw new Error('TODO: message not found'); + } + + let dwnMessage: DwnMessage = { message }; + + /** If the message is a RecordsWrite, either data will be present, OR + * we have to fetch it using a RecordsRead. */ + if (messageType === 'RecordsWrite') { + const { encodedData } = messageEntry; + const writeMessage = message as RecordsWriteMessage; + + if (encodedData) { + const dataBytes = Convert.base64Url(encodedData).toUint8Array(); + dwnMessage.data = new Blob([dataBytes]); + } else { + const recordsRead = await RecordsRead.create({ + authorizationSignatureInput : dwnSignatureInput, + recordId : writeMessage.recordId + }); + + const reply = await this._dwn.processMessage(author, recordsRead.toJSON()) as RecordsReadReply; + + if (reply.status.code >= 400) { + const { status: { code, detail } } = reply; + throw new Error(`(${code}) Failed to read data associated with record ${writeMessage.recordId}. ${detail}}`); + } else if (reply.record) { + const dataBytes = await DataStream.toBytes(reply.record.data); + dwnMessage.data = new Blob([dataBytes]); + } + } + } + + return dwnMessage; + } + + /** + * The following methods are a temporary workaround that should be removed + * once DWN SDK implements support for an external signer. + * + * - createAuthorization() + * - createJws() + * - getTempSignatureInput() + * - signAsAuthorization() + */ + + private async createAuthorization( + recordId: string, + contextId: string | undefined, + descriptorCid: string, + attestation: GeneralJws | undefined, + encryption: EncryptionProperty | undefined, + signingKeyId: string, + ): Promise { + const authorizationPayload: RecordsWriteAuthorizationPayload = { + recordId, + descriptorCid + }; + + const attestationCid = attestation ? await Cid.computeCid(attestation) : undefined; + const encryptionCid = encryption ? await Cid.computeCid(encryption) : undefined; + + if (contextId !== undefined) { authorizationPayload.contextId = contextId; } // assign `contextId` only if it is defined + if (attestationCid !== undefined) { authorizationPayload.attestationCid = attestationCid; } // assign `attestationCid` only if it is defined + if (encryptionCid !== undefined) { authorizationPayload.encryptionCid = encryptionCid; } // assign `encryptionCid` only if it is defined + + const authorizationPayloadU8A = Convert.object(authorizationPayload).toUint8Array(); + + const jws = await this.createJws(authorizationPayloadU8A, [signingKeyId]); + + return jws; + } + + private async createJws(payload: Uint8Array, signingKeyIds: string[] = []): Promise { + // Get the agent instance. + const agent = this.agent; + + // Begin constructing a JWS. + const jws: GeneralJws = { + payload : Convert.uint8Array(payload).toBase64Url(), + signatures : [] + }; + + for (const signingKeyId of signingKeyIds) { + + /** DID keys stored in KeyManager use the canonicalId as an alias, so + * normalize the signing key ID before attempting to retrieve the key. **/ + const parsedDid = didUtils.parseDid({ didUrl: signingKeyId }); + if (!parsedDid) throw new Error(`DidIonMethod: Unable to parse DID: ${signingKeyId}`); + const normalizedDid = parsedDid.did.split(':', 3).join(':'); + const normalizedSigningKeyId = `${normalizedDid}#${parsedDid.fragment}`; + + // Attempt to retrieve the signing key. + const signingKey = await agent.keyManager.getKey({ keyRef: normalizedSigningKeyId }); + + if (!isManagedKeyPair(signingKey)) { + throw new Error (`DwnManager: Signing key not found for author: '${normalizedDid}'`); + } + + // Get the JWS alg parameter given the key pair. + const { alg } = Jose.webCryptoToJose(signingKey.privateKey.algorithm); + + // Construct the JWS protected header. + const protectedHeader = Convert.object( + { alg, kid: signingKeyId } + ).toBase64Url(); + + // Concatenate the dot-separated header and payload and convert to bytes. + const headerAndPayload = Convert.string( + `${protectedHeader}.${jws.payload}` + ).toUint8Array(); + + // Sign the JWS. + const signatureBytes = await agent.keyManager.sign({ + algorithm : signingKey.privateKey.algorithm, + data : headerAndPayload, + keyRef : signingKey.privateKey.id + }); + const signature = Convert.uint8Array(signatureBytes).toBase64Url(); + + jws.signatures.push({ protected: protectedHeader, signature }); + } + + return jws; + } + + private getTempSignatureInput({ signingKeyId }: { signingKeyId: string }): SignatureInput { + const privateJwk: DwnPrivateKeyJwk = { + alg : 'placeholder', + d : 'placeholder', + crv : 'Ed25519', + kty : 'placeholder', + x : 'placeholder' + }; + + const protectedHeader = { + alg : 'placeholder', + kid : signingKeyId + }; + + const dwnSignatureInput: SignatureInput = { privateJwk, protectedHeader }; + + return dwnSignatureInput; + } + + private async signAsAuthorization( + descriptor: GenericMessage['descriptor'], + signingKeyId: string, + permissionsGrantId?: string + ): Promise { + const descriptorCid = await Cid.computeCid(descriptor); + + const authorizationPayload = { descriptorCid, permissionsGrantId }; + removeUndefinedProperties(authorizationPayload); + + const authorizationPayloadU8A = Convert.object(authorizationPayload).toUint8Array(); + + const jws = await this.createJws(authorizationPayloadU8A, [signingKeyId]); + + return jws; + } +} \ No newline at end of file diff --git a/packages/agent/src/identity-manager.ts b/packages/agent/src/identity-manager.ts new file mode 100644 index 000000000..fef975527 --- /dev/null +++ b/packages/agent/src/identity-manager.ts @@ -0,0 +1,165 @@ +import type { PortableDid } from '@web5/dids'; +import type { Web5ManagedAgent } from './types/agent.js'; +import type { CreateDidMethodOptions, ManagedDid } from './did-manager.js'; +import type { ManagedIdentityStore } from './store-managed-identity.js'; + +import { IdentityStoreMemory } from './store-managed-identity.js'; + +type CreateWithDid = Required> + & Pick + +type CreateWithDidMethod = Pick & { + didMethod: M; + didOptions?: CreateDidMethodOptions[M]; +} + +type DidMethod = keyof CreateDidMethodOptions; + +export type CreateIdentityOptions = { + did?: PortableDid; + didMethod?: any; + didOptions?: any; + context?: string; + kms?: string; + name: string; +} + +export type IdentityManagerOptions = { + agent?: Web5ManagedAgent; + store?: ManagedIdentityStore; +} + +export type ImportIdentityOptions = { + context?: string; + did?: PortableDid; + identity: ManagedIdentity; + kms?: string; +} + +export interface ManagedIdentity { + did: string; + name: string; +} + +export class IdentityManager { + /** + * Holds the instance of a `Web5ManagedAgent` that represents the current + * execution context for the `KeyManager`. This agent is utilized + * to interact with other Web5 agent components. It's vital + * to ensure this instance is set to correctly contextualize + * operations within the broader Web5 agent framework. + */ + private _agent?: Web5ManagedAgent; + private _store: ManagedIdentityStore; + + constructor(options?: IdentityManagerOptions) { + const { agent, store } = options ?? {}; + this._agent = agent; + this._store = store ?? new IdentityStoreMemory(); + } + + /** + * Retrieves the `Web5ManagedAgent` execution context. + * If the `agent` instance proprety is undefined, it will throw an error. + * + * @returns The `Web5ManagedAgent` instance that represents the current execution + * context. + * + * @throws Will throw an error if the `agent` instance property is undefined. + */ + get agent(): Web5ManagedAgent { + if (this._agent === undefined) { + throw new Error('IdentityManager: Unable to determine agent execution context.'); + } + + return this._agent; + } + + set agent(agent: Web5ManagedAgent) { + this._agent = agent; + } + + async create(options: CreateWithDidMethod): Promise; + async create(options: CreateWithDid): Promise; + async create(options: CreateIdentityOptions): Promise { + let { context, did, didMethod, didOptions, kms, name } = options; + + if (!(didMethod ? !did : did)) { + throw new Error(`Either 'did' or 'didMethod' must be defined, but not both.`); + } + + let managedDid: ManagedDid | undefined; + + // Get the agent instance. + const agent = this.agent; + + if (didMethod) { + // Create new DID and generate key set. + managedDid = await agent.didManager.create({ method: didMethod, context, kms, ...didOptions }); + + } else if (did) { + // Import given DID and key set. + managedDid = await agent.didManager.import({ did, context, kms }); + } + + if (managedDid === undefined) { + throw new Error('IdentityManager: Unable to generate or import DID.'); + } + + // Create a ManagedIdentity. + const identity: ManagedIdentity = { + did : managedDid.did, + name : name + }; + + /** If context is undefined, then the Identity will be stored under the + * tenant of the created DID. Otherwise, the Identity records will + * be stored under the tenant of the specified context. */ + context ??= identity.did; + + // Store the ManagedIdentity in the store. + await this._store.importIdentity({ identity, agent, context }); + + return identity; + } + + async get(options: { + did: string, + context?: string + }): Promise { + const { context, did } = options; + + const identity = this._store.getIdentity({ did, agent: this.agent, context }); + + return identity; + } + + async import(options: ImportIdentityOptions): Promise { + let { context, did, identity, kms } = options; + + // Get the agent instance. + const agent = this.agent; + + // If provided, import the given DID and key set. + if (did) { + await agent.didManager.import({ did, context, kms }); + } + + /** If context is undefined, then the Identity will be stored under the + * tenant of the imported DID. Otherwise, the Identity record will + * be stored under the tenant of the specified context. */ + context ??= identity.did; + + // Store the ManagedIdentity in the store. + await this._store.importIdentity({ identity, agent, context }); + + return identity; + } + + async list(options?: { context?: string }): Promise { + const { context } = options ?? {}; + const identities = this._store.listIdentities({ agent: this.agent, context }); + + return identities; + } +} \ No newline at end of file diff --git a/packages/agent/src/index.ts b/packages/agent/src/index.ts new file mode 100644 index 000000000..3b38d6cdb --- /dev/null +++ b/packages/agent/src/index.ts @@ -0,0 +1,17 @@ +export type * from './types/agent.js'; +export type * from './types/managed-key.js'; + +export * from './app-data-store.js'; +export * from './did-manager.js'; +export * from './dwn-manager.js'; +export * from './identity-manager.js'; +export * from './json-rpc.js'; +export * from './key-manager.js'; +export * from './kms-local.js'; +export * from './rpc-client.js'; +export * from './store-managed-did.js'; +export * from './store-managed-key.js'; +export * from './store-managed-identity.js'; +export * from './utils.js'; + +export * from './test-managed-agent.js'; \ No newline at end of file diff --git a/packages/web5-agent/src/json-rpc.ts b/packages/agent/src/json-rpc.ts similarity index 100% rename from packages/web5-agent/src/json-rpc.ts rename to packages/agent/src/json-rpc.ts diff --git a/packages/agent/src/key-manager.ts b/packages/agent/src/key-manager.ts new file mode 100644 index 000000000..f01e2de1b --- /dev/null +++ b/packages/agent/src/key-manager.ts @@ -0,0 +1,302 @@ +import type { + ManagedKey, + PortableKey, + SignOptions, + CryptoManager, + VerifyOptions, + DecryptOptions, + EncryptOptions, + ManagedKeyPair, + GenerateKeyType, + ManagedKeyStore, + ImportKeyOptions, + UpdateKeyOptions, + DeriveBitsOptions, + PortableKeyPair, + GenerateKeyOptions, + KeyManagementSystem, + GenerateKeyOptionTypes, +} from './types/managed-key.js'; + +import { Web5ManagedAgent } from './types/agent.js'; +import { LocalKms } from './kms-local.js'; +import { isManagedKey, isManagedKeyPair } from './utils.js'; +import { KeyStoreMemory, PrivateKeyStoreMemory } from './store-managed-key.js'; + +export type KmsMap = { + [name: string]: KeyManagementSystem; +} + +export type KeyManagerOptions = { + agent?: Web5ManagedAgent; + kms?: KmsMap; + store?: ManagedKeyStore; +} + +/** + * KeyManager + * + * This class orchestrates implementations of {@link KeyManagementSystem}, + * using a ManagedKeyStore to remember the link between a key reference, + * its metadata, and the respective key management system that provides the + * actual cryptographic capabilities. + * + * The methods of this class are used automatically by other Web5 Agent + * components to perform their required cryptographic operations using + * the managed keys. + * + * @public + */ +export class KeyManager implements CryptoManager { + /** + * Holds the instance of a `Web5ManagedAgent` that represents the current + * execution context for the `KeyManager`. This agent is utilized + * to interact with other Web5 agent components. It's vital + * to ensure this instance is set to correctly contextualize + * operations within the broader Web5 agent framework. + */ + private _agent?: Web5ManagedAgent; + // ManagedKey to use for signing DWN messages with DWN-backed store. + private _defaultSigningKey?: ManagedKeyPair; + // KMS name to KeyManagementSystem mapping. + private _kms: Map; + // Store for managed key metadata. + private _store: ManagedKeyStore; + + constructor(options?: KeyManagerOptions) { + let { agent, kms, store } = options ?? { }; + this._agent = agent; + this._store = store ?? new KeyStoreMemory(); + + kms ??= this.useMemoryKms(); + this._kms = new Map(Object.entries(kms)) ; + } + + /** + * Retrieves the `Web5ManagedAgent` execution context. + * If the `agent` instance proprety is undefined, it will throw an error. + * + * @returns The `Web5ManagedAgent` instance that represents the current execution + * context. + * + * @throws Will throw an error if the `agent` instance property is undefined. + */ + get agent(): Web5ManagedAgent { + if (this._agent === undefined) { + throw new Error('KeyManager: Unable to determine agent execution context.'); + } + + return this._agent; + } + + set agent(agent: Web5ManagedAgent) { + this._agent = agent; + this._kms.forEach((kms) => { + kms.agent = agent; + }); + } + + async decrypt(options: DecryptOptions): Promise { + let { keyRef, ...decryptOptions } = options; + + const key = await this.getKey({ keyRef }); + + if (!isManagedKey(key)) { + throw new Error(`Key not found: '${keyRef}'`); + } + + const kmsName = key.kms; + const kms = this.getKms(kmsName); + + const keyId = key.id; + const plaintext = await kms.decrypt({ keyRef: keyId, ...decryptOptions }); + + return plaintext; + } + + async deriveBits(options: DeriveBitsOptions): Promise { + const { baseKeyRef, ...deriveBitsOptions } = options; + + const ownKeyPair = await this.getKey({ keyRef: baseKeyRef }); + + if (!isManagedKeyPair(ownKeyPair)) { + throw new Error(`Key not found: '${baseKeyRef}'`); + } + + const kmsName = ownKeyPair.privateKey.kms; + const kms = this.getKms(kmsName); + + const ownKeyId = ownKeyPair.privateKey.id; + const sharedSecret = kms.deriveBits({ baseKeyRef: ownKeyId, ...deriveBitsOptions }); + + return sharedSecret; + } + + async encrypt(options: EncryptOptions): Promise { + let { keyRef, ...encryptOptions } = options; + + const key = await this.getKey({ keyRef }); + + if (!isManagedKey(key)) { + throw new Error(`Key not found: '${keyRef}'`); + } + + const kmsName = key.kms; + const kms = this.getKms(kmsName); + + const keyId = key.id; + const ciphertext = await kms.encrypt({ keyRef: keyId, ...encryptOptions }); + + return ciphertext; + } + + async generateKey(options: GenerateKeyOptions & { kms?: string }): Promise> { + const { kms: kmsName, ...generateKeyOptions } = options; + + const kms = this.getKms(kmsName); + + const keyOrKeyPair = await kms.generateKey(generateKeyOptions); + + // Store the ManagedKey or ManagedKeyPair in KeyManager's key store. + await this._store.importKey({ key: keyOrKeyPair, agent: this.agent }); + + return keyOrKeyPair; + } + + async getKey({ keyRef }: { keyRef: string }): Promise { + let keyOrKeyPair: ManagedKey | ManagedKeyPair | undefined; + + // First, check to see if the requested key is the default signing key. + const defaultSigningKeyId = this._defaultSigningKey?.publicKey.id; + const defaultSigningKeyAlias = this._defaultSigningKey?.publicKey.alias; + if (keyRef === defaultSigningKeyId || keyRef === defaultSigningKeyAlias) { + return this._defaultSigningKey; + } + + // Try to get key by ID. + keyOrKeyPair = await this._store.getKey({ id: keyRef, agent: this.agent }); + if (keyOrKeyPair) return keyOrKeyPair; + + // Try to find key by alias. + keyOrKeyPair = await this._store.findKey({ alias: keyRef, agent: this.agent }); + if (keyOrKeyPair) return keyOrKeyPair; + + return undefined; + } + + async importKey(options: PortableKeyPair): Promise; + async importKey(options: PortableKey): Promise; + async importKey(options: ImportKeyOptions): Promise { + const kmsName = ('privateKey' in options) ? options.privateKey.kms : options.kms; + const kms = this.getKms(kmsName); + + // Store the ManagedKey or ManagedKeyPair in the given KMS. + const importedKeyOrKeyPair = await kms.importKey(options); + + // Store the ManagedKey or ManagedKeyPair in KeyManager's key store. + await this._store.importKey({ key: importedKeyOrKeyPair, agent: this.agent }); + + return importedKeyOrKeyPair; + } + + listKms() { + return Array.from(this._kms.keys()); + } + + async setDefaultSigningKey({ key }: { key: PortableKeyPair }) { + const kmsName = key.privateKey.kms; + const kms = this.getKms(kmsName); + + // Store the default signing key pair in an in-memory KMS. + const importedDefaultSigningKey = await kms.importKey(key); + + // Set the in-memory key to be KeyManager's default signing key. + this._defaultSigningKey = importedDefaultSigningKey; + } + + async sign(options: SignOptions): Promise { + const { keyRef, ...signOptions } = options; + + const keyPair = await this.getKey({ keyRef }); + + if (!isManagedKeyPair(keyPair)) { + throw new Error(`Key not found: '${keyRef}'`); + } + + const kmsName = keyPair.privateKey.kms; + const kms = this.getKms(kmsName); + + const keyId = keyPair.privateKey.id; + const signature = await kms.sign({ keyRef: keyId, ...signOptions }); + + return signature; + } + + async updateKey(options: UpdateKeyOptions): Promise { + const { keyRef, alias, metadata } = options; + + const keyOrKeyPair = await this.getKey({ keyRef }); + + if (!keyOrKeyPair) { + throw new Error(`Key not found: '${keyRef}'`); + } + + const { id: keyId, kms: kmsName } = (isManagedKeyPair(keyOrKeyPair)) + ? { ...keyOrKeyPair.publicKey } + : { ...keyOrKeyPair }; + + // Update the ManagedKey or ManagedKeyPair in the given KMS. + const kms = this.getKms(kmsName); + const kmsUpdated = await kms.updateKey(options); + + if (!kmsUpdated) return false; + + // Since the KMS was successfully updated, update the KeyManager store. + return await this._store.updateKey({ id: keyId, alias, metadata, agent: this.agent }); + } + + async verify(options: VerifyOptions): Promise { + let { keyRef, ...verifyOptions } = options; + + const keyPair = await this.getKey({ keyRef }); + + if (!isManagedKeyPair(keyPair)) { + throw new Error(`Key not found: '${keyRef}'`); + } + + const kmsName = keyPair.publicKey.kms; + const kms = this.getKms(kmsName); + + const keyId = keyPair.publicKey.id; + const isValid = await kms.verify({ keyRef: keyId, ...verifyOptions }); + + return isValid; + } + + private getKms(name: string | undefined): KeyManagementSystem { + // For developer convenience, if a KMS name isn't specified and KeyManager only has + // one KMS defined, use it. Otherwise, an exception will be thrown. + name ??= (this._kms.size === 1) ? this._kms.keys().next().value : ''; + + const kms = this._kms.get(name!); + + if (!kms) { + throw Error(`Unknown key management system: '${name}'`); + } + + return kms; + } + + private useMemoryKms(): KmsMap { + // Instantiate in-memory store for KMS key metadata and public keys. + const keyStore = new KeyStoreMemory(); + + // Instantiate in-memory store for KMS private keys. + const privateKeyStore = new PrivateKeyStoreMemory(); + + // Instantiate local KMS using in-memory key stores. + const kms = new LocalKms({ kmsName: 'memory', keyStore, privateKeyStore }); + + return { memory: kms }; + } +} \ No newline at end of file diff --git a/packages/crypto/src/kms-local/kms-local.ts b/packages/agent/src/kms-local.ts similarity index 54% rename from packages/crypto/src/kms-local/kms-local.ts rename to packages/agent/src/kms-local.ts index db1ac61d3..b4bb334a3 100644 --- a/packages/crypto/src/kms-local/kms-local.ts +++ b/packages/agent/src/kms-local.ts @@ -1,59 +1,119 @@ -import type { RequireOnly } from '@tbd54566975/common'; -import type { AlgorithmImplementation, AlgorithmImplementations } from './supported-algorithms.js'; -import type { +import type { Web5Crypto } from '@web5/crypto'; +import type { RequireOnly } from '@web5/common'; + +import { isCryptoKeyPair, checkRequiredProperty } from '@web5/crypto/utils'; +import { + EcdhAlgorithm, + EcdsaAlgorithm, + EdDsaAlgorithm, + AesCtrAlgorithm, + CryptoAlgorithm, +} from '@web5/crypto'; + +import { ManagedKey, - Web5Crypto, + PortableKey, SignOptions, VerifyOptions, - ImportableKey, DecryptOptions, EncryptOptions, ManagedKeyPair, + ManagedKeyStore, GenerateKeyType, + PortableKeyPair, ImportKeyOptions, + UpdateKeyOptions, DeriveBitsOptions, - ImportableKeyPair, + ManagedPrivateKey, GenerateKeyOptions, KeyManagementSystem, GenerateKeyOptionTypes, -} from '../types/index.js'; +} from './types/managed-key.js'; -import { Convert } from '@tbd54566975/common'; +import { isManagedKey, isManagedKeyPair } from './utils.js'; +import { KeyStoreMemory, PrivateKeyStoreMemory } from './store-managed-key.js'; +import { Web5ManagedAgent } from './types/agent.js'; -import { CryptoAlgorithm } from '../algorithms-api/index.js'; -import { defaultAlgorithms } from './supported-algorithms.js'; -import { KmsKeyStore, KmsPrivateKeyStore } from './key-store.js'; -import { checkRequiredProperty, isCryptoKeyPair, isManagedKey, isManagedKeyPair } from '../utils-new.js'; +export type AlgorithmImplementation = typeof CryptoAlgorithm & { new(): CryptoAlgorithm; }; +export type AlgorithmImplementations = { + [algorithmName: string]: AlgorithmImplementation; +}; export type KmsOptions = { + agent?: Web5ManagedAgent; cryptoAlgorithms?: AlgorithmImplementations; + keyStore?: ManagedKeyStore; + kmsName: string; + privateKeyStore?: ManagedKeyStore; } -export class LocalKms implements KeyManagementSystem { - private name: string; - private keyStore: KmsKeyStore; - private privateKeyStore: KmsPrivateKeyStore; - private supportedAlgorithms: Map = new Map(); +// Map key operations to algorithm specs to implementations. +export const defaultAlgorithms: AlgorithmImplementations = { + 'AES-CTR' : AesCtrAlgorithm, + ECDH : EcdhAlgorithm, + ECDSA : EcdsaAlgorithm, + EdDSA : EdDsaAlgorithm, +}; - constructor(kmsName: string, keyStore: KmsKeyStore, privateKeyStore: KmsPrivateKeyStore, options: KmsOptions = {}) { - this.name = kmsName; - this.keyStore = keyStore; - this.privateKeyStore = privateKeyStore; +export class LocalKms implements KeyManagementSystem { + /** + * Holds the instance of a `Web5ManagedAgent` that represents the current + * execution context for the `KeyManager`. This agent is utilized + * to interact with other Web5 agent components. It's vital + * to ensure this instance is set to correctly contextualize + * operations within the broader Web5 agent framework. + */ + private _agent?: Web5ManagedAgent; + private _name: string; + private _keyStore: ManagedKeyStore; + private _privateKeyStore: ManagedKeyStore; + private _supportedAlgorithms: Map = new Map(); + + constructor(options: KmsOptions) { + const { agent, kmsName, keyStore, privateKeyStore } = options; + this._agent = agent; + this._name = kmsName; + this._keyStore = keyStore ?? new KeyStoreMemory(); + this._privateKeyStore = privateKeyStore ?? new PrivateKeyStoreMemory(); // Merge the default and custom algorithms and register with the KMS. const cryptoAlgorithms = {...defaultAlgorithms, ...options.cryptoAlgorithms}; this.registerSupportedAlgorithms(cryptoAlgorithms); } - async decrypt(options: DecryptOptions): Promise { + /** + * Retrieves the `Web5ManagedAgent` execution context. + * If the `agent` instance proprety is undefined, it will throw an error. + * + * @returns The `Web5ManagedAgent` instance that represents the current execution + * context. + * + * @throws Will throw an error if the `agent` instance property is undefined. + */ + get agent(): Web5ManagedAgent { + if (this._agent === undefined) { + throw new Error('KeyManager: Unable to determine agent execution context.'); + } + + return this._agent; + } + + set agent(agent: Web5ManagedAgent) { + this._agent = agent; + } + + async decrypt(options: DecryptOptions): Promise { const { algorithm, data, keyRef } = options; // Retrieve the ManagedKey from the KMS key metadata store. const key = await this.getKey({ keyRef }); if (isManagedKey(key)) { - const privateManagedKey = await this.privateKeyStore.getKey({ id: key.id }); + const privateManagedKey = await this._privateKeyStore.getKey({ + id : key.id, + agent : this.agent + }); if (privateManagedKey !== undefined) { // Construct a CryptoKey object from the key metadata and private key material. @@ -70,14 +130,17 @@ export class LocalKms implements KeyManagementSystem { throw new Error(`Operation failed: 'decrypt'. Key not found: ${keyRef}`); } - async deriveBits(options: DeriveBitsOptions): Promise { + async deriveBits(options: DeriveBitsOptions): Promise { let { algorithm, baseKeyRef, length } = options; // Retrieve the ManagedKeyPair from the KMS key metadata store. const ownKeyPair = await this.getKey({ keyRef: baseKeyRef }); if (isManagedKeyPair(ownKeyPair)) { - const privateManagedKey = await this.privateKeyStore.getKey({ id: ownKeyPair.privateKey.id }); + const privateManagedKey = await this._privateKeyStore.getKey({ + id : ownKeyPair.privateKey.id, + agent : this.agent + }); if (privateManagedKey !== undefined) { // Construct a CryptoKey object from the key metadata and private key material. @@ -94,14 +157,17 @@ export class LocalKms implements KeyManagementSystem { throw new Error(`Operation failed: 'deriveBits'. Key not found: ${baseKeyRef}`); } - async encrypt(options: EncryptOptions): Promise { + async encrypt(options: EncryptOptions): Promise { const { algorithm, data, keyRef } = options; // Retrieve the ManagedKey from the KMS key metadata store. const key = await this.getKey({ keyRef }); if (isManagedKey(key)) { - const privateManagedKey = await this.privateKeyStore.getKey({ id: key.id }); + const privateManagedKey = await this._privateKeyStore.getKey({ + id : key.id, + agent : this.agent + }); if (privateManagedKey !== undefined) { // Construct a CryptoKey object from the key metadata and private key material. @@ -132,29 +198,37 @@ export class LocalKms implements KeyManagementSystem { let managedKeyOrKeyPair: GenerateKeyType; if (isCryptoKeyPair(cryptoKey)) { const privateKeyType = cryptoKey.privateKey.type as Web5Crypto.PrivateKeyType; - const id = await this.privateKeyStore.importKey({ key: { material: cryptoKey.privateKey.handle, type: privateKeyType} }); - const privateKey = this.toManagedKey({ ...cryptoKey.privateKey, id, alias, metadata }); - const publicKey = this.toManagedKey({ ...cryptoKey.publicKey, material: cryptoKey.publicKey.handle, id, alias, metadata }); - managedKeyOrKeyPair = { privateKey, publicKey } as GenerateKeyType; + const id = await this._privateKeyStore.importKey({ + key : { material: cryptoKey.privateKey.material, type: privateKeyType}, + agent : this.agent + }); + const managedKeyPair: ManagedKeyPair = { + privateKey : this.toManagedKey({ ...cryptoKey.privateKey, id, alias, metadata }), + publicKey : this.toManagedKey({ ...cryptoKey.publicKey, material: cryptoKey.publicKey.material, id, alias, metadata }) + }; + managedKeyOrKeyPair = managedKeyPair as GenerateKeyType; } else { const keyType = cryptoKey.type as Web5Crypto.PrivateKeyType; - const id = await this.privateKeyStore.importKey({ key: { material: cryptoKey.handle, type: keyType } }); + const id = await this._privateKeyStore.importKey({ + key : { material: cryptoKey.material, type: keyType }, + agent : this.agent + }); managedKeyOrKeyPair = this.toManagedKey({ ...cryptoKey, id, alias, metadata }) as GenerateKeyType; } // Store the ManagedKey or ManagedKeyPair in the KMS key store. - await this.keyStore.importKey({ key: managedKeyOrKeyPair }); + await this._keyStore.importKey({ key: managedKeyOrKeyPair, agent: this.agent }); return managedKeyOrKeyPair; } async getKey(options: { keyRef: string }): Promise { - const keyOrKeyPair = this.keyStore.getKey({ id: options.keyRef }); + const keyOrKeyPair = this._keyStore.getKey({ id: options.keyRef, agent: this.agent }); return keyOrKeyPair; } - async importKey(options: ImportableKeyPair): Promise; - async importKey(options: ImportableKey): Promise; + async importKey(options: PortableKeyPair): Promise; + async importKey(options: PortableKey): Promise; async importKey(options: ImportKeyOptions): Promise { if ('privateKey' in options) { @@ -164,14 +238,15 @@ export class LocalKms implements KeyManagementSystem { throw new Error(`Import failed due to private and public key mismatch`); if (!(privateKey.type === 'private' && publicKey.type === 'public')) throw new TypeError(`Out of range: '${privateKey.type}, ${publicKey.type}'. Must be 'private, public'`); - privateKey.material = Convert.bufferSource(privateKey.material).toArrayBuffer(); - publicKey.material = Convert.bufferSource(publicKey.material).toArrayBuffer(); - const id = await this.privateKeyStore.importKey({ key: { material: privateKey.material, type: privateKey.type } }); + const id = await this._privateKeyStore.importKey({ + key : { material: privateKey.material, type: privateKey.type }, + agent : this.agent + }); const managedKeyPair = { - privateKey : this.toManagedKey({ ...privateKey, material: undefined, id }), + privateKey : this.toManagedKey({ ...privateKey, id, material: undefined }), publicKey : this.toManagedKey({ ...publicKey, material: publicKey.material, id }) }; - await this.keyStore.importKey({ key: managedKeyPair }); + await this._keyStore.importKey({ key: managedKeyPair, agent: this.agent }); return managedKeyPair; } @@ -179,30 +254,33 @@ export class LocalKms implements KeyManagementSystem { switch (keyType) { case 'private': { // Asymmetric private key import. - let { material } = options; - material = Convert.bufferSource(material).toArrayBuffer(); - const id = await this.privateKeyStore.importKey({ key: { material, type: keyType } }); + const material = options.material; + const id = await this._privateKeyStore.importKey({ + key : { material, type: keyType }, + agent : this.agent + }); const privateManagedKey = this.toManagedKey({ ...options, material: undefined, id }); - await this.keyStore.importKey({ key: privateManagedKey }); + await this._keyStore.importKey({ key: privateManagedKey, agent: this.agent }); return privateManagedKey; } case 'public': { // Asymmetric public key import. - let { material } = options; - material = Convert.bufferSource(material).toArrayBuffer(); - const privateManagedKey = this.toManagedKey({ ...options, material, id: 'placeholder' }); - privateManagedKey.id = await this.keyStore.importKey({ key: privateManagedKey }); - return privateManagedKey; + const material = options.material; + const publicManagedKey = this.toManagedKey({ ...options, material, id: '' }); + publicManagedKey.id = await this._keyStore.importKey({ key: publicManagedKey, agent: this.agent }); + return publicManagedKey; } case 'secret': { // Symmetric secret key import. - let { material } = options; - material = Convert.bufferSource(material).toArrayBuffer(); - const id = await this.privateKeyStore.importKey({ key: { material, type: keyType } }); + const material = options.material; + const id = await this._privateKeyStore.importKey({ + key : { material, type: keyType }, + agent : this.agent + }); const secretManagedKey = this.toManagedKey({ ...options, material: undefined, id }); - await this.keyStore.importKey({ key: secretManagedKey }); + await this._keyStore.importKey({ key: secretManagedKey, agent: this.agent }); return secretManagedKey; } @@ -211,14 +289,17 @@ export class LocalKms implements KeyManagementSystem { } } - async sign(options: SignOptions): Promise { + async sign(options: SignOptions): Promise { const { algorithm, data, keyRef } = options; // Retrieve the ManagedKeyPair from the KMS key metadata store. const keyPair = await this.getKey({ keyRef }); if (isManagedKeyPair(keyPair)) { - const privateManagedKey = await this.privateKeyStore.getKey({ id: keyPair.privateKey.id }); + const privateManagedKey = await this._privateKeyStore.getKey({ + id : keyPair.privateKey.id, + agent : this.agent + }); if (privateManagedKey !== undefined) { // Construct a CryptoKey object from the key metadata and private key material. @@ -235,6 +316,23 @@ export class LocalKms implements KeyManagementSystem { throw new Error(`Operation failed: 'sign'. Key not found: ${keyRef}`); } + async updateKey(options: UpdateKeyOptions): Promise { + const { keyRef, alias, metadata } = options; + + const keyOrKeyPair = await this.getKey({ keyRef }); + + if (!keyOrKeyPair) { + throw new Error(`Key not found: '${keyRef}'`); + } + + const keyId = (isManagedKeyPair(keyOrKeyPair)) + ? keyOrKeyPair.publicKey.id + : keyOrKeyPair.id; + + // Update the KMS key metadata store. + return this._keyStore.updateKey({ id: keyId, alias, metadata, agent: this.agent }); + } + async verify(options: VerifyOptions): Promise { const { algorithm, data, keyRef, signature } = options; @@ -242,8 +340,14 @@ export class LocalKms implements KeyManagementSystem { const keyPair = await this.getKey({ keyRef }); if (isManagedKeyPair(keyPair)) { + if (keyPair.publicKey.material === undefined) { + throw new Error(`Required property missing: 'material'`); + } // Construct a CryptoKey object from the key metadata and private key material. - const publicCryptoKey = this.toCryptoKey({ ...keyPair.publicKey }); + const publicCryptoKey = this.toCryptoKey({ + ...keyPair.publicKey, + material: keyPair.publicKey.material + }); // Verify the signature and data. const cryptoAlgorithm = this.getAlgorithm(algorithm); @@ -257,7 +361,7 @@ export class LocalKms implements KeyManagementSystem { private getAlgorithm(algorithmIdentifier: Web5Crypto.AlgorithmIdentifier): CryptoAlgorithm { checkRequiredProperty({ property: 'name', inObject: algorithmIdentifier }); - const algorithm = this.supportedAlgorithms.get(algorithmIdentifier.name.toUpperCase()); + const algorithm = this._supportedAlgorithms.get(algorithmIdentifier.name.toUpperCase()); if (algorithm === undefined) { throw new Error(`The algorithm '${algorithmIdentifier.name}' is not supported`); @@ -270,19 +374,18 @@ export class LocalKms implements KeyManagementSystem { for (const [name, implementation] of Object.entries(cryptoAlgorithms)) { // Add the algorithm name and its implementation to the supported algorithms map, // upper-cased to allow for case-insensitive. - this.supportedAlgorithms.set(name.toUpperCase(), implementation); + this._supportedAlgorithms.set(name.toUpperCase(), implementation); } } - private toCryptoKey(managedKey: ManagedKey): Web5Crypto.CryptoKey { - if (!managedKey.material) { - throw new Error(`Required property missing: 'material'`); - } + private toCryptoKey(managedKey: + RequireOnly + ): Web5Crypto.CryptoKey { const cryptoKey: Web5Crypto.CryptoKey = { algorithm : managedKey.algorithm, extractable : managedKey.extractable, - handle : managedKey.material, + material : managedKey.material, type : managedKey.type, usages : managedKey.usages }; @@ -290,13 +393,13 @@ export class LocalKms implements KeyManagementSystem { return cryptoKey; } - private toManagedKey(options: Omit & RequireOnly): ManagedKey { + private toManagedKey(options: Omit & RequireOnly): ManagedKey { const managedKey: ManagedKey = { id : options.id, algorithm : options.algorithm, alias : options.alias, extractable : options.extractable, - kms : this.name, + kms : this._name, material : (options.type === 'public') ? options.material : undefined, metadata : options.metadata, state : 'Enabled', diff --git a/packages/agent/src/rpc-client.ts b/packages/agent/src/rpc-client.ts new file mode 100644 index 000000000..9efc2861b --- /dev/null +++ b/packages/agent/src/rpc-client.ts @@ -0,0 +1,111 @@ +import type { JsonRpcResponse } from './json-rpc.js'; +import type { DwnRpc, DwnRpcRequest, DwnRpcResponse } from './types/agent.js'; + +import { randomUuid } from '@web5/crypto/utils'; + +import { createJsonRpcRequest, parseJson } from './json-rpc.js'; + +/** + * Client used to communicate with Dwn Servers + */ +export class Web5RpcClient implements DwnRpc { + private transportClients: Map; + + constructor(clients: DwnRpc[] = []) { + this.transportClients = new Map(); + + // include http client as default. can be overwritten for 'http:' or 'https:' if instantiator provides + // their own. + clients = [new HttpDwnRpcClient(), ...clients]; + + for (let client of clients) { + for (let transportScheme of client.transportProtocols) { + this.transportClients.set(transportScheme, client); + } + } + } + + get transportProtocols(): string[] { + return Array.from(this.transportClients.keys()); + } + + sendDwnRequest(request: DwnRpcRequest): Promise { + // will throw if url is invalid + const url = new URL(request.dwnUrl); + + const transportClient = this.transportClients.get(url.protocol); + if (!transportClient) { + const error = new Error(`no ${url.protocol} transport client available`); + error.name = 'NO_TRANSPORT_CLIENT'; + + throw error; + } + + return transportClient.sendDwnRequest(request); + } +} + +// TODO: move to dwn-server repo. i wrote this here for expediency + +/** + * Http client that can be used to communicate with Dwn Servers + */ +class HttpDwnRpcClient implements DwnRpc { + get transportProtocols() { return ['http:', 'https:']; } + + async sendDwnRequest(request: DwnRpcRequest): Promise { + const requestId = randomUuid(); + const jsonRpcRequest = createJsonRpcRequest(requestId, 'dwn.processMessage', { + target : request.targetDid, + message : request.message + }); + + const fetchOpts = { + method : 'POST', + headers : { + 'dwn-request': JSON.stringify(jsonRpcRequest) + } + }; + + if (request.data) { + // @ts-expect-error TODO: REMOVE + fetchOpts.headers['content-type'] = 'application/octet-stream'; + // @ts-expect-error TODO: REMOVE + fetchOpts['body'] = request.data; + } + + const resp = await fetch(request.dwnUrl, fetchOpts); + let dwnRpcResponse: JsonRpcResponse; + + // check to see if response is in header first. if it is, that means the response is a ReadableStream + let dataStream; + const { headers } = resp; + if (headers.has('dwn-response')) { + // @ts-expect-error TODO: REMOVE + const jsonRpcResponse = parseJson(headers.get('dwn-response')) as JsonRpcResponse; + + if (jsonRpcResponse == null) { + throw new Error(`failed to parse json rpc response. dwn url: ${request.dwnUrl}`); + } + + dataStream = resp.body; + dwnRpcResponse = jsonRpcResponse; + } else { + // TODO: wonder if i need to try/catch this? + const responseBody = await resp.text(); + dwnRpcResponse = JSON.parse(responseBody); + } + + if (dwnRpcResponse.error) { + const { code, message } = dwnRpcResponse.error; + throw new Error(`(${code}) - ${message}`); + } + + const { reply } = dwnRpcResponse.result; + if (dataStream) { + reply['record']['data'] = dataStream; + } + + return reply as DwnRpcResponse; + } +} \ No newline at end of file diff --git a/packages/agent/src/store-managed-did.ts b/packages/agent/src/store-managed-did.ts new file mode 100644 index 000000000..3979191a4 --- /dev/null +++ b/packages/agent/src/store-managed-did.ts @@ -0,0 +1,294 @@ +import type { RecordsWriteMessage } from '@tbd54566975/dwn-sdk-js'; + +import { Convert } from '@web5/common'; + +import type { Web5ManagedAgent } from './types/agent.js'; +import type { ManagedDid } from './did-manager.js'; + +export interface ManagedDidStore { + deleteDid(options: { did: string, agent?: Web5ManagedAgent, context?: string }): Promise + getDid(options: { did: string, agent?: Web5ManagedAgent, context?: string }): Promise + findDid(options: { did: string, agent?: Web5ManagedAgent, context?: string }): Promise + findDid(options: { alias: string, agent?: Web5ManagedAgent, context?: string }): Promise + importDid(options: { did: ManagedDid, agent?: Web5ManagedAgent, context?: string }): Promise + listDids(options?: { agent?: Web5ManagedAgent, context?: string }): Promise +} + +/** + * + */ +export class DidStoreDwn implements ManagedDidStore { + private _didRecordProperties = { + dataFormat : 'application/json', + schema : 'https://identity.foundation/schemas/web5/managed-did' + }; + + async deleteDid(options: { + agent: Web5ManagedAgent, + context?: string, + did: string + }): Promise { + const { agent, context, did } = options; + + // Determine which DID to use to author DWN messages. + const authorDid = await this.getAuthor({ agent, context, did }); + + // Query the DWN for all stored DID objects. + const { reply: queryReply} = await agent.dwnManager.processRequest({ + author : authorDid, + target : authorDid, + messageType : 'RecordsQuery', + messageOptions : { + filter: { ...this._didRecordProperties } + } + }); + + // Loop through all of the entries and try to find a match. + let matchingRecordId: string | undefined; + for (const record of queryReply.entries ?? []) { + if (record.encodedData) { + const storedDid = Convert.base64Url(record.encodedData).toObject() as ManagedDid; + if (storedDid && storedDid.did === did) { + matchingRecordId = (record as RecordsWriteMessage).recordId ; + break; + } + } + } + + // Return undefined if the specified DID was not found in the store. + if (!matchingRecordId) return false; + + // If a record for the specified DID was found, attempt to delete it. + const { reply: { status } } = await agent.dwnManager.processRequest({ + author : authorDid, + target : authorDid, + messageType : 'RecordsDelete', + messageOptions : { + recordId: matchingRecordId + } + }); + + // If the DID was successfully deleted, return true; + if (status.code === 202) return true; + + // If the DID could not be deleted, return false; + return false; + } + + async findDid(options: { agent: Web5ManagedAgent, context?: string, did: string }): Promise; + async findDid(options: { agent: Web5ManagedAgent, context?: string, alias: string }): Promise; + async findDid(options: { agent: Web5ManagedAgent, alias: string, context?: string, did: string }): Promise { + const { agent, alias, context, did } = options; + + // Determine which DID to use to author DWN messages. + const authorDid = await this.getAuthor({ agent, context, did }); + + // Query the DWN for all stored DID objects. + const { reply: queryReply} = await agent.dwnManager.processRequest({ + author : authorDid, + target : authorDid, + messageType : 'RecordsQuery', + messageOptions : { + filter: { ...this._didRecordProperties } + } + }); + + // Loop through all of the entries and return a match, if found. + for (const record of queryReply.entries ?? []) { + if (record.encodedData) { + const storedDid = Convert.base64Url(record.encodedData).toObject() as ManagedDid; + if (storedDid && storedDid.did === did) return storedDid; + if (storedDid && storedDid.alias === alias) return storedDid; + } + } + + // Return undefined if no matches were found. + return undefined; + } + + async getDid(options: { + agent: Web5ManagedAgent, + context?: string, + did: string + }): Promise { + const { agent, context, did } = options; + + // Determine which DID to use to author DWN messages. + const authorDid = await this.getAuthor({ agent, context, did }); + + // Query the DWN for all stored DID objects. + const { reply: queryReply} = await agent.dwnManager.processRequest({ + author : authorDid, + target : authorDid, + messageType : 'RecordsQuery', + messageOptions : { filter: { ...this._didRecordProperties } } + }); + + // Loop through all of the entries and return a match, if found. + for (const record of queryReply.entries ?? []) { + if (record.encodedData) { + const storedDid = Convert.base64Url(record.encodedData).toObject() as ManagedDid; + if (storedDid && storedDid.did === did) return storedDid; + } + } + + // Return undefined if no matches were found. + return undefined; + } + + async importDid(options: { + agent: Web5ManagedAgent, + context?: string, + did: ManagedDid + }) { + const { agent, context, did: importDid } = options; + + // Determine which DID to use to author DWN messages. + const authorDid = await this.getAuthor({ agent, context, did: importDid.did }); + + // Check if the DID being imported is already present in the store. + const duplicateFound = await this.getDid({ agent, context, did: importDid.did }); + if (duplicateFound) { + throw new Error(`DidStoreDwn: DID with ID already exists: '${importDid.did}'`); + } + + // Encode the ManagedDid as bytes. + const importDidU8A = Convert.object(importDid).toUint8Array(); + + const { reply: { status } } = await agent.dwnManager.processRequest({ + author : authorDid, + target : authorDid, + messageType : 'RecordsWrite', + messageOptions : { ...this._didRecordProperties }, + dataStream : new Blob([importDidU8A]) + }); + + // If the write fails, throw an error. + if (status.code !== 202) { + throw new Error('DidStoreDwn: Failed to write imported DID to store.'); + } + } + + async listDids(options: { + agent: Web5ManagedAgent, + context?: string + }): Promise { + const { agent, context } = options; + + // Determine which DID to use to author DWN messages. + const authorDid = await this.getAuthor({ agent, context }); + + // Query the DWN for all stored DID objects. + const { reply: queryReply} = await agent.dwnManager.processRequest({ + author : authorDid, + target : authorDid, + messageType : 'RecordsQuery', + messageOptions : { + filter: { ...this._didRecordProperties } + } + }); + + // Loop through all of the entries and accumulate the DID objects. + let storedDids: ManagedDid[] = []; + for (const record of queryReply.entries ?? []) { + if (record.encodedData) { + const storedDid = Convert.base64Url(record.encodedData).toObject() as ManagedDid; + storedDids.push(storedDid); + } + } + + return storedDids; + } + + private async getAuthor(options: { + context?: string, + did?: string, + agent: Web5ManagedAgent + }): Promise { + const { context, did, agent } = options; + + // If `context` is specified, DWN messages will be signed by this DID. + if (context) return context; + + // If Agent has an agentDid, use it to sign DWN messages. + if (agent.agentDid) return agent.agentDid; + + // If `context`, `agent.agentDid`, and `did` are undefined, throw error. + if (!did) { + throw new Error(`DidStoreDwn: Agent property 'agentDid' is undefined.`); + } + + /** Lacking a context and agentDid DID, check whether KeyManager has + * a key pair for the given `did` value.*/ + const signingKeyId = await agent.didManager.getDefaultSigningKey({ did }); + const keyPair = (signingKeyId) + ? await agent.keyManager.getKey({ keyRef: signingKeyId }) + : undefined; + + // If a key pair is found, use the `did` to sign messages. + if (keyPair) return did; + + // If all else fails, throw an error. + throw new Error(`DidStoreDwn: Agent property 'agentDid' is undefined and no keys were found for: '${did}'`); + } +} + +/** + * + */ +export class DidStoreMemory implements ManagedDidStore { + /** + * A private field that contains the Map used as the in-memory key-value store. + */ + private store: Map = new Map(); + + async deleteDid({ did }: { did: string; }): Promise { + if (this.store.has(did)) { + // DID with given identifier exists so proceed with delete. + this.store.delete(did); + return true; + } + + // DID with given identifier not present so delete operation not possible. + return false; + } + + async getDid({ did }: { did: string; }): Promise { + return this.store.get(did); + } + + async findDid(options: { did: string }): Promise; + async findDid(options: { alias: string }): Promise; + async findDid(options: { alias?: string, did?: string}): Promise { + let { alias, did } = options; + + // Get DID by identifier. + if (did) return this.store.get(did); + + if (alias) { + // Search through the store to find a matching entry + for (const did of this.store.values()) { + if (did.alias === alias) return did; + } + } + + return undefined; + } + + async importDid(options: { did: ManagedDid }) { + const { did: importDid } = options; + + if (this.store.has(importDid.did)) { + // DID with given identifier already exists so import operation cannot proceed. + throw new Error(`DidStoreMemory: DID with ID already exists: '${importDid.did}'`); + } + + // Make a deep copy of the DID so that the object stored does not share the same references as the input. + const clonedDid = structuredClone(importDid); + this.store.set(importDid.did, clonedDid); + } + + async listDids(): Promise { + return Array.from(this.store.values()); + } +} \ No newline at end of file diff --git a/packages/agent/src/store-managed-identity.ts b/packages/agent/src/store-managed-identity.ts new file mode 100644 index 000000000..cfc8f9d06 --- /dev/null +++ b/packages/agent/src/store-managed-identity.ts @@ -0,0 +1,242 @@ +import { Convert } from '@web5/common'; + +import type { Web5ManagedAgent } from './types/agent.js'; +import type { ManagedIdentity } from './identity-manager.js'; +import type { RecordsWriteMessage } from '@tbd54566975/dwn-sdk-js'; + +export interface ManagedIdentityStore { + deleteIdentity(options: { did: string, agent?: Web5ManagedAgent, context?: string }): Promise + getIdentity(options: { did: string, agent?: Web5ManagedAgent, context?: string }): Promise + importIdentity(options: { identity: ManagedIdentity, agent?: Web5ManagedAgent, context?: string }): Promise + listIdentities(options?: { agent?: Web5ManagedAgent, context?: string }): Promise +} + +/** + * + */ +export class IdentityStoreDwn implements ManagedIdentityStore { + private _identityRecordProperties = { + dataFormat : 'application/json', + schema : 'https://identity.foundation/schemas/web5/managed-identity' + }; + + async deleteIdentity(options: { + agent: Web5ManagedAgent, + context?: string, + did: string + }): Promise { + const { agent, context, did } = options; + + // Determine which DID to use to author DWN messages. + const authorDid = await this.getAuthor({ agent, context, did }); + + // Query the DWN for all stored Identity objects. + const { reply: queryReply} = await agent.dwnManager.processRequest({ + author : authorDid, + target : authorDid, + messageType : 'RecordsQuery', + messageOptions : { + filter: { ...this._identityRecordProperties } + } + }); + + // Loop through all of the entries and try to find a match. + let matchingRecordId: string | undefined; + for (const record of queryReply.entries ?? []) { + if (record.encodedData) { + const storedIdentity = Convert.base64Url(record.encodedData).toObject() as ManagedIdentity; + if (storedIdentity && storedIdentity.did === did) { + matchingRecordId = (record as RecordsWriteMessage).recordId ; + break; + } + } + } + + // Return undefined if the specified Identity was not found in the store. + if (!matchingRecordId) return false; + + // If a record for the specified Identity was found, attempt to delete it. + const { reply: { status } } = await agent.dwnManager.processRequest({ + author : authorDid, + target : authorDid, + messageType : 'RecordsDelete', + messageOptions : { + recordId: matchingRecordId + } + }); + + // If the Identity was successfully deleted, return true; + if (status.code === 202) return true; + + // If the Identity could not be deleted, return false; + return false; + } + + async getIdentity(options: { + agent: Web5ManagedAgent, + context?: string, + did: string + }): Promise { + const { agent, context, did } = options; + + // Determine which DID to use to author DWN messages. + const authorDid = await this.getAuthor({ agent, context, did }); + + // Query the DWN for all stored Identity objects. + const { reply: queryReply} = await agent.dwnManager.processRequest({ + author : authorDid, + target : authorDid, + messageType : 'RecordsQuery', + messageOptions : { filter: { ...this._identityRecordProperties } } + }); + + // Loop through all of the entries and return a match, if found. + for (const record of queryReply.entries ?? []) { + if (record.encodedData) { + const storedIdentity = Convert.base64Url(record.encodedData).toObject() as ManagedIdentity; + if (storedIdentity && storedIdentity.did === did) return storedIdentity; + } + } + + // Return undefined if no matches were found. + return undefined; + } + + async importIdentity(options: { + agent: Web5ManagedAgent, + context?: string, + identity: ManagedIdentity + }) { + const { agent, context, identity } = options; + + // Determine which DID to use to author DWN messages. + const authorDid = await this.getAuthor({ agent, context, did: identity.did }); + + // Check if the Identity being imported is already present in the store. + const duplicateFound = await this.getIdentity({ agent, context, did: identity.did }); + if (duplicateFound) { + throw new Error(`IdentityStoreDwn: Identity with DID already exists: '${identity.did}'`); + } + + // Encode the ManagedIdentity as bytes. + const identityU8A = Convert.object(identity).toUint8Array(); + + const { reply: { status } } = await agent.dwnManager.processRequest({ + author : authorDid, + target : authorDid, + messageType : 'RecordsWrite', + messageOptions : { ...this._identityRecordProperties }, + dataStream : new Blob([identityU8A]) + }); + + // If the write fails, throw an error. + if (status.code !== 202) { + throw new Error('IdentityStoreDwn: Failed to write imported identity to store.'); + } + } + + async listIdentities(options: { + agent: Web5ManagedAgent, + context?: string + }): Promise { + const { agent, context } = options; + + // Determine which DID to use to author DWN messages. + const authorDid = await this.getAuthor({ agent, context }); + + // Query the DWN for all stored Identity objects. + const { reply: queryReply} = await agent.dwnManager.processRequest({ + author : authorDid, + target : authorDid, + messageType : 'RecordsQuery', + messageOptions : { + filter: { ...this._identityRecordProperties } + } + }); + + // Loop through all of the entries and accumulate the Identity objects. + let storedIdentities: ManagedIdentity[] = []; + for (const record of queryReply.entries ?? []) { + if (record.encodedData) { + const storedIdentity = Convert.base64Url(record.encodedData).toObject() as ManagedIdentity; + storedIdentities.push(storedIdentity); + } + } + + return storedIdentities; + } + + private async getAuthor(options: { + context?: string, + did?: string, + agent: Web5ManagedAgent + }): Promise { + const { context, did, agent } = options; + + // If `context` is specified, DWN messages will be signed by this DID. + if (context) return context; + + // If Agent has an agentDid, use it to sign DWN messages. + if (agent.agentDid) return agent.agentDid; + + // If `context`, `agent.agentDid`, and `did` are undefined, throw error. + if (!did) { + throw new Error(`DidStoreDwn: Agent property 'agentDid' is undefined.`); + } + + /** Lacking a context and agentDid DID, check whether KeyManager has + * a key pair for the given `did` value.*/ + const signingKeyId = await agent.didManager.getDefaultSigningKey({ did }); + const keyPair = (signingKeyId) + ? await agent.keyManager.getKey({ keyRef: signingKeyId }) + : undefined; + + // If a key pair is found, use the `did` to sign messages. + if (keyPair) return did; + + // If all else fails, throw an error. + throw new Error(`IdentityStoreDwn: Agent property 'agentDid' is undefined and no keys were found for: '${did}'`); + } +} + +/** + * + */ +export class IdentityStoreMemory implements ManagedIdentityStore { + /** + * A private field that contains the Map used as the in-memory key-value store. + */ + private store: Map = new Map(); + + async deleteIdentity({ did }: { did: string; }): Promise { + if (this.store.has(did)) { + // Identity with given DID exists so proceed with delete. + this.store.delete(did); + return true; + } + + // Identity with given DID not present so delete operation not possible. + return false; + } + + async getIdentity({ did }: { did: string; }): Promise { + return this.store.get(did); + } + + async importIdentity(options: { identity: ManagedIdentity }) { + const { identity } = options; + + if (this.store.has(identity.did)) { + // Identity with given identifier already exists so import operation cannot proceed. + throw new Error(`IdentityStoreMemory: Identity with DID already exists: '${identity.did}'`); + } + + // Make a deep copy of the Identity so that the object stored does not share the same references as the input. + const clonedIdentity = structuredClone(identity); + this.store.set(identity.did, clonedIdentity); + } + + async listIdentities(): Promise { + return Array.from(this.store.values()); + } +} \ No newline at end of file diff --git a/packages/agent/src/store-managed-key.ts b/packages/agent/src/store-managed-key.ts new file mode 100644 index 000000000..696e7bb7c --- /dev/null +++ b/packages/agent/src/store-managed-key.ts @@ -0,0 +1,739 @@ +import type { RecordsWriteMessage, RecordsWriteOptions } from '@tbd54566975/dwn-sdk-js'; + +import { randomUuid } from '@web5/crypto/utils'; +import { Convert, removeEmptyObjects, removeUndefinedProperties } from '@web5/common'; + +import type { ManagedKeyPair, ManagedKeyStore, ManagedPrivateKey } from './types/managed-key.js'; + +import { DwnResponse, Web5ManagedAgent } from './types/agent.js'; +import { isManagedKeyPair } from './utils.js'; +import { ManagedKey } from './types/managed-key.js'; + +type EncodedPrivateKey = Omit & { + // Key material, encoded as Base64Url. + material: string; +} + +type EncodedKey = Omit & { + // Key material, encoded as Base64Url. + material?: string; +} + +type EncodedKeyPair = { + privateKey: EncodedKey; + publicKey: EncodedKey; +} + +/** + * An implementation of `ManagedKeyStore` that stores key metadata and + * public key material in a DWN. + * + * An instance of this class can be used by `KeyManager` or + * an implementation of `KeyManagementSystem`. + */ +export class KeyStoreDwn implements ManagedKeyStore { + private _keyRecordProperties = { + dataFormat : 'application/json', + schema : 'https://identity.foundation/schemas/web5/managed-key' + }; + + constructor(options?: { schema: string }) { + const { schema } = options ?? {}; + if (schema) { + this._keyRecordProperties.schema = schema; + } + } + + async deleteKey(options: { + agent: Web5ManagedAgent, + context?: string, + id: string + }): Promise { + const { agent, context, id } = options; + + // Determine which DID to use to author DWN messages. + const authorDid = await this.getAuthor({ agent, context }); + + // Query the DWN for all stored key objects. + const { reply: queryReply} = await this.getKeyRecords(agent, context); + + // Loop through all of the entries and try to find a match. + let matchingRecordId: string | undefined; + for (const record of queryReply.entries ?? []) { + if (record.encodedData) { + const storedKey = this.decodeKey(record.encodedData); + const storedKeyId = isManagedKeyPair(storedKey) ? storedKey.publicKey.id : storedKey.id; + if (storedKey && storedKeyId === id) { + matchingRecordId = (record as RecordsWriteMessage).recordId ; + break; + } + } + } + + // Return undefined if the specified key was not found in the store. + if (!matchingRecordId) return false; + + // If a record for the specified key was found, attempt to delete it. + const { reply: { status } } = await agent.dwnManager.processRequest({ + author : authorDid, + target : authorDid, + messageType : 'RecordsDelete', + messageOptions : { + recordId: matchingRecordId + } + }); + + // If the key was successfully deleted, return true; + if (status.code === 202) return true; + + // If the key could not be deleted, return false; + return false; + } + + async findKey(options: { id: string, agent: Web5ManagedAgent, context?: string }): Promise; + async findKey(options: { alias: string, agent: Web5ManagedAgent, context?: string }): Promise; + async findKey(options: { agent: Web5ManagedAgent, alias?: string, context?: string, id?: string }): Promise { + const { agent, alias, context, id } = options; + + // Query the DWN for all stored managed key objects. + const { reply: queryReply} = await this.getKeyRecords(agent, context); + + // Loop through all of the entries and return a match, if found. + for (const record of queryReply.entries ?? []) { + if (record.encodedData) { + const storedKey = this.decodeKey(record.encodedData); + if (isManagedKeyPair(storedKey)) { + if (storedKey.publicKey.id === id) return storedKey; + if (storedKey.publicKey.alias === alias) return storedKey; + } else { + if (storedKey.id === id) return storedKey; + if (storedKey.alias === alias) return storedKey; + } + } + } + + // Return undefined if no matches were found. + return undefined; + } + + async getKey(options: { + agent: Web5ManagedAgent, + context?: string, + id: string + }): Promise { + const { agent, context, id } = options; + + // Query the DWN for all stored managed key objects. + const { reply: queryReply} = await this.getKeyRecords(agent, context); + + // Loop through all of the entries and return a match, if found. + for (const record of queryReply.entries ?? []) { + if (record.encodedData) { + const storedKey = this.decodeKey(record.encodedData); + const storedKeyId = isManagedKeyPair(storedKey) ? storedKey.publicKey.id : storedKey.id; + if (storedKeyId === id) return storedKey; + } + } + + // Return undefined if no matches were found. + return undefined; + } + + async importKey(options: { + agent: Web5ManagedAgent, + context?: string, + key: ManagedKey | ManagedKeyPair + }): Promise { + const { agent, context, key } = options; + + let keyId: string; + if (isManagedKeyPair(key)) { + keyId = key.publicKey.id; + } else { + // If an ID wasn't specified, generate one. + if (!key.id) { + key.id = randomUuid(); + } + keyId = key.id; + } + + // Determine which DID to use to author DWN messages. + const authorDid = await this.getAuthor({ agent, context }); + + // Check if the key being imported is already present in the store. + const duplicateFound = await this.getKey({ agent, context, id: keyId }); + if (duplicateFound) { + throw new Error(`KeyStoreDwn: Key with ID already exists: '${keyId}'`); + } + + // Encode the managed key or key pair as bytes. + const encodedKey = this.encodeKey(key); + + const { reply: { status } } = await agent.dwnManager.processRequest({ + author : authorDid, + target : authorDid, + messageType : 'RecordsWrite', + messageOptions : { ...this._keyRecordProperties }, + dataStream : new Blob([encodedKey]) + }); + + // If the write fails, throw an error. + if (status.code !== 202) { + throw new Error('DidStoreDwn: Failed to write imported DID to store.'); + } + + return keyId; + } + + async listKeys(options: { + agent: Web5ManagedAgent, + context?: string + }): Promise<(ManagedKey | ManagedKeyPair)[]> { + const { agent, context } = options; + + // Query the DWN for all stored managed key objects. + const { reply: queryReply} = await this.getKeyRecords(agent, context); + + // Loop through all of the entries and accumulate the key objects. + let storedKeys: (ManagedKey | ManagedKeyPair)[] = []; + for (const record of queryReply.entries ?? []) { + if (record.encodedData) { + const storedKey = this.decodeKey(record.encodedData); + storedKeys.push(storedKey); + } + } + + return storedKeys; + } + + async updateKey(options: { + agent: Web5ManagedAgent, + context?: string + } & Pick): Promise { + const { agent, context, id } = options; + const propertyUpdates = { alias: options.alias, metadata: options.metadata }; + + // Determine which DID to use to author DWN messages. + const authorDid = await this.getAuthor({ agent, context }); + + // Query the DWN for all stored managed key objects. + const { reply: queryReply} = await this.getKeyRecords(agent, context); + + // Confirm the key being updated is already present in the store. + let keyToUpdate: ManagedKey | ManagedKeyPair | undefined; + let recordToUpdate: RecordsWriteMessage | undefined; + for (const entry of queryReply.entries ?? []) { + const { encodedData, ...record } = entry; + if (encodedData) { + const storedKey = this.decodeKey(encodedData); + const storedKeyId = isManagedKeyPair(storedKey) ? storedKey.publicKey.id : storedKey.id; + if (storedKey && storedKeyId === id) { + keyToUpdate = storedKey; + recordToUpdate = record as RecordsWriteMessage ; + break; + } + } + } + + // Key with given ID not present so update operation cannot proceed. + if (!recordToUpdate || !keyToUpdate) return false; + + // Make a deep copy of the update properties to ensure all nested objects do not share references. + removeUndefinedProperties(propertyUpdates); + removeEmptyObjects(propertyUpdates); + const clonedUpdates = structuredClone(propertyUpdates); + + // Update the given properties of the key. + if (isManagedKeyPair(keyToUpdate)) { + keyToUpdate.privateKey = { ...keyToUpdate.privateKey, ...clonedUpdates }; + keyToUpdate.publicKey = { ...keyToUpdate.publicKey, ...clonedUpdates }; + } else { + keyToUpdate = { ...keyToUpdate, ...clonedUpdates }; + } + + // Encode the updated key or key pair as bytes. + const updatedKeyBytes = this.encodeKey(keyToUpdate); + + // Assemble the update messsage, including record ID and context ID, if any. + let messageOptions = { ...recordToUpdate.descriptor } as Partial; + messageOptions.contextId = recordToUpdate.contextId; + messageOptions.recordId = recordToUpdate.recordId; + + /** Remove properties from the update messageOptions to let the DWN SDK + * auto-fill. Otherwisse, you will get 409 Conflict errors. */ + delete messageOptions.dataCid; + delete messageOptions.dataSize; + delete messageOptions.data; + delete messageOptions.messageTimestamp; + + // Overwrite the entry in the store with the updated object. + const { reply: { status } } = await agent.dwnManager.processRequest({ + author : authorDid, + target : authorDid, + messageType : 'RecordsWrite', + messageOptions, + dataStream : new Blob([updatedKeyBytes]) + }); + + // If the write fails, throw an error. + if (status.code !== 202) { + throw new Error('DidStoreDwn: Failed to write updated key to store.'); + } + + return true; + } + + private decodeKey(keyEncodedData: string): ManagedKey | ManagedKeyPair { + const encodedKey = Convert.base64Url(keyEncodedData).toObject() as EncodedKey | EncodedKeyPair; + + if ('publicKey' in encodedKey) { + const privateKeyMaterial = encodedKey.privateKey.material + ? Convert.base64Url(encodedKey.privateKey.material).toUint8Array() + : undefined; + + const publicKeyMaterial = encodedKey.publicKey.material + ? Convert.base64Url(encodedKey.publicKey.material).toUint8Array() + : undefined; + + const managedKeyPair = { + privateKey : { ...encodedKey.privateKey, material: privateKeyMaterial }, + publicKey : { ...encodedKey.publicKey, material: publicKeyMaterial} + } as ManagedKeyPair; + + return managedKeyPair; + + } else { + const material = encodedKey.material + ? Convert.base64Url(encodedKey.material).toUint8Array() + : undefined; + + const managedKey = { ...encodedKey, material } as ManagedKey; + + return managedKey; + } + } + + private encodeKey(managedKey: ManagedKey | ManagedKeyPair): Uint8Array { + let encodedKey: EncodedKey | EncodedKeyPair; + + if (isManagedKeyPair(managedKey)) { + const privateKeyMaterial = managedKey.privateKey.material + ? Convert.uint8Array(managedKey.privateKey.material).toBase64Url() + : undefined; + + const publicKeyMaterial = managedKey.publicKey.material + ? Convert.uint8Array(managedKey.publicKey.material).toBase64Url() + : undefined; + + encodedKey = { + privateKey : { ...managedKey.privateKey, material: privateKeyMaterial }, + publicKey : { ...managedKey.publicKey, material: publicKeyMaterial } + }; + + } else { + const material = managedKey.material + ? Convert.uint8Array(managedKey.material).toBase64Url() + : undefined; + + encodedKey = { ...managedKey, material }; + } + + const keyBytes = Convert.object(encodedKey).toUint8Array(); + + return keyBytes; + } + + private async getAuthor(options: { + agent: Web5ManagedAgent, + context?: string + }): Promise { + const { agent, context } = options; + + // If `context` is specified, DWN messages will be signed by this DID. + if (context) return context; + + // If Agent has an agentDid, use it to sign DWN messages. + if (agent.agentDid) return agent.agentDid; + + // If `context` and `agent.agentDid`are undefined, throw error. + throw new Error(`KeyStoreDwn: Agent property 'agentDid' is undefined and no context was specified.`); + } + + private async getKeyRecords(agent: Web5ManagedAgent, context?: string): Promise { + // Determine which DID to use to author DWN messages. + const authorDid = await this.getAuthor({ agent, context }); + + const dwnResponse = await agent.dwnManager.processRequest({ + author : authorDid, + target : authorDid, + messageType : 'RecordsQuery', + messageOptions : { + filter: { ...this._keyRecordProperties } + } + }); + + return dwnResponse; + } +} + +/** + * An implementation of `ManagedKeyStore` that stores key metadata and + * public key material in memory. + * + * An instance of this class can be used by `KeyManager` or + * an implementation of `KeyManagementSystem`. + */ +export class KeyStoreMemory implements ManagedKeyStore { + /** + * A private field that contains the Map used as the in-memory key-value store. + */ + private store: Map = new Map(); + + async deleteKey({ id }: { id: string }): Promise { + if (this.store.has(id)) { + // Key with given ID exists so proceed with delete. + this.store.delete(id); + return true; + } + + // Key with given ID not present so delete operation not possible. + return false; + } + + async findKey(options: { id: string }): Promise; + async findKey(options: { alias: string }): Promise; + async findKey(options: { alias?: string, id?: string }): Promise { + let { alias, id } = options; + + // Get key by ID. + if (id) return this.store.get(id); + + if (alias) { + // Search through the store to find a matching entry. + for (const key of await this.listKeys()) { + if ('alias' in key && key.alias === alias) return key; + if ('publicKey' in key && key.publicKey.alias === alias) return key; + } + } + + return undefined; + } + + async getKey({ id }: { id: string }): Promise { + return this.store.get(id); + } + + async importKey({ key }: { key: ManagedKey | ManagedKeyPair }): Promise { + let id: string; + if (isManagedKeyPair(key)) { + id = key.publicKey.id; + } else { + // If an ID wasn't specified, generate one. + if (!key.id) { + key.id = randomUuid(); + } + id = key.id; + } + + if (this.store.has(id)) { + // Key with given ID already exists so import operation cannot proceed. + throw new Error(`KeyStoreMemory: Key with ID already exists: '${id}'`); + } + + // Make a deep copy of the key so that the object stored does not share the same references as the input key. + const clonedKey = structuredClone(key); + this.store.set(id, clonedKey); + + return id; + } + + async listKeys(): Promise<(ManagedKey | ManagedKeyPair)[]> { + return Array.from(this.store.values()); + } + + async updateKey(options: + Pick + ): Promise { + const id = options.id; + const propertyUpdates = { alias: options.alias, metadata: options.metadata }; + + const keyExists = this.store.has(id); + if (!keyExists) { + // Key with given ID not present so update operation cannot proceed. + return false; + } + + // Retrieve the current value of the key from the store. + let key = await this.getKey({ id }) as ManagedKey | ManagedKeyPair; + + // Make a deep copy of the update properties to ensure all nested objects do not share references. + removeUndefinedProperties(propertyUpdates); + removeEmptyObjects(propertyUpdates); + const clonedUpdates = structuredClone(propertyUpdates); + + // Update the given properties of the key. + if (isManagedKeyPair(key)) { + key.privateKey = { ...key.privateKey, ...clonedUpdates }; + key.publicKey = { ...key.publicKey, ...clonedUpdates }; + } else { + key = { ...key, ...clonedUpdates, id: key.id }; + } + + // Overwrite the entry in the store with the updated object. + this.store.set(id, key); + + return true; + } +} + +/** + * An implementation of `ManagedKeyStore` that stores private key + * material in a DWN. + * + * An instance of this class can be used by an implementation of + * `KeyManagementSystem`. + */ +export class PrivateKeyStoreDwn implements ManagedKeyStore { + private _keyRecordProperties = { + dataFormat : 'application/json', + schema : 'https://identity.foundation/schemas/web5/kms-private-key' + }; + + async deleteKey(options: { + agent: Web5ManagedAgent, + context?: string, + id: string + }): Promise { + const { agent, context, id } = options; + + // Determine which DID to use to author DWN messages. + const authorDid = await this.getAuthor({ agent, context }); + + // Query the DWN for all stored key objects. + const { reply: queryReply} = await this.getKeyRecords(agent, context); + + // Loop through all of the entries and try to find a match. + let matchingRecordId: string | undefined; + for (const record of queryReply.entries ?? []) { + if (record.encodedData) { + const storedKey = this.decodeKey(record.encodedData); + if (storedKey && storedKey.id === id) { + matchingRecordId = (record as RecordsWriteMessage).recordId ; + break; + } + } + } + + // Return undefined if the specified key was not found in the store. + if (!matchingRecordId) return false; + + // If a record for the specified key was found, attempt to delete it. + const { reply: { status } } = await agent.dwnManager.processRequest({ + author : authorDid, + target : authorDid, + messageType : 'RecordsDelete', + messageOptions : { + recordId: matchingRecordId + } + }); + + // If the key was successfully deleted, return true; + if (status.code === 202) return true; + + // If the key could not be deleted, return false; + return false; + } + + async findKey(): Promise { + throw new Error(`PrivateKeyStoreDwn: Method not implemented: 'findKey'`); + } + + async getKey(options: { + agent: Web5ManagedAgent, + context?: string, + id: string + }): Promise { + const { agent, context, id } = options; + + // Query the DWN for all stored key objects. + const { reply: queryReply} = await this.getKeyRecords(agent, context); + + // Loop through all of the entries and return a match, if found. + for (const record of queryReply.entries ?? []) { + if (record.encodedData) { + const storedKey = this.decodeKey(record.encodedData); + if (storedKey.id === id) return storedKey; + } + } + + // Return undefined if no matches were found. + return undefined; + } + + async importKey(options: { + agent: Web5ManagedAgent, + context?: string, + key: Omit + }): Promise { + const { agent, context, key } = options; + + if (!key.material) throw new TypeError(`Required parameter missing: 'material'`); + if (!key.type) throw new TypeError(`Required parameter missing: 'type'`); + + // Determine which DID to use to author DWN messages. + const authorDid = await this.getAuthor({ agent, context }); + + // Encode the managed key or key pair as bytes. + const id = randomUuid(); // Generate a random ID. + const encodedPrivateKey = this.encodeKey({...key, id }); + + const { reply: { status } } = await agent.dwnManager.processRequest({ + author : authorDid, + target : authorDid, + messageType : 'RecordsWrite', + messageOptions : { ...this._keyRecordProperties }, + dataStream : new Blob([encodedPrivateKey]) + }); + + // If the write fails, throw an error. + if (status.code !== 202) { + throw new Error('PrivateKeyStoreDwn: Failed to write imported DID to store.'); + } + + return id; + } + + async listKeys(options: { + agent: Web5ManagedAgent, + context?: string + }): Promise { + const { agent, context } = options; + + // Query the DWN for all stored key objects. + const { reply: queryReply} = await this.getKeyRecords(agent, context); + + // Loop through all of the entries and accumulate the key objects. + let storedKeys: ManagedPrivateKey[] = []; + for (const record of queryReply.entries ?? []) { + if (record.encodedData) { + const storedKey = this.decodeKey(record.encodedData); + storedKeys.push(storedKey); + } + } + + return storedKeys; + } + + async updateKey(): Promise { + throw new Error(`PrivateKeyStoreMemory: Method not implemented: 'updateKey'`); + } + + private decodeKey(keyEncodedData: string): ManagedPrivateKey { + const encodedKey = Convert.base64Url(keyEncodedData).toObject() as EncodedPrivateKey; + + const privateKey = { + ...encodedKey, + material: Convert.base64Url(encodedKey.material).toUint8Array() + } as ManagedPrivateKey; + + return privateKey; + } + + private encodeKey(privateKey: ManagedPrivateKey): Uint8Array { + const encodedKey = { + ...privateKey, + material: Convert.uint8Array(privateKey.material).toBase64Url() + } as EncodedPrivateKey; + + const keyBytes = Convert.object(encodedKey).toUint8Array(); + + return keyBytes; + } + + private async getAuthor(options: { + agent: Web5ManagedAgent, + context?: string + }): Promise { + const { agent, context } = options; + + // If `context` is specified, DWN messages will be signed by this DID. + if (context) return context; + + // If Agent has an agentDid, use it to sign DWN messages. + if (agent.agentDid) return agent.agentDid; + + // If `context` and `agent.agentDid`are undefined, throw error. + throw new Error(`PrivateKeyStoreDwn: Agent property 'agentDid' is undefined and no context was specified.`); + } + + private async getKeyRecords(agent: Web5ManagedAgent, context?: string): Promise { + // Determine which DID to use to author DWN messages. + const authorDid = await this.getAuthor({ agent, context }); + + const dwnResponse = await agent.dwnManager.processRequest({ + author : authorDid, + target : authorDid, + messageType : 'RecordsQuery', + messageOptions : { + filter: { ...this._keyRecordProperties } + } + }); + + return dwnResponse; + } +} + +/** + * An implementation of `ManagedKeyStore` that stores private key + * material in memory. + * + * An instance of this class can be used by an implementation of + * `KeyManagementSystem`. + */ +export class PrivateKeyStoreMemory implements ManagedKeyStore { + /** + * A private field that contains the Map used as the in-memory key-value store. + */ + private store: Map = new Map(); + + async deleteKey({ id }: { id: string }): Promise { + if (this.store.has(id)) { + // Key with given ID exists so proceed with delete. + this.store.delete(id); + return true; + } + + // Key with given ID not present so delete operation not possible. + return false; + } + + async findKey(): Promise { + throw new Error(`PrivateKeyStoreMemory: Method not implemented: 'findKey'`); + } + + async getKey({ id }: { id: string }): Promise { + return this.store.get(id); + } + + async importKey({ key }: { key: Omit }): Promise { + if (!key.material) throw new TypeError(`Required parameter missing: 'material'`); + if (!key.type) throw new TypeError(`Required parameter missing: 'type'`); + + // Make a deep copy of the key so that the object stored does not share the same references as the input key. + // The private key material is transferred to the new object, making the original obj.material unusable. + const clonedKey = structuredClone(key, { transfer: [key.material.buffer] }) as ManagedPrivateKey; + + clonedKey.id = randomUuid(); + this.store.set(clonedKey.id, clonedKey); + + return clonedKey.id; + } + + async listKeys(): Promise { + return Array.from(this.store.values()); + } + + async updateKey(): Promise { + throw new Error(`PrivateKeyStoreMemory: Method not implemented: 'updateKey'`); + } +} \ No newline at end of file diff --git a/packages/agent/src/test-managed-agent.ts b/packages/agent/src/test-managed-agent.ts new file mode 100644 index 000000000..5b8651e43 --- /dev/null +++ b/packages/agent/src/test-managed-agent.ts @@ -0,0 +1,287 @@ +import type { KeyValueStore } from '@web5/common'; +import type { DidResolutionResult, DidResolverCache, PortableDid } from '@web5/dids'; + +import { Jose } from '@web5/crypto'; +import { Dwn } from '@tbd54566975/dwn-sdk-js'; +import { LevelStore, MemoryStore } from '@web5/common'; +import { DidIonMethod, DidKeyMethod, DidResolver, DidResolverCacheLevel } from '@web5/dids'; +import { MessageStoreLevel, DataStoreLevel, EventLogLevel } from '@tbd54566975/dwn-sdk-js/stores'; + +import type { Web5ManagedAgent } from './types/agent.js'; + +import { LocalKms } from './kms-local.js'; +import { DidManager } from './did-manager.js'; +import { DwnManager } from './dwn-manager.js'; +import { KeyManager } from './key-manager.js'; +import { Web5RpcClient } from './rpc-client.js'; +import { AppDataVault } from './app-data-store.js'; +import { cryptoToPortableKeyPair } from './utils.js'; +import { DidStoreDwn, DidStoreMemory } from './store-managed-did.js'; +import { IdentityManager, ManagedIdentity } from './identity-manager.js'; +import { IdentityStoreDwn, IdentityStoreMemory } from './store-managed-identity.js'; +import { KeyStoreDwn, KeyStoreMemory, PrivateKeyStoreDwn, PrivateKeyStoreMemory } from './store-managed-key.js'; + +type CreateMethodOptions = { + agentClass: new (options: any) => Web5ManagedAgent + agentStores?: 'dwn' | 'memory'; + testDataLocation?: string; +} + +type TestManagedAgentOptions = { + agent: Web5ManagedAgent + + agentStores: 'dwn' | 'memory'; + appDataStore: KeyValueStore; + didResolverCache: DidResolverCache; + dwn: Dwn; + dwnDataStore: DataStoreLevel; + dwnEventLog: EventLogLevel; + dwnMessageStore: MessageStoreLevel; +} + +export class TestManagedAgent { + agent: Web5ManagedAgent; + + agentStores: 'dwn' | 'memory'; + appDataStore: KeyValueStore; + didResolverCache: DidResolverCache; + dwn: Dwn; + dwnDataStore: DataStoreLevel; + dwnEventLog: EventLogLevel; + dwnMessageStore: MessageStoreLevel; + + constructor(options: TestManagedAgentOptions) { + this.agent = options.agent; + this.agentStores = options.agentStores; + this.appDataStore = options.appDataStore; + this.didResolverCache = options.didResolverCache; + this.dwn = options.dwn; + this.dwnDataStore = options.dwnDataStore; + this.dwnEventLog = options.dwnEventLog; + this.dwnMessageStore = options.dwnMessageStore; + } + + async clearStorage(): Promise { + this.agent.agentDid = undefined; + await this.appDataStore.clear(); + await this.didResolverCache.clear(); + await this.dwnDataStore.clear(); + await this.dwnEventLog.clear(); + await this.dwnMessageStore.clear(); + + /** Easiest way to start with fresh in-memory stores is to + * re-instantiate all of the managed agent components */ + if (this.agentStores === 'memory') { + const { didManager, identityManager, keyManager } = TestManagedAgent.useMemoryStorage({ agent: this.agent }); + this.agent.didManager = didManager; + this.agent.identityManager = identityManager; + this.agent.keyManager = keyManager; + } + } + + async closeStorage(): Promise { + await this.appDataStore.close(); + await this.didResolverCache.close(); + await this.dwnDataStore.close(); + await this.dwnEventLog.close(); + await this.dwnMessageStore.close(); + } + + static async create(options: CreateMethodOptions): Promise { + let { agentClass, agentStores, testDataLocation } = options; + + agentStores ??= 'memory'; + testDataLocation ??= '__TESTDATA__'; + const testDataPath = (path: string) => `${testDataLocation}/${path}`; + + const { appData, appDataStore, didManager, didResolverCache, identityManager, keyManager } = (agentStores === 'memory') + ? TestManagedAgent.useMemoryStorage() + : TestManagedAgent.useDiskStorage({ testDataLocation }); + + // Instantiate DID resolver. + const didMethodApis = [DidIonMethod, DidKeyMethod]; + const didResolver = new DidResolver({ + cache : didResolverCache, + didResolvers : didMethodApis + }); + + // Instantiate custom stores to use with DWN instance. + const dwnDataStore = new DataStoreLevel({ blockstoreLocation: testDataPath('DWN_DATASTORE') }); + const dwnEventLog = new EventLogLevel({ location: testDataPath('DWN_EVENTLOG') }); + const dwnMessageStore = new MessageStoreLevel({ + blockstoreLocation : testDataPath('DWN_MESSAGESTORE'), + indexLocation : testDataPath('DWN_MESSAGEINDEX') + }); + + // Instantiate custom DWN instance. + const dwn = await Dwn.create({ + eventLog : dwnEventLog, + dataStore : dwnDataStore, + // @ts-expect-error because the Web5.js DidResolver implementation doesn't have the dump() method. + didResolver : didResolver, + messageStore : dwnMessageStore + }); + + // Instantiate a DwnManager using the custom DWN instance. + const dwnManager = new DwnManager({ dwn }); + + // Instantiate an RPC Client. + const rpcClient = new Web5RpcClient(); + + const agent = new agentClass({ + agentDid: '', + appData, + didManager, + didResolver, + dwnManager, + identityManager, + keyManager, + rpcClient, + }); + + return new TestManagedAgent({ + agent, + agentStores, + appDataStore, + didResolverCache, + dwn, + dwnDataStore, + dwnEventLog, + dwnMessageStore, + }); + } + + async createAgentDid(): Promise { + // Create an a DID and key set for the Agent. + const agentDid = await DidKeyMethod.create({ keyAlgorithm: 'Ed25519' }); + const privateCryptoKey = await Jose.jwkToCryptoKey({ key: agentDid.keySet.verificationMethodKeys![0].privateKeyJwk! }); + const publicCryptoKey = await Jose.jwkToCryptoKey({ key: agentDid.keySet.verificationMethodKeys![0].publicKeyJwk! }); + const agentSigningKey = { privateKey: privateCryptoKey, publicKey: publicCryptoKey }; + + // Set the DID as the default signing key. + const alias = await this.agent.didManager.getDefaultSigningKey({ did: agentDid.did }); + const defaultSigningKey = cryptoToPortableKeyPair({ cryptoKeyPair: agentSigningKey, keyData: { alias, kms: 'memory' } }); + await this.agent.keyManager.setDefaultSigningKey({ key: defaultSigningKey }); + + // Set the DID as the Agent's DID. + this.agent.agentDid = agentDid.did; + } + + public async createIdentity(options: { + keyAlgorithm?: 'Ed25519' | 'secp256k1'; + testDwnUrls: string[] + }): Promise<{ did: PortableDid, identity: ManagedIdentity }> { + // Default to generating Ed25519 keys. + const { keyAlgorithm, testDwnUrls } = options; + + const didOptions = await DidIonMethod.generateDwnOptions({ + signingKeyAlgorithm : keyAlgorithm, + serviceEndpointNodes : testDwnUrls + }); + + // Create a PortableDid. + const did = await DidIonMethod.create({ + anchor: false, + ...didOptions + }); + + // Create a ManagedIdentity. + const identity: ManagedIdentity = { + did : did.did, + name : 'Test' + }; + + return { did, identity }; + } + + private static useDiskStorage(options: { agent?: Web5ManagedAgent, testDataLocation: string }) { + const { agent, testDataLocation } = options; + const testDataPath = (path: string) => `${testDataLocation}/${path}`; + + const appDataStore = new LevelStore(testDataPath('APPDATA')); + const appData = new AppDataVault({ + keyDerivationWorkFactor : 1, + store : appDataStore + }); + + const didManager = new DidManager({ + agent, + didMethods : [DidIonMethod, DidKeyMethod], + store : new DidStoreDwn() + }); + + const didResolverCache = new DidResolverCacheLevel({ + location: testDataPath('DID_RESOLVERCACHE') + }); + + const identityManager = new IdentityManager({ + agent, + store: new IdentityStoreDwn() + }); + + const localKmsDwn = new LocalKms({ + agent, + kmsName : 'local', + keyStore : new KeyStoreDwn({ schema: 'https://identity.foundation/schemas/web5/kms-key' }), + privateKeyStore : new PrivateKeyStoreDwn() + }); + const localKmsMemory = new LocalKms({ + agent, + kmsName: 'memory' + }); + const keyManager = new KeyManager({ + agent, + kms: { + local : localKmsDwn, + memory : localKmsMemory + }, + store: new KeyStoreDwn({ schema: 'https://identity.foundation/schemas/web5/managed-key' }) + }); + + return { appData, appDataStore, didManager, didResolverCache, identityManager, keyManager }; + } + + private static useMemoryStorage(options?: { agent: Web5ManagedAgent }) { + const { agent } = options ?? {}; + + const appDataStore = new MemoryStore(); + const appData = new AppDataVault({ + keyDerivationWorkFactor : 1, + store : appDataStore + }); + + const didManager = new DidManager({ + agent, + didMethods : [DidIonMethod, DidKeyMethod], + store : new DidStoreMemory() + }); + + const didResolverCache = new MemoryStore(); + + const identityManager = new IdentityManager({ + agent, + store: new IdentityStoreMemory() + }); + + const localKmsDwn = new LocalKms({ + agent, + kmsName : 'local', + keyStore : new KeyStoreMemory(), + privateKeyStore : new PrivateKeyStoreMemory() + }); + const localKmsMemory = new LocalKms({ + agent, + kmsName: 'memory' + }); + const keyManager = new KeyManager({ + agent, + kms: { + local : localKmsDwn, + memory : localKmsMemory + }, + store: new KeyStoreMemory() + }); + + return { appData, appDataStore, didManager, didResolverCache, identityManager, keyManager }; + } +} \ No newline at end of file diff --git a/packages/agent/src/types/agent.ts b/packages/agent/src/types/agent.ts new file mode 100644 index 000000000..47c01085e --- /dev/null +++ b/packages/agent/src/types/agent.ts @@ -0,0 +1,148 @@ +import type { Readable } from 'readable-stream'; +import type { + EventsGetMessage, + UnionMessageReply, + MessagesGetMessage, + RecordsQueryMessage, + RecordsWriteMessage, + RecordsDeleteMessage, + ProtocolsQueryMessage, + ProtocolsConfigureMessage, +} from '@tbd54566975/dwn-sdk-js'; + +import { DidResolver } from '@web5/dids'; + +import { DidManager } from '../did-manager.js'; +import { DwnManager } from '../dwn-manager.js'; +import { KeyManager } from '../key-manager.js'; +import { AppDataStore } from '../app-data-store.js'; +import { IdentityManager } from '../identity-manager.js'; + +/** + * DID Types + */ + +export type ProcessDidRequest = { /** empty */ } +export type SendDidRequest = { /** empty */ } +export type DidResponse = { /** empty */ } + +/** + * DWN Types + */ +export type DwnMessages = { + 'EventsGet': EventsGetMessage; + 'MessagesGet': MessagesGetMessage; + 'RecordsWrite': RecordsWriteMessage; + 'RecordsQuery': RecordsQueryMessage; + 'RecordsDelete': RecordsDeleteMessage; + 'ProtocolsQuery': ProtocolsQueryMessage; + 'ProtocolsConfigure': ProtocolsConfigureMessage; +}; + +export type DwnMessageType = keyof DwnMessages; + +export type DwnRequest = { + author: string; + target: string; + messageType: string; +} + +/** + * TODO: add JSDoc + */ +export type ProcessDwnRequest = DwnRequest & { + dataStream?: Blob | ReadableStream | Readable; + messageOptions: unknown; + store?: boolean; +}; + +export type SendDwnRequest = DwnRequest & (ProcessDwnRequest | { messageCid: string }) + +/** + * TODO: add JSDoc + */ +export type DwnResponse = { + message?: unknown; + messageCid?: string; + reply: UnionMessageReply; +}; + +/** + * TODO: add JSDoc + */ +export type SendDwnResponse = DwnRpcResponse; + +export interface SerializableDwnMessage { + toJSON(): string; +} + + +// TODO: move what's below to dwn-server repo. i wrote this here for expediency + +/** + * interface that can be implemented to communicate with Dwn Servers + */ +export interface DwnRpc { + /** + * TODO: add jsdoc + */ + get transportProtocols(): string[] + + /** + * TODO: add jsdoc + * @param request + */ + sendDwnRequest(request: DwnRpcRequest): Promise +} + +/** + * TODO: add jsdoc + */ +export type DwnRpcRequest = { + data?: any; + dwnUrl: string; + message: SerializableDwnMessage | any; + targetDid: string; +} + +/** + * TODO: add jsdoc + */ +export type DwnRpcResponse = UnionMessageReply; + + +/** + * Verifiable Credential Types + */ + +export type ProcessVcRequest = { /** empty */ } +export type SendVcRequest = { /** empty */ } +export type VcResponse = { /** empty */ } + +/** + * Web5 Agent Types + */ +export interface Web5Agent { + agentDid: string | undefined; + + processDidRequest(request: ProcessDidRequest): Promise + sendDidRequest(request: SendDidRequest): Promise; + processDwnRequest(request: ProcessDwnRequest): Promise + sendDwnRequest(request: SendDwnRequest): Promise; + processVcRequest(request: ProcessVcRequest): Promise + sendVcRequest(request: SendVcRequest): Promise; +} + +export interface Web5ManagedAgent extends Web5Agent { + appData: AppDataStore; + didManager: DidManager; + didResolver: DidResolver; + dwnManager: DwnManager; + identityManager: IdentityManager; + keyManager: KeyManager; + rpcClient: DwnRpc; + + firstLaunch(): Promise; + initialize(options: { passphrase: string }): Promise; + start(options: { passphrase: string }): Promise; +} \ No newline at end of file diff --git a/packages/agent/src/types/managed-key.ts b/packages/agent/src/types/managed-key.ts new file mode 100644 index 000000000..86f0aa84a --- /dev/null +++ b/packages/agent/src/types/managed-key.ts @@ -0,0 +1,442 @@ +import type { Web5Crypto } from '@web5/crypto'; +import type { RequireOnly } from '@web5/common'; + +import { Web5ManagedAgent } from './agent.js'; + +export interface CryptoManager { + agent: Web5ManagedAgent; + + decrypt(options: DecryptOptions): Promise; + + deriveBits(options: DeriveBitsOptions): Promise; + + encrypt(options: EncryptOptions): Promise; + + /** + * Generate a new ManagedKey within a CryptoManager implementation. + */ + generateKey(options: GenerateKeyOptions): Promise>; + + /** + * Retrieves detailed information about a ManagedKey or ManagedKeyPair object. + * + * @param options - The options for retrieving the key. + * @param options.keyRef - The reference identifier for the key. Can specify the id or alias property of the key. + * @returns A promise that resolves to either a ManagedKey or ManagedKeyPair object. + */ + getKey(options: { keyRef: string }): Promise; + + importKey(options: PortableKeyPair): Promise; + importKey(options: PortableKey): Promise; + importKey(options: ImportKeyOptions): Promise; + + sign(options: SignOptions): Promise; + + updateKey(options: UpdateKeyOptions): Promise; + + verify(options: VerifyOptions): Promise; +} + +/** + * Input arguments for implementations of the CryptoManager interface + * {@link CryptoManager.encrypt | encrypt} method. + * + * @public + */ +export type DecryptOptions = { + /** + * An object defining the cipher algorithm to use and its parameters. + */ + algorithm: Web5Crypto.AlgorithmIdentifier | Web5Crypto.AesCtrOptions | Web5Crypto.AesGcmOptions; + + /** + * A Uint8Array object containing the data to be decrypted + * (also known as the ciphertext). + */ + data: Uint8Array; + + /** + * An identifier of the ManagedKey to be used for decryption. + * You can use the id or alias property of the key. + */ + keyRef: string; +} + +/** + * Input arguments for implementations of the CryptoManager interface + * {@link CryptoManager.deriveBits | deriveBits} method. + * + * @public + */ +export type DeriveBitsOptions = { + + /** + * An object defining the derivation algorithm to use and its parameters. + */ + algorithm: Web5Crypto.AlgorithmIdentifier | Web5Crypto.EcdhDeriveKeyOptions; + + /** + * An identifier of the ManagedKey that will be the input to the + * derivation algorithm. + * + * If the algorithm is ECDH, this identifier will refer to an ECDH key pair. + * For PBKDF2, it might be a password. + * For HDKF, it might be the shared secret output of an ECDH key agreement operation. + */ + baseKeyRef: string; + + /** + * A number representing the number of bits to derive. To be compatible with + * all browsers, the number should be a multiple of 8. + */ + length?: number; +} + +/** + * Input arguments for implementations of the CryptoManager interface + * {@link CryptoManager.encrypt | encrypt} method. + * + * @public + */ +export type EncryptOptions = { + /** + * An object defining the cipher algorithm to use and its parameters. + */ + algorithm: Web5Crypto.AlgorithmIdentifier | Web5Crypto.AesCtrOptions | Web5Crypto.AesGcmOptions; + + /** + * An Uint8Array object containing the data to be encrypted + * (also known as the plaintext). + */ + data: Uint8Array; + + /** + * An identifier of the ManagedKey to be used for encryption. + * You can use the id or alias property of the key. + */ + keyRef: string; +} + +export type GenerateKeyOptions = { + algorithm: T; + alias?: string; + extractable?: boolean; + keyUsages: Web5Crypto.KeyUsage[]; + metadata?: KeyMetadata; +}; + +export type GenerateKeyOptionTypes = + | Web5Crypto.AlgorithmIdentifier + // | RsaHashedGenerateKeyOptions + | Web5Crypto.AesGenerateKeyOptions + | Web5Crypto.EcdsaGenerateKeyOptions + | Web5Crypto.EdDsaGenerateKeyOptions + // | HmacGenerateKeyOptions + // | Pbkdf2Params; + +export type GenerateKeyType = T extends Web5Crypto.EcGenerateKeyOptions ? ManagedKeyPair : + T extends Web5Crypto.AesGenerateKeyOptions /*| HmacGenerateKeyOptions | Pbkdf2Params*/ ? ManagedKey : + T extends Web5Crypto.AlgorithmIdentifier ? ManagedKey | ManagedKeyPair : + never; + +export type PortableKey = + RequireOnly< + ManagedKey, + 'algorithm' | 'extractable' | 'type' | 'usages', + 'id' | 'material' | 'state' + > + & { material: Uint8Array; }; + +export interface PortableKeyPair { + privateKey: PortableKey; + publicKey: PortableKey; +} + +export type ImportKeyOptions = + | PortableKey + | PortableKeyPair + +/** + * Base interface to be implemented by key management systems. + */ +export type KeyManagementSystem = CryptoManager; + +/** + * KeyMetadata + * + * Implementations of KeyManagementSystem can populate this object with KMS platform + * specific data about each key. + * + * This property can also be used to add various tags to the keys under management. + */ +export type KeyMetadata = { + /** + * Additional properties of any type. + */ + [key: string]: any; +} + +/** + * KeyState + * + * The read-only `state` property of the `ManagedKey` interface indicates the + * status of the ManagedKey. + * + * It can have the following string values: + * + * "Enabled": The key is ready for use. + * + * "Disabled": The key may not be used, but the key material is still available, + * and the key can be placed back into the Enabled state. + * + * "PendingCreation": The key is still being created. It may not be used, + * enabled, disabled, or destroyed yet. The KMS will + * automatically change the state to enabled as soon + * as the key is ready. + * + * "PendingDeletion": The key is scheduled for deletion. It can be placed back + * into the Disabled state up until the time of deletion + * using the CancelKeyDeletion() method. Once the key has + * been deleted, any ciphertext encrypted with this key + * is no longer recoverable. Minimum and maximum waiting + * periods are defined by each KMS implementation. + * + * "PendingImport": The key is still being imported. It may not be used, enabled, + * disabled, or deleted yet. The KMS will automatically change + * the state to Enabled once the key is ready. + * + * "PendingUpdate": The key is still being updated. It may not be used, enabled, + * disabled, or deleted until the update process completes. + * The KMS will automatically change the state to Enabled + * once the key is ready. + */ +export type KeyState = 'Enabled' | 'Disabled' | 'PendingCreation' | 'PendingDeletion' | 'PendingImport' | 'PendingUpdate'; + +/** + * ManagedKey + * + * A ManagedKey represents a cryptographic key used by a cipher for + * encryption or decryption or an algorithm for signing or verification. + */ +export interface ManagedKey { + /** + * A unique identifier for the Key, autogenerated by a KMS. + */ + id: string; + + /** + * An object detailing the algorithm for which the key can be used along + * with additional algorithm-specific parameters. + */ + algorithm: Web5Crypto.GenerateKeyOptions; + + /** + * An alternate identifier used to identify the key in a KMS. + * This property can be used to associate a DID document key ID with a ManagedKey. + */ + alias?: string; + + /** + * A boolean value that is `true` if the key can be exported and `false` if not. + */ + extractable: boolean; + + /** + * Name of a registered key management system. + */ + kms: string; + + /** + * Key material as a raw binary data buffer. + */ + material?: Uint8Array; + + /** + * Optional. Additional Key metadata. + */ + metadata?: KeyMetadata; + + /** + * A registered string value specifying the algorithm and any algorithm + * specific parameters. + * Supported algorithms vary by KMS. + */ + spec?: string; + + /** + * The current status of the ManagedKey. + */ + state: KeyState; + + /** + * The type of key. + */ + type: Web5Crypto.KeyType; + + /** + * Indicates which cryptographic operations are permissible to be used with this key. + */ + usages: Web5Crypto.KeyUsage[]; +} + +/** + * Represents information about a managed key. + * Private or secret key material is NOT present. + * + */ +export type ManagedKeyInfo = Omit; + +export type ManagedKeyOptions = Omit + +/** ManagedKeyPair + * + * A ManagedKeyPair represents a key pair for an asymmetric cryptography algorithm, + * also known as a public-key algorithm. + * + * A ManagedKeyPair object can be obtained using `generateKey()`, when the + * selected algorithm is one of the asymmetric algorithms: ECDSA or ECDH. + */ +export interface ManagedKeyPair { + /** + * A ManagedKey object representing the private key. For encryption and + * decryption algorithms, this key is used to decrypt. For signing and + * verification algorithms it is used to sign. + */ + privateKey: ManagedKey; + + /** + * A ManagedKey object representing the public key. For encryption and + * decryption algorithms, this key is used to encrypt. For signing and + * verification algorithms it is used to verify signatures. + */ + publicKey: ManagedKey; +} + +/** + * ManagedKeyStore + * + * This interface should be implemented to provide platform specific + * implementations that are usable by KeyManager and implementations + * of KeyManagementSystem. + * + * Implementations of this class can be used to store: + * ManagedKey and ManagedKeyPair + * or: + * ManagedPrivateKey + * objects. + * + * @public + */ +export interface ManagedKeyStore { + deleteKey(options: { id: K, agent?: Web5ManagedAgent, context?: string }): Promise + findKey(options: { id: K, agent?: Web5ManagedAgent, context?: string }): Promise; + findKey(options: { alias: K, agent?: Web5ManagedAgent, context?: string }): Promise; + getKey(options: { id: K, agent?: Web5ManagedAgent, context?: string }): Promise + importKey(options: { key: Omit, agent?: Web5ManagedAgent, context?: string }): Promise + listKeys(options?: { agent?: Web5ManagedAgent, context?: string }): Promise + updateKey(options: { id: K, agent?: Web5ManagedAgent, context?: string } & Partial): Promise +} + +/** + * Represents a private key. + * + * The `alias` is used to refer to the key material which is stored as the hex encoding of the raw byte array + * (`privateKeyHex`). + * + * The `type` refers to the type of key that is represented. + * + * @public + */ +export interface ManagedPrivateKey { + /** + * A unique identifier for the Key, autogenerated by a KMS. + */ + id: string + + /** + * Key material as raw binary data. + */ + material: Uint8Array; + + /** + * The type of key. + */ + type: Web5Crypto.PrivateKeyType; +} + +/** + * Input arguments for implementations of the CryptoManager interface {@link CryptoManager.sign | sign} method. + * + * @public + */ +export type SignOptions = { + /** + * An object that specifies the signature algorithm to use and its parameters. + */ + algorithm: Web5Crypto.AlgorithmIdentifier | Web5Crypto.EcdsaOptions | Web5Crypto.EdDsaOptions; + + /** + * An Uint8Array object containing the data to be signed. + */ + data: Uint8Array; + + /** + * An identifier of the ManagedKey to sign with. + * You can use the id or alias property of the key. + */ + keyRef: string; +} + +/** + * Input arguments for implementations of the CryptoManager interface + * {@link CryptoManager.updateKey | updateKey} method. + * + * @public + */ +export type UpdateKeyOptions = { + /** + * An alternate identifier used to identify the key in a KMS. + * This property can be used to associate a DID document key ID with a ManagedKey. + */ + alias?: string; + + /** + * An identifier of the ManagedKey to be used for decryption. + * You can use the id or alias property of the key. + */ + keyRef: string; + + /** + * Optional. Additional Key metadata. + */ + metadata?: KeyMetadata; +} + +/** + * Input arguments for implementations of the CryptoManager interface + * {@link CryptoManager.verify | verify} method. + * + * @public + */ +export type VerifyOptions = { + /** + * An object that specifies the algorithm to use and its parameters. + */ + algorithm: Web5Crypto.AlgorithmIdentifier | Web5Crypto.EcdsaOptions | Web5Crypto.EdDsaOptions; + + /** + * An Uint8Array object containing the data whose signature is to be verified. + */ + data: Uint8Array; + + /** + * An identifier of the ManagedKey to sign with. + * You can use the id or alias property of the key. + */ + keyRef: string; + + /** + * A Uint8Array containing the signature to verify. + */ + signature: Uint8Array; +} \ No newline at end of file diff --git a/packages/agent/src/utils.ts b/packages/agent/src/utils.ts new file mode 100644 index 000000000..c441d6e8e --- /dev/null +++ b/packages/agent/src/utils.ts @@ -0,0 +1,190 @@ +import type { JsonWebKey, Web5Crypto } from '@web5/crypto'; + +import { Jose } from '@web5/crypto'; +import { RequireOnly } from '@web5/common'; +import { Readable } from 'readable-stream'; +import { ReadableWebToNodeStream } from 'readable-web-to-node-stream'; + +import { ManagedKey, ManagedKeyPair, PortableKey, PortableKeyPair } from './types/managed-key.js'; + +export function blobToIsomorphicNodeReadable(blob: Blob): Readable { + return webReadableToIsomorphicNodeReadable(blob.stream() as ReadableStream); +} + +export function cryptoToManagedKey(options: { + cryptoKey: Web5Crypto.CryptoKey, + keyData: RequireOnly + }): ManagedKey { + const { cryptoKey, keyData } = options; + + const managedKey: ManagedKey = { + id : keyData.id ?? '', + algorithm : cryptoKey.algorithm, + alias : keyData.alias, + extractable : cryptoKey.extractable, + kms : keyData.kms, + material : (cryptoKey.type === 'public') ? cryptoKey.material : undefined, + metadata : keyData.metadata, + state : 'Enabled', + type : cryptoKey.type, + usages : cryptoKey.usages + }; + + return managedKey; +} + +export function cryptoToManagedKeyPair(options: { + cryptoKeyPair: Web5Crypto.CryptoKeyPair, + keyData: RequireOnly + }): ManagedKeyPair { + const { cryptoKeyPair, keyData } = options; + + const privateKey = cryptoKeyPair.privateKey; + const publicKey = cryptoKeyPair.publicKey; + + const managedKeyPair = { + privateKey: { + id : keyData.id ?? '', + algorithm : privateKey.algorithm, + alias : keyData.alias, + extractable : privateKey.extractable, + kms : keyData.kms, + metadata : keyData.metadata, + state : keyData.state, + type : privateKey.type, + usages : privateKey.usages + }, + + publicKey: { + id : keyData.id ?? '', + algorithm : publicKey.algorithm, + alias : keyData.alias, + extractable : publicKey.extractable, + kms : keyData.kms, + material : publicKey.material, + metadata : keyData.metadata, + state : keyData.state, + type : publicKey.type, + usages : publicKey.usages + }, + }; + + return managedKeyPair; +} + +export function cryptoToPortableKey(options: { + cryptoKey: Web5Crypto.CryptoKey, + keyData: RequireOnly + }): PortableKey { + const { cryptoKey, keyData } = options; + + const portableKey = { + id : keyData.id ?? '', + algorithm : cryptoKey.algorithm, + alias : keyData.alias, + extractable : cryptoKey.extractable, + kms : keyData.kms, + material : cryptoKey.material, + metadata : keyData.metadata, + type : cryptoKey.type, + usages : cryptoKey.usages + }; + + return portableKey; +} + +export function cryptoToPortableKeyPair(options: { + cryptoKeyPair: Web5Crypto.CryptoKeyPair, + keyData: RequireOnly + }): PortableKeyPair { + const { cryptoKeyPair, keyData } = options; + + const privateKey = cryptoKeyPair.privateKey; + const publicKey = cryptoKeyPair.publicKey; + + const portableKeyPair = { + privateKey: { + id : keyData.id ?? '', + algorithm : privateKey.algorithm, + alias : keyData.alias, + extractable : privateKey.extractable, + kms : keyData.kms, + material : privateKey.material, + metadata : keyData.metadata, + type : privateKey.type, + usages : privateKey.usages + }, + + publicKey: { + id : keyData.id ?? '', + algorithm : publicKey.algorithm, + alias : keyData.alias, + extractable : publicKey.extractable, + kms : keyData.kms, + material : publicKey.material, + metadata : keyData.metadata, + type : publicKey.type, + usages : publicKey.usages + }, + }; + + return portableKeyPair; +} + +/** + * Type guard function to check if the given key is a ManagedKey. + * + * @param key The key to check. + * @returns True if the key is a ManagedKeyPair, false otherwise. + */ +export function isManagedKey(key: ManagedKey | ManagedKeyPair | undefined): key is ManagedKey { + return key !== undefined && 'algorithm' in key && 'extractable' in key && 'type' in key && 'usages' in key; +} + +/** + * Type guard function to check if the given key is a ManagedKeyPair. + * + * @param key The key to check. + * @returns True if the key is a ManagedKeyPair, false otherwise. + */ +export function isManagedKeyPair(key: ManagedKey | ManagedKeyPair | undefined): key is ManagedKeyPair { + return key !== undefined && 'privateKey' in key && 'publicKey' in key; +} + +export async function managedKeyToJwk({ key }: { + key: RequireOnly +}): Promise { + if (key.material === undefined) { + throw new Error(`Could not convert to JWK: 'material' is undefined.`); + } + + const cryptoKey: Web5Crypto.CryptoKey = { + algorithm : key.algorithm, + extractable : key.extractable, + material : key.material, + type : key.type, + usages : key.usages + }; + + const jwk = await Jose.cryptoKeyToJwk({ key: cryptoKey }); + + return jwk; +} + +export function managedToCryptoKey({ key }: { + key: RequireOnly +}): Web5Crypto.CryptoKey { + const cryptoKey: Web5Crypto.CryptoKey = { + algorithm : key.algorithm, + extractable : key.extractable, + material : key.material, + type : key.type, + usages : key.usages + }; + + return cryptoKey; +} + +export function webReadableToIsomorphicNodeReadable(webReadable: ReadableStream) { + return new ReadableWebToNodeStream(webReadable); +} \ No newline at end of file diff --git a/packages/agent/tests/app-data-vault.spec.ts b/packages/agent/tests/app-data-vault.spec.ts new file mode 100644 index 000000000..92fb57b7b --- /dev/null +++ b/packages/agent/tests/app-data-vault.spec.ts @@ -0,0 +1,139 @@ +import type { Web5Crypto } from '@web5/crypto'; + +import chai, { expect } from 'chai'; +import chaiAsPromised from 'chai-as-promised'; +import { LevelStore, MemoryStore } from '@web5/common'; +import { CryptoKey, EdDsaAlgorithm } from '@web5/crypto'; + +import { AppDataVault } from '../src/app-data-store.js'; + +chai.use(chaiAsPromised); + +const testConfigurations = [ + { + name : 'MemoryStore', + dataStore : new MemoryStore() + }, + { + name : 'LevelStore', + dataStore : new LevelStore() + } +]; + +describe('AppDataVault', () => { + testConfigurations.forEach((test) => { + describe(`with ${test.name}`, () => { + + let dataVault: AppDataVault; + let dataStore = test.dataStore; + + before(() => { + dataVault = new AppDataVault({ store: dataStore, keyDerivationWorkFactor: 1 }); + }); + + beforeEach(() => { + dataStore.clear(); + }); + + afterEach(() => { + dataStore.clear(); + }); + + after(() => { + dataStore.close(); + }); + + describe('getPrivateKey()', () => { + let keyPair: Web5Crypto.CryptoKeyPair; + + beforeEach(async () => { + // Initialize and pre-populate the app data vault with a key pair. + const passphrase = 'dumbbell-krakatoa-ditty'; + keyPair = await EdDsaAlgorithm.create().generateKey({ + algorithm : { name: 'EdDSA', namedCurve: 'Ed25519' }, + extractable : true, + keyUsages : ['sign', 'verify'] + }); + await dataVault.initialize({ keyPair, passphrase }); + }); + + it('returns a private CryptoKey', async () => { + const privateKey = await dataVault.getPrivateKey(); + expect(privateKey).to.have.keys(['algorithm', 'extractable', 'type', 'usages']); + expect(privateKey).to.have.property('type', 'private'); + expect(privateKey.material).to.deep.equal(keyPair.privateKey.material); + }); + }); + + describe('getPublicKey()', () => { + let keyPair: Web5Crypto.CryptoKeyPair; + + beforeEach(async () => { + // Initialize and pre-populate the app data vault with a key pair. + const passphrase = 'dumbbell-krakatoa-ditty'; + keyPair = await EdDsaAlgorithm.create().generateKey({ + algorithm : { name: 'EdDSA', namedCurve: 'Ed25519' }, + extractable : true, + keyUsages : ['sign', 'verify'] + }); + await dataVault.initialize({ keyPair, passphrase }); + }); + + it('returns a public CryptoKey', async () => { + const publicKey = await dataVault.getPublicKey(); + expect(publicKey).to.have.keys(['algorithm', 'extractable', 'type', 'usages']); + expect(publicKey).to.have.property('type', 'public'); + expect(publicKey.material).to.deep.equal(keyPair.publicKey.material); + }); + }); + + describe('getStatus()', () => { + it('should return initialized=false when first instantiated', async () => { + const vaultStatus = await dataVault.getStatus(); + expect(vaultStatus.initialized).to.be.false; + expect(vaultStatus.lastBackup).to.be.undefined; + expect(vaultStatus.lastRestore).to.be.undefined; + }); + + it('should return initialized=true after initialization', async () => { + // Mock initialization having been completed. + dataStore.set('appDataStatus', { initialized: true }); + + const vaultStatus = await dataVault.getStatus(); + expect(vaultStatus.initialized).to.be.false; + expect(vaultStatus.lastBackup).to.be.undefined; + expect(vaultStatus.lastRestore).to.be.undefined; + }); + }); + + describe('initialize()', () => { + let keyPair = { + privateKey : new CryptoKey({ name: 'EdDSA', namedCurve: 'Ed25519' }, true, new Uint8Array(32), 'private', ['sign']), + publicKey : new CryptoKey({ name: 'EdDSA', namedCurve: 'Ed25519' }, true, new Uint8Array(32), 'public', ['verify']) + }; + + it('should initialize data vault when first instantiated', async () => { + let vaultStatus = await dataVault.getStatus(); + expect(vaultStatus.initialized).to.be.false; + + const passphrase = 'dumbbell-krakatoa-ditty'; + await dataVault.initialize({ keyPair, passphrase }); + vaultStatus = await dataVault.getStatus(); + expect(vaultStatus.initialized).to.be.true; + }); + + it('should throw if attempted on initialized data vault', async () => { + const vaultStatus = await dataVault.getStatus(); + expect(vaultStatus.initialized).to.be.false; + + const passphrase = 'dumbbell-krakatoa-ditty'; + await dataVault.initialize({ keyPair, passphrase }); + + await expect( + dataVault.initialize({ keyPair, passphrase }) + ).to.eventually.be.rejectedWith(Error, 'vault already initialized'); + }); + }); + }); + }); +}); \ No newline at end of file diff --git a/packages/agent/tests/did-manager.spec.ts b/packages/agent/tests/did-manager.spec.ts new file mode 100644 index 000000000..f13936ad7 --- /dev/null +++ b/packages/agent/tests/did-manager.spec.ts @@ -0,0 +1,815 @@ +import type { PrivateKeyJwk, PublicKeyJwk, Web5Crypto } from '@web5/crypto'; +import type { DidKeySet, PortableDid } from '@web5/dids'; + +import { expect } from 'chai'; +import { DidKeyMethod } from '@web5/dids'; +import { Jose, EdDsaAlgorithm } from '@web5/crypto'; + +import type { ManagedDid } from '../src/did-manager.js'; +import type { Web5ManagedAgent } from '../src/types/agent.js'; + +import { TestAgent } from './utils/test-agent.js'; +import { DidManager } from '../src/did-manager.js'; +import { TestManagedAgent } from '../src/test-managed-agent.js'; +import { DidStoreDwn, DidStoreMemory } from '../src/store-managed-did.js'; + +describe('DidManager', () => { + + describe('constructor', () => { + it('accepts an array of DID method implementations', () => { + expect( + new DidManager({ didMethods: [DidKeyMethod] }) + ).to.not.throw; + }); + + it('throws an exception if didMethods input is missing', () => { + expect(() => + // @ts-expect-error because an empty object is intentionally specified to trigger the error. + new DidManager({}) + ).to.throw(TypeError, `Required parameter missing: 'didMethods'`); + }); + }); + + describe('get agent', () => { + it(`returns the 'agent' instance property`, async () => { + // @ts-expect-error because we are only mocking a single property. + const mockAgent: Web5ManagedAgent = { + agentDid: 'did:method:abc123' + }; + const didManager = new DidManager({ didMethods: [DidKeyMethod], agent: mockAgent }); + const agent = didManager.agent; + expect(agent).to.exist; + expect(agent.agentDid).to.equal('did:method:abc123'); + }); + + it(`throws an error if the 'agent' instance property is undefined`, () => { + const didManager = new DidManager({ didMethods: [DidKeyMethod] }); + expect(() => + didManager.agent + ).to.throw(Error, 'Unable to determine agent execution context'); + }); + }); + + const agentStoreTypes = ['dwn', 'memory'] as const; + agentStoreTypes.forEach((agentStoreType) => { + + describe(`with ${agentStoreType} data stores`, () => { + let testAgent: TestManagedAgent; + + before(async () => { + testAgent = await TestManagedAgent.create({ + agentClass : TestAgent, + agentStores : agentStoreType + }); + }); + + beforeEach(async () => { + await testAgent.clearStorage(); + await testAgent.createAgentDid(); + }); + + after(async () => { + await testAgent.clearStorage(); + await testAgent.closeStorage(); + }); + + describe('create()', () => { + it('creates a did:key ManagedDid with keys if keySet is not given', async () => { + // Create a ManagedDid. + const managedDid = await testAgent.agent.didManager.create({ + method : 'key', + kms : 'local' + }); + + // Verify the result. + expect(managedDid).to.have.property('alias'); + expect(managedDid).to.have.property('did'); + expect(managedDid).to.have.property('document'); + expect(managedDid).to.have.property('metadata'); + expect(managedDid).to.have.property('method'); + }); + + it('creates a did:ion ManagedDid with keys if keySet is not given', async () => { + // Create a ManagedDid. + const managedDid = await testAgent.agent.didManager.create({ + method : 'ion', + kms : 'local' + }); + + // Verify the result. + expect(managedDid).to.have.property('alias'); + expect(managedDid).to.have.property('did'); + expect(managedDid).to.have.property('document'); + expect(managedDid).to.have.property('metadata'); + expect(managedDid).to.have.property('method'); + }).timeout(100000); + + it('adds generated keys to KeyManager if keySet is not given', async () => { + // Create a ManagedDid. + const managedDid = await testAgent.agent.didManager.create({ method: 'key', kms: 'local' }); + + // Attempt to retrieve the ManagedKeyPair from the KeyManager. + const signingKeyId = await testAgent.agent.didManager.getDefaultSigningKey({ did: managedDid.did }); + if (!signingKeyId) throw new Error('Type guard'); + const storedKeyPair = await testAgent.agent.keyManager.getKey({ keyRef: signingKeyId }); + + // Verify the key was found. + expect(storedKeyPair).to.exist; + expect(storedKeyPair).to.have.property('privateKey'); + expect(storedKeyPair).to.have.property('publicKey'); + }); + + it('updates KeyManager alias if keySet previously stored in KeyManager', async () => { + // Generate an Ed25519 signing key pair. + const keyPair = await testAgent.agent.keyManager.generateKey({ + algorithm : { name: 'EdDSA', namedCurve: 'Ed25519' }, + extractable : true, + keyUsages : ['sign', 'verify'], + kms : 'local' + }); + + // Create a ManagedDid using the keySet. + const keySet: DidKeySet = { + verificationMethodKeys: [{ + keyManagerId : keyPair.publicKey.id, + relationships : ['authentication'] + }] + }; + const managedDid = await testAgent.agent.didManager.create({ method: 'key', keySet, kms: 'local' }); + + // Attempt to retrieve the ManagedKeyPair from the KeyManager. + const signingKeyId = await testAgent.agent.didManager.getDefaultSigningKey({ did: managedDid.did }); + if (!signingKeyId) throw new Error('Type guard'); + const storedKeyPair = await testAgent.agent.keyManager.getKey({ keyRef: signingKeyId }); + + // Verify the key was found. + expect(storedKeyPair).to.exist; + expect(storedKeyPair).to.have.property('privateKey'); + expect(storedKeyPair).to.have.property('publicKey'); + }); + + it('updates KeyManager alias if keySet key pair not present in KeyManager', async () => { + // Generate an Ed25519 signing key pair. + const keyPair = await new EdDsaAlgorithm().generateKey({ + algorithm : { name: 'EdDSA', namedCurve: 'Ed25519' }, + extractable : true, + keyUsages : ['sign', 'verify'] + }); + + // Convert the key pair to JSON Web Key format. + const publicKeyJwk = await Jose.cryptoKeyToJwk({ key: keyPair.publicKey as Web5Crypto.CryptoKey }) as PublicKeyJwk; + const privateKeyJwk = await Jose.cryptoKeyToJwk({ key: keyPair.privateKey as Web5Crypto.CryptoKey }) as PrivateKeyJwk; + + // Create a ManagedDid using the keySet. + const keySet: DidKeySet = { + verificationMethodKeys: [{ + privateKeyJwk, + publicKeyJwk, + relationships: ['authentication'] + }] + }; + const managedDid = await testAgent.agent.didManager.create({ method: 'key', keySet, kms: 'local' }); + + // Attempt to retrieve the ManagedKeyPair from the KeyManager. + const signingKeyId = await testAgent.agent.didManager.getDefaultSigningKey({ did: managedDid.did }); + if (!signingKeyId) throw new Error('Type guard'); + const storedKeyPair = await testAgent.agent.keyManager.getKey({ keyRef: signingKeyId }); + + // Verify the key was found. + expect(storedKeyPair).to.exist; + expect(storedKeyPair).to.have.property('privateKey'); + expect(storedKeyPair).to.have.property('publicKey'); + }); + + it('updates KeyManager alias if keySet public key not present in KeyManager', async () => { + // Generate an Ed25519 signing key pair. + const keyPair = await new EdDsaAlgorithm().generateKey({ + algorithm : { name: 'EdDSA', namedCurve: 'Ed25519' }, + extractable : true, + keyUsages : ['sign', 'verify'] + }); + + // Convert the public key to JSON Web Key format. + const publicKeyJwk = await Jose.cryptoKeyToJwk({ key: keyPair.publicKey as Web5Crypto.CryptoKey }) as PublicKeyJwk; + + // Create a ManagedDid using the keySet. + const keySet: DidKeySet = { + verificationMethodKeys: [{ + publicKeyJwk, + relationships: ['authentication'] + }] + }; + const managedDid = await testAgent.agent.didManager.create({ + method : 'key', + keySet, + kms : 'local', + context : testAgent.agent.agentDid + }); + + // Attempt to retrieve the ManagedKey from the KeyManager. + const signingKeyId = await testAgent.agent.didManager.getDefaultSigningKey({ did: managedDid.did }); + if (!signingKeyId) throw new Error('Type guard'); + const storedPublicKey = await testAgent.agent.keyManager.getKey({ keyRef: signingKeyId }); + + // Verify the key was found. + expect(storedPublicKey).to.exist; + expect(storedPublicKey).to.have.property('type', 'public'); + }); + + it('throws an exception if keySet is missing publicKeyJwk and not present in KeyManager', async () => { + const keySet: DidKeySet = { verificationMethodKeys: [{ relationships: ['authentication'] }] + }; + + await expect( + testAgent.agent.didManager.create({ method: 'key', keySet }) + ).to.eventually.be.rejectedWith(Error, 'Required parameter(s) missing'); + }); + + it('throws an exception if keySet with privateKeyJwk is missing publicKeyJwk and not present in KeyManager', async () => { + // Generate an Ed25519 signing key pair. + const keyPair = await new EdDsaAlgorithm().generateKey({ + algorithm : { name: 'EdDSA', namedCurve: 'Ed25519' }, + extractable : true, + keyUsages : ['sign', 'verify'] + }); + + // Convert private key to JWK format. + const privateKeyJwk = await Jose.cryptoKeyToJwk({ key: keyPair.privateKey as Web5Crypto.CryptoKey }) as PrivateKeyJwk; + + const keySet: DidKeySet = { verificationMethodKeys: [{ privateKeyJwk, relationships: ['authentication'] }] + }; + + await expect( + testAgent.agent.didManager.create({ method: 'key', keySet }) + ).to.eventually.be.rejectedWith(Error, 'Required parameter(s) missing'); + }); + + // Tests that should only run for DWN-backed stores that provide multi-tenancy. + if (agentStoreType === 'dwn') { + it('creates DIDs under the tenant of the new DID, by default', async () => { + // Create a ManagedDid. + const managedDid = await testAgent.agent.didManager.create({ + method : 'key', + kms : 'local' + }); + + // Verify that the DID was NOT stored under the Agent's tenant. + let storedDid = await testAgent.agent.didManager.get({ didRef: managedDid.did }); + expect(storedDid).to.not.exist; + + // Verify that the DID WAS stored under the new DID's tenant. + storedDid = await testAgent.agent.didManager.get({ didRef: managedDid.did, context: managedDid.did }); + expect(storedDid).to.exist; + }); + + it('creates DIDs under the context of the specified DID', async () => { + // Create a ManagedDid. + const managedDid = await testAgent.agent.didManager.create({ + method : 'key', + kms : 'local', + context : testAgent.agent.agentDid + }); + + // Verify that the DID WAS stored under the Agent's tenant. + let storedDid = await testAgent.agent.didManager.get({ didRef: managedDid.did }); + expect(storedDid).to.exist; + + // Verify that the DID was NOT stored under the new DID's tenant. + storedDid = await testAgent.agent.didManager.get({ didRef: managedDid.did, context: managedDid.did }); + expect(storedDid).to.not.exist; + }); + } + }); + + describe('delete()', () => { + xit('should be implemented'); + }); + + describe('export()', () => { + xit('should be implemented'); + }); + + describe('import()', () => { + it('imports did:key DID and key set', async () => { + // Create did:key DID with key set to use to attempt import. + const portableDid = await DidKeyMethod.create({ keyAlgorithm: 'Ed25519' }); + + // Attempt to import the DID with DidManager under the Agent's context. + const managedDid = await testAgent.agent.didManager.import({ + did : portableDid, + kms : 'local', + context : testAgent.agent.agentDid + }); + + // Try to retrieve the DID from the DidManager store to verify it was imported. + const storedDid = await testAgent.agent.didManager.get({ didRef: managedDid.did }); + + if (storedDid === undefined) throw new Error('Type guard unexpectedly threw'); // Type guard. + expect(storedDid.did).to.equal(portableDid.did); + expect(storedDid.document).to.deep.equal(portableDid.document); + }); + + it('supports importing multiple DIDs to the same Identity/tenant', async () => { + // Create and import the first DID. + const did1 = await DidKeyMethod.create(); + const did1Import = await testAgent.agent.didManager.import({ + did : did1, + kms : 'local', + context : testAgent.agent.agentDid + }); + + // Create and import a second DID. + const did2 = await DidKeyMethod.create(); + const did2Import = await testAgent.agent.didManager.import({ + did : did2, + kms : 'local', + context : testAgent.agent.agentDid + }); + + // Verify that DID 1 WAS stored under the Agent's tenant. + let storedDid1 = await testAgent.agent.didManager.get({ didRef: did1Import.did }); + expect(storedDid1).to.exist; + expect(storedDid1?.did).to.equal(did1.did); + + // Verify that DID 2 WAS stored under the Agent's tenant. + let storedDid2 = await testAgent.agent.didManager.get({ didRef: did2Import.did }); + expect(storedDid2).to.exist; + expect(storedDid2?.did).to.equal(did2.did); + }); + + it('does not return private key JWK after import', async () => { + // Create did:key DID with key set to use to attempt import. + const portableDid = await DidKeyMethod.create({ keyAlgorithm: 'Ed25519' }); + + // Attempt to import the DID with DidManager. + const managedDid = await testAgent.agent.didManager.import({ did: portableDid, kms: 'local' }); + + // Verify private key material is not returned. + if (managedDid.keySet.verificationMethodKeys === undefined) throw new Error('Type guard unexpectedly threw'); // Type guard. + for (const key of managedDid.keySet.verificationMethodKeys) { + expect(key.privateKeyJwk).to.not.exist; + } + }); + + it('does not mutate DID input during import', async () => { + // Create did:key DID with key set to use to attempt import. + const portableDid = await DidKeyMethod.create({ keyAlgorithm: 'Ed25519' }); + + // Create a deep clone to use to check for side effects. + const portableDidClone = structuredClone(portableDid); + + // Import the DID with DidManager. + await testAgent.agent.didManager.import({ did: portableDid, kms: 'local' }); + + // Verify the input object was not mutated during import. + expect(portableDid).to.deep.equal(portableDidClone); + }); + + // Tests that should only run for DWN-backed stores that provide multi-tenancy. + if (agentStoreType === 'dwn') { + it('imports DIDs under the tenant of the new DID, by default', async () => { + // Create did:key DID with key set to use to attempt import. + const portableDid = await DidKeyMethod.create({ keyAlgorithm: 'Ed25519' }); + + // Attempt to import the DID with DidManager. + const managedDid = await testAgent.agent.didManager.import({ + did : portableDid, + kms : 'local' + }); + + // Verify that the DID was NOT stored under the Agent's tenant. + let storedDid = await testAgent.agent.didManager.get({ didRef: managedDid.did }); + expect(storedDid).to.not.exist; + + // Verify that the DID WAS stored under the new DID's tenant. + storedDid = await testAgent.agent.didManager.get({ didRef: managedDid.did, context: managedDid.did }); + expect(storedDid).to.exist; + }); + + it('imports DIDs under the context of the specified DID', async () => { + // Create did:key DID with key set to use to attempt import. + const portableDid = await DidKeyMethod.create({ keyAlgorithm: 'Ed25519' }); + + // Attempt to import the DID with DidManager. + const managedDid = await testAgent.agent.didManager.import({ + did : portableDid, + kms : 'local', + context : testAgent.agent.agentDid + }); + + // Verify that the DID was stored under the Agent's tenant. + let storedDid = await testAgent.agent.didManager.get({ didRef: managedDid.did }); + expect(storedDid).to.exist; + + // Verify that the DID was NOT stored under the new DID's tenant. + storedDid = await testAgent.agent.didManager.get({ didRef: managedDid.did, context: managedDid.did }); + expect(storedDid).to.not.exist; + }); + } + }); + + describe('update()', () => { + xit('should be implemented'); + }); + }); + }); +}); + +describe('DidStoreDwn', () => { + let didStoreDwn: DidStoreDwn; + let testAgent: TestAgent; + let testManagedDid: ManagedDid; + + before(async () => { + testAgent = await TestAgent.create(); + }); + + beforeEach(async () => { + didStoreDwn = new DidStoreDwn(); + + const didManager = new DidManager({ + didMethods : [DidKeyMethod], + store : didStoreDwn, + agent : testAgent + }); + + testAgent.didManager = didManager; + + // Create did:key DID with key set. + const portableDid = await DidKeyMethod.create({ keyAlgorithm: 'Ed25519' }); + testManagedDid = { ...portableDid, method: 'key' }; + }); + + afterEach(async () => { + await testAgent.clearStorage(); + }); + + after(async () => { + await testAgent.closeStorage(); + }); + + describe('deleteDid()', () => { + let portableDid: PortableDid; + + beforeEach(async () => { + // Create a DID for the test. + portableDid = await DidKeyMethod.create(); + }); + + it('should delete DID and return true if DID exists', async () => { + // Import the first DID and set as the Agent DID. + await testAgent.didManager.import({ did: portableDid }); + testAgent.agentDid = portableDid.did; + + // Test deleting the DID and validate the result. + const deleteResult = await didStoreDwn.deleteDid({ did: portableDid.did, agent: testAgent }); + expect(deleteResult).to.be.true; + + // Verify the DID is no longer in the store. + const storedDid = await didStoreDwn.getDid({ did: portableDid.did, agent: testAgent }); + expect(storedDid).to.be.undefined; + }); + + it('should return false if DID does not exist', async () => { + // Import the first DID and set as the Agent DID. + await testAgent.didManager.import({ did: portableDid }); + testAgent.agentDid = portableDid.did; + + // Test deleting the DID. + const deleteResult = await didStoreDwn.deleteDid({ did: 'non-existent', agent: testAgent }); + + // Validate the DID was not deleted. + expect(deleteResult).to.be.false; + }); + + it('throws an error if Agent DID is undefined and no keys exist for specified DID', async () => { + await expect( + didStoreDwn.deleteDid({ did: 'did:key:z6Mkt3UrUJXwrMzzBwt6XZ91aZYWk2GKvZbSgkZoEGdrRnB5', agent: testAgent }) + ).to.eventually.be.rejectedWith(Error, `Agent property 'agentDid' is undefined and no keys were found for`); + }); + }); + + describe('findDid()', () => { + let portableDid: PortableDid; + + beforeEach(async () => { + // Create a DID for the test. + portableDid = await DidKeyMethod.create(); + }); + + it('should return a DID by identifier if it exists', async () => { + // Import the DID to use for the test. + const importedDid = await testAgent.didManager.import({ did: portableDid, alias: 'social' }); + testAgent.agentDid = importedDid.did; + + // Test finding the DID. + const storedDid = await didStoreDwn.findDid({ did: importedDid.did, agent: testAgent}); + + // Verify the DID is in the store. + if (!storedDid) throw Error(); // Type guard. + expect(storedDid.did).to.equal(importedDid.did); + }); + + it('should return a DID by alias if it exists', async () => { + // Import the DID to use for the test. + const importedDid = await testAgent.didManager.import({ did: portableDid, alias: 'social' }); + testAgent.agentDid = importedDid.did; + + // Test finding the DID. + const storedDid = await didStoreDwn.findDid({ alias: 'social', agent: testAgent}); + + // Verify the DID is in the store. + if (!storedDid) throw Error(); // Type guard. + expect(storedDid.did).to.equal(importedDid.did); + }); + + it('should return undefined when attempting to get a non-existent DID', async () => { + // Import the first DID and set as the Agent DID. + const importedDid = await testAgent.didManager.import({ did: portableDid, alias: 'social' }); + testAgent.agentDid = importedDid.did; + + // Test finding the DID by ID. + expect( + await didStoreDwn.findDid({ did: 'non-existent-did', agent: testAgent }) + ).to.be.undefined; + + // Test finding the DID by alias. + expect( + await didStoreDwn.findDid({ alias: 'non-existent-did', agent: testAgent }) + ).to.be.undefined; + }); + + it('throws an error if Agent DID is undefined and no keys exist for specified DID', async () => { + await expect( + didStoreDwn.findDid({ did: 'did:key:z6Mkt3UrUJXwrMzzBwt6XZ91aZYWk2GKvZbSgkZoEGdrRnB5', agent: testAgent }) + ).to.eventually.be.rejectedWith(Error, `Agent property 'agentDid' is undefined and no keys were found for`); + }); + + it('throws an error if Agent DID is undefined when searching by alias', async () => { + await expect( + didStoreDwn.findDid({ alias: 'external-id', agent: testAgent }) + ).to.eventually.be.rejectedWith(Error, `Agent property 'agentDid' is undefined`); + }); + }); + + describe('getDid()', () => { + it('should return a DID by identifier if it exists', async () => { + // Create did:key DID with key set. + const portableDid = await DidKeyMethod.create(); + + // Import the DID to the DidManager DWN store. + const importedDid = await testAgent.didManager.import({ did: portableDid }); + + // Set the Agent's DID to the imported DID. + testAgent.agentDid = importedDid.did; + + // Test getting the DID. + const storedDid = await didStoreDwn.getDid({ did: portableDid.did, agent: testAgent }); + + // Verify the DID is in the store. + if (storedDid === undefined) throw new Error('Type guard unexpectedly threw'); // Type guard. + expect(storedDid.did).to.equal(importedDid.did); + expect(storedDid.method).to.equal(importedDid.method); + expect(storedDid.document).to.deep.equal(importedDid.document); + }); + + it('should return undefined when attempting to get a non-existent DID', async () => { + // Create did:key DID with key set. + const portableDid = await DidKeyMethod.create(); + + // Import the DID to the DidManager DWN store. + const importedDid = await testAgent.didManager.import({ did: portableDid }); + + // Set the Agent's DID to the imported DID. + testAgent.agentDid = importedDid.did; + + // Test getting the DID. + const storedDid = await didStoreDwn.getDid({ did: 'non-existent', agent: testAgent }); + + // Verify the result is undefined. + expect(storedDid).to.be.undefined; + }); + + it('throws an error if Agent DID is undefined and no keys exist for specified DID', async () => { + await expect( + didStoreDwn.getDid({ did: 'did:key:z6MkmRUyE6ywoYV2zL9Nus2YuFchpnTGzPXToZWDbdag6tvB', agent: testAgent }) + ).to.eventually.be.rejectedWith(Error, `Agent property 'agentDid' is undefined and no keys were found for`); + }); + }); + + describe('importDid()', () => { + it('imports did:key DID and key set', async () => { + // Create did:key DID with key set. + const portableDid = await DidKeyMethod.create({ keyAlgorithm: 'Ed25519' }); + const managedDid = { ...portableDid, method: 'key' }; + + // Import the key set into KeyManager. + // @ts-expect-error because we're accessing a private method. + managedDid.keySet = await testAgent.didManager.importOrGetKeySet({ + keySet : managedDid.keySet, + kms : 'memory' + }); + + // Set the alias for each key to the DID document method ID. + // @ts-expect-error because we're accessing a private method. + await testAgent.didManager.updateKeySet({ + canonicalId : managedDid.canonicalId, + didDocument : managedDid.document, + keySet : managedDid.keySet + }); + + // Import the first DID into the store. + await didStoreDwn.importDid({ + did : managedDid, + agent : testAgent + }); + + // Set the Agent's DID to the imported DID. + testAgent.agentDid = managedDid.did; + + // Try to retrieve the DID from the DidManager store to verify it was imported. + const storedDid = await didStoreDwn.getDid({ did: portableDid.did, agent: testAgent }); + + // Verify the DID is in the store. + if (storedDid === undefined) throw new Error('Type guard unexpectedly threw'); // Type guard. + expect(storedDid.did).to.equal(managedDid.did); + expect(storedDid.method).to.equal(managedDid.method); + expect(storedDid.document).to.deep.equal(managedDid.document); + }); + + it('throws an error when attempting to import a DID that already exists', async () => { + // Create did:key DID with key set. + const portableDid = await DidKeyMethod.create({ keyAlgorithm: 'Ed25519' }); + const managedDid = { ...portableDid, method: 'key' }; + + // Import the key set into KeyManager. + // @ts-expect-error because we're accessing a private method. + managedDid.keySet = await testAgent.didManager.importOrGetKeySet({ + keySet : managedDid.keySet, + kms : 'memory' + }); + + // Set the alias for each key to the DID document method ID. + // @ts-expect-error because we're accessing a private method. + await testAgent.didManager.updateKeySet({ + canonicalId : managedDid.canonicalId, + didDocument : managedDid.document, + keySet : managedDid.keySet + }); + + // Import the first DID into the store. + await didStoreDwn.importDid({ + did : managedDid, + agent : testAgent + }); + + // Set the Agent's DID to the imported DID. + testAgent.agentDid = managedDid.did; + + // Try to import the same key again. + await expect( + didStoreDwn.importDid({ + did : managedDid, + agent : testAgent + }) + ).to.eventually.be.rejectedWith(Error, 'DID with ID already exists'); + }); + + it('authors multiple imports with the same Agent DID', async () => { + // Create and import the Agent DID which will be used to author all record writes. + const portableAgentDid = await DidKeyMethod.create(); + await testAgent.didManager.import({ did: portableAgentDid }); + testAgent.agentDid = portableAgentDid.did; + + // Create two did:key DIDs with key sets to test import. + const portableDid2 = await DidKeyMethod.create(); + const managedDid2 = { ...portableDid2, method: 'key' }; + const portableDid3 = await DidKeyMethod.create(); + const managedDid3 = { ...portableDid3, method: 'key' }; + + // Import the two DIDs. + await didStoreDwn.importDid({ did: managedDid2, agent: testAgent }); + await didStoreDwn.importDid({ did: managedDid3, agent: testAgent }); + + // Get each DID and verify that all three were written under the Agent's DID tenant. + const storedDid1 = await didStoreDwn.getDid({ did: portableAgentDid.did, agent: testAgent }); + const storedDid2 = await didStoreDwn.getDid({ did: portableDid2.did, agent: testAgent }); + const storedDid3 = await didStoreDwn.getDid({ did: portableDid3.did, agent: testAgent }); + if (!(storedDid1 && storedDid2 && storedDid3)) throw new Error('Type guard unexpectedly threw'); // Type guard. + expect(storedDid1.did).to.equal(portableAgentDid.did); + expect(storedDid2.did).to.equal(portableDid2.did); + expect(storedDid3.did).to.equal(portableDid3.did); + }); + + it('throws an error if Agent DID is undefined and no keys exist for imported DID', async () => { + await expect( + didStoreDwn.importDid({ did: testManagedDid, agent: testAgent }) + ).to.eventually.be.rejectedWith(Error, `Agent property 'agentDid' is undefined and no keys were found for`); + }); + }); + + describe('listDids()', () => { + it('should return an array of all DIDs in the store', async () => { + // Create three did:key DIDs with key sets. + const portableDid1 = await DidKeyMethod.create(); + const portableDid2 = await DidKeyMethod.create(); + const portableDid3 = await DidKeyMethod.create(); + + // Import the first DID and set as the Agent DID. + const importedDid1 = await testAgent.didManager.import({ did: portableDid1 }); + testAgent.agentDid = importedDid1.did; + + // Import the other two DIDs under the same DID context. + const importedDid2 = await testAgent.didManager.import({ did: portableDid2, context: testAgent.agentDid }); + const importedDid3 = await testAgent.didManager.import({ did: portableDid3, context: testAgent.agentDid }); + + // List DIDs and verify the result. + const storedDids = await didStoreDwn.listDids({ agent: testAgent }); + expect(storedDids).to.have.length(3); + const importedDids = [importedDid1.did, importedDid2.did, importedDid3.did]; + for (const storedDid of storedDids) { + expect(importedDids).to.include(storedDid.did); + } + }); + + it('throws an error if Agent DID is undefined', async () => { + await expect( + didStoreDwn.listDids({ agent: testAgent }) + ).to.eventually.be.rejectedWith(Error, `Agent property 'agentDid' is undefined`); + }); + }); +}); + +describe('DidStoreMemory', () => { + let didStore: DidStoreMemory; + let testAgent: TestAgent; + let testManagedDid: ManagedDid; + + before(async () => { + testAgent = await TestAgent.create(); + }); + + beforeEach(async () => { + didStore = new DidStoreMemory(); + + const didManager = new DidManager({ + didMethods : [DidKeyMethod], + store : didStore, + agent : testAgent + }); + + testAgent.didManager = didManager; + + // Create did:key DID with key set. + const portableDid = await DidKeyMethod.create({ keyAlgorithm: 'Ed25519' }); + testManagedDid = { ...portableDid, method: 'key' }; + }); + + afterEach(async () => { + await testAgent.clearStorage(); + }); + + after(async () => { + await testAgent.closeStorage(); + }); + + describe('deleteIdentity()', () => { + it('should delete identity and return true if key exists', async () => { + // Import the identity. + await didStore.importDid({ did: testManagedDid }); + + // Test deleting the key and validate the result. + const deleteResult = await didStore.deleteDid({ did: testManagedDid.did }); + expect(deleteResult).to.be.true; + + // Verify the key is no longer in the store. + const storedKey = await didStore.getDid({ did: testManagedDid.did }); + expect(storedKey).to.be.undefined; + }); + + it('should return false if key does not exist', async () => { + // Test deleting the key. + const nonExistentId = '1234'; + const deleteResult = await didStore.deleteDid({ did: nonExistentId }); + + // Validate the key was not deleted. + expect(deleteResult).to.be.false; + }); + }); + + describe('getDid()', () => { + xit('tests needed'); + }); + + describe('findDid()', () => { + xit('tests needed'); + }); + + describe('importDid', () => { + xit('tests needed'); + }); + + describe('listDids', () => { + xit('tests needed'); + }); +}); \ No newline at end of file diff --git a/packages/agent/tests/dwn-manager.spec.ts b/packages/agent/tests/dwn-manager.spec.ts new file mode 100644 index 000000000..5ccdb0cdb --- /dev/null +++ b/packages/agent/tests/dwn-manager.spec.ts @@ -0,0 +1,431 @@ +import chai, { expect } from 'chai'; +import { Convert } from '@web5/common'; +import chaiAsPromised from 'chai-as-promised'; +import { + Dwn, + RecordsRead, + RecordsReadReply, + RecordsQueryReply, + UnionMessageReply, + RecordsQueryMessage, + RecordsWriteMessage, + RecordsDeleteMessage, +} from '@tbd54566975/dwn-sdk-js'; + +import { testDwnUrl } from './test-config.js'; +import { TestAgent } from './utils/test-agent.js'; +import { DwnManager } from '../src/dwn-manager.js'; +import { ManagedIdentity } from '../src/identity-manager.js'; +import { TestManagedAgent } from '../src/test-managed-agent.js'; + +// NOTE: @noble/secp256k1 requires globalThis.crypto polyfill for node.js <=18: https://github.com/paulmillr/noble-secp256k1/blob/main/README.md#usage +// Remove when we move off of node.js v18 to v20, earliest possible time would be Oct 2023: https://github.com/nodejs/release#release-schedule +import { webcrypto } from 'node:crypto'; + +// @ts-ignore +if (!globalThis.crypto) globalThis.crypto = webcrypto; + +chai.use(chaiAsPromised); + +let testDwnUrls: string[] = [testDwnUrl]; + +describe('DwnManager', () => { + + describe('constructor', () => { + it('accepts a custom DWN instance', async () => { + const mockDwn = ({} as unknown) as Dwn; + + // Instantiate DWN Manager with custom DWN instance. + const dwnManager = await DwnManager.create({ dwn: mockDwn }); + + expect(dwnManager).to.exist; + // @ts-expect-error because a private property is being accessed. + expect(dwnManager._dwn).to.exist; + }); + }); + + describe('get agent', () => { + it(`returns the 'agent' instance property`, () => { + // @ts-expect-error because we are only mocking a single property. + const mockAgent: Web5ManagedAgent = { + agentDid: 'did:method:abc123' + }; + const mockDwn = ({} as unknown) as Dwn; + const dwnManager = new DwnManager({ agent: mockAgent, dwn: mockDwn }); + const agent = dwnManager.agent; + expect(agent).to.exist; + expect(agent.agentDid).to.equal('did:method:abc123'); + }); + + it(`throws an error if the 'agent' instance property is undefined`, async () => { + const mockDwn = ({} as unknown) as Dwn; + const dwnManager = await DwnManager.create({ dwn: mockDwn }); + expect(() => + dwnManager.agent + ).to.throw(Error, 'Unable to determine agent execution context'); + }); + }); + + describe(`with dwn data stores`, () => { + let testAgent: TestManagedAgent; + + before(async () => { + testAgent = await TestManagedAgent.create({ + agentClass : TestAgent, + agentStores : 'dwn' + }); + }); + + after(async () => { + await testAgent.clearStorage(); + await testAgent.closeStorage(); + }); + + describe('processRequest()', () => { + let identity: ManagedIdentity; + + beforeEach(async () => { + await testAgent.clearStorage(); + await testAgent.createAgentDid(); + // Creates a new Identity to author the DWN messages. + identity = await testAgent.agent.identityManager.create({ + name : 'Alice', + didMethod : 'key', + kms : 'local' + }); + }); + + xit('handles EventsGet'); + xit('handles MessagesGet'); + xit('handles ProtocolsConfigure'); + xit('handles ProtocolsQuery'); + + it('handles RecordsDelete messages', async () => { + // Create test data to write. + const dataBytes = Convert.string('Hello, world!').toUint8Array(); + + // Write a record that can be deleted. + let { message, reply: { status: writeStatus } } = await testAgent.agent.dwnManager.processRequest({ + author : identity.did, + target : identity.did, + messageType : 'RecordsWrite', + messageOptions : { + dataFormat : 'text/plain', + schema : 'https://schemas.xyz/example' + }, + dataStream: new Blob([dataBytes]) + }); + expect(writeStatus.code).to.equal(202); + const writeMessage = message as RecordsWriteMessage; + + // Attempt to process the RecordsRead. + const deleteResponse = await testAgent.agent.dwnManager.processRequest({ + author : identity.did, + target : identity.did, + messageType : 'RecordsDelete', + messageOptions : { + recordId: writeMessage.recordId + } + }); + + // Verify the response. + expect(deleteResponse).to.have.property('message'); + expect(deleteResponse).to.have.property('messageCid'); + expect(deleteResponse).to.have.property('reply'); + + const deleteMessage = deleteResponse.message as RecordsDeleteMessage; + expect(deleteMessage).to.have.property('authorization'); + expect(deleteMessage).to.have.property('descriptor'); + + const deleteReply = deleteResponse.reply as UnionMessageReply; + expect(deleteReply).to.have.property('status'); + expect(deleteReply.status.code).to.equal(202); + }); + + it('handles RecordsQuery messages', async () => { + // Create test data to write. + const dataBytes = Convert.string('Hello, world!').toUint8Array(); + + // Write a record that can be queried for. + let { message, reply: { status: writeStatus } } = await testAgent.agent.dwnManager.processRequest({ + author : identity.did, + target : identity.did, + messageType : 'RecordsWrite', + messageOptions : { + dataFormat : 'text/plain', + schema : 'https://schemas.xyz/example' + }, + dataStream: new Blob([dataBytes]) + }); + expect(writeStatus.code).to.equal(202); + const writeMessage = message as RecordsWriteMessage; + + // Attempt to process the RecordsQuery. + const queryResponse = await testAgent.agent.dwnManager.processRequest({ + author : identity.did, + target : identity.did, + messageType : 'RecordsQuery', + messageOptions : { + filter: { + schema: 'https://schemas.xyz/example' + } + } + }); + + // Verify the response. + expect(queryResponse).to.have.property('message'); + expect(queryResponse).to.have.property('messageCid'); + expect(queryResponse).to.have.property('reply'); + + const queryMessage = queryResponse.message as RecordsQueryMessage; + expect(queryMessage).to.have.property('authorization'); + expect(queryMessage).to.have.property('descriptor'); + + const queryReply = queryResponse.reply as RecordsQueryReply; + expect(queryReply).to.have.property('status'); + expect(queryReply.status.code).to.equal(200); + expect(queryReply.entries).to.exist; + expect(queryReply.entries).to.have.length(1); + expect(queryReply.entries?.[0]).to.have.property('descriptor'); + expect(queryReply.entries?.[0]).to.have.property('encodedData'); + expect(queryReply.entries?.[0]).to.have.property('recordId', writeMessage.recordId); + }); + + it('handles RecordsRead messages', async () => { + // Create test data to write. + const dataBytes = Convert.string('Hello, world!').toUint8Array(); + + // Write a record that can be read. + let { message, reply: { status: writeStatus } } = await testAgent.agent.dwnManager.processRequest({ + author : identity.did, + target : identity.did, + messageType : 'RecordsWrite', + messageOptions : { + dataFormat : 'text/plain', + schema : 'https://schemas.xyz/example' + }, + dataStream: new Blob([dataBytes]) + }); + expect(writeStatus.code).to.equal(202); + const writeMessage = message as RecordsWriteMessage; + + // Attempt to process the RecordsRead. + const readResponse = await testAgent.agent.dwnManager.processRequest({ + author : identity.did, + target : identity.did, + messageType : 'RecordsRead', + messageOptions : { + recordId: writeMessage.recordId + } + }); + + // Verify the response. + expect(readResponse).to.have.property('message'); + expect(readResponse).to.have.property('messageCid'); + expect(readResponse).to.have.property('reply'); + + const readMessage = readResponse.message; + expect(readMessage).to.have.property('authorization'); + expect(readMessage).to.have.property('descriptor'); + + const readReply = readResponse.reply as RecordsReadReply; + expect(readReply).to.have.property('status'); + expect(readReply.status.code).to.equal(200); + expect(readReply).to.have.property('record'); + expect(readReply.record).to.have.property('data'); + expect(readReply.record).to.have.property('descriptor'); + expect(readReply.record).to.have.property('recordId', writeMessage.recordId); + }); + + it('handles RecordsWrite messages', async () => { + // Create test data to write. + const dataBytes = Convert.string('Hello, world!').toUint8Array(); + + // Attempt to process the RecordsWrite + let writeResponse = await testAgent.agent.dwnManager.processRequest({ + author : identity.did, + target : identity.did, + messageType : 'RecordsWrite', + messageOptions : { + dataFormat: 'text/plain' + }, + dataStream: new Blob([dataBytes]) + }); + + // Verify the response. + expect(writeResponse).to.have.property('message'); + expect(writeResponse).to.have.property('messageCid'); + expect(writeResponse).to.have.property('reply'); + + const writeMessage = writeResponse.message as RecordsWriteMessage; + expect(writeMessage).to.have.property('authorization'); + expect(writeMessage).to.have.property('descriptor'); + expect(writeMessage).to.have.property('recordId'); + + const writeReply = writeResponse.reply; + expect(writeReply).to.have.property('status'); + expect(writeReply.status.code).to.equal(202); + }); + }); + + describe('sendDwnRequest()', () => { + let identity: ManagedIdentity; + + before(async () => { + await testAgent.createAgentDid(); + + const services = [{ + id : '#dwn', + type : 'DecentralizedWebNode', + serviceEndpoint : { + encryptionKeys : ['#dwn-enc'], + nodes : testDwnUrls, + signingKeys : ['#dwn-sig'] + } + }]; + + // Creates a new Identity to author the DWN messages. + identity = await testAgent.agent.identityManager.create({ + name : 'Alice', + didMethod : 'ion', + didOptions : { services }, + kms : 'local' + }); + }); + + after(async () => { + await testAgent.clearStorage(); + }); + + it('throws an exception if target DID cannot be resolved', async () => { + await expect( + testAgent.agent.sendDwnRequest({ + author : identity.did, + target : 'did:test:abc123', + messageType : 'RecordsQuery', + messageOptions : { + filter: { + schema: 'https://schemas.xyz/example' + } + } + }) + ).to.eventually.be.rejectedWith(Error, 'DwnManager: methodNotSupported: Method not supported: test'); + }); + + it('throws an exception if target DID has no #dwn service endpoints', async () => { + const identity = await testAgent.agent.identityManager.create({ + name : 'Alice', + didMethod : 'ion', + didOptions : { services: [] }, + kms : 'local' + }); + + await expect( + testAgent.agent.sendDwnRequest({ + author : identity.did, + target : identity.did, + messageType : 'RecordsQuery', + messageOptions : { + filter: { + schema: 'https://schemas.xyz/example' + } + } + }) + ).to.eventually.be.rejectedWith(Error, `has no service endpoints with ID '#dwn'`); + }); + + it('handles RecordsDelete Messages', async () => { + const response = await testAgent.agent.sendDwnRequest({ + author : identity.did, + target : identity.did, + messageType : 'RecordsDelete', + messageOptions : { + recordId: 'abcd123' + } + }); + + expect(response.reply).to.exist; + expect(response.reply.status).to.exist; + expect(response.reply.status.code).to.equal(404); + }); + + it('handles RecordsQuery Messages', async () => { + const response = await testAgent.agent.sendDwnRequest({ + author : identity.did, + target : identity.did, + messageType : 'RecordsQuery', + messageOptions : { + filter: { + schema: 'https://schemas.xyz/example' + } + } + }); + + expect(response.reply).to.exist; + expect(response.message).to.exist; + expect(response.messageCid).to.exist; + expect(response.reply.status).to.exist; + expect(response.reply.entries).to.exist; + expect(response.reply.status.code).to.equal(200); + }); + + it('handles RecordsRead Messages', async () => { + const dataBytes = Convert.string('Hi').toUint8Array(); + + let response = await testAgent.agent.sendDwnRequest({ + author : identity.did, + target : identity.did, + messageType : 'RecordsWrite', + messageOptions : { + dataFormat : 'text/plain', + data : dataBytes + }, + dataStream: new Blob([dataBytes]) + }); + + const message = response.message as RecordsWriteMessage; + + response = await testAgent.agent.sendDwnRequest({ + author : identity.did, + target : identity.did, + messageType : 'RecordsRead', + messageOptions : { + recordId: message.recordId + } + }); + + expect(response.reply.status.code).to.equal(200); + expect(response.message).to.exist; + + const readMessage = response.message as RecordsRead['message']; + expect(readMessage.descriptor.method).to.equal('Read'); + expect(readMessage.descriptor.interface).to.equal('Records'); + + const readReply = response.reply as RecordsReadReply; + expect(readReply.record).to.exist; + + const record = readReply.record as unknown as RecordsWriteMessage & { data: ReadableStream }; + expect(record.recordId).to.equal(message.recordId); + + expect(record.data).to.exist; + expect(record.data instanceof ReadableStream).to.be.true; + + const { value } = await record.data.getReader().read(); + expect(dataBytes).to.eql(value); + }); + + it('throws an error when DwnRequest fails validation', async () => { + await expect( + testAgent.agent.sendDwnRequest({ + author : identity.did, + target : identity.did, + messageType : 'RecordsQuery', + messageOptions : { + filter: true + } + }) + ).to.eventually.be.rejectedWith(Error, '/descriptor/filter: must NOT have fewer than 1 properties'); + }); + }); + }); +}); \ No newline at end of file diff --git a/packages/agent/tests/identity-manager.spec.ts b/packages/agent/tests/identity-manager.spec.ts new file mode 100644 index 000000000..809e41c80 --- /dev/null +++ b/packages/agent/tests/identity-manager.spec.ts @@ -0,0 +1,772 @@ +import { expect } from 'chai'; +import { DidKeyMethod } from '@web5/dids'; + +import type { ManagedDid } from '../src/did-manager.js'; +import type { Web5ManagedAgent } from '../src/types/agent.js'; +import type { ManagedIdentity } from '../src/identity-manager.js'; + +import { TestAgent } from './utils/test-agent.js'; +import { IdentityManager } from '../src/identity-manager.js'; +import { TestManagedAgent } from '../src/test-managed-agent.js'; +import { IdentityStoreDwn, IdentityStoreMemory } from '../src/store-managed-identity.js'; + +describe('IdentityManager', () => { + describe('get agent', () => { + it(`returns the 'agent' instance property`, async () => { + // @ts-expect-error because we are only mocking a single property. + const mockAgent: Web5ManagedAgent = { + agentDid: 'did:method:abc123' + }; + const identityManager = new IdentityManager({ agent: mockAgent }); + const agent = identityManager.agent; + expect(agent).to.exist; + expect(agent.agentDid).to.equal('did:method:abc123'); + }); + + it(`throws an error if the 'agent' instance property is undefined`, () => { + const identityManager = new IdentityManager(); + expect(() => + identityManager.agent + ).to.throw(Error, 'Unable to determine agent execution context'); + }); + }); + + const agentStoreTypes = ['dwn', 'memory'] as const; + agentStoreTypes.forEach((agentStoreType) => { + + describe(`with ${agentStoreType} data stores`, () => { + let testAgent: TestManagedAgent; + + before(async () => { + testAgent = await TestManagedAgent.create({ + agentClass : TestAgent, + agentStores : agentStoreType + }); + }); + + beforeEach(async () => { + await testAgent.clearStorage(); + await testAgent.createAgentDid(); + }); + + afterEach(async () => { + await testAgent.clearStorage(); + }); + + after(async () => { + await testAgent.clearStorage(); + await testAgent.closeStorage(); + }); + + describe('create()', () => { + it('creates a ManagedIdentity with new DID and keys', async () => { + // Create a ManagedIdentity. + const managedIdentity = await testAgent.agent.identityManager.create({ + didMethod : 'key', + name : 'Alice', + kms : 'local' + }); + + // Verify the ManagedIdentity was created with the expected properties. + expect(managedIdentity).to.have.property('did'); + expect(managedIdentity).to.have.property('name'); + + // Confirm the DID was stored in the DidManager store. + const managedDid = await testAgent.agent.didManager.get({ + didRef : managedIdentity.did, + context : managedIdentity.did + }); + expect(managedDid).to.exist; + + // Confirm the keys were stored in the KeyManager store. + if (managedDid === undefined) throw new Error(); + const signingKeyId = await testAgent.agent.didManager.getDefaultSigningKey({ + did: managedDid.did + }); + if (!signingKeyId) throw new Error('Type guard'); + const keyPair = await testAgent.agent.keyManager.getKey({ keyRef: signingKeyId }); + expect(keyPair).to.exist; + expect(keyPair).to.have.property('privateKey'); + expect(keyPair).to.have.property('publicKey'); + }); + + it('creates a ManagedIdentity using an existing DID and key set', async () => { + // Create did:key DID with key set to use to attempt import. + const portableDid = await DidKeyMethod.create({ keyAlgorithm: 'Ed25519' }); + + // Create a ManagedIdentity. + const managedIdentity = await testAgent.agent.identityManager.create({ + did : portableDid, + name : 'Alice', + kms : 'local' + }); + + // Verify the ManagedIdentity was created with the expected properties. + expect(managedIdentity).to.have.property('did', portableDid.did); + expect(managedIdentity).to.have.property('name'); + + // Confirm the DID was stored in the DidManager store. + const managedDid = await testAgent.agent.didManager.get({ + didRef : managedIdentity.did, + context : managedIdentity.did + }); + expect(managedDid).to.exist; + + // Confirm the keys were stored in the KeyManager store. + if (managedDid === undefined) throw new Error('Type guard unexpectedly threw'); // Type guard. + const signingKeyId = await testAgent.agent.didManager.getDefaultSigningKey({ + did: managedDid.did + }); + if (!signingKeyId) throw new Error('Type guard'); + const keyPair = await testAgent.agent.keyManager.getKey({ + keyRef: signingKeyId + }); + expect(keyPair).to.exist; + expect(keyPair).to.have.property('privateKey'); + expect(keyPair).to.have.property('publicKey'); + }); + + // Tests that should only run for DWN-backed stores that provide multi-tenancy. + if (agentStoreType === 'dwn') { + it('creates Identities under the tenant of the new Identity, by default', async () => { + // Create a ManagedDid. + const managedIdentity = await testAgent.agent.identityManager.create({ + didMethod : 'key', + name : 'Alice', + kms : 'local' + }); + + // Verify that the Identity was NOT stored under the Agent's tenant. + let storedIdentity = await testAgent.agent.identityManager.get({ did: managedIdentity.did }); + expect(storedIdentity).to.not.exist; + + // Verify that the Identity WAS stored under the new Identity's tenant. + storedIdentity = await testAgent.agent.identityManager.get({ did: managedIdentity.did, context: managedIdentity.did }); + expect(storedIdentity).to.exist; + }); + + it('creates Identities under the context of the specified DID', async () => { + // Create a ManagedDid. + const managedDid = await testAgent.agent.identityManager.create({ + didMethod : 'key', + name : 'Alice', + kms : 'local', + context : testAgent.agent.agentDid + }); + + // Verify that the Identity WAS stored under the Agent's tenant. + let storedIdentity = await testAgent.agent.identityManager.get({ did: managedDid.did }); + expect(storedIdentity).to.exist; + + // Verify that the Identity was NOT stored under the new Identity's tenant. + storedIdentity = await testAgent.agent.identityManager.get({ did: managedDid.did, context: managedDid.did }); + expect(storedIdentity).to.not.exist; + }); + + it('supports creating a new Identity and importing to Agent tenant', async () => { + // Create a ManagedDid, stored under the new Identity's tenant. + const managedIdentity = await testAgent.agent.identityManager.create({ + didMethod : 'key', + name : 'Alice', + kms : 'local' + }); + + // Attempt to import just the Identity (not DID/keys) to the Agent tenant. + const importedIdentity = await testAgent.agent.identityManager.import({ + context : testAgent.agent.agentDid, + identity : managedIdentity, + kms : 'local' + }); + expect(importedIdentity).to.deep.equal(managedIdentity); + + // Verify that the Identity is stored under the Agent's tenant. + let storedIdentity = await testAgent.agent.identityManager.get({ did: managedIdentity.did }); + expect(storedIdentity).to.exist; + + // Verify that the Identity is also stored under the new Identity's tenant. + storedIdentity = await testAgent.agent.identityManager.get({ did: managedIdentity.did, context: managedIdentity.did }); + expect(storedIdentity).to.exist; + + // Verify the DID ONLY exists under the new Identity's tenant. + let storedDidAgent = await testAgent.agent.didManager.get({ didRef: managedIdentity.did }); + let storedDidNewIdentity = await testAgent.agent.didManager.get({ didRef: managedIdentity.did, context: managedIdentity.did }); + expect(storedDidAgent).to.not.exist; + expect(storedDidNewIdentity).to.exist; + }); + } + }); + + describe('export()', () => { + xit('should be implemented'); + }); + + describe('import()', () => { + it('imports Identity, DID and key set', async () => { + // Create did:key DID with key set to use to attempt import. + const portableDid = await DidKeyMethod.create({ keyAlgorithm: 'Ed25519' }); + + // Create ManagedIdentity to use to attempt import. + const managedIdentity: ManagedIdentity = { + did : portableDid.did, + name : 'Test' + }; + + // Attempt to import the Identity. + const importedIdentity = await testAgent.agent.identityManager.import({ + did : portableDid, + identity : managedIdentity, + kms : 'local' + }); + expect(importedIdentity).to.deep.equal(managedIdentity); + }); + + it('supports importing Identity without DID', async () => { + // Define a DID to use for the test. + const did = 'did:key:z6MkwcqjW8kmk23GVYHRdyfNr4e7eEoKs3MyuGia1TeSd9hk'; + + // Create ManagedIdentity to use to attempt import. + const managedIdentity: ManagedIdentity = { did, name: 'Test' }; + + // Attempt to import the Identity. + const importedIdentity = await testAgent.agent.identityManager.import({ + context : testAgent.agent.agentDid, + identity : managedIdentity, + kms : 'local' + }); + expect(importedIdentity).to.deep.equal(managedIdentity); + + // Verify that Identity WAS stored under the Agent's tenant. + let storedIdentity = await testAgent.agent.identityManager.get({ did: importedIdentity.did }); + expect(storedIdentity).to.exist; + expect(storedIdentity?.did).to.equal(did); + + // Verify no DID exists matching the specified identifier. + let storedDid = await testAgent.agent.didManager.get({ didRef: did }); + expect(storedDid).to.not.exist; + }); + + it('supports importing multiple Identities to the same Identity/tenant', async () => { + // Create and import the first Identity and DID. + const portableDid1 = await DidKeyMethod.create({ keyAlgorithm: 'Ed25519' }); + const managedIdentity1: ManagedIdentity = { did: portableDid1.did, name: 'Test' }; + const importedIdentity1 = await testAgent.agent.identityManager.import({ + context : testAgent.agent.agentDid, + did : portableDid1, + identity : managedIdentity1, + kms : 'local' + }); + + // Create and import a second DID. + const portableDid2 = await DidKeyMethod.create({ keyAlgorithm: 'Ed25519' }); + const managedIdentity2: ManagedIdentity = { did: portableDid2.did, name: 'Test' }; + const importedIdentity2 = await testAgent.agent.identityManager.import({ + context : testAgent.agent.agentDid, + did : portableDid2, + identity : managedIdentity2, + kms : 'local' + }); + + // Verify that Identity 1 WAS stored under the Agent's tenant. + let storedIdentity1 = await testAgent.agent.identityManager.get({ did: importedIdentity1.did }); + expect(storedIdentity1).to.exist; + expect(storedIdentity1?.did).to.equal(portableDid1.did); + + // Verify that Identity 2 WAS stored under the Agent's tenant. + let storedIdentity2 = await testAgent.agent.identityManager.get({ did: importedIdentity2.did }); + expect(storedIdentity2).to.exist; + expect(storedIdentity2?.did).to.equal(portableDid2.did); + }); + + // Tests that should only run for DWN-backed stores that provide multi-tenancy. + if (agentStoreType === 'dwn') { + it('imports Identities under the tenant of the new Identity, by default', async () => { + // Create did:key DID with key set to use to attempt import. + const portableDid = await DidKeyMethod.create({ keyAlgorithm: 'Ed25519' }); + + // Create ManagedIdentity to use to attempt import. + const managedIdentity: ManagedIdentity = { + did : portableDid.did, + name : 'Test' + }; + + // Attempt to import the Identity. + const importedIdentity = await testAgent.agent.identityManager.import({ + did : portableDid, + identity : managedIdentity, + kms : 'local' + }); + expect(importedIdentity).to.deep.equal(managedIdentity); + + // Verify that the Identity was NOT stored under the Agent's tenant. + let storedIdentity = await testAgent.agent.identityManager.get({ did: managedIdentity.did }); + expect(storedIdentity).to.not.exist; + + // Verify that the Identity WAS stored under the new Identity's tenant. + storedIdentity = await testAgent.agent.identityManager.get({ did: managedIdentity.did, context: managedIdentity.did }); + expect(storedIdentity).to.exist; + }); + + it('imports Identities under the context of the specified DID', async () => { + // Create did:key DID with key set to use to attempt import. + const portableDid = await DidKeyMethod.create({ keyAlgorithm: 'Ed25519' }); + + // Create ManagedIdentity to use to attempt import. + const managedIdentity: ManagedIdentity = { + did : portableDid.did, + name : 'Test' + }; + + // Attempt to import the Identity. + const importedIdentity = await testAgent.agent.identityManager.import({ + context : testAgent.agent.agentDid, + did : portableDid, + identity : managedIdentity, + kms : 'local' + }); + expect(importedIdentity).to.deep.equal(managedIdentity); + + // Verify that the Identity was stored under the Agent's tenant. + let storedIdentity = await testAgent.agent.identityManager.get({ did: managedIdentity.did }); + expect(storedIdentity).to.exist; + + // Verify that the Identity was NOT stored under the new Identity's tenant. + storedIdentity = await testAgent.agent.identityManager.get({ did: managedIdentity.did, context: managedIdentity.did }); + expect(storedIdentity).to.not.exist; + }); + + it('throws error if importing Identity without DID if keys for DID not present', async () => { + // Define a DID to use for the test. + const did = 'did:key:z6MkwcqjW8kmk23GVYHRdyfNr4e7eEoKs3MyuGia1TeSd9hk'; + + // Create ManagedIdentity to use to attempt import. + const managedIdentity: ManagedIdentity = { did, name: 'Test' }; + + // Attempt to import the Identity. + await expect( + testAgent.agent.identityManager.import({ + identity : managedIdentity, + kms : 'local' + }) + ).to.eventually.be.rejectedWith(Error, `Signing key not found for author: '${did}'`); + }); + } + }); + + describe('list()', () => { + it('should return an array of all identities', async () => { + // Create three new identities all under the Agent's tenant. + const managedIdentity1 = await testAgent.agent.identityManager.create({ + didMethod : 'key', + name : 'Alice', + kms : 'local', + context : testAgent.agent.agentDid + }); + const managedIdentity2 = await testAgent.agent.identityManager.create({ + didMethod : 'key', + name : 'Alice', + kms : 'local', + context : testAgent.agent.agentDid + }); + const managedIdentity3 = await testAgent.agent.identityManager.create({ + didMethod : 'key', + name : 'Alice', + kms : 'local', + context : testAgent.agent.agentDid + }); + + // List identities and verify the result. + const storedIdentities = await testAgent.agent.identityManager.list(); + expect(storedIdentities).to.have.length(3); + + const createdIdentities = [managedIdentity1.did, managedIdentity2.did, managedIdentity3.did]; + for (const storedIdentity of storedIdentities) { + expect(createdIdentities).to.include(storedIdentity.did); + } + }); + + it('should return an empty array if the store contains no Identities', async () => { + // List identities and verify the result is empty. + const storedIdentities = await testAgent.agent.identityManager.list(); + expect(storedIdentities).to.be.empty; + }); + }); + }); + }); +}); + +describe('IdentityStoreDwn', () => { + let identityStore: IdentityStoreDwn; + let testAgent: TestAgent; + let testManagedDid: ManagedDid; + let testManagedIdentity: ManagedIdentity; + + before(async () => { + testAgent = await TestAgent.create(); + }); + + beforeEach(async () => { + identityStore = new IdentityStoreDwn(); + const identityManager = new IdentityManager({ store: identityStore, agent: testAgent }); + testAgent.identityManager = identityManager; + + // Create did:key DID with key set. + const portableDid = await DidKeyMethod.create({ keyAlgorithm: 'Ed25519' }); + testManagedDid = { ...portableDid, method: 'key' }; + + // Import the key set into KeyManager. + // @ts-expect-error because we're accessing a private method. + testManagedDid.keySet = await testAgent.didManager.importOrGetKeySet({ + keySet : testManagedDid.keySet, + kms : 'memory' + }); + + // Set the alias for each key to the DID document method ID. + // @ts-expect-error because we're accessing a private method. + await testAgent.didManager.updateKeySet({ + canonicalId : testManagedDid.canonicalId, + didDocument : testManagedDid.document, + keySet : testManagedDid.keySet + }); + + // Create a ManagedIdentity to use for tests. + testManagedIdentity = { did: portableDid.did, name: 'Test' }; + }); + + afterEach(async () => { + await testAgent.clearStorage(); + }); + + after(async () => { + await testAgent.closeStorage(); + }); + + describe('deleteIdentity()', () => { + it('should delete Identity and return true if Identity exists', async () => { + // Import the first Identity and set as the Agent DID. + await identityStore.importIdentity({ + identity : testManagedIdentity, + agent : testAgent + }); + testAgent.agentDid = testManagedIdentity.did; + + // Test deleting the DID and validate the result. + const deleteResult = await identityStore.deleteIdentity({ did: testManagedIdentity.did, agent: testAgent }); + expect(deleteResult).to.be.true; + + // Verify the DID is no longer in the store. + const storedDid = await identityStore.getIdentity({ did: testManagedIdentity.did, agent: testAgent }); + expect(storedDid).to.be.undefined; + }); + + it('should return false if Identity does not exist', async () => { + // Import the first Identity and set as the Agent DID. + await identityStore.importIdentity({ + identity : testManagedIdentity, + agent : testAgent + }); + testAgent.agentDid = testManagedIdentity.did; + + // Test deleting the DID. + const deleteResult = await identityStore.deleteIdentity({ did: 'non-existent', agent: testAgent }); + + // Validate the DID was not deleted. + expect(deleteResult).to.be.false; + }); + + it('throws an error if Agent DID is undefined and no keys exist for specified DID', async () => { + await expect( + identityStore.deleteIdentity({ did: 'did:key:z6Mkt3UrUJXwrMzzBwt6XZ91aZYWk2GKvZbSgkZoEGdrRnB5', agent: testAgent }) + ).to.eventually.be.rejectedWith(Error, `Agent property 'agentDid' is undefined and no keys were found for`); + }); + }); + + describe('getIdentity()', () => { + it('should return an Identity by DID if it exists', async () => { + // Import the first Identity and set as the Agent DID. + await identityStore.importIdentity({ + identity : testManagedIdentity, + agent : testAgent + }); + testAgent.agentDid = testManagedIdentity.did; + + // Try to retrieve the Identity from the IdentityManager store to verify it was imported. + const storedIdentity = await identityStore.getIdentity({ did: testManagedIdentity.did, agent: testAgent }); + + // Verify the Identity is in the store. + if (storedIdentity === undefined) throw new Error('Type guard unexpectedly threw'); // Type guard. + expect(storedIdentity.did).to.equal(testManagedIdentity.did); + expect(storedIdentity.name).to.equal(testManagedIdentity.name); + }); + + it('should return undefined when attempting to get a non-existent Identity', async () => { + // Import the first Identity and set as the Agent DID. + await identityStore.importIdentity({ + identity : testManagedIdentity, + agent : testAgent + }); + testAgent.agentDid = testManagedIdentity.did; + + // Try to retrieve a non-existent Identity from the IdentityManager store. + const storedIdentity = await identityStore.getIdentity({ did: 'non-existant', agent: testAgent }); + + // Verify the result is undefined. + expect(storedIdentity).to.be.undefined; + }); + + it('throws an error if Agent DID is undefined and no keys exist for specified DID', async () => { + await expect( + identityStore.getIdentity({ + did : 'did:key:z6MkmRUyE6ywoYV2zL9Nus2YuFchpnTGzPXToZWDbdag6tvB', + agent : testAgent + }) + ).to.eventually.be.rejectedWith(Error, `Agent property 'agentDid' is undefined and no keys were found for`); + }); + }); + + describe('importIdentity()', () => { + it('should import an identity that does not already exist', async () => { + // Import the first Identity and set as the Agent DID. + await identityStore.importIdentity({ + identity : testManagedIdentity, + agent : testAgent + }); + testAgent.agentDid = testManagedIdentity.did; + + // Try to retrieve the Identity from the IdentityManager store to verify it was imported. + const storedIdentity = await identityStore.getIdentity({ did: testManagedIdentity.did, agent: testAgent }); + + // Verify the Identity is in the store. + if (storedIdentity === undefined) throw new Error('Type guard unexpectedly threw'); // Type guard. + expect(storedIdentity.did).to.equal(testManagedIdentity.did); + expect(storedIdentity.name).to.equal(testManagedIdentity.name); + }); + + it('throws an error when attempting to import an identity that already exists', async () => { + // Import the first Identity and set as the Agent DID. + await identityStore.importIdentity({ + identity : testManagedIdentity, + agent : testAgent + }); + testAgent.agentDid = testManagedIdentity.did; + + // Try to import the same key again. + await expect( + identityStore.importIdentity({ + identity : testManagedIdentity, + agent : testAgent + }) + ).to.eventually.be.rejectedWith(Error, 'Identity with DID already exists'); + }); + + it('should author multiple imports with the same Agent DID', async () => { + // Define multiple identities to be added. + const testIdentity2 = { did: 'did:key:456', name: 'Family' }; + const testIdentity3 = { did: 'did:key:789', name: 'Social' }; + + // Import the first Identity and set as the Agent DID. + await identityStore.importIdentity({ + identity : testManagedIdentity, + agent : testAgent + }); + + // Set the Agent's DID to the imported Identity's DID. + testAgent.agentDid = testManagedIdentity.did; + + // Import the other two DIDs. + await identityStore.importIdentity({ + identity : testIdentity2, + agent : testAgent + }); + await identityStore.importIdentity({ + identity : testIdentity3, + agent : testAgent + }); + + // Get each Identity and verify that all three were written using the same author DID. + const storedDid1 = await identityStore.getIdentity({ did: testManagedIdentity.did, agent: testAgent }); + const storedDid2 = await identityStore.getIdentity({ did: testIdentity2.did, agent: testAgent }); + const storedDid3 = await identityStore.getIdentity({ did: testIdentity3.did, agent: testAgent }); + if (!(storedDid1 && storedDid2 && storedDid3)) throw new Error('Type guard unexpectedly threw'); // Type guard. + expect(storedDid1.did).to.equal(testManagedIdentity.did); + expect(storedDid2.did).to.equal(testIdentity2.did); + expect(storedDid3.did).to.equal(testIdentity3.did); + }); + + it('throws an error if Agent DID is undefined and no keys exist for imported DID', async () => { + const testIdentity = { did: 'did:key:z6MkmRUyE6ywoYV2zL9Nus2YuFchpnTGzPXToZWDbdag6tvB', name: 'Test' }; + await expect( + identityStore.importIdentity({ identity: testIdentity, agent: testAgent }) + ).to.eventually.be.rejectedWith(Error, `Agent property 'agentDid' is undefined and no keys were found for`); + }); + }); + + describe('listIdentities()', () => { + it('should return an array of all DIDs in the store', async () => { + // Define multiple identities to be added. + const testIdentity2 = { did: 'did:key:456', name: 'Family' }; + const testIdentity3 = { did: 'did:key:789', name: 'Social' }; + + // Import the first Identity and set as the Agent DID. + await identityStore.importIdentity({ + identity : testManagedIdentity, + agent : testAgent + }); + + // Set the Agent's DID to the imported Identity's DID. + testAgent.agentDid = testManagedIdentity.did; + + // Import the other two DIDs. + await identityStore.importIdentity({ + identity : testIdentity2, + agent : testAgent + }); + await identityStore.importIdentity({ + identity : testIdentity3, + agent : testAgent + }); + + // List DIDs and verify the result. + const storedDids = await identityStore.listIdentities({ agent: testAgent }); + expect(storedDids).to.have.length(3); + const importedDids = [testManagedIdentity.did, testIdentity2.did, testIdentity3.did]; + for (const storedDid of storedDids) { + expect(importedDids).to.include(storedDid.did); + } + }); + + it('throws an error if Agent DID is undefined', async () => { + await expect( + identityStore.listIdentities({ agent: testAgent }) + ).to.eventually.be.rejectedWith(Error, `Agent property 'agentDid' is undefined`); + }); + }); +}); + +describe('IdentityStoreMemory', () => { + let identityStore: IdentityStoreMemory; + let testAgent: TestAgent; + let testManagedDid: ManagedDid; + let testManagedIdentity: ManagedIdentity; + + before(async () => { + testAgent = await TestAgent.create(); + }); + + beforeEach(async () => { + identityStore = new IdentityStoreMemory(); + const identityManager = new IdentityManager({ store: identityStore, agent: testAgent }); + testAgent.identityManager = identityManager; + + // Create did:key DID with key set. + const portableDid = await DidKeyMethod.create({ keyAlgorithm: 'Ed25519' }); + testManagedDid = { ...portableDid, method: 'key' }; + + // Create a ManagedIdentity to use for tests. + testManagedIdentity = { did: portableDid.did, name: 'Test' }; + }); + + afterEach(async () => { + await testAgent.clearStorage(); + }); + + after(async () => { + await testAgent.closeStorage(); + }); + + describe('deleteIdentity()', () => { + it('should delete identity and return true if identity exists', async () => { + // Import the identity. + await identityStore.importIdentity({ identity: { did: testManagedDid.did, name: 'Test' } }); + + // Test deleting the identity and validate the result. + const deleteResult = await identityStore.deleteIdentity({ did: testManagedDid.did }); + expect(deleteResult).to.be.true; + + // Verify the identity is no longer in the store. + const storedIdentity = await identityStore.getIdentity({ did: testManagedDid.did }); + expect(storedIdentity).to.be.undefined; + }); + + it('should return false if identity does not exist', async () => { + // Test deleting the identity. + const nonExistentId = '1234'; + const deleteResult = await identityStore.deleteIdentity({ did: nonExistentId }); + + // Validate the identity was not deleted. + expect(deleteResult).to.be.false; + }); + }); + + describe('getIdentity()', () => { + it('should return a identity by DID if it exists', async () => { + // Import the identity. + await identityStore.importIdentity({ identity: { did: testManagedDid.did, name: 'Test' } }); + + // Test getting the identity. + const storedIdentity = await identityStore.getIdentity({ did: testManagedDid.did }); + + // Verify the identity is in the store. + if (!storedIdentity) throw Error(); // Type guard. + expect(testManagedDid.did).to.equal(storedIdentity.did); + }); + + it('should return undefined when attempting to get a non-existent identity', async () => { + // Test getting the identity. + const storedIdentity = await identityStore.getIdentity({ did: 'non-existent-identity' }); + + // Verify the identity is not in the store. + expect(storedIdentity).to.be.undefined; + }); + }); + + describe('importIdentity', () => { + it('should import an identity that does not already exist', async () => { + // Test importing the identity and validate the result. + await identityStore.importIdentity({ identity: { did: testManagedDid.did, name: 'Test' } }); + + // Verify the identity is present in the identity store. + const storedIdentity = await identityStore.getIdentity({ did: testManagedDid.did }); + if (!storedIdentity) throw Error(); // Type guard. + expect(testManagedDid.did).to.equal(storedIdentity.did); + }); + + it('throws an error when attempting to import an identity that already exists', async () => { + // Import the identity. + await identityStore.importIdentity({ identity: { did: testManagedDid.did, name: 'Test' } }); + + // Set the Agent's DID to the imported Identity's DID. + testAgent.agentDid = testManagedIdentity.did; + + // Try to import the same Identity again. + await expect( + identityStore.importIdentity({ identity: testManagedIdentity }) + ).to.eventually.be.rejectedWith(Error, 'Identity with DID already exists'); + }); + }); + + describe('listIdentities', () => { + it('should return an array of all identities in the store', async () => { + // Define multiple identities to be added. + const testIdentities = [ + { did: 'did:key:123', name: 'Career' }, + { did: 'did:key:456', name: 'Family' }, + { did: 'did:key:789', name: 'Social' } + ]; + + // Import the identities into the store. + for (let identity of testIdentities) { + await identityStore.importIdentity({ identity }); + } + + // List identities and verify the result. + const storedIdentities = await identityStore.listIdentities(); + expect(storedIdentities).to.deep.equal(testIdentities); + }); + + it('should return an empty array if the store contains no identities', async () => { + // List identities and verify the result is empty. + const storedIdentities = await identityStore.listIdentities(); + expect(storedIdentities).to.be.empty; + }); + }); +}); \ No newline at end of file diff --git a/packages/crypto/tests/key-manager.spec.ts b/packages/agent/tests/key-manager.spec.ts similarity index 68% rename from packages/crypto/tests/key-manager.spec.ts rename to packages/agent/tests/key-manager.spec.ts index 277977959..40fddc221 100644 --- a/packages/crypto/tests/key-manager.spec.ts +++ b/packages/agent/tests/key-manager.spec.ts @@ -1,64 +1,63 @@ -import type { KeyManagerOptions } from '../src/key-manager/index.js'; -import type { ManagedKey, ManagedKeyPair, ManagedPrivateKey, Web5Crypto } from '../src/types/index.js'; +import type { Web5Crypto } from '@web5/crypto'; +import sinon from 'sinon'; import { expect } from 'chai'; -import { MemoryStore } from '@tbd54566975/common'; -import { KeyManager, KeyManagerStore } from '../src/key-manager/index.js'; -import { LocalKms, KmsKeyStore, KmsPrivateKeyStore } from '../src/kms-local/index.js'; +import type { KeyManagerOptions } from '../src/key-manager.js'; +import type { ManagedKey, ManagedKeyPair } from '../src/types/managed-key.js'; + +import { LocalKms } from '../src/kms-local.js'; +import { TestAgent } from './utils/test-agent.js'; +import { KeyManager } from '../src/key-manager.js'; +import { KeyStoreMemory } from '../src/store-managed-key.js'; describe('KeyManager', () => { let keyManager: KeyManager; - let keyManagerStore: KeyManagerStore; let localKms: LocalKms; - let kmsKeyStore: KmsKeyStore; - let kmsPrivateKeyStore: KmsPrivateKeyStore; - - beforeEach(() => { - // Instantiate in-memory store for KMS key metadata and public keys. - const kmsMemoryStore = new MemoryStore(); - kmsKeyStore = new KmsKeyStore(kmsMemoryStore); + let testAgent: TestAgent; - // Instantiate in-memory store for KMS private keys. - const memoryPrivateKeyStore = new MemoryStore(); - kmsPrivateKeyStore = new KmsPrivateKeyStore(memoryPrivateKeyStore); + before(async () => { + testAgent = await TestAgent.create(); + }); - // Instantiate local KMS using key stores. - localKms = new LocalKms('local', kmsKeyStore, kmsPrivateKeyStore); + beforeEach(() => { + // Instantiate local KMS using in-memory key stores. + localKms = new LocalKms({ kmsName: 'memory', agent: testAgent }); - // Instantiate in-memory store for KeyManager key metadata. - const kmMemoryStore = new MemoryStore(); - keyManagerStore = new KeyManagerStore({ store: kmMemoryStore }); + // Instantiate KeyManager with in-memory KMS and store. + keyManager = new KeyManager({ kms: { memory: localKms }, agent: testAgent }); + }); - const options: KeyManagerOptions = { - store : keyManagerStore, - kms : { local: localKms }, - }; + afterEach(async () => { + await testAgent.clearStorage(); + }); - keyManager = new KeyManager(options); + after(async () => { + await testAgent.closeStorage(); }); describe('constructor', () => { - it('throws an exception if store and kms inputs are missing', async () => { - // @ts-expect-error because KeyManager is intentionally instantiated without required properties. - expect(() => new KeyManager()).to.throw(TypeError); - }); - - it('throws an exception if store is missing', async () => { - // @ts-expect-error because KeyManager is intentionally instantiated without required properties. - expect(() => new KeyManager({ kms: { local: localKms } })).to.throw(TypeError, 'Required parameter was missing'); + it('will use an in-memory store and local KMS if store and kms inputs are missing', async () => { + expect(() => new KeyManager()).to.not.throw; + const kmsList = keyManager.listKms(); + expect(kmsList[0]).to.equal('memory'); }); it('will use a local KMS if kms is not specified', async () => { - keyManager = new KeyManager({ store: keyManagerStore }); + const store = new KeyStoreMemory(); + keyManager = new KeyManager({ store }); const kmsList = keyManager.listKms(); - expect(kmsList[0]).to.equal('local'); + expect(kmsList[0]).to.equal('memory'); }); }); describe('instances', () => { - it('should not be possible to externally access the KeyManager store', async () => { + xit('should not be possible to externally access the KeyManager store', async () => { + // TODO: This test should be re-enabled once we can use #private variables + // which won't be possible until after support for CJS is dropped. + // Dropping support for CJS is dependent on Electron supporting ESM. + /** * Note: It isn't possible to test that trying to access keyMgr.#store will throw a SyntaxError. * In JavaScript, a SyntaxError is thrown when parsing code before it is executed. This makes it @@ -71,6 +70,65 @@ describe('KeyManager', () => { }); }); + describe('get agent', () => { + it(`returns the 'agent' instance property`, () => { + const agent = testAgent.keyManager.agent; + expect(agent).to.exist; + }); + + it(`throws an error if the 'agent' instance property is undefined`, () => { + const keyManager = new KeyManager(); + expect(() => + keyManager.agent + ).to.throw(Error, 'Unable to determine agent execution context'); + }); + }); + + describe('with two KMS', () => { + beforeEach(() => { + // Instantiate two local KMSs using in-memory key stores. + const localKms1 = new LocalKms({ kmsName: 'one', agent: testAgent }); + const localKms2 = new LocalKms({ kmsName: 'two', agent: testAgent }); + + // Instantiate KeyManager with both KMS instances. + keyManager = new KeyManager({ + kms: { + one : localKms1, + two : localKms2 + } + }); + + // Set the KeyManager's agent instance. + keyManager.agent = testAgent; + }); + + it('should store keys in the specified KMS', async () => { + const keyPair1 = await keyManager.generateKey({ + algorithm : { name: 'ECDSA', namedCurve: 'secp256k1' }, + keyUsages : ['sign', 'verify'], + kms : 'one' + }); + + const keyPair2 = await keyManager.generateKey({ + algorithm : { name: 'ECDSA', namedCurve: 'secp256k1' }, + keyUsages : ['sign', 'verify'], + kms : 'two' + }); + + // Verify that key pair 1 was stored with specified KMS name. + const storedKeyPair1 = await keyManager.getKey({ keyRef: keyPair1.publicKey.id }); + if (!storedKeyPair1) throw new Error('Type guard unexpectedly threw'); // Type guard. + if (!('publicKey' in storedKeyPair1)) throw new Error('Type guard unexpectedly threw'); // Type guard. + expect(storedKeyPair1.publicKey.kms).to.equal('one'); + + // Verify that key pair 2 was stored with specified KMS name. + const storedKeyPair2 = await keyManager.getKey({ keyRef: keyPair2.publicKey.id }); + if (!storedKeyPair2) throw new Error('Type guard unexpectedly threw'); // Type guard. + if (!('publicKey' in storedKeyPair2)) throw new Error('Type guard unexpectedly threw'); // Type guard. + expect(storedKeyPair2.publicKey.kms).to.equal('two'); + }); + }); + describe('decrypt()', () => { let key: ManagedKey; @@ -86,59 +144,39 @@ describe('KeyManager', () => { const plaintext = await keyManager.decrypt({ algorithm: { name : 'AES-CTR', - counter : new ArrayBuffer(16), + counter : new Uint8Array(16), length : 128 }, keyRef : key.id, data : new Uint8Array([1, 2, 3, 4]) }); - expect(plaintext).to.be.instanceOf(ArrayBuffer); + expect(plaintext).to.be.instanceOf(Uint8Array); expect(plaintext.byteLength).to.equal(4); }); - it('accepts input data as ArrayBuffer, DataView, and TypedArray', async () => { - const algorithm = { name: 'AES-CTR', counter: new ArrayBuffer(16), length: 128 }; + it('accepts input data as Uint8Array', async () => { + const algorithm = { name: 'AES-CTR', counter: new Uint8Array(16), length: 128 }; const dataU8A = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); - let plaintext: ArrayBuffer; - - // ArrayBuffer - const dataArrayBuffer = dataU8A.buffer; - plaintext = await keyManager.decrypt({ algorithm, keyRef: key.id, data: dataArrayBuffer }); - expect(plaintext).to.be.instanceOf(ArrayBuffer); - - // DataView - const dataView = new DataView(dataArrayBuffer); - plaintext = await keyManager.decrypt({ algorithm, keyRef: key.id, data: dataView }); - expect(plaintext).to.be.instanceOf(ArrayBuffer); + let plaintext: Uint8Array; // TypedArray - Uint8Array plaintext = await keyManager.decrypt({ algorithm, keyRef: key.id, data: dataU8A }); - expect(plaintext).to.be.instanceOf(ArrayBuffer); - - // TypedArray - Int32Array - const dataI32A = new Int32Array([10, 20, 30, 40]); - plaintext = await keyManager.decrypt({ algorithm, keyRef: key.id, data: dataI32A }); - expect(plaintext).to.be.instanceOf(ArrayBuffer); - - // TypedArray - Uint32Array - const dataU32A = new Uint32Array([8, 7, 6, 5, 4, 3, 2, 1]); - plaintext = await keyManager.decrypt({ algorithm, keyRef: key.id, data: dataU32A }); - expect(plaintext).to.be.instanceOf(ArrayBuffer); + expect(plaintext).to.be.instanceOf(Uint8Array); }); it('decrypts data with AES-CTR', async () => { const plaintext = await keyManager.decrypt({ algorithm: { name : 'AES-CTR', - counter : new ArrayBuffer(16), + counter : new Uint8Array(16), length : 128 }, keyRef : key.id, data : new Uint8Array([1, 2, 3, 4]) }); - expect(plaintext).to.be.instanceOf(ArrayBuffer); + expect(plaintext).to.be.instanceOf(Uint8Array); expect(plaintext.byteLength).to.equal(4); }); @@ -146,7 +184,7 @@ describe('KeyManager', () => { await expect(keyManager.decrypt({ algorithm: { name : 'AES-CTR', - counter : new ArrayBuffer(16), + counter : new Uint8Array(16), length : 128 }, keyRef : 'non-existent-key', @@ -158,7 +196,7 @@ describe('KeyManager', () => { describe('deriveBits()', () => { let otherPartyPublicKey: ManagedKey; let otherPartyPublicCryptoKey: Web5Crypto.CryptoKey; - let ownPrivateKey: ManagedKey; + let ownKeyPair: ManagedKeyPair; beforeEach(async () => { const otherPartyKeyPair = await keyManager.generateKey({ @@ -171,43 +209,42 @@ describe('KeyManager', () => { otherPartyPublicCryptoKey = { algorithm : otherPartyPublicKey.algorithm, extractable : otherPartyPublicKey.extractable, - handle : otherPartyPublicKey.material!, + material : otherPartyPublicKey.material!, type : otherPartyPublicKey.type, usages : otherPartyPublicKey.usages }; - const ownKeyPair = await keyManager.generateKey({ + ownKeyPair = await keyManager.generateKey({ algorithm : { name: 'ECDH', namedCurve: 'secp256k1' }, extractable : false, keyUsages : ['deriveBits', 'deriveKey'] }); - ownPrivateKey = ownKeyPair.privateKey; }); it('generates shared secrets', async () => { const sharedSecret = await keyManager.deriveBits({ algorithm : { name: 'ECDH', publicKey: otherPartyPublicCryptoKey }, - baseKeyRef : ownPrivateKey.id + baseKeyRef : ownKeyPair.privateKey.id }); - expect(sharedSecret).to.be.an('ArrayBuffer'); + expect(sharedSecret).to.be.an('Uint8Array'); expect(sharedSecret.byteLength).to.equal(32); }); it(`accepts 'id' as a baseKey reference`, async () => { const sharedSecret = await keyManager.deriveBits({ algorithm : { name: 'ECDH', publicKey: otherPartyPublicCryptoKey }, - baseKeyRef : ownPrivateKey.id + baseKeyRef : ownKeyPair.privateKey.id }); - expect(sharedSecret).to.be.an('ArrayBuffer'); + expect(sharedSecret).to.be.an('Uint8Array'); expect(sharedSecret.byteLength).to.equal(32); }); it('generates ECDH secp256k1 shared secrets', async () => { const sharedSecret = await keyManager.deriveBits({ algorithm : { name: 'ECDH', publicKey: otherPartyPublicCryptoKey }, - baseKeyRef : ownPrivateKey.id + baseKeyRef : ownKeyPair.privateKey.id }); - expect(sharedSecret).to.be.an('ArrayBuffer'); + expect(sharedSecret).to.be.an('Uint8Array'); expect(sharedSecret.byteLength).to.equal(32); }); @@ -222,21 +259,20 @@ describe('KeyManager', () => { otherPartyPublicCryptoKey = { algorithm : otherPartyPublicKey.algorithm, extractable : otherPartyPublicKey.extractable, - handle : otherPartyPublicKey.material!, + material : otherPartyPublicKey.material!, type : otherPartyPublicKey.type, usages : otherPartyPublicKey.usages }; - const ownKeyPair = await keyManager.generateKey({ + ownKeyPair = await keyManager.generateKey({ algorithm : { name: 'ECDH', namedCurve: 'X25519' }, extractable : false, keyUsages : ['deriveBits'] }); - ownPrivateKey = ownKeyPair.privateKey; const sharedSecret = await keyManager.deriveBits({ algorithm : { name: 'ECDH', publicKey: otherPartyPublicCryptoKey }, - baseKeyRef : ownPrivateKey.id + baseKeyRef : ownKeyPair.privateKey.id }); expect(sharedSecret.byteLength).to.equal(32); }); @@ -264,59 +300,39 @@ describe('KeyManager', () => { const ciphertext = await keyManager.encrypt({ algorithm: { name : 'AES-CTR', - counter : new ArrayBuffer(16), + counter : new Uint8Array(16), length : 128 }, keyRef : key.id, data : new Uint8Array([1, 2, 3, 4]) }); - expect(ciphertext).to.be.instanceOf(ArrayBuffer); + expect(ciphertext).to.be.instanceOf(Uint8Array); expect(ciphertext.byteLength).to.equal(4); }); - it('accepts input data as ArrayBuffer, DataView, and TypedArray', async () => { - const algorithm = { name: 'AES-CTR', counter: new ArrayBuffer(16), length: 128 }; + it('accepts input data as Uint8Array', async () => { + const algorithm = { name: 'AES-CTR', counter: new Uint8Array(16), length: 128 }; const dataU8A = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); - let ciphertext: ArrayBuffer; - - // ArrayBuffer - const dataArrayBuffer = dataU8A.buffer; - ciphertext = await keyManager.encrypt({ algorithm, keyRef: key.id, data: dataArrayBuffer }); - expect(ciphertext).to.be.instanceOf(ArrayBuffer); - - // DataView - const dataView = new DataView(dataArrayBuffer); - ciphertext = await keyManager.encrypt({ algorithm, keyRef: key.id, data: dataView }); - expect(ciphertext).to.be.instanceOf(ArrayBuffer); + let ciphertext: Uint8Array; // TypedArray - Uint8Array ciphertext = await keyManager.encrypt({ algorithm, keyRef: key.id, data: dataU8A }); - expect(ciphertext).to.be.instanceOf(ArrayBuffer); - - // TypedArray - Int32Array - const dataI32A = new Int32Array([10, 20, 30, 40]); - ciphertext = await keyManager.encrypt({ algorithm, keyRef: key.id, data: dataI32A }); - expect(ciphertext).to.be.instanceOf(ArrayBuffer); - - // TypedArray - Uint32Array - const dataU32A = new Uint32Array([8, 7, 6, 5, 4, 3, 2, 1]); - ciphertext = await keyManager.encrypt({ algorithm, keyRef: key.id, data: dataU32A }); - expect(ciphertext).to.be.instanceOf(ArrayBuffer); + expect(ciphertext).to.be.instanceOf(Uint8Array); }); it('encrypts data with AES-CTR', async () => { const ciphertext = await keyManager.encrypt({ algorithm: { name : 'AES-CTR', - counter : new ArrayBuffer(16), + counter : new Uint8Array(16), length : 128 }, keyRef : key.id, data : new Uint8Array([1, 2, 3, 4]) }); - expect(ciphertext).to.be.instanceOf(ArrayBuffer); + expect(ciphertext).to.be.instanceOf(Uint8Array); expect(ciphertext.byteLength).to.equal(4); }); @@ -324,7 +340,7 @@ describe('KeyManager', () => { await expect(keyManager.encrypt({ algorithm: { name : 'AES-CTR', - counter : new ArrayBuffer(16), + counter : new Uint8Array(16), length : 128 }, keyRef : 'non-existent-key', @@ -347,8 +363,8 @@ describe('KeyManager', () => { // Check values that are identical for both keys in the pair. expect(keys.privateKey.algorithm.name).to.equal('ECDSA'); expect(keys.publicKey.algorithm.name).to.equal('ECDSA'); - expect(keys.privateKey.kms).to.equal('local'); - expect(keys.publicKey.kms).to.equal('local'); + expect(keys.privateKey.kms).to.equal('memory'); + expect(keys.publicKey.kms).to.equal('memory'); expect(keys.privateKey.spec).to.be.undefined; expect(keys.publicKey.spec).to.be.undefined; expect(keys.privateKey.state).to.equal('Enabled'); @@ -360,7 +376,7 @@ describe('KeyManager', () => { expect(keys.privateKey.usages).to.deep.equal(['sign']); // Check values unique to the public key. - expect(keys.publicKey.material).to.be.an.instanceOf(ArrayBuffer); + expect(keys.publicKey.material).to.be.an.instanceOf(Uint8Array); expect(keys.publicKey.type).to.equal('public'); expect(keys.publicKey.usages).to.deep.equal(['verify']); }); @@ -468,12 +484,12 @@ describe('KeyManager', () => { }); describe('getKey()', function() { - it('returns the key if it exists in the store', async function() { + it('returns the key by ID if it exists in the store', async function() { // Prepopulate the store with a key. const importedPrivateKey = await keyManager.importKey({ algorithm : { name: 'ECDSA', namedCurve: 'secp256k1' }, extractable : true, - kms : 'local', + kms : 'memory', material : new Uint8Array([1, 2, 3, 4]), type : 'private', usages : ['sign'], @@ -484,6 +500,25 @@ describe('KeyManager', () => { expect(storedPrivateKey).to.deep.equal(importedPrivateKey); }); + it('should return a key by alias if it exists', async () => { + // Prepopulate the store with a key. + const importedPrivateKey = await keyManager.importKey({ + algorithm : { name: 'ECDSA', namedCurve: 'secp256k1' }, + alias : 'did:method:abc123', + extractable : true, + kms : 'memory', + material : new Uint8Array([1, 2, 3, 4]), + type : 'private', + usages : ['sign'], + }); + + // Test finding the key. + const storedPrivateKey = await keyManager.getKey({ keyRef: 'did:method:abc123' }); + + // Verify the key is in the store. + expect(storedPrivateKey).to.deep.equal(importedPrivateKey); + }); + it('should return undefined if the key does not exist in the store', async function() { const keyRef = 'non-existent-key'; @@ -500,7 +535,7 @@ describe('KeyManager', () => { privateKey: { algorithm : { name: 'ECDSA', namedCurve: 'secp256k1' }, extractable : true, - kms : 'local', + kms : 'memory', material : new Uint8Array([1, 2, 3, 4]), type : 'private', usages : ['sign'], @@ -508,7 +543,7 @@ describe('KeyManager', () => { publicKey: { algorithm : { name: 'ECDSA', namedCurve: 'secp256k1' }, extractable : true, - kms : 'local', + kms : 'memory', material : new Uint8Array([1, 2, 3, 4]), type : 'public', usages : ['verify'], @@ -527,8 +562,8 @@ describe('KeyManager', () => { // Check values that are identical for both storedKeyPair in the pair. expect(storedKeyPair.privateKey.algorithm.name).to.equal('ECDSA'); expect(storedKeyPair.publicKey.algorithm.name).to.equal('ECDSA'); - expect(storedKeyPair.privateKey.kms).to.equal('local'); - expect(storedKeyPair.publicKey.kms).to.equal('local'); + expect(storedKeyPair.privateKey.kms).to.equal('memory'); + expect(storedKeyPair.publicKey.kms).to.equal('memory'); expect(storedKeyPair.privateKey.spec).to.be.undefined; expect(storedKeyPair.publicKey.spec).to.be.undefined; expect(storedKeyPair.privateKey.state).to.equal('Enabled'); @@ -540,7 +575,7 @@ describe('KeyManager', () => { expect(storedKeyPair.privateKey.usages).to.deep.equal(['sign']); // Check values unique to the public key. - expect(storedKeyPair.publicKey.material).to.be.an.instanceOf(ArrayBuffer); + expect(storedKeyPair.publicKey.material).to.be.an.instanceOf(Uint8Array); expect(storedKeyPair.publicKey.type).to.equal('public'); expect(storedKeyPair.publicKey.usages).to.deep.equal(['verify']); }); @@ -550,12 +585,12 @@ describe('KeyManager', () => { const importedPrivateKey = await keyManager.importKey({ algorithm : { name: 'ECDSA', namedCurve: 'secp256k1' }, extractable : true, - kms : 'local', + kms : 'memory', material : new Uint8Array([1, 2, 3, 4]), type : 'private', usages : ['sign'], }); - expect(importedPrivateKey.kms).to.equal('local'); + expect(importedPrivateKey.kms).to.equal('memory'); expect(importedPrivateKey).to.exist; // Verify the key is present in the key store. @@ -564,7 +599,7 @@ describe('KeyManager', () => { // Validate the expected values. expect(storedPrivateKey.algorithm.name).to.equal('ECDSA'); - expect(storedPrivateKey.kms).to.equal('local'); + expect(storedPrivateKey.kms).to.equal('memory'); expect(storedPrivateKey.spec).to.be.undefined; expect(storedPrivateKey.state).to.equal('Enabled'); expect(storedPrivateKey.material).to.be.undefined; @@ -577,12 +612,12 @@ describe('KeyManager', () => { const importedPublicKey = await keyManager.importKey({ algorithm : { name: 'ECDSA', namedCurve: 'secp256k1' }, extractable : true, - kms : 'local', + kms : 'memory', material : new Uint8Array([1, 2, 3, 4]), type : 'public', usages : ['verify'], }); - expect(importedPublicKey.kms).to.equal('local'); + expect(importedPublicKey.kms).to.equal('memory'); expect(importedPublicKey).to.exist; // Verify the key is present in the key store. @@ -591,10 +626,10 @@ describe('KeyManager', () => { // Validate the expected values. expect(storedPublicKey.algorithm.name).to.equal('ECDSA'); - expect(storedPublicKey.kms).to.equal('local'); + expect(storedPublicKey.kms).to.equal('memory'); expect(storedPublicKey.spec).to.be.undefined; expect(storedPublicKey.state).to.equal('Enabled'); - expect(storedPublicKey.material).to.be.an.instanceOf(ArrayBuffer); + expect(storedPublicKey.material).to.be.an.instanceOf(Uint8Array); expect(storedPublicKey.type).to.equal('public'); expect(storedPublicKey.usages).to.deep.equal(['verify']); }); @@ -604,12 +639,12 @@ describe('KeyManager', () => { const importedSecretKey = await keyManager.importKey({ algorithm : { name: 'AES-CTR', length: 128 }, extractable : true, - kms : 'local', + kms : 'memory', material : new Uint8Array([1, 2, 3, 4]), type : 'secret', usages : ['encrypt', 'decrypt'], }); - expect(importedSecretKey.kms).to.equal('local'); + expect(importedSecretKey.kms).to.equal('memory'); expect(importedSecretKey).to.exist; // Verify the key is present in the key store. @@ -618,7 +653,7 @@ describe('KeyManager', () => { // Validate the expected values. expect(storedSecretKey.algorithm.name).to.equal('AES-CTR'); - expect(storedSecretKey.kms).to.equal('local'); + expect(storedSecretKey.kms).to.equal('memory'); expect(storedSecretKey.spec).to.be.undefined; expect(storedSecretKey.state).to.equal('Enabled'); expect(storedSecretKey.material).to.be.undefined; @@ -635,7 +670,7 @@ describe('KeyManager', () => { algorithm : { name: 'ECDSA', namedCurve: 'secp256k1' }, extractable : true, id : '1234', - kms : 'local', + kms : 'memory', material : new Uint8Array([1, 2, 3, 4]), type : 'private', usages : ['sign'], @@ -649,7 +684,7 @@ describe('KeyManager', () => { algorithm : { name: 'ECDSA', namedCurve: 'secp256k1' }, extractable : true, id : '1234', - kms : 'local', + kms : 'memory', material : new Uint8Array([1, 2, 3, 4]), type : 'public', usages : ['sign'], @@ -664,7 +699,7 @@ describe('KeyManager', () => { algorithm : { name: 'ECDSA', namedCurve: 'secp256k1' }, extractable : true, id : '1234', - kms : 'local', + kms : 'memory', material : new Uint8Array([1, 2, 3, 4]), type : 'private', usages : ['sign'], @@ -673,7 +708,7 @@ describe('KeyManager', () => { algorithm : { name: 'ECDSA', namedCurve: 'secp256k1' }, extractable : true, id : '1234', - kms : 'local', + kms : 'memory', material : new Uint8Array([1, 2, 3, 4]), type : 'public', usages : ['verify'], @@ -690,7 +725,7 @@ describe('KeyManager', () => { const importedPrivateKey = await keyManager.importKey({ algorithm : { name: 'ECDSA', namedCurve: 'secp256k1' }, extractable : true, - kms : 'local', + kms : 'memory', material : new Uint8Array([1, 2, 3, 4]), type : 'private', usages : ['sign'], @@ -703,13 +738,13 @@ describe('KeyManager', () => { const importedPrivateKey = await keyManager.importKey({ algorithm : { name: 'ECDSA', namedCurve: 'secp256k1' }, extractable : true, - kms : 'local', + kms : 'memory', material : new Uint8Array([1, 2, 3, 4]), type : 'public', usages : ['verify'], }); expect(importedPrivateKey.material).to.exist; - expect(importedPrivateKey.material).to.be.an.instanceOf(ArrayBuffer); + expect(importedPrivateKey.material).to.be.an.instanceOf(Uint8Array); }); it('throws an error if public and private keys are swapped', async () => { @@ -718,7 +753,7 @@ describe('KeyManager', () => { privateKey: { algorithm : { name: 'ECDSA', namedCurve: 'secp256k1' }, extractable : true, - kms : 'local', + kms : 'memory', material : new Uint8Array([1, 2, 3, 4]), type : 'public', usages : ['verify'], @@ -726,7 +761,7 @@ describe('KeyManager', () => { publicKey: { algorithm : { name: 'ECDSA', namedCurve: 'secp256k1' }, extractable : true, - kms : 'local', + kms : 'memory', material : new Uint8Array([1, 2, 3, 4]), type : 'private', usages : ['sign'], @@ -737,16 +772,15 @@ describe('KeyManager', () => { describe('listKms()', function() { it('should return an empty array if no KMSs are specified', function() { - const keyManager = new KeyManager({ store: keyManagerStore, kms: {}, }); + const keyManager = new KeyManager({ kms: {}, }); const kmsList = keyManager.listKms(); expect(kmsList).to.be.an('array').that.is.empty; }); it('should return the names of all KMSs present', function() { const keyManager = new KeyManager({ - store : keyManagerStore, // @ts-expect-error because dummy KMS objects are intentionally used as input. - kms : { 'dummy1': {}, 'dummy2': {} } + kms: { 'dummy1': {}, 'dummy2': {} } }); const kmsList = keyManager.listKms(); expect(kmsList).to.be.an('array').that.includes.members(['dummy1', 'dummy2']); @@ -767,11 +801,11 @@ describe('KeyManager', () => { data : new Uint8Array([51, 52, 53]), }); - expect(signature).to.be.instanceOf(ArrayBuffer); + expect(signature).to.be.instanceOf(Uint8Array); expect(signature.byteLength).to.equal(64); }); - it('accepts input data as ArrayBuffer, DataView, and TypedArray', async () => { + it('accepts input data as Uint8Array', async () => { const algorithm = { name: 'ECDSA', hash: 'SHA-256' }; const dataU8A = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); const keyPair = await keyManager.generateKey({ @@ -780,31 +814,11 @@ describe('KeyManager', () => { keyUsages : ['sign', 'verify'] }); const key = keyPair.privateKey; - let signature: ArrayBuffer; - - // ArrayBuffer - const dataArrayBuffer = dataU8A.buffer; - signature = await keyManager.sign({ algorithm, keyRef: key.id, data: dataArrayBuffer }); - expect(signature).to.be.instanceOf(ArrayBuffer); - - // DataView - const dataView = new DataView(dataArrayBuffer); - signature = await keyManager.sign({ algorithm, keyRef: key.id, data: dataView }); - expect(signature).to.be.instanceOf(ArrayBuffer); + let signature: Uint8Array; // TypedArray - Uint8Array signature = await keyManager.sign({ algorithm, keyRef: key.id, data: dataU8A }); - expect(signature).to.be.instanceOf(ArrayBuffer); - - // TypedArray - Int32Array - const dataI32A = new Int32Array([10, 20, 30, 40]); - signature = await keyManager.sign({ algorithm, keyRef: key.id, data: dataI32A }); - expect(signature).to.be.instanceOf(ArrayBuffer); - - // TypedArray - Uint32Array - const dataU32A = new Uint32Array([8, 7, 6, 5, 4, 3, 2, 1]); - signature = await keyManager.sign({ algorithm, keyRef: key.id, data: dataU32A }); - expect(signature).to.be.instanceOf(ArrayBuffer); + expect(signature).to.be.instanceOf(Uint8Array); }); it('generates ECDSA secp256k1 signatures', async () => { @@ -820,7 +834,7 @@ describe('KeyManager', () => { data : new Uint8Array([51, 52, 53]), }); - expect(signature).to.be.instanceOf(ArrayBuffer); + expect(signature).to.be.instanceOf(Uint8Array); expect(signature.byteLength).to.equal(64); }); @@ -837,7 +851,7 @@ describe('KeyManager', () => { data : new Uint8Array([51, 52, 53]), }); - expect(signature).to.be.instanceOf(ArrayBuffer); + expect(signature).to.be.instanceOf(Uint8Array); expect(signature.byteLength).to.equal(64); }); @@ -850,6 +864,74 @@ describe('KeyManager', () => { }); }); + describe('updateKey()', () => { + let testKey: ManagedKey; + let testKeyPair: ManagedKeyPair; + + beforeEach(async () => { + testKey = await keyManager.generateKey({ + algorithm : { name: 'AES-CTR', length: 128 }, + alias : 'test-key', + extractable : false, + keyUsages : ['encrypt', 'decrypt'], + metadata : { foo: 'bar'} + }); + + testKeyPair = await keyManager.generateKey({ + algorithm : { name: 'ECDSA', namedCurve: 'secp256k1' }, + alias : 'test-key-pair', + extractable : false, + keyUsages : ['sign', 'verify'], + metadata : { foo: 'bar'} + }); + }); + + it('should update a key by ID', async () => { + // Attempt to update the key's alias. + const newAlias = 'did:method:new'; + const updateResult = await keyManager.updateKey({ keyRef: testKey.id, alias: newAlias }); + + // Verify that the alias property was updated. + expect(updateResult).to.be.true; + const storedKey = await keyManager.getKey({ keyRef: testKey.id }); + expect(storedKey).to.have.property('alias', newAlias); + }); + + it('should update a key pair by ID', async () => { + // Attempt to update the key's alias. + const newAlias = 'did:method:new'; + const updateResult = await keyManager.updateKey({ keyRef: testKeyPair.publicKey.id, alias: newAlias }); + + // Verify that the alias property was updated. + expect(updateResult).to.be.true; + const storedKey = await keyManager.getKey({ keyRef: testKeyPair.publicKey.id }); + if (!('privateKey' in storedKey!)) throw new Error('Expected ManagedKeyPair and not ManagedKey'); + expect(storedKey.publicKey).to.have.property('alias', newAlias); + }); + + it('throws an error when key reference is not found', async () => { + await expect( + keyManager.updateKey({ keyRef: 'non-existent', alias: 'new-alias' }) + ).to.eventually.be.rejectedWith(Error, 'Key not found'); + }); + + it('returns false if the update operation failed', async () => { + // Stub the `updateKey()` method of LocalKms to simulate a failed update. + sinon.stub(localKms, 'updateKey').returns(Promise.resolve(false)); + + // Attempt to update the key's alias. + const updateResult = await keyManager.updateKey({ keyRef: testKey.id, alias: '' }); + + // Remove the instance method stub. + sinon.restore(); + + // Verify that the update failed. + expect(updateResult).to.be.false; + const storedKey = await keyManager.getKey({ keyRef: testKey.id }); + expect(storedKey).to.deep.equal(testKey); + }); + }); + describe('verify()', () => { it('returns a boolean result', async () => { const dataU8A = new Uint8Array([51, 52, 53]); @@ -876,7 +958,7 @@ describe('KeyManager', () => { expect(isValid).to.be.true; }); - it('accepts input data as ArrayBuffer, DataView, and TypedArray', async () => { + it('accepts input data as Uint8Array', async () => { const algorithm = { name: 'ECDSA', hash: 'SHA-256' }; const dataU8A = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); const keyPair = await keyManager.generateKey({ @@ -884,37 +966,13 @@ describe('KeyManager', () => { extractable : false, keyUsages : ['sign', 'verify'] }); - let signature: ArrayBuffer; + let signature: Uint8Array; let isValid: boolean; - // ArrayBuffer - const dataArrayBuffer = dataU8A.buffer; - signature = await keyManager.sign({ algorithm, keyRef: keyPair.privateKey.id, data: dataArrayBuffer }); - isValid = await keyManager.verify({ algorithm, keyRef: keyPair.publicKey.id, signature, data: dataArrayBuffer }); - expect(isValid).to.be.true; - - // DataView - const dataView = new DataView(dataArrayBuffer); - signature = await keyManager.sign({ algorithm, keyRef: keyPair.privateKey.id, data: dataView }); - isValid = await keyManager.verify({ algorithm, keyRef: keyPair.publicKey.id, signature, data: dataView }); - expect(isValid).to.be.true; - // TypedArray - Uint8Array signature = await keyManager.sign({ algorithm, keyRef: keyPair.privateKey.id, data: dataU8A }); isValid = await keyManager.verify({ algorithm, keyRef: keyPair.publicKey.id, signature, data: dataU8A }); expect(isValid).to.be.true; - - // TypedArray - Int32Array - const dataI32A = new Int32Array([10, 20, 30, 40]); - signature = await keyManager.sign({ algorithm, keyRef: keyPair.privateKey.id, data: dataI32A }); - isValid = await keyManager.verify({ algorithm, keyRef: keyPair.publicKey.id, signature, data: dataI32A }); - expect(isValid).to.be.true; - - // TypedArray - Uint32Array - const dataU32A = new Uint32Array([8, 7, 6, 5, 4, 3, 2, 1]); - signature = await keyManager.sign({ algorithm, keyRef: keyPair.privateKey.id, data: dataU32A }); - isValid = await keyManager.verify({ algorithm, keyRef: keyPair.publicKey.id, signature, data: dataU32A }); - expect(isValid).to.be.true; }); it('verifies ECDSA secp256k1 signatures', async () => { @@ -953,27 +1011,26 @@ describe('KeyManager', () => { await expect(keyManager.verify({ algorithm : { name: 'ECDSA', hash: 'SHA-256' }, keyRef : 'non-existent-key', - signature : (new Uint8Array([51, 52, 53])).buffer, + signature : (new Uint8Array([51, 52, 53])), data : new Uint8Array([51, 52, 53]) })).to.eventually.be.rejectedWith(Error, 'Key not found'); }); }); - describe('#getKms()', () => { + describe('getKms()', () => { it(`if 'kms' is not specified and there is only one, use it automatically`, async () => { const key = await keyManager.generateKey({ algorithm : { name: 'EdDSA', namedCurve: 'Ed25519' }, keyUsages : ['sign', 'verify'] }); - expect(key.privateKey.kms).to.equal('local'); + expect(key.privateKey.kms).to.equal('memory'); }); it(`throws an error if 'kms' is not specified and there is more than 1`, async () => { // Instantiate KeyManager with two KMSs. const options: KeyManagerOptions = { - store : keyManagerStore, - kms : { + kms: { one : localKms, two : localKms }, @@ -994,118 +1051,4 @@ describe('KeyManager', () => { })).to.eventually.be.rejectedWith(Error, 'Unknown key management system'); }); }); -}); - -describe('KeyManagerStore', () => { - let keyManagerStore: KeyManagerStore; - let testKey: ManagedKey; - - beforeEach(() => { - const memoryStore = new MemoryStore(); - - keyManagerStore = new KeyManagerStore({ store: memoryStore }); - - testKey = { - id : 'testKey', - algorithm : { name: 'AES', length: 256 }, - extractable : true, - kms : 'testKms', - state : 'Enabled', - type : 'secret', - usages : ['encrypt', 'decrypt'], - }; - }); - - describe('deleteKey()', () => { - it('should delete key and return true if key exists', async () => { - // Import the key. - await keyManagerStore.importKey({ key: testKey }); - - // Test deleting the key and validate the result. - const deleteResult = await keyManagerStore.deleteKey({ id: testKey.id }); - expect(deleteResult).to.be.true; - - // Verify the key is no longer in the store. - const storedKey = await keyManagerStore.getKey({ id: testKey.id }); - expect(storedKey).to.be.undefined; - }); - - it('should return false if key does not exist', async () => { - // Test deleting the key. - const nonExistentId = '1234'; - const deleteResult = await keyManagerStore.deleteKey({ id: nonExistentId }); - - // Validate the key was not deleted. - expect(deleteResult).to.be.false; - }); - }); - - describe('getKey()', () => { - it('should return a key if it exists', async () => { - // Import the key. - await keyManagerStore.importKey({ key: testKey }); - - // Test getting the key. - const storedKey = await keyManagerStore.getKey({ id: testKey.id }); - - // Verify the key is in the store. - expect(storedKey).to.deep.equal(testKey); - }); - - it('should return undefined when attempting to get a non-existent key', async () => { - // Test getting the key. - const storedKey = await keyManagerStore.getKey({ id: 'non-existent-key' }); - - // Verify the key is no longer in the store. - expect(storedKey).to.be.undefined; - }); - }); - - describe('importKey()', () => { - it('should import a key that does not already exist', async () => { - // Test importing the key and validate the result. - const importResult = await keyManagerStore.importKey({ key: testKey }); - expect(importResult).to.be.true; - - // Verify the key is present in the key store. - const storedKey = await keyManagerStore.getKey({ id: testKey.id }); - expect(storedKey).to.deep.equal(testKey); - }); - - it('should throw an error when attempting to import a key that already exists', async () => { - // Import the key and validate the result. - const importResult = await keyManagerStore.importKey({ key: testKey }); - expect(importResult).to.be.true; - - // Test importing the key again and assert it throws an error. - const importKey = keyManagerStore.importKey({ key: testKey }); - await expect(importKey).to.eventually.be.rejectedWith(Error, 'Key with ID already exists'); - }); - }); - - describe('listKeys()', () => { - it('should return an array of all keys in the store', async () => { - // Define multiple keys to be added. - const testKeys = [ - { ...testKey, ...{ id: 'key-1' }}, - { ...testKey, ...{ id: 'key-2' }}, - { ...testKey, ...{ id: 'key-3' }} - ]; - - // Import the keys into the store. - for (let key of testKeys) { - await keyManagerStore.importKey({ key }); - } - - // List keys and verify the result. - const storedKeys = await keyManagerStore.listKeys(); - expect(storedKeys).to.deep.equal(testKeys); - }); - - it('should return an empty array if the store contains no keys', async () => { - // List keys and verify the result is empty. - const storedKeys = await keyManagerStore.listKeys(); - expect(storedKeys).to.be.empty; - }); - }); }); \ No newline at end of file diff --git a/packages/crypto/tests/kms-local.spec.ts b/packages/agent/tests/kms-local.spec.ts similarity index 63% rename from packages/crypto/tests/kms-local.spec.ts rename to packages/agent/tests/kms-local.spec.ts index c116f92f4..cac125b92 100644 --- a/packages/crypto/tests/kms-local.spec.ts +++ b/packages/agent/tests/kms-local.spec.ts @@ -1,23 +1,59 @@ -import type { ManagedKey, ManagedKeyPair, ManagedPrivateKey, Web5Crypto } from '../src/types/index.js'; +import type { Web5Crypto } from '@web5/crypto'; import sinon from 'sinon'; import chai, { expect } from 'chai'; import chaiAsPromised from 'chai-as-promised'; -import { MemoryStore } from '@tbd54566975/common'; -import { LocalKms, KmsKeyStore, KmsPrivateKeyStore } from '../src/kms-local/index.js'; +import type { ManagedKey, ManagedKeyPair } from '../src/types/managed-key.js'; + +import { LocalKms } from '../src/kms-local.js'; +import { TestAgent } from './utils/test-agent.js'; +import { KeyStoreMemory, PrivateKeyStoreMemory } from '../src/store-managed-key.js'; chai.use(chaiAsPromised); describe('LocalKms', () => { let kms: LocalKms; + let kmsKeyStore: KeyStoreMemory; + let testAgent: TestAgent; + + before(async () => { + testAgent = await TestAgent.create(); + }); beforeEach(() => { - const memoryKeyStore = new MemoryStore(); - const kmsKeyStore = new KmsKeyStore(memoryKeyStore); - const memoryPrivateKeyStore = new MemoryStore(); - const kmsPrivateKeyStore = new KmsPrivateKeyStore(memoryPrivateKeyStore); - kms = new LocalKms('local', kmsKeyStore, kmsPrivateKeyStore); + kmsKeyStore = new KeyStoreMemory(); + kms = new LocalKms({ kmsName: 'memory', keyStore: kmsKeyStore, agent: testAgent }); + }); + + afterEach(async () => { + await testAgent.clearStorage(); + }); + + after(async () => { + await testAgent.closeStorage(); + }); + + describe('constructor', () => { + it('uses in-memory stores by default if not specified', () => { + expect( + new LocalKms({ kmsName: 'test' }) + ).to.not.throw; + }); + + it('uses keyStore instance, if given', () => { + const keyStore = new KeyStoreMemory(); + expect( + new LocalKms({ kmsName: 'test', keyStore }) + ).to.not.throw; + }); + + it('uses privateKeyStore instance, if given', () => { + const privateKeyStore = new PrivateKeyStoreMemory(); + expect( + new LocalKms({ kmsName: 'test', privateKeyStore }) + ).to.not.throw; + }); }); describe('decrypt()', () => { @@ -35,59 +71,39 @@ describe('LocalKms', () => { const plaintext = await kms.decrypt({ algorithm: { name : 'AES-CTR', - counter : new ArrayBuffer(16), + counter : new Uint8Array(16), length : 128 }, keyRef : key.id, data : new Uint8Array([1, 2, 3, 4]) }); - expect(plaintext).to.be.instanceOf(ArrayBuffer); + expect(plaintext).to.be.instanceOf(Uint8Array); expect(plaintext.byteLength).to.equal(4); }); - it('accepts input data as ArrayBuffer, DataView, and TypedArray', async () => { - const algorithm = { name: 'AES-CTR', counter: new ArrayBuffer(16), length: 128 }; + it('accepts input data as Uint8Array', async () => { + const algorithm = { name: 'AES-CTR', counter: new Uint8Array(16), length: 128 }; const dataU8A = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); - let plaintext: ArrayBuffer; - - // ArrayBuffer - const dataArrayBuffer = dataU8A.buffer; - plaintext = await kms.decrypt({ algorithm, keyRef: key.id, data: dataArrayBuffer }); - expect(plaintext).to.be.instanceOf(ArrayBuffer); - - // DataView - const dataView = new DataView(dataArrayBuffer); - plaintext = await kms.decrypt({ algorithm, keyRef: key.id, data: dataView }); - expect(plaintext).to.be.instanceOf(ArrayBuffer); + let plaintext: Uint8Array; // TypedArray - Uint8Array plaintext = await kms.decrypt({ algorithm, keyRef: key.id, data: dataU8A }); - expect(plaintext).to.be.instanceOf(ArrayBuffer); - - // TypedArray - Int32Array - const dataI32A = new Int32Array([10, 20, 30, 40]); - plaintext = await kms.decrypt({ algorithm, keyRef: key.id, data: dataI32A }); - expect(plaintext).to.be.instanceOf(ArrayBuffer); - - // TypedArray - Uint32Array - const dataU32A = new Uint32Array([8, 7, 6, 5, 4, 3, 2, 1]); - plaintext = await kms.decrypt({ algorithm, keyRef: key.id, data: dataU32A }); - expect(plaintext).to.be.instanceOf(ArrayBuffer); + expect(plaintext).to.be.instanceOf(Uint8Array); }); it('decrypts data with AES-CTR', async () => { const plaintext = await kms.decrypt({ algorithm: { name : 'AES-CTR', - counter : new ArrayBuffer(16), + counter : new Uint8Array(16), length : 128 }, keyRef : key.id, data : new Uint8Array([1, 2, 3, 4]) }); - expect(plaintext).to.be.instanceOf(ArrayBuffer); + expect(plaintext).to.be.instanceOf(Uint8Array); expect(plaintext.byteLength).to.equal(4); }); @@ -95,7 +111,7 @@ describe('LocalKms', () => { await expect(kms.decrypt({ algorithm: { name : 'AES-CTR', - counter : new ArrayBuffer(16), + counter : new Uint8Array(16), length : 128 }, keyRef : 'non-existent-key', @@ -120,7 +136,7 @@ describe('LocalKms', () => { otherPartyPublicCryptoKey = { algorithm : otherPartyPublicKey.algorithm, extractable : otherPartyPublicKey.extractable, - handle : otherPartyPublicKey.material!, + material : otherPartyPublicKey.material!, type : otherPartyPublicKey.type, usages : otherPartyPublicKey.usages }; @@ -138,7 +154,7 @@ describe('LocalKms', () => { algorithm : { name: 'ECDH', publicKey: otherPartyPublicCryptoKey }, baseKeyRef : ownPrivateKey.id }); - expect(sharedSecret).to.be.an('ArrayBuffer'); + expect(sharedSecret).to.be.an('Uint8Array'); expect(sharedSecret.byteLength).to.equal(32); }); @@ -147,7 +163,7 @@ describe('LocalKms', () => { algorithm : { name: 'ECDH', publicKey: otherPartyPublicCryptoKey }, baseKeyRef : ownPrivateKey.id }); - expect(sharedSecret).to.be.an('ArrayBuffer'); + expect(sharedSecret).to.be.an('Uint8Array'); expect(sharedSecret.byteLength).to.equal(32); }); @@ -157,7 +173,7 @@ describe('LocalKms', () => { baseKeyRef : ownPrivateKey.id, length : 64 }); - expect(sharedSecret).to.be.an('ArrayBuffer'); + expect(sharedSecret).to.be.an('Uint8Array'); expect(sharedSecret.byteLength).to.equal(64 / 8); }); @@ -166,7 +182,7 @@ describe('LocalKms', () => { algorithm : { name: 'ECDH', publicKey: otherPartyPublicCryptoKey }, baseKeyRef : ownPrivateKey.id }); - expect(sharedSecret).to.be.an('ArrayBuffer'); + expect(sharedSecret).to.be.an('Uint8Array'); expect(sharedSecret.byteLength).to.equal(32); }); @@ -175,7 +191,7 @@ describe('LocalKms', () => { algorithm : { name: 'ECDH', publicKey: otherPartyPublicCryptoKey }, baseKeyRef : ownPrivateKey.id }); - expect(sharedSecret).to.be.an('ArrayBuffer'); + expect(sharedSecret).to.be.an('Uint8Array'); expect(sharedSecret.byteLength).to.equal(32); }); @@ -190,7 +206,7 @@ describe('LocalKms', () => { otherPartyPublicCryptoKey = { algorithm : otherPartyPublicKey.algorithm, extractable : otherPartyPublicKey.extractable, - handle : otherPartyPublicKey.material!, + material : otherPartyPublicKey.material!, type : otherPartyPublicKey.type, usages : otherPartyPublicKey.usages }; @@ -232,59 +248,39 @@ describe('LocalKms', () => { const ciphertext = await kms.encrypt({ algorithm: { name : 'AES-CTR', - counter : new ArrayBuffer(16), + counter : new Uint8Array(16), length : 128 }, keyRef : key.id, data : new Uint8Array([1, 2, 3, 4]) }); - expect(ciphertext).to.be.instanceOf(ArrayBuffer); + expect(ciphertext).to.be.instanceOf(Uint8Array); expect(ciphertext.byteLength).to.equal(4); }); - it('accepts input data as ArrayBuffer, DataView, and TypedArray', async () => { - const algorithm = { name: 'AES-CTR', counter: new ArrayBuffer(16), length: 128 }; + it('accepts input data as Uint8Array', async () => { + const algorithm = { name: 'AES-CTR', counter: new Uint8Array(16), length: 128 }; const dataU8A = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); - let ciphertext: ArrayBuffer; - - // ArrayBuffer - const dataArrayBuffer = dataU8A.buffer; - ciphertext = await kms.encrypt({ algorithm, keyRef: key.id, data: dataArrayBuffer }); - expect(ciphertext).to.be.instanceOf(ArrayBuffer); - - // DataView - const dataView = new DataView(dataArrayBuffer); - ciphertext = await kms.encrypt({ algorithm, keyRef: key.id, data: dataView }); - expect(ciphertext).to.be.instanceOf(ArrayBuffer); + let ciphertext: Uint8Array; // TypedArray - Uint8Array ciphertext = await kms.encrypt({ algorithm, keyRef: key.id, data: dataU8A }); - expect(ciphertext).to.be.instanceOf(ArrayBuffer); - - // TypedArray - Int32Array - const dataI32A = new Int32Array([10, 20, 30, 40]); - ciphertext = await kms.encrypt({ algorithm, keyRef: key.id, data: dataI32A }); - expect(ciphertext).to.be.instanceOf(ArrayBuffer); - - // TypedArray - Uint32Array - const dataU32A = new Uint32Array([8, 7, 6, 5, 4, 3, 2, 1]); - ciphertext = await kms.encrypt({ algorithm, keyRef: key.id, data: dataU32A }); - expect(ciphertext).to.be.instanceOf(ArrayBuffer); + expect(ciphertext).to.be.instanceOf(Uint8Array); }); it('encrypts data with AES-CTR', async () => { const ciphertext = await kms.encrypt({ algorithm: { name : 'AES-CTR', - counter : new ArrayBuffer(16), + counter : new Uint8Array(16), length : 128 }, keyRef : key.id, data : new Uint8Array([1, 2, 3, 4]) }); - expect(ciphertext).to.be.instanceOf(ArrayBuffer); + expect(ciphertext).to.be.instanceOf(Uint8Array); expect(ciphertext.byteLength).to.equal(4); }); @@ -292,7 +288,7 @@ describe('LocalKms', () => { await expect(kms.encrypt({ algorithm: { name : 'AES-CTR', - counter : new ArrayBuffer(16), + counter : new Uint8Array(16), length : 128 }, keyRef : 'non-existent-key', @@ -315,8 +311,8 @@ describe('LocalKms', () => { // Check values that are identical for both keys in the pair. expect(keys.privateKey.algorithm.name).to.equal('ECDSA'); expect(keys.publicKey.algorithm.name).to.equal('ECDSA'); - expect(keys.privateKey.kms).to.equal('local'); - expect(keys.publicKey.kms).to.equal('local'); + expect(keys.privateKey.kms).to.equal('memory'); + expect(keys.publicKey.kms).to.equal('memory'); expect(keys.privateKey.spec).to.be.undefined; expect(keys.publicKey.spec).to.be.undefined; expect(keys.privateKey.state).to.equal('Enabled'); @@ -328,7 +324,7 @@ describe('LocalKms', () => { expect(keys.privateKey.usages).to.deep.equal(['sign']); // Check values unique to the public key. - expect(keys.publicKey.material).to.be.an.instanceOf(ArrayBuffer); + expect(keys.publicKey.material).to.be.an.instanceOf(Uint8Array); expect(keys.publicKey.type).to.equal('public'); expect(keys.publicKey.usages).to.deep.equal(['verify']); }); @@ -470,8 +466,10 @@ describe('LocalKms', () => { // Check values that are identical for both storedKeyPair in the pair. expect(storedKeyPair.privateKey.algorithm.name).to.equal('ECDSA'); expect(storedKeyPair.publicKey.algorithm.name).to.equal('ECDSA'); - expect(storedKeyPair.privateKey.kms).to.equal('local'); - expect(storedKeyPair.publicKey.kms).to.equal('local'); + expect(storedKeyPair.privateKey.id).to.not.equal(''); + expect(storedKeyPair.publicKey.id).to.not.equal(''); + expect(storedKeyPair.privateKey.kms).to.equal('memory'); + expect(storedKeyPair.publicKey.kms).to.equal('memory'); expect(storedKeyPair.privateKey.spec).to.be.undefined; expect(storedKeyPair.publicKey.spec).to.be.undefined; expect(storedKeyPair.privateKey.state).to.equal('Enabled'); @@ -483,7 +481,7 @@ describe('LocalKms', () => { expect(storedKeyPair.privateKey.usages).to.deep.equal(['sign']); // Check values unique to the public key. - expect(storedKeyPair.publicKey.material).to.be.an.instanceOf(ArrayBuffer); + expect(storedKeyPair.publicKey.material).to.be.an.instanceOf(Uint8Array); expect(storedKeyPair.publicKey.type).to.equal('public'); expect(storedKeyPair.publicKey.usages).to.deep.equal(['verify']); }); @@ -498,7 +496,7 @@ describe('LocalKms', () => { type : 'private', usages : ['sign'], }); - expect(importedPrivateKey.kms).to.equal('local'); + expect(importedPrivateKey.kms).to.equal('memory'); expect(importedPrivateKey).to.exist; // Verify the key is present in the key store. @@ -507,7 +505,8 @@ describe('LocalKms', () => { // Validate the expected values. expect(storedPrivateKey.algorithm.name).to.equal('ECDSA'); - expect(storedPrivateKey.kms).to.equal('local'); + expect(storedPrivateKey.id).to.not.equal(''); + expect(storedPrivateKey.kms).to.equal('memory'); expect(storedPrivateKey.spec).to.be.undefined; expect(storedPrivateKey.state).to.equal('Enabled'); expect(storedPrivateKey.material).to.be.undefined; @@ -525,7 +524,7 @@ describe('LocalKms', () => { type : 'public', usages : ['verify'], }); - expect(importedPublicKey.kms).to.equal('local'); + expect(importedPublicKey.kms).to.equal('memory'); expect(importedPublicKey).to.exist; // Verify the key is present in the key store. @@ -534,10 +533,11 @@ describe('LocalKms', () => { // Validate the expected values. expect(storedPublicKey.algorithm.name).to.equal('ECDSA'); - expect(storedPublicKey.kms).to.equal('local'); + expect(storedPublicKey.id).to.not.equal(''); + expect(storedPublicKey.kms).to.equal('memory'); expect(storedPublicKey.spec).to.be.undefined; expect(storedPublicKey.state).to.equal('Enabled'); - expect(storedPublicKey.material).to.be.an.instanceOf(ArrayBuffer); + expect(storedPublicKey.material).to.be.an.instanceOf(Uint8Array); expect(storedPublicKey.type).to.equal('public'); expect(storedPublicKey.usages).to.deep.equal(['verify']); }); @@ -547,12 +547,12 @@ describe('LocalKms', () => { const importedSecretKey = await kms.importKey({ algorithm : { name: 'AES-CTR', length: 128 }, extractable : true, - kms : 'local', + kms : 'memory', material : new Uint8Array([1, 2, 3, 4]), type : 'secret', usages : ['encrypt', 'decrypt'], }); - expect(importedSecretKey.kms).to.equal('local'); + expect(importedSecretKey.kms).to.equal('memory'); expect(importedSecretKey).to.exist; // Verify the key is present in the key store. @@ -561,7 +561,7 @@ describe('LocalKms', () => { // Validate the expected values. expect(storedSecretKey.algorithm.name).to.equal('AES-CTR'); - expect(storedSecretKey.kms).to.equal('local'); + expect(storedSecretKey.kms).to.equal('memory'); expect(storedSecretKey.spec).to.be.undefined; expect(storedSecretKey.state).to.equal('Enabled'); expect(storedSecretKey.material).to.be.undefined; @@ -581,7 +581,7 @@ describe('LocalKms', () => { type : 'private', usages : ['sign'], }); - expect(importedPrivateKey.kms).to.equal('local'); + expect(importedPrivateKey.kms).to.equal('memory'); }); it(`ignores the 'id' property and overwrites with internally generated unique identifier`, async () => { @@ -665,7 +665,7 @@ describe('LocalKms', () => { usages : ['verify'], }); expect(importedPrivateKey.material).to.exist; - expect(importedPrivateKey.material).to.be.an.instanceOf(ArrayBuffer); + expect(importedPrivateKey.material).to.be.an.instanceOf(Uint8Array); }); it('throws an error if public and private keys are swapped', async () => { @@ -722,7 +722,7 @@ describe('LocalKms', () => { await expect(kms.importKey({ algorithm : { name: 'AES-CTR', length: 128 }, extractable : true, - kms : 'local', + kms : 'memory', material : new Uint8Array([1, 2, 3, 4]), type : 'invalid', usages : ['encrypt', 'decrypt'], @@ -744,11 +744,11 @@ describe('LocalKms', () => { data : new Uint8Array([51, 52, 53]), }); - expect(signature).to.be.instanceOf(ArrayBuffer); + expect(signature).to.be.instanceOf(Uint8Array); expect(signature.byteLength).to.equal(64); }); - it('accepts input data as ArrayBuffer, DataView, and TypedArray', async () => { + it('accepts input data as Uint8Array', async () => { const algorithm = { name: 'ECDSA', hash: 'SHA-256' }; const dataU8A = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); const keyPair = await kms.generateKey({ @@ -757,31 +757,11 @@ describe('LocalKms', () => { keyUsages : ['sign', 'verify'] }); const key = keyPair.privateKey; - let signature: ArrayBuffer; - - // ArrayBuffer - const dataArrayBuffer = dataU8A.buffer; - signature = await kms.sign({ algorithm, keyRef: key.id, data: dataArrayBuffer }); - expect(signature).to.be.instanceOf(ArrayBuffer); - - // DataView - const dataView = new DataView(dataArrayBuffer); - signature = await kms.sign({ algorithm, keyRef: key.id, data: dataView }); - expect(signature).to.be.instanceOf(ArrayBuffer); + let signature: Uint8Array; // TypedArray - Uint8Array signature = await kms.sign({ algorithm, keyRef: key.id, data: dataU8A }); - expect(signature).to.be.instanceOf(ArrayBuffer); - - // TypedArray - Int32Array - const dataI32A = new Int32Array([10, 20, 30, 40]); - signature = await kms.sign({ algorithm, keyRef: key.id, data: dataI32A }); - expect(signature).to.be.instanceOf(ArrayBuffer); - - // TypedArray - Uint32Array - const dataU32A = new Uint32Array([8, 7, 6, 5, 4, 3, 2, 1]); - signature = await kms.sign({ algorithm, keyRef: key.id, data: dataU32A }); - expect(signature).to.be.instanceOf(ArrayBuffer); + expect(signature).to.be.instanceOf(Uint8Array); }); it('generates ECDSA secp256k1 signatures', async () => { @@ -797,7 +777,7 @@ describe('LocalKms', () => { data : new Uint8Array([51, 52, 53]), }); - expect(signature).to.be.instanceOf(ArrayBuffer); + expect(signature).to.be.instanceOf(Uint8Array); expect(signature.byteLength).to.equal(64); }); @@ -814,7 +794,7 @@ describe('LocalKms', () => { data : new Uint8Array([51, 52, 53]), }); - expect(signature).to.be.instanceOf(ArrayBuffer); + expect(signature).to.be.instanceOf(Uint8Array); expect(signature.byteLength).to.equal(64); }); @@ -827,6 +807,75 @@ describe('LocalKms', () => { }); }); + describe('updateKey()', () => { + let testKey: ManagedKey; + let testKeyPair: ManagedKeyPair; + + beforeEach(async () => { + testKey = await kms.generateKey({ + algorithm : { name: 'AES-CTR', length: 128 }, + alias : 'test-key', + extractable : false, + keyUsages : ['encrypt', 'decrypt'], + metadata : { foo: 'bar'} + }); + + testKeyPair = await kms.generateKey({ + algorithm : { name: 'ECDSA', namedCurve: 'secp256k1' }, + alias : 'test-key-pair', + extractable : false, + keyUsages : ['sign', 'verify'], + metadata : { foo: 'bar'} + }); + }); + + it('should update a key by ID', async () => { + // Attempt to update the key's alias. + const newAlias = 'did:method:new'; + const updateResult = await kms.updateKey({ keyRef: testKey.id, alias: newAlias }); + + // Verify that the alias property was updated. + expect(updateResult).to.be.true; + const storedKey = await kms.getKey({ keyRef: testKey.id }); + expect(storedKey).to.have.property('alias', newAlias); + }); + + it('should update a key pair by ID', async () => { + // Attempt to update the key's alias. + const newAlias = 'did:method:new'; + const updateResult = await kms.updateKey({ keyRef: testKeyPair.publicKey.id, alias: newAlias }); + + // Verify that the alias property was updated. + expect(updateResult).to.be.true; + const storedKey = await kms.getKey({ keyRef: testKeyPair.publicKey.id }); + if (!('privateKey' in storedKey!)) throw new Error('Expected ManagedKeyPair and not ManagedKey'); + expect(storedKey.publicKey).to.have.property('alias', newAlias); + }); + + it('throws an error when key reference is not found', async () => { + await expect( + kms.updateKey({ keyRef: 'non-existent', alias: 'new-alias' }) + ).to.eventually.be.rejectedWith(Error, 'Key not found'); + }); + + it('returns false if the update operation failed', async () => { + /** Stub the `updateKey()` method of the kmsKeyStore instance of + * KeyStoreMemory to simulate a failed update. */ + sinon.stub(kmsKeyStore, 'updateKey').returns(Promise.resolve(false)); + + // Attempt to update the key's alias. + const updateResult = await kms.updateKey({ keyRef: testKey.id, alias: '' }); + + // Remove the instance method stub. + sinon.restore(); + + // Verify that the update failed. + expect(updateResult).to.be.false; + const storedKey = await kms.getKey({ keyRef: testKey.id }); + expect(storedKey).to.deep.equal(testKey); + }); + }); + describe('verify()', () => { it('returns a boolean result', async () => { const dataU8A = new Uint8Array([51, 52, 53]); @@ -853,7 +902,7 @@ describe('LocalKms', () => { expect(isValid).to.be.true; }); - it('accepts input data as ArrayBuffer, DataView, and TypedArray', async () => { + it('accepts input data as Uint8Array', async () => { const algorithm = { name: 'ECDSA', hash: 'SHA-256' }; const dataU8A = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); const keyPair = await kms.generateKey({ @@ -861,37 +910,13 @@ describe('LocalKms', () => { extractable : false, keyUsages : ['sign', 'verify'] }); - let signature: ArrayBuffer; + let signature: Uint8Array; let isValid: boolean; - // ArrayBuffer - const dataArrayBuffer = dataU8A.buffer; - signature = await kms.sign({ algorithm, keyRef: keyPair.privateKey.id, data: dataArrayBuffer }); - isValid = await kms.verify({ algorithm, keyRef: keyPair.publicKey.id, signature, data: dataArrayBuffer }); - expect(isValid).to.be.true; - - // DataView - const dataView = new DataView(dataArrayBuffer); - signature = await kms.sign({ algorithm, keyRef: keyPair.privateKey.id, data: dataView }); - isValid = await kms.verify({ algorithm, keyRef: keyPair.publicKey.id, signature, data: dataView }); - expect(isValid).to.be.true; - // TypedArray - Uint8Array signature = await kms.sign({ algorithm, keyRef: keyPair.privateKey.id, data: dataU8A }); isValid = await kms.verify({ algorithm, keyRef: keyPair.publicKey.id, signature, data: dataU8A }); expect(isValid).to.be.true; - - // TypedArray - Int32Array - const dataI32A = new Int32Array([10, 20, 30, 40]); - signature = await kms.sign({ algorithm, keyRef: keyPair.privateKey.id, data: dataI32A }); - isValid = await kms.verify({ algorithm, keyRef: keyPair.publicKey.id, signature, data: dataI32A }); - expect(isValid).to.be.true; - - // TypedArray - Uint32Array - const dataU32A = new Uint32Array([8, 7, 6, 5, 4, 3, 2, 1]); - signature = await kms.sign({ algorithm, keyRef: keyPair.privateKey.id, data: dataU32A }); - isValid = await kms.verify({ algorithm, keyRef: keyPair.publicKey.id, signature, data: dataU32A }); - expect(isValid).to.be.true; }); it('verifies ECDSA secp256k1 signatures', async () => { @@ -930,60 +955,19 @@ describe('LocalKms', () => { await expect(kms.verify({ algorithm : { name: 'ECDSA', hash: 'SHA-256' }, keyRef : 'non-existent-key', - signature : (new Uint8Array([51, 52, 53])).buffer, + signature : (new Uint8Array([51, 52, 53])), data : new Uint8Array([51, 52, 53]) })).to.eventually.be.rejectedWith(Error, 'Key not found'); }); - }); - - describe('#getAlgorithm', function() { - /** - * We can't directly test private methods, but we can indirectly - * test their behavior through the methods that use them. Since - * #getAlgorithm() is used in the generateKey() method, we can - * test this methods with known algorithm names. - */ - it('does not throw an error when a supported algorithm is specified', async () => { - await expect(kms.generateKey({ - algorithm : { name: 'ECDSA', namedCurve: 'secp256k1' }, - keyUsages : ['sign', 'verify'] - })).to.eventually.be.fulfilled; - }); - - it('throws error when an unsupported algorithm is specified', async () => { - await expect(kms.generateKey({ - algorithm : { name: 'not-valid' }, - keyUsages : [] - })).to.eventually.be.rejectedWith(Error, 'is not supported'); - }); - }); - - describe('#toCryptoKey', function() { - /** - * We can't directly test private methods, but we can indirectly - * test their behavior through the methods that use them. Since - * #toCryptoKey() is used in the verify() method, we can - * test this methods with known algorithm names. - */ - - let getKeyStub: sinon.SinonStub; - let kms: LocalKms; - let kmsKeyStore: KmsKeyStore; - beforeEach(() => { - const kmsMemoryStore = new MemoryStore(); - kmsKeyStore = new KmsKeyStore(kmsMemoryStore); - const kmsPrivateMemoryStore = new MemoryStore(); - const kmsPrivateKeyStore = new KmsPrivateKeyStore(kmsPrivateMemoryStore); - kms = new LocalKms('local', kmsKeyStore, kmsPrivateKeyStore); - }); + it('throws error when public key material is missing', async () => { + let getKeyStub: sinon.SinonStub; + let kms: LocalKms; + let kmsKeyStore: KeyStoreMemory; - afterEach(() => { - // Restore the original KmsKeyStore getKey() method after each test. - getKeyStub.restore(); - }); + kmsKeyStore = new KeyStoreMemory(); + kms = new LocalKms({ kmsName: 'memory', keyStore: kmsKeyStore, agent: testAgent }); - it('throws error when key material is missing', async () => { const keyPair = await kms.generateKey({ algorithm : { name: 'ECDSA', namedCurve: 'secp256k1' }, extractable : false, @@ -992,275 +976,38 @@ describe('LocalKms', () => { getKeyStub = sinon.stub(kmsKeyStore, 'getKey'); getKeyStub.returns(Promise.resolve({ privateKey: {}, publicKey: {} })); + await expect(kms.verify({ algorithm : { name: 'ECDSA', hash: 'SHA-256' }, keyRef : keyPair.publicKey.id, - signature : new ArrayBuffer(64), + signature : new Uint8Array(64), data : new Uint8Array([51, 52, 53]) })).to.eventually.be.rejectedWith(Error, `Required property missing: 'material'`); - }); - }); -}); -describe('KmsKeyStore', () => { - let kmsKeyStore: KmsKeyStore; - let testKey: ManagedKey; - - beforeEach(() => { - const memoryStore = new MemoryStore(); - - kmsKeyStore = new KmsKeyStore(memoryStore); - - testKey = { - id : 'testKey', - algorithm : { name: 'AES', length: 256 }, - extractable : true, - kms : 'testKms', - state : 'Enabled', - type : 'secret', - usages : ['encrypt', 'decrypt'], - }; - }); - - describe('deleteKey()', () => { - it('should delete key and return true if key exists', async () => { - // Import the key. - await kmsKeyStore.importKey({ key: testKey }); - - // Test deleting the key and validate the result. - const deleteResult = await kmsKeyStore.deleteKey({ id: testKey.id }); - expect(deleteResult).to.be.true; - - // Verify the key is no longer in the store. - const storedKey = await kmsKeyStore.getKey({ id: testKey.id }); - expect(storedKey).to.be.undefined; - }); - - it('should return false if key does not exist', async () => { - // Test deleting the key. - const nonExistentId = '1234'; - const deleteResult = await kmsKeyStore.deleteKey({ id: nonExistentId }); - - // Validate the key was not deleted. - expect(deleteResult).to.be.false; - }); - }); - - describe('getKey()', () => { - it('should return a key if it exists', async () => { - // Import the key. - await kmsKeyStore.importKey({ key: testKey }); - - // Test getting the key. - const storedKey = await kmsKeyStore.getKey({ id: testKey.id }); - - // Verify the key is in the store. - expect(storedKey).to.deep.equal(testKey); - }); - - it('should return undefined when attempting to get a non-existent key', async () => { - // Test getting the key. - const storedKey = await kmsKeyStore.getKey({ id: 'non-existent-key' }); - - // Verify the key is no longer in the store. - expect(storedKey).to.be.undefined; - }); - }); - - describe('importKey()', () => { - it('should import a key that does not already exist', async () => { - // Test importing the key and validate the result. - const importResult = await kmsKeyStore.importKey({ key: testKey }); - expect(importResult).to.equal(testKey.id); - expect(importResult).to.be.a.string; - - // Verify the key is present in the key store. - const storedKey = await kmsKeyStore.getKey({ id: testKey.id }); - expect(storedKey).to.deep.equal(testKey); - }); - - it('should generate and return an ID if one is not provided', async () => { - const testKey = { - algorithm : { name: 'AES', length: 256 }, - extractable : true, - kms : 'testKms', - state : 'Enabled', - type : 'secret', - usages : ['encrypt', 'decrypt'], - }; - - // Test importing the key and validate the result. - // @ts-expect-error because the ID property was intentionally omitted from the key object to be imported. - const importResult = await kmsKeyStore.importKey({ key: testKey }); - expect(importResult).to.be.a.string; - - // Verify the key is present in the key store. - const storedKey = await kmsKeyStore.getKey({ id: importResult }) as ManagedKey; - expect(storedKey.id).to.equal(importResult); - }); - - it('should throw an error when attempting to import a key that already exists', async () => { - // Import the key and validate the result. - const importResult = await kmsKeyStore.importKey({ key: testKey }); - expect(importResult).to.equal(testKey.id); - - // Test importing the key and assert it throws an error. - const importKey = kmsKeyStore.importKey({ key: testKey }); - await expect(importKey).to.eventually.be.rejectedWith(Error, 'Key with ID already exists'); - }); - }); - - describe('listKeys()', () => { - it('should return an array of all keys in the store', async () => { - // Define multiple keys to be added. - const testKeys = [ - { ...testKey, ...{ id: 'key-1' }}, - { ...testKey, ...{ id: 'key-2' }}, - { ...testKey, ...{ id: 'key-3' }} - ]; - - // Import the keys into the store. - for (let key of testKeys) { - await kmsKeyStore.importKey({ key }); - } - - // List keys and verify the result. - const storedKeys = await kmsKeyStore.listKeys(); - expect(storedKeys).to.deep.equal(testKeys); - }); - - it('should return an empty array if the store contains no keys', async () => { - // List keys and verify the result is empty. - const storedKeys = await kmsKeyStore.listKeys(); - expect(storedKeys).to.be.empty; - }); - }); -}); - -describe('KmsPrivateKeyStore', () => { - let kmsPrivateKeyStore: KmsPrivateKeyStore; - let testKey: Omit; - let keyMaterial: ArrayBuffer; - - beforeEach(() => { - const memoryStore = new MemoryStore(); - - kmsPrivateKeyStore = new KmsPrivateKeyStore(memoryStore); - - keyMaterial = (new Uint8Array([1, 2, 3])).buffer; - testKey = { - material : (new Uint8Array([1, 2, 3])).buffer, - type : 'private', - }; - }); - - describe('deleteKey()', () => { - it('should delete key and return true if key exists', async () => { - // Import the key and get back the assigned ID. - const id = await kmsPrivateKeyStore.importKey({ key: testKey }); - - // Test deleting the key and validate the result. - const deleteResult = await kmsPrivateKeyStore.deleteKey({ id }); - expect(deleteResult).to.be.true; - - // Verify the key is no longer in the store. - const storedKey = await kmsPrivateKeyStore.getKey({ id }); - expect(storedKey).to.be.undefined; - }); - - it('should return false if key does not exist', async () => { - // Test deleting the key. - const deleteResult = await kmsPrivateKeyStore.deleteKey({ id: 'non-existent-key' }); - - // Validate the key was deleted. - expect(deleteResult).to.be.false; - }); - }); - - describe('getKey()', () => { - it('sshould return a key if it exists', async () => { - // Import the key. - const id = await kmsPrivateKeyStore.importKey({ key: testKey }); - - // Test getting the key. - const storedKey = await kmsPrivateKeyStore.getKey({ id }); - - // Verify the key is in the store. - expect(storedKey).to.deep.equal({ id, material: keyMaterial, type: 'private' }); - }); - - it('should return undefined if the specified key does not exist', async () => { - // Test getting the key. - const storedKey = await kmsPrivateKeyStore.getKey({ id: 'non-existent-key' }); - - // Verify the key is no longer in the store. - expect(storedKey).to.be.undefined; - }); - }); - - describe('importKey()', () => { - it('should import a private key and return its ID', async () => { - // Test importing the key. - const id = await kmsPrivateKeyStore.importKey({ key: testKey }); - - // Validate the returned id. - expect(id).to.be.a('string'); - - // Verify the key is present in the private key store. - const storedKey = await kmsPrivateKeyStore.getKey({ id }); - expect(storedKey).to.deep.equal({ id, material: keyMaterial, type: 'private' }); - }); - - it('should permanently transfer the private key material', async () => { - // Test importing the key. - await kmsPrivateKeyStore.importKey({ key: testKey }); - - // Verify that attempting to access the key material after import triggers an error. - // Chrome, Firefox, Node.js, and Firefox report different error messages but all contain 'detached'. - expect(() => new Uint8Array(testKey.material)).to.throw(TypeError, 'detached'); - }); - - it('should throw an error if required parameters are missing', async () => { - // Missing 'material'. - const keyMissingMaterial = { type: 'private' }; - await expect(kmsPrivateKeyStore.importKey({ - // @ts-expect-error because the material property is intentionally omitted to trigger an error. - key: keyMissingMaterial - })).to.eventually.be.rejectedWith(TypeError, `Required parameter was missing: 'material'`); - - // Missing 'type'. - const keyMissingType = { material: new ArrayBuffer(8) }; - await expect(kmsPrivateKeyStore.importKey({ - // @ts-expect-error because the type property is intentionally omitted to trigger an error. - key: keyMissingType - })).to.eventually.be.rejectedWith(TypeError, `Required parameter was missing: 'type'`); + // Restore the original KmsKeyStore getKey() method after each test. + getKeyStub.restore(); }); }); - describe('listKeys()', function() { - it('should return an array of all keys in the store', async function() { - // Define multiple keys to be added. - const testKeys = [ - { ...testKey, material: (new Uint8Array([1, 2, 3])).buffer}, - { ...testKey, material: (new Uint8Array([1, 2, 3])).buffer}, - { ...testKey, material: (new Uint8Array([1, 2, 3])).buffer} - ]; - - // Import the keys into the store. - const expectedTestKeys: ManagedPrivateKey[] = []; - for (let key of testKeys) { - const id = await kmsPrivateKeyStore.importKey({ key }); - expectedTestKeys.push({ id, material: keyMaterial, type: 'private', }); - } - - const storedKeys = await kmsPrivateKeyStore.listKeys(); - expect(storedKeys).to.deep.equal(expectedTestKeys); + describe('getAlgorithm', function() { + /** + * We can't directly test private methods, but we can indirectly + * test their behavior through the methods that use them. Since + * #getAlgorithm() is used in the generateKey() method, we can + * test this methods with known algorithm names. + */ + it('does not throw an error when a supported algorithm is specified', async () => { + await expect(kms.generateKey({ + algorithm : { name: 'ECDSA', namedCurve: 'secp256k1' }, + keyUsages : ['sign', 'verify'] + })).to.eventually.be.fulfilled; }); - it('should return an empty array if the store contains no keys', async function() { - // List keys and verify the result is empty. - const storedKeys = await kmsPrivateKeyStore.listKeys(); - expect(storedKeys).to.be.empty; + it('throws error when an unsupported algorithm is specified', async () => { + await expect(kms.generateKey({ + algorithm : { name: 'not-valid' }, + keyUsages : [] + })).to.eventually.be.rejectedWith(Error, 'is not supported'); }); }); }); \ No newline at end of file diff --git a/packages/agent/tests/store-managed-key.spec.ts b/packages/agent/tests/store-managed-key.spec.ts new file mode 100644 index 000000000..5009a9944 --- /dev/null +++ b/packages/agent/tests/store-managed-key.spec.ts @@ -0,0 +1,1396 @@ +import type { PortableDid } from '@web5/dids'; +import type { Web5Crypto } from '@web5/crypto'; + +import chai, { expect } from 'chai'; +import { DidKeyMethod } from '@web5/dids'; +import chaiAsPromised from 'chai-as-promised'; +import { EdDsaAlgorithm, Jose } from '@web5/crypto'; + +import type { ManagedKey, ManagedKeyPair, ManagedPrivateKey } from '../src/types/managed-key.js'; + +import { LocalKms } from '../src/kms-local.js'; +import { TestAgent } from './utils/test-agent.js'; +import { KeyManager } from '../src/key-manager.js'; +import { cryptoToPortableKeyPair, isManagedKeyPair } from '../src/utils.js'; +import { + KeyStoreDwn, + KeyStoreMemory, + PrivateKeyStoreDwn, + PrivateKeyStoreMemory +} from '../src/store-managed-key.js'; + +chai.use(chaiAsPromised); + +describe('KeyStoreDwn', () => { + const testConfigurations = [ + { + name : 'KeyManager', + keyStoreDwn : new KeyStoreDwn({ schema: 'https://identity.foundation/schemas/web5/managed-key' }), + keyStoreMemory : new KeyStoreMemory(), + }, + { + name : 'LocalKms', + keyStoreDwn : new KeyStoreDwn({ schema: 'https://identity.foundation/schemas/web5/kms-key' }), + keyStoreMemory : new KeyStoreMemory(), + } + ]; + + let agentSigningKey: Web5Crypto.CryptoKeyPair; + let agentDid: PortableDid; + let testAgent: TestAgent; + + before(async () => { + testAgent = await TestAgent.create(); + }); + + beforeEach(async () => { + agentDid = await DidKeyMethod.create({ keyAlgorithm: 'Ed25519' }); + const privateCryptoKey = await Jose.jwkToCryptoKey({ key: agentDid.keySet.verificationMethodKeys![0].privateKeyJwk! }); + const publicCryptoKey = await Jose.jwkToCryptoKey({ key: agentDid.keySet.verificationMethodKeys![0].publicKeyJwk! }); + + agentSigningKey = { + privateKey : privateCryptoKey, + publicKey : publicCryptoKey + }; + }); + + afterEach(async () => { + await testAgent.clearStorage(); + }); + + after(async () => { + await testAgent.closeStorage(); + }); + + testConfigurations.forEach((testConfiguration) => { + describe(`with ${testConfiguration.name}`, () => { + let keyStoreDwn: KeyStoreDwn; + let kmsKeyStoreMemory: KeyStoreMemory; + let kmsPrivateKeyStoreMemory: PrivateKeyStoreMemory; + + beforeEach(async () => { + // Instantiate a local KMS with in-memory key stores. + kmsKeyStoreMemory = new KeyStoreMemory(); + const localKmsMemory = new LocalKms({ + kmsName : 'memory', + keyStore : kmsKeyStoreMemory + }); + + kmsPrivateKeyStoreMemory = new PrivateKeyStoreMemory(); + keyStoreDwn = testConfiguration.keyStoreDwn; + + if (testConfiguration.name === 'KeyManager') { + const localKmsDwn = new LocalKms({ + kmsName : 'local', + keyStore : testConfiguration.keyStoreMemory, + privateKeyStore : kmsPrivateKeyStoreMemory + }); + + const keyManager = new KeyManager({ + kms: { + local : localKmsDwn, + memory : localKmsMemory + }, + store: testConfiguration.keyStoreDwn + }); + keyManager.agent = testAgent; + testAgent.keyManager = keyManager; + } + + if (testConfiguration.name === 'LocalKms') { + const localKmsDwn = new LocalKms({ + kmsName : 'local', + keyStore : testConfiguration.keyStoreDwn, + privateKeyStore : kmsPrivateKeyStoreMemory + }); + + const keyManager = new KeyManager({ + kms: { + local : localKmsDwn, + memory : localKmsMemory + }, + store: testConfiguration.keyStoreMemory + }); + keyManager.agent = testAgent; + testAgent.keyManager = keyManager; + } + + // Convert the CryptoKeyPair object to a PortableKeyPair. + const defaultSigningKey = cryptoToPortableKeyPair({ + cryptoKeyPair : agentSigningKey, + keyData : { + alias : await testAgent.didManager.getDefaultSigningKey({ did: agentDid.did }), + kms : 'memory' + } + }); + + // Import the Agent's signing key pair to the in-memory KMS key stores. + await testAgent.keyManager.setDefaultSigningKey({ key: defaultSigningKey }); + + // Set the Agent's DID + testAgent.agentDid = agentDid.did; + }); + + describe('deleteKey()', () => { + let importedKeyPairId: string; + + beforeEach(async () => { + // Generate a key pair to import. + const randomKeyPair = await new EdDsaAlgorithm().generateKey({ + algorithm : { name: 'EdDSA', namedCurve: 'Ed25519' }, + extractable : true, + keyUsages : ['sign', 'verify'] + }); + + // Import the private key to the in-memory private key store. + const importedPrivateKeyId = await kmsPrivateKeyStoreMemory.importKey({ key: { + material : randomKeyPair.privateKey.material, + type : 'private' + }}); + + // And finally, attempt to import the key into the DWN-backed key store. + importedKeyPairId = await keyStoreDwn.importKey({ + agent : testAgent, + key : { + privateKey : { ...randomKeyPair.privateKey, id: importedPrivateKeyId, kms: 'local', state: 'Enabled' }, + publicKey : { ...randomKeyPair.publicKey, id: importedPrivateKeyId, kms: 'local', material: randomKeyPair.publicKey.material, state: 'Enabled' } + } + }); + }); + + it('deletes key and returns true if key exists', async () => { + // Test deleting the key and validate the result. + const deleteResult = await keyStoreDwn.deleteKey({ id: importedKeyPairId, agent: testAgent }); + expect(deleteResult).to.be.true; + + // Verify the key is no longer in the store. + const storedKey = await keyStoreDwn.getKey({ id: importedKeyPairId, agent: testAgent }); + expect(storedKey).to.be.undefined; + }); + + it('returns false if key does not exist', async () => { + // Test deleting the key. + const deleteResult = await keyStoreDwn.deleteKey({ id: 'non-existent', agent: testAgent }); + + // Validate the key was not deleted. + expect(deleteResult).to.be.false; + }); + + it('throws an error if Agent DID is undefined and no context was specified', async () => { + // Unset the Agent DID. + testAgent.agentDid = undefined; + await expect( + keyStoreDwn.deleteKey({ id: importedKeyPairId, agent: testAgent }) + ).to.eventually.be.rejectedWith(Error, `Agent property 'agentDid' is undefined and no context was specified`); + }); + }); + + describe('findKey()', () => { + let importedKeyPairId: string; + + beforeEach(async () => { + // Generate a key pair to import. + const randomKeyPair = await new EdDsaAlgorithm().generateKey({ + algorithm : { name: 'EdDSA', namedCurve: 'Ed25519' }, + extractable : true, + keyUsages : ['sign', 'verify'] + }); + + // Import the private key to the in-memory private key store. + const importedPrivateKeyId = await kmsPrivateKeyStoreMemory.importKey({ key: { + material : randomKeyPair.privateKey.material, + type : 'private' + }}); + + // And finally, attempt to import the key into the DWN-backed key store. + importedKeyPairId = await keyStoreDwn.importKey({ + agent : testAgent, + key : { + privateKey : { ...randomKeyPair.privateKey, id: importedPrivateKeyId, kms: 'local', alias: 'external-id', state: 'Enabled' }, + publicKey : { ...randomKeyPair.publicKey, id: importedPrivateKeyId, kms: 'local', alias: 'external-id', material: randomKeyPair.publicKey.material, state: 'Enabled' } + } + }); + }); + + it('returns a key by ID if it exists', async () => { + // Test finding the key. + const storedKey = await keyStoreDwn.findKey({ id: importedKeyPairId, agent: testAgent}); + + // Verify the key is in the store. + if (!(storedKey && 'publicKey' in storedKey)) throw Error(); // Type guard. + expect(storedKey.publicKey.id).to.equal(importedKeyPairId); + }); + + it('returns a key by alias if it exists', async () => { + // Test finding the key. + const storedKey = await keyStoreDwn.findKey({ alias: 'external-id', agent: testAgent}); + + // Verify the key is in the store. + if (!(storedKey && 'publicKey' in storedKey)) throw Error(); // Type guard. + expect(storedKey.publicKey.id).to.equal(importedKeyPairId); + }); + + it('returns undefined when attempting to get a non-existent key', async () => { + // Test finding the key by ID. + expect( + await keyStoreDwn.findKey({ id: 'non-existent-did', agent: testAgent }) + ).to.be.undefined; + + // Test finding the key by alias. + expect( + await keyStoreDwn.findKey({ alias: 'non-existent-did', agent: testAgent }) + ).to.be.undefined; + }); + + it('throws an error if Agent DID is undefined and no context was specified', async () => { + // Unset the Agent DID. + testAgent.agentDid = undefined; + await expect( + keyStoreDwn.findKey({ id: importedKeyPairId, agent: testAgent }) + ).to.eventually.be.rejectedWith(Error, `Agent property 'agentDid' is undefined and no context was specified`); + }); + + it('throws an error if Agent DID is undefined when searching by alias', async () => { + // Unset the Agent DID. + testAgent.agentDid = undefined; + await expect( + keyStoreDwn.findKey({ alias: 'external-id', agent: testAgent }) + ).to.eventually.be.rejectedWith(Error, `Agent property 'agentDid' is undefined`); + }); + }); + + describe('getKey()', () => { + let importedKeyPairId: string; + + beforeEach(async () => { + // Generate a key pair to import. + const randomKeyPair = await new EdDsaAlgorithm().generateKey({ + algorithm : { name: 'EdDSA', namedCurve: 'Ed25519' }, + extractable : true, + keyUsages : ['sign', 'verify'] + }); + + // Import the private key to the in-memory private key store. + const importedPrivateKeyId = await kmsPrivateKeyStoreMemory.importKey({ key: { + material : randomKeyPair.privateKey.material, + type : 'private' + }}); + + // And finally, attempt to import the key into the DWN-backed key store. + importedKeyPairId = await keyStoreDwn.importKey({ + agent : testAgent, + key : { + privateKey : { ...randomKeyPair.privateKey, id: importedPrivateKeyId, kms: 'local', alias: 'external-id', state: 'Enabled' }, + publicKey : { ...randomKeyPair.publicKey, id: importedPrivateKeyId, kms: 'local', alias: 'external-id', material: randomKeyPair.publicKey.material, state: 'Enabled' } + } + }); + }); + + it('returns a key by ID if it exists', async () => { + // Test getting the key. + const storedKey = await keyStoreDwn.getKey({ id: importedKeyPairId, agent: testAgent }); + + // Verify the key is in the store. + if (!(storedKey && 'publicKey' in storedKey)) throw Error(); // Type guard. + expect(storedKey.publicKey.id).to.equal(importedKeyPairId); + }); + + it('returns undefined when attempting to get a non-existent DID', async () => { + // Test getting the key. + const storedKey = await keyStoreDwn.getKey({ id: 'non-existent', agent: testAgent }); + + // Verify the result is undefined. + expect(storedKey).to.be.undefined; + }); + + it('throws an error if Agent DID is undefined and no context was specified', async () => { + // Unset the Agent DID. + testAgent.agentDid = undefined; + await expect( + keyStoreDwn.getKey({ id: importedKeyPairId, agent: testAgent }) + ).to.eventually.be.rejectedWith(Error, `Agent property 'agentDid' is undefined and no context was specified`); + }); + }); + + describe('importKey()', () => { + it('imports a key after Agent signing key is stored by in-memory KMS', async () => { + // Generate a key pair to import. + const randomKeyPair = await new EdDsaAlgorithm().generateKey({ + algorithm : { name: 'EdDSA', namedCurve: 'Ed25519' }, + extractable : true, + keyUsages : ['sign', 'verify'] + }); + + // Import the private key to the in-memory private key store. + const importedPrivateKeyId = await kmsPrivateKeyStoreMemory.importKey({ key: { + material : randomKeyPair.privateKey.material, + type : 'private' + }}); + + // And finally, attempt to import the key into the DWN-backed key store. + const importedKeyPairId = await keyStoreDwn.importKey({ + agent : testAgent, + key : { + privateKey : { ...randomKeyPair.privateKey, id: importedPrivateKeyId, kms: 'local', state: 'Enabled' }, + publicKey : { ...randomKeyPair.publicKey, id: importedPrivateKeyId, kms: 'local', material: randomKeyPair.publicKey.material, state: 'Enabled' } + } + }); + + // Verify the key is present in the DWN-backed key store. + const storedKeyPair = await keyStoreDwn.getKey({ id: importedKeyPairId, agent: testAgent }); + if (!isManagedKeyPair(storedKeyPair)) throw new Error('Type guard unexpectedly threw'); // Type guard. + expect(storedKeyPair.publicKey.id).to.equal(importedKeyPairId); + expect(storedKeyPair.privateKey.id).to.equal(importedKeyPairId); + expect(storedKeyPair.publicKey.kms).to.equal('local'); + expect(storedKeyPair.privateKey.kms).to.equal('local'); + }); + + it('uses the specified ID for the imported key', async () => { + const testKey: ManagedKey = { + id : 'test123', + algorithm : { name: 'AES', length: 256 }, + extractable : true, + kms : 'testKms', + state : 'Enabled', + type : 'secret', + usages : ['encrypt', 'decrypt'], + }; + + // Test importing the key and validate the result. + const importedKeyId = await keyStoreDwn.importKey({ key: testKey, agent: testAgent }); + expect(importedKeyId).to.equal(testKey.id); + }); + + it('generates and return an ID if one is not provided', async () => { + const testKey = { + algorithm : { name: 'AES', length: 256 }, + extractable : true, + kms : 'testKms', + state : 'Enabled', + type : 'secret', + usages : ['encrypt', 'decrypt'], + }; + + // Test importing the key and validate the result. + // @ts-expect-error because the ID property was intentionally omitted from the key object to be imported. + const importedKeyId = await keyStoreDwn.importKey({ key: testKey, agent: testAgent }); + expect(importedKeyId).to.be.a.string; + + // Verify the key is present in the key store. + const storedKey = await keyStoreDwn.getKey({ id: importedKeyId, agent: testAgent }) as ManagedKey; + expect(storedKey.id).to.equal(importedKeyId); + }); + + it('throws an error when attempting to import a key that already exists', async () => { + const testKey: ManagedKey = { + id : 'test123', + algorithm : { name: 'AES', length: 256 }, + extractable : true, + kms : 'testKms', + state : 'Enabled', + type : 'secret', + usages : ['encrypt', 'decrypt'], + }; + + // Test importing the key and validate the result. + const importedKeyId = await keyStoreDwn.importKey({ key: testKey, agent: testAgent }); + expect(importedKeyId).to.equal(testKey.id); + + // Test importing the same key again and assert it throws an error. + await expect( + keyStoreDwn.importKey({ key: testKey, agent: testAgent }) + ).to.eventually.be.rejectedWith(Error, 'Key with ID already exists'); + }); + + it('throws an error if Agent DID is undefined and no context was specified', async () => { + // Unset the Agent DID. + testAgent.agentDid = undefined; + await expect( + keyStoreDwn.importKey({ key: { id: undefined } as any, agent: testAgent }) + ).to.eventually.be.rejectedWith(Error, `Agent property 'agentDid' is undefined and no context was specified`); + }); + }); + + describe('listKeys()', () => { + it('returns an array of all keys in the store', async () => { + // Create key pair to import. + const randomKeyPair = await new EdDsaAlgorithm().generateKey({ + algorithm : { name: 'EdDSA', namedCurve: 'Ed25519' }, + extractable : true, + keyUsages : ['sign', 'verify'] + }); + const portableKeyPair = cryptoToPortableKeyPair({ + cryptoKeyPair : randomKeyPair, + keyData : { kms: 'local' } + }); + + // Import the key material three times. + const importedKey1 = await testAgent.keyManager.importKey(structuredClone(portableKeyPair)); + const importedKey2 = await testAgent.keyManager.importKey(structuredClone(portableKeyPair)); + const importedKey3 = await testAgent.keyManager.importKey(structuredClone(portableKeyPair)); + + // List keys and verify the result. + const storedKeys = await keyStoreDwn.listKeys({ agent: testAgent }); + expect(storedKeys).to.have.length(3); + const importedKeys = [importedKey1.publicKey.id, importedKey2.publicKey.id, importedKey3.publicKey.id]; + for (const storedKey of storedKeys) { + if (!isManagedKeyPair(storedKey)) throw Error(); // Type guard. + expect(importedKeys).to.include(storedKey.publicKey.id); + } + }); + + it('should return an empty array if the store contains no keys', async function() { + // List keys and verify the result is empty. + const storedKeys = await keyStoreDwn.listKeys({ agent: testAgent }); + expect(storedKeys).to.be.empty; + }); + + it('throws an error if Agent DID is undefined and no context was specified', async () => { + // Unset the Agent DID. + testAgent.agentDid = undefined; + await expect( + keyStoreDwn.listKeys({ agent: testAgent }) + ).to.eventually.be.rejectedWith(Error, `Agent property 'agentDid' is undefined and no context was specified`); + }); + }); + + describe('updateKey()', () => { + let importedKeyPairId: string; + + beforeEach(async () => { + // Generate a key pair to import. + const randomKeyPair = await new EdDsaAlgorithm().generateKey({ + algorithm : { name: 'EdDSA', namedCurve: 'Ed25519' }, + extractable : true, + keyUsages : ['sign', 'verify'] + }); + + // Import the private key to the in-memory private key store. + const importedPrivateKeyId = await kmsPrivateKeyStoreMemory.importKey({ key: { + material : randomKeyPair.privateKey.material, + type : 'private' + }}); + + // And finally, attempt to import the key into the DWN-backed key store. + importedKeyPairId = await keyStoreDwn.importKey({ + agent : testAgent, + key : { + privateKey : { ...randomKeyPair.privateKey, id: importedPrivateKeyId, kms: 'local', state: 'Enabled' }, + publicKey : { ...randomKeyPair.publicKey, id: importedPrivateKeyId, kms: 'local', material: randomKeyPair.publicKey.material, state: 'Enabled' } + } + }); + }); + + it('updates key alias and return true if key exists', async () => { + // Test updating the key and validate the result. + const updateResult = await keyStoreDwn.updateKey({ id: importedKeyPairId, alias: 'new-alias', agent: testAgent }); + expect(updateResult).to.be.true; + + const storedKey = await keyStoreDwn.getKey({ id: importedKeyPairId, agent: testAgent }); + if (!isManagedKeyPair(storedKey)) throw new Error('Type guard unexpectedly threw'); // Type guard. + expect(storedKey.privateKey.alias).to.equal('new-alias'); + }); + + it('updates key metadata and return true if key exists', async () => { + // Test updating the key and validate the result. + const updateResult = await keyStoreDwn.updateKey({ id: importedKeyPairId, metadata: { foo: 'bar' }, agent: testAgent }); + expect(updateResult).to.be.true; + + const storedKey = await keyStoreDwn.getKey({ id: importedKeyPairId, agent: testAgent }); + if (!isManagedKeyPair(storedKey)) throw new Error('Type guard unexpectedly threw'); // Type guard. + expect(storedKey.privateKey.metadata).to.deep.equal({ foo: 'bar' }); + }); + + it('returns false when attempting to update a non-existent key', async () => { + // Test updating the key and validate the result. + const updateResult = await keyStoreDwn.updateKey({ id: 'non-existent', metadata: { foo: 'bar' }, agent: testAgent }); + expect(updateResult).to.be.false; + }); + }); + + describe('data integrity', () => { + it('imports and gets stored key metadata without any alterations', async () => { + const randomKeyPair = await new EdDsaAlgorithm().generateKey({ + algorithm : { name: 'EdDSA', namedCurve: 'Ed25519' }, + extractable : true, + keyUsages : ['sign', 'verify'] + }); + const originalPublicKey = structuredClone(randomKeyPair.publicKey.material); + const originalPrivateKey = structuredClone(randomKeyPair.privateKey.material); + + // Import the private key to the in-memory private key store. + const importedPrivateKeyId = await kmsPrivateKeyStoreMemory.importKey({ + key: { + material : randomKeyPair.privateKey.material, + type : 'private' + } + }); + + // Import the key into the key store. + const importedKeyPairId = await keyStoreDwn.importKey({ + agent : testAgent, + key : { + privateKey : { ...randomKeyPair.privateKey, id: importedPrivateKeyId, kms: 'local', alias: 'external-id', state: 'Enabled' }, + publicKey : { ...randomKeyPair.publicKey, id: importedPrivateKeyId, kms: 'local', alias: 'external-id', material: randomKeyPair.publicKey.material, state: 'Enabled' } + } + }); + + // Retrieve the private key. + const storedPrivateKey = await kmsPrivateKeyStoreMemory.getKey({ id: importedPrivateKeyId }); + expect(storedPrivateKey?.material).to.deep.equal(originalPrivateKey); + + // Retrieve the key metadata. + const storedKey = await keyStoreDwn.getKey({ id: importedKeyPairId, agent: testAgent }) as ManagedKeyPair; + expect(storedKey?.publicKey.material).to.deep.equal(originalPublicKey); + }); + + it('finds key without any alterations', async () => { + const randomKeyPair = await new EdDsaAlgorithm().generateKey({ + algorithm : { name: 'EdDSA', namedCurve: 'Ed25519' }, + extractable : true, + keyUsages : ['sign', 'verify'] + }); + const originalPublicKey = structuredClone(randomKeyPair.publicKey.material); + + // Import the private key to the in-memory private key store. + const importedPrivateKeyId = await kmsPrivateKeyStoreMemory.importKey({ + key: { + material : randomKeyPair.privateKey.material, + type : 'private' + } + }); + + // Import the key into the key store. + const importedKeyPairId = await keyStoreDwn.importKey({ + agent : testAgent, + key : { + privateKey : { ...randomKeyPair.privateKey, id: importedPrivateKeyId, kms: 'local', alias: 'external-id', state: 'Enabled' }, + publicKey : { ...randomKeyPair.publicKey, id: importedPrivateKeyId, kms: 'local', alias: 'external-id', material: randomKeyPair.publicKey.material, state: 'Enabled' } + } + }); + + // Find the key. + const storedKey = await keyStoreDwn.findKey({ id: importedKeyPairId, agent: testAgent }) as ManagedKeyPair; + expect(storedKey?.publicKey.material).to.deep.equal(originalPublicKey); + }); + + it('updates keys without any alterations', async () => { + const randomKeyPair = await new EdDsaAlgorithm().generateKey({ + algorithm : { name: 'EdDSA', namedCurve: 'Ed25519' }, + extractable : true, + keyUsages : ['sign', 'verify'] + }); + const originalPublicKey = structuredClone(randomKeyPair.publicKey.material); + + // Import the private key to the in-memory private key store. + const importedPrivateKeyId = await kmsPrivateKeyStoreMemory.importKey({ + key: { + material : randomKeyPair.privateKey.material, + type : 'private' + } + }); + + // Import the key into the key store. + const importedKeyPairId = await keyStoreDwn.importKey({ + agent : testAgent, + key : { + privateKey : { ...randomKeyPair.privateKey, id: importedPrivateKeyId, kms: 'local', alias: 'external-id', state: 'Enabled' }, + publicKey : { ...randomKeyPair.publicKey, id: importedPrivateKeyId, kms: 'local', alias: 'external-id', material: randomKeyPair.publicKey.material, state: 'Enabled' } + } + }); + + // Update the key. + const updateResult = await keyStoreDwn.updateKey({ id: importedKeyPairId, alias: 'new-alias', agent: testAgent }); + expect(updateResult).to.be.true; + + // Retrieve the key. + const storedKey = await keyStoreDwn.getKey({ id: importedKeyPairId, agent: testAgent }); + if (!isManagedKeyPair(storedKey)) throw new Error('Type guard unexpectedly threw'); // Type guard. + expect(storedKey?.publicKey.material).to.deep.equal(originalPublicKey); + expect(storedKey?.publicKey.alias).to.equal('new-alias'); + }); + }); + }); + }); +}); + +describe('KeyStoreMemory', () => { + let keyStore: KeyStoreMemory; + let testKey: ManagedKey; + let testKeyPair: ManagedKeyPair; + + beforeEach(() => { + keyStore = new KeyStoreMemory(); + + testKey = { + id : 'testKey', + alias : 'did:method:abc123', + algorithm : { name: 'AES', length: 256 }, + extractable : true, + kms : 'testKms', + state : 'Enabled', + type : 'secret', + usages : ['encrypt', 'decrypt'], + }; + + testKeyPair = { + privateKey: { + ...testKey, + alias : 'did:method:def456', + id : 'testKeyPair', + type : 'private', + }, + + publicKey: { + ...testKey, + alias : 'did:method:def456', + id : 'testKeyPair', + type : 'public', + } + }; + }); + + describe('deleteKey()', () => { + it('should delete key and return true if key exists', async () => { + // Import the key. + await keyStore.importKey({ key: testKey }); + + // Test deleting the key and validate the result. + const deleteResult = await keyStore.deleteKey({ id: testKey.id }); + expect(deleteResult).to.be.true; + + // Verify the key is no longer in the store. + const storedKey = await keyStore.getKey({ id: testKey.id }); + expect(storedKey).to.be.undefined; + }); + + it('should return false if key does not exist', async () => { + // Test deleting the key. + const nonExistentId = '1234'; + const deleteResult = await keyStore.deleteKey({ id: nonExistentId }); + + // Validate the key was not deleted. + expect(deleteResult).to.be.false; + }); + }); + + describe('findKey()', () => { + + beforeEach(async () => { + // Import the key. + await keyStore.importKey({ key: testKey }); + }); + + it('should return a key by ID if it exists', async () => { + // Test finding the key. + const storedKey = await keyStore.findKey({ id: testKey.id }); + + // Verify the key is in the store. + expect(storedKey).to.deep.equal(testKey); + }); + + it('should return a key by alias if it exists', async () => { + // Test finding the key. + const storedKey = await keyStore.findKey({ alias: 'did:method:abc123' }); + + // Verify the key is in the store. + expect(storedKey).to.deep.equal(testKey); + }); + + it('should return a key pair by alias if it exists', async () => { + // Import the key pair. + await keyStore.importKey({ key: testKeyPair }); + + // Test finding the key pair. + const storedKey = await keyStore.findKey({ alias: 'did:method:def456' }); + + // Verify the key is in the store. + expect(storedKey).to.deep.equal(testKeyPair); + }); + + it('should return undefined when attempting to get a non-existent key', async () => { + // Test finding the key by ID. + expect( + await keyStore.findKey({ id: 'non-existent-key' }) + ).to.be.undefined; + + // Test finding the key by alias. + expect( + await keyStore.findKey({ alias: 'non-existent-key' }) + ).to.be.undefined; + }); + }); + + describe('getKey()', () => { + it('should return a key if it exists', async () => { + // Import the key. + await keyStore.importKey({ key: testKey }); + + // Test getting the key. + const storedKey = await keyStore.getKey({ id: testKey.id }); + + // Verify the key is in the store. + expect(storedKey).to.deep.equal(testKey); + }); + + it('should return a key pair by ID if it exists', async () => { + // Import the key pair. + await keyStore.importKey({ key: testKeyPair }); + + // Test finding the key pair. + const storedKey = await keyStore.getKey({ id: testKeyPair.publicKey.id }); + + // Verify the key is in the store. + expect(storedKey).to.deep.equal(testKeyPair); + }); + + it('should return undefined when attempting to get a non-existent key', async () => { + // Test getting the key. + const storedKey = await keyStore.getKey({ id: 'non-existent-key' }); + + // Verify the key is no longer in the store. + expect(storedKey).to.be.undefined; + }); + }); + + describe('importKey()', () => { + it('should import a key that does not already exist', async () => { + // Test importing the key and validate the result. + const importResult = await keyStore.importKey({ key: testKey }); + expect(importResult).to.equal(testKey.id); + expect(importResult).to.be.a.string; + + // Verify the key is present in the key store. + const storedKey = await keyStore.getKey({ id: testKey.id }); + expect(storedKey).to.deep.equal(testKey); + }); + + it('should generate and return an ID if one is not provided', async () => { + // @ts-expect-error because the ID property was intentionally omitted from the key object to be imported. + const testKey: ManagedKey = { + algorithm : { name: 'AES', length: 256 }, + extractable : true, + kms : 'testKms', + state : 'Enabled', + type : 'secret', + usages : ['encrypt', 'decrypt'], + }; + + // Test importing the key and validate the result. + const importResult = await keyStore.importKey({ key: testKey }); + expect(importResult).to.be.a.string; + + // Verify the key is present in the key store. + const storedKey = await keyStore.getKey({ id: importResult }) as ManagedKey; + expect(storedKey.id).to.equal(importResult); + }); + + it('should throw an error when attempting to import a key that already exists', async () => { + // Import the key and validate the result. + const importResult = await keyStore.importKey({ key: testKey }); + expect(importResult).to.equal(testKey.id); + + // Test importing the key and assert it throws an error. + const importKey = keyStore.importKey({ key: testKey }); + await expect(importKey).to.eventually.be.rejectedWith(Error, 'Key with ID already exists'); + }); + }); + + describe('listKeys()', () => { + it('should return an array of all keys in the store', async () => { + // Define multiple keys to be added. + const testKeys = [ + { ...testKey, ...{ id: 'key-1' }}, + { ...testKey, ...{ id: 'key-2' }}, + { ...testKey, ...{ id: 'key-3' }} + ]; + + // Import the keys into the store. + for (let key of testKeys) { + await keyStore.importKey({ key }); + } + + // List keys and verify the result. + const storedKeys = await keyStore.listKeys(); + expect(storedKeys).to.deep.equal(testKeys); + }); + + it('should return an empty array if the store contains no keys', async () => { + // List keys and verify the result is empty. + const storedKeys = await keyStore.listKeys(); + expect(storedKeys).to.be.empty; + }); + }); + + describe('updateKey()', () => { + it('should update the alias for a key when given', async () => { + // Import a key so we have something to update. + const importResult = await keyStore.importKey({ key: testKey }); + expect(importResult).to.equal(testKey.id); + + // Attempt to update the key. + const newAlias = 'did:method:new'; + const updateResult = await keyStore.updateKey({ id: testKey.id, alias: newAlias }); + + // Verify that the alias property was updated. + expect(updateResult).to.be.true; + const storedKey = await keyStore.getKey({ id: testKey.id }); + expect(storedKey).to.have.property('alias', newAlias); + }); + + it('should update the metadata for a key when given', async () => { + // Import a key so we have something to update. + const importResult = await keyStore.importKey({ key: testKey }); + expect(importResult).to.equal(testKey.id); + + // Attempt to update the key. + const newMetadata = { foo: 'bar' }; + const updateResult = await keyStore.updateKey({ id: testKey.id, metadata: newMetadata }); + + // Verify that the metadata property was updated. + expect(updateResult).to.be.true; + const storedKey = await keyStore.getKey({ id: testKey.id }); + if ('privateKey' in storedKey!) throw new Error('Expected ManagedKey and not ManagedKeyPair'); + expect(storedKey!.metadata).to.deep.equal(newMetadata); + }); + + it('should update the alias and metadata for a key when given', async () => { + // Import a key so we have something to update. + const importResult = await keyStore.importKey({ key: testKey }); + expect(importResult).to.equal(testKey.id); + + // Attempt to update the key. + const newAlias = 'did:method:new'; + const newMetadata = { foo: 'bar' }; + const updateResult = await keyStore.updateKey({ + id : testKey.id, + alias : newAlias, + metadata : newMetadata + }); + + // Verify that the alias and metadata properties were updated. + expect(updateResult).to.be.true; + const storedKey = await keyStore.getKey({ id: testKey.id }); + if ('privateKey' in storedKey!) throw new Error('Expected ManagedKey and not ManagedKeyPair'); + expect(storedKey).to.have.property('alias', newAlias); + expect(storedKey!.metadata).to.deep.equal(newMetadata); + }); + + it('should update the alias and metadata for a key pair when given', async () => { + // Import a key pair so we have something to update. + const importResult = await keyStore.importKey({ key: testKeyPair }); + expect(importResult).to.equal(testKeyPair.publicKey.id); + + // Attempt to update the key pair. + const newAlias = 'did:method:new'; + const newMetadata = { foo: 'bar' }; + const updateResult = await keyStore.updateKey({ + id : testKeyPair.publicKey.id, + alias : newAlias, + metadata : newMetadata + }); + + // Verify that the alias and metadata properties were updated. + expect(updateResult).to.be.true; + const storedKeyPair = await keyStore.getKey({ id: testKeyPair.publicKey.id }); + if (!('publicKey' in storedKeyPair!)) throw new Error('Expected ManagedKeyPair and not ManagedKey'); + expect(storedKeyPair!.publicKey).to.have.property('alias', newAlias); + expect(storedKeyPair!.publicKey.metadata).to.deep.equal(newMetadata); + }); + + it('should not ovewrite key properties if given values are undefined', async () => { + // Import a key so we have something to update. + const importResult = await keyStore.importKey({ key: testKey }); + expect(importResult).to.equal(testKey.id); + + // Attempt to update the key. + const newAlias = undefined; + const newMetadata = { /* empty */ }; + const updateResult = await keyStore.updateKey({ + id : testKey.id, + alias : newAlias, + metadata : newMetadata + }); + + // Verify that no properties were updated. + expect(updateResult).to.be.true; + const storedKey = await keyStore.getKey({ id: testKey.id }); + expect(storedKey).to.deep.equal(testKey); + }); + + it('should return false when attempting to update a non-existent key', async () => { + // Attempt to update a non-existent key. + const updateResult = await keyStore.updateKey({ + id : 'non-existent', + alias : 'did:method:a1', + metadata : { foo: 'bar' } + }); + + // Verify that the update operation was not successful. + expect(updateResult).to.be.false; + }); + }); +}); + +describe('PrivateKeyStoreDwn', () => { + let agentDid: PortableDid; + let agentSigningKey: Web5Crypto.CryptoKeyPair; + let keyMaterial: Uint8Array; + let kmsKeyStore: KeyStoreDwn; + let kmsPrivateKeyStore: PrivateKeyStoreDwn; + let testAgent: TestAgent; + let testKey: Omit; + + before(async () => { + testAgent = await TestAgent.create(); + }); + + beforeEach(async () => { + agentDid = await DidKeyMethod.create({ keyAlgorithm: 'Ed25519' }); + const privateCryptoKey = await Jose.jwkToCryptoKey({ key: agentDid.keySet.verificationMethodKeys![0].privateKeyJwk! }); + const publicCryptoKey = await Jose.jwkToCryptoKey({ key: agentDid.keySet.verificationMethodKeys![0].publicKeyJwk! }); + + agentSigningKey = { + privateKey : privateCryptoKey, + publicKey : publicCryptoKey + }; + + // Instantiate a local KMS with in-memory key stores. + const localKmsMemory = new LocalKms({ kmsName: 'memory' }); + + // Instantiate a local KMS with DWN-backed key stores. + kmsKeyStore = new KeyStoreDwn({ schema: 'https://identity.foundation/schemas/web5/kms-key' }); + kmsPrivateKeyStore = new PrivateKeyStoreDwn(); + const localKmsDwn = new LocalKms({ + kmsName : 'local', + keyStore : kmsKeyStore, + privateKeyStore : kmsPrivateKeyStore + }); + + // Insntiate KeyManager with in-memory and DWN-backed KMSs. + const keyManagerStore = new KeyStoreDwn({ schema: 'https://identity.foundation/schemas/web5/managed-key' }); + const keyManager = new KeyManager({ + kms: { + local : localKmsDwn, + memory : localKmsMemory + }, + store: keyManagerStore + }); + // Set the agent context for KeyManager and all KMSs. + keyManager.agent = testAgent; + + // Replace the TestAgent's KeyManager instance with the custom instance. + testAgent.keyManager = keyManager; + + // Convert the CryptoKeyPair object to a PortableKeyPair. + const defaultSigningKey = cryptoToPortableKeyPair({ + cryptoKeyPair : agentSigningKey, + keyData : { + alias : await testAgent.didManager.getDefaultSigningKey({ did: agentDid.did }), + kms : 'memory' + } + }); + + // Import the Agent's signing key pair to the in-memory KMS key stores. + await testAgent.keyManager.setDefaultSigningKey({ key: defaultSigningKey }); + + // Set the Agent's DID + testAgent.agentDid = agentDid.did; + + // Key to use for testing. + keyMaterial = new Uint8Array([1, 2, 3]); + testKey = { + material : new Uint8Array([1, 2, 3]), + type : 'private', + }; + }); + + afterEach(async () => { + await testAgent.clearStorage(); + }); + + after(async () => { + await testAgent.closeStorage(); + }); + + describe('deleteKey()', () => { + let importedKeyPairId: string; + + beforeEach(async () => { + // Generate a key pair to import. + const randomKeyPair = await new EdDsaAlgorithm().generateKey({ + algorithm : { name: 'EdDSA', namedCurve: 'Ed25519' }, + extractable : true, + keyUsages : ['sign', 'verify'] + }); + + // Import the private key to the in-memory private key store. + const importedPrivateKeyId = await kmsPrivateKeyStore.importKey({ + agent : testAgent, + key : { + material : randomKeyPair.privateKey.material, + type : 'private' + } + }); + + // And finally, attempt to import the key into the DWN-backed key store. + importedKeyPairId = await kmsKeyStore.importKey({ + agent : testAgent, + key : { + privateKey : { ...randomKeyPair.privateKey, id: importedPrivateKeyId, kms: 'local', state: 'Enabled' }, + publicKey : { ...randomKeyPair.publicKey, id: importedPrivateKeyId, kms: 'local', material: randomKeyPair.publicKey.material, state: 'Enabled' } + } + }); + }); + + it('deletes key and returns true if key exists', async () => { + // Import the key and get back the assigned ID. + const id = await kmsPrivateKeyStore.importKey({ key: testKey, agent: testAgent }); + + // Test deleting the key and validate the result. + const deleteResult = await kmsPrivateKeyStore.deleteKey({ id, agent: testAgent }); + expect(deleteResult).to.be.true; + + // Verify the key is no longer in the store. + const storedKey = await kmsPrivateKeyStore.getKey({ id, agent: testAgent }); + expect(storedKey).to.be.undefined; + }); + + it('returns false if key does not exist', async () => { + // Test deleting the key. + const deleteResult = await kmsPrivateKeyStore.deleteKey({ id: 'non-existent-key', agent: testAgent }); + + // Validate the key was deleted. + expect(deleteResult).to.be.false; + }); + + it('throws an error if Agent DID is undefined and no context was specified', async () => { + // Unset the Agent DID. + testAgent.agentDid = undefined; + await expect( + kmsPrivateKeyStore.deleteKey({ id: importedKeyPairId, agent: testAgent }) + ).to.eventually.be.rejectedWith(Error, `Agent property 'agentDid' is undefined and no context was specified`); + }); + }); + + describe('findKey()', async () => { + it('throws a not implemented error', async () => { + await expect( + kmsPrivateKeyStore.findKey() + ).to.eventually.be.rejectedWith(Error, 'Method not implemented'); + }); + }); + + describe('getKey()', () => { + let importedPrivateKeyId: string; + + beforeEach(async () => { + // Import the private key to the in-memory private key store. + importedPrivateKeyId = await kmsPrivateKeyStore.importKey({ + agent : testAgent, + key : testKey + }); + }); + + it('should return a key if it exists', async () => { + // Test getting the key. + const storedKey = await kmsPrivateKeyStore.getKey({ id: importedPrivateKeyId, agent: testAgent }); + + // Verify the key is in the store. + expect(storedKey).to.deep.equal({ id: importedPrivateKeyId, material: keyMaterial, type: 'private' }); + }); + + it('should return undefined if the specified key does not exist', async () => { + // Test getting the key. + const storedKey = await kmsPrivateKeyStore.getKey({ id: 'non-existent-key', agent: testAgent }); + + // Verify the key is no longer in the store. + expect(storedKey).to.be.undefined; + }); + + it('throws an error if Agent DID is undefined and no context was specified', async () => { + // Unset the Agent DID. + testAgent.agentDid = undefined; + await expect( + kmsPrivateKeyStore.getKey({ id: importedPrivateKeyId, agent: testAgent }) + ).to.eventually.be.rejectedWith(Error, `Agent property 'agentDid' is undefined and no context was specified`); + }); + }); + + describe('importKey()', () => { + it('should import a private key and return its ID', async () => { + // Import the private key to the in-memory private key store. + const importedPrivateKeyId = await kmsPrivateKeyStore.importKey({ + agent : testAgent, + key : testKey + }); + + // Validate the returned id. + expect(importedPrivateKeyId).to.be.a('string'); + + // Verify the key is present in the private key store. + const storedKey = await kmsPrivateKeyStore.getKey({ id: importedPrivateKeyId, agent: testAgent }); + expect(storedKey).to.deep.equal({ id: importedPrivateKeyId, material: keyMaterial, type: 'private' }); + }); + + it('should throw an error if required parameters are missing', async () => { + // Missing 'material'. + const keyMissingMaterial = { type: 'private' }; + await expect(kmsPrivateKeyStore.importKey({ + agent : testAgent, + // @ts-expect-error because the material property is intentionally omitted to trigger an error. + key : keyMissingMaterial + })).to.eventually.be.rejectedWith(TypeError, `Required parameter missing: 'material'`); + + // Missing 'type'. + const keyMissingType = { material: new Uint8Array(8) }; + await expect(kmsPrivateKeyStore.importKey({ + agent : testAgent, + // @ts-expect-error because the type property is intentionally omitted to trigger an error. + key : keyMissingType + })).to.eventually.be.rejectedWith(TypeError, `Required parameter missing: 'type'`); + }); + + it('throws an error if Agent DID is undefined and no context was specified', async () => { + // Unset the Agent DID. + testAgent.agentDid = undefined; + await expect( + kmsPrivateKeyStore.importKey({ key: testKey, agent: testAgent }) + ).to.eventually.be.rejectedWith(Error, `Agent property 'agentDid' is undefined and no context was specified`); + }); + }); + + describe('listKeys()', function() { + it('should return an array of all keys in the store', async function() { + // Define multiple keys to be added. + const testKeys = [ + { ...testKey, material: (new Uint8Array([1, 2, 3]))}, + { ...testKey, material: (new Uint8Array([1, 2, 3]))}, + { ...testKey, material: (new Uint8Array([1, 2, 3]))} + ]; + + // Import the keys into the store. + const importedKeys: Map = new Map(); + for (let key of testKeys) { + const id = await kmsPrivateKeyStore.importKey({ key, agent: testAgent }); + importedKeys.set(id, { ...key, id }); + } + + const storedKeys = await kmsPrivateKeyStore.listKeys({ agent: testAgent }); + expect(storedKeys).to.have.length(3); + for (const storedKey of storedKeys) { + expect(importedKeys.get(storedKey.id)).to.deep.equal(storedKey); + } + }); + + it('should return an empty array if the store contains no keys', async function() { + // List keys and verify the result is empty. + const storedKeys = await kmsPrivateKeyStore.listKeys({ agent: testAgent }); + expect(storedKeys).to.be.empty; + }); + + it('throws an error if Agent DID is undefined and no context was specified', async () => { + // Unset the Agent DID. + testAgent.agentDid = undefined; + await expect( + kmsPrivateKeyStore.listKeys({ agent: testAgent }) + ).to.eventually.be.rejectedWith(Error, `Agent property 'agentDid' is undefined and no context was specified`); + }); + }); + + describe('updateKey()', async () => { + it('throws a not implemented error', async () => { + await expect( + kmsPrivateKeyStore.updateKey() + ).to.eventually.be.rejectedWith(Error, 'Method not implemented'); + }); + }); + + describe('data integrity', () => { + it('imports and gets stored private key data without any alterations', async () => { + // Generate a key pair to import. + const randomKeyPair = await new EdDsaAlgorithm().generateKey({ + algorithm : { name: 'EdDSA', namedCurve: 'Ed25519' }, + extractable : true, + keyUsages : ['sign', 'verify'] + }); + + // Import the private key to the in-memory private key store. + const importedPrivateKeyId = await kmsPrivateKeyStore.importKey({ + agent : testAgent, + key : { + material : randomKeyPair.privateKey.material, + type : 'private' + } + }); + + // Retrieve the private key. + const storedPrivateKey = await kmsPrivateKeyStore.getKey({ id: importedPrivateKeyId, agent: testAgent }); + expect(storedPrivateKey?.material).to.deep.equal(randomKeyPair.privateKey.material); + }); + }); + + describe('with LocalKms', () => { + it('imports private key data', async () => { + // Generate a key pair to import. + const randomKeyPair = await new EdDsaAlgorithm().generateKey({ + algorithm : { name: 'EdDSA', namedCurve: 'Ed25519' }, + extractable : true, + keyUsages : ['sign', 'verify'] + }); + const portableKeyPair = cryptoToPortableKeyPair({ + cryptoKeyPair : randomKeyPair, + keyData : { + kms: 'local' + } + }); + const importedKeyPair = await testAgent.keyManager.importKey(portableKeyPair); + if (!isManagedKeyPair(importedKeyPair)) throw new Error('Type guard unexpectedly threw'); // Type guard. + expect(importedKeyPair.privateKey.id).to.be.a.string; + expect(importedKeyPair.publicKey.id).to.be.a.string; + expect(importedKeyPair.publicKey.material).to.deep.equal(randomKeyPair.publicKey.material); + }); + }); +}); + +describe('PrivateKeyStoreMemory', () => { + let kmsPrivateKeyStore: PrivateKeyStoreMemory; + let testKey: Omit; + let keyMaterial: Uint8Array; + + beforeEach(() => { + kmsPrivateKeyStore = new PrivateKeyStoreMemory(); + + keyMaterial = (new Uint8Array([1, 2, 3])); + testKey = { + material : (new Uint8Array([1, 2, 3])), + type : 'private', + }; + }); + + describe('deleteKey()', () => { + it('should delete key and return true if key exists', async () => { + // Import the key and get back the assigned ID. + const id = await kmsPrivateKeyStore.importKey({ key: testKey }); + + // Test deleting the key and validate the result. + const deleteResult = await kmsPrivateKeyStore.deleteKey({ id }); + expect(deleteResult).to.be.true; + + // Verify the key is no longer in the store. + const storedKey = await kmsPrivateKeyStore.getKey({ id }); + expect(storedKey).to.be.undefined; + }); + + it('should return false if key does not exist', async () => { + // Test deleting the key. + const deleteResult = await kmsPrivateKeyStore.deleteKey({ id: 'non-existent-key' }); + + // Validate the key was deleted. + expect(deleteResult).to.be.false; + }); + }); + + describe('findKey()', async () => { + it('throws a not implemented error', async () => { + await expect( + kmsPrivateKeyStore.findKey() + ).to.eventually.be.rejectedWith(Error, 'Method not implemented'); + }); + }); + + describe('getKey()', () => { + it('should return a key if it exists', async () => { + // Import the key. + const id = await kmsPrivateKeyStore.importKey({ key: testKey }); + + // Test getting the key. + const storedKey = await kmsPrivateKeyStore.getKey({ id }); + + // Verify the key is in the store. + expect(storedKey).to.deep.equal({ id, material: keyMaterial, type: 'private' }); + }); + + it('should return undefined if the specified key does not exist', async () => { + // Test getting the key. + const storedKey = await kmsPrivateKeyStore.getKey({ id: 'non-existent-key' }); + + // Verify the key is no longer in the store. + expect(storedKey).to.be.undefined; + }); + }); + + describe('importKey()', () => { + it('should import a private key and return its ID', async () => { + // Test importing the key. + const id = await kmsPrivateKeyStore.importKey({ key: testKey }); + + // Validate the returned id. + expect(id).to.be.a('string'); + + // Verify the key is present in the private key store. + const storedKey = await kmsPrivateKeyStore.getKey({ id }); + expect(storedKey).to.deep.equal({ id, material: keyMaterial, type: 'private' }); + }); + + it('should permanently transfer the private key material', async () => { + // Test importing the key. + await kmsPrivateKeyStore.importKey({ key: testKey }); + + // Verify that attempting to access the key material after import triggers an error. + // Chrome, Firefox, Node.js, and Firefox report different error messages but all contain 'detached'. + expect(() => new Uint8Array(testKey.material)).to.throw(TypeError, 'detached'); + }); + + it('should throw an error if required parameters are missing', async () => { + // Missing 'material'. + const keyMissingMaterial = { type: 'private' }; + await expect(kmsPrivateKeyStore.importKey({ + // @ts-expect-error because the material property is intentionally omitted to trigger an error. + key: keyMissingMaterial + })).to.eventually.be.rejectedWith(TypeError, `Required parameter missing: 'material'`); + + // Missing 'type'. + const keyMissingType = { material: new Uint8Array(8) }; + await expect(kmsPrivateKeyStore.importKey({ + // @ts-expect-error because the type property is intentionally omitted to trigger an error. + key: keyMissingType + })).to.eventually.be.rejectedWith(TypeError, `Required parameter missing: 'type'`); + }); + }); + + describe('listKeys()', function() { + it('should return an array of all keys in the store', async function() { + // Define multiple keys to be added. + const testKeys = [ + { ...testKey, material: (new Uint8Array([1, 2, 3]))}, + { ...testKey, material: (new Uint8Array([1, 2, 3]))}, + { ...testKey, material: (new Uint8Array([1, 2, 3]))} + ]; + + // Import the keys into the store. + const expectedTestKeys: ManagedPrivateKey[] = []; + for (let key of testKeys) { + const id = await kmsPrivateKeyStore.importKey({ key }); + expectedTestKeys.push({ id, material: keyMaterial, type: 'private', }); + } + + const storedKeys = await kmsPrivateKeyStore.listKeys(); + expect(storedKeys).to.deep.equal(expectedTestKeys); + }); + + it('should return an empty array if the store contains no keys', async function() { + // List keys and verify the result is empty. + const storedKeys = await kmsPrivateKeyStore.listKeys(); + expect(storedKeys).to.be.empty; + }); + }); + + describe('updateKey()', async () => { + it('throws a not implemented error', async () => { + await expect( + kmsPrivateKeyStore.updateKey() + ).to.eventually.be.rejectedWith(Error, 'Method not implemented'); + }); + }); +}); \ No newline at end of file diff --git a/packages/agent/tests/test-config.ts b/packages/agent/tests/test-config.ts new file mode 100644 index 000000000..213604404 --- /dev/null +++ b/packages/agent/tests/test-config.ts @@ -0,0 +1,24 @@ +declare const __karma__: { config?: { testDwnUrl?: string; } }; + +const DEFAULT_TEST_DWN_URL = 'https://dwn.tbddev.org/dwn0'; + +function getTestDwnUrl(): string { + // Check to see if we're running in a Karma browser test environment. + const browserTestEnvironment = typeof __karma__ !== 'undefined' && __karma__?.config?.testDwnUrl !== undefined; + + // Check to see if we're running in a Node environment. + const nodeTestEnvironment = process && process?.env !== undefined; + + // Attempt to use DWN URL defined in Karma config, if running a browser test. + // Otherwise, attempt to use the Node environment variable. + const envTestDwnUrl = (browserTestEnvironment) + ? __karma__.config!.testDwnUrl + : (nodeTestEnvironment) + ? process.env.TEST_DWN_URL + : undefined; + + // If defined, return the test environment DWN URL. Otherwise, return the default. + return envTestDwnUrl || DEFAULT_TEST_DWN_URL; +} + +export const testDwnUrl = getTestDwnUrl(); \ No newline at end of file diff --git a/packages/web5-agent/tests/tsconfig.json b/packages/agent/tests/tsconfig.json similarity index 100% rename from packages/web5-agent/tests/tsconfig.json rename to packages/agent/tests/tsconfig.json diff --git a/packages/agent/tests/utils/test-agent.ts b/packages/agent/tests/utils/test-agent.ts new file mode 100644 index 000000000..469fdbeb8 --- /dev/null +++ b/packages/agent/tests/utils/test-agent.ts @@ -0,0 +1,190 @@ +import { Dwn } from '@tbd54566975/dwn-sdk-js'; +import { DidIonMethod, DidKeyMethod, DidResolver } from '@web5/dids'; +import { MessageStoreLevel, DataStoreLevel, EventLogLevel } from '@tbd54566975/dwn-sdk-js/stores'; + +import type { AppDataStore } from '../../src/app-data-store.js'; +import type { + DwnRpc, + VcResponse, + DidResponse, + DwnResponse, + SendVcRequest, + SendDidRequest, + SendDwnRequest, + ProcessVcRequest, + Web5ManagedAgent, + ProcessDidRequest, + ProcessDwnRequest, +} from '../../src/types/agent.js'; + +import { LocalKms } from '../../src/kms-local.js'; +import { DidManager } from '../../src/did-manager.js'; +import { DwnManager } from '../../src/dwn-manager.js'; +import { KeyManager } from '../../src/key-manager.js'; +import { Web5RpcClient } from '../../src/rpc-client.js'; +import { AppDataVault } from '../../src/app-data-store.js'; +import { IdentityManager } from '../../src/identity-manager.js'; + +type CreateMethodOptions = { + testDataLocation?: string; +} + +type TestAgentOptions = { + appData: AppDataStore; + didManager: DidManager; + didResolver: DidResolver; + dwnManager: DwnManager; + identityManager: IdentityManager; + keyManager: KeyManager; + rpcClient: DwnRpc; + + dwn: Dwn; + dwnDataStore: DataStoreLevel; + dwnEventLog: EventLogLevel; + dwnMessageStore: MessageStoreLevel; +} + +export class TestAgent implements Web5ManagedAgent { + agentDid: string | undefined; + appData: AppDataStore; + didManager: DidManager; + didResolver: DidResolver; + dwnManager: DwnManager; + identityManager: IdentityManager; + keyManager: KeyManager; + rpcClient: DwnRpc; + + /** + * DWN-related properties. + */ + dwn: Dwn; + dwnDataStore: DataStoreLevel; + dwnEventLog: EventLogLevel; + dwnMessageStore: MessageStoreLevel; + + constructor(options: TestAgentOptions) { + this.appData = options.appData; + this.didManager = options.didManager; + this.didResolver = options.didResolver; + this.dwnManager = options.dwnManager; + this.identityManager = options.identityManager; + this.keyManager = options.keyManager; + this.rpcClient = options.rpcClient; + + // Set this agent to be the default agent for each component. + this.didManager.agent = this; + this.dwnManager.agent = this; + this.identityManager.agent = this; + this.keyManager.agent = this; + + // TestAgent-specific properties. + this.dwn = options.dwn; + this.dwnDataStore = options.dwnDataStore; + this.dwnEventLog = options.dwnEventLog; + this.dwnMessageStore = options.dwnMessageStore; + } + + async clearStorage(): Promise { + this.agentDid = undefined; + await this.dwnDataStore.clear(); + await this.dwnEventLog.clear(); + await this.dwnMessageStore.clear(); + } + + async closeStorage(): Promise { + await this.dwnDataStore.close(); + await this.dwnEventLog.close(); + await this.dwnMessageStore.close(); + } + + static async create(options: CreateMethodOptions = {}): Promise { + let { testDataLocation } = options; + + testDataLocation ??= '__TESTDATA__'; + const testDataPath = (path: string) => `${testDataLocation}/${path}`; + + // Instantiate custom stores to use with DWN instance. + const dwnDataStore = new DataStoreLevel({ blockstoreLocation: testDataPath('DATASTORE') }); + const dwnEventLog = new EventLogLevel({ location: testDataPath('EVENTLOG') }); + const dwnMessageStore = new MessageStoreLevel({ + blockstoreLocation : testDataPath('MESSAGESTORE'), + indexLocation : testDataPath('INDEX') + }); + + // Instantiate components with default in-memory stores. + const appData = new AppDataVault({ keyDerivationWorkFactor: 1 }); + const didManager = new DidManager({ didMethods: [DidKeyMethod] }); + const identityManager = new IdentityManager(); + const kms = { + memory: new LocalKms({ kmsName: 'memory' }) + }; + const keyManager = new KeyManager({ kms }); + + // Instantiate DID resolver. + const didMethodApis = [DidIonMethod, DidKeyMethod]; + const didResolver = new DidResolver({ didResolvers: didMethodApis }); + + // Instantiate custom DWN instance. + const dwn = await Dwn.create({ + eventLog : dwnEventLog, + dataStore : dwnDataStore, + messageStore : dwnMessageStore + }); + + // Instantiate a DwnManager using the custom DWN instance. + const dwnManager = new DwnManager({ dwn }); + + // Instantiate an RPC Client. + const rpcClient = new Web5RpcClient(); + + return new TestAgent({ + appData, + didManager, + didResolver, + dwn, + dwnDataStore, + dwnEventLog, + dwnMessageStore, + dwnManager, + identityManager, + keyManager, + rpcClient + }); + } + + async firstLaunch(): Promise { + throw new Error('Not implemented'); + } + + async initialize(_options: { passphrase: string; }): Promise { + throw new Error('Not implemented'); + } + + async processDidRequest(_request: ProcessDidRequest): Promise { + throw new Error('Not implemented'); + } + + async processDwnRequest(request: ProcessDwnRequest): Promise { + return this.dwnManager.processRequest(request); + } + + async processVcRequest(_request: ProcessVcRequest): Promise { + throw new Error('Not implemented'); + } + + async sendDidRequest(_request: SendDidRequest): Promise { + throw new Error('Not implemented'); + } + + async sendDwnRequest(request: SendDwnRequest): Promise { + return this.dwnManager.sendRequest(request); + } + + async sendVcRequest(_request: SendVcRequest): Promise { + throw new Error('Not implemented'); + } + + async start(_options: { passphrase: string; }): Promise { + throw new Error('Not implemented'); + } +} \ No newline at end of file diff --git a/packages/web5/tsconfig.cjs.json b/packages/agent/tsconfig.cjs.json similarity index 81% rename from packages/web5/tsconfig.cjs.json rename to packages/agent/tsconfig.cjs.json index 0384273d6..7a6f9c0c0 100644 --- a/packages/web5/tsconfig.cjs.json +++ b/packages/agent/tsconfig.cjs.json @@ -10,7 +10,8 @@ "outDir": "dist/cjs", "declaration": false, "declarationMap": false, - "declarationDir": null + "declarationDir": null, + "downlevelIteration": true }, "include": [ "src" diff --git a/packages/web5-agent/tsconfig.json b/packages/agent/tsconfig.json similarity index 95% rename from packages/web5-agent/tsconfig.json rename to packages/agent/tsconfig.json index 1d4154f54..b29e4e7e1 100644 --- a/packages/web5-agent/tsconfig.json +++ b/packages/agent/tsconfig.json @@ -22,7 +22,6 @@ "src", ], "exclude": [ - "node_modules", - "dist" + "node_modules" ] } \ No newline at end of file diff --git a/packages/web5-proxy-agent/.c8rc.json b/packages/api/.c8rc.json similarity index 66% rename from packages/web5-proxy-agent/.c8rc.json rename to packages/api/.c8rc.json index 1d1670b70..ab680f663 100644 --- a/packages/web5-proxy-agent/.c8rc.json +++ b/packages/api/.c8rc.json @@ -5,12 +5,12 @@ ".js" ], "include": [ - "tests/compiled/**" + "tests/compiled/src/**" ], "exclude": [ - "tests/compiled/src/main.js", + "tests/compiled/src/index.js", "tests/compiled/src/types.js", - "tests/compiled/types/**" + "tests/compiled/src/types/**" ], "reporter": [ "cobertura", diff --git a/packages/web5-proxy-agent/.mocharc.json b/packages/api/.mocharc.json similarity index 100% rename from packages/web5-proxy-agent/.mocharc.json rename to packages/api/.mocharc.json diff --git a/packages/web5/.vscode/launch.json b/packages/api/.vscode/launch.json similarity index 100% rename from packages/web5/.vscode/launch.json rename to packages/api/.vscode/launch.json diff --git a/packages/web5/.vscode/tasks.json b/packages/api/.vscode/tasks.json similarity index 94% rename from packages/web5/.vscode/tasks.json rename to packages/api/.vscode/tasks.json index 73ebbe310..0c7b4f4b9 100644 --- a/packages/web5/.vscode/tasks.json +++ b/packages/api/.vscode/tasks.json @@ -34,7 +34,7 @@ "$tsc" ], "options": { - "cwd": "${workspaceFolder:web5}" + "cwd": "${workspaceFolder:api}" } }, ] diff --git a/packages/web5-agent/LICENSE b/packages/api/LICENSE similarity index 100% rename from packages/web5-agent/LICENSE rename to packages/api/LICENSE diff --git a/packages/api/README.md b/packages/api/README.md new file mode 100644 index 000000000..619e4d77b --- /dev/null +++ b/packages/api/README.md @@ -0,0 +1,440 @@ +# Web5 JS SDK + +[![NPM](https://img.shields.io/npm/v/@web5/api.svg?style=flat-square&logo=npm&logoColor=FFFFFF&color=FFEC19&santize=true)](https://www.npmjs.com/package/@web5/api) +[![Build Status](https://img.shields.io/github/actions/workflow/status/TBD54566975/web5-js/tests-ci.yml?branch=main&logo=github&label=ci&logoColor=FFFFFF&style=flat-square)](https://github.com/TBD54566975/web5-js/actions/workflows/tests-ci.yml) +[![Coverage](https://img.shields.io/codecov/c/gh/TBD54566975/web5-js/main?logo=codecov&logoColor=FFFFFF&style=flat-square&token=YI87CKF1LI)](https://codecov.io/github/TBD54566975/web5-js) +[![License](https://img.shields.io/npm/l/@web5/api.svg?style=flat-square&color=24f2ff&logo=apache&logoColor=FFFFFF&santize=true)](https://github.com/TBD54566975/web5-js/blob/main/LICENSE) +[![Chat](https://img.shields.io/badge/chat-on%20discord-7289da.svg?style=flat-square&color=9a1aff&logo=discord&logoColor=FFFFFF&sanitize=true)](https://discord.com/channels/937858703112155166/969272658501976117) + +Making developing with Web5 components at least 5 times easier to work with. + +> ⚠️ WEB5 JS SDK IS CURRENTLY IN TECH PREVIEW ⚠️ + +The SDK is currently still under active development, but having entered the Tech Preview phase there is now a drive to avoid unnecessary changes unless backwards compatibility is provided. Additional functionality will be added in the lead up to 1.0 final, and modifications will be made to address issues and community feedback. + +## Table of Contents + +- [Introduction](#introduction) +- [Installation](#installation) +- [Usage](#usage) +- [API Documentation](#api-documentation) + - [Web5.connect](#web5connectoptions) + - [web5.dwn.records.query](#web5dwnrecordsqueryrequest) + - [web5.dwn.records.create](#web5dwnrecordscreaterequest) + - [web5.dwn.records.write](#web5dwnrecordswriterequest) + - [web5.dwn.records.read](#web5dwnrecordsreadrequest) + - [web5.dwn.records.delete](#web5dwnrecordsdeleterequest) + - [web5.dwn.protocols.configure](#web5dwnprotocolsconfigurerequest) + - [web5.dwn.protocols.query](#web5dwnprotocolsqueryrequest) + - [web5.did.create](#web5didcreatemethod-options) +- [Project Resources](#project-resources) + +## Introduction + +Web5 consists of the following components: + +- Decentralized Identifiers +- Verifiable Credentials +- DWeb Node personal datastores + +The SDK sets out to gather the most oft used functionality from all three of these +pillar technologies to provide a simple library that is as close to effortless as +possible. + +## Installation + +_NPM_ + +```yaml +npm install @web5/api +``` + +_CDNs_ + +```yaml +https://unpkg.com/0.8.1/dist/browser.js +``` + +```yaml +https://cdn.jsdelivr.net/npm/@web5/api@0.8.1/dist/browser.mjs +``` + +## Usage + +### Importing the SDK + +```javascript +import { Web5 } from "@web5/api"; +``` + +or + +```javascript +import { Web5 } from CDN_LINK_HERE; +``` + +### Additional Steps + +This SDK relies indirectly on the [`@noble/ed25519`](https://github.com/paulmillr/noble-ed25519#usage) +and [`@noble/secp256k1`](https://github.com/paulmillr/noble-secp256k1#usage) packages. Therefore, +in certain environments, you'll need to perform additional steps to make it work. + +- Node.js <= 18 + +```js +// node.js 18 and earlier, needs globalThis.crypto polyfill +import { webcrypto } from "node:crypto"; +// @ts-ignore +if (!globalThis.crypto) globalThis.crypto = webcrypto; +``` + +- React Native: + +```js +// If you're on react native. React Native needs crypto.getRandomValues polyfill and sha512 +import "react-native-get-random-values"; +import { hmac } from "@noble/hashes/hmac"; +import { sha256 } from "@noble/hashes/sha256"; +import { sha512 } from "@noble/hashes/sha512"; +ed.etc.sha512Sync = (...m) => sha512(ed.etc.concatBytes(...m)); +ed.etc.sha512Async = (...m) => Promise.resolve(ed.etc.sha512Sync(...m)); + +secp.etc.hmacSha256Sync = (k, ...m) => + hmac(sha256, k, secp.etc.concatBytes(...m)); +secp.etc.hmacSha256Async = (k, ...m) => + Promise.resolve(secp.etc.hmacSha256Sync(k, ...m)); +``` + +## API Documentation + +### **`Web5.connect(options)`** + +Enables an app to request connection to a user's local identity app (like a desktop or mobile agent - work is underway for reference apps of each), or generate an in-app DID to represent the user (e.g. if the user does not have an identity app). + +> **NOTE:** The outputs of this method invocation will be used throughout the other API methods below. + +```javascript +const { web5, did: myDid } = await Web5.connect(); +``` + +#### **`options`** _(optional)_ + +An object which may specify any of the following properties: + +- **`techPreview`** - _`object`_ _(optional)_: an object that specifies configuration parameters that are relevant during the Tech Preview period of Web5 JS and may be deprecated in the future with advance notice. + + - **`dwnEndpoints`** - _`array`_ _(optional)_: a list of DWeb Node endpoints to define in the DID created and returned by `Web5.connect()`. If this property is omitted, during the Tech Preview two nodes will be included by default (e.g., `['https://dwn.tbddev.org/dwn0', 'https://dwn.tbddev.org/dwn3']`). + + For example: + + ```typescript + const { web5, did: myDid } = await Web5.connect({ + techPreview: { + dwnEndpoints: ["https://dwn.your-domain.org/"], + }, + }); + ``` + + + +#### **Response** + +An invocation of `Web5.connect()` produces the following items in response: + +- **`web5`** - _`Web5 instance`_: A class instance that enables access to a locally running DWeb Node, DID interaction methods, and other capabilities related to the connected DID. +- **`did`** - _`string`_: The DID that was created or attained connection to. + +### **`Record` instances from responses** + +Every modifying method (`create`, `write`, etc.) and the `entries` from queries return an instance of a `Record` class, which is a representation of the Record(s) being referenced. + +Each `Record` instance has the following instance properties: `id`, `attestation`, `contextId`, `dataFormat`, `dateCreated`, `encryption`, `interface`, `method`, `parentId`, `protocol`, `protocolPath`, `recipient`, `schema`, `dataCid`, `dataSize`, `dateModified`, `datePublished`, and `published`. + +> **Note** The **`id`** property is a unique identifier based on the record entry's composition. All entries across all records are deterministically unique. + +Each `Record` instance has the following instance methods: + +- **`data`** - _`object`_: an object with the following convenience methods that read out the data of the record entry in the following formats: + - **`text`** - _`function`_: produces a textual representation of the data. + - **`json`** - _`function`_: if the value is JSON data, this method will return a parsed JSON object. + - **`stream`** - _`function`_: returns the raw stream of bytes for the data. +- **`send`** - _`function`_: sends the record the instance represents to the DWeb Node endpoints of a provided DID. +- **`update`** - _`function`_: takes in a new request object matching the expected method signature of a `write` and overwrites the record. This is a convenience method that allows you to easily overwrite records with less verbosity. +- **`delete`** - _`function`_: generates a `delete` entry tombstone for the record. This is a convenience method that allows you to easily delete records with less verbosity. + +### **`web5.dwn.records.query(request)`** + +Method for querying either the locally connected DWeb Node or any remote DWeb Node specified in the `from` property. + +```javascript +// This invocation will query the user's own DWeb Nodes +const { records } = await web5.dwn.records.query({ + message: { + filter: { + schema: "https://schema.org/Playlist", + dataFormat: "application/json", + }, + }, +}); + +console.log(records); // an array of record entries from Bob's DWeb Nodes + +// This invocation will query Bob's DWeb Nodes +const { records } = await web5.dwn.records.query({ + from: "did:example:bob", + message: { + filter: { + protocol: "https://music.org/protocol", + schema: "https://schema.org/Playlist", + dataFormat: "application/json", + }, + }, +}); + +console.log(records); // an array of record entries from Bob's DWeb Nodes +``` + +#### **Request** + +The query `request` contains the following properties: + +- **`from`** - _`DID string`_ (_optional_): the decentralized identifier of the DWeb Node the query will fetch results from. +- **`message`** - _`object`_: the properties of the DWeb Node Message Descriptor that will be used to construct a valid record query: + - **`filter`** - _`object`_: properties against which results of the query will be filtered: + - **`protocol`** - _`URI string`_ (_optional_): the URI of the protocol bucket in which to query. + - **`schema`** - _`URI string`_ (_optional_): the URI of the schema bucket in which to query. + - **`dataFormat`** - _`Media Type string`_ (_optional_): the IANA string corresponding with the format of the data to filter for. See IANA's Media Type list here: https://www.iana.org/assignments/media-types/media-types.xhtml + +### **`web5.dwn.records.create(request)`** + +Method for creating a new record and storing it in the user's local DWeb Node, remote DWeb Nodes, or another party's DWeb Nodes (if permitted). + +```javascript +// this creates a record and stores it in the user's local DWeb Node +const { record } = await web5.dwn.records.create({ + data: "Hello World!", + message: { + dataFormat: "text/plain", + }, +}); + +console.log(await record.data.text()); // logs "Hello World!" +const { status } = await record.send(myDid); // send the record to the user's remote DWeb Nodes +const { status } = await record.send("did:example:bob"); // send the newly generated record to Bob's DWeb Nodes + +// this creates a record, but does not store it in the user's local DWeb Node +const { record } = await web5.dwn.records.create({ + store: false, + data: "Hello again, World!", + message: { + dataFormat: "text/plain", + }, +}); + +const { status } = await record.send("did:example:bob"); // send the newly generated record to Bob's DWeb Nodes +``` + +#### **Request** + +The `create` request object is composed as follows: + +- **`store`** - _`boolean`_ (_optional_): tells the create function whether or not to store the record in the user's local DWeb Node. (you might pass `false` if you didn't want to retain a copy of the record for yourself) +- **`data`** - _`text|object|file|blob`_: the data payload of the record. +- **`message`** - _`object`_: The properties of the DWeb Node Message Descriptor that will be used to construct a valid record query: + - **`protocol`** - _`URI string`_ (_optional_): the URI of the protocol under which the record will be bucketed. + - **`schema`** - _`URI string`_ (_optional_): the URI of the schema under which the record will be bucketed. + - **`dataFormat`** - _`Media Type string`_ (_optional_): the IANA string corresponding with the format of the data the record will be bucketed. See IANA's Media Type list here: https://www.iana.org/assignments/media-types/media-types.xhtml + +### **`web5.dwn.records.write(request)`** + +The `create()` method is an alias for `write()` and both can take the same request object properties. + +### **`web5.dwn.records.read(request)`** + +Method for reading a record stored in the user's local DWeb Node, remote DWeb Nodes, or another party's DWeb Nodes (if permitted). + +```javascript +// Reads the indicated record from the user's DWeb Nodes +const { record } = await web5.dwn.records.read({ + message: { + recordId: "bfw35evr6e54c4cqa4c589h4cq3v7w4nc534c9w7h5", + }, +}); + +console.log(await record.data.text()); // assuming the record is a text payload, logs the text + +// Reads the indicated record from Bob's DWeb Nodes +const { record } = await web5.dwn.records.read({ + from: "did:example:bob", + message: { + recordId: "bfw35evr6e54c4cqa4c589h4cq3v7w4nc534c9w7h5", + }, +}); + +console.log(await record.data.text()); // assuming the record is a text payload, logs the text +``` + +#### **Request** + +The `read` request object is composed as follows: + +- **`from`** - _`DID string`_ (_optional_): The DID of the DWeb Node the read request will fetch the indicated record from. +- **`message`** - _`object`_: The properties of the DWeb Node Message Descriptor that will be used to construct a valid DWeb Node message. + - **`recordId`** - _`string`_: the required record ID string that identifies the record data you are fetching. + +### **`web5.dwn.records.delete(request)`** + +Method for deleting a record stored in the user's local DWeb Node, remote DWeb Nodes, or another party's DWeb Nodes (if permitted). + +```javascript +// Deletes the indicated record from the user's DWeb Node +const { record } = await web5.dwn.records.delete({ + message: { + recordId: "bfw35evr6e54c4cqa4c589h4cq3v7w4nc534c9w7h5", + }, +}); + +// Deletes the indicated record from Bob's DWeb Node +const { record } = await web5.dwn.records.delete({ + from: "did:example:bob", + message: { + recordId: "bfw35evr6e54c4cqa4c589h4cq3v7w4nc534c9w7h5", + }, +}); +``` + +#### **Request** + +The `delete` request object is composed as follows: + +- **`from`** - _`DID string`_ (_optional_): The DID of the DWeb Node the delete tombstone will be sent to. +- **`message`** - _`object`_: The properties of the DWeb Node Message Descriptor that will be used to construct a valid DWeb Node message. + - **`recordId`** - _`string`_: the required record ID string that identifies the record being deleted. + +### **`web5.dwn.protocols.configure(request)`** + +Method for configuring a protocol definition in the DWeb Node of the user's local DWeb Node, remote DWeb Nodes, or another party's DWeb Nodes (if permitted). + +```javascript +const { protocol } = await web5.dwn.protocols.configure({ + message: { + definition: { + protocol: "https://photos.org/protocol", + types: { + album: { + schema: "https://photos.org/protocol/album", + dataFormats: ["application/json"], + }, + photo: { + schema: "https://photos.org/protocols/photo", + dataFormats: ["application/json"], + }, + binaryImage: { + dataFormats: ["image/png", "jpeg", "gif"], + }, + }, + structure: { + album: { + $actions: [ + { + who: "recipient", + can: "read", + }, + ], + }, + photo: { + $actions: [ + { + who: "recipient", + can: "read", + }, + ], + binaryImage: { + $actions: [ + { + who: "author", + of: "photo", + can: "write", + }, + ], + }, + }, + }, + }, + }, +}); + +protocol.send(myDid); // sends the protocol configuration to the user's other DWeb Nodes. +``` + +#### **Request** + +The `configure` request object is composed as follows: + +- **`message`** - _`object`_: The properties of the DWeb Node Message Descriptor that will be used to construct a valid DWeb Node message. + - **`definition`** - _`object`_: an object that defines the enforced composition of the protocol. + - **`protocol`** - _`URI string`_: a URI that represents the protocol being configured. + - **`types`** - _`object`_: an object that defines the records that can be used in the `structure` graph of the `definition` object. The following properties are optional constraints you can set for the type being defined: + - **`schema`** - _`URI string`_ (_optional_): the URI of the schema under which the record will be bucketed. + - **`dataFormats`** - _`Media Type string[]`_ (_optional_): Array of the IANA strings corresponding with the formats of the data the record will be bucketed. See IANA's Media Type list here: https://www.iana.org/assignments/media-types/media-types.xhtml + - **`structure`** - _`object`_: an object that defines the structure of a protocol, including data relationships and constraints on which entities can perform various activities. Fields under the `structure` object of the Protocol definition are expected to be either type references matching those defined in the `types` object. The type structures are recursive, so types form a graph and each type can have within it further attached types or the following rule statements that are all denoted with the prefix `$`: + - **`$actions`** - _`array`_: one or more rule objects that expose various allowed actions to actors (`author`, `recipient`), composed as follows: + - **`who`** - _`string`_: the actor (`author`, `recipient`) that is being permitted to invoke a given action. + - **`of`** - _`string`_: the protocol path that refers to the record subject. Using the above example protocol, the protocol path to `binaryImage` would be `photo/binaryImage`. + - **`can`** - _`string`_: the action being permitted by the rule. + +### **`web5.dwn.protocols.query(request)`** + +Method for querying a DID's DWeb Nodes for the presence of a protocol. This method is useful in detecting what protocols a given DID has installed to enable interaction over the protocol. + +```javascript +const { protocols } = await web5.dwn.protocols.query({ + message: { + filter: { + protocol: "https://music.org/protocol", + }, + }, +}); + +console.log(protocols); // logs an array of protocol configurations installed on the user's own DWeb Node + +const { protocols } = await web5.dwn.protocols.query({ + from: "did:example:bob", + message: { + filter: { + protocol: "https://music.org/protocol", + }, + }, +}); + +console.log(protocols); // logs an array of protocol configurations installed on Bob's DWeb Node +``` + +#### **Request** + +The query `request` must contain the following: + +- **`from`** - _`DID string`_ (_optional_): the decentralized identifier of the DWeb Node the query will fetch results from. +- **`message`** - _`object`_: The properties of the DWeb Node Message Descriptor that will be used to construct a valid record query: + - **`filter`** - _`object`_ (_optional_): properties against which results of the query will be filtered: + - **`protocol`** - _`URI string`_ (_optional_): the URI of the protocol bucket in which to query. + +### **`web5.did.create(method, options)`** + +The `create` method under the `did` object enables generation of DIDs for a supported set of DID Methods ('ion'|'key'). The output is method-specific, and handles things like key generation and assembly of DID Documents that can be published to DID networks. + +> NOTE: You do not usually need to manually invoke this, as the `Web5.connect()` method already acquires a DID for the user (either by direct creation or connection to an identity agent app). + +```javascript +const myDid = await Web5.did.create("ion"); +``` + +## Project Resources + +| Resource | Description | +| ----------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- | +| [CODEOWNERS](https://github.com/TBD54566975/web5-js/blob/main/CODEOWNERS) | Outlines the project lead(s) | +| [CODE_OF_CONDUCT.md](https://github.com/TBD54566975/web5-js/blob/main/CODE_OF_CONDUCT.md) | Expected behavior for project contributors, promoting a welcoming environment | +| [CONTRIBUTING.md](https://github.com/TBD54566975/web5-js/blob/main/CONTRIBUTING.md) | Developer guide to build, test, run, access CI, chat, discuss, file issues | +| [GOVERNANCE.md](https://github.com/TBD54566975/web5-js/blob/main/GOVERNANCE.md) | Project governance | +| [LICENSE](./LICENSE) | Apache License, Version 2.0 | diff --git a/packages/web5/build/bundles.js b/packages/api/build/bundles.js similarity index 100% rename from packages/web5/build/bundles.js rename to packages/api/build/bundles.js diff --git a/packages/web5/build/esbuild-browser-config.cjs b/packages/api/build/esbuild-browser-config.cjs similarity index 96% rename from packages/web5/build/esbuild-browser-config.cjs rename to packages/api/build/esbuild-browser-config.cjs index a3ddbd9f8..bd8bd99b1 100644 --- a/packages/web5/build/esbuild-browser-config.cjs +++ b/packages/api/build/esbuild-browser-config.cjs @@ -15,7 +15,7 @@ for (let lib in stdLibBrowser) { /** @type {import('esbuild').BuildOptions} */ module.exports = { - entryPoints : ['./src/main.ts'], + entryPoints : ['./src/index.ts'], bundle : true, format : 'esm', sourcemap : true, @@ -27,4 +27,4 @@ module.exports = { define : { 'global': 'globalThis', }, -}; +}; \ No newline at end of file diff --git a/packages/api/karma.conf.cjs b/packages/api/karma.conf.cjs new file mode 100644 index 000000000..6b7407b2c --- /dev/null +++ b/packages/api/karma.conf.cjs @@ -0,0 +1,87 @@ +/* eslint-disable @typescript-eslint/no-var-requires */ +// Karma is what we're using to run our tests in browser environments +// Karma does not support .mjs + +// playwright acts as a safari executable on windows and mac +const playwright = require('@playwright/test'); +const esbuildBrowserConfig = require('./build/esbuild-browser-config.cjs'); + +// use playwright chrome exec path as run target for chromium tests +process.env.CHROME_BIN = playwright.chromium.executablePath(); + +// use playwright webkit exec path as run target for safari tests +process.env.WEBKIT_HEADLESS_BIN = playwright.webkit.executablePath(); + +// use playwright firefox exec path as run target for firefox tests +process.env.FIREFOX_BIN = playwright.firefox.executablePath(); + +module.exports = function (config) { + config.set({ + plugins: [ + 'karma-chrome-launcher', + 'karma-firefox-launcher', + 'karma-webkit-launcher', + 'karma-esbuild', + 'karma-mocha', + 'karma-mocha-reporter', + ], + + // frameworks to use + // available frameworks: https://www.npmjs.com/search?q=keywords:karma-adapter + frameworks: ['mocha'], + + client: { + // Increase Mocha's default timeout of 2 seconds to prevent timeouts during GitHub CI runs. + mocha: { + timeout: 10000 // 10 seconds + }, + // If an environment variable is defined, override the default test DWN URL. + testDwnUrl: process.env.TEST_DWN_URL, + }, + + // list of files / patterns to load in the browser + files: [ + { pattern: 'tests/**/*.spec.ts', watched: false }, + ], + + // preprocess matching files before serving them to the browser + // available preprocessors: https://www.npmjs.com/search?q=keywords:karma-preprocessor + preprocessors: { + 'tests/**/*.spec.ts': ['esbuild'], + }, + + esbuild: esbuildBrowserConfig, + + // list of files / patterns to exclude + exclude: [], + + // test results reporter to use + // available reporters: https://www.npmjs.com/search?q=keywords:karma-reporter + reporters: ['mocha'], + + // web server port + port: 9876, + + // enable / disable colors in the output (reporters and logs) + colors: true, + + // level of logging + // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || + // config.LOG_INFO || config.LOG_DEBUG + logLevel: config.LOG_INFO, + + concurrency: 1, + + // start these browsers + // available browser launchers: https://www.npmjs.com/search?q=keywords:karma-launcher + browsers: ['ChromeHeadless', 'FirefoxHeadless', 'WebkitHeadless'], + + // Continuous Integration mode + // if true, Karma captures browsers, runs the tests and exits + singleRun: true, + + // Increase browser timeouts to avoid DISCONNECTED messages during GitHub CI runs. + browserDisconnectTimeout : 10000, // default 2000 + browserDisconnectTolerance : 1, // default 0 + }); +}; diff --git a/packages/web5/package.json b/packages/api/package.json similarity index 75% rename from packages/web5/package.json rename to packages/api/package.json index 3a6d3b2e8..abe26e3ed 100644 --- a/packages/web5/package.json +++ b/packages/api/package.json @@ -1,11 +1,11 @@ { - "name": "@tbd54566975/web5", - "version": "0.8.0", + "name": "@web5/api", + "version": "0.8.1", "description": "SDK for accessing the features and capabilities of Web5", "type": "module", - "main": "./dist/cjs/main.js", - "module": "./dist/esm/main.js", - "types": "./dist/types/main.d.ts", + "main": "./dist/cjs/index.js", + "module": "./dist/esm/index.js", + "types": "./dist/types/index.d.ts", "scripts": { "clean": "rimraf dist tests/compiled", "build:esm": "rimraf dist/esm dist/types && npx tsc -p tsconfig.json", @@ -18,12 +18,12 @@ "test:node": "npm run build:tests:node && c8 mocha", "test:browser": "karma start karma.conf.cjs" }, - "homepage": "https://github.com/TBD54566975/web5-js/tree/main/packages/web5#readme", + "homepage": "https://github.com/TBD54566975/web5-js/tree/main/packages/api#readme", "bugs": "https://github.com/TBD54566975/web5-js/issues", "repository": { "type": "git", "url": "git+https://github.com/TBD54566975/web5-js", - "directory": "packages/web5" + "directory": "packages/api" }, "license": "Apache-2.0", "contributors": [ @@ -46,12 +46,12 @@ ], "exports": { ".": { - "import": "./dist/esm/main.js", - "require": "./dist/cjs/main.js", - "types": "./dist/types/main.d.ts" + "types": "./dist/types/index.d.ts", + "import": "./dist/esm/index.js", + "require": "./dist/cjs/index.js" } }, - "react-native": "./dist/esm/main.js", + "react-native": "./dist/esm/index.js", "keywords": [ "decentralized", "decentralized-applications", @@ -70,32 +70,32 @@ "node": ">=18.0.0" }, "dependencies": { - "@decentralized-identity/ion-tools": "1.1.4", - "@tbd54566975/crypto": "0.8.0", - "@tbd54566975/dids": "0.8.0", "@tbd54566975/dwn-sdk-js": "0.2.1", - "@tbd54566975/web5-agent": "0.8.0", - "@tbd54566975/web5-proxy-agent": "0.8.0", - "@tbd54566975/web5-user-agent": "0.8.0", + "@web5/agent": "0.2.0", + "@web5/crypto": "0.2.0", + "@web5/dids": "0.2.0", + "@web5/user-agent": "0.2.0", "level": "8.0.0", "ms": "2.1.3", + "readable-stream": "4.4.2", "readable-web-to-node-stream": "3.0.2" }, "devDependencies": { - "@types/chai": "4.3.0", + "@playwright/test": "1.36.2", + "@types/chai": "4.3.5", "@types/chai-as-promised": "7.1.5", - "@types/eslint": "8.37.0", + "@types/eslint": "8.44.2", "@types/mocha": "10.0.1", "@types/ms": "0.7.31", - "@types/readable-stream": "2.3.15", + "@types/readable-stream": "4.0.0", "@types/sinon": "10.0.15", - "@typescript-eslint/eslint-plugin": "5.59.0", - "@typescript-eslint/parser": "5.59.0", - "c8": "8.0.0", + "@typescript-eslint/eslint-plugin": "6.4.0", + "@typescript-eslint/parser": "6.4.0", + "c8": "8.0.1", "chai": "4.3.7", "chai-as-promised": "7.1.1", "esbuild": "0.16.17", - "eslint": "8.39.0", + "eslint": "8.47.0", "eslint-plugin-mocha": "10.1.0", "karma": "6.4.1", "karma-chai": "0.1.0", @@ -113,4 +113,4 @@ "source-map-loader": "4.0.1", "typescript": "5.1.6" } -} \ No newline at end of file +} diff --git a/packages/api/src/did-api.ts b/packages/api/src/did-api.ts new file mode 100644 index 000000000..d28474556 --- /dev/null +++ b/packages/api/src/did-api.ts @@ -0,0 +1,101 @@ +import type { Web5Agent } from '@web5/agent'; + +// import type { +// DidKeyOptions, +// DidIonCreateOptions, +// DidMethodApi, +// DidMethodCreator, +// DidMethodResolver, +// DidResolverCache, +// DidResolutionResult, +// DidState +// } from '@web5/dids'; + + + +// import { DidResolver } from '@web5/dids'; + +// // Map method names to option types +// type CreateMethodOptions = { +// ion: DidIonCreateOptions; +// key: DidKeyOptions; +// }; + +// // A conditional type for inferring options based on the method name +// type CreateOptions = CreateMethodOptions[M]; + +// export type DidApiOptions = { +// didMethodApis: DidMethodApi[]; +// cache?: DidResolverCache; +// } +export class DidApi { + // private didResolver: DidResolver; + // private methodCreatorMap: Map = new Map(); + + // /** + // * returns the DID resolver created by this api. useful in scenarios where you want to pass around + // * the same resolver so that you can leverage the resolver's cache + // */ + // get resolver() { + // return this.didResolver; + // } + + private agent: Web5Agent; + private connectedDid: string; + + constructor(options: { agent: Web5Agent, connectedDid: string }) { + this.agent = options.agent; + this.connectedDid = options.connectedDid; + } + + // constructor(options: DidApiOptions) { + // const { didMethodApis, cache } = options; + + // this.didResolver = new DidResolver({ methodResolvers: options.didMethodApis, cache }); + + // for (let methodApi of didMethodApis) { + // this.methodCreatorMap.set(methodApi.methodName, methodApi); + // } + // } + + // /** + // * Creates a DID of the method provided + // * @param method - the method of DID to create + // * @param options - method-specific options + // * @returns the created DID + // */ + // create(method: M, options?: CreateOptions): Promise { + // const didMethodCreator = this.methodCreatorMap.get(method); + // if (!didMethodCreator) { + // throw new Error(`no creator available for ${method}`); + // } + + // return didMethodCreator.create(options); + // } + + // /** + // * Resolves the provided DID + // * @param did - the did to resolve + // * @see {@link https://www.w3.org/TR/did-core/#did-resolution | DID Resolution} + // * @returns DID Resolution Result + // */ + // resolve(did: string): Promise { + // return this.didResolver.resolve(did); + // } + + // /** + // * can be used to add different did method resolvers + // * @param _resolver + // */ + // addMethodResolver(_resolver: DidMethodResolver) { + // throw new Error('not yet implemented'); + // } + + // /** + // * can be used to add differed did method creators + // * @param _creator + // */ + // addMethodCreator(_creator: DidMethodCreator) { + // throw new Error('not yet implemented'); + // } +} \ No newline at end of file diff --git a/packages/api/src/dwn-api.ts b/packages/api/src/dwn-api.ts new file mode 100644 index 000000000..dc70c5884 --- /dev/null +++ b/packages/api/src/dwn-api.ts @@ -0,0 +1,377 @@ +import type { DwnResponse, Web5Agent } from '@web5/agent'; +import type { + UnionMessageReply, + RecordsReadOptions, + RecordsQueryOptions, + RecordsWriteMessage, + RecordsWriteOptions, + RecordsDeleteOptions, + ProtocolsQueryOptions, + RecordsQueryReplyEntry, + ProtocolsConfigureMessage, + ProtocolsConfigureOptions, + ProtocolsConfigureDescriptor, +} from '@tbd54566975/dwn-sdk-js'; + +import { isEmptyObject } from '@web5/common'; +import { DwnInterfaceName, DwnMethodName } from '@tbd54566975/dwn-sdk-js'; + +import { Record } from './record.js'; +import { Protocol } from './protocol.js'; +import { dataToBlob } from './utils.js'; + +export type ProtocolsConfigureRequest = { + message: Omit; +} + +export type ProtocolsConfigureResponse = { + status: UnionMessageReply['status']; + protocol?: Protocol; +} + +export type ProtocolsQueryReplyEntry = { + descriptor: ProtocolsConfigureDescriptor; +}; + +export type ProtocolsQueryRequest = { + from?: string; + message: Omit +} + +export type ProtocolsQueryResponse = { + protocols: Protocol[]; + status: UnionMessageReply['status']; +} + +export type RecordsCreateRequest = RecordsWriteRequest; + +export type RecordsCreateResponse = RecordsWriteResponse; + +export type RecordsCreateFromRequest = { + author: string; + data: unknown; + message?: Omit; + record: Record; +} + +export type RecordsDeleteRequest = { + from?: string; + message: Omit; +} + +export type RecordsDeleteResponse = { + status: UnionMessageReply['status']; +}; + +export type RecordsQueryRequest = { + /** The from property indicates the DID to query from and return results. */ + from?: string; + message: Omit; +} + +export type RecordsQueryResponse = { + status: UnionMessageReply['status']; + records?: Record[] +}; + +export type RecordsReadRequest = { + /** The from property indicates the DID to read from and return results fro. */ + from?: string; + message: Omit; +} + +export type RecordsReadResponse = { + status: UnionMessageReply['status']; + record: Record; +}; + +export type RecordsWriteRequest = { + data: unknown; + message?: Omit, 'authorizationSignatureInput'>; + store?: boolean; +} + +export type RecordsWriteResponse = { + status: UnionMessageReply['status']; + record?: Record +}; + +/** + * TODO: Document class. + */ +export class DwnApi { + private agent: Web5Agent; + private connectedDid: string; + + constructor(options: { agent: Web5Agent, connectedDid: string }) { + this.agent = options.agent; + this.connectedDid = options.connectedDid; + } + + /** + * TODO: Document namespace. + */ + get protocols() { + return { + /** + * TODO: Document method. + */ + configure: async (request: ProtocolsConfigureRequest): Promise => { + const agentResponse = await this.agent.processDwnRequest({ + target : this.connectedDid, + author : this.connectedDid, + messageOptions : request.message, + messageType : DwnInterfaceName.Protocols + DwnMethodName.Configure + }); + + const { message, messageCid, reply: { status }} = agentResponse; + const response: ProtocolsConfigureResponse = { status }; + + if (status.code < 300) { + const metadata = { author: this.connectedDid, messageCid }; + response.protocol = new Protocol(this.agent, message as ProtocolsConfigureMessage, metadata); + } + + return response; + }, + + /** + * TODO: Document method. + */ + query: async (request: ProtocolsQueryRequest): Promise => { + const agentRequest = { + author : this.connectedDid, + messageOptions : request.message, + messageType : DwnInterfaceName.Protocols + DwnMethodName.Query, + target : request.from || this.connectedDid + }; + + let agentResponse: DwnResponse; + + if (request.from) { + agentResponse = await this.agent.sendDwnRequest(agentRequest); + } else { + agentResponse = await this.agent.processDwnRequest(agentRequest); + } + + const { reply: { entries = [], status } } = agentResponse; + + const protocols = entries.map((entry: ProtocolsQueryReplyEntry) => { + const metadata = { author: this.connectedDid, }; + + return new Protocol(this.agent, entry, metadata); + }); + + return { protocols, status }; + } + }; + } + + /** + * TODO: Document namespace. + */ + get records() { + return { + /** + * TODO: Document method. + */ + create: async (request: RecordsCreateRequest): Promise => { + return this.records.write(request); + }, + + /** + * TODO: Document method. + */ + createFrom: async (request: RecordsCreateFromRequest): Promise => { + const { author: inheritedAuthor, ...inheritedProperties } = request.record.toJSON(); + + // Remove target from inherited properties since target is being explicitly defined in method parameters. + delete inheritedProperties.target; + + + // If `data` is being updated then `dataCid` and `dataSize` must not be present. + if (request.data !== undefined) { + delete inheritedProperties.dataCid; + delete inheritedProperties.dataSize; + } + + // If `published` is set to false, ensure that `datePublished` is undefined. Otherwise, DWN SDK's schema validation + // will throw an error if `published` is false but `datePublished` is set. + if (request.message?.published === false && inheritedProperties.datePublished !== undefined) { + delete inheritedProperties.datePublished; + delete inheritedProperties.published; + } + + // If the request changes the `author` or message `descriptor` then the deterministic `recordId` will change. + // As a result, we will discard the `recordId` if either of these changes occur. + if (!isEmptyObject(request.message) || (request.author && request.author !== inheritedAuthor)) { + delete inheritedProperties.recordId; + } + + return this.records.write({ + data : request.data, + message : { + ...inheritedProperties, + ...request.message, + }, + }); + }, + + /** + * TODO: Document method. + */ + delete: async (request: RecordsDeleteRequest): Promise => { + const agentRequest = { + author : this.connectedDid, + messageOptions : request.message, + messageType : DwnInterfaceName.Records + DwnMethodName.Delete, + target : request.from || this.connectedDid + }; + + let agentResponse; + + if (request.from) { + agentResponse = await this.agent.sendDwnRequest(agentRequest); + } else { + agentResponse = await this.agent.processDwnRequest(agentRequest); + } + + //! TODO: (Frank -> Moe): This quirk is the result of how 4XX errors are being returned by `dwn-server` + //! When DWN SDK returns 404, agentResponse is { status: { code: 404 }} and that's it. + //! Need to decide how to resolve. + let status; + if (agentResponse.reply) { + ({ reply: { status } } = agentResponse); + } else { + ({ status } = agentResponse); + } + + return { status }; + }, + + /** + * TODO: Document method. + */ + query: async (request: RecordsQueryRequest): Promise => { + const agentRequest = { + author : this.connectedDid, + messageOptions : request.message, + messageType : DwnInterfaceName.Records + DwnMethodName.Query, + target : request.from || this.connectedDid + }; + + let agentResponse; + + if (request.from) { + agentResponse = await this.agent.sendDwnRequest(agentRequest); + } else { + agentResponse = await this.agent.processDwnRequest(agentRequest); + } + + const { reply: { entries, status } } = agentResponse; + + const records = entries.map((entry: RecordsQueryReplyEntry) => { + const recordOptions = { + author : this.connectedDid, + target : this.connectedDid, + ...entry as RecordsWriteMessage + }; + const record = new Record(this.agent, recordOptions); + return record; + }); + + return { records, status }; + }, + + /** + * TODO: Document method. + */ + read: async (request: RecordsReadRequest): Promise => { + const agentRequest = { + author : this.connectedDid, + messageOptions : request.message, + messageType : DwnInterfaceName.Records + DwnMethodName.Read, + target : request.from || this.connectedDid + }; + + let agentResponse; + + if (request.from) { + agentResponse = await this.agent.sendDwnRequest(agentRequest); + } else { + agentResponse = await this.agent.processDwnRequest(agentRequest); + } + + //! TODO: (Frank -> Moe): This quirk is the result of how 4XX errors are being returned by `dwn-server` + //! When DWN SDK returns 404, agentResponse is { status: { code: 404 }} and that's it. + //! Need to decide how to resolve. + let responseRecord; + let status; + if (agentResponse.reply) { + ({ reply: { record: responseRecord, status } } = agentResponse); + } else { + ({ status } = agentResponse); + } + + let record: Record; + if (200 <= status.code && status.code <= 299) { + const recordOptions = { + author : this.connectedDid, + target : this.connectedDid, + ...responseRecord, + }; + + record = new Record(this.agent, recordOptions); + } + + return { record, status }; + }, + + /** + * TODO: Document method. + * + * As a convenience, the Record instance returned will cache a copy of the data if the + * data size, in bytes, is less than the DWN 'max data size allowed to be encoded' + * parameter of 10KB. This is done to maintain consistency with other DWN methods, + * like RecordsQuery, that include relatively small data payloads when returning + * RecordsWrite message properties. Regardless of data size, methods such as + * `record.data.stream()` will return the data when called even if it requires fetching + * from the DWN datastore. + */ + write: async (request: RecordsWriteRequest): Promise => { + const messageOptions: Partial = { + ...request.message + }; + + const { dataBlob, dataFormat } = dataToBlob(request.data, messageOptions.dataFormat); + messageOptions.dataFormat = dataFormat; + + const agentResponse = await this.agent.processDwnRequest({ + author : this.connectedDid, + dataStream : dataBlob, + messageOptions, + messageType : DwnInterfaceName.Records + DwnMethodName.Write, + store : request.store, + target : this.connectedDid + }); + + const { message, reply: { status } } = agentResponse; + const responseMessage = message as RecordsWriteMessage; + + let record: Record; + if (200 <= status.code && status.code <= 299) { + const recordOptions = { + author : this.connectedDid, + encodedData : dataBlob, + target : this.connectedDid, + ...responseMessage, + }; + + record = new Record(this.agent, recordOptions); + } + + return { record, status }; + }, + }; + } +} \ No newline at end of file diff --git a/packages/api/src/index.ts b/packages/api/src/index.ts new file mode 100644 index 000000000..8bf80c7d6 --- /dev/null +++ b/packages/api/src/index.ts @@ -0,0 +1 @@ +export * from './web5.js'; \ No newline at end of file diff --git a/packages/api/src/protocol.ts b/packages/api/src/protocol.ts new file mode 100644 index 000000000..c22181eb3 --- /dev/null +++ b/packages/api/src/protocol.ts @@ -0,0 +1,40 @@ +import type { Web5Agent } from '@web5/agent'; +import type { ProtocolsConfigure } from '@tbd54566975/dwn-sdk-js'; + +// TODO: export ProtocolsConfigureMessage from dwn-sdk-js +export type ProtocolsConfigureMessage = ProtocolsConfigure['message']; +type ProtocolMetadata = { + author: string; + messageCid?: string; +}; + +export class Protocol { + private _agent: Web5Agent; + private _metadata: ProtocolMetadata; + private _protocolsConfigureMessage: ProtocolsConfigureMessage; + + get definition() { + return this._protocolsConfigureMessage.descriptor.definition; + } + + constructor(agent: Web5Agent, protocolsConfigureMessage: ProtocolsConfigureMessage, metadata: ProtocolMetadata) { + this._agent = agent; + this._metadata = metadata; + this._protocolsConfigureMessage = protocolsConfigureMessage; + } + + toJSON() { + return this._protocolsConfigureMessage; + } + + async send(target: string) { + const { reply } = await this._agent.sendDwnRequest({ + author : this._metadata.author, + messageCid : this._metadata.messageCid, + messageType : 'ProtocolsConfigure', + target : target, + }); + + return { status: reply.status }; + } +} \ No newline at end of file diff --git a/packages/web5/src/record.ts b/packages/api/src/record.ts similarity index 83% rename from packages/web5/src/record.ts rename to packages/api/src/record.ts index 684b7a8f4..1af6fe69e 100644 --- a/packages/web5/src/record.ts +++ b/packages/api/src/record.ts @@ -1,5 +1,5 @@ +import type { Web5Agent } from '@web5/agent'; import type { Readable } from 'readable-stream'; -import type { Web5Agent } from '@tbd54566975/web5-agent'; import type { RecordsReadReply, RecordsWriteDescriptor, RecordsWriteMessage, RecordsWriteOptions } from '@tbd54566975/dwn-sdk-js'; import { ReadableWebToNodeStream } from 'readable-web-to-node-stream'; @@ -15,23 +15,32 @@ export type RecordOptions = RecordsWriteMessage & { data?: Readable | ReadableStream; }; -export type RecordModel = RecordsWriteDescriptor & Omit & { - author: string; - recordId?: string; - target: string; -} +export type RecordModel = RecordsWriteDescriptor + & Omit + & { + author: string; + recordId?: string; + target: string; + } export type RecordUpdateOptions = { data?: unknown; dataCid?: RecordsWriteDescriptor['dataCid']; dataSize?: RecordsWriteDescriptor['dataSize']; - messageTimestamp?: RecordsWriteDescriptor['messageTimestamp']; + dateModified?: RecordsWriteDescriptor['messageTimestamp']; datePublished?: RecordsWriteDescriptor['datePublished']; published?: RecordsWriteDescriptor['published']; } /** * TODO: Document class. + * + * Note: The `messageTimestamp` of the most recent RecordsWrite message is + * logically equivalent to the date/time at which a Record was most + * recently modified. Since this Record class implementation is + * intended to simplify the developer experience of working with + * logical records (and not individual DWN messages) the + * `messageTimestamp` is mapped to `dateModified`. */ export class Record implements RecordModel { // mutable properties @@ -39,6 +48,7 @@ export class Record implements RecordModel { target: string; isDeleted = false; + private _agent: Web5Agent; private _attestation?: RecordsWriteMessage['attestation']; private _contextId?: string; private _descriptor: RecordsWriteDescriptor; @@ -46,7 +56,6 @@ export class Record implements RecordModel { private _encryption?: RecordsWriteMessage['encryption']; private _readableStream?: Readable | Promise; private _recordId: string; - private _web5Agent: Web5Agent; // Immutable DWN Record properties. get attestation(): RecordsWriteMessage['attestation'] { return this._attestation; } @@ -66,13 +75,13 @@ export class Record implements RecordModel { // Mutable DWN Record properties. get dataCid() { return this._descriptor.dataCid; } get dataSize() { return this._descriptor.dataSize; } - get messageTimestamp() { return this._descriptor.messageTimestamp; } - get dateModified() { return this.messageTimestamp; } + get dateModified() { return this._descriptor.messageTimestamp; } get datePublished() { return this._descriptor.datePublished; } + get messageTimestamp() { return this._descriptor.messageTimestamp; } get published() { return this._descriptor.published; } - constructor(web5Agent: Web5Agent, options: RecordOptions) { - this._web5Agent = web5Agent; + constructor(agent: Web5Agent, options: RecordOptions) { + this._agent = agent; // Store the target and author DIDs that were used to create the message to use for subsequent reads, etc. this.author = options.author; @@ -107,7 +116,7 @@ export class Record implements RecordModel { // `encodedData` will be set if the Record was instantiated by dwn.records.create()/write(). // `readableStream` will be set if Record was instantiated by dwn.records.read(). // If neither of the above are true, then the record must be fetched from the DWN. - this._readableStream = this._web5Agent.processDwnRequest({ + this._readableStream = this._agent.processDwnRequest({ author : this.author, messageOptions : { recordId: this.id }, messageType : DwnInterfaceName.Records + DwnMethodName.Read, @@ -127,7 +136,7 @@ export class Record implements RecordModel { this._encodedData = new Blob([dataBytes], { type: this.dataFormat }); } - // Explicitly cast _encodedData as a Blob since if non-null, it has been converted from string to Blob. + // Explicitly cast `encodedData` as a Blob since, if non-null, it has been converted from string to Blob. const dataBlob = this._encodedData as Blob; // eslint-disable-next-line @typescript-eslint/no-this-alias @@ -169,7 +178,7 @@ export class Record implements RecordModel { if (this.isDeleted) throw new Error('Operation failed: Attempted to call `delete()` on a record that has already been deleted.'); // Attempt to delete the record from the DWN. - const agentResponse = await this._web5Agent.processDwnRequest({ + const agentResponse = await this._agent.processDwnRequest({ author : this.author, messageOptions : { recordId: this.id }, messageType : DwnInterfaceName.Records + DwnMethodName.Delete, @@ -192,7 +201,7 @@ export class Record implements RecordModel { async send(target: string): Promise { if (this.isDeleted) throw new Error('Operation failed: Attempted to call `send()` on a record that has already been deleted.'); - const { reply: { status } } = await this._web5Agent.sendDwnRequest({ + const { reply: { status } } = await this._agent.sendDwnRequest({ messageType : DwnInterfaceName.Records + DwnMethodName.Write, author : this.author, dataStream : await this.data.blob(), @@ -259,13 +268,17 @@ export class Record implements RecordModel { async update(options: RecordUpdateOptions = {}) { if (this.isDeleted) throw new Error('Operation failed: Attempted to call `update()` on a record that has already been deleted.'); + // Map Record class `dateModified` property to DWN SDK `messageTimestamp`. + const { dateModified, ...updateOptions } = options as Partial & RecordUpdateOptions; + updateOptions.messageTimestamp = dateModified; + // Begin assembling update message. - let updateMessage = { ...this._descriptor, ...options } as Partial; + let updateMessage = {...this._descriptor, ...updateOptions } as Partial; let dataBlob: Blob; if (options.data !== undefined) { // If `data` is being updated then `dataCid` and `dataSize` must be undefined and the `data` property is passed as - // a top-level property to `web5Agent.processDwnRequest()`. + // a top-level property to `agent.processDwnRequest()`. delete updateMessage.dataCid; delete updateMessage.dataSize; delete updateMessage.data; @@ -277,10 +290,10 @@ export class Record implements RecordModel { const mutableDescriptorProperties = new Set(['data', 'dataCid', 'dataSize', 'dateModified', 'datePublished', 'published']); Record.verifyPermittedMutation(Object.keys(options), mutableDescriptorProperties); - // If a new `dateModified` was not provided, remove it from the updateMessage to let the DWN SDK auto-fill. - // This is necessary because otherwise DWN SDK throws an Error 409 Conflict due to attempting to overwrite a record - // when the `dateModified` timestamps are identical. - if (options.messageTimestamp === undefined) { + // If a new `dateModified` was not provided, remove the equivalent `messageTimestamp` property from from the + // updateMessage to let the DWN SDK auto-fill. This is necessary because otherwise DWN SDK throws an + // Error 409 Conflict due to attempting to overwrite a record when the `messageTimestamp` values are identical. + if (options.dateModified === undefined) { delete updateMessage.messageTimestamp; } @@ -298,7 +311,7 @@ export class Record implements RecordModel { ...updateMessage }; - const agentResponse = await this._web5Agent.processDwnRequest({ + const agentResponse = await this._agent.processDwnRequest({ author : this.author, dataStream : dataBlob, messageOptions, @@ -314,9 +327,9 @@ export class Record implements RecordModel { mutableDescriptorProperties.forEach(property => { this._descriptor[property] = responseMessage.descriptor[property]; }); - // Only cache data if `dataSize` is less than DWN 'max data size allowed to be encoded'. + // Cache data. if (options.data !== undefined) { - this._encodedData = dataBlob; // Clear `encodedData` in case it was previously set. + this._encodedData = dataBlob; } } @@ -333,7 +346,7 @@ export class Record implements RecordModel { /** * TODO: Document method. */ - static isReadableWebStream(stream) { + private static isReadableWebStream(stream) { // TODO: Improve robustness of the check modeled after node:stream. return typeof stream._read !== 'function'; } @@ -341,7 +354,7 @@ export class Record implements RecordModel { /** * TODO: Document method. */ - private static verifyPermittedMutation(propertiesToMutate: string[], mutableDescriptorProperties: Set) { + private static verifyPermittedMutation(propertiesToMutate: Iterable, mutableDescriptorProperties: Set) { for (const property of propertiesToMutate) { if (!mutableDescriptorProperties.has(property)) { throw new Error(`${property} is an immutable property. Its value cannot be changed.`); diff --git a/packages/api/src/tech-preview.ts b/packages/api/src/tech-preview.ts new file mode 100644 index 000000000..071636f3d --- /dev/null +++ b/packages/api/src/tech-preview.ts @@ -0,0 +1,55 @@ +import * as didUtils from '@web5/dids/utils'; + +/** + * Dynamically selects up to 2 DWN endpoints that are provided + * by default during the Tech Preview period. + */ +export async function getTechPreviewDwnEndpoints(): Promise { + let response: Response; + try { + response = await fetch('https://dwn.tbddev.org/.well-known/did.json'); + if (!response.ok) { + throw new Error(`HTTP Error: ${response.status} ${response.statusText}`); + } + } catch(error: any) { + console.warn('failed to get tech preview dwn endpoints:', error.message); + return []; + } + + const didDocument = await response.json(); + const [ dwnService ] = didUtils.getServices({ didDocument, id: '#dwn', type: 'DecentralizedWebNode' }); + + // allocate up to 2 nodes for a user. + const techPreviewEndpoints = new Set(); + + if ('serviceEndpoint' in dwnService + && !Array.isArray(dwnService.serviceEndpoint) + && typeof dwnService.serviceEndpoint !== 'string' + && Array.isArray(dwnService.serviceEndpoint.nodes)) { + const dwnUrls = dwnService.serviceEndpoint.nodes; + + const numNodesToAllocate = Math.min(dwnUrls.length, 2); + + for (let attempts = 0; attempts < dwnUrls.length && techPreviewEndpoints.size < numNodesToAllocate; attempts += 1) { + const nodeIdx = getRandomInt(0, dwnUrls.length); + const dwnUrl = dwnUrls[nodeIdx]; + + try { + const healthCheck = await fetch(`${dwnUrl}/health`); + if (healthCheck.ok) { + techPreviewEndpoints.add(dwnUrl); + } + } catch(error: unknown) { + // Ignore healthcheck failures and try the next node. + } + } + } + + return Array.from(techPreviewEndpoints); +} + +function getRandomInt(min, max) { + min = Math.ceil(min); + max = Math.floor(max); + return Math.floor(Math.random() * (max - min)) + min; +} \ No newline at end of file diff --git a/packages/api/src/utils.ts b/packages/api/src/utils.ts new file mode 100644 index 000000000..18048903f --- /dev/null +++ b/packages/api/src/utils.ts @@ -0,0 +1,27 @@ +import { Convert, universalTypeOf } from '@web5/common'; + +/** + * Set/detect the media type and return the data as bytes. + */ +export const dataToBlob = (data: any, dataFormat?: string) => { + let dataBlob: Blob; + + // Check for Object or String, and if neither, assume bytes. + const detectedType = universalTypeOf(data); + if (dataFormat === 'text/plain' || detectedType === 'String') { + dataBlob = new Blob([data], { type: 'text/plain' }); + } else if (dataFormat === 'application/json' || detectedType === 'Object') { + const dataBytes = Convert.object(data).toUint8Array(); + dataBlob = new Blob([dataBytes], { type: 'application/json' }); + } else if (detectedType === 'Uint8Array' || detectedType === 'ArrayBuffer') { + dataBlob = new Blob([data], { type: 'application/octet-stream' }); + } else if (detectedType === 'Blob') { + dataBlob = data; + } else { + throw new Error('data type not supported.'); + } + + dataFormat = dataFormat || dataBlob.type || 'application/octet-stream'; + + return { dataBlob, dataFormat }; +}; \ No newline at end of file diff --git a/packages/api/src/vc-api.ts b/packages/api/src/vc-api.ts new file mode 100644 index 000000000..7dd6620e1 --- /dev/null +++ b/packages/api/src/vc-api.ts @@ -0,0 +1,16 @@ +import type { Web5Agent } from '@web5/agent'; + +export class VcApi { + private agent: Web5Agent; + private connectedDid: string; + + constructor(options: { agent: Web5Agent, connectedDid: string }) { + this.agent = options.agent; + this.connectedDid = options.connectedDid; + } + + async create() { + // TODO: implement + throw new Error('Not implemented.'); + } +} \ No newline at end of file diff --git a/packages/api/src/web5.ts b/packages/api/src/web5.ts new file mode 100644 index 000000000..b8b8da587 --- /dev/null +++ b/packages/api/src/web5.ts @@ -0,0 +1,113 @@ +import type { AppDataStore, Web5Agent } from '@web5/agent'; + +import { Web5UserAgent } from '@web5/user-agent'; + +import { VcApi } from './vc-api.js'; +import { DwnApi } from './dwn-api.js'; +import { DidApi } from './did-api.js'; +import { getTechPreviewDwnEndpoints } from './tech-preview.js'; +import { DidIonMethod } from '@web5/dids'; + +/** + * Override defaults configured during the technical preview phase. + */ +export type TechPreviewOptions = { + // Override default dwnEndpoints provided for technical preview. + dwnEndpoints?: string[]; +} + +/** + * Optional overrides that can be provided when calling {@link Web5.connect}. + */ +export type Web5ConnectOptions = { + /** Provide a {@link Web5Agent} implementation. Defaults to creating a local + * {@link Web5UserAgent} if one isn't provided */ + agent?: Web5Agent; + + /** Specify an existing DID to connect to. */ + connectedDid?: string; + + /** Provide an instance of a {@link AppDataStore} implementation. Defaults to + * a LevelDB-backed store with an insecure, static unlock passphrase if one + * isn't provided. To allow the app user to enter a secure passphrase of + * their choosing, provide an initialized {@link AppDataStore} instance. */ + appData?: AppDataStore; + + /** Override defaults configured during the technical preview phase. + * See {@link TechPreviewOptions} for available options. */ + techPreview?: TechPreviewOptions; +} + +/** + * @see {@link Web5ConnectOptions} + */ +type Web5Options = { + agent: Web5Agent; + connectedDid: string; +}; + +export class Web5 { + agent: Web5Agent; + did: DidApi; + dwn: DwnApi; + vc: VcApi; + private connectedDid: string; + + constructor(options: Web5Options) { + const { agent, connectedDid } = options; + this.agent = agent; + this.connectedDid = connectedDid; + this.did = new DidApi({ agent, connectedDid }); + this.dwn = new DwnApi({ agent, connectedDid }); + this.vc = new VcApi({ agent, connectedDid }); + } + + /** + * Connects to a {@link Web5Agent}. Defaults to creating a local {@link Web5UserAgent} + * if one isn't provided. + * + * @param options - optional overrides + * @returns + */ + static async connect(options: Web5ConnectOptions = {}) { + let { agent, appData, connectedDid, techPreview } = options; + + if (agent === undefined) { + // A custom Web5Agent implementation was not specified, so use default managed user agent. + const userAgent = await Web5UserAgent.create({ appData }); + agent = userAgent; + + // Start the agent. + await userAgent.start({ passphrase: 'insecure-static-phrase' }); + + // TODO: Replace stubbed connection attempt once Connect Protocol has been implemented. + // Attempt to Connect to localhost agent or via Connect Server. + // userAgent.connect(); + + const notConnected = true; + if (/* !userAgent.isConnected() */ notConnected) { + // Connect attempt failed or was rejected so fallback to local user agent. + + // Query the Agent's DWN tenant for identity records. + const identities = await userAgent.identityManager.list(); + + // If an existing identity is not found found, create a new one. + if (identities.length === 0) { + const serviceEndpointNodes = techPreview?.dwnEndpoints ?? await getTechPreviewDwnEndpoints(); + const didOptions = await DidIonMethod.generateDwnOptions({ serviceEndpointNodes }); + const identity = await userAgent.identityManager.create({ + name : 'Default', + didMethod : 'ion', + didOptions, + kms : 'local' + }); + connectedDid = identity.did; + } + } + } + + const web5 = new Web5({ agent, connectedDid }); + + return { web5, did: connectedDid }; + } +} \ No newline at end of file diff --git a/packages/web5/tests/chai-plugins.d.ts b/packages/api/tests/chai-plugins.d.ts similarity index 100% rename from packages/web5/tests/chai-plugins.d.ts rename to packages/api/tests/chai-plugins.d.ts diff --git a/packages/api/tests/did-api.spec.ts b/packages/api/tests/did-api.spec.ts new file mode 100644 index 000000000..292e4131e --- /dev/null +++ b/packages/api/tests/did-api.spec.ts @@ -0,0 +1,43 @@ +import { expect } from 'chai'; +import { TestManagedAgent } from '@web5/agent'; + +import { DidApi } from '../src/did-api.js'; +import { TestUserAgent } from './utils/test-user-agent.js'; + +describe('DidApi', () => { + let did: DidApi; + let testAgent: TestManagedAgent; + + before(async () => { + testAgent = await TestManagedAgent.create({ + agentClass : TestUserAgent, + agentStores : 'memory' + }); + }); + + beforeEach(async () => { + await testAgent.clearStorage(); + + // Create an Agent DID. + await testAgent.createAgentDid(); + + // Create a new Identity to author DWN messages. + const identity = await testAgent.agent.identityManager.create({ + name : 'Test', + didMethod : 'key', + kms : 'local' + }); + + // Instantiate DwnApi. + did = new DidApi({ agent: testAgent.agent, connectedDid: identity.did }); + }); + + after(async () => { + await testAgent.clearStorage(); + await testAgent.closeStorage(); + }); + + it('needs tests', () => { + expect(did).to.exist; + }); +}); \ No newline at end of file diff --git a/packages/api/tests/dwn-api.spec.ts b/packages/api/tests/dwn-api.spec.ts new file mode 100644 index 000000000..d9d5d718f --- /dev/null +++ b/packages/api/tests/dwn-api.spec.ts @@ -0,0 +1,564 @@ +import type { PortableDid } from '@web5/dids'; +import type { ManagedIdentity } from '@web5/agent'; + +import { expect } from 'chai'; +import { TestManagedAgent } from '@web5/agent'; + +import { DwnApi } from '../src/dwn-api.js'; +import { testDwnUrl } from './test-config.js'; +import { TestUserAgent } from './utils/test-user-agent.js'; +import emailProtocolDefinition from './fixtures/protocol-definitions/email.json' assert { type: 'json' }; + +let testDwnUrls: string[] = [testDwnUrl]; + +describe('DwnApi', () => { + let alice: ManagedIdentity; + let aliceDid: PortableDid; + let dwn: DwnApi; + let testAgent: TestManagedAgent; + + before(async () => { + testAgent = await TestManagedAgent.create({ + agentClass : TestUserAgent, + agentStores : 'memory' + }); + }); + + beforeEach(async () => { + await testAgent.clearStorage(); + + // Create an Agent DID. + await testAgent.createAgentDid(); + + // Create a new Identity to author the DWN messages. + ({ did: aliceDid } = await testAgent.createIdentity({ testDwnUrls })); + alice = await testAgent.agent.identityManager.import({ + did : aliceDid, + identity : { name: 'Alice', did: aliceDid.did }, + kms : 'local' + }); + + // Instantiate DwnApi. + dwn = new DwnApi({ agent: testAgent.agent, connectedDid: aliceDid.did }); + }); + + after(async () => { + await testAgent.clearStorage(); + await testAgent.closeStorage(); + }); + + describe('protocols.configure()', () => { + describe('agent', () => { + it('writes a protocol definition', async () => { + const response = await dwn.protocols.configure({ + message: { + definition: emailProtocolDefinition + } + }); + + expect(response.status.code).to.equal(202); + expect(response.status.detail).to.equal('Accepted'); + }); + }); + }); + + describe('protocols.query()', () => { + describe('agent', () => { + it('should return protocols matching the query', async () => { + // Write a protocols configure to the connected agent's DWN. + const configureResponse = await dwn.protocols.configure({ + message: { + definition: emailProtocolDefinition + } + }); + expect(configureResponse.status.code).to.equal(202); + expect(configureResponse.status.detail).to.equal('Accepted'); + + // Query for the protocol just configured. + const queryResponse = await dwn.protocols.query({ + message: { + filter: { + protocol: emailProtocolDefinition.protocol + } + } + }); + + expect(queryResponse.status.code).to.equal(200); + expect(queryResponse.protocols.length).to.equal(1); + expect(queryResponse.protocols[0].definition).to.have.property('types'); + expect(queryResponse.protocols[0].definition).to.have.property('protocol'); + expect(queryResponse.protocols[0].definition.protocol).to.equal(emailProtocolDefinition.protocol); + expect(queryResponse.protocols[0].definition).to.have.property('structure'); + }); + }); + + describe('from: did', () => { + it('should return protocols matching the query', async () => { + // Write a protocols configure to the connected agent's DWN. + const configureResponse = await dwn.protocols.configure({ + message: { + definition: emailProtocolDefinition + } + }); + expect(configureResponse.status.code).to.equal(202); + expect(configureResponse.status.detail).to.equal('Accepted'); + + // Write the protocol to the remote DWN. + await configureResponse.protocol.send(alice.did); + + // Query for the protocol just configured. + const queryResponse = await dwn.protocols.query({ + from : alice.did, + message : { + filter: { + protocol: emailProtocolDefinition.protocol + } + } + }); + + expect(queryResponse.status.code).to.equal(200); + expect(queryResponse.protocols.length).to.equal(1); + expect(queryResponse.protocols[0].definition).to.have.property('types'); + expect(queryResponse.protocols[0].definition).to.have.property('protocol'); + expect(queryResponse.protocols[0].definition.protocol).to.equal(emailProtocolDefinition.protocol); + expect(queryResponse.protocols[0].definition).to.have.property('structure'); + }); + + it('returns empty protocols array when no protocols match the filter provided', async () => { + // Query for a non-existent protocol. + const response = await dwn.protocols.query({ + from : alice.did, + message : { + filter: { + protocol: 'https://doesnotexist.com/protocol' + } + } + }); + + expect(response.status.code).to.equal(200); + expect(response.protocols).to.exist; + expect(response.protocols.length).to.equal(0); + }); + + it('returns a 401 when authorization fails', async () => { + /** Create a new DID to represent an external entity who has a remote + * DWN server defined in their DID document. */ + const { did: bob } = await testAgent.createIdentity({ testDwnUrls }); + + // Attempt to query for a protocol on Bob's DWN. + const response = await dwn.protocols.query({ + from : bob.did, + message : { + filter: { + protocol: 'https://doesnotexist.com/protocol' + } + } + }); + + /** Confirm that authorization failed because the test identity does not have + * permission to delete a record from Bob's DWN. */ + expect(response.status.code).to.equal(401); + expect(response.status.detail).to.include('ProtocolsQuery failed authorization'); + expect(response.protocols).to.exist; + expect(response.protocols.length).to.equal(0); + }); + }); + }); + + describe('records.create()', () => { + describe('agent', () => { + it('creates a record with string data', async () => { + const dataString = 'Hello, world!Hello, world!'; + const result = await dwn.records.create({ + data : dataString, + message : { + schema : 'foo/bar', + dataFormat : 'text/plain' + } + }); + + expect(result.status.code).to.equal(202); + expect(result.status.detail).to.equal('Accepted'); + expect(result.record).to.exist; + expect(await result.record?.data.text()).to.equal(dataString); + }); + + it('creates a record with JSON data', async () => { + const dataJson = { hello: 'world!'}; + const result = await dwn.records.create({ + data : dataJson, + message : { + schema : 'foo/bar', + dataFormat : 'application/json' + } + }); + + expect(result.status.code).to.equal(202); + expect(result.status.detail).to.equal('Accepted'); + expect(result.record).to.exist; + expect(await result.record?.data.json()).to.deep.equal(dataJson); + }); + }); + + describe('agent store: false', () => { + it('does not persist record to agent DWN', async () => { + const dataString = 'Hello, world!'; + const createResult = await dwn.records.create({ + store : false, + data : dataString, + message : { + schema : 'foo/bar', + dataFormat : 'text/plain' + } + }); + + expect(createResult.status.code).to.equal(202); + expect(createResult.status.detail).to.equal('Accepted'); + expect(createResult.record).to.exist; + expect(await createResult.record?.data.text()).to.equal(dataString); + + const queryResult = await dwn.records.query({ + message: { + filter: { + schema: 'foo/bar' + } + } + }); + + expect(queryResult.status.code).to.equal(200); + expect(queryResult.records).to.exist; + expect(queryResult.records!.length).to.equal(0); + }); + + it('has no effect if `store: true`', async () => { + const dataString = 'Hello, world!'; + const createResult = await dwn.records.create({ + store : true, + data : dataString, + message : { + schema : 'foo/bar', + dataFormat : 'text/plain' + } + }); + + expect(createResult.status.code).to.equal(202); + expect(createResult.status.detail).to.equal('Accepted'); + expect(createResult.record).to.exist; + expect(await createResult.record?.data.text()).to.equal(dataString); + + const queryResult = await dwn.records.query({ + message: { + filter: { + schema: 'foo/bar' + } + } + }); + + expect(queryResult.status.code).to.equal(200); + expect(queryResult.records).to.exist; + expect(queryResult.records!.length).to.equal(1); + expect(queryResult.records![0].id).to.equal(createResult.record!.id); + expect(await queryResult.records![0].data.text()).to.equal(dataString); + }); + }); + }); + + describe('records.createFrom()', () => { + describe('agent', () => { + it('creates a new record that inherits properties from an existing record', async () => { + // Create a record. + const { record: baseRecord } = await dwn.records.create({ + data : 'Hello, world!', + message : { + schema : 'foo/bar', + dataFormat : 'text/plain' + } + }); + + // Create a new record, inheriting properties from the first record. + const writeResponse = await dwn.records.createFrom({ + author : alice.did, + data : 'Foo bar!', + record : baseRecord + }); + + expect(writeResponse.status.code).to.equal(202); + expect(writeResponse.status.detail).to.equal('Accepted'); + expect(writeResponse.record).to.exist; + expect(await writeResponse.record?.data.text()).to.equal('Foo bar!'); + }); + }); + }); + + describe('records.delete()', () => { + describe('agent', () => { + it('deletes a record', async () => { + const { status: writeStatus, record } = await dwn.records.write({ + data : 'Hello, world!', + message : { + schema : 'foo/bar', + dataFormat : 'text/plain' + } + }); + + expect(writeStatus.code).to.equal(202); + expect(record).to.not.be.undefined; + + // Write the record to Alice's remote DWN. + const { status } = await record!.send(alice.did); + expect(status.code).to.equal(202); + + const deleteResult = await dwn.records.delete({ + message: { + recordId: record!.id + } + }); + + expect(deleteResult.status.code).to.equal(202); + }); + + it('returns a 404 when the specified record does not exist', async () => { + let deleteResult = await dwn.records.delete({ + message: { + recordId: 'abcd1234' + } + }); + expect(deleteResult.status.code).to.equal(404); + }); + }); + + describe('from: did', () => { + it('deletes a record', async () => { + const { status: writeStatus, record } = await dwn.records.write({ + data : 'Hello, world!', + message : { + schema : 'foo/bar', + dataFormat : 'text/plain' + } + }); + + expect(writeStatus.code).to.equal(202); + expect(record).to.not.be.undefined; + + // Write the record to the remote DWN. + const { status } = await record!.send(alice.did); + expect(status.code).to.equal(202); + + // Attempt to delete a record from the remote DWN. + const deleteResult = await dwn.records.delete({ + from : alice.did, + message : { + recordId: record.id + } + }); + + expect(deleteResult.status.code).to.equal(202); + expect(deleteResult.status.detail).to.equal('Accepted'); + }); + + it('returns a 401 when authentication or authorization fails', async () => { + /** Create a new DID to represent an external entity who has a remote + * DWN server defined in their DID document. */ + const { did: bob } = await testAgent.createIdentity({ testDwnUrls }); + + // Attempt to delete a record from Bob's DWN specifying a recordId that does not exist. + const deleteResult = await dwn.records.delete({ + from : bob.did, + message : { + recordId: 'abcd1234' + } + }); + + /** Confirm that authorization failed because the test identity does not have + * permission to delete a record from Bob's DWN. */ + expect(deleteResult.status.code).to.equal(401); + expect(deleteResult.status.detail).to.include('message failed authorization'); + }); + }); + }); + + describe('records.query()', () => { + describe('agent', () => { + it('returns an array of records that match the filter provided', async () => { + const writeResult = await dwn.records.write({ + data : 'Hello, world!', + message : { + schema : 'foo/bar', + dataFormat : 'text/plain' + } + }); + + expect(writeResult.status.code).to.equal(202); + expect(writeResult.status.detail).to.equal('Accepted'); + expect(writeResult.record).to.exist; + + const result = await dwn.records.query({ + message: { + filter: { + schema: 'foo/bar' + } + } + }); + + expect(result.status.code).to.equal(200); + expect(result.records).to.exist; + expect(result.records!.length).to.equal(1); + expect(result.records![0].id).to.equal(writeResult.record!.id); + }); + }); + + describe('from: did', () => { + it('returns an array of records that match the filter provided', async () => { + // Write a record to the agent's local DWN. + const { record } = await dwn.records.write({ + data : 'Hello, world!', + message : { + schema : 'foo/bar', + dataFormat : 'text/plain' + } + }); + + // Write the record to the agent's remote DWN. + await record.send(alice.did); + + // Query the agent's remote DWN. + const result = await dwn.records.query({ + from : alice.did, + message : { + filter: { + schema: 'foo/bar' + } + } + }); + + // Verify the query returns a result. + expect(result.status.code).to.equal(200); + expect(result.records).to.exist; + expect(result.records!.length).to.equal(1); + expect(result.records![0].id).to.equal(record!.id); + }); + + it('returns empty records array when no records match the filter provided', async () => { + /** Create a new DID to represent an external entity who has a remote + * DWN server defined in their DID document. */ + const { did: bob } = await testAgent.createIdentity({ testDwnUrls }); + + // Attempt to query Bob's DWN using the ID of a record that does not exist. + const result = await dwn.records.query({ + from : bob.did, + message : { + filter: { + recordId: 'abcd1234' + } + } + }); + + // Confirm that the record does not currently exist on Bob's DWN. + expect(result.status.code).to.equal(200); + expect(result.records).to.exist; + expect(result.records!.length).to.equal(0); + }); + }); + }); + + describe('records.read()', () => { + describe('agent', () => { + it('returns a record', async () => { + const writeResult = await dwn.records.write({ + data : 'Hello, world!', + message : { + schema : 'foo/bar', + dataFormat : 'text/plain' + } + }); + + expect(writeResult.status.code).to.equal(202); + expect(writeResult.status.detail).to.equal('Accepted'); + expect(writeResult.record).to.exist; + + const result = await dwn.records.read({ + message: { + recordId: writeResult.record!.id + } + }); + + expect(result.status.code).to.equal(200); + expect(result.record.id).to.equal(writeResult.record!.id); + }); + + it('returns a 404 when a record cannot be found', async () => { + const writeResult = await dwn.records.write({ + data : 'Hello, world!', + message : { + schema : 'foo/bar', + dataFormat : 'text/plain' + } + }); + + expect(writeResult.status.code).to.equal(202); + expect(writeResult.status.detail).to.equal('Accepted'); + expect(writeResult.record).to.exist; + + await writeResult.record!.delete(); + + const result = await dwn.records.read({ + message: { + recordId: writeResult.record!.id + } + }); + + expect(result.status.code).to.equal(404); + expect(result.record).to.not.exist; + }); + }); + + describe('from: did', () => { + it('returns a record', async () => { + // Write a record to the agent's local DWN. + const writeResult = await dwn.records.write({ + data : 'Hello, world!', + message : { + schema : 'foo/bar', + dataFormat : 'text/plain' + } + }); + + expect(writeResult.status.code).to.equal(202); + expect(writeResult.status.detail).to.equal('Accepted'); + expect(writeResult.record).to.exist; + + // Write the record to the agent's remote DWN. + await writeResult.record.send(alice.did); + + // Attempt to read the record from the agent's remote DWN. + const result = await dwn.records.read({ + from : alice.did, + message : { + recordId: writeResult.record!.id + } + }); + + expect(result.status.code).to.equal(200); + expect(result.record.id).to.equal(writeResult.record!.id); + }); + + it('returns undefined record when requested record does not exit', async () => { + /** Create a new DID to represent an external entity who has a remote + * DWN server defined in their DID document. */ + const { did: bob } = await testAgent.createIdentity({ testDwnUrls }); + + // Attempt to read a record from Bob's DWN using the ID of a record that only exists in the connected agent's DWN. + const result = await dwn.records.read({ + from : bob.did, + message : { + recordId: 'non-existent-id' + } + }); + + // Confirm that the record does not currently exist on Bob's DWN. + expect(result.status.code).to.equal(404); + expect(result.record).to.be.undefined; + }); + }); + }); +}); \ No newline at end of file diff --git a/packages/api/tests/fixtures/protocol-definitions/email.json b/packages/api/tests/fixtures/protocol-definitions/email.json new file mode 100644 index 000000000..1e23bf5d2 --- /dev/null +++ b/packages/api/tests/fixtures/protocol-definitions/email.json @@ -0,0 +1,48 @@ +{ + "protocol": "http://email-protocol.xyz", + "published": false, + "types": { + "email": { + "schema": "http://email-protocol.xyz/schema/email", + "dataFormats": ["text/plain"] + } + }, + "structure": { + "email": { + "$actions": [ + { + "who": "anyone", + "can": "write" + }, + { + "who": "author", + "of": "email", + "can": "read" + }, + { + "who": "recipient", + "of": "email", + "can": "read" + } + ], + "email": { + "$actions": [ + { + "who": "anyone", + "can": "write" + }, + { + "who": "author", + "of": "email/email", + "can": "read" + }, + { + "who": "recipient", + "of": "email/email", + "can": "read" + } + ] + } + } + } +} diff --git a/packages/api/tests/record.spec.ts b/packages/api/tests/record.spec.ts new file mode 100644 index 000000000..bfb4aac6f --- /dev/null +++ b/packages/api/tests/record.spec.ts @@ -0,0 +1,1033 @@ +import type { PortableDid } from '@web5/dids'; +import type { ManagedIdentity } from '@web5/agent'; +import type { + RecordsWriteMessage, + PublicJwk as DwnPublicKeyJwk, + PrivateJwk as DwnPrivateKeyJwk, + EncryptionInput, +} from '@tbd54566975/dwn-sdk-js'; + +import chai, { expect } from 'chai'; +import chaiAsPromised from 'chai-as-promised'; +import * as didUtils from '@web5/dids/utils'; +import { TestManagedAgent } from '@web5/agent'; +import { + RecordsWrite, + DwnMethodName, + DwnInterfaceName, + EncryptionAlgorithm, + KeyDerivationScheme, +} from '@tbd54566975/dwn-sdk-js'; + +import { Record } from '../src/record.js'; +import { DwnApi } from '../src/dwn-api.js'; +import { dataToBlob } from '../src/utils.js'; +import { testDwnUrl } from './test-config.js'; +import { TestUserAgent } from './utils/test-user-agent.js'; +import { TestDataGenerator } from './utils/test-data-generator.js'; +import emailProtocolDefinition from './fixtures/protocol-definitions/email.json' assert { type: 'json' }; + +chai.use(chaiAsPromised); + +// NOTE: @noble/secp256k1 requires globalThis.crypto polyfill for node.js <=18: https://github.com/paulmillr/noble-secp256k1/blob/main/README.md#usage +// Remove when we move off of node.js v18 to v20, earliest possible time would be Oct 2023: https://github.com/nodejs/release#release-schedule +// NOTE: @noble/secp256k1 requires globalThis.crypto polyfill for node.js <=18: https://github.com/paulmillr/noble-secp256k1/blob/main/README.md#usage +// Remove when we move off of node.js v18 to v20, earliest possible time would be Oct 2023: https://github.com/nodejs/release#release-schedule +import { webcrypto } from 'node:crypto'; +// @ts-ignore +if (!globalThis.crypto) globalThis.crypto = webcrypto; + +// TODO: Come up with a better way of resolving the TS errors. +type RecordsWriteTest = RecordsWrite & RecordsWriteMessage; + +let testDwnUrls: string[] = [testDwnUrl]; + +describe('Record', () => { + let dataText: string; + let dataBlob: Blob; + let dataFormat: string; + let dwn: DwnApi; + let alice: ManagedIdentity; + let aliceDid: PortableDid; + let testAgent: TestManagedAgent; + + before(async () => { + testAgent = await TestManagedAgent.create({ + agentClass : TestUserAgent, + agentStores : 'memory' + }); + + dataText = TestDataGenerator.randomString(100); + ({ dataBlob, dataFormat } = dataToBlob(dataText)); + }); + + beforeEach(async () => { + await testAgent.clearStorage(); + + // Create an Agent DID. + await testAgent.createAgentDid(); + + // Create a new Identity to author the DWN messages. + ({ did: aliceDid } = await testAgent.createIdentity({ testDwnUrls })); + alice = await testAgent.agent.identityManager.import({ + did : aliceDid, + identity : { name: 'Alice', did: aliceDid.did }, + kms : 'local' + }); + + // Instantiate DwnApi. + dwn = new DwnApi({ agent: testAgent.agent, connectedDid: alice.did }); + }); + + after(async () => { + await testAgent.clearStorage(); + await testAgent.closeStorage(); + }); + + it('should retain all defined properties', async () => { + // RecordOptions properties + const author = alice.did; + const target = alice.did; + + // Retrieve `#dwn` service entry. + const [ didDwnService ] = didUtils.getServices({ didDocument: aliceDid.document, id: '#dwn' }); + + // Retrieve first message signing key from the #dwn service endpoint. + if (!didUtils.isDwnServiceEndpoint(didDwnService.serviceEndpoint)) throw Error('Type guard'); + const [ signingKeyIdFragment ] = didDwnService!.serviceEndpoint!.signingKeys; + const [ encryptionKeyIdFragment ] = didDwnService!.serviceEndpoint!.encryptionKeys; + + const signingKeyId = `${alice.did}${signingKeyIdFragment}`; + const signingKeyPair = aliceDid.keySet.verificationMethodKeys!.find(keyPair => keyPair.publicKeyJwk.kid === signingKeyIdFragment); + const signingPrivateKeyJwk = signingKeyPair.privateKeyJwk; + + const encryptionKeyId = `${alice.did}${encryptionKeyIdFragment}`; + const encryptionPublicKeyJwk = aliceDid.keySet.verificationMethodKeys!.find(keyPair => keyPair.publicKeyJwk.kid === encryptionKeyIdFragment)!.publicKeyJwk; + + // RecordsWriteMessage properties that can be pre-defined + const attestation = [{ + privateJwk : signingPrivateKeyJwk as DwnPrivateKeyJwk, + protectedHeader : { + alg : signingPrivateKeyJwk.alg as string, + kid : signingKeyId + } + }]; + + const authorization = { + privateJwk : signingPrivateKeyJwk as DwnPrivateKeyJwk, + protectedHeader : { + alg : signingPrivateKeyJwk.alg as string, + kid : signingKeyId + } + }; + + const encryptionInput: EncryptionInput = { + algorithm : EncryptionAlgorithm.Aes256Ctr, + initializationVector : TestDataGenerator.randomBytes(16), + key : TestDataGenerator.randomBytes(32), + keyEncryptionInputs : [{ + algorithm : EncryptionAlgorithm.EciesSecp256k1, + derivationScheme : KeyDerivationScheme.ProtocolPath, + publicKey : encryptionPublicKeyJwk as DwnPublicKeyJwk, + publicKeyId : encryptionKeyId + }] + }; + + // RecordsWriteDescriptor properties that can be pre-defined + const protocol = emailProtocolDefinition.protocol; + const protocolPath = 'email'; + const schema = emailProtocolDefinition.types.email.schema; + const recipient = alice.did; + const published = true; + + // Install a protocol on Alice's agent connected DWN. + await dwn.protocols.configure({ + message: { + definition: emailProtocolDefinition + } + }); + + // Create a parent record to reference in the RecordsWriteMessage used for validation + const parentRecorsWrite = await RecordsWrite.create({ + authorizationSignatureInput : authorization, + data : new Uint8Array(await dataBlob.arrayBuffer()), + dataFormat, + protocol, + protocolPath, + schema, + }) as RecordsWriteTest; + + // Create a RecordsWriteMessage + const recordsWrite = await RecordsWrite.create({ + attestationSignatureInputs : attestation, + authorizationSignatureInput : authorization, + data : new Uint8Array(await dataBlob.arrayBuffer()), + dataFormat, + encryptionInput, + parentId : parentRecorsWrite.recordId, + protocol, + protocolPath, + published, + recipient, + schema, + }) as RecordsWriteTest; + + // Create record using test RecordsWriteMessage. + const record = new Record(testAgent.agent, { + ...recordsWrite.message, + encodedData: dataBlob, + target, + author, + }); + + // Retained Record properties + expect(record.author).to.equal(author); + expect(record.target).to.equal(target); + + // Retained RecordsWriteMessage top-level properties + expect(record.contextId).to.equal(recordsWrite.message.contextId); + expect(record.id).to.equal(recordsWrite.message.recordId); + expect(record.encryption).to.not.be.undefined; + expect(record.encryption).to.deep.equal(recordsWrite.message.encryption); + expect(record.encryption!.keyEncryption.find(key => key.derivationScheme === KeyDerivationScheme.ProtocolPath)); + expect(record.attestation).to.not.be.undefined; + expect(record.attestation).to.have.property('signatures'); + + // Retained RecordsWriteDescriptor properties + expect(record.protocol).to.equal(protocol); + expect(record.protocolPath).to.equal(protocolPath); + expect(record.recipient).to.equal(recipient); + expect(record.schema).to.equal(schema); + expect(record.parentId).to.equal(parentRecorsWrite.recordId); + expect(record.dataCid).to.equal(recordsWrite.message.descriptor.dataCid); + expect(record.dataSize).to.equal(recordsWrite.message.descriptor.dataSize); + expect(record.dateCreated).to.equal(recordsWrite.message.descriptor.dateCreated); + expect(record.dateModified).to.equal(recordsWrite.message.descriptor.messageTimestamp); + expect(record.published).to.equal(published); + expect(record.datePublished).to.equal(recordsWrite.message.descriptor.datePublished); + expect(record.dataFormat).to.equal(dataFormat); + }); + + describe('data.blob()', () => { + it('returns small data payloads after dwn.records.write()', async () => { + // Generate data that is less than the encoded data limit to ensure that the data will not have to be fetched + // with a RecordsRead when record.data.blob() is executed. + const dataJson = TestDataGenerator.randomJson(500); + const inputDataBytes = new TextEncoder().encode(JSON.stringify(dataJson)); + + // Write the 500B record to agent-connected DWN. + const { record, status } = await dwn.records.write({ data: dataJson }); + + expect(status.code).to.equal(202); + + // Confirm that the size, in bytes, of the data read as a Blob matches the original input data. + const readDataBlob = await record!.data.blob(); + expect(readDataBlob.size).to.equal(inputDataBytes.length); + + // Convert the Blob into an array and ensure it matches the input data byte for byte. + const readDataBytes = new Uint8Array(await readDataBlob.arrayBuffer()); + expect(readDataBytes).to.deep.equal(inputDataBytes); + }); + + it('returns small data payloads after dwn.records.read()', async () => { + // Generate data that is less than the encoded data limit to ensure that the data will not have to be fetched + // with a RecordsRead when record.data.blob() is executed. + const dataJson = TestDataGenerator.randomJson(500); + const inputDataBytes = new TextEncoder().encode(JSON.stringify(dataJson)); + + // Write the 500B record to agent-connected DWN. + const { record, status } = await dwn.records.write({ data: dataJson }); + + expect(status.code).to.equal(202); + + // Read the record that was just created. + const { record: readRecord, status: readRecordStatus } = await dwn.records.read({ message: { recordId: record!.id }}); + + expect(readRecordStatus.code).to.equal(200); + + // Confirm that the size, in bytes, of the data read as a Blob matches the original input data. + const readDataBlob = await readRecord.data.blob(); + expect(readDataBlob.size).to.equal(inputDataBytes.length); + + // Convert the Blob into an array and ensure it matches the input data byte for byte. + const readDataBytes = new Uint8Array(await readDataBlob.arrayBuffer()); + expect(readDataBytes).to.deep.equal(inputDataBytes); + }); + + it('returns large data payloads after dwn.records.write()', async () => { + // Generate data that exceeds the DWN encoded data limit to ensure that the data will have to be fetched + // with a RecordsRead when record.data.blob() is executed. + const dataJson = TestDataGenerator.randomJson(11_000); + const inputDataBytes = new TextEncoder().encode(JSON.stringify(dataJson)); + + // Write the 11KB record to agent-connected DWN. + const { record, status } = await dwn.records.write({ data: dataJson }); + + expect(status.code).to.equal(202); + + // Confirm that the size, in bytes, of the data read as a Blob matches the original input data. + const readDataBlob = await record!.data.blob(); + expect(readDataBlob.size).to.equal(inputDataBytes.length); + + // Convert the Blob into an array and ensure it matches the input data byte for byte. + const readDataBytes = new Uint8Array(await readDataBlob.arrayBuffer()); + expect(readDataBytes).to.deep.equal(inputDataBytes); + }); + + it('returns large data payloads after dwn.records.read()', async () => { + // Generate data that exceeds the DWN encoded data limit to ensure that the data will have to be fetched + // with a RecordsRead when record.data.blob() is executed. + const dataJson = TestDataGenerator.randomJson(11_000); + const inputDataBytes = new TextEncoder().encode(JSON.stringify(dataJson)); + + // Write the 11KB record to agent-connected DWN. + const { record, status } = await dwn.records.write({ data: dataJson }); + + expect(status.code).to.equal(202); + + // Read the record that was just created. + const { record: readRecord, status: readRecordStatus } = await dwn.records.read({ message: { recordId: record!.id }}); + + expect(readRecordStatus.code).to.equal(200); + + // Confirm that the size, in bytes, of the data read as a Blob matches the original input data. + const readDataBlob = await readRecord.data.blob(); + expect(readDataBlob.size).to.equal(inputDataBytes.length); + + // Convert the Blob into an array and ensure it matches the input data byte for byte. + const readDataBytes = new Uint8Array(await readDataBlob.arrayBuffer()); + expect(readDataBytes).to.deep.equal(inputDataBytes); + }); + }); + + describe('data.json()', () => { + it('returns small data payloads after dwn.records.write()', async () => { + // Generate data that is less than the encoded data limit to ensure that the data will not have to be fetched + // with a RecordsRead when record.data.json() is executed. + const dataJson = TestDataGenerator.randomJson(500); + const inputDataBytes = new TextEncoder().encode(JSON.stringify(dataJson)); + + // Write the 500B record to agent-connected DWN. + const { record, status } = await dwn.records.write({ data: dataJson }); + + expect(status.code).to.equal(202); + + // Confirm that the size, in bytes, of the data read as JSON matches the original input data. + const readDataJson = await record!.data.json(); + const readDataBytes = new TextEncoder().encode(JSON.stringify(readDataJson)); + expect(readDataBytes.length).to.equal(inputDataBytes.length); + + // Ensure the JSON returned matches the input data, byte for byte. + expect(readDataBytes).to.deep.equal(inputDataBytes); + }); + + it('returns small data payloads after dwn.records.read()', async () => { + // Generate data that is less than the encoded data limit to ensure that the data will not have to be fetched + // with a RecordsRead when record.data.json() is executed. + const dataJson = TestDataGenerator.randomJson(500); + const inputDataBytes = new TextEncoder().encode(JSON.stringify(dataJson)); + + // Write the 500B record to agent-connected DWN. + const { record, status } = await dwn.records.write({ data: dataJson }); + + expect(status.code).to.equal(202); + + // Read the record that was just created. + const { record: readRecord, status: readRecordStatus } = await dwn.records.read({ message: { recordId: record!.id }}); + + expect(readRecordStatus.code).to.equal(200); + + // Confirm that the size, in bytes, of the data read as JSON matches the original input data. + const readDataJson = await readRecord!.data.json(); + const readDataBytes = new TextEncoder().encode(JSON.stringify(readDataJson)); + expect(readDataBytes.length).to.equal(inputDataBytes.length); + + // Ensure the JSON returned matches the input data, byte for byte. + expect(readDataBytes).to.deep.equal(inputDataBytes); + }); + + it('returns large data payloads after dwn.records.write()', async () => { + // Generate data that exceeds the DWN encoded data limit to ensure that the data will have to be fetched + // with a RecordsRead when record.data.json() is executed. + const dataJson = TestDataGenerator.randomJson(11_000); + const inputDataBytes = new TextEncoder().encode(JSON.stringify(dataJson)); + + // Write the 11KB record to agent-connected DWN. + const { record, status } = await dwn.records.write({ data: dataJson }); + + expect(status.code).to.equal(202); + + // Confirm that the size, in bytes, of the data read as JSON matches the original input data. + const readDataJson = await record!.data.json(); + const readDataBytes = new TextEncoder().encode(JSON.stringify(readDataJson)); + expect(readDataBytes.length).to.equal(inputDataBytes.length); + + // Ensure the JSON returned matches the input data, byte for byte. + expect(readDataBytes).to.deep.equal(inputDataBytes); + }); + + it('returns large data payloads after dwn.records.read()', async () => { + // Generate data that exceeds the DWN encoded data limit to ensure that the data will have to be fetched + // with a RecordsRead when record.data.json() is executed. + const dataJson = TestDataGenerator.randomJson(11_000); + const inputDataBytes = new TextEncoder().encode(JSON.stringify(dataJson)); + + // Write the 11KB record to agent-connected DWN. + const { record, status } = await dwn.records.write({ data: dataJson }); + + expect(status.code).to.equal(202); + + // Read the record that was just created. + const { record: readRecord, status: readRecordStatus } = await dwn.records.read({ message: { recordId: record!.id }}); + + expect(readRecordStatus.code).to.equal(200); + + // Confirm that the size, in bytes, of the data read as JSON matches the original input data. + const readDataJson = await readRecord!.data.json(); + const readDataBytes = new TextEncoder().encode(JSON.stringify(readDataJson)); + expect(readDataBytes.length).to.equal(inputDataBytes.length); + + // Ensure the JSON returned matches the input data, byte for byte. + expect(readDataBytes).to.deep.equal(inputDataBytes); + }); + }); + + describe('data.text()', () => { + it('returns small data payloads after dwn.records.write()', async () => { + // Generate data that is less than the encoded data limit to ensure that the data will not have to be fetched + // with a RecordsRead when record.data.text() is executed. + const dataText = TestDataGenerator.randomString(500); + + // Write the 500B record to agent-connected DWN. + const { record, status } = await dwn.records.write({ data: dataText }); + + expect(status.code).to.equal(202); + + // Confirm that the length of the data read as text matches the original input data. + const readDataText = await record!.data.text(); + expect(readDataText.length).to.equal(dataText.length); + + // Ensure the text returned matches the input data, char for char. + expect(readDataText).to.deep.equal(dataText); + }); + + it('returns small data payloads after dwn.records.read()', async () => { + // Generate data that is less than the encoded data limit to ensure that the data will not have to be fetched + // with a RecordsRead when record.data.text() is executed. + const dataText = TestDataGenerator.randomString(500); + + // Write the 500B record to agent-connected DWN. + const { record, status } = await dwn.records.write({ data: dataText }); + + expect(status.code).to.equal(202); + + // Read the record that was just created. + const { record: readRecord, status: readRecordStatus } = await dwn.records.read({ message: { recordId: record!.id }}); + + expect(readRecordStatus.code).to.equal(200); + + // Confirm that the length of the data read as text matches the original input data. + const readDataText = await readRecord!.data.text(); + expect(readDataText.length).to.equal(dataText.length); + + // Ensure the text returned matches the input data, char for char. + expect(readDataText).to.deep.equal(dataText); + }); + + it('returns large data payloads after dwn.records.write()', async () => { + // Generate data that exceeds the DWN encoded data limit to ensure that the data will have to be fetched + // with a RecordsRead when record.data.text() is executed. + const dataText = TestDataGenerator.randomString(11_000); + + // Write the 11KB record to agent-connected DWN. + const { record, status } = await dwn.records.write({ data: dataText }); + + expect(status.code).to.equal(202); + + // Confirm that the length of the data read as text matches the original input data. + const readDataText = await record!.data.text(); + expect(readDataText.length).to.equal(dataText.length); + + // Ensure the text returned matches the input data, char for char. + expect(readDataText).to.deep.equal(dataText); + }); + + it('returns large data payloads after dwn.records.read()', async () => { + // Generate data that exceeds the DWN encoded data limit to ensure that the data will have to be fetched + // with a RecordsRead when record.data.text() is executed. + const dataText = TestDataGenerator.randomString(11_000); + + // Write the 11KB record to agent-connected DWN. + const { record, status } = await dwn.records.write({ data: dataText }); + + expect(status.code).to.equal(202); + + // Read the record that was just created. + const { record: readRecord, status: readRecordStatus } = await dwn.records.read({ message: { recordId: record!.id }}); + + expect(readRecordStatus.code).to.equal(200); + + // Confirm that the length of the data read as text matches the original input data. + const readDataText = await readRecord!.data.text(); + expect(readDataText.length).to.equal(dataText.length); + + // Ensure the text returned matches the input data, char for char. + expect(readDataText).to.deep.equal(dataText); + }); + }); + + describe('delete()', () => { + it('deletes the record', async () => { + const { status, record } = await dwn.records.write({ + data : 'Hello, world!', + message : { + schema : 'foo/bar', + dataFormat : 'text/plain' + } + }); + + expect(status.code).to.equal(202); + expect(record).to.not.be.undefined; + + const deleteResult = await record!.delete(); + expect(deleteResult.status.code).to.equal(202); + + const queryResult = await dwn.records.query({ + message: { + filter: { + recordId: record!.id + } + } + }); + + expect(queryResult.status.code).to.equal(200); + expect(queryResult.records!.length).to.equal(0); + }); + + it('throws an exception when delete is called twice', async () => { + const { status, record } = await dwn.records.write({ + data : 'Hello, world!', + message : { + schema : 'foo/bar', + dataFormat : 'text/plain' + } + }); + + expect(status.code).to.equal(202); + expect(record).to.not.be.undefined; + + let deleteResult = await record!.delete(); + expect(deleteResult.status.code).to.equal(202); + + await expect(record!.delete()).to.eventually.be.rejectedWith('Operation failed'); + }); + }); + + describe('send()', () => { + let bob: ManagedIdentity; + + beforeEach(async () => { + // Create a new Identity to author the DWN messages. + const { did: bobDid } = await testAgent.createIdentity({ testDwnUrls }); + bob = await testAgent.agent.identityManager.import({ + did : bobDid, + identity : { name: 'Bob', did: bobDid.did }, + kms : 'local' + }); + }); + + it('writes records to remote DWNs for your own DID', async () => { + const dataString = 'Hello, world!'; + + // Alice writes a message to her agent connected DWN. + const { status: aliceEmailStatus, record: aliceEmailRecord } = await dwn.records.write({ + data : dataString, + message : { + schema: 'email', + } + }); + + expect(aliceEmailStatus.code).to.equal(202); + expect(await aliceEmailRecord?.data.text()).to.equal(dataString); + + // Query Alice's agent connected DWN for `email` schema records. + const aliceAgentQueryResult = await dwn.records.query({ + message: { + filter: { + schema: 'email' + } + } + }); + + expect(aliceAgentQueryResult.status.code).to.equal(200); + expect(aliceAgentQueryResult!.records).to.have.length(1); + const [ aliceAgentEmailRecord ] = aliceAgentQueryResult!.records!; + expect(await aliceAgentEmailRecord.data.text()).to.equal(dataString); + + // Attempt to write the record to Alice's remote DWN. + const { status } = await aliceEmailRecord!.send(alice.did); + expect(status.code).to.equal(202); + + // Query Alices's remote DWN for `email` schema records. + const aliceRemoteQueryResult = await dwn.records.query({ + from : alice.did, + message : { + filter: { + schema: 'email' + } + } + }); + + expect(aliceRemoteQueryResult.status.code).to.equal(200); + expect(aliceRemoteQueryResult.records).to.exist; + expect(aliceRemoteQueryResult.records!.length).to.equal(1); + const [ aliceRemoteEmailRecord ] = aliceAgentQueryResult!.records!; + expect(await aliceRemoteEmailRecord.data.text()).to.equal(dataString); + }); + + it(`writes records to remote DWNs for someone else's DID`, async () => { + const dataString = 'Hello, world!'; + + // Install the email protocol for Alice's local DWN. + let { protocol: aliceProtocol, status: aliceStatus } = await dwn.protocols.configure({ + message: { + definition: emailProtocolDefinition + } + }); + + expect(aliceStatus.code).to.equal(202); + expect(aliceProtocol).to.exist; + + // Install the email protocol for Alice's remote DWN. + const { status: alicePushStatus } = await aliceProtocol!.send(alice.did); + expect(alicePushStatus.code).to.equal(202); + + // Instantiate DwnApi instance for Bob. + const bobDwn = new DwnApi({ agent: testAgent.agent, connectedDid: bob.did }); + + // Install the email protocol for Bob's local DWN. + const { protocol: bobProtocol, status: bobStatus } = await bobDwn.protocols.configure({ + message: { + definition: emailProtocolDefinition + } + }); + + expect(bobStatus.code).to.equal(202); + expect(bobProtocol).to.exist; + + // Install the email protocol for Bob's remote DWN. + const { status: bobPushStatus } = await bobProtocol!.send(bob.did); + expect(bobPushStatus.code).to.equal(202); + + // Alice writes a message to her own DWN. + const { status: aliceEmailStatus, record: aliceEmailRecord } = await dwn.records.write({ + data : dataString, + message : { + protocol : emailProtocolDefinition.protocol, + protocolPath : 'email', + schema : 'http://email-protocol.xyz/schema/email', + } + }); + + expect(aliceEmailStatus.code).to.equal(202); + + // Attempt to write the message to Bob's DWN. + const { status } = await aliceEmailRecord!.send(bob.did); + expect(status.code).to.equal(202); + + // Query Bob's remote DWN for `email` schema records. + const bobQueryResult = await bobDwn.records.query({ + from : bob.did, + message : { + filter: { + schema: 'http://email-protocol.xyz/schema/email' + } + } + }); + + expect(bobQueryResult.status.code).to.equal(200); + expect(bobQueryResult.records).to.exist; + expect(bobQueryResult.records!.length).to.equal(1); + const [ bobRemoteEmailRecord ] = bobQueryResult!.records!; + expect(await bobRemoteEmailRecord.data.text()).to.equal(dataString); + }); + + describe('with store: false', () => { + it('writes records to your own remote DWN but not your agent DWN', async () => { + // Alice writes a message to her agent DWN with `store: false`. + const dataString = 'Hello, world!'; + const writeResult = await dwn.records.write({ + store : false, + data : dataString, + message : { + dataFormat: 'text/plain' + } + }); + + // Confirm that the request was accepted and a Record instance was returned. + expect(writeResult.status.code).to.equal(202); + expect(writeResult.status.detail).to.equal('Accepted'); + expect(writeResult.record).to.exist; + expect(await writeResult.record?.data.text()).to.equal(dataString); + + // Query Alice's agent DWN for `text/plain` records. + const queryResult = await dwn.records.query({ + message: { + filter: { + dataFormat: 'text/plain' + } + } + }); + + // Confirm no `email` schema records were written. + expect(queryResult.status.code).to.equal(200); + expect(queryResult.records).to.exist; + expect(queryResult.records!.length).to.equal(0); + + // Alice writes the message to her remote DWN. + const { status } = await writeResult.record!.send(alice.did); + expect(status.code).to.equal(202); + + // Query Alice's remote DWN for `plain/text` records. + const aliceRemoteQueryResult = await dwn.records.query({ + from : alice.did, + message : { + filter: { + dataFormat: 'text/plain' + } + } + }); + + // Confirm `email` schema record was written to Alice's remote DWN. + expect(aliceRemoteQueryResult.status.code).to.equal(200); + expect(aliceRemoteQueryResult.records).to.exist; + expect(aliceRemoteQueryResult.records!.length).to.equal(1); + const [ aliceRemoteEmailRecord ] = aliceRemoteQueryResult!.records!; + expect(await aliceRemoteEmailRecord.data.text()).to.equal(dataString); + }); + + it(`writes records to someone else's remote DWN but not your agent DWN`, async () => { + // Install a protocol on Alice's agent connected DWN. + let { protocol: aliceProtocol, status: aliceStatus } = await dwn.protocols.configure({ + message: { + definition: emailProtocolDefinition + } + }); + + expect(aliceStatus.code).to.equal(202); + expect(aliceProtocol).to.exist; + + // Install the protocol on Alice's remote DWN. + const { status: alicePushStatus } = await aliceProtocol!.send(alice.did); + expect(alicePushStatus.code).to.equal(202); + + // Instantiate DwnApi instance for Bob. + const bobDwn = new DwnApi({ agent: testAgent.agent, connectedDid: bob.did }); + + // Install the email protocol for Bob's local DWN. + const { protocol: bobProtocol, status: bobStatus } = await bobDwn.protocols.configure({ + message: { + definition: emailProtocolDefinition + } + }); + + expect(bobStatus.code).to.equal(202); + expect(bobProtocol).to.exist; + + // Install the email protocol for Bob's remote DWN. + const { status: bobPushStatus } = await bobProtocol!.send(bob.did); + expect(bobPushStatus.code).to.equal(202); + + // Alice writes a message to her agent DWN with `store: false`. + const dataString = 'Hello, world!'; + const writeResult = await dwn.records.write({ + store : false, + data : dataString, + message : { + protocol : emailProtocolDefinition.protocol, + protocolPath : 'email', + schema : 'http://email-protocol.xyz/schema/email', + } + }); + + // Confirm that the request was accepted and a Record instance was returned. + expect(writeResult.status.code).to.equal(202); + expect(writeResult.status.detail).to.equal('Accepted'); + expect(writeResult.record).to.exist; + expect(await writeResult.record?.data.text()).to.equal(dataString); + + // Query Alice's agent DWN for `email` schema records. + const queryResult = await dwn.records.query({ + message: { + filter: { + schema: 'http://email-protocol.xyz/schema/email' + } + } + }); + + // Confirm no `email` schema records were written. + expect(queryResult.status.code).to.equal(200); + expect(queryResult.records).to.exist; + expect(queryResult.records!.length).to.equal(0); + + // Alice writes the message to Bob's remote DWN. + const { status } = await writeResult.record!.send(bob.did); + expect(status.code).to.equal(202); + + // Query Bobs's remote DWN for `email` schema records. + const bobQueryResult = await bobDwn.records.query({ + from : bob.did, + message : { + filter: { + dataFormat: 'text/plain' + } + } + }); + + // Confirm `email` schema record was written to Bob's remote DWN. + expect(bobQueryResult.status.code).to.equal(200); + expect(bobQueryResult.records).to.exist; + expect(bobQueryResult.records!.length).to.equal(1); + const [ bobRemoteEmailRecord ] = bobQueryResult!.records!; + expect(await bobRemoteEmailRecord.data.text()).to.equal(dataString); + }); + + it('has no effect if `store: true`', async () => { + // Alice writes a message to her agent DWN with `store: true`. + const dataString = 'Hello, world!'; + const writeResult = await dwn.records.write({ + store : true, + data : dataString, + message : { + dataFormat: 'text/plain' + } + }); + + // Confirm that the request was accepted and a Record instance was returned. + expect(writeResult.status.code).to.equal(202); + expect(writeResult.status.detail).to.equal('Accepted'); + expect(writeResult.record).to.exist; + expect(await writeResult.record?.data.text()).to.equal(dataString); + + // Query Alice's agent DWN for `text/plain` records. + const queryResult = await dwn.records.query({ + message: { + filter: { + dataFormat: 'text/plain' + } + } + }); + + // Confirm the `email` schema records was written. + expect(queryResult.status.code).to.equal(200); + expect(queryResult.records).to.exist; + expect(queryResult.records!.length).to.equal(1); + const [ aliceAgentRecord ] = queryResult!.records!; + expect(await aliceAgentRecord.data.text()).to.equal(dataString); + + // Alice writes the message to her remote DWN. + const { status } = await writeResult.record!.send(alice.did); + expect(status.code).to.equal(202); + + // Query Alice's remote DWN for `plain/text` records. + const aliceRemoteQueryResult = await dwn.records.query({ + from : alice.did, + message : { + filter: { + dataFormat: 'text/plain' + } + } + }); + + // Confirm `email` schema record was written to Alice's remote DWN. + expect(aliceRemoteQueryResult.status.code).to.equal(200); + expect(aliceRemoteQueryResult.records).to.exist; + expect(aliceRemoteQueryResult.records!.length).to.equal(1); + const [ aliceRemoteEmailRecord ] = aliceRemoteQueryResult!.records!; + expect(await aliceRemoteEmailRecord.data.text()).to.equal(dataString); + }); + }); + }); + + describe('toJSON()', () => { + it('should return all defined properties', async () => { + // RecordOptions properties + const author = alice.did; + const target = alice.did; + + // Retrieve `#dwn` service entry. + const [ didDwnService ] = didUtils.getServices({ didDocument: aliceDid.document, id: '#dwn' }); + + // Retrieve first message signing key from the #dwn service endpoint. + if (!didUtils.isDwnServiceEndpoint(didDwnService.serviceEndpoint)) throw Error('Type guard'); + const [ signingKeyIdFragment ] = didDwnService!.serviceEndpoint!.signingKeys; + const [ encryptionKeyIdFragment ] = didDwnService!.serviceEndpoint!.encryptionKeys; + + const signingKeyId = `${alice.did}${signingKeyIdFragment}`; + const signingKeyPair = aliceDid.keySet.verificationMethodKeys!.find(keyPair => keyPair.publicKeyJwk.kid === signingKeyIdFragment); + const signingPrivateKeyJwk = signingKeyPair.privateKeyJwk; + + const encryptionKeyId = `${alice.did}${encryptionKeyIdFragment}`; + const encryptionPublicKeyJwk = aliceDid.keySet.verificationMethodKeys!.find(keyPair => keyPair.publicKeyJwk.kid === encryptionKeyIdFragment)!.publicKeyJwk; + + // RecordsWriteMessage properties that can be pre-defined + const attestation = [{ + privateJwk : signingPrivateKeyJwk as DwnPrivateKeyJwk, + protectedHeader : { + alg : signingPrivateKeyJwk.alg as string, + kid : signingKeyId + } + }]; + + const authorization = { + privateJwk : signingPrivateKeyJwk as DwnPrivateKeyJwk, + protectedHeader : { + alg : signingPrivateKeyJwk.alg as string, + kid : signingKeyId + } + }; + + const encryptionInput: EncryptionInput = { + algorithm : EncryptionAlgorithm.Aes256Ctr, + initializationVector : TestDataGenerator.randomBytes(16), + key : TestDataGenerator.randomBytes(32), + keyEncryptionInputs : [{ + algorithm : EncryptionAlgorithm.EciesSecp256k1, + derivationScheme : KeyDerivationScheme.ProtocolPath, + publicKey : encryptionPublicKeyJwk as DwnPublicKeyJwk, + publicKeyId : encryptionKeyId + }] + }; + + // RecordsWriteDescriptor properties that can be pre-defined + const protocol = emailProtocolDefinition.protocol; + const protocolPath = 'email'; + const schema = emailProtocolDefinition.types.email.schema; + const recipient = alice.did; + const published = true; + + // Install a protocol on Alice's agent connected DWN. + await dwn.protocols.configure({ + message: { + definition: emailProtocolDefinition + } + }); + + // Create a parent record to reference in the RecordsWriteMessage used for validation + const parentRecorsWrite = await RecordsWrite.create({ + authorizationSignatureInput : authorization, + data : new Uint8Array(await dataBlob.arrayBuffer()), + dataFormat, + protocol, + protocolPath, + schema, + }) as RecordsWriteTest; + + // Create a RecordsWriteMessage + const recordsWrite = await RecordsWrite.create({ + attestationSignatureInputs : attestation, + authorizationSignatureInput : authorization, + data : new Uint8Array(await dataBlob.arrayBuffer()), + dataFormat, + encryptionInput, + parentId : parentRecorsWrite.recordId, + protocol, + protocolPath, + published, + recipient, + schema, + }) as RecordsWriteTest; + + // Create record using test RecordsWriteMessage. + const record = new Record(testAgent.agent, { + ...recordsWrite.message, + encodedData: dataBlob, + target, + author, + }); + + // Call toJSON() method. + const recordJson = record.toJSON(); + + // Retained Record properties. + expect(recordJson.author).to.equal(author); + expect(recordJson.target).to.equal(target); + + // Retained RecordsWriteMessage top-level properties. + expect(record.contextId).to.equal(recordsWrite.message.contextId); + expect(record.id).to.equal(recordsWrite.message.recordId); + expect(record.encryption).to.not.be.undefined; + expect(record.encryption).to.deep.equal(recordsWrite.message.encryption); + expect(record.encryption!.keyEncryption.find(key => key.derivationScheme === KeyDerivationScheme.ProtocolPath)); + expect(record.attestation).to.not.be.undefined; + expect(record.attestation).to.have.property('signatures'); + + // Retained RecordsWriteDescriptor properties. + expect(recordJson.interface).to.equal(DwnInterfaceName.Records); + expect(recordJson.method).to.equal(DwnMethodName.Write); + expect(recordJson.protocol).to.equal(protocol); + expect(recordJson.protocolPath).to.equal(protocolPath); + expect(recordJson.recipient).to.equal(recipient); + expect(recordJson.schema).to.equal(schema); + expect(recordJson.parentId).to.equal(parentRecorsWrite.recordId); + expect(recordJson.dataCid).to.equal(recordsWrite.message.descriptor.dataCid); + expect(recordJson.dataSize).to.equal(recordsWrite.message.descriptor.dataSize); + expect(recordJson.dateCreated).to.equal(recordsWrite.message.descriptor.dateCreated); + expect(recordJson.messageTimestamp).to.equal(recordsWrite.message.descriptor.messageTimestamp); + expect(recordJson.published).to.equal(published); + expect(recordJson.datePublished).to.equal(recordsWrite.message.descriptor.datePublished); + expect(recordJson.dataFormat).to.equal(dataFormat); + }); + }); + + describe('update()', () => { + it('updates a record', async () => { + const { status, record } = await dwn.records.write({ + data : 'Hello, world!', + message : { + schema : 'foo/bar', + dataFormat : 'text/plain' + } + }); + + const dataCidBeforeDataUpdate = record!.dataCid; + + expect(status.code).to.equal(202); + expect(record).to.not.be.undefined; + + const updateResult = await record!.update({ data: 'bye' }); + expect(updateResult.status.code).to.equal(202); + + const readResult = await dwn.records.read({ + message: { + recordId: record!.id + } + }); + + expect(readResult.status.code).to.equal(200); + expect(readResult.record).to.not.be.undefined; + + expect(readResult.record.dataCid).to.not.equal(dataCidBeforeDataUpdate); + expect(readResult.record.dataCid).to.equal(record!.dataCid); + + const updatedData = await record!.data.text(); + expect(updatedData).to.equal('bye'); + }); + + it('throws an exception when an immutable property is modified', async () => { + const { status, record } = await dwn.records.write({ + data : 'Hello, world!', + message : { + schema : 'foo/bar', + dataFormat : 'text/plain' + } + }); + + expect(status.code).to.equal(202); + expect(record).to.not.be.undefined; + + // @ts-expect-error because this test intentionally specifies an immutable property that is not present in RecordUpdateOptions. + await expect(record!.update({ dataFormat: 'application/json' })).to.eventually.be.rejectedWith('is an immutable property. Its value cannot be changed.'); + }); + }); +}); \ No newline at end of file diff --git a/packages/api/tests/tech-preview.spec.ts b/packages/api/tests/tech-preview.spec.ts new file mode 100644 index 000000000..602b935bc --- /dev/null +++ b/packages/api/tests/tech-preview.spec.ts @@ -0,0 +1,186 @@ +import sinon from 'sinon'; +import chai, { expect } from 'chai'; + +import { chaiUrl } from './utils/chai-plugins.js'; +import { getTechPreviewDwnEndpoints } from '../src/tech-preview.js'; + +chai.use(chaiUrl); + +describe('Tech Preview', () => { + describe('getTechPreviewDwnEndpoints()', () => { + let fetchStub: sinon.SinonStub; + let mockDwnEndpoints: Array; + + let tbdWellKnownOkResponse = { + status : 200, + statusText : 'OK', + ok : true, + json : async () => Promise.resolve({ + id : 'did:web:dwn.tbddev.org', + service : [ + { + id : '#dwn', + serviceEndpoint : { + nodes: mockDwnEndpoints + }, + type: 'DecentralizedWebNode' + } + ] + }) + }; + + let tbdWellKnownBadResponse = { + status : 400, + statusText : 'Bad Request', + ok : false + }; + + let dwnServerHealthOkResponse = { + status : 200, + statusText : 'OK', + ok : true, + json : async () => Promise.resolve({ok: true}) + }; + + let dwnServerHealthBadResponse = { + status : 400, + statusText : 'Bad Request', + ok : false + }; + + beforeEach(() => { + mockDwnEndpoints = [ + 'https://dwn.tbddev.test/dwn0', + 'https://dwn.tbddev.test/dwn1', + 'https://dwn.tbddev.test/dwn2', + 'https://dwn.tbddev.test/dwn3', + 'https://dwn.tbddev.test/dwn4', + 'https://dwn.tbddev.test/dwn5', + 'https://dwn.tbddev.test/dwn6' + ]; + + fetchStub = sinon.stub(globalThis as any, 'fetch'); + + fetchStub.callsFake((url) => { + if (url === 'https://dwn.tbddev.org/.well-known/did.json') { + return Promise.resolve(tbdWellKnownOkResponse); + } else if (url.endsWith('/health')) { + return Promise.resolve(dwnServerHealthOkResponse); + } + }); + }); + + afterEach(() => { + fetchStub.restore(); + }); + + it('returns an array', async () => { + const dwnEndpoints = await getTechPreviewDwnEndpoints(); + + expect(dwnEndpoints).to.be.an('array'); + }); + + it('returns valid DWN endpoint URLs', async () => { + const dwnEndpoints = await getTechPreviewDwnEndpoints(); + + // There must be at one URL to check or else this test always passes. + expect(dwnEndpoints).to.have.length.greaterThan(0); + + dwnEndpoints.forEach(endpoint => { + expect(endpoint).to.be.a.url; + expect(mockDwnEndpoints).to.include(endpoint); + }); + }); + + it('returns 2 DWN endpoints if at least 2 are healthy', async () => { + const promises = Array(50).fill(0).map(() => getTechPreviewDwnEndpoints()); + + const results = await Promise.all(promises); + + results.forEach(result => { + expect(result).to.be.an('array').that.has.length(2); + }); + }); + + it('returns 1 DWN endpoints if only 1 is healthy', async () => { + mockDwnEndpoints = [ + 'https://dwn.tbddev.test/dwn0' + ]; + + const promises = Array(50).fill(0).map(() => getTechPreviewDwnEndpoints()); + + const results = await Promise.all(promises); + + results.forEach(result => { + expect(result).to.be.an('array').that.has.length(1); + }); + }); + + it('ignores health check failures and tries next endpooint', async () => { + mockDwnEndpoints = [ + 'https://dwn.tbddev.test/dwn0', + 'https://dwn.tbddev.test/dwn1', + ]; + + // Stub fetch to simulate dwn.tbddev.org responding but all of the hosted DWN Server reporting not healthy. + fetchStub.restore(); + fetchStub = sinon.stub(globalThis as any, 'fetch'); + fetchStub.callsFake((url) => { + if (url === 'https://dwn.tbddev.org/.well-known/did.json') { + return Promise.resolve(tbdWellKnownOkResponse); + } else if (url === 'https://dwn.tbddev.test/dwn0/health') { + return Promise.reject(dwnServerHealthOkResponse); + } else if (url === 'https://dwn.tbddev.test/dwn1/health') { + return Promise.resolve(dwnServerHealthBadResponse); + } + }); + + const dwnEndpoints = await getTechPreviewDwnEndpoints(); + + expect(dwnEndpoints).to.be.an('array').that.has.length(0); + }); + + it('returns 0 DWN endpoints if none are healthy', async () => { + // Stub fetch to simulate dwn.tbddev.org responding but all of the hosted DWN Server reporting not healthy. + fetchStub.restore(); + fetchStub = sinon.stub(globalThis as any, 'fetch'); + fetchStub.callsFake((url) => { + if (url === 'https://dwn.tbddev.org/.well-known/did.json') { + return Promise.resolve(tbdWellKnownOkResponse); + } else if (url.endsWith('/health')) { + return Promise.resolve(dwnServerHealthBadResponse); + } + }); + + const dwnEndpoints = await getTechPreviewDwnEndpoints(); + + expect(dwnEndpoints).to.be.an('array').that.has.length(0); + }); + + it('returns 0 DWN endpoints if dwn.tbddev.org is not responding', async () => { + // Stub fetch to simulate dwn.tbddev.org responding but all of the hosted DWN Server reporting not healthy. + fetchStub.restore(); + fetchStub = sinon.stub(globalThis as any, 'fetch'); + fetchStub.callsFake((url) => { + if (url === 'https://dwn.tbddev.org/.well-known/did.json') { + return Promise.resolve(tbdWellKnownBadResponse); + } + }); + + const dwnEndpoints = await getTechPreviewDwnEndpoints(); + + expect(dwnEndpoints).to.be.an('array').that.has.length(0); + }); + + it('returns 0 DWN endpoints if fetching dwn.tbddev.org throws an exception', async () => { + // Stub fetch to simulate fetching dwn.tbddev.org throwing an exception. + fetchStub.restore(); + fetchStub = sinon.stub(globalThis as any, 'fetch'); + fetchStub.withArgs('https://dwn.tbddev.org/.well-known/did.json').rejects(new Error('Network error')); + + const dwnEndpoints = await getTechPreviewDwnEndpoints(); + + expect(dwnEndpoints).to.be.an('array').that.has.length(0); + }); + }); +}); \ No newline at end of file diff --git a/packages/api/tests/test-config.ts b/packages/api/tests/test-config.ts new file mode 100644 index 000000000..213604404 --- /dev/null +++ b/packages/api/tests/test-config.ts @@ -0,0 +1,24 @@ +declare const __karma__: { config?: { testDwnUrl?: string; } }; + +const DEFAULT_TEST_DWN_URL = 'https://dwn.tbddev.org/dwn0'; + +function getTestDwnUrl(): string { + // Check to see if we're running in a Karma browser test environment. + const browserTestEnvironment = typeof __karma__ !== 'undefined' && __karma__?.config?.testDwnUrl !== undefined; + + // Check to see if we're running in a Node environment. + const nodeTestEnvironment = process && process?.env !== undefined; + + // Attempt to use DWN URL defined in Karma config, if running a browser test. + // Otherwise, attempt to use the Node environment variable. + const envTestDwnUrl = (browserTestEnvironment) + ? __karma__.config!.testDwnUrl + : (nodeTestEnvironment) + ? process.env.TEST_DWN_URL + : undefined; + + // If defined, return the test environment DWN URL. Otherwise, return the default. + return envTestDwnUrl || DEFAULT_TEST_DWN_URL; +} + +export const testDwnUrl = getTestDwnUrl(); \ No newline at end of file diff --git a/packages/web5-proxy-agent/tests/tsconfig.json b/packages/api/tests/tsconfig.json similarity index 100% rename from packages/web5-proxy-agent/tests/tsconfig.json rename to packages/api/tests/tsconfig.json diff --git a/packages/api/tests/utils.spec.ts b/packages/api/tests/utils.spec.ts new file mode 100644 index 000000000..b2bfb1811 --- /dev/null +++ b/packages/api/tests/utils.spec.ts @@ -0,0 +1,58 @@ +import { expect } from 'chai'; + +import { dataToBlob } from '../src/utils.js'; + +describe('Web5 API Utils', () => { + describe('dataToBlob()', () => { + it('should handle text data with explicit format', async () => { + const result = dataToBlob('Hello World', 'text/plain'); + expect(result.dataBlob.type).to.equal('text/plain'); + expect(result.dataFormat).to.equal('text/plain'); + const output = await result.dataBlob.text(); + expect(output).to.equal('Hello World'); + }); + + it('should handle text data with detected type', async () => { + const result = dataToBlob('Hello World'); + expect(result.dataBlob.type).to.equal('text/plain'); + expect(result.dataFormat).to.equal('text/plain'); + const output = await result.dataBlob.text(); + expect(output).to.equal('Hello World'); + }); + + it('should handle JSON data with explicit format', async () => { + const result = dataToBlob({ key: 'value' }, 'application/json'); + expect(result.dataBlob.type).to.equal('application/json'); + expect(result.dataFormat).to.equal('application/json'); + }); + + it('should handle JSON data with detected type', () => { + const result = dataToBlob({ key: 'value' }); + expect(result.dataBlob.type).to.equal('application/json'); + expect(result.dataFormat).to.equal('application/json'); + }); + + it('should handle Uint8Array data', () => { + const result = dataToBlob(new Uint8Array([1, 2, 3])); + expect(result.dataBlob.type).to.equal('application/octet-stream'); + expect(result.dataFormat).to.equal('application/octet-stream'); + }); + + it('should handle ArrayBuffer data', () => { + const result = dataToBlob(new ArrayBuffer(3)); + expect(result.dataBlob.type).to.equal('application/octet-stream'); + expect(result.dataFormat).to.equal('application/octet-stream'); + }); + + it('should handle Blob data', () => { + const blob = new Blob(['data'], { type: 'custom/type' }); + const result = dataToBlob(blob); + expect(result.dataBlob.type).to.equal('custom/type'); + expect(result.dataFormat).to.equal('custom/type'); + }); + + it('should throw an error for unsupported data types', () => { + expect(() => dataToBlob(42)).to.throw('data type not supported.'); + }); + }); +}); \ No newline at end of file diff --git a/packages/web5/tests/test-utils/chai-plugins.ts b/packages/api/tests/utils/chai-plugins.ts similarity index 100% rename from packages/web5/tests/test-utils/chai-plugins.ts rename to packages/api/tests/utils/chai-plugins.ts diff --git a/packages/api/tests/utils/test-data-generator.ts b/packages/api/tests/utils/test-data-generator.ts new file mode 100644 index 000000000..76ad53383 --- /dev/null +++ b/packages/api/tests/utils/test-data-generator.ts @@ -0,0 +1,71 @@ +import { randomBytes } from '@web5/crypto/utils'; + +export class TestDataGenerator { + /** + * Generates a random byte array of given length. + */ + static randomBytes(length: number): Uint8Array { + return randomBytes(length); + } + + /** + * Generate a random number of given length. + */ + static randomDigits(length: number): number { + let result = 0; + for(let i = 0; i < length; i++) { + result = result * 10 + Math.floor(Math.random() * 10); + } + return result; + } + + /** + * Generates a random JavaScript object of given length in bytes. + */ + static randomJson(length: number): object { + // Start with an empty object. + let obj = {}; + + // Generate properties until the JSON string is close to the desired length. + let lessThanDesiredLength = true; + while (lessThanDesiredLength) { + // Use a random key and value to avoid any optimization that might occur + // from using the same key and value repeatedly. + let key = Math.random().toString(36).substring(2); + let value = Math.random().toString(36).substring(2); + + // Calculate the size of the new property (including quotes and colon). + let propertySize = key.length + value.length + 4; + + // If the new property fits within the desired size, add it to the object. + const currentLength = JSON.stringify(obj).length; + + if (currentLength + propertySize <= length) { + obj[key] = value; + } else if (length - currentLength > 5) { + const padLength = length - currentLength - 4; + obj[0] = TestDataGenerator.randomDigits(padLength); + lessThanDesiredLength = false; + } else { + lessThanDesiredLength = false; + } + } + + return obj; + } + + /** + * Generates a random alpha-numeric string of given length. + */ + static randomString(length: number): string { + const charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; + + // Select characters randomly. + let randomChars: string[] = []; + for (let i = 0; i < length; i++) { + randomChars.push(charset.charAt(Math.floor(Math.random() * charset.length))); + } + + return randomChars.join(''); + } +} \ No newline at end of file diff --git a/packages/api/tests/utils/test-user-agent.ts b/packages/api/tests/utils/test-user-agent.ts new file mode 100644 index 000000000..9caf5d8c2 --- /dev/null +++ b/packages/api/tests/utils/test-user-agent.ts @@ -0,0 +1,196 @@ +import type { + DwnRpc, + VcResponse, + DidResponse, + DwnResponse, + AppDataStore, + SendVcRequest, + SendDidRequest, + SendDwnRequest, + ProcessVcRequest, + Web5ManagedAgent, + ProcessDidRequest, + ProcessDwnRequest, +} from '@web5/agent'; + +import { Dwn } from '@tbd54566975/dwn-sdk-js'; +import { + DidResolver, + DidKeyMethod, +} from '@web5/dids'; +import { + EventLogLevel, + DataStoreLevel, + MessageStoreLevel, +} from '@tbd54566975/dwn-sdk-js/stores'; +import { + LocalKms, + DidManager, + DwnManager, + KeyManager, + AppDataVault, + Web5RpcClient, + IdentityManager, +} from '@web5/agent'; + +type CreateMethodOptions = { + testDataLocation?: string; +} + +type TestUserAgentOptions = { + appData: AppDataStore; + didManager: DidManager; + didResolver: DidResolver; + dwnManager: DwnManager; + identityManager: IdentityManager; + keyManager: KeyManager; + rpcClient: DwnRpc; + + dwn: Dwn; + dwnDataStore: DataStoreLevel; + dwnEventLog: EventLogLevel; + dwnMessageStore: MessageStoreLevel; +} + +export class TestUserAgent implements Web5ManagedAgent { + agentDid: string | undefined; + appData: AppDataStore; + didManager: DidManager; + didResolver: DidResolver; + dwnManager: DwnManager; + identityManager: IdentityManager; + keyManager: KeyManager; + rpcClient: DwnRpc; + + /** + * DWN-related properties. + */ + dwn: Dwn; + dwnDataStore: DataStoreLevel; + dwnEventLog: EventLogLevel; + dwnMessageStore: MessageStoreLevel; + + constructor(options: TestUserAgentOptions) { + this.appData = options.appData; + this.didManager = options.didManager; + this.didResolver = options.didResolver; + this.dwnManager = options.dwnManager; + this.identityManager = options.identityManager; + this.keyManager = options.keyManager; + this.rpcClient = options.rpcClient; + + // Set this agent to be the default agent for each component. + this.didManager.agent = this; + this.dwnManager.agent = this; + this.identityManager.agent = this; + this.keyManager.agent = this; + + // TestUserAgent-specific properties. + this.dwn = options.dwn; + this.dwnDataStore = options.dwnDataStore; + this.dwnEventLog = options.dwnEventLog; + this.dwnMessageStore = options.dwnMessageStore; + } + + async clearStorage(): Promise { + this.agentDid = undefined; + await this.dwnDataStore.clear(); + await this.dwnEventLog.clear(); + await this.dwnMessageStore.clear(); + } + + async closeStorage(): Promise { + await this.dwnDataStore.close(); + await this.dwnEventLog.close(); + await this.dwnMessageStore.close(); + } + + static async create(options: CreateMethodOptions = {}): Promise { + const testDataLocation = options.testDataLocation ?? '__TESTDATA__'; + const testDataPath = (path: string) => `${testDataLocation}/${path}`; + + // Instantiate custom stores to use with DWN instance. + const dwnDataStore = new DataStoreLevel({ blockstoreLocation: testDataPath('DATASTORE') }); + const dwnEventLog = new EventLogLevel({ location: testDataPath('EVENTLOG') }); + const dwnMessageStore = new MessageStoreLevel({ + blockstoreLocation : testDataPath('MESSAGESTORE'), + indexLocation : testDataPath('INDEX') + }); + + // Instantiate components with default in-memory stores. + const appData = new AppDataVault({ keyDerivationWorkFactor: 1 }); + const didManager = new DidManager({ didMethods: [DidKeyMethod] }); + const identityManager = new IdentityManager(); + const kms = { + memory: new LocalKms({ kmsName: 'memory' }) + }; + const keyManager = new KeyManager({ kms }); + + // Instantiate DID resolver. + const didMethodApis = [DidKeyMethod]; + const didResolver = new DidResolver({ didResolvers: didMethodApis }); + + // Instantiate custom DWN instance. + const dwn = await Dwn.create({ + eventLog : dwnEventLog, + dataStore : dwnDataStore, + messageStore : dwnMessageStore + }); + + // Instantiate a DwnManager using the custom DWN instance. + const dwnManager = new DwnManager({ dwn }); + + // Instantiate an RPC Client. + const rpcClient = new Web5RpcClient(); + + return new TestUserAgent({ + appData, + didManager, + didResolver, + dwn, + dwnDataStore, + dwnEventLog, + dwnMessageStore, + dwnManager, + identityManager, + keyManager, + rpcClient, + }); + } + + async firstLaunch(): Promise { + throw new Error('Not implemented'); + } + + async initialize(_options: { passphrase: string; }): Promise { + throw new Error('Not implemented'); + } + + async processDidRequest(_request: ProcessDidRequest): Promise { + throw new Error('Not implemented'); + } + + async processDwnRequest(request: ProcessDwnRequest): Promise { + return this.dwnManager.processRequest(request); + } + + async processVcRequest(_request: ProcessVcRequest): Promise { + throw new Error('Not implemented'); + } + + async sendDidRequest(_request: SendDidRequest): Promise { + throw new Error('Not implemented'); + } + + async sendDwnRequest(request: SendDwnRequest): Promise { + return this.dwnManager.sendRequest(request); + } + + async sendVcRequest(_request: SendVcRequest): Promise { + throw new Error('Not implemented'); + } + + async start(_options: { passphrase: string; }): Promise { + throw new Error('Not implemented'); + } +} \ No newline at end of file diff --git a/packages/api/tests/vc-api.spec.ts b/packages/api/tests/vc-api.spec.ts new file mode 100644 index 000000000..dcfd9b03d --- /dev/null +++ b/packages/api/tests/vc-api.spec.ts @@ -0,0 +1,50 @@ +import { expect } from 'chai'; +import { TestManagedAgent } from '@web5/agent'; + +import { VcApi } from '../src/vc-api.js'; +import { TestUserAgent } from './utils/test-user-agent.js'; + +describe('VcApi', () => { + let vc: VcApi; + let testAgent: TestManagedAgent; + + before(async () => { + testAgent = await TestManagedAgent.create({ + agentClass : TestUserAgent, + agentStores : 'memory' + }); + }); + + beforeEach(async () => { + await testAgent.clearStorage(); + + // Create an Agent DID. + await testAgent.createAgentDid(); + + // Create a new Identity to author DWN messages. + const identity = await testAgent.agent.identityManager.create({ + name : 'Test', + didMethod : 'key', + kms : 'local' + }); + + // Instantiate VcApi. + vc = new VcApi({ agent: testAgent.agent, connectedDid: identity.did }); + }); + + after(async () => { + await testAgent.clearStorage(); + await testAgent.closeStorage(); + }); + + describe('create()', () => { + it('is not implemented', async () => { + try { + await vc.create(); + expect.fail('Expected method to throw, but it did not.'); + } catch(e) { + expect(e.message).to.include('Not implemented.'); + } + }); + }); +}); \ No newline at end of file diff --git a/packages/api/tests/web5.spec.ts b/packages/api/tests/web5.spec.ts new file mode 100644 index 000000000..6ee53da61 --- /dev/null +++ b/packages/api/tests/web5.spec.ts @@ -0,0 +1,89 @@ +import { expect } from 'chai'; +import { AppDataVault, TestManagedAgent } from '@web5/agent'; + +import { Web5 } from '../src/web5.js'; +import { TestUserAgent } from './utils/test-user-agent.js'; +import { MemoryStore } from '@web5/common'; +import { DidIonMethod } from '@web5/dids'; +import { Web5UserAgent } from '@web5/user-agent'; + +describe.only('Web5', () => { + describe('using TestManagedAgent', () => { + let testAgent: TestManagedAgent; + + before(async () => { + testAgent = await TestManagedAgent.create({ + agentClass : TestUserAgent, + agentStores : 'memory' + }); + }); + + beforeEach(async () => { + await testAgent.clearStorage(); + await testAgent.createAgentDid(); + }); + + after(async () => { + await testAgent.clearStorage(); + await testAgent.closeStorage(); + }); + + describe('connect()', () => { + it('accepts an externally created ION DID', async () => { + // Create an ION DID. + const didOptions = await DidIonMethod.generateDwnOptions({ + serviceEndpointNodes: ['https://dwn.example.com'] + }); + const portableDid = await DidIonMethod.create({ ...didOptions }); + + // Import the previously created DID. + await testAgent.agent.identityManager.import({ + identity : { name: 'Test', did: portableDid.did }, + did : portableDid, + kms : 'local' + }); + + // Call connect() with the custom agent. + const { web5, did } = await Web5.connect({ + agent : testAgent.agent, + connectedDid : portableDid.did + }); + + expect(did).to.exist; + expect(web5).to.exist; + }).timeout(5000); + }); + + describe('constructor', () => { + it('instantiates Web5 API with provided Web5Agent and connectedDid', async () => { + // Create a new Identity. + const socialIdentity = await testAgent.agent.identityManager.create({ + name : 'Social', + didMethod : 'key', + kms : 'local' + }); + + // Instantiates Web5 instance with test agent and new Identity's DID. + const web5 = new Web5({ agent: testAgent.agent, connectedDid: socialIdentity.did }); + expect(web5).to.exist; + expect(web5).to.have.property('did'); + expect(web5).to.have.property('dwn'); + expect(web5).to.have.property('vc'); + }); + }); + }); + + describe('connect()', () => { + it('returns a web5 instance and connected DID using Web5UserAgent, by default', async () => { + // Create an in-memory App data store to speed up tests. + const appData = new AppDataVault({ + keyDerivationWorkFactor : 1, + store : new MemoryStore() + }); + const { web5, did } = await Web5.connect({ appData }); + + expect(did).to.exist; + expect(web5).to.exist; + }).timeout(5000); + }); +}); \ No newline at end of file diff --git a/packages/web5-user-agent/tsconfig.cjs.json b/packages/api/tsconfig.cjs.json similarity index 81% rename from packages/web5-user-agent/tsconfig.cjs.json rename to packages/api/tsconfig.cjs.json index 0384273d6..7a6f9c0c0 100644 --- a/packages/web5-user-agent/tsconfig.cjs.json +++ b/packages/api/tsconfig.cjs.json @@ -10,7 +10,8 @@ "outDir": "dist/cjs", "declaration": false, "declarationMap": false, - "declarationDir": null + "declarationDir": null, + "downlevelIteration": true }, "include": [ "src" diff --git a/packages/web5/tsconfig.json b/packages/api/tsconfig.json similarity index 55% rename from packages/web5/tsconfig.json rename to packages/api/tsconfig.json index 86ee091a3..334d87aa4 100644 --- a/packages/web5/tsconfig.json +++ b/packages/api/tsconfig.json @@ -1,5 +1,6 @@ { "compilerOptions": { + // "strict": true, "lib": [ "DOM", "ES6" @@ -11,11 +12,16 @@ "declarationMap": true, "declarationDir": "dist/types", "outDir": "dist/esm", + // `NodeNext` will throw compilation errors if relative import paths are missing file extension + // reference: https://devblogs.microsoft.com/typescript/announcing-typescript-4-7/#ecmascript-module-support-in-node-js "moduleResolution": "NodeNext", "esModuleInterop": true, "resolveJsonModule": true }, "include": [ - "src" + "src", + ], + "exclude": [ + "node_modules" ] } \ No newline at end of file diff --git a/packages/common/.c8rc.json b/packages/common/.c8rc.json index 1d1670b70..ab680f663 100644 --- a/packages/common/.c8rc.json +++ b/packages/common/.c8rc.json @@ -5,12 +5,12 @@ ".js" ], "include": [ - "tests/compiled/**" + "tests/compiled/src/**" ], "exclude": [ - "tests/compiled/src/main.js", + "tests/compiled/src/index.js", "tests/compiled/src/types.js", - "tests/compiled/types/**" + "tests/compiled/src/types/**" ], "reporter": [ "cobertura", diff --git a/packages/common/build/cjs-bundle.js b/packages/common/build/cjs-bundle.js index 968bf88cf..367b90104 100644 --- a/packages/common/build/cjs-bundle.js +++ b/packages/common/build/cjs-bundle.js @@ -15,12 +15,12 @@ for (const dependency in packageJson.dependencies) { } esbuild.build({ - entryPoints : [ './src/main.ts' ], + entryPoints : [ './src/index.ts' ], bundle : true, external : excludeList, format : 'cjs', sourcemap : true, platform : 'node', - outfile : 'dist/cjs/main.js', + outfile : 'dist/cjs/index.js', allowOverwrite : true }); \ No newline at end of file diff --git a/packages/common/build/esbuild-browser-config.cjs b/packages/common/build/esbuild-browser-config.cjs index ae37c97f0..8fd899321 100644 --- a/packages/common/build/esbuild-browser-config.cjs +++ b/packages/common/build/esbuild-browser-config.cjs @@ -1,6 +1,6 @@ /** @type {import('esbuild').BuildOptions} */ module.exports = { - entryPoints : ['./src/main.ts'], + entryPoints : ['./src/index.ts'], bundle : true, format : 'esm', sourcemap : true, @@ -10,4 +10,4 @@ module.exports = { define : { 'global': 'globalThis', }, -}; +}; \ No newline at end of file diff --git a/packages/common/karma.conf.cjs b/packages/common/karma.conf.cjs index aa89cbca8..6b7407b2c 100644 --- a/packages/common/karma.conf.cjs +++ b/packages/common/karma.conf.cjs @@ -30,14 +30,15 @@ module.exports = function (config) { // available frameworks: https://www.npmjs.com/search?q=keywords:karma-adapter frameworks: ['mocha'], - // Increase Mocha's default timeout of 2 seconds to prevent timeouts during GitHub CI runs. client: { + // Increase Mocha's default timeout of 2 seconds to prevent timeouts during GitHub CI runs. mocha: { timeout: 10000 // 10 seconds - } + }, + // If an environment variable is defined, override the default test DWN URL. + testDwnUrl: process.env.TEST_DWN_URL, }, - // list of files / patterns to load in the browser files: [ { pattern: 'tests/**/*.spec.ts', watched: false }, diff --git a/packages/common/package.json b/packages/common/package.json index f23b0ed4b..c313854fa 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -1,10 +1,10 @@ { - "name": "@tbd54566975/common", - "version": "0.8.0", + "name": "@web5/common", + "version": "0.2.0", "type": "module", - "main": "./dist/cjs/main.js", - "module": "./dist/esm/main.js", - "types": "./dist/types/main.d.ts", + "main": "./dist/cjs/index.js", + "module": "./dist/esm/index.js", + "types": "./dist/types/index.d.ts", "scripts": { "clean": "rimraf dist coverage tests/compiled", "build:esm": "rimraf dist/esm dist/types && npx tsc -p tsconfig.json", @@ -45,12 +45,12 @@ ], "exports": { ".": { - "import": "./dist/esm/main.js", - "require": "./dist/cjs/main.js", - "types": "./dist/types/main.d.ts" + "types": "./dist/types/index.d.ts", + "import": "./dist/esm/index.js", + "require": "./dist/cjs/index.js" } }, - "react-native": "./dist/esm/main.js", + "react-native": "./dist/esm/index.js", "keywords": [ "decentralized", "decentralized-applications", @@ -67,18 +67,22 @@ "node": ">=18.0.0" }, "dependencies": { + "level": "8.0.0", "multiformats": "11.0.2" }, "devDependencies": { - "@types/chai": "4.3.0", - "@types/eslint": "8.37.0", + "@playwright/test": "1.36.2", + "@types/chai": "4.3.5", + "@types/chai-as-promised": "7.1.5", + "@types/eslint": "8.44.2", "@types/mocha": "10.0.1", - "@typescript-eslint/eslint-plugin": "5.59.0", - "@typescript-eslint/parser": "5.59.0", - "c8": "8.0.0", + "@typescript-eslint/eslint-plugin": "6.4.0", + "@typescript-eslint/parser": "6.4.0", + "c8": "8.0.1", "chai": "4.3.7", + "chai-as-promised": "7.1.1", "esbuild": "0.16.17", - "eslint": "8.39.0", + "eslint": "8.47.0", "eslint-plugin-mocha": "10.1.0", "karma": "6.4.1", "karma-chai": "0.1.0", diff --git a/packages/common/src/convert.ts b/packages/common/src/convert.ts index ed6871cea..294648582 100644 --- a/packages/common/src/convert.ts +++ b/packages/common/src/convert.ts @@ -96,11 +96,11 @@ export class Convert { } case 'Hex': { - return Convert.hex(this.data).toUint8Array().buffer; + return this.toUint8Array().buffer; } case 'String': { - return Convert.string(this.data).toUint8Array().buffer; + return this.toUint8Array().buffer; } case 'Uint8Array': { @@ -141,6 +141,11 @@ export class Convert { return base64url.baseEncode(u8a); } + case 'BufferSource': { + const u8a = this.toUint8Array(); + return base64url.baseEncode(u8a); + } + case 'Object': { const string = JSON.stringify(this.data); const u8a = textEncoder.encode(string); @@ -168,7 +173,12 @@ export class Convert { switch (this.format) { case 'ArrayBuffer': { - const u8a = new Uint8Array(this.data); + const u8a = this.toUint8Array(); + return Convert.uint8Array(u8a).toHex(); + } + + case 'Base64Url': { + const u8a = this.toUint8Array(); return Convert.uint8Array(u8a).toHex(); } @@ -181,7 +191,7 @@ export class Convert { } default: - throw new TypeError(`Conversion from ${this.format} to Object is not supported.`); + throw new TypeError(`Conversion from ${this.format} to Hex is not supported.`); } } diff --git a/packages/common/src/main.ts b/packages/common/src/index.ts similarity index 84% rename from packages/common/src/main.ts rename to packages/common/src/index.ts index 4767c3399..204ddeb1c 100644 --- a/packages/common/src/main.ts +++ b/packages/common/src/index.ts @@ -2,5 +2,6 @@ export type * from './types.js'; export * from './convert.js'; export * from './multicodec.js'; +export * from './object.js'; export * from './stores.js'; export * from './type-utils.js'; \ No newline at end of file diff --git a/packages/common/src/multicodec.ts b/packages/common/src/multicodec.ts index 98fa89034..18af88de6 100644 --- a/packages/common/src/multicodec.ts +++ b/packages/common/src/multicodec.ts @@ -54,9 +54,8 @@ export class Multicodec { }): Uint8Array { let { code, data, name } = options; - // Either code or name must be specified, but not both. if (!(name ? !code : code)) { - throw new Error(`Exactly one of 'name' or 'code' must be defined.`); + throw new Error(`Either 'name' or 'code' must be defined, but not both.`); } // If code was given, confirm it exists, or lookup code by name. @@ -64,7 +63,7 @@ export class Multicodec { // Throw error if a registered Codec wasn't found. if (code === undefined) { - throw new Error(`Multicodec not found: ${name ?? code}`); + throw new Error(`Unsupported multicodec: ${options.name ?? options.code}`); } // Create a new array to store the prefix and input data. @@ -94,6 +93,48 @@ export class Multicodec { return code; } + /** + * Get the Multicodec code from given Multicodec name. + * + * @param options - The options for getting the codec code. + * @param options.name - The name to lookup. + * @returns - The Multicodec code as a number. + */ + public static getCodeFromName(options: { + name: string + }): MulticodecCode { + const { name } = options; + + // Throw error if a registered Codec wasn't found. + const code = Multicodec.nameToCode.get(name); + if (code === undefined) { + throw new Error(`Unsupported multicodec: ${name}`); + } + + return code; + } + + /** + * Get the Multicodec name from given Multicodec code. + * + * @param options - The options for getting the codec name. + * @param options.name - The code to lookup. + * @returns - The Multicodec name as a string. + */ + public static getNameFromCode(options: { + code: MulticodecCode + }): string { + const { code } = options; + + // Throw error if a registered Codec wasn't found. + const name = Multicodec.codeToName.get(code); + if (name === undefined) { + throw new Error(`Unsupported multicodec: ${code}`); + } + + return name; + } + /** * Registers a new codec in the Multicodec class. * @@ -112,10 +153,17 @@ export class Multicodec { */ public static removePrefix(options: { prefixedData: Uint8Array - }): Uint8Array { + }): { code: MulticodecCode, name: string, data: Uint8Array } { const { prefixedData } = options; - const [_, codeByteLength] = varint.decode(prefixedData); - return prefixedData.slice(codeByteLength); + const [code, codeByteLength] = varint.decode(prefixedData); + + // Throw error if a registered Codec wasn't found. + const name = Multicodec.codeToName.get(code); + if (name === undefined) { + throw new Error(`Unsupported multicodec: ${code}`); + } + + return { code, data: prefixedData.slice(codeByteLength), name }; } } diff --git a/packages/common/src/object.ts b/packages/common/src/object.ts new file mode 100644 index 000000000..7d88fdfda --- /dev/null +++ b/packages/common/src/object.ts @@ -0,0 +1,43 @@ +/** + * Checks whether the given object has any properties. + */ +export function isEmptyObject(obj: unknown): boolean { + if (typeof obj !== 'object' || obj === null) { + return false; + } + + if (Object.getOwnPropertySymbols(obj).length > 0) { + return false; + } + + return Object.keys(obj).length === 0; +} + +/** + * Recursively removes all properties with an empty object or array as its value from the given object. + */ +export function removeEmptyObjects(obj: Record): void { + Object.keys(obj).forEach(key => { + if (typeof(obj[key]) === 'object') { + // recursive remove empty object or array properties in nested objects + removeEmptyObjects(obj[key] as Record); + } + + if (isEmptyObject(obj[key])) { + delete obj[key]; + } + }); +} + +/** + * Recursively removes all properties with `undefined` as its value from the given object. + */ +export function removeUndefinedProperties(obj: Record): void { + Object.keys(obj).forEach(key => { + if (obj[key] === undefined) { + delete obj[key]; + } else if (typeof(obj[key]) === 'object') { + removeUndefinedProperties(obj[key] as Record); // recursive remove `undefined` properties in nested objects + } + }); +} \ No newline at end of file diff --git a/packages/common/src/stores.ts b/packages/common/src/stores.ts index c9008b20e..1f4e9b090 100644 --- a/packages/common/src/stores.ts +++ b/packages/common/src/stores.ts @@ -1,5 +1,36 @@ +import { Level } from 'level'; + import type { KeyValueStore } from './types.js'; +export class LevelStore implements KeyValueStore { + private store: Level; + + constructor(location = 'DATASTORE') { + this.store = new Level(location); + } + + async clear(): Promise { + await this.store.clear(); + } + + async close(): Promise { + await this.store.close(); + } + + async delete(key: string): Promise { + await this.store.del(key); + return true; + } + + async get(key: string): Promise { + return await this.store.get(key); + } + + async set(key: string, value: any): Promise { + await this.store.put(key, value); + } +} + /** * The `MemoryStore` class is an implementation of * `KeyValueStore` that holds data in memory. @@ -35,11 +66,11 @@ export class MemoryStore implements KeyValueStore { } /** - * This operation is not supported by `MemoryStore` - * and will throw an error if called. + * This operation is no-op for `MemoryStore` + * and will log a warning if called. */ async close(): Promise { - throw new Error('MemoryStore does not support the close() method.'); + /** no-op */ } /** diff --git a/packages/common/tests/convert.spec.ts b/packages/common/tests/convert.spec.ts index 462fd70af..8e6b3d21f 100644 --- a/packages/common/tests/convert.spec.ts +++ b/packages/common/tests/convert.spec.ts @@ -96,6 +96,14 @@ describe('Convert', () =>{ expect(result).to.deep.equal(output); }); + it('to: Hex', () => { + // Test Vector 1. + let input = 'eyJmb28iOiJiYXIifQ'; + let output = '7b22666f6f223a22626172227d'; + const result = Convert.base64Url(input).toHex(); + expect(result).to.deep.equal(output); + }); + it('to: Object', () => { // Test Vector 1. let input = 'eyJmb28iOiJiYXIifQ'; @@ -178,6 +186,43 @@ describe('Convert', () =>{ expect (() => Convert.bufferSource(inputT8).toArrayBuffer()).to.throw(TypeError, 'value is not of type'); }); + it('to: Base64Url', () => { + // Test Vector 1 - BufferSource is Uint8Array. + let inputT1 = new Uint8Array([102, 111, 111]); + let outputT1 = 'Zm9v'; + let resultT1 = Convert.bufferSource(inputT1).toBase64Url(); + expect(resultT1).to.deep.equal(outputT1); + + // Test Vector 2 - BufferSource is ArrayBuffer. + let inputT2 = (new Uint8Array([50, 51, 52, 53])).buffer; + let outputT2 = 'MjM0NQ'; + let resultT2 = Convert.bufferSource(inputT2).toBase64Url(); + expect(resultT2).to.deep.equal(outputT2); + + // Test Vector 3 - BufferSource is DataView. + let inputT3 = new DataView((new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 0])).buffer); + let outputT3 = 'AQIDBAUGBwgJAA'; + let resultT3 = Convert.bufferSource(inputT3).toBase64Url(); + expect(resultT3).to.deep.equal(outputT3); + + // Test Vector 4 - BufferSource is an unsigned, 16-bit Typed Array. + let inputT4 = new Uint16Array([299, 298, 297]); + let outputT4 = 'KwEqASkB'; + let resultT4 = Convert.bufferSource(inputT4).toBase64Url(); + expect(resultT4).to.deep.equal(outputT4); + + // Test Vector 5 - BufferSource is a signed, 32-bit Typed Array. + let inputT5 = new Int32Array([1111, 1000, 2000]); + let outputT5 = 'VwQAAOgDAADQBwAA'; + let resultT5 = Convert.bufferSource(inputT5).toBase64Url(); + expect(resultT5).to.deep.equal(outputT5); + + // Test Vector 6 - BufferSource is Uint8Array. + let inputT6 = 'not BufferSource type'; + // @ts-expect-error because incorrect input data type is intentionally being used to trigger error. + expect (() => Convert.bufferSource(inputT6).toBase64Url()).to.throw(TypeError, 'value is not of type'); + }); + it('to: Uint8Array', () => { // Test Vector 1 - BufferSource is Uint8Array. let inputT1 = new Uint8Array([102, 111, 111]); diff --git a/packages/common/tests/multicodec.spec.ts b/packages/common/tests/multicodec.spec.ts index 5990a3765..1f35fba07 100644 --- a/packages/common/tests/multicodec.spec.ts +++ b/packages/common/tests/multicodec.spec.ts @@ -53,23 +53,23 @@ describe('Multicodec', () => { it('throws an error when code and name input data missing', () => { expect( () => Multicodec.addPrefix({ data: new Uint8Array(0) }) - ).to.throw(Error, `Exactly one of 'name' or 'code' must be defined.`); + ).to.throw(Error, `Either 'name' or 'code' must be defined, but not both.`); }); it('throws an error when both code and name specified', () => { expect( () => Multicodec.addPrefix({ code: 0x99999, name: 'non-existent', data: new Uint8Array(0) }) - ).to.throw(Error, `Exactly one of 'name' or 'code' must be defined.`); + ).to.throw(Error, `Either 'name' or 'code' must be defined, but not both.`); }); it('throws an error when codec not found', () => { expect( () => Multicodec.addPrefix({ code: 0x99999, data: new Uint8Array(0) }) - ).to.throw(Error, 'Multicodec not found'); + ).to.throw(Error, 'Unsupported multicodec: 629145'); expect( () => Multicodec.addPrefix({ name: 'non-existent', data: new Uint8Array(0) }) - ).to.throw(Error, 'Multicodec not found'); + ).to.throw(Error, 'Unsupported multicodec: non-existent'); }); }); @@ -86,17 +86,30 @@ describe('Multicodec', () => { }); describe('removePrefix()', () => { - it('returns Uint8Array with prefixed codec removed', () => { + it('returns code, name, and data', () => { + const input = new Uint8Array([0xed, 0x01, 0, 1, 2, 3]); + + const { code, data, name } = Multicodec.removePrefix({ prefixedData: input }); + + expect(code).to.be.a('Number'); + expect(data).to.be.a('Uint8Array'); + expect(name).to.be.a('String'); + }); + + it('returns data as Uint8Array with prefixed codec removed', () => { const input = new Uint8Array([0xed, 0x01, 0, 1, 2, 3]); const output = new Uint8Array([0, 1, 2, 3]); - const data = Multicodec.removePrefix({ prefixedData: input }); + const { data } = Multicodec.removePrefix({ prefixedData: input }); expect(data).to.be.a('Uint8Array'); expect(data).to.deep.equal(output); }); it('passes Multicodec test vectors', () => { + Multicodec.registerCodec({ code: 0x3ffff, name: 'test-vector-3' }); + Multicodec.registerCodec({ code: 0x3fffff, name: 'test-vector-4' }); + // Test vectors. const testVectors: [ArrayLike, ArrayLike][] = [ [[0xed, 0x01, 0, 1], [0, 1]], @@ -108,10 +121,22 @@ describe('Multicodec', () => { testVectors.forEach(([input, output]) => { const prefixedData = new Uint8Array(input); const [_, codeByteLength] = varint.decode(prefixedData); - const data = Multicodec.removePrefix({ prefixedData }); + const { data } = Multicodec.removePrefix({ prefixedData }); expect(data.byteLength).to.equal(prefixedData.byteLength - codeByteLength); expect(data).to.deep.equal(new Uint8Array(output)); }); }); + + it('throws an error when codec not found', () => { + const prefix = new Uint8Array([100, 100]); + const data = new Uint8Array([1, 2, 3, 4, 5]); + const dataWithPrefix = new Uint8Array(prefix.byteLength + data.byteLength); + dataWithPrefix.set(prefix, 0); + dataWithPrefix.set(data, prefix.length); + + expect( + () => Multicodec.removePrefix({ prefixedData: dataWithPrefix }) + ).to.throw(Error, 'Unsupported multicodec: 100'); + }); }); }); \ No newline at end of file diff --git a/packages/common/tests/object.spec.ts b/packages/common/tests/object.spec.ts new file mode 100644 index 000000000..58470795f --- /dev/null +++ b/packages/common/tests/object.spec.ts @@ -0,0 +1,88 @@ +import { expect } from 'chai'; + +import { isEmptyObject, removeEmptyObjects, removeUndefinedProperties } from '../src/object.js'; + + +describe('isEmptyObject()', () => { + it('should return true for an empty object', () => { + expect(isEmptyObject({})).to.be.true; + }); + + it('should return false for a non-empty object', () => { + expect(isEmptyObject({ key: 'value' })).to.be.false; + }); + + it('should return false for null', () => { + expect(isEmptyObject(null)).to.be.false; + }); + + it('should return true for an object with no prototype', () => { + expect(isEmptyObject(Object.create(null))).to.be.true; + }); + + it('should return false for an object with no prototype but containing properties', () => { + const obj = Object.create(null); + obj.key = 'value'; + expect(isEmptyObject(obj)).to.be.false; + }); + + it('should return false for an object with symbol properties', () => { + const symbol = Symbol('key'); + const obj = { [symbol]: 'value' }; + expect(isEmptyObject(obj)).to.be.false; + }); + + it('should return false for a non-object (number)', () => { + expect(isEmptyObject(42)).to.be.false; + }); + + it('should return false for a non-object (string)', () => { + expect(isEmptyObject('text')).to.be.false; + }); + + it('should return true for an object that inherits properties but has none of its own', () => { + const parent = { parentKey: 'value' }; + const child = Object.create(parent); + expect(isEmptyObject(child)).to.be.true; + }); +}); + +describe('removeEmptyObjects()', () => { + it('should remove all empty objects', () => { + const mockObject = { + foo : {}, + bar : { baz: {} }, + buzz : 'hello' + }; + + const expectedResult = { buzz: 'hello' }; + + removeEmptyObjects(mockObject); + + expect(mockObject).to.deep.equal(expectedResult); + }); +}); + +describe('removeUndefinedProperties()', () => { + it('should remove all `undefined` properties of a nested object', () => { + const mockObject = { + a : true, + b : undefined, + c : { + a : 0, + b : undefined, + } + }; + + const expectedResult = { + a : true, + c : { + a: 0 + } + }; + + removeUndefinedProperties(mockObject); + + expect(mockObject).to.deep.equal(expectedResult); + }); +}); \ No newline at end of file diff --git a/packages/common/tests/stores.spec.ts b/packages/common/tests/stores.spec.ts index a1c48017d..e6e23041f 100644 --- a/packages/common/tests/stores.spec.ts +++ b/packages/common/tests/stores.spec.ts @@ -25,10 +25,10 @@ describe('MemoryStore', () => { }); describe('close()', () => { - it('should throw an error when trying to close the store', async () => { + it('should no-op when trying to close the store', async () => { await expect( memoryStore.close() - ).to.be.rejectedWith('MemoryStore does not support the close() method.'); + ).to.be.fulfilled; }); }); diff --git a/packages/common/tests/type-utils.spec.ts b/packages/common/tests/type-utils.spec.ts index 29552e3c5..009f587e7 100644 --- a/packages/common/tests/type-utils.spec.ts +++ b/packages/common/tests/type-utils.spec.ts @@ -26,6 +26,10 @@ describe('universalTypeOf()', () => { expect(universalTypeOf(new ArrayBuffer(2))).to.equal('ArrayBuffer'); }); + it('should correctly identify Blob', () => { + expect(universalTypeOf(new Blob(['foo']))).to.equal('Blob'); + }); + it('should correctly identify Boolean', () => { expect(universalTypeOf(true)).to.equal('Boolean'); }); diff --git a/packages/common/tsconfig.json b/packages/common/tsconfig.json index 3147ea9c6..b29e4e7e1 100644 --- a/packages/common/tsconfig.json +++ b/packages/common/tsconfig.json @@ -20,5 +20,8 @@ }, "include": [ "src", + ], + "exclude": [ + "node_modules" ] } \ No newline at end of file diff --git a/packages/credentials/.c8rc.json b/packages/credentials/.c8rc.json index 1d1670b70..ab680f663 100644 --- a/packages/credentials/.c8rc.json +++ b/packages/credentials/.c8rc.json @@ -5,12 +5,12 @@ ".js" ], "include": [ - "tests/compiled/**" + "tests/compiled/src/**" ], "exclude": [ - "tests/compiled/src/main.js", + "tests/compiled/src/index.js", "tests/compiled/src/types.js", - "tests/compiled/types/**" + "tests/compiled/src/types/**" ], "reporter": [ "cobertura", diff --git a/packages/credentials/.vscode/launch.json b/packages/credentials/.vscode/launch.json index e2927b1de..bc398db79 100644 --- a/packages/credentials/.vscode/launch.json +++ b/packages/credentials/.vscode/launch.json @@ -11,7 +11,9 @@ "runtimeExecutable": "${workspaceFolder:root}/node_modules/.bin/mocha", "console": "internalConsole", "preLaunchTask": "build tests", - "skipFiles": ["/**"] + "skipFiles": [ + "/**" + ] } ] } \ No newline at end of file diff --git a/packages/credentials/build/bundles.js b/packages/credentials/build/bundles.js index 8137e7c71..a092adefb 100644 --- a/packages/credentials/build/bundles.js +++ b/packages/credentials/build/bundles.js @@ -11,6 +11,6 @@ esbuild.build({ esbuild.build({ ...browserConfig, format : 'iife', - globalName : 'Web5Ssi', + globalName : 'Web5Credentials', outfile : 'dist/browser.js', }); \ No newline at end of file diff --git a/packages/credentials/build/esbuild-browser-config.cjs b/packages/credentials/build/esbuild-browser-config.cjs index ae37c97f0..8fd899321 100644 --- a/packages/credentials/build/esbuild-browser-config.cjs +++ b/packages/credentials/build/esbuild-browser-config.cjs @@ -1,6 +1,6 @@ /** @type {import('esbuild').BuildOptions} */ module.exports = { - entryPoints : ['./src/main.ts'], + entryPoints : ['./src/index.ts'], bundle : true, format : 'esm', sourcemap : true, @@ -10,4 +10,4 @@ module.exports = { define : { 'global': 'globalThis', }, -}; +}; \ No newline at end of file diff --git a/packages/credentials/karma.conf.cjs b/packages/credentials/karma.conf.cjs index aa89cbca8..6b7407b2c 100644 --- a/packages/credentials/karma.conf.cjs +++ b/packages/credentials/karma.conf.cjs @@ -30,14 +30,15 @@ module.exports = function (config) { // available frameworks: https://www.npmjs.com/search?q=keywords:karma-adapter frameworks: ['mocha'], - // Increase Mocha's default timeout of 2 seconds to prevent timeouts during GitHub CI runs. client: { + // Increase Mocha's default timeout of 2 seconds to prevent timeouts during GitHub CI runs. mocha: { timeout: 10000 // 10 seconds - } + }, + // If an environment variable is defined, override the default test DWN URL. + testDwnUrl: process.env.TEST_DWN_URL, }, - // list of files / patterns to load in the browser files: [ { pattern: 'tests/**/*.spec.ts', watched: false }, diff --git a/packages/credentials/package.json b/packages/credentials/package.json index 60fc8bca7..136bf952e 100644 --- a/packages/credentials/package.json +++ b/packages/credentials/package.json @@ -1,11 +1,11 @@ { - "name": "@tbd54566975/credentials", - "version": "0.8.0", + "name": "@web5/credentials", + "version": "0.2.0", "description": "Verifiable Credentials", "type": "module", - "main": "./dist/cjs/main.js", - "module": "./dist/esm/main.js", - "types": "./dist/types/main.d.ts", + "main": "./dist/cjs/index.js", + "module": "./dist/esm/index.js", + "types": "./dist/types/index.d.ts", "scripts": { "clean": "rimraf dist coverage tests/compiled", "build:esm": "rimraf dist/esm dist/types && npx tsc -p tsconfig.json", @@ -46,12 +46,12 @@ ], "exports": { ".": { - "import": "./dist/esm/main.js", - "require": "./dist/cjs/main.js", - "types": "./dist/types/main.d.ts" + "types": "./dist/types/index.d.ts", + "import": "./dist/esm/index.js", + "require": "./dist/cjs/index.js" } }, - "react-native": "./dist/esm/main.js", + "react-native": "./dist/esm/index.js", "keywords": [ "decentralized", "decentralized-applications", @@ -69,15 +69,16 @@ }, "dependencies": {}, "devDependencies": { - "@types/chai": "4.3.0", - "@types/eslint": "8.37.0", + "@playwright/test": "1.36.2", + "@types/chai": "4.3.5", + "@types/eslint": "8.44.2", "@types/mocha": "10.0.1", - "@typescript-eslint/eslint-plugin": "5.59.0", - "@typescript-eslint/parser": "5.59.0", - "c8": "8.0.0", + "@typescript-eslint/eslint-plugin": "6.4.0", + "@typescript-eslint/parser": "6.4.0", + "c8": "8.0.1", "chai": "4.3.7", "esbuild": "0.16.17", - "eslint": "8.39.0", + "eslint": "8.47.0", "eslint-plugin-mocha": "10.1.0", "karma": "6.4.1", "karma-chai": "0.1.0", diff --git a/packages/credentials/src/main.ts b/packages/credentials/src/index.ts similarity index 100% rename from packages/credentials/src/main.ts rename to packages/credentials/src/index.ts diff --git a/packages/credentials/tests/example.spec.ts b/packages/credentials/tests/example.spec.ts index d5882cbaf..734da9934 100644 --- a/packages/credentials/tests/example.spec.ts +++ b/packages/credentials/tests/example.spec.ts @@ -1,7 +1,7 @@ import { expect } from 'chai'; describe('example', () => { - it('needs more tests', () => { + it('tests needed', () => { expect(true).to.be.true; }); }); \ No newline at end of file diff --git a/packages/credentials/tsconfig.json b/packages/credentials/tsconfig.json index 3147ea9c6..b29e4e7e1 100644 --- a/packages/credentials/tsconfig.json +++ b/packages/credentials/tsconfig.json @@ -20,5 +20,8 @@ }, "include": [ "src", + ], + "exclude": [ + "node_modules" ] } \ No newline at end of file diff --git a/packages/crypto/.c8rc.json b/packages/crypto/.c8rc.json index 9763ced85..ab680f663 100644 --- a/packages/crypto/.c8rc.json +++ b/packages/crypto/.c8rc.json @@ -5,13 +5,12 @@ ".js" ], "include": [ - "tests/compiled/**" + "tests/compiled/src/**" ], "exclude": [ - "tests/compiled/tests/**", - "tests/compiled/src/main.js", - "tests/compiled/src/types/**", - "tests/compiled/types/**" + "tests/compiled/src/index.js", + "tests/compiled/src/types.js", + "tests/compiled/src/types/**" ], "reporter": [ "cobertura", diff --git a/packages/crypto/.mocharc.json b/packages/crypto/.mocharc.json index 61014ff76..5aa8c5bfe 100644 --- a/packages/crypto/.mocharc.json +++ b/packages/crypto/.mocharc.json @@ -1,5 +1,5 @@ { - "enable-source-maps": true, - "exit": true, - "spec": ["tests/compiled/tests/**/*.spec.js"] - } \ No newline at end of file + "enable-source-maps": true, + "exit": true, + "spec": ["tests/compiled/**/*.spec.js"] +} \ No newline at end of file diff --git a/packages/crypto/.vscode/launch.json b/packages/crypto/.vscode/launch.json index e2927b1de..bc398db79 100644 --- a/packages/crypto/.vscode/launch.json +++ b/packages/crypto/.vscode/launch.json @@ -11,7 +11,9 @@ "runtimeExecutable": "${workspaceFolder:root}/node_modules/.bin/mocha", "console": "internalConsole", "preLaunchTask": "build tests", - "skipFiles": ["/**"] + "skipFiles": [ + "/**" + ] } ] } \ No newline at end of file diff --git a/packages/crypto/build/bundles.js b/packages/crypto/build/bundles.js index b697fbbfb..ac9d2e31f 100644 --- a/packages/crypto/build/bundles.js +++ b/packages/crypto/build/bundles.js @@ -13,4 +13,10 @@ esbuild.build({ format : 'iife', globalName : 'Web5Crypto', outfile : 'dist/browser.js', +}); + +esbuild.build({ + ...browserConfig, + entryPoints : ['./src/utils.ts'], + outfile : 'dist/utils.js' }); \ No newline at end of file diff --git a/packages/crypto/build/esbuild-browser-config.cjs b/packages/crypto/build/esbuild-browser-config.cjs index ae37c97f0..8fd899321 100644 --- a/packages/crypto/build/esbuild-browser-config.cjs +++ b/packages/crypto/build/esbuild-browser-config.cjs @@ -1,6 +1,6 @@ /** @type {import('esbuild').BuildOptions} */ module.exports = { - entryPoints : ['./src/main.ts'], + entryPoints : ['./src/index.ts'], bundle : true, format : 'esm', sourcemap : true, @@ -10,4 +10,4 @@ module.exports = { define : { 'global': 'globalThis', }, -}; +}; \ No newline at end of file diff --git a/packages/crypto/karma.conf.cjs b/packages/crypto/karma.conf.cjs index 083f0c963..6b7407b2c 100644 --- a/packages/crypto/karma.conf.cjs +++ b/packages/crypto/karma.conf.cjs @@ -30,11 +30,13 @@ module.exports = function (config) { // available frameworks: https://www.npmjs.com/search?q=keywords:karma-adapter frameworks: ['mocha'], - // Increase Mocha's default timeout of 2 seconds to prevent timeouts during GitHub CI runs. client: { + // Increase Mocha's default timeout of 2 seconds to prevent timeouts during GitHub CI runs. mocha: { timeout: 10000 // 10 seconds - } + }, + // If an environment variable is defined, override the default test DWN URL. + testDwnUrl: process.env.TEST_DWN_URL, }, // list of files / patterns to load in the browser diff --git a/packages/crypto/package.json b/packages/crypto/package.json index 4f1150624..8e32c0fde 100644 --- a/packages/crypto/package.json +++ b/packages/crypto/package.json @@ -1,11 +1,11 @@ { - "name": "@tbd54566975/crypto", - "version": "0.8.0", + "name": "@web5/crypto", + "version": "0.2.0", "description": "TBD crypto library", "type": "module", - "main": "./dist/cjs/main.js", - "module": "./dist/esm/main.js", - "types": "./dist/types/main.d.ts", + "main": "./dist/cjs/index.js", + "module": "./dist/esm/index.js", + "types": "./dist/types/index.d.ts", "scripts": { "clean": "rimraf dist tests/compiled", "build:esm": "rimraf dist/esm dist/types && npx tsc -p tsconfig.json", @@ -46,15 +46,20 @@ ], "exports": { ".": { - "import": "./dist/esm/main.js", - "require": "./dist/cjs/main.js", - "types": "./dist/types/main.d.ts" + "types": "./dist/types/index.d.ts", + "import": "./dist/esm/index.js", + "require": "./dist/cjs/index.js" + }, + "./utils": { + "types": "./dist/types/utils.d.ts", + "import": "./dist/esm/utils.js", + "require": "./dist/cjs/utils.js" } }, "browser": { "node:crypto": false }, - "react-native": "./dist/esm/main.js", + "react-native": "./dist/esm/index.js", "keywords": [ "cryptography", "ed25519", @@ -68,27 +73,27 @@ "node": ">=18.0.0" }, "dependencies": { - "@noble/ciphers": "0.1.3", + "@noble/ciphers": "0.1.4", "@noble/curves": "1.1.0", "@noble/hashes": "1.3.1", - "@tbd54566975/common": "0.8.0", - "ed2curve": "0.3.0" + "@web5/common": "0.2.0" }, "devDependencies": { - "@types/chai": "4.3.0", + "@playwright/test": "1.36.2", + "@types/chai": "4.3.5", "@types/chai-as-promised": "7.1.5", "@types/ed2curve": "0.2.2", - "@types/eslint": "8.37.0", + "@types/eslint": "8.44.2", "@types/mocha": "10.0.1", "@types/sinon": "10.0.15", "@types/uuid": "9.0.1", - "@typescript-eslint/eslint-plugin": "5.59.0", - "@typescript-eslint/parser": "5.59.0", - "c8": "8.0.0", + "@typescript-eslint/eslint-plugin": "6.4.0", + "@typescript-eslint/parser": "6.4.0", + "c8": "8.0.1", "chai": "4.3.7", "chai-as-promised": "7.1.1", "esbuild": "0.16.17", - "eslint": "8.39.0", + "eslint": "8.47.0", "eslint-plugin-mocha": "10.1.0", "karma": "6.4.1", "karma-chai": "0.1.0", diff --git a/packages/crypto/src/algorithms-api/aes/base.ts b/packages/crypto/src/algorithms-api/aes/base.ts index 96b579e5d..ad29f93ea 100644 --- a/packages/crypto/src/algorithms-api/aes/base.ts +++ b/packages/crypto/src/algorithms-api/aes/base.ts @@ -1,9 +1,9 @@ -import type { Web5Crypto } from '../../types/index.js'; +import { universalTypeOf } from '@web5/common'; -import { universalTypeOf } from '@tbd54566975/common'; +import type { Web5Crypto } from '../../types/web5-crypto.js'; +import { checkRequiredProperty } from '../../utils.js'; import { CryptoAlgorithm } from '../crypto-algorithm.js'; -import { checkRequiredProperty } from '../../utils-new.js'; import { InvalidAccessError, OperationError } from '../errors.js'; export abstract class BaseAesAlgorithm extends CryptoAlgorithm { @@ -35,11 +35,11 @@ export abstract class BaseAesAlgorithm extends CryptoAlgorithm { keyUsages: Web5Crypto.KeyUsage[] }): Promise; - public override async deriveBits(): Promise { + public override async deriveBits(): Promise { throw new InvalidAccessError(`Requested operation 'deriveBits' is not valid for ${this.name} keys.`); } - public override async sign(): Promise { + public override async sign(): Promise { throw new InvalidAccessError(`Requested operation 'sign' is not valid for ${this.name} keys.`); } diff --git a/packages/crypto/src/algorithms-api/aes/ctr.ts b/packages/crypto/src/algorithms-api/aes/ctr.ts index 379b87ffe..18b2c958b 100644 --- a/packages/crypto/src/algorithms-api/aes/ctr.ts +++ b/packages/crypto/src/algorithms-api/aes/ctr.ts @@ -1,10 +1,10 @@ -import type { Web5Crypto } from '../../types/index.js'; +import { universalTypeOf } from '@web5/common'; -import { universalTypeOf } from '@tbd54566975/common'; +import type { Web5Crypto } from '../../types/web5-crypto.js'; import { BaseAesAlgorithm } from './base.js'; import { OperationError } from '../errors.js'; -import { checkRequiredProperty } from '../../utils-new.js'; +import { checkRequiredProperty } from '../../utils.js'; export abstract class BaseAesCtrAlgorithm extends BaseAesAlgorithm { @@ -21,9 +21,9 @@ export abstract class BaseAesCtrAlgorithm extends BaseAesAlgorithm { this.checkAlgorithmName({ algorithmName: algorithm.name }); // The algorithm object must contain a counter property. checkRequiredProperty({ property: 'counter', inObject: algorithm }); - // The counter must an ArrayBuffer, DataView, or TypedArray. - if (!(universalTypeOf(algorithm.counter) === 'ArrayBuffer' || ArrayBuffer.isView(algorithm.counter))) { - throw new TypeError(`Algorithm 'counter' is not of type: ArrayBuffer, DataView, or TypedArray.`); + // The counter must a Uint8Array. + if (!(universalTypeOf(algorithm.counter) === 'Uint8Array')) { + throw new TypeError(`Algorithm 'counter' is not of type: Uint8Array.`); } // The initial value of the counter block must be 16 bytes long (the AES block size). if (algorithm.counter.byteLength !== 16) { diff --git a/packages/crypto/src/algorithms-api/crypto-algorithm.ts b/packages/crypto/src/algorithms-api/crypto-algorithm.ts index f8f4154b6..7f962aaf9 100644 --- a/packages/crypto/src/algorithms-api/crypto-algorithm.ts +++ b/packages/crypto/src/algorithms-api/crypto-algorithm.ts @@ -1,4 +1,4 @@ -import type { Web5Crypto } from '../types/index.js'; +import type { Web5Crypto } from '../types/web5-crypto.js'; import { InvalidAccessError, NotSupportedError } from './errors.js'; @@ -19,7 +19,7 @@ export abstract class CryptoAlgorithm { }): void { const { algorithmName } = options; if (algorithmName === undefined) { - throw new TypeError(`Required argument missing: 'algorithmName'`); + throw new TypeError(`Required parameter missing: 'algorithmName'`); } if (algorithmName !== this.name) { throw new NotSupportedError(`Algorithm not supported: '${algorithmName}'`); @@ -40,7 +40,7 @@ export abstract class CryptoAlgorithm { }): void { const { keyAlgorithmName } = options; if (keyAlgorithmName === undefined) { - throw new TypeError(`Required argument missing: 'keyAlgorithmName'`); + throw new TypeError(`Required parameter missing: 'keyAlgorithmName'`); } if (keyAlgorithmName && keyAlgorithmName !== this.name) { throw new InvalidAccessError(`Algorithm '${this.name}' does not match the provided '${keyAlgorithmName}' key.`); @@ -53,7 +53,7 @@ export abstract class CryptoAlgorithm { }): void { const { keyType, allowedKeyType } = options; if (keyType === undefined || allowedKeyType === undefined) { - throw new TypeError(`One or more required arguments missing: 'keyType, allowedKeyType'`); + throw new TypeError(`One or more required parameters missing: 'keyType, allowedKeyType'`); } if (keyType && keyType !== allowedKeyType) { throw new InvalidAccessError(`Requested operation is not valid for the provided '${keyType}' key.`); @@ -66,7 +66,7 @@ export abstract class CryptoAlgorithm { }): void { const { keyUsages, allowedKeyUsages } = options; if (!(keyUsages && keyUsages.length > 0)) { - throw new TypeError(`required parameter was missing or empty: 'keyUsages'`); + throw new TypeError(`Required parameter missing or empty: 'keyUsages'`); } const allowedUsages = (Array.isArray(allowedKeyUsages)) ? allowedKeyUsages : [...allowedKeyUsages.privateKey, ...allowedKeyUsages.publicKey]; if (!keyUsages.every(usage => allowedUsages.includes(usage))) { @@ -91,20 +91,20 @@ export abstract class CryptoAlgorithm { public abstract decrypt(options: { algorithm: Web5Crypto.AlgorithmIdentifier | Web5Crypto.AesCtrOptions | Web5Crypto.AesGcmOptions, key: Web5Crypto.CryptoKey, - data: BufferSource - }): Promise; + data: Uint8Array + }): Promise; public abstract deriveBits(options: { algorithm: Web5Crypto.AlgorithmIdentifier | Web5Crypto.EcdhDeriveKeyOptions, baseKey: Web5Crypto.CryptoKey, length: number | null - }): Promise; + }): Promise; public abstract encrypt(options: { algorithm: Web5Crypto.AlgorithmIdentifier | Web5Crypto.AesCtrOptions | Web5Crypto.AesGcmOptions, key: Web5Crypto.CryptoKey, - data: BufferSource - }): Promise; + data: Uint8Array + }): Promise; public abstract generateKey(options: { algorithm: Partial, @@ -115,13 +115,13 @@ export abstract class CryptoAlgorithm { public abstract sign(options: { algorithm: Web5Crypto.AlgorithmIdentifier | Web5Crypto.EcdsaOptions | Web5Crypto.EdDsaOptions, key: Web5Crypto.CryptoKey, - data: BufferSource - }): Promise; + data: Uint8Array + }): Promise; public abstract verify(options: { algorithm: Web5Crypto.AlgorithmIdentifier | Web5Crypto.EcdsaOptions | Web5Crypto.EdDsaOptions, key: Web5Crypto.CryptoKey, - signature: ArrayBuffer, - data: BufferSource + signature: Uint8Array, + data: Uint8Array }): Promise; } \ No newline at end of file diff --git a/packages/crypto/src/algorithms-api/crypto-key.ts b/packages/crypto/src/algorithms-api/crypto-key.ts index 8ffe3fec4..91d2477dc 100644 --- a/packages/crypto/src/algorithms-api/crypto-key.ts +++ b/packages/crypto/src/algorithms-api/crypto-key.ts @@ -1,16 +1,16 @@ -import type { Web5Crypto } from '../types/index.js'; +import type { Web5Crypto } from '../types/web5-crypto.js'; export class CryptoKey implements Web5Crypto.CryptoKey { public algorithm: Web5Crypto.GenerateKeyOptions; public extractable: boolean; - public handle: ArrayBuffer; + public material: Uint8Array; public type: Web5Crypto.KeyType; public usages: Web5Crypto.KeyUsage[]; - constructor (algorithm: Web5Crypto.GenerateKeyOptions, extractable: boolean, handle: ArrayBuffer, type: Web5Crypto.KeyType, usages: Web5Crypto.KeyUsage[]) { + constructor (algorithm: Web5Crypto.GenerateKeyOptions, extractable: boolean, material: Uint8Array, type: Web5Crypto.KeyType, usages: Web5Crypto.KeyUsage[]) { this.algorithm = algorithm; this.extractable = extractable; - this.handle = handle; + this.material = material; this.type = type; this.usages = usages; @@ -46,10 +46,10 @@ export class CryptoKey implements Web5Crypto.CryptoKey { // this is the "key material" used internally // it is not enumerable, but we need it to be // accessible by algorithm implementations - handle: { + material: { enumerable : false, writable : false, - value : handle + value : material } }); } diff --git a/packages/crypto/src/algorithms-api/ec/base.ts b/packages/crypto/src/algorithms-api/ec/base.ts index 2943034cd..de47f285d 100644 --- a/packages/crypto/src/algorithms-api/ec/base.ts +++ b/packages/crypto/src/algorithms-api/ec/base.ts @@ -1,8 +1,8 @@ -import type { Web5Crypto } from '../../types/index.js'; +import type { Web5Crypto } from '../../types/web5-crypto.js'; import { InvalidAccessError } from '../errors.js'; import { CryptoAlgorithm } from '../crypto-algorithm.js'; -import { checkValidProperty, checkRequiredProperty } from '../../utils-new.js'; +import { checkValidProperty, checkRequiredProperty } from '../../utils.js'; export abstract class BaseEllipticCurveAlgorithm extends CryptoAlgorithm { @@ -23,11 +23,11 @@ export abstract class BaseEllipticCurveAlgorithm extends CryptoAlgorithm { this.checkKeyUsages({ keyUsages, allowedKeyUsages: this.keyUsages }); } - public override async decrypt(): Promise { + public override async decrypt(): Promise { throw new InvalidAccessError(`Requested operation 'decrypt' is not valid for ${this.name} keys.`); } - public override async encrypt(): Promise { + public override async encrypt(): Promise { throw new InvalidAccessError(`Requested operation 'encrypt' is not valid for ${this.name} keys.`); } diff --git a/packages/crypto/src/algorithms-api/ec/ecdh.ts b/packages/crypto/src/algorithms-api/ec/ecdh.ts index ca8eb3b53..4667c3830 100644 --- a/packages/crypto/src/algorithms-api/ec/ecdh.ts +++ b/packages/crypto/src/algorithms-api/ec/ecdh.ts @@ -1,8 +1,8 @@ -import type { Web5Crypto } from '../../types/index.js'; +import type { Web5Crypto } from '../../types/web5-crypto.js'; import { InvalidAccessError } from '../errors.js'; import { BaseEllipticCurveAlgorithm } from './base.js'; -import { checkRequiredProperty } from '../../utils-new.js'; +import { checkRequiredProperty } from '../../utils.js'; export abstract class BaseEcdhAlgorithm extends BaseEllipticCurveAlgorithm { @@ -43,7 +43,7 @@ export abstract class BaseEcdhAlgorithm extends BaseEllipticCurveAlgorithm { } } - public override async sign(): Promise { + public override async sign(): Promise { throw new InvalidAccessError(`Requested operation 'sign' is not valid for ${this.name} keys.`); } diff --git a/packages/crypto/src/algorithms-api/ec/ecdsa.ts b/packages/crypto/src/algorithms-api/ec/ecdsa.ts index 63d1d8fe7..cfec1b22c 100644 --- a/packages/crypto/src/algorithms-api/ec/ecdsa.ts +++ b/packages/crypto/src/algorithms-api/ec/ecdsa.ts @@ -1,8 +1,8 @@ -import type { Web5Crypto } from '../../types/index.js'; +import type { Web5Crypto } from '../../types/web5-crypto.js'; import { InvalidAccessError } from '../errors.js'; import { BaseEllipticCurveAlgorithm } from './base.js'; -import { checkValidProperty, checkRequiredProperty } from '../../utils-new.js'; +import { checkValidProperty, checkRequiredProperty } from '../../utils.js'; export abstract class BaseEcdsaAlgorithm extends BaseEllipticCurveAlgorithm { @@ -27,11 +27,11 @@ export abstract class BaseEcdsaAlgorithm extends BaseEllipticCurveAlgorithm { checkValidProperty({ property: algorithm.hash, allowedProperties: this.hashAlgorithms }); } - public override async deriveBits(): Promise { + public override async deriveBits(): Promise { throw new InvalidAccessError(`Requested operation 'deriveBits' is not valid for ${this.name} keys.`); } - public abstract sign(options: { algorithm: Web5Crypto.EcdsaOptions; key: Web5Crypto.CryptoKey; data: BufferSource; }): Promise; + public abstract sign(options: { algorithm: Web5Crypto.EcdsaOptions; key: Web5Crypto.CryptoKey; data: Uint8Array; }): Promise; - public abstract verify(options: { algorithm: Web5Crypto.EcdsaOptions; key: Web5Crypto.CryptoKey; signature: ArrayBuffer; data: BufferSource; }): Promise; + public abstract verify(options: { algorithm: Web5Crypto.EcdsaOptions; key: Web5Crypto.CryptoKey; signature: Uint8Array; data: Uint8Array; }): Promise; } \ No newline at end of file diff --git a/packages/crypto/src/algorithms-api/ec/eddsa.ts b/packages/crypto/src/algorithms-api/ec/eddsa.ts index b98f8e83a..75f302221 100644 --- a/packages/crypto/src/algorithms-api/ec/eddsa.ts +++ b/packages/crypto/src/algorithms-api/ec/eddsa.ts @@ -1,4 +1,4 @@ -import type { Web5Crypto } from '../../types/index.js'; +import type { Web5Crypto } from '../../types/web5-crypto.js'; import { InvalidAccessError } from '../errors.js'; import { BaseEllipticCurveAlgorithm } from './base.js'; @@ -20,11 +20,11 @@ export abstract class BaseEdDsaAlgorithm extends BaseEllipticCurveAlgorithm { this.checkAlgorithmName({ algorithmName: algorithm.name }); } - public override async deriveBits(): Promise { + public override async deriveBits(): Promise { throw new InvalidAccessError(`Requested operation 'deriveBits' is not valid for ${this.name} keys.`); } - public abstract sign(options: { algorithm: Web5Crypto.EdDsaOptions; key: Web5Crypto.CryptoKey; data: BufferSource; }): Promise; + public abstract sign(options: { algorithm: Web5Crypto.EdDsaOptions; key: Web5Crypto.CryptoKey; data: Uint8Array; }): Promise; - public abstract verify(options: { algorithm: Web5Crypto.EdDsaOptions; key: Web5Crypto.CryptoKey; signature: ArrayBuffer; data: BufferSource; }): Promise; + public abstract verify(options: { algorithm: Web5Crypto.EdDsaOptions; key: Web5Crypto.CryptoKey; signature: Uint8Array; data: Uint8Array; }): Promise; } \ No newline at end of file diff --git a/packages/crypto/src/crypto-algorithms/aes-ctr.ts b/packages/crypto/src/crypto-algorithms/aes-ctr.ts index 7b2719061..8567f830f 100644 --- a/packages/crypto/src/crypto-algorithms/aes-ctr.ts +++ b/packages/crypto/src/crypto-algorithms/aes-ctr.ts @@ -1,6 +1,6 @@ -import type { Web5Crypto } from '../types/index.js'; +import { universalTypeOf } from '@web5/common'; -import { universalTypeOf } from '@tbd54566975/common'; +import type { Web5Crypto } from '../types/web5-crypto.js'; import { AesCtr } from '../crypto-primitives/index.js'; import { BaseAesCtrAlgorithm, CryptoKey } from '../algorithms-api/index.js'; @@ -9,8 +9,8 @@ export class AesCtrAlgorithm extends BaseAesCtrAlgorithm { public async decrypt(options: { algorithm: Web5Crypto.AesCtrOptions, key: Web5Crypto.CryptoKey, - data: BufferSource - }): Promise { + data: Uint8Array + }): Promise { const { algorithm, key, data } = options; this.checkAlgorithmOptions({ algorithm, key }); @@ -20,7 +20,7 @@ export class AesCtrAlgorithm extends BaseAesCtrAlgorithm { const plaintext = AesCtr.decrypt({ counter : algorithm.counter, data : data, - key : key.handle, + key : key.material, length : algorithm.length }); @@ -30,8 +30,8 @@ export class AesCtrAlgorithm extends BaseAesCtrAlgorithm { public async encrypt(options: { algorithm: Web5Crypto.AesCtrOptions, key: Web5Crypto.CryptoKey, - data: BufferSource - }): Promise { + data: Uint8Array + }): Promise { const { algorithm, key, data } = options; this.checkAlgorithmOptions({ algorithm, key }); @@ -41,7 +41,7 @@ export class AesCtrAlgorithm extends BaseAesCtrAlgorithm { const ciphertext = AesCtr.encrypt({ counter : algorithm.counter, data : data, - key : key.handle, + key : key.material, length : algorithm.length }); @@ -59,7 +59,7 @@ export class AesCtrAlgorithm extends BaseAesCtrAlgorithm { const secretKey = await AesCtr.generateKey({ length: algorithm.length }); - if (universalTypeOf(secretKey) !== 'ArrayBuffer') { + if (universalTypeOf(secretKey) !== 'Uint8Array') { throw new Error('Operation failed to generate key.'); } diff --git a/packages/crypto/src/crypto-algorithms/ecdh.ts b/packages/crypto/src/crypto-algorithms/ecdh.ts index 30d6eb155..a87fa67be 100644 --- a/packages/crypto/src/crypto-algorithms/ecdh.ts +++ b/packages/crypto/src/crypto-algorithms/ecdh.ts @@ -1,6 +1,7 @@ -import type { BufferKeyPair, Web5Crypto } from '../types/index.js'; +import type { Web5Crypto } from '../types/web5-crypto.js'; +import type { BytesKeyPair } from '../types/crypto-key.js'; -import { isBufferKeyPair } from '../utils-new.js'; +import { isBytesKeyPair } from '../utils.js'; import { Secp256k1, X25519 } from '../crypto-primitives/index.js'; import { CryptoKey, BaseEcdhAlgorithm, OperationError } from '../algorithms-api/index.js'; @@ -11,7 +12,7 @@ export class EcdhAlgorithm extends BaseEcdhAlgorithm { algorithm: Web5Crypto.EcdhDeriveKeyOptions, baseKey: Web5Crypto.CryptoKey, length: number | null - }): Promise { + }): Promise { const { algorithm, baseKey, length } = options; this.checkAlgorithmOptions({ algorithm, baseKey }); @@ -20,15 +21,15 @@ export class EcdhAlgorithm extends BaseEcdhAlgorithm { // The public key must be allowed to be used for deriveBits operations. this.checkKeyUsages({ keyUsages: ['deriveBits'], allowedKeyUsages: algorithm.publicKey.usages }); - let sharedSecret: ArrayBuffer; + let sharedSecret: Uint8Array; const ownKeyAlgorithm = baseKey.algorithm as Web5Crypto.EcGenerateKeyOptions; // Type guard. switch (ownKeyAlgorithm.namedCurve) { case 'secp256k1': { - const ownPrivateKey = baseKey.handle; - const otherPartyPublicKey = algorithm.publicKey.handle; + const ownPrivateKey = baseKey.material; + const otherPartyPublicKey = algorithm.publicKey.material; sharedSecret = await Secp256k1.sharedSecret({ privateKey : ownPrivateKey, publicKey : otherPartyPublicKey @@ -37,8 +38,8 @@ export class EcdhAlgorithm extends BaseEcdhAlgorithm { } case 'X25519': { - const ownPrivateKey = baseKey.handle; - const otherPartyPublicKey = algorithm.publicKey.handle; + const ownPrivateKey = baseKey.material; + const otherPartyPublicKey = algorithm.publicKey.material; sharedSecret = await X25519.sharedSecret({ privateKey : ownPrivateKey, publicKey : otherPartyPublicKey @@ -80,7 +81,7 @@ export class EcdhAlgorithm extends BaseEcdhAlgorithm { this.checkGenerateKey({ algorithm, keyUsages }); - let keyPair: BufferKeyPair | undefined; + let keyPair: BytesKeyPair | undefined; let cryptoKeyPair: Web5Crypto.CryptoKeyPair; switch (algorithm.namedCurve) { @@ -100,7 +101,7 @@ export class EcdhAlgorithm extends BaseEcdhAlgorithm { // Default case not needed because checkGenerateKey() already validates the specified namedCurve is supported. } - if (!isBufferKeyPair(keyPair)) { + if (!isBytesKeyPair(keyPair)) { throw new Error('Operation failed to generate key pair.'); } diff --git a/packages/crypto/src/crypto-algorithms/ecdsa.ts b/packages/crypto/src/crypto-algorithms/ecdsa.ts index c661864fd..828a42a6a 100644 --- a/packages/crypto/src/crypto-algorithms/ecdsa.ts +++ b/packages/crypto/src/crypto-algorithms/ecdsa.ts @@ -1,6 +1,7 @@ -import type { BufferKeyPair, Web5Crypto } from '../types/index.js'; +import type { Web5Crypto } from '../types/web5-crypto.js'; +import type { BytesKeyPair } from '../types/crypto-key.js'; -import { isBufferKeyPair } from '../utils-new.js'; +import { isBytesKeyPair } from '../utils.js'; import { Secp256k1 } from '../crypto-primitives/index.js'; import { CryptoKey, BaseEcdsaAlgorithm } from '../algorithms-api/index.js'; export class EcdsaAlgorithm extends BaseEcdsaAlgorithm { @@ -16,7 +17,7 @@ export class EcdsaAlgorithm extends BaseEcdsaAlgorithm { this.checkGenerateKey({ algorithm, keyUsages }); - let keyPair: BufferKeyPair | undefined; + let keyPair: BytesKeyPair | undefined; let cryptoKeyPair: Web5Crypto.CryptoKeyPair; switch (algorithm.namedCurve) { @@ -29,7 +30,7 @@ export class EcdsaAlgorithm extends BaseEcdsaAlgorithm { // Default case not needed because checkGenerateKey() already validates the specified namedCurve is supported. } - if (!isBufferKeyPair(keyPair)) { + if (!isBytesKeyPair(keyPair)) { throw new Error('Operation failed to generate key pair.'); } @@ -44,8 +45,8 @@ export class EcdsaAlgorithm extends BaseEcdsaAlgorithm { public async sign(options: { algorithm: Web5Crypto.EcdsaOptions, key: Web5Crypto.CryptoKey, - data: BufferSource - }): Promise { + data: Uint8Array + }): Promise { const { algorithm, key, data } = options; this.checkAlgorithmOptions({ algorithm }); @@ -56,14 +57,14 @@ export class EcdsaAlgorithm extends BaseEcdsaAlgorithm { // The key must be allowed to be used for sign operations. this.checkKeyUsages({ keyUsages: ['sign'], allowedKeyUsages: key.usages }); - let signature: ArrayBuffer; + let signature: Uint8Array; const keyAlgorithm = key.algorithm as Web5Crypto.EcdsaGenerateKeyOptions; // Type guard. switch (keyAlgorithm.namedCurve) { case 'secp256k1': { - signature = await Secp256k1.sign({ hash: algorithm.hash, key: key.handle, data }); + signature = await Secp256k1.sign({ hash: algorithm.hash, key: key.material, data }); break; } @@ -77,8 +78,8 @@ export class EcdsaAlgorithm extends BaseEcdsaAlgorithm { public async verify(options: { algorithm: Web5Crypto.EcdsaOptions; key: Web5Crypto.CryptoKey; - signature: ArrayBuffer; - data: BufferSource; + signature: Uint8Array; + data: Uint8Array; }): Promise { const { algorithm, key, signature, data } = options; @@ -97,7 +98,7 @@ export class EcdsaAlgorithm extends BaseEcdsaAlgorithm { switch (keyAlgorithm.namedCurve) { case 'secp256k1': { - isValid = await Secp256k1.verify({ hash: algorithm.hash, key: key.handle, signature, data }); + isValid = await Secp256k1.verify({ hash: algorithm.hash, key: key.material, signature, data }); break; } diff --git a/packages/crypto/src/crypto-algorithms/eddsa.ts b/packages/crypto/src/crypto-algorithms/eddsa.ts index 2309d1d49..1932443ba 100644 --- a/packages/crypto/src/crypto-algorithms/eddsa.ts +++ b/packages/crypto/src/crypto-algorithms/eddsa.ts @@ -1,6 +1,7 @@ -import type { BufferKeyPair, Web5Crypto } from '../types/index.js'; +import type { Web5Crypto } from '../types/web5-crypto.js'; +import type { BytesKeyPair } from '../types/crypto-key.js'; -import { isBufferKeyPair } from '../utils-new.js'; +import { isBytesKeyPair } from '../utils.js'; import { Ed25519 } from '../crypto-primitives/index.js'; import { CryptoKey, BaseEdDsaAlgorithm } from '../algorithms-api/index.js'; @@ -16,7 +17,7 @@ export class EdDsaAlgorithm extends BaseEdDsaAlgorithm { this.checkGenerateKey({ algorithm, keyUsages }); - let keyPair: BufferKeyPair | undefined; + let keyPair: BytesKeyPair | undefined; let cryptoKeyPair: Web5Crypto.CryptoKeyPair; switch (algorithm.namedCurve) { @@ -28,7 +29,7 @@ export class EdDsaAlgorithm extends BaseEdDsaAlgorithm { // Default case not needed because checkGenerateKey() already validates the specified namedCurve is supported. } - if (!isBufferKeyPair(keyPair)) { + if (!isBytesKeyPair(keyPair)) { throw new Error('Operation failed to generate key pair.'); } @@ -43,8 +44,8 @@ export class EdDsaAlgorithm extends BaseEdDsaAlgorithm { public async sign(options: { algorithm: Web5Crypto.EdDsaOptions, key: Web5Crypto.CryptoKey, - data: BufferSource - }): Promise { + data: Uint8Array + }): Promise { const { algorithm, key, data } = options; this.checkAlgorithmOptions({ algorithm }); @@ -55,14 +56,14 @@ export class EdDsaAlgorithm extends BaseEdDsaAlgorithm { // The key must be allowed to be used for sign operations. this.checkKeyUsages({ keyUsages: ['sign'], allowedKeyUsages: key.usages }); - let signature: ArrayBuffer; + let signature: Uint8Array; const keyAlgorithm = key.algorithm as Web5Crypto.EdDsaGenerateKeyOptions; // Type guard. switch (keyAlgorithm.namedCurve) { case 'Ed25519': { - signature = await Ed25519.sign({ key: key.handle, data }); + signature = await Ed25519.sign({ key: key.material, data }); break; } @@ -76,8 +77,8 @@ export class EdDsaAlgorithm extends BaseEdDsaAlgorithm { public async verify(options: { algorithm: Web5Crypto.EdDsaOptions; key: Web5Crypto.CryptoKey; - signature: ArrayBuffer; - data: BufferSource; + signature: Uint8Array; + data: Uint8Array; }): Promise { const { algorithm, key, signature, data } = options; @@ -96,7 +97,7 @@ export class EdDsaAlgorithm extends BaseEdDsaAlgorithm { switch (keyAlgorithm.namedCurve) { case 'Ed25519': { - isValid = await Ed25519.verify({ key: key.handle, signature, data }); + isValid = await Ed25519.verify({ key: key.material, signature, data }); break; } diff --git a/packages/crypto/src/crypto-primitives/aes-ctr.ts b/packages/crypto/src/crypto-primitives/aes-ctr.ts index 08db00555..f218bdf63 100644 --- a/packages/crypto/src/crypto-primitives/aes-ctr.ts +++ b/packages/crypto/src/crypto-primitives/aes-ctr.ts @@ -6,7 +6,7 @@ import { crypto } from '@noble/hashes/crypto'; * operations. The class uses the Web Crypto API for cryptographic operations. * * All methods of this class are asynchronous and return Promises. They all - * use the ArrayBuffer type for keys and data, providing a consistent + * use the Uint8Array type for keys and data, providing a consistent * interface for working with binary data. * * Example usage: @@ -39,25 +39,28 @@ export class AesCtr { * @param options.data - The data to decrypt. * @param options.key - The key to use for decryption. * @param options.length - The length of the counter block in bits. - * @returns A Promise that resolves to the decrypted data as an ArrayBuffer. + * @returns A Promise that resolves to the decrypted data as a Uint8Array. */ public static async decrypt(options: { - counter: BufferSource, - data: BufferSource, - key: ArrayBuffer, + counter: Uint8Array, + data: Uint8Array, + key: Uint8Array, length: number - }): Promise { + }): Promise { const { counter, data, key, length } = options; const webCryptoKey = await this.importKey(key); - const ciphertext = await crypto.subtle.decrypt( + const plaintextBuffer = await crypto.subtle.decrypt( { name: 'AES-CTR', counter, length }, webCryptoKey, data ); - return ciphertext; + // Convert from ArrayBuffer to Uint8Array. + const plaintext = new Uint8Array(plaintextBuffer); + + return plaintext; } /** @@ -68,43 +71,46 @@ export class AesCtr { * @param options.data - The data to encrypt. * @param options.key - The key to use for encryption. * @param options.length - The length of the counter block in bits. - * @returns A Promise that resolves to the encrypted data as an ArrayBuffer. + * @returns A Promise that resolves to the encrypted data as a Uint8Array. */ public static async encrypt(options: { - counter: BufferSource, - data: BufferSource, - key: ArrayBuffer, + counter: Uint8Array, + data: Uint8Array, + key: Uint8Array, length: number - }): Promise { + }): Promise { const { counter, data, key, length } = options; const webCryptoKey = await this.importKey(key); - const plaintext = await crypto.subtle.encrypt( + const ciphertextBuffer = await crypto.subtle.encrypt( { name: 'AES-CTR', counter, length }, webCryptoKey, data ); - return plaintext; + // Convert from ArrayBuffer to Uint8Array. + const ciphertext = new Uint8Array(ciphertextBuffer); + + return ciphertext; } /** * Generates an AES key of a given length. * * @param length - The length of the key in bits. - * @returns A Promise that resolves to the generated key as an ArrayBuffer. + * @returns A Promise that resolves to the generated key as a Uint8Array. */ public static async generateKey(options: { length: number - }): Promise { + }): Promise { const { length } = options; // Generate the secret key. const lengthInBytes = length / 8; const secretKey = crypto.getRandomValues(new Uint8Array(lengthInBytes)); - return secretKey.buffer; + return secretKey; } /** @@ -113,10 +119,10 @@ export class AesCtr { * @param key - The raw key material. * @returns A Promise that resolves to a CryptoKey. */ - private static async importKey(key: ArrayBuffer): Promise { + private static async importKey(key: Uint8Array): Promise { return crypto.subtle.importKey( 'raw', - key, + key.buffer, { name: 'AES-CTR', length: key.byteLength * 8 }, true, ['encrypt', 'decrypt'] diff --git a/packages/crypto/src/crypto-primitives/aes-gcm.ts b/packages/crypto/src/crypto-primitives/aes-gcm.ts index f3e19fdf7..852bb15e7 100644 --- a/packages/crypto/src/crypto-primitives/aes-gcm.ts +++ b/packages/crypto/src/crypto-primitives/aes-gcm.ts @@ -7,7 +7,7 @@ import { crypto } from '@noble/hashes/crypto'; * cryptographic operations. * * All methods of this class are asynchronous and return Promises. They all - * use the ArrayBuffer type for keys and data, providing a consistent + * use the Uint8Array type for keys and data, providing a consistent * interface for working with binary data. * * Example usage: @@ -41,26 +41,30 @@ export class AesGcm { * @param options.iv - A unique initialization vector. * @param options.key - The key to use for decryption. * @param options.tagLength - This size of the authentication tag generated in bits. - * @returns A Promise that resolves to the decrypted data as an ArrayBuffer. + * @returns A Promise that resolves to the decrypted data as a Uint8Array. */ public static async decrypt(options: { - additionalData?: BufferSource, - data: BufferSource, - iv: BufferSource, - key: ArrayBuffer, + additionalData?: Uint8Array, + data: Uint8Array, + iv: Uint8Array, + key: Uint8Array, tagLength?: number - }): Promise { + }): Promise { const { additionalData, data, iv, key, tagLength } = options; const webCryptoKey = await this.importKey(key); + // Web browsers throw an error if additionalData is undefined. const algorithm = (additionalData === undefined) ? { name: 'AES-GCM', iv, tagLength } : { name: 'AES-GCM', additionalData, iv, tagLength }; - const ciphertext = await crypto.subtle.decrypt(algorithm, webCryptoKey, data); + const plaintextBuffer = await crypto.subtle.decrypt(algorithm, webCryptoKey, data); - return ciphertext; + // Convert from ArrayBuffer to Uint8Array. + const plaintext = new Uint8Array(plaintextBuffer); + + return plaintext; } /** @@ -72,44 +76,48 @@ export class AesGcm { * @param options.iv - A unique initialization vector. * @param options.key - The key to use for decryption. * @param options.tagLength - This size of the authentication tag generated in bits. - * @returns A Promise that resolves to the encrypted data as an ArrayBuffer. + * @returns A Promise that resolves to the encrypted data as a Uint8Array. */ public static async encrypt(options: { - additionalData?: BufferSource, - data: BufferSource, - iv: BufferSource, - key: ArrayBuffer, + additionalData?: Uint8Array, + data: Uint8Array, + iv: Uint8Array, + key: Uint8Array, tagLength?: number - }): Promise { + }): Promise { const { additionalData, data, iv, key, tagLength } = options; const webCryptoKey = await this.importKey(key); + // Web browsers throw an error if additionalData is undefined. const algorithm = (additionalData === undefined) ? { name: 'AES-GCM', iv, tagLength } : { name: 'AES-GCM', additionalData, iv, tagLength }; - const plaintext = await crypto.subtle.encrypt(algorithm, webCryptoKey, data); + const ciphertextBuffer = await crypto.subtle.encrypt(algorithm, webCryptoKey, data); - return plaintext; + // Convert from ArrayBuffer to Uint8Array. + const ciphertext = new Uint8Array(ciphertextBuffer); + + return ciphertext; } /** * Generates an AES key of a given length. * * @param length - The length of the key in bits. - * @returns A Promise that resolves to the generated key as an ArrayBuffer. + * @returns A Promise that resolves to the generated key as a Uint8Array. */ public static async generateKey(options: { length: number - }): Promise { + }): Promise { const { length } = options; // Generate the secret key. const lengthInBytes = length / 8; const secretKey = crypto.getRandomValues(new Uint8Array(lengthInBytes)); - return secretKey.buffer; + return secretKey; } /** @@ -118,10 +126,10 @@ export class AesGcm { * @param key - The raw key material. * @returns A Promise that resolves to a CryptoKey. */ - private static async importKey(key: ArrayBuffer): Promise { + private static async importKey(key: Uint8Array): Promise { return crypto.subtle.importKey( 'raw', - key, + key.buffer, { name: 'AES-GCM', length: key.byteLength * 8 }, true, ['encrypt', 'decrypt'] diff --git a/packages/crypto/src/crypto-primitives/concat-kdf.ts b/packages/crypto/src/crypto-primitives/concat-kdf.ts index b5debe003..20b739e2e 100644 --- a/packages/crypto/src/crypto-primitives/concat-kdf.ts +++ b/packages/crypto/src/crypto-primitives/concat-kdf.ts @@ -1,6 +1,6 @@ import { sha256 } from '@noble/hashes/sha256'; +import { Convert, universalTypeOf } from '@web5/common'; import { TypedArray, concatBytes } from '@noble/hashes/utils'; -import { Convert, universalTypeOf } from '@tbd54566975/common'; import { NotSupportedError } from '../algorithms-api/errors.js'; @@ -14,14 +14,14 @@ export type ConcatKdfOtherInfo = { * Information related to party U (initiator) involved in the key agreement * transaction. It could be a public key, identifier, or any other data. */ - partyUInfo: ArrayBuffer | string | TypedArray; + partyUInfo: string | TypedArray; /** * Information related to party V (receiver) involved in the key * agreement transaction. Similar to partyUInfo, it could be a * public key, identifier, etc. */ - partyVInfo: ArrayBuffer | string | TypedArray; + partyVInfo: string | TypedArray; /** * Optional field. It is usually used to ensure the uniqueness of the @@ -37,7 +37,7 @@ export type ConcatKdfOtherInfo = { * It is a secret value agreed upon by the entities who are party * to the key agreement. */ - suppPrivInfo?: ArrayBuffer | string | TypedArray; + suppPrivInfo?: string | TypedArray; } /** @@ -79,15 +79,15 @@ export class ConcatKdf { * @param options.keyDataLen - The desired length of the derived key in bits. * @param options.sharedSecret - The shared secret key to derive from. * @param options.otherInfo - Additional public information to use in key derivation. - * @returns The derived key as an ArrayBuffer. + * @returns The derived key as a Uint8Array. * * @throws {NotSupportedError} If the keyDataLen would require multiple rounds. */ public static async deriveKey(options: { keyDataLen: number; otherInfo: ConcatKdfOtherInfo, - sharedSecret: ArrayBuffer, - }): Promise { + sharedSecret: Uint8Array, + }): Promise { const { keyDataLen, sharedSecret } = options; // RFC 7518 Section 4.6.2 specifies using SHA-256 for ECDH key agreement: @@ -106,18 +106,15 @@ export class ConcatKdf { const counter = new Uint8Array(4); new DataView(counter.buffer).setUint32(0, roundCount); - // Specify input parameter Z, which is the shared secret output of ECDH. - const sharedSecretU8A = new Uint8Array(sharedSecret); - // Compute the OtherInfo bit-string. const otherInfo = ConcatKdf.computeOtherInfo(options.otherInfo); // Compute K(i) = H(counter || Z || OtherInfo) - // return concatBytes(counter, sharedSecretU8A, otherInfo); - const derivedKeyingMaterial = sha256(concatBytes(counter, sharedSecretU8A, otherInfo)); + // return concatBytes(counter, sharedSecretZ, otherInfo); + const derivedKeyingMaterial = sha256(concatBytes(counter, sharedSecret, otherInfo)); // Return the bit string of derived keying material of length keyDataLen bits. - return derivedKeyingMaterial.buffer.slice(0, keyDataLen / 8); + return derivedKeyingMaterial.slice(0, keyDataLen / 8); } /** diff --git a/packages/crypto/src/crypto-primitives/ed25519.ts b/packages/crypto/src/crypto-primitives/ed25519.ts index 516d06419..2ba767718 100644 --- a/packages/crypto/src/crypto-primitives/ed25519.ts +++ b/packages/crypto/src/crypto-primitives/ed25519.ts @@ -1,7 +1,6 @@ -import type { BufferKeyPair } from '../types/index.js'; +import type { BytesKeyPair } from '../types/crypto-key.js'; -import { Convert } from '@tbd54566975/common'; -import { ed25519 } from '@noble/curves/ed25519'; +import { ed25519, edwardsToMontgomeryPub, edwardsToMontgomeryPriv } from '@noble/curves/ed25519'; /** * The `Ed25519` class provides an interface for generating Ed25519 key pairs, @@ -10,7 +9,7 @@ import { ed25519 } from '@noble/curves/ed25519'; * The class uses the '@noble/curves' package for the cryptographic operations. * * The methods of this class are all asynchronous and return Promises. They all use - * the ArrayBuffer type for keys, signatures, and data, providing a consistent + * the Uint8Array type for keys, signatures, and data, providing a consistent * interface for working with binary data. * * Example usage: @@ -31,19 +30,73 @@ import { ed25519 } from '@noble/curves/ed25519'; * ``` */ export class Ed25519 { + + /** + * Converts an Ed25519 private key to its X25519 counterpart. + * + * Similar to the public key conversion, this method aids in transitioning + * from signing to encryption operations. By converting an Ed25519 private + * key to X25519 format, one can use the same key pair for both digital + * signatures and key exchange operations. + * + * @param options - The options for the conversion. + * @param options.privateKey - The Ed25519 private key to convert, represented as a Uint8Array. + * @returns A Promise that resolves to the X25519 private key as a Uint8Array. + */ + public static async convertPrivateKeyToX25519(options: { + privateKey: Uint8Array + }): Promise { + const { privateKey } = options; + + // Converts Ed25519 private key to X25519 private key. + const montgomeryPrivateKey = edwardsToMontgomeryPriv(privateKey); + + return montgomeryPrivateKey; + } + + /** + * Converts an Ed25519 public key to its X25519 counterpart. + * + * This method is useful when transitioning from signing to encryption + * operations, as Ed25519 and X25519 keys share the same mathematical + * foundation but serve different purposes. Ed25519 keys are used for + * digital signatures, while X25519 keys are used for key exchange in + * encryption protocols like Diffie-Hellman. + * + * @param options - The options for the conversion. + * @param options.publicKey - The Ed25519 public key to convert, represented as a Uint8Array. + * @returns A Promise that resolves to the X25519 public key as a Uint8Array. + */ + public static async convertPublicKeyToX25519(options: { + publicKey: Uint8Array + }): Promise { + const { publicKey } = options; + + // Verify Edwards public key is valid. + const isValid = await Ed25519.validatePublicKey({ key: publicKey }); + if (!isValid) { + throw new Error('Ed25519: Invalid public key.'); + } + + // Converts Ed25519 public key to X25519 public key. + const montgomeryPublicKey = edwardsToMontgomeryPub(publicKey); + + return montgomeryPublicKey; + } + /** * Generates an Ed25519 key pair. * - * @returns A Promise that resolves to an object containing the private and public keys as ArrayBuffers. + * @returns A Promise that resolves to an object containing the private and public keys as Uint8Array. */ - public static async generateKeyPair(): Promise { + public static async generateKeyPair(): Promise { // Generate the private key and compute its public key. const privateKey = ed25519.utils.randomPrivateKey(); const publicKey = ed25519.getPublicKey(privateKey); const keyPair = { - privateKey : privateKey.buffer, - publicKey : publicKey.buffer + privateKey : privateKey, + publicKey : publicKey }; return keyPair; @@ -54,18 +107,15 @@ export class Ed25519 { * * @param options - The options for the public key computation. * @param options.privateKey - The 32-byte private key from which to compute the public key. - * @returns A Promise that resolves to the computed 32-byte public key as an ArrayBuffer. + * @returns A Promise that resolves to the computed 32-byte public key as a Uint8Array. */ public static async getPublicKey(options: { - privateKey: ArrayBuffer - }): Promise { + privateKey: Uint8Array + }): Promise { let { privateKey } = options; - // Convert key material from ArrayBuffer to Uint8Array. - const privateKeyU8A = Convert.arrayBuffer(privateKey).toUint8Array(); - // Compute public key. - const publicKey = ed25519.getPublicKey(privateKeyU8A); + const publicKey = ed25519.getPublicKey(privateKey); return publicKey; } @@ -76,24 +126,55 @@ export class Ed25519 { * @param options - The options for the signing operation. * @param options.key - The private key to use for signing. * @param options.data - The data to sign. - * @returns A Promise that resolves to the signature as an ArrayBuffer. + * @returns A Promise that resolves to the signature as a Uint8Array. */ public static async sign(options: { - data: BufferSource, - key: ArrayBuffer - }): Promise { + data: Uint8Array, + key: Uint8Array + }): Promise { const { key, data } = options; - // Convert data from BufferSource to Uint8Array. - const dataU8A = Convert.bufferSource(data).toUint8Array(); + // Signature operation. + const signature = ed25519.sign(data, key); - // Convert private key material from ArrayBuffer to Uint8Array. - const privateKeyU8A = Convert.arrayBuffer(key).toUint8Array(); + return signature; + } - // Signature operation. - const signatureU8A = ed25519.sign(dataU8A, privateKeyU8A); + /** + * Validates a given public key to ensure that it corresponds to a + * valid point on the Ed25519 elliptic curve. + * + * This method decodes the Edwards points from the key bytes and + * asserts their validity on the curve. If the points are not valid, + * the method returns false. If the points are valid, the method + * returns true. + * + * Note: This method does not check whether the key corresponds to a + * known or authorized entity, or whether it has been compromised. + * It only checks the mathematical validity of the key. + * + * @param options - The options for the key validation. + * @param options.key - The key to validate, represented as a Uint8Array. + * @returns A Promise that resolves to a boolean indicating whether the key + * corresponds to a valid point on the Edwards curve. + */ + public static async validatePublicKey(options: { + key: Uint8Array + }): Promise { + const { key } = options; + + try { + // Decode Edwards points from key bytes. + const point = ed25519.ExtendedPoint.fromHex(key); + + // Check if points are on the Twisted Edwards curve. + point.assertValidity(); - return signatureU8A.buffer; + } catch(error: any) { + return false; + } + + return true; } /** @@ -106,23 +187,14 @@ export class Ed25519 { * @returns A Promise that resolves to a boolean indicating whether the signature is valid. */ public static async verify(options: { - data: BufferSource, - key: ArrayBuffer, - signature: ArrayBuffer + data: Uint8Array, + key: Uint8Array, + signature: Uint8Array }): Promise { const { key, signature, data } = options; - // Convert public key material from ArrayBuffer to Uint8Array. - const publicKeyU8A = Convert.arrayBuffer(key).toUint8Array(); - - // Convert signature from ArrayBuffer to Uint8Array. - const signatureU8A = Convert.arrayBuffer(signature).toUint8Array(); - - // Convert data from BufferSource to Uint8Array. - const dataU8A = Convert.bufferSource(data).toUint8Array(); - // Verify operation. - const isValid = ed25519.verify(signatureU8A, dataU8A, publicKeyU8A); + const isValid = ed25519.verify(signature, data, key); return isValid; } diff --git a/packages/crypto/src/crypto-primitives/index.ts b/packages/crypto/src/crypto-primitives/index.ts index 6bf83f66a..790070b1b 100644 --- a/packages/crypto/src/crypto-primitives/index.ts +++ b/packages/crypto/src/crypto-primitives/index.ts @@ -2,6 +2,7 @@ export * from './x25519.js'; export * from './aes-ctr.js'; export * from './aes-gcm.js'; export * from './ed25519.js'; +export * from './concat-kdf.js'; export * from './secp256k1.js'; export * from './xchacha20.js'; -export * from './concat-kdf.js'; \ No newline at end of file +export * from './xchacha20-poly1305.js'; \ No newline at end of file diff --git a/packages/crypto/src/crypto-primitives/secp256k1.ts b/packages/crypto/src/crypto-primitives/secp256k1.ts index 0c56dbdf9..2626eb4de 100644 --- a/packages/crypto/src/crypto-primitives/secp256k1.ts +++ b/packages/crypto/src/crypto-primitives/secp256k1.ts @@ -1,8 +1,8 @@ -import type { BufferKeyPair } from '../types/index.js'; +import type { BytesKeyPair } from '../types/crypto-key.js'; -import { Convert } from '@tbd54566975/common'; import { sha256 } from '@noble/hashes/sha256'; import { secp256k1 } from '@noble/curves/secp256k1'; +import { numberToBytesBE } from '@noble/curves/abstract/utils'; export type HashFunction = (data: Uint8Array) => Uint8Array; @@ -16,7 +16,7 @@ export type HashFunction = (data: Uint8Array) => Uint8Array; * for the signing and verification operations. * * The methods of this class are all asynchronous and return Promises. They all use - * the ArrayBuffer type for keys, signatures, and data, providing a consistent + * the Uint8Array type for keys, signatures, and data, providing a consistent * interface for working with binary data. * * Example usage: @@ -48,16 +48,50 @@ export class Secp256k1 { 'SHA-256': sha256 }; + /** + * Converts a public key between its compressed and uncompressed forms. + * + * Given a public key, this method can either compress or decompress it + * depending on the provided `compressedPublicKey` option. The conversion + * process involves decoding the Weierstrass points from the key bytes + * and then returning the key in the desired format. + * + * This is useful in scenarios where space is a consideration or when + * interfacing with systems that expect a specific public key format. + * + * @param options - The options for the public key conversion. + * @param options.publicKey - The original public key, represented as a Uint8Array. + * @param options.compressedPublicKey - A boolean indicating whether the output + * should be in compressed form. If true, the + * method returns the compressed form of the + * provided public key. If false, it returns + * the uncompressed form. + * + * @returns A Promise that resolves to the converted public key as a Uint8Array. + */ + public static async convertPublicKey(options: { + publicKey: Uint8Array, + compressedPublicKey: boolean + }): Promise { + let { publicKey, compressedPublicKey } = options; + + // Decode Weierstrass points from key bytes. + const point = secp256k1.ProjectivePoint.fromHex(publicKey); + + // Return either the compressed or uncompressed form of hte public key. + return point.toRawBytes(compressedPublicKey); + } + /** * Generates a secp256k1 key pair. * * @param options - Optional parameters for the key generation. * @param options.compressedPublicKey - If true, generates a compressed public key. Defaults to true. - * @returns A Promise that resolves to an object containing the private and public keys as ArrayBuffers. + * @returns A Promise that resolves to an object containing the private and public keys as Uint8Array. */ - public static async generateKeyPair( - options?: { compressedPublicKey?: boolean } - ): Promise { + public static async generateKeyPair(options?: { + compressedPublicKey?: boolean + }): Promise { let { compressedPublicKey } = options ?? { }; compressedPublicKey ??= true; // Default to compressed public key, matching the default of @noble/secp256k1. @@ -67,13 +101,53 @@ export class Secp256k1 { const publicKey = secp256k1.getPublicKey(privateKey, compressedPublicKey); const keyPair = { - privateKey : privateKey.buffer, - publicKey : publicKey.buffer + privateKey : privateKey, + publicKey : publicKey }; return keyPair; } + /** + * Returns the elliptic curve points (x and y coordinates) for a given secp256k1 key. + * + * In the case of a private key, the public key is first computed from the private key, + * then the x and y coordinates of the public key point on the elliptic curve are returned. + * + * In the case of a public key, the x and y coordinates of the key point on the elliptic + * curve are returned directly. + * + * The returned coordinates can be used to perform various operations on the elliptic curve, + * such as addition and multiplication of points, which can be used in various cryptographic + * schemes and protocols. + * + * @param options - The options for the operation. + * @param options.key - The key for which to get the elliptic curve points. + * Can be either a private key or a public key. + * The key should be passed as a Uint8Array. + * @returns A Promise that resolves to an object with properties 'x' and 'y', + * each being a Uint8Array representing the x and y coordinates of the key point on the elliptic curve. + */ + public static async getCurvePoints(options: { + key: Uint8Array + }): Promise<{ x: Uint8Array, y: Uint8Array }> { + let { key } = options; + + // If key is a private key, first compute the public key. + if (key.byteLength === 32) { + key = await Secp256k1.getPublicKey({ privateKey: key }); + } + + // Decode Weierstrass points from key bytes. + const point = secp256k1.ProjectivePoint.fromHex(key); + + // Get x- and y-coordinate values and convert to Uint8Array. + const x = numberToBytesBE(point.x, 32); + const y = numberToBytesBE(point.y, 32); + + return { x, y }; + } + /** * Computes the public key from a given private key. * If compressedPublicKey=true then the output is a 33-byte public key. @@ -82,20 +156,18 @@ export class Secp256k1 { * @param options - The options for the public key computation. * @param options.privateKey - The 32-byte private key from which to compute the public key. * @param options.compressedPublicKey - If true, returns a compressed public key. Defaults to true. - * @returns A Promise that resolves to the computed public key as an ArrayBuffer. + * @returns A Promise that resolves to the computed public key as a Uint8Array. */ - public static async getPublicKey( - options: { privateKey: ArrayBuffer, compressedPublicKey?: boolean } - ): Promise { + public static async getPublicKey(options: { + privateKey: Uint8Array, + compressedPublicKey?: boolean + }): Promise { let { privateKey, compressedPublicKey } = options; compressedPublicKey ??= true; // Default to compressed public key, matching the default of @noble/secp256k1. - // Convert key material from ArrayBuffer to Uint8Array. - const privateKeyU8A = Convert.arrayBuffer(privateKey).toUint8Array(); - // Compute public key. - const publicKey = secp256k1.getPublicKey(privateKeyU8A, compressedPublicKey); + const publicKey = secp256k1.getPublicKey(privateKey, compressedPublicKey); return publicKey; } @@ -116,21 +188,17 @@ export class Secp256k1 { */ public static async sharedSecret(options: { compressedSecret?: boolean, - privateKey: ArrayBuffer, - publicKey: ArrayBuffer - }): Promise { + privateKey: Uint8Array, + publicKey: Uint8Array + }): Promise { let { privateKey, publicKey } = options; - // Convert private and public key material from ArrayBuffer to Uint8Array. - const privateKeyU8A = Convert.arrayBuffer(privateKey).toUint8Array(); - const publicKeyU8A = Convert.arrayBuffer(publicKey).toUint8Array(); - // Compute the shared secret between the public and private keys. - const sharedSecret = secp256k1.getSharedSecret(privateKeyU8A, publicKeyU8A); + const sharedSecret = secp256k1.getSharedSecret(privateKey, publicKey); // Remove the leading byte that indicates the sign of the y-coordinate // of the point on the elliptic curve. See note above. - return sharedSecret.slice(1).buffer; + return sharedSecret.slice(1); } /** @@ -140,32 +208,85 @@ export class Secp256k1 { * @param options.data - The data to sign. * @param options.hash - The hash algorithm to use to generate a digest of the data. * @param options.key - The private key to use for signing. - * @returns A Promise that resolves to the signature as an ArrayBuffer. + * @returns A Promise that resolves to the signature as a Uint8Array. */ public static async sign(options: { - data: BufferSource, + data: Uint8Array, hash: string, - key: ArrayBuffer - }): Promise { + key: Uint8Array + }): Promise { const { data, hash, key } = options; - // Convert data from BufferSource to Uint8Array. - const dataU8A = Convert.bufferSource(data).toUint8Array(); - // Generate a digest of the data using the specified hash function. const hashFunction = this.hashAlgorithms[hash]; - const digest = hashFunction(dataU8A); - - // Convert private key material from ArrayBuffer to Uint8Array. - const privateKeyU8A = Convert.arrayBuffer(key).toUint8Array(); + const digest = hashFunction(data); // Signature operation returns a Signature instance with { r, s, recovery } properties. - const signatureObject = secp256k1.sign(digest, privateKeyU8A); + const signatureObject = secp256k1.sign(digest, key); // Convert Signature object to Uint8Array. - const signatureU8A = signatureObject.toCompactRawBytes(); + const signature = signatureObject.toCompactRawBytes(); - return signatureU8A.buffer; + return signature; + } + + /** + * Validates a given private key to ensure that it's a valid 32-byte number + * that is less than the secp256k1 curve's order. + * + * This method checks the byte length of the key and its numerical validity + * according to the secp256k1 curve's parameters. It doesn't verify whether + * the key corresponds to a known or authorized entity or whether it has + * been compromised. + * + * @param options - The options for the key validation. + * @param options.key - The private key to validate, represented as a Uint8Array. + * @returns A Promise that resolves to a boolean indicating whether the private + * key is a valid 32-byte number less than the secp256k1 curve's order. + */ + public static async validatePrivateKey(options: { + key: Uint8Array + }): Promise { + const { key } = options; + + return secp256k1.utils.isValidPrivateKey(key); + } + + /** + * Validates a given public key to ensure that it corresponds to a + * valid point on the secp256k1 elliptic curve. + * + * This method decodes the Weierstrass points from the key bytes and + * asserts their validity on the curve. If the points are not valid, + * the method returns false. If the points are valid, the method + * returns true. + * + * Note: This method does not check whether the key corresponds to a + * known or authorized entity, or whether it has been compromised. + * It only checks the mathematical validity of the key. + * + * @param options - The options for the key validation. + * @param options.key - The key to validate, represented as a Uint8Array. + * @returns A Promise that resolves to a boolean indicating whether the key + * corresponds to a valid point on the secp256k1 elliptic curve. + */ + public static async validatePublicKey(options: { + key: Uint8Array + }): Promise { + const { key } = options; + + try { + // Decode Weierstrass points from key bytes. + const point = secp256k1.ProjectivePoint.fromHex(key); + + // Check if points are on the Short Weierstrass curve. + point.assertValidity(); + + } catch(error: any) { + return false; + } + + return true; } /** @@ -179,28 +300,19 @@ export class Secp256k1 { * @returns A Promise that resolves to a boolean indicating whether the signature is valid. */ public static async verify(options: { - data: BufferSource, + data: Uint8Array, hash: string, - key: ArrayBuffer, - signature: ArrayBuffer + key: Uint8Array, + signature: Uint8Array }): Promise { const { data, hash, key, signature } = options; - // Convert public key material from ArrayBuffer to Uint8Array. - const publicKeyU8A = Convert.arrayBuffer(key).toUint8Array(); - - // Convert signature from ArrayBuffer to Uint8Array. - const signatureU8A = Convert.arrayBuffer(signature).toUint8Array(); - - // Convert data from BufferSource to Uint8Array. - const dataU8A = Convert.bufferSource(data).toUint8Array(); - // Generate a digest of the data using the specified hash function. const hashFunction = this.hashAlgorithms[hash]; - const digest = hashFunction(dataU8A); + const digest = hashFunction(data); // Verify operation. - const isValid = secp256k1.verify(signatureU8A, digest, publicKeyU8A); + const isValid = secp256k1.verify(signature, digest, key); return isValid; } diff --git a/packages/crypto/src/crypto-primitives/x25519.ts b/packages/crypto/src/crypto-primitives/x25519.ts index a9b935499..522b36bcd 100644 --- a/packages/crypto/src/crypto-primitives/x25519.ts +++ b/packages/crypto/src/crypto-primitives/x25519.ts @@ -1,6 +1,5 @@ -import type { BufferKeyPair } from '../types/index.js'; +import type { BytesKeyPair } from '../types/crypto-key.js'; -import { Convert } from '@tbd54566975/common'; import { x25519 } from '@noble/curves/ed25519'; /** @@ -9,7 +8,7 @@ import { x25519 } from '@noble/curves/ed25519'; * uses the '@noble/curves/ed25519' package for the cryptographic operations. * * All methods of this class are asynchronous and return Promises. They all use - * the ArrayBuffer type for keys and data, providing a consistent + * the Uint8Array type for keys and data, providing a consistent * interface for working with binary data. * * Example usage: @@ -27,16 +26,16 @@ export class X25519 { /** * Generates a key pair for X25519 (private and public key). * - * @returns A Promise that resolves to a BufferKeyPair object. + * @returns A Promise that resolves to a BytesKeyPair object. */ - public static async generateKeyPair(): Promise { + public static async generateKeyPair(): Promise { // Generate the private key and compute its public key. const privateKey = x25519.utils.randomPrivateKey(); const publicKey = x25519.getPublicKey(privateKey); const keyPair = { - privateKey : privateKey.buffer, - publicKey : publicKey.buffer + privateKey : privateKey, + publicKey : publicKey }; return keyPair; @@ -47,18 +46,15 @@ export class X25519 { * * @param options - The options for the public key computation operation. * @param options.privateKey - The private key used to compute the public key. - * @returns A Promise that resolves to the computed public key as an ArrayBuffer. + * @returns A Promise that resolves to the computed public key as a Uint8Array. */ public static async getPublicKey(options: { - privateKey: ArrayBuffer - }): Promise { + privateKey: Uint8Array + }): Promise { let { privateKey } = options; - // Convert key material from ArrayBuffer to Uint8Array. - const privateKeyU8A = Convert.arrayBuffer(privateKey).toUint8Array(); - // Compute public key. - const publicKey = x25519.getPublicKey(privateKeyU8A); + const publicKey = x25519.getPublicKey(privateKey); return publicKey; } @@ -70,20 +66,36 @@ export class X25519 { * @param options - The options for the shared secret computation operation. * @param options.privateKey - The private key of one party. * @param options.publicKey - The public key of the other party. - * @returns A Promise that resolves to the computed shared secret as an ArrayBuffer. + * @returns A Promise that resolves to the computed shared secret as a Uint8Array. */ public static async sharedSecret(options: { - privateKey: ArrayBuffer, - publicKey: ArrayBuffer - }): Promise { + privateKey: Uint8Array, + publicKey: Uint8Array + }): Promise { let { privateKey, publicKey } = options; - // Convert private and public key material from ArrayBuffer to Uint8Array. - const privateKeyU8A = Convert.arrayBuffer(privateKey).toUint8Array(); - const publicKeyU8A = Convert.arrayBuffer(publicKey).toUint8Array(); - const sharedSecret = x25519.getSharedSecret(privateKeyU8A, publicKeyU8A); + const sharedSecret = x25519.getSharedSecret(privateKey, publicKey); + + return sharedSecret; + } - return sharedSecret.buffer; + /** + * Note that this method is currently unimplemented because the @noble/curves + * library does not yet provide a mechanism for checking whether a point + * belongs to the Curve25519. Therefore, it currently throws an error whenever + * it is called. + * + * @param options - The options for the key validation operation. + * @param options.key - The key to validate. + * @throws {Error} If the method is called because it is not yet implemented. + * @returns A Promise that resolves to void. + */ + public static async validatePublicKey(_options: { + key: Uint8Array + }): Promise { + // TODO: Implement once/if @noble/curves library implements checking + // proper points on the Montgomery curve. + throw new Error(`Not implemented: 'validatePublicKey()'`); } } \ No newline at end of file diff --git a/packages/crypto/src/crypto-primitives/xchacha20-poly1305.ts b/packages/crypto/src/crypto-primitives/xchacha20-poly1305.ts new file mode 100644 index 000000000..5aeb4c012 --- /dev/null +++ b/packages/crypto/src/crypto-primitives/xchacha20-poly1305.ts @@ -0,0 +1,46 @@ +import { xchacha20_poly1305 } from '@noble/ciphers/chacha'; + +const TAG_LENGTH = 16; + +export class XChaCha20Poly1305 { + + public static async decrypt(options: { + additionalData?: Uint8Array, + data: Uint8Array, + key: Uint8Array, + nonce: Uint8Array, + tag: Uint8Array + }): Promise { + const { additionalData, data, key, nonce, tag } = options; + + const xc20p = xchacha20_poly1305(key, nonce, additionalData); + const ciphertext = new Uint8Array([...data, ...tag]); + const plaintext = xc20p.decrypt(ciphertext); + + return plaintext; + } + + public static async encrypt(options: { + additionalData?: Uint8Array, + data: Uint8Array, + key: Uint8Array, + nonce: Uint8Array + }): Promise<{ ciphertext: Uint8Array, tag: Uint8Array }> { + const { additionalData, data, key, nonce } = options; + + const xc20p = xchacha20_poly1305(key, nonce, additionalData); + const cipherOutput = xc20p.encrypt(data); + + const ciphertext = cipherOutput.subarray(0, -TAG_LENGTH); + const tag = cipherOutput.subarray(-TAG_LENGTH); + + return { ciphertext, tag }; + } + + public static async generateKey(): Promise { + // Generate the secret key. + const secretKey = crypto.getRandomValues(new Uint8Array(32)); + + return secretKey; + } +} \ No newline at end of file diff --git a/packages/crypto/src/crypto-primitives/xchacha20.ts b/packages/crypto/src/crypto-primitives/xchacha20.ts index 312de64dd..f1a9e916f 100644 --- a/packages/crypto/src/crypto-primitives/xchacha20.ts +++ b/packages/crypto/src/crypto-primitives/xchacha20.ts @@ -1,45 +1,34 @@ -import { Convert } from '@tbd54566975/common'; import { xchacha20 } from '@noble/ciphers/chacha'; export class XChaCha20 { public static async decrypt(options: { - data: BufferSource, - key: ArrayBuffer, - nonce: BufferSource - }): Promise { + data: Uint8Array, + key: Uint8Array, + nonce: Uint8Array + }): Promise { const { data, key, nonce } = options; - // Convert data, key material, and nonce to Uint8Array. - const dataU8A = Convert.bufferSource(data).toUint8Array(); - const keyU8A = Convert.arrayBuffer(key).toUint8Array(); - const nonceU8A = Convert.bufferSource(nonce).toUint8Array(); + const ciphertext = xchacha20(key, nonce, data); - const ciphertext = xchacha20(keyU8A, nonceU8A, dataU8A); - - return ciphertext.buffer; + return ciphertext; } public static async encrypt(options: { - data: BufferSource, - key: ArrayBuffer, - nonce: BufferSource - }): Promise { + data: Uint8Array, + key: Uint8Array, + nonce: Uint8Array + }): Promise { const { data, key, nonce } = options; - // Convert data, key material, and nonce to Uint8Array. - const dataU8A = Convert.bufferSource(data).toUint8Array(); - const keyU8A = Convert.arrayBuffer(key).toUint8Array(); - const nonceU8A = Convert.bufferSource(nonce).toUint8Array(); - - const plaintext = xchacha20(keyU8A, nonceU8A, dataU8A); + const plaintext = xchacha20(key, nonce, data); - return plaintext.buffer; + return plaintext; } - public static async generateKey(): Promise { + public static async generateKey(): Promise { // Generate the secret key. const secretKey = crypto.getRandomValues(new Uint8Array(32)); - return secretKey.buffer; + return secretKey; } } \ No newline at end of file diff --git a/packages/crypto/src/ed25519.ts b/packages/crypto/src/ed25519.ts deleted file mode 100644 index 6b0ccc8ba..000000000 --- a/packages/crypto/src/ed25519.ts +++ /dev/null @@ -1,87 +0,0 @@ -import type { KeyPair, Jwk, PublicKeyJwk, PrivateKeyJwk, KeyPairJwk } from './types.js'; - -import nacl from 'tweetnacl'; -import ed2curve from 'ed2curve'; -import { Convert } from '@tbd54566975/common'; - -// TODO: (not important) decide if we want to use tweetnacl or @noble/ed25519. is there a functional difference? -// dwn-sdk-js also has ed25519 cryptosuite stuff - -export function generateKeyPair(): KeyPair { - const ed25519KeyPair = nacl.sign.keyPair(); - - return { publicKey: ed25519KeyPair.publicKey, privateKey: ed25519KeyPair.secretKey }; -} - -export function deriveX25519KeyPair(ed25519KeyPair: KeyPair): KeyPair { - // for some reason tweetnacl chose the term `secretKey` instead of `privateKey` even though ed25519 is asymmetric - const x25519KeyPair = ed2curve.convertKeyPair({ publicKey: ed25519KeyPair.publicKey, secretKey: ed25519KeyPair.privateKey }); - - // apparently the return value of `convertKeyPair` can return null - if (!x25519KeyPair) { - throw new Error('failed to derive x25519 key pair.'); - } - - return { publicKey: x25519KeyPair.publicKey, privateKey: x25519KeyPair.secretKey }; -} - -export type JwkOverrides = { crv: 'Ed25519' | 'X25519' }; - -export function keyPairToJwk(keyPair: KeyPair, kid: string, overrides: JwkOverrides = { crv: 'Ed25519' }): KeyPairJwk { - const jwk: Jwk = { kty: 'OKP', crv: overrides.crv, kid }; - - const encodedPublicKey = Convert.uint8Array(keyPair.publicKey).toBase64Url(); - const publicKeyJwk: PublicKeyJwk = { ...jwk, x: encodedPublicKey }; - - const encodedSecretKey = Convert.uint8Array(keyPair.privateKey).toBase64Url(); - const privateKeyJwk: PrivateKeyJwk = { ...publicKeyJwk, d: encodedSecretKey }; - - return { publicKeyJwk, privateKeyJwk }; -} - -export type SignOptions = { - /** the data being signed */ - payload: Uint8Array; - /** the key being used to sign */ - privateKeyJwk: PrivateKeyJwk; -}; - -export function sign(options: SignOptions) { - const { payload, privateKeyJwk } = options; - const privateKeyBytes = Convert.base64Url(privateKeyJwk.d).toUint8Array(); - - if (privateKeyJwk.crv !== 'Ed25519') { - throw new Error('crv must be Ed25519'); - } - - const signedData = nacl.sign(payload, privateKeyBytes); - - return signedData.slice(0, nacl.sign.signatureLength); -} - -export type VerifyOptions = { - /** the signature to verify */ - signature: Uint8Array; - /** the payload that was signed */ - payload: Uint8Array; - /** the key to verify the signature with */ - publicKeyJwk: PublicKeyJwk; -} - -export async function verify(options: VerifyOptions) { - const { signature, payload, publicKeyJwk } = options; - const publicKeyBytes = Convert.base64Url(publicKeyJwk.x).toUint8Array(); - - if (publicKeyJwk.crv !== 'Ed25519') { - throw new Error('crv must be Ed25519'); - } - - const signedData = new Uint8Array(signature.length + payload.length); - signedData.set(signature); - signedData.set(payload, signature.length); - - const result = nacl.sign.open(signedData, publicKeyBytes); - - - return !!result; -} \ No newline at end of file diff --git a/packages/crypto/src/index.ts b/packages/crypto/src/index.ts new file mode 100644 index 000000000..2ed684c02 --- /dev/null +++ b/packages/crypto/src/index.ts @@ -0,0 +1,8 @@ +export type * from './types/crypto-key.js'; +export type * from './types/web5-crypto.js'; + +export * from './algorithms-api/index.js'; +export * from './crypto-algorithms/index.js'; +export * from './crypto-primitives/index.js'; +export * from './jose.js'; +export * as utils from './utils.js'; \ No newline at end of file diff --git a/packages/crypto/src/jose.ts b/packages/crypto/src/jose.ts new file mode 100644 index 000000000..e80a949f5 --- /dev/null +++ b/packages/crypto/src/jose.ts @@ -0,0 +1,938 @@ +import { sha256 } from '@noble/hashes/sha256'; +import { Convert, Multicodec, MulticodecCode, removeUndefinedProperties } from '@web5/common'; + +import type { Web5Crypto } from './types/web5-crypto.js'; + +import { keyToMultibaseId } from './utils.js'; +import { CryptoKey } from './algorithms-api/index.js'; +import { Ed25519, Secp256k1, X25519 } from './crypto-primitives/index.js'; + +/** + * JSON Web Key Operations + * + * decrypt : Decrypt content and validate decryption, if applicable + * deriveBits : Derive bits not to be used as a key + * deriveKey : Derive key + * encrypt : Encrypt content + * sign : Compute digital signature or MAC + * unwrapKey : Decrypt key and validate decryption, if applicable + * verify : Verify digital signature or MAC + * wrapKey : Encrypt key + */ +export type JwkOperation = Web5Crypto.KeyUsage[] | string[]; + +/** + * JSON Web Key Use + * + * sig : Digital Signature or MAC + * enc : Encryption + */ +export type JwkUse = 'sig' | 'enc' | string; + +/** + * JSON Web Key Types + */ +export type JwkType = + /** + * Elliptic Curve + * Used with Elliptic Curve Digital Signature Algorithm (ECDSA) and Elliptic + * Curve Diffie-Hellman (ECDH), including secp256k1, P-256, P-384, and P-521. + */ + | 'EC' + /** + * RSA + * Widely used for encryption and digital signatures. RSA keys are used in + * various algorithms like RS256, RS384, RS512, etc. + */ + | 'RSA' + /** + * Octet sequence + * Used with symmetric signing (e.g., HMAC HS256, HS512, etc.) and + * symmetric encryption (e.g., A256CBC-HS512, A256GCM, etc.) algorithms. + */ + | 'oct' + /** + * Octet string key pairs (OKP) + * A type of public key that is used with algorithms such as EdDSA (Ed25519 and + * Ed448 curves) and ECDH (X25519 and X448 curves). + */ + | 'OKP' + +/** + * JSON Web Key Elliptic Curve + */ +export type JwkNamedCurves = + // P-256 Curve + | 'P-256' + // P-384 Curve + | 'P-384' + // P-521 Curve + | 'P-521' + // Ed25519 signature algorithm key pairs + | 'Ed25519' + // Ed448 signature algorithm key pairs + | 'Ed448' + // X25519 function key pairs + | 'X25519' + // X448 function key pairs + | 'X448' + // SECG secp256k1 curve + | 'secp256k1'; + +/** + * JSON Web Key Parameters + */ + +// Used with any "kty" (key type) value. +export type JwkParamsAnyKeyType = { + // The algorithm intended for use with the key + alg?: string; + // Extractable + ext?: 'true' | 'false'; + // Key Operations + key_ops?: JwkOperation; + // Key ID + kid?: string; + // Key Type + kty: JwkType; + // Public Key Use + use?: JwkUse; + // X.509 Certificate Chain + x5c?: string; + // X.509 Certificate SHA-1 Thumbprint + x5t?: string; + // X.509 Certificate SHA-256 Thumbprint + 'x5t#S256'?: string; + // X.509 URL + x5u?: string; +} + +// Used with "EC" (elliptic curve) public keys. +export type JwkParamsEcPublic = Omit & { + /** + * The algorithm intended for use with the key. + * ES256 : ECDSA using P-256 and SHA-256 + * ES256K : ECDSA using secp256k1 curve and SHA-256 + * ES384 : ECDSA using P-384 and SHA-384 + * ES512 : ECDSA using P-521 and SHA-512 + */ + alg?: 'ES256' | 'ES256K' | 'ES384' | 'ES512'; + + /** + * Elliptic Curve key pair. + */ + kty: 'EC'; + + /** + * The cryptographic curve used with the key. + * MUST be present for all EC public keys. + */ + crv: 'secp256k1' | 'P-256' | 'P-384' | 'P-521'; + + /** + * The x-coordinate for the Elliptic Curve point. + * Represented as the base64url encoding of the octet string + * representation of the coordinate. + * MUST be present for all EC public keys + */ + x: string; + + /** + * The y-coordinate for the Elliptic Curve point. + * Represented as the base64url encoding of the octet string + * representation of the coordinate. + * MUST be present only for secp256k1 public keys. + */ + y?: string; +} + +// Used with "EC" (elliptic curve) private keys. +export type JwkParamsEcPrivate = JwkParamsEcPublic & { + /** + * The d-coordinate for the Elliptic Curve point. + * Represented as the base64url encoding of the octet string + * representation of the coordinate. + * MUST be present for all EC private keys. + */ + d: string; +} + +// Used with "OKP" (octet key pair) public keys. +export type JwkParamsOkpPublic = + Omit & + Pick & { + /** + * The algorithm intended for use with the key. + * EdDSA: Edwards Curve Digital Signature Algorithm + */ + alg?: 'EdDSA'; + + /** + * The cryptographic curve used with the key. + * MUST be present for all OKP public keys. + */ + crv: 'Ed25519' | 'Ed448' | 'X25519' | 'X448'; + + /** + * Key type + * OKP (Octet Key Pair) is defined for public key algorithms that use octet + * strings as private and public keys. + */ + kty: 'OKP'; +} + +// Used with "OKP" (octet key pair) private keys. +export type JwkParamsOkpPrivate = JwkParamsOkpPublic & { + /** + * The d-coordinate for the Edwards Curve point. + * Represented as the base64url encoding of the octet string + * representation of the coordinate. + * MUST be present for all EC private keys. + */ + d: string; +}; + +// Used with "oct" (octet sequence) private keys. +export type JwkParamsOctPrivate = Omit & { + /** + * The algorithm intended for use with the key. + * Used with symmetric signing (e.g., HMAC HS256, etc.) and + * symmetric encryption (e.g., A256GCM, etc.) algorithms. + */ + alg?: + // AES CBC using 128-bit key + | 'A128CBC' + // AES CBC using 192-bit key + | 'A192CBC' + // AES CBC using 256-bit key + | 'A256CBC' + // AES CTR using 128-bit key + | 'A128CTR' + // AES CTR using 192-bit key + | 'A192CTR' + // AES CTR using 256-bit key + | 'A256CTR' + // AES GCM using a 128-bit key + | 'A128GCM' + // AES GCM using a 192-bit key + | 'A192GCM' + // AES GCM using a 256-bit key + | 'A256GCM' + // HMAC using SHA-256 + | 'HS256' + // HMAC using SHA-384 + | 'HS384' + // HMAC using SHA-512 + | 'HS512' + + /** + * The "k" (key value) parameter contains the value of the symmetric + * (or other single-valued) key. It is represented as the base64url + * encoding of the octet sequence containing the key value. + */ + k: string; + + /** + * Key type + * oct (Octet Sequence) is defined for symmetric encryption and + * symmetric signature algorithms. + */ + kty: 'oct'; +} + +// Used with "RSA" public keys. +export type JwkParamsRsaPublic = Omit & { + // Public exponent for RSA + e: string; + + /** + * Key type + * RSA is widely used for encryption and digital signatures. + */ + kty: 'RSA'; + + // Modulus for RSA + n: string; +}; + +// Used with "RSA" private keys. +export type JwkParamsRsaPrivate = JwkParamsRsaPublic & { + // Private exponent for RSA + d: string; + // First prime factor for RSA + p?: string; + // Second prime factor for RSA + q?: string; + // First factor's CRT exponent for RSA + dp?: string; + // Second factor's CRT exponent for RSA + dq?: string; + // First CRT coefficient for RSA + qi?: string; + // Other primes information (optional in RFC 7518) + oth?: { + r: string; + d: string; + t: string; + }[]; +}; + +export type PublicKeyJwk = JwkParamsEcPublic | JwkParamsOkpPublic | JwkParamsRsaPublic; + +export type PrivateKeyJwk = JwkParamsEcPrivate | JwkParamsOkpPrivate | JwkParamsOctPrivate | JwkParamsRsaPrivate; + +export type JwkKeyPair = { + publicKeyJwk: PublicKeyJwk; + privateKeyJwk: PrivateKeyJwk; +} + +export type JsonWebKey = PrivateKeyJwk | PublicKeyJwk; + +export interface JoseHeaderParams { + cty?: string; + jku?: string; + jwk?: PublicKeyJwk; + kid?: string; + typ?: string; + x5c?: string[]; + x5t?: string; + x5u?: string; +} + +export interface JwsHeaderParams extends JoseHeaderParams { + alg: + // HMAC using SHA-256 + | 'HS256' + // HMAC using SHA-384 + | 'HS384' + // HMAC using SHA-512 + | 'HS512' + // ECDSA using P-256 and SHA-256 + | 'ES256' + // ECDSA using secp256k1 curve and SHA-256 + | 'ES256K' + // ECDSA using P-384 and SHA-384 + | 'ES384' + // ECDSA using P-521 and SHA-512 + | 'ES512'; + + // Indicates that extensions to JOSE RFCs are being used + // that MUST be understood and processed. + crit?: string[] + + // Additional Public or Private Header Parameter names. + [key: string]: unknown +} + +export interface JweHeaderParams extends JoseHeaderParams { + alg: + // AES Key Wrap with default initial value using 128-bit key + | 'A128KW' + // AES Key Wrap with default initial value using 192-bit key + | 'A192KW' + // AES Key Wrap with default initial value using 256-bit key + | 'A256KW' + // Direct use of a shared symmetric key as the CEK + | 'dir' + // Elliptic Curve Diffie-Hellman Ephemeral Static key agreement using Concat KDF + | 'ECDH-ES' + // ECDH-ES using Concat KDF and CEK wrapped with "A128KW" + | 'ECDH-ES+A128KW' + // ECDH-ES using Concat KDF and CEK wrapped with "A192KW" + | 'ECDH-ES+A192KW' + // ECDH-ES using Concat KDF and CEK wrapped with "A256KW" + | 'ECDH-ES+A256KW' + // Key wrapping with AES GCM using 128-bit key + | 'A128GCMKW' + // Key wrapping with AES GCM using 192-bit key + | 'A192GCMKW' + // Key wrapping with AES GCM using 256-bit key + | 'A256GCMKW' + // PBES2 with HMAC SHA-256 and "A128KW" wrapping + | 'PBES2-HS256+A128KW' + // PBES2 with HMAC SHA-384 and "A192KW" wrapping + | 'PBES2-HS384+A192KW' + // PBES2 with HMAC SHA-512 and "A256KW" wrapping + | 'PBES2-HS512+A256KW' + // PBES2 with HMAC SHA-512 and "XC20PKW" wrapping + | 'PBES2-HS512+XC20PKW'; + + apu?: Uint8Array; + + apv?: Uint8Array; + + // Indicates that extensions to JOSE RFCs are being used + // that MUST be understood and processed. + crit?: string[] + + /** + * Cryptographic Algorithms for Content Encryption + * JWE uses cryptographic algorithms to encrypt and integrity-protect the + * plaintext and to integrity-protect the Additional Authenticated Data. + */ + enc: + // AES_128_CBC_HMAC_SHA_256 authenticated encryption algorithm, + // as defined in RFC 7518, Section 5.2.3 + | 'A128CBC-HS256' + // AES_192_CBC_HMAC_SHA_384 authenticated encryption algorithm, + // as defined in RFC 7518, Section 5.2.4 + | 'A192CBC-HS384' + // AES_256_CBC_HMAC_SHA_512 authenticated encryption algorithm, + // as defined in RFC 7518, Section 5.2.5 + | 'A256CBC-HS512' + // AES GCM using 128-bit key + | 'A128GCM' + // AES GCM using 192-bit key + | 'A192GCM' + // AES GCM using 256-bit key + | 'A256GCM' + // XChaCha20-Poly1305 authenticated encryption algorithm + | 'XC20P'; + + epk?: Uint8Array; + + iv?: Uint8Array; + + p2c?: number; + + p2s?: string; + + // Additional Public or Private Header Parameter names. + [key: string]: unknown +} + +const joseToWebCryptoMapping: { [key: string]: Web5Crypto.GenerateKeyOptions } = { + 'Ed25519' : { name: 'EdDSA', namedCurve: 'Ed25519' }, + 'Ed448' : { name: 'EdDSA', namedCurve: 'Ed448' }, + 'X25519' : { name: 'ECDH', namedCurve: 'X25519' }, + 'secp256k1:ES256K' : { name: 'ECDSA', namedCurve: 'secp256k1' }, + 'secp256k1' : { name: 'ECDH', namedCurve: 'secp256k1' }, + 'P-256' : { name: 'ECDSA', namedCurve: 'P-256' }, + 'P-384' : { name: 'ECDSA', namedCurve: 'P-384' }, + 'P-521' : { name: 'ECDSA', namedCurve: 'P-521' }, + 'A128CBC' : { name: 'AES-CBC', length: 128 }, + 'A192CBC' : { name: 'AES-CBC', length: 192 }, + 'A256CBC' : { name: 'AES-CBC', length: 256 }, + 'A128CTR' : { name: 'AES-CTR', length: 128 }, + 'A192CTR' : { name: 'AES-CTR', length: 192 }, + 'A256CTR' : { name: 'AES-CTR', length: 256 }, + 'A128GCM' : { name: 'AES-GCM', length: 128 }, + 'A192GCM' : { name: 'AES-GCM', length: 192 }, + 'A256GCM' : { name: 'AES-GCM', length: 256 }, + 'HS256' : { name: 'HMAC', hash: { name: 'SHA-256' } }, + 'HS384' : { name: 'HMAC', hash: { name: 'SHA-384' } }, + 'HS512' : { name: 'HMAC', hash: { name: 'SHA-512' } }, +}; + +const webCryptoToJoseMapping: { [key: string]: Partial } = { + 'EdDSA:Ed25519' : { alg: 'EdDSA', crv: 'Ed25519', kty: 'OKP' }, + 'EdDSA:Ed448' : { alg: 'EdDSA', crv: 'Ed448', kty: 'OKP' }, + 'ECDH:X25519' : { crv: 'X25519', kty: 'OKP' }, + 'ECDSA:secp256k1' : { alg: 'ES256K', crv: 'secp256k1', kty: 'EC' }, + 'ECDH:secp256k1' : { crv: 'secp256k1', kty: 'EC' }, + 'ECDSA:P-256' : { alg: 'ES256', crv: 'P-256', kty: 'EC' }, + 'ECDSA:P-384' : { alg: 'ES384', crv: 'P-384', kty: 'EC' }, + 'ECDSA:P-521' : { alg: 'ES512', crv: 'P-521', kty: 'EC' }, + 'AES-CBC:128' : { alg: 'A128CBC', kty: 'oct' }, + 'AES-CBC:192' : { alg: 'A192CBC', kty: 'oct' }, + 'AES-CBC:256' : { alg: 'A256CBC', kty: 'oct' }, + 'AES-CTR:128' : { alg: 'A128CTR', kty: 'oct' }, + 'AES-CTR:192' : { alg: 'A192CTR', kty: 'oct' }, + 'AES-CTR:256' : { alg: 'A256CTR', kty: 'oct' }, + 'AES-GCM:128' : { alg: 'A128GCM', kty: 'oct' }, + 'AES-GCM:192' : { alg: 'A192GCM', kty: 'oct' }, + 'AES-GCM:256' : { alg: 'A256GCM', kty: 'oct' }, + 'HMAC:SHA-256' : { alg: 'HS256', kty: 'oct' }, + 'HMAC:SHA-384' : { alg: 'HS384', kty: 'oct' }, + 'HMAC:SHA-512' : { alg: 'HS512', kty: 'oct' }, +}; + +const multicodecToJoseMapping: { [key: string]: JsonWebKey } = { + 'ed25519-pub' : { alg: 'EdDSA', crv: 'Ed25519', kty: 'OKP', x: '' }, + 'ed25519-priv' : { alg: 'EdDSA', crv: 'Ed25519', kty: 'OKP', x: '', d: '' }, + 'secp256k1-pub' : { alg: 'ES256K', crv: 'secp256k1', kty: 'EC', x: '', y: ''}, + 'secp256k1-priv' : { alg: 'ES256K', crv: 'secp256k1', kty: 'EC', x: '', y: '', d: '' }, + 'x25519-pub' : { crv: 'X25519', kty: 'OKP', x: '' }, + 'x25519-priv' : { crv: 'X25519', kty: 'OKP', x: '', d: '' }, +}; + +const joseToMulticodecMapping: { [key: string]: string } = { + 'Ed25519:public' : 'ed25519-pub', + 'Ed25519:private' : 'ed25519-priv', + 'secp256k1:public' : 'secp256k1-pub', + 'secp256k1:private' : 'secp256k1-priv', + 'X25519:public' : 'x25519-pub', + 'X25519:private' : 'x25519-priv', +}; + +export class Jose { + + public static async cryptoKeyToJwk(options: { + key: Web5Crypto.CryptoKey, + }): Promise { + const { algorithm, extractable, material, type, usages } = options.key; + + // Translate WebCrypto algorithm to JOSE format. + let jsonWebKey = Jose.webCryptoToJose(algorithm) as JsonWebKey; + + // Set extractable parameter. + jsonWebKey.ext = extractable ? 'true' : 'false'; + + // Set key use parameter. + jsonWebKey.key_ops = usages; + + jsonWebKey = await Jose.keyToJwk({ + keyMaterial : material, + keyType : type, + ...jsonWebKey + }); + + return { ...jsonWebKey }; + } + + public static async cryptoKeyToJwkPair(options: { + keyPair: Web5Crypto.CryptoKeyPair, + }): Promise { + const { keyPair } = options; + + // Convert public and private keys into JSON Web Key format. + const privateKeyJwk = await Jose.cryptoKeyToJwk({ key: keyPair.privateKey }) as PrivateKeyJwk; + const publicKeyJwk = await Jose.cryptoKeyToJwk({ key: keyPair.publicKey }) as PublicKeyJwk; + + // Assemble as a JWK key pair + const jwkKeyPair: JwkKeyPair = { privateKeyJwk, publicKeyJwk }; + + return { ...jwkKeyPair }; + } + + public static async joseToMulticodec(options: { + key: JsonWebKey + }): Promise<{ code?: MulticodecCode, name?: string }> { + const jsonWebKey = options.key; + + const params: string[] = []; + + if ('crv' in jsonWebKey) { + params.push(jsonWebKey.crv); + if ('d' in jsonWebKey) { + params.push('private'); + } else { + params.push('public'); + } + } + + const lookupKey = params.join(':'); + const name = joseToMulticodecMapping[lookupKey]; + + if (name === undefined) { + throw new Error(`Unsupported JOSE to Multicodec conversion: '${lookupKey}'`); + } + + const code = Multicodec.getCodeFromName({ name }); + + return { code, name }; + } + + public static joseToWebCrypto(options: + Partial + ): Web5Crypto.GenerateKeyOptions { + const params: string[] = []; + + /** + * All Elliptic Curve (EC) and Octet Key Pair (OKP) JSON Web Keys + * set a value for the "crv" parameter. + */ + if ('crv' in options && options.crv) { + params.push(options.crv); + // Special case for secp256k1. If alg is "ES256K", then ECDSA. Else ECDH. + if (options.crv === 'secp256k1' && options.alg === 'ES256K') { + params.push(options.alg); + } + + /** + * All Octet Sequence (oct) JSON Web Keys omit "crv" and + * set a value for the "alg" parameter. + */ + } else if (options.alg !== undefined) { + params.push(options.alg); + + } else { + throw new TypeError(`One or more parameters missing: 'alg' or 'crv'`); + } + + const lookupKey = params.join(':'); + const webCrypto = joseToWebCryptoMapping[lookupKey]; + + if (webCrypto === undefined) { + throw new Error(`Unsupported JOSE to WebCrypto conversion: '${lookupKey}'`); + } + + return { ...webCrypto }; + } + + /** + * Computes the thumbprint of a JSON Web Key (JWK) using the method + * specified in RFC 7638. This function accepts RSA, EC, OKP, and oct keys + * and returns the thumbprint as a base64url encoded SHA-256 hash of the + * JWK's required members, serialized and sorted lexicographically. + * + * Purpose: + * - Uniquely Identifying Keys: The thumbprint allows the unique + * identification of a specific JWK within a set of JWKs. It provides a + * deterministic way to generate a value that can be used as a key + * identifier (kid) or to match a specific key. + * + * - Simplifying Key Management: In systems where multiple keys are used, + * managing and identifying individual keys can become complex. The + * thumbprint method simplifies this by creating a standardized, unique + * identifier for each key. + * + * - Enabling Interoperability: By standardizing the method to compute a + * thumbprint, different systems can compute the same thumbprint value for + * a given JWK. This enables interoperability among systems that use JWKs. + * + * - Secure Comparison: The thumbprint provides a way to securely compare + * JWKs to determine if they are equivalent. + * + * @param jwk - The JSON Web Key for which the thumbprint will be computed. + * This must be an RSA, EC, OKP, or oct key. + * @returns The thumbprint as a base64url encoded string. + * @throws {Error} Throws an error if the provided key type is unsupported. + * + * @example + * const jwk: PublicKeyJwk = { + * 'kty': 'EC', + * 'crv': 'secp256k1', + * 'x': '61iPYuGefxotzBdQZtDvv6cWHZmXrTTscY-u7Y2pFZc', + * 'y': '88nPCVLfrAY9i-wg5ORcwVbHWC_tbeAd1JE2e0co0lU' + * }; + * + * const thumbprint = jwkThumbprint(jwk); + * console.log(`JWK thumbprint: ${thumbprint}`); + * + * @see {@link https://datatracker.ietf.org/doc/html/rfc7638|RFC 7638} for + * the specification of JWK thumbprint computation. + */ + public static async jwkThumbprint(options: { + key: JsonWebKey + }): Promise { + const { key } = options; + + /** Step 1 - Normalization: The JWK is normalized to include only specific + * members and in lexicographic order. + * */ + const keyType = key.kty; + let normalizedJwk: Partial; + if (keyType === 'EC') { + normalizedJwk = { crv: key.crv, kty: key.kty, x: key.x, y: key.y }; + } else if (keyType === 'oct') { + normalizedJwk = { k: key.k, kty: key.kty }; + } else if (keyType === 'OKP') { + normalizedJwk = { crv: key.crv, kty: key.kty, x: key.x }; + } else if (keyType === 'RSA') { + normalizedJwk = { e: key.e, kty: key.kty, n: key.n }; + } else { + throw new Error(`Unsupported key type: ${keyType}`); + } + removeUndefinedProperties(normalizedJwk); + + /** Step 2 - Serialization: The normalized JWK is serialized to a UTF-8 + * representation of its JSON encoding. */ + const serializedJwk = Jose.canonicalize(normalizedJwk); + + /** Step 3 - Digest Calculation: A cryptographic hash function + * (SHA-256 is recommended) is applied to the serialized JWK, + * resulting in the thumbprint. */ + const utf8Bytes = Convert.string(serializedJwk).toUint8Array(); + const digest = sha256(utf8Bytes); + + // Encode as Base64Url. + const thumbprint = Convert.uint8Array(digest).toBase64Url(); + + return thumbprint; + } + + public static async jwkToCryptoKey(options: { + key: JsonWebKey + }): Promise { + const jsonWebKey = options.key; + + const { keyMaterial, keyType } = await Jose.jwkToKey({ key: jsonWebKey }); + + // Translate JOSE format to WebCrypto algorithm. + let algorithm = Jose.joseToWebCrypto(jsonWebKey) as Web5Crypto.GenerateKeyOptions; + + // Set extractable parameter. + let extractable: boolean; + if ('ext' in jsonWebKey && jsonWebKey.ext !== undefined) { + extractable = jsonWebKey.ext === 'true' ? true : false; + } else { + throw new Error(`Conversion from JWK to CryptoKey failed. Required parameter missing: 'ext'`); + } + + // Set key use parameter. + let keyUsage: Web5Crypto.KeyUsage[]; + if ('key_ops' in jsonWebKey && jsonWebKey.key_ops !== undefined) { + keyUsage = jsonWebKey.key_ops as Web5Crypto.KeyUsage[]; + } else { + throw new Error(`Conversion from JWK to CryptoKey failed. Required parameter missing: 'key_ops'`); + } + + const cryptoKey = new CryptoKey( + algorithm, + extractable, + keyMaterial, + keyType, + keyUsage + ); + + return cryptoKey; + } + + public static async jwkToKey(options: { + key: JsonWebKey + }): Promise<{ keyMaterial: Uint8Array, keyType: Web5Crypto.KeyType }> { + const jsonWebKey = options.key; + + let keyMaterial: Uint8Array; + let keyType: Web5Crypto.KeyType; + + // Asymmetric private key ("EC" or "OKP" - Curve25519 or SECG curves). + if ('d' in jsonWebKey) { + keyMaterial = Convert.base64Url(jsonWebKey.d).toUint8Array(); + keyType = 'private'; + } + + // Asymmetric public key ("EC" - secp256k1, secp256r1, secp384r1, secp521r1). + else if ('y' in jsonWebKey && jsonWebKey.y) { + const prefix = new Uint8Array([0x04]); // Designates an uncompressed key. + const x = Convert.base64Url(jsonWebKey.x).toUint8Array(); + const y = Convert.base64Url(jsonWebKey.y).toUint8Array(); + + const publicKey = new Uint8Array([...prefix, ...x, ...y]); + keyMaterial = publicKey; + keyType = 'public'; + } + + // Asymmetric public key ("OKP" - Ed25519, X25519). + else if ('x' in jsonWebKey) { + keyMaterial = Convert.base64Url(jsonWebKey.x).toUint8Array(); + keyType = 'public'; + } + + // Symmetric encryption or signature key ("oct" - AES, HMAC) + else if ('k' in jsonWebKey) { + keyMaterial = Convert.base64Url(jsonWebKey.k).toUint8Array(); + keyType = 'private'; + } + + else { + throw new Error('Jose: Unknown JSON Web Key format.'); + } + + return { keyMaterial, keyType }; + } + + /** + * Note: All secp public keys are converted to compressed point encoding + * before the multibase identifier is computed. + * + * Per {@link https://github.com/multiformats/multicodec/blob/master/table.csv | Multicodec table}: + * public keys for Elliptic Curve cryptography algorithms (e.g., secp256k1, + * secp256k1r1, secp384r1, etc.) are always represented with compressed point + * encoding (e.g., secp256k1-pub, p256-pub, p384-pub, etc.). + * + * Per {@link https://datatracker.ietf.org/doc/html/rfc8812#name-jose-and-cose-secp256k1-cur | RFC 8812}: + * "As a compressed point encoding representation is not defined for JWK + * elliptic curve points, the uncompressed point encoding defined there + * MUST be used. The x and y values represented MUST both be exactly + * 256 bits, with any leading zeros preserved. + * + */ + public static async jwkToMultibaseId(options: { + key: JsonWebKey + }): Promise { + const jsonWebKey = options.key; + + // Convert the algorithm into Multicodec name format. + const { name: multicodecName } = await Jose.joseToMulticodec({ key: jsonWebKey }); + + // Decode the key as a raw binary data from the JWK. + let { keyMaterial } = await Jose.jwkToKey({ key: jsonWebKey }); + + // Convert secp256k1 public keys to compressed format. + if ('crv' in jsonWebKey && !('d' in jsonWebKey)) { + switch (jsonWebKey.crv) { + case 'secp256k1': { + keyMaterial = await Secp256k1.convertPublicKey({ + publicKey : keyMaterial, + compressedPublicKey : true + }); + break; + } + } + } + + // Compute the multibase identifier based on the provided key. + const multibaseId = keyToMultibaseId({ key: keyMaterial, multicodecName }); + + return multibaseId; + } + + public static async keyToJwk(options: + Partial & { + keyMaterial: Uint8Array, + keyType: Web5Crypto.KeyType, + }): Promise { + const { keyMaterial, keyType, ...jsonWebKeyOptions } = options; + + let jsonWebKey = { ...jsonWebKeyOptions } as JsonWebKey; + + /** + * All Elliptic Curve (EC) and Octet Key Pair (OKP) keys + * specify a "crv" (named curve) parameter. + */ + if ('crv' in jsonWebKey) { + switch (jsonWebKey.crv) { + + case 'Ed25519': { + const publicKey = (keyType === 'private') + ? await Ed25519.getPublicKey({ privateKey: keyMaterial }) + : keyMaterial; + jsonWebKey.x = Convert.uint8Array(publicKey).toBase64Url(); + jsonWebKey.kty ??= 'OKP'; + break; + } + + case 'X25519': { + const publicKey = (keyType === 'private') + ? await X25519.getPublicKey({ privateKey: keyMaterial }) + : keyMaterial; + jsonWebKey.x = Convert.uint8Array(publicKey).toBase64Url(); + jsonWebKey.kty ??= 'OKP'; + break; + } + + case 'secp256k1': { + const points = await Secp256k1.getCurvePoints({ key: keyMaterial }); + jsonWebKey.x = Convert.uint8Array(points.x).toBase64Url(); + jsonWebKey.y = Convert.uint8Array(points.y).toBase64Url(); + jsonWebKey.kty ??= 'EC'; + break; + } + + default: { + throw new Error(`Unsupported key to JWK conversion: ${jsonWebKey.crv}`); + } + } + + if (keyType === 'private') { + jsonWebKey = { + d: Convert.uint8Array(keyMaterial).toBase64Url(), + ...jsonWebKey + }; + } + } + + /** + * All Octet Sequence (oct) symmetric encryption and signature keys + * specify only an "alg" parameter. + */ + if (!('crv' in jsonWebKey) && jsonWebKey.kty === 'oct') { + jsonWebKey.k = Convert.uint8Array(keyMaterial).toBase64Url(); + } + + return { ...jsonWebKey }; + } + + public static async multicodecToJose(options: { + code?: MulticodecCode, + name?: string + }): Promise { + let { code, name } = options; + + // Either code or name must be specified, but not both. + if (!(name ? !code : code)) { + throw new Error(`Either 'name' or 'code' must be defined, but not both.`); + } + + // If name is undefined, lookup by code. + name = (name === undefined ) ? Multicodec.getNameFromCode({ code: code! }) : name; + + const lookupKey = name; + const jose = multicodecToJoseMapping[lookupKey]; + + if (jose === undefined) { + throw new Error(`Unsupported Multicodec to JOSE conversion: '${options.name ?? options.code}'`); + } + + return { ...jose }; + } + + public static webCryptoToJose(options: + Web5Crypto.GenerateKeyOptions + ): Partial { + const params: string[] = []; + + /** + * All WebCrypto algorithms have the "named" parameter. + */ + params.push(options.name); + + /** + * All Elliptic Curve (EC) WebCrypto algorithms + * set a value for the "namedCurve" parameter. + */ + if ('namedCurve' in options) { + params.push(options.namedCurve); + + /** + * All symmetric encryption (AES) WebCrypto algorithms + * set a value for the "length" parameter. + */ + } else if (options.length !== undefined) { + params.push(options.length.toString()); + + /** + * All symmetric signature (HMAC) WebCrypto algorithms + * set a value for the "hash" parameter. + */ + } else if ('hash' in options) { + params.push(options.hash.name); + + } else { + throw new TypeError(`One or more parameters missing: 'name', 'namedCurve', 'length', or 'hash'`); + } + + const lookupKey = params.join(':'); + const jose = webCryptoToJoseMapping[lookupKey]; + + if (jose === undefined) { + throw new Error(`Unsupported WebCrypto to JOSE conversion: '${lookupKey}'`); + } + + return { ...jose }; + } + + private static canonicalize(obj: { [key: string]: any }): string { + const sortedKeys = Object.keys(obj).sort(); + const sortedObj = sortedKeys.reduce<{ [key: string]: any }>((acc, key) => { + acc[key] = obj[key]; + return acc; + }, {}); + return JSON.stringify(sortedObj); + } +} + +type Constructable = new (...args: any[]) => object; + +export function CryptoKeyToJwkMixin(Base: T) { + return class extends Base { + public async toJwk(): Promise { + const jwk = Jose.cryptoKeyToJwk({ key: (this as unknown) as CryptoKey }); + return jwk; + } + }; +} + +export const CryptoKeyWithJwk = CryptoKeyToJwkMixin(CryptoKey); \ No newline at end of file diff --git a/packages/crypto/src/key-manager/index.ts b/packages/crypto/src/key-manager/index.ts deleted file mode 100644 index 7161e855a..000000000 --- a/packages/crypto/src/key-manager/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './key-store.js'; -export * from './key-manager.js'; \ No newline at end of file diff --git a/packages/crypto/src/key-manager/key-manager.ts b/packages/crypto/src/key-manager/key-manager.ts deleted file mode 100644 index 677d245d4..000000000 --- a/packages/crypto/src/key-manager/key-manager.ts +++ /dev/null @@ -1,219 +0,0 @@ -import type { - ManagedKey, - SignOptions, - CryptoManager, - ImportableKey, - VerifyOptions, - DecryptOptions, - EncryptOptions, - ManagedKeyPair, - GenerateKeyType, - ImportKeyOptions, - DeriveBitsOptions, - ImportableKeyPair, - ManagedPrivateKey, - GenerateKeyOptions, - KeyManagementSystem, - GenerateKeyOptionTypes, -} from '../types/index.js'; - -import { MemoryStore } from '@tbd54566975/common'; - -import { KeyManagerStore } from './key-store.js'; -import { LocalKms, KmsKeyStore, KmsPrivateKeyStore } from '../kms-local/index.js'; -import { checkRequiredProperty, isManagedKey, isManagedKeyPair } from '../utils-new.js'; - -export type KmsMap = { - [name: string]: KeyManagementSystem; -} - -export type KeyManagerOptions = { - store: KeyManagerStore; - kms?: KmsMap; -} - -/** - * KeyManager - * - * This class orchestrates implementations of {@link KeyManagementSystem}, - * using a ManagedKeyStore to remember the link between a key reference, - * its metadata, and the respective key management system that provides the - * actual cryptographic capabilities. - * - * The methods of this class are used automatically by other Web5 Agent - * components, such as - * {@link @tbd54566975/web5#DidApi | DidApi} or - * {@link @tbd54566975/web5-user-agent#ProfileApi | ProfileApi} to - * perform their required cryptographic operations using the managed keys. - * - * @public - */ -export class KeyManager implements CryptoManager { - // KMS name to KeyManagementSystem mapping - private kms: Map; - // Store for managed key metadata. - private keyStore: KeyManagerStore; - - constructor(options: KeyManagerOptions) { - checkRequiredProperty({ property: 'store', inObject: options }); - this.keyStore = options.store; - - options.kms ??= this.useLocalKms(); - this.kms = new Map(Object.entries(options.kms)) ; - } - - async decrypt(options: DecryptOptions): Promise { - let { keyRef, ...decryptOptions } = options; - - const key = await this.getKey({ keyRef }); - - if (!isManagedKey(key)) { - throw new Error(`Key not found: '${keyRef}'.`); - } - - const kmsName = key.kms; - const kms = this.getKms(kmsName); - - const keyId = key.id; - const plaintext = await kms.decrypt({ keyRef: keyId, ...decryptOptions }); - - return plaintext; - } - - async deriveBits(options: DeriveBitsOptions): Promise { - const { baseKeyRef, ...deriveBitsOptions } = options; - - const ownKeyPair = await this.getKey({ keyRef: baseKeyRef }); - - if (!isManagedKeyPair(ownKeyPair)) { - throw new Error(`Key not found: '${baseKeyRef}'.`); - } - - const kmsName = ownKeyPair.privateKey.kms; - const kms = this.getKms(kmsName); - - const ownKeyId = ownKeyPair.privateKey.id; - const sharedSecret = kms.deriveBits({ baseKeyRef: ownKeyId, ...deriveBitsOptions }); - - return sharedSecret; - } - - async encrypt(options: EncryptOptions): Promise { - let { keyRef, ...encryptOptions } = options; - - const key = await this.getKey({ keyRef }); - - if (!isManagedKey(key)) { - throw new Error(`Key not found: '${keyRef}'.`); - } - - const kmsName = key.kms; - const kms = this.getKms(kmsName); - - const keyId = key.id; - const ciphertext = await kms.encrypt({ keyRef: keyId, ...encryptOptions }); - - return ciphertext; - } - - async generateKey(options: GenerateKeyOptions & { kms?: string }): Promise> { - const { kms: kmsName, ...generateKeyOptions } = options; - - const kms = this.getKms(kmsName); - - const keyOrKeyPair = await kms.generateKey(generateKeyOptions); - - // Store the ManagedKey or ManagedKeyPair in KeyManager's key store. - await this.keyStore.importKey({ key: keyOrKeyPair }); - - return keyOrKeyPair; - } - - async getKey(options: { keyRef: string; }): Promise { - const keyOrKeyPair = this.keyStore.getKey({ id: options.keyRef }); - return keyOrKeyPair; - } - - async importKey(options: ImportableKeyPair): Promise; - async importKey(options: ImportableKey): Promise; - async importKey(options: ImportKeyOptions): Promise { - const kmsName = ('privateKey' in options) ? options.privateKey.kms : options.kms; - const kms = this.getKms(kmsName); - - const importedKeyOrKeyPair = await kms.importKey(options); - - // Store the ManagedKey or ManagedKeyPair in KeyManager's key store. - await this.keyStore.importKey({ key: importedKeyOrKeyPair }); - - return importedKeyOrKeyPair; - } - - listKms() { - return Array.from(this.kms.keys()); - } - - async sign(options: SignOptions): Promise { - let { keyRef, ...signOptions } = options; - - const keyPair = await this.getKey({ keyRef }); - - if (!isManagedKeyPair(keyPair)) { - throw new Error(`Key not found: '${keyRef}'.`); - } - - const kmsName = keyPair.privateKey.kms; - const kms = this.getKms(kmsName); - - const keyId = keyPair.privateKey.id; - const signature = await kms.sign({ keyRef: keyId, ...signOptions }); - - return signature; - } - - async verify(options: VerifyOptions): Promise { - let { keyRef, ...verifyOptions } = options; - - const keyPair = await this.getKey({ keyRef }); - - if (!isManagedKeyPair(keyPair)) { - throw new Error(`Key not found: '${keyRef}'.`); - } - - const kmsName = keyPair.publicKey.kms; - const kms = this.getKms(kmsName); - - const keyId = keyPair.publicKey.id; - const isValid = await kms.verify({ keyRef: keyId, ...verifyOptions }); - - return isValid; - } - - private getKms(name: string | undefined): KeyManagementSystem { - // For developer convenience, if a KMS name isn't specified and KeyManager only has - // one KMS defined, use it. Otherwise, an exception will be thrown. - name ??= (this.kms.size === 1) ? this.kms.keys().next().value : ''; - - const kms = this.kms.get(name!); - - if (!kms) { - throw Error(`Unknown key management system: '${name}'`); - } - - return kms; - } - - private useLocalKms(): KmsMap { - // Instantiate local in-memory store for KMS key metadata and public keys. - const kmsMemoryStore = new MemoryStore(); - const kmsKeyStore = new KmsKeyStore(kmsMemoryStore); - - // Instantiate local in-memory store for KMS private keys. - const kmsPrivateMemoryStore = new MemoryStore(); - const kmsPrivateKeyStore = new KmsPrivateKeyStore(kmsPrivateMemoryStore); - - // Instantiate local KMS using key stores. - const kms = new LocalKms('local', kmsKeyStore, kmsPrivateKeyStore); - - return { local: kms }; - } -} \ No newline at end of file diff --git a/packages/crypto/src/key-manager/key-store.ts b/packages/crypto/src/key-manager/key-store.ts deleted file mode 100644 index 0533e3ecd..000000000 --- a/packages/crypto/src/key-manager/key-store.ts +++ /dev/null @@ -1,52 +0,0 @@ -import type { ManagedKeyStore, ManagedKey, ManagedKeyPair } from '../types/index.js'; - -import { MemoryStore } from '@tbd54566975/common'; - -import { isManagedKeyPair } from '../utils-new.js'; - -/** - * An implementation of `ManagedKeyStore` that stores key metadata and - * public key material in memory. - * - * An instance of this class can be used by `KeyManager`.` - * - * This class must be initialized with a {@link MemoryStore}, which serves - * as the key/value store. - */ -export class KeyManagerStore implements ManagedKeyStore { - private store: MemoryStore; - - constructor(options: { store: MemoryStore }) { - this.store = options.store; - } - - async deleteKey({ id }: { id: string }) { - if (await this.store.has(id)) { - await this.store.delete(id); - return true; - } else { - return false; - } - } - - async getKey({ id }: { id: string }): Promise { - return this.store.get(id); - } - - async importKey({ key }: { key: ManagedKey | ManagedKeyPair }): Promise { - const id = isManagedKeyPair(key) ? key.publicKey!.id : key.id; - if (await this.store.has(id)) { - throw new Error(`Key with ID already exists: '${id}'`); - } - - // Make a deep copy of the key so that the object stored does not share the same references as the input key. - const clonedKey = structuredClone(key); - await this.store.set(id, clonedKey ); - - return true; - } - - async listKeys(): Promise> { - return this.store.list(); - } -} \ No newline at end of file diff --git a/packages/crypto/src/kms-local/index.ts b/packages/crypto/src/kms-local/index.ts deleted file mode 100644 index 53239a171..000000000 --- a/packages/crypto/src/kms-local/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './kms-local.js'; -export * from './key-store.js'; \ No newline at end of file diff --git a/packages/crypto/src/kms-local/key-store.ts b/packages/crypto/src/kms-local/key-store.ts deleted file mode 100644 index a65ec5504..000000000 --- a/packages/crypto/src/kms-local/key-store.ts +++ /dev/null @@ -1,109 +0,0 @@ -import type { ManagedKeyStore, ManagedKey, ManagedKeyPair, ManagedPrivateKey } from '../types/index.js'; - -import { MemoryStore } from '@tbd54566975/common'; - -import { randomUuid } from '../utils-new.js'; -import { isManagedKeyPair } from '../utils-new.js'; - -/** - * An implementation of `ManagedKeyStore` that stores key metadata and - * public key material in memory. - * - * An instance of this class can be used by an implementation of - * `KeyManagementSystem`. - * - * This class must be initialized with a {@link MemoryStore}, which serves - * as the key/value store. - */ -export class KmsKeyStore implements ManagedKeyStore { - private keyStore: MemoryStore; - - constructor(keyStore: MemoryStore) { - this.keyStore = keyStore; - } - - async deleteKey({ id }: { id: string }) { - if (await this.keyStore.has(id)) { - await this.keyStore.delete(id); - return true; - } else { - return false; - } - } - - async getKey({ id }: { id: string }): Promise { - return this.keyStore.get(id); - } - - async importKey({ key }: { key: ManagedKey | ManagedKeyPair }): Promise { - let id: string; - if (isManagedKeyPair(key)) { - id = key.publicKey.id; - } else { - key.id ??= randomUuid(); // If an ID wasn't specified, generate one. - id = key.id; - } - - if (await this.keyStore.has(id)) { - throw new Error(`Key with ID already exists: '${id}'`); - } - - // Make a deep copy of the key so that the object stored does not share the same references as the input key. - const clonedKey = structuredClone(key); - await this.keyStore.set(id, clonedKey); - return id; - } - - async listKeys(): Promise> { - return this.keyStore.list(); - } -} - -/** - * An implementation of `ManagedKeyStore` that stores private key - * material in memory. - * - * An instance of this class can be used by an implementation of - * `KeyManagementSystem`. - * - * This class must be initialized with a {@link MemoryStore}, which serves - * as the key/value store. - */ -export class KmsPrivateKeyStore implements ManagedKeyStore { - private keyStore: MemoryStore; - - constructor(keyStore: MemoryStore) { - this.keyStore = keyStore; - } - - async deleteKey({ id }: { id: string }) { - if (await this.keyStore.has(id)) { - await this.keyStore.delete(id); - return true; - } else { - return false; - } - } - - async getKey({ id }: { id: string }): Promise { - return this.keyStore.get(id); - } - - async importKey({ key }: { key: Omit }): Promise { - if (!key.material) throw new TypeError(`Required parameter was missing: 'material'`); - if (!key.type) throw new TypeError(`Required parameter was missing: 'type'`); - - // Make a deep copy of the key so that the object stored does not share the same references as the input key. - // The private key material is transferred to the new object, making the original obj.material unusable. - const clonedKey = structuredClone(key, { transfer: [key.material] }) as ManagedPrivateKey; - - clonedKey.id = randomUuid(); - await this.keyStore.set(clonedKey.id, clonedKey); - - return clonedKey.id; - } - - async listKeys(): Promise> { - return this.keyStore.list(); - } -} \ No newline at end of file diff --git a/packages/crypto/src/kms-local/supported-algorithms.ts b/packages/crypto/src/kms-local/supported-algorithms.ts deleted file mode 100644 index b052fd169..000000000 --- a/packages/crypto/src/kms-local/supported-algorithms.ts +++ /dev/null @@ -1,22 +0,0 @@ -import type { CryptoAlgorithm } from '../algorithms-api/index.js'; - -import { - EcdhAlgorithm, - EcdsaAlgorithm, - EdDsaAlgorithm, - AesCtrAlgorithm, -} from '../crypto-algorithms/index.js'; - -export type AlgorithmImplementation = typeof CryptoAlgorithm & { new(): CryptoAlgorithm; }; - -export type AlgorithmImplementations = { - [algorithmName: string]: AlgorithmImplementation; -}; - -// Map key operations to algorithm specs to implementations. -export const defaultAlgorithms: AlgorithmImplementations = { - 'AES-CTR' : AesCtrAlgorithm, - ECDH : EcdhAlgorithm, - ECDSA : EcdsaAlgorithm, - EdDSA : EdDsaAlgorithm, -}; \ No newline at end of file diff --git a/packages/crypto/src/main.ts b/packages/crypto/src/main.ts deleted file mode 100644 index 1fc111121..000000000 --- a/packages/crypto/src/main.ts +++ /dev/null @@ -1,11 +0,0 @@ -export type * from './types.js'; -export type * from './types/index.js'; - -export * as ed25519 from './ed25519.js'; - -export * from './utils-new.js'; -export * from './kms-local/index.js'; -export * from './key-manager/index.js'; -export * from './algorithms-api/index.js'; -export * from './crypto-algorithms/index.js'; -export * from './crypto-primitives/index.js'; \ No newline at end of file diff --git a/packages/crypto/src/types.ts b/packages/crypto/src/types.ts deleted file mode 100644 index 0617b4612..000000000 --- a/packages/crypto/src/types.ts +++ /dev/null @@ -1,47 +0,0 @@ -export type KeyPair = { - publicKey: Uint8Array; - privateKey: Uint8Array; -} - -export type KeyPairJwk = { - publicKeyJwk: PublicKeyJwk; - privateKeyJwk: PrivateKeyJwk; -}; - -export type Jwk = { - /** The "alg" (algorithm) parameter identifies the algorithm intended for use with the key. */ - alg?: string; - /** The "alg" (algorithm) parameter identifies the algorithm intended for use with the key. */ - kid?: string; - /** identifies the cryptographic algorithm family used with the key, such "EC". */ - kty: string; - - crv: string; -}; - -export type PublicKeyJwk = Jwk & { - /** The "crv" (curve) parameter identifies the cryptographic curve used with the key. - * MUST be present for all EC public keys - */ - crv: string; - /** - * the x coordinate for the Elliptic Curve point. - * Represented as the base64url encoding of the octet string representation of the coordinate. - * MUST be present for all EC public keys - */ - x: string; - /** - * the y coordinate for the Elliptic Curve point. - * Represented as the base64url encoding of the octet string representation of the coordinate. - */ - y?: string; -}; - -export type PrivateKeyJwk = PublicKeyJwk & { - /** - * the Elliptic Curve private key value. - * It is represented as the base64url encoding of the octet string representation of the private key value - * MUST be present to represent Elliptic Curve private keys. - */ - d: string; -}; \ No newline at end of file diff --git a/packages/crypto/src/types/crypto-key.ts b/packages/crypto/src/types/crypto-key.ts index bcd0f065b..864fc68cf 100644 --- a/packages/crypto/src/types/crypto-key.ts +++ b/packages/crypto/src/types/crypto-key.ts @@ -1,182 +1,4 @@ -import type { Web5Crypto } from './web5-crypto.js'; - -export interface BufferKeyPair { - privateKey: ArrayBuffer; - publicKey: ArrayBuffer; -} - -/** - * KeyMetadata - * - * Implementations of KeyManagementSystem can populate this object with KMS platform - * specific data about each key. - * - * This property can also be used to add various tags to the keys under management. - */ -export type KeyMetadata = { - /** - * Additional properties of any type. - */ - [key: string]: any; -} - -/** - * KeyState - * - * The read-only `state` property of the `ManagedKey` interface indicates the - * status of the ManagedKey. - * - * It can have the following string values: - * - * "Enabled": The key is ready for use. - * - * "Disabled": The key may not be used, but the key material is still available, - * and the key can be placed back into the Enabled state. - * - * "PendingCreation": The key is still being created. It may not be used, - * enabled, disabled, or destroyed yet. The KMS will - * automatically change the state to enabled as soon - * as the key is ready. - * - * "PendingDeletion": The key is scheduled for deletion. It can be placed back - * into the Disabled state up until the time of deletion - * using the CancelKeyDeletion() method. Once the key has - * been deleted, any ciphertext encrypted with this key - * is no longer recoverable. Minimum and maximum waiting - * periods are defined by each KMS implementation. - * - * "PendingImport": The key is still being imported. It may not be used, enabled, - * disabled, or deleted yet. The KMS will automatically change - * the state to Enabled once the key is ready. - * - * "PendingUpdate": The key is still being updated. It may not be used, enabled, - * disabled, or deleted until the update process completes. - * The KMS will automatically change the state to Enabled - * once the key is ready. - */ -export type KeyState = 'Enabled' | 'Disabled' | 'PendingCreation' | 'PendingDeletion' | 'PendingImport' | 'PendingUpdate'; - -/** ManagedKey - * - * A ManagedKey represents a cryptographic key used by a cipher for - * encryption or decryption or an algorithm for signing or verification. - */ -export interface ManagedKey { - /** - * A unique identifier for the Key, autogenerated by a KMS. - */ - id: string; - - /** - * An object detailing the algorithm for which the key can be used along - * with additional algorithm-specific parameters. - */ - algorithm: Web5Crypto.GenerateKeyOptions; - - /** - * An alternate identifier used to identify the key in a KMS. - * This property can be used to associate a DID document key ID with a ManagedKey. - */ - alias?: string; - - - /** - * A boolean value that is `true` if the key can be exported and `false` if not. - */ - extractable: boolean; - - /** - * Name of a registered key management system. - */ - kms: string; - - /** - * Optional. Key material as a raw binary data buffer. - */ - material?: ArrayBuffer; - - /** - * Optional. Additional Key metadata. - */ - metadata?: KeyMetadata; - - /** - * A registered string value specifying the algorithm and any algorithm - * specific parameters. - * Supported algorithms vary by KMS. - */ - spec?: string; - - /** - * The current status of the ManagedKey. - */ - state: KeyState; - - /** - * The type of key. - */ - type: Web5Crypto.KeyType; - - /** - * Indicates which cryptographic operations are permissible to be used with this key. - */ - usages: Web5Crypto.KeyUsage[]; -} - -/** - * Represents information about a managed key. - * Private or secret key material is NOT present. - * - */ -export type ManagedKeyInfo = Omit; - -/** ManagedKeyPair - * - * A ManagedKeyPair represents a key pair for an asymmetric cryptography algorithm, - * also known as a public-key algorithm. - * - * A ManagedKeyPair object can be obtained using `generateKey()`, when the - * selected algorithm is one of the asymmetric algorithms: ECDSA or ECDH. - */ -export interface ManagedKeyPair { - /** - * A ManagedKey object representing the private key. For encryption and - * decryption algorithms, this key is used to decrypt. For signing and - * verification algorithms it is used to sign. - */ - privateKey: ManagedKey; - - /** - * A ManagedKey object representing the public key. For encryption and - * decryption algorithms, this key is used to encrypt. For signing and - * verification algorithms it is used to verify signatures. - */ - publicKey: ManagedKey; -} - -/** - * Represents a private key. - * - * The `alias` is used to refer to the key material which is stored as the hex encoding of the raw byte array - * (`privateKeyHex`). - * - * The `type` refers to the type of key that is represented. - * - * @public - */ -export interface ManagedPrivateKey { - /** - * A unique identifier for the Key, autogenerated by a KMS. - */ - id: string - - /** - * Key material as a raw binary data buffer. - */ - material: ArrayBuffer; - - /** - * The type of key. - */ - type: Web5Crypto.PrivateKeyType; +export interface BytesKeyPair { + privateKey: Uint8Array; + publicKey: Uint8Array; } \ No newline at end of file diff --git a/packages/crypto/src/types/crypto-manager.ts b/packages/crypto/src/types/crypto-manager.ts deleted file mode 100644 index 895d56c7f..000000000 --- a/packages/crypto/src/types/crypto-manager.ts +++ /dev/null @@ -1,233 +0,0 @@ -import type { RequireOnly } from '@tbd54566975/common'; - -import type { Web5Crypto } from './web5-crypto.js'; -import type { KeyMetadata, ManagedKey, ManagedKeyPair } from './crypto-key.js'; - -export interface CryptoManager { - decrypt(options: DecryptOptions): Promise; - - deriveBits(options: DeriveBitsOptions): Promise; - - encrypt(options: EncryptOptions): Promise; - - /** - * Generate a new ManagedKey within a CryptoManager implementation. - */ - generateKey(options: GenerateKeyOptions): Promise>; - - /** - * Retrieves detailed information about a ManagedKey or ManagedKeyPair object. - * - * @param options - The options for retrieving the key. - * @param options.keyRef - The reference identifier for the key. Can specify the id or alias property of the key. - * @returns A promise that resolves to either a ManagedKey or ManagedKeyPair object. - */ - getKey(options: { keyRef: string }): Promise; - - importKey(options: ImportableKeyPair): Promise; - importKey(options: ImportableKey): Promise; - importKey(options: ImportKeyOptions): Promise; - - sign(options: SignOptions): Promise; - - verify(options: VerifyOptions): Promise; -} - -/** - * Input arguments for implementations of the CryptoManager interface - * {@link CryptoManager.encrypt | encrypt} method. - * - * @public - */ -export type DecryptOptions = { - /** - * An object defining the cipher algorithm to use and its parameters. - */ - algorithm: Web5Crypto.AlgorithmIdentifier | Web5Crypto.AesCtrOptions | Web5Crypto.AesGcmOptions; - - /** - * An ArrayBuffer, a TypedArray, or a DataView object containing the data - * to be decrypted (also known as the ciphertext). - */ - data: BufferSource; - - /** - * An identifier of the ManagedKey to be used for decryption. - * You can use the id or alias property of the key. - */ - keyRef: string; -} - -/** - * Input arguments for implementations of the CryptoManager interface - * {@link CryptoManager.deriveBits | deriveBits} method. - * - * @public - */ -export type DeriveBitsOptions = { - - /** - * An object defining the derivation algorithm to use and its parameters. - */ - algorithm: Web5Crypto.AlgorithmIdentifier | Web5Crypto.EcdhDeriveKeyOptions; - - /** - * An identifier of the ManagedKey that will be the input to the - * derivation algorithm. - * - * If the algorithm is ECDH, this identifier will refer to an ECDH key pair. - * For PBKDF2, it might be a password. - * For HDKF, it might be the shared secret output of an ECDH key agreement operation. - */ - baseKeyRef: string; - - /** - * A number representing the number of bits to derive. To be compatible with - * all browsers, the number should be a multiple of 8. - */ - length?: number; -} - -/** - * Input arguments for implementations of the CryptoManager interface - * {@link CryptoManager.encrypt | encrypt} method. - * - * @public - */ -export type EncryptOptions = { - /** - * An object defining the cipher algorithm to use and its parameters. - */ - algorithm: Web5Crypto.AlgorithmIdentifier | Web5Crypto.AesCtrOptions | Web5Crypto.AesGcmOptions; - - /** - * An ArrayBuffer, a TypedArray, or a DataView object containing the data - * to be encrypted (also known as the plaintext). - */ - data: BufferSource; - - /** - * An identifier of the ManagedKey to be used for encryption. - * You can use the id or alias property of the key. - */ - keyRef: string; -} - -export type GenerateKeyOptions = { - algorithm: T; - alias?: string; - extractable?: boolean; - keyUsages: Web5Crypto.KeyUsage[]; - metadata?: KeyMetadata; -}; - -export type GenerateKeyOptionTypes = - | Web5Crypto.AlgorithmIdentifier - // | RsaHashedGenerateKeyOptions - | Web5Crypto.AesGenerateKeyOptions - | Web5Crypto.EcdsaGenerateKeyOptions - | Web5Crypto.EdDsaGenerateKeyOptions - // | HmacGenerateKeyOptions - // | Pbkdf2Params; - -export type GenerateKeyType = T extends Web5Crypto.EcGenerateKeyOptions ? ManagedKeyPair : - T extends Web5Crypto.AesGenerateKeyOptions /*| HmacGenerateKeyOptions | Pbkdf2Params*/ ? ManagedKey : - T extends Web5Crypto.AlgorithmIdentifier ? ManagedKey | ManagedKeyPair : - never; - -export type ImportableKey = - RequireOnly< - ManagedKey, - 'algorithm' | 'extractable' | 'kms' | 'type' | 'usages', - 'id' | 'material' | 'state' - > - & { material: BufferSource; }; - -export interface ImportableKeyPair { - privateKey: ImportableKey; - publicKey: ImportableKey; -} - -export type ImportKeyOptions = - | ImportableKey - | ImportableKeyPair - -/** - * Base interface to be implemented by key management systems. - */ -export type KeyManagementSystem = CryptoManager; - -/** - * ManagedKeyStore - * - * This interface should be implemented to provide platform specific - * implementations that are usable by KeyManager and implementations - * of KeyManagementSystem. - * - * Implementations of this class can be used to store: - * ManagedKey and ManagedKeyPair - * or: - * ManagedPrivateKey - * objects. - * - * @public - */ -export interface ManagedKeyStore { - deleteKey(options: { id: K }): Promise - getKey(options: { id: K }): Promise - importKey(options: { key: Omit }): Promise - listKeys(options: unknown): Promise -} - -/** - * Input arguments for implementations of the CryptoManager interface {@link CryptoManager.sign | sign} method. - * - * @public - */ -export type SignOptions = { - /** - * An object that specifies the signature algorithm to use and its parameters. - */ - algorithm: Web5Crypto.AlgorithmIdentifier | Web5Crypto.EcdsaOptions | Web5Crypto.EdDsaOptions; - - /** - * An ArrayBuffer, a TypedArray, or a DataView object containing the data to be signed. - */ - data: BufferSource; - - /** - * An identifier of the ManagedKey to sign with. - * You can use the id or alias property of the key. - */ - keyRef: string; -} - -/** - * Input arguments for implementations of the CryptoManager interface - * {@link CryptoManager.verify | verify} method. - * - * @public - */ -export type VerifyOptions = { - /** - * An object that specifies the algorithm to use and its parameters. - */ - algorithm: Web5Crypto.AlgorithmIdentifier | Web5Crypto.EcdsaOptions | Web5Crypto.EdDsaOptions; - - /** - * An ArrayBuffer, a TypedArray, or a DataView object containing the data - * whose signature is to be verified. - */ - data: BufferSource; - - /** - * An identifier of the ManagedKey to sign with. - * You can use the id or alias property of the key. - */ - keyRef: string; - - /** - * A ArrayBuffer containing the signature to verify. - */ - signature: ArrayBuffer; -} \ No newline at end of file diff --git a/packages/crypto/src/types/index.ts b/packages/crypto/src/types/index.ts deleted file mode 100644 index 0edcbffad..000000000 --- a/packages/crypto/src/types/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export type * from './crypto-key.js'; -export type * from './web5-crypto.js'; -export type * from './crypto-manager.js'; \ No newline at end of file diff --git a/packages/crypto/src/types/web5-crypto.ts b/packages/crypto/src/types/web5-crypto.ts index ca7dcf458..03fa49f05 100644 --- a/packages/crypto/src/types/web5-crypto.ts +++ b/packages/crypto/src/types/web5-crypto.ts @@ -1,6 +1,6 @@ export namespace Web5Crypto { export interface AesCtrOptions extends Algorithm { - counter: BufferSource; + counter: Uint8Array; length: number; } @@ -9,8 +9,8 @@ export namespace Web5Crypto { } export interface AesGcmOptions extends Algorithm { - additionalData?: BufferSource; - iv: BufferSource; + additionalData?: Uint8Array; + iv: Uint8Array; tagLength?: number; } @@ -23,7 +23,7 @@ export namespace Web5Crypto { export interface CryptoKey { algorithm: Web5Crypto.GenerateKeyOptions; extractable: boolean; - handle: ArrayBuffer; + material: Uint8Array; type: KeyType; usages: KeyUsage[]; } @@ -53,7 +53,12 @@ export namespace Web5Crypto { export type EdDsaOptions = Algorithm - export type GenerateKeyOptions = AesGenerateKeyOptions | EcGenerateKeyOptions; + export type GenerateKeyOptions = AesGenerateKeyOptions | EcGenerateKeyOptions | HmacGenerateKeyOptions; + + export interface HmacGenerateKeyOptions extends Algorithm { + hash: AlgorithmIdentifier; + length?: number; + } export interface KeyAlgorithm { name: string; @@ -67,8 +72,8 @@ export namespace Web5Crypto { /** * KeyType * - * The read-only `type` property of the `ManagedKey` interface indicates which - * kind of key is represented by the object. + * The read-only `type` property indicates which kind of key + * is represented by the object. * * It can have the following string values: * @@ -81,8 +86,7 @@ export namespace Web5Crypto { /** * KeyUsage * - * The read-only usage property of the CryptoKey interface indicates what can be - * done with the key. + * The read-only usage property indicates what can be done with the key. * * An Array of strings from the following list: * diff --git a/packages/crypto/src/utils-new.ts b/packages/crypto/src/utils.ts similarity index 58% rename from packages/crypto/src/utils-new.ts rename to packages/crypto/src/utils.ts index c24dee818..5a9d3f165 100644 --- a/packages/crypto/src/utils-new.ts +++ b/packages/crypto/src/utils.ts @@ -1,7 +1,9 @@ -import type { BufferKeyPair, ManagedKey, ManagedKeyPair, Web5Crypto } from './types/index.js'; +// import type { BytesKeyPair, Web5Crypto } from './types/index.js'; +import type { Web5Crypto } from './types/web5-crypto.js'; +import type { BytesKeyPair } from './types/crypto-key.js'; -import { universalTypeOf } from '@tbd54566975/common'; -import { bytesToHex, randomBytes } from '@noble/hashes/utils'; +import { Convert, Multicodec, universalTypeOf } from '@web5/common'; +import { bytesToHex, randomBytes as nobleRandomBytes } from '@noble/hashes/utils'; /** * Checks whether the properties object provided contains the specified property. @@ -16,11 +18,11 @@ export function checkRequiredProperty(options: { inObject: object }): void { if (!options || options.property === undefined || options.inObject === undefined) { - throw new TypeError(`One or more required arguments missing: 'property, properties'`); + throw new TypeError(`One or more required parameters missing: 'property, properties'`); } const { property, inObject } = options; if (!(property in inObject)) { - throw new TypeError(`Required parameter was missing: '${property}'`); + throw new TypeError(`Required parameter missing: '${property}'`); } } @@ -36,7 +38,7 @@ export function checkValidProperty(options: { property: string, allowedProperties: Array | Map | Set }): void { if (!options || options.property === undefined || options.allowedProperties === undefined) { - throw new TypeError(`One or more required arguments missing: 'property, allowedProperties'`); + throw new TypeError(`One or more required parameters missing: 'property, allowedProperties'`); } const { property, allowedProperties } = options; if ( @@ -51,15 +53,15 @@ export function checkValidProperty(options: { /** * Type guard function to check if the given key is a raw key pair - * of ArrayBuffers. + * of Uint8Array typed arrays. * * @param key The key to check. - * @returns True if the key is a pair of key ArrayBuffers, false otherwise. + * @returns True if the key is a pair of Uint8Array typed arrays, false otherwise. */ -export function isBufferKeyPair(key: BufferKeyPair | undefined): key is BufferKeyPair { +export function isBytesKeyPair(key: BytesKeyPair | undefined): key is BytesKeyPair { return (key && 'privateKey' in key && 'publicKey' in key && - universalTypeOf(key.privateKey) === 'ArrayBuffer' && - universalTypeOf(key.publicKey) === 'ArrayBuffer') ? true : false; + universalTypeOf(key.privateKey) === 'Uint8Array' && + universalTypeOf(key.publicKey) === 'Uint8Array') ? true : false; } /** @@ -73,24 +75,50 @@ export function isCryptoKeyPair(key: Web5Crypto.CryptoKey | Web5Crypto.CryptoKey return key && 'privateKey' in key && 'publicKey' in key; } -/** - * Type guard function to check if the given key is a ManagedKey. - * - * @param key The key to check. - * @returns True if the key is a ManagedKeyPair, false otherwise. - */ -export function isManagedKey(key: ManagedKey | ManagedKeyPair | undefined): key is ManagedKey { - return key !== undefined && 'algorithm' in key && 'extractable' in key && 'type' in key && 'usages' in key; +export function keyToMultibaseId(options: { + key: Uint8Array, + multicodecCode?: number, + multicodecName?: string +}): string { + const { key, multicodecCode, multicodecName } = options; + const prefixedKey = Multicodec.addPrefix({ code: multicodecCode, data: key, name: multicodecName }); + const prefixedKeyB58 = Convert.uint8Array(prefixedKey).toBase58Btc(); + const multibaseKeyId = Convert.base58Btc(prefixedKeyB58).toMultibase(); + + return multibaseKeyId; +} + +export function multibaseIdToKey(options: { + multibaseKeyId: string +}): { key: Uint8Array, multicodecCode: number, multicodecName: string } { + const { multibaseKeyId } = options; + + const prefixedKeyB58 = Convert.multibase(multibaseKeyId).toBase58Btc(); + const prefixedKey = Convert.base58Btc(prefixedKeyB58).toUint8Array(); + const { code, data, name } = Multicodec.removePrefix({ prefixedData: prefixedKey }); + + return { key: data, multicodecCode: code, multicodecName: name }; } /** - * Type guard function to check if the given key is a ManagedKeyPair. + * Generates secure pseudorandom values of the specified length using + * `crypto.getRandomValues`, which defers to the operating system. * - * @param key The key to check. - * @returns True if the key is a ManagedKeyPair, false otherwise. + * This function is a wrapper around `randomBytes` from the '@noble/hashes' + * package. It's designed to be cryptographically strong, suitable for + * generating keys, initialization vectors, and other random values. + * + * @param bytesLength - The number of bytes to generate. + * @returns A Uint8Array containing the generated random bytes. + * + * @example + * const bytes = randomBytes(32); // Generates 32 random bytes + * + * @see {@link https://www.npmjs.com/package/@noble/hashes | @noble/hashes on NPM} + * for more information about the underlying implementation. */ -export function isManagedKeyPair(key: ManagedKey | ManagedKeyPair | undefined): key is ManagedKeyPair { - return key !== undefined && 'privateKey' in key && 'publicKey' in key; +export function randomBytes(bytesLength: number): Uint8Array { + return nobleRandomBytes(bytesLength); } /** diff --git a/packages/crypto/tests/algorithms-api.spec.ts b/packages/crypto/tests/algorithms-api.spec.ts index 80a7b1c2c..69592f949 100644 --- a/packages/crypto/tests/algorithms-api.spec.ts +++ b/packages/crypto/tests/algorithms-api.spec.ts @@ -1,6 +1,7 @@ -import type { Web5Crypto } from '../src/types/index.js'; +import type { Web5Crypto } from '../src/types/web5-crypto.js'; -import { expect } from 'chai'; +import chai, { expect } from 'chai'; +import chaiAsPromised from 'chai-as-promised'; import { CryptoKey, @@ -16,25 +17,27 @@ import { BaseEllipticCurveAlgorithm, } from '../src/algorithms-api/index.js'; +chai.use(chaiAsPromised); + describe('Algorithms API', () => { describe('CryptoAlgorithm', () => { class TestCryptoAlgorithm extends CryptoAlgorithm { public name = 'TestAlgorithm'; public keyUsages: KeyUsage[] = ['decrypt', 'deriveBits', 'deriveKey', 'encrypt', 'sign', 'unwrapKey', 'verify', 'wrapKey']; - public async decrypt(): Promise { + public async decrypt(): Promise { return null as any; } - public async deriveBits(): Promise { + public async deriveBits(): Promise { return null as any; } - public async encrypt(): Promise { + public async encrypt(): Promise { return null as any; } public async generateKey(): Promise { return { publicKey: {} as any, privateKey: {} as any }; } - public async sign(): Promise { + public async sign(): Promise { return null as any; } public async verify(): Promise { @@ -62,7 +65,7 @@ describe('Algorithms API', () => { }); it('throws an error if the algorithm name is missing', () => { - expect(() => alg.checkAlgorithmName({} as any)).to.throw(TypeError, 'Required argument missing'); + expect(() => alg.checkAlgorithmName({} as any)).to.throw(TypeError, 'Required parameter missing'); }); }); @@ -75,7 +78,7 @@ describe('Algorithms API', () => { usages : null }; expect(() => alg.checkCryptoKey({ - // @ts-expect-error because 'handle' property is intentionally omitted to support WebCrypto API CryptoKeys. + // @ts-expect-error because 'material' property is intentionally omitted to support WebCrypto API CryptoKeys. key: mockCryptoKey })).to.not.throw(); }); @@ -95,7 +98,7 @@ describe('Algorithms API', () => { describe('checkKeyAlgorithm()', () => { it('throws an error when keyAlgorithmName is undefined', async () => { - expect(() => alg.checkKeyAlgorithm({} as any)).to.throw(TypeError, 'Required argument missing'); + expect(() => alg.checkKeyAlgorithm({} as any)).to.throw(TypeError, 'Required parameter missing'); }); it('throws an error when keyAlgorithmName does not match', async () => { @@ -111,9 +114,9 @@ describe('Algorithms API', () => { describe('checkKeyType()', () => { it('throws an error when keyType or allowedKeyType is undefined', async () => { - expect(() => alg.checkKeyType({} as any)).to.throw(TypeError, 'One or more required arguments missing'); - expect(() => alg.checkKeyType({ keyType: 'public' } as any)).to.throw(TypeError, 'One or more required arguments missing'); - expect(() => alg.checkKeyType({ allowedKeyType: 'public' } as any)).to.throw(TypeError, 'One or more required arguments missing'); + expect(() => alg.checkKeyType({} as any)).to.throw(TypeError, 'One or more required parameters missing'); + expect(() => alg.checkKeyType({ keyType: 'public' } as any)).to.throw(TypeError, 'One or more required parameters missing'); + expect(() => alg.checkKeyType({ allowedKeyType: 'public' } as any)).to.throw(TypeError, 'One or more required parameters missing'); }); it('throws an error when keyType does not match allowedKeyType', async () => { @@ -131,8 +134,8 @@ describe('Algorithms API', () => { describe('checkKeyUsages()', () => { it('throws an error when keyUsages is undefined or empty', async () => { - expect(() => alg.checkKeyUsages({ allowedKeyUsages: ['sign'] } as any)).to.throw(TypeError, 'required parameter was missing or empty'); - expect(() => alg.checkKeyUsages({ keyUsages: [], allowedKeyUsages: ['sign'] })).to.throw(TypeError, 'required parameter was missing or empty'); + expect(() => alg.checkKeyUsages({ allowedKeyUsages: ['sign'] } as any)).to.throw(TypeError, 'Required parameter missing or empty'); + expect(() => alg.checkKeyUsages({ keyUsages: [], allowedKeyUsages: ['sign'] })).to.throw(TypeError, 'Required parameter missing or empty'); }); it('throws an error when keyUsages are not in allowedKeyUsages', async () => { @@ -159,10 +162,10 @@ describe('Algorithms API', () => { class TestAesAlgorithm extends BaseAesAlgorithm { public name = 'TestAlgorithm'; public keyUsages: KeyUsage[] = ['decrypt', 'encrypt']; - public async decrypt(): Promise { + public async decrypt(): Promise { return null as any; } - public async encrypt(): Promise { + public async encrypt(): Promise { return null as any; } public async generateKey(): Promise { @@ -196,7 +199,7 @@ describe('Algorithms API', () => { // @ts-expect-error because length was intentionally omitted. algorithm : { name: 'TestAlgorithm' }, keyUsages : ['encrypt'] - })).to.throw(TypeError, 'Required parameter was missing'); + })).to.throw(TypeError, 'Required parameter missing'); }); it('throws an error when the specified length is not a Number', () => { @@ -257,7 +260,7 @@ describe('Algorithms API', () => { let dataEncryptionKey: Web5Crypto.CryptoKey; beforeEach(() => { - dataEncryptionKey = new CryptoKey({ name: 'AES-CTR', length: 128 }, false, new ArrayBuffer(32), 'secret', ['encrypt', 'decrypt']); + dataEncryptionKey = new CryptoKey({ name: 'AES-CTR', length: 128 }, false, new Uint8Array(32), 'secret', ['encrypt', 'decrypt']); }); describe('checkAlgorithmOptions()', () => { @@ -265,7 +268,7 @@ describe('Algorithms API', () => { expect(() => alg.checkAlgorithmOptions({ algorithm: { name : 'AES-CTR', - counter : new ArrayBuffer(16), + counter : new Uint8Array(16), length : 128 }, key: dataEncryptionKey @@ -276,7 +279,7 @@ describe('Algorithms API', () => { expect(() => alg.checkAlgorithmOptions({ algorithm: { name : 'invalid-name', - counter : new ArrayBuffer(16), + counter : new Uint8Array(16), length : 128 }, key: dataEncryptionKey @@ -288,38 +291,17 @@ describe('Algorithms API', () => { expect(() => alg.checkAlgorithmOptions({ algorithm: { name : 'AES-CTR', length : 128 - }})).to.throw(TypeError, 'Required parameter was missing'); + }})).to.throw(TypeError, 'Required parameter missing'); }); - it('accepts counter as ArrayBuffer, DataView, and TypedArray', () => { - const dataU8A = new Uint8Array(16); + it('accepts counter as Uint8Array', () => { + const data = new Uint8Array(16); const algorithm: { name?: string, counter?: any, length?: number } = {}; algorithm.name = 'AES-CTR'; algorithm.length = 128; - // ArrayBuffer - algorithm.counter = dataU8A.buffer; - expect(() => alg.checkAlgorithmOptions({ - algorithm : algorithm as Web5Crypto.AesCtrOptions, - key : dataEncryptionKey - })).to.not.throw(); - - // DataView - algorithm.counter = new DataView(dataU8A.buffer); - expect(() => alg.checkAlgorithmOptions({ - algorithm : algorithm as Web5Crypto.AesCtrOptions, - key : dataEncryptionKey - })).to.not.throw(); - // TypedArray - Uint8Array - algorithm.counter = dataU8A; - expect(() => alg.checkAlgorithmOptions({ - algorithm : algorithm as Web5Crypto.AesCtrOptions, - key : dataEncryptionKey - })).to.not.throw(); - - // TypedArray - Int8Array - algorithm.counter = new Int8Array(16); + algorithm.counter = data; expect(() => alg.checkAlgorithmOptions({ algorithm : algorithm as Web5Crypto.AesCtrOptions, key : dataEncryptionKey @@ -342,7 +324,7 @@ describe('Algorithms API', () => { expect(() => alg.checkAlgorithmOptions({ algorithm: { name : 'AES-CTR', - counter : new ArrayBuffer(128), + counter : new Uint8Array(128), length : 128 }, key: dataEncryptionKey @@ -353,14 +335,14 @@ describe('Algorithms API', () => { // @ts-expect-error because lengthy property was intentionally omitted. expect(() => alg.checkAlgorithmOptions({ algorithm: { name : 'AES-CTR', - counter : new ArrayBuffer(16) - }})).to.throw(TypeError, `Required parameter was missing: 'length'`); + counter : new Uint8Array(16) + }})).to.throw(TypeError, `Required parameter missing: 'length'`); }); it('throws an error if length is not a Number', () => { expect(() => alg.checkAlgorithmOptions({ algorithm: { name : 'AES-CTR', - counter : new ArrayBuffer(16), + counter : new Uint8Array(16), // @ts-expect-error because length is being intentionally specified as a string instead of a number. length : '128' }})).to.throw(TypeError, 'is not of type'); @@ -370,7 +352,7 @@ describe('Algorithms API', () => { expect(() => alg.checkAlgorithmOptions({ algorithm: { name : 'AES-CTR', - counter : new ArrayBuffer(16), + counter : new Uint8Array(16), length : 0 }, key: dataEncryptionKey @@ -379,7 +361,7 @@ describe('Algorithms API', () => { expect(() => alg.checkAlgorithmOptions({ algorithm: { name : 'AES-CTR', - counter : new ArrayBuffer(16), + counter : new Uint8Array(16), length : 256 }, key: dataEncryptionKey @@ -390,40 +372,40 @@ describe('Algorithms API', () => { // @ts-expect-error because keyy property was intentionally omitted. expect(() => alg.checkAlgorithmOptions({ algorithm: { name : 'AES-CTR', - counter : new ArrayBuffer(16), + counter : new Uint8Array(16), length : 64 - }})).to.throw(TypeError, `Required parameter was missing: 'key'`); + }})).to.throw(TypeError, `Required parameter missing: 'key'`); }); it('throws an error if the given key is not valid', () => { // @ts-ignore-error because a required property is being intentionally deleted to trigger the check to throw. delete dataEncryptionKey.extractable; expect(() => alg.checkAlgorithmOptions({ - algorithm : { name: 'AES-CTR', counter: new ArrayBuffer(16), length: 64 }, + algorithm : { name: 'AES-CTR', counter: new Uint8Array(16), length: 64 }, key : dataEncryptionKey })).to.throw(TypeError, 'Object is not a CryptoKey'); }); it('throws an error if the algorithm of the key does not match', () => { - const dataEncryptionKey = new CryptoKey({ name: 'non-existent-algorithm', length: 128 }, false, new ArrayBuffer(32), 'secret', ['encrypt', 'decrypt']); + const dataEncryptionKey = new CryptoKey({ name: 'non-existent-algorithm', length: 128 }, false, new Uint8Array(32), 'secret', ['encrypt', 'decrypt']); expect(() => alg.checkAlgorithmOptions({ - algorithm : { name: 'AES-CTR', counter: new ArrayBuffer(16), length: 64 }, + algorithm : { name: 'AES-CTR', counter: new Uint8Array(16), length: 64 }, key : dataEncryptionKey })).to.throw(InvalidAccessError, 'does not match'); }); it('throws an error if a private key is specified as the key', () => { - const dataEncryptionKey = new CryptoKey({ name: 'AES-CTR', length: 128 }, false, new ArrayBuffer(32), 'private', ['encrypt', 'decrypt']); + const dataEncryptionKey = new CryptoKey({ name: 'AES-CTR', length: 128 }, false, new Uint8Array(32), 'private', ['encrypt', 'decrypt']); expect(() => alg.checkAlgorithmOptions({ - algorithm : { name: 'AES-CTR', counter: new ArrayBuffer(16), length: 64 }, + algorithm : { name: 'AES-CTR', counter: new Uint8Array(16), length: 64 }, key : dataEncryptionKey })).to.throw(InvalidAccessError, 'Requested operation is not valid'); }); it('throws an error if a public key is specified as the key', () => { - const dataEncryptionKey = new CryptoKey({ name: 'AES-CTR', length: 128 }, false, new ArrayBuffer(32), 'public', ['encrypt', 'decrypt']); + const dataEncryptionKey = new CryptoKey({ name: 'AES-CTR', length: 128 }, false, new Uint8Array(32), 'public', ['encrypt', 'decrypt']); expect(() => alg.checkAlgorithmOptions({ - algorithm : { name: 'AES-CTR', counter: new ArrayBuffer(16), length: 64 }, + algorithm : { name: 'AES-CTR', counter: new Uint8Array(16), length: 64 }, key : dataEncryptionKey })).to.throw(InvalidAccessError, 'Requested operation is not valid'); }); @@ -436,13 +418,13 @@ describe('Algorithms API', () => { public name = 'TestAlgorithm'; public namedCurves = ['curveA']; public keyUsages: KeyUsage[] = ['decrypt']; - public async deriveBits(): Promise { + public async deriveBits(): Promise { return null as any; } public async generateKey(): Promise { return { publicKey: {} as any, privateKey: {} as any }; } - public async sign(): Promise { + public async sign(): Promise { return null as any; } public async verify(): Promise { @@ -515,8 +497,8 @@ describe('Algorithms API', () => { let ownPrivateKey: Web5Crypto.CryptoKey; beforeEach(() => { - otherPartyPublicKey = new CryptoKey({ name: 'ECDH', namedCurve: 'X25519' }, false, new ArrayBuffer(32), 'public', ['deriveBits', 'deriveKey']); - ownPrivateKey = new CryptoKey({ name: 'ECDH', namedCurve: 'X25519' }, false, new ArrayBuffer(32), 'private', ['deriveBits', 'deriveKey']); + otherPartyPublicKey = new CryptoKey({ name: 'ECDH', namedCurve: 'X25519' }, false, new Uint8Array(32), 'public', ['deriveBits', 'deriveKey']); + ownPrivateKey = new CryptoKey({ name: 'ECDH', namedCurve: 'X25519' }, false, new Uint8Array(32), 'private', ['deriveBits', 'deriveKey']); }); it('does not throw with matching algorithm name and valid publicKey and baseKey', () => { @@ -538,7 +520,7 @@ describe('Algorithms API', () => { // @ts-expect-error because `publicKey` property is intentionally omitted. algorithm : { name: 'ECDH' }, baseKey : ownPrivateKey - })).to.throw(TypeError, `Required parameter was missing: 'publicKey'`); + })).to.throw(TypeError, `Required parameter missing: 'publicKey'`); }); it('throws an error if the given publicKey is not valid', () => { @@ -551,7 +533,7 @@ describe('Algorithms API', () => { }); it('throws an error if the algorithm of the publicKey does not match', () => { - const otherPartyPublicKey = new CryptoKey({ name: 'Nope', namedCurve: 'X25519' }, false, new ArrayBuffer(32), 'public', ['deriveBits', 'deriveKey']); + const otherPartyPublicKey = new CryptoKey({ name: 'Nope', namedCurve: 'X25519' }, false, new Uint8Array(32), 'public', ['deriveBits', 'deriveKey']); expect(() => alg.checkAlgorithmOptions({ algorithm : { name: 'ECDH', publicKey: otherPartyPublicKey }, baseKey : ownPrivateKey @@ -559,7 +541,7 @@ describe('Algorithms API', () => { }); it('throws an error if a private key is specified as the publicKey', () => { - const ecdhPrivateKey = new CryptoKey({ name: 'ECDH', namedCurve: 'X25519' }, false, new ArrayBuffer(32), 'private', ['deriveBits', 'deriveKey']); + const ecdhPrivateKey = new CryptoKey({ name: 'ECDH', namedCurve: 'X25519' }, false, new Uint8Array(32), 'private', ['deriveBits', 'deriveKey']); expect(() => alg.checkAlgorithmOptions({ algorithm : { name: 'ECDH', publicKey: ecdhPrivateKey }, baseKey : ownPrivateKey @@ -570,7 +552,7 @@ describe('Algorithms API', () => { // @ts-expect-error because `baseKey` property is intentionally omitted. expect(() => alg.checkAlgorithmOptions({ algorithm: { name: 'ECDH', publicKey: otherPartyPublicKey } - })).to.throw(TypeError, `Required parameter was missing: 'baseKey'`); + })).to.throw(TypeError, `Required parameter missing: 'baseKey'`); }); it('throws an error if the given baseKey is not valid', () => { @@ -583,7 +565,7 @@ describe('Algorithms API', () => { }); it('throws an error if the algorithm of the baseKey does not match', () => { - const ownPrivateKey = new CryptoKey({ name: 'non-existent-algorithm', namedCurve: 'X25519' }, false, new ArrayBuffer(32), 'private', ['deriveBits', 'deriveKey']); + const ownPrivateKey = new CryptoKey({ name: 'non-existent-algorithm', namedCurve: 'X25519' }, false, new Uint8Array(32), 'private', ['deriveBits', 'deriveKey']); expect(() => alg.checkAlgorithmOptions({ algorithm : { name: 'ECDH', publicKey: otherPartyPublicKey }, baseKey : ownPrivateKey @@ -591,7 +573,7 @@ describe('Algorithms API', () => { }); it('throws an error if a public key is specified as the baseKey', () => { - const ownPrivateKey = new CryptoKey({ name: 'ECDH', namedCurve: 'X25519' }, false, new ArrayBuffer(32), 'public', ['deriveBits', 'deriveKey']); + const ownPrivateKey = new CryptoKey({ name: 'ECDH', namedCurve: 'X25519' }, false, new Uint8Array(32), 'public', ['deriveBits', 'deriveKey']); expect(() => alg.checkAlgorithmOptions({ algorithm : { name: 'ECDH', publicKey: otherPartyPublicKey }, baseKey : ownPrivateKey @@ -599,7 +581,7 @@ describe('Algorithms API', () => { }); it('throws an error if the named curve of the public and base keys does not match', () => { - const ownPrivateKey = new CryptoKey({ name: 'ECDH', namedCurve: 'secp256k1' }, false, new ArrayBuffer(32), 'private', ['deriveBits', 'deriveKey']); + const ownPrivateKey = new CryptoKey({ name: 'ECDH', namedCurve: 'secp256k1' }, false, new Uint8Array(32), 'private', ['deriveBits', 'deriveKey']); expect(() => alg.checkAlgorithmOptions({ algorithm : { name: 'ECDH', publicKey: otherPartyPublicKey }, baseKey : ownPrivateKey @@ -648,11 +630,11 @@ describe('Algorithms API', () => { // @ts-expect-error because `hash` property is intentionally omitted. expect(() => alg.checkAlgorithmOptions({ algorithm: { name: 'ECDSA', - }})).to.throw(TypeError, 'Required parameter was missing'); + }})).to.throw(TypeError, 'Required parameter missing'); }); it('throws an error if the given hash algorithm is not supported', () => { - const ecdhPublicKey = new CryptoKey({ name: 'ECDH', namedCurve: 'X25519' }, false, new ArrayBuffer(32), 'public', ['deriveBits', 'deriveKey']); + const ecdhPublicKey = new CryptoKey({ name: 'ECDH', namedCurve: 'X25519' }, false, new Uint8Array(32), 'public', ['deriveBits', 'deriveKey']); // @ts-ignore-error because a required property is being intentionally deleted to trigger the check to throw. delete ecdhPublicKey.extractable; expect(() => alg.checkAlgorithmOptions({ algorithm: { diff --git a/packages/crypto/tests/crypto-algorithms.spec.ts b/packages/crypto/tests/crypto-algorithms.spec.ts index 5f8f10f9f..83c817542 100644 --- a/packages/crypto/tests/crypto-algorithms.spec.ts +++ b/packages/crypto/tests/crypto-algorithms.spec.ts @@ -1,9 +1,9 @@ -import type { Web5Crypto } from '../src/types/index.js'; +import type { Web5Crypto } from '../src/types/web5-crypto.js'; import sinon from 'sinon'; import chai, { expect } from 'chai'; +import { Convert } from '@web5/common'; import chaiAsPromised from 'chai-as-promised'; -import { Convert } from '@tbd54566975/common'; import { aesCtrTestVectors } from './fixtures/test-vectors/aes.js'; import { AesCtr, Ed25519, Secp256k1, X25519 } from '../src/crypto-primitives/index.js'; @@ -37,18 +37,18 @@ describe('Default Crypto Algorithm Implementations', () => { }); }); - it('returns plaintext as an ArrayBuffer', async () => { + it('returns plaintext as a Uint8Array', async () => { const plaintext = await aesCtr.decrypt({ algorithm: { name : 'AES-CTR', - counter : new ArrayBuffer(16), + counter : new Uint8Array(16), length : 128 }, key : secretCryptoKey, data : new Uint8Array([1, 2, 3, 4]) }); - expect(plaintext).to.be.instanceOf(ArrayBuffer); + expect(plaintext).to.be.instanceOf(Uint8Array); expect(plaintext.byteLength).to.equal(4); }); @@ -59,7 +59,7 @@ describe('Default Crypto Algorithm Implementations', () => { secretCryptoKey = new CryptoKey( { name: 'AES-CTR', length: 128 }, false, - Convert.hex(vector.key).toArrayBuffer(), + Convert.hex(vector.key).toUint8Array(), 'secret', ['encrypt', 'decrypt'] ); @@ -72,7 +72,7 @@ describe('Default Crypto Algorithm Implementations', () => { key : secretCryptoKey, data : Convert.hex(vector.ciphertext).toUint8Array() }); - expect(Convert.arrayBuffer(plaintext).toHex()).to.deep.equal(vector.data); + expect(Convert.uint8Array(plaintext).toHex()).to.deep.equal(vector.data); } }); @@ -80,28 +80,28 @@ describe('Default Crypto Algorithm Implementations', () => { const secretCryptoKey: Web5Crypto.CryptoKey = new CryptoKey( { name: 'AES-CTR', length: 128 }, false, - new ArrayBuffer(16), + new Uint8Array(16), 'secret', ['encrypt', 'decrypt'] ); // Invalid (algorithm name, counter, length) result in algorithm name check failing first. await expect(aesCtr.decrypt({ - algorithm : { name: 'foo', counter: new ArrayBuffer(64), length: 512 }, + algorithm : { name: 'foo', counter: new Uint8Array(64), length: 512 }, key : secretCryptoKey, data : new Uint8Array([1, 2, 3, 4]) })).to.eventually.be.rejectedWith(NotSupportedError, 'Algorithm not supported'); // Valid (algorithm name) + Invalid (counter, length) result counter check failing first. await expect(aesCtr.decrypt({ - algorithm : { name: 'AES-CTR', counter: new ArrayBuffer(64), length: 512 }, + algorithm : { name: 'AES-CTR', counter: new Uint8Array(64), length: 512 }, key : secretCryptoKey, data : new Uint8Array([1, 2, 3, 4]) })).to.eventually.be.rejectedWith(OperationError, `'counter' must have length`); // Valid (algorithm name, counter) + Invalid (length) result length check failing first. await expect(aesCtr.decrypt({ - algorithm : { name: 'AES-CTR', counter: new ArrayBuffer(16), length: 512 }, + algorithm : { name: 'AES-CTR', counter: new Uint8Array(16), length: 512 }, key : secretCryptoKey, data : new Uint8Array([1, 2, 3, 4]) })).to.eventually.be.rejectedWith(OperationError, `'length' should be in the range`); @@ -112,7 +112,7 @@ describe('Default Crypto Algorithm Implementations', () => { secretCryptoKey.usages = ['encrypt']; await expect(aesCtr.decrypt({ - algorithm : { name: 'AES-CTR', counter: new ArrayBuffer(16), length: 128 }, + algorithm : { name: 'AES-CTR', counter: new Uint8Array(16), length: 128 }, key : secretCryptoKey, data : new Uint8Array([1, 2, 3, 4]) })).to.eventually.be.rejectedWith(InvalidAccessError, 'is not valid for the provided key'); @@ -130,18 +130,18 @@ describe('Default Crypto Algorithm Implementations', () => { }); }); - it('returns ciphertext as an ArrayBuffer', async () => { + it('returns ciphertext as a Uint8Array', async () => { const ciphertext = await aesCtr.encrypt({ algorithm: { name : 'AES-CTR', - counter : new ArrayBuffer(16), + counter : new Uint8Array(16), length : 128 }, key : secretCryptoKey, data : new Uint8Array([1, 2, 3, 4]) }); - expect(ciphertext).to.be.instanceOf(ArrayBuffer); + expect(ciphertext).to.be.instanceOf(Uint8Array); expect(ciphertext.byteLength).to.equal(4); }); @@ -151,7 +151,7 @@ describe('Default Crypto Algorithm Implementations', () => { secretCryptoKey = new CryptoKey( { name: 'AES-CTR', length: 128 }, false, - Convert.hex(vector.key).toArrayBuffer(), + Convert.hex(vector.key).toUint8Array(), 'secret', ['encrypt', 'decrypt'] ); @@ -164,7 +164,7 @@ describe('Default Crypto Algorithm Implementations', () => { key : secretCryptoKey, data : Convert.hex(vector.data).toUint8Array() }); - expect(Convert.arrayBuffer(ciphertext).toHex()).to.deep.equal(vector.ciphertext); + expect(Convert.uint8Array(ciphertext).toHex()).to.deep.equal(vector.ciphertext); } }); @@ -172,28 +172,28 @@ describe('Default Crypto Algorithm Implementations', () => { const secretCryptoKey: Web5Crypto.CryptoKey = new CryptoKey( { name: 'AES-CTR', length: 128 }, false, - new ArrayBuffer(16), + new Uint8Array(16), 'secret', ['encrypt', 'decrypt'] ); // Invalid (algorithm name, counter, length) result in algorithm name check failing first. await expect(aesCtr.encrypt({ - algorithm : { name: 'foo', counter: new ArrayBuffer(64), length: 512 }, + algorithm : { name: 'foo', counter: new Uint8Array(64), length: 512 }, key : secretCryptoKey, data : new Uint8Array([1, 2, 3, 4]) })).to.eventually.be.rejectedWith(NotSupportedError, 'Algorithm not supported'); // Valid (algorithm name) + Invalid (counter, length) result counter check failing first. await expect(aesCtr.encrypt({ - algorithm : { name: 'AES-CTR', counter: new ArrayBuffer(64), length: 512 }, + algorithm : { name: 'AES-CTR', counter: new Uint8Array(64), length: 512 }, key : secretCryptoKey, data : new Uint8Array([1, 2, 3, 4]) })).to.eventually.be.rejectedWith(OperationError, `'counter' must have length`); // Valid (algorithm name, counter) + Invalid (length) result length check failing first. await expect(aesCtr.encrypt({ - algorithm : { name: 'AES-CTR', counter: new ArrayBuffer(16), length: 512 }, + algorithm : { name: 'AES-CTR', counter: new Uint8Array(16), length: 512 }, key : secretCryptoKey, data : new Uint8Array([1, 2, 3, 4]) })).to.eventually.be.rejectedWith(OperationError, `'length' should be in the range`); @@ -204,7 +204,7 @@ describe('Default Crypto Algorithm Implementations', () => { secretCryptoKey.usages = ['decrypt']; await expect(aesCtr.encrypt({ - algorithm : { name: 'AES-CTR', counter: new ArrayBuffer(16), length: 128 }, + algorithm : { name: 'AES-CTR', counter: new Uint8Array(16), length: 128 }, key : secretCryptoKey, data : new Uint8Array([1, 2, 3, 4]) })).to.eventually.be.rejectedWith(InvalidAccessError, 'is not valid for the provided key'); @@ -221,7 +221,7 @@ describe('Default Crypto Algorithm Implementations', () => { expect(key.algorithm.name).to.equal('AES-CTR'); expect(key.usages).to.deep.equal(['encrypt', 'decrypt', 'wrapKey', 'unwrapKey']); - expect(key.handle.byteLength).to.equal(128 / 8); + expect(key.material.byteLength).to.equal(128 / 8); }); it('secret key is selectively extractable', async () => { @@ -415,7 +415,7 @@ describe('Default Crypto Algorithm Implementations', () => { baseKey : ownPrivateKey, length : null }); - expect(sharedSecret).to.be.instanceOf(ArrayBuffer); + expect(sharedSecret).to.be.instanceOf(Uint8Array); expect(sharedSecret.byteLength).to.equal(32); }); @@ -440,7 +440,7 @@ describe('Default Crypto Algorithm Implementations', () => { length : null }); - expect(sharedSecret).to.be.instanceOf(ArrayBuffer); + expect(sharedSecret).to.be.instanceOf(Uint8Array); expect(sharedSecret.byteLength).to.equal(32); }); @@ -839,7 +839,7 @@ describe('Default Crypto Algorithm Implementations', () => { describe('sign()', () => { let keyPair: Web5Crypto.CryptoKeyPair; - let dataU8A = new Uint8Array([51, 52, 53]); + let data = new Uint8Array([51, 52, 53]); beforeEach(async () => { keyPair = await ecdsa.generateKey({ @@ -853,10 +853,10 @@ describe('Default Crypto Algorithm Implementations', () => { const signature = await ecdsa.sign({ algorithm : { name: 'ECDSA', hash: 'SHA-256' }, key : keyPair.privateKey, - data : dataU8A + data : data }); - expect(signature).to.be.instanceOf(ArrayBuffer); + expect(signature).to.be.instanceOf(Uint8Array); expect(signature.byteLength).to.equal(64); }); @@ -894,7 +894,7 @@ describe('Default Crypto Algorithm Implementations', () => { await expect(ecdsa.sign({ algorithm : { name: 'ECDSA', hash: 'SHA-256' }, key : keyPair.publicKey, - data : dataU8A + data : data })).to.eventually.be.rejectedWith(InvalidAccessError, 'Requested operation is not valid'); }); @@ -905,7 +905,7 @@ describe('Default Crypto Algorithm Implementations', () => { await expect(ecdsa.sign({ algorithm : { name: 'ECDSA', hash: 'SHA-256' }, key : keyPair.privateKey, - data : dataU8A + data : data })).to.eventually.be.rejectedWith(InvalidAccessError, 'is not valid for the provided key'); }); @@ -917,15 +917,15 @@ describe('Default Crypto Algorithm Implementations', () => { await expect(ecdsa.sign({ algorithm : { name: 'ECDSA', hash: 'SHA-256' }, key : keyPair.privateKey, - data : dataU8A + data : data })).to.eventually.be.rejectedWith(TypeError, 'Out of range'); }); }); describe('verify()', () => { let keyPair: Web5Crypto.CryptoKeyPair; - let signature: ArrayBuffer; - let dataU8A = new Uint8Array([51, 52, 53]); + let signature: Uint8Array; + let data = new Uint8Array([51, 52, 53]); beforeEach(async () => { keyPair = await ecdsa.generateKey({ @@ -937,7 +937,7 @@ describe('Default Crypto Algorithm Implementations', () => { signature = await ecdsa.sign({ algorithm : { name: 'ECDSA', hash: 'SHA-256' }, key : keyPair.privateKey, - data : dataU8A + data : data }); }); @@ -946,7 +946,7 @@ describe('Default Crypto Algorithm Implementations', () => { algorithm : { name: 'ECDSA', hash: 'SHA-256' }, key : keyPair.publicKey, signature : signature, - data : dataU8A + data : data }); expect(isValid).to.be.a('boolean'); @@ -994,7 +994,7 @@ describe('Default Crypto Algorithm Implementations', () => { algorithm : { name: 'ECDSA', hash: 'SHA-256' }, key : keyPair.privateKey, signature : signature, - data : dataU8A + data : data })).to.eventually.be.rejectedWith(InvalidAccessError, 'Requested operation is not valid'); }); @@ -1006,7 +1006,7 @@ describe('Default Crypto Algorithm Implementations', () => { algorithm : { name: 'ECDSA', hash: 'SHA-256' }, key : keyPair.publicKey, signature : signature, - data : dataU8A + data : data })).to.eventually.be.rejectedWith(InvalidAccessError, 'is not valid for the provided key'); }); @@ -1019,7 +1019,7 @@ describe('Default Crypto Algorithm Implementations', () => { algorithm : { name: 'ECDSA', hash: 'SHA-256' }, key : keyPair.publicKey, signature : signature, - data : dataU8A + data : data })).to.eventually.be.rejectedWith(TypeError, 'Out of range'); }); }); @@ -1166,7 +1166,7 @@ describe('Default Crypto Algorithm Implementations', () => { describe('sign()', () => { let keyPair: Web5Crypto.CryptoKeyPair; - let dataU8A = new Uint8Array([51, 52, 53]); + let data = new Uint8Array([51, 52, 53]); beforeEach(async () => { keyPair = await eddsa.generateKey({ @@ -1180,10 +1180,10 @@ describe('Default Crypto Algorithm Implementations', () => { const signature = await eddsa.sign({ algorithm : { name: 'EdDSA' }, key : keyPair.privateKey, - data : dataU8A + data : data }); - expect(signature).to.be.instanceOf(ArrayBuffer); + expect(signature).to.be.instanceOf(Uint8Array); expect(signature.byteLength).to.equal(64); }); @@ -1212,7 +1212,7 @@ describe('Default Crypto Algorithm Implementations', () => { await expect(eddsa.sign({ algorithm : { name: 'EdDSA' }, key : keyPair.publicKey, - data : dataU8A + data : data })).to.eventually.be.rejectedWith(InvalidAccessError, 'Requested operation is not valid'); }); @@ -1223,7 +1223,7 @@ describe('Default Crypto Algorithm Implementations', () => { await expect(eddsa.sign({ algorithm : { name: 'EdDSA' }, key : keyPair.privateKey, - data : dataU8A + data : data })).to.eventually.be.rejectedWith(InvalidAccessError, 'is not valid for the provided key'); }); @@ -1235,15 +1235,15 @@ describe('Default Crypto Algorithm Implementations', () => { await expect(eddsa.sign({ algorithm : { name: 'EdDSA' }, key : keyPair.privateKey, - data : dataU8A + data : data })).to.eventually.be.rejectedWith(TypeError, 'Out of range'); }); }); describe('verify()', () => { let keyPair: Web5Crypto.CryptoKeyPair; - let signature: ArrayBuffer; - let dataU8A = new Uint8Array([51, 52, 53]); + let signature: Uint8Array; + let data = new Uint8Array([51, 52, 53]); beforeEach(async () => { keyPair = await eddsa.generateKey({ @@ -1255,7 +1255,7 @@ describe('Default Crypto Algorithm Implementations', () => { signature = await eddsa.sign({ algorithm : { name: 'EdDSA' }, key : keyPair.privateKey, - data : dataU8A + data : data }); }); @@ -1264,7 +1264,7 @@ describe('Default Crypto Algorithm Implementations', () => { algorithm : { name: 'EdDSA' }, key : keyPair.publicKey, signature : signature, - data : dataU8A + data : data }); expect(isValid).to.be.a('boolean'); @@ -1301,7 +1301,7 @@ describe('Default Crypto Algorithm Implementations', () => { algorithm : { name: 'EdDSA' }, key : keyPair.privateKey, signature : signature, - data : dataU8A + data : data })).to.eventually.be.rejectedWith(InvalidAccessError, 'Requested operation is not valid'); }); @@ -1313,7 +1313,7 @@ describe('Default Crypto Algorithm Implementations', () => { algorithm : { name: 'EdDSA' }, key : keyPair.publicKey, signature : signature, - data : dataU8A + data : data })).to.eventually.be.rejectedWith(InvalidAccessError, 'is not valid for the provided key'); }); @@ -1326,7 +1326,7 @@ describe('Default Crypto Algorithm Implementations', () => { algorithm : { name: 'EdDSA' }, key : keyPair.publicKey, signature : signature, - data : dataU8A + data : data })).to.eventually.be.rejectedWith(TypeError, 'Out of range'); }); }); diff --git a/packages/crypto/tests/crypto-primitives.spec.ts b/packages/crypto/tests/crypto-primitives.spec.ts index cf5e52aa2..a5de3877e 100644 --- a/packages/crypto/tests/crypto-primitives.spec.ts +++ b/packages/crypto/tests/crypto-primitives.spec.ts @@ -1,11 +1,25 @@ -import type { BufferKeyPair } from '../src/types/index.js'; +import type { BytesKeyPair } from '../src/types/crypto-key.js'; -import { expect } from 'chai'; -import { Convert } from '@tbd54566975/common'; +import chai, { expect } from 'chai'; +import { Convert } from '@web5/common'; +import chaiAsPromised from 'chai-as-promised'; -import { aesCtrTestVectors, aesGcmTestVectors } from './fixtures/test-vectors/aes.js'; import { NotSupportedError } from '../src/algorithms-api/errors.js'; -import { AesCtr, AesGcm, ConcatKdf, Ed25519, Secp256k1, X25519, XChaCha20 } from '../src/crypto-primitives/index.js'; +import { ed25519TestVectors } from './fixtures/test-vectors/ed25519.js'; +import { secp256k1TestVectors } from './fixtures/test-vectors/secp256k1.js'; +import { aesCtrTestVectors, aesGcmTestVectors } from './fixtures/test-vectors/aes.js'; +import { + AesCtr, + AesGcm, + ConcatKdf, + Ed25519, + Secp256k1, + X25519, + XChaCha20, + XChaCha20Poly1305 +} from '../src/crypto-primitives/index.js'; + +chai.use(chaiAsPromised); // NOTE: @noble/secp256k1 requires globalThis.crypto polyfill for node.js <=18: https://github.com/paulmillr/noble-secp256k1/blob/main/README.md#usage // Remove when we move off of node.js v18 to v20, earliest possible time would be Oct 2023: https://github.com/nodejs/release#release-schedule @@ -22,41 +36,21 @@ describe('Cryptographic Primitive Implementations', () => { const plaintext = await AesCtr.decrypt({ counter : Convert.hex(vector.counter).toUint8Array(), data : Convert.hex(vector.ciphertext).toUint8Array(), - key : Convert.hex(vector.key).toArrayBuffer(), + key : Convert.hex(vector.key).toUint8Array(), length : vector.length }); - expect(Convert.arrayBuffer(plaintext).toHex()).to.deep.equal(vector.data); + expect(Convert.uint8Array(plaintext).toHex()).to.deep.equal(vector.data); }); } - it('accepts ciphertext input as ArrayBuffer, DataView, and TypedArray', async () => { - const dataU8A = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); + it('accepts ciphertext input as Uint8Array', async () => { + const data = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); const secretKey = await AesCtr.generateKey({ length: 256 }); - let ciphertext: ArrayBuffer; - - // ArrayBuffer - const dataArrayBuffer = dataU8A.buffer; - ciphertext = await AesCtr.decrypt({ counter: new ArrayBuffer(16), data: dataArrayBuffer, key: secretKey, length: 128 }); - expect(ciphertext).to.be.instanceOf(ArrayBuffer); - - // DataView - const dataView = new DataView(dataArrayBuffer); - ciphertext = await AesCtr.decrypt({ counter: new ArrayBuffer(16), data: dataView, key: secretKey, length: 128 }); - expect(ciphertext).to.be.instanceOf(ArrayBuffer); + let ciphertext: Uint8Array; // TypedArray - Uint8Array - ciphertext = await AesCtr.decrypt({ counter: new ArrayBuffer(16), data: dataU8A, key: secretKey, length: 128 }); - expect(ciphertext).to.be.instanceOf(ArrayBuffer); - - // TypedArray - Int32Array - const dataI32A = new Int32Array([10, 20, 30, 40]); - ciphertext = await AesCtr.decrypt({ counter: new ArrayBuffer(16), data: dataI32A, key: secretKey, length: 128 }); - expect(ciphertext).to.be.instanceOf(ArrayBuffer); - - // TypedArray - Uint32Array - const dataU32A = new Uint32Array([8, 7, 6, 5, 4, 3, 2, 1]); - ciphertext = await AesCtr.decrypt({ counter: new ArrayBuffer(16), data: dataU32A, key: secretKey, length: 128 }); - expect(ciphertext).to.be.instanceOf(ArrayBuffer); + ciphertext = await AesCtr.decrypt({ counter: new Uint8Array(16), data, key: secretKey, length: 128 }); + expect(ciphertext).to.be.instanceOf(Uint8Array); }); }); @@ -66,52 +60,32 @@ describe('Cryptographic Primitive Implementations', () => { const ciphertext = await AesCtr.encrypt({ counter : Convert.hex(vector.counter).toUint8Array(), data : Convert.hex(vector.data).toUint8Array(), - key : Convert.hex(vector.key).toArrayBuffer(), + key : Convert.hex(vector.key).toUint8Array(), length : vector.length }); - expect(Convert.arrayBuffer(ciphertext).toHex()).to.deep.equal(vector.ciphertext); + expect(Convert.uint8Array(ciphertext).toHex()).to.deep.equal(vector.ciphertext); }); } - it('accepts plaintext input as ArrayBuffer, DataView, and TypedArray', async () => { - const dataU8A = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); + it('accepts plaintext input as Uint8Array', async () => { + const data = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); const secretKey = await AesCtr.generateKey({ length: 256 }); - let ciphertext: ArrayBuffer; - - // ArrayBuffer - const dataArrayBuffer = dataU8A.buffer; - ciphertext = await AesCtr.encrypt({ counter: new ArrayBuffer(16), data: dataArrayBuffer, key: secretKey, length: 128 }); - expect(ciphertext).to.be.instanceOf(ArrayBuffer); + let ciphertext: Uint8Array; - // DataView - const dataView = new DataView(dataArrayBuffer); - ciphertext = await AesCtr.encrypt({ counter: new ArrayBuffer(16), data: dataView, key: secretKey, length: 128 }); - expect(ciphertext).to.be.instanceOf(ArrayBuffer); - - // TypedArray - Uint8Array - ciphertext = await AesCtr.encrypt({ counter: new ArrayBuffer(16), data: dataU8A, key: secretKey, length: 128 }); - expect(ciphertext).to.be.instanceOf(ArrayBuffer); - - // TypedArray - Int32Array - const dataI32A = new Int32Array([10, 20, 30, 40]); - ciphertext = await AesCtr.encrypt({ counter: new ArrayBuffer(16), data: dataI32A, key: secretKey, length: 128 }); - expect(ciphertext).to.be.instanceOf(ArrayBuffer); - - // TypedArray - Uint32Array - const dataU32A = new Uint32Array([8, 7, 6, 5, 4, 3, 2, 1]); - ciphertext = await AesCtr.encrypt({ counter: new ArrayBuffer(16), data: dataU32A, key: secretKey, length: 128 }); - expect(ciphertext).to.be.instanceOf(ArrayBuffer); + // Uint8Array + ciphertext = await AesCtr.encrypt({ counter: new Uint8Array(16), data, key: secretKey, length: 128 }); + expect(ciphertext).to.be.instanceOf(Uint8Array); }); }); describe('generateKey()', () => { - it('returns a secret key of type ArrayBuffer', async () => { + it('returns a secret key of type Uint8Array', async () => { const secretKey = await AesCtr.generateKey({ length: 256 }); - expect(secretKey).to.be.instanceOf(ArrayBuffer); + expect(secretKey).to.be.instanceOf(Uint8Array); }); it('returns a secret key of the specified length', async () => { - let secretKey: ArrayBuffer; + let secretKey: Uint8Array; // 128 bits secretKey= await AesCtr.generateKey({ length: 128 }); @@ -136,26 +110,21 @@ describe('Cryptographic Primitive Implementations', () => { additionalData : Convert.hex(vector.aad).toUint8Array(), iv : Convert.hex(vector.iv).toUint8Array(), data : Convert.hex(vector.ciphertext + vector.tag).toUint8Array(), - key : Convert.hex(vector.key).toArrayBuffer(), + key : Convert.hex(vector.key).toUint8Array(), tagLength : vector.tagLength }); - expect(Convert.arrayBuffer(plaintext).toHex()).to.deep.equal(vector.data); + expect(Convert.uint8Array(plaintext).toHex()).to.deep.equal(vector.data); }); } - it('accepts ciphertext input as ArrayBuffer and TypedArray', async () => { + it('accepts ciphertext input as Uint8Array', async () => { const secretKey = new Uint8Array([222, 78, 162, 222, 38, 146, 151, 191, 191, 75, 227, 71, 220, 221, 70, 49]); - let plaintext: ArrayBuffer; - - // ArrayBuffer - const ciphertextArrayBuffer = (new Uint8Array([242, 126, 129, 170, 99, 195, 21, 165, 205, 3, 226, 171, 203, 198, 42, 86, 101])).buffer; - plaintext = await AesGcm.decrypt({ data: ciphertextArrayBuffer, iv: new ArrayBuffer(12), key: secretKey, tagLength: 128 }); - expect(plaintext).to.be.instanceOf(ArrayBuffer); + let plaintext: Uint8Array; // TypedArray - Uint8Array - const ciphertextU8A = new Uint8Array([242, 126, 129, 170, 99, 195, 21, 165, 205, 3, 226, 171, 203, 198, 42, 86, 101]); - plaintext = await AesGcm.decrypt({ data: ciphertextU8A, iv: new ArrayBuffer(12), key: secretKey, tagLength: 128 }); - expect(plaintext).to.be.instanceOf(ArrayBuffer); + const ciphertext = new Uint8Array([242, 126, 129, 170, 99, 195, 21, 165, 205, 3, 226, 171, 203, 198, 42, 86, 101]); + plaintext = await AesGcm.decrypt({ data: ciphertext, iv: new Uint8Array(12), key: secretKey, tagLength: 128 }); + expect(plaintext).to.be.instanceOf(Uint8Array); }); }); @@ -166,52 +135,32 @@ describe('Cryptographic Primitive Implementations', () => { additionalData : Convert.hex(vector.aad).toUint8Array(), iv : Convert.hex(vector.iv).toUint8Array(), data : Convert.hex(vector.data).toUint8Array(), - key : Convert.hex(vector.key).toArrayBuffer(), + key : Convert.hex(vector.key).toUint8Array(), tagLength : vector.tagLength }); - expect(Convert.arrayBuffer(ciphertext).toHex()).to.deep.equal(vector.ciphertext + vector.tag); + expect(Convert.uint8Array(ciphertext).toHex()).to.deep.equal(vector.ciphertext + vector.tag); }); } - it('accepts plaintext input as ArrayBuffer, DataView, and TypedArray', async () => { - const dataU8A = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); + it('accepts plaintext input as Uint8Array', async () => { + const data = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); const secretKey = await AesGcm.generateKey({ length: 256 }); - let ciphertext: ArrayBuffer; - - // ArrayBuffer - const dataArrayBuffer = dataU8A.buffer; - ciphertext = await AesGcm.encrypt({ data: dataArrayBuffer, iv: new ArrayBuffer(12), key: secretKey, tagLength: 128 }); - expect(ciphertext).to.be.instanceOf(ArrayBuffer); - - // DataView - const dataView = new DataView(dataArrayBuffer); - ciphertext = await AesGcm.encrypt({ data: dataView, iv: new ArrayBuffer(12), key: secretKey, tagLength: 128 }); - expect(ciphertext).to.be.instanceOf(ArrayBuffer); + let ciphertext: Uint8Array; // TypedArray - Uint8Array - ciphertext = await AesGcm.encrypt({ data: dataU8A, iv: new ArrayBuffer(12), key: secretKey, tagLength: 128 }); - expect(ciphertext).to.be.instanceOf(ArrayBuffer); - - // TypedArray - Int32Array - const dataI32A = new Int32Array([10, 20, 30, 40]); - ciphertext = await AesGcm.encrypt({ data: dataI32A, iv: new ArrayBuffer(12), key: secretKey, tagLength: 128 }); - expect(ciphertext).to.be.instanceOf(ArrayBuffer); - - // TypedArray - Uint32Array - const dataU32A = new Uint32Array([8, 7, 6, 5, 4, 3, 2, 1]); - ciphertext = await AesGcm.encrypt({ data: dataU32A, iv: new ArrayBuffer(12), key: secretKey, tagLength: 128 }); - expect(ciphertext).to.be.instanceOf(ArrayBuffer); + ciphertext = await AesGcm.encrypt({ data, iv: new Uint8Array(12), key: secretKey, tagLength: 128 }); + expect(ciphertext).to.be.instanceOf(Uint8Array); }); }); describe('generateKey()', () => { - it('returns a secret key of type ArrayBuffer', async () => { + it('returns a secret key of type Uint8Array', async () => { const secretKey = await AesGcm.generateKey({ length: 256 }); - expect(secretKey).to.be.instanceOf(ArrayBuffer); + expect(secretKey).to.be.instanceOf(Uint8Array); }); it('returns a secret key of the specified length', async () => { - let secretKey: ArrayBuffer; + let secretKey: Uint8Array; // 128 bits secretKey= await AesGcm.generateKey({ length: 128 }); @@ -247,29 +196,18 @@ describe('Cryptographic Primitive Implementations', () => { const derivedKeyingMaterial = await ConcatKdf.deriveKey(input); - const expectedResult = Convert.base64Url(output).toArrayBuffer(); + const expectedResult = Convert.base64Url(output).toUint8Array(); expect(derivedKeyingMaterial).to.deep.equal(expectedResult); expect(derivedKeyingMaterial.byteLength).to.equal(16); }); - it('accepts other info as ArrayBuffer, String, and TypedArray', async () => { + it('accepts other info as String and TypedArray', async () => { const inputBase = { sharedSecret : new Uint8Array([1, 2, 3]), keyDataLen : 256, otherInfo : {} }; - // ArrayBuffer input. - const inputArrayBuffer = { ...inputBase, otherInfo: { - algorithmId : 'A128GCM', - partyUInfo : Convert.string('Alice').toArrayBuffer(), - partyVInfo : Convert.string('Bob').toArrayBuffer(), - suppPubInfo : 128 - }}; - let derivedKeyingMaterial = await ConcatKdf.deriveKey(inputArrayBuffer); - expect(derivedKeyingMaterial).to.be.an('ArrayBuffer'); - expect(derivedKeyingMaterial.byteLength).to.equal(32); - // String input. const inputString = { ...inputBase, otherInfo: { algorithmId : 'A128GCM', @@ -277,8 +215,8 @@ describe('Cryptographic Primitive Implementations', () => { partyVInfo : 'Bob', suppPubInfo : 128 }}; - derivedKeyingMaterial = await ConcatKdf.deriveKey(inputString); - expect(derivedKeyingMaterial).to.be.an('ArrayBuffer'); + let derivedKeyingMaterial = await ConcatKdf.deriveKey(inputString); + expect(derivedKeyingMaterial).to.be.an('Uint8Array'); expect(derivedKeyingMaterial.byteLength).to.equal(32); // TypedArray input. @@ -289,7 +227,7 @@ describe('Cryptographic Primitive Implementations', () => { suppPubInfo : 128 }}; derivedKeyingMaterial = await ConcatKdf.deriveKey(inputTypedArray); - expect(derivedKeyingMaterial).to.be.an('ArrayBuffer'); + expect(derivedKeyingMaterial).to.be.an('Uint8Array'); expect(derivedKeyingMaterial.byteLength).to.equal(32); }); @@ -317,7 +255,7 @@ describe('Cryptographic Primitive Implementations', () => { }); }); - describe('#computeOtherInfo()', () => { + describe('computeOtherInfo()', () => { it('returns concatenated and formatted Uint8Array', () => { const input = { algorithmId : 'A128GCM', @@ -355,13 +293,80 @@ describe('Cryptographic Primitive Implementations', () => { }); describe('Ed25519', () => { + describe('convertPrivateKeyToX25519()', () => { + let validEd25519PrivateKey: Uint8Array; + + // This is a setup step. Before each test, generate a new Ed25519 key pair + // and use the private key in tests. This ensures that we work with fresh keys for every test. + beforeEach(async () => { + const keyPair = await Ed25519.generateKeyPair(); + validEd25519PrivateKey = keyPair.publicKey; + }); + + it('converts a valid Ed25519 private key to X25519 format', async () => { + const x25519PrivateKey = await Ed25519.convertPrivateKeyToX25519({ privateKey: validEd25519PrivateKey }); + + expect(x25519PrivateKey).to.be.instanceOf(Uint8Array); + expect(x25519PrivateKey.length).to.equal(32); + }); + + it('accepts any Uint8Array value as a private key', async () => { + /** For Ed25519 the private key is a random string of bytes that is + * hashed, which means many possible values can serve as a valid + * private key. */ + const key0Bytes = new Uint8Array(0); + const key33Bytes = Convert.hex('02fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f').toUint8Array(); + + let x25519PrivateKey = await Ed25519.convertPrivateKeyToX25519({ privateKey: key0Bytes }); + expect(x25519PrivateKey.length).to.equal(32); + x25519PrivateKey = await Ed25519.convertPrivateKeyToX25519({ privateKey: key33Bytes }); + expect(x25519PrivateKey.length).to.equal(32); + }); + }); + + describe('convertPublicKeyToX25519()', () => { + let validEd25519PublicKey: Uint8Array; + + // This is a setup step. Before each test, generate a new Ed25519 key pair + // and use the public key in tests. This ensures that we work with fresh keys for every test. + beforeEach(async () => { + const keyPair = await Ed25519.generateKeyPair(); + validEd25519PublicKey = keyPair.publicKey; + }); + + it('converts a valid Ed25519 public key to X25519 format', async () => { + const x25519PublicKey = await Ed25519.convertPublicKeyToX25519({ publicKey: validEd25519PublicKey }); + + expect(x25519PublicKey).to.be.instanceOf(Uint8Array); + expect(x25519PublicKey.length).to.equal(32); + }); + + it('throws an error when provided an invalid Ed25519 public key', async () => { + const invalidEd25519PublicKey = Convert.hex('02fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f').toUint8Array(); + + await expect( + Ed25519.convertPublicKeyToX25519({ publicKey: invalidEd25519PublicKey }) + ).to.eventually.be.rejectedWith(Error, 'Invalid public key'); + }); + + it('throws an error when provided an Ed25519 private key', async () => { + for (const vector of ed25519TestVectors) { + const validEd25519PrivateKey = Convert.hex(vector.privateKey.encoded).toUint8Array(); + + await expect( + Ed25519.convertPublicKeyToX25519({ publicKey: validEd25519PrivateKey }) + ).to.eventually.be.rejectedWith(Error, 'Invalid public key'); + } + }); + }); + describe('generateKeyPair()', () => { - it('returns a pair of keys of type ArrayBuffer', async () => { + it('returns a pair of keys of type Uint8Array', async () => { const keyPair = await Ed25519.generateKeyPair(); expect(keyPair).to.have.property('privateKey'); expect(keyPair).to.have.property('publicKey'); - expect(keyPair.privateKey).to.be.instanceOf(ArrayBuffer); - expect(keyPair.publicKey).to.be.instanceOf(ArrayBuffer); + expect(keyPair.privateKey).to.be.instanceOf(Uint8Array); + expect(keyPair.publicKey).to.be.instanceOf(Uint8Array); }); it('returns a 32-byte private key', async () => { @@ -376,7 +381,7 @@ describe('Cryptographic Primitive Implementations', () => { }); describe('getPublicKey()', () => { - let keyPair: BufferKeyPair; + let keyPair: BytesKeyPair; before(async () => { keyPair = await Ed25519.generateKeyPair(); @@ -384,169 +389,213 @@ describe('Cryptographic Primitive Implementations', () => { it('returns a 32-byte compressed public key', async () => { const publicKey = await Ed25519.getPublicKey({ privateKey: keyPair.privateKey }); + expect(publicKey).to.be.instanceOf(Uint8Array); expect(publicKey.byteLength).to.equal(32); }); }); describe('sign()', () => { - let keyPair: BufferKeyPair; + let keyPair: BytesKeyPair; before(async () => { keyPair = await Ed25519.generateKeyPair(); }); - it('returns a 64-byte signature of type ArrayBuffer', async () => { - const dataU8A = new Uint8Array([51, 52, 53]); - const signature = await Ed25519.sign({ key: keyPair.privateKey, data: dataU8A }); - expect(signature).to.be.instanceOf(ArrayBuffer); + it('returns a 64-byte signature of type Uint8Array', async () => { + const data = new Uint8Array([51, 52, 53]); + const signature = await Ed25519.sign({ key: keyPair.privateKey, data }); + expect(signature).to.be.instanceOf(Uint8Array); expect(signature.byteLength).to.equal(64); }); - it('accepts input data as ArrayBuffer, DataView, and TypedArray', async () => { - const dataU8A = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); + it('accepts input data as Uint8Array', async () => { + const data = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); const key = keyPair.privateKey; - let signature: ArrayBuffer; - - // ArrayBuffer - const dataArrayBuffer = dataU8A.buffer; - signature = await Ed25519.sign({ key, data: dataArrayBuffer }); - expect(signature).to.be.instanceOf(ArrayBuffer); - - // DataView - const dataView = new DataView(dataArrayBuffer); - signature = await Ed25519.sign({ key, data: dataView }); - expect(signature).to.be.instanceOf(ArrayBuffer); + let signature: Uint8Array; // TypedArray - Uint8Array - signature = await Ed25519.sign({ key, data: dataU8A }); - expect(signature).to.be.instanceOf(ArrayBuffer); + signature = await Ed25519.sign({ key, data: data }); + expect(signature).to.be.instanceOf(Uint8Array); + }); + }); + + describe('validatePublicKey()', () => { + it('returns true for valid public keys', async () => { + for (const vector of ed25519TestVectors) { + const key = Convert.hex(vector.publicKey.encoded).toUint8Array(); + const isValid = await Ed25519.validatePublicKey({ key }); + expect(isValid).to.be.true; + } + }); - // TypedArray - Int32Array - const dataI32A = new Int32Array([10, 20, 30, 40]); - signature = await Ed25519.sign({ key, data: dataI32A }); - expect(signature).to.be.instanceOf(ArrayBuffer); + it('returns false for invalid public keys', async () => { + const key = Convert.hex('02fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f').toUint8Array(); + const isValid = await Ed25519.validatePublicKey({ key }); + expect(isValid).to.be.false; + }); - // TypedArray - Uint32Array - const dataU32A = new Uint32Array([8, 7, 6, 5, 4, 3, 2, 1]); - signature = await Ed25519.sign({ key, data: dataU32A }); - expect(signature).to.be.instanceOf(ArrayBuffer); + it('returns false if a private key is given', async () => { + for (const vector of ed25519TestVectors) { + const key = Convert.hex(vector.privateKey.encoded).toUint8Array(); + const isValid = await Ed25519.validatePublicKey({ key }); + expect(isValid).to.be.false; + } }); }); describe('verify()', () => { - let keyPair: BufferKeyPair; + let keyPair: BytesKeyPair; before(async () => { keyPair = await Ed25519.generateKeyPair(); }); it('returns a boolean result', async () => { - const dataU8A = new Uint8Array([51, 52, 53]); - const signature = await Ed25519.sign({ key: keyPair.privateKey, data: dataU8A }); + const data = new Uint8Array([51, 52, 53]); + const signature = await Ed25519.sign({ key: keyPair.privateKey, data }); - const isValid = await Ed25519.verify({ key: keyPair.publicKey, signature, data: dataU8A }); + const isValid = await Ed25519.verify({ key: keyPair.publicKey, signature, data }); expect(isValid).to.exist; expect(isValid).to.be.true; }); - it('accepts input data as ArrayBuffer, DataView, and TypedArray', async () => { - const dataU8A = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); + it('accepts input data as Uint8Array', async () => { + const data = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); let isValid: boolean; - let signature: ArrayBuffer; - - // ArrayBuffer - const dataArrayBuffer = dataU8A.buffer; - signature = await Ed25519.sign({ key: keyPair.privateKey, data: dataArrayBuffer }); - isValid = await Ed25519.verify({ key: keyPair.publicKey, signature, data: dataArrayBuffer }); - expect(isValid).to.be.true; - - // DataView - const dataView = new DataView(dataArrayBuffer); - signature = await Ed25519.sign({ key: keyPair.privateKey, data: dataView }); - isValid = await Ed25519.verify({ key: keyPair.publicKey, signature, data: dataView }); - expect(isValid).to.be.true; + let signature: Uint8Array; // TypedArray - Uint8Array - signature = await Ed25519.sign({ key: keyPair.privateKey, data: dataU8A }); - isValid = await Ed25519.verify({ key: keyPair.publicKey, signature, data: dataU8A }); - expect(isValid).to.be.true; - - // TypedArray - Int32Array - const dataI32A = new Int32Array([10, 20, 30, 40]); - signature = await Ed25519.sign({ key: keyPair.privateKey, data: dataI32A }); - isValid = await Ed25519.verify({ key: keyPair.publicKey, signature, data: dataI32A }); - expect(isValid).to.be.true; - - // TypedArray - Uint32Array - const dataU32A = new Uint32Array([8, 7, 6, 5, 4, 3, 2, 1]); - signature = await Ed25519.sign({ key: keyPair.privateKey, data: dataU32A }); - isValid = await Ed25519.verify({ key: keyPair.publicKey, signature, data: dataU32A }); + signature = await Ed25519.sign({ key: keyPair.privateKey, data }); + isValid = await Ed25519.verify({ key: keyPair.publicKey, signature, data }); expect(isValid).to.be.true; }); it('returns false if the signed data was mutated', async () => { - const dataU8A = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); + const data = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); let isValid: boolean; // Generate signature using the private key. - const signature = await Ed25519.sign({ key: keyPair.privateKey, data: dataU8A }); + const signature = await Ed25519.sign({ key: keyPair.privateKey, data }); // Verification should return true with the data used to generate the signature. - isValid = await Ed25519.verify({ key: keyPair.publicKey, signature, data: dataU8A }); + isValid = await Ed25519.verify({ key: keyPair.publicKey, signature, data }); expect(isValid).to.be.true; // Make a copy and flip the least significant bit (the rightmost bit) in the first byte of the array. - const mutatedDataU8A = new Uint8Array(dataU8A); - mutatedDataU8A[0] ^= 1 << 0; + const mutatedData = new Uint8Array(data); + mutatedData[0] ^= 1 << 0; // Verification should return false if the given data does not match the data used to generate the signature. - isValid = await Ed25519.verify({ key: keyPair.publicKey, signature, data: mutatedDataU8A }); + isValid = await Ed25519.verify({ key: keyPair.publicKey, signature, data: mutatedData }); expect(isValid).to.be.false; }); it('returns false if the signature was mutated', async () => { - const dataU8A = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); + const data = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); let isValid: boolean; // Generate a new key pair. keyPair = await Ed25519.generateKeyPair(); // Generate signature using the private key. - const signature = await Ed25519.sign({ key: keyPair.privateKey, data: dataU8A }); + const signature = await Ed25519.sign({ key: keyPair.privateKey, data }); // Make a copy and flip the least significant bit (the rightmost bit) in the first byte of the array. const mutatedSignature = new Uint8Array(signature); mutatedSignature[0] ^= 1 << 0; // Verification should return false if the signature was modified. - isValid = await Ed25519.verify({ key: keyPair.publicKey, signature: signature, data: mutatedSignature.buffer }); + isValid = await Ed25519.verify({ key: keyPair.publicKey, signature: signature, data: mutatedSignature }); expect(isValid).to.be.false; }); it('returns false with a signature generated using a different private key', async () => { - const dataU8A = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); + const data = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); const keyPairA = await Ed25519.generateKeyPair(); const keyPairB = await Ed25519.generateKeyPair(); let isValid: boolean; // Generate a signature using the private key from key pair B. - const signatureB = await Ed25519.sign({ key: keyPairB.privateKey, data: dataU8A }); + const signatureB = await Ed25519.sign({ key: keyPairB.privateKey, data }); // Verification should return false with the public key from key pair A. - isValid = await Ed25519.verify({ key: keyPairA.publicKey, signature: signatureB, data: dataU8A.buffer }); + isValid = await Ed25519.verify({ key: keyPairA.publicKey, signature: signatureB, data }); expect(isValid).to.be.false; }); }); }); describe('Secp256k1', () => { + describe('convertPublicKey method', () => { + it('converts an uncompressed public key to a compressed format', async () => { + // Generate the uncompressed public key. + const keyPair = await Secp256k1.generateKeyPair({ compressedPublicKey: false }); + const uncompressedPublicKey = keyPair.publicKey; + + // Attempt to convert to compressed format. + const compressedKey = await Secp256k1.convertPublicKey({ + publicKey : uncompressedPublicKey, + compressedPublicKey : true + }); + + // Confirm the length of the resulting public key is 33 bytes + expect(compressedKey.byteLength).to.equal(33); + }); + + it('converts a compressed public key to an uncompressed format', async () => { + // Generate the uncompressed public key. + const keyPair = await Secp256k1.generateKeyPair({ compressedPublicKey: true }); + const compressedPublicKey = keyPair.publicKey; + + const uncompressedKey = await Secp256k1.convertPublicKey({ + publicKey : compressedPublicKey, + compressedPublicKey : false + }); + + // Confirm the length of the resulting public key is 65 bytes + expect(uncompressedKey.byteLength).to.equal(65); + }); + + it('throws an error for an invalid compressed public key', async () => { + // Invalid compressed public key. + const invalidPublicKey = Convert.hex('fef0b998921eafb58f49efdeb0adc47123aa28a4042924236f08274d50c72fe7b0').toUint8Array(); + + try { + await Secp256k1.convertPublicKey({ + publicKey : invalidPublicKey, + compressedPublicKey : false + }); + expect.fail('Expected method to throw an error.'); + } catch (error) { + expect(error).to.be.instanceOf(Error); + expect((error as Error).message).to.include('Point of length 33 was invalid'); + } + }); + + it('throws an error for an invalid uncompressed public key', async () => { + // Here, generating a random byte array of size 65. It's unlikely to be a valid public key. + const invalidPublicKey = Convert.hex('dfebc16793a5737ac51f606a43524df8373c063e41d5a99b2f1530afd987284bd1c7cde1658a9a756e71f44a97b4783ea9dee5ccb7f1447eb4836d8de9bd4f81fd').toUint8Array(); + + try { + await Secp256k1.convertPublicKey({ + publicKey : invalidPublicKey, + compressedPublicKey : true + }); + expect.fail('Expected method to throw an error.'); + } catch (error) { + expect(error).to.be.instanceOf(Error); + expect((error as Error).message).to.include('Point of length 65 was invalid'); + } + }); + }); + describe('generateKeyPair()', () => { - it('returns a pair of keys of type ArrayBuffer', async () => { + it('returns a pair of keys of type Uint8Array', async () => { const keyPair = await Secp256k1.generateKeyPair(); expect(keyPair).to.have.property('privateKey'); expect(keyPair).to.have.property('publicKey'); - expect(keyPair.privateKey).to.be.instanceOf(ArrayBuffer); - expect(keyPair.publicKey).to.be.instanceOf(ArrayBuffer); + expect(keyPair.privateKey).to.be.instanceOf(Uint8Array); + expect(keyPair.publicKey).to.be.instanceOf(Uint8Array); }); it('returns a 32-byte private key', async () => { @@ -565,8 +614,54 @@ describe('Cryptographic Primitive Implementations', () => { }); }); + describe('getCurvePoints()', () => { + it('returns public key x and y coordinates given a public key', async () => { + for (const vector of secp256k1TestVectors) { + const key = Convert.hex(vector.publicKey.encoded).toUint8Array(); + const points = await Secp256k1.getCurvePoints({ key }); + expect(points.x).to.deep.equal(Convert.hex(vector.publicKey.x).toUint8Array()); + expect(points.y).to.deep.equal(Convert.hex(vector.publicKey.y).toUint8Array()); + } + }); + + it('returns public key x and y coordinates given a private key', async () => { + for (const vector of secp256k1TestVectors) { + const key = Convert.hex(vector.privateKey.encoded).toUint8Array(); + const points = await Secp256k1.getCurvePoints({ key }); + expect(points.x).to.deep.equal(Convert.hex(vector.publicKey.x).toUint8Array()); + expect(points.y).to.deep.equal(Convert.hex(vector.publicKey.y).toUint8Array()); + } + }); + + it('handles keys that require padded x-coordinate when converting from BigInt to bytes', async () => { + const key = Convert.hex('0206a1f9628c5bcd31f3bbc2f160ec98f99960147e04ea192f56c53a0086c5432d').toUint8Array(); + const points = await Secp256k1.getCurvePoints({ key }); + + const expectedX = Convert.hex('06a1f9628c5bcd31f3bbc2f160ec98f99960147e04ea192f56c53a0086c5432d').toUint8Array(); + const expectedY = Convert.hex('bf2efab7943be51219a283c0979ccba0fbe03f571e75b0eb338cc2ec01e70552').toUint8Array(); + expect(points.x).to.deep.equal(expectedX); + expect(points.y).to.deep.equal(expectedY); + }); + + it('handles keys that require padded y-coordinate when converting from BigInt to bytes', async () => { + const key = Convert.hex('032ff752fb8fc6af85c8682b0ca9d48901b2b9ac130f558bd1a9092240d42c4682').toUint8Array(); + const points = await Secp256k1.getCurvePoints({ key }); + + const expectedX = Convert.hex('2ff752fb8fc6af85c8682b0ca9d48901b2b9ac130f558bd1a9092240d42c4682').toUint8Array(); + const expectedY = Convert.hex('048c39d9ebdc1fd98bda38b7f00b93de1d2af5bb3ba8cb532ad47c1f36e19501').toUint8Array(); + expect(points.x).to.deep.equal(expectedX); + expect(points.y).to.deep.equal(expectedY); + }); + + it('throws error with invalid input key length', async () => { + await expect( + Secp256k1.getCurvePoints({ key: new Uint8Array(16) }) + ).to.eventually.be.rejectedWith(Error, 'Point of length 16 was invalid. Expected 33 compressed bytes or 65 uncompressed bytes'); + }); + }); + describe('getPublicKey()', () => { - let keyPair: BufferKeyPair; + let keyPair: BytesKeyPair; before(async () => { keyPair = await Secp256k1.generateKeyPair(); @@ -574,18 +669,20 @@ describe('Cryptographic Primitive Implementations', () => { it('returns a 33-byte compressed public key, by default', async () => { const publicKey = await Secp256k1.getPublicKey({ privateKey: keyPair.privateKey }); + expect(publicKey).to.be.instanceOf(Uint8Array); expect(publicKey.byteLength).to.equal(33); }); it('returns a 65-byte uncompressed public key, if specified', async () => { const publicKey = await Secp256k1.getPublicKey({ privateKey: keyPair.privateKey, compressedPublicKey: false }); + expect(publicKey).to.be.instanceOf(Uint8Array); expect(publicKey.byteLength).to.equal(65); }); }); describe('sharedSecret()', () => { - let otherPartyKeyPair: BufferKeyPair; - let ownKeyPair: BufferKeyPair; + let otherPartyKeyPair: BytesKeyPair; + let ownKeyPair: BytesKeyPair; beforeEach(async () => { otherPartyKeyPair = await Secp256k1.generateKeyPair(); @@ -597,7 +694,7 @@ describe('Cryptographic Primitive Implementations', () => { privateKey : ownKeyPair.privateKey, publicKey : otherPartyKeyPair.publicKey }); - expect(sharedSecret).to.be.instanceOf(ArrayBuffer); + expect(sharedSecret).to.be.instanceOf(Uint8Array); expect(sharedSecret.byteLength).to.equal(32); }); @@ -617,155 +714,159 @@ describe('Cryptographic Primitive Implementations', () => { }); describe('sign()', () => { - let keyPair: BufferKeyPair; + let keyPair: BytesKeyPair; before(async () => { keyPair = await Secp256k1.generateKeyPair(); }); - it('returns a 64-byte signature of type ArrayBuffer', async () => { + it('returns a 64-byte signature of type Uint8Array', async () => { const hash = 'SHA-256'; - const dataU8A = new Uint8Array([51, 52, 53]); - const signature = await Secp256k1.sign({ hash, key: keyPair.privateKey, data: dataU8A }); - expect(signature).to.be.instanceOf(ArrayBuffer); + const data = new Uint8Array([51, 52, 53]); + const signature = await Secp256k1.sign({ hash, key: keyPair.privateKey, data }); + expect(signature).to.be.instanceOf(Uint8Array); expect(signature.byteLength).to.equal(64); }); - it('accepts input data as ArrayBuffer, DataView, and TypedArray', async () => { - const dataU8A = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); + it('accepts input data as Uint8Array', async () => { + const data = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); const hash = 'SHA-256'; const key = keyPair.privateKey; - let signature: ArrayBuffer; + let signature: Uint8Array; - // ArrayBuffer - const dataArrayBuffer = dataU8A.buffer; - signature = await Secp256k1.sign({ hash, key, data: dataArrayBuffer }); - expect(signature).to.be.instanceOf(ArrayBuffer); + // TypedArray - Uint8Array + signature = await Secp256k1.sign({ hash, key, data }); + expect(signature).to.be.instanceOf(Uint8Array); + }); + }); - // DataView - const dataView = new DataView(dataArrayBuffer); - signature = await Secp256k1.sign({ hash, key, data: dataView }); - expect(signature).to.be.instanceOf(ArrayBuffer); + describe('validatePrivateKey()', () => { + it('returns true for valid private keys', async () => { + for (const vector of secp256k1TestVectors) { + const key = Convert.hex(vector.privateKey.encoded).toUint8Array(); + const isValid = await Secp256k1.validatePrivateKey({ key }); + expect(isValid).to.be.true; + } + }); - // TypedArray - Uint8Array - signature = await Secp256k1.sign({ hash, key, data: dataU8A }); - expect(signature).to.be.instanceOf(ArrayBuffer); + it('returns false for invalid private keys', async () => { + const key = Convert.hex('02fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f').toUint8Array(); + const isValid = await Secp256k1.validatePrivateKey({ key }); + expect(isValid).to.be.false; + }); + + it('returns false if a public key is given', async () => { + for (const vector of secp256k1TestVectors) { + const key = Convert.hex(vector.publicKey.encoded).toUint8Array(); + const isValid = await Secp256k1.validatePrivateKey({ key }); + expect(isValid).to.be.false; + } + }); + }); - // TypedArray - Int32Array - const dataI32A = new Int32Array([10, 20, 30, 40]); - signature = await Secp256k1.sign({ hash, key, data: dataI32A }); - expect(signature).to.be.instanceOf(ArrayBuffer); + describe('validatePublicKey()', () => { + it('returns true for valid public keys', async () => { + for (const vector of secp256k1TestVectors) { + const key = Convert.hex(vector.publicKey.encoded).toUint8Array(); + const isValid = await Secp256k1.validatePublicKey({ key }); + expect(isValid).to.be.true; + } + }); - // TypedArray - Uint32Array - const dataU32A = new Uint32Array([8, 7, 6, 5, 4, 3, 2, 1]); - signature = await Secp256k1.sign({ hash, key, data: dataU32A }); - expect(signature).to.be.instanceOf(ArrayBuffer); + it('returns false for invalid public keys', async () => { + const key = Convert.hex('02fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f').toUint8Array(); + const isValid = await Secp256k1.validatePublicKey({ key }); + expect(isValid).to.be.false; + }); + + it('returns false if a private key is given', async () => { + for (const vector of secp256k1TestVectors) { + const key = Convert.hex(vector.privateKey.encoded).toUint8Array(); + const isValid = await Secp256k1.validatePublicKey({ key }); + expect(isValid).to.be.false; + } }); }); describe('verify()', () => { - let keyPair: BufferKeyPair; + let keyPair: BytesKeyPair; before(async () => { keyPair = await Secp256k1.generateKeyPair(); }); it('returns a boolean result', async () => { - const dataU8A = new Uint8Array([51, 52, 53]); - const signature = await Secp256k1.sign({ hash: 'SHA-256', key: keyPair.privateKey, data: dataU8A }); + const data = new Uint8Array([51, 52, 53]); + const signature = await Secp256k1.sign({ hash: 'SHA-256', key: keyPair.privateKey, data }); - const isValid = await Secp256k1.verify({ hash: 'SHA-256', key: keyPair.publicKey, signature, data: dataU8A }); + const isValid = await Secp256k1.verify({ hash: 'SHA-256', key: keyPair.publicKey, signature, data }); expect(isValid).to.exist; expect(isValid).to.be.true; }); - it('accepts input data as ArrayBuffer, DataView, and TypedArray', async () => { - const dataU8A = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); + it('accepts input data as Uint8Array', async () => { + const data = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); const hash = 'SHA-256'; let isValid: boolean; - let signature: ArrayBuffer; - - // ArrayBuffer - const dataArrayBuffer = dataU8A.buffer; - signature = await Secp256k1.sign({ hash, key: keyPair.privateKey, data: dataArrayBuffer }); - isValid = await Secp256k1.verify({ hash, key: keyPair.publicKey, signature, data: dataArrayBuffer }); - expect(isValid).to.be.true; - - // DataView - const dataView = new DataView(dataArrayBuffer); - signature = await Secp256k1.sign({ hash, key: keyPair.privateKey, data: dataView }); - isValid = await Secp256k1.verify({ hash, key: keyPair.publicKey, signature, data: dataView }); - expect(isValid).to.be.true; + let signature: Uint8Array; // TypedArray - Uint8Array - signature = await Secp256k1.sign({ hash, key: keyPair.privateKey, data: dataU8A }); - isValid = await Secp256k1.verify({ hash, key: keyPair.publicKey, signature, data: dataU8A }); - expect(isValid).to.be.true; - - // TypedArray - Int32Array - const dataI32A = new Int32Array([10, 20, 30, 40]); - signature = await Secp256k1.sign({ hash, key: keyPair.privateKey, data: dataI32A }); - isValid = await Secp256k1.verify({ hash, key: keyPair.publicKey, signature, data: dataI32A }); - expect(isValid).to.be.true; - - // TypedArray - Uint32Array - const dataU32A = new Uint32Array([8, 7, 6, 5, 4, 3, 2, 1]); - signature = await Secp256k1.sign({ hash, key: keyPair.privateKey, data: dataU32A }); - isValid = await Secp256k1.verify({ hash, key: keyPair.publicKey, signature, data: dataU32A }); + signature = await Secp256k1.sign({ hash, key: keyPair.privateKey, data }); + isValid = await Secp256k1.verify({ hash, key: keyPair.publicKey, signature, data }); expect(isValid).to.be.true; }); it('accepts both compressed and uncompressed public keys', async () => { - let signature: ArrayBuffer; + let signature: Uint8Array; let isValid: boolean; const hash = 'SHA-256'; - const dataU8A = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); + const data = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); // Generate signature using the private key. - signature = await Secp256k1.sign({ hash, key: keyPair.privateKey, data: dataU8A }); + signature = await Secp256k1.sign({ hash, key: keyPair.privateKey, data }); // Attempt to verify the signature using a compressed public key. const compressedPublicKey = await Secp256k1.getPublicKey({ privateKey: keyPair.privateKey, compressedPublicKey: true }); - isValid = await Secp256k1.verify({ hash, key: compressedPublicKey, signature, data: dataU8A }); + isValid = await Secp256k1.verify({ hash, key: compressedPublicKey, signature, data }); expect(isValid).to.be.true; // Attempt to verify the signature using an uncompressed public key. const uncompressedPublicKey = await Secp256k1.getPublicKey({ privateKey: keyPair.privateKey, compressedPublicKey: false }); - isValid = await Secp256k1.verify({ hash, key: uncompressedPublicKey, signature, data: dataU8A }); + isValid = await Secp256k1.verify({ hash, key: uncompressedPublicKey, signature, data }); expect(isValid).to.be.true; }); it('returns false if the signed data was mutated', async () => { const hash = 'SHA-256'; - const dataU8A = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); + const data = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); let isValid: boolean; // Generate signature using the private key. - const signature = await Secp256k1.sign({ hash, key: keyPair.privateKey, data: dataU8A }); + const signature = await Secp256k1.sign({ hash, key: keyPair.privateKey, data }); // Verification should return true with the data used to generate the signature. - isValid = await Secp256k1.verify({ hash, key: keyPair.publicKey, signature, data: dataU8A }); + isValid = await Secp256k1.verify({ hash, key: keyPair.publicKey, signature, data }); expect(isValid).to.be.true; // Make a copy and flip the least significant bit (the rightmost bit) in the first byte of the array. - const mutatedDataU8A = new Uint8Array(dataU8A); - mutatedDataU8A[0] ^= 1 << 0; + const mutatedData = new Uint8Array(data); + mutatedData[0] ^= 1 << 0; // Verification should return false if the given data does not match the data used to generate the signature. - isValid = await Secp256k1.verify({ hash, key: keyPair.publicKey, signature, data: mutatedDataU8A }); + isValid = await Secp256k1.verify({ hash, key: keyPair.publicKey, signature, data: mutatedData }); expect(isValid).to.be.false; }); it('returns false if the signature was mutated', async () => { const hash = 'SHA-256'; - const dataU8A = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); + const data = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); let isValid: boolean; // Generate signature using the private key. - const signature = await Secp256k1.sign({ hash, key: keyPair.privateKey, data: dataU8A }); + const signature = await Secp256k1.sign({ hash, key: keyPair.privateKey, data }); // Verification should return true with the data used to generate the signature. - isValid = await Secp256k1.verify({ hash, key: keyPair.publicKey, signature, data: dataU8A }); + isValid = await Secp256k1.verify({ hash, key: keyPair.publicKey, signature, data }); expect(isValid).to.be.true; // Make a copy and flip the least significant bit (the rightmost bit) in the first byte of the array. @@ -773,22 +874,22 @@ describe('Cryptographic Primitive Implementations', () => { mutatedSignature[0] ^= 1 << 0; // Verification should return false if the signature was modified. - isValid = await Secp256k1.verify({ hash, key: keyPair.publicKey, signature: signature, data: mutatedSignature.buffer }); + isValid = await Secp256k1.verify({ hash, key: keyPair.publicKey, signature: signature, data: mutatedSignature }); expect(isValid).to.be.false; }); it('returns false with a signature generated using a different private key', async () => { const hash = 'SHA-256'; - const dataU8A = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); + const data = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); const keyPairA = await Secp256k1.generateKeyPair(); const keyPairB = await Secp256k1.generateKeyPair(); let isValid: boolean; // Generate a signature using the private key from key pair B. - const signatureB = await Secp256k1.sign({ hash, key: keyPairB.privateKey, data: dataU8A }); + const signatureB = await Secp256k1.sign({ hash, key: keyPairB.privateKey, data }); // Verification should return false with the public key from key pair A. - isValid = await Secp256k1.verify({ hash, key: keyPairA.publicKey, signature: signatureB, data: dataU8A.buffer }); + isValid = await Secp256k1.verify({ hash, key: keyPairA.publicKey, signature: signatureB, data }); expect(isValid).to.be.false; }); }); @@ -796,12 +897,12 @@ describe('Cryptographic Primitive Implementations', () => { describe('X25519', () => { describe('generateKeyPair()', () => { - it('returns a pair of keys of type ArrayBuffer', async () => { + it('returns a pair of keys of type Uint8Array', async () => { const keyPair = await X25519.generateKeyPair(); expect(keyPair).to.have.property('privateKey'); expect(keyPair).to.have.property('publicKey'); - expect(keyPair.privateKey).to.be.instanceOf(ArrayBuffer); - expect(keyPair.publicKey).to.be.instanceOf(ArrayBuffer); + expect(keyPair.privateKey).to.be.instanceOf(Uint8Array); + expect(keyPair.publicKey).to.be.instanceOf(Uint8Array); }); it('returns a 32-byte private key', async () => { @@ -816,7 +917,7 @@ describe('Cryptographic Primitive Implementations', () => { }); describe('getPublicKey()', () => { - let keyPair: BufferKeyPair; + let keyPair: BytesKeyPair; before(async () => { keyPair = await X25519.generateKeyPair(); @@ -824,65 +925,72 @@ describe('Cryptographic Primitive Implementations', () => { it('returns a 32-byte compressed public key', async () => { const publicKey = await X25519.getPublicKey({ privateKey: keyPair.privateKey }); + expect(publicKey).to.be.instanceOf(Uint8Array); expect(publicKey.byteLength).to.equal(32); }); }); describe('sharedSecret()', () => { - describe('sharedSecret()', () => { - let otherPartyKeyPair: BufferKeyPair; - let ownKeyPair: BufferKeyPair; + let otherPartyKeyPair: BytesKeyPair; + let ownKeyPair: BytesKeyPair; - beforeEach(async () => { - otherPartyKeyPair = await X25519.generateKeyPair(); - ownKeyPair = await X25519.generateKeyPair(); + beforeEach(async () => { + otherPartyKeyPair = await X25519.generateKeyPair(); + ownKeyPair = await X25519.generateKeyPair(); + }); + + it('generates a 32-byte compressed secret', async () => { + const sharedSecret = await X25519.sharedSecret({ + privateKey : ownKeyPair.privateKey, + publicKey : otherPartyKeyPair.publicKey }); + expect(sharedSecret).to.be.instanceOf(Uint8Array); + expect(sharedSecret.byteLength).to.equal(32); + }); - it('generates a 32-byte compressed secret, by default', async () => { - const sharedSecret = await X25519.sharedSecret({ - privateKey : ownKeyPair.privateKey, - publicKey : otherPartyKeyPair.publicKey - }); - expect(sharedSecret).to.be.instanceOf(ArrayBuffer); - expect(sharedSecret.byteLength).to.equal(32); + it('generates identical output if keypairs are swapped', async () => { + const sharedSecretOwnOther = await X25519.sharedSecret({ + privateKey : ownKeyPair.privateKey, + publicKey : otherPartyKeyPair.publicKey }); - it('generates identical output if keypairs are swapped', async () => { - const sharedSecretOwnOther = await X25519.sharedSecret({ - privateKey : ownKeyPair.privateKey, - publicKey : otherPartyKeyPair.publicKey - }); + const sharedSecretOtherOwn = await X25519.sharedSecret({ + privateKey : otherPartyKeyPair.privateKey, + publicKey : ownKeyPair.publicKey + }); - const sharedSecretOtherOwn = await X25519.sharedSecret({ - privateKey : otherPartyKeyPair.privateKey, - publicKey : ownKeyPair.publicKey - }); + expect(sharedSecretOwnOther).to.deep.equal(sharedSecretOtherOwn); + }); + }); - expect(sharedSecretOwnOther).to.deep.equal(sharedSecretOtherOwn); - }); + describe('validatePublicKey()', () => { + it('throws a not implemented error', async () => { + await expect( + X25519.validatePublicKey({ key: new Uint8Array(32) }) + ).to.eventually.be.rejectedWith(Error, 'Not implemented'); }); }); }); describe('XChaCha20', () => { describe('decrypt()', () => { - it('returns ArrayBuffer plaintext with length matching input', async () => { + it('returns Uint8Array plaintext with length matching input', async () => { const plaintext = await XChaCha20.decrypt({ data : new Uint8Array(10), - key : new ArrayBuffer(32), + key : new Uint8Array(32), nonce : new Uint8Array(24) }); - expect(plaintext).to.be.an('ArrayBuffer'); + expect(plaintext).to.be.an('Uint8Array'); expect(plaintext.byteLength).to.equal(10); }); it('passes test vectors', async () => { const input = { - data : Convert.hex('879b10a139674fe65087f59577ee2c1ab54655d900697fd02d953f53ddcc1ae476e8').toArrayBuffer(), - key : Convert.hex('79c99798ac67300bbb2704c95c341e3245f3dcb21761b98e52ff45b24f304fc4').toArrayBuffer(), - nonce : Convert.hex('b33ffd3096479bcfbc9aee49417688a0a2554f8d95389419').toArrayBuffer() + data : Convert.hex('879b10a139674fe65087f59577ee2c1ab54655d900697fd02d953f53ddcc1ae476e8').toUint8Array(), + key : Convert.hex('79c99798ac67300bbb2704c95c341e3245f3dcb21761b98e52ff45b24f304fc4').toUint8Array(), + nonce : Convert.hex('b33ffd3096479bcfbc9aee49417688a0a2554f8d95389419').toUint8Array() }; - const output = Convert.string(`Are You There Bob? It's Me, Alice.`).toArrayBuffer(); + const output = Convert.string(`Are You There Bob? It's Me, Alice.`).toUint8Array(); const ciphertext = await XChaCha20.decrypt({ data : input.data, @@ -892,63 +1000,26 @@ describe('Cryptographic Primitive Implementations', () => { expect(ciphertext).to.deep.equal(output); }); - - it('accepts plaintext input as ArrayBuffer, DataView, and TypedArray', async () => { - const input = { - data : Convert.hex('879b10a139674fe65087f59577ee2c1ab54655d900697fd02d953f53ddcc1ae476e8').toUint8Array(), - key : Convert.hex('79c99798ac67300bbb2704c95c341e3245f3dcb21761b98e52ff45b24f304fc4').toArrayBuffer(), - nonce : Convert.hex('b33ffd3096479bcfbc9aee49417688a0a2554f8d95389419').toArrayBuffer() - }; - let ciphertext: ArrayBuffer; - let output: ArrayBuffer; - output = Convert.string(`Are You There Bob? It's Me, Alice.`).toArrayBuffer(); - - // ArrayBuffer - const dataArrayBuffer = input.data.buffer; - ciphertext = await XChaCha20.decrypt({ data: dataArrayBuffer, key: input.key, nonce: input.nonce }); - expect(ciphertext).to.deep.equal(output); - - // DataView - const dataView = new DataView(dataArrayBuffer); - ciphertext = await XChaCha20.decrypt({ data: dataView, key: input.key, nonce: input.nonce }); - expect(ciphertext).to.deep.equal(output); - - // TypedArray - Uint8Array - ciphertext = await XChaCha20.decrypt({ data: input.data, key: input.key,nonce: input.nonce }); - expect(ciphertext).to.deep.equal(output); - - // TypedArray - Int32Array - const dataI32A = new Int32Array(Convert.hex('cce9758174083ac61aef90e73ace6e75').toArrayBuffer()); - ciphertext = await XChaCha20.decrypt({ data: dataI32A, key: input.key, nonce: input.nonce }); - output = (new Int32Array([10, 20, 30, 40])).buffer; - expect(ciphertext).to.deep.equal(output); - - // TypedArray - Uint32Array - const dataU32A = new Uint32Array(Convert.hex('cee9758167083ac602ef90e717ce6e75d3797590774e0cf062f013739da07387').toArrayBuffer()); - ciphertext = await XChaCha20.decrypt({ data: dataU32A, key: input.key, nonce: input.nonce }); - output = (new Uint32Array([8, 7, 6, 5, 4, 3, 2, 1])).buffer; - expect(ciphertext).to.deep.equal(output); - }); }); describe('encrypt()', () => { - it('returns ArrayBuffer ciphertext with length matching input', async () => { + it('returns Uint8Array ciphertext with length matching input', async () => { const ciphertext = await XChaCha20.encrypt({ data : new Uint8Array(10), - key : new ArrayBuffer(32), + key : new Uint8Array(32), nonce : new Uint8Array(24) }); - expect(ciphertext).to.be.an('ArrayBuffer'); + expect(ciphertext).to.be.an('Uint8Array'); expect(ciphertext.byteLength).to.equal(10); }); it('passes test vectors', async () => { const input = { - data : Convert.string(`Are You There Bob? It's Me, Alice.`).toArrayBuffer(), - key : Convert.hex('79c99798ac67300bbb2704c95c341e3245f3dcb21761b98e52ff45b24f304fc4').toArrayBuffer(), - nonce : Convert.hex('b33ffd3096479bcfbc9aee49417688a0a2554f8d95389419').toArrayBuffer() + data : Convert.string(`Are You There Bob? It's Me, Alice.`).toUint8Array(), + key : Convert.hex('79c99798ac67300bbb2704c95c341e3245f3dcb21761b98e52ff45b24f304fc4').toUint8Array(), + nonce : Convert.hex('b33ffd3096479bcfbc9aee49417688a0a2554f8d95389419').toUint8Array() }; - const output = Convert.hex('879b10a139674fe65087f59577ee2c1ab54655d900697fd02d953f53ddcc1ae476e8').toArrayBuffer(); + const output = Convert.hex('879b10a139674fe65087f59577ee2c1ab54655d900697fd02d953f53ddcc1ae476e8').toUint8Array(); const ciphertext = await XChaCha20.encrypt({ data : input.data, @@ -958,49 +1029,120 @@ describe('Cryptographic Primitive Implementations', () => { expect(ciphertext).to.deep.equal(output); }); + }); + + describe('generateKey()', () => { + it('returns a 32-byte secret key of type Uint8Array', async () => { + const secretKey = await XChaCha20.generateKey(); + expect(secretKey).to.be.instanceOf(Uint8Array); + expect(secretKey.byteLength).to.equal(32); + }); + }); + }); + + describe('XChaCha20Poly1305', () => { + describe('decrypt()', () => { + it('returns Uint8Array plaintext with length matching input', async () => { + const plaintext = await XChaCha20Poly1305.decrypt({ + data : Convert.hex('789e9689e5208d7fd9e1').toUint8Array(), + key : new Uint8Array(32), + nonce : new Uint8Array(24), + tag : Convert.hex('09701fb9f36ab77a0f136ca539229a34').toUint8Array() + }); + expect(plaintext).to.be.an('Uint8Array'); + expect(plaintext.byteLength).to.equal(10); + }); - it('accepts plaintext input as ArrayBuffer, DataView, and TypedArray', async () => { + it('passes test vectors', async () => { const input = { - data : Convert.string(`Are You There Bob? It's Me, Alice.`).toUint8Array(), - key : Convert.hex('79c99798ac67300bbb2704c95c341e3245f3dcb21761b98e52ff45b24f304fc4').toArrayBuffer(), - nonce : Convert.hex('b33ffd3096479bcfbc9aee49417688a0a2554f8d95389419').toArrayBuffer() + data : Convert.hex('80246ca517c0fb5860c19090a7e7a2b030dde4882520102cbc64fad937916596ca9d').toUint8Array(), + key : Convert.hex('79c99798ac67300bbb2704c95c341e3245f3dcb21761b98e52ff45b24f304fc4').toUint8Array(), + nonce : Convert.hex('b33ffd3096479bcfbc9aee49417688a0a2554f8d95389419').toUint8Array(), + tag : Convert.hex('9e10a121d990e6a290f6b534516aa32f').toUint8Array() }; - let ciphertext: ArrayBuffer; - let output: ArrayBuffer; - output = Convert.hex('879b10a139674fe65087f59577ee2c1ab54655d900697fd02d953f53ddcc1ae476e8').toArrayBuffer(); + const output = Convert.string(`Are You There Bob? It's Me, Alice.`).toUint8Array(); - // ArrayBuffer - const dataArrayBuffer = input.data.buffer; - ciphertext = await XChaCha20.encrypt({ data: dataArrayBuffer, key: input.key, nonce: input.nonce }); - expect(ciphertext).to.deep.equal(output); + const plaintext = await XChaCha20Poly1305.decrypt({ + data : input.data, + key : input.key, + nonce : input.nonce, + tag : input.tag + }); - // DataView - const dataView = new DataView(dataArrayBuffer); - ciphertext = await XChaCha20.encrypt({ data: dataView, key: input.key, nonce: input.nonce }); - expect(ciphertext).to.deep.equal(output); + expect(plaintext).to.deep.equal(output); + }); - // TypedArray - Uint8Array - ciphertext = await XChaCha20.encrypt({ data: input.data, key: input.key,nonce: input.nonce }); - expect(ciphertext).to.deep.equal(output); + it('throws an error if the wrong tag is given', async () => { + await expect( + XChaCha20Poly1305.decrypt({ + data : new Uint8Array(10), + key : new Uint8Array(32), + nonce : new Uint8Array(24), + tag : new Uint8Array(16) + }) + ).to.eventually.be.rejectedWith(Error, 'Wrong tag'); + }); + }); - // TypedArray - Int32Array - const dataI32A = new Int32Array([10, 20, 30, 40]); - ciphertext = await XChaCha20.encrypt({ data: dataI32A, key: input.key, nonce: input.nonce }); - output = Convert.hex('cce9758174083ac61aef90e73ace6e75').toArrayBuffer(); - expect(ciphertext).to.deep.equal(output); + describe('encrypt()', () => { + it('returns Uint8Array ciphertext and tag', async () => { + const { ciphertext, tag } = await XChaCha20Poly1305.encrypt({ + data : new Uint8Array(10), + key : new Uint8Array(32), + nonce : new Uint8Array(24) + }); + expect(ciphertext).to.be.an('Uint8Array'); + expect(ciphertext.byteLength).to.equal(10); + expect(tag).to.be.an('Uint8Array'); + expect(tag.byteLength).to.equal(16); + }); - // TypedArray - Uint32Array - const dataU32A = new Uint32Array([8, 7, 6, 5, 4, 3, 2, 1]); - ciphertext = await XChaCha20.encrypt({ data: dataU32A, key: input.key, nonce: input.nonce }); - output = Convert.hex('cee9758167083ac602ef90e717ce6e75d3797590774e0cf062f013739da07387').toArrayBuffer(); - expect(ciphertext).to.deep.equal(output); + it('accepts additional authenticated data', async () => { + const { ciphertext: ciphertextAad, tag: tagAad } = await XChaCha20Poly1305.encrypt({ + additionalData : new Uint8Array(64), + data : new Uint8Array(10), + key : new Uint8Array(32), + nonce : new Uint8Array(24) + }); + + const { ciphertext, tag } = await XChaCha20Poly1305.encrypt({ + data : new Uint8Array(10), + key : new Uint8Array(32), + nonce : new Uint8Array(24) + }); + + expect(ciphertextAad.byteLength).to.equal(10); + expect(ciphertext.byteLength).to.equal(10); + expect(ciphertextAad).to.deep.equal(ciphertext); + expect(tagAad).to.not.deep.equal(tag); + }); + + it('passes test vectors', async () => { + const input = { + data : Convert.string(`Are You There Bob? It's Me, Alice.`).toUint8Array(), + key : Convert.hex('79c99798ac67300bbb2704c95c341e3245f3dcb21761b98e52ff45b24f304fc4').toUint8Array(), + nonce : Convert.hex('b33ffd3096479bcfbc9aee49417688a0a2554f8d95389419').toUint8Array() + }; + const output = { + ciphertext : Convert.hex('80246ca517c0fb5860c19090a7e7a2b030dde4882520102cbc64fad937916596ca9d').toUint8Array(), + tag : Convert.hex('9e10a121d990e6a290f6b534516aa32f').toUint8Array() + }; + + const { ciphertext, tag } = await XChaCha20Poly1305.encrypt({ + data : input.data, + key : input.key, + nonce : input.nonce + }); + + expect(ciphertext).to.deep.equal(output.ciphertext); + expect(tag).to.deep.equal(output.tag); }); }); describe('generateKey()', () => { - it('returns a 32-byte secret key of type ArrayBuffer', async () => { - const secretKey = await XChaCha20.generateKey(); - expect(secretKey).to.be.instanceOf(ArrayBuffer); + it('returns a 32-byte secret key of type Uint8Array', async () => { + const secretKey = await XChaCha20Poly1305.generateKey(); + expect(secretKey).to.be.instanceOf(Uint8Array); expect(secretKey.byteLength).to.equal(32); }); }); diff --git a/packages/crypto/tests/fixtures/test-vectors/ed25519.ts b/packages/crypto/tests/fixtures/test-vectors/ed25519.ts new file mode 100644 index 000000000..261a00e56 --- /dev/null +++ b/packages/crypto/tests/fixtures/test-vectors/ed25519.ts @@ -0,0 +1,20 @@ +export const ed25519TestVectors = [ + { + id : '1', + privateKey : { + encoded: '4f2db3cf791aaa1a6445490117b1a110435394f4bef8e384c64dce9536053c5b' + }, + publicKey: { + encoded: 'b3cf2b4a6852f156ab1536c204ca6f2eed787bd44f4295104dcb9b6df8329386' + } + }, + { + id : '2', + privateKey : { + encoded: '9b65f2e65734d4f8b338e4a4c81457289564056890d3c539143ab292ad31ee87' + }, + publicKey: { + encoded: '20e95ce23a1b76d8538e8404f9ce22f2d5a0daaa327b07741a07f116e0e87e6e' + } + }, +]; \ No newline at end of file diff --git a/packages/crypto/tests/fixtures/test-vectors/jose.ts b/packages/crypto/tests/fixtures/test-vectors/jose.ts new file mode 100644 index 000000000..0aa31497e --- /dev/null +++ b/packages/crypto/tests/fixtures/test-vectors/jose.ts @@ -0,0 +1,428 @@ +export const cryptoKeyPairToJsonWebKeyTestVectors = [ + { + id : 'ckp.jwk.1', + cryptoKey : { + publicKey: { + algorithm : { name: 'ECDSA', namedCurve: 'secp256k1' }, + extractable : true, + material : '02c6cf53ccfc13fbdfb25d827636839d9874df3148eba88c07f07601645ca5a006', // Hex, compressed + type : 'public', + usages : ['verify'], + }, + privateKey: { + algorithm : { name: 'ECDSA', namedCurve: 'secp256k1' }, + extractable : true, + material : '1d70915381c9bcb940752c3892b6c3b4476a6906b6aee839227f3f38eaf91190', // Hex + type : 'private', + usages : ['sign'], + } + }, + jsonWebKey: { + publicKeyJwk: { + 'alg' : 'ES256K', + 'crv' : 'secp256k1', + 'ext' : 'true', + 'key_ops' : ['verify'], + 'kty' : 'EC', + 'x' : 'xs9TzPwT-9-yXYJ2NoOdmHTfMUjrqIwH8HYBZFyloAY', // Base64url + 'y' : 'tMa4vfJC9rR8S87Sx9yEHACYOWOh7_UWLiFal56lObY', // Base64url + }, + privateKeyJwk: { + 'alg' : 'ES256K', + 'crv' : 'secp256k1', + 'd' : 'HXCRU4HJvLlAdSw4krbDtEdqaQa2rug5In8_OOr5EZA', // Base64url + 'ext' : 'true', + 'key_ops' : ['sign'], + 'kty' : 'EC', + 'x' : 'xs9TzPwT-9-yXYJ2NoOdmHTfMUjrqIwH8HYBZFyloAY', // Base64url + 'y' : 'tMa4vfJC9rR8S87Sx9yEHACYOWOh7_UWLiFal56lObY', // Base64url + }, + } + }, + { + id : 'ckp.jwk.2', + cryptoKey : { + publicKey: { + algorithm : { name: 'ECDSA', namedCurve: 'secp256k1' }, + extractable : true, + material : '045d67b538b1f3dc38326a975b17c4312b7620c39b656b3012dc9205c5804870c7ab53846c0b4c6f6c0267f08b9ac7075fe1f0b617d013630d92a3c760908b71e3', // Hex, uncompressed + type : 'public', + usages : ['verify'], + }, + privateKey: { + algorithm : { name: 'ECDSA', namedCurve: 'secp256k1' }, + extractable : true, + material : 'c1f488e4919027f1da827a3f25c8121f9092f5d940c0da9a52cb36e192fa1610', // Hex + type : 'private', + usages : ['sign'], + } + }, + jsonWebKey: { + publicKeyJwk: { + 'alg' : 'ES256K', + 'crv' : 'secp256k1', + 'ext' : 'true', + 'key_ops' : ['verify'], + 'kty' : 'EC', + 'x' : 'XWe1OLHz3DgyapdbF8QxK3Ygw5tlazAS3JIFxYBIcMc', // Base64url + 'y' : 'q1OEbAtMb2wCZ_CLmscHX-HwthfQE2MNkqPHYJCLceM', // Base64url + }, + privateKeyJwk: { + 'alg' : 'ES256K', + 'crv' : 'secp256k1', + 'd' : 'wfSI5JGQJ_Hagno_JcgSH5CS9dlAwNqaUss24ZL6FhA', // Base64url + 'ext' : 'true', + 'key_ops' : ['sign'], + 'kty' : 'EC', + 'x' : 'XWe1OLHz3DgyapdbF8QxK3Ygw5tlazAS3JIFxYBIcMc', // Base64url + 'y' : 'q1OEbAtMb2wCZ_CLmscHX-HwthfQE2MNkqPHYJCLceM', // Base64url + }, + } + }, + { + id : 'ckp.jwk.3', + cryptoKey : { + publicKey: { + algorithm : { name: 'EdDSA', namedCurve: 'Ed25519' }, + extractable : true, + material : 'ae92a70cff05e3f8f0bd0ef10e492e2b1d7ae4e4b0732ad0be61169767a28085', // Hex + type : 'public', + usages : ['verify'], + }, + privateKey: { + algorithm : { name: 'EdDSA', namedCurve: 'Ed25519' }, + extractable : true, + material : 'f69e3da1db3fc8b7474224e3271099dab537807212477ad034ae52f3e39d8782', // Hex + type : 'private', + usages : ['sign'], + } + }, + jsonWebKey: { + publicKeyJwk: { + 'alg' : 'EdDSA', + 'crv' : 'Ed25519', + 'ext' : 'true', + 'key_ops' : ['verify'], + 'kty' : 'OKP', + 'x' : 'rpKnDP8F4_jwvQ7xDkkuKx165OSwcyrQvmEWl2eigIU', // Base64url + }, + privateKeyJwk: { + 'alg' : 'EdDSA', + 'crv' : 'Ed25519', + 'd' : '9p49ods_yLdHQiTjJxCZ2rU3gHISR3rQNK5S8-Odh4I', // Base64url + 'ext' : 'true', + 'key_ops' : ['sign'], + 'kty' : 'OKP', + 'x' : 'rpKnDP8F4_jwvQ7xDkkuKx165OSwcyrQvmEWl2eigIU', // Base64url + }, + } + }, + { + id : 'ckp.jwk.4', + cryptoKey : { + publicKey: { + algorithm : { name: 'ECDH', namedCurve: 'X25519' }, + extractable : true, + material : '796037a1434a9b79d9374bea882fed0a53c2901ce737947463d3687c99286973', // Hex + type : 'public', + usages : ['deriveBits', 'deriveKey'], + }, + privateKey: { + algorithm : { name: 'ECDH', namedCurve: 'X25519' }, + extractable : true, + material : '20a6d2ab343efc5d8718af1afb3157984b63712edc5f5c1c77bcf8f732f8b545', // Hex + type : 'private', + usages : ['deriveBits', 'deriveKey'], + } + }, + jsonWebKey: { + publicKeyJwk: { + 'crv' : 'X25519', + 'ext' : 'true', + 'key_ops' : ['deriveBits', 'deriveKey'], + 'kty' : 'OKP', + 'x' : 'eWA3oUNKm3nZN0vqiC_tClPCkBznN5R0Y9NofJkoaXM', // Base64url + }, + privateKeyJwk: { + 'crv' : 'X25519', + 'd' : 'IKbSqzQ-_F2HGK8a-zFXmEtjcS7cX1wcd7z49zL4tUU', // Base64url + 'ext' : 'true', + 'key_ops' : ['deriveBits', 'deriveKey'], + 'kty' : 'OKP', + 'x' : 'eWA3oUNKm3nZN0vqiC_tClPCkBznN5R0Y9NofJkoaXM', // Base64url + }, + } + }, +]; + +export const cryptoKeyToJwkTestVectors = [ + { + id : 'csk.jwk.1', + cryptoKey : { + algorithm : { name: 'AES-CTR', length: 256 }, + extractable : true, + material : '510b48012fab99607ebe03601b894fae74d2dad36fc033ca97daecd0bf480a75', // Hex + type : 'secret', + usages : ['encrypt', 'decrypt'], + }, + jsonWebKey: { + 'alg' : 'A256CTR', + 'ext' : 'true', + 'key_ops' : ['encrypt', 'decrypt'], + 'k' : 'UQtIAS-rmWB-vgNgG4lPrnTS2tNvwDPKl9rs0L9ICnU', // Base64url + 'kty' : 'oct', + } + }, + { + id : 'csk.jwk.2', + cryptoKey : { + algorithm : { name: 'AES-GCM', length: 256 }, + extractable : true, + material : 'fa919d00b0edc66c73efcc2325073fff8173bd30956174cd50b3381f438a56ac', // Hex + type : 'secret', + usages : ['encrypt', 'decrypt'], + }, + jsonWebKey: { + 'alg' : 'A256GCM', + 'ext' : 'true', + 'key_ops' : ['encrypt', 'decrypt'], + 'k' : '-pGdALDtxmxz78wjJQc__4FzvTCVYXTNULM4H0OKVqw', // Base64url + 'kty' : 'oct', + } + }, + { + id : 'csk.jwk.3', + cryptoKey : { + algorithm : { name: 'HMAC', hash: { name: 'SHA-256' } }, + extractable : true, + material : 'dc739a7be3ffc152af69bc45dfb02d81cfe313c7cb074c643144a9c15588d87468bafa02da20ab7fc8f7498916b184459b84aff27736be9cc8f60e49ca0d01c7', // Hex + type : 'secret', + usages : ['sign', 'verify'], + }, + jsonWebKey: { + 'alg' : 'HS256', + 'ext' : 'true', + 'key_ops' : ['sign', 'verify'], + 'k' : '3HOae-P_wVKvabxF37Atgc_jE8fLB0xkMUSpwVWI2HRouvoC2iCrf8j3SYkWsYRFm4Sv8nc2vpzI9g5Jyg0Bxw', // Base64url + 'kty' : 'oct', + } + }, +]; + +export const joseToWebCryptoTestVectors = [ + { + id : 'jose.wc.1', + jose : { crv: 'Ed25519', alg: 'EdDSA', kty: 'OKP' }, + webCrypto : { namedCurve: 'Ed25519', name: 'EdDSA' } + }, + { + id : 'jose.wc.2', + jose : { crv: 'Ed448', alg: 'EdDSA', kty: 'OKP' }, + webCrypto : { namedCurve: 'Ed448', name: 'EdDSA' } + }, + { + id : 'jose.wc.3', + jose : { crv: 'X25519', kty: 'OKP' }, + webCrypto : { namedCurve: 'X25519', name: 'ECDH' } + }, + { + id : 'jose.wc.4', + jose : { crv: 'secp256k1', alg: 'ES256K', kty: 'EC' }, + webCrypto : { namedCurve: 'secp256k1', name: 'ECDSA' } + }, + { + id : 'jose.wc.5', + jose : { crv: 'secp256k1', kty: 'EC' }, + webCrypto : { namedCurve: 'secp256k1', name: 'ECDH' } + }, + { + id : 'jose.wc.6', + jose : { crv: 'P-256', alg: 'ES256', kty: 'EC' }, + webCrypto : { namedCurve: 'P-256', name: 'ECDSA' } + }, + { + id : 'jose.wc.7', + jose : { crv: 'P-384', alg: 'ES384', kty: 'EC' }, + webCrypto : { namedCurve: 'P-384', name: 'ECDSA' } + }, + { + id : 'jose.wc.8', + jose : { crv: 'P-521', alg: 'ES512', kty: 'EC' }, + webCrypto : { namedCurve: 'P-521', name: 'ECDSA' } + }, + { + id : 'jose.wc.9', + jose : { alg: 'A128CBC', kty: 'oct' }, + webCrypto : { name: 'AES-CBC', length: 128 } + }, + { + id : 'jose.wc.10', + jose : { alg: 'A192CBC', kty: 'oct' }, + webCrypto : { name: 'AES-CBC', length: 192 } + }, + { + id : 'jose.wc.11', + jose : { alg: 'A256CBC', kty: 'oct' }, + webCrypto : { name: 'AES-CBC', length: 256 } + }, + { + id : 'jose.wc.12', + jose : { alg: 'A128CTR', kty: 'oct' }, + webCrypto : { name: 'AES-CTR', length: 128 } + }, + { + id : 'jose.wc.13', + jose : { alg: 'A192CTR', kty: 'oct' }, + webCrypto : { name: 'AES-CTR', length: 192 } + }, + { + id : 'jose.wc.14', + jose : { alg: 'A256CTR', kty: 'oct' }, + webCrypto : { name: 'AES-CTR', length: 256 } + }, + { + id : 'jose.wc.15', + jose : { alg: 'A128GCM', kty: 'oct' }, + webCrypto : { name: 'AES-GCM', length: 128 } + }, + { + id : 'jose.wc.16', + jose : { alg: 'A192GCM', kty: 'oct' }, + webCrypto : { name: 'AES-GCM', length: 192 } + }, + { + id : 'jose.wc.17', + jose : { alg: 'A256GCM', kty: 'oct' }, + webCrypto : { name: 'AES-GCM', length: 256 } + }, + { + id : 'jose.wc.18', + jose : { alg: 'HS256', kty: 'oct' }, + webCrypto : { name: 'HMAC', hash: { name: 'SHA-256' } } + }, + { + id : 'jose.wc.19', + jose : { alg: 'HS384', kty: 'oct' }, + webCrypto : { name: 'HMAC', hash: { name: 'SHA-384' } } + }, + { + id : 'jose.wc.20', + jose : { alg: 'HS512', kty: 'oct' }, + webCrypto : { name: 'HMAC', hash: { name: 'SHA-512' } } + }, +]; + +export const keyToJwkTestVectorsKeyMaterial = '72e63e7c4bbf575b386fc1db1b3cbff5539a36dc6250fccb9fa28e013773d24b'; +export const keyToJwkMulticodecTestVectors = [ + { + input : 'ed25519-pub', + output : { + alg : 'EdDSA', + crv : 'Ed25519', + kty : 'OKP', + x : 'cuY-fEu_V1s4b8HbGzy_9VOaNtxiUPzLn6KOATdz0ks' + } + }, + { + input : 'ed25519-priv', + output : { + d : '', + alg : 'EdDSA', + crv : 'Ed25519', + kty : 'OKP', + x : 'c5UR1q2r1lOT_ygDhSkU3paf5Bmukg-jX-1t4kIKJvA' + } + }, + { + input : 'secp256k1-pub', + output : { + alg : 'ES256K', + crv : 'secp256k1', + kty : 'EC', + x : '_TihFv5t24hjWsRcdZBeEJa65hQB5aiOYmG6mMu1RZA', + y : 'UfiOGckhJuh9f3-Yi7g-jTILYP6vEWOSF1drwjBHebA' + } + }, + { + input : 'secp256k1-priv', + output : { + d : '', + alg : 'ES256K', + crv : 'secp256k1', + kty : 'EC', + x : '_TihFv5t24hjWsRcdZBeEJa65hQB5aiOYmG6mMu1RZA', + y : 'UfiOGckhJuh9f3-Yi7g-jTILYP6vEWOSF1drwjBHebA' + } + }, + { + input : 'x25519-pub', + output : { + crv : 'X25519', + kty : 'OKP', + x : 'cuY-fEu_V1s4b8HbGzy_9VOaNtxiUPzLn6KOATdz0ks' + } + }, + { + input : 'x25519-priv', + output : { + d : '', + crv : 'X25519', + kty : 'OKP', + x : 'MBZd77wAy5932AEP7MHXOevv_MLzzD9OP_fZAOlnIWM' + } + } +]; +export const keyToJwkWebCryptoTestVectors = [ + { + input : { namedCurve: 'Ed25519', name: 'EdDSA' }, + output : { + alg : 'EdDSA', + crv : 'Ed25519', + kty : 'OKP', + x : 'cuY-fEu_V1s4b8HbGzy_9VOaNtxiUPzLn6KOATdz0ks' + } + }, + { + input : { namedCurve: 'X25519', name: 'ECDH' }, + output : { + crv : 'X25519', + kty : 'OKP', + x : 'cuY-fEu_V1s4b8HbGzy_9VOaNtxiUPzLn6KOATdz0ks' + } + }, + { + input : { namedCurve: 'secp256k1', name: 'ECDSA' }, + output : { + alg : 'ES256K', + crv : 'secp256k1', + kty : 'EC', + x : '_TihFv5t24hjWsRcdZBeEJa65hQB5aiOYmG6mMu1RZA', + y : 'UfiOGckhJuh9f3-Yi7g-jTILYP6vEWOSF1drwjBHebA' + } + }, + { + input : { namedCurve: 'secp256k1', name: 'ECDH' }, + output : { + crv : 'secp256k1', + kty : 'EC', + x : '_TihFv5t24hjWsRcdZBeEJa65hQB5aiOYmG6mMu1RZA', + y : 'UfiOGckhJuh9f3-Yi7g-jTILYP6vEWOSF1drwjBHebA' + } + }, + { + input : { name: 'AES-CBC', length: 128 }, + output : { + alg : 'A128CBC', + kty : 'oct', + k : 'cuY-fEu_V1s4b8HbGzy_9VOaNtxiUPzLn6KOATdz0ks' + } + }, + { + input : { name: 'HMAC', hash: { name: 'SHA-256' } }, + output : { + alg : 'HS256', + kty : 'oct', + k : 'cuY-fEu_V1s4b8HbGzy_9VOaNtxiUPzLn6KOATdz0ks' + } + } +]; \ No newline at end of file diff --git a/packages/crypto/tests/fixtures/test-vectors/secp256k1.ts b/packages/crypto/tests/fixtures/test-vectors/secp256k1.ts new file mode 100644 index 000000000..f6b63dfea --- /dev/null +++ b/packages/crypto/tests/fixtures/test-vectors/secp256k1.ts @@ -0,0 +1,46 @@ +export const secp256k1TestVectors = [ + { + id : '1', + privateKey : { + encoded: '740ec69810de9ad1b8f298f1d2c0e6a52dd1e958dc2afc85764bec169c222e88' + }, + publicKey: { + encoded : '043752951274023296c8a74b0ffe42f82ff4b4d4bba4326477422703f761f59258c26a7465b9a77ac0c3f1cedb139c428b0b1fbb5516867b527636f3286f705553', + x : '3752951274023296c8a74b0ffe42f82ff4b4d4bba4326477422703f761f59258', + y : 'c26a7465b9a77ac0c3f1cedb139c428b0b1fbb5516867b527636f3286f705553' + } + }, + { + id : '2', + privateKey : { + encoded: 'b4713736a3562ff9b7b9e56ad2a533f241610e88217536cf2e620967daf91fd4' + }, + publicKey: { + encoded : '042dc60f3eed21d861fe7ccd353fb87e4dba6d0f453a71d4f8a1d2a17fe5486fd72a1d3bb247c3ca44e2a4d94cc616d6ce991fca220262c51d4edfcd3a1f55c9b4', + x : '2dc60f3eed21d861fe7ccd353fb87e4dba6d0f453a71d4f8a1d2a17fe5486fd7', + y : '2a1d3bb247c3ca44e2a4d94cc616d6ce991fca220262c51d4edfcd3a1f55c9b4' + }, + }, + { + id : '3', + privateKey : { + encoded: 'ea3db478f42cdbca7dbfe521167b03f40a5245370cba07142868c21d0082b391' + }, + publicKey: { + encoded : '037a549a3bdc432592ed40f2549e8668172e8bf1c3985066199472477f767b08f3', + x : '7a549a3bdc432592ed40f2549e8668172e8bf1c3985066199472477f767b08f3', + y : 'a5d03261db10f90f42af658c88f56aaf96fb1561f9c70f61ebe2c5bd2870b571' + } + }, + { + id : '4', + privateKey : { + encoded: '1b23fe831540368c37ec150febdaecc3dc47168585f3171a705f919357f9fff7' + }, + publicKey: { + encoded : '02ea7dd6427cdc1bb1b79584cab8e8109bf98e1cfef6c8dc9d8005d8e49ef1c150', + x : 'ea7dd6427cdc1bb1b79584cab8e8109bf98e1cfef6c8dc9d8005d8e49ef1c150', + y : 'e02763fa1504fa357acbb00c6711b8733c0a5938ebdaf228abd6ccbe7dbc6f80' + } + } +]; \ No newline at end of file diff --git a/packages/crypto/tests/jose.spec.ts b/packages/crypto/tests/jose.spec.ts new file mode 100644 index 000000000..a0d0aa2c4 --- /dev/null +++ b/packages/crypto/tests/jose.spec.ts @@ -0,0 +1,236 @@ +import chai, { expect } from 'chai'; +import { Convert } from '@web5/common'; +import chaiAsPromised from 'chai-as-promised'; + +import type { JsonWebKey } from '../src/jose.js'; +import type { Web5Crypto } from '../src/types/web5-crypto.js'; + +import { CryptoKeyWithJwk, Jose } from '../src/jose.js'; +import { + cryptoKeyToJwkTestVectors, + cryptoKeyPairToJsonWebKeyTestVectors, + joseToWebCryptoTestVectors, + keyToJwkWebCryptoTestVectors, + keyToJwkMulticodecTestVectors, + keyToJwkTestVectorsKeyMaterial +} from './fixtures/test-vectors/jose.js'; + +chai.use(chaiAsPromised); + +describe('CryptoKeyWithJwk()', () => { + it('converts private CryptoKeys to JWK', async () => { + for (const vector of cryptoKeyPairToJsonWebKeyTestVectors) { + const privateKey = { + ...vector.cryptoKey.privateKey, + material: Convert.hex(vector.cryptoKey.privateKey.material).toUint8Array() + } as Web5Crypto.CryptoKey; + + const cryptoKey = new CryptoKeyWithJwk( + privateKey.algorithm, + privateKey.extractable, + privateKey.material, + privateKey.type, + privateKey.usages + ); + + const jsonWebKey = await cryptoKey.toJwk(); + + expect(jsonWebKey).to.deep.equal(vector.jsonWebKey.privateKeyJwk); + } + }); + + it('converts public CryptoKeys to JWK', async () => { + for (const vector of cryptoKeyPairToJsonWebKeyTestVectors) { + const publicKey = { + ...vector.cryptoKey.publicKey, + material: Convert.hex(vector.cryptoKey.publicKey.material).toUint8Array() + } as Web5Crypto.CryptoKey; + + const cryptoKey = new CryptoKeyWithJwk( + publicKey.algorithm, + publicKey.extractable, + publicKey.material, + publicKey.type, + publicKey.usages + ); + + const jsonWebKey = await cryptoKey.toJwk(); + + expect(jsonWebKey).to.deep.equal(vector.jsonWebKey.publicKeyJwk); + } + }); + + it('converts secret CryptoKeys to JWK', async () => { + for (const vector of cryptoKeyToJwkTestVectors) { + const secretKey = { + ...vector.cryptoKey, + material: Convert.hex(vector.cryptoKey.material).toUint8Array() + } as Web5Crypto.CryptoKey; + + const cryptoKey = new CryptoKeyWithJwk( + secretKey.algorithm, + secretKey.extractable, + secretKey.material, + secretKey.type, + secretKey.usages + ); + + const jsonWebKey = await cryptoKey.toJwk(); + + expect(jsonWebKey).to.deep.equal(vector.jsonWebKey); + } + }); + + it('converts public CryptoKeys with extractable=false', async () => { + for (const vector of cryptoKeyPairToJsonWebKeyTestVectors) { + const publicKey = { + ...vector.cryptoKey.publicKey, + material: Convert.hex(vector.cryptoKey.publicKey.material).toUint8Array() + } as Web5Crypto.CryptoKey; + + const cryptoKey = new CryptoKeyWithJwk( + publicKey.algorithm, + false, // override extractable to false + publicKey.material, + publicKey.type, + publicKey.usages + ); + + const jsonWebKey = await cryptoKey.toJwk(); + + expect(jsonWebKey).to.deep.equal({ ...vector.jsonWebKey.publicKeyJwk, ext: 'false' }); + } + }); + + it('throws an error with unsupported algorithms', async () => { + const cryptoKey = new CryptoKeyWithJwk( + { name: 'ECDSA', namedCurve: 'P-256' }, // algorithm identifier + false, // extractable + new Uint8Array(32), // material aka key material + 'private', // key type + ['sign', 'verify'] // key usages + ); + + await expect( + cryptoKey.toJwk() + ).to.eventually.be.rejectedWith(Error, 'Unsupported key to JWK conversion: P-256'); + }); +}); + +describe('Jose', () => { + describe('joseToWebCrypto()', () => { + it('translates algorithm format from JOSE to WebCrypto', () => { + let webCrypto: Web5Crypto.GenerateKeyOptions; + for (const vector of joseToWebCryptoTestVectors) { + webCrypto = Jose.joseToWebCrypto(vector.jose as JsonWebKey); + expect(webCrypto).to.deep.equal(vector.webCrypto); + } + }); + + it('throws an error if required parameters are missing', () => { + expect( + () => Jose.joseToWebCrypto({}) + ).to.throw(TypeError, 'One or more parameters missing'); + }); + + it('throws an error if an unknown JOSE algorithm is specified', () => { + expect( + () => Jose.joseToWebCrypto({ alg: 'non-existent' }) + ).to.throw(Error, `Unsupported JOSE to WebCrypto conversion: 'non-existent'`); + + expect( + // @ts-expect-error because invalid algorithm was intentionally specified to trigger an error. + () => Jose.joseToWebCrypto({ crv: 'non-existent' }) + ).to.throw(Error, `Unsupported JOSE to WebCrypto conversion: 'non-existent'`); + }); + }); + + describe('jwkThumbprint()', () => { + it('passes RFC 7638 test vector', async () => { + // @see {@link https://datatracker.ietf.org/doc/html/rfc7638#section-3.1 | Example JWK Thumbprint Computation} + const jwk: JsonWebKey = { + 'kty' : 'RSA', + 'n' : '0vx7agoebGcQSuuPiLJXZptN9nndrQmbXEps2aiAFbWhM78LhWx4cbbfAAtVT86zwu1RK7aPFFxuhDR1L6tSoc_BJECPebWKRXjBZCiFV4n3oknjhMstn64tZ_2W-5JsGY4Hc5n9yBXArwl93lqt7_RN5w6Cf0h4QyQ5v-65YGjQR0_FDW2QvzqY368QQMicAtaSqzs8KJZgnYb9c7d0zgdAZHzu6qMQvRL5hajrn1n91CbOpbISD08qNLyrdkt-bFTWhAI4vMQFh6WeZu0fM4lFd2NcRwr3XPksINHaQ-G_xBniIqbw0Ls1jF44-csFCur-kEgU8awapJzKnqDKgw', + 'e' : 'AQAB', + 'alg' : 'RS256', + 'kid' : '2011-04-29' + }; + + const jwkThumbprint = await Jose.jwkThumbprint({ key: jwk }); + expect(jwkThumbprint).to.equal('NzbLsXh8uDCcd-6MNwXF4W_7noWXFZAfHkxZsRGC9Xs'); + }); + }); + + describe('keyToJwk()', () => { + it('converts key with Jose parameters (from WebCrypto) into JWK', async () => { + let jwkParams: Partial; + const keyMaterial = Convert.hex(keyToJwkTestVectorsKeyMaterial).toUint8Array(); + + for (const vector of keyToJwkWebCryptoTestVectors) { + jwkParams = Jose.webCryptoToJose(vector.input); + const jwk = await Jose.keyToJwk({ keyMaterial, keyType: 'public', ...jwkParams }); + expect(jwk).to.deep.equal(vector.output); + } + }); + + it('converts key with Jose parameters (from Multicodec) into JWK', async () => { + let jwkParams: Partial; + const keyMaterial = Convert.hex(keyToJwkTestVectorsKeyMaterial).toUint8Array(); + + for (const vector of keyToJwkMulticodecTestVectors) { + jwkParams = await Jose.multicodecToJose({ name: vector.input }); + const keyType = vector.input.includes('priv') ? 'private' : 'public'; + const jwk = await Jose.keyToJwk({ keyMaterial, keyType, ...jwkParams }); + expect(jwk).to.deep.equal(vector.output); + } + }); + + it('throws an error for unsupported conversion', async () => { + let jwkParams: Partial; + const testVectors = [ + { namedCurve: 'Ed448', name: 'EdDSA' }, + { namedCurve: 'P-256', name: 'ECDSA' }, + { namedCurve: 'P-384', name: 'ECDSA' }, + { namedCurve: 'P-521', name: 'ECDSA' } + ]; + const keyMaterial = new Uint8Array(32); + for (const vector of testVectors) { + jwkParams = Jose.webCryptoToJose(vector); + await expect( + Jose.keyToJwk({ keyMaterial, keyType: 'public', ...jwkParams }) + ).to.eventually.be.rejectedWith(Error, 'Unsupported key to JWK conversion'); + } + }); + }); + + describe('webCryptoToJose()', () => { + it('translates algorithm format from WebCrypto to JOSE', () => { + let jose: Partial; + for (const vector of joseToWebCryptoTestVectors) { + jose = Jose.webCryptoToJose(vector.webCrypto); + expect(jose).to.deep.equal(vector.jose); + } + }); + + it('throws an error if required parameters are missing', () => { + expect( + // @ts-expect-error because parameters are intentionally omitted to trigger an error. + () => Jose.webCryptoToJose({}) + ).to.throw(TypeError, 'One or more parameters missing'); + }); + + it('throws an error if an unknown WebCrypto algorithm is specified', () => { + expect( + () => Jose.webCryptoToJose({ name: 'non-existent', namedCurve: 'non-existent' }) + ).to.throw(Error, `Unsupported WebCrypto to JOSE conversion: 'non-existent:non-existent'`); + + expect( + () => Jose.webCryptoToJose({ name: 'non-existent', length: 64 }) + ).to.throw(Error, `Unsupported WebCrypto to JOSE conversion: 'non-existent:64'`); + + expect( + () => Jose.webCryptoToJose({ name: 'non-existent', hash: { name: 'SHA-1' } }) + ).to.throw(Error, `Unsupported WebCrypto to JOSE conversion: 'non-existent:SHA-1'`); + }); + }); +}); \ No newline at end of file diff --git a/packages/crypto/tests/utils-new.spec.ts b/packages/crypto/tests/utils-new.spec.ts deleted file mode 100644 index 7d727c3a6..000000000 --- a/packages/crypto/tests/utils-new.spec.ts +++ /dev/null @@ -1,60 +0,0 @@ -import { expect } from 'chai'; - -import { checkValidProperty, checkRequiredProperty, randomUuid } from '../src/utils-new.js'; - -describe('Crypto Utils', () => { - describe('checkValidProperty()', () => { - it('should not throw for a property in the allowed list', () => { - expect(() => checkValidProperty({ property: 'foo', allowedProperties: ['foo', 'bar']})).to.not.throw(); - expect(() => checkValidProperty({ property: 'foo', allowedProperties: new Set(['foo', 'bar'])})).to.not.throw(); - expect(() => checkValidProperty({ property: 'foo', allowedProperties: new Map([['foo', 1], ['bar', 2]])})).to.not.throw(); - }); - - it('throws an error if required arguments are missing', () => { - expect(() => checkValidProperty({ property: 'foo' } as any)).to.throw(TypeError, 'required arguments missing'); - expect(() => checkValidProperty({ allowedProperties: ['foo', 'bar'] } as any)).to.throw(TypeError, 'required arguments missing'); - // @ts-expect-error because both arguments are intentionally omitted. - expect(() => checkValidProperty()).to.throw(TypeError, 'required arguments missing'); - }); - - it('throws an error if the property does not exist', () => { - expect(() => checkValidProperty({ property: 'baz', allowedProperties: ['foo', 'bar']})).to.throw(TypeError, 'Out of range'); - expect(() => checkValidProperty({ property: 'baz', allowedProperties: new Set(['foo', 'bar'])})).to.throw(TypeError, 'Out of range'); - expect(() => checkValidProperty({ property: 'baz', allowedProperties: new Map([['foo', 1], ['bar', 2]])})).to.throw(TypeError, 'Out of range'); - }); - - }); - - describe('checkRequiredProperty', () => { - it('throws an error if required arguments are missing', () => { - // @ts-expect-error because second argument is intentionally omitted. - expect(() => checkRequiredProperty({ property: 'foo' })).to.throw('required arguments missing'); - // @ts-expect-error because both arguments are intentionally omitted. - expect(() => checkRequiredProperty()).to.throw('required arguments missing'); - }); - - it('throws an error if the property is missing', () => { - const propertiesCollection = { foo: 'bar', baz: 'qux' }; - expect(() => checkRequiredProperty({ property: 'quux', inObject: propertiesCollection })).to.throw('Required parameter was missing'); - }); - - it('does not throw an error if the property is present', () => { - const propertiesCollection = { foo: 'bar', baz: 'qux' }; - expect(() => checkRequiredProperty({ property: 'foo', inObject: propertiesCollection })).to.not.throw(); - }); - }); - - describe('randomUuid()', () => { - it('should generate a valid v4 UUID', () => { - const id = randomUuid(); - expect(id).to.match(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/); - expect(id).to.have.length(36); - }); - - it('should generate different UUIDs', () => { - const id1 = randomUuid(); - const id2 = randomUuid(); - expect(id1).to.not.equal(id2); - }); - }); -}); \ No newline at end of file diff --git a/packages/crypto/tests/utils.spec.ts b/packages/crypto/tests/utils.spec.ts new file mode 100644 index 000000000..d36bc472d --- /dev/null +++ b/packages/crypto/tests/utils.spec.ts @@ -0,0 +1,187 @@ +import { expect } from 'chai'; + +import { CryptoKey } from '../src/algorithms-api/crypto-key.js'; +import { checkValidProperty, checkRequiredProperty, isCryptoKeyPair, randomUuid, multibaseIdToKey, keyToMultibaseId } from '../src/utils.js'; + +describe('Crypto Utils', () => { + describe('checkValidProperty()', () => { + it('should not throw for a property in the allowed list', () => { + expect(() => checkValidProperty({ property: 'foo', allowedProperties: ['foo', 'bar']})).to.not.throw(); + expect(() => checkValidProperty({ property: 'foo', allowedProperties: new Set(['foo', 'bar'])})).to.not.throw(); + expect(() => checkValidProperty({ property: 'foo', allowedProperties: new Map([['foo', 1], ['bar', 2]])})).to.not.throw(); + }); + + it('throws an error if required parameters are missing', () => { + expect(() => checkValidProperty({ property: 'foo' } as any)).to.throw(TypeError, 'required parameters missing'); + expect(() => checkValidProperty({ allowedProperties: ['foo', 'bar'] } as any)).to.throw(TypeError, 'required parameters missing'); + // @ts-expect-error because both arguments are intentionally omitted. + expect(() => checkValidProperty()).to.throw(TypeError, 'required parameters missing'); + }); + + it('throws an error if the property does not exist', () => { + expect(() => checkValidProperty({ property: 'baz', allowedProperties: ['foo', 'bar']})).to.throw(TypeError, 'Out of range'); + expect(() => checkValidProperty({ property: 'baz', allowedProperties: new Set(['foo', 'bar'])})).to.throw(TypeError, 'Out of range'); + expect(() => checkValidProperty({ property: 'baz', allowedProperties: new Map([['foo', 1], ['bar', 2]])})).to.throw(TypeError, 'Out of range'); + }); + + }); + + describe('checkRequiredProperty', () => { + it('throws an error if required parameters are missing', () => { + // @ts-expect-error because second argument is intentionally omitted. + expect(() => checkRequiredProperty({ property: 'foo' })).to.throw('required parameters missing'); + // @ts-expect-error because both arguments are intentionally omitted. + expect(() => checkRequiredProperty()).to.throw('required parameters missing'); + }); + + it('throws an error if the property is missing', () => { + const propertiesCollection = { foo: 'bar', baz: 'qux' }; + expect(() => checkRequiredProperty({ property: 'quux', inObject: propertiesCollection })).to.throw('Required parameter missing'); + }); + + it('does not throw an error if the property is present', () => { + const propertiesCollection = { foo: 'bar', baz: 'qux' }; + expect(() => checkRequiredProperty({ property: 'foo', inObject: propertiesCollection })).to.not.throw(); + }); + }); + + describe('isCryptoKeyPair()', () => { + it('returns true with a CryptoKeyPair object', () => { + const publicKey = new CryptoKey( + { name: 'EdDSA', namedCurve: 'Ed25519' }, + true, + new Uint8Array(32), + 'public', + ['verify'] + ); + const privateKey = new CryptoKey( + { name: 'EdDSA', namedCurve: 'Ed25519' }, + true, + new Uint8Array(32), + 'private', + ['sign'] + ); + const validCryptoKeyPair = { publicKey, privateKey }; + + const result = isCryptoKeyPair(validCryptoKeyPair); + expect(result).to.be.true; + }); + + it('returns false for a CryptoKey', () => { + const cryptoKey = new CryptoKey( + { name: 'EdDSA', namedCurve: 'Ed25519' }, + true, + new Uint8Array(32), + 'secret', + ['decrypt', 'encrypt'] + ); + + const result = isCryptoKeyPair(cryptoKey); + expect(result).to.be.false; + }); + }); + + describe('keyToMultibaseId()', () => { + it('returns a multibase encoded string', () => { + const input = { + key : new Uint8Array(32), + multicodecName : 'ed25519-pub', + }; + const encoded = keyToMultibaseId({ key: input.key, multicodecName: input.multicodecName }); + expect(encoded).to.be.a.string; + expect(encoded.substring(0, 1)).to.equal('z'); + expect(encoded.substring(1, 4)).to.equal('6Mk'); + }); + + it('passes test vectors', () => { + let input: { key: Uint8Array, multicodecName: string }; + let output: string; + let encoded: string; + + // Test Vector 1. + input = { + key : (new Uint8Array(32)).fill(0), + multicodecName : 'ed25519-pub', + }; + output = 'z6MkeTG3bFFSLYVU7VqhgZxqr6YzpaGrQtFMh1uvqGy1vDnP'; + encoded = keyToMultibaseId({ key: input.key, multicodecName: input.multicodecName }); + expect(encoded).to.equal(output); + + // Test Vector 2. + input = { + key : (new Uint8Array(32)).fill(1), + multicodecName : 'ed25519-pub', + }; + output = 'z6MkeXBLjYiSvqnhFb6D7sHm8yKm4jV45wwBFRaatf1cfZ76'; + encoded = keyToMultibaseId({ key: input.key, multicodecName: input.multicodecName }); + expect(encoded).to.equal(output); + + // Test Vector 3. + input = { + key : (new Uint8Array(32)).fill(9), + multicodecName : 'ed25519-pub', + }; + output = 'z6Mkf4XhsxSXfEAWNK6GcFu7TyVs21AfUTRjiguqMhNQeDgk'; + encoded = keyToMultibaseId({ key: input.key, multicodecName: input.multicodecName }); + expect(encoded).to.equal(output); + }); + }); + + describe('multibaseIdToKey()', () => { + it('Converts secp256k1-pub multibase identifiers', () => { + const multibaseKeyId = 'zQ3shMrXA3Ah8h5asMM69USP8qRDnPaCLRV3nPmitAXVfWhgp'; + + const { key, multicodecCode, multicodecName } = multibaseIdToKey({ multibaseKeyId }); + + expect(key).to.exist; + expect(key).to.be.a('Uint8Array'); + expect(key).to.have.length(33); + expect(multicodecCode).to.exist; + expect(multicodecCode).to.equal(231); + expect(multicodecName).to.exist; + expect(multicodecName).to.equal('secp256k1-pub'); + }); + + it('Converts ed25519-pub multibase identifiers', () => { + const multibaseKeyId = 'z6MkizSHspkM891CAnYZis1TJkB4fWwuyVjt4pV93rWPGYwW'; + + const { key, multicodecCode, multicodecName } = multibaseIdToKey({ multibaseKeyId }); + + expect(key).to.exist; + expect(key).to.be.a('Uint8Array'); + expect(key).to.have.length(32); + expect(multicodecCode).to.exist; + expect(multicodecCode).to.equal(237); + expect(multicodecName).to.exist; + expect(multicodecName).to.equal('ed25519-pub'); + }); + + it('Converts x25519-pub multibase identifiers', () => { + const multibaseKeyId = 'z6LSfsF6tQA7j56WSzNPT4yrzZprzGEK8137DMeAVLgGBJEz'; + + const { key, multicodecCode, multicodecName } = multibaseIdToKey({ multibaseKeyId }); + + expect(key).to.exist; + expect(key).to.be.a('Uint8Array'); + expect(key).to.have.length(32); + expect(multicodecCode).to.exist; + expect(multicodecCode).to.equal(236); + expect(multicodecName).to.exist; + expect(multicodecName).to.equal('x25519-pub'); + }); + }); + + describe('randomUuid()', () => { + it('should generate a valid v4 UUID', () => { + const id = randomUuid(); + expect(id).to.match(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/); + expect(id).to.have.length(36); + }); + + it('should generate different UUIDs', () => { + const id1 = randomUuid(); + const id2 = randomUuid(); + expect(id1).to.not.equal(id2); + }); + }); +}); \ No newline at end of file diff --git a/packages/crypto/tsconfig.cjs.json b/packages/crypto/tsconfig.cjs.json index 0384273d6..7a6f9c0c0 100644 --- a/packages/crypto/tsconfig.cjs.json +++ b/packages/crypto/tsconfig.cjs.json @@ -10,7 +10,8 @@ "outDir": "dist/cjs", "declaration": false, "declarationMap": false, - "declarationDir": null + "declarationDir": null, + "downlevelIteration": true }, "include": [ "src" diff --git a/packages/crypto/tsconfig.json b/packages/crypto/tsconfig.json index ef53536b2..7fec77c5f 100644 --- a/packages/crypto/tsconfig.json +++ b/packages/crypto/tsconfig.json @@ -19,5 +19,8 @@ }, "include": [ "src" + ], + "exclude": [ + "node_modules" ] } \ No newline at end of file diff --git a/packages/dev-env/README.md b/packages/dev-env/README.md new file mode 100644 index 000000000..a4ad967fa --- /dev/null +++ b/packages/dev-env/README.md @@ -0,0 +1 @@ +# Web5 Developer Environment diff --git a/packages/dids/.c8rc.json b/packages/dids/.c8rc.json index 1d1670b70..ab680f663 100644 --- a/packages/dids/.c8rc.json +++ b/packages/dids/.c8rc.json @@ -5,12 +5,12 @@ ".js" ], "include": [ - "tests/compiled/**" + "tests/compiled/src/**" ], "exclude": [ - "tests/compiled/src/main.js", + "tests/compiled/src/index.js", "tests/compiled/src/types.js", - "tests/compiled/types/**" + "tests/compiled/src/types/**" ], "reporter": [ "cobertura", diff --git a/packages/dids/build/bundles.js b/packages/dids/build/bundles.js index 225acdf4a..5d5e833f2 100644 --- a/packages/dids/build/bundles.js +++ b/packages/dids/build/bundles.js @@ -13,4 +13,10 @@ esbuild.build({ format : 'iife', globalName : 'Web5Dids', outfile : 'dist/browser.js', +}); + +esbuild.build({ + ...browserConfig, + entryPoints : ['./src/utils.ts'], + outfile : 'dist/utils.js' }); \ No newline at end of file diff --git a/packages/dids/build/cjs-bundle.js b/packages/dids/build/cjs-bundle.js new file mode 100644 index 000000000..db2e0f215 --- /dev/null +++ b/packages/dids/build/cjs-bundle.js @@ -0,0 +1,41 @@ +import esbuild from 'esbuild'; +import packageJson from '../package.json' assert { type: 'json' }; + +// list of dependencies that _dont_ ship cjs +const includeList = new Set([ + '@decentralized-identity/ion-sdk' +]); + +// create list of dependencies that we _do not_ want to include in our bundle +const excludeList = []; +for (const dependency in packageJson.dependencies) { + if (includeList.has(dependency)) { + continue; + } else { + excludeList.push(dependency); + } +} + +/** @type {import('esbuild').BuildOptions} */ +const baseConfig = { + allowOverwrite : true, + bundle : true, + external : excludeList, + format : 'cjs', + platform : 'node', + sourcemap : true, +}; + +const indexConfig = { + ...baseConfig, + entryPoints : ['./dist/esm/index.js'], + outfile : './dist/cjs/index.js', +}; +esbuild.buildSync(indexConfig); + +const utilsConfig = { + ...baseConfig, + entryPoints : ['./dist/esm/utils.js'], + outfile : './dist/cjs/utils.js', +}; +esbuild.buildSync(utilsConfig); \ No newline at end of file diff --git a/packages/dids/build/esbuild-browser-config.cjs b/packages/dids/build/esbuild-browser-config.cjs index a3ddbd9f8..8fd899321 100644 --- a/packages/dids/build/esbuild-browser-config.cjs +++ b/packages/dids/build/esbuild-browser-config.cjs @@ -1,30 +1,13 @@ -/* eslint-disable @typescript-eslint/no-var-requires */ -const polyfillProviderPlugin = require('node-stdlib-browser/helpers/esbuild/plugin'); -const stdLibBrowser = require('node-stdlib-browser'); - -const requiredPolyfills = new Set(['crypto', 'node:crypto', 'stream']); - -// populate object containing lib -> polyfill path -const polyfills = {}; -for (let lib in stdLibBrowser) { - if (requiredPolyfills.has(lib)) { - const polyfill = stdLibBrowser[lib]; - polyfills[lib] = polyfill; - } -} - /** @type {import('esbuild').BuildOptions} */ module.exports = { - entryPoints : ['./src/main.ts'], + entryPoints : ['./src/index.ts'], bundle : true, format : 'esm', sourcemap : true, minify : true, platform : 'browser', target : ['chrome101', 'firefox108', 'safari16'], - inject : [require.resolve('node-stdlib-browser/helpers/esbuild/shim')], - plugins : [polyfillProviderPlugin(polyfills)], define : { 'global': 'globalThis', }, -}; +}; \ No newline at end of file diff --git a/packages/dids/karma.conf.cjs b/packages/dids/karma.conf.cjs index 083f0c963..6b7407b2c 100644 --- a/packages/dids/karma.conf.cjs +++ b/packages/dids/karma.conf.cjs @@ -30,11 +30,13 @@ module.exports = function (config) { // available frameworks: https://www.npmjs.com/search?q=keywords:karma-adapter frameworks: ['mocha'], - // Increase Mocha's default timeout of 2 seconds to prevent timeouts during GitHub CI runs. client: { + // Increase Mocha's default timeout of 2 seconds to prevent timeouts during GitHub CI runs. mocha: { timeout: 10000 // 10 seconds - } + }, + // If an environment variable is defined, override the default test DWN URL. + testDwnUrl: process.env.TEST_DWN_URL, }, // list of files / patterns to load in the browser diff --git a/packages/dids/package.json b/packages/dids/package.json index 7f069ebc9..a51e4e782 100644 --- a/packages/dids/package.json +++ b/packages/dids/package.json @@ -1,15 +1,15 @@ { - "name": "@tbd54566975/dids", - "version": "0.8.0", + "name": "@web5/dids", + "version": "0.2.0", "description": "TBD DIDs library", "type": "module", - "main": "./dist/cjs/main.js", - "module": "./dist/esm/main.js", - "types": "./dist/types/main.d.ts", + "main": "./dist/cjs/index.js", + "module": "./dist/esm/index.js", + "types": "./dist/types/index.d.ts", "scripts": { "clean": "rimraf dist coverage tests/compiled", "build:esm": "rimraf dist/esm dist/types && npx tsc -p tsconfig.json", - "build:cjs": "rimraf dist/cjs && tsc -p tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > ./dist/cjs/package.json", + "build:cjs": "rimraf dist/cjs && node build/cjs-bundle.js && echo '{\"type\": \"commonjs\"}' > ./dist/cjs/package.json", "build:browser": "rimraf dist/browser.mjs dist/browser.js && node build/bundles.js", "build:tests:node": "rimraf tests/compiled && tsc -p tests/tsconfig.json", "build": "npm run clean && npm run build:esm && npm run build:cjs && npm run build:browser", @@ -46,12 +46,17 @@ ], "exports": { ".": { - "import": "./dist/esm/main.js", - "require": "./dist/cjs/main.js", - "types": "./dist/types/main.d.ts" + "types": "./dist/types/index.d.ts", + "import": "./dist/esm/index.js", + "require": "./dist/cjs/index.js" + }, + "./utils": { + "types": "./dist/types/utils.d.ts", + "import": "./dist/esm/utils.js", + "require": "./dist/cjs/utils.js" } }, - "react-native": "./dist/esm/main.js", + "react-native": "./dist/esm/index.js", "keywords": [ "decentralized", "decentralized-identity", @@ -69,25 +74,28 @@ "node": ">=18.0.0" }, "dependencies": { - "@decentralized-identity/ion-tools": "1.1.4", - "@tbd54566975/common": "0.8.0", - "@tbd54566975/crypto": "0.8.0", - "@tbd54566975/dwn-sdk-js": "0.2.1", - "cross-fetch": "4.0.0" + "@decentralized-identity/ion-pow-sdk": "1.0.17", + "@decentralized-identity/ion-sdk": "1.0.1", + "@web5/common": "0.2.0", + "@web5/crypto": "0.2.0", + "canonicalize": "2.0.0", + "did-resolver": "4.1.0", + "level": "8.0.0" }, "devDependencies": { - "@types/chai": "4.3.0", + "@playwright/test": "1.36.2", + "@types/chai": "4.3.5", "@types/chai-as-promised": "7.1.5", - "@types/eslint": "8.37.0", + "@types/eslint": "8.44.2", "@types/mocha": "10.0.1", "@types/sinon": "10.0.15", - "@typescript-eslint/eslint-plugin": "5.59.0", - "@typescript-eslint/parser": "5.59.0", - "c8": "8.0.0", + "@typescript-eslint/eslint-plugin": "6.4.0", + "@typescript-eslint/parser": "6.4.0", + "c8": "8.0.1", "chai": "4.3.7", "chai-as-promised": "7.1.1", "esbuild": "0.16.17", - "eslint": "8.39.0", + "eslint": "8.47.0", "eslint-plugin-mocha": "10.1.0", "karma": "6.4.1", "karma-chai": "0.1.0", @@ -98,11 +106,10 @@ "karma-mocha-reporter": "2.2.5", "karma-webkit-launcher": "2.1.0", "mocha": "10.2.0", - "node-stdlib-browser": "1.2.0", "playwright": "1.36.2", "rimraf": "4.4.0", "sinon": "15.0.2", "source-map-loader": "4.0.1", "typescript": "5.1.6" } -} \ No newline at end of file +} diff --git a/packages/dids/src/did-ion.ts b/packages/dids/src/did-ion.ts index 06352097a..3fa43e0b8 100644 --- a/packages/dids/src/did-ion.ts +++ b/packages/dids/src/did-ion.ts @@ -1,187 +1,614 @@ -import type { PublicKeyJwk, PrivateKeyJwk } from '@tbd54566975/crypto'; -import type { DidResolutionResult, DidMethodResolver, DidMethodCreator, DidState, DwnServiceEndpoint, DidDocument } from './types.js'; +import type { JwkKeyPair, PrivateKeyJwk, PublicKeyJwk, Web5Crypto } from '@web5/crypto'; +import type { IonDocumentModel, IonPublicKeyModel, JwkEd25519, JwkEs256k } from '@decentralized-identity/ion-sdk'; -import { DID, generateKeyPair } from '@decentralized-identity/ion-tools'; +import { Convert, universalTypeOf } from '@web5/common'; +import IonProofOfWork from '@decentralized-identity/ion-pow-sdk'; +// import { IonProofOfWork } from '@decentralized-identity/ion-pow-sdk'; +import { EcdsaAlgorithm, EdDsaAlgorithm, Jose } from '@web5/crypto'; +import { IonDid, IonPublicKeyPurpose, IonRequest } from '@decentralized-identity/ion-sdk'; + +import type { DidDocument, DidKeySetVerificationMethodKey, DidMethod, DidResolutionOptions, DidResolutionResult, DidService, DwnServiceEndpoint, PortableDid } from './types.js'; + +import { getServices, isDwnServiceEndpoint, parseDid } from './utils.js'; + +export type DidIonAnchorOptions = { + challengeEnabled?: boolean; + challengeEndpoint?: string; + operationsEndpoint?: string; + keySet: DidIonKeySet; + services: DidService[]; +} export type DidIonCreateOptions = { - keys?: KeyOption[]; - services?: ServiceOption[]; -}; + anchor?: boolean; + keyAlgorithm?: typeof SupportedCryptoAlgorithms[number]; + keySet?: DidIonKeySet; + services?: DidService[]; +} + +export type DidIonKeySet = { + recoveryKey?: JwkKeyPair; + updateKey?: JwkKeyPair; + verificationMethodKeys?: DidKeySetVerificationMethodKey[]; +} -export type ServiceOption = { - id: string; - type: string; - serviceEndpoint: string | DwnServiceEndpoint; +enum OperationType { + Create = 'create', + Update = 'update', + Deactivate = 'deactivate', + Recover = 'recover' } -export type KeyOption = { - id: string; - type: string; - keyPair: { - publicJwk: PublicKeyJwk; - privateJwk: PrivateKeyJwk; - }, - purposes: string[]; +/** + * Data model representing a public key in the DID Document. + */ +export interface IonCreateRequestModel { + type: OperationType; + suffixData: { + deltaHash: string; + recoveryCommitment: string; + }; + delta: { + updateCommitment: string; + patches: { + action: string; + document: IonDocumentModel; + }[]; + } } -export class DidIonApi implements DidMethodResolver, DidMethodCreator { +const SupportedCryptoAlgorithms = [ + 'Ed25519', + 'secp256k1' +] as const; + +const VerificationRelationshipToIonPublicKeyPurpose = { + assertionMethod : IonPublicKeyPurpose.AssertionMethod, + authentication : IonPublicKeyPurpose.Authentication, + capabilityDelegation : IonPublicKeyPurpose.CapabilityDelegation, + capabilityInvocation : IonPublicKeyPurpose.CapabilityInvocation, + keyAgreement : IonPublicKeyPurpose.KeyAgreement +}; + +export class DidIonMethod implements DidMethod { /** - * @param resolutionEndpoint optional custom URL to send DID resolution request to - */ - constructor (private resolutionEndpoint: string = 'https://discover.did.msidentity.com/1.0/identifiers/') {} + * Name of the DID method + */ + public static methodName = 'ion'; + + public static async anchor(options: { + services: DidService[], + keySet: DidIonKeySet, + challengeEnabled?: boolean, + challengeEndpoint?: string, + operationsEndpoint?: string + }): Promise { + const { + challengeEnabled = true, + challengeEndpoint = 'https://beta.ion.msidentity.com/api/v1.0/proof-of-work-challenge', + keySet, + services, + operationsEndpoint = 'https://beta.ion.msidentity.com/api/v1.0/operations' + } = options; + + // Create ION Document. + const ionDocument = await DidIonMethod.createIonDocument({ + keySet: keySet, + services + }); + + const createRequest = await DidIonMethod.getIonCreateRequest({ + ionDocument, + recoveryPublicKeyJwk : keySet.recoveryKey.publicKeyJwk, + updatePublicKeyJwk : keySet.updateKey.publicKeyJwk + }); + + let resolutionResult: DidResolutionResult; + + if (challengeEnabled) { + const response = await IonProofOfWork.submitIonRequest( + challengeEndpoint, + operationsEndpoint, + JSON.stringify(createRequest) + ); - get methodName() { - return 'ion'; + if (response !== undefined && universalTypeOf(response) === 'String') { + resolutionResult = JSON.parse(response); + } + + } else { + const response = await fetch(operationsEndpoint, { + method : 'POST', + mode : 'cors', + body : JSON.stringify(createRequest), + headers : { + 'Content-Type': 'application/json' + } + }); + + if (response.ok) { + resolutionResult = await response.json(); + } + } + + return resolutionResult; } - // TODO: discuss. need to normalize what's returned from `create`. DidIon.create and DidKey.create return different things. - async create(options: DidIonCreateOptions = {}): Promise { - options.keys ||= [ - { - id : 'dwn', - type : 'JsonWebKey2020', - keyPair : await generateKeyPair(), - purposes : ['authentication'], - }, - ]; + public static async create(options?: DidIonCreateOptions): Promise { + let { anchor, keyAlgorithm, keySet, services } = options ?? { }; + + // Begin constructing a PortableDid. + const did: Partial = {}; + + // If any member of the key set is missing, generate the keys. + did.keySet = await DidIonMethod.generateKeySet({ keyAlgorithm, keySet }); - const didOptions: any = { publicKeys: [] }; - if (options.services) { - didOptions.services = options.services; + // Generate Long Form DID URI. + did.did = await DidIonMethod.getLongFormDid({ + keySet: did.keySet, + services + }); + + // Get short form DID. + did.canonicalId = await DidIonMethod.getShortFormDid({ didUrl: did.did }); + + let didResolutionResult: DidResolutionResult | undefined; + if (anchor) { + // Attempt to anchor the DID. + didResolutionResult = await DidIonMethod.anchor({ + keySet: did.keySet, + services + }); + + } else { + // If anchoring was not requested, then resolve the long form DID. + didResolutionResult = await DidIonMethod.resolve({ didUrl: did.did }); } - for (let key of options.keys) { - const publicKey: any = { ...key }; + // Store the DID Document. + did.document = didResolutionResult.didDocument; + + return did as PortableDid; + } - publicKey.publicKeyJwk = key.keyPair.publicJwk; - delete publicKey.keyPair; + public static async decodeLongFormDid(options: { + didUrl: string + }): Promise { + const { didUrl } = options; - didOptions.publicKeys.push(publicKey); + const parsedDid = parseDid({ didUrl }); + + if (!parsedDid) { + throw new Error(`DidIonMethod: Unable to parse DID: ${didUrl}`); } - const did = new DID({ content: didOptions }); - const didState = { - id : await did.getURI(), - internalId : await did.getURI('short'), - methodData : await did.getAllOperations(), + const decodedLongFormDid = Convert.base64Url( + parsedDid.id.split(':').pop() + ).toObject() as Pick; + + const createRequest: IonCreateRequestModel = { + ...decodedLongFormDid, + type: OperationType.Create }; - // TODO: Migrate this to a utility function that generates a DID document given DidState. - // TODO: Add tests to DID Document generation function to ensure that it produces results identical to DidResolver. - // TODO: Ensure both DID ION and KEY do this consistently. - const didDocument: DidDocument = { - '@context' : 'https://www.w3.org/ns/did/v1', - id : didState.id, - verificationMethod : [], + return createRequest; + } + + /** + * Generates two key pairs used for authorization and encryption purposes + * when interfacing with DWNs. The IDs of these keys are referenced in the + * service object that includes the dwnUrls provided. + */ + public static async generateDwnOptions(options: { + encryptionKeyId?: string, + serviceEndpointNodes: string[], + serviceId?: string, + signingKeyAlgorithm?: typeof SupportedCryptoAlgorithms[number] + signingKeyId?: string, + }): Promise { + const { + signingKeyAlgorithm = 'Ed25519', // Generate Ed25519 key pairs, by default. + serviceId = '#dwn', // Use default ID value, unless overridden. + signingKeyId = '#dwn-sig', // Use default key ID value, unless overridden. + encryptionKeyId = '#dwn-enc', // Use default key ID value, unless overridden. + serviceEndpointNodes } = options; + + const signingKeyPair = await DidIonMethod.generateJwkKeyPair({ + keyAlgorithm : signingKeyAlgorithm, + keyId : signingKeyId + }); + + /** Currently, `dwn-sdk-js` has only implemented support for record + * encryption using the `ECIES-ES256K` crypto algorithm. Until the + * DWN SDK supports ECIES with EdDSA, the encryption key pair must + * use secp256k1. */ + const encryptionKeyPair = await DidIonMethod.generateJwkKeyPair({ + keyAlgorithm : 'secp256k1', + keyId : encryptionKeyId + }); + + const keySet: DidIonKeySet = { + verificationMethodKeys: [ + { ...signingKeyPair, relationships: ['authentication'] }, + { ...encryptionKeyPair, relationships: ['keyAgreement'] } + ] }; - for (let key of didState.methodData[0].content.publicKeys) { - const verificationMethod = { - id : `#${key.id}`, - controller : didState.id, - type : key.type, - publicKeyJwk : key.publicKeyJwk - }; - didDocument.verificationMethod.push(verificationMethod); + const serviceEndpoint: DwnServiceEndpoint = { + encryptionKeys : [encryptionKeyId], + nodes : serviceEndpointNodes, + signingKeys : [signingKeyId] + }; - for (let purpose of key.purposes) { - if (didDocument[purpose]) { - didDocument[purpose].push(key.id); - } else { - didDocument[purpose] = [`#${key.id}`]; - } + const services: DidService[] = [{ + id : serviceId, + serviceEndpoint, + type : 'DecentralizedWebNode', + }]; + + return { keySet, services }; + } + + public static async generateJwkKeyPair(options: { + keyAlgorithm: typeof SupportedCryptoAlgorithms[number], + keyId?: string + }): Promise { + const { keyAlgorithm, keyId } = options; + + let cryptoKeyPair: Web5Crypto.CryptoKeyPair; + + switch (keyAlgorithm) { + case 'Ed25519': { + cryptoKeyPair = await new EdDsaAlgorithm().generateKey({ + algorithm : { name: 'EdDSA', namedCurve: 'Ed25519' }, + extractable : true, + keyUsages : ['sign', 'verify'] + }); + break; } + + case 'secp256k1': { + cryptoKeyPair = await new EcdsaAlgorithm().generateKey({ + algorithm : { name: 'ECDSA', namedCurve: 'secp256k1' }, + extractable : true, + keyUsages : ['sign', 'verify'] + }); + break; + } + + default: { + throw new Error(`Unsupported crypto algorithm: '${keyAlgorithm}'`); + } + } + + // Convert the CryptoKeyPair to JwkKeyPair. + const jwkKeyPair = await Jose.cryptoKeyToJwkPair({ keyPair: cryptoKeyPair }); + + // Set kid values. + if (keyId) { + jwkKeyPair.privateKeyJwk.kid = keyId; + jwkKeyPair.publicKeyJwk.kid = keyId; + } else { + // If a key ID is not specified, generate RFC 7638 JWK thumbprint. + const jwkThumbprint = await Jose.jwkThumbprint({ key: jwkKeyPair.publicKeyJwk }); + jwkKeyPair.privateKeyJwk.kid = jwkThumbprint; + jwkKeyPair.publicKeyJwk.kid = jwkThumbprint; + } + + return jwkKeyPair; + } + + public static async generateKeySet(options?: { + keyAlgorithm?: typeof SupportedCryptoAlgorithms[number], + keySet?: DidIonKeySet + }): Promise { + // Generate Ed25519 authentication key pair, by default. + let { keyAlgorithm = 'Ed25519', keySet = {} } = options ?? {}; + + // If keySet lacks verification method keys, generate one. + if (keySet.verificationMethodKeys === undefined) { + const authenticationkeyPair = await DidIonMethod.generateJwkKeyPair({ + keyAlgorithm, + keyId: 'dwn-sig' + }); + keySet.verificationMethodKeys = [{ + ...authenticationkeyPair, + relationships: ['authentication'] + }]; + } + + // If keySet lacks recovery key, generate one. + if (keySet.recoveryKey === undefined) { + // Note: ION/Sidetree only supports secp256k1 recovery keys. + keySet.recoveryKey = await DidIonMethod.generateJwkKeyPair({ + keyAlgorithm : 'secp256k1', + keyId : 'ion-recovery-1' + }); + } + + // If keySet lacks update key, generate one. + if (keySet.updateKey === undefined) { + // Note: ION/Sidetree only supports secp256k1 update keys. + keySet.updateKey = await DidIonMethod.generateJwkKeyPair({ + keyAlgorithm : 'secp256k1', + keyId : 'ion-update-1' + }); + } + + // Generate RFC 7638 JWK thumbprints if `kid` is missing from any key. + for (const key of [...keySet.verificationMethodKeys, keySet.recoveryKey, keySet.updateKey]) { + if ('publicKeyJwk' in key) key.publicKeyJwk.kid ??= await Jose.jwkThumbprint({ key: key.publicKeyJwk }); + if ('privateKeyJwk' in key) key.privateKeyJwk.kid ??= await Jose.jwkThumbprint({ key: key.privateKeyJwk }); } - for (let service of didState.methodData[0]?.content?.services || []) { - const serviceEntry = { - id : `#${service.id}`, - type : service.type, - serviceEndpoint : { ...service.serviceEndpoint } + return keySet; + } + + /** + * Given the W3C DID Document of a `did:ion` DID, return the identifier of + * the verification method key that will be used for signing messages and + * credentials, by default. + * + * @param document = DID Document to get the default signing key from. + * @returns Verification method identifier for the default signing key. + */ + public static async getDefaultSigningKey(options: { + didDocument: DidDocument + }): Promise { + const { didDocument } = options; + + if (!didDocument.id) { + throw new Error(`DidIonMethod: DID document is missing 'id' property`); + } + + /** If the DID document contains a DWN service endpoint in the expected + * format, return the first entry in the `signingKeys` array. */ + const [dwnService] = getServices({ didDocument, type: 'DecentralizedWebNode' }); + if (isDwnServiceEndpoint(dwnService?.serviceEndpoint)) { + const [verificationMethodId] = dwnService.serviceEndpoint.signingKeys; + const did = didDocument.id; + const signingKeyId = `${did}${verificationMethodId}`; + return signingKeyId; + } + + /** Otherwise, fallback to a naive approach of returning the first key ID + * in the `authentication` verification relationships array. */ + if (didDocument.authentication + && Array.isArray(didDocument.authentication) + && didDocument.authentication.length > 0 + && typeof didDocument.authentication[0] === 'string') { + const [verificationMethodId] = didDocument.authentication; + const did = didDocument.id; + const signingKeyId = `${did}${verificationMethodId}`; + return signingKeyId; + } + } + + public static async getLongFormDid(options: { + services: DidService[], + keySet: DidIonKeySet + }): Promise { + const { services = [], keySet } = options; + + // Create ION Document. + const ionDocument = await DidIonMethod.createIonDocument({ + keySet: keySet, + services + }); + + // Filter JWK to only those properties expected by ION/Sidetree. + const recoveryKey = DidIonMethod.jwkToIonJwk({ key: keySet.recoveryKey.publicKeyJwk }) as JwkEs256k; + const updateKey = DidIonMethod.jwkToIonJwk({ key: keySet.updateKey.publicKeyJwk }) as JwkEs256k; + + // Create an ION DID create request operation. + const did = await IonDid.createLongFormDid({ + document: ionDocument, + recoveryKey, + updateKey + }); + + return did; + } + + public static async getShortFormDid(options: { + didUrl: string + }): Promise { + const { didUrl } = options; + + const parsedDid = parseDid({ didUrl }); + + if (!parsedDid) { + throw new Error(`DidIonMethod: Unable to parse DID: ${didUrl}`); + } + + const shortFormDid = parsedDid.did.split(':', 3).join(':'); + + return shortFormDid; + } + + public static async resolve(options: { + didUrl: string, + resolutionOptions?: DidResolutionOptions + }): Promise { + // TODO: Implement resolutionOptions as defined in https://www.w3.org/TR/did-core/#did-resolution + const { didUrl, resolutionOptions = {} } = options; + + const parsedDid = parseDid({ didUrl }); + if (!parsedDid) { + return { + '@context' : 'https://w3id.org/did-resolution/v1', + didDocument : undefined, + didDocumentMetadata : {}, + didResolutionMetadata : { + contentType : 'application/did+ld+json', + error : 'invalidDid', + errorMessage : `Cannot parse DID: ${didUrl}` + } }; - if (didDocument.service) { - didDocument.service.push(serviceEntry); - } else { - didDocument.service = [serviceEntry]; - } } - const keys = []; - for (let keyOption of options.keys) { - const key = { - id : `${didState.id}#${keyOption.id}`, - type : keyOption.type, - controller : didState.id, - publicKeyJwk : keyOption.keyPair.publicJwk, - privateKeyJwk : keyOption.keyPair.privateJwk + if (parsedDid.method !== 'ion') { + return { + '@context' : 'https://w3id.org/did-resolution/v1', + didDocument : undefined, + didDocumentMetadata : {}, + didResolutionMetadata : { + contentType : 'application/did+ld+json', + error : 'methodNotSupported', + errorMessage : `Method not supported: ${parsedDid.method}` + } }; + } + + const { resolutionEndpoint = 'https://discover.did.msidentity.com/1.0/identifiers/' } = resolutionOptions; + const normalizeUrl = (url: string): string => url.endsWith('/') ? url : url + '/'; + const resolutionUrl = `${normalizeUrl(resolutionEndpoint)}${parsedDid.did}`; + + const response = await fetch(resolutionUrl); + + let resolutionResult: DidResolutionResult | object; + try { + resolutionResult = await response.json(); + } catch (error) { + resolutionResult = {}; + } - keys.push(key); + if (response.ok) { + return resolutionResult as DidResolutionResult; + } + + // Response was not "OK" (HTTP 4xx-5xx status code) + + // Return result if it contains DID resolution metadata. + if ('didResolutionMetadata' in resolutionResult) { + return resolutionResult; + } + + // Set default error code and message. + let error = 'internalError'; + let errorMessage = `DID resolver responded with HTTP status code: ${response.status}`; + + /** The Microsoft resolution endpoint does not return a valid DidResolutionResult + * when an ION DID is "not found" so normalization is needed. */ + if ('error' in resolutionResult && + typeof resolutionResult.error === 'object' && + 'code' in resolutionResult.error && + typeof resolutionResult.error.code === 'string' && + 'message' in resolutionResult.error && + typeof resolutionResult.error.message === 'string') { + error = resolutionResult.error.code.includes('not_found') ? 'notFound' : error; + errorMessage = resolutionResult.error.message ?? errorMessage; } return { - id : didState.id, - internalId : didState.internalId, - didDocument : didDocument, - methodData : didState.methodData, - keys : keys // TODO: Remove keys once KeyManager/KeyStore implemented since everything BUT privateKeyJwk is already in the returned didDocument. + '@context' : 'https://w3id.org/did-resolution/v1', + didDocument : undefined, + didDocumentMetadata : {}, + didResolutionMetadata : { + contentType: 'application/did+ld+json', + error, + errorMessage + } }; } - async resolve(did: string): Promise { - // TODO: Support resolutionOptions as defined in https://www.w3.org/TR/did-core/#did-resolution - // using `URL` constructor to handle both existence and absence of trailing slash '/' in resolution endpoint - // appending './' to DID so 'did' in 'did:ion:abc' doesn't get interpreted as a URL scheme (e.g. like 'http') due to the colon - // TODO: Add tests to ensure that the scenarios this contemplated are checked. - const resolutionUrl = new URL('./' + did, this.resolutionEndpoint).toString(); - const response = await fetch(resolutionUrl); + private static async createIonDocument(options: { + keySet: DidIonKeySet, + services?: DidService[] + }): Promise { + const { services = [], keySet } = options; + + /** + * STEP 1: Convert key set verification method keys to ION SDK format. + */ - // TODO: Replace with check of resonse.ok to catch other 2XX codes. - if (response.status !== 200) { - throw new Error(`unable to resolve ${did}, got http status ${response.status}`); + const ionPublicKeys: IonPublicKeyModel[] = []; + + for (const key of keySet.verificationMethodKeys) { + // Map W3C DID verification relationship names to ION public key purposes. + const ionPurposes: IonPublicKeyPurpose[] = []; + for (const relationship of key.relationships) { + ionPurposes.push( + VerificationRelationshipToIonPublicKeyPurpose[relationship] + ); + } + + /** During certain ION operations, JWK validation will throw an error + * if key IDs provided as input are prefixed with `#`. ION operation + * outputs and DID document resolution always include the `#` prefix + * for key IDs resulting in a confusing mismatch between inputs and + * outputs. To improve the developer experience, this inconsistency + * is addressed by normalizing input key IDs before being passed + * to ION SDK methods. */ + const publicKeyId = (key.publicKeyJwk.kid.startsWith('#')) + ? key.publicKeyJwk.kid.substring(1) + : key.publicKeyJwk.kid; + + // Convert public key JWK to ION format. + const publicKey: IonPublicKeyModel = { + id : publicKeyId, + publicKeyJwk : DidIonMethod.jwkToIonJwk({ key: key.publicKeyJwk }), + purposes : ionPurposes, + type : 'JsonWebKey2020' + }; + + ionPublicKeys.push(publicKey); } - const didResolutionResult = await response.json(); - return didResolutionResult; + /** + * STEP 2: Convert service entries, if any, to ION SDK format. + */ + const ionServices = services.map(service => ({ + ...service, + id: service.id.startsWith('#') ? service.id.substring(1) : service.id + })); + + /** + * STEP 3: Format as ION document. + */ + + const ionDocumentModel: IonDocumentModel = { + publicKeys : ionPublicKeys, + services : ionServices + }; + + return ionDocumentModel; } - /** - * Generates two key pairs used for authorization and encryption purposes - * when interfacing with DWNs. The IDs of these keys are referenced in the - * service object that includes the dwnUrls provided. - */ - async generateDwnConfiguration(dwnUrls: string[]): Promise { - return DidIonApi.generateDwnConfiguration(dwnUrls); + private static async getIonCreateRequest(options: { + ionDocument: IonDocumentModel, + recoveryPublicKeyJwk: PublicKeyJwk, + updatePublicKeyJwk: PublicKeyJwk + }): Promise { + const { ionDocument, recoveryPublicKeyJwk, updatePublicKeyJwk } = options; + + // Create an ION DID create request operation. + const createRequest = await IonRequest.createCreateRequest({ + document : ionDocument, + recoveryKey : DidIonMethod.jwkToIonJwk({ key: recoveryPublicKeyJwk }) as JwkEs256k, + updateKey : DidIonMethod.jwkToIonJwk({ key: updatePublicKeyJwk }) as JwkEs256k + }); + + return createRequest; } - /** - * Generates two key pairs used for authorization and encryption purposes - * when interfacing with DWNs. The IDs of these keys are referenced in the - * service object that includes the dwnUrls provided. - */ - static async generateDwnConfiguration(dwnUrls: string[]): Promise { - const keys = [{ - id : 'authz', - type : 'JsonWebKey2020', - keyPair : await generateKeyPair('secp256k1'), - purposes : ['authentication'], - }, { - id : 'enc', - type : 'JsonWebKey2020', - keyPair : await generateKeyPair('secp256k1'), - purposes : ['keyAgreement'], - }]; + private static jwkToIonJwk({ key }: { key: PrivateKeyJwk | PublicKeyJwk }): JwkEd25519 | JwkEs256k { + let ionJwk: Partial = { }; + + if ('crv' in key) { + ionJwk.crv = key.crv; + ionJwk.kty = key.kty; + ionJwk.x = key.x; + if ('d' in key) ionJwk.d = key.d; - const services = [{ - 'id' : 'dwn', - 'type' : 'DecentralizedWebNode', - 'serviceEndpoint' : { - 'nodes' : dwnUrls, - 'messageAuthorizationKeys' : ['#authz'], - 'recordEncryptionKeys' : ['#enc'] + if ('y' in key && key.y) { + // secp256k1 JWK. + return { ...ionJwk, y: key.y} as JwkEs256k; } - }]; + // Ed25519 JWK. + return { ...ionJwk } as JwkEd25519; + } - return { keys, services }; + throw new Error(`jwkToIonJwk: Unsupported key algorithm.`); } } \ No newline at end of file diff --git a/packages/dids/src/did-key.ts b/packages/dids/src/did-key.ts index 4668704ef..886ea6fdf 100644 --- a/packages/dids/src/did-key.ts +++ b/packages/dids/src/did-key.ts @@ -1,50 +1,783 @@ -import type { DidMethodCreator, DidMethodResolver, DidState } from './types.js'; +import type { PrivateKeyJwk, PublicKeyJwk, Web5Crypto } from '@web5/crypto'; -import { ed25519 } from '@tbd54566975/crypto'; -import { DidKeyResolver } from '@tbd54566975/dwn-sdk-js'; -import { createVerificationMethodWithPrivateKeyJwk, keyToMultibaseId } from './utils.js'; +import { universalTypeOf } from '@web5/common'; +import { keyToMultibaseId, multibaseIdToKey } from '@web5/crypto/utils'; +import { + Jose, + Ed25519, + Secp256k1, + EcdsaAlgorithm, + EdDsaAlgorithm, +} from '@web5/crypto'; -const didKeyResolver = new DidKeyResolver(); +import type { DidDocument, DidMethod, DidResolutionOptions, DidResolutionResult, PortableDid, VerificationMethod } from './types.js'; -export type DidKeyOptions = never; +import { DidKeySetVerificationMethodKey } from './types.js'; +import { getVerificationMethodTypes, parseDid } from './utils.js'; -//! i know dwn-sdk-js has a resolver that includes both creation and resolving. but they're slightly different and we really -//! need to settle on what the normalized result of did creation is. +const SupportedCryptoAlgorithms = [ + 'Ed25519', + 'secp256k1' +] as const; -export class DidKeyApi implements DidMethodResolver, DidMethodCreator { - get methodName() { - return 'key'; +const SupportedPublicKeyFormats = [ + 'Ed25519VerificationKey2020', + 'JsonWebKey2020', + 'X25519KeyAgreementKey2020' +]; + +const VERIFICATION_METHOD_TYPES: Record = { + 'Ed25519VerificationKey2020' : 'https://w3id.org/security/suites/ed25519-2020/v1', + 'JsonWebKey2020' : 'https://w3id.org/security/suites/jws-2020/v1', + 'X25519KeyAgreementKey2020' : 'https://w3id.org/security/suites/x25519-2020/v1', +} as const; + +export type DidVerificationMethodType = keyof typeof VERIFICATION_METHOD_TYPES; + +const MULTICODEC_PUBLIC_KEY_LENGTH: Record = { + // secp256k1-pub - Secp256k1 public key (compressed) - 33 bytes + 0xe7: 33, + + // x25519-pub - Curve25519 public key - 32 bytes + 0xec: 32, + + // ed25519-pub - Ed25519 public key - 32 bytes + 0xed: 32 +}; + +export type DidKeyCreateOptions = { + enableEncryptionKeyDerivation?: boolean; + keyAlgorithm?: typeof SupportedCryptoAlgorithms[number]; + keySet?: DidKeyKeySet; + publicKeyFormat?: DidVerificationMethodType; +} + +export type DidKeyCreateDocumentOptions = { + defaultContext?: string; + did: string; + enableEncryptionKeyDerivation?: boolean; + enableExperimentalPublicKeyTypes?: boolean; + publicKeyFormat?: DidVerificationMethodType; +} + +export type DidKeyDeriveEncryptionKeyResult = { + key: Uint8Array; + multicodecCode: number; +} + +export type DidKeyIdentifier = { + fragment: string; + method: string; + multibaseValue: string; + scheme: string; + version: string; +} + +export type DidKeyKeySet = { + verificationMethodKeys?: DidKeySetVerificationMethodKey[]; +} + +export class DidKeyMethod implements DidMethod { + /** + * Name of the DID method + */ + public static methodName = 'key'; + + public static async create(options?: DidKeyCreateOptions): Promise { + let { + enableEncryptionKeyDerivation = false, + keyAlgorithm, + keySet, + publicKeyFormat = 'JsonWebKey2020' + } = options ?? { }; + + // If keySet not given, generate a default key set. + if (keySet === undefined) { + keySet = await DidKeyMethod.generateKeySet({ keyAlgorithm }); + } + + const portableDid: Partial = {}; + let multibaseId = ''; + + if (keySet.verificationMethodKeys?.[0]?.publicKeyJwk) { + // Compute the multibase identifier based on the JSON Web Key. + const publicKeyJwk = keySet.verificationMethodKeys[0].publicKeyJwk; + multibaseId = await Jose.jwkToMultibaseId({ key: publicKeyJwk }); + } + + if (!multibaseId) { + throw new Error('DidKeyMethod: Failed to create DID with given input.'); + } + + // Concatenate the DID identifier. + portableDid.did = `did:key:${multibaseId}`; + + // Expand the DID identifier to a DID document. + portableDid.document = await DidKeyMethod.createDocument({ + did: portableDid.did, + publicKeyFormat, + enableEncryptionKeyDerivation + }); + + // Return the given or generated key set. + portableDid.keySet = keySet; + + return portableDid as PortableDid; } - async create(_options: any = {}): Promise { - // Generate new sign key pair. - const verificationKeyPair = ed25519.generateKeyPair(); - const keyAgreementKeyPair = ed25519.deriveX25519KeyPair(verificationKeyPair); + /** + * Expands a did:key identifier to a DID Document. + * + * Reference: https://w3c-ccg.github.io/did-method-key/#document-creation-algorithm + * + * @param options + * @returns - A DID dodcument. + */ + public static async createDocument(options: DidKeyCreateDocumentOptions): Promise { + const { + defaultContext = 'https://www.w3.org/ns/did/v1', + did, + enableEncryptionKeyDerivation = false, + enableExperimentalPublicKeyTypes = false, + publicKeyFormat = 'JsonWebKey2020' + } = options; - const verificationKeyId = keyToMultibaseId({ key: verificationKeyPair.publicKey, multicodecName: 'ed25519-pub' }); - const keyAgreementKeyId = keyToMultibaseId({ key: keyAgreementKeyPair.publicKey, multicodecName: 'x25519-pub' }); + /** + * 1. Initialize document to an empty object. + */ + const document: Partial = {}; - const id = `did:key:${verificationKeyId}`; + /** + * 2. Using a colon (:) as the delimiter, split the identifier into its + * components: a scheme, a method, a version, and a multibaseValue. + * If there are only three components set the version to the string + * value 1 and use the last value as the multibaseValue. + * + * Note: The W3C DID specification makes no mention of a version value + * being part of the DID syntax. Additionally, there does not + * appear to be any real-world usage of the version number. + * Consequently, this implementation will ignore the version + * related guidance in the did:key specification. + */ + let multibaseValue: string; + try { + ({ id: multibaseValue } = parseDid({ didUrl: did })); + } catch (error: any) { + throw new Error(`invalidDid: Unknown format: ${did}`); + } - const verificationJwkPair = ed25519.keyPairToJwk(verificationKeyPair, verificationKeyId); - const verificationKey = createVerificationMethodWithPrivateKeyJwk(id, verificationJwkPair); + /** + * 3. Check the validity of the input identifier. + * The scheme MUST be the value did. The method MUST be the value key. + * The version MUST be convertible to a positive integer value. The + * multibaseValue MUST be a string and begin with the letter z. If any + * of these requirements fail, an invalidDid error MUST be raised. + */ + if (!DidKeyMethod.validateIdentifier({ did })) { + throw new Error(`invalidDid: Invalid identifier format: ${did}`); + } - const keyAgreementJwkPair = ed25519.keyPairToJwk(keyAgreementKeyPair, keyAgreementKeyId, { crv: 'X25519' }); - const keyAgreementKey = createVerificationMethodWithPrivateKeyJwk(id, keyAgreementJwkPair); + /** + * 4. Initialize the signatureVerificationMethod to the result of passing + * identifier, multibaseValue, and options to a + * {@link https://w3c-ccg.github.io/did-method-key/#signature-method-creation-algorithm | Signature Method Creation Algorithm}. + */ + const signatureVerificationMethod = await DidKeyMethod.createSignatureMethod({ + did, + enableExperimentalPublicKeyTypes, + multibaseValue, + publicKeyFormat + }); - return { - id, - internalId : id, - // didDocument : {}, //! TODO: Add DidDocument to object returned. - keys : [verificationKey, keyAgreementKey], - methodData : {} + /** + * 5. Set document.id to identifier. If document.id is not a valid DID, + * an invalidDid error MUST be raised. + * + * Note: Identifier was already confirmed to be valid in Step 3, so + * skipping the redundant validation. + */ + document.id = did; + + /** + * 6. Initialize the verificationMethod property in document to an array + * where the first value is the signatureVerificationMethod. + */ + document.verificationMethod = [signatureVerificationMethod]; + + /** + * 7. Initialize the authentication, assertionMethod, capabilityInvocation, + * and the capabilityDelegation properties in document to an array where + * the first item is the value of the id property in + * signatureVerificationMethod. + */ + document.authentication = [signatureVerificationMethod.id]; + document.assertionMethod = [signatureVerificationMethod.id]; + document.capabilityInvocation = [signatureVerificationMethod.id]; + document.capabilityDelegation = [signatureVerificationMethod.id]; + + /** + * 8. If options.enableEncryptionKeyDerivation is set to true: + * Add the encryptionVerificationMethod value to the verificationMethod + * array. Initialize the keyAgreement property in document to an array + * where the first item is the value of the id property in + * encryptionVerificationMethod. + */ + if (enableEncryptionKeyDerivation === true) { + /** + * Although not covered by the did:key method specification, a sensible + * default will be taken to use the 'X25519KeyAgreementKey2020' + * verification method type if the given publicKeyFormat is + * 'Ed25519VerificationKey2020' and 'JsonWebKey2020' otherwise. + */ + const encryptionPublicKeyFormat = + (publicKeyFormat === 'Ed25519VerificationKey2020') + ? 'X25519KeyAgreementKey2020' + : 'JsonWebKey2020'; + + /** + * 8.1 Initialize the encryptionVerificationMethod to the result of + * passing identifier, multibaseValue, and options to an + * {@link https://w3c-ccg.github.io/did-method-key/#encryption-method-creation-algorithm | Encryption Method Creation Algorithm}. + */ + const encryptionVerificationMethod = await this.createEncryptionMethod({ + did, + enableExperimentalPublicKeyTypes, + multibaseValue, + publicKeyFormat: encryptionPublicKeyFormat + }); + + /** + * 8.2 Add the encryptionVerificationMethod value to the + * verificationMethod array. + */ + document.verificationMethod.push(encryptionVerificationMethod); + + /** + * 8.3. Initialize the keyAgreement property in document to an array + * where the first item is the value of the id property in + * encryptionVerificationMethod. + */ + document.keyAgreement = [encryptionVerificationMethod.id]; + } + + /** + * 9. Initialize the @context property in document to the result of passing + * document and options to the Context Creation algorithm. + */ + // Set contextArray to an array that is initialized to + // options.defaultContext. + const contextArray = [defaultContext]; + + // For every object in every verification relationship listed in document, + // add a string value to the contextArray based on the object type value, + // if it doesn't already exist, according to the following table: + // {@link https://w3c-ccg.github.io/did-method-key/#context-creation-algorithm | Context Type URL} + const verificationMethodTypes = getVerificationMethodTypes({ didDocument: document }); + verificationMethodTypes.forEach((typeName: string) => { + const typeUrl = VERIFICATION_METHOD_TYPES[typeName]; + contextArray.push(typeUrl); + }); + document['@context'] = contextArray; + + /** + * 10. Return document. + */ + return document as DidDocument; + } + + /** + * Decoding a multibase-encoded multicodec value into a verification method + * that is suitable for verifying that encrypted information will be + * received by the intended recipient. + */ + public static async createEncryptionMethod(options: { + did: string, + enableExperimentalPublicKeyTypes: boolean, + multibaseValue: string, + publicKeyFormat: DidVerificationMethodType + }): Promise { + const { did, enableExperimentalPublicKeyTypes, multibaseValue, publicKeyFormat } = options; + + /** + * 1. Initialize verificationMethod to an empty object. + */ + const verificationMethod: Partial = {}; + + /** + * 2. Set multicodecValue and rawPublicKeyBytes to the result of passing + * multibaseValue and options to a Derive Encryption Key algorithm. + */ + const { + key: rawPublicKeyBytes, + multicodecCode: multicodecValue, + } = await DidKeyMethod.deriveEncryptionKey({ multibaseValue }); + + /** + * 3. Ensure the proper key length of rawPublicKeyBytes based on the + * multicodecValue table provided below: + * + * Multicodec hexadecimal value: 0xec + * + * If the byte length of rawPublicKeyBytes + * does not match the expected public key length for the associated + * multicodecValue, an invalidPublicKeyLength error MUST be raised. + */ + const actualLength = rawPublicKeyBytes.byteLength; + const expectedLength = MULTICODEC_PUBLIC_KEY_LENGTH[multicodecValue]; + if (actualLength !== expectedLength) { + throw new Error(`invalidPublicKeyLength: Expected ${actualLength} bytes. Actual ${expectedLength} bytes.`); + } + + /** + * 4. Create the multibaseValue by concatenating the letter 'z' and the + * base58-btc encoding of the concatenation of the multicodecValue and + * the rawPublicKeyBytes. + */ + const kemMultibaseValue = keyToMultibaseId({ + key : rawPublicKeyBytes, + multicodecCode : multicodecValue + }); + + /** + * 5. Set the verificationMethod.id value by concatenating identifier, + * a hash character (#), and the multibaseValue. If verificationMethod.id + * is not a valid DID URL, an invalidDidUrl error MUST be raised. + */ + verificationMethod.id = `${did}#${kemMultibaseValue}`; + try { + new URL(verificationMethod.id); + } catch (error: any) { + throw new Error('invalidDidUrl: Verification Method ID is not a valid DID URL.'); + } + + /** + * 6. Set the publicKeyFormat value to the options.publicKeyFormat value. + * 7. If publicKeyFormat is not known to the implementation, an + * unsupportedPublicKeyType error MUST be raised. + */ + if (!(SupportedPublicKeyFormats.includes(publicKeyFormat))) { + throw new Error(`unsupportedPublicKeyType: Unsupported format: ${publicKeyFormat}`); + } + + /** + * 8. If options.enableExperimentalPublicKeyTypes is set to false and + * publicKeyFormat is not Multikey, JsonWebKey2020, or + * X25519KeyAgreementKey2020, an invalidPublicKeyType error MUST be + * raised. + */ + const StandardPublicKeyTypes = ['Multikey', 'JsonWebKey2020', 'X25519KeyAgreementKey2020']; + if (enableExperimentalPublicKeyTypes === false + && !(StandardPublicKeyTypes.includes(publicKeyFormat))) { + throw new Error(`invalidPublicKeyType: Specified '${publicKeyFormat}' without setting enableExperimentalPublicKeyTypes to true.`); + } + + /** + * 9. Set verificationMethod.type to the publicKeyFormat value. + */ + verificationMethod.type = publicKeyFormat; + + /** + * 10. Set verificationMethod.controller to the identifier value. + * If verificationMethod.controller is not a valid DID, an invalidDid + * error MUST be raised. + */ + verificationMethod.controller = did; + if (!DidKeyMethod.validateIdentifier({ did })) { + throw new Error(`invalidDid: Invalid identifier format: ${did}`); + } + + /** + * 11. If publicKeyFormat is Multikey or X25519KeyAgreementKey2020, + * set the verificationMethod.publicKeyMultibase value to multibaseValue. + * + * Note: This implementation does not currently support the Multikey + * format. + */ + if (publicKeyFormat === 'X25519KeyAgreementKey2020') { + verificationMethod.publicKeyMultibase = kemMultibaseValue; + } + + /** + * 12. If publicKeyFormat is JsonWebKey2020, set the + * verificationMethod.publicKeyJwk value to the result of passing + * multicodecValue and rawPublicKeyBytes to a JWK encoding algorithm. + */ + if (publicKeyFormat === 'JsonWebKey2020') { + const jwkParams = await Jose.multicodecToJose({ code: multicodecValue }); + const jsonWebKey = await Jose.keyToJwk({ + keyMaterial : rawPublicKeyBytes, + keyType : 'public', + ...jwkParams + }); + // Ensure that "d" is NOT present. + if ('x' in jsonWebKey && !('d' in jsonWebKey)) { + verificationMethod.publicKeyJwk = jsonWebKey; + } + } + + /** + * 13. Return verificationMethod. + */ + return verificationMethod as VerificationMethod; + } + + /** + * Transform a multibase-encoded multicodec value to public encryption key + * components that are suitable for encrypting messages to a receiver. A + * mathematical proof elaborating on the safety of performing this operation + * is available in: + * {@link https://eprint.iacr.org/2021/509.pdf | On using the same key pair for Ed25519 and an X25519 based KEM} + */ + public static async deriveEncryptionKey(options: { + multibaseValue: string + }): Promise { + const { multibaseValue } = options; + + /** + * 1. Set publicEncryptionKey to an empty object. + */ + let publicEncryptionKey: Partial = {}; + + /** + * 2. Decode multibaseValue using the base58-btc multibase alphabet and + * set multicodecValue to the multicodec header for the decoded value. + * Implementers are cautioned to ensure that the multicodecValue is set + * to the result after performing varint decoding. + * + * 3. Set the rawPublicKeyBytes to the bytes remaining after the multicodec + * header. + */ + const { + key: rawPublicKeyBytes, + multicodecCode: multicodecValue + } = multibaseIdToKey({ multibaseKeyId: multibaseValue }); + + /** + * 4. If the multicodecValue is 0xed, derive a public X25519 encryption key + * by using the rawPublicKeyBytes and the algorithm defined in + * {@link https://datatracker.ietf.org/doc/html/draft-ietf-core-oscore-groupcomm | Group OSCORE - Secure Group Communication for CoAP} + * for Curve25519 in Section 2.4.2: ECDH with Montgomery Coordinates and + * set generatedPublicEncryptionKeyBytes to the result. + */ + if (multicodecValue === 0xed) { + const generatedPublicEncryptionKeyBytes = await Ed25519.convertPublicKeyToX25519({ + publicKey: rawPublicKeyBytes + }); + + /** + * 5. Set multicodecValue in publicEncryptionKey to 0xec. + * + * 6. Set rawPublicKeyBytes in publicEncryptionKey to + * generatedPublicEncryptionKeyBytes. + */ + publicEncryptionKey = { + key : generatedPublicEncryptionKeyBytes, + multicodecCode : 0xec + }; + } + + /** + * 7. Return publicEncryptionKey. + */ + return publicEncryptionKey as DidKeyDeriveEncryptionKeyResult; + } + + /** + * Decodes a multibase-encoded multicodec value into a verification method + * that is suitable for verifying digital signatures. + * @param options - Signature method creation algorithm inputs. + * @returns - A verification method. + */ + public static async createSignatureMethod(options: { + did: string, + enableExperimentalPublicKeyTypes: boolean, + multibaseValue: string, + publicKeyFormat: DidVerificationMethodType + }): Promise { + const { did, enableExperimentalPublicKeyTypes, multibaseValue, publicKeyFormat } = options; + + /** + * 1. Initialize verificationMethod to an empty object. + */ + const verificationMethod: Partial = {}; + + /** + * 2. Set multicodecValue and rawPublicKeyBytes to the result of passing + * multibaseValue and options to a Decode Public Key algorithm. + */ + const { + key: rawPublicKeyBytes, + multicodecCode: multicodecValue, + multicodecName + } = multibaseIdToKey({ multibaseKeyId: multibaseValue }); + + /** + * 3. Ensure the proper key length of rawPublicKeyBytes based on the + * multicodecValue {@link https://w3c-ccg.github.io/did-method-key/#signature-method-creation-algorithm | table provided}. + * If the byte length of rawPublicKeyBytes does not match the expected + * public key length for the associated multicodecValue, an + * invalidPublicKeyLength error MUST be raised. + */ + const actualLength = rawPublicKeyBytes.byteLength; + const expectedLength = MULTICODEC_PUBLIC_KEY_LENGTH[multicodecValue]; + if (actualLength !== expectedLength) { + throw new Error(`invalidPublicKeyLength: Expected ${actualLength} bytes. Actual ${expectedLength} bytes.`); + } + + /** + * 4. Ensure the rawPublicKeyBytes are a proper encoding of the public + * key type as specified by the multicodecValue. This validation is often + * done by a cryptographic library when importing the public key by, + * for example, ensuring that an Elliptic Curve public key is a specific + * coordinate that exists on the elliptic curve. If an invalid public key + * value is detected, an invalidPublicKey error MUST be raised. + */ + let isValid = false; + switch (multicodecName) { + case 'secp256k1-pub': + isValid = await Secp256k1.validatePublicKey({ key: rawPublicKeyBytes }); + break; + case 'ed25519-pub': + isValid = await Ed25519.validatePublicKey({ key: rawPublicKeyBytes }); + break; + case 'x25519-pub': + // TODO: Validate key once/if X25519.validatePublicKey() is implemented. + // isValid = X25519.validatePublicKey({ key: rawPublicKeyBytes}) + isValid = true; + break; + } + if (!isValid) { + throw new Error('invalidPublicKey: Invalid public key detected.'); + } + + /** + * 5. Set the verificationMethod.id value by concatenating identifier, + * a hash character (#), and the multibaseValue. If verificationMethod.id + * is not a valid DID URL, an invalidDidUrl error MUST be raised. + */ + verificationMethod.id = `${did}#${multibaseValue}`; + try { + new URL(verificationMethod.id); + } catch (error: any) { + throw new Error('invalidDidUrl: Verification Method ID is not a valid DID URL.'); + } + + /** + * 6. Set the publicKeyFormat value to the options.publicKeyFormat value. + * 7. If publicKeyFormat is not known to the implementation, an + * unsupportedPublicKeyType error MUST be raised. + */ + if (!(SupportedPublicKeyFormats.includes(publicKeyFormat))) { + throw new Error(`unsupportedPublicKeyType: Unsupported format: ${publicKeyFormat}`); + } + + /** + * 8. If options.enableExperimentalPublicKeyTypes is set to false and + * publicKeyFormat is not Multikey, JsonWebKey2020, or + * Ed25519VerificationKey2020, an invalidPublicKeyType error MUST be + * raised. + */ + const StandardPublicKeyTypes = ['Multikey', 'JsonWebKey2020', 'Ed25519VerificationKey2020']; + if (enableExperimentalPublicKeyTypes === false + && !(StandardPublicKeyTypes.includes(publicKeyFormat))) { + throw new Error(`invalidPublicKeyType: Specified '${publicKeyFormat}' without setting enableExperimentalPublicKeyTypes to true.`); + } + + /** + * 9. Set verificationMethod.type to the publicKeyFormat value. + */ + verificationMethod.type = publicKeyFormat; + + /** + * 10. Set verificationMethod.controller to the identifier value. + * If verificationMethod.controller is not a valid DID, an invalidDid + * error MUST be raised. + */ + verificationMethod.controller = did; + if (!DidKeyMethod.validateIdentifier({ did })) { + throw new Error(`invalidDid: Invalid identifier format: ${did}`); + } + + /** + * 11. If publicKeyFormat is Multikey or Ed25519VerificationKey2020, + * set the verificationMethod.publicKeyMultibase value to multibaseValue. + * + * Note: This implementation does not currently support the Multikey + * format. + */ + if (publicKeyFormat === 'Ed25519VerificationKey2020') { + verificationMethod.publicKeyMultibase = multibaseValue; + } + + /** + * 12. If publicKeyFormat is JsonWebKey2020, set the + * verificationMethod.publicKeyJwk value to the result of passing + * multicodecValue and rawPublicKeyBytes to a JWK encoding algorithm. + */ + if (publicKeyFormat === 'JsonWebKey2020') { + const jwkParams = await Jose.multicodecToJose({ code: multicodecValue }); + const jsonWebKey = await Jose.keyToJwk({ + keyMaterial : rawPublicKeyBytes, + keyType : 'public', + ...jwkParams + }); + // Ensure that "d" is NOT present. + if ('x' in jsonWebKey && !('d' in jsonWebKey)) { + verificationMethod.publicKeyJwk = jsonWebKey; + } + } + + /** + * 13. Return verificationMethod. + */ + return verificationMethod as VerificationMethod; + } + + public static async generateKeySet(options?: { + keyAlgorithm?: typeof SupportedCryptoAlgorithms[number] + }): Promise { + // Generate Ed25519 keys, by default. + const { keyAlgorithm = 'Ed25519' } = options ?? {}; + + let keyPair: Web5Crypto.CryptoKeyPair; + + switch (keyAlgorithm) { + case 'Ed25519': { + keyPair = await new EdDsaAlgorithm().generateKey({ + algorithm : { name: 'EdDSA', namedCurve: 'Ed25519' }, + extractable : true, + keyUsages : ['sign', 'verify'] + }); + break; + } + + case 'secp256k1': { + keyPair = await new EcdsaAlgorithm().generateKey({ + algorithm : { name: 'ECDSA', namedCurve: 'secp256k1' }, + extractable : true, + keyUsages : ['sign', 'verify'] + }); + break; + } + + default: { + throw new Error(`Unsupported crypto algorithm: '${keyAlgorithm}'`); + } + } + + const publicKeyJwk = await Jose.cryptoKeyToJwk({ key: keyPair.publicKey }) as PublicKeyJwk; + const privateKeyJwk = await Jose.cryptoKeyToJwk({ key: keyPair.privateKey }) as PrivateKeyJwk; + + const keySet: DidKeyKeySet = { + verificationMethodKeys: [{ + publicKeyJwk, + privateKeyJwk, + relationships: ['authentication'] + }] }; + + return keySet; } - resolve(did: string) { - // TODO: Support resolutionOptions as defined in https://www.w3.org/TR/did-core/#did-resolution - // TODO: move did:key resolving logic to this package. resolved Did Doc does **not** include keyAgreement - return didKeyResolver.resolve(did); + /** + * Given the W3C DID Document of a `did:key` DID, return the identifier of + * the verification method key that will be used for signing messages and + * credentials, by default. + * + * @param document = DID Document to get the default signing key from. + * @returns Verification method identifier for the default signing key. + */ + public static async getDefaultSigningKey(options: { + didDocument: DidDocument + }): Promise { + const { didDocument } = options; + + if (didDocument.authentication + && Array.isArray(didDocument.authentication) + && didDocument.authentication.length > 0 + && typeof didDocument.authentication[0] === 'string') { + + const [verificationMethodId] = didDocument.authentication; + const signingKeyId = verificationMethodId; + + return signingKeyId; + } } -} + public static async resolve(options: { + didUrl: string, + resolutionOptions?: DidResolutionOptions + }): Promise { + const { didUrl, resolutionOptions: _ } = options; + // TODO: Implement resolutionOptions as defined in https://www.w3.org/TR/did-core/#did-resolution + + const parsedDid = parseDid({ didUrl }); + if (!parsedDid) { + return { + '@context' : 'https://w3id.org/did-resolution/v1', + didDocument : undefined, + didDocumentMetadata : {}, + didResolutionMetadata : { + contentType : 'application/did+ld+json', + error : 'invalidDid', + errorMessage : `Cannot parse DID: ${didUrl}` + } + }; + } + + if (parsedDid.method !== 'key') { + return { + '@context' : 'https://w3id.org/did-resolution/v1', + didDocument : undefined, + didDocumentMetadata : {}, + didResolutionMetadata : { + contentType : 'application/did+ld+json', + error : 'methodNotSupported', + errorMessage : `Method not supported: ${parsedDid.method}` + } + }; + } + + const didDocument = await DidKeyMethod.createDocument({ did: parsedDid.did }); + + return { + '@context' : 'https://w3id.org/did-resolution/v1', + didDocument, + didDocumentMetadata : {}, + didResolutionMetadata : { + contentType : 'application/did+ld+json', + did : { + didString : parsedDid.did, + methodSpecificId : parsedDid.id, + method : parsedDid.method + } + } + }; + } + + public static validateIdentifier(options: { + did: string + }): boolean { + const { did } = options; + + const { method, id: multibaseValue } = parseDid({ didUrl: did }); + const [scheme] = did.split(':', 1); + + /** + * Note: The W3C DID specification makes no mention of a version value + * being part of the DID syntax. Additionally, there does not + * appear to be any real-world usage of the version number. + * Consequently, this implementation will ignore the version + * related guidance in the did:key specification. + */ + const version = '1'; + + return ( + scheme !== 'did' || + method !== 'key' || + parseInt(version) > 0 || + universalTypeOf(multibaseValue) !== 'String' || + !multibaseValue.startsWith('z') + ); + } +} \ No newline at end of file diff --git a/packages/dids/src/did-resolver.ts b/packages/dids/src/did-resolver.ts index 10d3d9d4f..cdd49d505 100644 --- a/packages/dids/src/did-resolver.ts +++ b/packages/dids/src/did-resolver.ts @@ -1,43 +1,107 @@ -import type { DidResolutionResult, DidMethodResolver, DidResolverCache } from './types.js'; +import type { + DidResolverCache, + DidMethodResolver, + DidResolutionResult, + DidResolutionOptions, +} from './types.js'; import { parseDid } from './utils.js'; -import { nopCache } from './nop-cache.js'; +import { DidResolverCacheNoop } from './resolver-cache-noop.js'; export type DidResolverOptions = { - methodResolvers: DidMethodResolver[]; + didResolvers: DidMethodResolver[]; cache?: DidResolverCache; } +/** + * The `DidResolver` class is responsible for resolving DIDs to DID documents. + * It uses method resolvers to resolve DIDs of different methods and a cache + * to store resolved DID documents. + */ export class DidResolver { - cache: DidResolverCache; - methodResolverMap: Map = new Map(); + /** + * A cache for storing resolved DID documents. + */ + private cache: DidResolverCache; + /** + * A map to store method resolvers against method names. + */ + private didResolvers: Map = new Map(); + + /** + * Constructs a new `DidResolver`. + * + * @param options - The options for constructing the `DidResolver`. + * @param options.didResolvers - An array of `DidMethodResolver` instances. + * @param options.cache - Optional. A cache for storing resolved DID documents. If not provided, a no-operation cache is used. + */ constructor(options: DidResolverOptions) { - this.cache = options.cache || nopCache; + this.cache = options.cache || DidResolverCacheNoop; - for (let methodResolver of options.methodResolvers) { - this.methodResolverMap.set(methodResolver.methodName, methodResolver); + for (const resolver of options.didResolvers) { + this.didResolvers.set(resolver.methodName, resolver); } } - async resolve(did: string): Promise { - // TODO: Support resolutionOptions as defined in https://www.w3.org/TR/did-core/#did-resolution - const { method } = parseDid(did); - const resolver = this.methodResolverMap.get(method); + /** + * Resolves a DID to a DID Resolution Result. + * If the DID Resolution Result is present in the cache, it returns the cached + * result. Otherwise, it uses the appropriate method resolver to resolve + * the DID, stores the resolution result in the cache, and returns the + * resolultion result. + * + * Note: The method signature for resolve() in this implementation must match + * the `DidResolver` implementation in + * {@link https://github.com/TBD54566975/dwn-sdk-js | dwn-sdk-js} so that + * Web5 apps and the underlying DWN instance can share the same DID + * resolution cache. + * + * @param didUrl - The DID or DID URL to resolve. + * @returns A promise that resolves to the DID Resolution Result. + */ + async resolve(didUrl: string, resolutionOptions?: DidResolutionOptions): Promise { + + const parsedDid = parseDid({ didUrl }); + if (!parsedDid) { + return { + '@context' : 'https://w3id.org/did-resolution/v1', + didDocument : undefined, + didDocumentMetadata : {}, + didResolutionMetadata : { + contentType : 'application/did+ld+json', + error : 'invalidDid', + errorMessage : `Cannot parse DID: ${didUrl}` + } + }; + } + const resolver = this.didResolvers.get(parsedDid.method); if (!resolver) { - throw new Error(`no resolver for ${method}`); + return { + '@context' : 'https://w3id.org/did-resolution/v1', + didDocument : undefined, + didDocumentMetadata : {}, + didResolutionMetadata : { + contentType : 'application/did+ld+json', + error : 'methodNotSupported', + errorMessage : `Method not supported: ${parsedDid.method}` + } + }; } - const cachedResolution = await this.cache.get(did); + const cachedResolutionResult = await this.cache.get(parsedDid.did); - if (cachedResolution) { - return cachedResolution; + if (cachedResolutionResult) { + return cachedResolutionResult; } else { - const didResolutionResult = await resolver.resolve(did); - await this.cache.set(did, didResolutionResult); + const resolutionResult = await resolver.resolve({ + didUrl: parsedDid.did, + resolutionOptions + }); + await this.cache.set(parsedDid.did, resolutionResult); - return didResolutionResult; + return resolutionResult; } } } \ No newline at end of file diff --git a/packages/dids/src/main.ts b/packages/dids/src/index.ts similarity index 65% rename from packages/dids/src/main.ts rename to packages/dids/src/index.ts index 247729026..b5105731b 100644 --- a/packages/dids/src/main.ts +++ b/packages/dids/src/index.ts @@ -1,7 +1,7 @@ -export * from './types.js'; export * from './did-ion.js'; export * from './did-key.js'; export * from './did-resolver.js'; - -// TODO: change name to didUtils? +export * from './resolver-cache-level.js'; +export * from './resolver-cache-noop.js'; +export * from './types.js'; export * as utils from './utils.js'; \ No newline at end of file diff --git a/packages/dids/src/resolver-cache-level.ts b/packages/dids/src/resolver-cache-level.ts new file mode 100644 index 000000000..973d5866e --- /dev/null +++ b/packages/dids/src/resolver-cache-level.ts @@ -0,0 +1,82 @@ +import type { DidResolutionResult, DidResolverCache } from './types.js'; + +import ms from 'ms'; +import { Level } from 'level'; + +export type DidResolverCacheOptions = { + location?: string; + ttl?: string; +} + +type CacheWrapper = { + ttlMillis: number; + value: DidResolutionResult; +} + +/** + * Naive level-based cache for did resolution results. It just so happens that level aggressively keeps as much as it + * can in memory when possible while also writing to the filesystem (in node runtime) and indexedDB (in browser runtime). + * the persistent aspect is especially useful across page refreshes. + */ +export class DidResolverCacheLevel implements DidResolverCache { + private cache: Level; + private ttl: number; + + private static defaultOptions: Required = { + location : 'DATA/AGENT/DID_RESOLVERCACHE', + ttl : '15m' + }; + + constructor(options: DidResolverCacheOptions = {}) { + let { location, ttl } = options; + + location ??= DidResolverCacheLevel.defaultOptions.location; + ttl ??= DidResolverCacheLevel.defaultOptions.ttl; + + this.cache = new Level(location); + this.ttl = ms(ttl); + } + + async get(did: string): Promise { + try { + const str = await this.cache.get(did); + const cacheWrapper: CacheWrapper = JSON.parse(str); + + if (Date.now() >= cacheWrapper.ttlMillis) { + // defer deletion to be called in the next tick of the js event loop + this.cache.nextTick(() => this.cache.del(did)); + + return; + } else { + return cacheWrapper.value; + } + + } catch(error: any) { + // Don't throw when a key wasn't found. + if (error.code === 'LEVEL_NOT_FOUND') { + return; + } + + throw error; + } + } + + set(did: string, value: DidResolutionResult): Promise { + const cacheWrapper: CacheWrapper = { ttlMillis: Date.now() + this.ttl, value }; + const str = JSON.stringify(cacheWrapper); + + return this.cache.put(did, str); + } + + delete(did: string): Promise { + return this.cache.del(did); + } + + clear(): Promise { + return this.cache.clear(); + } + + close(): Promise { + return this.cache.close(); + } +} \ No newline at end of file diff --git a/packages/dids/src/nop-cache.ts b/packages/dids/src/resolver-cache-noop.ts similarity index 77% rename from packages/dids/src/nop-cache.ts rename to packages/dids/src/resolver-cache-noop.ts index 51f2ca1b1..1823e30cb 100644 --- a/packages/dids/src/nop-cache.ts +++ b/packages/dids/src/resolver-cache-noop.ts @@ -6,20 +6,20 @@ import type { DidResolutionResult, DidResolverCache } from './types.js'; * the desire to maximize the potential for this library to be used * in as many JS runtimes as possible */ -export const nopCache: DidResolverCache = { +export const DidResolverCacheNoop: DidResolverCache = { get: function (_key: string): Promise { - return; + return null as any; }, set: function (_key: string, _value: DidResolutionResult): Promise { - return; + return null as any; }, delete: function (_key: string): Promise { - return; + return null as any; }, clear: function (): Promise { - return; + return null as any; }, close: function (): Promise { - return; + return null as any; } }; \ No newline at end of file diff --git a/packages/dids/src/types.ts b/packages/dids/src/types.ts index 361b5fe8d..d02e7ca56 100644 --- a/packages/dids/src/types.ts +++ b/packages/dids/src/types.ts @@ -1,18 +1,22 @@ -import type { KeyValueStore } from '@tbd54566975/common'; -import type { PublicKeyJwk, PrivateKeyJwk } from '@tbd54566975/crypto'; +import type { KeyValueStore } from '@web5/common'; +import type { PrivateKeyJwk, PublicKeyJwk } from '@web5/crypto'; -export type DidResolutionResult = { - '@context'?: 'https://w3id.org/did-resolution/v1' | string | string[] - didResolutionMetadata: DidResolutionMetadata - didDocument?: DidDocument - didDocumentMetadata: DidDocumentMetadata -}; +import { DidKeyKeySet } from './did-key.js'; +import { DidIonKeySet } from './did-ion.js'; -export type DidResolutionMetadata = { - contentType?: string - error?: 'invalidDid' | 'notFound' | 'representationNotSupported' | - 'unsupportedDidMethod' | string -}; +export type DidDocument = { + '@context'?: 'https://www.w3.org/ns/did/v1' | string | string[]; + id: string; + alsoKnownAs?: string[]; + controller?: string | string[]; + verificationMethod?: VerificationMethod[]; + service?: DidService[]; + assertionMethod?: VerificationMethod[] | string[]; + authentication?: VerificationMethod[] | string[]; + keyAgreement?: VerificationMethod[] | string[]; + capabilityDelegation?: VerificationMethod[] | string[]; + capabilityInvocation?: VerificationMethod[] | string[]; +} export type DidDocumentMetadata = { // indicates the timestamp of the Create operation. ISO8601 timestamp @@ -35,83 +39,239 @@ export type DidDocumentMetadata = { equivalentId?: string // @see https://www.w3.org/TR/did-core/#dfn-canonicalid canonicalId?: string + // Additional output metadata generated during DID Resolution. + [key: string]: any }; -export type DidDocument = { - '@context'?: 'https://www.w3.org/ns/did/v1' | string | string[] - id: string - alsoKnownAs?: string[] - controller?: string | string[] - verificationMethod?: VerificationMethod[] - service?: ServiceEndpoint[] - authentication?: VerificationMethod[] | string[] - assertionMethod?: VerificationMethod[] | string[] - keyAgreement?: VerificationMethod[] | string[] - capabilityInvocation?: VerificationMethod[] | string[] - capabilityDelegation?: VerificationMethod[] | string[] -}; +export type DidKeySet = DidKeyKeySet | DidIonKeySet; -export type ServiceEndpoint = { - id: string - type: string - serviceEndpoint: string | DwnServiceEndpoint - description?: string -}; +export type DidKeySetVerificationMethodKey = { + /** Unique identifier for the key in the KeyManager store. */ + keyManagerId?: string; + publicKeyJwk?: PublicKeyJwk; + privateKeyJwk?: PrivateKeyJwk; + relationships: VerificationRelationship[]; +} -export type DwnServiceEndpoint = { - messageAttestationKeys?: string[] - messageAuthorizationKeys?: string[] //! TODO: This property should be required by TS throws an error if it is. - nodes: string[] - recordEncryptionKeys?: string[] //! TODO: This property should be required by TS throws an error if it is. -}; +export type DidMetadata = { + /** + * Additional properties of any type. + */ + [key: string]: any; +} +// eslint-disable-next-line @typescript-eslint/no-empty-interface +export interface DidMethod {} -export type VerificationMethod = { - id: string - // one of the valid verification method types as per - // https://www.w3.org/TR/did-spec-registries/#verification-method-types - type: string - // DID of the key's controller - controller: string - // a JSON Web Key that conforms to https://datatracker.ietf.org/doc/html/rfc7517 - publicKeyJwk?: PublicKeyJwk -}; +export interface DidMethodApi extends DidMethodOperator, DidMethodResolver { + new (): DidMethod; + methodName: string; +} + +export interface DidMethodResolver { + new (): DidMethod; + methodName: string; + + resolve(options: { + didUrl: string, + resolutionOptions?: DidResolutionOptions + }): Promise; +} + +export interface DidMethodOperator { + new (): DidMethod; + methodName: string; + + create(options: any): Promise; + + generateKeySet(): Promise; + + getDefaultSigningKey(options: { didDocument: DidDocument }): Promise; +} /** - * implement this interface to provide your own cache for did resolution results. can be plugged in through Web5 API + * Services are used in DID documents to express ways of communicating with the DID subject or associated entities. + * A service can be any type of service the DID subject wants to advertise. + * + * @see {@link https://www.w3.org/TR/did-core/#services} */ -export type DidResolverCache = KeyValueStore; +export type DidService = { + id: string; + type: string; + serviceEndpoint: string | DidServiceEndpoint | DidServiceEndpoint[]; + description?: string; +}; /** - * implement this interface to include support for different did methods. can be plugged in through Web5 API + * A service endpoint is a URI (Uniform Resource Identifier) that can be used to interact with the service. + * + * @see {@link https://www.w3.org/TR/did-core/#dfn-serviceendpoint} */ -export interface DidMethodApi extends DidMethodCreator, DidMethodResolver {} +export interface DidServiceEndpoint { + [key: string]: any; +} + +export interface DwnServiceEndpoint extends DidServiceEndpoint { + encryptionKeys: string[]; + nodes: string[]; + signingKeys: string[]; +} + +export type DidResolutionMetadata = { + contentType?: string + + error?: + /** + * When an unexpected error occurs during DID Resolution or DID URL dereferencing, the value of the DID Resolution or DID URL Dereferencing Metadata error property MUST be internalError. + */ + | 'internalError' + + /** + * If an invalid DID is detected during DID Resolution, the value of the + * DID Resolution Metadata error property MUST be invalidDid. + */ + | 'invalidDid' + + /** + * If a DID method is not supported during DID Resolution or DID URL + * dereferencing, the value of the DID Resolution or DID URL Dereferencing + * Metadata error property MUST be methodNotSupported. + */ + | 'methodNotSupported' + + /** + * If during DID Resolution or DID URL dereferencing a DID or DID URL + * doesn't exist, the value of the DID Resolution or DID URL dereferencing + * Metadata error property MUST be notFound. + */ + | 'notFound' + + /** + * If a DID document representation is not supported during DID Resolution + * or DID URL dereferencing, the value of the DID Resolution Metadata error + * property MUST be representationNotSupported. + */ + | 'representationNotSupported' + | string + + // Additional output metadata generated during DID Resolution. + [key: string]: any +}; /** - * implement this interface to include support for resolving different dids. can be plugged in through Web5 API + * DID Resolution input metadata. + * + * @see {@link https://www.w3.org/TR/did-core/#did-resolution-options} */ -export interface DidMethodResolver { - get methodName(): string; - resolve(did: string): Promise +export interface DidResolutionOptions { + accept?: string + + // Additional properties used during DID Resolution. + [key: string]: any } +export type DidResolutionResult = { + '@context'?: 'https://w3id.org/did-resolution/v1' | string | string[] + didResolutionMetadata: DidResolutionMetadata + didDocument?: DidDocument + didDocumentMetadata: DidDocumentMetadata +}; + /** - * implement this interface to include support for creating different dids. can be plugged in through Web5 API + * implement this interface to provide your own cache for did resolution results. can be plugged in through Web5 API + */ +export type DidResolverCache = KeyValueStore; + +/** + * Format to document a DID identifier, along with its associated data, + * which can be exported, saved to a file, or imported. The intent is + * bundle all of the necessary metadata to enable usage of the DID in + * different contexts. */ -export interface DidMethodCreator { - get methodName(): string; - create(options: any): Promise +export interface PortableDid { + did: string; + + /** + * A DID method can define different forms of a DID that are logically + * equivalent. An example is when a DID takes one form prior to registration + * in a verifiable data registry and another form after such registration. + * This is the purpose of the canonicalId property. + * + * The `canonicalId` must be used as the primary ID for the DID subject, + * with all other equivalent values treated as secondary aliases. + * + * @see {@link https://www.w3.org/TR/did-core/#dfn-canonicalid | W3C DID Document Metadata} + */ + canonicalId?: string; + + /** + * A set of data describing the DID subject, including mechanisms, such as + * cryptographic public keys, that the DID subject or a DID delegate can use + * to authenticate itself and prove its association with the DID. + */ + document: DidDocument; + + /** + * A collection of cryptographic keys associated with the DID subject. The + * `keySet` encompasses various forms, such as recovery keys, update keys, + * and verification method keys, to enable authentication and verification + * of the DID subject's association with the DID. + */ + keySet: DidKeySet; + + /** + * This property can be used to store method specific data about + * each managed DID and additional properties of any type. + */ + metadata?: DidMetadata; } -export type DidState = { +export type VerificationMethod = { id: string; - internalId: string; - didDocument?: DidDocument; - keys: VerificationMethodWithPrivateKeyJwk[]; - methodData: { [prop: string]: any }; -} + // one of the valid verification method types as per + // https://www.w3.org/TR/did-spec-registries/#verification-method-types + type: string; + // DID of the key's controller + controller: string; + // a JSON Web Key that conforms to https://datatracker.ietf.org/doc/html/rfc7517 + publicKeyJwk?: PublicKeyJwk; + // an encoded (e.g, base58) key with a Multibase-prefix that conforms to + // https://datatracker.ietf.org/doc/draft-multiformats-multibase/ + publicKeyMultibase?: string; +}; + +export type VerificationRelationship = + /** + * Used to specify how the DID subject is expected to express claims, such + * as for the purposes of issuing a Verifiable Credential + */ + | 'assertionMethod' + + /** + * Used to specify how the DID subject is expected to be authenticated, for + * purposes such as logging into a website or engaging in any sort of + * challenge-response protocol. + */ + | 'authentication' + + /** + * Used to specify how an entity can generate encryption material in order to + * transmit confidential information intended for the DID subject, such as + * for the purposes of establishing a secure communication channel with the + * recipient. + */ + | 'keyAgreement' + + /** + * Used to specify a mechanism that might be used by the DID subject to + * delegate a cryptographic capability to another party, such as delegating + * the authority to access a specific HTTP API to a subordinate. + */ + | 'capabilityDelegation' -// TODO: remove this once we've figured out keystore stuff -export type VerificationMethodWithPrivateKeyJwk = VerificationMethod & { - privateKeyJwk: PrivateKeyJwk -}; \ No newline at end of file + /** + * Used to specify a verification method that might be used by the DID + * subject to invoke a cryptographic capability, such as the authorization + * to update the DID Document. + */ + | 'capabilityInvocation'; \ No newline at end of file diff --git a/packages/dids/src/utils.ts b/packages/dids/src/utils.ts index ba8359c9d..30f0cd23a 100644 --- a/packages/dids/src/utils.ts +++ b/packages/dids/src/utils.ts @@ -1,65 +1,125 @@ -import type { KeyPairJwk } from '@tbd54566975/crypto'; -import type { DidDocument, VerificationMethodWithPrivateKeyJwk, ServiceEndpoint } from './types.js'; +import type { PublicKeyJwk } from '@web5/crypto'; +import { parse, type ParsedDID } from 'did-resolver'; -import { Convert, Multicodec } from '@tbd54566975/common'; +import type { DidDocument, DidService, DidServiceEndpoint, DwnServiceEndpoint } from './types.js'; -export type ParsedDid = { - method: string; - id: string; +export interface ParsedDid { + did: string + didUrl: string + method: string + id: string + path?: string + fragment?: string + query?: string + params?: ParsedDID['params'] } export const DID_REGEX = /^did:([a-z0-9]+):((?:(?:[a-zA-Z0-9._-]|(?:%[0-9a-fA-F]{2}))*:)*((?:[a-zA-Z0-9._-]|(?:%[0-9a-fA-F]{2}))+))((;[a-zA-Z0-9_.:%-]+=[a-zA-Z0-9_.:%-]*)*)(\/[^#?]*)?([?][^#]*)?(#.*)?$/; -export function parseDid(did: string): ParsedDid { - if (!DID_REGEX.test(did)) { - throw new Error('Invalid DID'); - } - - const [didString,] = did.split('#'); - const [, method, id] = didString.split(':', 3); +/** + * Retrieves services from a given DID document based on provided options. + * If no `id` or `type` filters are provided, all defined services are returned. + * + * Note: The DID document must adhere to the W3C DID specification. + * + * @param options - An object containing input parameters for retrieving services. + * @param options.didDocument - The DID document from which services are retrieved. + * @param options.id - Optional. A string representing the specific service ID to match. If provided, only the service with this ID will be returned. + * @param options.type - Optional. A string representing the specific service type to match. If provided, only the service(s) of this type will be returned. + * + * @returns An array of services. If no matching service is found, an empty array is returned. + * + * @example + * + * const didDoc = { ... }; // W3C DID document + * const services = getServices({ didDocument: didDoc, type: 'DecentralizedWebNode' }); + */ +export function getServices(options: { + didDocument: DidDocument, + id?: string, + type?: string +}): DidService[] { + const { didDocument, id, type } = options ?? {}; - return { method, id }; + return didDocument?.service?.filter(service => { + if (id && service.id !== id) return false; + if (type && service.type !== type) return false; + return true; + }) ?? [ ]; } -export function createVerificationMethodWithPrivateKeyJwk(id: string, keyPairJwk: KeyPairJwk): VerificationMethodWithPrivateKeyJwk { - const { publicKeyJwk, privateKeyJwk } = keyPairJwk; +export function getVerificationMethodIds(options: { + didDocument: DidDocument, + publicKeyJwk?: PublicKeyJwk, + publicKeyMultibase?: string +}): string | undefined { + const { didDocument, publicKeyJwk, publicKeyMultibase } = options; + if (!didDocument) throw new Error(`Required parameter missing: 'didDocument'`); + if (!didDocument.verificationMethod) throw new Error('Given `didDocument` is missing `verificationMethod` entries.'); - return { - id : `${id}#${keyPairJwk.publicKeyJwk.kid}`, - type : 'JsonWebKey2020', - controller : id, - publicKeyJwk, - privateKeyJwk - }; + for (let method of didDocument.verificationMethod) { + if (publicKeyMultibase && 'publicKeyMultibase' in method) { + if (publicKeyMultibase === method.publicKeyMultibase) { + return method.id; + } + } else if (publicKeyJwk && 'crv' in publicKeyJwk && + 'publicKeyJwk' in method && 'crv' in method.publicKeyJwk) { + if (publicKeyJwk.crv === method.publicKeyJwk.crv && + publicKeyJwk.x === method.publicKeyJwk.x) { + return method.id; + } + } + } } -export type GetServicesOptions = { - id?: string; - type?: string; -}; +/** + * Retrieves DID verification method types from a given DID document. + * + * Note: The DID document must adhere to the W3C DID specification. + * + * @param options - An object containing input parameters for retrieving types. + * @param options.didDocument - The DID document from which types are retrieved. + * + * @returns An array of types. If no types were found, an empty array is returned. + */ +export function getVerificationMethodTypes(options: { + didDocument: Record +}): string[] { + const { didDocument } = options; + + let types: string[] = []; + + for (let key in didDocument) { + if (typeof didDocument[key] === 'object') { + types = types.concat(getVerificationMethodTypes({ + didDocument: didDocument[key] + })); + + } else if (key === 'type') { + types.push(didDocument[key]); + } + } + + return [...new Set(types)]; // return only unique types +} /** - * returns services from the provided DID Document based on the filter. will return all services if no filter is provided - * @param didDocument the did document to search - * @param options search filter - * @returns matched services + * Type guard function to check if the given endpoint is a DwnServiceEndpoint. + * + * @param key The endpoint to check. + * @returns True if the endpoint is a DwnServiceEndpoint, false otherwise. */ -export function getServices(didDocument: DidDocument, options: GetServicesOptions = {}): ServiceEndpoint[] { - return didDocument?.service?.filter(service => { - if (options?.id && service.id !== options.id) return false; - if (options?.type && service.type !== options.type) return false; - return true; - }) ?? [ ]; +export function isDwnServiceEndpoint(endpoint: string | DidServiceEndpoint | DidServiceEndpoint[]): endpoint is DwnServiceEndpoint { + return endpoint !== undefined && + typeof endpoint !== 'string' && + !Array.isArray(endpoint) && + 'encryptionKeys' in endpoint && + 'nodes' in endpoint && + 'signingKeys' in endpoint; } -export function keyToMultibaseId(options: { - key: Uint8Array, - multicodecName: string -}): string { - const { key, multicodecName } = options; - const prefixedKey = Multicodec.addPrefix({ name: multicodecName, data: key }); - const prefixedKeyB58 = Convert.uint8Array(prefixedKey).toBase58Btc(); - const multibaseKeyId = Convert.base58Btc(prefixedKeyB58).toMultibase(); +export function parseDid({ didUrl }: { didUrl: string }): ParsedDid | undefined { + const parsedDid: ParsedDid = parse(didUrl); - return multibaseKeyId; + return parsedDid; } \ No newline at end of file diff --git a/packages/dids/tests/did-ion.spec.ts b/packages/dids/tests/did-ion.spec.ts index c7cfa6eb1..735ee6a59 100644 --- a/packages/dids/tests/did-ion.spec.ts +++ b/packages/dids/tests/did-ion.spec.ts @@ -1,31 +1,803 @@ -import { expect } from 'chai'; +import type { JwkKeyPair } from '@web5/crypto'; -import { DidIonApi } from '../src/did-ion.js'; +import * as sinon from 'sinon'; +import chai, { expect } from 'chai'; +import chaiAsPromised from 'chai-as-promised'; -// NOTE: @noble/secp256k1 requires globalThis.crypto polyfill for node.js <=18: https://github.com/paulmillr/noble-secp256k1/blob/main/README.md#usage -// Remove when we move off of node.js v18 to v20, earliest possible time would be Oct 2023: https://github.com/nodejs/release#release-schedule -import { webcrypto } from 'node:crypto'; -// @ts-ignore -if (!globalThis.crypto) globalThis.crypto = webcrypto; +chai.use(chaiAsPromised); -const DidIon = new DidIonApi(); +import type { + DidService, + DidDocument, + DwnServiceEndpoint, + DidKeySetVerificationMethodKey, +} from '../src/types.js'; + +import { didIonCreateTestVectors } from './fixtures/test-vectors/did-ion.js'; +import { DidIonCreateOptions, DidIonKeySet, DidIonMethod } from '../src/did-ion.js'; + +describe('DidIonMethod', () => { + let testRecoveryKey: JwkKeyPair; + let testUpdateKey: JwkKeyPair; + let testVerificationMethodKeys: DidKeySetVerificationMethodKey[]; + let testKeySet: DidIonKeySet; + + beforeEach(() => { + testRecoveryKey = structuredClone(didIonCreateTestVectors[0].input.keySet.recoveryKey) as JwkKeyPair; + testRecoveryKey.privateKeyJwk.kid = 'test-recovery-1'; + testRecoveryKey.publicKeyJwk.kid = 'test-recovery-1'; + + testUpdateKey = structuredClone(didIonCreateTestVectors[0].input.keySet.updateKey) as JwkKeyPair; + testUpdateKey.privateKeyJwk.kid = 'test-update-1'; + testUpdateKey.publicKeyJwk.kid = 'test-update-1'; + + testVerificationMethodKeys = structuredClone(didIonCreateTestVectors[0].input.keySet.verificationMethodKeys) as DidKeySetVerificationMethodKey[]; + testVerificationMethodKeys[0].publicKeyJwk!.kid = 'test-kid'; + + testKeySet = { + recoveryKey : testRecoveryKey, + updateKey : testUpdateKey, + verificationMethodKeys : testVerificationMethodKeys + }; + }); + + describe('anchor()', () => { + it('accepts a custom operations endpoint', async () => { + // Setup stub so that a mocked response is returned rather than calling over the network. + const mockResult = { mock: 'data' }; + const fetchStub = sinon.stub(global, 'fetch'); + // @ts-expect-error because we're only mocking ok and json() from global.fetch(). + fetchStub.returns(Promise.resolve({ + ok : true, + json : () => Promise.resolve(mockResult) + })); + + const resolutionResult = await DidIonMethod.anchor({ + challengeEnabled : false, + keySet : testKeySet, + operationsEndpoint : 'https://ion-service.com/operations', + services : [] + }); + fetchStub.restore(); + + expect(resolutionResult).to.deep.equal(mockResult); + expect(fetchStub.calledOnceWith( + 'https://ion-service.com/operations', + sinon.match({ + method : 'POST', + mode : 'cors', + body : sinon.match.string, + headers : { + 'Content-Type': 'application/json' + } + }) + )).to.be.true; + }); + + it('supports disabling POW/challenge', async () => { + // Setup stub so that a mocked response is returned rather than calling over the network. + const mockResult = { mock: 'data' }; + const fetchStub = sinon.stub(global, 'fetch'); + // @ts-expect-error because we're only mocking ok and json() from global.fetch(). + fetchStub.returns(Promise.resolve({ + ok : true, + json : () => Promise.resolve(mockResult) + })); + + const resolutionResult = await DidIonMethod.anchor({ + challengeEnabled : false, + keySet : testKeySet, + operationsEndpoint : 'https://ion-service.com/operations', + services : [] + }); + fetchStub.restore(); + + expect(resolutionResult).to.deep.equal(mockResult); + }); + }); -describe('DidIonApi', () => { describe('create()', () => { - it('returns a valid didState', async () => { - const didState = await DidIon.create(); - - expect(didState.id).to.exist; - expect(didState.internalId).to.exist; - expect(didState.keys).to.exist; - - for (let key of didState.keys) { - expect(key.id).to.exist; - expect(key.controller).to.exist; - expect(key.publicKeyJwk).to.exist; - expect(key.privateKeyJwk).to.exist; - expect(key.type).to.exist; - } + it('creates a DID with Ed25519 keys, by default', async () => { + const portableDid = await DidIonMethod.create(); + + // Verify expected result. + expect(portableDid).to.have.property('did'); + expect(portableDid).to.have.property('canonicalId'); + expect(portableDid).to.have.property('document'); + expect(portableDid).to.have.property('keySet'); + + const keySet = portableDid.keySet as DidIonKeySet; + + expect(keySet).to.have.property('verificationMethodKeys'); + expect(keySet.verificationMethodKeys).to.have.length(1); + expect(keySet.verificationMethodKeys?.[0]).to.have.property('publicKeyJwk'); + expect(keySet.verificationMethodKeys?.[0]).to.have.property('privateKeyJwk'); + expect(keySet.verificationMethodKeys?.[0].publicKeyJwk).to.have.property('alg', 'EdDSA'); + expect(keySet.verificationMethodKeys?.[0].publicKeyJwk).to.have.property('crv', 'Ed25519'); + + expect(keySet).to.have.property('recoveryKey'); + expect(keySet.recoveryKey).to.have.property('publicKeyJwk'); + expect(keySet.recoveryKey).to.have.property('privateKeyJwk'); + + expect(keySet).to.have.property('updateKey'); + expect(keySet.recoveryKey).to.have.property('publicKeyJwk'); + expect(keySet.recoveryKey).to.have.property('privateKeyJwk'); + }); + + it('creates a DID with secp256k1 keys, if specified', async () => { + const portableDid = await DidIonMethod.create({ keyAlgorithm: 'secp256k1' }); + + // Verify expected result. + expect(portableDid).to.have.property('did'); + expect(portableDid).to.have.property('canonicalId'); + expect(portableDid).to.have.property('document'); + expect(portableDid).to.have.property('keySet'); + + const keySet = portableDid.keySet as DidIonKeySet; + + expect(keySet).to.have.property('verificationMethodKeys'); + expect(keySet.verificationMethodKeys).to.have.length(1); + expect(keySet.verificationMethodKeys?.[0]).to.have.property('publicKeyJwk'); + expect(keySet.verificationMethodKeys?.[0]).to.have.property('privateKeyJwk'); + expect(keySet.verificationMethodKeys?.[0].publicKeyJwk).to.have.property('alg', 'ES256K'); + expect(keySet.verificationMethodKeys?.[0].publicKeyJwk).to.have.property('crv', 'secp256k1'); + + expect(keySet).to.have.property('recoveryKey'); + expect(keySet.recoveryKey).to.have.property('publicKeyJwk'); + expect(keySet.recoveryKey).to.have.property('privateKeyJwk'); + + expect(keySet).to.have.property('updateKey'); + expect(keySet.recoveryKey).to.have.property('publicKeyJwk'); + expect(keySet.recoveryKey).to.have.property('privateKeyJwk'); + }); + + it('uses specified key ID values for key set, if given', async () => { + const portableDid = await DidIonMethod.create({ + keyAlgorithm : 'Ed25519', + keySet : testKeySet + }); + + const keySet = portableDid.keySet as DidIonKeySet; + expect(keySet.recoveryKey?.privateKeyJwk.kid).to.equal('test-recovery-1'); + expect(keySet.recoveryKey?.publicKeyJwk.kid).to.equal('test-recovery-1'); + expect(keySet.updateKey?.privateKeyJwk.kid).to.equal('test-update-1'); + expect(keySet.updateKey?.publicKeyJwk.kid).to.equal('test-update-1'); + expect(keySet.verificationMethodKeys?.[0].publicKeyJwk?.kid).to.equal('test-kid'); + expect(keySet.verificationMethodKeys?.[0].publicKeyJwk?.kid).to.equal('test-kid'); + }); + + it('generates key ID values for key set, if missing', async () => { + delete testRecoveryKey.privateKeyJwk.kid; + delete testRecoveryKey.publicKeyJwk.kid; + delete testUpdateKey.privateKeyJwk.kid; + delete testUpdateKey.publicKeyJwk.kid; + delete testVerificationMethodKeys[0].publicKeyJwk!.kid; + + const portableDid = await DidIonMethod.create({ + keyAlgorithm : 'Ed25519', + keySet : testKeySet + }); + + const keySet = portableDid.keySet as DidIonKeySet; + expect(keySet.recoveryKey?.privateKeyJwk.kid).to.equal('AEOG_sxXHhCA1Fel8fpheyLxAcW89D7V86lMcJXc500'); + expect(keySet.recoveryKey?.publicKeyJwk.kid).to.equal('AEOG_sxXHhCA1Fel8fpheyLxAcW89D7V86lMcJXc500'); + expect(keySet.updateKey?.privateKeyJwk.kid).to.equal('_1CySHVtk6tNXke3t_7NLI2nvaVlH5GFyuO9HjQCRKs'); + expect(keySet.updateKey?.publicKeyJwk.kid).to.equal('_1CySHVtk6tNXke3t_7NLI2nvaVlH5GFyuO9HjQCRKs'); + expect(keySet.verificationMethodKeys?.[0].publicKeyJwk?.kid).to.equal('OAPj7ObrEJFgVNA2rrkPM5A-vYVsH_lyz4LgOUdJBa8'); + expect(keySet.verificationMethodKeys?.[0].publicKeyJwk?.kid).to.equal('OAPj7ObrEJFgVNA2rrkPM5A-vYVsH_lyz4LgOUdJBa8'); + }); + + it('given key IDs are automatically prefixed with hash symbol (#) in DID document', async () => { + testVerificationMethodKeys[0].publicKeyJwk!.kid = 'noPrefixInput'; + + const portableDid = await DidIonMethod.create({ + keyAlgorithm : 'Ed25519', + keySet : testKeySet + }); + + expect(portableDid.document.authentication).includes(`#noPrefixInput`); + expect(portableDid.document.verificationMethod![0].id).to.equal(`#noPrefixInput`); + }); + + it('accepts recovery and update key IDs that include a hash symbol (#)', async () => { + testRecoveryKey.privateKeyJwk.kid = '#test-recovery-1'; + testRecoveryKey.publicKeyJwk.kid = '#test-recovery-1'; + + await expect( + DidIonMethod.create({ keySet: { recoveryKey: testRecoveryKey } }) + ).to.eventually.be.fulfilled; + + testUpdateKey.privateKeyJwk.kid = '#test-update-1'; + testUpdateKey.publicKeyJwk.kid = '#test-update-1'; + + await expect( + DidIonMethod.create({ keySet: { updateKey: testUpdateKey } }) + ).to.eventually.eventually.be.fulfilled; + }); + + it('accepts verification method key IDs that start with a hash symbol (#)', async () => { + testVerificationMethodKeys[0].publicKeyJwk!.kid = '#prefixedKid'; + + const portableDid = await DidIonMethod.create({ + keyAlgorithm : 'Ed25519', + keySet : testKeySet + }); + + expect(portableDid.document.authentication).includes(`#prefixedKid`); + expect(portableDid.document.verificationMethod![0].id).to.equal(`#prefixedKid`); + }); + + it('throws an error if verification method key IDs contain a hash symbol (#)', async () => { + testVerificationMethodKeys[0].publicKeyJwk!.kid = 'test#kid'; + + await expect( + DidIonMethod.create({ keySet: { verificationMethodKeys: testVerificationMethodKeys } }) + ).to.eventually.eventually.be.rejectedWith(Error, 'IdNotUsingBase64UrlCharacterSet'); + }); + + it('creates a DID with service entries, if specified', async () => { + const dwnEndpoints = [ + 'https://dwn.tbddev.test/dwn0', + 'https://dwn.tbddev.test/dwn1' + ]; + + const services: DidService[] = [{ + 'id' : 'dwn', + 'type' : 'DecentralizedWebNode', + 'serviceEndpoint' : { + 'nodes' : dwnEndpoints, + 'signingKeys' : ['#dwn-sig'], + 'encryptionKeys' : ['#dwn-enc'] + } + }]; + + const portableDid = await DidIonMethod.create({ services }); + + const dwnService = portableDid.document.service?.[0]; + expect(dwnService).to.have.property('type', 'DecentralizedWebNode'); + expect(dwnService?.serviceEndpoint).to.have.property('nodes'); + expect(dwnService?.serviceEndpoint).to.have.property('signingKeys'); + expect(dwnService?.serviceEndpoint).to.have.property('encryptionKeys'); + }); + + it('given service IDs are automatically prefixed with hash symbol (#) in DID document', async () => { + const dwnEndpoints = ['https://dwn.tbddev.test/dwn0']; + + const services: DidService[] = [{ + 'id' : 'dwn', + 'type' : 'DecentralizedWebNode', + 'serviceEndpoint' : { + 'nodes': dwnEndpoints + } + }]; + + const portableDid = await DidIonMethod.create({ services }); + + const dwnService = portableDid.document.service?.[0]; + expect(dwnService).to.have.property('id', '#dwn'); + }); + + it('accepts service IDs that start with a hash symbol (#)', async () => { + const services: DidService[] = [{ + 'id' : '#dwn', + 'type' : 'DecentralizedWebNode', + 'serviceEndpoint' : { } + }]; + + const portableDid = await DidIonMethod.create({ services }); + + const dwnService = portableDid.document.service?.[0]; + expect(dwnService).to.have.property('id', '#dwn'); + }); + + it('throws an error if verification method key IDs contain a hash symbol (#)', async () => { + const services = [{ + 'id' : 'foo#bar', + 'type' : 'DecentralizedWebNode', + 'serviceEndpoint' : { } + }]; + + await expect( + DidIonMethod.create({ services }) + ).to.eventually.eventually.be.rejectedWith(Error, 'IdNotUsingBase64UrlCharacterSet'); + }); + + for (const vector of didIonCreateTestVectors ) { + it(`passes test vector ${vector.id}`, async () => { + const portableDid = await DidIonMethod.create(vector.input as DidIonCreateOptions); + + expect(portableDid).to.deep.equal(vector.output); + }); + } + }); + + describe('decodeLongFormDid()', () => { + it('returns ION create request with services', async () => { + const longFormDid = 'did:ion:EiC94n5yoQEpRfmT6Co7Q4GCUWmuAK4UzDFpk5W4_BzP4A:eyJkZWx0YSI6eyJwYXRjaGVzIjpbeyJhY3Rpb24iOiJyZXBsYWNlIiwiZG9jdW1lbnQiOnsicHVibGljS2V5cyI6W3siaWQiOiJkd24tc2lnIiwicHVibGljS2V5SndrIjp7ImNydiI6IkVkMjU1MTkiLCJrdHkiOiJPS1AiLCJ4IjoiSl9lek5jT2pqNTIxbWEtN18tanFWdC1JODRzendSRTJzMGFCN3h2R1ljYyJ9LCJwdXJwb3NlcyI6WyJhdXRoZW50aWNhdGlvbiJdLCJ0eXBlIjoiSnNvbldlYktleTIwMjAifV0sInNlcnZpY2VzIjpbeyJpZCI6ImR3biIsInNlcnZpY2VFbmRwb2ludCI6eyJub2RlcyI6WyJodHRwczovL2R3bi50YmRkZXYudGVzdC9kd24wIl19LCJ0eXBlIjoiRGVjZW50cmFsaXplZFdlYk5vZGUifV19fV0sInVwZGF0ZUNvbW1pdG1lbnQiOiJFaUR2WHJNV3V0LTNIUWpsTm5JbHlKR2F0WVBsNWo2MFp3SnB4cG9wOHk2RGxBIn0sInN1ZmZpeERhdGEiOnsiZGVsdGFIYXNoIjoiRWlEd2VVOG82clVZY1lCNHQzaHBoaXdtZFpxZWRVdm5zQ251a2xMdWVfOVFOUSIsInJlY292ZXJ5Q29tbWl0bWVudCI6IkVpREhIb3E0bFhoMndjWUZNSnNuNkZBN3otVk9sTHBiU20xcnRNOXlJMUQzd3cifX0'; + + const createRequest = await DidIonMethod.decodeLongFormDid({ didUrl: longFormDid}); + + expect(createRequest).to.have.property('delta'); + expect(createRequest).to.have.property('suffixData'); + expect(createRequest).to.have.property('type', 'create'); + + expect(createRequest.delta).to.have.property('updateCommitment', 'EiDvXrMWut-3HQjlNnIlyJGatYPl5j60ZwJpxpop8y6DlA'); + expect(createRequest.suffixData).to.have.property('recoveryCommitment', 'EiDHHoq4lXh2wcYFMJsn6FA7z-VOlLpbSm1rtM9yI1D3ww'); + + expect(createRequest.delta.patches[0].document.services).to.deep.equal([{ + 'id' : 'dwn', + 'type' : 'DecentralizedWebNode', + 'serviceEndpoint' : { + 'nodes': ['https://dwn.tbddev.test/dwn0'] + } + }]); + }); + + it('returns output that matches ION create request', async () => { + const services: DidService[] = [{ + 'id' : 'dwn', + 'type' : 'DecentralizedWebNode', + 'serviceEndpoint' : { + 'nodes': ['https://dwn.tbddev.test/dwn0'] + } + }]; + + const { did } = await DidIonMethod.create({ + keySet: testKeySet, + services + }); + + // @ts-expect-error because we're intentionally accessing a private method. + const ionDocument = await DidIonMethod.createIonDocument({ + keySet: testKeySet, + services + }); + + if (!testKeySet.recoveryKey) throw new Error('Type guard'); + if (!testKeySet.updateKey) throw new Error('Type guard'); + // @ts-expect-error because we're intentionally accessing a private method. + const createRequest = await DidIonMethod.getIonCreateRequest({ + ionDocument, + recoveryPublicKeyJwk : testKeySet.recoveryKey.publicKeyJwk, + updatePublicKeyJwk : testKeySet.updateKey.publicKeyJwk + }); + + if (!did) throw Error('Type guard'); + const decodedLongFormDid = await DidIonMethod.decodeLongFormDid({ didUrl: did }); + + expect(decodedLongFormDid).to.deep.equal(createRequest); + }); + }); + + describe('generateDwnOptions()', () => { + it('returns keys and services with two DWN URLs', async () => { + const ionCreateOptions = await DidIonMethod.generateDwnOptions({ + serviceEndpointNodes: [ + 'https://dwn.tbddev.test/dwn0', + 'https://dwn.tbddev.test/dwn1' + ]}); + + expect(ionCreateOptions).to.have.property('keySet'); + expect(ionCreateOptions.keySet.verificationMethodKeys).to.have.length(2); + const authorizationKey = ionCreateOptions.keySet.verificationMethodKeys.find(key => key.privateKeyJwk.kid === '#dwn-sig'); + expect(authorizationKey).to.exist; + const encryptionKey = ionCreateOptions.keySet.verificationMethodKeys.find(key => key.privateKeyJwk.kid === '#dwn-enc'); + expect(encryptionKey).to.exist; + + expect(ionCreateOptions).to.have.property('services'); + expect(ionCreateOptions.services).to.have.length(1); + + const [ service ] = ionCreateOptions.services; + expect(service.id).to.equal('#dwn'); + expect(service).to.have.property('serviceEndpoint'); + + const serviceEndpoint = service.serviceEndpoint as DwnServiceEndpoint; + expect(serviceEndpoint).to.have.property('nodes'); + expect(serviceEndpoint.nodes).to.have.length(2); + expect(serviceEndpoint).to.have.property('signingKeys'); + expect(serviceEndpoint.signingKeys[0]).to.equal(authorizationKey.publicKeyJwk.kid); + expect(serviceEndpoint).to.have.property('encryptionKeys'); + expect(serviceEndpoint.encryptionKeys[0]).to.equal(encryptionKey.publicKeyJwk.kid); + }); + + it('returns keys and services with one DWN URLs', async () => { + const ionCreateOptions = await DidIonMethod.generateDwnOptions({ + serviceEndpointNodes: [ + 'https://dwn.tbddev.test/dwn0' + ]}); + + const [ service ] = ionCreateOptions.services!; + expect(service.id).to.equal('#dwn'); + expect(service).to.have.property('serviceEndpoint'); + + const serviceEndpoint = service.serviceEndpoint as DwnServiceEndpoint; + expect(serviceEndpoint).to.have.property('nodes'); + expect(serviceEndpoint.nodes).to.have.length(1); + expect(serviceEndpoint).to.have.property('signingKeys'); + expect(serviceEndpoint).to.have.property('encryptionKeys'); + }); + + it('returns keys and services with 0 DWN URLs', async () => { + const ionCreateOptions = await DidIonMethod.generateDwnOptions({ serviceEndpointNodes: [] }); + + const [ service ] = ionCreateOptions.services!; + expect(service.id).to.equal('#dwn'); + expect(service).to.have.property('serviceEndpoint'); + + const serviceEndpoint = service.serviceEndpoint as DwnServiceEndpoint; + expect(serviceEndpoint).to.have.property('nodes'); + expect(serviceEndpoint.nodes).to.have.length(0); + expect(serviceEndpoint).to.have.property('signingKeys'); + expect(serviceEndpoint).to.have.property('encryptionKeys'); + }); + }); + + describe('generateJwkKeyPair()', () => { + it('generates an Ed25519 JwkKeyPair', async () => { + const jwkKeyPair = await DidIonMethod.generateJwkKeyPair({ keyAlgorithm: 'Ed25519' }); + expect(jwkKeyPair).to.be.an('object'); + expect(jwkKeyPair.privateKeyJwk.kty).to.equal('OKP'); + if (!('crv' in jwkKeyPair.privateKeyJwk)) throw new Error('Type guard'); + expect(jwkKeyPair.privateKeyJwk.crv).to.equal('Ed25519'); + if (!('crv' in jwkKeyPair.publicKeyJwk)) throw new Error('Type guard'); + expect(jwkKeyPair.publicKeyJwk.kty).to.equal('OKP'); + expect(jwkKeyPair.publicKeyJwk.crv).to.equal('Ed25519'); + }); + + it('generates a secp256k1 JwkKeyPair', async () => { + const jwkKeyPair = await DidIonMethod.generateJwkKeyPair({ keyAlgorithm: 'secp256k1' }); + expect(jwkKeyPair).to.be.an('object'); + expect(jwkKeyPair.privateKeyJwk.kty).to.equal('EC'); + if (!('crv' in jwkKeyPair.privateKeyJwk)) throw new Error('Type guard'); + expect(jwkKeyPair.privateKeyJwk.crv).to.equal('secp256k1'); + expect(jwkKeyPair.publicKeyJwk.kty).to.equal('EC'); + if (!('crv' in jwkKeyPair.publicKeyJwk)) throw new Error('Type guard'); + expect(jwkKeyPair.publicKeyJwk.crv).to.equal('secp256k1'); + }); + + it('generates a JwkKeyPair with a custom key ID', async () => { + const keyId = 'custom-key-id'; + const jwkKeyPair = await DidIonMethod.generateJwkKeyPair({ keyAlgorithm: 'Ed25519', keyId }); + expect(jwkKeyPair.privateKeyJwk.kid).to.equal(keyId); + expect(jwkKeyPair.publicKeyJwk.kid).to.equal(keyId); + }); + + it('throws an error for unsupported key algorithm', async () => { + await expect( + // @ts-expect-error because an invalid algorithm is being intentionally specified. + DidIonMethod.generateJwkKeyPair({ keyAlgorithm: 'unsupported-algorithm' }) + ).to.eventually.be.rejectedWith(Error, 'Unsupported crypto algorithm'); + }); + }); + + describe('getDefaultSigningKey()', () => { + it('returns the did:ion default signing key from long form DID, when present', async () => { + const partialDidDocument: Partial = { + id : 'did:ion:EiAO3IAedMSHaGOZIuIVwLEBHd0SEuWwt2h00dbiGD7Hww:eyJkZWx0YSI6eyJwYXRjaGVzIjpbeyJhY3Rpb24iOiJyZXBsYWNlIiwiZG9jdW1lbnQiOnsicHVibGljS2V5cyI6W3siaWQiOiJkd24tc2lnIiwicHVibGljS2V5SndrIjp7ImNydiI6IkVkMjU1MTkiLCJrdHkiOiJPS1AiLCJ4IjoicnBLbkRQOEY0X2p3dlE3eERra3VLeDE2NU9Td2N5clF2bUVXbDJlaWdJVSJ9LCJwdXJwb3NlcyI6WyJhdXRoZW50aWNhdGlvbiJdLCJ0eXBlIjoiSnNvbldlYktleTIwMjAifV0sInNlcnZpY2VzIjpbXX19XSwidXBkYXRlQ29tbWl0bWVudCI6IkVpRFZyOHUzVWxvOGtNVUx3WEh6VUdSMFdGdy1ROU14el8zRGQyQXEwVF9KR3cifSwic3VmZml4RGF0YSI6eyJkZWx0YUhhc2giOiJFaUJOX1JaeXZka1lmb2tkRlV5MTNiWnFwR2gzdmhZU3IxVnh3MmVieE5uQzZRIiwicmVjb3ZlcnlDb21taXRtZW50IjoiRWlEOEQtdjlsVjdqTzZ3ajVjSXVsRXRwZEFqaHE5NEFnTm54SlozWThVUnlrZyJ9fQ', + service : [ + { + id : '#dwn', + type : 'DecentralizedWebNode', + serviceEndpoint : { + encryptionKeys: [ + '#dwn-enc' + ], + nodes: [ + 'https://dwn.tbddev.test/dwn0', + 'https://dwn.tbddev.test/dwn1' + ], + signingKeys: [ + '#dwn-sig' + ] + } + } + ], + }; + + const defaultSigningKeyId = await DidIonMethod.getDefaultSigningKey({ + didDocument: partialDidDocument as DidDocument + }); + + expect(defaultSigningKeyId).to.equal('did:ion:EiAO3IAedMSHaGOZIuIVwLEBHd0SEuWwt2h00dbiGD7Hww:eyJkZWx0YSI6eyJwYXRjaGVzIjpbeyJhY3Rpb24iOiJyZXBsYWNlIiwiZG9jdW1lbnQiOnsicHVibGljS2V5cyI6W3siaWQiOiJkd24tc2lnIiwicHVibGljS2V5SndrIjp7ImNydiI6IkVkMjU1MTkiLCJrdHkiOiJPS1AiLCJ4IjoicnBLbkRQOEY0X2p3dlE3eERra3VLeDE2NU9Td2N5clF2bUVXbDJlaWdJVSJ9LCJwdXJwb3NlcyI6WyJhdXRoZW50aWNhdGlvbiJdLCJ0eXBlIjoiSnNvbldlYktleTIwMjAifV0sInNlcnZpY2VzIjpbXX19XSwidXBkYXRlQ29tbWl0bWVudCI6IkVpRFZyOHUzVWxvOGtNVUx3WEh6VUdSMFdGdy1ROU14el8zRGQyQXEwVF9KR3cifSwic3VmZml4RGF0YSI6eyJkZWx0YUhhc2giOiJFaUJOX1JaeXZka1lmb2tkRlV5MTNiWnFwR2gzdmhZU3IxVnh3MmVieE5uQzZRIiwicmVjb3ZlcnlDb21taXRtZW50IjoiRWlEOEQtdjlsVjdqTzZ3ajVjSXVsRXRwZEFqaHE5NEFnTm54SlozWThVUnlrZyJ9fQ#dwn-sig'); + }); + + it('returns the did:ion default signing key from short form DID, when present', async () => { + const partialDidDocument: Partial = { + id : 'did:ion:EiAO3IAedMSHaGOZIuIVwLEBHd0SEuWwt2h00dbiGD7Hww:eyJkZWx0YSI6eyJwYXRjaGVzIjpbeyJhY3Rpb24iOiJyZXBsYWNlIiwiZG9jdW1lbnQiOnsicHVibGljS2V5cyI6W3siaWQiOiJkd24tc2lnIiwicHVibGljS2V5SndrIjp7ImNydiI6IkVkMjU1MTkiLCJrdHkiOiJPS1AiLCJ4IjoicnBLbkRQOEY0X2p3dlE3eERra3VLeDE2NU9Td2N5clF2bUVXbDJlaWdJVSJ9LCJwdXJwb3NlcyI6WyJhdXRoZW50aWNhdGlvbiJdLCJ0eXBlIjoiSnNvbldlYktleTIwMjAifV0sInNlcnZpY2VzIjpbXX19XSwidXBkYXRlQ29tbWl0bWVudCI6IkVpRFZyOHUzVWxvOGtNVUx3WEh6VUdSMFdGdy1ROU14el8zRGQyQXEwVF9KR3cifSwic3VmZml4RGF0YSI6eyJkZWx0YUhhc2giOiJFaUJOX1JaeXZka1lmb2tkRlV5MTNiWnFwR2gzdmhZU3IxVnh3MmVieE5uQzZRIiwicmVjb3ZlcnlDb21taXRtZW50IjoiRWlEOEQtdjlsVjdqTzZ3ajVjSXVsRXRwZEFqaHE5NEFnTm54SlozWThVUnlrZyJ9fQ', + service : [ + { + id : '#dwn', + type : 'DecentralizedWebNode', + serviceEndpoint : { + encryptionKeys: [ + '#dwn-enc' + ], + nodes: [ + 'https://dwn.tbddev.test/dwn0', + 'https://dwn.tbddev.test/dwn1' + ], + signingKeys: [ + '#dwn-sig' + ] + } + } + ], + }; + + const defaultSigningKeyId = await DidIonMethod.getDefaultSigningKey({ + didDocument: partialDidDocument as DidDocument + }); + + expect(defaultSigningKeyId).to.equal('did:ion:EiAO3IAedMSHaGOZIuIVwLEBHd0SEuWwt2h00dbiGD7Hww:eyJkZWx0YSI6eyJwYXRjaGVzIjpbeyJhY3Rpb24iOiJyZXBsYWNlIiwiZG9jdW1lbnQiOnsicHVibGljS2V5cyI6W3siaWQiOiJkd24tc2lnIiwicHVibGljS2V5SndrIjp7ImNydiI6IkVkMjU1MTkiLCJrdHkiOiJPS1AiLCJ4IjoicnBLbkRQOEY0X2p3dlE3eERra3VLeDE2NU9Td2N5clF2bUVXbDJlaWdJVSJ9LCJwdXJwb3NlcyI6WyJhdXRoZW50aWNhdGlvbiJdLCJ0eXBlIjoiSnNvbldlYktleTIwMjAifV0sInNlcnZpY2VzIjpbXX19XSwidXBkYXRlQ29tbWl0bWVudCI6IkVpRFZyOHUzVWxvOGtNVUx3WEh6VUdSMFdGdy1ROU14el8zRGQyQXEwVF9KR3cifSwic3VmZml4RGF0YSI6eyJkZWx0YUhhc2giOiJFaUJOX1JaeXZka1lmb2tkRlV5MTNiWnFwR2gzdmhZU3IxVnh3MmVieE5uQzZRIiwicmVjb3ZlcnlDb21taXRtZW50IjoiRWlEOEQtdjlsVjdqTzZ3ajVjSXVsRXRwZEFqaHE5NEFnTm54SlozWThVUnlrZyJ9fQ#dwn-sig'); + }); + + it(`returns first 'authentication' key if DID document is missing 'signingKeys'`, async () => { + const partialDidDocument: Partial = { + id : 'did:ion:EiAO3IAedMSHaGOZIuIVwLEBHd0SEuWwt2h00dbiGD7Hww:eyJkZWx0YSI6eyJwYXRjaGVzIjpbeyJhY3Rpb24iOiJyZXBsYWNlIiwiZG9jdW1lbnQiOnsicHVibGljS2V5cyI6W3siaWQiOiJkd24tc2lnIiwicHVibGljS2V5SndrIjp7ImNydiI6IkVkMjU1MTkiLCJrdHkiOiJPS1AiLCJ4IjoicnBLbkRQOEY0X2p3dlE3eERra3VLeDE2NU9Td2N5clF2bUVXbDJlaWdJVSJ9LCJwdXJwb3NlcyI6WyJhdXRoZW50aWNhdGlvbiJdLCJ0eXBlIjoiSnNvbldlYktleTIwMjAifV0sInNlcnZpY2VzIjpbXX19XSwidXBkYXRlQ29tbWl0bWVudCI6IkVpRFZyOHUzVWxvOGtNVUx3WEh6VUdSMFdGdy1ROU14el8zRGQyQXEwVF9KR3cifSwic3VmZml4RGF0YSI6eyJkZWx0YUhhc2giOiJFaUJOX1JaeXZka1lmb2tkRlV5MTNiWnFwR2gzdmhZU3IxVnh3MmVieE5uQzZRIiwicmVjb3ZlcnlDb21taXRtZW50IjoiRWlEOEQtdjlsVjdqTzZ3ajVjSXVsRXRwZEFqaHE5NEFnTm54SlozWThVUnlrZyJ9fQ', + 'verificationMethod' : [ + { + id : '#OAPj7ObrEJFgVNA2rrkPM5A-vYVsH_lyz4LgOUdJBa8', + type : 'JsonWebKey2020', + controller : 'did:ion:EiBP6JaGhwYye4zz-wdeXR2JWl1JclaVDPA7FDgpzM8-ig:eyJkZWx0YSI6eyJwYXRjaGVzIjpbeyJhY3Rpb24iOiJyZXBsYWNlIiwiZG9jdW1lbnQiOnsicHVibGljS2V5cyI6W3siaWQiOiJPQVBqN09ickVKRmdWTkEycnJrUE01QS12WVZzSF9seXo0TGdPVWRKQmE4IiwicHVibGljS2V5SndrIjp7ImNydiI6IkVkMjU1MTkiLCJrdHkiOiJPS1AiLCJ4IjoicnBLbkRQOEY0X2p3dlE3eERra3VLeDE2NU9Td2N5clF2bUVXbDJlaWdJVSJ9LCJwdXJwb3NlcyI6WyJhdXRoZW50aWNhdGlvbiJdLCJ0eXBlIjoiSnNvbldlYktleTIwMjAifV0sInNlcnZpY2VzIjpbXX19XSwidXBkYXRlQ29tbWl0bWVudCI6IkVpRFZyOHUzVWxvOGtNVUx3WEh6VUdSMFdGdy1ROU14el8zRGQyQXEwVF9KR3cifSwic3VmZml4RGF0YSI6eyJkZWx0YUhhc2giOiJFaUNUMEh4ZGNTRHkwQ0t5eHV4VkZ3d3A3N3YteEJkSkVRLUVtSXhZUGR4VnV3IiwicmVjb3ZlcnlDb21taXRtZW50IjoiRWlEOEQtdjlsVjdqTzZ3ajVjSXVsRXRwZEFqaHE5NEFnTm54SlozWThVUnlrZyJ9fQ', + publicKeyJwk : { + crv : 'Ed25519', + kty : 'OKP', + x : 'rpKnDP8F4_jwvQ7xDkkuKx165OSwcyrQvmEWl2eigIU' + } + } + ], + service: [ + { + id : '#dwn', + type : 'DecentralizedWebNode', + serviceEndpoint : { + encryptionKeys: [ + '#dwn-enc' + ], + nodes: [ + 'https://dwn.tbddev.test/dwn0', + 'https://dwn.tbddev.test/dwn1' + ] + } + } + ], + authentication: [ + '#OAPj7ObrEJFgVNA2rrkPM5A-vYVsH_lyz4LgOUdJBa8' + ], + }; + + const defaultSigningKeyId = await DidIonMethod.getDefaultSigningKey({ + didDocument: partialDidDocument as DidDocument + }); + + expect(defaultSigningKeyId).to.equal('did:ion:EiAO3IAedMSHaGOZIuIVwLEBHd0SEuWwt2h00dbiGD7Hww:eyJkZWx0YSI6eyJwYXRjaGVzIjpbeyJhY3Rpb24iOiJyZXBsYWNlIiwiZG9jdW1lbnQiOnsicHVibGljS2V5cyI6W3siaWQiOiJkd24tc2lnIiwicHVibGljS2V5SndrIjp7ImNydiI6IkVkMjU1MTkiLCJrdHkiOiJPS1AiLCJ4IjoicnBLbkRQOEY0X2p3dlE3eERra3VLeDE2NU9Td2N5clF2bUVXbDJlaWdJVSJ9LCJwdXJwb3NlcyI6WyJhdXRoZW50aWNhdGlvbiJdLCJ0eXBlIjoiSnNvbldlYktleTIwMjAifV0sInNlcnZpY2VzIjpbXX19XSwidXBkYXRlQ29tbWl0bWVudCI6IkVpRFZyOHUzVWxvOGtNVUx3WEh6VUdSMFdGdy1ROU14el8zRGQyQXEwVF9KR3cifSwic3VmZml4RGF0YSI6eyJkZWx0YUhhc2giOiJFaUJOX1JaeXZka1lmb2tkRlV5MTNiWnFwR2gzdmhZU3IxVnh3MmVieE5uQzZRIiwicmVjb3ZlcnlDb21taXRtZW50IjoiRWlEOEQtdjlsVjdqTzZ3ajVjSXVsRXRwZEFqaHE5NEFnTm54SlozWThVUnlrZyJ9fQ#OAPj7ObrEJFgVNA2rrkPM5A-vYVsH_lyz4LgOUdJBa8'); + }); + + it(`returns short form DID when DID has been anchored/published`, async () => { + let partialDidDocument: Partial = { + id : 'did:ion:EiAO3IAedMSHaGOZIuIVwLEBHd0SEuWwt2h00dbiGD7Hww', + service : [ + { + id : '#dwn', + type : 'DecentralizedWebNode', + serviceEndpoint : { + encryptionKeys: [ + '#dwn-enc' + ], + nodes: [ + 'https://dwn.tbddev.test/dwn0', + 'https://dwn.tbddev.test/dwn1' + ], + signingKeys: [ + '#dwn-sig' + ] + } + } + ], + }; + + let defaultSigningKeyId = await DidIonMethod.getDefaultSigningKey({ + didDocument: partialDidDocument as DidDocument + }); + + expect(defaultSigningKeyId).to.equal('did:ion:EiAO3IAedMSHaGOZIuIVwLEBHd0SEuWwt2h00dbiGD7Hww#dwn-sig'); + + partialDidDocument = { + 'id' : 'did:ion:EiCab9QRUcUTKKIM-W2SMCwnOPxa4y0q7emoWJDSOSz3HQ', + 'service' : [], + 'verificationMethod' : [ + { + 'id' : '#dwn-sig', + 'controller' : 'did:ion:EiCab9QRUcUTKKIM-W2SMCwnOPxa4y0q7emoWJDSOSz3HQ', + 'type' : 'JsonWebKey2020', + 'publicKeyJwk' : { + 'crv' : 'Ed25519', + 'kty' : 'OKP', + 'x' : 'Sy0lk6pMXC10WyIh4g8sLz1loL8ImzLcqmFW2267IXc' + } + } + ], + 'authentication': [ + '#dwn-sig' + ] + }; + + defaultSigningKeyId = await DidIonMethod.getDefaultSigningKey({ + didDocument: partialDidDocument as DidDocument + }); + + expect(defaultSigningKeyId).to.equal('did:ion:EiCab9QRUcUTKKIM-W2SMCwnOPxa4y0q7emoWJDSOSz3HQ#dwn-sig'); + }); + + it(`returns undefined if DID document is missing 'signingKeys' and 'authentication'`, async () => { + const partialDidDocument: Partial = { + id : 'did:ion:EiAO3IAedMSHaGOZIuIVwLEBHd0SEuWwt2h00dbiGD7Hww:eyJkZWx0YSI6eyJwYXRjaGVzIjpbeyJhY3Rpb24iOiJyZXBsYWNlIiwiZG9jdW1lbnQiOnsicHVibGljS2V5cyI6W3siaWQiOiJkd24tc2lnIiwicHVibGljS2V5SndrIjp7ImNydiI6IkVkMjU1MTkiLCJrdHkiOiJPS1AiLCJ4IjoicnBLbkRQOEY0X2p3dlE3eERra3VLeDE2NU9Td2N5clF2bUVXbDJlaWdJVSJ9LCJwdXJwb3NlcyI6WyJhdXRoZW50aWNhdGlvbiJdLCJ0eXBlIjoiSnNvbldlYktleTIwMjAifV0sInNlcnZpY2VzIjpbXX19XSwidXBkYXRlQ29tbWl0bWVudCI6IkVpRFZyOHUzVWxvOGtNVUx3WEh6VUdSMFdGdy1ROU14el8zRGQyQXEwVF9KR3cifSwic3VmZml4RGF0YSI6eyJkZWx0YUhhc2giOiJFaUJOX1JaeXZka1lmb2tkRlV5MTNiWnFwR2gzdmhZU3IxVnh3MmVieE5uQzZRIiwicmVjb3ZlcnlDb21taXRtZW50IjoiRWlEOEQtdjlsVjdqTzZ3ajVjSXVsRXRwZEFqaHE5NEFnTm54SlozWThVUnlrZyJ9fQ', + service : [ + { + id : '#dwn', + type : 'DecentralizedWebNode', + serviceEndpoint : { + encryptionKeys: [ + '#dwn-enc' + ], + nodes: [ + 'https://dwn.tbddev.test/dwn0', + 'https://dwn.tbddev.test/dwn1' + ] + } + } + ], + }; + + const defaultSigningKeyId = await DidIonMethod.getDefaultSigningKey({ + didDocument: partialDidDocument as DidDocument + }); + + expect(defaultSigningKeyId).to.be.undefined; + }); + + it(`throws error if DID document is missing 'id' property`, async () => { + const partialDidDocument: Partial = {}; + + await expect( + DidIonMethod.getDefaultSigningKey({ + didDocument: partialDidDocument as DidDocument + }) + ).to.eventually.be.rejectedWith(Error, `DID document is missing 'id' property`); + }); + }); + + describe('resolve()', () => { + it('resolves published short form ION DIDs', async() => { + const did = 'did:ion:EiCab9QRUcUTKKIM-W2SMCwnOPxa4y0q7emoWJDSOSz3HQ'; + const resolutionResult = await DidIonMethod.resolve({ didUrl: did }); + + expect(resolutionResult).to.have.property('@context'); + expect(resolutionResult).to.have.property('didDocument'); + expect(resolutionResult).to.have.property('didDocumentMetadata'); + + expect(resolutionResult.didDocument).to.have.property('id', did); + expect(resolutionResult.didDocumentMetadata.method).to.have.property('published', true); + }); + + it('returns notFound error with unpublished short form ION DIDs', async() => { + const did = 'did:ion:EiBCi7lnGtotBsFkbI_lQskQZLk_GPelU0C5-nRB4_nMfA'; + const resolutionResult = await DidIonMethod.resolve({ didUrl: did }); + + expect(resolutionResult).to.have.property('@context'); + expect(resolutionResult).to.have.property('didDocument'); + expect(resolutionResult).to.have.property('didDocumentMetadata'); + + expect(resolutionResult.didResolutionMetadata).to.have.property('error', 'notFound'); + }); + + it('resolves published long form ION DIDs', async() => { + const did = 'did:ion:EiAi68p2irCNQIzaui8gTjGDeOqSUusZS8jWVHfseSWZ5g:eyJkZWx0YSI6eyJwYXRjaGVzIjpbeyJhY3Rpb24iOiJyZXBsYWNlIiwiZG9jdW1lbnQiOnsicHVibGljS2V5cyI6W3siaWQiOiJrZXktMSIsInB1YmxpY0tleUp3ayI6eyJjcnYiOiJzZWNwMjU2azEiLCJrdHkiOiJFQyIsIngiOiI2MWlQWXVHZWZ4b3R6QmRRWnREdnY2Y1dIWm1YclRUc2NZLXU3WTJwRlpjIiwieSI6Ijg4blBDVkxmckFZOWktd2c1T1Jjd1ZiSFdDX3RiZUFkMUpFMmUwY28wbFUifSwicHVycG9zZXMiOlsiYXV0aGVudGljYXRpb24iXSwidHlwZSI6IkVjZHNhU2VjcDI1NmsxVmVyaWZpY2F0aW9uS2V5MjAxOSJ9XSwic2VydmljZXMiOlt7ImlkIjoiZHduIiwic2VydmljZUVuZHBvaW50Ijp7Im5vZGVzIjpbImh0dHA6Ly9sb2NhbGhvc3Q6ODA4NSJdfSwidHlwZSI6IkRlY2VudHJhbGl6ZWRXZWJOb2RlIn1dfX1dLCJ1cGRhdGVDb21taXRtZW50IjoiRWlCb1c2dGs4WlZRTWs3YjFubkF2R3F3QTQ2amlaaUc2dWNYemxyNTZDWWFiUSJ9LCJzdWZmaXhEYXRhIjp7ImRlbHRhSGFzaCI6IkVpQ3Y2cUhEMFV4TTBadmZlTHU4dDR4eU5DVjNscFBSaTl6a3paU3h1LW8wWUEiLCJyZWNvdmVyeUNvbW1pdG1lbnQiOiJFaUN0STM0ckdGNU9USkJETXRUYm14a1lQeC0ydFd3MldZLTU2UTVPNHR0WWJBIn19'; + const resolutionResult = await DidIonMethod.resolve({ didUrl: did }); + + expect(resolutionResult).to.have.property('@context'); + expect(resolutionResult).to.have.property('didDocument'); + expect(resolutionResult).to.have.property('didDocumentMetadata'); + + expect(resolutionResult.didDocument).to.have.property('id', did); + expect(resolutionResult.didDocumentMetadata.method).to.have.property('published', true); + }); + + + it('resolves unpublished long form ION DIDs', async() => { + const did = 'did:ion:EiBCi7lnGtotBsFkbI_lQskQZLk_GPelU0C5-nRB4_nMfA:eyJkZWx0YSI6eyJwYXRjaGVzIjpbeyJhY3Rpb24iOiJyZXBsYWNlIiwiZG9jdW1lbnQiOnsicHVibGljS2V5cyI6W3siaWQiOiJkd24tc2lnIiwicHVibGljS2V5SndrIjp7ImNydiI6IkVkMjU1MTkiLCJrdHkiOiJPS1AiLCJ4Ijoib0xVQmdKUnA1dlVfSTdfOXB3UTFkb2IwSWg2VjUwT2FrenNOY2R6Uk1CbyJ9LCJwdXJwb3NlcyI6WyJhdXRoZW50aWNhdGlvbiJdLCJ0eXBlIjoiSnNvbldlYktleTIwMjAifV0sInNlcnZpY2VzIjpbXX19XSwidXBkYXRlQ29tbWl0bWVudCI6IkVpQlRRYlV6cmlTU3FEVVpPb0JvUTZWek5wWFRvQWNtSjNHMlBIZzJ3ZXpFcHcifSwic3VmZml4RGF0YSI6eyJkZWx0YUhhc2giOiJFaURLSFlkRFRpT3lCTWRORWtBcGJtUklHU1ExOFctUHFUeGlrZ0IzX1RpSlVBIiwicmVjb3ZlcnlDb21taXRtZW50IjoiRWlBb2pZYzV6eTR2RFZFdElnS1lzWHgtdnBnZzNEeXBUOW0tRmtfMXZ0WHBkQSJ9fQ'; + const resolutionResult = await DidIonMethod.resolve({ didUrl: did }); + + expect(resolutionResult).to.have.property('@context'); + expect(resolutionResult).to.have.property('didDocument'); + expect(resolutionResult).to.have.property('didDocumentMetadata'); + + expect(resolutionResult.didDocument).to.have.property('id', did); + expect(resolutionResult.didDocumentMetadata.method).to.have.property('published', false); + }); + + it('returns internalError if custom DID resolver returns invalid response', async () => { + // Setup stub so that a mocked response is returned rather than calling over the network. + const mockResult = ` + 404 Not Found + +

404 Not Found

+
nginx/1.25.1
+ + `; + const fetchStub = sinon.stub(global, 'fetch'); + // @ts-expect-error because we're only mocking ok and json() from global.fetch(). + fetchStub.returns(Promise.resolve({ + ok : false, + json : () => Promise.reject(JSON.parse(mockResult)) + })); + + const did = 'did:ion:EiCab9QRUcUTKKIM-W2SMCwnOPxa4y0q7emoWJDSOSz3HQ'; + const resolutionResult = await DidIonMethod.resolve({ + didUrl : did, + resolutionOptions : { resolutionEndpoint: 'https://dev.uniresolver.io/7.5/identifiers' } + }); + fetchStub.restore(); + + expect(resolutionResult).to.have.property('@context'); + expect(resolutionResult).to.have.property('didDocument'); + expect(resolutionResult).to.have.property('didDocumentMetadata'); + + expect(resolutionResult.didResolutionMetadata).to.have.property('error', 'internalError'); + }); + + it(`returns methodNotSupported if DID method is not 'ion'`, async () => { + const did = 'did:key:z6MkvEvogvhMEv9bXLyDXdqSSvvh5goAMtUruYwCbFpuhDjx'; + const resolutionResult = await DidIonMethod.resolve({ didUrl: did }); + expect(resolutionResult).to.have.property('@context'); + expect(resolutionResult).to.have.property('didDocument'); + expect(resolutionResult).to.have.property('didDocumentMetadata'); + + expect(resolutionResult.didResolutionMetadata).to.have.property('error', 'methodNotSupported'); + }); + + it('accepts custom DID resolver with trailing slash', async () => { + const mockResult = { mock: 'data' }; + const fetchStub = sinon.stub(global, 'fetch'); + // @ts-expect-error because we're only mocking ok and json() from global.fetch(). + fetchStub.returns(Promise.resolve({ + ok : true, + json : () => Promise.resolve(mockResult) + })); + + const did = 'did:ion:EiCab9QRUcUTKKIM-W2SMCwnOPxa4y0q7emoWJDSOSz3HQ'; + const resolutionResult = await DidIonMethod.resolve({ + didUrl : did, + resolutionOptions : { resolutionEndpoint: 'https://dev.uniresolver.io/1.0/identifiers/' } + }); + fetchStub.restore(); + + expect(resolutionResult).to.deep.equal(mockResult); + expect(fetchStub.calledOnceWith( + `https://dev.uniresolver.io/1.0/identifiers/${did}` + )).to.be.true; + }); + + it('accepts custom DID resolver without trailing slash', async () => { + const mockResult = { mock: 'data' }; + const fetchStub = sinon.stub(global, 'fetch'); + // @ts-expect-error because we're only mocking ok and json() from global.fetch(). + fetchStub.returns(Promise.resolve({ + ok : true, + json : () => Promise.resolve(mockResult) + })); + + const did = 'did:ion:EiCab9QRUcUTKKIM-W2SMCwnOPxa4y0q7emoWJDSOSz3HQ'; + const resolutionResult = await DidIonMethod.resolve({ + didUrl : did, + resolutionOptions : { resolutionEndpoint: 'https://dev.uniresolver.io/1.0/identifiers' } + }); + fetchStub.restore(); + + expect(resolutionResult).to.deep.equal(mockResult); + expect(fetchStub.calledOnceWith( + `https://dev.uniresolver.io/1.0/identifiers/${did}` + )).to.be.true; }); }); }); \ No newline at end of file diff --git a/packages/dids/tests/did-key.spec.ts b/packages/dids/tests/did-key.spec.ts index ea5775ee3..682d2dbe4 100644 --- a/packages/dids/tests/did-key.spec.ts +++ b/packages/dids/tests/did-key.spec.ts @@ -1,27 +1,108 @@ import { expect } from 'chai'; -import { DidKeyApi } from '../src/did-key.js'; -const DidKey = new DidKeyApi(); +import type { DidKeyCreateOptions, DidKeyCreateDocumentOptions } from '../src/did-key.js'; -describe('DidKeyApi', () => { - it('works', async () => { - const didState = await DidKey.create(); +import { DidKeyMethod } from '../src/did-key.js'; +import { didKeyCreateTestVectors, didKeyCreateDocumentTestVectors, } from './fixtures/test-vectors/did-key.js'; +import { DidDocument } from '../src/types.js'; - expect(didState.id).to.exist; - expect(didState.internalId).to.exist; - expect(didState.keys).to.exist; +describe('DidKeyMethod', () => { + describe('create()', () => { + it('creates a DID with Ed25519 keys, by default', async () => { + const portableDid = await DidKeyMethod.create(); - expect(didState.methodData).to.exist; - expect(Object.keys(didState.methodData).length).to.equal(0); + // Verify expected result. + expect(portableDid).to.have.property('did'); + expect(portableDid).to.have.property('document'); + expect(portableDid).to.have.property('keySet'); + expect(portableDid.keySet).to.have.property('verificationMethodKeys'); + expect(portableDid.keySet.verificationMethodKeys).to.have.length(1); + expect(portableDid.keySet.verificationMethodKeys?.[0]).to.have.property('publicKeyJwk'); + expect(portableDid.keySet.verificationMethodKeys?.[0]).to.have.property('privateKeyJwk'); + expect(portableDid.keySet.verificationMethodKeys?.[0].publicKeyJwk).to.have.property('alg', 'EdDSA'); + expect(portableDid.keySet.verificationMethodKeys?.[0].publicKeyJwk).to.have.property('crv', 'Ed25519'); + }); - expect((didState as any).services).to.not.exist; + it('creates a DID with secp256k1 keys, if specified', async () => { + const portableDid = await DidKeyMethod.create({ keyAlgorithm: 'secp256k1' }); - for (let key of didState.keys) { - expect(key.id).to.exist; - expect(key.controller).to.exist; - expect(key.publicKeyJwk).to.exist; - expect(key.privateKeyJwk).to.exist; - expect(key.type).to.exist; + // Verify expected result. + expect(portableDid).to.have.property('did'); + expect(portableDid).to.have.property('document'); + expect(portableDid).to.have.property('keySet'); + expect(portableDid.keySet).to.have.property('verificationMethodKeys'); + expect(portableDid.keySet.verificationMethodKeys).to.have.length(1); + expect(portableDid.keySet.verificationMethodKeys?.[0]).to.have.property('publicKeyJwk'); + expect(portableDid.keySet.verificationMethodKeys?.[0]).to.have.property('privateKeyJwk'); + expect(portableDid.keySet.verificationMethodKeys?.[0].publicKeyJwk).to.have.property('alg', 'ES256K'); + expect(portableDid.keySet.verificationMethodKeys?.[0].publicKeyJwk).to.have.property('crv', 'secp256k1'); + }); + + for (const vector of didKeyCreateTestVectors ) { + it(`passes test vector ${vector.id}`, async () => { + const portableDid = await DidKeyMethod.create(vector.input as DidKeyCreateOptions); + + expect(portableDid).to.deep.equal(vector.output); + }); + } + }); + + describe('createDocument()', () => { + it('accepts an alternate default context', async () => { + const didDocument = await DidKeyMethod.createDocument({ + did : 'did:key:z6MkjVM3rLLh9KCFBfKPNA5oEBq6KXXsPu72FDX7cZzYJN3y', + defaultContext : 'https://www.w3.org/ns/did/v99', + publicKeyFormat : 'JsonWebKey2020' + }); + + expect(didDocument['@context']).to.include('https://www.w3.org/ns/did/v99'); + }); + + for (const vector of didKeyCreateDocumentTestVectors ) { + it(`passes test vector ${vector.id}`, async () => { + const didDocument = await DidKeyMethod.createDocument(vector.input as DidKeyCreateDocumentOptions); + expect(didDocument).to.deep.equal(vector.output); + }); } }); + + describe('getDefaultSigningKey()', () => { + it('returns the did:key default signing key, when present', async () => { + const partialDidDocument = { + authentication: [ + 'did:key:z6MkrCigh4zugDVEieqt4WbtWParigHeH5TEYEuKcSyCykUk#z6MkrCigh4zugDVEieqt4WbtWParigHeH5TEYEuKcSyCykUk' + ] + } as unknown as DidDocument; + + const defaultSigningKeyId = await DidKeyMethod.getDefaultSigningKey({ + didDocument: partialDidDocument + }); + + expect(defaultSigningKeyId).to.equal('did:key:z6MkrCigh4zugDVEieqt4WbtWParigHeH5TEYEuKcSyCykUk#z6MkrCigh4zugDVEieqt4WbtWParigHeH5TEYEuKcSyCykUk'); + }); + + it('returns undefined if the did:key default signing key is not present', async () => { + const partialDidDocument = { + authentication: [{ + id : 'did:key:z6LSgmjjYTAffdKWLmBbYxe5d5fgLzuZxi6PEbHZNt3Cifvg#z6LSgmjjYTAffdKWLmBbYxe5d5fgLzuZxi6PEbHZNt3Cifvg', + type : 'JsonWebKey2020', + controller : 'did:key:z6LSgmjjYTAffdKWLmBbYxe5d5fgLzuZxi6PEbHZNt3Cifvg', + publicKeyJwk : { + kty : 'OKP', + crv : 'X25519', + x : 'S7cqN2_-PIPK6fVjR6PrQ1YZyyw61ajVnAJClFcXVhk' + } + }], + keyAgreement: [ + 'did:key:z6LSqCkip7X19obTwRpWc8ZLLCiXLzVQBFpcBAsTW38m6Rzs#z6LSqCkip7X19obTwRpWc8ZLLCiXLzVQBFpcBAsTW38m6Rzs' + ] + } as unknown as DidDocument; + + const defaultSigningKeyId = await DidKeyMethod.getDefaultSigningKey({ + didDocument: partialDidDocument + }); + + expect(defaultSigningKeyId).to.be.undefined; + }); + }); }); \ No newline at end of file diff --git a/packages/dids/tests/did-resolver.spec.ts b/packages/dids/tests/did-resolver.spec.ts new file mode 100644 index 000000000..914e5a49d --- /dev/null +++ b/packages/dids/tests/did-resolver.spec.ts @@ -0,0 +1,117 @@ +import * as sinon from 'sinon'; +import { expect } from 'chai'; + +import { DidKeyMethod } from '../src/did-key.js'; +import { DidResolver } from '../src/did-resolver.js'; +import { didResolverTestVectors } from './fixtures/test-vectors/did-resolver.js'; +import { DidResolverCacheLevel } from '../src/resolver-cache-level.js'; +import { DidResolverCache } from '../src/types.js'; + +describe('DidResolver', () => { + describe('resolve()', () => { + let didResolver: DidResolver; + + describe('with no-op cache', () => { + beforeEach(() => { + const didMethodApis = [DidKeyMethod]; + didResolver = new DidResolver({ didResolvers: didMethodApis }); + }); + + it('returns an invalidDid error if the DID cannot be parsed', async () => { + const didResolutionResult = await didResolver.resolve('unparseable:did'); + expect(didResolutionResult).to.exist; + expect(didResolutionResult).to.have.property('@context'); + expect(didResolutionResult).to.have.property('didDocument'); + expect(didResolutionResult).to.have.property('didDocumentMetadata'); + expect(didResolutionResult).to.have.property('didResolutionMetadata'); + expect(didResolutionResult.didResolutionMetadata).to.have.property('error', 'invalidDid'); + }); + + it('returns a methodNotSupported error if the DID method is not supported', async () => { + const didResolutionResult = await didResolver.resolve('did:unknown:abc123'); + expect(didResolutionResult).to.exist; + expect(didResolutionResult).to.have.property('@context'); + expect(didResolutionResult).to.have.property('didDocument'); + expect(didResolutionResult).to.have.property('didDocumentMetadata'); + expect(didResolutionResult).to.have.property('didResolutionMetadata'); + expect(didResolutionResult.didResolutionMetadata).to.have.property('error', 'methodNotSupported'); + }); + + it('passes test vectors', async () => { + for (const vector of didResolverTestVectors) { + const didResolutionResult = await didResolver.resolve(vector.input); + expect(didResolutionResult.didDocument).to.deep.equal(vector.output); + } + }); + }); + + describe('with LevelDB cache', () => { + let cache: DidResolverCache; + + before(() => { + cache = new DidResolverCacheLevel(); + }); + + beforeEach(async () => { + await cache.clear(); + const didMethodApis = [DidKeyMethod]; + didResolver = new DidResolver({ cache, didResolvers: didMethodApis }); + }); + + after(async () => { + await cache.clear(); + }); + + it('should cache miss for the first resolution attempt', async () => { + const did = 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D'; + // Create a Sinon spy on the get method of the cache + const cacheGetSpy = sinon.spy(cache, 'get'); + + await didResolver.resolve(did); + + // Verify that cache.get() was called. + expect(cacheGetSpy.called).to.be.true; + + // Verify the cache returned undefined. + const getCacheResult = await cacheGetSpy.returnValues[0]; + expect(getCacheResult).to.be.undefined; + + cacheGetSpy.restore(); + }); + + it('should cache hit for the second resolution attempt', async () => { + const did = 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D'; + // Create a Sinon spy on the get method of the cache + const cacheGetSpy = sinon.spy(cache, 'get'); + const cacheSetSpy = sinon.spy(cache, 'set'); + + await didResolver.resolve(did); + + // Verify there was a cache miss. + expect(cacheGetSpy.calledOnce).to.be.true; + expect(cacheSetSpy.calledOnce).to.be.true; + + // Verify the cache returned undefined. + let getCacheResult = await cacheGetSpy.returnValues[0]; + expect(getCacheResult).to.be.undefined; + + // Resolve the same DID again. + await didResolver.resolve(did); + + // Verify that cache.get() was called. + expect(cacheGetSpy.called).to.be.true; + expect(cacheGetSpy.calledTwice).to.be.true; + + // Verify there was a cache hit this time. + getCacheResult = await cacheGetSpy.returnValues[1]; + expect(getCacheResult).to.not.be.undefined; + expect(getCacheResult).to.have.property('@context'); + expect(getCacheResult).to.have.property('didDocument'); + expect(getCacheResult).to.have.property('didDocumentMetadata'); + expect(getCacheResult).to.have.property('didResolutionMetadata'); + + cacheGetSpy.restore(); + }); + }); + }); +}); \ No newline at end of file diff --git a/packages/dids/tests/fixtures/test-vectors/did-ion.ts b/packages/dids/tests/fixtures/test-vectors/did-ion.ts new file mode 100644 index 000000000..872e6047d --- /dev/null +++ b/packages/dids/tests/fixtures/test-vectors/did-ion.ts @@ -0,0 +1,448 @@ +export const didIonCreateTestVectors = [ + { + id : 'did.create.1', + input : { + keySet: { + recoveryKey: { + privateKeyJwk: { + alg : 'ES256K', + crv : 'secp256k1', + d : 'cy4EzFT9K0sdCcz0gnctkcPq0szOP-d8smA9Hvp5ejo', + ext : 'true', + key_ops : ['sign'], + kid : 'ion-recovery-1', + kty : 'EC', + x : 'vLvKcPjYVnJi6dZpq15PrJqdxBERuvL8EqvTh1_0ikg', + y : 'AsQstiUIt5tGyAyM7LzytsbdVbsb-5oWVNYIUEjOePs' + }, + publicKeyJwk: { + alg : 'ES256K', + crv : 'secp256k1', + ext : 'true', + key_ops : ['verify'], + kid : 'ion-recovery-1', + kty : 'EC', + x : 'vLvKcPjYVnJi6dZpq15PrJqdxBERuvL8EqvTh1_0ikg', + y : 'AsQstiUIt5tGyAyM7LzytsbdVbsb-5oWVNYIUEjOePs' + }, + }, + updateKey: { + privateKeyJwk: { + alg : 'ES256K', + crv : 'secp256k1', + d : 'j4VcN2I5uw5kwPC5e8rxDaA7OxkmrJ-2BgdyKwayO9E', + ext : 'true', + key_ops : ['sign'], + kid : 'ion-update-1', + kty : 'EC', + x : '4Z9Tt1tuFlI3YwJfT3eS72r0sa9UxdtalgW14gep2DQ', + y : 'FIAtUW8B54L0Y-0e9n_rc1GJhxMIkZ3iYGnMQufgT_s' + }, + publicKeyJwk: { + alg : 'ES256K', + crv : 'secp256k1', + ext : 'true', + key_ops : ['verify'], + kid : 'ion-update-1', + kty : 'EC', + x : '4Z9Tt1tuFlI3YwJfT3eS72r0sa9UxdtalgW14gep2DQ', + y : 'FIAtUW8B54L0Y-0e9n_rc1GJhxMIkZ3iYGnMQufgT_s' + } + }, + verificationMethodKeys: [{ + publicKeyJwk: { + alg : 'EdDSA', + crv : 'Ed25519', + kid : 'dwn-sig', + kty : 'OKP', + x : 'rpKnDP8F4_jwvQ7xDkkuKx165OSwcyrQvmEWl2eigIU' + }, + relationships: ['authentication'] + }], + }, + keyAlgorithm: 'Ed25519' + }, + output: { + canonicalId : 'did:ion:EiAO3IAedMSHaGOZIuIVwLEBHd0SEuWwt2h00dbiGD7Hww', + did : 'did:ion:EiAO3IAedMSHaGOZIuIVwLEBHd0SEuWwt2h00dbiGD7Hww:eyJkZWx0YSI6eyJwYXRjaGVzIjpbeyJhY3Rpb24iOiJyZXBsYWNlIiwiZG9jdW1lbnQiOnsicHVibGljS2V5cyI6W3siaWQiOiJkd24tc2lnIiwicHVibGljS2V5SndrIjp7ImNydiI6IkVkMjU1MTkiLCJrdHkiOiJPS1AiLCJ4IjoicnBLbkRQOEY0X2p3dlE3eERra3VLeDE2NU9Td2N5clF2bUVXbDJlaWdJVSJ9LCJwdXJwb3NlcyI6WyJhdXRoZW50aWNhdGlvbiJdLCJ0eXBlIjoiSnNvbldlYktleTIwMjAifV0sInNlcnZpY2VzIjpbXX19XSwidXBkYXRlQ29tbWl0bWVudCI6IkVpRFZyOHUzVWxvOGtNVUx3WEh6VUdSMFdGdy1ROU14el8zRGQyQXEwVF9KR3cifSwic3VmZml4RGF0YSI6eyJkZWx0YUhhc2giOiJFaUJOX1JaeXZka1lmb2tkRlV5MTNiWnFwR2gzdmhZU3IxVnh3MmVieE5uQzZRIiwicmVjb3ZlcnlDb21taXRtZW50IjoiRWlEOEQtdjlsVjdqTzZ3ajVjSXVsRXRwZEFqaHE5NEFnTm54SlozWThVUnlrZyJ9fQ', + document : { + '@context': [ + 'https://www.w3.org/ns/did/v1', + { + '@base': 'did:ion:EiAO3IAedMSHaGOZIuIVwLEBHd0SEuWwt2h00dbiGD7Hww:eyJkZWx0YSI6eyJwYXRjaGVzIjpbeyJhY3Rpb24iOiJyZXBsYWNlIiwiZG9jdW1lbnQiOnsicHVibGljS2V5cyI6W3siaWQiOiJkd24tc2lnIiwicHVibGljS2V5SndrIjp7ImNydiI6IkVkMjU1MTkiLCJrdHkiOiJPS1AiLCJ4IjoicnBLbkRQOEY0X2p3dlE3eERra3VLeDE2NU9Td2N5clF2bUVXbDJlaWdJVSJ9LCJwdXJwb3NlcyI6WyJhdXRoZW50aWNhdGlvbiJdLCJ0eXBlIjoiSnNvbldlYktleTIwMjAifV0sInNlcnZpY2VzIjpbXX19XSwidXBkYXRlQ29tbWl0bWVudCI6IkVpRFZyOHUzVWxvOGtNVUx3WEh6VUdSMFdGdy1ROU14el8zRGQyQXEwVF9KR3cifSwic3VmZml4RGF0YSI6eyJkZWx0YUhhc2giOiJFaUJOX1JaeXZka1lmb2tkRlV5MTNiWnFwR2gzdmhZU3IxVnh3MmVieE5uQzZRIiwicmVjb3ZlcnlDb21taXRtZW50IjoiRWlEOEQtdjlsVjdqTzZ3ajVjSXVsRXRwZEFqaHE5NEFnTm54SlozWThVUnlrZyJ9fQ' + }, + ], + id : 'did:ion:EiAO3IAedMSHaGOZIuIVwLEBHd0SEuWwt2h00dbiGD7Hww:eyJkZWx0YSI6eyJwYXRjaGVzIjpbeyJhY3Rpb24iOiJyZXBsYWNlIiwiZG9jdW1lbnQiOnsicHVibGljS2V5cyI6W3siaWQiOiJkd24tc2lnIiwicHVibGljS2V5SndrIjp7ImNydiI6IkVkMjU1MTkiLCJrdHkiOiJPS1AiLCJ4IjoicnBLbkRQOEY0X2p3dlE3eERra3VLeDE2NU9Td2N5clF2bUVXbDJlaWdJVSJ9LCJwdXJwb3NlcyI6WyJhdXRoZW50aWNhdGlvbiJdLCJ0eXBlIjoiSnNvbldlYktleTIwMjAifV0sInNlcnZpY2VzIjpbXX19XSwidXBkYXRlQ29tbWl0bWVudCI6IkVpRFZyOHUzVWxvOGtNVUx3WEh6VUdSMFdGdy1ROU14el8zRGQyQXEwVF9KR3cifSwic3VmZml4RGF0YSI6eyJkZWx0YUhhc2giOiJFaUJOX1JaeXZka1lmb2tkRlV5MTNiWnFwR2gzdmhZU3IxVnh3MmVieE5uQzZRIiwicmVjb3ZlcnlDb21taXRtZW50IjoiRWlEOEQtdjlsVjdqTzZ3ajVjSXVsRXRwZEFqaHE5NEFnTm54SlozWThVUnlrZyJ9fQ', + 'verificationMethod' : [ + { + id : '#dwn-sig', + type : 'JsonWebKey2020', + controller : 'did:ion:EiAO3IAedMSHaGOZIuIVwLEBHd0SEuWwt2h00dbiGD7Hww:eyJkZWx0YSI6eyJwYXRjaGVzIjpbeyJhY3Rpb24iOiJyZXBsYWNlIiwiZG9jdW1lbnQiOnsicHVibGljS2V5cyI6W3siaWQiOiJkd24tc2lnIiwicHVibGljS2V5SndrIjp7ImNydiI6IkVkMjU1MTkiLCJrdHkiOiJPS1AiLCJ4IjoicnBLbkRQOEY0X2p3dlE3eERra3VLeDE2NU9Td2N5clF2bUVXbDJlaWdJVSJ9LCJwdXJwb3NlcyI6WyJhdXRoZW50aWNhdGlvbiJdLCJ0eXBlIjoiSnNvbldlYktleTIwMjAifV0sInNlcnZpY2VzIjpbXX19XSwidXBkYXRlQ29tbWl0bWVudCI6IkVpRFZyOHUzVWxvOGtNVUx3WEh6VUdSMFdGdy1ROU14el8zRGQyQXEwVF9KR3cifSwic3VmZml4RGF0YSI6eyJkZWx0YUhhc2giOiJFaUJOX1JaeXZka1lmb2tkRlV5MTNiWnFwR2gzdmhZU3IxVnh3MmVieE5uQzZRIiwicmVjb3ZlcnlDb21taXRtZW50IjoiRWlEOEQtdjlsVjdqTzZ3ajVjSXVsRXRwZEFqaHE5NEFnTm54SlozWThVUnlrZyJ9fQ', + publicKeyJwk : { + crv : 'Ed25519', + kty : 'OKP', + x : 'rpKnDP8F4_jwvQ7xDkkuKx165OSwcyrQvmEWl2eigIU' + } + } + ], + authentication: [ + '#dwn-sig' + ], + service: [] + }, + keySet: { + recoveryKey: { + privateKeyJwk: { + alg : 'ES256K', + crv : 'secp256k1', + d : 'cy4EzFT9K0sdCcz0gnctkcPq0szOP-d8smA9Hvp5ejo', + ext : 'true', + key_ops : ['sign'], + kid : 'ion-recovery-1', + kty : 'EC', + x : 'vLvKcPjYVnJi6dZpq15PrJqdxBERuvL8EqvTh1_0ikg', + y : 'AsQstiUIt5tGyAyM7LzytsbdVbsb-5oWVNYIUEjOePs' + }, + publicKeyJwk: { + alg : 'ES256K', + crv : 'secp256k1', + ext : 'true', + key_ops : ['verify'], + kid : 'ion-recovery-1', + kty : 'EC', + x : 'vLvKcPjYVnJi6dZpq15PrJqdxBERuvL8EqvTh1_0ikg', + y : 'AsQstiUIt5tGyAyM7LzytsbdVbsb-5oWVNYIUEjOePs' + }, + }, + updateKey: { + privateKeyJwk: { + alg : 'ES256K', + crv : 'secp256k1', + d : 'j4VcN2I5uw5kwPC5e8rxDaA7OxkmrJ-2BgdyKwayO9E', + ext : 'true', + key_ops : ['sign'], + kid : 'ion-update-1', + kty : 'EC', + x : '4Z9Tt1tuFlI3YwJfT3eS72r0sa9UxdtalgW14gep2DQ', + y : 'FIAtUW8B54L0Y-0e9n_rc1GJhxMIkZ3iYGnMQufgT_s' + }, + publicKeyJwk: { + alg : 'ES256K', + crv : 'secp256k1', + ext : 'true', + key_ops : ['verify'], + kid : 'ion-update-1', + kty : 'EC', + x : '4Z9Tt1tuFlI3YwJfT3eS72r0sa9UxdtalgW14gep2DQ', + y : 'FIAtUW8B54L0Y-0e9n_rc1GJhxMIkZ3iYGnMQufgT_s' + } + }, + verificationMethodKeys: [{ + publicKeyJwk: { + alg : 'EdDSA', + crv : 'Ed25519', + kid : 'dwn-sig', + kty : 'OKP', + x : 'rpKnDP8F4_jwvQ7xDkkuKx165OSwcyrQvmEWl2eigIU' + }, + relationships: ['authentication'] + }], + }, + } + }, + { + id : 'did.create.2', + input : { + keySet: { + recoveryKey: { + privateKeyJwk: { + alg : 'ES256K', + crv : 'secp256k1', + d : 'cy4EzFT9K0sdCcz0gnctkcPq0szOP-d8smA9Hvp5ejo', + ext : 'true', + key_ops : ['sign'], + kty : 'EC', + x : 'vLvKcPjYVnJi6dZpq15PrJqdxBERuvL8EqvTh1_0ikg', + y : 'AsQstiUIt5tGyAyM7LzytsbdVbsb-5oWVNYIUEjOePs' + }, + publicKeyJwk: { + alg : 'ES256K', + crv : 'secp256k1', + ext : 'true', + key_ops : ['verify'], + kty : 'EC', + x : 'vLvKcPjYVnJi6dZpq15PrJqdxBERuvL8EqvTh1_0ikg', + y : 'AsQstiUIt5tGyAyM7LzytsbdVbsb-5oWVNYIUEjOePs' + }, + }, + updateKey: { + privateKeyJwk: { + alg : 'ES256K', + crv : 'secp256k1', + d : 'j4VcN2I5uw5kwPC5e8rxDaA7OxkmrJ-2BgdyKwayO9E', + ext : 'true', + key_ops : ['sign'], + kty : 'EC', + x : '4Z9Tt1tuFlI3YwJfT3eS72r0sa9UxdtalgW14gep2DQ', + y : 'FIAtUW8B54L0Y-0e9n_rc1GJhxMIkZ3iYGnMQufgT_s' + }, + publicKeyJwk: { + alg : 'ES256K', + crv : 'secp256k1', + ext : 'true', + key_ops : ['verify'], + kty : 'EC', + x : '4Z9Tt1tuFlI3YwJfT3eS72r0sa9UxdtalgW14gep2DQ', + y : 'FIAtUW8B54L0Y-0e9n_rc1GJhxMIkZ3iYGnMQufgT_s' + } + }, + verificationMethodKeys: [{ + publicKeyJwk: { + alg : 'EdDSA', + crv : 'Ed25519', + kty : 'OKP', + x : 'rpKnDP8F4_jwvQ7xDkkuKx165OSwcyrQvmEWl2eigIU' + }, + relationships: ['authentication'] + }], + }, + keyAlgorithm: 'Ed25519' + }, + output: { + canonicalId : 'did:ion:EiBP6JaGhwYye4zz-wdeXR2JWl1JclaVDPA7FDgpzM8-ig', + did : 'did:ion:EiBP6JaGhwYye4zz-wdeXR2JWl1JclaVDPA7FDgpzM8-ig:eyJkZWx0YSI6eyJwYXRjaGVzIjpbeyJhY3Rpb24iOiJyZXBsYWNlIiwiZG9jdW1lbnQiOnsicHVibGljS2V5cyI6W3siaWQiOiJPQVBqN09ickVKRmdWTkEycnJrUE01QS12WVZzSF9seXo0TGdPVWRKQmE4IiwicHVibGljS2V5SndrIjp7ImNydiI6IkVkMjU1MTkiLCJrdHkiOiJPS1AiLCJ4IjoicnBLbkRQOEY0X2p3dlE3eERra3VLeDE2NU9Td2N5clF2bUVXbDJlaWdJVSJ9LCJwdXJwb3NlcyI6WyJhdXRoZW50aWNhdGlvbiJdLCJ0eXBlIjoiSnNvbldlYktleTIwMjAifV0sInNlcnZpY2VzIjpbXX19XSwidXBkYXRlQ29tbWl0bWVudCI6IkVpRFZyOHUzVWxvOGtNVUx3WEh6VUdSMFdGdy1ROU14el8zRGQyQXEwVF9KR3cifSwic3VmZml4RGF0YSI6eyJkZWx0YUhhc2giOiJFaUNUMEh4ZGNTRHkwQ0t5eHV4VkZ3d3A3N3YteEJkSkVRLUVtSXhZUGR4VnV3IiwicmVjb3ZlcnlDb21taXRtZW50IjoiRWlEOEQtdjlsVjdqTzZ3ajVjSXVsRXRwZEFqaHE5NEFnTm54SlozWThVUnlrZyJ9fQ', + document : { + '@context': [ + 'https://www.w3.org/ns/did/v1', + { + '@base': 'did:ion:EiBP6JaGhwYye4zz-wdeXR2JWl1JclaVDPA7FDgpzM8-ig:eyJkZWx0YSI6eyJwYXRjaGVzIjpbeyJhY3Rpb24iOiJyZXBsYWNlIiwiZG9jdW1lbnQiOnsicHVibGljS2V5cyI6W3siaWQiOiJPQVBqN09ickVKRmdWTkEycnJrUE01QS12WVZzSF9seXo0TGdPVWRKQmE4IiwicHVibGljS2V5SndrIjp7ImNydiI6IkVkMjU1MTkiLCJrdHkiOiJPS1AiLCJ4IjoicnBLbkRQOEY0X2p3dlE3eERra3VLeDE2NU9Td2N5clF2bUVXbDJlaWdJVSJ9LCJwdXJwb3NlcyI6WyJhdXRoZW50aWNhdGlvbiJdLCJ0eXBlIjoiSnNvbldlYktleTIwMjAifV0sInNlcnZpY2VzIjpbXX19XSwidXBkYXRlQ29tbWl0bWVudCI6IkVpRFZyOHUzVWxvOGtNVUx3WEh6VUdSMFdGdy1ROU14el8zRGQyQXEwVF9KR3cifSwic3VmZml4RGF0YSI6eyJkZWx0YUhhc2giOiJFaUNUMEh4ZGNTRHkwQ0t5eHV4VkZ3d3A3N3YteEJkSkVRLUVtSXhZUGR4VnV3IiwicmVjb3ZlcnlDb21taXRtZW50IjoiRWlEOEQtdjlsVjdqTzZ3ajVjSXVsRXRwZEFqaHE5NEFnTm54SlozWThVUnlrZyJ9fQ' + }, + ], + id : 'did:ion:EiBP6JaGhwYye4zz-wdeXR2JWl1JclaVDPA7FDgpzM8-ig:eyJkZWx0YSI6eyJwYXRjaGVzIjpbeyJhY3Rpb24iOiJyZXBsYWNlIiwiZG9jdW1lbnQiOnsicHVibGljS2V5cyI6W3siaWQiOiJPQVBqN09ickVKRmdWTkEycnJrUE01QS12WVZzSF9seXo0TGdPVWRKQmE4IiwicHVibGljS2V5SndrIjp7ImNydiI6IkVkMjU1MTkiLCJrdHkiOiJPS1AiLCJ4IjoicnBLbkRQOEY0X2p3dlE3eERra3VLeDE2NU9Td2N5clF2bUVXbDJlaWdJVSJ9LCJwdXJwb3NlcyI6WyJhdXRoZW50aWNhdGlvbiJdLCJ0eXBlIjoiSnNvbldlYktleTIwMjAifV0sInNlcnZpY2VzIjpbXX19XSwidXBkYXRlQ29tbWl0bWVudCI6IkVpRFZyOHUzVWxvOGtNVUx3WEh6VUdSMFdGdy1ROU14el8zRGQyQXEwVF9KR3cifSwic3VmZml4RGF0YSI6eyJkZWx0YUhhc2giOiJFaUNUMEh4ZGNTRHkwQ0t5eHV4VkZ3d3A3N3YteEJkSkVRLUVtSXhZUGR4VnV3IiwicmVjb3ZlcnlDb21taXRtZW50IjoiRWlEOEQtdjlsVjdqTzZ3ajVjSXVsRXRwZEFqaHE5NEFnTm54SlozWThVUnlrZyJ9fQ', + 'verificationMethod' : [ + { + id : '#OAPj7ObrEJFgVNA2rrkPM5A-vYVsH_lyz4LgOUdJBa8', + type : 'JsonWebKey2020', + controller : 'did:ion:EiBP6JaGhwYye4zz-wdeXR2JWl1JclaVDPA7FDgpzM8-ig:eyJkZWx0YSI6eyJwYXRjaGVzIjpbeyJhY3Rpb24iOiJyZXBsYWNlIiwiZG9jdW1lbnQiOnsicHVibGljS2V5cyI6W3siaWQiOiJPQVBqN09ickVKRmdWTkEycnJrUE01QS12WVZzSF9seXo0TGdPVWRKQmE4IiwicHVibGljS2V5SndrIjp7ImNydiI6IkVkMjU1MTkiLCJrdHkiOiJPS1AiLCJ4IjoicnBLbkRQOEY0X2p3dlE3eERra3VLeDE2NU9Td2N5clF2bUVXbDJlaWdJVSJ9LCJwdXJwb3NlcyI6WyJhdXRoZW50aWNhdGlvbiJdLCJ0eXBlIjoiSnNvbldlYktleTIwMjAifV0sInNlcnZpY2VzIjpbXX19XSwidXBkYXRlQ29tbWl0bWVudCI6IkVpRFZyOHUzVWxvOGtNVUx3WEh6VUdSMFdGdy1ROU14el8zRGQyQXEwVF9KR3cifSwic3VmZml4RGF0YSI6eyJkZWx0YUhhc2giOiJFaUNUMEh4ZGNTRHkwQ0t5eHV4VkZ3d3A3N3YteEJkSkVRLUVtSXhZUGR4VnV3IiwicmVjb3ZlcnlDb21taXRtZW50IjoiRWlEOEQtdjlsVjdqTzZ3ajVjSXVsRXRwZEFqaHE5NEFnTm54SlozWThVUnlrZyJ9fQ', + publicKeyJwk : { + crv : 'Ed25519', + kty : 'OKP', + x : 'rpKnDP8F4_jwvQ7xDkkuKx165OSwcyrQvmEWl2eigIU' + } + } + ], + authentication: [ + '#OAPj7ObrEJFgVNA2rrkPM5A-vYVsH_lyz4LgOUdJBa8' + ], + service: [] + }, + keySet: { + recoveryKey: { + privateKeyJwk: { + alg : 'ES256K', + crv : 'secp256k1', + d : 'cy4EzFT9K0sdCcz0gnctkcPq0szOP-d8smA9Hvp5ejo', + ext : 'true', + key_ops : ['sign'], + kid : 'AEOG_sxXHhCA1Fel8fpheyLxAcW89D7V86lMcJXc500', + kty : 'EC', + x : 'vLvKcPjYVnJi6dZpq15PrJqdxBERuvL8EqvTh1_0ikg', + y : 'AsQstiUIt5tGyAyM7LzytsbdVbsb-5oWVNYIUEjOePs' + }, + publicKeyJwk: { + alg : 'ES256K', + crv : 'secp256k1', + ext : 'true', + key_ops : ['verify'], + kid : 'AEOG_sxXHhCA1Fel8fpheyLxAcW89D7V86lMcJXc500', + kty : 'EC', + x : 'vLvKcPjYVnJi6dZpq15PrJqdxBERuvL8EqvTh1_0ikg', + y : 'AsQstiUIt5tGyAyM7LzytsbdVbsb-5oWVNYIUEjOePs' + }, + }, + updateKey: { + privateKeyJwk: { + alg : 'ES256K', + crv : 'secp256k1', + d : 'j4VcN2I5uw5kwPC5e8rxDaA7OxkmrJ-2BgdyKwayO9E', + ext : 'true', + key_ops : ['sign'], + kid : '_1CySHVtk6tNXke3t_7NLI2nvaVlH5GFyuO9HjQCRKs', + kty : 'EC', + x : '4Z9Tt1tuFlI3YwJfT3eS72r0sa9UxdtalgW14gep2DQ', + y : 'FIAtUW8B54L0Y-0e9n_rc1GJhxMIkZ3iYGnMQufgT_s' + }, + publicKeyJwk: { + alg : 'ES256K', + crv : 'secp256k1', + ext : 'true', + key_ops : ['verify'], + kid : '_1CySHVtk6tNXke3t_7NLI2nvaVlH5GFyuO9HjQCRKs', + kty : 'EC', + x : '4Z9Tt1tuFlI3YwJfT3eS72r0sa9UxdtalgW14gep2DQ', + y : 'FIAtUW8B54L0Y-0e9n_rc1GJhxMIkZ3iYGnMQufgT_s' + } + }, + verificationMethodKeys: [{ + publicKeyJwk: { + alg : 'EdDSA', + crv : 'Ed25519', + kid : 'OAPj7ObrEJFgVNA2rrkPM5A-vYVsH_lyz4LgOUdJBa8', + kty : 'OKP', + x : 'rpKnDP8F4_jwvQ7xDkkuKx165OSwcyrQvmEWl2eigIU' + }, + relationships: ['authentication'] + }], + }, + } + }, + { + id : 'did.create.3', + input : { + keySet: { + recoveryKey: { + privateKeyJwk: { + alg : 'ES256K', + crv : 'secp256k1', + d : 'cy4EzFT9K0sdCcz0gnctkcPq0szOP-d8smA9Hvp5ejo', + ext : 'true', + key_ops : ['sign'], + kty : 'EC', + x : 'vLvKcPjYVnJi6dZpq15PrJqdxBERuvL8EqvTh1_0ikg', + y : 'AsQstiUIt5tGyAyM7LzytsbdVbsb-5oWVNYIUEjOePs' + }, + publicKeyJwk: { + alg : 'ES256K', + crv : 'secp256k1', + ext : 'true', + key_ops : ['verify'], + kty : 'EC', + x : 'vLvKcPjYVnJi6dZpq15PrJqdxBERuvL8EqvTh1_0ikg', + y : 'AsQstiUIt5tGyAyM7LzytsbdVbsb-5oWVNYIUEjOePs' + }, + }, + updateKey: { + privateKeyJwk: { + alg : 'ES256K', + crv : 'secp256k1', + d : 'j4VcN2I5uw5kwPC5e8rxDaA7OxkmrJ-2BgdyKwayO9E', + ext : 'true', + key_ops : ['sign'], + kty : 'EC', + x : '4Z9Tt1tuFlI3YwJfT3eS72r0sa9UxdtalgW14gep2DQ', + y : 'FIAtUW8B54L0Y-0e9n_rc1GJhxMIkZ3iYGnMQufgT_s' + }, + publicKeyJwk: { + alg : 'ES256K', + crv : 'secp256k1', + ext : 'true', + key_ops : ['verify'], + kty : 'EC', + x : '4Z9Tt1tuFlI3YwJfT3eS72r0sa9UxdtalgW14gep2DQ', + y : 'FIAtUW8B54L0Y-0e9n_rc1GJhxMIkZ3iYGnMQufgT_s' + } + }, + verificationMethodKeys: [{ + publicKeyJwk: { + alg : 'ES256K', + crv : 'secp256k1', + kty : 'EC', + x : 'gdpQnpSlWSJXQEJJjVnNEi6-5H1L-jwNCDchM_JHDZQ', + y : 'SnEwisOamyUA7HYh8NKwYwgAR6_0CvHXWG26tXJa4RU' + }, + relationships: ['authentication'] + }], + }, + keyAlgorithm: 'secp256k1' + }, + output: { + canonicalId : 'did:ion:EiAeqx3f9VMGhk35znqsCEZuELryh8mXUyhnou1Zf6YpDw', + did : 'did:ion:EiAeqx3f9VMGhk35znqsCEZuELryh8mXUyhnou1Zf6YpDw:eyJkZWx0YSI6eyJwYXRjaGVzIjpbeyJhY3Rpb24iOiJyZXBsYWNlIiwiZG9jdW1lbnQiOnsicHVibGljS2V5cyI6W3siaWQiOiJLNkJwQW9xSU1La2d1Z2xGV0hNT01Xam5VM1BzeUhfQzBSZVJzUDZqRW0wIiwicHVibGljS2V5SndrIjp7ImNydiI6InNlY3AyNTZrMSIsImt0eSI6IkVDIiwieCI6ImdkcFFucFNsV1NKWFFFSkpqVm5ORWk2LTVIMUwtandOQ0RjaE1fSkhEWlEiLCJ5IjoiU25Fd2lzT2FteVVBN0hZaDhOS3dZd2dBUjZfMEN2SFhXRzI2dFhKYTRSVSJ9LCJwdXJwb3NlcyI6WyJhdXRoZW50aWNhdGlvbiJdLCJ0eXBlIjoiSnNvbldlYktleTIwMjAifV0sInNlcnZpY2VzIjpbXX19XSwidXBkYXRlQ29tbWl0bWVudCI6IkVpRFZyOHUzVWxvOGtNVUx3WEh6VUdSMFdGdy1ROU14el8zRGQyQXEwVF9KR3cifSwic3VmZml4RGF0YSI6eyJkZWx0YUhhc2giOiJFaUI0SzdZNHJtVEZTUjFWVUVlOEE1blQ0UnRpa1B6R3NTYjluOWl0SzJQWlhnIiwicmVjb3ZlcnlDb21taXRtZW50IjoiRWlEOEQtdjlsVjdqTzZ3ajVjSXVsRXRwZEFqaHE5NEFnTm54SlozWThVUnlrZyJ9fQ', + document : { + '@context': [ + 'https://www.w3.org/ns/did/v1', + { + '@base': 'did:ion:EiAeqx3f9VMGhk35znqsCEZuELryh8mXUyhnou1Zf6YpDw:eyJkZWx0YSI6eyJwYXRjaGVzIjpbeyJhY3Rpb24iOiJyZXBsYWNlIiwiZG9jdW1lbnQiOnsicHVibGljS2V5cyI6W3siaWQiOiJLNkJwQW9xSU1La2d1Z2xGV0hNT01Xam5VM1BzeUhfQzBSZVJzUDZqRW0wIiwicHVibGljS2V5SndrIjp7ImNydiI6InNlY3AyNTZrMSIsImt0eSI6IkVDIiwieCI6ImdkcFFucFNsV1NKWFFFSkpqVm5ORWk2LTVIMUwtandOQ0RjaE1fSkhEWlEiLCJ5IjoiU25Fd2lzT2FteVVBN0hZaDhOS3dZd2dBUjZfMEN2SFhXRzI2dFhKYTRSVSJ9LCJwdXJwb3NlcyI6WyJhdXRoZW50aWNhdGlvbiJdLCJ0eXBlIjoiSnNvbldlYktleTIwMjAifV0sInNlcnZpY2VzIjpbXX19XSwidXBkYXRlQ29tbWl0bWVudCI6IkVpRFZyOHUzVWxvOGtNVUx3WEh6VUdSMFdGdy1ROU14el8zRGQyQXEwVF9KR3cifSwic3VmZml4RGF0YSI6eyJkZWx0YUhhc2giOiJFaUI0SzdZNHJtVEZTUjFWVUVlOEE1blQ0UnRpa1B6R3NTYjluOWl0SzJQWlhnIiwicmVjb3ZlcnlDb21taXRtZW50IjoiRWlEOEQtdjlsVjdqTzZ3ajVjSXVsRXRwZEFqaHE5NEFnTm54SlozWThVUnlrZyJ9fQ' + }, + ], + id : 'did:ion:EiAeqx3f9VMGhk35znqsCEZuELryh8mXUyhnou1Zf6YpDw:eyJkZWx0YSI6eyJwYXRjaGVzIjpbeyJhY3Rpb24iOiJyZXBsYWNlIiwiZG9jdW1lbnQiOnsicHVibGljS2V5cyI6W3siaWQiOiJLNkJwQW9xSU1La2d1Z2xGV0hNT01Xam5VM1BzeUhfQzBSZVJzUDZqRW0wIiwicHVibGljS2V5SndrIjp7ImNydiI6InNlY3AyNTZrMSIsImt0eSI6IkVDIiwieCI6ImdkcFFucFNsV1NKWFFFSkpqVm5ORWk2LTVIMUwtandOQ0RjaE1fSkhEWlEiLCJ5IjoiU25Fd2lzT2FteVVBN0hZaDhOS3dZd2dBUjZfMEN2SFhXRzI2dFhKYTRSVSJ9LCJwdXJwb3NlcyI6WyJhdXRoZW50aWNhdGlvbiJdLCJ0eXBlIjoiSnNvbldlYktleTIwMjAifV0sInNlcnZpY2VzIjpbXX19XSwidXBkYXRlQ29tbWl0bWVudCI6IkVpRFZyOHUzVWxvOGtNVUx3WEh6VUdSMFdGdy1ROU14el8zRGQyQXEwVF9KR3cifSwic3VmZml4RGF0YSI6eyJkZWx0YUhhc2giOiJFaUI0SzdZNHJtVEZTUjFWVUVlOEE1blQ0UnRpa1B6R3NTYjluOWl0SzJQWlhnIiwicmVjb3ZlcnlDb21taXRtZW50IjoiRWlEOEQtdjlsVjdqTzZ3ajVjSXVsRXRwZEFqaHE5NEFnTm54SlozWThVUnlrZyJ9fQ', + 'verificationMethod' : [ + { + id : '#K6BpAoqIMKkguglFWHMOMWjnU3PsyH_C0ReRsP6jEm0', + type : 'JsonWebKey2020', + controller : 'did:ion:EiAeqx3f9VMGhk35znqsCEZuELryh8mXUyhnou1Zf6YpDw:eyJkZWx0YSI6eyJwYXRjaGVzIjpbeyJhY3Rpb24iOiJyZXBsYWNlIiwiZG9jdW1lbnQiOnsicHVibGljS2V5cyI6W3siaWQiOiJLNkJwQW9xSU1La2d1Z2xGV0hNT01Xam5VM1BzeUhfQzBSZVJzUDZqRW0wIiwicHVibGljS2V5SndrIjp7ImNydiI6InNlY3AyNTZrMSIsImt0eSI6IkVDIiwieCI6ImdkcFFucFNsV1NKWFFFSkpqVm5ORWk2LTVIMUwtandOQ0RjaE1fSkhEWlEiLCJ5IjoiU25Fd2lzT2FteVVBN0hZaDhOS3dZd2dBUjZfMEN2SFhXRzI2dFhKYTRSVSJ9LCJwdXJwb3NlcyI6WyJhdXRoZW50aWNhdGlvbiJdLCJ0eXBlIjoiSnNvbldlYktleTIwMjAifV0sInNlcnZpY2VzIjpbXX19XSwidXBkYXRlQ29tbWl0bWVudCI6IkVpRFZyOHUzVWxvOGtNVUx3WEh6VUdSMFdGdy1ROU14el8zRGQyQXEwVF9KR3cifSwic3VmZml4RGF0YSI6eyJkZWx0YUhhc2giOiJFaUI0SzdZNHJtVEZTUjFWVUVlOEE1blQ0UnRpa1B6R3NTYjluOWl0SzJQWlhnIiwicmVjb3ZlcnlDb21taXRtZW50IjoiRWlEOEQtdjlsVjdqTzZ3ajVjSXVsRXRwZEFqaHE5NEFnTm54SlozWThVUnlrZyJ9fQ', + publicKeyJwk : { + crv : 'secp256k1', + kty : 'EC', + x : 'gdpQnpSlWSJXQEJJjVnNEi6-5H1L-jwNCDchM_JHDZQ', + y : 'SnEwisOamyUA7HYh8NKwYwgAR6_0CvHXWG26tXJa4RU' + } + } + ], + authentication: [ + '#K6BpAoqIMKkguglFWHMOMWjnU3PsyH_C0ReRsP6jEm0' + ], + service: [] + }, + keySet: { + recoveryKey: { + privateKeyJwk: { + alg : 'ES256K', + crv : 'secp256k1', + d : 'cy4EzFT9K0sdCcz0gnctkcPq0szOP-d8smA9Hvp5ejo', + ext : 'true', + key_ops : ['sign'], + kid : 'AEOG_sxXHhCA1Fel8fpheyLxAcW89D7V86lMcJXc500', + kty : 'EC', + x : 'vLvKcPjYVnJi6dZpq15PrJqdxBERuvL8EqvTh1_0ikg', + y : 'AsQstiUIt5tGyAyM7LzytsbdVbsb-5oWVNYIUEjOePs' + }, + publicKeyJwk: { + alg : 'ES256K', + crv : 'secp256k1', + ext : 'true', + key_ops : ['verify'], + kid : 'AEOG_sxXHhCA1Fel8fpheyLxAcW89D7V86lMcJXc500', + kty : 'EC', + x : 'vLvKcPjYVnJi6dZpq15PrJqdxBERuvL8EqvTh1_0ikg', + y : 'AsQstiUIt5tGyAyM7LzytsbdVbsb-5oWVNYIUEjOePs' + }, + }, + updateKey: { + privateKeyJwk: { + alg : 'ES256K', + crv : 'secp256k1', + d : 'j4VcN2I5uw5kwPC5e8rxDaA7OxkmrJ-2BgdyKwayO9E', + ext : 'true', + key_ops : ['sign'], + kid : '_1CySHVtk6tNXke3t_7NLI2nvaVlH5GFyuO9HjQCRKs', + kty : 'EC', + x : '4Z9Tt1tuFlI3YwJfT3eS72r0sa9UxdtalgW14gep2DQ', + y : 'FIAtUW8B54L0Y-0e9n_rc1GJhxMIkZ3iYGnMQufgT_s' + }, + publicKeyJwk: { + alg : 'ES256K', + crv : 'secp256k1', + ext : 'true', + key_ops : ['verify'], + kid : '_1CySHVtk6tNXke3t_7NLI2nvaVlH5GFyuO9HjQCRKs', + kty : 'EC', + x : '4Z9Tt1tuFlI3YwJfT3eS72r0sa9UxdtalgW14gep2DQ', + y : 'FIAtUW8B54L0Y-0e9n_rc1GJhxMIkZ3iYGnMQufgT_s' + } + }, + verificationMethodKeys: [{ + publicKeyJwk: { + alg : 'ES256K', + crv : 'secp256k1', + kid : 'K6BpAoqIMKkguglFWHMOMWjnU3PsyH_C0ReRsP6jEm0', + kty : 'EC', + x : 'gdpQnpSlWSJXQEJJjVnNEi6-5H1L-jwNCDchM_JHDZQ', + y : 'SnEwisOamyUA7HYh8NKwYwgAR6_0CvHXWG26tXJa4RU' + }, + relationships: ['authentication'] + }], + }, + } + } +]; \ No newline at end of file diff --git a/packages/dids/tests/fixtures/test-vectors/did-key.ts b/packages/dids/tests/fixtures/test-vectors/did-key.ts new file mode 100644 index 000000000..580ac1162 --- /dev/null +++ b/packages/dids/tests/fixtures/test-vectors/did-key.ts @@ -0,0 +1,318 @@ +export const didKeyCreateDocumentTestVectors = [ + { + id : 'did.createDocument.1', + input : { + did : 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D', + publicKeyFormat : 'JsonWebKey2020' + }, + output: { + '@context': [ + 'https://www.w3.org/ns/did/v1', + 'https://w3id.org/security/suites/jws-2020/v1' + ], + 'id' : 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D', + 'verificationMethod' : [ + { + 'id' : 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D#z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D', + 'type' : 'JsonWebKey2020', + 'controller' : 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D', + 'publicKeyJwk' : { + 'alg' : 'EdDSA', + 'crv' : 'Ed25519', + 'kty' : 'OKP', + 'x' : 'ZuVpK6HnahBtV1Y_jhnYK-fqHAz3dXmWXT_h-J7SL6I' + } + } + ], + 'assertionMethod': [ + 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D#z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D' + ], + 'authentication': [ + 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D#z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D' + ], + 'capabilityDelegation': [ + 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D#z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D' + ], + 'capabilityInvocation': [ + 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D#z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D' + ] + } + }, + { + id : 'did.createDocument.2', + input : { + did : 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D', + publicKeyFormat : 'Ed25519VerificationKey2020' + }, + output: { + '@context': [ + 'https://www.w3.org/ns/did/v1', + 'https://w3id.org/security/suites/ed25519-2020/v1' + ], + 'id' : 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D', + 'verificationMethod' : [ + { + 'id' : 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D#z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D', + 'type' : 'Ed25519VerificationKey2020', + 'controller' : 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D', + 'publicKeyMultibase' : 'z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D' + } + ], + 'assertionMethod': [ + 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D#z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D' + ], + 'authentication': [ + 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D#z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D' + ], + 'capabilityDelegation': [ + 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D#z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D' + ], + 'capabilityInvocation': [ + 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D#z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D' + ] + } + }, + { + id : 'did.createDocument.3', + input : { + did : 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D', + enableEncryptionKeyDerivation : true, + publicKeyFormat : 'JsonWebKey2020' + }, + output: { + '@context': [ + 'https://www.w3.org/ns/did/v1', + 'https://w3id.org/security/suites/jws-2020/v1' + ], + 'id' : 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D', + 'verificationMethod' : [ + { + 'id' : 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D#z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D', + 'type' : 'JsonWebKey2020', + 'controller' : 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D', + 'publicKeyJwk' : { + 'alg' : 'EdDSA', + 'crv' : 'Ed25519', + 'kty' : 'OKP', + 'x' : 'ZuVpK6HnahBtV1Y_jhnYK-fqHAz3dXmWXT_h-J7SL6I' + } + }, + { + 'id' : 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D#z6LSdCnN59MPkRCaVvXczoipz5tMcPpjrCnvqBcHHjCDohYd', + 'type' : 'JsonWebKey2020', + 'controller' : 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D', + 'publicKeyJwk' : { + 'crv' : 'X25519', + 'kty' : 'OKP', + 'x' : 'FrLpNU0FVX4oAByhAbU71h4yb-WMr6penULFCzbMtxo', + }, + } + ], + 'assertionMethod': [ + 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D#z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D' + ], + 'authentication': [ + 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D#z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D' + ], + 'capabilityDelegation': [ + 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D#z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D' + ], + 'capabilityInvocation': [ + 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D#z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D' + ], + 'keyAgreement': [ + 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D#z6LSdCnN59MPkRCaVvXczoipz5tMcPpjrCnvqBcHHjCDohYd' + ] + } + }, + { + id : 'did.createDocument.4', + input : { + did : 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D', + enableEncryptionKeyDerivation : true, + publicKeyFormat : 'Ed25519VerificationKey2020' + }, + output: { + '@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:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D', + 'verificationMethod' : [ + { + 'id' : 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D#z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D', + 'type' : 'Ed25519VerificationKey2020', + 'controller' : 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D', + 'publicKeyMultibase' : 'z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D' + }, + { + 'id' : 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D#z6LSdCnN59MPkRCaVvXczoipz5tMcPpjrCnvqBcHHjCDohYd', + 'type' : 'X25519KeyAgreementKey2020', + 'controller' : 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D', + 'publicKeyMultibase' : 'z6LSdCnN59MPkRCaVvXczoipz5tMcPpjrCnvqBcHHjCDohYd' + } + ], + 'assertionMethod': [ + 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D#z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D' + ], + 'authentication': [ + 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D#z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D' + ], + 'capabilityDelegation': [ + 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D#z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D' + ], + 'capabilityInvocation': [ + 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D#z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D' + ], + 'keyAgreement': [ + 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D#z6LSdCnN59MPkRCaVvXczoipz5tMcPpjrCnvqBcHHjCDohYd' + ] + } + } +]; + +export const didKeyCreateTestVectors = [ + { + id : 'did.create.1', + input : { + keySet: { + verificationMethodKeys: [{ + 'publicKeyJwk': { + 'alg' : 'EdDSA', + 'crv' : 'Ed25519', + 'kty' : 'OKP', + 'x' : 'rpKnDP8F4_jwvQ7xDkkuKx165OSwcyrQvmEWl2eigIU' + }, + relationships: ['authentication'] + }], + }, + publicKeyAlgorithm : 'Ed25519', + publicKeyFormat : 'JsonWebKey2020' + }, + output: { + did : 'did:key:z6MkrCigh4zugDVEieqt4WbtWParigHeH5TEYEuKcSyCykUk', + document : { + '@context': [ + 'https://www.w3.org/ns/did/v1', + 'https://w3id.org/security/suites/jws-2020/v1' + ], + 'id' : 'did:key:z6MkrCigh4zugDVEieqt4WbtWParigHeH5TEYEuKcSyCykUk', + 'verificationMethod' : [ + { + 'id' : 'did:key:z6MkrCigh4zugDVEieqt4WbtWParigHeH5TEYEuKcSyCykUk#z6MkrCigh4zugDVEieqt4WbtWParigHeH5TEYEuKcSyCykUk', + 'type' : 'JsonWebKey2020', + 'controller' : 'did:key:z6MkrCigh4zugDVEieqt4WbtWParigHeH5TEYEuKcSyCykUk', + 'publicKeyJwk' : { + 'alg' : 'EdDSA', + 'crv' : 'Ed25519', + 'kty' : 'OKP', + 'x' : 'rpKnDP8F4_jwvQ7xDkkuKx165OSwcyrQvmEWl2eigIU' + } + } + ], + 'assertionMethod': [ + 'did:key:z6MkrCigh4zugDVEieqt4WbtWParigHeH5TEYEuKcSyCykUk#z6MkrCigh4zugDVEieqt4WbtWParigHeH5TEYEuKcSyCykUk' + ], + 'authentication': [ + 'did:key:z6MkrCigh4zugDVEieqt4WbtWParigHeH5TEYEuKcSyCykUk#z6MkrCigh4zugDVEieqt4WbtWParigHeH5TEYEuKcSyCykUk' + ], + 'capabilityDelegation': [ + 'did:key:z6MkrCigh4zugDVEieqt4WbtWParigHeH5TEYEuKcSyCykUk#z6MkrCigh4zugDVEieqt4WbtWParigHeH5TEYEuKcSyCykUk' + ], + 'capabilityInvocation': [ + 'did:key:z6MkrCigh4zugDVEieqt4WbtWParigHeH5TEYEuKcSyCykUk#z6MkrCigh4zugDVEieqt4WbtWParigHeH5TEYEuKcSyCykUk' + ], + }, + keySet: { + verificationMethodKeys: [{ + 'publicKeyJwk': { + 'alg' : 'EdDSA', + 'crv' : 'Ed25519', + 'kty' : 'OKP', + 'x' : 'rpKnDP8F4_jwvQ7xDkkuKx165OSwcyrQvmEWl2eigIU' + }, + relationships: ['authentication'] + }], + }, + } + }, + { + id : 'did.create.2', + input : { + enableEncryptionKeyDerivation : true, + keySet : { + verificationMethodKeys: [{ + publicKeyJwk: { + alg : 'EdDSA', + crv : 'Ed25519', + kty : 'OKP', + x : 'rpKnDP8F4_jwvQ7xDkkuKx165OSwcyrQvmEWl2eigIU' + }, + relationships: ['authentication'] + }], + }, + publicKeyAlgorithm : 'Ed25519', + publicKeyFormat : 'JsonWebKey2020' + }, + output: { + did : 'did:key:z6MkrCigh4zugDVEieqt4WbtWParigHeH5TEYEuKcSyCykUk', + document : { + '@context': [ + 'https://www.w3.org/ns/did/v1', + 'https://w3id.org/security/suites/jws-2020/v1' + ], + 'id' : 'did:key:z6MkrCigh4zugDVEieqt4WbtWParigHeH5TEYEuKcSyCykUk', + 'verificationMethod' : [ + { + 'id' : 'did:key:z6MkrCigh4zugDVEieqt4WbtWParigHeH5TEYEuKcSyCykUk#z6MkrCigh4zugDVEieqt4WbtWParigHeH5TEYEuKcSyCykUk', + 'type' : 'JsonWebKey2020', + 'controller' : 'did:key:z6MkrCigh4zugDVEieqt4WbtWParigHeH5TEYEuKcSyCykUk', + 'publicKeyJwk' : { + 'alg' : 'EdDSA', + 'crv' : 'Ed25519', + 'kty' : 'OKP', + 'x' : 'rpKnDP8F4_jwvQ7xDkkuKx165OSwcyrQvmEWl2eigIU' + } + }, + { + 'controller' : 'did:key:z6MkrCigh4zugDVEieqt4WbtWParigHeH5TEYEuKcSyCykUk', + 'type' : 'JsonWebKey2020', + 'id' : 'did:key:z6MkrCigh4zugDVEieqt4WbtWParigHeH5TEYEuKcSyCykUk#z6LSjqybG4FgDYHxo4v9tWzgTpCm9a3b9K3QYqicCabqWeHQ', + 'publicKeyJwk' : { + 'crv' : 'X25519', + 'kty' : 'OKP', + 'x' : 'eWA3oUNKm3nZN0vqiC_tClPCkBznN5R0Y9NofJkoaXM' + } + } + ], + 'assertionMethod': [ + 'did:key:z6MkrCigh4zugDVEieqt4WbtWParigHeH5TEYEuKcSyCykUk#z6MkrCigh4zugDVEieqt4WbtWParigHeH5TEYEuKcSyCykUk' + ], + 'authentication': [ + 'did:key:z6MkrCigh4zugDVEieqt4WbtWParigHeH5TEYEuKcSyCykUk#z6MkrCigh4zugDVEieqt4WbtWParigHeH5TEYEuKcSyCykUk' + ], + 'capabilityDelegation': [ + 'did:key:z6MkrCigh4zugDVEieqt4WbtWParigHeH5TEYEuKcSyCykUk#z6MkrCigh4zugDVEieqt4WbtWParigHeH5TEYEuKcSyCykUk' + ], + 'capabilityInvocation': [ + 'did:key:z6MkrCigh4zugDVEieqt4WbtWParigHeH5TEYEuKcSyCykUk#z6MkrCigh4zugDVEieqt4WbtWParigHeH5TEYEuKcSyCykUk' + ], + 'keyAgreement': [ + 'did:key:z6MkrCigh4zugDVEieqt4WbtWParigHeH5TEYEuKcSyCykUk#z6LSjqybG4FgDYHxo4v9tWzgTpCm9a3b9K3QYqicCabqWeHQ' + ] + }, + keySet: { + verificationMethodKeys: [{ + publicKeyJwk: { + alg : 'EdDSA', + crv : 'Ed25519', + kty : 'OKP', + x : 'rpKnDP8F4_jwvQ7xDkkuKx165OSwcyrQvmEWl2eigIU' + }, + relationships: ['authentication'] + }], + }, + } + } +]; \ No newline at end of file diff --git a/packages/dids/tests/fixtures/test-vectors/did-resolver.ts b/packages/dids/tests/fixtures/test-vectors/did-resolver.ts new file mode 100644 index 000000000..e215406e9 --- /dev/null +++ b/packages/dids/tests/fixtures/test-vectors/did-resolver.ts @@ -0,0 +1,38 @@ +export const didResolverTestVectors = [ + { + id : 'did.resolve.1', + input : 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D', + output : { + '@context': [ + 'https://www.w3.org/ns/did/v1', + 'https://w3id.org/security/suites/jws-2020/v1' + ], + 'id' : 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D', + 'verificationMethod' : [ + { + 'id' : 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D#z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D', + 'type' : 'JsonWebKey2020', + 'controller' : 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D', + 'publicKeyJwk' : { + 'alg' : 'EdDSA', + 'crv' : 'Ed25519', + 'kty' : 'OKP', + 'x' : 'ZuVpK6HnahBtV1Y_jhnYK-fqHAz3dXmWXT_h-J7SL6I' + } + } + ], + 'assertionMethod': [ + 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D#z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D' + ], + 'authentication': [ + 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D#z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D' + ], + 'capabilityDelegation': [ + 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D#z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D' + ], + 'capabilityInvocation': [ + 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D#z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D' + ] + } + }, +]; \ No newline at end of file diff --git a/packages/dids/tests/fixtures/test-vectors/did-utils.ts b/packages/dids/tests/fixtures/test-vectors/did-utils.ts new file mode 100644 index 000000000..0aed2d3de --- /dev/null +++ b/packages/dids/tests/fixtures/test-vectors/did-utils.ts @@ -0,0 +1,253 @@ +const didDocumentForIdTestVectors = { + '@context': [ + 'https://www.w3.org/ns/did/v1', + 'https://w3id.org/security/suites/jws-2020/v1', + 'https://w3id.org/security/suites/ed25519-2020/v1', + ], + id : 'did:method:alice', + verificationMethod : [ + { + id : 'did:method:alice#key-1', + type : 'JsonWebKey2020', + controller : 'did:method:alice', + publicKeyJwk : { + alg : 'EdDSA', + kty : 'OKP', + crv : 'Ed25519', + x : 'GM_NcTChsLlfdODKG573OSWGO7wNwzhkHRPHPxdAYfc' + } + }, + { + id : 'did:method:alice#key-2', + type : 'Ed25519VerificationKey2020', + controller : 'did:method:alice', + publicKeyMultibase : 'z6LSdCnN59MPkRCaVvXczoipz5tMcPpjrCnvqBcHHjCDohYd' + }, + ], + 'authentication': [ + 'did:method:alice#key-1', + { + id : 'did:method:alice#key-3', + type : 'JsonWebKey2020', + controller : 'did:method:alice', + publicKeyJwk : { + alg : 'EdDSA', + kty : 'OKP', + crv : 'Ed25519', + x : 'k1GKchkMMp9nbYsShY1R2UVzPsQill6zv2De38ERkfI' + }, + }, + ], + 'keyAgreement': [ + { + id : 'did:method:alice#key-5', + type : 'JsonWebKey2020', + controller : 'did:method:alice', + publicKeyJwk : { + alg : 'EdDSA', + kty : 'OKP', + crv : 'X25519', + x : 'SOKzporeWqJMJxf1NgPtup3whiBLPLZxgLDORNzbXwA' + }, + }, + { + id : 'did:method:alice#key-6', + type : 'X25519KeyAgreementKey2020', + controller : 'did:method:alice', + publicKeyMultibase : 'z6LSgah1r8rDCT2brDg7Vhh2LYmTkcEVgUHng1Ji68XBy4d' + }, + ] +}; + +export const didDocumentIdTestVectors = [ + { + id : 'did.getIdByKey.1', + input : { + didDocument : didDocumentForIdTestVectors, + publicKeyJwk : { + kty : 'OKP', + crv : 'Ed25519', + x : 'GM_NcTChsLlfdODKG573OSWGO7wNwzhkHRPHPxdAYfc' + }, + }, + output: 'did:method:alice#key-1' + }, + { + id : 'did.getIdByKey.2', + input : { + didDocument : didDocumentForIdTestVectors, + publicKeyMultibase : 'z6LSdCnN59MPkRCaVvXczoipz5tMcPpjrCnvqBcHHjCDohYd', + }, + output: 'did:method:alice#key-2' + }, + { + id : 'did.getIdByKey.3', + input : { + didDocument : didDocumentForIdTestVectors, + publicKeyJwk : { + kty : 'OKP', + crv : 'Ed25519', + x : 'k1GKchkMMp9nbYsShY1R2UVzPsQill6zv2De38ERkfI' + }, + publicKeyMultibase: 'z6LSdCnN59MPkRCaVvXczoipz5tMcPpjrCnvqBcHHjCDohYd', + }, + output: 'did:method:alice#key-2' + }, + { + id : 'did.getIdByKey.4', + input : { + didDocument : didDocumentForIdTestVectors, + publicKeyJwk : { + kty : 'OKP', + crv : 'Ed25519', + x : 'k1GKchkMMp9nbYsShY1R2UVzPsQill6zv2De38ERkfI' + }, + }, + output: undefined + } +]; + +export const didDocumentTypeTestVectors = [ + { + id : 'did.getTypes.1', + input : { + 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:key:z6MkiTBz1ymuepAQ4HEHYSF1H8quG5GLVVQR3djdX3mDooWp', + 'verificationMethod' : [ + { + 'id' : 'did:key:z6MkiTBz1ymuepAQ4HEHYSF1H8quG5GLVVQR3djdX3mDooWp#z6MkiTBz1ymuepAQ4HEHYSF1H8quG5GLVVQR3djdX3mDooWp', + 'type' : 'Ed25519VerificationKey2020', + 'controller' : 'did:key:z6MkiTBz1ymuepAQ4HEHYSF1H8quG5GLVVQR3djdX3mDooWp', + 'publicKeyMultibase' : 'z6MkiTBz1ymuepAQ4HEHYSF1H8quG5GLVVQR3djdX3mDooWp' + }, + { + 'id' : 'did:key:z6MkiTBz1ymuepAQ4HEHYSF1H8quG5GLVVQR3djdX3mDooWp#z6LShs9GGnqk85isEBzzshkuVWrVKsRp24GnDuHk8QWkARMW', + 'type' : 'X25519KeyAgreementKey2020', + 'controller' : 'did:key:z6MkiTBz1ymuepAQ4HEHYSF1H8quG5GLVVQR3djdX3mDooWp', + 'publicKeyMultibase' : 'z6LShs9GGnqk85isEBzzshkuVWrVKsRp24GnDuHk8QWkARMW' + } + ], + 'authentication': [ + 'did:key:z6MkiTBz1ymuepAQ4HEHYSF1H8quG5GLVVQR3djdX3mDooWp#z6MkiTBz1ymuepAQ4HEHYSF1H8quG5GLVVQR3djdX3mDooWp', + { + 'id' : 'did:key:z6MkiTBz1ymuepAQ4HEHYSF1H8quG5GLVVQR3djdX3mDooWp#zH3C2AVvLMv6gmMNam3uVAjZpfkcJCwDwnZn6z3wXmqPV', + 'type' : 'Ed25519VerificationKey2020', + 'controller' : 'did:key:z6MkiTBz1ymuepAQ4HEHYSF1H8quG5GLVVQR3djdX3mDooWp', + 'publicKeyMultibase' : 'zH3C2AVvLMv6gmMNam3uVAjZpfkcJCwDwnZn6z3wXmqPV' + } + ], + 'assertionMethod': [ + 'did:key:z6MkiTBz1ymuepAQ4HEHYSF1H8quG5GLVVQR3djdX3mDooWp#z6MkiTBz1ymuepAQ4HEHYSF1H8quG5GLVVQR3djdX3mDooWp', + { + 'id' : 'did:key:z6MkiTBz1ymuepAQ4HEHYSF1H8quG5GLVVQR3djdX3mDooWp#z6MknGc3ocHs3zdPiJbnaaqDi58NGb4pk1Sp9WxWufuXSdxf', + 'type' : 'Ed25519VerificationKey2020', + 'controller' : 'did:key:z6MkiTBz1ymuepAQ4HEHYSF1H8quG5GLVVQR3djdX3mDooWp', + 'publicKeyMultibase' : 'z6MknGc3ocHs3zdPiJbnaaqDi58NGb4pk1Sp9WxWufuXSdxf' + } + ], + 'capabilityDelegation': [ + 'did:key:z6MkiTBz1ymuepAQ4HEHYSF1H8quG5GLVVQR3djdX3mDooWp#z6MkiTBz1ymuepAQ4HEHYSF1H8quG5GLVVQR3djdX3mDooWp' + ], + 'capabilityInvocation': [ + 'did:key:z6MkiTBz1ymuepAQ4HEHYSF1H8quG5GLVVQR3djdX3mDooWp#z6MkiTBz1ymuepAQ4HEHYSF1H8quG5GLVVQR3djdX3mDooWp' + ], + 'keyAgreement': [ + 'did:key:z6MkiTBz1ymuepAQ4HEHYSF1H8quG5GLVVQR3djdX3mDooWp#z6LShs9GGnqk85isEBzzshkuVWrVKsRp24GnDuHk8QWkARMW' + ] + }, + }, + output: ['Ed25519VerificationKey2020', 'X25519KeyAgreementKey2020'] + }, + + { + id : 'did.getTypes.2', + input : { + didDocument: { + '@context': [ + 'https://www.w3.org/ns/did/v1', + 'https://w3id.org/security/suites/jws-2020/v1' + ], + 'id' : 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D', + 'verificationMethod' : [ + { + 'id' : 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D#z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D', + 'type' : 'JsonWebKey2020', + 'controller' : 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D', + 'publicKeyJwk' : { + 'alg' : 'EdDSA', + 'crv' : 'Ed25519', + 'kty' : 'OKP', + 'x' : 'ZuVpK6HnahBtV1Y_jhnYK-fqHAz3dXmWXT_h-J7SL6I' + } + } + ], + 'assertionMethod': [ + 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D#z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D' + ], + 'authentication': [ + 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D#z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D' + ], + 'capabilityDelegation': [ + 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D#z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D' + ], + 'capabilityInvocation': [ + 'did:key:z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D#z6MkmNvXGmVuux5W63nXKEM8zoxFmDLNfe7siCKG2GM7Kd8D' + ] + }, + }, + output: ['JsonWebKey2020'] + }, + + // Source: https://w3c.github.io/did-core/#example-did-document-with-different-verification-method-types + { + id : 'did.type.w3c.32', + input : { + didDocument: { + '@context': [ + 'https://www.w3.org/ns/did/v1', + 'https://w3id.org/security/suites/ed25519-2018/v1', + 'https://w3id.org/security/suites/x25519-2019/v1', + 'https://w3id.org/security/suites/secp256k1-2019/v1', + 'https://w3id.org/security/suites/jws-2020/v1' + ], + 'verificationMethod': [ + { + 'id' : 'did:example:123#key-0', + 'type' : 'Ed25519VerificationKey2018', + 'controller' : 'did:example:123', + 'publicKeyBase58' : '3M5RCDjPTWPkKSN3sxUmmMqHbmRPegYP1tjcKyrDbt9J' // external (property name) + }, + { + 'id' : 'did:example:123#key-1', + 'type' : 'X25519KeyAgreementKey2019', + 'controller' : 'did:example:123', + 'publicKeyBase58' : 'FbQWLPRhTH95MCkQUeFYdiSoQt8zMwetqfWoxqPgaq7x' // external (property name) + }, + { + 'id' : 'did:example:123#key-2', + 'type' : 'EcdsaSecp256k1VerificationKey2019', + 'controller' : 'did:example:123', + 'publicKeyBase58' : 'ns2aFDq25fEV1NUd3wZ65sgj5QjFW8JCAHdUJfLwfodt' // external (property name) + }, + { + 'id' : 'did:example:123#key-3', + 'type' : 'JsonWebKey2020', + 'controller' : 'did:example:123', + 'publicKeyJwk' : { + 'kty' : 'EC', // external (property name) + 'crv' : 'P-256', // external (property name) + 'x' : 'Er6KSSnAjI70ObRWhlaMgqyIOQYrDJTE94ej5hybQ2M', // external (property name) + 'y' : 'pPVzCOTJwgikPjuUE6UebfZySqEJ0ZtsWFpj7YSPGEk' // external (property name) + } + } + ] + }, + }, + output: ['Ed25519VerificationKey2018', 'X25519KeyAgreementKey2019', 'EcdsaSecp256k1VerificationKey2019', 'JsonWebKey2020'] + } +]; \ No newline at end of file diff --git a/packages/dids/tests/resolver-cache-level.spec.ts b/packages/dids/tests/resolver-cache-level.spec.ts new file mode 100644 index 000000000..e038f37df --- /dev/null +++ b/packages/dids/tests/resolver-cache-level.spec.ts @@ -0,0 +1,166 @@ +import sinon from 'sinon'; +import chai, { expect } from 'chai'; +import chaiAsPromised from 'chai-as-promised'; + +import { DidResolverCacheLevel } from '../src/resolver-cache-level.js'; + +chai.use(chaiAsPromised); + +describe('DidResolverCacheLevel', () => { + let cache: DidResolverCacheLevel; + let cacheStoreLocation = '__TESTDATA__/DID_RESOLVERCACHE'; + let clock: sinon.SinonFakeTimers; + + before(() => { + clock = sinon.useFakeTimers(); + }); + + afterEach(async () => { + await cache.close(); + }); + + after(() => { + clock.restore(); + }); + + describe('constructor', () => { + it('uses default options if none are specified', async () => { + cache = new DidResolverCacheLevel(); + expect(cache).to.exist; + }); + + it('uses a 15 minute TTL, by default', async () => { + cache = new DidResolverCacheLevel({ location: cacheStoreLocation }); + + const testDid = 'did:example:alice'; + + const testDidResolutionResult = { + didResolutionMetadata : {}, + didDocument : { id: 'abc123' }, + didDocumentMetadata : {} + }; + + // Write an entry into the cache. + await cache.set(testDid, testDidResolutionResult); + + // Confirm a cache hit. + let valueInCache = await cache.get(testDid); + expect(valueInCache).to.deep.equal(testDidResolutionResult); + + // Time travel 16 minutes. + clock.tick(1000 * 60 * 16); + + // Confirm a cache miss. + valueInCache = await cache.get(testDid); + expect(valueInCache).to.be.undefined; + }); + + it('uses a custom TTL, when specified', async () => { + // Instantiate DID resolution cache with custom TTL of 60 seconds. + cache = new DidResolverCacheLevel({ ttl: '1m', location: cacheStoreLocation }); + + const testDid = 'did:example:alice'; + + const testDidResolutionResult = { + didResolutionMetadata : {}, + didDocument : { id: 'abc123' }, + didDocumentMetadata : {} + }; + + // Write an entry into the cache. + await cache.set(testDid, testDidResolutionResult); + + // Confirm a cache hit. + let valueInCache = await cache.get(testDid); + expect(valueInCache).to.deep.equal(testDidResolutionResult); + + // Time travel 61 seconds. + clock.tick(1000 * 61); + + // Confirm a cache miss. + valueInCache = await cache.get(testDid); + expect(valueInCache).to.be.undefined; + }); + }); + + describe('clear()', () => { + it('removes all entries from cache', async () => { + // Instantiate DID resolution cache with default TTL of 15 minutes. + cache = new DidResolverCacheLevel({ location: cacheStoreLocation }); + + const testDid1 = 'did:example:alice'; + const testDid2 = 'did:example:bob'; + + const testDidResolutionResult = { + didResolutionMetadata : {}, + didDocument : { id: 'abc123' }, + didDocumentMetadata : {} + }; + + await cache.set(testDid1, testDidResolutionResult); + await cache.set(testDid2, testDidResolutionResult); + + await cache.clear(); + + let valueInCache = await cache.get(testDid1); + expect(valueInCache).to.be.undefined; + valueInCache = await cache.get(testDid2); + expect(valueInCache).to.be.undefined; + }); + }); + + describe('delete()', () => { + it('removes specified entry from cache', async () => { + // Instantiate DID resolution cache with default TTL of 15 minutes. + cache = new DidResolverCacheLevel({ location: cacheStoreLocation }); + + const testDid1 = 'did:example:alice'; + const testDid2 = 'did:example:bob'; + + const testDidResolutionResult = { + didResolutionMetadata : {}, + didDocument : { id: 'abc123' }, + didDocumentMetadata : {} + }; + + await cache.set(testDid1, testDidResolutionResult); + await cache.set(testDid2, testDidResolutionResult); + + await cache.delete(testDid1); + + // Confirm cache miss for deleted entry. + let valueInCache = await cache.get(testDid1); + expect(valueInCache).to.be.undefined; + + // Time travel 14 minutes. + clock.tick(1000 * 60 * 14); + + // Confirm cache hit for entry that hasn't yet expired. + valueInCache = await cache.get(testDid2); + expect(valueInCache).to.deep.equal(testDidResolutionResult); + }); + }); + + describe('get()', () => { + it('does not throw an error given DID that is not in the cache', async () => { + // Instantiate DID resolution cache with default TTL of 15 minutes. + cache = new DidResolverCacheLevel({ location: cacheStoreLocation }); + + const valueInCache = await cache.get('did:method:not-present'); + expect(valueInCache).to.be.undefined; + }); + + it('throws an error if the given DID is null or undefined', async () => { + // Instantiate DID resolution cache with default TTL of 15 minutes. + cache = new DidResolverCacheLevel({ location: cacheStoreLocation }); + + await expect( + cache.get(null) + ).to.eventually.be.rejectedWith(Error, 'Key cannot be null or undefine'); + + await expect( + cache.get(undefined) + ).to.eventually.be.rejectedWith(Error, 'Key cannot be null or undefine'); + }); + }); +}); \ No newline at end of file diff --git a/packages/dids/tests/tech-preview.spec.ts b/packages/dids/tests/tech-preview.spec.ts deleted file mode 100644 index 74c45022b..000000000 --- a/packages/dids/tests/tech-preview.spec.ts +++ /dev/null @@ -1,68 +0,0 @@ -import type { DwnServiceEndpoint } from '../src/types.js'; - -import { expect } from 'chai'; - -import { DidIonApi } from '../src/did-ion.js'; - -describe('Tech Preview', function () { - describe('generateDwnConfiguration()', () => { - it('returns keys and services with two DWN URLs', async () => { - const ionCreateOptions = await DidIonApi.generateDwnConfiguration([ - 'https://dwn.tbddev.test/dwn0', - 'https://dwn.tbddev.test/dwn1' - ]); - - expect(ionCreateOptions).to.have.property('keys'); - expect(ionCreateOptions.keys).to.have.lengthOf(2); - let encryptionKey = ionCreateOptions.keys!.find(key => key.id === 'enc'); - expect(encryptionKey).to.exist; - let authorizationKey = ionCreateOptions.keys!.find(key => key.id === 'authz'); - expect(authorizationKey).to.exist; - - expect(ionCreateOptions).to.have.property('services'); - expect(ionCreateOptions.services).to.have.lengthOf(1); - - const [ service ] = ionCreateOptions.services!; - expect(service.id).to.equal('dwn'); - expect(service).to.have.property('serviceEndpoint'); - - const serviceEndpoint = service.serviceEndpoint as DwnServiceEndpoint; - expect(serviceEndpoint).to.have.property('nodes'); - expect(serviceEndpoint.nodes).to.have.lengthOf(2); - expect(serviceEndpoint).to.have.property('messageAuthorizationKeys'); - expect(serviceEndpoint!.messageAuthorizationKeys![0]).to.equal(`#${authorizationKey!.id}`); - expect(serviceEndpoint).to.have.property('recordEncryptionKeys'); - expect(serviceEndpoint!.recordEncryptionKeys![0]).to.equal(`#${encryptionKey!.id}`); - }); - - it('returns keys and services with one DWN URLs', async () => { - const ionCreateOptions = await DidIonApi.generateDwnConfiguration([ - 'https://dwn.tbddev.test/dwn0' - ]); - - const [ service ] = ionCreateOptions.services!; - expect(service.id).to.equal('dwn'); - expect(service).to.have.property('serviceEndpoint'); - - const serviceEndpoint = service.serviceEndpoint as DwnServiceEndpoint; - expect(serviceEndpoint).to.have.property('nodes'); - expect(serviceEndpoint.nodes).to.have.lengthOf(1); - expect(serviceEndpoint).to.have.property('messageAuthorizationKeys'); - expect(serviceEndpoint).to.have.property('recordEncryptionKeys'); - }); - - it('returns keys and services with 0 DWN URLs', async () => { - const ionCreateOptions = await DidIonApi.generateDwnConfiguration([]); - - const [ service ] = ionCreateOptions.services!; - expect(service.id).to.equal('dwn'); - expect(service).to.have.property('serviceEndpoint'); - - const serviceEndpoint = service.serviceEndpoint as DwnServiceEndpoint; - expect(serviceEndpoint).to.have.property('nodes'); - expect(serviceEndpoint.nodes).to.have.lengthOf(0); - expect(serviceEndpoint).to.have.property('messageAuthorizationKeys'); - expect(serviceEndpoint).to.have.property('recordEncryptionKeys'); - }); - }); -}); \ No newline at end of file diff --git a/packages/dids/tests/tsconfig.json b/packages/dids/tests/tsconfig.json index 7c6d2c8e7..ee97c2267 100644 --- a/packages/dids/tests/tsconfig.json +++ b/packages/dids/tests/tsconfig.json @@ -7,6 +7,7 @@ }, "include": [ "../src", + "../typings", ".", ], "exclude": [ diff --git a/packages/dids/tests/utils.spec.ts b/packages/dids/tests/utils.spec.ts index 07eefdb27..59160fa12 100644 --- a/packages/dids/tests/utils.spec.ts +++ b/packages/dids/tests/utils.spec.ts @@ -1,51 +1,55 @@ import { expect } from 'chai'; -import { keyToMultibaseId } from '../src/utils.js'; +import { + getVerificationMethodIds, + getVerificationMethodTypes, + parseDid, +} from '../src/utils.js'; +import { didDocumentIdTestVectors, didDocumentTypeTestVectors } from './fixtures/test-vectors/did-utils.js'; describe('DID Utils', () => { - describe('keyToMultibaseId()', () => { - it('returns a multibase encoded string', () => { - const input = { - key : new Uint8Array(32), - multicodecName : 'ed25519-pub', - }; - const encoded = keyToMultibaseId({ key: input.key, multicodecName: input.multicodecName }); - expect(encoded).to.be.a.string; - expect(encoded.substring(0, 1)).to.equal('z'); - expect(encoded.substring(1, 4)).to.equal('6Mk'); + describe('getVerificationMethodIds()', () => { + for (const vector of didDocumentIdTestVectors) { + it(`passes test vector ${vector.id}`, () => { + const methodIds = getVerificationMethodIds(vector.input as any); + expect(methodIds).to.deep.equal(vector.output); + }); + } + }); + + describe('getTypesFromDocument()', () => { + for (const vector of didDocumentTypeTestVectors) { + it(`passes test vector ${vector.id}`, () => { + const types = getVerificationMethodTypes(vector.input); + expect(types).to.deep.equal(vector.output); + }); + } + }); + + describe('parseDid()', () => { + it('extracts ION DID long form identifier from DID URL', async () => { + const { did } = parseDid({ + didUrl: 'did:ion:EiAi68p2irCNQIzaui8gTjGDeOqSUusZS8jWVHfseSWZ5g:eyJkZWx0YSI6eyJwYXRjaGVzIjpbeyJhY3Rpb24iOiJyZXBsYWNlIiwiZG9jdW1lbnQiOnsicHVibGljS2V5cyI6W3siaWQiOiJrZXktMSIsInB1YmxpY0tleUp3ayI6eyJjcnYiOiJzZWNwMjU2azEiLCJrdHkiOiJFQyIsIngiOiI2MWlQWXVHZWZ4b3R6QmRRWnREdnY2Y1dIWm1YclRUc2NZLXU3WTJwRlpjIiwieSI6Ijg4blBDVkxmckFZOWktd2c1T1Jjd1ZiSFdDX3RiZUFkMUpFMmUwY28wbFUifSwicHVycG9zZXMiOlsiYXV0aGVudGljYXRpb24iXSwidHlwZSI6IkVjZHNhU2VjcDI1NmsxVmVyaWZpY2F0aW9uS2V5MjAxOSJ9XSwic2VydmljZXMiOlt7ImlkIjoiZHduIiwic2VydmljZUVuZHBvaW50Ijp7Im5vZGVzIjpbImh0dHA6Ly9sb2NhbGhvc3Q6ODA4NSJdfSwidHlwZSI6IkRlY2VudHJhbGl6ZWRXZWJOb2RlIn1dfX1dLCJ1cGRhdGVDb21taXRtZW50IjoiRWlCb1c2dGs4WlZRTWs3YjFubkF2R3F3QTQ2amlaaUc2dWNYemxyNTZDWWFiUSJ9LCJzdWZmaXhEYXRhIjp7ImRlbHRhSGFzaCI6IkVpQ3Y2cUhEMFV4TTBadmZlTHU4dDR4eU5DVjNscFBSaTl6a3paU3h1LW8wWUEiLCJyZWNvdmVyeUNvbW1pdG1lbnQiOiJFaUN0STM0ckdGNU9USkJETXRUYm14a1lQeC0ydFd3MldZLTU2UTVPNHR0WWJBIn19' + }) ?? {}; + + expect(did).to.equal('did:ion:EiAi68p2irCNQIzaui8gTjGDeOqSUusZS8jWVHfseSWZ5g:eyJkZWx0YSI6eyJwYXRjaGVzIjpbeyJhY3Rpb24iOiJyZXBsYWNlIiwiZG9jdW1lbnQiOnsicHVibGljS2V5cyI6W3siaWQiOiJrZXktMSIsInB1YmxpY0tleUp3ayI6eyJjcnYiOiJzZWNwMjU2azEiLCJrdHkiOiJFQyIsIngiOiI2MWlQWXVHZWZ4b3R6QmRRWnREdnY2Y1dIWm1YclRUc2NZLXU3WTJwRlpjIiwieSI6Ijg4blBDVkxmckFZOWktd2c1T1Jjd1ZiSFdDX3RiZUFkMUpFMmUwY28wbFUifSwicHVycG9zZXMiOlsiYXV0aGVudGljYXRpb24iXSwidHlwZSI6IkVjZHNhU2VjcDI1NmsxVmVyaWZpY2F0aW9uS2V5MjAxOSJ9XSwic2VydmljZXMiOlt7ImlkIjoiZHduIiwic2VydmljZUVuZHBvaW50Ijp7Im5vZGVzIjpbImh0dHA6Ly9sb2NhbGhvc3Q6ODA4NSJdfSwidHlwZSI6IkRlY2VudHJhbGl6ZWRXZWJOb2RlIn1dfX1dLCJ1cGRhdGVDb21taXRtZW50IjoiRWlCb1c2dGs4WlZRTWs3YjFubkF2R3F3QTQ2amlaaUc2dWNYemxyNTZDWWFiUSJ9LCJzdWZmaXhEYXRhIjp7ImRlbHRhSGFzaCI6IkVpQ3Y2cUhEMFV4TTBadmZlTHU4dDR4eU5DVjNscFBSaTl6a3paU3h1LW8wWUEiLCJyZWNvdmVyeUNvbW1pdG1lbnQiOiJFaUN0STM0ckdGNU9USkJETXRUYm14a1lQeC0ydFd3MldZLTU2UTVPNHR0WWJBIn19'); }); - it('passes test vectors', () => { - let input: { key: Uint8Array, multicodecName: string }; - let output: string; - let encoded: string; - - // Test Vector 1. - input = { - key : (new Uint8Array(32)).fill(0), - multicodecName : 'ed25519-pub', - }; - output = 'z6MkeTG3bFFSLYVU7VqhgZxqr6YzpaGrQtFMh1uvqGy1vDnP'; - encoded = keyToMultibaseId({ key: input.key, multicodecName: input.multicodecName }); - expect(encoded).to.equal(output); - - // Test Vector 2. - input = { - key : (new Uint8Array(32)).fill(1), - multicodecName : 'ed25519-pub', - }; - output = 'z6MkeXBLjYiSvqnhFb6D7sHm8yKm4jV45wwBFRaatf1cfZ76'; - encoded = keyToMultibaseId({ key: input.key, multicodecName: input.multicodecName }); - expect(encoded).to.equal(output); - - // Test Vector 3. - input = { - key : (new Uint8Array(32)).fill(9), - multicodecName : 'ed25519-pub', - }; - output = 'z6Mkf4XhsxSXfEAWNK6GcFu7TyVs21AfUTRjiguqMhNQeDgk'; - encoded = keyToMultibaseId({ key: input.key, multicodecName: input.multicodecName }); - expect(encoded).to.equal(output); + it('extracts ION DID long form identifier from DID URL with query and fragment', async () => { + const { did } = parseDid({ + didUrl: 'did:ion:EiAi68p2irCNQIzaui8gTjGDeOqSUusZS8jWVHfseSWZ5g:eyJkZWx0YSI6eyJwYXRjaGVzIjpbeyJhY3Rpb24iOiJyZXBsYWNlIiwiZG9jdW1lbnQiOnsicHVibGljS2V5cyI6W3siaWQiOiJrZXktMSIsInB1YmxpY0tleUp3ayI6eyJjcnYiOiJzZWNwMjU2azEiLCJrdHkiOiJFQyIsIngiOiI2MWlQWXVHZWZ4b3R6QmRRWnREdnY2Y1dIWm1YclRUc2NZLXU3WTJwRlpjIiwieSI6Ijg4blBDVkxmckFZOWktd2c1T1Jjd1ZiSFdDX3RiZUFkMUpFMmUwY28wbFUifSwicHVycG9zZXMiOlsiYXV0aGVudGljYXRpb24iXSwidHlwZSI6IkVjZHNhU2VjcDI1NmsxVmVyaWZpY2F0aW9uS2V5MjAxOSJ9XSwic2VydmljZXMiOlt7ImlkIjoiZHduIiwic2VydmljZUVuZHBvaW50Ijp7Im5vZGVzIjpbImh0dHA6Ly9sb2NhbGhvc3Q6ODA4NSJdfSwidHlwZSI6IkRlY2VudHJhbGl6ZWRXZWJOb2RlIn1dfX1dLCJ1cGRhdGVDb21taXRtZW50IjoiRWlCb1c2dGs4WlZRTWs3YjFubkF2R3F3QTQ2amlaaUc2dWNYemxyNTZDWWFiUSJ9LCJzdWZmaXhEYXRhIjp7ImRlbHRhSGFzaCI6IkVpQ3Y2cUhEMFV4TTBadmZlTHU4dDR4eU5DVjNscFBSaTl6a3paU3h1LW8wWUEiLCJyZWNvdmVyeUNvbW1pdG1lbnQiOiJFaUN0STM0ckdGNU9USkJETXRUYm14a1lQeC0ydFd3MldZLTU2UTVPNHR0WWJBIn19?service=agent&relativeRef=/credentials#degree' + }) ?? {}; + + expect(did).to.equal('did:ion:EiAi68p2irCNQIzaui8gTjGDeOqSUusZS8jWVHfseSWZ5g:eyJkZWx0YSI6eyJwYXRjaGVzIjpbeyJhY3Rpb24iOiJyZXBsYWNlIiwiZG9jdW1lbnQiOnsicHVibGljS2V5cyI6W3siaWQiOiJrZXktMSIsInB1YmxpY0tleUp3ayI6eyJjcnYiOiJzZWNwMjU2azEiLCJrdHkiOiJFQyIsIngiOiI2MWlQWXVHZWZ4b3R6QmRRWnREdnY2Y1dIWm1YclRUc2NZLXU3WTJwRlpjIiwieSI6Ijg4blBDVkxmckFZOWktd2c1T1Jjd1ZiSFdDX3RiZUFkMUpFMmUwY28wbFUifSwicHVycG9zZXMiOlsiYXV0aGVudGljYXRpb24iXSwidHlwZSI6IkVjZHNhU2VjcDI1NmsxVmVyaWZpY2F0aW9uS2V5MjAxOSJ9XSwic2VydmljZXMiOlt7ImlkIjoiZHduIiwic2VydmljZUVuZHBvaW50Ijp7Im5vZGVzIjpbImh0dHA6Ly9sb2NhbGhvc3Q6ODA4NSJdfSwidHlwZSI6IkRlY2VudHJhbGl6ZWRXZWJOb2RlIn1dfX1dLCJ1cGRhdGVDb21taXRtZW50IjoiRWlCb1c2dGs4WlZRTWs3YjFubkF2R3F3QTQ2amlaaUc2dWNYemxyNTZDWWFiUSJ9LCJzdWZmaXhEYXRhIjp7ImRlbHRhSGFzaCI6IkVpQ3Y2cUhEMFV4TTBadmZlTHU4dDR4eU5DVjNscFBSaTl6a3paU3h1LW8wWUEiLCJyZWNvdmVyeUNvbW1pdG1lbnQiOiJFaUN0STM0ckdGNU9USkJETXRUYm14a1lQeC0ydFd3MldZLTU2UTVPNHR0WWJBIn19'); + }); + + it('extracts query and fragment from DID URL', () => { + const { fragment, query } = parseDid({ + didUrl: 'did:example:123?service=agent&relativeRef=/credentials#degree' + }) ?? {}; + + expect(fragment).to.equal('degree'); + expect(query).to.equal('service=agent&relativeRef=/credentials'); }); }); }); \ No newline at end of file diff --git a/packages/dids/tsconfig.cjs.json b/packages/dids/tsconfig.cjs.json index 0384273d6..e34b3674f 100644 --- a/packages/dids/tsconfig.cjs.json +++ b/packages/dids/tsconfig.cjs.json @@ -10,9 +10,11 @@ "outDir": "dist/cjs", "declaration": false, "declarationMap": false, - "declarationDir": null + "declarationDir": null, + "downlevelIteration": true }, "include": [ - "src" + "src", + "typings" ] } \ No newline at end of file diff --git a/packages/dids/tsconfig.json b/packages/dids/tsconfig.json index c8ce1cc3d..efd20a630 100644 --- a/packages/dids/tsconfig.json +++ b/packages/dids/tsconfig.json @@ -20,7 +20,6 @@ "typings" ], "exclude": [ - "node_modules", - "dist" + "node_modules" ] } \ No newline at end of file diff --git a/packages/dids/typings/decentralized-identity__ion-pow-sdk.d.ts b/packages/dids/typings/decentralized-identity__ion-pow-sdk.d.ts new file mode 100644 index 000000000..03fc84a06 --- /dev/null +++ b/packages/dids/typings/decentralized-identity__ion-pow-sdk.d.ts @@ -0,0 +1,7 @@ +declare module '@decentralized-identity/ion-pow-sdk' { + export default class IonProofOfWork { + static randomHexString(): string; + static submitIonRequestUntilSuccess(getChallengeUri: string, solveChallengeUri: string, requestBody: string): Promise; + static submitIonRequest(getChallengeUri: string, solveChallengeUri: string, requestBody: string): Promise; + } +} \ No newline at end of file diff --git a/packages/dids/typings/decentralized-identity__ion-tools.d.ts b/packages/dids/typings/decentralized-identity__ion-tools.d.ts deleted file mode 100644 index 9a54c0d30..000000000 --- a/packages/dids/typings/decentralized-identity__ion-tools.d.ts +++ /dev/null @@ -1 +0,0 @@ -declare module '@decentralized-identity/ion-tools'; \ No newline at end of file diff --git a/packages/web5/.c8rc.json b/packages/identity-agent/.c8rc.json similarity index 66% rename from packages/web5/.c8rc.json rename to packages/identity-agent/.c8rc.json index 1d1670b70..ab680f663 100644 --- a/packages/web5/.c8rc.json +++ b/packages/identity-agent/.c8rc.json @@ -5,12 +5,12 @@ ".js" ], "include": [ - "tests/compiled/**" + "tests/compiled/src/**" ], "exclude": [ - "tests/compiled/src/main.js", + "tests/compiled/src/index.js", "tests/compiled/src/types.js", - "tests/compiled/types/**" + "tests/compiled/src/types/**" ], "reporter": [ "cobertura", diff --git a/packages/web5/.mocharc.json b/packages/identity-agent/.mocharc.json similarity index 100% rename from packages/web5/.mocharc.json rename to packages/identity-agent/.mocharc.json diff --git a/packages/web5-user-agent/.vscode/launch.json b/packages/identity-agent/.vscode/launch.json similarity index 100% rename from packages/web5-user-agent/.vscode/launch.json rename to packages/identity-agent/.vscode/launch.json diff --git a/packages/identity-agent/.vscode/tasks.json b/packages/identity-agent/.vscode/tasks.json new file mode 100644 index 000000000..c5b8d931a --- /dev/null +++ b/packages/identity-agent/.vscode/tasks.json @@ -0,0 +1,37 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "npm run build", + "type": "npm", + "script": "build", + "group": { + "kind": "build", + "isDefault": true + } + }, + { + "label": "tsc: build - tsconfig.json", + "type": "typescript", + "tsconfig": "tsconfig.json", + "problemMatcher": [ + "$tsc" + ], + "group": { + "kind": "build", + "isDefault": false + }, + "options": { + "cwd": "${workspaceFolder:root}" + } + }, + { + "label": "build tests", + "type": "npm", + "script": "build:tests:node", + "options": { + "cwd": "${workspaceFolder:identity-agent}" + } + } + ] +} \ No newline at end of file diff --git a/packages/identity-agent/build/bundles.js b/packages/identity-agent/build/bundles.js new file mode 100644 index 000000000..752ac09fc --- /dev/null +++ b/packages/identity-agent/build/bundles.js @@ -0,0 +1,16 @@ +import esbuild from 'esbuild'; +import browserConfig from './esbuild-browser-config.cjs'; + +// esm polyfilled bundle for browser +esbuild.build({ + ...browserConfig, + outfile: 'dist/browser.mjs', +}); + +// iife polyfilled bundle for browser +esbuild.build({ + ...browserConfig, + format : 'iife', + globalName : 'Web5IdentityAgent', + outfile : 'dist/browser.js', +}); \ No newline at end of file diff --git a/packages/identity-agent/build/esbuild-browser-config.cjs b/packages/identity-agent/build/esbuild-browser-config.cjs new file mode 100644 index 000000000..bd8bd99b1 --- /dev/null +++ b/packages/identity-agent/build/esbuild-browser-config.cjs @@ -0,0 +1,30 @@ +/* eslint-disable @typescript-eslint/no-var-requires */ +const polyfillProviderPlugin = require('node-stdlib-browser/helpers/esbuild/plugin'); +const stdLibBrowser = require('node-stdlib-browser'); + +const requiredPolyfills = new Set(['crypto', 'node:crypto', 'stream']); + +// populate object containing lib -> polyfill path +const polyfills = {}; +for (let lib in stdLibBrowser) { + if (requiredPolyfills.has(lib)) { + const polyfill = stdLibBrowser[lib]; + polyfills[lib] = polyfill; + } +} + +/** @type {import('esbuild').BuildOptions} */ +module.exports = { + entryPoints : ['./src/index.ts'], + bundle : true, + format : 'esm', + sourcemap : true, + minify : true, + platform : 'browser', + target : ['chrome101', 'firefox108', 'safari16'], + inject : [require.resolve('node-stdlib-browser/helpers/esbuild/shim')], + plugins : [polyfillProviderPlugin(polyfills)], + define : { + 'global': 'globalThis', + }, +}; \ No newline at end of file diff --git a/packages/identity-agent/karma.conf.cjs b/packages/identity-agent/karma.conf.cjs new file mode 100644 index 000000000..6b7407b2c --- /dev/null +++ b/packages/identity-agent/karma.conf.cjs @@ -0,0 +1,87 @@ +/* eslint-disable @typescript-eslint/no-var-requires */ +// Karma is what we're using to run our tests in browser environments +// Karma does not support .mjs + +// playwright acts as a safari executable on windows and mac +const playwright = require('@playwright/test'); +const esbuildBrowserConfig = require('./build/esbuild-browser-config.cjs'); + +// use playwright chrome exec path as run target for chromium tests +process.env.CHROME_BIN = playwright.chromium.executablePath(); + +// use playwright webkit exec path as run target for safari tests +process.env.WEBKIT_HEADLESS_BIN = playwright.webkit.executablePath(); + +// use playwright firefox exec path as run target for firefox tests +process.env.FIREFOX_BIN = playwright.firefox.executablePath(); + +module.exports = function (config) { + config.set({ + plugins: [ + 'karma-chrome-launcher', + 'karma-firefox-launcher', + 'karma-webkit-launcher', + 'karma-esbuild', + 'karma-mocha', + 'karma-mocha-reporter', + ], + + // frameworks to use + // available frameworks: https://www.npmjs.com/search?q=keywords:karma-adapter + frameworks: ['mocha'], + + client: { + // Increase Mocha's default timeout of 2 seconds to prevent timeouts during GitHub CI runs. + mocha: { + timeout: 10000 // 10 seconds + }, + // If an environment variable is defined, override the default test DWN URL. + testDwnUrl: process.env.TEST_DWN_URL, + }, + + // list of files / patterns to load in the browser + files: [ + { pattern: 'tests/**/*.spec.ts', watched: false }, + ], + + // preprocess matching files before serving them to the browser + // available preprocessors: https://www.npmjs.com/search?q=keywords:karma-preprocessor + preprocessors: { + 'tests/**/*.spec.ts': ['esbuild'], + }, + + esbuild: esbuildBrowserConfig, + + // list of files / patterns to exclude + exclude: [], + + // test results reporter to use + // available reporters: https://www.npmjs.com/search?q=keywords:karma-reporter + reporters: ['mocha'], + + // web server port + port: 9876, + + // enable / disable colors in the output (reporters and logs) + colors: true, + + // level of logging + // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || + // config.LOG_INFO || config.LOG_DEBUG + logLevel: config.LOG_INFO, + + concurrency: 1, + + // start these browsers + // available browser launchers: https://www.npmjs.com/search?q=keywords:karma-launcher + browsers: ['ChromeHeadless', 'FirefoxHeadless', 'WebkitHeadless'], + + // Continuous Integration mode + // if true, Karma captures browsers, runs the tests and exits + singleRun: true, + + // Increase browser timeouts to avoid DISCONNECTED messages during GitHub CI runs. + browserDisconnectTimeout : 10000, // default 2000 + browserDisconnectTolerance : 1, // default 0 + }); +}; diff --git a/packages/web5-agent/package.json b/packages/identity-agent/package.json similarity index 71% rename from packages/web5-agent/package.json rename to packages/identity-agent/package.json index ed090fdd0..103f9682e 100644 --- a/packages/web5-agent/package.json +++ b/packages/identity-agent/package.json @@ -1,13 +1,12 @@ { - "name": "@tbd54566975/web5-agent", - "version": "0.8.0", - "description": "Web5 Agent", + "name": "@web5/identity-agent", + "version": "0.2.0", "type": "module", - "main": "./dist/cjs/main.js", - "module": "./dist/esm/main.js", - "types": "./dist/types/main.d.ts", + "main": "./dist/cjs/index.js", + "module": "./dist/esm/index.js", + "types": "./dist/types/index.d.ts", "scripts": { - "clean": "rimraf dist coverage tests/compiled", + "clean": "rimraf dist tests/compiled", "build:esm": "rimraf dist/esm dist/types && npx tsc -p tsconfig.json", "build:cjs": "rimraf dist/cjs && tsc -p tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > ./dist/cjs/package.json", "build:browser": "rimraf dist/browser.mjs dist/browser.js && node build/bundles.js", @@ -18,12 +17,12 @@ "test:node": "npm run build:tests:node && c8 mocha", "test:browser": "karma start karma.conf.cjs" }, - "homepage": "https://github.com/TBD54566975/web5-js/tree/main/packages/web5-agent#readme", + "homepage": "https://github.com/TBD54566975/web5-js/tree/main/packages/identity-agent#readme", "bugs": "https://github.com/TBD54566975/web5-js/issues", "repository": { "type": "git", "url": "git+https://github.com/TBD54566975/web5-js", - "directory": "packages/web5-agent" + "directory": "packages/identity-agent" }, "license": "Apache-2.0", "contributors": [ @@ -46,17 +45,19 @@ ], "exports": { ".": { - "import": "./dist/esm/main.js", - "require": "./dist/cjs/main.js", - "types": "./dist/types/main.d.ts" + "types": "./dist/types/index.d.ts", + "import": "./dist/esm/index.js", + "require": "./dist/cjs/index.js" } }, - "react-native": "./dist/esm/main.mjs", + "react-native": "./dist/esm/index.js", "keywords": [ "decentralized", "decentralized-applications", "decentralized-identity", "decentralized-web", + "vcs", + "verifiable credentials", "web5" ], "publishConfig": { @@ -66,23 +67,22 @@ "node": ">=18.0.0" }, "dependencies": { - "readable-stream": "4.4.0", - "@tbd54566975/dwn-sdk-js": "0.2.1" + "@web5/agent": "0.2.0", + "@web5/api": "0.8.1" }, "devDependencies": { - "@types/chai": "4.3.0", + "@playwright/test": "1.36.2", + "@types/chai": "4.3.5", "@types/chai-as-promised": "7.1.5", - "@types/eslint": "8.37.0", + "@types/eslint": "8.44.2", "@types/mocha": "10.0.1", - "@types/readable-stream": "2.3.15", - "@types/sinon": "10.0.15", - "@typescript-eslint/eslint-plugin": "5.59.0", - "@typescript-eslint/parser": "5.59.0", - "c8": "8.0.0", + "@typescript-eslint/eslint-plugin": "6.4.0", + "@typescript-eslint/parser": "6.4.0", + "c8": "8.0.1", "chai": "4.3.7", "chai-as-promised": "7.1.1", "esbuild": "0.16.17", - "eslint": "8.39.0", + "eslint": "8.47.0", "eslint-plugin-mocha": "10.1.0", "karma": "6.4.1", "karma-chai": "0.1.0", @@ -93,10 +93,9 @@ "karma-mocha-reporter": "2.2.5", "karma-webkit-launcher": "2.1.0", "mocha": "10.2.0", + "node-stdlib-browser": "1.2.0", "playwright": "1.36.2", "rimraf": "4.4.0", - "sinon": "15.0.2", - "source-map-loader": "4.0.1", "typescript": "5.1.6" } -} \ No newline at end of file +} diff --git a/packages/identity-agent/src/identity-agent.ts b/packages/identity-agent/src/identity-agent.ts new file mode 100644 index 000000000..15bfb6690 --- /dev/null +++ b/packages/identity-agent/src/identity-agent.ts @@ -0,0 +1,238 @@ +import type { + DwnRpc, + VcResponse, + DidResponse, + DwnResponse, + AppDataStore, + SendVcRequest, + SendDidRequest, + SendDwnRequest, + ProcessVcRequest, + Web5ManagedAgent, + ProcessDwnRequest, + ProcessDidRequest, +} from '@web5/agent'; + +import { LevelStore } from '@web5/common'; +import { EdDsaAlgorithm } from '@web5/crypto'; +import { DidIonMethod, DidKeyMethod, DidResolver } from '@web5/dids'; +import { + LocalKms, + DidManager, + DwnManager, + KeyManager, + DidStoreDwn, + KeyStoreDwn, + AppDataVault, + Web5RpcClient, + IdentityManager, + IdentityStoreDwn, + PrivateKeyStoreDwn, + cryptoToPortableKeyPair, +} from '@web5/agent'; + +export type IdentityAgentOptions = { + agentDid: string; + appData: AppDataStore; + didManager: DidManager; + didResolver: DidResolver; + dwnManager: DwnManager; + identityManager: IdentityManager; + keyManager: KeyManager; + rpcClient: DwnRpc; +} + +export class IdentityAgent implements Web5ManagedAgent { + agentDid: string; + appData: AppDataStore; + didManager: DidManager; + didResolver: DidResolver; + dwnManager: DwnManager; + identityManager: IdentityManager; + keyManager: KeyManager; + rpcClient: DwnRpc; + + constructor(options: IdentityAgentOptions) { + this.agentDid = options.agentDid; + this.appData = options.appData; + this.didManager = options.didManager; + this.didResolver = options.didResolver; + this.dwnManager = options.dwnManager; + this.identityManager = options.identityManager; + this.keyManager = options.keyManager; + this.rpcClient = options.rpcClient; + + // Set this agent to be the default agent. + this.didManager.agent = this; + this.dwnManager.agent = this; + this.identityManager.agent = this; + this.keyManager.agent = this; + } + + static async create(options: Partial = {}): Promise { + let { agentDid, appData, didManager, didResolver, dwnManager, identityManager, keyManager, rpcClient } = options; + + if (agentDid === undefined) { + // An Agent DID was not specified, so set to empty string. + agentDid = ''; + } + + if (appData === undefined) { + // A custom AppDataStore implementation was not specified, so + // instantiate a LevelDB backed secure AppDataVault. + appData = new AppDataVault({ + store: new LevelStore('data/agent/vault') + }); + } + + if (didManager === undefined) { + // A custom DidManager implementation was not specified, so + // instantiate a default with in-memory store. + didManager = new DidManager({ + didMethods : [DidIonMethod, DidKeyMethod], + store : new DidStoreDwn() + }); + } + + if (didResolver === undefined) { + // A custom DidManager implementation was not specified, so + // instantiate a default with in-memory store. + didResolver = new DidResolver({ didResolvers: [DidIonMethod, DidKeyMethod] }); + } + + if (dwnManager === undefined) { + // A custom DwnManager implementation was not specified, so + // instantiate a default. + dwnManager = await DwnManager.create({ didResolver }); + } + + if (identityManager === undefined) { + // A custom IdentityManager implementation was not specified, so + // instantiate a default that uses a DWN store. + identityManager = new IdentityManager({ + store: new IdentityStoreDwn() + }); + } + + if (keyManager === undefined) { + // A custom KeyManager implementation was not specified, so + // instantiate a default with KMSs. + const localKmsDwn = new LocalKms({ + kmsName : 'local', + keyStore : new KeyStoreDwn({ schema: 'https://identity.foundation/schemas/web5/kms-key' }), + privateKeyStore : new PrivateKeyStoreDwn() + }); + const localKmsMemory = new LocalKms({ + kmsName: 'memory' + }); + keyManager = new KeyManager({ + kms: { + local : localKmsDwn, + memory : localKmsMemory + }, + store: new KeyStoreDwn({ schema: 'https://identity.foundation/schemas/web5/managed-key' }) + }); + } + + if (rpcClient === undefined) { + // A custom RPC Client implementation was not specified, so + // instantiate a default. + rpcClient = new Web5RpcClient(); + } + + // Instantiate the Identity Agent. + const agent = new IdentityAgent({ + agentDid, + appData, + didManager, + didResolver, + dwnManager, + identityManager, + keyManager, + rpcClient + }); + + return agent; + } + + async firstLaunch(): Promise { + // Check whether data vault is already initialized. + const { initialized } = await this.appData.getStatus(); + return initialized === false; + } + + /** + * Executed once the first time the Identity Agent is launched. + * The passphrase should be input by the end-user. + * */ + async initialize(options: { passphrase: string }) { + const { passphrase } = options; + + // Generate an Ed25519 key pair for the Identity Agent. + const agentKeyPair = await new EdDsaAlgorithm().generateKey({ + algorithm : { name: 'EdDSA', namedCurve: 'Ed25519' }, + extractable : true, + keyUsages : ['sign', 'verify'] + }); + + /** Initialize the AppDataStore with the Identity Agent's + * private key and passphrase, which also unlocks the data vault. */ + await this.appData.initialize({ + passphrase : passphrase, + keyPair : agentKeyPair, + }); + } + + async processDidRequest(_request: ProcessDidRequest): Promise { + throw new Error('Not implemented'); + } + + async processDwnRequest(request: ProcessDwnRequest): Promise { + return this.dwnManager.processRequest(request); + } + + async processVcRequest(_request: ProcessVcRequest): Promise { + throw new Error('Not implemented'); + } + + async sendDidRequest(_request: SendDidRequest): Promise { + throw new Error('Not implemented'); + } + + async sendDwnRequest(request: SendDwnRequest): Promise { + return this.dwnManager.sendRequest(request); + } + + async sendVcRequest(_request: SendVcRequest): Promise { + throw new Error('Not implemented'); + } + + async start(options: { passphrase: string }) { + const { passphrase } = options; + + if (await this.firstLaunch()) { + // 1A. Agent's first launch so initialize. + await this.initialize({ passphrase }); + } else { + // 1B. Agent was previously initialized. + // Unlock the data vault and cache the vault unlock key (VUK) in memory. + await this.appData.unlock({ passphrase }); + } + + // 2. Set the Identity Agent's root did:key identifier. + this.agentDid = await this.appData.getDid(); + + // 3. Import the Identity Agent's signing key pair to KeyManager. + const defaultSigningKey = cryptoToPortableKeyPair({ + cryptoKeyPair: { + privateKey : await this.appData.getPrivateKey(), + publicKey : await this.appData.getPublicKey() + }, + keyData: { + alias : await this.didManager.getDefaultSigningKey({ did: this.agentDid }), + kms : 'memory' + } + }); + await this.keyManager.setDefaultSigningKey({ key: defaultSigningKey }); + } +} \ No newline at end of file diff --git a/packages/identity-agent/src/index.ts b/packages/identity-agent/src/index.ts new file mode 100644 index 000000000..976d400e2 --- /dev/null +++ b/packages/identity-agent/src/index.ts @@ -0,0 +1 @@ +export * from './identity-agent.js'; \ No newline at end of file diff --git a/packages/identity-agent/tests/identity-agent.spec.ts b/packages/identity-agent/tests/identity-agent.spec.ts new file mode 100644 index 000000000..4debdcf52 --- /dev/null +++ b/packages/identity-agent/tests/identity-agent.spec.ts @@ -0,0 +1,177 @@ +import * as sinon from 'sinon'; +import chai, { expect } from 'chai'; +import chaiAsPromised from 'chai-as-promised'; +import { TestManagedAgent } from '@web5/agent'; + +import { IdentityAgent } from '../src/identity-agent.js'; + +chai.use(chaiAsPromised); + +// NOTE: @noble/secp256k1 requires globalThis.crypto polyfill for node.js <=18: https://github.com/paulmillr/noble-secp256k1/blob/main/README.md#usage +// Remove when we move off of node.js v18 to v20, earliest possible time would be Oct 2023: https://github.com/nodejs/release#release-schedule +// NOTE: @noble/secp256k1 requires globalThis.crypto polyfill for node.js <=18: https://github.com/paulmillr/noble-secp256k1/blob/main/README.md#usage +// Remove when we move off of node.js v18 to v20, earliest possible time would be Oct 2023: https://github.com/nodejs/release#release-schedule +import { webcrypto } from 'node:crypto'; +// @ts-ignore +if (!globalThis.crypto) globalThis.crypto = webcrypto; + +describe('IdentityAgent', () => { + + const agentStoreTypes = ['dwn', 'memory'] as const; + agentStoreTypes.forEach((agentStoreType) => { + + describe(`with ${agentStoreType} data stores`, () => { + let testAgent: TestManagedAgent; + + before(async () => { + testAgent = await TestManagedAgent.create({ + agentClass : IdentityAgent, + agentStores : agentStoreType + }); + }); + + beforeEach(async () => { + await testAgent.clearStorage(); + }); + + after(async () => { + await testAgent.clearStorage(); + await testAgent.closeStorage(); + }); + + describe('firstLaunch()', () => { + it('returns true the first time the Identity Agent runs', async () => { + await expect(testAgent.agent.firstLaunch()).to.eventually.be.true; + }); + + it('returns false after Identity Agent initialization', async () => { + await expect(testAgent.agent.firstLaunch()).to.eventually.be.true; + + await testAgent.agent.start({ passphrase: 'test' }); + await expect(testAgent.agent.firstLaunch()).to.eventually.be.false; + }); + }); + + describe('initialize()', () => { + it('initializes the AppData store and stores the vault key set', async () => { + await testAgent.agent.initialize({ passphrase: 'test' }); + + // Confirm the AppData store was initialized. + const { initialized } = await testAgent.agent.appData.getStatus(); + expect(initialized).to.be.true; + + // Confirm the vault key set was stored. + const storedVaultKeySet = await testAgent.appDataStore.get('vaultKeySet'); + expect(storedVaultKeySet).to.exist; + expect(storedVaultKeySet).to.be.a.string; + }); + }); + + describe('start()', () => { + it('initializes the AppData store the first time the Identity Agent runs', async () => { + // const agent = await IdentityAgent.create({ appData, dwnManager }); + let initializeSpy = sinon.spy(testAgent.agent, 'initialize'); + let unlockSpy = sinon.spy(testAgent.agent.appData, 'unlock'); + + // Execute agent.start() for the first time. + await testAgent.agent.start({ passphrase: 'test' }); + + // Confirm agent.initialize() was called. + expect(initializeSpy.called).to.be.true; + + // Confirm agent.appData.unlock() was not called. + expect(unlockSpy.called).to.be.false; + + // Confirm the AppData store was initialized. + const { initialized } = await testAgent.agent.appData.getStatus(); + expect(initialized).to.be.true; + + // Confirm the vault key set was stored. + const storedVaultKeySet = await testAgent.appDataStore.get('vaultKeySet'); + expect(storedVaultKeySet).to.exist; + expect(storedVaultKeySet).to.be.a.string; + + // Confirm the AppData store was unlocked. + // @ts-expect-error because a private variable is being intentionally accessed. + const vaultUnlockKey = testAgent.agent.appData._vaultUnlockKey; + expect(vaultUnlockKey).to.exist; + expect(vaultUnlockKey).to.be.a('Uint8Array'); + + // Confirm the Agent's key pair was stored in KeyManager. + if (testAgent.agent.agentDid === undefined) throw new Error(); // Type guard. + const signingKeyId = await testAgent.agent.didManager.getDefaultSigningKey({ did: testAgent.agent.agentDid }); + if (!signingKeyId) throw new Error('Type guard'); + const agentKeyPair = await testAgent.agent.keyManager.getKey({ keyRef: signingKeyId }); + expect(agentKeyPair).to.exist; + expect(agentKeyPair).to.have.property('privateKey'); + expect(agentKeyPair).to.have.property('publicKey'); + + initializeSpy.restore(); + unlockSpy.restore(); + }); + + it('unlocks the AppData store on subsequent Identity Agent runs', async () => { + // Execute agent.start() for the first time. + await testAgent.agent.start({ passphrase: 'test' }); + + let initializeSpy = sinon.spy(testAgent.agent, 'initialize'); + let unlockSpy = sinon.spy(testAgent.agent.appData, 'unlock'); + + // Execute agent.start() for the second time. + await testAgent.agent.start({ passphrase: 'test' }); + + // Confirm agent.initialize() was not called. + expect(initializeSpy.called).to.be.false; + + // Confirm agent.appData.unlock() was called. + expect(unlockSpy.called).to.be.true; + + // Confirm the vault key set was stored. + const storedVaultKeySet = await testAgent.appDataStore.get('vaultKeySet'); + expect(storedVaultKeySet).to.exist; + expect(storedVaultKeySet).to.be.a.string; + + // Confirm the AppData store was unlocked. + // @ts-expect-error because a private variable is being intentionally accessed. + const vaultUnlockKey = testAgent.agent.appData._vaultUnlockKey; + expect(vaultUnlockKey).to.exist; + expect(vaultUnlockKey).to.be.a('Uint8Array'); + + // Confirm the Agent's key pair was stored in KeyManager. + if (testAgent.agent.agentDid === undefined) throw new Error(); // Type guard. + const signingKeyId = await testAgent.agent.didManager.getDefaultSigningKey({ did: testAgent.agent.agentDid }); + if (!signingKeyId) throw new Error('Type guard'); + const agentKeyPair = await testAgent.agent.keyManager.getKey({ keyRef: signingKeyId }); + expect(agentKeyPair).to.exist; + expect(agentKeyPair).to.have.property('privateKey'); + expect(agentKeyPair).to.have.property('publicKey'); + + initializeSpy.restore(); + unlockSpy.restore(); + }); + + it('unlocks the AppData store', async () => { + // const agent = await IdentityAgent.create({ appData, dwnManager }); + let initializeSpy = sinon.spy(testAgent.agent, 'initialize'); + let unlockSpy = sinon.spy(testAgent.agent.appData, 'unlock'); + + await testAgent.agent.start({ passphrase: 'test' }); + + // Confirm agent.initialize() was called. + expect(initializeSpy.called).to.be.true; + + // Confirm agent.appData.unlock() was not called. + expect(unlockSpy.called).to.be.false; + + // @ts-expect-error because a private variable is being intentionally accessed. + const vaultUnlockKey = testAgent.agent.appData._vaultUnlockKey; + expect(vaultUnlockKey).to.exist; + expect(vaultUnlockKey).to.be.a('Uint8Array'); + + initializeSpy.restore(); + unlockSpy.restore(); + }); + }); + }); + }); +}); \ No newline at end of file diff --git a/packages/identity-agent/tests/managing-identities.spec.ts b/packages/identity-agent/tests/managing-identities.spec.ts new file mode 100644 index 000000000..f608e1102 --- /dev/null +++ b/packages/identity-agent/tests/managing-identities.spec.ts @@ -0,0 +1,222 @@ +import { Web5 } from '@web5/api'; +import chai, { expect } from 'chai'; +import chaiAsPromised from 'chai-as-promised'; +import { TestManagedAgent } from '@web5/agent'; + +import { IdentityAgent } from '../src/identity-agent.js'; + +chai.use(chaiAsPromised); + +// NOTE: @noble/secp256k1 requires globalThis.crypto polyfill for node.js <=18: https://github.com/paulmillr/noble-secp256k1/blob/main/README.md#usage +// Remove when we move off of node.js v18 to v20, earliest possible time would be Oct 2023: https://github.com/nodejs/release#release-schedule +// NOTE: @noble/secp256k1 requires globalThis.crypto polyfill for node.js <=18: https://github.com/paulmillr/noble-secp256k1/blob/main/README.md#usage +// Remove when we move off of node.js v18 to v20, earliest possible time would be Oct 2023: https://github.com/nodejs/release#release-schedule +import { webcrypto } from 'node:crypto'; +// @ts-ignore +if (!globalThis.crypto) globalThis.crypto = webcrypto; + +describe('Managing Identities', () => { + + const agentStoreTypes = ['dwn', 'memory'] as const; + agentStoreTypes.forEach((agentStoreType) => { + + describe(`with ${agentStoreType} data stores`, () => { + let testAgent: TestManagedAgent; + + before(async () => { + testAgent = await TestManagedAgent.create({ + agentClass : IdentityAgent, + agentStores : agentStoreType + }); + }); + + beforeEach(async () => { + await testAgent.clearStorage(); + }); + + after(async () => { + await testAgent.clearStorage(); + await testAgent.closeStorage(); + }); + + describe('initial identity creation', () => { + it('can create three identities', async () => { + // Start agent for the first time. + await testAgent.agent.start({ passphrase: 'test' }); + + // Create three identities, each of which is stored in a new tenant. + const careerIdentity = await testAgent.agent.identityManager.create({ + name : 'Social', + didMethod : 'key', + kms : 'local' + }); + + const familyIdentity = await testAgent.agent.identityManager.create({ + name : 'Social', + didMethod : 'key', + kms : 'local' + }); + + const socialIdentity = await testAgent.agent.identityManager.create({ + name : 'Social', + didMethod : 'key', + kms : 'local' + }); + + // Verify the Identities were stored in each new Identity's tenant. + const storedCareerIdentity = await testAgent.agent.identityManager.get({ did: careerIdentity.did, context: careerIdentity.did }); + const storedFamilyIdentity = await testAgent.agent.identityManager.get({ did: familyIdentity.did, context: familyIdentity.did }); + const storedSocialIdentity = await testAgent.agent.identityManager.get({ did: socialIdentity.did, context: socialIdentity.did }); + expect(storedCareerIdentity).to.have.property('did', careerIdentity.did); + expect(storedFamilyIdentity).to.have.property('did', familyIdentity.did); + expect(storedSocialIdentity).to.have.property('did', socialIdentity.did); + }); + + // Tests that should only run for DWN-backed stores that provide multi-tenancy. + if (agentStoreType === 'dwn') { + it('supports tenant isolation between Identity Agent and Identities under management', async () => { + // Start agent for the first time. + await testAgent.agent.start({ passphrase: 'test' }); + + // Create three identities, each of which is stored in a new tenant. + const careerIdentity = await testAgent.agent.identityManager.create({ + name : 'Career', + didMethod : 'key', + kms : 'local' + }); + + const familyIdentity = await testAgent.agent.identityManager.create({ + name : 'Family', + didMethod : 'key', + kms : 'local' + }); + + const socialIdentity = await testAgent.agent.identityManager.create({ + name : 'Social', + didMethod : 'key', + kms : 'local' + }); + + // Import just the Identity metadata for the new identities to the Identity Agent's tenant. + await testAgent.agent.identityManager.import({ identity: careerIdentity, context: testAgent.agent.agentDid }); + await testAgent.agent.identityManager.import({ identity: familyIdentity, context: testAgent.agent.agentDid }); + await testAgent.agent.identityManager.import({ identity: socialIdentity, context: testAgent.agent.agentDid }); + + // Verify the Identities were stored in each new Identity's tenant. + const storedCareerIdentity = await testAgent.agent.identityManager.get({ did: careerIdentity.did, context: careerIdentity.did }); + const storedFamilyIdentity = await testAgent.agent.identityManager.get({ did: familyIdentity.did, context: familyIdentity.did }); + const storedSocialIdentity = await testAgent.agent.identityManager.get({ did: socialIdentity.did, context: socialIdentity.did }); + expect(storedCareerIdentity).to.have.property('did', careerIdentity.did); + expect(storedFamilyIdentity).to.have.property('did', familyIdentity.did); + expect(storedSocialIdentity).to.have.property('did', socialIdentity.did); + + // Verify the Identities were ALSO stored in the Identity Agent's tenant. + const storedIdentities = await testAgent.agent.identityManager.list(); + expect(storedIdentities).to.have.length(3); + + // Verify the DIDs were only stored in the new Identity's tenant. + let storedCareerDid = await testAgent.agent.didManager.get({ didRef: careerIdentity.did, context: careerIdentity.did }); + expect(storedCareerDid).to.exist; + storedCareerDid = await testAgent.agent.didManager.get({ didRef: careerIdentity.did }); + expect(storedCareerDid).to.not.exist; + let storedFamilyDid = await testAgent.agent.didManager.get({ didRef: familyIdentity.did, context: familyIdentity.did }); + expect(storedFamilyDid).to.exist; + storedFamilyDid = await testAgent.agent.didManager.get({ didRef: familyIdentity.did }); + expect(storedFamilyDid).to.not.exist; + let storedSocialDid = await testAgent.agent.didManager.get({ didRef: socialIdentity.did, context: socialIdentity.did }); + expect(storedSocialDid).to.exist; + storedSocialDid = await testAgent.agent.didManager.get({ didRef: socialIdentity.did }); + expect(storedSocialDid).to.not.exist; + + // Verify keys were stored in Identity Agent's DWN. + const careerKey = await testAgent.agent.keyManager.getKey({ + keyRef: await testAgent.agent.didManager.getDefaultSigningKey({ did: careerIdentity.did }) ?? '' // Type guard. + }); + expect(careerKey).to.exist; + const familyKey = await testAgent.agent.keyManager.getKey({ + keyRef: await testAgent.agent.didManager.getDefaultSigningKey({ did: familyIdentity.did }) ?? '' // Type guard. + }); + expect(familyKey).to.exist; + const socialKey = await testAgent.agent.keyManager.getKey({ + keyRef: await testAgent.agent.didManager.getDefaultSigningKey({ did: socialIdentity.did }) ?? '' // Type guard. + }); + expect(socialKey).to.exist; + }); + } + }); + + describe('Using Web5 API', async () => { + it('should instantiate Web5 API with provided Web5Agent and DID', async () => { + // Start agent for the first time. + await testAgent.agent.start({ passphrase: 'test' }); + + // Create two identities, each of which is stored in a new tenant. + const careerIdentity = await testAgent.agent.identityManager.create({ + name : 'Career', + didMethod : 'key', + kms : 'local' + }); + const socialIdentity = await testAgent.agent.identityManager.create({ + name : 'Social', + didMethod : 'key', + kms : 'local' + }); + + // Instantiate a Web5 instance with the "Career" Identity, write a record, and verify the result. + const web5Career = new Web5({ agent: testAgent.agent, connectedDid: careerIdentity.did }); + expect(web5Career).to.exist; + + // Instantiate a Web5 instance with the "Social" Identity, write a record, and verify the result. + const web5Social = new Web5({ agent: testAgent.agent, connectedDid: socialIdentity.did }); + expect(web5Social).to.exist; + }); + + it('Can write records using an Identity under management', async () => { + // Start agent for the first time. + await testAgent.agent.start({ passphrase: 'test' }); + + // Create two identities, each of which is stored in a new tenant. + const careerIdentity = await testAgent.agent.identityManager.create({ + name : 'Social', + didMethod : 'key', + kms : 'local' + }); + const socialIdentity = await testAgent.agent.identityManager.create({ + name : 'Social', + didMethod : 'key', + kms : 'local' + }); + + // Instantiate a Web5 instance with the "Career" Identity, write a record, and verify the result. + const web5Career = new Web5({ agent: testAgent.agent, connectedDid: careerIdentity.did }); + const careerResult = await web5Career.dwn.records.write({ + data : 'Hello, world!', + message : { + schema : 'foo/bar', + dataFormat : 'text/plain' + } + }); + expect(careerResult.status.code).to.equal(202); + expect(careerResult.record).to.exist; + expect(careerResult.record?.author).to.equal(careerIdentity.did); + expect(await careerResult.record?.data.text()).to.equal('Hello, world!'); + + // Instantiate a Web5 instance with the "Social" Identity, write a record, and verify the result. + const web5Social = new Web5({ agent: testAgent.agent, connectedDid: socialIdentity.did }); + const socialResult = await web5Social.dwn.records.write({ + data : 'Hello, everyone!', + message : { + schema : 'foo/bar', + dataFormat : 'text/plain' + } + }); + expect(socialResult.status.code).to.equal(202); + expect(socialResult.record).to.exist; + expect(socialResult.record?.author).to.equal(socialIdentity.did); + expect(await socialResult.record?.data.text()).to.equal('Hello, everyone!'); + }); + + }); + }); + }); +}); \ No newline at end of file diff --git a/packages/web5-user-agent/tests/tsconfig.json b/packages/identity-agent/tests/tsconfig.json similarity index 100% rename from packages/web5-user-agent/tests/tsconfig.json rename to packages/identity-agent/tests/tsconfig.json diff --git a/packages/common/tsconfig.cjs.json b/packages/identity-agent/tsconfig.cjs.json similarity index 100% rename from packages/common/tsconfig.cjs.json rename to packages/identity-agent/tsconfig.cjs.json diff --git a/packages/web5-user-agent/tsconfig.json b/packages/identity-agent/tsconfig.json similarity index 87% rename from packages/web5-user-agent/tsconfig.json rename to packages/identity-agent/tsconfig.json index 9627f3d42..b29e4e7e1 100644 --- a/packages/web5-user-agent/tsconfig.json +++ b/packages/identity-agent/tsconfig.json @@ -1,5 +1,6 @@ { "compilerOptions": { + "strict": true, "lib": [ "DOM", "ES6" @@ -11,12 +12,16 @@ "declarationMap": true, "declarationDir": "dist/types", "outDir": "dist/esm", + "sourceMap": true, // `NodeNext` will throw compilation errors if relative import paths are missing file extension // reference: https://devblogs.microsoft.com/typescript/announcing-typescript-4-7/#ecmascript-module-support-in-node-js "moduleResolution": "NodeNext", "esModuleInterop": true }, "include": [ - "src" + "src", + ], + "exclude": [ + "node_modules" ] } \ No newline at end of file diff --git a/packages/old/build/bundles.cjs b/packages/old/pre-polyrepo/build/bundles.cjs similarity index 100% rename from packages/old/build/bundles.cjs rename to packages/old/pre-polyrepo/build/bundles.cjs diff --git a/packages/old/build/esbuild-browser-config.cjs b/packages/old/pre-polyrepo/build/esbuild-browser-config.cjs similarity index 100% rename from packages/old/build/esbuild-browser-config.cjs rename to packages/old/pre-polyrepo/build/esbuild-browser-config.cjs diff --git a/packages/old/build/publish-unstable.sh b/packages/old/pre-polyrepo/build/publish-unstable.sh similarity index 100% rename from packages/old/build/publish-unstable.sh rename to packages/old/pre-polyrepo/build/publish-unstable.sh diff --git a/packages/old/examples/README.md b/packages/old/pre-polyrepo/examples/README.md similarity index 100% rename from packages/old/examples/README.md rename to packages/old/pre-polyrepo/examples/README.md diff --git a/packages/old/examples/simple-agent/.gitignore b/packages/old/pre-polyrepo/examples/simple-agent/.gitignore similarity index 100% rename from packages/old/examples/simple-agent/.gitignore rename to packages/old/pre-polyrepo/examples/simple-agent/.gitignore diff --git a/packages/old/examples/simple-agent/README.md b/packages/old/pre-polyrepo/examples/simple-agent/README.md similarity index 100% rename from packages/old/examples/simple-agent/README.md rename to packages/old/pre-polyrepo/examples/simple-agent/README.md diff --git a/packages/old/examples/simple-agent/etc/did.json b/packages/old/pre-polyrepo/examples/simple-agent/etc/did.json similarity index 100% rename from packages/old/examples/simple-agent/etc/did.json rename to packages/old/pre-polyrepo/examples/simple-agent/etc/did.json diff --git a/packages/old/examples/simple-agent/package-lock.json b/packages/old/pre-polyrepo/examples/simple-agent/package-lock.json similarity index 100% rename from packages/old/examples/simple-agent/package-lock.json rename to packages/old/pre-polyrepo/examples/simple-agent/package-lock.json diff --git a/packages/old/examples/simple-agent/package.json b/packages/old/pre-polyrepo/examples/simple-agent/package.json similarity index 100% rename from packages/old/examples/simple-agent/package.json rename to packages/old/pre-polyrepo/examples/simple-agent/package.json diff --git a/packages/old/examples/simple-agent/resources/test-protocol.json b/packages/old/pre-polyrepo/examples/simple-agent/resources/test-protocol.json similarity index 100% rename from packages/old/examples/simple-agent/resources/test-protocol.json rename to packages/old/pre-polyrepo/examples/simple-agent/resources/test-protocol.json diff --git a/packages/old/examples/simple-agent/src/index.js b/packages/old/pre-polyrepo/examples/simple-agent/src/index.js similarity index 100% rename from packages/old/examples/simple-agent/src/index.js rename to packages/old/pre-polyrepo/examples/simple-agent/src/index.js diff --git a/packages/old/examples/simple-agent/src/utils.js b/packages/old/pre-polyrepo/examples/simple-agent/src/utils.js similarity index 100% rename from packages/old/examples/simple-agent/src/utils.js rename to packages/old/pre-polyrepo/examples/simple-agent/src/utils.js diff --git a/packages/old/examples/test-dashboard/desktop-agent-original.html b/packages/old/pre-polyrepo/examples/test-dashboard/desktop-agent-original.html similarity index 100% rename from packages/old/examples/test-dashboard/desktop-agent-original.html rename to packages/old/pre-polyrepo/examples/test-dashboard/desktop-agent-original.html diff --git a/packages/old/examples/test-dashboard/desktop-agent.html b/packages/old/pre-polyrepo/examples/test-dashboard/desktop-agent.html similarity index 100% rename from packages/old/examples/test-dashboard/desktop-agent.html rename to packages/old/pre-polyrepo/examples/test-dashboard/desktop-agent.html diff --git a/packages/old/examples/test-dashboard/index.js b/packages/old/pre-polyrepo/examples/test-dashboard/index.js similarity index 100% rename from packages/old/examples/test-dashboard/index.js rename to packages/old/pre-polyrepo/examples/test-dashboard/index.js diff --git a/packages/old/examples/test-dashboard/package-lock.json b/packages/old/pre-polyrepo/examples/test-dashboard/package-lock.json similarity index 100% rename from packages/old/examples/test-dashboard/package-lock.json rename to packages/old/pre-polyrepo/examples/test-dashboard/package-lock.json diff --git a/packages/old/examples/test-dashboard/package.json b/packages/old/pre-polyrepo/examples/test-dashboard/package.json similarity index 100% rename from packages/old/examples/test-dashboard/package.json rename to packages/old/pre-polyrepo/examples/test-dashboard/package.json diff --git a/packages/old/examples/test-dashboard/simple-agent.html b/packages/old/pre-polyrepo/examples/test-dashboard/simple-agent.html similarity index 100% rename from packages/old/examples/test-dashboard/simple-agent.html rename to packages/old/pre-polyrepo/examples/test-dashboard/simple-agent.html diff --git a/packages/old/jsdoc.json b/packages/old/pre-polyrepo/jsdoc.json similarity index 100% rename from packages/old/jsdoc.json rename to packages/old/pre-polyrepo/jsdoc.json diff --git a/packages/old/karma.conf.cjs b/packages/old/pre-polyrepo/karma.conf.cjs similarity index 100% rename from packages/old/karma.conf.cjs rename to packages/old/pre-polyrepo/karma.conf.cjs diff --git a/packages/old/package-lock.json b/packages/old/pre-polyrepo/package-lock.json similarity index 100% rename from packages/old/package-lock.json rename to packages/old/pre-polyrepo/package-lock.json diff --git a/packages/old/package.json b/packages/old/pre-polyrepo/package.json similarity index 100% rename from packages/old/package.json rename to packages/old/pre-polyrepo/package.json diff --git a/packages/old/src/did/connect/connect.js b/packages/old/pre-polyrepo/src/did/connect/connect.js similarity index 100% rename from packages/old/src/did/connect/connect.js rename to packages/old/pre-polyrepo/src/did/connect/connect.js diff --git a/packages/old/src/did/connect/utils.js b/packages/old/pre-polyrepo/src/did/connect/utils.js similarity index 100% rename from packages/old/src/did/connect/utils.js rename to packages/old/pre-polyrepo/src/did/connect/utils.js diff --git a/packages/old/src/did/connect/ws-client.js b/packages/old/pre-polyrepo/src/did/connect/ws-client.js similarity index 100% rename from packages/old/src/did/connect/ws-client.js rename to packages/old/pre-polyrepo/src/did/connect/ws-client.js diff --git a/packages/old/src/did/crypto/ciphers.js b/packages/old/pre-polyrepo/src/did/crypto/ciphers.js similarity index 100% rename from packages/old/src/did/crypto/ciphers.js rename to packages/old/pre-polyrepo/src/did/crypto/ciphers.js diff --git a/packages/old/src/did/crypto/x25519-xsalsa20-poly1305.js b/packages/old/pre-polyrepo/src/did/crypto/x25519-xsalsa20-poly1305.js similarity index 100% rename from packages/old/src/did/crypto/x25519-xsalsa20-poly1305.js rename to packages/old/pre-polyrepo/src/did/crypto/x25519-xsalsa20-poly1305.js diff --git a/packages/old/src/did/manager.js b/packages/old/pre-polyrepo/src/did/manager.js similarity index 100% rename from packages/old/src/did/manager.js rename to packages/old/pre-polyrepo/src/did/manager.js diff --git a/packages/old/src/did/methods/ion.js b/packages/old/pre-polyrepo/src/did/methods/ion.js similarity index 100% rename from packages/old/src/did/methods/ion.js rename to packages/old/pre-polyrepo/src/did/methods/ion.js diff --git a/packages/old/src/did/methods/key.js b/packages/old/pre-polyrepo/src/did/methods/key.js similarity index 100% rename from packages/old/src/did/methods/key.js rename to packages/old/pre-polyrepo/src/did/methods/key.js diff --git a/packages/old/src/did/methods/methods.js b/packages/old/pre-polyrepo/src/did/methods/methods.js similarity index 100% rename from packages/old/src/did/methods/methods.js rename to packages/old/pre-polyrepo/src/did/methods/methods.js diff --git a/packages/old/src/did/utils.js b/packages/old/pre-polyrepo/src/did/utils.js similarity index 100% rename from packages/old/src/did/utils.js rename to packages/old/pre-polyrepo/src/did/utils.js diff --git a/packages/old/src/did/web5-did.js b/packages/old/pre-polyrepo/src/did/web5-did.js similarity index 100% rename from packages/old/src/did/web5-did.js rename to packages/old/pre-polyrepo/src/did/web5-did.js diff --git a/packages/old/src/dwn/dwn-utils.js b/packages/old/pre-polyrepo/src/dwn/dwn-utils.js similarity index 100% rename from packages/old/src/dwn/dwn-utils.js rename to packages/old/pre-polyrepo/src/dwn/dwn-utils.js diff --git a/packages/old/src/dwn/interfaces/interface.js b/packages/old/pre-polyrepo/src/dwn/interfaces/interface.js similarity index 100% rename from packages/old/src/dwn/interfaces/interface.js rename to packages/old/pre-polyrepo/src/dwn/interfaces/interface.js diff --git a/packages/old/src/dwn/interfaces/permissions.js b/packages/old/pre-polyrepo/src/dwn/interfaces/permissions.js similarity index 100% rename from packages/old/src/dwn/interfaces/permissions.js rename to packages/old/pre-polyrepo/src/dwn/interfaces/permissions.js diff --git a/packages/old/src/dwn/interfaces/protocols.js b/packages/old/pre-polyrepo/src/dwn/interfaces/protocols.js similarity index 100% rename from packages/old/src/dwn/interfaces/protocols.js rename to packages/old/pre-polyrepo/src/dwn/interfaces/protocols.js diff --git a/packages/old/src/dwn/interfaces/records.js b/packages/old/pre-polyrepo/src/dwn/interfaces/records.js similarity index 100% rename from packages/old/src/dwn/interfaces/records.js rename to packages/old/pre-polyrepo/src/dwn/interfaces/records.js diff --git a/packages/old/src/dwn/models/record.js b/packages/old/pre-polyrepo/src/dwn/models/record.js similarity index 100% rename from packages/old/src/dwn/models/record.js rename to packages/old/pre-polyrepo/src/dwn/models/record.js diff --git a/packages/old/src/dwn/web5-dwn.js b/packages/old/pre-polyrepo/src/dwn/web5-dwn.js similarity index 100% rename from packages/old/src/dwn/web5-dwn.js rename to packages/old/pre-polyrepo/src/dwn/web5-dwn.js diff --git a/packages/old/src/main.js b/packages/old/pre-polyrepo/src/main.js similarity index 100% rename from packages/old/src/main.js rename to packages/old/pre-polyrepo/src/main.js diff --git a/packages/old/src/storage/local-storage.js b/packages/old/pre-polyrepo/src/storage/local-storage.js similarity index 100% rename from packages/old/src/storage/local-storage.js rename to packages/old/pre-polyrepo/src/storage/local-storage.js diff --git a/packages/old/src/storage/memory-storage.js b/packages/old/pre-polyrepo/src/storage/memory-storage.js similarity index 100% rename from packages/old/src/storage/memory-storage.js rename to packages/old/pre-polyrepo/src/storage/memory-storage.js diff --git a/packages/old/src/storage/storage.js b/packages/old/pre-polyrepo/src/storage/storage.js similarity index 100% rename from packages/old/src/storage/storage.js rename to packages/old/pre-polyrepo/src/storage/storage.js diff --git a/packages/old/src/transport/app-transport.js b/packages/old/pre-polyrepo/src/transport/app-transport.js similarity index 100% rename from packages/old/src/transport/app-transport.js rename to packages/old/pre-polyrepo/src/transport/app-transport.js diff --git a/packages/old/src/transport/http-transport.js b/packages/old/pre-polyrepo/src/transport/http-transport.js similarity index 100% rename from packages/old/src/transport/http-transport.js rename to packages/old/pre-polyrepo/src/transport/http-transport.js diff --git a/packages/old/src/transport/transport.js b/packages/old/pre-polyrepo/src/transport/transport.js similarity index 100% rename from packages/old/src/transport/transport.js rename to packages/old/pre-polyrepo/src/transport/transport.js diff --git a/packages/old/src/types.js b/packages/old/pre-polyrepo/src/types.js similarity index 100% rename from packages/old/src/types.js rename to packages/old/pre-polyrepo/src/types.js diff --git a/packages/old/src/utils.js b/packages/old/pre-polyrepo/src/utils.js similarity index 100% rename from packages/old/src/utils.js rename to packages/old/pre-polyrepo/src/utils.js diff --git a/packages/old/src/web5.js b/packages/old/pre-polyrepo/src/web5.js similarity index 100% rename from packages/old/src/web5.js rename to packages/old/pre-polyrepo/src/web5.js diff --git a/packages/old/tests/did/manager.spec.js b/packages/old/pre-polyrepo/tests/did/manager.spec.js similarity index 100% rename from packages/old/tests/did/manager.spec.js rename to packages/old/pre-polyrepo/tests/did/manager.spec.js diff --git a/packages/old/tests/did/methods/ion.spec.js b/packages/old/pre-polyrepo/tests/did/methods/ion.spec.js similarity index 100% rename from packages/old/tests/did/methods/ion.spec.js rename to packages/old/pre-polyrepo/tests/did/methods/ion.spec.js diff --git a/packages/old/tests/did/methods/key.spec.js b/packages/old/pre-polyrepo/tests/did/methods/key.spec.js similarity index 100% rename from packages/old/tests/did/methods/key.spec.js rename to packages/old/pre-polyrepo/tests/did/methods/key.spec.js diff --git a/packages/old/tests/did/utils.spec.js b/packages/old/pre-polyrepo/tests/did/utils.spec.js similarity index 100% rename from packages/old/tests/did/utils.spec.js rename to packages/old/pre-polyrepo/tests/did/utils.spec.js diff --git a/packages/old/tests/did/web5-did.spec.js b/packages/old/pre-polyrepo/tests/did/web5-did.spec.js similarity index 100% rename from packages/old/tests/did/web5-did.spec.js rename to packages/old/pre-polyrepo/tests/did/web5-did.spec.js diff --git a/packages/old/tests/dwn/interfaces/records.spec.js b/packages/old/pre-polyrepo/tests/dwn/interfaces/records.spec.js similarity index 100% rename from packages/old/tests/dwn/interfaces/records.spec.js rename to packages/old/pre-polyrepo/tests/dwn/interfaces/records.spec.js diff --git a/packages/old/tests/dwn/models/record.spec.js b/packages/old/pre-polyrepo/tests/dwn/models/record.spec.js similarity index 100% rename from packages/old/tests/dwn/models/record.spec.js rename to packages/old/pre-polyrepo/tests/dwn/models/record.spec.js diff --git a/packages/old/tests/fixtures/did-documents.js b/packages/old/pre-polyrepo/tests/fixtures/did-documents.js similarity index 100% rename from packages/old/tests/fixtures/did-documents.js rename to packages/old/pre-polyrepo/tests/fixtures/did-documents.js diff --git a/packages/old/tests/storage/memory-storage.spec.js b/packages/old/pre-polyrepo/tests/storage/memory-storage.spec.js similarity index 100% rename from packages/old/tests/storage/memory-storage.spec.js rename to packages/old/pre-polyrepo/tests/storage/memory-storage.spec.js diff --git a/packages/old/tests/test-utils/promises.js b/packages/old/pre-polyrepo/tests/test-utils/promises.js similarity index 100% rename from packages/old/tests/test-utils/promises.js rename to packages/old/pre-polyrepo/tests/test-utils/promises.js diff --git a/packages/old/tests/test-utils/test-data-generator.js b/packages/old/pre-polyrepo/tests/test-utils/test-data-generator.js similarity index 100% rename from packages/old/tests/test-utils/test-data-generator.js rename to packages/old/pre-polyrepo/tests/test-utils/test-data-generator.js diff --git a/packages/old/tests/test-utils/test-dwn.js b/packages/old/pre-polyrepo/tests/test-utils/test-dwn.js similarity index 100% rename from packages/old/tests/test-utils/test-dwn.js rename to packages/old/pre-polyrepo/tests/test-utils/test-dwn.js diff --git a/packages/old/tests/utils.spec.js b/packages/old/pre-polyrepo/tests/utils.spec.js similarity index 100% rename from packages/old/tests/utils.spec.js rename to packages/old/pre-polyrepo/tests/utils.spec.js diff --git a/packages/web5-user-agent/.c8rc.json b/packages/old/web5-agent/.c8rc.json similarity index 50% rename from packages/web5-user-agent/.c8rc.json rename to packages/old/web5-agent/.c8rc.json index 9763ced85..0d483c700 100644 --- a/packages/web5-user-agent/.c8rc.json +++ b/packages/old/web5-agent/.c8rc.json @@ -5,13 +5,11 @@ ".js" ], "include": [ - "tests/compiled/**" + "__tests__/src/**" ], "exclude": [ - "tests/compiled/tests/**", - "tests/compiled/src/main.js", - "tests/compiled/src/types/**", - "tests/compiled/types/**" + "__tests__/src/main.js", + "__tests__/types/**" ], "reporter": [ "cobertura", diff --git a/packages/old/web5-agent/.mocharc.json b/packages/old/web5-agent/.mocharc.json new file mode 100644 index 000000000..c223f40c7 --- /dev/null +++ b/packages/old/web5-agent/.mocharc.json @@ -0,0 +1,5 @@ +{ + "enable-source-maps": true, + "exit": true, + "spec": ["__tests__/**/*.spec.js"] + } \ No newline at end of file diff --git a/packages/old/web5-agent/.vscode/launch.json b/packages/old/web5-agent/.vscode/launch.json new file mode 100644 index 000000000..427bc2237 --- /dev/null +++ b/packages/old/web5-agent/.vscode/launch.json @@ -0,0 +1,22 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "test:node", + "runtimeExecutable": "${workspaceFolder:root}/node_modules/.bin/mocha", + "runtimeArgs": [ + "${workspaceFolder:web5-agent}/__tests__/**/*.spec.js" + ], + "console": "internalConsole", + "preLaunchTask": "tsc: build - tsconfig.test.json", + "outFiles": [ + "${workspaceFolder:web5-agent}/__tests__/**/*.js" + ], + } + ] +} \ No newline at end of file diff --git a/packages/old/web5-agent/.vscode/tasks.json b/packages/old/web5-agent/.vscode/tasks.json new file mode 100644 index 000000000..a6d959d04 --- /dev/null +++ b/packages/old/web5-agent/.vscode/tasks.json @@ -0,0 +1,45 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "npm run build", + "type": "npm", + "script": "build", + "problemMatcher": [], + "group": { + "kind": "build", + "isDefault": true + } + }, + { + "label": "tsc: build - tsconfig.json", + "type": "typescript", + "tsconfig": "tsconfig.json", + "problemMatcher": [ + "$tsc" + ], + "group": { + "kind": "build", + "isDefault": false + }, + "options": { + "cwd": "${workspaceFolder:root}" + } + }, + { + "label": "tsc: build - tsconfig.test.json", + "type": "typescript", + "tsconfig": "tsconfig.test.json", + "problemMatcher": [ + "$tsc" + ], + "group": { + "kind": "build", + "isDefault": false + }, + "options": { + "cwd": "${workspaceFolder:root}" + } + }, + ] +} \ No newline at end of file diff --git a/packages/web5-proxy-agent/LICENSE b/packages/old/web5-agent/LICENSE similarity index 100% rename from packages/web5-proxy-agent/LICENSE rename to packages/old/web5-agent/LICENSE diff --git a/packages/web5-agent/README.md b/packages/old/web5-agent/README.md similarity index 100% rename from packages/web5-agent/README.md rename to packages/old/web5-agent/README.md diff --git a/packages/old/web5-agent/build/bundles.js b/packages/old/web5-agent/build/bundles.js new file mode 100644 index 000000000..b1041cc61 --- /dev/null +++ b/packages/old/web5-agent/build/bundles.js @@ -0,0 +1,55 @@ +import esbuild from 'esbuild'; +import browserConfig from './esbuild-browser-config.cjs'; + +// cjs bundle for Electron apps. external dependencies bundled except LevelDB +// Remove if/when the following PR is merged and this bundle is no longer needed by Electron apps +// https://github.com/electron/electron/pull/37535 +esbuild.buildSync({ + platform : 'node', + bundle : true, + format : 'cjs', + // packages: 'external', + external : ['level'], + sourcemap : true, + entryPoints : ['./src/main.ts'], + outfile : './dist/electron/main.cjs', + allowOverwrite : true, +}); + +// cjs bundle. external dependencies **not** bundled +esbuild.buildSync({ + platform : 'node', + bundle : true, + format : 'cjs', + packages : 'external', + sourcemap : true, + entryPoints : ['./src/main.ts'], + outfile : './dist/cjs/main.cjs', + allowOverwrite : true, +}); + +// esm bundle. external dependencies **not** bundled +esbuild.buildSync({ + platform : 'node', + bundle : true, + format : 'esm', + packages : 'external', + sourcemap : true, + entryPoints : ['./src/main.ts'], + outfile : './dist/esm/main.mjs', + allowOverwrite : true, +}); + +// esm polyfilled bundle for browser +esbuild.build({ + ...browserConfig, + outfile: 'dist/browser.mjs', +}); + +// iife polyfilled bundle for browser +esbuild.build({ + ...browserConfig, + format : 'iife', + globalName : 'Web5', + outfile : 'dist/browser.js', +}); \ No newline at end of file diff --git a/packages/old/web5-agent/build/esbuild-browser-config.cjs b/packages/old/web5-agent/build/esbuild-browser-config.cjs new file mode 100644 index 000000000..4ef8cf1d8 --- /dev/null +++ b/packages/old/web5-agent/build/esbuild-browser-config.cjs @@ -0,0 +1,19 @@ +/* eslint-disable @typescript-eslint/no-var-requires */ +const polyfillProviderPlugin = require('node-stdlib-browser/helpers/esbuild/plugin'); +const stdLibBrowser = require('node-stdlib-browser'); + +/** @type {import('esbuild').BuildOptions} */ +module.exports = { + entryPoints : ['./src/main.ts'], + bundle : true, + format : 'esm', + sourcemap : true, + minify : true, + platform : 'browser', + target : ['chrome101', 'firefox108', 'safari16'], + inject : [require.resolve('node-stdlib-browser/helpers/esbuild/shim')], + plugins : [polyfillProviderPlugin(stdLibBrowser)], + define : { + 'global': 'globalThis', + }, +}; diff --git a/packages/web5-agent/karma.conf.cjs b/packages/old/web5-agent/karma.conf.cjs similarity index 100% rename from packages/web5-agent/karma.conf.cjs rename to packages/old/web5-agent/karma.conf.cjs diff --git a/packages/old/web5-agent/package.json b/packages/old/web5-agent/package.json new file mode 100644 index 000000000..2c4fda446 --- /dev/null +++ b/packages/old/web5-agent/package.json @@ -0,0 +1,117 @@ +{ + "name": "@tbd54566975/web5-agent", + "version": "0.1.7", + "description": "Web5 Agent", + "type": "module", + "main": "./dist/cjs/main.cjs", + "module": "./dist/esm/main.mjs", + "types": "./dist/types/main.d.ts", + "scripts": { + "build": "rimraf dist && node build/bundles.js && echo '{\"type\": \"commonjs\"}' > ./dist/cjs/package.json && tsc", + "lint": "eslint . --ext .ts --max-warnings 0", + "lint:fix": "eslint . --ext .ts --fix", + "test:node": "rimraf __tests__ && tsc -p tsconfig.test.json && c8 mocha", + "test:browser": "karma start karma.conf.cjs" + }, + "homepage": "https://github.com/TBD54566975/web5-js/tree/main/packages/web5-agent#readme", + "bugs": "https://github.com/TBD54566975/web5-js/issues", + "repository": { + "type": "git", + "url": "git+https://github.com/TBD54566975/web5-js", + "directory": "packages/web5-agent" + }, + "license": "Apache-2.0", + "contributors": [ + { + "name": "Daniel Buchner", + "url": "https://github.com/csuwildcat" + }, + { + "name": "Frank Hinek", + "url": "https://github.com/frankhinek" + }, + { + "name": "Moe Jangda", + "url": "https://github.com/mistermoe" + } + ], + "files": [ + "dist", + "src" + ], + "exports": { + ".": { + "import": "./dist/esm/main.mjs", + "require": "./dist/cjs/main.cjs", + "types": "./dist/types/main.d.ts" + }, + "./browser": { + "import": "./dist/browser.mjs", + "require": "./dist/browser.js", + "types": "./dist/types/main.d.ts" + }, + "./electron": { + "import": "./dist/esm/main.mjs", + "require": "./dist/electron/main.cjs", + "types": "./dist/types/main.d.ts" + } + }, + "browser": { + "./dist/esm/main.mjs": "./dist/browser.mjs", + "./dist/cjs/main.cjs": "./dist/browser.js", + "types": "./dist/types/main.d.ts" + }, + "react-native": { + "./dist/esm/main.mjs": "./dist/esm/main.mjs", + "./dist/cjs/main.cjs": "./dist/esm/main.mjs", + "types": "./dist/types/main.d.ts" + }, + "keywords": [ + "decentralized", + "decentralized-applications", + "decentralized-identity", + "decentralized-web", + "web5" + ], + "publishConfig": { + "access": "public" + }, + "engines": { + "node": ">=18.0.0" + }, + "dependencies": { + "readable-stream": "4.4.0", + "@tbd54566975/dwn-sdk-js": "0.0.37" + }, + "devDependencies": { + "@playwright/test": "1.34.3", + "@types/chai": "4.3.0", + "@types/chai-as-promised": "7.1.5", + "@types/eslint": "8.37.0", + "@types/mocha": "10.0.1", + "@types/readable-stream": "2.3.15", + "@types/sinon": "10.0.15", + "@typescript-eslint/eslint-plugin": "5.59.0", + "@typescript-eslint/parser": "5.59.0", + "c8": "8.0.0", + "chai": "4.3.7", + "chai-as-promised": "7.1.1", + "esbuild": "0.16.17", + "eslint": "8.39.0", + "eslint-plugin-mocha": "10.1.0", + "karma": "6.4.1", + "karma-chai": "0.1.0", + "karma-chrome-launcher": "3.1.1", + "karma-esbuild": "2.2.5", + "karma-firefox-launcher": "2.1.2", + "karma-mocha": "2.0.1", + "karma-mocha-reporter": "2.2.5", + "karma-webkit-launcher": "2.1.0", + "mocha": "10.2.0", + "node-stdlib-browser": "1.2.0", + "rimraf": "4.4.0", + "sinon": "15.0.2", + "source-map-loader": "4.0.1", + "typescript": "5.0.4" + } +} \ No newline at end of file diff --git a/packages/old/web5-agent/src/json-rpc.ts b/packages/old/web5-agent/src/json-rpc.ts new file mode 100644 index 000000000..14623fa57 --- /dev/null +++ b/packages/old/web5-agent/src/json-rpc.ts @@ -0,0 +1,107 @@ +export type JsonRpcId = string | number | null; +export type JsonRpcParams = any; +export type JsonRpcVersion = '2.0'; + +export interface JsonRpcRequest { + jsonrpc: JsonRpcVersion; + id?: JsonRpcId; + method: string; + params?: any; +} + +export interface JsonRpcError { + code: JsonRpcErrorCodes; + message: string; + data?: any; +} + +export enum JsonRpcErrorCodes { + // JSON-RPC 2.0 pre-defined errors + InvalidRequest = -32600, + MethodNotFound = -32601, + InvalidParams = -32602, + InternalError = -32603, + ParseError = -32700, + TransportError = -32300, + + // App defined errors + BadRequest = -50400, // equivalent to HTTP Status 400 + Unauthorized = -50401, // equivalent to HTTP Status 401 + Forbidden = -50403, // equivalent to HTTP Status 403 +} + +export type JsonRpcResponse = JsonRpcSuccessResponse | JsonRpcErrorResponse; + +export interface JsonRpcSuccessResponse { + jsonrpc: JsonRpcVersion; + id: JsonRpcId; + result: any; + error?: never; +} + +export interface JsonRpcErrorResponse { + jsonrpc: JsonRpcVersion; + id: JsonRpcId; + result?: never; + error: JsonRpcError; +} + +export const createJsonRpcErrorResponse = ( + id: JsonRpcId, + code: JsonRpcErrorCodes, + message: string, + data?: any, +): JsonRpcErrorResponse => { + const error: JsonRpcError = { code, message }; + if (data != undefined) { + error.data = data; + } + return { + jsonrpc: '2.0', + id, + error, + }; +}; + +export const createJsonRpcNotification = ( + method: string, + params?: JsonRpcParams, +): JsonRpcRequest => { + return { + jsonrpc: '2.0', + method, + params, + }; +}; + +export const createJsonRpcRequest = ( + id: JsonRpcId, + method: string, + params?: JsonRpcParams, +): JsonRpcRequest => { + return { + jsonrpc: '2.0', + id, + method, + params, + }; +}; + +export const createJsonRpcSuccessResponse = ( + id: JsonRpcId, + result?: any, +): JsonRpcSuccessResponse => { + return { + jsonrpc : '2.0', + id, + result : result ?? null, + }; +}; + +export function parseJson(text: string): object | null { + try { + return JSON.parse(text); + } catch { + return null; + } +} \ No newline at end of file diff --git a/packages/web5-agent/src/main.ts b/packages/old/web5-agent/src/main.ts similarity index 100% rename from packages/web5-agent/src/main.ts rename to packages/old/web5-agent/src/main.ts diff --git a/packages/web5-agent/src/query-store.ts b/packages/old/web5-agent/src/query-store.ts similarity index 100% rename from packages/web5-agent/src/query-store.ts rename to packages/old/web5-agent/src/query-store.ts diff --git a/packages/web5-agent/src/web5-agent.ts b/packages/old/web5-agent/src/web5-agent.ts similarity index 99% rename from packages/web5-agent/src/web5-agent.ts rename to packages/old/web5-agent/src/web5-agent.ts index 6297e376b..b1d1f8f6b 100644 --- a/packages/web5-agent/src/web5-agent.ts +++ b/packages/old/web5-agent/src/web5-agent.ts @@ -1,6 +1,6 @@ import type { Readable } from 'readable-stream'; -import type { +import { EventsGetMessage, UnionMessageReply, MessagesGetMessage, diff --git a/packages/web5-agent/tests/needed.spec.ts b/packages/old/web5-agent/tests/needed.spec.ts similarity index 100% rename from packages/web5-agent/tests/needed.spec.ts rename to packages/old/web5-agent/tests/needed.spec.ts diff --git a/packages/old/web5-agent/tsconfig.json b/packages/old/web5-agent/tsconfig.json new file mode 100644 index 000000000..b63536fdd --- /dev/null +++ b/packages/old/web5-agent/tsconfig.json @@ -0,0 +1,28 @@ +{ + "compilerOptions": { + "strict": true, + "lib": [ + "DOM", + "ES6" + ], + "allowJs": true, + "target": "es6", + "module": "ESNext", // Required for enabling JavaScript import assertion support + "declaration": true, + "declarationMap": true, + "emitDeclarationOnly": true, + "declarationDir": "dist/types", + "sourceMap": true, + // `NodeNext` will throw compilation errors if relative import paths are missing file extension + // reference: https://devblogs.microsoft.com/typescript/announcing-typescript-4-7/#ecmascript-module-support-in-node-js + "moduleResolution": "NodeNext", + "esModuleInterop": true + }, + "include": [ + "src", + ], + "exclude": [ + "node_modules", + "dist" + ] +} \ No newline at end of file diff --git a/packages/old/web5-agent/tsconfig.test.json b/packages/old/web5-agent/tsconfig.test.json new file mode 100644 index 000000000..7e40c3908 --- /dev/null +++ b/packages/old/web5-agent/tsconfig.test.json @@ -0,0 +1,29 @@ +{ + "compilerOptions": { + "lib": [ + "DOM", + "ES6" + ], + "target": "es6", + "module": "ESNext", // Required for enabling JavaScript import assertion support + "declaration": true, + "declarationMap": true, + "outDir": "__tests__", + "declarationDir": "__tests__/types", + "sourceMap": true, + // `NodeNext` will throw compilation errors if relative import paths are missing file extension + // reference: https://devblogs.microsoft.com/typescript/announcing-typescript-4-7/#ecmascript-module-support-in-node-js + "moduleResolution": "NodeNext", + // allows us to import json files + "resolveJsonModule": true, + "esModuleInterop": true + }, + "include": [ + "src", + "tests", + ], + "exclude": [ + "node_modules", + "dist" + ] +} \ No newline at end of file diff --git a/packages/old/web5-proxy-agent/.c8rc.json b/packages/old/web5-proxy-agent/.c8rc.json new file mode 100644 index 000000000..0d483c700 --- /dev/null +++ b/packages/old/web5-proxy-agent/.c8rc.json @@ -0,0 +1,18 @@ +{ + "all": true, + "cache": false, + "extension": [ + ".js" + ], + "include": [ + "__tests__/src/**" + ], + "exclude": [ + "__tests__/src/main.js", + "__tests__/types/**" + ], + "reporter": [ + "cobertura", + "text" + ] +} \ No newline at end of file diff --git a/packages/old/web5-proxy-agent/.mocharc.json b/packages/old/web5-proxy-agent/.mocharc.json new file mode 100644 index 000000000..c223f40c7 --- /dev/null +++ b/packages/old/web5-proxy-agent/.mocharc.json @@ -0,0 +1,5 @@ +{ + "enable-source-maps": true, + "exit": true, + "spec": ["__tests__/**/*.spec.js"] + } \ No newline at end of file diff --git a/packages/old/web5-proxy-agent/.vscode/launch.json b/packages/old/web5-proxy-agent/.vscode/launch.json new file mode 100644 index 000000000..4f8f247d2 --- /dev/null +++ b/packages/old/web5-proxy-agent/.vscode/launch.json @@ -0,0 +1,22 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "test:node", + "runtimeExecutable": "${workspaceFolder:root}/node_modules/.bin/mocha", + "runtimeArgs": [ + "${workspaceFolder:web5-proxy-agent}/__tests__/**/*.spec.js" + ], + "console": "internalConsole", + "preLaunchTask": "tsc: build - tsconfig.test.json", + "outFiles": [ + "${workspaceFolder:web5-proxy-agent}/__tests__/**/*.js" + ], + } + ] +} \ No newline at end of file diff --git a/packages/old/web5-proxy-agent/.vscode/tasks.json b/packages/old/web5-proxy-agent/.vscode/tasks.json new file mode 100644 index 000000000..a6d959d04 --- /dev/null +++ b/packages/old/web5-proxy-agent/.vscode/tasks.json @@ -0,0 +1,45 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "npm run build", + "type": "npm", + "script": "build", + "problemMatcher": [], + "group": { + "kind": "build", + "isDefault": true + } + }, + { + "label": "tsc: build - tsconfig.json", + "type": "typescript", + "tsconfig": "tsconfig.json", + "problemMatcher": [ + "$tsc" + ], + "group": { + "kind": "build", + "isDefault": false + }, + "options": { + "cwd": "${workspaceFolder:root}" + } + }, + { + "label": "tsc: build - tsconfig.test.json", + "type": "typescript", + "tsconfig": "tsconfig.test.json", + "problemMatcher": [ + "$tsc" + ], + "group": { + "kind": "build", + "isDefault": false + }, + "options": { + "cwd": "${workspaceFolder:root}" + } + }, + ] +} \ No newline at end of file diff --git a/packages/web5-user-agent/LICENSE b/packages/old/web5-proxy-agent/LICENSE similarity index 100% rename from packages/web5-user-agent/LICENSE rename to packages/old/web5-proxy-agent/LICENSE diff --git a/packages/web5-proxy-agent/README.md b/packages/old/web5-proxy-agent/README.md similarity index 100% rename from packages/web5-proxy-agent/README.md rename to packages/old/web5-proxy-agent/README.md diff --git a/packages/old/web5-proxy-agent/build/bundles.js b/packages/old/web5-proxy-agent/build/bundles.js new file mode 100644 index 000000000..b1041cc61 --- /dev/null +++ b/packages/old/web5-proxy-agent/build/bundles.js @@ -0,0 +1,55 @@ +import esbuild from 'esbuild'; +import browserConfig from './esbuild-browser-config.cjs'; + +// cjs bundle for Electron apps. external dependencies bundled except LevelDB +// Remove if/when the following PR is merged and this bundle is no longer needed by Electron apps +// https://github.com/electron/electron/pull/37535 +esbuild.buildSync({ + platform : 'node', + bundle : true, + format : 'cjs', + // packages: 'external', + external : ['level'], + sourcemap : true, + entryPoints : ['./src/main.ts'], + outfile : './dist/electron/main.cjs', + allowOverwrite : true, +}); + +// cjs bundle. external dependencies **not** bundled +esbuild.buildSync({ + platform : 'node', + bundle : true, + format : 'cjs', + packages : 'external', + sourcemap : true, + entryPoints : ['./src/main.ts'], + outfile : './dist/cjs/main.cjs', + allowOverwrite : true, +}); + +// esm bundle. external dependencies **not** bundled +esbuild.buildSync({ + platform : 'node', + bundle : true, + format : 'esm', + packages : 'external', + sourcemap : true, + entryPoints : ['./src/main.ts'], + outfile : './dist/esm/main.mjs', + allowOverwrite : true, +}); + +// esm polyfilled bundle for browser +esbuild.build({ + ...browserConfig, + outfile: 'dist/browser.mjs', +}); + +// iife polyfilled bundle for browser +esbuild.build({ + ...browserConfig, + format : 'iife', + globalName : 'Web5', + outfile : 'dist/browser.js', +}); \ No newline at end of file diff --git a/packages/web5-proxy-agent/build/esbuild-browser-config.cjs b/packages/old/web5-proxy-agent/build/esbuild-browser-config.cjs similarity index 54% rename from packages/web5-proxy-agent/build/esbuild-browser-config.cjs rename to packages/old/web5-proxy-agent/build/esbuild-browser-config.cjs index ae37c97f0..52f2f347c 100644 --- a/packages/web5-proxy-agent/build/esbuild-browser-config.cjs +++ b/packages/old/web5-proxy-agent/build/esbuild-browser-config.cjs @@ -1,3 +1,6 @@ +const polyfillProviderPlugin = require('node-stdlib-browser/helpers/esbuild/plugin'); +const stdLibBrowser = require('node-stdlib-browser'); + /** @type {import('esbuild').BuildOptions} */ module.exports = { entryPoints : ['./src/main.ts'], @@ -7,6 +10,8 @@ module.exports = { minify : true, platform : 'browser', target : ['chrome101', 'firefox108', 'safari16'], + inject : [require.resolve('node-stdlib-browser/helpers/esbuild/shim')], + plugins : [polyfillProviderPlugin(stdLibBrowser)], define : { 'global': 'globalThis', }, diff --git a/packages/web5-proxy-agent/karma.conf.cjs b/packages/old/web5-proxy-agent/karma.conf.cjs similarity index 100% rename from packages/web5-proxy-agent/karma.conf.cjs rename to packages/old/web5-proxy-agent/karma.conf.cjs diff --git a/packages/old/web5-proxy-agent/package.json b/packages/old/web5-proxy-agent/package.json new file mode 100644 index 000000000..768c75034 --- /dev/null +++ b/packages/old/web5-proxy-agent/package.json @@ -0,0 +1,116 @@ +{ + "name": "@tbd54566975/web5-proxy-agent", + "version": "0.1.7", + "description": "Web5 Proxy Agent", + "type": "module", + "main": "./dist/cjs/main.cjs", + "module": "./dist/esm/main.mjs", + "types": "./dist/types/main.d.ts", + "scripts": { + "build": "rimraf dist && node build/bundles.js && echo '{\"type\": \"commonjs\"}' > ./dist/cjs/package.json && tsc", + "lint": "eslint . --ext .ts --max-warnings 0", + "lint:fix": "eslint . --ext .ts --fix", + "test:node": "rimraf __tests__ && tsc -p tsconfig.test.json && c8 mocha", + "test:browser": "karma start karma.conf.cjs" + }, + "homepage": "https://github.com/TBD54566975/web5-js/tree/main/packages/web5-proxy-agent#readme", + "bugs": "https://github.com/TBD54566975/web5-js/issues", + "repository": { + "type": "git", + "url": "git+https://github.com/TBD54566975/web5-js", + "directory": "packages/web5-proxy-agent" + }, + "license": "Apache-2.0", + "contributors": [ + { + "name": "Daniel Buchner", + "url": "https://github.com/csuwildcat" + }, + { + "name": "Frank Hinek", + "url": "https://github.com/frankhinek" + }, + { + "name": "Moe Jangda", + "url": "https://github.com/mistermoe" + } + ], + "files": [ + "dist", + "src" + ], + "exports": { + ".": { + "import": "./dist/esm/main.mjs", + "require": "./dist/cjs/main.cjs", + "types": "./dist/types/main.d.ts" + }, + "./browser": { + "import": "./dist/browser.mjs", + "require": "./dist/browser.js", + "types": "./dist/types/main.d.ts" + }, + "./electron": { + "import": "./dist/esm/main.mjs", + "require": "./dist/electron/main.cjs", + "types": "./dist/types/main.d.ts" + } + }, + "browser": { + "./dist/esm/main.mjs": "./dist/browser.mjs", + "./dist/cjs/main.cjs": "./dist/browser.js", + "types": "./dist/types/main.d.ts" + }, + "react-native": { + "./dist/esm/main.mjs": "./dist/esm/main.mjs", + "./dist/cjs/main.cjs": "./dist/esm/main.mjs", + "types": "./dist/types/main.d.ts" + }, + "keywords": [ + "decentralized", + "decentralized-applications", + "decentralized-identity", + "decentralized-web", + "web5" + ], + "publishConfig": { + "access": "public" + }, + "engines": { + "node": ">=18.0.0" + }, + "dependencies": { + "@tbd54566975/web5-agent": "0.1.7" + }, + "devDependencies": { + "@playwright/test": "1.34.3", + "@types/chai": "4.3.0", + "@types/chai-as-promised": "7.1.5", + "@types/ed2curve": "0.2.2", + "@types/eslint": "8.37.0", + "@types/mocha": "10.0.1", + "@types/sinon": "10.0.15", + "@typescript-eslint/eslint-plugin": "5.59.0", + "@typescript-eslint/parser": "5.59.0", + "c8": "8.0.0", + "chai": "4.3.7", + "chai-as-promised": "7.1.1", + "esbuild": "0.16.17", + "eslint": "8.39.0", + "eslint-plugin-mocha": "10.1.0", + "karma": "6.4.1", + "karma-chai": "0.1.0", + "karma-chrome-launcher": "3.1.1", + "karma-esbuild": "2.2.5", + "karma-firefox-launcher": "2.1.2", + "karma-mocha": "2.0.1", + "karma-mocha-reporter": "2.2.5", + "karma-webkit-launcher": "2.1.0", + "mocha": "10.2.0", + "node-stdlib-browser": "1.2.0", + "rimraf": "4.4.0", + "sinon": "15.0.2", + "source-map-loader": "4.0.1", + "typescript": "5.0.4" + } +} diff --git a/packages/web5-proxy-agent/src/main.ts b/packages/old/web5-proxy-agent/src/main.ts similarity index 100% rename from packages/web5-proxy-agent/src/main.ts rename to packages/old/web5-proxy-agent/src/main.ts diff --git a/packages/web5-proxy-agent/src/web5-proxy-agent.ts b/packages/old/web5-proxy-agent/src/web5-proxy-agent.ts similarity index 100% rename from packages/web5-proxy-agent/src/web5-proxy-agent.ts rename to packages/old/web5-proxy-agent/src/web5-proxy-agent.ts diff --git a/packages/web5-proxy-agent/tests/needed.spec.ts b/packages/old/web5-proxy-agent/tests/needed.spec.ts similarity index 100% rename from packages/web5-proxy-agent/tests/needed.spec.ts rename to packages/old/web5-proxy-agent/tests/needed.spec.ts diff --git a/packages/old/web5-proxy-agent/tsconfig.json b/packages/old/web5-proxy-agent/tsconfig.json new file mode 100644 index 000000000..c4cc3b877 --- /dev/null +++ b/packages/old/web5-proxy-agent/tsconfig.json @@ -0,0 +1,28 @@ +{ + "compilerOptions": { + "strict": true, + "lib": [ + "DOM", + "ES6" + ], + "allowJs": true, + "target": "es6", + "module": "ESNext", // Required for enabling JavaScript import assertion support + "declaration": true, + "declarationMap": true, + "emitDeclarationOnly": true, + "declarationDir": "dist/types", + "sourceMap": true, + // `NodeNext` will throw compilation errors if relative import paths are missing file extension + // reference: https://devblogs.microsoft.com/typescript/announcing-typescript-4-7/#ecmascript-module-support-in-node-js + "moduleResolution": "NodeNext", + "esModuleInterop": true + }, + "include": [ + "src" + ], + "exclude": [ + "node_modules", + "dist" + ] +} \ No newline at end of file diff --git a/packages/old/web5-proxy-agent/tsconfig.test.json b/packages/old/web5-proxy-agent/tsconfig.test.json new file mode 100644 index 000000000..7e40c3908 --- /dev/null +++ b/packages/old/web5-proxy-agent/tsconfig.test.json @@ -0,0 +1,29 @@ +{ + "compilerOptions": { + "lib": [ + "DOM", + "ES6" + ], + "target": "es6", + "module": "ESNext", // Required for enabling JavaScript import assertion support + "declaration": true, + "declarationMap": true, + "outDir": "__tests__", + "declarationDir": "__tests__/types", + "sourceMap": true, + // `NodeNext` will throw compilation errors if relative import paths are missing file extension + // reference: https://devblogs.microsoft.com/typescript/announcing-typescript-4-7/#ecmascript-module-support-in-node-js + "moduleResolution": "NodeNext", + // allows us to import json files + "resolveJsonModule": true, + "esModuleInterop": true + }, + "include": [ + "src", + "tests", + ], + "exclude": [ + "node_modules", + "dist" + ] +} \ No newline at end of file diff --git a/packages/old/web5-user-agent/.c8rc.json b/packages/old/web5-user-agent/.c8rc.json new file mode 100644 index 000000000..0d483c700 --- /dev/null +++ b/packages/old/web5-user-agent/.c8rc.json @@ -0,0 +1,18 @@ +{ + "all": true, + "cache": false, + "extension": [ + ".js" + ], + "include": [ + "__tests__/src/**" + ], + "exclude": [ + "__tests__/src/main.js", + "__tests__/types/**" + ], + "reporter": [ + "cobertura", + "text" + ] +} \ No newline at end of file diff --git a/packages/web5-user-agent/.gitignore b/packages/old/web5-user-agent/.gitignore similarity index 100% rename from packages/web5-user-agent/.gitignore rename to packages/old/web5-user-agent/.gitignore diff --git a/packages/old/web5-user-agent/.mocharc.json b/packages/old/web5-user-agent/.mocharc.json new file mode 100644 index 000000000..c223f40c7 --- /dev/null +++ b/packages/old/web5-user-agent/.mocharc.json @@ -0,0 +1,5 @@ +{ + "enable-source-maps": true, + "exit": true, + "spec": ["__tests__/**/*.spec.js"] + } \ No newline at end of file diff --git a/packages/old/web5-user-agent/.vscode/launch.json b/packages/old/web5-user-agent/.vscode/launch.json new file mode 100644 index 000000000..506daa8a9 --- /dev/null +++ b/packages/old/web5-user-agent/.vscode/launch.json @@ -0,0 +1,22 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "test:node", + "runtimeExecutable": "${workspaceFolder:root}/node_modules/.bin/mocha", + "runtimeArgs": [ + "${workspaceFolder:web5-user-agent}/__tests__/**/*.spec.js" + ], + "console": "internalConsole", + "preLaunchTask": "tsc: build - tsconfig.test.json", + "outFiles": [ + "${workspaceFolder:web5-user-agent}/__tests__/**/*.js" + ], + } + ] +} \ No newline at end of file diff --git a/packages/old/web5-user-agent/.vscode/tasks.json b/packages/old/web5-user-agent/.vscode/tasks.json new file mode 100644 index 000000000..a6d959d04 --- /dev/null +++ b/packages/old/web5-user-agent/.vscode/tasks.json @@ -0,0 +1,45 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "npm run build", + "type": "npm", + "script": "build", + "problemMatcher": [], + "group": { + "kind": "build", + "isDefault": true + } + }, + { + "label": "tsc: build - tsconfig.json", + "type": "typescript", + "tsconfig": "tsconfig.json", + "problemMatcher": [ + "$tsc" + ], + "group": { + "kind": "build", + "isDefault": false + }, + "options": { + "cwd": "${workspaceFolder:root}" + } + }, + { + "label": "tsc: build - tsconfig.test.json", + "type": "typescript", + "tsconfig": "tsconfig.test.json", + "problemMatcher": [ + "$tsc" + ], + "group": { + "kind": "build", + "isDefault": false + }, + "options": { + "cwd": "${workspaceFolder:root}" + } + }, + ] +} \ No newline at end of file diff --git a/packages/web5/LICENSE b/packages/old/web5-user-agent/LICENSE similarity index 100% rename from packages/web5/LICENSE rename to packages/old/web5-user-agent/LICENSE diff --git a/packages/web5-user-agent/README.md b/packages/old/web5-user-agent/README.md similarity index 100% rename from packages/web5-user-agent/README.md rename to packages/old/web5-user-agent/README.md diff --git a/packages/old/web5-user-agent/build/bundles.js b/packages/old/web5-user-agent/build/bundles.js new file mode 100644 index 000000000..9da2522b3 --- /dev/null +++ b/packages/old/web5-user-agent/build/bundles.js @@ -0,0 +1,62 @@ +import esbuild from 'esbuild'; +import browserConfig from './esbuild-browser-config.cjs'; + +// cjs bundle for Electron apps. external dependencies bundled except LevelDB +// Remove if/when the following PR is merged and this bundle is no longer needed by Electron apps +// https://github.com/electron/electron/pull/37535 +esbuild.buildSync({ + platform : 'node', + bundle : true, + format : 'cjs', + // packages: 'external', + external : ['level'], + sourcemap : true, + entryPoints : ['./src/main.ts'], + outfile : './dist/electron/main.cjs', + allowOverwrite : true, +}); + +// cjs bundle. external dependencies **not** bundled +esbuild.buildSync({ + platform : 'node', + bundle : true, + format : 'cjs', + packages : 'external', + sourcemap : true, + entryPoints : ['./src/main.ts'], + outfile : './dist/cjs/main.cjs', + allowOverwrite : true, +}); + +// esm bundle. external dependencies **not** bundled +esbuild.buildSync({ + platform : 'node', + bundle : true, + format : 'esm', + packages : 'external', + sourcemap : true, + entryPoints : ['./src/main.ts'], + outfile : './dist/esm/main.mjs', + allowOverwrite : true, +}); + +// esm polyfilled bundle for browser +esbuild.build({ + ...browserConfig, + outfile: 'dist/browser.mjs', +}); + +// esm polyfilled test-user-agent bundle for playwright browser tests +esbuild.build({ + ...browserConfig, + entryPoints : ['tests/common/utils/test-user-agent.ts'], + outfile : '__tests__/browser/test-user-agent.mjs', +}); + +// iife polyfilled bundle for browser +esbuild.build({ + ...browserConfig, + format : 'iife', + globalName : 'Web5', + outfile : 'dist/browser.js', +}); \ No newline at end of file diff --git a/packages/old/web5-user-agent/build/esbuild-browser-config.cjs b/packages/old/web5-user-agent/build/esbuild-browser-config.cjs new file mode 100644 index 000000000..4ef8cf1d8 --- /dev/null +++ b/packages/old/web5-user-agent/build/esbuild-browser-config.cjs @@ -0,0 +1,19 @@ +/* eslint-disable @typescript-eslint/no-var-requires */ +const polyfillProviderPlugin = require('node-stdlib-browser/helpers/esbuild/plugin'); +const stdLibBrowser = require('node-stdlib-browser'); + +/** @type {import('esbuild').BuildOptions} */ +module.exports = { + entryPoints : ['./src/main.ts'], + bundle : true, + format : 'esm', + sourcemap : true, + minify : true, + platform : 'browser', + target : ['chrome101', 'firefox108', 'safari16'], + inject : [require.resolve('node-stdlib-browser/helpers/esbuild/shim')], + plugins : [polyfillProviderPlugin(stdLibBrowser)], + define : { + 'global': 'globalThis', + }, +}; diff --git a/packages/web5-user-agent/karma.conf.cjs b/packages/old/web5-user-agent/karma.conf.cjs similarity index 100% rename from packages/web5-user-agent/karma.conf.cjs rename to packages/old/web5-user-agent/karma.conf.cjs diff --git a/packages/old/web5-user-agent/package.json b/packages/old/web5-user-agent/package.json new file mode 100644 index 000000000..19a429674 --- /dev/null +++ b/packages/old/web5-user-agent/package.json @@ -0,0 +1,126 @@ +{ + "name": "@tbd54566975/web5-user-agent", + "version": "0.1.10", + "description": "Web5 User Agent", + "type": "module", + "main": "./dist/cjs/main.cjs", + "module": "./dist/esm/main.mjs", + "types": "./dist/types/main.d.ts", + "scripts": { + "build": "rimraf dist && node build/bundles.js && echo '{\"type\": \"commonjs\"}' > ./dist/cjs/package.json && tsc", + "lint": "eslint . --ext .ts --max-warnings 0", + "lint:fix": "eslint . --ext .ts --fix", + "test:node": "rimraf __tests__ && tsc -p tsconfig.test.json && c8 mocha", + "test:browser": "karma start karma.conf.cjs" + }, + "homepage": "https://github.com/TBD54566975/web5-js/tree/main/packages/web5-user-agent#readme", + "bugs": "https://github.com/TBD54566975/web5-js/issues", + "repository": { + "type": "git", + "url": "git+https://github.com/TBD54566975/web5-js", + "directory": "packages/web5-user-agent" + }, + "license": "Apache-2.0", + "contributors": [ + { + "name": "Daniel Buchner", + "url": "https://github.com/csuwildcat" + }, + { + "name": "Frank Hinek", + "url": "https://github.com/frankhinek" + }, + { + "name": "Moe Jangda", + "url": "https://github.com/mistermoe" + } + ], + "files": [ + "dist", + "src" + ], + "exports": { + ".": { + "import": "./dist/esm/main.mjs", + "require": "./dist/cjs/main.cjs", + "types": "./dist/types/main.d.ts" + }, + "./browser": { + "import": "./dist/browser.mjs", + "require": "./dist/browser.js", + "types": "./dist/types/main.d.ts" + }, + "./electron": { + "import": "./dist/esm/main.mjs", + "require": "./dist/electron/main.cjs", + "types": "./dist/types/main.d.ts" + } + }, + "browser": { + "./dist/esm/main.mjs": "./dist/browser.mjs", + "./dist/cjs/main.cjs": "./dist/browser.js", + "types": "./dist/types/main.d.ts" + }, + "react-native": { + "./dist/esm/main.mjs": "./dist/esm/main.mjs", + "./dist/cjs/main.cjs": "./dist/esm/main.mjs", + "types": "./dist/types/main.d.ts" + }, + "keywords": [ + "decentralized", + "decentralized-applications", + "decentralized-identity", + "decentralized-web", + "web5" + ], + "publishConfig": { + "access": "public" + }, + "engines": { + "node": ">=18.0.0" + }, + "dependencies": { + "@decentralized-identity/ion-tools": "1.1.1", + "@tbd54566975/dids": "0.1.9", + "@tbd54566975/dwn-sdk-js": "0.0.37", + "@tbd54566975/web5-agent": "0.1.7", + "abstract-level": "1.0.3", + "cross-fetch": "3.1.5", + "flat": "5.0.2", + "level": "8.0.0", + "readable-web-to-node-stream": "3.0.2", + "uuid": "9.0.0" + }, + "devDependencies": { + "@faker-js/faker": "8.0.1", + "@playwright/test": "1.34.3", + "@types/chai": "4.3.0", + "@types/chai-as-promised": "7.1.5", + "@types/flat": "5.0.2", + "@types/mocha": "10.0.1", + "@types/readable-stream": "2.3.15", + "@types/sinon": "10.0.15", + "@typescript-eslint/eslint-plugin": "5.59.0", + "@typescript-eslint/parser": "5.59.0", + "c8": "8.0.0", + "chai": "4.3.7", + "chai-as-promised": "7.1.1", + "esbuild": "0.16.17", + "eslint": "8.39.0", + "eslint-plugin-mocha": "10.1.0", + "karma": "6.4.1", + "karma-chai": "0.1.0", + "karma-chrome-launcher": "3.1.1", + "karma-esbuild": "2.2.5", + "karma-firefox-launcher": "2.1.2", + "karma-mocha": "2.0.1", + "karma-mocha-reporter": "2.2.5", + "karma-webkit-launcher": "2.1.0", + "mocha": "10.2.0", + "node-stdlib-browser": "1.2.0", + "rimraf": "4.4.0", + "sinon": "15.0.2", + "source-map-loader": "4.0.1", + "typescript": "5.0.4" + } +} \ No newline at end of file diff --git a/packages/old/web5-user-agent/playwright.config.ts b/packages/old/web5-user-agent/playwright.config.ts new file mode 100644 index 000000000..f45c01c0b --- /dev/null +++ b/packages/old/web5-user-agent/playwright.config.ts @@ -0,0 +1,77 @@ +import { defineConfig, devices } from '@playwright/test'; + +/** + * Read environment variables from file. + * https://github.com/motdotla/dotenv + */ +// require('dotenv').config(); + +/** + * See https://playwright.dev/docs/test-configuration. + */ +export default defineConfig({ + testDir : './tests/browser', + /* Run tests in files in parallel */ + fullyParallel : true, + /* Fail the build on CI if you accidentally left test.only in the source code. */ + forbidOnly : !!process.env.CI, + /* Retry on CI only */ + retries : process.env.CI ? 2 : 0, + /* Opt out of parallel tests on CI. */ + workers : process.env.CI ? 1 : undefined, + /* Reporter to use. See https://playwright.dev/docs/test-reporters */ + reporter : 'html', + /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ + use : { + /* Base URL to use in actions like `await page.goto('/')`. */ + // baseURL: 'http://127.0.0.1:3000', + + /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ + trace: 'on-first-retry', + }, + + /* Configure projects for major browsers */ + projects: [ + { + name : 'chromium', + use : { ...devices['Desktop Chrome'] }, + }, + + { + name : 'firefox', + use : { ...devices['Desktop Firefox'] }, + }, + + { + name : 'webkit', + use : { ...devices['Desktop Safari'] }, + }, + + /* Test against mobile viewports. */ + // { + // name: 'Mobile Chrome', + // use: { ...devices['Pixel 5'] }, + // }, + // { + // name: 'Mobile Safari', + // use: { ...devices['iPhone 12'] }, + // }, + + /* Test against branded browsers. */ + // { + // name: 'Microsoft Edge', + // use: { ...devices['Desktop Edge'], channel: 'msedge' }, + // }, + // { + // name: 'Google Chrome', + // use: { ..devices['Desktop Chrome'], channel: 'chrome' }, + // }, + ], + + /* Run your local dev server before starting the tests */ + webServer: { + command : 'npx http-server .', + url : 'http://127.0.0.1:8080/tests/browser/index.html', + reuseExistingServer : !process.env.CI, + }, +}); diff --git a/packages/web5-user-agent/src/dwn-rpc-client.ts b/packages/old/web5-user-agent/src/dwn-rpc-client.ts similarity index 91% rename from packages/web5-user-agent/src/dwn-rpc-client.ts rename to packages/old/web5-user-agent/src/dwn-rpc-client.ts index 1984e1059..e8569821c 100644 --- a/packages/web5-user-agent/src/dwn-rpc-client.ts +++ b/packages/old/web5-user-agent/src/dwn-rpc-client.ts @@ -9,10 +9,10 @@ import { createJsonRpcRequest, parseJson } from '@tbd54566975/web5-agent'; * Client used to communicate with Dwn Servers */ export class DwnRpcClient implements DwnRpc { - private transportClients: Map; + #transportClients: Map; constructor(clients: DwnRpc[] = []) { - this.transportClients = new Map(); + this.#transportClients = new Map(); // include http client as default. can be overwritten for 'http:' or 'https:' if instantiator provides // their own. @@ -20,20 +20,20 @@ export class DwnRpcClient implements DwnRpc { for (let client of clients) { for (let transportScheme of client.transportProtocols) { - this.transportClients.set(transportScheme, client); + this.#transportClients.set(transportScheme, client); } } } get transportProtocols(): string[] { - return Array.from(this.transportClients.keys()); + return Array.from(this.#transportClients.keys()); } sendDwnRequest(request: DwnRpcRequest): Promise { // will throw if url is invalid const url = new URL(request.dwnUrl); - const transportClient = this.transportClients.get(url.protocol); + const transportClient = this.#transportClients.get(url.protocol); if (!transportClient) { const error = new Error(`no ${url.protocol} transport client available`); error.name = 'NO_TRANSPORT_CLIENT'; diff --git a/packages/web5-user-agent/src/main.ts b/packages/old/web5-user-agent/src/main.ts similarity index 75% rename from packages/web5-user-agent/src/main.ts rename to packages/old/web5-user-agent/src/main.ts index 14333cd26..56768246f 100644 --- a/packages/web5-user-agent/src/main.ts +++ b/packages/old/web5-user-agent/src/main.ts @@ -3,4 +3,5 @@ export * from './profile-manager.js'; export * from './profile-api.js'; export * from './profile-store.js'; export * from './sync-manager.js'; -export * from './sync-api.js'; \ No newline at end of file +export * from './sync-api.js'; +export * from './utils.js'; \ No newline at end of file diff --git a/packages/web5-user-agent/src/profile-api.ts b/packages/old/web5-user-agent/src/profile-api.ts similarity index 100% rename from packages/web5-user-agent/src/profile-api.ts rename to packages/old/web5-user-agent/src/profile-api.ts diff --git a/packages/web5-user-agent/src/profile-index.ts b/packages/old/web5-user-agent/src/profile-index.ts similarity index 100% rename from packages/web5-user-agent/src/profile-index.ts rename to packages/old/web5-user-agent/src/profile-index.ts diff --git a/packages/web5-user-agent/src/profile-manager.ts b/packages/old/web5-user-agent/src/profile-manager.ts similarity index 100% rename from packages/web5-user-agent/src/profile-manager.ts rename to packages/old/web5-user-agent/src/profile-manager.ts diff --git a/packages/web5-user-agent/src/profile-store.ts b/packages/old/web5-user-agent/src/profile-store.ts similarity index 100% rename from packages/web5-user-agent/src/profile-store.ts rename to packages/old/web5-user-agent/src/profile-store.ts diff --git a/packages/web5-user-agent/src/sync-api.ts b/packages/old/web5-user-agent/src/sync-api.ts similarity index 76% rename from packages/web5-user-agent/src/sync-api.ts rename to packages/old/web5-user-agent/src/sync-api.ts index 2316f651f..c64c68444 100644 --- a/packages/web5-user-agent/src/sync-api.ts +++ b/packages/old/web5-user-agent/src/sync-api.ts @@ -46,43 +46,43 @@ type DwnMessage = { type DbBatchOperation = BatchOperation; export class SyncApi implements SyncManager { - private db: Level; - private dwn: Dwn; - private didResolver: DidResolver; - private profileManager: ProfileManager; - private dwnRpcClient: DwnRpc; + #db: Level; + #dwn: Dwn; + #didResolver: DidResolver; + #profileManager: ProfileManager; + #dwnRpcClient: DwnRpc; - static defaultOptions = { + static #defaultOptions = { storeLocation: 'data/agent/sync-store', }; constructor(options: SyncApiOptions) { - options = { ...SyncApi.defaultOptions, ...options }; - this.dwn = options.dwn; - this.didResolver = options.didResolver; - this.profileManager = options.profileManager; + options = { ...SyncApi.#defaultOptions, ...options }; + this.#dwn = options.dwn; + this.#didResolver = options.didResolver; + this.#profileManager = options.profileManager; - this.db = new Level(options.storeLocation); - this.dwnRpcClient = new DwnRpcClient(); + this.#db = new Level(options.storeLocation); + this.#dwnRpcClient = new DwnRpcClient(); } async clear() { - return this.db.clear(); + return this.#db.clear(); } async registerProfile(did: string): Promise { - const registeredProfiles = this.db.sublevel('registeredProfiles'); + const registeredProfiles = this.#db.sublevel('registeredProfiles'); await registeredProfiles.put(did, ''); } async enqueuePush() { - const profileDids = await this.db.sublevel('registeredProfiles').keys().all(); + const profileDids = await this.#db.sublevel('registeredProfiles').keys().all(); const syncStates: SyncState[] = []; for (let did of profileDids) { // TODO: try/catch - const { didDocument } = await this.didResolver.resolve(did); + const { didDocument } = await this.#didResolver.resolve(did); const [ service ] = didUtils.getServices(didDocument, { id: '#dwn', type: 'DecentralizedWebNode' }); // did has no dwn service endpoints listed in DID Doc. ignore @@ -99,13 +99,13 @@ export class SyncApi implements SyncManager { } for (let syncState of syncStates) { - const signatureInput = await this.getAuthorSignatureInput(syncState.did); + const signatureInput = await this.#getAuthorSignatureInput(syncState.did); const eventsGet = await EventsGet.create({ watermark : syncState.watermark, authorizationSignatureInput : signatureInput }); - const eventsReply = await this.dwn.processMessage(syncState.did, eventsGet.toJSON()) as EventsGetReply; + const eventsReply = await this.#dwn.processMessage(syncState.did, eventsGet.toJSON()) as EventsGetReply; const putOps: DbBatchOperation[] = []; for (let event of eventsReply.events) { @@ -115,13 +115,13 @@ export class SyncApi implements SyncManager { putOps.push(putOp); } - const pushQueue = this.getPushQueue(); + const pushQueue = this.#getPushQueue(); await pushQueue.batch(putOps as any); } } async getEvents(did: string, watermark: string | undefined, dwnUrl: string) { - const signatureInput = await this.getAuthorSignatureInput(did); + const signatureInput = await this.#getAuthorSignatureInput(did); const eventsGet = await EventsGet.create({ watermark : watermark, authorizationSignatureInput : signatureInput @@ -129,10 +129,10 @@ export class SyncApi implements SyncManager { let events: Event[]; if (dwnUrl === 'local') { - const reply = await this.dwn.processMessage(did, eventsGet.toJSON()) as EventsGetReply; + const reply = await this.#dwn.processMessage(did, eventsGet.toJSON()) as EventsGetReply; ({ events } = reply); } else { - const reply = await this.dwnRpcClient.sendDwnRequest({ + const reply = await this.#dwnRpcClient.sendDwnRequest({ dwnUrl, targetDid : did, message : eventsGet @@ -147,7 +147,7 @@ export class SyncApi implements SyncManager { async push() { await this.enqueuePush(); - const pushQueue = this.getPushQueue(); + const pushQueue = this.#getPushQueue(); const pushJobs = await pushQueue.iterator().all(); const errored: Set = new Set(); @@ -161,17 +161,17 @@ export class SyncApi implements SyncManager { continue; } - const dwnMessage = await this.getDwnMessage(did, messageCid); + const dwnMessage = await this.#getDwnMessage(did, messageCid); if (!dwnMessage) { delOps.push({ type: 'del', key: key }); await this.setWatermark(did, dwnUrl, 'push', watermark); - await this.addMessage(did, messageCid); + await this.#addMessage(did, messageCid); continue; } try { - const reply = await this.dwnRpcClient.sendDwnRequest({ + const reply = await this.#dwnRpcClient.sendDwnRequest({ dwnUrl, targetDid : did, data : dwnMessage.data, @@ -181,7 +181,7 @@ export class SyncApi implements SyncManager { if (reply.status.code === 202 || reply.status.code === 409) { delOps.push({ type: 'del', key: key }); await this.setWatermark(did, dwnUrl, 'push', watermark); - await this.addMessage(did, messageCid); + await this.#addMessage(did, messageCid); } } catch(e) { errored.add(dwnUrl); @@ -192,12 +192,12 @@ export class SyncApi implements SyncManager { } async enqueuePull() { - const profileDids = await this.db.sublevel('registeredProfiles').keys().all(); + const profileDids = await this.#db.sublevel('registeredProfiles').keys().all(); const syncStates: SyncState[] = []; for (let did of profileDids) { // TODO: try/catch - const { didDocument } = await this.didResolver.resolve(did); + const { didDocument } = await this.#didResolver.resolve(did); const [ service ] = didUtils.getServices(didDocument, { id: '#dwn', type: 'DecentralizedWebNode' }); // did has no dwn service endpoints listed in DID Doc. ignore @@ -215,7 +215,7 @@ export class SyncApi implements SyncManager { const pullOps: DbBatchOperation[] = []; for (let syncState of syncStates) { - const signatureInput = await this.getAuthorSignatureInput(syncState.did); + const signatureInput = await this.#getAuthorSignatureInput(syncState.did); const eventsGet = await EventsGet.create({ watermark : syncState.watermark, authorizationSignatureInput : signatureInput @@ -224,7 +224,7 @@ export class SyncApi implements SyncManager { let reply: EventsGetReply; try { - reply = await this.dwnRpcClient.sendDwnRequest({ + reply = await this.#dwnRpcClient.sendDwnRequest({ dwnUrl : syncState.dwnUrl, targetDid : syncState.did, message : eventsGet @@ -241,7 +241,7 @@ export class SyncApi implements SyncManager { } if (pullOps.length > 0) { - const pullQueue = this.getPullQueue(); + const pullQueue = this.#getPullQueue(); pullQueue.batch(pullOps as any); } } @@ -250,7 +250,7 @@ export class SyncApi implements SyncManager { async pull() { await this.enqueuePull(); - const pullQueue = this.getPullQueue(); + const pullQueue = this.#getPullQueue(); const pullJobs = await pullQueue.iterator().all(); const delOps: DbBatchOperation[] = []; const errored: Set = new Set(); @@ -263,7 +263,7 @@ export class SyncApi implements SyncManager { continue; } - const messageExists = await this.messageExists(did, messageCid); + const messageExists = await this.#messageExists(did, messageCid); if (messageExists) { await this.setWatermark(did, dwnUrl, 'pull', watermark); delOps.push({ type: 'del', key }); @@ -271,7 +271,7 @@ export class SyncApi implements SyncManager { continue; } - const signatureInput = await this.getAuthorSignatureInput(did); + const signatureInput = await this.#getAuthorSignatureInput(did); const messagesGet = await MessagesGet.create({ messageCids : [messageCid], authorizationSignatureInput : signatureInput @@ -280,7 +280,7 @@ export class SyncApi implements SyncManager { let reply: MessagesGetReply; try { - reply = await this.dwnRpcClient.sendDwnRequest({ + reply = await this.#dwnRpcClient.sendDwnRequest({ dwnUrl, targetDid : did, message : messagesGet @@ -295,13 +295,13 @@ export class SyncApi implements SyncManager { console.warn(`message ${messageCid} not found. entry: ${JSON.stringify(entry, null, 2)} ignoring..`); await this.setWatermark(did, dwnUrl, 'pull', watermark); - await this.addMessage(did, messageCid); + await this.#addMessage(did, messageCid); delOps.push({ type: 'del', key }); continue; } - const messageType = this.getDwnMessageType(entry.message); + const messageType = this.#getDwnMessageType(entry.message); let dataStream; if (messageType === 'RecordsWrite') { @@ -317,18 +317,18 @@ export class SyncApi implements SyncManager { recordId : message['recordId'] }); - const recordsReadReply = await this.dwnRpcClient.sendDwnRequest({ + const recordsReadReply = await this.#dwnRpcClient.sendDwnRequest({ targetDid : did, dwnUrl, message : recordsRead }) as RecordsReadReply; if (recordsReadReply.status.code >= 400) { - const pruneReply = await this.dwn.synchronizePrunedInitialRecordsWrite(did, message); + const pruneReply = await this.#dwn.synchronizePrunedInitialRecordsWrite(did, message); if (pruneReply.status.code === 202 || pruneReply.status.code === 409) { await this.setWatermark(did, dwnUrl, 'pull', watermark); - await this.addMessage(did, messageCid); + await this.#addMessage(did, messageCid); delOps.push({ type: 'del', key }); continue; @@ -341,11 +341,11 @@ export class SyncApi implements SyncManager { } } - const pullReply = await this.dwn.processMessage(did, entry.message, dataStream); + const pullReply = await this.#dwn.processMessage(did, entry.message, dataStream); if (pullReply.status.code === 202 || pullReply.status.code === 409) { await this.setWatermark(did, dwnUrl, 'pull', watermark); - await this.addMessage(did, messageCid); + await this.#addMessage(did, messageCid); delOps.push({ type: 'del', key }); } } @@ -354,14 +354,14 @@ export class SyncApi implements SyncManager { await pullQueue.batch(delOps as any); } - async getDwnMessage(author: string, messageCid: string): Promise { - const dwnSignatureInput = await this.getAuthorSignatureInput(author); + async #getDwnMessage(author: string, messageCid: string): Promise { + const dwnSignatureInput = await this.#getAuthorSignatureInput(author); const messagesGet = await MessagesGet.create({ authorizationSignatureInput : dwnSignatureInput, messageCids : [messageCid] }); - const result: MessagesGetReply = await this.dwn.processMessage(author, messagesGet.toJSON()); + const result: MessagesGetReply = await this.#dwn.processMessage(author, messagesGet.toJSON()); const [ messageEntry ] = result.messages; // absence of a messageEntry or message within messageEntry can happen because updating a Record actually creates another @@ -393,7 +393,7 @@ export class SyncApi implements SyncManager { recordId : message['recordId'] }); - const reply = await this.dwn.processMessage(author, recordsRead.toJSON()) as RecordsReadReply; + const reply = await this.#dwn.processMessage(author, recordsRead.toJSON()) as RecordsReadReply; // if the data no longer exists (aka 404), it's likely that a `RecordsDelete` took place. // `RecordsDelete` keeps a `RecordsWrite` and just deletes the associated data, effectively acting as a "tombstone". @@ -417,8 +417,8 @@ export class SyncApi implements SyncManager { * @param authorDid * @returns {SignatureInput} */ - async getAuthorSignatureInput(authorDid: string): Promise { - const profile = await this.profileManager.getProfile(authorDid); + async #getAuthorSignatureInput(authorDid: string): Promise { + const profile = await this.#profileManager.getProfile(authorDid); if (!profile) { throw new Error('profile not found for author.'); @@ -442,7 +442,7 @@ export class SyncApi implements SyncManager { async getWatermark(did: string, dwnUrl: string, direction: Direction) { const wmKey = `${did}~${dwnUrl}~${direction}`; - const watermarkStore = this.getWatermarkStore(); + const watermarkStore = this.#getWatermarkStore(); try { return await watermarkStore.get(wmKey); @@ -455,13 +455,13 @@ export class SyncApi implements SyncManager { async setWatermark(did: string, dwnUrl: string, direction: Direction, watermark: string) { const wmKey = `${did}~${dwnUrl}~${direction}`; - const watermarkStore = this.getWatermarkStore(); + const watermarkStore = this.#getWatermarkStore(); return watermarkStore.put(wmKey, watermark); } - async messageExists(did: string, messageCid: string) { - const messageStore = this.getMessageStore(did); + async #messageExists(did: string, messageCid: string) { + const messageStore = this.#getMessageStore(did); const hashedKey = new Set([messageCid]); const itr = messageStore.keys({ lte: messageCid, limit: 1 }); @@ -474,30 +474,30 @@ export class SyncApi implements SyncManager { } } - async addMessage(did: string, messageCid: string) { - const messageStore = this.getMessageStore(did); + async #addMessage(did: string, messageCid: string) { + const messageStore = this.#getMessageStore(did); return messageStore.put(messageCid, ''); } - getMessageStore(did: string) { - return this.db.sublevel('history').sublevel(did).sublevel('messages'); + #getMessageStore(did: string) { + return this.#db.sublevel('history').sublevel(did).sublevel('messages'); } - getWatermarkStore() { - return this.db.sublevel('watermarks'); + #getWatermarkStore() { + return this.#db.sublevel('watermarks'); } - getPushQueue() { - return this.db.sublevel('pushQueue'); + #getPushQueue() { + return this.#db.sublevel('pushQueue'); } - getPullQueue() { - return this.db.sublevel('pullQueue'); + #getPullQueue() { + return this.#db.sublevel('pullQueue'); } // TODO: export BaseMessage from dwn-sdk. - getDwnMessageType(message: any) { + #getDwnMessageType(message: any) { return `${message.descriptor.interface}${message.descriptor.method}`; } } \ No newline at end of file diff --git a/packages/web5-user-agent/src/sync-manager.ts b/packages/old/web5-user-agent/src/sync-manager.ts similarity index 100% rename from packages/web5-user-agent/src/sync-manager.ts rename to packages/old/web5-user-agent/src/sync-manager.ts diff --git a/packages/web5-user-agent/src/utils.ts b/packages/old/web5-user-agent/src/utils.ts similarity index 100% rename from packages/web5-user-agent/src/utils.ts rename to packages/old/web5-user-agent/src/utils.ts diff --git a/packages/web5-user-agent/src/web5-user-agent.ts b/packages/old/web5-user-agent/src/web5-user-agent.ts similarity index 90% rename from packages/web5-user-agent/src/web5-user-agent.ts rename to packages/old/web5-user-agent/src/web5-user-agent.ts index a3ac042e3..2b7698762 100644 --- a/packages/web5-user-agent/src/web5-user-agent.ts +++ b/packages/old/web5-user-agent/src/web5-user-agent.ts @@ -1,7 +1,4 @@ import type { DwnServiceEndpoint } from '@tbd54566975/dids'; - -import { Readable } from 'readable-stream'; -import { MessageStoreLevel, DataStoreLevel, EventLogLevel } from '@tbd54566975/dwn-sdk-js/stores'; import { DataStream, SignatureInput, @@ -10,12 +7,10 @@ import { UnionMessageReply, RecordsWriteMessage, RecordsWriteOptions, - Cid, - Encoder, - Message, PrivateJwk as DwnPrivateKeyJwk, } from '@tbd54566975/dwn-sdk-js'; +import { Readable } from 'readable-stream'; import { DwnRpc, Web5Agent, @@ -25,6 +20,12 @@ import { ProcessDwnRequest, } from '@tbd54566975/web5-agent'; +import { + Cid, + Encoder, + Message, +} from '@tbd54566975/dwn-sdk-js'; + import type { SyncManager } from './sync-manager.js'; import type { ProfileManager } from './profile-manager.js'; @@ -95,14 +96,7 @@ export class Web5UserAgent implements Web5Agent { * @returns */ static async create(options: Partial) { - if (!options.dwn) { - const messageStore = new MessageStoreLevel(); - const dataStore = new DataStoreLevel(); - const eventLog = new EventLogLevel(); - - options.dwn = await Dwn.create({ messageStore, dataStore, eventLog }); - } - + options.dwn ||= await Dwn.create(); options.profileManager ||= new ProfileApi(); options.didResolver ||= new DidResolver({ methodResolvers: [new DidIonApi(), new DidKeyApi()] }); @@ -115,7 +109,7 @@ export class Web5UserAgent implements Web5Agent { * @returns */ async processDwnRequest(request: ProcessDwnRequest): Promise { - const { message, dataStream }= await this.constructDwnMessage(request); + const { message, dataStream }= await this.#constructDwnMessage(request); let reply: UnionMessageReply; if (request.store !== false) { @@ -136,12 +130,12 @@ export class Web5UserAgent implements Web5Agent { let messageData; if ('messageCid' in request) { - const { message, data } = await this.getDwnMessage(request.author, request.messageType, request.messageCid); + const { message, data } = await this.#getDwnMessage(request.author, request.messageType, request.messageCid); dwnRpcRequest.message = message; messageData = data; } else { - const { message } = await this.constructDwnMessage(request); + const { message } = await this.#constructDwnMessage(request); dwnRpcRequest.message = message; messageData = request.dataStream; } @@ -196,8 +190,8 @@ export class Web5UserAgent implements Web5Agent { }; } - async getDwnMessage(author: string, messageType: string, messageCid: string): Promise { - const dwnSignatureInput = await this.getAuthorSignatureInput(author); + async #getDwnMessage(author: string, messageType: string, messageCid: string): Promise { + const dwnSignatureInput = await this.#getAuthorSignatureInput(author); const messagesGet = await MessagesGet.create({ authorizationSignatureInput : dwnSignatureInput, messageCids : [messageCid] @@ -246,8 +240,8 @@ export class Web5UserAgent implements Web5Agent { return dwnMessage; } - async constructDwnMessage(request: ProcessDwnRequest) { - const dwnSignatureInput = await this.getAuthorSignatureInput(request.author); + async #constructDwnMessage(request: ProcessDwnRequest) { + const dwnSignatureInput = await this.#getAuthorSignatureInput(request.author); let readableStream: Readable; // TODO: Consider refactoring to move data transformations imposed by fetch() limitations to the HTTP transport-related methods. @@ -291,7 +285,7 @@ export class Web5UserAgent implements Web5Agent { * @param authorDid * @returns {SignatureInput} */ - async getAuthorSignatureInput(authorDid: string): Promise { + async #getAuthorSignatureInput(authorDid: string): Promise { const profile = await this.profileManager.getProfile(authorDid); if (!profile) { diff --git a/packages/old/web5-user-agent/tests/browser/index.html b/packages/old/web5-user-agent/tests/browser/index.html new file mode 100644 index 000000000..821cd1201 --- /dev/null +++ b/packages/old/web5-user-agent/tests/browser/index.html @@ -0,0 +1,55 @@ + + + + + + + + Web5 User Agent Test + + + +
+ + +
+ + + + + \ No newline at end of file diff --git a/packages/old/web5-user-agent/tests/browser/test.jpeg b/packages/old/web5-user-agent/tests/browser/test.jpeg new file mode 100644 index 000000000..295f11c91 Binary files /dev/null and b/packages/old/web5-user-agent/tests/browser/test.jpeg differ diff --git a/packages/old/web5-user-agent/tests/browser/web5-user-agent.spec.ts b/packages/old/web5-user-agent/tests/browser/web5-user-agent.spec.ts new file mode 100644 index 000000000..cbf5b6ab2 --- /dev/null +++ b/packages/old/web5-user-agent/tests/browser/web5-user-agent.spec.ts @@ -0,0 +1,14 @@ +import { test, expect } from '@playwright/test'; + +test('processDwnRequest can take a file', async ({ page }) => { + await page.goto('http://127.0.0.1:8080/tests/browser/index.html'); + + page.on('console', msg => console.log(msg.text())); + + const inputChonkerHandler = await page.$('#chonker'); + await expect(inputChonkerHandler).toBeTruthy; + + await inputChonkerHandler?.setInputFiles('./tests/browser/test.jpeg'); + await page.click('#chonker_btn'); + expect(true).toBe(false); +}); diff --git a/packages/web5-user-agent/tests/common/utils/test-user-agent.ts b/packages/old/web5-user-agent/tests/common/utils/test-user-agent.ts similarity index 96% rename from packages/web5-user-agent/tests/common/utils/test-user-agent.ts rename to packages/old/web5-user-agent/tests/common/utils/test-user-agent.ts index 094106e65..d0120e7f9 100644 --- a/packages/web5-user-agent/tests/common/utils/test-user-agent.ts +++ b/packages/old/web5-user-agent/tests/common/utils/test-user-agent.ts @@ -1,11 +1,8 @@ import type { DidIonCreateOptions } from '@tbd54566975/dids'; -import { Dwn } from '@tbd54566975/dwn-sdk-js'; -import { DataStoreLevel, EventLogLevel, MessageStoreLevel } from '@tbd54566975/dwn-sdk-js/stores'; import { DidIonApi, DidKeyApi, DidResolver } from '@tbd54566975/dids'; - - import { Web5UserAgent, ProfileApi, ProfileStore } from '../../../src/main.js'; +import { Dwn, DataStoreLevel, EventLogLevel, MessageStoreLevel } from '@tbd54566975/dwn-sdk-js'; type CreateMethodOptions = { testDataLocation?: string; diff --git a/packages/web5-user-agent/tests/common/web5-user-agent.spec.ts b/packages/old/web5-user-agent/tests/common/web5-user-agent.spec.ts similarity index 100% rename from packages/web5-user-agent/tests/common/web5-user-agent.spec.ts rename to packages/old/web5-user-agent/tests/common/web5-user-agent.spec.ts diff --git a/packages/web5-user-agent/tests/fixtures/protocol-definitions/email.json b/packages/old/web5-user-agent/tests/fixtures/protocol-definitions/email.json similarity index 100% rename from packages/web5-user-agent/tests/fixtures/protocol-definitions/email.json rename to packages/old/web5-user-agent/tests/fixtures/protocol-definitions/email.json diff --git a/packages/web5-user-agent/tests/fixtures/protocol-definitions/message.json b/packages/old/web5-user-agent/tests/fixtures/protocol-definitions/message.json similarity index 100% rename from packages/web5-user-agent/tests/fixtures/protocol-definitions/message.json rename to packages/old/web5-user-agent/tests/fixtures/protocol-definitions/message.json diff --git a/packages/web5-user-agent/tests/fixtures/test-profiles.ts b/packages/old/web5-user-agent/tests/fixtures/test-profiles.ts similarity index 100% rename from packages/web5-user-agent/tests/fixtures/test-profiles.ts rename to packages/old/web5-user-agent/tests/fixtures/test-profiles.ts diff --git a/packages/web5-user-agent/tests/node/web5-user-agent.spec.ts b/packages/old/web5-user-agent/tests/node/web5-user-agent.spec.ts similarity index 100% rename from packages/web5-user-agent/tests/node/web5-user-agent.spec.ts rename to packages/old/web5-user-agent/tests/node/web5-user-agent.spec.ts diff --git a/packages/old/web5-user-agent/tsconfig.json b/packages/old/web5-user-agent/tsconfig.json new file mode 100644 index 000000000..30cb484fa --- /dev/null +++ b/packages/old/web5-user-agent/tsconfig.json @@ -0,0 +1,27 @@ +{ + "compilerOptions": { + "lib": [ + "DOM", + "ES6" + ], + "allowJs": true, + "target": "es6", + "module": "ESNext", // Required for enabling JavaScript import assertion support + "declaration": true, + "declarationMap": true, + "emitDeclarationOnly": true, + "declarationDir": "dist/types", + "sourceMap": true, + // `NodeNext` will throw compilation errors if relative import paths are missing file extension + // reference: https://devblogs.microsoft.com/typescript/announcing-typescript-4-7/#ecmascript-module-support-in-node-js + "moduleResolution": "NodeNext", + "esModuleInterop": true + }, + "include": [ + "src" + ], + "exclude": [ + "node_modules", + "dist" + ] +} \ No newline at end of file diff --git a/packages/old/web5-user-agent/tsconfig.test.json b/packages/old/web5-user-agent/tsconfig.test.json new file mode 100644 index 000000000..4c4902bfa --- /dev/null +++ b/packages/old/web5-user-agent/tsconfig.test.json @@ -0,0 +1,32 @@ +{ + "compilerOptions": { + "lib": [ + "DOM", + "ES6" + ], + "target": "ESNext", + "module": "ESNext", // Required for enabling JavaScript import assertion support + "declaration": true, + "declarationMap": true, + "rootDir": "./", + "outDir": "__tests__", + "declarationDir": "__tests__/types", + "sourceMap": true, + // `NodeNext` will throw compilation errors if relative import paths are missing file extension + // reference: https://devblogs.microsoft.com/typescript/announcing-typescript-4-7/#ecmascript-module-support-in-node-js + "moduleResolution": "NodeNext", + // allows us to import json files + "resolveJsonModule": true, + "esModuleInterop": true + }, + "include": [ + "src", + "tests/common", + "tests/node" + ], + "exclude": [ + "node_modules", + "dist", + "__tests__" + ] +} \ No newline at end of file diff --git a/packages/old/web5/.c8rc.json b/packages/old/web5/.c8rc.json new file mode 100644 index 000000000..0d483c700 --- /dev/null +++ b/packages/old/web5/.c8rc.json @@ -0,0 +1,18 @@ +{ + "all": true, + "cache": false, + "extension": [ + ".js" + ], + "include": [ + "__tests__/src/**" + ], + "exclude": [ + "__tests__/src/main.js", + "__tests__/types/**" + ], + "reporter": [ + "cobertura", + "text" + ] +} \ No newline at end of file diff --git a/packages/old/web5/.mocharc.json b/packages/old/web5/.mocharc.json new file mode 100644 index 000000000..c223f40c7 --- /dev/null +++ b/packages/old/web5/.mocharc.json @@ -0,0 +1,5 @@ +{ + "enable-source-maps": true, + "exit": true, + "spec": ["__tests__/**/*.spec.js"] + } \ No newline at end of file diff --git a/packages/old/web5/.vscode/launch.json b/packages/old/web5/.vscode/launch.json new file mode 100644 index 000000000..d00daba36 --- /dev/null +++ b/packages/old/web5/.vscode/launch.json @@ -0,0 +1,29 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Browser in-page.html", + "request": "launch", + "type": "chrome", + "url": "http://localhost:8000/packages/web5/examples/in-page.html", + "webRoot": "${workspaceFolder:web5}" + }, + { + "type": "node", + "request": "launch", + "name": "test:node", + "runtimeExecutable": "${workspaceFolder:root}/node_modules/.bin/mocha", + "runtimeArgs": [ + "${workspaceFolder:web5}/__tests__/**/*.spec.js" + ], + "console": "internalConsole", + "preLaunchTask": "tsc: build - tsconfig.test.json", + "outFiles": [ + "${workspaceFolder:web5}/__tests__/**/*.js" + ], + } + ] +} \ No newline at end of file diff --git a/packages/old/web5/.vscode/tasks.json b/packages/old/web5/.vscode/tasks.json new file mode 100644 index 000000000..2529e7e5d --- /dev/null +++ b/packages/old/web5/.vscode/tasks.json @@ -0,0 +1,45 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "npm run build", + "type": "npm", + "script": "build", + "problemMatcher": [], + "group": { + "kind": "build", + "isDefault": true + } + }, + { + "label": "tsc: build - tsconfig.json", + "type": "typescript", + "tsconfig": "tsconfig.json", + "problemMatcher": [ + "$tsc" + ], + "group": { + "kind": "build", + "isDefault": false + }, + "options": { + "cwd": "${workspaceFolder:root}" + } + }, + { + "label": "tsc: build - tsconfig.test.json", + "type": "typescript", + "tsconfig": "tsconfig.test.json", + "problemMatcher": [ + "$tsc" + ], + "group": { + "kind": "build", + "isDefault": false + }, + "options": { + "cwd": "${workspaceFolder:root}" + } + }, + ] +} \ No newline at end of file diff --git a/packages/old/web5/LICENSE b/packages/old/web5/LICENSE new file mode 100644 index 000000000..f49a4e16e --- /dev/null +++ b/packages/old/web5/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. \ No newline at end of file diff --git a/packages/web5/README.md b/packages/old/web5/README.md similarity index 100% rename from packages/web5/README.md rename to packages/old/web5/README.md diff --git a/packages/old/web5/build/bundles.js b/packages/old/web5/build/bundles.js new file mode 100644 index 000000000..b1041cc61 --- /dev/null +++ b/packages/old/web5/build/bundles.js @@ -0,0 +1,55 @@ +import esbuild from 'esbuild'; +import browserConfig from './esbuild-browser-config.cjs'; + +// cjs bundle for Electron apps. external dependencies bundled except LevelDB +// Remove if/when the following PR is merged and this bundle is no longer needed by Electron apps +// https://github.com/electron/electron/pull/37535 +esbuild.buildSync({ + platform : 'node', + bundle : true, + format : 'cjs', + // packages: 'external', + external : ['level'], + sourcemap : true, + entryPoints : ['./src/main.ts'], + outfile : './dist/electron/main.cjs', + allowOverwrite : true, +}); + +// cjs bundle. external dependencies **not** bundled +esbuild.buildSync({ + platform : 'node', + bundle : true, + format : 'cjs', + packages : 'external', + sourcemap : true, + entryPoints : ['./src/main.ts'], + outfile : './dist/cjs/main.cjs', + allowOverwrite : true, +}); + +// esm bundle. external dependencies **not** bundled +esbuild.buildSync({ + platform : 'node', + bundle : true, + format : 'esm', + packages : 'external', + sourcemap : true, + entryPoints : ['./src/main.ts'], + outfile : './dist/esm/main.mjs', + allowOverwrite : true, +}); + +// esm polyfilled bundle for browser +esbuild.build({ + ...browserConfig, + outfile: 'dist/browser.mjs', +}); + +// iife polyfilled bundle for browser +esbuild.build({ + ...browserConfig, + format : 'iife', + globalName : 'Web5', + outfile : 'dist/browser.js', +}); \ No newline at end of file diff --git a/packages/old/web5/build/esbuild-browser-config.cjs b/packages/old/web5/build/esbuild-browser-config.cjs new file mode 100644 index 000000000..4ef8cf1d8 --- /dev/null +++ b/packages/old/web5/build/esbuild-browser-config.cjs @@ -0,0 +1,19 @@ +/* eslint-disable @typescript-eslint/no-var-requires */ +const polyfillProviderPlugin = require('node-stdlib-browser/helpers/esbuild/plugin'); +const stdLibBrowser = require('node-stdlib-browser'); + +/** @type {import('esbuild').BuildOptions} */ +module.exports = { + entryPoints : ['./src/main.ts'], + bundle : true, + format : 'esm', + sourcemap : true, + minify : true, + platform : 'browser', + target : ['chrome101', 'firefox108', 'safari16'], + inject : [require.resolve('node-stdlib-browser/helpers/esbuild/shim')], + plugins : [polyfillProviderPlugin(stdLibBrowser)], + define : { + 'global': 'globalThis', + }, +}; diff --git a/packages/web5/examples/in-page.html b/packages/old/web5/examples/in-page.html similarity index 100% rename from packages/web5/examples/in-page.html rename to packages/old/web5/examples/in-page.html diff --git a/packages/web5/karma.conf.cjs b/packages/old/web5/karma.conf.cjs similarity index 100% rename from packages/web5/karma.conf.cjs rename to packages/old/web5/karma.conf.cjs diff --git a/packages/old/web5/package.json b/packages/old/web5/package.json new file mode 100644 index 000000000..6ac833053 --- /dev/null +++ b/packages/old/web5/package.json @@ -0,0 +1,130 @@ +{ + "name": "@tbd54566975/web5", + "version": "0.7.11", + "description": "SDK for accessing the features and capabilities of Web5", + "type": "module", + "main": "./dist/cjs/main.cjs", + "module": "./dist/esm/main.mjs", + "types": "./dist/types/main.d.ts", + "scripts": { + "build": "rimraf dist && node build/bundles.js && echo '{\"type\": \"commonjs\"}' > ./dist/cjs/package.json && tsc", + "lint": "eslint . --ext .ts --max-warnings 0", + "lint:fix": "eslint . --ext .ts --fix", + "test:node": "rimraf __tests__ && tsc -p tsconfig.test.json && c8 mocha", + "test:browser": "karma start karma.conf.cjs" + }, + "homepage": "https://github.com/TBD54566975/web5-js/tree/main/packages/web5#readme", + "bugs": "https://github.com/TBD54566975/web5-js/issues", + "repository": { + "type": "git", + "url": "git+https://github.com/TBD54566975/web5-js", + "directory": "packages/web5" + }, + "license": "Apache-2.0", + "contributors": [ + { + "name": "Daniel Buchner", + "url": "https://github.com/csuwildcat" + }, + { + "name": "Frank Hinek", + "url": "https://github.com/frankhinek" + }, + { + "name": "Moe Jangda", + "url": "https://github.com/mistermoe" + } + ], + "files": [ + "dist", + "src" + ], + "exports": { + ".": { + "import": "./dist/esm/main.mjs", + "require": "./dist/cjs/main.cjs", + "types": "./dist/types/main.d.ts" + }, + "./browser": { + "import": "./dist/browser.mjs", + "require": "./dist/browser.js", + "types": "./dist/types/main.d.ts" + }, + "./electron": { + "import": "./dist/esm/main.mjs", + "require": "./dist/electron/main.cjs", + "types": "./dist/types/main.d.ts" + } + }, + "browser": { + "./dist/esm/main.mjs": "./dist/browser.mjs", + "./dist/cjs/main.cjs": "./dist/browser.js", + "types": "./dist/types/main.d.ts" + }, + "react-native": { + "./dist/esm/main.mjs": "./dist/esm/main.mjs", + "./dist/cjs/main.cjs": "./dist/esm/main.mjs", + "types": "./dist/types/main.d.ts" + }, + "keywords": [ + "decentralized", + "decentralized-applications", + "decentralized-identity", + "decentralized-web", + "DID", + "sdk", + "verifiable-credentials", + "web5", + "web5-sdk" + ], + "publishConfig": { + "access": "public" + }, + "engines": { + "node": ">=18.0.0" + }, + "dependencies": { + "@decentralized-identity/ion-tools": "1.1.1", + "@tbd54566975/crypto": "0.1.6", + "@tbd54566975/dids": "0.1.9", + "@tbd54566975/dwn-sdk-js": "0.0.37", + "@tbd54566975/web5-agent": "0.1.7", + "@tbd54566975/web5-proxy-agent": "0.1.7", + "@tbd54566975/web5-user-agent": "0.1.10", + "level": "8.0.0", + "ms": "2.1.3", + "readable-web-to-node-stream": "3.0.2" + }, + "devDependencies": { + "@playwright/test": "1.34.3", + "@types/chai": "4.3.0", + "@types/chai-as-promised": "7.1.5", + "@types/eslint": "8.37.0", + "@types/mocha": "10.0.1", + "@types/ms": "0.7.31", + "@types/readable-stream": "2.3.15", + "@types/sinon": "10.0.15", + "@typescript-eslint/eslint-plugin": "5.59.0", + "@typescript-eslint/parser": "5.59.0", + "c8": "8.0.0", + "chai": "4.3.7", + "chai-as-promised": "7.1.1", + "esbuild": "0.16.17", + "eslint": "8.39.0", + "eslint-plugin-mocha": "10.1.0", + "karma": "6.4.1", + "karma-chai": "0.1.0", + "karma-chrome-launcher": "3.1.1", + "karma-esbuild": "2.2.5", + "karma-firefox-launcher": "2.1.2", + "karma-mocha": "2.0.1", + "karma-mocha-reporter": "2.2.5", + "karma-webkit-launcher": "2.1.0", + "mocha": "10.2.0", + "node-stdlib-browser": "1.2.0", + "rimraf": "4.4.0", + "sinon": "15.0.2", + "source-map-loader": "4.0.1", + "typescript": "5.0.4" + } +} \ No newline at end of file diff --git a/packages/web5/src/app-storage.ts b/packages/old/web5/src/app-storage.ts similarity index 100% rename from packages/web5/src/app-storage.ts rename to packages/old/web5/src/app-storage.ts diff --git a/packages/web5/src/did-api.ts b/packages/old/web5/src/did-api.ts similarity index 100% rename from packages/web5/src/did-api.ts rename to packages/old/web5/src/did-api.ts diff --git a/packages/web5/src/did-resolution-cache.ts b/packages/old/web5/src/did-resolution-cache.ts similarity index 94% rename from packages/web5/src/did-resolution-cache.ts rename to packages/old/web5/src/did-resolution-cache.ts index 641cde6bf..8969da7bb 100644 --- a/packages/web5/src/did-resolution-cache.ts +++ b/packages/old/web5/src/did-resolution-cache.ts @@ -22,13 +22,13 @@ export class DidResolutionCache implements DidResolverCache { private cache: Level; private ttl: number; - private static defaultOptions = { + static #defaultOptions = { location : 'data/did-res-cache', ttl : '15m' }; constructor(options: DidResolutionCacheOptions = {}) { - options = { ...DidResolutionCache.defaultOptions, ...options }; + options = { ...DidResolutionCache.#defaultOptions, ...options }; this.cache = new Level(options.location!); this.ttl = ms(options.ttl!); diff --git a/packages/web5/src/dwn-api.ts b/packages/old/web5/src/dwn-api.ts similarity index 100% rename from packages/web5/src/dwn-api.ts rename to packages/old/web5/src/dwn-api.ts diff --git a/packages/old/web5/src/main.ts b/packages/old/web5/src/main.ts new file mode 100644 index 000000000..8bf80c7d6 --- /dev/null +++ b/packages/old/web5/src/main.ts @@ -0,0 +1 @@ +export * from './web5.js'; \ No newline at end of file diff --git a/packages/web5/src/protocol.ts b/packages/old/web5/src/protocol.ts similarity index 56% rename from packages/web5/src/protocol.ts rename to packages/old/web5/src/protocol.ts index f70d86b73..291230e17 100644 --- a/packages/web5/src/protocol.ts +++ b/packages/old/web5/src/protocol.ts @@ -9,30 +9,30 @@ type ProtocolMetadata = { }; export class Protocol { - private metadata: ProtocolMetadata; - private web5Agent: Web5Agent; - private protocolsConfigureMessage: ProtocolsConfigureMessage; + #metadata: ProtocolMetadata; + #web5Agent: Web5Agent; + #protocolsConfigureMessage: ProtocolsConfigureMessage; get definition() { - return this.protocolsConfigureMessage.descriptor.definition; + return this.#protocolsConfigureMessage.descriptor.definition; } constructor(web5Agent: Web5Agent, protocolsConfigureMessage: ProtocolsConfigureMessage, metadata: ProtocolMetadata) { - this.metadata = metadata; - this.web5Agent = web5Agent; - this.protocolsConfigureMessage = protocolsConfigureMessage; + this.#metadata = metadata; + this.#web5Agent = web5Agent; + this.#protocolsConfigureMessage = protocolsConfigureMessage; } toJSON() { - return this.protocolsConfigureMessage; + return this.#protocolsConfigureMessage; } async send(target: string) { - const { reply } = await this.web5Agent.sendDwnRequest({ + const { reply } = await this.#web5Agent.sendDwnRequest({ messageType : 'ProtocolsConfigure', - author : this.metadata.author, + author : this.#metadata.author, target : target, - messageCid : this.metadata.messageCid + messageCid : this.#metadata.messageCid }); return { status: reply.status }; diff --git a/packages/old/web5/src/record.ts b/packages/old/web5/src/record.ts new file mode 100644 index 000000000..4e4f920ee --- /dev/null +++ b/packages/old/web5/src/record.ts @@ -0,0 +1,350 @@ +import type { Readable } from 'readable-stream'; +import type { Web5Agent } from '@tbd54566975/web5-agent'; +import type { RecordsReadReply, RecordsWriteDescriptor, RecordsWriteMessage, RecordsWriteOptions } from '@tbd54566975/dwn-sdk-js'; + +import { ReadableWebToNodeStream } from 'readable-web-to-node-stream'; +import { DataStream, DwnInterfaceName, DwnMethodName, Encoder } from '@tbd54566975/dwn-sdk-js'; + +import { dataToBlob } from './utils.js'; +import type { RecordsDeleteResponse } from './dwn-api.js'; + +export type RecordOptions = RecordsWriteMessage & { + author: string; + target: string; + encodedData?: string | Blob; + data?: Readable | ReadableStream; +}; + +export type RecordModel = RecordsWriteDescriptor & Omit & { + author: string; + recordId?: string; + target: string; +} + +export type RecordUpdateOptions = { + data?: unknown; + dataCid?: RecordsWriteDescriptor['dataCid']; + dataSize?: RecordsWriteDescriptor['dataSize']; + dateModified?: RecordsWriteDescriptor['dateModified']; + datePublished?: RecordsWriteDescriptor['datePublished']; + published?: RecordsWriteDescriptor['published']; +} + +/** + * TODO: Document class. + */ +export class Record implements RecordModel { + // mutable properties + author: string; + target: string; + isDeleted = false; + + #attestation?: RecordsWriteMessage['attestation']; + #contextId?: string; + #descriptor: RecordsWriteDescriptor; + #encodedData?: string | Blob | null; + #encryption?: RecordsWriteMessage['encryption']; + #readableStream?: Readable | Promise; + #recordId: string; + #web5Agent: Web5Agent; + + // Immutable DWN Record properties. + get attestation(): RecordsWriteMessage['attestation'] { return this.#attestation; } + get contextId() { return this.#contextId; } + get dataFormat() { return this.#descriptor.dataFormat; } + get dateCreated() { return this.#descriptor.dateCreated; } + get encryption(): RecordsWriteMessage['encryption'] { return this.#encryption; } + get id() { return this.#recordId; } + get interface() { return this.#descriptor.interface; } + get method() { return this.#descriptor.method; } + get parentId() { return this.#descriptor.parentId; } + get protocol() { return this.#descriptor.protocol; } + get protocolPath() { return this.#descriptor.protocolPath; } + get recipient() { return this.#descriptor.recipient; } + get schema() { return this.#descriptor.schema; } + + // Mutable DWN Record properties. + get dataCid() { return this.#descriptor.dataCid; } + get dataSize() { return this.#descriptor.dataSize; } + get dateModified() { return this.#descriptor.dateModified; } + get datePublished() { return this.#descriptor.datePublished; } + get published() { return this.#descriptor.published; } + + constructor(web5Agent: Web5Agent, options: RecordOptions) { + this.#web5Agent = web5Agent; + + // Store the target and author DIDs that were used to create the message to use for subsequent reads, etc. + this.author = options.author; + this.target = options.target; + + // RecordsWriteMessage properties. + this.#attestation = options.attestation; + this.#contextId = options.contextId; + this.#descriptor = options.descriptor; + this.#encryption = options.encryption; + this.#recordId = options.recordId; + + + // options.encodedData will either be a base64url encoded string (in the case of RecordsQuery) + // OR a Blob in the case of a RecordsWrite. + this.#encodedData = options.encodedData ?? null; + + // If the record was created from a RecordsRead reply then it will have a `data` property. + if (options.data) { + this.#readableStream = Record.isReadableWebStream(options.data) ? + new ReadableWebToNodeStream(options.data) as Readable : options.data as Readable; + } + } + + /** + * TODO: Document method. + */ + get data() { + if (this.isDeleted) throw new Error('Operation failed: Attempted to access `data` of a record that has already been deleted.'); + + if (!this.#encodedData && !this.#readableStream) { + // `encodedData` will be set if the Record was instantiated by dwn.records.create()/write(). + // `readableStream` will be set if Record was instantiated by dwn.records.read(). + // If neither of the above are true, then the record must be fetched from the DWN. + this.#readableStream = this.#web5Agent.processDwnRequest({ + author : this.author, + messageOptions : { recordId: this.id }, + messageType : DwnInterfaceName.Records + DwnMethodName.Read, + target : this.target, + }) + .then(response => response.reply as RecordsReadReply) + .then(reply => reply.record.data as Readable) + .catch(error => { throw new Error(`Error encountered while attempting to read data: ${error.message}`); }); + } + + if (typeof this.#encodedData === 'string') { + // If `encodedData` is set, then it is expected that: + // type is Blob if the Record object was instantiated by dwn.records.create()/write(). + // type is Base64 URL encoded string if the Record object was instantiated by dwn.records.query(). + // If it is a string, we need to Base64 URL decode to bytes and instantiate a Blob. + const dataBytes = Encoder.base64UrlToBytes(this.#encodedData); + this.#encodedData = new Blob([dataBytes], { type: this.dataFormat }); + } + + // Explicitly cast #encodedData as a Blob since if non-null, it has been converted from string to Blob. + const dataBlob = this.#encodedData as Blob; + + // eslint-disable-next-line @typescript-eslint/no-this-alias + const self = this; // Capture the context of the `Record` instance. + const dataObj = { + async blob(): Promise { + if (dataBlob) return dataBlob; + if (self.#readableStream) return new Blob([await this.stream().then(DataStream.toBytes)], { type: self.dataFormat }); + }, + async json() { + if (dataBlob) return this.text().then(JSON.parse); + if (self.#readableStream) return this.text().then(JSON.parse); + return null; + }, + async text() { + if (dataBlob) return dataBlob.text(); + if (self.#readableStream) return this.stream().then(DataStream.toBytes).then(Encoder.bytesToString); + return null; + }, + async stream() { + if (dataBlob) return new ReadableWebToNodeStream(dataBlob.stream()); + if (self.#readableStream) return self.#readableStream; + return null; + }, + then(...callbacks) { + return this.stream().then(...callbacks); + }, + catch(callback) { + return dataObj.then().catch(callback); + }, + }; + return dataObj; + } + + /** + * TODO: Document method. + */ + async delete(): Promise { + if (this.isDeleted) throw new Error('Operation failed: Attempted to call `delete()` on a record that has already been deleted.'); + + // Attempt to delete the record from the DWN. + const agentResponse = await this.#web5Agent.processDwnRequest({ + author : this.author, + messageOptions : { recordId: this.id }, + messageType : DwnInterfaceName.Records + DwnMethodName.Delete, + target : this.target, + }); + + const { reply: { status } } = agentResponse; + + if (status.code === 202) { + // If the record was successfully deleted, mark the instance as deleted to prevent further modifications. + this.#setDeletedStatus(true); + } + + return { status }; + } + + /** + * TODO: Document method. + */ + async send(target: string): Promise { + if (this.isDeleted) throw new Error('Operation failed: Attempted to call `send()` on a record that has already been deleted.'); + + const { reply: { status } } = await this.#web5Agent.sendDwnRequest({ + messageType : DwnInterfaceName.Records + DwnMethodName.Write, + author : this.author, + dataStream : await this.data.blob(), + target : target, + messageOptions : this.toJSON(), + }); + + return { status }; + } + + /** + * TODO: Document method. + * + * Called by `JSON.stringify(...)` automatically. + */ + toJSON(): RecordModel { + return { + attestation : this.attestation, + author : this.author, + contextId : this.contextId, + dataCid : this.dataCid, + dataFormat : this.dataFormat, + dataSize : this.dataSize, + dateCreated : this.dateCreated, + dateModified : this.dateModified, + datePublished : this.datePublished, + encryption : this.encryption, + interface : this.interface, + method : this.method, + parentId : this.parentId, + protocol : this.protocol, + protocolPath : this.protocolPath, + published : this.published, + recipient : this.recipient, + recordId : this.id, + schema : this.schema, + target : this.target, + }; + } + + /** + * TODO: Document method. + * + * Called automatically in string concatenation, String() type conversion, and template literals. + */ + toString() { + let str = `Record: {\n`; + str += ` ID: ${this.id}\n`; + str += this.contextId ? ` Context ID: ${this.contextId}\n` : ''; + str += this.protocol ? ` Protocol: ${this.protocol}\n` : ''; + str += this.schema ? ` Schema: ${this.schema}\n` : ''; + str += ` Data CID: ${this.dataCid}\n`; + str += ` Data Format: ${this.dataFormat}\n`; + str += ` Data Size: ${this.dataSize}\n`; + str += ` Created: ${this.dateCreated}\n`; + str += ` Modified: ${this.dateModified}\n`; + str += `}`; + return str; + } + + /** + * TODO: Document method. + */ + async update(options: RecordUpdateOptions = {}) { + if (this.isDeleted) throw new Error('Operation failed: Attempted to call `update()` on a record that has already been deleted.'); + + // Begin assembling update message. + let updateMessage = { ...this.#descriptor, ...options } as Partial; + + let dataBlob: Blob; + if (options.data !== undefined) { + // If `data` is being updated then `dataCid` and `dataSize` must be undefined and the `data` property is passed as + // a top-level property to `web5Agent.processDwnRequest()`. + delete updateMessage.dataCid; + delete updateMessage.dataSize; + delete updateMessage.data; + + ({ dataBlob } = dataToBlob(options.data, updateMessage.dataFormat)); + } + + // Throw an error if an attempt is made to modify immutable properties. `data` has already been handled. + const mutableDescriptorProperties = new Set(['data', 'dataCid', 'dataSize', 'dateModified', 'datePublished', 'published']); + Record.#verifyPermittedMutation(Object.keys(options), mutableDescriptorProperties); + + // If a new `dateModified` was not provided, remove it from the updateMessage to let the DWN SDK auto-fill. + // This is necessary because otherwise DWN SDK throws an Error 409 Conflict due to attempting to overwrite a record + // when the `dateModified` timestamps are identical. + if (options.dateModified === undefined) { + delete updateMessage.dateModified; + } + + // If `published` is set to false, ensure that `datePublished` is undefined. Otherwise, DWN SDK's schema validation + // will throw an error if `published` is false but `datePublished` is set. + if (options.published === false && updateMessage.datePublished !== undefined) { + delete updateMessage.datePublished; + } + + // Set the record ID and context ID, if any. + updateMessage.recordId = this.#recordId; + updateMessage.contextId = this.#contextId; + + const messageOptions: Partial = { + ...updateMessage + }; + + const agentResponse = await this.#web5Agent.processDwnRequest({ + author : this.author, + dataStream : dataBlob, + messageOptions, + messageType : DwnInterfaceName.Records + DwnMethodName.Write, + target : this.target, + }); + + const { message, reply: { status } } = agentResponse; + const responseMessage = message as RecordsWriteMessage; + + if (200 <= status.code && status.code <= 299) { + // Only update the local Record instance mutable properties if the record was successfully (over)written. + mutableDescriptorProperties.forEach(property => { + this.#descriptor[property] = responseMessage.descriptor[property]; + }); + // Only cache data if `dataSize` is less than DWN 'max data size allowed to be encoded'. + if (options.data !== undefined) { + this.#encodedData = dataBlob; // Clear `encodedData` in case it was previously set. + } + } + + return { status }; + } + + /** + * TODO: Document method. + */ + #setDeletedStatus(status: boolean): void { + this.isDeleted = status; + } + + /** + * TODO: Document method. + */ + static isReadableWebStream(stream) { + // TODO: Improve robustness of the check modeled after node:stream. + return typeof stream._read !== 'function'; + } + + /** + * TODO: Document method. + */ + static #verifyPermittedMutation(propertiesToMutate: Iterable, mutableDescriptorProperties: Set) { + for (const property of propertiesToMutate) { + if (!mutableDescriptorProperties.has(property)) { + throw new Error(`${property} is an immutable property. Its value cannot be changed.`); + } + } + } +} \ No newline at end of file diff --git a/packages/web5/src/utils.ts b/packages/old/web5/src/utils.ts similarity index 100% rename from packages/web5/src/utils.ts rename to packages/old/web5/src/utils.ts diff --git a/packages/web5/src/vc-api.ts b/packages/old/web5/src/vc-api.ts similarity index 65% rename from packages/web5/src/vc-api.ts rename to packages/old/web5/src/vc-api.ts index acbe71a28..b741f7076 100644 --- a/packages/web5/src/vc-api.ts +++ b/packages/old/web5/src/vc-api.ts @@ -1,12 +1,12 @@ import type { Web5Agent } from '@tbd54566975/web5-agent'; export class VcApi { - private agent: Web5Agent; - private connectedDid: string; + #agent: Web5Agent; + #connectedDid: string; constructor(agent: Web5Agent, connectedDid: string) { - this.agent = agent; - this.connectedDid = connectedDid; + this.#agent = agent; + this.#connectedDid = connectedDid; } async create() { diff --git a/packages/web5/src/web5.ts b/packages/old/web5/src/web5.ts similarity index 88% rename from packages/web5/src/web5.ts rename to packages/old/web5/src/web5.ts index 653a4f20e..0d22e0a30 100644 --- a/packages/web5/src/web5.ts +++ b/packages/old/web5/src/web5.ts @@ -4,8 +4,8 @@ import type { DidState, DidMethodApi, DidResolverCache, DwnServiceEndpoint } fro import ms from 'ms'; +// import { Web5ProxyAgent } from '@tbd54566975/web5-proxy-agent'; import { Dwn } from '@tbd54566975/dwn-sdk-js'; -import { MessageStoreLevel, DataStoreLevel, EventLogLevel } from '@tbd54566975/dwn-sdk-js/stores'; import { Web5UserAgent, ProfileApi, SyncApi } from '@tbd54566975/web5-user-agent'; import { DidIonApi, DidKeyApi, utils as didUtils } from '@tbd54566975/dids'; @@ -51,7 +51,7 @@ export class Web5 { appStorage: AppStorage; dwn: DwnApi; vc: VcApi; - private connectedDid: string; + #connectedDid: string; /** * Statically available DID functionality. can be used to create and resolve DIDs without calling {@link connect}. @@ -70,9 +70,9 @@ export class Web5 { private static APP_DID_KEY = 'WEB5_APP_DID'; private constructor(options: Web5Options) { - this.connectedDid = options.connectedDid; - this.dwn = new DwnApi(options.web5Agent, this.connectedDid); - this.vc = new VcApi(options.web5Agent, this.connectedDid); + this.#connectedDid = options.connectedDid; + this.dwn = new DwnApi(options.web5Agent, this.#connectedDid); + this.vc = new VcApi(options.web5Agent, this.#connectedDid); this.appStorage ||= new AppStorage(); } @@ -109,12 +109,7 @@ export class Web5 { cache : options.didResolutionCache || new DidResolutionCache() }); - const messageStore = new MessageStoreLevel({ blockstoreLocation: 'data/dwn/message-store', indexLocation: 'data/dwn/message-index' }); - const dataStore = new DataStoreLevel({ blockstoreLocation: 'data/dwn/data-store' }); - const eventLog = new EventLogLevel({ location: 'data/dwn/event-log' }); - - const dwn = await Dwn.create({ messageStore, dataStore, eventLog }); - + const dwn = await Dwn.create(); const syncManager = new SyncApi({ profileManager : profileApi, didResolver : Web5.did.resolver, // share the same resolver to share the same underlying cache @@ -146,7 +141,7 @@ export class Web5 { const connectedDid = profile.did.id; const web5 = new Web5({ appStorage: appStorage, web5Agent: agent, connectedDid }); - Web5.enqueueNextSync(syncManager, ms('2m')); + Web5.#enqueueNextSync(syncManager, ms('2m')); return { web5, did: connectedDid }; } @@ -192,13 +187,13 @@ export class Web5 { return Array.from(dwnUrls); } - private static enqueueNextSync(syncManager: SyncManager, delay = 1_000) { + static #enqueueNextSync(syncManager: SyncManager, delay = 1_000) { setTimeout(async () => { try { await syncManager.push(); await syncManager.pull(); - return this.enqueueNextSync(syncManager, delay); + return this.#enqueueNextSync(syncManager, delay); } catch(e) { console.error('Sync failed due to error: ', e); } diff --git a/packages/old/web5/tests/chai-plugins.d.ts b/packages/old/web5/tests/chai-plugins.d.ts new file mode 100644 index 000000000..8dbcb2354 --- /dev/null +++ b/packages/old/web5/tests/chai-plugins.d.ts @@ -0,0 +1,14 @@ +/// + +declare namespace Chai { + + // For BDD API + interface Assertion extends LanguageChains, NumericComparison, TypeComparison { + url: Assertion; + } + + // For Assert API + interface AssertStatic { + isUrl: (actual: any) => Assertion; + } +} \ No newline at end of file diff --git a/packages/web5/tests/did-resolution-cache.spec.ts b/packages/old/web5/tests/did-resolution-cache.spec.ts similarity index 100% rename from packages/web5/tests/did-resolution-cache.spec.ts rename to packages/old/web5/tests/did-resolution-cache.spec.ts diff --git a/packages/web5/tests/fixtures/did-documents.js b/packages/old/web5/tests/fixtures/did-documents.js similarity index 100% rename from packages/web5/tests/fixtures/did-documents.js rename to packages/old/web5/tests/fixtures/did-documents.js diff --git a/packages/web5/tests/fixtures/protocol-definitions/email.json b/packages/old/web5/tests/fixtures/protocol-definitions/email.json similarity index 97% rename from packages/web5/tests/fixtures/protocol-definitions/email.json rename to packages/old/web5/tests/fixtures/protocol-definitions/email.json index 9155bc22c..67e56f3c6 100644 --- a/packages/web5/tests/fixtures/protocol-definitions/email.json +++ b/packages/old/web5/tests/fixtures/protocol-definitions/email.json @@ -1,6 +1,5 @@ { "protocol": "http://email-protocol.xyz", - "published": false, "types": { "email": { "schema": "email", diff --git a/packages/web5/tests/fixtures/protocol-definitions/message.json b/packages/old/web5/tests/fixtures/protocol-definitions/message.json similarity index 100% rename from packages/web5/tests/fixtures/protocol-definitions/message.json rename to packages/old/web5/tests/fixtures/protocol-definitions/message.json diff --git a/packages/web5/tests/fixtures/test-profiles.ts b/packages/old/web5/tests/fixtures/test-profiles.ts similarity index 100% rename from packages/web5/tests/fixtures/test-profiles.ts rename to packages/old/web5/tests/fixtures/test-profiles.ts diff --git a/packages/web5/tests/record.spec.ts b/packages/old/web5/tests/record.spec.ts similarity index 99% rename from packages/web5/tests/record.spec.ts rename to packages/old/web5/tests/record.spec.ts index 3acdb66ab..3dfa13dcd 100644 --- a/packages/web5/tests/record.spec.ts +++ b/packages/old/web5/tests/record.spec.ts @@ -107,7 +107,7 @@ describe('Record', () => { key : TestDataGenerator.randomBytes(32), keyEncryptionInputs : [ { - derivationScheme : KeyDerivationScheme.ProtocolPath, + derivationScheme : KeyDerivationScheme.Protocols, publicKey : encryptionPublicKeyJwk as DwnPublicKeyJwk, publicKeyId : recordEncryptionKeyId }, @@ -168,7 +168,7 @@ describe('Record', () => { expect(record.id).to.equal(recordsWrite.message.recordId); expect(record.encryption).to.not.be.undefined; expect(record.encryption).to.deep.equal(recordsWrite.message.encryption); - expect(record.encryption!.keyEncryption.find(key => key.derivationScheme === KeyDerivationScheme.ProtocolPath)); + expect(record.encryption!.keyEncryption.find(key => key.derivationScheme === KeyDerivationScheme.Protocols)); expect(record.encryption!.keyEncryption.find(key => key.derivationScheme === KeyDerivationScheme.Schemas)); expect(record.attestation).to.not.be.undefined; expect(record.attestation).to.have.property('signatures'); @@ -182,7 +182,7 @@ describe('Record', () => { expect(record.dataCid).to.equal(recordsWrite.message.descriptor.dataCid); expect(record.dataSize).to.equal(recordsWrite.message.descriptor.dataSize); expect(record.dateCreated).to.equal(recordsWrite.message.descriptor.dateCreated); - expect(record.dateModified).to.equal(recordsWrite.message.descriptor.messageTimestamp); + expect(record.dateModified).to.equal(recordsWrite.message.descriptor.dateModified); expect(record.published).to.equal(published); expect(record.datePublished).to.equal(recordsWrite.message.descriptor.datePublished); expect(record.dataFormat).to.equal(dataFormat); @@ -918,7 +918,7 @@ describe('Record', () => { key : TestDataGenerator.randomBytes(32), keyEncryptionInputs : [ { - derivationScheme : KeyDerivationScheme.ProtocolPath, + derivationScheme : KeyDerivationScheme.Protocols, publicKey : encryptionPublicKeyJwk as DwnPublicKeyJwk, publicKeyId : recordEncryptionKeyId }, @@ -982,7 +982,7 @@ describe('Record', () => { expect(record.id).to.equal(recordsWrite.message.recordId); expect(record.encryption).to.not.be.undefined; expect(record.encryption).to.deep.equal(recordsWrite.message.encryption); - expect(record.encryption!.keyEncryption.find(key => key.derivationScheme === KeyDerivationScheme.ProtocolPath)); + expect(record.encryption!.keyEncryption.find(key => key.derivationScheme === KeyDerivationScheme.Protocols)); expect(record.encryption!.keyEncryption.find(key => key.derivationScheme === KeyDerivationScheme.Schemas)); expect(record.attestation).to.not.be.undefined; expect(record.attestation).to.have.property('signatures'); @@ -998,7 +998,7 @@ describe('Record', () => { expect(recordJson.dataCid).to.equal(recordsWrite.message.descriptor.dataCid); expect(recordJson.dataSize).to.equal(recordsWrite.message.descriptor.dataSize); expect(recordJson.dateCreated).to.equal(recordsWrite.message.descriptor.dateCreated); - expect(recordJson.messageTimestamp).to.equal(recordsWrite.message.descriptor.messageTimestamp); + expect(recordJson.dateModified).to.equal(recordsWrite.message.descriptor.dateModified); expect(recordJson.published).to.equal(published); expect(recordJson.datePublished).to.equal(recordsWrite.message.descriptor.datePublished); expect(recordJson.dataFormat).to.equal(dataFormat); diff --git a/packages/web5/tests/tech-preview.spec.ts b/packages/old/web5/tests/tech-preview.spec.ts similarity index 99% rename from packages/web5/tests/tech-preview.spec.ts rename to packages/old/web5/tests/tech-preview.spec.ts index ef9ef9ad8..404fd1ce3 100644 --- a/packages/web5/tests/tech-preview.spec.ts +++ b/packages/old/web5/tests/tech-preview.spec.ts @@ -7,8 +7,11 @@ import { Web5 } from '../src/web5.js'; chai.use(chaiUrl); describe('Tech Preview', () => { + describe('web5.getTechPreviewDwnEndpoints()', () => { + let fetchStub: sinon.SinonStub; + let mockDwnEndpoints: Array; let tbdWellKnownOkResponse = { diff --git a/packages/old/web5/tests/test-utils/chai-plugins.ts b/packages/old/web5/tests/test-utils/chai-plugins.ts new file mode 100644 index 000000000..5f0c9fc21 --- /dev/null +++ b/packages/old/web5/tests/test-utils/chai-plugins.ts @@ -0,0 +1,59 @@ +/** + * Chai plugin for validating URLs. + * + * This function adds two types of URL validation methods to Chai: + * 1. For the BDD "expect" API: `expect(string).to.be.a.url;` + * 2. For the Assert API: `assert.isUrl(string);` + * + * @param {Chai.ChaiStatic} chai - The Chai library object. + * @param {Chai.ChaiUtils} utils - The Chai Utilities object. + * + * @example + * // BDD API example: + * import chai, { expect } from 'chai'; + * import chaiUrl from './chai-plugins.js'; + * chai.use(chaiUrl); + * + * describe('My Test Suite', () => { + * it('should validate the URL', () => { + * const url = 'https://example.org'; + * expect(url).to.be.a.url; + * }); + * }); + * + * @example + * // Assert API example: + * import chai, { assert } from 'chai'; + * import chaiUrl from './chai-plugins.js'; + * chai.use(chaiUrl); + * + * describe('My Test Suite', () => { + * it('should validate the URL', () => { + * const url = 'https://example.org'; + * assert.isUrl(url); + * }); + * }); + */ +export const chaiUrl: Chai.ChaiPlugin = function(chai: Chai.ChaiStatic, utils: Chai.ChaiUtils) { + const assert = chai.assert; + function isValidUrl() { + const obj = utils.flag(this, 'object') as string; + let isUrl = true; + try { + new URL(obj); + } catch (err) { + isUrl = false; + } + this.assert( + isUrl, + 'expected #{this} to be a valid URL', + 'expected #{this} not to be a valid URL' + ); + } + + // Add the property to the BDD "expect" API. + utils.addProperty(chai.Assertion.prototype, 'url', isValidUrl); + + // Add the method to the Assert API. + assert.isUrl = (actual) => (new chai.Assertion(actual)).to.be.a.url; +}; \ No newline at end of file diff --git a/packages/web5/tests/test-utils/promises.ts b/packages/old/web5/tests/test-utils/promises.ts similarity index 100% rename from packages/web5/tests/test-utils/promises.ts rename to packages/old/web5/tests/test-utils/promises.ts diff --git a/packages/web5/tests/test-utils/test-data-generator.ts b/packages/old/web5/tests/test-utils/test-data-generator.ts similarity index 100% rename from packages/web5/tests/test-utils/test-data-generator.ts rename to packages/old/web5/tests/test-utils/test-data-generator.ts diff --git a/packages/web5/tests/test-utils/test-user-agent.ts b/packages/old/web5/tests/test-utils/test-user-agent.ts similarity index 96% rename from packages/web5/tests/test-utils/test-user-agent.ts rename to packages/old/web5/tests/test-utils/test-user-agent.ts index 4ded88897..5eb8d4b16 100644 --- a/packages/web5/tests/test-utils/test-user-agent.ts +++ b/packages/old/web5/tests/test-utils/test-user-agent.ts @@ -2,8 +2,7 @@ import type { DidIonCreateOptions } from '@tbd54566975/dids'; import { DidIonApi, DidKeyApi, DidResolver } from '@tbd54566975/dids'; import { Web5UserAgent, ProfileApi, ProfileStore } from '@tbd54566975/web5-user-agent'; -import { Dwn } from '@tbd54566975/dwn-sdk-js'; -import { DataStoreLevel, EventLogLevel, MessageStoreLevel } from '@tbd54566975/dwn-sdk-js/stores'; +import { Dwn, DataStoreLevel, EventLogLevel, MessageStoreLevel } from '@tbd54566975/dwn-sdk-js'; import { AppStorage } from '../../src/app-storage.js'; diff --git a/packages/web5/tests/web5-did.spec.ts b/packages/old/web5/tests/web5-did.spec.ts similarity index 100% rename from packages/web5/tests/web5-did.spec.ts rename to packages/old/web5/tests/web5-did.spec.ts diff --git a/packages/web5/tests/web5-dwn.spec.ts b/packages/old/web5/tests/web5-dwn.spec.ts similarity index 99% rename from packages/web5/tests/web5-dwn.spec.ts rename to packages/old/web5/tests/web5-dwn.spec.ts index bff8aee6b..6795c6718 100644 --- a/packages/web5/tests/web5-dwn.spec.ts +++ b/packages/old/web5/tests/web5-dwn.spec.ts @@ -30,7 +30,6 @@ describe('web5.dwn', () => { describe('protocols', () => { describe('configure', () => { - // eslint-disable-next-line mocha/no-exclusive-tests describe('agent', () => { it('writes a protocol definition', async () => { const response = await dwn.protocols.configure({ diff --git a/packages/web5/tests/web5-vc.spec.ts b/packages/old/web5/tests/web5-vc.spec.ts similarity index 100% rename from packages/web5/tests/web5-vc.spec.ts rename to packages/old/web5/tests/web5-vc.spec.ts diff --git a/packages/old/web5/tsconfig.json b/packages/old/web5/tsconfig.json new file mode 100644 index 000000000..5e66e05d4 --- /dev/null +++ b/packages/old/web5/tsconfig.json @@ -0,0 +1,28 @@ +{ + "compilerOptions": { + "strict": false, + "lib": [ + "DOM", + "ES6" + ], + "allowJs": true, + "target": "es6", + "module": "ESNext", // Required for enabling JavaScript import assertion support + "declaration": true, + "declarationMap": true, + "emitDeclarationOnly": true, + "declarationDir": "dist/types", + // `NodeNext` will throw compilation errors if relative import paths are missing file extension + // reference: https://devblogs.microsoft.com/typescript/announcing-typescript-4-7/#ecmascript-module-support-in-node-js + "moduleResolution": "NodeNext", + "esModuleInterop": true + }, + "include": [ + "./src/main.ts", + ], + "exclude": [ + "node_modules", + "dist", + "examples", + ] +} \ No newline at end of file diff --git a/packages/old/web5/tsconfig.test.json b/packages/old/web5/tsconfig.test.json new file mode 100644 index 000000000..7e40c3908 --- /dev/null +++ b/packages/old/web5/tsconfig.test.json @@ -0,0 +1,29 @@ +{ + "compilerOptions": { + "lib": [ + "DOM", + "ES6" + ], + "target": "es6", + "module": "ESNext", // Required for enabling JavaScript import assertion support + "declaration": true, + "declarationMap": true, + "outDir": "__tests__", + "declarationDir": "__tests__/types", + "sourceMap": true, + // `NodeNext` will throw compilation errors if relative import paths are missing file extension + // reference: https://devblogs.microsoft.com/typescript/announcing-typescript-4-7/#ecmascript-module-support-in-node-js + "moduleResolution": "NodeNext", + // allows us to import json files + "resolveJsonModule": true, + "esModuleInterop": true + }, + "include": [ + "src", + "tests", + ], + "exclude": [ + "node_modules", + "dist" + ] +} \ No newline at end of file diff --git a/packages/proxy-agent/.c8rc.json b/packages/proxy-agent/.c8rc.json new file mode 100644 index 000000000..ab680f663 --- /dev/null +++ b/packages/proxy-agent/.c8rc.json @@ -0,0 +1,19 @@ +{ + "all": true, + "cache": false, + "extension": [ + ".js" + ], + "include": [ + "tests/compiled/src/**" + ], + "exclude": [ + "tests/compiled/src/index.js", + "tests/compiled/src/types.js", + "tests/compiled/src/types/**" + ], + "reporter": [ + "cobertura", + "text" + ] +} \ No newline at end of file diff --git a/packages/web5-user-agent/.mocharc.json b/packages/proxy-agent/.mocharc.json similarity index 50% rename from packages/web5-user-agent/.mocharc.json rename to packages/proxy-agent/.mocharc.json index e999f4ae8..5aa8c5bfe 100644 --- a/packages/web5-user-agent/.mocharc.json +++ b/packages/proxy-agent/.mocharc.json @@ -1,5 +1,5 @@ { "enable-source-maps": true, "exit": true, - "spec": ["tests/compiled/tests/**/*.spec.js"] + "spec": ["tests/compiled/**/*.spec.js"] } \ No newline at end of file diff --git a/packages/web5-proxy-agent/.vscode/launch.json b/packages/proxy-agent/.vscode/launch.json similarity index 89% rename from packages/web5-proxy-agent/.vscode/launch.json rename to packages/proxy-agent/.vscode/launch.json index e2927b1de..bc398db79 100644 --- a/packages/web5-proxy-agent/.vscode/launch.json +++ b/packages/proxy-agent/.vscode/launch.json @@ -11,7 +11,9 @@ "runtimeExecutable": "${workspaceFolder:root}/node_modules/.bin/mocha", "console": "internalConsole", "preLaunchTask": "build tests", - "skipFiles": ["/**"] + "skipFiles": [ + "/**" + ] } ] } \ No newline at end of file diff --git a/packages/web5-user-agent/.vscode/tasks.json b/packages/proxy-agent/.vscode/tasks.json similarity index 92% rename from packages/web5-user-agent/.vscode/tasks.json rename to packages/proxy-agent/.vscode/tasks.json index 363a6c5c7..a11b32446 100644 --- a/packages/web5-user-agent/.vscode/tasks.json +++ b/packages/proxy-agent/.vscode/tasks.json @@ -31,7 +31,7 @@ "type": "npm", "script": "build:tests:node", "options": { - "cwd": "${workspaceFolder:web5-user-agent}" + "cwd": "${workspaceFolder:proxy-agent}" } } ] diff --git a/packages/web5-agent/build/bundles.js b/packages/proxy-agent/build/bundles.js similarity index 90% rename from packages/web5-agent/build/bundles.js rename to packages/proxy-agent/build/bundles.js index c9119e67b..3f09ffed6 100644 --- a/packages/web5-agent/build/bundles.js +++ b/packages/proxy-agent/build/bundles.js @@ -11,6 +11,6 @@ esbuild.build({ esbuild.build({ ...browserConfig, format : 'iife', - globalName : 'Web5', + globalName : 'Web5ProxyAgent', outfile : 'dist/browser.js', }); \ No newline at end of file diff --git a/packages/proxy-agent/build/esbuild-browser-config.cjs b/packages/proxy-agent/build/esbuild-browser-config.cjs new file mode 100644 index 000000000..bd8bd99b1 --- /dev/null +++ b/packages/proxy-agent/build/esbuild-browser-config.cjs @@ -0,0 +1,30 @@ +/* eslint-disable @typescript-eslint/no-var-requires */ +const polyfillProviderPlugin = require('node-stdlib-browser/helpers/esbuild/plugin'); +const stdLibBrowser = require('node-stdlib-browser'); + +const requiredPolyfills = new Set(['crypto', 'node:crypto', 'stream']); + +// populate object containing lib -> polyfill path +const polyfills = {}; +for (let lib in stdLibBrowser) { + if (requiredPolyfills.has(lib)) { + const polyfill = stdLibBrowser[lib]; + polyfills[lib] = polyfill; + } +} + +/** @type {import('esbuild').BuildOptions} */ +module.exports = { + entryPoints : ['./src/index.ts'], + bundle : true, + format : 'esm', + sourcemap : true, + minify : true, + platform : 'browser', + target : ['chrome101', 'firefox108', 'safari16'], + inject : [require.resolve('node-stdlib-browser/helpers/esbuild/shim')], + plugins : [polyfillProviderPlugin(polyfills)], + define : { + 'global': 'globalThis', + }, +}; \ No newline at end of file diff --git a/packages/proxy-agent/karma.conf.cjs b/packages/proxy-agent/karma.conf.cjs new file mode 100644 index 000000000..6b7407b2c --- /dev/null +++ b/packages/proxy-agent/karma.conf.cjs @@ -0,0 +1,87 @@ +/* eslint-disable @typescript-eslint/no-var-requires */ +// Karma is what we're using to run our tests in browser environments +// Karma does not support .mjs + +// playwright acts as a safari executable on windows and mac +const playwright = require('@playwright/test'); +const esbuildBrowserConfig = require('./build/esbuild-browser-config.cjs'); + +// use playwright chrome exec path as run target for chromium tests +process.env.CHROME_BIN = playwright.chromium.executablePath(); + +// use playwright webkit exec path as run target for safari tests +process.env.WEBKIT_HEADLESS_BIN = playwright.webkit.executablePath(); + +// use playwright firefox exec path as run target for firefox tests +process.env.FIREFOX_BIN = playwright.firefox.executablePath(); + +module.exports = function (config) { + config.set({ + plugins: [ + 'karma-chrome-launcher', + 'karma-firefox-launcher', + 'karma-webkit-launcher', + 'karma-esbuild', + 'karma-mocha', + 'karma-mocha-reporter', + ], + + // frameworks to use + // available frameworks: https://www.npmjs.com/search?q=keywords:karma-adapter + frameworks: ['mocha'], + + client: { + // Increase Mocha's default timeout of 2 seconds to prevent timeouts during GitHub CI runs. + mocha: { + timeout: 10000 // 10 seconds + }, + // If an environment variable is defined, override the default test DWN URL. + testDwnUrl: process.env.TEST_DWN_URL, + }, + + // list of files / patterns to load in the browser + files: [ + { pattern: 'tests/**/*.spec.ts', watched: false }, + ], + + // preprocess matching files before serving them to the browser + // available preprocessors: https://www.npmjs.com/search?q=keywords:karma-preprocessor + preprocessors: { + 'tests/**/*.spec.ts': ['esbuild'], + }, + + esbuild: esbuildBrowserConfig, + + // list of files / patterns to exclude + exclude: [], + + // test results reporter to use + // available reporters: https://www.npmjs.com/search?q=keywords:karma-reporter + reporters: ['mocha'], + + // web server port + port: 9876, + + // enable / disable colors in the output (reporters and logs) + colors: true, + + // level of logging + // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || + // config.LOG_INFO || config.LOG_DEBUG + logLevel: config.LOG_INFO, + + concurrency: 1, + + // start these browsers + // available browser launchers: https://www.npmjs.com/search?q=keywords:karma-launcher + browsers: ['ChromeHeadless', 'FirefoxHeadless', 'WebkitHeadless'], + + // Continuous Integration mode + // if true, Karma captures browsers, runs the tests and exits + singleRun: true, + + // Increase browser timeouts to avoid DISCONNECTED messages during GitHub CI runs. + browserDisconnectTimeout : 10000, // default 2000 + browserDisconnectTolerance : 1, // default 0 + }); +}; diff --git a/packages/web5-proxy-agent/package.json b/packages/proxy-agent/package.json similarity index 73% rename from packages/web5-proxy-agent/package.json rename to packages/proxy-agent/package.json index 771483a41..b8690a4f8 100644 --- a/packages/web5-proxy-agent/package.json +++ b/packages/proxy-agent/package.json @@ -1,11 +1,10 @@ { - "name": "@tbd54566975/web5-proxy-agent", - "version": "0.8.0", - "description": "Web5 Proxy Agent", + "name": "@web5/proxy-agent", + "version": "0.2.0", "type": "module", - "main": "./dist/cjs/main.js", - "module": "./dist/esm/main.js", - "types": "./dist/types/main.d.ts", + "main": "./dist/cjs/index.js", + "module": "./dist/esm/index.js", + "types": "./dist/types/index.d.ts", "scripts": { "clean": "rimraf dist coverage tests/compiled", "build:esm": "rimraf dist/esm dist/types && npx tsc -p tsconfig.json", @@ -18,12 +17,12 @@ "test:node": "npm run build:tests:node && c8 mocha", "test:browser": "karma start karma.conf.cjs" }, - "homepage": "https://github.com/TBD54566975/web5-js/tree/main/packages/web5-proxy-agent#readme", + "homepage": "https://github.com/TBD54566975/web5-js/tree/main/packages/proxy-agent#readme", "bugs": "https://github.com/TBD54566975/web5-js/issues", "repository": { "type": "git", "url": "git+https://github.com/TBD54566975/web5-js", - "directory": "packages/web5-proxy-agent" + "directory": "packages/proxy-agent" }, "license": "Apache-2.0", "contributors": [ @@ -46,17 +45,19 @@ ], "exports": { ".": { - "import": "./dist/esm/main.js", - "require": "./dist/cjs/main.js", - "types": "./dist/types/main.d.ts" + "types": "./dist/types/index.d.ts", + "import": "./dist/esm/index.js", + "require": "./dist/cjs/index.js" } }, - "react-native": "./dist/esm/main.js", + "react-native": "./dist/esm/index.js", "keywords": [ "decentralized", "decentralized-applications", "decentralized-identity", "decentralized-web", + "vcs", + "verifiable credentials", "web5" ], "publishConfig": { @@ -66,22 +67,24 @@ "node": ">=18.0.0" }, "dependencies": { - "@tbd54566975/web5-agent": "0.8.0" + "@web5/agent": "0.2.0", + "@web5/common": "0.2.0", + "@web5/crypto": "0.2.0", + "@web5/dids": "0.2.0" }, "devDependencies": { - "@types/chai": "4.3.0", + "@playwright/test": "1.36.2", + "@types/chai": "4.3.5", "@types/chai-as-promised": "7.1.5", - "@types/ed2curve": "0.2.2", - "@types/eslint": "8.37.0", + "@types/eslint": "8.44.2", "@types/mocha": "10.0.1", - "@types/sinon": "10.0.15", - "@typescript-eslint/eslint-plugin": "5.59.0", - "@typescript-eslint/parser": "5.59.0", - "c8": "8.0.0", + "@typescript-eslint/eslint-plugin": "6.4.0", + "@typescript-eslint/parser": "6.4.0", + "c8": "8.0.1", "chai": "4.3.7", "chai-as-promised": "7.1.1", "esbuild": "0.16.17", - "eslint": "8.39.0", + "eslint": "8.47.0", "eslint-plugin-mocha": "10.1.0", "karma": "6.4.1", "karma-chai": "0.1.0", @@ -92,10 +95,9 @@ "karma-mocha-reporter": "2.2.5", "karma-webkit-launcher": "2.1.0", "mocha": "10.2.0", + "node-stdlib-browser": "1.2.0", "playwright": "1.36.2", "rimraf": "4.4.0", - "sinon": "15.0.2", - "source-map-loader": "4.0.1", "typescript": "5.1.6" } } diff --git a/packages/proxy-agent/src/index.ts b/packages/proxy-agent/src/index.ts new file mode 100644 index 000000000..93ba1a294 --- /dev/null +++ b/packages/proxy-agent/src/index.ts @@ -0,0 +1 @@ +export * from './proxy-agent.js'; \ No newline at end of file diff --git a/packages/proxy-agent/src/proxy-agent.ts b/packages/proxy-agent/src/proxy-agent.ts new file mode 100644 index 000000000..1ef699287 --- /dev/null +++ b/packages/proxy-agent/src/proxy-agent.ts @@ -0,0 +1,240 @@ +import type { + DwnRpc, + VcResponse, + DidResponse, + DwnResponse, + AppDataStore, + SendVcRequest, + SendDidRequest, + SendDwnRequest, + ProcessVcRequest, + Web5ManagedAgent, + ProcessDwnRequest, + ProcessDidRequest, +} from '@web5/agent'; + +import { LevelStore } from '@web5/common'; +import { EdDsaAlgorithm } from '@web5/crypto'; +import { DidIonMethod, DidKeyMethod, DidResolver } from '@web5/dids'; +import { + LocalKms, + DidManager, + DwnManager, + KeyManager, + DidStoreDwn, + KeyStoreDwn, + AppDataVault, + Web5RpcClient, + IdentityManager, + IdentityStoreDwn, + PrivateKeyStoreDwn, + cryptoToPortableKeyPair, +} from '@web5/agent'; + +export type Web5ProxyAgentOptions = { + agentDid: string; + appData: AppDataStore; + didManager: DidManager; + didResolver: DidResolver; + dwnManager: DwnManager; + identityManager: IdentityManager; + keyManager: KeyManager; + rpcClient: DwnRpc; +} + +export class Web5ProxyAgent implements Web5ManagedAgent { + agentDid: string; + appData: AppDataStore; + didManager: DidManager; + didResolver: DidResolver; + dwnManager: DwnManager; + identityManager: IdentityManager; + keyManager: KeyManager; + rpcClient: DwnRpc; + + constructor(options: Web5ProxyAgentOptions) { + this.agentDid = options.agentDid; + this.appData = options.appData; + this.keyManager = options.keyManager; + this.didManager = options.didManager; + this.didResolver = options.didResolver; + this.dwnManager = options.dwnManager; + this.identityManager = options.identityManager; + this.rpcClient = options.rpcClient; + + // Set this agent to be the default agent. + this.didManager.agent = this; + this.dwnManager.agent = this; + this.identityManager.agent = this; + this.keyManager.agent = this; + } + + static async create(options: Partial = {}): Promise { + let { agentDid, appData, didManager, didResolver, dwnManager, identityManager, keyManager, rpcClient } = options; + + if (agentDid === undefined) { + // An Agent DID was not specified, so set to empty string. + agentDid = ''; + } + + if (appData === undefined) { + // A custom AppDataStore implementation was not specified, so + // instantiate a LevelDB backed secure AppDataVault. + appData = new AppDataVault({ + store: new LevelStore('data/agent/vault') + }); + } + + if (didManager === undefined) { + // A custom DidManager implementation was not specified, so + // instantiate a default with in-memory store. + didManager = new DidManager({ + didMethods : [DidIonMethod, DidKeyMethod], + store : new DidStoreDwn() + }); + } + + if (didResolver === undefined) { + // A custom DidManager implementation was not specified, so + // instantiate a default with in-memory store. + didResolver = new DidResolver({ didResolvers: [DidIonMethod, DidKeyMethod] }); + } + + if (dwnManager === undefined) { + // A custom DwnManager implementation was not specified, so + // instantiate a default. + dwnManager = await DwnManager.create({ didResolver }); + } + + if (identityManager === undefined) { + // A custom IdentityManager implementation was not specified, so + // instantiate a default that uses a DWN store. + identityManager = new IdentityManager({ + store: new IdentityStoreDwn() + }); + } + + if (keyManager === undefined) { + // A custom KeyManager implementation was not specified, so + // instantiate a default with KMSs. + const localKmsDwn = new LocalKms({ + kmsName : 'local', + keyStore : new KeyStoreDwn({ schema: 'https://identity.foundation/schemas/web5/kms-key' }), + privateKeyStore : new PrivateKeyStoreDwn() + }); + const localKmsMemory = new LocalKms({ + kmsName: 'memory' + }); + keyManager = new KeyManager({ + kms: { + local : localKmsDwn, + memory : localKmsMemory + }, + store: new KeyStoreDwn({ schema: 'https://identity.foundation/schemas/web5/managed-key' }) + }); + } + + if (rpcClient === undefined) { + // A custom RPC Client implementation was not specified, so + // instantiate a default. + rpcClient = new Web5RpcClient(); + } + + // Instantiate the Identity Agent. + const agent = new Web5ProxyAgent({ + agentDid, + appData, + didManager, + didResolver, + dwnManager, + keyManager, + identityManager, + rpcClient + }); + + return agent; + } + + async firstLaunch(): Promise { + // Check whether data vault is already initialized. + const { initialized } = await this.appData.getStatus(); + return initialized === false; + } + + /** + * Executed once the first time the Identity Agent is launched. + * The passphrase should be input by the end-user. + * */ + async initialize(options: { passphrase: string }) { + const { passphrase } = options; + + // Generate an Ed25519 key pair for the Identity Agent. + const agentKeyPair = await new EdDsaAlgorithm().generateKey({ + algorithm : { name: 'EdDSA', namedCurve: 'Ed25519' }, + extractable : true, + keyUsages : ['sign', 'verify'] + }); + + /** Initialize the AppDataStore with the Identity Agent's + * private key and passphrase, which also unlocks the data vault. */ + await this.appData.initialize({ + passphrase : passphrase, + keyPair : agentKeyPair, + }); + } + + async processDidRequest(_request: ProcessDidRequest): Promise { + throw new Error('Not implemented'); + } + + async processDwnRequest(request: ProcessDwnRequest): Promise { + return this.dwnManager.processRequest(request); + } + + async processVcRequest(_request: ProcessVcRequest): Promise { + throw new Error('Not implemented'); + } + + async sendDidRequest(_request: SendDidRequest): Promise { + throw new Error('Not implemented'); + } + + async sendDwnRequest(request: SendDwnRequest): Promise { + return this.dwnManager.sendRequest(request); + } + + async sendVcRequest(_request: SendVcRequest): Promise { + throw new Error('Not implemented'); + } + + async start(options: { passphrase: string }) { + const { passphrase } = options; + + if (await this.firstLaunch()) { + // 1A. Agent's first launch so initialize. + await this.initialize({ passphrase }); + } else { + // 1B. Agent was previously initialized. + // Unlock the data vault and cache the vault unlock key (VUK) in memory. + await this.appData.unlock({ passphrase }); + } + + // 2. Set the Identity Agent's root did:key identifier. + this.agentDid = await this.appData.getDid(); + + // 3. Import the Identity Agent's private key into the KeyManager. + const defaultSigningKey = cryptoToPortableKeyPair({ + cryptoKeyPair: { + privateKey : await this.appData.getPrivateKey(), + publicKey : await this.appData.getPublicKey() + }, + keyData: { + alias : await this.didManager.getDefaultSigningKey({ did: this.agentDid }), + kms : 'memory' + } + }); + + // Import the Agent's signing key pair to the in-memory KMS key stores. + await this.keyManager.setDefaultSigningKey({ key: defaultSigningKey }); + } +} \ No newline at end of file diff --git a/packages/proxy-agent/tests/proxy-agent.spec.ts b/packages/proxy-agent/tests/proxy-agent.spec.ts new file mode 100644 index 000000000..01cdc2810 --- /dev/null +++ b/packages/proxy-agent/tests/proxy-agent.spec.ts @@ -0,0 +1,87 @@ +import chai, { expect } from 'chai'; +import chaiAsPromised from 'chai-as-promised'; +import { TestManagedAgent } from '@web5/agent'; + +import { Web5ProxyAgent } from '../src/proxy-agent.js'; + +chai.use(chaiAsPromised); + +// NOTE: @noble/secp256k1 requires globalThis.crypto polyfill for node.js <=18: https://github.com/paulmillr/noble-secp256k1/blob/main/README.md#usage +// Remove when we move off of node.js v18 to v20, earliest possible time would be Oct 2023: https://github.com/nodejs/release#release-schedule +// NOTE: @noble/secp256k1 requires globalThis.crypto polyfill for node.js <=18: https://github.com/paulmillr/noble-secp256k1/blob/main/README.md#usage +// Remove when we move off of node.js v18 to v20, earliest possible time would be Oct 2023: https://github.com/nodejs/release#release-schedule +import { webcrypto } from 'node:crypto'; +// @ts-ignore +if (!globalThis.crypto) globalThis.crypto = webcrypto; + +describe('Web5ProxyAgent', () => { + + const agentStoreTypes = ['dwn', 'memory'] as const; + agentStoreTypes.forEach((agentStoreType) => { + + describe(`with ${agentStoreType} data stores`, () => { + let testAgent: TestManagedAgent; + + before(async () => { + testAgent = await TestManagedAgent.create({ + agentClass : Web5ProxyAgent, + agentStores : agentStoreType + }); + }); + + beforeEach(async () => { + await testAgent.clearStorage(); + }); + + after(async () => { + await testAgent.clearStorage(); + await testAgent.closeStorage(); + }); + + describe('firstLaunch()', () => { + it('returns true the first time the Identity Agent runs', async () => { + await expect(testAgent.agent.firstLaunch()).to.eventually.be.true; + }); + + it('returns false after Identity Agent initialization', async () => { + await expect(testAgent.agent.firstLaunch()).to.eventually.be.true; + + await testAgent.agent.initialize({ passphrase: 'test' }); + await expect(testAgent.agent.firstLaunch()).to.eventually.be.false; + }); + }); + + if (agentStoreType === 'dwn') { + describe('subsequent launches', () => { + it('can access stored identifiers after second launch', async () => { + // First launch and initialization. + await testAgent.agent.start({ passphrase: 'test' }); + + // Create and persist a new Identity (with DID and Keys). + const socialIdentity = await testAgent.agent.identityManager.create({ + name : 'Social', + didMethod : 'key', + kms : 'local' + }); + + // Simulate terminating and restarting an app. + testAgent.closeStorage(); + testAgent = await TestManagedAgent.create({ + agentClass : Web5ProxyAgent, + agentStores : 'dwn' + }); + await testAgent.agent.start({ passphrase: 'test' }); + + // Try to get the identity and verify it exists. + const storedIdentity = await testAgent.agent.identityManager.get({ + did : socialIdentity.did, + context : socialIdentity.did + }); + expect(storedIdentity).to.have.property('did', socialIdentity.did); + }); + }); + } + }); + }); + +}); diff --git a/packages/web5/tests/tsconfig.json b/packages/proxy-agent/tests/tsconfig.json similarity index 100% rename from packages/web5/tests/tsconfig.json rename to packages/proxy-agent/tests/tsconfig.json diff --git a/packages/web5-agent/tsconfig.cjs.json b/packages/proxy-agent/tsconfig.cjs.json similarity index 100% rename from packages/web5-agent/tsconfig.cjs.json rename to packages/proxy-agent/tsconfig.cjs.json diff --git a/packages/web5-proxy-agent/tsconfig.json b/packages/proxy-agent/tsconfig.json similarity index 91% rename from packages/web5-proxy-agent/tsconfig.json rename to packages/proxy-agent/tsconfig.json index c8ce1cc3d..fea2cf4f1 100644 --- a/packages/web5-proxy-agent/tsconfig.json +++ b/packages/proxy-agent/tsconfig.json @@ -1,5 +1,6 @@ { "compilerOptions": { + "strict": true, "lib": [ "DOM", "ES6" @@ -10,6 +11,7 @@ "declarationMap": true, "declarationDir": "dist/types", "outDir": "dist/esm", + "sourceMap": true, // `NodeNext` will throw compilation errors if relative import paths are missing file extension // reference: https://devblogs.microsoft.com/typescript/announcing-typescript-4-7/#ecmascript-module-support-in-node-js "moduleResolution": "NodeNext", @@ -17,10 +19,8 @@ }, "include": [ "src", - "typings" ], "exclude": [ - "node_modules", - "dist" + "node_modules" ] } \ No newline at end of file diff --git a/packages/user-agent/.c8rc.json b/packages/user-agent/.c8rc.json new file mode 100644 index 000000000..ab680f663 --- /dev/null +++ b/packages/user-agent/.c8rc.json @@ -0,0 +1,19 @@ +{ + "all": true, + "cache": false, + "extension": [ + ".js" + ], + "include": [ + "tests/compiled/src/**" + ], + "exclude": [ + "tests/compiled/src/index.js", + "tests/compiled/src/types.js", + "tests/compiled/src/types/**" + ], + "reporter": [ + "cobertura", + "text" + ] +} \ No newline at end of file diff --git a/packages/user-agent/.mocharc.json b/packages/user-agent/.mocharc.json new file mode 100644 index 000000000..5aa8c5bfe --- /dev/null +++ b/packages/user-agent/.mocharc.json @@ -0,0 +1,5 @@ +{ + "enable-source-maps": true, + "exit": true, + "spec": ["tests/compiled/**/*.spec.js"] +} \ No newline at end of file diff --git a/packages/user-agent/.vscode/launch.json b/packages/user-agent/.vscode/launch.json new file mode 100644 index 000000000..bc398db79 --- /dev/null +++ b/packages/user-agent/.vscode/launch.json @@ -0,0 +1,19 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "test:node", + "runtimeExecutable": "${workspaceFolder:root}/node_modules/.bin/mocha", + "console": "internalConsole", + "preLaunchTask": "build tests", + "skipFiles": [ + "/**" + ] + } + ] +} \ No newline at end of file diff --git a/packages/web5-proxy-agent/.vscode/tasks.json b/packages/user-agent/.vscode/tasks.json similarity index 92% rename from packages/web5-proxy-agent/.vscode/tasks.json rename to packages/user-agent/.vscode/tasks.json index 4acdcfd8d..8c5147274 100644 --- a/packages/web5-proxy-agent/.vscode/tasks.json +++ b/packages/user-agent/.vscode/tasks.json @@ -31,7 +31,7 @@ "type": "npm", "script": "build:tests:node", "options": { - "cwd": "${workspaceFolder:web5-proxy-agent}" + "cwd": "${workspaceFolder:user-agent}" } } ] diff --git a/packages/web5-proxy-agent/build/bundles.js b/packages/user-agent/build/bundles.js similarity index 91% rename from packages/web5-proxy-agent/build/bundles.js rename to packages/user-agent/build/bundles.js index c9119e67b..c77302f82 100644 --- a/packages/web5-proxy-agent/build/bundles.js +++ b/packages/user-agent/build/bundles.js @@ -11,6 +11,6 @@ esbuild.build({ esbuild.build({ ...browserConfig, format : 'iife', - globalName : 'Web5', + globalName : 'Web5UserAgent', outfile : 'dist/browser.js', }); \ No newline at end of file diff --git a/packages/user-agent/build/esbuild-browser-config.cjs b/packages/user-agent/build/esbuild-browser-config.cjs new file mode 100644 index 000000000..bd8bd99b1 --- /dev/null +++ b/packages/user-agent/build/esbuild-browser-config.cjs @@ -0,0 +1,30 @@ +/* eslint-disable @typescript-eslint/no-var-requires */ +const polyfillProviderPlugin = require('node-stdlib-browser/helpers/esbuild/plugin'); +const stdLibBrowser = require('node-stdlib-browser'); + +const requiredPolyfills = new Set(['crypto', 'node:crypto', 'stream']); + +// populate object containing lib -> polyfill path +const polyfills = {}; +for (let lib in stdLibBrowser) { + if (requiredPolyfills.has(lib)) { + const polyfill = stdLibBrowser[lib]; + polyfills[lib] = polyfill; + } +} + +/** @type {import('esbuild').BuildOptions} */ +module.exports = { + entryPoints : ['./src/index.ts'], + bundle : true, + format : 'esm', + sourcemap : true, + minify : true, + platform : 'browser', + target : ['chrome101', 'firefox108', 'safari16'], + inject : [require.resolve('node-stdlib-browser/helpers/esbuild/shim')], + plugins : [polyfillProviderPlugin(polyfills)], + define : { + 'global': 'globalThis', + }, +}; \ No newline at end of file diff --git a/packages/user-agent/karma.conf.cjs b/packages/user-agent/karma.conf.cjs new file mode 100644 index 000000000..6b7407b2c --- /dev/null +++ b/packages/user-agent/karma.conf.cjs @@ -0,0 +1,87 @@ +/* eslint-disable @typescript-eslint/no-var-requires */ +// Karma is what we're using to run our tests in browser environments +// Karma does not support .mjs + +// playwright acts as a safari executable on windows and mac +const playwright = require('@playwright/test'); +const esbuildBrowserConfig = require('./build/esbuild-browser-config.cjs'); + +// use playwright chrome exec path as run target for chromium tests +process.env.CHROME_BIN = playwright.chromium.executablePath(); + +// use playwright webkit exec path as run target for safari tests +process.env.WEBKIT_HEADLESS_BIN = playwright.webkit.executablePath(); + +// use playwright firefox exec path as run target for firefox tests +process.env.FIREFOX_BIN = playwright.firefox.executablePath(); + +module.exports = function (config) { + config.set({ + plugins: [ + 'karma-chrome-launcher', + 'karma-firefox-launcher', + 'karma-webkit-launcher', + 'karma-esbuild', + 'karma-mocha', + 'karma-mocha-reporter', + ], + + // frameworks to use + // available frameworks: https://www.npmjs.com/search?q=keywords:karma-adapter + frameworks: ['mocha'], + + client: { + // Increase Mocha's default timeout of 2 seconds to prevent timeouts during GitHub CI runs. + mocha: { + timeout: 10000 // 10 seconds + }, + // If an environment variable is defined, override the default test DWN URL. + testDwnUrl: process.env.TEST_DWN_URL, + }, + + // list of files / patterns to load in the browser + files: [ + { pattern: 'tests/**/*.spec.ts', watched: false }, + ], + + // preprocess matching files before serving them to the browser + // available preprocessors: https://www.npmjs.com/search?q=keywords:karma-preprocessor + preprocessors: { + 'tests/**/*.spec.ts': ['esbuild'], + }, + + esbuild: esbuildBrowserConfig, + + // list of files / patterns to exclude + exclude: [], + + // test results reporter to use + // available reporters: https://www.npmjs.com/search?q=keywords:karma-reporter + reporters: ['mocha'], + + // web server port + port: 9876, + + // enable / disable colors in the output (reporters and logs) + colors: true, + + // level of logging + // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || + // config.LOG_INFO || config.LOG_DEBUG + logLevel: config.LOG_INFO, + + concurrency: 1, + + // start these browsers + // available browser launchers: https://www.npmjs.com/search?q=keywords:karma-launcher + browsers: ['ChromeHeadless', 'FirefoxHeadless', 'WebkitHeadless'], + + // Continuous Integration mode + // if true, Karma captures browsers, runs the tests and exits + singleRun: true, + + // Increase browser timeouts to avoid DISCONNECTED messages during GitHub CI runs. + browserDisconnectTimeout : 10000, // default 2000 + browserDisconnectTolerance : 1, // default 0 + }); +}; diff --git a/packages/user-agent/package.json b/packages/user-agent/package.json new file mode 100644 index 000000000..7e9a2eae5 --- /dev/null +++ b/packages/user-agent/package.json @@ -0,0 +1,103 @@ +{ + "name": "@web5/user-agent", + "version": "0.2.0", + "type": "module", + "main": "./dist/cjs/index.js", + "module": "./dist/esm/index.js", + "types": "./dist/types/index.d.ts", + "scripts": { + "clean": "rimraf dist tests/compiled", + "build:esm": "rimraf dist/esm dist/types && npx tsc -p tsconfig.json", + "build:cjs": "rimraf dist/cjs && tsc -p tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > ./dist/cjs/package.json", + "build:browser": "rimraf dist/browser.mjs dist/browser.js && node build/bundles.js", + "build:tests:node": "rimraf tests/compiled && tsc -p tests/tsconfig.json", + "build": "npm run clean && npm run build:esm && npm run build:cjs && npm run build:browser", + "lint": "eslint . --ext .ts --max-warnings 0", + "lint:fix": "eslint . --ext .ts --fix", + "test:node": "npm run build:tests:node && c8 mocha", + "test:browser": "karma start karma.conf.cjs" + }, + "homepage": "https://github.com/TBD54566975/web5-js/tree/main/packages/user-agent#readme", + "bugs": "https://github.com/TBD54566975/web5-js/issues", + "repository": { + "type": "git", + "url": "git+https://github.com/TBD54566975/web5-js", + "directory": "packages/user-agent" + }, + "license": "Apache-2.0", + "contributors": [ + { + "name": "Daniel Buchner", + "url": "https://github.com/csuwildcat" + }, + { + "name": "Frank Hinek", + "url": "https://github.com/frankhinek" + }, + { + "name": "Moe Jangda", + "url": "https://github.com/mistermoe" + } + ], + "files": [ + "dist", + "src" + ], + "exports": { + ".": { + "types": "./dist/types/index.d.ts", + "import": "./dist/esm/index.js", + "require": "./dist/cjs/index.js" + } + }, + "react-native": "./dist/esm/index.js", + "keywords": [ + "decentralized", + "decentralized-applications", + "decentralized-identity", + "decentralized-web", + "vcs", + "verifiable credentials", + "web5" + ], + "publishConfig": { + "access": "public" + }, + "engines": { + "node": ">=18.0.0" + }, + "dependencies": { + "@web5/agent": "0.2.0", + "@web5/common": "0.2.0", + "@web5/crypto": "0.2.0", + "@web5/dids": "0.2.0" + }, + "devDependencies": { + "@playwright/test": "1.36.2", + "@types/chai": "4.3.5", + "@types/chai-as-promised": "7.1.5", + "@types/eslint": "8.44.2", + "@types/mocha": "10.0.1", + "@typescript-eslint/eslint-plugin": "6.4.0", + "@typescript-eslint/parser": "6.4.0", + "c8": "8.0.1", + "chai": "4.3.7", + "chai-as-promised": "7.1.1", + "esbuild": "0.16.17", + "eslint": "8.47.0", + "eslint-plugin-mocha": "10.1.0", + "karma": "6.4.1", + "karma-chai": "0.1.0", + "karma-chrome-launcher": "3.1.1", + "karma-esbuild": "2.2.5", + "karma-firefox-launcher": "2.1.2", + "karma-mocha": "2.0.1", + "karma-mocha-reporter": "2.2.5", + "karma-webkit-launcher": "2.1.0", + "mocha": "10.2.0", + "node-stdlib-browser": "1.2.0", + "playwright": "1.36.2", + "rimraf": "4.4.0", + "typescript": "5.1.6" + } +} diff --git a/packages/user-agent/src/index.ts b/packages/user-agent/src/index.ts new file mode 100644 index 000000000..278c66aaf --- /dev/null +++ b/packages/user-agent/src/index.ts @@ -0,0 +1 @@ +export * from './user-agent.js'; \ No newline at end of file diff --git a/packages/user-agent/src/user-agent.ts b/packages/user-agent/src/user-agent.ts new file mode 100644 index 000000000..a69deca8c --- /dev/null +++ b/packages/user-agent/src/user-agent.ts @@ -0,0 +1,242 @@ +import type { + DwnRpc, + VcResponse, + DidResponse, + DwnResponse, + AppDataStore, + SendVcRequest, + SendDidRequest, + SendDwnRequest, + ProcessVcRequest, + Web5ManagedAgent, + ProcessDwnRequest, + ProcessDidRequest, +} from '@web5/agent'; + +import { LevelStore } from '@web5/common'; +import { EdDsaAlgorithm } from '@web5/crypto'; +import { DidIonMethod, DidKeyMethod, DidResolverCacheLevel, DidResolver } from '@web5/dids'; +import { + LocalKms, + DidManager, + DwnManager, + KeyManager, + DidStoreDwn, + KeyStoreDwn, + AppDataVault, + Web5RpcClient, + IdentityManager, + IdentityStoreDwn, + PrivateKeyStoreDwn, + cryptoToPortableKeyPair, +} from '@web5/agent'; + +export type Web5UserAgentOptions = { + agentDid: string; + appData: AppDataStore; + didManager: DidManager; + didResolver: DidResolver; + dwnManager: DwnManager; + identityManager: IdentityManager; + keyManager: KeyManager; + rpcClient: DwnRpc; +} + +export class Web5UserAgent implements Web5ManagedAgent { + agentDid: string; + appData: AppDataStore; + didManager: DidManager; + didResolver: DidResolver; + dwnManager: DwnManager; + identityManager: IdentityManager; + keyManager: KeyManager; + rpcClient: DwnRpc; + + constructor(options: Web5UserAgentOptions) { + this.agentDid = options.agentDid; + this.appData = options.appData; + this.keyManager = options.keyManager; + this.didManager = options.didManager; + this.didResolver = options.didResolver; + this.dwnManager = options.dwnManager; + this.identityManager = options.identityManager; + this.rpcClient = options.rpcClient; + + // Set this agent to be the default agent. + this.didManager.agent = this; + this.dwnManager.agent = this; + this.identityManager.agent = this; + this.keyManager.agent = this; + } + + static async create(options: Partial = {}): Promise { + let { agentDid, appData, didManager, didResolver, dwnManager, identityManager, keyManager, rpcClient } = options; + + if (agentDid === undefined) { + // An Agent DID was not specified, so set to empty string. + agentDid = ''; + } + + if (appData === undefined) { + /** A custom AppDataStore implementation was not specified, so + * instantiate a LevelDB backed secure AppDataVault. */ + appData = new AppDataVault({ + store: new LevelStore('DATA/AGENT/APPDATA') + }); + } + + if (didManager === undefined) { + /** A custom DidManager implementation was not specified, so + * instantiate a default that uses a DWN-backed store. */ + didManager = new DidManager({ + didMethods : [DidIonMethod, DidKeyMethod], + store : new DidStoreDwn() + }); + } + + if (didResolver === undefined) { + /** A custom DidManager implementation was not specified, so + * instantiate a default that uses a DWN-backed store and + * LevelDB-backed resolution cache. */ + didResolver = new DidResolver({ + cache : new DidResolverCacheLevel(), + didResolvers : [DidIonMethod, DidKeyMethod] + }); + } + + if (dwnManager === undefined) { + /** A custom DwnManager implementation was not specified, so + * instantiate a default. */ + dwnManager = await DwnManager.create({ didResolver }); + } + + if (identityManager === undefined) { + /** A custom IdentityManager implementation was not specified, so + * instantiate a default that uses a DWN-backed store. */ + identityManager = new IdentityManager({ + store: new IdentityStoreDwn() + }); + } + + if (keyManager === undefined) { + /** A custom KeyManager implementation was not specified, so + * instantiate a default with KMSs that use a DWN-backed store. */ + const localKmsDwn = new LocalKms({ + kmsName : 'local', + keyStore : new KeyStoreDwn({ schema: 'https://identity.foundation/schemas/web5/kms-key' }), + privateKeyStore : new PrivateKeyStoreDwn() + }); + const localKmsMemory = new LocalKms({ + kmsName: 'memory' + }); + keyManager = new KeyManager({ + kms: { + local : localKmsDwn, + memory : localKmsMemory + }, + store: new KeyStoreDwn({ schema: 'https://identity.foundation/schemas/web5/managed-key' }) + }); + } + + if (rpcClient === undefined) { + // A custom RPC Client implementation was not specified, so + // instantiate a default. + rpcClient = new Web5RpcClient(); + } + + // Instantiate the Agent. + const agent = new Web5UserAgent({ + agentDid, + appData, + didManager, + didResolver, + dwnManager, + keyManager, + identityManager, + rpcClient + }); + + return agent; + } + + async firstLaunch(): Promise { + // Check whether data vault is already initialized. + const { initialized } = await this.appData.getStatus(); + return initialized === false; + } + + /** Executed once the first time the Agent is launched. + * The passphrase should be input by the end-user. */ + async initialize(options: { passphrase: string }) { + const { passphrase } = options; + + // Generate an Ed25519 key pair for the Agent. + const agentKeyPair = await new EdDsaAlgorithm().generateKey({ + algorithm : { name: 'EdDSA', namedCurve: 'Ed25519' }, + extractable : true, + keyUsages : ['sign', 'verify'] + }); + + /** Initialize the AppDataStore with the Agent's + * private key and passphrase, which also unlocks the data vault. */ + await this.appData.initialize({ + passphrase : passphrase, + keyPair : agentKeyPair, + }); + } + + async processDidRequest(_request: ProcessDidRequest): Promise { + throw new Error('Not implemented'); + } + + async processDwnRequest(request: ProcessDwnRequest): Promise { + return this.dwnManager.processRequest(request); + } + + async processVcRequest(_request: ProcessVcRequest): Promise { + throw new Error('Not implemented'); + } + + async sendDidRequest(_request: SendDidRequest): Promise { + throw new Error('Not implemented'); + } + + async sendDwnRequest(request: SendDwnRequest): Promise { + return this.dwnManager.sendRequest(request); + } + + async sendVcRequest(_request: SendVcRequest): Promise { + throw new Error('Not implemented'); + } + + async start(options: { passphrase: string }) { + const { passphrase } = options; + + if (await this.firstLaunch()) { + // 1A. Agent's first launch so initialize. + await this.initialize({ passphrase }); + } else { + // 1B. Agent was previously initialized. + // Unlock the data vault and cache the vault unlock key (VUK) in memory. + await this.appData.unlock({ passphrase }); + } + + // 2. Set the Agent's root did:key identifier. + this.agentDid = await this.appData.getDid(); + + // 3. Import the Agent's private key into the KeyManager. + const defaultSigningKey = cryptoToPortableKeyPair({ + cryptoKeyPair: { + privateKey : await this.appData.getPrivateKey(), + publicKey : await this.appData.getPublicKey() + }, + keyData: { + alias : await this.didManager.getDefaultSigningKey({ did: this.agentDid }), + kms : 'memory' + } + }); + + // Import the Agent's signing key pair to the in-memory KMS key stores. + await this.keyManager.setDefaultSigningKey({ key: defaultSigningKey }); + } +} \ No newline at end of file diff --git a/packages/user-agent/tests/tsconfig.json b/packages/user-agent/tests/tsconfig.json new file mode 100644 index 000000000..7c6d2c8e7 --- /dev/null +++ b/packages/user-agent/tests/tsconfig.json @@ -0,0 +1,15 @@ +{ + "extends": "../tsconfig.json", + "compilerOptions": { + "outDir": "compiled", + "declarationDir": "compiled/types", + "sourceMap": true, + }, + "include": [ + "../src", + ".", + ], + "exclude": [ + "./compiled" + ] +} \ No newline at end of file diff --git a/packages/user-agent/tests/user-agent.spec.ts b/packages/user-agent/tests/user-agent.spec.ts new file mode 100644 index 000000000..320f10d85 --- /dev/null +++ b/packages/user-agent/tests/user-agent.spec.ts @@ -0,0 +1,87 @@ +import chai, { expect } from 'chai'; +import chaiAsPromised from 'chai-as-promised'; +import { TestManagedAgent } from '@web5/agent'; + +import { Web5UserAgent } from '../src/user-agent.js'; + +chai.use(chaiAsPromised); + +// NOTE: @noble/secp256k1 requires globalThis.crypto polyfill for node.js <=18: https://github.com/paulmillr/noble-secp256k1/blob/main/README.md#usage +// Remove when we move off of node.js v18 to v20, earliest possible time would be Oct 2023: https://github.com/nodejs/release#release-schedule +// NOTE: @noble/secp256k1 requires globalThis.crypto polyfill for node.js <=18: https://github.com/paulmillr/noble-secp256k1/blob/main/README.md#usage +// Remove when we move off of node.js v18 to v20, earliest possible time would be Oct 2023: https://github.com/nodejs/release#release-schedule +import { webcrypto } from 'node:crypto'; +// @ts-ignore +if (!globalThis.crypto) globalThis.crypto = webcrypto; + +describe('Web5UserAgent', () => { + + const agentStoreTypes = ['dwn', 'memory'] as const; + agentStoreTypes.forEach((agentStoreType) => { + + describe(`with ${agentStoreType} data stores`, () => { + let testAgent: TestManagedAgent; + + before(async () => { + testAgent = await TestManagedAgent.create({ + agentClass : Web5UserAgent, + agentStores : agentStoreType + }); + }); + + beforeEach(async () => { + await testAgent.clearStorage(); + }); + + after(async () => { + await testAgent.clearStorage(); + await testAgent.closeStorage(); + }); + + describe('firstLaunch()', () => { + it('returns true the first time the Identity Agent runs', async () => { + await expect(testAgent.agent.firstLaunch()).to.eventually.be.true; + }); + + it('returns false after Identity Agent initialization', async () => { + await expect(testAgent.agent.firstLaunch()).to.eventually.be.true; + + await testAgent.agent.initialize({ passphrase: 'test' }); + await expect(testAgent.agent.firstLaunch()).to.eventually.be.false; + }); + }); + + if (agentStoreType === 'dwn') { + describe('subsequent launches', () => { + it('can access stored identifiers after second launch', async () => { + // First launch and initialization. + await testAgent.agent.start({ passphrase: 'test' }); + + // Create and persist a new Identity (with DID and Keys). + const socialIdentity = await testAgent.agent.identityManager.create({ + name : 'Social', + didMethod : 'key', + kms : 'local' + }); + + // Simulate terminating and restarting an app. + testAgent.closeStorage(); + testAgent = await TestManagedAgent.create({ + agentClass : Web5UserAgent, + agentStores : 'dwn' + }); + await testAgent.agent.start({ passphrase: 'test' }); + + // Try to get the identity and verify it exists. + const storedIdentity = await testAgent.agent.identityManager.get({ + did : socialIdentity.did, + context : socialIdentity.did + }); + expect(storedIdentity).to.have.property('did', socialIdentity.did); + }); + }); + } + }); + }); + +}); diff --git a/packages/web5-proxy-agent/tsconfig.cjs.json b/packages/user-agent/tsconfig.cjs.json similarity index 100% rename from packages/web5-proxy-agent/tsconfig.cjs.json rename to packages/user-agent/tsconfig.cjs.json diff --git a/packages/user-agent/tsconfig.json b/packages/user-agent/tsconfig.json new file mode 100644 index 000000000..b29e4e7e1 --- /dev/null +++ b/packages/user-agent/tsconfig.json @@ -0,0 +1,27 @@ +{ + "compilerOptions": { + "strict": true, + "lib": [ + "DOM", + "ES6" + ], + "allowJs": true, + "target": "es6", + "module": "ESNext", // Required for enabling JavaScript import assertion support + "declaration": true, + "declarationMap": true, + "declarationDir": "dist/types", + "outDir": "dist/esm", + "sourceMap": true, + // `NodeNext` will throw compilation errors if relative import paths are missing file extension + // reference: https://devblogs.microsoft.com/typescript/announcing-typescript-4-7/#ecmascript-module-support-in-node-js + "moduleResolution": "NodeNext", + "esModuleInterop": true + }, + "include": [ + "src", + ], + "exclude": [ + "node_modules" + ] +} \ No newline at end of file diff --git a/packages/web5-agent/build/esbuild-browser-config.cjs b/packages/web5-agent/build/esbuild-browser-config.cjs deleted file mode 100644 index ae37c97f0..000000000 --- a/packages/web5-agent/build/esbuild-browser-config.cjs +++ /dev/null @@ -1,13 +0,0 @@ -/** @type {import('esbuild').BuildOptions} */ -module.exports = { - entryPoints : ['./src/main.ts'], - bundle : true, - format : 'esm', - sourcemap : true, - minify : true, - platform : 'browser', - target : ['chrome101', 'firefox108', 'safari16'], - define : { - 'global': 'globalThis', - }, -}; diff --git a/packages/web5/src/main.ts b/packages/web5/src/main.ts deleted file mode 100644 index a3c2ca4ff..000000000 --- a/packages/web5/src/main.ts +++ /dev/null @@ -1,4 +0,0 @@ -export type { Record } from './record.js'; - -export * from './web5.js'; -export { DateSort } from '@tbd54566975/dwn-sdk-js'; \ No newline at end of file diff --git a/web5-js.code-workspace b/web5-js.code-workspace index 850885daf..7a2018698 100644 --- a/web5-js.code-workspace +++ b/web5-js.code-workspace @@ -1,104 +1,110 @@ { - "folders": [ - { - // Source root - "name": "root", - "path": "." - }, - { - // @tbd54566975/common - "name": "common", - "path": "packages/common", - }, - { - // @tbd54566975/credentials - "name": "credentials", - "path": "packages/credentials", - }, - { - // @tbd54566975/crypto - "name": "crypto", - "path": "packages/crypto", - }, - { - // @tbd54566975/dids - "name": "dids", - "path": "packages/dids", - }, - { - // @tbd54566975/web5 - "name": "web5", - "path": "packages/web5", - }, - { - // @tbd54566975/web5-agent - "name": "web5-agent", - "path": "packages/web5-agent", - }, - { - // @tbd54566975/web5-proxy-agent - "name": "web5-proxy-agent", - "path": "packages/web5-proxy-agent", - }, - { - // @tbd54566975/web5-user-agent - "name": "web5-user-agent", - "path": "packages/web5-user-agent", - }, - ], - "settings": { - "eslint.workingDirectories": [ - { - "mode": "auto" - } - ], - }, - "launch": { - "version": "0.2.0", - "configurations": [ - { - "type": "node", - "request": "launch", - "name": "Test All - Node", - "runtimeExecutable": "${workspaceFolder:root}/node_modules/.bin/mocha", - "runtimeArgs": [ - "${workspaceFolder:root}/packages/**/tests/compiled/**/*.spec.js" - ], - "preLaunchTask": "build tests", - "console": "internalConsole", - "internalConsoleOptions": "openOnSessionStart", - } - ] - }, - "tasks": { - "version": "2.0.0", - "tasks": [ - { - "label": "Build All", - "type": "shell", - "command": "npm run build", - "problemMatcher": [], - "group": { - "kind": "build", - "isDefault": true - } - }, - { - "label": "build tests", - "type": "shell", - "command": "npm", - "args": [ - "run", - "build:tests:node", - "--ws" - ], - "problemMatcher": [ - "$tsc" - ], - "options": { - "cwd": "${workspaceFolder:root}" - } - }, - ] - } + "folders": [ + { + // Source root + "name": "root", + "path": "." + }, + { + // @web5/agent + "name": "agent", + "path": "packages/agent", + }, + { + // @web5/api + "name": "api", + "path": "packages/api", + }, + { + // @web5/common + "name": "common", + "path": "packages/common", + }, + { + // @web5/credentials + "name": "credentials", + "path": "packages/credentials", + }, + { + // @web5/crypto + "name": "crypto", + "path": "packages/crypto", + }, + { + // @web5/dids + "name": "dids", + "path": "packages/dids", + }, + { + // @web5/identity-agent + "name": "identity-agent", + "path": "packages/identity-agent", + }, + { + // @web5/proxy-agent + "name": "proxy-agent", + "path": "packages/proxy-agent", + }, + { + // @web5/user-agent + "name": "user-agent", + "path": "packages/user-agent", + }, + ], + "settings": { + "eslint.workingDirectories": [ + { + "mode": "auto" + } + ], + "npm.packageManager": "npm" + }, + "launch": { + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Test All - Node", + "runtimeExecutable": "${workspaceFolder:root}/node_modules/.bin/mocha", + "runtimeArgs": [ + "${workspaceFolder:root}/packages/**/tests/compiled/**/*.spec.js" + ], + "preLaunchTask": "build tests", + "console": "internalConsole", + "internalConsoleOptions": "openOnSessionStart", + } + ] + }, + "tasks": { + "version": "2.0.0", + "tasks": [ + { + "label": "Build All", + "type": "shell", + "command": "npm run build", + "problemMatcher": [], + "group": { + "kind": "build", + "isDefault": true + } + }, + { + "label": "build tests", + "type": "shell", + "command": "npm", + "args": [ + "run", + "build:tests:node", + "--ws" + ], + "problemMatcher": [ + "$tsc" + ], + "options": { + "cwd": "${workspaceFolder:root}" + } + }, + ] + } } \ No newline at end of file