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

@cardano-sdk/core

Package Overview
Dependencies
Maintainers
1
Versions
144
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cardano-sdk/core - npm Package Compare versions

Comparing version 0.7.0-nightly.5 to 0.7.0-nightly.6

4

dist/cjs/CML/cmlToCore/cmlToCore.d.ts

@@ -15,2 +15,5 @@ import * as Cardano from '../../Cardano';

export declare const txWitnessRedeemers: (redeemers?: CML.Redeemers) => Cardano.Redeemer[] | undefined;
export declare const txWitnessDatums: (datums?: CML.PlutusList) => Cardano.Datum[] | undefined;
export declare const nativeScript: (script: CML.NativeScript) => Cardano.NativeScript;
export declare const txWitnessScripts: (witnessSet: CML.TransactionWitnessSet) => Cardano.Script[] | undefined;
export declare const txWitnessSet: (witnessSet: CML.TransactionWitnessSet) => Cardano.Witness;

@@ -22,3 +25,2 @@ export declare const txMetadatum: (transactionMetadatum: CML.TransactionMetadatum) => Cardano.Metadatum;

export declare const newTx: (cslTx: CML.Transaction) => Cardano.Tx;
export declare const nativeScript: (script: CML.NativeScript) => Cardano.NativeScript;
//# sourceMappingURL=cmlToCore.d.ts.map

@@ -26,3 +26,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.nativeScript = exports.newTx = exports.utxo = exports.txAuxiliaryData = exports.txMetadata = exports.txMetadatum = exports.txWitnessSet = exports.txWitnessRedeemers = exports.txWitnessBootstrap = exports.txBody = exports.txMint = exports.txCertificates = exports.txInputs = exports.txOutputs = exports.txOut = exports.txIn = exports.value = exports.txWithdrawals = exports.txRequiredExtraSignatures = void 0;
exports.newTx = exports.utxo = exports.txAuxiliaryData = exports.txMetadata = exports.txMetadatum = exports.txWitnessSet = exports.txWitnessScripts = exports.nativeScript = exports.txWitnessDatums = exports.txWitnessRedeemers = exports.txWitnessBootstrap = exports.txBody = exports.txMint = exports.txCertificates = exports.txInputs = exports.txOutputs = exports.txOut = exports.txIn = exports.value = exports.txWithdrawals = exports.txRequiredExtraSignatures = void 0;
const Cardano = __importStar(require("../../Cardano"));

@@ -207,10 +207,11 @@ const CML_1 = require("../CML");

const reedeemer = scope.manage(redeemers.get(j));
const index = scope.manage(reedeemer.index());
const data = scope.manage(reedeemer.data());
const exUnits = scope.manage(reedeemer.ex_units());
const redeemerTagKind = scope.manage(reedeemer.tag()).kind();
result.push({
data: Cardano.util.HexBlob(Buffer.from(data.to_bytes()).toString()),
executionUnits: { memory: Number(scope.manage(exUnits.mem())), steps: Number(scope.manage(exUnits.steps())) },
index: Number(index),
data: Cardano.util.HexBlob.fromBytes(scope.manage(reedeemer.data()).to_bytes()),
executionUnits: {
memory: Number(scope.manage(exUnits.mem()).to_str()),
steps: Number(scope.manage(exUnits.steps()).to_str())
},
index: Number(scope.manage(reedeemer.index()).to_str()),
purpose: Object.values(Cardano.RedeemerPurpose)[redeemerTagKind]

@@ -222,5 +223,118 @@ });

