@ckb-ccc/joy-id 0.0.8-alpha.2 → 0.0.8-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -4
- package/dist.commonjs/advanced.d.ts +1 -1
- package/dist.commonjs/advanced.js +40 -19
- package/dist.commonjs/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 +63 -56
- package/dist.commonjs/btc/index.js +140 -114
- package/dist.commonjs/ckb/index.d.ts +121 -114
- package/dist.commonjs/ckb/index.js +307 -250
- package/dist.commonjs/common/index.d.ts +34 -21
- package/dist.commonjs/common/index.js +50 -45
- package/dist.commonjs/connectionsStorage/index.d.ts +53 -44
- package/dist.commonjs/connectionsStorage/index.js +47 -44
- package/dist.commonjs/evm/index.d.ts +67 -61
- package/dist.commonjs/evm/index.js +135 -113
- package/dist.commonjs/index.d.ts +1 -1
- package/dist.commonjs/index.js +40 -19
- package/dist.commonjs/nostr/index.d.ts +48 -42
- package/dist.commonjs/nostr/index.js +108 -89
- package/dist.commonjs/signerFactory/index.d.ts +6 -2
- package/dist.commonjs/signerFactory/index.js +42 -31
- package/package.json +3 -3
|
@@ -12,264 +12,321 @@ const connectionsStorage_1 = require("../connectionsStorage");
|
|
|
12
12
|
* @extends {ccc.Signer}
|
|
13
13
|
*/
|
|
14
14
|
class CkbSigner extends core_1.ccc.Signer {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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");
|
|
21
38
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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;
|
|
28
89
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
* @private
|
|
61
|
-
* @returns {object} The configuration object.
|
|
62
|
-
*/
|
|
63
|
-
getConfig() {
|
|
64
|
-
return {
|
|
65
|
-
redirectURL: location.href,
|
|
66
|
-
joyidAppURL: this._appUri ?? this.client.addressPrefix === "ckb"
|
|
67
|
-
? "https://app.joy.id"
|
|
68
|
-
: "https://testnet.joyid.dev",
|
|
69
|
-
name: this.name,
|
|
70
|
-
logo: this.icon,
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Gets the aggregator URI.
|
|
75
|
-
* @private
|
|
76
|
-
* @returns {string} The aggregator URI.
|
|
77
|
-
*/
|
|
78
|
-
getAggregatorUri() {
|
|
79
|
-
if (this._aggregatorUri) {
|
|
80
|
-
return this._aggregatorUri;
|
|
81
|
-
}
|
|
82
|
-
return this.client.addressPrefix === "ckb"
|
|
83
|
-
? "https://cota.nervina.dev/mainnet-aggregator"
|
|
84
|
-
: "https://cota.nervina.dev/aggregator";
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Connects to the provider by requesting authentication.
|
|
88
|
-
* @returns {Promise<void>} A promise that resolves when the connection is established.
|
|
89
|
-
*/
|
|
90
|
-
async connect() {
|
|
91
|
-
const config = this.getConfig();
|
|
92
|
-
const res = await (0, common_2.createPopup)((0, common_1.buildJoyIDURL)(config, "popup", "/auth"), {
|
|
93
|
-
...config,
|
|
94
|
-
type: common_1.DappRequestType.Auth,
|
|
95
|
-
});
|
|
96
|
-
this.connection = {
|
|
97
|
-
address: res.address,
|
|
98
|
-
publicKey: core_1.ccc.hexFrom(res.pubkey),
|
|
99
|
-
keyType: res.keyType,
|
|
100
|
-
};
|
|
101
|
-
await this.saveConnection();
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Checks if the signer is connected.
|
|
105
|
-
* @returns {Promise<boolean>} A promise that resolves to true if connected, false otherwise.
|
|
106
|
-
*/
|
|
107
|
-
async isConnected() {
|
|
108
|
-
if (this.connection) {
|
|
109
|
-
return true;
|
|
110
|
-
}
|
|
111
|
-
await this.restoreConnection();
|
|
112
|
-
return this.connection !== undefined;
|
|
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;
|
|
113
121
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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;
|
|
120
177
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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 [];
|
|
131
195
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
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(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
|
+
);
|
|
138
223
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
* @returns {Promise<ccc.Address[]>} A promise that resolves to an array of address objects.
|
|
142
|
-
*/
|
|
143
|
-
async getAddressObjs() {
|
|
144
|
-
return [await this.getAddressObj()];
|
|
224
|
+
if (cotaDeps.length === 0) {
|
|
225
|
+
throw new Error("No COTA cells for sub key wallet");
|
|
145
226
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
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");
|
|
157
243
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
await this.prepareTransactionForSubKey(tx, witness);
|
|
161
|
-
tx.setWitnessArgsAt(position, witness);
|
|
162
|
-
return tx;
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* Prepares a transaction for a sub key.
|
|
166
|
-
* @private
|
|
167
|
-
* @param tx - The transaction object.
|
|
168
|
-
* @param witness - The witness arguments.
|
|
169
|
-
* @throws Will throw an error if no COTA cells are found for the sub key wallet.
|
|
170
|
-
*/
|
|
171
|
-
async prepareTransactionForSubKey(tx, witness) {
|
|
172
|
-
if (this.connection?.keyType !== "sub_key") {
|
|
173
|
-
return [];
|
|
174
|
-
}
|
|
175
|
-
const pubkeyHash = core_1.ccc.ckbHash(this.connection.publicKey).substring(0, 42);
|
|
176
|
-
const lock = (await this.getAddressObj()).script;
|
|
177
|
-
const aggregator = new ckb_1.Aggregator(this.getAggregatorUri());
|
|
178
|
-
const { unlock_entry: unlockEntry } = await aggregator.generateSubkeyUnlockSmt({
|
|
179
|
-
alg_index: 1,
|
|
180
|
-
pubkey_hash: pubkeyHash,
|
|
181
|
-
lock_script: core_1.ccc.hexFrom(lock.toBytes()),
|
|
182
|
-
});
|
|
183
|
-
witness.outputType = core_1.ccc.hexFrom(unlockEntry);
|
|
184
|
-
const cotaDeps = [];
|
|
185
|
-
for await (const cell of this.client.findCellsByLockAndType(lock, await core_1.ccc.Script.fromKnownScript(this.client, core_1.ccc.KnownScript.COTA, "0x"))) {
|
|
186
|
-
cotaDeps.push(core_1.ccc.CellDep.from({
|
|
187
|
-
depType: "code",
|
|
188
|
-
outPoint: cell.outPoint,
|
|
189
|
-
}));
|
|
244
|
+
if (input.cellOutput.lock.eq(script)) {
|
|
245
|
+
acc.push(i);
|
|
190
246
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
}
|
|
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
|
+
}
|
|
274
331
|
}
|
|
275
332
|
exports.CkbSigner = CkbSigner;
|
|
@@ -1,26 +1,36 @@
|
|
|
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";
|
|
2
12
|
/**
|
|
3
13
|
* Interface representing the return type for various Dapp request types.
|
|
4
14
|
* @interface
|
|
5
15
|
*/
|
|
6
16
|
export interface PopupReturnType {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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;
|
|
24
34
|
}
|
|
25
35
|
/**
|
|
26
36
|
* Creates a popup window for JoyID Dapp requests.
|
|
@@ -31,7 +41,10 @@ export interface PopupReturnType {
|
|
|
31
41
|
* @throws {PopupCancelledError} If the popup is closed by the user.
|
|
32
42
|
* @throws {PopupTimeoutError} If the popup operation times out.
|
|
33
43
|
*/
|
|
34
|
-
export declare function createPopup<T extends DappRequestType>(
|
|
44
|
+
export declare function createPopup<T extends DappRequestType>(
|
|
45
|
+
url: string,
|
|
46
|
+
config: PopupConfigOptions<T> & {
|
|
35
47
|
joyidAppURL: string;
|
|
36
|
-
}
|
|
37
|
-
|
|
48
|
+
},
|
|
49
|
+
): Promise<PopupReturnType[T]>;
|
|
50
|
+
//# sourceMappingURL=index.d.ts.map
|