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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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 +20 -0
  13. package/dist/client/clientPublicTestnet.advanced.d.ts.map +1 -1
  14. package/dist/client/clientPublicTestnet.advanced.js +20 -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 +20 -0
  50. package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts.map +1 -1
  51. package/dist.commonjs/client/clientPublicTestnet.advanced.js +20 -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 +23 -0
  82. package/src/client/clientPublicTestnet.advanced.ts +23 -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
@@ -1,88 +1,19 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
4
15
  };
5
16
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.hashTypeId = exports.hashCkb = exports.Hasher = void 0;
7
- const blake2b_1 = __importDefault(require("blake2b"));
8
- const index_js_1 = require("../bytes/index.js");
9
- const index_js_2 = require("../ckb/index.js");
10
- const index_js_3 = require("../num/index.js");
11
- const advanced_js_1 = require("./advanced.js");
12
- class Hasher {
13
- /**
14
- * Creates an instance of Hasher.
15
- *
16
- * @param outLength - The output length of the hash in bytes. Default is 32.
17
- * @param personal - The personal string for the Blake2b algorithm. Default is CKB_BLAKE2B_PERSONAL.
18
- */
19
- constructor(outLength = 32, personal = advanced_js_1.CKB_BLAKE2B_PERSONAL) {
20
- this.hasher = (0, blake2b_1.default)(outLength, undefined, undefined, (0, index_js_1.bytesFrom)(personal, "utf8"));
21
- }
22
- /**
23
- * Updates the hash with the given data.
24
- *
25
- * @param data - The data to update the hash with.
26
- * @returns The current Hasher instance for chaining.
27
- *
28
- * @example
29
- * ```typescript
30
- * const hasher = new Hasher();
31
- * hasher.update("some data").update("more data");
32
- * const hash = hasher.digest();
33
- * ```
34
- */
35
- update(data) {
36
- this.hasher.update((0, index_js_1.bytesFrom)(data));
37
- return this;
38
- }
39
- /**
40
- * Finalizes the hash and returns the digest as a hexadecimal string.
41
- *
42
- * @returns The hexadecimal string representation of the hash.
43
- *
44
- * @example
45
- * ```typescript
46
- * const hasher = new Hasher();
47
- * hasher.update("some data");
48
- * const hash = hasher.digest(); // Outputs something like "0x..."
49
- * ```
50
- */
51
- digest() {
52
- return `0x${this.hasher.digest("hex")}`;
53
- }
54
- }
55
- exports.Hasher = Hasher;
56
- /**
57
- * Computes the CKB hash of the given data using the Blake2b algorithm.
58
- *
59
- * @param data - The data to hash.
60
- * @returns The hexadecimal string representation of the hash.
61
- *
62
- * @example
63
- * ```typescript
64
- * const hash = hashCkb("some data"); // Outputs something like "0x..."
65
- * ```
66
- */
67
- function hashCkb(...data) {
68
- const hasher = new Hasher();
69
- data.forEach((d) => hasher.update(d));
70
- return hasher.digest();
71
- }
72
- exports.hashCkb = hashCkb;
73
- /**
74
- * Computes the Type ID hash of the given data.
75
- *
76
- * @param cellInput - The first cell input of the transaction.
77
- * @param outputIndex - The output index of the Type ID cell.
78
- * @returns The hexadecimal string representation of the hash.
79
- *
80
- * @example
81
- * ```typescript
82
- * const hash = hashTypeId(cellInput, outputIndex); // Outputs something like "0x..."
83
- * ```
84
- */
85
- function hashTypeId(cellInputLike, outputIndex) {
86
- return hashCkb(index_js_2.CellInput.from(cellInputLike).toBytes(), (0, index_js_3.numLeToBytes)(outputIndex, 8));
87
- }
88
- exports.hashTypeId = hashTypeId;
17
+ __exportStar(require("./hasher.js"), exports);
18
+ __exportStar(require("./hasherCkb.js"), exports);
19
+ __exportStar(require("./hasherKeecak256.js"), exports);
@@ -9,11 +9,11 @@ export declare function keystoreEncrypt(privateKeyLike: BytesLike, chainCodeLike
9
9
  cipher: string;
10
10
  kdf: string;
11
11
  kdfparams: {
12
- dklen: number;
13
- salt: string;
14
12
  n: number;
15
13
  r: number;
16
14
  p: number;
15
+ dklen: number;
16
+ salt: string;
17
17
  };
18
18
  mac: string;
19
19
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/keystore/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,EAAE,SAAS,EAA0B,MAAM,mBAAmB,CAAC;AAgB7E,wBAAsB,eAAe,CACnC,cAAc,EAAE,SAAS,EACzB,aAAa,EAAE,SAAS,EACxB,QAAQ,EAAE,MAAM;;;;;;;;;;;;;;;;;;GAsCjB;AAED,wBAAsB,eAAe,CACnC,QAAQ,EAAE,OAAO,EACjB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC;IACT,UAAU,EAAE,KAAK,CAAC;IAClB,SAAS,EAAE,KAAK,CAAC;CAClB,CAAC,CAoED"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/keystore/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,EAAE,SAAS,EAA0B,MAAM,mBAAmB,CAAC;AAgB7E,wBAAsB,eAAe,CACnC,cAAc,EAAE,SAAS,EACzB,aAAa,EAAE,SAAS,EACxB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC;IACT,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE;QACN,UAAU,EAAE,MAAM,CAAC;QACnB,YAAY,EAAE;YACZ,EAAE,EAAE,MAAM,CAAC;SACZ,CAAC;QACF,MAAM,EAAE,MAAM,CAAC;QACf,GAAG,EAAE,MAAM,CAAC;QACZ,SAAS,EAAE;YACT,CAAC,EAAE,MAAM,CAAC;YACV,CAAC,EAAE,MAAM,CAAC;YACV,CAAC,EAAE,MAAM,CAAC;YACV,KAAK,EAAE,MAAM,CAAC;YACd,IAAI,EAAE,MAAM,CAAC;SACd,CAAC;QACF,GAAG,EAAE,MAAM,CAAC;KACb,CAAC;CACH,CAAC,CAqCD;AAED,wBAAsB,eAAe,CACnC,QAAQ,EAAE,OAAO,EACjB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC;IACT,UAAU,EAAE,KAAK,CAAC;IAClB,SAAS,EAAE,KAAK,CAAC;CAClB,CAAC,CAoED"}
@@ -1,7 +1,8 @@
1
1
  import { Address } from "../../address/index.js";