exports.txWitnessRedeemers = txWitnessRedeemers;
const txWitnessDatums = (datums) => (0, util_1.usingAutoFree)((scope) => {
if (!datums)
return;
const result = [];
for (let j = 0; j < datums.len(); j++) {
result.push(Cardano.util.HexBlob.fromBytes(scope.manage(datums.get(j)).to_bytes()));
}
return result;
});
exports.txWitnessDatums = txWitnessDatums;
const nativeScript = (script) => (0, util_1.usingAutoFree)((scope) => {
let coreScript;
const scriptKind = script.kind();
switch (scriptKind) {
case Cardano.NativeScriptKind.RequireSignature: {
coreScript = {
__type: Cardano.ScriptType.Native,
keyHash: Cardano.Ed25519KeyHash((0, bytesToHex_1.bytesToHex)(scope.manage(scope.manage(script.as_script_pubkey()).addr_keyhash()).to_bytes()).toString()),
kind: Cardano.NativeScriptKind.RequireSignature
};
break;
}
case Cardano.NativeScriptKind.RequireAllOf: {
coreScript = {
__type: Cardano.ScriptType.Native,
kind: Cardano.NativeScriptKind.RequireAllOf,
scripts: new Array()
};
const scriptAll = scope.manage(script.as_script_all());
for (let i = 0; i < scope.manage(scriptAll.native_scripts()).len(); ++i) {
coreScript.scripts.push((0, exports.nativeScript)(scope.manage(scope.manage(scriptAll.native_scripts()).get(i))));
}
break;
}
case Cardano.NativeScriptKind.RequireAnyOf: {
coreScript = {
__type: Cardano.ScriptType.Native,
kind: Cardano.NativeScriptKind.RequireAnyOf,
scripts: new Array()
};
const scriptAny = scope.manage(script.as_script_any());
for (let i = 0; i < scope.manage(scriptAny.native_scripts()).len(); ++i) {
coreScript.scripts.push((0, exports.nativeScript)(scope.manage(scope.manage(scriptAny.native_scripts()).get(i))));
}
break;
}
case Cardano.NativeScriptKind.RequireNOf: {
const scriptMofK = scope.manage(script.as_script_n_of_k());
coreScript = {
__type: Cardano.ScriptType.Native,
kind: Cardano.NativeScriptKind.RequireNOf,
required: scriptMofK.n(),
scripts: new Array()
};
for (let i = 0; i < scope.manage(scriptMofK.native_scripts()).len(); ++i) {
coreScript.scripts.push((0, exports.nativeScript)(scope.manage(scope.manage(scriptMofK.native_scripts()).get(i))));
}
break;
}
case Cardano.NativeScriptKind.RequireTimeBefore: {
coreScript = {
__type: Cardano.ScriptType.Native,
kind: Cardano.NativeScriptKind.RequireTimeBefore,
slot: Cardano.Slot(Number(scope.manage(scope.manage(script.as_timelock_expiry()).slot()).to_str()))
};
break;
}
case Cardano.NativeScriptKind.RequireTimeAfter: {
coreScript = {
__type: Cardano.ScriptType.Native,
kind: Cardano.NativeScriptKind.RequireTimeAfter,
slot: Cardano.Slot(Number(scope.manage(scope.manage(script.as_timelock_start()).slot()).to_str()))
};
break;
}
default:
throw new errors_1.SerializationError(errors_1.SerializationFailure.InvalidNativeScriptKind, `Native Script Kind value '${scriptKind}' is not supported.`);
}
return coreScript;
});
exports.nativeScript = nativeScript;
const txWitnessScripts = (witnessSet) => (0, util_1.usingAutoFree)((scope) => {
const scripts = [];
const plutusScriptsV1 = scope.manage(witnessSet.plutus_v1_scripts());
const plutusScriptsV2 = scope.manage(witnessSet.plutus_v2_scripts());
const nativeScripts = scope.manage(witnessSet.native_scripts());
if (plutusScriptsV1) {
for (let i = 0; i < plutusScriptsV1.len(); ++i) {
scripts.push({
__type: Cardano.ScriptType.Plutus,
bytes: Cardano.util.HexBlob(scope.manage(plutusScriptsV1.get(i)).to_js_value()),
version: Cardano.PlutusLanguageVersion.V1
});
}
}
if (plutusScriptsV2) {
for (let i = 0; i < plutusScriptsV2.len(); ++i) {
scripts.push({
__type: Cardano.ScriptType.Plutus,
bytes: Cardano.util.HexBlob(scope.manage(plutusScriptsV2.get(i)).to_js_value()),
version: Cardano.PlutusLanguageVersion.V2
});
}
}
if (nativeScripts) {
for (let i = 0; i < nativeScripts.len(); ++i) {
scripts.push((0, exports.nativeScript)(scope.manage(nativeScripts.get(i))));
}
}
return scripts.length === 0 ? undefined : scripts;
});
exports.txWitnessScripts = txWitnessScripts;
const txWitnessSet = (witnessSet) => (0, util_1.usingAutoFree)((scope) => {
const vkeys = scope.manage(witnessSet.vkeys());
const redeemers = scope.manage(witnessSet.redeemers());
const plutusDatums = scope.manage(witnessSet.plutus_data());
const bootstraps = scope.manage(witnessSet.bootstraps());

@@ -236,3 +350,5 @@ const txSignatures = new Map();

bootstrap: (0, exports.txWitnessBootstrap)(bootstraps),
datums: (0, exports.txWitnessDatums)(plutusDatums),
redeemers: (0, exports.txWitnessRedeemers)(redeemers),
scripts: (0, exports.txWitnessScripts)(witnessSet),
signatures: txSignatures

@@ -319,73 +435,2 @@ };

exports.newTx = newTx;
const nativeScript = (script) => (0, util_1.usingAutoFree)((scope) => {
let coreScript;
const scriptKind = script.kind();
switch (scriptKind) {
case Cardano.NativeScriptKind.RequireSignature: {
coreScript = {
__type: Cardano.ScriptType.Native,
keyHash: Cardano.Ed25519KeyHash((0, bytesToHex_1.bytesToHex)(scope.manage(scope.manage(script.as_script_pubkey()).addr_keyhash()).to_bytes()).toString()),
kind: Cardano.NativeScriptKind.RequireSignature
};
break;
}
case Cardano.NativeScriptKind.RequireAllOf: {
coreScript = {
__type: Cardano.ScriptType.Native,
kind: Cardano.NativeScriptKind.RequireAllOf,
scripts: new Array()
};
const scriptAll = scope.manage(script.as_script_all());
for (let i = 0; i < scope.manage(scriptAll.native_scripts()).len(); ++i) {
coreScript.scripts.push((0, exports.nativeScript)(scope.manage(scope.manage(scriptAll.native_scripts()).get(i))));
}
break;
}
case Cardano.NativeScriptKind.RequireAnyOf: {
coreScript = {
__type: Cardano.ScriptType.Native,
kind: Cardano.NativeScriptKind.RequireAnyOf,
scripts: new Array()
};
const scriptAny = scope.manage(script.as_script_any());
for (let i = 0; i < scope.manage(scriptAny.native_scripts()).len(); ++i) {
coreScript.scripts.push((0, exports.nativeScript)(scope.manage(scope.manage(scriptAny.native_scripts()).get(i))));
}
break;
}
case Cardano.NativeScriptKind.RequireNOf: {
const scriptMofK = scope.manage(script.as_script_n_of_k());
coreScript = {
__type: Cardano.ScriptType.Native,
kind: Cardano.NativeScriptKind.RequireNOf,
required: scriptMofK.n(),
scripts: new Array()
};
for (let i = 0; i < scope.manage(scriptMofK.native_scripts()).len(); ++i) {
coreScript.scripts.push((0, exports.nativeScript)(scope.manage(scope.manage(scriptMofK.native_scripts()).get(i))));
}
break;
}
case Cardano.NativeScriptKind.RequireTimeBefore: {
coreScript = {
__type: Cardano.ScriptType.Native,
kind: Cardano.NativeScriptKind.RequireTimeBefore,
slot: Cardano.Slot(Number(scope.manage(scope.manage(script.as_timelock_expiry()).slot()).to_str()))
};
break;
}
case Cardano.NativeScriptKind.RequireTimeAfter: {
coreScript = {
__type: Cardano.ScriptType.Native,
kind: Cardano.NativeScriptKind.RequireTimeAfter,
slot: Cardano.Slot(Number(scope.manage(scope.manage(script.as_timelock_start()).slot()).to_str()))
};
break;
}
default:
throw new errors_1.SerializationError(errors_1.SerializationFailure.InvalidNativeScriptKind, `Native Script Kind value '${scriptKind}' is not supported.`);
}
return coreScript;
});
exports.nativeScript = nativeScript;
//# sourceMappingURL=cmlToCore.js.map
import * as Cardano from '../../Cardano';
import { AuxiliaryData, BootstrapWitness, BootstrapWitnesses, GeneralTransactionMetadata, Mint, MultiAsset, NativeScript, NativeScripts, PlutusV1Scripts, PlutusV2Scripts, Transaction, TransactionBody, TransactionInput, TransactionMetadatum, TransactionOutput, TransactionUnspentOutput, TransactionWitnessSet, Value } from '@dcspark/cardano-multiplatform-lib-nodejs';
import { AuxiliaryData, BootstrapWitness, BootstrapWitnesses, Datum, GeneralTransactionMetadata, Mint, MultiAsset, NativeScript, NativeScripts, PlutusList, PlutusV1Scripts, PlutusV2Scripts, Redeemer, Redeemers, Transaction, TransactionBody, TransactionInput, TransactionMetadatum, TransactionOutput, TransactionUnspentOutput, TransactionWitnessSet, Value } from '@dcspark/cardano-multiplatform-lib-nodejs';
import { CML } from '../CML';
import { ManagedFreeableScope } from '@cardano-sdk/util';

@@ -21,4 +22,6 @@ export declare const tokenMap: (scope: ManagedFreeableScope, map: Cardano.TokenMap) => MultiAsset;

export declare const txWitnessBootstrap: (scope: ManagedFreeableScope, bootstrap: Cardano.BootstrapWitness[]) => BootstrapWitnesses;
export declare const txWitnessRedeemers: (scope: ManagedFreeableScope, redeemers: Cardano.Redeemer[]) => Redeemers;
export declare const txWitnessDatumList: (scope: ManagedFreeableScope, datums: Cardano.Datum[]) => CML.PlutusList;
export declare const witnessSet: (scope: ManagedFreeableScope, witness: Cardano.Witness) => TransactionWitnessSet;
export declare const tx: (scope: ManagedFreeableScope, { body, witness, auxiliaryData }: Cardano.Tx) => Transaction;
//# sourceMappingURL=coreToCml.d.ts.map

@@ -26,6 +26,8 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.tx = exports.witnessSet = exports.txWitnessBootstrap = exports.txBody = exports.txAuxiliaryData = exports.getScripts = exports.nativeScript = exports.txMint = exports.txMetadata = exports.txMetadatum = exports.utxo = exports.txOut = exports.txIn = exports.value = exports.tokenMap = void 0;
exports.tx = exports.witnessSet = exports.txWitnessDatumList = exports.txWitnessRedeemers = exports.txWitnessBootstrap = exports.txBody = exports.txAuxiliaryData = exports.getScripts = exports.nativeScript = exports.txMint = exports.txMetadata = exports.txMetadatum = exports.utxo = exports.txOut = exports.txIn = exports.value = exports.tokenMap = void 0;
const Cardano = __importStar(require("../../Cardano"));
const cardano_multiplatform_lib_nodejs_1 = require("@dcspark/cardano-multiplatform-lib-nodejs");
const certificate = __importStar(require("./certificate"));
const CML_1 = require("../CML");
const Cardano_1 = require("../../Cardano");
const errors_1 = require("../../errors");

@@ -214,4 +216,11 @@ const assetId_1 = require("../../Asset/util/assetId");

case Cardano.ScriptType.Plutus:
if (script.version === Cardano.PlutusLanguageVersion.V1) {
plutusV1Scripts.add(cardano_multiplatform_lib_nodejs_1.PlutusV1Script.new(Buffer.from(script.bytes, 'hex')));
}
else if (script.version === Cardano.PlutusLanguageVersion.V2) {
plutusV2Scripts.add(cardano_multiplatform_lib_nodejs_1.PlutusV2Script.new(Buffer.from(script.bytes, 'hex')));
}
break;
default:
throw new errors_1.SerializationError(errors_1.SerializationFailure.InvalidScriptType, `Script Type value '${script.__type}' is not supported.`);
throw new errors_1.SerializationError(errors_1.SerializationFailure.InvalidScriptType, `Script '${script}' is not supported.`);
}

