@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,135 @@
|
|
|
1
|
+
import type { Jwk, KeyIdentifier } from '@enbox/crypto';
|
|
2
|
+
import type { CryptoApi } from '../types/crypto-api.js';
|
|
3
|
+
import type { KeyManager } from '../types/key-manager.js';
|
|
4
|
+
import type { JweDecryptOptions, JweEncryptOptions, JweHeaderParams } from './jwe.js';
|
|
5
|
+
/**
|
|
6
|
+
* Parameters required for decrypting a JWE in Compact Serialization format.
|
|
7
|
+
*
|
|
8
|
+
* @typeParam TKeyManager - The Key Manager used to manage cryptographic keys.
|
|
9
|
+
* @typeParam TCrypto - The Crypto API used to perform cryptographic operations.
|
|
10
|
+
*/
|
|
11
|
+
export interface CompactJweDecryptParams<TKeyManager, TCrypto> {
|
|
12
|
+
/** The JWE string in Compact Serialization format. */
|
|
13
|
+
jwe: string;
|
|
14
|
+
/**
|
|
15
|
+
* The decryption key which can be a Key Identifier such as a KMS key URI, a JSON Web Key (JWK),
|
|
16
|
+
* or raw key material represented as a byte array.
|
|
17
|
+
*/
|
|
18
|
+
key: KeyIdentifier | Jwk | Uint8Array;
|
|
19
|
+
/** Key Manager instanceß responsible for managing cryptographic keys. */
|
|
20
|
+
keyManager?: TKeyManager;
|
|
21
|
+
/** Crypto API instance that provides the necessary cryptographic operations. */
|
|
22
|
+
crypto?: TCrypto;
|
|
23
|
+
/** {@inheritDoc JweDecryptOptions} */
|
|
24
|
+
options?: JweDecryptOptions;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Result of decrypting a JWE in Compact Serialization format.
|
|
28
|
+
*/
|
|
29
|
+
export interface CompactJweDecryptResult {
|
|
30
|
+
/** Decrypted plaintext as a byte array. */
|
|
31
|
+
plaintext: Uint8Array;
|
|
32
|
+
/** The protected header of the JWE. */
|
|
33
|
+
protectedHeader: JweHeaderParams;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Parameters required for encrypting data into a JWE in Compact Serialization format.
|
|
37
|
+
*
|
|
38
|
+
* @typeParam TKeyManager - The Key Manager used to manage cryptographic keys.
|
|
39
|
+
* @typeParam TCrypto - The Crypto API used to perform cryptographic operations.
|
|
40
|
+
*/
|
|
41
|
+
export interface CompactJweEncryptParams<TKeyManager, TCrypto> {
|
|
42
|
+
/** The plaintext data to be encrypted as a byte array. */
|
|
43
|
+
plaintext: Uint8Array;
|
|
44
|
+
/** JWE Protected Header containing encryption algorithm details. */
|
|
45
|
+
protectedHeader: JweHeaderParams;
|
|
46
|
+
/**
|
|
47
|
+
* The encryption key which can be a Key Identifier such as a KMS key URI, a JSON Web Key (JWK),
|
|
48
|
+
* or raw key material represented as a byte array.
|
|
49
|
+
*/
|
|
50
|
+
key: KeyIdentifier | Jwk | Uint8Array;
|
|
51
|
+
/** Key Manager instanceß responsible for managing cryptographic keys. */
|
|
52
|
+
keyManager?: TKeyManager;
|
|
53
|
+
/** Crypto API instance that provides the necessary cryptographic operations. */
|
|
54
|
+
crypto?: TCrypto;
|
|
55
|
+
/** {@inheritDoc JweEncryptOptions} */
|
|
56
|
+
options?: JweEncryptOptions;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The `CompactJwe` class facilitates encryption and decryption processes using the JSON Web
|
|
60
|
+
* Encryption (JWE) Compact Serialization format. This class adheres to the specifications
|
|
61
|
+
* outlined in {@link https://datatracker.ietf.org/doc/html/rfc7516 | RFC 7516}, enabling secure
|
|
62
|
+
* data encapsulation through various cryptographic algorithms.
|
|
63
|
+
*
|
|
64
|
+
* Compact Serialization is a space-efficient representation of JWE, suitable for contexts
|
|
65
|
+
* where verbose data structures are impractical, such as HTTP headers. It provides mechanisms to
|
|
66
|
+
* encrypt content and protect its integrity with authenticated encryption, ensuring
|
|
67
|
+
* confidentiality, authenticity, and non-repudiation.
|
|
68
|
+
*
|
|
69
|
+
* This class supports the following operations:
|
|
70
|
+
* - Decrypting data from a compact serialized JWE string.
|
|
71
|
+
* - Encrypting data and producing a compact serialized JWE string.
|
|
72
|
+
*
|
|
73
|
+
* Usage involves specifying the cryptographic details, such as keys and algorithms, and the class
|
|
74
|
+
* handles the complexities of the JWE processing, including parsing, validating, and applying the
|
|
75
|
+
* cryptographic operations defined in the JWE specification.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* // Example usage of encrypt method
|
|
80
|
+
* const plaintext = new TextEncoder().encode("Secret Message");
|
|
81
|
+
* const key = { kty: "oct", k: "your-secret-key" }; // Example symmetric key
|
|
82
|
+
* const protectedHeader = { alg: "dir", enc: "A256GCM" };
|
|
83
|
+
* const encryptedJweString = await CompactJwe.encrypt({
|
|
84
|
+
* plaintext,
|
|
85
|
+
* protectedHeader,
|
|
86
|
+
* key,
|
|
87
|
+
* });
|
|
88
|
+
* console.log(encryptedJweString); // Outputs the JWE string in Compact Serialization format
|
|
89
|
+
* ```
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* // Example usage of decrypt method
|
|
94
|
+
* const jweString = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."; // A JWE in Compact Serialization
|
|
95
|
+
* const decryptionKey = { kty: "oct", k: "your-secret-key" }; // The key must match the one used for encryption
|
|
96
|
+
* const { plaintext, protectedHeader } = await CompactJwe.decrypt({
|
|
97
|
+
* jwe: jweString,
|
|
98
|
+
* key: decryptionKey,
|
|
99
|
+
* });
|
|
100
|
+
* console.log(new TextDecoder().decode(plaintext)); // Outputs the decrypted message
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
export declare class CompactJwe {
|
|
104
|
+
/**
|
|
105
|
+
* Decrypts a JWE string in Compact Serialization format, extracting the plaintext and
|
|
106
|
+
* reconstructing the JWE Protected Header.
|
|
107
|
+
*
|
|
108
|
+
* This method parses the compact JWE, validates its structure, and applies the appropriate
|
|
109
|
+
* decryption algorithm as specified in the JWE Protected Header. It returns the decrypted
|
|
110
|
+
* plaintext along with the reconstructed protected header, ensuring the data's authenticity
|
|
111
|
+
* and integrity.
|
|
112
|
+
*
|
|
113
|
+
* @param params - The decryption parameters including the JWE string, cryptographic key, and
|
|
114
|
+
* optional instances of Key Manager and Crypto API.
|
|
115
|
+
* @returns A promise resolving to the decrypted content and the JWE Protected Header.
|
|
116
|
+
* @throws {@link CryptoError} if the JWE format is invalid or decryption fails.
|
|
117
|
+
*/
|
|
118
|
+
static decrypt<TKeyManager extends KeyManager | undefined = KeyManager, TCrypto extends CryptoApi | undefined = CryptoApi>({ jwe, key, keyManager, crypto, options }: CompactJweDecryptParams<TKeyManager, TCrypto>): Promise<CompactJweDecryptResult>;
|
|
119
|
+
/**
|
|
120
|
+
* Encrypts plaintext to a JWE string in Compact Serialization format, encapsulating the content
|
|
121
|
+
* with the specified cryptographic protections.
|
|
122
|
+
*
|
|
123
|
+
* It constructs the JWE by encrypting the plaintext, then serializing the output to the
|
|
124
|
+
* compact format, which includes concatenating various components like the protected header,
|
|
125
|
+
* encrypted key, initialization vector, ciphertext, and authentication tag.
|
|
126
|
+
*
|
|
127
|
+
* @param params - The encryption parameters, including plaintext, JWE Protected Header,
|
|
128
|
+
* cryptographic key, and optional Key Manager and Crypto API instances.
|
|
129
|
+
* @returns A promise that resolves to a string representing the JWE in Compact Serialization
|
|
130
|
+
* format.
|
|
131
|
+
* @throws {@link CryptoError} if encryption fails or the input parameters are invalid.
|
|
132
|
+
*/
|
|
133
|
+
static encrypt<TKeyManager extends KeyManager | undefined = KeyManager, TCrypto extends CryptoApi | undefined = CryptoApi>({ plaintext, protectedHeader, key, keyManager, crypto, options }: CompactJweEncryptParams<TKeyManager, TCrypto>): Promise<string>;
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=jwe-compact.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jwe-compact.d.ts","sourceRoot":"","sources":["../../../../../src/prototyping/crypto/jose/jwe-compact.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAIxD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAOtF;;;;;GAKG;AACH,MAAM,WAAW,uBAAuB,CAAC,WAAW,EAAE,OAAO;IAC3D,sDAAsD;IACtD,GAAG,EAAE,MAAM,CAAC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,SAAS,GAAG,SAAS,GAAG,SAAS,EACjD,EACA,SAAS,EACT,eAAe,EACf,GAAG,EACH,UAAkC,EAClC,MAA6B,EAC7B,OAAY,EACb,EAAE,uBAAuB,CAAC,WAAW,EAAE,OAAO,CAAC,GAC7C,OAAO,CAAC,MAAM,CAAC;CAQnB"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import type { Jwk, KeyIdentifier } from '@enbox/crypto';
|
|
2
|
+
import type { CryptoApi } from '../types/crypto-api.js';
|
|
3
|
+
import type { KeyManager } from '../types/key-manager.js';
|
|
4
|
+
import type { JweDecryptOptions, JweEncryptOptions, JweHeaderParams } from './jwe.js';
|
|
5
|
+
/**
|
|
6
|
+
* Parameters required for decrypting a flattened JWE.
|
|
7
|
+
*
|
|
8
|
+
* @typeParam TKeyManager - The Key Manager used to manage cryptographic keys.
|
|
9
|
+
* @typeParam TCrypto - The Crypto API used to perform cryptographic operations.
|
|
10
|
+
*/
|
|
11
|
+
export interface FlattenedJweDecryptParams<TKeyManager, TCrypto> {
|
|
12
|
+
/** The flattened JWE. */
|
|
13
|
+
jwe: FlattenedJweParams | FlattenedJwe;
|
|
14
|
+
/**
|
|
15
|
+
* The decryption key which can be a Key Identifier such as a KMS key URI, a JSON Web Key (JWK),
|
|
16
|
+
* or raw key material represented as a byte array.
|
|
17
|
+
*/
|
|
18
|
+
key: KeyIdentifier | Jwk | Uint8Array;
|
|
19
|
+
/** Key Manager instanceß responsible for managing cryptographic keys. */
|
|
20
|
+
keyManager?: TKeyManager;
|
|
21
|
+
/** Crypto API instance that provides the necessary cryptographic operations. */
|
|
22
|
+
crypto?: TCrypto;
|
|
23
|
+
/** {@inheritDoc JweDecryptOptions} */
|
|
24
|
+
options?: JweDecryptOptions;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Result of decrypting a flattened JWE, containing the plaintext and related information.
|
|
28
|
+
*/
|
|
29
|
+
export interface FlattenedJweDecryptResult {
|
|
30
|
+
/** JWE Additional Authenticated Data (AAD). */
|
|
31
|
+
additionalAuthenticatedData?: Uint8Array;
|
|
32
|
+
/** Plaintext. */
|
|
33
|
+
plaintext: Uint8Array;
|
|
34
|
+
/** JWE Protected Header. */
|
|
35
|
+
protectedHeader?: Partial<JweHeaderParams>;
|
|
36
|
+
/** JWE Shared Unprotected Header. */
|
|
37
|
+
sharedUnprotectedHeader?: Partial<JweHeaderParams>;
|
|
38
|
+
/** JWE Per-Recipient Unprotected Header. */
|
|
39
|
+
unprotectedHeader?: Partial<JweHeaderParams>;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Parameters for encrypting data into a flattened JWE format.
|
|
43
|
+
*
|
|
44
|
+
* @typeParam TKeyManager - The Key Manager used to manage cryptographic keys.
|
|
45
|
+
* @typeParam TCrypto - The Crypto API used to perform cryptographic operations.
|
|
46
|
+
*/
|
|
47
|
+
export interface FlattenedJweEncryptParams<TKeyManager, TCrypto> extends FlattenedJweDecryptResult {
|
|
48
|
+
/**
|
|
49
|
+
* The encryption key which can be a Key Identifier such as a KMS key URI, a JSON Web Key (JWK),
|
|
50
|
+
* or raw key material represented as a byte array.
|
|
51
|
+
*/
|
|
52
|
+
key: KeyIdentifier | Jwk | Uint8Array;
|
|
53
|
+
/** Key Manager instanceß responsible for managing cryptographic keys. */
|
|
54
|
+
keyManager?: TKeyManager;
|
|
55
|
+
/** Crypto API instance that provides the necessary cryptographic operations. */
|
|
56
|
+
crypto?: TCrypto;
|
|
57
|
+
/** {@inheritDoc JweEncryptOptions} */
|
|
58
|
+
options?: JweEncryptOptions;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Represents the parameters for a flattened JWE object, typically used in single-recipient
|
|
62
|
+
* scenarios.
|
|
63
|
+
*/
|
|
64
|
+
export interface FlattenedJweParams {
|
|
65
|
+
/** Base64URL encoded additional authenticated data. */
|
|
66
|
+
aad?: string;
|
|
67
|
+
/** Base64URL encoded ciphertext. */
|
|
68
|
+
ciphertext: string;
|
|
69
|
+
/** Base64URL encoded encrypted key. */
|
|
70
|
+
encrypted_key?: string;
|
|
71
|
+
/** Per-Recipient Unprotected Header parameters. */
|
|
72
|
+
header?: Partial<JweHeaderParams>;
|
|
73
|
+
/** Base64URL encoded initialization vector. */
|
|
74
|
+
iv?: string;
|
|
75
|
+
/** Base64URL encoded string of the Protected Header. */
|
|
76
|
+
protected?: string;
|
|
77
|
+
/** Base64URL encoded authentication tag. */
|
|
78
|
+
tag?: string;
|
|
79
|
+
/** Shared Unprotected Header parameters. */
|
|
80
|
+
unprotected?: Partial<JweHeaderParams>;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The `FlattenedJwe` class handles the encryption and decryption of JSON Web Encryption (JWE)
|
|
84
|
+
* objects in the flattened serialization format. This format is a compact, URL-safe means of
|
|
85
|
+
* representing encrypted content, typically used when dealing with a single recipient or when
|
|
86
|
+
* bandwidth efficiency is important.
|
|
87
|
+
*
|
|
88
|
+
* This class provides methods to encrypt plaintext to a flattened JWE and decrypt a flattened JWE
|
|
89
|
+
* back to plaintext, utilizing a variety of supported cryptographic algorithms as specified in the
|
|
90
|
+
* JWE header parameters.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```ts
|
|
94
|
+
* // Example usage of encrypt method
|
|
95
|
+
* const plaintext = new TextEncoder().encode("Secret Message");
|
|
96
|
+
* const key = { kty: "oct", k: "your-secret-key" }; // Example symmetric key
|
|
97
|
+
* const protectedHeader = { alg: "dir", enc: "A256GCM" };
|
|
98
|
+
* const encryptedJwe = await FlattenedJwe.encrypt({
|
|
99
|
+
* plaintext,
|
|
100
|
+
* protectedHeader,
|
|
101
|
+
* key,
|
|
102
|
+
* });
|
|
103
|
+
* ```
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* // Decryption example
|
|
107
|
+
* const { plaintext, protectedHeader } = await FlattenedJwe.decrypt({
|
|
108
|
+
* jwe: yourFlattenedJweObject,
|
|
109
|
+
* key: yourDecryptionKey,
|
|
110
|
+
* crypto: new YourCryptoApi(),
|
|
111
|
+
* });
|
|
112
|
+
*/
|
|
113
|
+
export declare class FlattenedJwe {
|
|
114
|
+
/** Base64URL encoded additional authenticated data. */
|
|
115
|
+
aad?: string;
|
|
116
|
+
/** Base64URL encoded ciphertext. */
|
|
117
|
+
ciphertext: string;
|
|
118
|
+
/** Base64URL encoded encrypted key. */
|
|
119
|
+
encrypted_key?: string;
|
|
120
|
+
/** Per-Recipient Unprotected Header parameters. */
|
|
121
|
+
header?: Partial<JweHeaderParams>;
|
|
122
|
+
/** Base64URL encoded initialization vector. */
|
|
123
|
+
iv?: string;
|
|
124
|
+
/** Base64URL encoded string of the Protected Header. */
|
|
125
|
+
protected?: string;
|
|
126
|
+
/** Base64URL encoded authentication tag. */
|
|
127
|
+
tag?: string;
|
|
128
|
+
/** Shared Unprotected Header parameters. */
|
|
129
|
+
unprotected?: Partial<JweHeaderParams>;
|
|
130
|
+
constructor(params: FlattenedJweParams);
|
|
131
|
+
static decrypt<TKeyManager extends KeyManager | undefined = KeyManager, TCrypto extends CryptoApi | undefined = CryptoApi>({ jwe, key, keyManager, crypto, options }: FlattenedJweDecryptParams<TKeyManager, TCrypto>): Promise<FlattenedJweDecryptResult>;
|
|
132
|
+
static encrypt<TKeyManager extends KeyManager | undefined = KeyManager, TCrypto extends CryptoApi | undefined = CryptoApi>({ key, plaintext, additionalAuthenticatedData, protectedHeader, sharedUnprotectedHeader, unprotectedHeader, keyManager, crypto, }: FlattenedJweEncryptParams<TKeyManager, TCrypto>): Promise<FlattenedJwe>;
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=jwe-flattened.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jwe-flattened.d.ts","sourceRoot":"","sources":["../../../../../src/prototyping/crypto/jose/jwe-flattened.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AA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,WAAW,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,yBAAyB,CAAC;WAoInE,OAAO,CACzB,WAAW,SAAS,UAAU,GAAG,SAAS,GAAG,UAAU,EACvD,OAAO,SAAS,SAAS,GAAG,SAAS,GAAG,SAAS,EACjD,EACA,GAAG,EACH,SAAS,EACT,2BAA2B,EAC3B,eAAe,EACf,uBAAuB,EACvB,iBAAiB,EACjB,UAAkC,EAClC,MAA6B,GAC9B,EAAE,yBAAyB,CAAC,WAAW,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC;CAyG3E"}
|
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
import type { JoseHeaderParams, Jwk, KeyIdentifier } from '@enbox/crypto';
|
|
2
|
+
import type { CryptoApi } from '../types/crypto-api.js';
|
|
3
|
+
import type { KeyManager } from '../types/key-manager.js';
|
|
4
|
+
/**
|
|
5
|
+
* Specifies options for decrypting a JWE, allowing the caller to define constraints on the JWE
|
|
6
|
+
* decryption process, particularly regarding the algorithms used.
|
|
7
|
+
*
|
|
8
|
+
* These options ensure that only expected and permitted algorithms are utilized during the
|
|
9
|
+
* decryption, enhancing security by preventing unexpected algorithm usage.
|
|
10
|
+
*/
|
|
11
|
+
export interface JweDecryptOptions {
|
|
12
|
+
/**
|
|
13
|
+
* The allowed "alg" (Algorithm) Header Parameter values.
|
|
14
|
+
*
|
|
15
|
+
* These values specify the cryptographic algorithms that are permissible for decrypting
|
|
16
|
+
* the Content Encryption Key (CEK) or for key agreement to determine the CEK.
|
|
17
|
+
*
|
|
18
|
+
* Note: If not specified, all algorithm values are considered allowed, which might not be
|
|
19
|
+
* desirable in all contexts.
|
|
20
|
+
*/
|
|
21
|
+
allowedAlgValues?: string[];
|
|
22
|
+
/**
|
|
23
|
+
* The allowed "enc" (Encryption) Header Parameter values.
|
|
24
|
+
*
|
|
25
|
+
* These values determine the cryptographic algorithms that can be used for decrypting the
|
|
26
|
+
* ciphertext and protecting the integrity of the plaintext and Additional Authenticated Data.
|
|
27
|
+
*
|
|
28
|
+
* Note: If left unspecified, it implies that all encryption algorithms are acceptable, which may
|
|
29
|
+
* not be secure in every scenario.
|
|
30
|
+
*
|
|
31
|
+
*/
|
|
32
|
+
allowedEncValues?: string[];
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Placeholder for specifying options during the JWE encryption process. Currently, this interface
|
|
36
|
+
* does not define any specific options but can be extended in the future to include parameters
|
|
37
|
+
* that control various aspects of the JWE encryption workflow.
|
|
38
|
+
*/
|
|
39
|
+
export interface JweEncryptOptions {
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* JSON Web Encryption (JWE) Header Parameters
|
|
43
|
+
*
|
|
44
|
+
* The Header Parameter names for use in JWEs are registered in the IANA "JSON Web Signature and
|
|
45
|
+
* Encryption Header Parameters" registry.
|
|
46
|
+
*
|
|
47
|
+
* @see {@link https://datatracker.ietf.org/doc/html/rfc7516#section-4.1 | RFC 7516, Section 4.1}
|
|
48
|
+
*/
|
|
49
|
+
export interface JweHeaderParams extends JoseHeaderParams {
|
|
50
|
+
/**
|
|
51
|
+
* Algorithm Header Parameter
|
|
52
|
+
*
|
|
53
|
+
* Identifies the cryptographic algorithm used to encrypt or determine the value of the Content
|
|
54
|
+
* Encryption Key (CEK). The encrypted content is not usable if the "alg" value does not represent
|
|
55
|
+
* a supported algorithm, or if the recipient does not have a key that can be used with that
|
|
56
|
+
* algorithm.
|
|
57
|
+
*
|
|
58
|
+
* "alg" values should either be registered in the IANA "JSON Web Signature and Encryption
|
|
59
|
+
* Algorithms" registry or be a value that contains a Collision-Resistant Name. The "alg" value is
|
|
60
|
+
* a case-sensitive ASCII string. This Header Parameter MUST be present and MUST be understood
|
|
61
|
+
* and processed by implementations.
|
|
62
|
+
*
|
|
63
|
+
* @see {@link https://datatracker.ietf.org/doc/html/rfc7516#section-4.1.1 | RFC 7516, Section 4.1.1}
|
|
64
|
+
*/
|
|
65
|
+
alg: 'A128KW' | 'A192KW' | 'A256KW' | 'dir' | 'ECDH-ES' | 'ECDH-ES+A128KW' | 'ECDH-ES+A192KW' | 'ECDH-ES+A256KW' | 'A128GCMKW' | 'A192GCMKW' | 'A256GCMKW' | 'PBES2-HS256+A128KW' | 'PBES2-HS384+A192KW' | 'PBES2-HS512+A256KW' | 'PBES2-HS512+XC20PKW' | string;
|
|
66
|
+
/**
|
|
67
|
+
* Agreement PartyUInfo Header Parameter
|
|
68
|
+
*
|
|
69
|
+
* The "apu" (agreement PartyUInfo) value is a base64url-encoded octet sequence containing
|
|
70
|
+
* information about the producer of the JWE. This information is used by the recipient to
|
|
71
|
+
* determine the key agreement algorithm and key encryption algorithm to use to decrypt the JWE.
|
|
72
|
+
*
|
|
73
|
+
* Note: This parameter is intended only for use when the recipient is a key agreement algorithm
|
|
74
|
+
* that uses public key cryptography.
|
|
75
|
+
*/
|
|
76
|
+
apu?: string;
|
|
77
|
+
/**
|
|
78
|
+
* Agreement PartyVInfo Header Parameter
|
|
79
|
+
*
|
|
80
|
+
* The "apv" (agreement PartyVInfo) value is a base64url-encoded octet sequence containing
|
|
81
|
+
* information about the recipient of the JWE. This information is used by the recipient to
|
|
82
|
+
* determine the key agreement algorithm and key encryption algorithm to use to decrypt the JWE.
|
|
83
|
+
*
|
|
84
|
+
* Note: This parameter is intended only for use when the recipient is a key agreement algorithm
|
|
85
|
+
* that uses public key cryptography.
|
|
86
|
+
*/
|
|
87
|
+
apv?: string;
|
|
88
|
+
/**
|
|
89
|
+
* Critical Header Parameter
|
|
90
|
+
*
|
|
91
|
+
* Indicates that extensions to JOSE RFCs are being used that MUST be understood and processed.
|
|
92
|
+
*/
|
|
93
|
+
crit?: string[];
|
|
94
|
+
/**
|
|
95
|
+
* Encryption Algorithm Header Parameter
|
|
96
|
+
*
|
|
97
|
+
* Identifies the content encryption algorithm used to encrypt and integrity-protect (also
|
|
98
|
+
* known as "authenticated encryption") the plaintext and to integrity-protect the Additional
|
|
99
|
+
* Authenticated Data (AAD), if any. This algorithm MUST be an AEAD algorithm with a specified
|
|
100
|
+
* key length.
|
|
101
|
+
*
|
|
102
|
+
* The encrypted content is not usable if the "enc" value does not represent a supported
|
|
103
|
+
* algorithm. "enc" values should either be registered in the IANA "JSON Web Signature and
|
|
104
|
+
* Encryption Algorithms" registry or be a value that contains a Collision-Resistant Name. The
|
|
105
|
+
* "enc" value is a case-sensitive ASCII string containing a StringOrURI value. This Header
|
|
106
|
+
* Parameter MUST be present and MUST be understood and processed by implementations.
|
|
107
|
+
*
|
|
108
|
+
* @see {@link https://datatracker.ietf.org/doc/html/rfc7516#section-4.1.2 | RFC 7516, Section 4.1.2}
|
|
109
|
+
*/
|
|
110
|
+
enc: 'A128CBC-HS256' | 'A192CBC-HS384' | 'A256CBC-HS512' | 'A128GCM' | 'A192GCM' | 'A256GCM' | 'XC20P' | string;
|
|
111
|
+
/**
|
|
112
|
+
* Ephemeral Public Key Header Parameter
|
|
113
|
+
*
|
|
114
|
+
* The "epk" (ephemeral public key) value created by the originator for the use in key agreement
|
|
115
|
+
* algorithms. It is the ephemeral public key that corresponds to the key used to encrypt the
|
|
116
|
+
* JWE. This value is represented as a JSON Web Key (JWK).
|
|
117
|
+
*
|
|
118
|
+
* Note: This parameter is intended only for use when the recipient is a key agreement algorithm
|
|
119
|
+
* that uses public key cryptography.
|
|
120
|
+
*/
|
|
121
|
+
epk?: Jwk;
|
|
122
|
+
/**
|
|
123
|
+
* Initialization Vector Header Parameter
|
|
124
|
+
*
|
|
125
|
+
* The "iv" (initialization vector) value is a base64url-encoded octet sequence used by the
|
|
126
|
+
* specified "enc" algorithm. The length of this Initialization Vector value MUST be exactly
|
|
127
|
+
* equal to the value that would be produced by the "enc" algorithm.
|
|
128
|
+
*
|
|
129
|
+
* Note: With symmetric encryption algorithms such as AES GCM, this Header Parameter MUST
|
|
130
|
+
* be present and MUST be understood and processed by implementations.
|
|
131
|
+
*/
|
|
132
|
+
iv?: string;
|
|
133
|
+
/**
|
|
134
|
+
* PBES2 Count Header Parameter
|
|
135
|
+
*
|
|
136
|
+
* The "p2c" (PBES2 count) value is an integer indicating the number of iterations of the PBKDF2
|
|
137
|
+
* algorithm performed during key derivation.
|
|
138
|
+
*
|
|
139
|
+
* Note: The iteration count adds computational expense, ideally compounded by the possible range
|
|
140
|
+
* of keys introduced by the salt. A minimum iteration count of 1000 is RECOMMENDED.
|
|
141
|
+
*/
|
|
142
|
+
p2c?: number;
|
|
143
|
+
/**
|
|
144
|
+
* PBES2 Salt Input Header Parameter
|
|
145
|
+
*
|
|
146
|
+
* The "p2s" (PBES2 salt) value is a base64url-encoded octet sequence used as the salt value
|
|
147
|
+
* input to the PBKDF2 algorithm during key derivation.
|
|
148
|
+
*
|
|
149
|
+
* The salt value used is (UTF8(Alg) || 0x00 || Salt Input), where Alg is the "alg" (algorithm)
|
|
150
|
+
* Header Parameter value.
|
|
151
|
+
*
|
|
152
|
+
* Note: The salt value is used to ensure that each key derived from the master key is
|
|
153
|
+
* independent of every other key. A suitable source of salt value is a sequence of
|
|
154
|
+
* cryptographically random bytes containing 8 or more octets.
|
|
155
|
+
*/
|
|
156
|
+
p2s?: string;
|
|
157
|
+
/**
|
|
158
|
+
* Authentication Tag Header Parameter
|
|
159
|
+
*
|
|
160
|
+
* The "tag" value is a base64url-encoded octet sequence containing the value of the
|
|
161
|
+
* Authentication Tag output by the specified "enc" algorithm. The length of this
|
|
162
|
+
* Authentication Tag value MUST be exactly equal to the value that would be produced by the
|
|
163
|
+
* "enc" algorithm.
|
|
164
|
+
*
|
|
165
|
+
* Note: With authenticated encryption algorithms such as AES GCM, this Header Parameter MUST
|
|
166
|
+
* be present and MUST be understood and processed by implementations.
|
|
167
|
+
*/
|
|
168
|
+
tag?: string;
|
|
169
|
+
/**
|
|
170
|
+
* Additional Public or Private Header Parameter names.
|
|
171
|
+
*/
|
|
172
|
+
[key: string]: unknown;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Represents the result of the JWE key management encryption process, encapsulating the Content
|
|
176
|
+
* Encryption Key (CEK) and optionally the encrypted CEK.
|
|
177
|
+
*/
|
|
178
|
+
export interface JweKeyManagementEncryptResult {
|
|
179
|
+
/**
|
|
180
|
+
* The Content Encryption Key (CEK) used for encrypting the JWE payload. It can be a Key
|
|
181
|
+
* Identifier such as a KMS URI or a JSON Web Key (JWK).
|
|
182
|
+
*/
|
|
183
|
+
cek: KeyIdentifier | Jwk;
|
|
184
|
+
/**
|
|
185
|
+
* The encrypted version of the CEK, provided as a byte array. The encrypted version of the CEK
|
|
186
|
+
* is returned for all key management modes other than "dir" (Direct Encryption Mode).
|
|
187
|
+
*/
|
|
188
|
+
encryptedKey?: Uint8Array;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Defines the parameters required to decrypt a JWE encrypted key, including the key management
|
|
192
|
+
* details.
|
|
193
|
+
*
|
|
194
|
+
* @typeParam TKeyManager - The Key Manager used to manage cryptographic keys.
|
|
195
|
+
* @typeParam TCrypto - The Crypto API used to perform cryptographic operations.
|
|
196
|
+
*/
|
|
197
|
+
export interface JweKeyManagementDecryptParams<TKeyManager, TCrypto> {
|
|
198
|
+
/**
|
|
199
|
+
* The decryption key which can be a Key Identifier such as a KMS key URI, a JSON Web Key (JWK),
|
|
200
|
+
* or raw key material represented as a byte array.
|
|
201
|
+
*/
|
|
202
|
+
key: KeyIdentifier | Jwk | Uint8Array;
|
|
203
|
+
/**
|
|
204
|
+
* The encrypted key extracted from the JWE, represented as a byte array. This parameter is
|
|
205
|
+
* optional and is used when the key is wrapped.
|
|
206
|
+
*/
|
|
207
|
+
encryptedKey?: Uint8Array;
|
|
208
|
+
/**
|
|
209
|
+
* The JWE header parameters that define the characteristics of the decryption process, specifying
|
|
210
|
+
* the algorithm and encryption method among other settings.
|
|
211
|
+
*/
|
|
212
|
+
joseHeader: JweHeaderParams;
|
|
213
|
+
/** Key Manager instanceß responsible for managing cryptographic keys. */
|
|
214
|
+
keyManager: TKeyManager;
|
|
215
|
+
/** Crypto API instance that provides the necessary cryptographic operations. */
|
|
216
|
+
crypto: TCrypto;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Defines the parameters required for encrypting a JWE CEK, including the key management details.
|
|
220
|
+
*
|
|
221
|
+
* @typeParam TKeyManager - The Key Manager used to manage cryptographic keys.
|
|
222
|
+
* @typeParam TCrypto - The Crypto API used to perform cryptographic operations.
|
|
223
|
+
*/
|
|
224
|
+
export interface JweKeyManagementEncryptParams<TKeyManager, TCrypto> {
|
|
225
|
+
/**
|
|
226
|
+
* The encryption key which can be a Key Identifier such as a KMS key URI, a JSON Web Key (JWK),
|
|
227
|
+
* or raw key material represented as a byte array.
|
|
228
|
+
*/
|
|
229
|
+
key: KeyIdentifier | Jwk | Uint8Array;
|
|
230
|
+
/**
|
|
231
|
+
* The JWE header parameters that define the characteristics of the encryption process, specifying
|
|
232
|
+
* the algorithm and encryption method among other settings.
|
|
233
|
+
*/
|
|
234
|
+
joseHeader: JweHeaderParams;
|
|
235
|
+
/** Key Manager instanceß responsible for managing cryptographic keys. */
|
|
236
|
+
keyManager: TKeyManager;
|
|
237
|
+
/** Crypto API instance that provides the necessary cryptographic operations. */
|
|
238
|
+
crypto: TCrypto;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Checks if the provided object is a valid JWE (JSON Web Encryption) header.
|
|
242
|
+
*
|
|
243
|
+
* This function evaluates whether the given object adheres to the structure expected for
|
|
244
|
+
* a JWE header, specifically looking for the presence and proper format of the "alg" (algorithm)
|
|
245
|
+
* and "enc" (encryption algorithm) properties, which are essential for defining the JWE's
|
|
246
|
+
* cryptographic operations.
|
|
247
|
+
*
|
|
248
|
+
* @example
|
|
249
|
+
* ```ts
|
|
250
|
+
* const header = {
|
|
251
|
+
* alg: 'dir',
|
|
252
|
+
* enc: 'A256GCM'
|
|
253
|
+
* };
|
|
254
|
+
*
|
|
255
|
+
* if (isValidJweHeader(header)) {
|
|
256
|
+
* console.log('The object is a valid JWE header.');
|
|
257
|
+
* } else {
|
|
258
|
+
* console.log('The object is not a valid JWE header.');
|
|
259
|
+
* }
|
|
260
|
+
* ```
|
|
261
|
+
*
|
|
262
|
+
* @param obj - The object to be validated as a JWE header.
|
|
263
|
+
* @returns Returns `true` if the object is a valid JWE header, otherwise `false`.
|
|
264
|
+
*/
|
|
265
|
+
export declare function isValidJweHeader(obj: unknown): obj is JweHeaderParams;
|
|
266
|
+
/**
|
|
267
|
+
* The `JweKeyManagement` class implements the key management aspects of JSON Web Encryption (JWE)
|
|
268
|
+
* as specified in {@link https://datatracker.ietf.org/doc/html/rfc7516 | RFC 7516}.
|
|
269
|
+
*
|
|
270
|
+
* It supports algorithms for encrypting and decrypting keys, thereby enabling the secure
|
|
271
|
+
* transmission of information where the payload is encrypted, and the encryption key is also
|
|
272
|
+
* encrypted or agreed upon using key agreement techniques.
|
|
273
|
+
*
|
|
274
|
+
* The choice of algorithm is determined by the "alg" parameter in the JWE
|
|
275
|
+
* header, and the class is designed to handle the intricacies associated with each algorithm,
|
|
276
|
+
* ensuring the secure handling of the encryption keys.
|
|
277
|
+
*
|
|
278
|
+
* Supported algorithms include:
|
|
279
|
+
* - `"dir"`: Direct Encryption Mode
|
|
280
|
+
* - `"PBES2-HS256+A128KW"`, `"PBES2-HS384+A192KW"`, `"PBES2-HS512+A256KW"`: Password-Based
|
|
281
|
+
* Encryption Mode with Key Wrapping (PBES2) using HMAC-SHA and AES Key Wrap algorithms for key
|
|
282
|
+
* wrapping and encryption.
|
|
283
|
+
*
|
|
284
|
+
* @example
|
|
285
|
+
* // To encrypt a key:
|
|
286
|
+
* const keyEncryptionKey = Convert.string(passphrase).toUint8Array()
|
|
287
|
+
* const { cek, encryptedKey: encryptedCek } = await JweKeyManagement.encrypt({
|
|
288
|
+
* key: keyEncryptionKey,
|
|
289
|
+
* joseHeader: {
|
|
290
|
+
* alg: 'PBES2-HS512+A256KW',
|
|
291
|
+
* enc: 'A256GCM',
|
|
292
|
+
* p2c : 210_000,
|
|
293
|
+
p2s : Convert.uint8Array(saltInput).toBase64Url()
|
|
294
|
+
* },
|
|
295
|
+
* crypto: new AgentCryptoApi(),
|
|
296
|
+
* });
|
|
297
|
+
*
|
|
298
|
+
* // To decrypt a key:
|
|
299
|
+
* const cek = await JweKeyManagement.decrypt({
|
|
300
|
+
* key: keyEncryptionKey,
|
|
301
|
+
* encryptedKey: encryptedCek,
|
|
302
|
+
* joseHeader: {
|
|
303
|
+
* alg: 'PBES2-HS512+A256KW',
|
|
304
|
+
* enc: 'A256GCM',
|
|
305
|
+
* p2c : 210_000,
|
|
306
|
+
p2s : Convert.uint8Array(saltInput).toBase64Url()
|
|
307
|
+
* },
|
|
308
|
+
* crypto: new AgentCryptoApi(),
|
|
309
|
+
* });
|
|
310
|
+
*/
|
|
311
|
+
export declare class JweKeyManagement {
|
|
312
|
+
/**
|
|
313
|
+
* Decrypts the encrypted key (JWE Encrypted Key) using the specified key encryption algorithm
|
|
314
|
+
* defined in the JWE Header's "alg" parameter.
|
|
315
|
+
*
|
|
316
|
+
* This method supports multiple key management algorithms, including Direct Encryption (dir) and
|
|
317
|
+
* PBES2 schemes with key wrapping.
|
|
318
|
+
*
|
|
319
|
+
* The method takes a key, which can be a Key Identifier, JWK, or raw byte array, and the
|
|
320
|
+
* encrypted key along with the JWE header. It returns the decrypted Content Encryption Key (CEK)
|
|
321
|
+
* which can then be used to decrypt the JWE ciphertext.
|
|
322
|
+
*
|
|
323
|
+
* @example
|
|
324
|
+
* ```ts
|
|
325
|
+
* // Decrypting the CEK with the PBES2-HS512+A256KW algorithm
|
|
326
|
+
* const cek = await JweKeyManagement.decrypt({
|
|
327
|
+
* key: Convert.string(passphrase).toUint8Array(),
|
|
328
|
+
* encryptedKey: encryptedCek,
|
|
329
|
+
* joseHeader: {
|
|
330
|
+
* alg: 'PBES2-HS512+A256KW',
|
|
331
|
+
* enc: 'A256GCM',
|
|
332
|
+
* p2c: 210_000,
|
|
333
|
+
* p2s: Convert.uint8Array(saltInput).toBase64Url(),
|
|
334
|
+
* },
|
|
335
|
+
* crypto: new AgentCryptoApi()
|
|
336
|
+
* });
|
|
337
|
+
* ```
|
|
338
|
+
*
|
|
339
|
+
* @param params - The decryption parameters.
|
|
340
|
+
* @throws Throws an error if the key management algorithm is not supported or if required
|
|
341
|
+
* parameters are missing or invalid.
|
|
342
|
+
*/
|
|
343
|
+
static decrypt<TKeyManager extends KeyManager, TCrypto extends CryptoApi>({ key, encryptedKey, joseHeader, crypto }: JweKeyManagementDecryptParams<TKeyManager, TCrypto>): Promise<KeyIdentifier | Jwk>;
|
|
344
|
+
/**
|
|
345
|
+
* Encrypts a Content Encryption Key (CEK) using the key management algorithm specified in the
|
|
346
|
+
* JWE Header's "alg" parameter.
|
|
347
|
+
*
|
|
348
|
+
* This method supports various key management algorithms, including Direct Encryption (dir) and
|
|
349
|
+
* PBES2 with key wrapping.
|
|
350
|
+
*
|
|
351
|
+
* It generates a random CEK for the specified encryption algorithm in the JWE header, which
|
|
352
|
+
* can then be used to encrypt the actual payload. For algorithms that require an encrypted key,
|
|
353
|
+
* it returns the CEK along with the encrypted key.
|
|
354
|
+
*
|
|
355
|
+
* @example
|
|
356
|
+
* ```ts
|
|
357
|
+
* // Encrypting the CEK with the PBES2-HS512+A256KW algorithm
|
|
358
|
+
* const { cek, encryptedKey } = await JweKeyManagement.encrypt({
|
|
359
|
+
* key: Convert.string(passphrase).toUint8Array(),
|
|
360
|
+
* joseHeader: {
|
|
361
|
+
* alg: 'PBES2-HS512+A256KW',
|
|
362
|
+
* enc: 'A256GCM',
|
|
363
|
+
* p2c: 210_000,
|
|
364
|
+
* p2s: Convert.uint8Array(saltInput).toBase64Url(),
|
|
365
|
+
* },
|
|
366
|
+
* crypto: crypto: new AgentCryptoApi()
|
|
367
|
+
* });
|
|
368
|
+
* ```
|
|
369
|
+
*
|
|
370
|
+
* @param params - The encryption parameters.
|
|
371
|
+
* @returns The encrypted key result containing the CEK and optionally the encrypted CEK
|
|
372
|
+
* (JWE Encrypted Key).
|
|
373
|
+
* @throws Throws an error if the key management algorithm is not supported or if required
|
|
374
|
+
* parameters are missing or invalid.
|
|
375
|
+
*/
|
|
376
|
+
static encrypt<TKeyManager extends KeyManager, TCrypto extends CryptoApi>({ key, joseHeader, crypto }: JweKeyManagementEncryptParams<TKeyManager, TCrypto>): Promise<JweKeyManagementEncryptResult>;
|
|
377
|
+
}
|
|
378
|
+
//# sourceMappingURL=jwe.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jwe.d.ts","sourceRoot":"","sources":["../../../../../src/prototyping/crypto/jose/jwe.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,GAAG,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAI1E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAI1D;;;;;;GAMG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;;;;;;OAQG;IACH,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAE5B;;;;;;;;;OASG;IACH,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC7B;AAED;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;CAAG;AAErC;;;;;;;GAOG;AACH,MAAM,WAAW,eAAgB,SAAQ,gBAAgB;IACvD;;;;;;;;;;;;;;OAcG;IACH,GAAG,EAEC,QAAQ,GAER,QAAQ,GAER,QAAQ,GAER,KAAK,GAEL,SAAS,GAET,gBAAgB,GAEhB,gBAAgB,GAEhB,gBAAgB,GAEhB,WAAW,GAEX,WAAW,GAEX,WAAW,GAEX,oBAAoB,GAEpB,oBAAoB,GAEpB,oBAAoB,GAEpB,qBAAqB,GAErB,MAAM,CAAC;IAEX;;;;;;;;;OASG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb;;;;;;;;;OASG;IACH,GAAG,CAAC,EAAE,MAAM,CAA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