@ckb-ccc/eip6963 0.0.7-alpha.2 → 0.0.8-alpha.3
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/README.md +6 -4
- package/dist.commonjs/advanced.d.ts +1 -1
- package/dist.commonjs/advanced.js +40 -19
- package/dist.commonjs/barrel.d.ts +1 -1
- package/dist.commonjs/barrel.js +30 -14
- package/dist.commonjs/eip1193.advanced.d.ts +66 -69
- package/dist.commonjs/eip6963.advanced.d.ts +36 -36
- package/dist.commonjs/index.d.ts +1 -1
- package/dist.commonjs/index.js +40 -19
- package/dist.commonjs/signer.d.ts +29 -29
- package/dist.commonjs/signer.js +49 -44
- package/dist.commonjs/signersFactory.d.ts +14 -14
- package/dist.commonjs/signersFactory.js +29 -28
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -21,11 +21,13 @@
|
|
|
21
21
|
</p>
|
|
22
22
|
|
|
23
23
|
<p align="center">
|
|
24
|
-
"
|
|
24
|
+
"CCC - CKBers' Codebase" is the next step of "Common Chains Connector".
|
|
25
25
|
<br />
|
|
26
|
-
|
|
26
|
+
Empower yourself with CCC to discover the unlimited potential of CKB.
|
|
27
27
|
<br />
|
|
28
|
-
|
|
28
|
+
Interoperate with wallets from different chain ecosystems.
|
|
29
|
+
<br />
|
|
30
|
+
Fully enabling CKB's Turing completeness and cryptographic freedom power.
|
|
29
31
|
</p>
|
|
30
32
|
|
|
31
33
|
## Preview
|
|
@@ -36,7 +38,7 @@
|
|
|
36
38
|
</a>
|
|
37
39
|
</p>
|
|
38
40
|
|
|
39
|
-
This project is still under active development, and we are looking forward to your feedback. [Try its demo now here](https://ckbccc-demo.vercel.app/).
|
|
41
|
+
This project is still under active development, and we are looking forward to your feedback. [Try its demo now here](https://ckbccc-demo.vercel.app/). It showcases how to use CCC for some basic scenarios in CKB.
|
|
40
42
|
|
|
41
43
|
<h3 align="center">
|
|
42
44
|
Read more about CCC on its <a href="https://github.com/ckb-ecofund/ccc">GitHub Repo</a>.
|
|
@@ -1,27 +1,48 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
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)
|
|
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.Eip6963A = exports.Eip1193A = void 0;
|
|
27
48
|
exports.Eip1193A = __importStar(require("./eip1193.advanced"));
|
package/dist.commonjs/barrel.js
CHANGED
|
@@ -1,18 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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 __exportStar =
|
|
26
|
+
(this && this.__exportStar) ||
|
|
27
|
+
function (m, exports) {
|
|
28
|
+
for (var p in m)
|
|
29
|
+
if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p))
|
|
30
|
+
__createBinding(exports, m, p);
|
|
31
|
+
};
|
|
16
32
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
33
|
__exportStar(require("./signer"), exports);
|
|
18
34
|
__exportStar(require("./signersFactory"), exports);
|
|
@@ -4,85 +4,82 @@ import { Hex } from "@ckb-ccc/core";
|
|
|
4
4
|
* @interface
|
|
5
5
|
*/
|
|
6
6
|
export interface Provider {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Sends a request to the provider.
|
|
9
|
+
* @type {RequestMethod}
|
|
10
|
+
*/
|
|
11
|
+
request: RequestMethod;
|
|
12
|
+
/**
|
|
13
|
+
* Adds an event listener to the provider.
|
|
14
|
+
* @type {OnMethod}
|
|
15
|
+
*/
|
|
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
|
+
*/
|
|
23
|
+
removeListener(
|
|
24
|
+
eventName: string,
|
|
25
|
+
listener: (...args: unknown[]) => unknown,
|
|
26
|
+
): Provider;
|
|
24
27
|
}
|
|
25
28
|
/**
|
|
26
29
|
* Interface representing a method to send requests to the provider.
|
|
27
30
|
* @interface
|
|
28
31
|
*/
|
|
29
32
|
export interface RequestMethod {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
* @returns {Promise<unknown>} A promise that resolves to the response from the provider.
|
|
69
|
-
*/
|
|
70
|
-
(request: {
|
|
71
|
-
method: string;
|
|
72
|
-
params?: Array<unknown> | Record<string, unknown>;
|
|
73
|
-
}): Promise<unknown>;
|
|
33
|
+
/**
|
|
34
|
+
* Signs a message with the personal account.
|
|
35
|
+
* @param {object} request - The request object.
|
|
36
|
+
* @param {"personal_sign"} request.method - The method name.
|
|
37
|
+
* @param {[string, Hex]} request.params - The method parameters.
|
|
38
|
+
* @returns {Promise<Hex>} A promise that resolves to the signed message.
|
|
39
|
+
*/
|
|
40
|
+
(request: { method: "personal_sign"; params: [string, Hex] }): 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
|
+
*/
|
|
48
|
+
(request: {
|
|
49
|
+
method: "eth_requestAccounts";
|
|
50
|
+
params?: undefined;
|
|
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
|
+
*/
|
|
59
|
+
(request: { method: "eth_accounts"; params?: undefined }): Promise<Hex[]>;
|
|
60
|
+
/**
|
|
61
|
+
* Sends a generic request to the provider.
|
|
62
|
+
* @param {object} request - The request object.
|
|
63
|
+
* @param {string} request.method - The method name.
|
|
64
|
+
* @param {Array<unknown> | Record<string, unknown>} [request.params] - The optional method parameters.
|
|
65
|
+
* @returns {Promise<unknown>} A promise that resolves to the response from the provider.
|
|
66
|
+
*/
|
|
67
|
+
(request: {
|
|
68
|
+
method: string;
|
|
69
|
+
params?: Array<unknown> | Record<string, unknown>;
|
|
70
|
+
}): Promise<unknown>;
|
|
74
71
|
}
|
|
75
72
|
/**
|
|
76
73
|
* Interface representing a method to add event listeners to the provider.
|
|
77
74
|
* @interface
|
|
78
75
|
*/
|
|
79
76
|
export interface OnMethod {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
77
|
+
/**
|
|
78
|
+
* Adds an event listener to the provider.
|
|
79
|
+
* @param {string} eventName - The name of the event.
|
|
80
|
+
* @param {(...args: unknown[]) => unknown} listener - The listener function.
|
|
81
|
+
* @returns {Provider} The provider instance.
|
|
82
|
+
*/
|
|
83
|
+
(eventName: string, listener: (...args: unknown[]) => unknown): Provider;
|
|
87
84
|
}
|
|
88
|
-
//# sourceMappingURL=eip1193.advanced.d.ts.map
|
|
85
|
+
//# sourceMappingURL=eip1193.advanced.d.ts.map
|
|
@@ -4,52 +4,52 @@ import { Provider as EIP1193Provider } from "./eip1193.advanced";
|
|
|
4
4
|
* @interface
|
|
5
5
|
*/
|
|
6
6
|
export interface AnnounceProviderEvent {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
/**
|
|
8
|
+
* The detail of the provider.
|
|
9
|
+
* @type {ProviderDetail}
|
|
10
|
+
*/
|
|
11
|
+
detail: ProviderDetail;
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
14
|
* Interface representing the details of a provider.
|
|
15
15
|
* @interface
|
|
16
16
|
*/
|
|
17
17
|
export interface ProviderDetail {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
18
|
+
/**
|
|
19
|
+
* The information about the provider.
|
|
20
|
+
* @type {ProviderInfo}
|
|
21
|
+
*/
|
|
22
|
+
info: ProviderInfo;
|
|
23
|
+
/**
|
|
24
|
+
* The provider instance compliant with EIP-1193.
|
|
25
|
+
* @type {EIP1193Provider}
|
|
26
|
+
*/
|
|
27
|
+
provider: EIP1193Provider;
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
30
|
* Interface representing information about a provider.
|
|
31
31
|
* @interface
|
|
32
32
|
*/
|
|
33
33
|
export interface ProviderInfo {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
34
|
+
/**
|
|
35
|
+
* The reverse DNS name of the provider.
|
|
36
|
+
* @type {string}
|
|
37
|
+
*/
|
|
38
|
+
rdns: string;
|
|
39
|
+
/**
|
|
40
|
+
* The UUID of the provider.
|
|
41
|
+
* @type {string}
|
|
42
|
+
*/
|
|
43
|
+
uuid: string;
|
|
44
|
+
/**
|
|
45
|
+
* The name of the provider.
|
|
46
|
+
* @type {string}
|
|
47
|
+
*/
|
|
48
|
+
name: string;
|
|
49
|
+
/**
|
|
50
|
+
* The icon URL of the provider.
|
|
51
|
+
* @type {string}
|
|
52
|
+
*/
|
|
53
|
+
icon: string;
|
|
54
54
|
}
|
|
55
|
-
//# sourceMappingURL=eip6963.advanced.d.ts.map
|
|
55
|
+
//# sourceMappingURL=eip6963.advanced.d.ts.map
|
package/dist.commonjs/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * as Eip6963 from "./barrel";
|
|
2
|
-
//# sourceMappingURL=index.d.ts.map
|
|
2
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist.commonjs/index.js
CHANGED
|
@@ -1,27 +1,48 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
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)
|
|
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.Eip6963 = void 0;
|
|
27
48
|
exports.Eip6963 = __importStar(require("./barrel"));
|
|
@@ -6,33 +6,33 @@ import { ProviderDetail as EIP6963ProviderDetail } from "./eip6963.advanced";
|
|
|
6
6
|
* @extends {ccc.SignerEvm}
|
|
7
7
|
*/
|
|
8
8
|
export declare class Signer extends ccc.SignerEvm {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
+
*/
|
|
15
|
+
constructor(client: ccc.Client, detail: EIP6963ProviderDetail);
|
|
16
|
+
/**
|
|
17
|
+
* Gets the EVM account address.
|
|
18
|
+
* @returns {Promise<string>} A promise that resolves to the EVM account address.
|
|
19
|
+
*/
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
36
|
+
signMessageRaw(message: string | ccc.BytesLike): Promise<ccc.Hex>;
|
|
37
37
|
}
|
|
38
|
-
//# sourceMappingURL=signer.d.ts.map
|
|
38
|
+
//# sourceMappingURL=signer.d.ts.map
|
package/dist.commonjs/signer.js
CHANGED
|
@@ -8,49 +8,54 @@ const core_1 = require("@ckb-ccc/core");
|
|
|
8
8
|
* @extends {ccc.SignerEvm}
|
|
9
9
|
*/
|
|
10
10
|
class Signer extends core_1.ccc.SignerEvm {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Creates an instance of Signer.
|
|
13
|
+
* @param {ccc.Client} client - The client instance.
|
|
14
|
+
* @param {EIP6963ProviderDetail} detail - The provider detail.
|
|
15
|
+
*/
|
|
16
|
+
constructor(client, detail) {
|
|
17
|
+
super(client);
|
|
18
|
+
this.detail = detail;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Gets the EVM account address.
|
|
22
|
+
* @returns {Promise<string>} A promise that resolves to the EVM account address.
|
|
23
|
+
*/
|
|
24
|
+
async getEvmAccount() {
|
|
25
|
+
return (await this.detail.provider.request({ method: "eth_accounts" }))[0];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Connects to the provider by requesting accounts.
|
|
29
|
+
* @returns {Promise<void>} A promise that resolves when the connection is established.
|
|
30
|
+
*/
|
|
31
|
+
async connect() {
|
|
32
|
+
await this.detail.provider.request({ method: "eth_requestAccounts" });
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Checks if the provider is connected.
|
|
36
|
+
* @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
|
|
37
|
+
*/
|
|
38
|
+
async isConnected() {
|
|
39
|
+
return (
|
|
40
|
+
(await this.detail.provider.request({ method: "eth_accounts" }))
|
|
41
|
+
.length !== 0
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Signs a raw message with the personal account.
|
|
46
|
+
* @param {string | ccc.BytesLike} message - The message to sign.
|
|
47
|
+
* @returns {Promise<ccc.Hex>} A promise that resolves to the signed message.
|
|
48
|
+
*/
|
|
49
|
+
async signMessageRaw(message) {
|
|
50
|
+
const challenge =
|
|
51
|
+
typeof message === "string"
|
|
52
|
+
? core_1.ccc.bytesFrom(message, "utf8")
|
|
53
|
+
: message;
|
|
54
|
+
const address = await this.getEvmAccount();
|
|
55
|
+
return this.detail.provider.request({
|
|
56
|
+
method: "personal_sign",
|
|
57
|
+
params: [core_1.ccc.hexFrom(challenge), address],
|
|
58
|
+
});
|
|
59
|
+
}
|
|
55
60
|
}
|
|
56
61
|
exports.Signer = Signer;
|
|
@@ -5,18 +5,18 @@ import { Signer as EIP6963Signer } from "./signer";
|
|
|
5
5
|
* @class
|
|
6
6
|
*/
|
|
7
7
|
export declare class SignerFactory {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
8
|
+
private readonly client;
|
|
9
|
+
private readonly existedUuids;
|
|
10
|
+
/**
|
|
11
|
+
* Creates an instance of SignerFactory.
|
|
12
|
+
* @param {ccc.Client} client - The client instance.
|
|
13
|
+
*/
|
|
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
|
+
*/
|
|
20
|
+
subscribeSigners(callback: (newSigner: EIP6963Signer) => unknown): () => void;
|
|
21
21
|
}
|
|
22
|
-
//# sourceMappingURL=signersFactory.d.ts.map
|
|
22
|
+
//# sourceMappingURL=signersFactory.d.ts.map
|
|
@@ -7,33 +7,34 @@ const signer_1 = require("./signer");
|
|
|
7
7
|
* @class
|
|
8
8
|
*/
|
|
9
9
|
class SignerFactory {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Creates an instance of SignerFactory.
|
|
12
|
+
* @param {ccc.Client} client - The client instance.
|
|
13
|
+
*/
|
|
14
|
+
constructor(client) {
|
|
15
|
+
this.client = client;
|
|
16
|
+
this.existedUuids = [];
|
|
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
|
+
*/
|
|
23
|
+
subscribeSigners(callback) {
|
|
24
|
+
const onNewProvider = (event) => {
|
|
25
|
+
const { detail } = event;
|
|
26
|
+
const { uuid } = detail.info;
|
|
27
|
+
if (this.existedUuids.includes(uuid)) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
this.existedUuids.push(uuid);
|
|
31
|
+
const signer = new signer_1.Signer(this.client, detail);
|
|
32
|
+
callback(signer);
|
|
33
|
+
};
|
|
34
|
+
window.addEventListener("eip6963:announceProvider", onNewProvider);
|
|
35
|
+
window.dispatchEvent(new Event("eip6963:requestProvider"));
|
|
36
|
+
return () =>
|
|
37
|
+
window.removeEventListener("eip6963:announceProvider", onNewProvider);
|
|
38
|
+
}
|
|
38
39
|
}
|
|
39
40
|
exports.SignerFactory = SignerFactory;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ckb-ccc/eip6963",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8-alpha.3",
|
|
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.8-alpha.3"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "bddfa3e5631252194dfde32b79ee589703f18afb"
|
|
48
48
|
}
|