@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,15 +1,51 @@
1
1
  import { hexFrom } from "../../hex";
2
2
  import { SignerBtc } from "./signerBtc";
3
+ /**
4
+ * A class extending SignerBtc that provides read-only access to a Bitcoin public key and account.
5
+ * This class does not support signing operations.
6
+ */
3
7
  export class SignerBtcPublicKeyReadonly extends SignerBtc {
8
+ /**
9
+ * Creates an instance of SignerBtcPublicKeyReadonly.
10
+ *
11
+ * @param client - The client instance used for communication.
12
+ * @param account - The Bitcoin account associated with the signer.
13
+ * @param publicKey - The public key associated with the signer.
14
+ */
4
15
  constructor(client, account, publicKey) {
5
16
  super(client);
6
17
  this.account = account;
7
18
  this.publicKey = hexFrom(publicKey);
8
19
  }
20
+ /**
21
+ * Connects to the client. This implementation does nothing as the class is read-only.
22
+ *
23
+ * @returns A promise that resolves when the connection is complete.
24
+ */
9
25
  async connect() { }
26
+ /**
27
+ * Gets the Bitcoin account associated with the signer.
28
+ *
29
+ * @returns A promise that resolves to a string representing the Bitcoin account.
30
+ *
31
+ * @example
32
+ * ```typescript
33
+ * const account = await signer.getBtcAccount(); // Outputs the Bitcoin account
34
+ * ```
35
+ */
10
36
  async getBtcAccount() {
11
37
  return this.account;
12
38
  }
39
+ /**
40
+ * Gets the Bitcoin public key associated with the signer.
41
+ *
42
+ * @returns A promise that resolves to a Hex string representing the Bitcoin public key.
43
+ *
44
+ * @example
45
+ * ```typescript
46
+ * const publicKey = await signer.getBtcPublicKey(); // Outputs the Bitcoin public key
47
+ * ```
48
+ */
13
49
  async getBtcPublicKey() {
14
50
  return this.publicKey;
15
51
  }
@@ -2,11 +2,46 @@ import { Address } from "../../address";
2
2
  import { ScriptLike } from "../../ckb";
3
3
  import { Client } from "../../client";
4
4
  import { Signer } from "../signer";
5
+ /**
6
+ * A class extending Signer that provides read-only access to a CKB script.
7
+ * This class does not support signing operations.
8
+ */
5
9
  export declare class SignerCkbScriptReadonly extends Signer {
6
10
  private readonly script;
11
+ /**
12
+ * Creates an instance of SignerCkbScriptReadonly.
13
+ *
14
+ * @param client - The client instance used for communication.
15
+ * @param script - The script associated with the signer.
16
+ */
7
17
  constructor(client: Client, script: ScriptLike);
18
+ /**
19
+ * Connects to the client. This implementation does nothing as the class is read-only.
20
+ *
21
+ * @returns A promise that resolves when the connection is complete.
22
+ */
8
23
  connect(): Promise<void>;
24
+ /**
25
+ * Gets the internal address for the script.
26
+ *
27
+ * @returns A promise that resolves to a string representing the internal address.
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * const internalAddress = await signer.getInternalAddress(); // Outputs the internal address
32
+ * ```
33
+ */
9
34
  getInternalAddress(): Promise<string>;
35
+ /**
36
+ * Gets an array of Address objects representing the script address.
37
+ *
38
+ * @returns A promise that resolves to an array of Address objects.
39
+ *
40
+ * @example
41
+ * ```typescript
42
+ * const addressObjs = await signer.getAddressObjs(); // Outputs the array of Address objects
43
+ * ```
44
+ */
10
45
  getAddressObjs(): Promise<Address[]>;
11
46
  }
12
47
  //# sourceMappingURL=signerCkbScriptReadonly.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"signerCkbScriptReadonly.d.ts","sourceRoot":"","sources":["../../../src/signer/ckb/signerCkbScriptReadonly.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAU,UAAU,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,qBAAa,uBAAwB,SAAQ,MAAM;IACjD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;gBAEpB,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU;IAMxC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAExB,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAIrC,cAAc,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;CAG3C"}
1
+ {"version":3,"file":"signerCkbScriptReadonly.d.ts","sourceRoot":"","sources":["../../../src/signer/ckb/signerCkbScriptReadonly.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAU,UAAU,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC;;;GAGG;AACH,qBAAa,uBAAwB,SAAQ,MAAM;IACjD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAEhC;;;;;OAKG;gBACS,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU;IAM9C;;;;OAIG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAE9B;;;;;;;;;OASG;IACG,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAI3C;;;;;;;;;OASG;IAEG,cAAc,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;CAG3C"}
@@ -1,15 +1,50 @@
1
1
  import { Address } from "../../address";
2
2
  import { Script } from "../../ckb";
3
3
  import { Signer } from "../signer";
4
+ /**
5
+ * A class extending Signer that provides read-only access to a CKB script.
6
+ * This class does not support signing operations.
7
+ */
4
8
  export class SignerCkbScriptReadonly extends Signer {
9
+ /**
10
+ * Creates an instance of SignerCkbScriptReadonly.
11
+ *
12
+ * @param client - The client instance used for communication.
13
+ * @param script - The script associated with the signer.
14
+ */
5
15
  constructor(client, script) {
6
16
  super(client);
7
17
  this.script = Script.from(script);
8
18
  }
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
+ */
9
24
  async connect() { }
25
+ /**
26
+ * Gets the internal address for the script.
27
+ *
28
+ * @returns A promise that resolves to a string representing the internal address.
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * const internalAddress = await signer.getInternalAddress(); // Outputs the internal address
33
+ * ```
34
+ */
10
35
  async getInternalAddress() {
11
36
  return this.getRecommendedAddress();
12
37
  }
38
+ /**
39
+ * Gets an array of Address objects representing the script address.
40
+ *
41
+ * @returns A promise that resolves to an array of Address objects.
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * const addressObjs = await signer.getAddressObjs(); // Outputs the array of Address objects
46
+ * ```
47
+ */
13
48
  async getAddressObjs() {
14
49
  return [await Address.fromScript(this.script, this.client)];
15
50
  }
@@ -1,10 +1,35 @@
1
1
  import { Address } from "../../address";
2
- import { Transaction } from "../../ckb";
2
+ import { Transaction, TransactionLike } from "../../ckb";
3
3
  import { Signer } from "../signer";
4
+ /**
5
+ * An abstract class extending Signer for Ethereum Virtual Machine (EVM) based signing operations.
6
+ * This class provides methods to get EVM account, internal address, and signing transactions.
7
+ */
4
8
  export declare abstract class SignerEvm extends Signer {
9
+ /**
10
+ * Gets the EVM account associated with the signer.
11
+ *
12
+ * @returns A promise that resolves to a string representing the EVM account.
13
+ */
5
14
  abstract getEvmAccount(): Promise<string>;
15
+ /**
16
+ * Gets the internal address, which is the EVM account in this case.
17
+ *
18
+ * @returns A promise that resolves to a string representing the internal address.
19
+ */
6
20
  getInternalAddress(): Promise<string>;
21
+ /**
22
+ * Gets an array of Address objects representing the known script addresses for the signer.
23
+ *
24
+ * @returns A promise that resolves to an array of Address objects.
25
+ */
7
26
  getAddressObjs(): Promise<Address[]>;
8
- signOnlyTransaction(tx: Transaction): Promise<Transaction>;
27
+ /**
28
+ * Signs a transaction without modifying it.
29
+ *
30
+ * @param txLike - The transaction to sign, represented as a TransactionLike object.
31
+ * @returns A promise that resolves to a signed Transaction object.
32
+ */
33
+ signOnlyTransaction(txLike: TransactionLike): Promise<Transaction>;
9
34
  }
10
35
  //# sourceMappingURL=signerEvm.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"signerEvm.d.ts","sourceRoot":"","sources":["../../../src/signer/evm/signerEvm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC,OAAO,EAAE,WAAW,EAAe,MAAM,WAAW,CAAC;AAKrD,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,8BAAsB,SAAU,SAAQ,MAAM;IAC5C,QAAQ,CAAC,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAEnC,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAIrC,cAAc,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IAWpC,mBAAmB,CAAC,EAAE,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;CA8BjE"}
1
+ {"version":3,"file":"signerEvm.d.ts","sourceRoot":"","sources":["../../../src/signer/evm/signerEvm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC,OAAO,EAAE,WAAW,EAAE,eAAe,EAAe,MAAM,WAAW,CAAC;AAKtE,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC;;;GAGG;AACH,8BAAsB,SAAU,SAAQ,MAAM;IAC5C;;;;OAIG;IACH,QAAQ,CAAC,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAEzC;;;;OAIG;IACG,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAI3C;;;;OAIG;IACG,cAAc,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IAW1C;;;;;OAKG;IACG,mBAAmB,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC;CAgCzE"}
@@ -1,24 +1,45 @@
1
1
  import { Address } from "../../address";
2
2
  import { bytesConcat, bytesFrom } from "../../bytes";
3
- import { WitnessArgs } from "../../ckb";
3
+ import { Transaction, WitnessArgs } from "../../ckb";
4
4
  import { KnownScript } from "../../client";
5
5
  import { hexFrom } from "../../hex";
6
6
  import { numToBytes } from "../../num";
7
7
  import { getSignHashInfo } from "../helpers";
8
8
  import { Signer } from "../signer";
9
+ /**
10
+ * An abstract class extending Signer for Ethereum Virtual Machine (EVM) based signing operations.
11
+ * This class provides methods to get EVM account, internal address, and signing transactions.
12
+ */
9
13
  export class SignerEvm extends Signer {
14
+ /**
15
+ * Gets the internal address, which is the EVM account in this case.
16
+ *
17
+ * @returns A promise that resolves to a string representing the internal address.
18
+ */
10
19
  async getInternalAddress() {
11
20
  return this.getEvmAccount();
12
21
  }
22
+ /**
23
+ * Gets an array of Address objects representing the known script addresses for the signer.
24
+ *
25
+ * @returns A promise that resolves to an array of Address objects.
26
+ */
13
27
  async getAddressObjs() {
14
28
  const account = await this.getEvmAccount();
15
29
  return [
16
30
  await Address.fromKnownScript(KnownScript.OmniLock, hexFrom([0x12, ...bytesFrom(account), 0x00]), this.client),
17
31
  ];
18
32
  }
19
- async signOnlyTransaction(tx) {
33
+ /**
34
+ * Signs a transaction without modifying it.
35
+ *
36
+ * @param txLike - The transaction to sign, represented as a TransactionLike object.
37
+ * @returns A promise that resolves to a signed Transaction object.
38
+ */
39
+ async signOnlyTransaction(txLike) {
40
+ const tx = Transaction.from(txLike);
20
41
  const { script } = await this.getRecommendedAddressObj();
21
- const info = await getSignHashInfo(tx, script);
42
+ const info = await getSignHashInfo(tx, script, this.client);
22
43
  if (!info) {
23
44
  return tx;
24
45
  }
@@ -1,10 +1,40 @@
1
1
  import { Client } from "../../client";
2
2
  import { HexLike } from "../../hex";
3
3
  import { SignerEvm } from "./signerEvm";
4
+ /**
5
+ * A class extending SignerEvm that provides read-only access to an EVM address.
6
+ * This class does not support signing operations.
7
+ */
4
8
  export declare abstract class SignerEvmAddressReadonly extends SignerEvm {
5
9
  private readonly address;
10
+ /**
11
+ * Creates an instance of SignerEvmAddressReadonly.
12
+ *
13
+ * @param client - The client instance used for communication.
14
+ * @param address - The EVM address associated with the signer.
15
+ */
6
16
  constructor(client: Client, address: HexLike);
17
+ /**
18
+ * Connects to the client. This implementation does nothing as the class is read-only.
19
+ *
20
+ * @returns A promise that resolves when the connection is complete.
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * await signer.connect();
25
+ * ```
26
+ */
7
27
  connect(): Promise<void>;
28
+ /**
29
+ * Gets the EVM account associated with the signer.
30
+ *
31
+ * @returns A promise that resolves to a string representing the EVM account.
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * const account = await signer.getEvmAccount(); // Outputs the EVM account
36
+ * ```
37
+ */
8
38
  getEvmAccount(): Promise<string>;
9
39
  }
10
40
  //# sourceMappingURL=signerEvmAddressReadonly.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"signerEvmAddressReadonly.d.ts","sourceRoot":"","sources":["../../../src/signer/evm/signerEvmAddressReadonly.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAO,OAAO,EAAW,MAAM,WAAW,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,8BAAsB,wBAAyB,SAAQ,SAAS;IAC9D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAM;gBAElB,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO;IAMtC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAExB,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;CAGvC"}
1
+ {"version":3,"file":"signerEvmAddressReadonly.d.ts","sourceRoot":"","sources":["../../../src/signer/evm/signerEvmAddressReadonly.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAO,OAAO,EAAW,MAAM,WAAW,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC;;;GAGG;AACH,8BAAsB,wBAAyB,SAAQ,SAAS;IAC9D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAM;IAE9B;;;;;OAKG;gBACS,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO;IAM5C;;;;;;;;;OASG;IAEG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAE9B;;;;;;;;;OASG;IACG,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;CAGvC"}
@@ -1,11 +1,41 @@
1
1
  import { hexFrom } from "../../hex";
2
2
  import { SignerEvm } from "./signerEvm";
3
+ /**
4
+ * A class extending SignerEvm that provides read-only access to an EVM address.
5
+ * This class does not support signing operations.
6
+ */
3
7
  export class SignerEvmAddressReadonly extends SignerEvm {
8
+ /**
9
+ * Creates an instance of SignerEvmAddressReadonly.
10
+ *
11
+ * @param client - The client instance used for communication.
12
+ * @param address - The EVM address associated with the signer.
13
+ */
4
14
  constructor(client, address) {
5
15
  super(client);
6
16
  this.address = hexFrom(address);
7
17
  }
18
+ /**
19
+ * Connects to the client. This implementation does nothing as the class is read-only.
20
+ *
21
+ * @returns A promise that resolves when the connection is complete.
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * await signer.connect();
26
+ * ```
27
+ */
8
28
  async connect() { }
29
+ /**
30
+ * Gets the EVM account associated with the signer.
31
+ *
32
+ * @returns A promise that resolves to a string representing the EVM account.
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * const account = await signer.getEvmAccount(); // Outputs the EVM account
37
+ * ```
38
+ */
9
39
  async getEvmAccount() {
10
40
  return this.address;
11
41
  }
@@ -1,6 +1,24 @@
1
1
  import { ScriptLike, TransactionLike } from "../ckb";
2
+ import { Client } from "../client";
2
3
  import { Hex } from "../hex";
3
- export declare function getSignHashInfo(txLike: TransactionLike, scriptLike: ScriptLike): Promise<{
4
+ /**
5
+ * Computes the signing hash information for a given transaction and script.
6
+ *
7
+ * @param txLike - The transaction to sign, represented as a TransactionLike object.
8
+ * @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
9
+ * @returns A promise that resolves to an object containing the signing message and the witness position,
10
+ * or undefined if no matching input is found.
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * const signHashInfo = await getSignHashInfo(transactionLike, scriptLike);
15
+ * if (signHashInfo) {
16
+ * console.log(signHashInfo.message); // Outputs the signing message
17
+ * console.log(signHashInfo.position); // Outputs the witness position
18
+ * }
19
+ * ```
20
+ */
21
+ export declare function getSignHashInfo(txLike: TransactionLike, scriptLike: ScriptLike, client: Client): Promise<{
4
22
  message: Hex;
5
23
  position: number;
6
24
  } | undefined>;
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/signer/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,UAAU,EAAe,eAAe,EAAE,MAAM,QAAQ,CAAC;AAE1E,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAE7B,wBAAsB,eAAe,CACnC,MAAM,EAAE,eAAe,EACvB,UAAU,EAAE,UAAU,GACrB,OAAO,CAAC;IAAE,OAAO,EAAE,GAAG,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAAC,CAsCzD"}
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/signer/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,UAAU,EAAe,eAAe,EAAE,MAAM,QAAQ,CAAC;AAC1E,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAE7B;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,eAAe,EACvB,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC;IAAE,OAAO,EAAE,GAAG,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAAC,CAuCzD"}
@@ -1,18 +1,35 @@
1
1
  import { Script, Transaction } from "../ckb";
2
2
  import { Hasher } from "../hasher";
3
- export async function getSignHashInfo(txLike, scriptLike) {
3
+ /**
4
+ * Computes the signing hash information for a given transaction and script.
5
+ *
6
+ * @param txLike - The transaction to sign, represented as a TransactionLike object.
7
+ * @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
8
+ * @returns A promise that resolves to an object containing the signing message and the witness position,
9
+ * or undefined if no matching input is found.
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * const signHashInfo = await getSignHashInfo(transactionLike, scriptLike);
14
+ * if (signHashInfo) {
15
+ * console.log(signHashInfo.message); // Outputs the signing message
16
+ * console.log(signHashInfo.position); // Outputs the witness position
17
+ * }
18
+ * ```
19
+ */
20
+ export async function getSignHashInfo(txLike, scriptLike, client) {
4
21
  const tx = Transaction.from(txLike);
5
22
  const script = Script.from(scriptLike);
6
23
  let position = -1;
7
24
  const hasher = new Hasher();
8
25
  hasher.update(tx.hash());
9
- tx.witnesses.forEach((witness, i) => {
10
- const input = tx.inputs[i];
11
- if (input) {
12
- if (!input.cellOutput?.lock) {
13
- throw Error("Incomplete inputs info");
26
+ for (let i = 0; i < tx.witnesses.length; i += 1) {
27
+ if (tx.inputs[i]) {
28
+ const input = await tx.inputs[i].completeExtraInfos(client);
29
+ if (!input.cellOutput) {
30
+ throw Error("Unable to resolve inputs info");
14
31
  }
15
- if (!script.eq(input.cellOutput?.lock)) {
32
+ if (!script.eq(input.cellOutput.lock)) {
16
33
  return;
17
34
  }
18
35
  if (position === -1) {
@@ -22,8 +39,8 @@ export async function getSignHashInfo(txLike, scriptLike) {
22
39
  if (position === -1) {
23
40
  return undefined;
24
41
  }
25
- Transaction.hashWitnessToHasher(witness, hasher);
26
- });
42
+ Transaction.hashWitnessToHasher(tx.witnesses[i], hasher);
43
+ }
27
44
  if (position === -1) {
28
45
  return undefined;
29
46
  }
@@ -1,31 +1,102 @@
1
1
  import { Address } from "../address";
2
2
  import { BytesLike } from "../bytes";
3
- import { Transaction } from "../ckb";
3
+ import { Transaction, TransactionLike } from "../ckb";
4
4
  import { Client } from "../client";
5
5
  import { Hex } from "../hex";
6
+ /**
7
+ * An abstract class representing a generic signer.
8
+ * This class provides methods to connect, get addresses, and sign transactions.
9
+ */
6
10
  export declare abstract class Signer {
7
11
  readonly client: Client;
8
12
  constructor(client: Client);
13
+ /**
14
+ * Connects to the client.
15
+ *
16
+ * @returns A promise that resolves when the connection is complete.
17
+ */
9
18
  abstract connect(): Promise<void>;
19
+ /**
20
+ * Gets the internal address associated with the signer.
21
+ *
22
+ * @returns A promise that resolves to a string representing the internal address.
23
+ */
10
24
  abstract getInternalAddress(): Promise<string>;
25
+ /**
26
+ * Gets an array of Address objects associated with the signer.
27
+ *
28
+ * @returns A promise that resolves to an array of Address objects.
29
+ */
11
30
  abstract getAddressObjs(): Promise<Address[]>;
31
+ /**
32
+ * Gets the recommended Address object for the signer.
33
+ *
34
+ * @param _preference - Optional preference parameter.
35
+ * @returns A promise that resolves to the recommended Address object.
36
+ */
12
37
  getRecommendedAddressObj(_preference?: unknown): Promise<Address>;
38
+ /**
39
+ * Gets the recommended address for the signer as a string.
40
+ *
41
+ * @param preference - Optional preference parameter.
42
+ * @returns A promise that resolves to the recommended address as a string.
43
+ */
13
44
  getRecommendedAddress(preference?: unknown): Promise<string>;
45
+ /**
46
+ * Gets an array of addresses associated with the signer as strings.
47
+ *
48
+ * @returns A promise that resolves to an array of addresses as strings.
49
+ */
14
50
  getAddresses(): Promise<string[]>;
51
+ /**
52
+ * Signs a message. This method is not implemented and should be overridden by subclasses.
53
+ *
54
+ * @param _ - The message to sign, as a string or BytesLike object.
55
+ * @returns A promise that resolves to the signed message as a string.
56
+ * @throws Will throw an error if not implemented.
57
+ */
15
58
  signMessage(_: string | BytesLike): Promise<string>;
16
- sendTransaction(tx: Transaction): Promise<Hex>;
17
- signTransaction(tx: Transaction): Promise<Transaction>;
18
- signOnlyTransaction(_: Transaction): Promise<Transaction>;
59
+ /**
60
+ * Sends a transaction after signing it.
61
+ *
62
+ * @param tx - The transaction to send, represented as a TransactionLike object.
63
+ * @returns A promise that resolves to the transaction hash as a Hex string.
64
+ */
65
+ sendTransaction(tx: TransactionLike): Promise<Hex>;
66
+ /**
67
+ * Signs a transaction.
68
+ *
69
+ * @param tx - The transaction to sign, represented as a TransactionLike object.
70
+ * @returns A promise that resolves to the signed Transaction object.
71
+ */
72
+ signTransaction(tx: TransactionLike): Promise<Transaction>;
73
+ /**
74
+ * Signs a transaction without sending it. This method is not implemented and should be overridden by subclasses.
75
+ *
76
+ * @param _ - The transaction to sign, represented as a TransactionLike object.
77
+ * @returns A promise that resolves to the signed Transaction object.
78
+ * @throws Will throw an error if not implemented.
79
+ */
80
+ signOnlyTransaction(_: TransactionLike): Promise<Transaction>;
19
81
  }
82
+ /**
83
+ * An enumeration of signer types.
84
+ */
20
85
  export declare enum SignerType {
21
86
  EVM = "EVM",
22
87
  BTC = "BTC"
23
88
  }
89
+ /**
90
+ * A class representing information about a signer, including its type and the signer instance.
91
+ */
24
92
  export declare class SignerInfo {
25
93
  type: SignerType;
26
94
  signer: Signer;
27
95
  constructor(type: SignerType, signer: Signer);
28
96
  }
97
+ /**
98
+ * Represents a wallet with a name, icon, and an array of signer information.
99
+ */
29
100
  export type Wallet = {
30
101
  name: string;
31
102
  icon: string;
@@ -1 +1 @@
1
- {"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../../src/signer/signer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAE7B,8BAAsB,MAAM;aACE,MAAM,EAAE,MAAM;gBAAd,MAAM,EAAE,MAAM;IAE1C,QAAQ,CAAC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAEjC,QAAQ,CAAC,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAE9C,QAAQ,CAAC,cAAc,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IACvC,wBAAwB,CAAC,WAAW,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAIjE,qBAAqB,CAAC,UAAU,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;IAG5D,YAAY,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAMvC,WAAW,CAAC,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC;IAI7C,eAAe,CAAC,EAAE,EAAE,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC;IAI9C,eAAe,CAAC,EAAE,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IAI5D,mBAAmB,CAAC,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;CAG1D;AAED,oBAAY,UAAU;IACpB,GAAG,QAAQ;IACX,GAAG,QAAQ;CACZ;AAED,qBAAa,UAAU;IAEZ,IAAI,EAAE,UAAU;IAChB,MAAM,EAAE,MAAM;gBADd,IAAI,EAAE,UAAU,EAChB,MAAM,EAAE,MAAM;CAExB;AAED,MAAM,MAAM,MAAM,GAAG;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,UAAU,EAAE,CAAC;CACvB,CAAC"}
1
+ {"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../../src/signer/signer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAE7B;;;GAGG;AACH,8BAAsB,MAAM;aACE,MAAM,EAAE,MAAM;gBAAd,MAAM,EAAE,MAAM;IAE1C;;;;OAIG;IACH,QAAQ,CAAC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAEjC;;;;OAIG;IACH,QAAQ,CAAC,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAE9C;;;;OAIG;IACH,QAAQ,CAAC,cAAc,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IAE7C;;;;;OAKG;IACG,wBAAwB,CAAC,WAAW,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAIvE;;;;;OAKG;IACG,qBAAqB,CAAC,UAAU,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;IAIlE;;;;OAIG;IACG,YAAY,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAMvC;;;;;;OAMG;IACH,WAAW,CAAC,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC;IAInD;;;;;OAKG;IACG,eAAe,CAAC,EAAE,EAAE,eAAe,GAAG,OAAO,CAAC,GAAG,CAAC;IAIxD;;;;;OAKG;IACG,eAAe,CAAC,EAAE,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC;IAIhE;;;;;;OAMG;IACH,mBAAmB,CAAC,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC;CAG9D;AAED;;GAEG;AACH,oBAAY,UAAU;IACpB,GAAG,QAAQ;IACX,GAAG,QAAQ;CACZ;AAED;;GAEG;AACH,qBAAa,UAAU;IAEZ,IAAI,EAAE,UAAU;IAChB,MAAM,EAAE,MAAM;gBADd,IAAI,EAAE,UAAU,EAChB,MAAM,EAAE,MAAM;CAExB;AAED;;GAEG;AACH,MAAM,MAAM,MAAM,GAAG;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,UAAU,EAAE,CAAC;CACvB,CAAC"}
@@ -1,34 +1,87 @@
1
+ /**
2
+ * An abstract class representing a generic signer.
3
+ * This class provides methods to connect, get addresses, and sign transactions.
4
+ */
1
5
  export class Signer {
2
6
  constructor(client) {
3
7
  this.client = client;
4
8
  }
9
+ /**
10
+ * Gets the recommended Address object for the signer.
11
+ *
12
+ * @param _preference - Optional preference parameter.
13
+ * @returns A promise that resolves to the recommended Address object.
14
+ */
5
15
  async getRecommendedAddressObj(_preference) {
6
16
  return (await this.getAddressObjs())[0];
7
17
  }
18
+ /**
19
+ * Gets the recommended address for the signer as a string.
20
+ *
21
+ * @param preference - Optional preference parameter.
22
+ * @returns A promise that resolves to the recommended address as a string.
23
+ */
8
24
  async getRecommendedAddress(preference) {
9
25
  return (await this.getRecommendedAddressObj(preference)).toString();
10
26
  }
27
+ /**
28
+ * Gets an array of addresses associated with the signer as strings.
29
+ *
30
+ * @returns A promise that resolves to an array of addresses as strings.
31
+ */
11
32
  async getAddresses() {
12
33
  return this.getAddressObjs().then((addresses) => addresses.map((address) => address.toString()));
13
34
  }
35
+ /**
36
+ * Signs a message. This method is not implemented and should be overridden by subclasses.
37
+ *
38
+ * @param _ - The message to sign, as a string or BytesLike object.
39
+ * @returns A promise that resolves to the signed message as a string.
40
+ * @throws Will throw an error if not implemented.
41
+ */
14
42
  signMessage(_) {
15
43
  throw Error("Signer.signMessage not implemented");
16
44
  }
45
+ /**
46
+ * Sends a transaction after signing it.
47
+ *
48
+ * @param tx - The transaction to send, represented as a TransactionLike object.
49
+ * @returns A promise that resolves to the transaction hash as a Hex string.
50
+ */
17
51
  async sendTransaction(tx) {
18
52
  return this.client.sendTransaction(await this.signTransaction(tx));
19
53
  }
54
+ /**
55
+ * Signs a transaction.
56
+ *
57
+ * @param tx - The transaction to sign, represented as a TransactionLike object.
58
+ * @returns A promise that resolves to the signed Transaction object.
59
+ */
20
60
  async signTransaction(tx) {
21
61
  return this.signOnlyTransaction(tx);
22
62
  }
63
+ /**
64
+ * Signs a transaction without sending it. This method is not implemented and should be overridden by subclasses.
65
+ *
66
+ * @param _ - The transaction to sign, represented as a TransactionLike object.
67
+ * @returns A promise that resolves to the signed Transaction object.
68
+ * @throws Will throw an error if not implemented.
69
+ */
23
70
  signOnlyTransaction(_) {
24
71
  throw Error("Signer.signOnlyTransaction not implemented");
25
72
  }
26
73
  }
74
+ /**
75
+ * An enumeration of signer types.
76
+ */
27
77
  export var SignerType;
28
78
  (function (SignerType) {
29
79
  SignerType["EVM"] = "EVM";
30
80
  SignerType["BTC"] = "BTC";
31
81
  })(SignerType || (SignerType = {}));
82
+ /**
83
+ * A class representing information about a signer, including its type and the signer instance.
84
+ */
32
85
  export class SignerInfo {
33
86
  constructor(type, signer) {
34
87
  this.type = type;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckb-ccc/core",
3
- "version": "0.0.4-alpha.1",
3
+ "version": "0.0.4-alpha.3",
4
4
  "description": "Common Chains Connector Core",
5
5
  "author": "Hanssen0 <hanssen0@hanssen0.com>",
6
6
  "license": "MIT",
@@ -23,7 +23,6 @@
23
23
  "format": "prettier --write . && eslint --fix"
24
24
  },
25
25
  "devDependencies": {
26
- "@ckb-lumos/helpers": "^0.22.2",
27
26
  "@eslint/js": "^9.1.1",
28
27
  "@types/blake2b": "^2.1.3",
29
28
  "eslint": "^9.1.0",
@@ -40,6 +39,7 @@
40
39
  "access": "public"
41
40
  },
42
41
  "dependencies": {
42
+ "@ckb-lumos/helpers": "^0.22.2",
43
43
  "@noble/hashes": "^1.4.0",
44
44
  "abort-controller": "^3.0.0",
45
45
  "bech32": "^2.0.0",
@@ -47,5 +47,5 @@
47
47
  "buffer": "^6.0.3",
48
48
  "cross-fetch": "^4.0.0"
49
49
  },
50
- "gitHead": "7dab1a1d6e3e380b26f43d0d0308bd4da1617029"
50
+ "gitHead": "7eed10c29d8bb17e6b767197e36cede3180b1b2d"
51
51
  }