Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add secret header to SideShift #353

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/swap/central/sideshift.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ interface CreateSideshiftApiResponse {

const createSideshiftApi = (
baseUrl: string,
fetchCors: EdgeFetchFunction
fetchCors: EdgeFetchFunction,
privateKey?: string
): CreateSideshiftApiResponse => {
async function request<R>(
method: 'GET' | 'POST',
Expand All @@ -161,12 +162,17 @@ const createSideshiftApi = (
): Promise<R> {
const url = `${baseUrl}${path}`

const headers = {
'x-sideshift-secret': privateKey
}

const reply = await (method === 'GET'
? fetchCors(url)
? fetchCors(url, { headers })
: fetchCors(url, {
method,
headers: {
'Content-Type': 'application/json'
'Content-Type': 'application/json',
...headers
},
body: JSON.stringify(body)
}))
Expand Down Expand Up @@ -352,7 +358,7 @@ export function makeSideshiftPlugin(
opts: EdgeCorePluginOptions
): EdgeSwapPlugin {
const { io, initOptions } = opts
const api = createSideshiftApi(SIDESHIFT_BASE_URL, io.fetchCors ?? io.fetch)
const api = createSideshiftApi(SIDESHIFT_BASE_URL, io.fetchCors ?? io.fetch, initOptions.privateKey)
const fetchSwapQuote = createFetchSwapQuote(api, initOptions.affiliateId)

return {
Expand Down
Loading