@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,352 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
11
|
+
var t = {};
|
|
12
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
13
|
+
t[p] = s[p];
|
|
14
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
15
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
16
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
17
|
+
t[p[i]] = s[p[i]];
|
|
18
|
+
}
|
|
19
|
+
return t;
|
|
20
|
+
};
|
|
21
|
+
import { Convert } from '@enbox/common';
|
|
22
|
+
import { getWebcryptoSubtle } from '@noble/ciphers/webcrypto';
|
|
23
|
+
import { computeJwkThumbprint, isOctPrivateJwk } from '@enbox/crypto';
|
|
24
|
+
/**
|
|
25
|
+
* Const defining the AES-GCM initialization vector (IV) length in bits.
|
|
26
|
+
*
|
|
27
|
+
* @remarks
|
|
28
|
+
* NIST Special Publication 800-38D, Section 5.2.1.1 states that the IV length:
|
|
29
|
+
* > For IVs, it is recommended that implementations restrict support to the length of 96 bits, to
|
|
30
|
+
* > promote interoperability, efficiency, and simplicity of design.
|
|
31
|
+
*
|
|
32
|
+
* This implementation does not support IV lengths that are different from the value defined by
|
|
33
|
+
* this constant.
|
|
34
|
+
*
|
|
35
|
+
* @see {@link https://doi.org/10.6028/NIST.SP.800-38D | NIST SP 800-38D}
|
|
36
|
+
*/
|
|
37
|
+
const AES_GCM_IV_LENGTH = 96;
|
|
38
|
+
/**
|
|
39
|
+
* Constant defining the AES key length values in bits.
|
|
40
|
+
*
|
|
41
|
+
* @remarks
|
|
42
|
+
* NIST publication FIPS 197 states:
|
|
43
|
+
* > The AES algorithm is capable of using cryptographic keys of 128, 192, and 256 bits to encrypt
|
|
44
|
+
* > and decrypt data in blocks of 128 bits.
|
|
45
|
+
*
|
|
46
|
+
* This implementation does not support key lengths that are different from the three values
|
|
47
|
+
* defined by this constant.
|
|
48
|
+
*
|
|
49
|
+
* @see {@link https://doi.org/10.6028/NIST.FIPS.197-upd1 | NIST FIPS 197}
|
|
50
|
+
*/
|
|
51
|
+
const AES_KEY_LENGTHS = [128, 192, 256];
|
|
52
|
+
/**
|
|
53
|
+
* Constant defining the AES-GCM tag length values in bits.
|
|
54
|
+
*
|
|
55
|
+
* @remarks
|
|
56
|
+
* NIST Special Publication 800-38D, Section 5.2.1.2 states that the tag length:
|
|
57
|
+
* > may be any one of the following five values: 128, 120, 112, 104, or 96
|
|
58
|
+
*
|
|
59
|
+
* Although the NIST specification allows for tag lengths of 32 or 64 bits in certain applications,
|
|
60
|
+
* the use of shorter tag lengths can be problematic for GCM due to targeted forgery attacks. As a
|
|
61
|
+
* precaution, this implementation does not support tag lengths that are different from the five
|
|
62
|
+
* values defined by this constant. See Appendix C of the NIST SP 800-38D specification for
|
|
63
|
+
* additional guidance and details.
|
|
64
|
+
*
|
|
65
|
+
* @see {@link https://doi.org/10.6028/NIST.SP.800-38D | NIST SP 800-38D}
|
|
66
|
+
*/
|
|
67
|
+
export const AES_GCM_TAG_LENGTHS = [96, 104, 112, 120, 128];
|
|
68
|
+
/**
|
|
69
|
+
* The `AesGcm` class provides a comprehensive set of utilities for cryptographic operations
|
|
70
|
+
* using the Advanced Encryption Standard (AES) in Galois/Counter Mode (GCM). This class includes
|
|
71
|
+
* methods for key generation, encryption, decryption, and conversions between raw byte arrays
|
|
72
|
+
* and JSON Web Key (JWK) formats. It is designed to support AES-GCM, a symmetric key algorithm
|
|
73
|
+
* that is widely used for its efficiency, security, and provision of authenticated encryption.
|
|
74
|
+
*
|
|
75
|
+
* AES-GCM is particularly favored for scenarios that require both confidentiality and integrity
|
|
76
|
+
* of data. It integrates the counter mode of encryption with the Galois mode of authentication,
|
|
77
|
+
* offering high performance and parallel processing capabilities.
|
|
78
|
+
*
|
|
79
|
+
* Key Features:
|
|
80
|
+
* - Key Generation: Generate AES symmetric keys in JWK format.
|
|
81
|
+
* - Key Conversion: Transform keys between raw byte arrays and JWK formats.
|
|
82
|
+
* - Encryption: Encrypt data using AES-GCM with the provided symmetric key.
|
|
83
|
+
* - Decryption: Decrypt data encrypted with AES-GCM using the corresponding symmetric key.
|
|
84
|
+
*
|
|
85
|
+
* The methods in this class are asynchronous, returning Promises to accommodate various
|
|
86
|
+
* JavaScript environments.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* // Key Generation
|
|
91
|
+
* const length = 256; // Length of the key in bits (e.g., 128, 192, 256)
|
|
92
|
+
* const privateKey = await AesGcm.generateKey({ length });
|
|
93
|
+
*
|
|
94
|
+
* // Encryption
|
|
95
|
+
* const data = new TextEncoder().encode('Messsage');
|
|
96
|
+
* const iv = new Uint8Array(12); // 12-byte initialization vector
|
|
97
|
+
* const encryptedData = await AesGcm.encrypt({
|
|
98
|
+
* data,
|
|
99
|
+
* iv,
|
|
100
|
+
* key: privateKey
|
|
101
|
+
* });
|
|
102
|
+
*
|
|
103
|
+
* // Decryption
|
|
104
|
+
* const decryptedData = await AesGcm.decrypt({
|
|
105
|
+
* data: encryptedData,
|
|
106
|
+
* iv,
|
|
107
|
+
* key: privateKey
|
|
108
|
+
* });
|
|
109
|
+
*
|
|
110
|
+
* // Key Conversion
|
|
111
|
+
* const privateKeyBytes = await AesGcm.privateKeyToBytes({ privateKey });
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
export class AesGcm {
|
|
115
|
+
/**
|
|
116
|
+
* Converts a raw private key in bytes to its corresponding JSON Web Key (JWK) format.
|
|
117
|
+
*
|
|
118
|
+
* @remarks
|
|
119
|
+
* This method accepts a symmetric key represented as a byte array (Uint8Array) and
|
|
120
|
+
* converts it into a JWK object for use with AES-GCM (Advanced Encryption Standard -
|
|
121
|
+
* Galois/Counter Mode). The conversion process involves encoding the key into
|
|
122
|
+
* base64url format and setting the appropriate JWK parameters.
|
|
123
|
+
*
|
|
124
|
+
* The resulting JWK object includes the following properties:
|
|
125
|
+
* - `kty`: Key Type, set to 'oct' for Octet Sequence (representing a symmetric key).
|
|
126
|
+
* - `k`: The symmetric key, base64url-encoded.
|
|
127
|
+
* - `kid`: Key ID, generated based on the JWK thumbprint.
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```ts
|
|
131
|
+
* const privateKeyBytes = new Uint8Array([...]); // Replace with actual symmetric key bytes
|
|
132
|
+
* const privateKey = await AesGcm.bytesToPrivateKey({ privateKeyBytes });
|
|
133
|
+
* ```
|
|
134
|
+
*
|
|
135
|
+
* @param params - The parameters for the symmetric key conversion.
|
|
136
|
+
* @param params.privateKeyBytes - The raw symmetric key as a Uint8Array.
|
|
137
|
+
*
|
|
138
|
+
* @returns A Promise that resolves to the symmetric key in JWK format.
|
|
139
|
+
*/
|
|
140
|
+
static bytesToPrivateKey({ privateKeyBytes }) {
|
|
141
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
142
|
+
// Construct the private key in JWK format.
|
|
143
|
+
const privateKey = {
|
|
144
|
+
k: Convert.uint8Array(privateKeyBytes).toBase64Url(),
|
|
145
|
+
kty: 'oct'
|
|
146
|
+
};
|
|
147
|
+
// Compute the JWK thumbprint and set as the key ID.
|
|
148
|
+
privateKey.kid = yield computeJwkThumbprint({ jwk: privateKey });
|
|
149
|
+
// Add algorithm identifier based on key length.
|
|
150
|
+
const lengthInBits = privateKeyBytes.length * 8;
|
|
151
|
+
privateKey.alg = { 128: 'A128GCM', 192: 'A192GCM', 256: 'A256GCM' }[lengthInBits];
|
|
152
|
+
return privateKey;
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Decrypts the provided data using AES-GCM.
|
|
157
|
+
*
|
|
158
|
+
* @remarks
|
|
159
|
+
* This method performs AES-GCM decryption on the given encrypted data using the specified key.
|
|
160
|
+
* It requires an initialization vector (IV), the encrypted data along with the decryption key,
|
|
161
|
+
* and optionally, additional authenticated data (AAD). The method returns the decrypted data as a
|
|
162
|
+
* Uint8Array. The optional `tagLength` parameter specifies the size in bits of the authentication
|
|
163
|
+
* tag used when encrypting the data. If not specified, the default tag length of 128 bits is
|
|
164
|
+
* used.
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```ts
|
|
168
|
+
* const encryptedData = new Uint8Array([...]); // Encrypted data
|
|
169
|
+
* const iv = new Uint8Array([...]); // Initialization vector used during encryption
|
|
170
|
+
* const additionalData = new Uint8Array([...]); // Optional additional authenticated data
|
|
171
|
+
* const key = { ... }; // A Jwk object representing the AES key
|
|
172
|
+
* const decryptedData = await AesGcm.decrypt({
|
|
173
|
+
* data: encryptedData,
|
|
174
|
+
* iv,
|
|
175
|
+
* additionalData,
|
|
176
|
+
* key,
|
|
177
|
+
* tagLength: 128 // Optional tag length in bits
|
|
178
|
+
* });
|
|
179
|
+
* ```
|
|
180
|
+
*
|
|
181
|
+
* @param params - The parameters for the decryption operation.
|
|
182
|
+
* @param params.key - The key to use for decryption, represented in JWK format.
|
|
183
|
+
* @param params.data - The encrypted data to decrypt, represented as a Uint8Array.
|
|
184
|
+
* @param params.iv - The initialization vector, represented as a Uint8Array.
|
|
185
|
+
* @param params.additionalData - Optional additional authenticated data. Optional.
|
|
186
|
+
* @param params.tagLength - The length of the authentication tag in bits. Optional.
|
|
187
|
+
*
|
|
188
|
+
* @returns A Promise that resolves to the decrypted data as a Uint8Array.
|
|
189
|
+
*/
|
|
190
|
+
static decrypt({ key, data, iv, additionalData, tagLength }) {
|
|
191
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
192
|
+
// Validate the initialization vector length.
|
|
193
|
+
if (iv.byteLength !== AES_GCM_IV_LENGTH / 8) {
|
|
194
|
+
throw new TypeError(`The initialization vector must be ${AES_GCM_IV_LENGTH} bits in length`);
|
|
195
|
+
}
|
|
196
|
+
// Validate the tag length.
|
|
197
|
+
if (tagLength && !AES_GCM_TAG_LENGTHS.includes(tagLength)) {
|
|
198
|
+
throw new RangeError(`The tag length is invalid: Must be ${AES_GCM_TAG_LENGTHS.join(', ')} bits`);
|
|
199
|
+
}
|
|
200
|
+
// Get the Web Crypto API interface.
|
|
201
|
+
const webCrypto = getWebcryptoSubtle();
|
|
202
|
+
// Import the JWK into the Web Crypto API to use for the decrypt operation.
|
|
203
|
+
const webCryptoKey = yield webCrypto.importKey('jwk', key, { name: 'AES-GCM' }, true, ['decrypt']);
|
|
204
|
+
// Browser implementations of the Web Crypto API throw an error if additionalData is undefined.
|
|
205
|
+
const algorithm = (additionalData === undefined)
|
|
206
|
+
? { name: 'AES-GCM', iv, tagLength }
|
|
207
|
+
: { name: 'AES-GCM', additionalData, iv, tagLength };
|
|
208
|
+
// Decrypt the data.
|
|
209
|
+
const plaintextBuffer = yield webCrypto.decrypt(algorithm, webCryptoKey, data);
|
|
210
|
+
// Convert from ArrayBuffer to Uint8Array.
|
|
211
|
+
const plaintext = new Uint8Array(plaintextBuffer);
|
|
212
|
+
return plaintext;
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Encrypts the provided data using AES-GCM.
|
|
217
|
+
*
|
|
218
|
+
* @remarks
|
|
219
|
+
* This method performs AES-GCM encryption on the given data using the specified key.
|
|
220
|
+
* It requires an initialization vector (IV), the encrypted data along with the decryption key,
|
|
221
|
+
* and optionally, additional authenticated data (AAD). The method returns the encrypted data as a
|
|
222
|
+
* Uint8Array. The optional `tagLength` parameter specifies the size in bits of the authentication
|
|
223
|
+
* tag generated in the encryption operation and used for authentication in the corresponding
|
|
224
|
+
* decryption. If not specified, the default tag length of 128 bits is used.
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* ```ts
|
|
228
|
+
* const data = new TextEncoder().encode('Messsage');
|
|
229
|
+
* const iv = new Uint8Array([...]); // Initialization vector
|
|
230
|
+
* const additionalData = new Uint8Array([...]); // Optional additional authenticated data
|
|
231
|
+
* const key = { ... }; // A Jwk object representing an AES key
|
|
232
|
+
* const encryptedData = await AesGcm.encrypt({
|
|
233
|
+
* data,
|
|
234
|
+
* iv,
|
|
235
|
+
* additionalData,
|
|
236
|
+
* key,
|
|
237
|
+
* tagLength: 128 // Optional tag length in bits
|
|
238
|
+
* });
|
|
239
|
+
* ```
|
|
240
|
+
*
|
|
241
|
+
* @param params - The parameters for the encryption operation.
|
|
242
|
+
* @param params.key - The key to use for encryption, represented in JWK format.
|
|
243
|
+
* @param params.data - The data to encrypt, represented as a Uint8Array.
|
|
244
|
+
* @param params.iv - The initialization vector, represented as a Uint8Array.
|
|
245
|
+
* @param params.additionalData - Optional additional authenticated data. Optional.
|
|
246
|
+
* @param params.tagLength - The length of the authentication tag in bits. Optional.
|
|
247
|
+
*
|
|
248
|
+
* @returns A Promise that resolves to the encrypted data as a Uint8Array.
|
|
249
|
+
*/
|
|
250
|
+
static encrypt({ data, iv, key, additionalData, tagLength }) {
|
|
251
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
252
|
+
// Validate the initialization vector length.
|
|
253
|
+
if (iv.byteLength !== AES_GCM_IV_LENGTH / 8) {
|
|
254
|
+
throw new TypeError(`The initialization vector must be ${AES_GCM_IV_LENGTH} bits in length`);
|
|
255
|
+
}
|
|
256
|
+
// Validate the tag length.
|
|
257
|
+
if (tagLength && !AES_GCM_TAG_LENGTHS.includes(tagLength)) {
|
|
258
|
+
throw new RangeError(`The tag length is invalid: Must be ${AES_GCM_TAG_LENGTHS.join(', ')} bits`);
|
|
259
|
+
}
|
|
260
|
+
// Get the Web Crypto API interface.
|
|
261
|
+
const webCrypto = getWebcryptoSubtle();
|
|
262
|
+
// Import the JWK into the Web Crypto API to use for the encrypt operation.
|
|
263
|
+
const webCryptoKey = yield webCrypto.importKey('jwk', key, { name: 'AES-GCM' }, true, ['encrypt']);
|
|
264
|
+
// Browser implementations of the Web Crypto API throw an error if additionalData is undefined.
|
|
265
|
+
const algorithm = (additionalData === undefined)
|
|
266
|
+
? { name: 'AES-GCM', iv, tagLength }
|
|
267
|
+
: { name: 'AES-GCM', additionalData, iv, tagLength };
|
|
268
|
+
// Encrypt the data.
|
|
269
|
+
const ciphertextBuffer = yield webCrypto.encrypt(algorithm, webCryptoKey, data);
|
|
270
|
+
// Convert from ArrayBuffer to Uint8Array.
|
|
271
|
+
const ciphertext = new Uint8Array(ciphertextBuffer);
|
|
272
|
+
return ciphertext;
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Generates a symmetric key for AES in Galois/Counter Mode (GCM) in JSON Web Key (JWK) format.
|
|
277
|
+
*
|
|
278
|
+
* @remarks
|
|
279
|
+
* This method creates a new symmetric key of a specified length suitable for use with
|
|
280
|
+
* AES-GCM encryption. It leverages cryptographically secure random number generation
|
|
281
|
+
* to ensure the uniqueness and security of the key. The generated key adheres to the JWK
|
|
282
|
+
* format, facilitating compatibility with common cryptographic standards and ease of use
|
|
283
|
+
* in various cryptographic applications.
|
|
284
|
+
*
|
|
285
|
+
* The generated key includes these components:
|
|
286
|
+
* - `kty`: Key Type, set to 'oct' for Octet Sequence, indicating a symmetric key.
|
|
287
|
+
* - `k`: The symmetric key component, base64url-encoded.
|
|
288
|
+
* - `kid`: Key ID, generated based on the JWK thumbprint, providing a unique identifier.
|
|
289
|
+
*
|
|
290
|
+
* @example
|
|
291
|
+
* ```ts
|
|
292
|
+
* const length = 256; // Length of the key in bits (e.g., 128, 192, 256)
|
|
293
|
+
* const privateKey = await AesGcm.generateKey({ length });
|
|
294
|
+
* ```
|
|
295
|
+
*
|
|
296
|
+
* @param params - The parameters for the key generation.
|
|
297
|
+
* @param params.length - The length of the key in bits. Common lengths are 128, 192, and 256 bits.
|
|
298
|
+
*
|
|
299
|
+
* @returns A Promise that resolves to the generated symmetric key in JWK format.
|
|
300
|
+
*/
|
|
301
|
+
static generateKey({ length }) {
|
|
302
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
303
|
+
// Validate the key length.
|
|
304
|
+
if (!AES_KEY_LENGTHS.includes(length)) {
|
|
305
|
+
throw new RangeError(`The key length is invalid: Must be ${AES_KEY_LENGTHS.join(', ')} bits`);
|
|
306
|
+
}
|
|
307
|
+
// Get the Web Crypto API interface.
|
|
308
|
+
const webCrypto = getWebcryptoSubtle();
|
|
309
|
+
// Generate a random private key.
|
|
310
|
+
// See https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues#usage_notes for
|
|
311
|
+
// an explanation for why Web Crypto generateKey() is used instead of getRandomValues().
|
|
312
|
+
const webCryptoKey = yield webCrypto.generateKey({ name: 'AES-GCM', length }, true, ['encrypt']);
|
|
313
|
+
// Export the private key in JWK format.
|
|
314
|
+
const _a = yield webCrypto.exportKey('jwk', webCryptoKey), { ext, key_ops } = _a, privateKey = __rest(_a, ["ext", "key_ops"]);
|
|
315
|
+
// Compute the JWK thumbprint and set as the key ID.
|
|
316
|
+
privateKey.kid = yield computeJwkThumbprint({ jwk: privateKey });
|
|
317
|
+
return privateKey;
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Converts a private key from JSON Web Key (JWK) format to a raw byte array (Uint8Array).
|
|
322
|
+
*
|
|
323
|
+
* @remarks
|
|
324
|
+
* This method takes a symmetric key in JWK format and extracts its raw byte representation.
|
|
325
|
+
* It focuses on the 'k' parameter of the JWK, which represents the symmetric key component
|
|
326
|
+
* in base64url encoding. The method decodes this value into a byte array, providing
|
|
327
|
+
* the symmetric key in its raw binary form.
|
|
328
|
+
*
|
|
329
|
+
* @example
|
|
330
|
+
* ```ts
|
|
331
|
+
* const privateKey = { ... }; // A symmetric key in JWK format
|
|
332
|
+
* const privateKeyBytes = await AesGcm.privateKeyToBytes({ privateKey });
|
|
333
|
+
* ```
|
|
334
|
+
*
|
|
335
|
+
* @param params - The parameters for the symmetric key conversion.
|
|
336
|
+
* @param params.privateKey - The symmetric key in JWK format.
|
|
337
|
+
*
|
|
338
|
+
* @returns A Promise that resolves to the symmetric key as a Uint8Array.
|
|
339
|
+
*/
|
|
340
|
+
static privateKeyToBytes({ privateKey }) {
|
|
341
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
342
|
+
// Verify the provided JWK represents a valid oct private key.
|
|
343
|
+
if (!isOctPrivateJwk(privateKey)) {
|
|
344
|
+
throw new Error(`AesGcm: The provided key is not a valid oct private key.`);
|
|
345
|
+
}
|
|
346
|
+
// Decode the provided private key to bytes.
|
|
347
|
+
const privateKeyBytes = Convert.base64Url(privateKey.k).toUint8Array();
|
|
348
|
+
return privateKeyBytes;
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
//# sourceMappingURL=aes-gcm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aes-gcm.js","sourceRoot":"","sources":["../../../../../src/prototyping/crypto/primitives/aes-gcm.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAI9D,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEtE;;;;;;;;;;;;GAYG;AACH,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAE7B;;;;;;;;;;;;GAYG;AACH,MAAM,eAAe,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAU,CAAC;AAEjD;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAU,CAAC;AAErE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,MAAM,OAAO,MAAM;IACjB;;;;;;;;;;;;;;;;;;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GAAG,MAAM,oBAAoB,CAAC,EAAE,GAAG,EAAE,UAAU,EAAE,CAAC,CAAC;YAEjE,OAAO,UAAU,CAAC;QACpB,CAAC;KAAA;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACI,MAAM,CAAO,iBAAiB,CAAC,EAAE,UAAU,EAEjD;;YACC,8DAA8D;YAC9D,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,EAAE;gBAChC,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;aAC7E;YAED,4CAA4C;YAC5C,MAAM,eAAe,GAAG,OAAO,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,YAAY,EAAE,CAAC;YAEvE,OAAO,eAAe,CAAC;QACzB,CAAC;KAAA;CACF"}
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
11
|
+
var t = {};
|
|
12
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
13
|
+
t[p] = s[p];
|
|
14
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
15
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
16
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
17
|
+
t[p[i]] = s[p[i]];
|
|
18
|
+
}
|
|
19
|
+
return t;
|
|
20
|
+
};
|
|
21
|
+
// ! TODO : Make sure I remove `@noble/ciphers` from the Agent package.json once this is moved to the `@enbox/crypto` package.
|
|
22
|
+
import { getWebcryptoSubtle } from '@noble/ciphers/webcrypto';
|
|
23
|
+
import { Convert } from '@enbox/common';
|
|
24
|
+
import { computeJwkThumbprint, isOctPrivateJwk } from '@enbox/crypto';
|
|
25
|
+
import { CryptoError, CryptoErrorCode } from '../crypto-error.js';
|
|
26
|
+
/**
|
|
27
|
+
* Constant defining the AES key length values in bits.
|
|
28
|
+
*
|
|
29
|
+
* @remarks
|
|
30
|
+
* NIST publication FIPS 197 states:
|
|
31
|
+
* > The AES algorithm is capable of using cryptographic keys of 128, 192, and 256 bits to encrypt
|
|
32
|
+
* > and decrypt data in blocks of 128 bits.
|
|
33
|
+
*
|
|
34
|
+
* This implementation does not support key lengths that are different from the three values
|
|
35
|
+
* defined by this constant.
|
|
36
|
+
*
|
|
37
|
+
* @see {@link https://doi.org/10.6028/NIST.FIPS.197-upd1 | NIST FIPS 197}
|
|
38
|
+
*/
|
|
39
|
+
const AES_KEY_LENGTHS = [128, 192, 256];
|
|
40
|
+
export class AesKw {
|
|
41
|
+
/**
|
|
42
|
+
* Converts a raw private key in bytes to its corresponding JSON Web Key (JWK) format.
|
|
43
|
+
*
|
|
44
|
+
* @remarks
|
|
45
|
+
* This method takes a symmetric key represented as a byte array (Uint8Array) and
|
|
46
|
+
* converts it into a JWK object for use with AES (Advanced Encryption Standard)
|
|
47
|
+
* for key wrapping. The conversion process involves encoding the key into
|
|
48
|
+
* base64url format and setting the appropriate JWK parameters.
|
|
49
|
+
*
|
|
50
|
+
* The resulting JWK object includes the following properties:
|
|
51
|
+
* - `kty`: Key Type, set to 'oct' for Octet Sequence (representing a symmetric key).
|
|
52
|
+
* - `k`: The symmetric key, base64url-encoded.
|
|
53
|
+
* - `kid`: Key ID, generated based on the JWK thumbprint.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* const privateKeyBytes = new Uint8Array([...]); // Replace with actual symmetric key bytes
|
|
58
|
+
* const privateKey = await AesKw.bytesToPrivateKey({ privateKeyBytes });
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* @param params - The parameters for the symmetric key conversion.
|
|
62
|
+
* @param params.privateKeyBytes - The raw symmetric key as a Uint8Array.
|
|
63
|
+
*
|
|
64
|
+
* @returns A Promise that resolves to the symmetric key in JWK format.
|
|
65
|
+
*/
|
|
66
|
+
static bytesToPrivateKey({ privateKeyBytes }) {
|
|
67
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
// Construct the private key in JWK format.
|
|
69
|
+
const privateKey = {
|
|
70
|
+
k: Convert.uint8Array(privateKeyBytes).toBase64Url(),
|
|
71
|
+
kty: 'oct'
|
|
72
|
+
};
|
|
73
|
+
// Compute the JWK thumbprint and set as the key ID.
|
|
74
|
+
privateKey.kid = yield computeJwkThumbprint({ jwk: privateKey });
|
|
75
|
+
// Add algorithm identifier based on key length.
|
|
76
|
+
const lengthInBits = privateKeyBytes.length * 8;
|
|
77
|
+
privateKey.alg = { 128: 'A128KW', 192: 'A192KW', 256: 'A256KW' }[lengthInBits];
|
|
78
|
+
return privateKey;
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Generates a symmetric key for AES for key wrapping in JSON Web Key (JWK) format.
|
|
83
|
+
*
|
|
84
|
+
* @remarks
|
|
85
|
+
* This method creates a new symmetric key of a specified length suitable for use with
|
|
86
|
+
* AES key wrapping. It uses cryptographically secure random number generation to
|
|
87
|
+
* ensure the uniqueness and security of the key. The generated key adheres to the JWK
|
|
88
|
+
* format, making it compatible with common cryptographic standards and easy to use in
|
|
89
|
+
* various cryptographic processes.
|
|
90
|
+
*
|
|
91
|
+
* The generated key includes the following components:
|
|
92
|
+
* - `kty`: Key Type, set to 'oct' for Octet Sequence.
|
|
93
|
+
* - `k`: The symmetric key component, base64url-encoded.
|
|
94
|
+
* - `kid`: Key ID, generated based on the JWK thumbprint.
|
|
95
|
+
* - `alg`: Algorithm, set to 'A128KW', 'A192KW', or 'A256KW' for AES Key Wrap with the
|
|
96
|
+
* specified key length.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```ts
|
|
100
|
+
* const length = 256; // Length of the key in bits (e.g., 128, 192, 256)
|
|
101
|
+
* const privateKey = await AesKw.generateKey({ length });
|
|
102
|
+
* ```
|
|
103
|
+
*
|
|
104
|
+
* @param params - The parameters for the key generation.
|
|
105
|
+
* @param params.length - The length of the key in bits. Common lengths are 128, 192, and 256 bits.
|
|
106
|
+
*
|
|
107
|
+
* @returns A Promise that resolves to the generated symmetric key in JWK format.
|
|
108
|
+
*/
|
|
109
|
+
static generateKey({ length }) {
|
|
110
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
111
|
+
// Validate the key length.
|
|
112
|
+
if (!AES_KEY_LENGTHS.includes(length)) {
|
|
113
|
+
throw new RangeError(`The key length is invalid: Must be ${AES_KEY_LENGTHS.join(', ')} bits`);
|
|
114
|
+
}
|
|
115
|
+
// Get the Web Crypto API interface.
|
|
116
|
+
const webCrypto = getWebcryptoSubtle();
|
|
117
|
+
// Generate a random private key.
|
|
118
|
+
// See https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues#usage_notes for
|
|
119
|
+
// an explanation for why Web Crypto generateKey() is used instead of getRandomValues().
|
|
120
|
+
const webCryptoKey = yield webCrypto.generateKey({ name: 'AES-KW', length }, true, ['wrapKey', 'unwrapKey']);
|
|
121
|
+
// Export the private key in JWK format.
|
|
122
|
+
const _a = yield webCrypto.exportKey('jwk', webCryptoKey), { ext, key_ops } = _a, privateKey = __rest(_a, ["ext", "key_ops"]);
|
|
123
|
+
// Compute the JWK thumbprint and set as the key ID.
|
|
124
|
+
privateKey.kid = yield computeJwkThumbprint({ jwk: privateKey });
|
|
125
|
+
return privateKey;
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Converts a private key from JSON Web Key (JWK) format to a raw byte array (Uint8Array).
|
|
130
|
+
*
|
|
131
|
+
* @remarks
|
|
132
|
+
* This method takes a symmetric key in JWK format and extracts its raw byte representation.
|
|
133
|
+
* It decodes the 'k' parameter of the JWK value, which represents the symmetric key in base64url
|
|
134
|
+
* encoding, into a byte array.
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```ts
|
|
138
|
+
* const privateKey = { ... }; // A symmetric key in JWK format
|
|
139
|
+
* const privateKeyBytes = await AesKw.privateKeyToBytes({ privateKey });
|
|
140
|
+
* ```
|
|
141
|
+
*
|
|
142
|
+
* @param params - The parameters for the symmetric key conversion.
|
|
143
|
+
* @param params.privateKey - The symmetric key in JWK format.
|
|
144
|
+
*
|
|
145
|
+
* @returns A Promise that resolves to the symmetric key as a Uint8Array.
|
|
146
|
+
*/
|
|
147
|
+
static privateKeyToBytes({ privateKey }) {
|
|
148
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
149
|
+
// Verify the provided JWK represents a valid oct private key.
|
|
150
|
+
if (!isOctPrivateJwk(privateKey)) {
|
|
151
|
+
throw new Error(`AesKw: The provided key is not a valid oct private key.`);
|
|
152
|
+
}
|
|
153
|
+
// Decode the provided private key to bytes.
|
|
154
|
+
const privateKeyBytes = Convert.base64Url(privateKey.k).toUint8Array();
|
|
155
|
+
return privateKeyBytes;
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
static unwrapKey({ wrappedKeyBytes, wrappedKeyAlgorithm, decryptionKey }) {
|
|
159
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
160
|
+
if (!('alg' in decryptionKey && decryptionKey.alg)) {
|
|
161
|
+
throw new CryptoError(CryptoErrorCode.InvalidJwk, `The decryption key is missing the 'alg' property.`);
|
|
162
|
+
}
|
|
163
|
+
if (!['A128KW', 'A192KW', 'A256KW'].includes(decryptionKey.alg)) {
|
|
164
|
+
throw new CryptoError(CryptoErrorCode.AlgorithmNotSupported, `The 'decryptionKey' algorithm is not supported: ${decryptionKey.alg}`);
|
|
165
|
+
}
|
|
166
|
+
// Get the Web Crypto API interface.
|
|
167
|
+
const webCrypto = getWebcryptoSubtle();
|
|
168
|
+
// Import the decryption key for use with the Web Crypto API.
|
|
169
|
+
const decryptionCryptoKey = yield webCrypto.importKey('jwk', // key format
|
|
170
|
+
decryptionKey, // key data
|
|
171
|
+
{ name: 'AES-KW' }, // algorithm identifier
|
|
172
|
+
true, // key is extractable
|
|
173
|
+
['unwrapKey'] // key usages
|
|
174
|
+
);
|
|
175
|
+
// Map the private key's JOSE algorithm name to the Web Crypto API algorithm identifier.
|
|
176
|
+
const webCryptoAlgorithm = {
|
|
177
|
+
A128KW: 'AES-KW', A192KW: 'AES-KW', A256KW: 'AES-KW',
|
|
178
|
+
A128GCM: 'AES-GCM', A192GCM: 'AES-GCM', A256GCM: 'AES-GCM',
|
|
179
|
+
}[wrappedKeyAlgorithm];
|
|
180
|
+
if (!webCryptoAlgorithm) {
|
|
181
|
+
throw new CryptoError(CryptoErrorCode.AlgorithmNotSupported, `The 'wrappedKeyAlgorithm' is not supported: ${wrappedKeyAlgorithm}`);
|
|
182
|
+
}
|
|
183
|
+
// Unwrap the key using the Web Crypto API.
|
|
184
|
+
const unwrappedCryptoKey = yield webCrypto.unwrapKey('raw', // output format
|
|
185
|
+
wrappedKeyBytes.buffer, // key to unwrap
|
|
186
|
+
decryptionCryptoKey, // unwrapping key
|
|
187
|
+
'AES-KW', // algorithm identifier
|
|
188
|
+
{ name: webCryptoAlgorithm }, // unwrapped key algorithm identifier
|
|
189
|
+
true, // key is extractable
|
|
190
|
+
['unwrapKey'] // key usages
|
|
191
|
+
);
|
|
192
|
+
// Export the unwrapped key in JWK format.
|
|
193
|
+
const _a = yield webCrypto.exportKey('jwk', unwrappedCryptoKey), { ext, key_ops } = _a, unwrappedJsonWebKey = __rest(_a, ["ext", "key_ops"]);
|
|
194
|
+
const unwrappedKey = unwrappedJsonWebKey;
|
|
195
|
+
// Compute the JWK thumbprint and set as the key ID.
|
|
196
|
+
unwrappedKey.kid = yield computeJwkThumbprint({ jwk: unwrappedKey });
|
|
197
|
+
return unwrappedKey;
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
static wrapKey({ unwrappedKey, encryptionKey }) {
|
|
201
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
202
|
+
if (!('alg' in encryptionKey && encryptionKey.alg)) {
|
|
203
|
+
throw new CryptoError(CryptoErrorCode.InvalidJwk, `The encryption key is missing the 'alg' property.`);
|
|
204
|
+
}
|
|
205
|
+
if (!['A128KW', 'A192KW', 'A256KW'].includes(encryptionKey.alg)) {
|
|
206
|
+
throw new CryptoError(CryptoErrorCode.AlgorithmNotSupported, `The 'encryptionKey' algorithm is not supported: ${encryptionKey.alg}`);
|
|
207
|
+
}
|
|
208
|
+
if (!('alg' in unwrappedKey && unwrappedKey.alg)) {
|
|
209
|
+
throw new CryptoError(CryptoErrorCode.InvalidJwk, `The private key to wrap is missing the 'alg' property.`);
|
|
210
|
+
}
|
|
211
|
+
// Get the Web Crypto API interface.
|
|
212
|
+
const webCrypto = getWebcryptoSubtle();
|
|
213
|
+
// Import the encryption key for use with the Web Crypto API.
|
|
214
|
+
const encryptionCryptoKey = yield webCrypto.importKey('jwk', // key format
|
|
215
|
+
encryptionKey, // key data
|
|
216
|
+
{ name: 'AES-KW' }, // algorithm identifier
|
|
217
|
+
true, // key is extractable
|
|
218
|
+
['wrapKey'] // key usages
|
|
219
|
+
);
|
|
220
|
+
// Map the private key's JOSE algorithm name to the Web Crypto API algorithm identifier.
|
|
221
|
+
const webCryptoAlgorithm = {
|
|
222
|
+
A128KW: 'AES-KW', A192KW: 'AES-KW', A256KW: 'AES-KW',
|
|
223
|
+
A128GCM: 'AES-GCM', A192GCM: 'AES-GCM', A256GCM: 'AES-GCM',
|
|
224
|
+
}[unwrappedKey.alg];
|
|
225
|
+
if (!webCryptoAlgorithm) {
|
|
226
|
+
throw new CryptoError(CryptoErrorCode.AlgorithmNotSupported, `The 'unwrappedKey' algorithm is not supported: ${unwrappedKey.alg}`);
|
|
227
|
+
}
|
|
228
|
+
// Import the private key to wrap for use with the Web Crypto API.
|
|
229
|
+
const unwrappedCryptoKey = yield webCrypto.importKey('jwk', // key format
|
|
230
|
+
unwrappedKey, // key data
|
|
231
|
+
{ name: webCryptoAlgorithm }, // algorithm identifier
|
|
232
|
+
true, // key is extractable
|
|
233
|
+
['unwrapKey'] // key usages
|
|
234
|
+
);
|
|
235
|
+
// Wrap the key using the Web Crypto API.
|
|
236
|
+
const wrappedKeyBuffer = yield webCrypto.wrapKey('raw', // output format
|
|
237
|
+
unwrappedCryptoKey, // key to wrap
|
|
238
|
+
encryptionCryptoKey, // wrapping key
|
|
239
|
+
'AES-KW' // algorithm identifier
|
|
240
|
+
);
|
|
241
|
+
// Convert from ArrayBuffer to Uint8Array.
|
|
242
|
+
const wrappedKeyBytes = new Uint8Array(wrappedKeyBuffer);
|
|
243
|
+
return wrappedKeyBytes;
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
//# sourceMappingURL=aes-kw.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aes-kw.js","sourceRoot":"","sources":["../../../../../src/prototyping/crypto/primitives/aes-kw.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,8HAA8H;AAC9H,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAI9D,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAGtE,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAElE;;;;;;;;;;;;GAYG;AACH,MAAM,eAAe,GAAG,CAAC,GAAG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