Socket
Socket
Sign inDemoInstall

@metamask/snaps-utils

Package Overview
Dependencies
Maintainers
8
Versions
71
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@metamask/snaps-utils - npm Package Compare versions

Comparing version 0.27.1 to 0.28.0

dist/iframe.d.ts

2

dist/index.browser.d.ts
export * from './caveats';
export * from './cronjob';
export * from './deep-clone';

@@ -7,2 +8,3 @@ export * from './default-endowments';

export * from './handlers';
export * from './iframe';
export * from './json-rpc';

@@ -9,0 +11,0 @@ export * from './manifest/index.browser';

@@ -18,2 +18,3 @@ "use strict";

__exportStar(require("./caveats"), exports);
__exportStar(require("./cronjob"), exports);
__exportStar(require("./deep-clone"), exports);

@@ -24,2 +25,3 @@ __exportStar(require("./default-endowments"), exports);

__exportStar(require("./handlers"), exports);
__exportStar(require("./iframe"), exports);
__exportStar(require("./json-rpc"), exports);

@@ -26,0 +28,0 @@ __exportStar(require("./manifest/index.browser"), exports);

@@ -10,2 +10,3 @@ export * from './caveats';

export * from './handlers';
export * from './iframe';
export * from './json-rpc';

@@ -12,0 +13,0 @@ export * from './manifest';

@@ -26,2 +26,3 @@ "use strict";

__exportStar(require("./handlers"), exports);
__exportStar(require("./iframe"), exports);
__exportStar(require("./json-rpc"), exports);

@@ -28,0 +29,0 @@ __exportStar(require("./manifest"), exports);

27

dist/manifest/validation.d.ts
import { Infer, Struct } from 'superstruct';
export declare type Base64Opts = {
/**
* Is the `=` padding at the end required or not.
*
* @default false
*/
paddingRequired?: boolean;
/**
* Which character set should be used.
* The sets are based on {@link https://datatracker.ietf.org/doc/html/rfc4648 RFC 4648}.
*
* @default 'base64'
*/
characterSet?: 'base64' | 'base64url';
};
/**
* Ensure that a provided string-based struct is valid base64.
*
* @param struct - The string based struct.
* @param opts - Optional options to specialize base64 validation. See {@link Base64Opts} documentation.
* @returns A superstruct validating base64.
*/
export declare const base64: <T extends string, S>(struct: Struct<T, S>, opts?: Base64Opts) => Struct<T, S>;
export declare const Bip32PathStruct: Struct<string[], Struct<string, null>>;

