@ckb-ccc/nip07 0.0.8-alpha.1 → 0.0.8-alpha.2

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/signer.js CHANGED
@@ -34,12 +34,10 @@ export class Signer extends ccc.SignerNostr {
34
34
  await this.connectionsRepo.set({ publicKey: this.publicKey });
35
35
  }
36
36
  async isConnected() {
37
- try {
38
- await this.getNostrPublicKey();
37
+ if (this.publicKey) {
39
38
  return true;
40
39
  }
41
- catch (_) {
42
- return false;
43
- }
40
+ this.publicKey = (await this.connectionsRepo.get())?.publicKey;
41
+ return this.publicKey !== undefined;
44
42
  }
45
43
  }
@@ -1,2 +1,2 @@
1
1
  export * as Nip07A from "./nip07.advanced";
2
- //# sourceMappingURL=advanced.d.ts.map
2
+ //# sourceMappingURL=advanced.d.ts.map
@@ -1,48 +1,27 @@
1
1
  "use strict";
2
- var __createBinding =
3
- (this && this.__createBinding) ||
4
- (Object.create
5
- ? function (o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- var desc = Object.getOwnPropertyDescriptor(m, k);
8
- if (
9
- !desc ||
10
- ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)
11
- ) {
12
- desc = {
13
- enumerable: true,
14
- get: function () {
15
- return m[k];
16
- },
17
- };
18
- }
19
- Object.defineProperty(o, k2, desc);
20
- }
21
- : function (o, m, k, k2) {
22
- if (k2 === undefined) k2 = k;
23
- o[k2] = m[k];
24
- });
25
- var __setModuleDefault =
26
- (this && this.__setModuleDefault) ||
27
- (Object.create
28
- ? function (o, v) {
29
- Object.defineProperty(o, "default", { enumerable: true, value: v });
30
- }
31
- : function (o, v) {
32
- o["default"] = v;
33
- });
34
- var __importStar =
35
- (this && this.__importStar) ||
36
- function (mod) {
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
37
19
  if (mod && mod.__esModule) return mod;
38
20
  var result = {};
39
- if (mod != null)
40
- for (var k in mod)
41
- if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
42
- __createBinding(result, mod, k);
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
43
22
  __setModuleDefault(result, mod);
44
23
  return result;
45
- };
24
+ };
46
25
  Object.defineProperty(exports, "__esModule", { value: true });
47
26
  exports.Nip07A = void 0;
48
27
  exports.Nip07A = __importStar(require("./nip07.advanced"));
@@ -1,3 +1,3 @@
1
1
  export * from "./signer";
2
2
  export * from "./signersFactory";
3
- //# sourceMappingURL=barrel.d.ts.map
3
+ //# sourceMappingURL=barrel.d.ts.map
@@ -1,34 +1,18 @@
1
1
  "use strict";
2
- var __createBinding =
3
- (this && this.__createBinding) ||
4
- (Object.create
5
- ? function (o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- var desc = Object.getOwnPropertyDescriptor(m, k);
8
- if (
9
- !desc ||
10
- ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)
11
- ) {
12
- desc = {
13
- enumerable: true,
14
- get: function () {
15
- return m[k];
16
- },
17
- };
18
- }
19
- Object.defineProperty(o, k2, desc);
20
- }
21
- : function (o, m, k, k2) {
22
- if (k2 === undefined) k2 = k;
23
- o[k2] = m[k];
24
- });
25
- var __exportStar =
26
- (this && this.__exportStar) ||
27
- function (m, exports) {
28
- for (var p in m)
29
- if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p))
30
- __createBinding(exports, m, p);
31
- };
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
32
16
  Object.defineProperty(exports, "__esModule", { value: true });
33
17
  __exportStar(require("./signer"), exports);
34
18
  __exportStar(require("./signersFactory"), exports);
@@ -5,24 +5,24 @@ import { ccc } from "@ckb-ccc/core";
5
5
  * @property {ccc.Hex} publicKey - The public key of the connection.
6
6
  */
7
7
  export type Connection = {
8
- readonly publicKey: ccc.Hex;
8
+ readonly publicKey: ccc.Hex;
9
9
  };
10
10
  /**
11
11
  * Interface representing a repository for managing connections.
12
12
  * @interface
13
13
  */
14
14
  export interface ConnectionsRepo {
15
- /**
16
- * Gets a connection.
17
- * @returns {Promise<Connection | undefined>} A promise that resolves to the connection, if found.
18
- */
19
- get(): Promise<Connection | undefined>;
20
- /**
21
- * Sets a connection.
22
- * @param {Connection | undefined} connection - The connection to set.
23
- * @returns {Promise<void>} A promise that resolves when the connection is set.
24
- */
25
- set(connection: Connection | undefined): Promise<void>;
15
+ /**
16
+ * Gets a connection.
17
+ * @returns {Promise<Connection | undefined>} A promise that resolves to the connection, if found.
18
+ */
19
+ get(): Promise<Connection | undefined>;
20
+ /**
21
+ * Sets a connection.
22
+ * @param {Connection | undefined} connection - The connection to set.
23
+ * @returns {Promise<void>} A promise that resolves when the connection is set.
24
+ */
25
+ set(connection: Connection | undefined): Promise<void>;
26
26
  }
