@cardano-sdk/core
Advanced tools
Comparing version 0.5.0-nightly.4 to 0.5.0-nightly.5
@@ -19,5 +19,5 @@ import * as Ogmios from '@cardano-ogmios/schema'; | ||
export * from './TxSubmissionErrors'; | ||
export * as NativeScriptType from './NativeScriptType'; | ||
export * from './NativeScript'; | ||
export declare type ProtocolParametersBabbage = OptionalUndefined<RecursivelyReplaceNullWithUndefined<Ogmios.ProtocolParametersBabbage>>; | ||
export declare type ValidityInterval = OptionalUndefined<RecursivelyReplaceNullWithUndefined<Ogmios.ValidityInterval>>; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -13,19 +13,7 @@ "use strict"; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.NativeScriptType = exports.Hash28ByteBase16 = exports.Hash32ByteBase16 = void 0; | ||
exports.Hash28ByteBase16 = exports.Hash32ByteBase16 = void 0; | ||
var util_1 = require("../util"); | ||
@@ -48,3 +36,3 @@ Object.defineProperty(exports, "Hash32ByteBase16", { enumerable: true, get: function () { return util_1.Hash32ByteBase16; } }); | ||
__exportStar(require("./TxSubmissionErrors"), exports); | ||
exports.NativeScriptType = __importStar(require("./NativeScriptType")); | ||
__exportStar(require("./NativeScript"), exports); | ||
//# sourceMappingURL=index.js.map |
import * as Cardano from '../../Cardano'; | ||
import { AuxiliaryData, GeneralTransactionMetadata, Mint, MultiAsset, Transaction, TransactionBody, TransactionInput, TransactionMetadatum, TransactionOutput, TransactionUnspentOutput, TransactionWitnessSet, Value } from '@emurgo/cardano-serialization-lib-nodejs'; | ||
import { AuxiliaryData, GeneralTransactionMetadata, Mint, MultiAsset, NativeScript, Transaction, TransactionBody, TransactionInput, TransactionMetadatum, TransactionOutput, TransactionUnspentOutput, TransactionWitnessSet, Value } from '@emurgo/cardano-serialization-lib-nodejs'; | ||
export declare const tokenMap: (map: Cardano.TokenMap) => MultiAsset; | ||
@@ -15,2 +15,3 @@ export declare const value: ({ coins, assets }: Cardano.Value) => Value; | ||
export declare const tx: ({ body, witness, auxiliaryData }: Cardano.NewTxAlonzo) => Transaction; | ||
export declare const nativeScript: (script: Cardano.NativeScript) => NativeScript; | ||
//# sourceMappingURL=coreToCsl.d.ts.map |
@@ -26,7 +26,7 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.tx = exports.witnessSet = exports.txBody = exports.txAuxiliaryData = exports.txMint = exports.txMetadata = exports.txMetadatum = exports.utxo = exports.txOut = exports.txIn = exports.value = exports.tokenMap = void 0; | ||
exports.nativeScript = exports.tx = exports.witnessSet = exports.txBody = exports.txAuxiliaryData = exports.txMint = exports.txMetadata = exports.txMetadatum = exports.utxo = exports.txOut = exports.txIn = exports.value = exports.tokenMap = void 0; | ||
const Asset = __importStar(require("../../Asset")); | ||
const Cardano = __importStar(require("../../Cardano")); | ||
const cardano_serialization_lib_nodejs_1 = require("@emurgo/cardano-serialization-lib-nodejs"); | ||
const certificate = __importStar(require("./certificate")); | ||
const errors_1 = require("../../errors"); | ||
const __1 = require("../.."); | ||
@@ -79,7 +79,7 @@ const parseCslAddress_1 = require("../parseCslAddress"); | ||
if (len > 64) | ||
throw new errors_1.SerializationError(__1.SerializationFailure.MaxLengthLimit, `Metadatum value '${metadatum}' is too long. Length is ${len}. Max length is 64 bytes`); | ||
throw new __1.SerializationError(__1.SerializationFailure.MaxLengthLimit, `Metadatum value '${metadatum}' is too long. Length is ${len}. Max length is 64 bytes`); | ||
}; | ||
const txMetadatum = (metadatum) => { | ||
if (metadatum === null) | ||
throw new errors_1.SerializationError(__1.SerializationFailure.InvalidType); | ||
throw new __1.SerializationError(__1.SerializationFailure.InvalidType); | ||
switch (typeof metadatum) { | ||
@@ -89,3 +89,3 @@ case 'number': | ||
case 'undefined': | ||
throw new errors_1.SerializationError(__1.SerializationFailure.InvalidType); | ||
throw new __1.SerializationError(__1.SerializationFailure.InvalidType); | ||
case 'bigint': { | ||
@@ -182,3 +182,3 @@ const cslInt = metadatum >= 0 | ||
if (!cslAddress) { | ||
throw new errors_1.SerializationError(__1.SerializationFailure.InvalidAddress, `Invalid withdrawal address: ${stakeAddress}`); | ||
throw new __1.SerializationError(__1.SerializationFailure.InvalidAddress, `Invalid withdrawal address: ${stakeAddress}`); | ||
} | ||
@@ -244,2 +244,48 @@ cslWithdrawals.insert(cslAddress, cardano_serialization_lib_nodejs_1.BigNum.from_str(quantity.toString())); | ||
exports.tx = tx; | ||
const nativeScript = (script) => { | ||
let cslScript; | ||
const type = script.__type; | ||
switch (type) { | ||
case Cardano.NativeScriptType.RequireSignature: { | ||
cslScript = cardano_serialization_lib_nodejs_1.NativeScript.new_script_pubkey(cardano_serialization_lib_nodejs_1.ScriptPubkey.new(cardano_serialization_lib_nodejs_1.Ed25519KeyHash.from_bytes(Buffer.from(script.keyHash, 'hex')))); | ||
break; | ||
} | ||
case Cardano.NativeScriptType.RequireAllOf: { | ||
const cslScripts = cardano_serialization_lib_nodejs_1.NativeScripts.new(); | ||
for (const subscript of script.scripts) { | ||
cslScripts.add((0, exports.nativeScript)(subscript)); | ||
} | ||
cslScript = cardano_serialization_lib_nodejs_1.NativeScript.new_script_all(cardano_serialization_lib_nodejs_1.ScriptAll.new(cslScripts)); | ||
break; | ||
} | ||
case Cardano.NativeScriptType.RequireAnyOf: { | ||
const cslScripts2 = cardano_serialization_lib_nodejs_1.NativeScripts.new(); | ||
for (const subscript of script.scripts) { | ||
cslScripts2.add((0, exports.nativeScript)(subscript)); | ||
} | ||
cslScript = cardano_serialization_lib_nodejs_1.NativeScript.new_script_any(cardano_serialization_lib_nodejs_1.ScriptAny.new(cslScripts2)); | ||
break; | ||
} | ||
case Cardano.NativeScriptType.RequireMOf: { | ||
const cslScripts3 = cardano_serialization_lib_nodejs_1.NativeScripts.new(); | ||
for (const subscript of script.scripts) { | ||
cslScripts3.add((0, exports.nativeScript)(subscript)); | ||
} | ||
cslScript = cardano_serialization_lib_nodejs_1.NativeScript.new_script_n_of_k(cardano_serialization_lib_nodejs_1.ScriptNOfK.new(script.required, cslScripts3)); | ||
break; | ||
} | ||
case Cardano.NativeScriptType.RequireTimeBefore: { | ||
cslScript = cardano_serialization_lib_nodejs_1.NativeScript.new_timelock_expiry(cardano_serialization_lib_nodejs_1.TimelockExpiry.new_timelockexpiry(cardano_serialization_lib_nodejs_1.BigNum.from_str(script.slot.toString()))); | ||
break; | ||
} | ||
case Cardano.NativeScriptType.RequireTimeAfter: { | ||
cslScript = cardano_serialization_lib_nodejs_1.NativeScript.new_timelock_start(cardano_serialization_lib_nodejs_1.TimelockStart.new_timelockstart(cardano_serialization_lib_nodejs_1.BigNum.from_str(script.slot.toString()))); | ||
break; | ||
} | ||
default: | ||
throw new __1.SerializationError(__1.SerializationFailure.InvalidNativeScriptType, `Native Script Type value '${type}' is not supported.`); | ||
} | ||
return cslScript; | ||
}; | ||
exports.nativeScript = nativeScript; | ||
//# sourceMappingURL=coreToCsl.js.map |
import { CSL, Cardano } from '../..'; | ||
import { BootstrapWitness } from '@cardano-ogmios/schema'; | ||
import { Ed25519KeyHash } from '../../Cardano'; | ||
import { NativeScript } from '@emurgo/cardano-serialization-lib-nodejs'; | ||
export declare const txRequiredExtraSignatures: (signatures: CSL.Ed25519KeyHashes | undefined) => Cardano.Ed25519KeyHash[] | undefined; | ||
@@ -20,2 +22,11 @@ export declare const txWithdrawals: (withdrawals?: CSL.Withdrawals) => Cardano.Withdrawal[] | undefined; | ||
export declare const newTx: (cslTx: CSL.Transaction) => Cardano.NewTxAlonzo; | ||
export declare enum NativeScriptKind { | ||
RequireSignature = 0, | ||
RequireAllOf = 1, | ||
RequireAnyOf = 2, | ||
RequireMOf = 3, | ||
RequireTimeAfter = 4, | ||
RequireTimeBefore = 5 | ||
} | ||
export declare const nativeScript: (script: NativeScript) => Cardano.NativeScript; | ||
//# sourceMappingURL=cslToCore.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.newTx = exports.utxo = exports.txAuxiliaryData = exports.txMetadata = exports.txWitnessSet = exports.txRedeemers = exports.txBootstrap = exports.txBody = exports.txMint = exports.txCertificates = exports.txInputs = exports.txOutputs = exports.txOut = exports.txIn = exports.value = exports.txWithdrawals = exports.txRequiredExtraSignatures = void 0; | ||
exports.nativeScript = exports.NativeScriptKind = exports.newTx = exports.utxo = exports.txAuxiliaryData = exports.txMetadata = exports.txWitnessSet = exports.txRedeemers = exports.txBootstrap = exports.txBody = exports.txMint = exports.txCertificates = exports.txInputs = exports.txOutputs = exports.txOut = exports.txIn = exports.value = exports.txWithdrawals = exports.txRequiredExtraSignatures = void 0; | ||
const __1 = require("../.."); | ||
const Cardano_1 = require("../../Cardano"); | ||
const errors_1 = require("../../errors"); | ||
@@ -274,2 +275,64 @@ const certificate_1 = require("./certificate"); | ||
exports.newTx = newTx; | ||
var NativeScriptKind; | ||
(function (NativeScriptKind) { | ||
NativeScriptKind[NativeScriptKind["RequireSignature"] = 0] = "RequireSignature"; | ||
NativeScriptKind[NativeScriptKind["RequireAllOf"] = 1] = "RequireAllOf"; | ||
NativeScriptKind[NativeScriptKind["RequireAnyOf"] = 2] = "RequireAnyOf"; | ||
NativeScriptKind[NativeScriptKind["RequireMOf"] = 3] = "RequireMOf"; | ||
NativeScriptKind[NativeScriptKind["RequireTimeAfter"] = 4] = "RequireTimeAfter"; | ||
NativeScriptKind[NativeScriptKind["RequireTimeBefore"] = 5] = "RequireTimeBefore"; | ||
})(NativeScriptKind = exports.NativeScriptKind || (exports.NativeScriptKind = {})); | ||
const nativeScript = (script) => { | ||
let coreScript; | ||
const scriptKind = script.kind(); | ||
switch (scriptKind) { | ||
case NativeScriptKind.RequireSignature: { | ||
coreScript = { | ||
__type: Cardano_1.NativeScriptType.RequireSignature, | ||
keyHash: (0, Cardano_1.Ed25519KeyHash)(__1.util.bytesToHex(script.as_script_pubkey().addr_keyhash().to_bytes()).toString()) | ||
}; | ||
break; | ||
} | ||
case NativeScriptKind.RequireAllOf: { | ||
coreScript = { __type: Cardano_1.NativeScriptType.RequireAllOf, scripts: new Array() }; | ||
const scriptAll = script.as_script_all(); | ||
for (let i = 0; i < scriptAll.native_scripts().len(); ++i) { | ||
coreScript.scripts.push((0, exports.nativeScript)(scriptAll.native_scripts().get(i))); | ||
} | ||
break; | ||
} | ||
case NativeScriptKind.RequireAnyOf: { | ||
coreScript = { __type: Cardano_1.NativeScriptType.RequireAnyOf, scripts: new Array() }; | ||
const scriptAny = script.as_script_any(); | ||
for (let i = 0; i < scriptAny.native_scripts().len(); ++i) { | ||
coreScript.scripts.push((0, exports.nativeScript)(scriptAny.native_scripts().get(i))); | ||
} | ||
break; | ||
} | ||
case NativeScriptKind.RequireMOf: { | ||
const scriptMofK = script.as_script_n_of_k(); | ||
coreScript = { | ||
__type: Cardano_1.NativeScriptType.RequireMOf, | ||
required: scriptMofK.n(), | ||
scripts: new Array() | ||
}; | ||
for (let i = 0; i < scriptMofK.native_scripts().len(); ++i) { | ||
coreScript.scripts.push((0, exports.nativeScript)(scriptMofK.native_scripts().get(i))); | ||
} | ||
break; | ||
} | ||
case NativeScriptKind.RequireTimeBefore: { | ||
coreScript = { __type: Cardano_1.NativeScriptType.RequireTimeBefore, slot: script.as_timelock_expiry().slot() }; | ||
break; | ||
} | ||
case NativeScriptKind.RequireTimeAfter: { | ||
coreScript = { __type: Cardano_1.NativeScriptType.RequireTimeAfter, slot: script.as_timelock_start().slot() }; | ||
break; | ||
} | ||
default: | ||
throw new errors_1.SerializationError(__1.SerializationFailure.InvalidNativeScriptType, `Native Script Kind value '${scriptKind}' is not supported.`); | ||
} | ||
return coreScript; | ||
}; | ||
exports.nativeScript = nativeScript; | ||
//# sourceMappingURL=cslToCore.js.map |
@@ -21,3 +21,4 @@ import { CustomError } from 'ts-custom-error'; | ||
InvalidAddress = "INVALID_ADDRESS", | ||
MaxLengthLimit = "MAX_LENGTH_LIMIT" | ||
MaxLengthLimit = "MAX_LENGTH_LIMIT", | ||
InvalidNativeScriptType = "INVALID_NATIVE_SCRIPT_TYPE" | ||
} | ||
@@ -24,0 +25,0 @@ export declare class SerializationError extends CustomError { |
@@ -31,2 +31,3 @@ "use strict"; | ||
SerializationFailure["MaxLengthLimit"] = "MAX_LENGTH_LIMIT"; | ||
SerializationFailure["InvalidNativeScriptType"] = "INVALID_NATIVE_SCRIPT_TYPE"; | ||
})(SerializationFailure = exports.SerializationFailure || (exports.SerializationFailure = {})); | ||
@@ -33,0 +34,0 @@ class SerializationError extends ts_custom_error_1.CustomError { |
@@ -19,5 +19,5 @@ import * as Ogmios from '@cardano-ogmios/schema'; | ||
export * from './TxSubmissionErrors'; | ||
export * as NativeScriptType from './NativeScriptType'; | ||
export * from './NativeScript'; | ||
export declare type ProtocolParametersBabbage = OptionalUndefined<RecursivelyReplaceNullWithUndefined<Ogmios.ProtocolParametersBabbage>>; | ||
export declare type ValidityInterval = OptionalUndefined<RecursivelyReplaceNullWithUndefined<Ogmios.ValidityInterval>>; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -16,3 +16,3 @@ export { Hash32ByteBase16, Hash28ByteBase16 } from '../util'; | ||
export * from './TxSubmissionErrors'; | ||
export * as NativeScriptType from './NativeScriptType'; | ||
export * from './NativeScript'; | ||
//# sourceMappingURL=index.js.map |
import * as Cardano from '../../Cardano'; | ||
import { AuxiliaryData, GeneralTransactionMetadata, Mint, MultiAsset, Transaction, TransactionBody, TransactionInput, TransactionMetadatum, TransactionOutput, TransactionUnspentOutput, TransactionWitnessSet, Value } from '@emurgo/cardano-serialization-lib-nodejs'; | ||
import { AuxiliaryData, GeneralTransactionMetadata, Mint, MultiAsset, NativeScript, Transaction, TransactionBody, TransactionInput, TransactionMetadatum, TransactionOutput, TransactionUnspentOutput, TransactionWitnessSet, Value } from '@emurgo/cardano-serialization-lib-nodejs'; | ||
export declare const tokenMap: (map: Cardano.TokenMap) => MultiAsset; | ||
@@ -15,2 +15,3 @@ export declare const value: ({ coins, assets }: Cardano.Value) => Value; | ||
export declare const tx: ({ body, witness, auxiliaryData }: Cardano.NewTxAlonzo) => Transaction; | ||
export declare const nativeScript: (script: Cardano.NativeScript) => NativeScript; | ||
//# sourceMappingURL=coreToCsl.d.ts.map |
import * as Asset from '../../Asset'; | ||
import { Address, AssetName, Assets, AuxiliaryData, BigNum, Certificates, Ed25519KeyHash, Ed25519KeyHashes, Ed25519Signature, GeneralTransactionMetadata, Int, MetadataList, MetadataMap, Mint, MintAssets, MultiAsset, PublicKey, RewardAddress, ScriptDataHash, ScriptHash, Transaction, TransactionBody, TransactionHash, TransactionInput, TransactionInputs, TransactionMetadatum, TransactionOutput, TransactionOutputs, TransactionUnspentOutput, TransactionWitnessSet, Value, Vkey, Vkeywitness, Vkeywitnesses, Withdrawals, hash_auxiliary_data } from '@emurgo/cardano-serialization-lib-nodejs'; | ||
import * as Cardano from '../../Cardano'; | ||
import { Address, AssetName, Assets, AuxiliaryData, BigNum, Certificates, Ed25519KeyHash, Ed25519KeyHashes, Ed25519Signature, GeneralTransactionMetadata, Int, MetadataList, MetadataMap, Mint, MintAssets, MultiAsset, NativeScript, NativeScripts, 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 '@emurgo/cardano-serialization-lib-nodejs'; | ||
import * as certificate from './certificate'; | ||
import { SerializationError } from '../../errors'; | ||
import { SerializationFailure } from '../..'; | ||
import { SerializationError, SerializationFailure } from '../..'; | ||
import { parseCslAddress } from '../parseCslAddress'; | ||
@@ -202,2 +202,47 @@ export const tokenMap = (map) => { | ||
}; | ||
export const nativeScript = (script) => { | ||
let cslScript; | ||
const type = script.__type; | ||
switch (type) { | ||
case Cardano.NativeScriptType.RequireSignature: { | ||
cslScript = NativeScript.new_script_pubkey(ScriptPubkey.new(Ed25519KeyHash.from_bytes(Buffer.from(script.keyHash, 'hex')))); | ||
break; | ||
} | ||
case Cardano.NativeScriptType.RequireAllOf: { | ||
const cslScripts = NativeScripts.new(); | ||
for (const subscript of script.scripts) { | ||
cslScripts.add(nativeScript(subscript)); | ||
} | ||
cslScript = NativeScript.new_script_all(ScriptAll.new(cslScripts)); | ||
break; | ||
} | ||
case Cardano.NativeScriptType.RequireAnyOf: { | ||
const cslScripts2 = NativeScripts.new(); | ||
for (const subscript of script.scripts) { | ||
cslScripts2.add(nativeScript(subscript)); | ||
} | ||
cslScript = NativeScript.new_script_any(ScriptAny.new(cslScripts2)); | ||
break; | ||
} | ||
case Cardano.NativeScriptType.RequireMOf: { | ||
const cslScripts3 = NativeScripts.new(); | ||
for (const subscript of script.scripts) { | ||
cslScripts3.add(nativeScript(subscript)); | ||
} | ||
cslScript = NativeScript.new_script_n_of_k(ScriptNOfK.new(script.required, cslScripts3)); | ||
break; | ||
} | ||
case Cardano.NativeScriptType.RequireTimeBefore: { | ||
cslScript = NativeScript.new_timelock_expiry(TimelockExpiry.new_timelockexpiry(BigNum.from_str(script.slot.toString()))); | ||
break; | ||
} | ||
case Cardano.NativeScriptType.RequireTimeAfter: { | ||
cslScript = NativeScript.new_timelock_start(TimelockStart.new_timelockstart(BigNum.from_str(script.slot.toString()))); | ||
break; | ||
} | ||
default: | ||
throw new SerializationError(SerializationFailure.InvalidNativeScriptType, `Native Script Type value '${type}' is not supported.`); | ||
} | ||
return cslScript; | ||
}; | ||
//# sourceMappingURL=coreToCsl.js.map |
import { CSL, Cardano } from '../..'; | ||
import { BootstrapWitness } from '@cardano-ogmios/schema'; | ||
import { Ed25519KeyHash } from '../../Cardano'; | ||
import { NativeScript } from '@emurgo/cardano-serialization-lib-nodejs'; | ||
export declare const txRequiredExtraSignatures: (signatures: CSL.Ed25519KeyHashes | undefined) => Cardano.Ed25519KeyHash[] | undefined; | ||
@@ -20,2 +22,11 @@ export declare const txWithdrawals: (withdrawals?: CSL.Withdrawals) => Cardano.Withdrawal[] | undefined; | ||
export declare const newTx: (cslTx: CSL.Transaction) => Cardano.NewTxAlonzo; | ||
export declare enum NativeScriptKind { | ||
RequireSignature = 0, | ||
RequireAllOf = 1, | ||
RequireAnyOf = 2, | ||
RequireMOf = 3, | ||
RequireTimeAfter = 4, | ||
RequireTimeBefore = 5 | ||
} | ||
export declare const nativeScript: (script: NativeScript) => Cardano.NativeScript; | ||
//# sourceMappingURL=cslToCore.d.ts.map |
import { Asset, CSL, Cardano, SerializationFailure, util } from '../..'; | ||
import { Ed25519KeyHash, NativeScriptType } from '../../Cardano'; | ||
import { SerializationError } from '../../errors'; | ||
@@ -254,2 +255,63 @@ import { createCertificate } from './certificate'; | ||
}; | ||
export var NativeScriptKind; | ||
(function (NativeScriptKind) { | ||
NativeScriptKind[NativeScriptKind["RequireSignature"] = 0] = "RequireSignature"; | ||
NativeScriptKind[NativeScriptKind["RequireAllOf"] = 1] = "RequireAllOf"; | ||
NativeScriptKind[NativeScriptKind["RequireAnyOf"] = 2] = "RequireAnyOf"; | ||
NativeScriptKind[NativeScriptKind["RequireMOf"] = 3] = "RequireMOf"; | ||
NativeScriptKind[NativeScriptKind["RequireTimeAfter"] = 4] = "RequireTimeAfter"; | ||
NativeScriptKind[NativeScriptKind["RequireTimeBefore"] = 5] = "RequireTimeBefore"; | ||
})(NativeScriptKind || (NativeScriptKind = {})); | ||
export const nativeScript = (script) => { | ||
let coreScript; | ||
const scriptKind = script.kind(); | ||
switch (scriptKind) { | ||
case NativeScriptKind.RequireSignature: { | ||
coreScript = { | ||
__type: NativeScriptType.RequireSignature, | ||
keyHash: Ed25519KeyHash(util.bytesToHex(script.as_script_pubkey().addr_keyhash().to_bytes()).toString()) | ||
}; | ||
break; | ||
} | ||
case NativeScriptKind.RequireAllOf: { | ||
coreScript = { __type: NativeScriptType.RequireAllOf, scripts: new Array() }; | ||
const scriptAll = script.as_script_all(); | ||
for (let i = 0; i < scriptAll.native_scripts().len(); ++i) { | ||
coreScript.scripts.push(nativeScript(scriptAll.native_scripts().get(i))); | ||
} | ||
break; | ||
} | ||
case NativeScriptKind.RequireAnyOf: { | ||
coreScript = { __type: NativeScriptType.RequireAnyOf, scripts: new Array() }; | ||
const scriptAny = script.as_script_any(); | ||
for (let i = 0; i < scriptAny.native_scripts().len(); ++i) { | ||
coreScript.scripts.push(nativeScript(scriptAny.native_scripts().get(i))); | ||
} | ||
break; | ||
} | ||
case NativeScriptKind.RequireMOf: { | ||
const scriptMofK = script.as_script_n_of_k(); | ||
coreScript = { | ||
__type: NativeScriptType.RequireMOf, | ||
required: scriptMofK.n(), | ||
scripts: new Array() | ||
}; | ||
for (let i = 0; i < scriptMofK.native_scripts().len(); ++i) { | ||
coreScript.scripts.push(nativeScript(scriptMofK.native_scripts().get(i))); | ||
} | ||
break; | ||
} | ||
case NativeScriptKind.RequireTimeBefore: { | ||
coreScript = { __type: NativeScriptType.RequireTimeBefore, slot: script.as_timelock_expiry().slot() }; | ||
break; | ||
} | ||
case NativeScriptKind.RequireTimeAfter: { | ||
coreScript = { __type: NativeScriptType.RequireTimeAfter, slot: script.as_timelock_start().slot() }; | ||
break; | ||
} | ||
default: | ||
throw new SerializationError(SerializationFailure.InvalidNativeScriptType, `Native Script Kind value '${scriptKind}' is not supported.`); | ||
} | ||
return coreScript; | ||
}; | ||
//# sourceMappingURL=cslToCore.js.map |
@@ -21,3 +21,4 @@ import { CustomError } from 'ts-custom-error'; | ||
InvalidAddress = "INVALID_ADDRESS", | ||
MaxLengthLimit = "MAX_LENGTH_LIMIT" | ||
MaxLengthLimit = "MAX_LENGTH_LIMIT", | ||
InvalidNativeScriptType = "INVALID_NATIVE_SCRIPT_TYPE" | ||
} | ||
@@ -24,0 +25,0 @@ export declare class SerializationError extends CustomError { |
@@ -27,2 +27,3 @@ import { CustomError } from 'ts-custom-error'; | ||
SerializationFailure["MaxLengthLimit"] = "MAX_LENGTH_LIMIT"; | ||
SerializationFailure["InvalidNativeScriptType"] = "INVALID_NATIVE_SCRIPT_TYPE"; | ||
})(SerializationFailure || (SerializationFailure = {})); | ||
@@ -29,0 +30,0 @@ export class SerializationError extends CustomError { |
{ | ||
"name": "@cardano-sdk/core", | ||
"version": "0.5.0-nightly.4", | ||
"version": "0.5.0-nightly.5", | ||
"description": "Core types and libraries for Cardano", | ||
@@ -79,3 +79,3 @@ "engines": { | ||
], | ||
"gitHead": "462941dc783c2dfecba92d03027eaeb8ce051712" | ||
"gitHead": "05070495c93ba8d667e9bf076c8c25f58d29ebca" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
907191
7845