@ckb-ccc/type-id 0.0.0-canary-20260106175902
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 +11 -0
- package/README.md +41 -0
- package/dist/advanced.d.mts +2 -0
- package/dist/advanced.mjs +1 -0
- package/dist/advancedBarrel-B9poXL1x.mjs +2 -0
- package/dist/advancedBarrel-B9poXL1x.mjs.map +1 -0
- package/dist/advancedBarrel.d.mts +56 -0
- package/dist/advancedBarrel.d.mts.map +1 -0
- package/dist/advancedBarrel.mjs +1 -0
- package/dist/barrel.d.mts +49 -0
- package/dist/barrel.d.mts.map +1 -0
- package/dist/barrel.mjs +2 -0
- package/dist/barrel.mjs.map +1 -0
- package/dist/chunk-DjrJB4cf.mjs +1 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +1 -0
- package/dist/package.json +3 -0
- package/dist.commonjs/advanced.d.ts +2 -0
- package/dist.commonjs/advanced.js +1 -0
- package/dist.commonjs/advancedBarrel-Bkrzt1YX.js +1 -0
- package/dist.commonjs/advancedBarrel.d.ts +56 -0
- package/dist.commonjs/advancedBarrel.d.ts.map +1 -0
- package/dist.commonjs/advancedBarrel.js +1 -0
- package/dist.commonjs/barrel.d.ts +49 -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 +59 -0
- package/prettier.config.cjs +11 -0
- package/src/advanced.ts +2 -0
- package/src/advancedBarrel.ts +151 -0
- package/src/barrel.ts +12 -0
- package/src/index.ts +1 -0
- package/tsdown.config.mts +36 -0
- package/typedoc.json +6 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# @ckb-ccc/type-id
|
|
2
|
+
|
|
3
|
+
## 0.0.0-canary-20260106175902
|
|
4
|
+
### Patch Changes
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
- [#337](https://github.com/ckb-devrel/ccc/pull/337) [`f593970`](https://github.com/ckb-devrel/ccc/commit/f593970627a1430ed22997fda3380ee30d838e5c) Thanks [@Hanssen0](https://github.com/Hanssen0)! - feat(type-id): add type-id package for Type ID operations
|
|
9
|
+
|
|
10
|
+
- Updated dependencies [[`ae8e8c8`](https://github.com/ckb-devrel/ccc/commit/ae8e8c8c14bff70fe22f91b1a1b248be06114d6b)]:
|
|
11
|
+
- @ckb-ccc/core@0.0.0-canary-20260106175902
|
package/README.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
CCC's Support for Type ID
|
|
9
|
+
</h1>
|
|
10
|
+
|
|
11
|
+
<p align="center">
|
|
12
|
+
<a href="https://www.npmjs.com/package/@ckb-ccc/type-id"><img
|
|
13
|
+
alt="NPM Version" src="https://img.shields.io/npm/v/%40ckb-ccc%2Ftype-id"
|
|
14
|
+
/></a>
|
|
15
|
+
<img alt="GitHub commit activity" src="https://img.shields.io/github/commit-activity/m/ckb-devrel/ccc" />
|
|
16
|
+
<img alt="GitHub last commit" src="https://img.shields.io/github/last-commit/ckb-devrel/ccc/master" />
|
|
17
|
+
<img alt="GitHub branch check runs" src="https://img.shields.io/github/check-runs/ckb-devrel/ccc/master" />
|
|
18
|
+
<a href="https://live.ckbccc.com/"><img
|
|
19
|
+
alt="Playground" src="https://img.shields.io/website?url=https%3A%2F%2Flive.ckbccc.com%2F&label=Playground"
|
|
20
|
+
/></a>
|
|
21
|
+
<a href="https://app.ckbccc.com/"><img
|
|
22
|
+
alt="App" src="https://img.shields.io/website?url=https%3A%2F%2Fapp.ckbccc.com%2F&label=App"
|
|
23
|
+
/></a>
|
|
24
|
+
<a href="https://docs.ckbccc.com/"><img
|
|
25
|
+
alt="Docs" src="https://img.shields.io/website?url=https%3A%2F%2Fdocs.ckbccc.com%2F&label=Docs"
|
|
26
|
+
/></a>
|
|
27
|
+
</p>
|
|
28
|
+
|
|
29
|
+
<p align="center">
|
|
30
|
+
CCC - CKBers' Codebase is a one-stop solution for your CKB JS/TS ecosystem development.
|
|
31
|
+
<br />
|
|
32
|
+
Empower yourself with CCC to discover the unlimited potential of CKB.
|
|
33
|
+
<br />
|
|
34
|
+
Interoperate with wallets from different chain ecosystems.
|
|
35
|
+
<br />
|
|
36
|
+
Fully enabling CKB's Turing completeness and cryptographic freedom power.
|
|
37
|
+
</p>
|
|
38
|
+
|
|
39
|
+
<h3 align="center">
|
|
40
|
+
Read more about CCC on <a href="https://docs.ckbccc.com">our website</a> or <a href="https://github.com/ckb-devrel/ccc">GitHub Repo</a>.
|
|
41
|
+
</h3>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e,t}from"./advancedBarrel-B9poXL1x.mjs";export{e as buildTypeIdOperations,t as typeIdA};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{t as e}from"./chunk-DjrJB4cf.mjs";import{ccc as t}from"@ckb-ccc/core";var n=e({buildTypeIdOperations:()=>r});function r(e){async function n(n){return t.ScriptInfo.from(await e.getScriptInfo(n))}function r(e,n){return t.Script.from({...e,args:n})}async function i(n,r,i){return e.addCellDeps?t.Transaction.from(await e.addCellDeps(n,r,i)):(r.addCellDeps(...await n.getCellDeps(i.cellDeps)),r)}return{async create({signer:e,receiver:a,data:o,tx:s}){let c=t.Transaction.from(s??{});await c.completeInputsAtLeastOne(e);let l=t.hashTypeId(c.inputs[0],c.outputs.length),u=await n(e.client),d=c.addOutput({cellOutput:{type:r(u,l),lock:a?t.Script.from(a):(await e.getRecommendedAddressObj()).script},outputData:t.bytesFrom(o)});return{tx:await i(e.client,c,u),id:l,index:d-1}},async transfer({client:e,id:a,receiver:o,tx:s}){let c=t.Transaction.from(s??{}),l=await n(e),u=r(l,a),d=await e.findSingletonCellByType(u);if(!d)throw Error(`Type ID ${t.stringify(u)} not found`);let f=c.addInput(d),p=c.addOutput({...d,cellOutput:{...d.cellOutput,lock:t.Script.from(o)}});return{tx:await i(e,c,l),inIndex:f-1,outIndex:p-1}},async destroy({client:e,id:a,tx:o}){let s=t.Transaction.from(o??{}),c=await n(e),l=r(c,a),u=await e.findSingletonCellByType(l);if(!u)throw Error(`Type ID ${t.stringify(l)} not found`);let d=s.addInput(u);return{tx:await i(e,s,c),index:d-1}}}}export{r as n,n as t};
|
|
2
|
+
//# sourceMappingURL=advancedBarrel-B9poXL1x.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"advancedBarrel-B9poXL1x.mjs","names":[],"sources":["../src/advancedBarrel.ts"],"sourcesContent":["import { ccc } from \"@ckb-ccc/core\";\n\nexport function buildTypeIdOperations(props: {\n getScriptInfo: (client: ccc.Client) => Promise<ccc.ScriptInfoLike>;\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 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 return {\n async create(\n this: void,\n {\n signer,\n receiver,\n data,\n tx: txLike,\n }: {\n signer: ccc.Signer;\n data: ccc.BytesLike;\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 tx = ccc.Transaction.from(txLike ?? {});\n\n await tx.completeInputsAtLeastOne(signer);\n const id = ccc.hashTypeId(tx.inputs[0], tx.outputs.length);\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: ccc.bytesFrom(data),\n });\n\n return {\n tx: await addCellDeps(signer.client, tx, scriptInfo),\n id,\n index: len - 1,\n };\n },\n async transfer(\n this: void,\n {\n client,\n id,\n receiver,\n tx: txLike,\n }: {\n client: ccc.Client;\n id: ccc.HexLike;\n receiver: ccc.ScriptLike;\n tx?: ccc.TransactionLike | null;\n },\n ): Promise<{\n tx: ccc.Transaction;\n inIndex: number;\n outIndex: number;\n }> {\n const tx = ccc.Transaction.from(txLike ?? {});\n\n const scriptInfo = await getScriptInfo(client);\n const type = getTypeScript(scriptInfo, id);\n const typeIdCell = await client.findSingletonCellByType(type);\n if (!typeIdCell) {\n throw new Error(`Type ID ${ccc.stringify(type)} not found`);\n }\n\n const inLen = tx.addInput(typeIdCell);\n const outLen = tx.addOutput({\n ...typeIdCell,\n cellOutput: {\n ...typeIdCell.cellOutput,\n lock: ccc.Script.from(receiver),\n },\n });\n\n return {\n tx: await addCellDeps(client, tx, scriptInfo),\n inIndex: inLen - 1,\n outIndex: outLen - 1,\n };\n },\n async destroy(\n this: void,\n {\n client,\n id,\n tx: txLike,\n }: {\n client: ccc.Client;\n id: ccc.HexLike;\n tx?: ccc.TransactionLike | null;\n },\n ): Promise<{ tx: ccc.Transaction; index: number }> {\n const tx = ccc.Transaction.from(txLike ?? {});\n\n const scriptInfo = await getScriptInfo(client);\n const type = getTypeScript(scriptInfo, id);\n const typeIdCell = await client.findSingletonCellByType(type);\n if (!typeIdCell) {\n throw new Error(`Type ID ${ccc.stringify(type)} not found`);\n }\n\n const len = tx.addInput(typeIdCell);\n\n return {\n tx: await addCellDeps(client, tx, scriptInfo),\n index: len - 1,\n };\n },\n };\n}\n"],"mappings":"oHAEA,SAAgB,EAAsB,EASnC,CACD,eAAe,EAAc,EAA6C,CACxE,OAAO,EAAI,WAAW,KAAK,MAAM,EAAM,cAAc,EAAO,CAAC,CAG/D,SAAS,EAAc,EAA4B,EAAmB,CACpE,OAAO,EAAI,OAAO,KAAK,CACrB,GAAG,EACH,OACD,CAAC,CAGJ,eAAe,EACb,EACA,EACA,EAC0B,CAQ1B,OAPI,EAAM,YACD,EAAI,YAAY,KACrB,MAAM,EAAM,YAAY,EAAQ,EAAI,EAAW,CAChD,EAGH,EAAG,YAAY,GAAI,MAAM,EAAO,YAAY,EAAW,SAAS,CAAE,CAC3D,GAGT,MAAO,CACL,MAAM,OAEJ,CACE,SACA,WACA,OACA,GAAI,GAWL,CACD,IAAM,EAAK,EAAI,YAAY,KAAK,GAAU,EAAE,CAAC,CAE7C,MAAM,EAAG,yBAAyB,EAAO,CACzC,IAAM,EAAK,EAAI,WAAW,EAAG,OAAO,GAAI,EAAG,QAAQ,OAAO,CAEpD,EAAa,MAAM,EAAc,EAAO,OAAO,CAC/C,EAAM,EAAG,UAAU,CACvB,WAAY,CACV,KAAM,EAAc,EAAY,EAAG,CACnC,KAAM,EACF,EAAI,OAAO,KAAK,EAAS,EACxB,MAAM,EAAO,0BAA0B,EAAE,OAC/C,CACD,WAAY,EAAI,UAAU,EAAK,CAChC,CAAC,CAEF,MAAO,CACL,GAAI,MAAM,EAAY,EAAO,OAAQ,EAAI,EAAW,CACpD,KACA,MAAO,EAAM,EACd,EAEH,MAAM,SAEJ,CACE,SACA,KACA,WACA,GAAI,GAWL,CACD,IAAM,EAAK,EAAI,YAAY,KAAK,GAAU,EAAE,CAAC,CAEvC,EAAa,MAAM,EAAc,EAAO,CACxC,EAAO,EAAc,EAAY,EAAG,CACpC,EAAa,MAAM,EAAO,wBAAwB,EAAK,CAC7D,GAAI,CAAC,EACH,MAAU,MAAM,WAAW,EAAI,UAAU,EAAK,CAAC,YAAY,CAG7D,IAAM,EAAQ,EAAG,SAAS,EAAW,CAC/B,EAAS,EAAG,UAAU,CAC1B,GAAG,EACH,WAAY,CACV,GAAG,EAAW,WACd,KAAM,EAAI,OAAO,KAAK,EAAS,CAChC,CACF,CAAC,CAEF,MAAO,CACL,GAAI,MAAM,EAAY,EAAQ,EAAI,EAAW,CAC7C,QAAS,EAAQ,EACjB,SAAU,EAAS,EACpB,EAEH,MAAM,QAEJ,CACE,SACA,KACA,GAAI,GAM2C,CACjD,IAAM,EAAK,EAAI,YAAY,KAAK,GAAU,EAAE,CAAC,CAEvC,EAAa,MAAM,EAAc,EAAO,CACxC,EAAO,EAAc,EAAY,EAAG,CACpC,EAAa,MAAM,EAAO,wBAAwB,EAAK,CAC7D,GAAI,CAAC,EACH,MAAU,MAAM,WAAW,EAAI,UAAU,EAAK,CAAC,YAAY,CAG7D,IAAM,EAAM,EAAG,SAAS,EAAW,CAEnC,MAAO,CACL,GAAI,MAAM,EAAY,EAAQ,EAAI,EAAW,CAC7C,MAAO,EAAM,EACd,EAEJ"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
|
|
3
|
+
//#region src/advancedBarrel.d.ts
|
|
4
|
+
declare namespace advancedBarrel_d_exports {
|
|
5
|
+
export { buildTypeIdOperations };
|
|
6
|
+
}
|
|
7
|
+
declare function buildTypeIdOperations(props: {
|
|
8
|
+
getScriptInfo: (client: ccc.Client) => Promise<ccc.ScriptInfoLike>;
|
|
9
|
+
addCellDeps?: ((client: ccc.Client, tx: ccc.Transaction, scriptInfo: ccc.ScriptInfo) => Promise<ccc.TransactionLike>) | null;
|
|
10
|
+
}): {
|
|
11
|
+
create(this: void, {
|
|
12
|
+
signer,
|
|
13
|
+
receiver,
|
|
14
|
+
data,
|
|
15
|
+
tx: txLike
|
|
16
|
+
}: {
|
|
17
|
+
signer: ccc.Signer;
|
|
18
|
+
data: ccc.BytesLike;
|
|
19
|
+
receiver?: ccc.ScriptLike | null;
|
|
20
|
+
tx?: ccc.TransactionLike | null;
|
|
21
|
+
}): Promise<{
|
|
22
|
+
tx: ccc.Transaction;
|
|
23
|
+
id: ccc.Hex;
|
|
24
|
+
index: number;
|
|
25
|
+
}>;
|
|
26
|
+
transfer(this: void, {
|
|
27
|
+
client,
|
|
28
|
+
id,
|
|
29
|
+
receiver,
|
|
30
|
+
tx: txLike
|
|
31
|
+
}: {
|
|
32
|
+
client: ccc.Client;
|
|
33
|
+
id: ccc.HexLike;
|
|
34
|
+
receiver: ccc.ScriptLike;
|
|
35
|
+
tx?: ccc.TransactionLike | null;
|
|
36
|
+
}): Promise<{
|
|
37
|
+
tx: ccc.Transaction;
|
|
38
|
+
inIndex: number;
|
|
39
|
+
outIndex: number;
|
|
40
|
+
}>;
|
|
41
|
+
destroy(this: void, {
|
|
42
|
+
client,
|
|
43
|
+
id,
|
|
44
|
+
tx: txLike
|
|
45
|
+
}: {
|
|
46
|
+
client: ccc.Client;
|
|
47
|
+
id: ccc.HexLike;
|
|
48
|
+
tx?: ccc.TransactionLike | null;
|
|
49
|
+
}): Promise<{
|
|
50
|
+
tx: ccc.Transaction;
|
|
51
|
+
index: number;
|
|
52
|
+
}>;
|
|
53
|
+
};
|
|
54
|
+
//#endregion
|
|
55
|
+
export { buildTypeIdOperations, advancedBarrel_d_exports as t };
|
|
56
|
+
//# sourceMappingURL=advancedBarrel.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"advancedBarrel.d.mts","names":[],"sources":["../src/advancedBarrel.ts"],"sourcesContent":[],"mappings":";;;;;;iBAEgB,qBAAA;0BACU,GAAA,CAAI,WAAW,QAAQ,GAAA,CAAI;0BAGrC,GAAA,CAAI,YACR,GAAA,CAAI,yBACI,GAAA,CAAI,eACb,QAAQ,GAAA,CAAI;;EAPP,MAAA,CAAA,IAAA,EAAA,IAAA,EAAA;IAAA,MAAqB;IAAA,QAAA;IAAA,IAAA;IAAA,EAAA,EAsCrB;EAjCJ,CALyB,EAAA;IACP,MAAA,EA4Cd,GAAA,CAAI,MA5CU;IAAuB,IAAA,EA6CvC,GAAA,CAAI,SA7CmC;IAAZ,QAAA,CAAA,EA8CtB,GAAA,CAAI,UA9CkB,GAAA,IAAA;IAGrB,EAAA,CAAA,EA4CP,GAAA,CAAI,eA5CG,GAAA,IAAA;EACR,CAAI,CAAA,EA6CT,OA7CS,CAAA;IACQ,EAAA,EA6Cd,GAAA,CAAI,WA7CU;IACD,EAAA,EA6Cb,GAAA,CAAI,GA7CS;IAAZ,KAAA,EAAA,MAAA;EA+BK,CAAA,CAAA;EAAA,QAAA,CAAA,IAAA,EAAA,IAAA,EAAA;IAAA,MAAA;IAAA,EAAA;IAAA,QAAA;IAAA,EAAA,EAwCA;EA/BG,CATH,EAAA;IAAA,MAAA,EA+CA,GAAA,CAAI,MA/CJ;IAAA,EAAA,EAgDJ,GAAA,CAAI,OAhDA;IAOI,QAAA,EA0CF,GAAA,CAAI,UA1CF;IACF,EAAA,CAAA,EA0CL,GAAA,CAAI,eA1CC,GAAA,IAAA;EACC,CAAI,CAAA,EA2ChB,OA3CgB,CAAA;IACN,EAAA,EA2CP,GAAA,CAAI,WA3CG;IAGH,OAAA,EAAA,MAAA;IACA,QAAA,EAAA,MAAA;EAFP,CAAA,CAAA;EA4BS,OAAA,CAAA,IAAA,EAAA,IAAA,EAAA;IAAA,MAAA;IAAA,EAAA;IAAA,EAAA,EA0CA;EAnCA,CAPA,EAAA;IAAA,MAAA,EAgDA,GAAA,CAAI,MAhDJ;IAAA,EAAA,EAiDJ,GAAA,CAAI,OAjDA;IAAA,EAAA,CAAA,EAkDH,GAAA,CAAI,eAlDD,GAAA,IAAA;EAOA,CAAI,CAAA,EA6Cb,OA7Ca,CAAA;IACJ,EAAA,EA4CK,GAAA,CAAI,WA5CT;IACM,KAAA,EAAA,MAAA;EACT,CAAI,CAAA;CAGP"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e}from"./advancedBarrel-B9poXL1x.mjs";export{e as buildTypeIdOperations};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
|
|
3
|
+
//#region src/barrel.d.ts
|
|
4
|
+
declare namespace barrel_d_exports {
|
|
5
|
+
export { createTypeId, destroyTypeId, transferTypeId };
|
|
6
|
+
}
|
|
7
|
+
declare const createTypeId: (this: void, {
|
|
8
|
+
signer,
|
|
9
|
+
receiver,
|
|
10
|
+
data,
|
|
11
|
+
tx: txLike
|
|
12
|
+
}: {
|
|
13
|
+
signer: ccc.Signer;
|
|
14
|
+
data: ccc.BytesLike;
|
|
15
|
+
receiver?: ccc.ScriptLike | null;
|
|
16
|
+
tx?: ccc.TransactionLike | null;
|
|
17
|
+
}) => Promise<{
|
|
18
|
+
tx: ccc.Transaction;
|
|
19
|
+
id: ccc.Hex;
|
|
20
|
+
index: number;
|
|
21
|
+
}>, transferTypeId: (this: void, {
|
|
22
|
+
client,
|
|
23
|
+
id,
|
|
24
|
+
receiver,
|
|
25
|
+
tx: txLike
|
|
26
|
+
}: {
|
|
27
|
+
client: ccc.Client;
|
|
28
|
+
id: ccc.HexLike;
|
|
29
|
+
receiver: ccc.ScriptLike;
|
|
30
|
+
tx?: ccc.TransactionLike | null;
|
|
31
|
+
}) => Promise<{
|
|
32
|
+
tx: ccc.Transaction;
|
|
33
|
+
inIndex: number;
|
|
34
|
+
outIndex: number;
|
|
35
|
+
}>, destroyTypeId: (this: void, {
|
|
36
|
+
client,
|
|
37
|
+
id,
|
|
38
|
+
tx: txLike
|
|
39
|
+
}: {
|
|
40
|
+
client: ccc.Client;
|
|
41
|
+
id: ccc.HexLike;
|
|
42
|
+
tx?: ccc.TransactionLike | null;
|
|
43
|
+
}) => Promise<{
|
|
44
|
+
tx: ccc.Transaction;
|
|
45
|
+
index: number;
|
|
46
|
+
}>;
|
|
47
|
+
//#endregion
|
|
48
|
+
export { createTypeId, destroyTypeId, barrel_d_exports as t, transferTypeId };
|
|
49
|
+
//# sourceMappingURL=barrel.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"barrel.d.mts","names":[],"sources":["../src/barrel.ts"],"sourcesContent":[],"mappings":";;;;;;cAIU;;;;QAAY;;;;eAQ41B,GAAA,CAAA;SAAoC,GAAA,CAAA;;;;IAR54B,KAAA,EAAA,MAAA;GAAY,CAAA,EAAA,cAAA,EAAA,CAAA,IAAA,EAAA,IAAA,EAAA;IAAA,MAAA;IAAA,EAAA;IAAA,QAAA;IAAA,EAAA,EACI;GADJ,EAAA;IAAA,MAAA,YAAA;IAAA,EAAA,aAAA;IAAA,QAAA,gBAAA;SAQ+2D,GAAA,CAAA;;IAAnhC,EAAA,iBAAA;IAAoC,OAAA,EAAA,MAAA;;;;;QAN93B;;;IADE,EAAA,aAAA;IAAA,EAAA,CAAA,EAO21F,GAAA,CAAA,eAP31F,GAAA,IAAA;GAAA,EAAA,UAAA,CAAA;IAAA,EAAA,iBAAA"}
|
package/dist/barrel.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{t as e}from"./chunk-DjrJB4cf.mjs";import{n as t}from"./advancedBarrel-B9poXL1x.mjs";import{ccc as n}from"@ckb-ccc/core";var r=e({createTypeId:()=>i,destroyTypeId:()=>o,transferTypeId:()=>a});const{create:i,transfer:a,destroy:o}=t({async getScriptInfo(e){return e.getKnownScript(n.KnownScript.TypeId)}});export{i as createTypeId,o as destroyTypeId,r as t,a as transferTypeId};
|
|
2
|
+
//# sourceMappingURL=barrel.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"barrel.mjs","names":[],"sources":["../src/barrel.ts"],"sourcesContent":["import { ccc } from \"@ckb-ccc/core\";\nimport { buildTypeIdOperations } from \"./advancedBarrel\";\n\nexport const {\n create: createTypeId,\n transfer: transferTypeId,\n destroy: destroyTypeId,\n} = buildTypeIdOperations({\n async getScriptInfo(client: ccc.Client) {\n return client.getKnownScript(ccc.KnownScript.TypeId);\n },\n});\n"],"mappings":"sMAGA,KAAa,CACX,OAAQ,EACR,SAAU,EACV,QAAS,GACP,EAAsB,CACxB,MAAM,cAAc,EAAoB,CACtC,OAAO,EAAO,eAAe,EAAI,YAAY,OAAO,EAEvD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=Object.defineProperty,t=(t,n)=>{let r={};for(var i in t)e(r,i,{get:t[i],enumerable:!0});return n&&e(r,Symbol.toStringTag,{value:`Module`}),r};export{t};
|
package/dist/index.d.mts
ADDED
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./advancedBarrel-B9poXL1x.mjs";import{t as e}from"./barrel.mjs";export{e as typeId};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require(`./advancedBarrel-Bkrzt1YX.js`);exports.buildTypeIdOperations=e.n,Object.defineProperty(exports,`typeIdA`,{enumerable:!0,get:function(){return e.t}});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=Object.defineProperty,t=(t,n)=>{let r={};for(var i in t)e(r,i,{get:t[i],enumerable:!0});return n&&e(r,Symbol.toStringTag,{value:`Module`}),r};let n=require(`@ckb-ccc/core`);var r=t({buildTypeIdOperations:()=>i});function i(e){async function t(t){return n.ccc.ScriptInfo.from(await e.getScriptInfo(t))}function r(e,t){return n.ccc.Script.from({...e,args:t})}async function i(t,r,i){return e.addCellDeps?n.ccc.Transaction.from(await e.addCellDeps(t,r,i)):(r.addCellDeps(...await t.getCellDeps(i.cellDeps)),r)}return{async create({signer:e,receiver:a,data:o,tx:s}){let c=n.ccc.Transaction.from(s??{});await c.completeInputsAtLeastOne(e);let l=n.ccc.hashTypeId(c.inputs[0],c.outputs.length),u=await t(e.client),d=c.addOutput({cellOutput:{type:r(u,l),lock:a?n.ccc.Script.from(a):(await e.getRecommendedAddressObj()).script},outputData:n.ccc.bytesFrom(o)});return{tx:await i(e.client,c,u),id:l,index:d-1}},async transfer({client:e,id:a,receiver:o,tx:s}){let c=n.ccc.Transaction.from(s??{}),l=await t(e),u=r(l,a),d=await e.findSingletonCellByType(u);if(!d)throw Error(`Type ID ${n.ccc.stringify(u)} not found`);let f=c.addInput(d),p=c.addOutput({...d,cellOutput:{...d.cellOutput,lock:n.ccc.Script.from(o)}});return{tx:await i(e,c,l),inIndex:f-1,outIndex:p-1}},async destroy({client:e,id:a,tx:o}){let s=n.ccc.Transaction.from(o??{}),c=await t(e),l=r(c,a),u=await e.findSingletonCellByType(l);if(!u)throw Error(`Type ID ${n.ccc.stringify(l)} not found`);let d=s.addInput(u);return{tx:await i(e,s,c),index:d-1}}}}Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return r}});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
|
|
3
|
+
//#region src/advancedBarrel.d.ts
|
|
4
|
+
declare namespace advancedBarrel_d_exports {
|
|
5
|
+
export { buildTypeIdOperations };
|
|
6
|
+
}
|
|
7
|
+
declare function buildTypeIdOperations(props: {
|
|
8
|
+
getScriptInfo: (client: ccc.Client) => Promise<ccc.ScriptInfoLike>;
|
|
9
|
+
addCellDeps?: ((client: ccc.Client, tx: ccc.Transaction, scriptInfo: ccc.ScriptInfo) => Promise<ccc.TransactionLike>) | null;
|
|
10
|
+
}): {
|
|
11
|
+
create(this: void, {
|
|
12
|
+
signer,
|
|
13
|
+
receiver,
|
|
14
|
+
data,
|
|
15
|
+
tx: txLike
|
|
16
|
+
}: {
|
|
17
|
+
signer: ccc.Signer;
|
|
18
|
+
data: ccc.BytesLike;
|
|
19
|
+
receiver?: ccc.ScriptLike | null;
|
|
20
|
+
tx?: ccc.TransactionLike | null;
|
|
21
|
+
}): Promise<{
|
|
22
|
+
tx: ccc.Transaction;
|
|
23
|
+
id: ccc.Hex;
|
|
24
|
+
index: number;
|
|
25
|
+
}>;
|
|
26
|
+
transfer(this: void, {
|
|
27
|
+
client,
|
|
28
|
+
id,
|
|
29
|
+
receiver,
|
|
30
|
+
tx: txLike
|
|
31
|
+
}: {
|
|
32
|
+
client: ccc.Client;
|
|
33
|
+
id: ccc.HexLike;
|
|
34
|
+
receiver: ccc.ScriptLike;
|
|
35
|
+
tx?: ccc.TransactionLike | null;
|
|
36
|
+
}): Promise<{
|
|
37
|
+
tx: ccc.Transaction;
|
|
38
|
+
inIndex: number;
|
|
39
|
+
outIndex: number;
|
|
40
|
+
}>;
|
|
41
|
+
destroy(this: void, {
|
|
42
|
+
client,
|
|
43
|
+
id,
|
|
44
|
+
tx: txLike
|
|
45
|
+
}: {
|
|
46
|
+
client: ccc.Client;
|
|
47
|
+
id: ccc.HexLike;
|
|
48
|
+
tx?: ccc.TransactionLike | null;
|
|
49
|
+
}): Promise<{
|
|
50
|
+
tx: ccc.Transaction;
|
|
51
|
+
index: number;
|
|
52
|
+
}>;
|
|
53
|
+
};
|
|
54
|
+
//#endregion
|
|
55
|
+
export { buildTypeIdOperations, advancedBarrel_d_exports as t };
|
|
56
|
+
//# sourceMappingURL=advancedBarrel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"advancedBarrel.d.ts","names":[],"sources":["../src/advancedBarrel.ts"],"sourcesContent":[],"mappings":";;;;;;iBAEgB,qBAAA;0BACU,GAAA,CAAI,WAAW,QAAQ,GAAA,CAAI;0BAGrC,GAAA,CAAI,YACR,GAAA,CAAI,yBACI,GAAA,CAAI,eACb,QAAQ,GAAA,CAAI;;EAPP,MAAA,CAAA,IAAA,EAAA,IAAA,EAAA;IAAA,MAAqB;IAAA,QAAA;IAAA,IAAA;IAAA,EAAA,EAsCrB;EAjCJ,CALyB,EAAA;IACP,MAAA,EA4Cd,GAAA,CAAI,MA5CU;IAAuB,IAAA,EA6CvC,GAAA,CAAI,SA7CmC;IAAZ,QAAA,CAAA,EA8CtB,GAAA,CAAI,UA9CkB,GAAA,IAAA;IAGrB,EAAA,CAAA,EA4CP,GAAA,CAAI,eA5CG,GAAA,IAAA;EACR,CAAI,CAAA,EA6CT,OA7CS,CAAA;IACQ,EAAA,EA6Cd,GAAA,CAAI,WA7CU;IACD,EAAA,EA6Cb,GAAA,CAAI,GA7CS;IAAZ,KAAA,EAAA,MAAA;EA+BK,CAAA,CAAA;EAAA,QAAA,CAAA,IAAA,EAAA,IAAA,EAAA;IAAA,MAAA;IAAA,EAAA;IAAA,QAAA;IAAA,EAAA,EAwCA;EA/BG,CATH,EAAA;IAAA,MAAA,EA+CA,GAAA,CAAI,MA/CJ;IAAA,EAAA,EAgDJ,GAAA,CAAI,OAhDA;IAOI,QAAA,EA0CF,GAAA,CAAI,UA1CF;IACF,EAAA,CAAA,EA0CL,GAAA,CAAI,eA1CC,GAAA,IAAA;EACC,CAAI,CAAA,EA2ChB,OA3CgB,CAAA;IACN,EAAA,EA2CP,GAAA,CAAI,WA3CG;IAGH,OAAA,EAAA,MAAA;IACA,QAAA,EAAA,MAAA;EAFP,CAAA,CAAA;EA4BS,OAAA,CAAA,IAAA,EAAA,IAAA,EAAA;IAAA,MAAA;IAAA,EAAA;IAAA,EAAA,EA0CA;EAnCA,CAPA,EAAA;IAAA,MAAA,EAgDA,GAAA,CAAI,MAhDJ;IAAA,EAAA,EAiDJ,GAAA,CAAI,OAjDA;IAAA,EAAA,CAAA,EAkDH,GAAA,CAAI,eAlDD,GAAA,IAAA;EAOA,CAAI,CAAA,EA6Cb,OA7Ca,CAAA;IACJ,EAAA,EA4CK,GAAA,CAAI,WA5CT;IACM,KAAA,EAAA,MAAA;EACT,CAAI,CAAA;CAGP"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require(`./advancedBarrel-Bkrzt1YX.js`);exports.buildTypeIdOperations=e.n;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
|
|
3
|
+
//#region src/barrel.d.ts
|
|
4
|
+
declare namespace barrel_d_exports {
|
|
5
|
+
export { createTypeId, destroyTypeId, transferTypeId };
|
|
6
|
+
}
|
|
7
|
+
declare const createTypeId: (this: void, {
|
|
8
|
+
signer,
|
|
9
|
+
receiver,
|
|
10
|
+
data,
|
|
11
|
+
tx: txLike
|
|
12
|
+
}: {
|
|
13
|
+
signer: ccc.Signer;
|
|
14
|
+
data: ccc.BytesLike;
|
|
15
|
+
receiver?: ccc.ScriptLike | null;
|
|
16
|
+
tx?: ccc.TransactionLike | null;
|
|
17
|
+
}) => Promise<{
|
|
18
|
+
tx: ccc.Transaction;
|
|
19
|
+
id: ccc.Hex;
|
|
20
|
+
index: number;
|
|
21
|
+
}>, transferTypeId: (this: void, {
|
|
22
|
+
client,
|
|
23
|
+
id,
|
|
24
|
+
receiver,
|
|
25
|
+
tx: txLike
|
|
26
|
+
}: {
|
|
27
|
+
client: ccc.Client;
|
|
28
|
+
id: ccc.HexLike;
|
|
29
|
+
receiver: ccc.ScriptLike;
|
|
30
|
+
tx?: ccc.TransactionLike | null;
|
|
31
|
+
}) => Promise<{
|
|
32
|
+
tx: ccc.Transaction;
|
|
33
|
+
inIndex: number;
|
|
34
|
+
outIndex: number;
|
|
35
|
+
}>, destroyTypeId: (this: void, {
|
|
36
|
+
client,
|
|
37
|
+
id,
|
|
38
|
+
tx: txLike
|
|
39
|
+
}: {
|
|
40
|
+
client: ccc.Client;
|
|
41
|
+
id: ccc.HexLike;
|
|
42
|
+
tx?: ccc.TransactionLike | null;
|
|
43
|
+
}) => Promise<{
|
|
44
|
+
tx: ccc.Transaction;
|
|
45
|
+
index: number;
|
|
46
|
+
}>;
|
|
47
|
+
//#endregion
|
|
48
|
+
export { createTypeId, destroyTypeId, barrel_d_exports as t, transferTypeId };
|
|
49
|
+
//# sourceMappingURL=barrel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"barrel.d.ts","names":[],"sources":["../src/barrel.ts"],"sourcesContent":[],"mappings":";;;;;;cAIU;;;;QAAY;;;;eAQ41B,GAAA,CAAA;SAAoC,GAAA,CAAA;;;;IAR54B,KAAA,EAAA,MAAA;GAAY,CAAA,EAAA,cAAA,EAAA,CAAA,IAAA,EAAA,IAAA,EAAA;IAAA,MAAA;IAAA,EAAA;IAAA,QAAA;IAAA,EAAA,EACI;GADJ,EAAA;IAAA,MAAA,YAAA;IAAA,EAAA,aAAA;IAAA,QAAA,gBAAA;SAQ+2D,GAAA,CAAA;;IAAnhC,EAAA,iBAAA;IAAoC,OAAA,EAAA,MAAA;;;;;QAN93B;;;IADE,EAAA,aAAA;IAAA,EAAA,CAAA,EAO21F,GAAA,CAAA,eAP31F,GAAA,IAAA;GAAA,EAAA,UAAA,CAAA;IAAA,EAAA,iBAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require(`./advancedBarrel-Bkrzt1YX.js`);let t=require(`@ckb-ccc/core`);var n=e.r({createTypeId:()=>r,destroyTypeId:()=>a,transferTypeId:()=>i});const{create:r,transfer:i,destroy:a}=e.n({async getScriptInfo(e){return e.getKnownScript(t.ccc.KnownScript.TypeId)}});exports.createTypeId=r,exports.destroyTypeId=a,Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return n}}),exports.transferTypeId=i;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require(`./advancedBarrel-Bkrzt1YX.js`);const e=require(`./barrel.js`);Object.defineProperty(exports,`typeId`,{enumerable:!0,get:function(){return e.t}});
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ckb-ccc/type-id",
|
|
3
|
+
"version": "0.0.0-canary-20260106175902",
|
|
4
|
+
"description": "CCC - CKBer's Codebase. CCC's support for Type ID",
|
|
5
|
+
"author": "Hanssen0 <hanssen0@hanssen0.com>",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"private": false,
|
|
8
|
+
"homepage": "https://github.com/ckb-devrel/ccc",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git://github.com/ckb-devrel/ccc.git"
|
|
12
|
+
},
|
|
13
|
+
"main": "./dist.commonjs/index.js",
|
|
14
|
+
"module": "./dist/index.mjs",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"require": "./dist.commonjs/index.js",
|
|
18
|
+
"import": "./dist/index.mjs"
|
|
19
|
+
},
|
|
20
|
+
"./advanced": {
|
|
21
|
+
"require": "./dist.commonjs/advanced.js",
|
|
22
|
+
"import": "./dist/advanced.mjs"
|
|
23
|
+
},
|
|
24
|
+
"./advancedBarrel": {
|
|
25
|
+
"require": "./dist.commonjs/advancedBarrel.js",
|
|
26
|
+
"import": "./dist/advancedBarrel.mjs"
|
|
27
|
+
},
|
|
28
|
+
"./barrel": {
|
|
29
|
+
"require": "./dist.commonjs/barrel.js",
|
|
30
|
+
"import": "./dist/barrel.mjs"
|
|
31
|
+
},
|
|
32
|
+
"./package.json": "./package.json"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@eslint/js": "^9.34.0",
|
|
36
|
+
"@types/node": "^24.3.0",
|
|
37
|
+
"eslint": "^9.34.0",
|
|
38
|
+
"eslint-config-prettier": "^10.1.8",
|
|
39
|
+
"eslint-plugin-prettier": "^5.5.4",
|
|
40
|
+
"prettier": "^3.6.2",
|
|
41
|
+
"prettier-plugin-organize-imports": "^4.2.0",
|
|
42
|
+
"tsdown": "0.19.0-beta.3",
|
|
43
|
+
"typescript": "^5.9.2",
|
|
44
|
+
"typescript-eslint": "^8.41.0"
|
|
45
|
+
},
|
|
46
|
+
"publishConfig": {
|
|
47
|
+
"access": "public"
|
|
48
|
+
},
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"@ckb-ccc/core": "0.0.0-canary-20260106175902"
|
|
51
|
+
},
|
|
52
|
+
"types": "./dist.commonjs/index.d.ts",
|
|
53
|
+
"scripts": {
|
|
54
|
+
"test": "jest",
|
|
55
|
+
"build": "tsdown",
|
|
56
|
+
"lint": "eslint ./src",
|
|
57
|
+
"format": "prettier --write . && eslint --fix ./src"
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @see https://prettier.io/docs/configuration
|
|
3
|
+
* @type {import("prettier").Config}
|
|
4
|
+
*/
|
|
5
|
+
const config = {
|
|
6
|
+
singleQuote: false,
|
|
7
|
+
trailingComma: "all",
|
|
8
|
+
plugins: [require.resolve("prettier-plugin-organize-imports")],
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
module.exports = config;
|
package/src/advanced.ts
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
|
|
3
|
+
export function buildTypeIdOperations(props: {
|
|
4
|
+
getScriptInfo: (client: ccc.Client) => Promise<ccc.ScriptInfoLike>;
|
|
5
|
+
addCellDeps?:
|
|
6
|
+
| ((
|
|
7
|
+
client: ccc.Client,
|
|
8
|
+
tx: ccc.Transaction,
|
|
9
|
+
scriptInfo: ccc.ScriptInfo,
|
|
10
|
+
) => Promise<ccc.TransactionLike>)
|
|
11
|
+
| null;
|
|
12
|
+
}) {
|
|
13
|
+
async function getScriptInfo(client: ccc.Client): Promise<ccc.ScriptInfo> {
|
|
14
|
+
return ccc.ScriptInfo.from(await props.getScriptInfo(client));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function getTypeScript(scriptInfo: ccc.ScriptInfo, args: ccc.HexLike) {
|
|
18
|
+
return ccc.Script.from({
|
|
19
|
+
...scriptInfo,
|
|
20
|
+
args,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async function addCellDeps(
|
|
25
|
+
client: ccc.Client,
|
|
26
|
+
tx: ccc.Transaction,
|
|
27
|
+
scriptInfo: ccc.ScriptInfo,
|
|
28
|
+
): Promise<ccc.Transaction> {
|
|
29
|
+
if (props.addCellDeps) {
|
|
30
|
+
return ccc.Transaction.from(
|
|
31
|
+
await props.addCellDeps(client, tx, scriptInfo),
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
tx.addCellDeps(...(await client.getCellDeps(scriptInfo.cellDeps)));
|
|
36
|
+
return tx;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
async create(
|
|
41
|
+
this: void,
|
|
42
|
+
{
|
|
43
|
+
signer,
|
|
44
|
+
receiver,
|
|
45
|
+
data,
|
|
46
|
+
tx: txLike,
|
|
47
|
+
}: {
|
|
48
|
+
signer: ccc.Signer;
|
|
49
|
+
data: ccc.BytesLike;
|
|
50
|
+
receiver?: ccc.ScriptLike | null;
|
|
51
|
+
tx?: ccc.TransactionLike | null;
|
|
52
|
+
},
|
|
53
|
+
): Promise<{
|
|
54
|
+
tx: ccc.Transaction;
|
|
55
|
+
id: ccc.Hex;
|
|
56
|
+
index: number;
|
|
57
|
+
}> {
|
|
58
|
+
const tx = ccc.Transaction.from(txLike ?? {});
|
|
59
|
+
|
|
60
|
+
await tx.completeInputsAtLeastOne(signer);
|
|
61
|
+
const id = ccc.hashTypeId(tx.inputs[0], tx.outputs.length);
|
|
62
|
+
|
|
63
|
+
const scriptInfo = await getScriptInfo(signer.client);
|
|
64
|
+
const len = tx.addOutput({
|
|
65
|
+
cellOutput: {
|
|
66
|
+
type: getTypeScript(scriptInfo, id),
|
|
67
|
+
lock: receiver
|
|
68
|
+
? ccc.Script.from(receiver)
|
|
69
|
+
: (await signer.getRecommendedAddressObj()).script,
|
|
70
|
+
},
|
|
71
|
+
outputData: ccc.bytesFrom(data),
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
return {
|
|
75
|
+
tx: await addCellDeps(signer.client, tx, scriptInfo),
|
|
76
|
+
id,
|
|
77
|
+
index: len - 1,
|
|
78
|
+
};
|
|
79
|
+
},
|
|
80
|
+
async transfer(
|
|
81
|
+
this: void,
|
|
82
|
+
{
|
|
83
|
+
client,
|
|
84
|
+
id,
|
|
85
|
+
receiver,
|
|
86
|
+
tx: txLike,
|
|
87
|
+
}: {
|
|
88
|
+
client: ccc.Client;
|
|
89
|
+
id: ccc.HexLike;
|
|
90
|
+
receiver: ccc.ScriptLike;
|
|
91
|
+
tx?: ccc.TransactionLike | null;
|
|
92
|
+
},
|
|
93
|
+
): Promise<{
|
|
94
|
+
tx: ccc.Transaction;
|
|
95
|
+
inIndex: number;
|
|
96
|
+
outIndex: number;
|
|
97
|
+
}> {
|
|
98
|
+
const tx = ccc.Transaction.from(txLike ?? {});
|
|
99
|
+
|
|
100
|
+
const scriptInfo = await getScriptInfo(client);
|
|
101
|
+
const type = getTypeScript(scriptInfo, id);
|
|
102
|
+
const typeIdCell = await client.findSingletonCellByType(type);
|
|
103
|
+
if (!typeIdCell) {
|
|
104
|
+
throw new Error(`Type ID ${ccc.stringify(type)} not found`);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const inLen = tx.addInput(typeIdCell);
|
|
108
|
+
const outLen = tx.addOutput({
|
|
109
|
+
...typeIdCell,
|
|
110
|
+
cellOutput: {
|
|
111
|
+
...typeIdCell.cellOutput,
|
|
112
|
+
lock: ccc.Script.from(receiver),
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
return {
|
|
117
|
+
tx: await addCellDeps(client, tx, scriptInfo),
|
|
118
|
+
inIndex: inLen - 1,
|
|
119
|
+
outIndex: outLen - 1,
|
|
120
|
+
};
|
|
121
|
+
},
|
|
122
|
+
async destroy(
|
|
123
|
+
this: void,
|
|
124
|
+
{
|
|
125
|
+
client,
|
|
126
|
+
id,
|
|
127
|
+
tx: txLike,
|
|
128
|
+
}: {
|
|
129
|
+
client: ccc.Client;
|
|
130
|
+
id: ccc.HexLike;
|
|
131
|
+
tx?: ccc.TransactionLike | null;
|
|
132
|
+
},
|
|
133
|
+
): Promise<{ tx: ccc.Transaction; index: number }> {
|
|
134
|
+
const tx = ccc.Transaction.from(txLike ?? {});
|
|
135
|
+
|
|
136
|
+
const scriptInfo = await getScriptInfo(client);
|
|
137
|
+
const type = getTypeScript(scriptInfo, id);
|
|
138
|
+
const typeIdCell = await client.findSingletonCellByType(type);
|
|
139
|
+
if (!typeIdCell) {
|
|
140
|
+
throw new Error(`Type ID ${ccc.stringify(type)} not found`);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const len = tx.addInput(typeIdCell);
|
|
144
|
+
|
|
145
|
+
return {
|
|
146
|
+
tx: await addCellDeps(client, tx, scriptInfo),
|
|
147
|
+
index: len - 1,
|
|
148
|
+
};
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
}
|
package/src/barrel.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
import { buildTypeIdOperations } from "./advancedBarrel";
|
|
3
|
+
|
|
4
|
+
export const {
|
|
5
|
+
create: createTypeId,
|
|
6
|
+
transfer: transferTypeId,
|
|
7
|
+
destroy: destroyTypeId,
|
|
8
|
+
} = buildTypeIdOperations({
|
|
9
|
+
async getScriptInfo(client: ccc.Client) {
|
|
10
|
+
return client.getKnownScript(ccc.KnownScript.TypeId);
|
|
11
|
+
},
|
|
12
|
+
});
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as typeId from "./barrel.js";
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { defineConfig } from "tsdown";
|
|
2
|
+
|
|
3
|
+
const common = {
|
|
4
|
+
minify: true,
|
|
5
|
+
dts: true,
|
|
6
|
+
platform: "neutral" as const,
|
|
7
|
+
exports: true,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export default defineConfig(
|
|
11
|
+
(
|
|
12
|
+
[
|
|
13
|
+
{
|
|
14
|
+
entry: {
|
|
15
|
+
index: "src/index.ts",
|
|
16
|
+
barrel: "src/barrel.ts",
|
|
17
|
+
advanced: "src/advanced.ts",
|
|
18
|
+
advancedBarrel: "src/advancedBarrel.ts",
|
|
19
|
+
},
|
|
20
|
+
format: "esm",
|
|
21
|
+
copy: "./misc/basedirs/dist/*",
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
entry: {
|
|
25
|
+
index: "src/index.ts",
|
|
26
|
+
barrel: "src/barrel.ts",
|
|
27
|
+
advanced: "src/advanced.ts",
|
|
28
|
+
advancedBarrel: "src/advancedBarrel.ts",
|
|
29
|
+
},
|
|
30
|
+
format: "cjs",
|
|
31
|
+
outDir: "dist.commonjs",
|
|
32
|
+
copy: "./misc/basedirs/dist.commonjs/*",
|
|
33
|
+
},
|
|
34
|
+
] as const
|
|
35
|
+
).map((c) => ({ ...c, ...common })),
|
|
36
|
+
);
|