Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
bf479b4
Bump TypeScript to `~5.0.4`
MajorLift Dec 9, 2023
5084b8f
Set tsconfig `module`, `moduleResolution` options to `NodeNext`
MajorLift May 9, 2024
1d77aa8
'yarn build:types' works
mcmire Mar 14, 2024
dd45b15
Apply yarn patches to replace superstruct imports with `@metamask/sup…
MajorLift Jun 27, 2024
6e73a35
Linter fixes
MajorLift Jun 27, 2024
cad9be5
Bump TypeScript to `~5.0.4` in remaining packages
MajorLift May 31, 2024
a014d03
Fix missing yarn patch for `@metamask/keyring-api@^6.1.1`
MajorLift Jun 27, 2024
1d8944a
Replace `multiformats` import with dynamic import, and convert method…
MajorLift May 31, 2024
c509fb4
Apply `--experimental-vm-modules` flag to jest test scripts to enable…
MajorLift May 31, 2024
94ddd59
Update yarn constraints to apply `--experimental-vm-modules` flag to …
MajorLift Jun 27, 2024
c21f3f9
Remove `EthErc4337Method` enum usage due to upstream removal
MajorLift Jun 2, 2024
1b6fec9
Apply yarn patch to new `@metamask/keyring-api` version
MajorLift Jun 27, 2024
8a5c556
Linter fixes
MajorLift Jun 27, 2024
853340d
Linter fixes
MajorLift Jun 3, 2024
aceb333
Bump dependencies requiring new releases to latest
MajorLift Jun 27, 2024
fc9c89f
Apply yarn patch for `@metamask/snaps-sdk` `^4.4.1`
MajorLift Jun 27, 2024
6af5113
Apply yarn patch for `@metamask/snaps-utils` `^7.4.1`
MajorLift Jun 27, 2024
dc29903
Update yarn resolutions for dependencies affected by `superstruct` issue
MajorLift Jun 27, 2024
ac77a7b
Bump `@metamask/utils` from `^8.3.0` to `^8.5.0` in all packages
MajorLift Jun 27, 2024
a8b8a0d
Bump out-of-sync dependencies
MajorLift Jun 25, 2024
b35692d
Force yarn resolution for `@metamask/provider` to `17.1.0` release ca…
MajorLift Jun 26, 2024
4cfe39a
Update resolutions for new releases
MajorLift Jun 27, 2024
468f6d3
Merge branch 'main' into 231208-typescript-module-resolution
MajorLift Jun 27, 2024
cbf9e38
Remove unused yarn resolution for `superstruct`
MajorLift Jun 27, 2024
55a507e
Remove yarn resolutions for `@metamask/{providers,snaps-registry}`
MajorLift Jun 27, 2024
90962b5
[assets-controllers] Bump `@metamask/abi-utils` from `^2.0.2` to `^2.…
MajorLift Jun 27, 2024
7760b3d
Add yarn patches for `@metamask/snaps-{sdk,utils}` removing `superstr…
MajorLift Jun 27, 2024
cbbd428
Merge branch 'main' into 231208-typescript-module-resolution
MajorLift Jun 27, 2024
a67c547
Fix subpath imports, which are no longer supported unless specified i…
MajorLift Jun 27, 2024
864ec65
Bump `@metamask/utils` from `^8.5.0` to `^9.0.0`
MajorLift Jun 28, 2024
9bbd37d
Force yarn resolution for `@metamask/utils` to `9.0.0`
MajorLift Jun 29, 2024
bf5d240
Bump `@metamask/rpc-errors` from `^6.2.1` to `^6.3.1`
MajorLift Jul 3, 2024
2ca4265
Revert "Force yarn resolution for `@metamask/utils` to `9.0.0`"
MajorLift Jul 3, 2024
cb032c2
Bump `@metamask/chain-api` from `^0.0.1` to `^0.1.0`
MajorLift Jul 3, 2024
07fbffc
Fix lockfile
MajorLift Jul 3, 2024
d9160c6
Merge branch 'main' into 231208-typescript-module-resolution
MajorLift Jul 3, 2024
1a1b497
Merge branch 'main' into 231208-typescript-module-resolution
MajorLift Jul 5, 2024
9ddd7e6
Replace yarn resolutions for `@metamask/snaps-{sdk,utils}` with wip b…
MajorLift Jul 5, 2024
261638a
Remove unnecessary yarn resolution for `@metamask/eth-snap-keyring`
MajorLift Jul 5, 2024
e0ff883
Remove unused yarn patch files
MajorLift Jul 5, 2024
9226a38
Remove unused entry from .depcheckrc.yml
MajorLift Jul 6, 2024
555ec31
Update jest.config.scripts.js
MajorLift Jul 6, 2024
6defd76
build(tsc): Set `moduleResolution` to `node16`
MajorLift Jul 7, 2024
99abde6
Merge branch 'main' into 231208-typescript-module-resolution
MajorLift Jul 8, 2024
0910cea
Dedupe lockfile
MajorLift Jul 8, 2024
f28ecd5
Merge branch 'main' into 231208-typescript-module-resolution
MajorLift Jul 10, 2024
67f1484
Merge branch 'main' into 231208-typescript-module-resolution
MajorLift Jul 11, 2024
f37057c
Merge branch 'main' into 231208-typescript-module-resolution
MajorLift Jul 11, 2024
b0fd3b8
Remove unused `ts-expect-error` directive
MajorLift Jul 11, 2024
b8f8c52
Update yarn resolution for snaps monorepo and fix `@metamask/provider…
MajorLift Jul 14, 2024
87af678
Merge branch 'main' into 231208-typescript-module-resolution
MajorLift Jul 14, 2024
f2f7d1f
Remove yarn resolution for `@metamask/providers` `17.0.0`
MajorLift Jul 14, 2024
6f69db3
Merge branch 'main' into 231208-typescript-module-resolution
MajorLift Jul 16, 2024
27ba6c5
Bump `@metamask/keyring-api` from `^8.0.0` to `^8.0.1`
MajorLift Jul 17, 2024
b0c81fb
Merge branch 'main' into 231208-typescript-module-resolution
MajorLift Jul 17, 2024
09b29ca
Update yarn resolutions for `snaps-{sdk,utils}`
MajorLift Jul 17, 2024
de15ab3
Merge branch 'main' into 231208-typescript-module-resolution
MajorLift Jul 17, 2024
59fe394
Bump `@metamask/snaps-sdk` to `^6.1.0`, `@metamask/snaps-utils` to `^…
MajorLift Jul 19, 2024
6b0075d
Merge branch 'main' into 231208-typescript-module-resolution
MajorLift Jul 19, 2024
f50b209
Set yarn resolution for `@metamask/[email protected]` dependency `@meta…
MajorLift Jul 19, 2024
5f0b948
Merge branch 'main' into 231208-typescript-module-resolution
MajorLift Jul 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Apply yarn patches to replace superstruct imports with `@metamask/sup…
…erstruct` in all core nested dependencies
  • Loading branch information
