@ckb-ccc/eip6963 0.0.5-alpha.8 → 0.0.6-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.
- package/dist/eip1193.advanced.d.ts +60 -0
- package/dist/eip1193.advanced.d.ts.map +1 -1
- package/dist/eip6963.advanced.d.ts +40 -0
- package/dist/eip6963.advanced.d.ts.map +1 -1
- package/dist/signer.d.ts +27 -1
- package/dist/signer.d.ts.map +1 -1
- package/dist/signer.js +27 -3
- package/dist/signersFactory.d.ts +13 -0
- package/dist/signersFactory.d.ts.map +1 -1
- package/dist/signersFactory.js +14 -1
- package/dist.commonjs/eip1193.advanced.d.ts +60 -0
- package/dist.commonjs/eip1193.advanced.d.ts.map +1 -1
- package/dist.commonjs/eip6963.advanced.d.ts +40 -0
- package/dist.commonjs/eip6963.advanced.d.ts.map +1 -1
- package/dist.commonjs/signer.d.ts +27 -1
- package/dist.commonjs/signer.d.ts.map +1 -1
- package/dist.commonjs/signer.js +27 -3
- package/dist.commonjs/signersFactory.d.ts +13 -0
- package/dist.commonjs/signersFactory.d.ts.map +1 -1
- package/dist.commonjs/signersFactory.js +14 -1
- package/package.json +3 -3
- package/src/eip1193.advanced.ts +65 -0
- package/src/eip6963.advanced.ts +44 -0
- package/src/signer.ts +27 -4
- package/src/signersFactory.ts +18 -2
|
@@ -1,28 +1,88 @@
|
|
|
1
1
|
import { Hex } from "@ckb-ccc/core";
|
|
2
|
+
/**
|
|
3
|
+
* Interface representing a provider for interacting with Ethereum-compatible wallets.
|
|
4
|
+
* @interface
|
|
5
|
+
*/
|
|
2
6
|
export interface Provider {
|
|
7
|
+
/**
|
|
8
|
+
* Sends a request to the provider.
|
|
9
|
+
* @type {RequestMethod}
|
|
10
|
+
*/
|
|
3
11
|
request: RequestMethod;
|
|
12
|
+
/**
|
|
13
|
+
* Adds an event listener to the provider.
|
|
14
|
+
* @type {OnMethod}
|
|
15
|
+
*/
|
|
4
16
|
on: OnMethod;
|
|
17
|
+
/**
|
|
18
|
+
* Removes an event listener from the provider.
|
|
19
|
+
* @param {string} eventName - The name of the event to remove the listener from.
|
|
20
|
+
* @param {(...args: unknown[]) => unknown} listener - The listener function to remove.
|
|
21
|
+
* @returns {Provider} The provider instance.
|
|
22
|
+
*/
|
|
5
23
|
removeListener(eventName: string, listener: (...args: unknown[]) => unknown): Provider;
|
|
6
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Interface representing a method to send requests to the provider.
|
|
27
|
+
* @interface
|
|
28
|
+
*/
|
|
7
29
|
export interface RequestMethod {
|
|
30
|
+
/**
|
|
31
|
+
* Signs a message with the personal account.
|
|
32
|
+
* @param {object} request - The request object.
|
|
33
|
+
* @param {"personal_sign"} request.method - The method name.
|
|
34
|
+
* @param {[string, Hex]} request.params - The method parameters.
|
|
35
|
+
* @returns {Promise<Hex>} A promise that resolves to the signed message.
|
|
36
|
+
*/
|
|
8
37
|
(request: {
|
|
9
38
|
method: "personal_sign";
|
|
10
39
|
params: [string, Hex];
|
|
11
40
|
}): Promise<Hex>;
|
|
41
|
+
/**
|
|
42
|
+
* Requests the accounts from the provider.
|
|
43
|
+
* @param {object} request - The request object.
|
|
44
|
+
* @param {"eth_requestAccounts"} request.method - The method name.
|
|
45
|
+
* @param {undefined} [request.params] - The optional method parameters.
|
|
46
|
+
* @returns {Promise<Hex[]>} A promise that resolves to an array of account addresses.
|
|
47
|
+
*/
|
|
12
48
|
(request: {
|
|
13
49
|
method: "eth_requestAccounts";
|
|
14
50
|
params?: undefined;
|
|
15
51
|
}): Promise<Hex[]>;
|
|
52
|
+
/**
|
|
53
|
+
* Gets the accounts from the provider.
|
|
54
|
+
* @param {object} request - The request object.
|
|
55
|
+
* @param {"eth_accounts"} request.method - The method name.
|
|
56
|
+
* @param {undefined} [request.params] - The optional method parameters.
|
|
57
|
+
* @returns {Promise<Hex[]>} A promise that resolves to an array of account addresses.
|
|
58
|
+
*/
|
|
16
59
|
(request: {
|
|
17
60
|
method: "eth_accounts";
|
|
18
61
|
params?: undefined;
|
|
19
62
|
}): Promise<Hex[]>;
|
|
63
|
+
/**
|
|
64
|
+
* Sends a generic request to the provider.
|
|
65
|
+
* @param {object} request - The request object.
|
|
66
|
+
* @param {string} request.method - The method name.
|
|
67
|
+
* @param {Array<unknown> | Record<string, unknown>} [request.params] - The optional method parameters.
|
|
68
|
+
* @returns {Promise<unknown>} A promise that resolves to the response from the provider.
|
|
69
|
+
*/
|
|
20
70
|
(request: {
|
|
21
71
|
method: string;
|
|
22
72
|
params?: Array<unknown> | Record<string, unknown>;
|
|
23
73
|
}): Promise<unknown>;
|
|
24
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Interface representing a method to add event listeners to the provider.
|
|
77
|
+
* @interface
|
|
78
|
+
*/
|
|
25
79
|
export interface OnMethod {
|
|
80
|
+
/**
|
|
81
|
+
* Adds an event listener to the provider.
|
|
82
|
+
* @param {string} eventName - The name of the event.
|
|
83
|
+
* @param {(...args: unknown[]) => unknown} listener - The listener function.
|
|
84
|
+
* @returns {Provider} The provider instance.
|
|
85
|
+
*/
|
|
26
86
|
(eventName: string, listener: (...args: unknown[]) => unknown): Provider;
|
|
27
87
|
}
|
|
28
88
|
//# sourceMappingURL=eip1193.advanced.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eip1193.advanced.d.ts","sourceRoot":"","sources":["../src/eip1193.advanced.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEpC,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"eip1193.advanced.d.ts","sourceRoot":"","sources":["../src/eip1193.advanced.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEpC;;;GAGG;AACH,MAAM,WAAW,QAAQ;IACvB;;;OAGG;IACH,OAAO,EAAE,aAAa,CAAC;IAEvB;;;OAGG;IACH,EAAE,EAAE,QAAQ,CAAC;IAEb;;;;;OAKG;IACH,cAAc,CACZ,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,GACxC,QAAQ,CAAC;CACb;AAED;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B;;;;;;OAMG;IACH,CAAC,OAAO,EAAE;QAAE,MAAM,EAAE,eAAe,CAAC;QAAC,MAAM,EAAE,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;KAAE,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IAE5E;;;;;;OAMG;IACH,CAAC,OAAO,EAAE;QACR,MAAM,EAAE,qBAAqB,CAAC;QAC9B,MAAM,CAAC,EAAE,SAAS,CAAC;KACpB,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IAEnB;;;;;;OAMG;IACH,CAAC,OAAO,EAAE;QAAE,MAAM,EAAE,cAAc,CAAC;QAAC,MAAM,CAAC,EAAE,SAAS,CAAA;KAAE,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IAE1E;;;;;;OAMG;IACH,CAAC,OAAO,EAAE;QACR,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACnD,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACtB;AAED;;;GAGG;AACH,MAAM,WAAW,QAAQ;IACvB;;;;;OAKG;IACH,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,GAAG,QAAQ,CAAC;CAC1E"}
|
|
@@ -1,15 +1,55 @@
|
|
|
1
1
|
import { Provider as EIP1193Provider } from "./eip1193.advanced";
|
|
2
|
+
/**
|
|
3
|
+
* Interface representing an event announcing a provider.
|
|
4
|
+
* @interface
|
|
5
|
+
*/
|
|
2
6
|
export interface AnnounceProviderEvent {
|
|
7
|
+
/**
|
|
8
|
+
* The detail of the provider.
|
|
9
|
+
* @type {ProviderDetail}
|
|
10
|
+
*/
|
|
3
11
|
detail: ProviderDetail;
|
|
4
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Interface representing the details of a provider.
|
|
15
|
+
* @interface
|
|
16
|
+
*/
|
|
5
17
|
export interface ProviderDetail {
|
|
18
|
+
/**
|
|
19
|
+
* The information about the provider.
|
|
20
|
+
* @type {ProviderInfo}
|
|
21
|
+
*/
|
|
6
22
|
info: ProviderInfo;
|
|
23
|
+
/**
|
|
24
|
+
* The provider instance compliant with EIP-1193.
|
|
25
|
+
* @type {EIP1193Provider}
|
|
26
|
+
*/
|
|
7
27
|
provider: EIP1193Provider;
|
|
8
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Interface representing information about a provider.
|
|
31
|
+
* @interface
|
|
32
|
+
*/
|
|
9
33
|
export interface ProviderInfo {
|
|
34
|
+
/**
|
|
35
|
+
* The reverse DNS name of the provider.
|
|
36
|
+
* @type {string}
|
|
37
|
+
*/
|
|
10
38
|
rdns: string;
|
|
39
|
+
/**
|
|
40
|
+
* The UUID of the provider.
|
|
41
|
+
* @type {string}
|
|
42
|
+
*/
|
|
11
43
|
uuid: string;
|
|
44
|
+
/**
|
|
45
|
+
* The name of the provider.
|
|
46
|
+
* @type {string}
|
|
47
|
+
*/
|
|
12
48
|
name: string;
|
|
49
|
+
/**
|
|
50
|
+
* The icon URL of the provider.
|
|
51
|
+
* @type {string}
|
|
52
|
+
*/
|
|
13
53
|
icon: string;
|
|
14
54
|
}
|
|
15
55
|
//# sourceMappingURL=eip6963.advanced.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eip6963.advanced.d.ts","sourceRoot":"","sources":["../src/eip6963.advanced.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAEjE,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,cAAc,CAAC;CACxB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"eip6963.advanced.d.ts","sourceRoot":"","sources":["../src/eip6963.advanced.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAEjE;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,MAAM,EAAE,cAAc,CAAC;CACxB;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,IAAI,EAAE,YAAY,CAAC;IAEnB;;;OAGG;IACH,QAAQ,EAAE,eAAe,CAAC;CAC3B;AAED;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;CACd"}
|
package/dist/signer.d.ts
CHANGED
|
@@ -1,12 +1,38 @@
|
|
|
1
1
|
import { ccc } from "@ckb-ccc/core";
|
|
2
2
|
import { ProviderDetail as EIP6963ProviderDetail } from "./eip6963.advanced";
|
|
3
|
+
/**
|
|
4
|
+
* Class representing an EVM signer that extends SignerEvm from @ckb-ccc/core.
|
|
5
|
+
* @class
|
|
6
|
+
* @extends {ccc.SignerEvm}
|
|
7
|
+
*/
|
|
3
8
|
export declare class Signer extends ccc.SignerEvm {
|
|
4
9
|
readonly detail: EIP6963ProviderDetail;
|
|
10
|
+
/**
|
|
11
|
+
* Creates an instance of Signer.
|
|
12
|
+
* @param {ccc.Client} client - The client instance.
|
|
13
|
+
* @param {EIP6963ProviderDetail} detail - The provider detail.
|
|
14
|
+
*/
|
|
5
15
|
constructor(client: ccc.Client, detail: EIP6963ProviderDetail);
|
|
6
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Gets the EVM account address.
|
|
18
|
+
* @returns {Promise<string>} A promise that resolves to the EVM account address.
|
|
19
|
+
*/
|
|
7
20
|
getEvmAccount(): Promise<`0x${string}`>;
|
|
21
|
+
/**
|
|
22
|
+
* Connects to the provider by requesting accounts.
|
|
23
|
+
* @returns {Promise<void>} A promise that resolves when the connection is established.
|
|
24
|
+
*/
|
|
8
25
|
connect(): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Checks if the provider is connected.
|
|
28
|
+
* @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
|
|
29
|
+
*/
|
|
9
30
|
isConnected(): Promise<boolean>;
|
|
31
|
+
/**
|
|
32
|
+
* Signs a raw message with the personal account.
|
|
33
|
+
* @param {string | ccc.BytesLike} message - The message to sign.
|
|
34
|
+
* @returns {Promise<ccc.Hex>} A promise that resolves to the signed message.
|
|
35
|
+
*/
|
|
10
36
|
signMessageRaw(message: string | ccc.BytesLike): Promise<ccc.Hex>;
|
|
11
37
|
}
|
|
12
38
|
//# sourceMappingURL=signer.d.ts.map
|
package/dist/signer.d.ts.map
CHANGED
|
@@ -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,oBAAoB,CAAC;AAE7E,qBAAa,MAAO,SAAQ,GAAG,CAAC,SAAS;
|
|
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,oBAAoB,CAAC;AAE7E;;;;GAIG;AACH,qBAAa,MAAO,SAAQ,GAAG,CAAC,SAAS;aAQrB,MAAM,EAAE,qBAAqB;IAP/C;;;;OAIG;gBAED,MAAM,EAAE,GAAG,CAAC,MAAM,EACF,MAAM,EAAE,qBAAqB;IAK/C;;;OAGG;IACG,aAAa;IAInB;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAI9B;;;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;CAUxE"}
|
package/dist/signer.js
CHANGED
|
@@ -1,22 +1,46 @@
|
|
|
1
1
|
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
/**
|
|
3
|
+
* Class representing an EVM signer that extends SignerEvm from @ckb-ccc/core.
|
|
4
|
+
* @class
|
|
5
|
+
* @extends {ccc.SignerEvm}
|
|
6
|
+
*/
|
|
2
7
|
export class Signer extends ccc.SignerEvm {
|
|
8
|
+
/**
|
|
9
|
+
* Creates an instance of Signer.
|
|
10
|
+
* @param {ccc.Client} client - The client instance.
|
|
11
|
+
* @param {EIP6963ProviderDetail} detail - The provider detail.
|
|
12
|
+
*/
|
|
3
13
|
constructor(client, detail) {
|
|
4
14
|
super(client);
|
|
5
15
|
this.detail = detail;
|
|
6
16
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Gets the EVM account address.
|
|
19
|
+
* @returns {Promise<string>} A promise that resolves to the EVM account address.
|
|
20
|
+
*/
|
|
10
21
|
async getEvmAccount() {
|
|
11
22
|
return (await this.detail.provider.request({ method: "eth_accounts" }))[0];
|
|
12
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Connects to the provider by requesting accounts.
|
|
26
|
+
* @returns {Promise<void>} A promise that resolves when the connection is established.
|
|
27
|
+
*/
|
|
13
28
|
async connect() {
|
|
14
29
|
await this.detail.provider.request({ method: "eth_requestAccounts" });
|
|
15
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Checks if the provider is connected.
|
|
33
|
+
* @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
|
|
34
|
+
*/
|
|
16
35
|
async isConnected() {
|
|
17
36
|
return ((await this.detail.provider.request({ method: "eth_accounts" }))
|
|
18
37
|
.length !== 0);
|
|
19
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Signs a raw message with the personal account.
|
|
41
|
+
* @param {string | ccc.BytesLike} message - The message to sign.
|
|
42
|
+
* @returns {Promise<ccc.Hex>} A promise that resolves to the signed message.
|
|
43
|
+
*/
|
|
20
44
|
async signMessageRaw(message) {
|
|
21
45
|
const challenge = typeof message === "string" ? ccc.bytesFrom(message, "utf8") : message;
|
|
22
46
|
const address = await this.getEvmAccount();
|
package/dist/signersFactory.d.ts
CHANGED
|
@@ -1,9 +1,22 @@
|
|
|
1
1
|
import { ccc } from "@ckb-ccc/core";
|
|
2
2
|
import { Signer as EIP6963Signer } from "./signer";
|
|
3
|
+
/**
|
|
4
|
+
* Class representing a factory for creating and managing Signer instances.
|
|
5
|
+
* @class
|
|
6
|
+
*/
|
|
3
7
|
export declare class SignerFactory {
|
|
4
8
|
private readonly client;
|
|
5
9
|
private readonly existedUuids;
|
|
10
|
+
/**
|
|
11
|
+
* Creates an instance of SignerFactory.
|
|
12
|
+
* @param {ccc.Client} client - The client instance.
|
|
13
|
+
*/
|
|
6
14
|
constructor(client: ccc.Client);
|
|
15
|
+
/**
|
|
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.
|
|
19
|
+
*/
|
|
7
20
|
subscribeSigners(callback: (newSigner: EIP6963Signer) => unknown): () => void;
|
|
8
21
|
}
|
|
9
22
|
//# 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,UAAU,CAAC;AAEnD,qBAAa,aAAa;
|
|
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,UAAU,CAAC;AAEnD;;;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"}
|
package/dist/signersFactory.js
CHANGED
|
@@ -1,14 +1,27 @@
|
|
|
1
1
|
import { Signer as EIP6963Signer } from "./signer";
|
|
2
|
+
/**
|
|
3
|
+
* Class representing a factory for creating and managing Signer instances.
|
|
4
|
+
* @class
|
|
5
|
+
*/
|
|
2
6
|
export class SignerFactory {
|
|
7
|
+
/**
|
|
8
|
+
* Creates an instance of SignerFactory.
|
|
9
|
+
* @param {ccc.Client} client - The client instance.
|
|
10
|
+
*/
|
|
3
11
|
constructor(client) {
|
|
4
12
|
this.client = client;
|
|
5
13
|
this.existedUuids = [];
|
|
6
14
|
}
|
|
15
|
+
/**
|
|
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.
|
|
19
|
+
*/
|
|
7
20
|
subscribeSigners(callback) {
|
|
8
21
|
const onNewProvider = (event) => {
|
|
9
22
|
const { detail } = event;
|
|
10
23
|
const { uuid } = detail.info;
|
|
11
|
-
if (this.existedUuids.
|
|
24
|
+
if (this.existedUuids.includes(uuid)) {
|
|
12
25
|
return;
|
|
13
26
|
}
|
|
14
27
|
this.existedUuids.push(uuid);
|
|
@@ -1,28 +1,88 @@
|
|
|
1
1
|
import { Hex } from "@ckb-ccc/core";
|
|
2
|
+
/**
|
|
3
|
+
* Interface representing a provider for interacting with Ethereum-compatible wallets.
|
|
4
|
+
* @interface
|
|
5
|
+
*/
|
|
2
6
|
export interface Provider {
|
|
7
|
+
/**
|
|
8
|
+
* Sends a request to the provider.
|
|
9
|
+
* @type {RequestMethod}
|
|
10
|
+
*/
|
|
3
11
|
request: RequestMethod;
|
|
12
|
+
/**
|
|
13
|
+
* Adds an event listener to the provider.
|
|
14
|
+
* @type {OnMethod}
|
|
15
|
+
*/
|
|
4
16
|
on: OnMethod;
|
|
17
|
+
/**
|
|
18
|
+
* Removes an event listener from the provider.
|
|
19
|
+
* @param {string} eventName - The name of the event to remove the listener from.
|
|
20
|
+
* @param {(...args: unknown[]) => unknown} listener - The listener function to remove.
|
|
21
|
+
* @returns {Provider} The provider instance.
|
|
22
|
+
*/
|
|
5
23
|
removeListener(eventName: string, listener: (...args: unknown[]) => unknown): Provider;
|
|
6
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Interface representing a method to send requests to the provider.
|
|
27
|
+
* @interface
|
|
28
|
+
*/
|
|
7
29
|
export interface RequestMethod {
|
|
30
|
+
/**
|
|
31
|
+
* Signs a message with the personal account.
|
|
32
|
+
* @param {object} request - The request object.
|
|
33
|
+
* @param {"personal_sign"} request.method - The method name.
|
|
34
|
+
* @param {[string, Hex]} request.params - The method parameters.
|
|
35
|
+
* @returns {Promise<Hex>} A promise that resolves to the signed message.
|
|
36
|
+
*/
|
|
8
37
|
(request: {
|
|
9
38
|
method: "personal_sign";
|
|
10
39
|
params: [string, Hex];
|
|
11
40
|
}): Promise<Hex>;
|
|
41
|
+
/**
|
|
42
|
+
* Requests the accounts from the provider.
|
|
43
|
+
* @param {object} request - The request object.
|
|
44
|
+
* @param {"eth_requestAccounts"} request.method - The method name.
|
|
45
|
+
* @param {undefined} [request.params] - The optional method parameters.
|
|
46
|
+
* @returns {Promise<Hex[]>} A promise that resolves to an array of account addresses.
|
|
47
|
+
*/
|
|
12
48
|
(request: {
|
|
13
49
|
method: "eth_requestAccounts";
|
|
14
50
|
params?: undefined;
|
|
15
51
|
}): Promise<Hex[]>;
|
|
52
|
+
/**
|
|
53
|
+
* Gets the accounts from the provider.
|
|
54
|
+
* @param {object} request - The request object.
|
|
55
|
+
* @param {"eth_accounts"} request.method - The method name.
|
|
56
|
+
* @param {undefined} [request.params] - The optional method parameters.
|
|
57
|
+
* @returns {Promise<Hex[]>} A promise that resolves to an array of account addresses.
|
|
58
|
+
*/
|
|
16
59
|
(request: {
|
|
17
60
|
method: "eth_accounts";
|
|
18
61
|
params?: undefined;
|
|
19
62
|
}): Promise<Hex[]>;
|
|
63
|
+
/**
|
|
64
|
+
* Sends a generic request to the provider.
|
|
65
|
+
* @param {object} request - The request object.
|
|
66
|
+
* @param {string} request.method - The method name.
|
|
67
|
+
* @param {Array<unknown> | Record<string, unknown>} [request.params] - The optional method parameters.
|
|
68
|
+
* @returns {Promise<unknown>} A promise that resolves to the response from the provider.
|
|
69
|
+
*/
|
|
20
70
|
(request: {
|
|
21
71
|
method: string;
|
|
22
72
|
params?: Array<unknown> | Record<string, unknown>;
|
|
23
73
|
}): Promise<unknown>;
|
|
24
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Interface representing a method to add event listeners to the provider.
|
|
77
|
+
* @interface
|
|
78
|
+
*/
|
|
25
79
|
export interface OnMethod {
|
|
80
|
+
/**
|
|
81
|
+
* Adds an event listener to the provider.
|
|
82
|
+
* @param {string} eventName - The name of the event.
|
|
83
|
+
* @param {(...args: unknown[]) => unknown} listener - The listener function.
|
|
84
|
+
* @returns {Provider} The provider instance.
|
|
85
|
+
*/
|
|
26
86
|
(eventName: string, listener: (...args: unknown[]) => unknown): Provider;
|
|
27
87
|
}
|
|
28
88
|
//# sourceMappingURL=eip1193.advanced.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eip1193.advanced.d.ts","sourceRoot":"","sources":["../src/eip1193.advanced.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEpC,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"eip1193.advanced.d.ts","sourceRoot":"","sources":["../src/eip1193.advanced.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEpC;;;GAGG;AACH,MAAM,WAAW,QAAQ;IACvB;;;OAGG;IACH,OAAO,EAAE,aAAa,CAAC;IAEvB;;;OAGG;IACH,EAAE,EAAE,QAAQ,CAAC;IAEb;;;;;OAKG;IACH,cAAc,CACZ,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,GACxC,QAAQ,CAAC;CACb;AAED;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B;;;;;;OAMG;IACH,CAAC,OAAO,EAAE;QAAE,MAAM,EAAE,eAAe,CAAC;QAAC,MAAM,EAAE,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;KAAE,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IAE5E;;;;;;OAMG;IACH,CAAC,OAAO,EAAE;QACR,MAAM,EAAE,qBAAqB,CAAC;QAC9B,MAAM,CAAC,EAAE,SAAS,CAAC;KACpB,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IAEnB;;;;;;OAMG;IACH,CAAC,OAAO,EAAE;QAAE,MAAM,EAAE,cAAc,CAAC;QAAC,MAAM,CAAC,EAAE,SAAS,CAAA;KAAE,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IAE1E;;;;;;OAMG;IACH,CAAC,OAAO,EAAE;QACR,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACnD,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACtB;AAED;;;GAGG;AACH,MAAM,WAAW,QAAQ;IACvB;;;;;OAKG;IACH,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,GAAG,QAAQ,CAAC;CAC1E"}
|
|
@@ -1,15 +1,55 @@
|
|
|
1
1
|
import { Provider as EIP1193Provider } from "./eip1193.advanced";
|
|
2
|
+
/**
|
|
3
|
+
* Interface representing an event announcing a provider.
|
|
4
|
+
* @interface
|
|
5
|
+
*/
|
|
2
6
|
export interface AnnounceProviderEvent {
|
|
7
|
+
/**
|
|
8
|
+
* The detail of the provider.
|
|
9
|
+
* @type {ProviderDetail}
|
|
10
|
+
*/
|
|
3
11
|
detail: ProviderDetail;
|
|
4
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Interface representing the details of a provider.
|
|
15
|
+
* @interface
|
|
16
|
+
*/
|
|
5
17
|
export interface ProviderDetail {
|
|
18
|
+
/**
|
|
19
|
+
* The information about the provider.
|
|
20
|
+
* @type {ProviderInfo}
|
|
21
|
+
*/
|
|
6
22
|
info: ProviderInfo;
|
|
23
|
+
/**
|
|
24
|
+
* The provider instance compliant with EIP-1193.
|
|
25
|
+
* @type {EIP1193Provider}
|
|
26
|
+
*/
|
|
7
27
|
provider: EIP1193Provider;
|
|
8
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Interface representing information about a provider.
|
|
31
|
+
* @interface
|
|
32
|
+
*/
|
|
9
33
|
export interface ProviderInfo {
|
|
34
|
+
/**
|
|
35
|
+
* The reverse DNS name of the provider.
|
|
36
|
+
* @type {string}
|
|
37
|
+
*/
|
|
10
38
|
rdns: string;
|
|
39
|
+
/**
|
|
40
|
+
* The UUID of the provider.
|
|
41
|
+
* @type {string}
|
|
42
|
+
*/
|
|
11
43
|
uuid: string;
|
|
44
|
+
/**
|
|
45
|
+
* The name of the provider.
|
|
46
|
+
* @type {string}
|
|
47
|
+
*/
|
|
12
48
|
name: string;
|
|
49
|
+
/**
|
|
50
|
+
* The icon URL of the provider.
|
|
51
|
+
* @type {string}
|
|
52
|
+
*/
|
|
13
53
|
icon: string;
|
|
14
54
|
}
|
|
15
55
|
//# sourceMappingURL=eip6963.advanced.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eip6963.advanced.d.ts","sourceRoot":"","sources":["../src/eip6963.advanced.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAEjE,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,cAAc,CAAC;CACxB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"eip6963.advanced.d.ts","sourceRoot":"","sources":["../src/eip6963.advanced.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAEjE;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,MAAM,EAAE,cAAc,CAAC;CACxB;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,IAAI,EAAE,YAAY,CAAC;IAEnB;;;OAGG;IACH,QAAQ,EAAE,eAAe,CAAC;CAC3B;AAED;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;CACd"}
|
|
@@ -1,12 +1,38 @@
|
|
|
1
1
|
import { ccc } from "@ckb-ccc/core";
|
|
2
2
|
import { ProviderDetail as EIP6963ProviderDetail } from "./eip6963.advanced";
|
|
3
|
+
/**
|
|
4
|
+
* Class representing an EVM signer that extends SignerEvm from @ckb-ccc/core.
|
|
5
|
+
* @class
|
|
6
|
+
* @extends {ccc.SignerEvm}
|
|
7
|
+
*/
|
|
3
8
|
export declare class Signer extends ccc.SignerEvm {
|
|
4
9
|
readonly detail: EIP6963ProviderDetail;
|
|
10
|
+
/**
|
|
11
|
+
* Creates an instance of Signer.
|
|
12
|
+
* @param {ccc.Client} client - The client instance.
|
|
13
|
+
* @param {EIP6963ProviderDetail} detail - The provider detail.
|
|
14
|
+
*/
|
|
5
15
|
constructor(client: ccc.Client, detail: EIP6963ProviderDetail);
|
|
6
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Gets the EVM account address.
|
|
18
|
+
* @returns {Promise<string>} A promise that resolves to the EVM account address.
|
|
19
|
+
*/
|
|
7
20
|
getEvmAccount(): Promise<`0x${string}`>;
|
|
21
|
+
/**
|
|
22
|
+
* Connects to the provider by requesting accounts.
|
|
23
|
+
* @returns {Promise<void>} A promise that resolves when the connection is established.
|
|
24
|
+
*/
|
|
8
25
|
connect(): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Checks if the provider is connected.
|
|
28
|
+
* @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
|
|
29
|
+
*/
|
|
9
30
|
isConnected(): Promise<boolean>;
|
|
31
|
+
/**
|
|
32
|
+
* Signs a raw message with the personal account.
|
|
33
|
+
* @param {string | ccc.BytesLike} message - The message to sign.
|
|
34
|
+
* @returns {Promise<ccc.Hex>} A promise that resolves to the signed message.
|
|
35
|
+
*/
|
|
10
36
|
signMessageRaw(message: string | ccc.BytesLike): Promise<ccc.Hex>;
|
|
11
37
|
}
|
|
12
38
|
//# sourceMappingURL=signer.d.ts.map
|
|
@@ -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,oBAAoB,CAAC;AAE7E,qBAAa,MAAO,SAAQ,GAAG,CAAC,SAAS;
|
|
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,oBAAoB,CAAC;AAE7E;;;;GAIG;AACH,qBAAa,MAAO,SAAQ,GAAG,CAAC,SAAS;aAQrB,MAAM,EAAE,qBAAqB;IAP/C;;;;OAIG;gBAED,MAAM,EAAE,GAAG,CAAC,MAAM,EACF,MAAM,EAAE,qBAAqB;IAK/C;;;OAGG;IACG,aAAa;IAInB;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAI9B;;;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;CAUxE"}
|
package/dist.commonjs/signer.js
CHANGED
|
@@ -2,24 +2,48 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Signer = void 0;
|
|
4
4
|
const core_1 = require("@ckb-ccc/core");
|
|
5
|
+
/**
|
|
6
|
+
* Class representing an EVM signer that extends SignerEvm from @ckb-ccc/core.
|
|
7
|
+
* @class
|
|
8
|
+
* @extends {ccc.SignerEvm}
|
|
9
|
+
*/
|
|
5
10
|
class Signer extends core_1.ccc.SignerEvm {
|
|
11
|
+
/**
|
|
12
|
+
* Creates an instance of Signer.
|
|
13
|
+
* @param {ccc.Client} client - The client instance.
|
|
14
|
+
* @param {EIP6963ProviderDetail} detail - The provider detail.
|
|
15
|
+
*/
|
|
6
16
|
constructor(client, detail) {
|
|
7
17
|
super(client);
|
|
8
18
|
this.detail = detail;
|
|
9
19
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Gets the EVM account address.
|
|
22
|
+
* @returns {Promise<string>} A promise that resolves to the EVM account address.
|
|
23
|
+
*/
|
|
13
24
|
async getEvmAccount() {
|
|
14
25
|
return (await this.detail.provider.request({ method: "eth_accounts" }))[0];
|
|
15
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Connects to the provider by requesting accounts.
|
|
29
|
+
* @returns {Promise<void>} A promise that resolves when the connection is established.
|
|
30
|
+
*/
|
|
16
31
|
async connect() {
|
|
17
32
|
await this.detail.provider.request({ method: "eth_requestAccounts" });
|
|
18
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Checks if the provider is connected.
|
|
36
|
+
* @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
|
|
37
|
+
*/
|
|
19
38
|
async isConnected() {
|
|
20
39
|
return ((await this.detail.provider.request({ method: "eth_accounts" }))
|
|
21
40
|
.length !== 0);
|
|
22
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Signs a raw message with the personal account.
|
|
44
|
+
* @param {string | ccc.BytesLike} message - The message to sign.
|
|
45
|
+
* @returns {Promise<ccc.Hex>} A promise that resolves to the signed message.
|
|
46
|
+
*/
|
|
23
47
|
async signMessageRaw(message) {
|
|
24
48
|
const challenge = typeof message === "string" ? core_1.ccc.bytesFrom(message, "utf8") : message;
|
|
25
49
|
const address = await this.getEvmAccount();
|
|
@@ -1,9 +1,22 @@
|
|
|
1
1
|
import { ccc } from "@ckb-ccc/core";
|
|
2
2
|
import { Signer as EIP6963Signer } from "./signer";
|
|
3
|
+
/**
|
|
4
|
+
* Class representing a factory for creating and managing Signer instances.
|
|
5
|
+
* @class
|
|
6
|
+
*/
|
|
3
7
|
export declare class SignerFactory {
|
|
4
8
|
private readonly client;
|
|
5
9
|
private readonly existedUuids;
|
|
10
|
+
/**
|
|
11
|
+
* Creates an instance of SignerFactory.
|
|
12
|
+
* @param {ccc.Client} client - The client instance.
|
|
13
|
+
*/
|
|
6
14
|
constructor(client: ccc.Client);
|
|
15
|
+
/**
|
|
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.
|
|
19
|
+
*/
|
|
7
20
|
subscribeSigners(callback: (newSigner: EIP6963Signer) => unknown): () => void;
|
|
8
21
|
}
|
|
9
22
|
//# 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,UAAU,CAAC;AAEnD,qBAAa,aAAa;
|
|
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,UAAU,CAAC;AAEnD;;;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"}
|
|
@@ -2,16 +2,29 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SignerFactory = void 0;
|
|
4
4
|
const signer_1 = require("./signer");
|
|
5
|
+
/**
|
|
6
|
+
* Class representing a factory for creating and managing Signer instances.
|
|
7
|
+
* @class
|
|
8
|
+
*/
|
|
5
9
|
class SignerFactory {
|
|
10
|
+
/**
|
|
11
|
+
* Creates an instance of SignerFactory.
|
|
12
|
+
* @param {ccc.Client} client - The client instance.
|
|
13
|
+
*/
|
|
6
14
|
constructor(client) {
|
|
7
15
|
this.client = client;
|
|
8
16
|
this.existedUuids = [];
|
|
9
17
|
}
|
|
18
|
+
/**
|
|
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.
|
|
22
|
+
*/
|
|
10
23
|
subscribeSigners(callback) {
|
|
11
24
|
const onNewProvider = (event) => {
|
|
12
25
|
const { detail } = event;
|
|
13
26
|
const { uuid } = detail.info;
|
|
14
|
-
if (this.existedUuids.
|
|
27
|
+
if (this.existedUuids.includes(uuid)) {
|
|
15
28
|
return;
|
|
16
29
|
}
|
|
17
30
|
this.existedUuids.push(uuid);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ckb-ccc/eip6963",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6-alpha.0",
|
|
4
4
|
"description": "Common Chains Connector's support for EIP6963",
|
|
5
5
|
"author": "Hanssen0 <hanssen0@hanssen0.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"access": "public"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@ckb-ccc/core": "0.0.
|
|
45
|
+
"@ckb-ccc/core": "0.0.6-alpha.0"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "2cbb4f450ed88e773a353a13ad006dbe6208f67f"
|
|
48
48
|
}
|
package/src/eip1193.advanced.ts
CHANGED
|
@@ -1,27 +1,92 @@
|
|
|
1
1
|
import { Hex } from "@ckb-ccc/core";
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Interface representing a provider for interacting with Ethereum-compatible wallets.
|
|
5
|
+
* @interface
|
|
6
|
+
*/
|
|
3
7
|
export interface Provider {
|
|
8
|
+
/**
|
|
9
|
+
* Sends a request to the provider.
|
|
10
|
+
* @type {RequestMethod}
|
|
11
|
+
*/
|
|
4
12
|
request: RequestMethod;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Adds an event listener to the provider.
|
|
16
|
+
* @type {OnMethod}
|
|
17
|
+
*/
|
|
5
18
|
on: OnMethod;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Removes an event listener from the provider.
|
|
22
|
+
* @param {string} eventName - The name of the event to remove the listener from.
|
|
23
|
+
* @param {(...args: unknown[]) => unknown} listener - The listener function to remove.
|
|
24
|
+
* @returns {Provider} The provider instance.
|
|
25
|
+
*/
|
|
6
26
|
removeListener(
|
|
7
27
|
eventName: string,
|
|
8
28
|
listener: (...args: unknown[]) => unknown,
|
|
9
29
|
): Provider;
|
|
10
30
|
}
|
|
11
31
|
|
|
32
|
+
/**
|
|
33
|
+
* Interface representing a method to send requests to the provider.
|
|
34
|
+
* @interface
|
|
35
|
+
*/
|
|
12
36
|
export interface RequestMethod {
|
|
37
|
+
/**
|
|
38
|
+
* Signs a message with the personal account.
|
|
39
|
+
* @param {object} request - The request object.
|
|
40
|
+
* @param {"personal_sign"} request.method - The method name.
|
|
41
|
+
* @param {[string, Hex]} request.params - The method parameters.
|
|
42
|
+
* @returns {Promise<Hex>} A promise that resolves to the signed message.
|
|
43
|
+
*/
|
|
13
44
|
(request: { method: "personal_sign"; params: [string, Hex] }): Promise<Hex>;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Requests the accounts from the provider.
|
|
48
|
+
* @param {object} request - The request object.
|
|
49
|
+
* @param {"eth_requestAccounts"} request.method - The method name.
|
|
50
|
+
* @param {undefined} [request.params] - The optional method parameters.
|
|
51
|
+
* @returns {Promise<Hex[]>} A promise that resolves to an array of account addresses.
|
|
52
|
+
*/
|
|
14
53
|
(request: {
|
|
15
54
|
method: "eth_requestAccounts";
|
|
16
55
|
params?: undefined;
|
|
17
56
|
}): Promise<Hex[]>;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Gets the accounts from the provider.
|
|
60
|
+
* @param {object} request - The request object.
|
|
61
|
+
* @param {"eth_accounts"} request.method - The method name.
|
|
62
|
+
* @param {undefined} [request.params] - The optional method parameters.
|
|
63
|
+
* @returns {Promise<Hex[]>} A promise that resolves to an array of account addresses.
|
|
64
|
+
*/
|
|
18
65
|
(request: { method: "eth_accounts"; params?: undefined }): Promise<Hex[]>;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Sends a generic request to the provider.
|
|
69
|
+
* @param {object} request - The request object.
|
|
70
|
+
* @param {string} request.method - The method name.
|
|
71
|
+
* @param {Array<unknown> | Record<string, unknown>} [request.params] - The optional method parameters.
|
|
72
|
+
* @returns {Promise<unknown>} A promise that resolves to the response from the provider.
|
|
73
|
+
*/
|
|
19
74
|
(request: {
|
|
20
75
|
method: string;
|
|
21
76
|
params?: Array<unknown> | Record<string, unknown>;
|
|
22
77
|
}): Promise<unknown>;
|
|
23
78
|
}
|
|
24
79
|
|
|
80
|
+
/**
|
|
81
|
+
* Interface representing a method to add event listeners to the provider.
|
|
82
|
+
* @interface
|
|
83
|
+
*/
|
|
25
84
|
export interface OnMethod {
|
|
85
|
+
/**
|
|
86
|
+
* Adds an event listener to the provider.
|
|
87
|
+
* @param {string} eventName - The name of the event.
|
|
88
|
+
* @param {(...args: unknown[]) => unknown} listener - The listener function.
|
|
89
|
+
* @returns {Provider} The provider instance.
|
|
90
|
+
*/
|
|
26
91
|
(eventName: string, listener: (...args: unknown[]) => unknown): Provider;
|
|
27
92
|
}
|
package/src/eip6963.advanced.ts
CHANGED
|
@@ -1,17 +1,61 @@
|
|
|
1
1
|
import { Provider as EIP1193Provider } from "./eip1193.advanced";
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Interface representing an event announcing a provider.
|
|
5
|
+
* @interface
|
|
6
|
+
*/
|
|
3
7
|
export interface AnnounceProviderEvent {
|
|
8
|
+
/**
|
|
9
|
+
* The detail of the provider.
|
|
10
|
+
* @type {ProviderDetail}
|
|
11
|
+
*/
|
|
4
12
|
detail: ProviderDetail;
|
|
5
13
|
}
|
|
6
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Interface representing the details of a provider.
|
|
17
|
+
* @interface
|
|
18
|
+
*/
|
|
7
19
|
export interface ProviderDetail {
|
|
20
|
+
/**
|
|
21
|
+
* The information about the provider.
|
|
22
|
+
* @type {ProviderInfo}
|
|
23
|
+
*/
|
|
8
24
|
info: ProviderInfo;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The provider instance compliant with EIP-1193.
|
|
28
|
+
* @type {EIP1193Provider}
|
|
29
|
+
*/
|
|
9
30
|
provider: EIP1193Provider;
|
|
10
31
|
}
|
|
11
32
|
|
|
33
|
+
/**
|
|
34
|
+
* Interface representing information about a provider.
|
|
35
|
+
* @interface
|
|
36
|
+
*/
|
|
12
37
|
export interface ProviderInfo {
|
|
38
|
+
/**
|
|
39
|
+
* The reverse DNS name of the provider.
|
|
40
|
+
* @type {string}
|
|
41
|
+
*/
|
|
13
42
|
rdns: string;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The UUID of the provider.
|
|
46
|
+
* @type {string}
|
|
47
|
+
*/
|
|
14
48
|
uuid: string;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The name of the provider.
|
|
52
|
+
* @type {string}
|
|
53
|
+
*/
|
|
15
54
|
name: string;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The icon URL of the provider.
|
|
58
|
+
* @type {string}
|
|
59
|
+
*/
|
|
16
60
|
icon: string;
|
|
17
61
|
}
|
package/src/signer.ts
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
import { ccc } from "@ckb-ccc/core";
|
|
2
2
|
import { ProviderDetail as EIP6963ProviderDetail } from "./eip6963.advanced";
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Class representing an EVM signer that extends SignerEvm from @ckb-ccc/core.
|
|
6
|
+
* @class
|
|
7
|
+
* @extends {ccc.SignerEvm}
|
|
8
|
+
*/
|
|
4
9
|
export class Signer extends ccc.SignerEvm {
|
|
10
|
+
/**
|
|
11
|
+
* Creates an instance of Signer.
|
|
12
|
+
* @param {ccc.Client} client - The client instance.
|
|
13
|
+
* @param {EIP6963ProviderDetail} detail - The provider detail.
|
|
14
|
+
*/
|
|
5
15
|
constructor(
|
|
6
16
|
client: ccc.Client,
|
|
7
17
|
public readonly detail: EIP6963ProviderDetail,
|
|
@@ -9,18 +19,26 @@ export class Signer extends ccc.SignerEvm {
|
|
|
9
19
|
super(client);
|
|
10
20
|
}
|
|
11
21
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Gets the EVM account address.
|
|
24
|
+
* @returns {Promise<string>} A promise that resolves to the EVM account address.
|
|
25
|
+
*/
|
|
16
26
|
async getEvmAccount() {
|
|
17
27
|
return (await this.detail.provider.request({ method: "eth_accounts" }))[0];
|
|
18
28
|
}
|
|
19
29
|
|
|
30
|
+
/**
|
|
31
|
+
* Connects to the provider by requesting accounts.
|
|
32
|
+
* @returns {Promise<void>} A promise that resolves when the connection is established.
|
|
33
|
+
*/
|
|
20
34
|
async connect(): Promise<void> {
|
|
21
35
|
await this.detail.provider.request({ method: "eth_requestAccounts" });
|
|
22
36
|
}
|
|
23
37
|
|
|
38
|
+
/**
|
|
39
|
+
* Checks if the provider is connected.
|
|
40
|
+
* @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
|
|
41
|
+
*/
|
|
24
42
|
async isConnected(): Promise<boolean> {
|
|
25
43
|
return (
|
|
26
44
|
(await this.detail.provider.request({ method: "eth_accounts" }))
|
|
@@ -28,6 +46,11 @@ export class Signer extends ccc.SignerEvm {
|
|
|
28
46
|
);
|
|
29
47
|
}
|
|
30
48
|
|
|
49
|
+
/**
|
|
50
|
+
* Signs a raw message with the personal account.
|
|
51
|
+
* @param {string | ccc.BytesLike} message - The message to sign.
|
|
52
|
+
* @returns {Promise<ccc.Hex>} A promise that resolves to the signed message.
|
|
53
|
+
*/
|
|
31
54
|
async signMessageRaw(message: string | ccc.BytesLike): Promise<ccc.Hex> {
|
|
32
55
|
const challenge =
|
|
33
56
|
typeof message === "string" ? ccc.bytesFrom(message, "utf8") : message;
|
package/src/signersFactory.ts
CHANGED
|
@@ -2,17 +2,32 @@ import { ccc } from "@ckb-ccc/core";
|
|
|
2
2
|
import { AnnounceProviderEvent as EIP6963AnnounceProviderEvent } from "./eip6963.advanced";
|
|
3
3
|
import { Signer as EIP6963Signer } from "./signer";
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Class representing a factory for creating and managing Signer instances.
|
|
7
|
+
* @class
|
|
8
|
+
*/
|
|
5
9
|
export class SignerFactory {
|
|
6
10
|
private readonly existedUuids: string[] = [];
|
|
7
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Creates an instance of SignerFactory.
|
|
14
|
+
* @param {ccc.Client} client - The client instance.
|
|
15
|
+
*/
|
|
8
16
|
constructor(private readonly client: ccc.Client) {}
|
|
9
17
|
|
|
10
|
-
|
|
18
|
+
/**
|
|
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.
|
|
22
|
+
*/
|
|
23
|
+
subscribeSigners(
|
|
24
|
+
callback: (newSigner: EIP6963Signer) => unknown,
|
|
25
|
+
): () => void {
|
|
11
26
|
const onNewProvider = (event: Event) => {
|
|
12
27
|
const { detail } = event as unknown as EIP6963AnnounceProviderEvent;
|
|
13
28
|
const { uuid } = detail.info;
|
|
14
29
|
|
|
15
|
-
if (this.existedUuids.
|
|
30
|
+
if (this.existedUuids.includes(uuid)) {
|
|
16
31
|
return;
|
|
17
32
|
}
|
|
18
33
|
|
|
@@ -23,6 +38,7 @@ export class SignerFactory {
|
|
|
23
38
|
|
|
24
39
|
window.addEventListener("eip6963:announceProvider", onNewProvider);
|
|
25
40
|
window.dispatchEvent(new Event("eip6963:requestProvider"));
|
|
41
|
+
|
|
26
42
|
return () =>
|
|
27
43
|
window.removeEventListener("eip6963:announceProvider", onNewProvider);
|
|
28
44
|
}
|