@ckb-ccc/core 0.0.4-alpha.1 → 0.0.4-alpha.11

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 (114) 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/advanced.d.ts +1 -0
  20. package/dist/client/advanced.d.ts.map +1 -1
  21. package/dist/client/advanced.js +1 -0
  22. package/dist/client/client.d.ts +10 -8
  23. package/dist/client/client.d.ts.map +1 -1
  24. package/dist/client/client.js +18 -0
  25. package/dist/client/clientPublicMainnet.advanced.d.ts +2 -2
  26. package/dist/client/clientPublicMainnet.advanced.d.ts.map +1 -1
  27. package/dist/client/clientPublicMainnet.d.ts +3 -3
  28. package/dist/client/clientPublicMainnet.d.ts.map +1 -1
  29. package/dist/client/clientPublicMainnet.js +2 -2
  30. package/dist/client/clientPublicTestnet.advanced.d.ts +2 -2
  31. package/dist/client/clientPublicTestnet.advanced.d.ts.map +1 -1
  32. package/dist/client/clientPublicTestnet.d.ts +3 -3
  33. package/dist/client/clientPublicTestnet.d.ts.map +1 -1
  34. package/dist/client/clientPublicTestnet.js +2 -2
  35. package/dist/client/clientTypes.d.ts +6 -0
  36. package/dist/client/clientTypes.d.ts.map +1 -1
  37. package/dist/client/index.d.ts +1 -0
  38. package/dist/client/index.d.ts.map +1 -1
  39. package/dist/client/index.js +1 -0
  40. package/dist/client/jsonRpc/advanced.d.ts +2 -87
  41. package/dist/client/jsonRpc/advanced.d.ts.map +1 -1
  42. package/dist/client/jsonRpc/advanced.js +2 -65
  43. package/dist/client/jsonRpc/index.d.ts +60 -6
  44. package/dist/client/jsonRpc/index.d.ts.map +1 -1
  45. package/dist/client/jsonRpc/index.js +72 -7
  46. package/dist/client/jsonRpc/transformers.d.ts +28 -0
  47. package/dist/client/jsonRpc/transformers.d.ts.map +1 -0
  48. package/dist/client/jsonRpc/transformers.js +122 -0
  49. package/dist/client/jsonRpc/types.d.ts +41 -0
  50. package/dist/client/jsonRpc/types.d.ts.map +1 -0
  51. package/dist/client/jsonRpc/types.js +1 -0
  52. package/dist/fixedPoint/index.d.ts +43 -1
  53. package/dist/fixedPoint/index.d.ts.map +1 -1
  54. package/dist/fixedPoint/index.js +39 -1
  55. package/dist/hasher/index.d.ts +43 -2
  56. package/dist/hasher/index.d.ts.map +1 -1
  57. package/dist/hasher/index.js +42 -0
  58. package/dist/hex/index.d.ts +19 -0
  59. package/dist/hex/index.d.ts.map +1 -1
  60. package/dist/hex/index.js +12 -0
  61. package/dist/num/index.d.ts +99 -0
  62. package/dist/num/index.d.ts.map +1 -1
  63. package/dist/num/index.js +92 -0
  64. package/dist/signer/btc/signerBtc.d.ts +40 -2
  65. package/dist/signer/btc/signerBtc.d.ts.map +1 -1
  66. package/dist/signer/btc/signerBtc.js +36 -4
  67. package/dist/signer/btc/signerBtcPublicKeyReadonly.d.ts +48 -0
  68. package/dist/signer/btc/signerBtcPublicKeyReadonly.d.ts.map +1 -1
  69. package/dist/signer/btc/signerBtcPublicKeyReadonly.js +53 -0
  70. package/dist/signer/ckb/signerCkbScriptReadonly.d.ts +47 -0
  71. package/dist/signer/ckb/signerCkbScriptReadonly.d.ts.map +1 -1
  72. package/dist/signer/ckb/signerCkbScriptReadonly.js +52 -0
  73. package/dist/signer/evm/signerEvm.d.ts +34 -2
  74. package/dist/signer/evm/signerEvm.d.ts.map +1 -1
  75. package/dist/signer/evm/signerEvm.js +35 -4
  76. package/dist/signer/evm/signerEvmAddressReadonly.d.ts +43 -1
  77. package/dist/signer/evm/signerEvmAddressReadonly.d.ts.map +1 -1
  78. package/dist/signer/evm/signerEvmAddressReadonly.js +47 -0
  79. package/dist/signer/helpers.d.ts +35 -2
  80. package/dist/signer/helpers.d.ts.map +1 -1
  81. package/dist/signer/helpers.js +67 -11
  82. package/dist/signer/signer.d.ts +98 -7
  83. package/dist/signer/signer.d.ts.map +1 -1
  84. package/dist/signer/signer.js +70 -3
  85. package/package.json +3 -3
  86. package/src/address/address.advanced.ts +54 -18
  87. package/src/address/index.ts +51 -7
  88. package/src/bytes/advanced.ts +12 -9
  89. package/src/bytes/index.ts +60 -0
  90. package/src/ckb/script.ts +111 -2
  91. package/src/ckb/transaction.ts +455 -2
  92. package/src/client/advanced.ts +1 -0
  93. package/src/client/client.ts +31 -8
  94. package/src/client/clientPublicMainnet.advanced.ts +5 -2
  95. package/src/client/clientPublicMainnet.ts +6 -4
  96. package/src/client/clientPublicTestnet.advanced.ts +5 -2
  97. package/src/client/clientPublicTestnet.ts +6 -4
  98. package/src/client/clientTypes.ts +13 -0
  99. package/src/client/index.ts +1 -0
  100. package/src/client/jsonRpc/advanced.ts +2 -93
  101. package/src/client/jsonRpc/index.ts +99 -11
  102. package/src/client/jsonRpc/transformers.ts +161 -0
  103. package/src/client/jsonRpc/types.ts +48 -0
  104. package/src/fixedPoint/index.ts +52 -2
  105. package/src/hasher/index.ts +47 -1
  106. package/src/hex/index.ts +19 -0
  107. package/src/num/index.ts +101 -0
  108. package/src/signer/btc/signerBtc.ts +47 -4
  109. package/src/signer/btc/signerBtcPublicKeyReadonly.ts +54 -0
  110. package/src/signer/ckb/signerCkbScriptReadonly.ts +54 -0
  111. package/src/signer/evm/signerEvm.ts +42 -4
  112. package/src/signer/evm/signerEvmAddressReadonly.ts +50 -1
  113. package/src/signer/helpers.ts +87 -11
  114. package/src/signer/signer.ts +109 -7
