@ckb-ccc/joy-id 0.0.6-alpha.0 → 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.
@@ -17,37 +17,48 @@ const nostr_1 = require("../nostr");
17
17
  * @returns {ccc.SignerInfo[]} An array of signer information objects.
18
18
  */
19
19
  function getJoyIdSigners(client, name, icon) {
20
- if ((0, common_1.isStandaloneBrowser)() || core_1.ccc.isWebview(window.navigator.userAgent)) {
21
- return [core_1.ccc.SignerType.CKB, core_1.ccc.SignerType.EVM, core_1.ccc.SignerType.BTC].map((type) => ({
22
- name: type,
23
- signer: new core_1.ccc.SignerAlwaysError(client, type, "JoyID can only be used with standard browsers"),
24
- }));
25
- }
20
+ if (
21
+ (0, common_1.isStandaloneBrowser)() ||
22
+ core_1.ccc.isWebview(window.navigator.userAgent)
23
+ ) {
26
24
  return [
27
- {
28
- name: "CKB",
29
- signer: new ckb_1.CkbSigner(client, name, icon),
30
- },
31
- {
32
- name: "BTC",
33
- signer: new btc_1.BitcoinSigner(client, name, icon),
34
- },
35
- {
36
- name: "Nostr",
37
- signer: new nostr_1.NostrSigner(client, name, icon),
38
- },
39
- {
40
- name: "EVM",
41
- signer: new evm_1.EvmSigner(client, name, icon),
42
- },
43
- {
44
- name: "BTC (P2WPKH)",
45
- signer: new btc_1.BitcoinSigner(client, name, icon, "p2wpkh"),
46
- },
47
- {
48
- name: "BTC (P2TR)",
49
- signer: new btc_1.BitcoinSigner(client, name, icon, "p2tr"),
50
- },
51
- ];
25
+ core_1.ccc.SignerType.CKB,
26
+ core_1.ccc.SignerType.EVM,
27
+ core_1.ccc.SignerType.BTC,
28
+ ].map((type) => ({
29
+ name: type,
30
+ signer: new core_1.ccc.SignerAlwaysError(
31
+ client,
32
+ type,
33
+ "JoyID can only be used with standard browsers",
34
+ ),
35
+ }));
36
+ }
37
+ return [
38
+ {
39
+ name: "CKB",
40
+ signer: new ckb_1.CkbSigner(client, name, icon),
41
+ },
42
+ {
43
+ name: "BTC",
44
+ signer: new btc_1.BitcoinSigner(client, name, icon),
45
+ },
46
+ {
47
+ name: "Nostr",
48
+ signer: new nostr_1.NostrSigner(client, name, icon),
49
+ },
50
+ {
51
+ name: "EVM",
52
+ signer: new evm_1.EvmSigner(client, name, icon),
53
+ },
54
+ {
55
+ name: "BTC (P2WPKH)",
56
+ signer: new btc_1.BitcoinSigner(client, name, icon, "p2wpkh"),
57
+ },
58
+ {
59
+ name: "BTC (P2TR)",
60
+ signer: new btc_1.BitcoinSigner(client, name, icon, "p2tr"),
61
+ },
62
+ ];
52
63
  }
53
64
  exports.getJoyIdSigners = getJoyIdSigners;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckb-ccc/joy-id",
3
- "version": "0.0.6-alpha.0",
3
+ "version": "0.0.7-alpha.0",
4
4
  "description": "Connector's support for JoyID",
5
5
  "author": "Hanssen0 <hanssen0@hanssen0.com>",
6
6
  "license": "MIT",
@@ -38,9 +38,9 @@
38
38
  "access": "public"
39
39
  },
40
40
  "dependencies": {
41
- "@ckb-ccc/core": "0.0.6-alpha.0",
42
- "@joyid/ckb": "^0.0.11",
43
- "@joyid/common": "^0.0.3"
41
+ "@ckb-ccc/core": "0.0.7-alpha.0",
42
+ "@joyid/ckb": "^1.0.0",
43
+ "@joyid/common": "^0.2.0"
44
44
  },
45
- "gitHead": "2cbb4f450ed88e773a353a13ad006dbe6208f67f"
45
+ "gitHead": "99d88c6179e7af6f592b1b39f8df6f6968cc0df3"
46
46
  }
