@metamask/snaps-utils 2.0.1 → 3.1.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.
Files changed (74) hide show
  1. package/CHANGELOG.md +20 -1
  2. package/dist/cjs/auxiliary-files.js +40 -0
  3. package/dist/cjs/auxiliary-files.js.map +1 -0
  4. package/dist/cjs/caveats.js +3 -0
  5. package/dist/cjs/caveats.js.map +1 -1
  6. package/dist/cjs/errors.js +353 -3
  7. package/dist/cjs/errors.js.map +1 -1
  8. package/dist/cjs/handlers.js +8 -0
  9. package/dist/cjs/handlers.js.map +1 -1
  10. package/dist/cjs/index.browser.js +1 -0
  11. package/dist/cjs/index.browser.js.map +1 -1
  12. package/dist/cjs/index.executionenv.js +1 -0
  13. package/dist/cjs/index.executionenv.js.map +1 -1
  14. package/dist/cjs/index.js +1 -0
  15. package/dist/cjs/index.js.map +1 -1
  16. package/dist/cjs/json-rpc.js +39 -4
  17. package/dist/cjs/json-rpc.js.map +1 -1
  18. package/dist/cjs/manifest/manifest.js +25 -5
  19. package/dist/cjs/manifest/manifest.js.map +1 -1
  20. package/dist/cjs/manifest/validation.js +7 -1
  21. package/dist/cjs/manifest/validation.js.map +1 -1
  22. package/dist/cjs/npm.js +5 -3
  23. package/dist/cjs/npm.js.map +1 -1
  24. package/dist/cjs/snaps.js +3 -2
  25. package/dist/cjs/snaps.js.map +1 -1
  26. package/dist/cjs/types.js.map +1 -1
  27. package/dist/cjs/validation.js.map +1 -1
  28. package/dist/cjs/virtual-file/VirtualFile.js +6 -0
  29. package/dist/cjs/virtual-file/VirtualFile.js.map +1 -1
  30. package/dist/cjs/virtual-file/toVirtualFile.js.map +1 -1
  31. package/dist/esm/auxiliary-files.js +28 -0
  32. package/dist/esm/auxiliary-files.js.map +1 -0
  33. package/dist/esm/caveats.js +3 -0
  34. package/dist/esm/caveats.js.map +1 -1
  35. package/dist/esm/errors.js +350 -1
  36. package/dist/esm/errors.js.map +1 -1
  37. package/dist/esm/handlers.js +8 -0
  38. package/dist/esm/handlers.js.map +1 -1
  39. package/dist/esm/index.browser.js +1 -0
  40. package/dist/esm/index.browser.js.map +1 -1
  41. package/dist/esm/index.executionenv.js +1 -0
  42. package/dist/esm/index.executionenv.js.map +1 -1
  43. package/dist/esm/index.js +1 -0
  44. package/dist/esm/index.js.map +1 -1
  45. package/dist/esm/json-rpc.js +46 -6
  46. package/dist/esm/json-rpc.js.map +1 -1
  47. package/dist/esm/manifest/manifest.js +30 -5
  48. package/dist/esm/manifest/manifest.js.map +1 -1
  49. package/dist/esm/manifest/validation.js +5 -2
  50. package/dist/esm/manifest/validation.js.map +1 -1
  51. package/dist/esm/npm.js +5 -3
  52. package/dist/esm/npm.js.map +1 -1
  53. package/dist/esm/snaps.js +3 -2
  54. package/dist/esm/snaps.js.map +1 -1
  55. package/dist/esm/types.js.map +1 -1
  56. package/dist/esm/validation.js.map +1 -1
  57. package/dist/esm/virtual-file/VirtualFile.js +7 -1
  58. package/dist/esm/virtual-file/VirtualFile.js.map +1 -1
  59. package/dist/esm/virtual-file/toVirtualFile.js.map +1 -1
  60. package/dist/types/auxiliary-files.d.ts +13 -0
  61. package/dist/types/caveats.d.ts +4 -0
  62. package/dist/types/errors.d.ts +182 -0
  63. package/dist/types/handlers.d.ts +21 -2
  64. package/dist/types/index.browser.d.ts +1 -0
  65. package/dist/types/index.d.ts +1 -0
  66. package/dist/types/index.executionenv.d.ts +1 -0
  67. package/dist/types/json-rpc.d.ts +28 -1
  68. package/dist/types/manifest/manifest.d.ts +11 -1
  69. package/dist/types/manifest/validation.d.ts +30 -0
  70. package/dist/types/snaps.d.ts +13 -6
  71. package/dist/types/types.d.ts +6 -0
  72. package/dist/types/validation.d.ts +2 -2
  73. package/dist/types/virtual-file/toVirtualFile.d.ts +1 -1
  74. package/package.json +20 -21
