@enbox/agent 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.js +2215 -0
- package/dist/browser.js.map +7 -0
- package/dist/browser.mjs +2215 -0
- package/dist/browser.mjs.map +7 -0
- package/dist/cjs/index.js +8530 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/package.json +1 -0
- package/dist/esm/agent-did-resolver-cache.js +87 -0
- package/dist/esm/agent-did-resolver-cache.js.map +1 -0
- package/dist/esm/bearer-identity.js +41 -0
- package/dist/esm/bearer-identity.js.map +1 -0
- package/dist/esm/connect.js +191 -0
- package/dist/esm/connect.js.map +1 -0
- package/dist/esm/crypto-api.js +346 -0
- package/dist/esm/crypto-api.js.map +1 -0
- package/dist/esm/did-api.js +278 -0
- package/dist/esm/did-api.js.map +1 -0
- package/dist/esm/dwn-api.js +336 -0
- package/dist/esm/dwn-api.js.map +1 -0
- package/dist/esm/dwn-registrar.js +120 -0
- package/dist/esm/dwn-registrar.js.map +1 -0
- package/dist/esm/hd-identity-vault.js +729 -0
- package/dist/esm/hd-identity-vault.js.map +1 -0
- package/dist/esm/identity-api.js +262 -0
- package/dist/esm/identity-api.js.map +1 -0
- package/dist/esm/index.js +23 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/local-key-manager.js +498 -0
- package/dist/esm/local-key-manager.js.map +1 -0
- package/dist/esm/oidc.js +507 -0
- package/dist/esm/oidc.js.map +1 -0
- package/dist/esm/permissions-api.js +322 -0
- package/dist/esm/permissions-api.js.map +1 -0
- package/dist/esm/prototyping/clients/dwn-rpc-types.js +2 -0
- package/dist/esm/prototyping/clients/dwn-rpc-types.js.map +1 -0
- package/dist/esm/prototyping/clients/dwn-server-info-cache-memory.js +74 -0
- package/dist/esm/prototyping/clients/dwn-server-info-cache-memory.js.map +1 -0
- package/dist/esm/prototyping/clients/http-dwn-rpc-client.js +105 -0
- package/dist/esm/prototyping/clients/http-dwn-rpc-client.js.map +1 -0
- package/dist/esm/prototyping/clients/json-rpc-socket.js +150 -0
- package/dist/esm/prototyping/clients/json-rpc-socket.js.map +1 -0
- package/dist/esm/prototyping/clients/json-rpc.js +58 -0
- package/dist/esm/prototyping/clients/json-rpc.js.map +1 -0
- package/dist/esm/prototyping/clients/server-info-types.js +2 -0
- package/dist/esm/prototyping/clients/server-info-types.js.map +1 -0
- package/dist/esm/prototyping/clients/web-socket-clients.js +90 -0
- package/dist/esm/prototyping/clients/web-socket-clients.js.map +1 -0
- package/dist/esm/prototyping/common/object.js +14 -0
- package/dist/esm/prototyping/common/object.js.map +1 -0
- package/dist/esm/prototyping/common/type-utils.js +2 -0
- package/dist/esm/prototyping/common/type-utils.js.map +1 -0
- package/dist/esm/prototyping/crypto/algorithms/aes-gcm.js +147 -0
- package/dist/esm/prototyping/crypto/algorithms/aes-gcm.js.map +1 -0
- package/dist/esm/prototyping/crypto/algorithms/aes-kw.js +137 -0
- package/dist/esm/prototyping/crypto/algorithms/aes-kw.js.map +1 -0
- package/dist/esm/prototyping/crypto/algorithms/ecdsa.js +307 -0
- package/dist/esm/prototyping/crypto/algorithms/ecdsa.js.map +1 -0
- package/dist/esm/prototyping/crypto/algorithms/eddsa.js +264 -0
- package/dist/esm/prototyping/crypto/algorithms/eddsa.js.map +1 -0
- package/dist/esm/prototyping/crypto/algorithms/hkdf.js +39 -0
- package/dist/esm/prototyping/crypto/algorithms/hkdf.js.map +1 -0
- package/dist/esm/prototyping/crypto/algorithms/pbkdf2.js +41 -0
- package/dist/esm/prototyping/crypto/algorithms/pbkdf2.js.map +1 -0
- package/dist/esm/prototyping/crypto/crypto-error.js +41 -0
- package/dist/esm/prototyping/crypto/crypto-error.js.map +1 -0
- package/dist/esm/prototyping/crypto/dsa.js +236 -0
- package/dist/esm/prototyping/crypto/dsa.js.map +1 -0
- package/dist/esm/prototyping/crypto/jose/jwe-compact.js +130 -0
- package/dist/esm/prototyping/crypto/jose/jwe-compact.js.map +1 -0
- package/dist/esm/prototyping/crypto/jose/jwe-flattened.js +294 -0
- package/dist/esm/prototyping/crypto/jose/jwe-flattened.js.map +1 -0
- package/dist/esm/prototyping/crypto/jose/jwe.js +308 -0
- package/dist/esm/prototyping/crypto/jose/jwe.js.map +1 -0
- package/dist/esm/prototyping/crypto/primitives/aes-gcm.js +352 -0
- package/dist/esm/prototyping/crypto/primitives/aes-gcm.js.map +1 -0
- package/dist/esm/prototyping/crypto/primitives/aes-kw.js +247 -0
- package/dist/esm/prototyping/crypto/primitives/aes-kw.js.map +1 -0
- package/dist/esm/prototyping/crypto/primitives/hkdf.js +80 -0
- package/dist/esm/prototyping/crypto/primitives/hkdf.js.map +1 -0
- package/dist/esm/prototyping/crypto/primitives/pbkdf2.js +85 -0
- package/dist/esm/prototyping/crypto/primitives/pbkdf2.js.map +1 -0
- package/dist/esm/prototyping/crypto/types/cipher.js +2 -0
- package/dist/esm/prototyping/crypto/types/cipher.js.map +1 -0
- package/dist/esm/prototyping/crypto/types/crypto-api.js +2 -0
- package/dist/esm/prototyping/crypto/types/crypto-api.js.map +1 -0
- package/dist/esm/prototyping/crypto/types/key-converter.js +2 -0
- package/dist/esm/prototyping/crypto/types/key-converter.js.map +1 -0
- package/dist/esm/prototyping/crypto/types/key-deriver.js +2 -0
- package/dist/esm/prototyping/crypto/types/key-deriver.js.map +1 -0
- package/dist/esm/prototyping/crypto/types/key-io.js +2 -0
- package/dist/esm/prototyping/crypto/types/key-io.js.map +1 -0
- package/dist/esm/prototyping/crypto/types/key-manager.js +2 -0
- package/dist/esm/prototyping/crypto/types/key-manager.js.map +1 -0
- package/dist/esm/prototyping/crypto/types/key-wrapper.js +2 -0
- package/dist/esm/prototyping/crypto/types/key-wrapper.js.map +1 -0
- package/dist/esm/prototyping/crypto/types/params-direct.js +2 -0
- package/dist/esm/prototyping/crypto/types/params-direct.js.map +1 -0
- package/dist/esm/prototyping/crypto/types/params-kms.js +2 -0
- package/dist/esm/prototyping/crypto/types/params-kms.js.map +1 -0
- package/dist/esm/prototyping/crypto/utils.js +19 -0
- package/dist/esm/prototyping/crypto/utils.js.map +1 -0
- package/dist/esm/prototyping/dids/resolver-cache-memory.js +77 -0
- package/dist/esm/prototyping/dids/resolver-cache-memory.js.map +1 -0
- package/dist/esm/prototyping/dids/utils.js +9 -0
- package/dist/esm/prototyping/dids/utils.js.map +1 -0
- package/dist/esm/rpc-client.js +123 -0
- package/dist/esm/rpc-client.js.map +1 -0
- package/dist/esm/store-data-protocols.js +38 -0
- package/dist/esm/store-data-protocols.js.map +1 -0
- package/dist/esm/store-data.js +320 -0
- package/dist/esm/store-data.js.map +1 -0
- package/dist/esm/store-did.js +136 -0
- package/dist/esm/store-did.js.map +1 -0
- package/dist/esm/store-identity.js +140 -0
- package/dist/esm/store-identity.js.map +1 -0
- package/dist/esm/store-key.js +136 -0
- package/dist/esm/store-key.js.map +1 -0
- package/dist/esm/sync-api.js +61 -0
- package/dist/esm/sync-api.js.map +1 -0
- package/dist/esm/sync-engine-level.js +618 -0
- package/dist/esm/sync-engine-level.js.map +1 -0
- package/dist/esm/test-harness.js +239 -0
- package/dist/esm/test-harness.js.map +1 -0
- package/dist/esm/types/agent.js +2 -0
- package/dist/esm/types/agent.js.map +1 -0
- package/dist/esm/types/dwn.js +31 -0
- package/dist/esm/types/dwn.js.map +1 -0
- package/dist/esm/types/identity-vault.js +2 -0
- package/dist/esm/types/identity-vault.js.map +1 -0
- package/dist/esm/types/identity.js +2 -0
- package/dist/esm/types/identity.js.map +1 -0
- package/dist/esm/types/key-manager.js +2 -0
- package/dist/esm/types/key-manager.js.map +1 -0
- package/dist/esm/types/permissions.js +2 -0
- package/dist/esm/types/permissions.js.map +1 -0
- package/dist/esm/types/sync.js +2 -0
- package/dist/esm/types/sync.js.map +1 -0
- package/dist/esm/types/vc.js +5 -0
- package/dist/esm/types/vc.js.map +1 -0
- package/dist/esm/utils-internal.js +147 -0
- package/dist/esm/utils-internal.js.map +1 -0
- package/dist/esm/utils.js +161 -0
- package/dist/esm/utils.js.map +1 -0
- package/dist/types/agent-did-resolver-cache.d.ts +30 -0
- package/dist/types/agent-did-resolver-cache.d.ts.map +1 -0
- package/dist/types/bearer-identity.d.ts +31 -0
- package/dist/types/bearer-identity.d.ts.map +1 -0
- package/dist/types/connect.d.ts +88 -0
- package/dist/types/connect.d.ts.map +1 -0
- package/dist/types/crypto-api.d.ts +286 -0
- package/dist/types/crypto-api.d.ts.map +1 -0
- package/dist/types/did-api.d.ts +119 -0
- package/dist/types/did-api.d.ts.map +1 -0
- package/dist/types/dwn-api.d.ts +66 -0
- package/dist/types/dwn-api.d.ts.map +1 -0
- package/dist/types/dwn-registrar.d.ts +29 -0
- package/dist/types/dwn-registrar.d.ts.map +1 -0
- package/dist/types/hd-identity-vault.d.ts +306 -0
- package/dist/types/hd-identity-vault.d.ts.map +1 -0
- package/dist/types/identity-api.d.ts +107 -0
- package/dist/types/identity-api.d.ts.map +1 -0
- package/dist/types/index.d.ts +30 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/local-key-manager.d.ts +311 -0
- package/dist/types/local-key-manager.d.ts.map +1 -0
- package/dist/types/oidc.d.ts +247 -0
- package/dist/types/oidc.d.ts.map +1 -0
- package/dist/types/permissions-api.d.ts +35 -0
- package/dist/types/permissions-api.d.ts.map +1 -0
- package/dist/types/prototyping/clients/dwn-rpc-types.d.ts +45 -0
- package/dist/types/prototyping/clients/dwn-rpc-types.d.ts.map +1 -0
- package/dist/types/prototyping/clients/dwn-server-info-cache-memory.d.ts +57 -0
- package/dist/types/prototyping/clients/dwn-server-info-cache-memory.d.ts.map +1 -0
- package/dist/types/prototyping/clients/http-dwn-rpc-client.d.ts +13 -0
- package/dist/types/prototyping/clients/http-dwn-rpc-client.d.ts.map +1 -0
- package/dist/types/prototyping/clients/json-rpc-socket.d.ts +43 -0
- package/dist/types/prototyping/clients/json-rpc-socket.d.ts.map +1 -0
- package/dist/types/prototyping/clients/json-rpc.d.ts +49 -0
- package/dist/types/prototyping/clients/json-rpc.d.ts.map +1 -0
- package/dist/types/prototyping/clients/server-info-types.d.ts +20 -0
- package/dist/types/prototyping/clients/server-info-types.d.ts.map +1 -0
- package/dist/types/prototyping/clients/web-socket-clients.d.ts +10 -0
- package/dist/types/prototyping/clients/web-socket-clients.d.ts.map +1 -0
- package/dist/types/prototyping/common/object.d.ts +2 -0
- package/dist/types/prototyping/common/object.d.ts.map +1 -0
- package/dist/types/prototyping/common/type-utils.d.ts +7 -0
- package/dist/types/prototyping/common/type-utils.d.ts.map +1 -0
- package/dist/types/prototyping/crypto/algorithms/aes-gcm.d.ts +151 -0
- package/dist/types/prototyping/crypto/algorithms/aes-gcm.d.ts.map +1 -0
- package/dist/types/prototyping/crypto/algorithms/aes-kw.d.ts +109 -0
- package/dist/types/prototyping/crypto/algorithms/aes-kw.d.ts.map +1 -0
- package/dist/types/prototyping/crypto/algorithms/ecdsa.d.ts +160 -0
- package/dist/types/prototyping/crypto/algorithms/ecdsa.d.ts.map +1 -0
- package/dist/types/prototyping/crypto/algorithms/eddsa.d.ts +157 -0
- package/dist/types/prototyping/crypto/algorithms/eddsa.d.ts.map +1 -0
- package/dist/types/prototyping/crypto/algorithms/hkdf.d.ts +21 -0
- package/dist/types/prototyping/crypto/algorithms/hkdf.d.ts.map +1 -0
- package/dist/types/prototyping/crypto/algorithms/pbkdf2.d.ts +21 -0
- package/dist/types/prototyping/crypto/algorithms/pbkdf2.d.ts.map +1 -0
- package/dist/types/prototyping/crypto/crypto-error.d.ts +29 -0
- package/dist/types/prototyping/crypto/crypto-error.d.ts.map +1 -0
- package/dist/types/prototyping/crypto/dsa.d.ts +169 -0
- package/dist/types/prototyping/crypto/dsa.d.ts.map +1 -0
- package/dist/types/prototyping/crypto/jose/jwe-compact.d.ts +135 -0
- package/dist/types/prototyping/crypto/jose/jwe-compact.d.ts.map +1 -0
- package/dist/types/prototyping/crypto/jose/jwe-flattened.d.ts +134 -0
- package/dist/types/prototyping/crypto/jose/jwe-flattened.d.ts.map +1 -0
- package/dist/types/prototyping/crypto/jose/jwe.d.ts +378 -0
- package/dist/types/prototyping/crypto/jose/jwe.d.ts.map +1 -0
- package/dist/types/prototyping/crypto/primitives/aes-gcm.d.ts +245 -0
- package/dist/types/prototyping/crypto/primitives/aes-gcm.d.ts.map +1 -0
- package/dist/types/prototyping/crypto/primitives/aes-kw.d.ts +103 -0
- package/dist/types/prototyping/crypto/primitives/aes-kw.d.ts.map +1 -0
- package/dist/types/prototyping/crypto/primitives/hkdf.d.ts +90 -0
- package/dist/types/prototyping/crypto/primitives/hkdf.d.ts.map +1 -0
- package/dist/types/prototyping/crypto/primitives/pbkdf2.d.ts +84 -0
- package/dist/types/prototyping/crypto/primitives/pbkdf2.d.ts.map +1 -0
- package/dist/types/prototyping/crypto/types/cipher.d.ts +14 -0
- package/dist/types/prototyping/crypto/types/cipher.d.ts.map +1 -0
- package/dist/types/prototyping/crypto/types/crypto-api.d.ts +35 -0
- package/dist/types/prototyping/crypto/types/crypto-api.d.ts.map +1 -0
- package/dist/types/prototyping/crypto/types/key-converter.d.ts +49 -0
- package/dist/types/prototyping/crypto/types/key-converter.d.ts.map +1 -0
- package/dist/types/prototyping/crypto/types/key-deriver.d.ts +50 -0
- package/dist/types/prototyping/crypto/types/key-deriver.d.ts.map +1 -0
- package/dist/types/prototyping/crypto/types/key-io.d.ts +49 -0
- package/dist/types/prototyping/crypto/types/key-io.d.ts.map +1 -0
- package/dist/types/prototyping/crypto/types/key-manager.d.ts +69 -0
- package/dist/types/prototyping/crypto/types/key-manager.d.ts.map +1 -0
- package/dist/types/prototyping/crypto/types/key-wrapper.d.ts +14 -0
- package/dist/types/prototyping/crypto/types/key-wrapper.d.ts.map +1 -0
- package/dist/types/prototyping/crypto/types/params-direct.d.ts +75 -0
- package/dist/types/prototyping/crypto/types/params-direct.d.ts.map +1 -0
- package/dist/types/prototyping/crypto/types/params-kms.d.ts +63 -0
- package/dist/types/prototyping/crypto/types/params-kms.d.ts.map +1 -0
- package/dist/types/prototyping/crypto/utils.d.ts +7 -0
- package/dist/types/prototyping/crypto/utils.d.ts.map +1 -0
- package/dist/types/prototyping/dids/resolver-cache-memory.d.ts +57 -0
- package/dist/types/prototyping/dids/resolver-cache-memory.d.ts.map +1 -0
- package/dist/types/prototyping/dids/utils.d.ts +3 -0
- package/dist/types/prototyping/dids/utils.d.ts.map +1 -0
- package/dist/types/rpc-client.d.ts +51 -0
- package/dist/types/rpc-client.d.ts.map +1 -0
- package/dist/types/store-data-protocols.d.ts +4 -0
- package/dist/types/store-data-protocols.d.ts.map +1 -0
- package/dist/types/store-data.d.ts +95 -0
- package/dist/types/store-data.d.ts.map +1 -0
- package/dist/types/store-did.d.ts +33 -0
- package/dist/types/store-did.d.ts.map +1 -0
- package/dist/types/store-identity.d.ts +34 -0
- package/dist/types/store-identity.d.ts.map +1 -0
- package/dist/types/store-key.d.ts +32 -0
- package/dist/types/store-key.d.ts.map +1 -0
- package/dist/types/sync-api.d.ts +41 -0
- package/dist/types/sync-api.d.ts.map +1 -0
- package/dist/types/sync-engine-level.d.ts +85 -0
- package/dist/types/sync-engine-level.d.ts.map +1 -0
- package/dist/types/test-harness.d.ts +69 -0
- package/dist/types/test-harness.d.ts.map +1 -0
- package/dist/types/types/agent.d.ts +172 -0
- package/dist/types/types/agent.d.ts.map +1 -0
- package/dist/types/types/dwn.d.ts +178 -0
- package/dist/types/types/dwn.d.ts.map +1 -0
- package/dist/types/types/identity-vault.d.ts +129 -0
- package/dist/types/types/identity-vault.d.ts.map +1 -0
- package/dist/types/types/identity.d.ts +16 -0
- package/dist/types/types/identity.d.ts.map +1 -0
- package/dist/types/types/key-manager.d.ts +9 -0
- package/dist/types/types/key-manager.d.ts.map +1 -0
- package/dist/types/types/permissions.d.ts +98 -0
- package/dist/types/types/permissions.d.ts.map +1 -0
- package/dist/types/types/sync.d.ts +66 -0
- package/dist/types/types/sync.d.ts.map +1 -0
- package/dist/types/types/vc.d.ts +7 -0
- package/dist/types/types/vc.d.ts.map +1 -0
- package/dist/types/utils-internal.d.ts +50 -0
- package/dist/types/utils-internal.d.ts.map +1 -0
- package/dist/types/utils.d.ts +37 -0
- package/dist/types/utils.d.ts.map +1 -0
- package/package.json +112 -0
- package/src/agent-did-resolver-cache.ts +95 -0
- package/src/bearer-identity.ts +42 -0
- package/src/connect.ts +296 -0
- package/src/crypto-api.ts +593 -0
- package/src/did-api.ts +429 -0
- package/src/dwn-api.ts +462 -0
- package/src/dwn-registrar.ts +127 -0
- package/src/hd-identity-vault.ts +853 -0
- package/src/identity-api.ts +324 -0
- package/src/index.ts +30 -0
- package/src/local-key-manager.ts +672 -0
- package/src/oidc.ts +857 -0
- package/src/permissions-api.ts +408 -0
- package/src/prototyping/clients/dwn-rpc-types.ts +55 -0
- package/src/prototyping/clients/dwn-server-info-cache-memory.ts +79 -0
- package/src/prototyping/clients/http-dwn-rpc-client.ts +110 -0
- package/src/prototyping/clients/json-rpc-socket.ts +169 -0
- package/src/prototyping/clients/json-rpc.ts +113 -0
- package/src/prototyping/clients/server-info-types.ts +21 -0
- package/src/prototyping/clients/web-socket-clients.ts +100 -0
- package/src/prototyping/common/object.ts +15 -0
- package/src/prototyping/common/type-utils.ts +6 -0
- package/src/prototyping/crypto/algorithms/aes-gcm.ts +211 -0
- package/src/prototyping/crypto/algorithms/aes-kw.ts +164 -0
- package/src/prototyping/crypto/algorithms/ecdsa.ts +365 -0
- package/src/prototyping/crypto/algorithms/eddsa.ts +310 -0
- package/src/prototyping/crypto/algorithms/hkdf.ts +40 -0
- package/src/prototyping/crypto/algorithms/pbkdf2.ts +44 -0
- package/src/prototyping/crypto/crypto-error.ts +45 -0
- package/src/prototyping/crypto/dsa.ts +367 -0
- package/src/prototyping/crypto/jose/jwe-compact.ts +225 -0
- package/src/prototyping/crypto/jose/jwe-flattened.ts +459 -0
- package/src/prototyping/crypto/jose/jwe.ts +653 -0
- package/src/prototyping/crypto/primitives/aes-gcm.ts +374 -0
- package/src/prototyping/crypto/primitives/aes-kw.ts +271 -0
- package/src/prototyping/crypto/primitives/hkdf.ts +121 -0
- package/src/prototyping/crypto/primitives/pbkdf2.ts +116 -0
- package/src/prototyping/crypto/types/cipher.ts +17 -0
- package/src/prototyping/crypto/types/crypto-api.ts +78 -0
- package/src/prototyping/crypto/types/key-converter.ts +53 -0
- package/src/prototyping/crypto/types/key-deriver.ts +56 -0
- package/src/prototyping/crypto/types/key-io.ts +51 -0
- package/src/prototyping/crypto/types/key-manager.ts +83 -0
- package/src/prototyping/crypto/types/key-wrapper.ts +17 -0
- package/src/prototyping/crypto/types/params-direct.ts +95 -0
- package/src/prototyping/crypto/types/params-kms.ts +76 -0
- package/src/prototyping/crypto/utils.ts +41 -0
- package/src/prototyping/dids/resolver-cache-memory.ts +83 -0
- package/src/prototyping/dids/utils.ts +10 -0
- package/src/rpc-client.ts +162 -0
- package/src/store-data-protocols.ts +40 -0
- package/src/store-data.ts +400 -0
- package/src/store-did.ts +105 -0
- package/src/store-identity.ts +109 -0
- package/src/store-key.ts +104 -0
- package/src/sync-api.ts +71 -0
- package/src/sync-engine-level.ts +714 -0
- package/src/test-harness.ts +330 -0
- package/src/types/agent.ts +195 -0
- package/src/types/dwn.ts +278 -0
- package/src/types/identity-vault.ts +137 -0
- package/src/types/identity.ts +18 -0
- package/src/types/key-manager.ts +15 -0
- package/src/types/permissions.ts +115 -0
- package/src/types/sync.ts +58 -0
- package/src/types/vc.ts +7 -0
- package/src/utils-internal.ts +157 -0
- package/src/utils.ts +181 -0
package/src/did-api.ts
ADDED
|
@@ -0,0 +1,429 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
DidDocument,
|
|
3
|
+
DidMetadata,
|
|
4
|
+
PortableDid,
|
|
5
|
+
DidMethodApi,
|
|
6
|
+
DidDhtCreateOptions,
|
|
7
|
+
DidJwkCreateOptions,
|
|
8
|
+
DidResolutionResult,
|
|
9
|
+
DidResolutionOptions,
|
|
10
|
+
DidVerificationMethod,
|
|
11
|
+
DidResolverCache,
|
|
12
|
+
} from '@enbox/dids';
|
|
13
|
+
|
|
14
|
+
import { BearerDid, Did, DidDht, UniversalResolver } from '@enbox/dids';
|
|
15
|
+
|
|
16
|
+
import type { AgentDataStore } from './store-data.js';
|
|
17
|
+
import type { AgentKeyManager } from './types/key-manager.js';
|
|
18
|
+
import type { ResponseStatus, Web5PlatformAgent } from './types/agent.js';
|
|
19
|
+
|
|
20
|
+
import { InMemoryDidStore } from './store-did.js';
|
|
21
|
+
import { AgentDidResolverCache } from './agent-did-resolver-cache.js';
|
|
22
|
+
import { canonicalize } from '@enbox/crypto';
|
|
23
|
+
|
|
24
|
+
export enum DidInterface {
|
|
25
|
+
Create = 'Create',
|
|
26
|
+
// Deactivate = 'Deactivate',
|
|
27
|
+
Resolve = 'Resolve',
|
|
28
|
+
// Update = 'Update'
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface DidMessageParams {
|
|
32
|
+
[DidInterface.Create]: DidCreateParams;
|
|
33
|
+
// [DidInterface.Deactivate]: DidDeactivateParams;
|
|
34
|
+
[DidInterface.Resolve]: DidResolveParams;
|
|
35
|
+
// [DidInterface.Update]: DidUpdateParams;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface DidMessageResult {
|
|
39
|
+
[DidInterface.Create]: DidCreateResult;
|
|
40
|
+
// [DidInterface.Deactivate]: DidDeactivateResult;
|
|
41
|
+
[DidInterface.Resolve]: DidResolveResult;
|
|
42
|
+
// [DidInterface.Update]: DidUpdateResult;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export type DidCreateResult = {
|
|
46
|
+
uri: string;
|
|
47
|
+
document: DidDocument;
|
|
48
|
+
metadata: DidMetadata;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export type DidResolveResult = DidResolutionResult
|
|
52
|
+
|
|
53
|
+
export type DidRequest<T extends DidInterface> = {
|
|
54
|
+
messageType: T;
|
|
55
|
+
messageParams: DidMessageParams[T];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export type DidResolveParams = {
|
|
59
|
+
didUri: string;
|
|
60
|
+
options?: DidResolutionOptions;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export type DidResponse<T extends DidInterface> = ResponseStatus & {
|
|
64
|
+
result?: DidMessageResult[T];
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export interface DidCreateParams<
|
|
68
|
+
TKeyManager = AgentKeyManager,
|
|
69
|
+
TMethod extends keyof DidMethodCreateOptions<TKeyManager> = keyof DidMethodCreateOptions<TKeyManager>
|
|
70
|
+
> {
|
|
71
|
+
method: TMethod;
|
|
72
|
+
options?: DidMethodCreateOptions<TKeyManager>[TMethod];
|
|
73
|
+
store?: boolean;
|
|
74
|
+
tenant?: string;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface DidMethodCreateOptions<TKeyManager> {
|
|
78
|
+
dht: DidDhtCreateOptions<TKeyManager>;
|
|
79
|
+
jwk: DidJwkCreateOptions<TKeyManager>;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface DidApiParams {
|
|
83
|
+
didMethods: DidMethodApi[];
|
|
84
|
+
|
|
85
|
+
agent?: Web5PlatformAgent;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* An optional `DidResolverCache` instance used for caching resolved DID documents.
|
|
89
|
+
*
|
|
90
|
+
* Providing a cache implementation can significantly enhance resolution performance by avoiding
|
|
91
|
+
* redundant resolutions for previously resolved DIDs. If omitted, the default is an instance of `AgentDidResolverCache`.
|
|
92
|
+
*
|
|
93
|
+
* `AgentDidResolverCache` keeps a stale copy of the Agent's managed Identity DIDs and only refreshes upon a successful resolution.
|
|
94
|
+
* This allows for quick and offline access to the internal DIDs used by the agent.
|
|
95
|
+
*/
|
|
96
|
+
resolverCache?: DidResolverCache;
|
|
97
|
+
|
|
98
|
+
store?: AgentDataStore<PortableDid>;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function isDidRequest<T extends DidInterface>(
|
|
102
|
+
didRequest: DidRequest<DidInterface>, messageType: T
|
|
103
|
+
): didRequest is DidRequest<T> {
|
|
104
|
+
return didRequest.messageType === messageType;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* This API is used to manage and interact with DIDs within the Web5 Agent framework.
|
|
109
|
+
*
|
|
110
|
+
* If a DWN Data Store is used, the DID information is stored under DID's own tenant by default.
|
|
111
|
+
* If a tenant property is passed, that tenant will be used to store the DID information.
|
|
112
|
+
*/
|
|
113
|
+
export class AgentDidApi<TKeyManager extends AgentKeyManager = AgentKeyManager> extends UniversalResolver {
|
|
114
|
+
/**
|
|
115
|
+
* Holds the instance of a `Web5PlatformAgent` that represents the current execution context for
|
|
116
|
+
* the `AgentDidApi`. This agent is used to interact with other Web5 agent components. It's vital
|
|
117
|
+
* to ensure this instance is set to correctly contextualize operations within the broader Web5
|
|
118
|
+
* Agent framework.
|
|
119
|
+
*/
|
|
120
|
+
private _agent?: Web5PlatformAgent;
|
|
121
|
+
|
|
122
|
+
private _didMethods: Map<string, DidMethodApi> = new Map();
|
|
123
|
+
|
|
124
|
+
private _store: AgentDataStore<PortableDid>;
|
|
125
|
+
|
|
126
|
+
constructor({ agent, didMethods, resolverCache, store }: DidApiParams) {
|
|
127
|
+
if (!didMethods) {
|
|
128
|
+
throw new TypeError(`AgentDidApi: Required parameter missing: 'didMethods'`);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Initialize the DID resolver with the given DID methods and resolver cache, or use a default
|
|
132
|
+
// AgentDidResolverCache if none is provided.
|
|
133
|
+
super({
|
|
134
|
+
didResolvers : didMethods,
|
|
135
|
+
cache : resolverCache ?? new AgentDidResolverCache({ agent, location: 'DATA/AGENT/DID_CACHE' })
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
this._agent = agent;
|
|
139
|
+
|
|
140
|
+
// If `store` is not given, use an in-memory store by default.
|
|
141
|
+
this._store = store ?? new InMemoryDidStore();
|
|
142
|
+
|
|
143
|
+
for (const didMethod of didMethods) {
|
|
144
|
+
this._didMethods.set(didMethod.methodName, didMethod);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Retrieves the `Web5PlatformAgent` execution context.
|
|
150
|
+
*
|
|
151
|
+
* @returns The `Web5PlatformAgent` instance that represents the current execution context.
|
|
152
|
+
* @throws Will throw an error if the `agent` instance property is undefined.
|
|
153
|
+
*/
|
|
154
|
+
get agent(): Web5PlatformAgent {
|
|
155
|
+
if (this._agent === undefined) {
|
|
156
|
+
throw new Error('AgentDidApi: Unable to determine agent execution context.');
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return this._agent;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
set agent(agent: Web5PlatformAgent) {
|
|
163
|
+
this._agent = agent;
|
|
164
|
+
|
|
165
|
+
// AgentDidResolverCache should set the agent if it is the type of cache being used
|
|
166
|
+
if ('agent' in this.cache) {
|
|
167
|
+
this.cache.agent = agent;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
public async create({
|
|
172
|
+
method, tenant, options, store
|
|
173
|
+
}: DidCreateParams<TKeyManager>): Promise<BearerDid> {
|
|
174
|
+
// Get the DID method implementation, which also verifies the method is supported.
|
|
175
|
+
const didMethod = this.getMethod(method);
|
|
176
|
+
|
|
177
|
+
// Create the DID and store the generated keys in the Agent's key manager.
|
|
178
|
+
const bearerDid = await didMethod.create({ keyManager: this.agent.keyManager, options });
|
|
179
|
+
|
|
180
|
+
// pre-populate the resolution cache with the document and metadata
|
|
181
|
+
await this.cache.set(bearerDid.uri, { didDocument: bearerDid.document, didResolutionMetadata: { }, didDocumentMetadata: bearerDid.metadata });
|
|
182
|
+
|
|
183
|
+
// Persist the DID to the store, by default, unless the `store` option is set to false.
|
|
184
|
+
if (store ?? true) {
|
|
185
|
+
// Data stored in the Agent's DID store must be in PortableDid format.
|
|
186
|
+
const { uri, document, metadata } = bearerDid;
|
|
187
|
+
const portableDid: PortableDid = { uri, document, metadata };
|
|
188
|
+
|
|
189
|
+
// Unless an existing `tenant` is specified, a record that includes the DID's URI, document,
|
|
190
|
+
// and metadata will be stored under a new tenant controlled by the newly created DID.
|
|
191
|
+
await this._store.set({
|
|
192
|
+
id : portableDid.uri,
|
|
193
|
+
data : portableDid,
|
|
194
|
+
agent : this.agent,
|
|
195
|
+
tenant : tenant ?? portableDid.uri,
|
|
196
|
+
preventDuplicates : false,
|
|
197
|
+
useCache : true
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return bearerDid;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
public async export({ didUri, tenant }: {
|
|
205
|
+
didUri: string;
|
|
206
|
+
tenant?: string;
|
|
207
|
+
}): Promise<PortableDid> {
|
|
208
|
+
// Attempt to retrieve the DID from the agent's DID store.
|
|
209
|
+
const bearerDid = await this.get({ didUri, tenant });
|
|
210
|
+
|
|
211
|
+
if (!bearerDid) {
|
|
212
|
+
throw new Error(`AgentDidApi: Failed to export due to DID not found: ${didUri}`);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// If the DID was found, return the DID in a portable format, and if supported by the Agent's
|
|
216
|
+
// key manager, the private key material.
|
|
217
|
+
const portableDid = await bearerDid.export();
|
|
218
|
+
|
|
219
|
+
return portableDid;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
public async get({ didUri, tenant }: {
|
|
223
|
+
didUri: string,
|
|
224
|
+
tenant?: string
|
|
225
|
+
}): Promise<BearerDid | undefined> {
|
|
226
|
+
const portableDid = await this._store.get({ id: didUri, agent: this.agent, tenant, useCache: true });
|
|
227
|
+
|
|
228
|
+
if (!portableDid) return undefined;
|
|
229
|
+
|
|
230
|
+
const bearerDid = await BearerDid.import({ portableDid, keyManager: this.agent.keyManager });
|
|
231
|
+
|
|
232
|
+
return bearerDid;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
public async getSigningMethod({ didUri, methodId }: {
|
|
236
|
+
didUri: string;
|
|
237
|
+
methodId?: string;
|
|
238
|
+
}): Promise<DidVerificationMethod> {
|
|
239
|
+
// Verify the DID method is supported.
|
|
240
|
+
const parsedDid = Did.parse(didUri);
|
|
241
|
+
if (!parsedDid) {
|
|
242
|
+
throw new Error(`Invalid DID URI: ${didUri}`);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// Get the DID method implementation, which also verifies the method is supported.
|
|
246
|
+
const didMethod = this.getMethod(parsedDid.method);
|
|
247
|
+
|
|
248
|
+
// Resolve the DID document.
|
|
249
|
+
const { didDocument, didResolutionMetadata } = await this.resolve(didUri);
|
|
250
|
+
if (!didDocument) {
|
|
251
|
+
throw new Error(`DID resolution failed for '${didUri}': ${JSON.stringify(didResolutionMetadata)}`);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// Retrieve the method-specific verification method to be used for signing operations.
|
|
255
|
+
const verificationMethod = await didMethod.getSigningMethod({ didDocument, methodId });
|
|
256
|
+
|
|
257
|
+
return verificationMethod;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
public async update({ tenant, portableDid, publish = true }: {
|
|
261
|
+
tenant?: string;
|
|
262
|
+
portableDid: PortableDid;
|
|
263
|
+
publish?: boolean;
|
|
264
|
+
}): Promise<BearerDid> {
|
|
265
|
+
|
|
266
|
+
// Check if the DID exists in the store.
|
|
267
|
+
const existingDid = await this.get({ didUri: portableDid.uri, tenant: tenant ?? portableDid.uri });
|
|
268
|
+
if (!existingDid) {
|
|
269
|
+
throw new Error(`AgentDidApi: Could not update, DID not found: ${portableDid.uri}`);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// If the document has not changed, abort the update.
|
|
273
|
+
if (canonicalize(portableDid.document) === canonicalize(existingDid.document)) {
|
|
274
|
+
throw new Error('AgentDidApi: No changes detected, update aborted');
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// If private keys are present in the PortableDid, import the key material into the Agent's key
|
|
278
|
+
// manager. Validate that the key material for every verification method in the DID document is
|
|
279
|
+
// present in the key manager. If no keys are present, this will fail.
|
|
280
|
+
// NOTE: We currently do not delete the previous keys from the document.
|
|
281
|
+
// TODO: Add support for deleting the keys no longer present in the document.
|
|
282
|
+
const bearerDid = await BearerDid.import({ keyManager: this.agent.keyManager, portableDid });
|
|
283
|
+
|
|
284
|
+
// Only the DID URI, document, and metadata are stored in the Agent's DID store.
|
|
285
|
+
const { uri, document, metadata } = bearerDid;
|
|
286
|
+
const portableDidWithoutKeys: PortableDid = { uri, document, metadata };
|
|
287
|
+
|
|
288
|
+
// pre-populate the resolution cache with the document and metadata
|
|
289
|
+
await this.cache.set(uri, { didDocument: document, didResolutionMetadata: { }, didDocumentMetadata: metadata });
|
|
290
|
+
|
|
291
|
+
await this._store.set({
|
|
292
|
+
id : uri,
|
|
293
|
+
data : portableDidWithoutKeys,
|
|
294
|
+
agent : this.agent,
|
|
295
|
+
tenant : tenant ?? uri,
|
|
296
|
+
updateExisting : true,
|
|
297
|
+
useCache : true
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
if (publish) {
|
|
301
|
+
const parsedDid = Did.parse(uri);
|
|
302
|
+
// currently only supporting DHT as a publishable method.
|
|
303
|
+
// TODO: abstract this into the didMethod class so that other publishable methods can be supported.
|
|
304
|
+
if (parsedDid && parsedDid.method === 'dht') {
|
|
305
|
+
await DidDht.publish({ did: bearerDid });
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
return bearerDid;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
public async import({ portableDid, tenant }: {
|
|
313
|
+
portableDid: PortableDid;
|
|
314
|
+
tenant?: string;
|
|
315
|
+
}): Promise<BearerDid> {
|
|
316
|
+
// If private keys are present in the PortableDid, import the key material into the Agent's key
|
|
317
|
+
// manager. Validate that the key material for every verification method in the DID document is
|
|
318
|
+
// present in the key manager.
|
|
319
|
+
const bearerDid = await BearerDid.import({ keyManager: this.agent.keyManager, portableDid });
|
|
320
|
+
|
|
321
|
+
// Only the DID URI, document, and metadata are stored in the Agent's DID store.
|
|
322
|
+
const { uri, document, metadata } = bearerDid;
|
|
323
|
+
const portableDidWithoutKeys: PortableDid = { uri, document, metadata };
|
|
324
|
+
|
|
325
|
+
// pre-populate the resolution cache with the document and metadata
|
|
326
|
+
await this.cache.set(uri, { didDocument: document, didResolutionMetadata: { }, didDocumentMetadata: metadata });
|
|
327
|
+
|
|
328
|
+
// Store the DID in the agent's DID store.
|
|
329
|
+
// Unless an existing `tenant` is specified, a record that includes the DID's URI, document,
|
|
330
|
+
// and metadata will be stored under a new tenant controlled by the imported DID.
|
|
331
|
+
await this._store.set({
|
|
332
|
+
id : portableDidWithoutKeys.uri,
|
|
333
|
+
data : portableDidWithoutKeys,
|
|
334
|
+
agent : this.agent,
|
|
335
|
+
tenant : tenant ?? portableDidWithoutKeys.uri,
|
|
336
|
+
preventDuplicates : true,
|
|
337
|
+
useCache : true
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
return bearerDid;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
public async delete({ didUri, tenant, deleteKey = true }: {
|
|
344
|
+
didUri: string;
|
|
345
|
+
tenant?: string;
|
|
346
|
+
deleteKey?: boolean;
|
|
347
|
+
}): Promise<void> {
|
|
348
|
+
const portableDid = await this._store.get({ id: didUri, agent: this.agent, tenant, useCache: false });
|
|
349
|
+
if(!portableDid) {
|
|
350
|
+
throw new Error('AgentDidApi: Could not delete, DID not found');
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
// delete from the cache
|
|
354
|
+
await this.cache.delete(didUri);
|
|
355
|
+
|
|
356
|
+
// Delete the data before deleting the associated keys.
|
|
357
|
+
await this._store.delete({ id: didUri, agent: this.agent, tenant });
|
|
358
|
+
|
|
359
|
+
if (deleteKey) {
|
|
360
|
+
// Delete the keys associated with the DID
|
|
361
|
+
// TODO: this could be made a static method on `BearerDid` class
|
|
362
|
+
await this.deleteKeys({ portableDid });
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
public async deleteKeys({ portableDid }: {
|
|
367
|
+
portableDid: PortableDid;
|
|
368
|
+
}): Promise<void> {
|
|
369
|
+
for (const verificationMethod of portableDid.document.verificationMethod || []) {
|
|
370
|
+
if (!verificationMethod.publicKeyJwk) {
|
|
371
|
+
continue;
|
|
372
|
+
}
|
|
373
|
+
// Compute the key URI of the verification method's public key.
|
|
374
|
+
const keyUri = await this.agent.keyManager.getKeyUri({ key: verificationMethod.publicKeyJwk });
|
|
375
|
+
await this.agent.keyManager.deleteKey({ keyUri });
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
public async processRequest<T extends DidInterface>(
|
|
380
|
+
request: DidRequest<T>
|
|
381
|
+
): Promise<DidResponse<T>> {
|
|
382
|
+
// Process Create DID request.
|
|
383
|
+
if (isDidRequest(request, DidInterface.Create)) {
|
|
384
|
+
try {
|
|
385
|
+
const bearerDid = await this.create({ ...request.messageParams });
|
|
386
|
+
const response: DidResponse<typeof request.messageType> = {
|
|
387
|
+
result: {
|
|
388
|
+
uri : bearerDid.uri,
|
|
389
|
+
document : bearerDid.document,
|
|
390
|
+
metadata : bearerDid.metadata,
|
|
391
|
+
},
|
|
392
|
+
ok : true,
|
|
393
|
+
status : { code: 201, message: 'Created' }
|
|
394
|
+
};
|
|
395
|
+
return response;
|
|
396
|
+
|
|
397
|
+
} catch (error: any) {
|
|
398
|
+
return {
|
|
399
|
+
ok : false,
|
|
400
|
+
status : { code: 500, message: error.message ?? 'Unknown error occurred' }
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// Process Resolve DID request.
|
|
406
|
+
if (isDidRequest(request, DidInterface.Resolve)) {
|
|
407
|
+
const { didUri, options } = request.messageParams;
|
|
408
|
+
const resolutionResult = await this.resolve(didUri, options);
|
|
409
|
+
const response: DidResponse<typeof request.messageType> = {
|
|
410
|
+
result : resolutionResult,
|
|
411
|
+
ok : true,
|
|
412
|
+
status : { code: 200, message: 'OK' }
|
|
413
|
+
};
|
|
414
|
+
return response;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
throw new Error(`AgentDidApi: Unsupported request type: ${request.messageType}`);
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
private getMethod(methodName: string): DidMethodApi {
|
|
421
|
+
const didMethodApi = this._didMethods.get(methodName);
|
|
422
|
+
|
|
423
|
+
if (didMethodApi === undefined) {
|
|
424
|
+
throw new Error(`DID Method not supported: ${methodName}`);
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
return didMethodApi;
|
|
428
|
+
}
|
|
429
|
+
}
|