From 607ef4b9803c7b1f62fe16ff2863a89935820b7d Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sun, 10 Sep 2023 15:37:32 -0500 Subject: [PATCH] Make POW configurable, expose over the API --- src/app.ts | 3 ++- src/config.ts | 6 ++++++ src/controllers/api/instance.ts | 3 +++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/app.ts b/src/app.ts index c30579a..2e3fc70 100644 --- a/src/app.ts +++ b/src/app.ts @@ -1,3 +1,4 @@ +import { Conf } from '@/config.ts'; import '@/cron.ts'; import { type Context, @@ -103,7 +104,7 @@ app.post('/oauth/revoke', emptyObjectController); app.post('/oauth/authorize', oauthAuthorizeController); app.get('/oauth/authorize', oauthController); -app.post('/api/v1/acccounts', requireProof({ pow: 20 }), createAccountController); +app.post('/api/v1/acccounts', requireProof({ pow: Conf.pow.registrations }), createAccountController); app.get('/api/v1/accounts/verify_credentials', requirePubkey, verifyCredentialsController); app.patch('/api/v1/accounts/update_credentials', requirePubkey, updateCredentialsController); app.get('/api/v1/accounts/search', accountSearchController); diff --git a/src/config.ts b/src/config.ts index 4f60580..440cd26 100644 --- a/src/config.ts +++ b/src/config.ts @@ -126,6 +126,12 @@ const Conf = { 'system', ]; }, + /** Proof-of-work configuration. */ + pow: { + get registrations() { + return Number(Deno.env.get('DITTO_POW_REGISTRATIONS') ?? 20); + }, + }, /** Domain of the Ditto server as a `URL` object, for easily grabbing the `hostname`, etc. */ get url() { return new URL(Conf.localDomain); diff --git a/src/controllers/api/instance.ts b/src/controllers/api/instance.ts index b30c753..8ef38a7 100644 --- a/src/controllers/api/instance.ts +++ b/src/controllers/api/instance.ts @@ -53,6 +53,9 @@ const instanceController: AppController = (c) => { nostr: { pubkey: Conf.pubkey, relay: `${wsProtocol}//${host}/relay`, + pow: { + registrations: Conf.pow.registrations, + }, }, rules: [], });