@ckb-ccc/joy-id 0.0.5-alpha.8 → 0.0.7-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 +94 -2
- package/dist/ckb/index.d.ts.map +1 -1
- package/dist/ckb/index.js +115 -14
- 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 +14 -0
- package/dist.commonjs/advanced.d.ts +1 -1
- package/dist.commonjs/advanced.js +40 -19
- package/dist.commonjs/advancedBarrel.d.ts +1 -1
- package/dist.commonjs/advancedBarrel.js +30 -14
- package/dist.commonjs/barrel.d.ts +1 -1
- package/dist.commonjs/barrel.js +30 -14
- package/dist.commonjs/btc/index.d.ts +68 -16
- package/dist.commonjs/btc/index.d.ts.map +1 -1
- package/dist.commonjs/btc/index.js +145 -76
- package/dist.commonjs/ckb/index.d.ts +126 -27
- package/dist.commonjs/ckb/index.d.ts.map +1 -1
- package/dist.commonjs/ckb/index.js +312 -154
- package/dist.commonjs/common/index.d.ts +47 -21
- package/dist.commonjs/common/index.d.ts.map +1 -1
- package/dist.commonjs/common/index.js +59 -45
- package/dist.commonjs/connectionsStorage/index.d.ts +81 -14
- package/dist.commonjs/connectionsStorage/index.d.ts.map +1 -1
- package/dist.commonjs/connectionsStorage/index.js +58 -25
- package/dist.commonjs/evm/index.d.ts +72 -16
- package/dist.commonjs/evm/index.d.ts.map +1 -1
- package/dist.commonjs/evm/index.js +140 -70
- package/dist.commonjs/index.d.ts +1 -1
- package/dist.commonjs/index.js +40 -19
- package/dist.commonjs/nostr/index.d.ts +57 -0
- package/dist.commonjs/nostr/index.d.ts.map +1 -0
- package/dist.commonjs/nostr/index.js +129 -0
- package/dist.commonjs/signerFactory/index.d.ts +15 -2
- package/dist.commonjs/signerFactory/index.d.ts.map +1 -1
- package/dist.commonjs/signerFactory/index.js +52 -27
- package/package.json +5 -5
- package/src/btc/index.ts +47 -12
- package/src/ckb/index.ts +127 -25
- 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 +14 -0
|
@@ -6,169 +6,327 @@ const ckb_1 = require("@joyid/ckb");
|
|
|
6
6
|
const common_1 = require("@joyid/common");
|
|
7
7
|
const common_2 = require("../common");
|
|
8
8
|
const connectionsStorage_1 = require("../connectionsStorage");
|
|
9
|
+
/**
|
|
10
|
+
* Class representing a CKB signer that extends Signer from @ckb-ccc/core.
|
|
11
|
+
* @class
|
|
12
|
+
* @extends {ccc.Signer}
|
|
13
|
+
*/
|
|
9
14
|
class CkbSigner extends core_1.ccc.Signer {
|
|
10
|
-
|
|
11
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Gets the signer type.
|
|
17
|
+
* @returns {ccc.SignerType} The type of the signer.
|
|
18
|
+
*/
|
|
19
|
+
get type() {
|
|
20
|
+
return core_1.ccc.SignerType.CKB;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Gets the sign type.
|
|
24
|
+
* @returns {ccc.SignerSignType} The sign type.
|
|
25
|
+
*/
|
|
26
|
+
get signType() {
|
|
27
|
+
return core_1.ccc.SignerSignType.JoyId;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Ensures that the signer is connected and returns the connection.
|
|
31
|
+
* @private
|
|
32
|
+
* @throws Will throw an error if not connected.
|
|
33
|
+
* @returns {Promise<Connection>} A promise that resolves to the current connection.
|
|
34
|
+
*/
|
|
35
|
+
async assertConnection() {
|
|
36
|
+
if (!(await this.isConnected()) || !this.connection) {
|
|
37
|
+
throw new Error("Not connected");
|
|
12
38
|
}
|
|
13
|
-
|
|
14
|
-
|
|
39
|
+
return this.connection;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Creates an instance of CkbSigner.
|
|
43
|
+
* @param {ccc.Client} client - The client instance.
|
|
44
|
+
* @param {string} name - The name of the signer.
|
|
45
|
+
* @param {string} icon - The icon URL of the signer.
|
|
46
|
+
* @param {string} [_appUri] - The application URI.
|
|
47
|
+
* @param {string} [_aggregatorUri] - The aggregator URI.
|
|
48
|
+
* @param {ConnectionsRepo} [connectionsRepo=new ConnectionsRepoLocalStorage()] - The connections repository.
|
|
49
|
+
*/
|
|
50
|
+
constructor(
|
|
51
|
+
client,
|
|
52
|
+
name,
|
|
53
|
+
icon,
|
|
54
|
+
_appUri,
|
|
55
|
+
_aggregatorUri,
|
|
56
|
+
connectionsRepo = new connectionsStorage_1.ConnectionsRepoLocalStorage(),
|
|
57
|
+
) {
|
|
58
|
+
super(client);
|
|
59
|
+
this.name = name;
|
|
60
|
+
this.icon = icon;
|
|
61
|
+
this._appUri = _appUri;
|
|
62
|
+
this._aggregatorUri = _aggregatorUri;
|
|
63
|
+
this.connectionsRepo = connectionsRepo;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Gets the configuration for JoyID.
|
|
67
|
+
* @private
|
|
68
|
+
* @returns {object} The configuration object.
|
|
69
|
+
*/
|
|
70
|
+
getConfig() {
|
|
71
|
+
return {
|
|
72
|
+
redirectURL: location.href,
|
|
73
|
+
joyidAppURL:
|
|
74
|
+
this._appUri ?? this.client.addressPrefix === "ckb"
|
|
75
|
+
? "https://app.joy.id"
|
|
76
|
+
: "https://testnet.joyid.dev",
|
|
77
|
+
name: this.name,
|
|
78
|
+
logo: this.icon,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Gets the aggregator URI.
|
|
83
|
+
* @private
|
|
84
|
+
* @returns {string} The aggregator URI.
|
|
85
|
+
*/
|
|
86
|
+
getAggregatorUri() {
|
|
87
|
+
if (this._aggregatorUri) {
|
|
88
|
+
return this._aggregatorUri;
|
|
15
89
|
}
|
|
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
|
-
return this.client.addressPrefix === "ckb"
|
|
48
|
-
? "https://cota.nervina.dev/mainnet-aggregator"
|
|
49
|
-
: "https://cota.nervina.dev/aggregator";
|
|
50
|
-
}
|
|
51
|
-
async connect() {
|
|
52
|
-
const config = this.getConfig();
|
|
53
|
-
const res = await (0, common_2.createPopup)((0, common_1.buildJoyIDURL)(config, "popup", "/auth"), {
|
|
54
|
-
...config,
|
|
55
|
-
type: common_1.DappRequestType.Auth,
|
|
56
|
-
});
|
|
57
|
-
this.connection = {
|
|
58
|
-
address: res.address,
|
|
59
|
-
publicKey: core_1.ccc.hexFrom(res.pubkey),
|
|
60
|
-
keyType: res.keyType,
|
|
61
|
-
};
|
|
62
|
-
await this.saveConnection();
|
|
63
|
-
}
|
|
64
|
-
async disconnect() {
|
|
65
|
-
this.connection = undefined;
|
|
66
|
-
await this.saveConnection();
|
|
67
|
-
}
|
|
68
|
-
async isConnected() {
|
|
69
|
-
if (this.connection) {
|
|
70
|
-
return true;
|
|
71
|
-
}
|
|
72
|
-
await this.restoreConnection();
|
|
73
|
-
return this.connection !== undefined;
|
|
74
|
-
}
|
|
75
|
-
async getInternalAddress() {
|
|
76
|
-
return (await this.assertConnection()).address;
|
|
90
|
+
return this.client.addressPrefix === "ckb"
|
|
91
|
+
? "https://cota.nervina.dev/mainnet-aggregator"
|
|
92
|
+
: "https://cota.nervina.dev/aggregator";
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Connects to the provider by requesting authentication.
|
|
96
|
+
* @returns {Promise<void>} A promise that resolves when the connection is established.
|
|
97
|
+
*/
|
|
98
|
+
async connect() {
|
|
99
|
+
const config = this.getConfig();
|
|
100
|
+
const res = await (0, common_2.createPopup)(
|
|
101
|
+
(0, common_1.buildJoyIDURL)(config, "popup", "/auth"),
|
|
102
|
+
{
|
|
103
|
+
...config,
|
|
104
|
+
type: common_1.DappRequestType.Auth,
|
|
105
|
+
},
|
|
106
|
+
);
|
|
107
|
+
this.connection = {
|
|
108
|
+
address: res.address,
|
|
109
|
+
publicKey: core_1.ccc.hexFrom(res.pubkey),
|
|
110
|
+
keyType: res.keyType,
|
|
111
|
+
};
|
|
112
|
+
await this.saveConnection();
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Checks if the signer is connected.
|
|
116
|
+
* @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
|
|
117
|
+
*/
|
|
118
|
+
async isConnected() {
|
|
119
|
+
if (this.connection) {
|
|
120
|
+
return true;
|
|
77
121
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
122
|
+
await this.restoreConnection();
|
|
123
|
+
return this.connection !== undefined;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Gets the internal address.
|
|
127
|
+
* @returns {Promise<string>} A promise that resolves to the internal address.
|
|
128
|
+
*/
|
|
129
|
+
async getInternalAddress() {
|
|
130
|
+
return (await this.assertConnection()).address;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Gets the identity of the signer.
|
|
134
|
+
* @returns {Promise<string>} A promise that resolves to the identity.
|
|
135
|
+
*/
|
|
136
|
+
async getIdentity() {
|
|
137
|
+
const connection = await this.assertConnection();
|
|
138
|
+
return JSON.stringify({
|
|
139
|
+
keyType: connection.keyType,
|
|
140
|
+
publicKey: connection.publicKey.slice(2),
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Gets the address object.
|
|
145
|
+
* @returns {Promise<ccc.Address>} A promise that resolves to the address object.
|
|
146
|
+
*/
|
|
147
|
+
async getAddressObj() {
|
|
148
|
+
return await core_1.ccc.Address.fromString(
|
|
149
|
+
await this.getInternalAddress(),
|
|
150
|
+
this.client,
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Gets the address objects.
|
|
155
|
+
* @returns {Promise<ccc.Address[]>} A promise that resolves to an array of address objects.
|
|
156
|
+
*/
|
|
157
|
+
async getAddressObjs() {
|
|
158
|
+
return [await this.getAddressObj()];
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Prepares a transaction.
|
|
162
|
+
* @param {ccc.TransactionLike} txLike - The transaction-like object.
|
|
163
|
+
* @returns {Promise<ccc.Transaction>} A promise that resolves to the prepared transaction.
|
|
164
|
+
*/
|
|
165
|
+
async prepareTransaction(txLike) {
|
|
166
|
+
const tx = core_1.ccc.Transaction.from(txLike);
|
|
167
|
+
await tx.addCellDepsOfKnownScripts(
|
|
168
|
+
this.client,
|
|
169
|
+
core_1.ccc.KnownScript.JoyId,
|
|
170
|
+
);
|
|
171
|
+
const position = await tx.findInputIndexByLock(
|
|
172
|
+
(await this.getAddressObj()).script,
|
|
173
|
+
this.client,
|
|
174
|
+
);
|
|
175
|
+
if (position === undefined) {
|
|
176
|
+
return tx;
|
|
84
177
|
}
|
|
85
|
-
|
|
86
|
-
|
|
178
|
+
const witness =
|
|
179
|
+
tx.getWitnessArgsAt(position) ?? core_1.ccc.WitnessArgs.from({});
|
|
180
|
+
witness.lock = core_1.ccc.hexFrom("00".repeat(1000));
|
|
181
|
+
await this.prepareTransactionForSubKey(tx, witness);
|
|
182
|
+
tx.setWitnessArgsAt(position, witness);
|
|
183
|
+
return tx;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Prepares a transaction for a sub key.
|
|
187
|
+
* @private
|
|
188
|
+
* @param tx - The transaction object.
|
|
189
|
+
* @param witness - The witness arguments.
|
|
190
|
+
* @throws Will throw an error if no COTA cells are found for the sub key wallet.
|
|
191
|
+
*/
|
|
192
|
+
async prepareTransactionForSubKey(tx, witness) {
|
|
193
|
+
if (this.connection?.keyType !== "sub_key") {
|
|
194
|
+
return [];
|
|
87
195
|
}
|
|
88
|
-
|
|
89
|
-
|
|
196
|
+
const pubkeyHash = core_1.ccc
|
|
197
|
+
.ckbHash(this.connection.publicKey)
|
|
198
|
+
.substring(0, 42);
|
|
199
|
+
const lock = (await this.getAddressObj()).script;
|
|
200
|
+
const aggregator = new ckb_1.Aggregator(await this.getAggregatorUri());
|
|
201
|
+
const { unlock_entry: unlockEntry } =
|
|
202
|
+
await aggregator.generateSubkeyUnlockSmt({
|
|
203
|
+
alg_index: 1,
|
|
204
|
+
pubkey_hash: pubkeyHash,
|
|
205
|
+
lock_script: core_1.ccc.hexFrom(lock.toBytes()),
|
|
206
|
+
});
|
|
207
|
+
witness.outputType = core_1.ccc.hexFrom(unlockEntry);
|
|
208
|
+
const cotaDeps = [];
|
|
209
|
+
for await (const cell of this.client.findCellsByLockAndType(
|
|
210
|
+
lock,
|
|
211
|
+
await core_1.ccc.Script.fromKnownScript(
|
|
212
|
+
this.client,
|
|
213
|
+
core_1.ccc.KnownScript.COTA,
|
|
214
|
+
"0x",
|
|
215
|
+
),
|
|
216
|
+
)) {
|
|
217
|
+
cotaDeps.push(
|
|
218
|
+
core_1.ccc.CellDep.from({
|
|
219
|
+
depType: "code",
|
|
220
|
+
outPoint: cell.outPoint,
|
|
221
|
+
}),
|
|
222
|
+
);
|
|
90
223
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const position = await tx.findInputIndexByLock((await this.getAddressObj()).script, this.client);
|
|
94
|
-
if (position === undefined) {
|
|
95
|
-
return tx;
|
|
96
|
-
}
|
|
97
|
-
const witness = tx.getWitnessArgsAt(position) ?? core_1.ccc.WitnessArgs.from({});
|
|
98
|
-
witness.lock = "0x";
|
|
99
|
-
await this.prepareTransactionForSubKey(tx, witness);
|
|
100
|
-
return tx.setWitnessArgsAt(position, witness);
|
|
224
|
+
if (cotaDeps.length === 0) {
|
|
225
|
+
throw new Error("No COTA cells for sub key wallet");
|
|
101
226
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
227
|
+
tx.cellDeps.unshift(...cotaDeps);
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Signs a transaction.
|
|
231
|
+
* @param {ccc.TransactionLike} txLike - The transaction-like object.
|
|
232
|
+
* @returns {Promise<ccc.Transaction>} A promise that resolves to the signed transaction.
|
|
233
|
+
*/
|
|
234
|
+
async signOnlyTransaction(txLike) {
|
|
235
|
+
const tx = core_1.ccc.Transaction.from(txLike);
|
|
236
|
+
const { script } = await this.getAddressObj();
|
|
237
|
+
const witnessIndexes = await core_1.ccc.reduceAsync(
|
|
238
|
+
tx.inputs,
|
|
239
|
+
async (acc, input, i) => {
|
|
240
|
+
await input.completeExtraInfos(this.client);
|
|
241
|
+
if (!input.cellOutput) {
|
|
242
|
+
throw new Error("Unable to complete input");
|
|
105
243
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const aggregator = new ckb_1.Aggregator(await this.getAggregatorUri());
|
|
109
|
-
const { unlock_entry: unlockEntry } = await aggregator.generateSubkeyUnlockSmt({
|
|
110
|
-
alg_index: 1,
|
|
111
|
-
pubkey_hash: pubkeyHash,
|
|
112
|
-
lock_script: core_1.ccc.hexFrom(lock.toBytes()),
|
|
113
|
-
});
|
|
114
|
-
witness.outputType = core_1.ccc.hexFrom(unlockEntry);
|
|
115
|
-
const cotaDeps = [];
|
|
116
|
-
for await (const cell of this.client.findCellsByLockAndType(lock, {
|
|
117
|
-
...(await this.client.getKnownScript(core_1.ccc.KnownScript.COTA)),
|
|
118
|
-
args: "0x",
|
|
119
|
-
})) {
|
|
120
|
-
cotaDeps.push(core_1.ccc.CellDep.from({
|
|
121
|
-
depType: "code",
|
|
122
|
-
outPoint: cell.outPoint,
|
|
123
|
-
}));
|
|
244
|
+
if (input.cellOutput.lock.eq(script)) {
|
|
245
|
+
acc.push(i);
|
|
124
246
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
247
|
+
},
|
|
248
|
+
[],
|
|
249
|
+
);
|
|
250
|
+
// Trim unnecessary fields to reduce tx size
|
|
251
|
+
await tx.prepareSighashAllWitness(script, 0, this.client);
|
|
252
|
+
tx.inputs.forEach((i) => {
|
|
253
|
+
i.cellOutput = undefined;
|
|
254
|
+
i.outputData = undefined;
|
|
255
|
+
});
|
|
256
|
+
const config = this.getConfig();
|
|
257
|
+
const res = await (0, common_2.createPopup)(
|
|
258
|
+
(0, common_1.buildJoyIDURL)(
|
|
259
|
+
{
|
|
260
|
+
...config,
|
|
261
|
+
tx: JSON.parse(tx.stringify()),
|
|
262
|
+
signerAddress: (await this.assertConnection()).address,
|
|
263
|
+
witnessIndexes,
|
|
264
|
+
},
|
|
265
|
+
"popup",
|
|
266
|
+
"/sign-ckb-raw-tx",
|
|
267
|
+
),
|
|
268
|
+
{
|
|
269
|
+
...config,
|
|
270
|
+
type: common_1.DappRequestType.SignCkbRawTx,
|
|
271
|
+
},
|
|
272
|
+
);
|
|
273
|
+
return core_1.ccc.Transaction.from(res.tx);
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Signs a raw message with the account.
|
|
277
|
+
* @param {string | ccc.BytesLike} message - The message to sign.
|
|
278
|
+
* @returns {Promise<string>} A promise that resolves to the signed message.
|
|
279
|
+
*/
|
|
280
|
+
async signMessageRaw(message) {
|
|
281
|
+
const { address } = await this.assertConnection();
|
|
282
|
+
const challenge =
|
|
283
|
+
typeof message === "string"
|
|
284
|
+
? message
|
|
285
|
+
: core_1.ccc.hexFrom(message).slice(2);
|
|
286
|
+
const config = this.getConfig();
|
|
287
|
+
const res = await (0, common_2.createPopup)(
|
|
288
|
+
(0, common_1.buildJoyIDURL)(
|
|
289
|
+
{
|
|
290
|
+
...config,
|
|
291
|
+
challenge,
|
|
292
|
+
isData: typeof message !== "string",
|
|
293
|
+
address,
|
|
294
|
+
},
|
|
295
|
+
"popup",
|
|
296
|
+
"/sign-message",
|
|
297
|
+
),
|
|
298
|
+
{ ...config, type: common_1.DappRequestType.SignMessage },
|
|
299
|
+
);
|
|
300
|
+
return JSON.stringify({
|
|
301
|
+
signature: res.signature,
|
|
302
|
+
alg: res.alg,
|
|
303
|
+
message: res.message,
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Saves the current connection.
|
|
308
|
+
* @private
|
|
309
|
+
* @returns {Promise<void>}
|
|
310
|
+
*/
|
|
311
|
+
async saveConnection() {
|
|
312
|
+
return this.connectionsRepo.set(
|
|
313
|
+
{
|
|
314
|
+
uri: this.getConfig().joyidAppURL,
|
|
315
|
+
addressType: "ckb",
|
|
316
|
+
},
|
|
317
|
+
this.connection,
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Restores the previous connection.
|
|
322
|
+
* @private
|
|
323
|
+
* @returns {Promise<void>}
|
|
324
|
+
*/
|
|
325
|
+
async restoreConnection() {
|
|
326
|
+
this.connection = await this.connectionsRepo.get({
|
|
327
|
+
uri: this.getConfig().joyidAppURL,
|
|
328
|
+
addressType: "ckb",
|
|
329
|
+
});
|
|
330
|
+
}
|
|
173
331
|
}
|
|
174
332
|
exports.CkbSigner = CkbSigner;
|
|
@@ -1,24 +1,50 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
AuthResponseData,
|
|
3
|
+
DappRequestType,
|
|
4
|
+
EvmWeb2LoginResponse,
|
|
5
|
+
PopupConfigOptions,
|
|
6
|
+
SignCkbTxResponseData,
|
|
7
|
+
SignCotaNFTResponseData,
|
|
8
|
+
SignEvmTxResponseData,
|
|
9
|
+
SignMessageResponseData,
|
|
10
|
+
SignNostrEventData,
|
|
11
|
+
} from "@joyid/common";
|
|
12
|
+
/**
|
|
13
|
+
* Interface representing the return type for various Dapp request types.
|
|
14
|
+
* @interface
|
|
15
|
+
*/
|
|
2
16
|
export interface PopupReturnType {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
[DappRequestType.Auth]: AuthResponseData;
|
|
18
|
+
[DappRequestType.SignMessage]: SignMessageResponseData;
|
|
19
|
+
[DappRequestType.SignEvm]: SignEvmTxResponseData;
|
|
20
|
+
[DappRequestType.SignPsbt]: SignEvmTxResponseData;
|
|
21
|
+
[DappRequestType.BatchSignPsbt]: {
|
|
22
|
+
psbts: string[];
|
|
23
|
+
};
|
|
24
|
+
[DappRequestType.SignCkbTx]: SignCkbTxResponseData;
|
|
25
|
+
[DappRequestType.SignCotaNFT]: SignCotaNFTResponseData;
|
|
26
|
+
[DappRequestType.SignCkbRawTx]: SignCkbTxResponseData;
|
|
27
|
+
[DappRequestType.SignNostrEvent]: SignNostrEventData;
|
|
28
|
+
[DappRequestType.EncryptNostrMessage]: any;
|
|
29
|
+
[DappRequestType.DecryptNostrMessage]: any;
|
|
30
|
+
[DappRequestType.AuthMiniApp]: any;
|
|
31
|
+
[DappRequestType.SignMiniAppEvm]: any;
|
|
32
|
+
[DappRequestType.SignMiniAppMessage]: any;
|
|
33
|
+
[DappRequestType.EvmWeb2Login]: EvmWeb2LoginResponse;
|
|
20
34
|
}
|
|
21
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Creates a popup window for JoyID Dapp requests.
|
|
37
|
+
* @param {string} url - The URL to open in the popup.
|
|
38
|
+
* @param {PopupConfigOptions<T> & { joyidAppURL: string }} config - The popup configuration options.
|
|
39
|
+
* @returns {Promise<PopupReturnType[T]>} A promise that resolves to the response data of the requested type.
|
|
40
|
+
* @throws {PopupNotSupportedError} If popups are not supported in the current browser.
|
|
41
|
+
* @throws {PopupCancelledError} If the popup is closed by the user.
|
|
42
|
+
* @throws {PopupTimeoutError} If the popup operation times out.
|
|
43
|
+
*/
|
|
44
|
+
export declare function createPopup<T extends DappRequestType>(
|
|
45
|
+
url: string,
|
|
46
|
+
config: PopupConfigOptions<T> & {
|
|
22
47
|
joyidAppURL: string;
|
|
23
|
-
}
|
|
24
|
-
|
|
48
|
+
},
|
|
49
|
+
): Promise<PopupReturnType[T]>;
|
|
50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