@ckb-ccc/joy-id 0.0.9-alpha.2 → 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.
Files changed (43) hide show
  1. package/dist/btc/index.d.ts +0 -1
  2. package/dist/btc/index.d.ts.map +1 -1
  3. package/dist/btc/index.js +0 -7
  4. package/dist/ckb/index.d.ts +0 -1
  5. package/dist/ckb/index.d.ts.map +1 -1
  6. package/dist/ckb/index.js +0 -7
  7. package/dist/evm/index.d.ts +2 -3
  8. package/dist/evm/index.d.ts.map +1 -1
  9. package/dist/evm/index.js +1 -8
  10. package/dist/nostr/index.d.ts +0 -1
  11. package/dist/nostr/index.d.ts.map +1 -1
  12. package/dist/nostr/index.js +0 -7
  13. package/dist.commonjs/advanced.d.ts +1 -1
  14. package/dist.commonjs/advanced.js +40 -19
  15. package/dist.commonjs/advancedBarrel.d.ts +1 -1
  16. package/dist.commonjs/advancedBarrel.js +30 -14
  17. package/dist.commonjs/barrel.d.ts +1 -1
  18. package/dist.commonjs/barrel.js +30 -14
  19. package/dist.commonjs/btc/index.d.ts +67 -60
  20. package/dist.commonjs/btc/index.d.ts.map +1 -1
  21. package/dist.commonjs/btc/index.js +176 -148
  22. package/dist.commonjs/ckb/index.d.ts +122 -116
  23. package/dist.commonjs/ckb/index.d.ts.map +1 -1
  24. package/dist.commonjs/ckb/index.js +312 -262
  25. package/dist.commonjs/common/index.d.ts +34 -21
  26. package/dist.commonjs/common/index.js +50 -45
  27. package/dist.commonjs/connectionsStorage/index.d.ts +53 -44
  28. package/dist.commonjs/connectionsStorage/index.js +49 -44
  29. package/dist.commonjs/evm/index.d.ts +68 -63
  30. package/dist.commonjs/evm/index.d.ts.map +1 -1
  31. package/dist.commonjs/evm/index.js +143 -127
  32. package/dist.commonjs/index.d.ts +1 -1
  33. package/dist.commonjs/index.js +40 -19
  34. package/dist.commonjs/nostr/index.d.ts +59 -54
  35. package/dist.commonjs/nostr/index.d.ts.map +1 -1
  36. package/dist.commonjs/nostr/index.js +127 -114
  37. package/dist.commonjs/signerFactory/index.d.ts +7 -2
  38. package/dist.commonjs/signerFactory/index.js +54 -31
  39. package/package.json +3 -3
  40. package/src/btc/index.ts +0 -8
  41. package/src/ckb/index.ts +0 -8
  42. package/src/evm/index.ts +3 -11
  43. package/src/nostr/index.ts +0 -8
@@ -11,134 +11,150 @@ 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");
23
- }
24
- return this.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
+ assertConnection() {
21
+ if (!this.isConnected() || !this.connection) {
22
+ throw new Error("Not connected");
25
23
  }
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
- });
24
+ return this.connection;
25
+ }
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(
35
+ client,
36
+ name,
37
+ icon,
38
+ _appUri,
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:
56
+ 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 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)(
78
+ (0, common_1.buildJoyIDURL)(config, "popup", "/auth"),
79
+ {
80
+ ...config,
81
+ type: common_1.DappRequestType.Auth,
82
+ },
83
+ );
84
+ this.connection = {
85
+ address: res.ethAddress,
86
+ publicKey: core_1.ccc.hexFrom(res.pubkey),
87
+ keyType: res.keyType,
88
+ };
89
+ await this.saveConnection();
90
+ }
91
+ async disconnect() {
92
+ await super.disconnect();
93
+ this.connection = undefined;
94
+ await this.saveConnection();
95
+ }
96
+ /**
97
+ * Checks if the signer is connected.
98
+ * @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
99
+ */
100
+ async isConnected() {
101
+ if (this.connection) {
102
+ return true;
142
103
  }
104
+ await this.restoreConnection();
105
+ return this.connection !== undefined;
106
+ }
107
+ /**
108
+ * Signs a raw message with the EVM account.
109
+ * @param {string | ccc.BytesLike} message - The message to sign.
110
+ * @returns {Promise<ccc.Hex>} A promise that resolves to the signed message.
111
+ */
112
+ async signMessageRaw(message) {
113
+ const { address } = this.assertConnection();
114
+ const challenge =
115
+ typeof message === "string"
116
+ ? message
117
+ : core_1.ccc.hexFrom(message).slice(2);
118
+ const config = this.getConfig();
119
+ const { signature } = await (0, common_2.createPopup)(
120
+ (0, common_1.buildJoyIDURL)(
121
+ {
122
+ ...config,
123
+ challenge,
124
+ isData: typeof message !== "string",
125
+ address,
126
+ },
127
+ "popup",
128
+ "/sign-message",
129
+ ),
130
+ { ...config, type: common_1.DappRequestType.SignMessage },
131
+ );
132
+ return core_1.ccc.hexFrom(signature);
133
+ }
134
+ /**
135
+ * Saves the current connection.
136
+ * @private
137
+ * @returns {Promise<void>}
138
+ */
139
+ async saveConnection() {
140
+ return this.connectionsRepo.set(
141
+ {
142
+ uri: this.getConfig().joyidAppURL,
143
+ addressType: "ethereum",
144
+ },
145
+ this.connection,
146
+ );
147
+ }
148
+ /**
149
+ * Restores the previous connection.
150
+ * @private
151
+ * @returns {Promise<void>}
152
+ */
153
+ async restoreConnection() {
154
+ this.connection = await this.connectionsRepo.get({
155
+ uri: this.getConfig().joyidAppURL,
156
+ addressType: "ethereum",
157
+ });
158
+ }
143
159
  }
144
160
  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,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.JoyId = void 0;
27
48
  exports.JoyId = __importStar(require("./barrel"));
@@ -6,58 +6,63 @@ 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 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;
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(
30
+ client: ccc.Client,
31
+ name: string,
32
+ icon: string,
33
+ _appUri?: string | undefined,
34
+ connectionsRepo?: ConnectionsRepo,
35
+ );
36
+ /**
37
+ * Gets the configuration for JoyID.
38
+ * @private
39
+ * @returns {object} The configuration object.
40
+ */
41
+ private getConfig;
42
+ /**
43
+ * Connects to the provider by requesting authentication.
44
+ * @returns {Promise<void>} A promise that resolves when the connection is established.
45
+ */
46
+ connect(): Promise<void>;
47
+ disconnect(): Promise<void>;
48
+ /**
49
+ * Checks if the signer is connected.
50
+ * @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
51
+ */
52
+ isConnected(): Promise<boolean>;
53
+ getNostrPublicKey(): Promise<ccc.Hex>;
54
+ signNostrEvent(event: ccc.NostrEvent): Promise<Required<ccc.NostrEvent>>;
55
+ /**
56
+ * Saves the current connection.
57
+ * @private
58
+ * @returns {Promise<void>}
59
+ */
60
+ private saveConnection;
61
+ /**
62
+ * Restores the previous connection.
63
+ * @private
64
+ * @returns {Promise<void>}
65
+ */
66
+ private restoreConnection;
62
67
  }
63
- //# sourceMappingURL=index.d.ts.map
68
+ //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/nostr/index.ts"],"names":[],"mappings":"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