@ckb-ccc/core 1.10.0 → 1.11.1

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.
Files changed (71) hide show
  1. package/CHANGELOG.md +43 -4
  2. package/dist/ckb/hash.d.ts +18 -0
  3. package/dist/ckb/hash.d.ts.map +1 -0
  4. package/dist/ckb/hash.js +19 -0
  5. package/dist/ckb/index.d.ts +1 -0
  6. package/dist/ckb/index.d.ts.map +1 -1
  7. package/dist/ckb/index.js +1 -0
  8. package/dist/ckb/transaction.d.ts +179 -11
  9. package/dist/ckb/transaction.d.ts.map +1 -1
  10. package/dist/ckb/transaction.js +197 -59
  11. package/dist/client/clientPublicMainnet.advanced.d.ts.map +1 -1
  12. package/dist/client/clientPublicMainnet.advanced.js +63 -62
  13. package/dist/client/clientPublicTestnet.advanced.d.ts +0 -23
  14. package/dist/client/clientPublicTestnet.advanced.d.ts.map +1 -1
  15. package/dist/client/clientPublicTestnet.advanced.js +63 -146
  16. package/dist/client/knownScript.d.ts +1 -3
  17. package/dist/client/knownScript.d.ts.map +1 -1
  18. package/dist/client/knownScript.js +0 -4
  19. package/dist/hasher/hasherCkb.d.ts +0 -16
  20. package/dist/hasher/hasherCkb.d.ts.map +1 -1
  21. package/dist/hasher/hasherCkb.js +0 -18
  22. package/dist/molecule/codec.d.ts +30 -10
  23. package/dist/molecule/codec.d.ts.map +1 -1
  24. package/dist/molecule/codec.js +46 -13
  25. package/dist/signer/ckb/signerCkbScriptReadonly.d.ts +18 -6
  26. package/dist/signer/ckb/signerCkbScriptReadonly.d.ts.map +1 -1
  27. package/dist/signer/ckb/signerCkbScriptReadonly.js +18 -6
  28. package/dist/signer/signer/index.d.ts +11 -1
  29. package/dist/signer/signer/index.d.ts.map +1 -1
  30. package/dist/signer/signer/index.js +23 -0
  31. package/dist.commonjs/ckb/hash.d.ts +18 -0
  32. package/dist.commonjs/ckb/hash.d.ts.map +1 -0
  33. package/dist.commonjs/ckb/hash.js +22 -0
  34. package/dist.commonjs/ckb/index.d.ts +1 -0
  35. package/dist.commonjs/ckb/index.d.ts.map +1 -1
  36. package/dist.commonjs/ckb/index.js +1 -0
  37. package/dist.commonjs/ckb/transaction.d.ts +179 -11
  38. package/dist.commonjs/ckb/transaction.d.ts.map +1 -1
  39. package/dist.commonjs/ckb/transaction.js +197 -59
  40. package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts.map +1 -1
  41. package/dist.commonjs/client/clientPublicMainnet.advanced.js +63 -62
  42. package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts +0 -23
  43. package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts.map +1 -1
  44. package/dist.commonjs/client/clientPublicTestnet.advanced.js +64 -147
  45. package/dist.commonjs/client/knownScript.d.ts +1 -3
  46. package/dist.commonjs/client/knownScript.d.ts.map +1 -1
  47. package/dist.commonjs/client/knownScript.js +0 -4
  48. package/dist.commonjs/hasher/hasherCkb.d.ts +0 -16
  49. package/dist.commonjs/hasher/hasherCkb.d.ts.map +1 -1
  50. package/dist.commonjs/hasher/hasherCkb.js +2 -21
  51. package/dist.commonjs/molecule/codec.d.ts +30 -10
  52. package/dist.commonjs/molecule/codec.d.ts.map +1 -1
  53. package/dist.commonjs/molecule/codec.js +46 -13
  54. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.d.ts +18 -6
  55. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.d.ts.map +1 -1
  56. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.js +18 -6
  57. package/dist.commonjs/signer/signer/index.d.ts +11 -1
  58. package/dist.commonjs/signer/signer/index.d.ts.map +1 -1
  59. package/dist.commonjs/signer/signer/index.js +23 -0
  60. package/package.json +1 -1
  61. package/prettier.config.mjs +1 -1
  62. package/src/ckb/hash.ts +28 -0
  63. package/src/ckb/index.ts +1 -0
  64. package/src/ckb/transaction.ts +231 -52
  65. package/src/client/clientPublicMainnet.advanced.ts +72 -70
  66. package/src/client/clientPublicTestnet.advanced.ts +72 -165
  67. package/src/client/knownScript.ts +0 -5
  68. package/src/hasher/hasherCkb.ts +0 -26
  69. package/src/molecule/codec.ts +50 -13
  70. package/src/signer/ckb/signerCkbScriptReadonly.ts +24 -8
  71. package/src/signer/signer/index.ts +34 -0