@@ -1,12 +1,60 @@
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
+ * Construct a new signer with the client replaced.
21
+ *
22
+ * @returns A promise that resolves the new Signer.
23
+ */
24
+ replaceClient(client: Client): Promise<SignerBtcPublicKeyReadonly>;
25
+ /**
26
+ * Connects to the client. This implementation does nothing as the class is read-only.
27
+ *
28
+ * @returns A promise that resolves when the connection is complete.
29
+ */
8
30
  connect(): Promise<void>;
31
+ /**
32
+ * Check if the signer is connected.
33
+ *
34
+ * @returns A promise that resolves the connection status.
35
+ */
36
+ isConnected(): Promise<boolean>;
37
+ /**
38
+ * Gets the Bitcoin account associated with the signer.
39
+ *
40
+ * @returns A promise that resolves to a string representing the Bitcoin account.
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * const account = await signer.getBtcAccount(); // Outputs the Bitcoin account
45
+ * ```
46
+ */
9
47
  getBtcAccount(): Promise<string>;
48
+ /**
49
+ * Gets the Bitcoin public key associated with the signer.
50
+ *
51
+ * @returns A promise that resolves to a Hex string representing the Bitcoin public key.
52
+ *
53
+ * @example
54
+ * ```typescript
55
+ * const publicKey = await signer.getBtcPublicKey(); // Outputs the Bitcoin public key
56
+ * ```
57
+ */
10
58
  getBtcPublicKey(): Promise<Hex>;
