import { NativeScript, parseNativeScript } from "./nativeScript"; import { PlutusData, PlutusV1Script, PlutusV2Script, PlutusV3Script } from "./plutus"; import { Redeemers, parseRedeemers } from "./redeemer"; type VKey = Buffer; type Signature = Buffer; type VKeyWitness = { vkey: Buffer; signature: Buffer; }; type BootStrapWitness = { publicKey: VKey; signature: Signature; chainCode: Buffer; attributes: Buffer; }; export type TxWitnessSet = { vkeyWitnesses?: VKeyWitness[]; nativeScripts?: NativeScript[]; bootstrapWitnesses?: BootStrapWitness[]; plutusV1Script?: Set; plutusData?: Set; redeemers?: Redeemers[]; plutusV2Script?: Set; plutusV3Script?: Set; }; export function parseTxWitness(witnessSet: Map): TxWitnessSet { const vKeyWitness = witnessSet.get(0) ? parseVkeyWitness(witnessSet.get(0)) : undefined; const nativeScripts = witnessSet.get(1) ? parseNativeScript(witnessSet.get(1)) : undefined; const bootStrapWitness = witnessSet.get(2) ? parseBootStrapWitness(witnessSet.get(2)) : undefined; const plutusV1Scirpt = witnessSet.get(3) ? witnessSet.get(3) : undefined; const plutusData = witnessSet.get(4) ? witnessSet.get(4) : undefined; const redeemers = witnessSet.get(5) ? parseRedeemers(witnessSet.get(5)) : undefined; const plutusV2Script = witnessSet.get(6) ? witnessSet.get(6) : undefined; const plutusV3Script = witnessSet.get(7) ? witnessSet.get(7) : undefined; return { vkeyWitnesses: vKeyWitness, nativeScripts: nativeScripts, bootstrapWitnesses: bootStrapWitness, plutusV1Script: plutusV1Scirpt, plutusData: plutusData, redeemers: redeemers, plutusV2Script: plutusV2Script, plutusV3Script: plutusV3Script, }; } function parseVkeyWitness(vkeyWitnesses: any[]): VKeyWitness[] { const parsedVkeyWitnesses: VKeyWitness[] = []; vkeyWitnesses.forEach((vkeyWitness) => { parsedVkeyWitnesses.push({ vkey: vkeyWitness[0], signature: vkeyWitness[1] }); }); return parsedVkeyWitnesses; } function parseBootStrapWitness(bootstrapWitnesses: any[]): BootStrapWitness[] { const parsedBootStrapWitnesses: BootStrapWitness[] = []; bootstrapWitnesses.forEach((bootStrapWitness) => { parsedBootStrapWitnesses.push({ publicKey: bootStrapWitness[0], signature: bootStrapWitness[1], chainCode: bootStrapWitness[2], attributes: bootStrapWitness[3], }); }); return parsedBootStrapWitnesses; }