@ckb-ccc/core 1.10.0 → 1.11.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.
Files changed (71) hide show
  1. package/CHANGELOG.md +36 -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 +0 -60
  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 +0 -144
  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 +0 -60
  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 +1 -145
  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 +0 -68
  66. package/src/client/clientPublicTestnet.advanced.ts +0 -163
  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
@@ -172,26 +172,15 @@ let CellOutput = CellOutput_1 = class CellOutput extends mol.Entity.Base() {
172
172
  get occupiedSize() {
173
173
  return 8 + this.lock.occupiedSize + (this.type?.occupiedSize ?? 0);
174
174
  }
175
- /**
176
- * Creates a CellOutput instance from a CellOutputLike object.
177
- *
178
- * @param cellOutput - A CellOutputLike object or an instance of CellOutput.
179
- * @returns A CellOutput instance.
180
- *
181
- * @example
182
- * ```typescript
183
- * const cellOutput = CellOutput.from({
184
- * capacity: 1000n,
185
- * lock: { codeHash: "0x...", hashType: "type", args: "0x..." },
186
- * type: { codeHash: "0x...", hashType: "type", args: "0x..." }
187
- * });
188
- * ```
189
- */
190
- static from(cellOutput) {
175
+ static from(cellOutput, outputData) {
191
176
  if (cellOutput instanceof CellOutput_1) {
192
177
  return cellOutput;
193
178
  }
194
- return new CellOutput_1(numFrom(cellOutput.capacity), Script.from(cellOutput.lock), apply(Script.from, cellOutput.type));
179
+ const output = new CellOutput_1(numFrom(cellOutput.capacity ?? 0), Script.from(cellOutput.lock), apply(Script.from, cellOutput.type));
180
+ if (output.capacity === Zero) {
181
+ output.capacity = fixedPointFrom(output.occupiedSize + bytesFrom(outputData ?? "0x").length);
182
+ }
183
+ return output;
195
184
  }
196
185
  /**
197
186
  * Clone a CellOutput.
@@ -234,15 +223,43 @@ export class Cell {
234
223
  }
235
224
  /**
236
225
  * Creates a Cell instance from a CellLike object.
226
+ * This method accepts either `outPoint` or `previousOutput` to specify the cell's location,
227
+ * and supports automatic capacity calculation for the cell output.
237
228
  *
238
- * @param cell - A CellLike object or an instance of Cell.
229
+ * @param cell - A CellLike object or an instance of Cell. The object can use either:
230
+ * - `outPoint`: For referencing a cell output
231
+ * - `previousOutput`: For referencing a cell input (alternative name for outPoint)
232
+ * The cellOutput can omit capacity for automatic calculation.
239
233
  * @returns A Cell instance.
234
+ *
235
+ * @example
236
+ * ```typescript
237
+ * // Using outPoint with explicit capacity
238
+ * const cell1 = Cell.from({
239
+ * outPoint: { txHash: "0x...", index: 0 },
240
+ * cellOutput: {
241
+ * capacity: 1000n,
242
+ * lock: { codeHash: "0x...", hashType: "type", args: "0x..." }
243
+ * },
244
+ * outputData: "0x"
245
+ * });
246
+ *
247
+ * // Using previousOutput with automatic capacity calculation
248
+ * const cell2 = Cell.from({
249
+ * previousOutput: { txHash: "0x...", index: 0 },
250
+ * cellOutput: {
251
+ * lock: { codeHash: "0x...", hashType: "type", args: "0x..." }
252
+ * // capacity will be calculated automatically
253
+ * },
254
+ * outputData: "0x1234"
255
+ * });
256
+ * ```
240
257
  */
241
258
  static from(cell) {
242
259
  if (cell instanceof Cell) {
243
260
  return cell;
244
261
  }
245
- return new Cell(OutPoint.from("outPoint" in cell ? cell.outPoint : cell.previousOutput), CellOutput.from(cell.cellOutput), hexFrom(cell.outputData));
262
+ return new Cell(OutPoint.from("outPoint" in cell ? cell.outPoint : cell.previousOutput), CellOutput.from(cell.cellOutput, cell.outputData), hexFrom(cell.outputData));
246
263
  }
247
264
  get capacityFree() {
248
265
  const occupiedSize = fixedPointFrom(this.cellOutput.occupiedSize + bytesFrom(this.outputData).length);
@@ -720,6 +737,9 @@ let Transaction = Transaction_1 = class Transaction extends mol.Entity.Base() {
720
737
  }
721
738
  /**
722
739
  * Copy every properties from another transaction.
740
+ * This method replaces all properties of the current transaction with those from the provided transaction.
741
+ *
742
+ * @param txLike - The transaction-like object to copy properties from.
723
743
  *
724
744
  * @example
725
745
  * ```typescript
@@ -799,17 +819,7 @@ let Transaction = Transaction_1 = class Transaction extends mol.Entity.Base() {
799
819
  if (tx instanceof Transaction_1) {
800
820
  return tx;
801
821
  }
802
- const outputs = tx.outputs?.map((output, i) => {
803
- const o = CellOutput.from({
804
- ...output,
805
- capacity: output.capacity ?? 0,
806
- });
807
- if (o.capacity === Zero) {
808
- o.capacity = fixedPointFrom(o.occupiedSize +
809
- (apply(bytesFrom, tx.outputsData?.[i])?.length ?? 0));
810
- }
811
- return o;
812
- }) ?? [];
822
+ const outputs = tx.outputs?.map((output, i) => CellOutput.from(output, tx.outputsData?.[i] ?? [])) ?? [];
813
823
  const outputsData = outputs.map((_, i) => hexFrom(tx.outputsData?.[i] ?? "0x"));
814
824
  if (tx.outputsData != null && outputsData.length < tx.outputsData.length) {
815
825
  outputsData.push(...tx.outputsData.slice(outputsData.length).map((d) => hexFrom(d)));
@@ -992,7 +1002,7 @@ let Transaction = Transaction_1 = class Transaction extends mol.Entity.Base() {
992
1002
  *
993
1003
  * @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
994
1004
  * @param client - The client for complete extra infos in the transaction.
995
- * @returns A promise that resolves to the prepared transaction
1005
+ * @returns A promise that resolves to the found index, or undefined if no matching input is found.
996
1006
  *
997
1007
  * @example
998
1008
  * ```typescript
@@ -1013,7 +1023,7 @@ let Transaction = Transaction_1 = class Transaction extends mol.Entity.Base() {
1013
1023
  *
1014
1024
  * @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
1015
1025
  * @param client - The client for complete extra infos in the transaction.
1016
- * @returns A promise that resolves to the prepared transaction
1026
+ * @returns A promise that resolves to the found index, or undefined if no matching input is found.
1017
1027
  *
1018
1028
  * @example
1019
1029
  * ```typescript
@@ -1101,18 +1111,18 @@ let Transaction = Transaction_1 = class Transaction extends mol.Entity.Base() {
1101
1111
  * Set output data at index.
1102
1112
  *
1103
1113
  * @param index - The index of the output data.
1104
- * @param witness - The data to set.
1114
+ * @param data - The data to set.
1105
1115
  *
1106
1116
  * @example
1107
1117
  * ```typescript
1108
- * await tx.setOutputDataAt(0, "0x00");
1118
+ * tx.setOutputDataAt(0, "0x00");
1109
1119
  * ```
1110
1120
  */
1111
- setOutputDataAt(index, witness) {
1121
+ setOutputDataAt(index, data) {
1112
1122
  if (this.outputsData.length < index) {
1113
1123
  this.outputsData.push(...Array.from(new Array(index - this.outputsData.length), () => "0x"));
1114
1124
  }
1115
- this.outputsData[index] = hexFrom(witness);
1125
+ this.outputsData[index] = hexFrom(data);
1116
1126
  }
1117
1127
  /**
1118
1128
  * get input
@@ -1175,14 +1185,7 @@ let Transaction = Transaction_1 = class Transaction extends mol.Entity.Base() {
1175
1185
  * ```
1176
1186
  */
1177
1187
  addOutput(outputLike, outputData = "0x") {
1178
- const output = CellOutput.from({
1179
- ...outputLike,
1180
- capacity: outputLike.capacity ?? 0,
1181
- });
1182
- if (output.capacity === Zero) {
1183
- output.capacity = fixedPointFrom(output.occupiedSize + bytesFrom(outputData).length);
1184
- }
1185
- const len = this.outputs.push(output);
1188
+ const len = this.outputs.push(CellOutput.from(outputLike, outputData));
1186
1189
  this.setOutputDataAt(len - 1, outputData);
1187
1190
  return len;
1188
1191
  }
@@ -1454,18 +1457,20 @@ let Transaction = Transaction_1 = class Transaction extends mol.Entity.Base() {
1454
1457
  await this.getInputsCapacity(from.client);
1455
1458
  let leastFee = Zero;
1456
1459
  let leastExtraCapacity = Zero;
1460
+ let collected = 0;
1461
+ // ===
1462
+ // Usually, for the worst situation, three iterations are needed
1463
+ // 1. First attempt to complete the transaction.
1464
+ // 2. Not enough capacity for the change cell.
1465
+ // 3. Fee increased by the change cell.
1466
+ // ===
1457
1467
  while (true) {
1458
- const tx = this.clone();
1459
- const collected = await (async () => {
1468
+ collected += await (async () => {
1460
1469
  if (!(options?.shouldAddInputs ?? true)) {
1461
- const fee = (await tx.getFee(from.client)) - leastFee - leastExtraCapacity;
1462
- if (fee < Zero) {
1463
- throw new ErrorTransactionInsufficientCapacity(-fee);
1464
- }
1465
1470
  return 0;
1466
1471
  }
1467
1472
  try {
1468
- return await tx.completeInputsByCapacity(from, leastFee + leastExtraCapacity, filter);
1473
+ return await this.completeInputsByCapacity(from, leastFee + leastExtraCapacity, filter);
1469
1474
  }
1470
1475
  catch (err) {
1471
1476
  if (err instanceof ErrorTransactionInsufficientCapacity &&
@@ -1477,20 +1482,28 @@ let Transaction = Transaction_1 = class Transaction extends mol.Entity.Base() {
1477
1482
  throw err;
1478
1483
  }
1479
1484
  })();
1480
- await from.prepareTransaction(tx);
1485
+ const fee = await this.getFee(from.client);
1486
+ if (fee < leastFee + leastExtraCapacity) {
1487
+ // Not enough capacity are collected, it should only happens when shouldAddInputs is false
1488
+ throw new ErrorTransactionInsufficientCapacity(leastFee + leastExtraCapacity - fee, { isForChange: leastExtraCapacity !== Zero });
1489
+ }
1490
+ await from.prepareTransaction(this);
1481
1491
  if (leastFee === Zero) {
1482
1492
  // The initial fee is calculated based on prepared transaction
1483
- leastFee = tx.estimateFee(feeRate);
1493
+ // This should only happens during the first iteration
1494
+ leastFee = this.estimateFee(feeRate);
1484
1495
  }
1485
- const fee = await tx.getFee(from.client);
1486
1496
  // The extra capacity paid the fee without a change
1497
+ // leastExtraCapacity should be 0 here, otherwise we should failed in the previous check
1498
+ // So this only happens in the first iteration
1487
1499
  if (fee === leastFee) {
1488
- this.copy(tx);
1489
1500
  return [collected, false];
1490
1501
  }
1502
+ // Invoke the change function on a transaction multiple times may cause problems, so we clone it
1503
+ const tx = this.clone();
1491
1504
  const needed = numFrom(await Promise.resolve(change(tx, fee - leastFee)));
1492
- // No enough extra capacity to create new cells for change
1493
1505
  if (needed > Zero) {
1506
+ // No enough extra capacity to create new cells for change, collect inputs again
1494
1507
  leastExtraCapacity = needed;
1495
1508
  continue;
1496
1509
  }
@@ -1512,6 +1525,38 @@ let Transaction = Transaction_1 = class Transaction extends mol.Entity.Base() {
1512
1525
  leastFee = changedFee;
1513
1526
  }
1514
1527
  }
1528
+ /**
1529
+ * Completes the transaction fee by adding inputs and creating a change output with the specified lock script.
1530
+ * This is a convenience method that automatically creates a change cell with the provided lock script
1531
+ * when there's excess capacity after paying the transaction fee.
1532
+ *
1533
+ * @param from - The signer to complete inputs from and prepare the transaction.
1534
+ * @param change - The lock script for the change output cell.
1535
+ * @param feeRate - Optional fee rate in shannons per 1000 bytes. If not provided, it will be fetched from the client.
1536
+ * @param filter - Optional filter for selecting cells when adding inputs.
1537
+ * @param options - Optional configuration object.
1538
+ * @param options.feeRateBlockRange - Block range for fee rate calculation when feeRate is not provided.
1539
+ * @param options.maxFeeRate - Maximum allowed fee rate.
1540
+ * @param options.shouldAddInputs - Whether to add inputs automatically. Defaults to true.
1541
+ * @returns A promise that resolves to a tuple containing:
1542
+ * - The number of inputs added during the process
1543
+ * - A boolean indicating whether change outputs were created (true) or fee was paid without change (false)
1544
+ *
1545
+ * @example
1546
+ * ```typescript
1547
+ * const changeScript = Script.from({
1548
+ * codeHash: "0x...",
1549
+ * hashType: "type",
1550
+ * args: "0x..."
1551
+ * });
1552
+ *
1553
+ * const [addedInputs, hasChange] = await tx.completeFeeChangeToLock(
1554
+ * signer,
1555
+ * changeScript,
1556
+ * 1000n // 1000 shannons per 1000 bytes
1557
+ * );
1558
+ * ```
1559
+ */
1515
1560
  completeFeeChangeToLock(from, change, feeRate, filter, options) {
1516
1561
  const script = Script.from(change);
1517
1562
  return this.completeFee(from, (tx, capacity) => {
@@ -1525,10 +1570,66 @@ let Transaction = Transaction_1 = class Transaction extends mol.Entity.Base() {
1525
1570
  return 0;
1526
1571
  }, feeRate, filter, options);
1527
1572
  }
1573
+ /**
1574
+ * Completes the transaction fee using the signer's recommended address for change.
1575
+ * This is a convenience method that automatically uses the signer's recommended
1576
+ * address as the change destination, making it easier to complete transactions
1577
+ * without manually specifying a change address.
1578
+ *
1579
+ * @param from - The signer to complete inputs from and prepare the transaction.
1580
+ * @param feeRate - Optional fee rate in shannons per 1000 bytes. If not provided, it will be fetched from the client.
1581
+ * @param filter - Optional filter for selecting cells when adding inputs.
1582
+ * @param options - Optional configuration object.
1583
+ * @param options.feeRateBlockRange - Block range for fee rate calculation when feeRate is not provided.
1584
+ * @param options.maxFeeRate - Maximum allowed fee rate.
1585
+ * @param options.shouldAddInputs - Whether to add inputs automatically. Defaults to true.
1586
+ * @returns A promise that resolves to a tuple containing:
1587
+ * - The number of inputs added during the process
1588
+ * - A boolean indicating whether change outputs were created (true) or fee was paid without change (false)
1589
+ *
1590
+ * @example
1591
+ * ```typescript
1592
+ * const [addedInputs, hasChange] = await tx.completeFeeBy(
1593
+ * signer,
1594
+ * 1000n // 1000 shannons per 1000 bytes
1595
+ * );
1596
+ *
1597
+ * // Change will automatically go to signer's recommended address
1598
+ * ```
1599
+ */
1528
1600
  async completeFeeBy(from, feeRate, filter, options) {
1529
1601
  const { script } = await from.getRecommendedAddressObj();
1530
1602
  return this.completeFeeChangeToLock(from, script, feeRate, filter, options);
1531
1603
  }
1604
+ /**
1605
+ * Completes the transaction fee by adding excess capacity to an existing output.
1606
+ * Instead of creating a new change output, this method adds any excess capacity
1607
+ * to the specified existing output in the transaction.
1608
+ *
1609
+ * @param from - The signer to complete inputs from and prepare the transaction.
1610
+ * @param index - The index of the existing output to add excess capacity to.
1611
+ * @param feeRate - Optional fee rate in shannons per 1000 bytes. If not provided, it will be fetched from the client.
1612
+ * @param filter - Optional filter for selecting cells when adding inputs.
1613
+ * @param options - Optional configuration object.
1614
+ * @param options.feeRateBlockRange - Block range for fee rate calculation when feeRate is not provided.
1615
+ * @param options.maxFeeRate - Maximum allowed fee rate.
1616
+ * @param options.shouldAddInputs - Whether to add inputs automatically. Defaults to true.
1617
+ * @returns A promise that resolves to a tuple containing:
1618
+ * - The number of inputs added during the process
1619
+ * - A boolean indicating whether change was applied (true) or fee was paid without change (false)
1620
+ *
1621
+ * @throws {Error} When the specified output index doesn't exist.
1622
+ *
1623
+ * @example
1624
+ * ```typescript
1625
+ * // Add excess capacity to the first output (index 0)
1626
+ * const [addedInputs, hasChange] = await tx.completeFeeChangeToOutput(
1627
+ * signer,
1628
+ * 0, // Output index
1629
+ * 1000n // 1000 shannons per 1000 bytes
1630
+ * );
1631
+ * ```
1632
+ */
1532
1633
  completeFeeChangeToOutput(from, index, feeRate, filter, options) {
1533
1634
  const change = Number(numFrom(index));
1534
1635
  if (!this.outputs[change]) {
@@ -1557,7 +1658,26 @@ Transaction = Transaction_1 = __decorate([
1557
1658
  ], Transaction);
1558
1659
  export { Transaction };
1559
1660
  /**
1560
- * Calculate Nervos DAO profit between two blocks
1661
+ * Calculate Nervos DAO profit between two blocks.
1662
+ * This function computes the profit earned from a Nervos DAO deposit
1663
+ * based on the capacity and the time period between deposit and withdrawal.
1664
+ *
1665
+ * @param profitableCapacity - The capacity that earns profit (total capacity minus occupied capacity).
1666
+ * @param depositHeaderLike - The block header when the DAO deposit was made.
1667
+ * @param withdrawHeaderLike - The block header when the DAO withdrawal is made.
1668
+ * @returns The profit amount in CKB (capacity units).
1669
+ *
1670
+ * @example
1671
+ * ```typescript
1672
+ * const profit = calcDaoProfit(
1673
+ * ccc.fixedPointFrom(100), // 100 CKB profitable capacity
1674
+ * depositHeader,
1675
+ * withdrawHeader
1676
+ * );
1677
+ * console.log(`Profit: ${profit} shannons`);
1678
+ * ```
1679
+ *
1680
+ * @see {@link https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0023-dao-deposit-withdraw/0023-dao-deposit-withdraw.md | Nervos DAO RFC}
1561
1681
  */
1562
1682
  export function calcDaoProfit(profitableCapacity, depositHeaderLike, withdrawHeaderLike) {
1563
1683
  const depositHeader = ClientBlockHeader.from(depositHeaderLike);
@@ -1567,8 +1687,26 @@ export function calcDaoProfit(profitableCapacity, depositHeaderLike, withdrawHea
1567
1687
  profitableSize);
1568
1688
  }
1569
1689
  /**
1570
- * Calculate claimable epoch for Nervos DAO withdrawal
1571
- * See https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0023-dao-deposit-withdraw/0023-dao-deposit-withdraw.md
1690
+ * Calculate claimable epoch for Nervos DAO withdrawal.
1691
+ * This function determines the earliest epoch when a Nervos DAO withdrawal
1692
+ * can be claimed based on the deposit and withdrawal epochs.
1693
+ *
1694
+ * @param depositHeader - The block header when the DAO deposit was made.
1695
+ * @param withdrawHeader - The block header when the DAO withdrawal was initiated.
1696
+ * @returns The epoch when the withdrawal can be claimed, represented as [number, index, length].
1697
+ *
1698
+ * @example
1699
+ * ```typescript
1700
+ * const claimEpoch = calcDaoClaimEpoch(depositHeader, withdrawHeader);
1701
+ * console.log(`Can claim at epoch: ${claimEpoch[0]}, index: ${claimEpoch[1]}, length: ${claimEpoch[2]}`);
1702
+ * ```
1703
+ *
1704
+ * @remarks
1705
+ * The Nervos DAO has a minimum lock period of 180 epochs (~30 days).
1706
+ * This function calculates the exact epoch when the withdrawal becomes claimable
1707
+ * based on the deposit epoch and withdrawal epoch timing.
1708
+ *
1709
+ * @see {@link https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0023-dao-deposit-withdraw/0023-dao-deposit-withdraw.md | Nervos DAO RFC}
1572
1710
  */
1573
1711
  export function calcDaoClaimEpoch(depositHeader, withdrawHeader) {
1574
1712
  const depositEpoch = 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,CAkYxE,CAAC"}
@@ -338,64 +338,4 @@ export const MAINNET_SCRIPTS = Object.freeze({
338
338
  },
339
339
  ],
340
340
  },
341
- [KnownScript.RgbppLock]: {
342
- codeHash: "0xbc6c568a1a0d0a09f6844dc9d74ddb4343c32143ff25f727c59edf4fb72d6936",
343
- hashType: "type",
344
- cellDeps: [
345
- {
346
- cellDep: {
347
- outPoint: {
348
- txHash: "0x04c5c3e69f1aa6ee27fb9de3d15a81704e387ab3b453965adbe0b6ca343c6f41",
349
- index: 0,
350
- },
351
- depType: "code",
352
- },
353
- type: {
354
- codeHash: "0x00000000000000000000000000000000000000000000000000545950455f4944",
355
- hashType: "type",
356
- args: "0x68ad3d9e0bb9ea841a5d1fcd600137bd3f45401e759e353121f26cd0d981452f",
357
- },
358
- },
359
- // Rgbpp lock config cell dep
360
- {
361
- cellDep: {
362
- outPoint: {
363
- txHash: "0x04c5c3e69f1aa6ee27fb9de3d15a81704e387ab3b453965adbe0b6ca343c6f41",
364
- index: 1,
365
- },
366
- depType: "code",
367
- },
368
- },
369
- ],
370
- },
371
- [KnownScript.BtcTimeLock]: {
372
- codeHash: "0x70d64497a075bd651e98ac030455ea200637ee325a12ad08aff03f1a117e5a62",
373
- hashType: "type",
374
- cellDeps: [
375
- {
376
- cellDep: {
377
- outPoint: {
378
- txHash: "0x6257bf4297ee75fcebe2654d8c5f8d93bc9fc1b3dc62b8cef54ffe166162e996",
379
- index: 0,
380
- },
381
- depType: "code",
382
- },
383
- type: {
384
- codeHash: "0x00000000000000000000000000000000000000000000000000545950455f4944",
385
- hashType: "type",
386
- args: "0x44b8253ae18e913a2845b0d548eaf6b3ba1099ed26835888932a754194028a8a",
387
- },
388
- },
389
- // btc time lock config cell dep
390
- {
391
- cellDep: {
392
- outPoint: {
393
- txHash: "0x6257bf4297ee75fcebe2654d8c5f8d93bc9fc1b3dc62b8cef54ffe166162e996",
394
- index: 1,
395
- },
396
- depType: "code",
397
- },
398
- },
399
- ],
400
- },
401
341
  });
@@ -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,CA8Y5D,CAAC"}
@@ -348,148 +348,4 @@ export const TESTNET_SCRIPTS = Object.freeze({
348
348
  },
349
349
  ],
350
350
  },
351
- [KnownScript.RgbppLock]: {
352
- codeHash: "0x61ca7a4796a4eb19ca4f0d065cb9b10ddcf002f10f7cbb810c706cb6bb5c3248",
353
- hashType: "type",
354
- cellDeps: [
355
- {
356
- cellDep: {
357
- outPoint: {
358
- txHash: "0xf1de59e973b85791ec32debbba08dff80c63197e895eb95d67fc1e9f6b413e00",
359
- index: 0,
360
- },
361
- depType: "code",
362
- },
363
- type: {
364
- codeHash: "0x00000000000000000000000000000000000000000000000000545950455f4944",
365
- hashType: "type",
366
- args: "0xa3bc8441df149def76cfe15fec7b1e51d949548bc27fb7a75e9d4b3ef1c12c7f",
367
- },
368
- },
369
- // Rgbpp lock config cell dep for Bitcoin Testnet3
370
- {
371
- cellDep: {
372
- outPoint: {
373
- txHash: "0xf1de59e973b85791ec32debbba08dff80c63197e895eb95d67fc1e9f6b413e00",
374
- index: 1,
375
- },
376
- depType: "code",
377
- },
378
- },
379
- ],
380
- },
381
- [KnownScript.BtcTimeLock]: {
382
- codeHash: "0x00cdf8fab0f8ac638758ebf5ea5e4052b1d71e8a77b9f43139718621f6849326",
383
- hashType: "type",
384
- cellDeps: [
385
- {
386
- cellDep: {
387
- outPoint: {
388
- txHash: "0xde0f87878a97500f549418e5d46d2f7704c565a262aa17036c9c1c13ad638529",
389
- index: 0,
390
- },
391
- depType: "code",
392
- },
393
- type: {
394
- codeHash: "0x00000000000000000000000000000000000000000000000000545950455f4944",
395
- hashType: "type",
396
- args: "0xc9828585e6dd2afacb9e6e8ca7deb0975121aabee5c7983178a45509ffaec984",
397
- },
398
- },
399
- // btc time lock config cell dep for Bitcoin Testnet3
400
- {
401
- cellDep: {
402
- outPoint: {
403
- txHash: "0xde0f87878a97500f549418e5d46d2f7704c565a262aa17036c9c1c13ad638529",
404
- index: 1,
405
- },
406
- depType: "code",
407
- },
408
- },
409
- ],
410
- },
411
- });
412
- /**
413
- * Bitcoin Signet specific script overrides for testnet
414
- *
415
- * Contains script configurations that differ when using Bitcoin Signet
416
- * instead of Bitcoin Testnet3. Only RgbppLock and BtcTimeLock are affected.
417
- *
418
- * @example
419
- * ```typescript
420
- * import { ClientPublicTestnet } from "@ckb-ccc/core";
421
- * import { TESTNET_SCRIPTS, TESTNET_SCRIPTS_BTC_SIGNET_OVERRIDES } from "@ckb-ccc/core/advanced";
422
- *
423
- * // Use Bitcoin Testnet3 scripts (default)
424
- * const testnet3Client = new ClientPublicTestnet();
425
- *
426
- * // Use Bitcoin Signet scripts by merging overrides
427
- * const signetClient = new ClientPublicTestnet({
428
- * scripts: {
429
- * ...TESTNET_SCRIPTS,
430
- * ...TESTNET_SCRIPTS_BTC_SIGNET_OVERRIDES
431
- * }
432
- * });
433
- */
434
- export const TESTNET_SCRIPTS_BTC_SIGNET_OVERRIDES = Object.freeze({
435
- [KnownScript.RgbppLock]: {
436
- codeHash: "0xd07598deec7ce7b5665310386b4abd06a6d48843e953c5cc2112ad0d5a220364",
437
- hashType: "type",
438
- cellDeps: [
439
- {
440
- cellDep: {
441
- outPoint: {
442
- txHash: "0x61efdeddbaa0bb4132c0eb174b3e8002ff5ec430f61ba46f30768d683c516eec",
443
- index: 0,
444
- },
445
- depType: "code",
446
- },
447
- type: {
448
- codeHash: "0x00000000000000000000000000000000000000000000000000545950455f4944",
449
- hashType: "type",
450
- args: "0xb69fe766ce3b7014a2a78ad1fe688d82f1679325805371d2856c3b8d18ebfa5a",
451
- },
452
- },
453
- // Rgbpp lock config cell dep for Bitcoin Signet
454
- {
455
- cellDep: {
456
- outPoint: {
457
- txHash: "0x61efdeddbaa0bb4132c0eb174b3e8002ff5ec430f61ba46f30768d683c516eec",
458
- index: 1,
459
- },
460
- depType: "code",
461
- },
462
- },
463
- ],
464
- },
465
- [KnownScript.BtcTimeLock]: {
466
- codeHash: "0x80a09eca26d77cea1f5a69471c59481be7404febf40ee90f886c36a948385b55",
467
- hashType: "type",
468
- cellDeps: [
469
- {
470
- cellDep: {
471
- outPoint: {
472
- txHash: "0x5364b3535965e9eac9a35dd7af8e9e45a61d30a16e115923c032f80b28783e21",
473
- index: 0,
474
- },
475
- depType: "code",
476
- },
477
- type: {
478
- codeHash: "0x00000000000000000000000000000000000000000000000000545950455f4944",
479
- hashType: "type",
480
- args: "0x32fc8c70a6451a1439fd91e214bba093f9cdd9276bc4ab223430dab5940aff92",
481
- },
482
- },
483
- // btc time lock config cell dep for Bitcoin Signet
484
- {
485
- cellDep: {
486
- outPoint: {
487
- txHash: "0x5364b3535965e9eac9a35dd7af8e9e45a61d30a16e115923c032f80b28783e21",
488
- index: 1,
489
- },
490
- depType: "code",
491
- },
492
- },
493
- ],
494
- },
495
351
  });
@@ -22,8 +22,6 @@ export declare enum KnownScript {
22
22
  SingleUseLock = "SingleUseLock",
23
23
  TypeBurnLock = "TypeBurnLock",
24
24
  EasyToDiscoverType = "EasyToDiscoverType",
25
- TimeLock = "TimeLock",
26
- RgbppLock = "RgbppLock",
27
- BtcTimeLock = "BtcTimeLock"
25
+ TimeLock = "TimeLock"
28
26
  }
29
27
  //# sourceMappingURL=knownScript.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"knownScript.d.ts","sourceRoot":"","sources":["../../src/client/knownScript.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,oBAAY,WAAW;IACrB,SAAS,cAAc;IACvB,iBAAiB,sBAAsB;IACvC,iBAAiB,sBAAsB;IACvC,mBAAmB,wBAAwB,CAAE,wFAAwF;IACrI,YAAY,iBAAiB;IAC7B,MAAM,WAAW;IACjB,IAAI,SAAS;IACb,KAAK,UAAU;IACf,IAAI,SAAS;IACb,MAAM,WAAW;IACjB,QAAQ,aAAa;IACrB,SAAS,cAAc;IACvB,UAAU,eAAe;IAGzB,aAAa,kBAAkB;IAC/B,kBAAkB,uBAAuB;IACzC,mBAAmB,wBAAwB;IAC3C,aAAa,kBAAkB;IAC/B,aAAa,kBAAkB;IAC/B,YAAY,iBAAiB;IAC7B,kBAAkB,uBAAuB;IACzC,QAAQ,aAAa;IAIrB,SAAS,cAAc;IACvB,WAAW,gBAAgB;CAC5B"}
1
+ {"version":3,"file":"knownScript.d.ts","sourceRoot":"","sources":["../../src/client/knownScript.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,oBAAY,WAAW;IACrB,SAAS,cAAc;IACvB,iBAAiB,sBAAsB;IACvC,iBAAiB,sBAAsB;IACvC,mBAAmB,wBAAwB,CAAE,wFAAwF;IACrI,YAAY,iBAAiB;IAC7B,MAAM,WAAW;IACjB,IAAI,SAAS;IACb,KAAK,UAAU;IACf,IAAI,SAAS;IACb,MAAM,WAAW;IACjB,QAAQ,aAAa;IACrB,SAAS,cAAc;IACvB,UAAU,eAAe;IAGzB,aAAa,kBAAkB;IAC/B,kBAAkB,uBAAuB;IACzC,mBAAmB,wBAAwB;IAC3C,aAAa,kBAAkB;IAC/B,aAAa,kBAAkB;IAC/B,YAAY,iBAAiB;IAC7B,kBAAkB,uBAAuB;IACzC,QAAQ,aAAa;CACtB"}
@@ -25,8 +25,4 @@ export var KnownScript;
25
25
  KnownScript["TypeBurnLock"] = "TypeBurnLock";
26
26
  KnownScript["EasyToDiscoverType"] = "EasyToDiscoverType";
27
27
  KnownScript["TimeLock"] = "TimeLock";
28
- // RGB++ related scripts (default using Bitcoin Testnet3)
29
- // For Bitcoin Signet, use TESTNET_SCRIPTS_BTC_SIGNET_OVERRIDES from @ckb-ccc/core/advanced
30
- KnownScript["RgbppLock"] = "RgbppLock";
31
- KnownScript["BtcTimeLock"] = "BtcTimeLock";
32
28
  })(KnownScript || (KnownScript = {}));