@@ -313,11 +322,37 @@ }

exports.txWitnessBootstrap = txWitnessBootstrap;
const mapRedeemerTag = (scope, redeemerPurpose) => {
switch (redeemerPurpose) {
case Cardano_1.RedeemerPurpose.spend:
return scope.manage(cardano_multiplatform_lib_nodejs_1.RedeemerTag.new_spend());
case Cardano_1.RedeemerPurpose.mint:
return scope.manage(cardano_multiplatform_lib_nodejs_1.RedeemerTag.new_mint());
case Cardano_1.RedeemerPurpose.certificate:
return scope.manage(cardano_multiplatform_lib_nodejs_1.RedeemerTag.new_cert());
case Cardano_1.RedeemerPurpose.withdrawal:
return scope.manage(cardano_multiplatform_lib_nodejs_1.RedeemerTag.new_reward());
}
};
const txWitnessRedeemers = (scope, redeemers) => {
const witnessRedeemers = scope.manage(cardano_multiplatform_lib_nodejs_1.Redeemers.new());
for (const redeemer of redeemers) {
const tag = mapRedeemerTag(scope, redeemer.purpose);
const index = scope.manage(cardano_multiplatform_lib_nodejs_1.BigNum.from_str(redeemer.index.toString()));
const data = scope.manage(cardano_multiplatform_lib_nodejs_1.PlutusData.from_bytes(Buffer.from(redeemer.data, 'hex')));
const units = scope.manage(cardano_multiplatform_lib_nodejs_1.ExUnits.new(scope.manage(cardano_multiplatform_lib_nodejs_1.BigNum.from_str(redeemer.executionUnits.memory.toString())), scope.manage(cardano_multiplatform_lib_nodejs_1.BigNum.from_str(redeemer.executionUnits.steps.toString()))));
witnessRedeemers.add(scope.manage(cardano_multiplatform_lib_nodejs_1.Redeemer.new(tag, index, data, units)));
}
return witnessRedeemers;
};
exports.txWitnessRedeemers = txWitnessRedeemers;
const txWitnessDatumList = (scope, datums) => {
const plutusDatumList = scope.manage(cardano_multiplatform_lib_nodejs_1.PlutusList.new());
for (const datum of datums) {
plutusDatumList.add(scope.manage(CML_1.CML.PlutusData.from_bytes(Buffer.from(datum.toString(), 'hex'))));
}
return plutusDatumList;
};
exports.txWitnessDatumList = txWitnessDatumList;
const witnessSet = (scope, witness) => {
const cslWitnessSet = scope.manage(cardano_multiplatform_lib_nodejs_1.TransactionWitnessSet.new());
const txWitnessSet = scope.manage(cardano_multiplatform_lib_nodejs_1.TransactionWitnessSet.new());
const vkeyWitnesses = scope.manage(cardano_multiplatform_lib_nodejs_1.Vkeywitnesses.new());
if (witness.scripts) {
const { nativeScripts, plutusV1Scripts, plutusV2Scripts } = (0, exports.getScripts)(scope, witness.scripts);
cslWitnessSet.set_native_scripts(nativeScripts);
cslWitnessSet.set_plutus_v1_scripts(plutusV1Scripts);
cslWitnessSet.set_plutus_v2_scripts(plutusV2Scripts);
}
for (const [vkey, signature] of witness.signatures.entries()) {

@@ -328,7 +363,19 @@ const publicKey = scope.manage(cardano_multiplatform_lib_nodejs_1.PublicKey.from_bytes(Buffer.from(vkey, 'hex')));

}
cslWitnessSet.set_vkeys(vkeyWitnesses);
txWitnessSet.set_vkeys(vkeyWitnesses);
if (witness.scripts) {
const { nativeScripts, plutusV1Scripts, plutusV2Scripts } = (0, exports.getScripts)(scope, witness.scripts);
txWitnessSet.set_native_scripts(nativeScripts);
txWitnessSet.set_plutus_v1_scripts(plutusV1Scripts);
txWitnessSet.set_plutus_v2_scripts(plutusV2Scripts);
}
if (witness.bootstrap) {
cslWitnessSet.set_bootstraps((0, exports.txWitnessBootstrap)(scope, witness.bootstrap));
txWitnessSet.set_bootstraps((0, exports.txWitnessBootstrap)(scope, witness.bootstrap));
}
return cslWitnessSet;
if (witness.redeemers) {
txWitnessSet.set_redeemers((0, exports.txWitnessRedeemers)(scope, witness.redeemers));
}
if (witness.datums) {
txWitnessSet.set_plutus_data((0, exports.txWitnessDatumList)(scope, witness.datums));
}
return txWitnessSet;
};

