Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@harmoniclabs/cardano-ledger-ts

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@harmoniclabs/cardano-ledger-ts - npm Package Compare versions

Comparing version 0.2.0-dev0 to 0.2.0-dev1

27

dist/ledger/Value/IValue.d.ts

@@ -1,2 +0,2 @@

import { Hash28 } from "../../hashes/Hash28/Hash28.js";
import { CanBeHash28, Hash28 } from "../../hashes/Hash28/Hash28.js";
import { CanBeUInteger } from "../../utils/ints.js";

@@ -10,6 +10,10 @@ export type AssetJson = {

export type IValue = (IValuePolicyEntry | IValueAdaEntry)[];
export type NormalizedIValue = (NormalizedIValuePolicyEntry | NormalizedIValueAdaEntry)[];
export declare function normalizeIValue(val: IValue): NormalizedIValue;
export type IValueAsset = {
name: Uint8Array;
/** bytes or **HEXADECIMAL** string */
name: Uint8Array | string;
quantity: CanBeUInteger;
};
export declare function normalizeIValueAsset(asset: IValueAsset): IValueAssetBI;
export type IValueAssetBI = {

@@ -19,7 +23,10 @@ name: Uint8Array;

};
export type IValueAssets = IValueAsset[];
export type IValuePolicyEntry = {
export interface IValuePolicyEntry {
policy: CanBeHash28;
assets: IValueAsset[];
}
export interface NormalizedIValuePolicyEntry {
policy: Hash28;
assets: IValueAssets;
};
assets: IValueAssetBI[];
}
export type IValueAdaEntry = {

@@ -29,2 +36,6 @@ policy: "";

};
export type NormalizedIValueAdaEntry = {
policy: "";
assets: [IValueAssetBI];
};
export declare function cloneIValue(ival: IValue): IValue;

@@ -34,5 +45,5 @@ export declare function IValueToJson(iVal: IValue): ValueJson;

export declare function isIValue(entries: any[]): entries is IValue;
export declare function getNameQty(assets: IValueAssets | undefined, searchName: Uint8Array): CanBeUInteger | undefined;
export declare function getEmptyNameQty(assets: IValueAssets | undefined): CanBeUInteger | undefined;
export declare function getNameQty(assets: IValueAsset[] | undefined, searchName: Uint8Array): CanBeUInteger | undefined;
export declare function getEmptyNameQty(assets: IValueAsset[] | undefined): CanBeUInteger | undefined;
export declare function addIValues(a: IValue, b: IValue): IValue;
export declare function subIValues(a: IValue, b: IValue): IValue;

@@ -14,6 +14,44 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.subIValues = exports.addIValues = exports.getEmptyNameQty = exports.getNameQty = exports.isIValue = exports.cloneIValueEntry = exports.IValueToJson = exports.cloneIValue = void 0;
exports.subIValues = exports.addIValues = exports.getEmptyNameQty = exports.getNameQty = exports.isIValue = exports.cloneIValueEntry = exports.IValueToJson = exports.cloneIValue = exports.normalizeIValueAsset = exports.normalizeIValue = void 0;
var uint8array_utils_1 = require("@harmoniclabs/uint8array-utils");
var Hash28_1 = require("../../hashes/Hash28/Hash28.js");
var obj_utils_1 = require("@harmoniclabs/obj-utils");
function normalizeIValue(val) {
return val.map(function (_c) {
var policy = _c.policy, assets = _c.assets;
if (policy === "")
return {
policy: "",
assets: [
{
name: new Uint8Array([]),
quantity: BigInt(assets[0].quantity)
}
]
};
policy = new Hash28_1.Hash28(policy);
// precompute bytes and string representation.
policy.toBuffer();
policy.toString();
return {
policy: policy,
assets: assets.map(function (_c) {
var name = _c.name, quantity = _c.quantity;
return {
name: typeof name === "string" ? (0, uint8array_utils_1.fromHex)(name) : name,
quantity: BigInt(quantity)
};
})
};
});
}
exports.normalizeIValue = normalizeIValue;
function normalizeIValueAsset(asset) {
return {
name: typeof asset.name === "string" ? (0, uint8array_utils_1.fromHex)(asset.name) : asset.name,
quantity: BigInt(asset.quantity)
};
}
exports.normalizeIValueAsset = normalizeIValueAsset;
;
function cloneIValue(ival) {

@@ -24,3 +62,4 @@ return ival.map(cloneIValueEntry);

function policyToString(policy) {
return policy === "" ? policy : policy.toString();
return typeof policy === "string" ? policy : (policy instanceof Uint8Array ? (0, uint8array_utils_1.toHex)(policy) :
policy.toString());
}

@@ -37,3 +76,3 @@ function IValueToJson(iVal) {

var _f = assets_1_1.value, name_1 = _f.name, quantity = _f.quantity;
(0, obj_utils_1.defineReadOnlyProperty)(_assets, (0, uint8array_utils_1.toHex)(name_1), quantity.toString());
(0, obj_utils_1.defineReadOnlyProperty)(_assets, typeof name_1 === "string" ? name_1 : (0, uint8array_utils_1.toHex)(name_1), quantity.toString());
}

@@ -156,3 +195,3 @@ }

var name = _c.name;
return (0, uint8array_utils_1.uint8ArrayEq)(name, searchName);
return (0, uint8array_utils_1.uint8ArrayEq)(typeof name === "string" ? (0, uint8array_utils_1.fromHex)(name) : name, searchName);
})) === null || _c === void 0 ? void 0 : _c.quantity;

