@ckb-ccc/nip07 0.0.6-alpha.0

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.
Files changed (51) hide show
  1. package/README.md +43 -0
  2. package/dist/advanced.d.ts +2 -0
  3. package/dist/advanced.d.ts.map +1 -0
  4. package/dist/advanced.js +1 -0
  5. package/dist/barrel.d.ts +3 -0
  6. package/dist/barrel.d.ts.map +1 -0
  7. package/dist/barrel.js +2 -0
  8. package/dist/connectionsRepo.d.ts +51 -0
  9. package/dist/connectionsRepo.d.ts.map +1 -0
  10. package/dist/connectionsRepo.js +34 -0
  11. package/dist/index.d.ts +2 -0
  12. package/dist/index.d.ts.map +1 -0
  13. package/dist/index.js +1 -0
  14. package/dist/nip07.advanced.d.ts +6 -0
  15. package/dist/nip07.advanced.d.ts.map +1 -0
  16. package/dist/nip07.advanced.js +1 -0
  17. package/dist/signer.d.ts +16 -0
  18. package/dist/signer.d.ts.map +1 -0
  19. package/dist/signer.js +36 -0
  20. package/dist/signersFactory.d.ts +4 -0
  21. package/dist/signersFactory.d.ts.map +1 -0
  22. package/dist/signersFactory.js +8 -0
  23. package/dist.commonjs/advanced.d.ts +2 -0
  24. package/dist.commonjs/advanced.d.ts.map +1 -0
  25. package/dist.commonjs/advanced.js +27 -0
  26. package/dist.commonjs/barrel.d.ts +3 -0
  27. package/dist.commonjs/barrel.d.ts.map +1 -0
  28. package/dist.commonjs/barrel.js +18 -0
  29. package/dist.commonjs/connectionsRepo.d.ts +51 -0
  30. package/dist.commonjs/connectionsRepo.d.ts.map +1 -0
  31. package/dist.commonjs/connectionsRepo.js +38 -0
  32. package/dist.commonjs/index.d.ts +2 -0
  33. package/dist.commonjs/index.d.ts.map +1 -0
  34. package/dist.commonjs/index.js +27 -0
  35. package/dist.commonjs/nip07.advanced.d.ts +6 -0
  36. package/dist.commonjs/nip07.advanced.d.ts.map +1 -0
  37. package/dist.commonjs/nip07.advanced.js +2 -0
  38. package/dist.commonjs/signer.d.ts +16 -0
  39. package/dist.commonjs/signer.d.ts.map +1 -0
  40. package/dist.commonjs/signer.js +40 -0
  41. package/dist.commonjs/signersFactory.d.ts +4 -0
  42. package/dist.commonjs/signersFactory.d.ts.map +1 -0
  43. package/dist.commonjs/signersFactory.js +12 -0
  44. package/package.json +48 -0
  45. package/src/advanced.ts +1 -0
  46. package/src/barrel.ts +2 -0
  47. package/src/connectionsRepo.ts +65 -0
  48. package/src/index.ts +1 -0
  49. package/src/nip07.advanced.ts +6 -0
  50. package/src/signer.ts +53 -0
  51. package/src/signersFactory.ts +13 -0
