Add Nostr `bunker` slice to redux store

This commit is contained in:
Alex Gleason 2024-10-27 17:02:21 -05:00
parent 38bc1641c5
commit 1223e3b9b6
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
1 changed files with 42 additions and 0 deletions

42
src/reducers/bunker.ts Normal file
View File

@ -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: {},
});