diff --git a/.changeset/remove-buffer-usage.md b/.changeset/remove-buffer-usage.md new file mode 100644 index 00000000..d234a06f --- /dev/null +++ b/.changeset/remove-buffer-usage.md @@ -0,0 +1,14 @@ +--- +"@evolution-sdk/evolution": patch +--- + +### Remove Buffer Usage from Source Code + +Replaced all `Buffer.from()` usage with `Bytes.fromHex()` and `Bytes.toHex()` from the core module for better cross-platform compatibility. + +**Files Updated:** +- `TxBuilderImpl.ts` - Use `Bytes.toHex()` for key hash hex conversion in `buildFakeWitnessSet` +- `Assets/index.ts` - Use `Bytes.fromHex()` for policy ID and asset name decoding +- `MaestroEffect.ts` - Use `Bytes.fromHex()` for transaction CBOR conversion +- `Ogmios.ts` - Use `Bytes.toHex()` for datum hash hex conversion +- `KupmiosEffects.ts` - Use `Bytes.fromHex()` for datum hash and script bytes decoding diff --git a/packages/evolution/src/core/Assets/index.ts b/packages/evolution/src/core/Assets/index.ts index da478d92..00efa643 100644 --- a/packages/evolution/src/core/Assets/index.ts +++ b/packages/evolution/src/core/Assets/index.ts @@ -1,6 +1,7 @@ import { Effect as Eff, Equal, FastCheck, Hash, Inspectable, ParseResult, Schema } from "effect" import * as AssetName from "../AssetName.js" +import * as Bytes from "../Bytes.js" import * as CBOR from "../CBOR.js" import * as Coin from "../Coin.js" import * as MultiAsset from "../MultiAsset.js" @@ -107,12 +108,12 @@ export const fromUnit = ( const assetNameHex = dotIndex === -1 ? "" : unit.slice(dotIndex + 1) // Decode policy ID from hex (28 bytes = 56 hex chars) - const policyIdBytes = new Uint8Array(Buffer.from(policyIdHex, "hex")) + const policyIdBytes = Bytes.fromHex(policyIdHex) const policyId = new PolicyId.PolicyId({ hash: policyIdBytes }) // Decode asset name from hex (empty string yields empty bytes) const assetNameBytes = assetNameHex - ? new Uint8Array(Buffer.from(assetNameHex, "hex")) + ? Bytes.fromHex(assetNameHex) : new Uint8Array(0) const assetName = new AssetName.AssetName({ bytes: assetNameBytes }) diff --git a/packages/evolution/src/sdk/builders/TxBuilderImpl.ts b/packages/evolution/src/sdk/builders/TxBuilderImpl.ts index b1bf73cb..52221de8 100644 --- a/packages/evolution/src/sdk/builders/TxBuilderImpl.ts +++ b/packages/evolution/src/sdk/builders/TxBuilderImpl.ts @@ -5,6 +5,7 @@ import type * as Array from "effect/Array" // Core imports import type * as CoreAddress from "../../core/Address.js" import * as CoreAssets from "../../core/Assets/index.js" +import * as Bytes from "../../core/Bytes.js" import * as Bytes32 from "../../core/Bytes32.js" import * as PlutusData from "../../core/Data.js" import * as DatumOption from "../../core/DatumOption.js" @@ -825,7 +826,7 @@ export const buildFakeWitnessSet = ( for (const utxo of inputUtxos) { const keyHash = extractPaymentKeyHashFromCore(utxo.address) if (keyHash) { - const keyHashHex = Buffer.from(keyHash).toString("hex") + const keyHashHex = Bytes.toHex(keyHash) if (!keyHashesSet.has(keyHashHex)) { keyHashesSet.add(keyHashHex) keyHashes.push(keyHash) @@ -854,7 +855,7 @@ export const buildFakeWitnessSet = ( // Fill with unique pattern: 0xFF prefix + counter to distinguish from real keys dummyKeyHash[0] = 0xFF dummyKeyHash[1] = (keyHashesSet.size + i) & 0xFF - const dummyHashHex = Buffer.from(dummyKeyHash).toString("hex") + const dummyHashHex = Bytes.toHex(dummyKeyHash) // Only add if not already in the set if (!keyHashesSet.has(dummyHashHex)) { diff --git a/packages/evolution/src/sdk/provider/internal/KupmiosEffects.ts b/packages/evolution/src/sdk/provider/internal/KupmiosEffects.ts index 66aaec7a..da9866cc 100644 --- a/packages/evolution/src/sdk/provider/internal/KupmiosEffects.ts +++ b/packages/evolution/src/sdk/provider/internal/KupmiosEffects.ts @@ -1,6 +1,7 @@ import { FetchHttpClient } from "@effect/platform" import { Array as _Array, Effect, pipe, Schedule, Schema } from "effect" +import * as Bytes from "../../../core/Bytes.js" import * as CoreAddress from "../../../core/Address.js" import * as CoreAssets from "../../../core/Assets/index.js" import * as PlutusData from "../../../core/Data.js" @@ -89,7 +90,7 @@ const retrieveDatumEffect = Effect.catchAll((cause) => new ProviderError({ cause, message: "Failed to retrieve datum" })) ) } else if (datum_type === "hash" && datum_hash) { - const hashBytes = new Uint8Array(Buffer.from(datum_hash, "hex")) + const hashBytes = Bytes.fromHex(datum_hash) return new DatumOption.DatumHash({ hash: hashBytes }) } @@ -121,7 +122,7 @@ const getScriptEffect = break } // Convert hex script to bytes and wrap in ScriptRef - const scriptBytes = new Uint8Array(Buffer.from(encodedScript, "hex")) + const scriptBytes = Bytes.fromHex(encodedScript) return new ScriptRef.ScriptRef({ bytes: scriptBytes }) }), Effect.catchAll((cause) => new ProviderError({ cause, message: "Failed to get script" })) diff --git a/packages/evolution/src/sdk/provider/internal/MaestroEffect.ts b/packages/evolution/src/sdk/provider/internal/MaestroEffect.ts index 778bead3..ce489f05 100644 --- a/packages/evolution/src/sdk/provider/internal/MaestroEffect.ts +++ b/packages/evolution/src/sdk/provider/internal/MaestroEffect.ts @@ -5,6 +5,7 @@ import { Effect, Schema } from "effect" +import * as Bytes from "../../../core/Bytes.js" import * as CoreAddress from "../../../core/Address.js" import type * as CoreUTxO from "../../../core/UTxO.js" import type * as Credential from "../../Credential.js" @@ -169,7 +170,7 @@ export const submitTx = (baseUrl: string, apiKey: string, turboSubmit?: boolean) const endpoint = turboSubmit ? "/turbo/submit" : "/submit" // Convert hex string to Uint8Array for submission - const txBytes = new Uint8Array(Buffer.from(cbor, "hex")) + const txBytes = Bytes.fromHex(cbor) const response = yield* HttpUtils.postUint8Array( `${baseUrl}${endpoint}`, diff --git a/packages/evolution/src/sdk/provider/internal/Ogmios.ts b/packages/evolution/src/sdk/provider/internal/Ogmios.ts index 27a9fbb4..ca098394 100644 --- a/packages/evolution/src/sdk/provider/internal/Ogmios.ts +++ b/packages/evolution/src/sdk/provider/internal/Ogmios.ts @@ -1,6 +1,7 @@ import type { Record } from "effect" import { Schema } from "effect" +import * as Bytes from "../../../core/Bytes.js" import * as CoreAddress from "../../../core/Address.js" import * as AssetName from "../../../core/AssetName.js" import type * as CoreAssets from "../../../core/Assets/index.js" @@ -185,7 +186,7 @@ export const toOgmiosUTxOs = (utxos: Array | undefined): Array { if (!datumOption) return {} if (datumOption._tag === "DatumHash") { - return { datumHash: Buffer.from(datumOption.hash).toString("hex") } + return { datumHash: Bytes.toHex(datumOption.hash) } } if (datumOption._tag === "InlineDatum") { // Convert PlutusData to hex CBOR