@metamask/snaps-utils 3.1.0 → 3.3.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 +12 -1
- package/dist/cjs/eval-worker.js +2 -2
- package/dist/cjs/eval-worker.js.map +1 -1
- package/dist/cjs/handler-types.js +32 -0
- package/dist/cjs/handler-types.js.map +1 -0
- package/dist/cjs/handlers.js +37 -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 +1 -0
- package/dist/cjs/index.executionenv.js.map +1 -1
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/localization.js +113 -0
- package/dist/cjs/localization.js.map +1 -0
- package/dist/cjs/manifest/manifest.js +23 -9
- package/dist/cjs/manifest/manifest.js.map +1 -1
- package/dist/cjs/manifest/validation.js +3 -2
- package/dist/cjs/manifest/validation.js.map +1 -1
- package/dist/cjs/npm.js +16 -3
- package/dist/cjs/npm.js.map +1 -1
- 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 +2 -0
- package/dist/cjs/validation.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 +14 -0
- package/dist/esm/handler-types.js.map +1 -0
- package/dist/esm/handlers.js +17 -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 +1 -0
- package/dist/esm/index.executionenv.js.map +1 -1
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/localization.js +115 -0
- package/dist/esm/localization.js.map +1 -0
- package/dist/esm/manifest/manifest.js +30 -12
- package/dist/esm/manifest/manifest.js.map +1 -1
- package/dist/esm/manifest/validation.js +4 -3
- package/dist/esm/manifest/validation.js.map +1 -1
- package/dist/esm/npm.js +16 -3
- package/dist/esm/npm.js.map +1 -1
- 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 +2 -0
- package/dist/esm/validation.js.map +1 -1
- package/dist/types/handler-types.d.ts +32 -0
- package/dist/types/handlers.d.ts +95 -36
- package/dist/types/index.browser.d.ts +2 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.executionenv.d.ts +1 -0
- package/dist/types/localization.d.ts +143 -0
- package/dist/types/manifest/manifest.d.ts +15 -6
- package/dist/types/manifest/validation.d.ts +5 -2
- package/dist/types/snaps.d.ts +5 -0
- package/dist/types/types.d.ts +6 -10
- package/package.json +2 -2
package/dist/esm/npm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/npm.ts"],"sourcesContent":["import { assertIsSnapIcon } from './icon';\nimport { validateNpmSnapManifest } from './manifest/manifest';\nimport { assertIsSnapManifest } from './manifest/validation';\nimport type { SnapFiles, UnvalidatedSnapFiles } from './types';\nimport { assertIsNpmSnapPackageJson, NpmSnapFileNames } from './types';\n\nexport const EXPECTED_SNAP_FILES = [\n 'manifest',\n 'packageJson',\n 'sourceCode',\n] as const;\n\nexport const SnapFileNameFromKey = {\n manifest: NpmSnapFileNames.Manifest,\n packageJson: NpmSnapFileNames.PackageJson,\n sourceCode: 'source code bundle',\n} as const;\n\n// TODO: Refactor this to be more shared with other validation.\n\n/**\n * Validates the files extracted from an npm Snap package tarball by ensuring\n * that they're non-empty and that the Json files match their respective schemas\n * and the Snaps publishing specification.\n *\n * @param snapFiles - The object containing the expected Snap file contents,\n * if any.\n * @param errorPrefix - The prefix of the error message.\n * @returns A tuple of the Snap manifest object and the Snap source code.\n */\nexport function validateNpmSnap(\n snapFiles: UnvalidatedSnapFiles,\n errorPrefix?: `${string}: `,\n): SnapFiles {\n EXPECTED_SNAP_FILES.forEach((key) => {\n if (!snapFiles[key]) {\n throw new Error(\n `${errorPrefix ?? ''}Missing file \"${SnapFileNameFromKey[key]}\".`,\n );\n }\n });\n\n // Typecast: We are assured that the required files exist if we get here.\n const {
|
|
1
|
+
{"version":3,"sources":["../../src/npm.ts"],"sourcesContent":["import { assertIsSnapIcon } from './icon';\nimport {\n getValidatedLocalizationFiles,\n validateSnapManifestLocalizations,\n} from './localization';\nimport { validateNpmSnapManifest } from './manifest/manifest';\nimport { assertIsSnapManifest } from './manifest/validation';\nimport type { SnapFiles, UnvalidatedSnapFiles } from './types';\nimport { assertIsNpmSnapPackageJson, NpmSnapFileNames } from './types';\n\nexport const EXPECTED_SNAP_FILES = [\n 'manifest',\n 'packageJson',\n 'sourceCode',\n] as const;\n\nexport const SnapFileNameFromKey = {\n manifest: NpmSnapFileNames.Manifest,\n packageJson: NpmSnapFileNames.PackageJson,\n sourceCode: 'source code bundle',\n} as const;\n\n// TODO: Refactor this to be more shared with other validation.\n\n/**\n * Validates the files extracted from an npm Snap package tarball by ensuring\n * that they're non-empty and that the Json files match their respective schemas\n * and the Snaps publishing specification.\n *\n * @param snapFiles - The object containing the expected Snap file contents,\n * if any.\n * @param errorPrefix - The prefix of the error message.\n * @returns A tuple of the Snap manifest object and the Snap source code.\n */\nexport function validateNpmSnap(\n snapFiles: UnvalidatedSnapFiles,\n errorPrefix?: `${string}: `,\n): SnapFiles {\n EXPECTED_SNAP_FILES.forEach((key) => {\n if (!snapFiles[key]) {\n throw new Error(\n `${errorPrefix ?? ''}Missing file \"${SnapFileNameFromKey[key]}\".`,\n );\n }\n });\n\n // Typecast: We are assured that the required files exist if we get here.\n const {\n manifest,\n packageJson,\n sourceCode,\n svgIcon,\n auxiliaryFiles,\n localizationFiles,\n } = snapFiles as SnapFiles;\n\n try {\n assertIsSnapManifest(manifest.result);\n } catch (error) {\n throw new Error(`${errorPrefix ?? ''}${error.message}`);\n }\n const validatedManifest = manifest;\n\n const { iconPath } = validatedManifest.result.source.location.npm;\n if (iconPath && !svgIcon) {\n throw new Error(`Missing file \"${iconPath}\".`);\n }\n\n try {\n assertIsNpmSnapPackageJson(packageJson.result);\n } catch (error) {\n throw new Error(`${errorPrefix ?? ''}${error.message}`);\n }\n\n const validatedPackageJson = packageJson;\n validateNpmSnapManifest({\n manifest: validatedManifest,\n packageJson: validatedPackageJson,\n sourceCode,\n svgIcon,\n auxiliaryFiles,\n localizationFiles,\n });\n\n if (svgIcon) {\n try {\n assertIsSnapIcon(svgIcon);\n } catch (error) {\n throw new Error(`${errorPrefix ?? ''}${error.message}`);\n }\n }\n\n if (localizationFiles) {\n try {\n // This function validates and returns the localization files. We don't\n // use the return value here, but we do want to validate the files.\n getValidatedLocalizationFiles(localizationFiles);\n\n validateSnapManifestLocalizations(\n manifest.result,\n localizationFiles.map((file) => file.result),\n );\n } catch (error) {\n throw new Error(`${errorPrefix ?? ''}${error.message}`);\n }\n }\n\n return {\n manifest: validatedManifest,\n packageJson: validatedPackageJson,\n sourceCode,\n svgIcon,\n auxiliaryFiles,\n localizationFiles,\n };\n}\n"],"names":["assertIsSnapIcon","getValidatedLocalizationFiles","validateSnapManifestLocalizations","validateNpmSnapManifest","assertIsSnapManifest","assertIsNpmSnapPackageJson","NpmSnapFileNames","EXPECTED_SNAP_FILES","SnapFileNameFromKey","manifest","Manifest","packageJson","PackageJson","sourceCode","validateNpmSnap","snapFiles","errorPrefix","forEach","key","Error","svgIcon","auxiliaryFiles","localizationFiles","result","error","message","validatedManifest","iconPath","source","location","npm","validatedPackageJson","map","file"],"mappings":"AAAA,SAASA,gBAAgB,QAAQ,SAAS;AAC1C,SACEC,6BAA6B,EAC7BC,iCAAiC,QAC5B,iBAAiB;AACxB,SAASC,uBAAuB,QAAQ,sBAAsB;AAC9D,SAASC,oBAAoB,QAAQ,wBAAwB;AAE7D,SAASC,0BAA0B,EAAEC,gBAAgB,QAAQ,UAAU;AAEvE,OAAO,MAAMC,sB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,OAAO;YACd,MAAM,IAAIL,MAAM,CAAC,EAAEH,eAAe,GAAG,EAAEQ,MAAMC,OAAO,CAAC,CAAC;QACxD;IACF;IAEA,IAAIH,mBAAmB;QACrB,IAAI;YACF,uEAAuE;YACvE,mEAAmE;YACnErB,8BAA8BqB;YAE9BpB,kCACEO,SAASc,MAAM,EACfD,kBAAkBU,GAAG,CAAC,CAACC,OAASA,KAAKV,MAAM;QAE/C,EAAE,OAAOC,OAAO;YACd,MAAM,IAAIL,MAAM,CAAC,EAAEH,eAAe,GAAG,EAAEQ,MAAMC,OAAO,CAAC,CAAC;QACxD;IACF;IAEA,OAAO;QACLhB,UAAUiB;QACVf,aAAaoB;QACblB;QACAO;QACAC;QACAC;IACF;AACF"}
|
package/dist/esm/snaps.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/snaps.ts"],"sourcesContent":["import type {\n Caveat,\n SubjectPermissions,\n PermissionConstraint,\n} from '@metamask/permission-controller';\nimport type { BlockReason } from '@metamask/snaps-registry';\nimport type {\n Json,\n JsonRpcError,\n Opaque,\n SemVerVersion,\n} from '@metamask/utils';\nimport { assert, isObject, assertStruct } from '@metamask/utils';\nimport { base64 } from '@scure/base';\nimport stableStringify from 'fast-json-stable-stringify';\nimport type { Struct } from 'superstruct';\nimport {\n empty,\n enums,\n intersection,\n literal,\n pattern,\n refine,\n string,\n union,\n validate,\n} from 'superstruct';\nimport validateNPMPackage from 'validate-npm-package-name';\n\nimport { SnapCaveatType } from './caveats';\nimport { checksumFiles } from './checksum';\nimport type { SnapManifest, SnapPermissions } from './manifest/validation';\nimport type { FetchedSnapFiles, SnapId, SnapsPermissionRequest } from './types';\nimport { SnapIdPrefixes, SnapValidationFailureReason, uri } from './types';\nimport type { VirtualFile } from './virtual-file';\n\n// This RegEx matches valid npm package names (with some exceptions) and space-\n// separated alphanumerical words, optionally with dashes and underscores.\n// The RegEx consists of two parts. The first part matches space-separated\n// words. It is based on the following Stackoverflow answer:\n// https://stackoverflow.com/a/34974982\n// The second part, after the pipe operator, is the same RegEx used for the\n// `name` field of the official package.json JSON Schema, except that we allow\n// mixed-case letters. It was originally copied from:\n// https://github.com/SchemaStore/schemastore/blob/81a16897c1dabfd98c72242a5fd62eb080ff76d8/src/schemas/json/package.json#L132-L138\nexport const PROPOSED_NAME_REGEX =\n /^(?:[A-Za-z0-9-_]+( [A-Za-z0-9-_]+)*)|(?:(?:@[A-Za-z0-9-*~][A-Za-z0-9-*._~]*\\/)?[A-Za-z0-9-~][A-Za-z0-9-._~]*)$/u;\n\n/**\n * wallet_enable / wallet_installSnaps permission typing.\n *\n * @deprecated This type is confusing and not descriptive, people confused it with typing initialPermissions, remove when removing wallet_enable.\n */\nexport type RequestedSnapPermissions = {\n [permission: string]: Record<string, Json>;\n};\n\nexport enum SnapStatus {\n Installing = 'installing',\n Updating = 'updating',\n Running = 'running',\n Stopped = 'stopped',\n Crashed = 'crashed',\n}\n\nexport enum SnapStatusEvents {\n Start = 'START',\n Stop = 'STOP',\n Crash = 'CRASH',\n Update = 'UPDATE',\n}\n\nexport type StatusContext = { snapId: ValidatedSnapId };\nexport type StatusEvents = { type: SnapStatusEvents };\nexport type StatusStates = {\n value: SnapStatus;\n context: StatusContext;\n};\nexport type Status = StatusStates['value'];\n\nexport type VersionHistory = {\n origin: string;\n version: string;\n // Unix timestamp\n date: number;\n};\n\nexport type SnapAuxilaryFile = {\n path: string;\n // Value here should be stored as base64\n value: string;\n};\n\nexport type PersistedSnap = Snap;\n\n/**\n * A Snap as it exists in {@link SnapController} state.\n */\nexport type Snap = {\n /**\n * Whether the Snap is enabled, which determines if it can be started.\n */\n enabled: boolean;\n\n /**\n * The ID of the Snap.\n */\n id: ValidatedSnapId;\n\n /**\n * The initial permissions of the Snap, which will be requested when it is\n * installed.\n */\n initialPermissions: SnapPermissions;\n\n /**\n * The source code of the Snap.\n */\n sourceCode: string;\n\n /**\n * The Snap's manifest file.\n */\n manifest: SnapManifest;\n\n /**\n * Whether the Snap is blocked.\n */\n blocked: boolean;\n\n /**\n * Information detailing why the snap is blocked.\n */\n blockInformation?: BlockReason;\n\n /**\n * The current status of the Snap, e.g. whether it's running or stopped.\n */\n status: Status;\n\n /**\n * The version of the Snap.\n */\n version: SemVerVersion;\n\n /**\n * The version history of the Snap.\n * Can be used to derive when the Snap was installed, when it was updated to a certain version and who requested the change.\n */\n versionHistory: VersionHistory[];\n\n /**\n * Static auxiliary files that can be loaded at runtime.\n */\n auxiliaryFiles?: SnapAuxilaryFile[];\n};\n\nexport type TruncatedSnapFields =\n | 'id'\n | 'initialPermissions'\n | 'version'\n | 'enabled'\n | 'blocked';\n\n/**\n * A {@link Snap} object with the fields that are relevant to an external\n * caller.\n */\nexport type TruncatedSnap = Pick<Snap, TruncatedSnapFields>;\n\nexport type ProcessSnapResult = TruncatedSnap | { error: JsonRpcError };\n\nexport type InstallSnapsResult = Record<SnapId, ProcessSnapResult>;\n\n/**\n * An error indicating that a Snap validation failure is programmatically\n * fixable during development.\n */\nexport class ProgrammaticallyFixableSnapError extends Error {\n reason: SnapValidationFailureReason;\n\n constructor(message: string, reason: SnapValidationFailureReason) {\n super(message);\n this.reason = reason;\n }\n}\n\n/**\n * Gets a checksummable manifest by removing the shasum property and reserializing the JSON using a deterministic algorithm.\n *\n * @param manifest - The manifest itself.\n * @returns A virtual file containing the checksummable manifest.\n */\nfunction getChecksummableManifest(\n manifest: VirtualFile<SnapManifest>,\n): VirtualFile {\n const manifestCopy = manifest.clone() as VirtualFile<any>;\n delete manifestCopy.result.source.shasum;\n\n // We use fast-json-stable-stringify to deterministically serialize the JSON\n // This is required before checksumming so we get reproducible checksums across platforms etc\n manifestCopy.value = stableStringify(manifestCopy.result);\n return manifestCopy;\n}\n\n/**\n * Calculates the Base64-encoded SHA-256 digest of all required Snap files.\n *\n * @param files - All required Snap files to be included in the checksum.\n * @returns The Base64-encoded SHA-256 digest of the source code.\n */\nexport function getSnapChecksum(files: FetchedSnapFiles): string {\n const { manifest, sourceCode, svgIcon, auxiliaryFiles } = files;\n const all = [\n getChecksummableManifest(manifest),\n sourceCode,\n svgIcon,\n ...auxiliaryFiles,\n ].filter((file) => file !== undefined);\n return base64.encode(checksumFiles(all as VirtualFile[]));\n}\n\n/**\n * Checks whether the `source.shasum` property of a Snap manifest matches the\n * shasum of the snap.\n *\n * @param files - All required Snap files to be included in the checksum.\n * @param errorMessage - The error message to throw if validation fails.\n */\nexport function validateSnapShasum(\n files: FetchedSnapFiles,\n errorMessage = 'Invalid Snap manifest: manifest shasum does not match computed shasum.',\n): void {\n if (files.manifest.result.source.shasum !== getSnapChecksum(files)) {\n throw new ProgrammaticallyFixableSnapError(\n errorMessage,\n SnapValidationFailureReason.ShasumMismatch,\n );\n }\n}\n\nexport const LOCALHOST_HOSTNAMES = ['localhost', '127.0.0.1', '[::1]'] as const;\n\n// Require snap ids to only consist of printable ASCII characters\nexport const BaseSnapIdStruct = pattern(string(), /^[\\x21-\\x7E]*$/u);\n\nconst LocalSnapIdSubUrlStruct = uri({\n protocol: enums(['http:', 'https:']),\n hostname: enums(LOCALHOST_HOSTNAMES),\n hash: empty(string()),\n search: empty(string()),\n});\nexport const LocalSnapIdStruct = refine(\n BaseSnapIdStruct,\n 'local Snap Id',\n (value) => {\n if (!value.startsWith(SnapIdPrefixes.local)) {\n return `Expected local snap ID, got \"${value}\".`;\n }\n\n const [error] = validate(\n value.slice(SnapIdPrefixes.local.length),\n LocalSnapIdSubUrlStruct,\n );\n return error ?? true;\n },\n);\nexport const NpmSnapIdStruct = intersection([\n BaseSnapIdStruct,\n uri({\n protocol: literal(SnapIdPrefixes.npm),\n pathname: refine(string(), 'package name', function* (value) {\n const normalized = value.startsWith('/') ? value.slice(1) : value;\n const { errors, validForNewPackages, warnings } =\n validateNPMPackage(normalized);\n if (!validForNewPackages) {\n if (errors === undefined) {\n assert(warnings !== undefined);\n yield* warnings;\n } else {\n yield* errors;\n }\n }\n return true;\n }),\n search: empty(string()),\n hash: empty(string()),\n }),\n]) as unknown as Struct<string, null>;\n\nexport const HttpSnapIdStruct = intersection([\n BaseSnapIdStruct,\n uri({\n protocol: enums(['http:', 'https:']),\n search: empty(string()),\n hash: empty(string()),\n }),\n]) as unknown as Struct<string, null>;\n\nexport const SnapIdStruct = union([NpmSnapIdStruct, LocalSnapIdStruct]);\n\nexport type ValidatedSnapId = Opaque<string, typeof snapIdSymbol>;\ndeclare const snapIdSymbol: unique symbol;\n\n/**\n * Extracts the snap prefix from a snap ID.\n *\n * @param snapId - The snap ID to extract the prefix from.\n * @returns The snap prefix from a snap id, e.g. `npm:`.\n */\nexport function getSnapPrefix(snapId: string): SnapIdPrefixes {\n const prefix = Object.values(SnapIdPrefixes).find((possiblePrefix) =>\n snapId.startsWith(possiblePrefix),\n );\n if (prefix !== undefined) {\n return prefix;\n }\n throw new Error(`Invalid or no prefix found for \"${snapId}\"`);\n}\n\n/**\n * Strips snap prefix from a full snap ID.\n *\n * @param snapId - The snap ID to strip.\n * @returns The stripped snap ID.\n */\nexport function stripSnapPrefix(snapId: string): string {\n return snapId.replace(getSnapPrefix(snapId), '');\n}\n\n/**\n * Assert that the given value is a valid snap ID.\n *\n * @param value - The value to check.\n * @throws If the value is not a valid snap ID.\n */\nexport function assertIsValidSnapId(\n value: unknown,\n): asserts value is ValidatedSnapId {\n assertStruct(value, SnapIdStruct, 'Invalid snap ID');\n}\n\n/**\n * Typeguard to ensure a chainId follows the CAIP-2 standard.\n *\n * @param chainId - The chainId being tested.\n * @returns `true` if the value is a valid CAIP chain id, and `false` otherwise.\n */\nexport function isCaipChainId(chainId: unknown): chainId is string {\n return (\n typeof chainId === 'string' &&\n /^(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-a-zA-Z0-9]{1,32})$/u.test(\n chainId,\n )\n );\n}\n\n/**\n * Utility function to check if an origin has permission (and caveat) for a particular snap.\n *\n * @param permissions - An origin's permissions object.\n * @param snapId - The id of the snap.\n * @returns A boolean based on if an origin has the specified snap.\n */\nexport function isSnapPermitted(\n permissions: SubjectPermissions<PermissionConstraint>,\n snapId: SnapId,\n) {\n return Boolean(\n (\n (\n (permissions?.wallet_snap?.caveats?.find(\n (caveat) => caveat.type === SnapCaveatType.SnapIds,\n ) ?? {}) as Caveat<string, Json>\n ).value as Record<string, unknown>\n )?.[snapId],\n );\n}\n\n/**\n * Checks whether the passed in requestedPermissions is a valid\n * permission request for a `wallet_snap` permission.\n *\n * @param requestedPermissions - The requested permissions.\n * @throws If the criteria is not met.\n */\nexport function verifyRequestedSnapPermissions(\n requestedPermissions: unknown,\n): asserts requestedPermissions is SnapsPermissionRequest {\n assert(\n isObject(requestedPermissions),\n 'Requested permissions must be an object.',\n );\n\n const { wallet_snap: walletSnapPermission } = requestedPermissions;\n\n assert(\n isObject(walletSnapPermission),\n 'wallet_snap is missing from the requested permissions.',\n );\n\n const { caveats } = walletSnapPermission;\n\n assert(\n Array.isArray(caveats) && caveats.length === 1,\n 'wallet_snap must have a caveat property with a single-item array value.',\n );\n\n const [caveat] = caveats;\n\n assert(\n isObject(caveat) &&\n caveat.type === SnapCaveatType.SnapIds &&\n isObject(caveat.value),\n `The requested permissions do not have a valid ${SnapCaveatType.SnapIds} caveat.`,\n );\n}\n"],"names":["assert","isObject","assertStruct","base64","stableStringify","empty","enums","intersection","literal","pattern","refine","string","union","validate","validateNPMPackage","SnapCaveatType","checksumFiles","SnapIdPrefixes","SnapValidationFailureReason","uri","PROPOSED_NAME_REGEX","SnapStatus","Installing","Updating","Running","Stopped","Crashed","SnapStatusEvents","Start","Stop","Crash","Update","ProgrammaticallyFixableSnapError","Error","constructor","message","reason","getChecksummableManifest","manifest","manifestCopy","clone","result","source","shasum","value","getSnapChecksum","files","sourceCode","svgIcon","auxiliaryFiles","all","filter","file","undefined","encode","validateSnapShasum","errorMessage","ShasumMismatch","LOCALHOST_HOSTNAMES","BaseSnapIdStruct","LocalSnapIdSubUrlStruct","protocol","hostname","hash","search","LocalSnapIdStruct","startsWith","local","error","slice","length","NpmSnapIdStruct","npm","pathname","normalized","errors","validForNewPackages","warnings","HttpSnapIdStruct","SnapIdStruct","getSnapPrefix","snapId","prefix","Object","values","find","possiblePrefix","stripSnapPrefix","replace","assertIsValidSnapId","isCaipChainId","chainId","test","isSnapPermitted","permissions","Boolean","wallet_snap","caveats","caveat","type","SnapIds","verifyRequestedSnapPermissions","requestedPermissions","walletSnapPermission","Array","isArray"],"mappings":";;;;;;;;;;;;;AAYA,SAASA,MAAM,EAAEC,QAAQ,EAAEC,YAAY,QAAQ,kBAAkB;AACjE,SAASC,MAAM,QAAQ,cAAc;AACrC,OAAOC,qBAAqB,6BAA6B;AAEzD,SACEC,KAAK,EACLC,KAAK,EACLC,YAAY,EACZC,OAAO,EACPC,OAAO,EACPC,MAAM,EACNC,MAAM,EACNC,KAAK,EACLC,QAAQ,QACH,cAAc;AACrB,OAAOC,wBAAwB,4BAA4B;AAE3D,SAASC,cAAc,QAAQ,YAAY;AAC3C,SAASC,aAAa,QAAQ,aAAa;AAG3C,SAASC,cAAc,EAAEC,2BAA2B,EAAEC,GAAG,QAAQ,UAAU;AAG3E,+EAA+E;AAC/E,0EAA0E;AAC1E,0EAA0E;AAC1E,4DAA4D;AAC5D,uCAAuC;AACvC,2EAA2E;AAC3E,8EAA8E;AAC9E,qDAAqD;AACrD,mIAAmI;AACnI,OAAO,MAAMC,sBACX,mHAAmH;WAW9G;UAAKC,UAAU;IAAVA,WACVC,gBAAa;IADHD,WAEVE,cAAW;IAFDF,WAGVG,aAAU;IAHAH,WAIVI,aAAU;IAJAJ,WAKVK,aAAU;GALAL,eAAAA;WAQL;UAAKM,gBAAgB;IAAhBA,iBACVC,WAAQ;IADED,iBAEVE,UAAO;IAFGF,iBAGVG,WAAQ;IAHEH,iBAIVI,YAAS;GAJCJ,qBAAAA;AA6GZ;;;CAGC,GACD,OAAO,MAAMK,yCAAyCC;IAGpDC,YAAYC,OAAe,EAAEC,MAAmC,CAAE;QAChE,KAAK,CAACD;QAHRC,uBAAAA,UAAAA,KAAA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SAAS;AAC/C;AAEA;;;;;CAKC,GACD,OAAO,SAASQ,oBACd7C,KAAc;IAEd1C,aAAa0C,OAAOmC,cAAc;AACpC;AAEA;;;;;CAKC,GACD,OAAO,SAASW,cAAcC,OAAgB;IAC5C,OACE,OAAOA,YAAY,YACnB,+EAAmEC,IAAI,CACrED;AAGN;AAEA;;;;;;CAMC,GACD,OAAO,SAASE,gBACdC,WAAqD,EACrDb,MAAc;IAEd,OAAOc,QAEH,AACGD,CAAAA,aAAaE,aAAaC,SAASZ,KAClC,CAACa,SAAWA,OAAOC,IAAI,KAAKpF,eAAeqF,OAAO,KAC/C,CAAC,CAAA,EACNxD,KAAK,EACN,CAACqC,OAAO;AAEf;AAEA;;;;;;CAMC,GACD,OAAO,SAASoB,+BACdC,oBAA6B;IAE7BtG,OACEC,SAASqG,uBACT;IAGF,MAAM,EAAEN,aAAaO,oBAAoB,EAAE,GAAGD;IAE9CtG,OACEC,SAASsG,uBACT;IAGF,MAAM,EAAEN,OAAO,EAAE,GAAGM;IAEpBvG,OACEwG,MAAMC,OAAO,CAACR,YAAYA,QAAQ3B,MAAM,KAAK,GAC7C;IAGF,MAAM,CAAC4B,OAAO,GAAGD;IAEjBjG,OACEC,SAASiG,WACPA,OAAOC,IAAI,KAAKpF,eAAeqF,OAAO,IACtCnG,SAASiG,OAAOtD,KAAK,GACvB,CAAC,8CAA8C,EAAE7B,eAAeqF,OAAO,CAAC,QAAQ,CAAC;AAErF"}
|
|
1
|
+
{"version":3,"sources":["../../src/snaps.ts"],"sourcesContent":["import type {\n Caveat,\n SubjectPermissions,\n PermissionConstraint,\n} from '@metamask/permission-controller';\nimport type { BlockReason } from '@metamask/snaps-registry';\nimport type {\n Json,\n JsonRpcError,\n Opaque,\n SemVerVersion,\n} from '@metamask/utils';\nimport { assert, isObject, assertStruct } from '@metamask/utils';\nimport { base64 } from '@scure/base';\nimport stableStringify from 'fast-json-stable-stringify';\nimport type { Struct } from 'superstruct';\nimport {\n empty,\n enums,\n intersection,\n literal,\n pattern,\n refine,\n string,\n union,\n validate,\n} from 'superstruct';\nimport validateNPMPackage from 'validate-npm-package-name';\n\nimport { SnapCaveatType } from './caveats';\nimport { checksumFiles } from './checksum';\nimport type { LocalizationFile } from './localization';\nimport type { SnapManifest, SnapPermissions } from './manifest/validation';\nimport type { FetchedSnapFiles, SnapId, SnapsPermissionRequest } from './types';\nimport { SnapIdPrefixes, SnapValidationFailureReason, uri } from './types';\nimport type { VirtualFile } from './virtual-file';\n\n// This RegEx matches valid npm package names (with some exceptions) and space-\n// separated alphanumerical words, optionally with dashes and underscores.\n// The RegEx consists of two parts. The first part matches space-separated\n// words. It is based on the following Stackoverflow answer:\n// https://stackoverflow.com/a/34974982\n// The second part, after the pipe operator, is the same RegEx used for the\n// `name` field of the official package.json JSON Schema, except that we allow\n// mixed-case letters. It was originally copied from:\n// https://github.com/SchemaStore/schemastore/blob/81a16897c1dabfd98c72242a5fd62eb080ff76d8/src/schemas/json/package.json#L132-L138\nexport const PROPOSED_NAME_REGEX =\n /^(?:[A-Za-z0-9-_]+( [A-Za-z0-9-_]+)*)|(?:(?:@[A-Za-z0-9-*~][A-Za-z0-9-*._~]*\\/)?[A-Za-z0-9-~][A-Za-z0-9-._~]*)$/u;\n\n/**\n * wallet_enable / wallet_installSnaps permission typing.\n *\n * @deprecated This type is confusing and not descriptive, people confused it with typing initialPermissions, remove when removing wallet_enable.\n */\nexport type RequestedSnapPermissions = {\n [permission: string]: Record<string, Json>;\n};\n\nexport enum SnapStatus {\n Installing = 'installing',\n Updating = 'updating',\n Running = 'running',\n Stopped = 'stopped',\n Crashed = 'crashed',\n}\n\nexport enum SnapStatusEvents {\n Start = 'START',\n Stop = 'STOP',\n Crash = 'CRASH',\n Update = 'UPDATE',\n}\n\nexport type StatusContext = { snapId: ValidatedSnapId };\nexport type StatusEvents = { type: SnapStatusEvents };\nexport type StatusStates = {\n value: SnapStatus;\n context: StatusContext;\n};\nexport type Status = StatusStates['value'];\n\nexport type VersionHistory = {\n origin: string;\n version: string;\n // Unix timestamp\n date: number;\n};\n\nexport type SnapAuxilaryFile = {\n path: string;\n // Value here should be stored as base64\n value: string;\n};\n\nexport type PersistedSnap = Snap;\n\n/**\n * A Snap as it exists in {@link SnapController} state.\n */\nexport type Snap = {\n /**\n * Whether the Snap is enabled, which determines if it can be started.\n */\n enabled: boolean;\n\n /**\n * The ID of the Snap.\n */\n id: ValidatedSnapId;\n\n /**\n * The initial permissions of the Snap, which will be requested when it is\n * installed.\n */\n initialPermissions: SnapPermissions;\n\n /**\n * The source code of the Snap.\n */\n sourceCode: string;\n\n /**\n * The Snap's manifest file.\n */\n manifest: SnapManifest;\n\n /**\n * Whether the Snap is blocked.\n */\n blocked: boolean;\n\n /**\n * Information detailing why the snap is blocked.\n */\n blockInformation?: BlockReason;\n\n /**\n * The current status of the Snap, e.g. whether it's running or stopped.\n */\n status: Status;\n\n /**\n * The version of the Snap.\n */\n version: SemVerVersion;\n\n /**\n * The version history of the Snap.\n * Can be used to derive when the Snap was installed, when it was updated to a certain version and who requested the change.\n */\n versionHistory: VersionHistory[];\n\n /**\n * Static auxiliary files that can be loaded at runtime.\n */\n auxiliaryFiles?: SnapAuxilaryFile[];\n\n /**\n * Localization files which are used to translate the manifest.\n */\n localizationFiles?: LocalizationFile[];\n};\n\nexport type TruncatedSnapFields =\n | 'id'\n | 'initialPermissions'\n | 'version'\n | 'enabled'\n | 'blocked';\n\n/**\n * A {@link Snap} object with the fields that are relevant to an external\n * caller.\n */\nexport type TruncatedSnap = Pick<Snap, TruncatedSnapFields>;\n\nexport type ProcessSnapResult = TruncatedSnap | { error: JsonRpcError };\n\nexport type InstallSnapsResult = Record<SnapId, ProcessSnapResult>;\n\n/**\n * An error indicating that a Snap validation failure is programmatically\n * fixable during development.\n */\nexport class ProgrammaticallyFixableSnapError extends Error {\n reason: SnapValidationFailureReason;\n\n constructor(message: string, reason: SnapValidationFailureReason) {\n super(message);\n this.reason = reason;\n }\n}\n\n/**\n * Gets a checksummable manifest by removing the shasum property and reserializing the JSON using a deterministic algorithm.\n *\n * @param manifest - The manifest itself.\n * @returns A virtual file containing the checksummable manifest.\n */\nfunction getChecksummableManifest(\n manifest: VirtualFile<SnapManifest>,\n): VirtualFile {\n const manifestCopy = manifest.clone() as VirtualFile<any>;\n delete manifestCopy.result.source.shasum;\n\n // We use fast-json-stable-stringify to deterministically serialize the JSON\n // This is required before checksumming so we get reproducible checksums across platforms etc\n manifestCopy.value = stableStringify(manifestCopy.result);\n return manifestCopy;\n}\n\n/**\n * Calculates the Base64-encoded SHA-256 digest of all required Snap files.\n *\n * @param files - All required Snap files to be included in the checksum.\n * @returns The Base64-encoded SHA-256 digest of the source code.\n */\nexport function getSnapChecksum(files: FetchedSnapFiles): string {\n const { manifest, sourceCode, svgIcon, auxiliaryFiles } = files;\n const all = [\n getChecksummableManifest(manifest),\n sourceCode,\n svgIcon,\n ...auxiliaryFiles,\n ].filter((file) => file !== undefined);\n return base64.encode(checksumFiles(all as VirtualFile[]));\n}\n\n/**\n * Checks whether the `source.shasum` property of a Snap manifest matches the\n * shasum of the snap.\n *\n * @param files - All required Snap files to be included in the checksum.\n * @param errorMessage - The error message to throw if validation fails.\n */\nexport function validateSnapShasum(\n files: FetchedSnapFiles,\n errorMessage = 'Invalid Snap manifest: manifest shasum does not match computed shasum.',\n): void {\n if (files.manifest.result.source.shasum !== getSnapChecksum(files)) {\n throw new ProgrammaticallyFixableSnapError(\n errorMessage,\n SnapValidationFailureReason.ShasumMismatch,\n );\n }\n}\n\nexport const LOCALHOST_HOSTNAMES = ['localhost', '127.0.0.1', '[::1]'] as const;\n\n// Require snap ids to only consist of printable ASCII characters\nexport const BaseSnapIdStruct = pattern(string(), /^[\\x21-\\x7E]*$/u);\n\nconst LocalSnapIdSubUrlStruct = uri({\n protocol: enums(['http:', 'https:']),\n hostname: enums(LOCALHOST_HOSTNAMES),\n hash: empty(string()),\n search: empty(string()),\n});\n\nexport const LocalSnapIdStruct = refine(\n BaseSnapIdStruct,\n 'local Snap Id',\n (value) => {\n if (!value.startsWith(SnapIdPrefixes.local)) {\n return `Expected local snap ID, got \"${value}\".`;\n }\n\n const [error] = validate(\n value.slice(SnapIdPrefixes.local.length),\n LocalSnapIdSubUrlStruct,\n );\n return error ?? true;\n },\n);\nexport const NpmSnapIdStruct = intersection([\n BaseSnapIdStruct,\n uri({\n protocol: literal(SnapIdPrefixes.npm),\n pathname: refine(string(), 'package name', function* (value) {\n const normalized = value.startsWith('/') ? value.slice(1) : value;\n const { errors, validForNewPackages, warnings } =\n validateNPMPackage(normalized);\n if (!validForNewPackages) {\n if (errors === undefined) {\n assert(warnings !== undefined);\n yield* warnings;\n } else {\n yield* errors;\n }\n }\n return true;\n }),\n search: empty(string()),\n hash: empty(string()),\n }),\n]) as unknown as Struct<string, null>;\n\nexport const HttpSnapIdStruct = intersection([\n BaseSnapIdStruct,\n uri({\n protocol: enums(['http:', 'https:']),\n search: empty(string()),\n hash: empty(string()),\n }),\n]) as unknown as Struct<string, null>;\n\nexport const SnapIdStruct = union([NpmSnapIdStruct, LocalSnapIdStruct]);\n\nexport type ValidatedSnapId = Opaque<string, typeof snapIdSymbol>;\ndeclare const snapIdSymbol: unique symbol;\n\n/**\n * Extracts the snap prefix from a snap ID.\n *\n * @param snapId - The snap ID to extract the prefix from.\n * @returns The snap prefix from a snap id, e.g. `npm:`.\n */\nexport function getSnapPrefix(snapId: string): SnapIdPrefixes {\n const prefix = Object.values(SnapIdPrefixes).find((possiblePrefix) =>\n snapId.startsWith(possiblePrefix),\n );\n if (prefix !== undefined) {\n return prefix;\n }\n throw new Error(`Invalid or no prefix found for \"${snapId}\"`);\n}\n\n/**\n * Strips snap prefix from a full snap ID.\n *\n * @param snapId - The snap ID to strip.\n * @returns The stripped snap ID.\n */\nexport function stripSnapPrefix(snapId: string): string {\n return snapId.replace(getSnapPrefix(snapId), '');\n}\n\n/**\n * Assert that the given value is a valid snap ID.\n *\n * @param value - The value to check.\n * @throws If the value is not a valid snap ID.\n */\nexport function assertIsValidSnapId(\n value: unknown,\n): asserts value is ValidatedSnapId {\n assertStruct(value, SnapIdStruct, 'Invalid snap ID');\n}\n\n/**\n * Typeguard to ensure a chainId follows the CAIP-2 standard.\n *\n * @param chainId - The chainId being tested.\n * @returns `true` if the value is a valid CAIP chain id, and `false` otherwise.\n */\nexport function isCaipChainId(chainId: unknown): chainId is string {\n return (\n typeof chainId === 'string' &&\n /^(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-a-zA-Z0-9]{1,32})$/u.test(\n chainId,\n )\n );\n}\n\n/**\n * Utility function to check if an origin has permission (and caveat) for a particular snap.\n *\n * @param permissions - An origin's permissions object.\n * @param snapId - The id of the snap.\n * @returns A boolean based on if an origin has the specified snap.\n */\nexport function isSnapPermitted(\n permissions: SubjectPermissions<PermissionConstraint>,\n snapId: SnapId,\n) {\n return Boolean(\n (\n (\n (permissions?.wallet_snap?.caveats?.find(\n (caveat) => caveat.type === SnapCaveatType.SnapIds,\n ) ?? {}) as Caveat<string, Json>\n ).value as Record<string, unknown>\n )?.[snapId],\n );\n}\n\n/**\n * Checks whether the passed in requestedPermissions is a valid\n * permission request for a `wallet_snap` permission.\n *\n * @param requestedPermissions - The requested permissions.\n * @throws If the criteria is not met.\n */\nexport function verifyRequestedSnapPermissions(\n requestedPermissions: unknown,\n): asserts requestedPermissions is SnapsPermissionRequest {\n assert(\n isObject(requestedPermissions),\n 'Requested permissions must be an object.',\n );\n\n const { wallet_snap: walletSnapPermission } = requestedPermissions;\n\n assert(\n isObject(walletSnapPermission),\n 'wallet_snap is missing from the requested permissions.',\n );\n\n const { caveats } = walletSnapPermission;\n\n assert(\n Array.isArray(caveats) && caveats.length === 1,\n 'wallet_snap must have a caveat property with a single-item array value.',\n );\n\n const [caveat] = caveats;\n\n assert(\n isObject(caveat) &&\n caveat.type === SnapCaveatType.SnapIds &&\n isObject(caveat.value),\n `The requested permissions do not have a valid ${SnapCaveatType.SnapIds} caveat.`,\n );\n}\n"],"names":["assert","isObject","assertStruct","base64","stableStringify","empty","enums","intersection","literal","pattern","refine","string","union","validate","validateNPMPackage","SnapCaveatType","checksumFiles","SnapIdPrefixes","SnapValidationFailureReason","uri","PROPOSED_NAME_REGEX","SnapStatus","Installing","Updating","Running","Stopped","Crashed","SnapStatusEvents","Start","Stop","Crash","Update","ProgrammaticallyFixableSnapError","Error","constructor","message","reason","getChecksummableManifest","manifest","manifestCopy","clone","result","source","shasum","value","getSnapChecksum","files","sourceCode","svgIcon","auxiliaryFiles","all","filter","file","undefined","encode","validateSnapShasum","errorMessage","ShasumMismatch","LOCALHOST_HOSTNAMES","BaseSnapIdStruct","LocalSnapIdSubUrlStruct","protocol","hostname","hash","search","LocalSnapIdStruct","startsWith","local","error","slice","length","NpmSnapIdStruct","npm","pathname","normalized","errors","validForNewPackages","warnings","HttpSnapIdStruct","SnapIdStruct","getSnapPrefix","snapId","prefix","Object","values","find","possiblePrefix","stripSnapPrefix","replace","assertIsValidSnapId","isCaipChainId","chainId","test","isSnapPermitted","permissions","Boolean","wallet_snap","caveats","caveat","type","SnapIds","verifyRequestedSnapPermissions","requestedPermissions","walletSnapPermission","Array","isArray"],"mappings":";;;;;;;;;;;;;AAYA,SAASA,MAAM,EAAEC,QAAQ,EAAEC,YAAY,QAAQ,kBAAkB;AACjE,SAASC,MAAM,QAAQ,cAAc;AACrC,OAAOC,qBAAqB,6BAA6B;AAEzD,SACEC,KAAK,EACLC,KAAK,EACLC,YAAY,EACZC,OAAO,EACPC,OAAO,EACPC,MAAM,EACNC,MAAM,EACNC,KAAK,EACLC,QAAQ,QACH,cAAc;AACrB,OAAOC,wBAAwB,4BAA4B;AAE3D,SAASC,cAAc,QAAQ,YAAY;AAC3C,SAASC,aAAa,QAAQ,aAAa;AAI3C,SAASC,cAAc,EAAEC,2BAA2B,EAAEC,GAAG,QAAQ,UAAU;AAG3E,+EAA+E;AAC/E,0EAA0E;AAC1E,0EAA0E;AAC1E,4DAA4D;AAC5D,uCAAuC;AACvC,2EAA2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ASiG,WACPA,OAAOC,IAAI,KAAKpF,eAAeqF,OAAO,IACtCnG,SAASiG,OAAOtD,KAAK,GACvB,CAAC,8CAA8C,EAAE7B,eAAeqF,OAAO,CAAC,QAAQ,CAAC;AAErF"}
|
package/dist/esm/types.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { assertStruct, VersionStruct } from '@metamask/utils';
|
|
2
2
|
import { instance, is, object, optional, pattern, refine, size, string, type, union, assert as assertSuperstruct } from 'superstruct';
|
|
3
|
-
import { HandlerType } from './handlers';
|
|
4
3
|
export var NpmSnapFileNames;
|
|
5
4
|
(function(NpmSnapFileNames) {
|
|
6
5
|
NpmSnapFileNames["PackageJson"] = 'package.json';
|
|
@@ -51,7 +50,6 @@ export var SNAP_STREAM_NAMES;
|
|
|
51
50
|
SNAP_STREAM_NAMES["JSON_RPC"] = 'jsonRpc';
|
|
52
51
|
SNAP_STREAM_NAMES["COMMAND"] = 'command';
|
|
53
52
|
})(SNAP_STREAM_NAMES || (SNAP_STREAM_NAMES = {}));
|
|
54
|
-
/* eslint-enable @typescript-eslint/naming-convention */ export const SNAP_EXPORT_NAMES = Object.values(HandlerType);
|
|
55
53
|
export const uri = (opts = {})=>refine(union([
|
|
56
54
|
string(),
|
|
57
55
|
instance(URL)
|
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 } from './handlers';\nimport {
|
|
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 { LocalizationFile } from './localization';\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 localizationFiles: 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 localizationFiles: VirtualFile<LocalizationFile>[];\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' | 'localizationFiles'\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;WAQd;UAAKC,gBAAgB;IAAhBA,iBACVC,iBAAc;IADJD,iBAEVE,cAAW;GAFDF,qBAAAA;AAKZ,OAAO,MAAMG,aAAaT,KACxBF,QACEG,UACA,gEAE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,+CAA+C;AAC/C,OAAO,MAAMK,6BAA6B,cAAc"}
|
package/dist/esm/validation.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { assertIsSnapIcon } from './icon';
|
|
2
|
+
import { validateSnapManifestLocalizations } from './localization';
|
|
2
3
|
import { assertIsSnapManifest } from './manifest/validation';
|
|
3
4
|
import { validateSnapShasum } from './snaps';
|
|
4
5
|
/**
|
|
@@ -9,6 +10,7 @@ import { validateSnapShasum } from './snaps';
|
|
|
9
10
|
*/ export function validateFetchedSnap(files) {
|
|
10
11
|
assertIsSnapManifest(files.manifest.result);
|
|
11
12
|
validateSnapShasum(files);
|
|
13
|
+
validateSnapManifestLocalizations(files.manifest.result, files.localizationFiles.map((file)=>file.result));
|
|
12
14
|
if (files.svgIcon) {
|
|
13
15
|
assertIsSnapIcon(files.svgIcon);
|
|
14
16
|
}
|
|
@@ -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 { 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;
|
|
1
|
+
{"version":3,"sources":["../../src/validation.ts"],"sourcesContent":["import { assertIsSnapIcon } from './icon';\nimport { validateSnapManifestLocalizations } from './localization';\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 validateSnapManifestLocalizations(\n files.manifest.result,\n files.localizationFiles.map((file) => file.result),\n );\n\n if (files.svgIcon) {\n assertIsSnapIcon(files.svgIcon);\n }\n}\n"],"names":["assertIsSnapIcon","validateSnapManifestLocalizations","assertIsSnapManifest","validateSnapShasum","validateFetchedSnap","files","manifest","result","localizationFiles","map","file","svgIcon"],"mappings":"AAAA,SAASA,gBAAgB,QAAQ,SAAS;AAC1C,SAASC,iCAAiC,QAAQ,iBAAiB;AACnE,SAASC,oBAAoB,QAAQ,wBAAwB;AAC7D,SAASC,kBAAkB,QAAQ,UAAU;AAG7C;;;;;CAKC,GACD,OAAO,SAASC,oBAAoBC,KAAuB;IACzDH,qBAAqBG,MAAMC,QAAQ,CAACC,MAAM;IAC1CJ,mBAAmBE;IACnBJ,kCACEI,MAAMC,QAAQ,CAACC,MAAM,EACrBF,MAAMG,iBAAiB,CAACC,GAAG,CAAC,CAACC,OAASA,KAAKH,MAAM;IAGnD,IAAIF,MAAMM,OAAO,EAAE;QACjBX,iBAAiBK,MAAMM,OAAO;IAChC;AACF"}
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
OnHomePage = "onHomePage"
|
|
10
|
+
}
|
|
11
|
+
export declare type SnapHandler = {
|
|
12
|
+
/**
|
|
13
|
+
* The type of handler.
|
|
14
|
+
*/
|
|
15
|
+
type: HandlerType;
|
|
16
|
+
/**
|
|
17
|
+
* Whether the handler is required, i.e., whether the request will fail if the
|
|
18
|
+
* handler is called, but the snap does not export it.
|
|
19
|
+
*
|
|
20
|
+
* This is primarily used for the lifecycle handlers, which are optional.
|
|
21
|
+
*/
|
|
22
|
+
required: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Validate the given snap export. This should return a type guard for the
|
|
25
|
+
* handler type.
|
|
26
|
+
*
|
|
27
|
+
* @param snapExport - The export to validate.
|
|
28
|
+
* @returns Whether the export is valid.
|
|
29
|
+
*/
|
|
30
|
+
validator: (snapExport: unknown) => boolean;
|
|
31
|
+
};
|
|
32
|
+
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: {
|
|
@@ -68,6 +44,11 @@ export declare const SNAP_EXPORTS: {
|
|
|
68
44
|
readonly required: true;
|
|
69
45
|
readonly validator: (snapExport: unknown) => snapExport is OnKeyringRequestHandler<JsonRpcParams>;
|
|
70
46
|
};
|
|
47
|
+
readonly onHomePage: {
|
|
48
|
+
readonly type: HandlerType.OnHomePage;
|
|
49
|
+
readonly required: true;
|
|
50
|
+
readonly validator: (snapExport: unknown) => snapExport is OnHomePageHandler;
|
|
51
|
+
};
|
|
71
52
|
};
|
|
72
53
|
/**
|
|
73
54
|
* The `onRpcRequest` handler. This is called whenever a JSON-RPC request is
|
|
@@ -89,6 +70,47 @@ export declare type OnRpcRequestHandler<Params extends JsonRpcParams = JsonRpcPa
|
|
|
89
70
|
export declare enum SeverityLevel {
|
|
90
71
|
Critical = "critical"
|
|
91
72
|
}
|
|
73
|
+
export declare const OnTransactionResponseStruct: import("superstruct").Struct<{
|
|
74
|
+
content: import("@metamask/snaps-ui").Panel | {
|
|
75
|
+
value: string;
|
|
76
|
+
type: import("@metamask/snaps-ui").NodeType.Copyable;
|
|
77
|
+
} | {
|
|
78
|
+
type: import("@metamask/snaps-ui").NodeType.Divider;
|
|
79
|
+
} | {
|
|
80
|
+
value: string;
|
|
81
|
+
type: import("@metamask/snaps-ui").NodeType.Heading;
|
|
82
|
+
} | {
|
|
83
|
+
type: import("@metamask/snaps-ui").NodeType.Spinner;
|
|
84
|
+
} | {
|
|
85
|
+
value: string;
|
|
86
|
+
type: import("@metamask/snaps-ui").NodeType.Text;
|
|
87
|
+
markdown?: boolean | undefined;
|
|
88
|
+
} | {
|
|
89
|
+
value: string;
|
|
90
|
+
type: import("@metamask/snaps-ui").NodeType.Image;
|
|
91
|
+
};
|
|
92
|
+
severity?: SeverityLevel | undefined;
|
|
93
|
+
}, {
|
|
94
|
+
content: import("superstruct").Struct<import("@metamask/snaps-ui").Panel | {
|
|
95
|
+
value: string;
|
|
96
|
+
type: import("@metamask/snaps-ui").NodeType.Copyable;
|
|
97
|
+
} | {
|
|
98
|
+
type: import("@metamask/snaps-ui").NodeType.Divider;
|
|
99
|
+
} | {
|
|
100
|
+
value: string;
|
|
101
|
+
type: import("@metamask/snaps-ui").NodeType.Heading;
|
|
102
|
+
} | {
|
|
103
|
+
type: import("@metamask/snaps-ui").NodeType.Spinner;
|
|
104
|
+
} | {
|
|
105
|
+
value: string;
|
|
106
|
+
type: import("@metamask/snaps-ui").NodeType.Text;
|
|
107
|
+
markdown?: boolean | undefined;
|
|
108
|
+
} | {
|
|
109
|
+
value: string;
|
|
110
|
+
type: import("@metamask/snaps-ui").NodeType.Image;
|
|
111
|
+
}, null>;
|
|
112
|
+
severity: import("superstruct").Struct<SeverityLevel | undefined, SeverityLevel>;
|
|
113
|
+
}>;
|
|
92
114
|
/**
|
|
93
115
|
* The response from a snap's `onTransaction` handler.
|
|
94
116
|
*
|
|
@@ -96,10 +118,7 @@ export declare enum SeverityLevel {
|
|
|
96
118
|
*
|
|
97
119
|
* If the snap has no insights about the transaction, this should be `null`.
|
|
98
120
|
*/
|
|
99
|
-
export declare type OnTransactionResponse =
|
|
100
|
-
content: Component | null;
|
|
101
|
-
severity?: EnumToUnion<SeverityLevel>;
|
|
102
|
-
};
|
|
121
|
+
export declare type OnTransactionResponse = Infer<typeof OnTransactionResponseStruct>;
|
|
103
122
|
/**
|
|
104
123
|
* The `onTransaction` handler. This is called whenever a transaction is
|
|
105
124
|
* submitted to the snap. It can return insights about the transaction, which
|
|
@@ -161,6 +180,47 @@ export declare type OnKeyringRequestHandler<Params extends JsonRpcParams = JsonR
|
|
|
161
180
|
origin: string;
|
|
162
181
|
request: JsonRpcRequest<Params>;
|
|
163
182
|
}) => Promise<unknown>;
|
|
183
|
+
export declare type OnHomePageHandler = () => Promise<OnHomePageResponse>;
|
|
184
|
+
export declare const OnHomePageResponseStruct: import("superstruct").Struct<{
|
|
185
|
+
content: import("@metamask/snaps-ui").Panel | {
|
|
186
|
+
value: string;
|
|
187
|
+
type: import("@metamask/snaps-ui").NodeType.Copyable;
|
|
188
|
+
} | {
|
|
189
|
+
type: import("@metamask/snaps-ui").NodeType.Divider;
|
|
190
|
+
} | {
|
|
191
|
+
value: string;
|
|
192
|
+
type: import("@metamask/snaps-ui").NodeType.Heading;
|
|
193
|
+
} | {
|
|
194
|
+
type: import("@metamask/snaps-ui").NodeType.Spinner;
|
|
195
|
+
} | {
|
|
196
|
+
value: string;
|
|
197
|
+
type: import("@metamask/snaps-ui").NodeType.Text;
|
|
198
|
+
markdown?: boolean | undefined;
|
|
199
|
+
} | {
|
|
200
|
+
value: string;
|
|
201
|
+
type: import("@metamask/snaps-ui").NodeType.Image;
|
|
202
|
+
};
|
|
203
|
+
}, {
|
|
204
|
+
content: import("superstruct").Struct<import("@metamask/snaps-ui").Panel | {
|
|
205
|
+
value: string;
|
|
206
|
+
type: import("@metamask/snaps-ui").NodeType.Copyable;
|
|
207
|
+
} | {
|
|
208
|
+
type: import("@metamask/snaps-ui").NodeType.Divider;
|
|
209
|
+
} | {
|
|
210
|
+
value: string;
|
|
211
|
+
type: import("@metamask/snaps-ui").NodeType.Heading;
|
|
212
|
+
} | {
|
|
213
|
+
type: import("@metamask/snaps-ui").NodeType.Spinner;
|
|
214
|
+
} | {
|
|
215
|
+
value: string;
|
|
216
|
+
type: import("@metamask/snaps-ui").NodeType.Text;
|
|
217
|
+
markdown?: boolean | undefined;
|
|
218
|
+
} | {
|
|
219
|
+
value: string;
|
|
220
|
+
type: import("@metamask/snaps-ui").NodeType.Image;
|
|
221
|
+
}, null>;
|
|
222
|
+
}>;
|
|
223
|
+
export declare type OnHomePageResponse = Infer<typeof OnHomePageResponseStruct>;
|
|
164
224
|
/**
|
|
165
225
|
* Utility type for getting the handler function type from a handler type.
|
|
166
226
|
*/
|
|
@@ -212,4 +272,3 @@ export declare type SnapFunctionExports = {
|
|
|
212
272
|
* All handlers that a snap can implement.
|
|
213
273
|
*/
|
|
214
274
|
export declare type SnapExports = SnapFunctionExports;
|
|
215
|
-
export {};
|
|
@@ -9,9 +9,11 @@ export * from './entropy';
|
|
|
9
9
|
export * from './enum';
|
|
10
10
|
export * from './errors';
|
|
11
11
|
export * from './handlers';
|
|
12
|
+
export * from './handler-types';
|
|
12
13
|
export * from './iframe';
|
|
13
14
|
export * from './json';
|
|
14
15
|
export * from './json-rpc';
|
|
16
|
+
export * from './localization';
|
|
15
17
|
export * from './logging';
|
|
16
18
|
export * from './manifest/index.browser';
|
|
17
19
|
export * from './namespace';
|
package/dist/types/index.d.ts
CHANGED
|
@@ -11,9 +11,11 @@ export * from './eval';
|
|
|
11
11
|
export * from './errors';
|
|
12
12
|
export * from './fs';
|
|
13
13
|
export * from './handlers';
|
|
14
|
+
export * from './handler-types';
|
|
14
15
|
export * from './iframe';
|
|
15
16
|
export * from './json';
|
|
16
17
|
export * from './json-rpc';
|
|
18
|
+
export * from './localization';
|
|
17
19
|
export * from './logging';
|
|
18
20
|
export * from './manifest';
|
|
19
21
|
export * from './mock';
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import type { Infer } from 'superstruct';
|
|
2
|
+
import type { SnapManifest } from './manifest';
|
|
3
|
+
import type { VirtualFile } from './virtual-file';
|
|
4
|
+
export declare const LOCALIZABLE_FIELDS: readonly ["description", "proposedName"];
|
|
5
|
+
export declare const LocalizationFileStruct: import("superstruct").Struct<{
|
|
6
|
+
locale: string;
|
|
7
|
+
messages: Record<string, {
|
|
8
|
+
message: string;
|
|
9
|
+
description?: string | undefined;
|
|
10
|
+
}>;
|
|
11
|
+
}, {
|
|
12
|
+
locale: import("superstruct").Struct<string, null>;
|
|
13
|
+
messages: import("superstruct").Struct<Record<string, {
|
|
14
|
+
message: string;
|
|
15
|
+
description?: string | undefined;
|
|
16
|
+
}>, null>;
|
|
17
|
+
}>;
|
|
18
|
+
export declare type LocalizationFile = Infer<typeof LocalizationFileStruct>;
|
|
19
|
+
/**
|
|
20
|
+
* Validate a list of localization files.
|
|
21
|
+
*
|
|
22
|
+
* @param localizationFiles - The localization files to validate.
|
|
23
|
+
* @returns The validated localization files.
|
|
24
|
+
* @throws If any of the files are considered invalid.
|
|
25
|
+
*/
|
|
26
|
+
export declare function getValidatedLocalizationFiles(localizationFiles: VirtualFile[]): VirtualFile<LocalizationFile>[];
|
|
27
|
+
/**
|
|
28
|
+
* Get the localization file for a given locale. If the locale is not found,
|
|
29
|
+
* the English localization file will be returned.
|
|
30
|
+
*
|
|
31
|
+
* @param locale - The locale to use.
|
|
32
|
+
* @param localizationFiles - The localization files to use.
|
|
33
|
+
* @returns The localization file, or `undefined` if no localization file was
|
|
34
|
+
* found.
|
|
35
|
+
*/
|
|
36
|
+
export declare function getLocalizationFile(locale: string, localizationFiles: LocalizationFile[]): {
|
|
37
|
+
locale: string;
|
|
38
|
+
messages: Record<string, {
|
|
39
|
+
message: string;
|
|
40
|
+
description?: string | undefined;
|
|
41
|
+
}>;
|
|
42
|
+
} | undefined;
|
|
43
|
+
export declare const TRANSLATION_REGEX: RegExp;
|
|
44
|
+
/**
|
|
45
|
+
* Translate a string using a localization file. This will replace all instances
|
|
46
|
+
* of `{{key}}` with the localized version of `key`.
|
|
47
|
+
*
|
|
48
|
+
* @param value - The string to translate.
|
|
49
|
+
* @param file - The localization file to use, or `undefined` if no localization
|
|
50
|
+
* file was found.
|
|
51
|
+
* @returns The translated string.
|
|
52
|
+
* @throws If the string contains a key that is not present in the localization
|
|
53
|
+
* file, or if no localization file was found.
|
|
54
|
+
*/
|
|
55
|
+
export declare function translate(value: string, file: LocalizationFile | undefined): string;
|
|
56
|
+
/**
|
|
57
|
+
* Get the localized Snap manifest for a given locale. This will replace all
|
|
58
|
+
* localized strings in the manifest with the localized version.
|
|
59
|
+
*
|
|
60
|
+
* @param snapManifest - The Snap manifest to localize.
|
|
61
|
+
* @param locale - The locale to use.
|
|
62
|
+
* @param localizationFiles - The localization files to use.
|
|
63
|
+
* @returns The localized Snap manifest.
|
|
64
|
+
*/
|
|
65
|
+
export declare function getLocalizedSnapManifest(snapManifest: SnapManifest, locale: string, localizationFiles: LocalizationFile[]): {
|
|
66
|
+
description: string;
|
|
67
|
+
source: {
|
|
68
|
+
location: {
|
|
69
|
+
npm: {
|
|
70
|
+
registry: "https://registry.npmjs.org" | "https://registry.npmjs.org/";
|
|
71
|
+
filePath: string;
|
|
72
|
+
packageName: string;
|
|
73
|
+
iconPath?: string | undefined;
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
shasum: string;
|
|
77
|
+
files?: string[] | undefined;
|
|
78
|
+
locales?: string[] | undefined;
|
|
79
|
+
};
|
|
80
|
+
version: import("@metamask/utils").SemVerVersion;
|
|
81
|
+
proposedName: string;
|
|
82
|
+
initialPermissions: {
|
|
83
|
+
'endowment:network-access'?: {} | undefined;
|
|
84
|
+
'endowment:webassembly'?: {} | undefined;
|
|
85
|
+
'endowment:transaction-insight'?: {
|
|
86
|
+
allowTransactionOrigin?: boolean | undefined;
|
|
87
|
+
} | undefined;
|
|
88
|
+
'endowment:cronjob'?: {
|
|
89
|
+
jobs: {
|
|
90
|
+
request: {
|
|
91
|
+
method: string;
|
|
92
|
+
params?: Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[] | undefined;
|
|
93
|
+
id?: string | number | null | undefined;
|
|
94
|
+
jsonrpc?: "2.0" | undefined;
|
|
95
|
+
};
|
|
96
|
+
expression: string;
|
|
97
|
+
}[];
|
|
98
|
+
} | undefined;
|
|
99
|
+
'endowment:rpc'?: {
|
|
100
|
+
dapps?: boolean | undefined;
|
|
101
|
+
snaps?: boolean | undefined;
|
|
102
|
+
allowedOrigins?: string[] | undefined;
|
|
103
|
+
} | undefined;
|
|
104
|
+
'endowment:name-lookup'?: string[] | undefined;
|
|
105
|
+
'endowment:keyring'?: {
|
|
106
|
+
allowedOrigins?: string[] | undefined;
|
|
107
|
+
} | undefined;
|
|
108
|
+
snap_dialog?: {} | undefined;
|
|
109
|
+
snap_confirm?: {} | undefined;
|
|
110
|
+
snap_manageState?: {} | undefined;
|
|
111
|
+
snap_manageAccounts?: {} | undefined;
|
|
112
|
+
snap_notify?: {} | undefined;
|
|
113
|
+
snap_getBip32Entropy?: {
|
|
114
|
+
path: string[];
|
|
115
|
+
curve: "ed25519" | "secp256k1";
|
|
116
|
+
}[] | undefined;
|
|
117
|
+
snap_getBip32PublicKey?: {
|
|
118
|
+
path: string[];
|
|
119
|
+
curve: "ed25519" | "secp256k1";
|
|
120
|
+
}[] | undefined;
|
|
121
|
+
snap_getBip44Entropy?: {
|
|
122
|
+
coinType: number;
|
|
123
|
+
}[] | undefined;
|
|
124
|
+
snap_getEntropy?: {} | undefined;
|
|
125
|
+
wallet_snap?: Record<string, {
|
|
126
|
+
version?: string | undefined;
|
|
127
|
+
}> | undefined;
|
|
128
|
+
};
|
|
129
|
+
manifestVersion: "0.1";
|
|
130
|
+
repository?: {
|
|
131
|
+
type: string;
|
|
132
|
+
url: string;
|
|
133
|
+
} | undefined;
|
|
134
|
+
$schema?: string | undefined;
|
|
135
|
+
};
|
|
136
|
+
/**
|
|
137
|
+
* Validate the localization files for a Snap manifest.
|
|
138
|
+
*
|
|
139
|
+
* @param snapManifest - The Snap manifest to validate.
|
|
140
|
+
* @param localizationFiles - The localization files to validate.
|
|
141
|
+
* @throws If the manifest cannot be localized.
|
|
142
|
+
*/
|
|
143
|
+
export declare function validateSnapManifestLocalizations(snapManifest: SnapManifest, localizationFiles: LocalizationFile[]): void;
|
|
@@ -67,14 +67,22 @@ export declare function getSnapSourceCode(basePath: string, manifest: Json, sour
|
|
|
67
67
|
*/
|
|
68
68
|
export declare function getSnapIcon(basePath: string, manifest: Json): Promise<VirtualFile | undefined>;
|
|
69
69
|
/**
|
|
70
|
-
*
|
|
71
|
-
* and read them.
|
|
70
|
+
* Get an array of paths from an unvalidated Snap manifest.
|
|
72
71
|
*
|
|
73
|
-
* @param basePath - The path to the folder with the manifest files.
|
|
74
72
|
* @param manifest - The unvalidated Snap manifest file contents.
|
|
73
|
+
* @param selector - A function that returns the paths to the files.
|
|
74
|
+
* @returns The paths to the files, if any.
|
|
75
|
+
*/
|
|
76
|
+
export declare function getSnapFilePaths(manifest: Json, selector: (manifest: Partial<SnapManifest>) => string[] | undefined): string[] | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* Given an unvalidated Snap manifest, attempts to extract the files with the
|
|
79
|
+
* given paths and read them.
|
|
80
|
+
*
|
|
81
|
+
* @param basePath - The path to the folder with the manifest files.
|
|
82
|
+
* @param paths - The paths to the files.
|
|
75
83
|
* @returns A list of auxiliary files and their contents, if any.
|
|
76
84
|
*/
|
|
77
|
-
export declare function
|
|
85
|
+
export declare function getSnapFiles(basePath: string, paths: string[] | undefined): Promise<VirtualFile[] | undefined>;
|
|
78
86
|
/**
|
|
79
87
|
* Sorts the given manifest in our preferred sort order and removes the
|
|
80
88
|
* `repository` field if it is falsy (it may be `null`).
|
|
@@ -84,7 +92,7 @@ export declare function getSnapAuxiliaryFiles(basePath: string, manifest: Json):
|
|
|
84
92
|
*/
|
|
85
93
|
export declare function getWritableManifest(manifest: SnapManifest): SnapManifest;
|
|
86
94
|
/**
|
|
87
|
-
* Validates the fields of an
|
|
95
|
+
* Validates the fields of an NPM Snap manifest that has already passed JSON
|
|
88
96
|
* Schema validation.
|
|
89
97
|
*
|
|
90
98
|
* @param snapFiles - The relevant snap files to validate.
|
|
@@ -93,5 +101,6 @@ export declare function getWritableManifest(manifest: SnapManifest): SnapManifes
|
|
|
93
101
|
* @param snapFiles.sourceCode - The Snap's source code.
|
|
94
102
|
* @param snapFiles.svgIcon - The Snap's optional icon.
|
|
95
103
|
* @param snapFiles.auxiliaryFiles - Any auxiliary files required by the snap at runtime.
|
|
104
|
+
* @param snapFiles.localizationFiles - The Snap's localization files.
|
|
96
105
|
*/
|
|
97
|
-
export declare function validateNpmSnapManifest({ manifest, packageJson, sourceCode, svgIcon, auxiliaryFiles, }: SnapFiles): void;
|
|
106
|
+
export declare function validateNpmSnapManifest({ manifest, packageJson, sourceCode, svgIcon, auxiliaryFiles, localizationFiles, }: SnapFiles): void;
|