@cashscript/utils 0.10.0-next.5 → 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 CHANGED
@@ -1,9 +1,9 @@
1
1
  # @cashscript/utils
2
2
 
3
- [![Build Status](https://travis-ci.org/Bitcoin-com/cashscript.svg)](https://travis-ci.org/Bitcoin-com/cashscript)
4
- [![Coverage Status](https://img.shields.io/codecov/c/github/Bitcoin-com/cashscript.svg)](https://codecov.io/gh/Bitcoin-com/cashscript)
3
+ [![Build Status](https://travis-ci.org/CashScript/cashscript.svg)](https://travis-ci.org/CashScript/cashscript)
4
+ [![Coverage Status](https://img.shields.io/codecov/c/github/CashScript/cashscript.svg)](https://codecov.io/gh/CashScript/cashscript)
5
5
  [![NPM Version](https://img.shields.io/npm/v/@cashscript/utils.svg)](https://www.npmjs.com/package/@cashscript/utils)
6
6
  [![NPM Monthly Downloads](https://img.shields.io/npm/dm/@cashscript/utils.svg)](hhttps://www.npmjs.com/package/@cashscript/utils)
7
7
  [![NPM License](https://img.shields.io/npm/l/@cashscript/utils.svg)](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 JavaScript 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`.
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`.
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { PathLike } from 'fs';
3
2
  export interface AbiInput {
4
3
  name: string;
@@ -13,7 +12,7 @@ export interface DebugInformation {
13
12
  bytecode: string;
14
13
  sourceMap: string;
15
14
  logs: LogEntry[];
16
- requireMessages: RequireMessage[];
15
+ requires: RequireStatement[];
17
16
  }
18
17
  export interface LogEntry {
19
18
  ip: number;
@@ -23,12 +22,13 @@ export interface LogEntry {
23
22
  export interface StackItem {
24
23
  type: string;
25
24
  stackIndex: number;
25
+ ip: number;
26
26
  }
27
- export declare type LogData = StackItem | string;
28
- export interface RequireMessage {
27
+ export type LogData = StackItem | string;
28
+ export interface RequireStatement {
29
29
  ip: number;
30
30
  line: number;
31
- message: string;
31
+ message?: string;
32
32
  }
33
33
  export interface Artifact {
34
34
  contractName: string;
@@ -1,6 +1,6 @@
1
1
  import { Script } from './script.js';
2
- export declare type LineToOpcodesMap = Record<string, Script>;
3
- export declare type LineToAsmMap = Record<string, string>;
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 declare type Op = number;
3
- export declare type OpOrData = Op | Uint8Array;
4
- export declare type Script = OpOrData[];
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);
@@ -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
- ...(hint ? { positionHint: hint } : {}),
92
+ positionHint: hint,
93
93
  };
94
94
  });
95
95
  };
package/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare type Type = PrimitiveType | ArrayType | TupleType | BytesType;
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 declare type SingleLocationData = {
45
+ export type SingleLocationData = {
46
46
  location: LocationI;
47
- positionHint?: PositionHint;
47
+ positionHint: PositionHint;
48
48
  };
49
- export declare type FullLocationData = Array<SingleLocationData>;
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-next.5",
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/Bitcoin-com/cashscript/issues"
13
+ "url": "https://github.com/CashScript/cashscript/issues"
14
14
  },
15
15
  "repository": {
16
16
  "type": "git",
17
- "url": "git+https://github.com/Bitcoin-com/cashscript.git"
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": "^2.0.0",
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": "^4.1.5"
50
+ "typescript": "^5.5.4"
51
51
  },
52
- "gitHead": "3d6611410e8c7ed9d760071a8c639e91c2cbb477"
52
+ "gitHead": "cd3031b60dc4ca2d2351608dfd838a50bcc7bbb9"
53
53
  }