Skip to content

Commit

Permalink
Add new snap metadata (#49)
Browse files Browse the repository at this point in the history
* Add new snap metadata

The added metadata will be visible to users when they're adding a new
snap account. All the newly introduced fields are optional, as they
might not be necessary for other types of snaps.

* Rename `reports` to `audits`

Co-authored-by: Frederik Bolding <[email protected]>

* Add `support` and `sourceCode` fields

---------

Co-authored-by: Frederik Bolding <[email protected]>
  • Loading branch information
danroc and FrederikBolding authored Sep 4, 2023
1 parent 3a2374f commit b201e67
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
union,
optional,
Infer,
enums,
} from 'superstruct';

const VerifiedSnapVersionStruct = object({
Expand All @@ -21,6 +22,15 @@ export const VerifiedSnapStruct = object({
id: string(),
metadata: object({
name: string(),
type: optional(enums(['account'])),
author: optional(string()),
website: optional(string()),
summary: optional(string()),
description: optional(string()),
audits: optional(array(string())),
tags: optional(array(string())),
support: optional(string()),
sourceCode: optional(string()),
}),
versions: record(VersionStruct, VerifiedSnapVersionStruct),
});
Expand Down
108 changes: 108 additions & 0 deletions src/registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,112 @@ describe('Snaps Registry', () => {
it('has valid format', () => {
expect(() => assert(registry, SnapsRegistryDatabaseStruct)).not.toThrow();
});

it('has a valid account snap', () => {
/* eslint-disable @typescript-eslint/naming-convention */
const registryDb = {
verifiedSnaps: {
'npm:example-snap': {
id: 'npm:example-snap',
metadata: {
name: 'Example Snap',
type: 'account',
author: 'Example Author',
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',
],
support: 'https://metamask.io/example/support',
sourceCode: 'https://metamask.io/example/source-code',
tags: ['accounts', 'example'],
},
versions: {
'0.1.0': {
checksum: 'A83r5/ZIcKeKw3An13HBeV4CAofj7jGK5hOStmHY6A0=',
},
},
},
},
blockedSnaps: [
{
id: 'npm:example-blocked-snap',
versionRange: '^0.1.0',
reason: {
explanation: 'Example explanation',
url: 'https://metamask.io/example/explanation',
},
},
{
checksum: 'B3ar53ZIcKeKw3An3aqBeV4CAofj7jGK5hOAAxQY6A0=',
reason: {
explanation: 'Example explanation',
url: 'https://metamask.io/example/explanation',
},
},
],
};
/* eslint-enable @typescript-eslint/naming-convention */

expect(() => assert(registryDb, SnapsRegistryDatabaseStruct)).not.toThrow();
});

it('has a only mandatory fields', () => {
/* eslint-disable @typescript-eslint/naming-convention */
const registryDb = {
verifiedSnaps: {
'npm:example-snap': {
id: 'npm:example-snap',
metadata: {
name: 'Example Snap',
},
versions: {
'0.1.0': {
checksum: 'A83r5/ZIcKeKw3An13HBeV4CAofj7jGK5hOStmHY6A0=',
},
},
},
},
blockedSnaps: [
{
id: 'npm:example-blocked-snap',
versionRange: '^0.1.0',
},
{
checksum: 'B3ar53ZIcKeKw3An3aqBeV4CAofj7jGK5hOAAxQY6A0=',
},
],
};
/* eslint-enable @typescript-eslint/naming-convention */

expect(() => assert(registryDb, SnapsRegistryDatabaseStruct)).not.toThrow();
});

it('should throw when the metadata has an unexpected field', () => {
/* eslint-disable @typescript-eslint/naming-convention */
const registryDb = {
verifiedSnaps: {
'npm:example-snap': {
id: 'npm:example-snap',
metadata: {
name: 'Example Snap',
unexpected: 'field',
},
versions: {
'0.1.0': {
checksum: 'A83r5/ZIcKeKw3An13HBeV4CAofj7jGK5hOStmHY6A0=',
},
},
},
},
blockedSnaps: [],
};
/* eslint-enable @typescript-eslint/naming-convention */

expect(() => assert(registryDb, SnapsRegistryDatabaseStruct)).toThrow(
'At path: verifiedSnaps.npm:example-snap.metadata.unexpected -- Expected a value of type `never`, but received: `"field"`',
);
});
});

0 comments on commit b201e67

Please sign in to comment.