Skip to content

Commit

Permalink
packaging changes
Browse files Browse the repository at this point in the history
  • Loading branch information
micahkendall committed Jul 30, 2024
1 parent 6e9352d commit ae2d1f2
Show file tree
Hide file tree
Showing 15 changed files with 139 additions and 94 deletions.
10 changes: 10 additions & 0 deletions .changeset/funny-trains-allow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@blaze-cardano/blueprint": minor
"@blaze-cardano/query": minor
"@blaze-cardano/core": minor
"@blaze-cardano/uplc": minor
"@blaze-cardano/sdk": minor
"@blaze-cardano/tx": minor
---

packaging changes
5 changes: 1 addition & 4 deletions packages/blaze-blueprint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,10 @@
"ts-jest": "^29.2.3",
"tsup": "^8.2.3",
"tsx": "^4.16.2",
"typescript": "^5.5.4"
},
"dependencies": {
"typescript": "^5.5.4",
"@blaze-cardano/core": "workspace:*",
"@blaze-cardano/tx": "workspace:*",
"@blaze-cardano/uplc": "workspace:*",
"@cardano-sdk/core": "^0.35.4",
"@commander-js/extra-typings": "^12.1.0",
"commander": "^12.1.0"
},
Expand Down
12 changes: 6 additions & 6 deletions packages/blaze-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,30 @@
},
"types": "./dist/index.d.ts",
"scripts": {
"build": "tsup src/index.ts --format esm,cjs --dts ",
"build": "tsup src/index.ts --format esm,cjs --dts",
"dev": "tsup src/index.ts --format esm,cjs --watch --dts",
"lint": "eslint \"src/**/*.ts*\"",
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
},
"devDependencies": {
"@blaze-cardano/eslint-config": "workspace:*",
"@blaze-cardano/tsconfig": "workspace:*",
"@cardano-sdk/core": "^0.35.4",
"@cardano-sdk/crypto": "^0.1.28",
"@cardano-sdk/util": "^0.15.4",
"eslint": "^8.57.0",
"terser": "^5.31.3",
"tsup": "^8.2.3",
"typescript": "^5.5.4"
},
"publishConfig": {
"access": "public"
},
"dependencies": {
"@cardano-sdk/core": "^0.35.4",
"@cardano-sdk/crypto": "^0.1.28",
"@cardano-sdk/util": "^0.15.4",
"@noble/curves": "^1.4.2",
"@noble/ed25519": "^2.1.0",
"@noble/hashes": "^1.4.0",
"@scure/bip39": "^1.3.0",
"blakejs": "^1.2.1",
"rxjs": "7.8.1"
"blakejs": "^1.2.1"
}
}
6 changes: 6 additions & 0 deletions packages/blaze-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@ export type CostModel = C.Serialization.CostModel;
export const CborWriter = C.Serialization.CborWriter;
export type CborWriter = C.Serialization.CborWriter;

export const CborReader = C.Serialization.CborReader;
export type CborReader = C.Serialization.CborReader;

export const CborReaderState = C.Serialization.CborReaderState;
export type CborReaderState = C.Serialization.CborReaderState;

export const RewardAccount = C.Cardano.RewardAccount;
export type RewardAccount = C.Cardano.RewardAccount;

Expand Down
4 changes: 2 additions & 2 deletions packages/blaze-query/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
"jest": "^29.7.0",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.2",
"typescript": "^5.3.3"
"typescript": "^5.3.3",
"@cardano-ogmios/schema": "^6.4.0"
},
"publishConfig": {
"access": "public"
},
"dependencies": {
"@blaze-cardano/core": "workspace:*",
"@blaze-cardano/jest-config": "workspace:*",
"@cardano-ogmios/schema": "^6.4.0",
"ws": "^8.17.1"
}
}
2 changes: 1 addition & 1 deletion packages/blaze-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
"access": "public"
},
"dependencies": {
"@blaze-cardano/blueprint": "workspace:*",
"@blaze-cardano/core": "workspace:*",
"@blaze-cardano/query": "workspace:*",
"@blaze-cardano/tx": "workspace:*",
"@blaze-cardano/uplc": "workspace:*",
"@blaze-cardano/wallet": "workspace:*"
}
}
2 changes: 1 addition & 1 deletion packages/blaze-sdk/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export * from "./blaze";
export * from "@blaze-cardano/blueprint";
export * from "@blaze-cardano/query";
export * from "@blaze-cardano/tx";
export * from "@blaze-cardano/wallet";
export * from "@blaze-cardano/uplc";
export * as Core from "@blaze-cardano/core";
6 changes: 3 additions & 3 deletions packages/blaze-tx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@
"ts-jest": "^29.1.1",
"ts-node": "^10.9.2",
"tsup": "^8.0.2",
"typescript": "^5.3.3"
"typescript": "^5.3.3",
"@sinclair/typebox": "^0.32.32"
},
"publishConfig": {
"access": "public"
},
"dependencies": {
"@blaze-cardano/core": "workspace:*",
"@sinclair/typebox": "^0.32.32"
"@blaze-cardano/core": "workspace:*"
}
}
4 changes: 1 addition & 3 deletions packages/blaze-uplc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,14 @@
"jest": "^29.7.0",
"ts-jest": "^29.2.3",
"tsup": "^8.2.3",
"typescript": "^5.5.4",
"uplc-node": "^0.0.3"
"typescript": "^5.5.4"
},
"publishConfig": {
"access": "public"
},
"dependencies": {
"@blaze-cardano/core": "workspace:*",
"@blaze-cardano/tx": "workspace:*",
"@cardano-sdk/core": "^0.35.4",
"hex-encoding": "^2.0.2"
}
}
16 changes: 9 additions & 7 deletions packages/blaze-uplc/src/decoder.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Serialization, type Cardano } from "@cardano-sdk/core";
import { Parser as FlatDecoder } from "./flat";
import type { Byte, Data, ParsedProgram, ParsedTerm, SemVer } from "./types";
import { BuiltinFunctions, DataType, type TermNames, termTags } from "./types";
import { HexBlob, fromHex, toHex } from "@blaze-cardano/core";
import { ConstrPlutusData, PlutusList } from "@blaze-cardano/core";
import { HexBlob, PlutusData, fromHex, toHex } from "@blaze-cardano/core";

