-
Notifications
You must be signed in to change notification settings - Fork 311
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/df 18971 gsr lwba endpoint (#2938)
* GSR LWBA endpoint * add changeset * update integration test * update tests * updates to separate price and lwba endpoints following discussion with GSR & associated changes * back to price endpoint alias due to GSR DP decision * review fix * update to use framework LWBA types * update readme endpoints * number readability --------- Co-authored-by: cl-ea <[email protected]>
- Loading branch information
1 parent
0f0d9be
commit 816452b
Showing
10 changed files
with
139 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@chainlink/gsr-adapter': minor | ||
--- | ||
|
||
Added LWBA endpoint for GSR EA |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import crypto from 'crypto' | ||
import axios from 'axios' | ||
import { makeLogger } from '@chainlink/external-adapter-framework/util' | ||
|
||
const logger = makeLogger('GSR Auth Token Utils') | ||
|
||
interface TokenError { | ||
success: false | ||
ts: number | ||
error: string | ||
} | ||
|
||
interface TokenSuccess { | ||
success: true | ||
ts: number | ||
token: string | ||
validUntil: string | ||
} | ||
|
||
type AccessTokenResponse = TokenError | TokenSuccess | ||
|
||
const currentTimeNanoSeconds = (): number => new Date(Date.now()).getTime() * 1_000_000 | ||
|
||
const generateSignature = (userId: string, publicKey: string, privateKey: string, ts: number) => | ||
crypto | ||
.createHmac('sha256', privateKey) | ||
.update(`userId=${userId}&apiKey=${publicKey}&ts=${ts}`) | ||
.digest('hex') | ||
|
||
// restApiEndpoint is used for token auth | ||
export const getToken = async ( | ||
restApiEndpoint: string, | ||
userId: string, | ||
publicKey: string, | ||
privateKey: string, | ||
) => { | ||
logger.debug('Fetching new access token') | ||
|
||
const ts = currentTimeNanoSeconds() | ||
const signature = generateSignature(userId, publicKey, privateKey, ts) | ||
const response = await axios.post<AccessTokenResponse>(`${restApiEndpoint}/token`, { | ||
apiKey: publicKey, | ||
userId, | ||
ts, | ||
signature, | ||
}) | ||
|
||
if (!response.data.success) { | ||
logger.error(`Unable to get access token: ${response.data.error}`) | ||
throw new Error(response.data.error) | ||
} | ||
|
||
return response.data.token | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,13 @@ | ||
{ | ||
"requests": [{ | ||
"from": "ETH", | ||
"to": "USD" | ||
}] | ||
"requests": [ | ||
{ | ||
"from": "ETH", | ||
"to": "USD" | ||
}, | ||
{ | ||
"from": "ETH", | ||
"to": "USD", | ||
"endpoint": "crypto-lwba" | ||
} | ||
] | ||
} |
21 changes: 21 additions & 0 deletions
21
packages/sources/gsr/test/integration/__snapshots__/adapter.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters