@ckb-ccc/rei 1.0.32 → 1.1.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/CHANGELOG.md +23 -0
- package/dist/advanced.d.mts +2 -0
- package/dist/advanced.mjs +1 -0
- package/dist/advancedBarrel-DQiM1LUp.d.mts +113 -0
- package/dist/advancedBarrel-DQiM1LUp.d.mts.map +1 -0
- package/dist/advancedBarrel.d.mts +2 -0
- package/dist/advancedBarrel.mjs +2 -0
- package/dist/advancedBarrel.mjs.map +1 -0
- package/dist/barrel.d.mts +99 -0
- package/dist/barrel.d.mts.map +1 -0
- package/dist/barrel.mjs +2 -0
- package/dist/barrel.mjs.map +1 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +1 -0
- package/dist/rolldown-runtime-DK3Fl9T5.mjs +1 -0
- package/dist.commonjs/advanced.d.ts +2 -2
- package/dist.commonjs/advanced.js +1 -37
- package/dist.commonjs/advancedBarrel-BVsjztuv.d.ts +113 -0
- package/dist.commonjs/advancedBarrel-BVsjztuv.d.ts.map +1 -0
- package/dist.commonjs/advancedBarrel.d.ts +2 -106
- package/dist.commonjs/advancedBarrel.js +2 -2
- package/dist.commonjs/advancedBarrel.js.map +1 -0
- package/dist.commonjs/barrel.d.ts +98 -2
- package/dist.commonjs/barrel.d.ts.map +1 -1
- package/dist.commonjs/barrel.js +2 -18
- package/dist.commonjs/barrel.js.map +1 -0
- package/dist.commonjs/index.d.ts +2 -2
- package/dist.commonjs/index.js +1 -37
- package/dist.commonjs/rolldown-runtime-BIInC43l.js +1 -0
- package/package.json +26 -29
- package/tsdown.config.mts +43 -0
- package/dist/advanced.d.ts +0 -2
- package/dist/advanced.d.ts.map +0 -1
- package/dist/advanced.js +0 -1
- package/dist/advancedBarrel.d.ts +0 -106
- package/dist/advancedBarrel.d.ts.map +0 -1
- package/dist/advancedBarrel.js +0 -1
- package/dist/barrel.d.ts +0 -3
- package/dist/barrel.d.ts.map +0 -1
- package/dist/barrel.js +0 -2
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -1
- package/dist/signer.d.ts +0 -83
- package/dist/signer.d.ts.map +0 -1
- package/dist/signer.js +0 -144
- package/dist/signersFactory.d.ts +0 -9
- package/dist/signersFactory.d.ts.map +0 -1
- package/dist/signersFactory.js +0 -19
- package/dist.commonjs/advanced.d.ts.map +0 -1
- package/dist.commonjs/advancedBarrel.d.ts.map +0 -1
- package/dist.commonjs/index.d.ts.map +0 -1
- package/dist.commonjs/signer.d.ts +0 -83
- package/dist.commonjs/signer.d.ts.map +0 -1
- package/dist.commonjs/signer.js +0 -148
- package/dist.commonjs/signersFactory.d.ts +0 -9
- package/dist.commonjs/signersFactory.d.ts.map +0 -1
- package/dist.commonjs/signersFactory.js +0 -22
package/dist/signer.js
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
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
|
-
}
|
package/dist/signersFactory.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { ccc } from "@ckb-ccc/core";
|
|
2
|
-
/**
|
|
3
|
-
* Retrieves the Rei signer if available.
|
|
4
|
-
* @param {ccc.Client} client - The client instance.
|
|
5
|
-
* @returns {Signer | undefined} The Signer instance if the Rei provider is available, otherwise undefined.
|
|
6
|
-
|
|
7
|
-
*/
|
|
8
|
-
export declare function getReiSigners(client: ccc.Client): ccc.SignerInfo[];
|
|
9
|
-
//# sourceMappingURL=signersFactory.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"signersFactory.d.ts","sourceRoot":"","sources":["../src/signersFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAIpC;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,UAAU,EAAE,CAYlE"}
|
package/dist/signersFactory.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { ReiSigner } from "./signer.js";
|
|
2
|
-
/**
|
|
3
|
-
* Retrieves the Rei signer if available.
|
|
4
|
-
* @param {ccc.Client} client - The client instance.
|
|
5
|
-
* @returns {Signer | undefined} The Signer instance if the Rei provider is available, otherwise undefined.
|
|
6
|
-
|
|
7
|
-
*/
|
|
8
|
-
export function getReiSigners(client) {
|
|
9
|
-
const windowRef = window;
|
|
10
|
-
if (typeof windowRef?.rei?.ckb === "undefined") {
|
|
11
|
-
return [];
|
|
12
|
-
}
|
|
13
|
-
return [
|
|
14
|
-
{
|
|
15
|
-
signer: new ReiSigner(client, windowRef.rei.ckb),
|
|
16
|
-
name: "CKB",
|
|
17
|
-
},
|
|
18
|
-
];
|
|
19
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"advanced.d.ts","sourceRoot":"","sources":["../src/advanced.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,qBAAqB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"advancedBarrel.d.ts","sourceRoot":"","sources":["../src/advancedBarrel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAE9C;;;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;AACH,MAAM,WAAW,QAAQ;IACvB;;;;;OAKG;IACH,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,GAAG,IAAI,CAAC;CACtE;AAED,MAAM,WAAW,aAAa;IAC5B;;;;;;OAMG;IACH,CAAC,OAAO,EAAE;QACR,MAAM,EAAE,qBAAqB,CAAC;QAC9B,IAAI,CAAC,EAAE,SAAS,CAAC;KAClB,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAEpB;;;;;;OAMG;IACH,CAAC,OAAO,EAAE;QACR,MAAM,EAAE,iBAAiB,CAAC;QAC1B,IAAI,EAAE;YAAE,OAAO,EAAE,MAAM,CAAA;SAAE,CAAC;KAC3B,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAErB;;;;;OAKG;IACH,CAAC,OAAO,EAAE;QAAE,MAAM,EAAE,kBAAkB,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAE3D;;;;;;OAMG;IACH,CAAC,OAAO,EAAE;QACR,MAAM,EAAE,mBAAmB,CAAC;QAC5B,IAAI,EAAE,MAAM,CAAC;KACd,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAE/C;;;;;;OAMG;IAEH,CAAC,OAAO,EAAE;QACR,MAAM,EAAE,qBAAqB,CAAC;QAC9B,IAAI,EAAE;YAAE,UAAU,EAAE,IAAI,CAAC,kBAAkB,CAAA;SAAE,CAAC;KAC/C,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;CAC9B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,aAAa,CAAC"}
|
|
@@ -1,83 +0,0 @@
|
|
|
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
|
-
//# sourceMappingURL=signer.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../src/signer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAGpC,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAE/C;;;GAGG;AACH,qBAAa,SAAU,SAAQ,GAAG,CAAC,MAAM;aAQrB,QAAQ,EAAE,QAAQ;IAPpC;;;;OAIG;gBAED,MAAM,EAAE,GAAG,CAAC,MAAM,EACF,QAAQ,EAAE,QAAQ;IAKpC;;;;OAIG;IAEH,UAAU,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI;IAgB5C;;;OAGG;IACH,IAAI,IAAI,IAAI,GAAG,CAAC,UAAU,CAEzB;IAED;;;OAGG;IACH,IAAI,QAAQ,IAAI,GAAG,CAAC,cAAc,CAEjC;IAED;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAS9B;;;OAGG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAQ/B,kBAAkB,IAAI,OAAO,CAAC,OAAO,CAAC;IAQ5C;;;OAGG;IACG,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAI3C;;;OAGG;IACG,aAAa,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC;IAI3C;;;OAGG;IACG,cAAc,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;IAI9C;;;OAGG;IACG,WAAW,IAAI,OAAO,CAAC,MAAM,CAAC;IAMpC;;;;OAIG;IACG,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;IAOvD;;;;;OAKG;IAEG,kBAAkB,CACtB,MAAM,EAAE,GAAG,CAAC,eAAe,GAC1B,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC;IAc3B;;;;;OAKG;IAEG,mBAAmB,CACvB,MAAM,EAAE,GAAG,CAAC,eAAe,GAC1B,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC;CAQ5B"}
|
package/dist.commonjs/signer.js
DELETED
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ReiSigner = void 0;
|
|
4
|
-
const core_1 = require("@ckb-ccc/core");
|
|
5
|
-
const advanced_1 = require("@ckb-ccc/core/advanced");
|
|
6
|
-
/**
|
|
7
|
-
* Class representing a CKB signer that extends Signer from @ckb-ccc/core.
|
|
8
|
-
* @public
|
|
9
|
-
*/
|
|
10
|
-
class ReiSigner extends core_1.ccc.Signer {
|
|
11
|
-
/**
|
|
12
|
-
* Creates an instance of Signer.
|
|
13
|
-
* @param client - The client instance.
|
|
14
|
-
* @param provider - The provider instance.
|
|
15
|
-
*/
|
|
16
|
-
constructor(client, provider) {
|
|
17
|
-
super(client);
|
|
18
|
-
this.provider = provider;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Register a listener to be called when this signer is replaced.
|
|
22
|
-
*
|
|
23
|
-
* @returns A function for unregister
|
|
24
|
-
*/
|
|
25
|
-
onReplaced(listener) {
|
|
26
|
-
const stop = [];
|
|
27
|
-
const replacer = async () => {
|
|
28
|
-
listener();
|
|
29
|
-
stop[0]?.();
|
|
30
|
-
};
|
|
31
|
-
stop.push(() => {
|
|
32
|
-
this.provider.off("accountsChanged", replacer);
|
|
33
|
-
this.provider.off("chainChanged", replacer);
|
|
34
|
-
});
|
|
35
|
-
this.provider.on("accountsChanged", replacer);
|
|
36
|
-
this.provider.on("chainChanged", replacer);
|
|
37
|
-
return stop[0];
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Gets the signer type.
|
|
41
|
-
* @returns The type of the signer.
|
|
42
|
-
*/
|
|
43
|
-
get type() {
|
|
44
|
-
return core_1.ccc.SignerType.CKB;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Gets the sign type.
|
|
48
|
-
* @returns The sign type.
|
|
49
|
-
*/
|
|
50
|
-
get signType() {
|
|
51
|
-
return core_1.ccc.SignerSignType.CkbSecp256k1;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Connects to the provider by requesting authentication.
|
|
55
|
-
* @returns A promise that resolves when the connection is established.
|
|
56
|
-
*/
|
|
57
|
-
async connect() {
|
|
58
|
-
const prefixClient = this.client.addressPrefix;
|
|
59
|
-
const netChange = await this._getNetworkChanged();
|
|
60
|
-
if (netChange) {
|
|
61
|
-
const data = prefixClient === "ckb" ? "mainnet" : "testnet";
|
|
62
|
-
await this.provider.request({ method: "ckb_switchNetwork", data });
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Checks if the signer is connected.
|
|
67
|
-
* @returns A promise that resolves to true if connected, false otherwise.
|
|
68
|
-
*/
|
|
69
|
-
async isConnected() {
|
|
70
|
-
const connected = await this.provider.isConnected();
|
|
71
|
-
if (!connected || (await this._getNetworkChanged())) {
|
|
72
|
-
return false;
|
|
73
|
-
}
|
|
74
|
-
return connected;
|
|
75
|
-
}
|
|
76
|
-
async _getNetworkChanged() {
|
|
77
|
-
const prefixClient = this.client.addressPrefix;
|
|
78
|
-
const address = await this.getInternalAddress();
|
|
79
|
-
const { prefix } = advanced_1.cccA.addressPayloadFromString(address);
|
|
80
|
-
return prefixClient !== prefix;
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Gets the internal address.
|
|
84
|
-
* @returns A promise that resolves to the internal address.
|
|
85
|
-
*/
|
|
86
|
-
async getInternalAddress() {
|
|
87
|
-
return this.provider.request({ method: "ckb_requestAccounts" });
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Gets the address object.
|
|
91
|
-
* @returns A promise that resolves to the address object.
|
|
92
|
-
*/
|
|
93
|
-
async getAddressObj() {
|
|
94
|
-
return core_1.ccc.Address.fromString(await this.getInternalAddress(), this.client);
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Gets the address objects.
|
|
98
|
-
* @returns A promise that resolves to an array of address objects.
|
|
99
|
-
*/
|
|
100
|
-
async getAddressObjs() {
|
|
101
|
-
return [await this.getAddressObj()];
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Gets the identity of the signer.
|
|
105
|
-
* @returns A promise that resolves to the identity.
|
|
106
|
-
*/
|
|
107
|
-
async getIdentity() {
|
|
108
|
-
return this.provider.request({
|
|
109
|
-
method: "ckb_getPublicKey",
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Signs a raw message with the personal account.
|
|
114
|
-
* @param message - The message to sign.
|
|
115
|
-
* @returns A promise that resolves to the signed message.
|
|
116
|
-
*/
|
|
117
|
-
async signMessageRaw(message) {
|
|
118
|
-
return this.provider.request({
|
|
119
|
-
method: "ckb_signMessage",
|
|
120
|
-
data: { message },
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* prepare a transaction before signing.
|
|
125
|
-
*
|
|
126
|
-
* @param txLike - The transaction to prepare, represented as a TransactionLike object.
|
|
127
|
-
* @returns A promise that resolves to the prepared Transaction object.
|
|
128
|
-
*/
|
|
129
|
-
async prepareTransaction(txLike) {
|
|
130
|
-
const tx = core_1.ccc.Transaction.from(txLike);
|
|
131
|
-
await tx.addCellDepsOfKnownScripts(this.client, core_1.ccc.KnownScript.Secp256k1Blake160);
|
|
132
|
-
return core_1.ccc.reduceAsync(await this.getAddressObjs(), (tx, { script }) => tx.prepareSighashAllWitness(script, 65, this.client), tx);
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Signs a transaction without preparing information for it.
|
|
136
|
-
*
|
|
137
|
-
* @param txLike - The transaction to sign, represented as a TransactionLike object.
|
|
138
|
-
* @returns A promise that resolves to the signed Transaction object.
|
|
139
|
-
*/
|
|
140
|
-
async signOnlyTransaction(txLike) {
|
|
141
|
-
const txFormat = advanced_1.cccA.JsonRpcTransformers.transactionFrom(txLike);
|
|
142
|
-
return this.provider.request({
|
|
143
|
-
method: "ckb_signTransaction",
|
|
144
|
-
data: { txSkeleton: txFormat },
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
exports.ReiSigner = ReiSigner;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { ccc } from "@ckb-ccc/core";
|
|
2
|
-
/**
|
|
3
|
-
* Retrieves the Rei signer if available.
|
|
4
|
-
* @param {ccc.Client} client - The client instance.
|
|
5
|
-
* @returns {Signer | undefined} The Signer instance if the Rei provider is available, otherwise undefined.
|
|
6
|
-
|
|
7
|
-
*/
|
|
8
|
-
export declare function getReiSigners(client: ccc.Client): ccc.SignerInfo[];
|
|
9
|
-
//# sourceMappingURL=signersFactory.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"signersFactory.d.ts","sourceRoot":"","sources":["../src/signersFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAIpC;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,UAAU,EAAE,CAYlE"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getReiSigners = getReiSigners;
|
|
4
|
-
const signer_js_1 = require("./signer.js");
|
|
5
|
-
/**
|
|
6
|
-
* Retrieves the Rei signer if available.
|
|
7
|
-
* @param {ccc.Client} client - The client instance.
|
|
8
|
-
* @returns {Signer | undefined} The Signer instance if the Rei provider is available, otherwise undefined.
|
|
9
|
-
|
|
10
|
-
*/
|
|
11
|
-
function getReiSigners(client) {
|
|
12
|
-
const windowRef = window;
|
|
13
|
-
if (typeof windowRef?.rei?.ckb === "undefined") {
|
|
14
|
-
return [];
|
|
15
|
-
}
|
|
16
|
-
return [
|
|
17
|
-
{
|
|
18
|
-
signer: new signer_js_1.ReiSigner(client, windowRef.rei.ckb),
|
|
19
|
-
name: "CKB",
|
|
20
|
-
},
|
|
21
|
-
];
|
|
22
|
-
}
|