/**
* This class provides decoding functionality for UPLC (Untyped Plutus Core) programs.
Expand Down Expand Up @@ -111,17 +111,19 @@ export class UPLCDecoder extends FlatDecoder {
* Decodes a boolean value from the binary stream.
* @returns {object} The decoded boolean value as a UPLC data structure.
*/
#decodeBool(): Cardano.ConstrPlutusData {
return { constructor: this.popBit() == 0 ? 0n : 1n, fields: { items: [] } };
#decodeBool(): Data {
return PlutusData.newConstrPlutusData(
new ConstrPlutusData(this.popBit() == 0 ? 0n : 1n, new PlutusList()),
).toCore();
}

/**
* Decodes CBOR data from the binary stream.
* @returns {Cardano.PlutusData} The decoded data in Plutus core format.
* @returns {PlutusData} The decoded data in Plutus core format.
*/
#decodeCborData(): Cardano.PlutusData {
#decodeCborData(): Data {
const cbor = this.#decodeByteString();
return Serialization.PlutusData.fromCbor(HexBlob(toHex(cbor))).toCore();
return PlutusData.fromCbor(HexBlob(toHex(cbor))).toCore();
}

/**
Expand Down
31 changes: 21 additions & 10 deletions packages/blaze-uplc/src/encoder.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Encoder as FlatEncoder } from "./flat";
import { type Cardano } from "@cardano-sdk/core";
import { BuiltinFunctions, DataType, TermNames, termTags } from "./types";
import type {
Data,
Expand Down Expand Up @@ -109,20 +108,32 @@ export class UPLCEncoder extends FlatEncoder {
} else if (type === "Unit") {
// No data to encode for Unit type
} else if (type === "Bool") {
this.encodeBool((data as Cardano.ConstrPlutusData).constructor === 1n);
if (typeof data == "object" && "constructor" in data) {
this.encodeBool(data.constructor === 1n);
} else {
throw new Error(`Cannot encode data of type ${JSON.stringify(type)}`);
}
} else if (type === "Data") {
this.encodeByteString(fromHex(PlutusData.fromCore(data).toCbor()));
} else if (typeof type === "object" && "list" in type) {
const list = (data as Cardano.PlutusList).items;
for (let i = 0; i < list.length; i++) {
this.pushBit(1);
this.encodeData(type.list, list[i]!);
if (typeof data == "object" && "items" in data) {
const list = data.items;
for (let i = 0; i < list.length; i++) {
this.pushBit(1);
this.encodeData(type.list, list[i]!);
}
this.pushBit(0);
} else {
throw new Error(`Cannot encode data of type ${JSON.stringify(type)}`);
}
this.pushBit(0);
} else if (typeof type === "object" && "pair" in type) {
const pair = (data as Cardano.PlutusList).items as [Data, Data];
this.encodeData(type.pair[0], pair[0]);
this.encodeData(type.pair[1], pair[1]);
if (typeof data == "object" && "items" in data) {
const pair = data.items as [Data, Data];
this.encodeData(type.pair[0], pair[0]);
this.encodeData(type.pair[1], pair[1]);
} else {
throw new Error(`Cannot encode data of type ${JSON.stringify(type)}`);
}
} else {
throw new Error(`Cannot encode data of type ${JSON.stringify(type)}`);
}
Expand Down
5 changes: 2 additions & 3 deletions packages/blaze-uplc/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Serialization } from "@cardano-sdk/core";
export const { CborReader, PlutusData } = Serialization;
import type { PlutusData } from "@blaze-cardano/core";

export type Bit = 0 | 1;
export type Byte = number & { __opaqueNumber: "Byte" };
Expand All @@ -24,7 +23,7 @@ export const TermNames = {
} as const;
export type TermNames = typeof TermNames;

export type Data = ReturnType<Serialization.PlutusData["toCore"]>;
export type Data = ReturnType<PlutusData["toCore"]>;

export const DataType = {
0: "Integer",
Expand Down
5 changes: 3 additions & 2 deletions packages/blaze-uplc/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import {
PlutusV1Script,
PlutusV2Script,
Script,
CborReader,
CborWriter,
CborReaderState,
} from "@blaze-cardano/core";
import { HexBlob } from "@blaze-cardano/core";
import { UPLCDecoder } from "./decoder";
import { type ParsedProgram, TermNames } from "./types";
import { Serialization } from "@cardano-sdk/core";
import { UPLCEncoder } from "./encoder";
import { type Exact, Data } from "@blaze-cardano/tx";
import type { TArray } from "@sinclair/typebox";
const { CborReader, CborWriter, CborReaderState } = Serialization;

// TODO: Use the c-js-sdk enums for this if possible
export type ScriptType = "Native" | "PlutusV1" | "PlutusV2";
Expand Down
5 changes: 0 additions & 5 deletions packages/blaze-uplc/tsup.config.ts

This file was deleted.

Loading

0 comments on commit ae2d1f2

Please sign in to comment.