27
27
  /**
28
28
  * Class representing a local storage-based repository for managing connections.
@@ -30,22 +30,22 @@ export interface ConnectionsRepo {
30
30
  * @implements {ConnectionsRepo}
31
31
  */
32
32
  export declare class ConnectionsRepoLocalStorage implements ConnectionsRepo {
33
- private readonly storageKey;
34
- /**
35
- * Creates an instance of ConnectionsRepoLocalStorage.
36
- * @param {string} [storageKey="ccc-nip07-signer"] - The local storage key.
37
- */
38
- constructor(storageKey?: string);
39
- /**
40
- * Gets a connection.
41
- * @returns {Promise<Connection | undefined>} A promise that resolves to the connection, if found.
42
- */
43
- get(): Promise<Connection | undefined>;
44
- /**
45
- * Sets a connection.
46
- * @param {Connection | undefined} connection - The connection to set.
47
- * @returns {Promise<void>}
48
- */
49
- set(connection: Connection | undefined): Promise<void>;
33
+ private readonly storageKey;
34
+ /**
35
+ * Creates an instance of ConnectionsRepoLocalStorage.
36
+ * @param {string} [storageKey="ccc-nip07-signer"] - The local storage key.
37
+ */
38
+ constructor(storageKey?: string);
39
+ /**
40
+ * Gets a connection.
41
+ * @returns {Promise<Connection | undefined>} A promise that resolves to the connection, if found.
42
+ */
43
+ get(): Promise<Connection | undefined>;
44
+ /**
45
+ * Sets a connection.
46
+ * @param {Connection | undefined} connection - The connection to set.
47
+ * @returns {Promise<void>}
48
+ */
49
+ set(connection: Connection | undefined): Promise<void>;
50
50
  }
51
- //# sourceMappingURL=connectionsRepo.d.ts.map
51
+ //# sourceMappingURL=connectionsRepo.d.ts.map
@@ -7,32 +7,32 @@ exports.ConnectionsRepoLocalStorage = void 0;
7
7
  * @implements {ConnectionsRepo}
8
8
  */
9
9
  class ConnectionsRepoLocalStorage {
10
- /**
11
- * Creates an instance of ConnectionsRepoLocalStorage.
12
- * @param {string} [storageKey="ccc-nip07-signer"] - The local storage key.
13
- */
14
- constructor(storageKey = "ccc-nip07-signer") {
15
- this.storageKey = storageKey;
16
- }
17
- /**
18
- * Gets a connection.
19
- * @returns {Promise<Connection | undefined>} A promise that resolves to the connection, if found.
20
- */
21
- async get() {
22
- const got = window.localStorage.getItem(this.storageKey);
23
- return got ? JSON.parse(got) : undefined;
24
- }
25
- /**
26
- * Sets a connection.
27
- * @param {Connection | undefined} connection - The connection to set.
28
- * @returns {Promise<void>}
29
- */
30
- async set(connection) {
31
- if (connection === undefined) {
32
- window.localStorage.removeItem(this.storageKey);
33
- return;
10
+ /**
11
+ * Creates an instance of ConnectionsRepoLocalStorage.
12
+ * @param {string} [storageKey="ccc-nip07-signer"] - The local storage key.
13
+ */
14
+ constructor(storageKey = "ccc-nip07-signer") {
15
+ this.storageKey = storageKey;
16
+ }
17
+ /**
18
+ * Gets a connection.
19
+ * @returns {Promise<Connection | undefined>} A promise that resolves to the connection, if found.
20
+ */
21
+ async get() {
22
+ const got = window.localStorage.getItem(this.storageKey);
23
+ return got ? JSON.parse(got) : undefined;
24
+ }
25
+ /**
26
+ * Sets a connection.
27
+ * @param {Connection | undefined} connection - The connection to set.
28
+ * @returns {Promise<void>}
29
+ */
30
+ async set(connection) {
31
+ if (connection === undefined) {
32
+ window.localStorage.removeItem(this.storageKey);
33
+ return;
34
+ }
35
+ window.localStorage.setItem(this.storageKey, JSON.stringify(connection));
34
36
  }
35
- window.localStorage.setItem(this.storageKey, JSON.stringify(connection));
36
- }
37
37
  }
38
38
  exports.ConnectionsRepoLocalStorage = ConnectionsRepoLocalStorage;
@@ -1,2 +1,2 @@
1
1
  export * as Nip07 from "./barrel";
2
- //# sourceMappingURL=index.d.ts.map
2
+ //# sourceMappingURL=index.d.ts.map
@@ -1,48 +1,27 @@
1
1
  "use strict";
2
- var __createBinding =
3
- (this && this.__createBinding) ||
4
- (Object.create
5
- ? function (o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- var desc = Object.getOwnPropertyDescriptor(m, k);
8
- if (
9
- !desc ||
10
- ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)
11
- ) {
12
- desc = {
13
- enumerable: true,
14
- get: function () {
15
- return m[k];
16
- },
17
- };
18
- }
19
- Object.defineProperty(o, k2, desc);
20
- }
21
- : function (o, m, k, k2) {
22
- if (k2 === undefined) k2 = k;
23
- o[k2] = m[k];
24
- });
25
- var __setModuleDefault =
26
- (this && this.__setModuleDefault) ||
27
- (Object.create
28
- ? function (o, v) {
29
- Object.defineProperty(o, "default", { enumerable: true, value: v });
30
- }
31
- : function (o, v) {
32
- o["default"] = v;
33
- });
34
- var __importStar =
35
- (this && this.__importStar) ||
36
- function (mod) {
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
37
19
  if (mod && mod.__esModule) return mod;
38
20
  var result = {};
39
- if (mod != null)
40
- for (var k in mod)
41
- if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
42
- __createBinding(result, mod, k);
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
43
22
  __setModuleDefault(result, mod);
44
23
  return result;
45
- };
24
+ };
46
25
  Object.defineProperty(exports, "__esModule", { value: true });
