@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
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// ! TODO : Make sure I remove `@noble/ciphers` from the Agent package.json once this is moved to the `@enbox/crypto` package.
|
|
2
|
+
import { getWebcryptoSubtle } from '@noble/ciphers/webcrypto';
|
|
3
|
+
|
|
4
|
+
import { Convert } from '@enbox/common';
|
|
5
|
+
import { DeriveKeyBytesParams } from '../types/params-direct.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The object that should be passed into `Hkdf.deriveKey()`, when using the HKDF algorithm.
|
|
9
|
+
*/
|
|
10
|
+
export type HkdfParams = {
|
|
11
|
+
/**
|
|
12
|
+
* A string representing the digest algorithm to use. This may be one of:
|
|
13
|
+
* - 'SHA-256'
|
|
14
|
+
* - 'SHA-384'
|
|
15
|
+
* - 'SHA-512'
|
|
16
|
+
*/
|
|
17
|
+
hash: 'SHA-256' | 'SHA-384' | 'SHA-512';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The salt value to use in the derivation process.
|
|
21
|
+
*
|
|
22
|
+
* Ideally, the salt is a random or pseudo-random value with the same length as the output of the
|
|
23
|
+
* digest function. Unlike the input key material passed into deriveKey(), salt does not need to
|
|
24
|
+
* be kept secret.
|
|
25
|
+
*
|
|
26
|
+
* Note: The {@link https://datatracker.ietf.org/doc/html/rfc5869 | HKDF specification} states
|
|
27
|
+
* that adding salt "adds significantly to the strength of HKDF".
|
|
28
|
+
*/
|
|
29
|
+
salt: string | Uint8Array;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Optional application-specific information to use in the HKDF.
|
|
33
|
+
*
|
|
34
|
+
* If given, this value is used to bind the derived key to application-specific contextual
|
|
35
|
+
* information. This makes it possible to derive different keys for different contexts while using
|
|
36
|
+
* the same input key material.
|
|
37
|
+
*
|
|
38
|
+
* If not provided, the `info` value is set to an empty array.
|
|
39
|
+
*
|
|
40
|
+
* Note: It is important that the `info` value be independent and unrelated to the input key
|
|
41
|
+
* material.
|
|
42
|
+
*/
|
|
43
|
+
info?: string | Uint8Array,
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The `Hkdf` class provides an interface for HMAC-based Extract-and-Expand Key Derivation Function (HKDF)
|
|
48
|
+
* as defined in RFC 5869.
|
|
49
|
+
*
|
|
50
|
+
* Note: The `baseKeyBytes` that will be the input key material for HKDF should be a high-entropy secret
|
|
51
|
+
* value, such as a cryptographic key. It should be kept confidential and not be derived from a
|
|
52
|
+
* low-entropy value, such as a password.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* const info = new Uint8Array([...]);
|
|
57
|
+
* const derivedKeyBytes = await Hkdf.deriveKeyBytes({
|
|
58
|
+
* baseKeyBytes: new Uint8Array([...]), // Input keying material
|
|
59
|
+
* hash: 'SHA-256', // The hash function to use ('SHA-256', 'SHA-384', 'SHA-512')
|
|
60
|
+
* salt: new Uint8Array([...]), // The salt value
|
|
61
|
+
* info: new Uint8Array([...]), // Optional application-specific information
|
|
62
|
+
* length: 256 // The length of the derived key in bits
|
|
63
|
+
* });
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export class Hkdf {
|
|
67
|
+
/**
|
|
68
|
+
* Derives a key using the HMAC-based Extract-and-Expand Key Derivation Function (HKDF).
|
|
69
|
+
*
|
|
70
|
+
* This method generates a derived key using a hash function from input keying material given as
|
|
71
|
+
* `baseKeyBytes`. The length of the derived key can be specified. Optionally, it can also use a salt
|
|
72
|
+
* and info for the derivation process.
|
|
73
|
+
*
|
|
74
|
+
* HKDF is useful in various cryptographic applications and protocols, especially when
|
|
75
|
+
* there's a need to derive multiple keys from a single source of key material.
|
|
76
|
+
*
|
|
77
|
+
* Note: The `baseKeyBytes` that will be the input key material for HKDF should be a high-entropy
|
|
78
|
+
* secret value, such as a cryptographic key. It should be kept confidential and not be derived
|
|
79
|
+
* from a low-entropy value, such as a password.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```ts
|
|
83
|
+
* const info = new Uint8Array([...]);
|
|
84
|
+
* const derivedKeyBytes = await Hkdf.deriveKeyBytes({
|
|
85
|
+
* baseKeyBytes: new Uint8Array([...]), // Input keying material
|
|
86
|
+
* hash: 'SHA-256', // The hash function to use ('SHA-256', 'SHA-384', 'SHA-512')
|
|
87
|
+
* salt: new Uint8Array([...]), // The salt value
|
|
88
|
+
* info: new Uint8Array([...]), // Optional application-specific information
|
|
89
|
+
* length: 256 // The length of the derived key in bits
|
|
90
|
+
* });
|
|
91
|
+
* ```
|
|
92
|
+
*
|
|
93
|
+
* @param params - The parameters for key derivation.
|
|
94
|
+
* @returns A Promise that resolves to the derived key as a byte array.
|
|
95
|
+
*/
|
|
96
|
+
public static async deriveKeyBytes({ baseKeyBytes, length, hash, salt, info = new Uint8Array() }:
|
|
97
|
+
DeriveKeyBytesParams & HkdfParams
|
|
98
|
+
): Promise<Uint8Array> {
|
|
99
|
+
// Get the Web Crypto API interface.
|
|
100
|
+
const webCrypto = getWebcryptoSubtle() as SubtleCrypto;
|
|
101
|
+
|
|
102
|
+
// Import the baseKeyBytes into the Web Crypto API to use for the key derivation operation.
|
|
103
|
+
const webCryptoKey = await webCrypto.importKey('raw', baseKeyBytes, { name: 'HKDF' }, false, ['deriveBits']);
|
|
104
|
+
|
|
105
|
+
// Convert the salt and info to Uint8Array if they are provided as strings.
|
|
106
|
+
salt = typeof salt === 'string' ? Convert.string(salt).toUint8Array() : salt;
|
|
107
|
+
info = typeof info === 'string' ? Convert.string(info).toUint8Array() : info;
|
|
108
|
+
|
|
109
|
+
// Derive the bytes using the Web Crypto API.
|
|
110
|
+
const derivedKeyBuffer = await crypto.subtle.deriveBits(
|
|
111
|
+
{ name: 'HKDF', hash, salt, info },
|
|
112
|
+
webCryptoKey,
|
|
113
|
+
length
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
// Convert from ArrayBuffer to Uint8Array.
|
|
117
|
+
const derivedKeyBytes = new Uint8Array(derivedKeyBuffer);
|
|
118
|
+
|
|
119
|
+
return derivedKeyBytes;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// ! TODO : Make sure I remove `@noble/ciphers` from the Agent package.json once this is moved to the `@enbox/crypto` package.
|
|
2
|
+
import { getWebcryptoSubtle } from '@noble/ciphers/webcrypto';
|
|
3
|
+
|
|
4
|
+
import type { DeriveKeyBytesParams } from '../types/params-direct.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The object that should be passed into `Pbkdf2.deriveKeyBytes()`, when using the PBKDF2 algorithm.
|
|
8
|
+
*/
|
|
9
|
+
export interface Pbkdf2Params {
|
|
10
|
+
/**
|
|
11
|
+
* A string representing the digest algorithm to use. This may be one of:
|
|
12
|
+
* - 'SHA-256'
|
|
13
|
+
* - 'SHA-384'
|
|
14
|
+
* - 'SHA-512'
|
|
15
|
+
*/
|
|
16
|
+
hash: 'SHA-256' | 'SHA-384' | 'SHA-512';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The salt value to use in the derivation process, as a Uint8Array. This should be a random or
|
|
20
|
+
* pseudo-random value of at least 16 bytes. Unlike the `password`, `salt` does not need to be
|
|
21
|
+
* kept secret.
|
|
22
|
+
*/
|
|
23
|
+
salt: Uint8Array;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* A `Number` representing the number of iterations the hash function will be executed in
|
|
27
|
+
* `deriveKey()`. This impacts the computational cost of the `deriveKey()` operation, making it
|
|
28
|
+
* more resistant to dictionary attacks. The higher the number, the more secure, but also slower,
|
|
29
|
+
* the operation. Choose a value that balances security needs and performance for your
|
|
30
|
+
* application.
|
|
31
|
+
*/
|
|
32
|
+
iterations: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The `Pbkdf2` class provides a secure way to derive cryptographic keys from a password
|
|
37
|
+
* using the PBKDF2 (Password-Based Key Derivation Function 2) algorithm.
|
|
38
|
+
*
|
|
39
|
+
* The PBKDF2 algorithm is widely used for generating keys from passwords, as it applies
|
|
40
|
+
* a pseudorandom function to the input password along with a salt value and iterates the
|
|
41
|
+
* process multiple times to increase the key's resistance to brute-force attacks.
|
|
42
|
+
*
|
|
43
|
+
* Notes:
|
|
44
|
+
* - The `baseKeyBytes` that will be the input key material for PBKDF2 is expected to be a low-entropy
|
|
45
|
+
* value, such as a password or passphrase. It should be kept confidential.
|
|
46
|
+
* - In 2023, {@link https://web.archive.org/web/20230123232056/https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html#pbkdf2 | OWASP recommended}
|
|
47
|
+
* a minimum of 600,000 iterations for PBKDF2-HMAC-SHA256 and 210,000 for PBKDF2-HMAC-SHA512.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* // Key Derivation
|
|
52
|
+
* const derivedKeyBytes = await Pbkdf2.deriveKeyBytes({
|
|
53
|
+
* baseKeyBytes: new TextEncoder().encode('password'), // The password as a Uint8Array
|
|
54
|
+
* hash: 'SHA-256', // The hash function to use ('SHA-256', 'SHA-384', 'SHA-512')
|
|
55
|
+
* salt: new Uint8Array([...]), // The salt value
|
|
56
|
+
* iterations: 600_000, // The number of iterations
|
|
57
|
+
* length: 256 // The length of the derived key in bits
|
|
58
|
+
* });
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* @remarks
|
|
62
|
+
* This class relies on the availability of the Web Crypto API.
|
|
63
|
+
*/
|
|
64
|
+
export class Pbkdf2 {
|
|
65
|
+
/**
|
|
66
|
+
* Derives a cryptographic key from a password using the PBKDF2 algorithm.
|
|
67
|
+
*
|
|
68
|
+
* @remarks
|
|
69
|
+
* This method applies the PBKDF2 algorithm to the provided password along with
|
|
70
|
+
* a salt value and iterates the process a specified number of times. It uses
|
|
71
|
+
* a cryptographic hash function to enhance security and produce a key of the
|
|
72
|
+
* desired length. The method is capable of utilizing either the Web Crypto API
|
|
73
|
+
* or the Node.js Crypto module, depending on the environment's support.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* const derivedKeyBytes = await Pbkdf2.deriveKeyBytes({
|
|
78
|
+
* baseKeyBytes: new TextEncoder().encode('password'), // The password as a Uint8Array
|
|
79
|
+
* hash: 'SHA-256', // The hash function to use ('SHA-256', 'SHA-384', 'SHA-512')
|
|
80
|
+
* salt: new Uint8Array([...]), // The salt value
|
|
81
|
+
* iterations: 600_000, // The number of iterations
|
|
82
|
+
* length: 256 // The length of the derived key in bits
|
|
83
|
+
* });
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
86
|
+
* @param params - The parameters for key derivation.
|
|
87
|
+
* @returns A Promise that resolves to the derived key as a byte array.
|
|
88
|
+
*/
|
|
89
|
+
public static async deriveKeyBytes({ baseKeyBytes, hash, salt, iterations, length }:
|
|
90
|
+
DeriveKeyBytesParams & Pbkdf2Params
|
|
91
|
+
): Promise<Uint8Array> {
|
|
92
|
+
// Get the Web Crypto API interface.
|
|
93
|
+
const webCrypto = getWebcryptoSubtle() as SubtleCrypto;
|
|
94
|
+
|
|
95
|
+
// Import the password as a raw key for use with the Web Crypto API.
|
|
96
|
+
const webCryptoKey = await webCrypto.importKey(
|
|
97
|
+
'raw', // key format is raw bytes
|
|
98
|
+
baseKeyBytes, // key data to import
|
|
99
|
+
{ name: 'PBKDF2' }, // algorithm identifier
|
|
100
|
+
false, // key is not extractable
|
|
101
|
+
['deriveBits'] // key usages
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
// Derive the bytes using the Web Crypto API.
|
|
105
|
+
const derivedKeyBuffer = await webCrypto.deriveBits(
|
|
106
|
+
{ name: 'PBKDF2', hash, salt, iterations },
|
|
107
|
+
webCryptoKey,
|
|
108
|
+
length
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
// Convert from ArrayBuffer to Uint8Array.
|
|
112
|
+
const derivedKeyBytes = new Uint8Array(derivedKeyBuffer);
|
|
113
|
+
|
|
114
|
+
return derivedKeyBytes;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type InferCipherAlgorithm<T> = 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;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Jwk,
|
|
3
|
+
CryptoApi as OldCryptoApi,
|
|
4
|
+
KeyWrapper,
|
|
5
|
+
SignParams,
|
|
6
|
+
DigestParams,
|
|
7
|
+
VerifyParams,
|
|
8
|
+
GenerateKeyParams,
|
|
9
|
+
GetPublicKeyParams,
|
|
10
|
+
Cipher,
|
|
11
|
+
} from '@enbox/crypto';
|
|
12
|
+
|
|
13
|
+
import type { KeyConverter } from './key-converter.js';
|
|
14
|
+
import type { AsymmetricKeyConverter } from './key-converter.js';
|
|
15
|
+
import type { KeyBytesDeriver, KeyDeriver } from './key-deriver.js';
|
|
16
|
+
import type { BytesToPrivateKeyParams, BytesToPublicKeyParams, CipherParams, DeriveKeyBytesParams, DeriveKeyParams, PrivateKeyToBytesParams, PublicKeyToBytesParams, UnwrapKeyParams, WrapKeyParams } from './params-direct.js';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The `DsaApi` interface integrates key generation, hashing, and signing functionalities,
|
|
20
|
+
* designed for use with a Key Management System (KMS). It extends `AsymmetricKeyGenerator` for
|
|
21
|
+
* generating asymmetric keys, `Hasher` for hash digest computations, and `Signer` for signing and
|
|
22
|
+
* verifying operations.
|
|
23
|
+
*
|
|
24
|
+
* Concrete implementations of this interface are intended to be used with a KMS, which is
|
|
25
|
+
* responsible for generating and storing cryptographic keys. The KMS is also responsible for
|
|
26
|
+
* performing cryptographic operations using the keys it manages. The KMS is typically a cloud
|
|
27
|
+
* service, but it can also be a hardware device or software application.
|
|
28
|
+
*
|
|
29
|
+
* Guidelines for implementing this interface:
|
|
30
|
+
* - Must use JSON Web Keys ({@link Jwk | JWK}) as the key format.
|
|
31
|
+
* - Must IANA registered JSON Object Signing and Encryption
|
|
32
|
+
* {@ link https://www.iana.org/assignments/jose/jose.xhtml#web-signature-encryption-algorithms | (JOSE)}
|
|
33
|
+
* names for algorithm, curves, etc. whenever possible.
|
|
34
|
+
* - All I/O that interacts with private or secret keys must be done via reference using a
|
|
35
|
+
* {@link KeyIdentifier | `KeyIdentifier`}. Implementations can use any string as the key
|
|
36
|
+
* identifier (e.g. JWK thumbprint, UUID generated by hosted KMS, etc.).
|
|
37
|
+
* - Must support key generation, hashing, signing, and verifying operations.
|
|
38
|
+
* - May be extended to support other cryptographic operations.
|
|
39
|
+
* - Implementations of the `DsaApi` interface can be passed as an argument to the public API
|
|
40
|
+
* methods of Web5 libraries that involve key material (e.g., DID creation, VC signing, arbitrary
|
|
41
|
+
* data signing/verification, etc.).
|
|
42
|
+
*/
|
|
43
|
+
export interface DsaApi<
|
|
44
|
+
GenerateKeyInput = GenerateKeyParams,
|
|
45
|
+
GenerateKeyOutput = Jwk,
|
|
46
|
+
GetPublicKeyInput = GetPublicKeyParams,
|
|
47
|
+
DigestInput = DigestParams,
|
|
48
|
+
SignInput = SignParams,
|
|
49
|
+
VerifyInput = VerifyParams
|
|
50
|
+
> extends OldCryptoApi<GenerateKeyInput, GenerateKeyOutput, GetPublicKeyInput, DigestInput, SignInput, VerifyInput> {}
|
|
51
|
+
|
|
52
|
+
export interface CryptoApi<
|
|
53
|
+
GenerateKeyInput = GenerateKeyParams,
|
|
54
|
+
GenerateKeyOutput = Jwk,
|
|
55
|
+
GetPublicKeyInput = GetPublicKeyParams,
|
|
56
|
+
DigestInput = DigestParams,
|
|
57
|
+
SignInput = SignParams,
|
|
58
|
+
VerifyInput = VerifyParams,
|
|
59
|
+
EncryptInput = CipherParams,
|
|
60
|
+
DecryptInput = CipherParams,
|
|
61
|
+
BytesToPublicKeyInput = BytesToPublicKeyParams,
|
|
62
|
+
PublicKeyToBytesInput = PublicKeyToBytesParams,
|
|
63
|
+
BytesToPrivateKeyInput = BytesToPrivateKeyParams,
|
|
64
|
+
PrivateKeyToBytesInput = PrivateKeyToBytesParams,
|
|
65
|
+
DeriveKeyInput = DeriveKeyParams,
|
|
66
|
+
DeriveKeyOutput = Jwk,
|
|
67
|
+
DeriveKeyBytesInput = DeriveKeyBytesParams,
|
|
68
|
+
DeriveKeyBytesOutput = Uint8Array,
|
|
69
|
+
WrapKeyInput = WrapKeyParams,
|
|
70
|
+
UnwrapKeyInput = UnwrapKeyParams
|
|
71
|
+
> extends
|
|
72
|
+
DsaApi<GenerateKeyInput, GenerateKeyOutput, GetPublicKeyInput, DigestInput, SignInput, VerifyInput>,
|
|
73
|
+
Cipher<EncryptInput, DecryptInput>,
|
|
74
|
+
AsymmetricKeyConverter<BytesToPublicKeyInput, PublicKeyToBytesInput>,
|
|
75
|
+
KeyConverter<BytesToPrivateKeyInput, PrivateKeyToBytesInput>,
|
|
76
|
+
KeyDeriver<DeriveKeyInput, DeriveKeyOutput>,
|
|
77
|
+
KeyBytesDeriver<DeriveKeyBytesInput, DeriveKeyBytesOutput>,
|
|
78
|
+
KeyWrapper<WrapKeyInput, UnwrapKeyInput> {}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { Jwk } from '@enbox/crypto';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* `KeyConverter` interface for converting private keys between byte array and JWK formats.
|
|
5
|
+
*/
|
|
6
|
+
export interface KeyConverter<BytesToPrivateKeyInput, PrivateKeyToBytesInput> {
|
|
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: BytesToPrivateKeyInput): Promise<Jwk>;
|
|
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: PrivateKeyToBytesInput): Promise<Uint8Array>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* `AsymmetricKeyConverter` interface extends {@link KeyConverter |`KeyConverter`}, adding support
|
|
31
|
+
* for public key conversions.
|
|
32
|
+
*/
|
|
33
|
+
export interface AsymmetricKeyConverter<BytesToPublicKeyInput, PublicKeyToBytesInput> {
|
|
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: BytesToPublicKeyInput): Promise<Jwk>;
|
|
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: PublicKeyToBytesInput): Promise<Uint8Array>;
|
|
53
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `KeyDeriver` interface provide a method for key derivation.
|
|
3
|
+
*
|
|
4
|
+
* The `deriveKey()` method derives a {@link Jwk | JWK} from input data using the specified key
|
|
5
|
+
* derivation algorithm. This interface is designed to support various key derivation
|
|
6
|
+
* algorithms, accommodating different input and output types.
|
|
7
|
+
*/
|
|
8
|
+
export interface KeyDeriver<
|
|
9
|
+
DeriveKeyInput,
|
|
10
|
+
DeriveKeyOutput,
|
|
11
|
+
> {
|
|
12
|
+
/**
|
|
13
|
+
* Derives a cryptographic key in JWK format based on the provided input parameters.
|
|
14
|
+
*
|
|
15
|
+
* @remarks
|
|
16
|
+
* The `deriveKey()` method of the {@link KeyDeriver | `KeyDeriver`} interface is utilized to
|
|
17
|
+
* generate cryptographic keys for operations like encryption, decryption, or signing. The method
|
|
18
|
+
* takes in parameters tailored to the key derivation algorithm being used and returns a promise
|
|
19
|
+
* that resolves to the derived key.
|
|
20
|
+
*
|
|
21
|
+
* @param params - The parameters for the key derivation process, specific to the chosen
|
|
22
|
+
* algorithm.
|
|
23
|
+
*
|
|
24
|
+
* @returns A Promise resolving to the derived key in the specified output format.
|
|
25
|
+
*/
|
|
26
|
+
deriveKey(params: DeriveKeyInput): Promise<DeriveKeyOutput>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The `KeyBytesDeriver` interface provide a method for deriving a byte array using a key derivation
|
|
31
|
+
* algorithm.
|
|
32
|
+
*
|
|
33
|
+
* The `deriveKeyBytes()` method to derives cryptographic bits from input data using the specified
|
|
34
|
+
* key derivation algorithm. This interface is designed to support various key derivation
|
|
35
|
+
* algorithms, accommodating different input and output types.
|
|
36
|
+
*/
|
|
37
|
+
export interface KeyBytesDeriver<
|
|
38
|
+
DeriveKeyBytesInput,
|
|
39
|
+
DeriveKeyBytesOutput
|
|
40
|
+
> {
|
|
41
|
+
/**
|
|
42
|
+
* Generates a specified number of cryptographic bits from given input parameters.
|
|
43
|
+
*
|
|
44
|
+
* @remarks
|
|
45
|
+
* The `deriveKeyBytes()` method of the {@link KeyBytesDeriver | `KeyBytesDeriver`} interface is
|
|
46
|
+
* used to create cryptographic material such as initialization vectors or keys from various
|
|
47
|
+
* sources. The method takes in parameters specific to the chosen key derivation algorithm and
|
|
48
|
+
* outputs a promise that resolves to a `Uint8Array` containing the derived bits.
|
|
49
|
+
*
|
|
50
|
+
* @param params - The parameters for the key derivation process, specific to the chosen
|
|
51
|
+
* algorithm.
|
|
52
|
+
*
|
|
53
|
+
* @returns A Promise resolving to the derived bits in the specified format.
|
|
54
|
+
*/
|
|
55
|
+
deriveKeyBytes(params: DeriveKeyBytesInput): Promise<DeriveKeyBytesOutput>;
|
|
56
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { Jwk } from '@enbox/crypto';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The `KeyExporter` interface provides a method for exporting cryptographic keys.
|
|
5
|
+
*/
|
|
6
|
+
export interface KeyExporter<ExportKeyInput, ExportKeyOutput = Jwk> {
|
|
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<ExportKeyOutput>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The `KeyImporter` interface provides a method for importing cryptographic keys.
|
|
23
|
+
*/
|
|
24
|
+
export interface KeyImporter<ImportKeyInput, ImportKeyOutput = void> {
|
|
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<ImportKeyOutput>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface KeyDeleter<DeleteKeyInput> {
|
|
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<void>;
|
|
51
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
KeyIdentifier,
|
|
3
|
+
KmsSignParams,
|
|
4
|
+
KmsDigestParams,
|
|
5
|
+
KmsVerifyParams,
|
|
6
|
+
KmsGetKeyUriParams,
|
|
7
|
+
KmsGenerateKeyParams,
|
|
8
|
+
KmsGetPublicKeyParams,
|
|
9
|
+
} from '@enbox/crypto';
|
|
10
|
+
|
|
11
|
+
import type { DsaApi } from './crypto-api.js';
|
|
12
|
+
import type { KmsCipherParams } from './params-kms.js';
|
|
13
|
+
// import type { Web5PlatformAgent } from '../../../types/agent.js';
|
|
14
|
+
|
|
15
|
+
export interface KeyManagerParams {
|
|
16
|
+
CipherInput?: unknown;
|
|
17
|
+
GenerateKeyInput?: unknown;
|
|
18
|
+
GenerateKeyOutput?: unknown;
|
|
19
|
+
GetPublicKeyInput?: unknown;
|
|
20
|
+
SignInput?: unknown;
|
|
21
|
+
VerifyInput?: unknown;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface DefaultKeyManagerParams {
|
|
25
|
+
CipherInput: KmsCipherParams;
|
|
26
|
+
GenerateKeyInput: KmsGenerateKeyParams;
|
|
27
|
+
GenerateKeyOutput: KeyIdentifier;
|
|
28
|
+
GetPublicKeyInput: KmsGetPublicKeyParams;
|
|
29
|
+
SignInput: KmsSignParams;
|
|
30
|
+
VerifyInput: KmsVerifyParams;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The `KeyManager` interface integrates key generation and signing capabilities.
|
|
35
|
+
*
|
|
36
|
+
* Concrete implementations of this interface are intended to be used as a Key Management System
|
|
37
|
+
* (KMS), which is responsible for generating and storing cryptographic keys. The KMS is also
|
|
38
|
+
* responsible for performing cryptographic operations using the keys it manages. The KMS can be
|
|
39
|
+
* a local software based KMS, a cloud service, or a hardware device.
|
|
40
|
+
*
|
|
41
|
+
* Guidelines for implementing this interface:
|
|
42
|
+
* - Must use JSON Web Keys ({@link Jwk | JWK}) as the key format.
|
|
43
|
+
* - Must IANA registered JSON Object Signing and Encryption
|
|
44
|
+
* {@ link https://www.iana.org/assignments/jose/jose.xhtml#web-signature-encryption-algorithms | (JOSE)}
|
|
45
|
+
* names for algorithm, curves, etc. whenever possible.
|
|
46
|
+
* - All I/O that interacts with private or secret keys must be done via reference using a
|
|
47
|
+
* {@link KeyIdentifier | `KeyIdentifier`}. Implementations can use any string as the key
|
|
48
|
+
* identifier (e.g. JWK thumbprint, UUID generated by hosted KMS, etc.).
|
|
49
|
+
* - Must support key generation an signing operations.
|
|
50
|
+
* - May be extended to support other cryptographic operations.
|
|
51
|
+
* - Implementations of the `CryptoApi` interface can be passed as an argument to the public API
|
|
52
|
+
* methods of Web5 libraries that involve key material (e.g., DID creation, VC signing, arbitrary
|
|
53
|
+
* data signing/verification, etc.).
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* // Example of using the KeyManager interface with default types
|
|
58
|
+
* class DefaultKeyManager implements KeyManager {} // Uses default types
|
|
59
|
+
*
|
|
60
|
+
* // Example of using the KeyManager interface with custom types
|
|
61
|
+
* class CustomKeyManager implements KeyManager<{
|
|
62
|
+
* GenerateKeyInput: CustomGenerateKeyParams, // Custom type
|
|
63
|
+
* KmsGetPublicKeyParams: CustomGetPublicKeyParams, // Custom type
|
|
64
|
+
* KmsSignParams: CustomSignParams, // Custom type
|
|
65
|
+
* // Omitting KmsVerifyParams to use the default
|
|
66
|
+
* }> {
|
|
67
|
+
* // Implementation here
|
|
68
|
+
* }
|
|
69
|
+
* ```
|
|
70
|
+
*
|
|
71
|
+
* @typeParam T - The type of the key manager parameters.
|
|
72
|
+
*/
|
|
73
|
+
export interface KeyManager<T extends KeyManagerParams = DefaultKeyManagerParams>
|
|
74
|
+
extends DsaApi<T['GenerateKeyInput'], T['GenerateKeyOutput'], T['GetPublicKeyInput'], KmsDigestParams, T['SignInput'], T['VerifyInput']> {
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
*
|
|
78
|
+
* @param params - The parameters for getting the key URI.
|
|
79
|
+
* @param params.key - The key to get the URI for.
|
|
80
|
+
* @returns The key URI.
|
|
81
|
+
*/
|
|
82
|
+
getKeyUri(params: KmsGetKeyUriParams): Promise<KeyIdentifier>;
|
|
83
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type InferKeyUnwrapAlgorithm<T> = 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;
|