2
- import { BytesLike } from "../../bytes/index.js";
2
+ import { Bytes, BytesLike } from "../../bytes/index.js";
3
3
  import { Script, Transaction, TransactionLike } from "../../ckb/index.js";
4
- import { Hex } from "../../hex/index.js";
4
+ import { Hasher } from "../../hasher/index.js";
5
+ import { Hex, HexLike } from "../../hex/index.js";
5
6
  import { Signer, SignerSignType, SignerType } from "../signer/index.js";
6
7
  /**
7
8
  * An abstract class extending Signer for Ethereum Virtual Machine (EVM) based signing operations.
@@ -28,8 +29,11 @@ export declare abstract class SignerEvm extends Signer {
28
29
  * @returns A promise that resolves to an array of Address objects.
29
30
  */
30
31
  getAddressObjs(): Promise<Address[]>;
31
- _getOmniLockEvmAddressObj(account: string): Promise<Address>;
32
- _getOmniLockOldEvmAddressObj(account: string): Promise<Address>;
32
+ _getOmniLockAddresses(account: HexLike): Promise<Address[]>;
33
+ _getPWLockAddresses(account: HexLike): Promise<Address[]>;
34
+ _getOmniLockEvmAddressObj(account: HexLike): Promise<Address>;
35
+ _getOmniLockOldEvmAddressObj(account: HexLike): Promise<Address>;
36
+ _getPWLockEvmAddressObj(account: HexLike): Promise<Address | undefined>;
33
37
  /**
34
38
  * prepare a transaction before signing. This method is not implemented and should be overridden by subclasses.
35
39
  *
@@ -45,5 +49,10 @@ export declare abstract class SignerEvm extends Signer {
45
49
  */
46
50
  signOnlyTransaction(txLike: TransactionLike): Promise<Transaction>;
47
51
  _signOmniLockScriptForTransaction(tx: Transaction, script: Script, messageTransformer: (hash: string) => BytesLike): Promise<Transaction>;
