@metamask/snaps-utils 3.0.0 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -1
- package/dist/cjs/auxiliary-files.js +40 -0
- package/dist/cjs/auxiliary-files.js.map +1 -0
- package/dist/cjs/errors.js +353 -3
- package/dist/cjs/errors.js.map +1 -1
- package/dist/cjs/eval-worker.js +2 -2
- package/dist/cjs/eval-worker.js.map +1 -1
- package/dist/cjs/handler-types.js +31 -0
- package/dist/cjs/handler-types.js.map +1 -0
- package/dist/cjs/handlers.js +24 -27
- package/dist/cjs/handlers.js.map +1 -1
- package/dist/cjs/index.browser.js +2 -0
- package/dist/cjs/index.browser.js.map +1 -1
- package/dist/cjs/index.executionenv.js +2 -0
- package/dist/cjs/index.executionenv.js.map +1 -1
- package/dist/cjs/index.js +9 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/manifest/manifest.js +25 -5
- package/dist/cjs/manifest/manifest.js.map +1 -1
- package/dist/cjs/manifest/validation.js +6 -1
- package/dist/cjs/manifest/validation.js.map +1 -1
- package/dist/cjs/npm.js +5 -3
- package/dist/cjs/npm.js.map +1 -1
- package/dist/cjs/snaps.js +3 -2
- package/dist/cjs/snaps.js.map +1 -1
- package/dist/cjs/types.js +0 -5
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/validation.js.map +1 -1
- package/dist/cjs/virtual-file/VirtualFile.js +6 -0
- package/dist/cjs/virtual-file/VirtualFile.js.map +1 -1
- package/dist/esm/auxiliary-files.js +28 -0
- package/dist/esm/auxiliary-files.js.map +1 -0
- package/dist/esm/errors.js +350 -1
- package/dist/esm/errors.js.map +1 -1
- package/dist/esm/eval-worker.js +1 -1
- package/dist/esm/eval-worker.js.map +1 -1
- package/dist/esm/handler-types.js +13 -0
- package/dist/esm/handler-types.js.map +1 -0
- package/dist/esm/handlers.js +7 -10
- package/dist/esm/handlers.js.map +1 -1
- package/dist/esm/index.browser.js +2 -0
- package/dist/esm/index.browser.js.map +1 -1
- package/dist/esm/index.executionenv.js +2 -0
- package/dist/esm/index.executionenv.js.map +1 -1
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/manifest/manifest.js +30 -5
- package/dist/esm/manifest/manifest.js.map +1 -1
- package/dist/esm/manifest/validation.js +3 -1
- package/dist/esm/manifest/validation.js.map +1 -1
- package/dist/esm/npm.js +5 -3
- package/dist/esm/npm.js.map +1 -1
- package/dist/esm/snaps.js +3 -2
- package/dist/esm/snaps.js.map +1 -1
- package/dist/esm/types.js +0 -2
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/validation.js.map +1 -1
- package/dist/esm/virtual-file/VirtualFile.js +7 -1
- package/dist/esm/virtual-file/VirtualFile.js.map +1 -1
- package/dist/types/auxiliary-files.d.ts +13 -0
- package/dist/types/errors.d.ts +182 -0
- package/dist/types/handler-types.d.ts +31 -0
- package/dist/types/handlers.d.ts +49 -36
- package/dist/types/index.browser.d.ts +2 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.executionenv.d.ts +2 -0
- package/dist/types/manifest/manifest.d.ts +11 -1
- package/dist/types/manifest/validation.d.ts +6 -2
- package/dist/types/snaps.d.ts +13 -6
- package/dist/types/types.d.ts +8 -9
- package/dist/types/validation.d.ts +2 -2
- package/package.json +17 -18
package/dist/esm/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/types.ts"],"sourcesContent":["import type { Json } from '@metamask/utils';\nimport { assertStruct, VersionStruct } from '@metamask/utils';\nimport type { Infer, Struct } from 'superstruct';\nimport {\n instance,\n is,\n object,\n optional,\n pattern,\n refine,\n size,\n string,\n type,\n union,\n assert as assertSuperstruct,\n} from 'superstruct';\n\nimport type { SnapCaveatType } from './caveats';\nimport type { SnapFunctionExports
|
|
1
|
+
{"version":3,"sources":["../../src/types.ts"],"sourcesContent":["import type { Json } from '@metamask/utils';\nimport { assertStruct, VersionStruct } from '@metamask/utils';\nimport type { Infer, Struct } from 'superstruct';\nimport {\n instance,\n is,\n object,\n optional,\n pattern,\n refine,\n size,\n string,\n type,\n union,\n assert as assertSuperstruct,\n} from 'superstruct';\n\nimport type { SnapCaveatType } from './caveats';\nimport type { SnapFunctionExports, SnapRpcHookArgs } from './handlers';\nimport type { SnapManifest } from './manifest';\nimport type { VirtualFile } from './virtual-file';\n\nexport enum NpmSnapFileNames {\n PackageJson = 'package.json',\n Manifest = 'snap.manifest.json',\n}\n\nexport const NameStruct = size(\n pattern(\n string(),\n /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\\/)?[a-z0-9-~][a-z0-9-._~]*$/u,\n ),\n 1,\n 214,\n);\n\n// Note we use `type` instead of `object` here, because the latter does not\n// allow unknown keys.\nexport const NpmSnapPackageJsonStruct = type({\n version: VersionStruct,\n name: NameStruct,\n main: optional(size(string(), 1, Infinity)),\n repository: optional(\n object({\n type: size(string(), 1, Infinity),\n url: size(string(), 1, Infinity),\n }),\n ),\n});\n\nexport type NpmSnapPackageJson = Infer<typeof NpmSnapPackageJsonStruct> &\n Record<string, any>;\n\n/**\n * Check if the given value is a valid {@link NpmSnapPackageJson} object.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid {@link NpmSnapPackageJson} object.\n */\nexport function isNpmSnapPackageJson(\n value: unknown,\n): value is NpmSnapPackageJson {\n return is(value, NpmSnapPackageJsonStruct);\n}\n\n/**\n * Asserts that the given value is a valid {@link NpmSnapPackageJson} object.\n *\n * @param value - The value to check.\n * @throws If the value is not a valid {@link NpmSnapPackageJson} object.\n */\nexport function assertIsNpmSnapPackageJson(\n value: unknown,\n): asserts value is NpmSnapPackageJson {\n assertStruct(\n value,\n NpmSnapPackageJsonStruct,\n `\"${NpmSnapFileNames.PackageJson}\" is invalid`,\n );\n}\n\n/**\n * An object for storing parsed but unvalidated Snap file contents.\n */\nexport type UnvalidatedSnapFiles = {\n manifest?: VirtualFile<Json>;\n packageJson?: VirtualFile<Json>;\n sourceCode?: VirtualFile;\n svgIcon?: VirtualFile;\n auxiliaryFiles: VirtualFile[];\n};\n\n/**\n * An object for storing the contents of Snap files that have passed JSON\n * Schema validation, or are non-empty if they are strings.\n */\nexport type SnapFiles = {\n manifest: VirtualFile<SnapManifest>;\n packageJson: VirtualFile<NpmSnapPackageJson>;\n sourceCode: VirtualFile;\n svgIcon?: VirtualFile;\n auxiliaryFiles: VirtualFile[];\n};\n\n/**\n * A subset of snap files extracted from a fetched snap.\n */\nexport type FetchedSnapFiles = Pick<\n SnapFiles,\n 'manifest' | 'sourceCode' | 'svgIcon' | 'auxiliaryFiles'\n>;\n\n/**\n * The possible prefixes for snap ids.\n */\n/* eslint-disable @typescript-eslint/naming-convention */\nexport enum SnapIdPrefixes {\n npm = 'npm:',\n local = 'local:',\n}\n/* eslint-enable @typescript-eslint/naming-convention */\n\nexport type SnapId = string;\n\n/**\n * Snap validation failure reason codes that are programmatically fixable\n * if validation occurs during development.\n */\nexport enum SnapValidationFailureReason {\n NameMismatch = '\"name\" field mismatch',\n VersionMismatch = '\"version\" field mismatch',\n RepositoryMismatch = '\"repository\" field mismatch',\n ShasumMismatch = '\"shasum\" field mismatch',\n}\n\n/* eslint-disable @typescript-eslint/naming-convention */\nexport enum SNAP_STREAM_NAMES {\n JSON_RPC = 'jsonRpc',\n COMMAND = 'command',\n}\n/* eslint-enable @typescript-eslint/naming-convention */\n\n// The snap is the callee\nexport type SnapRpcHook = (options: SnapRpcHookArgs) => Promise<unknown>;\n\ntype ObjectParameters<\n Type extends Record<string, (...args: any[]) => unknown>,\n> = Parameters<Type[keyof Type]>;\n\nexport type SnapExportsParameters = ObjectParameters<SnapFunctionExports>;\n\ntype UriOptions<Type extends string> = {\n protocol?: Struct<Type>;\n hash?: Struct<Type>;\n port?: Struct<Type>;\n hostname?: Struct<Type>;\n pathname?: Struct<Type>;\n search?: Struct<Type>;\n};\n\nexport const uri = (opts: UriOptions<any> = {}) =>\n refine(union([string(), instance(URL)]), 'uri', (value) => {\n try {\n const url = new URL(value);\n\n const UrlStruct = type(opts);\n assertSuperstruct(url, UrlStruct);\n return true;\n } catch {\n return `Expected URL, got \"${value.toString()}\".`;\n }\n });\n\n/**\n * Returns whether a given value is a valid URL.\n *\n * @param url - The value to check.\n * @param opts - Optional constraints for url checking.\n * @returns Whether `url` is valid URL or not.\n */\nexport function isValidUrl(\n url: unknown,\n opts: UriOptions<any> = {},\n): url is string | URL {\n return is(url, uri(opts));\n}\n\n// redefining here to avoid circular dependency\nexport const WALLET_SNAP_PERMISSION_KEY = 'wallet_snap';\n\nexport type SnapsPermissionRequest = {\n [WALLET_SNAP_PERMISSION_KEY]: {\n caveats: [\n {\n type: SnapCaveatType.SnapIds;\n value: Record<string, Json>;\n },\n ];\n };\n};\n"],"names":["assertStruct","VersionStruct","instance","is","object","optional","pattern","refine","size","string","type","union","assert","assertSuperstruct","NpmSnapFileNames","PackageJson","Manifest","NameStruct","NpmSnapPackageJsonStruct","version","name","main","Infinity","repository","url","isNpmSnapPackageJson","value","assertIsNpmSnapPackageJson","SnapIdPrefixes","npm","local","SnapValidationFailureReason","NameMismatch","VersionMismatch","RepositoryMismatch","ShasumMismatch","SNAP_STREAM_NAMES","JSON_RPC","COMMAND","uri","opts","URL","UrlStruct","toString","isValidUrl","WALLET_SNAP_PERMISSION_KEY"],"mappings":"AACA,SAASA,YAAY,EAAEC,aAAa,QAAQ,kBAAkB;AAE9D,SACEC,QAAQ,EACRC,EAAE,EACFC,MAAM,EACNC,QAAQ,EACRC,OAAO,EACPC,MAAM,EACNC,IAAI,EACJC,MAAM,EACNC,IAAI,EACJC,KAAK,EACLC,UAAUC,iBAAiB,QACtB,cAAc;WAOd;UAAKC,gBAAgB;IAAhBA,iBACVC,iBAAc;IADJD,iBAEVE,cAAW;GAFDF,qBAAAA;AAKZ,OAAO,MAAMG,aAAaT,KACxBF,QACEG,UACA,gEAEF,GACA,KACA;AAEF,2EAA2E;AAC3E,sBAAsB;AACtB,OAAO,MAAMS,2BAA2BR,KAAK;IAC3CS,SAASlB;IACTmB,MAAMH;IACNI,MAAMhB,SAASG,KAAKC,UAAU,GAAGa;IACjCC,YAAYlB,SACVD,OAAO;QACLM,MAAMF,KAAKC,UAAU,GAAGa;QACxBE,KAAKhB,KAAKC,UAAU,GAAGa;IACzB;AAEJ,GAAG;AAKH;;;;;CAKC,GACD,OAAO,SAASG,qBACdC,KAAc;IAEd,OAAOvB,GAAGuB,OAAOR;AACnB;AAEA;;;;;CAKC,GACD,OAAO,SAASS,2BACdD,KAAc;IAEd1B,aACE0B,OACAR,0BACA,CAAC,CAAC,EAAEJ,iBAAiBC,WAAW,CAAC,YAAY,CAAC;AAElD;WAqCO;UAAKa,cAAc;IAAdA,eACVC,SAAM;IADID,eAEVE,WAAQ;GAFEF,mBAAAA;WAYL;UAAKG,2BAA2B;IAA3BA,4BACVC,kBAAe;IADLD,4BAEVE,qBAAkB;IAFRF,4BAGVG,wBAAqB;IAHXH,4BAIVI,oBAAiB;GAJPJ,gCAAAA;WAQL;UAAKK,iBAAiB;IAAjBA,kBACVC,cAAW;IADDD,kBAEVE,aAAU;GAFAF,sBAAAA;AAwBZ,OAAO,MAAMG,MAAM,CAACC,OAAwB,CAAC,CAAC,GAC5CjC,OAAOI,MAAM;QAACF;QAAUP,SAASuC;KAAK,GAAG,OAAO,CAACf;QAC/C,IAAI;YACF,MAAMF,MAAM,IAAIiB,IAAIf;YAEpB,MAAMgB,YAAYhC,KAAK8B;YACvB3B,kBAAkBW,KAAKkB;YACvB,OAAO;QACT,EAAE,OAAM;YACN,OAAO,CAAC,mBAAmB,EAAEhB,MAAMiB,QAAQ,GAAG,EAAE,CAAC;QACnD;IACF,GAAG;AAEL;;;;;;CAMC,GACD,OAAO,SAASC,WACdpB,GAAY,EACZgB,OAAwB,CAAC,CAAC;IAE1B,OAAOrC,GAAGqB,KAAKe,IAAIC;AACrB;AAEA,+CAA+C;AAC/C,OAAO,MAAMK,6BAA6B,cAAc"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/validation.ts"],"sourcesContent":["import { assertIsSnapIcon } from './icon';\nimport { assertIsSnapManifest } from './manifest/validation';\nimport { validateSnapShasum } from './snaps';\nimport type {
|
|
1
|
+
{"version":3,"sources":["../../src/validation.ts"],"sourcesContent":["import { assertIsSnapIcon } from './icon';\nimport { assertIsSnapManifest } from './manifest/validation';\nimport { validateSnapShasum } from './snaps';\nimport type { FetchedSnapFiles } from './types';\n\n/**\n * Validates the files contained in a fetched snap.\n *\n * @param files - All potentially included files in a fetched snap.\n * @throws If any of the files are considered invalid.\n */\nexport function validateFetchedSnap(files: FetchedSnapFiles): void {\n assertIsSnapManifest(files.manifest.result);\n validateSnapShasum(files);\n\n if (files.svgIcon) {\n assertIsSnapIcon(files.svgIcon);\n }\n}\n"],"names":["assertIsSnapIcon","assertIsSnapManifest","validateSnapShasum","validateFetchedSnap","files","manifest","result","svgIcon"],"mappings":"AAAA,SAASA,gBAAgB,QAAQ,SAAS;AAC1C,SAASC,oBAAoB,QAAQ,wBAAwB;AAC7D,SAASC,kBAAkB,QAAQ,UAAU;AAG7C;;;;;CAKC,GACD,OAAO,SAASC,oBAAoBC,KAAuB;IACzDH,qBAAqBG,MAAMC,QAAQ,CAACC,MAAM;IAC1CJ,mBAAmBE;IAEnB,IAAIA,MAAMG,OAAO,EAAE;QACjBP,iBAAiBI,MAAMG,OAAO;IAChC;AACF"}
|
|
@@ -19,13 +19,19 @@ function _define_property(obj, key, value) {
|
|
|
19
19
|
}
|
|
20
20
|
return obj;
|
|
21
21
|
}
|
|
22
|
-
import { assert } from '@metamask/utils';
|
|
22
|
+
import { assert, bytesToHex } from '@metamask/utils';
|
|
23
|
+
import { base64 } from '@scure/base';
|
|
23
24
|
import { deepClone } from '../deep-clone';
|
|
24
25
|
export class VirtualFile {
|
|
25
26
|
toString(encoding) {
|
|
26
27
|
if (typeof this.value === 'string') {
|
|
27
28
|
assert(encoding === undefined, 'Tried to encode string.');
|
|
28
29
|
return this.value;
|
|
30
|
+
} else if (this.value instanceof Uint8Array && encoding === 'hex') {
|
|
31
|
+
return bytesToHex(this.value);
|
|
32
|
+
} else if (this.value instanceof Uint8Array && encoding === 'base64') {
|
|
33
|
+
// TODO: Use @metamask/utils for this
|
|
34
|
+
return base64.encode(this.value);
|
|
29
35
|
}
|
|
30
36
|
const decoder = new TextDecoder(encoding);
|
|
31
37
|
return decoder.decode(this.value);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/virtual-file/VirtualFile.ts"],"sourcesContent":["// TODO(ritave): Move into separate package @metamask/vfile / @metamask/utils + @metamask/to-vfile when passes code review\n// TODO(ritave): Streaming vfile contents similar to vinyl maybe?\n// TODO(ritave): Move fixing manifest in cli and bundler plugins to write messages to vfile\n// similar to unified instead of throwing \"ProgrammaticallyFixableErrors\".\n//\n// Using https://github.com/vfile/vfile would be helpful, but they only support ESM and we need to support CommonJS.\n// https://github.com/gulpjs/vinyl is also good, but they normalize paths, which we can't do, because\n// we're calculating checksums based on original path.\nimport { assert } from '@metamask/utils';\n\nimport { deepClone } from '../deep-clone';\n\n/**\n * This map registers the type of the {@link VirtualFile.data} key of a {@link VirtualFile}.\n *\n * This type can be augmented to register custom `data` types.\n *\n * @example\n * declare module '@metamask/snaps-utils' {\n * interface DataMap {\n * // `file.data.name` is typed as `string`\n * name: string\n * }\n * }\n */\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions, @typescript-eslint/no-empty-interface\nexport interface DataMap {}\n\nexport type Value = string | Uint8Array;\nexport type Compatible<Result = unknown> =\n | string\n | Uint8Array\n | Options<Result>;\nexport type Data = Record<string, unknown> & Partial<DataMap>;\nexport type Options<Result = unknown> = {\n value: Value;\n path?: string;\n data?: Data;\n result?: Result;\n};\n\nexport class VirtualFile<Result = unknown> {\n constructor(value?: Compatible<Result>) {\n let options: Options | undefined;\n if (typeof value === 'string' || value instanceof Uint8Array) {\n options = { value };\n } else {\n options = value;\n }\n\n this.value = options?.value ?? '';\n // This situations happens when there's no .result used,\n // we expect the file to have default generic in that situation:\n // VirtualFile<unknown> which will handle undefined properly\n //\n // While not 100% type safe, it'll be way less frustrating to work with.\n // The alternative would be to have VirtualFile.result be Result | undefined\n // and that would result in needing to branch out and check in all situations.\n //\n // In short, optimizing for most common use case.\n this.result = options?.result ?? (undefined as any);\n this.data = options?.data ?? {};\n this.path = options?.path ?? '/';\n }\n\n value: Value;\n\n result: Result;\n\n data: Data;\n\n path: string;\n\n toString(encoding?: string) {\n if (typeof this.value === 'string') {\n assert(encoding === undefined, 'Tried to encode string.');\n return this.value;\n }\n const decoder = new TextDecoder(encoding);\n return decoder.decode(this.value);\n }\n\n clone() {\n const vfile = new VirtualFile<Result>();\n if (typeof this.value === 'string') {\n vfile.value = this.value;\n } else {\n // deep-clone doesn't clone Buffer properly, even if it's a sub-class of Uint8Array\n vfile.value = this.value.slice(0);\n }\n vfile.result = deepClone(this.result);\n vfile.data = deepClone(this.data);\n vfile.path = this.path;\n return vfile;\n }\n}\n"],"names":["assert","deepClone","VirtualFile","toString","encoding","value","undefined","decoder","TextDecoder","decode","clone","vfile","slice","result","data","path","constructor","options"
|
|
1
|
+
{"version":3,"sources":["../../../src/virtual-file/VirtualFile.ts"],"sourcesContent":["// TODO(ritave): Move into separate package @metamask/vfile / @metamask/utils + @metamask/to-vfile when passes code review\n// TODO(ritave): Streaming vfile contents similar to vinyl maybe?\n// TODO(ritave): Move fixing manifest in cli and bundler plugins to write messages to vfile\n// similar to unified instead of throwing \"ProgrammaticallyFixableErrors\".\n//\n// Using https://github.com/vfile/vfile would be helpful, but they only support ESM and we need to support CommonJS.\n// https://github.com/gulpjs/vinyl is also good, but they normalize paths, which we can't do, because\n// we're calculating checksums based on original path.\nimport { assert, bytesToHex } from '@metamask/utils';\nimport { base64 } from '@scure/base';\n\nimport { deepClone } from '../deep-clone';\n\n/**\n * This map registers the type of the {@link VirtualFile.data} key of a {@link VirtualFile}.\n *\n * This type can be augmented to register custom `data` types.\n *\n * @example\n * declare module '@metamask/snaps-utils' {\n * interface DataMap {\n * // `file.data.name` is typed as `string`\n * name: string\n * }\n * }\n */\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions, @typescript-eslint/no-empty-interface\nexport interface DataMap {}\n\nexport type Value = string | Uint8Array;\nexport type Compatible<Result = unknown> =\n | string\n | Uint8Array\n | Options<Result>;\nexport type Data = Record<string, unknown> & Partial<DataMap>;\nexport type Options<Result = unknown> = {\n value: Value;\n path?: string;\n data?: Data;\n result?: Result;\n};\n\nexport class VirtualFile<Result = unknown> {\n constructor(value?: Compatible<Result>) {\n let options: Options | undefined;\n if (typeof value === 'string' || value instanceof Uint8Array) {\n options = { value };\n } else {\n options = value;\n }\n\n this.value = options?.value ?? '';\n // This situations happens when there's no .result used,\n // we expect the file to have default generic in that situation:\n // VirtualFile<unknown> which will handle undefined properly\n //\n // While not 100% type safe, it'll be way less frustrating to work with.\n // The alternative would be to have VirtualFile.result be Result | undefined\n // and that would result in needing to branch out and check in all situations.\n //\n // In short, optimizing for most common use case.\n this.result = options?.result ?? (undefined as any);\n this.data = options?.data ?? {};\n this.path = options?.path ?? '/';\n }\n\n value: Value;\n\n result: Result;\n\n data: Data;\n\n path: string;\n\n toString(encoding?: string) {\n if (typeof this.value === 'string') {\n assert(encoding === undefined, 'Tried to encode string.');\n return this.value;\n } else if (this.value instanceof Uint8Array && encoding === 'hex') {\n return bytesToHex(this.value);\n } else if (this.value instanceof Uint8Array && encoding === 'base64') {\n // TODO: Use @metamask/utils for this\n return base64.encode(this.value);\n }\n const decoder = new TextDecoder(encoding);\n return decoder.decode(this.value);\n }\n\n clone() {\n const vfile = new VirtualFile<Result>();\n if (typeof this.value === 'string') {\n vfile.value = this.value;\n } else {\n // deep-clone doesn't clone Buffer properly, even if it's a sub-class of Uint8Array\n vfile.value = this.value.slice(0);\n }\n vfile.result = deepClone(this.result);\n vfile.data = deepClone(this.data);\n vfile.path = this.path;\n return vfile;\n }\n}\n"],"names":["assert","bytesToHex","base64","deepClone","VirtualFile","toString","encoding","value","undefined","Uint8Array","encode","decoder","TextDecoder","decode","clone","vfile","slice","result","data","path","constructor","options"],"mappings":"AAAA,0HAA0H;AAC1H,iEAAiE;AACjE,2FAA2F;AAC3F,wFAAwF;AACxF,EAAE;AACF,oHAAoH;AACpH,qGAAqG;AACrG,sDAAsD;;;;;;;;;;;;;;AACtD,SAASA,MAAM,EAAEC,UAAU,QAAQ,kBAAkB;AACrD,SAASC,MAAM,QAAQ,cAAc;AAErC,SAASC,SAAS,QAAQ,gBAAgB;AA+B1C,OAAO,MAAMC;IAgCXC,SAASC,QAAiB,EAAE;QAC1B,IAAI,OAAO,IAAI,CAACC,KAAK,KAAK,UAAU;YAClCP,OAAOM,aAAaE,WAAW;YAC/B,OAAO,IAAI,CAACD,KAAK;QACnB,OAAO,IAAI,IAAI,CAACA,KAAK,YAAYE,cAAcH,aAAa,OAAO;YACjE,OAAOL,WAAW,IAAI,CAACM,KAAK;QAC9B,OAAO,IAAI,IAAI,CAACA,KAAK,YAAYE,cAAcH,aAAa,UAAU;YACpE,qCAAqC;YACrC,OAAOJ,OAAOQ,MAAM,CAAC,IAAI,CAACH,KAAK;QACjC;QACA,MAAMI,UAAU,IAAIC,YAAYN;QAChC,OAAOK,QAAQE,MAAM,CAAC,IAAI,CAACN,KAAK;IAClC;IAEAO,QAAQ;QACN,MAAMC,QAAQ,IAAIX;QAClB,IAAI,OAAO,IAAI,CAACG,KAAK,KAAK,UAAU;YAClCQ,MAAMR,KAAK,GAAG,IAAI,CAACA,KAAK;QAC1B,OAAO;YACL,mFAAmF;YACnFQ,MAAMR,KAAK,GAAG,IAAI,CAACA,KAAK,CAACS,KAAK,CAAC;QACjC;QACAD,MAAME,MAAM,GAAGd,UAAU,IAAI,CAACc,MAAM;QACpCF,MAAMG,IAAI,GAAGf,UAAU,IAAI,CAACe,IAAI;QAChCH,MAAMI,IAAI,GAAG,IAAI,CAACA,IAAI;QACtB,OAAOJ;IACT;IAzDAK,YAAYb,KAA0B,CAAE;QAuBxCA,uBAAAA,SAAAA,KAAAA;QAEAU,uBAAAA,UAAAA,KAAAA;QAEAC,uBAAAA,QAAAA,KAAAA;QAEAC,uBAAAA,QAAAA,KAAAA;QA5BE,IAAIE;QACJ,IAAI,OAAOd,UAAU,YAAYA,iBAAiBE,YAAY;YAC5DY,UAAU;gBAAEd;YAAM;QACpB,OAAO;YACLc,UAAUd;QACZ;QAEA,IAAI,CAACA,KAAK,GAAGc,SAASd,SAAS;QAC/B,wDAAwD;QACxD,gEAAgE;QAChE,4DAA4D;QAC5D,EAAE;QACF,wEAAwE;QACxE,4EAA4E;QAC5E,8EAA8E;QAC9E,EAAE;QACF,iDAAiD;QACjD,IAAI,CAACU,MAAM,GAAGI,SAASJ,UAAWT;QAClC,IAAI,CAACU,IAAI,GAAGG,SAASH,QAAQ,CAAC;QAC9B,IAAI,CAACC,IAAI,GAAGE,SAASF,QAAQ;IAC/B;AAqCF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare enum AuxiliaryFileEncoding {
|
|
2
|
+
Base64 = "base64",
|
|
3
|
+
Hex = "hex",
|
|
4
|
+
Utf8 = "utf8"
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Re-encodes an auxiliary file if needed depending on the requested file encoding.
|
|
8
|
+
*
|
|
9
|
+
* @param value - The base64 value stored for the auxiliary file.
|
|
10
|
+
* @param encoding - The chosen encoding.
|
|
11
|
+
* @returns The file encoded in the requested encoding.
|
|
12
|
+
*/
|
|
13
|
+
export declare function encodeAuxiliaryFile(value: string, encoding: AuxiliaryFileEncoding): string;
|
package/dist/types/errors.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { JsonRpcError as RpcError } from '@metamask/rpc-errors';
|
|
2
|
+
import type { DataWithOptionalCause } from '@metamask/rpc-errors';
|
|
3
|
+
import type { Json, JsonRpcError } from '@metamask/utils';
|
|
1
4
|
/**
|
|
2
5
|
* Get the error message from an unknown error type.
|
|
3
6
|
*
|
|
@@ -8,3 +11,182 @@
|
|
|
8
11
|
* @returns The error message.
|
|
9
12
|
*/
|
|
10
13
|
export declare function getErrorMessage(error: unknown): string;
|
|
14
|
+
/**
|
|
15
|
+
* Get the error stack from an unknown error type.
|
|
16
|
+
*
|
|
17
|
+
* @param error - The error to get the stack from.
|
|
18
|
+
* @returns The error stack, or undefined if the error does not have a valid
|
|
19
|
+
* stack.
|
|
20
|
+
*/
|
|
21
|
+
export declare function getErrorStack(error: unknown): string | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Get the error code from an unknown error type.
|
|
24
|
+
*
|
|
25
|
+
* @param error - The error to get the code from.
|
|
26
|
+
* @returns The error code, or `-32603` if the error does not have a valid code.
|
|
27
|
+
*/
|
|
28
|
+
export declare function getErrorCode(error: unknown): number;
|
|
29
|
+
/**
|
|
30
|
+
* Get the error data from an unknown error type.
|
|
31
|
+
*
|
|
32
|
+
* @param error - The error to get the data from.
|
|
33
|
+
* @returns The error data, or an empty object if the error does not have valid
|
|
34
|
+
* data.
|
|
35
|
+
*/
|
|
36
|
+
export declare function getErrorData(error: unknown): {
|
|
37
|
+
[prop: string]: Json;
|
|
38
|
+
};
|
|
39
|
+
export declare const SNAP_ERROR_WRAPPER_CODE = -31001;
|
|
40
|
+
export declare const SNAP_ERROR_WRAPPER_MESSAGE = "Wrapped Snap Error";
|
|
41
|
+
export declare const SNAP_ERROR_CODE = -31002;
|
|
42
|
+
export declare const SNAP_ERROR_MESSAGE = "Snap Error";
|
|
43
|
+
export declare type SerializedSnapErrorWrapper = {
|
|
44
|
+
code: typeof SNAP_ERROR_WRAPPER_CODE;
|
|
45
|
+
message: typeof SNAP_ERROR_WRAPPER_MESSAGE;
|
|
46
|
+
data: {
|
|
47
|
+
cause: Json;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
export declare type SerializedSnapError = {
|
|
51
|
+
code: typeof SNAP_ERROR_CODE;
|
|
52
|
+
message: typeof SNAP_ERROR_MESSAGE;
|
|
53
|
+
data: {
|
|
54
|
+
cause: JsonRpcError & {
|
|
55
|
+
data: Record<string, Json>;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
export declare class WrappedSnapError extends Error {
|
|
60
|
+
#private;
|
|
61
|
+
/**
|
|
62
|
+
* Create a new `WrappedSnapError`.
|
|
63
|
+
*
|
|
64
|
+
* @param error - The error to create the `WrappedSnapError` from.
|
|
65
|
+
*/
|
|
66
|
+
constructor(error: unknown);
|
|
67
|
+
/**
|
|
68
|
+
* The error name.
|
|
69
|
+
*
|
|
70
|
+
* @returns The error name.
|
|
71
|
+
*/
|
|
72
|
+
get name(): string;
|
|
73
|
+
/**
|
|
74
|
+
* The error message.
|
|
75
|
+
*
|
|
76
|
+
* @returns The error message.
|
|
77
|
+
*/
|
|
78
|
+
get message(): string;
|
|
79
|
+
/**
|
|
80
|
+
* The error stack.
|
|
81
|
+
*
|
|
82
|
+
* @returns The error stack.
|
|
83
|
+
*/
|
|
84
|
+
get stack(): string | undefined;
|
|
85
|
+
/**
|
|
86
|
+
* Convert the error to a JSON object.
|
|
87
|
+
*
|
|
88
|
+
* @returns The JSON object.
|
|
89
|
+
*/
|
|
90
|
+
toJSON(): SerializedSnapErrorWrapper;
|
|
91
|
+
/**
|
|
92
|
+
* Serialize the error to a JSON object. This is called by
|
|
93
|
+
* `@metamask/rpc-errors` when serializing the error.
|
|
94
|
+
*
|
|
95
|
+
* @returns The JSON object.
|
|
96
|
+
*/
|
|
97
|
+
serialize(): SerializedSnapErrorWrapper;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* A generic error which can be thrown by a Snap, without it causing the Snap to
|
|
101
|
+
* crash.
|
|
102
|
+
*/
|
|
103
|
+
export declare class SnapError extends Error {
|
|
104
|
+
#private;
|
|
105
|
+
/**
|
|
106
|
+
* Create a new `SnapError`.
|
|
107
|
+
*
|
|
108
|
+
* @param error - The error to create the `SnapError` from. If this is a
|
|
109
|
+
* `string`, it will be used as the error message. If this is an `Error`, its
|
|
110
|
+
* `message` property will be used as the error message. If this is a
|
|
111
|
+
* `JsonRpcError`, its `message` property will be used as the error message
|
|
112
|
+
* and its `code` property will be used as the error code. Otherwise, the
|
|
113
|
+
* error will be converted to a string and used as the error message.
|
|
114
|
+
* @param data - Additional data to include in the error. This will be merged
|
|
115
|
+
* with the error data, if any.
|
|
116
|
+
*/
|
|
117
|
+
constructor(error: string | Error | JsonRpcError, data?: Record<string, Json>);
|
|
118
|
+
/**
|
|
119
|
+
* The error name.
|
|
120
|
+
*
|
|
121
|
+
* @returns The error name.
|
|
122
|
+
*/
|
|
123
|
+
get name(): string;
|
|
124
|
+
/**
|
|
125
|
+
* The error code.
|
|
126
|
+
*
|
|
127
|
+
* @returns The error code.
|
|
128
|
+
*/
|
|
129
|
+
get code(): number;
|
|
130
|
+
/**
|
|
131
|
+
* The error message.
|
|
132
|
+
*
|
|
133
|
+
* @returns The error message.
|
|
134
|
+
*/
|
|
135
|
+
get message(): string;
|
|
136
|
+
/**
|
|
137
|
+
* Additional data for the error.
|
|
138
|
+
*
|
|
139
|
+
* @returns Additional data for the error.
|
|
140
|
+
*/
|
|
141
|
+
get data(): Record<string, Json>;
|
|
142
|
+
/**
|
|
143
|
+
* The error stack.
|
|
144
|
+
*
|
|
145
|
+
* @returns The error stack.
|
|
146
|
+
*/
|
|
147
|
+
get stack(): string | undefined;
|
|
148
|
+
/**
|
|
149
|
+
* Convert the error to a JSON object.
|
|
150
|
+
*
|
|
151
|
+
* @returns The JSON object.
|
|
152
|
+
*/
|
|
153
|
+
toJSON(): SerializedSnapError;
|
|
154
|
+
/**
|
|
155
|
+
* Serialize the error to a JSON object. This is called by
|
|
156
|
+
* `@metamask/rpc-errors` when serializing the error.
|
|
157
|
+
*
|
|
158
|
+
* @returns The JSON object.
|
|
159
|
+
*/
|
|
160
|
+
serialize(): SerializedSnapError;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Check if an object is a `SnapError`.
|
|
164
|
+
*
|
|
165
|
+
* @param error - The object to check.
|
|
166
|
+
* @returns Whether the object is a `SnapError`.
|
|
167
|
+
*/
|
|
168
|
+
export declare function isSnapError(error: unknown): error is SnapError;
|
|
169
|
+
/**
|
|
170
|
+
* Check if a JSON-RPC error is a `SnapError`.
|
|
171
|
+
*
|
|
172
|
+
* @param error - The object to check.
|
|
173
|
+
* @returns Whether the object is a `SnapError`.
|
|
174
|
+
*/
|
|
175
|
+
export declare function isSerializedSnapError(error: JsonRpcError): error is SerializedSnapError;
|
|
176
|
+
/**
|
|
177
|
+
* Check if a JSON-RPC error is a `WrappedSnapError`.
|
|
178
|
+
*
|
|
179
|
+
* @param error - The object to check.
|
|
180
|
+
* @returns Whether the object is a `WrappedSnapError`.
|
|
181
|
+
*/
|
|
182
|
+
export declare function isWrappedSnapError(error: unknown): error is SerializedSnapErrorWrapper;
|
|
183
|
+
/**
|
|
184
|
+
* Attempt to unwrap an unknown error to a `JsonRpcError`. This function will
|
|
185
|
+
* try to get the error code, message, and data from the error, and return a
|
|
186
|
+
* `JsonRpcError` with those properties.
|
|
187
|
+
*
|
|
188
|
+
* @param error - The error to unwrap.
|
|
189
|
+
* @returns A tuple containing the unwrapped error and a boolean indicating
|
|
190
|
+
* whether the error was handled.
|
|
191
|
+
*/
|
|
192
|
+
export declare function unwrapError(error: unknown): [error: RpcError<DataWithOptionalCause>, isHandled: boolean];
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export declare enum HandlerType {
|
|
2
|
+
OnRpcRequest = "onRpcRequest",
|
|
3
|
+
OnTransaction = "onTransaction",
|
|
4
|
+
OnCronjob = "onCronjob",
|
|
5
|
+
OnInstall = "onInstall",
|
|
6
|
+
OnUpdate = "onUpdate",
|
|
7
|
+
OnNameLookup = "onNameLookup",
|
|
8
|
+
OnKeyringRequest = "onKeyringRequest"
|
|
9
|
+
}
|
|
10
|
+
export declare type SnapHandler = {
|
|
11
|
+
/**
|
|
12
|
+
* The type of handler.
|
|
13
|
+
*/
|
|
14
|
+
type: HandlerType;
|
|
15
|
+
/**
|
|
16
|
+
* Whether the handler is required, i.e., whether the request will fail if the
|
|
17
|
+
* handler is called, but the snap does not export it.
|
|
18
|
+
*
|
|
19
|
+
* This is primarily used for the lifecycle handlers, which are optional.
|
|
20
|
+
*/
|
|
21
|
+
required: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Validate the given snap export. This should return a type guard for the
|
|
24
|
+
* handler type.
|
|
25
|
+
*
|
|
26
|
+
* @param snapExport - The export to validate.
|
|
27
|
+
* @returns Whether the export is valid.
|
|
28
|
+
*/
|
|
29
|
+
validator: (snapExport: unknown) => boolean;
|
|
30
|
+
};
|
|
31
|
+
export declare const SNAP_EXPORT_NAMES: HandlerType[];
|
package/dist/types/handlers.d.ts
CHANGED
|
@@ -1,36 +1,12 @@
|
|
|
1
|
-
import type { Component } from '@metamask/snaps-ui';
|
|
2
1
|
import type { Json, JsonRpcParams, JsonRpcRequest } from '@metamask/utils';
|
|
3
|
-
import type {
|
|
2
|
+
import type { Infer } from 'superstruct';
|
|
3
|
+
import type { SnapHandler } from './handler-types';
|
|
4
|
+
import { HandlerType } from './handler-types';
|
|
4
5
|
import type { AccountAddress, Caip2ChainId } from './namespace';
|
|
5
|
-
export declare
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
OnInstall = "onInstall",
|
|
10
|
-
OnUpdate = "onUpdate",
|
|
11
|
-
OnNameLookup = "onNameLookup",
|
|
12
|
-
OnKeyringRequest = "onKeyringRequest"
|
|
13
|
-
}
|
|
14
|
-
declare type SnapHandler = {
|
|
15
|
-
/**
|
|
16
|
-
* The type of handler.
|
|
17
|
-
*/
|
|
18
|
-
type: HandlerType;
|
|
19
|
-
/**
|
|
20
|
-
* Whether the handler is required, i.e., whether the request will fail if the
|
|
21
|
-
* handler is called, but the snap does not export it.
|
|
22
|
-
*
|
|
23
|
-
* This is primarily used for the lifecycle handlers, which are optional.
|
|
24
|
-
*/
|
|
25
|
-
required: boolean;
|
|
26
|
-
/**
|
|
27
|
-
* Validate the given snap export. This should return a type guard for the
|
|
28
|
-
* handler type.
|
|
29
|
-
*
|
|
30
|
-
* @param snapExport - The export to validate.
|
|
31
|
-
* @returns Whether the export is valid.
|
|
32
|
-
*/
|
|
33
|
-
validator: (snapExport: unknown) => boolean;
|
|
6
|
+
export declare type SnapRpcHookArgs = {
|
|
7
|
+
origin: string;
|
|
8
|
+
handler: HandlerType;
|
|
9
|
+
request: Record<string, unknown>;
|
|
34
10
|
};
|
|
35
11
|
export declare const SNAP_EXPORTS: {
|
|
36
12
|
readonly onRpcRequest: {
|
|
@@ -89,6 +65,47 @@ export declare type OnRpcRequestHandler<Params extends JsonRpcParams = JsonRpcPa
|
|
|
89
65
|
export declare enum SeverityLevel {
|
|
90
66
|
Critical = "critical"
|
|
91
67
|
}
|
|
68
|
+
export declare const OnTransactionResponseStruct: import("superstruct").Struct<{
|
|
69
|
+
content: import("@metamask/snaps-ui").Panel | {
|
|
70
|
+
value: string;
|
|
71
|
+
type: import("@metamask/snaps-ui").NodeType.Copyable;
|
|
72
|
+
} | {
|
|
73
|
+
type: import("@metamask/snaps-ui").NodeType.Divider;
|
|
74
|
+
} | {
|
|
75
|
+
value: string;
|
|
76
|
+
type: import("@metamask/snaps-ui").NodeType.Heading;
|
|
77
|
+
} | {
|
|
78
|
+
type: import("@metamask/snaps-ui").NodeType.Spinner;
|
|
79
|
+
} | {
|
|
80
|
+
value: string;
|
|
81
|
+
type: import("@metamask/snaps-ui").NodeType.Text;
|
|
82
|
+
markdown?: boolean | undefined;
|
|
83
|
+
} | {
|
|
84
|
+
value: string;
|
|
85
|
+
type: import("@metamask/snaps-ui").NodeType.Image;
|
|
86
|
+
};
|
|
87
|
+
severity?: SeverityLevel | undefined;
|
|
88
|
+
}, {
|
|
89
|
+
content: import("superstruct").Struct<import("@metamask/snaps-ui").Panel | {
|
|
90
|
+
value: string;
|
|
91
|
+
type: import("@metamask/snaps-ui").NodeType.Copyable;
|
|
92
|
+
} | {
|
|
93
|
+
type: import("@metamask/snaps-ui").NodeType.Divider;
|
|
94
|
+
} | {
|
|
95
|
+
value: string;
|
|
96
|
+
type: import("@metamask/snaps-ui").NodeType.Heading;
|
|
97
|
+
} | {
|
|
98
|
+
type: import("@metamask/snaps-ui").NodeType.Spinner;
|
|
99
|
+
} | {
|
|
100
|
+
value: string;
|
|
101
|
+
type: import("@metamask/snaps-ui").NodeType.Text;
|
|
102
|
+
markdown?: boolean | undefined;
|
|
103
|
+
} | {
|
|
104
|
+
value: string;
|
|
105
|
+
type: import("@metamask/snaps-ui").NodeType.Image;
|
|
106
|
+
}, null>;
|
|
107
|
+
severity: import("superstruct").Struct<SeverityLevel | undefined, SeverityLevel>;
|
|
108
|
+
}>;
|
|
92
109
|
/**
|
|
93
110
|
* The response from a snap's `onTransaction` handler.
|
|
94
111
|
*
|
|
@@ -96,10 +113,7 @@ export declare enum SeverityLevel {
|
|
|
96
113
|
*
|
|
97
114
|
* If the snap has no insights about the transaction, this should be `null`.
|
|
98
115
|
*/
|
|
99
|
-
export declare type OnTransactionResponse =
|
|
100
|
-
content: Component | null;
|
|
101
|
-
severity?: EnumToUnion<SeverityLevel>;
|
|
102
|
-
};
|
|
116
|
+
export declare type OnTransactionResponse = Infer<typeof OnTransactionResponseStruct>;
|
|
103
117
|
/**
|
|
104
118
|
* The `onTransaction` handler. This is called whenever a transaction is
|
|
105
119
|
* submitted to the snap. It can return insights about the transaction, which
|
|
@@ -212,4 +226,3 @@ export declare type SnapFunctionExports = {
|
|
|
212
226
|
* All handlers that a snap can implement.
|
|
213
227
|
*/
|
|
214
228
|
export declare type SnapExports = SnapFunctionExports;
|
|
215
|
-
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from './array';
|
|
2
|
+
export * from './auxiliary-files';
|
|
2
3
|
export * from './caveats';
|
|
3
4
|
export * from './checksum';
|
|
4
5
|
export * from './cronjob';
|
|
@@ -8,6 +9,7 @@ export * from './entropy';
|
|
|
8
9
|
export * from './enum';
|
|
9
10
|
export * from './errors';
|
|
10
11
|
export * from './handlers';
|
|
12
|
+
export * from './handler-types';
|
|
11
13
|
export * from './iframe';
|
|
12
14
|
export * from './json';
|
|
13
15
|
export * from './json-rpc';
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from './array';
|
|
2
|
+
export * from './auxiliary-files';
|
|
2
3
|
export * from './caveats';
|
|
3
4
|
export * from './cronjob';
|
|
4
5
|
export * from './checksum';
|
|
@@ -10,6 +11,7 @@ export * from './eval';
|
|
|
10
11
|
export * from './errors';
|
|
11
12
|
export * from './fs';
|
|
12
13
|
export * from './handlers';
|
|
14
|
+
export * from './handler-types';
|
|
13
15
|
export * from './iframe';
|
|
14
16
|
export * from './json';
|
|
15
17
|
export * from './json-rpc';
|
|
@@ -27,3 +29,4 @@ export * from './types';
|
|
|
27
29
|
export * from './validation';
|
|
28
30
|
export * from './versions';
|
|
29
31
|
export * from './virtual-file';
|
|
32
|
+
export { assertLinksAreSafe } from '@metamask/snaps-ui';
|
|
@@ -66,6 +66,15 @@ export declare function getSnapSourceCode(basePath: string, manifest: Json, sour
|
|
|
66
66
|
* @returns The contents of the icon, if any.
|
|
67
67
|
*/
|
|
68
68
|
export declare function getSnapIcon(basePath: string, manifest: Json): Promise<VirtualFile | undefined>;
|
|
69
|
+
/**
|
|
70
|
+
* Given an unvalidated Snap manifest, attempts to extract the auxiliary files
|
|
71
|
+
* and read them.
|
|
72
|
+
*
|
|
73
|
+
* @param basePath - The path to the folder with the manifest files.
|
|
74
|
+
* @param manifest - The unvalidated Snap manifest file contents.
|
|
75
|
+
* @returns A list of auxiliary files and their contents, if any.
|
|
76
|
+
*/
|
|
77
|
+
export declare function getSnapAuxiliaryFiles(basePath: string, manifest: Json): Promise<VirtualFile[] | undefined>;
|
|
69
78
|
/**
|
|
70
79
|
* Sorts the given manifest in our preferred sort order and removes the
|
|
71
80
|
* `repository` field if it is falsy (it may be `null`).
|
|
@@ -83,5 +92,6 @@ export declare function getWritableManifest(manifest: SnapManifest): SnapManifes
|
|
|
83
92
|
* @param snapFiles.packageJson - The npm Snap's `package.json`.
|
|
84
93
|
* @param snapFiles.sourceCode - The Snap's source code.
|
|
85
94
|
* @param snapFiles.svgIcon - The Snap's optional icon.
|
|
95
|
+
* @param snapFiles.auxiliaryFiles - Any auxiliary files required by the snap at runtime.
|
|
86
96
|
*/
|
|
87
|
-
export declare function validateNpmSnapManifest({ manifest, packageJson, sourceCode, svgIcon, }: SnapFiles): void;
|
|
97
|
+
export declare function validateNpmSnapManifest({ manifest, packageJson, sourceCode, svgIcon, auxiliaryFiles, }: SnapFiles): void;
|
|
@@ -190,10 +190,9 @@ export declare const PermissionsStruct: Struct<{
|
|
|
190
190
|
}> | undefined, null>;
|
|
191
191
|
}>;
|
|
192
192
|
export declare type SnapPermissions = Infer<typeof PermissionsStruct>;
|
|
193
|
+
export declare const SnapAuxilaryFilesStruct: Struct<string[], Struct<string, null>>;
|
|
193
194
|
export declare const SnapManifestStruct: Struct<{
|
|
194
195
|
description: string;
|
|
195
|
-
version: import("@metamask/utils").SemVerVersion;
|
|
196
|
-
proposedName: string;
|
|
197
196
|
source: {
|
|
198
197
|
location: {
|
|
199
198
|
npm: {
|
|
@@ -204,7 +203,10 @@ export declare const SnapManifestStruct: Struct<{
|
|
|
204
203
|
};
|
|
205
204
|
};
|
|
206
205
|
shasum: string;
|
|
206
|
+
files?: string[] | undefined;
|
|
207
207
|
};
|
|
208
|
+
version: import("@metamask/utils").SemVerVersion;
|
|
209
|
+
proposedName: string;
|
|
208
210
|
initialPermissions: {
|
|
209
211
|
'endowment:network-access'?: {} | undefined;
|
|
210
212
|
'endowment:webassembly'?: {} | undefined;
|
|
@@ -279,6 +281,7 @@ export declare const SnapManifestStruct: Struct<{
|
|
|
279
281
|
};
|
|
280
282
|
};
|
|
281
283
|
shasum: string;
|
|
284
|
+
files?: string[] | undefined;
|
|
282
285
|
}, {
|
|
283
286
|
shasum: Struct<string, null>;
|
|
284
287
|
location: Struct<{
|
|
@@ -301,6 +304,7 @@ export declare const SnapManifestStruct: Struct<{
|
|
|
301
304
|
registry: Struct<"https://registry.npmjs.org" | "https://registry.npmjs.org/", null>;
|
|
302
305
|
}>;
|
|
303
306
|
}>;
|
|
307
|
+
files: Struct<string[] | undefined, Struct<string, null>>;
|
|
304
308
|
}>;
|
|
305
309
|
initialPermissions: Struct<{
|
|
306
310
|
'endowment:network-access'?: {} | undefined;
|
package/dist/types/snaps.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import type { SubjectPermissions, PermissionConstraint } from '@metamask/permission-controller';
|
|
2
2
|
import type { BlockReason } from '@metamask/snaps-registry';
|
|
3
|
-
import type { Json,
|
|
4
|
-
import type { SerializedEthereumRpcError } from 'eth-rpc-errors/dist/classes';
|
|
3
|
+
import type { Json, JsonRpcError, Opaque, SemVerVersion } from '@metamask/utils';
|
|
5
4
|
import type { Struct } from 'superstruct';
|
|
6
5
|
import type { SnapManifest, SnapPermissions } from './manifest/validation';
|
|
7
|
-
import type {
|
|
6
|
+
import type { FetchedSnapFiles, SnapId, SnapsPermissionRequest } from './types';
|
|
8
7
|
import { SnapIdPrefixes, SnapValidationFailureReason } from './types';
|
|
9
8
|
export declare const PROPOSED_NAME_REGEX: RegExp;
|
|
10
9
|
/**
|
|
@@ -44,6 +43,10 @@ export declare type VersionHistory = {
|
|
|
44
43
|
version: string;
|
|
45
44
|
date: number;
|
|
46
45
|
};
|
|
46
|
+
export declare type SnapAuxilaryFile = {
|
|
47
|
+
path: string;
|
|
48
|
+
value: string;
|
|
49
|
+
};
|
|
47
50
|
export declare type PersistedSnap = Snap;
|
|
48
51
|
/**
|
|
49
52
|
* A Snap as it exists in {@link SnapController} state.
|
|
@@ -91,6 +94,10 @@ export declare type Snap = {
|
|
|
91
94
|
* Can be used to derive when the Snap was installed, when it was updated to a certain version and who requested the change.
|
|
92
95
|
*/
|
|
93
96
|
versionHistory: VersionHistory[];
|
|
97
|
+
/**
|
|
98
|
+
* Static auxiliary files that can be loaded at runtime.
|
|
99
|
+
*/
|
|
100
|
+
auxiliaryFiles?: SnapAuxilaryFile[];
|
|
94
101
|
};
|
|
95
102
|
export declare type TruncatedSnapFields = 'id' | 'initialPermissions' | 'version' | 'enabled' | 'blocked';
|
|
96
103
|
/**
|
|
@@ -99,7 +106,7 @@ export declare type TruncatedSnapFields = 'id' | 'initialPermissions' | 'version
|
|
|
99
106
|
*/
|
|
100
107
|
export declare type TruncatedSnap = Pick<Snap, TruncatedSnapFields>;
|
|
101
108
|
export declare type ProcessSnapResult = TruncatedSnap | {
|
|
102
|
-
error:
|
|
109
|
+
error: JsonRpcError;
|
|
103
110
|
};
|
|
104
111
|
export declare type InstallSnapsResult = Record<SnapId, ProcessSnapResult>;
|
|
105
112
|
/**
|
|
@@ -116,7 +123,7 @@ export declare class ProgrammaticallyFixableSnapError extends Error {
|
|
|
116
123
|
* @param files - All required Snap files to be included in the checksum.
|
|
117
124
|
* @returns The Base64-encoded SHA-256 digest of the source code.
|
|
118
125
|
*/
|
|
119
|
-
export declare function getSnapChecksum(files:
|
|
126
|
+
export declare function getSnapChecksum(files: FetchedSnapFiles): string;
|
|
120
127
|
/**
|
|
121
128
|
* Checks whether the `source.shasum` property of a Snap manifest matches the
|
|
122
129
|
* shasum of the snap.
|
|
@@ -124,7 +131,7 @@ export declare function getSnapChecksum(files: Pick<SnapFiles, 'manifest' | 'sou
|
|
|
124
131
|
* @param files - All required Snap files to be included in the checksum.
|
|
125
132
|
* @param errorMessage - The error message to throw if validation fails.
|
|
126
133
|
*/
|
|
127
|
-
export declare function validateSnapShasum(files:
|
|
134
|
+
export declare function validateSnapShasum(files: FetchedSnapFiles, errorMessage?: string): void;
|
|
128
135
|
export declare const LOCALHOST_HOSTNAMES: readonly ["localhost", "127.0.0.1", "[::1]"];
|
|
129
136
|
export declare const BaseSnapIdStruct: Struct<string, null>;
|
|
130
137
|
export declare const LocalSnapIdStruct: Struct<string, null>;
|