Skip to content

Commit 586c4c1

Browse files
committed
feat: multiaddr check for policy-uri, arbitratoraddress as ethaddressschema
1 parent 6c28d00 commit 586c4c1

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

kleros-sdk/src/dataMappings/utils/disputeDetailsSchema.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ import { isAddress } from "viem";
33
import { normalize } from "viem/ens";
44

55
const isHexAddress = (str: string): boolean => /^0x[a-fA-F0-9]{40}$/.test(str);
6-
76
const isHexId = (str: string): boolean => /^0x[a-fA-F0-9]{1,64}$/.test(str);
7+
const isMultiaddr = (str: string): boolean =>
8+
/^\/(?:ip4|ip6|dns4|dns6|dnsaddr|tcp|udp|utp|tls|ws|wss|ipfs|p2p-circuit|p2p-webrtc-star|p2p-webrtc-direct|p2p-websocket-star|onion)(\/[^\s\/]+)*$/.test(
9+
str
10+
);
811

912
export const ethAddressSchema = z.string().refine((value) => isAddress(value), {
1013
message: "Provided address is invalid.",
@@ -33,7 +36,7 @@ export const AnswerSchema = z.object({
3336
id: z
3437
.string()
3538
.regex(/^0x[0-9a-fA-F]+$/)
36-
.optional(), // should be a bigint
39+
.optional(),
3740
title: z.string(),
3841
description: z.string(),
3942
reserved: z.boolean().optional(),
@@ -53,12 +56,14 @@ const DisputeDetailsSchema = z.object({
5356
description: z.string(),
5457
question: z.string(),
5558
answers: z.array(AnswerSchema),
56-
policyURI: z.string(),
59+
policyURI: z.string().refine((value) => isMultiaddr(value), {
60+
message: "Provided policy URI is not a valid multiaddr.",
61+
}),
5762
attachment: AttachmentSchema.optional(),
5863
frontendUrl: z.string().optional(),
5964
metadata: MetadataSchema.optional(),
6065
arbitratorChainID: z.string(),
61-
arbitratorAddress: z.string(), // should be changed for ethAddressSchema eventually, but some
66+
arbitratorAddress: ethAddressSchema,
6267
category: z.string().optional(),
6368
lang: z.string().optional(),
6469
specification: z.string().optional(),

0 commit comments

Comments
 (0)