@ckb-ccc/nip07 0.0.9-alpha.1 → 0.0.10-alpha.4

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.d.ts CHANGED
@@ -1,12 +1,9 @@
1
1
  import { ccc } from "@ckb-ccc/core";
2
- import { ConnectionsRepo } from "./connectionsRepo";
3
2
  import { Provider } from "./nip07.advanced";
4
3
  export declare class Signer extends ccc.SignerNostr {
5
4
  readonly provider: Provider;
6
- private readonly connectionsRepo;
7
- private publicKey;
8
- constructor(client: ccc.Client, provider: Provider, connectionsRepo?: ConnectionsRepo);
9
- replaceClient(client: ccc.Client): Promise<boolean>;
5
+ private publicKeyCache?;
6
+ constructor(client: ccc.Client, provider: Provider);
10
7
  getNostrPublicKey(): Promise<ccc.Hex>;
11
8
  signNostrEvent(event: ccc.NostrEvent): Promise<Required<ccc.NostrEvent>>;
12
9
  connect(): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../src/signer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EACL,eAAe,EAEhB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,qBAAa,MAAO,SAAQ,GAAG,CAAC,WAAW;aAKvB,QAAQ,EAAE,QAAQ;IAClC,OAAO,CAAC,QAAQ,CAAC,eAAe;IALlC,OAAO,CAAC,SAAS,CAAkC;gBAGjD,MAAM,EAAE,GAAG,CAAC,MAAM,EACF,QAAQ,EAAE,QAAQ,EACjB,eAAe,GAAE,eAAmD;IAKjF,aAAa,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAInD,iBAAiB,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;IAarC,cAAc,CAClB,KAAK,EAAE,GAAG,CAAC,UAAU,GACpB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAI9B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAKxB,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;CAQtC"}
1
+ {"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../src/signer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,qBAAa,MAAO,SAAQ,GAAG,CAAC,WAAW;aAKvB,QAAQ,EAAE,QAAQ;IAJpC,OAAO,CAAC,cAAc,CAAC,CAA8B;gBAGnD,MAAM,EAAE,GAAG,CAAC,MAAM,EACF,QAAQ,EAAE,QAAQ;IAK9B,iBAAiB,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;IAQrC,cAAc,CAClB,KAAK,EAAE,GAAG,CAAC,UAAU,GACpB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAO9B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAIxB,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;CAGtC"}
package/dist/signer.js CHANGED
@@ -1,37 +1,26 @@
1
1
  import { ccc } from "@ckb-ccc/core";
2
- import { ConnectionsRepoLocalStorage, } from "./connectionsRepo";
3
2
  export class Signer extends ccc.SignerNostr {
4
- constructor(client, provider, connectionsRepo = new ConnectionsRepoLocalStorage()) {
3
+ constructor(client, provider) {
5
4
  super(client);
6
5
  this.provider = provider;
7
- this.connectionsRepo = connectionsRepo;
8
- this.publicKey = undefined;
9
- }
10
- async replaceClient(client) {
11
- return super.replaceClient(client);
6
+ this.publicKeyCache = undefined;
12
7
  }
13
8
  async getNostrPublicKey() {
14
- if (this.publicKey) {
15
- return this.publicKey;
16
- }
17
- this.publicKey = (await this.connectionsRepo.get())?.publicKey;
18
- if (!this.publicKey) {
19
- throw new Error("Not connected");
9
+ if (!this.publicKeyCache) {
10
+ this.publicKeyCache = this.provider.getPublicKey();
20
11
  }
21
- return this.publicKey;
12
+ return ccc.hexFrom(await this.publicKeyCache);
22
13
  }
23
14
  async signNostrEvent(event) {
24
- return this.provider.signEvent(event);
15
+ return this.provider.signEvent({
16
+ ...event,
17
+ pubkey: await this.publicKeyCache,
18
+ });
25
19
  }
26
20
  async connect() {
27
- this.publicKey = ccc.hexFrom(await this.provider.getPublicKey());
28
- await this.connectionsRepo.set({ publicKey: this.publicKey });
21
+ return;
29
22
  }
30
23
  async isConnected() {
31
- if (this.publicKey) {
32
- return true;
33
- }
34
- this.publicKey = (await this.connectionsRepo.get())?.publicKey;
35
- return this.publicKey !== undefined;
24
+ return true;
36
25
  }
37
26
  }
@@ -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,27 +1,48 @@
1
1
  "use strict";
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) {
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) {
19
37
  if (mod && mod.__esModule) return mod;
20
38
  var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
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);
22
43
  __setModuleDefault(result, mod);
23
44
  return result;
24
- };
45
+ };
25
46
  Object.defineProperty(exports, "__esModule", { value: true });