package/README.md ADDED
@@ -0,0 +1,43 @@
1
+ <p align="center">
2
+ <a href="https://ckbccc-demo.vercel.app/">
3
+ <img alt="Logo" src="https://raw.githubusercontent.com/ckb-ecofund/ccc/master/assets/logo.svg" width="20%" />
4
+ </a>
5
+ </p>
6
+
7
+ <h1 align="center" style="font-size: 48px;">
8
+ CCC's support for NIP07
9
+ </h1>
10
+
11
+ <p align="center">
12
+ <a href="https://www.npmjs.com/package/@ckb-ccc/nip07"><img
13
+ alt="NPM Version" src="https://img.shields.io/npm/v/%40ckb-ccc%2Fnip07"
14
+ /></a>
15
+ <img alt="GitHub commit activity" src="https://img.shields.io/github/commit-activity/m/ckb-ecofund/ccc" />
16
+ <img alt="GitHub last commit" src="https://img.shields.io/github/last-commit/ckb-ecofund/ccc/master" />
17
+ <img alt="GitHub deployments" src="https://img.shields.io/github/deployments/ckb-ecofund/ccc/production" />
18
+ <a href="https://ckbccc-demo.vercel.app/"><img
19
+ alt="Demo" src="https://img.shields.io/website?url=https%3A%2F%2Fckbccc-demo.vercel.app%2F&label=Demo"
20
+ /></a>
21
+ </p>
22
+
23
+ <p align="center">
24
+ "Common Chains Connector" is where CCC begins.
25
+ <br />
26
+ CCC helps you to interoperate wallets from different chain ecosystems with CKB,
27
+ <br />
28
+ fully enabling CKB's cryptographic freedom power.
29
+ </p>
30
+
31
+ ## Preview
32
+
33
+ <p align="center">
34
+ <a href="https://ckbccc-demo.vercel.app/">
35
+ <img src="https://raw.githubusercontent.com/ckb-ecofund/ccc/master/assets/preview.png" width="30%" />
36
+ </a>
37
+ </p>
38
+
39
+ This project is still under active development, and we are looking forward to your feedback. [Try its demo now here](https://ckbccc-demo.vercel.app/).
40
+
41
+ <h3 align="center">
42
+ Read more about CCC on its <a href="https://github.com/ckb-ecofund/ccc">GitHub Repo</a>.
43
+ </h3>
@@ -0,0 +1,2 @@
1
+ export * as Nip07A from "./nip07.advanced";
2
+ //# sourceMappingURL=advanced.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"advanced.d.ts","sourceRoot":"","sources":["../src/advanced.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1 @@
1
+ export * as Nip07A from "./nip07.advanced";
@@ -0,0 +1,3 @@
1
+ export * from "./signer";
2
+ export * from "./signersFactory";
3
+ //# sourceMappingURL=barrel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"barrel.d.ts","sourceRoot":"","sources":["../src/barrel.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC"}
package/dist/barrel.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./signer";
2
+ export * from "./signersFactory";
@@ -0,0 +1,51 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,34 @@
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
+ }
@@ -0,0 +1,2 @@
1
+ export * as Nip07 from "./barrel";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,UAAU,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export * as Nip07 from "./barrel";
@@ -0,0 +1,6 @@
1
+ import { ccc } from "@ckb-ccc/core";
2
+ export interface Provider {
3
+ getPublicKey(): Promise<string>;
4
+ signEvent(event: ccc.NostrEvent): Promise<Required<ccc.NostrEvent>>;
5
+ }
6
+ //# sourceMappingURL=nip07.advanced.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nip07.advanced.d.ts","sourceRoot":"","sources":["../src/nip07.advanced.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEpC,MAAM,WAAW,QAAQ;IACvB,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAChC,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC,UAAU,GAAG,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC;CACrE"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,16 @@
1
+ import { ccc } from "@ckb-ccc/core";
2
+ import { ConnectionsRepo } from "./connectionsRepo";
3
+ import { Provider } from "./nip07.advanced";
4
+ 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
+ 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>;
15
+ }
16
+ //# sourceMappingURL=signer.d.ts.map
@@ -0,0 +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;IAKvF,MAAM,CAAC,aAAa,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,OAAO;IAI3C,aAAa,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAOnD,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;IAI9B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAKxB,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;CAItC"}
package/dist/signer.js ADDED
@@ -0,0 +1,36 @@
1
+ import { ccc } from "@ckb-ccc/core";
2
+ import { ConnectionsRepoLocalStorage, } from "./connectionsRepo";
3
+ export class Signer extends ccc.SignerNostr {
4
+ constructor(client, provider, connectionsRepo = new ConnectionsRepoLocalStorage()) {
5
+ super(client);
6
+ this.provider = provider;
7
+ this.connectionsRepo = connectionsRepo;
8
+ this.publicKey = undefined;
9
+ }
10
+ static isValidClient(client) {
11
+ return client.addressPrefix === "ckt";
12
+ }
13
+ async replaceClient(client) {
14
+ if (!Signer.isValidClient(client)) {
15
+ return false;
16
+ }
17
+ return super.replaceClient(client);
18
+ }
19
+ async getNostrPublicKey() {
20
+ if (!this.publicKey) {
21
+ throw new Error("Not connected");
22
+ }
23
+ return this.publicKey;
24
+ }
25
+ async signNostrEvent(event) {
26
+ return this.provider.signEvent(event);
27
+ }
28
+ async connect() {
29
+ this.publicKey = ccc.hexFrom(await this.provider.getPublicKey());
30
+ await this.connectionsRepo.set({ publicKey: this.publicKey });
31
+ }
32
+ async isConnected() {
33
+ this.publicKey = (await this.connectionsRepo.get())?.publicKey;
34
+ return this.publicKey !== undefined;
35
+ }
36
+ }
@@ -0,0 +1,4 @@
1
+ import { ccc } from "@ckb-ccc/core";
2
+ import { Signer } from "./signer";
3
+ export declare function getNip07Signer(client: ccc.Client): Signer | undefined;
4
+ //# sourceMappingURL=signersFactory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signersFactory.d.ts","sourceRoot":"","sources":["../src/signersFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEpC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,wBAAgB,cAAc,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,MAAM,GAAG,SAAS,CAQrE"}
@@ -0,0 +1,8 @@
1
+ import { Signer } from "./signer";
2
+ export function getNip07Signer(client) {
3
+ const windowRef = window;
4
+ if (typeof windowRef.nostr === "undefined" || !Signer.isValidClient(client)) {
5
+ return;
6
+ }
7
+ return new Signer(client, windowRef.nostr);
8
+ }
@@ -0,0 +1,2 @@
1
+ export * as Nip07A from "./nip07.advanced";
2
+ //# sourceMappingURL=advanced.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"advanced.d.ts","sourceRoot":"","sources":["../src/advanced.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,27 @@
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) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.Nip07A = void 0;
27
+ exports.Nip07A = __importStar(require("./nip07.advanced"));
@@ -0,0 +1,3 @@
1
+ export * from "./signer";
2
+ export * from "./signersFactory";
3
+ //# sourceMappingURL=barrel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"barrel.d.ts","sourceRoot":"","sources":["../src/barrel.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC"}
@@ -0,0 +1,18 @@
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
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./signer"), exports);
18
+ __exportStar(require("./signersFactory"), exports);
@@ -0,0 +1,51 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,38 @@
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;
@@ -0,0 +1,2 @@
1
+ export * as Nip07 from "./barrel";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,UAAU,CAAC"}
@@ -0,0 +1,27 @@
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) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.Nip07 = void 0;
27
+ exports.Nip07 = __importStar(require("./barrel"));
@@ -0,0 +1,6 @@
1
+ import { ccc } from "@ckb-ccc/core";
2
+ export interface Provider {
3
+ getPublicKey(): Promise<string>;
4
+ signEvent(event: ccc.NostrEvent): Promise<Required<ccc.NostrEvent>>;
5
+ }
6
+ //# sourceMappingURL=nip07.advanced.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nip07.advanced.d.ts","sourceRoot":"","sources":["../src/nip07.advanced.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEpC,MAAM,WAAW,QAAQ;IACvB,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAChC,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC,UAAU,GAAG,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC;CACrE"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,16 @@
1
+ import { ccc } from "@ckb-ccc/core";
2
+ import { ConnectionsRepo } from "./connectionsRepo";
3
+ import { Provider } from "./nip07.advanced";
4
+ 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
+ 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>;
15
+ }
16
+ //# sourceMappingURL=signer.d.ts.map
@@ -0,0 +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;IAKvF,MAAM,CAAC,aAAa,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,OAAO;IAI3C,aAAa,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAOnD,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;IAI9B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAKxB,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;CAItC"}
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Signer = void 0;
4
+ const core_1 = require("@ckb-ccc/core");
5
+ const connectionsRepo_1 = require("./connectionsRepo");
6
+ 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
+ static isValidClient(client) {
14
+ return client.addressPrefix === "ckt";
15
+ }
16
+ async replaceClient(client) {
17
+ if (!Signer.isValidClient(client)) {
18
+ return false;
19
+ }
20
+ return super.replaceClient(client);
21
+ }
22
+ async getNostrPublicKey() {
23
+ if (!this.publicKey) {
24
+ throw new Error("Not connected");
25
+ }
26
+ return this.publicKey;
27
+ }
28
+ async signNostrEvent(event) {
29
+ return this.provider.signEvent(event);
30
+ }
31
+ async connect() {
32
+ this.publicKey = core_1.ccc.hexFrom(await this.provider.getPublicKey());
33
+ await this.connectionsRepo.set({ publicKey: this.publicKey });
34
+ }
35
+ async isConnected() {
36
+ this.publicKey = (await this.connectionsRepo.get())?.publicKey;
37
+ return this.publicKey !== undefined;
38
+ }
39
+ }
40
+ exports.Signer = Signer;
@@ -0,0 +1,4 @@
1
+ import { ccc } from "@ckb-ccc/core";
2
+ import { Signer } from "./signer";
3
+ export declare function getNip07Signer(client: ccc.Client): Signer | undefined;
4
+ //# sourceMappingURL=signersFactory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signersFactory.d.ts","sourceRoot":"","sources":["../src/signersFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEpC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,wBAAgB,cAAc,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,MAAM,GAAG,SAAS,CAQrE"}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getNip07Signer = void 0;
4
+ const signer_1 = require("./signer");
5
+ function getNip07Signer(client) {
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);
11
+ }
12
+ exports.getNip07Signer = getNip07Signer;
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@ckb-ccc/nip07",
3
+ "version": "0.0.6-alpha.0",
4
+ "description": "Common Chains Connector's support for NIP07",
5
+ "author": "Hanssen0 <hanssen0@hanssen0.com>",
6
+ "license": "MIT",
7
+ "private": false,
8
+ "homepage": "https://github.com/ckb-ecofund/ccc",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git://github.com/ckb-ecofund/ccc.git"
12
+ },
13
+ "main": "dist.commonjs/index.js",
14
+ "module": "dist/index.js",
15
+ "exports": {
16
+ ".": {
17
+ "import": "./dist/index.js",
18
+ "default": "./dist.commonjs/index.js"
19
+ },
20
+ "./advanced": {
21
+ "import": "./dist/advanced.js",
22
+ "default": "./dist.commonjs/advanced.js"
23
+ }
24
+ },
25
+ "scripts": {
26
+ "build": "rimraf ./dist && rimraf ./dist.commonjs && tsc && tsc --project tsconfig.commonjs.json",
27
+ "lint": "eslint",
28
+ "format": "prettier --write . && eslint --fix"
29
+ },
30
+ "devDependencies": {
31
+ "@eslint/js": "^9.1.1",
32
+ "eslint": "^9.1.0",
33
+ "eslint-config-prettier": "^9.1.0",
34
+ "eslint-plugin-prettier": "^5.1.3",
35
+ "prettier": "^3.2.5",
36
+ "prettier-plugin-organize-imports": "^3.2.4",
37
+ "rimraf": "^5.0.5",
38
+ "typescript": "^5.4.5",
39
+ "typescript-eslint": "^7.7.0"
40
+ },
41
+ "publishConfig": {
42
+ "access": "public"
43
+ },
44
+ "dependencies": {
45
+ "@ckb-ccc/core": "0.0.6-alpha.0"
46
+ },
47
+ "gitHead": "2cbb4f450ed88e773a353a13ad006dbe6208f67f"
48
+ }
@@ -0,0 +1 @@
1
+ export * as Nip07A from "./nip07.advanced";
package/src/barrel.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./signer";
2
+ export * from "./signersFactory";
@@ -0,0 +1,65 @@
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
+ }
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * as Nip07 from "./barrel";
@@ -0,0 +1,6 @@
1
+ import { ccc } from "@ckb-ccc/core";
2
+
3
+ export interface Provider {
4
+ getPublicKey(): Promise<string>;
5
+ signEvent(event: ccc.NostrEvent): Promise<Required<ccc.NostrEvent>>;
6
+ }
package/src/signer.ts ADDED
@@ -0,0 +1,53 @@
1
+ import { ccc } from "@ckb-ccc/core";
2
+ import {
3
+ ConnectionsRepo,
4
+ ConnectionsRepoLocalStorage,
5
+ } from "./connectionsRepo";
6
+ import { Provider } from "./nip07.advanced";
7
+
8
+ export class Signer extends ccc.SignerNostr {
9
+ private publicKey: ccc.Hex | undefined = undefined;
10
+
11
+ constructor(
12
+ client: ccc.Client,
13
+ public readonly provider: Provider,
14
+ private readonly connectionsRepo: ConnectionsRepo = new ConnectionsRepoLocalStorage(),
15
+ ) {
16
+ super(client);
17
+ }
18
+
19
+ static isValidClient(client: ccc.Client): boolean {
20
+ return client.addressPrefix === "ckt";
21
+ }
22
+
23
+ async replaceClient(client: ccc.Client): Promise<boolean> {
24
+ if (!Signer.isValidClient(client)) {
25
+ return false;
26
+ }
27
+ return super.replaceClient(client);
28
+ }
29
+
30
+ async getNostrPublicKey(): Promise<ccc.Hex> {
31
+ if (!this.publicKey) {
32
+ throw new Error("Not connected");
33
+ }
34
+
35
+ return this.publicKey;
36
+ }
37
+
38
+ async signNostrEvent(
39
+ event: ccc.NostrEvent,
40
+ ): Promise<Required<ccc.NostrEvent>> {
41
+ return this.provider.signEvent(event);
42
+ }
43
+
44
+ async connect(): Promise<void> {
45
+ this.publicKey = ccc.hexFrom(await this.provider.getPublicKey());
46
+ await this.connectionsRepo.set({ publicKey: this.publicKey });
47
+ }
48
+
49
+ async isConnected(): Promise<boolean> {
50
+ this.publicKey = (await this.connectionsRepo.get())?.publicKey;
51
+ return this.publicKey !== undefined;
52
+ }
53
+ }
@@ -0,0 +1,13 @@
1
+ import { ccc } from "@ckb-ccc/core";
2
+ import { Provider } from "./nip07.advanced";
3
+ import { Signer } from "./signer";
4
+
5
+ export function getNip07Signer(client: ccc.Client): Signer | undefined {
6
+ const windowRef = window as { nostr?: Provider };
7
+
8
+ if (typeof windowRef.nostr === "undefined" || !Signer.isValidClient(client)) {
9
+ return;
10
+ }
11
+
12
+ return new Signer(client, windowRef.nostr);
13
+ }