Files
boris/node_modules/applesauce-accounts/dist/accounts/password-account.js
Gigi 5d53a827e0 feat: initialize markr nostr bookmark client
- Add project structure with TypeScript, React, and Vite
- Implement nostr authentication using browser extension (NIP-07)
- Add NIP-51 compliant bookmark fetching and display
- Create minimal UI with login and bookmark components
- Integrate applesauce-core and applesauce-react libraries
- Add responsive styling with dark/light mode support
- Include comprehensive README with setup instructions

This is a minimal MVP for a nostr bookmark client that allows users to
view their bookmarks according to NIP-51 specification.
2025-10-02 07:17:07 +02:00

52 lines
2.0 KiB
JavaScript

import { PasswordSigner } from "applesauce-signers/signers/password-signer";
import { BaseAccount } from "../account.js";
export class PasswordAccount extends BaseAccount {
static type = "ncryptsec";
get unlocked() {
return this.signer.unlocked;
}
/** called when PasswordAccount.unlock is called without a password */
static requestUnlockPassword;
/**
* Attempt to unlock the signer with a password
* @throws
*/
async unlock(password) {
if (!password) {
if (!PasswordAccount.requestUnlockPassword)
throw new Error("Cant unlock PasswordAccount without a password. either pass one in or set PasswordAccount.requestUnlockPassword");
password = await PasswordAccount.requestUnlockPassword(this);
}
await this.signer.unlock(password);
}
operation(operation) {
// If the account is not unlocked, wait for the unlock password to be provided
if (!this.unlocked) {
if (!PasswordAccount.requestUnlockPassword)
throw new Error("Account is locked and there is no requestUnlockPassword method");
return this.unlock().then(() => super.operation(operation));
}
else
return super.operation(operation);
}
toJSON() {
if (!this.signer.ncryptsec)
throw new Error("Cant save account without ncryptsec");
return super.saveCommonFields({
signer: { ncryptsec: this.signer.ncryptsec },
});
}
static fromJSON(json) {
const signer = new PasswordSigner();
signer.ncryptsec = json.signer.ncryptsec;
const account = new PasswordAccount(json.pubkey, signer);
return super.loadCommonFields(account, json);
}
/** Creates a new PasswordAccount from a ncryptsec string */
static fromNcryptsec(pubkey, ncryptsec) {
const signer = new PasswordSigner();
signer.ncryptsec = ncryptsec;
return new PasswordAccount(pubkey, signer);
}
}