@ckb-ccc/core 0.0.11-alpha.3 → 0.0.12-alpha.1

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 (92) hide show
  1. package/dist/address/index.d.ts.map +1 -1
  2. package/dist/ckb/script.d.ts +1 -5
  3. package/dist/ckb/script.d.ts.map +1 -1
  4. package/dist/ckb/transaction.d.ts +21 -39
  5. package/dist/ckb/transaction.d.ts.map +1 -1
  6. package/dist/ckb/transaction.js +28 -3
  7. package/dist/client/client.advanced.d.ts.map +1 -1
  8. package/dist/client/client.d.ts +1 -0
  9. package/dist/client/client.d.ts.map +1 -1
  10. package/dist/client/client.js +1 -0
  11. package/dist/client/clientPublicMainnet.advanced.d.ts.map +1 -1
  12. package/dist/client/clientPublicMainnet.advanced.js +29 -0
  13. package/dist/client/clientPublicTestnet.advanced.d.ts.map +1 -1
  14. package/dist/client/clientPublicTestnet.advanced.js +29 -0
  15. package/dist/client/jsonRpc/index.d.ts.map +1 -1
  16. package/dist/fixedPoint/index.d.ts +2 -2
  17. package/dist/fixedPoint/index.d.ts.map +1 -1
  18. package/dist/hasher/hasher.d.ts +32 -0
  19. package/dist/hasher/hasher.d.ts.map +1 -0
  20. package/dist/hasher/hasher.js +1 -0
  21. package/dist/hasher/hasherCkb.d.ts +68 -0
  22. package/dist/hasher/hasherCkb.d.ts.map +1 -0
  23. package/dist/hasher/hasherCkb.js +83 -0
  24. package/dist/hasher/hasherKeecak256.d.ts +38 -0
  25. package/dist/hasher/hasherKeecak256.d.ts.map +1 -0
  26. package/dist/hasher/hasherKeecak256.js +43 -0
  27. package/dist/hasher/index.d.ts +3 -66
  28. package/dist/hasher/index.d.ts.map +1 -1
  29. package/dist/hasher/index.js +3 -79
  30. package/dist/keystore/index.d.ts +2 -2
  31. package/dist/keystore/index.d.ts.map +1 -1
  32. package/dist/signer/evm/signerEvm.d.ts +13 -4
  33. package/dist/signer/evm/signerEvm.d.ts.map +1 -1
  34. package/dist/signer/evm/signerEvm.js +63 -11
  35. package/dist/signer/signer/index.d.ts.map +1 -1
  36. package/dist/utils/index.d.ts +1 -1
  37. package/dist/utils/index.d.ts.map +1 -1
  38. package/dist.commonjs/address/index.d.ts.map +1 -1
  39. package/dist.commonjs/ckb/script.d.ts +1 -5
  40. package/dist.commonjs/ckb/script.d.ts.map +1 -1
  41. package/dist.commonjs/ckb/transaction.d.ts +21 -39
  42. package/dist.commonjs/ckb/transaction.d.ts.map +1 -1
  43. package/dist.commonjs/ckb/transaction.js +27 -2
  44. package/dist.commonjs/client/client.advanced.d.ts.map +1 -1
  45. package/dist.commonjs/client/client.d.ts +1 -0
  46. package/dist.commonjs/client/client.d.ts.map +1 -1
  47. package/dist.commonjs/client/client.js +1 -0
  48. package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts.map +1 -1
  49. package/dist.commonjs/client/clientPublicMainnet.advanced.js +29 -0
  50. package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts.map +1 -1
  51. package/dist.commonjs/client/clientPublicTestnet.advanced.js +29 -0
  52. package/dist.commonjs/client/jsonRpc/index.d.ts.map +1 -1
  53. package/dist.commonjs/fixedPoint/index.d.ts +2 -2
  54. package/dist.commonjs/fixedPoint/index.d.ts.map +1 -1
  55. package/dist.commonjs/hasher/hasher.d.ts +32 -0
  56. package/dist.commonjs/hasher/hasher.d.ts.map +1 -0
  57. package/dist.commonjs/hasher/hasher.js +2 -0
  58. package/dist.commonjs/hasher/hasherCkb.d.ts +68 -0
  59. package/dist.commonjs/hasher/hasherCkb.d.ts.map +1 -0
  60. package/dist.commonjs/hasher/hasherCkb.js +89 -0
  61. package/dist.commonjs/hasher/hasherKeecak256.d.ts +38 -0
  62. package/dist.commonjs/hasher/hasherKeecak256.d.ts.map +1 -0
  63. package/dist.commonjs/hasher/hasherKeecak256.js +47 -0
  64. package/dist.commonjs/hasher/index.d.ts +3 -66
  65. package/dist.commonjs/hasher/index.d.ts.map +1 -1
  66. package/dist.commonjs/hasher/index.js +16 -85
  67. package/dist.commonjs/keystore/index.d.ts +2 -2
  68. package/dist.commonjs/keystore/index.d.ts.map +1 -1
  69. package/dist.commonjs/signer/evm/signerEvm.d.ts +13 -4
  70. package/dist.commonjs/signer/evm/signerEvm.d.ts.map +1 -1
  71. package/dist.commonjs/signer/evm/signerEvm.js +72 -20
  72. package/dist.commonjs/signer/signer/index.d.ts.map +1 -1
  73. package/dist.commonjs/utils/index.d.ts +1 -1
  74. package/dist.commonjs/utils/index.d.ts.map +1 -1
  75. package/package.json +2 -3
  76. package/src/address/index.ts +1 -1
  77. package/src/ckb/script.ts +1 -1
  78. package/src/ckb/transaction.ts +43 -9
  79. package/src/client/client.advanced.ts +1 -1
  80. package/src/client/client.ts +1 -0
  81. package/src/client/clientPublicMainnet.advanced.ts +33 -0
  82. package/src/client/clientPublicTestnet.advanced.ts +33 -0
  83. package/src/client/jsonRpc/index.ts +3 -3
  84. package/src/fixedPoint/index.ts +2 -2
  85. package/src/hasher/hasher.ts +35 -0
  86. package/src/hasher/hasherCkb.ts +102 -0
  87. package/src/hasher/hasherKeecak256.ts +52 -0
  88. package/src/hasher/index.ts +3 -103
  89. package/src/keystore/index.ts +19 -1
  90. package/src/signer/evm/signerEvm.ts +131 -24
  91. package/src/signer/signer/index.ts +1 -1
  92. package/src/utils/index.ts +2 -2