11
59
  }
12
60
  //# 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,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,0BAA0B,CAAC;IAIxE;;;;OAIG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAE9B;;;;OAIG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAIrC;;;;;;;;;OASG;IACG,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAItC;;;;;;;;;OASG;IACG,eAAe,IAAI,OAAO,CAAC,GAAG,CAAC;CAGtC"}
@@ -1,15 +1,68 @@
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
+ * Construct a new signer with the client replaced.
22
+ *
23
+ * @returns A promise that resolves the new Signer.
24
+ */
25
+ async replaceClient(client) {
26
+ return new SignerBtcPublicKeyReadonly(client, this.account, this.publicKey);
27
+ }
28
+ /**
29
+ * Connects to the client. This implementation does nothing as the class is read-only.
30
+ *
31
+ * @returns A promise that resolves when the connection is complete.
32
+ */
9
33
  async connect() { }
34
+ /**
35
+ * Check if the signer is connected.
36
+ *
37
+ * @returns A promise that resolves the connection status.
38
+ */
39
+ async isConnected() {
40
+ return true;
41
+ }
42
+ ;
43
+ /**
44
+ * Gets the Bitcoin account associated with the signer.
45
+ *
46
+ * @returns A promise that resolves to a string representing the Bitcoin account.
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * const account = await signer.getBtcAccount(); // Outputs the Bitcoin account
51
+ * ```
52
+ */
10
53
  async getBtcAccount() {
11
54
  return this.account;
12
55
  }
56
+ /**
57
+ * Gets the Bitcoin public key associated with the signer.
58
+ *
59
+ * @returns A promise that resolves to a Hex string representing the Bitcoin public key.
60
+ *
61
+ * @example
62
+ * ```typescript
63
+ * const publicKey = await signer.getBtcPublicKey(); // Outputs the Bitcoin public key
64
+ * ```
65
+ */
13
66
  async getBtcPublicKey() {
14
67
  return this.publicKey;
15
68
  }
@@ -2,11 +2,58 @@ 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
+ * Construct a new signer with the client replaced.
20
+ *
21
+ * @returns A promise that resolves the new Signer.
22
+ */
23
+ replaceClient(client: Client): Promise<SignerCkbScriptReadonly>;
24
+ /**
25
+ * Connects to the client. This implementation does nothing as the class is read-only.
26
+ *
27
+ * @returns A promise that resolves when the connection is complete.
28
+ */
8
29
  connect(): Promise<void>;
30
+ /**
31
+ * Check if the signer is connected.
32
+ *
33
+ * @returns A promise that resolves the connection status.
34
+ */
35
+ isConnected(): Promise<boolean>;
36
+ /**
37
+ * Gets the internal address for the script.
38
+ *
39
+ * @returns A promise that resolves to a string representing the internal address.
40
+ *
41
+ * @example
42
+ * ```typescript
43
+ * const internalAddress = await signer.getInternalAddress(); // Outputs the internal address
44
+ * ```
45
+ */
9
46
  getInternalAddress(): Promise<string>;
47
+ /**
48
+ * Gets an array of Address objects representing the script address.
49
+ *
50
+ * @returns A promise that resolves to an array of Address objects.
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * const addressObjs = await signer.getAddressObjs(); // Outputs the array of Address objects
55
+ * ```
56
+ */
10
57
  getAddressObjs(): Promise<Address[]>;
11
58
  }
12
59
  //# 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,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,uBAAuB,CAAC;IAIrE;;;;OAIG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAE9B;;;;OAIG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAIrC;;;;;;;;;OASG;IACG,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAI3C;;;;;;;;;OASG;IAEG,cAAc,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;CAG3C"}
@@ -1,15 +1,67 @@
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
+ * Construct a new signer with the client replaced.
21
+ *
22
+ * @returns A promise that resolves the new Signer.
23
+ */
24
+ async replaceClient(client) {
25
+ return new SignerCkbScriptReadonly(client, this.script);
26
+ }
27
+ /**
28
+ * Connects to the client. This implementation does nothing as the class is read-only.
29
+ *
30
+ * @returns A promise that resolves when the connection is complete.
31
+ */
9
32
  async connect() { }
