@ckb-ccc/ccc 0.0.12-alpha.7 → 0.0.13-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 (46) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/README.md +10 -7
  3. package/dist/assets/rei.svg.d.ts +2 -0
  4. package/dist/assets/rei.svg.d.ts.map +1 -0
  5. package/dist/assets/rei.svg.js +2 -0
  6. package/dist/barrel.d.ts +1 -0
  7. package/dist/barrel.d.ts.map +1 -1
  8. package/dist/barrel.js +1 -0
  9. package/dist/signersController.d.ts +24 -6
  10. package/dist/signersController.d.ts.map +1 -1
  11. package/dist/signersController.js +53 -35
  12. package/dist.commonjs/advanced.d.ts +1 -1
  13. package/dist.commonjs/advanced.js +22 -47
  14. package/dist.commonjs/advancedBarrel.d.ts +1 -1
  15. package/dist.commonjs/advancedBarrel.js +14 -30
  16. package/dist.commonjs/assets/eth.svg.d.ts +1 -1
  17. package/dist.commonjs/assets/eth.svg.js +1 -3
  18. package/dist.commonjs/assets/joy-id.svg.d.ts +1 -1
  19. package/dist.commonjs/assets/joy-id.svg.js +1 -3
  20. package/dist.commonjs/assets/metamask.svg.d.ts +1 -1
  21. package/dist.commonjs/assets/metamask.svg.js +1 -3
  22. package/dist.commonjs/assets/nostr.svg.d.ts +1 -1
  23. package/dist.commonjs/assets/nostr.svg.js +1 -3
  24. package/dist.commonjs/assets/okx.svg.d.ts +1 -1
  25. package/dist.commonjs/assets/okx.svg.js +1 -3
  26. package/dist.commonjs/assets/rei.svg.d.ts +2 -0
  27. package/dist.commonjs/assets/rei.svg.d.ts.map +1 -0
  28. package/dist.commonjs/assets/rei.svg.js +5 -0
  29. package/dist.commonjs/assets/uni-sat.svg.d.ts +1 -1
  30. package/dist.commonjs/assets/uni-sat.svg.js +1 -3
  31. package/dist.commonjs/assets/utils.d.ts +1 -1
  32. package/dist.commonjs/assets/utils.js +1 -1
  33. package/dist.commonjs/assets/utxo-global.svg.d.ts +1 -1
  34. package/dist.commonjs/barrel.d.ts +2 -1
  35. package/dist.commonjs/barrel.d.ts.map +1 -1
  36. package/dist.commonjs/barrel.js +15 -30
  37. package/dist.commonjs/index.d.ts +1 -1
  38. package/dist.commonjs/index.js +22 -47
  39. package/dist.commonjs/signersController.d.ts +41 -30
  40. package/dist.commonjs/signersController.d.ts.map +1 -1
  41. package/dist.commonjs/signersController.js +100 -207
  42. package/package.json +9 -8
  43. package/src/assets/rei.svg.ts +5 -0
  44. package/src/barrel.ts +1 -0
  45. package/src/signersController.ts +85 -113
  46. package/typedoc.json +6 -0
@@ -3,6 +3,7 @@ import { Eip6963 } from "@ckb-ccc/eip6963";
3
3
  import { JoyId } from "@ckb-ccc/joy-id";
4
4
  import { Nip07 } from "@ckb-ccc/nip07";
5
5
  import { Okx } from "@ckb-ccc/okx";
6
+ import { Rei } from "@ckb-ccc/rei";
6
7
  import { UniSat } from "@ckb-ccc/uni-sat";
7
8
  import { UtxoGlobal } from "@ckb-ccc/utxo-global";
8
9
  import { ETH_SVG } from "./assets/eth.svg.js";
@@ -10,13 +11,32 @@ import { JOY_ID_SVG } from "./assets/joy-id.svg.js";
10
11
  import { METAMASK_SVG } from "./assets/metamask.svg.js";
11
12
  import { NOSTR_SVG } from "./assets/nostr.svg.js";
12
13
  import { OKX_SVG } from "./assets/okx.svg.js";
14
+ import { REI_SVG } from "./assets/rei.svg.js";
13
15
  import { UNI_SAT_SVG } from "./assets/uni-sat.svg.js";
14
16
  import { UTXO_GLOBAL_SVG } from "./assets/utxo-global.svg.js";
15
17
 
18
+ /**
19
+ * @public
20
+ */
16
21
  export type WalletWithSigners = ccc.Wallet & {
17
22
  signers: ccc.SignerInfo[];
18
23
  };
19
24
 
