diff --git a/packages/common/package.json b/packages/common/package.json index 90a912b..deabcae 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -1,7 +1,7 @@ { "name": "@meshsdk/common", "description": "Cardano common utils & constants for Mesh SDK", - "version": "1.0.0-alpha.10", + "version": "1.0.0-alpha.12", "license": "Apache-2.0", "main": "dist/cjs/index.js", "module": "dist/mjs/index.js", diff --git a/packages/common/src/builder/data/plutus.ts b/packages/common/src/builder/data/plutus.ts index 9d3b8a0..a1c582b 100644 --- a/packages/common/src/builder/data/plutus.ts +++ b/packages/common/src/builder/data/plutus.ts @@ -77,10 +77,24 @@ export const maybeStakingHash = ( conStr0([conStr0([builtinByteString(stakeCredential)])]), ]); }; -export const pubKeyAddress = (bytes: string, stakeCredential?: string): PubKeyAddress => - conStr0([conStr0([builtinByteString(bytes)]), maybeStakingHash(stakeCredential || '')]); -export const scriptAddress = (bytes: string, stakeCredential?: string): ScriptAddress => - conStr0([conStr1([builtinByteString(bytes)]), maybeStakingHash(stakeCredential || '')]); +export const pubKeyAddress = ( + bytes: string, + stakeCredential?: string, + isScriptCredential = false, +): PubKeyAddress => + conStr0([ + conStr0([builtinByteString(bytes)]), + maybeStakingHash(stakeCredential || '', isScriptCredential), + ]); +export const scriptAddress = ( + bytes: string, + stakeCredential?: string, + isScriptCredential = false, +): ScriptAddress => + conStr0([ + conStr1([builtinByteString(bytes)]), + maybeStakingHash(stakeCredential || '', isScriptCredential), + ]); export const assetClass = (policyId: string, assetName: string): AssetClass => conStr0([currencySymbol(policyId), tokenName(assetName)]); diff --git a/packages/common/src/builder/serializer.ts b/packages/common/src/builder/serializer.ts index fa59e81..c29ed47 100644 --- a/packages/common/src/builder/serializer.ts +++ b/packages/common/src/builder/serializer.ts @@ -15,6 +15,7 @@ export const emptyTxBuilderBody = (): MeshTxBuilderBody => ({ validityRange: {}, certificates: [], signingKey: [], + withdrawals: [], }); export interface IMeshSerializer { diff --git a/packages/common/src/builder/types.ts b/packages/common/src/builder/types.ts index 926c3b9..ae07078 100644 --- a/packages/common/src/builder/types.ts +++ b/packages/common/src/builder/types.ts @@ -7,16 +7,16 @@ export type MeshTxBuilderBody = { collaterals: PubKeyTxIn[]; requiredSignatures: string[]; referenceInputs: RefTxIn[]; + withdrawals: Withdrawal[]; mints: MintItem[]; changeAddress: string; changeDatum?: BuilderData; metadata: Metadata[]; validityRange: ValidityRange; + certificates: Certificate[]; signingKey: string[]; extraInputs: UTxO[]; selectionThreshold: number; - certificates: Certificate[]; - // withdrawals?: Record; }; export type TxIn = PubKeyTxIn | ScriptTxIn; @@ -37,15 +37,7 @@ export type ScriptTxIn = { }; export type ScriptTxInParameter = { - scriptSource?: - | { - type: 'Provided'; - script: PlutusScript; - } - | { - type: 'Inline'; - txInInfo: ScriptSourceInfo; - }; + scriptSource?: ScriptSource; datumSource?: | { type: 'Provided'; @@ -59,6 +51,16 @@ export type ScriptTxInParameter = { redeemer?: Redeemer; }; +export type ScriptSource = + | { + type: 'Provided'; + script: PlutusScript; + } + | { + type: 'Inline'; + txInInfo: ScriptSourceInfo; + }; + export type ScriptSourceInfo = { txHash: string; txIndex: number; @@ -137,6 +139,16 @@ export type Certificate = | { type: 'DeregisterStake'; stakeKeyHash: string } | { type: 'RetirePool'; poolId: string; epoch: number }; +export type Withdrawal = + | { type: 'PubKeyWithdrawal'; address: string; coin: number } + | { + type: 'PlutusScriptWithdrawal'; + address: string; + coin: number; + scriptSource?: ScriptSource; + redeemer?: Redeemer; + }; + // Utilities export type RequiredWith = Required & {