@ckb-ccc/ccc 0.0.12-alpha.7 → 0.0.12
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/CHANGELOG.md +16 -0
- package/README.md +5 -5
- package/dist/assets/rei.svg.d.ts +2 -0
- package/dist/assets/rei.svg.d.ts.map +1 -0
- package/dist/assets/rei.svg.js +2 -0
- package/dist/barrel.d.ts +1 -0
- package/dist/barrel.d.ts.map +1 -1
- package/dist/barrel.js +1 -0
- package/dist/signersController.d.ts +24 -6
- package/dist/signersController.d.ts.map +1 -1
- package/dist/signersController.js +53 -35
- package/dist.commonjs/advanced.d.ts +1 -1
- package/dist.commonjs/advanced.js +22 -47
- package/dist.commonjs/advancedBarrel.d.ts +1 -1
- package/dist.commonjs/advancedBarrel.js +14 -30
- package/dist.commonjs/assets/eth.svg.d.ts +1 -1
- package/dist.commonjs/assets/eth.svg.js +1 -3
- package/dist.commonjs/assets/joy-id.svg.d.ts +1 -1
- package/dist.commonjs/assets/joy-id.svg.js +1 -3
- package/dist.commonjs/assets/metamask.svg.d.ts +1 -1
- package/dist.commonjs/assets/metamask.svg.js +1 -3
- package/dist.commonjs/assets/nostr.svg.d.ts +1 -1
- package/dist.commonjs/assets/nostr.svg.js +1 -3
- package/dist.commonjs/assets/okx.svg.d.ts +1 -1
- package/dist.commonjs/assets/okx.svg.js +1 -3
- package/dist.commonjs/assets/rei.svg.d.ts +2 -0
- package/dist.commonjs/assets/rei.svg.d.ts.map +1 -0
- package/dist.commonjs/assets/rei.svg.js +5 -0
- package/dist.commonjs/assets/uni-sat.svg.d.ts +1 -1
- package/dist.commonjs/assets/uni-sat.svg.js +1 -3
- package/dist.commonjs/assets/utils.d.ts +1 -1
- package/dist.commonjs/assets/utils.js +1 -1
- package/dist.commonjs/assets/utxo-global.svg.d.ts +1 -1
- package/dist.commonjs/barrel.d.ts +2 -1
- package/dist.commonjs/barrel.d.ts.map +1 -1
- package/dist.commonjs/barrel.js +15 -30
- package/dist.commonjs/index.d.ts +1 -1
- package/dist.commonjs/index.js +22 -47
- package/dist.commonjs/signersController.d.ts +41 -30
- package/dist.commonjs/signersController.d.ts.map +1 -1
- package/dist.commonjs/signersController.js +100 -207
- package/package.json +9 -8
- package/src/assets/rei.svg.ts +5 -0
- package/src/barrel.ts +1 -0
- package/src/signersController.ts +85 -113
- package/typedoc.json +6 -0
package/src/signersController.ts
CHANGED
|
@@ -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
|
|
50
|
+
const appName =
|
|
31
51
|
configs?.name ??
|
|
32
52
|
(document.querySelector("head title") as HTMLTitleElement | null)?.text ??
|
|
33
53
|
"Unknown";
|
|
34
|
-
const
|
|
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
|
-
|
|
56
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
91
|
-
|
|
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,
|
|
99
|
-
|
|
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
|
-
|
|
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
|
-
|
|
118
|
-
configs,
|
|
146
|
+
context,
|
|
119
147
|
);
|
|
120
148
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
167
|
+
{
|
|
168
|
+
name: "EVM",
|
|
169
|
+
signer,
|
|
170
|
+
},
|
|
171
|
+
context,
|
|
141
172
|
),
|
|
142
173
|
),
|
|
143
174
|
);
|
|
175
|
+
}
|
|
144
176
|
|
|
145
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
188
|
-
configs,
|
|
208
|
+
context,
|
|
189
209
|
);
|
|
190
|
-
// ===
|
|
191
210
|
}
|
|
192
211
|
|
|
193
|
-
|
|
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
|
-
|
|
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
|
-
|
|
217
|
-
configs,
|
|
226
|
+
context,
|
|
218
227
|
);
|
|
219
228
|
}
|
|
220
229
|
|
|
221
|
-
|
|
222
|
-
wallets: WalletWithSigners[],
|
|
230
|
+
async addSigners(
|
|
223
231
|
walletName: string,
|
|
224
232
|
icon: string,
|
|
225
233
|
signers: ccc.SignerInfo[],
|
|
226
|
-
|
|
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((
|
|
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
|
-
|
|
250
|
-
wallets: WalletWithSigners[],
|
|
243
|
+
protected async addSigner(
|
|
251
244
|
walletName: string,
|
|
252
245
|
icon: string,
|
|
253
|
-
|
|
254
|
-
|
|
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) {
|