33
+ /**
34
+ * Check if the signer is connected.
35
+ *
36
+ * @returns A promise that resolves the connection status.
37
+ */
38
+ async isConnected() {
39
+ return true;
40
+ }
41
+ ;
42
+ /**
43
+ * Gets the internal address for the script.
44
+ *
45
+ * @returns A promise that resolves to a string representing the internal address.
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * const internalAddress = await signer.getInternalAddress(); // Outputs the internal address
50
+ * ```
51
+ */
10
52
  async getInternalAddress() {
11
53
  return this.getRecommendedAddress();
12
54
  }
55
+ /**
56
+ * Gets an array of Address objects representing the script address.
57
+ *
58
+ * @returns A promise that resolves to an array of Address objects.
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * const addressObjs = await signer.getAddressObjs(); // Outputs the array of Address objects
63
+ * ```
64
+ */
13
65
  async getAddressObjs() {
14
66
  return [await Address.fromScript(this.script, this.client)];
15
67
  }
@@ -1,10 +1,42 @@
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
+ * prepare a transaction before signing. This method is not implemented and should be overridden by subclasses.
29
+ *
30
+ * @param txLike - The transaction to prepare, represented as a TransactionLike object.
31
+ * @returns A promise that resolves to the prepared Transaction object.
32
+ */
33
+ prepareTransaction(txLike: TransactionLike): Promise<Transaction>;
34
+ /**
35
+ * Signs a transaction without modifying it.
36
+ *
37
+ * @param txLike - The transaction to sign, represented as a TransactionLike object.
38
+ * @returns A promise that resolves to a signed Transaction object.
39
+ */
40
+ signOnlyTransaction(txLike: TransactionLike): Promise<Transaction>;
9
41
  }
10
42
  //# 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,kBAAkB,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC;IAKvE;;;;;OAKG;IACG,mBAAmB,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC;CAgCzE"}
@@ -1,24 +1,55 @@
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
- import { getSignHashInfo } from "../helpers";
7
+ import { getSignHashInfo, prepareSighashAllWitness } 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
+ * prepare a transaction before signing. This method is not implemented and should be overridden by subclasses.
35
+ *
36
+ * @param txLike - The transaction to prepare, represented as a TransactionLike object.
37
+ * @returns A promise that resolves to the prepared Transaction object.
38
+ */
39
+ async prepareTransaction(txLike) {
20
40
  const { script } = await this.getRecommendedAddressObj();
21
- const info = await getSignHashInfo(tx, script);
41
+ return prepareSighashAllWitness(txLike, script, 85, this.client);
42
+ }
43
+ /**
44
+ * Signs a transaction without modifying it.
45
+ *
46
+ * @param txLike - The transaction to sign, represented as a TransactionLike object.
47
+ * @returns A promise that resolves to a signed Transaction object.
48
+ */
49
+ async signOnlyTransaction(txLike) {
50
+ const tx = Transaction.from(txLike);
51
+ const { script } = await this.getRecommendedAddressObj();
52
+ const info = await getSignHashInfo(tx, script, this.client);
22
53
  if (!info) {
23
54
  return tx;
24
55
  }
@@ -1,10 +1,52 @@
1
1
  import { Client } from "../../client";
2
2
  import { HexLike } from "../../hex";
3
3
  import { SignerEvm } from "./signerEvm";
4
- export declare abstract class SignerEvmAddressReadonly extends 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
+ */
8
+ export declare 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
+ * Construct a new signer with the client replaced.
19
+ *
20
+ * @returns A promise that resolves the new Signer.
21
+ */
22
+ replaceClient(client: Client): Promise<SignerEvmAddressReadonly>;
23
+ /**
24
+ * Connects to the client. This implementation does nothing as the class is read-only.
25
+ *
26
+ * @returns A promise that resolves when the connection is complete.
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * await signer.connect();
31
+ * ```
32
+ */
7
33
  connect(): Promise<void>;
34
+ /**
35
+ * Check if the signer is connected.
36
+ *
37
+ * @returns A promise that resolves the connection status.
38
+ */
39
+ isConnected(): Promise<boolean>;
40
+ /**
41
+ * Gets the EVM account associated with the signer.
42
+ *
43
+ * @returns A promise that resolves to a string representing the EVM account.
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * const account = await signer.getEvmAccount(); // Outputs the EVM account
48
+ * ```
49
+ */
8
50
  getEvmAccount(): Promise<string>;
9
51
  }