26
47
  exports.Nip07A = void 0;
27
48
  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,18 +1,34 @@
1
1
  "use strict";
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
- };
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
+ };
16
32
  Object.defineProperty(exports, "__esModule", { value: true });
17
33
  __exportStar(require("./signer"), exports);
18
34
  __exportStar(require("./signersFactory"), exports);
@@ -1,2 +1,2 @@
1
1
  export * as Nip07 from "./barrel";
2
- //# sourceMappingURL=index.d.ts.map
2
+ //# sourceMappingURL=index.d.ts.map
@@ -1,27 +1,48 @@
1
1
  "use strict";
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) {
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) {
19
37
  if (mod && mod.__esModule) return mod;
20
38
  var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
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);
22
43
  __setModuleDefault(result, mod);
23
44
  return result;
24
- };
45
+ };
25
46
  Object.defineProperty(exports, "__esModule", { value: true });
26
47
  exports.Nip07 = void 0;
27
48
  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
@@ -1,15 +1,12 @@
1
1
  import { ccc } from "@ckb-ccc/core";
2
- import { ConnectionsRepo } from "./connectionsRepo";
3
2
  import { Provider } from "./nip07.advanced";
4
3
  export declare class Signer extends ccc.SignerNostr {
5
- readonly provider: Provider;
6
- private readonly connectionsRepo;
7
- private publicKey;
8
- constructor(client: ccc.Client, provider: Provider, connectionsRepo?: ConnectionsRepo);
9
- replaceClient(client: ccc.Client): Promise<boolean>;
10
- getNostrPublicKey(): Promise<ccc.Hex>;
11
- signNostrEvent(event: ccc.NostrEvent): Promise<Required<ccc.NostrEvent>>;
12
- connect(): Promise<void>;
13
- isConnected(): Promise<boolean>;
4
+ readonly provider: Provider;
5
+ private publicKeyCache?;
6
+ constructor(client: ccc.Client, provider: Provider);
7
+ getNostrPublicKey(): Promise<ccc.Hex>;
8
+ signNostrEvent(event: ccc.NostrEvent): Promise<Required<ccc.NostrEvent>>;
9
+ connect(): Promise<void>;
10
+ isConnected(): Promise<boolean>;
14
11
  }
15
- //# sourceMappingURL=signer.d.ts.map
12
+ //# sourceMappingURL=signer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../src/signer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EACL,eAAe,EAEhB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,qBAAa,MAAO,SAAQ,GAAG,CAAC,WAAW;aAKvB,QAAQ,EAAE,QAAQ;IAClC,OAAO,CAAC,QAAQ,CAAC,eAAe;IALlC,OAAO,CAAC,SAAS,CAAkC;gBAGjD,MAAM,EAAE,GAAG,CAAC,MAAM,EACF,QAAQ,EAAE,QAAQ,EACjB,eAAe,GAAE,eAAmD;IAKjF,aAAa,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAInD,iBAAiB,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;IAarC,cAAc,CAClB,KAAK,EAAE,GAAG,CAAC,UAAU,GACpB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAI9B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAKxB,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;CAQtC"}
1
+ {"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../src/signer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,qBAAa,MAAO,SAAQ,GAAG,CAAC,WAAW;aAKvB,QAAQ,EAAE,QAAQ;IAJpC,OAAO,CAAC,cAAc,CAAC,CAA8B;gBAGnD,MAAM,EAAE,GAAG,CAAC,MAAM,EACF,QAAQ,EAAE,QAAQ;IAK9B,iBAAiB,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;IAQrC,cAAc,CAClB,KAAK,EAAE,GAAG,CAAC,UAAU,GACpB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAO9B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAIxB,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;CAGtC"}
@@ -2,40 +2,29 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Signer = void 0;
4
4
  const core_1 = require("@ckb-ccc/core");
