├── .changeset ├── README.md └── config.json ├── .codesandbox └── tasks.json ├── .github ├── dependabot.yml └── workflows │ ├── alpha-npm.yml │ ├── codeql.yml │ ├── docs-ci.yml │ ├── docs-publish.yml │ ├── release-notify.yml │ ├── release-snapshot.yml │ ├── release.yml │ ├── reports.yml │ ├── scorecard.yml │ ├── security.yml │ ├── take.yml │ ├── tbdocs-commenter.yml │ └── tests-ci.yml ├── .gitignore ├── .gitmodules ├── .vscode ├── extensions.json └── settings.json ├── CODEOWNERS ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── GOVERNANCE.md ├── LICENSE ├── README.md ├── audit-ci.json ├── bin ├── .node-20.15.1.pkg ├── .pnpm-9.6.0.pkg ├── README.hermit.md ├── activate-hermit ├── hermit ├── hermit.hcl ├── node ├── npm ├── npx └── pnpm ├── codecov.yml ├── eslint.config.cjs ├── examples └── wallet-connect.html ├── package.json ├── packages ├── agent │ ├── .c8rc.json │ ├── .mocharc.json │ ├── .vscode │ │ ├── launch.json │ │ └── tasks.json │ ├── CHANGELOG.md │ ├── build │ │ ├── bundles.js │ │ ├── cjs-bundle.js │ │ ├── esbuild-browser-config.cjs │ │ └── esbuild-tests.cjs │ ├── package.json │ ├── src │ │ ├── agent-did-resolver-cache.ts │ │ ├── bearer-identity.ts │ │ ├── connect.ts │ │ ├── crypto-api.ts │ │ ├── did-api.ts │ │ ├── dwn-api.ts │ │ ├── dwn-registrar.ts │ │ ├── hd-identity-vault.ts │ │ ├── identity-api.ts │ │ ├── index.ts │ │ ├── local-key-manager.ts │ │ ├── oidc.ts │ │ ├── permissions-api.ts │ │ ├── prototyping │ │ │ ├── clients │ │ │ │ ├── dwn-rpc-types.ts │ │ │ │ ├── dwn-server-info-cache-memory.ts │ │ │ │ ├── http-dwn-rpc-client.ts │ │ │ │ ├── json-rpc-socket.ts │ │ │ │ ├── json-rpc.ts │ │ │ │ ├── server-info-types.ts │ │ │ │ └── web-socket-clients.ts │ │ │ ├── common │ │ │ │ ├── object.ts │ │ │ │ └── type-utils.ts │ │ │ ├── crypto │ │ │ │ ├── algorithms │ │ │ │ │ ├── aes-gcm.ts │ │ │ │ │ ├── aes-kw.ts │ │ │ │ │ ├── ecdsa.ts │ │ │ │ │ ├── eddsa.ts │ │ │ │ │ ├── hkdf.ts │ │ │ │ │ └── pbkdf2.ts │ │ │ │ ├── crypto-error.ts │ │ │ │ ├── dsa.ts │ │ │ │ ├── jose │ │ │ │ │ ├── jwe-compact.ts │ │ │ │ │ ├── jwe-flattened.ts │ │ │ │ │ └── jwe.ts │ │ │ │ ├── primitives │ │ │ │ │ ├── aes-gcm.ts │ │ │ │ │ ├── aes-kw.ts │ │ │ │ │ ├── hkdf.ts │ │ │ │ │ └── pbkdf2.ts │ │ │ │ ├── types │ │ │ │ │ ├── cipher.ts │ │ │ │ │ ├── crypto-api.ts │ │ │ │ │ ├── key-converter.ts │ │ │ │ │ ├── key-deriver.ts │ │ │ │ │ ├── key-io.ts │ │ │ │ │ ├── key-manager.ts │ │ │ │ │ ├── key-wrapper.ts │ │ │ │ │ ├── params-direct.ts │ │ │ │ │ └── params-kms.ts │ │ │ │ └── utils.ts │ │ │ └── dids │ │ │ │ ├── resolver-cache-memory.ts │ │ │ │ └── utils.ts │ │ ├── rpc-client.ts │ │ ├── store-data-protocols.ts │ │ ├── store-data.ts │ │ ├── store-did.ts │ │ ├── store-identity.ts │ │ ├── store-key.ts │ │ ├── sync-api.ts │ │ ├── sync-engine-level.ts │ │ ├── test-harness.ts │ │ ├── types │ │ │ ├── agent.ts │ │ │ ├── dwn.ts │ │ │ ├── identity-vault.ts │ │ │ ├── identity.ts │ │ │ ├── key-manager.ts │ │ │ ├── permissions.ts │ │ │ ├── sync.ts │ │ │ └── vc.ts │ │ ├── utils-internal.ts │ │ └── utils.ts │ ├── tests │ │ ├── agent-did-resolver-cach.spec.ts │ │ ├── connect.spec.ts │ │ ├── crypto-api.spec.ts │ │ ├── did-api.spec.ts │ │ ├── dwn-api.spec.ts │ │ ├── fixtures │ │ │ └── protocol-definitions │ │ │ │ └── email.json │ │ ├── hd-identity-vault.spec.ts │ │ ├── identity-api.spec.ts │ │ ├── local-key-manager.spec.ts │ │ ├── permissions-api.spec.ts │ │ ├── prototyping │ │ │ ├── clients │ │ │ │ ├── dwn-server-info-cache.spec.ts │ │ │ │ ├── http-dwn-rpc-client.spec.ts │ │ │ │ ├── json-rpc-socket.spec.ts │ │ │ │ └── ws-dwn-rpc-client.spec.ts │ │ │ ├── crypto │ │ │ │ ├── algorithms │ │ │ │ │ └── aes-kw.spec.ts │ │ │ │ ├── fixtures │ │ │ │ │ └── test-vectors │ │ │ │ │ │ └── hkdf.ts │ │ │ │ ├── jose │ │ │ │ │ ├── jwe-compact.spec.ts │ │ │ │ │ └── jwe-flattened.spec.ts │ │ │ │ └── primitives │ │ │ │ │ ├── aes-kw.spec.ts │ │ │ │ │ └── hkdf.spec.ts │ │ │ └── dids │ │ │ │ └── resolver-cache-memory.spec.ts │ │ ├── rpc-client.spec.ts │ │ ├── store-data.spec.ts │ │ ├── store-did.spec.ts │ │ ├── store-identity.spec.ts │ │ ├── store-key.spec.ts │ │ ├── sync-api.spec.ts │ │ ├── sync-engine-level.spec.ts │ │ ├── tsconfig.json │ │ ├── utils-internal.spec.ts │ │ ├── utils.spec.ts │ │ └── utils │ │ │ ├── runtimes.ts │ │ │ ├── test-agent.ts │ │ │ └── test-config.ts │ ├── tsconfig.cjs.json │ ├── tsconfig.json │ └── web-test-runner.config.cjs ├── api │ ├── .c8rc.json │ ├── .mocharc.json │ ├── .vscode │ │ ├── launch.json │ │ └── tasks.json │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── build │ │ ├── bundles.js │ │ ├── esbuild-browser-config.cjs │ │ └── esbuild-tests.cjs │ ├── package.json │ ├── src │ │ ├── did-api.ts │ │ ├── dwn-api.ts │ │ ├── grant-revocation.ts │ │ ├── index.ts │ │ ├── permission-grant.ts │ │ ├── permission-request.ts │ │ ├── protocol.ts │ │ ├── record.ts │ │ ├── subscription-util.ts │ │ ├── utils.ts │ │ ├── vc-api.ts │ │ └── web5.ts │ ├── tests │ │ ├── chai-plugins.d.ts │ │ ├── did-api.spec.ts │ │ ├── dwn-api.spec.ts │ │ ├── fixtures │ │ │ └── protocol-definitions │ │ │ │ ├── email.json │ │ │ │ ├── notes.json │ │ │ │ └── photos.json │ │ ├── permission-grant.spec.ts │ │ ├── permission-request.spec.ts │ │ ├── protocol.spec.ts │ │ ├── record.spec.ts │ │ ├── tsconfig.json │ │ ├── utils.spec.ts │ │ ├── utils │ │ │ ├── chai-plugins.ts │ │ │ ├── test-config.ts │ │ │ └── test-data-generator.ts │ │ ├── vc-api.spec.ts │ │ └── web5.spec.ts │ ├── tsconfig.cjs.json │ ├── tsconfig.json │ └── web-test-runner.config.cjs ├── browser │ ├── .c8rc.json │ ├── CHANGELOG.md │ ├── README.md │ ├── build │ │ ├── esbuild-browser-config.cjs │ │ └── esbuild-tests.cjs │ ├── package.json │ ├── src │ │ ├── index.ts │ │ └── web-features.ts │ ├── tests │ │ ├── tsconfig.json │ │ └── web-features.spec.ts │ ├── tsconfig.json │ └── web-test-runner.config.cjs ├── common │ ├── .c8rc.json │ ├── .mocharc.json │ ├── .vscode │ │ ├── launch.json │ │ └── tasks.json │ ├── CHANGELOG.md │ ├── build │ │ ├── bundles.js │ │ ├── cjs-bundle.js │ │ ├── esbuild-browser-config.cjs │ │ └── esbuild-tests.cjs │ ├── package.json │ ├── src │ │ ├── cache.ts │ │ ├── convert.ts │ │ ├── index.ts │ │ ├── logger.ts │ │ ├── multicodec.ts │ │ ├── object.ts │ │ ├── stores.ts │ │ ├── stream-node.ts │ │ ├── stream.ts │ │ ├── type-utils.ts │ │ └── types.ts │ ├── tests │ │ ├── cache.spec.ts │ │ ├── convert.spec.ts │ │ ├── multicodec.spec.ts │ │ ├── object.spec.ts │ │ ├── stores.spec.ts │ │ ├── stream-node.spec.ts │ │ ├── stream.spec.ts │ │ ├── tsconfig.json │ │ └── type-utils.spec.ts │ ├── tsconfig.json │ └── web-test-runner.config.cjs ├── credentials │ ├── .c8rc.json │ ├── .mocharc.json │ ├── .vscode │ │ ├── launch.json │ │ └── tasks.json │ ├── CHANGELOG.md │ ├── README.md │ ├── build │ │ ├── bundles.js │ │ ├── esbuild-browser-config.cjs │ │ └── esbuild-tests.cjs │ ├── package.json │ ├── src │ │ ├── index.ts │ │ ├── jwt.ts │ │ ├── presentation-exchange.ts │ │ ├── status-list-credential.ts │ │ ├── utils.ts │ │ ├── validators.ts │ │ ├── verifiable-credential.ts │ │ └── verifiable-presentation.ts │ ├── tests │ │ ├── jwt.spec.ts │ │ ├── presentation-exchange.spec.ts │ │ ├── ssi-validator.spec.ts │ │ ├── status-list-credential.spec.ts │ │ ├── tsconfig.json │ │ ├── utils.spec.ts │ │ ├── verifiable-credential.spec.ts │ │ └── verifiable-presentation.spec.ts │ ├── tsconfig.cjs.json │ ├── tsconfig.json │ └── web-test-runner.config.cjs ├── crypto-aws-kms │ ├── .c8rc.json │ ├── .mocharc.json │ ├── .vscode │ │ ├── launch.json │ │ └── tasks.json │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── eslint.config.cjs │ ├── package.json │ ├── src │ │ ├── ecdsa.ts │ │ ├── index.ts │ │ ├── key-manager.ts │ │ └── utils.ts │ ├── tests │ │ ├── ecdsa.spec.ts │ │ ├── fixtures │ │ │ └── mock-ecdsa-secp256k1.ts │ │ ├── key-manager.spec.ts │ │ ├── tsconfig.json │ │ └── utils.spec.ts │ ├── tsconfig.cjs.json │ └── tsconfig.json ├── crypto │ ├── .c8rc.json │ ├── .mocharc.json │ ├── .vscode │ │ ├── launch.json │ │ └── tasks.json │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── build │ │ ├── bundles.js │ │ ├── esbuild-browser-config.cjs │ │ └── esbuild-tests.cjs │ ├── eslint.config.cjs │ ├── package.json │ ├── src │ │ ├── algorithms │ │ │ ├── aes-ctr.ts │ │ │ ├── aes-gcm.ts │ │ │ ├── crypto-algorithm.ts │ │ │ ├── ecdsa.ts │ │ │ ├── eddsa.ts │ │ │ └── sha-2.ts │ │ ├── index.ts │ │ ├── jose │ │ │ ├── jwe.ts │ │ │ ├── jwk.ts │ │ │ ├── jws.ts │ │ │ ├── jwt.ts │ │ │ └── utils.ts │ │ ├── local-key-manager.ts │ │ ├── primitives │ │ │ ├── aes-ctr.ts │ │ │ ├── aes-gcm.ts │ │ │ ├── concat-kdf.ts │ │ │ ├── ed25519.ts │ │ │ ├── pbkdf2.ts │ │ │ ├── secp256k1.ts │ │ │ ├── secp256r1.ts │ │ │ ├── sha256.ts │ │ │ ├── x25519.ts │ │ │ ├── xchacha20-poly1305.ts │ │ │ └── xchacha20.ts │ │ ├── types │ │ │ ├── cipher.ts │ │ │ ├── crypto-api.ts │ │ │ ├── hasher.ts │ │ │ ├── identifier.ts │ │ │ ├── key-compressor.ts │ │ │ ├── key-converter.ts │ │ │ ├── key-deriver.ts │ │ │ ├── key-generator.ts │ │ │ ├── key-io.ts │ │ │ ├── key-wrapper.ts │ │ │ ├── params-direct.ts │ │ │ ├── params-enclosed.ts │ │ │ ├── params-kms.ts │ │ │ └── signer.ts │ │ └── utils.ts │ ├── tests │ │ ├── algorithms │ │ │ ├── aes-ctr.spec.ts │ │ │ ├── aes-gcm.spec.ts │ │ │ ├── ecdsa.spec.ts │ │ │ ├── eddsa.spec.ts │ │ │ └── sha-2.spec.ts │ │ ├── fixtures │ │ │ └── test-vectors │ │ │ │ ├── aes-ctr │ │ │ │ ├── decrypt.json │ │ │ │ └── encrypt.json │ │ │ │ ├── aes-gcm │ │ │ │ ├── decrypt.json │ │ │ │ └── encrypt.json │ │ │ │ ├── ed25519 │ │ │ │ ├── bytes-to-private-key.json │ │ │ │ ├── bytes-to-public-key.json │ │ │ │ ├── compute-public-key.json │ │ │ │ ├── convert-private-key-to-x25519.json │ │ │ │ ├── convert-public-key-to-x25519.json │ │ │ │ ├── private-key-to-bytes.json │ │ │ │ └── public-key-to-bytes.json │ │ │ │ ├── jwk.ts │ │ │ │ ├── secp256k1 │ │ │ │ ├── bytes-to-private-key.json │ │ │ │ ├── bytes-to-public-key.json │ │ │ │ ├── get-curve-points.json │ │ │ │ ├── private-key-to-bytes.json │ │ │ │ ├── public-key-to-bytes.json │ │ │ │ ├── validate-private-key.json │ │ │ │ └── validate-public-key.json │ │ │ │ ├── secp256r1 │ │ │ │ ├── bytes-to-private-key.json │ │ │ │ ├── bytes-to-public-key.json │ │ │ │ ├── get-curve-points.json │ │ │ │ ├── private-key-to-bytes.json │ │ │ │ ├── public-key-to-bytes.json │ │ │ │ ├── validate-private-key.json │ │ │ │ └── validate-public-key.json │ │ │ │ ├── sha256 │ │ │ │ └── digest.json │ │ │ │ └── x25519 │ │ │ │ ├── bytes-to-private-key.json │ │ │ │ ├── bytes-to-public-key.json │ │ │ │ ├── private-key-to-bytes.json │ │ │ │ └── public-key-to-bytes.json │ │ ├── jose │ │ │ ├── jwk.spec.ts │ │ │ └── utils.spec.ts │ │ ├── local-key-manager.spec.ts │ │ ├── primitives │ │ │ ├── aes-ctr.spec.ts │ │ │ ├── aes-gcm.spec.ts │ │ │ ├── concat-kdf.spec.ts │ │ │ ├── ed25519.spec.ts │ │ │ ├── pbkdf2.spec.ts │ │ │ ├── secp256k1.spec.ts │ │ │ ├── secp256r1.spec.ts │ │ │ ├── sha256.spec.ts │ │ │ ├── x25519.spec.ts │ │ │ ├── xchacha20-poly1305.spec.ts │ │ │ └── xchacha20.spec.ts │ │ ├── tsconfig.json │ │ ├── utils.spec.ts │ │ └── utils │ │ │ └── runtimes.ts │ ├── tsconfig.cjs.json │ ├── tsconfig.json │ └── web-test-runner.config.cjs ├── dev-env │ ├── README.md │ └── docker-compose.yaml ├── dids │ ├── .c8rc.json │ ├── .mocharc.json │ ├── .vscode │ │ ├── launch.json │ │ └── tasks.json │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── build │ │ ├── buffer-polyfill.cjs │ │ ├── bundles.js │ │ ├── cjs-bundle.js │ │ ├── esbuild-browser-config.cjs │ │ └── esbuild-tests.cjs │ ├── package.json │ ├── src │ │ ├── bearer-did.ts │ │ ├── did-error.ts │ │ ├── did.ts │ │ ├── index.ts │ │ ├── methods │ │ │ ├── did-dht.ts │ │ │ ├── did-ion.ts │ │ │ ├── did-jwk.ts │ │ │ ├── did-key.ts │ │ │ ├── did-method.ts │ │ │ └── did-web.ts │ │ ├── resolver │ │ │ ├── resolver-cache-level.ts │ │ │ ├── resolver-cache-noop.ts │ │ │ └── universal-resolver.ts │ │ ├── types │ │ │ ├── did-core.ts │ │ │ ├── did-resolution.ts │ │ │ ├── multibase.ts │ │ │ └── portable-did.ts │ │ └── utils.ts │ ├── tests │ │ ├── bearer-did.spec.ts │ │ ├── did.spec.ts │ │ ├── fixtures │ │ │ └── test-vectors │ │ │ │ ├── did-dht │ │ │ │ ├── vector-1.json │ │ │ │ ├── vector-2.json │ │ │ │ └── vector-3.json │ │ │ │ ├── did-ion.ts │ │ │ │ ├── did-ion │ │ │ │ ├── create.ts │ │ │ │ └── resolve.ts │ │ │ │ └── utils │ │ │ │ ├── get-verification-method-by-key.json │ │ │ │ ├── get-verification-method-types.json │ │ │ │ └── get-verification-methods.json │ │ ├── methods │ │ │ ├── did-dht.spec.ts │ │ │ ├── did-ion.spec.ts │ │ │ ├── did-jwk.spec.ts │ │ │ ├── did-key.spec.ts │ │ │ ├── did-method.spec.ts │ │ │ └── did-web.spec.ts │ │ ├── resolver │ │ │ ├── resolver-cache-level.spec.ts │ │ │ ├── resolver-cache-noop.spec.ts │ │ │ └── universal-resolver.spec.ts │ │ ├── tsconfig.json │ │ └── utils.spec.ts │ ├── tsconfig.cjs.json │ ├── tsconfig.json │ └── web-test-runner.config.cjs ├── identity-agent │ ├── .c8rc.json │ ├── .mocharc.json │ ├── .vscode │ │ ├── launch.json │ │ └── tasks.json │ ├── CHANGELOG.md │ ├── README.md │ ├── build │ │ ├── bundles.js │ │ ├── esbuild-browser-config.cjs │ │ └── esbuild-tests.cjs │ ├── package.json │ ├── src │ │ ├── identity-agent.ts │ │ └── index.ts │ ├── tests │ │ ├── identity-agent.spec.ts │ │ ├── managing-identities.spec.ts │ │ ├── tsconfig.json │ │ └── utils │ │ │ └── test-config.ts │ ├── tsconfig.cjs.json │ ├── tsconfig.json │ └── web-test-runner.config.cjs ├── proxy-agent │ ├── .c8rc.json │ ├── .mocharc.json │ ├── .vscode │ │ ├── launch.json │ │ └── tasks.json │ ├── CHANGELOG.md │ ├── README.md │ ├── build │ │ ├── bundles.js │ │ ├── esbuild-browser-config.cjs │ │ └── esbuild-tests.cjs │ ├── package.json │ ├── src │ │ ├── index.ts │ │ └── proxy-agent.ts │ ├── tests │ │ ├── proxy-agent.spec.ts │ │ ├── tsconfig.json │ │ └── utils │ │ │ └── test-config.ts │ ├── tsconfig.cjs.json │ ├── tsconfig.json │ └── web-test-runner.config.cjs └── user-agent │ ├── .c8rc.json │ ├── .mocharc.json │ ├── .vscode │ ├── launch.json │ └── tasks.json │ ├── CHANGELOG.md │ ├── README.md │ ├── build │ ├── bundles.js │ ├── esbuild-browser-config.cjs │ └── esbuild-tests.cjs │ ├── package.json │ ├── src │ ├── index.ts │ └── user-agent.ts │ ├── tests │ ├── tsconfig.json │ ├── user-agent.spec.ts │ └── utils │ │ └── test-config.ts │ ├── tsconfig.cjs.json │ ├── tsconfig.json │ └── web-test-runner.config.cjs ├── pnpm-lock.yaml ├── pnpm-workspace.yaml ├── scripts ├── bump-workspace.mjs ├── changesets-api-release-check.sh ├── changesets-version.sh └── tbdocs-check-local.sh ├── tsconfig.json └── web5-js.code-workspace /.changeset/README.md: -------------------------------------------------------------------------------- 1 | # Changesets 2 | 3 | Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works 4 | with multi-package repos, or single-package repos to help you version and publish your code. You can 5 | find the full documentation for it [in our repository](https://github.com/changesets/changesets) 6 | 7 | We have a quick list of common questions to get you started engaging with this project in 8 | [our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md) -------------------------------------------------------------------------------- /.changeset/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://unpkg.com/@changesets/config@3.0.0/schema.json", 3 | "changelog": [ 4 | "@changesets/changelog-github", 5 | { 6 | "repo": "TBD54566975/web5-js" 7 | } 8 | ], 9 | "commit": false, 10 | "fixed": [], 11 | "linked": [], 12 | "access": "public", 13 | "baseBranch": "main", 14 | "updateInternalDependencies": "patch", 15 | "bumpVersionsWithWorkspaceProtocolOnly": true, 16 | "ignore": [] 17 | } -------------------------------------------------------------------------------- /.codesandbox/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://codesandbox.io/schemas/tasks.json", 3 | "setupTasks": [ 4 | { 5 | "name": "Installing Dependencies", 6 | "command": "pnpm install" 7 | } 8 | ], 9 | "tasks": { 10 | "dev": { 11 | "name": "Build Web5 SDK", 12 | "command": "pnpm build", 13 | "runAtStart": true, 14 | "restartOn": { 15 | "files": [ 16 | "package-lock.json" 17 | ] 18 | } 19 | }, 20 | "tests": { 21 | "name": "Run tests", 22 | "command": "pnpm --recursive --stream test:node" 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: "npm" # See documentation for possible values 9 | directory: "/packages/common" # Location of package manifests 10 | schedule: 11 | interval: "monthly" 12 | 13 | - package-ecosystem: "npm" 14 | directory: "/packages/credentials" 15 | schedule: 16 | interval: "monthly" 17 | 18 | - package-ecosystem: "npm" 19 | directory: "/packages/crypto" 20 | schedule: 21 | interval: "monthly" 22 | 23 | - package-ecosystem: "npm" 24 | directory: "/packages/crypto-aws-kms" 25 | schedule: 26 | interval: "monthly" 27 | 28 | - package-ecosystem: "npm" 29 | directory: "/packages/dids" 30 | schedule: 31 | interval: "monthly" 32 | -------------------------------------------------------------------------------- /.github/workflows/release-notify.yml: -------------------------------------------------------------------------------- 1 | name: Create Issue On Release 2 | 3 | on: 4 | release: 5 | types: [created] 6 | 7 | jobs: 8 | create-issue: 9 | runs-on: ubuntu-latest 10 | 11 | steps: 12 | - name: Create Issue 13 | uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea #v7.0.1 14 | with: 15 | github-token: ${{ secrets.DOCS_PAT }} # Assuming 'PAT' is your Personal Access Token stored as a secret 16 | script: | 17 | const issueTitle = `A new release ${context.payload.release.tag_name} just cut for ${context.payload.repository.name}.`; 18 | const issueBody = `Please check the api docs for compatibility with the release. Here is the [link to release notes](${context.payload.release.html_url}).`; 19 | const labels = ['triage', 'priority-1-blocker', 'documentation']; 20 | const issue = await github.rest.issues.create({ 21 | owner: 'TBD54566975', 22 | repo: 'developer.tbd.website', 23 | title: issueTitle, 24 | body: issueBody, 25 | labels: labels 26 | }); 27 | return { issueNumber: issue.data.number, releaseTag: context.payload.release.tag_name, repo: context.payload.repository.name }; 28 | - name: Notify Discord 29 | uses: Ilshidur/action-discord@0.3.2 30 | env: 31 | DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} 32 | with: 33 | args: "A new release {{ EVENT_PAYLOAD.release.tag_name }} of project {{ EVENT_PAYLOAD.repository.name }} has been cut. Please check the release notes: {{ EVENT_PAYLOAD.release.html_url }} for compatibility with docs." 34 | -------------------------------------------------------------------------------- /.github/workflows/scorecard.yml: -------------------------------------------------------------------------------- 1 | name: Scorecard supply-chain security 2 | on: 3 | # For Branch-Protection check. Only the default branch is supported. See 4 | # https://github.com/ossf/scorecard/blob/main/docs/checks.md#branch-protection 5 | branch_protection_rule: 6 | 7 | # Manual trigger 8 | workflow_dispatch: 9 | 10 | # To guarantee Maintained check is occasionally updated. See 11 | # https://github.com/ossf/scorecard/blob/main/docs/checks.md#maintained 12 | schedule: 13 | - cron: "0 5 * * 1" 14 | push: 15 | branches: ["main"] 16 | 17 | # Declare default permissions as read only. 18 | permissions: read-all 19 | 20 | jobs: 21 | ossf: 22 | uses: TBD54566975/open-source-programs/.github/workflows/scorecard.yml@main 23 | secrets: inherit 24 | permissions: 25 | security-events: write 26 | id-token: write 27 | -------------------------------------------------------------------------------- /.github/workflows/security.yml: -------------------------------------------------------------------------------- 1 | name: Security and License Scans 2 | 3 | on: 4 | pull_request_target: 5 | branches: 6 | - main 7 | 8 | push: 9 | branches: 10 | - main 11 | 12 | # Run every day at 5am UTC 13 | schedule: 14 | - cron: "0 5 * * *" 15 | 16 | # Allows you to run this workflow manually from the Actions tab 17 | workflow_dispatch: 18 | 19 | jobs: 20 | security-license-scan: 21 | uses: TBD54566975/open-source-programs/.github/workflows/security.yml@main 22 | secrets: inherit 23 | -------------------------------------------------------------------------------- /.github/workflows/take.yml: -------------------------------------------------------------------------------- 1 | name: Auto-assign issue to contributor 2 | 3 | on: 4 | issue_comment: 5 | types: [created] 6 | 7 | jobs: 8 | assign: 9 | name: Take an issue 10 | runs-on: ubuntu-latest 11 | permissions: 12 | issues: write 13 | steps: 14 | - name: Check if it's October 15 | id: check-month 16 | run: | 17 | current_month=$(date -u +%m) 18 | if [[ $current_month == "10" ]]; then 19 | echo "is_october=true" >> $GITHUB_OUTPUT 20 | else 21 | echo "is_october=false" >> $GITHUB_OUTPUT 22 | fi 23 | 24 | - name: Take the issue 25 | if: steps.check-month.outputs.is_october == 'true' 26 | uses: bdougie/take-action@1439165ac45a7461c2d89a59952cd7d941964b87 27 | with: 28 | message: Thanks for taking this issue! Let us know if you have any questions! 29 | trigger: .take 30 | token: ${{ secrets.GITHUB_TOKEN }} 31 | 32 | - name: Log when outside October 33 | if: steps.check-month.outputs.is_october == 'false' 34 | run: echo "Action skipped because the current date is not in October." -------------------------------------------------------------------------------- /.github/workflows/tbdocs-commenter.yml: -------------------------------------------------------------------------------- 1 | name: TBDocs Commenter 2 | 3 | on: 4 | workflow_run: 5 | workflows: ["Docs Continuous Integration"] 6 | types: 7 | - completed 8 | 9 | jobs: 10 | comment-action: 11 | name: TBDocs PR Comment 12 | runs-on: ubuntu-latest 13 | # runs only if it's triggered from a PR 14 | if: github.event.workflow_run.pull_requests[0].number != null 15 | 16 | steps: 17 | - name: Download TBDocs Report 18 | uses: dawidd6/action-download-artifact@v2 19 | with: 20 | run_id: ${{ github.event.workflow_run.id }} 21 | name: tbdocs-reporter-output 22 | path: ./.tbdocs 23 | 24 | - name: Add footer to markdown report 25 | run: | 26 | report_file='.tbdocs/docs-report.md' 27 | head_sha="${{ github.event.workflow_run.pull_requests[0].head.sha }}" 28 | short_sha=${head_sha:0:7} 29 | timestamp=$(date -u +"%Y-%m-%dT%H:%M:%SZ") 30 | repo="${{ github.repository }}" 31 | sha_link="https://github.com/$repo/commit/$head_sha" 32 | 33 | footer_line="_TBDocs Report Updated at $timestamp [\`$short_sha\`]($sha_link)_" 34 | 35 | echo "---" >> $report_file 36 | echo $footer_line >> $report_file 37 | 38 | - name: Find Comment 39 | uses: peter-evans/find-comment@v2 40 | id: fc 41 | with: 42 | issue-number: ${{ github.event.workflow_run.pull_requests[0].number }} 43 | comment-author: "github-actions[bot]" 44 | body-includes: TBDocs Report 45 | 46 | - name: Comment on PR 47 | uses: peter-evans/create-or-update-comment@v3 48 | with: 49 | comment-id: ${{ steps.fc.outputs.comment-id }} 50 | issue-number: ${{ github.event.workflow_run.pull_requests[0].number }} 51 | edit-mode: replace 52 | body-path: .tbdocs/docs-report.md 53 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "web5-spec"] 2 | path = web5-spec 3 | url = https://github.com/TBD54566975/web5-spec 4 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "aaron-bond.better-comments", 4 | "ambar.bundle-size", 5 | "dbaeumer.vscode-eslint", 6 | "eamodio.gitlens", 7 | "christian-kohler.npm-intellisense", 8 | "christian-kohler.path-intellisense" 9 | ] 10 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "npm.packageManager": "pnpm", 3 | "editor.formatOnSave":true, 4 | "eslint.useFlatConfig": true, 5 | "eslint.lintTask.enable": true, 6 | "eslint.workingDirectories": [{ "mode": "auto" }], 7 | "eslint.format.enable": true, 8 | "[javascript]": { "editor.defaultFormatter": "dbaeumer.vscode-eslint" }, 9 | "[typescript]": { "editor.defaultFormatter": "dbaeumer.vscode-eslint" }, 10 | } -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | # This CODEOWNERS file denotes the project leads 2 | # and encodes their responsibilities for code review. 3 | 4 | # Lines starting with '#' are comments. 5 | # Each line is a file pattern followed by one or more owners. 6 | # The format is described: https://github.blog/2017-07-06-introducing-code-owners/ 7 | 8 | # These owners will be the default owners for all directories in the repo that do not have a designated owner. 9 | * @frankhinek @csuwildcat @mistermoe @thehenrytsai @lirancohen @shamilovtim 10 | 11 | # These are owners who can approve folders under the root directory and other CICD and QoL directories. 12 | # Should be the union list of all owners of sub-directories, optionally minus the default owners. 13 | /** @csuwildcat @lirancohen @thehenrytsai @shamilovtim @nitro-neal 14 | 15 | # These are owners of any file in the `common`, `crypto`, `crypto-aws-kms`, `dids`, and 16 | # `credentials` packages and their sub-directories. 17 | /packages/common @csuwildcat @thehenrytsai @nitro-neal @shamilovtim @lirancohen 18 | /packages/crypto @csuwildcat @thehenrytsai @nitro-neal @shamilovtim @lirancohen 19 | /packages/crypto-aws-kms @csuwildcat @thehenrytsai @nitro-neal @shamilovtim @lirancohen 20 | /packages/dids @csuwildcat @thehenrytsai @nitro-neal @shamilovtim @lirancohen 21 | /packages/credentials @csuwildcat @thehenrytsai @nitro-neal @shamilovtim @lirancohen 22 | 23 | # These are owners of any file in the `agent`, `user-agent`, `proxy-agent`, `identity-agent`, and 24 | # `api` packages and their sub-directories. 25 | /packages/agent @lirancohen @csuwildcat @shamilovtim 26 | /packages/proxy-agent @lirancohen @csuwildcat @shamilovtim 27 | /packages/user-agent @lirancohen @csuwildcat @shamilovtim 28 | /packages/identity-agent @lirancohen @csuwildcat @shamilovtim 29 | /packages/api @lirancohen @csuwildcat @shamilovtim @nitro-neal 30 | /packages/browser @lirancohen @csuwildcat 31 | 32 | -------------------------------------------------------------------------------- /audit-ci.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://github.com/IBM/audit-ci/raw/main/docs/schema.json", 3 | "moderate": true, 4 | "allowlist": [ 5 | "ip", 6 | "mysql2", 7 | "braces", 8 | "GHSA-rv95-896h-c2vc", 9 | "GHSA-952p-6rrq-rcjv", 10 | "GHSA-4vvj-4cpr-p986" 11 | ] 12 | } -------------------------------------------------------------------------------- /bin/.node-20.15.1.pkg: -------------------------------------------------------------------------------- 1 | hermit -------------------------------------------------------------------------------- /bin/.pnpm-9.6.0.pkg: -------------------------------------------------------------------------------- 1 | hermit -------------------------------------------------------------------------------- /bin/README.hermit.md: -------------------------------------------------------------------------------- 1 | # Hermit environment 2 | 3 | This is a [Hermit](https://github.com/cashapp/hermit) bin directory. 4 | 5 | The symlinks in this directory are managed by Hermit and will automatically 6 | download and install Hermit itself as well as packages. These packages are 7 | local to this environment. 8 | -------------------------------------------------------------------------------- /bin/activate-hermit: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # This file must be used with "source bin/activate-hermit" from bash or zsh. 3 | # You cannot run it directly 4 | # 5 | # THIS FILE IS GENERATED; DO NOT MODIFY 6 | 7 | if [ "${BASH_SOURCE-}" = "$0" ]; then 8 | echo "You must source this script: \$ source $0" >&2 9 | exit 33 10 | fi 11 | 12 | BIN_DIR="$(dirname "${BASH_SOURCE[0]:-${(%):-%x}}")" 13 | if "${BIN_DIR}/hermit" noop > /dev/null; then 14 | eval "$("${BIN_DIR}/hermit" activate "${BIN_DIR}/..")" 15 | 16 | if [ -n "${BASH-}" ] || [ -n "${ZSH_VERSION-}" ]; then 17 | hash -r 2>/dev/null 18 | fi 19 | 20 | echo "Hermit environment $("${HERMIT_ENV}"/bin/hermit env HERMIT_ENV) activated" 21 | fi 22 | -------------------------------------------------------------------------------- /bin/hermit: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # THIS FILE IS GENERATED; DO NOT MODIFY 4 | 5 | set -eo pipefail 6 | 7 | export HERMIT_USER_HOME=~ 8 | 9 | if [ -z "${HERMIT_STATE_DIR}" ]; then 10 | case "$(uname -s)" in 11 | Darwin) 12 | export HERMIT_STATE_DIR="${HERMIT_USER_HOME}/Library/Caches/hermit" 13 | ;; 14 | Linux) 15 | export HERMIT_STATE_DIR="${XDG_CACHE_HOME:-${HERMIT_USER_HOME}/.cache}/hermit" 16 | ;; 17 | esac 18 | fi 19 | 20 | export HERMIT_DIST_URL="${HERMIT_DIST_URL:-https://github.com/cashapp/hermit/releases/download/stable}" 21 | HERMIT_CHANNEL="$(basename "${HERMIT_DIST_URL}")" 22 | export HERMIT_CHANNEL 23 | export HERMIT_EXE=${HERMIT_EXE:-${HERMIT_STATE_DIR}/pkg/hermit@${HERMIT_CHANNEL}/hermit} 24 | 25 | if [ ! -x "${HERMIT_EXE}" ]; then 26 | echo "Bootstrapping ${HERMIT_EXE} from ${HERMIT_DIST_URL}" 1>&2 27 | INSTALL_SCRIPT="$(mktemp)" 28 | # This value must match that of the install script 29 | INSTALL_SCRIPT_SHA256="180e997dd837f839a3072a5e2f558619b6d12555cd5452d3ab19d87720704e38" 30 | if [ "${INSTALL_SCRIPT_SHA256}" = "BYPASS" ]; then 31 | curl -fsSL "${HERMIT_DIST_URL}/install.sh" -o "${INSTALL_SCRIPT}" 32 | else 33 | # Install script is versioned by its sha256sum value 34 | curl -fsSL "${HERMIT_DIST_URL}/install-${INSTALL_SCRIPT_SHA256}.sh" -o "${INSTALL_SCRIPT}" 35 | # Verify install script's sha256sum 36 | openssl dgst -sha256 "${INSTALL_SCRIPT}" | \ 37 | awk -v EXPECTED="$INSTALL_SCRIPT_SHA256" \ 38 | '$2!=EXPECTED {print "Install script sha256 " $2 " does not match " EXPECTED; exit 1}' 39 | fi 40 | /bin/bash "${INSTALL_SCRIPT}" 1>&2 41 | fi 42 | 43 | exec "${HERMIT_EXE}" --level=fatal exec "$0" -- "$@" 44 | -------------------------------------------------------------------------------- /bin/hermit.hcl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/decentralized-identity/web5-js/707bc224243aceeefd62f0e8592735315d580ec2/bin/hermit.hcl -------------------------------------------------------------------------------- /bin/node: -------------------------------------------------------------------------------- 1 | .node-20.15.1.pkg -------------------------------------------------------------------------------- /bin/npm: -------------------------------------------------------------------------------- 1 | .node-20.15.1.pkg -------------------------------------------------------------------------------- /bin/npx: -------------------------------------------------------------------------------- 1 | .node-20.15.1.pkg -------------------------------------------------------------------------------- /bin/pnpm: -------------------------------------------------------------------------------- 1 | .pnpm-9.6.0.pkg -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | comment: 2 | layout: "header, diff, components" 3 | 4 | component_management: 5 | default_rules: 6 | statuses: 7 | - type: project 8 | target: auto # auto compares coverage to the previous base commit 9 | threshold: 5% # allows a 5% drop from the previous base commit coverage 10 | informational: true 11 | - type: patch 12 | target: 90 13 | informational: true 14 | if_ci_failed: success 15 | 16 | individual_components: 17 | - component_id: package-agent 18 | name: agent 19 | paths: ["packages/agent/**"] 20 | 21 | - component_id: package-api 22 | name: api 23 | paths: ["packages/api/**"] 24 | 25 | - component_id: package_common 26 | name: common 27 | paths: ["packages/common/**"] 28 | 29 | - component_id: package_credentials 30 | name: credentials 31 | paths: ["packages/credentials/**"] 32 | 33 | - component_id: package_crypto 34 | name: crypto 35 | paths: ["packages/crypto/**"] 36 | 37 | - component_id: package_dids 38 | name: dids 39 | paths: ["packages/dids/**"] 40 | 41 | - component_id: package-identity-agent 42 | name: identity-agent 43 | paths: ["packages/identity-agent/**"] 44 | 45 | - component_id: package-crypto-aws-kms 46 | name: crypto-aws-kms 47 | paths: ["packages/crypto-aws-kms/**"] 48 | 49 | - component_id: package-proxy-agent 50 | name: proxy-agent 51 | paths: ["packages/proxy-agent/**"] 52 | 53 | - component_id: package-user-agent 54 | name: user-agent 55 | paths: ["packages/user-agent/**"] 56 | 57 | coverage: 58 | status: 59 | project: 60 | default: 61 | informational: true 62 | patch: 63 | default: 64 | informational: true # Don't gate PRs based on Codecov passing thresholds 65 | if_ci_failed: success 66 | -------------------------------------------------------------------------------- /packages/agent/.c8rc.json: -------------------------------------------------------------------------------- 1 | { 2 | "all": true, 3 | "cache": false, 4 | "extension": [ 5 | ".js" 6 | ], 7 | "include": [ 8 | "tests/compiled/**/src/**" 9 | ], 10 | "exclude": [ 11 | "tests/compiled/**/src/index.js", 12 | "tests/compiled/**/src/types.js", 13 | "tests/compiled/**/src/types/**", 14 | "tests/compiled/**/src/prototyping/clients/*-types.js", 15 | "tests/compiled/**/src/prototyping/**/types/**" 16 | ], 17 | "reporter": [ 18 | "cobertura", 19 | "html", 20 | "text" 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /packages/agent/.mocharc.json: -------------------------------------------------------------------------------- 1 | { 2 | "enable-source-maps": true, 3 | "exit": true, 4 | "spec": ["tests/compiled/**/*.spec.js"] 5 | } 6 | -------------------------------------------------------------------------------- /packages/agent/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "node", 9 | "request": "launch", 10 | "name": "test:node", 11 | "runtimeExecutable": "${workspaceFolder:agent}/node_modules/.bin/mocha", 12 | "console": "internalConsole", 13 | "preLaunchTask": "build tests", 14 | "skipFiles": [ 15 | "/**" 16 | ], 17 | "env": { 18 | "TEST_DWN_URL": "http://localhost:3000" 19 | } 20 | } 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /packages/agent/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "pnpm build", 6 | "type": "npm", 7 | "script": "build", 8 | "problemMatcher": [], 9 | "group": { 10 | "kind": "build", 11 | "isDefault": true 12 | } 13 | }, 14 | { 15 | "label": "tsc: build - tsconfig.json", 16 | "type": "typescript", 17 | "tsconfig": "tsconfig.json", 18 | "problemMatcher": [ 19 | "$tsc" 20 | ], 21 | "group": { 22 | "kind": "build", 23 | "isDefault": false 24 | }, 25 | "options": { 26 | "cwd": "${workspaceFolder:root}" 27 | } 28 | }, 29 | { 30 | "label": "build tests", 31 | "type": "npm", 32 | "script": "build:tests:node", 33 | "options": { 34 | "cwd": "${workspaceFolder:agent}" 35 | } 36 | } 37 | ] 38 | } -------------------------------------------------------------------------------- /packages/agent/build/bundles.js: -------------------------------------------------------------------------------- 1 | import esbuild from 'esbuild'; 2 | import browserConfig from './esbuild-browser-config.cjs'; 3 | 4 | // esm polyfilled bundle for browser 5 | esbuild.build({ 6 | ...browserConfig, 7 | outfile: 'dist/browser.mjs', 8 | }); 9 | 10 | // iife polyfilled bundle for browser 11 | esbuild.build({ 12 | ...browserConfig, 13 | format : 'iife', 14 | globalName : 'Web5Agent', 15 | outfile : 'dist/browser.js', 16 | }); -------------------------------------------------------------------------------- /packages/agent/build/cjs-bundle.js: -------------------------------------------------------------------------------- 1 | import esbuild from 'esbuild'; 2 | import packageJson from '../package.json' assert { type: 'json' }; 3 | 4 | // list of dependencies that _dont_ ship cjs 5 | const includeList = new Set(['ed25519-keygen']); 6 | 7 | // create list of dependencies that we _do not_ want to include in our bundle 8 | const excludeList = []; 9 | for (const dependency in packageJson.dependencies) { 10 | if (includeList.has(dependency)) { 11 | continue; 12 | } else { 13 | excludeList.push(dependency); 14 | } 15 | } 16 | 17 | esbuild.build({ 18 | entryPoints : [ './src/index.ts' ], 19 | bundle : true, 20 | external : excludeList, 21 | format : 'cjs', 22 | sourcemap : true, 23 | platform : 'node', 24 | outfile : 'dist/cjs/index.js', 25 | allowOverwrite : true 26 | }); -------------------------------------------------------------------------------- /packages/agent/build/esbuild-browser-config.cjs: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-var-requires */ 2 | const polyfillProviderPlugin = require('node-stdlib-browser/helpers/esbuild/plugin'); 3 | const stdLibBrowser = require('node-stdlib-browser'); 4 | 5 | const requiredPolyfills = new Set(['crypto', 'node:crypto', 'stream']); 6 | 7 | // populate object containing lib -> polyfill path 8 | const polyfills = {}; 9 | for (let lib in stdLibBrowser) { 10 | if (requiredPolyfills.has(lib)) { 11 | const polyfill = stdLibBrowser[lib]; 12 | polyfills[lib] = polyfill; 13 | } 14 | } 15 | 16 | /** @type {import('esbuild').BuildOptions} */ 17 | module.exports = { 18 | entryPoints : ['./src/index.ts'], 19 | bundle : true, 20 | format : 'esm', 21 | sourcemap : true, 22 | minify : true, 23 | platform : 'browser', 24 | target : ['chrome101', 'firefox108', 'safari16'], 25 | inject : [require.resolve('node-stdlib-browser/helpers/esbuild/shim')], 26 | plugins : [polyfillProviderPlugin(polyfills)], 27 | define : { 28 | 'global': 'globalThis', 29 | }, 30 | }; -------------------------------------------------------------------------------- /packages/agent/build/esbuild-tests.cjs: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-var-requires */ 2 | const esbuild = require('esbuild'); 3 | const browserConfig = require('./esbuild-browser-config.cjs'); 4 | 5 | esbuild.build({ 6 | ...browserConfig, 7 | format : 'esm', 8 | entryPoints : ['./tests/**/*.spec.*'], 9 | bundle : true, 10 | minify : false, 11 | outdir : 'tests/compiled', 12 | define : { 13 | ...browserConfig.define, 14 | 'process.env.TEST_DWN_URL': JSON.stringify(process.env.TEST_DWN_URL ?? null), 15 | }, 16 | }); 17 | -------------------------------------------------------------------------------- /packages/agent/src/bearer-identity.ts: -------------------------------------------------------------------------------- 1 | import { BearerDid } from '@web5/dids'; 2 | import { IdentityMetadata, PortableIdentity } from './types/identity.js'; 3 | 4 | /** 5 | * Represents a Web5 Identity with its DID and metadata. 6 | */ 7 | export class BearerIdentity { 8 | /** {@inheritDoc BearerDid} */ 9 | public did: BearerDid; 10 | 11 | /** {@inheritDoc DidMetadata} */ 12 | public metadata: IdentityMetadata; 13 | 14 | constructor({ did, metadata }: { 15 | did: BearerDid; 16 | metadata: IdentityMetadata; 17 | }) { 18 | this.did = did; 19 | this.metadata = metadata; 20 | } 21 | 22 | /** 23 | * Converts a `BearerIdentity` object to a portable format containing the DID and metadata 24 | * associated with the Identity. 25 | * 26 | * @example 27 | * ```ts 28 | * // Assuming `identity` is an instance of BearerIdentity. 29 | * const portableIdentity = await identity.export(); 30 | * // portableIdentity now contains the and metadata. 31 | * ``` 32 | * 33 | * @returns A `PortableIdentity` containing the DID and metadata associated with the 34 | * `BearerIdentity`. 35 | */ 36 | public async export(): Promise { 37 | return { 38 | portableDid : await this.did.export(), 39 | metadata : { ...this.metadata }, 40 | }; 41 | } 42 | } -------------------------------------------------------------------------------- /packages/agent/src/index.ts: -------------------------------------------------------------------------------- 1 | export type * from './types/agent.js'; 2 | export * from './types/dwn.js'; 3 | export type * from './types/identity.js'; 4 | export type * from './types/identity-vault.js'; 5 | export type * from './types/key-manager.js'; 6 | export type * from './types/permissions.js'; 7 | export type * from './types/sync.js'; 8 | export type * from './types/vc.js'; 9 | 10 | export * from './agent-did-resolver-cache.js'; 11 | export * from './bearer-identity.js'; 12 | export * from './crypto-api.js'; 13 | export * from './did-api.js'; 14 | export * from './dwn-api.js'; 15 | export * from './dwn-registrar.js'; 16 | export * from './hd-identity-vault.js'; 17 | export * from './identity-api.js'; 18 | export * from './local-key-manager.js'; 19 | export * from './permissions-api.js'; 20 | export * from './rpc-client.js'; 21 | export * from './store-data.js'; 22 | export * from './store-did.js'; 23 | export * from './store-identity.js'; 24 | export * from './store-key.js'; 25 | export * from './sync-api.js'; 26 | export * from './sync-engine-level.js'; 27 | export * from './test-harness.js'; 28 | export * from './utils.js'; 29 | export * from './connect.js'; 30 | export * from './oidc.js'; -------------------------------------------------------------------------------- /packages/agent/src/prototyping/clients/server-info-types.ts: -------------------------------------------------------------------------------- 1 | import { KeyValueStore } from '@web5/common'; 2 | 3 | export type ServerInfo = { 4 | /** the maximum file size the user can request to store */ 5 | maxFileSize: number, 6 | /** 7 | * an array of strings representing the server's registration requirements. 8 | * 9 | * ie. ['proof-of-work-sha256-v0', 'terms-of-service'] 10 | * */ 11 | registrationRequirements: string[], 12 | /** whether web socket support is enabled on this server */ 13 | webSocketSupport: boolean, 14 | } 15 | 16 | export interface DwnServerInfoCache extends KeyValueStore {} 17 | 18 | export interface DwnServerInfoRpc { 19 | /** retrieves the DWN Sever info, used to detect features such as WebSocket Subscriptions */ 20 | getServerInfo(url: string): Promise; 21 | } -------------------------------------------------------------------------------- /packages/agent/src/prototyping/common/object.ts: -------------------------------------------------------------------------------- 1 | export function hasDuplicateProperties(...objects: Array | undefined>): boolean { 2 | const propertySet = new Set(); 3 | const objectsWithoutUndefined = objects.filter(Boolean); // Remove any undefined values 4 | 5 | for (const obj of objectsWithoutUndefined) { 6 | for (const key in obj) { 7 | if (propertySet.has(key)) { 8 | return true; // Return true if a duplicate property is found 9 | } 10 | propertySet.add(key); 11 | } 12 | } 13 | 14 | return false; // Return false if no duplicates are found 15 | } -------------------------------------------------------------------------------- /packages/agent/src/prototyping/common/type-utils.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Infer the type of a type parameter. 3 | * 4 | * This is useful when you want to infer the type of a type parameter in a generic function. 5 | */ 6 | export type InferType = T extends infer U ? U : never; -------------------------------------------------------------------------------- /packages/agent/src/prototyping/crypto/algorithms/hkdf.ts: -------------------------------------------------------------------------------- 1 | import { CryptoAlgorithm } from '@web5/crypto'; 2 | 3 | import type { DeriveKeyBytesParams } from '../types/params-direct.js'; 4 | 5 | import { Hkdf, HkdfParams } from '../primitives/hkdf.js'; 6 | import { KeyBytesDeriver } from '../types/key-deriver.js'; 7 | 8 | /** 9 | * The `HkdfDeriveKeyBytesParams` interface defines the algorithm-specific parameters that should be 10 | * passed into the `deriveKeyBytes()` method when using the HKDF algorithm. 11 | */ 12 | export interface HkdfDeriveKeyBytesParams extends DeriveKeyBytesParams { 13 | /** Specifies the algorithm variant for HKDF key derivation. 14 | * The value determines the hash function that will be used and must be one of the following: 15 | * - `"HKDF-256"`: HKDF with SHA-256. 16 | * - `"HKDF-384"`: HKDF with SHA-384. 17 | * - `"HKDF-512"`: HKDF with SHA-512. 18 | */ 19 | algorithm: 'HKDF-256' | 'HKDF-384' | 'HKDF-512'; 20 | } 21 | 22 | export class HkdfAlgorithm extends CryptoAlgorithm 23 | implements KeyBytesDeriver { 24 | 25 | public async deriveKeyBytes({ algorithm, ...params }: 26 | HkdfDeriveKeyBytesParams & Omit 27 | ): Promise { 28 | // Map algorithm name to hash function. 29 | const hash = { 30 | 'HKDF-256' : 'SHA-256' as const, 31 | 'HKDF-384' : 'SHA-384' as const, 32 | 'HKDF-512' : 'SHA-512' as const 33 | }[algorithm]; 34 | 35 | // Derive a cryptographic byte array using HKDF. 36 | const derivedKeyBytes = await Hkdf.deriveKeyBytes({ ...params, hash }); 37 | 38 | return derivedKeyBytes; 39 | } 40 | } -------------------------------------------------------------------------------- /packages/agent/src/prototyping/crypto/algorithms/pbkdf2.ts: -------------------------------------------------------------------------------- 1 | import { CryptoAlgorithm } from '@web5/crypto'; 2 | 3 | import type { Pbkdf2Params } from '../primitives/pbkdf2.js'; 4 | import type { KeyBytesDeriver } from '../types/key-deriver.js'; 5 | import type { DeriveKeyBytesParams } from '../types/params-direct.js'; 6 | 7 | import { Pbkdf2 } from '../primitives/pbkdf2.js'; 8 | 9 | /** 10 | * The `Pbkdf2DeriveKeyBytesParams` interface defines the algorithm-specific parameters that 11 | * should be passed into the `deriveKeyBytes()` method when using the PBKDF2 algorithm. 12 | */ 13 | export interface Pbkdf2DeriveKeyBytesParams extends DeriveKeyBytesParams { 14 | /** Specifies the algorithm variant for PBKDF2 key derivation. 15 | * The value determines the hash function that will be used and must be one of the following: 16 | * - `"PBKDF2-HS256+A128KW"`: PBKDF2 with HMAC SHA-256 and A128KW key wrapping. 17 | * - `"PBKDF2-HS384+A192KW"`: PBKDF2 with HMAC SHA-384 and A192KW key wrapping. 18 | * - `"PBKDF2-HS512+A256KW"`: PBKDF2 with HMAC SHA-512 and A256KW key wrapping. 19 | */ 20 | algorithm: 'PBES2-HS256+A128KW' | 'PBES2-HS384+A192KW' | 'PBES2-HS512+A256KW'; 21 | } 22 | 23 | export class Pbkdf2Algorithm extends CryptoAlgorithm 24 | implements KeyBytesDeriver { 25 | 26 | public async deriveKeyBytes({ algorithm, ...params }: 27 | Pbkdf2DeriveKeyBytesParams & Omit 28 | ): Promise { 29 | // Extract the hash function component of the `algorithm` parameter. 30 | const [, hashFunction] = algorithm.split(/[-+]/); 31 | 32 | // Map from JOSE algorithm name to "SHA" hash function identifier. 33 | const hash = { 34 | 'HS256' : 'SHA-256' as const, 35 | 'HS384' : 'SHA-384' as const, 36 | 'HS512' : 'SHA-512' as const 37 | }[hashFunction]!; 38 | 39 | // Derive a cryptographic byte array using PBKDF2. 40 | const derivedKeyBytes = await Pbkdf2.deriveKeyBytes({ ...params, hash }); 41 | 42 | return derivedKeyBytes; 43 | } 44 | } -------------------------------------------------------------------------------- /packages/agent/src/prototyping/crypto/crypto-error.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * A custom error class for Crypto-related errors. 3 | */ 4 | export class CryptoError extends Error { 5 | /** 6 | * Constructs an instance of CryptoError, a custom error class for handling Crypto-related errors. 7 | * 8 | * @param code - A {@link CryptoErrorCode} representing the specific type of error encountered. 9 | * @param message - A human-readable description of the error. 10 | */ 11 | constructor(public code: CryptoErrorCode, message: string) { 12 | super(message); 13 | this.name = 'CryptoError'; 14 | 15 | // Ensures that instanceof works properly, the correct prototype chain when using inheritance, 16 | // and that V8 stack traces (like Chrome, Edge, and Node.js) are more readable and relevant. 17 | Object.setPrototypeOf(this, new.target.prototype); 18 | 19 | // Captures the stack trace in V8 engines (like Chrome, Edge, and Node.js). 20 | // In non-V8 environments, the stack trace will still be captured. 21 | if (Error.captureStackTrace) { 22 | Error.captureStackTrace(this, CryptoError); 23 | } 24 | } 25 | } 26 | 27 | /** 28 | * An enumeration of possible Crypto error codes. 29 | */ 30 | export enum CryptoErrorCode { 31 | /** The supplied algorithm identifier is not supported by the implementation. */ 32 | AlgorithmNotSupported = 'algorithmNotSupported', 33 | 34 | /** The encoding operation (either encoding or decoding) failed. */ 35 | EncodingError = 'encodingError', 36 | 37 | /** The JWE supplied does not conform to valid syntax. */ 38 | InvalidJwe = 'invalidJwe', 39 | 40 | /** The JWK supplied does not conform to valid syntax. */ 41 | InvalidJwk = 'invalidJwk', 42 | 43 | /** The requested operation is not supported by the implementation. */ 44 | OperationNotSupported = 'operationNotSupported', 45 | } -------------------------------------------------------------------------------- /packages/agent/src/prototyping/crypto/types/cipher.ts: -------------------------------------------------------------------------------- 1 | export type InferCipherAlgorithm = T extends { 2 | /** 3 | * The `encrypt` method signature from which the algorithm type is inferred. 4 | * This is an internal implementation detail and not part of the public API. 5 | */ 6 | encrypt(params: infer P): any; 7 | } 8 | ? P extends { 9 | /** 10 | * The `algorithm` property within the parameters of `encrypt`. 11 | * This internal element is used to infer the algorithm type. 12 | */ 13 | algorithm: infer A 14 | } 15 | ? A 16 | : never 17 | : never; -------------------------------------------------------------------------------- /packages/agent/src/prototyping/crypto/types/key-io.ts: -------------------------------------------------------------------------------- 1 | import type { Jwk } from '@web5/crypto'; 2 | 3 | /** 4 | * The `KeyExporter` interface provides a method for exporting cryptographic keys. 5 | */ 6 | export interface KeyExporter { 7 | /** 8 | * Exports a cryptographic key to an external JWK object. 9 | * 10 | * @remarks 11 | * The `exportKey()` method of the {@link KeyImporterExporter | `KeyImporterExporter`} interface 12 | * returns a cryptographic key in JWK format, facilitating interoperability and backup. 13 | * 14 | * @param params - The parameters for the key export operation. 15 | * 16 | * @returns A Promise resolving to the exported key in JWK format. 17 | */ 18 | exportKey(params: ExportKeyInput): Promise; 19 | } 20 | 21 | /** 22 | * The `KeyImporter` interface provides a method for importing cryptographic keys. 23 | */ 24 | export interface KeyImporter { 25 | /** 26 | * Imports an external key in JWK format. 27 | * 28 | * @remarks 29 | * The `importKey()` method of the {@link KeyImporterExporter | `KeyImporterExporter`} interface 30 | * takes as input an external key in JWK format and typically returns a key identifier reference 31 | * for the imported key. 32 | * 33 | * @param params - The parameters for the key import operation. 34 | * 35 | * @returns A Promise resolving to the key identifier of the imported key. 36 | */ 37 | importKey(params: ImportKeyInput): Promise; 38 | } 39 | 40 | export interface KeyDeleter { 41 | /** 42 | * Deletes a cryptographic key. 43 | * 44 | * @remarks 45 | * The `deleteKey()` method of the {@link KeyDeleter | `KeyDeleter`} interface deletes a cryptographic 46 | * key from the key store. 47 | * 48 | * @param params - The parameters for the key deletion operation. 49 | */ 50 | deleteKey(params: DeleteKeyInput): Promise; 51 | } -------------------------------------------------------------------------------- /packages/agent/src/prototyping/crypto/types/key-wrapper.ts: -------------------------------------------------------------------------------- 1 | export type InferKeyUnwrapAlgorithm = T extends { 2 | /** 3 | * The `unwrapKey` method signature from which the algorithm type is inferred. 4 | * This is an internal implementation detail and not part of the public API. 5 | */ 6 | unwrapKey(params: infer P): any; 7 | } 8 | ? P extends { 9 | /** 10 | * The `wrappedKeyAlgorithm` property within the parameters of `unwrapKey`. 11 | * This internal element is used to infer the algorithm type. 12 | */ 13 | wrappedKeyAlgorithm: infer A 14 | } 15 | ? A 16 | : never 17 | : never; -------------------------------------------------------------------------------- /packages/agent/src/prototyping/crypto/utils.ts: -------------------------------------------------------------------------------- 1 | import type { Cipher, KeyWrapper } from '@web5/crypto'; 2 | 3 | import type { KeyExporter, KeyImporter } from './types/key-io.js'; 4 | 5 | export function isCipher( 6 | obj: unknown 7 | ): obj is Cipher { 8 | return ( 9 | obj !== null && typeof obj === 'object' 10 | && 'encrypt' in obj && typeof obj.encrypt === 'function' 11 | && 'decrypt' in obj && typeof obj.decrypt === 'function' 12 | ); 13 | } 14 | 15 | export function isKeyExporter( 16 | obj: unknown 17 | ): obj is KeyExporter { 18 | return ( 19 | obj !== null && typeof obj === 'object' 20 | && 'exportKey' in obj && typeof obj.exportKey === 'function' 21 | ); 22 | } 23 | 24 | export function isKeyImporter( 25 | obj: unknown 26 | ): obj is KeyImporter { 27 | return ( 28 | obj !== null && typeof obj === 'object' 29 | && 'importKey' in obj && typeof obj.importKey === 'function' 30 | ); 31 | } 32 | 33 | export function isKeyWrapper( 34 | obj: unknown 35 | ): obj is KeyWrapper { 36 | return ( 37 | obj !== null && typeof obj === 'object' 38 | && 'wrapKey' in obj && typeof obj.wrapKey === 'function' 39 | && 'unwrapKey' in obj && typeof obj.unwrapKey === 'function' 40 | ); 41 | } -------------------------------------------------------------------------------- /packages/agent/src/prototyping/dids/utils.ts: -------------------------------------------------------------------------------- 1 | import type { PortableDid } from '@web5/dids'; 2 | 3 | export function isPortableDid(obj: unknown): obj is PortableDid { 4 | // Validate that the given value is an object that has the necessary properties of PortableDid. 5 | return !(!obj || typeof obj !== 'object' || obj === null) 6 | && 'uri' in obj 7 | && 'document' in obj 8 | && 'metadata' in obj 9 | && (!('keyManager' in obj) || obj.keyManager === undefined); 10 | } -------------------------------------------------------------------------------- /packages/agent/src/store-data-protocols.ts: -------------------------------------------------------------------------------- 1 | import type { ProtocolDefinition } from '@tbd54566975/dwn-sdk-js'; 2 | 3 | export const IdentityProtocolDefinition: ProtocolDefinition = { 4 | protocol : 'http://identity.foundation/protocols/web5/identity-store', 5 | published : false, 6 | types : { 7 | portableDid: { 8 | schema : 'https://identity.foundation/schemas/web5/portable-did', 9 | dataFormats : [ 10 | 'application/json' 11 | ] 12 | }, 13 | identityMetadata: { 14 | schema : 'https://identity.foundation/schemas/web5/identity-metadata', 15 | dataFormats : [ 16 | 'application/json' 17 | ] 18 | } 19 | }, 20 | structure: { 21 | portableDid : {}, 22 | identityMetadata : {} 23 | } 24 | }; 25 | 26 | export const JwkProtocolDefinition: ProtocolDefinition = { 27 | protocol : 'http://identity.foundation/protocols/web5/jwk-store', 28 | published : false, 29 | types : { 30 | privateJwk: { 31 | schema : 'https://identity.foundation/schemas/web5/private-jwk', 32 | dataFormats : [ 33 | 'application/json' 34 | ] 35 | }, 36 | }, 37 | structure: { 38 | privateJwk: {} 39 | } 40 | }; -------------------------------------------------------------------------------- /packages/agent/src/types/identity.ts: -------------------------------------------------------------------------------- 1 | import type { PortableDid } from '@web5/dids'; 2 | 3 | /** 4 | * Represents metadata about a Web5 Identity. 5 | */ 6 | export interface IdentityMetadata { 7 | name: string; 8 | tenant: string; 9 | uri: string; 10 | connectedDid?: string; 11 | } 12 | 13 | export interface PortableIdentity { 14 | portableDid: PortableDid; 15 | 16 | /** {@inheritDoc IdentityMetadata} */ 17 | metadata: IdentityMetadata; 18 | } -------------------------------------------------------------------------------- /packages/agent/src/types/key-manager.ts: -------------------------------------------------------------------------------- 1 | import type { Cipher, Jwk, KeyIdentifier, KeyWrapper, KmsExportKeyParams, KmsImportKeyParams } from '@web5/crypto'; 2 | 3 | import type { Web5PlatformAgent } from './agent.js'; 4 | import type { KeyManager } from '../prototyping/crypto/types/key-manager.js'; 5 | import type { KeyDeleter, KeyExporter, KeyImporter } from '../prototyping/crypto/types/key-io.js'; 6 | import type { KmsCipherParams, KmsDeleteKeyParams, KmsUnwrapKeyParams, KmsWrapKeyParams } from '../prototyping/crypto/types/params-kms.js'; 7 | export interface AgentKeyManager extends KeyManager, 8 | Cipher, 9 | KeyImporter, 10 | KeyExporter, 11 | KeyDeleter, 12 | KeyWrapper { 13 | 14 | agent: Web5PlatformAgent; 15 | } -------------------------------------------------------------------------------- /packages/agent/src/types/vc.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Verifiable Credential Types 3 | */ 4 | 5 | export type ProcessVcRequest = { /** empty */ } 6 | export type SendVcRequest = { /** empty */ } 7 | export type VcResponse = { /** empty */ } -------------------------------------------------------------------------------- /packages/agent/tests/fixtures/protocol-definitions/email.json: -------------------------------------------------------------------------------- 1 | { 2 | "protocol": "http://email-protocol.xyz", 3 | "published": true, 4 | "types": { 5 | "thread": { 6 | "schema": "http://email-protocol.xyz/schema/thread", 7 | "dataFormats": [ 8 | "text/plain" 9 | ] 10 | }, 11 | "email": { 12 | "schema": "http://email-protocol.xyz/schema/email", 13 | "dataFormats": [ 14 | "text/plain" 15 | ] 16 | } 17 | }, 18 | "structure": { 19 | "thread": { 20 | "$actions": [ 21 | { 22 | "who": "anyone", 23 | "can": [ 24 | "create", "update" 25 | ] 26 | }, 27 | { 28 | "who": "author", 29 | "of": "thread", 30 | "can": [ 31 | "read" 32 | ] 33 | }, 34 | { 35 | "who": "recipient", 36 | "of": "thread", 37 | "can": [ 38 | "read" 39 | ] 40 | } 41 | ], 42 | "email": { 43 | "$actions": [ 44 | { 45 | "who": "recipient", 46 | "of": "thread", 47 | "can": [ 48 | "create", "update" 49 | ] 50 | }, 51 | { 52 | "who": "author", 53 | "of": "thread/email", 54 | "can": [ 55 | "read" 56 | ] 57 | }, 58 | { 59 | "who": "recipient", 60 | "of": "thread/email", 61 | "can": [ 62 | "read" 63 | ] 64 | } 65 | ] 66 | } 67 | } 68 | } 69 | } -------------------------------------------------------------------------------- /packages/agent/tests/prototyping/crypto/fixtures/test-vectors/hkdf.ts: -------------------------------------------------------------------------------- 1 | export const hkdfTestVectors = [ 2 | { 3 | id : 'rfc5869-A.1', 4 | hash : 'SHA-256', 5 | baseKeyBytes : '0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b', 6 | salt : '000102030405060708090a0b0c', 7 | info : 'f0f1f2f3f4f5f6f7f8f9', 8 | length : 336, 9 | output : '3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865' 10 | }, 11 | { 12 | id : 'rfc5869-A.2', 13 | hash : 'SHA-256', 14 | baseKeyBytes : '000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f', 15 | salt : '606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeaf', 16 | info : 'b0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff', 17 | length : 656, 18 | output : 'b11e398dc80327a1c8e7f78c596a49344f012eda2d4efad8a050cc4c19afa97c59045a99cac7827271cb41c65e590e09da3275600c2f09b8367793a9aca3db71cc30c58179ec3e87c14c01d5c1f3434f1d87' 19 | }, 20 | { 21 | id : 'rfc5869-A.3', 22 | hash : 'SHA-256', 23 | baseKeyBytes : '0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b', 24 | salt : '', 25 | info : '', 26 | length : 336, 27 | output : '8da4e775a563c18f715f802a063c5a31b8a11f5c5ee1879ec3454e5f3c738d2d9d201395faa4b61a96c8' 28 | } 29 | ]; -------------------------------------------------------------------------------- /packages/agent/tests/sync-api.spec.ts: -------------------------------------------------------------------------------- 1 | import { expect } from 'chai'; 2 | 3 | import type { SyncEngine } from '../src/types/sync.js'; 4 | 5 | import { AgentSyncApi } from '../src/sync-api.js'; 6 | 7 | describe('AgentSyncApi', () => { 8 | 9 | describe('get agent', () => { 10 | it(`returns the 'agent' instance property`, async () => { 11 | // we are only mocking 12 | const mockAgent: any = { 13 | agentDid: 'did:method:abc123' 14 | }; 15 | const mockSyncEngine: SyncEngine = {} as SyncEngine; 16 | const syncApi = new AgentSyncApi({ agent: mockAgent, syncEngine: mockSyncEngine }); 17 | const agent = syncApi.agent; 18 | expect(agent).to.exist; 19 | expect(agent.agentDid).to.equal('did:method:abc123'); 20 | }); 21 | 22 | it(`throws an error if the 'agent' instance property is undefined`, () => { 23 | const mockSyncEngine: SyncEngine = {} as SyncEngine; 24 | const syncApi = new AgentSyncApi({ syncEngine: mockSyncEngine }); 25 | expect(() => 26 | syncApi.agent 27 | ).to.throw(Error, 'Unable to determine agent execution context'); 28 | }); 29 | }); 30 | }); -------------------------------------------------------------------------------- /packages/agent/tests/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "compiled", 5 | "declarationDir": "compiled/types", 6 | "sourceMap": true, 7 | "resolveJsonModule": true 8 | }, 9 | "include": [ 10 | "../src", 11 | ".", 12 | ], 13 | "exclude": [ 14 | "./compiled" 15 | ] 16 | } -------------------------------------------------------------------------------- /packages/agent/tests/utils-internal.spec.ts: -------------------------------------------------------------------------------- 1 | import { expect } from 'chai'; 2 | 3 | import { DeterministicKeyGenerator } from '../src/utils-internal.js'; 4 | import { EdDsaAlgorithm } from '@web5/crypto'; 5 | 6 | describe('Internal Utils', () => { 7 | describe('DeterministicKeyGenerator', () => { 8 | let keyGenerator: DeterministicKeyGenerator; 9 | 10 | beforeEach(() => { 11 | keyGenerator = new DeterministicKeyGenerator(); 12 | }); 13 | 14 | it('returns the expected pre-defined keys', async () => { 15 | const ecdsa = new EdDsaAlgorithm(); 16 | 17 | const identityPrivateKey = await ecdsa.generateKey({ 18 | algorithm: 'Ed25519' 19 | }); 20 | 21 | const signingPrivateKey = await ecdsa.generateKey({ 22 | algorithm: 'Ed25519' 23 | }); 24 | 25 | await keyGenerator.addPredefinedKeys({ 26 | privateKeys: [ identityPrivateKey, signingPrivateKey] 27 | }); 28 | 29 | const firstKeyUri = await keyGenerator.generateKey({ algorithm: 'Ed25519' }); 30 | expect(firstKeyUri).to.include(identityPrivateKey.kid); 31 | 32 | const secondKeyUri = await keyGenerator.generateKey({ algorithm: 'Ed25519' }); 33 | expect(secondKeyUri).to.include(signingPrivateKey.kid); 34 | }); 35 | }); 36 | }); -------------------------------------------------------------------------------- /packages/agent/tests/utils/runtimes.ts: -------------------------------------------------------------------------------- 1 | export const isChrome = typeof navigator !== 'undefined' && /Chrome/.test(navigator.userAgent); 2 | export const isNode = typeof navigator === 'undefined' && typeof process !== 'undefined' && process.versions != null && process.versions.node != null; -------------------------------------------------------------------------------- /packages/agent/tests/utils/test-config.ts: -------------------------------------------------------------------------------- 1 | const DEFAULT_TEST_DWN_URL = 'http://localhost:3000'; 2 | 3 | const getTestDwnUrl = () => process.env.TEST_DWN_URL || DEFAULT_TEST_DWN_URL; 4 | 5 | export const testDwnUrl = getTestDwnUrl(); -------------------------------------------------------------------------------- /packages/agent/tsconfig.cjs.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "lib": [ 5 | "DOM", 6 | "ES5" 7 | ], 8 | "target": "ES5", 9 | "module": "CommonJS", 10 | "outDir": "dist/cjs", 11 | "declaration": false, 12 | "declarationMap": false, 13 | "declarationDir": null, 14 | "downlevelIteration": true 15 | }, 16 | "include": [ 17 | "src" 18 | ] 19 | } -------------------------------------------------------------------------------- /packages/agent/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "declarationDir": "dist/types", 5 | "outDir": "dist/esm" 6 | }, 7 | "include": [ 8 | "src" 9 | ], 10 | "exclude": [ 11 | "node_modules" 12 | ] 13 | } -------------------------------------------------------------------------------- /packages/agent/web-test-runner.config.cjs: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-var-requires */ 2 | const playwrightLauncher = 3 | require('@web/test-runner-playwright').playwrightLauncher; 4 | 5 | /** 6 | * @type {import('@web/test-runner').TestRunnerConfig} 7 | */ 8 | module.exports = { 9 | files : 'tests/compiled/**/*.spec.js', 10 | playwright : true, 11 | nodeResolve : true, 12 | browsers : [ 13 | playwrightLauncher({ 14 | product: 'chromium', 15 | }), 16 | playwrightLauncher({ 17 | product: 'firefox', 18 | }), 19 | playwrightLauncher({ 20 | product: 'webkit', 21 | }), 22 | ], 23 | testsFinishTimeout : 300000, 24 | concurrentBrowsers : 2, 25 | testFramework : { 26 | config: { 27 | timeout: '30000', 28 | }, 29 | }, 30 | }; 31 | -------------------------------------------------------------------------------- /packages/api/.c8rc.json: -------------------------------------------------------------------------------- 1 | { 2 | "all": true, 3 | "cache": false, 4 | "extension": [ 5 | ".js" 6 | ], 7 | "include": [ 8 | "tests/compiled/**/src/**" 9 | ], 10 | "exclude": [ 11 | "tests/compiled/**/src/web-features.js", 12 | "tests/compiled/**/src/index.js", 13 | "tests/compiled/**/src/types.js", 14 | "tests/compiled/**/src/types/**" 15 | ], 16 | "reporter": [ 17 | "cobertura", 18 | "text" 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /packages/api/.mocharc.json: -------------------------------------------------------------------------------- 1 | { 2 | "enable-source-maps": true, 3 | "exit": true, 4 | "spec": ["tests/compiled/**/*.spec.js"], 5 | "timeout": 5000 6 | } -------------------------------------------------------------------------------- /packages/api/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Browser in-page.html", 9 | "request": "launch", 10 | "type": "chrome", 11 | "url": "http://localhost:8000/packages/web5/examples/in-page.html", 12 | "webRoot": "${workspaceFolder:web5}" 13 | }, 14 | { 15 | "type": "node", 16 | "request": "launch", 17 | "name": "test:node", 18 | "runtimeExecutable": "${workspaceFolder:api}/node_modules/.bin/mocha", 19 | "console": "internalConsole", 20 | "preLaunchTask": "build tests", 21 | "skipFiles": [ 22 | "/**" 23 | ], 24 | "env": { 25 | "TEST_DWN_URL": "http://localhost:3000" 26 | } 27 | } 28 | ] 29 | } -------------------------------------------------------------------------------- /packages/api/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "pnpm build", 6 | "type": "npm", 7 | "script": "build", 8 | "problemMatcher": [], 9 | "group": { 10 | "kind": "build", 11 | "isDefault": true 12 | } 13 | }, 14 | { 15 | "label": "tsc: build - tsconfig.json", 16 | "type": "typescript", 17 | "tsconfig": "tsconfig.json", 18 | "problemMatcher": [ 19 | "$tsc" 20 | ], 21 | "group": { 22 | "kind": "build", 23 | "isDefault": false 24 | }, 25 | "options": { 26 | "cwd": "${workspaceFolder:root}" 27 | } 28 | }, 29 | { 30 | "label": "build tests", 31 | "type": "npm", 32 | "script": "build:tests:node", 33 | "problemMatcher": [ 34 | "$tsc" 35 | ], 36 | "options": { 37 | "cwd": "${workspaceFolder:api}" 38 | } 39 | }, 40 | ] 41 | } -------------------------------------------------------------------------------- /packages/api/build/bundles.js: -------------------------------------------------------------------------------- 1 | import esbuild from 'esbuild'; 2 | import browserConfig from './esbuild-browser-config.cjs'; 3 | 4 | // esm polyfilled bundle for browser 5 | esbuild.build({ 6 | ...browserConfig, 7 | metafile : true, 8 | outfile : 'dist/browser.mjs', 9 | }); 10 | 11 | // iife polyfilled bundle for browser 12 | esbuild.build({ 13 | ...browserConfig, 14 | format : 'iife', 15 | globalName : 'Web5', 16 | outfile : 'dist/browser.js', 17 | }); -------------------------------------------------------------------------------- /packages/api/build/esbuild-browser-config.cjs: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-var-requires */ 2 | const polyfillProviderPlugin = require('node-stdlib-browser/helpers/esbuild/plugin'); 3 | const stdLibBrowser = require('node-stdlib-browser'); 4 | 5 | const requiredPolyfills = new Set(['crypto', 'node:crypto', 'stream']); 6 | 7 | // populate object containing lib -> polyfill path 8 | const polyfills = {}; 9 | for (let lib in stdLibBrowser) { 10 | if (requiredPolyfills.has(lib)) { 11 | const polyfill = stdLibBrowser[lib]; 12 | polyfills[lib] = polyfill; 13 | } 14 | } 15 | 16 | /** @type {import('esbuild').BuildOptions} */ 17 | module.exports = { 18 | entryPoints : ['./src/index.ts'], 19 | bundle : true, 20 | format : 'esm', 21 | sourcemap : true, 22 | minify : true, 23 | platform : 'browser', 24 | target : ['chrome101', 'firefox108', 'safari16'], 25 | inject : [require.resolve('node-stdlib-browser/helpers/esbuild/shim')], 26 | plugins : [polyfillProviderPlugin(polyfills)], 27 | define : { 28 | 'global': 'globalThis', 29 | }, 30 | }; -------------------------------------------------------------------------------- /packages/api/build/esbuild-tests.cjs: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-var-requires */ 2 | const esbuild = require('esbuild'); 3 | const browserConfig = require('./esbuild-browser-config.cjs'); 4 | 5 | esbuild.build({ 6 | ...browserConfig, 7 | format : 'esm', 8 | entryPoints : ['./tests/**/*.spec.*'], 9 | bundle : true, 10 | minify : false, 11 | outdir : 'tests/compiled', 12 | define : { 13 | ...browserConfig.define, 14 | 'process.env.TEST_DWN_URL': JSON.stringify(process.env.TEST_DWN_URL ?? null), 15 | }, 16 | }); 17 | -------------------------------------------------------------------------------- /packages/api/src/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Making developing with Web5 components at least 5 times easier to work with. 3 | * 4 | * Web5 consists of the following components: 5 | * - Decentralized Identifiers 6 | * - Verifiable Credentials 7 | * - DWeb Node personal datastores 8 | * 9 | * The SDK sets out to gather the most oft used functionality from all three of 10 | * these pillar technologies to provide a simple library that is as close to 11 | * effortless as possible. 12 | * 13 | * The SDK is currently still under active development, but having entered the 14 | * Tech Preview phase there is now a drive to avoid unnecessary changes unless 15 | * backwards compatibility is provided. Additional functionality will be added 16 | * in the lead up to 1.0 final, and modifications will be made to address 17 | * issues and community feedback. 18 | * 19 | * [Link to GitHub Repo](https://github.com/TBD54566975/web5-js) 20 | * 21 | * @packageDocumentation 22 | */ 23 | 24 | export * from './did-api.js'; 25 | export * from './dwn-api.js'; 26 | export * from './grant-revocation.js'; 27 | export * from './permission-grant.js'; 28 | export * from './permission-request.js'; 29 | export * from './protocol.js'; 30 | export * from './record.js'; 31 | export * from './vc-api.js'; 32 | export * from './web5.js'; 33 | 34 | import * as utils from './utils.js'; 35 | export { utils }; -------------------------------------------------------------------------------- /packages/api/src/subscription-util.ts: -------------------------------------------------------------------------------- 1 | import { DwnRecordSubscriptionHandler, getRecordAuthor, PermissionsApi, Web5Agent } from '@web5/agent'; 2 | import { RecordsSubscribeRequest } from './dwn-api.js'; 3 | import { Record } from './record.js'; 4 | 5 | /** 6 | * Utility class for dealing with subscriptions. 7 | */ 8 | export class SubscriptionUtil { 9 | /** 10 | * Creates a record subscription handler that can be used to process incoming {Record} messages. 11 | */ 12 | static recordSubscriptionHandler({ agent, connectedDid, request, delegateDid, protocolRole, permissionsApi }:{ 13 | agent: Web5Agent; 14 | connectedDid: string; 15 | delegateDid?: string; 16 | protocolRole?: string; 17 | permissionsApi?: PermissionsApi; 18 | request: RecordsSubscribeRequest; 19 | }): DwnRecordSubscriptionHandler { 20 | const { subscriptionHandler, from: remoteOrigin } = request; 21 | 22 | return async (event) => { 23 | const { message, initialWrite } = event; 24 | const author = getRecordAuthor(message); 25 | const recordOptions = { 26 | author, 27 | connectedDid, 28 | remoteOrigin, 29 | initialWrite 30 | }; 31 | 32 | const record = new Record(agent, { 33 | ...message, 34 | ...recordOptions, 35 | protocolRole, 36 | delegateDid: delegateDid, 37 | }, permissionsApi); 38 | 39 | subscriptionHandler(record); 40 | }; 41 | } 42 | } -------------------------------------------------------------------------------- /packages/api/src/vc-api.ts: -------------------------------------------------------------------------------- 1 | import type { Web5Agent } from '@web5/agent'; 2 | 3 | /** 4 | * The VC API is used to issue, present and verify VCs 5 | * 6 | * @beta 7 | */ 8 | export class VcApi { 9 | /** 10 | * Holds the instance of a {@link Web5Agent} that represents the current execution context for 11 | * the `VcApi`. This agent is used to process VC requests. 12 | */ 13 | private agent: Web5Agent; 14 | 15 | /** The DID of the tenant under which DID operations are being performed. */ 16 | private connectedDid: string; 17 | 18 | constructor(options: { agent: Web5Agent, connectedDid: string }) { 19 | this.agent = options.agent; 20 | this.connectedDid = options.connectedDid; 21 | } 22 | 23 | /** 24 | * Issues a VC (Not implemented yet) 25 | */ 26 | async create() { 27 | // TODO: implement 28 | throw new Error('Not implemented.'); 29 | } 30 | } -------------------------------------------------------------------------------- /packages/api/tests/chai-plugins.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | declare namespace Chai { 4 | 5 | // For BDD API 6 | interface Assertion extends LanguageChains, NumericComparison, TypeComparison { 7 | url: Assertion; 8 | } 9 | 10 | // For Assert API 11 | interface AssertStatic { 12 | isUrl: (actual: any) => Assertion; 13 | } 14 | } -------------------------------------------------------------------------------- /packages/api/tests/fixtures/protocol-definitions/email.json: -------------------------------------------------------------------------------- 1 | { 2 | "protocol": "http://email-protocol.xyz", 3 | "published": true, 4 | "types": { 5 | "thread": { 6 | "schema": "http://email-protocol.xyz/schema/thread", 7 | "dataFormats": [ 8 | "text/plain", 9 | "application/json" 10 | ] 11 | }, 12 | "email": { 13 | "schema": "http://email-protocol.xyz/schema/email", 14 | "dataFormats": [ 15 | "text/plain" 16 | ] 17 | } 18 | }, 19 | "structure": { 20 | "thread": { 21 | "$actions": [ 22 | { 23 | "who": "anyone", 24 | "can": [ 25 | "create", "update" 26 | ] 27 | }, 28 | { 29 | "who": "author", 30 | "of": "thread", 31 | "can": [ 32 | "read" 33 | ] 34 | }, 35 | { 36 | "who": "recipient", 37 | "of": "thread", 38 | "can": [ 39 | "read" 40 | ] 41 | } 42 | ], 43 | "email": { 44 | "$actions": [ 45 | { 46 | "who": "recipient", 47 | "of": "thread", 48 | "can": [ 49 | "create", "update" 50 | ] 51 | }, 52 | { 53 | "who": "author", 54 | "of": "thread/email", 55 | "can": [ 56 | "read" 57 | ] 58 | }, 59 | { 60 | "who": "recipient", 61 | "of": "thread/email", 62 | "can": [ 63 | "read" 64 | ] 65 | } 66 | ] 67 | } 68 | } 69 | } 70 | } -------------------------------------------------------------------------------- /packages/api/tests/fixtures/protocol-definitions/notes.json: -------------------------------------------------------------------------------- 1 | { 2 | "protocol": "http://notes-protocol.xyz", 3 | "published": true, 4 | "types": { 5 | "note": { 6 | "schema": "http://notes-protocol.xyz/schema/note", 7 | "dataFormats": [ 8 | "text/plain", 9 | "application/json" 10 | ] 11 | }, 12 | "comment": { 13 | "schema": "http://notes-protocol.xyz/schema/comment", 14 | "dataFormats": [ 15 | "text/plain", 16 | "application/json" 17 | ] 18 | }, 19 | "friend" : { 20 | "schema": "http://notes-protocol.xyz/schema/friend", 21 | "dataFormats": [ 22 | "text/plain", 23 | "application/json" 24 | ] 25 | }, 26 | "coAuthor" : { 27 | "schema": "http://notes-protocol.xyz/schema/coAuthor", 28 | "dataFormats": [ 29 | "text/plain", 30 | "application/json" 31 | ] 32 | } 33 | }, 34 | "structure": { 35 | "friend" :{ 36 | "$role": true 37 | }, 38 | "note": { 39 | "coAuthor" : { 40 | "$role": true 41 | }, 42 | "$actions": [ 43 | { 44 | "role": "friend", 45 | "can": ["read", "query", "subscribe"] 46 | }, 47 | { 48 | "role": "note/coAuthor", 49 | "can": [ "co-update", "co-delete" ] 50 | } 51 | ], 52 | "comment": { 53 | "$actions": [ 54 | { 55 | "role": "friend", 56 | "can": ["create", "update", "delete", "read", "query", "subscribe"] 57 | }, { 58 | "role": "note/coAuthor", 59 | "can": ["create", "update", "delete", "co-delete", "read", "query", "subscribe"] 60 | } 61 | ] 62 | } 63 | } 64 | } 65 | } -------------------------------------------------------------------------------- /packages/api/tests/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "compiled", 5 | "declarationDir": "compiled/types", 6 | "sourceMap": true, 7 | }, 8 | "include": [ 9 | "../src", 10 | ".", 11 | ], 12 | "exclude": [ 13 | "./compiled" 14 | ] 15 | } -------------------------------------------------------------------------------- /packages/api/tests/utils/chai-plugins.ts: -------------------------------------------------------------------------------- 1 | import * as Chai from 'chai'; 2 | 3 | /** 4 | * Chai plugin for validating URLs. 5 | * 6 | * This function adds two types of URL validation methods to Chai: 7 | * 1. For the BDD "expect" API: `expect(string).to.be.a.url;` 8 | * 2. For the Assert API: `assert.isUrl(string);` 9 | * 10 | * @param {Chai.ChaiStatic} chai - The Chai library object. 11 | * @param {Chai.ChaiUtils} utils - The Chai Utilities object. 12 | * 13 | * @example 14 | * // BDD API example: 15 | * import chai, { expect } from 'chai'; 16 | * import chaiUrl from './chai-plugins.js'; 17 | * chai.use(chaiUrl); 18 | * 19 | * describe('My Test Suite', () => { 20 | * it('should validate the URL', () => { 21 | * const url = 'https://example.org'; 22 | * expect(url).to.be.a.url; 23 | * }); 24 | * }); 25 | * 26 | * @example 27 | * // Assert API example: 28 | * import chai, { assert } from 'chai'; 29 | * import chaiUrl from './chai-plugins.js'; 30 | * chai.use(chaiUrl); 31 | * 32 | * describe('My Test Suite', () => { 33 | * it('should validate the URL', () => { 34 | * const url = 'https://example.org'; 35 | * assert.isUrl(url); 36 | * }); 37 | * }); 38 | */ 39 | export const chaiUrl: Chai.ChaiPlugin = function(chai: Chai.ChaiStatic, utils: Chai.ChaiUtils) { 40 | const assert = chai.assert; 41 | function isValidUrl() { 42 | const obj = utils.flag(this, 'object') as string; 43 | let isUrl = true; 44 | try { 45 | new URL(obj); 46 | } catch (err) { 47 | isUrl = false; 48 | } 49 | this.assert( 50 | isUrl, 51 | 'expected #{this} to be a valid URL', 52 | 'expected #{this} not to be a valid URL' 53 | ); 54 | } 55 | 56 | // Add the property to the BDD "expect" API. 57 | utils.addProperty(chai.Assertion.prototype, 'url', isValidUrl); 58 | 59 | // Add the method to the Assert API. 60 | assert.isUrl = (actual) => (new chai.Assertion(actual)).to.be.a.url; 61 | }; -------------------------------------------------------------------------------- /packages/api/tests/utils/test-config.ts: -------------------------------------------------------------------------------- 1 | const DEFAULT_TEST_DWN_URL = 'http://localhost:3000'; 2 | 3 | const getTestDwnUrl = () => process.env.TEST_DWN_URL || DEFAULT_TEST_DWN_URL; 4 | 5 | export const testDwnUrl = getTestDwnUrl(); -------------------------------------------------------------------------------- /packages/api/tests/vc-api.spec.ts: -------------------------------------------------------------------------------- 1 | import { expect } from 'chai'; 2 | import { Web5UserAgent } from '@web5/user-agent'; 3 | import { PlatformAgentTestHarness } from '@web5/agent'; 4 | 5 | import { VcApi } from '../src/vc-api.js'; 6 | 7 | describe('VcApi', () => { 8 | let vc: VcApi; 9 | let testHarness: PlatformAgentTestHarness; 10 | 11 | before(async () => { 12 | testHarness = await PlatformAgentTestHarness.setup({ 13 | agentClass : Web5UserAgent, 14 | agentStores : 'memory' 15 | }); 16 | }); 17 | 18 | beforeEach(async () => { 19 | await testHarness.clearStorage(); 20 | await testHarness.createAgentDid(); 21 | 22 | // Create a new Identity to author VC requests. 23 | const identity = await testHarness.agent.identity.create({ 24 | metadata : { name: 'Test' }, 25 | didMethod : 'jwk', 26 | }); 27 | 28 | // Instantiate VcApi. 29 | vc = new VcApi({ agent: testHarness.agent, connectedDid: identity.did.uri }); 30 | }); 31 | 32 | after(async () => { 33 | await testHarness.clearStorage(); 34 | await testHarness.closeStorage(); 35 | }); 36 | 37 | describe('create()', () => { 38 | it('is not implemented', async () => { 39 | try { 40 | await vc.create(); 41 | expect.fail('Expected method to throw, but it did not.'); 42 | } catch(e) { 43 | expect(e.message).to.include('Not implemented.'); 44 | } 45 | }); 46 | }); 47 | }); -------------------------------------------------------------------------------- /packages/api/tsconfig.cjs.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "lib": [ 5 | "DOM", 6 | "ES5" 7 | ], 8 | "target": "ES5", 9 | "module": "CommonJS", 10 | "outDir": "dist/cjs", 11 | "declaration": false, 12 | "declarationMap": false, 13 | "declarationDir": null, 14 | "downlevelIteration": true 15 | }, 16 | "include": [ 17 | "src" 18 | ] 19 | } -------------------------------------------------------------------------------- /packages/api/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "lib": [ 5 | "DOM", 6 | "ES2022" 7 | ], 8 | "strict": false, 9 | "declarationDir": "dist/types", 10 | "outDir": "dist/esm" 11 | }, 12 | "include": [ 13 | "src" 14 | ], 15 | "exclude": [ 16 | "node_modules" 17 | ] 18 | } -------------------------------------------------------------------------------- /packages/api/web-test-runner.config.cjs: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-var-requires */ 2 | const playwrightLauncher = 3 | require('@web/test-runner-playwright').playwrightLauncher; 4 | 5 | /** 6 | * @type {import('@web/test-runner').TestRunnerConfig} 7 | */ 8 | module.exports = { 9 | files : 'tests/compiled/**/*.spec.js', 10 | playwright : true, 11 | nodeResolve : true, 12 | browsers : [ 13 | playwrightLauncher({ 14 | product: 'chromium', 15 | }), 16 | playwrightLauncher({ 17 | product: 'firefox', 18 | }), 19 | playwrightLauncher({ 20 | product: 'webkit', 21 | }), 22 | ], 23 | testsFinishTimeout : 300000, 24 | concurrentBrowsers : 2, 25 | testFramework : { 26 | config: { 27 | timeout: '15000', 28 | }, 29 | }, 30 | }; 31 | -------------------------------------------------------------------------------- /packages/browser/.c8rc.json: -------------------------------------------------------------------------------- 1 | { 2 | "all": true, 3 | "cache": false, 4 | "extension": [ 5 | ".js" 6 | ], 7 | "include": [ 8 | "tests/compiled/**/src/**" 9 | ], 10 | "exclude": [ 11 | "tests/compiled/**/src/index.js", 12 | "tests/compiled/**/src/types.js", 13 | "tests/compiled/**/src/types/**" 14 | ], 15 | "reporter": [ 16 | "cobertura", 17 | "text" 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /packages/browser/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # @web5/browser 2 | 3 | ## 0.0.3 4 | 5 | ### Patch Changes 6 | 7 | - Updated dependencies [[`bd1cb00`](https://github.com/TBD54566975/web5-js/commit/bd1cb00616029b0d18687b597e90d3b7c4dbeae1), [`3f39bf1`](https://github.com/TBD54566975/web5-js/commit/3f39bf1d14cf835a2959b5386a82ff7228d31e6c)]: 8 | - @web5/dids@1.2.0 9 | 10 | ## 0.0.2 11 | 12 | ### Patch Changes 13 | 14 | - [#905](https://github.com/TBD54566975/web5-js/pull/905) [`3cfc21d`](https://github.com/TBD54566975/web5-js/commit/3cfc21df01e505891a47c9d6cd5bd1aa916c1550) Thanks [@LiranCohen](https://github.com/LiranCohen)! - Initial publish 15 | 16 | - Updated dependencies [[`17a4290`](https://github.com/TBD54566975/web5-js/commit/17a42902582481e2424fe7f3c3eb10dd1851e24a)]: 17 | - @web5/dids@1.1.5 18 | -------------------------------------------------------------------------------- /packages/browser/build/esbuild-browser-config.cjs: -------------------------------------------------------------------------------- 1 | /** @type {import('esbuild').BuildOptions} */ 2 | module.exports = { 3 | entryPoints : ['./src/index.ts'], 4 | bundle : true, 5 | format : 'esm', 6 | sourcemap : true, 7 | minify : true, 8 | platform : 'browser', 9 | target : ['chrome101', 'firefox108', 'safari16'], 10 | define : { 11 | 'global': 'globalThis', 12 | }, 13 | }; -------------------------------------------------------------------------------- /packages/browser/build/esbuild-tests.cjs: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-var-requires */ 2 | const esbuild = require('esbuild'); 3 | const browserConfig = require('./esbuild-browser-config.cjs'); 4 | 5 | esbuild.build({ 6 | ...browserConfig, 7 | format : 'esm', 8 | entryPoints : ['./tests/**/*.spec.*'], 9 | bundle : true, 10 | minify : false, 11 | outdir : 'tests/compiled', 12 | define : { 13 | ...browserConfig.define, 14 | 'process.env.TEST_DWN_URL': JSON.stringify(process.env.TEST_DWN_URL ?? null), 15 | }, 16 | }); 17 | -------------------------------------------------------------------------------- /packages/browser/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './web-features.js'; -------------------------------------------------------------------------------- /packages/browser/tests/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "compiled", 5 | "declarationDir": "compiled/types", 6 | "sourceMap": true, 7 | }, 8 | "include": [ 9 | "../src", 10 | ".", 11 | ], 12 | "exclude": [ 13 | "./compiled" 14 | ] 15 | } -------------------------------------------------------------------------------- /packages/browser/tests/web-features.spec.ts: -------------------------------------------------------------------------------- 1 | import { expect } from 'chai'; 2 | 3 | import { activatePolyfills } from '../src/web-features.js'; 4 | 5 | describe('web features', () => { 6 | describe('activatePolyfills', () => { 7 | it('does not throw', () => { 8 | expect(() => activatePolyfills()).to.not.throw(); 9 | }); 10 | }); 11 | }); 12 | -------------------------------------------------------------------------------- /packages/browser/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "lib": ["DOM", "ES6", "WebWorker"], 5 | "strict": false, 6 | "declarationDir": "dist/types", 7 | "outDir": "dist/esm" 8 | }, 9 | "include": [ 10 | "src" 11 | ], 12 | "exclude": [ 13 | "node_modules" 14 | ] 15 | } -------------------------------------------------------------------------------- /packages/browser/web-test-runner.config.cjs: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-var-requires */ 2 | const playwrightLauncher = 3 | require('@web/test-runner-playwright').playwrightLauncher; 4 | 5 | /** 6 | * @type {import('@web/test-runner').TestRunnerConfig} 7 | */ 8 | module.exports = { 9 | files : 'tests/compiled/**/*.spec.js', 10 | playwright : true, 11 | nodeResolve : true, 12 | browsers : [ 13 | playwrightLauncher({ 14 | product: 'chromium', 15 | }), 16 | playwrightLauncher({ 17 | product: 'firefox', 18 | }), 19 | playwrightLauncher({ 20 | product: 'webkit', 21 | }), 22 | ], 23 | testsFinishTimeout : 300000, 24 | concurrentBrowsers : 2, 25 | testFramework : { 26 | config: { 27 | timeout: '15000', 28 | }, 29 | }, 30 | }; 31 | -------------------------------------------------------------------------------- /packages/common/.c8rc.json: -------------------------------------------------------------------------------- 1 | { 2 | "all": true, 3 | "cache": false, 4 | "extension": [ 5 | ".js" 6 | ], 7 | "include": [ 8 | "tests/compiled/**/src/**" 9 | ], 10 | "exclude": [ 11 | "tests/compiled/**/src/index.js", 12 | "tests/compiled/**/src/types.js", 13 | "tests/compiled/**/src/types/**" 14 | ], 15 | "reporter": [ 16 | "cobertura", 17 | "text" 18 | ] 19 | } -------------------------------------------------------------------------------- /packages/common/.mocharc.json: -------------------------------------------------------------------------------- 1 | { 2 | "enable-source-maps": true, 3 | "exit": true, 4 | "spec": ["tests/compiled/**/*.spec.js"] 5 | } -------------------------------------------------------------------------------- /packages/common/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "node", 9 | "request": "launch", 10 | "name": "test:node", 11 | "runtimeExecutable": "${workspaceFolder:common}/node_modules/.bin/mocha", 12 | "console": "internalConsole", 13 | "preLaunchTask": "build tests", 14 | "skipFiles": [ 15 | "/**" 16 | ] 17 | } 18 | ] 19 | } -------------------------------------------------------------------------------- /packages/common/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "pnpm build", 6 | "type": "npm", 7 | "script": "build", 8 | "group": { 9 | "kind": "build", 10 | "isDefault": true 11 | } 12 | }, 13 | { 14 | "label": "tsc: build - tsconfig.json", 15 | "type": "typescript", 16 | "tsconfig": "tsconfig.json", 17 | "problemMatcher": [ 18 | "$tsc" 19 | ], 20 | "group": { 21 | "kind": "build", 22 | "isDefault": false 23 | }, 24 | "options": { 25 | "cwd": "${workspaceFolder:root}" 26 | } 27 | }, 28 | { 29 | "label": "build tests", 30 | "type": "npm", 31 | "script": "build:tests:node", 32 | "options": { 33 | "cwd": "${workspaceFolder:common}" 34 | } 35 | } 36 | ] 37 | } -------------------------------------------------------------------------------- /packages/common/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # @web5/common 2 | 3 | ## 1.1.0 4 | 5 | ### Minor Changes 6 | 7 | - [#948](https://github.com/TBD54566975/web5-js/pull/948) [`bfa0417`](https://github.com/TBD54566975/web5-js/commit/bfa0417a2e9fc1300c5e604bea19b75ab1c73645) Thanks [@thehenrytsai](https://github.com/thehenrytsai)! - Added a logger. 8 | 9 | ## 1.0.2 10 | 11 | ### Patch Changes 12 | 13 | - [#694](https://github.com/TBD54566975/web5-js/pull/694) [`cc3aa58`](https://github.com/TBD54566975/web5-js/commit/cc3aa58069dd5465834b32174e3f840ddf782d60) Thanks [@thehenrytsai](https://github.com/thehenrytsai)! - Dependency updates. 14 | 15 | ## 1.0.1 16 | 17 | ### Patch Changes 18 | 19 | - [#579](https://github.com/TBD54566975/web5-js/pull/579) [`b36e7b1`](https://github.com/TBD54566975/web5-js/commit/b36e7b1eabd7c99313d6f6adb335c5a6d085d83e) Thanks [@thehenrytsai](https://github.com/thehenrytsai)! - Updated dependencies of all packages 20 | 21 | ## 1.0.0 22 | 23 | ### Major Changes 24 | 25 | - [#479](https://github.com/TBD54566975/web5-js/pull/479) [`a0edc10`](https://github.com/TBD54566975/web5-js/commit/a0edc1085cd78fa0a57383a9919c71f4971d3aba) Thanks [@leordev](https://github.com/leordev)! - Official tbDEX v1 release 🎉 26 | -------------------------------------------------------------------------------- /packages/common/build/bundles.js: -------------------------------------------------------------------------------- 1 | import esbuild from 'esbuild'; 2 | import browserConfig from './esbuild-browser-config.cjs'; 3 | 4 | // esm polyfilled bundle for browser 5 | esbuild.build({ 6 | ...browserConfig, 7 | outfile: 'dist/browser.mjs', 8 | }); 9 | 10 | // iife polyfilled bundle for browser 11 | esbuild.build({ 12 | ...browserConfig, 13 | format : 'iife', 14 | globalName : 'Web5Common', 15 | outfile : 'dist/browser.js', 16 | }); -------------------------------------------------------------------------------- /packages/common/build/cjs-bundle.js: -------------------------------------------------------------------------------- 1 | import esbuild from 'esbuild'; 2 | import packageJson from '../package.json' assert { type: 'json' }; 3 | 4 | // list of dependencies that _dont_ ship cjs 5 | const includeList = new Set(['multiformats']); 6 | 7 | // create list of dependencies that we _do not_ want to include in our bundle 8 | const excludeList = []; 9 | for (const dependency in packageJson.dependencies) { 10 | if (includeList.has(dependency)) { 11 | continue; 12 | } else { 13 | excludeList.push(dependency); 14 | } 15 | } 16 | 17 | esbuild.build({ 18 | entryPoints : [ './src/index.ts' ], 19 | bundle : true, 20 | external : excludeList, 21 | format : 'cjs', 22 | sourcemap : true, 23 | platform : 'node', 24 | outfile : 'dist/cjs/index.js', 25 | allowOverwrite : true 26 | }); -------------------------------------------------------------------------------- /packages/common/build/esbuild-browser-config.cjs: -------------------------------------------------------------------------------- 1 | /** @type {import('esbuild').BuildOptions} */ 2 | module.exports = { 3 | entryPoints : ['./src/index.ts'], 4 | bundle : true, 5 | format : 'esm', 6 | sourcemap : true, 7 | minify : true, 8 | platform : 'browser', 9 | target : ['chrome101', 'firefox108', 'safari16'], 10 | define : { 11 | 'global': 'globalThis', 12 | }, 13 | }; -------------------------------------------------------------------------------- /packages/common/build/esbuild-tests.cjs: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-var-requires */ 2 | const esbuild = require('esbuild'); 3 | const browserConfig = require('./esbuild-browser-config.cjs'); 4 | 5 | esbuild.build({ 6 | ...browserConfig, 7 | format : 'esm', 8 | entryPoints : ['./tests/**/*.spec.*'], 9 | bundle : true, 10 | minify : false, 11 | outdir : 'tests/compiled', 12 | define : { 13 | ...browserConfig.define, 14 | 'process.env.TEST_DWN_URL': JSON.stringify(process.env.TEST_DWN_URL ?? null), 15 | }, 16 | }); 17 | -------------------------------------------------------------------------------- /packages/common/src/cache.ts: -------------------------------------------------------------------------------- 1 | import TTLCache from '@isaacs/ttlcache'; 2 | export { TTLCache as TtlCache }; -------------------------------------------------------------------------------- /packages/common/src/index.ts: -------------------------------------------------------------------------------- 1 | export type * from './types.js'; 2 | 3 | export * from './cache.js'; 4 | export * from './convert.js'; 5 | export * from './logger.js'; 6 | export * from './multicodec.js'; 7 | export * from './object.js'; 8 | export * from './stores.js'; 9 | export * from './stream.js'; 10 | export * from './stream-node.js'; 11 | export * from './type-utils.js'; -------------------------------------------------------------------------------- /packages/common/src/logger.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Web5 logger level. 3 | */ 4 | export enum Web5LogLevel { 5 | Debug = 'debug', 6 | Silent = 'silent', 7 | } 8 | 9 | /** 10 | * Web5 logger interface. 11 | */ 12 | export interface Web5LoggerInterface { 13 | 14 | /** 15 | * Sets the log verbose level. 16 | */ 17 | setLogLevel(logLevel: Web5LogLevel): void; 18 | 19 | /** 20 | * Same as `info()`. 21 | * Logs an informational message. 22 | */ 23 | log (message: string): void; 24 | 25 | /** 26 | * Logs an informational message. 27 | */ 28 | info(message: string): void; 29 | 30 | /** 31 | * Logs an error message. 32 | */ 33 | error(message: string): void; 34 | } 35 | 36 | /** 37 | * A Web5 logger implementation. 38 | */ 39 | class Web5Logger implements Web5LoggerInterface { 40 | private logLevel: Web5LogLevel = Web5LogLevel.Silent; // Default to silent/no-op log level 41 | 42 | setLogLevel(logLevel: Web5LogLevel): void { 43 | this.logLevel = logLevel; 44 | } 45 | 46 | public log(message: string): void { 47 | this.info(message); 48 | } 49 | 50 | public info(message: string): void { 51 | if (this.logLevel === Web5LogLevel.Silent) { return; } 52 | 53 | console.info(message); 54 | } 55 | 56 | public error(message: string): void { 57 | if (this.logLevel === Web5LogLevel.Silent) { return; } 58 | 59 | console.error(message); 60 | } 61 | } 62 | 63 | // Export a singleton logger instance 64 | export const logger = new Web5Logger(); 65 | 66 | // Attach logger to the global window object in browser environment for easy access to the logger instance. 67 | // e.g. can call `web5logger.setLogLevel('debug');` directly in browser console. 68 | if (typeof window !== 'undefined') { 69 | (window as any).web5logger = logger; // Makes `web5Logger` accessible globally in browser 70 | } -------------------------------------------------------------------------------- /packages/common/src/object.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Checks whether the given object has any properties. 3 | */ 4 | export function isEmptyObject(obj: unknown): boolean { 5 | if (typeof obj !== 'object' || obj === null) { 6 | return false; 7 | } 8 | 9 | if (Object.getOwnPropertySymbols(obj).length > 0) { 10 | return false; 11 | } 12 | 13 | return Object.keys(obj).length === 0; 14 | } 15 | 16 | /** 17 | * Recursively removes all properties with an empty object or array as its value from the given object. 18 | */ 19 | export function removeEmptyObjects(obj: Record): void { 20 | Object.keys(obj).forEach(key => { 21 | if (typeof(obj[key]) === 'object') { 22 | // recursive remove empty object or array properties in nested objects 23 | removeEmptyObjects(obj[key] as Record); 24 | } 25 | 26 | if (isEmptyObject(obj[key])) { 27 | delete obj[key]; 28 | } 29 | }); 30 | } 31 | 32 | /** 33 | * Recursively removes all properties with `undefined` as its value from the given object. 34 | */ 35 | export function removeUndefinedProperties(obj: Record): void { 36 | Object.keys(obj).forEach(key => { 37 | if (obj[key] === undefined) { 38 | delete obj[key]; 39 | } else if (typeof(obj[key]) === 'object') { 40 | removeUndefinedProperties(obj[key] as Record); // recursive remove `undefined` properties in nested objects 41 | } 42 | }); 43 | } -------------------------------------------------------------------------------- /packages/common/src/types.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Interface for a generic key-value store. 3 | */ 4 | export interface KeyValueStore { 5 | /** 6 | * Clears the store, removing all key-value pairs. 7 | * 8 | * @returns A promise that resolves when the store has been cleared. 9 | */ 10 | clear(): Promise; 11 | 12 | /** 13 | * Closes the store, freeing up any resources used. After calling this method, no other operations can be performed on the store. 14 | * 15 | * @returns A promise that resolves when the store has been closed. 16 | */ 17 | close(): Promise; 18 | 19 | /** 20 | * Deletes a key-value pair from the store. 21 | * 22 | * @param key - The key of the value to delete. 23 | * @returns A promise that resolves to true if the element existed and has been removed, or false if the element does not exist. 24 | */ 25 | delete(key: K): Promise; 26 | 27 | /** 28 | * Fetches a value from the store given its key. 29 | * 30 | * @param key - The key of the value to retrieve. 31 | * @returns A promise that resolves with the value associated with the key, or `undefined` if no value exists for that key. 32 | */ 33 | get(key: K): Promise; 34 | 35 | /** 36 | * Sets the value for a key in the store. 37 | * 38 | * @param key - The key under which to store the value. 39 | * @param value - The value to be stored. 40 | * @returns A promise that resolves when the value has been set. 41 | */ 42 | set(key: K, value: V): Promise; 43 | } -------------------------------------------------------------------------------- /packages/common/tests/cache.spec.ts: -------------------------------------------------------------------------------- 1 | import { expect } from 'chai'; 2 | 3 | import { TtlCache } from '../src/cache.js'; 4 | 5 | describe('TTLCache', function () { 6 | it('should store and retrieve string values', function () { 7 | const cache = new TtlCache({ max: 10000, ttl: 1000 }); 8 | cache.set('key1', 'value1'); 9 | 10 | expect(cache.has('key1')).to.be.true; 11 | expect(cache.get('key1')).to.equal('value1'); 12 | 13 | expect(cache.has('key1')).to.be.true; 14 | expect(cache.get('key1')).to.equal('value1'); 15 | }); 16 | 17 | it('should store and retrieve object values', function () { 18 | const cache = new TtlCache({ max: 10000, ttl: 1000 }); 19 | const value = { prop: 'value' }; 20 | cache.set('key2', value); 21 | 22 | expect(cache.has('key2')).to.be.true; 23 | expect(cache.get('key2')).to.deep.equal(value); 24 | 25 | expect(cache.has('key2')).to.be.true; 26 | expect(cache.get('key2')).to.deep.equal(value); 27 | }); 28 | }); 29 | -------------------------------------------------------------------------------- /packages/common/tests/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "compiled", 5 | "declarationDir": "compiled/types", 6 | "sourceMap": true, 7 | }, 8 | "include": [ 9 | "../src", 10 | ".", 11 | ], 12 | "exclude": [ 13 | "./compiled" 14 | ] 15 | } -------------------------------------------------------------------------------- /packages/common/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "declarationDir": "dist/types", 5 | "outDir": "dist/esm" 6 | }, 7 | "include": [ 8 | "src" 9 | ], 10 | "exclude": [ 11 | "node_modules" 12 | ] 13 | } -------------------------------------------------------------------------------- /packages/common/web-test-runner.config.cjs: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-var-requires */ 2 | const playwrightLauncher = 3 | require('@web/test-runner-playwright').playwrightLauncher; 4 | 5 | /** 6 | * @type {import('@web/test-runner').TestRunnerConfig} 7 | */ 8 | module.exports = { 9 | files : 'tests/compiled/**/*.spec.js', 10 | playwright : true, 11 | nodeResolve : true, 12 | browsers : [ 13 | playwrightLauncher({ 14 | product: 'chromium', 15 | }), 16 | playwrightLauncher({ 17 | product: 'firefox', 18 | }), 19 | playwrightLauncher({ 20 | product: 'webkit', 21 | }), 22 | ], 23 | testsFinishTimeout : 300000, 24 | concurrentBrowsers : 2, 25 | testFramework : { 26 | config: { 27 | timeout: '15000', 28 | }, 29 | }, 30 | }; 31 | -------------------------------------------------------------------------------- /packages/credentials/.c8rc.json: -------------------------------------------------------------------------------- 1 | { 2 | "all": true, 3 | "cache": false, 4 | "extension": [ 5 | ".js" 6 | ], 7 | "include": [ 8 | "tests/compiled/**/src/**" 9 | ], 10 | "exclude": [ 11 | "tests/compiled/**/src/index.js", 12 | "tests/compiled/**/src/types.js", 13 | "tests/compiled/**/src/types/**" 14 | ], 15 | "reporter": [ 16 | "cobertura", 17 | "text" 18 | ] 19 | } -------------------------------------------------------------------------------- /packages/credentials/.mocharc.json: -------------------------------------------------------------------------------- 1 | { 2 | "enable-source-maps": true, 3 | "exit": true, 4 | "spec": ["tests/compiled/**/*.spec.js"] 5 | } -------------------------------------------------------------------------------- /packages/credentials/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "node", 9 | "request": "launch", 10 | "name": "test:node", 11 | "runtimeExecutable": "${workspaceFolder:credentials}/node_modules/.bin/mocha", 12 | "console": "internalConsole", 13 | "preLaunchTask": "build tests", 14 | "skipFiles": [ 15 | "/**" 16 | ] 17 | } 18 | ] 19 | } -------------------------------------------------------------------------------- /packages/credentials/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "pnpm build", 6 | "type": "npm", 7 | "script": "build", 8 | "problemMatcher": [], 9 | "group": { 10 | "kind": "build", 11 | "isDefault": true 12 | } 13 | }, 14 | { 15 | "label": "tsc: build - tsconfig.json", 16 | "type": "typescript", 17 | "tsconfig": "tsconfig.json", 18 | "problemMatcher": [ 19 | "$tsc" 20 | ], 21 | "group": { 22 | "kind": "build", 23 | "isDefault": false 24 | }, 25 | "options": { 26 | "cwd": "${workspaceFolder:root}" 27 | } 28 | }, 29 | { 30 | "label": "build tests", 31 | "type": "npm", 32 | "script": "build:tests:node", 33 | "options": { 34 | "cwd": "${workspaceFolder:credentials}" 35 | } 36 | } 37 | ] 38 | } -------------------------------------------------------------------------------- /packages/credentials/build/bundles.js: -------------------------------------------------------------------------------- 1 | import esbuild from 'esbuild'; 2 | import browserConfig from './esbuild-browser-config.cjs'; 3 | 4 | // esm polyfilled bundle for browser 5 | esbuild.build({ 6 | ...browserConfig, 7 | outfile: 'dist/browser.mjs', 8 | }); 9 | 10 | // iife polyfilled bundle for browser 11 | esbuild.build({ 12 | ...browserConfig, 13 | format : 'iife', 14 | globalName : 'Web5Credentials', 15 | outfile : 'dist/browser.js', 16 | }); 17 | 18 | esbuild.build({ 19 | ...browserConfig, 20 | entryPoints : ['./src/utils.ts'], 21 | outfile : 'dist/utils.js' 22 | }); -------------------------------------------------------------------------------- /packages/credentials/build/esbuild-browser-config.cjs: -------------------------------------------------------------------------------- 1 | /** @type {import('esbuild').BuildOptions} */ 2 | module.exports = { 3 | entryPoints : ['./src/index.ts'], 4 | bundle : true, 5 | format : 'esm', 6 | sourcemap : true, 7 | minify : true, 8 | platform : 'browser', 9 | target : ['chrome101', 'firefox108', 'safari16'], 10 | define : { 11 | 'global': 'globalThis', 12 | }, 13 | }; -------------------------------------------------------------------------------- /packages/credentials/build/esbuild-tests.cjs: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-var-requires */ 2 | const esbuild = require('esbuild'); 3 | const browserConfig = require('./esbuild-browser-config.cjs'); 4 | 5 | esbuild.build({ 6 | ...browserConfig, 7 | format : 'esm', 8 | entryPoints : ['./tests/**/*.spec.*'], 9 | bundle : true, 10 | minify : false, 11 | outdir : 'tests/compiled', 12 | define : { 13 | ...browserConfig.define, 14 | 'process.env.TEST_DWN_URL': JSON.stringify(process.env.TEST_DWN_URL ?? null), 15 | }, 16 | }); 17 | -------------------------------------------------------------------------------- /packages/credentials/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './jwt.js'; 2 | export * from './presentation-exchange.js'; 3 | export * from './status-list-credential.js'; 4 | export * from './verifiable-credential.js'; 5 | export * from './verifiable-presentation.js'; 6 | export * as utils from './utils.js'; -------------------------------------------------------------------------------- /packages/credentials/tests/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "compiled", 5 | "declarationDir": "compiled/types", 6 | "sourceMap": true, 7 | }, 8 | "include": [ 9 | "../src", 10 | ".", 11 | ], 12 | "exclude": [ 13 | "./compiled" 14 | ] 15 | } -------------------------------------------------------------------------------- /packages/credentials/tsconfig.cjs.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "lib": [ 5 | "DOM", 6 | "ES5" 7 | ], 8 | "target": "ES5", 9 | "module": "CommonJS", 10 | "moduleResolution": "Node", 11 | "outDir": "dist/cjs", 12 | "declaration": false, 13 | "declarationMap": false, 14 | "declarationDir": null 15 | }, 16 | "include": [ 17 | "src" 18 | ] 19 | } -------------------------------------------------------------------------------- /packages/credentials/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "declarationDir": "dist/types", 5 | "outDir": "dist/esm" 6 | }, 7 | "include": [ 8 | "src" 9 | ], 10 | "exclude": [ 11 | "node_modules" 12 | ] 13 | } -------------------------------------------------------------------------------- /packages/credentials/web-test-runner.config.cjs: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-var-requires */ 2 | const playwrightLauncher = 3 | require('@web/test-runner-playwright').playwrightLauncher; 4 | 5 | /** 6 | * @type {import('@web/test-runner').TestRunnerConfig} 7 | */ 8 | module.exports = { 9 | files : 'tests/compiled/**/*.spec.js', 10 | playwright : true, 11 | nodeResolve : true, 12 | browsers : [ 13 | playwrightLauncher({ 14 | product: 'chromium', 15 | }), 16 | playwrightLauncher({ 17 | product: 'firefox', 18 | }), 19 | playwrightLauncher({ 20 | product: 'webkit', 21 | }), 22 | ], 23 | testsFinishTimeout : 300000, 24 | concurrentBrowsers : 2, 25 | testFramework : { 26 | config: { 27 | timeout: '15000', 28 | }, 29 | }, 30 | }; 31 | -------------------------------------------------------------------------------- /packages/crypto-aws-kms/.c8rc.json: -------------------------------------------------------------------------------- 1 | { 2 | "all": true, 3 | "cache": false, 4 | "extension": [ 5 | ".js" 6 | ], 7 | "include": [ 8 | "tests/compiled/**/src/**" 9 | ], 10 | "exclude": [ 11 | "tests/compiled/**/src/index.js", 12 | "tests/compiled/**/src/types.js", 13 | "tests/compiled/**/src/types/**" 14 | ], 15 | "reporter": [ 16 | "cobertura", 17 | "text" 18 | ] 19 | } -------------------------------------------------------------------------------- /packages/crypto-aws-kms/.mocharc.json: -------------------------------------------------------------------------------- 1 | { 2 | "enable-source-maps": true, 3 | "exit": true, 4 | "spec": ["tests/compiled/**/*.spec.js"] 5 | } -------------------------------------------------------------------------------- /packages/crypto-aws-kms/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "node", 9 | "request": "launch", 10 | "name": "test:node", 11 | "runtimeExecutable": "${workspaceFolder:crypto-aws-kms}/node_modules/.bin/mocha", 12 | "console": "internalConsole", 13 | "preLaunchTask": "build tests", 14 | "skipFiles": [ 15 | "/**" 16 | ] 17 | } 18 | ] 19 | } -------------------------------------------------------------------------------- /packages/crypto-aws-kms/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "pnpm build", 6 | "type": "npm", 7 | "script": "build", 8 | "problemMatcher": [], 9 | "group": { 10 | "kind": "build", 11 | "isDefault": true 12 | } 13 | }, 14 | { 15 | "label": "tsc: build - tsconfig.json", 16 | "type": "typescript", 17 | "tsconfig": "tsconfig.json", 18 | "problemMatcher": [ 19 | "$tsc" 20 | ], 21 | "group": { 22 | "kind": "build", 23 | "isDefault": false 24 | }, 25 | "options": { 26 | "cwd": "${workspaceFolder:root}" 27 | } 28 | }, 29 | { 30 | "label": "build tests", 31 | "type": "npm", 32 | "script": "build:tests:node", 33 | "options": { 34 | "cwd": "${workspaceFolder:crypto-aws-kms}" 35 | } 36 | } 37 | ] 38 | } -------------------------------------------------------------------------------- /packages/crypto-aws-kms/eslint.config.cjs: -------------------------------------------------------------------------------- 1 | const baseConfig = require('../../eslint.config.cjs'); 2 | 3 | /** @type {import('eslint').ESLint.ConfigData} */ 4 | module.exports = [ 5 | ...baseConfig, 6 | { 7 | rules: { 8 | '@typescript-eslint/no-namespace': 'off', 9 | } 10 | }]; -------------------------------------------------------------------------------- /packages/crypto-aws-kms/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './ecdsa.js'; 2 | export * from './key-manager.js'; 3 | export * from './utils.js'; -------------------------------------------------------------------------------- /packages/crypto-aws-kms/tests/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "compiled", 5 | "declarationDir": "compiled/types", 6 | "resolveJsonModule": true, 7 | "sourceMap": true 8 | }, 9 | "include": [ 10 | "../src", 11 | ".", 12 | ], 13 | "exclude": [ 14 | "./compiled" 15 | ] 16 | } -------------------------------------------------------------------------------- /packages/crypto-aws-kms/tsconfig.cjs.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "lib": [ 5 | "DOM", 6 | "ES5" 7 | ], 8 | "target": "ES5", 9 | "module": "CommonJS", 10 | "moduleResolution": "Node", 11 | "outDir": "dist/cjs", 12 | "declaration": false, 13 | "declarationMap": false, 14 | "declarationDir": null, 15 | "downlevelIteration": true 16 | }, 17 | "include": [ 18 | "src" 19 | ] 20 | } -------------------------------------------------------------------------------- /packages/crypto-aws-kms/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "declarationDir": "dist/types", 5 | "outDir": "dist/esm" 6 | }, 7 | "include": [ 8 | "src" 9 | ], 10 | "exclude": [ 11 | "node_modules" 12 | ] 13 | } -------------------------------------------------------------------------------- /packages/crypto/.c8rc.json: -------------------------------------------------------------------------------- 1 | { 2 | "all": true, 3 | "cache": false, 4 | "extension": [ 5 | ".js" 6 | ], 7 | "include": [ 8 | "tests/compiled/**/src/**" 9 | ], 10 | "exclude": [ 11 | "tests/compiled/**/src/index.js", 12 | "tests/compiled/**/src/types.js", 13 | "tests/compiled/**/src/types/**" 14 | ], 15 | "reporter": [ 16 | "cobertura", 17 | "text" 18 | ] 19 | } -------------------------------------------------------------------------------- /packages/crypto/.mocharc.json: -------------------------------------------------------------------------------- 1 | { 2 | "enable-source-maps": true, 3 | "exit": true, 4 | "spec": ["tests/compiled/**/*.spec.js"] 5 | } -------------------------------------------------------------------------------- /packages/crypto/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "node", 9 | "request": "launch", 10 | "name": "test:node", 11 | "runtimeExecutable": "${workspaceFolder:crypto}/node_modules/.bin/mocha", 12 | "console": "internalConsole", 13 | "preLaunchTask": "build tests", 14 | "skipFiles": [ 15 | "/**" 16 | ] 17 | } 18 | ] 19 | } -------------------------------------------------------------------------------- /packages/crypto/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "pnpm build", 6 | "type": "npm", 7 | "script": "build", 8 | "problemMatcher": [], 9 | "group": { 10 | "kind": "build", 11 | "isDefault": true 12 | } 13 | }, 14 | { 15 | "label": "tsc: build - tsconfig.json", 16 | "type": "typescript", 17 | "tsconfig": "tsconfig.json", 18 | "problemMatcher": [ 19 | "$tsc" 20 | ], 21 | "group": { 22 | "kind": "build", 23 | "isDefault": false 24 | }, 25 | "options": { 26 | "cwd": "${workspaceFolder:root}" 27 | } 28 | }, 29 | { 30 | "label": "build tests", 31 | "type": "npm", 32 | "script": "build:tests:node", 33 | "options": { 34 | "cwd": "${workspaceFolder:crypto}" 35 | } 36 | } 37 | ] 38 | } -------------------------------------------------------------------------------- /packages/crypto/build/bundles.js: -------------------------------------------------------------------------------- 1 | import esbuild from 'esbuild'; 2 | import browserConfig from './esbuild-browser-config.cjs'; 3 | 4 | // esm polyfilled bundle for browser 5 | esbuild.build({ 6 | ...browserConfig, 7 | outfile: 'dist/browser.mjs', 8 | }); 9 | 10 | // iife polyfilled bundle for browser 11 | esbuild.build({ 12 | ...browserConfig, 13 | format : 'iife', 14 | globalName : 'Web5Crypto', 15 | outfile : 'dist/browser.js', 16 | }); 17 | 18 | esbuild.build({ 19 | ...browserConfig, 20 | entryPoints : ['./src/utils.ts'], 21 | outfile : 'dist/utils.js' 22 | }); -------------------------------------------------------------------------------- /packages/crypto/build/esbuild-browser-config.cjs: -------------------------------------------------------------------------------- 1 | /** @type {import('esbuild').BuildOptions} */ 2 | module.exports = { 3 | entryPoints : ['./src/index.ts'], 4 | bundle : true, 5 | format : 'esm', 6 | sourcemap : true, 7 | minify : true, 8 | platform : 'browser', 9 | target : ['chrome101', 'firefox108', 'safari16'], 10 | define : { 11 | 'global': 'globalThis', 12 | }, 13 | }; -------------------------------------------------------------------------------- /packages/crypto/build/esbuild-tests.cjs: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-var-requires */ 2 | const esbuild = require('esbuild'); 3 | const browserConfig = require('./esbuild-browser-config.cjs'); 4 | 5 | esbuild.build({ 6 | ...browserConfig, 7 | format : 'esm', 8 | entryPoints : ['./tests/**/*.spec.*'], 9 | bundle : true, 10 | minify : false, 11 | outdir : 'tests/compiled', 12 | define : { 13 | ...browserConfig.define, 14 | 'process.env.TEST_DWN_URL': JSON.stringify(process.env.TEST_DWN_URL ?? null), 15 | }, 16 | }); 17 | -------------------------------------------------------------------------------- /packages/crypto/eslint.config.cjs: -------------------------------------------------------------------------------- 1 | const baseConfig = require('../../eslint.config.cjs'); 2 | 3 | /** @type {import('eslint').ESLint.ConfigData} */ 4 | module.exports = [ 5 | ...baseConfig, 6 | { 7 | rules: { 8 | '@typescript-eslint/no-namespace': 'off', 9 | } 10 | }]; -------------------------------------------------------------------------------- /packages/crypto/src/algorithms/crypto-algorithm.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Base class for all cryptographic algorithm implementations. 3 | */ 4 | export abstract class CryptoAlgorithm {} -------------------------------------------------------------------------------- /packages/crypto/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './local-key-manager.js'; 2 | export * from './utils.js'; 3 | 4 | export * from './algorithms/aes-ctr.js'; 5 | export * from './algorithms/aes-gcm.js'; 6 | export * from './algorithms/crypto-algorithm.js'; 7 | export * from './algorithms/ecdsa.js'; 8 | export * from './algorithms/eddsa.js'; 9 | export * from './algorithms/sha-2.js'; 10 | 11 | export * from './jose/jwe.js'; 12 | export * from './jose/jwk.js'; 13 | export * from './jose/jws.js'; 14 | export * from './jose/jwt.js'; 15 | export * from './jose/utils.js'; 16 | 17 | export * from './primitives/aes-ctr.js'; 18 | export * from './primitives/aes-gcm.js'; 19 | export * from './primitives/concat-kdf.js'; 20 | export * from './primitives/ed25519.js'; 21 | export * from './primitives/secp256r1.js'; 22 | export * from './primitives/pbkdf2.js'; 23 | export * from './primitives/secp256k1.js'; 24 | export * from './primitives/sha256.js'; 25 | export * from './primitives/x25519.js'; 26 | export * from './primitives/xchacha20.js'; 27 | export * from './primitives/xchacha20-poly1305.js'; 28 | 29 | export type * from './types/cipher.js'; 30 | export type * from './types/crypto-api.js'; 31 | export type * from './types/hasher.js'; 32 | export type * from './types/identifier.js'; 33 | export type * from './types/key-compressor.js'; 34 | export type * from './types/key-converter.js'; 35 | export type * from './types/key-deriver.js'; 36 | export type * from './types/key-generator.js'; 37 | export type * from './types/key-io.js'; 38 | export type * from './types/key-wrapper.js'; 39 | export type * from './types/params-direct.js'; 40 | export type * from './types/params-enclosed.js'; 41 | export type * from './types/params-kms.js'; 42 | export type * from './types/signer.js'; -------------------------------------------------------------------------------- /packages/crypto/src/jose/utils.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Canonicalizes a given object according to RFC 8785 (https://tools.ietf.org/html/rfc8785), 3 | * which describes JSON Canonicalization Scheme (JCS). This function sorts the keys of the 4 | * object and its nested objects alphabetically and then returns a stringified version of it. 5 | * This method handles nested objects, array values, and null values appropriately. 6 | * 7 | * @param obj - The object to canonicalize. 8 | * @returns The stringified version of the input object with its keys sorted alphabetically 9 | * per RFC 8785. 10 | */ 11 | export function canonicalize(obj: { [key: string]: any }): string { 12 | /** 13 | * Recursively sorts the keys of an object. 14 | * 15 | * @param obj - The object whose keys are to be sorted. 16 | * @returns A new object with sorted keys. 17 | */ 18 | const sortObjKeys = (obj: { [key: string]: any }): { [key: string]: any } => { 19 | if (obj !== null && typeof obj === 'object' && !Array.isArray(obj)) { 20 | const sortedKeys = Object.keys(obj).sort(); 21 | const sortedObj: { [key: string]: any } = {}; 22 | for (const key of sortedKeys) { 23 | // Recursively sort keys of nested objects. 24 | sortedObj[key] = sortObjKeys(obj[key]); 25 | } 26 | return sortedObj; 27 | } 28 | return obj; 29 | }; 30 | 31 | // Stringify and return the final sorted object. 32 | const sortedObj = sortObjKeys(obj); 33 | return JSON.stringify(sortedObj); 34 | } -------------------------------------------------------------------------------- /packages/crypto/src/primitives/sha256.ts: -------------------------------------------------------------------------------- 1 | import { sha256 } from '@noble/hashes/sha256'; 2 | 3 | /** 4 | * The `Sha256` class provides an interface for generating SHA-256 hash digests. 5 | * 6 | * This class utilizes the '@noble/hashes/sha256' function to generate hash digests 7 | * of the provided data. The SHA-256 algorithm is widely used in cryptographic 8 | * applications to produce a fixed-size 256-bit (32-byte) hash. 9 | * 10 | * The methods of this class are asynchronous and return Promises. They use the Uint8Array 11 | * type for input data and the resulting digest, ensuring a consistent interface 12 | * for binary data processing. 13 | * 14 | * @example 15 | * ```ts 16 | * const data = new Uint8Array([...]); 17 | * const hash = await Sha256.digest({ data }); 18 | * ``` 19 | */ 20 | export class Sha256 { 21 | /** 22 | * Generates a SHA-256 hash digest for the given data. 23 | * 24 | * @remarks 25 | * This method produces a hash digest using the SHA-256 algorithm. The resultant digest 26 | * is deterministic, meaning the same data will always produce the same hash, but 27 | * is computationally infeasible to regenerate the original data from the hash. 28 | * 29 | * @example 30 | * ```ts 31 | * const data = new Uint8Array([...]); 32 | * const hash = await Sha256.digest({ data }); 33 | * ``` 34 | * 35 | * @param params - The parameters for the hashing operation. 36 | * @param params.data - The data to hash, represented as a Uint8Array. 37 | * 38 | * @returns A Promise that resolves to the SHA-256 hash digest of the provided data as a Uint8Array. 39 | */ 40 | public static async digest({ data }: { 41 | data: Uint8Array; 42 | }): Promise { 43 | const hash = sha256(data); 44 | 45 | return hash; 46 | } 47 | } -------------------------------------------------------------------------------- /packages/crypto/src/types/hasher.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The `Hasher` interface provides a method for generating digests of data using hash functions. 3 | * It defines the core function `digest()` for processing variable-size input data to produce a 4 | * fixed-size output (the "digest") which uniquely represents the input data. 5 | * 6 | * This method operates asynchronously and returns a digest, often used for data integrity checks. 7 | * The interface can be implemented with various hash algorithms and their unique parameters. 8 | * 9 | * The interface is designed to accommodate byte array input data but can be extended to support 10 | * other input types as needed. 11 | */ 12 | export interface Hasher { 13 | /** 14 | * Generates a hash digest of the provided data. 15 | * 16 | * @remarks 17 | * The `digest()` method of the {@link Hasher | `Hasher`} interface generates a hash digest of the 18 | * input data. 19 | * 20 | * A digest is the output of the hash function. It's a fixed-size string of bytes 21 | * that uniquely represents the data input into the hash function. The digest is often used for 22 | * data integrity checks, as any alteration in the input data results in a significantly 23 | * different digest. 24 | * 25 | * It typically takes the data to digest as input and returns the digest of the data. 26 | * 27 | * @param params - The parameters for the digest operation. 28 | * 29 | * @returns A Promise which will be fulfilled with the hash digest. 30 | */ 31 | digest(params: DigestInput): Promise; 32 | } -------------------------------------------------------------------------------- /packages/crypto/src/types/identifier.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Represents an identifier for a cryptographic algorithm. 3 | * 4 | * This is typically a string that specifies the name of the algorithm, such as 'ES256K', 'A256GCM', 5 | * 'SHA-256', etc. It's used to refer to the specific algorithm in cryptographic operations. 6 | */ 7 | export type AlgorithmIdentifier = string; 8 | 9 | /** 10 | * Denotes an identifier for a cryptographic key. 11 | * 12 | * It's a string used to uniquely identify a key within a given context, such as in key management 13 | * systems (KMS) or cryptographic protocols. This identifier can be a simple string, a UUID, a URI, 14 | * or any format chosen to suit the application's needs. 15 | */ 16 | export type KeyIdentifier = string; -------------------------------------------------------------------------------- /packages/crypto/src/types/key-compressor.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * `KeyCompressor` interface for converting public keys between compressed and uncompressed form. 3 | */ 4 | export interface KeyCompressor { 5 | 6 | /** 7 | * Converts a public key to its compressed form. 8 | * 9 | * @param params - The parameters for the public key compression. 10 | * @param params.publicKeyBytes - The public key as a Uint8Array. 11 | * 12 | * @returns A Promise that resolves to the compressed public key as a Uint8Array. 13 | */ 14 | compressPublicKey(params: { publicKeyBytes: Uint8Array }): Promise; 15 | 16 | /** 17 | * Converts a public key to its uncompressed form. 18 | * 19 | * @param params - The parameters for the public key decompression. 20 | * @param params.publicKeyBytes - The public key as a Uint8Array. 21 | * 22 | * @returns A Promise that resolves to the uncompressed public key as a Uint8Array. 23 | */ 24 | decompressPublicKey(params: { publicKeyBytes: Uint8Array }): Promise; 25 | } -------------------------------------------------------------------------------- /packages/crypto/src/types/key-converter.ts: -------------------------------------------------------------------------------- 1 | import type { Jwk } from '../jose/jwk.js'; 2 | 3 | /** 4 | * `KeyConverter` interface for converting private keys between byte array and JWK formats. 5 | */ 6 | export interface KeyConverter { 7 | 8 | /** 9 | * Converts a private key from a byte array to JWK format. 10 | * 11 | * @param params - The parameters for the private key conversion. 12 | * @param params.privateKeyBytes - The raw private key as a Uint8Array. 13 | * 14 | * @returns A Promise that resolves to the private key in JWK format. 15 | */ 16 | bytesToPrivateKey(params: { privateKeyBytes: Uint8Array }): Promise; 17 | 18 | /** 19 | * Converts a private key from JWK format to a byte array. 20 | * 21 | * @param params - The parameters for the private key conversion. 22 | * @param params.privateKey - The private key in JWK format. 23 | * 24 | * @returns A Promise that resolves to the private key as a Uint8Array. 25 | */ 26 | privateKeyToBytes(params: { privateKey: Jwk }): Promise; 27 | } 28 | 29 | /** 30 | * `AsymmetricKeyConverter` interface extends {@link KeyConverter |`KeyConverter`}, adding support 31 | * for public key conversions. 32 | */ 33 | export interface AsymmetricKeyConverter extends KeyConverter { 34 | /** 35 | * Converts a public key from a byte array to JWK format. 36 | * 37 | * @param params - The parameters for the public key conversion. 38 | * @param params.publicKeyBytes - The raw public key as a Uint8Array. 39 | * 40 | * @returns A Promise that resolves to the public key in JWK format. 41 | */ 42 | bytesToPublicKey(params: { publicKeyBytes: Uint8Array }): Promise; 43 | 44 | /** 45 | * Converts a public key from JWK format to a byte array. 46 | * 47 | * @param params - The parameters for the public key conversion. 48 | * @param params.publicKey - The public key in JWK format. 49 | * 50 | * @returns A Promise that resolves to the public key as a Uint8Array. 51 | */ 52 | publicKeyToBytes(params: { publicKey: Jwk }): Promise; 53 | } -------------------------------------------------------------------------------- /packages/crypto/src/types/key-io.ts: -------------------------------------------------------------------------------- 1 | import type { Jwk } from '../jose/jwk.js'; 2 | 3 | /** 4 | * The `KeyImporterExporter` interface provides methods for importing and exporting cryptographic 5 | * keys. It includes `importKey()` for importing external keys, and `exportKey()` for exporting a 6 | * cryptographic key to an external JWK object. 7 | * 8 | * This interface is designed to handle various key formats and is adaptable for different 9 | * cryptographic environments and requirements. 10 | */ 11 | export interface KeyImporterExporter< 12 | ImportKeyInput, 13 | ImportKeyOutput, 14 | ExportKeyInput 15 | > { 16 | /** 17 | * Exports a cryptographic key to an external JWK object. 18 | * 19 | * @remarks 20 | * The `exportKey()` method of the {@link KeyImporterExporter | `KeyImporterExporter`} interface 21 | * returns a cryptographic key in JWK format, facilitating interoperability and backup. 22 | * 23 | * @param params - The parameters for the key export operation. 24 | * 25 | * @returns A Promise resolving to the exported key in JWK format. 26 | */ 27 | exportKey(params: ExportKeyInput): Promise; 28 | 29 | /** 30 | * Imports an external key in JWK format. 31 | * 32 | * @remarks 33 | * The `importKey()` method of the {@link KeyImporterExporter | `KeyImporterExporter`} interface 34 | * takes as input an external key in JWK format and typically returns a key identifier reference 35 | * for the imported key. 36 | * 37 | * @param params - The parameters for the key import operation. 38 | * 39 | * @returns A Promise resolving to the key identifier of the imported key. 40 | */ 41 | importKey(params: ImportKeyInput): Promise; 42 | } -------------------------------------------------------------------------------- /packages/crypto/src/types/key-wrapper.ts: -------------------------------------------------------------------------------- 1 | import type { Jwk } from '../jose/jwk.js'; 2 | 3 | /** 4 | * The `KeyWrapper` interface provides methods for wrapping and unwrapping cryptographic keys. 5 | * It includes `wrapKey()` for securely encapsulating a key within another key, and `unwrapKey()` 6 | * for extracting the original key from its wrapped state. 7 | * 8 | * This interface is crucial in scenarios where secure key management and exchange are required, 9 | * ensuring that keys remain protected during transit or storage. 10 | */ 11 | export interface KeyWrapper< 12 | WrapKeyInput, 13 | UnwrapKeyInput 14 | > { 15 | /** 16 | * Wraps a cryptographic key using another key, typically for secure key transmission or storage. 17 | * 18 | * @remarks 19 | * The `wrapKey()` method of the {@link KeyWrapper | `KeyWrapper`} interface secures a 20 | * cryptographic key by encapsulating it within another key, producing a wrapped key represented 21 | * as a `Uint8Array`. 22 | * 23 | * @param params - The parameters for the key wrapping operation. 24 | * 25 | * @returns A Promise resolving to the wrapped key as a `Uint8Array`. 26 | */ 27 | wrapKey(params: WrapKeyInput): Promise; 28 | 29 | /** 30 | * Unwraps a previously wrapped cryptographic key, restoring it to its original form. 31 | * 32 | * @remarks 33 | * The `unwrapKey()` method of the {@link KeyWrapper | `KeyWrapper`} interface reverses the 34 | * wrapping process, extracting the original key from its wrapped state, typically for use in 35 | * cryptographic operations. 36 | * 37 | * @param params - The parameters for the key unwrapping operation. 38 | * 39 | * @returns A Promise resolving to the unwrapped key in a cryptographic format, usually JWK. 40 | */ 41 | unwrapKey(params: UnwrapKeyInput): Promise; 42 | } -------------------------------------------------------------------------------- /packages/crypto/src/types/params-enclosed.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Parameters for enclosed decryption operations. 3 | * 4 | * Note: This interface is intended to be used with a closure that captures the key and 5 | * algorithm-specific parameters so that arbitrary data can be decrypted without exposing the key or 6 | * parameters to the caller. 7 | */ 8 | export interface EnclosedDecryptParams { 9 | /** Data to be decrypted. */ 10 | data: Uint8Array; 11 | } 12 | 13 | /** 14 | * Parameters for enclosed encryption operations. 15 | * 16 | * Note: This interface is intended to be used with a closure that captures the key and 17 | * algorithm-specific parameters so that arbitrary data can be encrypted without exposing the key or 18 | * parameters to the caller. 19 | */ 20 | export interface EnclosedEncryptParams { 21 | /** Data to be encrypted. */ 22 | data: Uint8Array; 23 | } 24 | 25 | /** 26 | * Parameters for enclosed signing operations. 27 | * 28 | * Note: This interface is intended to be used with a closure that captures the key and 29 | * algorithm-specific parameters so that arbitrary data can be signed without exposing the key or 30 | * parameters to the caller. 31 | */ 32 | export interface EnclosedSignParams { 33 | /** Data to be signed. */ 34 | data: Uint8Array; 35 | } 36 | 37 | /** 38 | * Parameters for enclosed verification operations. 39 | * 40 | * Note: This interface is intended to be used with a closure that captures the key and 41 | * algorithm-specific parameters so that signatures of arbitrary data can be verified without 42 | * exposing the key or parameters to the caller. 43 | */ 44 | export interface EnclosedVerifyParams { 45 | /** Signature to be verified. */ 46 | signature: Uint8Array; 47 | 48 | /** Data associated with the signature. */ 49 | data: Uint8Array; 50 | } -------------------------------------------------------------------------------- /packages/crypto/tests/algorithms/sha-2.spec.ts: -------------------------------------------------------------------------------- 1 | import { expect } from 'chai'; 2 | import { Convert } from '@web5/common'; 3 | 4 | import { Sha2Algorithm } from '../../src/algorithms/sha-2.js'; 5 | 6 | describe('Sha2Algorithm', () => { 7 | let sha2: Sha2Algorithm; 8 | 9 | beforeEach(() => { 10 | sha2 = new Sha2Algorithm(); 11 | }); 12 | 13 | describe('digest()', () => { 14 | it('computes and returns a digest as a Uint8Array', async () => { 15 | // Setup. 16 | const data = new Uint8Array([0, 1, 2, 3, 4]); 17 | 18 | // Test the method. 19 | const digest = await sha2.digest({ algorithm: 'SHA-256', data }); 20 | 21 | // Validate the result. 22 | expect(digest).to.exist; 23 | expect(digest).to.be.an.instanceOf(Uint8Array); 24 | }); 25 | 26 | it('supports SHA-256', async () => { 27 | // Setup. 28 | const data = Convert.string('abc').toUint8Array(); 29 | const expectedOutput = Convert.hex('ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad').toUint8Array(); 30 | 31 | // Test the method. 32 | const digest = await sha2.digest({ algorithm: 'SHA-256', data }); 33 | 34 | // Validate the result. 35 | expect(digest).to.exist; 36 | expect(digest).to.be.an.instanceOf(Uint8Array); 37 | expect(digest).to.have.lengthOf(32); 38 | expect(digest).to.deep.equal(expectedOutput); 39 | }); 40 | }); 41 | }); -------------------------------------------------------------------------------- /packages/crypto/tests/fixtures/test-vectors/aes-ctr/decrypt.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "AES-CTR decrypt test vectors", 3 | "vectors": [ 4 | { 5 | "description": "matches NIST 800-38A F.5.1 output", 6 | "input": { 7 | "key": "2b7e151628aed2a6abf7158809cf4f3c", 8 | "data": "874d6191b620e3261bef6864990db6ce9806f66b7970fdff8617187bb9fffdff5ae4df3edbd5d35e5b4f09020db03eab1e031dda2fbe03d1792170a0f3009cee", 9 | "counter": "f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", 10 | "length": 128 11 | }, 12 | "output": "6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc1191a0a52eff69f2445df4f9b17ad2b417be66c3710" 13 | }, 14 | { 15 | "description": "matches NIST 800-38A F.5.3 output", 16 | "input": { 17 | "key": "8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b", 18 | "data": "1abc932417521ca24f2b0459fe7e6e0b090339ec0aa6faefd5ccc2c6f4ce8e941e36b26bd1ebc670d1bd1d665620abf74f78a7f6d29809585a97daec58c6b050", 19 | "counter": "f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", 20 | "length": 128 21 | }, 22 | "output": "6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc1191a0a52eff69f2445df4f9b17ad2b417be66c3710" 23 | }, 24 | { 25 | "description": "matches NIST 800-38A F.5.5 output", 26 | "input": { 27 | "key": "603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4", 28 | "data": "601ec313775789a5b7a7f504bbf3d228f443e3ca4d62b59aca84e990cacaf5c52b0930daa23de94ce87017ba2d84988ddfc9c58db67aada613c2dd08457941a6", 29 | "counter": "f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", 30 | "length": 128 31 | }, 32 | "output": "6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc1191a0a52eff69f2445df4f9b17ad2b417be66c3710" 33 | } 34 | ] 35 | } -------------------------------------------------------------------------------- /packages/crypto/tests/fixtures/test-vectors/aes-ctr/encrypt.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "AES-CTR encrypt test vectors", 3 | "vectors": [ 4 | { 5 | "description": "matches NIST 800-38A F.5.1 output", 6 | "input": { 7 | "key": "2b7e151628aed2a6abf7158809cf4f3c", 8 | "data": "6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc1191a0a52eff69f2445df4f9b17ad2b417be66c3710", 9 | "counter": "f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", 10 | "length": 128 11 | }, 12 | "output": "874d6191b620e3261bef6864990db6ce9806f66b7970fdff8617187bb9fffdff5ae4df3edbd5d35e5b4f09020db03eab1e031dda2fbe03d1792170a0f3009cee" 13 | }, 14 | { 15 | "description": "matches NIST 800-38A F.5.3 output", 16 | "input": { 17 | "key": "8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b", 18 | "data": "6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc1191a0a52eff69f2445df4f9b17ad2b417be66c3710", 19 | "counter": "f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", 20 | "length": 128 21 | }, 22 | "output": "1abc932417521ca24f2b0459fe7e6e0b090339ec0aa6faefd5ccc2c6f4ce8e941e36b26bd1ebc670d1bd1d665620abf74f78a7f6d29809585a97daec58c6b050" 23 | }, 24 | { 25 | "description": "matches NIST 800-38A F.5.5 output", 26 | "input": { 27 | "key": "603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4", 28 | "data": "6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc1191a0a52eff69f2445df4f9b17ad2b417be66c3710", 29 | "counter": "f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff", 30 | "length": 128 31 | }, 32 | "output": "601ec313775789a5b7a7f504bbf3d228f443e3ca4d62b59aca84e990cacaf5c52b0930daa23de94ce87017ba2d84988ddfc9c58db67aada613c2dd08457941a6" 33 | } 34 | ] 35 | } -------------------------------------------------------------------------------- /packages/crypto/tests/fixtures/test-vectors/aes-gcm/decrypt.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "AES-GCM encrypt test vectors", 3 | "vectors": [ 4 | { 5 | "description": "matches Wycheproof tcId 1 output", 6 | "input": { 7 | "key": "5b9604fe14eadba931b0ccf34843dab9", 8 | "data": "26073cc1d851beff176384dc9896d5ff0a3ea7a5487cb5f7d70fb6c58d038554", 9 | "iv": "028318abc1824029138141a2", 10 | "additionalData": "", 11 | "tagLength": 128 12 | }, 13 | "output": "001d0c231287c1182784554ca3a21908" 14 | }, 15 | { 16 | "description": "matches Wycheproof tcId 2 output", 17 | "input": { 18 | "key": "5b9604fe14eadba931b0ccf34843dab9", 19 | "data": "49d8b9783e911913d87094d1f63cc7651e348ba07cca2cf04c618cb4d43a5b92", 20 | "iv": "921d2507fa8007b7bd067d34", 21 | "additionalData": "00112233445566778899aabbccddeeff", 22 | "tagLength": 128 23 | }, 24 | "output": "001d0c231287c1182784554ca3a21908" 25 | } 26 | ] 27 | } -------------------------------------------------------------------------------- /packages/crypto/tests/fixtures/test-vectors/aes-gcm/encrypt.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "AES-GCM encrypt test vectors", 3 | "vectors": [ 4 | { 5 | "description": "matches Wycheproof tcId 1 output", 6 | "input": { 7 | "key": "5b9604fe14eadba931b0ccf34843dab9", 8 | "data": "001d0c231287c1182784554ca3a21908", 9 | "iv": "028318abc1824029138141a2", 10 | "additionalData": "", 11 | "tagLength": 128 12 | }, 13 | "output": "26073cc1d851beff176384dc9896d5ff0a3ea7a5487cb5f7d70fb6c58d038554" 14 | }, 15 | { 16 | "description": "matches Wycheproof tcId 2 output", 17 | "input": { 18 | "key": "5b9604fe14eadba931b0ccf34843dab9", 19 | "data": "001d0c231287c1182784554ca3a21908", 20 | "iv": "921d2507fa8007b7bd067d34", 21 | "additionalData": "00112233445566778899aabbccddeeff", 22 | "tagLength": 128 23 | }, 24 | "output": "49d8b9783e911913d87094d1f63cc7651e348ba07cca2cf04c618cb4d43a5b92" 25 | } 26 | ] 27 | } -------------------------------------------------------------------------------- /packages/crypto/tests/fixtures/test-vectors/ed25519/bytes-to-private-key.json: -------------------------------------------------------------------------------- 1 | { 2 | "description" : "Ed25519 bytesToPrivateKey test vectors", 3 | "vectors" : [ 4 | { 5 | "description" : "converts wycheproof vector 1 to the expected private key", 6 | "input" : { 7 | "privateKeyBytes": "add4bb8103785baf9ac534258e8aaf65f5f1adb5ef5f3df19bb80ab989c4d64b" 8 | }, 9 | "output": { 10 | "crv" : "Ed25519", 11 | "d" : "rdS7gQN4W6-axTQljoqvZfXxrbXvXz3xm7gKuYnE1ks", 12 | "kid" : "whzXN9WPd2qZyKXCZmDMlU5TGQjzRHZa496Dj1K0ZAs", 13 | "kty" : "OKP", 14 | "x" : "fU0Of2FTpptiQrUiq77mhf2kQg-INLEIw72uNp71Sfo" 15 | } 16 | }, 17 | { 18 | "description" : "converts wycheproof vector 2 to the expected private key", 19 | "input" : { 20 | "privateKeyBytes": "0a23a20072891237aa0864b5765139514908787878cd77135a0059881d313f00" 21 | }, 22 | "output": { 23 | "crv" : "Ed25519", 24 | "d" : "CiOiAHKJEjeqCGS1dlE5UUkIeHh4zXcTWgBZiB0xPwA", 25 | "kid" : "e1A_70UPZow2psBhMg1fT7K5FfRtkrK-PJKgGbWB6Uk", 26 | "kty" : "OKP", 27 | "x" : "oSwr63cmXyqslTtQCTSdlBVaA62kFqrUUTGUgOmDykw" 28 | } 29 | }, 30 | { 31 | "description" : "converts wycheproof vector 3 to the expected private key", 32 | "input" : { 33 | "privateKeyBytes": "9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60" 34 | }, 35 | "output": { 36 | "crv" : "Ed25519", 37 | "d" : "nWGxne_9WmC6hEr0kuwsxERJxWl7MmkZcDusAxyuf2A", 38 | "kid" : "kPrK_qmxVWaYVA9wwBF6Iuo3vVzz7TxHCTwXBygrS4k", 39 | "kty" : "OKP", 40 | "x" : "11qYAYKxCrfVS_7TyWQHOg7hcvPapiMlrwIaaPcHURo" 41 | } 42 | } 43 | ] 44 | } -------------------------------------------------------------------------------- /packages/crypto/tests/fixtures/test-vectors/ed25519/bytes-to-public-key.json: -------------------------------------------------------------------------------- 1 | { 2 | "description" : "Ed25519 bytesToPublicKey test vectors", 3 | "vectors" : [ 4 | { 5 | "description" : "converts wycheproof vector 1 to the expected public key", 6 | "input" : { 7 | "publicKeyBytes": "7d4d0e7f6153a69b6242b522abbee685fda4420f8834b108c3bdae369ef549fa" 8 | }, 9 | "output": { 10 | "crv" : "Ed25519", 11 | "kid" : "whzXN9WPd2qZyKXCZmDMlU5TGQjzRHZa496Dj1K0ZAs", 12 | "kty" : "OKP", 13 | "x" : "fU0Of2FTpptiQrUiq77mhf2kQg-INLEIw72uNp71Sfo" 14 | } 15 | }, 16 | { 17 | "description" : "converts wycheproof vector 2 to the expected public key", 18 | "input" : { 19 | "publicKeyBytes": "a12c2beb77265f2aac953b5009349d94155a03ada416aad451319480e983ca4c" 20 | }, 21 | "output": { 22 | "crv" : "Ed25519", 23 | "kid" : "e1A_70UPZow2psBhMg1fT7K5FfRtkrK-PJKgGbWB6Uk", 24 | "kty" : "OKP", 25 | "x" : "oSwr63cmXyqslTtQCTSdlBVaA62kFqrUUTGUgOmDykw" 26 | } 27 | }, 28 | { 29 | "description" : "converts wycheproof vector 3 to the expected public key", 30 | "input" : { 31 | "publicKeyBytes": "d75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a" 32 | }, 33 | "output": { 34 | "crv" : "Ed25519", 35 | "kid" : "kPrK_qmxVWaYVA9wwBF6Iuo3vVzz7TxHCTwXBygrS4k", 36 | "kty" : "OKP", 37 | "x" : "11qYAYKxCrfVS_7TyWQHOg7hcvPapiMlrwIaaPcHURo" 38 | } 39 | } 40 | ] 41 | } -------------------------------------------------------------------------------- /packages/crypto/tests/fixtures/test-vectors/ed25519/convert-private-key-to-x25519.json: -------------------------------------------------------------------------------- 1 | { 2 | "description" : "Ed25519 convertPrivateKeyToX25519 test vectors", 3 | "vectors" : [ 4 | { 5 | "description" : "converts Ed25519 private key to expected X25519 private key 1", 6 | "input" : { 7 | "privateKey": { 8 | "kty": "OKP", 9 | "crv": "Ed25519", 10 | "d": "dwdtCnMYpX08FsFyUbJmRd9ML4frwJkqsXf7pR25LCo", 11 | "x": "0KTOwPi1C6HpNuxWFUVKqX37J4ZPXxdgivLLsQVI8bM" 12 | } 13 | }, 14 | "output": { 15 | "crv": "X25519", 16 | "d": "qM1E646TMZwFcLwRAFwOAYnTT_AvbBd3NBGtGRKTyU8", 17 | "kid": "xtsuKULPh6VN9fuJMRwj66cDfQyLaxuXHkMlmAe_v6I", 18 | "kty": "OKP", 19 | "x": "7XdJtNmJ9pV_O_3mxWdn6YjiHJ-HhNkdYQARzVU_mwY" 20 | } 21 | }, 22 | { 23 | "description" : "converts Ed25519 private key to expected X25519 private key 2", 24 | "input" : { 25 | "privateKey": { 26 | "kty": "OKP", 27 | "crv": "Ed25519", 28 | "d": "aeJsLIvfKVFAqRpCzldslD-NXtKItqK0jAs2vOxbGcA", 29 | "x": "0nQq-UcELyC07P95hpWOOChIzrWhLC5P8I-EtoyBvwI" 30 | } 31 | }, 32 | "output": { 33 | "crv": "X25519", 34 | "d": "oJofguv460IW5L3-7FmN3MttwqHTN3vbn5kJbbqxmGw", 35 | "kid": "2o1RtaNsesiPxOTA4nqjKi8tuFPK4goGW5geg8R8YYA", 36 | "kty": "OKP", 37 | "x": "2gWwpR90WzM8pF6c2u4hVkisC9Z_vibouROB-bRpVhc" 38 | } 39 | } 40 | ] 41 | } -------------------------------------------------------------------------------- /packages/crypto/tests/fixtures/test-vectors/ed25519/convert-public-key-to-x25519.json: -------------------------------------------------------------------------------- 1 | { 2 | "description" : "Ed25519 convertPublicKeyToX25519 test vectors", 3 | "vectors" : [ 4 | { 5 | "description" : "converts Ed25519 public key to expected X25519 public key 1", 6 | "input" : { 7 | "publicKey": { 8 | "kty": "OKP", 9 | "crv": "Ed25519", 10 | "x": "0KTOwPi1C6HpNuxWFUVKqX37J4ZPXxdgivLLsQVI8bM" 11 | } 12 | }, 13 | "output": { 14 | "crv": "X25519", 15 | "kid": "xtsuKULPh6VN9fuJMRwj66cDfQyLaxuXHkMlmAe_v6I", 16 | "kty": "OKP", 17 | "x": "7XdJtNmJ9pV_O_3mxWdn6YjiHJ-HhNkdYQARzVU_mwY" 18 | } 19 | }, 20 | { 21 | "description" : "converts Ed25519 public key to expected X25519 public key 2", 22 | "input" : { 23 | "publicKey": { 24 | "kty": "OKP", 25 | "crv": "Ed25519", 26 | "x": "kZoyeYylO0RwCTgPuX-MG0V2YcqXOBVWL5TwCsWhkzU" 27 | } 28 | }, 29 | "output": { 30 | "crv": "X25519", 31 | "kid": "O7xmoK9ptzlG6ewnl1cQ-6DbVgzIeMhP4nHUM8oD_M8", 32 | "kty": "OKP", 33 | "x": "cz3yKnz6Wfc1GchUbCDR-Pp2jZeXLTehnzPTsBJ_J14" 34 | } 35 | } 36 | ] 37 | } -------------------------------------------------------------------------------- /packages/crypto/tests/fixtures/test-vectors/ed25519/private-key-to-bytes.json: -------------------------------------------------------------------------------- 1 | { 2 | "description" : "Ed25519 privateKeyToBytes test vectors", 3 | "vectors" : [ 4 | { 5 | "description" : "converts wycheproof vector 1 to the expected byte array", 6 | "input" : { 7 | "privateKey": { 8 | "crv" : "Ed25519", 9 | "d" : "rdS7gQN4W6-axTQljoqvZfXxrbXvXz3xm7gKuYnE1ks", 10 | "kid" : "whzXN9WPd2qZyKXCZmDMlU5TGQjzRHZa496Dj1K0ZAs", 11 | "kty" : "OKP", 12 | "x" : "fU0Of2FTpptiQrUiq77mhf2kQg-INLEIw72uNp71Sfo" 13 | } 14 | }, 15 | "output": "add4bb8103785baf9ac534258e8aaf65f5f1adb5ef5f3df19bb80ab989c4d64b" 16 | }, 17 | { 18 | "description" : "converts wycheproof vector 2 to the expected byte array", 19 | "input" : { 20 | "privateKey": { 21 | "crv" : "Ed25519", 22 | "d" : "CiOiAHKJEjeqCGS1dlE5UUkIeHh4zXcTWgBZiB0xPwA", 23 | "kid" : "e1A_70UPZow2psBhMg1fT7K5FfRtkrK-PJKgGbWB6Uk", 24 | "kty" : "OKP", 25 | "x" : "oSwr63cmXyqslTtQCTSdlBVaA62kFqrUUTGUgOmDykw" 26 | } 27 | }, 28 | "output": "0a23a20072891237aa0864b5765139514908787878cd77135a0059881d313f00" 29 | }, 30 | { 31 | "description" : "converts wycheproof vector 3 to the expected byte array", 32 | "input" : { 33 | "privateKey": { 34 | "crv" : "Ed25519", 35 | "d" : "nWGxne_9WmC6hEr0kuwsxERJxWl7MmkZcDusAxyuf2A", 36 | "kid" : "kPrK_qmxVWaYVA9wwBF6Iuo3vVzz7TxHCTwXBygrS4k", 37 | "kty" : "OKP", 38 | "x" : "11qYAYKxCrfVS_7TyWQHOg7hcvPapiMlrwIaaPcHURo" 39 | } 40 | }, 41 | "output": "9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60" 42 | } 43 | ] 44 | } -------------------------------------------------------------------------------- /packages/crypto/tests/fixtures/test-vectors/ed25519/public-key-to-bytes.json: -------------------------------------------------------------------------------- 1 | { 2 | "description" : "Ed25519 publicKeyToBytes test vectors", 3 | "vectors" : [ 4 | { 5 | "description" : "converts wycheproof vector 1 to the expected byte array", 6 | "input" : { 7 | "publicKey": { 8 | "crv" : "Ed25519", 9 | "kid" : "whzXN9WPd2qZyKXCZmDMlU5TGQjzRHZa496Dj1K0ZAs", 10 | "kty" : "OKP", 11 | "x" : "fU0Of2FTpptiQrUiq77mhf2kQg-INLEIw72uNp71Sfo" 12 | } 13 | }, 14 | "output": "7d4d0e7f6153a69b6242b522abbee685fda4420f8834b108c3bdae369ef549fa" 15 | }, 16 | { 17 | "description" : "converts wycheproof vector 2 to the expected byte array", 18 | "input" : { 19 | "publicKey": { 20 | "crv" : "Ed25519", 21 | "kid" : "e1A_70UPZow2psBhMg1fT7K5FfRtkrK-PJKgGbWB6Uk", 22 | "kty" : "OKP", 23 | "x" : "oSwr63cmXyqslTtQCTSdlBVaA62kFqrUUTGUgOmDykw" 24 | } 25 | }, 26 | "output": "a12c2beb77265f2aac953b5009349d94155a03ada416aad451319480e983ca4c" 27 | }, 28 | { 29 | "description" : "converts wycheproof vector 3 to the expected byte array", 30 | "input" : { 31 | "publicKey": { 32 | "crv" : "Ed25519", 33 | "kid" : "kPrK_qmxVWaYVA9wwBF6Iuo3vVzz7TxHCTwXBygrS4k", 34 | "kty" : "OKP", 35 | "x" : "11qYAYKxCrfVS_7TyWQHOg7hcvPapiMlrwIaaPcHURo" 36 | } 37 | }, 38 | "output": "d75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a" 39 | } 40 | ] 41 | } -------------------------------------------------------------------------------- /packages/crypto/tests/fixtures/test-vectors/jwk.ts: -------------------------------------------------------------------------------- 1 | export const jwkToThumbprintTestVectors = [ 2 | { 3 | input: { 4 | kty : 'RSA', 5 | n : '0vx7agoebGcQSuuPiLJXZptN9nndrQmbXEps2aiAFbWhM78LhWx4cbbfAAtVT86zwu1RK7aPFFxuhDR1L6tSoc_BJECPebWKRXjBZCiFV4n3oknjhMstn64tZ_2W-5JsGY4Hc5n9yBXArwl93lqt7_RN5w6Cf0h4QyQ5v-65YGjQR0_FDW2QvzqY368QQMicAtaSqzs8KJZgnYb9c7d0zgdAZHzu6qMQvRL5hajrn1n91CbOpbISD08qNLyrdkt-bFTWhAI4vMQFh6WeZu0fM4lFd2NcRwr3XPksINHaQ-G_xBniIqbw0Ls1jF44-csFCur-kEgU8awapJzKnqDKgw', 6 | e : 'AQAB', 7 | alg : 'RS256', 8 | kid : '2011-04-29', 9 | }, 10 | output: 'NzbLsXh8uDCcd-6MNwXF4W_7noWXFZAfHkxZsRGC9Xs', 11 | }, 12 | { 13 | input: { 14 | alg : 'A128CBC', 15 | kty : 'oct', 16 | k : 'cuY-fEu_V1s4b8HbGzy_9VOaNtxiUPzLn6KOATdz0ks', 17 | }, 18 | output: 'legaImFEtXYAJYZ8_ZGbZnx-bhc_9nN53pxGpOum3Io', 19 | }, 20 | { 21 | input: { 22 | alg : 'ES256K', 23 | crv : 'secp256k1', 24 | kty : 'EC', 25 | x : '_TihFv5t24hjWsRcdZBeEJa65hQB5aiOYmG6mMu1RZA', 26 | y : 'UfiOGckhJuh9f3-Yi7g-jTILYP6vEWOSF1drwjBHebA', 27 | }, 28 | output: 'dwzDb6KNsqS3QMTqH0jfBHcoHJzYZBc5scB5n5VLe1E', 29 | }, 30 | { 31 | input: { 32 | crv : 'X25519', 33 | kty : 'OKP', 34 | x : 'cuY-fEu_V1s4b8HbGzy_9VOaNtxiUPzLn6KOATdz0ks', 35 | }, 36 | output: 'KCfBQ0EA2cWr1Kbt-mnlj8LQ9C2AJfcuEm8mtgOe7wQ', 37 | }, 38 | { 39 | input: { 40 | d : 'MJf4AAqcwfBC68Wkb8nRbmnIdHb07zYM7vU_TAOgmtM', 41 | crv : 'X25519', 42 | kty : 'OKP', 43 | x : 'Uszsfy4vkz9MKeflgUpQot7sJhDyco2aYWCRXKTrcQg', 44 | }, 45 | output: 'lQN1EkHZz4VkAcVGD4gsc0JBcLwvkUprOxkiO4kpbbs', 46 | }, 47 | ]; -------------------------------------------------------------------------------- /packages/crypto/tests/fixtures/test-vectors/secp256k1/get-curve-points.json: -------------------------------------------------------------------------------- 1 | { 2 | "description" : "Secp256k1 getCurvePoints test vectors", 3 | "vectors" : [ 4 | { 5 | "description" : "returns public key x and y coordinates given a public key", 6 | "input" : { 7 | "keyBytes": "043752951274023296c8a74b0ffe42f82ff4b4d4bba4326477422703f761f59258c26a7465b9a77ac0c3f1cedb139c428b0b1fbb5516867b527636f3286f705553" 8 | }, 9 | "output": { 10 | "x": "3752951274023296c8a74b0ffe42f82ff4b4d4bba4326477422703f761f59258", 11 | "y": "c26a7465b9a77ac0c3f1cedb139c428b0b1fbb5516867b527636f3286f705553" 12 | } 13 | }, 14 | { 15 | "description" : "returns public key x and y coordinates given a private key", 16 | "input" : { 17 | "keyBytes": "740ec69810de9ad1b8f298f1d2c0e6a52dd1e958dc2afc85764bec169c222e88" 18 | }, 19 | "output": { 20 | "x": "3752951274023296c8a74b0ffe42f82ff4b4d4bba4326477422703f761f59258", 21 | "y": "c26a7465b9a77ac0c3f1cedb139c428b0b1fbb5516867b527636f3286f705553" 22 | } 23 | }, 24 | { 25 | "description" : "handles private keys that require padded x-coordinate when converting from BigInt to bytes", 26 | "input" : { 27 | "keyBytes": "0206a1f9628c5bcd31f3bbc2f160ec98f99960147e04ea192f56c53a0086c5432d" 28 | }, 29 | "output": { 30 | "x": "06a1f9628c5bcd31f3bbc2f160ec98f99960147e04ea192f56c53a0086c5432d", 31 | "y": "bf2efab7943be51219a283c0979ccba0fbe03f571e75b0eb338cc2ec01e70552" 32 | } 33 | }, 34 | { 35 | "description" : "handles private keys that require padded y-coordinate when converting from BigInt to bytes", 36 | "input" : { 37 | "keyBytes": "032ff752fb8fc6af85c8682b0ca9d48901b2b9ac130f558bd1a9092240d42c4682" 38 | }, 39 | "output": { 40 | "x": "2ff752fb8fc6af85c8682b0ca9d48901b2b9ac130f558bd1a9092240d42c4682", 41 | "y": "048c39d9ebdc1fd98bda38b7f00b93de1d2af5bb3ba8cb532ad47c1f36e19501" 42 | } 43 | } 44 | ] 45 | } -------------------------------------------------------------------------------- /packages/crypto/tests/fixtures/test-vectors/secp256k1/validate-private-key.json: -------------------------------------------------------------------------------- 1 | { 2 | "description" : "Secp256k1 validatePrivateKey test vectors", 3 | "vectors" : [ 4 | { 5 | "description" : "returns true for valid private keys", 6 | "input" : { 7 | "privateKeyBytes": "740ec69810de9ad1b8f298f1d2c0e6a52dd1e958dc2afc85764bec169c222e88" 8 | }, 9 | "output": true 10 | }, 11 | { 12 | "description" : "returns false for invalid private keys", 13 | "input" : { 14 | "privateKeyBytes": "02fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f" 15 | }, 16 | "output": false 17 | }, 18 | { 19 | "description" : "returns false if a compressed public key is given", 20 | "input" : { 21 | "privateKeyBytes": "026bcdccc644b309921d3b0c266183a20786650c1634d34e8dfa1ed74cd66ce214" 22 | }, 23 | "output": false 24 | }, 25 | { 26 | "description" : "returns false if an uncompressed public key is given", 27 | "input" : { 28 | "privateKeyBytes": "043752951274023296c8a74b0ffe42f82ff4b4d4bba4326477422703f761f59258c26a7465b9a77ac0c3f1cedb139c428b0b1fbb5516867b527636f3286f705553" 29 | }, 30 | "output": false 31 | } 32 | ] 33 | } -------------------------------------------------------------------------------- /packages/crypto/tests/fixtures/test-vectors/secp256k1/validate-public-key.json: -------------------------------------------------------------------------------- 1 | { 2 | "description" : "Secp256k1 validatePublicKey test vectors", 3 | "vectors" : [ 4 | { 5 | "description" : "returns true for valid compressed public keys", 6 | "input" : { 7 | "publicKeyBytes": "026bcdccc644b309921d3b0c266183a20786650c1634d34e8dfa1ed74cd66ce214" 8 | }, 9 | "output": true 10 | }, 11 | { 12 | "description" : "returns true for valid uncompressed public keys", 13 | "input" : { 14 | "publicKeyBytes": "043752951274023296c8a74b0ffe42f82ff4b4d4bba4326477422703f761f59258c26a7465b9a77ac0c3f1cedb139c428b0b1fbb5516867b527636f3286f705553" 15 | }, 16 | "output": true 17 | }, 18 | { 19 | "description" : "returns false for invalid public keys", 20 | "input" : { 21 | "publicKeyBytes": "02fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f" 22 | }, 23 | "output": false 24 | }, 25 | { 26 | "description" : "returns false if a private key is given", 27 | "input" : { 28 | "publicKeyBytes": "740ec69810de9ad1b8f298f1d2c0e6a52dd1e958dc2afc85764bec169c222e88" 29 | }, 30 | "output": false 31 | } 32 | ] 33 | } -------------------------------------------------------------------------------- /packages/crypto/tests/fixtures/test-vectors/secp256r1/bytes-to-private-key.json: -------------------------------------------------------------------------------- 1 | { 2 | "description" : "Secp256k1 bytesToPrivateKey test vectors", 3 | "vectors" : [ 4 | { 5 | "description" : "converts RFC6979 vector 1 to the expected private key", 6 | "input" : { 7 | "privateKeyBytes": "c9afa9d845ba75166b5c215767b1d6934e50c3db36e89b127b8a622b120f6721" 8 | }, 9 | "output": { 10 | "crv" : "P-256", 11 | "d" : "ya-p2EW6dRZrXCFXZ7HWk05Qw9s26JsSe4piKxIPZyE", 12 | "kid" : "DOvxvJiAdIqVWIkFt5hDtCunXLF0BV4-JGv4f-ALSm0", 13 | "kty" : "EC", 14 | "x" : "YP7UuiVanTHJYet0xjVtaMBJuJI7Yfps5mliLmDyn7Y", 15 | "y": "eQP-EAi4vJmkGunpVii8ZPLxsgwtfp9Rd6PClNRGIpk" 16 | } 17 | } 18 | ] 19 | } -------------------------------------------------------------------------------- /packages/crypto/tests/fixtures/test-vectors/secp256r1/bytes-to-public-key.json: -------------------------------------------------------------------------------- 1 | { 2 | "description" : "Secp256r1 bytesToPublicKey test vectors", 3 | "vectors" : [ 4 | { 5 | "description" : "converts wycheproof vector 1 to the expected public key", 6 | "input" : { 7 | "publicKeyBytes": "042927b10512bae3eddcfe467828128bad2903269919f7086069c8c4df6c732838c7787964eaac00e5921fb1498a60f4606766b3d9685001558d1a974e7341513e" 8 | }, 9 | "output": { 10 | "crv" : "P-256", 11 | "kid" : "UB0bE6ogZhikgZQC5i4LIZIpUDDiJ6AnzpDOzOEwJiA", 12 | "kty" : "EC", 13 | "x" : "KSexBRK64-3c_kZ4KBKLrSkDJpkZ9whgacjE32xzKDg", 14 | "y": "x3h5ZOqsAOWSH7FJimD0YGdms9loUAFVjRqXTnNBUT4" 15 | } 16 | }, 17 | { 18 | "description" : "converts wycheproof vector 2 to the expected public key", 19 | "input" : { 20 | "publicKeyBytes": "040ad99500288d466940031d72a9f5445a4d43784640855bf0a69874d2de5fe103c5011e6ef2c42dcd50d5d3d29f99ae6eba2c80c9244f4c5422f0979ff0c3ba5e" 21 | }, 22 | "output": { 23 | "crv" : "P-256", 24 | "kid" : "rC40rZh4ODQ5Y3RKw0dLQBXkVQbkEpCHEoNyFzeSIMU", 25 | "kty" : "EC", 26 | "x" : "CtmVACiNRmlAAx1yqfVEWk1DeEZAhVvwpph00t5f4QM", 27 | "y": "xQEebvLELc1Q1dPSn5mubrosgMkkT0xUIvCXn_DDul4" 28 | } 29 | }, 30 | { 31 | "description" : "converts wycheproof vector 3 to the expected public key", 32 | "input" : { 33 | "publicKeyBytes": "04ab05fd9d0de26b9ce6f4819652d9fc69193d0aa398f0fba8013e09c58220455419235271228c786759095d12b75af0692dd4103f19f6a8c32f49435a1e9b8d45" 34 | }, 35 | "output": { 36 | "crv" : "P-256", 37 | "kid" : "UnGLajygjRCFie0aEyUb9y6Ec_ZohzbqY7sggZGL6Tk", 38 | "kty" : "EC", 39 | "x" : "qwX9nQ3ia5zm9IGWUtn8aRk9CqOY8PuoAT4JxYIgRVQ", 40 | "y": "GSNScSKMeGdZCV0St1rwaS3UED8Z9qjDL0lDWh6bjUU" 41 | } 42 | } 43 | ] 44 | } -------------------------------------------------------------------------------- /packages/crypto/tests/fixtures/test-vectors/secp256r1/get-curve-points.json: -------------------------------------------------------------------------------- 1 | { 2 | "description" : "Secp256k1 getCurvePoints test vectors", 3 | "vectors" : [ 4 | { 5 | "description" : "returns public key x and y coordinates given a public key", 6 | "input" : { 7 | "keyBytes": "048b542fa180e78bc981e6671374a64413e0323b439d06870dc49cb56e97775d96a0e469310d10a8ff2cb253a08d46fd845ae330e3ac4e41d0d0a85fbeb8e15795" 8 | }, 9 | "output": { 10 | "x": "8b542fa180e78bc981e6671374a64413e0323b439d06870dc49cb56e97775d96", 11 | "y": "a0e469310d10a8ff2cb253a08d46fd845ae330e3ac4e41d0d0a85fbeb8e15795" 12 | } 13 | }, 14 | { 15 | "description" : "returns public key x and y coordinates given a private key", 16 | "input" : { 17 | "keyBytes": "08169cf81812f2e288a1131de246ebdf29b020c7625a98d098296a30a876d35a" 18 | }, 19 | "output": { 20 | "x": "25f61964e7797e36d9c369b752f53e33033c473e6db4697d74950095a1bfbe49", 21 | "y": "9c2077c6252c520501e365868a22e3a8a8106bf7be95096394d9095c55239366" 22 | } 23 | } 24 | ] 25 | } -------------------------------------------------------------------------------- /packages/crypto/tests/fixtures/test-vectors/secp256r1/private-key-to-bytes.json: -------------------------------------------------------------------------------- 1 | { 2 | "description" : "Secp256k1 bytesToPrivateKey test vectors", 3 | "vectors" : [ 4 | { 5 | "description" : "converts RFC6979 vector 1 to the expected private key", 6 | "input" : { 7 | "privateKey": { 8 | "crv" : "P-256", 9 | "d" : "ya-p2EW6dRZrXCFXZ7HWk05Qw9s26JsSe4piKxIPZyE", 10 | "kid" : "DOvxvJiAdIqVWIkFt5hDtCunXLF0BV4-JGv4f-ALSm0", 11 | "kty" : "EC", 12 | "x" : "YP7UuiVanTHJYet0xjVtaMBJuJI7Yfps5mliLmDyn7Y", 13 | "y": "eQP-EAi4vJmkGunpVii8ZPLxsgwtfp9Rd6PClNRGIpk" 14 | } 15 | }, 16 | "output": "c9afa9d845ba75166b5c215767b1d6934e50c3db36e89b127b8a622b120f6721" 17 | } 18 | ] 19 | } -------------------------------------------------------------------------------- /packages/crypto/tests/fixtures/test-vectors/secp256r1/public-key-to-bytes.json: -------------------------------------------------------------------------------- 1 | { 2 | "description" : "Secp256r1 bytesToPublicKey test vectors", 3 | "vectors" : [ 4 | { 5 | "description" : "converts wycheproof vector 1 to the expected public key", 6 | "input" : { 7 | "publicKey": { 8 | "crv" : "P-256", 9 | "kid" : "UB0bE6ogZhikgZQC5i4LIZIpUDDiJ6AnzpDOzOEwJiA", 10 | "kty" : "EC", 11 | "x" : "KSexBRK64-3c_kZ4KBKLrSkDJpkZ9whgacjE32xzKDg", 12 | "y": "x3h5ZOqsAOWSH7FJimD0YGdms9loUAFVjRqXTnNBUT4" 13 | } 14 | }, 15 | "output": "042927b10512bae3eddcfe467828128bad2903269919f7086069c8c4df6c732838c7787964eaac00e5921fb1498a60f4606766b3d9685001558d1a974e7341513e" 16 | }, 17 | { 18 | "description" : "converts wycheproof vector 2 to the expected public key", 19 | "input" : { 20 | "publicKey": { 21 | "crv" : "P-256", 22 | "kid" : "rC40rZh4ODQ5Y3RKw0dLQBXkVQbkEpCHEoNyFzeSIMU", 23 | "kty" : "EC", 24 | "x" : "CtmVACiNRmlAAx1yqfVEWk1DeEZAhVvwpph00t5f4QM", 25 | "y": "xQEebvLELc1Q1dPSn5mubrosgMkkT0xUIvCXn_DDul4" 26 | } 27 | }, 28 | "output": "040ad99500288d466940031d72a9f5445a4d43784640855bf0a69874d2de5fe103c5011e6ef2c42dcd50d5d3d29f99ae6eba2c80c9244f4c5422f0979ff0c3ba5e" 29 | }, 30 | { 31 | "description" : "converts wycheproof vector 3 to the expected public key", 32 | "input" : { 33 | "publicKey": { 34 | "crv" : "P-256", 35 | "kid" : "UnGLajygjRCFie0aEyUb9y6Ec_ZohzbqY7sggZGL6Tk", 36 | "kty" : "EC", 37 | "x" : "qwX9nQ3ia5zm9IGWUtn8aRk9CqOY8PuoAT4JxYIgRVQ", 38 | "y": "GSNScSKMeGdZCV0St1rwaS3UED8Z9qjDL0lDWh6bjUU" 39 | } 40 | }, 41 | "output": "04ab05fd9d0de26b9ce6f4819652d9fc69193d0aa398f0fba8013e09c58220455419235271228c786759095d12b75af0692dd4103f19f6a8c32f49435a1e9b8d45" 42 | } 43 | ] 44 | } -------------------------------------------------------------------------------- /packages/crypto/tests/fixtures/test-vectors/secp256r1/validate-private-key.json: -------------------------------------------------------------------------------- 1 | { 2 | "description" : "Secp256r1 validatePrivateKey test vectors", 3 | "vectors" : [ 4 | { 5 | "description" : "returns true for valid private keys", 6 | "input" : { 7 | "privateKeyBytes": "08169cf81812f2e288a1131de246ebdf29b020c7625a98d098296a30a876d35a" 8 | }, 9 | "output": true 10 | }, 11 | { 12 | "description" : "returns false for invalid private keys", 13 | "input" : { 14 | "privateKeyBytes": "02fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f" 15 | }, 16 | "output": false 17 | }, 18 | { 19 | "description" : "returns false if a compressed public key is given", 20 | "input" : { 21 | "privateKeyBytes": "02ca156301f628b64ef0ccff5aba2f78f29bc865fc1da35f1b4e8f3726f1f2d987" 22 | }, 23 | "output": false 24 | }, 25 | { 26 | "description" : "returns false if an uncompressed public key is given", 27 | "input" : { 28 | "privateKeyBytes": "048b542fa180e78bc981e6671374a64413e0323b439d06870dc49cb56e97775d96a0e469310d10a8ff2cb253a08d46fd845ae330e3ac4e41d0d0a85fbeb8e15795" 29 | }, 30 | "output": false 31 | } 32 | ] 33 | } -------------------------------------------------------------------------------- /packages/crypto/tests/fixtures/test-vectors/secp256r1/validate-public-key.json: -------------------------------------------------------------------------------- 1 | { 2 | "description" : "Secp256r1 validatePublicKey test vectors", 3 | "vectors" : [ 4 | { 5 | "description" : "returns true for valid compressed public keys", 6 | "input" : { 7 | "publicKeyBytes": "02ca156301f628b64ef0ccff5aba2f78f29bc865fc1da35f1b4e8f3726f1f2d987" 8 | }, 9 | "output": true 10 | }, 11 | { 12 | "description" : "returns true for valid uncompressed public keys", 13 | "input" : { 14 | "publicKeyBytes": "048b542fa180e78bc981e6671374a64413e0323b439d06870dc49cb56e97775d96a0e469310d10a8ff2cb253a08d46fd845ae330e3ac4e41d0d0a85fbeb8e15795" 15 | }, 16 | "output": true 17 | }, 18 | { 19 | "description" : "returns false for invalid public keys", 20 | "input" : { 21 | "publicKeyBytes": "02fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f" 22 | }, 23 | "output": false 24 | }, 25 | { 26 | "description" : "returns false if a private key is given", 27 | "input" : { 28 | "publicKeyBytes": "08169cf81812f2e288a1131de246ebdf29b020c7625a98d098296a30a876d35a" 29 | }, 30 | "output": false 31 | } 32 | ] 33 | } -------------------------------------------------------------------------------- /packages/crypto/tests/fixtures/test-vectors/sha256/digest.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "SHA-256 digest", 3 | "vectors": [ 4 | { 5 | "description": "matches NIST FIPS 180-2 One Block Message Sample output", 6 | "input": "abc", 7 | "output": "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad" 8 | }, 9 | { 10 | "description": "matches NIST FIPS 180-2 Two Block Message Sample output", 11 | "input": "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 12 | "output": "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1" 13 | } 14 | ] 15 | } -------------------------------------------------------------------------------- /packages/crypto/tests/fixtures/test-vectors/x25519/bytes-to-private-key.json: -------------------------------------------------------------------------------- 1 | { 2 | "description" : "X25519 bytesToPrivateKey test vectors", 3 | "vectors" : [ 4 | { 5 | "description" : "converts wycheproof vector 1 to the expected private key", 6 | "input" : { 7 | "privateKeyBytes": "c8a9d5a91091ad851c668b0736c1c9a02936c0d3ad62670858088047ba057475" 8 | }, 9 | "output": { 10 | "crv" : "X25519", 11 | "d" : "yKnVqRCRrYUcZosHNsHJoCk2wNOtYmcIWAiAR7oFdHU", 12 | "kid" : "tzkgHF2KJ5d1ir5OaJi9VdNtwKrvnDUPUagtedeyyNE", 13 | "kty" : "OKP", 14 | "x" : "X2S0HM6Kaz1qOHYwiPYVpJd9QiKIrkK0mrOlfi_Nb20" 15 | } 16 | }, 17 | { 18 | "description" : "converts wycheproof vector 2 to the expected private key", 19 | "input" : { 20 | "privateKeyBytes": "d85d8c061a50804ac488ad774ac716c3f5ba714b2712e048491379a500211958" 21 | }, 22 | "output": { 23 | "crv" : "X25519", 24 | "d" : "2F2MBhpQgErEiK13SscWw_W6cUsnEuBISRN5pQAhGVg", 25 | "kid" : "0FSNmN_cVErHxsnoRtFHANkAQyklGgA7crsE-HiFPwg", 26 | "kty" : "OKP", 27 | "x" : "qQMfm22ifgIOV-IEKfLitbg0jEkoIQbCpbI2WnI_DSA" 28 | } 29 | }, 30 | { 31 | "description" : "converts wycheproof vector 3 to the expected private key", 32 | "input" : { 33 | "privateKeyBytes": "c8b45bfd32e55325d9fd648cb302848039000b390e44d521e58aab3b29a6964b" 34 | }, 35 | "output": { 36 | "crv" : "X25519", 37 | "d" : "yLRb_TLlUyXZ_WSMswKEgDkACzkORNUh5YqrOymmlks", 38 | "kid" : "OaJSSSZ5RBIGtsE8-ah1lWjcXrk5Fk4TYpuu_AgQKJs", 39 | "kty" : "OKP", 40 | "x" : "_s8qHPERyRymPqNATkQbqkB7-jpudS-30g-VRmkN00M" 41 | } 42 | } 43 | ] 44 | } -------------------------------------------------------------------------------- /packages/crypto/tests/fixtures/test-vectors/x25519/bytes-to-public-key.json: -------------------------------------------------------------------------------- 1 | { 2 | "description" : "X25519 bytesToPublicKey test vectors", 3 | "vectors" : [ 4 | { 5 | "description" : "converts wycheproof vector 1 to the expected public key", 6 | "input" : { 7 | "publicKeyBytes": "5f64b41cce8a6b3d6a38763088f615a4977d422288ae42b49ab3a57e2fcd6f6d" 8 | }, 9 | "output": { 10 | "crv" : "X25519", 11 | "kid" : "tzkgHF2KJ5d1ir5OaJi9VdNtwKrvnDUPUagtedeyyNE", 12 | "kty" : "OKP", 13 | "x" : "X2S0HM6Kaz1qOHYwiPYVpJd9QiKIrkK0mrOlfi_Nb20" 14 | } 15 | }, 16 | { 17 | "description" : "converts wycheproof vector 2 to the expected public key", 18 | "input" : { 19 | "publicKeyBytes": "a9031f9b6da27e020e57e20429f2e2b5b8348c49282106c2a5b2365a723f0d20" 20 | }, 21 | "output": { 22 | "crv" : "X25519", 23 | "kid" : "0FSNmN_cVErHxsnoRtFHANkAQyklGgA7crsE-HiFPwg", 24 | "kty" : "OKP", 25 | "x" : "qQMfm22ifgIOV-IEKfLitbg0jEkoIQbCpbI2WnI_DSA" 26 | } 27 | }, 28 | { 29 | "description" : "converts wycheproof vector 3 to the expected public key", 30 | "input" : { 31 | "publicKeyBytes": "fecf2a1cf111c91ca63ea3404e441baa407bfa3a6e752fb7d20f9546690dd343" 32 | }, 33 | "output": { 34 | "crv" : "X25519", 35 | "kid" : "OaJSSSZ5RBIGtsE8-ah1lWjcXrk5Fk4TYpuu_AgQKJs", 36 | "kty" : "OKP", 37 | "x" : "_s8qHPERyRymPqNATkQbqkB7-jpudS-30g-VRmkN00M" 38 | } 39 | } 40 | ] 41 | } -------------------------------------------------------------------------------- /packages/crypto/tests/fixtures/test-vectors/x25519/private-key-to-bytes.json: -------------------------------------------------------------------------------- 1 | { 2 | "description" : "X25519 privateKeyToBytes test vectors", 3 | "vectors" : [ 4 | { 5 | "description" : "converts wycheproof vector 1 to the expected byte array", 6 | "input" : { 7 | "privateKey": { 8 | "crv" : "X25519", 9 | "d" : "yKnVqRCRrYUcZosHNsHJoCk2wNOtYmcIWAiAR7oFdHU", 10 | "kid" : "tzkgHF2KJ5d1ir5OaJi9VdNtwKrvnDUPUagtedeyyNE", 11 | "kty" : "OKP", 12 | "x" : "X2S0HM6Kaz1qOHYwiPYVpJd9QiKIrkK0mrOlfi_Nb20" 13 | } 14 | }, 15 | "output": "c8a9d5a91091ad851c668b0736c1c9a02936c0d3ad62670858088047ba057475" 16 | }, 17 | { 18 | "description" : "converts wycheproof vector 2 to the expected byte array", 19 | "input" : { 20 | "privateKey": { 21 | "crv" : "X25519", 22 | "d" : "2F2MBhpQgErEiK13SscWw_W6cUsnEuBISRN5pQAhGVg", 23 | "kid" : "0FSNmN_cVErHxsnoRtFHANkAQyklGgA7crsE-HiFPwg", 24 | "kty" : "OKP", 25 | "x" : "qQMfm22ifgIOV-IEKfLitbg0jEkoIQbCpbI2WnI_DSA" 26 | } 27 | }, 28 | "output": "d85d8c061a50804ac488ad774ac716c3f5ba714b2712e048491379a500211958" 29 | }, 30 | { 31 | "description" : "converts wycheproof vector 3 to the expected byte array", 32 | "input" : { 33 | "privateKey": { 34 | "crv" : "X25519", 35 | "d" : "yLRb_TLlUyXZ_WSMswKEgDkACzkORNUh5YqrOymmlks", 36 | "kid" : "OaJSSSZ5RBIGtsE8-ah1lWjcXrk5Fk4TYpuu_AgQKJs", 37 | "kty" : "OKP", 38 | "x" : "_s8qHPERyRymPqNATkQbqkB7-jpudS-30g-VRmkN00M" 39 | } 40 | }, 41 | "output": "c8b45bfd32e55325d9fd648cb302848039000b390e44d521e58aab3b29a6964b" 42 | } 43 | ] 44 | } -------------------------------------------------------------------------------- /packages/crypto/tests/fixtures/test-vectors/x25519/public-key-to-bytes.json: -------------------------------------------------------------------------------- 1 | { 2 | "description" : "X25519 publicKeyToBytes test vectors", 3 | "vectors" : [ 4 | { 5 | "description" : "converts wycheproof vector 1 to the expected byte array", 6 | "input" : { 7 | "publicKey": { 8 | "crv" : "X25519", 9 | "kid" : "tzkgHF2KJ5d1ir5OaJi9VdNtwKrvnDUPUagtedeyyNE", 10 | "kty" : "OKP", 11 | "x" : "X2S0HM6Kaz1qOHYwiPYVpJd9QiKIrkK0mrOlfi_Nb20" 12 | } 13 | }, 14 | "output": "5f64b41cce8a6b3d6a38763088f615a4977d422288ae42b49ab3a57e2fcd6f6d" 15 | }, 16 | { 17 | "description" : "converts wycheproof vector 2 to the expected byte array", 18 | "input" : { 19 | "publicKey": { 20 | "crv" : "X25519", 21 | "kid" : "0FSNmN_cVErHxsnoRtFHANkAQyklGgA7crsE-HiFPwg", 22 | "kty" : "OKP", 23 | "x" : "qQMfm22ifgIOV-IEKfLitbg0jEkoIQbCpbI2WnI_DSA" 24 | } 25 | }, 26 | "output": "a9031f9b6da27e020e57e20429f2e2b5b8348c49282106c2a5b2365a723f0d20" 27 | }, 28 | { 29 | "description" : "converts wycheproof vector 3 to the expected byte array", 30 | "input" : { 31 | "publicKey": { 32 | "crv" : "X25519", 33 | "kid" : "OaJSSSZ5RBIGtsE8-ah1lWjcXrk5Fk4TYpuu_AgQKJs", 34 | "kty" : "OKP", 35 | "x" : "_s8qHPERyRymPqNATkQbqkB7-jpudS-30g-VRmkN00M" 36 | } 37 | }, 38 | "output": "fecf2a1cf111c91ca63ea3404e441baa407bfa3a6e752fb7d20f9546690dd343" 39 | } 40 | ] 41 | } -------------------------------------------------------------------------------- /packages/crypto/tests/jose/utils.spec.ts: -------------------------------------------------------------------------------- 1 | import { expect, use } from 'chai'; 2 | import chaiAsPromised from 'chai-as-promised'; 3 | 4 | import { canonicalize } from '../../src/jose/utils.js'; 5 | 6 | use(chaiAsPromised); 7 | 8 | describe('JOSE Utils', () => { 9 | describe('canonicalize', () => { 10 | it('returns the stringified version of an object with its keys sorted alphabetically', () => { 11 | const obj = { banana: 1, apple: 2, cherry: 3 }; 12 | const expectedResult = '{"apple":2,"banana":1,"cherry":3}'; 13 | expect(canonicalize(obj)).to.equal(expectedResult); 14 | }); 15 | 16 | it('handles an empty object', () => { 17 | const obj = {}; 18 | const expectedResult = '{}'; 19 | expect(canonicalize(obj)).to.equal(expectedResult); 20 | }); 21 | 22 | it('handles an object with nested properties', () => { 23 | const obj = { c: 3, a: { z: 1, b: 2 } }; 24 | const expectedResult = '{"a":{"b":2,"z":1},"c":3}'; 25 | expect(canonicalize(obj)).to.equal(expectedResult); 26 | }); 27 | 28 | it('handles an object with array values', () => { 29 | const obj = { b: [3, 2, 1], a: [1, 2, 3] }; 30 | const expectedResult = '{"a":[1,2,3],"b":[3,2,1]}'; 31 | expect(canonicalize(obj)).to.equal(expectedResult); 32 | }); 33 | 34 | it('handles an object with null values', () => { 35 | const obj = { b: null, a: 1 }; 36 | const expectedResult = '{"a":1,"b":null}'; 37 | expect(canonicalize(obj)).to.equal(expectedResult); 38 | }); 39 | 40 | it('handles an object with undefined values', () => { 41 | const obj = { b: undefined, a: 1 }; 42 | const expectedResult = '{"a":1}'; 43 | expect(canonicalize(obj)).to.equal(expectedResult); 44 | }); 45 | }); 46 | }); -------------------------------------------------------------------------------- /packages/crypto/tests/primitives/sha256.spec.ts: -------------------------------------------------------------------------------- 1 | import { expect, use } from 'chai'; 2 | import { Convert } from '@web5/common'; 3 | import chaiAsPromised from 'chai-as-promised'; 4 | 5 | import Sha256DigestTestVector from '../fixtures/test-vectors/sha256/digest.json' assert { type: 'json' }; 6 | 7 | import { Sha256 } from '../../src/primitives/sha256.js'; 8 | 9 | use(chaiAsPromised); 10 | 11 | describe('Sha256', () => { 12 | describe('digest()', () => { 13 | it('returns a Uint8Array digest of length 32', async () => { 14 | const digest = await Sha256.digest({ 15 | data: new Uint8Array(10) 16 | }); 17 | 18 | expect(digest).to.be.an('Uint8Array'); 19 | expect(digest.byteLength).to.equal(32); 20 | }); 21 | 22 | for (const vector of Sha256DigestTestVector.vectors) { 23 | it(vector.description, async () => { 24 | const digest = await Sha256.digest({ 25 | data: Convert.string(vector.input).toUint8Array() 26 | }); 27 | 28 | expect(digest).to.deep.equal( 29 | Convert.hex(vector.output).toUint8Array() 30 | ); 31 | }); 32 | } 33 | }); 34 | }); -------------------------------------------------------------------------------- /packages/crypto/tests/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "compiled", 5 | "declarationDir": "compiled/types", 6 | "sourceMap": true 7 | }, 8 | "include": [ 9 | "../src", 10 | ".", 11 | ], 12 | "exclude": [ 13 | "./compiled" 14 | ] 15 | } -------------------------------------------------------------------------------- /packages/crypto/tests/utils/runtimes.ts: -------------------------------------------------------------------------------- 1 | export const isChrome = typeof navigator !== 'undefined' && /Chrome/.test(navigator.userAgent); -------------------------------------------------------------------------------- /packages/crypto/tsconfig.cjs.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "lib": [ 5 | "DOM", 6 | "ES5" 7 | ], 8 | "target": "ES5", 9 | "module": "CommonJS", 10 | "moduleResolution": "Node", 11 | "outDir": "dist/cjs", 12 | "declaration": false, 13 | "declarationMap": false, 14 | "declarationDir": null, 15 | "downlevelIteration": true 16 | }, 17 | "include": [ 18 | "src" 19 | ] 20 | } -------------------------------------------------------------------------------- /packages/crypto/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "declarationDir": "dist/types", 5 | "outDir": "dist/esm" 6 | }, 7 | "include": [ 8 | "src" 9 | ], 10 | "exclude": [ 11 | "node_modules" 12 | ] 13 | } -------------------------------------------------------------------------------- /packages/crypto/web-test-runner.config.cjs: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-var-requires */ 2 | const playwrightLauncher = 3 | require('@web/test-runner-playwright').playwrightLauncher; 4 | 5 | /** 6 | * @type {import('@web/test-runner').TestRunnerConfig} 7 | */ 8 | module.exports = { 9 | files : 'tests/compiled/**/*.spec.js', 10 | playwright : true, 11 | nodeResolve : true, 12 | browsers : [ 13 | playwrightLauncher({ 14 | product: 'chromium', 15 | }), 16 | playwrightLauncher({ 17 | product: 'firefox', 18 | }), 19 | playwrightLauncher({ 20 | product: 'webkit', 21 | }), 22 | ], 23 | testsFinishTimeout : 300000, 24 | concurrentBrowsers : 2, 25 | testFramework : { 26 | config: { 27 | timeout: '15000', 28 | }, 29 | }, 30 | }; 31 | -------------------------------------------------------------------------------- /packages/dev-env/README.md: -------------------------------------------------------------------------------- 1 | # Web5 Developer Environment 2 | -------------------------------------------------------------------------------- /packages/dev-env/docker-compose.yaml: -------------------------------------------------------------------------------- 1 | version: "3.98" 2 | 3 | services: 4 | dwn-server: 5 | container_name: dwn-server 6 | image: ghcr.io/tbd54566975/dwn-server:0.6.0 7 | ports: 8 | - "3000:3000" 9 | -------------------------------------------------------------------------------- /packages/dids/.c8rc.json: -------------------------------------------------------------------------------- 1 | { 2 | "all": true, 3 | "cache": false, 4 | "extension": [ 5 | ".js" 6 | ], 7 | "include": [ 8 | "tests/compiled/**/src/**" 9 | ], 10 | "exclude": [ 11 | "tests/compiled/**/src/index.js", 12 | "tests/compiled/**/src/types.js", 13 | "tests/compiled/**/src/types/**" 14 | ], 15 | "reporter": [ 16 | "cobertura", 17 | "html", 18 | "text" 19 | ] 20 | } -------------------------------------------------------------------------------- /packages/dids/.mocharc.json: -------------------------------------------------------------------------------- 1 | { 2 | "enable-source-maps": true, 3 | "exit": true, 4 | "spec": ["tests/compiled/**/*.spec.js"] 5 | } 6 | -------------------------------------------------------------------------------- /packages/dids/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "node", 9 | "request": "launch", 10 | "name": "test:node", 11 | "runtimeExecutable": "${workspaceFolder:dids}/../../node_modules/.bin/mocha", 12 | "console": "internalConsole", 13 | "preLaunchTask": "build tests", 14 | "skipFiles": [ 15 | "/**" 16 | ] 17 | } 18 | ] 19 | } -------------------------------------------------------------------------------- /packages/dids/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "pnpm build", 6 | "type": "npm", 7 | "script": "build", 8 | "problemMatcher": [], 9 | "group": { 10 | "kind": "build", 11 | "isDefault": true 12 | } 13 | }, 14 | { 15 | "label": "tsc: build - tsconfig.json", 16 | "type": "typescript", 17 | "tsconfig": "tsconfig.json", 18 | "problemMatcher": [ 19 | "$tsc" 20 | ], 21 | "group": { 22 | "kind": "build", 23 | "isDefault": false 24 | }, 25 | "options": { 26 | "cwd": "${workspaceFolder:root}" 27 | } 28 | }, 29 | { 30 | "label": "build tests", 31 | "type": "npm", 32 | "script": "build:tests:node", 33 | "options": { 34 | "cwd": "${workspaceFolder:dids}" 35 | } 36 | } 37 | ] 38 | } -------------------------------------------------------------------------------- /packages/dids/README.md: -------------------------------------------------------------------------------- 1 | # Web5 DID 2 | -------------------------------------------------------------------------------- /packages/dids/build/buffer-polyfill.cjs: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-var-requires */ 2 | const polyfilledBuffer = require('buffer/').Buffer; 3 | const { Buffer } = require('buffer'); 4 | 5 | // monkeypatch writeBigUInt64BE in polyfill bc its borked 6 | // can remove this if/when this PR is merged: https://github.com/feross/buffer/pull/280 7 | polyfilledBuffer.prototype.writeBigUInt64BE = Buffer.prototype.writeBigUInt64BE; 8 | globalThis.Buffer = polyfilledBuffer; 9 | -------------------------------------------------------------------------------- /packages/dids/build/bundles.js: -------------------------------------------------------------------------------- 1 | import esbuild from 'esbuild'; 2 | import browserConfig from './esbuild-browser-config.cjs'; 3 | 4 | // esm polyfilled bundle for browser 5 | esbuild.build({ 6 | ...browserConfig, 7 | outfile: 'dist/browser.mjs', 8 | }); 9 | 10 | // iife polyfilled bundle for browser 11 | esbuild.build({ 12 | ...browserConfig, 13 | format : 'iife', 14 | globalName : 'Web5Dids', 15 | outfile : 'dist/browser.js', 16 | }); 17 | 18 | esbuild.build({ 19 | ...browserConfig, 20 | entryPoints : ['./src/utils.ts'], 21 | outfile : 'dist/utils.js' 22 | }); -------------------------------------------------------------------------------- /packages/dids/build/cjs-bundle.js: -------------------------------------------------------------------------------- 1 | import esbuild from 'esbuild'; 2 | import packageJson from '../package.json' assert { type: 'json' }; 3 | 4 | // list of dependencies that _dont_ ship cjs 5 | const includeList = new Set([ 6 | '@decentralized-identity/ion-sdk', 7 | 'bencode' 8 | ]); 9 | 10 | // create list of dependencies that we _do not_ want to include in our bundle 11 | const excludeList = []; 12 | for (const dependency in packageJson.dependencies) { 13 | if (includeList.has(dependency)) { 14 | continue; 15 | } else { 16 | excludeList.push(dependency); 17 | } 18 | } 19 | 20 | /** @type {import('esbuild').BuildOptions} */ 21 | const baseConfig = { 22 | allowOverwrite : true, 23 | bundle : true, 24 | external : excludeList, 25 | format : 'cjs', 26 | platform : 'node', 27 | sourcemap : true, 28 | }; 29 | 30 | const indexConfig = { 31 | ...baseConfig, 32 | entryPoints : ['./dist/esm/index.js'], 33 | outfile : './dist/cjs/index.js', 34 | }; 35 | esbuild.buildSync(indexConfig); 36 | 37 | const utilsConfig = { 38 | ...baseConfig, 39 | entryPoints : ['./dist/esm/utils.js'], 40 | outfile : './dist/cjs/utils.js', 41 | }; 42 | esbuild.buildSync(utilsConfig); -------------------------------------------------------------------------------- /packages/dids/build/esbuild-browser-config.cjs: -------------------------------------------------------------------------------- 1 | /** @type {import('esbuild').BuildOptions} */ 2 | module.exports = { 3 | entryPoints : ['./src/index.ts'], 4 | bundle : true, 5 | format : 'esm', 6 | sourcemap : true, 7 | minify : true, 8 | platform : 'browser', 9 | target : ['chrome101', 'firefox108', 'safari16'], 10 | inject : ['./build/buffer-polyfill.cjs'], 11 | define : { 12 | 'global': 'globalThis', 13 | }, 14 | }; 15 | -------------------------------------------------------------------------------- /packages/dids/build/esbuild-tests.cjs: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-var-requires */ 2 | const esbuild = require('esbuild'); 3 | const browserConfig = require('./esbuild-browser-config.cjs'); 4 | 5 | esbuild.build({ 6 | ...browserConfig, 7 | format : 'esm', 8 | entryPoints : ['./tests/**/*.spec.*'], 9 | bundle : true, 10 | minify : false, 11 | outdir : 'tests/compiled', 12 | define : { 13 | ...browserConfig.define, 14 | 'process.env.TEST_DWN_URL': JSON.stringify(process.env.TEST_DWN_URL ?? null), 15 | }, 16 | }); 17 | -------------------------------------------------------------------------------- /packages/dids/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './types/did-core.js'; 2 | export * from './types/did-resolution.js'; 3 | export type * from './types/multibase.js'; 4 | export type * from './types/portable-did.js'; 5 | 6 | export * from './did.js'; 7 | export * from './did-error.js'; 8 | export * from './bearer-did.js'; 9 | 10 | export * from './methods/did-dht.js'; 11 | export * from './methods/did-ion.js'; 12 | export * from './methods/did-jwk.js'; 13 | export * from './methods/did-key.js'; 14 | export * from './methods/did-method.js'; 15 | export * from './methods/did-web.js'; 16 | 17 | export * from './resolver/resolver-cache-level.js'; 18 | export * from './resolver/resolver-cache-noop.js'; 19 | export * from './resolver/universal-resolver.js'; 20 | 21 | export * as utils from './utils.js'; -------------------------------------------------------------------------------- /packages/dids/src/resolver/resolver-cache-noop.ts: -------------------------------------------------------------------------------- 1 | import type { DidResolutionResult } from '../types/did-core.js'; 2 | import type { DidResolverCache } from '../types/did-resolution.js'; 3 | 4 | /** 5 | * No-op cache that is used as the default cache for did-resolver. 6 | * 7 | * The motivation behind using a no-op cache as the default stems from the desire to maximize the 8 | * potential for this library to be used in as many JS runtimes as possible. 9 | */ 10 | export const DidResolverCacheNoop: DidResolverCache = { 11 | get: function (_key: string): Promise { 12 | return null as any; 13 | }, 14 | set: function (_key: string, _value: DidResolutionResult): Promise { 15 | return null as any; 16 | }, 17 | delete: function (_key: string): Promise { 18 | return null as any; 19 | }, 20 | clear: function (): Promise { 21 | return null as any; 22 | }, 23 | close: function (): Promise { 24 | return null as any; 25 | } 26 | }; -------------------------------------------------------------------------------- /packages/dids/src/types/multibase.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Represents a cryptographic key with associated multicodec metadata. 3 | * 4 | * The `KeyWithMulticodec` type encapsulates a cryptographic key along with optional multicodec 5 | * information. It is primarily used in functions that convert between cryptographic keys and their 6 | * string representations, ensuring that the key's format and encoding are preserved and understood 7 | * across different systems and applications. 8 | */ 9 | export type KeyWithMulticodec = { 10 | /** 11 | * A `Uint8Array` representing the raw bytes of the cryptographic key. This is the primary data of 12 | * the type and is essential for cryptographic operations. 13 | */ 14 | keyBytes: Uint8Array, 15 | 16 | /** 17 | * An optional number representing the multicodec code. This code uniquely identifies the encoding 18 | * format or protocol associated with the key. The presence of this code is crucial for decoding 19 | * the key correctly in different contexts. 20 | */ 21 | multicodecCode?: number, 22 | 23 | /** 24 | * An optional string representing the human-readable name of the multicodec. This name provides 25 | * an easier way to identify the encoding format or protocol of the key, especially when the 26 | * numerical code is not immediately recognizable. 27 | */ 28 | multicodecName?: string 29 | }; -------------------------------------------------------------------------------- /packages/dids/tests/fixtures/test-vectors/did-dht/vector-1.json: -------------------------------------------------------------------------------- 1 | { 2 | "didDocument": { 3 | "id": "did:dht:cyuoqaf7itop8ohww4yn5ojg13qaq83r9zihgqntc5i9zwrfdfoo", 4 | "verificationMethod": [ 5 | { 6 | "id": "did:dht:cyuoqaf7itop8ohww4yn5ojg13qaq83r9zihgqntc5i9zwrfdfoo#0", 7 | "type": "JsonWebKey", 8 | "controller": "did:dht:cyuoqaf7itop8ohww4yn5ojg13qaq83r9zihgqntc5i9zwrfdfoo", 9 | "publicKeyJwk": { 10 | "kid": "HP6bkG6mv-YPsU3Vi5Coi5wGYSVW9abFBwBSQwLQ7PU", 11 | "alg": "EdDSA", 12 | "crv": "Ed25519", 13 | "kty": "OKP", 14 | "x": "YCcHYL2sYNPDlKaALcEmll2HHyT968M4UWbr-9CFGWE" 15 | } 16 | } 17 | ], 18 | "authentication": [ 19 | "did:dht:cyuoqaf7itop8ohww4yn5ojg13qaq83r9zihgqntc5i9zwrfdfoo#0" 20 | ], 21 | "assertionMethod": [ 22 | "did:dht:cyuoqaf7itop8ohww4yn5ojg13qaq83r9zihgqntc5i9zwrfdfoo#0" 23 | ], 24 | "capabilityInvocation": [ 25 | "did:dht:cyuoqaf7itop8ohww4yn5ojg13qaq83r9zihgqntc5i9zwrfdfoo#0" 26 | ], 27 | "capabilityDelegation": [ 28 | "did:dht:cyuoqaf7itop8ohww4yn5ojg13qaq83r9zihgqntc5i9zwrfdfoo#0" 29 | ] 30 | }, 31 | "dnsRecords": [ 32 | { 33 | "name": "_did.cyuoqaf7itop8ohww4yn5ojg13qaq83r9zihgqntc5i9zwrfdfoo.", 34 | "type": "TXT", 35 | "ttl": 7200, 36 | "rdata": "v=0;vm=k0;auth=k0;asm=k0;inv=k0;del=k0" 37 | }, 38 | { 39 | "name": "_k0._did.", 40 | "type": "TXT", 41 | "ttl": 7200, 42 | "rdata": "t=0;k=YCcHYL2sYNPDlKaALcEmll2HHyT968M4UWbr-9CFGWE" 43 | } 44 | ] 45 | } -------------------------------------------------------------------------------- /packages/dids/tests/fixtures/test-vectors/did-ion/resolve.ts: -------------------------------------------------------------------------------- 1 | import type { Jwk } from '@web5/crypto'; 2 | 3 | import type { DidResolutionResult } from '../../../../src/types/did-core.js'; 4 | 5 | type TestVector = { 6 | [key: string]: { 7 | didUri: string; 8 | privateKey: Jwk[]; 9 | didResolutionResult: DidResolutionResult; 10 | }; 11 | }; 12 | 13 | export const vectors: TestVector = { 14 | publishedDid: { 15 | didUri : 'did:ion:EiCab9QRUcUTKKIM-W2SMCwnOPxa4y0q7emoWJDSOSz3HQ', 16 | privateKey : [], 17 | didResolutionResult : { 18 | '@context' : 'https://w3id.org/did-resolution/v1', 19 | didDocument : { 20 | id : 'did:ion:EiCab9QRUcUTKKIM-W2SMCwnOPxa4y0q7emoWJDSOSz3HQ', 21 | '@context' : [ 22 | 'https://www.w3.org/ns/did/v1', 23 | { 24 | '@base': 'did:ion:EiCab9QRUcUTKKIM-W2SMCwnOPxa4y0q7emoWJDSOSz3HQ', 25 | }, 26 | ], 27 | service: [ 28 | ], 29 | verificationMethod: [ 30 | { 31 | id : '#dwn-sig', 32 | controller : 'did:ion:EiCab9QRUcUTKKIM-W2SMCwnOPxa4y0q7emoWJDSOSz3HQ', 33 | type : 'JsonWebKey2020', 34 | publicKeyJwk : { 35 | crv : 'Ed25519', 36 | kty : 'OKP', 37 | x : 'Sy0lk6pMXC10WyIh4g8sLz1loL8ImzLcqmFW2267IXc', 38 | }, 39 | }, 40 | ], 41 | authentication: [ 42 | '#dwn-sig', 43 | ], 44 | }, 45 | didDocumentMetadata: { 46 | method: { 47 | published : true, 48 | recoveryCommitment : 'EiDzYFBF-EPcbt4sVdepmniqfg93wrh1dZTZY1ZI4m6enw', 49 | updateCommitment : 'EiAp4ocUKXcYC3D-DaGiW2D01D3QVxqGegT1Fq42bDaPoQ', 50 | }, 51 | canonicalId: 'did:ion:EiCab9QRUcUTKKIM-W2SMCwnOPxa4y0q7emoWJDSOSz3HQ', 52 | }, 53 | didResolutionMetadata: {} 54 | } 55 | }, 56 | }; -------------------------------------------------------------------------------- /packages/dids/tests/methods/did-method.spec.ts: -------------------------------------------------------------------------------- 1 | import { expect } from 'chai'; 2 | 3 | import { DidMethod } from '../../src/methods/did-method.js'; 4 | 5 | describe('DidMethod', () => { 6 | describe('getSigningMethod()', () => { 7 | it('throws an error if the DID method implementation does not provide a getSigningMethod() function', async () => { 8 | class DidTest extends DidMethod {} 9 | 10 | try { 11 | await DidTest.getSigningMethod({ didDocument: { id: 'did:method:example' } }); 12 | expect.fail('Error should have been thrown'); 13 | } catch (error: any) { 14 | expect(error.message).to.include('must implement getSigningMethod()'); 15 | } 16 | }); 17 | }); 18 | 19 | describe('resolve()', () => { 20 | it('throws an error if the DID method implementation does not provide a resolve() function', async () => { 21 | class DidTest extends DidMethod {} 22 | 23 | try { 24 | await DidTest.resolve('did:method:example'); 25 | expect.fail('Error should have been thrown'); 26 | } catch (error: any) { 27 | expect(error.message).to.include('must implement resolve()'); 28 | } 29 | }); 30 | }); 31 | }); -------------------------------------------------------------------------------- /packages/dids/tests/resolver/resolver-cache-noop.spec.ts: -------------------------------------------------------------------------------- 1 | import { expect } from 'chai'; 2 | import { DidResolverCacheNoop } from '../../src/resolver/resolver-cache-noop.js'; 3 | 4 | describe('DidResolverCacheNoop', function() { 5 | it('returns null for get method', async function() { 6 | const result = await DidResolverCacheNoop.get('someKey'); 7 | expect(result).to.be.null; 8 | }); 9 | 10 | it('returns null for set method', async function() { 11 | const result = await DidResolverCacheNoop.set('someKey', { 12 | didResolutionMetadata : {}, 13 | didDocument : null, 14 | didDocumentMetadata : {}, 15 | }); 16 | expect(result).to.be.null; 17 | }); 18 | 19 | it('returns null for delete method', async function() { 20 | const result = await DidResolverCacheNoop.delete('someKey'); 21 | expect(result).to.be.null; 22 | }); 23 | 24 | it('returns null for clear method', async function() { 25 | const result = await DidResolverCacheNoop.clear(); 26 | expect(result).to.be.null; 27 | }); 28 | 29 | it('returns null for close method', async function() { 30 | const result = await DidResolverCacheNoop.close(); 31 | expect(result).to.be.null; 32 | }); 33 | }); 34 | -------------------------------------------------------------------------------- /packages/dids/tests/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "compiled", 5 | "declarationDir": "compiled/types", 6 | "sourceMap": true, 7 | }, 8 | "include": [ 9 | "../src", 10 | ".", 11 | ], 12 | "exclude": [ 13 | "./compiled" 14 | ] 15 | } -------------------------------------------------------------------------------- /packages/dids/tsconfig.cjs.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "lib": [ 5 | "DOM", 6 | "ES5" 7 | ], 8 | "target": "ES5", 9 | "module": "CommonJS", 10 | "outDir": "dist/cjs", 11 | "declaration": false, 12 | "declarationMap": false, 13 | "declarationDir": null, 14 | "downlevelIteration": true 15 | }, 16 | "include": [ 17 | "src" 18 | ] 19 | } -------------------------------------------------------------------------------- /packages/dids/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "declarationDir": "dist/types", 5 | "outDir": "dist/esm" 6 | }, 7 | "include": [ 8 | "src" 9 | ], 10 | "exclude": [ 11 | "node_modules" 12 | ] 13 | } -------------------------------------------------------------------------------- /packages/dids/web-test-runner.config.cjs: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-var-requires */ 2 | const playwrightLauncher = 3 | require('@web/test-runner-playwright').playwrightLauncher; 4 | 5 | /** 6 | * @type {import('@web/test-runner').TestRunnerConfig} 7 | */ 8 | module.exports = { 9 | files : 'tests/compiled/**/*.spec.js', 10 | playwright : true, 11 | nodeResolve : true, 12 | browsers : [ 13 | playwrightLauncher({ 14 | product: 'chromium', 15 | }), 16 | playwrightLauncher({ 17 | product: 'firefox', 18 | }), 19 | playwrightLauncher({ 20 | product: 'webkit', 21 | }), 22 | ], 23 | testsFinishTimeout : 300000, 24 | concurrentBrowsers : 2, 25 | testFramework : { 26 | config: { 27 | timeout: '15000', 28 | }, 29 | }, 30 | }; 31 | -------------------------------------------------------------------------------- /packages/identity-agent/.c8rc.json: -------------------------------------------------------------------------------- 1 | { 2 | "all": true, 3 | "cache": false, 4 | "extension": [ 5 | ".js" 6 | ], 7 | "include": [ 8 | "tests/compiled/**/src/**" 9 | ], 10 | "exclude": [ 11 | "tests/compiled/**/src/index.js", 12 | "tests/compiled/**/src/types.js", 13 | "tests/compiled/**/src/types/**" 14 | ], 15 | "reporter": [ 16 | "cobertura", 17 | "text" 18 | ] 19 | } -------------------------------------------------------------------------------- /packages/identity-agent/.mocharc.json: -------------------------------------------------------------------------------- 1 | { 2 | "enable-source-maps": true, 3 | "exit": true, 4 | "spec": ["tests/compiled/**/*.spec.js"] 5 | } -------------------------------------------------------------------------------- /packages/identity-agent/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "node", 9 | "request": "launch", 10 | "name": "test:node", 11 | "runtimeExecutable": "${workspaceFolder:identity-agent}/node_modules/.bin/mocha", 12 | "console": "internalConsole", 13 | "preLaunchTask": "build tests", 14 | "skipFiles": [ 15 | "/**" 16 | ], 17 | "env": { 18 | "TEST_DWN_URL": "http://localhost:3000" 19 | } 20 | } 21 | ] 22 | } -------------------------------------------------------------------------------- /packages/identity-agent/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "pnpm build", 6 | "type": "npm", 7 | "script": "build", 8 | "group": { 9 | "kind": "build", 10 | "isDefault": true 11 | } 12 | }, 13 | { 14 | "label": "tsc: build - tsconfig.json", 15 | "type": "typescript", 16 | "tsconfig": "tsconfig.json", 17 | "problemMatcher": [ 18 | "$tsc" 19 | ], 20 | "group": { 21 | "kind": "build", 22 | "isDefault": false 23 | }, 24 | "options": { 25 | "cwd": "${workspaceFolder:root}" 26 | } 27 | }, 28 | { 29 | "label": "build tests", 30 | "type": "npm", 31 | "script": "build:tests:node", 32 | "options": { 33 | "cwd": "${workspaceFolder:identity-agent}" 34 | } 35 | } 36 | ] 37 | } -------------------------------------------------------------------------------- /packages/identity-agent/build/bundles.js: -------------------------------------------------------------------------------- 1 | import esbuild from 'esbuild'; 2 | import browserConfig from './esbuild-browser-config.cjs'; 3 | 4 | // esm polyfilled bundle for browser 5 | esbuild.build({ 6 | ...browserConfig, 7 | outfile: 'dist/browser.mjs', 8 | }); 9 | 10 | // iife polyfilled bundle for browser 11 | esbuild.build({ 12 | ...browserConfig, 13 | format : 'iife', 14 | globalName : 'Web5IdentityAgent', 15 | outfile : 'dist/browser.js', 16 | }); -------------------------------------------------------------------------------- /packages/identity-agent/build/esbuild-browser-config.cjs: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-var-requires */ 2 | const polyfillProviderPlugin = require('node-stdlib-browser/helpers/esbuild/plugin'); 3 | const stdLibBrowser = require('node-stdlib-browser'); 4 | 5 | const requiredPolyfills = new Set(['crypto', 'node:crypto', 'stream']); 6 | 7 | // populate object containing lib -> polyfill path 8 | const polyfills = {}; 9 | for (let lib in stdLibBrowser) { 10 | if (requiredPolyfills.has(lib)) { 11 | const polyfill = stdLibBrowser[lib]; 12 | polyfills[lib] = polyfill; 13 | } 14 | } 15 | 16 | /** @type {import('esbuild').BuildOptions} */ 17 | module.exports = { 18 | entryPoints : ['./src/index.ts'], 19 | bundle : true, 20 | format : 'esm', 21 | sourcemap : true, 22 | minify : true, 23 | platform : 'browser', 24 | target : ['chrome101', 'firefox108', 'safari16'], 25 | inject : [require.resolve('node-stdlib-browser/helpers/esbuild/shim')], 26 | plugins : [polyfillProviderPlugin(polyfills)], 27 | define : { 28 | 'global': 'globalThis', 29 | }, 30 | }; -------------------------------------------------------------------------------- /packages/identity-agent/build/esbuild-tests.cjs: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-var-requires */ 2 | const esbuild = require('esbuild'); 3 | const browserConfig = require('./esbuild-browser-config.cjs'); 4 | 5 | esbuild.build({ 6 | ...browserConfig, 7 | format : 'esm', 8 | entryPoints : ['./tests/**/*.spec.*'], 9 | bundle : true, 10 | minify : false, 11 | outdir : 'tests/compiled', 12 | define : { 13 | ...browserConfig.define, 14 | 'process.env.TEST_DWN_URL': JSON.stringify(process.env.TEST_DWN_URL ?? null), 15 | }, 16 | }); 17 | -------------------------------------------------------------------------------- /packages/identity-agent/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './identity-agent.js'; -------------------------------------------------------------------------------- /packages/identity-agent/tests/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "compiled", 5 | "declarationDir": "compiled/types", 6 | "sourceMap": true, 7 | }, 8 | "include": [ 9 | "../src", 10 | ".", 11 | ], 12 | "exclude": [ 13 | "./compiled" 14 | ] 15 | } -------------------------------------------------------------------------------- /packages/identity-agent/tests/utils/test-config.ts: -------------------------------------------------------------------------------- 1 | const DEFAULT_TEST_DWN_URL = 'http://localhost:3000'; 2 | 3 | const getTestDwnUrl = () => process.env.TEST_DWN_URL || DEFAULT_TEST_DWN_URL; 4 | 5 | export const testDwnUrl = getTestDwnUrl(); -------------------------------------------------------------------------------- /packages/identity-agent/tsconfig.cjs.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "lib": [ 5 | "DOM", 6 | "ES5" 7 | ], 8 | "target": "ES5", 9 | "module": "CommonJS", 10 | "outDir": "dist/cjs", 11 | "declaration": false, 12 | "declarationMap": false, 13 | "declarationDir": null 14 | }, 15 | "include": [ 16 | "src" 17 | ] 18 | } -------------------------------------------------------------------------------- /packages/identity-agent/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "declarationDir": "dist/types", 5 | "outDir": "dist/esm" 6 | }, 7 | "include": [ 8 | "src", 9 | ], 10 | "exclude": [ 11 | "node_modules" 12 | ] 13 | } -------------------------------------------------------------------------------- /packages/identity-agent/web-test-runner.config.cjs: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-var-requires */ 2 | const playwrightLauncher = 3 | require('@web/test-runner-playwright').playwrightLauncher; 4 | 5 | /** 6 | * @type {import('@web/test-runner').TestRunnerConfig} 7 | */ 8 | module.exports = { 9 | files : 'tests/compiled/**/*.spec.js', 10 | playwright : true, 11 | nodeResolve : true, 12 | browsers : [ 13 | playwrightLauncher({ 14 | product: 'chromium', 15 | }), 16 | playwrightLauncher({ 17 | product: 'firefox', 18 | }), 19 | playwrightLauncher({ 20 | product: 'webkit', 21 | }), 22 | ], 23 | testsFinishTimeout : 300000, 24 | concurrentBrowsers : 2, 25 | testFramework : { 26 | config: { 27 | timeout: '15000', 28 | }, 29 | }, 30 | }; 31 | -------------------------------------------------------------------------------- /packages/proxy-agent/.c8rc.json: -------------------------------------------------------------------------------- 1 | { 2 | "all": true, 3 | "cache": false, 4 | "extension": [ 5 | ".js" 6 | ], 7 | "include": [ 8 | "tests/compiled/**/src/**" 9 | ], 10 | "exclude": [ 11 | "tests/compiled/**/src/index.js", 12 | "tests/compiled/**/src/types.js", 13 | "tests/compiled/**/src/types/**" 14 | ], 15 | "reporter": [ 16 | "cobertura", 17 | "text" 18 | ] 19 | } -------------------------------------------------------------------------------- /packages/proxy-agent/.mocharc.json: -------------------------------------------------------------------------------- 1 | { 2 | "enable-source-maps": true, 3 | "exit": true, 4 | "spec": ["tests/compiled/**/*.spec.js"] 5 | } -------------------------------------------------------------------------------- /packages/proxy-agent/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "node", 9 | "request": "launch", 10 | "name": "test:node", 11 | "runtimeExecutable": "${workspaceFolder:proxy-agent}/node_modules/.bin/mocha", 12 | "console": "internalConsole", 13 | "preLaunchTask": "build tests", 14 | "skipFiles": [ 15 | "/**" 16 | ], 17 | "env": { 18 | "TEST_DWN_URL": "http://localhost:3000" 19 | } 20 | } 21 | ] 22 | } -------------------------------------------------------------------------------- /packages/proxy-agent/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "pnpm build", 6 | "type": "npm", 7 | "script": "build", 8 | "problemMatcher": [], 9 | "group": { 10 | "kind": "build", 11 | "isDefault": true 12 | } 13 | }, 14 | { 15 | "label": "tsc: build - tsconfig.json", 16 | "type": "typescript", 17 | "tsconfig": "tsconfig.json", 18 | "problemMatcher": [ 19 | "$tsc" 20 | ], 21 | "group": { 22 | "kind": "build", 23 | "isDefault": false 24 | }, 25 | "options": { 26 | "cwd": "${workspaceFolder:root}" 27 | } 28 | }, 29 | { 30 | "label": "build tests", 31 | "type": "npm", 32 | "script": "build:tests:node", 33 | "options": { 34 | "cwd": "${workspaceFolder:proxy-agent}" 35 | } 36 | } 37 | ] 38 | } -------------------------------------------------------------------------------- /packages/proxy-agent/README.md: -------------------------------------------------------------------------------- 1 | # Web5 Proxy Agent -------------------------------------------------------------------------------- /packages/proxy-agent/build/bundles.js: -------------------------------------------------------------------------------- 1 | import esbuild from 'esbuild'; 2 | import browserConfig from './esbuild-browser-config.cjs'; 3 | 4 | // esm polyfilled bundle for browser 5 | esbuild.build({ 6 | ...browserConfig, 7 | outfile: 'dist/browser.mjs', 8 | }); 9 | 10 | // iife polyfilled bundle for browser 11 | esbuild.build({ 12 | ...browserConfig, 13 | format : 'iife', 14 | globalName : 'Web5ProxyAgent', 15 | outfile : 'dist/browser.js', 16 | }); -------------------------------------------------------------------------------- /packages/proxy-agent/build/esbuild-browser-config.cjs: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-var-requires */ 2 | const polyfillProviderPlugin = require('node-stdlib-browser/helpers/esbuild/plugin'); 3 | const stdLibBrowser = require('node-stdlib-browser'); 4 | 5 | const requiredPolyfills = new Set(['crypto', 'node:crypto', 'stream']); 6 | 7 | // populate object containing lib -> polyfill path 8 | const polyfills = {}; 9 | for (let lib in stdLibBrowser) { 10 | if (requiredPolyfills.has(lib)) { 11 | const polyfill = stdLibBrowser[lib]; 12 | polyfills[lib] = polyfill; 13 | } 14 | } 15 | 16 | /** @type {import('esbuild').BuildOptions} */ 17 | module.exports = { 18 | entryPoints : ['./src/index.ts'], 19 | bundle : true, 20 | format : 'esm', 21 | sourcemap : true, 22 | minify : true, 23 | platform : 'browser', 24 | target : ['chrome101', 'firefox108', 'safari16'], 25 | inject : [require.resolve('node-stdlib-browser/helpers/esbuild/shim')], 26 | plugins : [polyfillProviderPlugin(polyfills)], 27 | define : { 28 | 'global': 'globalThis', 29 | }, 30 | }; -------------------------------------------------------------------------------- /packages/proxy-agent/build/esbuild-tests.cjs: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-var-requires */ 2 | const esbuild = require('esbuild'); 3 | const browserConfig = require('./esbuild-browser-config.cjs'); 4 | 5 | esbuild.build({ 6 | ...browserConfig, 7 | format : 'esm', 8 | entryPoints : ['./tests/**/*.spec.*'], 9 | bundle : true, 10 | minify : false, 11 | outdir : 'tests/compiled', 12 | define : { 13 | ...browserConfig.define, 14 | 'process.env.TEST_DWN_URL': JSON.stringify(process.env.TEST_DWN_URL ?? null), 15 | }, 16 | }); 17 | -------------------------------------------------------------------------------- /packages/proxy-agent/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './proxy-agent.js'; -------------------------------------------------------------------------------- /packages/proxy-agent/tests/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "compiled", 5 | "declarationDir": "compiled/types", 6 | "sourceMap": true, 7 | }, 8 | "include": [ 9 | "../src", 10 | ".", 11 | ], 12 | "exclude": [ 13 | "./compiled" 14 | ] 15 | } -------------------------------------------------------------------------------- /packages/proxy-agent/tests/utils/test-config.ts: -------------------------------------------------------------------------------- 1 | const DEFAULT_TEST_DWN_URL = 'http://localhost:3000'; 2 | 3 | const getTestDwnUrl = () => process.env.TEST_DWN_URL || DEFAULT_TEST_DWN_URL; 4 | 5 | export const testDwnUrl = getTestDwnUrl(); -------------------------------------------------------------------------------- /packages/proxy-agent/tsconfig.cjs.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "lib": [ 5 | "DOM", 6 | "ES5" 7 | ], 8 | "target": "ES5", 9 | "module": "CommonJS", 10 | "outDir": "dist/cjs", 11 | "declaration": false, 12 | "declarationMap": false, 13 | "declarationDir": null 14 | }, 15 | "include": [ 16 | "src" 17 | ] 18 | } -------------------------------------------------------------------------------- /packages/proxy-agent/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "declarationDir": "dist/types", 5 | "outDir": "dist/esm" 6 | }, 7 | "include": [ 8 | "src", 9 | ], 10 | "exclude": [ 11 | "node_modules" 12 | ] 13 | } -------------------------------------------------------------------------------- /packages/proxy-agent/web-test-runner.config.cjs: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-var-requires */ 2 | const playwrightLauncher = 3 | require('@web/test-runner-playwright').playwrightLauncher; 4 | 5 | /** 6 | * @type {import('@web/test-runner').TestRunnerConfig} 7 | */ 8 | module.exports = { 9 | files : 'tests/compiled/**/*.spec.js', 10 | playwright : true, 11 | nodeResolve : true, 12 | browsers : [ 13 | playwrightLauncher({ 14 | product: 'chromium', 15 | }), 16 | playwrightLauncher({ 17 | product: 'firefox', 18 | }), 19 | playwrightLauncher({ 20 | product: 'webkit', 21 | }), 22 | ], 23 | testsFinishTimeout : 300000, 24 | concurrentBrowsers : 2, 25 | testFramework : { 26 | config: { 27 | timeout: '15000', 28 | }, 29 | }, 30 | }; 31 | -------------------------------------------------------------------------------- /packages/user-agent/.c8rc.json: -------------------------------------------------------------------------------- 1 | { 2 | "all": true, 3 | "cache": false, 4 | "extension": [ 5 | ".js" 6 | ], 7 | "include": [ 8 | "tests/compiled/**/src/**" 9 | ], 10 | "exclude": [ 11 | "tests/compiled/**/src/index.js", 12 | "tests/compiled/**/src/types.js", 13 | "tests/compiled/**/src/types/**" 14 | ], 15 | "reporter": [ 16 | "cobertura", 17 | "text" 18 | ] 19 | } -------------------------------------------------------------------------------- /packages/user-agent/.mocharc.json: -------------------------------------------------------------------------------- 1 | { 2 | "enable-source-maps": true, 3 | "exit": true, 4 | "spec": ["tests/compiled/**/*.spec.js"] 5 | } -------------------------------------------------------------------------------- /packages/user-agent/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "node", 9 | "request": "launch", 10 | "name": "test:node", 11 | "runtimeExecutable": "${workspaceFolder:user-agent}/node_modules/.bin/mocha", 12 | "console": "internalConsole", 13 | "preLaunchTask": "build tests", 14 | "skipFiles": [ 15 | "/**" 16 | ], 17 | "env": { 18 | "TEST_DWN_URL": "http://localhost:3000" 19 | } 20 | } 21 | ] 22 | } -------------------------------------------------------------------------------- /packages/user-agent/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "pnpm build", 6 | "type": "npm", 7 | "script": "build", 8 | "problemMatcher": [], 9 | "group": { 10 | "kind": "build", 11 | "isDefault": true 12 | } 13 | }, 14 | { 15 | "label": "tsc: build - tsconfig.json", 16 | "type": "typescript", 17 | "tsconfig": "tsconfig.json", 18 | "problemMatcher": [ 19 | "$tsc" 20 | ], 21 | "group": { 22 | "kind": "build", 23 | "isDefault": false 24 | }, 25 | "options": { 26 | "cwd": "${workspaceFolder:root}" 27 | } 28 | }, 29 | { 30 | "label": "build tests", 31 | "type": "npm", 32 | "script": "build:tests:node", 33 | "options": { 34 | "cwd": "${workspaceFolder:user-agent}" 35 | } 36 | } 37 | ] 38 | } -------------------------------------------------------------------------------- /packages/user-agent/README.md: -------------------------------------------------------------------------------- 1 | # Web5 User Agent -------------------------------------------------------------------------------- /packages/user-agent/build/bundles.js: -------------------------------------------------------------------------------- 1 | import esbuild from 'esbuild'; 2 | import browserConfig from './esbuild-browser-config.cjs'; 3 | 4 | // esm polyfilled bundle for browser 5 | esbuild.build({ 6 | ...browserConfig, 7 | outfile: 'dist/browser.mjs', 8 | }); 9 | 10 | // iife polyfilled bundle for browser 11 | esbuild.build({ 12 | ...browserConfig, 13 | format : 'iife', 14 | globalName : 'Web5UserAgent', 15 | outfile : 'dist/browser.js', 16 | }); -------------------------------------------------------------------------------- /packages/user-agent/build/esbuild-browser-config.cjs: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-var-requires */ 2 | const polyfillProviderPlugin = require('node-stdlib-browser/helpers/esbuild/plugin'); 3 | const stdLibBrowser = require('node-stdlib-browser'); 4 | 5 | const requiredPolyfills = new Set(['crypto', 'node:crypto', 'stream']); 6 | 7 | // populate object containing lib -> polyfill path 8 | const polyfills = {}; 9 | for (let lib in stdLibBrowser) { 10 | if (requiredPolyfills.has(lib)) { 11 | const polyfill = stdLibBrowser[lib]; 12 | polyfills[lib] = polyfill; 13 | } 14 | } 15 | 16 | /** @type {import('esbuild').BuildOptions} */ 17 | module.exports = { 18 | entryPoints : ['./src/index.ts'], 19 | bundle : true, 20 | format : 'esm', 21 | sourcemap : true, 22 | minify : true, 23 | platform : 'browser', 24 | target : ['chrome101', 'firefox108', 'safari16'], 25 | inject : [require.resolve('node-stdlib-browser/helpers/esbuild/shim')], 26 | plugins : [polyfillProviderPlugin(polyfills)], 27 | define : { 28 | 'global': 'globalThis', 29 | }, 30 | }; -------------------------------------------------------------------------------- /packages/user-agent/build/esbuild-tests.cjs: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-var-requires */ 2 | const esbuild = require('esbuild'); 3 | const browserConfig = require('./esbuild-browser-config.cjs'); 4 | 5 | esbuild.build({ 6 | ...browserConfig, 7 | format : 'esm', 8 | entryPoints : ['./tests/**/*.spec.*'], 9 | bundle : true, 10 | minify : false, 11 | outdir : 'tests/compiled', 12 | define : { 13 | ...browserConfig.define, 14 | 'process.env.TEST_DWN_URL': JSON.stringify(process.env.TEST_DWN_URL ?? null), 15 | }, 16 | }); 17 | -------------------------------------------------------------------------------- /packages/user-agent/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './user-agent.js'; -------------------------------------------------------------------------------- /packages/user-agent/tests/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "compiled", 5 | "declarationDir": "compiled/types", 6 | "sourceMap": true, 7 | }, 8 | "include": [ 9 | "../src", 10 | ".", 11 | ], 12 | "exclude": [ 13 | "./compiled" 14 | ] 15 | } -------------------------------------------------------------------------------- /packages/user-agent/tests/utils/test-config.ts: -------------------------------------------------------------------------------- 1 | const DEFAULT_TEST_DWN_URL = 'http://localhost:3000'; 2 | 3 | const getTestDwnUrl = () => process.env.TEST_DWN_URL || DEFAULT_TEST_DWN_URL; 4 | 5 | export const testDwnUrl = getTestDwnUrl(); -------------------------------------------------------------------------------- /packages/user-agent/tsconfig.cjs.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "lib": [ 5 | "DOM", 6 | "ES5" 7 | ], 8 | "target": "ES5", 9 | "module": "CommonJS", 10 | "outDir": "dist/cjs", 11 | "declaration": false, 12 | "declarationMap": false, 13 | "declarationDir": null 14 | }, 15 | "include": [ 16 | "src" 17 | ] 18 | } -------------------------------------------------------------------------------- /packages/user-agent/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "declarationDir": "dist/types", 5 | "outDir": "dist/esm" 6 | }, 7 | "include": [ 8 | "src" 9 | ], 10 | "exclude": [ 11 | "node_modules" 12 | ] 13 | } -------------------------------------------------------------------------------- /packages/user-agent/web-test-runner.config.cjs: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-var-requires */ 2 | const playwrightLauncher = 3 | require('@web/test-runner-playwright').playwrightLauncher; 4 | 5 | /** 6 | * @type {import('@web/test-runner').TestRunnerConfig} 7 | */ 8 | module.exports = { 9 | files : 'tests/compiled/**/*.spec.js', 10 | playwright : true, 11 | nodeResolve : true, 12 | browsers : [ 13 | playwrightLauncher({ 14 | product: 'chromium', 15 | }), 16 | playwrightLauncher({ 17 | product: 'firefox', 18 | }), 19 | playwrightLauncher({ 20 | product: 'webkit', 21 | }), 22 | ], 23 | testsFinishTimeout : 300000, 24 | concurrentBrowsers : 2, 25 | testFramework : { 26 | config: { 27 | timeout: '15000', 28 | }, 29 | }, 30 | }; 31 | -------------------------------------------------------------------------------- /pnpm-workspace.yaml: -------------------------------------------------------------------------------- 1 | packages: 2 | - "packages/common" 3 | - "packages/crypto" 4 | - "packages/crypto-aws-kms" 5 | - "packages/dids" 6 | - "packages/credentials" 7 | - "packages/agent" 8 | - "packages/user-agent" 9 | - "packages/proxy-agent" 10 | - "packages/identity-agent" 11 | - "packages/api" 12 | - "packages/browser" 13 | -------------------------------------------------------------------------------- /scripts/changesets-api-release-check.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | CHANGESET_STATUS=$(pnpm changeset status) 4 | 5 | ALL_RELEASES_COUNT=$(echo $CHANGESET_STATUS | grep -o "web5/" | wc -l) 6 | API_RELEASES_COUNT=$(echo $CHANGESET_STATUS | grep -o "web5/api" | wc -l) 7 | 8 | # check if it has changesets 9 | if [[ $ALL_RELEASES_COUNT == 0 ]]; then 10 | echo "No changesets detected, proceed as normal..." 11 | exit 0 12 | fi 13 | 14 | # check if it has any api releases to be handled 15 | if [[ $API_RELEASES_COUNT == 0 ]]; then 16 | echo "No API releases detected, proceed as normal..." 17 | exit 0 18 | fi 19 | 20 | # manual kick api release trigger input 21 | echo "KICK_API_RELEASE: $KICK_API_RELEASE" 22 | 23 | # check for api release labeled PRs 24 | API_RELEASE_PR=$(gh pr list \ 25 | --base 'main' \ 26 | --head 'changeset-release/main' \ 27 | --json title,labels,number \ 28 | --jq '[.[] | select(.labels[]?.name == "api-release")] | first | .number') 29 | echo "API_RELEASE_PR: $API_RELEASE_PR" 30 | 31 | if [[ -n $API_RELEASE_PR || $KICK_API_RELEASE == "true" ]]; then 32 | echo "@web5/api release DETECTED" 33 | RELEASE_WEB5_API="true" 34 | echo "release_web5_api=$RELEASE_WEB5_API" >> $GITHUB_OUTPUT 35 | exit 0 36 | fi 37 | 38 | if [[ $API_RELEASES_COUNT == $ALL_RELEASES_COUNT ]]; then 39 | echo "Only @web5/api release detected, checking for API Release labeled PR or Kick trigger..." 40 | if [[ -z $RELEASE_WEB5_API ]]; then 41 | echo "No API Release labeled PR found and KICK_API_RELEASE is false, skipping the PR creation..." 42 | # removes all the api changesets files to ensure a Version Packages PR is not created 43 | find .changeset -type f -name "*.md" ! -name "README.md" -exec rm {} + 44 | exit 0 45 | fi 46 | fi 47 | -------------------------------------------------------------------------------- /scripts/changesets-version.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | IGNORE_API_RELEASE="" 4 | 5 | # force api release if argument is passed 6 | FORCE_API_RELEASE=$1 7 | 8 | # if there is no PR, then we release without the Web5 API 9 | if [[ -z "$FORCE_API_RELEASE" ]]; then 10 | echo "This is a release without the Web5 API" 11 | IGNORE_API_RELEASE="--ignore @web5/api" 12 | else 13 | echo "Web5 API Release DETECTED" 14 | fi 15 | 16 | CMD="pnpm changeset version $IGNORE_API_RELEASE" 17 | echo "Running: $CMD" 18 | $CMD 19 | 20 | # update pnpm-lock.yaml 21 | pnpm install --no-frozen-lockfile -------------------------------------------------------------------------------- /scripts/tbdocs-check-local.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | mkdir -p .tbdocs 4 | 5 | SUMMARY_FILE=.tbdocs/summary.md 6 | 7 | rm -f ${SUMMARY_FILE} 8 | touch ${SUMMARY_FILE} 9 | 10 | INPUT_ENTRY_POINTS=" 11 | - file: packages/api/src/index.ts 12 | docsReporter: typedoc 13 | docsGenerator: typedoc-html 14 | readmeFile: packages/api/README.md 15 | - file: packages/crypto/src/index.ts 16 | docsReporter: typedoc 17 | docsGenerator: typedoc-html 18 | readmeFile: packages/crypto/README.md 19 | - file: packages/crypto-aws-kms/src/index.ts 20 | docsReporter: typedoc 21 | docsGenerator: typedoc-html 22 | readmeFile: packages/crypto-aws-kms/README.md 23 | - file: packages/dids/src/index.ts 24 | docsReporter: typedoc 25 | docsGenerator: typedoc-html 26 | readmeFile: packages/dids/README.md 27 | - file: packages/credentials/src/index.ts 28 | docsReporter: typedoc 29 | docsGenerator: typedoc-html 30 | readmeFile: packages/credentials/README.md 31 | " 32 | 33 | # Default docker image 34 | DOCKER_IMAGE="ghcr.io/tbd54566975/tbdocs:main" 35 | 36 | # Check for --local-image flag and update DOCKER_IMAGE if present 37 | for arg in "$@" 38 | do 39 | if [ "$arg" == "--local-image" ]; then 40 | DOCKER_IMAGE="tbdocs:latest" 41 | fi 42 | done 43 | 44 | docker run -v $(pwd):/github/workspace/ \ 45 | --workdir /github/workspace \ 46 | -e "GITHUB_REPOSITORY=TBD54566975/web5-js" \ 47 | -e "GITHUB_STEP_SUMMARY=${SUMMARY_FILE}" \ 48 | -e "INPUT_ENTRY_POINTS=${INPUT_ENTRY_POINTS}" \ 49 | -e "INPUT_GROUP_DOCS=true" \ 50 | ${DOCKER_IMAGE} -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "lib": [ 4 | "DOM", 5 | "ES2022", 6 | ], 7 | "allowJs": false, 8 | "strict": true, 9 | "declaration": true, 10 | "declarationMap": true, 11 | "target": "ES6", 12 | "module": "NodeNext", // Required for enabling JavaScript import assertion support 13 | "sourceMap": true, 14 | // `NodeNext` will throw compilation errors if relative import paths are missing file extension 15 | // reference: https://devblogs.microsoft.com/typescript/announcing-typescript-4-7/#ecmascript-module-support-in-node-js 16 | "esModuleInterop": true, 17 | "resolveJsonModule": true, 18 | "moduleResolution": "NodeNext", 19 | "skipLibCheck": true 20 | }, 21 | "exclude": ["eslint.config.cjs", "data", "bin", "web5-spec", "node_modules"] 22 | } --------------------------------------------------------------------------------