52
+ _signPWLockScriptForTransaction(tx: Transaction, script: Script, messageTransformer: (hash: string) => BytesLike): Promise<Transaction>;
53
+ _signPersonalEvmForTransaction(tx: Transaction, script: Script, messageTransformer: (hash: string) => BytesLike, hasher?: Hasher): Promise<{
54
+ signature: Bytes;
55
+ position: number;
56
+ } | undefined>;
48
57
  }
49
58
  //# 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,wBAAwB,CAAC;AACjD,OAAO,EAAE,SAAS,EAA0B,MAAM,sBAAsB,CAAC;AACzE,OAAO,EACL,MAAM,EACN,WAAW,EACX,eAAe,EAEhB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,GAAG,EAAW,MAAM,oBAAoB,CAAC;AAGlD,OAAO,EAAE,MAAM,EAAE,c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AA8B,CAClC,EAAE,EAAE,WAAW,EACf,MAAM,EAAE,MAAM,EACd,kBAAkB,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,SAAS,EAC/C,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC;QAAE,SAAS,EAAE,KAAK,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC;CAe/D"}
@@ -5,20 +5,21 @@ const index_js_1 = require("../../address/index.js");
5
5
  const index_js_2 = require("../../bytes/index.js");
6
6
  const index_js_3 = require("../../ckb/index.js");
7
7
  const index_js_4 = require("../../client/index.js");
8
- const index_js_5 = require("../../hex/index.js");
9
- const index_js_6 = require("../../num/index.js");
10
- const index_js_7 = require("../../utils/index.js");
11
- const index_js_8 = require("../signer/index.js");
8
+ const index_js_5 = require("../../hasher/index.js");
9
+ const index_js_6 = require("../../hex/index.js");
10
+ const index_js_7 = require("../../num/index.js");
11
+ const index_js_8 = require("../../utils/index.js");
12
+ const index_js_9 = require("../signer/index.js");
12
13
  /**
13
14
  * An abstract class extending Signer for Ethereum Virtual Machine (EVM) based signing operations.
14
15
  * This class provides methods to get EVM account, internal address, and signing transactions.
15
16
  */