5
- const connectionsRepo_1 = require("./connectionsRepo");
6
5
  class Signer extends core_1.ccc.SignerNostr {
7
- constructor(client, provider, connectionsRepo = new connectionsRepo_1.ConnectionsRepoLocalStorage()) {
8
- super(client);
9
- this.provider = provider;
10
- this.connectionsRepo = connectionsRepo;
11
- this.publicKey = undefined;
12
- }
13
- async replaceClient(client) {
14
- return super.replaceClient(client);
15
- }
16
- async getNostrPublicKey() {
17
- if (this.publicKey) {
18
- return this.publicKey;
19
- }
20
- this.publicKey = (await this.connectionsRepo.get())?.publicKey;
21
- if (!this.publicKey) {
22
- throw new Error("Not connected");
23
- }
24
- return this.publicKey;
25
- }
26
- async signNostrEvent(event) {
27
- return this.provider.signEvent(event);
28
- }
29
- async connect() {
30
- this.publicKey = core_1.ccc.hexFrom(await this.provider.getPublicKey());
31
- await this.connectionsRepo.set({ publicKey: this.publicKey });
32
- }
33
- async isConnected() {
34
- if (this.publicKey) {
35
- return true;
36
- }
37
- this.publicKey = (await this.connectionsRepo.get())?.publicKey;
38
- return this.publicKey !== undefined;
6
+ constructor(client, provider) {
7
+ super(client);
8
+ this.provider = provider;
9
+ this.publicKeyCache = undefined;
10
+ }
11
+ async getNostrPublicKey() {
12
+ if (!this.publicKeyCache) {
13
+ this.publicKeyCache = this.provider.getPublicKey();
39
14
  }
15
+ return core_1.ccc.hexFrom(await this.publicKeyCache);
16
+ }
17
+ async signNostrEvent(event) {
18
+ return this.provider.signEvent({
19
+ ...event,
20
+ pubkey: await this.publicKeyCache,
21
+ });
22
+ }
23
+ async connect() {
24
+ return;
25
+ }
26
+ async isConnected() {
27
+ return true;
28
+ }
40
29
  }
41
30
  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,10 +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 (typeof windowRef.nostr === "undefined") {
8
- return;
9
- }
10
- return new signer_1.Signer(client, windowRef.nostr);
6
+ const windowRef = window;
7
+ if (typeof windowRef.nostr === "undefined") {
8
+ return;
9
+ }
10
+ return new signer_1.Signer(client, windowRef.nostr);
11
11
  }
12
12
  exports.getNip07Signer = getNip07Signer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckb-ccc/nip07",
3
- "version": "0.0.9-alpha.1",
3
+ "version": "0.0.10-alpha.4",
4
4
  "description": "CCC - CKBer's Codebase. Common Chains Connector's support for NIP07",
5
5
  "author": "Hanssen0 <hanssen0@hanssen0.com>",
6
6
  "license": "MIT",
@@ -42,7 +42,7 @@
42
42
  "access": "public"
43
43
  },
44
44
  "dependencies": {
45
- "@ckb-ccc/core": "0.0.9-alpha.1"
45
+ "@ckb-ccc/core": "0.0.10-alpha.4"
46
46
  },
47
- "gitHead": "d708cbabd48a160d7608a0b86093b16f35451f79"
47
+ "gitHead": "61228337bbf4bdc0bc082e3c9530f843c2182106"
48
48
  }
package/src/signer.ts CHANGED
@@ -1,55 +1,38 @@
1
1
  import { ccc } from "@ckb-ccc/core";
2
- import {
3
- ConnectionsRepo,
4
- ConnectionsRepoLocalStorage,
5
- } from "./connectionsRepo";
6
2
  import { Provider } from "./nip07.advanced";
7
3
 
