Skip to content

Commit

Permalink
fix: comments
Browse files Browse the repository at this point in the history
  • Loading branch information
eruizgar91 committed Aug 8, 2024
1 parent b67cbd8 commit f4de552
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/common/guards/auth/session-key.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ export class SessionKeyAuthGuard implements CanActivate {
const clientAssertion: ClientAssertion = req.body
const payload = await parseJwt(clientAssertion.client_assertion)
request.payload = payload
if (!clientAssertion.nevermined_api_key) {
if (!clientAssertion.nvm_key_hash) {
throw new Error('Invalid NVM API Key')
}

const nvmApiKey = await this.backendService.validateApiKey(clientAssertion.nevermined_api_key)
const nvmApiKey = await this.backendService.validateApiKey(clientAssertion.nvm_key_hash)
if (!nvmApiKey) {
throw new Error('Invalid NVM API Key')
}
Expand Down
10 changes: 5 additions & 5 deletions src/common/helpers/jwt.utils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Logger } from '@nestjs/common'
import { ethers } from 'ethers'
import * as jose from 'jose'
import { getChecksumAddress, isValidAddress } from '@nevermined-io/sdk'

export interface ClientAssertion {
client_assertion_type: string
client_assertion: string
nevermined_api_key?: string
nvm_key_hash?: string
}

export interface Eip712Data {
Expand Down Expand Up @@ -54,12 +54,12 @@ export const parseJwt = async (jwt: string): Promise<JWTPayload> => {
throw new JwtEthVerifyError('Payload: "iss" field is required')
}

const isValidAddress = ethers.isAddress(parsedPayload.iss)
if (!isValidAddress) {
const isValid = isValidAddress(parsedPayload.iss)
if (!isValid) {
Logger.error('Payload: "iss" field must be a valid ethereum address')
throw new JwtEthVerifyError('Payload: "iss" field must be a valid ethereum address')
}
const isChecksumAddress = ethers.getAddress(parsedPayload.iss) === parsedPayload.iss
const isChecksumAddress = getChecksumAddress(parsedPayload.iss) === parsedPayload.iss
if (!isChecksumAddress) {
Logger.error('Payload: "iss" field must be a checksum address')
throw new JwtEthVerifyError('Payload: "iss" field must be a checksum address')
Expand Down

0 comments on commit f4de552

Please # to comment.