Socket
Socket
Sign inDemoInstall

@hyperionbt/helios

Package Overview
Dependencies
0
Maintainers
2
Versions
160
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.15.7 to 0.15.8

2

package.json
{
"name": "@hyperionbt/helios",
"type": "module",
"version": "0.15.7",
"version": "0.15.8",
"description": "Helios is a Domain Specific Language that compiles to Plutus-Core (i.e. Cardano on-chain validator scripts). Helios is a non-Haskell alternative to Plutus. With this library you can compile Helios scripts and build Cardano transactions, all you need to build 100% client-side dApps for Cardano.",

@@ -6,0 +6,0 @@ "main": "helios.js",

@@ -34,3 +34,6 @@ //@ts-check

ListData,
UplcData
IntData,
MapData,
UplcData,
ByteArrayData
} from "./uplc-data.js";

@@ -1119,2 +1122,38 @@

/**
* Uses field names as keys, not tags
* @param {any} obj
* @param {JsToUplcHelpers} helpers
* @return {Promise<[UplcData, UplcData][]>}
*/
async jsMapToUplc(obj, helpers) {
/**
* @type {[UplcData, UplcData][]}
*/
const fields = [];
if (Object.keys(obj).length == this.nFields && Object.keys(obj).every(k => this.hasField(new Word(Site.dummy(), k)))) {
for (let i = 0; i < this.nFields; i++) {
const fieldName = this.fieldNames[i];
const arg = assertDefined(obj[fieldName]);
const fieldType = this.getFieldType(i);
if (!fieldType.typeDetails) {
throw new Error(`typeDetails for ${fieldType.name} not yet implemented`);
}
fields.push([
new ByteArrayData(textToBytes(this.#fields[i].tag)),
await fieldType.jsToUplc(arg, helpers)
]);
};
} else {
throw new Error(`expected ${this.nFields} args, got ${Object.keys(obj).length}`);
}
return fields;
}
/**
* @param {UplcData[]} fields

@@ -1139,2 +1178,30 @@ * @param {UplcToJsHelpers} helpers

/**
* For Cip68-tagged structs
* @param {[UplcData, UplcData][]} fields
* @param {UplcToJsHelpers} helpers
* @returns {Promise<any>}
*/
async uplcMapToJs(fields, helpers) {
const obj = {};
for (let i = 0; i < this.#fields.length; i++) {
const f = this.#fields[i];
const fn = this.getFieldName(i);
const j = fields.findIndex(([key, value]) => {
return ByteArrayData.comp(key.bytes, textToBytes(f.tag))
})
if (j == -1) {
throw new Error(`couldn't find field ${f.tag}`)
}
obj[fn] = await this.getFieldType(i).uplcToJs(fields[j][1], helpers);
};
return obj;
}
/**
* @param {ToIRContext} ctx

@@ -1646,18 +1713,28 @@ * @param {string} path

jsToUplc: async (obj, helpers) => {
/**
* @type {UplcData[]}
*/
const fields = await this.#dataDef.jsFieldsToUplc(obj, helpers);
if (this.#dataDef.hasTags()) {
const pairs = await this.#dataDef.jsMapToUplc(obj, helpers);
if (fields.length == 1) {
return fields[0];
return new ConstrData(0, [new MapData(pairs), new IntData(1n)]);
} else {
return new ListData(fields);
/**
* @type {UplcData[]}
*/
const fields = await this.#dataDef.jsFieldsToUplc(obj, helpers);
if (fields.length == 1) {
return fields[0];
} else {
return new ListData(fields);
}
}
},
uplcToJs: async (data, helpers) => {
if (this.#dataDef.nFields == 1) {
return this.#dataDef.getFieldType(0).uplcToJs(data, helpers);
if (this.#dataDef.hasTags()) {
return this.#dataDef.uplcMapToJs(data.fields[0].map, helpers);
} else {
return this.#dataDef.uplcFieldsToJs(data.list, helpers);
if (this.#dataDef.nFields == 1) {
return this.#dataDef.getFieldType(0).uplcToJs(data, helpers);
} else {
return this.#dataDef.uplcFieldsToJs(data.list, helpers);
}
}

@@ -1664,0 +1741,0 @@ },

@@ -75,2 +75,51 @@ //@ts-check

/**
* @type {string}
*/
get networkName() {
return this.#networkName;
}
/**
* Throws an error if a Blockfrost project_id is missing for that specific network.
* @param {TxInput} refUtxo
* @param {{
* preview?: string,
* preprod?: string,
* mainnet?: string
* }} projectIds
* @returns {Promise<BlockfrostV0>}
*/
static async resolveUsingUtxo(refUtxo, projectIds) {
const mainnetProjectId = projectIds["mainnet"];
const preprodProjectId = projectIds["preprod"];
const previewProjectId = projectIds["preview"];
if (preprodProjectId !== undefined) {
const preprodNetwork = new BlockfrostV0("preprod", preprodProjectId);
if (await preprodNetwork.hasUtxo(refUtxo)) {
return preprodNetwork;
}
}
if (previewProjectId !== undefined) {
const previewNetwork = new BlockfrostV0("preview", previewProjectId);
if (await previewNetwork.hasUtxo(refUtxo)) {
return previewNetwork;
}
}
if (mainnetProjectId !== undefined) {
const mainnetNetwork = new BlockfrostV0("mainnet", mainnetProjectId);
if (await mainnetNetwork.hasUtxo(refUtxo)) {
return mainnetNetwork;
}
}
throw new Error("refUtxo not found on a network for which you have a project id");
}
/**
* Connects to the same network a given `Wallet` is connected to (preview, preprod or mainnet).

@@ -87,3 +136,3 @@ *

*/
static async resolve(wallet, projectIds) {
static async resolveUsingWallet(wallet, projectIds) {
if (await wallet.isMainnet()) {

@@ -99,28 +148,3 @@ return new BlockfrostV0("mainnet", assertDefined(projectIds["mainnet"]));

} else {
const preprodProjectId = projectIds["preprod"];
const previewProjectId = projectIds["preview"];
if (preprodProjectId !== undefined) {
const preprodNetwork = new BlockfrostV0("preprod", preprodProjectId);
if (await preprodNetwork.hasUtxo(refUtxo)) {
return preprodNetwork;
}
}
if (previewProjectId !== undefined) {
const previewNetwork = new BlockfrostV0("preview", previewProjectId);
if (!(await previewNetwork.hasUtxo(refUtxo))) {
throw new Error("not preview network (hint: provide project id for preprod");
} else {
return previewNetwork;
}
} else {
if (preprodProjectId === undefined) {
throw new Error("no project ids for testnets");
} else {
throw new Error("no project id for preview testnet");
}
}
return BlockfrostV0.resolveUsingUtxo(refUtxo, projectIds);
}

@@ -130,2 +154,22 @@ }

/**
* Connects to the same network a given `Wallet` or the given `TxInput` (preview, preprod or mainnet).
*
* Throws an error if a Blockfrost project_id is missing for that specific network.
* @param {TxInput | Wallet} utxoOrWallet
* @param {{
* preview?: string,
* preprod?: string,
* mainnet?: string
* }} projectIds
* @returns {Promise<BlockfrostV0>}
*/
static async resolve(utxoOrWallet, projectIds) {
if (utxoOrWallet instanceof TxInput) {
return BlockfrostV0.resolveUsingUtxo(utxoOrWallet, projectIds);
} else {
return BlockfrostV0.resolveUsingWallet(utxoOrWallet, projectIds);
}
}
/**

@@ -132,0 +176,0 @@ * @internal

@@ -661,2 +661,7 @@ //@ts-check

const expr = reader.readTerm();
reader.finalize();
// check version here, so any other errors in the deserialization are thrown first (which means the input is garbage)
if (versionKey != UPLC_VERSION) {

@@ -666,6 +671,2 @@ console.error(`Warning: Plutus-core script doesn't match version of Helios (expected ${UPLC_VERSION}, got ${versionKey})`);

const expr = reader.readTerm();
reader.finalize();
return new UplcProgram(expr, properties, version);

@@ -1108,2 +1109,4 @@ }

this.moveToByteBoundary(true);
assert(this.eof(), "not at end");
}

@@ -1110,0 +1113,0 @@ }

@@ -14,3 +14,3 @@ {

"name": "@hyperionbt/helios",
"version": "0.15.7",
"version": "0.15.8",
"license": "BSD-3-Clause",

@@ -17,0 +17,0 @@ "devDependencies": {

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc