@ckb-ccc/joy-id 0.0.8-alpha.3 → 0.0.9-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 (53) hide show
  1. package/dist/btc/index.d.ts +16 -12
  2. package/dist/btc/index.d.ts.map +1 -1
  3. package/dist/btc/index.js +38 -13
  4. package/dist/ckb/index.d.ts +3 -1
  5. package/dist/ckb/index.d.ts.map +1 -1
  6. package/dist/ckb/index.js +14 -2
  7. package/dist/connectionsStorage/index.d.ts +1 -1
  8. package/dist/connectionsStorage/index.d.ts.map +1 -1
  9. package/dist/connectionsStorage/index.js +5 -5
  10. package/dist/evm/index.d.ts +9 -7
  11. package/dist/evm/index.d.ts.map +1 -1
  12. package/dist/evm/index.js +22 -8
  13. package/dist/nostr/index.d.ts +20 -8
  14. package/dist/nostr/index.d.ts.map +1 -1
  15. package/dist/nostr/index.js +42 -18
  16. package/dist/signerFactory/index.d.ts +1 -1
  17. package/dist/signerFactory/index.d.ts.map +1 -1
  18. package/dist/signerFactory/index.js +4 -4
  19. package/dist.commonjs/advanced.d.ts +1 -1
  20. package/dist.commonjs/advanced.js +19 -40
  21. package/dist.commonjs/advancedBarrel.d.ts +1 -1
  22. package/dist.commonjs/advancedBarrel.js +14 -30
  23. package/dist.commonjs/barrel.d.ts +1 -1
  24. package/dist.commonjs/barrel.js +14 -30
  25. package/dist.commonjs/btc/index.d.ts +60 -63
  26. package/dist.commonjs/btc/index.d.ts.map +1 -1
  27. package/dist.commonjs/btc/index.js +139 -140
  28. package/dist.commonjs/ckb/index.d.ts +116 -121
  29. package/dist.commonjs/ckb/index.d.ts.map +1 -1
  30. package/dist.commonjs/ckb/index.js +262 -307
  31. package/dist.commonjs/common/index.d.ts +21 -34
  32. package/dist.commonjs/common/index.js +45 -50
  33. package/dist.commonjs/connectionsStorage/index.d.ts +44 -53
  34. package/dist.commonjs/connectionsStorage/index.d.ts.map +1 -1
  35. package/dist.commonjs/connectionsStorage/index.js +47 -50
  36. package/dist.commonjs/evm/index.d.ts +63 -67
  37. package/dist.commonjs/evm/index.d.ts.map +1 -1
  38. package/dist.commonjs/evm/index.js +127 -135
  39. package/dist.commonjs/index.d.ts +1 -1
  40. package/dist.commonjs/index.js +19 -40
  41. package/dist.commonjs/nostr/index.d.ts +54 -48
  42. package/dist.commonjs/nostr/index.d.ts.map +1 -1
  43. package/dist.commonjs/nostr/index.js +113 -108
  44. package/dist.commonjs/signerFactory/index.d.ts +2 -6
  45. package/dist.commonjs/signerFactory/index.d.ts.map +1 -1
  46. package/dist.commonjs/signerFactory/index.js +32 -43
  47. package/package.json +3 -3
  48. package/src/btc/index.ts +53 -15
  49. package/src/ckb/index.ts +17 -2
  50. package/src/connectionsStorage/index.ts +10 -5
  51. package/src/evm/index.ts +25 -7
  52. package/src/nostr/index.ts +49 -21
  53. package/src/signerFactory/index.ts +10 -3
@@ -11,142 +11,134 @@ const connectionsStorage_1 = require("../connectionsStorage");
11
11
  * @extends {ccc.SignerEvm}
12
12
  */