@@ -335,0 +382,0 @@ exports.witnessSet = witnessSet;

@@ -15,2 +15,5 @@ import * as Cardano from '../../Cardano';

export declare const txWitnessRedeemers: (redeemers?: CML.Redeemers) => Cardano.Redeemer[] | undefined;
export declare const txWitnessDatums: (datums?: CML.PlutusList) => Cardano.Datum[] | undefined;
export declare const nativeScript: (script: CML.NativeScript) => Cardano.NativeScript;
export declare const txWitnessScripts: (witnessSet: CML.TransactionWitnessSet) => Cardano.Script[] | undefined;
export declare const txWitnessSet: (witnessSet: CML.TransactionWitnessSet) => Cardano.Witness;

@@ -22,3 +25,2 @@ export declare const txMetadatum: (transactionMetadatum: CML.TransactionMetadatum) => Cardano.Metadatum;

export declare const newTx: (cslTx: CML.Transaction) => Cardano.Tx;
export declare const nativeScript: (script: CML.NativeScript) => Cardano.NativeScript;
//# sourceMappingURL=cmlToCore.d.ts.map

@@ -169,10 +169,11 @@ import * as Cardano from '../../Cardano';

const reedeemer = scope.manage(redeemers.get(j));
const index = scope.manage(reedeemer.index());
const data = scope.manage(reedeemer.data());
const exUnits = scope.manage(reedeemer.ex_units());
const redeemerTagKind = scope.manage(reedeemer.tag()).kind();
result.push({
data: Cardano.util.HexBlob(Buffer.from(data.to_bytes()).toString()),
executionUnits: { memory: Number(scope.manage(exUnits.mem())), steps: Number(scope.manage(exUnits.steps())) },
index: Number(index),
data: Cardano.util.HexBlob.fromBytes(scope.manage(reedeemer.data()).to_bytes()),
executionUnits: {
memory: Number(scope.manage(exUnits.mem()).to_str()),
steps: Number(scope.manage(exUnits.steps()).to_str())
},
index: Number(scope.manage(reedeemer.index()).to_str()),
purpose: Object.values(Cardano.RedeemerPurpose)[redeemerTagKind]

@@ -183,5 +184,115 @@ });

});
export const txWitnessDatums = (datums) => usingAutoFree((scope) => {
if (!datums)
return;
const result = [];
for (let j = 0; j < datums.len(); j++) {
result.push(Cardano.util.HexBlob.fromBytes(scope.manage(datums.get(j)).to_bytes()));
}
return result;
});
export const nativeScript = (script) => usingAutoFree((scope) => {
let coreScript;
const scriptKind = script.kind();
switch (scriptKind) {
case Cardano.NativeScriptKind.RequireSignature: {
coreScript = {
__type: Cardano.ScriptType.Native,
keyHash: Cardano.Ed25519KeyHash(bytesToHex(scope.manage(scope.manage(script.as_script_pubkey()).addr_keyhash()).to_bytes()).toString()),
kind: Cardano.NativeScriptKind.RequireSignature
};
break;
}
case Cardano.NativeScriptKind.RequireAllOf: {
coreScript = {
__type: Cardano.ScriptType.Native,
kind: Cardano.NativeScriptKind.RequireAllOf,
scripts: new Array()
};
const scriptAll = scope.manage(script.as_script_all());
for (let i = 0; i < scope.manage(scriptAll.native_scripts()).len(); ++i) {
coreScript.scripts.push(nativeScript(scope.manage(scope.manage(scriptAll.native_scripts()).get(i))));
}
break;
}
case Cardano.NativeScriptKind.RequireAnyOf: {
coreScript = {
__type: Cardano.ScriptType.Native,
kind: Cardano.NativeScriptKind.RequireAnyOf,
scripts: new Array()
};
const scriptAny = scope.manage(script.as_script_any());
for (let i = 0; i < scope.manage(scriptAny.native_scripts()).len(); ++i) {
coreScript.scripts.push(nativeScript(scope.manage(scope.manage(scriptAny.native_scripts()).get(i))));
}
break;
}
case Cardano.NativeScriptKind.RequireNOf: {
const scriptMofK = scope.manage(script.as_script_n_of_k());
coreScript = {
__type: Cardano.ScriptType.Native,
kind: Cardano.NativeScriptKind.RequireNOf,
required: scriptMofK.n(),
scripts: new Array()
};
for (let i = 0; i < scope.manage(scriptMofK.native_scripts()).len(); ++i) {
coreScript.scripts.push(nativeScript(scope.manage(scope.manage(scriptMofK.native_scripts()).get(i))));
}
break;
}
case Cardano.NativeScriptKind.RequireTimeBefore: {
coreScript = {
__type: Cardano.ScriptType.Native,
kind: Cardano.NativeScriptKind.RequireTimeBefore,
slot: Cardano.Slot(Number(scope.manage(scope.manage(script.as_timelock_expiry()).slot()).to_str()))
};
break;
}
case Cardano.NativeScriptKind.RequireTimeAfter: {
coreScript = {
__type: Cardano.ScriptType.Native,
kind: Cardano.NativeScriptKind.RequireTimeAfter,
slot: Cardano.Slot(Number(scope.manage(scope.manage(script.as_timelock_start()).slot()).to_str()))
};
break;
}
default:
throw new SerializationError(SerializationFailure.InvalidNativeScriptKind, `Native Script Kind value '${scriptKind}' is not supported.`);
}
return coreScript;
});
export const txWitnessScripts = (witnessSet) => usingAutoFree((scope) => {
const scripts = [];
const plutusScriptsV1 = scope.manage(witnessSet.plutus_v1_scripts());
const plutusScriptsV2 = scope.manage(witnessSet.plutus_v2_scripts());
const nativeScripts = scope.manage(witnessSet.native_scripts());
if (plutusScriptsV1) {
for (let i = 0; i < plutusScriptsV1.len(); ++i) {
scripts.push({
__type: Cardano.ScriptType.Plutus,
bytes: Cardano.util.HexBlob(scope.manage(plutusScriptsV1.get(i)).to_js_value()),
version: Cardano.PlutusLanguageVersion.V1
});
}
}
if (plutusScriptsV2) {
for (let i = 0; i < plutusScriptsV2.len(); ++i) {
scripts.push({
__type: Cardano.ScriptType.Plutus,
bytes: Cardano.util.HexBlob(scope.manage(plutusScriptsV2.get(i)).to_js_value()),
version: Cardano.PlutusLanguageVersion.V2
});
}
}
if (nativeScripts) {
for (let i = 0; i < nativeScripts.len(); ++i) {
scripts.push(nativeScript(scope.manage(nativeScripts.get(i))));
}
}
return scripts.length === 0 ? undefined : scripts;
});
export const txWitnessSet = (witnessSet) => usingAutoFree((scope) => {
const vkeys = scope.manage(witnessSet.vkeys());
const redeemers = scope.manage(witnessSet.redeemers());
const plutusDatums = scope.manage(witnessSet.plutus_data());
const bootstraps = scope.manage(witnessSet.bootstraps());

@@ -197,3 +308,5 @@ const txSignatures = new Map();

bootstrap: txWitnessBootstrap(bootstraps),
datums: txWitnessDatums(plutusDatums),
redeemers: txWitnessRedeemers(redeemers),
scripts: txWitnessScripts(witnessSet),
signatures: txSignatures

@@ -274,72 +387,2 @@ };

});
export const nativeScript = (script) => usingAutoFree((scope) => {
let coreScript;
const scriptKind = script.kind();
switch (scriptKind) {
case Cardano.NativeScriptKind.RequireSignature: {
coreScript = {
__type: Cardano.ScriptType.Native,
keyHash: Cardano.Ed25519KeyHash(bytesToHex(scope.manage(scope.manage(script.as_script_pubkey()).addr_keyhash()).to_bytes()).toString()),
kind: Cardano.NativeScriptKind.RequireSignature
};
break;
}
case Cardano.NativeScriptKind.RequireAllOf: {
coreScript = {
__type: Cardano.ScriptType.Native,
kind: Cardano.NativeScriptKind.RequireAllOf,
scripts: new Array()
};
const scriptAll = scope.manage(script.as_script_all());
for (let i = 0; i < scope.manage(scriptAll.native_scripts()).len(); ++i) {
coreScript.scripts.push(nativeScript(scope.manage(scope.manage(scriptAll.native_scripts()).get(i))));
}
break;
}
case Cardano.NativeScriptKind.RequireAnyOf: {
coreScript = {
__type: Cardano.ScriptType.Native,
kind: Cardano.NativeScriptKind.RequireAnyOf,
scripts: new Array()
};
const scriptAny = scope.manage(script.as_script_any());
for (let i = 0; i < scope.manage(scriptAny.native_scripts()).len(); ++i) {
coreScript.scripts.push(nativeScript(scope.manage(scope.manage(scriptAny.native_scripts()).get(i))));
}
break;
}
case Cardano.NativeScriptKind.RequireNOf: {
const scriptMofK = scope.manage(script.as_script_n_of_k());
coreScript = {
__type: Cardano.ScriptType.Native,
kind: Cardano.NativeScriptKind.RequireNOf,
required: scriptMofK.n(),
scripts: new Array()
};
for (let i = 0; i < scope.manage(scriptMofK.native_scripts()).len(); ++i) {
coreScript.scripts.push(nativeScript(scope.manage(scope.manage(scriptMofK.native_scripts()).get(i))));
}
break;
}
case Cardano.NativeScriptKind.RequireTimeBefore: {
coreScript = {
__type: Cardano.ScriptType.Native,
kind: Cardano.NativeScriptKind.RequireTimeBefore,
slot: Cardano.Slot(Number(scope.manage(scope.manage(script.as_timelock_expiry()).slot()).to_str()))
};
break;
}
case Cardano.NativeScriptKind.RequireTimeAfter: {
coreScript = {
__type: Cardano.ScriptType.Native,
kind: Cardano.NativeScriptKind.RequireTimeAfter,
slot: Cardano.Slot(Number(scope.manage(scope.manage(script.as_timelock_start()).slot()).to_str()))
};
break;
}
default:
throw new SerializationError(SerializationFailure.InvalidNativeScriptKind, `Native Script Kind value '${scriptKind}' is not supported.`);
}
return coreScript;
});
//# sourceMappingURL=cmlToCore.js.map
import * as Cardano from '../../Cardano';
import { AuxiliaryData, BootstrapWitness, BootstrapWitnesses, GeneralTransactionMetadata, Mint, MultiAsset, NativeScript, NativeScripts, PlutusV1Scripts, PlutusV2Scripts, Transaction, TransactionBody, TransactionInput, TransactionMetadatum, TransactionOutput, TransactionUnspentOutput, TransactionWitnessSet, Value } from '@dcspark/cardano-multiplatform-lib-nodejs';
import { AuxiliaryData, BootstrapWitness, BootstrapWitnesses, Datum, GeneralTransactionMetadata, Mint, MultiAsset, NativeScript, NativeScripts, PlutusList, PlutusV1Scripts, PlutusV2Scripts, Redeemer, Redeemers, Transaction, TransactionBody, TransactionInput, TransactionMetadatum, TransactionOutput, TransactionUnspentOutput, TransactionWitnessSet, Value } from '@dcspark/cardano-multiplatform-lib-nodejs';
import { CML } from '../CML';
import { ManagedFreeableScope } from '@cardano-sdk/util';

