Merge branch 'admin-crypto' into 'main'
Remove crypo.ts, call AdminSigner instead See merge request soapbox-pub/ditto!113
This commit is contained in:
commit
3de63834f2
|
@ -1,8 +1,8 @@
|
||||||
import { type AppController } from '@/app.ts';
|
import { type AppController } from '@/app.ts';
|
||||||
import { Conf } from '@/config.ts';
|
import { Conf } from '@/config.ts';
|
||||||
import { decryptAdmin, encryptAdmin } from '@/crypto.ts';
|
|
||||||
import { z } from '@/deps.ts';
|
import { z } from '@/deps.ts';
|
||||||
import { configSchema, elixirTupleSchema } from '@/schemas/pleroma-api.ts';
|
import { configSchema, elixirTupleSchema } from '@/schemas/pleroma-api.ts';
|
||||||
|
import { AdminSigner } from '@/signers/AdminSigner.ts';
|
||||||
import { eventsDB } from '@/storages.ts';
|
import { eventsDB } from '@/storages.ts';
|
||||||
import { createAdminEvent } from '@/utils/api.ts';
|
import { createAdminEvent } from '@/utils/api.ts';
|
||||||
import { jsonSchema } from '@/schema.ts';
|
import { jsonSchema } from '@/schema.ts';
|
||||||
|
@ -18,7 +18,7 @@ const frontendConfigController: AppController = async (c) => {
|
||||||
}], { signal });
|
}], { signal });
|
||||||
|
|
||||||
const configs = jsonSchema.pipe(z.array(configSchema)).catch([]).parse(
|
const configs = jsonSchema.pipe(z.array(configSchema)).catch([]).parse(
|
||||||
event?.content ? await decryptAdmin(Conf.pubkey, event.content) : '',
|
event?.content ? await new AdminSigner().nip04.decrypt(Conf.pubkey, event.content) : '',
|
||||||
);
|
);
|
||||||
|
|
||||||
const frontendConfig = configs.find(({ group, key }) => group === ':pleroma' && key === ':frontend_configurations');
|
const frontendConfig = configs.find(({ group, key }) => group === ':pleroma' && key === ':frontend_configurations');
|
||||||
|
@ -47,7 +47,7 @@ const configController: AppController = async (c) => {
|
||||||
}], { signal });
|
}], { signal });
|
||||||
|
|
||||||
const configs = jsonSchema.pipe(z.array(configSchema)).catch([]).parse(
|
const configs = jsonSchema.pipe(z.array(configSchema)).catch([]).parse(
|
||||||
event?.content ? await decryptAdmin(pubkey, event.content) : '',
|
event?.content ? await new AdminSigner().nip04.decrypt(pubkey, event.content) : '',
|
||||||
);
|
);
|
||||||
|
|
||||||
return c.json({ configs, need_reboot: false });
|
return c.json({ configs, need_reboot: false });
|
||||||
|
@ -66,7 +66,7 @@ const updateConfigController: AppController = async (c) => {
|
||||||
}], { signal });
|
}], { signal });
|
||||||
|
|
||||||
const configs = jsonSchema.pipe(z.array(configSchema)).catch([]).parse(
|
const configs = jsonSchema.pipe(z.array(configSchema)).catch([]).parse(
|
||||||
event?.content ? await decryptAdmin(pubkey, event.content) : '',
|
event?.content ? await await new AdminSigner().nip04.decrypt(pubkey, event.content) : '',
|
||||||
);
|
);
|
||||||
|
|
||||||
const { configs: newConfigs } = z.object({ configs: z.array(configSchema) }).parse(await c.req.json());
|
const { configs: newConfigs } = z.object({ configs: z.array(configSchema) }).parse(await c.req.json());
|
||||||
|
@ -82,7 +82,7 @@ const updateConfigController: AppController = async (c) => {
|
||||||
|
|
||||||
await createAdminEvent({
|
await createAdminEvent({
|
||||||
kind: 30078,
|
kind: 30078,
|
||||||
content: await encryptAdmin(pubkey, JSON.stringify(configs)),
|
content: await await new AdminSigner().nip04.encrypt(pubkey, JSON.stringify(configs)),
|
||||||
tags: [['d', 'pub.ditto.pleroma.config']],
|
tags: [['d', 'pub.ditto.pleroma.config']],
|
||||||
}, c);
|
}, c);
|
||||||
|
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
import { Conf } from '@/config.ts';
|
|
||||||
import { nip04 } from '@/deps.ts';
|
|
||||||
|
|
||||||
/** Encrypt a message as the Ditto server account. */
|
|
||||||
function encryptAdmin(targetPubkey: string, message: string): Promise<string> {
|
|
||||||
return nip04.encrypt(Conf.seckey, targetPubkey, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Decrypt a message as the Ditto server account. */
|
|
||||||
function decryptAdmin(targetPubkey: string, message: string): Promise<string> {
|
|
||||||
return nip04.decrypt(Conf.seckey, targetPubkey, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
export { decryptAdmin, encryptAdmin };
|
|
|
@ -17,7 +17,6 @@ export {
|
||||||
getPublicKey,
|
getPublicKey,
|
||||||
matchFilter,
|
matchFilter,
|
||||||
matchFilters,
|
matchFilters,
|
||||||
nip04,
|
|
||||||
nip05,
|
nip05,
|
||||||
nip13,
|
nip13,
|
||||||
nip19,
|
nip19,
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import { Conf } from '@/config.ts';
|
import { Conf } from '@/config.ts';
|
||||||
import { encryptAdmin } from '@/crypto.ts';
|
|
||||||
import { addRelays } from '@/db/relays.ts';
|
import { addRelays } from '@/db/relays.ts';
|
||||||
import { deleteAttachedMedia } from '@/db/unattached-media.ts';
|
import { deleteAttachedMedia } from '@/db/unattached-media.ts';
|
||||||
import { Debug, LNURL, type NostrEvent } from '@/deps.ts';
|
import { Debug, LNURL, type NostrEvent } from '@/deps.ts';
|
||||||
|
@ -198,7 +197,7 @@ async function payZap(event: DittoEvent, signal: AbortSignal) {
|
||||||
|
|
||||||
const nwcRequestEvent = await signer.signEvent({
|
const nwcRequestEvent = await signer.signEvent({
|
||||||
kind: 23194,
|
kind: 23194,
|
||||||
content: await encryptAdmin(
|
content: await signer.nip04.encrypt(
|
||||||
event.pubkey,
|
event.pubkey,
|
||||||
JSON.stringify({ method: 'pay_invoice', params: { invoice: pr } }),
|
JSON.stringify({ method: 'pay_invoice', params: { invoice: pr } }),
|
||||||
),
|
),
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import { type AppContext } from '@/app.ts';
|
import { type AppContext } from '@/app.ts';
|
||||||
import { Conf } from '@/config.ts';
|
import { Conf } from '@/config.ts';
|
||||||
import { decryptAdmin, encryptAdmin } from '@/crypto.ts';
|
|
||||||
import { HTTPException, type NostrEvent, type NostrSigner, NSecSigner, Stickynotes } from '@/deps.ts';
|
import { HTTPException, type NostrEvent, type NostrSigner, NSecSigner, Stickynotes } from '@/deps.ts';
|
||||||
import { connectResponseSchema } from '@/schemas/nostr.ts';
|
import { connectResponseSchema } from '@/schemas/nostr.ts';
|
||||||
import { jsonSchema } from '@/schema.ts';
|
import { jsonSchema } from '@/schema.ts';
|
||||||
|
import { AdminSigner } from '@/signers/AdminSigner.ts';
|
||||||
import { Sub } from '@/subs.ts';
|
import { Sub } from '@/subs.ts';
|
||||||
import { eventMatchesTemplate } from '@/utils.ts';
|
import { eventMatchesTemplate } from '@/utils.ts';
|
||||||
import { createAdminEvent } from '@/utils/api.ts';
|
import { createAdminEvent } from '@/utils/api.ts';
|
||||||
|
@ -63,7 +63,7 @@ export class APISigner implements NostrSigner {
|
||||||
|
|
||||||
createAdminEvent({
|
createAdminEvent({
|
||||||
kind: 24133,
|
kind: 24133,
|
||||||
content: await encryptAdmin(
|
content: await new AdminSigner().nip04.encrypt(
|
||||||
pubkey,
|
pubkey,
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
id: messageId,
|
id: messageId,
|
||||||
|
@ -93,7 +93,7 @@ export class APISigner implements NostrSigner {
|
||||||
this.#c.req.raw.signal.addEventListener('abort', close);
|
this.#c.req.raw.signal.addEventListener('abort', close);
|
||||||
|
|
||||||
for await (const event of sub) {
|
for await (const event of sub) {
|
||||||
const decrypted = await decryptAdmin(event.pubkey, event.content);
|
const decrypted = await new AdminSigner().nip04.decrypt(event.pubkey, event.content);
|
||||||
|
|
||||||
const result = jsonSchema
|
const result = jsonSchema
|
||||||
.pipe(connectResponseSchema)
|
.pipe(connectResponseSchema)
|
||||||
|
|
Loading…
Reference in New Issue