diff --git a/package-lock.json b/package-lock.json index c3875f14..599ec4c5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "cardano-serialization-lib", - "version": "13.0.0", + "version": "13.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "cardano-serialization-lib", - "version": "13.0.0", + "version": "13.1.0", "hasInstallScript": true, "license": "MIT", "devDependencies": { diff --git a/package.json b/package.json index d0e7eb16..2d44d54a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cardano-serialization-lib", - "version": "13.0.0", + "version": "13.1.0", "description": "(De)serialization functions for the Cardano blockchain along with related utility functions", "scripts": { "rust:build-nodejs": "(rimraf ./rust/pkg && cd rust; wasm-pack build --target=nodejs; cd ..; npm run js:ts-json-gen; cd rust; wasm-pack pack) && npm run js:flowgen", diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 2800caae..40dd2f0e 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cardano-serialization-lib" -version = "13.0.0" +version = "13.1.0" edition = "2018" authors = ["EMURGO"] license = "MIT" diff --git a/rust/json-gen/Cargo.lock b/rust/json-gen/Cargo.lock index 4aa19346..d2422215 100644 --- a/rust/json-gen/Cargo.lock +++ b/rust/json-gen/Cargo.lock @@ -49,7 +49,7 @@ checksum = "a4a45a46ab1f2412e53d3a0ade76ffad2025804294569aae387231a0cd6e0899" [[package]] name = "cardano-serialization-lib" -version = "13.0.0" +version = "13.1.0" dependencies = [ "bech32", "cbor_event", diff --git a/rust/json-gen/src/main.rs b/rust/json-gen/src/main.rs index d22dc080..6f296bde 100644 --- a/rust/json-gen/src/main.rs +++ b/rust/json-gen/src/main.rs @@ -7,6 +7,7 @@ use cardano_serialization_lib::*; macro_rules! gen_json_schema { ($name:ident) => { //let out_dir = std::env::var_os("OUT_DIR").expect("no env"); + println!("Generating schema for {}", stringify!($name)); let dest_path = Path::new(&"schemas").join(&format!("{}.json", stringify!($name))); fs::write(&dest_path, serde_json::to_string_pretty(&schemars::schema_for!($name)).unwrap()).unwrap(); } diff --git a/rust/pkg/cardano_serialization_lib.js.flow b/rust/pkg/cardano_serialization_lib.js.flow index 341da9b2..c0d602bc 100644 --- a/rust/pkg/cardano_serialization_lib.js.flow +++ b/rust/pkg/cardano_serialization_lib.js.flow @@ -18,27 +18,43 @@ declare export function create_send_all( ): TransactionBatchList; /** - * @param {string} password - * @param {string} salt - * @param {string} nonce - * @param {string} data - * @returns {string} + * @param {Uint8Array} bytes + * @returns {TransactionMetadatum} */ -declare export function encrypt_with_password( - password: string, - salt: string, - nonce: string, - data: string -): string; +declare export function encode_arbitrary_bytes_as_metadatum( + bytes: Uint8Array +): TransactionMetadatum; /** - * @param {string} password - * @param {string} data + * @param {TransactionMetadatum} metadata + * @returns {Uint8Array} + */ +declare export function decode_arbitrary_bytes_from_metadatum( + metadata: TransactionMetadatum +): Uint8Array; + +/** + * @param {string} json + * @param {$Values< + typeof + MetadataJsonSchema>} schema + * @returns {TransactionMetadatum} + */ +declare export function encode_json_str_to_metadatum( + json: string, + schema: $Values +): TransactionMetadatum; + +/** + * @param {TransactionMetadatum} metadatum + * @param {$Values< + typeof + MetadataJsonSchema>} schema * @returns {string} */ -declare export function decrypt_with_password( - password: string, - data: string +declare export function decode_metadatum_to_json_str( + metadatum: TransactionMetadatum, + schema: $Values ): string; /** @@ -102,46 +118,6 @@ declare export function decode_plutus_datum_to_json_str( schema: $Values ): string; -/** - * @param {Uint8Array} bytes - * @returns {TransactionMetadatum} - */ -declare export function encode_arbitrary_bytes_as_metadatum( - bytes: Uint8Array -): TransactionMetadatum; - -/** - * @param {TransactionMetadatum} metadata - * @returns {Uint8Array} - */ -declare export function decode_arbitrary_bytes_from_metadatum( - metadata: TransactionMetadatum -): Uint8Array; - -/** - * @param {string} json - * @param {$Values< - typeof - MetadataJsonSchema>} schema - * @returns {TransactionMetadatum} - */ -declare export function encode_json_str_to_metadatum( - json: string, - schema: $Values -): TransactionMetadatum; - -/** - * @param {TransactionMetadatum} metadatum - * @param {$Values< - typeof - MetadataJsonSchema>} schema - * @returns {string} - */ -declare export function decode_metadatum_to_json_str( - metadatum: TransactionMetadatum, - schema: $Values -): string; - /** * @param {TransactionHash} tx_body_hash * @param {ByronAddress} addr @@ -277,39 +253,41 @@ declare export function has_transaction_set_tag( ): $Values; /** + * @param {string} password + * @param {string} salt + * @param {string} nonce + * @param {string} data + * @returns {string} */ - -declare export var CoinSelectionStrategyCIP2: {| - +LargestFirst: 0, // 0 - +RandomImprove: 1, // 1 - +LargestFirstMultiAsset: 2, // 2 - +RandomImproveMultiAsset: 3, // 3 -|}; +declare export function encrypt_with_password( + password: string, + salt: string, + nonce: string, + data: string +): string; /** - * JSON <-> PlutusData conversion schemas. - * Follows ScriptDataJsonSchema in cardano-cli defined at: - * https://github.com/input-output-hk/cardano-node/blob/master/cardano-api/src/Cardano/Api/ScriptData.hs#L254 - * - * All methods here have the following restrictions due to limitations on dependencies: - * * JSON numbers above u64::MAX (positive) or below i64::MIN (negative) will throw errors - * * Hex strings for bytes don't accept odd-length (half-byte) strings. - * cardano-cli seems to support these however but it seems to be different than just 0-padding - * on either side when tested so proceed with caution + * @param {string} password + * @param {string} data + * @returns {string} */ - -declare export var PlutusDatumSchema: {| - +BasicConversions: 0, // 0 - +DetailedSchema: 1, // 1 -|}; +declare export function decrypt_with_password( + password: string, + data: string +): string; /** + * Each new language uses a different namespace for hashing its script + * This is because you could have a language where the same bytes have different semantics + * So this avoids scripts in different languages mapping to the same hash + * Note that the enum value here is different than the enum value for deciding the cost model of a script */ -declare export var RelayKind: {| - +SingleHostAddr: 0, // 0 - +SingleHostName: 1, // 1 - +MultiHostName: 2, // 2 +declare export var ScriptHashNamespace: {| + +NativeScript: 0, // 0 + +PlutusScript: 1, // 1 + +PlutusScriptV2: 2, // 2 + +PlutusScriptV3: 3, // 3 |}; /** @@ -324,53 +302,54 @@ declare export var VoteKind: {| /** */ -declare export var AddressKind: {| - +Base: 0, // 0 - +Pointer: 1, // 1 - +Enterprise: 2, // 2 - +Reward: 3, // 3 - +Byron: 4, // 4 - +Malformed: 5, // 5 +declare export var NativeScriptKind: {| + +ScriptPubkey: 0, // 0 + +ScriptAll: 1, // 1 + +ScriptAny: 2, // 2 + +ScriptNOfK: 3, // 3 + +TimelockStart: 4, // 4 + +TimelockExpiry: 5, // 5 |}; /** - * Each new language uses a different namespace for hashing its script - * This is because you could have a language where the same bytes have different semantics - * So this avoids scripts in different languages mapping to the same hash - * Note that the enum value here is different than the enum value for deciding the cost model of a script */ -declare export var ScriptHashNamespace: {| - +NativeScript: 0, // 0 - +PlutusScript: 1, // 1 - +PlutusScriptV2: 2, // 2 - +PlutusScriptV3: 3, // 3 +declare export var RelayKind: {| + +SingleHostAddr: 0, // 0 + +SingleHostName: 1, // 1 + +MultiHostName: 2, // 2 |}; /** + * Used to choosed the schema for a script JSON string */ -declare export var TransactionSetsState: {| - +AllSetsHaveTag: 0, // 0 - +AllSetsHaveNoTag: 1, // 1 - +MixedSets: 2, // 2 +declare export var ScriptSchema: {| + +Wallet: 0, // 0 + +Node: 1, // 1 |}; /** */ -declare export var CredKind: {| - +Key: 0, // 0 - +Script: 1, // 1 +declare export var CoinSelectionStrategyCIP2: {| + +LargestFirst: 0, // 0 + +RandomImprove: 1, // 1 + +LargestFirstMultiAsset: 2, // 2 + +RandomImproveMultiAsset: 3, // 3 |}; /** - * Used to choosed the schema for a script JSON string */ -declare export var ScriptSchema: {| - +Wallet: 0, // 0 - +Node: 1, // 1 +declare export var GovernanceActionKind: {| + +ParameterChangeAction: 0, // 0 + +HardForkInitiationAction: 1, // 1 + +TreasuryWithdrawalsAction: 2, // 2 + +NoConfidenceAction: 3, // 3 + +UpdateCommitteeAction: 4, // 4 + +NewConstitutionAction: 5, // 5 + +InfoAction: 6, // 6 |}; /** @@ -384,62 +363,51 @@ declare export var CborContainerType: {| /** */ -declare export var RedeemerTagKind: {| - +Spend: 0, // 0 - +Mint: 1, // 1 - +Cert: 2, // 2 +declare export var AddressKind: {| + +Base: 0, // 0 + +Pointer: 1, // 1 + +Enterprise: 2, // 2 +Reward: 3, // 3 - +Vote: 4, // 4 - +VotingProposal: 5, // 5 -|}; - -/** - */ - -declare export var PlutusDataKind: {| - +ConstrPlutusData: 0, // 0 - +Map: 1, // 1 - +List: 2, // 2 - +Integer: 3, // 3 - +Bytes: 4, // 4 + +Byron: 4, // 4 + +Malformed: 5, // 5 |}; /** */ -declare export var DRepKind: {| - +KeyHash: 0, // 0 - +ScriptHash: 1, // 1 - +AlwaysAbstain: 2, // 2 - +AlwaysNoConfidence: 3, // 3 +declare export var MetadataJsonSchema: {| + +NoConversions: 0, // 0 + +BasicConversions: 1, // 1 + +DetailedSchema: 2, // 2 |}; /** */ -declare export var MIRPot: {| - +Reserves: 0, // 0 - +Treasury: 1, // 1 +declare export var MIRKind: {| + +ToOtherPot: 0, // 0 + +ToStakeCredentials: 1, // 1 |}; /** */ -declare export var LanguageKind: {| - +PlutusV1: 0, // 0 - +PlutusV2: 1, // 1 - +PlutusV3: 2, // 2 +declare export var DRepKind: {| + +KeyHash: 0, // 0 + +ScriptHash: 1, // 1 + +AlwaysAbstain: 2, // 2 + +AlwaysNoConfidence: 3, // 3 |}; /** */ -declare export var VoterKind: {| - +ConstitutionalCommitteeHotKeyHash: 0, // 0 - +ConstitutionalCommitteeHotScriptHash: 1, // 1 - +DRepKeyHash: 2, // 2 - +DRepScriptHash: 3, // 3 - +StakingPoolKeyHash: 4, // 4 +declare export var TransactionMetadatumKind: {| + +MetadataMap: 0, // 0 + +MetadataList: 1, // 1 + +Int: 2, // 2 + +Bytes: 3, // 3 + +Text: 4, // 4 |}; /** @@ -453,39 +421,28 @@ declare export var NetworkIdKind: {| /** */ -declare export var TransactionMetadatumKind: {| - +MetadataMap: 0, // 0 - +MetadataList: 1, // 1 - +Int: 2, // 2 - +Bytes: 3, // 3 - +Text: 4, // 4 +declare export var CredKind: {| + +Key: 0, // 0 + +Script: 1, // 1 |}; /** */ -declare export var GovernanceActionKind: {| - +ParameterChangeAction: 0, // 0 - +HardForkInitiationAction: 1, // 1 - +TreasuryWithdrawalsAction: 2, // 2 - +NoConfidenceAction: 3, // 3 - +UpdateCommitteeAction: 4, // 4 - +NewConstitutionAction: 5, // 5 - +InfoAction: 6, // 6 +declare export var PlutusDataKind: {| + +ConstrPlutusData: 0, // 0 + +Map: 1, // 1 + +List: 2, // 2 + +Integer: 3, // 3 + +Bytes: 4, // 4 |}; /** */ -declare export var BlockEra: {| - +Byron: 0, // 0 - +Shelley: 1, // 1 - +Allegra: 2, // 2 - +Mary: 3, // 3 - +Alonzo: 4, // 4 - +Babbage: 5, // 5 - +Conway: 6, // 6 - +Unknown: 7, // 7 +declare export var MIRPot: {| + +Reserves: 0, // 0 + +Treasury: 1, // 1 |}; /** @@ -514,30 +471,56 @@ declare export var CertificateKind: {| /** */ -declare export var MetadataJsonSchema: {| - +NoConversions: 0, // 0 - +BasicConversions: 1, // 1 - +DetailedSchema: 2, // 2 +declare export var TransactionSetsState: {| + +AllSetsHaveTag: 0, // 0 + +AllSetsHaveNoTag: 1, // 1 + +MixedSets: 2, // 2 |}; /** */ -declare export var MIRKind: {| - +ToOtherPot: 0, // 0 - +ToStakeCredentials: 1, // 1 +declare export var BlockEra: {| + +Byron: 0, // 0 + +Shelley: 1, // 1 + +Allegra: 2, // 2 + +Mary: 3, // 3 + +Alonzo: 4, // 4 + +Babbage: 5, // 5 + +Conway: 6, // 6 + +Unknown: 7, // 7 |}; /** */ -declare export var NativeScriptKind: {| - +ScriptPubkey: 0, // 0 - +ScriptAll: 1, // 1 - +ScriptAny: 2, // 2 - +ScriptNOfK: 3, // 3 - +TimelockStart: 4, // 4 - +TimelockExpiry: 5, // 5 +declare export var RedeemerTagKind: {| + +Spend: 0, // 0 + +Mint: 1, // 1 + +Cert: 2, // 2 + +Reward: 3, // 3 + +Vote: 4, // 4 + +VotingProposal: 5, // 5 +|}; + +/** + */ + +declare export var LanguageKind: {| + +PlutusV1: 0, // 0 + +PlutusV2: 1, // 1 + +PlutusV3: 2, // 2 +|}; + +/** + */ + +declare export var VoterKind: {| + +ConstitutionalCommitteeHotKeyHash: 0, // 0 + +ConstitutionalCommitteeHotScriptHash: 1, // 1 + +DRepKeyHash: 2, // 2 + +DRepScriptHash: 3, // 3 + +StakingPoolKeyHash: 4, // 4 |}; /** @@ -548,6 +531,23 @@ declare export var CborSetType: {| +Untagged: 1, // 1 |}; +/** + * JSON <-> PlutusData conversion schemas. + * Follows ScriptDataJsonSchema in cardano-cli defined at: + * https://github.com/input-output-hk/cardano-node/blob/master/cardano-api/src/Cardano/Api/ScriptData.hs#L254 + * + * All methods here have the following restrictions due to limitations on dependencies: + * * JSON numbers above u64::MAX (positive) or below i64::MIN (negative) will throw errors + * * Hex strings for bytes don't accept odd-length (half-byte) strings. + * cardano-cli seems to support these however but it seems to be different than just 0-padding + * on either side when tested so proceed with caution + */ + +declare export var PlutusDatumSchema: {| + +BasicConversions: 0, // 0 + +DetailedSchema: 1, // 1 +|}; + /** */ declare export class Address { @@ -565,9 +565,9 @@ declare export class Address { to_json(): string; /** - * @returns {any} + * @returns {AddressJSON} */ - to_js_value(): any; + to_js_value(): AddressJSON; /** * @param {string} json @@ -658,9 +658,9 @@ declare export class Anchor { to_json(): string; /** - * @returns {any} + * @returns {AnchorJSON} */ - to_js_value(): any; + to_js_value(): AnchorJSON; /** * @param {string} json @@ -757,9 +757,9 @@ declare export class AssetName { to_json(): string; /** - * @returns {any} + * @returns {AssetNameJSON} */ - to_js_value(): any; + to_js_value(): AssetNameJSON; /** * @param {string} json @@ -811,9 +811,9 @@ declare export class AssetNames { to_json(): string; /** - * @returns {any} + * @returns {AssetNamesJSON} */ - to_js_value(): any; + to_js_value(): AssetNamesJSON; /** * @param {string} json @@ -875,9 +875,9 @@ declare export class Assets { to_json(): string; /** - * @returns {any} + * @returns {AssetsJSON} */ - to_js_value(): any; + to_js_value(): AssetsJSON; /** * @param {string} json @@ -946,9 +946,9 @@ declare export class AuxiliaryData { to_json(): string; /** - * @returns {any} + * @returns {AuxiliaryDataJSON} */ - to_js_value(): any; + to_js_value(): AuxiliaryDataJSON; /** * @param {string} json @@ -1149,9 +1149,9 @@ declare export class BigInt { to_json(): string; /** - * @returns {any} + * @returns {BigIntJSON} */ - to_js_value(): any; + to_js_value(): BigIntJSON; /** * @param {string} json @@ -1274,9 +1274,9 @@ declare export class BigNum { to_json(): string; /** - * @returns {any} + * @returns {BigNumJSON} */ - to_js_value(): any; + to_js_value(): BigNumJSON; /** * @param {string} json @@ -1587,9 +1587,9 @@ declare export class Block { to_json(): string; /** - * @returns {any} + * @returns {BlockJSON} */ - to_js_value(): any; + to_js_value(): BlockJSON; /** * @param {string} json @@ -1710,9 +1710,9 @@ declare export class BootstrapWitness { to_json(): string; /** - * @returns {any} + * @returns {BootstrapWitnessJSON} */ - to_js_value(): any; + to_js_value(): BootstrapWitnessJSON; /** * @param {string} json @@ -1787,9 +1787,9 @@ declare export class BootstrapWitnesses { to_json(): string; /** - * @returns {any} + * @returns {BootstrapWitnessesJSON} */ - to_js_value(): any; + to_js_value(): BootstrapWitnessesJSON; /** * @param {string} json @@ -1925,9 +1925,9 @@ declare export class Certificate { to_json(): string; /** - * @returns {any} + * @returns {CertificateJSON} */ - to_js_value(): any; + to_js_value(): CertificateJSON; /** * @param {string} json @@ -2227,9 +2227,9 @@ declare export class Certificates { to_json(): string; /** - * @returns {any} + * @returns {CertificatesJSON} */ - to_js_value(): any; + to_js_value(): CertificatesJSON; /** * @param {string} json @@ -2392,9 +2392,9 @@ declare export class Committee { to_json(): string; /** - * @returns {any} + * @returns {CommitteeJSON} */ - to_js_value(): any; + to_js_value(): CommitteeJSON; /** * @param {string} json @@ -2463,9 +2463,9 @@ declare export class CommitteeColdResign { to_json(): string; /** - * @returns {any} + * @returns {CommitteeColdResignJSON} */ - to_js_value(): any; + to_js_value(): CommitteeColdResignJSON; /** * @param {string} json @@ -2537,9 +2537,9 @@ declare export class CommitteeHotAuth { to_json(): string; /** - * @returns {any} + * @returns {CommitteeHotAuthJSON} */ - to_js_value(): any; + to_js_value(): CommitteeHotAuthJSON; /** * @param {string} json @@ -2605,9 +2605,9 @@ declare export class Constitution { to_json(): string; /** - * @returns {any} + * @returns {ConstitutionJSON} */ - to_js_value(): any; + to_js_value(): ConstitutionJSON; /** * @param {string} json @@ -2718,9 +2718,9 @@ declare export class CostModel { to_json(): string; /** - * @returns {any} + * @returns {CostModelJSON} */ - to_js_value(): any; + to_js_value(): CostModelJSON; /** * @param {string} json @@ -2788,9 +2788,9 @@ declare export class Costmdls { to_json(): string; /** - * @returns {any} + * @returns {CostmdlsJSON} */ - to_js_value(): any; + to_js_value(): CostmdlsJSON; /** * @param {string} json @@ -2899,9 +2899,9 @@ declare export class Credential { to_json(): string; /** - * @returns {any} + * @returns {CredentialJSON} */ - to_js_value(): any; + to_js_value(): CredentialJSON; /** * @param {string} json @@ -2942,9 +2942,9 @@ declare export class Credentials { to_json(): string; /** - * @returns {any} + * @returns {CredentialsJSON} */ - to_js_value(): any; + to_js_value(): CredentialsJSON; /** * @param {string} json @@ -3009,9 +3009,9 @@ declare export class DNSRecordAorAAAA { to_json(): string; /** - * @returns {any} + * @returns {DNSRecordAorAAAAJSON} */ - to_js_value(): any; + to_js_value(): DNSRecordAorAAAAJSON; /** * @param {string} json @@ -3063,9 +3063,9 @@ declare export class DNSRecordSRV { to_json(): string; /** - * @returns {any} + * @returns {DNSRecordSRVJSON} */ - to_js_value(): any; + to_js_value(): DNSRecordSRVJSON; /** * @param {string} json @@ -3117,9 +3117,9 @@ declare export class DRep { to_json(): string; /** - * @returns {any} + * @returns {DRepJSON} */ - to_js_value(): any; + to_js_value(): DRepJSON; /** * @param {string} json @@ -3216,9 +3216,9 @@ declare export class DRepDeregistration { to_json(): string; /** - * @returns {any} + * @returns {DRepDeregistrationJSON} */ - to_js_value(): any; + to_js_value(): DRepDeregistrationJSON; /** * @param {string} json @@ -3281,9 +3281,9 @@ declare export class DRepRegistration { to_json(): string; /** - * @returns {any} + * @returns {DRepRegistrationJSON} */ - to_js_value(): any; + to_js_value(): DRepRegistrationJSON; /** * @param {string} json @@ -3363,9 +3363,9 @@ declare export class DRepUpdate { to_json(): string; /** - * @returns {any} + * @returns {DRepUpdateJSON} */ - to_js_value(): any; + to_js_value(): DRepUpdateJSON; /** * @param {string} json @@ -3437,9 +3437,9 @@ declare export class DRepVotingThresholds { to_json(): string; /** - * @returns {any} + * @returns {DRepVotingThresholdsJSON} */ - to_js_value(): any; + to_js_value(): DRepVotingThresholdsJSON; /** * @param {string} json @@ -3717,9 +3717,9 @@ declare export class Ed25519KeyHashes { to_json(): string; /** - * @returns {any} + * @returns {Ed25519KeyHashesJSON} */ - to_js_value(): any; + to_js_value(): Ed25519KeyHashesJSON; /** * @param {string} json @@ -3866,9 +3866,9 @@ declare export class ExUnitPrices { to_json(): string; /** - * @returns {any} + * @returns {ExUnitPricesJSON} */ - to_js_value(): any; + to_js_value(): ExUnitPricesJSON; /** * @param {string} json @@ -3926,9 +3926,9 @@ declare export class ExUnits { to_json(): string; /** - * @returns {any} + * @returns {ExUnitsJSON} */ - to_js_value(): any; + to_js_value(): ExUnitsJSON; /** * @param {string} json @@ -4329,9 +4329,9 @@ declare export class GeneralTransactionMetadata { to_json(): string; /** - * @returns {any} + * @returns {GeneralTransactionMetadataJSON} */ - to_js_value(): any; + to_js_value(): GeneralTransactionMetadataJSON; /** * @param {string} json @@ -4478,9 +4478,9 @@ declare export class GenesisHashes { to_json(): string; /** - * @returns {any} + * @returns {GenesisHashesJSON} */ - to_js_value(): any; + to_js_value(): GenesisHashesJSON; /** * @param {string} json @@ -4542,9 +4542,9 @@ declare export class GenesisKeyDelegation { to_json(): string; /** - * @returns {any} + * @returns {GenesisKeyDelegationJSON} */ - to_js_value(): any; + to_js_value(): GenesisKeyDelegationJSON; /** * @param {string} json @@ -4612,9 +4612,9 @@ declare export class GovernanceAction { to_json(): string; /** - * @returns {any} + * @returns {GovernanceActionJSON} */ - to_js_value(): any; + to_js_value(): GovernanceActionJSON; /** * @param {string} json @@ -4751,9 +4751,9 @@ declare export class GovernanceActionId { to_json(): string; /** - * @returns {any} + * @returns {GovernanceActionIdJSON} */ - to_js_value(): any; + to_js_value(): GovernanceActionIdJSON; /** * @param {string} json @@ -4792,9 +4792,9 @@ declare export class GovernanceActionIds { to_json(): string; /** - * @returns {any} + * @returns {GovernanceActionIdsJSON} */ - to_js_value(): any; + to_js_value(): GovernanceActionIdsJSON; /** * @param {string} json @@ -4856,9 +4856,9 @@ declare export class HardForkInitiationAction { to_json(): string; /** - * @returns {any} + * @returns {HardForkInitiationActionJSON} */ - to_js_value(): any; + to_js_value(): HardForkInitiationActionJSON; /** * @param {string} json @@ -4925,9 +4925,9 @@ declare export class Header { to_json(): string; /** - * @returns {any} + * @returns {HeaderJSON} */ - to_js_value(): any; + to_js_value(): HeaderJSON; /** * @param {string} json @@ -4985,9 +4985,9 @@ declare export class HeaderBody { to_json(): string; /** - * @returns {any} + * @returns {HeaderBodyJSON} */ - to_js_value(): any; + to_js_value(): HeaderBodyJSON; /** * @param {string} json @@ -5179,9 +5179,9 @@ declare export class Int { to_json(): string; /** - * @returns {any} + * @returns {IntJSON} */ - to_js_value(): any; + to_js_value(): IntJSON; /** * @param {string} json @@ -5302,9 +5302,9 @@ declare export class Ipv4 { to_json(): string; /** - * @returns {any} + * @returns {Ipv4JSON} */ - to_js_value(): any; + to_js_value(): Ipv4JSON; /** * @param {string} json @@ -5356,9 +5356,9 @@ declare export class Ipv6 { to_json(): string; /** - * @returns {any} + * @returns {Ipv6JSON} */ - to_js_value(): any; + to_js_value(): Ipv6JSON; /** * @param {string} json @@ -5465,9 +5465,9 @@ declare export class Language { to_json(): string; /** - * @returns {any} + * @returns {LanguageJSON} */ - to_js_value(): any; + to_js_value(): LanguageJSON; /** * @param {string} json @@ -5604,9 +5604,9 @@ declare export class MIRToStakeCredentials { to_json(): string; /** - * @returns {any} + * @returns {MIRToStakeCredentialsJSON} */ - to_js_value(): any; + to_js_value(): MIRToStakeCredentialsJSON; /** * @param {string} json @@ -5840,9 +5840,9 @@ declare export class Mint { to_json(): string; /** - * @returns {any} + * @returns {MintJSON} */ - to_js_value(): any; + to_js_value(): MintJSON; /** * @param {string} json @@ -6028,9 +6028,9 @@ declare export class MintsAssets { to_json(): string; /** - * @returns {any} + * @returns {MintsAssetsJSON} */ - to_js_value(): any; + to_js_value(): MintsAssetsJSON; /** * @param {string} json @@ -6092,9 +6092,9 @@ declare export class MoveInstantaneousReward { to_json(): string; /** - * @returns {any} + * @returns {MoveInstantaneousRewardJSON} */ - to_js_value(): any; + to_js_value(): MoveInstantaneousRewardJSON; /** * @param {string} json @@ -6183,9 +6183,9 @@ declare export class MoveInstantaneousRewardsCert { to_json(): string; /** - * @returns {any} + * @returns {MoveInstantaneousRewardsCertJSON} */ - to_js_value(): any; + to_js_value(): MoveInstantaneousRewardsCertJSON; /** * @param {string} json @@ -6239,9 +6239,9 @@ declare export class MultiAsset { to_json(): string; /** - * @returns {any} + * @returns {MultiAssetJSON} */ - to_js_value(): any; + to_js_value(): MultiAssetJSON; /** * @param {string} json @@ -6345,9 +6345,9 @@ declare export class MultiHostName { to_json(): string; /** - * @returns {any} + * @returns {MultiHostNameJSON} */ - to_js_value(): any; + to_js_value(): MultiHostNameJSON; /** * @param {string} json @@ -6399,9 +6399,9 @@ declare export class NativeScript { to_json(): string; /** - * @returns {any} + * @returns {NativeScriptJSON} */ - to_js_value(): any; + to_js_value(): NativeScriptJSON; /** * @param {string} json @@ -6582,9 +6582,9 @@ declare export class NativeScripts { to_json(): string; /** - * @returns {any} + * @returns {NativeScriptsJSON} */ - to_js_value(): any; + to_js_value(): NativeScriptsJSON; /** * @param {string} json @@ -6625,9 +6625,9 @@ declare export class NetworkId { to_json(): string; /** - * @returns {any} + * @returns {NetworkIdJSON} */ - to_js_value(): any; + to_js_value(): NetworkIdJSON; /** * @param {string} json @@ -6722,9 +6722,9 @@ declare export class NewConstitutionAction { to_json(): string; /** - * @returns {any} + * @returns {NewConstitutionActionJSON} */ - to_js_value(): any; + to_js_value(): NewConstitutionActionJSON; /** * @param {string} json @@ -6796,9 +6796,9 @@ declare export class NoConfidenceAction { to_json(): string; /** - * @returns {any} + * @returns {NoConfidenceActionJSON} */ - to_js_value(): any; + to_js_value(): NoConfidenceActionJSON; /** * @param {string} json @@ -6857,9 +6857,9 @@ declare export class Nonce { to_json(): string; /** - * @returns {any} + * @returns {NonceJSON} */ - to_js_value(): any; + to_js_value(): NonceJSON; /** * @param {string} json @@ -6916,9 +6916,9 @@ declare export class OperationalCert { to_json(): string; /** - * @returns {any} + * @returns {OperationalCertJSON} */ - to_js_value(): any; + to_js_value(): OperationalCertJSON; /** * @param {string} json @@ -7020,9 +7020,9 @@ declare export class ParameterChangeAction { to_json(): string; /** - * @returns {any} + * @returns {ParameterChangeActionJSON} */ - to_js_value(): any; + to_js_value(): ParameterChangeActionJSON; /** * @param {string} json @@ -7218,6 +7218,12 @@ declare export class PlutusData { * @returns {PlutusData} */ static from_address(address: Address): PlutusData; + + /** + * @param {NetworkInfo} network + * @returns {Address} + */ + as_address(network: NetworkInfo): Address; } /** */ @@ -7225,47 +7231,47 @@ declare export class PlutusList { free(): void; /** - * @returns {PlutusList} + * @returns {Uint8Array} */ - static new(): PlutusList; + to_bytes(): Uint8Array; /** - * @returns {number} + * @param {Uint8Array} bytes + * @returns {PlutusList} */ - len(): number; + static from_bytes(bytes: Uint8Array): PlutusList; /** - * @param {number} index - * @returns {PlutusData} + * @returns {string} */ - get(index: number): PlutusData; + to_hex(): string; /** - * @param {PlutusData} elem + * @param {string} hex_str + * @returns {PlutusList} */ - add(elem: PlutusData): void; + static from_hex(hex_str: string): PlutusList; /** - * @returns {Uint8Array} + * @returns {PlutusList} */ - to_bytes(): Uint8Array; + static new(): PlutusList; /** - * @param {Uint8Array} bytes - * @returns {PlutusList} + * @returns {number} */ - static from_bytes(bytes: Uint8Array): PlutusList; + len(): number; /** - * @returns {string} + * @param {number} index + * @returns {PlutusData} */ - to_hex(): string; + get(index: number): PlutusData; /** - * @param {string} hex_str - * @returns {PlutusList} + * @param {PlutusData} elem */ - static from_hex(hex_str: string): PlutusList; + add(elem: PlutusData): void; } /** */ @@ -7541,9 +7547,9 @@ declare export class PlutusScripts { to_json(): string; /** - * @returns {any} + * @returns {PlutusScriptsJSON} */ - to_js_value(): any; + to_js_value(): PlutusScriptsJSON; /** * @param {string} json @@ -7796,9 +7802,9 @@ declare export class PoolMetadata { to_json(): string; /** - * @returns {any} + * @returns {PoolMetadataJSON} */ - to_js_value(): any; + to_js_value(): PoolMetadataJSON; /** * @param {string} json @@ -7895,9 +7901,9 @@ declare export class PoolParams { to_json(): string; /** - * @returns {any} + * @returns {PoolParamsJSON} */ - to_js_value(): any; + to_js_value(): PoolParamsJSON; /** * @param {string} json @@ -8007,9 +8013,9 @@ declare export class PoolRegistration { to_json(): string; /** - * @returns {any} + * @returns {PoolRegistrationJSON} */ - to_js_value(): any; + to_js_value(): PoolRegistrationJSON; /** * @param {string} json @@ -8061,9 +8067,9 @@ declare export class PoolRetirement { to_json(): string; /** - * @returns {any} + * @returns {PoolRetirementJSON} */ - to_js_value(): any; + to_js_value(): PoolRetirementJSON; /** * @param {string} json @@ -8121,9 +8127,9 @@ declare export class PoolVotingThresholds { to_json(): string; /** - * @returns {any} + * @returns {PoolVotingThresholdsJSON} */ - to_js_value(): any; + to_js_value(): PoolVotingThresholdsJSON; /** * @param {string} json @@ -8278,9 +8284,9 @@ declare export class ProposedProtocolParameterUpdates { to_json(): string; /** - * @returns {any} + * @returns {ProposedProtocolParameterUpdatesJSON} */ - to_js_value(): any; + to_js_value(): ProposedProtocolParameterUpdatesJSON; /** * @param {string} json @@ -8352,9 +8358,9 @@ declare export class ProtocolParamUpdate { to_json(): string; /** - * @returns {any} + * @returns {ProtocolParamUpdateJSON} */ - to_js_value(): any; + to_js_value(): ProtocolParamUpdateJSON; /** * @param {string} json @@ -8732,9 +8738,9 @@ declare export class ProtocolVersion { to_json(): string; /** - * @returns {any} + * @returns {ProtocolVersionJSON} */ - to_js_value(): any; + to_js_value(): ProtocolVersionJSON; /** * @param {string} json @@ -8873,9 +8879,9 @@ declare export class Redeemer { to_json(): string; /** - * @returns {any} + * @returns {RedeemerJSON} */ - to_js_value(): any; + to_js_value(): RedeemerJSON; /** * @param {string} json @@ -8950,9 +8956,9 @@ declare export class RedeemerTag { to_json(): string; /** - * @returns {any} + * @returns {RedeemerTagJSON} */ - to_js_value(): any; + to_js_value(): RedeemerTagJSON; /** * @param {string} json @@ -9030,9 +9036,9 @@ declare export class Redeemers { to_json(): string; /** - * @returns {any} + * @returns {RedeemersJSON} */ - to_js_value(): any; + to_js_value(): RedeemersJSON; /** * @param {string} json @@ -9107,9 +9113,9 @@ declare export class Relay { to_json(): string; /** - * @returns {any} + * @returns {RelayJSON} */ - to_js_value(): any; + to_js_value(): RelayJSON; /** * @param {string} json @@ -9190,9 +9196,9 @@ declare export class Relays { to_json(): string; /** - * @returns {any} + * @returns {RelaysJSON} */ - to_js_value(): any; + to_js_value(): RelaysJSON; /** * @param {string} json @@ -9287,9 +9293,9 @@ declare export class RewardAddresses { to_json(): string; /** - * @returns {any} + * @returns {RewardAddressesJSON} */ - to_js_value(): any; + to_js_value(): RewardAddressesJSON; /** * @param {string} json @@ -9351,9 +9357,9 @@ declare export class ScriptAll { to_json(): string; /** - * @returns {any} + * @returns {ScriptAllJSON} */ - to_js_value(): any; + to_js_value(): ScriptAllJSON; /** * @param {string} json @@ -9405,9 +9411,9 @@ declare export class ScriptAny { to_json(): string; /** - * @returns {any} + * @returns {ScriptAnyJSON} */ - to_js_value(): any; + to_js_value(): ScriptAnyJSON; /** * @param {string} json @@ -9537,9 +9543,9 @@ declare export class ScriptHashes { to_json(): string; /** - * @returns {any} + * @returns {ScriptHashesJSON} */ - to_js_value(): any; + to_js_value(): ScriptHashesJSON; /** * @param {string} json @@ -9601,9 +9607,9 @@ declare export class ScriptNOfK { to_json(): string; /** - * @returns {any} + * @returns {ScriptNOfKJSON} */ - to_js_value(): any; + to_js_value(): ScriptNOfKJSON; /** * @param {string} json @@ -9661,9 +9667,9 @@ declare export class ScriptPubkey { to_json(): string; /** - * @returns {any} + * @returns {ScriptPubkeyJSON} */ - to_js_value(): any; + to_js_value(): ScriptPubkeyJSON; /** * @param {string} json @@ -9715,9 +9721,9 @@ declare export class ScriptRef { to_json(): string; /** - * @returns {any} + * @returns {ScriptRefJSON} */ - to_js_value(): any; + to_js_value(): ScriptRefJSON; /** * @param {string} json @@ -9798,9 +9804,9 @@ declare export class SingleHostAddr { to_json(): string; /** - * @returns {any} + * @returns {SingleHostAddrJSON} */ - to_js_value(): any; + to_js_value(): SingleHostAddrJSON; /** * @param {string} json @@ -9864,9 +9870,9 @@ declare export class SingleHostName { to_json(): string; /** - * @returns {any} + * @returns {SingleHostNameJSON} */ - to_js_value(): any; + to_js_value(): SingleHostNameJSON; /** * @param {string} json @@ -9924,9 +9930,9 @@ declare export class StakeAndVoteDelegation { to_json(): string; /** - * @returns {any} + * @returns {StakeAndVoteDelegationJSON} */ - to_js_value(): any; + to_js_value(): StakeAndVoteDelegationJSON; /** * @param {string} json @@ -9999,9 +10005,9 @@ declare export class StakeDelegation { to_json(): string; /** - * @returns {any} + * @returns {StakeDelegationJSON} */ - to_js_value(): any; + to_js_value(): StakeDelegationJSON; /** * @param {string} json @@ -10067,9 +10073,9 @@ declare export class StakeDeregistration { to_json(): string; /** - * @returns {any} + * @returns {StakeDeregistrationJSON} */ - to_js_value(): any; + to_js_value(): StakeDeregistrationJSON; /** * @param {string} json @@ -10141,9 +10147,9 @@ declare export class StakeRegistration { to_json(): string; /** - * @returns {any} + * @returns {StakeRegistrationJSON} */ - to_js_value(): any; + to_js_value(): StakeRegistrationJSON; /** * @param {string} json @@ -10215,9 +10221,9 @@ declare export class StakeRegistrationAndDelegation { to_json(): string; /** - * @returns {any} + * @returns {StakeRegistrationAndDelegationJSON} */ - to_js_value(): any; + to_js_value(): StakeRegistrationAndDelegationJSON; /** * @param {string} json @@ -10290,9 +10296,9 @@ declare export class StakeVoteRegistrationAndDelegation { to_json(): string; /** - * @returns {any} + * @returns {StakeVoteRegistrationAndDelegationJSON} */ - to_js_value(): any; + to_js_value(): StakeVoteRegistrationAndDelegationJSON; /** * @param {string} json @@ -10398,9 +10404,9 @@ declare export class TimelockExpiry { to_json(): string; /** - * @returns {any} + * @returns {TimelockExpiryJSON} */ - to_js_value(): any; + to_js_value(): TimelockExpiryJSON; /** * @param {string} json @@ -10466,9 +10472,9 @@ declare export class TimelockStart { to_json(): string; /** - * @returns {any} + * @returns {TimelockStartJSON} */ - to_js_value(): any; + to_js_value(): TimelockStartJSON; /** * @param {string} json @@ -10538,9 +10544,9 @@ declare export class Transaction { to_json(): string; /** - * @returns {any} + * @returns {TransactionJSON} */ - to_js_value(): any; + to_js_value(): TransactionJSON; /** * @param {string} json @@ -10650,9 +10656,9 @@ declare export class TransactionBodies { to_json(): string; /** - * @returns {any} + * @returns {TransactionBodiesJSON} */ - to_js_value(): any; + to_js_value(): TransactionBodiesJSON; /** * @param {string} json @@ -10714,9 +10720,9 @@ declare export class TransactionBody { to_json(): string; /** - * @returns {any} + * @returns {TransactionBodyJSON} */ - to_js_value(): any; + to_js_value(): TransactionBodyJSON; /** * @param {string} json @@ -11776,9 +11782,9 @@ declare export class TransactionInput { to_json(): string; /** - * @returns {any} + * @returns {TransactionInputJSON} */ - to_js_value(): any; + to_js_value(): TransactionInputJSON; /** * @param {string} json @@ -11836,9 +11842,9 @@ declare export class TransactionInputs { to_json(): string; /** - * @returns {any} + * @returns {TransactionInputsJSON} */ - to_js_value(): any; + to_js_value(): TransactionInputsJSON; /** * @param {string} json @@ -12045,9 +12051,9 @@ declare export class TransactionOutput { to_json(): string; /** - * @returns {any} + * @returns {TransactionOutputJSON} */ - to_js_value(): any; + to_js_value(): TransactionOutputJSON; /** * @param {string} json @@ -12243,9 +12249,9 @@ declare export class TransactionOutputs { to_json(): string; /** - * @returns {any} + * @returns {TransactionOutputsJSON} */ - to_js_value(): any; + to_js_value(): TransactionOutputsJSON; /** * @param {string} json @@ -12307,9 +12313,9 @@ declare export class TransactionUnspentOutput { to_json(): string; /** - * @returns {any} + * @returns {TransactionUnspentOutputJSON} */ - to_js_value(): any; + to_js_value(): TransactionUnspentOutputJSON; /** * @param {string} json @@ -12348,9 +12354,9 @@ declare export class TransactionUnspentOutputs { to_json(): string; /** - * @returns {any} + * @returns {TransactionUnspentOutputsJSON} */ - to_js_value(): any; + to_js_value(): TransactionUnspentOutputsJSON; /** * @param {string} json @@ -12412,9 +12418,9 @@ declare export class TransactionWitnessSet { to_json(): string; /** - * @returns {any} + * @returns {TransactionWitnessSetJSON} */ - to_js_value(): any; + to_js_value(): TransactionWitnessSetJSON; /** * @param {string} json @@ -12520,9 +12526,9 @@ declare export class TransactionWitnessSets { to_json(): string; /** - * @returns {any} + * @returns {TransactionWitnessSetsJSON} */ - to_js_value(): any; + to_js_value(): TransactionWitnessSetsJSON; /** * @param {string} json @@ -12562,9 +12568,9 @@ declare export class TreasuryWithdrawals { to_json(): string; /** - * @returns {any} + * @returns {TreasuryWithdrawalsJSON} */ - to_js_value(): any; + to_js_value(): TreasuryWithdrawalsJSON; /** * @param {string} json @@ -12632,9 +12638,9 @@ declare export class TreasuryWithdrawalsAction { to_json(): string; /** - * @returns {any} + * @returns {TreasuryWithdrawalsActionJSON} */ - to_js_value(): any; + to_js_value(): TreasuryWithdrawalsActionJSON; /** * @param {string} json @@ -12845,9 +12851,9 @@ declare export class URL { to_json(): string; /** - * @returns {any} + * @returns {URLJSON} */ - to_js_value(): any; + to_js_value(): URLJSON; /** * @param {string} json @@ -12899,9 +12905,9 @@ declare export class UnitInterval { to_json(): string; /** - * @returns {any} + * @returns {UnitIntervalJSON} */ - to_js_value(): any; + to_js_value(): UnitIntervalJSON; /** * @param {string} json @@ -12959,9 +12965,9 @@ declare export class Update { to_json(): string; /** - * @returns {any} + * @returns {UpdateJSON} */ - to_js_value(): any; + to_js_value(): UpdateJSON; /** * @param {string} json @@ -13022,9 +13028,9 @@ declare export class UpdateCommitteeAction { to_json(): string; /** - * @returns {any} + * @returns {UpdateCommitteeActionJSON} */ - to_js_value(): any; + to_js_value(): UpdateCommitteeActionJSON; /** * @param {string} json @@ -13102,9 +13108,9 @@ declare export class VRFCert { to_json(): string; /** - * @returns {any} + * @returns {VRFCertJSON} */ - to_js_value(): any; + to_js_value(): VRFCertJSON; /** * @param {string} json @@ -13240,9 +13246,9 @@ declare export class Value { to_json(): string; /** - * @returns {any} + * @returns {ValueJSON} */ - to_js_value(): any; + to_js_value(): ValueJSON; /** * @param {string} json @@ -13357,9 +13363,9 @@ declare export class VersionedBlock { to_json(): string; /** - * @returns {any} + * @returns {VersionedBlockJSON} */ - to_js_value(): any; + to_js_value(): VersionedBlockJSON; /** * @param {string} json @@ -13419,9 +13425,9 @@ declare export class Vkey { to_json(): string; /** - * @returns {any} + * @returns {VkeyJSON} */ - to_js_value(): any; + to_js_value(): VkeyJSON; /** * @param {string} json @@ -13499,9 +13505,9 @@ declare export class Vkeywitness { to_json(): string; /** - * @returns {any} + * @returns {VkeywitnessJSON} */ - to_js_value(): any; + to_js_value(): VkeywitnessJSON; /** * @param {string} json @@ -13559,9 +13565,9 @@ declare export class Vkeywitnesses { to_json(): string; /** - * @returns {any} + * @returns {VkeywitnessesJSON} */ - to_js_value(): any; + to_js_value(): VkeywitnessesJSON; /** * @param {string} json @@ -13626,9 +13632,9 @@ declare export class VoteDelegation { to_json(): string; /** - * @returns {any} + * @returns {VoteDelegationJSON} */ - to_js_value(): any; + to_js_value(): VoteDelegationJSON; /** * @param {string} json @@ -13691,9 +13697,9 @@ declare export class VoteRegistrationAndDelegation { to_json(): string; /** - * @returns {any} + * @returns {VoteRegistrationAndDelegationJSON} */ - to_js_value(): any; + to_js_value(): VoteRegistrationAndDelegationJSON; /** * @param {string} json @@ -13766,9 +13772,9 @@ declare export class Voter { to_json(): string; /** - * @returns {any} + * @returns {VoterJSON} */ - to_js_value(): any; + to_js_value(): VoterJSON; /** * @param {string} json @@ -13837,9 +13843,9 @@ declare export class Voters { to_json(): string; /** - * @returns {any} + * @returns {VotersJSON} */ - to_js_value(): any; + to_js_value(): VotersJSON; /** * @param {string} json @@ -13973,9 +13979,9 @@ declare export class VotingProcedure { to_json(): string; /** - * @returns {any} + * @returns {VotingProcedureJSON} */ - to_js_value(): any; + to_js_value(): VotingProcedureJSON; /** * @param {string} json @@ -14048,9 +14054,9 @@ declare export class VotingProcedures { to_json(): string; /** - * @returns {any} + * @returns {VotingProceduresJSON} */ - to_js_value(): any; + to_js_value(): VotingProceduresJSON; /** * @param {string} json @@ -14128,9 +14134,9 @@ declare export class VotingProposal { to_json(): string; /** - * @returns {any} + * @returns {VotingProposalJSON} */ - to_js_value(): any; + to_js_value(): VotingProposalJSON; /** * @param {string} json @@ -14249,9 +14255,9 @@ declare export class VotingProposals { to_json(): string; /** - * @returns {any} + * @returns {VotingProposalsJSON} */ - to_js_value(): any; + to_js_value(): VotingProposalsJSON; /** * @param {string} json @@ -14327,9 +14333,9 @@ declare export class Withdrawals { to_json(): string; /** - * @returns {any} + * @returns {WithdrawalsJSON} */ - to_js_value(): any; + to_js_value(): WithdrawalsJSON; /** * @param {string} json @@ -14433,3 +14439,929 @@ declare export class WithdrawalsBuilder { */ build(): Withdrawals; } +export type AddressJSON = string; +export type URLJSON = string; +export interface AnchorJSON { + anchor_data_hash: string; + anchor_url: URLJSON; +} +export type AnchorDataHashJSON = string; +export type AssetNameJSON = string; +export type AssetNamesJSON = string[]; +export interface AssetsJSON { + [k: string]: string; +} +export type NativeScriptJSON = + | { + ScriptPubkey: ScriptPubkeyJSON, + ... + } + | { + ScriptAll: ScriptAllJSON, + ... + } + | { + ScriptAny: ScriptAnyJSON, + ... + } + | { + ScriptNOfK: ScriptNOfKJSON, + ... + } + | { + TimelockStart: TimelockStartJSON, + ... + } + | { + TimelockExpiry: TimelockExpiryJSON, + ... + }; +export interface AuxiliaryDataJSON { + metadata?: { + [k: string]: string, + } | null; + native_scripts?: NativeScriptJSON[] | null; + plutus_scripts?: string[] | null; + prefer_alonzo_format: boolean; +} +export interface ScriptPubkeyJSON { + addr_keyhash: string; +} +export interface ScriptAllJSON { + native_scripts: NativeScriptJSON[]; +} +export interface ScriptAnyJSON { + native_scripts: NativeScriptJSON[]; +} +export interface ScriptNOfKJSON { + n: number; + native_scripts: NativeScriptJSON[]; +} +export interface TimelockStartJSON { + slot: string; +} +export interface TimelockExpiryJSON { + slot: string; +} +export type AuxiliaryDataHashJSON = string; +export interface AuxiliaryDataSetJSON { + [k: string]: AuxiliaryDataJSON; +} +export type BigIntJSON = string; +export type BigNumJSON = string; +export type VkeyJSON = string; +export type HeaderLeaderCertEnumJSON = + | { + /** + * @minItems 2 + * @maxItems 2 + */ + NonceAndLeader: [VRFCertJSON, VRFCertJSON], + ... + } + | { + VrfResult: VRFCertJSON, + ... + }; +export type CertificateJSON = + | { + StakeRegistration: StakeRegistrationJSON, + ... + } + | { + StakeDeregistration: StakeDeregistrationJSON, + ... + } + | { + StakeDelegation: StakeDelegationJSON, + ... + } + | { + PoolRegistration: PoolRegistrationJSON, + ... + } + | { + PoolRetirement: PoolRetirementJSON, + ... + } + | { + GenesisKeyDelegation: GenesisKeyDelegationJSON, + ... + } + | { + MoveInstantaneousRewardsCert: MoveInstantaneousRewardsCertJSON, + ... + } + | { + CommitteeHotAuth: CommitteeHotAuthJSON, + ... + } + | { + CommitteeColdResign: CommitteeColdResignJSON, + ... + } + | { + DRepDeregistration: DRepDeregistrationJSON, + ... + } + | { + DRepRegistration: DRepRegistrationJSON, + ... + } + | { + DRepUpdate: DRepUpdateJSON, + ... + } + | { + StakeAndVoteDelegation: StakeAndVoteDelegationJSON, + ... + } + | { + StakeRegistrationAndDelegation: StakeRegistrationAndDelegationJSON, + ... + } + | { + StakeVoteRegistrationAndDelegation: StakeVoteRegistrationAndDelegationJSON, + ... + } + | { + VoteDelegation: VoteDelegationJSON, + ... + } + | { + VoteRegistrationAndDelegation: VoteRegistrationAndDelegationJSON, + ... + }; +export type CredTypeJSON = + | { + Key: string, + ... + } + | { + Script: string, + ... + }; +export type RelayJSON = + | { + SingleHostAddr: SingleHostAddrJSON, + ... + } + | { + SingleHostName: SingleHostNameJSON, + ... + } + | { + MultiHostName: MultiHostNameJSON, + ... + }; +/** + * @minItems 4 + * @maxItems 4 + */ +export type Ipv4JSON = [number, number, number, number]; +/** + * @minItems 16 + * @maxItems 16 + */ +export type Ipv6JSON = [ + number, + number, + number, + number, + number, + number, + number, + number, + number, + number, + number, + number, + number, + number, + number, + number +]; +export type DNSRecordAorAAAAJSON = string; +export type DNSRecordSRVJSON = string; +export type RelaysJSON = RelayJSON[]; +export type MIRPotJSON = "Reserves" | "Treasury"; +export type MIREnumJSON = + | { + ToOtherPot: string, + ... + } + | { + ToStakeCredentials: StakeToCoinJSON[], + ... + }; +export type DRepJSON = + | ("AlwaysAbstain" | "AlwaysNoConfidence") + | { + KeyHash: string, + ... + } + | { + ScriptHash: string, + ... + }; +export type DataOptionJSON = + | { + DataHash: string, + ... + } + | { + Data: string, + ... + }; +export type ScriptRefJSON = + | { + NativeScript: NativeScriptJSON, + ... + } + | { + PlutusScript: string, + ... + }; +export type MintJSON = [string, MintAssetsJSON][]; +export type NetworkIdJSON = "Testnet" | "Mainnet"; +export type TransactionOutputsJSON = TransactionOutputJSON[]; +export type CostModelJSON = string[]; +export type VoterJSON = + | { + ConstitutionalCommitteeHotCred: CredTypeJSON, + ... + } + | { + DRep: CredTypeJSON, + ... + } + | { + StakingPool: string, + ... + }; +export type VoteKindJSON = "No" | "Yes" | "Abstain"; +export type GovernanceActionJSON = + | { + ParameterChangeAction: ParameterChangeActionJSON, + ... + } + | { + HardForkInitiationAction: HardForkInitiationActionJSON, + ... + } + | { + TreasuryWithdrawalsAction: TreasuryWithdrawalsActionJSON, + ... + } + | { + NoConfidenceAction: NoConfidenceActionJSON, + ... + } + | { + UpdateCommitteeAction: UpdateCommitteeActionJSON, + ... + } + | { + NewConstitutionAction: NewConstitutionActionJSON, + ... + } + | { + InfoAction: InfoActionJSON, + ... + }; +/** + * @minItems 0 + * @maxItems 0 + */ +export type InfoActionJSON = []; +export type TransactionBodiesJSON = TransactionBodyJSON[]; +export type RedeemerTagJSON = + | "Spend" + | "Mint" + | "Cert" + | "Reward" + | "Vote" + | "VotingProposal"; +export type TransactionWitnessSetsJSON = TransactionWitnessSetJSON[]; +export interface BlockJSON { + auxiliary_data_set: { + [k: string]: AuxiliaryDataJSON, + }; + header: HeaderJSON; + invalid_transactions: number[]; + transaction_bodies: TransactionBodiesJSON; + transaction_witness_sets: TransactionWitnessSetsJSON; +} +export interface HeaderJSON { + body_signature: string; + header_body: HeaderBodyJSON; +} +export interface HeaderBodyJSON { + block_body_hash: string; + block_body_size: number; + block_number: number; + issuer_vkey: VkeyJSON; + leader_cert: HeaderLeaderCertEnumJSON; + operational_cert: OperationalCertJSON; + prev_hash?: string | null; + protocol_version: ProtocolVersionJSON; + slot: string; + vrf_vkey: string; +} +export interface VRFCertJSON { + output: number[]; + proof: number[]; +} +export interface OperationalCertJSON { + hot_vkey: string; + kes_period: number; + sequence_number: number; + sigma: string; +} +export interface ProtocolVersionJSON { + major: number; + minor: number; +} +export interface TransactionBodyJSON { + auxiliary_data_hash?: string | null; + certs?: CertificateJSON[] | null; + collateral?: TransactionInputJSON[] | null; + collateral_return?: TransactionOutputJSON | null; + current_treasury_value?: string | null; + donation?: string | null; + fee: string; + inputs: TransactionInputJSON[]; + mint?: MintJSON | null; + network_id?: NetworkIdJSON | null; + outputs: TransactionOutputsJSON; + reference_inputs?: TransactionInputJSON[] | null; + required_signers?: string[] | null; + script_data_hash?: string | null; + total_collateral?: string | null; + ttl?: string | null; + update?: UpdateJSON | null; + validity_start_interval?: string | null; + voting_procedures?: VoterVotesJSON[] | null; + voting_proposals?: VotingProposalJSON[] | null; + withdrawals?: { + [k: string]: string, + } | null; +} +export interface StakeRegistrationJSON { + coin?: string | null; + stake_credential: CredTypeJSON; +} +export interface StakeDeregistrationJSON { + coin?: string | null; + stake_credential: CredTypeJSON; +} +export interface StakeDelegationJSON { + pool_keyhash: string; + stake_credential: CredTypeJSON; +} +export interface PoolRegistrationJSON { + pool_params: PoolParamsJSON; +} +export interface PoolParamsJSON { + cost: string; + margin: UnitIntervalJSON; + operator: string; + pledge: string; + pool_metadata?: PoolMetadataJSON | null; + pool_owners: string[]; + relays: RelaysJSON; + reward_account: string; + vrf_keyhash: string; +} +export interface UnitIntervalJSON { + denominator: string; + numerator: string; +} +export interface PoolMetadataJSON { + pool_metadata_hash: string; + url: URLJSON; +} +export interface SingleHostAddrJSON { + ipv4?: Ipv4JSON | null; + ipv6?: Ipv6JSON | null; + port?: number | null; +} +export interface SingleHostNameJSON { + dns_name: DNSRecordAorAAAAJSON; + port?: number | null; +} +export interface MultiHostNameJSON { + dns_name: DNSRecordSRVJSON; +} +export interface PoolRetirementJSON { + epoch: number; + pool_keyhash: string; +} +export interface GenesisKeyDelegationJSON { + genesis_delegate_hash: string; + genesishash: string; + vrf_keyhash: string; +} +export interface MoveInstantaneousRewardsCertJSON { + move_instantaneous_reward: MoveInstantaneousRewardJSON; +} +export interface MoveInstantaneousRewardJSON { + pot: MIRPotJSON; + variant: MIREnumJSON; +} +export interface StakeToCoinJSON { + amount: string; + stake_cred: CredTypeJSON; +} +export interface CommitteeHotAuthJSON { + committee_cold_credential: CredTypeJSON; + committee_hot_credential: CredTypeJSON; +} +export interface CommitteeColdResignJSON { + anchor?: AnchorJSON | null; + committee_cold_credential: CredTypeJSON; +} +export interface DRepDeregistrationJSON { + coin: string; + voting_credential: CredTypeJSON; +} +export interface DRepRegistrationJSON { + anchor?: AnchorJSON | null; + coin: string; + voting_credential: CredTypeJSON; +} +export interface DRepUpdateJSON { + anchor?: AnchorJSON | null; + voting_credential: CredTypeJSON; +} +export interface StakeAndVoteDelegationJSON { + drep: DRepJSON; + pool_keyhash: string; + stake_credential: CredTypeJSON; +} +export interface StakeRegistrationAndDelegationJSON { + coin: string; + pool_keyhash: string; + stake_credential: CredTypeJSON; +} +export interface StakeVoteRegistrationAndDelegationJSON { + coin: string; + drep: DRepJSON; + pool_keyhash: string; + stake_credential: CredTypeJSON; +} +export interface VoteDelegationJSON { + drep: DRepJSON; + stake_credential: CredTypeJSON; +} +export interface VoteRegistrationAndDelegationJSON { + coin: string; + drep: DRepJSON; + stake_credential: CredTypeJSON; +} +export interface TransactionInputJSON { + index: number; + transaction_id: string; +} +export interface TransactionOutputJSON { + address: string; + amount: ValueJSON; + plutus_data?: DataOptionJSON | null; + script_ref?: ScriptRefJSON | null; +} +export interface ValueJSON { + coin: string; + multiasset?: MultiAssetJSON | null; +} +export interface MultiAssetJSON { + [k: string]: AssetsJSON; +} +export interface MintAssetsJSON { + [k: string]: string; +} +export interface UpdateJSON { + epoch: number; + proposed_protocol_parameter_updates: { + [k: string]: ProtocolParamUpdateJSON, + }; +} +export interface ProtocolParamUpdateJSON { + ada_per_utxo_byte?: string | null; + collateral_percentage?: number | null; + committee_term_limit?: number | null; + cost_models?: CostmdlsJSON | null; + d?: UnitIntervalJSON | null; + drep_deposit?: string | null; + drep_inactivity_period?: number | null; + drep_voting_thresholds?: DRepVotingThresholdsJSON | null; + execution_costs?: ExUnitPricesJSON | null; + expansion_rate?: UnitIntervalJSON | null; + extra_entropy?: NonceJSON | null; + governance_action_deposit?: string | null; + governance_action_validity_period?: number | null; + key_deposit?: string | null; + max_block_body_size?: number | null; + max_block_ex_units?: ExUnitsJSON | null; + max_block_header_size?: number | null; + max_collateral_inputs?: number | null; + max_epoch?: number | null; + max_tx_ex_units?: ExUnitsJSON | null; + max_tx_size?: number | null; + max_value_size?: number | null; + min_committee_size?: number | null; + min_pool_cost?: string | null; + minfee_a?: string | null; + minfee_b?: string | null; + n_opt?: number | null; + pool_deposit?: string | null; + pool_pledge_influence?: UnitIntervalJSON | null; + pool_voting_thresholds?: PoolVotingThresholdsJSON | null; + protocol_version?: ProtocolVersionJSON | null; + ref_script_coins_per_byte?: UnitIntervalJSON | null; + treasury_growth_rate?: UnitIntervalJSON | null; +} +export interface CostmdlsJSON { + [k: string]: CostModelJSON; +} +export interface DRepVotingThresholdsJSON { + committee_no_confidence: UnitIntervalJSON; + committee_normal: UnitIntervalJSON; + hard_fork_initiation: UnitIntervalJSON; + motion_no_confidence: UnitIntervalJSON; + pp_economic_group: UnitIntervalJSON; + pp_governance_group: UnitIntervalJSON; + pp_network_group: UnitIntervalJSON; + pp_technical_group: UnitIntervalJSON; + treasury_withdrawal: UnitIntervalJSON; + update_constitution: UnitIntervalJSON; +} +export interface ExUnitPricesJSON { + mem_price: UnitIntervalJSON; + step_price: UnitIntervalJSON; +} +export interface NonceJSON { + /** + * @minItems 32 + * @maxItems 32 + */ + hash?: + | [ + number, + number, + number, + number, + number, + number, + number, + number, + number, + number, + number, + number, + number, + number, + number, + number, + number, + number, + number, + number, + number, + number, + number, + number, + number, + number, + number, + number, + number, + number, + number, + number + ] + | null; +} +export interface ExUnitsJSON { + mem: string; + steps: string; +} +export interface PoolVotingThresholdsJSON { + committee_no_confidence: UnitIntervalJSON; + committee_normal: UnitIntervalJSON; + hard_fork_initiation: UnitIntervalJSON; + motion_no_confidence: UnitIntervalJSON; + security_relevant_threshold: UnitIntervalJSON; +} +export interface VoterVotesJSON { + voter: VoterJSON; + votes: VoteJSON[]; +} +export interface VoteJSON { + action_id: GovernanceActionIdJSON; + voting_procedure: VotingProcedureJSON; +} +export interface GovernanceActionIdJSON { + index: number; + transaction_id: string; +} +export interface VotingProcedureJSON { + anchor?: AnchorJSON | null; + vote: VoteKindJSON; +} +export interface VotingProposalJSON { + anchor: AnchorJSON; + deposit: string; + governance_action: GovernanceActionJSON; + reward_account: string; +} +export interface ParameterChangeActionJSON { + gov_action_id?: GovernanceActionIdJSON | null; + policy_hash?: string | null; + protocol_param_updates: ProtocolParamUpdateJSON; +} +export interface HardForkInitiationActionJSON { + gov_action_id?: GovernanceActionIdJSON | null; + protocol_version: ProtocolVersionJSON; +} +export interface TreasuryWithdrawalsActionJSON { + policy_hash?: string | null; + withdrawals: TreasuryWithdrawalsJSON; +} +export interface TreasuryWithdrawalsJSON { + [k: string]: string; +} +export interface NoConfidenceActionJSON { + gov_action_id?: GovernanceActionIdJSON | null; +} +export interface UpdateCommitteeActionJSON { + committee: CommitteeJSON; + gov_action_id?: GovernanceActionIdJSON | null; + members_to_remove: CredTypeJSON[]; +} +export interface CommitteeJSON { + members: CommitteeMemberJSON[]; + quorum_threshold: UnitIntervalJSON; +} +export interface CommitteeMemberJSON { + stake_credential: CredTypeJSON; + term_limit: number; +} +export interface NewConstitutionActionJSON { + constitution: ConstitutionJSON; + gov_action_id?: GovernanceActionIdJSON | null; +} +export interface ConstitutionJSON { + anchor: AnchorJSON; + script_hash?: string | null; +} +export interface TransactionWitnessSetJSON { + bootstraps?: BootstrapWitnessJSON[] | null; + native_scripts?: NativeScriptJSON[] | null; + plutus_data?: PlutusListJSON | null; + plutus_scripts?: string[] | null; + redeemers?: RedeemerJSON[] | null; + vkeys?: VkeywitnessJSON[] | null; +} +export interface BootstrapWitnessJSON { + attributes: number[]; + chain_code: number[]; + signature: string; + vkey: VkeyJSON; +} +export interface PlutusListJSON { + definite_encoding?: boolean | null; + elems: string[]; +} +export interface RedeemerJSON { + data: string; + ex_units: ExUnitsJSON; + index: string; + tag: RedeemerTagJSON; +} +export interface VkeywitnessJSON { + signature: string; + vkey: VkeyJSON; +} +export type BlockHashJSON = string; +export type BootstrapWitnessesJSON = BootstrapWitnessJSON[]; +export type CertificateEnumJSON = + | { + StakeRegistration: StakeRegistrationJSON, + ... + } + | { + StakeDeregistration: StakeDeregistrationJSON, + ... + } + | { + StakeDelegation: StakeDelegationJSON, + ... + } + | { + PoolRegistration: PoolRegistrationJSON, + ... + } + | { + PoolRetirement: PoolRetirementJSON, + ... + } + | { + GenesisKeyDelegation: GenesisKeyDelegationJSON, + ... + } + | { + MoveInstantaneousRewardsCert: MoveInstantaneousRewardsCertJSON, + ... + } + | { + CommitteeHotAuth: CommitteeHotAuthJSON, + ... + } + | { + CommitteeColdResign: CommitteeColdResignJSON, + ... + } + | { + DRepDeregistration: DRepDeregistrationJSON, + ... + } + | { + DRepRegistration: DRepRegistrationJSON, + ... + } + | { + DRepUpdate: DRepUpdateJSON, + ... + } + | { + StakeAndVoteDelegation: StakeAndVoteDelegationJSON, + ... + } + | { + StakeRegistrationAndDelegation: StakeRegistrationAndDelegationJSON, + ... + } + | { + StakeVoteRegistrationAndDelegation: StakeVoteRegistrationAndDelegationJSON, + ... + } + | { + VoteDelegation: VoteDelegationJSON, + ... + } + | { + VoteRegistrationAndDelegation: VoteRegistrationAndDelegationJSON, + ... + }; +export type CertificatesJSON = CertificateJSON[]; +export type CredentialJSON = CredTypeJSON; +export type CredentialsJSON = CredTypeJSON[]; +export type DRepEnumJSON = + | ("AlwaysAbstain" | "AlwaysNoConfidence") + | { + KeyHash: string, + ... + } + | { + ScriptHash: string, + ... + }; +export type DataHashJSON = string; +export type Ed25519KeyHashJSON = string; +export type Ed25519KeyHashesJSON = string[]; +export type Ed25519SignatureJSON = string; +export interface GeneralTransactionMetadataJSON { + [k: string]: string; +} +export type GenesisDelegateHashJSON = string; +export type GenesisHashJSON = string; +export type GenesisHashesJSON = string[]; +export type GovernanceActionEnumJSON = + | { + ParameterChangeAction: ParameterChangeActionJSON, + ... + } + | { + HardForkInitiationAction: HardForkInitiationActionJSON, + ... + } + | { + TreasuryWithdrawalsAction: TreasuryWithdrawalsActionJSON, + ... + } + | { + NoConfidenceAction: NoConfidenceActionJSON, + ... + } + | { + UpdateCommitteeAction: UpdateCommitteeActionJSON, + ... + } + | { + NewConstitutionAction: NewConstitutionActionJSON, + ... + } + | { + InfoAction: InfoActionJSON, + ... + }; +export type GovernanceActionIdsJSON = GovernanceActionIdJSON[]; +export type IntJSON = string; +/** + * @minItems 4 + * @maxItems 4 + */ +export type KESVKeyJSON = string; +export type LanguageJSON = LanguageKindJSON; +export type LanguageKindJSON = "PlutusV1" | "PlutusV2" | "PlutusV3"; +export type LanguagesJSON = LanguageJSON[]; +export type MIRToStakeCredentialsJSON = StakeToCoinJSON[]; +export type MintsAssetsJSON = MintAssetsJSON[]; +export type NativeScriptsJSON = NativeScriptJSON[]; +export type NetworkIdKindJSON = "Testnet" | "Mainnet"; +export type PlutusScriptJSON = string; +export type PlutusScriptsJSON = string[]; +export type PoolMetadataHashJSON = string; +export interface ProposedProtocolParameterUpdatesJSON { + [k: string]: ProtocolParamUpdateJSON; +} +export type PublicKeyJSON = string; +export type RedeemerTagKindJSON = + | "Spend" + | "Mint" + | "Cert" + | "Reward" + | "Vote" + | "VotingProposal"; +export type RedeemersJSON = RedeemerJSON[]; +export type RelayEnumJSON = + | { + SingleHostAddr: SingleHostAddrJSON, + ... + } + | { + SingleHostName: SingleHostNameJSON, + ... + } + | { + MultiHostName: MultiHostNameJSON, + ... + }; +/** + * @minItems 4 + * @maxItems 4 + */ +export type RewardAddressJSON = string; +export type RewardAddressesJSON = string[]; +export type ScriptDataHashJSON = string; +export type ScriptHashJSON = string; +export type ScriptHashesJSON = string[]; +export type ScriptRefEnumJSON = + | { + NativeScript: NativeScriptJSON, + ... + } + | { + PlutusScript: string, + ... + }; +export interface TransactionJSON { + auxiliary_data?: AuxiliaryDataJSON | null; + body: TransactionBodyJSON; + is_valid: boolean; + witness_set: TransactionWitnessSetJSON; +} +export type TransactionHashJSON = string; +export type TransactionInputsJSON = TransactionInputJSON[]; +export type TransactionMetadatumJSON = string; +export interface TransactionUnspentOutputJSON { + input: TransactionInputJSON; + output: TransactionOutputJSON; +} +export type TransactionUnspentOutputsJSON = TransactionUnspentOutputJSON[]; +export type VRFKeyHashJSON = string; +export type VRFVKeyJSON = string; +export interface VersionedBlockJSON { + block: BlockJSON; + era_code: number; +} +export type VkeywitnessesJSON = VkeywitnessJSON[]; +export type VoterEnumJSON = + | { + ConstitutionalCommitteeHotCred: CredTypeJSON, + ... + } + | { + DRep: CredTypeJSON, + ... + } + | { + StakingPool: string, + ... + }; +export type VotersJSON = VoterJSON[]; +export type VotingProceduresJSON = VoterVotesJSON[]; +export type VotingProposalsJSON = VotingProposalJSON[]; +export interface WithdrawalsJSON { + [k: string]: string; +} diff --git a/rust/src/protocol_types/native_scripts.rs b/rust/src/protocol_types/native_scripts.rs index 58e8a47a..3c073a50 100644 --- a/rust/src/protocol_types/native_scripts.rs +++ b/rust/src/protocol_types/native_scripts.rs @@ -179,13 +179,13 @@ impl<'de> serde::de::Deserialize<'de> for NativeScripts { impl JsonSchema for NativeScripts { fn is_referenceable() -> bool { - Vec::::is_referenceable() + Vec::::is_referenceable() } fn schema_name() -> String { String::from("NativeScripts") } fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema { - Vec::::json_schema(gen) + Vec::::json_schema(gen) } } diff --git a/rust/src/protocol_types/plutus/plutus_data.rs b/rust/src/protocol_types/plutus/plutus_data.rs index 9dd9b9ea..753337fa 100644 --- a/rust/src/protocol_types/plutus/plutus_data.rs +++ b/rust/src/protocol_types/plutus/plutus_data.rs @@ -310,7 +310,9 @@ impl PlutusData { AddrType::Base(addr) => Ok(addr.payment_cred()), AddrType::Enterprise(addr) => Ok(addr.payment_cred()), AddrType::Ptr(addr) => Ok(addr.payment_cred()), - AddrType::Reward(addr) => Ok(addr.payment_cred()), + AddrType::Reward(_) => Err(JsError::from_str( + "Cannot convert Reward address to PlutusData", + )), AddrType::Byron(_) => Err(JsError::from_str( "Cannot convert Byron address to PlutusData", )), @@ -321,7 +323,7 @@ impl PlutusData { let staking_data = match &address.0 { AddrType::Base(addr) => { - let staking_bytes_data = PlutusData::from_stake_credential(&addr.stake_cred())?; + let staking_bytes_data = PlutusData::from_credential(&addr.stake_cred())?; Some(PlutusData::new_single_value_constr_plutus_data( &BigNum::from(0u32), &staking_bytes_data, @@ -335,7 +337,7 @@ impl PlutusData { _ => None, }; - let payment_data = PlutusData::from_stake_credential(&payment_cred)?; + let payment_data = PlutusData::from_credential(&payment_cred)?; let staking_optional_data = match (staking_data, pointer_data) { (Some(_), Some(_)) => Err(JsError::from_str( "Address can't have both staking and pointer data", @@ -364,7 +366,91 @@ impl PlutusData { ))) } - fn from_stake_credential(stake_credential: &Credential) -> Result { + pub fn as_address(&self, network: &NetworkInfo) -> Result { + let constr_data = self.as_constr_plutus_data().ok_or_else(|| { + JsError::from_str("Expected PlutusData to be a ConstrPlutusData") + })?; + + if constr_data.alternative().0 != 0 { + return Err(JsError::from_str( + "Expected alternative 0 in ConstrPlutusData", + )); + } + + let data_list = constr_data.data(); + if data_list.len() != 2 { + return Err(JsError::from_str( + "Expected exactly 2 elements in the data list", + )); + } + + let payment_data = data_list.get(0); + let payment_cred = payment_data.as_credential()?; + + let staking_data = data_list.get(1); + let staking_cred_option = + if let Some(constr_staking_data) = staking_data.as_constr_plutus_data() + { + match constr_staking_data.alternative().0 { + 0 => { + let staking_inner_data = constr_staking_data.data(); + if staking_inner_data.len() != 1 { + return Err(JsError::from_str( + "Expected exactly 1 element in staking inner data", + )); + } + let constr_staking_inner_data = staking_inner_data.get(0); + Some(constr_staking_inner_data) + } + 1 => { + None + } + _ => { + return Err(JsError::from_str( + "Invalid alternative in staking data constructor", + )); + } + } + } else { + return Err(JsError::from_str( + "Expected staking data to be a ConstrPlutusData", + )); + }; + + let network = network.network_id(); + let address = if let Some(staking_cred_data) = staking_cred_option { + let staking_cred_constr = staking_cred_data.as_constr_plutus_data().ok_or_else(|| { + JsError::from_str("Expected staking data to be a ConstrPlutusData") + })?; + match staking_cred_constr.alternative.0 { + 0 => { + let staking_cred_constr_data = staking_cred_constr.data(); + if staking_cred_constr_data.len() != 1 { + return Err(JsError::from_str( + "Expected exactly 1 element in staking data constructor", + )); + } + let staking_cred = staking_cred_constr_data.get(0).as_credential()?; + BaseAddress::new(network, &payment_cred, &staking_cred).to_address() + } + 1 => { + let pointer = staking_cred_data.as_pointer()?; + PointerAddress::new(network, &payment_cred, &pointer).to_address() + } + _ => { + return Err(JsError::from_str( + "Invalid alternative in staking data constructor", + )); + } + } + } else { + EnterpriseAddress::new(network, &payment_cred).to_address() + }; + + Ok(address) + } + + fn from_credential(stake_credential: &Credential) -> Result { let (bytes_plutus_data, index) = match &stake_credential.0 { CredType::Key(key_hash) => ( PlutusData::new_bytes(key_hash.to_bytes().to_vec()), @@ -382,6 +468,44 @@ impl PlutusData { )) } + fn as_credential(&self) -> Result { + let constr_data = self.as_constr_plutus_data().ok_or_else(|| { + JsError::from_str("Expected PlutusData to be a ConstrPlutusData") + })?; + + let index = constr_data.alternative().0; + + let data_list = constr_data.data(); + if data_list.len() != 1 { + return Err(JsError::from_str( + "Expected exactly one element in ConstrPlutusData data", + )); + } + + let bytes_data = data_list.get(0); + let bytes = bytes_data.as_bytes().ok_or_else(|| { + JsError::from_str("Expected the inner PlutusData to be bytes") + })?; + + match index { + 0 => { + let key_hash = Ed25519KeyHash::from_bytes(bytes).map_err(|_| { + JsError::from_str("Invalid KeyHash bytes") + })?; + Ok(Credential(CredType::Key(key_hash))) + } + 1 => { + let script_hash = ScriptHash::from_bytes(bytes).map_err(|_| { + JsError::from_str("Invalid ScriptHash bytes") + })?; + Ok(Credential(CredType::Script(script_hash))) + } + _ => Err(JsError::from_str( + "Invalid alternative index in ConstrPlutusData for Credential", + )), + } + } + fn from_pointer(pointer: &Pointer) -> Result { let mut data_list = PlutusList::new(); data_list.add(&PlutusData::new_integer(&pointer.slot_bignum().into())); @@ -395,6 +519,49 @@ impl PlutusData { &data_list, ))) } + + fn as_pointer(&self) -> Result { + let constr_data = self.as_constr_plutus_data().ok_or_else(|| { + JsError::from_str("Expected PlutusData to be a ConstrPlutusData") + })?; + + if constr_data.alternative() != BigNum(1) { + return Err(JsError::from_str("Expected alternative 1 in ConstrPlutusData")); + } + + let data_list = constr_data.data(); + if data_list.len() != 3 { + return Err(JsError::from_str("Expected exactly 3 elements in data list")); + } + + let slot_data = data_list.get(0); + let tx_index_data = data_list.get(1); + let cert_index_data = data_list.get(2); + + let slot_integer = slot_data.as_integer().ok_or_else(|| { + JsError::from_str("Expected slot data to be an integer") + })?; + let tx_index_integer = tx_index_data.as_integer().ok_or_else(|| { + JsError::from_str("Expected tx_index data to be an integer") + })?; + let cert_index_integer = cert_index_data.as_integer().ok_or_else(|| { + JsError::from_str("Expected cert_index data to be an integer") + })?; + + let slot_bignum = slot_integer + .as_u64() + .ok_or_else(|| JsError::from_str("Slot integer must be positive"))?; + let tx_index_bignum = tx_index_integer + .as_u64() + .ok_or_else(|| JsError::from_str("Tx index integer must be positive"))?; + let cert_index_bignum = cert_index_integer + .as_u64() + .ok_or_else(|| JsError::from_str("Cert index integer must be positive"))?; + + let pointer = Pointer::new_pointer(&slot_bignum, &tx_index_bignum, &cert_index_bignum); + + Ok(pointer) + } } //TODO: replace this by cardano-node schemas @@ -449,6 +616,8 @@ pub struct PlutusList { pub(crate) cbor_set_type: Option, } +to_from_bytes!(PlutusList); + #[wasm_bindgen] impl PlutusList { pub fn new() -> Self { @@ -529,6 +698,12 @@ impl NoneOrEmpty for PlutusList { } } +#[derive(serde::Deserialize, JsonSchema)] +struct PlutusListFields { + elems: Vec, + definite_encoding: Option, +} + impl serde::Serialize for PlutusList { fn serialize(&self, serializer: S) -> Result where @@ -542,12 +717,6 @@ impl serde::Serialize for PlutusList { } -#[derive(serde::Deserialize, JsonSchema)] -struct PlutusListFields { - elems: Vec, - definite_encoding: Option, -} - impl<'de> serde::de::Deserialize<'de> for PlutusList { fn deserialize(deserializer: D) -> Result where @@ -616,8 +785,6 @@ impl std::cmp::PartialEq for PlutusList { impl std::cmp::Eq for PlutusList {} -to_from_bytes!(PlutusList); - impl From> for PlutusList { fn from(elems: Vec) -> Self { Self { diff --git a/rust/src/tests/plutus.rs b/rust/src/tests/plutus.rs index 7539f91a..7d5d2190 100644 --- a/rust/src/tests/plutus.rs +++ b/rust/src/tests/plutus.rs @@ -1,5 +1,6 @@ use crate::*; use hex::*; +use crate::tests::fakes::{fake_byron_address, fake_key_hash, fake_script_hash}; #[test] pub fn plutus_constr_data() { @@ -591,4 +592,92 @@ fn script_data_hash_no_redeemers() { hex::encode(hash.to_bytes()), "fd53a28a846ae6ccf8b221d03d4af122b0b3c442089c05b87e3d86c6792b3ef0" ); -} \ No newline at end of file +} + +#[test] +fn plutus_data_base_address_roundtrip_keyhash() { + let payment_cred = Credential::from_keyhash(&fake_key_hash(1)); + let staking_cred = Credential::from_keyhash(&fake_key_hash(2)); + let network_id = NetworkInfo::testnet_preprod().network_id(); + let base_address = BaseAddress::new(network_id, &payment_cred, &staking_cred).to_address(); + let plutus_data = PlutusData::from_address(&base_address).unwrap(); + let address_from_data = plutus_data.as_address(&NetworkInfo::testnet_preprod()).unwrap(); + assert_eq!(address_from_data, base_address); +} + +#[test] +fn plutus_data_base_address_roundtrip_scripthash() { + let payment_cred = Credential::from_scripthash(&fake_script_hash(1)); + let staking_cred = Credential::from_scripthash(&fake_script_hash(2)); + let network_id = NetworkInfo::testnet_preprod().network_id(); + let base_address = BaseAddress::new(network_id, &payment_cred, &staking_cred).to_address(); + let plutus_data = PlutusData::from_address(&base_address).unwrap(); + let address_from_data = plutus_data.as_address(&NetworkInfo::testnet_preprod()).unwrap(); + assert_eq!(address_from_data, base_address); +} + +#[test] +fn plutus_data_enterprise_address_roundtrip_scripthash() { + let payment_cred = Credential::from_scripthash(&fake_script_hash(1)); + let network_id = NetworkInfo::testnet_preprod().network_id(); + let enterprise_address = EnterpriseAddress::new(network_id, &payment_cred).to_address(); + let plutus_data = PlutusData::from_address(&enterprise_address).unwrap(); + let address_from_data = plutus_data.as_address(&NetworkInfo::testnet_preprod()).unwrap(); + assert_eq!(address_from_data, enterprise_address); +} + +#[test] +fn plutus_data_enterprise_address_roundtrip_keyhash() { + let payment_cred = Credential::from_keyhash(&fake_key_hash(1)); + let network_id = NetworkInfo::testnet_preprod().network_id(); + let enterprise_address = EnterpriseAddress::new(network_id, &payment_cred).to_address(); + let plutus_data = PlutusData::from_address(&enterprise_address).unwrap(); + let address_from_data = plutus_data.as_address(&NetworkInfo::testnet_preprod()).unwrap(); + assert_eq!(address_from_data, enterprise_address); +} + +#[test] +fn plutus_data_pointer_address_roundtrip_keyhash() { + let pointer = Pointer::new_pointer(&BigNum(1), &BigNum(256), &BigNum(99999999999999999)); + let payment_cred = Credential::from_keyhash(&fake_key_hash(1)); + let network_id = NetworkInfo::mainnet().network_id(); + let pointer_address = PointerAddress::new(network_id, &payment_cred, &pointer).to_address(); + let plutus_data = PlutusData::from_address(&pointer_address).unwrap(); + let address_from_data = plutus_data.as_address(&NetworkInfo::mainnet()).unwrap(); + assert_eq!(address_from_data, pointer_address); +} + +#[test] +fn plutus_data_pointer_address_roundtrip_scripthash() { + let pointer = Pointer::new_pointer(&BigNum(1), &BigNum(256), &BigNum(99999999999999999)); + let payment_cred = Credential::from_scripthash(&fake_script_hash(2)); + let network_id = NetworkInfo::testnet_preprod().network_id(); + let pointer_address = PointerAddress::new(network_id, &payment_cred, &pointer).to_address(); + let plutus_data = PlutusData::from_address(&pointer_address).unwrap(); + let address_from_data = plutus_data.as_address(&NetworkInfo::testnet_preprod()).unwrap(); + assert_eq!(address_from_data, pointer_address); +} + +#[test] +fn plutus_data_reward_address_error() { + let payment_cred = Credential::from_keyhash(&fake_key_hash(1)); + let network_id = NetworkInfo::testnet_preprod().network_id(); + let reward_address = RewardAddress::new(network_id, &payment_cred).to_address(); + + let plutus_data = PlutusData::from_address(&reward_address); + assert!(plutus_data.is_err()); +} + +#[test] +fn plutus_data_byron_address_error() { + let byron_address = fake_byron_address(); + let plutus_data = PlutusData::from_address(&byron_address); + assert!(plutus_data.is_err()); +} + +#[test] +fn plutus_data_malformed_address_error() { + let malformed_address = MalformedAddress(vec![1, 2 ,3]).to_address(); + let plutus_data = PlutusData::from_address(&malformed_address); + assert!(plutus_data.is_err()); +} diff --git a/rust/src/tests/serialization/general.rs b/rust/src/tests/serialization/general.rs index ac8187aa..269cbcac 100644 --- a/rust/src/tests/serialization/general.rs +++ b/rust/src/tests/serialization/general.rs @@ -1,5 +1,4 @@ -use crate::{Address, BigInt, BigNum, Block, BlockHash, CborContainerType, Coin, Credential, DataHash, ExUnits, HeaderBody, HeaderLeaderCertEnum, Int, KESVKey, MIRPot, MIRToStakeCredentials, MoveInstantaneousReward, NativeScript, OperationalCert, PlutusData, PlutusList, PlutusScript, PlutusScripts, ProtocolVersion, Redeemer, RedeemerTag, Redeemers, ScriptHash, ScriptRef, TimelockStart, TransactionBody, TransactionInputs, TransactionOutput, TransactionOutputs, TransactionWitnessSet, VRFCert, VRFVKey, Value, Vkeywitness, Vkeywitnesses, VersionedBlock, BlockEra, to_bytes, BootstrapWitnesses, Credentials, Ed25519KeyHashes, CborSetType, ScriptPubkey, NativeScripts, Language}; - +use crate::{Address, BigInt, BigNum, Block, BlockHash, CborContainerType, Coin, Credential, DataHash, ExUnits, HeaderBody, HeaderLeaderCertEnum, Int, KESVKey, MIRPot, MIRToStakeCredentials, MoveInstantaneousReward, NativeScript, OperationalCert, PlutusData, PlutusList, PlutusScript, PlutusScripts, ProtocolVersion, Redeemer, RedeemerTag, Redeemers, ScriptHash, ScriptRef, TimelockStart, TransactionBody, TransactionInputs, TransactionOutput, TransactionOutputs, TransactionWitnessSet, VRFCert, VRFVKey, Value, Vkeywitness, Vkeywitnesses, VersionedBlock, BlockEra, to_bytes, BootstrapWitnesses, Credentials, Ed25519KeyHashes, CborSetType, ScriptPubkey, NativeScripts, Language, PlutusDatumSchema}; use crate::protocol_types::ScriptRefEnum; use crate::tests::fakes::{fake_base_address, fake_bootsrap_witness, fake_bytes_32, fake_data_hash, fake_key_hash, fake_signature, fake_tx_input, fake_tx_output, fake_value, fake_value2, fake_vkey, fake_vkey_witness}; @@ -1080,3 +1079,57 @@ fn pure_plutus_list_always_should_be_without_tag() { assert_eq!(plutus_data_list, plutus_data_list_from_bytes); assert_eq!(plutus_data_list_from_bytes.get_set_type(), Some(CborSetType::Untagged)); } + +#[test] +fn plutus_list_round_trip() { + let plutus_data = PlutusData::new_integer(&BigInt::one()); + let plutus_data_list = PlutusList::from(vec![plutus_data]); + + let bytes = plutus_data_list.to_bytes(); + let new_plutus_data_list = PlutusList::from_bytes(bytes.clone()).unwrap(); + + let json = PlutusData::new_list(&plutus_data_list).to_json(PlutusDatumSchema::DetailedSchema).unwrap(); + let new_plutus_data_list_json = PlutusData::from_json(&json, PlutusDatumSchema::DetailedSchema).unwrap().as_list().unwrap(); + + assert_eq!(plutus_data_list, new_plutus_data_list); + assert_eq!(plutus_data_list, new_plutus_data_list_json); + assert_eq!(bytes, new_plutus_data_list.to_bytes()); +} + +#[test] +fn plutus_list_round_trip_in_witnesses_set() { + let plutus_data = PlutusData::new_integer(&BigInt::one()); + let plutus_data_list = PlutusList::from(vec![plutus_data]); + + let mut witnesses_set = TransactionWitnessSet::new(); + witnesses_set.set_plutus_data(&plutus_data_list); + + let bytes = witnesses_set.to_bytes(); + let new_witnesses_set = TransactionWitnessSet::from_bytes(bytes.clone()).unwrap(); + + let plutus_data_list_from_bytes = new_witnesses_set.plutus_data().unwrap(); + assert_eq!(plutus_data_list, plutus_data_list_from_bytes); + + let json = witnesses_set.to_json().unwrap(); + let new_witnesses_set_json = TransactionWitnessSet::from_json(&json).unwrap(); + let new_plutus_data_list_json = new_witnesses_set_json.plutus_data().unwrap(); + + assert_eq!(plutus_data_list, new_plutus_data_list_json); +} + +#[test] +fn native_scripts_roundtrip() { + let native_script = NativeScript::new_script_pubkey(&ScriptPubkey::new(&fake_key_hash(1))); + let native_scripts = NativeScripts::from(vec![&native_script]); + + let bytes = native_scripts.to_bytes(); + let new_native_scripts = NativeScripts::from_bytes(bytes.clone()).unwrap(); + + let json = native_scripts.to_json().unwrap(); + let new_native_scripts_json = NativeScripts::from_json(&json).unwrap(); + + assert_eq!(native_scripts, new_native_scripts); + assert_eq!(native_scripts, new_native_scripts_json); + assert_eq!(bytes, new_native_scripts.to_bytes()); + assert_eq!(json, new_native_scripts_json.to_json().unwrap()); +}