@ckb-ccc/core 1.11.5 → 1.12.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 (53) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/ckb/transaction.d.ts +160 -29
  3. package/dist/ckb/transaction.d.ts.map +1 -1
  4. package/dist/ckb/transaction.js +185 -39
  5. package/dist/client/jsonRpc/client.d.ts +1 -1
  6. package/dist/client/jsonRpc/client.d.ts.map +1 -1
  7. package/dist/client/jsonRpc/client.js +4 -1
  8. package/dist/client/jsonRpc/transformers.d.ts +1 -1
  9. package/dist/client/jsonRpc/transformers.d.ts.map +1 -1
  10. package/dist/client/jsonRpc/transformers.js +2 -1
  11. package/dist/jsonRpc/requestor.js +1 -1
  12. package/dist/signer/btc/verify.d.ts +21 -0
  13. package/dist/signer/btc/verify.d.ts.map +1 -1
  14. package/dist/signer/btc/verify.js +38 -2
  15. package/dist/signer/doge/signerDogePrivateKey.d.ts.map +1 -1
  16. package/dist/signer/doge/signerDogePrivateKey.js +2 -2
  17. package/dist/signer/doge/verify.d.ts +12 -1
  18. package/dist/signer/doge/verify.d.ts.map +1 -1
  19. package/dist/signer/doge/verify.js +15 -5
  20. package/dist/signer/signer/index.d.ts +14 -5
  21. package/dist/signer/signer/index.d.ts.map +1 -1
  22. package/dist/signer/signer/index.js +19 -11
  23. package/dist.commonjs/ckb/transaction.d.ts +160 -29
  24. package/dist.commonjs/ckb/transaction.d.ts.map +1 -1
  25. package/dist.commonjs/ckb/transaction.js +187 -40
  26. package/dist.commonjs/client/jsonRpc/client.d.ts +1 -1
  27. package/dist.commonjs/client/jsonRpc/client.d.ts.map +1 -1
  28. package/dist.commonjs/client/jsonRpc/client.js +4 -1
  29. package/dist.commonjs/client/jsonRpc/transformers.d.ts +1 -1
  30. package/dist.commonjs/client/jsonRpc/transformers.d.ts.map +1 -1
  31. package/dist.commonjs/client/jsonRpc/transformers.js +2 -1
  32. package/dist.commonjs/jsonRpc/requestor.js +1 -1
  33. package/dist.commonjs/signer/btc/verify.d.ts +21 -0
  34. package/dist.commonjs/signer/btc/verify.d.ts.map +1 -1
  35. package/dist.commonjs/signer/btc/verify.js +40 -2
  36. package/dist.commonjs/signer/doge/signerDogePrivateKey.d.ts.map +1 -1
  37. package/dist.commonjs/signer/doge/signerDogePrivateKey.js +2 -2
  38. package/dist.commonjs/signer/doge/verify.d.ts +12 -1
  39. package/dist.commonjs/signer/doge/verify.d.ts.map +1 -1
  40. package/dist.commonjs/signer/doge/verify.js +15 -4
  41. package/dist.commonjs/signer/signer/index.d.ts +14 -5
  42. package/dist.commonjs/signer/signer/index.d.ts.map +1 -1
  43. package/dist.commonjs/signer/signer/index.js +21 -13
  44. package/package.json +3 -4
  45. package/{prettier.config.mjs → prettier.config.cjs} +2 -4
  46. package/src/ckb/transaction.ts +254 -80
  47. package/src/client/jsonRpc/client.ts +5 -2
  48. package/src/client/jsonRpc/transformers.ts +6 -1
  49. package/src/jsonRpc/requestor.ts +2 -2
  50. package/src/signer/btc/verify.ts +52 -3
  51. package/src/signer/doge/signerDogePrivateKey.ts +2 -2
  52. package/src/signer/doge/verify.ts +23 -7
  53. package/src/signer/signer/index.ts +20 -10
@@ -1,12 +1,32 @@
1
1
  import { secp256k1 } from "@noble/curves/secp256k1";
