diff --git a/packages/core/package.json b/packages/core/package.json index 6e000c30258..3d1c2b8187e 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -22,7 +22,6 @@ }, "dependencies": { "@cardano-ogmios/schema": "^4.0.0-beta.6", - "@emurgo/cardano-serialization-lib-nodejs": "^8.0.0", "buffer": "^6.0.3" } } diff --git a/packages/core/src/Asset/util.ts b/packages/core/src/Asset/util.ts index e16921fce91..2d328c92591 100644 --- a/packages/core/src/Asset/util.ts +++ b/packages/core/src/Asset/util.ts @@ -1,5 +1,4 @@ -import { CardanoSerializationLib } from '@cardano-sdk/cardano-serialization-lib'; -import { AssetName, ScriptHash } from '@emurgo/cardano-serialization-lib-nodejs'; +import { CardanoSerializationLib, CSL } from '@cardano-sdk/cardano-serialization-lib'; import { Buffer } from 'buffer'; export const policyIdFromAssetId = (assetId: string): string => assetId.slice(0, 56); @@ -8,7 +7,7 @@ export const assetNameFromAssetId = (assetId: string): string => assetId.slice(5 /** * @returns {string} concatenated hex-encoded policy id and asset name */ -export const createAssetId = (scriptHash: ScriptHash, assetName: AssetName): string => +export const createAssetId = (scriptHash: CSL.ScriptHash, assetName: CSL.AssetName): string => Buffer.from(scriptHash.to_bytes()).toString('hex') + Buffer.from(assetName.name()).toString('hex'); export const parseAssetId = (assetId: string, csl: CardanoSerializationLib) => { diff --git a/packages/core/src/Ogmios/OgmiosToCardanoWasm.ts b/packages/core/src/Ogmios/OgmiosToCardanoWasm.ts index eef952e9464..6fc992082fa 100644 --- a/packages/core/src/Ogmios/OgmiosToCardanoWasm.ts +++ b/packages/core/src/Ogmios/OgmiosToCardanoWasm.ts @@ -1,40 +1,34 @@ -import CardanoWasm from '@emurgo/cardano-serialization-lib-nodejs'; +import { CSL } from '@cardano-sdk/cardano-serialization-lib'; import OgmiosSchema from '@cardano-ogmios/schema'; import * as Asset from '../Asset'; export const OgmiosToCardanoWasm = { - txIn: (ogmios: OgmiosSchema.TxIn): CardanoWasm.TransactionInput => - CardanoWasm.TransactionInput.new( - CardanoWasm.TransactionHash.from_bytes(Buffer.from(ogmios.txId, 'hex')), - ogmios.index - ), - txOut: (ogmios: OgmiosSchema.TxOut): CardanoWasm.TransactionOutput => - CardanoWasm.TransactionOutput.new( - CardanoWasm.Address.from_bech32(ogmios.address), - OgmiosToCardanoWasm.value(ogmios.value) - ), - utxo: (ogmios: OgmiosSchema.Utxo): CardanoWasm.TransactionUnspentOutput[] => + txIn: (ogmios: OgmiosSchema.TxIn): CSL.TransactionInput => + CSL.TransactionInput.new(CSL.TransactionHash.from_bytes(Buffer.from(ogmios.txId, 'hex')), ogmios.index), + txOut: (ogmios: OgmiosSchema.TxOut): CSL.TransactionOutput => + CSL.TransactionOutput.new(CSL.Address.from_bech32(ogmios.address), OgmiosToCardanoWasm.value(ogmios.value)), + utxo: (ogmios: OgmiosSchema.Utxo): CSL.TransactionUnspentOutput[] => ogmios.map((item) => - CardanoWasm.TransactionUnspentOutput.new(OgmiosToCardanoWasm.txIn(item[0]), OgmiosToCardanoWasm.txOut(item[1])) + CSL.TransactionUnspentOutput.new(OgmiosToCardanoWasm.txIn(item[0]), OgmiosToCardanoWasm.txOut(item[1])) ), - value: (ogmios: OgmiosSchema.Value): CardanoWasm.Value => { - const value = CardanoWasm.Value.new(CardanoWasm.BigNum.from_str(ogmios.coins.toString())); + value: (ogmios: OgmiosSchema.Value): CSL.Value => { + const value = CSL.Value.new(CSL.BigNum.from_str(ogmios.coins.toString())); const assets = ogmios.assets !== undefined ? Object.entries(ogmios.assets) : []; if (assets.length === 0) { return value; } - const multiAsset = CardanoWasm.MultiAsset.new(); + const multiAsset = CSL.MultiAsset.new(); const policies = [...new Set(assets.map(([assetId]) => Asset.util.policyIdFromAssetId(assetId)))]; for (const policy of policies) { const policyAssets = assets.filter(([assetId]) => Asset.util.policyIdFromAssetId(assetId) === policy); - const wasmAssets = CardanoWasm.Assets.new(); + const wasmAssets = CSL.Assets.new(); for (const [assetId, assetQuantity] of policyAssets) { wasmAssets.insert( - CardanoWasm.AssetName.new(Buffer.from(Asset.util.assetNameFromAssetId(assetId), 'hex')), - CardanoWasm.BigNum.from_str(assetQuantity.toString()) + CSL.AssetName.new(Buffer.from(Asset.util.assetNameFromAssetId(assetId), 'hex')), + CSL.BigNum.from_str(assetQuantity.toString()) ); } - multiAsset.insert(CardanoWasm.ScriptHash.from_bytes(Buffer.from(policy, 'hex')), wasmAssets); + multiAsset.insert(CSL.ScriptHash.from_bytes(Buffer.from(policy, 'hex')), wasmAssets); } value.set_multiasset(multiAsset); return value; diff --git a/packages/core/src/Provider/CardanoProvider.ts b/packages/core/src/Provider/CardanoProvider.ts index 3e9441cc28a..3c1dc40847b 100644 --- a/packages/core/src/Provider/CardanoProvider.ts +++ b/packages/core/src/Provider/CardanoProvider.ts @@ -1,5 +1,4 @@ -// Importing types from cardano-serialization-lib-browser will cause TypeScript errors. -import CardanoSerializationLib from '@emurgo/cardano-serialization-lib-nodejs'; +import { CSL } from '@cardano-sdk/cardano-serialization-lib'; import Cardano, { ProtocolParametersAlonzo } from '@cardano-ogmios/schema'; import { Transaction } from '../'; @@ -20,7 +19,7 @@ export type ProtocolParametersRequiredByWallet = Pick< export interface CardanoProvider { ledgerTip: () => Promise; /** @param signedTransaction signed and serialized cbor */ - submitTx: (tx: CardanoSerializationLib.Transaction) => Promise; + submitTx: (tx: CSL.Transaction) => Promise; utxoDelegationAndRewards: ( addresses: Cardano.Address[], stakeKeyHash: Cardano.Hash16 diff --git a/packages/core/test/Ogmios/OgmiosToCardanoWasm.test.ts b/packages/core/test/Ogmios/OgmiosToCardanoWasm.test.ts index b5bfaf4c70c..44f69012bd1 100644 --- a/packages/core/test/Ogmios/OgmiosToCardanoWasm.test.ts +++ b/packages/core/test/Ogmios/OgmiosToCardanoWasm.test.ts @@ -1,4 +1,4 @@ -import CardanoWasm from '@emurgo/cardano-serialization-lib-nodejs'; +import { CSL } from '@cardano-sdk/cardano-serialization-lib'; import { OgmiosToCardanoWasm } from '../../src/Ogmios'; import * as OgmiosSchema from '@cardano-ogmios/schema'; @@ -11,15 +11,15 @@ const txOut: OgmiosSchema.TxOut = { describe('OgmiosToCardanoWasm', () => { test('txIn', () => { - expect(OgmiosToCardanoWasm.txIn(txIn)).toBeInstanceOf(CardanoWasm.TransactionInput); + expect(OgmiosToCardanoWasm.txIn(txIn)).toBeInstanceOf(CSL.TransactionInput); }); test('txOut', () => { - expect(OgmiosToCardanoWasm.txOut(txOut)).toBeInstanceOf(CardanoWasm.TransactionOutput); + expect(OgmiosToCardanoWasm.txOut(txOut)).toBeInstanceOf(CSL.TransactionOutput); }); test('utxo', () => { - expect(OgmiosToCardanoWasm.utxo([[txIn, txOut]])[0]).toBeInstanceOf(CardanoWasm.TransactionUnspentOutput); + expect(OgmiosToCardanoWasm.utxo([[txIn, txOut]])[0]).toBeInstanceOf(CSL.TransactionUnspentOutput); }); test('value', () => { - expect(OgmiosToCardanoWasm.value(txOut.value)).toBeInstanceOf(CardanoWasm.Value); + expect(OgmiosToCardanoWasm.value(txOut.value)).toBeInstanceOf(CSL.Value); }); });