@tychosdk/disasm 0.1.1 → 0.1.3

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/README.md CHANGED
@@ -26,9 +26,66 @@ const code = Cell.fromBase64("te6ccgEBAgEACwABCvgAgHuIAQABYA==");
26
26
  const parsed = await disasmStructured(code);
27
27
  ```
28
28
 
29
- ## Development
29
+ ### Example output
30
+
31
+ ```json
32
+ {
33
+ "root": 0,
34
+ "items": [
35
+ {
36
+ "id": 0,
37
+ "type": "code",
38
+ "cellHash": "4c22ee65d587da45ad571a90740ea5a50ba58ee88e75769fbc9ac47eef693e68",
39
+ "isInline": false,
40
+ "offsetBits": 0,
41
+ "offsetRefs": 0,
42
+ "bits": 40,
43
+ "refs": 1,
44
+ "opcodes": [
45
+ {
46
+ "bits": 16,
47
+ "name": "ACCEPT",
48
+ "gas": 26
49
+ },
50
+ {
51
+ "bits": 16,
52
+ "name": "PUSHINT",
53
+ "args": [
54
+ {
55
+ "type": "int",
56
+ "value": "123"
57
+ }
58
+ ],
59
+ "gas": 26
60
+ },
61
+ {
62
+ "bits": 8,
63
+ "refs": 1,
64
+ "name": "PUSHREF",
65
+ "args": [
66
+ {
67
+ "type": "cell",
68
+ "id": 1
69
+ }
70
+ ],
71
+ "gas": 18
72
+ }
73
+ ],
74
+ "tail": null
75
+ },
76
+ {
77
+ "id": 1,
78
+ "type": "data",
79
+ "data": {
80
+ "type": "cell",
81
+ "boc": "te6ccgEBAQEAAwAAAWA="
82
+ }
83
+ }
84
+ ]
85
+ }
86
+ ```
30
87
 
31
- ### @tychosdk/disasm
88
+ ## Development
32
89
 
33
90
  To install dependencies:
34
91
 
package/dist/index.d.ts CHANGED
@@ -1,4 +1,110 @@
1
- export type { Code, CodeBlock, CodeBlockTail, Data, DataBlock, Item, ItemId, JumpTable, Library, Link, LinkType, Opcode, } from "./env";
2
- import type { Code } from "./env";
3
1
  import { Cell } from "@ton/core";
2
+ /**
3
+ * All code parts are referenced by a numberic ID.
4
+ */
5
+ export type ItemId = number;
6
+ /**
7
+ * Code is a group of parsed parts and an index from which to start.
8
+ */
9
+ export type Code = {
10
+ root: ItemId;
11
+ items: Item[];
12
+ };
13
+ export type Item = ({
14
+ id: number;
15
+ type: "jumpTable";
16
+ } & JumpTable) | ({
17
+ id: number;
18
+ type: "code";
19
+ } & CodeBlock) | ({
20
+ id: number;
21
+ type: "dataBlock";
22
+ } & DataBlock) | ({
23
+ id: number;
24
+ type: "library";
25
+ } & Library);
26
+ export type ItemType = Item["type"];
27
+ /**
28
+ * Jump table is a dictionary which maps int to some continuations.
29
+ */
30
+ export type JumpTable = {
31
+ cellHash: string;
32
+ keyBits: number;
33
+ items: Record<string, ItemId>;
34
+ isFullCode: boolean;
35
+ };
36
+ /**
37
+ * Parsed continuation.
38
+ */
39
+ export type CodeBlock = {
40
+ cellHash: string;
41
+ isInline: boolean;
42
+ offsetBits: number;
43
+ offsetRefs: number;
44
+ bits: number;
45
+ refs: number;
46
+ opcodes: Opcode[];
47
+ tail?: CodeBlockTail;
48
+ };
49
+ /**
50
+ * What follows the continuation.
51
+ */
52
+ export type CodeBlockTail = {
53
+ type: "incomplete";
54
+ } | {
55
+ type: "child";
56
+ id: ItemId;
57
+ };
58
+ export type CodeBlockTailType = CodeBlockTail["type"];
59
+ /**
60
+ * Parsed opcode.
61
+ */
62
+ export type Opcode = {
63
+ bits: number;
64
+ refs?: number;
65
+ name: string;
66
+ args: OpcodeArg[];
67
+ gas: number;
68
+ };
69
+ /**
70
+ * Parsed opcode argument.
71
+ */
72
+ export type OpcodeArg = {
73
+ type: "int";
74
+ value: string;
75
+ } | {
76
+ type: "stack";
77
+ idx: number;
78
+ } | {
79
+ type: "reg";
80
+ idx: number;
81
+ } | {
82
+ type: "cell";
83
+ id: ItemId;
84
+ } | {
85
+ type: "slice";
86
+ id: ItemId;
87
+ };
88
+ export type OpcodeArgType = OpcodeArg["type"];
89
+ /**
90
+ * Cell tree parts that are treated as data.
91
+ */
92
+ export type DataBlock = {
93
+ data: Data;
94
+ };
95
+ export type Data = {
96
+ type: "slice";
97
+ offsetBits: number;
98
+ offsetRefs: number;
99
+ bits: number;
100
+ refs: number;
101
+ boc: string;
102
+ } | {
103
+ type: "cell";
104
+ boc: string;
105
+ };
106
+ export type DataType = Data["type"];
107
+ export type Library = {
108
+ hash: string;
109
+ };
4
110
  export declare function disasmStructured(code: Cell | string): Promise<Code>;
package/dist/index.js CHANGED
@@ -13,5 +13,6 @@ async function disasmStructured(code) {
13
13
  boc = code;
14
14
  }
15
15
  const res = env_1.wasm.disasm_structured(boc);
16
- return JSON.parse(res);
16
+ const parsed = JSON.parse(res);
17
+ return parsed;
17
18
  }
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tychosdk/disasm",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Tycho TVM disasm",
5
5
  "main": "dist/index.js",
6
6
  "browser": {