diff --git a/packages/csl/package.json b/packages/csl/package.json index 5e0530b..666050c 100644 --- a/packages/csl/package.json +++ b/packages/csl/package.json @@ -1,7 +1,7 @@ { "name": "@meshsdk/core-csl", "description": "Cardano Off-chain Code APIs built on cardano-serialization-lib", - "version": "1.6.0-alpha.3", + "version": "1.6.0-alpha.5", "license": "Apache-2.0", "main": "dist/cjs/index.js", "module": "dist/mjs/index.js", @@ -38,8 +38,8 @@ "@sidan-lab/sidan-csl-rs-nodejs": "@sidan-lab/sidan-csl-rs-browser" }, "dependencies": { - "@sidan-lab/sidan-csl-rs-browser": "^0.3.6", - "@sidan-lab/sidan-csl-rs-nodejs": "^0.3.6", + "@sidan-lab/sidan-csl-rs-browser": "^0.5.0-alpha.9", + "@sidan-lab/sidan-csl-rs-nodejs": "^0.5.0-alpha.9", "blakejs": "^1.2.1", "json-bigint": "^1.0.0" }, diff --git a/packages/csl/src/core/builder.ts b/packages/csl/src/core/builder.ts index c734ebc..2feb824 100644 --- a/packages/csl/src/core/builder.ts +++ b/packages/csl/src/core/builder.ts @@ -1,44 +1,10 @@ /* eslint-disable default-case */ /* eslint-disable class-methods-use-this */ /* eslint-disable radix */ -import type { - Asset, - BuilderData, - Certificate, - MeshTxBuilderBody, - Metadata, - MintItem, - Output, - PoolParams, - Protocol, - PubKeyTxIn, - Quantity, - RefTxIn, - RequiredWith, - ScriptSourceInfo, - ScriptTxIn, - TxIn, - TxInParameter, - UTxO, - Unit, - ValidityRange, - IMeshSerializer, -} from '@meshsdk/common'; -import { DEFAULT_PROTOCOL_PARAMETERS, selectUtxos } from '@meshsdk/common'; -import JSONbig from 'json-bigint'; +import type { MeshTxBuilderBody, Protocol, TxInParameter, IMeshSerializer } from '@meshsdk/common'; +import { DEFAULT_PROTOCOL_PARAMETERS } from '@meshsdk/common'; import { signTransaction } from '../utils'; -import { - TransactionBuilder, - buildDataCost, - buildTxBuilder, - toAddress, - toPlutusData, - toRelay, - toValue, - csl, - LANGUAGE_VERSIONS, - Relay, -} from '../deser'; +import { csl } from '../deser'; export const emptyTxBuilderBody = (): MeshTxBuilderBody => ({ inputs: [], @@ -57,126 +23,19 @@ export const emptyTxBuilderBody = (): MeshTxBuilderBody => ({ }); export class CSLSerializer implements IMeshSerializer { - txBuilder: TransactionBuilder; - protocolParams: Protocol; meshTxBuilderBody: MeshTxBuilderBody = emptyTxBuilderBody(); constructor(protocolParams?: Protocol) { this.protocolParams = protocolParams || DEFAULT_PROTOCOL_PARAMETERS; - this.txBuilder = buildTxBuilder(protocolParams); } serializeTxBody(txBody: MeshTxBuilderBody, protocolParams?: Protocol): string { - if (protocolParams) { - this.protocolParams = protocolParams; - } - this.txBuilder = buildTxBuilder(protocolParams); - const { - inputs, - outputs, - extraInputs, - selectionThreshold, - collaterals, - referenceInputs, - mints, - changeAddress, - certificates, - validityRange, - requiredSignatures, - metadata, - } = txBody; - - if (extraInputs.length > 0) { - this.addUtxosFrom(extraInputs, String(selectionThreshold)); - } - - this.removeDuplicateInputs(); - - mints.sort((a, b) => a.policyId.localeCompare(b.policyId)); - inputs.sort((a, b) => { - if (a.txIn.txHash === b.txIn.txHash) { - return a.txIn.txIndex - b.txIn.txIndex; - } - return a.txIn.txHash.localeCompare(b.txIn.txHash); - }); - - this.addAllInputs(inputs); - this.addAllOutputs(outputs); - this.addAllCollaterals(collaterals); - this.addAllReferenceInputs(referenceInputs); - this.addAllMints(mints); - this.addAllCertificates(certificates); - this.addValidityRange(validityRange); - this.addAllRequiredSignatures(requiredSignatures); - this.addAllMetadata(metadata); - - this.addCostModels(); - if (changeAddress) { - // Hacky fix to set a dummy collateral return so fees are calculated correctly - const totalCollateral = collaterals - .map( - (collateral) => - collateral.txIn.amount?.find((asset) => asset.unit === 'lovelace') - ?.quantity || '0', - ) - .reduce((acc, curr) => acc + parseInt(curr), 0); - - const collateralEstimate = Math.ceil( - (this.protocolParams.collateralPercent * - Number( - Number( - this.txBuilder - .min_fee() - .checked_add(csl.BigNum.from_str('10000')) - .to_js_value(), - ), - )) / - 100, - ); - - let collateralReturnNeeded = false; - - if (totalCollateral - collateralEstimate > 0) { - const collateralEstimateOutput = csl.TransactionOutput.new( - csl.Address.from_bech32(changeAddress), - csl.Value.new(csl.BigNum.from_str(String(collateralEstimate))), - ); - - if ( - totalCollateral - collateralEstimate > - Number( - csl - .min_ada_for_output( - collateralEstimateOutput, - csl.DataCost.new_coins_per_byte( - csl.BigNum.from_str(this.protocolParams.coinsPerUTxOSize), - ), - ) - .to_js_value(), - ) - ) { - this.txBuilder.set_collateral_return( - csl.TransactionOutput.new( - csl.Address.from_bech32(changeAddress), - csl.Value.new(csl.BigNum.from_str(String(totalCollateral))), - ), - ); - this.txBuilder.set_total_collateral( - csl.BigNum.from_str(String(totalCollateral)), - ); - collateralReturnNeeded = true; - } - } - - this.addChange(changeAddress); - if (collateralReturnNeeded) this.addCollateralReturn(changeAddress); - } - - const tx = this.txBuilder.build_tx(); - // const txJson = JSON.parse(tx.to_json()); - const txHex = tx.to_hex(); + const txHex = csl.js_serialize_tx_body( + JSON.stringify(txBody), + JSON.stringify(protocolParams || this.protocolParams), + ); return txHex; } @@ -187,66 +46,6 @@ export class CSLSerializer implements IMeshSerializer { return txHex; } - private addUtxosFrom = (extraInputs: UTxO[], threshold: Quantity) => { - const requiredAssets = this.meshTxBuilderBody.outputs.reduce((map, output) => { - const outputAmount = output.amount; - outputAmount.forEach((asset) => { - const { unit, quantity } = asset; - const existingQuantity = Number(map.get(unit)) || 0; - map.set(unit, String(existingQuantity + Number(quantity))); - }); - return map; - }, new Map()); - this.meshTxBuilderBody.inputs.reduce((map, input) => { - const inputAmount = input.txIn.amount; - inputAmount?.forEach((asset) => { - const { unit, quantity } = asset; - const existingQuantity = Number(map.get(unit)) || 0; - map.set(unit, String(existingQuantity - Number(quantity))); - }); - return map; - }, requiredAssets); - this.meshTxBuilderBody.mints.reduce((map, mint) => { - const mintAmount: Asset = { - unit: mint.policyId + mint.assetName, - quantity: String(mint.amount), - }; - const existingQuantity = Number(map.get(mintAmount.unit)) || 0; - map.set(mintAmount.unit, String(existingQuantity - Number(mintAmount.quantity))); - return map; - }, requiredAssets); - const selectedInputs = selectUtxos(extraInputs, requiredAssets, threshold); - selectedInputs.forEach((input) => { - const pubKeyTxIn: PubKeyTxIn = { - type: 'PubKey', - txIn: { - txHash: input.input.txHash, - txIndex: input.input.outputIndex, - amount: input.output.amount, - address: input.output.address, - }, - }; - this.meshTxBuilderBody.inputs.push(pubKeyTxIn); - this.addTxIn(pubKeyTxIn as RequiredWith); - }); - }; - - private makePlutusScriptSource = ( - scriptSourceInfo: Required, - ): csl.PlutusScriptSource => { - const scriptHash = csl.ScriptHash.from_hex(scriptSourceInfo.spendingScriptHash); - const scriptRefInput = csl.TransactionInput.new( - csl.TransactionHash.from_hex(scriptSourceInfo.txHash), - scriptSourceInfo.txIndex, - ); - const scriptSource = csl.PlutusScriptSource.new_ref_input_with_lang_ver( - scriptHash, - scriptRefInput, - LANGUAGE_VERSIONS[scriptSourceInfo.version as 'V1' | 'V2'], - ); - return scriptSource; - }; - // Below protected functions for completing tx building protected removeDuplicateInputs = () => { @@ -263,402 +62,4 @@ export class CSLSerializer implements IMeshSerializer { } } }; - - private addAllInputs = (inputs: TxIn[]) => { - for (let i = 0; i < inputs.length; i += 1) { - const currentTxIn = inputs[i]; // TODO: add type - switch (currentTxIn.type) { - case 'PubKey': - this.addTxIn(currentTxIn as RequiredWith); - break; - case 'Script': - this.addScriptTxIn( - currentTxIn as RequiredWith, - ); - break; - } - } - }; - - private addTxIn = (currentTxIn: RequiredWith) => { - this.txBuilder.add_input( - csl.Address.from_bech32(currentTxIn.txIn.address), - csl.TransactionInput.new( - csl.TransactionHash.from_hex(currentTxIn.txIn.txHash), - currentTxIn.txIn.txIndex, - ), - toValue(currentTxIn.txIn.amount), - ); - }; - - private addScriptTxIn = ({ - scriptTxIn, - txIn, - }: RequiredWith) => { - let cslDatum: csl.DatumSource; - const { datumSource, scriptSource, redeemer } = scriptTxIn; - if (datumSource.type === 'Provided') { - cslDatum = csl.DatumSource.new(this.castDataToPlutusData(datumSource.data)); - } else { - const refTxIn = csl.TransactionInput.new( - csl.TransactionHash.from_hex(datumSource.txHash), - datumSource.txIndex, - ); - cslDatum = csl.DatumSource.new_ref_input(refTxIn); - } - let cslScript: csl.PlutusScriptSource; - if (scriptSource.type === 'Inline') { - cslScript = this.makePlutusScriptSource( - scriptSource.txInInfo as Required, - ); - } else { - cslScript = csl.PlutusScriptSource.new( - csl.PlutusScript.from_hex_with_version( - scriptSource.script.code, - LANGUAGE_VERSIONS[scriptSource.script.version as 'V1' | 'V2'], - ), - ); - } - const cslRedeemer = csl.Redeemer.new( - csl.RedeemerTag.new_spend(), - csl.BigNum.from_str('0'), - this.castDataToPlutusData(redeemer.data), - csl.ExUnits.new( - csl.BigNum.from_str(String(redeemer.exUnits.mem)), - csl.BigNum.from_str(String(redeemer.exUnits.steps)), - ), - ); - this.txBuilder.add_plutus_script_input( - csl.PlutusWitness.new_with_ref(cslScript, cslDatum, cslRedeemer), - csl.TransactionInput.new(csl.TransactionHash.from_hex(txIn.txHash), txIn.txIndex), - toValue(txIn.amount), - ); - }; - - private addAllOutputs = (outputs: Output[]) => { - for (let i = 0; i < outputs.length; i += 1) { - const currentOutput = outputs[i]; - this.addOutput(currentOutput); - } - }; - - private addOutput = ({ amount, address, datum, referenceScript }: Output) => { - const txValue = toValue(amount); - const multiAsset = txValue.multiasset(); - if (txValue.is_zero() && multiAsset === undefined) throw Error('Invalid output amount'); - - let outputBuilder = csl.TransactionOutputBuilder.new().with_address(toAddress(address)); - if (datum && datum.type === 'Hash') { - outputBuilder = outputBuilder.with_data_hash( - csl.hash_plutus_data(this.castDataToPlutusData(datum.data)), - ); - } - if (datum && datum.type === 'Inline') { - outputBuilder = outputBuilder.with_plutus_data(this.castDataToPlutusData(datum.data)); - } - if (referenceScript) { - outputBuilder = outputBuilder.with_script_ref( - csl.ScriptRef.new_plutus_script( - csl.PlutusScript.from_hex_with_version( - referenceScript.code, - LANGUAGE_VERSIONS[referenceScript.version as 'V1' | 'V2'], - ), - ), - ); - } - const amountBuilder = outputBuilder.next(); - - if (multiAsset) { - const output = txValue.coin().is_zero() - ? amountBuilder - .with_asset_and_min_required_coin_by_utxo_cost( - multiAsset, - buildDataCost(this.protocolParams.coinsPerUTxOSize), - ) - .build() - : amountBuilder.with_coin_and_asset(txValue.coin(), multiAsset).build(); - this.txBuilder.add_output(output); - } else { - const output = amountBuilder.with_coin(txValue.coin()).build(); - this.txBuilder.add_output(output); - } - }; - - private addAllCollaterals = (collaterals: PubKeyTxIn[]) => { - const collateralBuilder = csl.TxInputsBuilder.new(); - for (let i = 0; i < collaterals.length; i += 1) { - const currentCollateral = collaterals[i]; - this.addCollateral( - collateralBuilder, - currentCollateral as RequiredWith, - ); - } - this.txBuilder.set_collateral(collateralBuilder); - }; - - private addCollateral = ( - collateralBuilder: csl.TxInputsBuilder, - currentCollateral: RequiredWith, - ) => { - collateralBuilder.add_input( - csl.Address.from_bech32(currentCollateral.txIn.address), - csl.TransactionInput.new( - csl.TransactionHash.from_hex(currentCollateral.txIn.txHash), - currentCollateral.txIn.txIndex, - ), - toValue(currentCollateral.txIn.amount), - ); - }; - - private addCollateralReturn = (returnAddress: string) => { - const currentFee = this.txBuilder.get_fee_if_set()?.to_js_value(); - if (currentFee) { - const collateralAmount = Math.ceil( - (this.protocolParams.collateralPercent * Number(currentFee)) / 100, - ); - this.txBuilder.set_total_collateral_and_return( - csl.BigNum.from_str(String(collateralAmount)), - csl.Address.from_bech32(returnAddress), - ); - } - }; - - private addAllReferenceInputs = (refInputs: RefTxIn[]) => { - refInputs.forEach((refInput) => { - this.addReferenceInput(refInput); - }); - }; - - private addReferenceInput = ({ txHash, txIndex }: RefTxIn) => { - const refInput = csl.TransactionInput.new(csl.TransactionHash.from_hex(txHash), txIndex); - this.txBuilder.add_reference_input(refInput); - }; - - protected addAllMints = (mints: MintItem[]) => { - const mintBuilder = csl.MintBuilder.new(); - let plutusMintCount = 0; - for (let i = 0; i < mints.length; i += 1) { - const mintItem = mints[i] as Required; - if (!mintItem.scriptSource) throw Error('Mint script is expected to be provided'); - if (mintItem.type === 'Plutus') { - if (!mintItem.redeemer) throw Error('Missing mint redeemer information'); - this.addPlutusMint(mintBuilder, mintItem, plutusMintCount); // TODO: Update after csl update - plutusMintCount += 1; // TODO: Remove after csl update - } else if (mintItem.type === 'Native') { - this.addNativeMint(mintBuilder, mintItem); - } - } - this.txBuilder.set_mint_builder(mintBuilder); - }; - - private addPlutusMint = ( - mintBuilder: csl.MintBuilder, - { redeemer, policyId, scriptSource, assetName, amount }: Required, - redeemerIndex: number, - ) => { - const newRedeemer: csl.Redeemer = csl.Redeemer.new( - csl.RedeemerTag.new_mint(), - csl.BigNum.from_str(String(redeemerIndex)), - this.castDataToPlutusData(redeemer.data), - csl.ExUnits.new( - csl.BigNum.from_str(String(redeemer.exUnits.mem)), - csl.BigNum.from_str(String(redeemer.exUnits.steps)), - ), - ); - const script = - scriptSource.type === 'Reference Script' - ? csl.PlutusScriptSource.new_ref_input_with_lang_ver( - csl.ScriptHash.from_hex(policyId), - csl.TransactionInput.new( - csl.TransactionHash.from_hex(scriptSource.txHash), - scriptSource.txIndex, - ), - LANGUAGE_VERSIONS[scriptSource.version as 'V1' | 'V2'], - ) - : csl.PlutusScriptSource.new( - csl.PlutusScript.from_hex_with_version( - scriptSource.script.code, - LANGUAGE_VERSIONS[scriptSource.script.version as 'V1' | 'V2'], - ), - ); - - mintBuilder.add_asset( - csl.MintWitness.new_plutus_script(script, newRedeemer), - csl.AssetName.new(Buffer.from(assetName, 'hex')), - csl.Int.from_str(amount), - ); - }; - - private addNativeMint = ( - mintBuilder: csl.MintBuilder, - { scriptSource, assetName, amount }: Required, - ) => { - if (scriptSource.type === 'Reference Script') - throw Error('Native mint cannot have reference script'); - mintBuilder.add_asset( - csl.MintWitness.new_native_script(csl.NativeScript.from_hex(scriptSource.script.code)), - csl.AssetName.new(Buffer.from(assetName, 'hex')), - csl.Int.from_str(amount), - ); - }; - - private decimalToFraction(decimal: number): [numerator: number, denominator: number] { - const powerOf10 = 10 ** decimal.toString().split('.')[1].length; - const numerator = decimal * powerOf10; - const denominator = powerOf10; - - return [numerator, denominator]; - } - - private toPoolParams = (poolParams: PoolParams): csl.PoolParams => { - const marginFraction = this.decimalToFraction(poolParams.margin); - const relays = csl.Relays.new(); - poolParams.relays.forEach((relay) => { - relays.add(toRelay(relay) as Relay); - }); - const rewardAddress = csl.RewardAddress.from_address( - csl.Address.from_bech32(poolParams.rewardAddress), - ); - if (rewardAddress === undefined) { - throw new Error('Reward address is invalid'); - } - const poolOwners = csl.Ed25519KeyHashes.new(); - poolParams.owners.forEach((owner) => { - poolOwners.add(csl.Ed25519KeyHash.from_hex(owner)); - }); - return csl.PoolParams.new( - csl.Ed25519KeyHash.from_hex(poolParams.operator), - csl.VRFKeyHash.from_hex(poolParams.VRFKeyHash), - csl.BigNum.from_str(poolParams.pledge), - csl.BigNum.from_str(poolParams.cost), - csl.UnitInterval.new( - csl.BigNum.from_str(marginFraction[0].toString()), - csl.BigNum.from_str(marginFraction[1].toString()), - ), - rewardAddress, - poolOwners, - relays, - poolParams.metadata - ? csl.PoolMetadata.from_json(JSONbig.stringify(poolParams.metadata)) - : undefined, - ); - }; - - private addCertificate = (certificates: csl.Certificates, cert: Certificate) => { - switch (cert.type) { - case 'RegisterPool': - certificates.add( - csl.Certificate.new_pool_registration( - csl.PoolRegistration.new(this.toPoolParams(cert.poolParams)), - ), - ); - break; - case 'RegisterStake': - certificates.add( - csl.Certificate.new_stake_registration( - csl.StakeRegistration.new( - csl.StakeCredential.from_keyhash( - csl.Ed25519KeyHash.from_hex(cert.stakeKeyHash), - ), - ), - ), - ); - break; - case 'DelegateStake': - certificates.add( - csl.Certificate.new_stake_delegation( - csl.StakeDelegation.new( - csl.StakeCredential.from_keyhash( - csl.Ed25519KeyHash.from_hex(cert.stakeKeyHash), - ), - cert.poolId.startsWith('pool') - ? csl.Ed25519KeyHash.from_bech32(cert.poolId) - : csl.Ed25519KeyHash.from_hex(cert.poolId), - ), - ), - ); - break; - case 'DeregisterStake': - certificates.add( - csl.Certificate.new_stake_deregistration( - csl.StakeDeregistration.new( - csl.StakeCredential.from_keyhash( - csl.Ed25519KeyHash.from_hex(cert.stakeKeyHash), - ), - ), - ), - ); - break; - case 'RetirePool': - certificates.add( - csl.Certificate.new_pool_retirement( - csl.PoolRetirement.new( - cert.poolId.startsWith('pool') - ? csl.Ed25519KeyHash.from_bech32(cert.poolId) - : csl.Ed25519KeyHash.from_hex(cert.poolId), - cert.epoch, - ), - ), - ); - } - }; - - protected addAllCertificates = (allCertificates: Certificate[]) => { - const certificates = csl.Certificates.new(); - allCertificates.forEach((cert) => { - this.addCertificate(certificates, cert); - }); - this.txBuilder.set_certs(certificates); - }; - - protected addCostModels = () => { - this.txBuilder.calc_script_data_hash(csl.TxBuilderConstants.plutus_vasil_cost_models()); - }; - - private addChange = (changeAddress: string) => { - this.txBuilder.add_change_if_needed(csl.Address.from_bech32(changeAddress)); - }; - - private addValidityRange = ({ invalidBefore, invalidHereafter }: ValidityRange) => { - if (invalidBefore) { - this.txBuilder.set_validity_start_interval_bignum( - csl.BigNum.from_str(invalidBefore.toString()), - ); - } - if (invalidHereafter) { - this.txBuilder.set_ttl_bignum(csl.BigNum.from_str(invalidHereafter.toString())); - } - }; - - private addAllRequiredSignatures = (requiredSignatures: string[]) => { - requiredSignatures.forEach((pubKeyHash) => { - this.txBuilder.add_required_signer(csl.Ed25519KeyHash.from_hex(pubKeyHash)); - }); - }; - - private addAllMetadata = (allMetadata: Metadata[]) => { - allMetadata.forEach(({ tag, metadata }) => { - this.txBuilder.add_json_metadatum( - csl.BigNum.from_str(tag), - JSONbig.stringify(metadata), - ); - }); - }; - - protected castRawDataToJsonString = (rawData: object | string) => { - if (typeof rawData === 'object') { - return JSONbig.stringify(rawData); - } - return rawData as string; - }; - - protected castDataToPlutusData = ({ type, content }: BuilderData) => { - if (type === 'Mesh') { - return toPlutusData(content); - } - if (type === 'CBOR') { - return csl.PlutusData.from_hex(content as string); - } - return csl.PlutusData.from_json(content as string, csl.PlutusDatumSchema.DetailedSchema); - }; } diff --git a/packages/csl/src/deser/builder.ts b/packages/csl/src/deser/builder.ts deleted file mode 100644 index c34af44..0000000 --- a/packages/csl/src/deser/builder.ts +++ /dev/null @@ -1,240 +0,0 @@ -/* eslint-disable no-use-before-define */ -import type { Action, Data, PlutusScript, Recipient, UTxO } from '@meshsdk/common'; -import { DEFAULT_PROTOCOL_PARAMETERS, DEFAULT_REDEEMER_BUDGET } from '@meshsdk/common'; -import { LANGUAGE_VERSIONS } from './constants'; - -import { csl } from './csl'; -import type { - BaseAddress, - Bip32PrivateKey, - DataCost, - DatumSource, - Ed25519KeyHash, - EnterpriseAddress, - MintWitness, - PlutusScriptSource, - RewardAddress, - TransactionBuilder, - TransactionOutputBuilder, - TransactionUnspentOutput, - TxInputsBuilder, -} from './types'; -import { - fromScriptRef, - fromUTF8, - toAddress, - toBytes, - toPlutusData, - toRedeemer, - toScriptRef, - toTxUnspentOutput, - toUnitInterval, -} from './converter'; -import { deserializeNativeScript, deserializePlutusScript } from './deserializer'; - -export const buildBaseAddress = ( - networkId: number, - paymentKeyHash: Ed25519KeyHash, - stakeKeyHash: Ed25519KeyHash, -): BaseAddress => - csl.BaseAddress.new( - networkId, - csl.StakeCredential.from_keyhash(paymentKeyHash), - csl.StakeCredential.from_keyhash(stakeKeyHash), - ); - -export const buildBip32PrivateKey = (entropy: string, password = ''): Bip32PrivateKey => - csl.Bip32PrivateKey.from_bip39_entropy(toBytes(entropy), toBytes(fromUTF8(password))); - -export const buildDataCost = (coinsPerByte: string): DataCost => - csl.DataCost.new_coins_per_byte(csl.BigNum.from_str(coinsPerByte)); - -export const buildDatumSource = (datum: Data | UTxO): DatumSource => { - if (typeof datum !== 'object' || !('input' in datum)) { - return csl.DatumSource.new(toPlutusData(datum)); - } - - const utxo = toTxUnspentOutput(datum); - if (utxo.output().has_plutus_data()) { - return csl.DatumSource.new_ref_input(utxo.input()); - } - - throw new Error(`No inline datum found in UTxO: ${utxo.input().transaction_id().to_hex()}`); -}; - -export const buildEnterpriseAddress = ( - networkId: number, - paymentKeyHash: Ed25519KeyHash, -): EnterpriseAddress => - csl.EnterpriseAddress.new(networkId, csl.StakeCredential.from_keyhash(paymentKeyHash)); - -export const buildGeneralTxMetadata = (metadata: Record) => { - const generalTxMetadata = csl.GeneralTransactionMetadata.new(); - - Object.entries(metadata).forEach(([MetadataLabel, Metadata]) => { - generalTxMetadata.insert( - csl.BigNum.from_str(MetadataLabel), - csl.encode_json_str_to_metadatum( - JSON.stringify(Metadata), - csl.MetadataJsonSchema.NoConversions, - ), - ); - }); - - return generalTxMetadata; -}; - -export const buildMintWitness = ( - script: string | PlutusScript | UTxO, - redeemer?: Partial, -): MintWitness => { - if (typeof script === 'string') { - return csl.MintWitness.new_native_script(deserializeNativeScript(script)); - } - - if (redeemer === undefined) - throw new Error('Minting with plutus requires a redeemer to be defined'); - - if (redeemer.tag !== 'MINT') - throw new Error("Minting redeemer's tag must be defined as 'MINT'"); - - return csl.MintWitness.new_plutus_script( - buildPlutusScriptSource(script), - toRedeemer({ - tag: 'MINT', - index: 0, - budget: DEFAULT_REDEEMER_BUDGET, - data: { - alternative: 0, - fields: [], - }, - ...redeemer, - }), - ); -}; - -export const buildRewardAddress = ( - networkId: number, - stakeKeyHash: Ed25519KeyHash, -): RewardAddress => - csl.RewardAddress.new(networkId, csl.StakeCredential.from_keyhash(stakeKeyHash)); - -export const buildPlutusScriptSource = (script: PlutusScript | UTxO): PlutusScriptSource => { - if ('code' in script) { - return csl.PlutusScriptSource.new(deserializePlutusScript(script.code, script.version)); - } - - const utxo = toTxUnspentOutput(script); - if (utxo.output().has_script_ref()) { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const scriptRef = utxo.output().script_ref()!; - if (scriptRef.is_plutus_script()) { - const plutusScript = fromScriptRef(scriptRef) as PlutusScript; - const scriptHash = deserializePlutusScript( - plutusScript.code, - plutusScript.version, - ).hash(); - - return csl.PlutusScriptSource.new_ref_input_with_lang_ver( - scriptHash, - utxo.input(), - LANGUAGE_VERSIONS[plutusScript.version as 'V1' | 'V2'], - ); - } - } - - throw new Error( - `No plutus script reference found in UTxO: ${utxo.input().transaction_id().to_hex()}`, - ); -}; - -export const buildScriptPubkey = (keyHash: Ed25519KeyHash) => { - const scriptPubkey = csl.ScriptPubkey.new(keyHash); - return csl.NativeScript.new_script_pubkey(scriptPubkey); -}; - -export const buildTimelockExpiry = (slot: string) => { - const expiry = csl.BigNum.from_str(slot); - const timelockExpiry = csl.TimelockExpiry.new_timelockexpiry(expiry); - return csl.NativeScript.new_timelock_expiry(timelockExpiry); -}; - -export const buildTimelockStart = (slot: string) => { - const start = csl.BigNum.from_str(slot); - const timelockStart = csl.TimelockStart.new_timelockstart(start); - return csl.NativeScript.new_timelock_start(timelockStart); -}; - -export const buildTxBuilder = (parameters = DEFAULT_PROTOCOL_PARAMETERS): TransactionBuilder => { - const txBuilderConfig = csl.TransactionBuilderConfigBuilder.new() - .coins_per_utxo_byte(csl.BigNum.from_str(parameters.coinsPerUTxOSize)) - .ex_unit_prices( - csl.ExUnitPrices.new( - toUnitInterval(parameters.priceMem.toString()), - toUnitInterval(parameters.priceStep.toString()), - ), - ) - .fee_algo( - csl.LinearFee.new( - csl.BigNum.from_str(parameters.minFeeA.toString()), - csl.BigNum.from_str(parameters.minFeeB.toString()), - ), - ) - .key_deposit(csl.BigNum.from_str(parameters.keyDeposit)) - .max_tx_size(parameters.maxTxSize) - .max_value_size(parseInt(parameters.maxValSize, 10)) - .pool_deposit(csl.BigNum.from_str(parameters.poolDeposit)) - .build(); - - return csl.TransactionBuilder.new(txBuilderConfig); -}; - -export const buildTxInputsBuilder = (utxos: unknown[]): TxInputsBuilder => { - const txInputsBuilder = csl.TxInputsBuilder.new(); - - utxos - .map((utxo) => - utxo instanceof csl.TransactionUnspentOutput - ? (utxo as TransactionUnspentOutput) - : toTxUnspentOutput(utxo as UTxO), - ) - .forEach((utxo) => { - txInputsBuilder.add_input( - utxo.output().address(), - utxo.input(), - utxo.output().amount(), - ); - }); - - return txInputsBuilder; -}; - -export const buildTxOutputBuilder = (recipient: Recipient): TransactionOutputBuilder => { - if (typeof recipient === 'string') { - return csl.TransactionOutputBuilder.new().with_address(toAddress(recipient)); - } - - let txOutputBuilder = csl.TransactionOutputBuilder.new().with_address( - toAddress(recipient.address), - ); - - if (recipient.datum) { - const { value, inline } = recipient.datum; - - const plutusData = toPlutusData(value); - - txOutputBuilder = txOutputBuilder.with_data_hash(csl.hash_plutus_data(plutusData)); - - if (inline) { - txOutputBuilder = txOutputBuilder.with_plutus_data(plutusData); - } - } - - if (recipient.script) { - const reference = toScriptRef(recipient.script); - - txOutputBuilder = txOutputBuilder.with_script_ref(reference); - } - - return txOutputBuilder; -}; diff --git a/packages/csl/src/deser/converter.ts b/packages/csl/src/deser/converter.ts index aaddd0a..b7d3d80 100644 --- a/packages/csl/src/deser/converter.ts +++ b/packages/csl/src/deser/converter.ts @@ -1,39 +1,8 @@ -/* eslint-disable radix */ -/* eslint-disable no-use-before-define */ /* eslint-disable consistent-return */ /* eslint-disable default-case */ -/* eslint-disable import/no-cycle */ -import type { - Action, - Asset, - Data, - NativeScript, - PlutusScript, - PoolParams, - Relay, - UTxO, -} from '@meshsdk/common'; -// import { POLICY_ID_LENGTH } from '@meshsdk/core'; +import type { BuilderData, Data } from '@meshsdk/common'; +import JSONbig from 'json-bigint'; import { csl } from './csl'; -import { - Value, - PlutusData, - PlutusList, - PlutusMap, - RedeemerTag, - ScriptRef, - TransactionUnspentOutput, -} from './types'; -import { LANGUAGE_VERSIONS, REDEEMER_TAGS, POLICY_ID_LENGTH } from './constants'; -import { - deserializeDataHash, - deserializeEd25519KeyHash, - deserializePlutusData, - deserializePlutusScript, - deserializeScriptHash, - deserializeScriptRef, - deserializeTxHash, -} from './deserializer'; /* -----------------[ Address ]----------------- */ @@ -63,163 +32,8 @@ export const fromLovelace = (lovelace: number) => lovelace / 1_000_000; export const toLovelace = (ada: number) => ada * 1_000_000; -/* -----------------[ NativeScript ]----------------- */ - -export const fromNativeScript = (script: csl.NativeScript) => { - const fromNativeScripts = (scripts: csl.NativeScripts) => { - const nativeScripts = new Array(); - - for (let index = 0; index < scripts.len(); index += 1) { - nativeScripts.push(fromNativeScript(scripts.get(index))); - } - - return nativeScripts; - }; - - switch (script.kind()) { - case csl.NativeScriptKind.ScriptAll: { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const scriptAll = script.as_script_all()!; - return { - type: 'all', - scripts: fromNativeScripts(scriptAll.native_scripts()), - }; - } - case csl.NativeScriptKind.ScriptAny: { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const scriptAny = script.as_script_any()!; - return { - type: 'any', - scripts: fromNativeScripts(scriptAny.native_scripts()), - }; - } - case csl.NativeScriptKind.ScriptNOfK: { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const scriptNOfK = script.as_script_n_of_k()!; - return { - type: 'atLeast', - required: scriptNOfK.n(), - scripts: fromNativeScripts(scriptNOfK.native_scripts()), - }; - } - case csl.NativeScriptKind.TimelockStart: { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const timelockStart = script.as_timelock_start()!; - return { - type: 'after', - slot: timelockStart.slot_bignum().to_str(), - }; - } - case csl.NativeScriptKind.TimelockExpiry: { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const timelockExpiry = script.as_timelock_expiry()!; - return { - type: 'before', - slot: timelockExpiry.slot_bignum().to_str(), - }; - } - case csl.NativeScriptKind.ScriptPubkey: { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const scriptPubkey = script.as_script_pubkey()!; - return { - type: 'sig', - keyHash: scriptPubkey.addr_keyhash().to_hex(), - }; - } - default: - throw new Error(`Script Kind: ${script.kind()}, is not supported`); - } -}; - -export const toNativeScript = (script: NativeScript): csl.NativeScript => { - const toNativeScripts = (scripts: NativeScript[]) => { - const nativeScripts = csl.NativeScripts.new(); - - scripts.forEach((scriptItem) => { - nativeScripts.add(toNativeScript(scriptItem)); - }); - - return nativeScripts; - }; - - switch (script.type) { - case 'all': - return csl.NativeScript.new_script_all( - csl.ScriptAll.new(toNativeScripts(script.scripts)), - ); - case 'any': - return csl.NativeScript.new_script_any( - csl.ScriptAny.new(toNativeScripts(script.scripts)), - ); - case 'atLeast': - return csl.NativeScript.new_script_n_of_k( - csl.ScriptNOfK.new(script.required, toNativeScripts(script.scripts)), - ); - case 'after': - return csl.NativeScript.new_timelock_start( - csl.TimelockStart.new_timelockstart(csl.BigNum.from_str(script.slot)), - ); - case 'before': - return csl.NativeScript.new_timelock_expiry( - csl.TimelockExpiry.new_timelockexpiry(csl.BigNum.from_str(script.slot)), - ); - case 'sig': - return csl.NativeScript.new_script_pubkey( - csl.ScriptPubkey.new(deserializeEd25519KeyHash(script.keyHash)), - ); - } -}; - /* -----------------[ PlutusData ]----------------- */ -export const fromPlutusData = (plutusData: PlutusData) => { - const fromPlutusList = (plutusList: PlutusList) => { - const dataList: Data[] = []; - for (let index = 0; index < plutusList.len(); index += 1) { - dataList.push(fromPlutusData(plutusList.get(index))); - } - - return dataList; - }; - - const fromPlutusMap = (plutusMap: PlutusMap) => { - const dataMap = new Map(); - for (let index = 0; index < plutusMap.len(); index += 1) { - const key = plutusMap.keys().get(index); - const value = - plutusMap.get(key) ?? - csl.PlutusData.from_hex(fromUTF8('NO_ITEM_FOUND_INSIDE_GOLD_ROOM')); - - dataMap.set(fromPlutusData(key), fromPlutusData(value)); - } - - return dataMap; - }; - - switch (plutusData.kind()) { - case csl.PlutusDataKind.Bytes: - return fromBytes(plutusData.as_bytes() ?? new Uint8Array()); - case csl.PlutusDataKind.Integer: - return parseInt(plutusData.as_integer()?.to_str() ?? '0', 10); - case csl.PlutusDataKind.List: - return fromPlutusList(plutusData.as_list() ?? csl.PlutusList.new()); - case csl.PlutusDataKind.Map: - return fromPlutusMap(plutusData.as_map() ?? csl.PlutusMap.new()); - case csl.PlutusDataKind.ConstrPlutusData: - return { - alternative: parseInt( - plutusData.as_constr_plutus_data()?.alternative().to_str() ?? '0', - 10, - ), - fields: fromPlutusList( - plutusData.as_constr_plutus_data()?.data() ?? csl.PlutusList.new(), - ), - }; - default: - throw new Error(`PlutusData Kind: ${plutusData.kind()}, is not supported`); - } -}; - export const toPlutusData = (data: Data): csl.PlutusData => { const toPlutusList = (dataArray: Data[]) => { const plutusList = csl.PlutusList.new(); @@ -258,225 +72,19 @@ export const toPlutusData = (data: Data): csl.PlutusData => { } }; -/* -----------------[ PoolParams ]----------------- */ - -export const toPoolParams = (params: PoolParams) => { - const relays = csl.Relays.new(); - params.relays.forEach((relay) => { - relays.add(toRelay(relay)); - }); - - throw new Error('toPoolParams not implemented.'); -}; - -/* -----------------[ Redeemer ]----------------- */ - -export const toRedeemer = (action: Action) => { - const lookupRedeemerTag = (key: keyof typeof REDEEMER_TAGS): RedeemerTag => REDEEMER_TAGS[key]; - - return csl.Redeemer.new( - lookupRedeemerTag(action.tag as keyof typeof REDEEMER_TAGS), - csl.BigNum.from_str(action.index.toString()), - toPlutusData(action.data), - csl.ExUnits.new( - csl.BigNum.from_str(action.budget.mem.toString()), - csl.BigNum.from_str(action.budget.steps.toString()), - ), - ); -}; - -/* -----------------[ Relay ]----------------- */ - -export const toRelay = (relay: Relay): csl.Relay => { - switch (relay.type) { - case 'SingleHostAddr': { - const IPV4 = relay.IPV4 - ? csl.Ipv4.new(new Uint8Array(relay.IPV4.split('.').map((b) => parseInt(b)))) - : undefined; - - const IPV6 = relay.IPV6 - ? csl.Ipv6.new(toBytes(relay.IPV6.replaceAll(':', ''))) - : undefined; - - return csl.Relay.new_single_host_addr(csl.SingleHostAddr.new(relay.port, IPV4, IPV6)); - } - case 'SingleHostName': - return csl.Relay.new_single_host_name( - csl.SingleHostName.new(relay.port, csl.DNSRecordAorAAAA.new(relay.domainName)), - ); - case 'MultiHostName': - return csl.Relay.new_multi_host_name( - csl.MultiHostName.new(csl.DNSRecordSRV.new(relay.domainName)), - ); +export const castRawDataToJsonString = (rawData: object | string) => { + if (typeof rawData === 'object') { + return JSONbig.stringify(rawData); } + return rawData as string; }; -/* -----------------[ ScriptRef ]----------------- */ - -export const fromScriptRef = (scriptRef: ScriptRef) => { - if (scriptRef.is_plutus_script()) { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const plutusScript = scriptRef.plutus_script()!; - - return { - code: plutusScript.to_hex(), - version: Object.keys(LANGUAGE_VERSIONS).find( - (key) => - LANGUAGE_VERSIONS[key as keyof typeof LANGUAGE_VERSIONS].to_hex() === - plutusScript.language_version().to_hex(), - ), - }; +export const castDataToPlutusData = ({ type, content }: BuilderData): csl.PlutusData => { + if (type === 'Mesh') { + return toPlutusData(content); } - - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const nativeScript = scriptRef.native_script()!; - - return fromNativeScript(nativeScript); -}; - -export const toScriptRef = (script: PlutusScript | NativeScript) => { - if ('code' in script) { - const plutusScript = deserializePlutusScript(script.code, script.version); - - return csl.ScriptRef.new_plutus_script(plutusScript); - } - - return csl.ScriptRef.new_native_script(toNativeScript(script)); -}; - -/* -----------------[ TransactionUnspentOutput ]----------------- */ - -export const fromTxUnspentOutput = (txUnspentOutput: TransactionUnspentOutput) => { - const dataHash = txUnspentOutput.output().has_data_hash() - ? txUnspentOutput.output().data_hash()?.to_hex() - : undefined; - - const plutusData = txUnspentOutput.output().has_plutus_data() - ? txUnspentOutput.output().plutus_data()?.to_hex() - : undefined; - - const scriptRef = txUnspentOutput.output().has_script_ref() - ? txUnspentOutput.output().script_ref()?.to_hex() - : undefined; - - return { - input: { - outputIndex: txUnspentOutput.input().index(), - txHash: txUnspentOutput.input().transaction_id().to_hex(), - }, - output: { - address: txUnspentOutput.output().address().to_bech32(), - amount: fromValue(txUnspentOutput.output().amount()), - dataHash, - plutusData, - scriptRef, - }, - }; -}; - -export const toTxUnspentOutput = (utxo: UTxO) => { - const txInput = csl.TransactionInput.new( - deserializeTxHash(utxo.input.txHash), - utxo.input.outputIndex, - ); - - const txOutput = csl.TransactionOutput.new( - toAddress(utxo.output.address), - toValue(utxo.output.amount), - ); - - if (utxo.output.dataHash !== undefined) { - txOutput.set_data_hash(deserializeDataHash(utxo.output.dataHash)); - } - - if (utxo.output.plutusData !== undefined) { - txOutput.set_plutus_data(deserializePlutusData(utxo.output.plutusData)); - } - - if (utxo.output.scriptRef !== undefined) { - txOutput.set_script_ref(deserializeScriptRef(utxo.output.scriptRef)); - } - - return csl.TransactionUnspentOutput.new(txInput, txOutput); -}; - -/* -----------------[ UnitInterval ]----------------- */ - -export const toUnitInterval = (float: string) => { - const decimal = float.split('.')[1] ?? '0'; - - const numerator = `${parseInt(decimal, 10)}`; - const denominator = `1${'0'.repeat(decimal.length)}`; - - return csl.UnitInterval.new(csl.BigNum.from_str(numerator), csl.BigNum.from_str(denominator)); -}; - -/* -----------------[ UTF-8 ]----------------- */ - -export const fromUTF8 = (utf8: string) => { - if (utf8.length % 2 === 0 && /^[0-9A-F]*$/i.test(utf8)) return utf8; - - return fromBytes(Buffer.from(utf8, 'utf-8')); -}; - -export const toUTF8 = (hex: string) => Buffer.from(hex, 'hex').toString('utf-8'); - -/* -----------------[ Value ]----------------- */ - -export const fromValue = (value: Value) => { - const assets: Asset[] = [{ unit: 'lovelace', quantity: value.coin().to_str() }]; - - const multiAsset = value.multiasset(); - if (multiAsset !== undefined) { - const policies = multiAsset.keys(); - for (let i = 0; i < policies.len(); i += 1) { - const policyId = policies.get(i); - const policyAssets = multiAsset.get(policyId); - if (policyAssets !== undefined) { - const policyAssetNames = policyAssets.keys(); - for (let j = 0; j < policyAssetNames.len(); j += 1) { - const assetName = policyAssetNames.get(j); - const quantity = policyAssets.get(assetName) ?? csl.BigNum.from_str('0'); - const assetId = policyId.to_hex() + fromBytes(assetName.name()); - assets.push({ unit: assetId, quantity: quantity.to_str() }); - } - } - } - } - - return assets; -}; - -export const toValue = (assets: Asset[]) => { - const lovelace = assets.find((asset) => asset.unit === 'lovelace'); - const policies = Array.from( - new Set( - assets - .filter((asset) => asset.unit !== 'lovelace') - .map((asset) => asset.unit.slice(0, POLICY_ID_LENGTH)), - ), - ); - - const multiAsset = csl.MultiAsset.new(); - policies.forEach((policyId) => { - const policyAssets = csl.Assets.new(); - assets - .filter((asset) => asset.unit.slice(0, POLICY_ID_LENGTH) === policyId) - .forEach((asset) => { - policyAssets.insert( - csl.AssetName.new(toBytes(asset.unit.slice(POLICY_ID_LENGTH))), - csl.BigNum.from_str(asset.quantity), - ); - }); - - multiAsset.insert(deserializeScriptHash(policyId), policyAssets); - }); - - const value = csl.Value.new(csl.BigNum.from_str(lovelace ? lovelace.quantity : '0')); - - if (assets.length > 1 || !lovelace) { - value.set_multiasset(multiAsset); + if (type === 'CBOR') { + return csl.PlutusData.from_hex(content as string); } - - return value; + return csl.PlutusData.from_json(content as string, csl.PlutusDatumSchema.DetailedSchema); }; diff --git a/packages/csl/src/deser/index.ts b/packages/csl/src/deser/index.ts index 3f0c1c3..3910799 100644 --- a/packages/csl/src/deser/index.ts +++ b/packages/csl/src/deser/index.ts @@ -1,6 +1,4 @@ -export * from './types'; export * from './deserializer'; export * from './converter'; export * from './csl'; export * from './constants'; -export * from './builder'; diff --git a/packages/csl/src/deser/types.ts b/packages/csl/src/deser/types.ts deleted file mode 100644 index b6fda3a..0000000 --- a/packages/csl/src/deser/types.ts +++ /dev/null @@ -1,153 +0,0 @@ -import { csl } from './csl'; - -export type Address = InstanceType; -export type AssetName = InstanceType; -export type AssetNames = InstanceType; -export type Assets = InstanceType; -export type AuxiliaryData = InstanceType; -export type AuxiliaryDataHash = InstanceType; -export type AuxiliaryDataSet = InstanceType; -export type BaseAddress = InstanceType; -export type BigInt = InstanceType; -export type BigNum = InstanceType; -export type Bip32PrivateKey = InstanceType; -export type Bip32PublicKey = InstanceType; -export type Block = InstanceType; -export type BlockHash = InstanceType; -export type BootstrapWitness = InstanceType; -export type BootstrapWitnesses = InstanceType; -export type ByronAddress = InstanceType; -export type Certificate = InstanceType; -export type Certificates = InstanceType; -export type ConstrPlutusData = InstanceType; -export type CostModel = InstanceType; -export type Costmdls = InstanceType; -export type DNSRecordAorAAAA = InstanceType; -export type DNSRecordSRV = InstanceType; -export type DataCost = InstanceType; -export type DataHash = InstanceType; -export type DatumSource = InstanceType; -export type Ed25519KeyHash = InstanceType; -export type Ed25519KeyHashes = InstanceType; -export type Ed25519Signature = InstanceType; -export type EnterpriseAddress = InstanceType; -export type ExUnitPrices = InstanceType; -export type ExUnits = InstanceType; -export type GeneralTransactionMetadata = InstanceType; -export type GenesisDelegateHash = InstanceType; -export type GenesisHash = InstanceType; -export type GenesisHashes = InstanceType; -export type GenesisKeyDelegation = InstanceType; -export type Header = InstanceType; -export type HeaderBody = InstanceType; -export type Int = InstanceType; -export type Ipv4 = InstanceType; -export type Ipv6 = InstanceType; -export type KESSignature = InstanceType; -export type KESVKey = InstanceType; -export type Language = InstanceType; -export type Languages = InstanceType; -export type LegacyDaedalusPrivateKey = InstanceType; -export type LinearFee = InstanceType; -export type MIRToStakeCredentials = InstanceType; -export type MetadataList = InstanceType; -export type MetadataMap = InstanceType; -export type Mint = InstanceType; -export type MintAssets = InstanceType; -export type MintBuilder = InstanceType; -export type MintWitness = InstanceType; -export type MintsAssets = InstanceType; -export type MoveInstantaneousReward = InstanceType; -export type MoveInstantaneousRewardsCert = InstanceType; -export type MultiAsset = InstanceType; -export type MultiHostName = InstanceType; -export type NativeScript = InstanceType; -export type NativeScripts = InstanceType; -export type NetworkId = InstanceType; -export type NetworkInfo = InstanceType; -export type Nonce = InstanceType; -export type OperationalCert = InstanceType; -export type PlutusData = InstanceType; -export type PlutusList = InstanceType; -export type PlutusMap = InstanceType; -export type PlutusScript = InstanceType; -export type PlutusScripts = InstanceType; -export type PlutusScriptSource = InstanceType; -export type PlutusWitness = InstanceType; -export type PlutusWitnesses = InstanceType; -export type Pointer = InstanceType; -export type PointerAddress = InstanceType; -export type PoolMetadata = InstanceType; -export type PoolMetadataHash = InstanceType; -export type PoolParams = InstanceType; -export type PoolRegistration = InstanceType; -export type PoolRetirement = InstanceType; -export type PrivateKey = InstanceType; -export type ProposedProtocolParameterUpdates = InstanceType< - typeof csl.ProposedProtocolParameterUpdates ->; -export type ProtocolParamUpdate = InstanceType; -export type ProtocolVersion = InstanceType; -export type PublicKey = InstanceType; -export type PublicKeys = InstanceType; -export type Redeemer = InstanceType; -export type RedeemerTag = InstanceType; -export type Redeemers = InstanceType; -export type Relay = InstanceType; -export type Relays = InstanceType; -export type RewardAddress = InstanceType; -export type RewardAddresses = InstanceType; -export type ScriptAll = InstanceType; -export type ScriptAny = InstanceType; -export type ScriptDataHash = InstanceType; -export type ScriptHash = InstanceType; -export type ScriptHashes = InstanceType; -export type ScriptNOfK = InstanceType; -export type ScriptPubkey = InstanceType; -export type ScriptRef = InstanceType; -export type SingleHostAddr = InstanceType; -export type SingleHostName = InstanceType; -export type StakeCredential = InstanceType; -export type StakeCredentials = InstanceType; -export type StakeDelegation = InstanceType; -export type StakeRegistration = InstanceType; -export type Strings = InstanceType; -export type TimelockExpiry = InstanceType; -export type TimelockStart = InstanceType; -export type Transaction = InstanceType; -export type TransactionBodies = InstanceType; -export type TransactionBody = InstanceType; -export type TransactionBuilder = InstanceType; -export type TransactionBuilderConfig = InstanceType; -export type TransactionBuilderConfigBuilder = InstanceType< - typeof csl.TransactionBuilderConfigBuilder ->; -export type TransactionHash = InstanceType; -export type TransactionInput = InstanceType; -export type TransactionInputs = InstanceType; -export type TransactionMetadatum = InstanceType; -export type TransactionMetadatumLabels = InstanceType; -export type TransactionOutput = InstanceType; -export type TransactionOutputAmountBuilder = InstanceType< - typeof csl.TransactionOutputAmountBuilder ->; -export type TransactionOutputBuilder = InstanceType; -export type TransactionOutputs = InstanceType; -export type TransactionUnspentOutput = InstanceType; -export type TransactionUnspentOutputs = InstanceType; -export type TransactionWitnessSet = InstanceType; -export type TransactionWitnessSets = InstanceType; -export type TxBuilderConstants = InstanceType; -export type TxInputsBuilder = InstanceType; -export type URL = InstanceType; -export type UnitInterval = InstanceType; -export type Update = InstanceType; -export type VRFCert = InstanceType; -export type VRFKeyHash = InstanceType; -export type VRFVKey = InstanceType; -export type Value = InstanceType; -export type Vkey = InstanceType; -export type Vkeys = InstanceType; -export type Vkeywitness = InstanceType; -export type Vkeywitnesses = InstanceType; -export type Withdrawals = InstanceType; diff --git a/packages/csl/src/utils/address.ts b/packages/csl/src/utils/address.ts index 7d201c5..fad918a 100644 --- a/packages/csl/src/utils/address.ts +++ b/packages/csl/src/utils/address.ts @@ -20,32 +20,10 @@ export const parsePlutusAddressObjToBech32 = ( plutusDataAddressObject: PubKeyAddress | ScriptAddress, networkId = 0, ) => { - const plutusDataPaymentKeyObject = plutusDataAddressObject.fields[0]; - const plutusDataStakeKeyObject = plutusDataAddressObject.fields[1]; - const cslPaymentKeyHash = plutusDataPaymentKeyObject.fields[0].bytes; - - // Take into account whether the hash is a PubKeyHash or ScriptHash - const cslPaymentCredential = - plutusDataPaymentKeyObject.constructor === 0 - ? csl.StakeCredential.from_keyhash(csl.Ed25519KeyHash.from_hex(cslPaymentKeyHash)) - : csl.StakeCredential.from_scripthash(csl.ScriptHash.from_hex(cslPaymentKeyHash)); - let bech32Addr = ''; - - // Parsing address according to whether it has a stake key - if (plutusDataStakeKeyObject.constructor === 0) { - const cslStakeKeyHash = csl.Ed25519KeyHash.from_hex( - plutusDataStakeKeyObject.fields[0].fields[0].fields[0].bytes, - ); - const cslBaseAddress = csl.BaseAddress.new( - networkId, - cslPaymentCredential, - csl.StakeCredential.from_keyhash(cslStakeKeyHash), - ); - bech32Addr = cslBaseAddress.to_address().to_bech32(); - } else { - const cslEnterpriseAddress = csl.EnterpriseAddress.new(networkId, cslPaymentCredential); - bech32Addr = cslEnterpriseAddress.to_address().to_bech32(); - } + const bech32Addr = csl.parse_plutus_address_obj_to_bech32( + JSON.stringify(plutusDataAddressObject), + networkId, + ); return bech32Addr; }; diff --git a/packages/csl/src/utils/aiken.ts b/packages/csl/src/utils/aiken.ts index dc22128..2771150 100644 --- a/packages/csl/src/utils/aiken.ts +++ b/packages/csl/src/utils/aiken.ts @@ -1,20 +1,47 @@ -import { csl } from '../deser'; +import { Data } from '@meshsdk/common'; +import { csl, toPlutusData } from '../deser'; -export const applyParamsToScript = (rawAikenScriptBlueprint: string, params: string[]): string => { - const cslParams = csl.JsVecString.new(); - params.forEach((param) => { - cslParams.add(param); - }); - return csl.apply_params_to_script(cslParams, rawAikenScriptBlueprint); -}; - -export const applyObjParamsToScript = ( - rawAikenScriptBlueprint: string, - params: T[], +/** + * Apply parameters to a given script blueprint. + * + * @param rawScript - The raw script CborHex from blueprint. + * @param params - The parameters to apply, in an array. + * @param type - The type of the parameters, default to be Mesh's Data type. It could also be in JSON and raw CBOR. + * @returns The double-cbor encoded script CborHex with the parameters applied. + */ +export const applyParamsToScript = ( + rawScript: string, + params: object[] | Data[], + type: 'Mesh' | 'JSON' | 'CBOR' = 'Mesh', ): string => { const cslParams = csl.JsVecString.new(); - params.forEach((param) => { - cslParams.add(JSON.stringify(param)); - }); - return csl.apply_params_to_script(cslParams, rawAikenScriptBlueprint); + let paramType = csl.BuilderDataType.CBOR; + + switch (type) { + case 'JSON': + paramType = csl.BuilderDataType.JSON; + params.forEach((param) => { + if (typeof param === 'object') { + cslParams.add(JSON.stringify(param)); + } else if (typeof param === 'string') { + cslParams.add(param); + } + }); + break; + + case 'Mesh': + params.forEach((param) => { + const paramCbor = toPlutusData(param as Data); + cslParams.add(paramCbor.to_hex()); + }); + break; + + default: + params.forEach((param) => { + cslParams.add(param as string); + }); + break; + } + + return csl.apply_params_to_script(rawScript, cslParams, paramType); }; diff --git a/packages/csl/test/utils/address.test.ts b/packages/csl/test/utils/address.test.ts index 4436c5c..5ffbba6 100644 --- a/packages/csl/test/utils/address.test.ts +++ b/packages/csl/test/utils/address.test.ts @@ -1,4 +1,9 @@ -import { scriptHashToBech32, serializeBech32Address } from '../../src'; +import { pubKeyAddress, scriptAddress } from '@meshsdk/common'; +import { + parsePlutusAddressObjToBech32, + scriptHashToBech32, + serializeBech32Address, +} from '../../src'; describe('Address', () => { test('serializeBech32Address', () => { @@ -21,4 +26,24 @@ describe('Address', () => { 'addr_test1zqqyn5zvcvfksx5rjr276pyyk6qrcakcpnvhuuwl3e897w4l4gu9er4t0w7udjvt2pqngddn6q4h8h3uv38p8p9cq82q7xtsrh', ); }); + test('parsePlutusAddressObjToBech32', () => { + const address = scriptAddress( + '0049d04cc313681a8390d5ed0484b6803c76d80cd97e71df8e4e5f3a', + 'bfaa385c8eab7bbdc6c98b50413435b3d02b73de3c644e1384b801d4', + ); + const serializedAddress = parsePlutusAddressObjToBech32(address); + expect(serializedAddress).toBe( + 'addr_test1zqqyn5zvcvfksx5rjr276pyyk6qrcakcpnvhuuwl3e897w4l4gu9er4t0w7udjvt2pqngddn6q4h8h3uv38p8p9cq82q7xtsrh', + ); + }); + test('parsePlutusAddressObjToBech32 2', () => { + const address = pubKeyAddress( + '36314aebecfbc929ee447dcb50fd690604eceae9403a298d9b1f9a54', + '75531fbe1e68b11e9a10dbbc5df889edea92325a85b758bbbf8735d9', + ); + const serializedAddress = parsePlutusAddressObjToBech32(address); + expect(serializedAddress).toBe( + 'addr_test1qqmrzjhtanauj20wg37uk58adyrqfm82a9qr52vdnv0e54r42v0mu8ngky0f5yxmh3wl3z0da2fryk59kavth0u8xhvsufgmc8', + ); + }); }); diff --git a/packages/csl/test/utils/aiken.test.ts b/packages/csl/test/utils/aiken.test.ts new file mode 100644 index 0000000..7efe1e4 --- /dev/null +++ b/packages/csl/test/utils/aiken.test.ts @@ -0,0 +1,34 @@ +import { builtinByteString } from '@meshsdk/common'; +import { applyParamsToScript, serializeBech32Address } from '../../src'; + +describe('Aiken', () => { + test('applyParamsToScript 1', () => { + const scriptCbor = + '584501000032323232323222533300432323253330073370e900018041baa0011324a2600c0022c60120026012002600600229309b2b118021baa0015734aae7555cf2ba157441'; + const expectedCbor = + '584f584d010000332323232323222533300432323253330073370e900018041baa0011324a2600c0022c60120026012002600600229309b2b118021baa0015734aae7555cf2ba157449801034212340001'; + expect(applyParamsToScript(scriptCbor, ['1234'])).toBe(expectedCbor); + expect(applyParamsToScript(scriptCbor, [builtinByteString('1234')], 'JSON')).toBe( + expectedCbor, + ); + }); + const hash1 = 'e6e5285a878161c101a59b4e36f1f99e5e464d30f510be3ee34f907f'; + const hash2 = '2291f67ee643db1a830734bd54d39022c5d1f990682e689c95d8fed0'; + test('applyParamsToScript 2', () => { + const address = + 'addr_test1qz8j439j54afpl4hw978xcw8qsa0dsmyd6wm9v8xzeyz7ucrj5rt3et7z59mvmmpxnejvn2scwmseezdq5h5fpw08z8s8d93my'; + const { pubKeyHash } = serializeBech32Address(address); + const scriptCbor = + '590a24010000323232323232323232232232232222323232533300f323232323232323232323232323232323232323253330233370e90000008a99981199b8748008c0880084c94ccc090cdc3a4000604600226464646464646464a66605e60640042646644646600200200444a66606800229444c8c94ccc0cccc0880180084cc010010004528181c0011bae30360013758602a605601c660626ea409ccc0c4dd480225eb80c94ccc0b4cdc3a4000002264646464a666068606e004264649319299981999b87480000044c8c94ccc0e0c0ec0084c9263253330363370e900000089919299981d981f00109924c60520022c607800260680042a66606c66e1d20020011323232323232533303f3042002149858dd6982000098200011bad303e001303e002375a607800260680042c60680022c607200260620062a66606666e1d200200115333036303100314985858c0c4008c08800c58c0d4004c0d4008c0cc004c0ac01858c0ac01458dd7181800098180011bae302e001302e002302c001302c002375c605400260440022c6464a66604a66e1d20003024001132323253330283370e900218138008981698130008b180b981298081812800981580098118008b19809000919b873330103756601c6046601c604600204291010048008dd6180618108020b0a99981199b87480080044c8c94ccc094cdc3a40046048008264a66604c66e1d20003025001132323253330293370e90021814000899191919299981699b87480080044c8c8c8c8c8c8c8c94ccc0d54ccc0d54ccc0d4010400c52808010a50100114a066660326eacc060c0c80540b0c05cc078c0c8c074c0c80352001323232323232323232533303c3370e9001181d80109919299981f002899b88010001003375a60840026074004002264a66607866e1d2002303b00213232533303e0050031337120200026eb4c108004c0e8008004528181d80119b8748008c0e8dd5181d80099bb00033330380014c103d87a80004c0103d87980003370e9001181c1baa303c001303c002303a0013032301e3032001301930310143302137586034606002605866e3c0040acdd7181a800981a8011bad3033001302b00314a06056004603e002605e002604e0022c6030604c6022604c002605800260480022c660186eb0c03cc08c01800458c0a4004c0840644c8c94ccc094cdc3a400460480082646464a66605066e1d200030270011323232323253330303033002132323232325333032533303253330325333032005100414a020062940400852808008a50323232323232323232533303a3370e9001181c80109919299981e002899b88001018003375a60800026070004002264a66607466e1d2002303900213232533303c0050031337120020306eb4c100004c0e0008004528181c80119b8748008c0e0dd5181c80099bb00033330360014c103d87a80004c0103d87980003370e9001181b1baa303a001303a00230380013030301b30300013017302f012323253330323370e900200089919299981a19b8748008c0cc0044c8c8c8c94ccc0ecc0f800854ccc0e0cdc7800819099b8700301414a02c6eb8c0f0004c0f0008dd6981d00098190008b181c00098180010a5030300013020302e004323253330313370e900200089919299981999b8748010c0c80044c8c94ccc0e0c0ec0084cdc78008178b1bae30390013031001163037001302f00214a0605e002603e605a6030605a00c66660266eacc048c0b003c098c04401120023301c3758602a605601c04e2c60620026644646600200200644a666064002297ae013232533303153330313375e6036605e00400e266e1cccc070dd5980d1817801014802a400429404cc0d4008cc0100100044cc010010004c0d8008c0d0004dd6180d98148061807000980a181418099814000981700098130008b198071bac30113025008001302b001302300416375a605200260420326042030604c002604c00460480026038026464a66603e66e1d2002301e00113232323253330233370e90010008980780189919299981299b8748000c0900044c8c8c94ccc0a0cdc3a4000002260286602a0106eb8c0b4c0980084c050cc054020dd7181698130011813000981580098118008b1814800981080118108009805180f8021bae3025001301d001163008301c001230223023302330233023001222232533302300114a0264a666048002264646464a66604aa66604a66e3c0040244cdc78010040a5013370e00600e2940dd718148019bae30283029002375a604e605060500026eb0c09800852818130009919198008008011129998128008a5eb804c8ccc888c8cc00400400c894ccc0ac004400c4c8cc0b4dd3998169ba90063302d37526eb8c0a8004cc0b4dd41bad302b0014bd7019801801981780118168009bae30240013756604a002660060066052004604e002646600200200a44a666048002297adef6c6013232323253330253371e911000021003133029337606ea4008dd3000998030030019bab3026003375c60480046050004604c0024604060426042604260426042604260420024466012004466ebcc018c0680040088c078c07cc07cc07cc07cc07cc07cc07cc07c0048c074c0780048c070004888c8c8c94ccc06ccdc3a40040022900009bad30203019002301900132533301a3370e90010008a60103d87a8000132323300100100222533302000114c103d87a800013232323253330213371e014004266e95200033025375000297ae0133006006003375a60440066eb8c080008c090008c088004dd5980f980c001180c000991980080080211299980e8008a6103d87a8000132323232533301e3371e010004266e95200033022374c00297ae01330060060033756603e0066eb8c074008c084008c07c0048dca0009119b8a00200122323300100100322533301900114c0103d87a8000132325333018300500213374a90001980e00125eb804cc010010004c074008c06c00488c8cc00400400c894ccc06000452809919299980b99b8f00200514a226600800800260380046eb8c0680048c058c05cc05c0048c94ccc044cdc3a400000226464a66602c60320042930b1bae3017001300f002153330113370e900100089919299980b180c8010a4c2c6eb8c05c004c03c00858c03c0045261365632533300f3370e90000008a99980918068028a4c2c2a66601e66e1d20020011323253330143017002132498c94ccc048cdc3a4000002264646464a66603260380042649319299980b99b87480000044c8c94ccc070c07c00852616375c603a002602a0082c602a0062c6eb4c068004c068008c060004c04000858c04000458c054004c03401454ccc03ccdc3a400800226464a666028602e0042930b1bad3015001300d00516300d0043001004232533300e3370e90000008a99980898060010a4c2c2a66601c66e1d200200113232323253330153018002149858dd7180b000980b0011bad3014001300c0021533300e3370e9002000899192999809980b0010a4c2c6eb8c050004c03000858c030004dd70009bae001375c0024600a6ea80048c00cdd5000ab9a5573aaae7955cfaba05742ae89'; + const expectedCbor = + '590a8f590a8c010000333323232323232323232232232232222323232533300f323232323232323232323232323232323232323253330233370e90000008a99981199b8748008c0880084c94ccc090cdc3a4000604600226464646464646464a66605e60640042646644646600200200444a66606800229444c8c94ccc0cccc0880180084cc010010004528181c0011bae30360013758602a605601c660626ea409ccc0c4dd480225eb80c94ccc0b4cdc3a4000002264646464a666068606e004264649319299981999b87480000044c8c94ccc0e0c0ec0084c9263253330363370e900000089919299981d981f00109924c60520022c607800260680042a66606c66e1d20020011323232323232533303f3042002149858dd6982000098200011bad303e001303e002375a607800260680042c60680022c607200260620062a66606666e1d200200115333036303100314985858c0c4008c08800c58c0d4004c0d4008c0cc004c0ac01858c0ac01458dd7181800098180011bae302e001302e002302c001302c002375c605400260440022c6464a66604a66e1d20003024001132323253330283370e900218138008981698130008b180b981298081812800981580098118008b19809000919b873330103756601c6046601c60460020429110048008dd6180618108020b0a99981199b87480080044c8c94ccc094cdc3a40046048008264a66604c66e1d20003025001132323253330293370e90021814000899191919299981699b87480080044c8c8c8c8c8c8c8c94ccc0d54ccc0d54ccc0d4010400c52808010a50100114a066660326eacc060c0c80540b0c05cc078c0c8c074c0c80352001323232323232323232533303c3370e9001181d80109919299981f002899b88010001003375a60840026074004002264a66607866e1d2002303b00213232533303e0050031337120200026eb4c108004c0e8008004528181d80119b8748008c0e8dd5181d80099bb00033330380014c103d87a80004c0103d87980003370e9001181c1baa303c001303c002303a0013032301e3032001301930310143302137586034606002605866e3c0040acdd7181a800981a8011bad3033001302b00314a06056004603e002605e002604e0022c6030604c6022604c002605800260480022c660186eb0c03cc08c01800458c0a4004c0840644c8c94ccc094cdc3a400460480082646464a66605066e1d200030270011323232323253330303033002132323232325333032533303253330325333032005100414a020062940400852808008a50323232323232323232533303a3370e9001181c80109919299981e002899b88001018003375a60800026070004002264a66607466e1d2002303900213232533303c0050031337120020306eb4c100004c0e0008004528181c80119b8748008c0e0dd5181c80099bb00033330360014c103d87a80004c0103d87980003370e9001181b1baa303a001303a00230380013030301b30300013017302f012323253330323370e900200089919299981a19b8748008c0cc0044c8c8c8c94ccc0ecc0f800854ccc0e0cdc7800819099b8700301414a02c6eb8c0f0004c0f0008dd6981d00098190008b181c00098180010a5030300013020302e004323253330313370e900200089919299981999b8748010c0c80044c8c94ccc0e0c0ec0084cdc78008178b1bae30390013031001163037001302f00214a0605e002603e605a6030605a00c66660266eacc048c0b003c098c04401120023301c3758602a605601c04e2c60620026644646600200200644a666064002297ae013232533303153330313375e6036605e00400e266e1cccc070dd5980d1817801014802a400429404cc0d4008cc0100100044cc010010004c0d8008c0d0004dd6180d98148061807000980a181418099814000981700098130008b198071bac30113025008001302b001302300416375a605200260420326042030604c002604c00460480026038026464a66603e66e1d2002301e00113232323253330233370e90010008980780189919299981299b8748000c0900044c8c8c94ccc0a0cdc3a4000002260286602a0106eb8c0b4c0980084c050cc054020dd7181698130011813000981580098118008b1814800981080118108009805180f8021bae3025001301d001163008301c001230223023302330233023001222232533302300114a0264a666048002264646464a66604aa66604a66e3c0040244cdc78010040a5013370e00600e2940dd718148019bae30283029002375a604e605060500026eb0c09800852818130009919198008008011129998128008a5eb804c8ccc888c8cc00400400c894ccc0ac004400c4c8cc0b4dd3998169ba90063302d37526eb8c0a8004cc0b4dd41bad302b0014bd7019801801981780118168009bae30240013756604a002660060066052004604e002646600200200a44a666048002297adef6c6013232323253330253371e911000021003133029337606ea4008dd3000998030030019bab3026003375c60480046050004604c0024604060426042604260426042604260420024466012004466ebcc018c0680040088c078c07cc07cc07cc07cc07cc07cc07cc07c0048c074c0780048c070004888c8c8c94ccc06ccdc3a40040022900009bad30203019002301900132533301a3370e90010008a60103d87a8000132323300100100222533302000114c103d87a800013232323253330213371e014004266e95200033025375000297ae0133006006003375a60440066eb8c080008c090008c088004dd5980f980c001180c000991980080080211299980e8008a6103d87a8000132323232533301e3371e010004266e95200033022374c00297ae01330060060033756603e0066eb8c074008c084008c07c0048dca0009119b8a00200122323300100100322533301900114c0103d87a8000132325333018300500213374a90001980e00125eb804cc010010004c074008c06c00488c8cc00400400c894ccc06000452809919299980b99b8f00200514a226600800800260380046eb8c0680048c058c05cc05c0048c94ccc044cdc3a400000226464a66602c60320042930b1bae3017001300f002153330113370e900100089919299980b180c8010a4c2c6eb8c05c004c03c00858c03c0045261365632533300f3370e90000008a99980918068028a4c2c2a66601e66e1d20020011323253330143017002132498c94ccc048cdc3a4000002264646464a66603260380042649319299980b99b87480000044c8c94ccc070c07c00852616375c603a002602a0082c602a0062c6eb4c068004c068008c060004c04000858c04000458c054004c03401454ccc03ccdc3a400800226464a666028602e0042930b1bad3015001300d00516300d0043001004232533300e3370e90000008a99980898060010a4c2c2a66601c66e1d200200113232323253330153018002149858dd7180b000980b0011bad3014001300c0021533300e3370e9002000899192999809980b0010a4c2c6eb8c050004c03000858c030004dd70009bae001375c0024600a6ea80048c00cdd5000ab9a5573aaae7955cfaba05742ae8930011e581ce6e5285a878161c101a59b4e36f1f99e5e464d30f510be3ee34f907f004c011e581c8f2ac4b2a57a90feb7717c7361c7043af6c3646e9db2b0e616482f73004c011e581c2291f67ee643db1a830734bd54d39022c5d1f990682e689c95d8fed00001'; + expect(applyParamsToScript(scriptCbor, [hash1, pubKeyHash, hash2])).toBe(expectedCbor); + expect( + applyParamsToScript( + scriptCbor, + [builtinByteString(hash1), builtinByteString(pubKeyHash), builtinByteString(hash2)], + 'JSON', + ), + ).toBe(expectedCbor); + }); +}); diff --git a/packages/csl/yarn.lock b/packages/csl/yarn.lock index 67272a4..2489c20 100644 --- a/packages/csl/yarn.lock +++ b/packages/csl/yarn.lock @@ -27,15 +27,15 @@ "@jridgewell/resolve-uri" "^3.0.3" "@jridgewell/sourcemap-codec" "^1.4.10" -"@sidan-lab/sidan-csl-rs-browser@^0.3.6": - version "0.3.6" - resolved "https://registry.yarnpkg.com/@sidan-lab/sidan-csl-rs-browser/-/sidan-csl-rs-browser-0.3.6.tgz#689ee5c1f2ddf623a29a70b4c878ab716cd018be" - integrity sha512-CeFeGIjdPsyNqlQlYChf0s04yLbj/m1eAjBRG6jV2iEU1lFnNHHlebUS9wEJMH9LU4UT3cP4vHlex6hURuc4DA== - -"@sidan-lab/sidan-csl-rs-nodejs@^0.3.6": - version "0.3.6" - resolved "https://registry.yarnpkg.com/@sidan-lab/sidan-csl-rs-nodejs/-/sidan-csl-rs-nodejs-0.3.6.tgz#a16ae74324a61c2302fc34e3ae60d062ac17b214" - integrity sha512-nyfTqWI2IQY+LQmXOaam3NUzZK6fF8h6lL1mB3otajLNXpEhc0ZDKv1QeV9ia5rmky799nrzLfwKtxuDmtRIfQ== +"@sidan-lab/sidan-csl-rs-browser@^0.5.0-alpha.9": + version "0.5.0-alpha.9" + resolved "https://registry.yarnpkg.com/@sidan-lab/sidan-csl-rs-browser/-/sidan-csl-rs-browser-0.5.0-alpha.9.tgz#d159e14a7090af0e8d229eb39251f924d3dbf862" + integrity sha512-SeDziFm3QaakJgakDE1/PKfmHYDwGPkJEC+yX8bWvzNOx/Hql8OC1wUyMKd12VZx3NAE/AoRYtqF4mKknSyc+g== + +"@sidan-lab/sidan-csl-rs-nodejs@^0.5.0-alpha.9": + version "0.5.0-alpha.9" + resolved "https://registry.yarnpkg.com/@sidan-lab/sidan-csl-rs-nodejs/-/sidan-csl-rs-nodejs-0.5.0-alpha.9.tgz#37d0994f168c263923ee2489f81c514d2efe8a82" + integrity sha512-t/aci5uFgCsedJGiM3zqvTrjr2lEtkVIcf5VkPESo9VE6aL42gUqZ+k7DAw/HbpmGUesMWlEjaSpHofvn7cxsg== "@tsconfig/node10@^1.0.7": version "1.0.9"