@@ -31,7 +31,9 @@ export function loadNucToken<
3131 ) ;
3232 }
3333
34- const envelope = Codec . decodeBase64Url ( tokenString ) ;
34+ // We must use the unsafe decode first to extract the subject/claims required
35+ // to fetch the correct context (User/Builder) for validation
36+ const envelope = Codec . _unsafeDecodeBase64Url ( tokenString ) ;
3537 c . set ( "envelope" , envelope ) ;
3638
3739 return next ( ) ;
@@ -60,7 +62,9 @@ export function loadSubjectAndVerifyAsAdmin<
6062 return async ( c , next ) => {
6163 try {
6264 const envelope = c . get ( "envelope" ) ;
63- Validator . validate ( envelope , { rootIssuers : [ nildbNodeDid . didString ] } ) ;
65+ await Validator . validate ( envelope , {
66+ rootIssuers : [ nildbNodeDid . didString ] ,
67+ } ) ;
6468 return next ( ) ;
6569 } catch ( cause ) {
6670 if ( cause && typeof cause === "object" && "message" in cause ) {
@@ -127,7 +131,7 @@ export function loadSubjectAndVerifyAsBuilder<
127131 const nilauthDid = Did . fromPublicKey ( config . nilauthPubKey ) ;
128132 const nildbNodeDid = bindings . node . did ;
129133
130- Validator . validate ( envelope , {
134+ await Validator . validate ( envelope , {
131135 rootIssuers : [ nilauthDid . didString ] ,
132136 params : {
133137 tokenRequirements : {
@@ -215,7 +219,7 @@ export function loadSubjectAndVerifyAsUser<
215219 StatusCodes . UNAUTHORIZED ,
216220 ) ;
217221 }
218- Validator . validate ( envelope , {
222+ await Validator . validate ( envelope , {
219223 rootIssuers : [ subject ] ,
220224 } ) ;
221225 c . set ( "user" , user ) ;
0 commit comments