@ckb-ccc/co-build 0.0.0-canary-20260713182150
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 +14 -0
- package/README.md +44 -0
- package/dist/barrel-BLUKLBQb.mjs +2 -0
- package/dist/barrel-BLUKLBQb.mjs.map +1 -0
- package/dist/barrel.d.mts +809 -0
- package/dist/barrel.d.mts.map +1 -0
- package/dist/barrel.mjs +1 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +1 -0
- package/dist/package.json +3 -0
- package/dist/rolldown-runtime-DK3Fl9T5.mjs +1 -0
- package/dist.commonjs/barrel-Cbdw9XZd.js +2 -0
- package/dist.commonjs/barrel-Cbdw9XZd.js.map +1 -0
- package/dist.commonjs/barrel.d.ts +811 -0
- package/dist.commonjs/barrel.d.ts.map +1 -0
- package/dist.commonjs/barrel.js +1 -0
- package/dist.commonjs/index.d.ts +2 -0
- package/dist.commonjs/index.js +1 -0
- package/dist.commonjs/package.json +3 -0
- package/package.json +53 -0
- package/prettier.config.cjs +11 -0
- package/src/barrel.ts +2 -0
- package/src/coBuild.ts +387 -0
- package/src/codec/buildingPacket.ts +166 -0
- package/src/codec/index.ts +2 -0
- package/src/codec/witnessLayout.ts +66 -0
- package/src/index.ts +2 -0
- package/tsdown.config.mts +41 -0
- package/typedoc.json +6 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# @ckb-ccc/co-build
|
|
2
|
+
|
|
3
|
+
## 0.0.0-canary-20260713182150
|
|
4
|
+
### Minor Changes
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
- [#419](https://github.com/ckb-devrel/ccc/pull/419) [`81ca371`](https://github.com/ckb-devrel/ccc/commit/81ca3713edd3c74968e391e48e9a36978435c45f) Thanks [@Hanssen0](https://github.com/Hanssen0)! - feat(co-build): new CoBuild package
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [[`eb806a1`](https://github.com/ckb-devrel/ccc/commit/eb806a171356a35200fccb46667da5574b350609), [`584a1eb`](https://github.com/ckb-devrel/ccc/commit/584a1ebeeb083904e5c2851208bc8491914b3d34), [`81ca371`](https://github.com/ckb-devrel/ccc/commit/81ca3713edd3c74968e391e48e9a36978435c45f), [`3dd2aea`](https://github.com/ckb-devrel/ccc/commit/3dd2aea90ce235fdcc1b0b3d1e4282391ea944fe), [`235676f`](https://github.com/ckb-devrel/ccc/commit/235676f5a7edb0ed95a0909bf530767e35952ffa), [`5ebe6b6`](https://github.com/ckb-devrel/ccc/commit/5ebe6b61e2823cbb6fdbf776bdb16ef4ab83b2f6), [`ec643ac`](https://github.com/ckb-devrel/ccc/commit/ec643ac6bbfeacd3e444ccf5970ea070a30fce8f), [`23110d2`](https://github.com/ckb-devrel/ccc/commit/23110d2f0c90ccaf334bd4736c3e374d07913d72), [`2a8f542`](https://github.com/ckb-devrel/ccc/commit/2a8f542ac2aa1f117991d5737a64da90ef3b138a), [`5e1f8d2`](https://github.com/ckb-devrel/ccc/commit/5e1f8d2d3e6ee26002e323ff0bcd1fcf54240f0b)]:
|
|
14
|
+
- @ckb-ccc/core@0.0.0-canary-20260713182150
|
package/README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://app.ckbccc.com/">
|
|
3
|
+
<img alt="Logo" src="https://raw.githubusercontent.com/ckb-devrel/ccc/master/assets/logoAndText.svg" style="height: 8rem; max-width: 90%; padding: 0.5rem 0;" />
|
|
4
|
+
</a>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<h1 align="center" style="font-size: 48px;">
|
|
8
|
+
@ckb-ccc/co-build
|
|
9
|
+
</h1>
|
|
10
|
+
|
|
11
|
+
<p align="center">
|
|
12
|
+
CCC - CKBers' Codebase is a one-stop solution for your CKB JS/TS ecosystem development.
|
|
13
|
+
</p>
|
|
14
|
+
|
|
15
|
+
## Overview
|
|
16
|
+
|
|
17
|
+
`@ckb-ccc/co-build` provides tools and Molecule codecs to support the CKB Co-build Protocol, a standard for coordinating multi-party signers and complex script operations (such as Spore actions) within a single transaction.
|
|
18
|
+
|
|
19
|
+
## Quick Example
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { ccc } from "@ckb-ccc/core";
|
|
23
|
+
import { CoBuild, ScriptInfo } from "@ckb-ccc/co-build";
|
|
24
|
+
|
|
25
|
+
const coBuild = new CoBuild(
|
|
26
|
+
{
|
|
27
|
+
codeHash: "0x...",
|
|
28
|
+
hashType: "type",
|
|
29
|
+
args: "0x...",
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: "MyScript",
|
|
33
|
+
url: "https://example.com",
|
|
34
|
+
schema: "MySchema",
|
|
35
|
+
messageType: "MyMessageType",
|
|
36
|
+
},
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
// Build action
|
|
40
|
+
const action = coBuild.buildAction(ccc.bytesFrom("action payload"));
|
|
41
|
+
|
|
42
|
+
// Append to transaction
|
|
43
|
+
const { tx } = await coBuild.appendActions(transaction, action);
|
|
44
|
+
```
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{t as e}from"./rolldown-runtime-DK3Fl9T5.mjs";import{ccc as t,mol as n}from"@ckb-ccc/core";function r(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}var i;const a=n.table({scriptInfoHash:n.Byte32,scriptHash:n.Byte32,data:n.Bytes});let o=class extends t.Entity.Base(){constructor({scriptInfoHash:e,scriptHash:t,data:n}){super(),this.scriptInfoHash=e,this.scriptHash=t,this.data=n}};o=r([t.codec(a)],o);const s=n.vector(o),c=n.table({actions:s});let l=class extends t.Entity.Base(){constructor({actions:e}){super(),this.actions=e}};l=r([t.codec(c)],l);const u=n.table({name:n.String,url:n.String,scriptHash:n.Byte32,schema:n.String,messageType:n.String});let d=i=class extends t.Entity.Base(){constructor({name:e,url:t,scriptHash:n,schema:r,messageType:i}){super(),this.name=e,this.url=t,this.scriptHash=n,this.schema=r,this.messageType=i}static from(e){return e instanceof i?e:super.from({name:e.name??``,url:e.url??``,scriptHash:e.scriptHash,schema:e.schema??``,messageType:e.messageType??``})}};d=i=r([t.codec(u)],d);const f=n.vector(d),p=n.table({seal:n.Bytes,message:l});let m=class extends t.Entity.Base(){constructor({seal:e,message:t}){super(),this.seal=e,this.message=t}};m=r([t.codec(p)],m);const h={SighashAll:`SighashAll`},g={SighashAll:4278190081},_=n.union({SighashAll:m},g);let v=class extends t.Entity.BaseUnion(){};v=r([t.codec(_)],v);function y(e,n=!1){let r=t.Transaction.from(e);if(r.witnesses.length===0)return{actions:[],tx:r};try{return v.decode(r.witnesses[r.witnesses.length-1]).match({SighashAll:({message:{actions:e}})=>(n&&r.witnesses.pop(),{actions:e,tx:r}),_:()=>({actions:[],tx:r})})}catch{return{actions:[],tx:r}}}async function b(e,n){let r=t.Transaction.from(e),i=y(r,!0);r=i.tx;let a=Math.max(r.witnesses.length,r.inputs.length,r.outputs.length);return r.setWitnessAt(a,v.encode({type:h.SighashAll,value:{seal:`0x`,message:{actions:await n(i.actions)}}})),{tx:r,witnessIndex:a}}async function x(e,t){let n=[];if(typeof t==`object`&&t)if(Symbol.iterator in t)for(let e of t)n.push(e);else if(Symbol.asyncIterator in t)for await(let e of t)n.push(e);else n.push(t);return b(e,e=>e.concat(n.map(o.from)))}function S(e,n){return C(e,t.Script.from(n).hash())}function C(e,n){let r=t.hexFrom(n),{actions:i}=y(e);return i.filter(e=>e.scriptHash===r)}function w(e,t){return T(e,d.from(t).hash())}function T(e,n){let r=t.hexFrom(n),{actions:i}=y(e);return i.filter(e=>e.scriptInfoHash===r)}var E=class{constructor(e,n){this.script=t.Script.from(e),this.scriptHash=this.script.hash(),this.scriptInfo=d.from({...n??{},scriptHash:this.script.hash()}),this.scriptInfoHash=this.scriptInfo.hash()}buildAction(e){return o.from({scriptInfoHash:this.scriptInfoHash,scriptHash:this.scriptHash,data:e instanceof t.Entity?e.toBytes():e})}parseActions(e,t=!1){return y(e,t)}manipulateActions(e,t){return b(e,t)}async appendActions(e,t){let n=[];if(typeof t==`object`&&t)if(Symbol.iterator in t)for(let e of t)n.push(e);else if(Symbol.asyncIterator in t)for await(let e of t)n.push(e);else n.push(t);return this.manipulateActions(e,e=>e.concat(n.map(e=>typeof e==`object`&&e&&`scriptInfoHash`in e&&`scriptHash`in e&&`data`in e?o.from(e):this.buildAction(e))))}findActions(e,n){return C(e,n?t.Script.from(n).hash():this.scriptHash)}findActionsByHash(e,t){return C(e,t??this.scriptHash)}findActionsByScriptInfo(e,t){return T(e,t?d.from(t).hash():this.scriptInfoHash)}findActionsByScriptInfoHash(e,t){return T(e,t??this.scriptInfoHash)}},D=e({Action:()=>o,ActionCodec:()=>a,ActionVec:()=>s,CoBuild:()=>E,Message:()=>l,MessageCodec:()=>c,ScriptInfo:()=>d,ScriptInfoCodec:()=>u,ScriptInfoVec:()=>f,SighashAll:()=>m,SighashAllCodec:()=>p,WitnessLayout:()=>v,WitnessLayoutCodec:()=>_,WitnessLayoutVariant:()=>h,WitnessLayoutVariantId:()=>g,appendActions:()=>x,findActions:()=>S,findActionsByHash:()=>C,findActionsByScriptInfo:()=>w,findActionsByScriptInfoHash:()=>T,manipulateActions:()=>b,parseActions:()=>y});export{f as C,u as S,a as _,C as a,c as b,b as c,p as d,v as f,o as g,g as h,S as i,y as l,h as m,E as n,w as o,_ as p,x as r,T as s,D as t,m as u,s as v,d as x,l as y};
|
|
2
|
+
//# sourceMappingURL=barrel-BLUKLBQb.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"barrel-BLUKLBQb.mjs","names":[],"sources":["../src/codec/buildingPacket.ts","../src/codec/witnessLayout.ts","../src/coBuild.ts","../src/barrel.ts"],"sourcesContent":["import { ccc, mol } from \"@ckb-ccc/core\";\n\nexport const ActionCodec = mol.table({\n scriptInfoHash: mol.Byte32,\n scriptHash: mol.Byte32,\n data: mol.Bytes,\n});\n\n/**\n * Representation of an Action's properties.\n */\nexport type ActionLike = ccc.EncodableType<typeof ActionCodec>;\n\n/**\n * Represents a single Action inside the CoBuild protocol.\n */\n@ccc.codec(ActionCodec)\nexport class Action extends ccc.Entity.Base<ActionLike, Action>() {\n public scriptInfoHash: ccc.Hex;\n public scriptHash: ccc.Hex;\n public data: ccc.Hex;\n\n /**\n * Constructs an Action instance.\n * @param scriptInfoHash The hex-encoded hash of the ScriptInfo.\n * @param scriptHash The hex-encoded script hash.\n * @param data The hex-encoded action payload data.\n */\n constructor({\n scriptInfoHash,\n scriptHash,\n data,\n }: ccc.DecodedType<typeof ActionCodec>) {\n super();\n\n this.scriptInfoHash = scriptInfoHash;\n this.scriptHash = scriptHash;\n this.data = data;\n }\n}\n\n/**\n * Molecule vector of Action codecs.\n */\nexport const ActionVec = mol.vector(Action);\n\nexport const MessageCodec = mol.table({\n actions: ActionVec,\n});\n\n/**\n * Representation of a Message's properties.\n */\nexport type MessageLike = ccc.EncodableType<typeof MessageCodec>;\n\n/**\n * Represents a Message containing a list of actions.\n */\n@ccc.codec(MessageCodec)\nexport class Message extends ccc.Entity.Base<MessageLike, Message>() {\n public actions: Action[];\n\n /**\n * Constructs a Message instance.\n * @param actions The list of Action instances.\n */\n constructor({ actions }: ccc.DecodedType<typeof MessageCodec>) {\n super();\n\n this.actions = actions;\n }\n}\n\nexport const ScriptInfoCodec = mol.table({\n name: mol.String,\n url: mol.String,\n scriptHash: mol.Byte32,\n schema: mol.String,\n messageType: mol.String,\n});\n\n/**\n * Representation of a ScriptInfo's properties.\n */\nexport type ScriptInfoLike = {\n /**\n * The developer/dapp name.\n */\n name?: string | null;\n /**\n * The url associated with the script or dapp.\n */\n url?: string | null;\n /**\n * The script hash.\n */\n scriptHash: ccc.BytesLike;\n /**\n * The action schema description.\n */\n schema?: string | null;\n /**\n * The entry action type name used in the WitnessLayout.\n */\n messageType?: string | null;\n};\n\n/**\n * Represents script metadata information (ScriptInfo).\n */\n@ccc.codec(ScriptInfoCodec)\nexport class ScriptInfo extends ccc.Entity.Base<ScriptInfoLike, ScriptInfo>() {\n public name: string;\n public url: string;\n public scriptHash: ccc.Hex;\n public schema: string;\n public messageType: string;\n\n /**\n * Constructs a ScriptInfo instance.\n * @param name The developer/dapp name.\n * @param url The url associated with the script or dapp.\n * @param scriptHash The hex-encoded script hash.\n * @param schema The action schema.\n * @param messageType The message type.\n */\n constructor({\n name,\n url,\n scriptHash,\n schema,\n messageType,\n }: ccc.DecodedType<typeof ScriptInfoCodec>) {\n super();\n\n this.name = name;\n this.url = url;\n this.scriptHash = scriptHash;\n this.schema = schema;\n this.messageType = messageType;\n }\n\n /**\n * Creates a ScriptInfo instance from a ScriptInfoLike object.\n * @param scriptInfoLike The source ScriptInfoLike object or ScriptInfo instance.\n * @returns A new or existing ScriptInfo instance.\n */\n static from(scriptInfoLike: ScriptInfoLike): ScriptInfo {\n if (scriptInfoLike instanceof ScriptInfo) {\n return scriptInfoLike;\n }\n\n return super.from({\n name: scriptInfoLike.name ?? \"\",\n url: scriptInfoLike.url ?? \"\",\n scriptHash: scriptInfoLike.scriptHash,\n schema: scriptInfoLike.schema ?? \"\",\n messageType: scriptInfoLike.messageType ?? \"\",\n });\n }\n}\n\n/**\n * Molecule vector of ScriptInfo codecs.\n */\nexport const ScriptInfoVec = mol.vector(ScriptInfo);\n","import { ccc, mol } from \"@ckb-ccc/core\";\nimport { Message } from \"./buildingPacket.js\";\n\nexport const SighashAllCodec = mol.table({\n seal: mol.Bytes,\n message: Message,\n});\n\n/**\n * Representation of a SighashAll's properties.\n */\nexport type SighashAllLike = ccc.EncodableType<typeof SighashAllCodec>;\n\n/**\n * Represents a SighashAll witness structure.\n */\n@ccc.codec(SighashAllCodec)\nexport class SighashAll extends ccc.Entity.Base<SighashAllLike, SighashAll>() {\n public seal: ccc.Hex;\n public message: Message;\n\n /**\n * Constructs a SighashAll instance.\n * @param seal The hex-encoded signature or seal.\n * @param message The Message instance.\n */\n constructor({ seal, message }: ccc.DecodedType<typeof SighashAllCodec>) {\n super();\n\n this.seal = seal;\n this.message = message;\n }\n}\n\n/**\n * WitnessLayout union variant names.\n */\nexport const WitnessLayoutVariant = {\n SighashAll: \"SighashAll\",\n} as const;\n\n/**\n * WitnessLayout union variant numeric identifiers.\n */\nexport const WitnessLayoutVariantId = {\n SighashAll: 4278190081,\n};\n\n/**\n * Molecule union representing the layout of the transaction witness.\n */\nexport const WitnessLayoutCodec = mol.union(\n {\n SighashAll,\n },\n WitnessLayoutVariantId,\n);\n\ntype WitnessLayoutLike = ccc.EncodableType<typeof WitnessLayoutCodec>;\n\n@ccc.codec(WitnessLayoutCodec)\nexport class WitnessLayout extends ccc.Entity.BaseUnion<\n typeof WitnessLayoutCodec,\n WitnessLayoutLike,\n WitnessLayout\n>() {}\n","import { ccc } from \"@ckb-ccc/core\";\nimport {\n Action,\n ActionLike,\n ScriptInfo,\n ScriptInfoLike,\n WitnessLayout,\n WitnessLayoutVariant,\n} from \"./codec/index.js\";\n\n/**\n * Parses the CoBuild actions from the last witness of a transaction.\n * @param txLike The transaction containing the witnesses.\n * @param shouldRemoveParsedWitness If true, removes the last witness from the returned transaction.\n * @returns An object containing the parsed actions and the transaction.\n */\nexport function parseActions(\n txLike: ccc.TransactionLike,\n shouldRemoveParsedWitness: boolean = false,\n): {\n actions: Action[];\n tx: ccc.Transaction;\n} {\n const tx = ccc.Transaction.from(txLike);\n\n if (tx.witnesses.length === 0) {\n return { actions: [], tx };\n }\n\n try {\n return WitnessLayout.decode(tx.witnesses[tx.witnesses.length - 1]).match({\n SighashAll: ({ message: { actions } }) => {\n if (shouldRemoveParsedWitness) {\n tx.witnesses.pop();\n }\n return { actions, tx };\n },\n _: () => {\n // In the original CoBuild design, the SighashAll can be anywhere in the transaction witnesses.\n // I don't think that design will come to reality in a short time, so I will just ignore other possibilities for now.\n return { actions: [], tx };\n },\n });\n } catch {\n return { actions: [], tx };\n }\n}\n\n/**\n * Parses existing actions, executes a manipulator function to modify or add actions,\n * and encodes/updates the witness layout at the correct index.\n * @param txLike The target transaction.\n * @param manipulator A function that takes the current actions and returns updated actions.\n * @returns The updated transaction and the index of the modified witness.\n */\nexport async function manipulateActions(\n txLike: ccc.TransactionLike,\n manipulator: (actions: Action[]) => Action[] | Promise<Action[]>,\n): Promise<{\n tx: ccc.Transaction;\n witnessIndex: number;\n}> {\n let tx = ccc.Transaction.from(txLike);\n const parsedRes = parseActions(tx, true);\n tx = parsedRes.tx;\n\n const witnessIndex = Math.max(\n tx.witnesses.length,\n tx.inputs.length,\n tx.outputs.length,\n );\n\n tx.setWitnessAt(\n witnessIndex,\n WitnessLayout.encode({\n type: WitnessLayoutVariant.SighashAll,\n value: {\n seal: \"0x\",\n message: {\n actions: await manipulator(parsedRes.actions),\n },\n },\n }),\n );\n\n return {\n tx,\n witnessIndex,\n };\n}\n\n/**\n * Appends actions to the transaction's CoBuild witness.\n * Supports single action, iterables, or async iterables of actions.\n * @param txLike The target transaction.\n * @param actions The action(s) to append. Can be a single ActionLike, or an iterable/async iterable of ActionLike.\n * @returns The updated transaction and the index of the witness.\n */\nexport async function appendActions(\n txLike: ccc.TransactionLike,\n actions: ActionLike | Iterable<ActionLike> | AsyncIterable<ActionLike>,\n): Promise<{\n tx: ccc.Transaction;\n witnessIndex: number;\n}> {\n const actionList: ActionLike[] = [];\n if (typeof actions === \"object\" && actions !== null) {\n if (Symbol.iterator in actions) {\n for (const action of actions) {\n actionList.push(action);\n }\n } else if (Symbol.asyncIterator in actions) {\n for await (const action of actions) {\n actionList.push(action);\n }\n } else {\n actionList.push(actions);\n }\n }\n\n return manipulateActions(txLike, (existedActions) =>\n existedActions.concat(actionList.map(Action.from)),\n );\n}\n\n/**\n * Filters actions in a transaction matching the given CKB Script.\n * @param txLike The transaction containing the witnesses.\n * @param scriptLike The script to match actions against.\n * @returns The list of matching actions.\n */\nexport function findActions(\n txLike: ccc.TransactionLike,\n scriptLike: ccc.ScriptLike,\n): Action[] {\n const scriptHash = ccc.Script.from(scriptLike).hash();\n return findActionsByHash(txLike, scriptHash);\n}\n\n/**\n * Filters actions in a transaction matching the given script hash.\n * @param txLike The transaction containing the witnesses.\n * @param scriptHashLike The script hash to match.\n * @returns The list of matching actions.\n */\nexport function findActionsByHash(\n txLike: ccc.TransactionLike,\n scriptHashLike: ccc.HexLike,\n): Action[] {\n const scriptHash = ccc.hexFrom(scriptHashLike);\n const { actions } = parseActions(txLike);\n return actions.filter((action) => action.scriptHash === scriptHash);\n}\n\n/**\n * Filters actions in a transaction matching the given ScriptInfo.\n * @param txLike The transaction containing the witnesses.\n * @param scriptInfoLike The ScriptInfo metadata to match.\n * @returns The list of matching actions.\n */\nexport function findActionsByScriptInfo(\n txLike: ccc.TransactionLike,\n scriptInfoLike: ScriptInfoLike,\n): Action[] {\n const scriptInfoHash = ScriptInfo.from(scriptInfoLike).hash();\n return findActionsByScriptInfoHash(txLike, scriptInfoHash);\n}\n\n/**\n * Filters actions in a transaction matching the given ScriptInfo hash.\n * @param txLike The transaction containing the witnesses.\n * @param scriptInfoHashLike The ScriptInfo hash to match.\n * @returns The list of matching actions.\n */\nexport function findActionsByScriptInfoHash(\n txLike: ccc.TransactionLike,\n scriptInfoHashLike: ccc.HexLike,\n): Action[] {\n const scriptInfoHash = ccc.hexFrom(scriptInfoHashLike);\n const { actions } = parseActions(txLike);\n return actions.filter((action) => action.scriptInfoHash === scriptInfoHash);\n}\n\n/**\n * CoBuild helper class associated with a specific script and script info,\n * delegating actions to top-level helper functions.\n */\nexport class CoBuild {\n /**\n * The ScriptInfo metadata used for building actions.\n */\n public readonly scriptInfo: ScriptInfo;\n /**\n * The CKB script executing the actions.\n */\n public readonly script: ccc.Script;\n /**\n * Hex-encoded hash of the ScriptInfo.\n */\n public readonly scriptInfoHash: ccc.Hex;\n /**\n * Hex-encoded script hash.\n */\n public readonly scriptHash: ccc.Hex;\n\n /**\n * Constructs a CoBuild instance.\n * @param script The target CKB Script.\n * @param scriptInfo The ScriptInfo metadata.\n */\n constructor(\n script: ccc.ScriptLike,\n scriptInfo?: Omit<ScriptInfoLike, \"scriptHash\"> | null,\n ) {\n this.script = ccc.Script.from(script);\n this.scriptHash = this.script.hash();\n this.scriptInfo = ScriptInfo.from({\n ...(scriptInfo ?? {}),\n scriptHash: this.script.hash(),\n });\n this.scriptInfoHash = this.scriptInfo.hash();\n }\n\n /**\n * Helper to construct an Action with prefilled scriptInfoHash and scriptHash.\n * @param data The custom action payload data (either raw bytes or a serialized ccc Entity).\n * @returns A new Action instance.\n */\n buildAction(data: ccc.BytesLike | ccc.Entity): Action {\n return Action.from({\n scriptInfoHash: this.scriptInfoHash,\n scriptHash: this.scriptHash,\n data: data instanceof ccc.Entity ? data.toBytes() : data,\n });\n }\n\n /**\n * Parses the CoBuild actions from the last witness of a transaction.\n * @param txLike The transaction containing the witnesses.\n * @param shouldRemoveParsedWitness If true, removes the last witness from the returned transaction.\n * @returns An object containing the parsed actions and the transaction.\n */\n parseActions(\n txLike: ccc.TransactionLike,\n shouldRemoveParsedWitness: boolean = false,\n ): {\n actions: Action[];\n tx: ccc.Transaction;\n } {\n return parseActions(txLike, shouldRemoveParsedWitness);\n }\n\n /**\n * Parses existing actions, executes a manipulator function to modify or add actions,\n * and encodes/updates the witness layout at the correct index.\n * @param txLike The target transaction.\n * @param manipulator A function that takes the current actions and returns updated actions.\n * @returns The updated transaction and the index of the modified witness.\n */\n manipulateActions(\n txLike: ccc.TransactionLike,\n manipulator: (actions: Action[]) => Action[] | Promise<Action[]>,\n ): Promise<{\n tx: ccc.Transaction;\n witnessIndex: number;\n }> {\n return manipulateActions(txLike, manipulator);\n }\n\n /**\n * Appends actions to the transaction's CoBuild witness using the script context.\n * Supports single, iterables, or async iterables of actions or entities.\n * @param txLike The target transaction.\n * @param actions The action(s) to append.\n * @returns The updated transaction and the index of the witness.\n */\n async appendActions(\n txLike: ccc.TransactionLike,\n actions:\n | ActionLike\n | ccc.Entity\n | Iterable<ActionLike | ccc.Entity>\n | AsyncIterable<ActionLike | ccc.Entity>,\n ): Promise<{\n tx: ccc.Transaction;\n witnessIndex: number;\n }> {\n const actionList: (ActionLike | ccc.Entity)[] = [];\n if (typeof actions === \"object\" && actions !== null) {\n if (Symbol.iterator in actions) {\n for (const action of actions) {\n actionList.push(action);\n }\n } else if (Symbol.asyncIterator in actions) {\n for await (const action of actions) {\n actionList.push(action);\n }\n } else {\n actionList.push(actions);\n }\n }\n\n return this.manipulateActions(txLike, (existedActions) =>\n existedActions.concat(\n actionList.map((action) => {\n if (typeof action === \"object\" && action !== null) {\n if (\n \"scriptInfoHash\" in action &&\n \"scriptHash\" in action &&\n \"data\" in action\n ) {\n return Action.from(action);\n }\n }\n return this.buildAction(action);\n }),\n ),\n );\n }\n\n /**\n * Filters actions in a transaction matching the given CKB Script.\n * If omitted or null, defaults to the helper's script.\n * @param txLike The transaction containing the witnesses.\n * @param scriptLike The script to match actions against.\n * @returns The list of matching actions.\n */\n findActions(\n txLike: ccc.TransactionLike,\n scriptLike?: ccc.ScriptLike | null,\n ): Action[] {\n return findActionsByHash(\n txLike,\n scriptLike ? ccc.Script.from(scriptLike).hash() : this.scriptHash,\n );\n }\n\n /**\n * Filters actions in a transaction matching the given script hash.\n * If omitted or null, defaults to the helper's script hash.\n * @param txLike The transaction containing the witnesses.\n * @param scriptHashLike The script hash to match.\n * @returns The list of matching actions.\n */\n findActionsByHash(\n txLike: ccc.TransactionLike,\n scriptHashLike?: ccc.HexLike | null,\n ): Action[] {\n return findActionsByHash(txLike, scriptHashLike ?? this.scriptHash);\n }\n\n /**\n * Filters actions in a transaction matching the given ScriptInfo.\n * If omitted or null, defaults to the helper's script info.\n * @param txLike The transaction containing the witnesses.\n * @param scriptInfoLike The ScriptInfo metadata to match.\n * @returns The list of matching actions.\n */\n findActionsByScriptInfo(\n txLike: ccc.TransactionLike,\n scriptInfoLike?: ScriptInfoLike | null,\n ): Action[] {\n return findActionsByScriptInfoHash(\n txLike,\n scriptInfoLike\n ? ScriptInfo.from(scriptInfoLike).hash()\n : this.scriptInfoHash,\n );\n }\n\n /**\n * Filters actions in a transaction matching the given ScriptInfo hash.\n * If omitted or null, defaults to the helper's script info hash.\n * @param txLike The transaction containing the witnesses.\n * @param scriptInfoHashLike The ScriptInfo hash to match.\n * @returns The list of matching actions.\n */\n findActionsByScriptInfoHash(\n txLike: ccc.TransactionLike,\n scriptInfoHashLike?: ccc.HexLike | null,\n ): Action[] {\n return findActionsByScriptInfoHash(\n txLike,\n scriptInfoHashLike ?? this.scriptInfoHash,\n );\n }\n}\n","export * from \"./coBuild.js\";\nexport * from \"./codec/index.js\";\n"],"mappings":"4aAEA,MAAa,EAAc,EAAI,MAAM,CACnC,eAAgB,EAAI,OACpB,WAAY,EAAI,OAChB,KAAM,EAAI,KACZ,CAAC,EAWM,IAAA,EAAA,cAAqB,EAAI,OAAO,KAAyB,CAAC,AAAC,CAWhE,YAAY,CACV,iBACA,aACA,QACsC,CACtC,MAAM,EAEN,KAAK,eAAiB,EACtB,KAAK,WAAa,EAClB,KAAK,KAAO,CACd,CACF,OAvBC,EAAI,MAAM,CAAW,CAAA,EAAA,CAAA,EA4BtB,MAAa,EAAY,EAAI,OAAO,CAAM,EAE7B,EAAe,EAAI,MAAM,CACpC,QAAS,CACX,CAAC,EAWM,IAAA,EAAA,cAAsB,EAAI,OAAO,KAA2B,CAAC,AAAC,CAOnE,YAAY,CAAE,WAAiD,CAC7D,MAAM,EAEN,KAAK,QAAU,CACjB,CACF,OAbC,EAAI,MAAM,CAAY,CAAA,EAAA,CAAA,EAevB,MAAa,EAAkB,EAAI,MAAM,CACvC,KAAM,EAAI,OACV,IAAK,EAAI,O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