@ckb-ccc/eip6963 0.0.11-alpha.3 → 0.0.12-alpha.1

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/dist/signer.d.ts CHANGED
@@ -1,19 +1,19 @@
1
1
  import { ccc } from "@ckb-ccc/core";
2
- import { ProviderDetail as EIP6963ProviderDetail } from "./eip6963.advanced.js";
2
+ import { Provider } from "./eip1193.advanced.js";
3
3
  /**
4
4
  * Class representing an EVM signer that extends SignerEvm from @ckb-ccc/core.
5
5
  * @class
6
6
  * @extends {ccc.SignerEvm}
7
7
  */
8
8
  export declare class Signer extends ccc.SignerEvm {
9
- readonly detail: EIP6963ProviderDetail;
9
+ readonly provider: Provider;
10
10
  private accountCache?;
11
11
  /**
12
12
  * Creates an instance of Signer.
13
13
  * @param {ccc.Client} client - The client instance.
14
14
  * @param {EIP6963ProviderDetail} detail - The provider detail.
15
15
  */
16
- constructor(client: ccc.Client, detail: EIP6963ProviderDetail);
16
+ constructor(client: ccc.Client, provider: Provider);
17
17
  /**
18
18
  * Gets the EVM account address.
19
19
  * @returns A promise that resolves to the EVM account address.
@@ -1 +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,EAAE,cAAc,IAAI,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAEhF;;;;GAIG;AACH,qBAAa,MAAO,SAAQ,GAAG,CAAC,SAAS;aAUrB,MAAM,EAAE,qBAAqB;IAT/C,OAAO,CAAC,YAAY,CAAC,CAAsB;IAE3C;;;;OAIG;gBAED,MAAM,EAAE,GAAG,CAAC,MAAM,EACF,MAAM,EAAE,qBAAqB;IAK/C;;;OAGG;IACG,aAAa,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;IAOvC;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAI9B,UAAU,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI;IAiB5C;;;OAGG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAOrC;;;;OAIG;IACG,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAC,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;CAWxE"}
1
+ {"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../src/signer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD;;;;GAIG;AACH,qBAAa,MAAO,SAAQ,GAAG,CAAC,SAAS;aAUrB,QAAQ,EAAE,QAAQ;IATpC,OAAO,CAAC,YAAY,CAAC,CAAsB;IAE3C;;;;OAIG;gBAED,MAAM,EAAE,GAAG,CAAC,MAAM,EACF,QAAQ,EAAE,QAAQ;IAKpC;;;OAGG;IACG,aAAa,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;IAOvC;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAI9B,UAAU,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI;IAiB5C;;;OAGG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAMrC;;;;OAIG;IACG,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAC,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;CAWxE"}
package/dist/signer.js CHANGED
@@ -10,9 +10,9 @@ export class Signer extends ccc.SignerEvm {
10
10
  * @param {ccc.Client} client - The client instance.
11
11
  * @param {EIP6963ProviderDetail} detail - The provider detail.
12
12
  */
13
- constructor(client, detail) {
13
+ constructor(client, provider) {
14
14
  super(client);
15
- this.detail = detail;
15
+ this.provider = provider;
16
16
  this.accountCache = undefined;
17
17
  }
18
18
  /**
@@ -20,7 +20,7 @@ export class Signer extends ccc.SignerEvm {
20
20
  * @returns A promise that resolves to the EVM account address.
21
21
  */
22
22
  async getEvmAccount() {
23
- this.accountCache = (await this.detail.provider.request({ method: "eth_accounts" }))[0];
23
+ this.accountCache = (await this.provider.request({ method: "eth_accounts" }))[0];
24
24
  return this.accountCache;
25
25
  }
26
26
  /**
@@ -28,7 +28,7 @@ export class Signer extends ccc.SignerEvm {
28
28
  * @returns {Promise<void>} A promise that resolves when the connection is established.
29
29
  */
30
30
  async connect() {
31
- await this.detail.provider.request({ method: "eth_requestAccounts" });
31
+ await this.provider.request({ method: "eth_requestAccounts" });
32
32
  }
33
33
  onReplaced(listener) {
34
34
  const stop = [];
@@ -37,11 +37,11 @@ export class Signer extends ccc.SignerEvm {
37
37
  stop[0]?.();
38
38
  };
39
39
  stop.push(() => {
40
- this.detail.provider.removeListener("accountsChanged", replacer);
41
- this.detail.provider.removeListener("disconnect", replacer);
40
+ this.provider.removeListener("accountsChanged", replacer);
41
+ this.provider.removeListener("disconnect", replacer);
42
42
  });
43
- this.detail.provider.on("accountsChanged", replacer);
44
- this.detail.provider.on("disconnect", replacer);
43
+ this.provider.on("accountsChanged", replacer);
44
+ this.provider.on("disconnect", replacer);
45
45
  return stop[0];
46
46
  }
47
47
  /**
@@ -49,8 +49,7 @@ export class Signer extends ccc.SignerEvm {
49
49
  * @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
50
50
  */
51
51
  async isConnected() {
52
- return ((await this.detail.provider.request({ method: "eth_accounts" }))
53
- .length !== 0);
52
+ return ((await this.provider.request({ method: "eth_accounts" })).length !== 0);
54
53
  }
55
54
  /**
56
55
  * Signs a raw message with the personal account.
@@ -60,7 +59,7 @@ export class Signer extends ccc.SignerEvm {
60
59
  async signMessageRaw(message) {
61
60
  const challenge = typeof message === "string" ? ccc.bytesFrom(message, "utf8") : message;
62
61
  const account = this.accountCache ?? (await this.getEvmAccount());
63
- return this.detail.provider.request({
62
+ return this.provider.request({
64
63
  method: "personal_sign",
65
64
  params: [ccc.hexFrom(challenge), account],
66
65
  });
@@ -1,5 +1,6 @@
1
1
  import { ccc } from "@ckb-ccc/core";
2
- import { Signer as EIP6963Signer } from "./signer.js";
2
+ import { ProviderDetail } from "./eip6963.advanced.js";
3
+ import { Signer } from "./signer.js";
3
4
  /**
4
5
  * Class representing a factory for creating and managing Signer instances.
5
6
  * @class
@@ -14,9 +15,9 @@ export declare class SignerFactory {
14
15
  constructor(client: ccc.Client);
15
16
  /**
16
17
  * Subscribes to new signers and triggers a callback when a new signer is available.
17
- * @param {(newSigner: EIP6963Signer) => unknown} callback - The callback to trigger with the new signer.
18
- * @returns {() => void} A function to unsubscribe from the signer events.
18
+ * @param callback - The callback to trigger with the new signer.
19
+ * @returns A function to unsubscribe from the signer events.
19
20
  */
20
- subscribeSigners(callback: (newSigner: EIP6963Signer) => unknown): () => void;
21
+ subscribeSigners(callback: (newSigner: Signer, detail?: ProviderDetail) => unknown): () => void;
21
22
  }
22
23
  //# sourceMappingURL=signersFactory.d.ts.map
@@ -1 +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,IAAI,aAAa,EAAE,MAAM,aAAa,CAAC;AAEtD;;;GAGG;AACH,qBAAa,aAAa;IAOZ,OAAO,CAAC,QAAQ,CAAC,MAAM;IANnC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAgB;IAE7C;;;OAGG;gBAC0B,MAAM,EAAE,GAAG,CAAC,MAAM;IAE/C;;;;OAIG;IACH,gBAAgB,CACd,QAAQ,EAAE,CAAC,SAAS,EAAE,aAAa,KAAK,OAAO,GAC9C,MAAM,IAAI;CAoBd"}
1
+ {"version":3,"file":"signersFactory.d.ts","sourceRoot":"","sources":["../src/signersFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEpC,OAAO,EAEL,cAAc,EACf,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC;;;GAGG;AACH,qBAAa,aAAa;IAOZ,OAAO,CAAC,QAAQ,CAAC,MAAM;IANnC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAgB;IAE7C;;;OAGG;gBAC0B,MAAM,EAAE,GAAG,CAAC,MAAM;IAE/C;;;;OAIG;IACH,gBAAgB,CACd,QAAQ,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,cAAc,KAAK,OAAO,GAChE,MAAM,IAAI;CA0Bd"}
@@ -1,4 +1,4 @@
1
- import { Signer as EIP6963Signer } from "./signer.js";
1
+ import { Signer } from "./signer.js";
2
2
  /**
3
3
  * Class representing a factory for creating and managing Signer instances.
4
4
  * @class
@@ -14,8 +14,8 @@ export class SignerFactory {
14
14
  }
15
15
  /**
16
16
  * Subscribes to new signers and triggers a callback when a new signer is available.
17
- * @param {(newSigner: EIP6963Signer) => unknown} callback - The callback to trigger with the new signer.
18
- * @returns {() => void} A function to unsubscribe from the signer events.
17
+ * @param callback - The callback to trigger with the new signer.
18
+ * @returns A function to unsubscribe from the signer events.
19
19
  */
20
20
  subscribeSigners(callback) {
21
21
  const onNewProvider = (event) => {
@@ -25,11 +25,15 @@ export class SignerFactory {
25
25
  return;
26
26
  }
27
27
  this.existedUuids.push(uuid);
28
- const signer = new EIP6963Signer(this.client, detail);
29
- callback(signer);
28
+ const signer = new Signer(this.client, detail.provider);
29
+ callback(signer, detail);
30
30
  };
31
31
  window.addEventListener("eip6963:announceProvider", onNewProvider);
32
32
  window.dispatchEvent(new Event("eip6963:requestProvider"));
33
+ const windowRef = window;
34
+ if (typeof windowRef.ethereum !== "undefined") {
35
+ callback(new Signer(this.client, windowRef.ethereum));
36
+ }
33
37
  return () => window.removeEventListener("eip6963:announceProvider", onNewProvider);
34
38
  }
35
39
  }
@@ -1,19 +1,19 @@
1
1
  import { ccc } from "@ckb-ccc/core";
2
- import { ProviderDetail as EIP6963ProviderDetail } from "./eip6963.advanced.js";
2
+ import { Provider } from "./eip1193.advanced.js";
3
3
  /**
4
4
  * Class representing an EVM signer that extends SignerEvm from @ckb-ccc/core.
5
5
  * @class
6
6
  * @extends {ccc.SignerEvm}
7
7
  */
8
8
  export declare class Signer extends ccc.SignerEvm {
9
- readonly detail: EIP6963ProviderDetail;
9
+ readonly provider: Provider;
10
10
  private accountCache?;
11
11
  /**
12
12
  * Creates an instance of Signer.
13
13
  * @param {ccc.Client} client - The client instance.
14
14
  * @param {EIP6963ProviderDetail} detail - The provider detail.
15
15
  */
16
- constructor(client: ccc.Client, detail: EIP6963ProviderDetail);
16
+ constructor(client: ccc.Client, provider: Provider);
17
17
  /**
18
18
  * Gets the EVM account address.
19
19
  * @returns A promise that resolves to the EVM account address.
@@ -1 +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,EAAE,cAAc,IAAI,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAEhF;;;;GAIG;AACH,qBAAa,MAAO,SAAQ,GAAG,CAAC,SAAS;aAUrB,MAAM,EAAE,qBAAqB;IAT/C,OAAO,CAAC,YAAY,CAAC,CAAsB;IAE3C;;;;OAIG;gBAED,MAAM,EAAE,GAAG,CAAC,MAAM,EACF,MAAM,EAAE,qBAAqB;IAK/C;;;OAGG;IACG,aAAa,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;IAOvC;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAI9B,UAAU,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI;IAiB5C;;;OAGG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAOrC;;;;OAIG;IACG,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAC,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;CAWxE"}
1
+ {"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../src/signer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD;;;;GAIG;AACH,qBAAa,MAAO,SAAQ,GAAG,CAAC,SAAS;aAUrB,QAAQ,EAAE,QAAQ;IATpC,OAAO,CAAC,YAAY,CAAC,CAAsB;IAE3C;;;;OAIG;gBAED,MAAM,EAAE,GAAG,CAAC,MAAM,EACF,QAAQ,EAAE,QAAQ;IAKpC;;;OAGG;IACG,aAAa,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;IAOvC;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAI9B,UAAU,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI;IAiB5C;;;OAGG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAMrC;;;;OAIG;IACG,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAC,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;CAWxE"}
@@ -13,9 +13,9 @@ class Signer extends core_1.ccc.SignerEvm {
13
13
  * @param {ccc.Client} client - The client instance.
14
14
  * @param {EIP6963ProviderDetail} detail - The provider detail.
15
15
  */
16
- constructor(client, detail) {
16
+ constructor(client, provider) {
17
17
  super(client);
18
- this.detail = detail;
18
+ this.provider = provider;
19
19
  this.accountCache = undefined;
20
20
  }
21
21
  /**
@@ -23,7 +23,7 @@ class Signer extends core_1.ccc.SignerEvm {
23
23
  * @returns A promise that resolves to the EVM account address.
24
24
  */
25
25
  async getEvmAccount() {
26
- this.accountCache = (await this.detail.provider.request({ method: "eth_accounts" }))[0];
26
+ this.accountCache = (await this.provider.request({ method: "eth_accounts" }))[0];
27
27
  return this.accountCache;
28
28
  }
29
29
  /**
@@ -31,7 +31,7 @@ class Signer extends core_1.ccc.SignerEvm {
31
31
  * @returns {Promise<void>} A promise that resolves when the connection is established.
32
32
  */
33
33
  async connect() {
34
- await this.detail.provider.request({ method: "eth_requestAccounts" });
34
+ await this.provider.request({ method: "eth_requestAccounts" });
35
35
  }
36
36
  onReplaced(listener) {
37
37
  const stop = [];
@@ -40,11 +40,11 @@ class Signer extends core_1.ccc.SignerEvm {
40
40
  stop[0]?.();
41
41
  };
42
42
  stop.push(() => {
43
- this.detail.provider.removeListener("accountsChanged", replacer);
44
- this.detail.provider.removeListener("disconnect", replacer);
43
+ this.provider.removeListener("accountsChanged", replacer);
44
+ this.provider.removeListener("disconnect", replacer);
45
45
  });
46
- this.detail.provider.on("accountsChanged", replacer);
47
- this.detail.provider.on("disconnect", replacer);
46
+ this.provider.on("accountsChanged", replacer);
47
+ this.provider.on("disconnect", replacer);
48
48
  return stop[0];
49
49
  }
50
50
  /**
@@ -52,8 +52,7 @@ class Signer extends core_1.ccc.SignerEvm {
52
52
  * @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
53
53
  */
54
54
  async isConnected() {
55
- return ((await this.detail.provider.request({ method: "eth_accounts" }))
56
- .length !== 0);
55
+ return ((await this.provider.request({ method: "eth_accounts" })).length !== 0);
57
56
  }
58
57
  /**
59
58
  * Signs a raw message with the personal account.
@@ -63,7 +62,7 @@ class Signer extends core_1.ccc.SignerEvm {
63
62
  async signMessageRaw(message) {
64
63
  const challenge = typeof message === "string" ? core_1.ccc.bytesFrom(message, "utf8") : message;
65
64
  const account = this.accountCache ?? (await this.getEvmAccount());
66
- return this.detail.provider.request({
65
+ return this.provider.request({
67
66
  method: "personal_sign",
68
67
  params: [core_1.ccc.hexFrom(challenge), account],
69
68
  });
@@ -1,5 +1,6 @@
1
1
  import { ccc } from "@ckb-ccc/core";
2
- import { Signer as EIP6963Signer } from "./signer.js";
2
+ import { ProviderDetail } from "./eip6963.advanced.js";
3
+ import { Signer } from "./signer.js";
3
4
  /**
4
5
  * Class representing a factory for creating and managing Signer instances.
5
6
  * @class
@@ -14,9 +15,9 @@ export declare class SignerFactory {
14
15
  constructor(client: ccc.Client);
15
16
  /**
16
17
  * Subscribes to new signers and triggers a callback when a new signer is available.
17
- * @param {(newSigner: EIP6963Signer) => unknown} callback - The callback to trigger with the new signer.
18
- * @returns {() => void} A function to unsubscribe from the signer events.
18
+ * @param callback - The callback to trigger with the new signer.
19
+ * @returns A function to unsubscribe from the signer events.
19
20
  */
20
- subscribeSigners(callback: (newSigner: EIP6963Signer) => unknown): () => void;
21
+ subscribeSigners(callback: (newSigner: Signer, detail?: ProviderDetail) => unknown): () => void;
21
22
  }
22
23
  //# sourceMappingURL=signersFactory.d.ts.map
@@ -1 +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,IAAI,aAAa,EAAE,MAAM,aAAa,CAAC;AAEtD;;;GAGG;AACH,qBAAa,aAAa;IAOZ,OAAO,CAAC,QAAQ,CAAC,MAAM;IANnC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAgB;IAE7C;;;OAGG;gBAC0B,MAAM,EAAE,GAAG,CAAC,MAAM;IAE/C;;;;OAIG;IACH,gBAAgB,CACd,QAAQ,EAAE,CAAC,SAAS,EAAE,aAAa,KAAK,OAAO,GAC9C,MAAM,IAAI;CAoBd"}
1
+ {"version":3,"file":"signersFactory.d.ts","sourceRoot":"","sources":["../src/signersFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEpC,OAAO,EAEL,cAAc,EACf,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC;;;GAGG;AACH,qBAAa,aAAa;IAOZ,OAAO,CAAC,QAAQ,CAAC,MAAM;IANnC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAgB;IAE7C;;;OAGG;gBAC0B,MAAM,EAAE,GAAG,CAAC,MAAM;IAE/C;;;;OAIG;IACH,gBAAgB,CACd,QAAQ,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,cAAc,KAAK,OAAO,GAChE,MAAM,IAAI;CA0Bd"}
@@ -17,8 +17,8 @@ class SignerFactory {
17
17
  }
18
18
  /**
19
19
  * Subscribes to new signers and triggers a callback when a new signer is available.
20
- * @param {(newSigner: EIP6963Signer) => unknown} callback - The callback to trigger with the new signer.
21
- * @returns {() => void} A function to unsubscribe from the signer events.
20
+ * @param callback - The callback to trigger with the new signer.
21
+ * @returns A function to unsubscribe from the signer events.
22
22
  */
23
23
  subscribeSigners(callback) {
24
24
  const onNewProvider = (event) => {
@@ -28,11 +28,15 @@ class SignerFactory {
28
28
  return;
29
29
  }
30
30
  this.existedUuids.push(uuid);
31
- const signer = new signer_js_1.Signer(this.client, detail);
32
- callback(signer);
31
+ const signer = new signer_js_1.Signer(this.client, detail.provider);
32
+ callback(signer, detail);
33
33
  };
34
34
  window.addEventListener("eip6963:announceProvider", onNewProvider);
35
35
  window.dispatchEvent(new Event("eip6963:requestProvider"));
36
+ const windowRef = window;
37
+ if (typeof windowRef.ethereum !== "undefined") {
38
+ callback(new signer_js_1.Signer(this.client, windowRef.ethereum));
39
+ }
36
40
  return () => window.removeEventListener("eip6963:announceProvider", onNewProvider);
37
41
  }
38
42
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckb-ccc/eip6963",
3
- "version": "0.0.11-alpha.3",
3
+ "version": "0.0.12-alpha.1",
4
4
  "description": "CCC - CKBer's Codebase. Common Chains Connector's support for EIP6963",
5
5
  "author": "Hanssen0 <hanssen0@hanssen0.com>",
6
6
  "license": "MIT",
@@ -43,7 +43,7 @@
43
43
  "access": "public"
44
44
  },
45
45
  "dependencies": {
46
- "@ckb-ccc/core": "0.0.11-alpha.3"
46
+ "@ckb-ccc/core": "0.0.12-alpha.1"
47
47
  },
48
- "gitHead": "235ba3c69a0a1098fcd741fafb4b8f32dcfbc2b5"
48
+ "gitHead": "22b1e1e4c7e56c8a6e9f699f54193cbec7d30a8b"
49
49
  }
package/src/signer.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ccc } from "@ckb-ccc/core";
2
- import { ProviderDetail as EIP6963ProviderDetail } from "./eip6963.advanced.js";
2
+ import { Provider } from "./eip1193.advanced.js";
3
3
 