MajorLift committed Jun 27, 2024
commit dd45b15542c09ccab612368cf92682909505d357
21 changes: 21 additions & 0 deletions .yarn/patches/@metamask-keyring-api-npm-6.1.0-1b3da6f710.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
diff --git a/dist/superstruct.d.ts b/dist/superstruct.d.ts
index b81329da445b729dc26533adb51443f14e58e5dc..2857b6d3d4c9070d7c557bd15f7c1b9bc41c9951 100644
--- a/dist/superstruct.d.ts
+++ b/dist/superstruct.d.ts
@@ -1,6 +1,6 @@
import type { Infer } from 'superstruct';
import { Struct } from 'superstruct';
-import type { ObjectSchema, OmitBy, Optionalize, PickBy, Simplify } from 'superstruct/dist/utils';
+import type { ObjectSchema, OmitBy, Optionalize, PickBy, Simplify } from 'superstruct';
declare const ExactOptionalSymbol: unique symbol;
export declare type ExactOptionalTag = {
type: typeof ExactOptionalSymbol;
diff --git a/dist/superstruct.js.map b/dist/superstruct.js.map
index 746668d2b1959fedd9150a9faf35ea30e30b5a7a..aaf130b761f57ade6c49f009f1f5c825186e858a 100644
--- a/dist/superstruct.js.map
+++ b/dist/superstruct.js.map
@@ -1 +1 @@
-{"version":3,"file":"superstruct.js","sourceRoot":"","sources":["../src/superstruct.ts"],"names":[],"mappings":";;;AACA,6CAAiE;AAkDjE;;;;;;GAMG;AACH,SAAgB,MAAM,CACpB,MAAc;IAEd,OAAO,IAAA,oBAAQ,EAAC,MAAM,CAAQ,CAAC;AACjC,CAAC;AAJD,wBAIC;AAED;;;;;GAKG;AACH,SAAS,WAAW,CAAC,GAAY;IAC/B,MAAM,QAAQ,GAAW,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACvD,MAAM,MAAM,GAA4B,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAE1E,OAAO,QAAQ,IAAI,MAAM,CAAC;AAC5B,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,aAAa,CAC3B,MAA4B;IAE5B,OAAO,IAAI,oBAAM,CAAC;QAChB,GAAG,MAAM;QAET,SAAS,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CACxB,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC;QAEnD,OAAO,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CACtB,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAa,EAAE,GAAG,CAAC;KAC1D,CAAC,CAAC;AACL,CAAC;AAZD,sCAYC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,aAAa,CAC3B,IAAY,EACZ,OAAe;IAEf,OAAO,IAAA,oBAAM,EACX,IAAI,EACJ,CAAC,KAAc,EAAW,EAAE,CAC1B,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CACnD,CAAC;AACJ,CAAC;AATD,sCASC;AAED;;;;;GAKG;AACU,QAAA,SAAS,GAAG,IAAA,oBAAM,EAAS,KAAK,EAAE,CAAC,KAAc,EAAE,EAAE;IAChE,IAAI,GAAG,CAAC;IAER,IAAI;QACF,GAAG,GAAG,IAAI,GAAG,CAAC,KAAe,CAAC,CAAC;KAChC;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,KAAK,CAAC;KACd;IAED,OAAO,GAAG,CAAC,QAAQ,KAAK,OAAO,IAAI,GAAG,CAAC,QAAQ,KAAK,QAAQ,CAAC;AAC/D,CAAC,CAAC,CAAC","sourcesContent":["import type { Infer, Context } from 'superstruct';\nimport { Struct, define, object as stObject } from 'superstruct';\nimport type {\n ObjectSchema,\n OmitBy,\n Optionalize,\n PickBy,\n Simplify,\n} from 'superstruct/dist/utils';\n\ndeclare const ExactOptionalSymbol: unique symbol;\n\nexport type ExactOptionalTag = {\n type: typeof ExactOptionalSymbol;\n};\n\n/**\n * Exclude type `Type` from the properties of `Obj`.\n *\n * ```ts\n * type Foo = { a: string | null; b: number };\n * type Bar = ExcludeType<Foo, null>;\n * // Bar = { a: string, b: number }\n * ```\n */\nexport type ExcludeType<Obj, Type> = {\n [K in keyof Obj]: Exclude<Obj[K], Type>;\n};\n\n/**\n * Make optional all properties that have the `ExactOptionalTag` type.\n *\n * ```ts\n * type Foo = { a: string | ExactOptionalTag; b: number};\n * type Bar = ExactOptionalize<Foo>;\n * // Bar = { a?: string; b: number}\n * ```\n */\nexport type ExactOptionalize<Schema extends object> = OmitBy<\n Schema,\n ExactOptionalTag\n> &\n Partial<ExcludeType<PickBy<Schema, ExactOptionalTag>, ExactOptionalTag>>;\n\n/**\n * Infer a type from an superstruct object schema.\n */\nexport type ObjectType<Schema extends ObjectSchema> = Simplify<\n ExactOptionalize<Optionalize<{ [K in keyof Schema]: Infer<Schema[K]> }>>\n>;\n\n/**\n * Change the return type of a superstruct object struct to support exact\n * optional properties.\n *\n * @param schema - The object schema.\n * @returns A struct representing an object with a known set of properties.\n */\nexport function object<Schema extends ObjectSchema>(\n schema: Schema,\n): Struct<ObjectType<Schema>, Schema> {\n return stObject(schema) as any;\n}\n\n/**\n * Check if the current property is present in its parent object.\n *\n * @param ctx - The context to check.\n * @returns `true` if the property is present, `false` otherwise.\n */\nfunction hasOptional(ctx: Context): boolean {\n const property: string = ctx.path[ctx.path.length - 1];\n const parent: Record<string, unknown> = ctx.branch[ctx.branch.length - 2];\n\n return property in parent;\n}\n\n/**\n * Augment a struct to allow exact-optional values. Exact-optional values can\n * be omitted but cannot be `undefined`.\n *\n * ```ts\n * const foo = object({ bar: exactOptional(string()) });\n * type Foo = Infer<typeof foo>;\n * // Foo = { bar?: string }\n * ```\n *\n * @param struct - The struct to augment.\n * @returns The augmented struct.\n */\nexport function exactOptional<Type, Schema>(\n struct: Struct<Type, Schema>,\n): Struct<Type | ExactOptionalTag, Schema> {\n return new Struct({\n ...struct,\n\n validator: (value, ctx) =>\n !hasOptional(ctx) || struct.validator(value, ctx),\n\n refiner: (value, ctx) =>\n !hasOptional(ctx) || struct.refiner(value as Type, ctx),\n });\n}\n\n/**\n * Defines a new string-struct matching a regular expression.\n *\n * Example:\n *\n * ```ts\n * const EthAddressStruct = definePattern('EthAddress', /^0x[0-9a-f]{40}$/iu);\n * ```\n *\n * @param name - Type name.\n * @param pattern - Regular expression to match.\n * @returns A new string-struct that matches the given pattern.\n */\nexport function definePattern(\n name: string,\n pattern: RegExp,\n): Struct<string, null> {\n return define<string>(\n name,\n (value: unknown): boolean =>\n typeof value === 'string' && pattern.test(value),\n );\n}\n\n/**\n * Validates if a given value is a valid URL.\n *\n * @param value - The value to be validated.\n * @returns A boolean indicating if the value is a valid URL.\n */\nexport const UrlStruct = define<string>('Url', (value: unknown) => {\n let url;\n\n try {\n url = new URL(value as string);\n } catch (_) {\n return false;\n }\n\n return url.protocol === 'http:' || url.protocol === 'https:';\n});\n"]}
\ No newline at end of file
+{"version":3,"file":"superstruct.js","sourceRoot":"","sources":["../src/superstruct.ts"],"names":[],"mappings":";;;AACA,6CAAiE;AAkDjE;;;;;;GAMG;AACH,SAAgB,MAAM,CACpB,MAAc;IAEd,OAAO,IAAA,oBAAQ,EAAC,MAAM,CAAQ,CAAC;AACjC,CAAC;AAJD,wBAIC;AAED;;;;;GAKG;AACH,SAAS,WAAW,CAAC,GAAY;IAC/B,MAAM,QAAQ,GAAW,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACvD,MAAM,MAAM,GAA4B,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAE1E,OAAO,QAAQ,IAAI,MAAM,CAAC;AAC5B,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,aAAa,CAC3B,MAA4B;IAE5B,OAAO,IAAI,oBAAM,CAAC;QAChB,GAAG,MAAM;QAET,SAAS,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CACxB,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC;QAEnD,OAAO,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CACtB,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAa,EAAE,GAAG,CAAC;KAC1D,CAAC,CAAC;AACL,CAAC;AAZD,sCAYC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,aAAa,CAC3B,IAAY,EACZ,OAAe;IAEf,OAAO,IAAA,oBAAM,EACX,IAAI,EACJ,CAAC,KAAc,EAAW,EAAE,CAC1B,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CACnD,CAAC;AACJ,CAAC;AATD,sCASC;AAED;;;;;GAKG;AACU,QAAA,SAAS,GAAG,IAAA,oBAAM,EAAS,KAAK,EAAE,CAAC,KAAc,EAAE,EAAE;IAChE,IAAI,GAAG,CAAC;IAER,IAAI;QACF,GAAG,GAAG,IAAI,GAAG,CAAC,KAAe,CAAC,CAAC;KAChC;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,KAAK,CAAC;KACd;IAED,OAAO,GAAG,CAAC,QAAQ,KAAK,OAAO,IAAI,GAAG,CAAC,QAAQ,KAAK,QAAQ,CAAC;AAC/D,CAAC,CAAC,CAAC","sourcesContent":["import type { Infer, Context } from 'superstruct';\nimport { Struct, define, object as stObject } from 'superstruct';\nimport type {\n ObjectSchema,\n OmitBy,\n Optionalize,\n PickBy,\n Simplify,\n} from 'superstruct';\n\ndeclare const ExactOptionalSymbol: unique symbol;\n\nexport type ExactOptionalTag = {\n type: typeof ExactOptionalSymbol;\n};\n\n/**\n * Exclude type `Type` from the properties of `Obj`.\n *\n * ```ts\n * type Foo = { a: string | null; b: number };\n * type Bar = ExcludeType<Foo, null>;\n * // Bar = { a: string, b: number }\n * ```\n */\nexport type ExcludeType<Obj, Type> = {\n [K in keyof Obj]: Exclude<Obj[K], Type>;\n};\n\n/**\n * Make optional all properties that have the `ExactOptionalTag` type.\n *\n * ```ts\n * type Foo = { a: string | ExactOptionalTag; b: number};\n * type Bar = ExactOptionalize<Foo>;\n * // Bar = { a?: string; b: number}\n * ```\n */\nexport type ExactOptionalize<Schema extends object> = OmitBy<\n Schema,\n ExactOptionalTag\n> &\n Partial<ExcludeType<PickBy<Schema, ExactOptionalTag>, ExactOptionalTag>>;\n\n/**\n * Infer a type from an superstruct object schema.\n */\nexport type ObjectType<Schema extends ObjectSchema> = Simplify<\n ExactOptionalize<Optionalize<{ [K in keyof Schema]: Infer<Schema[K]> }>>\n>;\n\n/**\n * Change the return type of a superstruct object struct to support exact\n * optional properties.\n *\n * @param schema - The object schema.\n * @returns A struct representing an object with a known set of properties.\n */\nexport function object<Schema extends ObjectSchema>(\n schema: Schema,\n): Struct<ObjectType<Schema>, Schema> {\n return stObject(schema) as any;\n}\n\n/**\n * Check if the current property is present in its parent object.\n *\n * @param ctx - The context to check.\n * @returns `true` if the property is present, `false` otherwise.\n */\nfunction hasOptional(ctx: Context): boolean {\n const property: string = ctx.path[ctx.path.length - 1];\n const parent: Record<string, unknown> = ctx.branch[ctx.branch.length - 2];\n\n return property in parent;\n}\n\n/**\n * Augment a struct to allow exact-optional values. Exact-optional values can\n * be omitted but cannot be `undefined`.\n *\n * ```ts\n * const foo = object({ bar: exactOptional(string()) });\n * type Foo = Infer<typeof foo>;\n * // Foo = { bar?: string }\n * ```\n *\n * @param struct - The struct to augment.\n * @returns The augmented struct.\n */\nexport function exactOptional<Type, Schema>(\n struct: Struct<Type, Schema>,\n): Struct<Type | ExactOptionalTag, Schema> {\n return new Struct({\n ...struct,\n\n validator: (value, ctx) =>\n !hasOptional(ctx) || struct.validator(value, ctx),\n\n refiner: (value, ctx) =>\n !hasOptional(ctx) || struct.refiner(value as Type, ctx),\n });\n}\n\n/**\n * Defines a new string-struct matching a regular expression.\n *\n * Example:\n *\n * ```ts\n * const EthAddressStruct = definePattern('EthAddress', /^0x[0-9a-f]{40}$/iu);\n * ```\n *\n * @param name - Type name.\n * @param pattern - Regular expression to match.\n * @returns A new string-struct that matches the given pattern.\n */\nexport function definePattern(\n name: string,\n pattern: RegExp,\n): Struct<string, null> {\n return define<string>(\n name,\n (value: unknown): boolean =>\n typeof value === 'string' && pattern.test(value),\n );\n}\n\n/**\n * Validates if a given value is a valid URL.\n *\n * @param value - The value to be validated.\n * @returns A boolean indicating if the value is a valid URL.\n */\nexport const UrlStruct = define<string>('Url', (value: unknown) => {\n let url;\n\n try {\n url = new URL(value as string);\n } catch (_) {\n return false;\n }\n\n return url.protocol === 'http:' || url.protocol === 'https:';\n});\n"]}
\ No newline at end of file
86 changes: 86 additions & 0 deletions .yarn/patches/@metamask-snaps-sdk-npm-4.2.0-68c745cc62.patch

Large diffs are not rendered by default.

39 changes: 39 additions & 0 deletions .yarn/patches/@metamask-snaps-utils-npm-7.4.0-61301b942a.patch

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion jest.config.scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module.exports = {
// This ensures that Babel can resolve ESM exports correctly.
moduleNameMapper: {
'^@metamask/utils/(.+)$': [
'<rootDir>/node_modules/@metamask/utils/dist/$1.js',
'<rootDir>/node_modules/@metamask/utils/dist/$1.cjs',
],
},

Expand Down
11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@
"pre-push": "yarn lint"
},
"resolutions": {
"@metamask/keyring-api@^6.0.0": "patch:@metamask/keyring-api@npm%3A6.1.0#./.yarn/patches/@metamask-keyring-api-npm-6.1.0-1b3da6f710.patch",
"@metamask/keyring-api@^6.1.0": "patch:@metamask/keyring-api@npm%3A6.1.0#./.yarn/patches/@metamask-keyring-api-npm-6.1.0-1b3da6f710.patch",
"@metamask/snaps-sdk@^4.0.1": "patch:@metamask/snaps-sdk@npm%3A4.2.0#./.yarn/patches/@metamask-snaps-sdk-npm-4.2.0-68c745cc62.patch",
"@metamask/snaps-sdk@^4.0.0": "patch:@metamask/snaps-sdk@npm%3A4.2.0#./.yarn/patches/@metamask-snaps-sdk-npm-4.2.0-68c745cc62.patch",
"@metamask/snaps-sdk@^4.2.0": "patch:@metamask/snaps-sdk@npm%3A4.2.0#./.yarn/patches/@metamask-snaps-sdk-npm-4.2.0-68c745cc62.patch",
"@metamask/snaps-sdk@^4.1.0": "patch:@metamask/snaps-sdk@npm%3A4.2.0#./.yarn/patches/@metamask-snaps-sdk-npm-4.2.0-68c745cc62.patch",
"@metamask/snaps-utils@^7.1.0": "patch:@metamask/snaps-utils@npm%3A7.4.0#./.yarn/patches/@metamask-snaps-utils-npm-7.4.0-61301b942a.patch",
"@metamask/snaps-utils@^7.0.3": "patch:@metamask/snaps-utils@npm%3A7.4.0#./.yarn/patches/@metamask-snaps-utils-npm-7.4.0-61301b942a.patch",
"@metamask/snaps-utils@^7.3.0": "patch:@metamask/snaps-utils@npm%3A7.4.0#./.yarn/patches/@metamask-snaps-utils-npm-7.4.0-61301b942a.patch",
"@metamask/utils": "8.5.0",
"superstruct": "github:MetaMask/superstruct#v3.1.0",
"tsup@^8.0.2": "patch:tsup@npm%3A8.0.2#./.yarn/patches/tsup-npm-8.0.2-86e40f68a7.patch"
},
"devDependencies": {
Expand Down
14 changes: 6 additions & 8 deletions packages/assets-controllers/src/NftController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,6 @@ const SECOND_OWNER_ADDRESS = '0x500017171kasdfbou081';
const DEPRESSIONIST_CID_V1 =
'bafybeidf7aw7bmnmewwj4ayq3she2jfk5jrdpp24aaucf6fddzb3cfhrvm';

const DEPRESSIONIST_CLOUDFLARE_IPFS_SUBDOMAIN_PATH = getFormattedIpfsUrl(
IPFS_DEFAULT_GATEWAY_URL,
`ipfs://${DEPRESSIONIST_CID_V1}`,
true,
);

const SEPOLIA = {
chainId: toHex(11155111),
type: NetworkType.sepolia,
Expand Down Expand Up @@ -296,7 +290,7 @@ function setupController({
}

describe('NftController', () => {
beforeEach(() => {
beforeEach(async () => {
nock(NFT_API_BASE_URL)
.get(
`/tokens?chainIds=1&tokens=0x01%3A1&includeTopBid=true&includeAttributes=true&includeLastSale=true`,
Expand All @@ -317,7 +311,11 @@ describe('NftController', () => {
},
],
});

const DEPRESSIONIST_CLOUDFLARE_IPFS_SUBDOMAIN_PATH = await getFormattedIpfsUrl(
IPFS_DEFAULT_GATEWAY_URL,
`ipfs://${DEPRESSIONIST_CID_V1}`,
true,
);
nock(DEPRESSIONIST_CLOUDFLARE_IPFS_SUBDOMAIN_PATH).get('/').reply(200, {
name: 'name',
image: 'image',
Expand Down
2 changes: 1 addition & 1 deletion packages/assets-controllers/src/NftController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ export class NftController extends BaseController<
}

if (hasIpfsTokenURI) {
tokenURI = getFormattedIpfsUrl(
tokenURI = await getFormattedIpfsUrl(
this.#ipfsGateway,
tokenURI,
this.#useIpfsSubdomains,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ import type {
NetworkClientId,
} from '@metamask/network-controller';
import { defaultState as defaultNetworkState } from '@metamask/network-controller';
import type { AutoManagedNetworkClient } from '@metamask/network-controller/src/create-auto-managed-network-client';
import type { CustomNetworkClientConfiguration } from '@metamask/network-controller/src/types';
import type { AutoManagedNetworkClient, CustomNetworkClientConfiguration } from '@metamask/network-controller';
import {
getDefaultPreferencesState,
type PreferencesState,
Expand Down
12 changes: 6 additions & 6 deletions packages/assets-controllers/src/assetsUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
import type { Hex } from '@metamask/utils';
import { remove0x } from '@metamask/utils';
import BN from 'bn.js';
import { CID } from 'multiformats';

import type { Nft, NftMetadata } from './NftController';
import type { AbstractTokenPricesService } from './token-prices-service';
Expand Down Expand Up @@ -217,10 +216,10 @@ export function removeIpfsProtocolPrefix(ipfsUrl: string) {
* @returns IFPS content identifier (cid) and sub path as string.
* @throws Will throw if the url passed is not ipfs.
*/
export function getIpfsCIDv1AndPath(ipfsUrl: string): {
export async function getIpfsCIDv1AndPath(ipfsUrl: string): Promise<{
cid: string;
path?: string;
} {
}> {
const url = removeIpfsProtocolPrefix(ipfsUrl);

// check if there is a path
Expand All @@ -229,6 +228,7 @@ export function getIpfsCIDv1AndPath(ipfsUrl: string): {
const cid = index !== -1 ? url.substring(0, index) : url;
const path = index !== -1 ? url.substring(index) : undefined;

const { CID } = await import('multiformats/cid');
// We want to ensure that the CID is v1 (https://docs.ipfs.io/concepts/content-addressing/#identifier-formats)
// because most cid v0s appear to be incompatible with IPFS subdomains
return {
Expand All @@ -245,14 +245,14 @@ export function getIpfsCIDv1AndPath(ipfsUrl: string): {
* @param subdomainSupported - Boolean indicating whether the URL should be formatted with subdomains or not.
* @returns A formatted URL, with the user's preferred IPFS gateway and format (subdomain or not), pointing to an asset hosted on IPFS.
*/
export function getFormattedIpfsUrl(
export async function getFormattedIpfsUrl(
ipfsGateway: string,
ipfsUrl: string,
subdomainSupported: boolean,
): string {
): Promise<string> {
const { host, protocol, origin } = new URL(addUrlProtocolPrefix(ipfsGateway));
if (subdomainSupported) {
const { cid, path } = getIpfsCIDv1AndPath(ipfsUrl);
const { cid, path } = await getIpfsCIDv1AndPath(ipfsUrl);
return `${protocol}//${cid}.ipfs.${host}${path ?? ''}`;
}
const cidAndPath = removeIpfsProtocolPrefix(ipfsUrl);
Expand Down
3 changes: 2 additions & 1 deletion packages/network-controller/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export type { AutoManagedNetworkClient } from './create-auto-managed-network-client';
export * from './NetworkController';
export * from './constants';
export type { BlockTracker, Provider } from './types';
export type { NetworkClientConfiguration } from './types';
export type { NetworkClientConfiguration, InfuraNetworkClientConfiguration, CustomNetworkClientConfiguration } from './types';
export { NetworkClientType } from './types';
export type { NetworkClient } from './create-network-client';
2 changes: 1 addition & 1 deletion packages/user-operation-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@
"@metamask/network-controller": "^19.0.0",
"@metamask/polling-controller": "^8.0.0",
"@metamask/rpc-errors": "^6.2.1",
"@metamask/superstruct": "^3.1.0",
"@metamask/transaction-controller": "^33.0.1",
"@metamask/utils": "^8.3.0",
"bn.js": "^5.2.1",
"immer": "^9.0.6",
"lodash": "^4.17.21",
"superstruct": "^1.0.3",
"uuid": "^8.3.2"
},
"devDependencies": {
Expand Down
8 changes: 4 additions & 4 deletions packages/user-operation-controller/src/utils/validation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { TransactionType } from '@metamask/transaction-controller';
import { isStrictHexString } from '@metamask/utils';
import type { Struct, StructError } from 'superstruct';
import type { Struct, StructError } from '@metamask/superstruct';
import {
assert,
boolean,
Expand All @@ -12,7 +10,9 @@ import {
optional,
refine,
string,
} from 'superstruct';
} from '@metamask/superstruct';
import { TransactionType } from '@metamask/transaction-controller';
import { isStrictHexString } from '@metamask/utils';

import { EMPTY_BYTES } from '../constants';
import type {
Expand Down
Loading