Skip to content

Commit fe0757e

Browse files
Merge pull request #103 from IntersectMBO/fix/remove-buffer
fix: remove buffer
2 parents 2edb617 + 65b7259 commit fe0757e

File tree

6 files changed

+27
-8
lines changed

6 files changed

+27
-8
lines changed

.changeset/remove-buffer-usage.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
"@evolution-sdk/evolution": patch
3+
---
4+
5+
### Remove Buffer Usage from Source Code
6+
7+
Replaced all `Buffer.from()` usage with `Bytes.fromHex()` and `Bytes.toHex()` from the core module for better cross-platform compatibility.
8+
9+
**Files Updated:**
10+
- `TxBuilderImpl.ts` - Use `Bytes.toHex()` for key hash hex conversion in `buildFakeWitnessSet`
11+
- `Assets/index.ts` - Use `Bytes.fromHex()` for policy ID and asset name decoding
12+
- `MaestroEffect.ts` - Use `Bytes.fromHex()` for transaction CBOR conversion
13+
- `Ogmios.ts` - Use `Bytes.toHex()` for datum hash hex conversion
14+
- `KupmiosEffects.ts` - Use `Bytes.fromHex()` for datum hash and script bytes decoding

packages/evolution/src/core/Assets/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Effect as Eff, Equal, FastCheck, Hash, Inspectable, ParseResult, Schema } from "effect"
22

33
import * as AssetName from "../AssetName.js"
4+
import * as Bytes from "../Bytes.js"
45
import * as CBOR from "../CBOR.js"
56
import * as Coin from "../Coin.js"
67
import * as MultiAsset from "../MultiAsset.js"
@@ -107,12 +108,12 @@ export const fromUnit = (
107108
const assetNameHex = dotIndex === -1 ? "" : unit.slice(dotIndex + 1)
108109

109110
// Decode policy ID from hex (28 bytes = 56 hex chars)
110-
const policyIdBytes = new Uint8Array(Buffer.from(policyIdHex, "hex"))
111+
const policyIdBytes = Bytes.fromHex(policyIdHex)
111112
const policyId = new PolicyId.PolicyId({ hash: policyIdBytes })
112113

113114
// Decode asset name from hex (empty string yields empty bytes)
114115
const assetNameBytes = assetNameHex
115-
? new Uint8Array(Buffer.from(assetNameHex, "hex"))
116+
? Bytes.fromHex(assetNameHex)
116117
: new Uint8Array(0)
117118
const assetName = new AssetName.AssetName({ bytes: assetNameBytes })
118119

packages/evolution/src/sdk/builders/TxBuilderImpl.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type * as Array from "effect/Array"
55
// Core imports
66
import type * as CoreAddress from "../../core/Address.js"
77
import * as CoreAssets from "../../core/Assets/index.js"
8+
import * as Bytes from "../../core/Bytes.js"
89
import * as Bytes32 from "../../core/Bytes32.js"
910
import * as PlutusData from "../../core/Data.js"
1011
import * as DatumOption from "../../core/DatumOption.js"
@@ -825,7 +826,7 @@ export const buildFakeWitnessSet = (
825826
for (const utxo of inputUtxos) {
826827
const keyHash = extractPaymentKeyHashFromCore(utxo.address)
827828
if (keyHash) {
828-
const keyHashHex = Buffer.from(keyHash).toString("hex")
829+
const keyHashHex = Bytes.toHex(keyHash)
829830
if (!keyHashesSet.has(keyHashHex)) {
830831
keyHashesSet.add(keyHashHex)
831832
keyHashes.push(keyHash)
@@ -854,7 +855,7 @@ export const buildFakeWitnessSet = (
854855
// Fill with unique pattern: 0xFF prefix + counter to distinguish from real keys
855856
dummyKeyHash[0] = 0xFF
856857
dummyKeyHash[1] = (keyHashesSet.size + i) & 0xFF
857-
const dummyHashHex = Buffer.from(dummyKeyHash).toString("hex")
858+
const dummyHashHex = Bytes.toHex(dummyKeyHash)
858859

859860
// Only add if not already in the set
860861
if (!keyHashesSet.has(dummyHashHex)) {

packages/evolution/src/sdk/provider/internal/KupmiosEffects.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { FetchHttpClient } from "@effect/platform"
22
import { Array as _Array, Effect, pipe, Schedule, Schema } from "effect"
33

4+
import * as Bytes from "../../../core/Bytes.js"
45
import * as CoreAddress from "../../../core/Address.js"
56
import * as CoreAssets from "../../../core/Assets/index.js"
67
import * as PlutusData from "../../../core/Data.js"
@@ -89,7 +90,7 @@ const retrieveDatumEffect =
8990
Effect.catchAll((cause) => new ProviderError({ cause, message: "Failed to retrieve datum" }))
9091
)
9192
} else if (datum_type === "hash" && datum_hash) {
92-
const hashBytes = new Uint8Array(Buffer.from(datum_hash, "hex"))
93+
const hashBytes = Bytes.fromHex(datum_hash)
9394
return new DatumOption.DatumHash({ hash: hashBytes })
9495
}
9596

@@ -121,7 +122,7 @@ const getScriptEffect =
121122
break
122123
}
123124
// Convert hex script to bytes and wrap in ScriptRef
124-
const scriptBytes = new Uint8Array(Buffer.from(encodedScript, "hex"))
125+
const scriptBytes = Bytes.fromHex(encodedScript)
125126
return new ScriptRef.ScriptRef({ bytes: scriptBytes })
126127
}),
127128
Effect.catchAll((cause) => new ProviderError({ cause, message: "Failed to get script" }))

packages/evolution/src/sdk/provider/internal/MaestroEffect.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import { Effect, Schema } from "effect"
77

8+
import * as Bytes from "../../../core/Bytes.js"
89
import * as CoreAddress from "../../../core/Address.js"
910
import type * as CoreUTxO from "../../../core/UTxO.js"
1011
import type * as Credential from "../../Credential.js"
@@ -169,7 +170,7 @@ export const submitTx = (baseUrl: string, apiKey: string, turboSubmit?: boolean)
169170
const endpoint = turboSubmit ? "/turbo/submit" : "/submit"
170171

171172
// Convert hex string to Uint8Array for submission
172-
const txBytes = new Uint8Array(Buffer.from(cbor, "hex"))
173+
const txBytes = Bytes.fromHex(cbor)
173174

174175
const response = yield* HttpUtils.postUint8Array(
175176
`${baseUrl}${endpoint}`,

packages/evolution/src/sdk/provider/internal/Ogmios.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Record } from "effect"
22
import { Schema } from "effect"
33

4+
import * as Bytes from "../../../core/Bytes.js"
45
import * as CoreAddress from "../../../core/Address.js"
56
import * as AssetName from "../../../core/AssetName.js"
67
import type * as CoreAssets from "../../../core/Assets/index.js"
@@ -185,7 +186,7 @@ export const toOgmiosUTxOs = (utxos: Array<CoreUTxO.UTxO> | undefined): Array<Og
185186
const toOgmiosDatum = (datumOption: DatumOption.DatumOption | undefined): { datumHash?: string; datum?: string } => {
186187
if (!datumOption) return {}
187188
if (datumOption._tag === "DatumHash") {
188-
return { datumHash: Buffer.from(datumOption.hash).toString("hex") }
189+
return { datumHash: Bytes.toHex(datumOption.hash) }
189190
}
190191
if (datumOption._tag === "InlineDatum") {
191192
// Convert PlutusData to hex CBOR

0 commit comments

Comments
 (0)