@ckb-ccc/lumos-patches 0.0.6-alpha.0 → 0.0.8-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.
package/README.md CHANGED
@@ -21,11 +21,13 @@
21
21
  </p>
22
22
 
23
23
  <p align="center">
24
- "Common Chains Connector" is where CCC begins.
24
+ "CCC - CKBers' Codebase" is the next step of "Common Chains Connector".
25
25
  <br />
26
- CCC helps you to interoperate wallets from different chain ecosystems with CKB,
26
+ Empower yourself with CCC to discover the unlimited potential of CKB.
27
27
  <br />
28
- fully enabling CKB's cryptographic freedom power.
28
+ Interoperate with wallets from different chain ecosystems.
29
+ <br />
30
+ Fully enabling CKB's Turing completeness and cryptographic freedom power.
29
31
  </p>
30
32
 
31
33
  ## Preview
@@ -36,7 +38,7 @@
36
38
  </a>
37
39
  </p>
38
40
 
39
- This project is still under active development, and we are looking forward to your feedback. [Try its demo now here](https://ckbccc-demo.vercel.app/).
41
+ This project is still under active development, and we are looking forward to your feedback. [Try its demo now here](https://ckbccc-demo.vercel.app/). It showcases how to use CCC for some basic scenarios in CKB.
40
42
 
41
43
  <h3 align="center">
42
44
  Read more about CCC on its <a href="https://github.com/ckb-ecofund/ccc">GitHub Repo</a>.
@@ -1,15 +1,19 @@
1
- import { LockScriptInfo } from "@ckb-lumos/common-scripts";
2
1
  import { CellDep, Script } from "@ckb-lumos/base";
2
+ import { LockScriptInfo } from "@ckb-lumos/common-scripts";
3
3
  /**
4
4
  * Generates custom lock script information.
5
5
  * @param {string} codeHash - The code hash of the custom script.
6
6
  * @param {CellDep[]} cellDeps - The cell dependencies for the custom script.
7
7
  * @returns {LockScriptInfo} The lock script information.
8
8
  */
9
- export declare function generateScriptInfo(codeHash: string, cellDeps: CellDep[], cellDepTypes?: Script[]): LockScriptInfo;
9
+ export declare function generateScriptInfo(
10
+ codeHash: string,
11
+ cellDeps: CellDep[],
12
+ cellDepTypes?: Script[],
13
+ ): LockScriptInfo;
10
14
  /**
11
15
  * Generates default script information for CCC.
12
16
  * @returns {LockScriptInfo[]} An array of lock script information.
13
17
  */
14
18
  export declare function generateDefaultScriptInfos(): LockScriptInfo[];
15
- //# sourceMappingURL=default.d.ts.map
19
+ //# sourceMappingURL=default.d.ts.map
@@ -13,53 +13,59 @@ const utils_1 = require("./utils");
13
13
  * @returns {typeof JoyIDCellCollector} The CustomCellCollector class.
14
14
  */
15
15
  function generateCollectorClass(codeHash) {
16
+ /**
17
+ * Class representing a collector for custom script cells.
18
+ * @class
19
+ */
20
+ return class CustomCellCollector {
16
21
  /**
17
- * Class representing a collector for custom script cells.
18
- * @class
22
+ * Creates an instance of CustomCollector.
23
+ * @param {FromInfo} fromInfo - The information about the address to collect cells from.
24
+ * @param {CellProvider} cellProvider - The provider to collect cells from.
25
+ * @param {Object} options - The options for the collector.
26
+ * @param {QueryOptions} [options.queryOptions={}] - The query options for collecting cells.
27
+ * @param {Config} [options.config=getConfig()] - The Lumos configuration.
28
+ * @throws {Error} If cellProvider is not provided or fromInfo is not a string.
19
29
  */
20
- return class CustomCellCollector {
21
- /**
22
- * Creates an instance of CustomCollector.
23
- * @param {FromInfo} fromInfo - The information about the address to collect cells from.
24
- * @param {CellProvider} cellProvider - The provider to collect cells from.
25
- * @param {Object} options - The options for the collector.
26
- * @param {QueryOptions} [options.queryOptions={}] - The query options for collecting cells.
27
- * @param {Config} [options.config=getConfig()] - The Lumos configuration.
28
- * @throws {Error} If cellProvider is not provided or fromInfo is not a string.
29
- */
30
- constructor(fromInfo, cellProvider, { queryOptions = {}, config = (0, config_manager_1.getConfig)(), }) {
31
- if (!cellProvider) {
32
- throw new Error(`cellProvider is required when collecting cells`);
33
- }
34
- const { fromScript } = (0, common_scripts_1.parseFromInfo)(fromInfo, { config });
35
- this.fromScript = fromScript;
36
- if (!codec_1.bytes.equal(fromScript.codeHash, codeHash)) {
37
- this.cellCollector = undefined;
38
- return;
39
- }
40
- queryOptions = {
41
- ...queryOptions,
42
- lock: this.fromScript,
43
- type: queryOptions.type || "empty",
44
- data: queryOptions.data || "0x",
45
- };
46
- this.cellCollector = cellProvider.collector(queryOptions);
47
- }
48
- /**
49
- * Collects custom cells.
50
- * @async
51
- * @generator
52
- * @yields {Cell} The collected cell.
53
- */
54
- async *collect() {
55
- if (!this.cellCollector) {
56
- return;
57
- }
58
- for await (const inputCell of this.cellCollector.collect()) {
59
- yield inputCell;
60
- }
61
- }
62
- };
30
+ constructor(
31
+ fromInfo,
32
+ cellProvider,
33
+ { queryOptions = {}, config = (0, config_manager_1.getConfig)() },
34
+ ) {
35
+ if (!cellProvider) {
36
+ throw new Error(`cellProvider is required when collecting cells`);
37
+ }
38
+ const { fromScript } = (0, common_scripts_1.parseFromInfo)(fromInfo, {
39
+ config,
40
+ });
41
+ this.fromScript = fromScript;
42
+ if (!codec_1.bytes.equal(fromScript.codeHash, codeHash)) {
43
+ this.cellCollector = undefined;
44
+ return;
45
+ }
46
+ queryOptions = {
47
+ ...queryOptions,
48
+ lock: this.fromScript,
49
+ type: queryOptions.type || "empty",
50
+ data: queryOptions.data || "0x",
51
+ };
52
+ this.cellCollector = cellProvider.collector(queryOptions);
53
+ }
54
+ /**
55
+ * Collects custom cells.
56
+ * @async
57
+ * @generator
58
+ * @yields {Cell} The collected cell.
59
+ */
60
+ async *collect() {
61
+ if (!this.cellCollector) {
62
+ return;
63
+ }
64
+ for await (const inputCell of this.cellCollector.collect()) {
65
+ yield inputCell;
66
+ }
67
+ }
68
+ };
63
69
  }
64
70
  /**
65
71
  * Generates custom lock script information.
@@ -68,76 +74,89 @@ function generateCollectorClass(codeHash) {
68
74
  * @returns {LockScriptInfo} The lock script information.
69
75
  */
70
76
  function generateScriptInfo(codeHash, cellDeps, cellDepTypes = []) {
71
- return {
72
- codeHash: codeHash,
73
- hashType: "type",
74
- lockScriptInfo: {
75
- CellCollector: generateCollectorClass(codeHash),
76
- prepareSigningEntries: () => {
77
- throw new Error("Custom scripts doesn't support prepareSigningEntries.");
78
- },
79
- async setupInputCell(txSkeleton, inputCell, _, options = {}) {
80
- const fromScript = inputCell.cellOutput.lock;
81
- (0, utils_1.asserts)(codec_1.bytes.equal(fromScript.codeHash, codeHash), `The input script is not specified script`);
82
- // add inputCell to txSkeleton
83
- txSkeleton = txSkeleton.update("inputs", (inputs) => inputs.push(inputCell));
84
- const output = {
85
- cellOutput: {
86
- capacity: inputCell.cellOutput.capacity,
87
- lock: inputCell.cellOutput.lock,
88
- type: inputCell.cellOutput.type,
89
- },
90
- data: inputCell.data,
91
- };
92
- txSkeleton = txSkeleton.update("outputs", (outputs) => outputs.push(output));
93
- const since = options.since;
94
- if (since) {
95
- txSkeleton = txSkeleton.update("inputSinces", (inputSinces) => {
96
- return inputSinces.set(txSkeleton.get("inputs").size - 1, since);
97
- });
98
- }
99
- cellDeps.forEach((item) => {
100
- txSkeleton = (0, helper_1.addCellDep)(txSkeleton, item);
77
+ return {
78
+ codeHash: codeHash,
79
+ hashType: "type",
80
+ lockScriptInfo: {
81
+ CellCollector: generateCollectorClass(codeHash),
82
+ prepareSigningEntries: () => {
83
+ throw new Error(
84
+ "Custom scripts doesn't support prepareSigningEntries.",
85
+ );
86
+ },
87
+ async setupInputCell(txSkeleton, inputCell, _, options = {}) {
88
+ const fromScript = inputCell.cellOutput.lock;
89
+ (0, utils_1.asserts)(
90
+ codec_1.bytes.equal(fromScript.codeHash, codeHash),
91
+ `The input script is not specified script`,
92
+ );
93
+ // add inputCell to txSkeleton
94
+ txSkeleton = txSkeleton.update("inputs", (inputs) =>
95
+ inputs.push(inputCell),
96
+ );
97
+ const output = {
98
+ cellOutput: {
99
+ capacity: inputCell.cellOutput.capacity,
100
+ lock: inputCell.cellOutput.lock,
101
+ type: inputCell.cellOutput.type,
102
+ },
103
+ data: inputCell.data,
104
+ };
105
+ txSkeleton = txSkeleton.update("outputs", (outputs) =>
106
+ outputs.push(output),
107
+ );
108
+ const since = options.since;
109
+ if (since) {
110
+ txSkeleton = txSkeleton.update("inputSinces", (inputSinces) => {
111
+ return inputSinces.set(txSkeleton.get("inputs").size - 1, since);
112
+ });
113
+ }
114
+ cellDeps.forEach((item) => {
115
+ txSkeleton = (0, helper_1.addCellDep)(txSkeleton, item);
116
+ });
117
+ if (txSkeleton.cellProvider != null) {
118
+ await Promise.all(
119
+ cellDepTypes.map(async (type) => {
120
+ for await (const cell of txSkeleton.cellProvider
121
+ .collector({
122
+ type,
123
+ })
124
+ .collect()) {
125
+ txSkeleton = (0, helper_1.addCellDep)(txSkeleton, {
126
+ depType: "code",
127
+ outPoint: cell.outPoint,
101
128
  });
102
- if (txSkeleton.cellProvider != null) {
103
- await Promise.all(cellDepTypes.map(async (type) => {
104
- for await (const cell of txSkeleton
105
- .cellProvider.collector({
106
- type,
107
- })
108
- .collect()) {
109
- txSkeleton = (0, helper_1.addCellDep)(txSkeleton, {
110
- depType: "code",
111
- outPoint: cell.outPoint,
112
- });
113
- }
114
- }));
115
- }
116
- return txSkeleton;
117
- },
118
- },
119
- };
129
+ }
130
+ }),
131
+ );
132
+ }
133
+ return txSkeleton;
134
+ },
135
+ },
136
+ };
120
137
  }
121
138
  exports.generateScriptInfo = generateScriptInfo;
122
- const NOSTR_TESTNET_TYPE_HASH = "0x6ae5ee0cb887b2df5a9a18137315b9bdc55be8d52637b2de0624092d5f0c91d5";
139
+ const NOSTR_TESTNET_TYPE_HASH =
140
+ "0x6ae5ee0cb887b2df5a9a18137315b9bdc55be8d52637b2de0624092d5f0c91d5";
123
141
  const NOSTR_TESTNET_TYPE = {
124
- codeHash: "0x00000000000000000000000000000000000000000000000000545950455f4944",
125
- hashType: "type",
126
- args: "0x8dc56c6f35f0c535e23ded1629b1f20535477a1b43e59f14617d11e32c50e0aa",
142
+ codeHash:
143
+ "0x00000000000000000000000000000000000000000000000000545950455f4944",
144
+ hashType: "type",
145
+ args: "0x8dc56c6f35f0c535e23ded1629b1f20535477a1b43e59f14617d11e32c50e0aa",
127
146
  };
128
147
  /**
129
148
  * Generates default script information for CCC.
130
149
  * @returns {LockScriptInfo[]} An array of lock script information.
131
150
  */
132
151
  function generateDefaultScriptInfos() {
133
- return [
134
- generateScriptInfo((0, ckb_1.getJoyIDLockScript)(false).codeHash, [
135
- (0, ckb_1.getJoyIDCellDep)(false),
136
- ]),
137
- generateScriptInfo((0, ckb_1.getJoyIDLockScript)(true).codeHash, [
138
- (0, ckb_1.getJoyIDCellDep)(true),
139
- ]),
140
- generateScriptInfo(NOSTR_TESTNET_TYPE_HASH, [], [NOSTR_TESTNET_TYPE]),
141
- ];
152
+ return [
153
+ generateScriptInfo((0, ckb_1.getJoyIDLockScript)(false).codeHash, [
154
+ (0, ckb_1.getJoyIDCellDep)(false),
155
+ ]),
156
+ generateScriptInfo((0, ckb_1.getJoyIDLockScript)(true).codeHash, [
157
+ (0, ckb_1.getJoyIDCellDep)(true),
158
+ ]),
159
+ generateScriptInfo(NOSTR_TESTNET_TYPE_HASH, [], [NOSTR_TESTNET_TYPE]),
160
+ ];
142
161
  }
143
162
  exports.generateDefaultScriptInfos = generateDefaultScriptInfos;
@@ -1,3 +1,3 @@
1
1
  export * from "./default";
2
2
  export * from "./utils";
3
- //# sourceMappingURL=index.d.ts.map
3
+ //# sourceMappingURL=index.d.ts.map
@@ -1,18 +1,34 @@
1
1
  "use strict";
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);
15
- };
2
+ var __createBinding =
3
+ (this && this.__createBinding) ||
4
+ (Object.create
5
+ ? function (o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (
9
+ !desc ||
10
+ ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)
11
+ ) {
12
+ desc = {
13
+ enumerable: true,
14
+ get: function () {
15
+ return m[k];
16
+ },
17
+ };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
20
+ }
21
+ : function (o, m, k, k2) {
22
+ if (k2 === undefined) k2 = k;
23
+ o[k2] = m[k];
24
+ });
25
+ var __exportStar =
26
+ (this && this.__exportStar) ||
27
+ function (m, exports) {
28
+ for (var p in m)
29
+ if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p))
30
+ __createBinding(exports, m, p);
31
+ };
16
32
  Object.defineProperty(exports, "__esModule", { value: true });