@@ -21,4 +22,6 @@ export declare const tokenMap: (scope: ManagedFreeableScope, map: Cardano.TokenMap) => MultiAsset;

export declare const txWitnessBootstrap: (scope: ManagedFreeableScope, bootstrap: Cardano.BootstrapWitness[]) => BootstrapWitnesses;
export declare const txWitnessRedeemers: (scope: ManagedFreeableScope, redeemers: Cardano.Redeemer[]) => Redeemers;
export declare const txWitnessDatumList: (scope: ManagedFreeableScope, datums: Cardano.Datum[]) => CML.PlutusList;
export declare const witnessSet: (scope: ManagedFreeableScope, witness: Cardano.Witness) => TransactionWitnessSet;
export declare const tx: (scope: ManagedFreeableScope, { body, witness, auxiliaryData }: Cardano.Tx) => Transaction;
//# sourceMappingURL=coreToCml.d.ts.map
import * as Cardano from '../../Cardano';
import { AddrAttributes, Address, AssetName, Assets, AuxiliaryData, BigNum, BootstrapWitness, BootstrapWitnesses, Certificates, DataHash, Datum, Ed25519KeyHash, Ed25519KeyHashes, Ed25519Signature, GeneralTransactionMetadata, Int, MetadataList, MetadataMap, Mint, MintAssets, MultiAsset, NativeScript, NativeScripts, PlutusV1Scripts, PlutusV2Scripts, PublicKey, RewardAddress, ScriptAll, ScriptAny, ScriptDataHash, ScriptHash, ScriptNOfK, ScriptPubkey, TimelockExpiry, TimelockStart, Transaction, TransactionBody, TransactionHash, TransactionInput, TransactionInputs, TransactionMetadatum, TransactionOutput, TransactionOutputs, TransactionUnspentOutput, TransactionWitnessSet, Value, Vkey, Vkeywitness, Vkeywitnesses, Withdrawals, hash_auxiliary_data } from '@dcspark/cardano-multiplatform-lib-nodejs';
import { AddrAttributes, Address, AssetName, Assets, AuxiliaryData, BigNum, BootstrapWitness, BootstrapWitnesses, Certificates, DataHash, Datum, Ed25519KeyHash, Ed25519KeyHashes, Ed25519Signature, ExUnits, GeneralTransactionMetadata, Int, MetadataList, MetadataMap, Mint, MintAssets, MultiAsset, NativeScript, NativeScripts, PlutusData, PlutusList, PlutusV1Script, PlutusV1Scripts, PlutusV2Script, PlutusV2Scripts, PublicKey, Redeemer, RedeemerTag, Redeemers, RewardAddress, ScriptAll, ScriptAny, ScriptDataHash, ScriptHash, ScriptNOfK, ScriptPubkey, TimelockExpiry, TimelockStart, Transaction, TransactionBody, TransactionHash, TransactionInput, TransactionInputs, TransactionMetadatum, TransactionOutput, TransactionOutputs, TransactionUnspentOutput, TransactionWitnessSet, Value, Vkey, Vkeywitness, Vkeywitnesses, Withdrawals, hash_auxiliary_data } from '@dcspark/cardano-multiplatform-lib-nodejs';
import * as certificate from './certificate';
import { CML } from '../CML';
import { RedeemerPurpose } from '../../Cardano';
import { SerializationError, SerializationFailure } from '../../errors';