47
26
  exports.Nip07 = void 0;
48
27
  exports.Nip07 = __importStar(require("./barrel"));
@@ -1,6 +1,6 @@
1
1
  import { ccc } from "@ckb-ccc/core";
2
2
  export interface Provider {
3
- getPublicKey(): Promise<string>;
4
- signEvent(event: ccc.NostrEvent): Promise<Required<ccc.NostrEvent>>;
3
+ getPublicKey(): Promise<string>;
4
+ signEvent(event: ccc.NostrEvent): Promise<Required<ccc.NostrEvent>>;
5
5
  }
6
- //# sourceMappingURL=nip07.advanced.d.ts.map
6
+ //# sourceMappingURL=nip07.advanced.d.ts.map
@@ -2,19 +2,15 @@ import { ccc } from "@ckb-ccc/core";
2
2
  import { ConnectionsRepo } from "./connectionsRepo";
3
3
  import { Provider } from "./nip07.advanced";
4
4
  export declare class Signer extends ccc.SignerNostr {
5
- readonly provider: Provider;
6
- private readonly connectionsRepo;
7
- private publicKey;
8
- constructor(
9
- client: ccc.Client,
10
- provider: Provider,
11
- connectionsRepo?: ConnectionsRepo,
12
- );
13
- static isValidClient(client: ccc.Client): boolean;
14
- replaceClient(client: ccc.Client): Promise<boolean>;
15
- getNostrPublicKey(): Promise<ccc.Hex>;
16
- signNostrEvent(event: ccc.NostrEvent): Promise<Required<ccc.NostrEvent>>;
17
- connect(): Promise<void>;
18
- isConnected(): Promise<boolean>;
5
+ readonly provider: Provider;
6
+ private readonly connectionsRepo;
7
+ private publicKey;
8
+ constructor(client: ccc.Client, provider: Provider, connectionsRepo?: ConnectionsRepo);
9
+ static isValidClient(client: ccc.Client): boolean;
10
+ replaceClient(client: ccc.Client): Promise<boolean>;
11
+ getNostrPublicKey(): Promise<ccc.Hex>;
12
+ signNostrEvent(event: ccc.NostrEvent): Promise<Required<ccc.NostrEvent>>;
13
+ connect(): Promise<void>;
14
+ isConnected(): Promise<boolean>;
19
15
  }
20
- //# sourceMappingURL=signer.d.ts.map
16
+ //# sourceMappingURL=signer.d.ts.map
@@ -4,49 +4,44 @@ exports.Signer = void 0;
4
4
  const core_1 = require("@ckb-ccc/core");
5
5
  const connectionsRepo_1 = require("./connectionsRepo");