4
4
  /**
5
5
  * Class representing an EVM signer that extends SignerEvm from @ckb-ccc/core.
@@ -16,7 +16,7 @@ export class Signer extends ccc.SignerEvm {
16
16
  */
17
17
  constructor(
18
18
  client: ccc.Client,
19
- public readonly detail: EIP6963ProviderDetail,
19
+ public readonly provider: Provider,
20
20
  ) {
21
21
  super(client);
22
22
  }
@@ -27,7 +27,7 @@ export class Signer extends ccc.SignerEvm {
27
27
  */
28
28
  async getEvmAccount(): Promise<ccc.Hex> {
29
29
  this.accountCache = (
30
- await this.detail.provider.request({ method: "eth_accounts" })
30
+ await this.provider.request({ method: "eth_accounts" })
31
31
  )[0];
32
32
  return this.accountCache;
33
33
  }
@@ -37,7 +37,7 @@ export class Signer extends ccc.SignerEvm {
37
37
  * @returns {Promise<void>} A promise that resolves when the connection is established.
38
38
  */
39
39
  async connect(): Promise<void> {
40
- await this.detail.provider.request({ method: "eth_requestAccounts" });
40
+ await this.provider.request({ method: "eth_requestAccounts" });
41
41
  }
42
42
 
43
43
  onReplaced(listener: () => void): () => void {
@@ -47,12 +47,12 @@ export class Signer extends ccc.SignerEvm {
47
47
  stop[0]?.();
48
48
  };
49
49
  stop.push(() => {
50
- this.detail.provider.removeListener("accountsChanged", replacer);
51
- this.detail.provider.removeListener("disconnect", replacer);
50
+ this.provider.removeListener("accountsChanged", replacer);
51
+ this.provider.removeListener("disconnect", replacer);
52
52
  });
53
53
 
54
- this.detail.provider.on("accountsChanged", replacer);
55
- this.detail.provider.on("disconnect", replacer);
54
+ this.provider.on("accountsChanged", replacer);
55
+ this.provider.on("disconnect", replacer);
56
56
 
57
57
  return stop[0];
58
58
  }
@@ -63,8 +63,7 @@ export class Signer extends ccc.SignerEvm {
63
63
  */
64
64
  async isConnected(): Promise<boolean> {
65
65
  return (
66
- (await this.detail.provider.request({ method: "eth_accounts" }))
67
- .length !== 0
66
+ (await this.provider.request({ method: "eth_accounts" })).length !== 0
68
67
  );
69
68
  }
70
69
 
@@ -79,7 +78,7 @@ export class Signer extends ccc.SignerEvm {
79
78
 
80
79
  const account = this.accountCache ?? (await this.getEvmAccount());
81
80
 
82
- return this.detail.provider.request({
81
+ return this.provider.request({
83
82
  method: "personal_sign",
84
83
  params: [ccc.hexFrom(challenge), account],
85
84
  });
@@ -1,6 +1,10 @@
1
1
  import { ccc } from "@ckb-ccc/core";
2
- import { AnnounceProviderEvent as EIP6963AnnounceProviderEvent } from "./eip6963.advanced.js";
3
- import { Signer as EIP6963Signer } from "./signer.js";
2
+ import { Provider } from "./eip1193.advanced.js";
3
+ import {
4
+ AnnounceProviderEvent as EIP6963AnnounceProviderEvent,
5
+ ProviderDetail,
6
+ } from "./eip6963.advanced.js";
7
+ import { Signer } from "./signer.js";
4
8
 
5
9
  /**
6
10
  * Class representing a factory for creating and managing Signer instances.
@@ -17,11 +21,11 @@ export class SignerFactory {
17
21
 
18
22
  /**
19
23
  * Subscribes to new signers and triggers a callback when a new signer is available.
20
- * @param {(newSigner: EIP6963Signer) => unknown} callback - The callback to trigger with the new signer.
21
- * @returns {() => void} A function to unsubscribe from the signer events.
24
+ * @param callback - The callback to trigger with the new signer.
25
+ * @returns A function to unsubscribe from the signer events.
22
26
  */
23
27
  subscribeSigners(
24
- callback: (newSigner: EIP6963Signer) => unknown,
28
+ callback: (newSigner: Signer, detail?: ProviderDetail) => unknown,
25
29
  ): () => void {
26
30
  const onNewProvider = (event: Event) => {
27
31
  const { detail } = event as unknown as EIP6963AnnounceProviderEvent;
@@ -32,13 +36,19 @@ export class SignerFactory {
32
36
  }
33
37
 
34
38
  this.existedUuids.push(uuid);
35
- const signer = new EIP6963Signer(this.client, detail);
36
- callback(signer);
39
+ const signer = new Signer(this.client, detail.provider);
40
+ callback(signer, detail);
37
41
  };
38
42
 
39
43
  window.addEventListener("eip6963:announceProvider", onNewProvider);
40
44
  window.dispatchEvent(new Event("eip6963:requestProvider"));
41
45
 
46
+ const windowRef = window as { ethereum?: Provider };
47
+
48
+ if (typeof windowRef.ethereum !== "undefined") {
49
+ callback(new Signer(this.client, windowRef.ethereum));
50
+ }
51
+
42
52
  return () =>
43
53
  window.removeEventListener("eip6963:announceProvider", onNewProvider);
44
54
  }