diff --git a/packages/mesh-core-cst/src/resolvers/index.ts b/packages/mesh-core-cst/src/resolvers/index.ts index 1951000e5..81e38fb2f 100644 --- a/packages/mesh-core-cst/src/resolvers/index.ts +++ b/packages/mesh-core-cst/src/resolvers/index.ts @@ -7,8 +7,6 @@ Apache-2.0 License for more details. */ import { Cardano } from "@cardano-sdk/core"; -import { blake2b } from "@cardano-sdk/crypto"; -import { HexBlob } from "@cardano-sdk/util"; import base32 from "base32-encoding"; import { bech32 } from "bech32"; @@ -47,7 +45,7 @@ import { hexToBytes } from "../utils/encoding"; export const resolveDataHash = ( rawData: BuilderData["content"], type: PlutusDataType = "Mesh", -) => { +): string => { const plutusData = fromBuilderToPlutusData({ content: rawData, type, @@ -58,7 +56,7 @@ export const resolveDataHash = ( export const resolveNativeScriptAddress = ( script: NativeScript, networkId = 0, -) => { +): string => { const nativeScript = toNativeScript(script); const enterpriseAddress = EnterpriseAddress.fromCredentials(networkId, { @@ -69,11 +67,11 @@ export const resolveNativeScriptAddress = ( return enterpriseAddress.toAddress().toBech32().toString(); }; -export const resolveNativeScriptHash = (script: NativeScript) => { +export const resolveNativeScriptHash = (script: NativeScript): string => { return toNativeScript(script).hash().toString(); }; -export const resolvePaymentKeyHash = (bech32: string) => { +export const resolvePaymentKeyHash = (bech32: string): string => { try { const paymentKeyHash = [ toBaseAddress(bech32)?.getPaymentCredential().hash, @@ -95,7 +93,7 @@ export const resolvePaymentKeyHash = (bech32: string) => { export const resolvePlutusScriptAddress = ( script: PlutusScript, networkId = 0, -) => { +): string => { const plutusScript = deserializePlutusScript(script.code, script.version); const enterpriseAddress = EnterpriseAddress.fromCredentials(networkId, { @@ -106,7 +104,7 @@ export const resolvePlutusScriptAddress = ( return enterpriseAddress.toAddress().toBech32().toString(); }; -export const resolvePlutusScriptHash = (bech32: string) => { +export const resolvePlutusScriptHash = (bech32: string): string => { try { const enterpriseAddress = toEnterpriseAddress(bech32); const scriptHash = enterpriseAddress?.getPaymentCredential().hash; @@ -119,11 +117,11 @@ export const resolvePlutusScriptHash = (bech32: string) => { } }; -export const resolvePoolId = (hash: string) => { +export const resolvePoolId = (hash: string): string => { return PoolId.fromKeyHash(Ed25519KeyHashHex(hash)).toString(); }; -export const resolvePrivateKey = (words: string[]) => { +export const resolvePrivateKey = (words: string[]): string => { const buildBip32PrivateKey = ( entropy: string, password = "", @@ -142,11 +140,13 @@ export const resolvePrivateKey = (words: string[]) => { return bech32PrivateKey; }; -export const resolveScriptRef = (script: PlutusScript | NativeScript) => { +export const resolveScriptRef = ( + script: PlutusScript | NativeScript, +): string => { return toScriptRef(script).toCbor().toString(); }; -export const resolveRewardAddress = (bech32: string) => { +export const resolveRewardAddress = (bech32: string): string => { try { const address = toAddress(bech32); const baseAddress = toBaseAddress(bech32); @@ -164,7 +164,7 @@ export const resolveRewardAddress = (bech32: string) => { } }; -export const resolveStakeKeyHash = (bech32: string) => { +export const resolveStakeKeyHash = (bech32: string): string => { try { const stakeKeyHash = [ toBaseAddress(bech32)?.getStakeCredential().hash, @@ -179,19 +179,19 @@ export const resolveStakeKeyHash = (bech32: string) => { } }; -export const resolveTxHash = (txHex: string) => { +export const resolveTxHash = (txHex: string): string => { const txBody = deserializeTx(txHex).body(); return txBody.hash().toString(); }; -export const resolveScriptHashDRepId = (scriptHash: string) => { +export const resolveScriptHashDRepId = (scriptHash: string): string => { return DRepID.cip129FromCredential({ type: Cardano.CredentialType.ScriptHash, hash: Hash28ByteBase16(scriptHash), }).toString(); }; -export const resolveEd25519KeyHash = (bech32: string) => { +export const resolveEd25519KeyHash = (bech32: string): string => { try { const keyHash = [ toBaseAddress(bech32)?.getPaymentCredential().hash, diff --git a/packages/mesh-core/src/utils/deserializer.ts b/packages/mesh-core/src/utils/deserializer.ts index db4db004c..62c2ac225 100644 --- a/packages/mesh-core/src/utils/deserializer.ts +++ b/packages/mesh-core/src/utils/deserializer.ts @@ -1,4 +1,5 @@ import { DeserializedAddress } from "@meshsdk/common"; +import { PoolId } from "@meshsdk/core-cst"; import { core } from "../core"; @@ -27,5 +28,7 @@ export const deserializeDatum = (datumCbor: string): T => * @param poolId The poolxxxx bech32 pool id * @returns The Ed25519 key hash */ -export const deserializePoolId = (poolId: string): string => - core.resolveEd25519KeyHash(poolId); +export const deserializePoolId = (poolId: string): string => { + const cardanoPoolId: PoolId = PoolId(poolId); + return PoolId.toKeyHash(cardanoPoolId).toString(); +}; diff --git a/packages/mesh-provider/test/ogmios/evaluator.test.ts b/packages/mesh-provider/test/ogmios/evaluator.test.ts index 2322de61d..e64fe475a 100644 --- a/packages/mesh-provider/test/ogmios/evaluator.test.ts +++ b/packages/mesh-provider/test/ogmios/evaluator.test.ts @@ -7,7 +7,7 @@ import { resolveScriptHash, serializeRewardAddress, } from "@meshsdk/core"; -import { blake2b } from "@meshsdk/core-cst"; +import { blake2b, HexBlob } from "@meshsdk/core-cst"; import { OgmiosProvider } from "@meshsdk/provider"; dotenv.config(); @@ -60,7 +60,7 @@ describe("Ogmios Evaluator", () => { it("should succeed with with registering certificates", async () => { const txHash = (tx: string) => { - return blake2b(32).update(Buffer.from(tx, "utf-8")).digest("hex"); + return blake2b.hash(HexBlob(tx), 32); }; const alwaysSucceedCbor = applyCborEncoding(