@ckb-ccc/joy-id 0.0.5-alpha.7 → 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/btc/index.d.ts +46 -1
- package/dist/btc/index.d.ts.map +1 -1
- package/dist/btc/index.js +46 -3
- package/dist/ckb/index.d.ts +95 -2
- package/dist/ckb/index.d.ts.map +1 -1
- package/dist/ckb/index.js +98 -8
- package/dist/common/index.d.ts +13 -0
- package/dist/common/index.d.ts.map +1 -1
- package/dist/common/index.js +9 -0
- package/dist/connectionsStorage/index.d.ts +58 -0
- package/dist/connectionsStorage/index.d.ts.map +1 -1
- package/dist/connectionsStorage/index.js +30 -0
- package/dist/evm/index.d.ts +51 -1
- package/dist/evm/index.d.ts.map +1 -1
- package/dist/evm/index.js +52 -4
- package/dist/nostr/index.d.ts +51 -0
- package/dist/nostr/index.d.ts.map +1 -0
- package/dist/nostr/index.js +106 -0
- package/dist/signerFactory/index.d.ts +9 -0
- package/dist/signerFactory/index.d.ts.map +1 -1
- package/dist/signerFactory/index.js +20 -2
- package/dist.commonjs/btc/index.d.ts +46 -1
- package/dist.commonjs/btc/index.d.ts.map +1 -1
- package/dist.commonjs/btc/index.js +46 -3
- package/dist.commonjs/ckb/index.d.ts +95 -2
- package/dist.commonjs/ckb/index.d.ts.map +1 -1
- package/dist.commonjs/ckb/index.js +98 -8
- package/dist.commonjs/common/index.d.ts +13 -0
- package/dist.commonjs/common/index.d.ts.map +1 -1
- package/dist.commonjs/common/index.js +9 -0
- package/dist.commonjs/connectionsStorage/index.d.ts +58 -0
- package/dist.commonjs/connectionsStorage/index.d.ts.map +1 -1
- package/dist.commonjs/connectionsStorage/index.js +30 -0
- package/dist.commonjs/evm/index.d.ts +51 -1
- package/dist.commonjs/evm/index.d.ts.map +1 -1
- package/dist.commonjs/evm/index.js +52 -4
- package/dist.commonjs/nostr/index.d.ts +51 -0
- package/dist.commonjs/nostr/index.d.ts.map +1 -0
- package/dist.commonjs/nostr/index.js +110 -0
- package/dist.commonjs/signerFactory/index.d.ts +9 -0
- package/dist.commonjs/signerFactory/index.d.ts.map +1 -1
- package/dist.commonjs/signerFactory/index.js +20 -2
- package/package.json +3 -3
- package/src/btc/index.ts +47 -12
- package/src/ckb/index.ts +104 -19
- package/src/common/index.ts +13 -0
- package/src/connectionsStorage/index.ts +64 -2
- package/src/evm/index.ts +56 -15
- package/src/nostr/index.ts +135 -0
- package/src/signerFactory/index.ts +25 -2
package/dist/btc/index.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { ccc } from "@ckb-ccc/core";
|
|
2
2
|
import { ConnectionsRepo } from "../connectionsStorage";
|
|
3
|
+
/**
|
|
4
|
+
* Class representing a Bitcoin signer that extends SignerBtc from @ckb-ccc/core.
|
|
5
|
+
* @class
|
|
6
|
+
* @extends {ccc.SignerBtc}
|
|
7
|
+
*/
|
|
3
8
|
export declare class BitcoinSigner extends ccc.SignerBtc {
|
|
4
9
|
private readonly name;
|
|
5
10
|
private readonly icon;
|
|
@@ -7,14 +12,54 @@ export declare class BitcoinSigner extends ccc.SignerBtc {
|
|
|
7
12
|
private readonly appUri;
|
|
8
13
|
private readonly connectionsRepo;
|
|
9
14
|
private connection?;
|
|
15
|
+
/**
|
|
16
|
+
* Ensures that the signer is connected and returns the connection.
|
|
17
|
+
* @private
|
|
18
|
+
* @throws Will throw an error if not connected.
|
|
19
|
+
* @returns {Connection} The current connection.
|
|
20
|
+
*/
|
|
10
21
|
private assertConnection;
|
|
22
|
+
/**
|
|
23
|
+
* Creates an instance of BitcoinSigner.
|
|
24
|
+
* @param {ccc.Client} client - The client instance.
|
|
25
|
+
* @param {string} name - The name of the signer.
|
|
26
|
+
* @param {string} icon - The icon URL of the signer.
|
|
27
|
+
* @param {"auto" | "p2wpkh" | "p2tr"} [addressType="auto"] - The address type.
|
|
28
|
+
* @param {string} [appUri="https://app.joy.id"] - The application URI.
|
|
29
|
+
* @param {ConnectionsRepo} [connectionsRepo=new ConnectionsRepoLocalStorage()] - The connections repository.
|
|
30
|
+
*/
|
|
11
31
|
constructor(client: ccc.Client, name: string, icon: string, addressType?: "auto" | "p2wpkh" | "p2tr", appUri?: string, connectionsRepo?: ConnectionsRepo);
|
|
12
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Gets the configuration for JoyID.
|
|
34
|
+
* @private
|
|
35
|
+
* @returns {object} The configuration object.
|
|
36
|
+
*/
|
|
13
37
|
private getConfig;
|
|
38
|
+
/**
|
|
39
|
+
* Gets the Bitcoin account address.
|
|
40
|
+
* @returns {Promise<string>} A promise that resolves to the Bitcoin account address.
|
|
41
|
+
*/
|
|
14
42
|
getBtcAccount(): Promise<string>;
|
|
43
|
+
/**
|
|
44
|
+
* Gets the Bitcoin public key.
|
|
45
|
+
* @returns {Promise<ccc.Hex>} A promise that resolves to the Bitcoin public key.
|
|
46
|
+
*/
|
|
15
47
|
getBtcPublicKey(): Promise<ccc.Hex>;
|
|
48
|
+
/**
|
|
49
|
+
* Connects to the provider by requesting authentication.
|
|
50
|
+
* @returns {Promise<void>} A promise that resolves when the connection is established.
|
|
51
|
+
*/
|
|
16
52
|
connect(): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Checks if the signer is connected.
|
|
55
|
+
* @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
|
|
56
|
+
*/
|
|
17
57
|
isConnected(): Promise<boolean>;
|
|
58
|
+
/**
|
|
59
|
+
* Signs a raw message with the Bitcoin account.
|
|
60
|
+
* @param {string | ccc.BytesLike} message - The message to sign.
|
|
61
|
+
* @returns {Promise<string>} A promise that resolves to the signed message.
|
|
62
|
+
*/
|
|
18
63
|
signMessageRaw(message: string | ccc.BytesLike): Promise<string>;
|
|
19
64
|
}
|
|
20
65
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/btc/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","s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,CAAC,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC;CAsBvE"}
|
package/dist/btc/index.js
CHANGED
|
@@ -2,13 +2,33 @@ import { ccc } from "@ckb-ccc/core";
|
|
|
2
2
|
import { DappRequestType, buildJoyIDURL } from "@joyid/common";
|
|
3
3
|
import { createPopup } from "../common";
|
|
4
4
|
import { ConnectionsRepoLocalStorage, } from "../connectionsStorage";
|
|
5
|
+
/**
|
|
6
|
+
* Class representing a Bitcoin signer that extends SignerBtc from @ckb-ccc/core.
|
|
7
|
+
* @class
|
|
8
|
+
* @extends {ccc.SignerBtc}
|
|
9
|
+
*/
|
|
5
10
|
export class BitcoinSigner extends ccc.SignerBtc {
|
|
11
|
+
/**
|
|
12
|
+
* Ensures that the signer is connected and returns the connection.
|
|
13
|
+
* @private
|
|
14
|
+
* @throws Will throw an error if not connected.
|
|
15
|
+
* @returns {Connection} The current connection.
|
|
16
|
+
*/
|
|
6
17
|
assertConnection() {
|
|
7
18
|
if (!this.isConnected() || !this.connection) {
|
|
8
19
|
throw new Error("Not connected");
|
|
9
20
|
}
|
|
10
21
|
return this.connection;
|
|
11
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Creates an instance of BitcoinSigner.
|
|
25
|
+
* @param {ccc.Client} client - The client instance.
|
|
26
|
+
* @param {string} name - The name of the signer.
|
|
27
|
+
* @param {string} icon - The icon URL of the signer.
|
|
28
|
+
* @param {"auto" | "p2wpkh" | "p2tr"} [addressType="auto"] - The address type.
|
|
29
|
+
* @param {string} [appUri="https://app.joy.id"] - The application URI.
|
|
30
|
+
* @param {ConnectionsRepo} [connectionsRepo=new ConnectionsRepoLocalStorage()] - The connections repository.
|
|
31
|
+
*/
|
|
12
32
|
constructor(client, name, icon, addressType = "auto", appUri = "https://app.joy.id", connectionsRepo = new ConnectionsRepoLocalStorage()) {
|
|
13
33
|
super(client);
|
|
14
34
|
this.name = name;
|
|
@@ -17,9 +37,11 @@ export class BitcoinSigner extends ccc.SignerBtc {
|
|
|
17
37
|
this.appUri = appUri;
|
|
18
38
|
this.connectionsRepo = connectionsRepo;
|
|
19
39
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Gets the configuration for JoyID.
|
|
42
|
+
* @private
|
|
43
|
+
* @returns {object} The configuration object.
|
|
44
|
+
*/
|
|
23
45
|
getConfig() {
|
|
24
46
|
return {
|
|
25
47
|
redirectURL: location.href,
|
|
@@ -29,14 +51,26 @@ export class BitcoinSigner extends ccc.SignerBtc {
|
|
|
29
51
|
logo: this.icon,
|
|
30
52
|
};
|
|
31
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Gets the Bitcoin account address.
|
|
56
|
+
* @returns {Promise<string>} A promise that resolves to the Bitcoin account address.
|
|
57
|
+
*/
|
|
32
58
|
async getBtcAccount() {
|
|
33
59
|
const { address } = this.assertConnection();
|
|
34
60
|
return address;
|
|
35
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Gets the Bitcoin public key.
|
|
64
|
+
* @returns {Promise<ccc.Hex>} A promise that resolves to the Bitcoin public key.
|
|
65
|
+
*/
|
|
36
66
|
async getBtcPublicKey() {
|
|
37
67
|
const { publicKey } = this.assertConnection();
|
|
38
68
|
return publicKey;
|
|
39
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Connects to the provider by requesting authentication.
|
|
72
|
+
* @returns {Promise<void>} A promise that resolves when the connection is established.
|
|
73
|
+
*/
|
|
40
74
|
async connect() {
|
|
41
75
|
const config = this.getConfig();
|
|
42
76
|
const res = await createPopup(buildJoyIDURL(config, "popup", "/auth"), {
|
|
@@ -59,6 +93,10 @@ export class BitcoinSigner extends ccc.SignerBtc {
|
|
|
59
93
|
this.connectionsRepo.set({ uri: this.appUri, addressType: "btc-auto" }, this.connection),
|
|
60
94
|
]);
|
|
61
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Checks if the signer is connected.
|
|
98
|
+
* @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
|
|
99
|
+
*/
|
|
62
100
|
async isConnected() {
|
|
63
101
|
if (this.connection) {
|
|
64
102
|
return true;
|
|
@@ -69,6 +107,11 @@ export class BitcoinSigner extends ccc.SignerBtc {
|
|
|
69
107
|
});
|
|
70
108
|
return this.connection !== undefined;
|
|
71
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* Signs a raw message with the Bitcoin account.
|
|
112
|
+
* @param {string | ccc.BytesLike} message - The message to sign.
|
|
113
|
+
* @returns {Promise<string>} A promise that resolves to the signed message.
|
|
114
|
+
*/
|
|
72
115
|
async signMessageRaw(message) {
|
|
73
116
|
const { address } = this.assertConnection();
|
|
74
117
|
const challenge = typeof message === "string" ? message : ccc.hexFrom(message).slice(2);
|
package/dist/ckb/index.d.ts
CHANGED
|
@@ -1,31 +1,124 @@
|
|
|
1
1
|
import { ccc } from "@ckb-ccc/core";
|
|
2
2
|
import { ConnectionsRepo } from "../connectionsStorage";
|
|
3
|
+
/**
|
|
4
|
+
* Class representing a CKB signer that extends Signer from @ckb-ccc/core.
|
|
5
|
+
* @class
|
|
6
|
+
* @extends {ccc.Signer}
|
|
7
|
+
*/
|
|
3
8
|
export declare class CkbSigner extends ccc.Signer {
|
|
4
9
|
private readonly name;
|
|
5
10
|
private readonly icon;
|
|
6
11
|
private readonly _appUri?;
|
|
7
12
|
private readonly _aggregatorUri?;
|
|
8
13
|
private readonly connectionsRepo;
|
|
14
|
+
/**
|
|
15
|
+
* Gets the signer type.
|
|
16
|
+
* @returns {ccc.SignerType} The type of the signer.
|
|
17
|
+
*/
|
|
9
18
|
get type(): ccc.SignerType;
|
|
19
|
+
/**
|
|
20
|
+
* Gets the sign type.
|
|
21
|
+
* @returns {ccc.SignerSignType} The sign type.
|
|
22
|
+
*/
|
|
10
23
|
get signType(): ccc.SignerSignType;
|
|
11
24
|
private connection?;
|
|
25
|
+
/**
|
|
26
|
+
* Ensures that the signer is connected and returns the connection.
|
|
27
|
+
* @private
|
|
28
|
+
* @throws Will throw an error if not connected.
|
|
29
|
+
* @returns {Promise<Connection>} A promise that resolves to the current connection.
|
|
30
|
+
*/
|
|
12
31
|
private assertConnection;
|
|
32
|
+
/**
|
|
33
|
+
* Creates an instance of CkbSigner.
|
|
34
|
+
* @param {ccc.Client} client - The client instance.
|
|
35
|
+
* @param {string} name - The name of the signer.
|
|
36
|
+
* @param {string} icon - The icon URL of the signer.
|
|
37
|
+
* @param {string} [_appUri] - The application URI.
|
|
38
|
+
* @param {string} [_aggregatorUri] - The aggregator URI.
|
|
39
|
+
* @param {ConnectionsRepo} [connectionsRepo=new ConnectionsRepoLocalStorage()] - The connections repository.
|
|
40
|
+
*/
|
|
13
41
|
constructor(client: ccc.Client, name: string, icon: string, _appUri?: string | undefined, _aggregatorUri?: string | undefined, connectionsRepo?: ConnectionsRepo);
|
|
14
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Gets the configuration for JoyID.
|
|
44
|
+
* @private
|
|
45
|
+
* @returns {object} The configuration object.
|
|
46
|
+
*/
|
|
15
47
|
private getConfig;
|
|
48
|
+
/**
|
|
49
|
+
* Gets the aggregator URI.
|
|
50
|
+
* @private
|
|
51
|
+
* @returns {string} The aggregator URI.
|
|
52
|
+
*/
|
|
16
53
|
private getAggregatorUri;
|
|
54
|
+
/**
|
|
55
|
+
* Connects to the provider by requesting authentication.
|
|
56
|
+
* @returns {Promise<void>} A promise that resolves when the connection is established.
|
|
57
|
+
*/
|
|
17
58
|
connect(): Promise<void>;
|
|
18
|
-
|
|
59
|
+
/**
|
|
60
|
+
* Checks if the signer is connected.
|
|
61
|
+
* @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
|
|
62
|
+
*/
|
|
19
63
|
isConnected(): Promise<boolean>;
|
|
64
|
+
/**
|
|
65
|
+
* Gets the internal address.
|
|
66
|
+
* @returns {Promise<string>} A promise that resolves to the internal address.
|
|
67
|
+
*/
|
|
20
68
|
getInternalAddress(): Promise<string>;
|
|
69
|
+
/**
|
|
70
|
+
* Gets the identity of the signer.
|
|
71
|
+
* @returns {Promise<string>} A promise that resolves to the identity.
|
|
72
|
+
*/
|
|
21
73
|
getIdentity(): Promise<string>;
|
|
74
|
+
/**
|
|
75
|
+
* Gets the address object.
|
|
76
|
+
* @returns {Promise<ccc.Address>} A promise that resolves to the address object.
|
|
77
|
+
*/
|
|
22
78
|
getAddressObj(): Promise<ccc.Address>;
|
|
79
|
+
/**
|
|
80
|
+
* Gets the address objects.
|
|
81
|
+
* @returns {Promise<ccc.Address[]>} A promise that resolves to an array of address objects.
|
|
82
|
+
*/
|
|
23
83
|
getAddressObjs(): Promise<ccc.Address[]>;
|
|
84
|
+
/**
|
|
85
|
+
* Prepares a transaction.
|
|
86
|
+
* @param {ccc.TransactionLike} txLike - The transaction-like object.
|
|
87
|
+
* @returns {Promise<ccc.Transaction>} A promise that resolves to the prepared transaction.
|
|
88
|
+
*/
|
|
24
89
|
prepareTransaction(txLike: ccc.TransactionLike): Promise<ccc.Transaction>;
|
|
90
|
+
/**
|
|
91
|
+
* Prepares a transaction for a sub key.
|
|
92
|
+
* @private
|
|
93
|
+
* @param {ccc.Transaction} tx - The transaction object.
|
|
94
|
+
* @param {ccc.WitnessArgs} witness - The witness arguments.
|
|
95
|
+
* @returns {Promise<void>}
|
|
96
|
+
* @throws Will throw an error if no COTA cells are found for the sub key wallet.
|
|
97
|
+
*/
|
|
25
98
|
private prepareTransactionForSubKey;
|
|
99
|
+
/**
|
|
100
|
+
* Signs a transaction.
|
|
101
|
+
* @param {ccc.TransactionLike} txLike - The transaction-like object.
|
|
102
|
+
* @returns {Promise<ccc.Transaction>} A promise that resolves to the signed transaction.
|
|
103
|
+
*/
|
|
26
104
|
signOnlyTransaction(txLike: ccc.TransactionLike): Promise<ccc.Transaction>;
|
|
105
|
+
/**
|
|
106
|
+
* Signs a raw message with the account.
|
|
107
|
+
* @param {string | ccc.BytesLike} message - The message to sign.
|
|
108
|
+
* @returns {Promise<string>} A promise that resolves to the signed message.
|
|
109
|
+
*/
|
|
27
110
|
signMessageRaw(message: string | ccc.BytesLike): Promise<string>;
|
|
111
|
+
/**
|
|
112
|
+
* Saves the current connection.
|
|
113
|
+
* @private
|
|
114
|
+
* @returns {Promise<void>}
|
|
115
|
+
*/
|
|
28
116
|
private saveConnection;
|
|
117
|
+
/**
|
|
118
|
+
* Restores the previous connection.
|
|
119
|
+
* @private
|
|
120
|
+
* @returns {Promise<void>}
|
|
121
|
+
*/
|
|
29
122
|
private restoreConnection;
|
|
30
123
|
}
|
|
31
124
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/ckb/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ckb/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAIpC,OAAO,EAEL,eAAe,EAEhB,MAAM,uBAAuB,CAAC;AAE/B,qBAAa,SAAU,SAAQ,GAAG,CAAC,MAAM;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ckb/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAIpC,OAAO,EAEL,eAAe,EAEhB,MAAM,uBAAuB,CAAC;AAE/B;;;;GAIG;AACH,qBAAa,SAAU,SAAQ,GAAG,CAAC,MAAM;IA4CrC,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC;IACzB,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC;IAChC,OAAO,CAAC,QAAQ,CAAC,eAAe;IA/ClC;;;OAGG;IACH,IAAI,IAAI,IAAI,GAAG,CAAC,UAAU,CAEzB;IAED;;;OAGG;IACH,IAAI,QAAQ,IAAI,GAAG,CAAC,cAAc,CAEjC;IAED,OAAO,CAAC,UAAU,CAAC,CAAa;IAEhC;;;;;OAKG;YACW,gBAAgB;IAQ9B;;;;;;;;OAQG;gBAED,MAAM,EAAE,GAAG,CAAC,MAAM,EACD,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,oBAAQ,EAChB,cAAc,CAAC,oBAAQ,EACvB,eAAe,GAAE,eAAmD;IAKvF;;;;OAIG;IACH,OAAO,CAAC,SAAS;IAYjB;;;;OAIG;IACH,OAAO,CAAC,gBAAgB;IAUxB;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAgB9B;;;OAGG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAQrC;;;OAGG;IACG,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAI3C;;;OAGG;IACG,WAAW,IAAI,OAAO,CAAC,MAAM,CAAC;IAQpC;;;OAGG;IACG,aAAa,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC;IAO3C;;;OAGG;IACG,cAAc,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;IAI9C;;;;OAIG;IACG,kBAAkB,CACtB,MAAM,EAAE,GAAG,CAAC,eAAe,GAC1B,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC;IAkB3B;;;;;;;OAOG;YACW,2BAA2B;IAuCzC;;;;OAIG;IACG,mBAAmB,CACvB,MAAM,EAAE,GAAG,CAAC,eAAe,GAC1B,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC;IA6B3B;;;;OAIG;IACG,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAC,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC;IA2BtE;;;;OAIG;YACW,cAAc;IAU5B;;;;OAIG;YACW,iBAAiB;CAMhC"}
|
package/dist/ckb/index.js
CHANGED
|
@@ -3,19 +3,47 @@ import { Aggregator } from "@joyid/ckb";
|
|
|
3
3
|
import { DappRequestType, buildJoyIDURL } from "@joyid/common";
|
|
4
4
|
import { createPopup } from "../common";
|
|
5
5
|
import { ConnectionsRepoLocalStorage, } from "../connectionsStorage";
|
|
6
|
+
/**
|
|
7
|
+
* Class representing a CKB signer that extends Signer from @ckb-ccc/core.
|
|
8
|
+
* @class
|
|
9
|
+
* @extends {ccc.Signer}
|
|
10
|
+
*/
|
|
6
11
|
export class CkbSigner extends ccc.Signer {
|
|
12
|
+
/**
|
|
13
|
+
* Gets the signer type.
|
|
14
|
+
* @returns {ccc.SignerType} The type of the signer.
|
|
15
|
+
*/
|
|
7
16
|
get type() {
|
|
8
17
|
return ccc.SignerType.CKB;
|
|
9
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Gets the sign type.
|
|
21
|
+
* @returns {ccc.SignerSignType} The sign type.
|
|
22
|
+
*/
|
|
10
23
|
get signType() {
|
|
11
24
|
return ccc.SignerSignType.JoyId;
|
|
12
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Ensures that the signer is connected and returns the connection.
|
|
28
|
+
* @private
|
|
29
|
+
* @throws Will throw an error if not connected.
|
|
30
|
+
* @returns {Promise<Connection>} A promise that resolves to the current connection.
|
|
31
|
+
*/
|
|
13
32
|
async assertConnection() {
|
|
14
33
|
if (!(await this.isConnected()) || !this.connection) {
|
|
15
34
|
throw new Error("Not connected");
|
|
16
35
|
}
|
|
17
36
|
return this.connection;
|
|
18
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Creates an instance of CkbSigner.
|
|
40
|
+
* @param {ccc.Client} client - The client instance.
|
|
41
|
+
* @param {string} name - The name of the signer.
|
|
42
|
+
* @param {string} icon - The icon URL of the signer.
|
|
43
|
+
* @param {string} [_appUri] - The application URI.
|
|
44
|
+
* @param {string} [_aggregatorUri] - The aggregator URI.
|
|
45
|
+
* @param {ConnectionsRepo} [connectionsRepo=new ConnectionsRepoLocalStorage()] - The connections repository.
|
|
46
|
+
*/
|
|
19
47
|
constructor(client, name, icon, _appUri, _aggregatorUri, connectionsRepo = new ConnectionsRepoLocalStorage()) {
|
|
20
48
|
super(client);
|
|
21
49
|
this.name = name;
|
|
@@ -24,9 +52,11 @@ export class CkbSigner extends ccc.Signer {
|
|
|
24
52
|
this._aggregatorUri = _aggregatorUri;
|
|
25
53
|
this.connectionsRepo = connectionsRepo;
|
|
26
54
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
55
|
+
/**
|
|
56
|
+
* Gets the configuration for JoyID.
|
|
57
|
+
* @private
|
|
58
|
+
* @returns {object} The configuration object.
|
|
59
|
+
*/
|
|
30
60
|
getConfig() {
|
|
31
61
|
return {
|
|
32
62
|
redirectURL: location.href,
|
|
@@ -37,6 +67,11 @@ export class CkbSigner extends ccc.Signer {
|
|
|
37
67
|
logo: this.icon,
|
|
38
68
|
};
|
|
39
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Gets the aggregator URI.
|
|
72
|
+
* @private
|
|
73
|
+
* @returns {string} The aggregator URI.
|
|
74
|
+
*/
|
|
40
75
|
getAggregatorUri() {
|
|
41
76
|
if (this._aggregatorUri) {
|
|
42
77
|
return this._aggregatorUri;
|
|
@@ -45,6 +80,10 @@ export class CkbSigner extends ccc.Signer {
|
|
|
45
80
|
? "https://cota.nervina.dev/mainnet-aggregator"
|
|
46
81
|
: "https://cota.nervina.dev/aggregator";
|
|
47
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Connects to the provider by requesting authentication.
|
|
85
|
+
* @returns {Promise<void>} A promise that resolves when the connection is established.
|
|
86
|
+
*/
|
|
48
87
|
async connect() {
|
|
49
88
|
const config = this.getConfig();
|
|
50
89
|
const res = await createPopup(buildJoyIDURL(config, "popup", "/auth"), {
|
|
@@ -58,10 +97,10 @@ export class CkbSigner extends ccc.Signer {
|
|
|
58
97
|
};
|
|
59
98
|
await this.saveConnection();
|
|
60
99
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
100
|
+
/**
|
|
101
|
+
* Checks if the signer is connected.
|
|
102
|
+
* @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
|
|
103
|
+
*/
|
|
65
104
|
async isConnected() {
|
|
66
105
|
if (this.connection) {
|
|
67
106
|
return true;
|
|
@@ -69,9 +108,17 @@ export class CkbSigner extends ccc.Signer {
|
|
|
69
108
|
await this.restoreConnection();
|
|
70
109
|
return this.connection !== undefined;
|
|
71
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* Gets the internal address.
|
|
113
|
+
* @returns {Promise<string>} A promise that resolves to the internal address.
|
|
114
|
+
*/
|
|
72
115
|
async getInternalAddress() {
|
|
73
116
|
return (await this.assertConnection()).address;
|
|
74
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* Gets the identity of the signer.
|
|
120
|
+
* @returns {Promise<string>} A promise that resolves to the identity.
|
|
121
|
+
*/
|
|
75
122
|
async getIdentity() {
|
|
76
123
|
const connection = await this.assertConnection();
|
|
77
124
|
return JSON.stringify({
|
|
@@ -79,12 +126,25 @@ export class CkbSigner extends ccc.Signer {
|
|
|
79
126
|
publicKey: connection.publicKey.slice(2),
|
|
80
127
|
});
|
|
81
128
|
}
|
|
129
|
+
/**
|
|
130
|
+
* Gets the address object.
|
|
131
|
+
* @returns {Promise<ccc.Address>} A promise that resolves to the address object.
|
|
132
|
+
*/
|
|
82
133
|
async getAddressObj() {
|
|
83
134
|
return await ccc.Address.fromString(await this.getInternalAddress(), this.client);
|
|
84
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* Gets the address objects.
|
|
138
|
+
* @returns {Promise<ccc.Address[]>} A promise that resolves to an array of address objects.
|
|
139
|
+
*/
|
|
85
140
|
async getAddressObjs() {
|
|
86
141
|
return [await this.getAddressObj()];
|
|
87
142
|
}
|
|
143
|
+
/**
|
|
144
|
+
* Prepares a transaction.
|
|
145
|
+
* @param {ccc.TransactionLike} txLike - The transaction-like object.
|
|
146
|
+
* @returns {Promise<ccc.Transaction>} A promise that resolves to the prepared transaction.
|
|
147
|
+
*/
|
|
88
148
|
async prepareTransaction(txLike) {
|
|
89
149
|
const tx = ccc.Transaction.from(txLike);
|
|
90
150
|
const position = await tx.findInputIndexByLock((await this.getAddressObj()).script, this.client);
|
|
@@ -94,8 +154,17 @@ export class CkbSigner extends ccc.Signer {
|
|
|
94
154
|
const witness = tx.getWitnessArgsAt(position) ?? ccc.WitnessArgs.from({});
|
|
95
155
|
witness.lock = "0x";
|
|
96
156
|
await this.prepareTransactionForSubKey(tx, witness);
|
|
97
|
-
|
|
157
|
+
tx.setWitnessArgsAt(position, witness);
|
|
158
|
+
return tx;
|
|
98
159
|
}
|
|
160
|
+
/**
|
|
161
|
+
* Prepares a transaction for a sub key.
|
|
162
|
+
* @private
|
|
163
|
+
* @param {ccc.Transaction} tx - The transaction object.
|
|
164
|
+
* @param {ccc.WitnessArgs} witness - The witness arguments.
|
|
165
|
+
* @returns {Promise<void>}
|
|
166
|
+
* @throws Will throw an error if no COTA cells are found for the sub key wallet.
|
|
167
|
+
*/
|
|
99
168
|
async prepareTransactionForSubKey(tx, witness) {
|
|
100
169
|
if (this.connection?.keyType !== "sub_key") {
|
|
101
170
|
return [];
|
|
@@ -124,6 +193,11 @@ export class CkbSigner extends ccc.Signer {
|
|
|
124
193
|
}
|
|
125
194
|
tx.cellDeps.unshift(...cotaDeps);
|
|
126
195
|
}
|
|
196
|
+
/**
|
|
197
|
+
* Signs a transaction.
|
|
198
|
+
* @param {ccc.TransactionLike} txLike - The transaction-like object.
|
|
199
|
+
* @returns {Promise<ccc.Transaction>} A promise that resolves to the signed transaction.
|
|
200
|
+
*/
|
|
127
201
|
async signOnlyTransaction(txLike) {
|
|
128
202
|
const tx = ccc.Transaction.from(txLike);
|
|
129
203
|
const { script } = await this.getAddressObj();
|
|
@@ -133,12 +207,18 @@ export class CkbSigner extends ccc.Signer {
|
|
|
133
207
|
tx: JSON.parse(tx.stringify()),
|
|
134
208
|
signerAddress: (await this.assertConnection()).address,
|
|
135
209
|
witnessIndex: await tx.findInputIndexByLock(script, this.client),
|
|
210
|
+
witnessLastIndex: await tx.findLastInputIndexByLock(script, this.client),
|
|
136
211
|
}, "popup", "/sign-ckb-raw-tx"), {
|
|
137
212
|
...config,
|
|
138
213
|
type: DappRequestType.SignCkbRawTx,
|
|
139
214
|
});
|
|
140
215
|
return ccc.Transaction.from(res.tx);
|
|
141
216
|
}
|
|
217
|
+
/**
|
|
218
|
+
* Signs a raw message with the account.
|
|
219
|
+
* @param {string | ccc.BytesLike} message - The message to sign.
|
|
220
|
+
* @returns {Promise<string>} A promise that resolves to the signed message.
|
|
221
|
+
*/
|
|
142
222
|
async signMessageRaw(message) {
|
|
143
223
|
const { address } = await this.assertConnection();
|
|
144
224
|
const challenge = typeof message === "string" ? message : ccc.hexFrom(message).slice(2);
|
|
@@ -155,12 +235,22 @@ export class CkbSigner extends ccc.Signer {
|
|
|
155
235
|
message: res.message,
|
|
156
236
|
});
|
|
157
237
|
}
|
|
238
|
+
/**
|
|
239
|
+
* Saves the current connection.
|
|
240
|
+
* @private
|
|
241
|
+
* @returns {Promise<void>}
|
|
242
|
+
*/
|
|
158
243
|
async saveConnection() {
|
|
159
244
|
return this.connectionsRepo.set({
|
|
160
245
|
uri: this.getConfig().joyidAppURL,
|
|
161
246
|
addressType: "ckb",
|
|
162
247
|
}, this.connection);
|
|
163
248
|
}
|
|
249
|
+
/**
|
|
250
|
+
* Restores the previous connection.
|
|
251
|
+
* @private
|
|
252
|
+
* @returns {Promise<void>}
|
|
253
|
+
*/
|
|
164
254
|
async restoreConnection() {
|
|
165
255
|
this.connection = await this.connectionsRepo.get({
|
|
166
256
|
uri: this.getConfig().joyidAppURL,
|
package/dist/common/index.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { AuthResponseData, DappRequestType, EvmWeb2LoginResponse, PopupConfigOptions, SignCkbTxResponseData, SignCotaNFTResponseData, SignEvmTxResponseData, SignMessageResponseData, SignNostrEventData } from "@joyid/common";
|
|
2
|
+
/**
|
|
3
|
+
* Interface representing the return type for various Dapp request types.
|
|
4
|
+
* @interface
|
|
5
|
+
*/
|
|
2
6
|
export interface PopupReturnType {
|
|
3
7
|
[DappRequestType.Auth]: AuthResponseData;
|
|
4
8
|
[DappRequestType.SignMessage]: SignMessageResponseData;
|
|
@@ -18,6 +22,15 @@ export interface PopupReturnType {
|
|
|
18
22
|
[DappRequestType.SignMiniAppMessage]: any;
|
|
19
23
|
[DappRequestType.EvmWeb2Login]: EvmWeb2LoginResponse;
|
|
20
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Creates a popup window for JoyID Dapp requests.
|
|
27
|
+
* @param {string} url - The URL to open in the popup.
|
|
28
|
+
* @param {PopupConfigOptions<T> & { joyidAppURL: string }} config - The popup configuration options.
|
|
29
|
+
* @returns {Promise<PopupReturnType[T]>} A promise that resolves to the response data of the requested type.
|
|
30
|
+
* @throws {PopupNotSupportedError} If popups are not supported in the current browser.
|
|
31
|
+
* @throws {PopupCancelledError} If the popup is closed by the user.
|
|
32
|
+
* @throws {PopupTimeoutError} If the popup operation times out.
|
|
33
|
+
*/
|
|
21
34
|
export declare function createPopup<T extends DappRequestType>(url: string, config: PopupConfigOptions<T> & {
|
|
22
35
|
joyidAppURL: string;
|
|
23
36
|
}): Promise<PopupReturnType[T]>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,oBAAoB,EAEpB,kBAAkB,EAGlB,qBAAqB,EACrB,uBAAuB,EACvB,qBAAqB,EACrB,uBAAuB,EACvB,kBAAkB,EAInB,MAAM,eAAe,CAAC;AAEvB,MAAM,WAAW,eAAe;IAC9B,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE,gBAAgB,CAAC;IACzC,CAAC,eAAe,CAAC,WAAW,CAAC,EAAE,uBAAuB,CAAC;IACvD,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE,qBAAqB,CAAC;IACjD,CAAC,eAAe,CAAC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AgB,CAAC;IACzC,CAAC,eAAe,CAAC,WAAW,CAAC,EAAE,uBAAuB,CAAC;IACvD,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE,qBAAqB,CAAC;IACjD,CAAC,eAAe,CAAC,QAAQ,CAAC,EAAE,qBAAqB,CAAC;IAClD,CAAC,eAAe,CAAC,aAAa,CAAC,EAAE;QAC/B,KAAK,EAAE,MAAM,EAAE,CAAC;KACjB,CAAC;IACF,CAAC,eAAe,CAAC,SAAS,CAAC,EAAE,qBAAqB,CAAC;IACnD,CAAC,eAAe,CAAC,WAAW,CAAC,EAAE,uBAAuB,CAAC;IACvD,CAAC,eAAe,CAAC,YAAY,CAAC,EAAE,qBAAqB,CAAC;IACtD,CAAC,eAAe,CAAC,cAAc,CAAC,EAAE,kBAAkB,CAAC;IACrD,CAAC,eAAe,CAAC,mBAAmB,CAAC,EAAE,GAAG,CAAC;IAC3C,CAAC,eAAe,CAAC,mBAAmB,CAAC,EAAE,GAAG,CAAC;IAC3C,CAAC,eAAe,CAAC,WAAW,CAAC,EAAE,GAAG,CAAC;IACnC,CAAC,eAAe,CAAC,cAAc,CAAC,EAAE,GAAG,CAAC;IACtC,CAAC,eAAe,CAAC,kBAAkB,CAAC,EAAE,GAAG,CAAC;IAC1C,CAAC,eAAe,CAAC,YAAY,CAAC,EAAE,oBAAoB,CAAC;CACtD;AAED;;;;;;;;GAQG;AACH,wBAAsB,WAAW,CAAC,CAAC,SAAS,eAAe,EACzD,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAAC,GAAG;IAAE,WAAW,EAAE,MAAM,CAAA;CAAE,GACtD,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CA0D7B"}
|
package/dist/common/index.js
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
import { DappRequestType, PopupCancelledError, PopupNotSupportedError, PopupTimeoutError, createBlockDialog, isStandaloneBrowser, openPopup, } from "@joyid/common";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a popup window for JoyID Dapp requests.
|
|
4
|
+
* @param {string} url - The URL to open in the popup.
|
|
5
|
+
* @param {PopupConfigOptions<T> & { joyidAppURL: string }} config - The popup configuration options.
|
|
6
|
+
* @returns {Promise<PopupReturnType[T]>} A promise that resolves to the response data of the requested type.
|
|
7
|
+
* @throws {PopupNotSupportedError} If popups are not supported in the current browser.
|
|
8
|
+
* @throws {PopupCancelledError} If the popup is closed by the user.
|
|
9
|
+
* @throws {PopupTimeoutError} If the popup operation times out.
|
|
10
|
+
*/
|
|
2
11
|
export async function createPopup(url, config) {
|
|
3
12
|
if (config.popup == null) {
|
|
4
13
|
config.popup = openPopup("");
|
|
@@ -1,23 +1,81 @@
|
|
|
1
1
|
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
/**
|
|
3
|
+
* Type representing an account selector with a URI and address type.
|
|
4
|
+
* @typedef {Object} AccountSelector
|
|
5
|
+
* @property {string} uri - The URI of the account.
|
|
6
|
+
* @property {string} addressType - The address type of the account.
|
|
7
|
+
*/
|
|
2
8
|
export type AccountSelector = {
|
|
3
9
|
uri: string;
|
|
4
10
|
addressType: string;
|
|
5
11
|
};
|
|
12
|
+
/**
|
|
13
|
+
* Checks if two AccountSelectors are equal.
|
|
14
|
+
* @param {AccountSelector} a - The first account selector.
|
|
15
|
+
* @param {AccountSelector} b - The second account selector.
|
|
16
|
+
* @returns {boolean} True if the selectors are equal, false otherwise.
|
|
17
|
+
*/
|
|
6
18
|
export declare function isSelectorEq(a: AccountSelector, b: AccountSelector): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Type representing a connection with an address, public key, and key type.
|
|
21
|
+
* @typedef {Object} Connection
|
|
22
|
+
* @property {string} address - The address of the connection.
|
|
23
|
+
* @property {ccc.Hex} publicKey - The public key of the connection.
|
|
24
|
+
* @property {string} keyType - The key type of the connection.
|
|
25
|
+
*/
|
|
7
26
|
export type Connection = {
|
|
8
27
|
readonly address: string;
|
|
9
28
|
readonly publicKey: ccc.Hex;
|
|
10
29
|
readonly keyType: string;
|
|
11
30
|
};
|
|
31
|
+
/**
|
|
32
|
+
* Interface representing a repository for managing connections.
|
|
33
|
+
* @interface
|
|
34
|
+
*/
|
|
12
35
|
export interface ConnectionsRepo {
|
|
36
|
+
/**
|
|
37
|
+
* Gets a connection for the given selector.
|
|
38
|
+
* @param {AccountSelector} selector - The account selector.
|
|
39
|
+
* @returns {Promise<Connection | undefined>} A promise that resolves to the connection, if found.
|
|
40
|
+
*/
|
|
13
41
|
get(selector: AccountSelector): Promise<Connection | undefined>;
|
|
42
|
+
/**
|
|
43
|
+
* Sets a connection for the given selector.
|
|
44
|
+
* @param {AccountSelector} selector - The account selector.
|
|
45
|
+
* @param {Connection | undefined} connection - The connection to set.
|
|
46
|
+
* @returns {Promise<void>} A promise that resolves when the connection is set.
|
|
47
|
+
*/
|
|
14
48
|
set(selector: AccountSelector, connection: Connection | undefined): Promise<void>;
|
|
15
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Class representing a local storage-based repository for managing connections.
|
|
52
|
+
* @class
|
|
53
|
+
* @implements {ConnectionsRepo}
|
|
54
|
+
*/
|
|
16
55
|
export declare class ConnectionsRepoLocalStorage implements ConnectionsRepo {
|
|
17
56
|
private readonly storageKey;
|
|
57
|
+
/**
|
|
58
|
+
* Creates an instance of ConnectionsRepoLocalStorage.
|
|
59
|
+
* @param {string} [storageKey="ccc-joy-id-signer"] - The local storage key.
|
|
60
|
+
*/
|
|
18
61
|
constructor(storageKey?: string);
|
|
62
|
+
/**
|
|
63
|
+
* Reads all connections from local storage.
|
|
64
|
+
* @returns {Promise<[AccountSelector, Connection][]>} A promise that resolves to an array of selectors and connections.
|
|
65
|
+
*/
|
|
19
66
|
readConnections(): Promise<[AccountSelector, Connection][]>;
|
|
67
|
+
/**
|
|
68
|
+
* Gets a connection for the given selector.
|
|
69
|
+
* @param {AccountSelector} selector - The account selector.
|
|
70
|
+
* @returns {Promise<Connection | undefined>} A promise that resolves to the connection, if found.
|
|
71
|
+
*/
|
|
20
72
|
get(selector: AccountSelector): Promise<Connection | undefined>;
|
|
73
|
+
/**
|
|
74
|
+
* Sets a connection for the given selector.
|
|
75
|
+
* @param {AccountSelector} selector - The account selector.
|
|
76
|
+
* @param {Connection | undefined} connection - The connection to set.
|
|
77
|
+
* @returns {Promise<void>}
|
|
78
|
+
*/
|
|
21
79
|
set(selector: AccountSelector, connection: Connection | undefined): Promise<void>;
|
|
22
80
|
}
|
|
23
81
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/connectionsStorage/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEpC,MAAM,MAAM,eAAe,GAAG;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,wBAAgB,YAAY,CAAC,CAAC,EAAE,eAAe,EAAE,CAAC,EAAE,eAAe,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/connectionsStorage/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEpC;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,eAAe,EAAE,CAAC,EAAE,eAAe,GAAG,OAAO,CAE5E;AAED;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,GAAG,CAAC,GAAG,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF;;;GAGG;AACH,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