@helios-lang/ledger
Advanced tools
Comparing version 0.1.16 to 0.1.17
{ | ||
"name": "@helios-lang/ledger", | ||
"version": "0.1.16", | ||
"version": "0.1.17", | ||
"description": "Ledger types (eg. for building transactions)", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -0,1 +1,3 @@ | ||
import { None } from "@helios-lang/type-utils" | ||
export { DatumHash } from "./DatumHash.js" | ||
@@ -15,2 +17,3 @@ export { MintingPolicyHash } from "./MintingPolicyHash.js" | ||
* @typedef {import("./ScriptHash.js").ScriptHashLike} ScriptHashLike | ||
* @typedef {import("./StakingHash.js").StakingHashKind} StakingHashKind | ||
* @typedef {import("./StakingHash.js").StakingHashLike} StakingHashLike | ||
@@ -17,0 +20,0 @@ * @typedef {import("./StakingValidatorHash.js").StakingValidatorHashLike} StakingValidatorHashLike |
@@ -11,3 +11,3 @@ import { decodeBytes } from "@helios-lang/cbor" | ||
import { compareBytes, equalsBytes } from "@helios-lang/codec-utils" | ||
import { None } from "@helios-lang/type-utils" | ||
import { None, isSome } from "@helios-lang/type-utils" | ||
@@ -18,11 +18,6 @@ /** | ||
* @typedef {import("./Hash.js").Hash} Hash | ||
* @typedef {import("./MintingContext.js").MintingContext} MintingContext | ||
*/ | ||
/** | ||
* @template TStrict | ||
* @template TPermissive | ||
* @typedef {import("./Cast.js").Cast<TStrict, TPermissive>} Cast | ||
*/ | ||
/** | ||
* @typedef {MintingPolicyHash | ByteArrayLike} MintingPolicyHashLike | ||
@@ -32,14 +27,11 @@ */ | ||
/** | ||
* @template [TRedeemer=UplcData] | ||
* @typedef {{ | ||
* program: UplcProgramV1 | UplcProgramV2, | ||
* redeemer: Cast<UplcData, TRedeemer> | ||
* }} MintingPolicyHashContext | ||
*/ | ||
/** | ||
* Represents a blake2b-224 hash of a minting policy script | ||
* | ||
* **Note**: to calculate this hash the script is first encoded as a CBOR byte-array and then prepended by a script version byte. | ||
* @template [TRedeemer=UplcData] | ||
* | ||
* `C` is some optional context: | ||
* null: unwitnessed or witnessed by NativeScript | ||
* unknown: witnessed or unwitnessed (default) | ||
* {program: ..., redeemer: ...}: witnessed by UplcProgram | ||
* @template [C=unknown] | ||
* @implements {Hash} | ||
@@ -50,3 +42,3 @@ */ | ||
* @readonly | ||
* @type {Option<MintingPolicyHashContext<TRedeemer>>} | ||
* @type {C} | ||
*/ | ||
@@ -57,4 +49,4 @@ context | ||
* Can be 0 bytes in case of Ada | ||
* @param {Exclude<MintingPolicyHashLike, MintingPolicyHash>} bytes | ||
* @param {Option<MintingPolicyHashContext<TRedeemer>>} context | ||
* @param {ByteArrayLike} bytes | ||
* @param {Option<C>} context - not recommended to set this manually | ||
*/ | ||
@@ -70,13 +62,16 @@ constructor(bytes, context = None) { | ||
this.context = context | ||
if (isSome(context)) { | ||
this.context = context | ||
} | ||
} | ||
/** | ||
* @param {MintingPolicyHashLike} arg | ||
* @returns {MintingPolicyHash} | ||
* @template {MintingPolicyHashLike} T | ||
* @param {T} arg | ||
* @returns {T extends MintingPolicyHash<infer C> ? MintingPolicyHash<C> : MintingPolicyHash} | ||
*/ | ||
static fromAlike(arg) { | ||
return arg instanceof MintingPolicyHash | ||
? arg | ||
: new MintingPolicyHash(arg) | ||
return /** @type {any} */ ( | ||
arg instanceof MintingPolicyHash ? arg : new MintingPolicyHash(arg) | ||
) | ||
} | ||
@@ -83,0 +78,0 @@ |
import { decodeTagged, encodeInt, encodeTuple } from "@helios-lang/cbor" | ||
import { ByteStream } from "@helios-lang/codec-utils" | ||
import { None } from "@helios-lang/type-utils" | ||
import { None, isSome } from "@helios-lang/type-utils" | ||
import { ConstrData } from "@helios-lang/uplc" | ||
@@ -36,2 +36,3 @@ import { PubKeyHash } from "./PubKeyHash.js" | ||
* @template {StakingHashKind} [T=StakingHashKind] | ||
* @template [C=unknown] | ||
*/ | ||
@@ -54,9 +55,20 @@ export class StakingHash { | ||
/** | ||
* @readonly | ||
* @type {C} | ||
*/ | ||
context | ||
/** | ||
* @private | ||
* @param {T} kind | ||
* @param {StakingHashProps<T>} props | ||
* @param {Option<C>} context | ||
*/ | ||
constructor(kind, props) { | ||
constructor(kind, props, context = None) { | ||
this.kind = kind | ||
this.props = props | ||
if (isSome(context)) { | ||
this.context = context | ||
} | ||
} | ||
@@ -66,3 +78,3 @@ | ||
* @param {PubKeyHashLike} hash | ||
* @returns {StakingHash<"PubKey">} | ||
* @returns {StakingHash<"PubKey", null>} | ||
*/ | ||
@@ -74,23 +86,36 @@ static PubKey(hash) { | ||
/** | ||
* @param {StakingValidatorHashLike} hash | ||
* @returns {StakingHash<"Validator">} | ||
* @template {StakingValidatorHashLike} T | ||
* @param {T} hash | ||
* @returns {T extends StakingValidatorHash<infer C> ? StakingHash<"Validator", C> : StakingHash<"Validator">} | ||
*/ | ||
static Validator(hash) { | ||
return new StakingHash("Validator", { | ||
hash: StakingValidatorHash.fromAlike(hash) | ||
}) | ||
return /** @type {any} */ ( | ||
new StakingHash( | ||
"Validator", | ||
{ | ||
hash: StakingValidatorHash.fromAlike(hash) | ||
}, | ||
hash instanceof StakingValidatorHash ? hash.context : None | ||
) | ||
) | ||
} | ||
/** | ||
* @param {StakingHashLike} arg | ||
* @returns {StakingHash} | ||
* @template {StakingHashLike} T | ||
* @param {T} arg | ||
* @returns {( | ||
* T extends PubKeyHash ? StakingHash<"PubKey", null> : | ||
* T extends StakingValidatorHash<infer C> ? StakingHash<"Validator", C> : | ||
* T extends StakingHash<infer K, infer C> ? StakingHash<K, C> : | ||
* StakingHash | ||
* )} | ||
*/ | ||
static fromAlike(arg) { | ||
if (arg instanceof StakingHash) { | ||
return arg | ||
} else if (arg instanceof PubKeyHash) { | ||
return StakingHash.PubKey(arg) | ||
} else { | ||
return StakingHash.Validator(arg) | ||
} | ||
return /** @type {any} */ ( | ||
arg instanceof PubKeyHash | ||
? StakingHash.PubKey(arg) | ||
: arg instanceof StakingValidatorHash | ||
? StakingHash.Validator(arg) | ||
: arg | ||
) | ||
} | ||
@@ -120,4 +145,4 @@ | ||
/** | ||
* | ||
* @param {UplcData} data | ||
* @returns {StakingHash} | ||
*/ | ||
@@ -151,3 +176,3 @@ static fromUplcData(data) { | ||
/** | ||
* @type {T extends "PubKey" ? PubKeyHash : T extends "Validator" ? StakingValidatorHash : (PubKeyHash | StakingValidatorHash)} | ||
* @type {T extends "PubKey" ? PubKeyHash : T extends "Validator" ? StakingValidatorHash<C> : (PubKeyHash | StakingValidatorHash<C>)} | ||
*/ | ||
@@ -166,3 +191,3 @@ get hash() { | ||
/** | ||
* @type {T extends "Validator" ? StakingValidatorHash : T extends "PubKey" ? typeof None : Option<StakingValidatorHash>} | ||
* @type {T extends "Validator" ? StakingValidatorHash<C> : T extends "PubKey" ? typeof None : Option<StakingValidatorHash<C>>} | ||
*/ | ||
@@ -174,3 +199,3 @@ get stakingValidatorHash() { | ||
/** | ||
* @returns {this is StakingHash<"PubKey">} | ||
* @returns {this is StakingHash<"PubKey", null>} | ||
*/ | ||
@@ -182,3 +207,3 @@ isPubKey() { | ||
/** | ||
* @returns {this is StakingHash<"Validator">} | ||
* @returns {this is StakingHash<"Validator", C>} | ||
*/ | ||
@@ -185,0 +210,0 @@ isValidator() { |
import { decodeBytes } from "@helios-lang/cbor" | ||
import { compareBytes, equalsBytes } from "@helios-lang/codec-utils" | ||
import { None, isSome } from "@helios-lang/type-utils" | ||
import { ByteArrayData, decodeUplcData } from "@helios-lang/uplc" | ||
import { ScriptHash } from "./ScriptHash.js" | ||
import { compareBytes, equalsBytes } from "@helios-lang/codec-utils" | ||
@@ -13,3 +14,4 @@ /** | ||
/** | ||
* @typedef {StakingValidatorHash | ByteArrayLike} StakingValidatorHashLike | ||
* @template [C=unknown] | ||
* @typedef {StakingValidatorHash<C> | ByteArrayLike} StakingValidatorHashLike | ||
*/ | ||
@@ -21,2 +23,3 @@ | ||
* **Note**: before hashing, the staking script is first encoded as a CBOR byte-array and then prepended by a script version byte. | ||
* @template [C=unknown] | ||
* @implements {Hash} | ||
@@ -26,5 +29,12 @@ */ | ||
/** | ||
* @param {Exclude<StakingValidatorHashLike, StakingValidatorHash>} bytes | ||
* @readonly | ||
* @type {C} | ||
*/ | ||
constructor(bytes) { | ||
context | ||
/** | ||
* @param {ByteArrayLike} bytes | ||
* @param {Option<C>} context | ||
*/ | ||
constructor(bytes, context = None) { | ||
super(bytes) | ||
@@ -37,12 +47,26 @@ | ||
} | ||
if (isSome(context)) { | ||
this.context = context | ||
} | ||
} | ||
/** | ||
* @param {StakingValidatorHashLike} arg | ||
* @returns {StakingValidatorHash} | ||
* @returns {StakingValidatorHash<unknown>} | ||
*/ | ||
static dummy() { | ||
return new StakingValidatorHash(new Array(28).fill(0)) | ||
} | ||
/** | ||
* @template {StakingValidatorHashLike} T | ||
* @param {T} arg | ||
* @returns {T extends StakingValidatorHash<infer C> ? StakingValidatorHash<C> : StakingValidatorHash} | ||
*/ | ||
static fromAlike(arg) { | ||
return arg instanceof StakingValidatorHash | ||
? arg | ||
: new StakingValidatorHash(arg) | ||
return /** @type {any} */ ( | ||
arg instanceof StakingValidatorHash | ||
? arg | ||
: new StakingValidatorHash(arg) | ||
) | ||
} | ||
@@ -49,0 +73,0 @@ |
import { decodeBytes } from "@helios-lang/cbor" | ||
import { | ||
ByteArrayData, | ||
UplcProgramV1, | ||
UplcProgramV2, | ||
decodeUplcData | ||
} from "@helios-lang/uplc" | ||
import { ByteArrayData, decodeUplcData } from "@helios-lang/uplc" | ||
import { ScriptHash } from "./ScriptHash.js" | ||
import { compareBytes, equalsBytes } from "@helios-lang/codec-utils" | ||
import { None } from "@helios-lang/type-utils" | ||
import { None, isSome } from "@helios-lang/type-utils" | ||
@@ -15,3 +10,2 @@ /** | ||
* @typedef {import("@helios-lang/uplc").UplcData} UplcData | ||
* @typedef {import("./Hash.js").Hash} Hash | ||
@@ -21,8 +15,2 @@ */ | ||
/** | ||
* @template TStrict | ||
* @template TPermissive | ||
* @typedef {import("./Cast.js").Cast<TStrict, TPermissive>} Cast | ||
*/ | ||
/** | ||
* @typedef {ValidatorHash | ByteArrayLike} ValidatorHashLike | ||
@@ -32,17 +20,4 @@ */ | ||
/** | ||
* @template TDatumStrict | ||
* @template TDatumPermissive | ||
* @template TRedeemer | ||
* @typedef {{ | ||
* program: UplcProgramV1 | UplcProgramV2 | ||
* datum: Cast<TDatumStrict, TDatumPermissive> | ||
* redeemer: Cast<any, TRedeemer> | ||
* }} ValidatorHashContext | ||
*/ | ||
/** | ||
* Represents a blake2b-224 hash of a spending validator script (first encoded as a CBOR byte-array and prepended by a script version byte). | ||
* @template [TDatumStrict=UplcData] | ||
* @template [TDatumPermissive=UplcData] | ||
* @template [TRedeemer=UplcData] | ||
* @template [C=unknown] | ||
* @implements {Hash} | ||
@@ -52,5 +27,11 @@ */ | ||
/** | ||
* @param {Exclude<ValidatorHashLike, ValidatorHash>} bytes | ||
* @param {Option<ValidatorHashContext<TDatumStrict, TDatumPermissive, TRedeemer>>} context | ||
* @readonly | ||
* @type {C} | ||
*/ | ||
context | ||
/** | ||
* @param {ByteArrayLike} bytes | ||
* @param {Option<C>} context | ||
*/ | ||
constructor(bytes, context = None) { | ||
@@ -65,11 +46,23 @@ super(bytes) | ||
this.context = context | ||
if (isSome(context)) { | ||
this.context = context | ||
} | ||
} | ||
/** | ||
* @param {ValidatorHashLike} arg | ||
* @returns {ValidatorHash} | ||
* @returns {ValidatorHash<unknown>} | ||
*/ | ||
static dummy() { | ||
return new ValidatorHash(new Array(28).fill(0)) | ||
} | ||
/** | ||
* @template {ValidatorHashLike} T | ||
* @param {T} arg | ||
* @returns {arg extends ValidatorHash<infer C> ? ValidatorHash<C> : ValidatorHash} | ||
*/ | ||
static fromAlike(arg) { | ||
return arg instanceof ValidatorHash ? arg : new ValidatorHash(arg) | ||
return /** @type {any} */ ( | ||
arg instanceof ValidatorHash ? arg : new ValidatorHash(arg) | ||
) | ||
} | ||
@@ -76,0 +69,0 @@ |
@@ -1,4 +0,1 @@ | ||
import { ByteStream, bytesToHex, toBytes } from "@helios-lang/codec-utils" | ||
import { ByteArrayData, ConstrData, decodeUplcData } from "@helios-lang/uplc" | ||
import { blake2b, encodeBech32 } from "@helios-lang/crypto" | ||
import { | ||
@@ -10,2 +7,6 @@ decodeBytes, | ||
} from "@helios-lang/cbor" | ||
import { ByteStream, bytesToHex, toBytes } from "@helios-lang/codec-utils" | ||
import { blake2b, encodeBech32 } from "@helios-lang/crypto" | ||
import { None } from "@helios-lang/type-utils" | ||
import { ByteArrayData, ConstrData, decodeUplcData } from "@helios-lang/uplc" | ||
import { MintingPolicyHash } from "../hashes/index.js" | ||
@@ -18,2 +19,3 @@ | ||
*/ | ||
/** | ||
@@ -31,6 +33,7 @@ * @typedef {string | [ | ||
* Represents a `MintingPolicyHash` combined with a token name. | ||
* @template [C=unknown] | ||
*/ | ||
export class AssetClass { | ||
/** | ||
* @type {MintingPolicyHash} | ||
* @type {MintingPolicyHash<C>} | ||
*/ | ||
@@ -45,11 +48,18 @@ mph | ||
/** | ||
* Intelligently converts arguments. | ||
* | ||
* The format for single argument string is "<hex-encoded-mph>.<hex-encoded-token-name>". | ||
* @param {MintingPolicyHashLike} mph | ||
* @readonly | ||
* @type {C} | ||
*/ | ||
context | ||
/** | ||
* @param {MintingPolicyHash<C>} mph - policy with optional context | ||
* @param {ByteArrayLike} tokenName | ||
*/ | ||
constructor(mph, tokenName) { | ||
this.mph = MintingPolicyHash.fromAlike(mph) | ||
this.mph = mph | ||
this.tokenName = toBytes(tokenName) | ||
if (mph.context) { | ||
this.context = mph.context | ||
} | ||
} | ||
@@ -61,19 +71,26 @@ | ||
static get ADA() { | ||
return new AssetClass("", "") | ||
return AssetClass.fromAlike(".") | ||
} | ||
/** | ||
* @param {AssetClassLike} arg | ||
* @returns {AssetClass} | ||
* @template {AssetClassLike} T | ||
* @param {T} arg | ||
* @returns {T extends [MintingPolicyHash<infer C>, ByteArrayLike] ? AssetClass<C> : T extends AssetClass<infer C> ? AssetClass<C> : AssetClass} | ||
*/ | ||
static fromAlike(arg) { | ||
if (arg instanceof AssetClass) { | ||
return arg | ||
} else if (typeof arg == "string") { | ||
return AssetClass.fromString(arg) | ||
} else if (Array.isArray(arg)) { | ||
return new AssetClass(arg[0], arg[1]) | ||
} else { | ||
return new AssetClass(arg.mph, arg.tokenName) | ||
} | ||
return /** @type {any} */ ( | ||
arg instanceof AssetClass | ||
? arg | ||
: typeof arg == "string" | ||
? AssetClass.fromString(arg) | ||
: Array.isArray(arg) | ||
? new AssetClass( | ||
MintingPolicyHash.fromAlike(arg[0]), | ||
arg[1] | ||
) | ||
: new AssetClass( | ||
MintingPolicyHash.fromAlike(arg.mph), | ||
arg.tokenName | ||
) | ||
) | ||
} | ||
@@ -116,3 +133,3 @@ | ||
return new AssetClass(parts[0], parts[1]) | ||
return new AssetClass(MintingPolicyHash.fromAlike(parts[0]), parts[1]) | ||
} | ||
@@ -119,0 +136,0 @@ |
import { decodeBytes, encodeBytes } from "@helios-lang/cbor" | ||
import { bytesToHex, toBytes } from "@helios-lang/codec-utils" | ||
import { decodeBech32, encodeBech32 } from "@helios-lang/crypto" | ||
import { isSome, None } from "@helios-lang/type-utils" | ||
import { expectSome, isSome, None } from "@helios-lang/type-utils" | ||
import { | ||
@@ -20,3 +20,3 @@ ByteArrayData, | ||
import { config } from "./config.js" | ||
import { PaymentCredential } from "./PaymentCredential.js" | ||
import { SpendingCredential } from "./SpendingCredential.js" | ||
import { StakingCredential } from "./StakingCredential.js" | ||
@@ -27,11 +27,7 @@ | ||
* @typedef {import("@helios-lang/uplc").UplcData} UplcData | ||
* @typedef {import("../hashes/index.js").StakingHashKind} StakingHashKind | ||
* @typedef {import("./SpendingCredential.js").SpendingCredentialKind} SpendingCredentialKind | ||
*/ | ||
/** | ||
* @template TStrict | ||
* @template TPermissive | ||
* @typedef {import("../hashes/Cast.js").Cast<TStrict, TPermissive>} Cast | ||
*/ | ||
/** | ||
* @typedef {Address | ByteArrayLike} AddressLike | ||
@@ -41,13 +37,2 @@ */ | ||
/** | ||
* @template TDatumStrict | ||
* @template TDatumPermissive | ||
* @template TPaymentRedeemer | ||
* @typedef {{ | ||
* paymentProgram: UplcProgramV1 | UplcProgramV2 | ||
* datum: Cast<TDatumStrict, TDatumPermissive> | ||
* paymentRedeemer: Cast<any, TPaymentRedeemer> | ||
* }} AddressContext | ||
*/ | ||
/** | ||
* Wrapper for Cardano address bytes. An `Address` consists of three parts internally: | ||
@@ -57,5 +42,4 @@ * * Header (1 byte, see [CIP 19](https://cips.cardano.org/cips/cip19/)) | ||
* * Optional staking credential (0 or 28 bytes) | ||
* @template [TDatumStrict=UplcData] | ||
* @template [TDatumPermissive=UplcData] | ||
* @template [TPaymentRedeemer=UplcData] | ||
* @template [CSpending=unknown] - spending can have a context | ||
* @template [CStaking=unknown] - staking can have a separate context | ||
*/ | ||
@@ -71,23 +55,18 @@ export class Address { | ||
* @readonly | ||
* @type {PaymentCredential} | ||
* @type {CSpending} | ||
*/ | ||
paymentCredential | ||
spendingContext | ||
/** | ||
* @readonly | ||
* @type {Option<StakingCredential>} | ||
* @type {CStaking} | ||
*/ | ||
stakingCredential | ||
stakingContext | ||
/** | ||
* @readonly | ||
* @type {Option<AddressContext<TDatumStrict, TDatumPermissive, TPaymentRedeemer>>} | ||
* @param {ByteArrayLike} bytes | ||
* @param {Option<CSpending>} spendingContext | ||
* @param {Option<CStaking>} stakingContext | ||
*/ | ||
context | ||
/** | ||
* @param {Exclude<AddressLike, Address>} bytes | ||
* @param {Option<AddressContext<TDatumStrict, TDatumPermissive, TPaymentRedeemer>>} context | ||
*/ | ||
constructor(bytes, context = None) { | ||
constructor(bytes, spendingContext = None, stakingContext = None) { | ||
this.bytes = toBytes(bytes) | ||
@@ -101,6 +80,9 @@ | ||
this.paymentCredential = PaymentCredential.fromAddressBytes(this.bytes) | ||
this.stakingCredential = StakingCredential.fromAddressBytes(this.bytes) | ||
if (spendingContext) { | ||
this.spendingContext = spendingContext | ||
} | ||
this.context = context | ||
if (stakingContext) { | ||
this.stakingContext = stakingContext | ||
} | ||
} | ||
@@ -157,3 +139,3 @@ | ||
/** | ||
* @param {PaymentCredential} paymentCredential | ||
* @param {SpendingCredential} paymentCredential | ||
* @param {Option<StakingCredential>} stakingCredential | ||
@@ -179,8 +161,10 @@ * @param {boolean} isTestnet | ||
* without a staking hash. | ||
* @template [TDatumStrict=UplcData] | ||
* @template [TDatumPermissive=UplcData] | ||
* @template [TPaymentRedeemer=UplcData] | ||
* @param {PubKeyHash | ValidatorHash<TDatumStrict, TDatumPermissive, TPaymentRedeemer>} hash | ||
* @template {PubKeyHash | ValidatorHash} [TSpending=PubKeyHash | ValidatorHash] | ||
* @param {TSpending} hash | ||
* @param {boolean} isTestnet | ||
* @returns {Address<TDatumStrict, TDatumPermissive, TPaymentRedeemer>} | ||
* @returns {( | ||
* TSpending extends PubKeyHash ? Address<null, null> : | ||
* TSpending extends ValidatorHash<infer CSpending> ? Address<CSpending, null> : | ||
* Address<unknown, null> | ||
* )} | ||
*/ | ||
@@ -195,23 +179,34 @@ static fromHash(hash, isTestnet = config.IS_TESTNET) { | ||
* in combination with an optional staking hash (`PubKeyHash` or `StakingValidatorHash`). | ||
* @template [TDatumStrict=UplcData] | ||
* @template [TDatumPermissive=UplcData] | ||
* @template [TPaymentRedeemer=UplcData] | ||
* @param {PubKeyHash | ValidatorHash<TDatumStrict, TDatumPermissive, TPaymentRedeemer>} paymentHash | ||
* @param {Option<PubKeyHash | StakingValidatorHash>} stakingHash | ||
* @template {PubKeyHash | ValidatorHash} [TSpending=PubKeyHash | ValidatorHash] | ||
* @template {PubKeyHash | StakingValidatorHash} [TStaking=PubKeyHash | StakingValidatorHash] | ||
* @param {TSpending} spendingHash | ||
* @param {Option<TStaking>} stakingHash | ||
* @param {boolean} isTestnet | ||
* @returns {Address<TDatumStrict, TDatumPermissive, TPaymentRedeemer>} | ||
* @returns {( | ||
* TSpending extends PubKeyHash ? ( | ||
* TStaking extends PubKeyHash ? Address<null, null> : | ||
* TStaking extends StakingValidatorHash<infer CStaking> ? Address<null, CStaking> : | ||
* Address<null, unknown> | ||
* ) : TSpending extends ValidatorHash<infer CSpending> ? ( | ||
* TStaking extends PubKeyHash ? Address<CSpending, null> : | ||
* TStaking extends StakingValidatorHash<infer CStaking> ? Address<CSpending, CStaking> : | ||
* Address<CSpending, unknown> | ||
* ) : Address | ||
* )} | ||
*/ | ||
static fromHashes(paymentHash, stakingHash, isTestnet = config.IS_TESTNET) { | ||
if (paymentHash instanceof PubKeyHash) { | ||
static fromHashes( | ||
spendingHash, | ||
stakingHash, | ||
isTestnet = config.IS_TESTNET | ||
) { | ||
if (spendingHash instanceof PubKeyHash) { | ||
return /** @type {any} */ ( | ||
Address.fromPubKeyHash(paymentHash, stakingHash, isTestnet) | ||
Address.fromPubKeyHash(spendingHash, stakingHash, isTestnet) | ||
) | ||
} else if (paymentHash instanceof ValidatorHash) { | ||
return Address.fromValidatorHash( | ||
paymentHash, | ||
stakingHash, | ||
isTestnet | ||
} else if (spendingHash instanceof ValidatorHash) { | ||
return /** @type {any} */ ( | ||
Address.fromValidatorHash(spendingHash, stakingHash, isTestnet) | ||
) | ||
} else { | ||
throw new Error("unexpected") | ||
throw new Error("invalid Spending hash") | ||
} | ||
@@ -223,6 +218,11 @@ } | ||
* @private | ||
* @template {PubKeyHash | StakingValidatorHash} [TStaking=PubKeyHash | StakingValidatorHash] | ||
* @param {PubKeyHash} paymentHash | ||
* @param {Option<PubKeyHash | StakingValidatorHash>} stakingHash | ||
* @param {Option<TStaking>} stakingHash | ||
* @param {boolean} isTestnet | ||
* @returns {Address} | ||
* @returns {( | ||
* TStaking extends PubKeyHash ? Address<null, null> : | ||
* TStaking extends StakingValidatorHash<infer C> ? Address<null, C> : | ||
* Address<null, unknown> | ||
* )} | ||
*/ | ||
@@ -232,17 +232,31 @@ static fromPubKeyHash(paymentHash, stakingHash, isTestnet) { | ||
if (stakingHash instanceof PubKeyHash) { | ||
return new Address( | ||
[isTestnet ? 0x00 : 0x01] | ||
.concat(paymentHash.bytes) | ||
.concat(stakingHash.bytes) | ||
return /** @type {any} */ ( | ||
new Address( | ||
[isTestnet ? 0x00 : 0x01] | ||
.concat(paymentHash.bytes) | ||
.concat(stakingHash.bytes), | ||
None, | ||
None | ||
) | ||
) | ||
} else if (stakingHash instanceof StakingValidatorHash) { | ||
return /** @type {any} */ ( | ||
new Address( | ||
[isTestnet ? 0x20 : 0x21] | ||
.concat(paymentHash.bytes) | ||
.concat(stakingHash.bytes), | ||
None, | ||
stakingHash.context | ||
) | ||
) | ||
} else { | ||
return new Address( | ||
[isTestnet ? 0x20 : 0x21] | ||
.concat(paymentHash.bytes) | ||
.concat(stakingHash.bytes) | ||
) | ||
throw new Error("invalid Staking hash") | ||
} | ||
} else { | ||
return new Address( | ||
[isTestnet ? 0x60 : 0x61].concat(paymentHash.bytes) | ||
return /** @type {any} */ ( | ||
new Address( | ||
[isTestnet ? 0x60 : 0x61].concat(paymentHash.bytes), | ||
None, | ||
None | ||
) | ||
) | ||
@@ -269,3 +283,5 @@ } | ||
const paymentCredential = PaymentCredential.fromUplcData(data.fields[0]) | ||
const paymentCredential = SpendingCredential.fromUplcData( | ||
data.fields[0] | ||
) | ||
const stakingCredentialData = ConstrData.expect( | ||
@@ -307,42 +323,45 @@ data.fields[1], | ||
* @private | ||
* @template [TDatumStrict=UplcData] | ||
* @template [TDatumPermissive=UplcData] | ||
* @template [TPaymentRedeemer=UplcData] | ||
* @param {ValidatorHash<TDatumStrict, TDatumPermissive, TPaymentRedeemer>} paymentHash | ||
* @param {Option<PubKeyHash | StakingValidatorHash>} stakingHash | ||
* @template [CSpending=unknown] | ||
* @param {ValidatorHash<CSpending>} spendingHash | ||
* @template {PubKeyHash | StakingValidatorHash} [TStaking=PubKeyHash | StakingValidatorHash]pytho | ||
* @param {Option<TStaking>} stakingHash | ||
* @param {boolean} isTestnet | ||
* @returns {Address<TDatumStrict, TDatumPermissive, TPaymentRedeemer>} | ||
* @returns {( | ||
* TStaking extends (null | undefined | PubKeyHash) ? Address<CSpending, null> : | ||
* TStaking extends StakingValidatorHash<infer CStaking> ? Address<CSpending, CStaking> : | ||
* Address<CSpending, unknown> | ||
* )} | ||
*/ | ||
static fromValidatorHash(paymentHash, stakingHash, isTestnet) { | ||
/** | ||
* @type {Option<AddressContext<TDatumStrict, TDatumPermissive, TPaymentRedeemer>>} | ||
*/ | ||
const context = paymentHash.context | ||
? { | ||
paymentProgram: paymentHash.context.program, | ||
datum: paymentHash.context.datum, | ||
paymentRedeemer: paymentHash.context.redeemer | ||
} | ||
: None | ||
static fromValidatorHash(spendingHash, stakingHash, isTestnet) { | ||
if (isSome(stakingHash)) { | ||
if (stakingHash instanceof PubKeyHash) { | ||
return new Address( | ||
[isTestnet ? 0x10 : 0x11] | ||
.concat(paymentHash.bytes) | ||
.concat(stakingHash.bytes), | ||
context | ||
return /** @type {any} */ ( | ||
new Address( | ||
[isTestnet ? 0x10 : 0x11] | ||
.concat(spendingHash.bytes) | ||
.concat(stakingHash.bytes), | ||
spendingHash.context, | ||
null | ||
) | ||
) | ||
} else if (stakingHash instanceof StakingValidatorHash) { | ||
return /** @type {any} */ ( | ||
new Address( | ||
[isTestnet ? 0x30 : 0x31] | ||
.concat(spendingHash.bytes) | ||
.concat(stakingHash.bytes), | ||
spendingHash.context, | ||
stakingHash.context | ||
) | ||
) | ||
} else { | ||
return new Address( | ||
[isTestnet ? 0x30 : 0x31] | ||
.concat(paymentHash.bytes) | ||
.concat(stakingHash.bytes), | ||
context | ||
) | ||
throw new Error("invalid StakingHash type") | ||
} | ||
} else { | ||
return new Address( | ||
[isTestnet ? 0x70 : 0x71].concat(paymentHash.bytes), | ||
context | ||
return /** @type {any} */ ( | ||
new Address( | ||
[isTestnet ? 0x70 : 0x71].concat(spendingHash.bytes), | ||
spendingHash.context, | ||
null | ||
) | ||
) | ||
@@ -375,2 +394,12 @@ } | ||
/** | ||
* @type {SpendingCredential<SpendingCredentialKind, CSpending>} | ||
*/ | ||
get spendingCredential() { | ||
return SpendingCredential.fromAddressBytes( | ||
this.bytes, | ||
this.spendingContext | ||
) | ||
} | ||
/** | ||
* Returns the underlying `PubKeyHash` of a simple payment address, or `null` for a script address. | ||
@@ -380,8 +409,18 @@ * @type {Option<PubKeyHash>} | ||
get pubKeyHash() { | ||
return this.paymentCredential.pubKeyHash | ||
return this.spendingCredential.pubKeyHash | ||
} | ||
/** | ||
* @type {Option<StakingHash>} | ||
* @type {Option<StakingCredential<StakingHashKind, CStaking>>} | ||
*/ | ||
get stakingCredential() { | ||
return StakingCredential.fromAddressBytes( | ||
this.bytes, | ||
this.stakingContext | ||
) | ||
} | ||
/** | ||
* @type {Option<StakingHash<StakingHashKind, CStaking>>} | ||
*/ | ||
get stakingHash() { | ||
@@ -393,6 +432,6 @@ return this.stakingCredential ? this.stakingCredential.hash : None | ||
* Returns the underlying `ValidatorHash` of a script address, or `null` for a regular payment address. | ||
* @type {Option<ValidatorHash>} | ||
* @type {Option<ValidatorHash<CSpending>>} | ||
*/ | ||
get validatorHash() { | ||
return this.paymentCredential.validatorHash | ||
return this.spendingCredential.validatorHash | ||
} | ||
@@ -460,3 +499,3 @@ | ||
return new ConstrData(0, [ | ||
this.paymentCredential.toUplcData(), | ||
this.spendingCredential.toUplcData(), | ||
encodeOptionData(this.stakingCredential?.toUplcData()) | ||
@@ -463,0 +502,0 @@ ]) |
export { Address } from "./Address.js" | ||
export { PaymentCredential as Credential } from "./PaymentCredential.js" | ||
export { SpendingCredential as Credential } from "./SpendingCredential.js" | ||
export { DCert } from "./DCert.js" | ||
@@ -17,3 +17,4 @@ export { StakingCredential } from "./StakingCredential.js" | ||
/** | ||
* @typedef {import("./SpendingCredential.js").SpendingCredentialLike} SpendingCredentialLike | ||
* @typedef {import("./TxOutputDatum.js").TxOutputDatumKind} TxOutputDatumKind | ||
*/ |
@@ -6,3 +6,4 @@ import { None } from "@helios-lang/type-utils" | ||
StakingHash, | ||
StakingValidatorHash | ||
StakingValidatorHash, | ||
ValidatorHash | ||
} from "../hashes/index.js" | ||
@@ -12,6 +13,8 @@ | ||
* @typedef {import("@helios-lang/uplc").UplcData} UplcData | ||
* @typedef {import("../hashes/index.js").StakingHashKind} StakingHashKind | ||
* @typedef {import("../hashes/index.js").StakingHashLike} StakingHashLike | ||
*/ | ||
/** | ||
* @typedef {StakingCredential | StakingHash | PubKeyHash | StakingValidatorHash} StakingCredentialLike | ||
* @typedef {StakingCredential | StakingHashLike} StakingCredentialLike | ||
*/ | ||
@@ -21,2 +24,4 @@ | ||
* TODO: implement support for staking pointers | ||
* @template {StakingHashKind} [K=StakingHashKind] | ||
* @template [C=unknown] - optional context | ||
*/ | ||
@@ -26,3 +31,3 @@ export class StakingCredential { | ||
* @readonly | ||
* @type {StakingHash} | ||
* @type {StakingHash<K, C>} | ||
*/ | ||
@@ -32,13 +37,15 @@ hash | ||
/** | ||
* @param {Exclude<StakingCredentialLike, StakingCredential>} hash | ||
* @param {StakingHash<K, C>} hash | ||
*/ | ||
constructor(hash) { | ||
this.hash = StakingHash.fromAlike(hash) | ||
this.hash = hash | ||
} | ||
/** | ||
* @template [C=unknown] | ||
* @param {number[]} bytes | ||
* @param {Option<C>} context | ||
* @returns {Option<StakingCredential>} | ||
*/ | ||
static fromAddressBytes(bytes) { | ||
static fromAddressBytes(bytes, context = None) { | ||
if (bytes.length > 29) { | ||
@@ -58,3 +65,5 @@ const head = bytes[0] | ||
return new StakingCredential( | ||
StakingHash.Validator(new StakingValidatorHash(body)) | ||
StakingHash.Validator( | ||
new StakingValidatorHash(body, context) | ||
) | ||
) | ||
@@ -70,9 +79,18 @@ default: | ||
/** | ||
* @param {StakingCredentialLike} arg | ||
* @returns {StakingCredential} | ||
* @template {StakingCredentialLike} T | ||
* @param {T} arg | ||
* @returns {( | ||
* T extends StakingCredential<infer K, infer C> ? StakingCredential<K, C> : | ||
* T extends StakingHash<infer K, infer C> ? StakingCredential<K, C> : | ||
* T extends PubKeyHash ? StakingCredential<"PubKey", null> : | ||
* T extends ValidatorHash<infer C> ? StakingCredential<"Validator", C> : | ||
* StakingCredential | ||
* )} | ||
*/ | ||
static fromAlike(arg) { | ||
return arg instanceof StakingCredential | ||
? arg | ||
: new StakingCredential(arg) | ||
return /** @type {any} */ ( | ||
arg instanceof StakingCredential | ||
? arg | ||
: new StakingCredential(StakingHash.fromAlike(arg)) | ||
) | ||
} | ||
@@ -97,4 +115,11 @@ | ||
/** | ||
* @returns {StakingHash} | ||
* @type {C} | ||
*/ | ||
get context() { | ||
return this.hash.context | ||
} | ||
/** | ||
* @returns {StakingHash<K, C>} | ||
*/ | ||
expectStakingHash() { | ||
@@ -101,0 +126,0 @@ return this.hash |
@@ -287,3 +287,3 @@ import { | ||
this.inputs.forEach((input, i) => { | ||
const paymentCredential = input.output.address.paymentCredential | ||
const paymentCredential = input.output.address.spendingCredential | ||
const datum = input.output.datum | ||
@@ -290,0 +290,0 @@ |
@@ -5,6 +5,4 @@ import { bytesToHex, equalsBytes } from "@helios-lang/codec-utils" | ||
import { | ||
DatumHash, | ||
MintingPolicyHash, | ||
PubKeyHash, | ||
ScriptHash, | ||
ValidatorHash | ||
@@ -47,2 +45,15 @@ } from "../hashes/index.js" | ||
/** | ||
* @template TDatumStrict | ||
* @template TDatumPermissive | ||
* @template TRedeemerStrict | ||
* @template TRedeemerPermissive | ||
* @typedef {import("./SpendingContext.js").SpendingContext<TDatumStrict, TDatumPermissive, TRedeemerStrict, TRedeemerPermissive>} SpendingContext | ||
*/ | ||
/** | ||
* @template T | ||
* @typedef {import("./TxOutputDatum.js").TxOutputDatumCastable<T>} TxOutputDatumCastable | ||
*/ | ||
export class TxBuilder { | ||
@@ -455,10 +466,42 @@ /** | ||
/** | ||
* @template TDatumPermissive | ||
* @overload | ||
* @param {Address<any, TDatumPermissive, any>} address | ||
* @param {Address<null, any>} address | ||
* @param {ValueLike} value | ||
* @param {{hash: TDatumPermissive} | {inline: TDatumPermissive}} datum | ||
* @returns {TxBuilder} | ||
* | ||
* @template TDatum | ||
* @overload | ||
* @param {Address<SpendingContext<any, TDatum, any, any>, any>} address | ||
* @param {ValueLike} value | ||
* @param {TxOutputDatumCastable<TDatum>} datum | ||
* @returns {TxBuilder} | ||
*/ | ||
/** | ||
* @template [TDatum=UplcData] | ||
* @param {[ | ||
* Address<null, any>, ValueLike | ||
* ] | [ | ||
* Address<SpendingContext<any, TDatum, any, any>, any>, ValueLike, TxOutputDatumCastable<TDatum> | ||
* ]} args | ||
* @returns {TxBuilder} | ||
*/ | ||
pay(...args) { | ||
if (args.length == 2) { | ||
return this.payUnsafe(...args) | ||
} else if (args.length == 3) { | ||
const [address, value, datum] = args | ||
return this.payUnsafe( | ||
address, | ||
value, | ||
TxOutputDatum.fromCast(datum, address.spendingContext.datum) | ||
) | ||
} else { | ||
throw new Error("invalid number of args") | ||
} | ||
} | ||
/** | ||
* @overload | ||
* @param {AddressLike} address | ||
@@ -480,6 +523,3 @@ * @param {ValueLike} value | ||
/** | ||
* @template TDatumPermissive | ||
* @param {[ | ||
* Address<any, TDatumPermissive, any>, ValueLike, {hash: TDatumPermissive} | {inline: TDatumPermissive} | ||
* ] | [ | ||
* AddressLike, ValueLike | ||
@@ -493,3 +533,3 @@ * ] | [ | ||
*/ | ||
pay(...args) { | ||
payUnsafe(...args) { | ||
// handle overloads | ||
@@ -500,46 +540,7 @@ const outputs = (() => { | ||
} else if (args.length == 2) { | ||
return new TxOutput(args[0], args[1]) | ||
return new TxOutput(Address.fromAlike(args[0]), args[1]) | ||
} else if (args.length == 3) { | ||
const datum = args[2] | ||
if (datum instanceof TxOutputDatum) { | ||
return new TxOutput( | ||
/** @type {Address} */ (args[0]), | ||
args[1], | ||
datum | ||
) | ||
} else if (datum) { | ||
const address = | ||
/** @type {Address<any, TDatumPermissive, any>} */ ( | ||
args[0] | ||
) | ||
const context = address.context | ||
const value = args[1] | ||
if ("hash" in datum && context) { | ||
return new TxOutput( | ||
/** @type {Address} */ (address), | ||
value, | ||
TxOutputDatum.Hash( | ||
context.datum.toUplcData( | ||
/** @type {TDatumPermissive} */ (args[2]) | ||
) | ||
) | ||
) | ||
} else if ("inline" in datum && context) { | ||
return new TxOutput( | ||
/** @type {Address} */ (address), | ||
value, | ||
TxOutputDatum.Inline( | ||
context.datum.toUplcData( | ||
/** @type {TDatumPermissive} */ (args[2]) | ||
) | ||
) | ||
) | ||
} else { | ||
throw new Error("invalid arguments") | ||
} | ||
} else { | ||
throw new Error("invalid arguments") | ||
} | ||
return new TxOutput(Address.fromAlike(args[0]), args[1], datum) | ||
} else { | ||
@@ -551,3 +552,3 @@ throw new Error("invalid arguments") | ||
if (Array.isArray(outputs)) { | ||
outputs.forEach((output) => this.pay(output)) | ||
outputs.forEach((output) => this.payUnsafe(output)) | ||
return this | ||
@@ -614,21 +615,61 @@ } | ||
/** | ||
* @template TRedeemer | ||
* @overload | ||
* @param {TxInput<any, TRedeemer> | TxInput<any, TRedeemer>[]} utxos | ||
* @param {TRedeemer} redeemer | ||
* @param {TxInput<null, any> | TxInput<null, any>[]} utxos | ||
* @returns {TxBuilder} | ||
* | ||
* @template TRedeemer | ||
* @overload | ||
* @param {TxInput | TxInput[]} utxos | ||
* @param {Option<UplcData>} redeemer | ||
* @param {TxInput<SpendingContext<any, any, any, TRedeemer>, any> | TxInput<SpendingContext<any, any, any, TRedeemer>, any>[]} utxos | ||
* @param {TRedeemer} redeemer | ||
* @returns {TxBuilder} | ||
*/ | ||
/** | ||
* @template TRedeemer | ||
* @param {[ | ||
* TxInput<null, any> | TxInput<null, any>[] | ||
* ] | [ | ||
* TxInput<SpendingContext<any, any, any, TRedeemer>, any> | TxInput<SpendingContext<any, any, any, TRedeemer>, any>[], | ||
* TRedeemer | ||
* ]} args | ||
* @returns {TxBuilder} | ||
*/ | ||
spend(...args) { | ||
if (args.length == 1) { | ||
return this.spendUnsafe(args[0]) | ||
} else if (args.length == 2) { | ||
const [utxos, redeemer] = args | ||
if (Array.isArray(utxos)) { | ||
if (utxos.length == 0) { | ||
throw new Error("expected at least one UTxO") | ||
} | ||
utxos.forEach((utxo) => | ||
this.attachUplcProgram(utxo.spendingContext.program) | ||
) | ||
return this.spendUnsafe( | ||
utxos, | ||
utxos[0].spendingContext.redeemer.toUplcData(redeemer) | ||
) | ||
} else { | ||
this.attachUplcProgram(utxos.spendingContext.program) | ||
return this.spendUnsafe( | ||
utxos, | ||
utxos.spendingContext.redeemer.toUplcData(redeemer) | ||
) | ||
} | ||
} else { | ||
throw new Error("invalid number of arguments") | ||
} | ||
} | ||
/** | ||
* Add a UTxO instance as an input to the transaction being built. | ||
* Throws an error if the UTxO is locked at a script address but a redeemer isn't specified (unless the script is a known `NativeScript`). | ||
* @param {TxInput | TxInput[]} utxos | ||
* @param {TRedeemer | Option<UplcData>} redeemer | ||
* @param {Option<UplcData>} redeemer | ||
* @returns {TxBuilder} | ||
*/ | ||
spend(utxos, redeemer = None) { | ||
spendUnsafe(utxos, redeemer = None) { | ||
if (Array.isArray(utxos)) { | ||
@@ -643,3 +684,3 @@ utxos.forEach((utxo) => this.spend(utxo, redeemer)) | ||
const origOutput = utxo.output | ||
const paymentCredential = utxo.address.paymentCredential | ||
const spendingCredential = utxo.address.spendingCredential | ||
const datum = origOutput?.datum | ||
@@ -651,3 +692,3 @@ | ||
if (redeemer) { | ||
if (!paymentCredential.isValidator()) { | ||
if (!spendingCredential.isValidator()) { | ||
throw new Error( | ||
@@ -658,9 +699,3 @@ "input isn't locked by a script, (hint: omit the redeemer)" | ||
const context = utxo.context | ||
if (context) { | ||
this.attachUplcProgram(context.program) | ||
} | ||
if (!this.hasUplcScript(paymentCredential.validatorHash.bytes)) { | ||
if (!this.hasUplcScript(spendingCredential.validatorHash.bytes)) { | ||
throw new Error( | ||
@@ -671,8 +706,3 @@ "input is locked by an unknown script (hint: attach the script before calling TxBuilder.spend()" | ||
this.addSpendingRedeemer( | ||
utxo, | ||
context | ||
? context.redeemer.toUplcData(/** @type {any} */ (redeemer)) | ||
: /** @type {UplcData} */ (redeemer) | ||
) | ||
this.addSpendingRedeemer(utxo, redeemer) | ||
@@ -684,5 +714,5 @@ if (!datum) { | ||
this.addDatum(datum.data) | ||
} else if (paymentCredential.isValidator()) { | ||
} else if (spendingCredential.isValidator()) { | ||
// redeemerless spending from a validator is only possible if it is a native script | ||
if (!this.hasNativeScript(paymentCredential.validatorHash.bytes)) { | ||
if (!this.hasNativeScript(spendingCredential.validatorHash.bytes)) { | ||
throw new Error( | ||
@@ -819,8 +849,8 @@ "input is locked by a script, but redeemer isn't specified (hint: if this is a NativeScript, attach that script before calling TxBuiilder.spend())" | ||
const paymentCredential = output.address.paymentCredential | ||
const spendingCredential = output.address.spendingCredential | ||
if ( | ||
isNone(output.datum) && | ||
paymentCredential.isValidator() && | ||
!this.hasNativeScript(paymentCredential.validatorHash.bytes) | ||
spendingCredential.isValidator() && | ||
!this.hasNativeScript(spendingCredential.validatorHash.bytes) | ||
) { | ||
@@ -1094,3 +1124,3 @@ throw new Error( | ||
balanceAssets(changeAddress) { | ||
if (changeAddress.paymentCredential.isValidator()) { | ||
if (changeAddress.spendingCredential.isValidator()) { | ||
throw new Error("can't send change to validator") | ||
@@ -1097,0 +1127,0 @@ } |
@@ -41,4 +41,4 @@ import { | ||
* TxInput represents UTxOs that are available for spending | ||
* @template [TDatum=UplcData] | ||
* @template [TRedeemer=UplcData] | ||
* @template [CSpending=unknown] | ||
* @template [CStaking=unknown] | ||
*/ | ||
@@ -59,16 +59,8 @@ export class TxInput { | ||
/** | ||
* @readonly | ||
* @type {Option<TxInputContext<TDatum, TRedeemer>>} | ||
*/ | ||
context | ||
/** | ||
* @param {TxOutputId} outputId | ||
* @param {Option<TxOutput>} output - used during building/emulation, not part of serialization | ||
* @param {Option<TxInputContext<TDatum, TRedeemer>>} context | ||
* @param {Option<TxOutput<CSpending, CStaking>>} output - used during building/emulation, not part of serialization | ||
*/ | ||
constructor(outputId, output = None, context = None) { | ||
constructor(outputId, output = None) { | ||
this.id = outputId | ||
this.#output = output | ||
this.context = context | ||
} | ||
@@ -168,3 +160,3 @@ | ||
* Shortcut | ||
* @type {Address} | ||
* @type {Address<CSpending, CStaking>} | ||
*/ | ||
@@ -185,3 +177,3 @@ get address() { | ||
* Throws an error if the TxInput hasn't been recovered | ||
* @returns {TxOutput} | ||
* @returns {TxOutput<CSpending, CStaking>} | ||
*/ | ||
@@ -197,2 +189,16 @@ get output() { | ||
/** | ||
* @type {CSpending} | ||
*/ | ||
get spendingContext() { | ||
return this.address.spendingContext | ||
} | ||
/** | ||
* @type {CStaking} | ||
*/ | ||
get stakingContext() { | ||
return this.address.stakingContext | ||
} | ||
/** | ||
* Shortcut | ||
@@ -199,0 +205,0 @@ * @type {Value} |
@@ -41,2 +41,4 @@ import { | ||
* Represents a transaction output that is used when building a transaction. | ||
* @template [CSpending=unknown] | ||
* @template [CStaking=unknown] | ||
*/ | ||
@@ -46,3 +48,3 @@ export class TxOutput { | ||
* Mutation is useful when correcting the quantity of lovelace in a utxo | ||
* @type {Address} | ||
* @type {Address<CSpending, CStaking>} | ||
*/ | ||
@@ -70,3 +72,3 @@ address | ||
* Constructs a `TxOutput` instance using an `Address`, a `Value`, an optional `Datum`, and optional `UplcProgram` reference script. | ||
* @param {AddressLike} address | ||
* @param {Address<CSpending, CStaking>} address | ||
* @param {ValueLike} value | ||
@@ -77,3 +79,3 @@ * @param {Option<TxOutputDatum>} datum | ||
constructor(address, value, datum = None, refScript = None) { | ||
this.address = Address.fromAlike(address) | ||
this.address = address | ||
this.value = Value.fromAlike(value) | ||
@@ -173,2 +175,16 @@ this.datum = datum | ||
/** | ||
* @type {CSpending} | ||
*/ | ||
get spendingContext() { | ||
return this.address.spendingContext | ||
} | ||
/** | ||
* @type {CStaking} | ||
*/ | ||
get stakingContext() { | ||
return this.address.stakingContext | ||
} | ||
/** | ||
* @returns {Object} | ||
@@ -175,0 +191,0 @@ */ |
@@ -22,2 +22,8 @@ import { None } from "@helios-lang/type-utils" | ||
/** | ||
* @template TStrict | ||
* @template TPermissive | ||
* @typedef {import("../hashes/Cast.js").Cast<TStrict, TPermissive>} Cast | ||
*/ | ||
/** | ||
* @typedef {Option<TxOutputDatum> | DatumHash | UplcData} TxOutputDatumLike | ||
@@ -27,2 +33,7 @@ */ | ||
/** | ||
* @template T | ||
* @typedef {{hash: T} | {inline: T}} TxOutputDatumCastable | ||
*/ | ||
/** | ||
* @typedef {"Hash" | "Inline"} TxOutputDatumKind | ||
@@ -129,2 +140,17 @@ */ | ||
/** | ||
* @template T | ||
* @template {TxOutputDatumCastable<T>} D | ||
* @param {D} data | ||
* @param {Cast<any, T>} cast | ||
* @returns {D extends {hash: T} ? TxOutputDatum<"Hash"> : TxOutputDatum<"Inline">} | ||
*/ | ||
static fromCast(data, cast) { | ||
return /** @type {any} */ ( | ||
"hash" in data | ||
? TxOutputDatum.Hash(cast.toUplcData(data.hash)) | ||
: TxOutputDatum.Inline(cast.toUplcData(data.inline)) | ||
) | ||
} | ||
/** | ||
* @param {ByteArrayLike} bytes | ||
@@ -131,0 +157,0 @@ * @returns {TxOutputDatum} |
@@ -13,2 +13,3 @@ export { DatumHash } from "./DatumHash.js"; | ||
export type ScriptHashLike = import("./ScriptHash.js").ScriptHashLike; | ||
export type StakingHashKind = import("./StakingHash.js").StakingHashKind; | ||
export type StakingHashLike = import("./StakingHash.js").StakingHashLike; | ||
@@ -15,0 +16,0 @@ export type StakingValidatorHashLike = import("./StakingValidatorHash.js").StakingValidatorHashLike; |
@@ -5,31 +5,26 @@ /** | ||
* @typedef {import("./Hash.js").Hash} Hash | ||
* @typedef {import("./MintingContext.js").MintingContext} MintingContext | ||
*/ | ||
/** | ||
* @template TStrict | ||
* @template TPermissive | ||
* @typedef {import("./Cast.js").Cast<TStrict, TPermissive>} Cast | ||
*/ | ||
/** | ||
* @typedef {MintingPolicyHash | ByteArrayLike} MintingPolicyHashLike | ||
*/ | ||
/** | ||
* @template [TRedeemer=UplcData] | ||
* @typedef {{ | ||
* program: UplcProgramV1 | UplcProgramV2, | ||
* redeemer: Cast<UplcData, TRedeemer> | ||
* }} MintingPolicyHashContext | ||
*/ | ||
/** | ||
* Represents a blake2b-224 hash of a minting policy script | ||
* | ||
* **Note**: to calculate this hash the script is first encoded as a CBOR byte-array and then prepended by a script version byte. | ||
* @template [TRedeemer=UplcData] | ||
* | ||
* `C` is some optional context: | ||
* null: unwitnessed or witnessed by NativeScript | ||
* unknown: witnessed or unwitnessed (default) | ||
* {program: ..., redeemer: ...}: witnessed by UplcProgram | ||
* @template [C=unknown] | ||
* @implements {Hash} | ||
*/ | ||
export class MintingPolicyHash<TRedeemer = import("@helios-lang/uplc").UplcData> extends ScriptHash implements Hash { | ||
export class MintingPolicyHash<C = unknown> extends ScriptHash implements Hash { | ||
/** | ||
* @param {MintingPolicyHashLike} arg | ||
* @returns {MintingPolicyHash} | ||
* @template {MintingPolicyHashLike} T | ||
* @param {T} arg | ||
* @returns {T extends MintingPolicyHash<infer C> ? MintingPolicyHash<C> : MintingPolicyHash} | ||
*/ | ||
static fromAlike(arg: MintingPolicyHashLike): MintingPolicyHash; | ||
static fromAlike<T extends MintingPolicyHashLike>(arg: T): T extends MintingPolicyHash<infer C_1> ? MintingPolicyHash<C_1> : MintingPolicyHash<any>; | ||
/** | ||
@@ -58,11 +53,11 @@ * @param {ByteArrayLike} bytes | ||
* Can be 0 bytes in case of Ada | ||
* @param {Exclude<MintingPolicyHashLike, MintingPolicyHash>} bytes | ||
* @param {Option<MintingPolicyHashContext<TRedeemer>>} context | ||
* @param {ByteArrayLike} bytes | ||
* @param {Option<C>} context - not recommended to set this manually | ||
*/ | ||
constructor(bytes: Exclude<MintingPolicyHashLike, MintingPolicyHash>, context?: Option<MintingPolicyHashContext<TRedeemer>>); | ||
constructor(bytes: ByteArrayLike, context?: Option<C>); | ||
/** | ||
* @readonly | ||
* @type {Option<MintingPolicyHashContext<TRedeemer>>} | ||
* @type {C} | ||
*/ | ||
readonly context: Option<MintingPolicyHashContext<TRedeemer>>; | ||
readonly context: C; | ||
/** | ||
@@ -82,11 +77,5 @@ * @param {MintingPolicyHash} other | ||
export type Hash = import("./Hash.js").Hash; | ||
export type Cast<TStrict, TPermissive> = import("./Cast.js").Cast<TStrict, TPermissive>; | ||
export type MintingContext = import("./MintingContext.js").MintingContext; | ||
export type MintingPolicyHashLike = MintingPolicyHash | ByteArrayLike; | ||
export type MintingPolicyHashContext<TRedeemer = import("@helios-lang/uplc").UplcData> = { | ||
program: UplcProgramV1 | UplcProgramV2; | ||
redeemer: Cast<UplcData, TRedeemer>; | ||
}; | ||
import { ScriptHash } from "./ScriptHash.js"; | ||
import { UplcProgramV1 } from "@helios-lang/uplc"; | ||
import { UplcProgramV2 } from "@helios-lang/uplc"; | ||
//# sourceMappingURL=MintingPolicyHash.d.ts.map |
@@ -24,19 +24,27 @@ /** | ||
* @template {StakingHashKind} [T=StakingHashKind] | ||
* @template [C=unknown] | ||
*/ | ||
export class StakingHash<T extends StakingHashKind = StakingHashKind> { | ||
export class StakingHash<T extends StakingHashKind = StakingHashKind, C = unknown> { | ||
/** | ||
* @param {PubKeyHashLike} hash | ||
* @returns {StakingHash<"PubKey">} | ||
* @returns {StakingHash<"PubKey", null>} | ||
*/ | ||
static PubKey(hash: PubKeyHashLike): StakingHash<"PubKey">; | ||
static PubKey(hash: PubKeyHashLike): StakingHash<"PubKey", null>; | ||
/** | ||
* @param {StakingValidatorHashLike} hash | ||
* @returns {StakingHash<"Validator">} | ||
* @template {StakingValidatorHashLike} T | ||
* @param {T} hash | ||
* @returns {T extends StakingValidatorHash<infer C> ? StakingHash<"Validator", C> : StakingHash<"Validator">} | ||
*/ | ||
static Validator(hash: StakingValidatorHashLike): StakingHash<"Validator">; | ||
static Validator<T_1 extends import("../hashes/index.js").StakingValidatorHashLike>(hash: T_1): T_1 extends StakingValidatorHash<infer C_1> ? StakingHash<"Validator", C_1> : StakingHash<"Validator", any>; | ||
/** | ||
* @param {StakingHashLike} arg | ||
* @returns {StakingHash} | ||
* @template {StakingHashLike} T | ||
* @param {T} arg | ||
* @returns {( | ||
* T extends PubKeyHash ? StakingHash<"PubKey", null> : | ||
* T extends StakingValidatorHash<infer C> ? StakingHash<"Validator", C> : | ||
* T extends StakingHash<infer K, infer C> ? StakingHash<K, C> : | ||
* StakingHash | ||
* )} | ||
*/ | ||
static fromAlike(arg: StakingHashLike): StakingHash; | ||
static fromAlike<T_2 extends StakingHashLike>(arg: T_2): T_2 extends PubKeyHash ? StakingHash<"PubKey", null> : T_2 extends StakingValidatorHash<infer C_2> ? StakingHash<"Validator", C_2> : T_2 extends StakingHash<infer K extends StakingHashKind, infer C_3> ? StakingHash<K, C_3> : StakingHash<StakingHashKind, any>; | ||
/** | ||
@@ -48,6 +56,6 @@ * @param {ByteArrayLike} bytes | ||
/** | ||
* | ||
* @param {UplcData} data | ||
* @returns {StakingHash} | ||
*/ | ||
static fromUplcData(data: UplcData): StakingHash<"PubKey"> | StakingHash<"Validator">; | ||
static fromUplcData(data: UplcData): StakingHash; | ||
/** | ||
@@ -57,2 +65,3 @@ * @private | ||
* @param {StakingHashProps<T>} props | ||
* @param {Option<C>} context | ||
*/ | ||
@@ -73,2 +82,7 @@ private constructor(); | ||
/** | ||
* @readonly | ||
* @type {C} | ||
*/ | ||
readonly context: C; | ||
/** | ||
* @type {number[]} | ||
@@ -78,5 +92,5 @@ */ | ||
/** | ||
* @type {T extends "PubKey" ? PubKeyHash : T extends "Validator" ? StakingValidatorHash : (PubKeyHash | StakingValidatorHash)} | ||
* @type {T extends "PubKey" ? PubKeyHash : T extends "Validator" ? StakingValidatorHash<C> : (PubKeyHash | StakingValidatorHash<C>)} | ||
*/ | ||
get hash(): T extends "PubKey" ? PubKeyHash : T extends "Validator" ? StakingValidatorHash : PubKeyHash | StakingValidatorHash; | ||
get hash(): T extends "PubKey" ? PubKeyHash : T extends "Validator" ? StakingValidatorHash<C> : PubKeyHash | StakingValidatorHash<C>; | ||
/** | ||
@@ -87,13 +101,13 @@ * @type {T extends "PubKey" ? PubKeyHash : T extends "Validator" ? typeof None : Option<PubKeyHash>} | ||
/** | ||
* @type {T extends "Validator" ? StakingValidatorHash : T extends "PubKey" ? typeof None : Option<StakingValidatorHash>} | ||
* @type {T extends "Validator" ? StakingValidatorHash<C> : T extends "PubKey" ? typeof None : Option<StakingValidatorHash<C>>} | ||
*/ | ||
get stakingValidatorHash(): T extends "Validator" ? StakingValidatorHash : T extends "PubKey" ? null : Option<StakingValidatorHash>; | ||
get stakingValidatorHash(): T extends "Validator" ? StakingValidatorHash<C> : T extends "PubKey" ? null : Option<StakingValidatorHash<C>>; | ||
/** | ||
* @returns {this is StakingHash<"PubKey">} | ||
* @returns {this is StakingHash<"PubKey", null>} | ||
*/ | ||
isPubKey(): this is StakingHash<"PubKey">; | ||
isPubKey(): this is StakingHash<"PubKey", null>; | ||
/** | ||
* @returns {this is StakingHash<"Validator">} | ||
* @returns {this is StakingHash<"Validator", C>} | ||
*/ | ||
isValidator(): this is StakingHash<"Validator">; | ||
isValidator(): this is StakingHash<"Validator", C>; | ||
/** | ||
@@ -100,0 +114,0 @@ * @returns {number[]} |
@@ -7,3 +7,4 @@ /** | ||
/** | ||
* @typedef {StakingValidatorHash | ByteArrayLike} StakingValidatorHashLike | ||
* @template [C=unknown] | ||
* @typedef {StakingValidatorHash<C> | ByteArrayLike} StakingValidatorHashLike | ||
*/ | ||
@@ -14,5 +15,48 @@ /** | ||
* **Note**: before hashing, the staking script is first encoded as a CBOR byte-array and then prepended by a script version byte. | ||
* @template [C=unknown] | ||
* @implements {Hash} | ||
*/ | ||
export class StakingValidatorHash extends ScriptHash implements Hash { | ||
export class StakingValidatorHash<C = unknown> extends ScriptHash implements Hash { | ||
/** | ||
* @template {StakingValidatorHashLike} T | ||
* @param {T} arg | ||
* @returns {T extends StakingValidatorHash<infer C> ? StakingValidatorHash<C> : StakingValidatorHash} | ||
*/ | ||
static fromAlike<T extends StakingValidatorHashLike<unknown>>(arg: T): T extends StakingValidatorHash<infer C_1> ? StakingValidatorHash<C_1> : StakingValidatorHash<any>; | ||
/** | ||
* @param {ByteArrayLike} bytes | ||
* @returns {StakingValidatorHash} | ||
*/ | ||
static fromCbor(bytes: ByteArrayLike): StakingValidatorHash; | ||
/** | ||
* @param {UplcData} data | ||
* @returns {StakingValidatorHash} | ||
*/ | ||
static fromUplcData(data: UplcData): StakingValidatorHash; | ||
/** | ||
* @param {ByteArrayLike} bytes | ||
* @returns {StakingValidatorHash} | ||
*/ | ||
static fromUplcCbor(bytes: ByteArrayLike): StakingValidatorHash; | ||
/** | ||
* @param {StakingValidatorHash} a | ||
* @param {StakingValidatorHash} b | ||
* @returns {number} | ||
*/ | ||
static compare(a: StakingValidatorHash, b: StakingValidatorHash): number; | ||
/** | ||
* @param {ByteArrayLike} bytes | ||
* @param {Option<C>} context | ||
*/ | ||
constructor(bytes: ByteArrayLike, context?: Option<C>); | ||
/** | ||
* @readonly | ||
* @type {C} | ||
*/ | ||
readonly context: C; | ||
/** | ||
* @param {StakingValidatorHash} other | ||
* @returns {boolean} | ||
*/ | ||
isEqual(other: StakingValidatorHash): boolean; | ||
} | ||
@@ -22,4 +66,4 @@ export type ByteArrayLike = import("@helios-lang/codec-utils").ByteArrayLike; | ||
export type Hash = import("./Hash.js").Hash; | ||
export type StakingValidatorHashLike = StakingValidatorHash | ByteArrayLike; | ||
export type StakingValidatorHashLike<C = unknown> = StakingValidatorHash<C> | ByteArrayLike; | ||
import { ScriptHash } from "./ScriptHash.js"; | ||
//# sourceMappingURL=StakingValidatorHash.d.ts.map |
/** | ||
* @typedef {import("@helios-lang/codec-utils").ByteArrayLike} ByteArrayLike | ||
* @typedef {import("@helios-lang/uplc").UplcData} UplcData | ||
* @typedef {import("./Hash.js").Hash} Hash | ||
*/ | ||
/** | ||
* @template TStrict | ||
* @template TPermissive | ||
* @typedef {import("./Cast.js").Cast<TStrict, TPermissive>} Cast | ||
*/ | ||
/** | ||
* @typedef {ValidatorHash | ByteArrayLike} ValidatorHashLike | ||
*/ | ||
/** | ||
* @template TDatumStrict | ||
* @template TDatumPermissive | ||
* @template TRedeemer | ||
* @typedef {{ | ||
* program: UplcProgramV1 | UplcProgramV2 | ||
* datum: Cast<TDatumStrict, TDatumPermissive> | ||
* redeemer: Cast<any, TRedeemer> | ||
* }} ValidatorHashContext | ||
*/ | ||
/** | ||
* Represents a blake2b-224 hash of a spending validator script (first encoded as a CBOR byte-array and prepended by a script version byte). | ||
* @template [TDatumStrict=UplcData] | ||
* @template [TDatumPermissive=UplcData] | ||
* @template [TRedeemer=UplcData] | ||
* @template [C=unknown] | ||
* @implements {Hash} | ||
*/ | ||
export class ValidatorHash<TDatumStrict = import("@helios-lang/uplc").UplcData, TDatumPermissive = import("@helios-lang/uplc").UplcData, TRedeemer = import("@helios-lang/uplc").UplcData> extends ScriptHash implements Hash { | ||
export class ValidatorHash<C = unknown> extends ScriptHash implements Hash { | ||
/** | ||
* @param {ValidatorHashLike} arg | ||
* @returns {ValidatorHash} | ||
* @template {ValidatorHashLike} T | ||
* @param {T} arg | ||
* @returns {arg extends ValidatorHash<infer C> ? ValidatorHash<C> : ValidatorHash} | ||
*/ | ||
static fromAlike(arg: ValidatorHashLike): ValidatorHash; | ||
static fromAlike<T extends ValidatorHashLike>(arg: T): T extends ValidatorHash<infer C_1> ? ValidatorHash<C_1> : ValidatorHash<any>; | ||
/** | ||
@@ -60,8 +43,12 @@ * @param {ByteArrayLike} bytes | ||
/** | ||
* @param {Exclude<ValidatorHashLike, ValidatorHash>} bytes | ||
* @param {Option<ValidatorHashContext<TDatumStrict, TDatumPermissive, TRedeemer>>} context | ||
* @param {ByteArrayLike} bytes | ||
* @param {Option<C>} context | ||
*/ | ||
constructor(bytes: Exclude<ValidatorHashLike, ValidatorHash>, context?: Option<ValidatorHashContext<TDatumStrict, TDatumPermissive, TRedeemer>>); | ||
context: ValidatorHashContext<TDatumStrict, TDatumPermissive, TRedeemer> | null; | ||
constructor(bytes: ByteArrayLike, context?: Option<C>); | ||
/** | ||
* @readonly | ||
* @type {C} | ||
*/ | ||
readonly context: C; | ||
/** | ||
* @param {ValidatorHash} other | ||
@@ -75,12 +62,4 @@ * @returns {boolean} | ||
export type Hash = import("./Hash.js").Hash; | ||
export type Cast<TStrict, TPermissive> = import("./Cast.js").Cast<TStrict, TPermissive>; | ||
export type ValidatorHashLike = ValidatorHash | ByteArrayLike; | ||
export type ValidatorHashContext<TDatumStrict, TDatumPermissive, TRedeemer> = { | ||
program: UplcProgramV1 | UplcProgramV2; | ||
datum: Cast<TDatumStrict, TDatumPermissive>; | ||
redeemer: Cast<any, TRedeemer>; | ||
}; | ||
import { ScriptHash } from "./ScriptHash.js"; | ||
import { UplcProgramV1 } from "@helios-lang/uplc"; | ||
import { UplcProgramV2 } from "@helios-lang/uplc"; | ||
//# sourceMappingURL=ValidatorHash.d.ts.map |
@@ -27,13 +27,15 @@ /** | ||
* Represents a `MintingPolicyHash` combined with a token name. | ||
* @template [C=unknown] | ||
*/ | ||
export class AssetClass { | ||
export class AssetClass<C = unknown> { | ||
/** | ||
* @type {AssetClass} | ||
*/ | ||
static get ADA(): AssetClass; | ||
static get ADA(): AssetClass<any>; | ||
/** | ||
* @param {AssetClassLike} arg | ||
* @returns {AssetClass} | ||
* @template {AssetClassLike} T | ||
* @param {T} arg | ||
* @returns {T extends [MintingPolicyHash<infer C>, ByteArrayLike] ? AssetClass<C> : T extends AssetClass<infer C> ? AssetClass<C> : AssetClass} | ||
*/ | ||
static fromAlike(arg: AssetClassLike): AssetClass; | ||
static fromAlike<T extends AssetClassLike>(arg: T): T extends [MintingPolicyHash<infer C_1>, import("@helios-lang/codec-utils").ByteArrayLike] ? AssetClass<C_1> : T extends AssetClass<infer C_2> ? AssetClass<C_2> : AssetClass<any>; | ||
/** | ||
@@ -62,13 +64,10 @@ * Deserializes bytes into an `AssetClass`. | ||
/** | ||
* Intelligently converts arguments. | ||
* | ||
* The format for single argument string is "<hex-encoded-mph>.<hex-encoded-token-name>". | ||
* @param {MintingPolicyHashLike} mph | ||
* @param {MintingPolicyHash<C>} mph - policy with optional context | ||
* @param {ByteArrayLike} tokenName | ||
*/ | ||
constructor(mph: MintingPolicyHashLike, tokenName: ByteArrayLike); | ||
constructor(mph: MintingPolicyHash<C>, tokenName: ByteArrayLike); | ||
/** | ||
* @type {MintingPolicyHash} | ||
* @type {MintingPolicyHash<C>} | ||
*/ | ||
mph: MintingPolicyHash; | ||
mph: MintingPolicyHash<C>; | ||
/** | ||
@@ -79,2 +78,7 @@ * @type {number[]} | ||
/** | ||
* @readonly | ||
* @type {C} | ||
*/ | ||
readonly context: C; | ||
/** | ||
* Converts an `AssetClass` instance into its CBOR representation. | ||
@@ -81,0 +85,0 @@ * @returns {number[]} |
/** | ||
* @typedef {import("@helios-lang/codec-utils").ByteArrayLike} ByteArrayLike | ||
* @typedef {import("@helios-lang/uplc").UplcData} UplcData | ||
* @typedef {import("../hashes/index.js").StakingHashKind} StakingHashKind | ||
* @typedef {import("./SpendingCredential.js").SpendingCredentialKind} SpendingCredentialKind | ||
*/ | ||
/** | ||
* @template TStrict | ||
* @template TPermissive | ||
* @typedef {import("../hashes/Cast.js").Cast<TStrict, TPermissive>} Cast | ||
*/ | ||
/** | ||
* @typedef {Address | ByteArrayLike} AddressLike | ||
*/ | ||
/** | ||
* @template TDatumStrict | ||
* @template TDatumPermissive | ||
* @template TPaymentRedeemer | ||
* @typedef {{ | ||
* paymentProgram: UplcProgramV1 | UplcProgramV2 | ||
* datum: Cast<TDatumStrict, TDatumPermissive> | ||
* paymentRedeemer: Cast<any, TPaymentRedeemer> | ||
* }} AddressContext | ||
*/ | ||
/** | ||
* Wrapper for Cardano address bytes. An `Address` consists of three parts internally: | ||
@@ -28,7 +15,6 @@ * * Header (1 byte, see [CIP 19](https://cips.cardano.org/cips/cip19/)) | ||
* * Optional staking credential (0 or 28 bytes) | ||
* @template [TDatumStrict=UplcData] | ||
* @template [TDatumPermissive=UplcData] | ||
* @template [TPaymentRedeemer=UplcData] | ||
* @template [CSpending=unknown] - spending can have a context | ||
* @template [CStaking=unknown] - staking can have a separate context | ||
*/ | ||
export class Address<TDatumStrict = import("@helios-lang/uplc").UplcData, TDatumPermissive = import("@helios-lang/uplc").UplcData, TPaymentRedeemer = import("@helios-lang/uplc").UplcData> { | ||
export class Address<CSpending = unknown, CStaking = unknown> { | ||
/** | ||
@@ -58,3 +44,3 @@ * Returns a dummy address (based on a PubKeyHash with all null bytes) | ||
/** | ||
* @param {PaymentCredential} paymentCredential | ||
* @param {SpendingCredential} paymentCredential | ||
* @param {Option<StakingCredential>} stakingCredential | ||
@@ -64,3 +50,3 @@ * @param {boolean} isTestnet | ||
*/ | ||
static fromCredentials(paymentCredential: PaymentCredential, stakingCredential: Option<StakingCredential>, isTestnet?: boolean): Address; | ||
static fromCredentials(paymentCredential: SpendingCredential, stakingCredential: Option<StakingCredential>, isTestnet?: boolean): Address; | ||
/** | ||
@@ -70,10 +56,12 @@ * Constructs an Address using either a `PubKeyHash` (i.e. simple payment address) | ||
* without a staking hash. | ||
* @template [TDatumStrict=UplcData] | ||
* @template [TDatumPermissive=UplcData] | ||
* @template [TPaymentRedeemer=UplcData] | ||
* @param {PubKeyHash | ValidatorHash<TDatumStrict, TDatumPermissive, TPaymentRedeemer>} hash | ||
* @template {PubKeyHash | ValidatorHash} [TSpending=PubKeyHash | ValidatorHash] | ||
* @param {TSpending} hash | ||
* @param {boolean} isTestnet | ||
* @returns {Address<TDatumStrict, TDatumPermissive, TPaymentRedeemer>} | ||
* @returns {( | ||
* TSpending extends PubKeyHash ? Address<null, null> : | ||
* TSpending extends ValidatorHash<infer CSpending> ? Address<CSpending, null> : | ||
* Address<unknown, null> | ||
* )} | ||
*/ | ||
static fromHash<TDatumStrict_1 = import("@helios-lang/uplc").UplcData, TDatumPermissive_1 = import("@helios-lang/uplc").UplcData, TPaymentRedeemer_1 = import("@helios-lang/uplc").UplcData>(hash: PubKeyHash | ValidatorHash<TDatumStrict_1, TDatumPermissive_1, TPaymentRedeemer_1>, isTestnet?: boolean): Address<TDatumStrict_1, TDatumPermissive_1, TPaymentRedeemer_1>; | ||
static fromHash<TSpending extends PubKeyHash | ValidatorHash<any> = PubKeyHash | ValidatorHash<any>>(hash: TSpending, isTestnet?: boolean): TSpending extends PubKeyHash ? Address<null, null> : TSpending extends ValidatorHash<infer CSpending_1> ? Address<CSpending_1, null> : Address<unknown, null>; | ||
/** | ||
@@ -83,18 +71,32 @@ * Constructs an Address using either a `PubKeyHash` (i.e. simple payment address) | ||
* in combination with an optional staking hash (`PubKeyHash` or `StakingValidatorHash`). | ||
* @template [TDatumStrict=UplcData] | ||
* @template [TDatumPermissive=UplcData] | ||
* @template [TPaymentRedeemer=UplcData] | ||
* @param {PubKeyHash | ValidatorHash<TDatumStrict, TDatumPermissive, TPaymentRedeemer>} paymentHash | ||
* @param {Option<PubKeyHash | StakingValidatorHash>} stakingHash | ||
* @template {PubKeyHash | ValidatorHash} [TSpending=PubKeyHash | ValidatorHash] | ||
* @template {PubKeyHash | StakingValidatorHash} [TStaking=PubKeyHash | StakingValidatorHash] | ||
* @param {TSpending} spendingHash | ||
* @param {Option<TStaking>} stakingHash | ||
* @param {boolean} isTestnet | ||
* @returns {Address<TDatumStrict, TDatumPermissive, TPaymentRedeemer>} | ||
* @returns {( | ||
* TSpending extends PubKeyHash ? ( | ||
* TStaking extends PubKeyHash ? Address<null, null> : | ||
* TStaking extends StakingValidatorHash<infer CStaking> ? Address<null, CStaking> : | ||
* Address<null, unknown> | ||
* ) : TSpending extends ValidatorHash<infer CSpending> ? ( | ||
* TStaking extends PubKeyHash ? Address<CSpending, null> : | ||
* TStaking extends StakingValidatorHash<infer CStaking> ? Address<CSpending, CStaking> : | ||
* Address<CSpending, unknown> | ||
* ) : Address | ||
* )} | ||
*/ | ||
static fromHashes<TDatumStrict_2 = import("@helios-lang/uplc").UplcData, TDatumPermissive_2 = import("@helios-lang/uplc").UplcData, TPaymentRedeemer_2 = import("@helios-lang/uplc").UplcData>(paymentHash: PubKeyHash | ValidatorHash<TDatumStrict_2, TDatumPermissive_2, TPaymentRedeemer_2>, stakingHash: Option<PubKeyHash | StakingValidatorHash>, isTestnet?: boolean): Address<TDatumStrict_2, TDatumPermissive_2, TPaymentRedeemer_2>; | ||
static fromHashes<TSpending_1 extends PubKeyHash | ValidatorHash<any> = PubKeyHash | ValidatorHash<any>, TStaking extends PubKeyHash | StakingValidatorHash<any> = PubKeyHash | StakingValidatorHash<any>>(spendingHash: TSpending_1, stakingHash: Option<TStaking>, isTestnet?: boolean): TSpending_1 extends PubKeyHash ? TStaking extends PubKeyHash ? Address<null, null> : TStaking extends StakingValidatorHash<infer CStaking_1> ? Address<null, CStaking_1> : Address<null, unknown> : TSpending_1 extends ValidatorHash<infer CSpending_2> ? TStaking extends PubKeyHash ? Address<CSpending_2, null> : TStaking extends StakingValidatorHash<infer CStaking_2> ? Address<CSpending_2, CStaking_2> : Address<CSpending_2, unknown> : Address<any, any>; | ||
/** | ||
* Simple payment address with an optional staking hash (`PubKeyHash` or `StakingValidatorHash`). | ||
* @private | ||
* @template {PubKeyHash | StakingValidatorHash} [TStaking=PubKeyHash | StakingValidatorHash] | ||
* @param {PubKeyHash} paymentHash | ||
* @param {Option<PubKeyHash | StakingValidatorHash>} stakingHash | ||
* @param {Option<TStaking>} stakingHash | ||
* @param {boolean} isTestnet | ||
* @returns {Address} | ||
* @returns {( | ||
* TStaking extends PubKeyHash ? Address<null, null> : | ||
* TStaking extends StakingValidatorHash<infer C> ? Address<null, C> : | ||
* Address<null, unknown> | ||
* )} | ||
*/ | ||
@@ -117,9 +119,12 @@ private static fromPubKeyHash; | ||
* @private | ||
* @template [TDatumStrict=UplcData] | ||
* @template [TDatumPermissive=UplcData] | ||
* @template [TPaymentRedeemer=UplcData] | ||
* @param {ValidatorHash<TDatumStrict, TDatumPermissive, TPaymentRedeemer>} paymentHash | ||
* @param {Option<PubKeyHash | StakingValidatorHash>} stakingHash | ||
* @template [CSpending=unknown] | ||
* @param {ValidatorHash<CSpending>} spendingHash | ||
* @template {PubKeyHash | StakingValidatorHash} [TStaking=PubKeyHash | StakingValidatorHash]pytho | ||
* @param {Option<TStaking>} stakingHash | ||
* @param {boolean} isTestnet | ||
* @returns {Address<TDatumStrict, TDatumPermissive, TPaymentRedeemer>} | ||
* @returns {( | ||
* TStaking extends (null | undefined | PubKeyHash) ? Address<CSpending, null> : | ||
* TStaking extends StakingValidatorHash<infer CStaking> ? Address<CSpending, CStaking> : | ||
* Address<CSpending, unknown> | ||
* )} | ||
*/ | ||
@@ -136,6 +141,7 @@ private static fromValidatorHash; | ||
/** | ||
* @param {Exclude<AddressLike, Address>} bytes | ||
* @param {Option<AddressContext<TDatumStrict, TDatumPermissive, TPaymentRedeemer>>} context | ||
* @param {ByteArrayLike} bytes | ||
* @param {Option<CSpending>} spendingContext | ||
* @param {Option<CStaking>} stakingContext | ||
*/ | ||
constructor(bytes: Exclude<AddressLike, Address>, context?: Option<AddressContext<TDatumStrict, TDatumPermissive, TPaymentRedeemer>>); | ||
constructor(bytes: ByteArrayLike, spendingContext?: Option<CSpending>, stakingContext?: Option<CStaking>); | ||
/** | ||
@@ -148,15 +154,14 @@ * @readonly | ||
* @readonly | ||
* @type {PaymentCredential} | ||
* @type {CSpending} | ||
*/ | ||
readonly paymentCredential: PaymentCredential; | ||
readonly spendingContext: CSpending; | ||
/** | ||
* @readonly | ||
* @type {Option<StakingCredential>} | ||
* @type {CStaking} | ||
*/ | ||
readonly stakingCredential: Option<StakingCredential>; | ||
readonly stakingContext: CStaking; | ||
/** | ||
* @readonly | ||
* @type {Option<AddressContext<TDatumStrict, TDatumPermissive, TPaymentRedeemer>>} | ||
* @type {SpendingCredential<SpendingCredentialKind, CSpending>} | ||
*/ | ||
readonly context: Option<AddressContext<TDatumStrict, TDatumPermissive, TPaymentRedeemer>>; | ||
get spendingCredential(): SpendingCredential<import("./SpendingCredential.js").SpendingCredentialKind, CSpending>; | ||
/** | ||
@@ -168,10 +173,14 @@ * Returns the underlying `PubKeyHash` of a simple payment address, or `null` for a script address. | ||
/** | ||
* @type {Option<StakingHash>} | ||
* @type {Option<StakingCredential<StakingHashKind, CStaking>>} | ||
*/ | ||
get stakingHash(): Option<StakingHash<import("../hashes/StakingHash.js").StakingHashKind>>; | ||
get stakingCredential(): Option<StakingCredential<import("./StakingCredential.js").StakingHashKind, CStaking>>; | ||
/** | ||
* @type {Option<StakingHash<StakingHashKind, CStaking>>} | ||
*/ | ||
get stakingHash(): Option<StakingHash<import("./StakingCredential.js").StakingHashKind, CStaking>>; | ||
/** | ||
* Returns the underlying `ValidatorHash` of a script address, or `null` for a regular payment address. | ||
* @type {Option<ValidatorHash>} | ||
* @type {Option<ValidatorHash<CSpending>>} | ||
*/ | ||
get validatorHash(): Option<ValidatorHash<import("@helios-lang/uplc").UplcData, import("@helios-lang/uplc").UplcData, import("@helios-lang/uplc").UplcData>>; | ||
get validatorHash(): Option<ValidatorHash<CSpending>>; | ||
/** | ||
@@ -213,17 +222,11 @@ * @returns {Object} | ||
export type UplcData = import("@helios-lang/uplc").UplcData; | ||
export type Cast<TStrict, TPermissive> = import("../hashes/Cast.js").Cast<TStrict, TPermissive>; | ||
export type StakingHashKind = import("../hashes/index.js").StakingHashKind; | ||
export type SpendingCredentialKind = import("./SpendingCredential.js").SpendingCredentialKind; | ||
export type AddressLike = Address | ByteArrayLike; | ||
export type AddressContext<TDatumStrict, TDatumPermissive, TPaymentRedeemer> = { | ||
paymentProgram: UplcProgramV1 | UplcProgramV2; | ||
datum: Cast<TDatumStrict, TDatumPermissive>; | ||
paymentRedeemer: Cast<any, TPaymentRedeemer>; | ||
}; | ||
import { PaymentCredential } from "./PaymentCredential.js"; | ||
import { SpendingCredential } from "./SpendingCredential.js"; | ||
import { PubKeyHash } from "../hashes/index.js"; | ||
import { StakingCredential } from "./StakingCredential.js"; | ||
import { PubKeyHash } from "../hashes/index.js"; | ||
import { StakingHash } from "../hashes/index.js"; | ||
import { ValidatorHash } from "../hashes/index.js"; | ||
import { StakingValidatorHash } from "../hashes/index.js"; | ||
import { UplcProgramV1 } from "@helios-lang/uplc"; | ||
import { UplcProgramV2 } from "@helios-lang/uplc"; | ||
//# sourceMappingURL=Address.d.ts.map |
@@ -87,3 +87,3 @@ /** | ||
*/ | ||
get credential(): T extends "Register" | "Deregister" | "Delegate" ? StakingCredential : T extends "RegisterPool" | "RetirePool" ? never : Option<StakingCredential>; | ||
get credential(): T extends "Register" | "Deregister" | "Delegate" ? StakingCredential<import("./StakingCredential.js").StakingHashKind, any> : T extends "RegisterPool" | "RetirePool" ? never : Option<StakingCredential<import("./StakingCredential.js").StakingHashKind, any>>; | ||
/** | ||
@@ -90,0 +90,0 @@ * @typedef {"RetirePool"} DCertKindWithEpoch |
export { Address } from "./Address.js"; | ||
export { PaymentCredential as Credential } from "./PaymentCredential.js"; | ||
export { SpendingCredential as Credential } from "./SpendingCredential.js"; | ||
export { DCert } from "./DCert.js"; | ||
@@ -15,3 +15,4 @@ export { StakingCredential } from "./StakingCredential.js"; | ||
export { TxWitnesses } from "./TxWitnesses.js"; | ||
export type SpendingCredentialLike = import("./SpendingCredential.js").SpendingCredentialLike; | ||
export type TxOutputDatumKind = import("./TxOutputDatum.js").TxOutputDatumKind; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -98,3 +98,3 @@ /** | ||
*/ | ||
get stakingHash(): StakingHash<import("../hashes/StakingHash.js").StakingHashKind>; | ||
get stakingHash(): StakingHash<import("./Address.js").StakingHashKind, any>; | ||
/** | ||
@@ -101,0 +101,0 @@ * @param {StakingAddress} other |
/** | ||
* @typedef {import("@helios-lang/uplc").UplcData} UplcData | ||
* @typedef {import("../hashes/index.js").StakingHashKind} StakingHashKind | ||
* @typedef {import("../hashes/index.js").StakingHashLike} StakingHashLike | ||
*/ | ||
/** | ||
* @typedef {StakingCredential | StakingHash | PubKeyHash | StakingValidatorHash} StakingCredentialLike | ||
* @typedef {StakingCredential | StakingHashLike} StakingCredentialLike | ||
*/ | ||
/** | ||
* TODO: implement support for staking pointers | ||
* @template {StakingHashKind} [K=StakingHashKind] | ||
* @template [C=unknown] - optional context | ||
*/ | ||
export class StakingCredential { | ||
export class StakingCredential<K extends import("../hashes/StakingHash.js").StakingHashKind = import("../hashes/StakingHash.js").StakingHashKind, C = unknown> { | ||
/** | ||
* @template [C=unknown] | ||
* @param {number[]} bytes | ||
* @param {Option<C>} context | ||
* @returns {Option<StakingCredential>} | ||
*/ | ||
static fromAddressBytes(bytes: number[]): Option<StakingCredential>; | ||
static fromAddressBytes<C_1 = unknown>(bytes: number[], context?: Option<C_1>): Option<StakingCredential>; | ||
/** | ||
* @param {StakingCredentialLike} arg | ||
* @returns {StakingCredential} | ||
* @template {StakingCredentialLike} T | ||
* @param {T} arg | ||
* @returns {( | ||
* T extends StakingCredential<infer K, infer C> ? StakingCredential<K, C> : | ||
* T extends StakingHash<infer K, infer C> ? StakingCredential<K, C> : | ||
* T extends PubKeyHash ? StakingCredential<"PubKey", null> : | ||
* T extends ValidatorHash<infer C> ? StakingCredential<"Validator", C> : | ||
* StakingCredential | ||
* )} | ||
*/ | ||
static fromAlike(arg: StakingCredentialLike): StakingCredential; | ||
static fromAlike<T extends StakingCredentialLike>(arg: T): T extends StakingCredential<infer K_1 extends import("../hashes/StakingHash.js").StakingHashKind, infer C_2> ? StakingCredential<K_1, C_2> : T extends StakingHash<infer K_2 extends import("../hashes/StakingHash.js").StakingHashKind, infer C_3> ? StakingCredential<K_2, C_3> : T extends PubKeyHash ? StakingCredential<"PubKey", null> : T extends ValidatorHash<infer C_4> ? StakingCredential<"Validator", C_4> : StakingCredential<import("../hashes/StakingHash.js").StakingHashKind, any>; | ||
/** | ||
* @param {UplcData} data | ||
*/ | ||
static fromUplcData(data: UplcData): StakingCredential; | ||
static fromUplcData(data: UplcData): StakingCredential<import("../hashes/StakingHash.js").StakingHashKind, any>; | ||
/** | ||
* @param {Exclude<StakingCredentialLike, StakingCredential>} hash | ||
* @param {StakingHash<K, C>} hash | ||
*/ | ||
constructor(hash: Exclude<StakingCredentialLike, StakingCredential>); | ||
constructor(hash: StakingHash<K, C>); | ||
/** | ||
* @readonly | ||
* @type {StakingHash} | ||
* @type {StakingHash<K, C>} | ||
*/ | ||
readonly hash: StakingHash; | ||
readonly hash: StakingHash<K, C>; | ||
/** | ||
@@ -39,6 +52,10 @@ * @type {number[]} | ||
/** | ||
* @returns {StakingHash} | ||
* @type {C} | ||
*/ | ||
expectStakingHash(): StakingHash; | ||
get context(): C; | ||
/** | ||
* @returns {StakingHash<K, C>} | ||
*/ | ||
expectStakingHash(): StakingHash<K, C>; | ||
/** | ||
* Only valid for Staking hashes | ||
@@ -55,7 +72,9 @@ * XXX: this is quite confusing, if only staking hashes are serialized into transactions, how can staking pointers be available inside the scriptcontext in validators? | ||
export type UplcData = import("@helios-lang/uplc").UplcData; | ||
export type StakingCredentialLike = StakingCredential | StakingHash | PubKeyHash | StakingValidatorHash; | ||
export type StakingHashKind = import("../hashes/index.js").StakingHashKind; | ||
export type StakingHashLike = import("../hashes/index.js").StakingHashLike; | ||
export type StakingCredentialLike = StakingCredential | StakingHashLike; | ||
import { StakingHash } from "../hashes/index.js"; | ||
import { ConstrData } from "@helios-lang/uplc"; | ||
import { PubKeyHash } from "../hashes/index.js"; | ||
import { StakingValidatorHash } from "../hashes/index.js"; | ||
import { ValidatorHash } from "../hashes/index.js"; | ||
//# sourceMappingURL=StakingCredential.d.ts.map |
@@ -13,2 +13,13 @@ /** | ||
*/ | ||
/** | ||
* @template TDatumStrict | ||
* @template TDatumPermissive | ||
* @template TRedeemerStrict | ||
* @template TRedeemerPermissive | ||
* @typedef {import("./SpendingContext.js").SpendingContext<TDatumStrict, TDatumPermissive, TRedeemerStrict, TRedeemerPermissive>} SpendingContext | ||
*/ | ||
/** | ||
* @template T | ||
* @typedef {import("./TxOutputDatum.js").TxOutputDatumCastable<T>} TxOutputDatumCastable | ||
*/ | ||
export class TxBuilder { | ||
@@ -121,3 +132,3 @@ /** | ||
networkParams?: import("../params/NetworkParams.js").NetworkParams | NetworkParamsHelper | undefined; | ||
spareUtxos?: TxInput<import("@helios-lang/uplc").UplcData, import("@helios-lang/uplc").UplcData>[] | undefined; | ||
spareUtxos?: TxInput<any, any>[] | undefined; | ||
}): Tx; | ||
@@ -175,38 +186,31 @@ reset(): void; | ||
/** | ||
* @template TDatumPermissive | ||
* @overload | ||
* @param {Address<any, TDatumPermissive, any>} address | ||
* @param {Address<null, any>} address | ||
* @param {ValueLike} value | ||
* @param {{hash: TDatumPermissive} | {inline: TDatumPermissive}} datum | ||
* @returns {TxBuilder} | ||
* | ||
* @template TDatum | ||
* @overload | ||
* @param {AddressLike} address | ||
* @param {Address<SpendingContext<any, TDatum, any, any>, any>} address | ||
* @param {ValueLike} value | ||
* @param {TxOutputDatumCastable<TDatum>} datum | ||
* @returns {TxBuilder} | ||
* | ||
*/ | ||
pay<TDatum = import("@helios-lang/uplc").UplcData>(address: Address<null, any>, value: ValueLike): TxBuilder; | ||
/** | ||
* @overload | ||
* @param {AddressLike} address | ||
* @param {Address<null, any>} address | ||
* @param {ValueLike} value | ||
* @param {Option<TxOutputDatum>} datum | ||
* @returns {TxBuilder} | ||
* | ||
* @template TDatum | ||
* @overload | ||
* @param {TxOutput | TxOutput[]} output | ||
* @param {Address<SpendingContext<any, TDatum, any, any>, any>} address | ||
* @param {ValueLike} value | ||
* @param {TxOutputDatumCastable<TDatum>} datum | ||
* @returns {TxBuilder} | ||
*/ | ||
pay<TDatumPermissive>(address: Address<any, TDatumPermissive, any>, value: ValueLike, datum: { | ||
hash: TDatumPermissive; | ||
} | { | ||
inline: TDatumPermissive; | ||
}): TxBuilder; | ||
pay<TDatum = import("@helios-lang/uplc").UplcData>(address: Address<SpendingContext<any, TDatum, any, any>, any>, value: ValueLike, datum: TxOutputDatumCastable<TDatum>): TxBuilder; | ||
/** | ||
* @template TDatumPermissive | ||
* @overload | ||
* @param {Address<any, TDatumPermissive, any>} address | ||
* @param {ValueLike} value | ||
* @param {{hash: TDatumPermissive} | {inline: TDatumPermissive}} datum | ||
* @returns {TxBuilder} | ||
* | ||
* @overload | ||
* @param {AddressLike} address | ||
@@ -226,12 +230,5 @@ * @param {ValueLike} value | ||
*/ | ||
pay<TDatumPermissive>(address: AddressLike, value: ValueLike): TxBuilder; | ||
payUnsafe(address: AddressLike, value: ValueLike): TxBuilder; | ||
/** | ||
* @template TDatumPermissive | ||
* @overload | ||
* @param {Address<any, TDatumPermissive, any>} address | ||
* @param {ValueLike} value | ||
* @param {{hash: TDatumPermissive} | {inline: TDatumPermissive}} datum | ||
* @returns {TxBuilder} | ||
* | ||
* @overload | ||
* @param {AddressLike} address | ||
@@ -251,12 +248,5 @@ * @param {ValueLike} value | ||
*/ | ||
pay<TDatumPermissive>(address: AddressLike, value: ValueLike, datum: Option<TxOutputDatum>): TxBuilder; | ||
payUnsafe(address: AddressLike, value: ValueLike, datum: Option<TxOutputDatum>): TxBuilder; | ||
/** | ||
* @template TDatumPermissive | ||
* @overload | ||
* @param {Address<any, TDatumPermissive, any>} address | ||
* @param {ValueLike} value | ||
* @param {{hash: TDatumPermissive} | {inline: TDatumPermissive}} datum | ||
* @returns {TxBuilder} | ||
* | ||
* @overload | ||
* @param {AddressLike} address | ||
@@ -276,3 +266,3 @@ * @param {ValueLike} value | ||
*/ | ||
pay<TDatumPermissive>(output: TxOutput | TxOutput[]): TxBuilder; | ||
payUnsafe(output: TxOutput | TxOutput[]): TxBuilder; | ||
/** | ||
@@ -305,22 +295,28 @@ * Include a reference input | ||
/** | ||
* @template TRedeemer | ||
* @overload | ||
* @param {TxInput<any, TRedeemer> | TxInput<any, TRedeemer>[]} utxos | ||
* @param {TRedeemer} redeemer | ||
* @param {TxInput<null, any> | TxInput<null, any>[]} utxos | ||
* @returns {TxBuilder} | ||
* | ||
* @template TRedeemer | ||
* @overload | ||
* @param {TxInput | TxInput[]} utxos | ||
* @param {Option<UplcData>} redeemer | ||
* @param {TxInput<SpendingContext<any, any, any, TRedeemer>, any> | TxInput<SpendingContext<any, any, any, TRedeemer>, any>[]} utxos | ||
* @param {TRedeemer} redeemer | ||
* @returns {TxBuilder} | ||
*/ | ||
spend<TRedeemer_1>(utxos: TxInput<any, TRedeemer_1> | TxInput<any, TRedeemer_1>[], redeemer: TRedeemer_1): TxBuilder; | ||
spend<TRedeemer_1>(utxos: TxInput<null, any> | TxInput<null, any>[]): TxBuilder; | ||
/** | ||
* @overload | ||
* @param {TxInput<null, any> | TxInput<null, any>[]} utxos | ||
* @returns {TxBuilder} | ||
* | ||
* @template TRedeemer | ||
* @overload | ||
* @param {TxInput<any, TRedeemer> | TxInput<any, TRedeemer>[]} utxos | ||
* @param {TxInput<SpendingContext<any, any, any, TRedeemer>, any> | TxInput<SpendingContext<any, any, any, TRedeemer>, any>[]} utxos | ||
* @param {TRedeemer} redeemer | ||
* @returns {TxBuilder} | ||
* | ||
* @overload | ||
*/ | ||
spend<TRedeemer_1>(utxos: TxInput<SpendingContext<any, any, any, TRedeemer_1>, any> | TxInput<SpendingContext<any, any, any, TRedeemer_1>, any>[], redeemer: TRedeemer_1): TxBuilder; | ||
/** | ||
* Add a UTxO instance as an input to the transaction being built. | ||
* Throws an error if the UTxO is locked at a script address but a redeemer isn't specified (unless the script is a known `NativeScript`). | ||
* @param {TxInput | TxInput[]} utxos | ||
@@ -330,3 +326,3 @@ * @param {Option<UplcData>} redeemer | ||
*/ | ||
spend<TRedeemer_1>(utxos: TxInput | TxInput[], redeemer: Option<UplcData>): TxBuilder; | ||
spendUnsafe(utxos: TxInput | TxInput[], redeemer?: Option<UplcData>): TxBuilder; | ||
/** | ||
@@ -527,3 +523,3 @@ * Set the start of the valid time range by specifying a slot. | ||
private balanceCollateral; | ||
collateralReturn: TxOutput | undefined; | ||
collateralReturn: TxOutput<any, any> | undefined; | ||
/** | ||
@@ -622,2 +618,4 @@ * Calculates fee and balances transaction by sending an output back to changeAddress. | ||
export type TxMetadataAttr = import("./TxMetadataAttr.js").TxMetadataAttr; | ||
export type SpendingContext<TDatumStrict, TDatumPermissive, TRedeemerStrict, TRedeemerPermissive> = import("./SpendingContext.js").SpendingContext<TDatumStrict, TDatumPermissive, TRedeemerStrict, TRedeemerPermissive>; | ||
export type TxOutputDatumCastable<T> = import("./TxOutputDatum.js").TxOutputDatumCastable<T>; | ||
import { Address } from "./Address.js"; | ||
@@ -624,0 +622,0 @@ import { NetworkParamsHelper } from "../params/index.js"; |
@@ -22,6 +22,6 @@ /** | ||
* TxInput represents UTxOs that are available for spending | ||
* @template [TDatum=UplcData] | ||
* @template [TRedeemer=UplcData] | ||
* @template [CSpending=unknown] | ||
* @template [CStaking=unknown] | ||
*/ | ||
export class TxInput<TDatum = import("@helios-lang/uplc").UplcData, TRedeemer = import("@helios-lang/uplc").UplcData> { | ||
export class TxInput<CSpending = unknown, CStaking = unknown> { | ||
/** | ||
@@ -61,6 +61,5 @@ * Decodes either the ledger representation of full representation of a TxInput | ||
* @param {TxOutputId} outputId | ||
* @param {Option<TxOutput>} output - used during building/emulation, not part of serialization | ||
* @param {Option<TxInputContext<TDatum, TRedeemer>>} context | ||
* @param {Option<TxOutput<CSpending, CStaking>>} output - used during building/emulation, not part of serialization | ||
*/ | ||
constructor(outputId: TxOutputId, output?: Option<TxOutput>, context?: Option<TxInputContext<TDatum, TRedeemer>>); | ||
constructor(outputId: TxOutputId, output?: Option<TxOutput<CSpending, CStaking>>); | ||
/** | ||
@@ -72,11 +71,6 @@ * @readonly | ||
/** | ||
* @readonly | ||
* @type {Option<TxInputContext<TDatum, TRedeemer>>} | ||
*/ | ||
readonly context: Option<TxInputContext<TDatum, TRedeemer>>; | ||
/** | ||
* Shortcut | ||
* @type {Address} | ||
* @type {Address<CSpending, CStaking>} | ||
*/ | ||
get address(): Address<import("@helios-lang/uplc").UplcData, import("@helios-lang/uplc").UplcData, import("@helios-lang/uplc").UplcData>; | ||
get address(): Address<CSpending, CStaking>; | ||
/** | ||
@@ -89,6 +83,14 @@ * Shortcut | ||
* Throws an error if the TxInput hasn't been recovered | ||
* @returns {TxOutput} | ||
* @returns {TxOutput<CSpending, CStaking>} | ||
*/ | ||
get output(): TxOutput; | ||
get output(): TxOutput<CSpending, CStaking>; | ||
/** | ||
* @type {CSpending} | ||
*/ | ||
get spendingContext(): CSpending; | ||
/** | ||
* @type {CStaking} | ||
*/ | ||
get stakingContext(): CStaking; | ||
/** | ||
* Shortcut | ||
@@ -95,0 +97,0 @@ * @type {Value} |
@@ -10,4 +10,6 @@ /** | ||
* Represents a transaction output that is used when building a transaction. | ||
* @template [CSpending=unknown] | ||
* @template [CStaking=unknown] | ||
*/ | ||
export class TxOutput { | ||
export class TxOutput<CSpending = unknown, CStaking = unknown> { | ||
/** | ||
@@ -25,3 +27,3 @@ * @param {ByteArrayLike} bytes | ||
* Constructs a `TxOutput` instance using an `Address`, a `Value`, an optional `Datum`, and optional `UplcProgram` reference script. | ||
* @param {AddressLike} address | ||
* @param {Address<CSpending, CStaking>} address | ||
* @param {ValueLike} value | ||
@@ -31,8 +33,8 @@ * @param {Option<TxOutputDatum>} datum | ||
*/ | ||
constructor(address: AddressLike, value: ValueLike, datum?: Option<TxOutputDatum>, refScript?: Option<UplcProgramV1 | UplcProgramV2>); | ||
constructor(address: Address<CSpending, CStaking>, value: ValueLike, datum?: Option<TxOutputDatum>, refScript?: Option<UplcProgramV1 | UplcProgramV2>); | ||
/** | ||
* Mutation is useful when correcting the quantity of lovelace in a utxo | ||
* @type {Address} | ||
* @type {Address<CSpending, CStaking>} | ||
*/ | ||
address: Address; | ||
address: Address<CSpending, CStaking>; | ||
/** | ||
@@ -53,2 +55,10 @@ * Mutation is handy when correcting the quantity of lovelace in a utxo | ||
/** | ||
* @type {CSpending} | ||
*/ | ||
get spendingContext(): CSpending; | ||
/** | ||
* @type {CStaking} | ||
*/ | ||
get stakingContext(): CStaking; | ||
/** | ||
* @returns {Object} | ||
@@ -55,0 +65,0 @@ */ |
@@ -6,5 +6,14 @@ /** | ||
/** | ||
* @template TStrict | ||
* @template TPermissive | ||
* @typedef {import("../hashes/Cast.js").Cast<TStrict, TPermissive>} Cast | ||
*/ | ||
/** | ||
* @typedef {Option<TxOutputDatum> | DatumHash | UplcData} TxOutputDatumLike | ||
*/ | ||
/** | ||
* @template T | ||
* @typedef {{hash: T} | {inline: T}} TxOutputDatumCastable | ||
*/ | ||
/** | ||
* @typedef {"Hash" | "Inline"} TxOutputDatumKind | ||
@@ -53,2 +62,12 @@ */ | ||
/** | ||
* @template T | ||
* @template {TxOutputDatumCastable<T>} D | ||
* @param {D} data | ||
* @param {Cast<any, T>} cast | ||
* @returns {D extends {hash: T} ? TxOutputDatum<"Hash"> : TxOutputDatum<"Inline">} | ||
*/ | ||
static fromCast<T_1, D extends TxOutputDatumCastable<T_1>>(data: D, cast: Cast<any, T_1>): D extends { | ||
hash: T_1; | ||
} ? TxOutputDatum<"Hash"> : TxOutputDatum<"Inline">; | ||
/** | ||
* @param {ByteArrayLike} bytes | ||
@@ -113,3 +132,9 @@ * @returns {TxOutputDatum} | ||
export type UplcData = import("@helios-lang/uplc").UplcData; | ||
export type Cast<TStrict, TPermissive> = import("../hashes/Cast.js").Cast<TStrict, TPermissive>; | ||
export type TxOutputDatumLike = Option<TxOutputDatum> | DatumHash | UplcData; | ||
export type TxOutputDatumCastable<T> = { | ||
hash: T; | ||
} | { | ||
inline: T; | ||
}; | ||
export type TxOutputDatumKind = "Hash" | "Inline"; | ||
@@ -116,0 +141,0 @@ export type TxOutputDatumProps<T extends TxOutputDatumKind> = T extends "Inline" ? { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
650639
327
18869