1- import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing" ;
1+ import { Secp256k1HdWallet } from "@cosmjs/amino" ;
2+ import type { AccountData } from "@cosmjs/proto-signing" ;
23import { beforeAll , describe , expect , it } from "@jest/globals" ;
34import fs from "fs" ;
45import path from "path" ;
@@ -8,28 +9,29 @@ import type { CreateJWTOptions } from "./jwt-token.ts";
89import { JwtTokenManager } from "./jwt-token.ts" ;
910import type { ClaimsTestCase , SigningTestCase } from "./test/test-utils.ts" ;
1011import { replaceTemplateValues } from "./test/test-utils.ts" ;
11- import { createSignArbitraryAkashWallet , type SignArbitraryAkashWallet } from "./wallet-utils.ts" ;
12+ import { createOfflineDataSigner } from "./wallet-utils.ts" ;
1213
1314describe ( "JWT Claims Validation" , ( ) => {
1415 const testdataPath = path . join ( __dirname , "../../../../../.." , "testdata" , "jwt" ) ;
1516 const jwtMnemonic = fs . readFileSync ( path . join ( testdataPath , "mnemonic" ) , "utf-8" ) . trim ( ) ;
1617 const jwtSigningTestCases = JSON . parse ( fs . readFileSync ( path . join ( testdataPath , "cases_es256k.json" ) , "utf-8" ) ) as SigningTestCase [ ] ;
1718 const jwtClaimsTestCases = JSON . parse ( fs . readFileSync ( path . join ( testdataPath , "cases_jwt.json.tmpl" ) , "utf-8" ) ) as ClaimsTestCase [ ] ;
1819
19- let testWallet : DirectSecp256k1HdWallet ;
20+ let testWallet : Secp256k1HdWallet ;
2021 let jwtToken : JwtTokenManager ;
21- let akashWallet : SignArbitraryAkashWallet ;
22+ let testAccount : AccountData ;
2223
2324 beforeAll ( async ( ) => {
24- testWallet = await DirectSecp256k1HdWallet . fromMnemonic ( jwtMnemonic , {
25+ testWallet = await Secp256k1HdWallet . fromMnemonic ( jwtMnemonic , {
2526 prefix : "akash" ,
2627 } ) ;
27- akashWallet = await createSignArbitraryAkashWallet ( testWallet ) ;
28- jwtToken = new JwtTokenManager ( akashWallet ) ;
28+ const [ account ] = await testWallet . getAccounts ( ) ;
29+ testAccount = account ;
30+ jwtToken = new JwtTokenManager ( testWallet ) ;
2931 } ) ;
3032
31- it . each ( jwtClaimsTestCases ) ( "$description" , async ( testCase ) => {
32- const { claims, tokenString } = replaceTemplateValues ( testCase ) ;
33+ it . each ( jwtClaimsTestCases . filter ( isSigningWithES256KADR36 ) ) ( "$description" , async ( testCase ) => {
34+ const { claims, tokenString } = replaceTemplateValues ( testCase , { iss : testAccount . address } ) ;
3335
3436 // For test cases that should fail, we need to validate the payload first
3537 if ( testCase . expected . signFail || testCase . expected . verifyFail ) {
@@ -54,16 +56,17 @@ describe("JWT Claims Validation", () => {
5456 }
5557 } ) ;
5658
57- it . each ( jwtSigningTestCases ) ( "$description" , async ( testCase ) => {
59+ it . each ( jwtSigningTestCases . filter ( isSigningWithES256KADR36 ) ) ( "$description" , async ( testCase ) => {
5860 const [ expectedHeader , expectedPayload , expectedSignature ] = testCase . tokenString . split ( "." ) ;
5961 expect ( expectedHeader ) . toBeDefined ( ) ;
6062 expect ( expectedPayload ) . toBeDefined ( ) ;
6163 expect ( expectedSignature ) . toBeDefined ( ) ;
6264
6365 const signingString = `${ expectedHeader } .${ expectedPayload } ` ;
6466
65- // Sign using the mock wallet's signArbitrary method
66- const signResponse = await akashWallet . signArbitrary ( akashWallet . address , signingString ) ;
67+ const signer = createOfflineDataSigner ( testWallet ) ;
68+ const [ account ] = await testWallet . getAccounts ( ) ;
69+ const signResponse = await signer . signArbitrary ( account . address , signingString ) ;
6770 const signature = toBase64Url ( signResponse . signature ) ;
6871
6972 if ( ! testCase . mustFail ) {
@@ -72,4 +75,8 @@ describe("JWT Claims Validation", () => {
7275 expect ( signature ) . not . toBe ( expectedSignature ) ;
7376 }
7477 } ) ;
78+
79+ function isSigningWithES256KADR36 ( testCase : SigningTestCase | ClaimsTestCase ) : boolean {
80+ return ! testCase . expected . alg || testCase . expected . alg === "ES256KADR36" ;
81+ }
7582} ) ;
0 commit comments