10
52
  //# 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,qBAAa,wBAAyB,SAAQ,SAAS;IACrD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAM;IAE9B;;;;;OAKG;gBACS,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO;IAM5C;;;;OAIG;IACG,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,wBAAwB,CAAC;IAItE;;;;;;;;;OASG;IAEG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAE9B;;;;OAIG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAIrC;;;;;;;;;OASG;IACG,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;CAGvC"}
@@ -1,11 +1,58 @@
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
+ * Construct a new signer with the client replaced.
20
+ *
21
+ * @returns A promise that resolves the new Signer.
22
+ */
23
+ async replaceClient(client) {
24
+ return new SignerEvmAddressReadonly(client, this.address);
25
+ }
26
+ /**
27
+ * Connects to the client. This implementation does nothing as the class is read-only.
28
+ *
29
+ * @returns A promise that resolves when the connection is complete.
30
+ *
31
+ * @example
32
+ * ```typescript
33
+ * await signer.connect();
34
+ * ```
35
+ */
8
36
  async connect() { }
37
+ /**
38
+ * Check if the signer is connected.
39
+ *
40
+ * @returns A promise that resolves the connection status.
41
+ */
42
+ async isConnected() {
43
+ return true;
44
+ }
45
+ ;
46
+ /**
47
+ * Gets the EVM account associated with the signer.
48
+ *
49
+ * @returns A promise that resolves to a string representing the EVM account.
50
+ *
51
+ * @example
52
+ * ```typescript
53
+ * const account = await signer.getEvmAccount(); // Outputs the EVM account
54
+ * ```
55
+ */
9
56
  async getEvmAccount() {
10
57
  return this.address;
11
58
  }