2
- import { magicHash } from "bitcoinjs-message";
3
- import { bytesFrom, BytesLike } from "../../bytes/index.js";
2
+ import { Bytes, bytesFrom, BytesLike } from "../../bytes/index.js";
4
3
  import { hexFrom } from "../../hex/index.js";
5
4
  import {
6
5
  btcEcdsaPublicKeyHash,
7
6
  btcPublicKeyFromP2pkhAddress,
7
+ messageHashBtcEcdsa,
8
8
  } from "../btc/verify.js";
9
9
 
10
+ /**
11
+ * Computes the message hash for Dogecoin ECDSA signatures.
12
+ * This function follows the Dogecoin message signing standard, which involves
13
+ * prefixing the message with a magic string and its length, then double SHA256 hashing the result.
14
+ *
15
+ * @param message - The message to be hashed. Can be a string or BytesLike.
16
+ * @param messagePrefix - Optional. A custom prefix to use instead of the default "\x19Dogecoin Signed Message:\n".
17
+ * @returns The Dogecoin hash of the prefixed message as Bytes.
18
+ * @public
19
+ */
20
+ export function messageHashDogeEcdsa(
21
+ message: string | BytesLike,
22
+ messagePrefix?: string | BytesLike,
23
+ ): Bytes {
24
+ return messageHashBtcEcdsa(
25
+ message,
26
+ messagePrefix ?? "\x19Dogecoin Signed Message:\n",
27
+ );
28
+ }
29
+
10
30
  /**
11
31
  * @public
12
32
  */
@@ -29,11 +49,7 @@ export function verifyMessageDogeEcdsa(
29
49
  btcPublicKeyFromP2pkhAddress(address) ===
30
50
  hexFrom(
31
51
  btcEcdsaPublicKeyHash(
32
- sig
33
- .recoverPublicKey(
34
- magicHash(challenge, "\x19Dogecoin Signed Message:\n"),
35
- )
36
- .toHex(),
52
+ sig.recoverPublicKey(messageHashDogeEcdsa(challenge)).toHex(),
37
53
  ),
38
54
  )
39
55
  );
@@ -96,11 +96,12 @@ export abstract class Signer {
96
96
  ): NetworkPreference | undefined {
97
97
  if (
98
98
  currentNetwork !== undefined &&
99
- preferences.some(({ signerType, addressPrefix, network }) => {
100
- signerType === this.type &&
99
+ preferences.some(
100
+ ({ signerType, addressPrefix, network }) =>
101
+ signerType === this.type &&
101
102
  addressPrefix === this.client.addressPrefix &&
102
- network === currentNetwork;
103
- })
103
+ network === currentNetwork,
104
+ )
104
105
  ) {
105
106
  return;
106
107
  }
@@ -459,14 +460,23 @@ export abstract class Signer {
459
460
  }
460
461
 
461
462
  /**
462
- * prepare a transaction before signing. This method is not implemented and should be overridden by subclasses.
463
+ * Prepares a transaction before signing.
464
+ * This method can be overridden by subclasses to perform any necessary steps,
465
+ * such as adding cell dependencies or witnesses, before the transaction is signed.
466
+ * The default implementation converts the {@link TransactionLike} object to a {@link Transaction} object
467
+ * without modification.
463
468
  *
464
- * @param _ - The transaction to prepare, represented as a TransactionLike object.
465
- * @returns A promise that resolves to the prepared Transaction object.
466
- * @throws Will throw an error if not implemented.
469
+ * @remarks
470
+ * Note that this default implementation does not add any cell dependencies or dummy witnesses.
471
+ * This may lead to an underestimation of transaction size and fees if used with methods
472
+ * like `Transaction.completeFee`. Subclasses for signers that are intended to sign
473
+ * transactions should override this method to perform necessary preparations.
474
+ *
475
+ * @param tx - The transaction to prepare.
476
+ * @returns A promise that resolves to the prepared {@link Transaction} object.
467
477
  */
468
- prepareTransaction(_: TransactionLike): Promise<Transaction> {
469
- throw Error("Signer.prepareTransaction not implemented");
478
+ async prepareTransaction(tx: TransactionLike): Promise<Transaction> {
479
+ return Transaction.from(tx);
470
480
  }
471
481
 
472
482
  /**