import { storeJson } from '../fileModels/storeJson' import { i18n } from '../i18n' import { encodeNpub, encodeNsec } from '../nostr' import { sdk } from '../sdk' export const showOperatorCredentials = sdk.Action.withoutInput( // id 'show-operator-credentials', // metadata async ({ effects }) => ({ name: i18n('Show Operator Credentials'), description: i18n( 'Display the Nostr operator keypair SpacesOps signs events with (npub, nsec, and hex public key).', ), warning: null, allowedStatuses: 'any', group: null, visibility: 'enabled', }), // run async ({ effects }) => { const store = await storeJson.read().once() const secretHex = store?.operatorSecretHex ?? null const publicHex = store?.operatorPublicHex ?? null if (!secretHex || !publicHex) { return { version: '1', title: i18n('Operator Credentials'), message: i18n( 'The operator keypair has not been generated yet. Start the service once to generate it.', ), result: null, } } return { version: '1', title: i18n('Operator Credentials'), message: i18n( 'SpacesOps signs operator events on Nostr with this keypair. Keep the secret (nsec / hex) private.', ), result: { type: 'group', value: [ { type: 'single', name: i18n('Public Key (npub)'), description: null, value: encodeNpub(publicHex), masked: false, copyable: true, qr: true, }, { type: 'single', name: i18n('Public Key (hex)'), description: null, value: publicHex, masked: false, copyable: true, qr: false, }, { type: 'single', name: i18n('Secret Key (nsec)'), description: null, value: encodeNsec(secretHex), masked: true, copyable: true, qr: false, }, { type: 'single', name: i18n('Secret Key (hex)'), description: null, value: secretHex, masked: true, copyable: true, qr: false, }, ], }, } }, )