@@ -18,9 +18,41 @@ import {
18
18
import { isAddress , toHex } from "viem"
19
19
import { AddressCanonicalBytes } from "./schema/address.js"
20
20
import { Hex , HexFromString } from "./schema/hex.js"
21
+ import { isValidSuiAddress , normalizeSuiAddress } from "@mysten/sui/utils"
21
22
22
23
// const AddressFromChain = (chain: Chain) =>
23
24
25
+
26
+ /**
27
+ * @category models
28
+ * @since 2.0.0
29
+ */
30
+ export const SuiAddress = S . NonEmptyString . pipe (
31
+ S . filter ( ( a ) => isValidSuiAddress ( a ) , {
32
+ description :
33
+ "Sui address (32-byte hex). Accepts with/without 0x; even length; hex only." ,
34
+ } ) ,
35
+ )
36
+ /**
37
+ * @category models
38
+ * @since 2.0.0
39
+ */
40
+ export type SuiAddress = typeof SuiAddress . Type
41
+
42
+ /**
43
+ * @category models
44
+ * @since 2.0.0
45
+ */
46
+ export const SuiDisplay = S . Struct ( {
47
+ _tag : S . tag ( "SuiDisplay" ) ,
48
+ address : SuiAddress ,
49
+ } )
50
+ /**
51
+ * @category models
52
+ * @since 2.0.0
53
+ */
54
+ export type SuiDisplay = typeof SuiDisplay . Type
55
+
24
56
/**
25
57
* @category models
26
58
* @since 2.0.0
@@ -209,6 +241,7 @@ export type CosmosDisplay = typeof CosmosDisplay.Type
209
241
export const AnyDisplay = S . Union (
210
242
CosmosDisplay ,
211
243
EvmDisplay ,
244
+ SuiDisplay ,
212
245
)
213
246
/**
214
247
* @category models
@@ -229,6 +262,7 @@ export const AnyDisplayFromString = S.transformOrFail(
229
262
Effect . raceAll ( [
230
263
S . decodeUnknownEither ( EvmDisplay ) ( { _tag : "EvmDisplay" , address } ) ,
231
264
S . decodeUnknownEither ( CosmosDisplay ) ( { _tag : "CosmosDisplay" , address } ) ,
265
+ S . decodeUnknownEither ( SuiDisplay ) ( { _tag : "SuiDisplay" , address } ) ,
232
266
] ) ,
233
267
Effect . catchTag ( "ParseError" , ( error ) => ParseResult . fail ( error . issue ) ) ,
234
268
) ,
@@ -266,6 +300,7 @@ export const ZkgmFromAnyDisplay = S.transform(
266
300
Match . tagsExhaustive ( {
267
301
CosmosDisplay : ( { address } ) => toHex ( address ) ,
268
302
EvmDisplay : ( { address } ) => identity < Hex > ( address ) ,
303
+ SuiDisplay : ( { address } ) => identity < Hex > ( normalizeSuiAddress ( address ) as Hex )
269
304
} ) ,
270
305
) ,
271
306
encode : ( _ ) => absurd < AnyDisplay > ( void 0 as never ) ,
@@ -280,6 +315,7 @@ export const anyDisplayToZkgm = Match.type<AnyDisplay>().pipe(
280
315
Match . tagsExhaustive ( {
281
316
CosmosDisplay : ( { address } ) => S . decode ( HexFromString ) ( address ) ,
282
317
EvmDisplay : ( { address } ) => Effect . succeed < Hex > ( address ) ,
318
+ SuiDisplay : ( { address } ) => S . decode ( HexFromString ) ( normalizeSuiAddress ( address ) ) ,
283
319
} ) ,
284
320
)
285
321
@@ -298,6 +334,7 @@ export const anyDisplayToCanonical = Match.type<AnyDisplay>().pipe(
298
334
console . log ( "bytes" , { result } )
299
335
} ,
300
336
EvmDisplay : ( { address } ) => AddressCanonicalBytes . make ( address ) ,
337
+ SuiDisplay : ( { address } ) => AddressCanonicalBytes . make ( normalizeSuiAddress ( address ) )
301
338
} ) ,
302
339
)
303
340
/**
@@ -306,7 +343,7 @@ export const anyDisplayToCanonical = Match.type<AnyDisplay>().pipe(
306
343
* @category models
307
344
* @since 2.0.0
308
345
*/
309
- export const ValidAddress = S . Union ( ERC55 , Bech32 )
346
+ export const ValidAddress = S . Union ( ERC55 , Bech32 , SuiAddress )
310
347
/**
311
348
* @category models
312
349
* @since 2.0.0
0 commit comments