Skip to content

Commit 75ccca7

Browse files
committed
chore: cleaned up error reporting
chore: cleaned up code
1 parent df4ed99 commit 75ccca7

File tree

5 files changed

+16
-5
lines changed

5 files changed

+16
-5
lines changed

src/client/callers/authSignToken.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { HandlerTypes } from '@matrixai/rpc';
2-
import type AuthSignToken from '../handlers/AgentLockAll.js';
2+
import type AuthSignToken from '../handlers/AuthSignToken.js';
33
import { UnaryCaller } from '@matrixai/rpc';
44

55
type CallerTypes = HandlerTypes<AuthSignToken>;

src/client/errors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class ErrorClientVerificationFailed<T> extends ErrorClientService<T> {
5353
class ErrorAuthentication<T> extends ErrorPolykey<T> {}
5454

5555
class ErrorAuthenticationInvalidToken<T> extends ErrorAuthentication<T> {
56-
static description = 'Incoming token does not match its signature';
56+
static description = 'Token is invalid';
5757
exitCode = sysexits.PROTOCOL;
5858
}
5959

src/client/handlers/AuthSignToken.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,19 @@ class AuthSignToken extends UnaryHandler<
2828
// Get and verify incoming node
2929
const inputToken = { payload: input.payload, signatures: input.signatures };
3030
const incomingToken = Token.fromEncoded<IdentityRequestData>(inputToken);
31+
if (!('publicKey' in incomingToken.payload)) {
32+
throw new clientErrors.ErrorAuthenticationInvalidToken(
33+
'Input token does not contain public key',
34+
);
35+
}
3136
const incomingPublicKey = Buffer.from(
3237
incomingToken.payload.publicKey,
38+
'base64url',
3339
) as PublicKey;
3440
if (!incomingToken.verifyWithPublicKey(incomingPublicKey)) {
35-
throw new clientErrors.ErrorAuthenticationInvalidToken();
41+
throw new clientErrors.ErrorAuthenticationInvalidToken(
42+
'Incoming token does not match its signature',
43+
);
3644
}
3745

3846
// Create the outgoing token with the incoming token integrated into the

src/client/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ type TokenMessage = {
111111
// Return URL must be present on the token, otherwise token contents is decided
112112
// by the client.
113113
type IdentityRequestData = TokenPayload & {
114-
returnUrl: string;
114+
returnURL: string;
115115
publicKey: string;
116116
};
117117

src/network/utils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,10 @@ function fromError(error: any) {
477477
// serialising only the error type, message and its stack.
478478
const wrappedError = new errors.ErrorPolykeyUnexpected(
479479
`Unexpected error occurred: ${error.name}`,
480-
{ cause: error },
480+
{
481+
cause: error,
482+
data: { message: 'message' in error ? error.message : undefined },
483+
},
481484
);
482485
return wrappedError.toJSON();
483486
}

0 commit comments

Comments
 (0)