8
4
  export class Signer extends ccc.SignerNostr {
9
- private publicKey: ccc.Hex | undefined = undefined;
5
+ private publicKeyCache?: Promise<string> = undefined;
10
6
 
11
7
  constructor(
12
8
  client: ccc.Client,
13
9
  public readonly provider: Provider,
14
- private readonly connectionsRepo: ConnectionsRepo = new ConnectionsRepoLocalStorage(),
15
10
  ) {
16
11
  super(client);
17
12
  }
18
13
 
19
- async replaceClient(client: ccc.Client): Promise<boolean> {
20
- return super.replaceClient(client);
21
- }
22
-
23
14
  async getNostrPublicKey(): Promise<ccc.Hex> {
24
- if (this.publicKey) {
25
- return this.publicKey;
26
- }
27
-
28
- this.publicKey = (await this.connectionsRepo.get())?.publicKey;
29
- if (!this.publicKey) {
30
- throw new Error("Not connected");
15
+ if (!this.publicKeyCache) {
16
+ this.publicKeyCache = this.provider.getPublicKey();
31
17
  }
32
18
 
33
- return this.publicKey;
19
+ return ccc.hexFrom(await this.publicKeyCache);
34
20
  }
35
21
 
36
22
  async signNostrEvent(
37
23
  event: ccc.NostrEvent,
38
24
  ): Promise<Required<ccc.NostrEvent>> {
39
- return this.provider.signEvent(event);
25
+ return this.provider.signEvent({
26
+ ...event,
27
+ pubkey: await this.publicKeyCache,
28
+ });
40
29
  }
41
30
 
42
31
  async connect(): Promise<void> {
43
- this.publicKey = ccc.hexFrom(await this.provider.getPublicKey());
44
- await this.connectionsRepo.set({ publicKey: this.publicKey });
32
+ return;
45
33
  }
46
34
 
47
35
  async isConnected(): Promise<boolean> {
48
- if (this.publicKey) {
49
- return true;
50
- }
51
-
52
- this.publicKey = (await this.connectionsRepo.get())?.publicKey;
53
- return this.publicKey !== undefined;
36
+ return true;
54
37
  }
55
38
  }
@@ -1,51 +0,0 @@
1
- import { ccc } from "@ckb-ccc/core";
2
- /**
3
- * Type representing a connection with public key.
4
- * @typedef {Object} Connection
5
- * @property {ccc.Hex} publicKey - The public key of the connection.
6
- */
7
- export type Connection = {
8
- readonly publicKey: ccc.Hex;
9
- };
10
- /**
11
- * Interface representing a repository for managing connections.
12
- * @interface
13
- */
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>;
26
- }
27
- /**
28
- * Class representing a local storage-based repository for managing connections.
29
- * @class
30
- * @implements {ConnectionsRepo}
31
- */
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>;
50
- }
51
- //# sourceMappingURL=connectionsRepo.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"connectionsRepo.d.ts","sourceRoot":"","sources":["../src/connectionsRepo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEpC;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,SAAS,EAAE,GAAG,CAAC,GAAG,CAAC;CAC7B,CAAC;AAEF;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,GAAG,IAAI,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAAC;IAEvC;;;;OAIG;IACH,GAAG,CAAC,UAAU,EAAE,UAAU,GAAG,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACxD;AAED;;;;GAIG;AACH,qBAAa,2BAA4B,YAAW,eAAe;IAKrD,OAAO,CAAC,QAAQ,CAAC,UAAU;IAJvC;;;OAGG;gBAC0B,UAAU,SAAqB;IAE5D;;;OAGG;IACG,GAAG,IAAI,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IAK5C;;;;OAIG;IACG,GAAG,CAAC,UAAU,EAAE,UAAU,GAAG,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;CAQ7D"}
@@ -1,34 +0,0 @@
1
- /**
2
- * Class representing a local storage-based repository for managing connections.
3
- * @class
4
- * @implements {ConnectionsRepo}
5
- */
6
- export class ConnectionsRepoLocalStorage {
7
- /**
8
- * Creates an instance of ConnectionsRepoLocalStorage.
9
- * @param {string} [storageKey="ccc-nip07-signer"] - The local storage key.
10
- */
11
- constructor(storageKey = "ccc-nip07-signer") {
12
- this.storageKey = storageKey;
13
- }
14
- /**
15
- * Gets a connection.
16
- * @returns {Promise<Connection | undefined>} A promise that resolves to the connection, if found.
17
- */
18
- async get() {
19
- const got = window.localStorage.getItem(this.storageKey);
20
- return got ? JSON.parse(got) : undefined;
21
- }
22
- /**
23
- * Sets a connection.
24
- * @param {Connection | undefined} connection - The connection to set.
25
- * @returns {Promise<void>}
26
- */
27
- async set(connection) {
28
- if (connection === undefined) {
29
- window.localStorage.removeItem(this.storageKey);
30
- return;
31
- }
32
- window.localStorage.setItem(this.storageKey, JSON.stringify(connection));
33
- }
34
- }
@@ -1,51 +0,0 @@
1
- import { ccc } from "@ckb-ccc/core";
2
- /**
3
- * Type representing a connection with public key.
4
- * @typedef {Object} Connection
5
- * @property {ccc.Hex} publicKey - The public key of the connection.
6
- */
7
- export type Connection = {
8
- readonly publicKey: ccc.Hex;
9
- };
10
- /**
11
- * Interface representing a repository for managing connections.
12
- * @interface
13
- */
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>;
26
- }
27
- /**
28
- * Class representing a local storage-based repository for managing connections.
29
- * @class
30
- * @implements {ConnectionsRepo}
31
- */
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>;
50
- }
51
- //# sourceMappingURL=connectionsRepo.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"connectionsRepo.d.ts","sourceRoot":"","sources":["../src/connectionsRepo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEpC;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,SAAS,EAAE,GAAG,CAAC,GAAG,CAAC;CAC7B,CAAC;AAEF;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,GAAG,IAAI,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAAC;IAEvC;;;;OAIG;IACH,GAAG,CAAC,UAAU,EAAE,UAAU,GAAG,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACxD;AAED;;;;GAIG;AACH,qBAAa,2BAA4B,YAAW,eAAe;IAKrD,OAAO,CAAC,QAAQ,CAAC,UAAU;IAJvC;;;OAGG;gBAC0B,UAAU,SAAqB;IAE5D;;;OAGG;IACG,GAAG,IAAI,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IAK5C;;;;OAIG;IACG,GAAG,CAAC,UAAU,EAAE,UAAU,GAAG,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;CAQ7D"}
@@ -1,38 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ConnectionsRepoLocalStorage = void 0;
4
- /**
5
- * Class representing a local storage-based repository for managing connections.
6
- * @class
7
- * @implements {ConnectionsRepo}
8
- */
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;
34
- }
35
- window.localStorage.setItem(this.storageKey, JSON.stringify(connection));
36
- }
37
- }
38
- exports.ConnectionsRepoLocalStorage = ConnectionsRepoLocalStorage;
@@ -1,65 +0,0 @@
1
- import { ccc } from "@ckb-ccc/core";
2
-
3
- /**
4
- * Type representing a connection with public key.
5
- * @typedef {Object} Connection
6
- * @property {ccc.Hex} publicKey - The public key of the connection.
7
- */
8
- export type Connection = {
9
- readonly publicKey: ccc.Hex;
10
- };
11
-
12
- /**
13
- * Interface representing a repository for managing connections.
14
- * @interface
15
- */
16
- export interface ConnectionsRepo {
17
- /**
18
- * Gets a connection.
19
- * @returns {Promise<Connection | undefined>} A promise that resolves to the connection, if found.
20
- */
21
- get(): Promise<Connection | undefined>;
22
-
23
- /**
24
- * Sets a connection.
25
- * @param {Connection | undefined} connection - The connection to set.
26
- * @returns {Promise<void>} A promise that resolves when the connection is set.
27
- */
28
- set(connection: Connection | undefined): Promise<void>;
29
- }
30
-
31
- /**
32
- * Class representing a local storage-based repository for managing connections.
33
- * @class
34
- * @implements {ConnectionsRepo}
35
- */
36
- export class ConnectionsRepoLocalStorage implements ConnectionsRepo {
37
- /**
38
- * Creates an instance of ConnectionsRepoLocalStorage.
39
- * @param {string} [storageKey="ccc-nip07-signer"] - The local storage key.
40
- */
41
- constructor(private readonly storageKey = "ccc-nip07-signer") {}
42
-
43
- /**
44
- * Gets a connection.
45
- * @returns {Promise<Connection | undefined>} A promise that resolves to the connection, if found.
46
- */
47
- async get(): Promise<Connection | undefined> {
48
- const got = window.localStorage.getItem(this.storageKey);
49
- return got ? JSON.parse(got) : undefined;
50
- }
51
-
52
- /**
53
- * Sets a connection.
54
- * @param {Connection | undefined} connection - The connection to set.
55
- * @returns {Promise<void>}
56
- */
57
- async set(connection: Connection | undefined): Promise<void> {
58
- if (connection === undefined) {
59
- window.localStorage.removeItem(this.storageKey);
60
- return;
61
- }
62
-
63
- window.localStorage.setItem(this.storageKey, JSON.stringify(connection));
64
- }
65
- }