applesauce-accounts 0.0.0-next-20250128154531 → 0.0.0-next-20250128164720

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/account.d.ts CHANGED
@@ -23,6 +23,8 @@ export declare class BaseAccount<Signer extends Nip07Interface, SignerData, Meta
23
23
  } | undefined;
24
24
  constructor(pubkey: string, signer: Signer);
25
25
  toJSON(): SerializedAccount<SignerData, Metadata>;
26
+ /** Sets an accounts id and metadata. NOTE: This should only be used in fromJSON methods */
27
+ static loadCommonFields<T extends IAccount<any, any, any>>(account: T, json: SerializedAccount<any, any>): T;
26
28
  /** Gets the pubkey from the signer */
27
29
  getPublicKey(): string | Promise<string>;
28
30
  /** sign the event and make sure its signed with the correct pubkey */
package/dist/account.js CHANGED
@@ -68,6 +68,14 @@ export class BaseAccount {
68
68
  toJSON() {
69
69
  throw new Error("Not implemented");
70
70
  }
71
+ /** Sets an accounts id and metadata. NOTE: This should only be used in fromJSON methods */
72
+ static loadCommonFields(account, json) {
73
+ if (json.id)
74
+ account.id = json.id;
75
+ if (json.metadata)
76
+ account.metadata = json.metadata;
77
+ return account;
78
+ }
71
79
  /** Gets the pubkey from the signer */
72
80
  getPublicKey() {
73
81
  const result = this.signer.getPublicKey();
@@ -5,5 +5,5 @@ import { SerializedAccount } from "../types.js";
5
5
  export declare class AmberClipboardAccount<Metadata extends unknown> extends BaseAccount<AmberClipboardSigner, void, Metadata> {
6
6
  static type: string;
7
7
  toJSON(): SerializedAccount<void, Metadata>;
8
- static fromJSON<MD extends unknown>(json: SerializedAccount<void, MD>): AmberClipboardAccount<MD>;
8
+ static fromJSON<Metadata extends unknown>(json: SerializedAccount<void, Metadata>): AmberClipboardAccount<Metadata>;
9
9
  }
@@ -13,6 +13,7 @@ export class AmberClipboardAccount extends BaseAccount {
13
13
  };
14
14
  }
15
15
  static fromJSON(json) {
16
- return new AmberClipboardAccount(json.pubkey, new AmberClipboardSigner());
16
+ const account = new AmberClipboardAccount(json.pubkey, new AmberClipboardSigner());
17
+ return super.loadCommonFields(account, json);
17
18
  }
18
19
  }
@@ -12,5 +12,5 @@ export declare class ExtensionAccount<Metadata extends unknown> extends BaseAcco
12
12
  metadata: Metadata | undefined;
13
13
  signer: undefined;
14
14
  };
15
- static fromJSON<MD extends unknown>(json: SerializedAccount<void, MD>): ExtensionAccount<unknown>;
15
+ static fromJSON<Metadata extends unknown>(json: SerializedAccount<void, Metadata>): ExtensionAccount<Metadata>;
16
16
  }
@@ -17,6 +17,7 @@ export class ExtensionAccount extends BaseAccount {
17
17
  };
18
18
  }
19
19
  static fromJSON(json) {
20
- return new ExtensionAccount(json.pubkey, new ExtensionSigner());
20
+ const account = new ExtensionAccount(json.pubkey, new ExtensionSigner());
21
+ return super.loadCommonFields(account, json);
21
22
  }
22
23
  }
@@ -27,6 +27,7 @@ export class NostrConnectAccount extends BaseAccount {
27
27
  remote: json.signer.remote,
28
28
  signer: new SimpleSigner(hexToBytes(json.signer.clientKey)),
29
29
  });
30
- return new NostrConnectAccount(json.pubkey, signer);
30
+ const account = new NostrConnectAccount(json.pubkey, signer);
31
+ return super.loadCommonFields(account, json);
31
32
  }
32
33
  }
@@ -31,7 +31,8 @@ export class PasswordAccount extends BaseAccount {
31
31
  static fromJSON(json) {
32
32
  const signer = new PasswordSigner();
33
33
  signer.ncryptsec = json.signer.ncryptsec;
34
- return new PasswordAccount(json.pubkey, signer);
34
+ const account = new PasswordAccount(json.pubkey, signer);
35
+ return super.loadCommonFields(account, json);
35
36
  }
36
37
  /** Creates a new PasswordAccount from a ncryptsec string */
37
38
  static fromNcryptsec(pubkey, ncryptsec) {
@@ -13,6 +13,7 @@ export class ReadonlyAccount extends BaseAccount {
13
13
  };
14
14
  }
15
15
  static fromJSON(json) {
16
- return new ReadonlyAccount(json.pubkey, new ReadonlySigner(json.pubkey));
16
+ const account = new ReadonlyAccount(json.pubkey, new ReadonlySigner(json.pubkey));
17
+ return super.loadCommonFields(account, json);
17
18
  }
18
19
  }
@@ -24,6 +24,8 @@ export class SerialPortAccount extends BaseAccount {
24
24
  };
25
25
  }
26
26
  static fromJSON(json) {
27
- return new SerialPortAccount(json.pubkey, new SerialPortSigner());
27
+ const signer = new SerialPortSigner();
28
+ const account = new SerialPortAccount(json.pubkey, signer);
29
+ return super.loadCommonFields(account, json);
28
30
  }
29
31
  }
@@ -15,7 +15,8 @@ export class SimpleAccount extends BaseAccount {
15
15
  }
16
16
  static fromJSON(json) {
17
17
  const key = hexToBytes(json.signer.key);
18
- return new SimpleAccount(json.pubkey, new SimpleSigner(key));
18
+ const account = new SimpleAccount(json.pubkey, new SimpleSigner(key));
19
+ return super.loadCommonFields(account, json);
19
20
  }
20
21
  static fromKey(key) {
21
22
  if (typeof key === "string")
package/dist/types.d.ts CHANGED
@@ -10,8 +10,6 @@ export type SerializedAccount<SignerData, Metadata extends unknown> = {
10
10
  id: string;
11
11
  /** account type */
12
12
  type: string;
13
- /** local name of the account */
14
- name?: string;
15
13
  /** pubkey of the account */
16
14
  pubkey: string;
17
15
  /** Signer data */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "applesauce-accounts",
3
- "version": "0.0.0-next-20250128154531",
3
+ "version": "0.0.0-next-20250128164720",
4
4
  "description": "A simple nostr account management system",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -33,7 +33,7 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "@noble/hashes": "^1.5.0",
36
- "applesauce-signers": "0.0.0-next-20250128154531",
36
+ "applesauce-signers": "0.0.0-next-20250128164720",
37
37
  "nanoid": "^5.0.9",
38
38
  "nostr-tools": "^2.10.3",
39
39
  "rxjs": "^7.8.1"