@@ -335,3 +374,3 @@ }

result.push({
policy: policy,
policy: new Hash28_1.Hash28(policy),
assets: subtractedAssets

@@ -343,3 +382,3 @@ });

result.push({
policy: policy,
policy: new Hash28_1.Hash28(policy),
assets: aAssets

@@ -416,3 +455,3 @@ });

name: name_5.slice(),
quantity: amt
quantity: BigInt(amt)
});

@@ -419,0 +458,0 @@ }

@@ -5,3 +5,3 @@ import { ToCbor, CborString, CborObj, CanBeCborString } from "@harmoniclabs/cbor";

import { CanBeUInteger } from "../../utils/ints.js";
import { IValue, IValueAssets, IValueAdaEntry, IValueAsset, IValuePolicyEntry, ValueJson } from "./IValue.js";
import { IValue, IValueAsset, ValueJson, NormalizedIValuePolicyEntry, IValueAssetBI, NormalizedIValueAdaEntry, NormalizedIValue } from "./IValue.js";
export type ValueUnitEntry = {

@@ -18,6 +18,6 @@ unit: string;

export declare class Value implements ToCbor, ToData {
readonly map: IValue;
readonly map: NormalizedIValue;
[Symbol.iterator](): Generator<{
policy: string;
assets: IValueAssets;
assets: IValueAssetBI[];
}, void, unknown>;

@@ -33,8 +33,8 @@ constructor(map: IValue);

static isAdaOnly(v: Value): boolean;
static lovelaceEntry(n: CanBeUInteger): IValueAdaEntry;
static lovelaceEntry(n: CanBeUInteger): NormalizedIValueAdaEntry;
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 assetEntry(name: Uint8Array, qty: number | bigint): IValueAssetBI;
static singleAssetEntry(policy: Hash28, name: Uint8Array, qty: number | bigint): NormalizedIValuePolicyEntry;
static singleAsset(policy: Hash28, name: Uint8Array, qty: number | bigint): Value;
static entry(policy: Hash28, assets: IValueAssets): IValuePolicyEntry;
static entry(policy: Hash28, assets: IValueAsset[]): NormalizedIValuePolicyEntry;
static add(a: Value, b: Value): Value;

@@ -41,0 +41,0 @@ static sub(a: Value, b: Value): Value;

@@ -51,2 +51,3 @@ "use strict";

var obj_utils_1 = require("@harmoniclabs/obj-utils");
var _0n = BigInt(0);
var Value = /** @class */ (function () {

@@ -56,3 +57,4 @@ function Value(map) {

(0, assert_1.assert)((0, IValue_1.isIValue)(map), "invalid value interface passed to contruct a 'value' instance");
map.forEach(function (entry) {
var _map = (0, IValue_1.normalizeIValue)(map);
_map.forEach(function (entry, i) {
var assets = entry.assets;

@@ -63,4 +65,4 @@ assets.forEach(function (a) { return Object.freeze(a); });

// value MUST have an ada entry
if (!map.some(function (entry) { return entry.policy === ""; })) {
map.unshift({
if (!_map.some(function (entry) { return entry.policy === ""; })) {
_map.unshift({
policy: "",

@@ -70,3 +72,3 @@ assets: [

name: new Uint8Array([]),
quantity: 0
quantity: _0n
}

@@ -76,3 +78,3 @@ ]

}
map.sort(function (a, b) {
_map.sort(function (a, b) {
if (a.policy === "") {

@@ -89,3 +91,3 @@ if (b.policy === "")

});
(0, obj_utils_1.defineReadOnlyProperty)(this, "map", Object.freeze(map));
(0, obj_utils_1.defineReadOnlyProperty)(this, "map", Object.freeze(_map));
Object.defineProperty(this, "lovelaces", {

@@ -226,3 +228,3 @@ get: function () {

name: new Uint8Array([]),
quantity: typeof n === "number" ? Math.round(n) : BigInt(n)
quantity: typeof n === "number" ? BigInt(Math.round(n)) : BigInt(n)
}

@@ -241,3 +243,3 @@ ]

name: name.slice(),
quantity: typeof qty === "number" ? Math.round(qty) : BigInt(qty)
quantity: typeof qty === "number" ? BigInt(Math.round(qty)) : BigInt(qty)
};

@@ -257,3 +259,3 @@ };

Value.entry = function (policy, assets) {
return { policy: policy, assets: assets };
return { policy: policy, assets: assets.map(IValue_1.normalizeIValueAsset) };
};

@@ -359,3 +361,3 @@ Value.add = function (a, b) {

throw new Error("Invalid CBOR format for \"Value\"");
var policy = k.buffer.length === 0 ? "" : new hashes_1.Hash28(k.buffer);
var policy = k.bytes.length === 0 ? "" : new hashes_1.Hash28(k.bytes);
if (!(v instanceof cbor_1.CborMap))

@@ -373,3 +375,3 @@ throw new Error("Invalid CBOR format for \"Value\"");

assets.push({
name: k_1.buffer,
name: k_1.bytes,
quantity: v_1.num

@@ -376,0 +378,0 @@ });

{
"name": "@harmoniclabs/cardano-ledger-ts",
"version": "0.2.0-dev0",
"version": "0.2.0-dev1",
"description": "",

@@ -5,0 +5,0 @@ "main": "./dist/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc