@ckb-ccc/spore 0.1.0-alpha.4 → 0.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.
Files changed (70) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/cluster/index.d.ts +17 -2
  3. package/dist/cluster/index.d.ts.map +1 -1
  4. package/dist/cluster/index.js +40 -1
  5. package/dist/cobuild/index.d.ts +10 -11
  6. package/dist/cobuild/index.d.ts.map +1 -1
  7. package/dist/cobuild/index.js +17 -17
  8. package/dist/codec/cluster.d.ts +17 -24
  9. package/dist/codec/cluster.d.ts.map +1 -1
  10. package/dist/codec/cluster.js +17 -28
  11. package/dist/codec/cobuild/buildingPacket.d.ts +258 -455
  12. package/dist/codec/cobuild/buildingPacket.d.ts.map +1 -1
  13. package/dist/codec/cobuild/buildingPacket.js +27 -38
  14. package/dist/codec/cobuild/sporeAction.d.ts +532 -257
  15. package/dist/codec/cobuild/sporeAction.d.ts.map +1 -1
  16. package/dist/codec/cobuild/sporeAction.js +45 -59
  17. package/dist/codec/cobuild/witnessLayout.d.ts +113 -30
  18. package/dist/codec/cobuild/witnessLayout.d.ts.map +1 -1
  19. package/dist/codec/cobuild/witnessLayout.js +10 -11
  20. package/dist/codec/spore.d.ts +5 -10
  21. package/dist/codec/spore.d.ts.map +1 -1
  22. package/dist/codec/spore.js +9 -17
  23. package/dist/spore/advanced.d.ts +3 -4
  24. package/dist/spore/advanced.d.ts.map +1 -1
  25. package/dist/spore/index.d.ts +20 -2
  26. package/dist/spore/index.d.ts.map +1 -1
  27. package/dist/spore/index.js +44 -1
  28. package/dist.commonjs/cluster/index.d.ts +17 -2
  29. package/dist.commonjs/cluster/index.d.ts.map +1 -1
  30. package/dist.commonjs/cluster/index.js +40 -0
  31. package/dist.commonjs/cobuild/index.d.ts +10 -11
  32. package/dist.commonjs/cobuild/index.d.ts.map +1 -1
  33. package/dist.commonjs/cobuild/index.js +17 -17
  34. package/dist.commonjs/codec/cluster.d.ts +17 -24
  35. package/dist.commonjs/codec/cluster.d.ts.map +1 -1
  36. package/dist.commonjs/codec/cluster.js +17 -28
  37. package/dist.commonjs/codec/cobuild/buildingPacket.d.ts +258 -455
  38. package/dist.commonjs/codec/cobuild/buildingPacket.d.ts.map +1 -1
  39. package/dist.commonjs/codec/cobuild/buildingPacket.js +27 -38
  40. package/dist.commonjs/codec/cobuild/sporeAction.d.ts +532 -257
  41. package/dist.commonjs/codec/cobuild/sporeAction.d.ts.map +1 -1
  42. package/dist.commonjs/codec/cobuild/sporeAction.js +45 -59
  43. package/dist.commonjs/codec/cobuild/witnessLayout.d.ts +113 -30
  44. package/dist.commonjs/codec/cobuild/witnessLayout.d.ts.map +1 -1
  45. package/dist.commonjs/codec/cobuild/witnessLayout.js +10 -11
  46. package/dist.commonjs/codec/spore.d.ts +5 -10
  47. package/dist.commonjs/codec/spore.d.ts.map +1 -1
  48. package/dist.commonjs/codec/spore.js +9 -17
  49. package/dist.commonjs/spore/advanced.d.ts +3 -4
  50. package/dist.commonjs/spore/advanced.d.ts.map +1 -1
  51. package/dist.commonjs/spore/index.d.ts +20 -2
  52. package/dist.commonjs/spore/index.d.ts.map +1 -1
  53. package/dist.commonjs/spore/index.js +44 -0
  54. package/package.json +5 -6
  55. package/src/cluster/index.ts +59 -2
  56. package/src/cobuild/index.ts +27 -28
  57. package/src/codec/cluster.ts +51 -56
  58. package/src/codec/cobuild/buildingPacket.ts +41 -72
  59. package/src/codec/cobuild/sporeAction.ts +75 -129
  60. package/src/codec/cobuild/witnessLayout.ts +12 -18
  61. package/src/codec/spore.ts +18 -27
  62. package/src/spore/advanced.ts +4 -5
  63. package/src/spore/index.ts +58 -2
  64. package/dist/codec/base.d.ts +0 -6
  65. package/dist/codec/base.d.ts.map +0 -1
  66. package/dist/codec/base.js +0 -10
  67. package/dist.commonjs/codec/base.d.ts +0 -6
  68. package/dist.commonjs/codec/base.d.ts.map +0 -1
  69. package/dist.commonjs/codec/base.js +0 -13
  70. package/src/codec/base.ts +0 -11
