2023-10-04 23:03:26 +00:00
|
|
|
import { nip19 } from 'nostr-tools';
|
|
|
|
|
2024-02-11 18:40:14 +00:00
|
|
|
import { signer } from 'soapbox/features/nostr/sign';
|
2023-10-04 23:03:26 +00:00
|
|
|
import { type AppDispatch } from 'soapbox/store';
|
|
|
|
|
|
|
|
import { verifyCredentials } from './auth';
|
|
|
|
|
|
|
|
/** Log in with a Nostr pubkey. */
|
|
|
|
function nostrLogIn() {
|
|
|
|
return async (dispatch: AppDispatch) => {
|
2024-02-11 18:45:33 +00:00
|
|
|
if (!signer) {
|
|
|
|
throw new Error('No Nostr signer available');
|
|
|
|
}
|
|
|
|
|
2024-02-11 18:40:14 +00:00
|
|
|
const pubkey = await signer.getPublicKey();
|
2023-10-04 23:03:26 +00:00
|
|
|
const npub = nip19.npubEncode(pubkey);
|
|
|
|
|
|
|
|
return dispatch(verifyCredentials(npub));
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export { nostrLogIn };
|