@ckb-ccc/rei 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 +8 -0
- package/README.md +45 -0
- package/dist/advanced.d.ts +2 -0
- package/dist/advanced.d.ts.map +1 -0
- package/dist/advanced.js +1 -0
- package/dist/advancedBarrel.d.ts +103 -0
- package/dist/advancedBarrel.d.ts.map +1 -0
- package/dist/advancedBarrel.js +1 -0
- package/dist/barrel.d.ts +3 -0
- package/dist/barrel.d.ts.map +1 -0
- package/dist/barrel.js +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -0
- package/dist/package.json +3 -0
- package/dist/signer.d.ts +83 -0
- package/dist/signer.d.ts.map +1 -0
- package/dist/signer.js +144 -0
- package/dist/signersFactory.d.ts +8 -0
- package/dist/signersFactory.d.ts.map +1 -0
- package/dist/signersFactory.js +18 -0
- package/dist.commonjs/advanced.d.ts +2 -0
- package/dist.commonjs/advanced.d.ts.map +1 -0
- package/dist.commonjs/advanced.js +27 -0
- package/dist.commonjs/advancedBarrel.d.ts +103 -0
- package/dist.commonjs/advancedBarrel.d.ts.map +1 -0
- package/dist.commonjs/advancedBarrel.js +2 -0
- package/dist.commonjs/barrel.d.ts +3 -0
- package/dist.commonjs/barrel.d.ts.map +1 -0
- package/dist.commonjs/barrel.js +18 -0
- package/dist.commonjs/index.d.ts +2 -0
- package/dist.commonjs/index.d.ts.map +1 -0
- package/dist.commonjs/index.js +27 -0
- package/dist.commonjs/package.json +3 -0
- package/dist.commonjs/signer.d.ts +83 -0
- package/dist.commonjs/signer.d.ts.map +1 -0
- package/dist.commonjs/signer.js +148 -0
- package/dist.commonjs/signersFactory.d.ts +8 -0
- package/dist.commonjs/signersFactory.d.ts.map +1 -0
- package/dist.commonjs/signersFactory.js +22 -0
- package/package.json +55 -0
- package/src/advanced.ts +1 -0
- package/src/advancedBarrel.ts +103 -0
- package/src/barrel.ts +2 -0
- package/src/index.ts +1 -0
- package/src/signer.ts +180 -0
- package/src/signersFactory.ts +23 -0
- package/typedoc.json +6 -0
package/CHANGELOG.md
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://app.ckbccc.com/">
|
|
3
|
+
<img alt="Logo" src="https://raw.githubusercontent.com/ckb-ecofund/ccc/master/assets/logo.svg" width="20%" />
|
|
4
|
+
</a>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<h1 align="center" style="font-size: 48px;">
|
|
8
|
+
CCC's support for REI Wallet
|
|
9
|
+
</h1>
|
|
10
|
+
|
|
11
|
+
<p align="center">
|
|
12
|
+
<a href="https://www.npmjs.com/package/@ckb-ccc/rei"><img
|
|
13
|
+
alt="NPM Version" src="https://img.shields.io/npm/v/%40ckb-ccc%2Frei"
|
|
14
|
+
/></a>
|
|
15
|
+
<img alt="GitHub commit activity" src="https://img.shields.io/github/commit-activity/m/ckb-ecofund/ccc" />
|
|
16
|
+
<img alt="GitHub last commit" src="https://img.shields.io/github/last-commit/ckb-ecofund/ccc/master" />
|
|
17
|
+
<img alt="GitHub deployments" src="https://img.shields.io/github/deployments/ckb-ecofund/ccc/production" />
|
|
18
|
+
<a href="https://app.ckbccc.com/"><img
|
|
19
|
+
alt="Demo" src="https://img.shields.io/website?url=https%3A%2F%2Fapp.ckbccc.com%2F&label=Demo"
|
|
20
|
+
/></a>
|
|
21
|
+
</p>
|
|
22
|
+
|
|
23
|
+
<p align="center">
|
|
24
|
+
"CCC - CKBers' Codebase" is the next step of "Common Chains Connector".
|
|
25
|
+
<br />
|
|
26
|
+
Empower yourself with CCC to discover the unlimited potential of CKB.
|
|
27
|
+
<br />
|
|
28
|
+
Interoperate with wallets from different chain ecosystems.
|
|
29
|
+
<br />
|
|
30
|
+
Fully enabling CKB's Turing completeness and cryptographic freedom power.
|
|
31
|
+
</p>
|
|
32
|
+
|
|
33
|
+
## Preview
|
|
34
|
+
|
|
35
|
+
<p align="center">
|
|
36
|
+
<a href="https://app.ckbccc.com/">
|
|
37
|
+
<img src="https://raw.githubusercontent.com/ckb-ecofund/ccc/master/assets/preview.png" width="30%" />
|
|
38
|
+
</a>
|
|
39
|
+
</p>
|
|
40
|
+
|
|
41
|
+
This project is still under active development, and we are looking forward to your feedback. [Try its demo now here](https://app.ckbccc.com/). It showcases how to use CCC for some basic scenarios in CKB.
|
|
42
|
+
|
|
43
|
+
<h3 align="center">
|
|
44
|
+
Read more about CCC on <a href="https://docs.ckbccc.com">our website</a> or <a href="https://github.com/ckb-ecofund/ccc">GitHub Repo</a>.
|
|
45
|
+
</h3>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"advanced.d.ts","sourceRoot":"","sources":["../src/advanced.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,qBAAqB,CAAC"}
|
package/dist/advanced.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as ReiA from "./advancedBarrel.js";
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
/**
|
|
3
|
+
* Interface representing a provider for interacting with accounts and signing messages.
|
|
4
|
+
* @interface
|
|
5
|
+
*/
|
|
6
|
+
export interface Provider {
|
|
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
|
+
* Checks if rei wallet is connected.
|
|
19
|
+
* @returns A promise that resolves to true if connected, false otherwise.
|
|
20
|
+
*/
|
|
21
|
+
isConnected(): Promise<boolean>;
|
|
22
|
+
/**
|
|
23
|
+
* Removes an event listener from the provider.
|
|
24
|
+
* @param {string} eventName - The name of the event to remove the listener from.
|
|
25
|
+
* @param {(...args: unknown[]) => unknown} listener - The listener function to remove.
|
|
26
|
+
* @returns {Provider} The provider instance.
|
|
27
|
+
*/
|
|
28
|
+
off(eventName: string, listener: (...args: unknown[]) => unknown): void;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Interface representing a method to add event listeners to the provider.
|
|
32
|
+
* @interface
|
|
33
|
+
*/
|
|
34
|
+
export interface OnMethod {
|
|
35
|
+
/**
|
|
36
|
+
* Adds an event listener to the provider.
|
|
37
|
+
* @param {string} eventName - The name of the event.
|
|
38
|
+
* @param {(...args: unknown[]) => unknown} listener - The listener function.
|
|
39
|
+
* @returns {Provider} The provider instance.
|
|
40
|
+
*/
|
|
41
|
+
(eventName: string, listener: (...args: unknown[]) => unknown): void;
|
|
42
|
+
}
|
|
43
|
+
export interface RequestMethod {
|
|
44
|
+
/**
|
|
45
|
+
* Requests the accounts from the provider.
|
|
46
|
+
* @param request - The request object.
|
|
47
|
+
* @param request.method - The method name.
|
|
48
|
+
* @param request.data - The optional method parameters.
|
|
49
|
+
* @returns A promise that resolves to an array of account addresses.
|
|
50
|
+
*/
|
|
51
|
+
(request: {
|
|
52
|
+
method: "ckb_requestAccounts";
|
|
53
|
+
data?: undefined;
|
|
54
|
+
}): Promise<string>;
|
|
55
|
+
/**
|
|
56
|
+
* Signs a message with the personal account.
|
|
57
|
+
* @param request - The request object.
|
|
58
|
+
* @param request.method - The method name.
|
|
59
|
+
* @param request.data - The method parameters.
|
|
60
|
+
* @returns A promise that resolves to the signed message.
|
|
61
|
+
*/
|
|
62
|
+
(request: {
|
|
63
|
+
method: "ckb_signMessage";
|
|
64
|
+
data: {
|
|
65
|
+
message: string;
|
|
66
|
+
};
|
|
67
|
+
}): Promise<ccc.Hex>;
|
|
68
|
+
/**
|
|
69
|
+
* Gets the identity of the signer.
|
|
70
|
+
* @param request - The request object.
|
|
71
|
+
* @param request.method - The method name.
|
|
72
|
+
* @returns A promise that resolves to the signed message.
|
|
73
|
+
*/
|
|
74
|
+
(request: {
|
|
75
|
+
method: "ckb_getPublicKey";
|
|
76
|
+
}): Promise<string>;
|
|
77
|
+
/**
|
|
78
|
+
* Get network.
|
|
79
|
+
* @param request - The request object.
|
|
80
|
+
* @param request.method - The method name.
|
|
81
|
+
* @param request.data - The method parameters.
|
|
82
|
+
* @returns A promise that resolves to the signed message.
|
|
83
|
+
*/
|
|
84
|
+
(request: {
|
|
85
|
+
method: "ckb_switchNetwork";
|
|
86
|
+
data: string;
|
|
87
|
+
}): Promise<{
|
|
88
|
+
type: string;
|
|
89
|
+
network: string;
|
|
90
|
+
}>;
|
|
91
|
+
/**
|
|
92
|
+
* Signs transaction .
|
|
93
|
+
* @param request - The request object.
|
|
94
|
+
* @param request.method - The method name.
|
|
95
|
+
* @param request.data - The method parameters.
|
|
96
|
+
* @returns A promise that resolves to the signed message.
|
|
97
|
+
*/
|
|
98
|
+
(request: {
|
|
99
|
+
method: "ckb_signTransaction";
|
|
100
|
+
data: any;
|
|
101
|
+
}): Promise<any>;
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=advancedBarrel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"advancedBarrel.d.ts","sourceRoot":"","sources":["../src/advancedBarrel.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;;;OAGG;IACH,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAEhC;;;;;OAKG;IACH,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,GAAG,IAAI,CAAC;CACzE;AAED;;;GAGG;A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el.js
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as Rei from "./barrel.js";
|
package/dist/signer.d.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
import { Provider } from "./advancedBarrel.js";
|
|
3
|
+
/**
|
|
4
|
+
* Class representing a CKB signer that extends Signer from @ckb-ccc/core.
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export declare class ReiSigner extends ccc.Signer {
|
|
8
|
+
readonly provider: Provider;
|
|
9
|
+
/**
|
|
10
|
+
* Creates an instance of Signer.
|
|
11
|
+
* @param client - The client instance.
|
|
12
|
+
* @param provider - The provider instance.
|
|
13
|
+
*/
|
|
14
|
+
constructor(client: ccc.Client, provider: Provider);
|
|
15
|
+
/**
|
|
16
|
+
* Register a listener to be called when this signer is replaced.
|
|
17
|
+
*
|
|
18
|
+
* @returns A function for unregister
|
|
19
|
+
*/
|
|
20
|
+
onReplaced(listener: () => void): () => void;
|
|
21
|
+
/**
|
|
22
|
+
* Gets the signer type.
|
|
23
|
+
* @returns The type of the signer.
|
|
24
|
+
*/
|
|
25
|
+
get type(): ccc.SignerType;
|
|
26
|
+
/**
|
|
27
|
+
* Gets the sign type.
|
|
28
|
+
* @returns The sign type.
|
|
29
|
+
*/
|
|
30
|
+
get signType(): ccc.SignerSignType;
|
|
31
|
+
/**
|
|
32
|
+
* Connects to the provider by requesting authentication.
|
|
33
|
+
* @returns A promise that resolves when the connection is established.
|
|
34
|
+
*/
|
|
35
|
+
connect(): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Checks if the signer is connected.
|
|
38
|
+
* @returns A promise that resolves to true if connected, false otherwise.
|
|
39
|
+
*/
|
|
40
|
+
isConnected(): Promise<boolean>;
|
|
41
|
+
_getNetworkChanged(): Promise<boolean>;
|
|
42
|
+
/**
|
|
43
|
+
* Gets the internal address.
|
|
44
|
+
* @returns A promise that resolves to the internal address.
|
|
45
|
+
*/
|
|
46
|
+
getInternalAddress(): Promise<string>;
|
|
47
|
+
/**
|
|
48
|
+
* Gets the address object.
|
|
49
|
+
* @returns A promise that resolves to the address object.
|
|
50
|
+
*/
|
|
51
|
+
getAddressObj(): Promise<ccc.Address>;
|
|
52
|
+
/**
|
|
53
|
+
* Gets the address objects.
|
|
54
|
+
* @returns A promise that resolves to an array of address objects.
|
|
55
|
+
*/
|
|
56
|
+
getAddressObjs(): Promise<ccc.Address[]>;
|
|
57
|
+
/**
|
|
58
|
+
* Gets the identity of the signer.
|
|
59
|
+
* @returns A promise that resolves to the identity.
|
|
60
|
+
*/
|
|
61
|
+
getIdentity(): Promise<string>;
|
|
62
|
+
/**
|
|
63
|
+
* Signs a raw message with the personal account.
|
|
64
|
+
* @param message - The message to sign.
|
|
65
|
+
* @returns A promise that resolves to the signed message.
|
|
66
|
+
*/
|
|
67
|
+
signMessageRaw(message: string): Promise<ccc.Hex>;
|
|
68
|
+
/**
|
|
69
|
+
* prepare a transaction before signing.
|
|
70
|
+
*
|
|
71
|
+
* @param txLike - The transaction to prepare, represented as a TransactionLike object.
|
|
72
|
+
* @returns A promise that resolves to the prepared Transaction object.
|
|
73
|
+
*/
|
|
74
|
+
prepareTransaction(txLike: ccc.TransactionLike): Promise<ccc.Transaction>;
|
|
75
|
+
/**
|
|
76
|
+
* Signs a transaction without preparing information for it.
|
|
77
|
+
*
|
|
78
|
+
* @param txLike - The transaction to sign, represented as a TransactionLike object.
|
|
79
|
+
* @returns A promise that resolves to the signed Transaction object.
|
|
80
|
+
*/
|
|
81
|
+
signOnlyTransaction(txLike: ccc.TransactionLike): Promise<ccc.Transaction>;
|
|
82
|
+
}
|
|
83
|
+
//# sourceM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EG,mBAAmB,CACvB,MAAM,EAAE,GAAG,CAAC,eAAe,GAC1B,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC;CAQ5B"}
|
package/dist/signer.js
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
import { cccA } from "@ckb-ccc/core/advanced";
|
|
3
|
+
/**
|
|
4
|
+
* Class representing a CKB signer that extends Signer from @ckb-ccc/core.
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export class ReiSigner extends ccc.Signer {
|
|
8
|
+
/**
|
|
9
|
+
* Creates an instance of Signer.
|
|
10
|
+
* @param client - The client instance.
|
|
11
|
+
* @param provider - The provider instance.
|
|
12
|
+
*/
|
|
13
|
+
constructor(client, provider) {
|
|
14
|
+
super(client);
|
|
15
|
+
this.provider = provider;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Register a listener to be called when this signer is replaced.
|
|
19
|
+
*
|
|
20
|
+
* @returns A function for unregister
|
|
21
|
+
*/
|
|
22
|
+
onReplaced(listener) {
|
|
23
|
+
const stop = [];
|
|
24
|
+
const replacer = async () => {
|
|
25
|
+
listener();
|
|
26
|
+
stop[0]?.();
|
|
27
|
+
};
|
|
28
|
+
stop.push(() => {
|
|
29
|
+
this.provider.off("accountsChanged", replacer);
|
|
30
|
+
this.provider.off("chainChanged", replacer);
|
|
31
|
+
});
|
|
32
|
+
this.provider.on("accountsChanged", replacer);
|
|
33
|
+
this.provider.on("chainChanged", replacer);
|
|
34
|
+
return stop[0];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Gets the signer type.
|
|
38
|
+
* @returns The type of the signer.
|
|
39
|
+
*/
|
|
40
|
+
get type() {
|
|
41
|
+
return ccc.SignerType.CKB;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Gets the sign type.
|
|
45
|
+
* @returns The sign type.
|
|
46
|
+
*/
|
|
47
|
+
get signType() {
|
|
48
|
+
return ccc.SignerSignType.CkbSecp256k1;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Connects to the provider by requesting authentication.
|
|
52
|
+
* @returns A promise that resolves when the connection is established.
|
|
53
|
+
*/
|
|
54
|
+
async connect() {
|
|
55
|
+
const prefixClient = this.client.addressPrefix;
|
|
56
|
+
const netChange = await this._getNetworkChanged();
|
|
57
|
+
if (netChange) {
|
|
58
|
+
const data = prefixClient === "ckb" ? "mainnet" : "testnet";
|
|
59
|
+
await this.provider.request({ method: "ckb_switchNetwork", data });
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Checks if the signer is connected.
|
|
64
|
+
* @returns A promise that resolves to true if connected, false otherwise.
|
|
65
|
+
*/
|
|
66
|
+
async isConnected() {
|
|
67
|
+
const connected = await this.provider.isConnected();
|
|
68
|
+
if (!connected || (await this._getNetworkChanged())) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
return connected;
|
|
72
|
+
}
|
|
73
|
+
async _getNetworkChanged() {
|
|
74
|
+
const prefixClient = this.client.addressPrefix;
|
|
75
|
+
const address = await this.getInternalAddress();
|
|
76
|
+
const { prefix } = cccA.addressPayloadFromString(address);
|
|
77
|
+
return prefixClient !== prefix;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Gets the internal address.
|
|
81
|
+
* @returns A promise that resolves to the internal address.
|
|
82
|
+
*/
|
|
83
|
+
async getInternalAddress() {
|
|
84
|
+
return this.provider.request({ method: "ckb_requestAccounts" });
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Gets the address object.
|
|
88
|
+
* @returns A promise that resolves to the address object.
|
|
89
|
+
*/
|
|
90
|
+
async getAddressObj() {
|
|
91
|
+
return ccc.Address.fromString(await this.getInternalAddress(), this.client);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Gets the address objects.
|
|
95
|
+
* @returns A promise that resolves to an array of address objects.
|
|
96
|
+
*/
|
|
97
|
+
async getAddressObjs() {
|
|
98
|
+
return [await this.getAddressObj()];
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Gets the identity of the signer.
|
|
102
|
+
* @returns A promise that resolves to the identity.
|
|
103
|
+
*/
|
|
104
|
+
async getIdentity() {
|
|
105
|
+
return this.provider.request({
|
|
106
|
+
method: "ckb_getPublicKey",
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Signs a raw message with the personal account.
|
|
111
|
+
* @param message - The message to sign.
|
|
112
|
+
* @returns A promise that resolves to the signed message.
|
|
113
|
+
*/
|
|
114
|
+
async signMessageRaw(message) {
|
|
115
|
+
return this.provider.request({
|
|
116
|
+
method: "ckb_signMessage",
|
|
117
|
+
data: { message },
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* prepare a transaction before signing.
|
|
122
|
+
*
|
|
123
|
+
* @param txLike - The transaction to prepare, represented as a TransactionLike object.
|
|
124
|
+
* @returns A promise that resolves to the prepared Transaction object.
|
|
125
|
+
*/
|
|
126
|
+
async prepareTransaction(txLike) {
|
|
127
|
+
const tx = ccc.Transaction.from(txLike);
|
|
128
|
+
await tx.addCellDepsOfKnownScripts(this.client, ccc.KnownScript.Secp256k1Blake160);
|
|
129
|
+
return ccc.reduceAsync(await this.getAddressObjs(), (tx, { script }) => tx.prepareSighashAllWitness(script, 65, this.client), tx);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Signs a transaction without preparing information for it.
|
|
133
|
+
*
|
|
134
|
+
* @param txLike - The transaction to sign, represented as a TransactionLike object.
|
|
135
|
+
* @returns A promise that resolves to the signed Transaction object.
|
|
136
|
+
*/
|
|
137
|
+
async signOnlyTransaction(txLike) {
|
|
138
|
+
const txFormat = cccA.JsonRpcTransformers.transactionFrom(txLike);
|
|
139
|
+
return this.provider.request({
|
|
140
|
+
method: "ckb_signTransaction",
|
|
141
|
+
data: { txSkeleton: txFormat },
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
/**
|
|
3
|
+
* Retrieves the Rei signer if available.
|
|
4
|
+
* @param client - The client instance.
|
|
5
|
+
* @returns The Signer instance if the Rei provider is available, otherwise undefined.
|
|
6
|
+
*/
|
|
7
|
+
export declare function getReiSigners(client: ccc.Client): ccc.SignerInfo[];
|
|
8
|
+
//# sourceMappingURL=signersFactory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signersFactory.d.ts","sourceRoot":"","sources":["../src/signersFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAIpC;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,UAAU,EAAE,CAalE"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ReiSigner } from "./signer.js";
|
|
2
|
+
/**
|
|
3
|
+
* Retrieves the Rei signer if available.
|
|
4
|
+
* @param client - The client instance.
|
|
5
|
+
* @returns The Signer instance if the Rei provider is available, otherwise undefined.
|
|
6
|
+
*/
|
|
7
|
+
export function getReiSigners(client) {
|
|
8
|
+
const windowRef = window;
|
|
9
|
+
if (typeof windowRef.ckb === "undefined") {
|
|
10
|
+
return [];
|
|
11
|
+
}
|
|
12
|
+
return [
|
|
13
|
+
{
|
|
14
|
+
signer: new ReiSigner(client, windowRef.ckb),
|
|
15
|
+
name: "CKB",
|
|
16
|
+
},
|
|
17
|
+
];
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"advanced.d.ts","sourceRoot":"","sources":["../src/advanced.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.ReiA = void 0;
|
|
27
|
+
exports.ReiA = __importStar(require("./advancedBarrel.js"));
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
/**
|
|
3
|
+
* Interface representing a provider for interacting with accounts and signing messages.
|
|
4
|
+
* @interface
|
|
5
|
+
*/
|
|
6
|
+
export interface Provider {
|
|
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
|
+
* Checks if rei wallet is connected.
|
|
19
|
+
* @returns A promise that resolves to true if connected, false otherwise.
|
|
20
|
+
*/
|
|
21
|
+
isConnected(): Promise<boolean>;
|
|
22
|
+
/**
|
|
23
|
+
* Removes an event listener from the provider.
|
|
24
|
+
* @param {string} eventName - The name of the event to remove the listener from.
|
|
25
|
+
* @param {(...args: unknown[]) => unknown} listener - The listener function to remove.
|
|
26
|
+
* @returns {Provider} The provider instance.
|
|
27
|
+
*/
|
|
28
|
+
off(eventName: string, listener: (...args: unknown[]) => unknown): void;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Interface representing a method to add event listeners to the provider.
|
|
32
|
+
* @interface
|
|
33
|
+
*/
|
|
34
|
+
export interface OnMethod {
|
|
35
|
+
/**
|
|
36
|
+
* Adds an event listener to the provider.
|
|
37
|
+
* @param {string} eventName - The name of the event.
|
|
38
|
+
* @param {(...args: unknown[]) => unknown} listener - The listener function.
|
|
39
|
+
* @returns {Provider} The provider instance.
|
|
40
|
+
*/
|
|
41
|
+
(eventName: string, listener: (...args: unknown[]) => unknown): void;
|
|
42
|
+
}
|
|
43
|
+
export interface RequestMethod {
|
|
44
|
+
/**
|
|
45
|
+
* Requests the accounts from the provider.
|
|
46
|
+
* @param request - The request object.
|
|
47
|
+
* @param request.method - The method name.
|
|
48
|
+
* @param request.data - The optional method parameters.
|
|
49
|
+
* @returns A promise that resolves to an array of account addresses.
|
|
50
|
+
*/
|
|
51
|
+
(request: {
|
|
52
|
+
method: "ckb_requestAccounts";
|
|
53
|
+
data?: undefined;
|
|
54
|
+
}): Promise<string>;
|
|
55
|
+
/**
|
|
56
|
+
* Signs a message with the personal account.
|
|
57
|
+
* @param request - The request object.
|
|
58
|
+
* @param request.method - The method name.
|
|
59
|
+
* @param request.data - The method parameters.
|
|
60
|
+
* @returns A promise that resolves to the signed message.
|
|
61
|
+
*/
|
|
62
|
+
(request: {
|
|
63
|
+
method: "ckb_signMessage";
|
|
64
|
+
data: {
|
|
65
|
+
message: string;
|
|
66
|
+
};
|
|
67
|
+
}): Promise<ccc.Hex>;
|
|
68
|
+
/**
|
|
69
|
+
* Gets the identity of the signer.
|
|
70
|
+
* @param request - The request object.
|
|
71
|
+
* @param request.method - The method name.
|
|
72
|
+
* @returns A promise that resolves to the signed message.
|
|
73
|
+
*/
|
|
74
|
+
(request: {
|
|
75
|
+
method: "ckb_getPublicKey";
|
|
76
|
+
}): Promise<string>;
|
|
77
|
+
/**
|
|
78
|
+
* Get network.
|
|
79
|
+
* @param request - The request object.
|
|
80
|
+
* @param request.method - The method name.
|
|
81
|
+
* @param request.data - The method parameters.
|
|
82
|
+
* @returns A promise that resolves to the signed message.
|
|
83
|
+
*/
|
|
84
|
+
(request: {
|
|
85
|
+
method: "ckb_switchNetwork";
|
|
86
|
+
data: string;
|
|
87
|
+
}): Promise<{
|
|
88
|
+
type: string;
|
|
89
|
+
network: string;
|
|
90
|
+
}>;
|
|
91
|
+
/**
|
|
92
|
+
* Signs transaction .
|
|
93
|
+
* @param request - The request object.
|
|
94
|
+
* @param request.method - The method name.
|
|
95
|
+
* @param request.data - The method parameters.
|
|
96
|
+
* @returns A promise that resolves to the signed message.
|
|
97
|
+
*/
|
|
98
|
+
(request: {
|
|
99
|
+
method: "ckb_signTransaction";
|
|
100
|
+
data: any;
|
|
101
|
+
}): Promise<any>;
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=advancedBarrel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"advancedBarrel.d.ts","sourceRoot":"","sources":["../src/advancedBarrel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEpC;;;GAGG;AACH,MAAM,WAAW,QAAQ;IACvB;;;OAGG;IACH,OA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,CAAA;KAAE,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;CACvE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"barrel.d.ts","sourceRoot":"","sources":["../src/barrel.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./signer.js"), exports);
|
|
18
|
+
__exportStar(require("./signersFactory.js"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,aAAa,CAAC"}
|