Make POW configurable, expose over the API

This commit is contained in:
Alex Gleason 2023-09-10 15:37:32 -05:00
parent b725550fc4
commit 607ef4b980
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
3 changed files with 11 additions and 1 deletions

View File

@ -1,3 +1,4 @@
import { Conf } from '@/config.ts';
import '@/cron.ts'; import '@/cron.ts';
import { import {
type Context, type Context,
@ -103,7 +104,7 @@ app.post('/oauth/revoke', emptyObjectController);
app.post('/oauth/authorize', oauthAuthorizeController); app.post('/oauth/authorize', oauthAuthorizeController);
app.get('/oauth/authorize', oauthController); 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.get('/api/v1/accounts/verify_credentials', requirePubkey, verifyCredentialsController);
app.patch('/api/v1/accounts/update_credentials', requirePubkey, updateCredentialsController); app.patch('/api/v1/accounts/update_credentials', requirePubkey, updateCredentialsController);
app.get('/api/v1/accounts/search', accountSearchController); app.get('/api/v1/accounts/search', accountSearchController);

View File

@ -126,6 +126,12 @@ const Conf = {
'system', '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. */ /** Domain of the Ditto server as a `URL` object, for easily grabbing the `hostname`, etc. */
get url() { get url() {
return new URL(Conf.localDomain); return new URL(Conf.localDomain);

View File

@ -53,6 +53,9 @@ const instanceController: AppController = (c) => {
nostr: { nostr: {
pubkey: Conf.pubkey, pubkey: Conf.pubkey,
relay: `${wsProtocol}//${host}/relay`, relay: `${wsProtocol}//${host}/relay`,
pow: {
registrations: Conf.pow.registrations,
},
}, },
rules: [], rules: [],
}); });