@metamask/snaps-utils
Advanced tools
Comparing version 0.25.0 to 0.26.0
@@ -12,3 +12,3 @@ export * from './caveats'; | ||
export * from './types'; | ||
export * from './url'; | ||
export * from './versions'; | ||
export * from './virtual-file/index.browser'; |
@@ -28,4 +28,4 @@ "use strict"; | ||
__exportStar(require("./types"), exports); | ||
__exportStar(require("./url"), exports); | ||
__exportStar(require("./versions"), exports); | ||
__exportStar(require("./virtual-file/index.browser"), exports); | ||
//# sourceMappingURL=index.browser.js.map |
@@ -18,3 +18,3 @@ export * from './caveats'; | ||
export * from './types'; | ||
export * from './url'; | ||
export * from './versions'; | ||
export * from './virtual-file'; |
@@ -34,4 +34,4 @@ "use strict"; | ||
__exportStar(require("./types"), exports); | ||
__exportStar(require("./url"), exports); | ||
__exportStar(require("./versions"), exports); | ||
__exportStar(require("./virtual-file"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -189,4 +189,5 @@ "use strict"; | ||
node.property.name === 'eval' && | ||
// If the expression is already wrapped we can ignore it | ||
path.parent.type !== 'SequenceExpression') { | ||
// We only apply this to MemberExpressions that are the callee of CallExpression | ||
path.parent.type === 'CallExpression' && | ||
path.parent.callee === node) { | ||
path.replaceWith(objectEvalWrapper({ | ||
@@ -193,0 +194,0 @@ OBJECT: node.object, |
import { Json } from '@metamask/utils'; | ||
import { SerializedEthereumRpcError } from 'eth-rpc-errors/dist/classes'; | ||
import { Struct } from 'superstruct'; | ||
import { SnapManifest, SnapPermissions } from './manifest/validation'; | ||
import { SnapId, SnapIdPrefixes, SnapValidationFailureReason } from './types'; | ||
import { SemVerVersion } from './versions'; | ||
export declare const LOCALHOST_HOSTNAMES: Set<string>; | ||
export declare const SNAP_PREFIX = "wallet_snap_"; | ||
@@ -139,2 +139,6 @@ export declare const SNAP_PREFIX_REGEX: RegExp; | ||
export declare function validateSnapShasum(manifest: SnapManifest, sourceCode: string, errorMessage?: string): void; | ||
export declare const LOCALHOST_HOSTNAMES: readonly ["localhost", "127.0.0.1", "[::1]"]; | ||
export declare const LocalSnapIdStruct: Struct<string, null>; | ||
export declare const NpmSnapIdStruct: Struct<string, null>; | ||
export declare const HttpSnapIdStruct: Struct<string, null>; | ||
/** | ||
@@ -141,0 +145,0 @@ * Extracts the snap prefix from a snap ID. |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isCaipChainId = exports.validateSnapId = exports.getSnapPermissionName = exports.getSnapPrefix = exports.validateSnapShasum = exports.getSnapSourceShasum = exports.ProgrammaticallyFixableSnapError = exports.SnapStatusEvents = exports.SnapStatus = exports.PROPOSED_NAME_REGEX = exports.SNAP_PREFIX_REGEX = exports.SNAP_PREFIX = exports.LOCALHOST_HOSTNAMES = void 0; | ||
exports.isCaipChainId = exports.validateSnapId = exports.getSnapPermissionName = exports.getSnapPrefix = exports.HttpSnapIdStruct = exports.NpmSnapIdStruct = exports.LocalSnapIdStruct = exports.LOCALHOST_HOSTNAMES = exports.validateSnapShasum = exports.getSnapSourceShasum = exports.ProgrammaticallyFixableSnapError = exports.SnapStatusEvents = exports.SnapStatus = exports.PROPOSED_NAME_REGEX = exports.SNAP_PREFIX_REGEX = exports.SNAP_PREFIX = void 0; | ||
const utils_1 = require("@metamask/utils"); | ||
const sha256_1 = require("@noble/hashes/sha256"); | ||
const base_1 = require("@scure/base"); | ||
const superstruct_1 = require("superstruct"); | ||
const validate_npm_package_name_1 = __importDefault(require("validate-npm-package-name")); | ||
const types_1 = require("./types"); | ||
exports.LOCALHOST_HOSTNAMES = new Set(['localhost', '127.0.0.1', '::1']); | ||
exports.SNAP_PREFIX = 'wallet_snap_'; | ||
@@ -70,2 +75,46 @@ exports.SNAP_PREFIX_REGEX = new RegExp(`^${exports.SNAP_PREFIX}`, 'u'); | ||
exports.validateSnapShasum = validateSnapShasum; | ||
exports.LOCALHOST_HOSTNAMES = ['localhost', '127.0.0.1', '[::1]']; | ||
const LocalSnapIdSubUrlStruct = (0, types_1.uri)({ | ||
protocol: (0, superstruct_1.enums)(['http:', 'https:']), | ||
hostname: (0, superstruct_1.enums)(exports.LOCALHOST_HOSTNAMES), | ||
hash: (0, superstruct_1.empty)((0, superstruct_1.string)()), | ||
search: (0, superstruct_1.empty)((0, superstruct_1.string)()), | ||
}); | ||
exports.LocalSnapIdStruct = (0, superstruct_1.refine)((0, superstruct_1.string)(), 'local Snap Id', (value) => { | ||
if (!value.startsWith(types_1.SnapIdPrefixes.local)) { | ||
return `Expected local Snap ID, got "${value}".`; | ||
} | ||
const [error] = (0, superstruct_1.validate)(value.slice(types_1.SnapIdPrefixes.local.length), LocalSnapIdSubUrlStruct); | ||
return error !== null && error !== void 0 ? error : true; | ||
}); | ||
exports.NpmSnapIdStruct = (0, superstruct_1.intersection)([ | ||
(0, superstruct_1.string)(), | ||
(0, types_1.uri)({ | ||
protocol: (0, superstruct_1.literal)(types_1.SnapIdPrefixes.npm), | ||
pathname: (0, superstruct_1.refine)((0, superstruct_1.string)(), 'package name', function* (value) { | ||
const normalized = value.startsWith('/') ? value.slice(1) : value; | ||
const { errors, validForNewPackages, warnings } = (0, validate_npm_package_name_1.default)(normalized); | ||
if (!validForNewPackages) { | ||
if (errors === undefined) { | ||
(0, utils_1.assert)(warnings !== undefined); | ||
yield* warnings; | ||
} | ||
else { | ||
yield* errors; | ||
} | ||
} | ||
return true; | ||
}), | ||
search: (0, superstruct_1.empty)((0, superstruct_1.string)()), | ||
hash: (0, superstruct_1.empty)((0, superstruct_1.string)()), | ||
}), | ||
]); | ||
exports.HttpSnapIdStruct = (0, superstruct_1.intersection)([ | ||
(0, superstruct_1.string)(), | ||
(0, types_1.uri)({ | ||
protocol: (0, superstruct_1.enums)(['http:', 'https:']), | ||
search: (0, superstruct_1.empty)((0, superstruct_1.string)()), | ||
hash: (0, superstruct_1.empty)((0, superstruct_1.string)()), | ||
}), | ||
]); | ||
/** | ||
@@ -110,3 +159,3 @@ * Extracts the snap prefix from a snap ID. | ||
} | ||
throw new Error(`Invalid snap id. Unknown prefix. Received: "${snapId}"`); | ||
throw new Error(`Invalid snap id. Unknown prefix. Received: "${snapId}".`); | ||
} | ||
@@ -113,0 +162,0 @@ exports.validateSnapId = validateSnapId; |
import { SnapFunctionExports, SnapKeyring as Keyring } from '@metamask/snaps-types'; | ||
import { Json } from '@metamask/utils'; | ||
import { Infer } from 'superstruct'; | ||
import { Infer, Struct } from 'superstruct'; | ||
import { SnapManifest } from './manifest/validation'; | ||
@@ -9,4 +9,4 @@ export declare enum NpmSnapFileNames { | ||
} | ||
export declare const NameStruct: import("superstruct").Struct<string, null>; | ||
export declare const NpmSnapPackageJsonStruct: import("superstruct").Struct<{ | ||
export declare const NameStruct: Struct<string, null>; | ||
export declare const NpmSnapPackageJsonStruct: Struct<{ | ||
name: string; | ||
@@ -20,11 +20,11 @@ version: import("./versions").SemVerVersion; | ||
}, { | ||
version: import("superstruct").Struct<import("./versions").SemVerVersion, null>; | ||
name: import("superstruct").Struct<string, null>; | ||
main: import("superstruct").Struct<string | undefined, null>; | ||
repository: import("superstruct").Struct<{ | ||
version: Struct<import("./versions").SemVerVersion, null>; | ||
name: Struct<string, null>; | ||
main: Struct<string | undefined, null>; | ||
repository: Struct<{ | ||
type: string; | ||
url: string; | ||
} | undefined, { | ||
type: import("superstruct").Struct<string, null>; | ||
url: import("superstruct").Struct<string, null>; | ||
type: Struct<string, null>; | ||
url: Struct<string, null>; | ||
}>; | ||
@@ -109,2 +109,19 @@ }>; | ||
}; | ||
declare type UriOptions<T extends string> = { | ||
protocol?: Struct<T>; | ||
hash?: Struct<T>; | ||
port?: Struct<T>; | ||
hostname?: Struct<T>; | ||
pathname?: Struct<T>; | ||
search?: Struct<T>; | ||
}; | ||
export declare const uri: (opts?: UriOptions<any>) => Struct<string | URL, null>; | ||
/** | ||
* Returns whether a given value is a valid URL. | ||
* | ||
* @param url - The value to check. | ||
* @param opts - Optional constraints for url checking. | ||
* @returns Whether `url` is valid URL or not. | ||
*/ | ||
export declare function isValidUrl(url: unknown, opts?: UriOptions<any>): url is string | URL; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SNAP_EXPORT_NAMES = exports.HandlerType = exports.SNAP_STREAM_NAMES = exports.SnapValidationFailureReason = exports.SnapIdPrefixes = exports.assertIsNpmSnapPackageJson = exports.isNpmSnapPackageJson = exports.NpmSnapPackageJsonStruct = exports.NameStruct = exports.NpmSnapFileNames = void 0; | ||
exports.isValidUrl = exports.uri = exports.SNAP_EXPORT_NAMES = exports.HandlerType = exports.SNAP_STREAM_NAMES = exports.SnapValidationFailureReason = exports.SnapIdPrefixes = exports.assertIsNpmSnapPackageJson = exports.isNpmSnapPackageJson = exports.NpmSnapPackageJsonStruct = exports.NameStruct = exports.NpmSnapFileNames = void 0; | ||
const utils_1 = require("@metamask/utils"); | ||
@@ -79,2 +79,25 @@ const superstruct_1 = require("superstruct"); | ||
exports.SNAP_EXPORT_NAMES = Object.values(HandlerType); | ||
const uri = (opts = {}) => (0, superstruct_1.refine)((0, superstruct_1.union)([(0, superstruct_1.string)(), (0, superstruct_1.instance)(URL)]), 'uri', (value) => { | ||
try { | ||
const url = new URL(value); | ||
const UrlStruct = (0, superstruct_1.type)(opts); | ||
(0, superstruct_1.assert)(url, UrlStruct); | ||
return true; | ||
} | ||
catch (_a) { | ||
return `Expected URL, got "${value.toString()}".`; | ||
} | ||
}); | ||
exports.uri = uri; | ||
/** | ||
* Returns whether a given value is a valid URL. | ||
* | ||
* @param url - The value to check. | ||
* @param opts - Optional constraints for url checking. | ||
* @returns Whether `url` is valid URL or not. | ||
*/ | ||
function isValidUrl(url, opts = {}) { | ||
return (0, superstruct_1.is)(url, (0, exports.uri)(opts)); | ||
} | ||
exports.isValidUrl = isValidUrl; | ||
//# sourceMappingURL=types.js.map |
@@ -87,2 +87,10 @@ import { Json } from '@metamask/utils'; | ||
/** | ||
* Checks whether a SemVer version is greater than all possibilities in a range. | ||
* | ||
* @param version - A SemvVer version. | ||
* @param range - The range to check against. | ||
* @returns `version > range`. | ||
*/ | ||
export declare function gtRange(version: SemVerVersion, range: SemVerRange): boolean; | ||
/** | ||
* Returns whether a SemVer version satisfies a SemVer range. | ||
@@ -89,0 +97,0 @@ * |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.resolveVersionRange = exports.getTargetVersion = exports.satisfiesVersionRange = exports.gtVersion = exports.assertIsSemVerRange = exports.assertIsSemVerVersion = exports.isValidSemVerRange = exports.isValidSemVerVersion = exports.VersionRangeStruct = exports.VersionStruct = exports.DEFAULT_REQUESTED_SNAP_VERSION = void 0; | ||
exports.resolveVersionRange = exports.getTargetVersion = exports.satisfiesVersionRange = exports.gtRange = exports.gtVersion = exports.assertIsSemVerRange = exports.assertIsSemVerVersion = exports.isValidSemVerRange = exports.isValidSemVerVersion = exports.VersionRangeStruct = exports.VersionStruct = exports.DEFAULT_REQUESTED_SNAP_VERSION = void 0; | ||
const utils_1 = require("@metamask/utils"); | ||
@@ -73,2 +73,13 @@ const semver_1 = require("semver"); | ||
/** | ||
* Checks whether a SemVer version is greater than all possibilities in a range. | ||
* | ||
* @param version - A SemvVer version. | ||
* @param range - The range to check against. | ||
* @returns `version > range`. | ||
*/ | ||
function gtRange(version, range) { | ||
return (0, semver_1.gtr)(version, range); | ||
} | ||
exports.gtRange = gtRange; | ||
/** | ||
* Returns whether a SemVer version satisfies a SemVer range. | ||
@@ -75,0 +86,0 @@ * |
{ | ||
"name": "@metamask/snaps-utils", | ||
"version": "0.25.0", | ||
"version": "0.26.0", | ||
"repository": { | ||
@@ -55,3 +55,3 @@ "type": "git", | ||
"@babel/types": "^7.18.7", | ||
"@metamask/snaps-types": "^0.25.0", | ||
"@metamask/snaps-types": "^0.26.0", | ||
"@metamask/utils": "^3.3.1", | ||
@@ -66,3 +66,4 @@ "@noble/hashes": "^1.1.3", | ||
"ses": "^0.17.0", | ||
"superstruct": "^0.16.7" | ||
"superstruct": "^0.16.7", | ||
"validate-npm-package-name": "^5.0.0" | ||
}, | ||
@@ -78,2 +79,3 @@ "devDependencies": { | ||
"@types/semver": "^7.3.10", | ||
"@types/validate-npm-package-name": "^4.0.0", | ||
"@typescript-eslint/eslint-plugin": "^5.42.1", | ||
@@ -91,3 +93,3 @@ "@typescript-eslint/parser": "^5.42.1", | ||
"jest-it-up": "^2.0.0", | ||
"memfs": "^3.4.7", | ||
"memfs": "^3.4.12", | ||
"prettier": "^2.7.1", | ||
@@ -94,0 +96,0 @@ "prettier-plugin-packagejson": "^2.2.11", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
313306
87
4038
14
27
5
+ Added@metamask/snaps-types@0.26.2(transitive)
+ Added@metamask/snaps-utils@0.26.2(transitive)
+ Addedvalidate-npm-package-name@5.0.1(transitive)
- Removed@metamask/snaps-types@0.25.0(transitive)