File tree Expand file tree Collapse file tree 3 files changed +18
-5
lines changed
Expand file tree Collapse file tree 3 files changed +18
-5
lines changed Original file line number Diff line number Diff line change 11import type {
22 ClientRPCRequestParams ,
33 ClientRPCResponseResult ,
4+ IdentityResponseData ,
5+ TokenIdentityResponse ,
46} from '../types.js' ;
5- import type { SignedTokenEncoded , TokenPayload } from '../../tokens/types.js' ;
67import type KeyRing from '../../keys/KeyRing.js' ;
78import { IdSortable } from '@matrixai/id' ;
89import { UnaryHandler } from '@matrixai/rpc' ;
@@ -15,16 +16,16 @@ class AuthIdentityToken extends UnaryHandler<
1516 keyRing : KeyRing ;
1617 } ,
1718 ClientRPCRequestParams ,
18- ClientRPCResponseResult < SignedTokenEncoded >
19+ ClientRPCResponseResult < TokenIdentityResponse >
1920> {
20- public handle = async ( ) : Promise < SignedTokenEncoded > => {
21+ public handle = async ( ) : Promise < TokenIdentityResponse > => {
2122 const { keyRing } : { keyRing : KeyRing } = this . container ;
2223 const idGen = new IdSortable ( ) ;
2324 const jti = idGen . next ( ) . value ;
2425 if ( jti == null ) {
2526 throw new clientErrors . ErrorClientAuthenticationInvalidJTI ( ) ;
2627 }
27- const outgoingToken = Token . fromPayload < TokenPayload > ( {
28+ const outgoingToken = Token . fromPayload < IdentityResponseData > ( {
2829 jti : jti . toMultibase ( 'base64' ) ,
2930 exp : Math . floor ( Date . now ( ) / 1000 ) + 60 , // 60 seconds after issuing
3031 iss : nodesUtils . encodeNodeId ( keyRing . getNodeId ( ) ) ,
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ import type {
2121} from '../keys/types.js' ;
2222import type { Notification } from '../notifications/types.js' ;
2323import type { ProviderToken } from '../identities/types.js' ;
24+ import type { TokenPayload , SignedTokenEncoded } from '../tokens/types.js' ;
2425import type { AuditMetricGetTypeOverride } from './callers/auditMetricGet.js' ;
2526import type {
2627 NodeContact ,
@@ -107,6 +108,14 @@ type TokenMessage = {
107108 token : ProviderToken ;
108109} ;
109110
111+ type IdentityResponseData = TokenPayload & {
112+ jti : string ;
113+ exp : number ;
114+ iss : NodeIdEncoded ;
115+ } ;
116+
117+ type TokenIdentityResponse = SignedTokenEncoded ;
118+
110119// Nodes messages
111120
112121type NodeIdMessage = {
@@ -405,6 +414,8 @@ export type {
405414 ClaimIdMessage ,
406415 ClaimNodeMessage ,
407416 TokenMessage ,
417+ IdentityResponseData ,
418+ TokenIdentityResponse ,
408419 NodeIdMessage ,
409420 AddressMessage ,
410421 NodeAddressMessage ,
Original file line number Diff line number Diff line change 1+ import type { IdentityResponseData } from '#src/client/types.js' ;
12import type { TLSConfig } from '#network/types.js' ;
23import fs from 'node:fs' ;
34import path from 'node:path' ;
@@ -89,7 +90,7 @@ describe('authIdentityToken', () => {
8990
9091 test ( 'should return a signed token' , async ( ) => {
9192 const identityToken = await rpcClient . methods . authIdentityToken ( { } ) ;
92- const decodedToken = Token . fromEncoded ( identityToken ) ;
93+ const decodedToken = Token . fromEncoded < IdentityResponseData > ( identityToken ) ;
9394 const decodedPublicKey = keysUtils . publicKeyFromNodeId ( keyRing . getNodeId ( ) ) ;
9495 expect ( decodedToken . verifyWithPublicKey ( decodedPublicKey ) ) . toBeTrue ( ) ;
9596 const encodedNodeId = nodesUtils . encodeNodeId ( keyRing . getNodeId ( ) ) ;
You can’t perform that action at this time.
0 commit comments