@@ -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","Uint8Array"],"mappings":"AAAA,0HAA0H;AAC1H,iEAAiE;AACjE,2FAA2F;AAC3F,wFAAwF;AACxF,EAAE;AACF,oHAAoH;AACpH,qGAAqG;AACrG,sDAAsD;;;;;;;;;;;;;;AACtD,SAASA,MAAM,QAAQ,kBAAkB;AAEzC,SAASC,SAAS,QAAQ,gBAAgB;AA+B1C,OAAO,MAAMC;IAgCXC,SAASC,QAAiB,EAAE;QAC1B,IAAI,OAAO,IAAI,CAACC,KAAK,KAAK,UAAU;YAClCL,OAAOI,aAAaE,WAAW;YAC/B,OAAO,IAAI,CAACD,KAAK;QACnB;QACA,MAAME,UAAU,IAAIC,YAAYJ;QAChC,OAAOG,QAAQE,MAAM,CAAC,IAAI,CAACJ,KAAK;IAClC;IAEAK,QAAQ;QACN,MAAMC,QAAQ,IAAIT;QAClB,IAAI,OAAO,IAAI,CAACG,KAAK,KAAK,UAAU;YAClCM,MAAMN,KAAK,GAAG,IAAI,CAACA,KAAK;QAC1B,OAAO;YACL,mFAAmF;YACnFM,MAAMN,KAAK,GAAG,IAAI,CAACA,KAAK,CAACO,KAAK,CAAC;QACjC;QACAD,MAAME,MAAM,GAAGZ,UAAU,IAAI,CAACY,MAAM;QACpCF,MAAMG,IAAI,GAAGb,UAAU,IAAI,CAACa,IAAI;QAChCH,MAAMI,IAAI,GAAG,IAAI,CAACA,IAAI;QACtB,OAAOJ;IACT;IApDAK,YAAYX,KAA0B,CAAE;QAuBxCA,uBAAAA,SAAAA,KAAAA;QAEAQ,uBAAAA,UAAAA,KAAAA;QAEAC,uBAAAA,QAAAA,KAAAA;QAEAC,uBAAAA,QAAAA,KAAAA;QA5BE,IAAIE;QACJ,IAAI,OAAOZ,UAAU,YAAYA,iBAAiBa,YAAY;YAC5DD,UAAU;gBAAEZ;YAAM;QACpB,OAAO;YACLY,UAAUZ;QACZ;QAEA,IAAI,CAACA,KAAK,GAAGY,SAASZ,SAAS;QAC/B,wDAAwD;QACxD,gEAAgE;QAChE,4DAA4D;QAC5D,EAAE;QACF,wEAAwE;QACxE,4EAA4E;QAC5E,8EAA8E;QAC9E,EAAE;QACF,iDAAiD;QACjD,IAAI,CAACQ,MAAM,GAAGI,SAASJ,UAAWP;QAClC,IAAI,CAACQ,IAAI,GAAGG,SAASH,QAAQ,CAAC;QAC9B,IAAI,CAACC,IAAI,GAAGE,SAASF,QAAQ;IAC/B;AAgCF"}
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"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/virtual-file/toVirtualFile.ts"],"sourcesContent":["import { promises as fsPromises } from 'fs';\n\nimport { VirtualFile } from './VirtualFile';\n\n/**\n * Reads a file from filesystem and creates a vfile.\n *\n * @param path - Filesystem path to load the contents from.\n * @param encoding - Optional encoding to pass down to fs.readFile.\n * @returns Promise returning VFile with loaded file contents.\n */\nexport async function readVirtualFile(\n path: string,\n encoding: BufferEncoding | null = null,\n) {\n return new VirtualFile({\n path,\n value: await fsPromises.readFile(path, { encoding }),\n });\n}\n\ntype WriteVFileOptions = Exclude<\n Parameters<typeof fsPromises['writeFile']>[2],\n undefined\n>;\n\n/**\n * Writes vfile to filesystem.\n *\n * @param vfile - The vfile to write.\n * @param options - Options to pass down to fs.writeFile.\n */\nexport async function writeVirtualFile(\n vfile: VirtualFile,\n options?: WriteVFileOptions,\n) {\n return fsPromises.writeFile(vfile.path, vfile.value, options);\n}\n"],"names":["promises","fsPromises","VirtualFile","readVirtualFile","path","encoding","value","readFile","writeVirtualFile","vfile","options","writeFile"],"mappings":"AAAA,SAASA,YAAYC,UAAU,QAAQ,KAAK;AAE5C,SAASC,WAAW,QAAQ,gBAAgB;AAE5C;;;;;;CAMC,GACD,OAAO,eAAeC,gBACpBC,IAAY,EACZC,WAAkC,IAAI;IAEtC,OAAO,IAAIH,YAAY;QACrBE;QACAE,OAAO,MAAML,WAAWM,QAAQ,CAACH,MAAM;YAAEC;QAAS;IACpD;AACF;AAOA;;;;;CAKC,GACD,OAAO,eAAeG,iBACpBC,KAAkB,EAClBC,OAA2B;IAE3B,OAAOT,WAAWU,SAAS,CAACF,MAAML,IAAI,EAAEK,MAAMH,KAAK,EAAEI;AACvD"}
1
+ {"version":3,"sources":["../../../src/virtual-file/toVirtualFile.ts"],"sourcesContent":["import { promises as fsPromises } from 'fs';\n\nimport { VirtualFile } from './VirtualFile';\n\n/**\n * Reads a file from filesystem and creates a vfile.\n *\n * @param path - Filesystem path to load the contents from.\n * @param encoding - Optional encoding to pass down to fs.readFile.\n * @returns Promise returning VFile with loaded file contents.\n */\nexport async function readVirtualFile(\n path: string,\n encoding: BufferEncoding | null = null,\n) {\n return new VirtualFile({\n path,\n value: await fsPromises.readFile(path, { encoding }),\n });\n}\n\ntype WriteVFileOptions = Exclude<\n Parameters<(typeof fsPromises)['writeFile']>[2],\n undefined\n>;\n\n/**\n * Writes vfile to filesystem.\n *\n * @param vfile - The vfile to write.\n * @param options - Options to pass down to fs.writeFile.\n */\nexport async function writeVirtualFile(\n vfile: VirtualFile,\n options?: WriteVFileOptions,\n) {\n return fsPromises.writeFile(vfile.path, vfile.value, options);\n}\n"],"names":["promises","fsPromises","VirtualFile","readVirtualFile","path","encoding","value","readFile","writeVirtualFile","vfile","options","writeFile"],"mappings":"AAAA,SAASA,YAAYC,UAAU,QAAQ,KAAK;AAE5C,SAASC,WAAW,QAAQ,gBAAgB;AAE5C;;;;;;CAMC,GACD,OAAO,eAAeC,gBACpBC,IAAY,EACZC,WAAkC,IAAI;IAEtC,OAAO,IAAIH,YAAY;QACrBE;QACAE,OAAO,MAAML,WAAWM,QAAQ,CAACH,MAAM;YAAEC;QAAS;IACpD;AACF;AAOA;;;;;CAKC,GACD,OAAO,eAAeG,iBACpBC,KAAkB,EAClBC,OAA2B;IAE3B,OAAOT,WAAWU,SAAS,CAACF,MAAML,IAAI,EAAEK,MAAMH,KAAK,EAAEI;AACvD"}
@@ -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;
@@ -19,6 +19,10 @@ export declare enum SnapCaveatType {
19
19
  * The origins that a Snap can receive JSON-RPC messages from.
20
20
  */
21
21
  RpcOrigin = "rpcOrigin",
22
+ /**
23
+ * The origins that a Snap can receive keyring messages from.
24
+ */
25
+ KeyringOrigin = "keyringOrigin",
22
26
  /**
23
27
  * Caveat specifying the snap IDs that can be interacted with.
24
28
  */
@@ -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];
@@ -8,7 +8,8 @@ export declare enum HandlerType {
8
8
  OnCronjob = "onCronjob",
9
9
  OnInstall = "onInstall",
10
10
  OnUpdate = "onUpdate",
11
- OnNameLookup = "onNameLookup"
11
+ OnNameLookup = "onNameLookup",
12
+ OnKeyringRequest = "onKeyringRequest"
12
13
  }
