diff --git a/src/rpc-handler.test.ts b/src/rpc-handler.test.ts index c64fd0472..b467fbd29 100644 --- a/src/rpc-handler.test.ts +++ b/src/rpc-handler.test.ts @@ -77,7 +77,7 @@ describe('keyringRpcDispatcher', () => { }; await expect(handleKeyringRequest(keyring, request)).rejects.toThrow( - 'At path: params.id -- Expected a string, but received: undefined', + 'At path: params.id -- Expected a value of type `UuidV4`, but received: `undefined`', ); }); diff --git a/src/utils.ts b/src/utils.ts index 593f59025..75d22dd4d 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,12 +1,15 @@ -import { assert, pattern, string } from 'superstruct'; +import { assert, define } from 'superstruct'; import type { Struct } from 'superstruct'; +const UUID_V4_REGEX = + /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu; + /** * UUIDv4 struct. */ -export const UuidStruct = pattern( - string(), - /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu, +export const UuidStruct = define( + 'UuidV4', + (id: unknown): boolean => typeof id === 'string' && UUID_V4_REGEX.test(id), ); /**