@@ -1,153 +1,99 @@
1
- import { blockchain } from "@ckb-lumos/base";
2
- import { molecule } from "@ckb-lumos/codec";
1
+ import { mol } from "@ckb-ccc/core";
3
2
 
4
- const Hash = blockchain.Byte32;
5
-
6
- export const Address = molecule.union(
7
- {
8
- Script: blockchain.Script,
9
- },
10
- ["Script"],
11
- );
3
+ export const Address = mol.union({
4
+ Script: mol.Script,
5
+ });
12
6
 
13
7
  /**
14
8
  * Spore
15
9
  */
16
- export const CreateSpore = molecule.table(
17
- {
18
- sporeId: Hash,
19
- to: Address,
20
- dataHash: Hash,
21
- },
22
- ["sporeId", "to", "dataHash"],
23
- );
24
- export const TransferSpore = molecule.table(
25
- {
26
- sporeId: Hash,
27
- from: Address,
28
- to: Address,
29
- },
30
- ["sporeId", "from", "to"],
31
- );
32
- export const MeltSpore = molecule.table(
33
- {
34
- sporeId: Hash,
35
- from: Address,
36
- },
37
- ["sporeId", "from"],
38
- );
10
+ export const CreateSpore = mol.table({
11
+ sporeId: mol.Hash,
12
+ to: Address,
13
+ dataHash: mol.Hash,
14
+ });
15
+ export const TransferSpore = mol.table({
16
+ sporeId: mol.Hash,
17
+ from: Address,
18
+ to: Address,
19
+ });
20
+ export const MeltSpore = mol.table({
21
+ sporeId: mol.Hash,
22
+ from: Address,
23
+ });
39
24
 
40
25
  /**
41
26
  * Cluster
42
27
  */
43
- export const CreateCluster = molecule.table(
44
- {
45
- clusterId: Hash,
46
- to: Address,
47
- dataHash: Hash,
48
- },
49
- ["clusterId", "to", "dataHash"],
50
- );
51
- export const TransferCluster = molecule.table(
52
- {
53
- clusterId: Hash,
54
- from: Address,
55
- to: Address,
56
- },
57
- ["clusterId", "from", "to"],
58
- );
28
+ export const CreateCluster = mol.table({
29
+ clusterId: mol.Hash,
30
+ to: Address,
31
+ dataHash: mol.Hash,
32
+ });
33
+ export const TransferCluster = mol.table({
34
+ clusterId: mol.Hash,
35
+ from: Address,
36
+ to: Address,
37
+ });
59
38
 
60
39
  /**
61
40
  * ClusterProxy
62
41
  */
63
- export const CreateClusterProxy = molecule.table(
64
- {
65
- clusterId: Hash,
66
- clusterProxyId: Hash,
67
- to: Address,
68
- },
69
- ["clusterId", "clusterProxyId", "to"],
70
- );
71
- export const TransferClusterProxy = molecule.table(
72
- {
73
- clusterId: Hash,
74
- clusterProxyId: Hash,
75
- from: Address,
76
- to: Address,
77
- },
78
- ["clusterId", "clusterProxyId", "from", "to"],
79
- );
80
- export const MeltClusterProxy = molecule.table(
81
- {
82
- clusterId: Hash,
83
- clusterProxyId: Hash,
84
- from: Address,
85
- },
86
- ["clusterId", "clusterProxyId", "from"],
87
- );
42
+ export const CreateClusterProxy = mol.table({
43
+ clusterId: mol.Hash,
44
+ clusterProxyId: mol.Hash,
45
+ to: Address,
46
+ });
47
+ export const TransferClusterProxy = mol.table({
48
+ clusterId: mol.Hash,
49
+ clusterProxyId: mol.Hash,
50
+ from: Address,
51
+ to: Address,
52
+ });
53
+ export const MeltClusterProxy = mol.table({
54
+ clusterId: mol.Hash,
55
+ clusterProxyId: mol.Hash,
56
+ from: Address,
57
+ });
88
58
 