13
14
  declare type SnapHandler = {
14
15
  /**
@@ -62,6 +63,11 @@ export declare const SNAP_EXPORTS: {
62
63
  readonly required: false;
63
64
  readonly validator: (snapExport: unknown) => snapExport is LifecycleEventHandler;
64
65
  };
66
+ readonly onKeyringRequest: {
67
+ readonly type: HandlerType.OnKeyringRequest;
68
+ readonly required: true;
69
+ readonly validator: (snapExport: unknown) => snapExport is OnKeyringRequestHandler<JsonRpcParams>;
70
+ };
65
71
  };
66
72
  /**
67
73
  * The `onRpcRequest` handler. This is called whenever a JSON-RPC request is
@@ -142,6 +148,19 @@ export declare type OnInstallHandler = LifecycleEventHandler;
142
148
  * This type is an alias for {@link LifecycleEventHandler}.
143
149
  */
144
150
  export declare type OnUpdateHandler = LifecycleEventHandler;
151
+ /**
152
+ * The `onKeyringRequest` handler. This is called by the MetaMask client for
153
+ * privileged keyring actions.
154
+ *
155
+ * @param args - The request arguments.
156
+ * @param args.origin - The origin of the request. This can be the ID of
157
+ * another snap, or the URL of a dapp.
158
+ * @param args.request - The JSON-RPC request sent to the snap.
159
+ */
160
+ export declare type OnKeyringRequestHandler<Params extends JsonRpcParams = JsonRpcParams> = (args: {
161
+ origin: string;
162
+ request: JsonRpcRequest<Params>;
163
+ }) => Promise<unknown>;
145
164
  /**
146
165
  * Utility type for getting the handler function type from a handler type.
147
166
  */
@@ -187,7 +206,7 @@ export declare type OnNameLookupHandler = (args: OnNameLookupArgs) => Promise<On
187
206
  * All the function-based handlers that a snap can implement.
188
207
  */
189
208
  export declare type SnapFunctionExports = {
190
- [Key in keyof typeof SNAP_EXPORTS]?: HandlerFunction<typeof SNAP_EXPORTS[Key]>;
209
+ [Key in keyof typeof SNAP_EXPORTS]?: HandlerFunction<(typeof SNAP_EXPORTS)[Key]>;
191
210
  };
192
211
  /**
193
212
  * All handlers that a snap can implement.
@@ -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';
@@ -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';
@@ -1,3 +1,4 @@
1
+ export * from './errors';
1
2
  export * from './handlers';
2
3
  export * from './logging';
3
4
  export * from './namespace';
@@ -1,11 +1,14 @@
1
- import type { Json, JsonRpcSuccess, AssertionErrorConstructor } from '@metamask/utils';
1
+ import { SubjectType } from '@metamask/permission-controller';
2
+ import type { AssertionErrorConstructor, Json, JsonRpcSuccess } from '@metamask/utils';
2
3
  import type { Infer } from 'superstruct';
3
4
  export declare const RpcOriginsStruct: import("superstruct").Struct<{
4
5
  dapps?: boolean | undefined;
5
6
  snaps?: boolean | undefined;
7
+ allowedOrigins?: string[] | undefined;
6
8
  }, {
7
9
  dapps: import("superstruct").Struct<boolean | undefined, null>;
8
10
  snaps: import("superstruct").Struct<boolean | undefined, null>;
11
+ allowedOrigins: import("superstruct").Struct<string[] | undefined, import("superstruct").Struct<string, null>>;
9
12
  }>;
10
13
  export declare type RpcOrigins = Infer<typeof RpcOriginsStruct>;
11
14
  /**
@@ -17,6 +20,30 @@ export declare type RpcOrigins = Infer<typeof RpcOriginsStruct>;
17
20
  * @throws If the value is not a valid {@link RpcOrigins} object.
18
21
  */
19
22
  export declare function assertIsRpcOrigins(value: unknown, ErrorWrapper?: AssertionErrorConstructor): asserts value is RpcOrigins;
23
+ export declare const KeyringOriginsStruct: import("superstruct").Struct<{
24
+ allowedOrigins?: string[] | undefined;
25
+ }, {
26
+ allowedOrigins: import("superstruct").Struct<string[] | undefined, import("superstruct").Struct<string, null>>;
27
+ }>;
28
+ export declare type KeyringOrigins = Infer<typeof KeyringOriginsStruct>;
29
+ /**
30
+ * Assert that the given value is a valid {@link KeyringOrigins} object.
31
+ *
32
+ * @param value - The value to assert.
33
+ * @param ErrorWrapper - An optional error wrapper to use. Defaults to
34
+ * {@link AssertionError}.
35
+ * @throws If the value is not a valid {@link KeyringOrigins} object.
36
+ */
37
+ export declare function assertIsKeyringOrigins(value: unknown, ErrorWrapper?: AssertionErrorConstructor): asserts value is KeyringOrigins;
38
+ /**
39
+ * Check if the given origin is allowed by the given JSON-RPC origins object.
40
+ *
41
+ * @param origins - The JSON-RPC origins object.
42
+ * @param subjectType - The type of the origin.
43
+ * @param origin - The origin to check.
44
+ * @returns Whether the origin is allowed.
45
+ */
46
+ export declare function isOriginAllowed(origins: RpcOrigins, subjectType: SubjectType, origin: string): boolean;
20
47
  /**
21
48
  * Assert that the given value is a successful JSON-RPC response. If the value
22
49
  * is not a success response, an error is thrown. If the value is an JSON-RPC
@@ -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;
@@ -55,8 +55,12 @@ export declare const PermissionsStruct: Struct<{
55
55
  'endowment:rpc'?: {
56
56
  dapps?: boolean | undefined;
57
57
  snaps?: boolean | undefined;
58
+ allowedOrigins?: string[] | undefined;
58
59
  } | undefined;
59
60
  'endowment:name-lookup'?: string[] | undefined;
61
+ 'endowment:keyring'?: {
62
+ allowedOrigins?: string[] | undefined;
63
+ } | undefined;
60
64
  snap_dialog?: {} | undefined;
61
65
  snap_confirm?: {} | undefined;
62
66
  snap_manageState?: {} | undefined;
@@ -130,11 +134,18 @@ export declare const PermissionsStruct: Struct<{
130
134
  'endowment:rpc': Struct<{
131
135
  dapps?: boolean | undefined;
132
136
  snaps?: boolean | undefined;
137
+ allowedOrigins?: string[] | undefined;
133
138
  } | undefined, {
134
139
  dapps: Struct<boolean | undefined, null>;
135
140
  snaps: Struct<boolean | undefined, null>;
141
+ allowedOrigins: Struct<string[] | undefined, Struct<string, null>>;
136
142
  }>;
137
143
  'endowment:name-lookup': Struct<string[] | undefined, Struct<string, null>>;
144
+ 'endowment:keyring': Struct<{
145
+ allowedOrigins?: string[] | undefined;
146
+ } | undefined, {
147
+ allowedOrigins: Struct<string[] | undefined, Struct<string, null>>;
148
+ }>;
138
149
  snap_dialog: Struct<{} | undefined, {}>;
139
150
  snap_confirm: Struct<{} | undefined, {}>;
140
151
  snap_manageState: Struct<{} | undefined, {}>;
@@ -179,6 +190,7 @@ export declare const PermissionsStruct: Struct<{
179
190
  }> | undefined, null>;
180
191
  }>;
181
192
  export declare type SnapPermissions = Infer<typeof PermissionsStruct>;
193
+ export declare const SnapAuxilaryFilesStruct: Struct<string[], Struct<string, null>>;
182
194
  export declare const SnapManifestStruct: Struct<{
183
195
  description: string;
184
196
  version: import("@metamask/utils").SemVerVersion;
@@ -193,6 +205,7 @@ export declare const SnapManifestStruct: Struct<{
193
205
  };
194
206
  };
195
207
  shasum: string;
208
+ files?: string[] | undefined;
196
209
  };
197
210
  initialPermissions: {
198
211
  'endowment:network-access'?: {} | undefined;
@@ -214,8 +227,12 @@ export declare const SnapManifestStruct: Struct<{
214
227
  'endowment:rpc'?: {
215
228
  dapps?: boolean | undefined;
216
229
  snaps?: boolean | undefined;
230
+ allowedOrigins?: string[] | undefined;
217
231
  } | undefined;
218
232
  'endowment:name-lookup'?: string[] | undefined;
233
+ 'endowment:keyring'?: {
234
+ allowedOrigins?: string[] | undefined;
235
+ } | undefined;
219
236
  snap_dialog?: {} | undefined;
220
237
  snap_confirm?: {} | undefined;
221
238
  snap_manageState?: {} | undefined;
@@ -264,6 +281,7 @@ export declare const SnapManifestStruct: Struct<{
264
281
  };
265
282
  };
266
283
  shasum: string;
284
+ files?: string[] | undefined;
267
285
  }, {
268
286
  shasum: Struct<string, null>;
269
287
  location: Struct<{
@@ -286,6 +304,7 @@ export declare const SnapManifestStruct: Struct<{
286
304
  registry: Struct<"https://registry.npmjs.org" | "https://registry.npmjs.org/", null>;
287
305
  }>;
288
306
  }>;
307
+ files: Struct<string[] | undefined, Struct<string, null>>;
289
308
  }>;
290
309
  initialPermissions: Struct<{
291
310
  'endowment:network-access'?: {} | undefined;
@@ -307,8 +326,12 @@ export declare const SnapManifestStruct: Struct<{
307
326
  'endowment:rpc'?: {
308
327
  dapps?: boolean | undefined;
309
328
  snaps?: boolean | undefined;
329
+ allowedOrigins?: string[] | undefined;
310
330
  } | undefined;
311
331
  'endowment:name-lookup'?: string[] | undefined;
332
+ 'endowment:keyring'?: {
333
+ allowedOrigins?: string[] | undefined;
334
+ } | undefined;
312
335
  snap_dialog?: {} | undefined;
313
336
  snap_confirm?: {} | undefined;
314
337
  snap_manageState?: {} | undefined;
@@ -382,11 +405,18 @@ export declare const SnapManifestStruct: Struct<{
382
405
  'endowment:rpc': Struct<{
383
406
  dapps?: boolean | undefined;
384
407
  snaps?: boolean | undefined;
408
+ allowedOrigins?: string[] | undefined;
385
409
  } | undefined, {
386
410
  dapps: Struct<boolean | undefined, null>;
387
411
  snaps: Struct<boolean | undefined, null>;
412
+ allowedOrigins: Struct<string[] | undefined, Struct<string, null>>;
388
413
  }>;
389
414
  'endowment:name-lookup': Struct<string[] | undefined, Struct<string, null>>;
415
+ 'endowment:keyring': Struct<{
416
+ allowedOrigins?: string[] | undefined;
417
+ } | undefined, {
418
+ allowedOrigins: Struct<string[] | undefined, Struct<string, null>>;
419
+ }>;
390
420
  snap_dialog: Struct<{} | undefined, {}>;
391
421
  snap_confirm: Struct<{} | undefined, {}>;
392
422
  snap_manageState: Struct<{} | undefined, {}>;
@@ -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, SemVerVersion, Opaque } from '@metamask/utils';
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 { SnapFiles, SnapId, SnapsPermissionRequest } from './types';
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: SerializedEthereumRpcError;
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: Pick<SnapFiles, 'manifest' | 'sourceCode' | 'svgIcon'>): string;
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: Pick<SnapFiles, 'manifest' | 'sourceCode' | 'svgIcon'>, errorMessage?: string): void;
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>;
@@ -53,6 +53,7 @@ export declare type UnvalidatedSnapFiles = {
53
53
  packageJson?: VirtualFile<Json>;
54
54
  sourceCode?: VirtualFile;
55
55
  svgIcon?: VirtualFile;
56
+ auxiliaryFiles: VirtualFile[];
56
57
  };
57
58
  /**
58
59
  * An object for storing the contents of Snap files that have passed JSON
@@ -63,7 +64,12 @@ export declare type SnapFiles = {
63
64
  packageJson: VirtualFile<NpmSnapPackageJson>;
64
65
  sourceCode: VirtualFile;
65
66
  svgIcon?: VirtualFile;
67
+ auxiliaryFiles: VirtualFile[];
66
68
  };
69
+ /**
70
+ * A subset of snap files extracted from a fetched snap.
71
+ */
72
+ export declare type FetchedSnapFiles = Pick<SnapFiles, 'manifest' | 'sourceCode' | 'svgIcon' | 'auxiliaryFiles'>;
67
73
  /**
68
74
  * The possible prefixes for snap ids.
69
75
  */
@@ -1,8 +1,8 @@
1
- import type { SnapFiles } from './types';
1
+ import type { FetchedSnapFiles } from './types';
2
2
  /**
3
3
  * Validates the files contained in a fetched snap.
4
4
  *
5
5
  * @param files - All potentially included files in a fetched snap.
6
6
  * @throws If any of the files are considered invalid.
7
7
  */
8
- export declare function validateFetchedSnap(files: Pick<SnapFiles, 'manifest' | 'sourceCode' | 'svgIcon'>): void;
8
+ export declare function validateFetchedSnap(files: FetchedSnapFiles): void;
@@ -10,7 +10,7 @@ import { VirtualFile } from './VirtualFile';
10
10
  * @returns Promise returning VFile with loaded file contents.
11
11
  */
12
12
  export declare function readVirtualFile(path: string, encoding?: BufferEncoding | null): Promise<VirtualFile<unknown>>;
13
- declare type WriteVFileOptions = Exclude<Parameters<typeof fsPromises['writeFile']>[2], undefined>;
13
+ declare type WriteVFileOptions = Exclude<Parameters<(typeof fsPromises)['writeFile']>[2], undefined>;
14
14
  /**
15
15
  * Writes vfile to filesystem.
16
16
  *