New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@sidan-lab/sidan-csl

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sidan-lab/sidan-csl - npm Package Compare versions

Comparing version 0.1.4 to 0.1.5

dist/cjs/csl/index.d.ts

17

dist/cjs/utils/blockfrost.js
"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 csl_1 = require("../csl");
const getOutputLovelace = (output) => {

@@ -44,11 +41,11 @@ const amounts = (output === null || output === void 0 ? void 0 : output.amount) || [];

});
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_1.csl.Value.new(csl_1.csl.BigNum.from_str(lovelaceAmount));
const cslMultiAsset = csl_1.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_1.csl.Assets.new();
cslAssets.insert(csl_1.csl.AssetName.new(Buffer.from(asset.unit.slice(56), 'hex')), csl_1.csl.BigNum.from_str(asset.quantity));
cslMultiAsset.insert(csl_1.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_1.csl.TransactionUnspentOutput.new(csl_1.csl.TransactionInput.new(csl_1.csl.TransactionHash.from_hex(blockfrostUtxo.tx_hash), blockfrostUtxo.tx_index), csl_1.csl.TransactionOutput.new(csl_1.csl.Address.from_bech32(blockfrostUtxo.address), cslValue));
serUTxOs.push(cslUtxo.to_hex());

@@ -55,0 +52,0 @@ if (blockfrostUtxo.amount.length === 1 && serCollateral.length < 3) {

"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 csl_1 = require("../csl");
const bytesToHex = (bytes) => Buffer.from(bytes).toString('hex');

@@ -17,5 +14,5 @@ exports.bytesToHex = bytesToHex;

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();
const hexAddress = csl_1.csl.Address.from_bech32(bech32).to_hex();
const cslAddress = csl_1.csl.Address.from_hex(hexAddress);
const hex = csl_1.csl.PlutusData.from_address(cslAddress).to_hex();
return hex;

@@ -25,15 +22,15 @@ };

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));
const hexAddress = csl_1.csl.Address.from_bech32(bech32).to_hex();
const cslAddress = csl_1.csl.Address.from_hex(hexAddress);
const json = JSON.parse(csl_1.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));
const hexToObj = (hex) => JSON.parse(csl_1.csl.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();
const objToHex = (obj) => csl_1.csl.PlutusData.from_json(JSON.stringify(obj), 1).to_hex();
exports.objToHex = objToHex;
const parseInlineDatum = (utxo) => {
const datumCbor = utxo.inline_datum || '';
const parsedDatum = cardano_serialization_lib_nodejs_1.default.PlutusData.from_hex(datumCbor);
const parsedDatum = csl_1.csl.PlutusData.from_hex(datumCbor);
const datum = JSON.parse(parsedDatum.to_json(1));

@@ -45,24 +42,24 @@ return datum;

var _a, _b, _c, _d, _e;
const cslAddress = cardano_serialization_lib_nodejs_1.default.BaseAddress.from_address(cardano_serialization_lib_nodejs_1.default.Address.from_bech32(bech32Addr));
const cslKeyHash = ((_a = cslAddress === null || cslAddress === void 0 ? void 0 : cslAddress.payment_cred().to_keyhash()) === null || _a === void 0 ? void 0 : _a.to_hex()) || "";
const cslScriptHash = ((_b = cslAddress === null || cslAddress === void 0 ? void 0 : cslAddress.payment_cred().to_scripthash()) === null || _b === void 0 ? void 0 : _b.to_hex()) || "";
const cslStakeHash = ((_c = cslAddress === null || cslAddress === void 0 ? void 0 : cslAddress.stake_cred().to_keyhash()) === null || _c === void 0 ? void 0 : _c.to_hex()) || "";
const cslAddress = csl_1.csl.BaseAddress.from_address(csl_1.csl.Address.from_bech32(bech32Addr));
const cslKeyHash = ((_a = cslAddress === null || cslAddress === void 0 ? void 0 : cslAddress.payment_cred().to_keyhash()) === null || _a === void 0 ? void 0 : _a.to_hex()) || '';
const cslScriptHash = ((_b = cslAddress === null || cslAddress === void 0 ? void 0 : cslAddress.payment_cred().to_scripthash()) === null || _b === void 0 ? void 0 : _b.to_hex()) || '';
const cslStakeHash = ((_c = cslAddress === null || cslAddress === void 0 ? void 0 : cslAddress.stake_cred().to_keyhash()) === null || _c === void 0 ? void 0 : _c.to_hex()) || '';
if (cslKeyHash) {
return ({ pubKeyHash: cslKeyHash, scriptHash: "", stakeCredential: cslStakeHash });
return { pubKeyHash: cslKeyHash, scriptHash: '', stakeCredential: cslStakeHash };
}
if (cslScriptHash) {
return ({ pubKeyHash: "", scriptHash: cslScriptHash, stakeCredential: cslStakeHash });
return { pubKeyHash: '', scriptHash: cslScriptHash, stakeCredential: cslStakeHash };
}
const cslEnterprizeAddress = cardano_serialization_lib_nodejs_1.default.EnterpriseAddress.from_address(cardano_serialization_lib_nodejs_1.default.Address.from_bech32(bech32Addr));
const cslEAKeyHash = ((_d = cslEnterprizeAddress === null || cslEnterprizeAddress === void 0 ? void 0 : cslEnterprizeAddress.payment_cred().to_keyhash()) === null || _d === void 0 ? void 0 : _d.to_hex()) || "";
const cslEnterprizeAddress = csl_1.csl.EnterpriseAddress.from_address(csl_1.csl.Address.from_bech32(bech32Addr));
const cslEAKeyHash = ((_d = cslEnterprizeAddress === null || cslEnterprizeAddress === void 0 ? void 0 : cslEnterprizeAddress.payment_cred().to_keyhash()) === null || _d === void 0 ? void 0 : _d.to_hex()) || '';
if (cslEAKeyHash) {
return ({ pubKeyHash: cslEAKeyHash, scriptHash: "", stakeCredential: "" });
return { pubKeyHash: cslEAKeyHash, scriptHash: '', stakeCredential: '' };
}
const cslEAScriptHash = ((_e = cslEnterprizeAddress === null || cslEnterprizeAddress === void 0 ? void 0 : cslEnterprizeAddress.payment_cred().to_scripthash()) === null || _e === void 0 ? void 0 : _e.to_hex()) || "";
return ({ pubKeyHash: "", scriptHash: cslEAScriptHash, stakeCredential: "" });
const cslEAScriptHash = ((_e = cslEnterprizeAddress === null || cslEnterprizeAddress === void 0 ? void 0 : cslEnterprizeAddress.payment_cred().to_scripthash()) === null || _e === void 0 ? void 0 : _e.to_hex()) || '';
return { pubKeyHash: '', scriptHash: cslEAScriptHash, stakeCredential: '' };
};
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));
const cslPlutusDataAddress = csl_1.csl.PlutusData.from_hex(plutusHex);
const plutusDataAddressObject = JSON.parse(cslPlutusDataAddress.to_json(csl_1.csl.PlutusDatumSchema.DetailedSchema));
const plutusDataPaymentKeyObject = plutusDataAddressObject.fields[0];

