MultiAsset.ts
MultiAsset overview
Table of contents
arbitrary
arbitrary
Change generator to arbitrary and rename CBOR schemas.
Signature
export declare const arbitrary: FastCheck.Arbitrary<MultiAsset>Added in v2.0.0
constructors
empty
Create an empty MultiAsset
Signature
export declare const empty: () => MultiAssetAdded in v2.0.0
singleton
Create a MultiAsset from a single asset.
Signature
export declare const singleton: (
policyId: PolicyId.PolicyId,
assetName: AssetName.AssetName,
amount: bigint
) => MultiAssetAdded in v2.0.0
encoding
toCBORBytes
Encode MultiAsset to CBOR bytes.
Signature
export declare const toCBORBytes: (data: MultiAsset, options?: CBOR.CodecOptions) => anyAdded in v2.0.0
toCBORHex
Encode MultiAsset to CBOR hex string.
Signature
export declare const toCBORHex: (data: MultiAsset, options?: CBOR.CodecOptions) => stringAdded in v2.0.0
model
AssetMap (type alias)
Type alias for the inner asset map.
Signature
export type AssetMap = typeof AssetMap.TypeAdded in v2.0.0
MultiAsset (class)
Schema for MultiAsset representing native assets.
This is a base type with no constraints on size or values. It supports arithmetic operations (merge, subtract, negate) which may produce empty maps or negative quantities during intermediate calculations.
Constraints (non-empty, positive values) are applied at boundaries
like TransactionOutput where CDDL requires multiasset<positive_coin>.
multiasset<a0> = {* policy_id => {* asset_name => a0}}Signature
export declare class MultiAssetAdded in v2.0.0
toJSON (method)
Convert to JSON representation.
Signature
toJSON()Added in v2.0.0
toString (method)
Convert to string representation.
Signature
toString(): stringAdded in v2.0.0
[Inspectable.NodeInspectSymbol] (method)
Custom inspect for Node.js REPL.
Signature
[Inspectable.NodeInspectSymbol](): unknownAdded in v2.0.0
[Equal.symbol] (method)
Structural equality check.
Signature
[Equal.symbol](that: unknown): booleanAdded in v2.0.0
[Hash.symbol] (method)
Signature
[Hash.symbol](): numberAdded in v2.0.0
parsing
fromCBORBytes
Parse MultiAsset from CBOR bytes.
Signature
export declare const fromCBORBytes: (bytes: Uint8Array, options?: CBOR.CodecOptions) => MultiAssetAdded in v2.0.0
fromCBORHex
Parse MultiAsset from CBOR hex string.
Signature
export declare const fromCBORHex: (hex: string, options?: CBOR.CodecOptions) => MultiAssetAdded in v2.0.0
predicates
hasAsset
Check if a MultiAsset contains a specific asset.
Signature
export declare const hasAsset: (
multiAsset: MultiAsset,
policyId: PolicyId.PolicyId,
assetName: AssetName.AssetName
) => booleanAdded in v2.0.0
is
Check if a value is a valid MultiAsset.
Signature
export declare const is: (value: unknown) => value is MultiAssetAdded in v2.0.0
schemas
AssetMap
Schema for inner asset map (asset_name => bigint).
This is a base type with no constraints. Values can be positive, negative, or zero to support arithmetic operations.
Constraints (positive values) are applied at boundaries like
TransactionOutput where CDDL requires positive_coin.
Signature
export declare const AssetMap: Schema.transform<
Schema.Array$<Schema.Tuple2<typeof AssetName.AssetName, typeof Schema.BigInt>>,
Schema.MapFromSelf<
Schema.SchemaClass<AssetName.AssetName, AssetName.AssetName, never>,
Schema.SchemaClass<bigint, bigint, never>
>
>Added in v2.0.0
FromCBORBytes
CBOR bytes transformation schema for MultiAsset. Transforms between CBOR bytes and MultiAsset using CBOR encoding.
Signature
export declare const FromCBORBytes: (
options?: CBOR.CodecOptions
) => Schema.transform<
Schema.transformOrFail<
typeof Schema.Uint8ArrayFromSelf,
Schema.declare<CBOR.CBOR, CBOR.CBOR, readonly [], never>,
never
>,
Schema.transformOrFail<
Schema.MapFromSelf<
typeof Schema.Uint8ArrayFromSelf,
Schema.MapFromSelf<typeof Schema.Uint8ArrayFromSelf, typeof Schema.BigIntFromSelf>
>,
Schema.SchemaClass<MultiAsset, MultiAsset, never>,
never
>
>Added in v2.0.0
FromCBORHex
CBOR hex transformation schema for MultiAsset. Transforms between CBOR hex string and MultiAsset using CBOR encoding.
Signature
export declare const FromCBORHex: (
options?: CBOR.CodecOptions
) => Schema.transform<
Schema.Schema<Uint8Array, string, never>,
Schema.transform<
Schema.transformOrFail<
typeof Schema.Uint8ArrayFromSelf,
Schema.declare<CBOR.CBOR, CBOR.CBOR, readonly [], never>,
never
>,
Schema.transformOrFail<
Schema.MapFromSelf<
typeof Schema.Uint8ArrayFromSelf,
Schema.MapFromSelf<typeof Schema.Uint8ArrayFromSelf, typeof Schema.BigIntFromSelf>
>,
Schema.SchemaClass<MultiAsset, MultiAsset, never>,
never
>
>
>Added in v2.0.0
FromCDDL
CDDL schema for MultiAsset.
multiasset<positive_coin> = {+ policy_id => {+ asset_name => positive_coin}}Signature
export declare const FromCDDL: Schema.transformOrFail<
Schema.MapFromSelf<
typeof Schema.Uint8ArrayFromSelf,
Schema.MapFromSelf<typeof Schema.Uint8ArrayFromSelf, typeof Schema.BigIntFromSelf>
>,
Schema.SchemaClass<MultiAsset, MultiAsset, never>,
never
>Added in v2.0.0
transformation
addAsset
Add an asset to a MultiAsset, combining amounts if the asset already exists.
Signature
export declare const addAsset: (
multiAsset: MultiAsset,
policyId: PolicyId.PolicyId,
assetName: AssetName.AssetName,
amount: bigint
) => MultiAssetAdded in v2.0.0
getAsset
Get the amount of a specific asset from a MultiAsset.
Signature
export declare const getAsset: (
multiAsset: MultiAsset,
policyId: PolicyId.PolicyId,
assetName: AssetName.AssetName
) => bigint | undefinedAdded in v2.0.0
getAssetsByPolicy
Get all assets for a specific policy ID.
Signature
export declare const getAssetsByPolicy: (
multiAsset: MultiAsset,
policyId: PolicyId.PolicyId
) => [AssetName.AssetName, bigint][]Added in v2.0.0
getPolicyIds
Get all policy IDs in a MultiAsset.
Signature
export declare const getPolicyIds: (multiAsset: MultiAsset) => Array<PolicyId.PolicyId>Added in v2.0.0
merge
Merge two MultiAsset instances, combining amounts for assets that exist in both.
Signature
export declare const merge: (a: MultiAsset, b: MultiAsset) => MultiAssetAdded in v2.0.0
subtract
Subtract MultiAsset b from MultiAsset a. Returns a new MultiAsset with amounts reduced by the amounts in b. If any asset would result in zero or negative amount, it's removed from the result. If the result would be empty, an error is thrown since MultiAsset cannot be empty.
Signature
export declare const subtract: (a: MultiAsset, b: MultiAsset) => MultiAssetAdded in v2.0.0
utils
equals
Signature
export declare const equals: (a: MultiAsset, b: MultiAsset) => boolean