89
59
  /**
90
60
  * ClusterAgent
91
61
  */
92
- export const CreateClusterAgent = molecule.table(
93
- {
94
- clusterId: Hash,
95
- clusterProxyId: Hash,
96
- to: Address,
97
- },
98
- ["clusterId", "clusterProxyId", "to"],
99
- );
100
- export const TransferClusterAgent = molecule.table(
101
- {
102
- clusterId: Hash,
103
- from: Address,
104
- to: Address,
105
- },
106
- ["clusterId", "from", "to"],
107
- );
108
- export const MeltClusterAgent = molecule.table(
109
- {
110
- clusterId: Hash,
111
- from: Address,
112
- },
113
- ["clusterId", "from"],
114
- );
62
+ export const CreateClusterAgent = mol.table({
63
+ clusterId: mol.Hash,
64
+ clusterProxyId: mol.Hash,
65
+ to: Address,
66
+ });
67
+ export const TransferClusterAgent = mol.table({
68
+ clusterId: mol.Hash,
69
+ from: Address,
70
+ to: Address,
71
+ });
72
+ export const MeltClusterAgent = mol.table({
73
+ clusterId: mol.Hash,
74
+ from: Address,
75
+ });
115
76
 
116
77
  /**
117
78
  * Spore ScriptInfo Actions
118
79
  */
119
- export const SporeAction = molecule.union(
120
- {
121
- // Spore
122
- CreateSpore,
123
- TransferSpore,
124
- MeltSpore,
80
+ export const SporeAction = mol.union({
81
+ // Spore
82
+ CreateSpore,
83
+ TransferSpore,
84
+ MeltSpore,
125
85
 
126
- // Cluster
127
- CreateCluster,
128
- TransferCluster,
86
+ // Cluster
87
+ CreateCluster,
88
+ TransferCluster,
129
89
 
130
- // ClusterProxy
131
- CreateClusterProxy,
132
- TransferClusterProxy,
133
- MeltClusterProxy,
90
+ // ClusterProxy
91
+ CreateClusterProxy,
92
+ TransferClusterProxy,
93
+ MeltClusterProxy,
134
94
 
135
- // ClusterAgent
136
- CreateClusterAgent,
137
- TransferClusterAgent,
138
- MeltClusterAgent,
139
- },
140
- [
141
- "CreateSpore",
142
- "TransferSpore",
143
- "MeltSpore",
144
- "CreateCluster",
145
- "TransferCluster",
146
- "CreateClusterProxy",
147
- "TransferClusterProxy",
148
- "MeltClusterProxy",
149
- "CreateClusterAgent",
150
- "TransferClusterAgent",
151
- "MeltClusterAgent",
152
- ],
153
- );
95
+ // ClusterAgent
96
+ CreateClusterAgent,
97
+ TransferClusterAgent,
98
+ MeltClusterAgent,
99
+ });
@@ -1,26 +1,20 @@
1
- import { blockchain } from "@ckb-lumos/base";
2
- import { molecule } from "@ckb-lumos/codec";
1
+ import { mol } from "@ckb-ccc/core";
3
2
  import { Message } from "./buildingPacket.js";
4
3
 
5
- export const SighashAll = molecule.table(
6
- {
7
- seal: blockchain.Bytes,
8
- message: Message,
9
- },
10
- ["seal", "message"],
11
- );
12
- export const SighashAllOnly = molecule.table(
13
- {
14
- seal: blockchain.Bytes,
15
- },
16
- ["seal"],
17
- );
4
+ export const SighashAll = mol.table({
5
+ seal: mol.Bytes,
6
+ message: Message,
7
+ });
8
+
9
+ export const SighashAllOnly = mol.table({
10
+ seal: mol.Bytes,
11
+ });
18
12
 
19
13
  /**
20
14
  * Otx related are not implemented yet, so just placeholders.
21
15
  */
22
- export const Otx = molecule.table({}, []);
23
- export const OtxStart = molecule.table({}, []);
16
+ export const Otx = mol.table({});
17
+ export const OtxStart = mol.table({});
24
18
 