@@ -0,0 +1,35 @@
1
+ import { BytesLike } from "../bytes/index.js";
2
+ import { Hex } from "../hex/index.js";
3
+
4
+ export interface Hasher {
5
+ /**
6
+ * Updates the hash with the given data.
7
+ *
8
+ * @param data - The data to update the hash with.
9
+ * @returns The current Hasher instance for chaining.
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * const hasher = new Hasher();
14
+ * hasher.update("some data").update("more data");
15
+ * const hash = hasher.digest();
16
+ * ```
17
+ */
18
+
19
+ update(data: BytesLike): Hasher;
20
+
21
+ /**
22
+ * Finalizes the hash and returns the digest as a hexadecimal string.
23
+ *
24
+ * @returns The hexadecimal string representation of the hash.
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * const hasher = new Hasher();
29
+ * hasher.update("some data");
30
+ * const hash = hasher.digest(); // Outputs something like "0x..."
31
+ * ```
32
+ */
33
+
34
+ digest(): Hex;
35
+ }
@@ -0,0 +1,102 @@
1
+ import { blake2b } from "@noble/hashes/blake2b";
2
+ import { BytesLike, bytesFrom } from "../bytes/index.js";
3
+ import { CellInput, CellInputLike } from "../ckb/index.js";
4
+ import { Hex, hexFrom } from "../hex/index.js";
5
+ import { NumLike, numLeToBytes } from "../num/index.js";
6
+ import { CKB_BLAKE2B_PERSONAL } from "./advanced.js";
7
+ import { Hasher } from "./hasher.js";
8
+
9
+ export class HasherCkb implements Hasher {
10
+ private readonly hasher: ReturnType<(typeof blake2b)["create"]>;
11
+
12
+ /**
13
+ * Creates an instance of Hasher.
14
+ *
15
+ * @param outLength - The output length of the hash in bytes. Default is 32.
16
+ * @param personal - The personal string for the Blake2b algorithm. Default is CKB_BLAKE2B_PERSONAL.
17
+ */
18
+
19
+ constructor(outLength = 32, personal = CKB_BLAKE2B_PERSONAL) {
20
+ this.hasher = blake2b.create({
21
+ personalization: personal,
22
+ dkLen: outLength,
23
+ });
24
+ }
25
+
26
+ /**
27
+ * Updates the hash with the given data.
28
+ *
29
+ * @param data - The data to update the hash with.
30
+ * @returns The current Hasher instance for chaining.
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * const hasher = new Hasher();
35
+ * hasher.update("some data").update("more data");
36
+ * const hash = hasher.digest();
37
+ * ```
38
+ */
39
+
40
+ update(data: BytesLike): HasherCkb {
41
+ this.hasher.update(bytesFrom(data));
42
+ return this;
43
+ }
44
+
45
+ /**
46
+ * Finalizes the hash and returns the digest as a hexadecimal string.
47
+ *
48
+ * @returns The hexadecimal string representation of the hash.
49
+ *
50
+ * @example
51
+ * ```typescript
52
+ * const hasher = new Hasher();
53
+ * hasher.update("some data");
54
+ * const hash = hasher.digest(); // Outputs something like "0x..."
55
+ * ```
56
+ */
57
+
58
+ digest(): Hex {
59
+ return hexFrom(this.hasher.digest());
60
+ }
61
+ }
62
+
63
+ /**
64
+ * Computes the CKB hash of the given data using the Blake2b algorithm.
65
+ *
66
+ * @param data - The data to hash.
67
+ * @returns The hexadecimal string representation of the hash.
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * const hash = hashCkb("some data"); // Outputs something like "0x..."
72
+ * ```
73
+ */
74
+
75
+ export function hashCkb(...data: BytesLike[]): Hex {
76
+ const hasher = new HasherCkb();
77
+ data.forEach((d) => hasher.update(d));
78
+ return hasher.digest();
79
+ }
80
+
81
+ /**
82
+ * Computes the Type ID hash of the given data.
83
+ *
84
+ * @param cellInput - The first cell input of the transaction.
85
+ * @param outputIndex - The output index of the Type ID cell.
86
+ * @returns The hexadecimal string representation of the hash.
87
+ *
88
+ * @example
89
+ * ```typescript
90
+ * const hash = hashTypeId(cellInput, outputIndex); // Outputs something like "0x..."
91
+ * ```
92
+ */
93
+
94
+ export function hashTypeId(
95
+ cellInputLike: CellInputLike,
96
+ outputIndex: NumLike,
97
+ ): Hex {
98
+ return hashCkb(
99
+ CellInput.from(cellInputLike).toBytes(),
100
+ numLeToBytes(outputIndex, 8),
101
+ );
102
+ }
@@ -0,0 +1,52 @@
1
+ import { keccak_256 } from "@noble/hashes/sha3";
2
+ import { BytesLike, bytesFrom } from "../bytes/index.js";
3
+ import { Hex, hexFrom } from "../hex/index.js";
4
+ import { Hasher } from "./hasher.js";
5
+
6
+ export class HasherKeecak256 implements Hasher {
7
+ private readonly hasher: ReturnType<(typeof keccak_256)["create"]>;
8
+
9
+ /**
10
+ * Creates an instance of Hasher.
11
+ */
12
+
13
+ constructor() {
14
+ this.hasher = keccak_256.create();
15
+ }
16
+
17
+ /**
18
+ * Updates the hash with the given data.
19
+ *
20
+ * @param data - The data to update the hash with.
21
+ * @returns The current Hasher instance for chaining.
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * const hasher = new Hasher();
26
+ * hasher.update("some data").update("more data");
27
+ * const hash = hasher.digest();
28
+ * ```
29
+ */
30
+
31
+ update(data: BytesLike): HasherKeecak256 {
32
+ this.hasher.update(bytesFrom(data));
33
+ return this;
34
+ }
35
+
36
+ /**
37
+ * Finalizes the hash and returns the digest as a hexadecimal string.
38
+ *
39
+ * @returns The hexadecimal string representation of the hash.
40
+ *
41
+ * @example
42
+ * ```typescript
43
+ * const hasher = new Hasher();
44
+ * hasher.update("some data");
45
+ * const hash = hasher.digest(); // Outputs something like "0x..."
46
+ * ```
47
+ */
48
+
49
+ digest(): Hex {
50
+ return hexFrom(this.hasher.digest());
51
+ }
52
+ }
@@ -1,103 +1,3 @@
1
- import blake2b, { Blake2b } from "blake2b";
2
- import { BytesLike, bytesFrom } from "../bytes/index.js";
3
- import { CellInput, CellInputLike } from "../ckb/index.js";
4
- import { Hex } from "../hex/index.js";
5
- import { NumLike, numLeToBytes } from "../num/index.js";
6
- import { CKB_BLAKE2B_PERSONAL } from "./advanced.js";
7
-
8
- export class Hasher {
9
- private readonly hasher: Blake2b;
10
-
11
- /**
12
- * Creates an instance of Hasher.
13
- *
14
- * @param outLength - The output length of the hash in bytes. Default is 32.
15
- * @param personal - The personal string for the Blake2b algorithm. Default is CKB_BLAKE2B_PERSONAL.
16
- */
17
-
18
- constructor(outLength = 32, personal = CKB_BLAKE2B_PERSONAL) {
19
- this.hasher = blake2b(
20
- outLength,
21
- undefined,
22
- undefined,
23
- bytesFrom(personal, "utf8"),
24
- );
25
- }
26
-
27
- /**
28
- * Updates the hash with the given data.
29
- *
30
- * @param data - The data to update the hash with.
31
- * @returns The current Hasher instance for chaining.
32
- *
33
- * @example
34
- * ```typescript
35
- * const hasher = new Hasher();
36
- * hasher.update("some data").update("more data");
37
- * const hash = hasher.digest();
38
- * ```
39
- */
40
-
41
- update(data: BytesLike): Hasher {
42
- this.hasher.update(bytesFrom(data));
43
- return this;
44
- }
45
-
46
- /**
47
- * Finalizes the hash and returns the digest as a hexadecimal string.
48
- *
49
- * @returns The hexadecimal string representation of the hash.
50
- *
51
- * @example
52
- * ```typescript
53
- * const hasher = new Hasher();
54
- * hasher.update("some data");
55
- * const hash = hasher.digest(); // Outputs something like "0x..."
56
- * ```
57
- */
58
-
59
- digest(): Hex {
60
- return `0x${this.hasher.digest("hex")}`;
61
- }
62
- }
63
-
64
- /**
65
- * Computes the CKB hash of the given data using the Blake2b algorithm.
66
- *
67
- * @param data - The data to hash.
68
- * @returns The hexadecimal string representation of the hash.
69
- *
70
- * @example
71
- * ```typescript
72
- * const hash = hashCkb("some data"); // Outputs something like "0x..."
73
- * ```
74
- */
75
-
76
- export function hashCkb(...data: BytesLike[]): Hex {
77
- const hasher = new Hasher();
78
- data.forEach((d) => hasher.update(d));
79
- return hasher.digest();
80
- }
81
-
82
- /**
83
- * Computes the Type ID hash of the given data.
84
- *
85
- * @param cellInput - The first cell input of the transaction.
86
- * @param outputIndex - The output index of the Type ID cell.
87
- * @returns The hexadecimal string representation of the hash.
88
- *
89
- * @example
90
- * ```typescript
91
- * const hash = hashTypeId(cellInput, outputIndex); // Outputs something like "0x..."
92
- * ```
93
- */
94
-
95
- export function hashTypeId(
96
- cellInputLike: CellInputLike,
97
- outputIndex: NumLike,
98
- ): Hex {
99
- return hashCkb(
100
- CellInput.from(cellInputLike).toBytes(),
101
- numLeToBytes(outputIndex, 8),
102
- );
103
- }
1
+ export * from "./hasher.js";
2
+ export * from "./hasherCkb.js";
3
+ export * from "./hasherKeecak256.js";
@@ -22,7 +22,25 @@ export async function keystoreEncrypt(
22
22
  privateKeyLike: BytesLike,
23
23
  chainCodeLike: BytesLike,
24
24
  password: string,
25
- ) {
25
+ ): Promise<{
26
+ id: string;
27
+ crypto: {
28
+ ciphertext: string;
29
+ cipherparams: {
30
+ iv: string;
31
+ };
32
+ cipher: string;
33
+ kdf: string;
34
+ kdfparams: {
35
+ n: number;
36
+ r: number;
37
+ p: number;
38
+ dklen: number;
39
+ salt: string;
40
+ };
41
+ mac: string;
42
+ };
43
+ }> {
26
44
  const salt = randomBytes(32);
27
45
  const iv = randomBytes(16);
28
46
  const kdfparams = {
@@ -1,5 +1,5 @@
1
1
  import { Address } from "../../address/index.js";
2
- import { BytesLike, bytesConcat, bytesFrom } from "../../bytes/index.js";
2
+ import { Bytes, BytesLike, bytesConcat, bytesFrom } from "../../bytes/index.js";
3
3
  import {
4
4
  Script,
5
5
  Transaction,
@@ -7,7 +7,8 @@ import {
7
7
  WitnessArgs,
8
8
  } from "../../ckb/index.js";
9
9
  import { KnownScript } from "../../client/index.js";
10
- import { Hex, hexFrom } from "../../hex/index.js";
10
+ import { Hasher, HasherKeecak256 } from "../../hasher/index.js";
11
+ import { Hex, HexLike, hexFrom } from "../../hex/index.js";
11
12
  import { numToBytes } from "../../num/index.js";
12
13
  import { reduceAsync } from "../../utils/index.js";
13
14
  import { Signer, SignerSignType, SignerType } from "../signer/index.js";
@@ -48,13 +49,30 @@ export abstract class SignerEvm extends Signer {
48
49
  */
49
50
  async getAddressObjs(): Promise<Address[]> {
50
51
  const account = await this.getEvmAccount();
51
- return [
52
- await this._getOmniLockEvmAddressObj(account),
53
- await this._getOmniLockOldEvmAddressObj(account),
54
- ];
52
+ const addresses = await Promise.all([
53
+ this._getOmniLockAddresses(account),
54
+ this._getPWLockAddresses(account),
55
+ ]);
56
+
57
+ return addresses.flat();
58
+ }
59
+
60
+ _getOmniLockAddresses(account: HexLike): Promise<Address[]> {
61
+ return Promise.all([
62
+ this._getOmniLockEvmAddressObj(account),
63
+ this._getOmniLockOldEvmAddressObj(account),
64
+ ]);
65
+ }
66
+
67
+ async _getPWLockAddresses(account: HexLike): Promise<Address[]> {
68
+ const addr = await this._getPWLockEvmAddressObj(account);
69
+ if (!addr) {
70
+ return [];
71
+ }
72
+ return [addr];
55
73
  }
56
74
 
57
- async _getOmniLockEvmAddressObj(account: string): Promise<Address> {
75
+ async _getOmniLockEvmAddressObj(account: HexLike): Promise<Address> {
58
76
  return Address.fromKnownScript(
59
77
  this.client,
60
78
  KnownScript.OmniLock,
@@ -62,7 +80,7 @@ export abstract class SignerEvm extends Signer {
62
80
  );
63
81
  }
64
82
 
65
- async _getOmniLockOldEvmAddressObj(account: string): Promise<Address> {
83
+ async _getOmniLockOldEvmAddressObj(account: HexLike): Promise<Address> {
66
84
  return Address.fromKnownScript(
67
85
  this.client,
68
86
  KnownScript.OmniLock,
@@ -70,6 +88,19 @@ export abstract class SignerEvm extends Signer {
70
88
  );
71
89
  }
72
90
 
91
+ async _getPWLockEvmAddressObj(
92
+ account: HexLike,
93
+ ): Promise<Address | undefined> {
94
+ try {
95
+ return Address.fromKnownScript(
96
+ this.client,
97
+ KnownScript.PWLock,
98
+ hexFrom(bytesFrom(account)),
99
+ );
100
+ } catch {}
101
+ return;
102
+ }
103
+
73
104
  /**
74
105
  * prepare a transaction before signing. This method is not implemented and should be overridden by subclasses.
75
106
  *
@@ -78,13 +109,40 @@ export abstract class SignerEvm extends Signer {
78
109
  */
79
110
  async prepareTransaction(txLike: TransactionLike): Promise<Transaction> {
80
111
  const tx = Transaction.from(txLike);
81
- await tx.addCellDepsOfKnownScripts(this.client, KnownScript.OmniLock);
82
- return reduceAsync(
83
- await this.getAddressObjs(),
112
+ if (
113
+ (await tx.findInputIndexByLockId(
114
+ await this.client.getKnownScript(KnownScript.OmniLock),
115
+ this.client,
116
+ )) !== undefined
117
+ ) {
118
+ await tx.addCellDepsOfKnownScripts(this.client, KnownScript.OmniLock);
119
+ }
120
+ if (
121
+ (await tx.findInputIndexByLockId(
122
+ await this.client.getKnownScript(KnownScript.PWLock),
123
+ this.client,
124
+ )) !== undefined
125
+ ) {
126
+ await tx.addCellDepsOfKnownScripts(this.client, KnownScript.PWLock);
127
+ }
128
+
129
+ const account = await this.getEvmAccount();
130
+ const omniLockAddresses = await this._getOmniLockAddresses(account);
131
+ const pwLockAddresses = await this._getPWLockAddresses(account);
132
+
133
+ const omniTx = reduceAsync(
134
+ omniLockAddresses,
84
135
  (tx: Transaction, { script }) =>
85
136
  tx.prepareSighashAllWitness(script, 85, this.client),
86
137
  tx,
87
138
  );
139
+
140
+ return reduceAsync(
141
+ pwLockAddresses,
142
+ (tx: Transaction, { script }) =>
143
+ tx.prepareSighashAllWitness(script, 65, this.client),
144
+ omniTx,
145
+ );
88
146
  }
89
147
 
90
148
  /**
@@ -112,6 +170,15 @@ export abstract class SignerEvm extends Signer {
112
170
  (hash) => bytesFrom(hash),
113
171
  );
114
172
 
173
+ const pwAddress = await this._getPWLockEvmAddressObj(account);
174
+ if (pwAddress) {
175
+ tx = await this._signPWLockScriptForTransaction(
176
+ tx,
177
+ pwAddress.script,
178
+ (hash) => bytesFrom(hash),
179
+ );
180
+ }
181
+
115
182
  return tx;
116
183
  }
117
184
 
@@ -120,27 +187,24 @@ export abstract class SignerEvm extends Signer {
120
187
  script: Script,
121
188
  messageTransformer: (hash: string) => BytesLike,
122
189
  ): Promise<Transaction> {
123
- const info = await tx.getSignHashInfo(script, this.client);
190
+ const info = await this._signPersonalEvmForTransaction(
191
+ tx,
192
+ script,
193
+ messageTransformer,
194
+ );
124
195
  if (!info) {
125
196
  return tx;
126
197
  }
127
198
 
128
- const signature = bytesFrom(
129
- await this.signMessageRaw(messageTransformer(info.message)),
130
- );
131
- if (signature[signature.length - 1] >= 27) {
132
- signature[signature.length - 1] -= 27;
133
- }
134
-
135
199
  const witness = WitnessArgs.fromBytes(tx.witnesses[info.position]);
136
200
  witness.lock = hexFrom(
137
201
  bytesConcat(
138
- numToBytes(5 * 4 + signature.length, 4),
202
+ numToBytes(5 * 4 + info.signature.length, 4),
139
203
  numToBytes(4 * 4, 4),
140
- numToBytes(5 * 4 + signature.length, 4),
141
- numToBytes(5 * 4 + signature.length, 4),
142
- numToBytes(signature.length, 4),
143
- signature,
204
+ numToBytes(5 * 4 + info.signature.length, 4),
205
+ numToBytes(5 * 4 + info.signature.length, 4),
206
+ numToBytes(info.signature.length, 4),
207
+ info.signature,
144
208
  ),
145
209
  );
146
210
 
@@ -148,4 +212,47 @@ export abstract class SignerEvm extends Signer {
148
212
 
149
213
  return tx;
150
214
  }
215
+
216
+ async _signPWLockScriptForTransaction(
217
+ tx: Transaction,
218
+ script: Script,
219
+ messageTransformer: (hash: string) => BytesLike,
220
+ ): Promise<Transaction> {
221
+ const info = await this._signPersonalEvmForTransaction(
222
+ tx,
223
+ script,
224
+ messageTransformer,
225
+ new HasherKeecak256(),
226
+ );
227
+ if (!info) {
228
+ return tx;
229
+ }
230
+
231
+ const witness = WitnessArgs.fromBytes(tx.witnesses[info.position]);
232
+ witness.lock = hexFrom(info.signature);
233
+ tx.setWitnessArgsAt(info.position, witness);
234
+
235
+ return tx;
236
+ }
237
+
238
+ async _signPersonalEvmForTransaction(
239
+ tx: Transaction,
240
+ script: Script,
241
+ messageTransformer: (hash: string) => BytesLike,
242
+ hasher?: Hasher,
243
+ ): Promise<{ signature: Bytes; position: number } | undefined> {
244
+ const info = await tx.getSignHashInfo(script, this.client, hasher);
245
+ if (!info) {
246
+ return;
247
+ }
248
+
249
+ const signature = bytesFrom(
250
+ await this.signMessageRaw(messageTransformer(info.message)),
251
+ );
252
+ if (signature[signature.length - 1] >= 27) {
253
+ signature[signature.length - 1] -= 27;
254
+ }
255
+
256
+ return { signature, position: info.position };
257
+ }
151
258
  }
@@ -73,7 +73,7 @@ export abstract class Signer {
73
73
  matchNetworkPreference(
74
74
  preferences: NetworkPreference[],
75
75
  currentNetwork: string,
76
- ) {
76
+ ): NetworkPreference | undefined {
77
77
  if (
78
78
  preferences.some(({ signerType, addressPrefix, network }) => {
79
79
  signerType === this.type &&
@@ -118,7 +118,7 @@ export async function reduceAsync<T, V>(
118
118
  i: number,
119
119
  values: V[],
120
120
  ) => Promise<T | undefined | null | void> | T | undefined | null | void,
121
- init: T,
121
+ init: T | Promise<T>,
122
122
  ): Promise<T>;
123
123
  export async function reduceAsync<T, V>(
124
124
  values: (V | T)[],
@@ -128,7 +128,7 @@ export async function reduceAsync<T, V>(
128
128
  i: number,
129
129
  values: (V | T)[],
130
130
  ) => Promise<T | undefined | null | void> | T | undefined | null | void,
131
- init?: T,
131
+ init?: T | Promise<T>,
132
132
  ): Promise<T> {
133
133
  if (init === undefined) {
134
134
  if (values.length === 0) {