@ckb-ccc/core 0.0.4-alpha.1 → 0.0.4-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.
Files changed (104) hide show
  1. package/README.md +12 -7
  2. package/dist/address/address.advanced.d.ts +34 -0
  3. package/dist/address/address.advanced.d.ts.map +1 -1
  4. package/dist/address/address.advanced.js +41 -7
  5. package/dist/address/index.d.ts +36 -0
  6. package/dist/address/index.d.ts.map +1 -1
  7. package/dist/address/index.js +44 -5
  8. package/dist/bytes/advanced.d.ts +3 -0
  9. package/dist/bytes/advanced.d.ts.map +1 -1
  10. package/dist/bytes/index.d.ts +57 -0
  11. package/dist/bytes/index.d.ts.map +1 -1
  12. package/dist/bytes/index.js +57 -0
  13. package/dist/ckb/script.d.ts +98 -1
  14. package/dist/ckb/script.d.ts.map +1 -1
  15. package/dist/ckb/script.js +98 -1
  16. package/dist/ckb/transaction.d.ts +392 -1
  17. package/dist/ckb/transaction.d.ts.map +1 -1
  18. package/dist/ckb/transaction.js +403 -1
  19. package/dist/client/client.d.ts +10 -8
  20. package/dist/client/client.d.ts.map +1 -1
  21. package/dist/client/client.js +18 -0
  22. package/dist/client/clientPublicMainnet.advanced.d.ts +2 -2
  23. package/dist/client/clientPublicMainnet.advanced.d.ts.map +1 -1
  24. package/dist/client/clientPublicMainnet.d.ts +2 -2
  25. package/dist/client/clientPublicMainnet.d.ts.map +1 -1
  26. package/dist/client/clientPublicTestnet.advanced.d.ts +2 -2
  27. package/dist/client/clientPublicTestnet.advanced.d.ts.map +1 -1
  28. package/dist/client/clientPublicTestnet.d.ts +2 -2
  29. package/dist/client/clientPublicTestnet.d.ts.map +1 -1
  30. package/dist/client/clientTypes.d.ts +6 -0
  31. package/dist/client/clientTypes.d.ts.map +1 -1
  32. package/dist/client/jsonRpc/advanced.d.ts +2 -87
  33. package/dist/client/jsonRpc/advanced.d.ts.map +1 -1
  34. package/dist/client/jsonRpc/advanced.js +2 -65
  35. package/dist/client/jsonRpc/index.d.ts +60 -6
  36. package/dist/client/jsonRpc/index.d.ts.map +1 -1
  37. package/dist/client/jsonRpc/index.js +72 -7
  38. package/dist/client/jsonRpc/transformers.d.ts +28 -0
  39. package/dist/client/jsonRpc/transformers.d.ts.map +1 -0
  40. package/dist/client/jsonRpc/transformers.js +122 -0
  41. package/dist/client/jsonRpc/types.d.ts +41 -0
  42. package/dist/client/jsonRpc/types.d.ts.map +1 -0
  43. package/dist/client/jsonRpc/types.js +1 -0
  44. package/dist/fixedPoint/index.d.ts +43 -1
  45. package/dist/fixedPoint/index.d.ts.map +1 -1
  46. package/dist/fixedPoint/index.js +39 -1
  47. package/dist/hasher/index.d.ts +43 -2
  48. package/dist/hasher/index.d.ts.map +1 -1
  49. package/dist/hasher/index.js +42 -0
  50. package/dist/hex/index.d.ts +19 -0
  51. package/dist/hex/index.d.ts.map +1 -1
  52. package/dist/hex/index.js +12 -0
  53. package/dist/num/index.d.ts +99 -0
  54. package/dist/num/index.d.ts.map +1 -1
  55. package/dist/num/index.js +92 -0
  56. package/dist/signer/btc/signerBtc.d.ts +33 -2
  57. package/dist/signer/btc/signerBtc.d.ts.map +1 -1
  58. package/dist/signer/btc/signerBtc.js +25 -3
  59. package/dist/signer/btc/signerBtcPublicKeyReadonly.d.ts +36 -0
  60. package/dist/signer/btc/signerBtcPublicKeyReadonly.d.ts.map +1 -1
  61. package/dist/signer/btc/signerBtcPublicKeyReadonly.js +36 -0
  62. package/dist/signer/ckb/signerCkbScriptReadonly.d.ts +35 -0
  63. package/dist/signer/ckb/signerCkbScriptReadonly.d.ts.map +1 -1
  64. package/dist/signer/ckb/signerCkbScriptReadonly.js +35 -0
  65. package/dist/signer/evm/signerEvm.d.ts +27 -2
  66. package/dist/signer/evm/signerEvm.d.ts.map +1 -1
  67. package/dist/signer/evm/signerEvm.js +24 -3
  68. package/dist/signer/evm/signerEvmAddressReadonly.d.ts +30 -0
  69. package/dist/signer/evm/signerEvmAddressReadonly.d.ts.map +1 -1
  70. package/dist/signer/evm/signerEvmAddressReadonly.js +30 -0
  71. package/dist/signer/helpers.d.ts +19 -1
  72. package/dist/signer/helpers.d.ts.map +1 -1
  73. package/dist/signer/helpers.js +26 -9
  74. package/dist/signer/signer.d.ts +75 -4
  75. package/dist/signer/signer.d.ts.map +1 -1
  76. package/dist/signer/signer.js +53 -0
  77. package/package.json +3 -3
  78. package/src/address/address.advanced.ts +54 -18
  79. package/src/address/index.ts +51 -7
  80. package/src/bytes/advanced.ts +12 -9
  81. package/src/bytes/index.ts +60 -0
  82. package/src/ckb/script.ts +111 -2
  83. package/src/ckb/transaction.ts +455 -2
  84. package/src/client/client.ts +31 -8
  85. package/src/client/clientPublicMainnet.advanced.ts +5 -2
  86. package/src/client/clientPublicMainnet.ts +4 -2
  87. package/src/client/clientPublicTestnet.advanced.ts +5 -2
  88. package/src/client/clientPublicTestnet.ts +4 -2
  89. package/src/client/clientTypes.ts +13 -0
  90. package/src/client/jsonRpc/advanced.ts +2 -93
  91. package/src/client/jsonRpc/index.ts +99 -11
  92. package/src/client/jsonRpc/transformers.ts +159 -0
  93. package/src/client/jsonRpc/types.ts +48 -0
  94. package/src/fixedPoint/index.ts +52 -2
  95. package/src/hasher/index.ts +47 -1
  96. package/src/hex/index.ts +19 -0
  97. package/src/num/index.ts +101 -0
  98. package/src/signer/btc/signerBtc.ts +35 -3
  99. package/src/signer/btc/signerBtcPublicKeyReadonly.ts +36 -0
  100. package/src/signer/ckb/signerCkbScriptReadonly.ts +36 -0
  101. package/src/signer/evm/signerEvm.ts +30 -3
  102. package/src/signer/evm/signerEvmAddressReadonly.ts +31 -0
  103. package/src/signer/helpers.ts +28 -8
  104. package/src/signer/signer.ts +77 -4
