@cashscript/utils 0.6.2 → 0.7.0-next.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/dist/main/artifact.d.ts +1 -1
- package/dist/main/data.d.ts +1 -1
- package/dist/main/script.d.ts +17 -1
- package/dist/main/script.js +19 -1
- package/dist/main/types.js +4 -4
- package/dist/module/artifact.d.ts +1 -1
- package/dist/module/data.d.ts +1 -1
- package/dist/module/script.d.ts +17 -1
- package/dist/module/script.js +18 -0
- package/dist/module/types.js +4 -4
- package/package.json +1 -1
package/dist/main/artifact.d.ts
CHANGED
package/dist/main/data.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare function encodeBool(bool: boolean): Uint8Array;
|
|
2
2
|
export declare function decodeBool(encodedBool: Uint8Array): boolean;
|
|
3
|
-
export declare function encodeInt(int: number): Uint8Array;
|
|
3
|
+
export declare function encodeInt(int: number | bigint): Uint8Array;
|
|
4
4
|
export declare function decodeInt(encodedInt: Uint8Array, maxLength?: number): number;
|
|
5
5
|
export declare function encodeString(str: string): Uint8Array;
|
|
6
6
|
export declare function decodeString(encodedString: Uint8Array): string;
|
package/dist/main/script.d.ts
CHANGED
|
@@ -1,4 +1,20 @@
|
|
|
1
1
|
import { OpcodesBCH } from '@bitauth/libauth';
|
|
2
|
+
export declare enum IntrospectionOp {
|
|
3
|
+
OP_INPUTINDEX = 192,
|
|
4
|
+
OP_ACTIVEBYTECODE = 193,
|
|
5
|
+
OP_TXVERSION = 194,
|
|
6
|
+
OP_TXINPUTCOUNT = 195,
|
|
7
|
+
OP_TXOUTPUTCOUNT = 196,
|
|
8
|
+
OP_TXLOCKTIME = 197,
|
|
9
|
+
OP_UTXOVALUE = 198,
|
|
10
|
+
OP_UTXOBYTECODE = 199,
|
|
11
|
+
OP_OUTPOINTTXHASH = 200,
|
|
12
|
+
OP_OUTPOINTINDEX = 201,
|
|
13
|
+
OP_INPUTBYTECODE = 202,
|
|
14
|
+
OP_INPUTSEQUENCENUMBER = 203,
|
|
15
|
+
OP_OUTPUTVALUE = 204,
|
|
16
|
+
OP_OUTPUTBYTECODE = 205
|
|
17
|
+
}
|
|
2
18
|
export declare const Op: typeof OpcodesBCH;
|
|
3
19
|
export declare type Op = number;
|
|
4
20
|
export declare type OpOrData = Op | Uint8Array;
|
|
@@ -11,7 +27,7 @@ export declare function asmToBytecode(asm: string): Uint8Array;
|
|
|
11
27
|
export declare function bytecodeToAsm(bytecode: Uint8Array): string;
|
|
12
28
|
export declare function countOpcodes(script: Script): number;
|
|
13
29
|
export declare function calculateBytesize(script: Script): number;
|
|
14
|
-
export declare function encodeNullDataScript(chunks:
|
|
30
|
+
export declare function encodeNullDataScript(chunks: OpOrData[]): Uint8Array;
|
|
15
31
|
/**
|
|
16
32
|
* When cutting out the tx.bytecode preimage variable, the compiler does not know
|
|
17
33
|
* the size of the final redeem scrip yet, because the constructor parameters still
|
package/dist/main/script.js
CHANGED
|
@@ -3,10 +3,28 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.optimiseBytecode = exports.generateRedeemScript = exports.replaceBytecodeNop = exports.encodeNullDataScript = exports.calculateBytesize = exports.countOpcodes = exports.bytecodeToAsm = exports.asmToBytecode = exports.bytecodeToScript = exports.scriptToBytecode = exports.asmToScript = exports.scriptToAsm = exports.Op = void 0;
|
|
6
|
+
exports.optimiseBytecode = exports.generateRedeemScript = exports.replaceBytecodeNop = exports.encodeNullDataScript = exports.calculateBytesize = exports.countOpcodes = exports.bytecodeToAsm = exports.asmToBytecode = exports.bytecodeToScript = exports.scriptToBytecode = exports.asmToScript = exports.scriptToAsm = exports.Op = exports.IntrospectionOp = void 0;
|
|
7
7
|
const libauth_1 = require("@bitauth/libauth");
|
|
8
8
|
const data_1 = require("./data");
|
|
9
9
|
const cashproof_optimisations_1 = __importDefault(require("./cashproof-optimisations"));
|
|
10
|
+
// TODO: Replace this when these opcodes are in Libauth
|
|
11
|
+
var IntrospectionOp;
|
|
12
|
+
(function (IntrospectionOp) {
|
|
13
|
+
IntrospectionOp[IntrospectionOp["OP_INPUTINDEX"] = 192] = "OP_INPUTINDEX";
|
|
14
|
+
IntrospectionOp[IntrospectionOp["OP_ACTIVEBYTECODE"] = 193] = "OP_ACTIVEBYTECODE";
|
|
15
|
+
IntrospectionOp[IntrospectionOp["OP_TXVERSION"] = 194] = "OP_TXVERSION";
|
|
16
|
+
IntrospectionOp[IntrospectionOp["OP_TXINPUTCOUNT"] = 195] = "OP_TXINPUTCOUNT";
|
|
17
|
+
IntrospectionOp[IntrospectionOp["OP_TXOUTPUTCOUNT"] = 196] = "OP_TXOUTPUTCOUNT";
|
|
18
|
+
IntrospectionOp[IntrospectionOp["OP_TXLOCKTIME"] = 197] = "OP_TXLOCKTIME";
|
|
19
|
+
IntrospectionOp[IntrospectionOp["OP_UTXOVALUE"] = 198] = "OP_UTXOVALUE";
|
|
20
|
+
IntrospectionOp[IntrospectionOp["OP_UTXOBYTECODE"] = 199] = "OP_UTXOBYTECODE";
|
|
21
|
+
IntrospectionOp[IntrospectionOp["OP_OUTPOINTTXHASH"] = 200] = "OP_OUTPOINTTXHASH";
|
|
22
|
+
IntrospectionOp[IntrospectionOp["OP_OUTPOINTINDEX"] = 201] = "OP_OUTPOINTINDEX";
|
|
23
|
+
IntrospectionOp[IntrospectionOp["OP_INPUTBYTECODE"] = 202] = "OP_INPUTBYTECODE";
|
|
24
|
+
IntrospectionOp[IntrospectionOp["OP_INPUTSEQUENCENUMBER"] = 203] = "OP_INPUTSEQUENCENUMBER";
|
|
25
|
+
IntrospectionOp[IntrospectionOp["OP_OUTPUTVALUE"] = 204] = "OP_OUTPUTVALUE";
|
|
26
|
+
IntrospectionOp[IntrospectionOp["OP_OUTPUTBYTECODE"] = 205] = "OP_OUTPUTBYTECODE";
|
|
27
|
+
})(IntrospectionOp = exports.IntrospectionOp || (exports.IntrospectionOp = {}));
|
|
10
28
|
exports.Op = libauth_1.OpcodesBCH;
|
|
11
29
|
function scriptToAsm(script) {
|
|
12
30
|
return bytecodeToAsm(scriptToBytecode(script));
|
package/dist/main/types.js
CHANGED
|
@@ -17,7 +17,7 @@ class BytesType {
|
|
|
17
17
|
this.bound = bound;
|
|
18
18
|
}
|
|
19
19
|
static fromString(str) {
|
|
20
|
-
const bound = Number.parseInt(str.substring(5), 10) || undefined;
|
|
20
|
+
const bound = str === 'byte' ? 1 : Number.parseInt(str.substring(5), 10) || undefined;
|
|
21
21
|
return new BytesType(bound);
|
|
22
22
|
}
|
|
23
23
|
toString() {
|
|
@@ -53,7 +53,7 @@ const ExplicitlyCastableTo = {
|
|
|
53
53
|
[PrimitiveType.BOOL]: [PrimitiveType.BOOL, PrimitiveType.INT],
|
|
54
54
|
[PrimitiveType.STRING]: [PrimitiveType.STRING],
|
|
55
55
|
[PrimitiveType.PUBKEY]: [PrimitiveType.PUBKEY],
|
|
56
|
-
[PrimitiveType.SIG]: [PrimitiveType.SIG
|
|
56
|
+
[PrimitiveType.SIG]: [PrimitiveType.SIG],
|
|
57
57
|
[PrimitiveType.DATASIG]: [PrimitiveType.DATASIG],
|
|
58
58
|
[PrimitiveType.ANY]: [],
|
|
59
59
|
};
|
|
@@ -93,7 +93,7 @@ function explicitlyCastable(from, to) {
|
|
|
93
93
|
if (from instanceof BytesType) {
|
|
94
94
|
// Can cast unbounded bytes or <=4 bytes to int
|
|
95
95
|
if (to === PrimitiveType.INT)
|
|
96
|
-
return !from.bound || from.bound <=
|
|
96
|
+
return !from.bound || from.bound <= 8;
|
|
97
97
|
// Can't cast bytes to bool or string
|
|
98
98
|
if (to === PrimitiveType.BOOL)
|
|
99
99
|
return false;
|
|
@@ -180,7 +180,7 @@ function implicitlyCastableSignature(actual, expected) {
|
|
|
180
180
|
}
|
|
181
181
|
exports.implicitlyCastableSignature = implicitlyCastableSignature;
|
|
182
182
|
function parseType(str) {
|
|
183
|
-
if (str.startsWith('
|
|
183
|
+
if (str.startsWith('byte'))
|
|
184
184
|
return BytesType.fromString(str);
|
|
185
185
|
return PrimitiveType[str.toUpperCase()];
|
|
186
186
|
}
|
package/dist/module/data.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare function encodeBool(bool: boolean): Uint8Array;
|
|
2
2
|
export declare function decodeBool(encodedBool: Uint8Array): boolean;
|
|
3
|
-
export declare function encodeInt(int: number): Uint8Array;
|
|
3
|
+
export declare function encodeInt(int: number | bigint): Uint8Array;
|
|
4
4
|
export declare function decodeInt(encodedInt: Uint8Array, maxLength?: number): number;
|
|
5
5
|
export declare function encodeString(str: string): Uint8Array;
|
|
6
6
|
export declare function decodeString(encodedString: Uint8Array): string;
|
package/dist/module/script.d.ts
CHANGED
|
@@ -1,4 +1,20 @@
|
|
|
1
1
|
import { OpcodesBCH } from '@bitauth/libauth';
|
|
2
|
+
export declare enum IntrospectionOp {
|
|
3
|
+
OP_INPUTINDEX = 192,
|
|
4
|
+
OP_ACTIVEBYTECODE = 193,
|
|
5
|
+
OP_TXVERSION = 194,
|
|
6
|
+
OP_TXINPUTCOUNT = 195,
|
|
7
|
+
OP_TXOUTPUTCOUNT = 196,
|
|
8
|
+
OP_TXLOCKTIME = 197,
|
|
9
|
+
OP_UTXOVALUE = 198,
|
|
10
|
+
OP_UTXOBYTECODE = 199,
|
|
11
|
+
OP_OUTPOINTTXHASH = 200,
|
|
12
|
+
OP_OUTPOINTINDEX = 201,
|
|
13
|
+
OP_INPUTBYTECODE = 202,
|
|
14
|
+
OP_INPUTSEQUENCENUMBER = 203,
|
|
15
|
+
OP_OUTPUTVALUE = 204,
|
|
16
|
+
OP_OUTPUTBYTECODE = 205
|
|
17
|
+
}
|
|
2
18
|
export declare const Op: typeof OpcodesBCH;
|
|
3
19
|
export declare type Op = number;
|
|
4
20
|
export declare type OpOrData = Op | Uint8Array;
|
|
@@ -11,7 +27,7 @@ export declare function asmToBytecode(asm: string): Uint8Array;
|
|
|
11
27
|
export declare function bytecodeToAsm(bytecode: Uint8Array): string;
|
|
12
28
|
export declare function countOpcodes(script: Script): number;
|
|
13
29
|
export declare function calculateBytesize(script: Script): number;
|
|
14
|
-
export declare function encodeNullDataScript(chunks:
|
|
30
|
+
export declare function encodeNullDataScript(chunks: OpOrData[]): Uint8Array;
|
|
15
31
|
/**
|
|
16
32
|
* When cutting out the tx.bytecode preimage variable, the compiler does not know
|
|
17
33
|
* the size of the final redeem scrip yet, because the constructor parameters still
|
package/dist/module/script.js
CHANGED
|
@@ -1,6 +1,24 @@
|
|
|
1
1
|
import { OpcodesBCH, encodeDataPush, parseBytecode, serializeAuthenticationInstructions, hexToBin, disassembleBytecodeBCH, flattenBinArray, } from '@bitauth/libauth';
|
|
2
2
|
import { decodeInt, encodeInt } from './data';
|
|
3
3
|
import OptimisationsEquivFile from './cashproof-optimisations';
|
|
4
|
+
// TODO: Replace this when these opcodes are in Libauth
|
|
5
|
+
export var IntrospectionOp;
|
|
6
|
+
(function (IntrospectionOp) {
|
|
7
|
+
IntrospectionOp[IntrospectionOp["OP_INPUTINDEX"] = 192] = "OP_INPUTINDEX";
|
|
8
|
+
IntrospectionOp[IntrospectionOp["OP_ACTIVEBYTECODE"] = 193] = "OP_ACTIVEBYTECODE";
|
|
9
|
+
IntrospectionOp[IntrospectionOp["OP_TXVERSION"] = 194] = "OP_TXVERSION";
|
|
10
|
+
IntrospectionOp[IntrospectionOp["OP_TXINPUTCOUNT"] = 195] = "OP_TXINPUTCOUNT";
|
|
11
|
+
IntrospectionOp[IntrospectionOp["OP_TXOUTPUTCOUNT"] = 196] = "OP_TXOUTPUTCOUNT";
|
|
12
|
+
IntrospectionOp[IntrospectionOp["OP_TXLOCKTIME"] = 197] = "OP_TXLOCKTIME";
|
|
13
|
+
IntrospectionOp[IntrospectionOp["OP_UTXOVALUE"] = 198] = "OP_UTXOVALUE";
|
|
14
|
+
IntrospectionOp[IntrospectionOp["OP_UTXOBYTECODE"] = 199] = "OP_UTXOBYTECODE";
|
|
15
|
+
IntrospectionOp[IntrospectionOp["OP_OUTPOINTTXHASH"] = 200] = "OP_OUTPOINTTXHASH";
|
|
16
|
+
IntrospectionOp[IntrospectionOp["OP_OUTPOINTINDEX"] = 201] = "OP_OUTPOINTINDEX";
|
|
17
|
+
IntrospectionOp[IntrospectionOp["OP_INPUTBYTECODE"] = 202] = "OP_INPUTBYTECODE";
|
|
18
|
+
IntrospectionOp[IntrospectionOp["OP_INPUTSEQUENCENUMBER"] = 203] = "OP_INPUTSEQUENCENUMBER";
|
|
19
|
+
IntrospectionOp[IntrospectionOp["OP_OUTPUTVALUE"] = 204] = "OP_OUTPUTVALUE";
|
|
20
|
+
IntrospectionOp[IntrospectionOp["OP_OUTPUTBYTECODE"] = 205] = "OP_OUTPUTBYTECODE";
|
|
21
|
+
})(IntrospectionOp || (IntrospectionOp = {}));
|
|
4
22
|
export const Op = OpcodesBCH;
|
|
5
23
|
export function scriptToAsm(script) {
|
|
6
24
|
return bytecodeToAsm(scriptToBytecode(script));
|
package/dist/module/types.js
CHANGED
|
@@ -13,7 +13,7 @@ export class BytesType {
|
|
|
13
13
|
this.bound = bound;
|
|
14
14
|
}
|
|
15
15
|
static fromString(str) {
|
|
16
|
-
const bound = Number.parseInt(str.substring(5), 10) || undefined;
|
|
16
|
+
const bound = str === 'byte' ? 1 : Number.parseInt(str.substring(5), 10) || undefined;
|
|
17
17
|
return new BytesType(bound);
|
|
18
18
|
}
|
|
19
19
|
toString() {
|
|
@@ -47,7 +47,7 @@ const ExplicitlyCastableTo = {
|
|
|
47
47
|
[PrimitiveType.BOOL]: [PrimitiveType.BOOL, PrimitiveType.INT],
|
|
48
48
|
[PrimitiveType.STRING]: [PrimitiveType.STRING],
|
|
49
49
|
[PrimitiveType.PUBKEY]: [PrimitiveType.PUBKEY],
|
|
50
|
-
[PrimitiveType.SIG]: [PrimitiveType.SIG
|
|
50
|
+
[PrimitiveType.SIG]: [PrimitiveType.SIG],
|
|
51
51
|
[PrimitiveType.DATASIG]: [PrimitiveType.DATASIG],
|
|
52
52
|
[PrimitiveType.ANY]: [],
|
|
53
53
|
};
|
|
@@ -87,7 +87,7 @@ export function explicitlyCastable(from, to) {
|
|
|
87
87
|
if (from instanceof BytesType) {
|
|
88
88
|
// Can cast unbounded bytes or <=4 bytes to int
|
|
89
89
|
if (to === PrimitiveType.INT)
|
|
90
|
-
return !from.bound || from.bound <=
|
|
90
|
+
return !from.bound || from.bound <= 8;
|
|
91
91
|
// Can't cast bytes to bool or string
|
|
92
92
|
if (to === PrimitiveType.BOOL)
|
|
93
93
|
return false;
|
|
@@ -169,7 +169,7 @@ export function implicitlyCastableSignature(actual, expected) {
|
|
|
169
169
|
return expected.every((t, i) => implicitlyCastable(actual[i], t));
|
|
170
170
|
}
|
|
171
171
|
export function parseType(str) {
|
|
172
|
-
if (str.startsWith('
|
|
172
|
+
if (str.startsWith('byte'))
|
|
173
173
|
return BytesType.fromString(str);
|
|
174
174
|
return PrimitiveType[str.toUpperCase()];
|
|
175
175
|
}
|