6
6
  class Signer extends core_1.ccc.SignerNostr {
7
- constructor(
8
- client,
9
- provider,
10
- connectionsRepo = new connectionsRepo_1.ConnectionsRepoLocalStorage(),
11
- ) {
12
- super(client);
13
- this.provider = provider;
14
- this.connectionsRepo = connectionsRepo;
15
- this.publicKey = undefined;
16
- }
17
- static isValidClient(client) {
18
- return client.addressPrefix === "ckt";
19
- }
20
- async replaceClient(client) {
21
- if (!Signer.isValidClient(client)) {
22
- return false;
7
+ constructor(client, provider, connectionsRepo = new connectionsRepo_1.ConnectionsRepoLocalStorage()) {
8
+ super(client);
9
+ this.provider = provider;
10
+ this.connectionsRepo = connectionsRepo;
11
+ this.publicKey = undefined;
23
12
  }
24
- return super.replaceClient(client);
25
- }
26
- async getNostrPublicKey() {
27
- if (this.publicKey) {
28
- return this.publicKey;
13
+ static isValidClient(client) {
14
+ return client.addressPrefix === "ckt";
29
15
  }
30
- this.publicKey = (await this.connectionsRepo.get())?.publicKey;
31
- if (!this.publicKey) {
32
- throw new Error("Not connected");
16
+ async replaceClient(client) {
17
+ if (!Signer.isValidClient(client)) {
18
+ return false;
19
+ }
20
+ return super.replaceClient(client);
33
21
  }
34
- return this.publicKey;
35
- }
36
- async signNostrEvent(event) {
37
- return this.provider.signEvent(event);
38
- }
39
- async connect() {
40
- this.publicKey = core_1.ccc.hexFrom(await this.provider.getPublicKey());
41
- await this.connectionsRepo.set({ publicKey: this.publicKey });
42
- }
43
- async isConnected() {
44
- try {
45
- await this.getNostrPublicKey();
46
- return true;
47
- } catch (_) {
48
- return false;
22
+ async getNostrPublicKey() {
23
+ if (this.publicKey) {
24
+ return this.publicKey;
25
+ }
26
+ this.publicKey = (await this.connectionsRepo.get())?.publicKey;
27
+ if (!this.publicKey) {
28
+ throw new Error("Not connected");
29
+ }
30
+ return this.publicKey;
31
+ }
32
+ async signNostrEvent(event) {
33
+ return this.provider.signEvent(event);
34
+ }
35
+ async connect() {
36
+ this.publicKey = core_1.ccc.hexFrom(await this.provider.getPublicKey());
37
+ await this.connectionsRepo.set({ publicKey: this.publicKey });
38
+ }
39
+ async isConnected() {
40
+ if (this.publicKey) {
41
+ return true;
42
+ }
43
+ this.publicKey = (await this.connectionsRepo.get())?.publicKey;
44
+ return this.publicKey !== undefined;
49
45
  }
50
- }
51
46
  }
52
47
  exports.Signer = Signer;
@@ -1,4 +1,4 @@
1
1
  import { ccc } from "@ckb-ccc/core";
2
2
  import { Signer } from "./signer";
3
3
  export declare function getNip07Signer(client: ccc.Client): Signer | undefined;
4
- //# sourceMappingURL=signersFactory.d.ts.map
4
+ //# sourceMappingURL=signersFactory.d.ts.map
@@ -3,13 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getNip07Signer = void 0;
4
4
  const signer_1 = require("./signer");
5
5
  function getNip07Signer(client) {
6
- const windowRef = window;
7
- if (
8
- typeof windowRef.nostr === "undefined" ||
9
- !signer_1.Signer.isValidClient(client)
10
- ) {
11
- return;
12
- }
13
- return new signer_1.Signer(client, windowRef.nostr);
6
+ const windowRef = window;
7
+ if (typeof windowRef.nostr === "undefined" || !signer_1.Signer.isValidClient(client)) {
8
+ return;
9
+ }
10
+ return new signer_1.Signer(client, windowRef.nostr);
14
11
  }
15
12
  exports.getNip07Signer = getNip07Signer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckb-ccc/nip07",
3
- "version": "0.0.8-alpha.1",
3
+ "version": "0.0.8-alpha.2",
4
4
  "description": "Common Chains Connector's support for NIP07",
5
5
  "author": "Hanssen0 <hanssen0@hanssen0.com>",
6
6
  "license": "MIT",
@@ -44,5 +44,5 @@
44
44
  "dependencies": {
45
45
  "@ckb-ccc/core": "0.0.7-alpha.2"
46
46
  },
47
- "gitHead": "68f78f532ecc1ee70c94c5756f963c709205709f"
47
+ "gitHead": "ca01248c0bb4c59c7e3ce83ec5fc50d9de4f7d93"
48
48
  }
package/src/signer.ts CHANGED
@@ -52,11 +52,11 @@ export class Signer extends ccc.SignerNostr {
52
52
  }
53
53
 
54
54
  async isConnected(): Promise<boolean> {
55
- try {
56
- await this.getNostrPublicKey();
55
+ if (this.publicKey) {
57
56
  return true;
58
- } catch (_) {
59
- return false;
60
57
  }
58
+
59
+ this.publicKey = (await this.connectionsRepo.get())?.publicKey;
60
+ return this.publicKey !== undefined;
61
61
  }
62
62
  }