From 1223e3b9b6c2663ba62eb970281671667d03ad86 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sun, 27 Oct 2024 17:02:21 -0500 Subject: [PATCH] Add Nostr `bunker` slice to redux store --- src/reducers/bunker.ts | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/reducers/bunker.ts diff --git a/src/reducers/bunker.ts b/src/reducers/bunker.ts new file mode 100644 index 000000000..d2079888b --- /dev/null +++ b/src/reducers/bunker.ts @@ -0,0 +1,42 @@ +import { createSlice } from '@reduxjs/toolkit'; + +/** + * Temporary authorization details to establish a bunker connection with an app. + * Will be upgraded to a `BunkerConnection` once the connection is established. + */ +interface BunkerAuthorization { + /** + * Authorization secret generated by the bunker. + * The app should return it to us in its `connect` call to establish a connection. + */ + secret: string; + /** User pubkey. Events will be signed by this pubkey. */ + pubkey: string; + /** Secret key for this connection. NIP-46 responses will be signed by this key. */ + bunkerSeckey: Uint8Array; +} + +/** + * A bunker connection maps an OAuth token from Mastodon API to a user pubkey and bunker keypair. + * The user pubkey is used to determine whether to use keys from localStorage or a browser extension, + * and the bunker keypair is used to sign and encrypt NIP-46 messages. + */ +interface BunkerConnection { + /** User pubkey. Events will be signed by this pubkey. */ + pubkey: string; + /** Mastodon API access token associated with this connection. */ + accessToken: string; + /** Pubkey of the app authorized to sign events with this connection. */ + authorizedPubkey: string; + /** Secret key for this connection. NIP-46 responses will be signed by this key. */ + bunkerSeckey: Uint8Array; +} + +export default createSlice({ + name: 'bunker', + initialState: { + authorizations: [] as BunkerAuthorization[], + connections: [] as BunkerConnection[], + }, + reducers: {}, +}); \ No newline at end of file