@ckb-ccc/type-id 0.1.0 → 0.1.2

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,17 @@
1
1
  # @ckb-ccc/type-id
2
2
 
3
+ ## 0.1.2
4
+ ### Patch Changes
5
+
6
+ - Updated dependencies [[`209f332`](https://github.com/ckb-devrel/ccc/commit/209f3322ffc22860b1ad43f31cbf51322493b3d9), [`ac8dba2`](https://github.com/ckb-devrel/ccc/commit/ac8dba21ab899b707e46236aa40b9e12566f9c8a), [`52309a4`](https://github.com/ckb-devrel/ccc/commit/52309a442a48f1c376fa65813ba56bcceb405b90)]:
7
+ - @ckb-ccc/core@1.16.0
8
+
9
+ ## 0.1.1
10
+ ### Patch Changes
11
+
12
+ - Updated dependencies [[`98597b5`](https://github.com/ckb-devrel/ccc/commit/98597b56eb6eeb029b72ea963649155dfe1f4215), [`bef9d0a`](https://github.com/ckb-devrel/ccc/commit/bef9d0a037fba045eab24d7ad55400fa26fbbffd), [`8067a08`](https://github.com/ckb-devrel/ccc/commit/8067a08de041ffd7a624adea0b594eb283e2634e), [`7019a1a`](https://github.com/ckb-devrel/ccc/commit/7019a1a7f765dfa7940cdfe51474bcd347f18ec6), [`9beee4d`](https://github.com/ckb-devrel/ccc/commit/9beee4d7f39e4b4b19919c5feb86e1c8be0e089d), [`2d4e701`](https://github.com/ckb-devrel/ccc/commit/2d4e701e54e9bf5247c2363490009acc5606c0ea), [`0eb8435`](https://github.com/ckb-devrel/ccc/commit/0eb8435d9694602fce3b7e6a95f04f793452a88d)]:
13
+ - @ckb-ccc/core@1.15.0
14
+
3
15
  ## 0.1.0
4
16
  ### Minor Changes
5
17
 
@@ -1 +1 @@
1
- {"version":3,"file":"advancedBarrel.d.mts","names":[],"sources":["../src/advancedBarrel.ts"],"mappings":";;;;;;;;;;AAWA;;;;iBAAgB,qBAAA,aACF,GAAA,CAAI,SAAA,YACN,GA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;EAAA,IAG9D,OAAA;IACD,EAAA,EAAI,GAAA,CAAI,WAAA;IACR,OAAA;IACA,QAAA;EAAA;EA/HM;;;;;;;;sBA0LI,KAAA;IAER,MAAA,EAAQ,GAAA,CAAI,MAAA;IACZ,EAAA,EAAI,GAAA,CAAI,OAAA;IACR,EAAA,GAAK,GAAA,CAAI,eAAA;EAAA,IAEV,OAAA;IACD,EAAA,EAAI,GAAA,CAAI,WAAA;IACR,KAAA;EAAA;AAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"advancedBarrel.mjs","names":[],"sources":["../src/advancedBarrel.ts"],"sourcesContent":["import { ccc } from \"@ckb-ccc/core\";\n\n/**\n * Build Type ID operations.\n *\n * @param props The properties to build the operations.\n * @param props.getScriptInfo Function to get the script info.\n * @param props.calculateTypeId Function to calculate the Type ID.\n * @param props.addCellDeps Function to add cell dependencies.\n */\n\nexport function buildTypeIdOperations<\n Encodable = ccc.BytesLike,\n Decoded = ccc.Bytes,\n>(props: {\n getScriptInfo: (client: ccc.Client) => Promise<ccc.ScriptInfoLike>;\n codec?: ccc.CodecLike<Encodable, Decoded> | null;\n calculateTypeId?:\n | ((client: ccc.Client, tx: ccc.Transaction) => Promise<ccc.HexLike>)\n | null;\n addCellDeps?:\n | ((\n client: ccc.Client,\n tx: ccc.Transaction,\n scriptInfo: ccc.ScriptInfo,\n ) => Promise<ccc.TransactionLike>)\n | null;\n}) {\n async function getScriptInfo(client: ccc.Client): Promise<ccc.ScriptInfo> {\n return ccc.ScriptInfo.from(await props.getScriptInfo(client));\n }\n\n const codec = (\n props.codec ? ccc.Codec.from(props.codec) : ccc.CodecRaw\n ) as ccc.Codec<Encodable, Decoded>;\n\n function getTypeScript(scriptInfo: ccc.ScriptInfo, args: ccc.HexLike) {\n return ccc.Script.from({\n ...scriptInfo,\n args,\n });\n }\n\n async function addCellDeps(\n client: ccc.Client,\n tx: ccc.Transaction,\n scriptInfo: ccc.ScriptInfo,\n ): Promise<ccc.Transaction> {\n if (props.addCellDeps) {\n return ccc.Transaction.from(\n await props.addCellDeps(client, tx, scriptInfo),\n );\n }\n\n tx.addCellDeps(...(await client.getCellDeps(scriptInfo.cellDeps)));\n return tx;\n }\n\n async function calculateTypeId(\n client: ccc.Client,\n tx: ccc.Transaction,\n ): Promise<ccc.Hex> {\n if (props.calculateTypeId) {\n return ccc.hexFrom(await props.calculateTypeId(client, tx));\n }\n\n return ccc.hashTypeId(tx.inputs[0], tx.outputs.length);\n }\n\n return {\n /**\n * Create a Type ID cell.\n *\n * @param props The arguments for creating the cell.\n * @param props.signer The signer to sign the transaction.\n * @param props.receiver The receiver script (optional).\n * @param props.data The output data.\n * @param props.tx The transaction skeleton (optional).\n */\n async create(\n this: void,\n props: {\n signer: ccc.Signer;\n data: Encodable;\n receiver?: ccc.ScriptLike | null;\n tx?: ccc.TransactionLike | null;\n },\n ): Promise<{\n tx: ccc.Transaction;\n id: ccc.Hex;\n index: number;\n }> {\n const { signer, receiver, data, tx: txLike } = props;\n const tx = ccc.Transaction.from(txLike ?? {});\n\n await tx.completeInputsAtLeastOne(signer);\n const id = await calculateTypeId(signer.client, tx);\n\n const scriptInfo = await getScriptInfo(signer.client);\n const len = tx.addOutput({\n cellOutput: {\n type: getTypeScript(scriptInfo, id),\n lock: receiver\n ? ccc.Script.from(receiver)\n : (await signer.getRecommendedAddressObj()).script,\n },\n outputData: codec.encode(data),\n });\n\n return {\n tx: await addCellDeps(signer.client, tx, scriptInfo),\n id,\n index: len - 1,\n };\n },\n\n /**\n * Transfer a Type ID cell.\n *\n * @param props The arguments for transferring the cell.\n * @param props.client The client to communicate with CKB.\n * @param props.id The Type ID to transfer.\n * @param props.receiver The new receiver script.\n * @param props.tx The transaction skeleton (optional).\n * @param props.data The new output data or a transformer to update the data (optional).\n */\n async transfer(\n this: void,\n props: {\n client: ccc.Client;\n id: ccc.HexLike;\n receiver: ccc.ScriptLike;\n tx?: ccc.TransactionLike | null;\n data?:\n | Encodable\n | ((cell: ccc.Cell, data?: Decoded) => Encodable | Promise<Encodable>)\n | null;\n },\n ): Promise<{\n tx: ccc.Transaction;\n inIndex: number;\n outIndex: number;\n }> {\n const { client, id, receiver, tx: txLike, data } = props;\n const tx = ccc.Transaction.from(txLike ?? {});\n\n const scriptInfo = await getScriptInfo(client);\n const type = getTypeScript(scriptInfo, id);\n const inCell = await client.findSingletonCellByType(type);\n if (!inCell) {\n throw new Error(`Type ID ${ccc.stringify(type)} not found`);\n }\n\n const outputData = await (async () => {\n if (!data) {\n return inCell.outputData;\n }\n\n if (typeof data === \"function\") {\n return codec.encode(\n await (\n data as (\n cell: ccc.Cell,\n data?: Decoded,\n ) => Encodable | Promise<Encodable>\n )(inCell, codec.decodeOr(inCell.outputData, undefined)),\n );\n }\n\n return codec.encode(data);\n })();\n\n const outCell = ccc.CellAny.from({\n ...inCell,\n cellOutput: {\n ...inCell.cellOutput,\n lock: ccc.Script.from(receiver),\n },\n outputData,\n });\n\n const inLen = tx.addInput(inCell);\n const outLen = tx.addOutput(outCell);\n\n return {\n tx: await addCellDeps(client, tx, scriptInfo),\n inIndex: inLen - 1,\n outIndex: outLen - 1,\n };\n },\n\n /**\n * Destroy a Type ID cell.\n *\n * @param props The arguments for destroying the cell.\n * @param props.client The client to communicate with CKB.\n * @param props.id The Type ID to destroy.\n * @param props.tx The transaction skeleton (optional).\n */\n async destroy(\n this: void,\n props: {\n client: ccc.Client;\n id: ccc.HexLike;\n tx?: ccc.TransactionLike | null;\n },\n ): Promise<{\n tx: ccc.Transaction;\n index: number;\n }> {\n const { client, id, tx: txLike } = props;\n const tx = ccc.Transaction.from(txLike ?? {});\n\n const scriptInfo = await getScriptInfo(client);\n const type = getTypeScript(scriptInfo, id);\n const cell = await client.findSingletonCellByType(type);\n if (!cell) {\n throw new Error(`Type ID ${ccc.stringify(type)} not found`);\n }\n\n const len = tx.addInput(cell);\n\n return {\n tx: await addCellDeps(client, tx, scriptInfo),\n index: len - 1,\n };\n },\n };\n}\n"],"mappings":"+HAWA,SAAgB,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c/core\";\n\n/**\n * Build Type ID operations.\n *\n * @param props The properties to build the operations.\n * @param props.getScriptInfo Function to get the script info.\n * @param props.calculateTypeId Function to calculate the Type ID.\n * @param props.addCellDeps Function to add cell dependencies.\n */\n\nexport function buildTypeIdOperations<\n Encodable = ccc.BytesLike,\n Decoded = ccc.Bytes,\n>(props: {\n getScriptInfo: (client: ccc.Client) => Promise<ccc.ScriptInfoLike>;\n codec?: ccc.CodecLike<Encodable, Decoded> | null;\n calculateTypeId?:\n ((client: ccc.Client, tx: ccc.Transaction) => Promise<ccc.HexLike>) | null;\n addCellDeps?:\n | ((\n client: ccc.Client,\n tx: ccc.Transaction,\n scriptInfo: ccc.ScriptInfo,\n ) => Promise<ccc.TransactionLike>)\n | null;\n}) {\n async function getScriptInfo(client: ccc.Client): Promise<ccc.ScriptInfo> {\n return ccc.ScriptInfo.from(await props.getScriptInfo(client));\n }\n\n const codec = (\n props.codec ? ccc.Codec.from(props.codec) : ccc.CodecRaw\n ) as ccc.Codec<Encodable, Decoded>;\n\n function getTypeScript(scriptInfo: ccc.ScriptInfo, args: ccc.HexLike) {\n return ccc.Script.from({\n ...scriptInfo,\n args,\n });\n }\n\n async function addCellDeps(\n client: ccc.Client,\n tx: ccc.Transaction,\n scriptInfo: ccc.ScriptInfo,\n ): Promise<ccc.Transaction> {\n if (props.addCellDeps) {\n return ccc.Transaction.from(\n await props.addCellDeps(client, tx, scriptInfo),\n );\n }\n\n tx.addCellDeps(...(await client.getCellDeps(scriptInfo.cellDeps)));\n return tx;\n }\n\n async function calculateTypeId(\n client: ccc.Client,\n tx: ccc.Transaction,\n ): Promise<ccc.Hex> {\n if (props.calculateTypeId) {\n return ccc.hexFrom(await props.calculateTypeId(client, tx));\n }\n\n return ccc.hashTypeId(tx.inputs[0], tx.outputs.length);\n }\n\n return {\n /**\n * Create a Type ID cell.\n *\n * @param props The arguments for creating the cell.\n * @param props.signer The signer to sign the transaction.\n * @param props.receiver The receiver script (optional).\n * @param props.data The output data.\n * @param props.tx The transaction skeleton (optional).\n */\n async create(\n this: void,\n props: {\n signer: ccc.Signer;\n data: Encodable;\n receiver?: ccc.ScriptLike | null;\n tx?: ccc.TransactionLike | null;\n },\n ): Promise<{\n tx: ccc.Transaction;\n id: ccc.Hex;\n index: number;\n }> {\n const { signer, receiver, data, tx: txLike } = props;\n const tx = ccc.Transaction.from(txLike ?? {});\n\n await tx.completeInputsAtLeastOne(signer);\n const id = await calculateTypeId(signer.client, tx);\n\n const scriptInfo = await getScriptInfo(signer.client);\n const len = tx.addOutput({\n cellOutput: {\n type: getTypeScript(scriptInfo, id),\n lock: receiver\n ? ccc.Script.from(receiver)\n : (await signer.getRecommendedAddressObj()).script,\n },\n outputData: codec.encode(data),\n });\n\n return {\n tx: await addCellDeps(signer.client, tx, scriptInfo),\n id,\n index: len - 1,\n };\n },\n\n /**\n * Transfer a Type ID cell.\n *\n * @param props The arguments for transferring the cell.\n * @param props.client The client to communicate with CKB.\n * @param props.id The Type ID to transfer.\n * @param props.receiver The new receiver script.\n * @param props.tx The transaction skeleton (optional).\n * @param props.data The new output data or a transformer to update the data (optional).\n */\n async transfer(\n this: void,\n props: {\n client: ccc.Client;\n id: ccc.HexLike;\n receiver: ccc.ScriptLike;\n tx?: ccc.TransactionLike | null;\n data?:\n | Encodable\n | ((cell: ccc.Cell, data?: Decoded) => Encodable | Promise<Encodable>)\n | null;\n },\n ): Promise<{\n tx: ccc.Transaction;\n inIndex: number;\n outIndex: number;\n }> {\n const { client, id, receiver, tx: txLike, data } = props;\n const tx = ccc.Transaction.from(txLike ?? {});\n\n const scriptInfo = await getScriptInfo(client);\n const type = getTypeScript(scriptInfo, id);\n const inCell = await client.findSingletonCellByType(type);\n if (!inCell) {\n throw new Error(`Type ID ${ccc.stringify(type)} not found`);\n }\n\n const outputData = await (async () => {\n if (!data) {\n return inCell.outputData;\n }\n\n if (typeof data === \"function\") {\n return codec.encode(\n await (\n data as (\n cell: ccc.Cell,\n data?: Decoded,\n ) => Encodable | Promise<Encodable>\n )(inCell, codec.decodeOr(inCell.outputData, undefined)),\n );\n }\n\n return codec.encode(data);\n })();\n\n const outCell = ccc.CellAny.from({\n ...inCell,\n cellOutput: {\n ...inCell.cellOutput,\n lock: ccc.Script.from(receiver),\n },\n outputData,\n });\n\n const inLen = tx.addInput(inCell);\n const outLen = tx.addOutput(outCell);\n\n return {\n tx: await addCellDeps(client, tx, scriptInfo),\n inIndex: inLen - 1,\n outIndex: outLen - 1,\n };\n },\n\n /**\n * Destroy a Type ID cell.\n *\n * @param props The arguments for destroying the cell.\n * @param props.client The client to communicate with CKB.\n * @param props.id The Type ID to destroy.\n * @param props.tx The transaction skeleton (optional).\n */\n async destroy(\n this: void,\n props: {\n client: ccc.Client;\n id: ccc.HexLike;\n tx?: ccc.TransactionLike | null;\n },\n ): Promise<{\n tx: ccc.Transaction;\n index: number;\n }> {\n const { client, id, tx: txLike } = props;\n const tx = ccc.Transaction.from(txLike ?? {});\n\n const scriptInfo = await getScriptInfo(client);\n const type = getTypeScript(scriptInfo, id);\n const cell = await client.findSingletonCellByType(type);\n if (!cell) {\n throw new Error(`Type ID ${ccc.stringify(type)} not found`);\n }\n\n const len = tx.addInput(cell);\n\n return {\n tx: await addCellDeps(client, tx, scriptInfo),\n index: len - 1,\n };\n },\n };\n}\n"],"mappings":"+HAWA,SAAgB,EAGd,EAYC,CACD,eAAe,EAAc,EAA6C,CACxE,OAAO,EAAI,WAAW,KAAK,MAAM,EAAM,cAAc,CAAM,CAAC,CAC9D,CAEA,IAAM,EACJ,EAAM,MAAQ,EAAI,MAAM,KAAK,EAAM,KAAK,EAAI,EAAI,SAGlD,SAAS,EAAc,EAA4B,EAAmB,CACpE,OAAO,EAAI,OAAO,KAAK,CACrB,GAAG,EACH,MACF,CAAC,CACH,CAEA,eAAe,EACb,EACA,EACA,EAC0B,CAQ1B,OAPI,EAAM,YACD,EAAI,YAAY,KACrB,MAAM,EAAM,YAAY,EAAQ,EAAI,CAAU,CAChD,GAGF,EAAG,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"],"sources":["../src/advancedBarrel.ts"],"sourcesContent":["import { ccc } from \"@ckb-ccc/core\";\n\n/**\n * Build Type ID operations.\n *\n * @param props The properties to build the operations.\n * @param props.getScriptInfo Function to get the script info.\n * @param props.calculateTypeId Function to calculate the Type ID.\n * @param props.addCellDeps Function to add cell dependencies.\n */\n\nexport function buildTypeIdOperations<\n Encodable = ccc.BytesLike,\n Decoded = ccc.Bytes,\n>(props: {\n getScriptInfo: (client: ccc.Client) => Promise<ccc.ScriptInfoLike>;\n codec?: ccc.CodecLike<Encodable, Decoded> | null;\n calculateTypeId?:\n | ((client: ccc.Client, tx: ccc.Transaction) => Promise<ccc.HexLike>)\n | null;\n addCellDeps?:\n | ((\n client: ccc.Client,\n tx: ccc.Transaction,\n scriptInfo: ccc.ScriptInfo,\n ) => Promise<ccc.TransactionLike>)\n | null;\n}) {\n async function getScriptInfo(client: ccc.Client): Promise<ccc.ScriptInfo> {\n return ccc.ScriptInfo.from(await props.getScriptInfo(client));\n }\n\n const codec = (\n props.codec ? ccc.Codec.from(props.codec) : ccc.CodecRaw\n ) as ccc.Codec<Encodable, Decoded>;\n\n function getTypeScript(scriptInfo: ccc.ScriptInfo, args: ccc.HexLike) {\n return ccc.Script.from({\n ...scriptInfo,\n args,\n });\n }\n\n async function addCellDeps(\n client: ccc.Client,\n tx: ccc.Transaction,\n scriptInfo: ccc.ScriptInfo,\n ): Promise<ccc.Transaction> {\n if (props.addCellDeps) {\n return ccc.Transaction.from(\n await props.addCellDeps(client, tx, scriptInfo),\n );\n }\n\n tx.addCellDeps(...(await client.getCellDeps(scriptInfo.cellDeps)));\n return tx;\n }\n\n async function calculateTypeId(\n client: ccc.Client,\n tx: ccc.Transaction,\n ): Promise<ccc.Hex> {\n if (props.calculateTypeId) {\n return ccc.hexFrom(await props.calculateTypeId(client, tx));\n }\n\n return ccc.hashTypeId(tx.inputs[0], tx.outputs.length);\n }\n\n return {\n /**\n * Create a Type ID cell.\n *\n * @param props The arguments for creating the cell.\n * @param props.signer The signer to sign the transaction.\n * @param props.receiver The receiver script (optional).\n * @param props.data The output data.\n * @param props.tx The transaction skeleton (optional).\n */\n async create(\n this: void,\n props: {\n signer: ccc.Signer;\n data: Encodable;\n receiver?: ccc.ScriptLike | null;\n tx?: ccc.TransactionLike | null;\n },\n ): Promise<{\n tx: ccc.Transaction;\n id: ccc.Hex;\n index: number;\n }> {\n const { signer, receiver, data, tx: txLike } = props;\n const tx = ccc.Transaction.from(txLike ?? {});\n\n await tx.completeInputsAtLeastOne(signer);\n const id = await calculateTypeId(signer.client, tx);\n\n const scriptInfo = await getScriptInfo(signer.client);\n const len = tx.addOutput({\n cellOutput: {\n type: getTypeScript(scriptInfo, id),\n lock: receiver\n ? ccc.Script.from(receiver)\n : (await signer.getRecommendedAddressObj()).script,\n },\n outputData: codec.encode(data),\n });\n\n return {\n tx: await addCellDeps(signer.client, tx, scriptInfo),\n id,\n index: len - 1,\n };\n },\n\n /**\n * Transfer a Type ID cell.\n *\n * @param props The arguments for transferring the cell.\n * @param props.client The client to communicate with CKB.\n * @param props.id The Type ID to transfer.\n * @param props.receiver The new receiver script.\n * @param props.tx The transaction skeleton (optional).\n * @param props.data The new output data or a transformer to update the data (optional).\n */\n async transfer(\n this: void,\n props: {\n client: ccc.Client;\n id: ccc.HexLike;\n receiver: ccc.ScriptLike;\n tx?: ccc.TransactionLike | null;\n data?:\n | Encodable\n | ((cell: ccc.Cell, data?: Decoded) => Encodable | Promise<Encodable>)\n | null;\n },\n ): Promise<{\n tx: ccc.Transaction;\n inIndex: number;\n outIndex: number;\n }> {\n const { client, id, receiver, tx: txLike, data } = props;\n const tx = ccc.Transaction.from(txLike ?? {});\n\n const scriptInfo = await getScriptInfo(client);\n const type = getTypeScript(scriptInfo, id);\n const inCell = await client.findSingletonCellByType(type);\n if (!inCell) {\n throw new Error(`Type ID ${ccc.stringify(type)} not found`);\n }\n\n const outputData = await (async () => {\n if (!data) {\n return inCell.outputData;\n }\n\n if (typeof data === \"function\") {\n return codec.encode(\n await (\n data as (\n cell: ccc.Cell,\n data?: Decoded,\n ) => Encodable | Promise<Encodable>\n )(inCell, codec.decodeOr(inCell.outputData, undefined)),\n );\n }\n\n return codec.encode(data);\n })();\n\n const outCell = ccc.CellAny.from({\n ...inCell,\n cellOutput: {\n ...inCell.cellOutput,\n lock: ccc.Script.from(receiver),\n },\n outputData,\n });\n\n const inLen = tx.addInput(inCell);\n const outLen = tx.addOutput(outCell);\n\n return {\n tx: await addCellDeps(client, tx, scriptInfo),\n inIndex: inLen - 1,\n outIndex: outLen - 1,\n };\n },\n\n /**\n * Destroy a Type ID cell.\n *\n * @param props The arguments for destroying the cell.\n * @param props.client The client to communicate with CKB.\n * @param props.id The Type ID to destroy.\n * @param props.tx The transaction skeleton (optional).\n */\n async destroy(\n this: void,\n props: {\n client: ccc.Client;\n id: ccc.HexLike;\n tx?: ccc.TransactionLike | null;\n },\n ): Promise<{\n tx: ccc.Transaction;\n index: number;\n }> {\n const { client, id, tx: txLike } = props;\n const tx = ccc.Transaction.from(txLike ?? {});\n\n const scriptInfo = await getScriptInfo(client);\n const type = getTypeScript(scriptInfo, id);\n const cell = await client.findSingletonCellByType(type);\n if (!cell) {\n throw new Error(`Type ID ${ccc.stringify(type)} not found`);\n }\n\n const len = tx.addInput(cell);\n\n return {\n tx: await addCellDeps(client, tx, scriptInfo),\n index: len - 1,\n };\n },\n };\n}\n"],"mappings":"6LAWA,SAAgB,EAGd,EAaC,CACD,eAAe,EAAc,EAA6C,CACxE,OAAOA,EAAAA,IAAI,WAAW,KAAK,MAAM,EAAM,cAAc,CAAM,CAAC,CAC9D,CAEA,IAAM,EACJ,EAAM,MAAQA,EAAAA,IAAI,MAAM,KAAK,EAAM,KAAK,EAAIA,EAAAA,IAAI,SAGlD,SAAS,EAAc,EAA4B,EAAmB,CACpE,OAAOA,EAAAA,IAAI,OAAO,KAAK,CACrB,GAAG,EACH,MACF,CAAC,CACH,CAEA,eAAe,EACb,EACA,EACA,EAC0B,CAQ1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AAM,EAAa,MAAO,SACnB,EAID,OAAO,GAAS,WACX,EAAM,OACX,MACE,EAIA,EAAQ,EAAM,SAAS,EAAO,WAAY,IAAA,EAAS,CAAC,CACxD,EAGK,EAAM,OAAO,CAAI,EAdf,EAAO,WAelB,CAAG,EAEG,EAAUA,EAAAA,IAAI,QAAQ,KAAK,CAC/B,GAAG,EACH,WAAY,CACV,GAAG,EAAO,WACV,KAAMA,EAAAA,IAAI,OAAO,KAAK,CAAQ,CAChC,EACA,YACF,CAAC,EAEK,EAAQ,EAAG,SAAS,CAAM,EAC1B,EAAS,EAAG,UAAU,CAAO,EAEnC,MAAO,CACL,GAAI,MAAM,EAAY,EAAQ,EAAI,CAAU,EAC5C,QAAS,EAAQ,EACjB,SAAU,EAAS,CACrB,CACF,EAUA,MAAM,QAEJ,EAQC,CACD,GAAM,CAAE,SAAQ,KAAI,GAAI,GAAW,EAC7B,EAAKA,EAAAA,IAAI,YAAY,KAAK,GAAU,CAAC,CAAC,EAEtC,EAAa,MAAM,EAAc,CAAM,EACvC,EAAO,EAAc,EAAY,CAAE,EACnC,EAAO,MAAM,EAAO,wBAAwB,CAAI,EACtD,GAAI,CAAC,EACH,MAAU,MAAM,WAAWA,EAAAA,IAAI,UAAU,CAAI,EAAE,WAAW,EAG5D,IAAM,EAAM,EAAG,SAAS,CAAI,EAE5B,MAAO,CACL,GAAI,MAAM,EAAY,EAAQ,EAAI,CAAU,EAC5C,MAAO,EAAM,CACf,CACF,CACF,CACF"}
1
+ {"version":3,"file":"advancedBarrel.js","names":["ccc"],"sources":["../src/advancedBarrel.ts"],"sourcesContent":["import { ccc } from \"@ckb-ccc/core\";\n\n/**\n * Build Type ID operations.\n *\n * @param props The properties to build the operations.\n * @param props.getScriptInfo Function to get the script info.\n * @param props.calculateTypeId Function to calculate the Type ID.\n * @param props.addCellDeps Function to add cell dependencies.\n */\n\nexport function buildTypeIdOperations<\n Encodable = ccc.BytesLike,\n Decoded = ccc.Bytes,\n>(props: {\n getScriptInfo: (client: ccc.Client) => Promise<ccc.ScriptInfoLike>;\n codec?: ccc.CodecLike<Encodable, Decoded> | null;\n calculateTypeId?:\n ((client: ccc.Client, tx: ccc.Transaction) => Promise<ccc.HexLike>) | null;\n addCellDeps?:\n | ((\n client: ccc.Client,\n tx: ccc.Transaction,\n scriptInfo: ccc.ScriptInfo,\n ) => Promise<ccc.TransactionLike>)\n | null;\n}) {\n async function getScriptInfo(client: ccc.Client): Promise<ccc.ScriptInfo> {\n return ccc.ScriptInfo.from(await props.getScriptInfo(client));\n }\n\n const codec = (\n props.codec ? ccc.Codec.from(props.codec) : ccc.CodecRaw\n ) as ccc.Codec<Encodable, Decoded>;\n\n function getTypeScript(scriptInfo: ccc.ScriptInfo, args: ccc.HexLike) {\n return ccc.Script.from({\n ...scriptInfo,\n args,\n });\n }\n\n async function addCellDeps(\n client: ccc.Client,\n tx: ccc.Transaction,\n scriptInfo: ccc.ScriptInfo,\n ): Promise<ccc.Transaction> {\n if (props.addCellDeps) {\n return ccc.Transaction.from(\n await props.addCellDeps(client, tx, scriptInfo),\n );\n }\n\n tx.addCellDeps(...(await client.getCellDeps(scriptInfo.cellDeps)));\n return tx;\n }\n\n async function calculateTypeId(\n client: ccc.Client,\n tx: ccc.Transaction,\n ): Promise<ccc.Hex> {\n if (props.calculateTypeId) {\n return ccc.hexFrom(await props.calculateTypeId(client, tx));\n }\n\n return ccc.hashTypeId(tx.inputs[0], tx.outputs.length);\n }\n\n return {\n /**\n * Create a Type ID cell.\n *\n * @param props The arguments for creating the cell.\n * @param props.signer The signer to sign the transaction.\n * @param props.receiver The receiver script (optional).\n * @param props.data The output data.\n * @param props.tx The transaction skeleton (optional).\n */\n async create(\n this: void,\n props: {\n signer: ccc.Signer;\n data: Encodable;\n receiver?: ccc.ScriptLike | null;\n tx?: ccc.TransactionLike | null;\n },\n ): Promise<{\n tx: ccc.Transaction;\n id: ccc.Hex;\n index: number;\n }> {\n const { signer, receiver, data, tx: txLike } = props;\n const tx = ccc.Transaction.from(txLike ?? {});\n\n await tx.completeInputsAtLeastOne(signer);\n const id = await calculateTypeId(signer.client, tx);\n\n const scriptInfo = await getScriptInfo(signer.client);\n const len = tx.addOutput({\n cellOutput: {\n type: getTypeScript(scriptInfo, id),\n lock: receiver\n ? ccc.Script.from(receiver)\n : (await signer.getRecommendedAddressObj()).script,\n },\n outputData: codec.encode(data),\n });\n\n return {\n tx: await addCellDeps(signer.client, tx, scriptInfo),\n id,\n index: len - 1,\n };\n },\n\n /**\n * Transfer a Type ID cell.\n *\n * @param props The arguments for transferring the cell.\n * @param props.client The client to communicate with CKB.\n * @param props.id The Type ID to transfer.\n * @param props.receiver The new receiver script.\n * @param props.tx The transaction skeleton (optional).\n * @param props.data The new output data or a transformer to update the data (optional).\n */\n async transfer(\n this: void,\n props: {\n client: ccc.Client;\n id: ccc.HexLike;\n receiver: ccc.ScriptLike;\n tx?: ccc.TransactionLike | null;\n data?:\n | Encodable\n | ((cell: ccc.Cell, data?: Decoded) => Encodable | Promise<Encodable>)\n | null;\n },\n ): Promise<{\n tx: ccc.Transaction;\n inIndex: number;\n outIndex: number;\n }> {\n const { client, id, receiver, tx: txLike, data } = props;\n const tx = ccc.Transaction.from(txLike ?? {});\n\n const scriptInfo = await getScriptInfo(client);\n const type = getTypeScript(scriptInfo, id);\n const inCell = await client.findSingletonCellByType(type);\n if (!inCell) {\n throw new Error(`Type ID ${ccc.stringify(type)} not found`);\n }\n\n const outputData = await (async () => {\n if (!data) {\n return inCell.outputData;\n }\n\n if (typeof data === \"function\") {\n return codec.encode(\n await (\n data as (\n cell: ccc.Cell,\n data?: Decoded,\n ) => Encodable | Promise<Encodable>\n )(inCell, codec.decodeOr(inCell.outputData, undefined)),\n );\n }\n\n return codec.encode(data);\n })();\n\n const outCell = ccc.CellAny.from({\n ...inCell,\n cellOutput: {\n ...inCell.cellOutput,\n lock: ccc.Script.from(receiver),\n },\n outputData,\n });\n\n const inLen = tx.addInput(inCell);\n const outLen = tx.addOutput(outCell);\n\n return {\n tx: await addCellDeps(client, tx, scriptInfo),\n inIndex: inLen - 1,\n outIndex: outLen - 1,\n };\n },\n\n /**\n * Destroy a Type ID cell.\n *\n * @param props The arguments for destroying the cell.\n * @param props.client The client to communicate with CKB.\n * @param props.id The Type ID to destroy.\n * @param props.tx The transaction skeleton (optional).\n */\n async destroy(\n this: void,\n props: {\n client: ccc.Client;\n id: ccc.HexLike;\n tx?: ccc.TransactionLike | null;\n },\n ): Promise<{\n tx: ccc.Transaction;\n index: number;\n }> {\n const { client, id, tx: txLike } = props;\n const tx = ccc.Transaction.from(txLike ?? {});\n\n const scriptInfo = await getScriptInfo(client);\n const type = getTypeScript(scriptInfo, id);\n const cell = await client.findSingletonCellByType(type);\n if (!cell) {\n throw new Error(`Type ID ${ccc.stringify(type)} not found`);\n }\n\n const len = tx.addInput(cell);\n\n return {\n tx: await addCellDeps(client, tx, scriptInfo),\n index: len - 1,\n };\n },\n };\n}\n"],"mappings":"6LAWA,SAAgB,EAGd,EAYC,CACD,eAAe,EAAc,EAA6C,CACxE,OAAOA,EAAAA,IAAI,WAAW,KAAK,MAAM,EAAM,cAAc,CAAM,CAAC,CAC9D,CAEA,IAAM,EACJ,EAAM,MAAQA,EAAAA,IAAI,MAAM,KAAK,EAAM,KAAK,EAAIA,EAAAA,IAAI,SAGlD,SAAS,EAAc,EAA4B,EAAmB,CACpE,OAAOA,EAAAA,IAAI,OAAO,KAAK,CACrB,GAAG,EACH,MACF,CAAC,CACH,CAEA,eAAe,EACb,EACA,EACA,EAC0B,CAQ1B,OAPI,EAAM,YACDA,EAAAA,IAAI,YAAY,KACrB,MAAM,EAAM,YAAY,EAAQ,EAAI,CAAU,CAChD,GAGF,EAAG,YAAY,GAAI,MAAM,EAAO,YAAY,EAAW,QAAQ,CAAE,EAC1D,EACT,CAEA,eAAe,EACb,EACA,EACkB,CAKlB,OAJI,EAAM,gBACDA,EAAAA,IAAI,QAAQ,MAAM,EAAM,gBAAgB,EAAQ,CAAE,CAAC,E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AO,KAAK,CAAQ,CAChC,EACA,YACF,CAAC,EAEK,EAAQ,EAAG,SAAS,CAAM,EAC1B,EAAS,EAAG,UAAU,CAAO,EAEnC,MAAO,CACL,GAAI,MAAM,EAAY,EAAQ,EAAI,CAAU,EAC5C,QAAS,EAAQ,EACjB,SAAU,EAAS,CACrB,CACF,EAUA,MAAM,QAEJ,EAQC,CACD,GAAM,CAAE,SAAQ,KAAI,GAAI,GAAW,EAC7B,EAAKA,EAAAA,IAAI,YAAY,KAAK,GAAU,CAAC,CAAC,EAEtC,EAAa,MAAM,EAAc,CAAM,EACvC,EAAO,EAAc,EAAY,CAAE,EACnC,EAAO,MAAM,EAAO,wBAAwB,CAAI,EACtD,GAAI,CAAC,EACH,MAAU,MAAM,WAAWA,EAAAA,IAAI,UAAU,CAAI,EAAE,WAAW,EAG5D,IAAM,EAAM,EAAG,SAAS,CAAI,EAE5B,MAAO,CACL,GAAI,MAAM,EAAY,EAAQ,EAAI,CAAU,EAC5C,MAAO,EAAM,CACf,CACF,CACF,CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckb-ccc/type-id",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "CCC - CKBer's Codebase. CCC's support for Type ID",
5
5
  "author": "Hanssen0 <hanssen0@hanssen0.com>",
6
6
  "license": "MIT",
@@ -48,14 +48,14 @@
48
48
  "access": "public"
49
49
  },
50
50
  "dependencies": {
51
- "@ckb-ccc/core": "1.14.0"
51
+ "@ckb-ccc/core": "1.16.0"
52
52
  },
53
53
  "types": "./dist.commonjs/index.d.ts",
54
54
  "scripts": {
55
55
  "test": "vitest",
56
56
  "test:ci": "vitest run",
57
57
  "build": "tsdown",
58
- "lint": "eslint ./src",
58
+ "lint": "tsc --noEmit && eslint ./src",
59
59
  "format": "prettier --write . && eslint --fix ./src"
60
60
  }
61
61
  }
@@ -16,8 +16,7 @@ export function buildTypeIdOperations<
16
16
  getScriptInfo: (client: ccc.Client) => Promise<ccc.ScriptInfoLike>;
17
17
  codec?: ccc.CodecLike<Encodable, Decoded> | null;
18
18
  calculateTypeId?:
19
- | ((client: ccc.Client, tx: ccc.Transaction) => Promise<ccc.HexLike>)
20
- | null;
19
+ ((client: ccc.Client, tx: ccc.Transaction) => Promise<ccc.HexLike>) | null;
21
20
  addCellDeps?:
22
21
  | ((
23
22
  client: ccc.Client,