16
- class SignerEvm extends index_js_8.Signer {
17
+ class SignerEvm extends index_js_9.Signer {
17
18
  get type() {
18
- return index_js_8.SignerType.EVM;
19
+ return index_js_9.SignerType.EVM;
19
20
  }
20
21
  get signType() {
21
- return index_js_8.SignerSignType.EvmPersonal;
22
+ return index_js_9.SignerSignType.EvmPersonal;
22
23
  }
23
24
  /**
24
25
  * Gets the internal address, which is the EVM account in this case.
@@ -35,16 +36,37 @@ class SignerEvm extends index_js_8.Signer {
35
36
  */
36
37
  async getAddressObjs() {
37
38
  const account = await this.getEvmAccount();
38
- return [
39
- await this._getOmniLockEvmAddressObj(account),
40
- await this._getOmniLockOldEvmAddressObj(account),
41
- ];
39
+ const addresses = await Promise.all([
40
+ this._getOmniLockAddresses(account),
41
+ this._getPWLockAddresses(account),
42
+ ]);
43
+ return addresses.flat();
44
+ }
45
+ _getOmniLockAddresses(account) {
46
+ return Promise.all([
47
+ this._getOmniLockEvmAddressObj(account),
48
+ this._getOmniLockOldEvmAddressObj(account),
49
+ ]);
50
+ }
51
+ async _getPWLockAddresses(account) {
52
+ const addr = await this._getPWLockEvmAddressObj(account);
53
+ if (!addr) {
54
+ return [];
55
+ }
56
+ return [addr];
42
57
  }
43
58
  async _getOmniLockEvmAddressObj(account) {
44
- return index_js_1.Address.fromKnownScript(this.client, index_js_4.KnownScript.OmniLock, (0, index_js_5.hexFrom)([0x12, ...(0, index_js_2.bytesFrom)(account), 0x00]));
59
+ return index_js_1.Address.fromKnownScript(this.client, index_js_4.KnownScript.OmniLock, (0, index_js_6.hexFrom)([0x12, ...(0, index_js_2.bytesFrom)(account), 0x00]));
45
60
  }
46
61
  async _getOmniLockOldEvmAddressObj(account) {
47
- return index_js_1.Address.fromKnownScript(this.client, index_js_4.KnownScript.OmniLock, (0, index_js_5.hexFrom)([0x1, ...(0, index_js_2.bytesFrom)(account), 0x00]));
62
+ return index_js_1.Address.fromKnownScript(this.client, index_js_4.KnownScript.OmniLock, (0, index_js_6.hexFrom)([0x1, ...(0, index_js_2.bytesFrom)(account), 0x00]));
63
+ }
64
+ async _getPWLockEvmAddressObj(account) {
65
+ try {
66
+ return index_js_1.Address.fromKnownScript(this.client, index_js_4.KnownScript.PWLock, (0, index_js_6.hexFrom)((0, index_js_2.bytesFrom)(account)));
67
+ }
68
+ catch { }
69
+ return;
48
70
  }
49
71
  /**
50
72
  * prepare a transaction before signing. This method is not implemented and should be overridden by subclasses.
@@ -54,8 +76,17 @@ class SignerEvm extends index_js_8.Signer {
54
76
  */
55
77
  async prepareTransaction(txLike) {
56
78
  const tx = index_js_3.Transaction.from(txLike);
57
- await tx.addCellDepsOfKnownScripts(this.client, index_js_4.KnownScript.OmniLock);
58
- return (0, index_js_7.reduceAsync)(await this.getAddressObjs(), (tx, { script }) => tx.prepareSighashAllWitness(script, 85, this.client), tx);
79
+ if ((await tx.findInputIndexByLockId(await this.client.getKnownScript(index_js_4.KnownScript.OmniLock), this.client)) !== undefined) {
80
+ await tx.addCellDepsOfKnownScripts(this.client, index_js_4.KnownScript.OmniLock);
81
+ }
82
+ if ((await tx.findInputIndexByLockId(await this.client.getKnownScript(index_js_4.KnownScript.PWLock), this.client)) !== undefined) {
83
+ await tx.addCellDepsOfKnownScripts(this.client, index_js_4.KnownScript.PWLock);
84
+ }
85
+ const account = await this.getEvmAccount();
86
+ const omniLockAddresses = await this._getOmniLockAddresses(account);
87
+ const pwLockAddresses = await this._getPWLockAddresses(account);
88
+ const omniTx = (0, index_js_8.reduceAsync)(omniLockAddresses, (tx, { script }) => tx.prepareSighashAllWitness(script, 85, this.client), tx);
89
+ return (0, index_js_8.reduceAsync)(pwLockAddresses, (tx, { script }) => tx.prepareSighashAllWitness(script, 65, this.client), omniTx);
59
90
  }
60
91
  /**
61
92
  * Signs a transaction without modifying it.
@@ -70,21 +101,42 @@ class SignerEvm extends index_js_8.Signer {
70
101
  const { script: oldEvmScript } = await this._getOmniLockOldEvmAddressObj(account);
71
102
  tx = await this._signOmniLockScriptForTransaction(tx, evmScript, (hash) => `CKB transaction: ${hash}`);
72
103
  tx = await this._signOmniLockScriptForTransaction(tx, oldEvmScript, (hash) => (0, index_js_2.bytesFrom)(hash));
104
+ const pwAddress = await this._getPWLockEvmAddressObj(account);
105
+ if (pwAddress) {
106
+ tx = await this._signPWLockScriptForTransaction(tx, pwAddress.script, (hash) => (0, index_js_2.bytesFrom)(hash));
107
+ }
73
108
  return tx;
74
109
  }
75
110
  async _signOmniLockScriptForTransaction(tx, script, messageTransformer) {
76
- const info = await tx.getSignHashInfo(script, this.client);
111
+ const info = await this._signPersonalEvmForTransaction(tx, script, messageTransformer);
77
112
  if (!info) {
78
113
  return tx;
79
114
  }
80
- const signature = (0, index_js_2.bytesFrom)(await this.signMessageRaw(messageTransformer(info.message)));
81
- if (signature[signature.length - 1] >= 27) {
82
- signature[signature.length - 1] -= 27;
115
+ const witness = index_js_3.WitnessArgs.fromBytes(tx.witnesses[info.position]);
116
+ witness.lock = (0, index_js_6.hexFrom)((0, index_js_2.bytesConcat)((0, index_js_7.numToBytes)(5 * 4 + info.signature.length, 4), (0, index_js_7.numToBytes)(4 * 4, 4), (0, index_js_7.numToBytes)(5 * 4 + info.signature.length, 4), (0, index_js_7.numToBytes)(5 * 4 + info.signature.length, 4), (0, index_js_7.numToBytes)(info.signature.length, 4), info.signature));
117
+ tx.setWitnessArgsAt(info.position, witness);
118
+ return tx;
119
+ }
120
+ async _signPWLockScriptForTransaction(tx, script, messageTransformer) {
121
+ const info = await this._signPersonalEvmForTransaction(tx, script, messageTransformer, new index_js_5.HasherKeecak256());
122
+ if (!info) {
123
+ return tx;
83
124
  }
84
125
  const witness = index_js_3.WitnessArgs.fromBytes(tx.witnesses[info.position]);
85
- witness.lock = (0, index_js_5.hexFrom)((0, index_js_2.bytesConcat)((0, index_js_6.numToBytes)(5 * 4 + signature.length, 4), (0, index_js_6.numToBytes)(4 * 4, 4), (0, index_js_6.numToBytes)(5 * 4 + signature.length, 4), (0, index_js_6.numToBytes)(5 * 4 + signature.length, 4), (0, index_js_6.numToBytes)(signature.length, 4), signature));
126
+ witness.lock = (0, index_js_6.hexFrom)(info.signature);
86
127
  tx.setWitnessArgsAt(info.position, witness);
87
128
  return tx;
88
129
  }
130
+ async _signPersonalEvmForTransaction(tx, script, messageTransformer, hasher) {
131
+ const info = await tx.getSignHashInfo(script, this.client, hasher);
132
+ if (!info) {
133
+ return;
134
+ }
135
+ const signature = (0, index_js_2.bytesFrom)(await this.signMessageRaw(messageTransformer(info.message)));
136
+ if (signature[signature.length - 1] >= 27) {
137
+ signature[signature.length - 1] -= 27;
138
+ }
139
+ return { signature, position: info.position };
140
+ }
89
141
  }
90
142
  exports.SignerEvm = SignerEvm;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/signer/signer/index.ts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.
72
72
  * @returns The accumulated result.
73
73
  */
74
- export declare function reduceAsync<T, V>(values: V[], accumulator: (a: T, b: V, i: number, values: V[]) => Promise<T | undefined | null | void> | T | undefined | null | void, init: T): Promise<T>;
74
+ export declare function reduceAsync<T, V>(values: V[], accumulator: (a: T, b: V, i: number, values: V[]) => Promise<T | undefined | null | void> | T | undefined | null | void, init: T | Promise<T>): Promise<T>;
75
75
  export declare function isWebview(userAgent: string): boolean;
76
76
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,EACxB,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAC1B,KAAK,EAAE,SAAS,GACf,SAAS,CAAC;AACb;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,GAAG,SAAS,CAAC;AAChF;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC;AACrE;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,EACxB,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAC1B,KAAK,EAAE,CAAC,GAAG,SAAS,GACnB,CAAC,GAAG,SAAS,CAAC;AACjB;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,EACxB,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAC1B,KAAK,EAAE,CAAC,GAAG,IAAI,GACd,CAAC,GAAG,SAAS,CAAC;AACj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AM,EAAE,CAAC,EAAE,EACX,WAAW,EAAE,CACX,CAAC,EAAE,CAAC,EACJ,CAAC,EAAE,CAAC,KACD,OAAO,CAAC,CAAC,GAAG,SAAS,GAAG,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,SAAS,GAAG,IAAI,GAAG,IAAI,GACtE,OAAO,CAAC,CAAC,CAAC,CAAC;AACd;;;;;;;GAOG;AACH,wBAAsB,WAAW,CAAC,CAAC,EAAE,CAAC,EACpC,MAAM,EAAE,CAAC,EAAE,EACX,WAAW,EAAE,CACX,CAAC,EAAE,CAAC,EACJ,CAAC,EAAE,CAAC,EACJ,CAAC,EAAE,MAAM,EACT,MAAM,EAAE,CAAC,EAAE,KACR,OAAO,CAAC,CAAC,GAAG,SAAS,GAAG,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,SAAS,GAAG,IAAI,GAAG,IAAI,EACvE,IAAI,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GACnB,OAAO,CAAC,CAAC,CAAC,CAAC;AA4Bd,wBAAgB,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAEpD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckb-ccc/core",
3
- "version": "0.0.11-alpha.3",
3
+ "version": "0.0.12-alpha.0",
4
4
  "description": "Core of CCC - CKBer's Codebase",
5
5
  "author": "Hanssen0 <hanssen0@hanssen0.com>",
6
6
  "license": "MIT",
@@ -65,10 +65,9 @@
65
65
  "abort-controller": "^3.0.0",
66
66
  "bech32": "^2.0.0",
67
67
  "bitcoinjs-message": "^2.2.0",
68
- "blake2b": "^2.1.4",
69
68
  "buffer": "^6.0.3",
70
69
  "cross-fetch": "^4.0.0",
71
70
  "ethers": "^6.13.1"
72
71
  },
73
- "gitHead": "235ba3c69a0a1098fcd741fafb4b8f32dcfbc2b5"
72
+ "gitHead": "171a9941a56575dd5db2e3fad21d04bff8ec3fc5"
74
73
  }
