Skip to content

Commit 597907d

Browse files
authored
Merge branch 'master' into rayane/event-ika-polling
2 parents ffae07f + 52590e4 commit 597907d

File tree

13 files changed

+12132
-19
lines changed

13 files changed

+12132
-19
lines changed

AGENTS.md

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,9 @@ Check @README.md for more details.
1414

1515
### Packages
1616

17-
- `./packages/lib` : a library package where we put common functions to be shared with other packages.
18-
- `./packages/btcindexer` : a Bitcoin indexer (btcindexer) for the nBTC project. The project is designed to monitor the Bitcoin blockchain, parse Bitcoin blocks, identify nBTC deposits, and facilitate their minting on the Sui blockchain.
19-
- `./packages/sui-indexer` : Polls Sui events for all active packages listed in the `nbtc_packages` database. The events are handled by the `SuiEventHandler`. Provides Redeem Solver and RPC.
20-
- `./packages/block-ingestor` : a new worker that exposes REST API to receive new blocks and queue them for processing.
17+
All packages are in the `./packages` directory. Each package, except `lib` is a service (Cloudflare worker). `lib` is a package with helper modules and functions shared between other packages.
2118

22-
Details about each package is in described in the sections below.
19+
See @README.md file for details about packages.
2320

2421
### Core Technologies
2522

@@ -245,17 +242,6 @@ Regenerate using `tree --gitignore`.
245242
│ └── git-hooks/
246243
├── node_modules/
247244
├── packages/
248-
│ └── btcindexer/
249-
│ ├── db/
250-
│ │ └── migrations/
251-
│ └── src/
252-
│ ├── api/
253-
│ ├── btcindexer.test.ts
254-
│ ├── electrs-service.ts
255-
│ ├── models.ts
256-
│ ├── router.ts
257-
│ ├── sui_client.ts
258-
│ └── sui_client.test.ts
259245
├── .editorconfig
260246
├── .gitignore
261247
├── .markdownlint.yml

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ Workers are based on the Cloudflare Workers framework.
3535
- Proposes appropriate UTXO sets for withdrawal transactions
3636
- Coordinates with BTCIndexer for consistent state
3737

38+
#### [Compliance](./packages/compliance/)
39+
40+
- Updates sanctions and geo-location data.
41+
- Providing API to block specific addresses or queries.
42+
3843
#### [Shared Library](./packages/lib/) (`lib`)
3944

4045
- Provides shared functions, types, and configurations

packages/compliance/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Compliance
2+
3+
This worker provides data for compliance checks:
4+
5+
- Sanctioned addresses
6+
- Geoblocking locations

packages/compliance/package.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "@gonative-cc/compliance",
3+
"version": "0.0.1",
4+
"exports": {
5+
"./*": "./src/*.ts"
6+
},
7+
"type": "module",
8+
"scripts": {
9+
"dev": "wrangler dev --test-scheduled",
10+
"deploy": "wrangler deploy",
11+
"typecheck": "tsc --noEmit",
12+
"cf-typegen": "wrangler types",
13+
"test": "bun test"
14+
},
15+
"dependencies": {
16+
"@gonative-cc/lib": "workspace:*"
17+
},
18+
"devDependencies": {
19+
"miniflare": "4.20251008.0"
20+
}
21+
}

packages/compliance/src/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { D1Storage } from "./storage";
2+
3+
// Export RPC entrypoints for service bindings
4+
export { RPC } from "./rpc";
5+
6+
export default {
7+
async scheduled(_event: ScheduledController, env: Env, _ctx: ExecutionContext): Promise<void> {
8+
// TODO: run DB updates
9+
const storage = new D1Storage(env.DB);
10+
},
11+
} satisfies ExportedHandler<Env>;

packages/compliance/src/rpc.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { WorkerEntrypoint } from "cloudflare:workers";
2+
3+
import { D1Storage } from "./storage";
4+
import type {
5+
ConfirmingRedeemReq,
6+
RedeemRequestEventRaw,
7+
RedeemRequestResp,
8+
FinalizeRedeemTx,
9+
} from "@gonative-cc/lib/rpc-types";
10+
11+
/**
12+
* RPC entrypoint for the worker.
13+
*
14+
* @see https://developers.cloudflare.com/workers/runtime-apis/bindings/service-bindings/rpc/
15+
*/
16+
export class RPC extends WorkerEntrypoint<Env> {
17+
// TODO: check if we can use a proper type for address instead of string
18+
async isBtcBlocked(btcAddrs: string[]): Promise<boolean> {
19+
const storage = new D1Storage(this.env.DB);
20+
return storage.isBtcBlocked(btcAddrs);
21+
}
22+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { describe, test, expect, beforeAll, afterAll, beforeEach, afterEach } from "bun:test";
2+
import { Miniflare } from "miniflare";
3+
import { D1Storage } from "./storage";
4+
import { payments, networks } from "bitcoinjs-lib";
5+
import { dropTables, initDb } from "@gonative-cc/lib/test-helpers/init_db";
6+
7+
export const UTXO_LOCK_TIME_MS = 120000; // 2 minutes
8+
9+
let mf: Miniflare;
10+
11+
beforeAll(async () => {
12+
mf = new Miniflare({
13+
script: "",
14+
modules: true,
15+
d1Databases: ["DB"],
16+
d1Persist: false,
17+
});
18+
});
19+
20+
afterAll(async () => {
21+
await mf.dispose();
22+
});
23+
24+
const p2wpkh1 = payments.p2wpkh({
25+
pubkey: Buffer.from(
26+
"03b32dc780fba98db25b4b72cf2b69da228f5e10ca6aa8f46eabe7f9fe22c994ee",
27+
"hex",
28+
),
29+
network: networks.regtest,
30+
});
31+
32+
describe("Bitcoin compliance", () => {
33+
let storage: D1Storage;
34+
let db: D1Database;
35+
36+
beforeEach(async () => {
37+
db = await mf.getD1Database("DB");
38+
await initDb(db);
39+
40+
storage = new D1Storage(db);
41+
});
42+
43+
afterEach(() => dropTables(db));
44+
45+
test("should detect sanctioned bitcoin addresses", async () => {
46+
expect(await storage.isBtcBlocked([])).toBeFalse();
47+
});
48+
});

packages/compliance/src/storage.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { logError } from "@gonative-cc/lib/logger";
2+
3+
export class D1Storage {
4+
constructor(private db: D1Database) {}
5+
6+
// returns true if any of the given btcAddrs is blocked
7+
async isBtcBlocked(btcAddrs: string[]): Promise<boolean> {
8+
// TODO: finish implementation
9+
return false;
10+
}
11+
}

packages/compliance/tsconfig.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"compilerOptions": {
3+
// Environment setup & latest features
4+
"lib": ["ESNext"],
5+
"target": "ESNext",
6+
"module": "Preserve",
7+
"moduleDetection": "force",
8+
"allowJs": true,
9+
10+
// Bundler mode
11+
"moduleResolution": "bundler",
12+
"allowImportingTsExtensions": true,
13+
"verbatimModuleSyntax": true,
14+
"noEmit": true,
15+
16+
// Best practices
17+
"strict": true,
18+
"skipLibCheck": true,
19+
"noFallthroughCasesInSwitch": true,
20+
"noUncheckedIndexedAccess": true,
21+
"noImplicitOverride": true,
22+
23+
// Some stricter flags (disabled by default)
24+
"noUnusedLocals": false,
25+
"noUnusedParameters": false,
26+
"noPropertyAccessFromIndexSignature": false
27+
}
28+
}

0 commit comments

Comments
 (0)