17
33
  __exportStar(require("./default"), exports);
18
34
  __exportStar(require("./utils"), exports);
@@ -4,5 +4,8 @@
4
4
  * @param {string} [message="Assert failed"] - The error message to throw if the condition is false.
5
5
  * @throws {Error} If the condition is false.
6
6
  */
7
- export declare function asserts(condition: unknown, message?: string): asserts condition;
8
- //# sourceMappingURL=utils.d.ts.map
7
+ export declare function asserts(
8
+ condition: unknown,
9
+ message?: string,
10
+ ): asserts condition;
11
+ //# sourceMappingURL=utils.d.ts.map
@@ -8,8 +8,8 @@ exports.asserts = void 0;
8
8
  * @throws {Error} If the condition is false.
9
9
  */
10
10
  function asserts(condition, message = "Assert failed") {
11
- if (!condition) {
12
- throw new Error(message);
13
- }
11
+ if (!condition) {
12
+ throw new Error(message);
13
+ }
14
14
  }
15
15
  exports.asserts = asserts;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckb-ccc/lumos-patches",
3
- "version": "0.0.6-alpha.0",
3
+ "version": "0.0.8-alpha.3",
4
4
  "description": "Patches for using Lumos with CCC",
5
5
  "author": "Hanssen0 <hanssen0@hanssen0.com>",
6
6
  "license": "MIT",
@@ -44,5 +44,5 @@
44
44
  "@ckb-lumos/config-manager": "^0.22.2",
45
45
  "@joyid/ckb": "^0.0.11"
46
46
  },
47
- "gitHead": "2cbb4f450ed88e773a353a13ad006dbe6208f67f"
47
+ "gitHead": "bddfa3e5631252194dfde32b79ee589703f18afb"
48
48
  }