25
+ /**
26
+ * @public
27
+ */
28
+ export interface SignersControllerRefreshContext {
29
+ client: ccc.Client;
30
+ appName: string;
31
+ appIcon: string;
32
+ preferredNetworks: ccc.NetworkPreference[];
33
+ onUpdate: (wallets: WalletWithSigners[]) => void;
34
+ wallets: WalletWithSigners[];
35
+ }
36
+
37
+ /**
38
+ * @public
39
+ */
20
40
  export class SignersController {
21
41
  private resetListeners: (() => void)[] = [];
22
42
 
@@ -27,11 +47,11 @@ export class SignersController {
27
47
  name?: string;
28
48
  icon?: string;
29
49
  }) {
30
- const name =
50
+ const appName =
31
51
  configs?.name ??
32
52
  (document.querySelector("head title") as HTMLTitleElement | null)?.text ??
33
53
  "Unknown";
34
- const icon =
54
+ const appIcon =
35
55
  configs?.icon ??
36
56
  (document.querySelector('link[rel="icon"]') as HTMLLinkElement | null)
37
57
  ?.href ??
@@ -52,8 +72,8 @@ export class SignersController {
52
72
  ];
53
73
 
54
74
  return {
55
- name,
56
- icon,
75
+ appName,
76
+ appIcon,
57
77
  preferredNetworks,
58
78
  };
59
79
  }