13
13
  class EvmSigner extends core_1.ccc.SignerEvm {
14
- /**
15
- * Ensures that the signer is connected and returns the connection.
16
- * @private
17
- * @throws Will throw an error if not connected.
18
- * @returns {Connection} The current connection.
19
- */
20
- assertConnection() {
21
- if (!this.isConnected() || !this.connection) {
22
- throw new Error("Not connected");
14
+ /**
15
+ * Ensures that the signer is connected and returns the connection.
16
+ * @private
17
+ * @throws Will throw an error if not connected.
18
+ * @returns {Connection} The current connection.
19
+ */
20
+ assertConnection() {
21
+ if (!this.isConnected() || !this.connection) {
22
+ throw new Error("Not connected");
23
+ }
24
+ return this.connection;
23
25
  }
24
- return this.connection;
25
- }
26
- /**
27
- * Creates an instance of EvmSigner.
28
- * @param {ccc.Client} client - The client instance.
29
- * @param {string} name - The name of the signer.
30
- * @param {string} icon - The icon URL of the signer.
31
- * @param {string} [appUri="https://app.joy.id"] - The application URI.
32
- * @param {ConnectionsRepo} [connectionsRepo=new ConnectionsRepoLocalStorage()] - The connections repository.
33
- */
34
- constructor(
35
- client,
36
- name,
37
- icon,
38
- appUri = "https://app.joy.id",
39
- connectionsRepo = new connectionsStorage_1.ConnectionsRepoLocalStorage(),
40
- ) {
41
- super(client);
42
- this.name = name;
43
- this.icon = icon;
44
- this.appUri = appUri;
45
- this.connectionsRepo = connectionsRepo;
46
- }
47
- /**
48
- * Gets the configuration for JoyID.
49
- * @private
50
- * @returns {object} The configuration object.
51
- */
52
- getConfig() {
53
- return {
54
- redirectURL: location.href,
55
- joyidAppURL: this.appUri,
56
- requestNetwork: `ethereum`,
57
- name: this.name,
58
- logo: this.icon,
59
- };
60
- }
61
- /**
62
- * Gets the EVM account address.
63
- * @returns {Promise<string>} A promise that resolves to the EVM account address.
64
- */
65
- async getEvmAccount() {
66
- return this.assertConnection().address;
67
- }
68
- /**
69
- * Connects to the provider by requesting authentication.
70
- * @returns {Promise<void>} A promise that resolves when the connection is established.
71
- */
72
- async connect() {
73
- const config = this.getConfig();
74
- const res = await (0, common_2.createPopup)(
75
- (0, common_1.buildJoyIDURL)(config, "popup", "/auth"),
76
- {
77
- ...config,
78
- type: common_1.DappRequestType.Auth,
79
- },
80
- );
81
- this.connection = {
82
- address: res.ethAddress,
83
- publicKey: core_1.ccc.hexFrom(res.pubkey),
84
- keyType: res.keyType,
85
- };
86
- await this.saveConnection();
87
- }
88
- /**
89
- * Checks if the signer is connected.
90
- * @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
91
- */
92
- async isConnected() {
93
- if (this.connection) {
94
- return true;
26
+ /**
27
+ * Creates an instance of EvmSigner.
28
+ * @param client - The client instance.
29
+ * @param name - The name of the signer.
30
+ * @param icon - The icon URL of the signer.
31
+ * @param appUri - The application URI.
32
+ * @param connectionsRepo - The connections repository.
33
+ */
34
+ constructor(client, name, icon, _appUri, connectionsRepo = new connectionsStorage_1.ConnectionsRepoLocalStorage()) {
35
+ super(client);
36
+ this.name = name;
37
+ this.icon = icon;
38
+ this._appUri = _appUri;
39
+ this.connectionsRepo = connectionsRepo;
40
+ }
41
+ async replaceClient(client) {
42
+ if (!(await super.replaceClient(client))) {
43
+ return false;
44
+ }
45
+ this.connection = undefined;
46
+ return true;
47
+ }
48
+ /**
49
+ * Gets the configuration for JoyID.
50
+ * @private
51
+ * @returns {object} The configuration object.
52
+ */
53
+ getConfig() {
54
+ return {
55
+ redirectURL: location.href,
56
+ joyidAppURL: this._appUri ?? this.client.addressPrefix === "ckb"
57
+ ? "https://app.joy.id"
58
+ : "https://testnet.joyid.dev",
59
+ requestNetwork: `ethereum`,
60
+ name: this.name,
61
+ logo: this.icon,
62
+ };
63
+ }
64
+ /**
65
+ * Gets the EVM account address.
66
+ * @returns {Promise<string>} A promise that resolves to the EVM account address.
67
+ */
68
+ async getEvmAccount() {
69
+ return this.assertConnection().address;
70
+ }
71
+ /**
72
+ * Connects to the provider by requesting authentication.
73
+ * @returns {Promise<void>} A promise that resolves when the connection is established.
74
+ */
75
+ async connect() {
76
+ const config = this.getConfig();
77
+ const res = await (0, common_2.createPopup)((0, common_1.buildJoyIDURL)(config, "popup", "/auth"), {
78
+ ...config,
79
+ type: common_1.DappRequestType.Auth,
80
+ });
81
+ this.connection = {
82
+ address: res.ethAddress,
83
+ publicKey: core_1.ccc.hexFrom(res.pubkey),
84
+ keyType: res.keyType,
85
+ };
86
+ await this.saveConnection();
87
+ }
88
+ async disconnect() {
89
+ await super.disconnect();
90
+ this.connection = undefined;
91
+ await this.saveConnection();
92
+ }
93
+ /**
94
+ * Checks if the signer is connected.
95
+ * @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
96
+ */
97
+ async isConnected() {
98
+ if (this.connection) {
99
+ return true;
100
+ }
101
+ await this.restoreConnection();
102
+ return this.connection !== undefined;
103
+ }
104
+ /**
105
+ * Signs a raw message with the EVM account.
106
+ * @param {string | ccc.BytesLike} message - The message to sign.
107
+ * @returns {Promise<ccc.Hex>} A promise that resolves to the signed message.
108
+ */
109
+ async signMessageRaw(message) {
110
+ const { address } = this.assertConnection();
111
+ const challenge = typeof message === "string" ? message : core_1.ccc.hexFrom(message).slice(2);
112
+ const config = this.getConfig();
113
+ const { signature } = await (0, common_2.createPopup)((0, common_1.buildJoyIDURL)({
114
+ ...config,
115
+ challenge,
116
+ isData: typeof message !== "string",
117
+ address,
118
+ }, "popup", "/sign-message"), { ...config, type: common_1.DappRequestType.SignMessage });
119
+ return core_1.ccc.hexFrom(signature);
120
+ }
121
+ /**
122
+ * Saves the current connection.
123
+ * @private
124
+ * @returns {Promise<void>}
125
+ */
126
+ async saveConnection() {
127
+ return this.connectionsRepo.set({
128
+ uri: this.getConfig().joyidAppURL,
129
+ addressType: "ethereum",
130
+ }, this.connection);
131
+ }
132
+ /**
133
+ * Restores the previous connection.
134
+ * @private
135
+ * @returns {Promise<void>}
136
+ */
137
+ async restoreConnection() {
138
+ this.connection = await this.connectionsRepo.get({
139
+ uri: this.getConfig().joyidAppURL,
140
+ addressType: "ethereum",
141
+ });
95
142
  }
96
- await this.restoreConnection();
97
- return this.connection !== undefined;
98
- }
99
- /**
100
- * Signs a raw message with the EVM account.
101
- * @param {string | ccc.BytesLike} message - The message to sign.
102
- * @returns {Promise<ccc.Hex>} A promise that resolves to the signed message.
103
- */
104
- async signMessageRaw(message) {
105
- const { address } = this.assertConnection();
106
- const challenge =
107
- typeof message === "string"
108
- ? message
109
- : core_1.ccc.hexFrom(message).slice(2);
110
- const config = this.getConfig();
111
- const { signature } = await (0, common_2.createPopup)(
112
- (0, common_1.buildJoyIDURL)(
113
- {
114
- ...config,
115
- challenge,
116
- isData: typeof message !== "string",
117
- address,
118
- },
119
- "popup",
120
- "/sign-message",
121
- ),
122
- { ...config, type: common_1.DappRequestType.SignMessage },
123
- );
124
- return core_1.ccc.hexFrom(signature);
125
- }
126
- /**
127
- * Saves the current connection.
128
- * @private
129
- * @returns {Promise<void>}
130
- */
131
- async saveConnection() {
132
- return this.connectionsRepo.set(
133
- {
134
- uri: this.getConfig().joyidAppURL,
135
- addressType: "ethereum",
136
- },
137
- this.connection,
138
- );
139
- }
140
- /**
141
- * Restores the previous connection.
142
- * @private
143
- * @returns {Promise<void>}
144
- */
145
- async restoreConnection() {
146
- this.connection = await this.connectionsRepo.get({
147
- uri: this.getConfig().joyidAppURL,
148
- addressType: "ethereum",
149
- });
150
- }
151
143
  }
152
144
  exports.EvmSigner = EvmSigner;
@@ -1,2 +1,2 @@
1
1
  export * as JoyId 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.JoyId = void 0;
48
27
  exports.JoyId = __importStar(require("./barrel"));
@@ -6,52 +6,58 @@ import { ConnectionsRepo } from "../connectionsStorage";
6
6
  * @extends {ccc.SignerNostr}
7
7
  */
8
8
  export declare class NostrSigner extends ccc.SignerNostr {
9
- private readonly name;
10
- private readonly icon;
11
- private readonly appUri;
12
- private readonly connectionsRepo;
13
- private connection?;
14
- /**
15
- * Ensures that the signer is connected and returns the connection.
16
- * @private
17
- * @throws Will throw an error if not connected.
18
- * @returns {Connection} The current connection.
19
- */
20
- private assertConnection;
21
- /**
22
- * Creates an instance of NostrSigner.
23
- * @param {ccc.Client} client - The client instance.
24
- * @param {string} name - The name of the signer.
25
- * @param {string} icon - The icon URL of the signer.
26
- * @param {string} [appUri="https://app.joy.id"] - The application URI.
27
- * @param {ConnectionsRepo} [connectionsRepo=new ConnectionsRepoLocalStorage()] - The connections repository.
28
- */
29
- constructor(
30
- client: ccc.Client,
31
- name: string,
32
- icon: string,
33
- appUri?: string,
34
- connectionsRepo?: ConnectionsRepo,
35
- );
36
- static isValidClient(client: ccc.Client): boolean;
37
- replaceClient(client: ccc.Client): Promise<boolean>;
38
- /**
39
- * Gets the configuration for JoyID.
40
- * @private
41
- * @returns {object} The configuration object.
42
- */
43
- private getConfig;
44
- /**
45
- * Connects to the provider by requesting authentication.
46
- * @returns {Promise<void>} A promise that resolves when the connection is established.
47
- */
48
- connect(): Promise<void>;
49
- /**
50
- * Checks if the signer is connected.
51
- * @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
52
- */
53
- isConnected(): Promise<boolean>;
54
- getNostrPublicKey(): Promise<ccc.Hex>;
55
- signNostrEvent(event: ccc.NostrEvent): Promise<Required<ccc.NostrEvent>>;
9
+ private readonly name;
10
+ private readonly icon;
11
+ private readonly _appUri?;
12
+ private readonly connectionsRepo;
13
+ private connection?;
14
+ /**
15
+ * Ensures that the signer is connected and returns the connection.
16
+ * @private
17
+ * @throws Will throw an error if not connected.
18
+ * @returns {Connection} The current connection.
19
+ */
20
+ private assertConnection;
21
+ /**
22
+ * Creates an instance of NostrSigner.
23
+ * @param client - The client instance.
24
+ * @param name - The name of the signer.
25
+ * @param icon - The icon URL of the signer.
26
+ * @param appUri - The application URI.
27
+ * @param connectionsRepo - The connections repository.
28
+ */
29
+ constructor(client: ccc.Client, name: string, icon: string, _appUri?: string | undefined, connectionsRepo?: ConnectionsRepo);
30
+ replaceClient(client: ccc.Client): Promise<boolean>;
31
+ /**
32
+ * Gets the configuration for JoyID.
33
+ * @private
34
+ * @returns {object} The configuration object.
35
+ */
36
+ private getConfig;
37
+ /**
38
+ * Connects to the provider by requesting authentication.
39
+ * @returns {Promise<void>} A promise that resolves when the connection is established.
40
+ */
41
+ connect(): Promise<void>;
42
+ disconnect(): Promise<void>;
43
+ /**
44
+ * Checks if the signer is connected.
45
+ * @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
46
+ */
47
+ isConnected(): Promise<boolean>;
48
+ getNostrPublicKey(): Promise<ccc.Hex>;
49
+ signNostrEvent(event: ccc.NostrEvent): Promise<Required<ccc.NostrEvent>>;
50
+ /**
51
+ * Saves the current connection.
52
+ * @private
53
+ * @returns {Promise<void>}
54
+ */
55
+ private saveConnection;
56
+ /**
57
+ * Restores the previous connection.
58
+ * @private
59
+ * @returns {Promise<void>}
60
+ */
61
+ private restoreConnection;
56
62
  }
57
- //# sourceMappingURL=index.d.ts.map
63
+ //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/nostr/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAGpC,OAAO,EAEL,eAAe,EAEhB,MAAM,uBAAuB,CAAC;AAE/B;;;;GAIG;AACH,qBAAa,WAAY,SAAQ,GAAG,CAAC,WAAW;IA2B5C,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,eAAe;IA7BlC,OAAO,CAAC,UAAU,CAAC,CAAa;IAEhC;;;;;OAKG;IACH,OAAO,CAAC,gBAAgB;IAQxB;;;;;;;OAOG;gBAED,MAAM,EAAE,GAAG,CAAC,MAAM,EACD,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,MAAM,SAAuB,EAC7B,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;IAOzD;;;;OAIG;IACH,OAAO,CAAC,SAAS;IAUjB;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAkB9B;;;OAGG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAY/B,iBAAiB,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;IAIrC,cAAc,CAClB,KAAK,EAAE,GAAG,CAAC,UAAU,GACpB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;CAWrC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/nostr/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAGpC,OAAO,EAEL,eAAe,EAEhB,MAAM,uBAAuB,CAAC;AAE/B;;;;GAIG;AACH,qBAAa,WAAY,SAAQ,GAAG,CAAC,WAAW;IA2B5C,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC;IACzB,OAAO,CAAC,QAAQ,CAAC,eAAe;IA7BlC,OAAO,CAAC,UAAU,CAAC,CAAa;IAEhC;;;;;OAKG;IACH,OAAO,CAAC,gBAAgB;IAQxB;;;;;;;OAOG;gBAED,MAAM,EAAE,GAAG,CAAC,MAAM,EACD,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,oBAAQ,EAChB,eAAe,GAAE,eAAmD;IAKjF,aAAa,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAQzD;;;;OAIG;IACH,OAAO,CAAC,SAAS;IAajB;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAexB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAOjC;;;OAGG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAS/B,iBAAiB,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;IAIrC,cAAc,CAClB,KAAK,EAAE,GAAG,CAAC,UAAU,GACpB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAYpC;;;;OAIG;YACW,cAAc;IAU5B;;;;OAIG;YACW,iBAAiB;CAMhC"}