-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
46a48a7
commit 35b8866
Showing
13 changed files
with
678 additions
and
34 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 |
---|---|---|
|
@@ -128,3 +128,4 @@ dist | |
.yarn/build-state.yml | ||
.yarn/install-state.gz | ||
.pnp.* | ||
secrets |
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 |
---|---|---|
|
@@ -128,3 +128,4 @@ dist | |
.yarn/build-state.yml | ||
.yarn/install-state.gz | ||
.pnp.* | ||
secrets |
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 @@ | ||
secrets |
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,10 +1,17 @@ | ||
import http from 'node:http' | ||
import { once } from 'node:events' | ||
import { handler } from '../index.js' | ||
import { createHandler } from '../index.js' | ||
import assert from 'node:assert' | ||
|
||
const { PORT = 3000 } = process.env | ||
const { | ||
PORT = 3000, | ||
CHAINALYSIS_API_KEY | ||
} = process.env | ||
assert(CHAINALYSIS_API_KEY) | ||
|
||
const server = http.createServer(handler) | ||
const server = http.createServer(createHandler({ | ||
apiKey: CHAINALYSIS_API_KEY | ||
})) | ||
server.listen(PORT) | ||
await once(server, 'listening') | ||
console.log(`http://127.0.0.1:${PORT}`) |
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,11 +1,31 @@ | ||
import { STATUS_CODES } from 'node:http' | ||
import assert from 'node:assert' | ||
|
||
const forbiddenAddresses = new Set([ | ||
'0xFORBIDDEN' | ||
]) | ||
|
||
export const handler = (req, res) => { | ||
const handler = async (req, res, apiKey, fetch, log) => { | ||
const address = req.url.split('/')[1].trim() | ||
res.statusCode = forbiddenAddresses.has(address) ? 403 : 200 | ||
const fetchRes = await fetch( | ||
`https://public.chainalysis.com/api/v1/address/${address}`, | ||
{ | ||
headers: { | ||
'X-API-Key': apiKey, | ||
accept: 'application/json' | ||
} | ||
} | ||
) | ||
assert(fetchRes.ok, `Chainalysis API status ${fetchRes.status}`) | ||
const body = await fetchRes.json() | ||
res.statusCode = body.identifications.length > 0 ? 403 : 200 | ||
res.end(STATUS_CODES[res.statusCode]) | ||
} | ||
|
||
export const createHandler = ({ | ||
apiKey, | ||
fetch = globalThis.fetch, | ||
log = console.log | ||
}) => (req, res) => { | ||
handler(req, res, apiKey, fetch, log).catch(err => { | ||
log(err) | ||
res.statusCode = 500 | ||
res.end('Internal Server Error') | ||
}) | ||
} |
Oops, something went wrong.