@@ -94,7 +94,7 @@ export class Address {
94
94
  client: Client,
95
95
  script: KnownScript,
96
96
  args: HexLike,
97
- ) {
97
+ ): Promise<Address> {
98
98
  return Address.from({
99
99
  script: await Script.fromKnownScript(client, script, args),
100
100
  prefix: client.addressPrefix,
package/src/ckb/script.ts CHANGED
@@ -180,7 +180,7 @@ export class Script {
180
180
  * @returns An object representing the script in molecule data format.
181
181
  */
182
182
 
183
- _toMolData() {
183
+ _toMolData(): mol.ScriptType {
184
184
  return {
185
185
  codeHash: bytesFrom(this.codeHash),
186
186
  hashType: hashTypeToBytes(this.hashType),
@@ -7,7 +7,7 @@ import {
7
7
  fixedPointFrom,
8
8
  fixedPointToString,
9
9
  } from "../fixedPoint/index.js";
10
- import { Hasher, hashCkb } from "../hasher/index.js";
10
+ import { Hasher, HasherCkb, hashCkb } from "../hasher/index.js";
11
11
  import { Hex, HexLike, hexFrom } from "../hex/index.js";
12
12
  import {
13
13
  Num,
@@ -148,7 +148,7 @@ export class OutPoint {
148
148
  * @returns An object representing the outpoint in molecule data format.
149
149
  */
150
150
 
151
- _toMolData() {
151
+ _toMolData(): mol.OutPointType {
152
152
  return {
153
153
  txHash: bytesFrom(this.txHash),
154
154
  index: numToBytes(this.index, 4),
@@ -282,7 +282,7 @@ export class CellOutput {
282
282
  * @returns An object representing the cell output in molecule data format.
283
283
  */
284
284
 
285
- _toMolData() {
285
+ _toMolData(): mol.CellOutputType {
286
286
  return {
287
287
  capacity: numToBytes(this.capacity, 8),
288
288
  lock: this.lock._toMolData(),
@@ -488,7 +488,7 @@ export class CellInput {
488
488
  * @returns An object representing the cell input in molecule data format.
489
489
  */
490
490
 
491
- _toMolData() {
491
+ _toMolData(): mol.CellInputType {
492
492
  return {
493
493
  previousOutput: this.previousOutput._toMolData(),
494
494
  since: numToBytes(this.since, 8),
@@ -599,7 +599,7 @@ export class CellDep {
599
599
  * @returns An object representing the cell dependency in molecule data format.
600
600
  */
601
601
 
602
- _toMolData() {
602
+ _toMolData(): mol.CellDepType {
603
603
  return {
604
604
  outPoint: this.outPoint._toMolData(),
605
605
  depType: depTypeToBytes(this.depType),
@@ -716,7 +716,7 @@ export class WitnessArgs {
716
716
  * @returns An object representing the witness arguments in molecule data format.
717
717
  */
718
718
 
719
- _toMolData() {
719
+ _toMolData(): mol.WitnessArgsType {
720
720
  return {
721
721
  lock: apply(bytesFrom, this.lock),
722
722
  inputType: apply(bytesFrom, this.inputType),
@@ -765,7 +765,7 @@ export class WitnessArgs {
765
765
  }
766
766
  }
767
767
 
768
- export function udtBalanceFrom(dataLike: BytesLike) {
768
+ export function udtBalanceFrom(dataLike: BytesLike): Num {
769
769
  const data = bytesFrom(dataLike).slice(0, 16);
770
770
  if (data.length !== 16) {
771
771
  throw new Error("Invalid UDT cell data");
@@ -1028,7 +1028,7 @@ export class Transaction {
1028
1028
  * ```
1029
1029
  */
1030
1030
 
1031
- hash() {
1031
+ hash(): Hex {
1032
1032
  return hashCkb(this.rawToBytes());
1033
1033
  }
1034
1034
 
@@ -1070,10 +1070,10 @@ export class Transaction {
1070
1070
  async getSignHashInfo(
1071
1071
  scriptLike: ScriptLike,
1072
1072
  client: Client,
1073
+ hasher: Hasher = new HasherCkb(),
1073
1074
  ): Promise<{ message: Hex; position: number } | undefined> {
1074
1075
  const script = Script.from(scriptLike);
1075
1076
  let position = -1;
1076
- const hasher = new Hasher();
1077
1077
  hasher.update(this.hash());
1078
1078
 
1079
1079
  for (let i = 0; i < this.witnesses.length; i += 1) {
@@ -1111,6 +1111,40 @@ export class Transaction {
1111
1111
  };
1112
1112
  }
1113
1113
 
1114
+ /**
1115
+ * Find the first occurrence of a input with the specified lock id
1116
+ *
1117
+ * @param scriptIdLike - The script associated with the transaction, represented as a ScriptLike object without args.
1118
+ * @param client - The client for complete extra infos in the transaction.
1119
+ * @returns A promise that resolves to the found index
1120
+ *
1121
+ * @example
1122
+ * ```typescript
1123
+ * const index = await tx.findInputIndexByLockId(scriptIdLike, client);
1124
+ * ```
1125
+ */
1126
+ async findInputIndexByLockId(
1127
+ scriptLike: Pick<ScriptLike, "codeHash" | "hashType">,
1128
+ client: Client,
1129
+ ): Promise<number | undefined> {
1130
+ const script = Script.from({ ...scriptLike, args: "0x" });
1131
+
1132
+ for (let i = 0; i < this.inputs.length; i += 1) {
1133
+ const input = this.inputs[i];
1134
+ await input.completeExtraInfos(client);
1135
+ if (!input.cellOutput) {
1136
+ throw new Error("Unable to complete input");
1137
+ }
1138
+
1139
+ if (
1140
+ script.codeHash === input.cellOutput.lock.codeHash &&
1141
+ script.hashType === input.cellOutput.lock.hashType
1142
+ ) {
1143
+ return i;
1144
+ }
1145
+ }
1146
+ }
1147
+
1114
1148
  /**
1115
1149
  * Find the first occurrence of a input with the specified lock
1116
1150
  *
@@ -57,7 +57,7 @@ export function filterScript(
57
57
  export function filterNumByRange(
58
58
  lengthLike: NumLike,
59
59
  range: [NumLike, NumLike] | undefined,
60
- ) {
60
+ ): boolean {
61
61
  if (!range) {
62
62
  return true;
63
63
  }
@@ -36,6 +36,7 @@ export enum KnownScript {
36
36
  XUdt = "XUdt",
37
37
  JoyId = "JoyId",
38
38
  COTA = "COTA",
39
+ PWLock = "PWLock",
39
40
  OmniLock = "OmniLock",
40
41
  NostrLock = "NostrLock",
41
42
  UniqueType = "UniqueType",
@@ -114,6 +114,29 @@ export const MAINNET_SCRIPTS: Record<
114
114
  },
115
115
  ],
116
116
  },
117
+ [KnownScript.PWLock]: {
118
+ codeHash:
119
+ "0xbf43c3602455798c1a61a596e0d95278864c552fafe231c063b3fabf97a8febc",
120
+ hashType: "type",
121
+ cellDeps: [
122
+ {
123
+ cellDep: {
124
+ outPoint: {
125
+ txHash:
126
+ "0x1d60cb8f4666e039f418ea94730b1a8c5aa0bf2f7781474406387462924d15d4",
127
+ index: 0,
128
+ },
129
+ depType: "code",
130
+ },
131
+ type: {
132
+ codeHash:
133
+ "0x00000000000000000000000000000000000000000000000000545950455f4944",
134
+ hashType: "type",
135
+ args: "0x42ade2f25eb938b5dbfd3d8f07b8b07aa593d848e7ff14bdfbbea5aeb6175261",
136
+ },
137
+ },
138
+ ],
139
+ },
117
140
  [KnownScript.OmniLock]: {
118
141
  codeHash:
119
142
  "0x9b819793a64463aed77c615d6cb226eea5487ccfc0783043a587254cda2b6f26",
@@ -119,6 +119,29 @@ export const TESTNET_SCRIPTS: Record<
119
119
  },
120
120
  ],
121
121
  },
122
+ [KnownScript.PWLock]: {
123
+ codeHash:
124
+ "0x58c5f491aba6d61678b7cf7edf4910b1f5e00ec0cde2f42e0abb4fd9aff25a63",
125
+ hashType: "type",
126
+ cellDeps: [
127
+ {
128
+ cellDep: {
129
+ outPoint: {
130
+ txHash:
131
+ "0x57a62003daeab9d54aa29b944fc3b451213a5ebdf2e232216a3cfed0dde61b38",
132
+ index: 0,
133
+ },
134
+ depType: "code",
135
+ },
136
+ type: {
137
+ codeHash:
138
+ "0x00000000000000000000000000000000000000000000000000545950455f4944",
139
+ hashType: "type",
140
+ args: "0xf6d90bfe3041d0fd7e01c45770241697f5f837974bd6ae1672a7ec0f9f523268",
141
+ },
142
+ },
143
+ ],
144
+ },
122
145
  [KnownScript.OmniLock]: {
123
146
  codeHash:
124
147
  "0xf329effd1c475a2978453c8600e1eaf0bc2087ee093c3ee64cc96ec6847752cb",
@@ -63,7 +63,7 @@ export abstract class ClientJsonRpc extends Client {
63
63
  * @returns The URL of the JSON-RPC server.
64
64
  */
65
65
 
66
- get url() {
66
+ get url(): string {
67
67
  return this.url_;
68
68
  }
69
69
 
@@ -206,7 +206,7 @@ export abstract class ClientJsonRpc extends Client {
206
206
  rpcMethod: string,
207
207
  inTransformers: (((_: any) => unknown) | undefined)[],
208
208
  outTransformer?: (_: any) => unknown,
209
- ) {
209
+ ): (...req: unknown[]) => Promise<unknown> {
210
210
  return async (...req: unknown[]) => {
211
211
  const payload = ClientJsonRpc.buildPayload(
212
212
  rpcMethod,
@@ -234,7 +234,7 @@ export abstract class ClientJsonRpc extends Client {
234
234
  * @throws Will throw an error if the response ID does not match the request ID, or if the response contains an error.
235
235
  */
236
236
 
237
- async send(payload: JsonRpcPayload) {
237
+ async send(payload: JsonRpcPayload): Promise<unknown> {
238
238
  const aborter = new AbortController();
239
239
  const abortTimer = setTimeout(() => aborter.abort(), this.timeout);
240
240
 
@@ -76,11 +76,11 @@ export function fixedPointFrom(val: FixedPointLike, decimals = 8): FixedPoint {
76
76
  * Represents the fixed point value of zero as a bigint.
77
77
  */
78
78
 
79
- export const Zero = 0n;
79
+ export const Zero: FixedPoint = 0n;
80
80
 
81
81
  /**
82
82
  * Represents the fixed point value of one as a FixedPoint (bigint).
83
83
  * Equivalent to 1 in fixed-point representation with default decimals (8).
84
84
  */
85
85
 
86
- export const One = fixedPointFrom("1");
86
+ export const One: FixedPoint = fixedPointFrom("1");