From a5648da6f254f39630feabd43ef0c59963fa0c91 Mon Sep 17 00:00:00 2001 From: Tom Meagher Date: Tue, 20 Aug 2024 17:21:51 -0400 Subject: [PATCH] chore: tweaks --- site/vocs.config.tsx | 54 +++++++++++++------------- src/Siwe.test.ts | 18 +++++++++ src/Siwe.ts | 2 + src/internal/siwe/createSiweMessage.ts | 2 +- src/internal/{ => siwe}/isUri.test.ts | 0 src/internal/{ => siwe}/isUri.ts | 18 +++++++-- 6 files changed, 63 insertions(+), 31 deletions(-) create mode 100644 src/Siwe.test.ts rename src/internal/{ => siwe}/isUri.test.ts (100%) rename src/internal/{ => siwe}/isUri.ts (83%) diff --git a/site/vocs.config.tsx b/site/vocs.config.tsx index 342b0171..f1a58e99 100644 --- a/site/vocs.config.tsx +++ b/site/vocs.config.tsx @@ -413,33 +413,33 @@ export default defineConfig({ }, ], }, - // { - // text: 'Siwe (ERC-4361) 🚧', - // collapsed: true, - // link: '/api/siwe', - // items: [ - // { - // text: '.createMessage', - // link: '/api/siwe/createMessage', - // }, - // { - // text: '.generateNonce', - // link: '/api/siwe/generateNonce', - // }, - // { - // text: '.isUri', - // link: '/api/siwe/isUri', - // }, - // { - // text: '.parseMessage', - // link: '/api/siwe/parseMessage', - // }, - // { - // text: '.validateMessage', - // link: '/api/siwe/validateMessage', - // }, - // ], - // }, + { + text: 'Siwe (ERC-4361) 🚧', + collapsed: true, + link: '/api/siwe', + items: [ + { + text: '.createMessage', + link: '/api/siwe/createMessage', + }, + { + text: '.generateNonce', + link: '/api/siwe/generateNonce', + }, + { + text: '.isUri', + link: '/api/siwe/isUri', + }, + { + text: '.parseMessage', + link: '/api/siwe/parseMessage', + }, + { + text: '.validateMessage', + link: '/api/siwe/validateMessage', + }, + ], + }, { text: 'Transaction 🚧', collapsed: true, diff --git a/src/Siwe.test.ts b/src/Siwe.test.ts new file mode 100644 index 00000000..e57e3da3 --- /dev/null +++ b/src/Siwe.test.ts @@ -0,0 +1,18 @@ +import { expect, test } from 'vitest' +import * as exports from './Siwe.js' + +test('exports', () => { + expect(Object.keys(exports)).toMatchInlineSnapshot(` + [ + "createMessage", + "createSiweMessage", + "generateNonce", + "generateSiweNonce", + "isUri", + "parseMessage", + "parseSiweMessage", + "validateMessage", + "validateSiweMessage", + ] + `) +}) diff --git a/src/Siwe.ts b/src/Siwe.ts index 94ec54ce..5ce17488 100644 --- a/src/Siwe.ts +++ b/src/Siwe.ts @@ -8,6 +8,8 @@ export { generateSiweNonce, } from './internal/siwe/generateSiweNonce.js' +export { isUri } from './internal/siwe/isUri.js' + export { parseSiweMessage as parseMessage, parseSiweMessage, diff --git a/src/internal/siwe/createSiweMessage.ts b/src/internal/siwe/createSiweMessage.ts index 98b2ceb9..d1bcd698 100644 --- a/src/internal/siwe/createSiweMessage.ts +++ b/src/internal/siwe/createSiweMessage.ts @@ -1,7 +1,7 @@ import type { GlobalErrorType } from 'src/Errors.js' import { toAddress } from '../address/from.js' import { SiweInvalidMessageFieldError } from '../errors/siwe.js' -import { isUri } from '../isUri.js' +import { isUri } from './isUri.js' import type { SiweMessage } from '../types/siwe.js' /** diff --git a/src/internal/isUri.test.ts b/src/internal/siwe/isUri.test.ts similarity index 100% rename from src/internal/isUri.test.ts rename to src/internal/siwe/isUri.test.ts diff --git a/src/internal/isUri.ts b/src/internal/siwe/isUri.ts similarity index 83% rename from src/internal/isUri.ts rename to src/internal/siwe/isUri.ts index 4792d2e4..2b324a30 100644 --- a/src/internal/isUri.ts +++ b/src/internal/siwe/isUri.ts @@ -1,7 +1,19 @@ -/** @internal */ -export function isUri(value: string) { - // based on https://github.com/ogt/valid-url +// based on https://github.com/ogt/valid-url + +/** + * Check if the given URI is a valid URI. + * + * - Docs: https://oxlib.sh/api/siwe/isUri + * - Spec: https://www.rfc-editor.org/rfc/rfc3986 + * + * @example + * import { Siwe } from 'ox' + * + * Siwe.isUri('https://example.com/foo') + * // true + */ +export function isUri(value: string) { // check for illegal characters if (/[^a-z0-9\:\/\?\#\[\]\@\!\$\&\'\(\)\*\+\,\;\=\.\-\_\~\%]/i.test(value)) return false