Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .changeset/remove-buffer-usage.md
Original file line number Diff line number Diff line change
@@ -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
5 changes: 3 additions & 2 deletions packages/evolution/src/core/Assets/index.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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 })

Expand Down
5 changes: 3 additions & 2 deletions packages/evolution/src/sdk/builders/TxBuilderImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { FetchHttpClient } from "@effect/platform"

Check failure on line 1 in packages/evolution/src/sdk/provider/internal/KupmiosEffects.ts

View workflow job for this annotation

GitHub Actions / ⬣ ESLint

Run autofix to sort these imports!
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"
Expand Down Expand Up @@ -89,7 +90,7 @@
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 })
}

Expand Down Expand Up @@ -121,7 +122,7 @@
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" }))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
* Internal module implementing curry pattern with rate limiting
*/

import { Effect, Schema } from "effect"

Check failure on line 6 in packages/evolution/src/sdk/provider/internal/MaestroEffect.ts

View workflow job for this annotation

GitHub Actions / ⬣ ESLint

Run autofix to sort these imports!

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"
Expand Down Expand Up @@ -169,7 +170,7 @@
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}`,
Expand Down
3 changes: 2 additions & 1 deletion packages/evolution/src/sdk/provider/internal/Ogmios.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Record } from "effect"

Check failure on line 1 in packages/evolution/src/sdk/provider/internal/Ogmios.ts

View workflow job for this annotation

GitHub Actions / ⬣ ESLint

Run autofix to sort these imports!
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"
Expand Down Expand Up @@ -185,7 +186,7 @@
const toOgmiosDatum = (datumOption: DatumOption.DatumOption | undefined): { datumHash?: string; datum?: string } => {
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
Expand Down
Loading