diff --git a/packages/snaps-cli/src/structs.test.ts b/packages/snaps-cli/src/structs.test.ts index 42c1106119..534fd569fd 100644 --- a/packages/snaps-cli/src/structs.test.ts +++ b/packages/snaps-cli/src/structs.test.ts @@ -1,5 +1,5 @@ -import { resolve } from 'path/posix'; import { create, is } from '@metamask/superstruct'; +import { resolve } from 'path/posix'; import { file } from './structs'; diff --git a/packages/snaps-cli/src/structs.ts b/packages/snaps-cli/src/structs.ts index 4acb094a81..c6bd57ec59 100644 --- a/packages/snaps-cli/src/structs.ts +++ b/packages/snaps-cli/src/structs.ts @@ -1,5 +1,5 @@ -import { resolve } from 'path'; import { coerce, string } from '@metamask/superstruct'; +import { resolve } from 'path'; /** * A wrapper of `superstruct`'s `string` struct that coerces a value to a string diff --git a/packages/snaps-controllers/src/services/AbstractExecutionService.ts b/packages/snaps-controllers/src/services/AbstractExecutionService.ts index 6b5f9c57d2..c0b0d102a6 100644 --- a/packages/snaps-controllers/src/services/AbstractExecutionService.ts +++ b/packages/snaps-controllers/src/services/AbstractExecutionService.ts @@ -441,9 +441,8 @@ export abstract class AbstractExecutionService } log('Parent: Sending Command', message); - const response: PendingJsonRpcResponse = await job.rpcEngine.handle( - message, - ); + const response: PendingJsonRpcResponse = + job.rpcEngine.handle(message); if (response.error) { throw new JsonRpcError( diff --git a/packages/snaps-execution-environments/src/common/BaseSnapExecutor.ts b/packages/snaps-execution-environments/src/common/BaseSnapExecutor.ts index e2ccd1d865..cabd40c57d 100644 --- a/packages/snaps-execution-environments/src/common/BaseSnapExecutor.ts +++ b/packages/snaps-execution-environments/src/common/BaseSnapExecutor.ts @@ -19,6 +19,7 @@ import { unwrapError, logInfo, } from '@metamask/snaps-utils'; +import { validate, is } from '@metamask/superstruct'; import type { JsonRpcNotification, JsonRpcId, @@ -33,7 +34,6 @@ import { JsonRpcIdStruct, } from '@metamask/utils'; import type { Duplex } from 'readable-stream'; -import { validate, is } from '@metamask/superstruct'; import { log } from '../logging'; import type { CommandMethodsMapping } from './commands'; diff --git a/packages/snaps-jest/src/internals/request.ts b/packages/snaps-jest/src/internals/request.ts index dd112aef13..3cbda61b4c 100644 --- a/packages/snaps-jest/src/internals/request.ts +++ b/packages/snaps-jest/src/internals/request.ts @@ -7,6 +7,7 @@ import { } from '@metamask/snaps-sdk'; import type { HandlerType } from '@metamask/snaps-utils'; import { unwrapError } from '@metamask/snaps-utils'; +import { is } from '@metamask/superstruct'; import { assert, getSafeJson, @@ -14,7 +15,6 @@ import { isPlainObject, } from '@metamask/utils'; import { nanoid } from '@reduxjs/toolkit'; -import { is } from '@metamask/superstruct'; import type { RequestOptions, diff --git a/packages/snaps-jest/src/internals/simulation/options.ts b/packages/snaps-jest/src/internals/simulation/options.ts index e090e68ab1..2ea0be940f 100644 --- a/packages/snaps-jest/src/internals/simulation/options.ts +++ b/packages/snaps-jest/src/internals/simulation/options.ts @@ -1,4 +1,3 @@ -import { JsonStruct } from '@metamask/utils'; import type { Infer } from '@metamask/superstruct'; import { create, @@ -9,6 +8,7 @@ import { record, string, } from '@metamask/superstruct'; +import { JsonStruct } from '@metamask/utils'; import { DEFAULT_LOCALE, DEFAULT_SRP } from './constants'; diff --git a/packages/snaps-jest/src/internals/structs.ts b/packages/snaps-jest/src/internals/structs.ts index 1a886e95ba..1d19d6a67a 100644 --- a/packages/snaps-jest/src/internals/structs.ts +++ b/packages/snaps-jest/src/internals/structs.ts @@ -1,12 +1,5 @@ import { NotificationType, enumValue } from '@metamask/snaps-sdk'; import { JSXElementStruct } from '@metamask/snaps-sdk/jsx'; -import { - bytesToHex, - JsonStruct, - StrictHexStruct, - valueToBytes, -} from '@metamask/utils'; -import { randomBytes } from 'crypto'; import { array, assign, @@ -25,6 +18,13 @@ import { func, type, } from '@metamask/superstruct'; +import { + bytesToHex, + JsonStruct, + StrictHexStruct, + valueToBytes, +} from '@metamask/utils'; +import { randomBytes } from 'crypto'; // TODO: Export this from `@metamask/utils` instead. const BytesLikeStruct = union([ diff --git a/packages/snaps-jest/src/matchers.ts b/packages/snaps-jest/src/matchers.ts index ec8a1aa99d..bf08b706d9 100644 --- a/packages/snaps-jest/src/matchers.ts +++ b/packages/snaps-jest/src/matchers.ts @@ -14,6 +14,7 @@ import type { import type { JSXElement, SnapNode } from '@metamask/snaps-sdk/jsx'; import { isJSXElementUnsafe } from '@metamask/snaps-sdk/jsx'; import { getJsxElementFromComponent } from '@metamask/snaps-utils'; +import { is } from '@metamask/superstruct'; import type { Json } from '@metamask/utils'; import { hasProperty } from '@metamask/utils'; import type { MatcherHintOptions } from 'jest-matcher-utils'; @@ -26,7 +27,6 @@ import { printWithType, RECEIVED_COLOR, } from 'jest-matcher-utils'; -import { is } from '@metamask/superstruct'; import { InterfaceStruct, SnapResponseStruct } from './internals'; import type { SnapResponse } from './types'; diff --git a/packages/snaps-jest/src/types.ts b/packages/snaps-jest/src/types.ts index be9e7210c9..edd34518ab 100644 --- a/packages/snaps-jest/src/types.ts +++ b/packages/snaps-jest/src/types.ts @@ -1,8 +1,8 @@ import type { NotificationType, EnumToUnion } from '@metamask/snaps-sdk'; import type { JSXElement } from '@metamask/snaps-sdk/jsx'; import type { InferMatching } from '@metamask/snaps-utils'; -import type { Json, JsonRpcId, JsonRpcParams } from '@metamask/utils'; import type { Infer } from '@metamask/superstruct'; +import type { Json, JsonRpcId, JsonRpcParams } from '@metamask/utils'; import type { SignatureOptionsStruct, diff --git a/packages/snaps-rpc-methods/src/permitted/getFile.ts b/packages/snaps-rpc-methods/src/permitted/getFile.ts index c2785596c7..f256677a9f 100644 --- a/packages/snaps-rpc-methods/src/permitted/getFile.ts +++ b/packages/snaps-rpc-methods/src/permitted/getFile.ts @@ -4,9 +4,9 @@ import { rpcErrors } from '@metamask/rpc-errors'; import type { GetFileParams, GetFileResult } from '@metamask/snaps-sdk'; import { AuxiliaryFileEncoding, enumValue } from '@metamask/snaps-sdk'; import type { InferMatching } from '@metamask/snaps-utils'; +import { object, optional, string, union } from '@metamask/superstruct'; import type { PendingJsonRpcResponse, JsonRpcRequest } from '@metamask/utils'; import { assertStruct } from '@metamask/utils'; -import { object, optional, string, union } from '@metamask/superstruct'; import type { MethodHooksObject } from '../utils'; diff --git a/packages/snaps-rpc-methods/src/permitted/getInterfaceState.ts b/packages/snaps-rpc-methods/src/permitted/getInterfaceState.ts index c2d8b3f35f..acd1568cb7 100644 --- a/packages/snaps-rpc-methods/src/permitted/getInterfaceState.ts +++ b/packages/snaps-rpc-methods/src/permitted/getInterfaceState.ts @@ -8,8 +8,8 @@ import type { JsonRpcRequest, } from '@metamask/snaps-sdk'; import { type InferMatching } from '@metamask/snaps-utils'; -import type { PendingJsonRpcResponse } from '@metamask/utils'; import { StructError, create, object, string } from '@metamask/superstruct'; +import type { PendingJsonRpcResponse } from '@metamask/utils'; import type { MethodHooksObject } from '../utils'; diff --git a/packages/snaps-rpc-methods/src/permitted/updateInterface.ts b/packages/snaps-rpc-methods/src/permitted/updateInterface.ts index e7acd44f00..13c6bf0c4b 100644 --- a/packages/snaps-rpc-methods/src/permitted/updateInterface.ts +++ b/packages/snaps-rpc-methods/src/permitted/updateInterface.ts @@ -9,8 +9,8 @@ import type { } from '@metamask/snaps-sdk'; import { ComponentOrElementStruct } from '@metamask/snaps-sdk'; import { type InferMatching } from '@metamask/snaps-utils'; -import type { PendingJsonRpcResponse } from '@metamask/utils'; import { StructError, create, object, string } from '@metamask/superstruct'; +import type { PendingJsonRpcResponse } from '@metamask/utils'; import type { MethodHooksObject } from '../utils'; diff --git a/packages/snaps-rpc-methods/src/restricted/caveats/permittedDerivationPaths.ts b/packages/snaps-rpc-methods/src/restricted/caveats/permittedDerivationPaths.ts index 074f9cb5d5..7b856425a0 100644 --- a/packages/snaps-rpc-methods/src/restricted/caveats/permittedDerivationPaths.ts +++ b/packages/snaps-rpc-methods/src/restricted/caveats/permittedDerivationPaths.ts @@ -10,9 +10,9 @@ import { Bip32EntropyStruct, isEqual, } from '@metamask/snaps-utils'; +import { array, size, type } from '@metamask/superstruct'; import type { Json } from '@metamask/utils'; import { assertStruct } from '@metamask/utils'; -import { array, size, type } from '@metamask/superstruct'; /** * Map a raw value from the `initialPermissions` to a caveat specification. diff --git a/packages/snaps-rpc-methods/src/restricted/caveats/snapIds.ts b/packages/snaps-rpc-methods/src/restricted/caveats/snapIds.ts index 61ad66642d..f0923e9b8e 100644 --- a/packages/snaps-rpc-methods/src/restricted/caveats/snapIds.ts +++ b/packages/snaps-rpc-methods/src/restricted/caveats/snapIds.ts @@ -8,9 +8,9 @@ import type { import { rpcErrors } from '@metamask/rpc-errors'; import type { SnapIds } from '@metamask/snaps-utils'; import { SnapCaveatType, SnapIdsStruct } from '@metamask/snaps-utils'; +import { type } from '@metamask/superstruct'; import type { Json } from '@metamask/utils'; import { hasProperty, assertStruct } from '@metamask/utils'; -import { type } from '@metamask/superstruct'; import type { InvokeSnapParams } from '../invokeSnap'; diff --git a/packages/snaps-rpc-methods/src/restricted/dialog.ts b/packages/snaps-rpc-methods/src/restricted/dialog.ts index f1630d340f..f10389f8ec 100644 --- a/packages/snaps-rpc-methods/src/restricted/dialog.ts +++ b/packages/snaps-rpc-methods/src/restricted/dialog.ts @@ -21,7 +21,6 @@ import type { } from '@metamask/snaps-sdk'; import { createUnion } from '@metamask/snaps-utils'; import type { InferMatching } from '@metamask/snaps-utils'; -import { hasProperty, type NonEmptyArray } from '@metamask/utils'; import type { Infer, Struct } from '@metamask/superstruct'; import { create, @@ -32,6 +31,7 @@ import { string, type, } from '@metamask/superstruct'; +import { hasProperty, type NonEmptyArray } from '@metamask/utils'; import { type MethodHooksObject } from '../utils'; diff --git a/packages/snaps-rpc-methods/src/restricted/getEntropy.ts b/packages/snaps-rpc-methods/src/restricted/getEntropy.ts index 5570242648..ecf9709ff1 100644 --- a/packages/snaps-rpc-methods/src/restricted/getEntropy.ts +++ b/packages/snaps-rpc-methods/src/restricted/getEntropy.ts @@ -7,10 +7,10 @@ import { PermissionType, SubjectType } from '@metamask/permission-controller'; import { rpcErrors } from '@metamask/rpc-errors'; import type { GetEntropyParams, GetEntropyResult } from '@metamask/snaps-sdk'; import { SIP_6_MAGIC_VALUE } from '@metamask/snaps-utils'; -import type { NonEmptyArray } from '@metamask/utils'; -import { assertStruct } from '@metamask/utils'; import type { Infer } from '@metamask/superstruct'; import { literal, object, optional, string } from '@metamask/superstruct'; +import type { NonEmptyArray } from '@metamask/utils'; +import { assertStruct } from '@metamask/utils'; import type { MethodHooksObject } from '../utils'; import { deriveEntropy } from '../utils'; diff --git a/packages/snaps-rpc-methods/src/restricted/manageAccounts.ts b/packages/snaps-rpc-methods/src/restricted/manageAccounts.ts index 9c382e2fb9..220fa25ba2 100644 --- a/packages/snaps-rpc-methods/src/restricted/manageAccounts.ts +++ b/packages/snaps-rpc-methods/src/restricted/manageAccounts.ts @@ -9,8 +9,6 @@ import type { ManageAccountsResult, } from '@metamask/snaps-sdk'; import type { InferMatching } from '@metamask/snaps-utils'; -import type { Json, NonEmptyArray } from '@metamask/utils'; -import { JsonStruct } from '@metamask/utils'; import { assert, string, @@ -19,6 +17,8 @@ import { array, record, } from '@metamask/superstruct'; +import type { Json, NonEmptyArray } from '@metamask/utils'; +import { JsonStruct } from '@metamask/utils'; const SnapMessageStruct = union([ object({ diff --git a/packages/snaps-sdk/src/ui/builder.ts b/packages/snaps-sdk/src/ui/builder.ts index a40e7fb621..03514b2533 100644 --- a/packages/snaps-sdk/src/ui/builder.ts +++ b/packages/snaps-sdk/src/ui/builder.ts @@ -1,5 +1,5 @@ -import { assertStruct, isPlainObject } from '@metamask/utils'; import type { Struct } from '@metamask/superstruct'; +import { assertStruct, isPlainObject } from '@metamask/utils'; import type { Component } from './components'; import type { NodeType } from './nodes'; diff --git a/packages/snaps-sdk/src/ui/component.ts b/packages/snaps-sdk/src/ui/component.ts index 66628c0348..a482e99ce2 100644 --- a/packages/snaps-sdk/src/ui/component.ts +++ b/packages/snaps-sdk/src/ui/component.ts @@ -1,5 +1,5 @@ -import { assertStruct } from '@metamask/utils'; import { is } from '@metamask/superstruct'; +import { assertStruct } from '@metamask/utils'; import { ComponentStruct } from './components'; import type { Component } from './components'; diff --git a/packages/snaps-sdk/src/ui/components/address.ts b/packages/snaps-sdk/src/ui/components/address.ts index 90317283fc..b90871e54a 100644 --- a/packages/snaps-sdk/src/ui/components/address.ts +++ b/packages/snaps-sdk/src/ui/components/address.ts @@ -1,6 +1,6 @@ -import { HexChecksumAddressStruct } from '@metamask/utils'; import type { Infer } from '@metamask/superstruct'; import { assign, literal, object } from '@metamask/superstruct'; +import { HexChecksumAddressStruct } from '@metamask/utils'; import { createBuilder } from '../builder'; import { LiteralStruct, NodeType } from '../nodes'; diff --git a/packages/snaps-utils/src/cronjob.ts b/packages/snaps-utils/src/cronjob.ts index 9f613bf1ae..694ce762c0 100644 --- a/packages/snaps-utils/src/cronjob.ts +++ b/packages/snaps-utils/src/cronjob.ts @@ -1,9 +1,3 @@ -import { - JsonRpcIdStruct, - JsonRpcParamsStruct, - JsonRpcVersionStruct, -} from '@metamask/utils'; -import { parseExpression } from 'cron-parser'; import type { Infer } from '@metamask/superstruct'; import { array, @@ -13,6 +7,12 @@ import { refine, string, } from '@metamask/superstruct'; +import { + JsonRpcIdStruct, + JsonRpcParamsStruct, + JsonRpcVersionStruct, +} from '@metamask/utils'; +import { parseExpression } from 'cron-parser'; export const CronjobRpcRequestStruct = object({ jsonrpc: optional(JsonRpcVersionStruct), diff --git a/packages/snaps-utils/src/json-rpc.ts b/packages/snaps-utils/src/json-rpc.ts index 8c1275f3ad..4792eecc3d 100644 --- a/packages/snaps-utils/src/json-rpc.ts +++ b/packages/snaps-utils/src/json-rpc.ts @@ -1,4 +1,13 @@ import { SubjectType } from '@metamask/permission-controller'; +import type { Infer } from '@metamask/superstruct'; +import { + array, + boolean, + object, + optional, + refine, + string, +} from '@metamask/superstruct'; import type { AssertionErrorConstructor, Json, @@ -9,15 +18,6 @@ import { isJsonRpcFailure, isJsonRpcSuccess, } from '@metamask/utils'; -import type { Infer } from '@metamask/superstruct'; -import { - array, - boolean, - object, - optional, - refine, - string, -} from '@metamask/superstruct'; const AllowedOriginsStruct = array( refine(string(), 'Allowed origin', (value) => { diff --git a/packages/snaps-utils/src/snaps.ts b/packages/snaps-utils/src/snaps.ts index f720d89912..5db313e993 100644 --- a/packages/snaps-utils/src/snaps.ts +++ b/packages/snaps-utils/src/snaps.ts @@ -5,10 +5,6 @@ import type { } from '@metamask/permission-controller'; import type { BlockReason } from '@metamask/snaps-registry'; import type { SnapId, Snap as TruncatedSnap } from '@metamask/snaps-sdk'; -import type { Json } from '@metamask/utils'; -import { assert, isObject, assertStruct } from '@metamask/utils'; -import { base64 } from '@scure/base'; -import stableStringify from 'fast-json-stable-stringify'; import type { Struct } from '@metamask/superstruct'; import { empty, @@ -21,6 +17,10 @@ import { union, validate, } from '@metamask/superstruct'; +import type { Json } from '@metamask/utils'; +import { assert, isObject, assertStruct } from '@metamask/utils'; +import { base64 } from '@scure/base'; +import stableStringify from 'fast-json-stable-stringify'; import validateNPMPackage from 'validate-npm-package-name'; import { SnapCaveatType } from './caveats'; diff --git a/packages/snaps-utils/src/structs.test.ts b/packages/snaps-utils/src/structs.test.ts index 923e96c611..8e1110a917 100644 --- a/packages/snaps-utils/src/structs.test.ts +++ b/packages/snaps-utils/src/structs.test.ts @@ -1,6 +1,4 @@ import { union, literal } from '@metamask/snaps-sdk'; -import { assert } from '@metamask/utils'; -import { bold, green, red } from 'chalk'; import type { Struct } from '@metamask/superstruct'; import superstruct, { size, @@ -12,6 +10,8 @@ import superstruct, { union as superstructUnion, array, } from '@metamask/superstruct'; +import { assert } from '@metamask/utils'; +import { bold, green, red } from 'chalk'; import { arrayToGenerator, diff --git a/packages/snaps-utils/src/structs.ts b/packages/snaps-utils/src/structs.ts index 1bed08fc10..1c619f2904 100644 --- a/packages/snaps-utils/src/structs.ts +++ b/packages/snaps-utils/src/structs.ts @@ -1,8 +1,4 @@ import { union } from '@metamask/snaps-sdk'; -import type { NonEmptyArray } from '@metamask/utils'; -import { assert, isObject } from '@metamask/utils'; -import { bold, green, red } from 'chalk'; -import type { Failure } from '@metamask/superstruct'; import { is, validate, @@ -11,7 +7,10 @@ import { StructError, create, } from '@metamask/superstruct'; -import type { AnyStruct } from '@metamask/superstruct'; +import type { Failure, AnyStruct } from '@metamask/superstruct'; +import type { NonEmptyArray } from '@metamask/utils'; +import { assert, isObject } from '@metamask/utils'; +import { bold, green, red } from 'chalk'; import { indent } from './strings'; diff --git a/packages/snaps-utils/src/types.ts b/packages/snaps-utils/src/types.ts index a1adad7e68..8aed6bd340 100644 --- a/packages/snaps-utils/src/types.ts +++ b/packages/snaps-utils/src/types.ts @@ -1,5 +1,3 @@ -import type { Json } from '@metamask/utils'; -import { assertStruct, VersionStruct } from '@metamask/utils'; import type { Infer, Struct } from '@metamask/superstruct'; import { instance, @@ -14,6 +12,8 @@ import { union, assert as assertSuperstruct, } from '@metamask/superstruct'; +import type { Json } from '@metamask/utils'; +import { assertStruct, VersionStruct } from '@metamask/utils'; import type { SnapCaveatType } from './caveats'; import type { SnapFunctionExports, SnapRpcHookArgs } from './handlers'; diff --git a/packages/snaps-utils/src/versions.ts b/packages/snaps-utils/src/versions.ts index 399bd84a58..0eaf0f32bb 100644 --- a/packages/snaps-utils/src/versions.ts +++ b/packages/snaps-utils/src/versions.ts @@ -1,7 +1,7 @@ +import { validate } from '@metamask/superstruct'; import type { Json, SemVerVersion, SemVerRange } from '@metamask/utils'; import { VersionRangeStruct } from '@metamask/utils'; import { maxSatisfying as maxSatisfyingSemver } from 'semver'; -import { validate } from '@metamask/superstruct'; export const DEFAULT_REQUESTED_SNAP_VERSION = '*' as SemVerRange;