@@ -184,26 +184,15 @@ let CellOutput = CellOutput_1 = class CellOutput extends index_js_6.mol.Entity.B
184
184
  get occupiedSize() {
185
185
  return 8 + this.lock.occupiedSize + (this.type?.occupiedSize ?? 0);
186
186
  }
187
- /**
188
- * Creates a CellOutput instance from a CellOutputLike object.
189
- *
190
- * @param cellOutput - A CellOutputLike object or an instance of CellOutput.
191
- * @returns A CellOutput instance.
192
- *
193
- * @example
194
- * ```typescript
195
- * const cellOutput = CellOutput.from({
196
- * capacity: 1000n,
197
- * lock: { codeHash: "0x...", hashType: "type", args: "0x..." },
198
- * type: { codeHash: "0x...", hashType: "type", args: "0x..." }
199
- * });
200
- * ```
201
- */
202
- static from(cellOutput) {
187
+ static from(cellOutput, outputData) {
203
188
  if (cellOutput instanceof CellOutput_1) {
204
189
  return cellOutput;
205
190
  }
206
- return new CellOutput_1((0, index_js_7.numFrom)(cellOutput.capacity), script_js_1.Script.from(cellOutput.lock), (0, index_js_8.apply)(script_js_1.Script.from, cellOutput.type));
191
+ const output = new CellOutput_1((0, index_js_7.numFrom)(cellOutput.capacity ?? 0), script_js_1.Script.from(cellOutput.lock), (0, index_js_8.apply)(script_js_1.Script.from, cellOutput.type));
192
+ if (output.capacity === index_js_3.Zero) {
193
+ output.capacity = (0, index_js_3.fixedPointFrom)(output.occupiedSize + (0, index_js_1.bytesFrom)(outputData ?? "0x").length);
194
+ }
195
+ return output;
207
196
  }
208
197
  /**
209
198
  * Clone a CellOutput.
@@ -246,15 +235,43 @@ class Cell {
246
235
  }
247
236
  /**
248
237
  * Creates a Cell instance from a CellLike object.
238
+ * This method accepts either `outPoint` or `previousOutput` to specify the cell's location,
239
+ * and supports automatic capacity calculation for the cell output.
249
240
  *
250
- * @param cell - A CellLike object or an instance of Cell.
241
+ * @param cell - A CellLike object or an instance of Cell. The object can use either:
242
+ * - `outPoint`: For referencing a cell output
243
+ * - `previousOutput`: For referencing a cell input (alternative name for outPoint)
244
+ * The cellOutput can omit capacity for automatic calculation.
251
245
  * @returns A Cell instance.
246
+ *
247
+ * @example
248
+ * ```typescript
249
+ * // Using outPoint with explicit capacity
250
+ * const cell1 = Cell.from({
251
+ * outPoint: { txHash: "0x...", index: 0 },
252
+ * cellOutput: {
253
+ * capacity: 1000n,
254
+ * lock: { codeHash: "0x...", hashType: "type", args: "0x..." }
255
+ * },
256
+ * outputData: "0x"
257
+ * });
258
+ *
259
+ * // Using previousOutput with automatic capacity calculation
260
+ * const cell2 = Cell.from({
261
+ * previousOutput: { txHash: "0x...", index: 0 },
262
+ * cellOutput: {
263
+ * lock: { codeHash: "0x...", hashType: "type", args: "0x..." }
264
+ * // capacity will be calculated automatically
265
+ * },
266
+ * outputData: "0x1234"
267
+ * });
268
+ * ```
252
269
  */
253
270
  static from(cell) {
254
271
  if (cell instanceof Cell) {
255
272
  return cell;
256
273
  }
257
- return new Cell(OutPoint.from("outPoint" in cell ? cell.outPoint : cell.previousOutput), CellOutput.from(cell.cellOutput), (0, index_js_5.hexFrom)(cell.outputData));
274
+ return new Cell(OutPoint.from("outPoint" in cell ? cell.outPoint : cell.previousOutput), CellOutput.from(cell.cellOutput, cell.outputData), (0, index_js_5.hexFrom)(cell.outputData));
258
275
  }
259
276
  get capacityFree() {
260
277
  const occupiedSize = (0, index_js_3.fixedPointFrom)(this.cellOutput.occupiedSize + (0, index_js_1.bytesFrom)(this.outputData).length);
@@ -733,6 +750,9 @@ let Transaction = Transaction_1 = class Transaction extends index_js_6.mol.Entit
733
750
  }
734
751
  /**
735
752
  * Copy every properties from another transaction.
753
+ * This method replaces all properties of the current transaction with those from the provided transaction.
754
+ *
755
+ * @param txLike - The transaction-like object to copy properties from.
736
756
  *
737
757
  * @example
738
758
  * ```typescript
@@ -812,17 +832,7 @@ let Transaction = Transaction_1 = class Transaction extends index_js_6.mol.Entit
812
832
  if (tx instanceof Transaction_1) {
813
833
  return tx;
814
834
  }
815
- const outputs = tx.outputs?.map((output, i) => {
816
- const o = CellOutput.from({
817
- ...output,
818
- capacity: output.capacity ?? 0,
819
- });
820
- if (o.capacity === index_js_3.Zero) {
821
- o.capacity = (0, index_js_3.fixedPointFrom)(o.occupiedSize +
822
- ((0, index_js_8.apply)(index_js_1.bytesFrom, tx.outputsData?.[i])?.length ?? 0));
823
- }
824
- return o;
825
- }) ?? [];
835
+ const outputs = tx.outputs?.map((output, i) => CellOutput.from(output, tx.outputsData?.[i] ?? [])) ?? [];
826
836
  const outputsData = outputs.map((_, i) => (0, index_js_5.hexFrom)(tx.outputsData?.[i] ?? "0x"));
827
837
  if (tx.outputsData != null && outputsData.length < tx.outputsData.length) {
828
838
  outputsData.push(...tx.outputsData.slice(outputsData.length).map((d) => (0, index_js_5.hexFrom)(d)));
@@ -1005,7 +1015,7 @@ let Transaction = Transaction_1 = class Transaction extends index_js_6.mol.Entit
1005
1015
  *
1006
1016
  * @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
1007
1017
  * @param client - The client for complete extra infos in the transaction.
1008
- * @returns A promise that resolves to the prepared transaction
1018
+ * @returns A promise that resolves to the found index, or undefined if no matching input is found.
1009
1019
  *
1010
1020
  * @example
1011
1021
  * ```typescript
@@ -1026,7 +1036,7 @@ let Transaction = Transaction_1 = class Transaction extends index_js_6.mol.Entit
1026
1036
  *
1027
1037
  * @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
1028
1038
  * @param client - The client for complete extra infos in the transaction.
1029
- * @returns A promise that resolves to the prepared transaction
1039
+ * @returns A promise that resolves to the found index, or undefined if no matching input is found.
1030
1040
  *
1031
1041
  * @example
1032
1042
  * ```typescript
@@ -1114,18 +1124,18 @@ let Transaction = Transaction_1 = class Transaction extends index_js_6.mol.Entit
1114
1124
  * Set output data at index.
1115
1125
  *
1116
1126
  * @param index - The index of the output data.
1117
- * @param witness - The data to set.
1127
+ * @param data - The data to set.
1118
1128
  *
1119
1129
  * @example
1120
1130
  * ```typescript
1121
- * await tx.setOutputDataAt(0, "0x00");
1131
+ * tx.setOutputDataAt(0, "0x00");
1122
1132
  * ```
1123
1133
  */
1124
- setOutputDataAt(index, witness) {
1134
+ setOutputDataAt(index, data) {
1125
1135
  if (this.outputsData.length < index) {
1126
1136
  this.outputsData.push(...Array.from(new Array(index - this.outputsData.length), () => "0x"));
1127
1137
  }
1128
- this.outputsData[index] = (0, index_js_5.hexFrom)(witness);
1138
+ this.outputsData[index] = (0, index_js_5.hexFrom)(data);
1129
1139
  }
1130
1140
  /**
1131
1141
  * get input
@@ -1188,14 +1198,7 @@ let Transaction = Transaction_1 = class Transaction extends index_js_6.mol.Entit
1188
1198
  * ```
1189
1199
  */
1190
1200
  addOutput(outputLike, outputData = "0x") {
1191
- const output = CellOutput.from({
1192
- ...outputLike,
1193
- capacity: outputLike.capacity ?? 0,
1194
- });
1195
- if (output.capacity === index_js_3.Zero) {
1196
- output.capacity = (0, index_js_3.fixedPointFrom)(output.occupiedSize + (0, index_js_1.bytesFrom)(outputData).length);
1197
- }
1198
- const len = this.outputs.push(output);
1201
+ const len = this.outputs.push(CellOutput.from(outputLike, outputData));
1199
1202
  this.setOutputDataAt(len - 1, outputData);
1200
1203
  return len;
1201
1204
  }
@@ -1467,18 +1470,20 @@ let Transaction = Transaction_1 = class Transaction extends index_js_6.mol.Entit
1467
1470
  await this.getInputsCapacity(from.client);
1468
1471
  let leastFee = index_js_3.Zero;
1469
1472
  let leastExtraCapacity = index_js_3.Zero;
1473
+ let collected = 0;
1474
+ // ===
1475
+ // Usually, for the worst situation, three iterations are needed
1476
+ // 1. First attempt to complete the transaction.
1477
+ // 2. Not enough capacity for the change cell.
1478
+ // 3. Fee increased by the change cell.
1479
+ // ===
1470
1480
  while (true) {
1471
- const tx = this.clone();
1472
- const collected = await (async () => {
1481
+ collected += await (async () => {
1473
1482
  if (!(options?.shouldAddInputs ?? true)) {
1474
- const fee = (await tx.getFee(from.client)) - leastFee - leastExtraCapacity;
1475
- if (fee < index_js_3.Zero) {
1476
- throw new transactionErrors_js_1.ErrorTransactionInsufficientCapacity(-fee);
1477
- }
1478
1483
  return 0;
1479
1484
  }
1480
1485
  try {
1481
- return await tx.completeInputsByCapacity(from, leastFee + leastExtraCapacity, filter);
1486
+ return await this.completeInputsByCapacity(from, leastFee + leastExtraCapacity, filter);
1482
1487
  }
1483
1488
  catch (err) {
1484
1489
  if (err instanceof transactionErrors_js_1.ErrorTransactionInsufficientCapacity &&
@@ -1490,20 +1495,28 @@ let Transaction = Transaction_1 = class Transaction extends index_js_6.mol.Entit
1490
1495
  throw err;
1491
1496
  }
1492
1497
  })();
1493
- await from.prepareTransaction(tx);
1498
+ const fee = await this.getFee(from.client);
1499
+ if (fee < leastFee + leastExtraCapacity) {
1500
+ // Not enough capacity are collected, it should only happens when shouldAddInputs is false
1501
+ throw new transactionErrors_js_1.ErrorTransactionInsufficientCapacity(leastFee + leastExtraCapacity - fee, { isForChange: leastExtraCapacity !== index_js_3.Zero });
1502
+ }
1503
+ await from.prepareTransaction(this);
1494
1504
  if (leastFee === index_js_3.Zero) {
1495
1505
  // The initial fee is calculated based on prepared transaction
1496
- leastFee = tx.estimateFee(feeRate);
1506
+ // This should only happens during the first iteration
1507
+ leastFee = this.estimateFee(feeRate);
1497
1508
  }
1498
- const fee = await tx.getFee(from.client);
1499
1509
  // The extra capacity paid the fee without a change
1510
+ // leastExtraCapacity should be 0 here, otherwise we should failed in the previous check
1511
+ // So this only happens in the first iteration
1500
1512
  if (fee === leastFee) {
1501
- this.copy(tx);
1502
1513
  return [collected, false];
1503
1514
  }
1515
+ // Invoke the change function on a transaction multiple times may cause problems, so we clone it
1516
+ const tx = this.clone();
1504
1517
  const needed = (0, index_js_7.numFrom)(await Promise.resolve(change(tx, fee - leastFee)));
1505
- // No enough extra capacity to create new cells for change
1506
1518
  if (needed > index_js_3.Zero) {
1519
+ // No enough extra capacity to create new cells for change, collect inputs again
1507
1520
  leastExtraCapacity = needed;
1508
1521
  continue;
1509
1522
  }
@@ -1525,6 +1538,38 @@ let Transaction = Transaction_1 = class Transaction extends index_js_6.mol.Entit
1525
1538
  leastFee = changedFee;
1526
1539
  }
1527
1540
  }
1541
+ /**
1542
+ * Completes the transaction fee by adding inputs and creating a change output with the specified lock script.
1543
+ * This is a convenience method that automatically creates a change cell with the provided lock script
1544
+ * when there's excess capacity after paying the transaction fee.
1545
+ *
1546
+ * @param from - The signer to complete inputs from and prepare the transaction.
1547
+ * @param change - The lock script for the change output cell.
1548
+ * @param feeRate - Optional fee rate in shannons per 1000 bytes. If not provided, it will be fetched from the client.
1549
+ * @param filter - Optional filter for selecting cells when adding inputs.
1550
+ * @param options - Optional configuration object.
1551
+ * @param options.feeRateBlockRange - Block range for fee rate calculation when feeRate is not provided.
1552
+ * @param options.maxFeeRate - Maximum allowed fee rate.
1553
+ * @param options.shouldAddInputs - Whether to add inputs automatically. Defaults to true.
1554
+ * @returns A promise that resolves to a tuple containing:
1555
+ * - The number of inputs added during the process
1556
+ * - A boolean indicating whether change outputs were created (true) or fee was paid without change (false)
1557
+ *
1558
+ * @example
1559
+ * ```typescript
1560
+ * const changeScript = Script.from({
1561
+ * codeHash: "0x...",
1562
+ * hashType: "type",
1563
+ * args: "0x..."
1564
+ * });
1565
+ *
1566
+ * const [addedInputs, hasChange] = await tx.completeFeeChangeToLock(
1567
+ * signer,
1568
+ * changeScript,
1569
+ * 1000n // 1000 shannons per 1000 bytes
1570
+ * );
1571
+ * ```
1572
+ */
1528
1573
  completeFeeChangeToLock(from, change, feeRate, filter, options) {
1529
1574
  const script = script_js_1.Script.from(change);
1530
1575
  return this.completeFee(from, (tx, capacity) => {
@@ -1538,10 +1583,66 @@ let Transaction = Transaction_1 = class Transaction extends index_js_6.mol.Entit
1538
1583
  return 0;
1539
1584
  }, feeRate, filter, options);
1540
1585
  }
1586
+ /**
1587
+ * Completes the transaction fee using the signer's recommended address for change.
1588
+ * This is a convenience method that automatically uses the signer's recommended
1589
+ * address as the change destination, making it easier to complete transactions
1590
+ * without manually specifying a change address.
1591
+ *
1592
+ * @param from - The signer to complete inputs from and prepare the transaction.
1593
+ * @param feeRate - Optional fee rate in shannons per 1000 bytes. If not provided, it will be fetched from the client.
1594
+ * @param filter - Optional filter for selecting cells when adding inputs.
1595
+ * @param options - Optional configuration object.
1596
+ * @param options.feeRateBlockRange - Block range for fee rate calculation when feeRate is not provided.
1597
+ * @param options.maxFeeRate - Maximum allowed fee rate.
1598
+ * @param options.shouldAddInputs - Whether to add inputs automatically. Defaults to true.
1599
+ * @returns A promise that resolves to a tuple containing:
1600
+ * - The number of inputs added during the process
1601
+ * - A boolean indicating whether change outputs were created (true) or fee was paid without change (false)
1602
+ *
1603
+ * @example
1604
+ * ```typescript
1605
+ * const [addedInputs, hasChange] = await tx.completeFeeBy(
1606
+ * signer,
1607
+ * 1000n // 1000 shannons per 1000 bytes
1608
+ * );
1609
+ *
1610
+ * // Change will automatically go to signer's recommended address
1611
+ * ```
1612
+ */
1541
1613
  async completeFeeBy(from, feeRate, filter, options) {
1542
1614
  const { script } = await from.getRecommendedAddressObj();
1543
1615
  return this.completeFeeChangeToLock(from, script, feeRate, filter, options);
1544
1616
  }
1617
+ /**
1618
+ * Completes the transaction fee by adding excess capacity to an existing output.
1619
+ * Instead of creating a new change output, this method adds any excess capacity
1620
+ * to the specified existing output in the transaction.
1621
+ *
1622
+ * @param from - The signer to complete inputs from and prepare the transaction.
1623
+ * @param index - The index of the existing output to add excess capacity to.
1624
+ * @param feeRate - Optional fee rate in shannons per 1000 bytes. If not provided, it will be fetched from the client.
1625
+ * @param filter - Optional filter for selecting cells when adding inputs.
1626
+ * @param options - Optional configuration object.
1627
+ * @param options.feeRateBlockRange - Block range for fee rate calculation when feeRate is not provided.
1628
+ * @param options.maxFeeRate - Maximum allowed fee rate.
1629
+ * @param options.shouldAddInputs - Whether to add inputs automatically. Defaults to true.
1630
+ * @returns A promise that resolves to a tuple containing:
1631
+ * - The number of inputs added during the process
1632
+ * - A boolean indicating whether change was applied (true) or fee was paid without change (false)
1633
+ *
1634
+ * @throws {Error} When the specified output index doesn't exist.
1635
+ *
1636
+ * @example
1637
+ * ```typescript
1638
+ * // Add excess capacity to the first output (index 0)
1639
+ * const [addedInputs, hasChange] = await tx.completeFeeChangeToOutput(
1640
+ * signer,
1641
+ * 0, // Output index
1642
+ * 1000n // 1000 shannons per 1000 bytes
1643
+ * );
1644
+ * ```
1645
+ */
1545
1646
  completeFeeChangeToOutput(from, index, feeRate, filter, options) {
1546
1647
  const change = Number((0, index_js_7.numFrom)(index));
1547
1648
  if (!this.outputs[change]) {
@@ -1570,7 +1671,26 @@ exports.Transaction = Transaction = Transaction_1 = __decorate([
1570
1671
  .mapOut((tx) => Transaction.from({ ...tx.raw, witnesses: tx.witnesses })))
1571
1672
  ], Transaction);
1572
1673
  /**
1573
- * Calculate Nervos DAO profit between two blocks
1674
+ * Calculate Nervos DAO profit between two blocks.
1675
+ * This function computes the profit earned from a Nervos DAO deposit
1676
+ * based on the capacity and the time period between deposit and withdrawal.
1677
+ *
1678
+ * @param profitableCapacity - The capacity that earns profit (total capacity minus occupied capacity).
1679
+ * @param depositHeaderLike - The block header when the DAO deposit was made.
1680
+ * @param withdrawHeaderLike - The block header when the DAO withdrawal is made.
1681
+ * @returns The profit amount in CKB (capacity units).
1682
+ *
1683
+ * @example
1684
+ * ```typescript
1685
+ * const profit = calcDaoProfit(
1686
+ * ccc.fixedPointFrom(100), // 100 CKB profitable capacity
1687
+ * depositHeader,
1688
+ * withdrawHeader
1689
+ * );
1690
+ * console.log(`Profit: ${profit} shannons`);
1691
+ * ```
1692
+ *
1693
+ * @see {@link https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0023-dao-deposit-withdraw/0023-dao-deposit-withdraw.md | Nervos DAO RFC}
1574
1694
  */
1575
1695
  function calcDaoProfit(profitableCapacity, depositHeaderLike, withdrawHeaderLike) {
1576
1696
  const depositHeader = index_js_2.ClientBlockHeader.from(depositHeaderLike);
@@ -1580,8 +1700,26 @@ function calcDaoProfit(profitableCapacity, depositHeaderLike, withdrawHeaderLike
1580
1700
  profitableSize);
1581
1701
  }
1582
1702
  /**
1583
- * Calculate claimable epoch for Nervos DAO withdrawal
1584
- * See https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0023-dao-deposit-withdraw/0023-dao-deposit-withdraw.md
1703
+ * Calculate claimable epoch for Nervos DAO withdrawal.
1704
+ * This function determines the earliest epoch when a Nervos DAO withdrawal
1705
+ * can be claimed based on the deposit and withdrawal epochs.
1706
+ *
1707
+ * @param depositHeader - The block header when the DAO deposit was made.
1708
+ * @param withdrawHeader - The block header when the DAO withdrawal was initiated.
1709
+ * @returns The epoch when the withdrawal can be claimed, represented as [number, index, length].
1710
+ *
1711
+ * @example
1712
+ * ```typescript
1713
+ * const claimEpoch = calcDaoClaimEpoch(depositHeader, withdrawHeader);
1714
+ * console.log(`Can claim at epoch: ${claimEpoch[0]}, index: ${claimEpoch[1]}, length: ${claimEpoch[2]}`);
1715
+ * ```
1716
+ *
1717
+ * @remarks
1718
+ * The Nervos DAO has a minimum lock period of 180 epochs (~30 days).
1719
+ * This function calculates the exact epoch when the withdrawal becomes claimable
1720
+ * based on the deposit epoch and withdrawal epoch timing.
1721
+ *
1722
+ * @see {@link https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0023-dao-deposit-withdraw/0023-dao-deposit-withdraw.md | Nervos DAO RFC}
1585
1723
  */
1586
1724
  function calcDaoClaimEpoch(depositHeader, withdrawHeader) {
1587
1725
  const depositEpoch = index_js_2.ClientBlockHeader.from(depositHeader).epoch;
@@ -1 +1 @@
1
- {"version":3,"file":"clientPublicMainnet.advanced.d.ts","sourceRoot":"","sources":["../../src/client/clientPublicMainnet.advanced.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,WAAW,EAAE,cAAc,GAAG,SAAS,CAscxE,CAAC"}
1
+ {"version":3,"file":"clientPublicMainnet.advanced.d.ts","sourceRoot":"","sources":["../../src/client/clientPublicMainnet.advanced.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,WAAW,EAAE,cAAc,GAAG,SAAS,CAwcxE,CAAC"}
@@ -105,10 +105,71 @@ exports.MAINNET_SCRIPTS = Object.freeze({
105
105
  {
106
106
  cellDep: {
107
107
  outPoint: {
108
- txHash: "0xf05188e5f3a6767fc4687faf45ba5f1a6e25d3ada6129dae8722cb282f262493",
108
+ txHash: "0xbdc3153fcb7c256d007be758c0b50c8da60b5ac0e44ae9e11d3dcc5b73d2b347",
109
109
  index: 0,
110
110
  },
111
- depType: "depGroup",
111
+ depType: "code",
112
+ },
113
+ type: {
114
+ codeHash: "0x00000000000000000000000000000000000000000000000000545950455f4944",
115
+ hashType: "type",
116
+ args: "0xd00c84f0ec8fd441c38bc3f87a371f547190f2fcff88e642bc5bf54b9e318323",
117
+ },
118
+ },
119
+ {
120
+ cellDep: {
121
+ outPoint: {
122
+ txHash: "0xbac0f6f0a177a03974870df47ab0c3e761c5dd19e9ca165358d0b72bd7f433f5",
123
+ index: 1,
124
+ },
125
+ depType: "code",
126
+ },
127
+ type: {
128
+ codeHash: "0x00000000000000000000000000000000000000000000000000545950455f4944",
129
+ hashType: "type",
130
+ args: "0xaede124e8eca8ea4a0029d5f0999299a3f9a4090c6fd6f83d88c41707cc8aa75",
131
+ },
132
+ },
133
+ {
134
+ cellDep: {
135
+ outPoint: {
136
+ txHash: "0xbac0f6f0a177a03974870df47ab0c3e761c5dd19e9ca165358d0b72bd7f433f5",
137
+ index: 2,
138
+ },
139
+ depType: "code",
140
+ },
141
+ type: {
142
+ codeHash: "0x00000000000000000000000000000000000000000000000000545950455f4944",
143
+ hashType: "type",
144
+ args: "0x2409a9568c2ae67e73e12b1f0193c9a44c782ec1c73627b3c92ad2d0fb6128ed",
145
+ },
146
+ },
147
+ {
148
+ cellDep: {
149
+ outPoint: {
150
+ txHash: "0xbac0f6f0a177a03974870df47ab0c3e761c5dd19e9ca165358d0b72bd7f433f5",
151
+ index: 3,
152
+ },
153
+ depType: "code",
154
+ },
155
+ type: {
156
+ codeHash: "0x00000000000000000000000000000000000000000000000000545950455f4944",
157
+ hashType: "type",
158
+ args: "0xaf96ed62f5997c4a4814058545bc958124bada97fcd42955756e3c078da64523",
159
+ },
160
+ },
161
+ {
162
+ cellDep: {
163
+ outPoint: {
164
+ txHash: "0xbac0f6f0a177a03974870df47ab0c3e761c5dd19e9ca165358d0b72bd7f433f5",
165
+ index: 4,
166
+ },
167
+ depType: "code",
168
+ },
169
+ type: {
170
+ codeHash: "0x00000000000000000000000000000000000000000000000000545950455f4944",
171
+ hashType: "type",
172
+ args: "0xfa9f0c3599dc23b9489a11dfedb11489c7ad342982848495856966ed23a6bc7d",
112
173
  },
113
174
  },
114
175
  ],
@@ -341,64 +402,4 @@ exports.MAINNET_SCRIPTS = Object.freeze({
341
402
  },
342
403
  ],
343
404
  },
344
- [knownScript_js_1.KnownScript.RgbppLock]: {
345
- codeHash: "0xbc6c568a1a0d0a09f6844dc9d74ddb4343c32143ff25f727c59edf4fb72d6936",
346
- hashType: "type",
347
- cellDeps: [
348
- {
349
- cellDep: {
350
- outPoint: {
351
- txHash: "0x04c5c3e69f1aa6ee27fb9de3d15a81704e387ab3b453965adbe0b6ca343c6f41",
352
- index: 0,
353
- },
354
- depType: "code",
355
- },
356
- type: {
357
- codeHash: "0x00000000000000000000000000000000000000000000000000545950455f4944",
358
- hashType: "type",
359
- args: "0x68ad3d9e0bb9ea841a5d1fcd600137bd3f45401e759e353121f26cd0d981452f",
360
- },
361
- },
362
- // Rgbpp lock config cell dep
363
- {
364
- cellDep: {
365
- outPoint: {
366
- txHash: "0x04c5c3e69f1aa6ee27fb9de3d15a81704e387ab3b453965adbe0b6ca343c6f41",
367
- index: 1,
368
- },
369
- depType: "code",
370
- },
371
- },
372
- ],
373
- },
374
- [knownScript_js_1.KnownScript.BtcTimeLock]: {
375
- codeHash: "0x70d64497a075bd651e98ac030455ea200637ee325a12ad08aff03f1a117e5a62",
376
- hashType: "type",
377
- cellDeps: [
378
- {
379
- cellDep: {
380
- outPoint: {
381
- txHash: "0x6257bf4297ee75fcebe2654d8c5f8d93bc9fc1b3dc62b8cef54ffe166162e996",
382
- index: 0,
383
- },
384
- depType: "code",
385
- },
386
- type: {
387
- codeHash: "0x00000000000000000000000000000000000000000000000000545950455f4944",
388
- hashType: "type",
389
- args: "0x44b8253ae18e913a2845b0d548eaf6b3ba1099ed26835888932a754194028a8a",
390
- },
391
- },
392
- // btc time lock config cell dep
393
- {
394
- cellDep: {
395
- outPoint: {
396
- txHash: "0x6257bf4297ee75fcebe2654d8c5f8d93bc9fc1b3dc62b8cef54ffe166162e996",
397
- index: 1,
398
- },
399
- depType: "code",
400
- },
401
- },
402
- ],
403
- },
404
405
  });
@@ -1,27 +1,4 @@
1
1
  import { ScriptInfoLike } from "./clientTypes.js";
2
2
  import { KnownScript } from "./knownScript.js";
3
3
  export declare const TESTNET_SCRIPTS: Record<KnownScript, ScriptInfoLike>;
4
- /**
5
- * Bitcoin Signet specific script overrides for testnet
6
- *
7
- * Contains script configurations that differ when using Bitcoin Signet
8
- * instead of Bitcoin Testnet3. Only RgbppLock and BtcTimeLock are affected.
9
- *
10
- * @example
11
- * ```typescript
12
- * import { ClientPublicTestnet } from "@ckb-ccc/core";
13
- * import { TESTNET_SCRIPTS, TESTNET_SCRIPTS_BTC_SIGNET_OVERRIDES } from "@ckb-ccc/core/advanced";
14
- *
15
- * // Use Bitcoin Testnet3 scripts (default)
16
- * const testnet3Client = new ClientPublicTestnet();
17
- *
18
- * // Use Bitcoin Signet scripts by merging overrides
19
- * const signetClient = new ClientPublicTestnet({
20
- * scripts: {
21
- * ...TESTNET_SCRIPTS,
22
- * ...TESTNET_SCRIPTS_BTC_SIGNET_OVERRIDES
23
- * }
24
- * });
25
- */
26
- export declare const TESTNET_SCRIPTS_BTC_SIGNET_OVERRIDES: Partial<Record<KnownScript, ScriptInfoLike>>;
27
4
  //# sourceMappingURL=clientPublicTestnet.advanced.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"clientPublicTestnet.advanced.d.ts","sourceRoot":"","sources":["../../src/client/clientPublicTestnet.advanced.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,WAAW,EAAE,cAAc,CAkd5D,CAAC;AAEL;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,oCAAoC,EAAE,OAAO,CACxD,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,CAsEnC,CAAC"}
1
+ {"version":3,"file":"clientPublicTestnet.advanced.d.ts","sourceRoot":"","sources":["../../src/client/clientPublicTestnet.advanced.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,WAAW,EAAE,cAAc,CAod5D,CAAC"}