@@ -1,5 +1,22 @@
1
+ /**
2
+ * Represents a fixed point value as a bigint.
3
+ */
4
+ /**
5
+ * Converts a FixedPointLike value to its string representation with fixed-point decimals.
6
+ *
7
+ * @param val - The value to convert, which can be a bigint, string, or number.
8
+ * @param decimals - The number of decimal places for the fixed-point representation. Default is 8.
9
+ * @returns A string representing the fixed-point value.
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * const str = fixedPointToString(123456789n, 8); // Outputs "1.23456789"
14
+ * const strFromString = fixedPointToString("123456789", 8); // Outputs "1.23456789"
15
+ * const strFromNumber = fixedPointToString(123456789, 8); // Outputs "1.23456789"
16
+ * ```
17
+ */
1
18
  export function fixedPointToString(val, decimals = 8) {
2
- const str = val.toString();
19
+ const str = fixedPointFrom(val).toString();
3
20
  const l = str.length <= decimals ? "0" : str.slice(0, -decimals);
4
21
  const r = str.slice(-decimals).padStart(decimals, "0").replace(/0*$/, "");
5
22
  if (r === "") {
@@ -7,6 +24,20 @@ export function fixedPointToString(val, decimals = 8) {
7
24
  }
8
25
  return `${l}.${r}`;
9
26
  }
27
+ /**
28
+ * Converts a FixedPointLike value to a FixedPoint (bigint) with fixed-point decimals.
29
+ *
30
+ * @param val - The value to convert, which can be a bigint, string, or number.
31
+ * @param decimals - The number of decimal places for the fixed-point representation. Default is 8.
32
+ * @returns A FixedPoint (bigint) representing the value with fixed-point decimals.
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * const fixedPoint = fixedPointFrom(1.23456789, 8); // Outputs 123456789n
37
+ * const fixedPointFromString = fixedPointFrom("1.23456789", 8); // Outputs 123456789n
38
+ * const fixedPointFromNumber = fixedPointFrom(1.23456789, 8); // Outputs 123456789n
39
+ * ```
40
+ */
10
41
  export function fixedPointFrom(val, decimals = 8) {
11
42
  if (typeof val === "bigint") {
12
43
  return val;
@@ -18,5 +49,12 @@ export function fixedPointFrom(val, decimals = 8) {
18
49
  }
19
50
  return lVal + BigInt(r.slice(0, decimals).padEnd(decimals, "0"));
20
51
  }
52
+ /**
53
+ * Represents the fixed point value of zero as a bigint.
54
+ */
21
55
  export const Zero = 0n;
56
+ /**
57
+ * Represents the fixed point value of one as a FixedPoint (bigint).
58
+ * Equivalent to 1 in fixed-point representation with default decimals (8).
59
+ */
22
60
  export const One = fixedPointFrom("1");
@@ -1,11 +1,52 @@
1
- import { Blake2b } from "blake2b";
2
1
  import { BytesLike } from "../bytes";
3
2
  import { Hex } from "../hex";
4
3
  export declare class Hasher {
5
- hasher: Blake2b;
4
+ private readonly hasher;
5
+ /**
6
+ * Creates an instance of Hasher.
7
+ *
8
+ * @param outLength - The output length of the hash in bytes. Default is 32.
9
+ * @param personal - The personal string for the Blake2b algorithm. Default is CKB_BLAKE2B_PERSONAL.
10
+ */
6
11
  constructor(outLength?: number, personal?: string);
12
+ /**
13
+ * Updates the hash with the given data.
14
+ *
15
+ * @param data - The data to update the hash with.
16
+ * @returns The current Hasher instance for chaining.
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * const hasher = new Hasher();
21
+ * hasher.update("some data").update("more data");
22
+ * const hash = hasher.digest();
23
+ * ```
24
+ */
7
25
  update(data: BytesLike): Hasher;
26
+ /**
27
+ * Finalizes the hash and returns the digest as a hexadecimal string.
28
+ *
29
+ * @returns The hexadecimal string representation of the hash.
30
+ *
31
+ * @example
32
+ * ```typescript
33
+ * const hasher = new Hasher();
34
+ * hasher.update("some data");
35
+ * const hash = hasher.digest(); // Outputs something like "0x..."
36
+ * ```
37
+ */
8
38
  digest(): Hex;
9
39
  }
40
+ /**
41
+ * Computes the CKB hash of the given data using the Blake2b algorithm.
42
+ *
43
+ * @param data - The data to hash.
44
+ * @returns The hexadecimal string representation of the hash.
45
+ *
46
+ * @example
47
+ * ```typescript
48
+ * const hash = ckbHash("some data"); // Outputs something like "0x..."
49
+ * ```
50
+ */
10
51
  export declare function ckbHash(data: BytesLike): Hex;
11
52
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hasher/index.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAa,MAAM,UAAU,CAAC;AAChD,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAG7B,qBAAa,MAAM;IACjB,MAAM,EAAE,OAAO,CAAC;gBAEJ,SAAS,SAAK,EAAE,QAAQ,SAAuB;IAS3D,MAAM,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM;IAK/B,MAAM,IAAI,GAAG;CAGd;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,SAAS,GAAG,GAAG,CAE5C"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hasher/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAa,MAAM,UAAU,CAAC;AAChD,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAG7B,qBAAa,MAAM;IACjB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAU;IAEjC;;;;;OAKG;gBAES,SAAS,SAAK,EAAE,QAAQ,SAAuB;IAS3D;;;;;;;;;;;;OAYG;IAEH,MAAM,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM;IAK/B;;;;;;;;;;;OAWG;IAEH,MAAM,IAAI,GAAG;CAGd;AAED;;;;;;;;;;GAUG;AAEH,wBAAgB,OAAO,CAAC,IAAI,EAAE,SAAS,GAAG,GAAG,CAE5C"}
@@ -2,17 +2,59 @@ import blake2b from "blake2b";
2
2
  import { bytesFrom } from "../bytes";
3
3
  import { CKB_BLAKE2B_PERSONAL } from "./advanced";
4
4
  export class Hasher {
5
+ /**
6
+ * Creates an instance of Hasher.
7
+ *
8
+ * @param outLength - The output length of the hash in bytes. Default is 32.
9
+ * @param personal - The personal string for the Blake2b algorithm. Default is CKB_BLAKE2B_PERSONAL.
10
+ */
5
11
  constructor(outLength = 32, personal = CKB_BLAKE2B_PERSONAL) {
6
12
  this.hasher = blake2b(outLength, undefined, undefined, bytesFrom(personal, "utf8"));
7
13
  }
14
+ /**
15
+ * Updates the hash with the given data.
16
+ *
17
+ * @param data - The data to update the hash with.
18
+ * @returns The current Hasher instance for chaining.
19
+ *
20
+ * @example
21
+ * ```typescript
22
+ * const hasher = new Hasher();
23
+ * hasher.update("some data").update("more data");
24
+ * const hash = hasher.digest();
25
+ * ```
26
+ */
8
27
  update(data) {
9
28
  this.hasher.update(bytesFrom(data));
10
29
  return this;
11
30
  }
31
+ /**
32
+ * Finalizes the hash and returns the digest as a hexadecimal string.
33
+ *
34
+ * @returns The hexadecimal string representation of the hash.
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * const hasher = new Hasher();
39
+ * hasher.update("some data");
40
+ * const hash = hasher.digest(); // Outputs something like "0x..."
41
+ * ```
42
+ */
12
43
  digest() {
13
44
  return `0x${this.hasher.digest("hex")}`;
14
45
  }
15
46
  }
47
+ /**
48
+ * Computes the CKB hash of the given data using the Blake2b algorithm.
49
+ *
50
+ * @param data - The data to hash.
51
+ * @returns The hexadecimal string representation of the hash.
52
+ *
53
+ * @example
54
+ * ```typescript
55
+ * const hash = ckbHash("some data"); // Outputs something like "0x..."
56
+ * ```
57
+ */
16
58
  export function ckbHash(data) {
17
59
  return new Hasher().update(data).digest();
18
60
  }
@@ -1,5 +1,24 @@
1
1
  import { BytesLike } from "../bytes";
2
+ /**
3
+ * Represents a hexadecimal string prefixed with "0x".
4
+ */
2
5
  export type Hex = `0x${string}`;
6
+ /**
7
+ * Represents a value that can be converted to a hexadecimal string.
8
+ * It extends the BytesLike type.
9
+ */
3
10
  export type HexLike = BytesLike;
11
+ /**
12
+ * Converts a HexLike value to a Hex string.
13
+ *
14
+ * @param hex - The value to convert, which can be a string, Uint8Array, ArrayBuffer, or number array.
15
+ * @returns A Hex string representing the value.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * const hexString = hexFrom("68656c6c6f"); // Outputs "0x68656c6c6f"
20
+ * const hexStringFromBytes = hexFrom(new Uint8Array([104, 101, 108, 108, 111])); // Outputs "0x68656c6c6f"
21
+ * ```
22
+ */
4
23
  export declare function hexFrom(hex: HexLike): Hex;
5
24
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hex/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,SAAS,EAAW,MAAM,UAAU,CAAC;AAEzD,MAAM,MAAM,GAAG,GAAG,KAAK,MAAM,EAAE,CAAC;AAChC,MAAM,MAAM,OAAO,GAAG,SAAS,CAAC;AAEhC,wBAAgB,OAAO,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,CAEzC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hex/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,SAAS,EAAW,MAAM,UAAU,CAAC;AAEzD;;GAEG;AACH,MAAM,MAAM,GAAG,GAAG,KAAK,MAAM,EAAE,CAAC;AAChC;;;GAGG;AACH,MAAM,MAAM,OAAO,GAAG,SAAS,CAAC;AAEhC;;;;;;;;;;;GAWG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,CAEzC"}
package/dist/hex/index.js CHANGED
@@ -1,4 +1,16 @@
1
1
  import { bytesFrom, bytesTo } from "../bytes";
2
+ /**
3
+ * Converts a HexLike value to a Hex string.
4
+ *
5
+ * @param hex - The value to convert, which can be a string, Uint8Array, ArrayBuffer, or number array.
6
+ * @returns A Hex string representing the value.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * const hexString = hexFrom("68656c6c6f"); // Outputs "0x68656c6c6f"
11
+ * const hexStringFromBytes = hexFrom(new Uint8Array([104, 101, 108, 108, 111])); // Outputs "0x68656c6c6f"
12
+ * ```
13
+ */
2
14
  export function hexFrom(hex) {
3
15
  return `0x${bytesTo(bytesFrom(hex), "hex")}`;
4
16
  }
@@ -1,13 +1,112 @@
1
1
  import { Bytes, BytesLike } from "../bytes";
2
2
  import { Hex, HexLike } from "../hex";
3
+ /**
4
+ * Represents a numeric value as a bigint.
5
+ */
3
6
  export type Num = bigint;
7
+ /**
8
+ * Represents a value that can be converted to a numeric value.
9
+ * It can be a string, number, bigint, or HexLike.
10
+ */
4
11
  export type NumLike = string | number | bigint | HexLike;
12
+ /**
13
+ * Converts a NumLike value to a Num (bigint).
14
+ *
15
+ * @param val - The value to convert, which can be a string, number, bigint, or HexLike.
16
+ * @returns A Num (bigint) representing the value.
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * const num = numFrom("12345"); // Outputs 12345n
21
+ * const numFromHex = numFrom("0x3039"); // Outputs 12345n
22
+ * ```
23
+ */
5
24
  export declare function numFrom(val: NumLike): Num;
25
+ /**
26
+ * Converts a NumLike value to a hexadecimal string.
27
+ *
28
+ * @param val - The value to convert, which can be a string, number, bigint, or HexLike.
29
+ * @returns A Hex string representing the numeric value.
30
+ *
31
+ * @example
32
+ * ```typescript
33
+ * const hex = numToHex(12345); // Outputs "0x3039"
34
+ * ```
35
+ */
6
36
  export declare function numToHex(val: NumLike): Hex;
37
+ /**
38
+ * Converts a NumLike value to a byte array in little-endian order.
39
+ *
40
+ * @param val - The value to convert, which can be a string, number, bigint, or HexLike.
41
+ * @param bytes - The number of bytes to use for the representation. If not provided, the exact number of bytes needed is used.
42
+ * @returns A Uint8Array containing the byte representation of the numeric value.
43
+ *
44
+ * @example
45
+ * ```typescript
46
+ * const bytes = numToBytes(12345, 4); // Outputs Uint8Array [57, 48, 0, 0]
47
+ * ```
48
+ */
7
49
  export declare function numToBytes(val: NumLike, bytes?: number): Bytes;
50
+ /**
51
+ * Converts a NumLike value to a byte array in little-endian order.
52
+ *
53
+ * @param val - The value to convert, which can be a string, number, bigint, or HexLike.
54
+ * @param bytes - The number of bytes to use for the representation. If not provided, the exact number of bytes needed is used.
55
+ * @returns A Uint8Array containing the byte representation of the numeric value.
56
+ *
57
+ * @example
58
+ * ```typescript
59
+ * const bytes = numLeToBytes(12345, 4); // Outputs Uint8Array [57, 48, 0, 0]
60
+ * ```
61
+ */
8
62
  export declare function numLeToBytes(val: NumLike, bytes?: number): Bytes;
63
+ /**
64
+ * Converts a NumLike value to a byte array in big-endian order.
65
+ *
66
+ * @param val - The value to convert, which can be a string, number, bigint, or HexLike.
67
+ * @param bytes - The number of bytes to use for the representation. If not provided, the exact number of bytes needed is used.
68
+ * @returns A Uint8Array containing the byte representation of the numeric value.
69
+ *
70
+ * @example
71
+ * ```typescript
72
+ * const bytes = numBeToBytes(12345, 4); // Outputs Uint8Array [0, 0, 48, 57]
73
+ * ```
74
+ */
9
75
  export declare function numBeToBytes(val: NumLike, bytes?: number): Bytes;
76
+ /**
77
+ * Converts a byte array to a Num (bigint) assuming little-endian order.
78
+ *
79
+ * @param val - The byte array to convert.
80
+ * @returns A Num (bigint) representing the numeric value.
81
+ *
82
+ * @example
83
+ * ```typescript
84
+ * const num = numFromBytes(new Uint8Array([57, 48, 0, 0])); // Outputs 12345n
85
+ * ```
86
+ */
10
87
  export declare function numFromBytes(val: BytesLike): Num;
88
+ /**
89
+ * Converts a byte array to a Num (bigint) assuming little-endian order.
90
+ *
91
+ * @param val - The byte array to convert.
92
+ * @returns A Num (bigint) representing the numeric value.
93
+ *
94
+ * @example
95
+ * ```typescript
96
+ * const num = numLeFromBytes(new Uint8Array([57, 48, 0, 0])); // Outputs 12345n
97
+ * ```
98
+ */
11
99
  export declare function numLeFromBytes(val: BytesLike): Num;
100
+ /**
101
+ * Converts a byte array to a Num (bigint) assuming big-endian order.
102
+ *
103
+ * @param val - The byte array to convert.
104
+ * @returns A Num (bigint) representing the numeric value.
105
+ *
106
+ * @example
107
+ * ```typescript
108
+ * const num = numBeFromBytes(new Uint8Array([0, 0, 48, 57])); // Outputs 12345n
109
+ * ```
110
+ */
12
111
  export declare function numBeFromBytes(val: BytesLike): Num;
13
112
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/num/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAA0B,MAAM,UAAU,CAAC;AACpE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAW,MAAM,QAAQ,CAAC;AAE/C,MAAM,MAAM,GAAG,GAAG,MAAM,CAAC;AACzB,MAAM,MAAM,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAEzD,wBAAgB,OAAO,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,CAUzC;AAED,wBAAgB,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,CAE1C;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,KAAK,CAE9D;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,KAAK,CAEhE;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,KAAK,CAUhE;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,SAAS,GAAG,GAAG,CAEhD;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,SAAS,GAAG,GAAG,CAElD;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,SAAS,GAAG,GAAG,CAElD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/num/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAA0B,MAAM,UAAU,CAAC;AACpE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAW,MAAM,QAAQ,CAAC;AAE/C;;GAEG;AACH,MAAM,MAAM,GAAG,GAAG,MAAM,CAAC;AAEzB;;;GAGG;AACH,MAAM,MAAM,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAEzD;;;;;;;;;;;GAWG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,CAUzC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,CAE1C;AAED;;;;;;;;;;;GAWG;AAEH,wBAAgB,UAAU,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,KAAK,CAE9D;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,KAAK,CAEhE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,KAAK,CAUhE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,SAAS,GAAG,GAAG,CAEhD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,SAAS,GAAG,GAAG,CAElD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,SAAS,GAAG,GAAG,CAElD"}
package/dist/num/index.js CHANGED
@@ -1,5 +1,17 @@
1
1
  import { bytesConcat, bytesFrom } from "../bytes";
2
2
  import { hexFrom } from "../hex";
3
+ /**
4
+ * Converts a NumLike value to a Num (bigint).
5
+ *
6
+ * @param val - The value to convert, which can be a string, number, bigint, or HexLike.
7
+ * @returns A Num (bigint) representing the value.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * const num = numFrom("12345"); // Outputs 12345n
12
+ * const numFromHex = numFrom("0x3039"); // Outputs 12345n
13
+ * ```
14
+ */
3
15
  export function numFrom(val) {
4
16
  if (typeof val === "bigint") {
5
17
  return val;
@@ -9,15 +21,62 @@ export function numFrom(val) {
9
21
  }
10
22
  return BigInt(hexFrom(val));
11
23
  }
24
+ /**
25
+ * Converts a NumLike value to a hexadecimal string.
26
+ *
27
+ * @param val - The value to convert, which can be a string, number, bigint, or HexLike.
28
+ * @returns A Hex string representing the numeric value.
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * const hex = numToHex(12345); // Outputs "0x3039"
33
+ * ```
34
+ */
12
35
  export function numToHex(val) {
13
36
  return `0x${numFrom(val).toString(16)}`;
14
37
  }
38
+ /**
39
+ * Converts a NumLike value to a byte array in little-endian order.
40
+ *
41
+ * @param val - The value to convert, which can be a string, number, bigint, or HexLike.
42
+ * @param bytes - The number of bytes to use for the representation. If not provided, the exact number of bytes needed is used.
43
+ * @returns A Uint8Array containing the byte representation of the numeric value.
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * const bytes = numToBytes(12345, 4); // Outputs Uint8Array [57, 48, 0, 0]
48
+ * ```
49
+ */
15
50
  export function numToBytes(val, bytes) {
16
51
  return numLeToBytes(val, bytes);
17
52
  }
53
+ /**
54
+ * Converts a NumLike value to a byte array in little-endian order.
55
+ *
56
+ * @param val - The value to convert, which can be a string, number, bigint, or HexLike.
57
+ * @param bytes - The number of bytes to use for the representation. If not provided, the exact number of bytes needed is used.
58
+ * @returns A Uint8Array containing the byte representation of the numeric value.
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * const bytes = numLeToBytes(12345, 4); // Outputs Uint8Array [57, 48, 0, 0]
63
+ * ```
64
+ */
18
65
  export function numLeToBytes(val, bytes) {
19
66
  return numBeToBytes(val, bytes).reverse();
20
67
  }
68
+ /**
69
+ * Converts a NumLike value to a byte array in big-endian order.
70
+ *
71
+ * @param val - The value to convert, which can be a string, number, bigint, or HexLike.
72
+ * @param bytes - The number of bytes to use for the representation. If not provided, the exact number of bytes needed is used.
73
+ * @returns A Uint8Array containing the byte representation of the numeric value.
74
+ *
75
+ * @example
76
+ * ```typescript
77
+ * const bytes = numBeToBytes(12345, 4); // Outputs Uint8Array [0, 0, 48, 57]
78
+ * ```
79
+ */
21
80
  export function numBeToBytes(val, bytes) {
22
81
  const rawBytes = bytesFrom(numFrom(val).toString(16));
23
82
  if (bytes == null) {
@@ -25,12 +84,45 @@ export function numBeToBytes(val, bytes) {
25
84
  }
26
85
  return bytesConcat(Array.from(Array(bytes - rawBytes.length), () => 0), rawBytes);
27
86
  }
87
+ /**
88
+ * Converts a byte array to a Num (bigint) assuming little-endian order.
89
+ *
90
+ * @param val - The byte array to convert.
91
+ * @returns A Num (bigint) representing the numeric value.
92
+ *
93
+ * @example
94
+ * ```typescript
95
+ * const num = numFromBytes(new Uint8Array([57, 48, 0, 0])); // Outputs 12345n
96
+ * ```
97
+ */
28
98
  export function numFromBytes(val) {
29
99
  return numLeFromBytes(val);
30
100
  }
101
+ /**
102
+ * Converts a byte array to a Num (bigint) assuming little-endian order.
103
+ *
104
+ * @param val - The byte array to convert.
105
+ * @returns A Num (bigint) representing the numeric value.
106
+ *
107
+ * @example
108
+ * ```typescript
109
+ * const num = numLeFromBytes(new Uint8Array([57, 48, 0, 0])); // Outputs 12345n
110
+ * ```
111
+ */
31
112
  export function numLeFromBytes(val) {
32
113
  return numBeFromBytes(bytesFrom(val).reverse());
33
114
  }
115
+ /**
116
+ * Converts a byte array to a Num (bigint) assuming big-endian order.
117
+ *
118
+ * @param val - The byte array to convert.
119
+ * @returns A Num (bigint) representing the numeric value.
120
+ *
121
+ * @example
122
+ * ```typescript
123
+ * const num = numBeFromBytes(new Uint8Array([0, 0, 48, 57])); // Outputs 12345n
124
+ * ```
125
+ */
34
126
  export function numBeFromBytes(val) {
35
127
  return numFrom(bytesFrom(val));
36
128
  }
@@ -1,12 +1,43 @@
1
1
  import { Address } from "../../address";
2
- import { Transaction } from "../../ckb";
2
+ import { Transaction, TransactionLike } from "../../ckb";
3
3
  import { HexLike } from "../../hex";
4
4
  import { Signer } from "../signer";
5
+ /**
6
+ * An abstract class extending the Signer class for Bitcoin-like signing operations.
7
+ * This class provides methods to get Bitcoin account, public key, and internal address,
8
+ * as well as signing transactions.
9
+ */
5
10
  export declare abstract class SignerBtc extends Signer {
11
+ /**
12
+ * Gets the Bitcoin account associated with the signer.
13
+ *
14
+ * @returns A promise that resolves to a string representing the Bitcoin account.
15
+ */
6
16
  abstract getBtcAccount(): Promise<string>;
17
+ /**
18
+ * Gets the Bitcoin public key associated with the signer.
19
+ *
20
+ * @returns A promise that resolves to a HexLike value representing the Bitcoin public key.
21
+ */
7
22
  abstract getBtcPublicKey(): Promise<HexLike>;
23
+ /**
24
+ * Gets the internal address, which is the Bitcoin account in this case.
25
+ *
26
+ * @returns A promise that resolves to a string representing the internal address.
27
+ */
8
28
  getInternalAddress(): Promise<string>;
29
+ /**
30
+ * Gets an array of Address objects representing the known script addresses for the signer.
31
+ *
32
+ * @returns A promise that resolves to an array of Address objects.
33
+ */
9
34
  getAddressObjs(): Promise<Address[]>;
10
- signOnlyTransaction(tx: Transaction): Promise<Transaction>;
35
+ /**
36
+ * Signs a transaction without modifying it.
37
+ *
38
+ * @param txLike - The transaction to sign, represented as a TransactionLike object.
39
+ * @returns A promise that resolves to a signed Transaction object.
40
+ */
41
+ signOnlyTransaction(txLike: TransactionLike): Promise<Transaction>;
11
42
  }
12
43
  //# sourceMappingURL=signerBtc.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"signerBtc.d.ts","sourceRoot":"","sources":["../../../src/signer/btc/signerBtc.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC,OAAO,EAAE,WAAW,EAAe,MAAM,WAAW,CAAC;AAErD,OAAO,EAAE,OAAO,EAAW,MAAM,WAAW,CAAC;AAG7C,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,8BAAsB,SAAU,SAAQ,MAAM;IAC5C,QAAQ,CAAC,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAEzC,QAAQ,CAAC,eAAe,IAAI,OAAO,CAAC,OAAO,CAAC;IAEtC,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAIrC,cAAc,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IAapC,mBAAmB,CAAC,EAAE,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;CA+BjE"}
1
+ {"version":3,"file":"signerBtc.d.ts","sourceRoot":"","sources":["../../../src/signer/btc/signerBtc.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC,OAAO,EAAE,WAAW,EAAE,eAAe,EAAe,MAAM,WAAW,CAAC;AAEtE,OAAO,EAAE,OAAO,EAAW,MAAM,WAAW,CAAC;AAG7C,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC;;;;GAIG;AACH,8BAAsB,SAAU,SAAQ,MAAM;IAC5C;;;;OAIG;IACH,QAAQ,CAAC,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAEzC;;;;OAIG;IACH,QAAQ,CAAC,eAAe,IAAI,OAAO,CAAC,OAAO,CAAC;IAE5C;;;;OAIG;IACG,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAI3C;;;;OAIG;IACG,cAAc,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IAa1C;;;;;OAKG;IACG,mBAAmB,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC;CAgCzE"}
@@ -2,16 +2,31 @@ import { ripemd160 } from "@noble/hashes/ripemd160";
2
2
  import { sha256 } from "@noble/hashes/sha256";
3
3
  import { Address } from "../../address";
4
4
  import { bytesConcat, bytesFrom } from "../../bytes";
5
- import { WitnessArgs } from "../../ckb";
5
+ import { Transaction, WitnessArgs } from "../../ckb";
6
6
  import { KnownScript } from "../../client";
7
7
  import { hexFrom } from "../../hex";
8
8
  import { numToBytes } from "../../num";
9
9
  import { getSignHashInfo } from "../helpers";
10
10
  import { Signer } from "../signer";
11
+ /**
12
+ * An abstract class extending the Signer class for Bitcoin-like signing operations.
13
+ * This class provides methods to get Bitcoin account, public key, and internal address,
14
+ * as well as signing transactions.
15
+ */
11
16
  export class SignerBtc extends Signer {
17
+ /**
18
+ * Gets the internal address, which is the Bitcoin account in this case.
19
+ *
20
+ * @returns A promise that resolves to a string representing the internal address.
21
+ */
12
22
  async getInternalAddress() {
13
23
  return this.getBtcAccount();
14
24
  }
25
+ /**
26
+ * Gets an array of Address objects representing the known script addresses for the signer.
27
+ *
28
+ * @returns A promise that resolves to an array of Address objects.
29
+ */
15
30
  async getAddressObjs() {
16
31
  const publicKey = await this.getBtcPublicKey();
17
32
  const hash = ripemd160(sha256(bytesFrom(publicKey)));
@@ -19,9 +34,16 @@ export class SignerBtc extends Signer {
19
34
  await Address.fromKnownScript(KnownScript.OmniLock, hexFrom([0x04, ...hash, 0x00]), this.client),
20
35
  ];
21
36
  }
22
- async signOnlyTransaction(tx) {
37
+ /**
38
+ * Signs a transaction without modifying it.
39
+ *
40
+ * @param txLike - The transaction to sign, represented as a TransactionLike object.
41
+ * @returns A promise that resolves to a signed Transaction object.
42
+ */
43
+ async signOnlyTransaction(txLike) {
44
+ const tx = Transaction.from(txLike);
23
45
  const { script } = await this.getRecommendedAddressObj();
24
- const info = await getSignHashInfo(tx, script);
46
+ const info = await getSignHashInfo(tx, script, this.client);
25
47
  if (!info) {
26
48
  return tx;
27
49
  }
@@ -1,12 +1,48 @@
1
1
  import { Client } from "../../client";
2
2
  import { Hex, HexLike } from "../../hex";
3
3
  import { SignerBtc } from "./signerBtc";
4
+ /**
5
+ * A class extending SignerBtc that provides read-only access to a Bitcoin public key and account.
6
+ * This class does not support signing operations.
7
+ */
4
8
  export declare class SignerBtcPublicKeyReadonly extends SignerBtc {
5
9
  private readonly account;
6
10
  private readonly publicKey;
11
+ /**
12
+ * Creates an instance of SignerBtcPublicKeyReadonly.
13
+ *
14
+ * @param client - The client instance used for communication.
15
+ * @param account - The Bitcoin account associated with the signer.
16
+ * @param publicKey - The public key associated with the signer.
17
+ */
7
18
  constructor(client: Client, account: string, publicKey: HexLike);
19
+ /**
20
+ * Connects to the client. This implementation does nothing as the class is read-only.
21
+ *
22
+ * @returns A promise that resolves when the connection is complete.
23
+ */
8
24
  connect(): Promise<void>;
25
+ /**
26
+ * Gets the Bitcoin account associated with the signer.
27
+ *
28
+ * @returns A promise that resolves to a string representing the Bitcoin account.
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * const account = await signer.getBtcAccount(); // Outputs the Bitcoin account
33
+ * ```
34
+ */
9
35
  getBtcAccount(): Promise<string>;
36
+ /**
37
+ * Gets the Bitcoin public key associated with the signer.
38
+ *
39
+ * @returns A promise that resolves to a Hex string representing the Bitcoin public key.
40
+ *
41
+ * @example
42
+ * ```typescript
43
+ * const publicKey = await signer.getBtcPublicKey(); // Outputs the Bitcoin public key
44
+ * ```
45
+ */
10
46
  getBtcPublicKey(): Promise<Hex>;
11
47
  }
12
48
  //# sourceMappingURL=signerBtcPublicKeyReadonly.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"signerBtcPublicKeyReadonly.d.ts","sourceRoot":"","sources":["../../../src/signer/btc/signerBtcPublicKeyReadonly.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,GAAG,EAAE,OAAO,EAAW,MAAM,WAAW,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,qBAAa,0BAA2B,SAAQ,SAAS;IAKrD,OAAO,CAAC,QAAQ,CAAC,OAAO;IAJ1B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAM;gBAG9B,MAAM,EAAE,MAAM,EACG,OAAO,EAAE,MAAM,EAChC,SAAS,EAAE,OAAO;IAOd,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAExB,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAIhC,eAAe,IAAI,OAAO,CAAC,GAAG,CAAC;CAGtC"}
1
+ {"version":3,"file":"signerBtcPublicKeyReadonly.d.ts","sourceRoot":"","sources":["../../../src/signer/btc/signerBtcPublicKeyReadonly.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,GAAG,EAAE,OAAO,EAAW,MAAM,WAAW,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC;;;GAGG;AACH,qBAAa,0BAA2B,SAAQ,SAAS;IAYrD,OAAO,CAAC,QAAQ,CAAC,OAAO;IAX1B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAM;IAEhC;;;;;;OAMG;gBAED,MAAM,EAAE,MAAM,EACG,OAAO,EAAE,MAAM,EAChC,SAAS,EAAE,OAAO;IAOpB;;;;OAIG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAE9B;;;;;;;;;OASG;IACG,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAItC;;;;;;;;;OASG;IACG,eAAe,IAAI,OAAO,CAAC,GAAG,CAAC;CAGtC"}