@cashscript/utils 0.10.0-next.2 → 0.10.0-next.4
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/dist/artifact.d.ts +13 -10
- package/dist/bitauth-script.d.ts +3 -3
- package/dist/bitauth-script.js +11 -9
- package/dist/source-map.d.ts +3 -13
- package/dist/source-map.js +29 -21
- package/dist/types.d.ts +19 -0
- package/dist/types.js +6 -0
- package/package.json +3 -3
package/dist/artifact.d.ts
CHANGED
|
@@ -9,14 +9,22 @@ export interface AbiFunction {
|
|
|
9
9
|
covenant?: boolean;
|
|
10
10
|
inputs: AbiInput[];
|
|
11
11
|
}
|
|
12
|
+
export interface DebugInformation {
|
|
13
|
+
bytecode: string;
|
|
14
|
+
sourceMap: string;
|
|
15
|
+
logs: LogEntry[];
|
|
16
|
+
requireMessages: RequireMessage[];
|
|
17
|
+
}
|
|
12
18
|
export interface LogEntry {
|
|
13
19
|
ip: number;
|
|
14
20
|
line: number;
|
|
15
|
-
data: Array<
|
|
16
|
-
stackIndex: number;
|
|
17
|
-
type: string;
|
|
18
|
-
} | string>;
|
|
21
|
+
data: Array<LogData>;
|
|
19
22
|
}
|
|
23
|
+
export interface StackItem {
|
|
24
|
+
type: string;
|
|
25
|
+
stackIndex: number;
|
|
26
|
+
}
|
|
27
|
+
export declare type LogData = StackItem | string;
|
|
20
28
|
export interface RequireMessage {
|
|
21
29
|
ip: number;
|
|
22
30
|
line: number;
|
|
@@ -28,12 +36,7 @@ export interface Artifact {
|
|
|
28
36
|
abi: AbiFunction[];
|
|
29
37
|
bytecode: string;
|
|
30
38
|
source: string;
|
|
31
|
-
debug?:
|
|
32
|
-
bytecode: string;
|
|
33
|
-
sourceMap: string;
|
|
34
|
-
logs: LogEntry[];
|
|
35
|
-
requireMessages: RequireMessage[];
|
|
36
|
-
};
|
|
39
|
+
debug?: DebugInformation;
|
|
37
40
|
compiler: {
|
|
38
41
|
name: string;
|
|
39
42
|
version: string;
|
package/dist/bitauth-script.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Script } from './script.js';
|
|
2
2
|
export declare type LineToOpcodesMap = Record<string, Script>;
|
|
3
3
|
export declare type LineToAsmMap = Record<string, string>;
|
|
4
|
-
export declare function buildLineToOpcodesMap(bytecode: Script,
|
|
5
|
-
export declare function buildLineToAsmMap(bytecode: Script,
|
|
6
|
-
export declare function formatBitAuthScript(bytecode: Script,
|
|
4
|
+
export declare function buildLineToOpcodesMap(bytecode: Script, sourceMap: string): LineToOpcodesMap;
|
|
5
|
+
export declare function buildLineToAsmMap(bytecode: Script, sourceMap: string): LineToAsmMap;
|
|
6
|
+
export declare function formatBitAuthScript(bytecode: Script, sourceMap: string, sourceCode: string): string;
|
package/dist/bitauth-script.js
CHANGED
|
@@ -1,23 +1,25 @@
|
|
|
1
1
|
import { scriptToBitAuthAsm } from './script.js';
|
|
2
2
|
import { sourceMapToLocationData } from './source-map.js';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
import { PositionHint } from './types.js';
|
|
4
|
+
export function buildLineToOpcodesMap(bytecode, sourceMap) {
|
|
5
|
+
const locationData = sourceMapToLocationData(sourceMap);
|
|
6
|
+
return locationData.reduce((lineToOpcodeMap, { location, positionHint }, index) => {
|
|
6
7
|
const opcode = bytecode[index];
|
|
7
|
-
const line = positionHint ? location?.end.line : location?.start.line;
|
|
8
|
+
const line = positionHint === PositionHint.END ? location?.end.line : location?.start.line;
|
|
8
9
|
return {
|
|
9
10
|
...lineToOpcodeMap,
|
|
10
11
|
[line]: [...(lineToOpcodeMap[line] || []), opcode],
|
|
11
12
|
};
|
|
12
13
|
}, {});
|
|
13
14
|
}
|
|
14
|
-
export function buildLineToAsmMap(bytecode,
|
|
15
|
-
const lineToOpcodesMap = buildLineToOpcodesMap(bytecode,
|
|
15
|
+
export function buildLineToAsmMap(bytecode, sourceMap) {
|
|
16
|
+
const lineToOpcodesMap = buildLineToOpcodesMap(bytecode, sourceMap);
|
|
16
17
|
return Object.fromEntries(Object.entries(lineToOpcodesMap).map(([lineNumber, opcodeList]) => [lineNumber, scriptToBitAuthAsm(opcodeList)]));
|
|
17
18
|
}
|
|
18
|
-
export function formatBitAuthScript(bytecode,
|
|
19
|
-
const lineToAsmMap = buildLineToAsmMap(bytecode,
|
|
20
|
-
const
|
|
19
|
+
export function formatBitAuthScript(bytecode, sourceMap, sourceCode) {
|
|
20
|
+
const lineToAsmMap = buildLineToAsmMap(bytecode, sourceMap);
|
|
21
|
+
const escapedSourceCode = sourceCode.replaceAll('/*', '\\/*').replaceAll('*/', '*\\/');
|
|
22
|
+
const sourceCodeLines = escapedSourceCode.split('\n');
|
|
21
23
|
const sourceCodeLineLengths = sourceCodeLines.map((line) => line.length);
|
|
22
24
|
const bytecodeLineLengths = Object.values(lineToAsmMap).map((line) => line.length);
|
|
23
25
|
const maxSourceCodeLength = Math.max(...sourceCodeLineLengths);
|
package/dist/source-map.d.ts
CHANGED
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
column: number;
|
|
5
|
-
};
|
|
6
|
-
end: {
|
|
7
|
-
line: number;
|
|
8
|
-
column: number;
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
export declare type LocationData = Array<[location: LocationI, positionHint?: number]>;
|
|
12
|
-
export declare function generateSourceMap(locationData: LocationData): string;
|
|
13
|
-
export declare const sourceMapToLocationData: (sourceMap: string) => LocationData;
|
|
1
|
+
import { FullLocationData } from './types.js';
|
|
2
|
+
export declare function generateSourceMap(locationData: FullLocationData): string;
|
|
3
|
+
export declare const sourceMapToLocationData: (sourceMap: string) => FullLocationData;
|
package/dist/source-map.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PositionHint } from './types.js';
|
|
1
2
|
/*
|
|
2
3
|
* The source mappings for the bytecode use the following notation (similar to Solidity):
|
|
3
4
|
*
|
|
@@ -28,17 +29,17 @@ export function generateSourceMap(locationData) {
|
|
|
28
29
|
let prevStartColumn = 0;
|
|
29
30
|
let prevEndLine = 0;
|
|
30
31
|
let prevEndColumn = 0;
|
|
31
|
-
let prevHint =
|
|
32
|
-
return locationData.map((
|
|
33
|
-
const prevStartLineString = prevStartLine ===
|
|
34
|
-
prevStartLine =
|
|
35
|
-
const prevStartColumnString = prevStartColumn ===
|
|
36
|
-
prevStartColumn =
|
|
37
|
-
const prevEndLineString = prevEndLine ===
|
|
38
|
-
prevEndLine =
|
|
39
|
-
const prevEndColumnString = prevEndColumn ===
|
|
40
|
-
prevEndColumn =
|
|
41
|
-
const hint =
|
|
32
|
+
let prevHint = PositionHint.START;
|
|
33
|
+
return locationData.map(({ location, positionHint }) => {
|
|
34
|
+
const prevStartLineString = prevStartLine === location.start.line ? '' : String(location.start.line);
|
|
35
|
+
prevStartLine = location.start.line;
|
|
36
|
+
const prevStartColumnString = prevStartColumn === location.start.column ? '' : String(location.start.column);
|
|
37
|
+
prevStartColumn = location.start.column;
|
|
38
|
+
const prevEndLineString = prevEndLine === location.end.line ? '' : String(location.end.line);
|
|
39
|
+
prevEndLine = location.end.line;
|
|
40
|
+
const prevEndColumnString = prevEndColumn === location.end.column ? '' : String(location.end.column);
|
|
41
|
+
prevEndColumn = location.end.column;
|
|
42
|
+
const hint = positionHint ?? PositionHint.START;
|
|
42
43
|
const prevHintString = prevHint === hint ? '' : String(hint);
|
|
43
44
|
prevHint = hint;
|
|
44
45
|
let result = '';
|
|
@@ -72,24 +73,31 @@ export const sourceMapToLocationData = (sourceMap) => {
|
|
|
72
73
|
let prevEndColumn = 0;
|
|
73
74
|
let prevHint;
|
|
74
75
|
return sourceMap.split(';').map((entry) => {
|
|
75
|
-
const
|
|
76
|
-
const startLine =
|
|
76
|
+
const [startLineStr, startColumnStr, endLineStr, endColumnStr, positionHintStr] = entry.split(':');
|
|
77
|
+
const startLine = startLineStr ? Number(startLineStr) : prevStartLine;
|
|
77
78
|
prevStartLine = startLine;
|
|
78
|
-
const startColumn =
|
|
79
|
+
const startColumn = startColumnStr ? Number(startColumnStr) : prevStartColumn;
|
|
79
80
|
prevStartColumn = startColumn;
|
|
80
|
-
const endLine =
|
|
81
|
+
const endLine = endLineStr ? Number(endLineStr) : prevEndLine;
|
|
81
82
|
prevEndLine = endLine;
|
|
82
|
-
const endColumn =
|
|
83
|
+
const endColumn = endColumnStr ? Number(endColumnStr) : prevEndColumn;
|
|
83
84
|
prevEndColumn = endColumn;
|
|
84
|
-
const hint =
|
|
85
|
+
const hint = parsePositionHint(positionHintStr) ?? prevHint;
|
|
85
86
|
prevHint = hint;
|
|
86
|
-
return
|
|
87
|
-
{
|
|
87
|
+
return {
|
|
88
|
+
location: {
|
|
88
89
|
start: { line: startLine, column: startColumn },
|
|
89
90
|
end: { line: endLine, column: endColumn },
|
|
90
91
|
},
|
|
91
|
-
...(hint ?
|
|
92
|
-
|
|
92
|
+
...(hint ? { positionHint: hint } : {}),
|
|
93
|
+
};
|
|
93
94
|
});
|
|
94
95
|
};
|
|
96
|
+
const parsePositionHint = (hint) => {
|
|
97
|
+
if (hint === '1')
|
|
98
|
+
return PositionHint.END;
|
|
99
|
+
if (hint === '0')
|
|
100
|
+
return PositionHint.START;
|
|
101
|
+
return undefined;
|
|
102
|
+
};
|
|
95
103
|
//# sourceMappingURL=source-map.js.map
|
package/dist/types.d.ts
CHANGED
|
@@ -32,3 +32,22 @@ export declare function arrayType(types: Type[]): Type | undefined;
|
|
|
32
32
|
export declare function implicitlyCastableSignature(actual: Type[], expected: Type[]): boolean;
|
|
33
33
|
export declare function parseType(str: string): Type;
|
|
34
34
|
export declare function isPrimitive(type: Type): type is PrimitiveType;
|
|
35
|
+
export interface LocationI {
|
|
36
|
+
start: {
|
|
37
|
+
line: number;
|
|
38
|
+
column: number;
|
|
39
|
+
};
|
|
40
|
+
end: {
|
|
41
|
+
line: number;
|
|
42
|
+
column: number;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
export declare type SingleLocationData = {
|
|
46
|
+
location: LocationI;
|
|
47
|
+
positionHint?: PositionHint;
|
|
48
|
+
};
|
|
49
|
+
export declare type FullLocationData = Array<SingleLocationData>;
|
|
50
|
+
export declare enum PositionHint {
|
|
51
|
+
START = 0,
|
|
52
|
+
END = 1
|
|
53
|
+
}
|
package/dist/types.js
CHANGED
|
@@ -172,4 +172,10 @@ export function parseType(str) {
|
|
|
172
172
|
export function isPrimitive(type) {
|
|
173
173
|
return !!PrimitiveType[type.toString().toUpperCase()];
|
|
174
174
|
}
|
|
175
|
+
// Denotes whether an opcode belongs to the "start" or "end" of the statement it's in (defaults to "start")
|
|
176
|
+
export var PositionHint;
|
|
177
|
+
(function (PositionHint) {
|
|
178
|
+
PositionHint[PositionHint["START"] = 0] = "START";
|
|
179
|
+
PositionHint[PositionHint["END"] = 1] = "END";
|
|
180
|
+
})(PositionHint || (PositionHint = {}));
|
|
175
181
|
//# sourceMappingURL=types.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cashscript/utils",
|
|
3
|
-
"version": "0.10.0-next.
|
|
3
|
+
"version": "0.10.0-next.4",
|
|
4
4
|
"description": "CashScript utilities and types",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bitcoin cash",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"test": "NODE_OPTIONS='--experimental-vm-modules --no-warnings' jest"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@bitauth/libauth": "^2.0.0
|
|
43
|
+
"@bitauth/libauth": "^2.0.0",
|
|
44
44
|
"hash.js": "^1.1.7"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
"jest": "^29.4.1",
|
|
50
50
|
"typescript": "^4.1.5"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "9105dbcd300aa6a96f8f5297147572a9a79af6c4"
|
|
53
53
|
}
|