@cashscript/utils 0.10.0-next.6 → 0.10.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.
- package/README.md +3 -3
- package/dist/artifact.d.ts +1 -2
- package/dist/bitauth-script.d.ts +2 -2
- package/dist/script.d.ts +3 -3
- package/dist/script.js +1 -4
- package/dist/source-map.js +2 -2
- package/dist/types.d.ts +4 -4
- package/dist/types.js +5 -0
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# @cashscript/utils
|
|
2
2
|
|
|
3
|
-
[](https://travis-ci.org/CashScript/cashscript)
|
|
4
|
+
[](https://codecov.io/gh/CashScript/cashscript)
|
|
5
5
|
[](https://www.npmjs.com/package/@cashscript/utils)
|
|
6
6
|
[](hhttps://www.npmjs.com/package/@cashscript/utils)
|
|
7
7
|
[](https://www.npmjs.com/package/@cashscript/utils)
|
|
8
8
|
|
|
9
|
-
`@cashscript/utils` is a package containing a number of utilities and types used by both the CashScript compiler and the
|
|
9
|
+
`@cashscript/utils` is a package containing a number of utilities and types used by both the CashScript compiler and the TypeScript SDK. This package can be used by other applications as well, but it should be considered an unstable API and will not necessarily follow semantic versioning rules. So if you want to use `@cashscript/utils` as a standalone package, it is recommended to specify a specific version (instead of a range) in your `package.json`.
|
package/dist/artifact.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import { PathLike } from 'fs';
|
|
3
2
|
export interface AbiInput {
|
|
4
3
|
name: string;
|
|
@@ -25,7 +24,7 @@ export interface StackItem {
|
|
|
25
24
|
stackIndex: number;
|
|
26
25
|
ip: number;
|
|
27
26
|
}
|
|
28
|
-
export
|
|
27
|
+
export type LogData = StackItem | string;
|
|
29
28
|
export interface RequireStatement {
|
|
30
29
|
ip: number;
|
|
31
30
|
line: number;
|
package/dist/bitauth-script.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Script } from './script.js';
|
|
2
|
-
export
|
|
3
|
-
export
|
|
2
|
+
export type LineToOpcodesMap = Record<string, Script>;
|
|
3
|
+
export type LineToAsmMap = Record<string, string>;
|
|
4
4
|
export declare function buildLineToOpcodesMap(bytecode: Script, sourceMap: string): LineToOpcodesMap;
|
|
5
5
|
export declare function buildLineToAsmMap(bytecode: Script, sourceMap: string): LineToAsmMap;
|
|
6
6
|
export declare function formatBitAuthScript(bytecode: Script, sourceMap: string, sourceCode: string): string;
|
package/dist/script.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare const Op: typeof import("@bitauth/libauth").OpcodesBCH2023;
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
2
|
+
export type Op = number;
|
|
3
|
+
export type OpOrData = Op | Uint8Array;
|
|
4
|
+
export type Script = OpOrData[];
|
|
5
5
|
export declare function scriptToAsm(script: Script): string;
|
|
6
6
|
export declare function scriptToBitAuthAsm(script: Script): string;
|
|
7
7
|
export declare function asmToScript(asm: string): Script;
|
package/dist/script.js
CHANGED
|
@@ -5,11 +5,9 @@ export const Op = OpcodesBCH;
|
|
|
5
5
|
export function scriptToAsm(script) {
|
|
6
6
|
return bytecodeToAsm(scriptToBytecode(script));
|
|
7
7
|
}
|
|
8
|
-
// TODO: See note at bytecodeToAsm
|
|
9
8
|
export function scriptToBitAuthAsm(script) {
|
|
10
9
|
return bytecodeToBitAuthAsm(scriptToBytecode(script));
|
|
11
10
|
}
|
|
12
|
-
// TODO: Figure out why OP_0 is decoded to an empty Uint8Array (while e.g. OP_3 is just OP_3)
|
|
13
11
|
export function asmToScript(asm) {
|
|
14
12
|
return bytecodeToScript(asmToBytecode(asm));
|
|
15
13
|
}
|
|
@@ -60,8 +58,7 @@ export function bytecodeToAsm(bytecode) {
|
|
|
60
58
|
asm = asm.replace(/\s+/g, ' ').trim();
|
|
61
59
|
return asm;
|
|
62
60
|
}
|
|
63
|
-
// TODO: If we decide to change the ASM / artifact format, we can remove this function and merge it
|
|
64
|
-
// with bytecodeToAsm
|
|
61
|
+
// TODO: If we decide to change the ASM / artifact format, we can remove this function and merge it with bytecodeToAsm
|
|
65
62
|
export function bytecodeToBitAuthAsm(bytecode) {
|
|
66
63
|
// Convert the bytecode to libauth's ASM format
|
|
67
64
|
let asm = disassembleBytecodeBCH(bytecode);
|
package/dist/source-map.js
CHANGED
|
@@ -71,7 +71,7 @@ export const sourceMapToLocationData = (sourceMap) => {
|
|
|
71
71
|
let prevStartColumn = 0;
|
|
72
72
|
let prevEndLine = 0;
|
|
73
73
|
let prevEndColumn = 0;
|
|
74
|
-
let prevHint;
|
|
74
|
+
let prevHint = PositionHint.START;
|
|
75
75
|
return sourceMap.split(';').map((entry) => {
|
|
76
76
|
const [startLineStr, startColumnStr, endLineStr, endColumnStr, positionHintStr] = entry.split(':');
|
|
77
77
|
const startLine = startLineStr ? Number(startLineStr) : prevStartLine;
|
|
@@ -89,7 +89,7 @@ export const sourceMapToLocationData = (sourceMap) => {
|
|
|
89
89
|
start: { line: startLine, column: startColumn },
|
|
90
90
|
end: { line: endLine, column: endColumn },
|
|
91
91
|
},
|
|
92
|
-
|
|
92
|
+
positionHint: hint,
|
|
93
93
|
};
|
|
94
94
|
});
|
|
95
95
|
};
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type Type = PrimitiveType | ArrayType | TupleType | BytesType;
|
|
2
2
|
export declare class ArrayType {
|
|
3
3
|
elementType: Type;
|
|
4
4
|
bound?: number | undefined;
|
|
@@ -42,11 +42,11 @@ export interface LocationI {
|
|
|
42
42
|
column: number;
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
|
-
export
|
|
45
|
+
export type SingleLocationData = {
|
|
46
46
|
location: LocationI;
|
|
47
|
-
positionHint
|
|
47
|
+
positionHint: PositionHint;
|
|
48
48
|
};
|
|
49
|
-
export
|
|
49
|
+
export type FullLocationData = Array<SingleLocationData>;
|
|
50
50
|
export declare enum PositionHint {
|
|
51
51
|
START = 0,
|
|
52
52
|
END = 1
|
package/dist/types.js
CHANGED
|
@@ -173,6 +173,11 @@ export function isPrimitive(type) {
|
|
|
173
173
|
return !!PrimitiveType[type.toString().toUpperCase()];
|
|
174
174
|
}
|
|
175
175
|
// Denotes whether an opcode belongs to the "start" or "end" of the statement it's in (defaults to "start")
|
|
176
|
+
// Examples:
|
|
177
|
+
// require(true); --> the OP_VERIFY comes after the condition (OP_TRUE), so it should get a PositionHint.END
|
|
178
|
+
// !true --> the OP_NOT comes after the condition (OP_TRUE), so it should get a PositionHint.END
|
|
179
|
+
// if (true) { ... } --> the OP_IF comes before the body, so it should get a PositionHint.START,
|
|
180
|
+
// the OP_ENDIF comes after the body, so it should get a PositionHint.END
|
|
176
181
|
export var PositionHint;
|
|
177
182
|
(function (PositionHint) {
|
|
178
183
|
PositionHint[PositionHint["START"] = 0] = "START";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cashscript/utils",
|
|
3
|
-
"version": "0.10.0
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "CashScript utilities and types",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bitcoin cash",
|
|
@@ -10,11 +10,11 @@
|
|
|
10
10
|
],
|
|
11
11
|
"homepage": "https://cashscript.org",
|
|
12
12
|
"bugs": {
|
|
13
|
-
"url": "https://github.com/
|
|
13
|
+
"url": "https://github.com/CashScript/cashscript/issues"
|
|
14
14
|
},
|
|
15
15
|
"repository": {
|
|
16
16
|
"type": "git",
|
|
17
|
-
"url": "git+https://github.com/
|
|
17
|
+
"url": "git+https://github.com/CashScript/cashscript.git"
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"author": "Rosco Kalis <roscokalis@gmail.com>",
|
|
@@ -40,14 +40,14 @@
|
|
|
40
40
|
"test": "NODE_OPTIONS='--experimental-vm-modules --no-warnings' jest"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@bitauth/libauth": "^
|
|
43
|
+
"@bitauth/libauth": "^3.0.0",
|
|
44
44
|
"hash.js": "^1.1.7"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@jest/globals": "^29.4.1",
|
|
48
48
|
"eslint": "^8.54.0",
|
|
49
49
|
"jest": "^29.4.1",
|
|
50
|
-
"typescript": "^
|
|
50
|
+
"typescript": "^5.5.4"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "cd3031b60dc4ca2d2351608dfd838a50bcc7bbb9"
|
|
53
53
|
}
|