faucet-server-app 0.0.6 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/api/index.d.ts +51 -16
- package/dist/esm/api/index.d.ts.map +1 -1
- package/dist/esm/api/index.js +567 -79
- package/dist/esm/api/index.js.map +1 -1
- package/dist/esm/calls.d.ts +107 -0
- package/dist/esm/calls.d.ts.map +1 -0
- package/dist/esm/calls.js +304 -0
- package/dist/esm/calls.js.map +1 -0
- package/dist/esm/captcha.d.ts +28 -0
- package/dist/esm/captcha.d.ts.map +1 -0
- package/dist/esm/captcha.js +58 -0
- package/dist/esm/captcha.js.map +1 -0
- package/dist/esm/chains.d.ts +17552 -0
- package/dist/esm/chains.d.ts.map +1 -0
- package/dist/esm/chains.js +137 -0
- package/dist/esm/chains.js.map +1 -0
- package/dist/esm/config.d.ts +12 -0
- package/dist/esm/config.d.ts.map +1 -0
- package/dist/esm/config.js +28 -0
- package/dist/esm/config.js.map +1 -0
- package/dist/esm/env.d.ts +56 -0
- package/dist/esm/env.d.ts.map +1 -1
- package/dist/esm/env.js +81 -1
- package/dist/esm/env.js.map +1 -1
- package/dist/esm/index.d.ts +135 -42
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +39 -16
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/schema/ts/db.sql.d.ts +1 -1
- package/dist/esm/schema/ts/db.sql.d.ts.map +1 -1
- package/dist/esm/schema/ts/db.sql.js +25 -4
- package/dist/esm/schema/ts/db.sql.js.map +1 -1
- package/dist/esm/setup.d.ts +2 -0
- package/dist/esm/setup.d.ts.map +1 -1
- package/dist/esm/setup.js +25 -7
- package/dist/esm/setup.js.map +1 -1
- package/dist/esm/storage/RemoteSQLStorage.d.ts +49 -0
- package/dist/esm/storage/RemoteSQLStorage.d.ts.map +1 -0
- package/dist/esm/storage/RemoteSQLStorage.js +158 -0
- package/dist/esm/storage/RemoteSQLStorage.js.map +1 -0
- package/package.json +1 -1
- package/src/api/index.ts +752 -105
- package/src/calls.ts +447 -0
- package/src/captcha.ts +92 -0
- package/src/chains.ts +175 -0
- package/src/config.ts +33 -0
- package/src/env.ts +129 -0
- package/src/index.ts +60 -18
- package/src/schema/sql/db.sql +25 -4
- package/src/schema/ts/db.sql.ts +25 -4
- package/src/setup.ts +28 -11
- package/src/storage/RemoteSQLStorage.ts +252 -0
package/dist/esm/index.js
CHANGED
|
@@ -2,24 +2,45 @@ import { Hono } from 'hono';
|
|
|
2
2
|
import { cors } from 'hono/cors';
|
|
3
3
|
import { hc } from 'hono/client';
|
|
4
4
|
import { HTTPException } from 'hono/http-exception';
|
|
5
|
+
import { getCorsOrigins } from './env.js';
|
|
5
6
|
import { getAPI } from './api/index.js';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
});
|
|
7
|
+
import { RemoteSQLStorage } from './storage/RemoteSQLStorage.js';
|
|
8
|
+
export { RemoteSQLStorage };
|
|
9
|
+
export { verifyProsopoCaptcha } from './captcha.js';
|
|
10
|
+
export { DEFAULT_CORS_ORIGINS, DEFAULT_CLAIM_COOLDOWN_SECONDS } from './env.js';
|
|
11
|
+
export { getArbitraryCallsMode, getCallAllowlist, getCallLimits, isCallAllowed, parseCallRequest, planGas, selectorOf, DEFAULT_MAX_CALL_GAS, GAS_BUFFER_PERCENT, SIMPLE_TRANSFER_GAS, } from './calls.js';
|
|
12
|
+
export { checkConfig } from './config.js';
|
|
13
|
+
export { parseChainId } from './chains.js';
|
|
14
|
+
/**
|
|
15
|
+
* Creates the tables the faucet needs. Idempotent, safe to call on every boot.
|
|
16
|
+
*/
|
|
17
|
+
export async function setupDB(db) {
|
|
18
|
+
await new RemoteSQLStorage(db).setup();
|
|
19
|
+
}
|
|
20
20
|
export function createServer(options) {
|
|
21
21
|
const app = new Hono();
|
|
22
22
|
const api = getAPI(options);
|
|
23
|
+
// The frontend is served from the same origin as the api, so this only
|
|
24
|
+
// controls which OTHER sites may drive the faucet from a browser.
|
|
25
|
+
const corsSetup = cors({
|
|
26
|
+
origin: (origin, c) => {
|
|
27
|
+
const allowed = getCorsOrigins(options.getEnv(c));
|
|
28
|
+
if (allowed === '*') {
|
|
29
|
+
return origin || '*';
|
|
30
|
+
}
|
|
31
|
+
return allowed.includes(origin) ? origin : null;
|
|
32
|
+
},
|
|
33
|
+
allowHeaders: [
|
|
34
|
+
'X-Custom-Header',
|
|
35
|
+
'Upgrade-Insecure-Requests',
|
|
36
|
+
'Content-Type',
|
|
37
|
+
'SIGNATURE',
|
|
38
|
+
],
|
|
39
|
+
allowMethods: ['POST', 'GET', 'HEAD', 'OPTIONS'],
|
|
40
|
+
exposeHeaders: ['Content-Length', 'X-Kuma-Revision', 'Retry-After'],
|
|
41
|
+
maxAge: 600,
|
|
42
|
+
credentials: true,
|
|
43
|
+
});
|
|
23
44
|
return app
|
|
24
45
|
.use('/api/*', corsSetup)
|
|
25
46
|
.route('/api/', api)
|
|
@@ -40,8 +61,10 @@ export function createServer(options) {
|
|
|
40
61
|
code: 'code' in err ? err.code : 5000,
|
|
41
62
|
status: 'status' in err ? err.status : undefined,
|
|
42
63
|
message: err.message,
|
|
43
|
-
|
|
44
|
-
|
|
64
|
+
// an explicit 'true', so that DEV=false does not read as
|
|
65
|
+
// truthy and leak stack traces
|
|
66
|
+
cause: env.DEV === 'true' ? err.cause : undefined,
|
|
67
|
+
stack: env.DEV === 'true' ? err.stack : undefined,
|
|
45
68
|
},
|
|
46
69
|
],
|
|
47
70
|
}, 500);
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAC,MAAM,MAAM,CAAC;AAC1B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AC,IAAI,CACZ;YACC,OAAO,EAAE,KAAK;YACd,MAAM,EAAE;gBACP;oBACC,IAAI,EAAE,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS;oBAC1C,IAAI,EAAE,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI;oBACrC,MAAM,EAAE,QAAQ,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS;oBAChD,OAAO,EAAE,GAAG,CAAC,OAAO;oBACpB,yDAAyD;oBACzD,+BAA+B;oBAC/B,KAAK,EAAE,GAAG,CAAC,GAAG,KAAK,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS;oBACjD,KAAK,EAAE,GAAG,CAAC,GAAG,KAAK,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS;iBACjD;aACD;SACD,EACD,GAAG,CACH,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAID,uDAAuD;AACvD,MAAM,MAAM,GAAG,EAAE,CAAM,EAAE,CAAC,CAAC;AAE3B,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,GAAG,IAA2B,EAAU,EAAE,CACtE,EAAE,CAAM,GAAG,IAAI,CAAC,CAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
declare const _default: "CREATE TABLE IF NOT EXISTS
|
|
1
|
+
declare const _default: "CREATE TABLE IF NOT EXISTS Claims (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n chain_id TEXT NOT NULL,\n address TEXT NOT NULL,\n ip TEXT NOT NULL DEFAULT '',\n amount TEXT NOT NULL,\n tx_hash TEXT,\n claimed_at INTEGER NOT NULL\n);\n\nCREATE INDEX IF NOT EXISTS idx_claims_address ON Claims (chain_id, address, claimed_at);\n\nCREATE INDEX IF NOT EXISTS idx_claims_ip ON Claims (chain_id, ip, claimed_at);\n\nCREATE TABLE IF NOT EXISTS ChainLocks (\n chain_id TEXT PRIMARY KEY,\n locked_until INTEGER NOT NULL DEFAULT 0,\n last_nonce INTEGER\n);\n\nCREATE TABLE IF NOT EXISTS UsedTokens (\n token_hash TEXT PRIMARY KEY,\n used_at INTEGER NOT NULL\n);\n\nCREATE INDEX IF NOT EXISTS idx_used_tokens_used_at ON UsedTokens (used_at);\n";
|
|
2
2
|
export default _default;
|
|
3
3
|
//# sourceMappingURL=db.sql.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"db.sql.d.ts","sourceRoot":"","sources":["../../../../src/schema/ts/db.sql.ts"],"names":[],"mappings":";AAAA,
|
|
1
|
+
{"version":3,"file":"db.sql.d.ts","sourceRoot":"","sources":["../../../../src/schema/ts/db.sql.ts"],"names":[],"mappings":";AAAA,wBA0BC"}
|
|
@@ -1,7 +1,28 @@
|
|
|
1
|
-
export default `CREATE TABLE IF NOT EXISTS
|
|
2
|
-
id
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
export default `CREATE TABLE IF NOT EXISTS Claims (
|
|
2
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
3
|
+
chain_id TEXT NOT NULL,
|
|
4
|
+
address TEXT NOT NULL,
|
|
5
|
+
ip TEXT NOT NULL DEFAULT '',
|
|
6
|
+
amount TEXT NOT NULL,
|
|
7
|
+
tx_hash TEXT,
|
|
8
|
+
claimed_at INTEGER NOT NULL
|
|
5
9
|
);
|
|
10
|
+
|
|
11
|
+
CREATE INDEX IF NOT EXISTS idx_claims_address ON Claims (chain_id, address, claimed_at);
|
|
12
|
+
|
|
13
|
+
CREATE INDEX IF NOT EXISTS idx_claims_ip ON Claims (chain_id, ip, claimed_at);
|
|
14
|
+
|
|
15
|
+
CREATE TABLE IF NOT EXISTS ChainLocks (
|
|
16
|
+
chain_id TEXT PRIMARY KEY,
|
|
17
|
+
locked_until INTEGER NOT NULL DEFAULT 0,
|
|
18
|
+
last_nonce INTEGER
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
CREATE TABLE IF NOT EXISTS UsedTokens (
|
|
22
|
+
token_hash TEXT PRIMARY KEY,
|
|
23
|
+
used_at INTEGER NOT NULL
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
CREATE INDEX IF NOT EXISTS idx_used_tokens_used_at ON UsedTokens (used_at);
|
|
6
27
|
`;
|
|
7
28
|
//# sourceMappingURL=db.sql.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"db.sql.js","sourceRoot":"","sources":["../../../../src/schema/ts/db.sql.ts"],"names":[],"mappings":"AAAA,eAAe
|
|
1
|
+
{"version":3,"file":"db.sql.js","sourceRoot":"","sources":["../../../../src/schema/ts/db.sql.ts"],"names":[],"mappings":"AAAA,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;CA0Bd,CAAA"}
|
package/dist/esm/setup.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { MiddlewareHandler } from 'hono/types';
|
|
2
2
|
import { ServerOptions } from './types.js';
|
|
3
3
|
import { Env } from './env.js';
|
|
4
|
+
import { RemoteSQLStorage } from './storage/RemoteSQLStorage.js';
|
|
4
5
|
export type SetupOptions<CustomEnv extends Env> = {
|
|
5
6
|
serverOptions: ServerOptions<CustomEnv>;
|
|
6
7
|
};
|
|
7
8
|
export type Config<CustomEnv extends Env> = {
|
|
9
|
+
storage: RemoteSQLStorage;
|
|
8
10
|
env: CustomEnv;
|
|
9
11
|
};
|
|
10
12
|
declare module 'hono' {
|
package/dist/esm/setup.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/setup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,iBAAiB,EAAC,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAC,aAAa,EAAC,MAAM,YAAY,CAAC;AACzC,OAAO,EAAC,GAAG,EAAC,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/setup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,iBAAiB,EAAC,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAC,aAAa,EAAC,MAAM,YAAY,CAAC;AACzC,OAAO,EAAC,GAAG,EAAC,MAAM,UAAU,CAAC;AAC7B,OAAO,EAAC,gBAAgB,EAAC,MAAM,+BAA+B,CAAC;AAG/D,MAAM,MAAM,YAAY,CAAC,SAAS,SAAS,GAAG,IAAI;IACjD,aAAa,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,MAAM,CAAC,SAAS,SAAS,GAAG,IAAI;IAC3C,OAAO,EAAE,gBAAgB,CAAC;IAC1B,GAAG,EAAE,SAAS,CAAC;CACf,CAAC;AAEF,OAAO,QAAQ,MAAM,CAAC;IACrB,UAAU,kBAAkB;QAC3B,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;KACpB;CACD;AAwBD,wBAAgB,KAAK,CAAC,SAAS,SAAS,GAAG,EAC1C,OAAO,EAAE,YAAY,CAAC,SAAS,CAAC,GAC9B,iBAAiB,CAgBnB"}
|
package/dist/esm/setup.js
CHANGED
|
@@ -1,18 +1,36 @@
|
|
|
1
|
+
import { RemoteSQLStorage } from './storage/RemoteSQLStorage.js';
|
|
2
|
+
import { checkConfig } from './config.js';
|
|
3
|
+
// Cloudflare Workers has no boot hook, so the configuration is reported once
|
|
4
|
+
// per isolate instead: an operator gets the same errors and warnings the node
|
|
5
|
+
// cli prints at startup, on the first request the isolate serves.
|
|
6
|
+
let configReported = false;
|
|
7
|
+
function reportConfigOnce(env) {
|
|
8
|
+
if (configReported) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
configReported = true;
|
|
12
|
+
const issues = checkConfig(env);
|
|
13
|
+
for (const line of issues.info) {
|
|
14
|
+
console.log(line);
|
|
15
|
+
}
|
|
16
|
+
for (const warning of issues.warnings) {
|
|
17
|
+
console.warn(`WARNING: ${warning}`);
|
|
18
|
+
}
|
|
19
|
+
for (const error of issues.errors) {
|
|
20
|
+
console.error(`ERROR: ${error}`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
1
23
|
export function setup(options) {
|
|
2
24
|
const { getDB, getEnv } = options.serverOptions;
|
|
3
25
|
return async (c, next) => {
|
|
4
26
|
const env = getEnv(c);
|
|
27
|
+
reportConfigOnce(env);
|
|
5
28
|
const db = getDB(c);
|
|
6
|
-
|
|
7
|
-
// const storage = new RemoteSQLStorage(db);
|
|
29
|
+
const storage = new RemoteSQLStorage(db);
|
|
8
30
|
c.set('config', {
|
|
9
|
-
|
|
31
|
+
storage,
|
|
10
32
|
env,
|
|
11
33
|
});
|
|
12
|
-
// // auto setup
|
|
13
|
-
// if (c.req.query('_initDB') == 'true') {
|
|
14
|
-
// await storage.setup();
|
|
15
|
-
// }
|
|
16
34
|
return next();
|
|
17
35
|
};
|
|
18
36
|
}
|
package/dist/esm/setup.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup.js","sourceRoot":"","sources":["../../src/setup.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"setup.js","sourceRoot":"","sources":["../../src/setup.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,gBAAgB,EAAC,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAC,WAAW,EAAC,MAAM,aAAa,CAAC;AAiBxC,6EAA6E;AAC7E,8EAA8E;AAC9E,kEAAkE;AAClE,IAAI,cAAc,GAAG,KAAK,CAAC;AAE3B,SAAS,gBAAgB,CAAC,GAAQ;IACjC,IAAI,cAAc,EAAE,CAAC;QACpB,OAAO;IACR,CAAC;IACD,cAAc,GAAG,IAAI,CAAC;IACtB,MAAM,MAAM,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;IAChC,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;QAChC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACnB,CAAC;IACD,KAAK,MAAM,OAAO,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;QACvC,OAAO,CAAC,IAAI,CAAC,YAAY,OAAO,EAAE,CAAC,CAAC;IACrC,CAAC;IACD,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;QACnC,OAAO,CAAC,KAAK,CAAC,UAAU,KAAK,EAAE,CAAC,CAAC;IAClC,CAAC;AACF,CAAC;AAED,MAAM,UAAU,KAAK,CACpB,OAAgC;IAEhC,MAAM,EAAC,KAAK,EAAE,MAAM,EAAC,GAAG,OAAO,CAAC,aAAa,CAAC;IAE9C,OAAO,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE;QACxB,MAAM,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QACtB,gBAAgB,CAAC,GAAG,CAAC,CAAC;QACtB,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACpB,MAAM,OAAO,GAAG,IAAI,gBAAgB,CAAC,EAAE,CAAC,CAAC;QAEzC,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE;YACf,OAAO;YACP,GAAG;SACH,CAAC,CAAC;QAEH,OAAO,IAAI,EAAE,CAAC;IACf,CAAC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { RemoteSQL } from 'remote-sql';
|
|
2
|
+
export type ClaimRow = {
|
|
3
|
+
id: number;
|
|
4
|
+
chain_id: string;
|
|
5
|
+
address: string;
|
|
6
|
+
ip: string;
|
|
7
|
+
amount: string;
|
|
8
|
+
tx_hash: string | null;
|
|
9
|
+
claimed_at: number;
|
|
10
|
+
};
|
|
11
|
+
export type ChainLockAcquisition = {
|
|
12
|
+
acquired: boolean;
|
|
13
|
+
lastNonce: number | null;
|
|
14
|
+
};
|
|
15
|
+
export type RateLimitHit = {
|
|
16
|
+
reason: 'address' | 'ip';
|
|
17
|
+
retryAfter: number;
|
|
18
|
+
};
|
|
19
|
+
export declare class RemoteSQLStorage {
|
|
20
|
+
protected db: RemoteSQL;
|
|
21
|
+
constructor(db: RemoteSQL);
|
|
22
|
+
setup(): Promise<void>;
|
|
23
|
+
burnToken(tokenHash: string, now: number): Promise<boolean>;
|
|
24
|
+
reserveClaim(params: {
|
|
25
|
+
chainId: string;
|
|
26
|
+
address: string;
|
|
27
|
+
ip: string;
|
|
28
|
+
amount: string;
|
|
29
|
+
now: number;
|
|
30
|
+
addressCutoff: number;
|
|
31
|
+
ipCutoff: number;
|
|
32
|
+
}): Promise<number | null>;
|
|
33
|
+
getRateLimitHit(params: {
|
|
34
|
+
chainId: string;
|
|
35
|
+
address: string;
|
|
36
|
+
ip: string;
|
|
37
|
+
now: number;
|
|
38
|
+
addressCutoff: number;
|
|
39
|
+
ipCutoff: number;
|
|
40
|
+
addressCooldown: number;
|
|
41
|
+
ipCooldown: number;
|
|
42
|
+
}): Promise<RateLimitHit>;
|
|
43
|
+
cancelClaim(id: number): Promise<void>;
|
|
44
|
+
recordClaimTx(id: number, txHash: string): Promise<void>;
|
|
45
|
+
acquireChainLock(chainId: string, now: number, lockedUntil: number): Promise<ChainLockAcquisition>;
|
|
46
|
+
releaseChainLock(chainId: string, nonceUsed?: number | null): Promise<void>;
|
|
47
|
+
cleanup(tokenCutoff: number, claimCutoff: number): Promise<void>;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=RemoteSQLStorage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RemoteSQLStorage.d.ts","sourceRoot":"","sources":["../../../src/storage/RemoteSQLStorage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,YAAY,CAAC;AAGrC,MAAM,MAAM,QAAQ,GAAG;IACtB,EAAE,EAAE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ACnB,GAAG,OAAO,CAAC,YAAY,CAAC;IAuCnB,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAItC,aAAa,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAaxD,gBAAgB,CACrB,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,MAAM,EACX,WAAW,EAAE,MAAM,GACjB,OAAO,CAAC,oBAAoB,CAAC;IAyB1B,gBAAgB,CACrB,OAAO,EAAE,MAAM,EACf,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,GACvB,OAAO,CAAC,IAAI,CAAC;IAoBV,OAAO,CAAC,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAUtE"}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import schema from '../schema/ts/db.sql.js';
|
|
2
|
+
// A statement chunk that only contains comments cannot be executed on its own.
|
|
3
|
+
function isExecutable(statement) {
|
|
4
|
+
return statement
|
|
5
|
+
.split('\n')
|
|
6
|
+
.some((line) => line.trim().length > 0 && !line.trim().startsWith('--'));
|
|
7
|
+
}
|
|
8
|
+
export class RemoteSQLStorage {
|
|
9
|
+
db;
|
|
10
|
+
constructor(db) {
|
|
11
|
+
this.db = db;
|
|
12
|
+
}
|
|
13
|
+
// ------------------------------------------------------------------------
|
|
14
|
+
// schema
|
|
15
|
+
// ------------------------------------------------------------------------
|
|
16
|
+
// Idempotent: every statement in db.sql is a CREATE ... IF NOT EXISTS.
|
|
17
|
+
async setup() {
|
|
18
|
+
const statements = schema
|
|
19
|
+
.split(';')
|
|
20
|
+
.map((v) => v.trim())
|
|
21
|
+
.filter((v) => v.length > 0 && isExecutable(v))
|
|
22
|
+
.map((v) => this.db.prepare(`${v};`));
|
|
23
|
+
await this.db.batch(statements);
|
|
24
|
+
}
|
|
25
|
+
// ------------------------------------------------------------------------
|
|
26
|
+
// captcha token replay protection
|
|
27
|
+
// ------------------------------------------------------------------------
|
|
28
|
+
// Burns a captcha token. Returns false when that token was already used,
|
|
29
|
+
// which means the request is a replay of an earlier successful verification.
|
|
30
|
+
async burnToken(tokenHash, now) {
|
|
31
|
+
const { results } = await this.db
|
|
32
|
+
.prepare(`INSERT INTO UsedTokens (token_hash, used_at) VALUES (?, ?)
|
|
33
|
+
ON CONFLICT (token_hash) DO NOTHING
|
|
34
|
+
RETURNING token_hash;`)
|
|
35
|
+
.bind(tokenHash, now)
|
|
36
|
+
.all();
|
|
37
|
+
return results.length > 0;
|
|
38
|
+
}
|
|
39
|
+
// ------------------------------------------------------------------------
|
|
40
|
+
// rate limiting
|
|
41
|
+
// ------------------------------------------------------------------------
|
|
42
|
+
// Atomically reserves a claim slot: the row is only inserted when no recent
|
|
43
|
+
// claim exists for that address or that ip. A single INSERT ... SELECT
|
|
44
|
+
// WHERE NOT EXISTS statement is atomic in SQLite, so two concurrent requests
|
|
45
|
+
// cannot both reserve. An empty `ip` disables the ip bucket, and an empty
|
|
46
|
+
// `address` disables the address bucket (used by /api/execute, whose `to` is
|
|
47
|
+
// a shared contract and so cannot be a rate limiting key: without the
|
|
48
|
+
// `address <> ''` guard every such row would collide with every other one
|
|
49
|
+
// and the first call would lock out every caller for a whole cooldown).
|
|
50
|
+
async reserveClaim(params) {
|
|
51
|
+
const { chainId, address, ip, amount, now, addressCutoff, ipCutoff } = params;
|
|
52
|
+
const { results } = await this.db
|
|
53
|
+
.prepare(`INSERT INTO Claims (chain_id, address, ip, amount, claimed_at)
|
|
54
|
+
SELECT ?, ?, ?, ?, ?
|
|
55
|
+
WHERE NOT EXISTS (
|
|
56
|
+
SELECT 1 FROM Claims
|
|
57
|
+
WHERE chain_id = ?
|
|
58
|
+
AND (
|
|
59
|
+
(address <> '' AND address = ? AND claimed_at > ?)
|
|
60
|
+
OR (ip <> '' AND ip = ? AND claimed_at > ?)
|
|
61
|
+
)
|
|
62
|
+
)
|
|
63
|
+
RETURNING id;`)
|
|
64
|
+
.bind(chainId, address, ip, amount, now, chainId, address, addressCutoff, ip, ipCutoff)
|
|
65
|
+
.all();
|
|
66
|
+
if (results.length === 0) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
return results[0].id;
|
|
70
|
+
}
|
|
71
|
+
// Only called when reserveClaim returned null, to explain why.
|
|
72
|
+
async getRateLimitHit(params) {
|
|
73
|
+
const { chainId, address, ip, now, addressCutoff, ipCutoff, addressCooldown, ipCooldown, } = params;
|
|
74
|
+
const { results } = await this.db
|
|
75
|
+
.prepare(`SELECT address, ip, claimed_at FROM Claims
|
|
76
|
+
WHERE chain_id = ?
|
|
77
|
+
AND (
|
|
78
|
+
(address <> '' AND address = ? AND claimed_at > ?)
|
|
79
|
+
OR (ip <> '' AND ip = ? AND claimed_at > ?)
|
|
80
|
+
)
|
|
81
|
+
ORDER BY claimed_at DESC LIMIT 1;`)
|
|
82
|
+
.bind(chainId, address, addressCutoff, ip, ipCutoff)
|
|
83
|
+
.all();
|
|
84
|
+
if (results.length === 0) {
|
|
85
|
+
// the offending claim expired between the two queries, ask for an immediate retry
|
|
86
|
+
return { reason: 'address', retryAfter: 1 };
|
|
87
|
+
}
|
|
88
|
+
const row = results[0];
|
|
89
|
+
// `address !== ''` matters: an /api/execute row also has an empty address,
|
|
90
|
+
// so a plain `row.address === address` would call an ip hit an address hit
|
|
91
|
+
// and report the wrong cooldown.
|
|
92
|
+
const matchedAddress = address !== '' && row.address === address;
|
|
93
|
+
const cooldown = matchedAddress ? addressCooldown : ipCooldown;
|
|
94
|
+
const retryAfter = Math.max(1, row.claimed_at + cooldown - now);
|
|
95
|
+
return { reason: matchedAddress ? 'address' : 'ip', retryAfter };
|
|
96
|
+
}
|
|
97
|
+
// Releases a reservation when the claim ended up not being dispensed.
|
|
98
|
+
async cancelClaim(id) {
|
|
99
|
+
await this.db.prepare(`DELETE FROM Claims WHERE id = ?;`).bind(id).all();
|
|
100
|
+
}
|
|
101
|
+
async recordClaimTx(id, txHash) {
|
|
102
|
+
await this.db
|
|
103
|
+
.prepare(`UPDATE Claims SET tx_hash = ? WHERE id = ?;`)
|
|
104
|
+
.bind(txHash, id)
|
|
105
|
+
.all();
|
|
106
|
+
}
|
|
107
|
+
// ------------------------------------------------------------------------
|
|
108
|
+
// per chain send lock (nonce serialisation)
|
|
109
|
+
// ------------------------------------------------------------------------
|
|
110
|
+
// Takes the per chain lock so only one claim at a time picks a nonce.
|
|
111
|
+
// The lock is time boxed, so a crashed request cannot wedge the faucet.
|
|
112
|
+
async acquireChainLock(chainId, now, lockedUntil) {
|
|
113
|
+
await this.db
|
|
114
|
+
.prepare(`INSERT INTO ChainLocks (chain_id, locked_until, last_nonce)
|
|
115
|
+
VALUES (?, 0, NULL)
|
|
116
|
+
ON CONFLICT (chain_id) DO NOTHING;`)
|
|
117
|
+
.bind(chainId)
|
|
118
|
+
.all();
|
|
119
|
+
const { results } = await this.db
|
|
120
|
+
.prepare(`UPDATE ChainLocks SET locked_until = ?
|
|
121
|
+
WHERE chain_id = ? AND locked_until < ?
|
|
122
|
+
RETURNING last_nonce;`)
|
|
123
|
+
.bind(lockedUntil, chainId, now)
|
|
124
|
+
.all();
|
|
125
|
+
if (results.length === 0) {
|
|
126
|
+
return { acquired: false, lastNonce: null };
|
|
127
|
+
}
|
|
128
|
+
return { acquired: true, lastNonce: results[0].last_nonce ?? null };
|
|
129
|
+
}
|
|
130
|
+
async releaseChainLock(chainId, nonceUsed) {
|
|
131
|
+
if (typeof nonceUsed === 'number') {
|
|
132
|
+
await this.db
|
|
133
|
+
.prepare(`UPDATE ChainLocks SET locked_until = 0, last_nonce = ? WHERE chain_id = ?;`)
|
|
134
|
+
.bind(nonceUsed, chainId)
|
|
135
|
+
.all();
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
await this.db
|
|
139
|
+
.prepare(`UPDATE ChainLocks SET locked_until = 0 WHERE chain_id = ?;`)
|
|
140
|
+
.bind(chainId)
|
|
141
|
+
.all();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
// ------------------------------------------------------------------------
|
|
145
|
+
// housekeeping
|
|
146
|
+
// ------------------------------------------------------------------------
|
|
147
|
+
async cleanup(tokenCutoff, claimCutoff) {
|
|
148
|
+
await this.db.batch([
|
|
149
|
+
this.db
|
|
150
|
+
.prepare(`DELETE FROM UsedTokens WHERE used_at < ?;`)
|
|
151
|
+
.bind(tokenCutoff),
|
|
152
|
+
this.db
|
|
153
|
+
.prepare(`DELETE FROM Claims WHERE claimed_at < ?;`)
|
|
154
|
+
.bind(claimCutoff),
|
|
155
|
+
]);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=RemoteSQLStorage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RemoteSQLStorage.js","sourceRoot":"","sources":["../../../src/storage/RemoteSQLStorage.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,wBAAwB,CAAC;AAyB5C,+EAA+E;AAC/E,SAAS,YAAY,CAAC,SAAiB;IACtC,OAAO,SAAS;SACd,KAAK,CAAC,IAAI,CAAC;SACX,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC;AAC3E,CAAC;AAED,MAAM,OAAO,gBAAgB;IACN;IAAtB,YAAsB,EAAa;QAAb,OAAE,GAAF,EAAE,CAAW;IAAG,CAAC;IAEvC,2EAA2E;IAC3E,SAAS;IACT,2EAA2E;IAE3E,uEAAuE;IACvE,KAAK,CAAC,KAAK;QACV,MAAM,UAAU,GAAG,MAAM;aACvB,KAAK,CAAC,GAAG,CAAC;aACV,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;aACpB,MAAM,CAAC,CA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