@ckb-ccc/lumos-patches 1.0.32 → 1.1.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # @ckb-ccc/lumos-patches
2
2
 
3
+ ## 1.1.0
4
+ ### Minor Changes
5
+
6
+
7
+
8
+ - [#381](https://github.com/ckb-devrel/ccc/pull/381) [`46cc045`](https://github.com/ckb-devrel/ccc/commit/46cc045a3eefe9ba6625482dc7f740a0c59c99d4) Thanks [@Hanssen0](https://github.com/Hanssen0)! - chore: bump packages
9
+
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies [[`46cc045`](https://github.com/ckb-devrel/ccc/commit/46cc045a3eefe9ba6625482dc7f740a0c59c99d4)]:
14
+ - @ckb-ccc/core@1.14.0
15
+
16
+ ## 1.0.33
17
+ ### Patch Changes
18
+
19
+
20
+
21
+ - [#379](https://github.com/ckb-devrel/ccc/pull/379) [`f01a05b`](https://github.com/ckb-devrel/ccc/commit/f01a05bab332d9f4e0cf7f84aecfd688f8e9f346) Thanks [@Hanssen0](https://github.com/Hanssen0)! - chore: bump pnpm to v11.8.0
22
+
23
+ - Updated dependencies [[`1148a5c`](https://github.com/ckb-devrel/ccc/commit/1148a5c403cde985fb4ba713ccfa0c163d287174), [`bf0f8d8`](https://github.com/ckb-devrel/ccc/commit/bf0f8d8ca011e627821445a10bc38519510e5b9d), [`a803d5f`](https://github.com/ckb-devrel/ccc/commit/a803d5fba8d0e082c6aba14db156856025402e72), [`bf0f8d8`](https://github.com/ckb-devrel/ccc/commit/bf0f8d8ca011e627821445a10bc38519510e5b9d), [`6727ffe`](https://github.com/ckb-devrel/ccc/commit/6727ffe05f60e6bfb2060a565c19acb0fd0f375e), [`f01a05b`](https://github.com/ckb-devrel/ccc/commit/f01a05bab332d9f4e0cf7f84aecfd688f8e9f346), [`a526890`](https://github.com/ckb-devrel/ccc/commit/a5268909ea9d61c4e2f5187a43e2318327b27cae), [`4bb3d9d`](https://github.com/ckb-devrel/ccc/commit/4bb3d9d2ef36b3ee8820036625abd9befb1980c4), [`9f7ecb6`](https://github.com/ckb-devrel/ccc/commit/9f7ecb6ab8db9c6866dad029f2888e1e5cfcbe7d)]:
24
+ - @ckb-ccc/core@1.13.0
25
+
3
26
  ## 1.0.32
4
27
  ### Patch Changes
5
28
 
@@ -0,0 +1,32 @@
1
+ import { ccc } from "@ckb-ccc/core";
2
+ import { LockScriptInfo } from "@ckb-lumos/common-scripts";
3
+
4
+ //#region src/default.d.ts
5
+ /**
6
+ * Generates custom lock script information.
7
+ * @public
8
+ *
9
+ * @param codeHash - The code hash of the custom script.
10
+ * @param cellDeps - The cell dependencies for the custom script.
11
+ * @returns The lock script information.
12
+ */
13
+ declare function generateScriptInfo(codeHash: string, cellDeps: ccc.CellDepInfoLike[], dummyLockLength: number): LockScriptInfo;
14
+ /**
15
+ * Generates default script information for CCC.
16
+ * @returns An array of lock script information.
17
+ */
18
+ declare function generateDefaultScriptInfos(): LockScriptInfo[];
19
+ //#endregion
20
+ //#region src/utils.d.ts
21
+ /**
22
+ * Asserts that a condition is true, throwing an error if it is not.
23
+ * @public
24
+ *
25
+ * @param condition - The condition to assert.
26
+ * @param [message="Assert failed"] - The error message to throw if the condition is false.
27
+ * @throws {Error} If the condition is false.
28
+ */
29
+ declare function asserts(condition: unknown, message?: string): asserts condition;
30
+ //#endregion
31
+ export { asserts, generateDefaultScriptInfos, generateScriptInfo };
32
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/default.ts","../src/utils.ts"],"mappings":";;;;;;AA2HA;;;;;;iBAAgB,kBAAA,CACd,QAAA,UACA,QAAA,EAAU,GAAA,CAAI,eAAA,IACd,eAAA,WACC,cAAc;;;;;iBAyGD,0BAAA,IAA8B,cAAc;;;;;;;AA7G5D;;;;iBCnHgB,OAAA,CACd,SAAA,WACA,OAAA,oBACS,SAAA"}
package/dist/index.mjs ADDED
@@ -0,0 +1,2 @@
1
+ import{ccc as e}from"@ckb-ccc/core";import{cccA as t}from"@ckb-ccc/core/advanced";import{bytes as n}from"@ckb-lumos/codec";import{parseFromInfo as r}from"@ckb-lumos/common-scripts";import{getConfig as i}from"@ckb-lumos/config-manager";function a(e,t=`Assert failed`){if(!e)throw Error(t)}function o(t,n){return t.get(`cellDeps`).find(t=>t.depType===n.depType&&e.OutPoint.from(t.outPoint).eq(e.OutPoint.from(n.outPoint)))||(t=t.update(`cellDeps`,e=>e.push({outPoint:n.outPoint,depType:n.depType}))),t}function s(e){return class{constructor(t,a,{queryOptions:o={},config:s=i()}){if(!a)throw Error(`cellProvider is required when collecting cells`);let{fromScript:c}=r(t,{config:s});if(this.fromScript=c,!n.equal(c.codeHash,e)){this.cellCollector=void 0;return}o={...o,lock:this.fromScript,type:o.type||`empty`,data:o.data||`0x`},this.cellCollector=a.collector(o)}async*collect(){if(this.cellCollector)for await(let e of this.cellCollector.collect())yield e}}}function c(t,r,i){return{codeHash:t,hashType:`type`,lockScriptInfo:{CellCollector:s(t),prepareSigningEntries:()=>{throw Error(`Custom scripts doesn't support prepareSigningEntries.`)},async setupInputCell(s,c,l,u={}){let d=c.cellOutput.lock;a(n.equal(d.codeHash,t),`The input script is not specified script`),s=s.update(`inputs`,e=>e.push(c));let f={cellOutput:{capacity:c.cellOutput.capacity,lock:c.cellOutput.lock,type:c.cellOutput.type},data:c.data};s=s.update(`outputs`,e=>e.push(f));let p=u.since;p&&(s=s.update(`inputSinces`,e=>e.set(s.get(`inputs`).size-1,p))),await Promise.all(r.map(async t=>{let n=e.CellDepInfo.from(t);if(n.type&&s.cellProvider!=null)for await(let e of s.cellProvider.collector({type:n.type}).collect())s=o(s,{depType:`code`,outPoint:e.outPoint});else s=o(s,{...n.cellDep,outPoint:{txHash:n.cellDep.outPoint.txHash,index:e.numToHex(n.cellDep.outPoint.index)}})}));let m=s.get(`inputs`).findIndex(t=>e.Script.from(t.cellOutput.lock).eq(e.Script.from(d)));return s=s.update(`witnesses`,t=>(t.get(m)&&(t=t.merge(Array.from(Array(m+1-t.size),()=>`0x`))),t.set(m,e.hexFrom(e.WitnessArgs.from({lock:Array.from(Array(i),()=>0)}).toBytes())))),s}}}}function l(){let n=t.MAINNET_SCRIPTS,r=t.TESTNET_SCRIPTS;return[[e.KnownScript.JoyId,1e3],[e.KnownScript.NostrLock,572],[e.KnownScript.PWLock,65]].map(([t,i])=>[c(e.hexFrom(r[t].codeHash),r[t].cellDeps,i),c(e.hexFrom(n[t].codeHash),n[t].cellDeps,i)]).flat()}export{a as asserts,l as generateDefaultScriptInfos,c as generateScriptInfo};
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/utils.ts","../src/default.ts"],"sourcesContent":["/**\n * Asserts that a condition is true, throwing an error if it is not.\n * @public\n *\n * @param condition - The condition to assert.\n * @param [message=\"Assert failed\"] - The error message to throw if the condition is false.\n * @throws {Error} If the condition is false.\n */\nexport function asserts(\n condition: unknown,\n message = \"Assert failed\",\n): asserts condition {\n if (!condition) {\n throw new Error(message);\n }\n}\n","import { ccc } from \"@ckb-ccc/core\";\nimport { cccA } from \"@ckb-ccc/core/advanced\";\nimport {\n Cell,\n CellCollector,\n CellDep,\n CellProvider,\n QueryOptions,\n Script,\n} from \"@ckb-lumos/base\";\nimport { bytes } from \"@ckb-lumos/codec\";\nimport {\n FromInfo,\n LockScriptInfo,\n parseFromInfo,\n} from \"@ckb-lumos/common-scripts\";\nimport { Config, getConfig } from \"@ckb-lumos/config-manager\";\nimport { TransactionSkeletonType } from \"@ckb-lumos/helpers\";\nimport { asserts } from \"./utils.js\";\n\nfunction addCellDep(\n txSkeleton: TransactionSkeletonType,\n newCellDep: CellDep,\n): TransactionSkeletonType {\n const cellDep = txSkeleton.get(\"cellDeps\").find((cellDep) => {\n return (\n cellDep.depType === newCellDep.depType &&\n ccc.OutPoint.from(cellDep.outPoint).eq(\n ccc.OutPoint.from(newCellDep.outPoint),\n )\n );\n });\n\n if (!cellDep) {\n txSkeleton = txSkeleton.update(\"cellDeps\", (cellDeps) => {\n return cellDeps.push({\n outPoint: newCellDep.outPoint,\n depType: newCellDep.depType,\n });\n });\n }\n\n return txSkeleton;\n}\n\n/**\n * Generates a class for collecting custom script cells.\n * @param codeHash - The code hash of the custom script.\n * @returns The CustomCellCollector class.\n */\nfunction generateCollectorClass(codeHash: string) {\n /**\n * Class representing a collector for custom script cells.\n */\n return class CustomCellCollector {\n readonly fromScript: Script;\n readonly cellCollector: CellCollector | undefined;\n\n /**\n * Creates an instance of CustomCollector.\n * @param fromInfo - The information about the address to collect cells from.\n * @param cellProvider - The provider to collect cells from.\n * @param options - The options for the collector.\n * @param] - The query options for collecting cells.\n * @param [options.config=getConfig()] - The Lumos configuration.\n * @throws {Error} If cellProvider is not provided or fromInfo is not a string.\n */\n constructor(\n fromInfo: FromInfo,\n cellProvider: CellProvider,\n {\n queryOptions = {},\n config = getConfig(),\n }: { queryOptions?: QueryOptions; config?: Config },\n ) {\n if (!cellProvider) {\n throw new Error(`cellProvider is required when collecting cells`);\n }\n\n const { fromScript } = parseFromInfo(fromInfo, { config });\n this.fromScript = fromScript;\n\n if (!bytes.equal(fromScript.codeHash, codeHash)) {\n this.cellCollector = undefined;\n return;\n }\n\n queryOptions = {\n ...queryOptions,\n lock: this.fromScript,\n type: queryOptions.type || \"empty\",\n data: queryOptions.data || \"0x\",\n };\n\n this.cellCollector = cellProvider.collector(queryOptions);\n }\n\n /**\n * Collects custom cells.\n * @async\n * @generator\n * @yields {Cell} The collected cell.\n */\n async *collect(): AsyncGenerator<Cell> {\n if (!this.cellCollector) {\n return;\n }\n\n for await (const inputCell of this.cellCollector.collect()) {\n yield inputCell;\n }\n }\n };\n}\n\n/**\n * Generates custom lock script information.\n * @public\n *\n * @param codeHash - The code hash of the custom script.\n * @param cellDeps - The cell dependencies for the custom script.\n * @returns The lock script information.\n */\nexport function generateScriptInfo(\n codeHash: string,\n cellDeps: ccc.CellDepInfoLike[],\n dummyLockLength: number,\n): LockScriptInfo {\n return {\n codeHash: codeHash,\n hashType: \"type\",\n lockScriptInfo: {\n CellCollector: generateCollectorClass(codeHash),\n prepareSigningEntries: () => {\n throw new Error(\n \"Custom scripts doesn't support prepareSigningEntries.\",\n );\n },\n async setupInputCell(txSkeleton, inputCell, _, options = {}) {\n const fromScript = inputCell.cellOutput.lock;\n asserts(\n bytes.equal(fromScript.codeHash, codeHash),\n `The input script is not specified script`,\n );\n // add inputCell to txSkeleton\n txSkeleton = txSkeleton.update(\"inputs\", (inputs) =>\n inputs.push(inputCell),\n );\n\n const output: Cell = {\n cellOutput: {\n capacity: inputCell.cellOutput.capacity,\n lock: inputCell.cellOutput.lock,\n type: inputCell.cellOutput.type,\n },\n data: inputCell.data,\n };\n\n txSkeleton = txSkeleton.update(\"outputs\", (outputs) =>\n outputs.push(output),\n );\n\n const since = options.since;\n if (since) {\n txSkeleton = txSkeleton.update(\"inputSinces\", (inputSinces) => {\n return inputSinces.set(txSkeleton.get(\"inputs\").size - 1, since);\n });\n }\n\n await Promise.all(\n cellDeps.map(async (itemLike) => {\n const item = ccc.CellDepInfo.from(itemLike);\n if (item.type && txSkeleton.cellProvider != null) {\n for await (const cell of txSkeleton.cellProvider\n .collector({\n type: item.type,\n })\n .collect()) {\n txSkeleton = addCellDep(txSkeleton, {\n depType: \"code\",\n outPoint: cell.outPoint!,\n });\n }\n } else {\n txSkeleton = addCellDep(txSkeleton, {\n ...item.cellDep,\n outPoint: {\n txHash: item.cellDep.outPoint.txHash,\n index: ccc.numToHex(item.cellDep.outPoint.index),\n },\n });\n }\n }),\n );\n\n const firstIndex = txSkeleton\n .get(\"inputs\")\n .findIndex((input) =>\n ccc.Script.from(input.cellOutput.lock).eq(\n ccc.Script.from(fromScript),\n ),\n );\n txSkeleton = txSkeleton.update(\"witnesses\", (witnesses) => {\n if (witnesses.get(firstIndex)) {\n witnesses = witnesses.merge(\n Array.from(\n new Array(firstIndex + 1 - witnesses.size),\n () => \"0x\",\n ),\n );\n }\n\n return witnesses.set(\n firstIndex,\n ccc.hexFrom(\n ccc.WitnessArgs.from({\n lock: Array.from(new Array(dummyLockLength), () => 0),\n }).toBytes(),\n ),\n );\n });\n\n return txSkeleton;\n },\n },\n };\n}\n\n/**\n * Generates default script information for CCC.\n * @returns An array of lock script information.\n */\nexport function generateDefaultScriptInfos(): LockScriptInfo[] {\n const mainnet = cccA.MAINNET_SCRIPTS;\n const testnet = cccA.TESTNET_SCRIPTS;\n\n return (\n [\n [ccc.KnownScript.JoyId, 1000],\n [ccc.KnownScript.NostrLock, 572],\n [ccc.KnownScript.PWLock, 65],\n ] as [ccc.KnownScript, number][]\n )\n .map(([script, dummyLockLength]) => [\n generateScriptInfo(\n ccc.hexFrom(testnet[script].codeHash),\n testnet[script].cellDeps,\n dummyLockLength,\n ),\n generateScriptInfo(\n ccc.hexFrom(mainnet[script]!.codeHash),\n mainnet[script]!.cellDeps,\n dummyLockLength,\n ),\n ])\n .flat();\n}\n"],"mappings":"2OAQA,SAAgB,EACd,EACA,EAAU,gBACS,CACnB,GAAI,CAAC,EACH,MAAU,MAAM,CAAO,CAE3B,CCKA,SAAS,EACP,EACA,EACyB,CAmBzB,OAlBgB,EAAW,IAAI,UAAU,CAAC,CAAC,KAAM,GAE7C,EAAQ,UAAY,EAAW,SAC/B,EAAI,SAAS,KAAK,EAAQ,QAAQ,CAAC,CAAC,GAClC,EAAI,SAAS,KAAK,EAAW,QAAQ,CACvC,CAIO,IACT,EAAa,EAAW,OAAO,WAAa,GACnC,EAAS,KAAK,CACnB,SAAU,EAAW,SACrB,QAAS,EAAW,OACtB,CAAC,CACF,GAGI,CACT,CAOA,SAAS,EAAuB,EAAkB,CAIhD,OAAO,KAA0B,CAa/B,YACE,EACA,EACA,CACE,eAAe,CAAC,EAChB,SAAS,EAAU,GAErB,CACA,GAAI,CAAC,EACH,MAAU,MAA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,32 @@
1
- export * from "./default.js";
2
- export * from "./utils.js";
1
+ import { ccc } from "@ckb-ccc/core";
2
+ import { LockScriptInfo } from "@ckb-lumos/common-scripts";
3
+
4
+ //#region src/default.d.ts
5
+ /**
6
+ * Generates custom lock script information.
7
+ * @public
8
+ *
9
+ * @param codeHash - The code hash of the custom script.
10
+ * @param cellDeps - The cell dependencies for the custom script.
11
+ * @returns The lock script information.
12
+ */
13
+ declare function generateScriptInfo(codeHash: string, cellDeps: ccc.CellDepInfoLike[], dummyLockLength: number): LockScriptInfo;
14
+ /**
15
+ * Generates default script information for CCC.
16
+ * @returns An array of lock script information.
17
+ */
18
+ declare function generateDefaultScriptInfos(): LockScriptInfo[];
19
+ //#endregion
20
+ //#region src/utils.d.ts
21
+ /**
22
+ * Asserts that a condition is true, throwing an error if it is not.
23
+ * @public
24
+ *
25
+ * @param condition - The condition to assert.
26
+ * @param [message="Assert failed"] - The error message to throw if the condition is false.
27
+ * @throws {Error} If the condition is false.
28
+ */
29
+ declare function asserts(condition: unknown, message?: string): asserts condition;
30
+ //#endregion
31
+ export { asserts, generateDefaultScriptInfos, generateScriptInfo };
3
32
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/default.ts","../src/utils.ts"],"mappings":";;;;;;AA2HA;;;;;;iBAAgB,kBAAA,CACd,QAAA,UACA,QAAA,EAAU,GAAA,CAAI,eAAA,IACd,eAAA,WACC,cAAc;;;;;iBAyGD,0BAAA,IAA8B,cAAc;;;;;;;AA7G5D;;;;iBCnHgB,OAAA,CACd,SAAA,WACA,OAAA,oBACS,SAAA"}
@@ -1,18 +1,2 @@
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
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./default.js"), exports);
18
- __exportStar(require("./utils.js"), exports);
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@ckb-ccc/core"),t=require("@ckb-ccc/core/advanced"),n=require("@ckb-lumos/codec"),r=require("@ckb-lumos/common-scripts"),i=require("@ckb-lumos/config-manager");function a(e,t=`Assert failed`){if(!e)throw Error(t)}function o(t,n){return t.get(`cellDeps`).find(t=>t.depType===n.depType&&e.ccc.OutPoint.from(t.outPoint).eq(e.ccc.OutPoint.from(n.outPoint)))||(t=t.update(`cellDeps`,e=>e.push({outPoint:n.outPoint,depType:n.depType}))),t}function s(e){return class{constructor(t,a,{queryOptions:o={},config:s=(0,i.getConfig)()}){if(!a)throw Error(`cellProvider is required when collecting cells`);let{fromScript:c}=(0,r.parseFromInfo)(t,{config:s});if(this.fromScript=c,!n.bytes.equal(c.codeHash,e)){this.cellCollector=void 0;return}o={...o,lock:this.fromScript,type:o.type||`empty`,data:o.data||`0x`},this.cellCollector=a.collector(o)}async*collect(){if(this.cellCollector)for await(let e of this.cellCollector.collect())yield e}}}function c(t,r,i){return{codeHash:t,hashType:`type`,lockScriptInfo:{CellCollector:s(t),prepareSigningEntries:()=>{throw Error(`Custom scripts doesn't support prepareSigningEntries.`)},async setupInputCell(s,c,l,u={}){let d=c.cellOutput.lock;a(n.bytes.equal(d.codeHash,t),`The input script is not specified script`),s=s.update(`inputs`,e=>e.push(c));let f={cellOutput:{capacity:c.cellOutput.capacity,lock:c.cellOutput.lock,type:c.cellOutput.type},data:c.data};s=s.update(`outputs`,e=>e.push(f));let p=u.since;p&&(s=s.update(`inputSinces`,e=>e.set(s.get(`inputs`).size-1,p))),await Promise.all(r.map(async t=>{let n=e.ccc.CellDepInfo.from(t);if(n.type&&s.cellProvider!=null)for await(let e of s.cellProvider.collector({type:n.type}).collect())s=o(s,{depType:`code`,outPoint:e.outPoint});else s=o(s,{...n.cellDep,outPoint:{txHash:n.cellDep.outPoint.txHash,index:e.ccc.numToHex(n.cellDep.outPoint.index)}})}));let m=s.get(`inputs`).findIndex(t=>e.ccc.Script.from(t.cellOutput.lock).eq(e.ccc.Script.from(d)));return s=s.update(`witnesses`,t=>(t.get(m)&&(t=t.merge(Array.from(Array(m+1-t.size),()=>`0x`))),t.set(m,e.ccc.hexFrom(e.ccc.WitnessArgs.from({lock:Array.from(Array(i),()=>0)}).toBytes())))),s}}}}function l(){let n=t.cccA.MAINNET_SCRIPTS,r=t.cccA.TESTNET_SCRIPTS;return[[e.ccc.KnownScript.JoyId,1e3],[e.ccc.KnownScript.NostrLock,572],[e.ccc.KnownScript.PWLock,65]].map(([t,i])=>[c(e.ccc.hexFrom(r[t].codeHash),r[t].cellDeps,i),c(e.ccc.hexFrom(n[t].codeHash),n[t].cellDeps,i)]).flat()}exports.asserts=a,exports.generateDefaultScriptInfos=l,exports.generateScriptInfo=c;
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["ccc","bytes","cccA"],"sources":["../src/utils.ts","../src/default.ts"],"sourcesContent":["/**\n * Asserts that a condition is true, throwing an error if it is not.\n * @public\n *\n * @param condition - The condition to assert.\n * @param [message=\"Assert failed\"] - The error message to throw if the condition is false.\n * @throws {Error} If the condition is false.\n */\nexport function asserts(\n condition: unknown,\n message = \"Assert failed\",\n): asserts condition {\n if (!condition) {\n throw new Error(message);\n }\n}\n","import { ccc } from \"@ckb-ccc/core\";\nimport { cccA } from \"@ckb-ccc/core/advanced\";\nimport {\n Cell,\n CellCollector,\n CellDep,\n CellProvider,\n QueryOptions,\n Script,\n} from \"@ckb-lumos/base\";\nimport { bytes } from \"@ckb-lumos/codec\";\nimport {\n FromInfo,\n LockScriptInfo,\n parseFromInfo,\n} from \"@ckb-lumos/common-scripts\";\nimport { Config, getConfig } from \"@ckb-lumos/config-manager\";\nimport { TransactionSkeletonType } from \"@ckb-lumos/helpers\";\nimport { asserts } from \"./utils.js\";\n\nfunction addCellDep(\n txSkeleton: TransactionSkeletonType,\n newCellDep: CellDep,\n): TransactionSkeletonType {\n const cellDep = txSkeleton.get(\"cellDeps\").find((cellDep) => {\n return (\n cellDep.depType === newCellDep.depType &&\n ccc.OutPoint.from(cellDep.outPoint).eq(\n ccc.OutPoint.from(newCellDep.outPoint),\n )\n );\n });\n\n if (!cellDep) {\n txSkeleton = txSkeleton.update(\"cellDeps\", (cellDeps) => {\n return cellDeps.push({\n outPoint: newCellDep.outPoint,\n depType: newCellDep.depType,\n });\n });\n }\n\n return txSkeleton;\n}\n\n/**\n * Generates a class for collecting custom script cells.\n * @param codeHash - The code hash of the custom script.\n * @returns The CustomCellCollector class.\n */\nfunction generateCollectorClass(codeHash: string) {\n /**\n * Class representing a collector for custom script cells.\n */\n return class CustomCellCollector {\n readonly fromScript: Script;\n readonly cellCollector: CellCollector | undefined;\n\n /**\n * Creates an instance of CustomCollector.\n * @param fromInfo - The information about the address to collect cells from.\n * @param cellProvider - The provider to collect cells from.\n * @param options - The options for the collector.\n * @param] - The query options for collecting cells.\n * @param [options.config=getConfig()] - The Lumos configuration.\n * @throws {Error} If cellProvider is not provided or fromInfo is not a string.\n */\n constructor(\n fromInfo: FromInfo,\n cellProvider: CellProvider,\n {\n queryOptions = {},\n config = getConfig(),\n }: { queryOptions?: QueryOptions; config?: Config },\n ) {\n if (!cellProvider) {\n throw new Error(`cellProvider is required when collecting cells`);\n }\n\n const { fromScript } = parseFromInfo(fromInfo, { config });\n this.fromScript = fromScript;\n\n if (!bytes.equal(fromScript.codeHash, codeHash)) {\n this.cellCollector = undefined;\n return;\n }\n\n queryOptions = {\n ...queryOptions,\n lock: this.fromScript,\n type: queryOptions.type || \"empty\",\n data: queryOptions.data || \"0x\",\n };\n\n this.cellCollector = cellProvider.collector(queryOptions);\n }\n\n /**\n * Collects custom cells.\n * @async\n * @generator\n * @yields {Cell} The collected cell.\n */\n async *collect(): AsyncGenerator<Cell> {\n if (!this.cellCollector) {\n return;\n }\n\n for await (const inputCell of this.cellCollector.collect()) {\n yield inputCell;\n }\n }\n };\n}\n\n/**\n * Generates custom lock script information.\n * @public\n *\n * @param codeHash - The code hash of the custom script.\n * @param cellDeps - The cell dependencies for the custom script.\n * @returns The lock script information.\n */\nexport function generateScriptInfo(\n codeHash: string,\n cellDeps: ccc.CellDepInfoLike[],\n dummyLockLength: number,\n): LockScriptInfo {\n return {\n codeHash: codeHash,\n hashType: \"type\",\n lockScriptInfo: {\n CellCollector: generateCollectorClass(codeHash),\n prepareSigningEntries: () => {\n throw new Error(\n \"Custom scripts doesn't support prepareSigningEntries.\",\n );\n },\n async setupInputCell(txSkeleton, inputCell, _, options = {}) {\n const fromScript = inputCell.cellOutput.lock;\n asserts(\n bytes.equal(fromScript.codeHash, codeHash),\n `The input script is not specified script`,\n );\n // add inputCell to txSkeleton\n txSkeleton = txSkeleton.update(\"inputs\", (inputs) =>\n inputs.push(inputCell),\n );\n\n const output: Cell = {\n cellOutput: {\n capacity: inputCell.cellOutput.capacity,\n lock: inputCell.cellOutput.lock,\n type: inputCell.cellOutput.type,\n },\n data: inputCell.data,\n };\n\n txSkeleton = txSkeleton.update(\"outputs\", (outputs) =>\n outputs.push(output),\n );\n\n const since = options.since;\n if (since) {\n txSkeleton = txSkeleton.update(\"inputSinces\", (inputSinces) => {\n return inputSinces.set(txSkeleton.get(\"inputs\").size - 1, since);\n });\n }\n\n await Promise.all(\n cellDeps.map(async (itemLike) => {\n const item = ccc.CellDepInfo.from(itemLike);\n if (item.type && txSkeleton.cellProvider != null) {\n for await (const cell of txSkeleton.cellProvider\n .collector({\n type: item.type,\n })\n .collect()) {\n txSkeleton = addCellDep(txSkeleton, {\n depType: \"code\",\n outPoint: cell.outPoint!,\n });\n }\n } else {\n txSkeleton = addCellDep(txSkeleton, {\n ...item.cellDep,\n outPoint: {\n txHash: item.cellDep.outPoint.txHash,\n index: ccc.numToHex(item.cellDep.outPoint.index),\n },\n });\n }\n }),\n );\n\n const firstIndex = txSkeleton\n .get(\"inputs\")\n .findIndex((input) =>\n ccc.Script.from(input.cellOutput.lock).eq(\n ccc.Script.from(fromScript),\n ),\n );\n txSkeleton = txSkeleton.update(\"witnesses\", (witnesses) => {\n if (witnesses.get(firstIndex)) {\n witnesses = witnesses.merge(\n Array.from(\n new Array(firstIndex + 1 - witnesses.size),\n () => \"0x\",\n ),\n );\n }\n\n return witnesses.set(\n firstIndex,\n ccc.hexFrom(\n ccc.WitnessArgs.from({\n lock: Array.from(new Array(dummyLockLength), () => 0),\n }).toBytes(),\n ),\n );\n });\n\n return txSkeleton;\n },\n },\n };\n}\n\n/**\n * Generates default script information for CCC.\n * @returns An array of lock script information.\n */\nexport function generateDefaultScriptInfos(): LockScriptInfo[] {\n const mainnet = cccA.MAINNET_SCRIPTS;\n const testnet = cccA.TESTNET_SCRIPTS;\n\n return (\n [\n [ccc.KnownScript.JoyId, 1000],\n [ccc.KnownScript.NostrLock, 572],\n [ccc.KnownScript.PWLock, 65],\n ] as [ccc.KnownScript, number][]\n )\n .map(([script, dummyLockLength]) => [\n generateScriptInfo(\n ccc.hexFrom(testnet[script].codeHash),\n testnet[script].cellDeps,\n dummyLockLength,\n ),\n generateScriptInfo(\n ccc.hexFrom(mainnet[script]!.codeHash),\n mainnet[script]!.cellDeps,\n dummyLockLength,\n ),\n ])\n .flat();\n}\n"],"mappings":"kPAQA,SAAgB,EACd,EACA,EAAU,gBACS,CACnB,GA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EACAA,EAAAA,IAAI,QACFA,EAAAA,IAAI,YAAY,KAAK,CACnB,KAAM,MAAM,KAAS,MAAM,CAAe,MAAS,CAAC,CACtD,CAAC,CAAC,CAAC,QAAQ,CACb,CACF,EACD,EAEM,CACT,CACF,CACF,CACF,CAMA,SAAgB,GAA+C,CAC7D,IAAM,EAAUE,EAAAA,KAAK,gBACf,EAAUA,EAAAA,KAAK,gBAErB,MACE,CACE,CAACF,EAAAA,IAAI,YAAY,MAAO,GAAI,EAC5B,CAACA,EAAAA,IAAI,YAAY,UAAW,GAAG,EAC/B,CAACA,EAAAA,IAAI,YAAY,OAAQ,EAAE,CAC7B,CAAC,CAEA,KAAK,CAAC,EAAQ,KAAqB,CAClC,EACEA,EAAAA,IAAI,QAAQ,EAAQ,EAAO,CAAC,QAAQ,EACpC,EAAQ,EAAO,CAAC,SAChB,CACF,EACA,EACEA,EAAAA,IAAI,QAAQ,EAAQ,EAAO,CAAE,QAAQ,EACrC,EAAQ,EAAO,CAAE,SACjB,CACF,CACF,CAAC,CAAC,CACD,KAAK,CACV"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckb-ccc/lumos-patches",
3
- "version": "1.0.32",
3
+ "version": "1.1.0",
4
4
  "description": "Patches for using Lumos with CCC",
5
5
  "author": "Hanssen0 <hanssen0@hanssen0.com>",
6
6
  "license": "MIT",
@@ -11,26 +11,24 @@
11
11
  "url": "git://github.com/ckb-devrel/ccc.git"
12
12
  },
13
13
  "sideEffects": false,
14
- "main": "dist.commonjs/index.js",
15
- "module": "dist/index.js",
14
+ "main": "./dist.commonjs/index.js",
15
+ "module": "./dist/index.mjs",
16
16
  "exports": {
17
17
  ".": {
18
- "import": "./dist/index.js",
19
- "require": "./dist.commonjs/index.js",
20
- "default": "./dist.commonjs/index.js"
21
- }
18
+ "import": "./dist/index.mjs",
19
+ "require": "./dist.commonjs/index.js"
20
+ },
21
+ "./package.json": "./package.json"
22
22
  },
23
23
  "devDependencies": {
24
- "@eslint/js": "^9.34.0",
25
- "copyfiles": "^2.4.1",
26
- "eslint": "^9.34.0",
24
+ "@eslint/js": "^10.0.1",
25
+ "eslint": "^10.5.0",
27
26
  "eslint-config-prettier": "^10.1.8",
28
- "eslint-plugin-prettier": "^5.5.4",
29
- "prettier": "^3.6.2",
30
- "prettier-plugin-organize-imports": "^4.2.0",
31
- "rimraf": "^6.0.1",
32
- "typescript": "^5.9.2",
33
- "typescript-eslint": "^8.41.0"
27
+ "eslint-plugin-prettier": "^5.5.6",
28
+ "prettier": "^3.8.4",
29
+ "prettier-plugin-organize-imports": "^4.3.0",
30
+ "typescript": "^6.0.3",
31
+ "typescript-eslint": "^8.61.1"
34
32
  },
35
33
  "publishConfig": {
36
34
  "access": "public"
@@ -41,11 +39,13 @@
41
39
  "@ckb-lumos/common-scripts": "0.24.0-next.2",
42
40
  "@ckb-lumos/config-manager": "0.24.0-next.2",
43
41
  "@ckb-lumos/helpers": "0.24.0-next.2",
44
- "@joyid/ckb": "^1.1.2",
45
- "@ckb-ccc/core": "1.12.5"
42
+ "@joyid/ckb": "^1.1.4",
43
+ "tsdown": "^0.22.3",
44
+ "@ckb-ccc/core": "1.14.0"
46
45
  },
46
+ "types": "./dist.commonjs/index.d.ts",
47
47
  "scripts": {
48
- "build": "rimraf ./dist && rimraf ./dist.commonjs && tsc && tsc --project tsconfig.commonjs.json && copyfiles -u 2 misc/basedirs/**/* .",
48
+ "build": "tsdown",
49
49
  "lint": "eslint ./src",
50
50
  "format": "prettier --write . && eslint --fix ./src"
51
51
  }
@@ -0,0 +1,40 @@
1
+ import { defineConfig } from "tsdown";
2
+
3
+ const common = {
4
+ minify: true,
5
+ dts: true,
6
+ platform: "neutral" as const,
7
+ sourcemap: true,
8
+ exports: true,
9
+ };
10
+
11
+ const entry = {
12
+ index: "src/index.ts",
13
+ } as const;
14
+
15
+ const bundleDeps: string[] = [];
16
+
17
+ export default defineConfig(
18
+ (
19
+ [
20
+ {
21
+ entry,
22
+ deps: {
23
+ onlyBundle: [] as string[],
24
+ },
25
+ format: "esm",
26
+ copy: "./misc/basedirs/dist/*",
27
+ },
28
+ {
29
+ entry,
30
+ deps: {
31
+ alwaysBundle: bundleDeps,
32
+ onlyBundle: bundleDeps,
33
+ },
34
+ format: "cjs",
35
+ outDir: "dist.commonjs",
36
+ copy: "./misc/basedirs/dist.commonjs/*",
37
+ },
38
+ ] as const
39
+ ).map((c) => ({ ...c, ...common })),
40
+ );
package/dist/default.d.ts DELETED
@@ -1,17 +0,0 @@
1
- import { ccc } from "@ckb-ccc/core";
2
- import { LockScriptInfo } from "@ckb-lumos/common-scripts";
3
- /**
4
- * Generates custom lock script information.
5
- * @public
6
- *
7
- * @param codeHash - The code hash of the custom script.
8
- * @param cellDeps - The cell dependencies for the custom script.
9
- * @returns The lock script information.
10
- */
11
- export declare function generateScriptInfo(codeHash: string, cellDeps: ccc.CellDepInfoLike[], dummyLockLength: number): LockScriptInfo;
12
- /**
13
- * Generates default script information for CCC.
14
- * @returns An array of lock script information.
15
- */
16
- export declare function generateDefaultScriptInfos(): LockScriptInfo[];
17
- //# sourceMappingURL=default.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"default.d.ts","sourceRoot":"","sources":["../src/default.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAWpC,OAAO,EAEL,cAAc,EAEf,MAAM,2BAA2B,CAAC;AAoGnC;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,GAAG,CAAC,eAAe,EAAE,EAC/B,eAAe,EAAE,MAAM,GACtB,cAAc,CAmGhB;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,IAAI,cAAc,EAAE,CAwB7D"}
package/dist/default.js DELETED
@@ -1,169 +0,0 @@
1
- import { ccc } from "@ckb-ccc/core";
2
- import { cccA } from "@ckb-ccc/core/advanced";
3
- import { bytes } from "@ckb-lumos/codec";
4
- import { parseFromInfo, } from "@ckb-lumos/common-scripts";
5
- import { getConfig } from "@ckb-lumos/config-manager";
6
- import { asserts } from "./utils.js";
7
- function addCellDep(txSkeleton, newCellDep) {
8
- const cellDep = txSkeleton.get("cellDeps").find((cellDep) => {
9
- return (cellDep.depType === newCellDep.depType &&
10
- ccc.OutPoint.from(cellDep.outPoint).eq(ccc.OutPoint.from(newCellDep.outPoint)));
11
- });
12
- if (!cellDep) {
13
- txSkeleton = txSkeleton.update("cellDeps", (cellDeps) => {
14
- return cellDeps.push({
15
- outPoint: newCellDep.outPoint,
16
- depType: newCellDep.depType,
17
- });
18
- });
19
- }
20
- return txSkeleton;
21
- }
22
- /**
23
- * Generates a class for collecting custom script cells.
24
- * @param codeHash - The code hash of the custom script.
25
- * @returns The CustomCellCollector class.
26
- */
27
- function generateCollectorClass(codeHash) {
28
- /**
29
- * Class representing a collector for custom script cells.
30
- */
31
- return class CustomCellCollector {
32
- /**
33
- * Creates an instance of CustomCollector.
34
- * @param fromInfo - The information about the address to collect cells from.
35
- * @param cellProvider - The provider to collect cells from.
36
- * @param options - The options for the collector.
37
- * @param] - The query options for collecting cells.
38
- * @param [options.config=getConfig()] - The Lumos configuration.
39
- * @throws {Error} If cellProvider is not provided or fromInfo is not a string.
40
- */
41
- constructor(fromInfo, cellProvider, { queryOptions = {}, config = getConfig(), }) {
42
- if (!cellProvider) {
43
- throw new Error(`cellProvider is required when collecting cells`);
44
- }
45
- const { fromScript } = parseFromInfo(fromInfo, { config });
46
- this.fromScript = fromScript;
47
- if (!bytes.equal(fromScript.codeHash, codeHash)) {
48
- this.cellCollector = undefined;
49
- return;
50
- }
51
- queryOptions = {
52
- ...queryOptions,
53
- lock: this.fromScript,
54
- type: queryOptions.type || "empty",
55
- data: queryOptions.data || "0x",
56
- };
57
- this.cellCollector = cellProvider.collector(queryOptions);
58
- }
59
- /**
60
- * Collects custom cells.
61
- * @async
62
- * @generator
63
- * @yields {Cell} The collected cell.
64
- */
65
- async *collect() {
66
- if (!this.cellCollector) {
67
- return;
68
- }
69
- for await (const inputCell of this.cellCollector.collect()) {
70
- yield inputCell;
71
- }
72
- }
73
- };
74
- }
75
- /**
76
- * Generates custom lock script information.
77
- * @public
78
- *
79
- * @param codeHash - The code hash of the custom script.
80
- * @param cellDeps - The cell dependencies for the custom script.
81
- * @returns The lock script information.
82
- */
83
- export function generateScriptInfo(codeHash, cellDeps, dummyLockLength) {
84
- return {
85
- codeHash: codeHash,
86
- hashType: "type",
87
- lockScriptInfo: {
88
- CellCollector: generateCollectorClass(codeHash),
89
- prepareSigningEntries: () => {
90
- throw new Error("Custom scripts doesn't support prepareSigningEntries.");
91
- },
92
- async setupInputCell(txSkeleton, inputCell, _, options = {}) {
93
- const fromScript = inputCell.cellOutput.lock;
94
- asserts(bytes.equal(fromScript.codeHash, codeHash), `The input script is not specified script`);
95
- // add inputCell to txSkeleton
96
- txSkeleton = txSkeleton.update("inputs", (inputs) => inputs.push(inputCell));
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) => outputs.push(output));
106
- const since = options.since;
107
- if (since) {
108
- txSkeleton = txSkeleton.update("inputSinces", (inputSinces) => {
109
- return inputSinces.set(txSkeleton.get("inputs").size - 1, since);
110
- });
111
- }
112
- await Promise.all(cellDeps.map(async (itemLike) => {
113
- const item = ccc.CellDepInfo.from(itemLike);
114
- if (item.type && txSkeleton.cellProvider != null) {
115
- for await (const cell of txSkeleton.cellProvider
116
- .collector({
117
- type: item.type,
118
- })
119
- .collect()) {
120
- txSkeleton = addCellDep(txSkeleton, {
121
- depType: "code",
122
- outPoint: cell.outPoint,
123
- });
124
- }
125
- }
126
- else {
127
- txSkeleton = addCellDep(txSkeleton, {
128
- ...item.cellDep,
129
- outPoint: {
130
- txHash: item.cellDep.outPoint.txHash,
131
- index: ccc.numToHex(item.cellDep.outPoint.index),
132
- },
133
- });
134
- }
135
- }));
136
- const firstIndex = txSkeleton
137
- .get("inputs")
138
- .findIndex((input) => ccc.Script.from(input.cellOutput.lock).eq(ccc.Script.from(fromScript)));
139
- txSkeleton = txSkeleton.update("witnesses", (witnesses) => {
140
- if (witnesses.get(firstIndex)) {
141
- witnesses = witnesses.merge(Array.from(new Array(firstIndex + 1 - witnesses.size), () => "0x"));
142
- }
143
- return witnesses.set(firstIndex, ccc.hexFrom(ccc.WitnessArgs.from({
144
- lock: Array.from(new Array(dummyLockLength), () => 0),
145
- }).toBytes()));
146
- });
147
- return txSkeleton;
148
- },
149
- },
150
- };
151
- }
152
- /**
153
- * Generates default script information for CCC.
154
- * @returns An array of lock script information.
155
- */
156
- export function generateDefaultScriptInfos() {
157
- const mainnet = cccA.MAINNET_SCRIPTS;
158
- const testnet = cccA.TESTNET_SCRIPTS;
159
- return [
160
- [ccc.KnownScript.JoyId, 1000],
161
- [ccc.KnownScript.NostrLock, 572],
162
- [ccc.KnownScript.PWLock, 65],
163
- ]
164
- .map(([script, dummyLockLength]) => [
165
- generateScriptInfo(ccc.hexFrom(testnet[script].codeHash), testnet[script].cellDeps, dummyLockLength),
166
- generateScriptInfo(ccc.hexFrom(mainnet[script].codeHash), mainnet[script].cellDeps, dummyLockLength),
167
- ])
168
- .flat();
169
- }
package/dist/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from "./default.js";
2
- export * from "./utils.js";
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC"}
package/dist/index.js DELETED
@@ -1,2 +0,0 @@
1
- export * from "./default.js";
2
- export * from "./utils.js";
package/dist/utils.d.ts DELETED
@@ -1,10 +0,0 @@
1
- /**
2
- * Asserts that a condition is true, throwing an error if it is not.
3
- * @public
4
- *
5
- * @param condition - The condition to assert.
6
- * @param [message="Assert failed"] - The error message to throw if the condition is false.
7
- * @throws {Error} If the condition is false.
8
- */
9
- export declare function asserts(condition: unknown, message?: string): asserts condition;
10
- //# sourceMappingURL=utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,OAAO,CACrB,SAAS,EAAE,OAAO,EAClB,OAAO,SAAkB,GACxB,OAAO,CAAC,SAAS,CAInB"}
package/dist/utils.js DELETED
@@ -1,13 +0,0 @@
1
- /**
2
- * Asserts that a condition is true, throwing an error if it is not.
3
- * @public
4
- *
5
- * @param condition - The condition to assert.
6
- * @param [message="Assert failed"] - The error message to throw if the condition is false.
7
- * @throws {Error} If the condition is false.
8
- */
9
- export function asserts(condition, message = "Assert failed") {
10
- if (!condition) {
11
- throw new Error(message);
12
- }
13
- }
@@ -1,17 +0,0 @@
1
- import { ccc } from "@ckb-ccc/core";
2
- import { LockScriptInfo } from "@ckb-lumos/common-scripts";
3
- /**
4
- * Generates custom lock script information.
5
- * @public
6
- *
7
- * @param codeHash - The code hash of the custom script.
8
- * @param cellDeps - The cell dependencies for the custom script.
9
- * @returns The lock script information.
10
- */
11
- export declare function generateScriptInfo(codeHash: string, cellDeps: ccc.CellDepInfoLike[], dummyLockLength: number): LockScriptInfo;
12
- /**
13
- * Generates default script information for CCC.
14
- * @returns An array of lock script information.
15
- */
16
- export declare function generateDefaultScriptInfos(): LockScriptInfo[];
17
- //# sourceMappingURL=default.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"default.d.ts","sourceRoot":"","sources":["../src/default.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAWpC,OAAO,EAEL,cAAc,EAEf,MAAM,2BAA2B,CAAC;AAoGnC;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,GAAG,CAAC,eAAe,EAAE,EAC/B,eAAe,EAAE,MAAM,GACtB,cAAc,CAmGhB;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,IAAI,cAAc,EAAE,CAwB7D"}
@@ -1,173 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateScriptInfo = generateScriptInfo;
4
- exports.generateDefaultScriptInfos = generateDefaultScriptInfos;
5
- const core_1 = require("@ckb-ccc/core");
6
- const advanced_1 = require("@ckb-ccc/core/advanced");
7
- const codec_1 = require("@ckb-lumos/codec");
8
- const common_scripts_1 = require("@ckb-lumos/common-scripts");
9
- const config_manager_1 = require("@ckb-lumos/config-manager");
10
- const utils_js_1 = require("./utils.js");
11
- function addCellDep(txSkeleton, newCellDep) {
12
- const cellDep = txSkeleton.get("cellDeps").find((cellDep) => {
13
- return (cellDep.depType === newCellDep.depType &&
14
- core_1.ccc.OutPoint.from(cellDep.outPoint).eq(core_1.ccc.OutPoint.from(newCellDep.outPoint)));
15
- });
16
- if (!cellDep) {
17
- txSkeleton = txSkeleton.update("cellDeps", (cellDeps) => {
18
- return cellDeps.push({
19
- outPoint: newCellDep.outPoint,
20
- depType: newCellDep.depType,
21
- });
22
- });
23
- }
24
- return txSkeleton;
25
- }
26
- /**
27
- * Generates a class for collecting custom script cells.
28
- * @param codeHash - The code hash of the custom script.
29
- * @returns The CustomCellCollector class.
30
- */
31
- function generateCollectorClass(codeHash) {
32
- /**
33
- * Class representing a collector for custom script cells.
34
- */
35
- return class CustomCellCollector {
36
- /**
37
- * Creates an instance of CustomCollector.
38
- * @param fromInfo - The information about the address to collect cells from.
39
- * @param cellProvider - The provider to collect cells from.
40
- * @param options - The options for the collector.
41
- * @param] - The query options for collecting cells.
42
- * @param [options.config=getConfig()] - The Lumos configuration.
43
- * @throws {Error} If cellProvider is not provided or fromInfo is not a string.
44
- */
45
- constructor(fromInfo, cellProvider, { queryOptions = {}, config = (0, config_manager_1.getConfig)(), }) {
46
- if (!cellProvider) {
47
- throw new Error(`cellProvider is required when collecting cells`);
48
- }
49
- const { fromScript } = (0, common_scripts_1.parseFromInfo)(fromInfo, { config });
50
- this.fromScript = fromScript;
51
- if (!codec_1.bytes.equal(fromScript.codeHash, codeHash)) {
52
- this.cellCollector = undefined;
53
- return;
54
- }
55
- queryOptions = {
56
- ...queryOptions,
57
- lock: this.fromScript,
58
- type: queryOptions.type || "empty",
59
- data: queryOptions.data || "0x",
60
- };
61
- this.cellCollector = cellProvider.collector(queryOptions);
62
- }
63
- /**
64
- * Collects custom cells.
65
- * @async
66
- * @generator
67
- * @yields {Cell} The collected cell.
68
- */
69
- async *collect() {
70
- if (!this.cellCollector) {
71
- return;
72
- }
73
- for await (const inputCell of this.cellCollector.collect()) {
74
- yield inputCell;
75
- }
76
- }
77
- };
78
- }
79
- /**
80
- * Generates custom lock script information.
81
- * @public
82
- *
83
- * @param codeHash - The code hash of the custom script.
84
- * @param cellDeps - The cell dependencies for the custom script.
85
- * @returns The lock script information.
86
- */
87
- function generateScriptInfo(codeHash, cellDeps, dummyLockLength) {
88
- return {
89
- codeHash: codeHash,
90
- hashType: "type",
91
- lockScriptInfo: {
92
- CellCollector: generateCollectorClass(codeHash),
93
- prepareSigningEntries: () => {
94
- throw new Error("Custom scripts doesn't support prepareSigningEntries.");
95
- },
96
- async setupInputCell(txSkeleton, inputCell, _, options = {}) {
97
- const fromScript = inputCell.cellOutput.lock;
98
- (0, utils_js_1.asserts)(codec_1.bytes.equal(fromScript.codeHash, codeHash), `The input script is not specified script`);
99
- // add inputCell to txSkeleton
100
- txSkeleton = txSkeleton.update("inputs", (inputs) => inputs.push(inputCell));
101
- const output = {
102
- cellOutput: {
103
- capacity: inputCell.cellOutput.capacity,
104
- lock: inputCell.cellOutput.lock,
105
- type: inputCell.cellOutput.type,
106
- },
107
- data: inputCell.data,
108
- };
109
- txSkeleton = txSkeleton.update("outputs", (outputs) => outputs.push(output));
110
- const since = options.since;
111
- if (since) {
112
- txSkeleton = txSkeleton.update("inputSinces", (inputSinces) => {
113
- return inputSinces.set(txSkeleton.get("inputs").size - 1, since);
114
- });
115
- }
116
- await Promise.all(cellDeps.map(async (itemLike) => {
117
- const item = core_1.ccc.CellDepInfo.from(itemLike);
118
- if (item.type && txSkeleton.cellProvider != null) {
119
- for await (const cell of txSkeleton.cellProvider
120
- .collector({
121
- type: item.type,
122
- })
123
- .collect()) {
124
- txSkeleton = addCellDep(txSkeleton, {
125
- depType: "code",
126
- outPoint: cell.outPoint,
127
- });
128
- }
129
- }
130
- else {
131
- txSkeleton = addCellDep(txSkeleton, {
132
- ...item.cellDep,
133
- outPoint: {
134
- txHash: item.cellDep.outPoint.txHash,
135
- index: core_1.ccc.numToHex(item.cellDep.outPoint.index),
136
- },
137
- });
138
- }
139
- }));
140
- const firstIndex = txSkeleton
141
- .get("inputs")
142
- .findIndex((input) => core_1.ccc.Script.from(input.cellOutput.lock).eq(core_1.ccc.Script.from(fromScript)));
143
- txSkeleton = txSkeleton.update("witnesses", (witnesses) => {
144
- if (witnesses.get(firstIndex)) {
145
- witnesses = witnesses.merge(Array.from(new Array(firstIndex + 1 - witnesses.size), () => "0x"));
146
- }
147
- return witnesses.set(firstIndex, core_1.ccc.hexFrom(core_1.ccc.WitnessArgs.from({
148
- lock: Array.from(new Array(dummyLockLength), () => 0),
149
- }).toBytes()));
150
- });
151
- return txSkeleton;
152
- },
153
- },
154
- };
155
- }
156
- /**
157
- * Generates default script information for CCC.
158
- * @returns An array of lock script information.
159
- */
160
- function generateDefaultScriptInfos() {
161
- const mainnet = advanced_1.cccA.MAINNET_SCRIPTS;
162
- const testnet = advanced_1.cccA.TESTNET_SCRIPTS;
163
- return [
164
- [core_1.ccc.KnownScript.JoyId, 1000],
165
- [core_1.ccc.KnownScript.NostrLock, 572],
166
- [core_1.ccc.KnownScript.PWLock, 65],
167
- ]
168
- .map(([script, dummyLockLength]) => [
169
- generateScriptInfo(core_1.ccc.hexFrom(testnet[script].codeHash), testnet[script].cellDeps, dummyLockLength),
170
- generateScriptInfo(core_1.ccc.hexFrom(mainnet[script].codeHash), mainnet[script].cellDeps, dummyLockLength),
171
- ])
172
- .flat();
173
- }
@@ -1,10 +0,0 @@
1
- /**
2
- * Asserts that a condition is true, throwing an error if it is not.
3
- * @public
4
- *
5
- * @param condition - The condition to assert.
6
- * @param [message="Assert failed"] - The error message to throw if the condition is false.
7
- * @throws {Error} If the condition is false.
8
- */
9
- export declare function asserts(condition: unknown, message?: string): asserts condition;
10
- //# sourceMappingURL=utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,OAAO,CACrB,SAAS,EAAE,OAAO,EAClB,OAAO,SAAkB,GACxB,OAAO,CAAC,SAAS,CAInB"}
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.asserts = asserts;
4
- /**
5
- * Asserts that a condition is true, throwing an error if it is not.
6
- * @public
7
- *
8
- * @param condition - The condition to assert.
9
- * @param [message="Assert failed"] - The error message to throw if the condition is false.
10
- * @throws {Error} If the condition is false.
11
- */
12
- function asserts(condition, message = "Assert failed") {
13
- if (!condition) {
14
- throw new Error(message);
15
- }
16
- }