@@ -67,10 +87,6 @@ export class SignersController {
67
87
  client: ccc.Client,
68
88
  onUpdate: (wallets: WalletWithSigners[]) => void,
69
89
  configs?: {
70
- signerFilter?: (
71
- signerInfo: ccc.SignerInfo,
72
- wallet: ccc.Wallet,
73
- ) => Promise<boolean>;
74
90
  preferredNetworks?: ccc.NetworkPreference[];
75
91
  name?: string;
76
92
  icon?: string;
@@ -78,202 +94,158 @@ export class SignersController {
78
94
  ) {
79
95
  this.disconnect();
80
96
 
81
- const wallets: WalletWithSigners[] = [];
97
+ const { appName, appIcon, preferredNetworks } = this.getConfig(configs);
98
+
99
+ const context: SignersControllerRefreshContext = {
100
+ client,
101
+ appName,
102
+ appIcon,
103
+ preferredNetworks,
104
+ onUpdate,
105
+ wallets: [],
106
+ };
82
107
 
83
- const { name, icon, preferredNetworks } = this.getConfig(configs);
108
+ await this.addRealSigners(context);
109
+ await this.addDummySigners(context);
110
+ }
84
111
 
112
+ async addRealSigners(context: SignersControllerRefreshContext) {
113
+ const { appName, appIcon, client, preferredNetworks } = context;
85
114
  await this.addSigners(
86
- wallets,
87
115
  "UTXO Global Wallet",
88
116
  UTXO_GLOBAL_SVG,
89
117
  UtxoGlobal.getUtxoGlobalSigners(client),
90
- onUpdate,
91
- configs,
118
+ context,
119
+ );
120
+
121
+ await this.addSigners(
122
+ "Rei Wallet",
123
+ REI_SVG,
124
+ Rei.getReiSigners(client),
125
+ context,
92
126
  );
93
127
 
94
128
  await this.addSigners(
95
- wallets,
96
129
  "JoyID Passkey",
97
130
  JOY_ID_SVG,
98
- JoyId.getJoyIdSigners(client, name, icon, preferredNetworks),
99
- onUpdate,
100
- configs,
131
+ JoyId.getJoyIdSigners(client, appName, appIcon, preferredNetworks),
132
+ context,
101
133
  );
102
134
 
103
135
  await this.addSigners(
104
- wallets,
105
136
  "UniSat",
106
137
  UNI_SAT_SVG,
107
138
  UniSat.getUniSatSigners(client, preferredNetworks),
108
- onUpdate,
109
- configs,
139
+ context,
110
140
  );
111
141
 
112
142
  await this.addSigners(
113
- wallets,
114
143
  "OKX Wallet",
115
144
  OKX_SVG,
116
145
  Okx.getOKXSigners(client, preferredNetworks),
117
- onUpdate,
118
- configs,
146
+ context,
119
147
  );
120
148
 
121
- await this.addSigner(
122
- wallets,
123
- "Nostr",
124
- NOSTR_SVG,
125
- "Nostr",
126
- Nip07.getNip07Signer(client),
127
- onUpdate,
128
- configs,
129
- );
149
+ const nostrSigner = Nip07.getNip07Signer(client);
150
+ if (nostrSigner) {
151
+ await this.addSigner(
152
+ "Nostr",
153
+ NOSTR_SVG,
154
+ {
155
+ name: "Nostr",
156
+ signer: nostrSigner,
157
+ },
158
+ context,
159
+ );
160
+ }
130
161
 
131
162
  this.resetListeners.push(
132
163
  new Eip6963.SignerFactory(client).subscribeSigners((signer, detail) =>
133
164
  this.addSigner(
134
- wallets,
135
165
  detail?.info.name ?? "EVM",
136
166
  detail?.info.icon ?? ETH_SVG,
137
- "EVM",
138
- signer,
139
- onUpdate,
140
- configs,
167
+ {
168
+ name: "EVM",
169
+ signer,
170
+ },
171
+ context,
141
172
  ),
142
173
  ),
143
174
  );
175
+ }
144
176
 
145
- // === Dummy signers ===
177
+ async addDummySigners(context: SignersControllerRefreshContext) {
146
178
  await this.addLinkSigners(
147
- wallets,
148
179
  "MetaMask",
149
180
  METAMASK_SVG,
150
- client,
151
181
  [ccc.SignerType.EVM],
152
182
  `https://metamask.app.link/dapp/${window.location.href}`,
153
- onUpdate,
154
- configs,
183
+ context,
155
184
  );
156
185
  await this.addLinkSigners(
157
- wallets,
158
186
  "OKX Wallet",
159
187
  OKX_SVG,
160
- client,
161
188
  [ccc.SignerType.EVM, ccc.SignerType.BTC],
162
189
  "https://www.okx.com/download?deeplink=" +
163
190
  encodeURIComponent(
164
191
  "okx://wallet/dapp/url?dappUrl=" +
165
192
  encodeURIComponent(window.location.href),
166
193
  ),
167
- onUpdate,
168
- configs,
194
+ context,
169
195
  );
170
196
  await this.addLinkSigners(
171
- wallets,
172
197
  "UniSat",
173
198
  UNI_SAT_SVG,
174
- client,
175
199
  [ccc.SignerType.BTC],
176
200
  "https://unisat.io/download",
177
- onUpdate,
178
- configs,
201
+ context,
179
202
  );
180
203
  await this.addLinkSigners(
181
- wallets,
182
204
  "UTXO Global Wallet",
183
205
  UTXO_GLOBAL_SVG,
184
- client,
185
206
  [ccc.SignerType.CKB, ccc.SignerType.BTC],
186
207
  "https://chromewebstore.google.com/detail/lnamkkidoonpeknminiadpgjiofpdmle",
187
- onUpdate,
188
- configs,
208
+ context,
189
209
  );
190
- // ===
191
210
  }
192
211
 
193
- private async addLinkSigners(
194
- wallets: WalletWithSigners[],
212
+ async addLinkSigners(
195
213
  walletName: string,
196
214
  icon: string,
197
- client: ccc.Client,
198
215
  signerTypes: ccc.SignerType[],
199
216
  link: string,
200
- onUpdate: (wallets: WalletWithSigners[]) => void,
201
- configs?: {
202
- signerFilter?: (
203
- signerInfo: ccc.SignerInfo,
204
- wallet: ccc.Wallet,
205
- ) => Promise<boolean>;
206
- },
217
+ context: SignersControllerRefreshContext,
207
218
  ) {
208
219
  return this.addSigners(
209
- wallets,
210
220
  walletName,
211
221
  icon,
212
222
  signerTypes.map((type) => ({
213
223
  name: type,
214
- signer: new ccc.SignerOpenLink(client, type, link),
224
+ signer: new ccc.SignerOpenLink(context.client, type, link),
215
225
  })),
216
- onUpdate,
217
- configs,
226
+ context,
218
227
  );
219
228
  }
220
229
 
221
- private async addSigners(
222
- wallets: WalletWithSigners[],
230
+ async addSigners(
223
231
  walletName: string,
224
232
  icon: string,
225
233
  signers: ccc.SignerInfo[],
226
- onUpdate: (wallets: WalletWithSigners[]) => void,
227
- configs?: {
228
- signerFilter?: (
229
- signerInfo: ccc.SignerInfo,
230
- wallet: ccc.Wallet,
231
- ) => Promise<boolean>;
232
- },
234
+ context: SignersControllerRefreshContext,
233
235
  ) {
234
236
  return Promise.all(
235
- signers.map(({ signer, name }) =>
236
- this.addSigner(
237
- wallets,
238
- walletName,
239
- icon,
240
- name,
241
- signer,
242
- onUpdate,
243
- configs,
244
- ),
237
+ signers.map((signerInfo) =>
238
+ this.addSigner(walletName, icon, signerInfo, context),
245
239
  ),
246
240
  );
247
241
  }
248
242
 
249
- private async addSigner(
250
- wallets: WalletWithSigners[],
243
+ protected async addSigner(
251
244
  walletName: string,
252
245
  icon: string,
253
- signerName: string,
254
- signer: ccc.Signer | null | undefined,
255
- onUpdate: (wallets: WalletWithSigners[]) => void,
256
- configs?: {
257
- signerFilter?: (
258
- signerInfo: ccc.SignerInfo,
259
- wallet: ccc.Wallet,
260
- ) => Promise<boolean>;
261
- },
246
+ signerInfo: ccc.SignerInfo,
247
+ { wallets, onUpdate }: SignersControllerRefreshContext,
262
248
  ): Promise<void> {
263
- if (!signer) {
264
- return;
265
- }
266
-
267
- const signerInfo = { name: signerName, signer };
268
- const signerFilter = configs?.signerFilter;
269
-
270
- if (
271
- signerFilter &&
272
- !(await signerFilter(signerInfo, { name: walletName, icon }))
273
- ) {
274
- return;
275
- }
276
-
277
249
  const wallet = wallets.find((w) => w.name === walletName);
278
250
 
279
251
  if (!wallet) {
package/typedoc.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "$schema": "https://typedoc.org/schema.json",
3
+ "entryPoints": ["./src/index.ts", "./src/advanced.ts"],
4
+ "extends": ["../../typedoc.base.json"],
5
+ "name": "@ckb-ccc ccc"
6
+ }