Skip to content

Commit

Permalink
add chainalysis
Browse files Browse the repository at this point in the history
  • Loading branch information
juliangruber committed Nov 5, 2023
1 parent 46a48a7 commit 35b8866
Show file tree
Hide file tree
Showing 13 changed files with 678 additions and 34 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,4 @@ dist
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
secrets
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ jobs:
node-version: node
- run: npm ci
- run: npm test
- run: CHAINALYSIS_API_KEY=${{ secrets.CHAINALYSIS_API_KEY }} npm run test:integration
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,4 @@ dist
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
secrets
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
secrets
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ WORKDIR /app
# Set production environment
ENV NODE_ENV="production"


# Throw-away build stage to reduce size of final image
FROM base as build

Expand Down
13 changes: 10 additions & 3 deletions bin/station-wallet-screening.js
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}`)
3 changes: 3 additions & 0 deletions fly.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ primary_region = "cdg"
auto_start_machines = true
min_machines_running = 0
processes = ["app"]

[[http_service.checks]]
path = "/0x000000000000000000000000000000000000dEaD"
32 changes: 26 additions & 6 deletions index.js
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')
})
}
Loading

0 comments on commit 35b8866

Please sign in to comment.