@@ -178,4 +180,11 @@ import { assetNameFromAssetId, parseAssetId, policyIdFromAssetId } from '../../Asset/util/assetId';

case Cardano.ScriptType.Plutus:
if (script.version === Cardano.PlutusLanguageVersion.V1) {
plutusV1Scripts.add(PlutusV1Script.new(Buffer.from(script.bytes, 'hex')));
}
else if (script.version === Cardano.PlutusLanguageVersion.V2) {
plutusV2Scripts.add(PlutusV2Script.new(Buffer.from(script.bytes, 'hex')));
}
break;
default:
throw new SerializationError(SerializationFailure.InvalidScriptType, `Script Type value '${script.__type}' is not supported.`);
throw new SerializationError(SerializationFailure.InvalidScriptType, `Script '${script}' is not supported.`);
}

@@ -273,11 +282,35 @@ }

};
const mapRedeemerTag = (scope, redeemerPurpose) => {
switch (redeemerPurpose) {
case RedeemerPurpose.spend:
return scope.manage(RedeemerTag.new_spend());
case RedeemerPurpose.mint:
return scope.manage(RedeemerTag.new_mint());
case RedeemerPurpose.certificate:
return scope.manage(RedeemerTag.new_cert());
case RedeemerPurpose.withdrawal:
return scope.manage(RedeemerTag.new_reward());
}
};
export const txWitnessRedeemers = (scope, redeemers) => {
const witnessRedeemers = scope.manage(Redeemers.new());
for (const redeemer of redeemers) {
const tag = mapRedeemerTag(scope, redeemer.purpose);
const index = scope.manage(BigNum.from_str(redeemer.index.toString()));
const data = scope.manage(PlutusData.from_bytes(Buffer.from(redeemer.data, 'hex')));
const units = scope.manage(ExUnits.new(scope.manage(BigNum.from_str(redeemer.executionUnits.memory.toString())), scope.manage(BigNum.from_str(redeemer.executionUnits.steps.toString()))));
witnessRedeemers.add(scope.manage(Redeemer.new(tag, index, data, units)));
}
return witnessRedeemers;
};
export const txWitnessDatumList = (scope, datums) => {
const plutusDatumList = scope.manage(PlutusList.new());
for (const datum of datums) {
plutusDatumList.add(scope.manage(CML.PlutusData.from_bytes(Buffer.from(datum.toString(), 'hex'))));
}
return plutusDatumList;
};
export const witnessSet = (scope, witness) => {
const cslWitnessSet = scope.manage(TransactionWitnessSet.new());
const txWitnessSet = scope.manage(TransactionWitnessSet.new());
const vkeyWitnesses = scope.manage(Vkeywitnesses.new());
if (witness.scripts) {
const { nativeScripts, plutusV1Scripts, plutusV2Scripts } = getScripts(scope, witness.scripts);
cslWitnessSet.set_native_scripts(nativeScripts);
cslWitnessSet.set_plutus_v1_scripts(plutusV1Scripts);
cslWitnessSet.set_plutus_v2_scripts(plutusV2Scripts);
}
for (const [vkey, signature] of witness.signatures.entries()) {

@@ -288,7 +321,19 @@ const publicKey = scope.manage(PublicKey.from_bytes(Buffer.from(vkey, 'hex')));

}
cslWitnessSet.set_vkeys(vkeyWitnesses);
txWitnessSet.set_vkeys(vkeyWitnesses);
if (witness.scripts) {
const { nativeScripts, plutusV1Scripts, plutusV2Scripts } = getScripts(scope, witness.scripts);
txWitnessSet.set_native_scripts(nativeScripts);
txWitnessSet.set_plutus_v1_scripts(plutusV1Scripts);
txWitnessSet.set_plutus_v2_scripts(plutusV2Scripts);
}
if (witness.bootstrap) {
cslWitnessSet.set_bootstraps(txWitnessBootstrap(scope, witness.bootstrap));
txWitnessSet.set_bootstraps(txWitnessBootstrap(scope, witness.bootstrap));
}
return cslWitnessSet;
if (witness.redeemers) {
txWitnessSet.set_redeemers(txWitnessRedeemers(scope, witness.redeemers));
}
if (witness.datums) {
txWitnessSet.set_plutus_data(txWitnessDatumList(scope, witness.datums));
}
return txWitnessSet;
};

@@ -295,0 +340,0 @@ export const tx = (scope, { body, witness, auxiliaryData }) => {

{
"name": "@cardano-sdk/core",
"version": "0.7.0-nightly.5",
"version": "0.7.0-nightly.6",
"description": "Core types and libraries for Cardano",

@@ -81,3 +81,3 @@ "engines": {

],
"gitHead": "b17861e618a4b4bc063e6f65e904cef1bccaec1d"
"gitHead": "fda0711e622cb1fac6c374e74bfa490564cce659"
}

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

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc