-
Notifications
You must be signed in to change notification settings - Fork 542
/
types.ts
76 lines (64 loc) · 1.81 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { SnapExports } from '@metamask/snap-types';
import { Json } from '@metamask/utils';
import { NpmSnapPackageJson, SnapManifest } from './json-schemas';
/**
* An object for storing parsed but unvalidated Snap file contents.
*/
export type UnvalidatedSnapFiles = {
manifest?: Json;
packageJson?: Json;
sourceCode?: string;
svgIcon?: string;
};
/**
* An object for storing the contents of Snap files that have passed JSON
* Schema validation, or are non-empty if they are strings.
*/
export type SnapFiles = {
manifest: SnapManifest;
packageJson: NpmSnapPackageJson;
sourceCode: string;
svgIcon?: string;
};
/**
* The possible prefixes for snap ids.
*/
export enum SnapIdPrefixes {
npm = 'npm:',
local = 'local:',
}
export type SnapId = string;
export enum NpmSnapFileNames {
PackageJson = 'package.json',
Manifest = 'snap.manifest.json',
}
/**
* Snap validation failure reason codes that are programmatically fixable
* if validation occurs during development.
*/
export enum SnapValidationFailureReason {
NameMismatch = '"name" field mismatch',
VersionMismatch = '"version" field mismatch',
RepositoryMismatch = '"repository" field mismatch',
ShasumMismatch = '"shasum" field mismatch',
}
export enum SNAP_STREAM_NAMES {
JSON_RPC = 'jsonRpc',
COMMAND = 'command',
}
export enum HandlerType {
OnRpcRequest = 'onRpcRequest',
OnTransaction = 'onTransaction',
OnCronjob = 'onCronjob',
}
export type SnapRpcHookArgs = {
origin: string;
handler: HandlerType;
request: Record<string, unknown>;
};
// The snap is the callee
export type SnapRpcHook = (options: SnapRpcHookArgs) => Promise<unknown>;
type ObjectParameters<
Type extends Record<string, (...args: any[]) => unknown>,
> = Parameters<Type[keyof Type]>;
export type SnapExportsParameters = ObjectParameters<SnapExports>;