Skip to content

Commit 47ed1ff

Browse files
committed
Changed solana authentication parameters
* It's not needed to pass whole SWIS payload, only address and nonce are sufficient
1 parent fabd80a commit 47ed1ff

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

src/controllers/v1/authenticationController.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,15 @@ export class AuthenticationController {
4040
@Body() body: solanaAuthenticateRequest,
4141
): Promise<AuthenticationResponse> {
4242
try {
43-
const { signature, message, payload } = body;
43+
const { signature, message, nonce, address } = body;
4444

4545
const header = new Header();
4646
header.t = 'sip99';
4747

4848
const msg = new SIWS(message);
49+
const payload = new Payload();
50+
payload.address = address;
51+
payload.nonce = nonce;
4952

5053
const result = await msg.verify({
5154
payload,
@@ -62,7 +65,7 @@ export class AuthenticationController {
6265
);
6366
}
6467

65-
return await this.issueToken(payload, payload.nonce);
68+
return await this.issueToken(result.data.payload, nonce);
6669
} catch (e) {
6770
logger.error('authenticationController error', e);
6871
throw e;

src/routes/v1/authenticationRouter.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ function authenticationTestCases() {
101101
payload.uri = origin;
102102
payload.statement = 'This is a test statement';
103103
payload.version = '1';
104-
payload.chainId = 0;
105104
payload.nonce = nonce;
106105

107106
const message = new SIWS({
@@ -117,7 +116,8 @@ function authenticationTestCases() {
117116
const data = {
118117
message,
119118
signature: base58.encode(signature),
120-
payload: payload,
119+
address: solanaPublicKey,
120+
nonce,
121121
};
122122
const result = await axios.post(
123123
`${serverUrl}/v1/solanaAuthentication`,

src/routes/v1/authenticationRouter.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,22 @@ authenticationRouter.post(
3232
'/solanaAuthentication',
3333
async (req: Request, res: Response, next) => {
3434
try {
35-
if (!req.body.payload || !req.body.signature || !req.body.message) {
35+
if (
36+
!req.body.message ||
37+
!req.body.nonce ||
38+
!req.body.signature ||
39+
!req.body.address
40+
) {
3641
res.status(422).json({ message: errorMessagesEnum.MISSING_LOGIN_DATA });
3742
return;
3843
}
3944

40-
const { message, signature, payload } = req.body;
45+
const { nonce, message, signature, address } = req.body;
4146
const result = await authController.solanaAuthenticate({
4247
message,
4348
signature,
44-
payload,
49+
address,
50+
nonce,
4551
});
4652
res.send(result);
4753
} catch (e) {

src/types/requestResponses.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { Payload } from '@web3auth/sign-in-with-solana';
21
import { JwtPayload } from '../services/jwtService';
32

43
export type AuthenticationRequest = {
@@ -7,8 +6,8 @@ export type AuthenticationRequest = {
76
nonce: string;
87
};
98

10-
export type solanaAuthenticateRequest = Omit<AuthenticationRequest, 'nonce'> & {
11-
payload: Payload;
9+
export type solanaAuthenticateRequest = AuthenticationRequest & {
10+
address: string;
1211
};
1312

1413
export type MultisigAuthenticationRequest = {

0 commit comments

Comments
 (0)