@@ -216,3 +193,3 @@ export declare const bip32entropy: <T extends {

export declare const SnapManifestStruct: Struct<{
version: import("../versions").SemVerVersion;
version: import("@metamask/utils").SemVerVersion;
description: string;

@@ -284,3 +261,3 @@ proposedName: string;

}, {
version: Struct<import("../versions").SemVerVersion, null>;
version: Struct<import("@metamask/utils").SemVerVersion, null>;
description: Struct<string, null>;

@@ -287,0 +264,0 @@ proposedName: Struct<string, null>;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createSnapManifest = exports.assertIsSnapManifest = exports.isSnapManifest = exports.SnapManifestStruct = exports.PermissionsStruct = exports.SnapGetBip32EntropyPermissionsStruct = exports.Bip32EntropyStruct = exports.bip32entropy = exports.Bip32PathStruct = exports.base64 = void 0;
exports.createSnapManifest = exports.assertIsSnapManifest = exports.isSnapManifest = exports.SnapManifestStruct = exports.PermissionsStruct = exports.SnapGetBip32EntropyPermissionsStruct = exports.Bip32EntropyStruct = exports.bip32entropy = exports.Bip32PathStruct = void 0;
const utils_1 = require("@metamask/utils");

@@ -12,3 +12,2 @@ const superstruct_1 = require("superstruct");

const types_1 = require("../types");
const versions_1 = require("../versions");
// BIP-43 purposes that cannot be used for entropy derivation. These are in the

@@ -20,31 +19,2 @@ // string form, ending with `'`.

];
/**
* Ensure that a provided string-based struct is valid base64.
*
* @param struct - The string based struct.
* @param opts - Optional options to specialize base64 validation. See {@link Base64Opts} documentation.
* @returns A superstruct validating base64.
*/
const base64 = (struct, opts = {}) => {
var _a, _b;
const paddingRequired = (_a = opts.paddingRequired) !== null && _a !== void 0 ? _a : false;
const characterSet = (_b = opts.characterSet) !== null && _b !== void 0 ? _b : 'base64';
let letters;
if (characterSet === 'base64') {
letters = String.raw `[A-Za-z0-9+\/]`;
}
else {
(0, utils_1.assert)(characterSet === 'base64url');
letters = String.raw `[-_A-Za-z0-9]`;
}
let re;
if (paddingRequired) {
re = new RegExp(`^(?:${letters}{4})*(?:${letters}{3}=|${letters}{2}==)?$`, 'u');
}
else {
re = new RegExp(`^(?:${letters}{4})*(?:${letters}{2,3}|${letters}{3}=|${letters}{2}==)?$`, 'u');
}
return (0, superstruct_1.pattern)(struct, re);
};
exports.base64 = base64;
const BIP32_INDEX_REGEX = /^\d+'?$/u;

@@ -106,3 +76,3 @@ exports.Bip32PathStruct = (0, superstruct_1.refine)((0, superstruct_1.array)((0, superstruct_1.string)()), 'BIP-32 path', (path) => {

exports.SnapManifestStruct = (0, superstruct_1.object)({
version: versions_1.VersionStruct,
version: utils_1.VersionStruct,
description: (0, superstruct_1.size)((0, superstruct_1.string)(), 1, 280),

@@ -115,3 +85,3 @@ proposedName: (0, superstruct_1.size)((0, superstruct_1.pattern)((0, superstruct_1.string)(), /^(?:[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), 1, 214),

source: (0, superstruct_1.object)({
shasum: (0, superstruct_1.size)((0, exports.base64)((0, superstruct_1.string)(), { paddingRequired: true }), 44, 44),
shasum: utils_1.ChecksumStruct,
location: (0, superstruct_1.object)({

@@ -118,0 +88,0 @@ npm: (0, superstruct_1.object)({

@@ -10,3 +10,3 @@ "use strict";

const default_endowments_1 = require("./default-endowments");
const NETWORK_APIS = ['fetch', 'WebSocket'];
const NETWORK_APIS = ['fetch'];
exports.ALL_APIS = [...default_endowments_1.DEFAULT_ENDOWMENTS, ...NETWORK_APIS];

@@ -71,3 +71,2 @@ /**

const mockWindow = {
WebSocket: MockClass,
crypto: crypto_1.default,

@@ -74,0 +73,0 @@ SubtleCrypto: MockClass,

@@ -1,2 +0,3 @@

import { Json } from '@metamask/utils';
import { BlockReason } from '@metamask/snaps-registry';
import { Json, SemVerVersion } from '@metamask/utils';
import { SerializedEthereumRpcError } from 'eth-rpc-errors/dist/classes';

@@ -6,3 +7,2 @@ import { Struct } from 'superstruct';

import { SnapId, SnapIdPrefixes, SnapValidationFailureReason } from './types';
import { SemVerVersion } from './versions';
export declare const SNAP_PREFIX = "wallet_snap_";

@@ -19,6 +19,2 @@ export declare const SNAP_PREFIX_REGEX: RegExp;

};
export declare type BlockedSnapInfo = {
infoUrl?: string;
reason?: string;
};
export declare enum SnapStatus {

@@ -87,3 +83,3 @@ Installing = "installing",

*/
blockInformation?: BlockedSnapInfo;
blockInformation?: BlockReason;
/**

@@ -90,0 +86,0 @@ * The name of the permission used to invoke the Snap.

@@ -12,3 +12,3 @@ import { Json } from '@metamask/utils';

name: string;
version: import("./versions").SemVerVersion;
version: import("@metamask/utils").SemVerVersion;
repository?: {

@@ -20,3 +20,3 @@ type: string;

}, {
version: Struct<import("./versions").SemVerVersion, null>;
version: Struct<import("@metamask/utils").SemVerVersion, null>;
name: Struct<string, null>;

@@ -105,6 +105,2 @@ main: Struct<string | undefined, null>;

export declare type SnapExportsParameters = ObjectParameters<SnapFunctionExports> | KeyringParameters;
declare const brand: unique symbol;
export declare type Opaque<Base, Brand extends symbol> = Base & {
[brand]: Brand;
};
declare type UriOptions<T extends string> = {

@@ -111,0 +107,0 @@ protocol?: Struct<T>;

@@ -6,3 +6,2 @@ "use strict";

const superstruct_1 = require("superstruct");
const versions_1 = require("./versions");
var NpmSnapFileNames;

@@ -17,3 +16,3 @@ (function (NpmSnapFileNames) {

exports.NpmSnapPackageJsonStruct = (0, superstruct_1.type)({
version: versions_1.VersionStruct,
version: utils_1.VersionStruct,
name: exports.NameStruct,

@@ -20,0 +19,0 @@ main: (0, superstruct_1.optional)((0, superstruct_1.size)((0, superstruct_1.string)(), 1, Infinity)),

@@ -1,103 +0,4 @@

import { Json } from '@metamask/utils';
import { Struct } from 'superstruct';
import { Opaque } from './types';
import { Json, SemVerVersion, SemVerRange } from '@metamask/utils';
export declare const DEFAULT_REQUESTED_SNAP_VERSION: SemVerRange;
/**
* {@link https://codemix.com/opaque-types-in-javascript/ Opaque} type for SemVer ranges.
*
* @example Use {@link assertIsSemVerRange} and {@link isValidSemVerRange} to cast to proper type.
* ```typescript
* const unsafeRange: string = dataFromUser();
* assertIsSemVerRange(unsafeRange);
* unsafeRange
* // ^? SemVerRange
* ```
* @example If you know what you're doing and want to side-step type safety, casting from a string works correctly.
* ```typescript
* const unsafeRange: string = dataFromUser();
* unsafeRange as SemVerRange;
* // ^? SemVerRange
* ```
* @see {@link assertIsSemVerRange}
* @see {@link isValidSemVerRange}
*/
export declare type SemVerRange = Opaque<string, typeof semVerRange>;
declare const semVerRange: unique symbol;
/**
* {@link https://codemix.com/opaque-types-in-javascript/ Opaque} type for singular SemVer version.
*
* @example Use {@link assertIsSemVerVersion} and {@link isValidSemVerVersion} to cast to proper type.
* ```typescript
* const unsafeVersion: string = dataFromUser();
* assertIsSemVerVersion(unsafeRange);
* unsafeVersion
* // ^? SemVerVersion
* ```
* @example If you know what you're doing and want to side-step type safety, casting from a string works correctly.
* ```typescript
* const unsafeVersion: string = dataFromUser();
* unsafeRange as SemVerVersion;
* // ^? SemVerVersion
* ```
* @see {@link assertIsSemVerVersion}
* @see {@link isValidSemVerVersion}
*/
export declare type SemVerVersion = Opaque<string, typeof semVerVersion>;
declare const semVerVersion: unique symbol;
/**
* A struct for validating a version string.
*/
export declare const VersionStruct: Struct<SemVerVersion, null>;
export declare const VersionRangeStruct: Struct<SemVerRange, null>;
/**
* Checks whether a SemVer version is valid.
*
* @param version - A potential version.
* @returns `true` if the version is valid, and `false` otherwise.
*/
export declare function isValidSemVerVersion(version: unknown): version is SemVerVersion;
/**
* Checks whether a SemVer version range is valid.
*
* @param versionRange - A potential version range.
* @returns `true` if the version range is valid, and `false` otherwise.
*/
export declare function isValidSemVerRange(versionRange: unknown): versionRange is SemVerRange;
/**
* Asserts that a value is a valid concrete SemVer version.
*
* @param version - A potential SemVer concrete version.
*/
export declare function assertIsSemVerVersion(version: unknown): asserts version is SemVerVersion;
/**
* Asserts that a value is a valid SemVer range.
*
* @param range - A potential SemVer range.
*/
export declare function assertIsSemVerRange(range: unknown): asserts range is SemVerRange;
/**
* Checks whether a SemVer version is greater than another.
*
* @param version1 - The left-hand version.
* @param version2 - The right-hand version.
* @returns `version1 > version2`.
*/
export declare function gtVersion(version1: SemVerVersion, version2: SemVerVersion): boolean;
/**
* 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.
*
* @param version - The SemVer version to check.
* @param versionRange - The SemVer version range to check against.
* @returns Whether the version satisfied the version range.
*/
export declare function satisfiesVersionRange(version: SemVerVersion, versionRange: SemVerRange): boolean;
/**
* Return the highest version in the list that satisfies the range, or `null` if

@@ -121,2 +22,1 @@ * none of them do. For the satisfaction check, pre-release versions will only

export declare function resolveVersionRange(version?: Json): [error: undefined, range: SemVerRange] | [error: Error, range: undefined];
export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
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;
exports.resolveVersionRange = exports.getTargetVersion = exports.DEFAULT_REQUESTED_SNAP_VERSION = void 0;
const utils_1 = require("@metamask/utils");

@@ -9,90 +9,2 @@ const semver_1 = require("semver");

/**
* A struct for validating a version string.
*/
exports.VersionStruct = (0, superstruct_1.refine)((0, superstruct_1.string)(), 'Version', (value) => {
if ((0, semver_1.valid)(value) === null) {
return `Expected SemVer version, got "${value}"`;
}
return true;
});
exports.VersionRangeStruct = (0, superstruct_1.refine)((0, superstruct_1.string)(), 'Version range', (value) => {
if ((0, semver_1.validRange)(value) === null) {
return `Expected SemVer range, got "${value}"`;
}
return true;
});
/**
* Checks whether a SemVer version is valid.
*
* @param version - A potential version.
* @returns `true` if the version is valid, and `false` otherwise.
*/
function isValidSemVerVersion(version) {
return (0, superstruct_1.is)(version, exports.VersionStruct);
}
exports.isValidSemVerVersion = isValidSemVerVersion;
/**
* Checks whether a SemVer version range is valid.
*
* @param versionRange - A potential version range.
* @returns `true` if the version range is valid, and `false` otherwise.
*/
function isValidSemVerRange(versionRange) {
return (0, superstruct_1.is)(versionRange, exports.VersionRangeStruct);
}
exports.isValidSemVerRange = isValidSemVerRange;
/**
* Asserts that a value is a valid concrete SemVer version.
*
* @param version - A potential SemVer concrete version.
*/
function assertIsSemVerVersion(version) {
(0, utils_1.assertStruct)(version, exports.VersionStruct);
}
exports.assertIsSemVerVersion = assertIsSemVerVersion;
/**
* Asserts that a value is a valid SemVer range.
*
* @param range - A potential SemVer range.
*/
function assertIsSemVerRange(range) {
(0, utils_1.assertStruct)(range, exports.VersionRangeStruct);
}
exports.assertIsSemVerRange = assertIsSemVerRange;
/**
* Checks whether a SemVer version is greater than another.
*
* @param version1 - The left-hand version.
* @param version2 - The right-hand version.
* @returns `version1 > version2`.
*/
function gtVersion(version1, version2) {
return (0, semver_1.gt)(version1, version2);
}
exports.gtVersion = gtVersion;
/**
* 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.
*
* @param version - The SemVer version to check.
* @param versionRange - The SemVer version range to check against.
* @returns Whether the version satisfied the version range.
*/
function satisfiesVersionRange(version, versionRange) {
return (0, semver_1.satisfies)(version, versionRange, {
includePrerelease: true,
});
}
exports.satisfiesVersionRange = satisfiesVersionRange;
/**
* Return the highest version in the list that satisfies the range, or `null` if

@@ -130,5 +42,5 @@ * none of them do. For the satisfaction check, pre-release versions will only

}
return (0, superstruct_1.validate)(version, exports.VersionRangeStruct);
return (0, superstruct_1.validate)(version, utils_1.VersionRangeStruct);
}
exports.resolveVersionRange = resolveVersionRange;
//# sourceMappingURL=versions.js.map
{
"name": "@metamask/snaps-utils",
"version": "0.27.1",
"version": "0.28.0",
"repository": {

@@ -56,4 +56,5 @@ "type": "git",

"@metamask/providers": "^10.2.1",
"@metamask/snaps-ui": "^0.27.1",
"@metamask/utils": "^3.3.1",
"@metamask/snaps-registry": "^1.0.0",
"@metamask/snaps-ui": "^0.28.0",
"@metamask/utils": "^3.4.1",
"@noble/hashes": "^1.1.3",

@@ -66,4 +67,4 @@ "@scure/base": "^1.1.1",

"semver": "^7.3.7",
"ses": "^0.17.0",
"superstruct": "^0.16.7",
"ses": "^0.18.1",
"superstruct": "^1.0.3",
"validate-npm-package-name": "^5.0.0"

@@ -78,2 +79,4 @@ },

"@metamask/eslint-config-typescript": "^11.0.0",
"@metamask/key-tree": "^6.2.0",
"@metamask/post-message-stream": "^6.1.0",
"@types/jest": "^27.5.1",

@@ -98,2 +101,3 @@ "@types/semver": "^7.3.10",

"rimraf": "^3.0.2",
"serve-handler": "^6.1.5",
"ts-jest": "^29.0.0",

@@ -100,0 +104,0 @@ "typescript": "~4.8.4"

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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc