import { Credential, StakeAddress, StakeCredential } from "../serialization/address"; import { AbstainDRep, KeyDRep, NoConfidenceDRep, ScriptDRep } from "../serialization/drep"; import { RawScript, Script } from "../serialization/plutusScript"; import { RawValue, Value } from "../serialization/value"; import { bech32 } from "../lib/bech32"; import { Buffer } from "buffer"; type Operator = "eq" | "lt" | "gt" | "lte" | "gte" | "contains" | "hasProperty"; type PropertyType = "string" | "number" | "object" | "array"; const hexPattern = /^[0-9a-fA-F]+$/; // for storing event meatadata interface IEventFilterAtribute { id: string; label: string; type: string; operators?: Operator[]; validator?: (arg: any) => any | undefined; properties?: IEventFilterAtribute[]; } const keyAndScriptCredentialSchema: IEventFilterAtribute[] = [ { id: "keyHash", label: "KeyHash", type: "string", validator: (arg: string) => { try { const parsedKeyHash = Credential.fromKeyHash(Buffer.from(arg, "hex")); return parsedKeyHash; } catch (error: any) { return undefined; } }, }, { id: "scriptHash", label: "ScriptHash", type: "string", validator: (arg: string) => { try { const parsedScriptHash = Credential.fromScriptHash(Buffer.from(arg, "hex")); return parsedScriptHash; } catch (error: any) { return undefined; } }, }, ]; const epochSchema: IEventFilterAtribute = { id: "epoch", label: "Epoch", type: "number", validator: (arg: string) => { return verifyBigInt(arg); }, }; const credentialSchema: IEventFilterAtribute = { id: "credential", label: "Credential", type: "string", properties: keyAndScriptCredentialSchema, }; const poolKeyHashSchema: IEventFilterAtribute = { id: "poolKeyHash", label: "PoolKeyHash", type: "string", validator: (arg: string) => { return verifyHash(arg, 28); }, }; const urlSchema: IEventFilterAtribute = { id: "url", label: "Url", type: "string", validator: (arg: string) => { try { const url = new URL(arg); // Allow HTTP, HTTPS, and IPFS protocols const allowedProtocols = ["http:", "https:", "ipfs:"]; if (!allowedProtocols.includes(url.protocol)) { return undefined; } return arg; } catch (error: any) { return undefined; } }, }; const poolParamsSchema: IEventFilterAtribute = { id: "poolParams", label: "PoolParams", type: "object", properties: [ // operator { id: "operator", label: "Operator", type: "string", validator: (arg: string) => { return verifyHash(arg, 28); }, }, // verificationKeyHash { id: "verificationKeyHash", label: "VerificationKeyHash", type: "string", validator: (arg: string) => { return verifyHash(arg, 32); }, }, // pool Pledge { id: "pledge", label: "Pledge", type: "bigint", validator: (arg: string) => { return verifyBigInt(arg); }, }, // cost { id: "cost", label: "Cost", type: "bigin", validator: (arg: string) => { return verifyBigInt(arg); }, }, // margin { id: "margin", label: "Margin", type: "array", // TODO: this is not complete validator: (arg: string[]) => { return verifyInterval(arg); }, }, // rewardAccount StakeAddress.schema("rewardAccount", "RewardAccount"), // poolOwners { id: "poolOwners", label: "PoolOwners", type: "array", validator: (arg: string[]) => { let parsedPoolOwners = arg.map((keyHash) => verifyHash(keyHash, 28)); return parsedPoolOwners.includes(undefined) ? undefined : parsedPoolOwners; }, }, // pool relay { id: "relays", label: "Relays", type: "array", properties: [ { id: "port", label: "Port", type: "number", }, { id: "ipv4", label: "IPv4", type: "string", validator: (arg: string) => { return verifyHash(arg, 4); }, }, { id: "ipv6", label: "IPv6", type: "string", validator: (arg: string) => { return verifyHash(arg, 16); }, }, { id: "dnsName", label: "DNSName", type: "string", validator: (arg: string) => { if (arg.length <= 128) { return arg; } else { return undefined; } }, }, ], }, // pool metadata { id: "poolMetadata", label: "PoolMetadata", type: "object", properties: [ urlSchema, { id: "poolMetadataHash", label: "PoolMetadataHash", type: "string", validator: (arg: string) => { return verifyHash(arg, 32); }, }, ], }, ], }; const stakeCredentialSchema: IEventFilterAtribute = { id: "stakePart", label: "stakePart", type: "string", properties: [ { id: "keyHash", label: "KeyHash", type: "string", validator: (arg: any) => { try { const parsedkeyHash = StakeCredential.fromKeyHash(Buffer.from(arg, "hex")); return parsedkeyHash; } catch (error: any) { return undefined; } }, }, { id: "scriptHash", label: "ScriptHash", type: "string", validator: (arg: any) => { try { const parsedScriptHash = StakeCredential.fromScriptHash(Buffer.from(arg, "hex")); return parsedScriptHash; } catch (error: any) { return undefined; } }, }, ], }; const paymentCredentialSchema: IEventFilterAtribute = { id: "paymentPart", label: "PaymentPart", type: "string", properties: credentialSchema.properties, }; const transactionInputPropertiesSchema: IEventFilterAtribute[] = [ { id: "txHash", label: "TxHash", type: "string", validator: (arg: any) => { return verifyHash(arg, 32); }, }, { id: "index", label: "TxIndex", type: "number", validator: (arg: string) => { const parsedIndex = parseInt(arg); if (!isNaN(parsedIndex) && parsedIndex.toString() == arg) { return arg; } else { return undefined; } }, }, ]; const transactionOutputPropertiesSchema: IEventFilterAtribute[] = [ // value { id: "value", label: "Value", type: "object", operators: ["eq", "lt", "gt", "lte", "gte"], properties: [ { id: "lovelace", label: "Lovelace", type: "bigint", validator: (arg: string) => { try { return Value.fromString(arg); } catch (error: any) { return undefined; } }, }, { id: "multiAsset", label: "MultiAsset", type: "object", validator: (arg: string) => { try { return Value.fromString(arg); } catch (error: any) { return undefined; } }, }, ], validator: (arg: any) => { if (typeof arg == "string") { try { return Value.fromString(arg); } catch (error: any) { return undefined; } } else if (typeof arg == "bigint" || typeof arg == "number" || typeof arg == "object" || Array.isArray(arg)) { try { return Value.fromCborObject(arg as RawValue); } catch (error: any) { return undefined; } } else { return undefined; } }, }, // address { id: "address", label: "address", type: "string", operators: ["eq", "lt", "gt", "contains"], properties: [ { id: "networkId", label: "NetworkID", type: "string", validator: (arg: string) => { const intNetId = parseInt(arg); if (intNetId == 0) { return "testnet"; } else if (intNetId == 1) { return "mainnet"; } else { return undefined; } }, }, paymentCredentialSchema, stakeCredentialSchema, ], }, // datum { id: "inlineDatum", label: "InlineDatum", type: "object", }, //datumHash { id: "datumHash", label: "DatumHash", type: "string", }, //referenceScript { id: "referenceScript", label: "ReferenceScript", type: "string", validator: (arg: string) => { const rawScript: RawScript = { tag: 24, value: Buffer.from(arg, "hex") }; try { return Script.fromRawScript(rawScript); } catch (error: any) { return undefined; } }, }, ]; const depositSchema: IEventFilterAtribute = { id: "deposit", label: "Deposit", type: "string", validator: (arg: string) => { return verifyBigInt(arg); }, }; const dRepSchema: IEventFilterAtribute = { id: "dRep", label: "DRep", type: "string", properties: [ { id: "keyDRep", label: "KeyDRep", type: "string", validator: (arg: string) => { return verifyKeyDRep(arg); }, }, { id: "scriptDRep", label: "ScriptDRep", type: "string", validator: (arg: string) => { return verifyScriptDRep(arg); }, }, { id: "abstainDRep", label: "AbstainDRep", type: "boolean", validator: (arg: boolean) => { return arg ? new AbstainDRep() : undefined; }, }, { id: "noConfidenceDRep", label: "NoConfidenceDRep", type: "boolean", validator: (arg: boolean) => { return arg ? new NoConfidenceDRep() : undefined; }, }, ], }; const anchorSchema: IEventFilterAtribute = { id: "anchor", label: "Anchor", type: "object", properties: [ // anchor url urlSchema, // anchor hash { id: "hash", label: "AnchorHash", type: "string", validator: (arg: string) => { return verifyHash(arg, 32); }, }, ], }; export const Events: IEventFilterAtribute[] = [ { id: "tx", label: "Transaction", type: "object", properties: [ // output { id: "outputs", label: "Output", type: "object", properties: transactionOutputPropertiesSchema, }, // input { id: "inputs", label: "Input", type: "object", properties: transactionInputPropertiesSchema, }, // fee { id: "fee", label: "Fee", type: "string", validator: (arg: string) => { return verifyBigInt(arg); }, }, // ttl { id: "ttl", label: "TimeToLive", type: "string", validator: (arg: string) => { return verifyBigInt(arg); }, }, // certificates { id: "certificate", label: "Certificate", type: "object", properties: [ stakeCredentialSchema, poolKeyHashSchema, poolParamsSchema, depositSchema, dRepSchema, { id: "coldCredential", label: "ColdCredential", type: "object", properties: keyAndScriptCredentialSchema, }, { id: "hotCredential", label: "HotCredential", type: "object", properties: keyAndScriptCredentialSchema, }, anchorSchema, credentialSchema, ], }, // withdrawals { id: "withdrawal", label: "Withdrawal", type: "object", properties: [ StakeAddress.schema("rewardAccount", "RewardAccount"), { id: "amount", label: "Amount", type: "string", validator: (arg: string) => { return verifyBigInt(arg); }, }, ], }, // auxiliary data hash { id: "auxDataHash", label: "AuxDataHash", type: "string", validator: (arg: string) => { return verifyHash(arg, 32); }, }, // validity interval start { id: "validityIntervalStart", label: "ValidityIntervalStart", type: "string", validator: (arg: string) => { return verifyBigInt(arg); }, }, // mint { id: "mint", label: "Mint", type: "object", ///TODO: make this better properties: [ { id: "currencySymbol", label: "CurrencySymbol", type: "string", validator: (arg: string) => { return verifyHash(arg, 28); }, properties: [ { id: "amount", label: "Amount", type: "object", properties: [ { id: "tokenName", label: "TokenName", type: "string", validator: (arg: string) => { if (hexPattern.test(arg)) { if (Buffer.from(arg, "hex").toString("utf-8").length <= 32) { return arg; } else { return undefined; } } else { if (arg.length <= 32) { return arg; } else { return undefined; } } }, }, ], }, { id: "quantity", label: "Quantity", type: "string", validator: (arg: string) => { return verifyBigInt(arg); }, }, ], }, ], }, // script data hash { id: "scriptDataHash", label: "ScriptDataHash", type: "string", validator: (arg: string) => { return verifyHash(arg, 32); }, }, // collateral inputs { id: "collateralInput", label: "CollateralInput", type: "object", properties: [ { id: "txHash", label: "TxHash", type: "string", validator: (arg: any) => { return verifyHash(arg, 32); }, }, { id: "index", label: "TxIndex", type: "string", validator: (arg: string) => { const parsedIndex = parseInt(arg); if (!isNaN(parsedIndex) && parsedIndex.toString() == arg) { return arg; } else { return undefined; } }, }, ], }, // signers { id: "requiredSigners", label: "RequiredSigners", type: "array", validator: (arg: string[]) => { let parsedSigners = arg.map((keyHash) => verifyHash(keyHash, 28)); return parsedSigners.includes(undefined) ? undefined : parsedSigners; }, }, // networkId { id: "networkId", label: "NetworkID", type: "string", validator: (arg: string) => { const intNetId = parseInt(arg); if (intNetId == 0) { return "testnet"; } else if (intNetId == 1) { return "mainnet"; } else { return undefined; } }, }, // collateral return { id: "collateralReturn", label: "collateralReturn", type: "object", properties: transactionOutputPropertiesSchema, }, // total collateral { id: "collateral", label: "Collateral", type: "string", validator: (arg: string) => { return verifyBigInt(arg); }, }, // reference Inputs { id: "referenceInputs", label: "ReferenceInputs", type: "object", properties: transactionInputPropertiesSchema, }, //voting procedures { id: "votingProcedure", label: "VotingProcedure", type: "object", properties: [ //voter { id: "voter", label: "Voter", type: "string", properties: [ { id: "committee", label: "Committee", type: "object", properties: [credentialSchema], }, { id: "dRep", label: "DRep", type: "object", properties: [credentialSchema], }, poolKeyHashSchema, ], }, // vote { id: "vote", label: "Vote", type: "number", validator: (arg: number) => { if (arg == 0 || arg == 1 || arg == 2) { return arg; } else { return undefined; } }, }, // proposal Id { id: "proposalId", label: "ProposalId", type: "object", properties: transactionInputPropertiesSchema, }, // anchor anchorSchema, ], }, // proposal procedures { id: "proposalProcedures", label: "ProposalProcedures", type: "object", properties: [ // deposit depositSchema, // reward account StakeAddress.schema("rewardAccount", "RewardAccount"), // anchor anchorSchema, // gov action { id: "govAction", label: "GovAction", type: "object", properties: [ // prevGovActionId { id: "prevGovActionId", label: "PrevGovActionId", type: "object", properties: transactionInputPropertiesSchema, }, // policyHash { id: "policyHash", label: "PolicyHash", type: "string", validator: (arg: string) => { return verifyHash(arg, 28); }, }, // reward account map (for treasury withdrawal) { id: "withdrawalMap", label: "WithdrawalMap", type: "object", properties: [ // reward account StakeAddress.schema("rewardAccount", "RewardAccount"), // amount { id: "amount", label: "Amount", type: "string", validator: (arg: string) => { return verifyBigInt(arg); }, }, ], }, // protocol param update { id: "protocolParameterUpdate", label: "ProtocolParameterUpdate", type: "object", properties: [ { id: "minfeeA", label: "MinFeeA", type: "number", validator: (arg: string) => { return verifyBigInt(arg); }, }, { id: "minfeeB", label: "MinFeeB", type: "number", validator: (arg: string) => { return verifyBigInt(arg); }, }, { id: "maxBlockBodySize", label: "MaxBlockBodySize", type: "number", validator: (arg: string) => { return verifyBigInt(arg); }, }, { id: "maxTransactionSize", label: "MaxTransactionSize", type: "number", validator: (arg: string) => { return verifyBigInt(arg); }, }, { id: "maxBlockHeaderSize", label: "MaxBlockHeaderSize", type: "number", validator: (arg: string) => { return verifyBigInt(arg); }, }, { id: "keyDeposit", label: "KeyDeposit", type: "number", validator: (arg: string) => { return verifyBigInt(arg); }, }, { id: "poolDeposit", label: "poolDeposit", type: "number", validator: (arg: string) => { return verifyBigInt(arg); }, }, { id: "maximumEpoch", label: "MaximumEpoch", type: "number", validator: (arg: string) => { return verifyBigInt(arg); }, }, { id: "desiredStakePools", label: "DesiredStakePools", type: "number", validator: (arg: string) => { return verifyBigInt(arg); }, }, { id: "poolPledgeInfluence", label: "PoolPledgeInfluence", type: "number", validator: (arg: string[]) => { return verifyInterval(arg); }, }, { id: "expansionRate", label: "ExpansionRate", type: "number", validator: (arg: string[]) => { return verifyInterval(arg); }, }, { id: "treasuryGrowthRate", label: "TreasuryGrowthRate", type: "number", validator: (arg: string[]) => { return verifyInterval(arg); }, }, { id: "minPoolCost", label: "MinPoolCost", type: "number", validator: (arg: string) => { return verifyBigInt(arg); }, }, { id: "adaPerUTxOByte", label: "AdaPerUTxOByte", type: "number", validator: (arg: string) => { return verifyBigInt(arg); }, }, { id: "costModels", label: "CostModels", type: "number", validator: (arg: number[]) => { if (arg.length == 166) { return { type: "PlutusV1", costModel: arg }; } else if (arg.length == 175) { return { type: "PlutusV2", costModel: arg }; } else if (arg.length == 233) { return { type: "PlutusV3", costModel: arg }; } else { return { type: "key", costModel: arg }; } }, }, { id: "executionCosts", label: "ExecutionCosts", type: "array", //TODO: VALIDATE properties: [ { id: "memPrice", label: "MemPrice", type: "array", validator: (arg: number[]) => { return verifyInterval(arg); }, }, { id: "stepPrice", label: "StepPrice", type: "array", validator: (arg: number[]) => { return verifyInterval(arg); }, }, ], }, { id: "maxTxExUnits", label: "MaxTxExUnits", type: "array", validator: (arg: number[]) => { return verifyInterval(arg); }, }, { id: "maxBlockExUnits", label: "MaxBlockExUnits", type: "array", validator: (arg: number[]) => { return verifyInterval(arg); }, }, { id: "maxValueSize", label: "MaxValueSize", type: "number", validator: (arg: string) => { return verifyBigInt(arg); }, }, { id: "collateralPercentage", label: "CollateralPercentage", type: "number", validator: (arg: string) => { return verifyBigInt(arg); }, }, { id: "maxCollateralInputs", label: "MaxCollateralInputs", type: "number", validator: (arg: string) => { return verifyBigInt(arg); }, }, { id: "poolVotingThreshold", label: "PoolVotingThreshold", type: "object", properties: [ { id: "motionNoConfidence", label: "MotionNoConfidence", type: "number", validator: (arg: number[]) => { return verifyInterval(arg); }, }, { id: "committeeNormal", label: "CommitteeNormal", type: "number", validator: (arg: number[]) => { return verifyInterval(arg); }, }, { id: "committeeNoConfidence", label: "CommitteeNoConfidence", type: "number", validator: (arg: number[]) => { return verifyInterval(arg); }, }, { id: "hardForkInitiation", label: "HardForkInitiation", type: "number", validator: (arg: number[]) => { return verifyInterval(arg); }, }, { id: "securityThreshold", label: "SecurityThreshold", type: "number", validator: (arg: number[]) => { return verifyInterval(arg); }, }, ], }, { id: "dRepVotingThreshold", label: "DRepVotingThreshold", type: "array", properties: [ { id: "motionNoConfidence", label: "MotionNoConfidence", type: "number", validator: (arg: number[]) => { return verifyInterval(arg); }, }, { id: "committeeNormal", label: "CommitteeNormal", type: "number", validator: (arg: number[]) => { return verifyInterval(arg); }, }, { id: "committeeNoConfidence", label: "CommitteeNoConfidence", type: "number", validator: (arg: number[]) => { return verifyInterval(arg); }, }, { id: "updateConstitution", label: "UpdateConstitution", type: "number", validator: (arg: number[]) => { return verifyInterval(arg); }, }, { id: "hardForkInitiation", label: "HardForkInitiation", type: "number", validator: (arg: number[]) => { return verifyInterval(arg); }, }, { id: "ppNetworkGroup", label: "PPNetworkGroup", type: "number", validator: (arg: number[]) => { return verifyInterval(arg); }, }, { id: "ppEconomicGroup", label: "PPEconomicGroup", type: "number", validator: (arg: number[]) => { return verifyInterval(arg); }, }, { id: "ppTechnicalGroup", label: "PPTechnicalGroup", type: "number", validator: (arg: number[]) => { return verifyInterval(arg); }, }, { id: "ppGovernanceGroup", label: "PPGovernanceGroup", type: "number", validator: (arg: number[]) => { return verifyInterval(arg); }, }, { id: "treasuryWithdrawal", label: "TreasuryWithdrawal", type: "number", validator: (arg: number[]) => { return verifyInterval(arg); }, }, ], }, { id: "minCommitteeSize", label: "MinCommitteeSize", type: "number", validator: (arg: string) => { return verifyBigInt(arg); }, }, { id: "committeeTermLimit", label: "CommitteeTermLimit", type: "bigint", validator: (arg: string) => { return verifyBigInt(arg); }, }, { id: "govActionValidityPeriod", label: "GovActionValidityPeriod", type: "number", validator: (arg: string) => { return verifyBigInt(arg); }, }, { id: "govActionDeposit", label: "GovActionDeposit", type: "number", validator: (arg: string) => { return verifyBigInt(arg); }, }, { id: "dRepDeposit", label: "DRepDeposit", type: "bigint", validator: (arg: string) => { return verifyBigInt(arg); }, }, { id: "dRepInactivityPeriod", label: "DRepInactivityPeriod", type: "bigint", validator: (arg: string) => { return verifyBigInt(arg); }, }, { id: "minFeeReferenceScriptCostPerByte", label: "MinFeeReferenceScriptCostPerByte", type: "number", validator: (arg: string[]) => { return verifyInterval(arg); }, }, ], }, // protocol version (for hardfork) { id: "protocolVersion", label: "ProtocolVersion", type: "object", properties: [ // major protocol version { id: "majorProtocolVersion", label: "MajorProtocolVersion", type: "string", validator: (arg: string) => { const validMajorProtocolVersions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]; try { if (validMajorProtocolVersions.includes(parseInt(arg))) { return arg; } else { return undefined; } } catch (error: any) { return undefined; } }, }, // minor protocol version { id: "minorProtocolVersion", label: "MinorProtocolVersion", type: "number", validator: (arg: string) => { try { const parsedIntMinorProtocolVersion = parseInt(arg); if (!isNaN(parsedIntMinorProtocolVersion) && parsedIntMinorProtocolVersion.toString() == arg) { return arg; } else { return undefined; } } catch (error: any) { return undefined; } }, }, ], }, // committee cold creds (for update committee action) { id: "committeeColdCredential", label: "CommitteeColdCredential", type: "string", properties: keyAndScriptCredentialSchema, }, // credential-epoch map (udpate committee action) { id: "committeeColdCredentialEpochMap", label: "CommitteeColdCredentialEpochMap", type: "object", properties: [ // CC cold credential { id: "committeeColdCredential", label: "CommitteeColdCredential", type: "string", properties: keyAndScriptCredentialSchema, }, // epoch epochSchema, ], }, // epochInterval { id: "epochInterval", label: "EpochInterval", type: "array", validator: (arg: string[]) => { return verifyInterval(arg); }, }, // constitution (for update constitution) { id: "constitution", label: "Constitution", type: "object", properties: [ // anchor anchorSchema, // guardrail script hash { id: "scriptHash", label: "ScriptHash", type: "string", validator: (arg: string) => { return verifyHash(arg, 28); }, }, ], }, // info action { id: "info", label: "Info", type: "string", validator: (arg: string) => { const parsedInfo = parseInt(arg); if (!isNaN(parsedInfo) && parsedInfo == 6) { return arg; } else { return undefined; } }, }, ], }, ], }, // current treasury value { id: "currentTreasuryValue", label: "CurrentTreasuryValue", type: "bigint", validator: (arg: string) => { return verifyBigInt(arg); }, }, // donation { id: "donation", label: "Donation", type: "bigint", validator: (arg: string) => { return verifyBigInt(arg); }, }, ], }, ]; const verifyBigInt = (arg: string | number) => { try { const parsedBigInt = BigInt(arg); return parsedBigInt; } catch (error: any) { return undefined; } }; const verifyHash = (arg: string, length: number) => { if (hexPattern.test(arg) && arg.length == length * 2) { return arg; } else { return undefined; } }; const verifyKeyDRepHex = (arg: string) => { if (hexPattern.test(arg)) { if (arg.length == 56) { return "22" + arg; } else if (arg.length == 58) { if (arg.slice(0, 2) == "22") { return arg; } else { return undefined; } } else { return undefined; } } return undefined; }; const verifyKeyDRep = (arg: string) => { try { // check if arg is hex and return arg with prefix if valid const isValidDrepHex = verifyKeyDRepHex(arg); if (isValidDrepHex) { return new KeyDRep(Buffer.from(isValidDrepHex, "hex")); } // if arg is bech32, check prefix: "drep" and return keyDrep hex with prefix 22 if valid const decodedBech32 = bech32.decode(arg); if (decodedBech32.prefix == "drep") { const key = verifyKeyDRepHex(decodedBech32.data.toString("hex")); if (key) { return new KeyDRep(Buffer.from(key, "hex")); } else { return undefined; } } else { // if bech32 has incorrect prefix, return undefined return undefined; } } catch (error: any) { // if bech32 decoding fails, return undefined return undefined; } }; const veryfyScriptDRepHex = (arg: string) => { if (hexPattern.test(arg)) { if (arg.length == 56) { return "23" + arg; } else if (arg.length == 58) { if (arg.slice(0, 2) == "23") { return arg; } else { return undefined; } } else { return undefined; } } return undefined; }; const verifyScriptDRep = (arg: string) => { try { // check if arg is hex and return arg with prefix if valid const isValidDrepHex = veryfyScriptDRepHex(arg); if (isValidDrepHex) { return new ScriptDRep(Buffer.from(isValidDrepHex, "hex")); } // if arg is bech32, check prefix: "drep" and return keyDrep hex with prefix 23 if valid const decodedBech32 = bech32.decode(arg); if (decodedBech32.prefix == "drep") { const key = veryfyScriptDRepHex(decodedBech32.data.toString("hex")); if (key) { return new ScriptDRep(Buffer.from(key, "hex")); } else { return undefined; } } else { // if prefix is not "drep", return undefined return undefined; } } catch (error: any) { // if bech32 decoding fails, return undefined return undefined; } }; const verifyInterval = (arg: (string | number)[]) => { if (arg.length == 2 && verifyBigInt(arg[0]) && verifyBigInt(arg[1])) { return arg; } else { return undefined; } };