package/src/ckb/index.ts CHANGED
@@ -178,6 +178,7 @@ export class CkbSigner extends ccc.Signer {
178
178
  txLike: ccc.TransactionLike,
179
179
  ): Promise<ccc.Transaction> {
180
180
  const tx = ccc.Transaction.from(txLike);
181
+ await tx.addCellDepsOfKnownScripts(this.client, ccc.KnownScript.JoyId);
181
182
  const position = await tx.findInputIndexByLock(
182
183
  (await this.getAddressObj()).script,
183
184
  this.client,
@@ -187,7 +188,7 @@ export class CkbSigner extends ccc.Signer {
187
188
  }
188
189
 
189
190
  const witness = tx.getWitnessArgsAt(position) ?? ccc.WitnessArgs.from({});
190
- witness.lock = "0x";
191
+ witness.lock = ccc.hexFrom("00".repeat(1000));
191
192
  await this.prepareTransactionForSubKey(tx, witness);
192
193
  tx.setWitnessArgsAt(position, witness);
193
194
 
@@ -197,9 +198,8 @@ export class CkbSigner extends ccc.Signer {
197
198
  /**
198
199
  * Prepares a transaction for a sub key.
199
200
  * @private
200
- * @param {ccc.Transaction} tx - The transaction object.
201
- * @param {ccc.WitnessArgs} witness - The witness arguments.
202
- * @returns {Promise<void>}
201
+ * @param tx - The transaction object.
202
+ * @param witness - The witness arguments.
203
203
  * @throws Will throw an error if no COTA cells are found for the sub key wallet.
204
204
  */
205
205
  private async prepareTransactionForSubKey(
@@ -222,10 +222,10 @@ export class CkbSigner extends ccc.Signer {
222
222
  witness.outputType = ccc.hexFrom(unlockEntry);
223
223
 
224
224
  const cotaDeps: ccc.CellDep[] = [];
225
- for await (const cell of this.client.findCellsByLockAndType(lock, {
226
- ...(await this.client.getKnownScript(ccc.KnownScript.COTA)),
227
- args: "0x",
228
- })) {
225
+ for await (const cell of this.client.findCellsByLockAndType(
226
+ lock,
227
+ await ccc.Script.fromKnownScript(this.client, ccc.KnownScript.COTA, "0x"),
228
+ )) {
229
229
  cotaDeps.push(
230
230
  ccc.CellDep.from({
231
231
  depType: "code",
@@ -251,6 +251,27 @@ export class CkbSigner extends ccc.Signer {
251
251
  ): Promise<ccc.Transaction> {
252
252
  const tx = ccc.Transaction.from(txLike);
253
253
  const { script } = await this.getAddressObj();
254
+ const witnessIndexes = await ccc.reduceAsync(
255
+ tx.inputs,
256
+ async (acc, input, i) => {
257
+ await input.completeExtraInfos(this.client);
258
+ if (!input.cellOutput) {
259
+ throw new Error("Unable to complete input");
260
+ }
261
+
262
+ if (input.cellOutput.lock.eq(script)) {
263
+ acc.push(i);
264
+ }
265
+ },
266
+ [] as number[],
267
+ );
268
+
269
+ // Trim unnecessary fields to reduce tx size
270
+ await tx.prepareSighashAllWitness(script, 0, this.client);
271
+ tx.inputs.forEach((i) => {
272
+ i.cellOutput = undefined;
273
+ i.outputData = undefined;
274
+ });
254
275
 
255
276
  const config = this.getConfig();
256
277
  const res = await createPopup(
@@ -259,11 +280,7 @@ export class CkbSigner extends ccc.Signer {
259
280
  ...config,
260
281
  tx: JSON.parse(tx.stringify()),
261
282
  signerAddress: (await this.assertConnection()).address,
262
- witnessIndex: await tx.findInputIndexByLock(script, this.client),
263
- witnessLastIndex: await tx.findLastInputIndexByLock(
264
- script,
265
- this.client,
266
- ),
283
+ witnessIndexes,
267
284
  },
268
285
  "popup",
269
286
  "/sign-ckb-raw-tx",