fix(askar): use NativeAskar.instance instead of the deprecated askar export#2843
fix(askar): use NativeAskar.instance instead of the deprecated askar export#2843tarunvadde wants to merge 1 commit into
Conversation
…export Signed-off-by: Tarun Vadde <vaddeofficial@gmail.com>
🦋 Changeset detectedLatest commit: fc49aa2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 18 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
| @@ -1,5 +1,5 @@ | |||
| import { Kms, TypedArrayEncoder } from '@credo-ts/core' | |||
| import { askar, Key } from '@openwallet-foundation/askar-shared' | |||
| import { Key, NativeAskar } from '@openwallet-foundation/askar-shared' | |||
There was a problem hiding this comment.
I think we should try to read Askar from the module config: https://github.com/openwallet-foundation/credo-ts/blob/main/packages/askar/src/AskarModuleConfig.ts#L130
- inject Moduleconfig on agent context
- extract askar instance from it
- We should probably update the
askargetter in the module config, to see if Askar is passed or theNativeAskar?
There was a problem hiding this comment.
Makes sense, reading the injected instance from AskarModuleConfig is cleaner than the global getter,.
Two things I want to confirm before I push it:
-
Scope.
deriveKey,fetchAskarKey, and encrypt/decrypt all haveagentContext, so those are straightforward. ButkeyFromJwk,privateJwkFromKey, andpublicJwkFromKeydon't receiveagentContext, and they're called from ~13 spots acrossgetPublicKey/createKey/sign/verify/encrypt/decrypt. Doing this consistently means threading the resolved instance through those helpers too (doing it only inderiveKeywould leave the JWK paths on the global, which defeats the purpose). Good with that? -
The getter.
askaris currently a required option, soconfig.askaralways resolves and a fallback isn't strictly needed. Do you want me to make it optional and fall back toNativeAskar.instancewhen it isn't passed? Heads up that this decides the peer range: with the fallback we keep referencingNativeAskar, soaskar-sharedstays at^0.6.0(changesetminor); ifaskarstays required, nothing referencesNativeAskaranymore and the peer can go back to the broad range (patch).
The KMS reads the askar binding through the deprecated
askarexport fromaskar-shared. That binding is only set as a side effect of importingaskar-nodejs, so if anything loads the KMS first (ESM, bundlers, test runners) it's stillundefinedand key ops throwCannot read properties of undefined (reading 'keyGetJwkSecret').This switches
AskarKeyManagementServiceand the ECDH derive helpers (plus the two tests that used it) toNativeAskar.instance, the getter added in askar 0.6.0 (openwallet-foundation/askar-wrapper-javascript#77 / #78), which resolves the binding on each call so import order stops mattering.NativeAskaronly exists from 0.6.0, so theaskar-sharedpeer is narrowed to^0.6.0and the changeset isminor. Flagging that this drops pre-0.6.0 support, in case anyone still pins an older askar.Relates to #2597, #2607.