@cashscript/utils 0.13.0-next.5 → 0.13.0-next.7
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/data.d.ts +1 -0
- package/dist/data.js +7 -1
- package/package.json +2 -2
package/dist/data.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export declare function encodeBool(bool: boolean): Uint8Array;
|
|
2
2
|
export declare function decodeBool(encodedBool: Uint8Array): boolean;
|
|
3
3
|
export declare function encodeInt(int: bigint): Uint8Array;
|
|
4
|
+
export declare function encodeIntAsFixedBytes(int: bigint, byteLength: number): Uint8Array;
|
|
4
5
|
export declare function decodeInt(encodedInt: Uint8Array, maxLength?: number): bigint;
|
|
5
6
|
export declare function encodeString(str: string): Uint8Array;
|
|
6
7
|
export declare function decodeString(encodedString: Uint8Array): string;
|
package/dist/data.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { bigIntToVmNumber, utf8ToBin, binToUtf8, vmNumberToBigInt, isVmNumberError, } from '@bitauth/libauth';
|
|
1
|
+
import { bigIntToVmNumber, utf8ToBin, binToUtf8, vmNumberToBigInt, isVmNumberError, padMinimallyEncodedVmNumber, } from '@bitauth/libauth';
|
|
2
2
|
export function encodeBool(bool) {
|
|
3
3
|
return bool ? encodeInt(1n) : encodeInt(0n);
|
|
4
4
|
}
|
|
@@ -17,6 +17,12 @@ export function decodeBool(encodedBool) {
|
|
|
17
17
|
export function encodeInt(int) {
|
|
18
18
|
return bigIntToVmNumber(int);
|
|
19
19
|
}
|
|
20
|
+
export function encodeIntAsFixedBytes(int, byteLength) {
|
|
21
|
+
const minimal = encodeInt(int);
|
|
22
|
+
if (minimal.length > byteLength)
|
|
23
|
+
throw new Error('value exceeds the requested byteLength');
|
|
24
|
+
return padMinimallyEncodedVmNumber(minimal, byteLength);
|
|
25
|
+
}
|
|
20
26
|
export function decodeInt(encodedInt, maxLength = Infinity) {
|
|
21
27
|
const options = { maximumVmNumberByteLength: maxLength };
|
|
22
28
|
const result = vmNumberToBigInt(encodedInt, options);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cashscript/utils",
|
|
3
|
-
"version": "0.13.0-next.
|
|
3
|
+
"version": "0.13.0-next.7",
|
|
4
4
|
"description": "CashScript utilities and types",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bitcoin cash",
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"typescript": "^5.9.2",
|
|
49
49
|
"vitest": "^4.0.15"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "4e8e91589e1218a7c04db1a4772f625efb0140e9"
|
|
52
52
|
}
|