@harmoniclabs/plu-ts
Advanced tools
Comparing version 0.3.2-dev2 to 0.4.0-dev0
@@ -11,5 +11,6 @@ import { CborObj } from "../../../cbor/CborObj/index.js"; | ||
import { Hash28 } from "../../hashes/Hash28/Hash28.js"; | ||
import { IValue } from "./IValue.js"; | ||
import { IValue, IValueAdaEntry, IValueAsset, IValuePolicyEntry } from "./IValue.js"; | ||
import { IValueAssets } from "./IValue.js"; | ||
import { hex } from "../../../types/HexString/index.js"; | ||
import { CanBeUInteger } from "../../../types/ints/Integer/index.js"; | ||
export type ValueUnitEntry = { | ||
@@ -40,3 +41,7 @@ unit: string; | ||
static isAdaOnly(v: Value): boolean; | ||
static lovelaceEntry(n: CanBeUInteger): IValueAdaEntry; | ||
static lovelaces(n: number | bigint): Value; | ||
static assetEntry(name: Uint8Array, qty: number | bigint): IValueAsset; | ||
static singleAssetEntry(policy: Hash28, name: Uint8Array, qty: number | bigint): IValuePolicyEntry; | ||
static entry(policy: Hash28, assets: IValueAssets): IValuePolicyEntry; | ||
static add(a: Value, b: Value): Value; | ||
@@ -43,0 +48,0 @@ static sub(a: Value, b: Value): Value; |
@@ -63,2 +63,3 @@ "use strict"; | ||
var uint8array_utils_1 = require("@harmoniclabs/uint8array-utils"); | ||
var BasePlutsError_1 = require("../../../errors/BasePlutsError.js"); | ||
var Value = /** @class */ (function () { | ||
@@ -230,13 +231,34 @@ function Value(map) { | ||
}; | ||
Value.lovelaceEntry = function (n) { | ||
return { | ||
policy: "", | ||
assets: [ | ||
{ | ||
name: new Uint8Array([]), | ||
quantity: typeof n === "number" ? Math.round(n) : BigInt(n) | ||
} | ||
] | ||
}; | ||
}; | ||
Value.lovelaces = function (n) { | ||
return new Value([{ | ||
policy: "", | ||
assets: [ | ||
{ | ||
name: new Uint8Array([]), | ||
quantity: typeof n === "number" ? Math.round(n) : BigInt(n) | ||
} | ||
] | ||
}]); | ||
return new Value([Value.lovelaceEntry(n)]); | ||
}; | ||
Value.assetEntry = function (name, qty) { | ||
if (!(name instanceof Uint8Array && | ||
name.length <= 32)) | ||
throw new BasePlutsError_1.BasePlutsError("invalid asset name; must be Uint8Array of length <= 32"); | ||
return { | ||
name: name.slice(), | ||
quantity: typeof qty === "number" ? Math.round(qty) : BigInt(qty) | ||
}; | ||
}; | ||
Value.singleAssetEntry = function (policy, name, qty) { | ||
return { | ||
policy: policy, | ||
assets: [Value.assetEntry(name, qty)] | ||
}; | ||
}; | ||
Value.entry = function (policy, assets) { | ||
return { policy: policy, assets: assets }; | ||
}; | ||
Value.add = function (a, b) { | ||
@@ -243,0 +265,0 @@ return new Value((0, IValue_1.addIValues)(a.map, b.map)); |
@@ -1,6 +0,5 @@ | ||
import { Cloneable } from "../interfaces/Cloneable.js"; | ||
export declare class ByteString implements Cloneable<ByteString> { | ||
export declare class ByteString { | ||
static isStrictInstance(bs: any): bs is ByteString; | ||
protected _bytes: Uint8Array; | ||
constructor(bs: string | Uint8Array); | ||
constructor(bs: string | Uint8Array | ByteString); | ||
/** | ||
@@ -7,0 +6,0 @@ * @deprecated use `toString()` instead |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ByteString = void 0; | ||
var JsRuntime_1 = __importDefault(require("../../utils/JsRuntime/index.js")); | ||
var _1 = require("./index.js"); | ||
var uint8array_utils_1 = require("@harmoniclabs/uint8array-utils"); | ||
function isHex(anyString) { | ||
// always think in javasript | ||
if (typeof anyString !== "string") | ||
return false; | ||
var str = anyString.toLowerCase(); | ||
var validHex = "987654321abcdef0"; | ||
for (var i = 0; i < str.length; i++) { | ||
if (!validHex.includes(str[i])) | ||
return false; | ||
} | ||
// if false has not been returned yet, then it must be a valid hex | ||
return true; | ||
} | ||
function assert(condition, errorMessage, addInfos) { | ||
var args = []; | ||
for (var _i = 3; _i < arguments.length; _i++) { | ||
args[_i - 3] = arguments[_i]; | ||
} | ||
if (condition) | ||
return; | ||
args.length > 0 && console.error.apply(console, __spreadArray([], __read(args), false)); | ||
addInfos && console.error(addInfos); | ||
if (errorMessage instanceof Error) { | ||
throw errorMessage; | ||
} | ||
; | ||
throw new Error(errorMessage); | ||
} | ||
var ByteString = /** @class */ (function () { | ||
@@ -15,8 +63,9 @@ function ByteString(bs) { | ||
bs = bs.trim().split(" ").join(""); | ||
JsRuntime_1.default.assert(_1.HexString.isHex(bs), "invalid hex input while constructing a ByteString: " + bs); | ||
assert(isHex(bs), "invalid hex input while constructing a ByteString: " + bs); | ||
// even length | ||
this._bytes = (0, uint8array_utils_1.fromHex)((bs.length % 2) === 1 ? "0" + bs : bs); | ||
return; | ||
bs = (0, uint8array_utils_1.fromHex)((bs.length % 2) === 1 ? "0" + bs : bs); | ||
} | ||
JsRuntime_1.default.assert((0, uint8array_utils_1.isUint8Array)(bs), "invalid Uint8Array input while constructing a ByteString"); | ||
if (!(bs instanceof Uint8Array)) | ||
bs = bs.toBuffer(); | ||
assert((0, uint8array_utils_1.isUint8Array)(bs), "invalid Uint8Array input while constructing a ByteString"); | ||
this._bytes = bs; | ||
@@ -63,3 +112,3 @@ } | ||
ByteString.isValidHexValue = function (str) { | ||
return (_1.HexString.isHex(str) && | ||
return (isHex(str) && | ||
str.length % 2 === 0); | ||
@@ -66,0 +115,0 @@ }; |
{ | ||
"name": "@harmoniclabs/plu-ts", | ||
"version": "0.3.2-dev2", | ||
"version": "0.4.0-dev0", | ||
"description": "An embedded DSL for Cardano smart contracts creation coupled with a library for Cardano transactions, all in Typescript", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2123632
43838