25
19
  export const WitnessLayoutFieldTags = {
26
20
  SighashAll: 4278190081,
@@ -29,7 +23,7 @@ export const WitnessLayoutFieldTags = {
29
23
  OtxStart: 4278190084,
30
24
  } as const;
31
25
 
32
- export const WitnessLayout = molecule.union(
26
+ export const WitnessLayout = mol.union(
33
27
  {
34
28
  SighashAll,
35
29
  SighashAllOnly,
@@ -1,36 +1,27 @@
1
- import { ccc } from "@ckb-ccc/core";
2
- import { blockchain } from "@ckb-lumos/base";
3
- import { molecule } from "@ckb-lumos/codec";
4
- import { RawString } from "./base.js";
1
+ import { ccc, mol } from "@ckb-ccc/core";
5
2
 
6
- export const MolSporeData = molecule.table(
7
- {
8
- contentType: RawString,
9
- content: blockchain.Bytes,
10
- clusterId: blockchain.BytesOpt,
11
- },
12
- ["contentType", "content", "clusterId"],
13
- );
14
-
15
- export interface SporeData {
3
+ export interface SporeDataView {
16
4
  contentType: string;
17
5
  content: ccc.BytesLike;
18
6
  clusterId?: ccc.HexLike;
19
7
  }
20
8
 
21
- export function packRawSporeData(packable: SporeData): Uint8Array {
22
- return MolSporeData.pack({
23
- contentType: packable.contentType,
24
- content: packable.content,
25
- clusterId: packable.clusterId,
26
- });
9
+ export const SporeData: mol.Codec<SporeDataView> = mol.table({
10
+ contentType: mol.String,
11
+ content: mol.Bytes,
12
+ clusterId: mol.BytesOpt,
13
+ });
14
+
15
+ export function packRawSporeData(packable: SporeDataView): Uint8Array {
16
+ return ccc.bytesFrom(
17
+ SporeData.encode({
18
+ contentType: packable.contentType,
19
+ content: packable.content,
20
+ clusterId: packable.clusterId,
21
+ }),
22
+ );
27
23
  }
28
24
 
29
- export function unpackToRawSporeData(unpackable: ccc.BytesLike): SporeData {
30
- const unpacked = MolSporeData.unpack(unpackable);
31
- return {
32
- contentType: unpacked.contentType,
33
- content: unpacked.content,
34
- clusterId: ccc.apply(ccc.hexFrom, unpacked.clusterId),
35
- };
25
+ export function unpackToRawSporeData(unpackable: ccc.BytesLike): SporeDataView {
26
+ return SporeData.decode(unpackable);
36
27
  }
@@ -1,17 +1,16 @@
1
- import { ccc } from "@ckb-ccc/core";
2
- import { UnpackResult } from "@ckb-lumos/codec";
1
+ import { ccc, mol } from "@ckb-ccc/core";
3
2
  import { assembleTransferClusterAction } from "../advanced.js";
4
3
  import { assertCluster } from "../cluster/index.js";
5
- import { Action, SporeData } from "../codec/index.js";
4
+ import { Action, SporeDataView } from "../codec/index.js";
6
5
  import { searchOneCellBySigner } from "../helper/index.js";
7
6
 
8
7
  export async function prepareCluster(
9
8
  signer: ccc.Signer,
10
9
  tx: ccc.Transaction,
11
- data: SporeData,
10
+ data: SporeDataView,
12
11
  clusterMode?: "lockProxy" | "clusterCell" | "skip",
13
12
  scriptInfoHash?: ccc.HexLike,
14
- ): Promise<UnpackResult<typeof Action> | undefined> {
13
+ ): Promise<mol.EncodableType<typeof Action> | undefined> {
15
14
  // skip if the spore is not belong to a cluster
16
15
  if (!data.clusterId || clusterMode === "skip") {
17
16
  return;
@@ -5,7 +5,7 @@ import {
5
5
  assembleTransferSporeAction,
6
6
  prepareSporeTransaction,
7
7
  } from "../advanced.js";
8
- import { SporeData, packRawSporeData } from "../codec/index.js";
8
+ import { SporeData, SporeDataView, packRawSporeData } from "../codec/index.js";
9
9
  import {
10
10
  findSingletonCellByArgs,
11
11
  injectOneCapacityCell,
@@ -73,7 +73,7 @@ export async function assertSpore(
73
73
  */
74
74
  export async function createSpore(params: {
75
75
  signer: ccc.Signer;
76
- data: SporeData;
76
+ data: SporeDataView;
77
77
  to?: ccc.ScriptLike;
78
78
  clusterMode?: "lockProxy" | "clusterCell" | "skip";
79
79
  tx?: ccc.TransactionLike;
@@ -234,3 +234,59 @@ export async function meltSpore(params: {
234
234
  tx: await prepareSporeTransaction(signer, tx, actions),
235
235
  };
236
236
  }
237
+
238
+ /**
239
+ * Search on-chain spores under the signer's control, if cluster provided, filter spores belonging to this cluster
240
+ *
241
+ * @param signer the owner of spores
242
+ * @param order the order in creation time of spores
243
+ * @param clusterId the cluster that spores belong to
244
+ * @param scriptInfos the deployed script infos of spores
245
+ * @returns speific spore cells
246
+ */
247
+ export async function* findSporesBySigner(params: {
248
+ signer: ccc.Signer;
249
+ order?: "asc" | "desc";
250
+ clusterId?: ccc.HexLike;
251
+ scriptInfos?: SporeScriptInfoLike[];
252
+ }): AsyncGenerator<{
253
+ spore: ccc.Cell;
254
+ sporeData: SporeDataView;
255
+ }> {
256
+ const { signer, clusterId, scriptInfos, order } = params;
257
+ for (const scriptInfo of scriptInfos ??
258
+ Object.values(getSporeScriptInfos(signer.client))) {
259
+ if (!scriptInfo) {
260
+ continue;
261
+ }
262
+ for await (const spore of signer.findCells(
263
+ {
264
+ script: {
265
+ ...scriptInfo,
266
+ args: [],
267
+ },
268
+ },
269
+ true,
270
+ order,
271
+ 10,
272
+ )) {
273
+ try {
274
+ const sporeData = SporeData.decode(spore.outputData);
275
+ if (!clusterId) {
276
+ yield {
277
+ spore,
278
+ sporeData,
279
+ };
280
+ }
281
+ if (sporeData.clusterId === clusterId) {
282
+ return {
283
+ spore,
284
+ sporeData,
285
+ };
286
+ }
287
+ } catch (e: unknown) {
288
+ throw new Error(`Spore data decode failed: ${(e as Error).toString()}`);
289
+ }
290
+ }
291
+ }
292
+ }
@@ -1,6 +0,0 @@
1
- /**
2
- * The codec for packing/unpacking UTF-8 raw strings.
3
- * Should be packed like so: String.pack('something')
4
- */
5
- export declare const RawString: import("@ckb-lumos/codec/lib/base").BytesCodec<string, string>;
6
- //# sourceMappingURL=base.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/codec/base.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,eAAO,MAAM,SAAS,gEAGpB,CAAC"}
@@ -1,10 +0,0 @@
1
- import { ccc } from "@ckb-ccc/core";
2
- import { molecule } from "@ckb-lumos/codec";
3
- /**
4
- * The codec for packing/unpacking UTF-8 raw strings.
5
- * Should be packed like so: String.pack('something')
6
- */
7
- export const RawString = molecule.byteVecOf({
8
- pack: (packable) => ccc.bytesFrom(packable, "utf8"),
9
- unpack: (unpackable) => ccc.bytesTo(unpackable, "utf8"),
10
- });
@@ -1,6 +0,0 @@
1
- /**
2
- * The codec for packing/unpacking UTF-8 raw strings.
3
- * Should be packed like so: String.pack('something')
4
- */
5
- export declare const RawString: import("@ckb-lumos/codec/lib/base").BytesCodec<string, string>;
6
- //# sourceMappingURL=base.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/codec/base.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,eAAO,MAAM,SAAS,gEAGpB,CAAC"}
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RawString = void 0;
4
- const core_1 = require("@ckb-ccc/core");
5
- const codec_1 = require("@ckb-lumos/codec");
6
- /**
7
- * The codec for packing/unpacking UTF-8 raw strings.
8
- * Should be packed like so: String.pack('something')
9
- */
10
- exports.RawString = codec_1.molecule.byteVecOf({
11
- pack: (packable) => core_1.ccc.bytesFrom(packable, "utf8"),
12
- unpack: (unpackable) => core_1.ccc.bytesTo(unpackable, "utf8"),
13
- });
package/src/codec/base.ts DELETED
@@ -1,11 +0,0 @@
1
- import { ccc } from "@ckb-ccc/core";
2
- import { molecule } from "@ckb-lumos/codec";
3
-
4
- /**
5
- * The codec for packing/unpacking UTF-8 raw strings.
6
- * Should be packed like so: String.pack('something')
7
- */
8
- export const RawString = molecule.byteVecOf({
9
- pack: (packable: string) => ccc.bytesFrom(packable, "utf8"),
10
- unpack: (unpackable: ccc.BytesLike) => ccc.bytesTo(unpackable, "utf8"),
11
- });