@@ -3,8 +3,11 @@ import { isAddress } from "viem";
3
3
import { normalize } from "viem/ens" ;
4
4
5
5
const isHexAddress = ( str : string ) : boolean => / ^ 0 x [ a - f A - F 0 - 9 ] { 40 } $ / . test ( str ) ;
6
-
7
6
const isHexId = ( str : string ) : boolean => / ^ 0 x [ a - f A - F 0 - 9 ] { 1 , 64 } $ / . test ( str ) ;
7
+ const isMultiaddr = ( str : string ) : boolean =>
8
+ / ^ \/ (?: i p 4 | i p 6 | d n s 4 | d n s 6 | d n s a d d r | t c p | u d p | u t p | t l s | w s | w s s | i p f s | p 2 p - c i r c u i t | p 2 p - w e b r t c - s t a r | p 2 p - w e b r t c - d i r e c t | p 2 p - w e b s o c k e t - s t a r | o n i o n ) ( \/ [ ^ \s \/ ] + ) * $ / . test (
9
+ str
10
+ ) ;
8
11
9
12
export const ethAddressSchema = z . string ( ) . refine ( ( value ) => isAddress ( value ) , {
10
13
message : "Provided address is invalid." ,
@@ -33,7 +36,7 @@ export const AnswerSchema = z.object({
33
36
id : z
34
37
. string ( )
35
38
. regex ( / ^ 0 x [ 0 - 9 a - f A - F ] + $ / )
36
- . optional ( ) , // should be a bigint
39
+ . optional ( ) ,
37
40
title : z . string ( ) ,
38
41
description : z . string ( ) ,
39
42
reserved : z . boolean ( ) . optional ( ) ,
@@ -53,12 +56,14 @@ const DisputeDetailsSchema = z.object({
53
56
description : z . string ( ) ,
54
57
question : z . string ( ) ,
55
58
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
+ } ) ,
57
62
attachment : AttachmentSchema . optional ( ) ,
58
63
frontendUrl : z . string ( ) . optional ( ) ,
59
64
metadata : MetadataSchema . optional ( ) ,
60
65
arbitratorChainID : z . string ( ) ,
61
- arbitratorAddress : z . string ( ) , // should be changed for ethAddressSchema eventually, but some
66
+ arbitratorAddress : ethAddressSchema ,
62
67
category : z . string ( ) . optional ( ) ,
63
68
lang : z . string ( ) . optional ( ) ,
64
69
specification : z . string ( ) . optional ( ) ,
0 commit comments