@@ -1,7 +1,40 @@
1
- import { ScriptLike, TransactionLike } from "../ckb";
1
+ import { ScriptLike, Transaction, 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
+ * @param client - The client for complete extra infos in the transaction.
10
+ * @returns A promise that resolves to an object containing the signing message and the witness position,
11
+ * or undefined if no matching input is found.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * const signHashInfo = await getSignHashInfo(transactionLike, scriptLike, client);
16
+ * if (signHashInfo) {
17
+ * console.log(signHashInfo.message); // Outputs the signing message
18
+ * console.log(signHashInfo.position); // Outputs the witness position
19
+ * }
20
+ * ```
21
+ */
22
+ export declare function getSignHashInfo(txLike: TransactionLike, scriptLike: ScriptLike, client: Client): Promise<{
4
23
  message: Hex;
5
24
  position: number;
6
25
  } | undefined>;
26
+ /**
27
+ * Prepare dummy witness for sighash all method
28
+ *
29
+ * @param txLike - The transaction to prepare, represented as a TransactionLike object.
30
+ * @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
31
+ * @param client - The client for complete extra infos in the transaction.
32
+ * @returns A promise that resolves to the prepared transaction
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * const tx = await prepareSighashAllWitness(transactionLike, scriptLike, client);
37
+ * ```
38
+ */
39
+ export declare function prepareSighashAllWitness(txLike: TransactionLike, scriptLike: ScriptLike, lockLen: number, client: Client): Promise<Transaction>;
7
40
  //# sourceMappingURL=helpers.d.ts.map
@@ -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,EAEL,UAAU,EACV,WAAW,EACX,eAAe,EAEhB,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,OAAO,EAAE,GAAG,EAAW,MAAM,QAAQ,CAAC;AAEtC;;;;;;;;;;;;;;;;;GAiBG;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;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,wBAAwB,CAC5C,MAAM,EAAE,eAAe,EACvB,UAAU,EAAE,UAAU,EACtB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,WAAW,CAAC,CA6BtB"}
@@ -1,19 +1,38 @@
1
- import { Script, Transaction } from "../ckb";
1
+ import { Script, Transaction, WitnessArgs, } from "../ckb";
2
2
  import { Hasher } from "../hasher";
3
- export async function getSignHashInfo(txLike, scriptLike) {
3
+ import { hexFrom } from "../hex";
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
+ * @param client - The client for complete extra infos in the transaction.
10
+ * @returns A promise that resolves to an object containing the signing message and the witness position,
11
+ * or undefined if no matching input is found.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * const signHashInfo = await getSignHashInfo(transactionLike, scriptLike, client);
16
+ * if (signHashInfo) {
17
+ * console.log(signHashInfo.message); // Outputs the signing message
18
+ * console.log(signHashInfo.position); // Outputs the witness position
19
+ * }
20
+ * ```
21
+ */
22
+ export async function getSignHashInfo(txLike, scriptLike, client) {
4
23
  const tx = Transaction.from(txLike);
5
24
  const script = Script.from(scriptLike);
6
25
  let position = -1;
7
26
  const hasher = new Hasher();
8
27
  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");
28
+ for (let i = 0; i < tx.witnesses.length; i += 1) {
29
+ if (tx.inputs[i]) {
30
+ const input = await tx.inputs[i].completeExtraInfos(client);
31
+ if (!input.cellOutput) {
32
+ throw Error("Unable to resolve inputs info");
14
33
  }
15
- if (!script.eq(input.cellOutput?.lock)) {
16
- return;
34
+ if (!script.eq(input.cellOutput.lock)) {
35
+ continue;
17
36
  }
18
37
  if (position === -1) {
19
38
  position = i;
@@ -22,8 +41,8 @@ export async function getSignHashInfo(txLike, scriptLike) {
22
41
  if (position === -1) {
23
42
  return undefined;
24
43
  }
25
- Transaction.hashWitnessToHasher(witness, hasher);
26
- });
44
+ Transaction.hashWitnessToHasher(tx.witnesses[i], hasher);
45
+ }
27
46
  if (position === -1) {
28
47
  return undefined;
29
48
  }
@@ -32,3 +51,40 @@ export async function getSignHashInfo(txLike, scriptLike) {
32
51
  position,
33
52
  };
34
53
  }
54
+ /**
55
+ * Prepare dummy witness for sighash all method
56
+ *
57
+ * @param txLike - The transaction to prepare, represented as a TransactionLike object.
58
+ * @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
59
+ * @param client - The client for complete extra infos in the transaction.
60
+ * @returns A promise that resolves to the prepared transaction
61
+ *
62
+ * @example
63
+ * ```typescript
64
+ * const tx = await prepareSighashAllWitness(transactionLike, scriptLike, client);
65
+ * ```
66
+ */
67
+ export async function prepareSighashAllWitness(txLike, scriptLike, lockLen, client) {
68
+ const tx = Transaction.from(txLike);
69
+ const script = Script.from(scriptLike);
70
+ let position = -1;
71
+ for (let i = 0; i < tx.inputs.length; i += 1) {
72
+ const input = await tx.inputs[i].completeExtraInfos(client);
73
+ if (!input.cellOutput) {
74
+ throw Error("Unable to resolve inputs info");
75
+ }
76
+ if (script.eq(input.cellOutput.lock)) {
77
+ position = i;
78
+ break;
79
+ }
80
+ }
81
+ if (position === -1) {
82
+ return tx;
83
+ }
84
+ const witness = tx.witnesses[position]
85
+ ? WitnessArgs.fromBytes(tx.witnesses[position])
86
+ : WitnessArgs.from({});
87
+ witness.lock = hexFrom(Array.from(new Array(lockLen), () => 0));
88
+ tx.witnesses[position] = hexFrom(witness.toBytes());
89
+ return tx;
90
+ }