@sidan-lab/sidan-csl
Advanced tools
Comparing version 0.0.5 to 0.0.6
@@ -1,21 +0,5 @@ | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
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); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./txBuilder"), exports); | ||
__exportStar(require("./multiAsset"), exports); | ||
__exportStar(require("./transactionInput"), exports); | ||
__exportStar(require("./redeemer"), exports); | ||
export * from './txBuilder'; | ||
export * from './multiAsset'; | ||
export * from './transactionInput'; | ||
export * from './redeemer'; | ||
//# sourceMappingURL=index.js.map |
@@ -1,22 +0,15 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SidanValue = void 0; | ||
const cardano_serialization_lib_nodejs_1 = __importDefault(require("@emurgo/cardano-serialization-lib-nodejs")); | ||
class SidanValue { | ||
import csl from '@emurgo/cardano-serialization-lib-nodejs'; | ||
export class SidanValue { | ||
constructor() { | ||
this.withLovelace = (lovelace) => cardano_serialization_lib_nodejs_1.default.Value.new_with_assets(cardano_serialization_lib_nodejs_1.default.BigNum.from_str(lovelace), this.self); | ||
this.withLovelace = (lovelace) => csl.Value.new_with_assets(csl.BigNum.from_str(lovelace), this.self); | ||
this.return = () => this.self; | ||
this.add = (policyId, tokenName, quantity) => { | ||
const cslAssets = cardano_serialization_lib_nodejs_1.default.Assets.new(); | ||
cslAssets.insert(cardano_serialization_lib_nodejs_1.default.AssetName.new(Buffer.from(tokenName, 'utf-8')), cardano_serialization_lib_nodejs_1.default.BigNum.from_str(quantity)); | ||
this.self.insert(cardano_serialization_lib_nodejs_1.default.ScriptHash.from_hex(policyId), cslAssets); | ||
const cslAssets = csl.Assets.new(); | ||
cslAssets.insert(csl.AssetName.new(Buffer.from(tokenName, 'utf-8')), csl.BigNum.from_str(quantity)); | ||
this.self.insert(csl.ScriptHash.from_hex(policyId), cslAssets); | ||
return this; | ||
}; | ||
this.self = cardano_serialization_lib_nodejs_1.default.MultiAsset.new(); | ||
this.self = csl.MultiAsset.new(); | ||
} | ||
} | ||
exports.SidanValue = SidanValue; | ||
//# sourceMappingURL=multiAsset.js.map |
@@ -1,5 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.sidanRedeemer = void 0; | ||
exports.sidanRedeemer = {}; | ||
export const sidanRedeemer = {}; | ||
//# sourceMappingURL=redeemer.js.map |
@@ -1,7 +0,3 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SidanTransactionInput = void 0; | ||
class SidanTransactionInput { | ||
export class SidanTransactionInput { | ||
} | ||
exports.SidanTransactionInput = SidanTransactionInput; | ||
//# sourceMappingURL=transactionInput.js.map |
@@ -1,18 +0,11 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.initiateTxBuilder = void 0; | ||
const cardano_serialization_lib_nodejs_1 = __importDefault(require("@emurgo/cardano-serialization-lib-nodejs")); | ||
const initiateTxBuilder = () => cardano_serialization_lib_nodejs_1.default?.TransactionBuilder.new(cardano_serialization_lib_nodejs_1.default.TransactionBuilderConfigBuilder.new() | ||
.fee_algo(cardano_serialization_lib_nodejs_1.default.LinearFee.new(cardano_serialization_lib_nodejs_1.default.BigNum.from_str('44'), cardano_serialization_lib_nodejs_1.default.BigNum.from_str('155381'))) | ||
.coins_per_utxo_byte(cardano_serialization_lib_nodejs_1.default.BigNum.from_str('4310')) | ||
.pool_deposit(cardano_serialization_lib_nodejs_1.default.BigNum.from_str('500000000')) | ||
.key_deposit(cardano_serialization_lib_nodejs_1.default.BigNum.from_str('2000000')) | ||
.ex_unit_prices(cardano_serialization_lib_nodejs_1.default.ExUnitPrices.new(cardano_serialization_lib_nodejs_1.default.UnitInterval.new(cardano_serialization_lib_nodejs_1.default.BigNum.from_str('577'), cardano_serialization_lib_nodejs_1.default.BigNum.from_str('10000')), cardano_serialization_lib_nodejs_1.default.UnitInterval.new(cardano_serialization_lib_nodejs_1.default.BigNum.from_str('721'), cardano_serialization_lib_nodejs_1.default.BigNum.from_str('10000000')))) | ||
import csl from '@emurgo/cardano-serialization-lib-nodejs'; | ||
export const initiateTxBuilder = () => csl?.TransactionBuilder.new(csl.TransactionBuilderConfigBuilder.new() | ||
.fee_algo(csl.LinearFee.new(csl.BigNum.from_str('44'), csl.BigNum.from_str('155381'))) | ||
.coins_per_utxo_byte(csl.BigNum.from_str('4310')) | ||
.pool_deposit(csl.BigNum.from_str('500000000')) | ||
.key_deposit(csl.BigNum.from_str('2000000')) | ||
.ex_unit_prices(csl.ExUnitPrices.new(csl.UnitInterval.new(csl.BigNum.from_str('577'), csl.BigNum.from_str('10000')), csl.UnitInterval.new(csl.BigNum.from_str('721'), csl.BigNum.from_str('10000000')))) | ||
.max_value_size(5000) | ||
.max_tx_size(16384) | ||
.build()); | ||
exports.initiateTxBuilder = initiateTxBuilder; | ||
//# sourceMappingURL=txBuilder.js.map |
@@ -1,20 +0,4 @@ | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
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); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./type"), exports); | ||
__exportStar(require("./csl"), exports); | ||
__exportStar(require("./utils"), exports); | ||
export * from './type'; | ||
export * from './csl'; | ||
export * from './utils'; | ||
//# sourceMappingURL=index.js.map |
@@ -1,3 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
export {}; | ||
//# sourceMappingURL=blockfrost.js.map |
@@ -1,19 +0,3 @@ | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
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); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./plutus"), exports); | ||
__exportStar(require("./type"), exports); | ||
export * from './plutus'; | ||
export * from './type'; | ||
//# sourceMappingURL=index.js.map |
@@ -1,50 +0,32 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.tuple = exports.assocMap = exports.integer = exports.posixTime = exports.pubKeyHash = exports.paymentPubKeyHash = exports.assetClass = exports.scriptAddress = exports.pubKeyAddress = exports.maybeStakingHash = exports.builtinByteString = exports.conStr2 = exports.conStr1 = exports.conStr0 = exports.conStr = void 0; | ||
const conStr = (constructor, fields) => ({ | ||
export const conStr = (constructor, fields) => ({ | ||
constructor, | ||
fields | ||
}); | ||
exports.conStr = conStr; | ||
const conStr0 = (fields) => (0, exports.conStr)(0, fields); | ||
exports.conStr0 = conStr0; | ||
const conStr1 = (fields) => (0, exports.conStr)(1, fields); | ||
exports.conStr1 = conStr1; | ||
const conStr2 = (fields) => (0, exports.conStr)(2, fields); | ||
exports.conStr2 = conStr2; | ||
const builtinByteString = (bytes) => ({ bytes }); | ||
exports.builtinByteString = builtinByteString; | ||
const maybeStakingHash = (stakeCredential) => { | ||
export const conStr0 = (fields) => conStr(0, fields); | ||
export const conStr1 = (fields) => conStr(1, fields); | ||
export const conStr2 = (fields) => conStr(2, fields); | ||
export const builtinByteString = (bytes) => ({ bytes }); | ||
export const maybeStakingHash = (stakeCredential) => { | ||
if (stakeCredential === '') { | ||
return (0, exports.conStr1)([]); | ||
return conStr1([]); | ||
} | ||
return (0, exports.conStr0)([ | ||
(0, exports.conStr0)([(0, exports.conStr0)([(0, exports.builtinByteString)(stakeCredential)])]) | ||
return conStr0([ | ||
conStr0([conStr0([builtinByteString(stakeCredential)])]) | ||
]); | ||
}; | ||
exports.maybeStakingHash = maybeStakingHash; | ||
const pubKeyAddress = (bytes, stakeCredential) => (0, exports.conStr0)([ | ||
(0, exports.conStr0)([(0, exports.builtinByteString)(bytes)]), | ||
(0, exports.maybeStakingHash)(stakeCredential || '') | ||
export const pubKeyAddress = (bytes, stakeCredential) => conStr0([ | ||
conStr0([builtinByteString(bytes)]), | ||
maybeStakingHash(stakeCredential || '') | ||
]); | ||
exports.pubKeyAddress = pubKeyAddress; | ||
const scriptAddress = (bytes, stakeCredential) => (0, exports.conStr0)([ | ||
(0, exports.conStr1)([(0, exports.builtinByteString)(bytes)]), | ||
(0, exports.maybeStakingHash)(stakeCredential || '') | ||
export const scriptAddress = (bytes, stakeCredential) => conStr0([ | ||
conStr1([builtinByteString(bytes)]), | ||
maybeStakingHash(stakeCredential || '') | ||
]); | ||
exports.scriptAddress = scriptAddress; | ||
const assetClass = (policyId, tokenName) => (0, exports.conStr0)([(0, exports.builtinByteString)(policyId), (0, exports.builtinByteString)(tokenName)]); | ||
exports.assetClass = assetClass; | ||
const paymentPubKeyHash = (bytes) => (0, exports.builtinByteString)(bytes); | ||
exports.paymentPubKeyHash = paymentPubKeyHash; | ||
const pubKeyHash = (bytes) => (0, exports.builtinByteString)(bytes); | ||
exports.pubKeyHash = pubKeyHash; | ||
const posixTime = (int) => ({ int }); | ||
exports.posixTime = posixTime; | ||
const integer = (int) => ({ int }); | ||
exports.integer = integer; | ||
const assocMap = (itemsMap) => ({ map: itemsMap.map(([k, v]) => ({ k, v })) }); | ||
exports.assocMap = assocMap; | ||
const tuple = (key, value) => (0, exports.conStr0)([key, value]); | ||
exports.tuple = tuple; | ||
export const assetClass = (policyId, tokenName) => conStr0([builtinByteString(policyId), builtinByteString(tokenName)]); | ||
export const paymentPubKeyHash = (bytes) => builtinByteString(bytes); | ||
export const pubKeyHash = (bytes) => builtinByteString(bytes); | ||
export const posixTime = (int) => ({ int }); | ||
export const integer = (int) => ({ int }); | ||
export const assocMap = (itemsMap) => ({ map: itemsMap.map(([k, v]) => ({ k, v })) }); | ||
export const tuple = (key, value) => conStr0([key, value]); | ||
//# sourceMappingURL=plutus.js.map |
@@ -1,3 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
export {}; | ||
//# sourceMappingURL=type.js.map |
@@ -1,9 +0,3 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.serializeBFUTxO = exports.locateUTxOWithAddressAndPolicyId = exports.locateUTxOWithPolicyId = exports.locateUTxOWithAddress = exports.getOutputLovelace = void 0; | ||
const cardano_serialization_lib_nodejs_1 = __importDefault(require("@emurgo/cardano-serialization-lib-nodejs")); | ||
const getOutputLovelace = (output) => { | ||
import csl from '@emurgo/cardano-serialization-lib-nodejs'; | ||
export const getOutputLovelace = (output) => { | ||
const amounts = output?.amount || []; | ||
@@ -17,16 +11,12 @@ let result = '0'; | ||
}; | ||
exports.getOutputLovelace = getOutputLovelace; | ||
const locateUTxOWithAddress = (output, targetAddress) => output.find((o) => o.address === targetAddress); | ||
exports.locateUTxOWithAddress = locateUTxOWithAddress; | ||
const locateUTxOWithPolicyId = (output, targetPolicyId) => output.find((o) => o.amount?.findIndex((a) => a.unit?.startsWith(targetPolicyId)) !== -1); | ||
exports.locateUTxOWithPolicyId = locateUTxOWithPolicyId; | ||
const locateUTxOWithAddressAndPolicyId = (output, targetAddress, targetPolicyId) => { | ||
const utxoAtAddress = (0, exports.locateUTxOWithPolicyId)(output, targetPolicyId); | ||
export const locateUTxOWithAddress = (output, targetAddress) => output.find((o) => o.address === targetAddress); | ||
export const locateUTxOWithPolicyId = (output, targetPolicyId) => output.find((o) => o.amount?.findIndex((a) => a.unit?.startsWith(targetPolicyId)) !== -1); | ||
export const locateUTxOWithAddressAndPolicyId = (output, targetAddress, targetPolicyId) => { | ||
const utxoAtAddress = locateUTxOWithPolicyId(output, targetPolicyId); | ||
if (utxoAtAddress) { | ||
return (0, exports.locateUTxOWithAddress)([utxoAtAddress], targetAddress); | ||
return locateUTxOWithAddress([utxoAtAddress], targetAddress); | ||
} | ||
return undefined; | ||
}; | ||
exports.locateUTxOWithAddressAndPolicyId = locateUTxOWithAddressAndPolicyId; | ||
const serializeBFUTxO = (bfData) => { | ||
export const serializeBFUTxO = (bfData) => { | ||
const serUTxOs = []; | ||
@@ -45,11 +35,11 @@ const serCollateral = []; | ||
}); | ||
const cslValue = cardano_serialization_lib_nodejs_1.default.Value.new(cardano_serialization_lib_nodejs_1.default.BigNum.from_str(lovelaceAmount)); | ||
const cslMultiAsset = cardano_serialization_lib_nodejs_1.default.MultiAsset.new(); | ||
const cslValue = csl.Value.new(csl.BigNum.from_str(lovelaceAmount)); | ||
const cslMultiAsset = csl.MultiAsset.new(); | ||
valueAmounts.forEach((asset) => { | ||
const cslAssets = cardano_serialization_lib_nodejs_1.default.Assets.new(); | ||
cslAssets.insert(cardano_serialization_lib_nodejs_1.default.AssetName.new(Buffer.from(asset.unit.slice(56), 'hex')), cardano_serialization_lib_nodejs_1.default.BigNum.from_str(asset.quantity)); | ||
cslMultiAsset.insert(cardano_serialization_lib_nodejs_1.default.ScriptHash.from_hex(asset.unit.slice(0, 56)), cslAssets); | ||
const cslAssets = csl.Assets.new(); | ||
cslAssets.insert(csl.AssetName.new(Buffer.from(asset.unit.slice(56), 'hex')), csl.BigNum.from_str(asset.quantity)); | ||
cslMultiAsset.insert(csl.ScriptHash.from_hex(asset.unit.slice(0, 56)), cslAssets); | ||
}); | ||
cslValue.set_multiasset(cslMultiAsset); | ||
const cslUtxo = cardano_serialization_lib_nodejs_1.default.TransactionUnspentOutput.new(cardano_serialization_lib_nodejs_1.default.TransactionInput.new(cardano_serialization_lib_nodejs_1.default.TransactionHash.from_hex(blockfrostUtxo.tx_hash), blockfrostUtxo.tx_index), cardano_serialization_lib_nodejs_1.default.TransactionOutput.new(cardano_serialization_lib_nodejs_1.default.Address.from_bech32(blockfrostUtxo.address), cslValue)); | ||
const cslUtxo = csl.TransactionUnspentOutput.new(csl.TransactionInput.new(csl.TransactionHash.from_hex(blockfrostUtxo.tx_hash), blockfrostUtxo.tx_index), csl.TransactionOutput.new(csl.Address.from_bech32(blockfrostUtxo.address), cslValue)); | ||
serUTxOs.push(cslUtxo.to_hex()); | ||
@@ -62,3 +52,2 @@ if (blockfrostUtxo.amount.length === 1 && serCollateral.length < 3) { | ||
}; | ||
exports.serializeBFUTxO = serializeBFUTxO; | ||
//# sourceMappingURL=blockfrost.js.map |
@@ -1,19 +0,3 @@ | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
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); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./blockfrost"), exports); | ||
__exportStar(require("./parser"), exports); | ||
export * from './blockfrost'; | ||
export * from './parser'; | ||
//# sourceMappingURL=index.js.map |
@@ -1,43 +0,28 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.parsePlutusAddressToBech32 = exports.serializeBech32Address = exports.parseInlineDatum = exports.objToHex = exports.hexToObj = exports.addrBech32ToObj = exports.addrBech32ToHex = exports.hexToString = exports.stringToHex = exports.hexToBytes = exports.bytesToHex = void 0; | ||
const cardano_serialization_lib_nodejs_1 = __importDefault(require("@emurgo/cardano-serialization-lib-nodejs")); | ||
const bytesToHex = (bytes) => Buffer.from(bytes).toString('hex'); | ||
exports.bytesToHex = bytesToHex; | ||
const hexToBytes = (hex) => Buffer.from(hex, 'hex'); | ||
exports.hexToBytes = hexToBytes; | ||
const stringToHex = (str) => Buffer.from(str, 'utf8').toString('hex'); | ||
exports.stringToHex = stringToHex; | ||
const hexToString = (hex) => Buffer.from(hex, 'hex').toString('utf8'); | ||
exports.hexToString = hexToString; | ||
const addrBech32ToHex = (bech32) => { | ||
const hexAddress = cardano_serialization_lib_nodejs_1.default.Address.from_bech32(bech32).to_hex(); | ||
const cslAddress = cardano_serialization_lib_nodejs_1.default.Address.from_hex(hexAddress); | ||
const hex = cardano_serialization_lib_nodejs_1.default.PlutusData.from_address(cslAddress).to_hex(); | ||
import csl from '@emurgo/cardano-serialization-lib-nodejs'; | ||
export const bytesToHex = (bytes) => Buffer.from(bytes).toString('hex'); | ||
export const hexToBytes = (hex) => Buffer.from(hex, 'hex'); | ||
export const stringToHex = (str) => Buffer.from(str, 'utf8').toString('hex'); | ||
export const hexToString = (hex) => Buffer.from(hex, 'hex').toString('utf8'); | ||
export const addrBech32ToHex = (bech32) => { | ||
const hexAddress = csl.Address.from_bech32(bech32).to_hex(); | ||
const cslAddress = csl.Address.from_hex(hexAddress); | ||
const hex = csl.PlutusData.from_address(cslAddress).to_hex(); | ||
return hex; | ||
}; | ||
exports.addrBech32ToHex = addrBech32ToHex; | ||
const addrBech32ToObj = (bech32) => { | ||
const hexAddress = cardano_serialization_lib_nodejs_1.default.Address.from_bech32(bech32).to_hex(); | ||
const cslAddress = cardano_serialization_lib_nodejs_1.default.Address.from_hex(hexAddress); | ||
const json = JSON.parse(cardano_serialization_lib_nodejs_1.default.PlutusData.from_address(cslAddress).to_json(1)); | ||
export const addrBech32ToObj = (bech32) => { | ||
const hexAddress = csl.Address.from_bech32(bech32).to_hex(); | ||
const cslAddress = csl.Address.from_hex(hexAddress); | ||
const json = JSON.parse(csl.PlutusData.from_address(cslAddress).to_json(1)); | ||
return json; | ||
}; | ||
exports.addrBech32ToObj = addrBech32ToObj; | ||
const hexToObj = (hex) => JSON.parse(cardano_serialization_lib_nodejs_1.default.PlutusData.from_hex(hex).to_json(1)); | ||
exports.hexToObj = hexToObj; | ||
const objToHex = (obj) => cardano_serialization_lib_nodejs_1.default.PlutusData.from_json(JSON.stringify(obj), 1).to_hex(); | ||
exports.objToHex = objToHex; | ||
const parseInlineDatum = (utxo) => { | ||
export const hexToObj = (hex) => JSON.parse(csl.PlutusData.from_hex(hex).to_json(1)); | ||
export const objToHex = (obj) => csl.PlutusData.from_json(JSON.stringify(obj), 1).to_hex(); | ||
export const parseInlineDatum = (utxo) => { | ||
const datumCbor = utxo.inline_datum || ''; | ||
const parsedDatum = cardano_serialization_lib_nodejs_1.default.PlutusData.from_hex(datumCbor); | ||
const parsedDatum = csl.PlutusData.from_hex(datumCbor); | ||
const datum = JSON.parse(parsedDatum.to_json(1)); | ||
return datum; | ||
}; | ||
exports.parseInlineDatum = parseInlineDatum; | ||
const serializeBech32Address = (bech32Addr) => { | ||
const cslAddress = cardano_serialization_lib_nodejs_1.default.BaseAddress.from_address(cardano_serialization_lib_nodejs_1.default.Address.from_bech32(bech32Addr)); | ||
export const serializeBech32Address = (bech32Addr) => { | ||
const cslAddress = csl.BaseAddress.from_address(csl.Address.from_bech32(bech32Addr)); | ||
const cslKeyHash = cslAddress?.payment_cred().to_keyhash()?.to_hex() || ""; | ||
@@ -52,3 +37,3 @@ const cslScriptHash = cslAddress?.payment_cred().to_scripthash()?.to_hex() || ""; | ||
} | ||
const cslEnterprizeAddress = cardano_serialization_lib_nodejs_1.default.EnterpriseAddress.from_address(cardano_serialization_lib_nodejs_1.default.Address.from_bech32(bech32Addr)); | ||
const cslEnterprizeAddress = csl.EnterpriseAddress.from_address(csl.Address.from_bech32(bech32Addr)); | ||
const cslEAKeyHash = cslEnterprizeAddress?.payment_cred().to_keyhash()?.to_hex() || ""; | ||
@@ -61,6 +46,5 @@ if (cslEAKeyHash) { | ||
}; | ||
exports.serializeBech32Address = serializeBech32Address; | ||
const parsePlutusAddressToBech32 = (plutusHex, networkId = 0) => { | ||
const cslPlutusDataAddress = cardano_serialization_lib_nodejs_1.default.PlutusData.from_hex(plutusHex); | ||
const plutusDataAddressObject = JSON.parse(cslPlutusDataAddress.to_json(cardano_serialization_lib_nodejs_1.default.PlutusDatumSchema.DetailedSchema)); | ||
export const parsePlutusAddressToBech32 = (plutusHex, networkId = 0) => { | ||
const cslPlutusDataAddress = csl.PlutusData.from_hex(plutusHex); | ||
const plutusDataAddressObject = JSON.parse(cslPlutusDataAddress.to_json(csl.PlutusDatumSchema.DetailedSchema)); | ||
const plutusDataPaymentKeyObject = plutusDataAddressObject.fields[0]; | ||
@@ -70,12 +54,12 @@ const plutusDataStakeKeyObject = plutusDataAddressObject.fields[1]; | ||
const cslPaymentCredential = plutusDataPaymentKeyObject.constructor === 0 | ||
? cardano_serialization_lib_nodejs_1.default.StakeCredential.from_keyhash(cardano_serialization_lib_nodejs_1.default.Ed25519KeyHash.from_hex(cslPaymentKeyHash)) | ||
: cardano_serialization_lib_nodejs_1.default.StakeCredential.from_scripthash(cardano_serialization_lib_nodejs_1.default.ScriptHash.from_hex(cslPaymentKeyHash)); | ||
? csl.StakeCredential.from_keyhash(csl.Ed25519KeyHash.from_hex(cslPaymentKeyHash)) | ||
: csl.StakeCredential.from_scripthash(csl.ScriptHash.from_hex(cslPaymentKeyHash)); | ||
let bech32Addr = ""; | ||
if (plutusDataStakeKeyObject.constructor === 0 && plutusDataStakeKeyObject.fields.length !== 0) { | ||
const cslStakeKeyHash = cardano_serialization_lib_nodejs_1.default.Ed25519KeyHash.from_hex(plutusDataStakeKeyObject.fields[0].fields[0].fields[0].bytes); | ||
const cslBaseAddress = cardano_serialization_lib_nodejs_1.default.BaseAddress.new(networkId, cslPaymentCredential, cardano_serialization_lib_nodejs_1.default.StakeCredential.from_keyhash(cslStakeKeyHash)); | ||
const cslStakeKeyHash = csl.Ed25519KeyHash.from_hex(plutusDataStakeKeyObject.fields[0].fields[0].fields[0].bytes); | ||
const cslBaseAddress = csl.BaseAddress.new(networkId, cslPaymentCredential, csl.StakeCredential.from_keyhash(cslStakeKeyHash)); | ||
bech32Addr = cslBaseAddress.to_address().to_bech32(); | ||
} | ||
else { | ||
const cslEnterpriseAddress = cardano_serialization_lib_nodejs_1.default.EnterpriseAddress.new(networkId, cslPaymentCredential); | ||
const cslEnterpriseAddress = csl.EnterpriseAddress.new(networkId, cslPaymentCredential); | ||
bech32Addr = cslEnterpriseAddress.to_address().to_bech32(); | ||
@@ -86,3 +70,2 @@ } | ||
}; | ||
exports.parsePlutusAddressToBech32 = parsePlutusAddressToBech32; | ||
//# sourceMappingURL=parser.js.map |
{ | ||
"name": "@sidan-lab/sidan-csl", | ||
"description": "Cardano Off-chain Code APIs built on cardano-serialization-lib", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"license": "MIT", | ||
@@ -6,0 +6,0 @@ "type": "module", |
@@ -6,3 +6,3 @@ { | ||
"lib": ["DOM", "ESNext"], | ||
"module": "CommonJS", | ||
"module": "ESNext", | ||
"moduleResolution": "node", | ||
@@ -9,0 +9,0 @@ "noUnusedLocals": true, |
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
49422
764