diff --git a/src/index.ts b/src/index.ts index 1b0cabe1..fd6887d6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -24,16 +24,30 @@ const VerifiedSnapVersionStruct = object({ checksum: ChecksumStruct, }); +export const AuthorStruct = object({ + name: string(), + website: string(), +}); + +export type Author = Infer; + +export const AuditStruct = object({ + auditor: string(), + report: string(), +}); + +export type Audit = Infer; + export const VerifiedSnapStruct = object({ id: NpmIdStruct, metadata: object({ name: string(), type: optional(enums(['account'])), - author: optional(string()), + author: optional(AuthorStruct), website: optional(string()), summary: optional(string()), description: optional(string()), - audits: optional(array(string())), + audits: optional(array(AuditStruct)), tags: optional(array(string())), support: optional(string()), sourceCode: optional(string()), diff --git a/src/registry.test.ts b/src/registry.test.ts index 70461509..776e454a 100644 --- a/src/registry.test.ts +++ b/src/registry.test.ts @@ -1,5 +1,7 @@ +import type { SemVerRange, SemVerVersion } from '@metamask/utils'; import { assert } from 'superstruct'; +import type { SnapsRegistryDatabase } from '.'; import { SnapsRegistryDatabaseStruct } from '.'; import registry from './registry.json'; @@ -10,27 +12,36 @@ describe('Snaps Registry', () => { it('has a valid account snap', () => { /* eslint-disable @typescript-eslint/naming-convention */ - const registryDb = { + const registryDb: SnapsRegistryDatabase = { verifiedSnaps: { 'npm:example-snap': { id: 'npm:example-snap', metadata: { name: 'Example Snap', type: 'account', - author: 'Example Author', + author: { + name: 'MetaMask', + website: 'https://metamask.io', + }, website: 'https://metamask.io', summary: 'Example Snap', description: 'Longer Example Snap description.', audits: [ - 'https://metamask.io/example/report-1.pdf', - 'https://metamask.io/example/report-2.pdf', + { + auditor: 'Example Auditor', + report: 'https://metamask.io/example/report-1.pdf', + }, + { + auditor: 'Example Auditor', + report: 'https://metamask.io/example/report-2.pdf', + }, ], support: 'https://metamask.io/example/support', sourceCode: 'https://metamask.io/example/source-code', tags: ['accounts', 'example'], }, versions: { - '0.1.0': { + ['0.1.0' as SemVerVersion]: { checksum: 'A83r5/ZIcKeKw3An13HBeV4CAofj7jGK5hOStmHY6A0=', }, }, @@ -39,7 +50,7 @@ describe('Snaps Registry', () => { blockedSnaps: [ { id: 'npm:example-blocked-snap', - versionRange: '^0.1.0', + versionRange: '^0.1.0' as SemVerRange, reason: { explanation: 'Example explanation', url: 'https://metamask.io/example/explanation', @@ -61,7 +72,7 @@ describe('Snaps Registry', () => { it('has a only mandatory fields', () => { /* eslint-disable @typescript-eslint/naming-convention */ - const registryDb = { + const registryDb: SnapsRegistryDatabase = { verifiedSnaps: { 'npm:example-snap': { id: 'npm:example-snap', @@ -69,7 +80,7 @@ describe('Snaps Registry', () => { name: 'Example Snap', }, versions: { - '0.1.0': { + ['0.1.0' as SemVerVersion]: { checksum: 'A83r5/ZIcKeKw3An13HBeV4CAofj7jGK5hOStmHY6A0=', }, }, @@ -78,7 +89,7 @@ describe('Snaps Registry', () => { blockedSnaps: [ { id: 'npm:example-blocked-snap', - versionRange: '^0.1.0', + versionRange: '^0.1.0' as SemVerRange, }, { checksum: 'B3ar53ZIcKeKw3An3aqBeV4CAofj7jGK5hOAAxQY6A0=', @@ -91,17 +102,17 @@ describe('Snaps Registry', () => { }); it('should throw when the metadata has an unexpected field', () => { - /* eslint-disable @typescript-eslint/naming-convention */ - const registryDb = { + const registryDb: SnapsRegistryDatabase = { verifiedSnaps: { 'npm:example-snap': { id: 'npm:example-snap', metadata: { name: 'Example Snap', + // @ts-expect-error - Unexpected field. unexpected: 'field', }, versions: { - '0.1.0': { + ['0.1.0' as SemVerVersion]: { checksum: 'A83r5/ZIcKeKw3An13HBeV4CAofj7jGK5hOStmHY6A0=', }, },