@@ -73,18 +70,19 @@ 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));
let bech32Addr = "";
? csl_1.csl.StakeCredential.from_keyhash(csl_1.csl.Ed25519KeyHash.from_hex(cslPaymentKeyHash))
: csl_1.csl.StakeCredential.from_scripthash(csl_1.csl.ScriptHash.from_hex(cslPaymentKeyHash));
let bech32Addr = '';
// Parsing address according to whether it has a stake key
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));
if (plutusDataStakeKeyObject.constructor === 0 &&
plutusDataStakeKeyObject.fields.length !== 0) {
const cslStakeKeyHash = csl_1.csl.Ed25519KeyHash.from_hex(plutusDataStakeKeyObject.fields[0].fields[0].fields[0].bytes);
const cslBaseAddress = csl_1.csl.BaseAddress.new(networkId, cslPaymentCredential, csl_1.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_1.csl.EnterpriseAddress.new(networkId, cslPaymentCredential);
bech32Addr = cslEnterpriseAddress.to_address().to_bech32();
}
console.log("Parsed address", bech32Addr);
console.log('Parsed address', bech32Addr);
return bech32Addr;
};
exports.parsePlutusAddressToBech32 = parsePlutusAddressToBech32;

@@ -1,2 +0,2 @@

import csl from '@emurgo/cardano-serialization-lib-nodejs';
import { csl } from '../csl';
export const getOutputLovelace = (output) => {

@@ -3,0 +3,0 @@ const amounts = output?.amount || [];

@@ -1,2 +0,2 @@

import csl from '@emurgo/cardano-serialization-lib-nodejs';
import { csl } from '../csl';
export const bytesToHex = (bytes) => Buffer.from(bytes).toString('hex');

@@ -28,18 +28,18 @@ export const hexToBytes = (hex) => Buffer.from(hex, 'hex');

const cslAddress = csl.BaseAddress.from_address(csl.Address.from_bech32(bech32Addr));
const cslKeyHash = cslAddress?.payment_cred().to_keyhash()?.to_hex() || "";
const cslScriptHash = cslAddress?.payment_cred().to_scripthash()?.to_hex() || "";
const cslStakeHash = cslAddress?.stake_cred().to_keyhash()?.to_hex() || "";
const cslKeyHash = cslAddress?.payment_cred().to_keyhash()?.to_hex() || '';
const cslScriptHash = cslAddress?.payment_cred().to_scripthash()?.to_hex() || '';
const cslStakeHash = cslAddress?.stake_cred().to_keyhash()?.to_hex() || '';
if (cslKeyHash) {
return ({ pubKeyHash: cslKeyHash, scriptHash: "", stakeCredential: cslStakeHash });
return { pubKeyHash: cslKeyHash, scriptHash: '', stakeCredential: cslStakeHash };
}
if (cslScriptHash) {
return ({ pubKeyHash: "", scriptHash: cslScriptHash, stakeCredential: cslStakeHash });
return { pubKeyHash: '', scriptHash: cslScriptHash, stakeCredential: cslStakeHash };
}
const cslEnterprizeAddress = csl.EnterpriseAddress.from_address(csl.Address.from_bech32(bech32Addr));
const cslEAKeyHash = cslEnterprizeAddress?.payment_cred().to_keyhash()?.to_hex() || "";
const cslEAKeyHash = cslEnterprizeAddress?.payment_cred().to_keyhash()?.to_hex() || '';
if (cslEAKeyHash) {
return ({ pubKeyHash: cslEAKeyHash, scriptHash: "", stakeCredential: "" });
return { pubKeyHash: cslEAKeyHash, scriptHash: '', stakeCredential: '' };
}
const cslEAScriptHash = cslEnterprizeAddress?.payment_cred().to_scripthash()?.to_hex() || "";
return ({ pubKeyHash: "", scriptHash: cslEAScriptHash, stakeCredential: "" });
const cslEAScriptHash = cslEnterprizeAddress?.payment_cred().to_scripthash()?.to_hex() || '';
return { pubKeyHash: '', scriptHash: cslEAScriptHash, stakeCredential: '' };
};

@@ -56,5 +56,6 @@ export const parsePlutusAddressToBech32 = (plutusHex, networkId = 0) => {

: csl.StakeCredential.from_scripthash(csl.ScriptHash.from_hex(cslPaymentKeyHash));
let bech32Addr = "";
let bech32Addr = '';
// Parsing address according to whether it has a stake key
if (plutusDataStakeKeyObject.constructor === 0 && plutusDataStakeKeyObject.fields.length !== 0) {
if (plutusDataStakeKeyObject.constructor === 0 &&
plutusDataStakeKeyObject.fields.length !== 0) {
const cslStakeKeyHash = csl.Ed25519KeyHash.from_hex(plutusDataStakeKeyObject.fields[0].fields[0].fields[0].bytes);

@@ -68,4 +69,4 @@ const cslBaseAddress = csl.BaseAddress.new(networkId, cslPaymentCredential, csl.StakeCredential.from_keyhash(cslStakeKeyHash));

}
console.log("Parsed address", bech32Addr);
console.log('Parsed address', bech32Addr);
return bech32Addr;
};
{
"name": "@sidan-lab/sidan-csl",
"description": "Cardano Off-chain Code APIs built on cardano-serialization-lib",
"version": "0.1.4",
"version": "0.1.5",
"license": "MIT",

@@ -6,0 +6,0 @@ "main": "dist/cjs/index.js",

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