-
Notifications
You must be signed in to change notification settings - Fork 479
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
100 additions
and
89 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
apps/gui/src/lib/components/partials/relay-single/RelayNip11.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<script lang="ts"> | ||
import { Nip11 } from '@nostrwatch/nip66/models'; | ||
import { onMount } from 'svelte'; | ||
import { derived, writable, type Readable, type Writable } from 'svelte/store'; | ||
import { SchemaValidationService, type SchemaValidationServiceResponse } from '$lib/services/SchemaValidationService'; | ||
export let nip11: Writable<Nip11> | ||
const schemaValidationService = new SchemaValidationService(); | ||
const validationResult: Writable<SchemaValidationServiceResponse | null> = writable(null); | ||
const nip11Valid: Readable<boolean> = derived(validationResult, $validationResult => { | ||
return $validationResult?.status === 'success' && $validationResult?.result?.valid === true; | ||
}); | ||
onMount(() => { | ||
schemaValidationService.validateNip11($nip11?.json, $nip11?.hash).then( (result: SchemaValidationServiceResponse) => { | ||
validationResult.set(result); | ||
}) | ||
}); | ||
</script> | ||
|
||
{#if $nip11Valid} | ||
<div class="bg-green-500 text-white p-4 rounded-lg"> | ||
<p class="text-lg font-bold">NIP-11 has no issues</p> | ||
</div> | ||
{:else} | ||
<div class="bg-red-500 text-white p-4 rounded-lg"> | ||
<p class="text-lg font-bold">NIP-11 requires attentions</p> | ||
</div> | ||
{/if} | ||
|
||
{#if $validationResult} | ||
<pre class="py-6 px-8 bg-white/5 rounded-lg">{JSON.stringify($validationResult, null, 4)}</pre> | ||
{/if} | ||
|
||
<pre class="py-6 px-8 bg-white/5 rounded-lg">{JSON.stringify($nip11?.json, null, 4)}</pre> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 36 additions & 37 deletions
73
apps/gui/src/lib/services/SchemaValidationService/schemavalidation.worker.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,41 @@ | ||
import { deterministicHash } from '@nostrwatch/nip66/utils/hash'; | ||
import { type SchemaValidatorResult } from '@nostrwatch/schemata-js-ajv' | ||
import { deterministicHash } from '@nostrwatch/nip66/utils'; | ||
import { validateNip11, validateMessage, validateNote, type SchemaValidatorResult } from '@nostrwatch/schemata-js-ajv' | ||
|
||
self.onmessage = ({ data }) => { | ||
import('@nostrwatch/schemata-js-ajv').then( ({validateNip11, validateMessage, validateNote}) => { | ||
const { json, type, subject, slug } = data as any; | ||
let { hash } = data as any; | ||
let result: SchemaValidatorResult; | ||
let error: string = ''; | ||
if(!hash) { | ||
hash = deterministicHash(json) | ||
console.log('schema validation worker recieved data', data) | ||
const { json, type, subject, slug } = data as any; | ||
let { hash } = data as any; | ||
let result: SchemaValidatorResult; | ||
let error: string = ''; | ||
if(!hash) { | ||
hash = deterministicHash(json) | ||
} | ||
if(type === 'nip11') { | ||
result = validateNip11(json) | ||
} | ||
else if(type === 'message') { | ||
if(subject && slug) { | ||
result = validateMessage(json, subject, slug) | ||
} | ||
if(type === 'nip11') { | ||
result = validateNip11(json) | ||
else { | ||
error = 'Both subject and slug are required for message validation (for example subject as "relay" and slug as "ok" for the NIP-01 "OK" message.)' | ||
} | ||
else if(type === 'message') { | ||
if(subject && slug) { | ||
result = validateMessage(json, subject, slug) | ||
} | ||
else { | ||
error = 'Both subject and slug are required for message validation (for example subject "relay" and slug "ok"' | ||
} | ||
} | ||
else if(type === 'note') { | ||
result = validateNote(json) | ||
} | ||
if(result) { | ||
self.postMessage({ | ||
status: 'success', | ||
hash, | ||
result | ||
}) | ||
} | ||
else if(error){ | ||
self.postMessage({ | ||
status: 'error', | ||
hash, | ||
error | ||
}) | ||
} | ||
}); | ||
} | ||
else if(type === 'note') { | ||
result = validateNote(json) | ||
} | ||
if(result) { | ||
self.postMessage({ | ||
status: 'success', | ||
hash, | ||
result | ||
}) | ||
} | ||
else if(error){ | ||
self.postMessage({ | ||
status: 'error', | ||
hash, | ||
error | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters