Skip to content

Commit

Permalink
OG-1021: Missing trailing '/' in URLs breaks relay URLs with paths (#957
Browse files Browse the repository at this point in the history
)
  • Loading branch information
forshtat authored Mar 16, 2023
1 parent 3ce127e commit 3a2cf29
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
9 changes: 5 additions & 4 deletions packages/common/src/HttpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { RelayTransactionRequest } from './types/RelayTransactionRequest'
import { AuditRequest, AuditResponse } from './types/AuditRequest'
import { ConfigResponse } from './ConfigResponse'
import { Address, ObjectMap } from './types/Aliases'
import { appendSlashTrim } from './Utils'

export class HttpClient {
private readonly httpWrapper: HttpWrapper
Expand All @@ -19,7 +20,7 @@ export class HttpClient {
}

async getPingResponse (relayUrl: string, paymaster?: string): Promise<PingResponse> {
const url = new URL('getaddr', relayUrl.trim())
const url = new URL('getaddr', appendSlashTrim(relayUrl))
if (paymaster != null) {
url.searchParams.set('paymaster', paymaster)
}
Expand All @@ -32,7 +33,7 @@ export class HttpClient {
}

async relayTransaction (relayUrl: string, request: RelayTransactionRequest): Promise<{ signedTx: PrefixedHexString, nonceGapFilled: ObjectMap<PrefixedHexString> }> {
const url = new URL('relay', relayUrl.trim())
const url = new URL('relay', appendSlashTrim(relayUrl))
const {
signedTx,
nonceGapFilled,
Expand All @@ -49,7 +50,7 @@ export class HttpClient {
}

async auditTransaction (relayUrl: string, signedTx: PrefixedHexString): Promise<AuditResponse> {
const url = new URL('audit', relayUrl.trim())
const url = new URL('audit', appendSlashTrim(relayUrl))
const auditRequest: AuditRequest = { signedTx }
const auditResponse: AuditResponse = await this.httpWrapper.sendPromise(url, auditRequest)
this.logger.info(`auditTransaction response: ${JSON.stringify(auditResponse)}`)
Expand All @@ -63,7 +64,7 @@ export class HttpClient {
}

async getVerifyingPaymasterAddress (verifierServerUrl: string, chainId: number): Promise<Address> {
const url = new URL('getPaymasterAddress', verifierServerUrl.trim())
const url = new URL('getPaymasterAddress', appendSlashTrim(verifierServerUrl))
url.searchParams.set('chainId', chainId.toString())
const { paymasterAddress } = await this.httpWrapper.sendPromise(url)
this.logger.info(`VerifyingPaymaster address: ${JSON.stringify(paymasterAddress)}`)
Expand Down
8 changes: 8 additions & 0 deletions packages/common/src/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,3 +539,11 @@ export function wrapWeb3JsProvider (provider: any): JsonRpcProvider {
}
return provider
}

export function appendSlashTrim (urlInput: string): string {
urlInput = urlInput.trim()
if (urlInput[urlInput.length - 1] !== '/') {
urlInput += '/'
}
return urlInput
}
4 changes: 2 additions & 2 deletions packages/provider/src/VerifierUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PrefixedHexString } from 'ethereumjs-util'
import { ApprovalDataCallback, HttpWrapper, LoggerInterface, RelayRequest } from '@opengsn/common'
import { ApprovalDataCallback, HttpWrapper, LoggerInterface, RelayRequest, appendSlashTrim } from '@opengsn/common'

// TODO: replace with production URL before release
export const DEFAULT_VERIFIER_SERVER_URL = 'https://staging-api.opengsn.org'
Expand Down Expand Up @@ -32,7 +32,7 @@ export function createVerifierApprovalDataCallback (
relayRequest,
relayRequestId
}
const signRelayRequestResponse = await httpWrapper.sendPromise(new URL('signRelayRequest', verifierUrl), approvalRequest)
const signRelayRequestResponse = await httpWrapper.sendPromise(new URL('signRelayRequest', appendSlashTrim(verifierUrl)), approvalRequest)
logger.info(`signRelayRequest response: ${JSON.stringify(signRelayRequestResponse)}`)
return signRelayRequestResponse.signature
}
Expand Down

0 comments on commit 3a2cf29

Please sign in to comment.