@metamask/snaps-utils 9.2.0 → 9.2.1
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 +9 -1
- package/dist/eval-worker.cjs +2 -3
- package/dist/eval-worker.cjs.map +1 -1
- package/dist/eval-worker.mjs +2 -3
- package/dist/eval-worker.mjs.map +1 -1
- package/dist/index.executionenv.cjs +1 -0
- package/dist/index.executionenv.cjs.map +1 -1
- package/dist/index.executionenv.d.cts +1 -0
- package/dist/index.executionenv.d.cts.map +1 -1
- package/dist/index.executionenv.d.mts +1 -0
- package/dist/index.executionenv.d.mts.map +1 -1
- package/dist/index.executionenv.mjs +1 -0
- package/dist/index.executionenv.mjs.map +1 -1
- package/dist/json-rpc.cjs.map +1 -1
- package/dist/json-rpc.d.cts +2 -2
- package/dist/json-rpc.d.cts.map +1 -1
- package/dist/json-rpc.d.mts +2 -2
- package/dist/json-rpc.d.mts.map +1 -1
- package/dist/json-rpc.mjs.map +1 -1
- package/dist/json.cjs +5 -1
- package/dist/json.cjs.map +1 -1
- package/dist/json.d.cts +3 -0
- package/dist/json.d.cts.map +1 -1
- package/dist/json.d.mts +3 -0
- package/dist/json.d.mts.map +1 -1
- package/dist/json.mjs +5 -1
- package/dist/json.mjs.map +1 -1
- package/package.json +9 -8
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [9.2.1]
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
- Reduce unnecessary validation on responses ([#3350](https://github.com/MetaMask/snaps/pull/3350))
|
|
15
|
+
- Speed up JSON size calculation ([#3348](https://github.com/MetaMask/snaps/pull/3348))
|
|
16
|
+
|
|
10
17
|
## [9.2.0]
|
|
11
18
|
|
|
12
19
|
### Added
|
|
@@ -590,7 +597,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
590
597
|
- The version of the package no longer needs to match the version of all other
|
|
591
598
|
MetaMask Snaps packages.
|
|
592
599
|
|
|
593
|
-
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@9.2.
|
|
600
|
+
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@9.2.1...HEAD
|
|
601
|
+
[9.2.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@9.2.0...@metamask/snaps-utils@9.2.1
|
|
594
602
|
[9.2.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@9.1.0...@metamask/snaps-utils@9.2.0
|
|
595
603
|
[9.1.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@9.0.1...@metamask/snaps-utils@9.1.0
|
|
596
604
|
[9.0.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@9.0.0...@metamask/snaps-utils@9.0.1
|
package/dist/eval-worker.cjs
CHANGED
|
@@ -9,11 +9,10 @@ const fs_1 = require("fs");
|
|
|
9
9
|
const handlers_1 = require("./handlers/index.cjs");
|
|
10
10
|
const mock_1 = require("./mock.cjs");
|
|
11
11
|
lockdown({
|
|
12
|
-
consoleTaming: 'unsafe',
|
|
13
12
|
errorTaming: 'unsafe',
|
|
14
|
-
|
|
15
|
-
dateTaming: 'unsafe',
|
|
13
|
+
stackFiltering: 'verbose',
|
|
16
14
|
overrideTaming: 'severe',
|
|
15
|
+
localeTaming: 'unsafe',
|
|
17
16
|
// We disable domain taming, because it does not work in certain cases when
|
|
18
17
|
// running tests. This is unlikely to be a problem in production, because
|
|
19
18
|
// Node.js domains are deprecated.
|
package/dist/eval-worker.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eval-worker.cjs","sourceRoot":"","sources":["../src/eval-worker.ts"],"names":[],"mappings":";;AAAA,6DAA6D;AAC7D,4EAA4E;AAC5E,6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CAAC,4BAAiB,CAAC,QAAQ,CAAC,UAAyB,CAAC,CACvE,CAAC;AAEF,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;IAC9B,sCAAsC;IACtC,OAAO,CAAC,IAAI,CAAC,mCAAmC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC/E,CAAC;AAED,0DAA0D;AAC1D,0EAA0E;AAC1E,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC","sourcesContent":["// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore - TypeScript complains about this being ESM in a CJS file, but\n// `ses/lockdown` has a CommonJS entry point.\n// eslint-disable-next-line import-x/no-unassigned-import\nimport 'ses/lockdown';\n\nimport { readFileSync } from 'fs';\n\nimport type { HandlerType } from './handlers';\nimport { SNAP_EXPORT_NAMES } from './handlers';\nimport { generateMockEndowments } from './mock';\n\ndeclare let lockdown: any, Compartment: any;\n\nlockdown({\n errorTaming: 'unsafe',\n stackFiltering: 'verbose',\n overrideTaming: 'severe',\n localeTaming: 'unsafe',\n\n // We disable domain taming, because it does not work in certain cases when\n // running tests. This is unlikely to be a problem in production, because\n // Node.js domains are deprecated.\n domainTaming: 'unsafe',\n});\n\nconst snapFilePath = process.argv[2];\n\nconst snapModule: { exports?: any } = { exports: {} };\n\nconst compartment = new Compartment({\n ...generateMockEndowments(),\n module: snapModule,\n exports: snapModule.exports,\n});\n\n// Mirror BaseSnapExecutor\ncompartment.globalThis.self = compartment.globalThis;\ncompartment.globalThis.global = compartment.globalThis;\ncompartment.globalThis.window = compartment.globalThis;\n\ncompartment.evaluate(readFileSync(snapFilePath, 'utf8'));\n\nconst invalidExports = Object.keys(snapModule.exports).filter(\n (snapExport) => !SNAP_EXPORT_NAMES.includes(snapExport as HandlerType),\n);\n\nif (invalidExports.length > 0) {\n // eslint-disable-next-line no-console\n console.warn(`Invalid snap exports detected:\\n${invalidExports.join('\\n')}`);\n}\n\n// To ensure the worker exits we explicitly call exit here\n// If we didn't the eval would wait for timers set during Compartment eval\nprocess.exit(0);\n"]}
|
package/dist/eval-worker.mjs
CHANGED
|
@@ -7,11 +7,10 @@ import { readFileSync } from "fs";
|
|
|
7
7
|
import { SNAP_EXPORT_NAMES } from "./handlers/index.mjs";
|
|
8
8
|
import { generateMockEndowments } from "./mock.mjs";
|
|
9
9
|
lockdown({
|
|
10
|
-
consoleTaming: 'unsafe',
|
|
11
10
|
errorTaming: 'unsafe',
|
|
12
|
-
|
|
13
|
-
dateTaming: 'unsafe',
|
|
11
|
+
stackFiltering: 'verbose',
|
|
14
12
|
overrideTaming: 'severe',
|
|
13
|
+
localeTaming: 'unsafe',
|
|
15
14
|
// We disable domain taming, because it does not work in certain cases when
|
|
16
15
|
// running tests. This is unlikely to be a problem in production, because
|
|
17
16
|
// Node.js domains are deprecated.
|
package/dist/eval-worker.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eval-worker.mjs","sourceRoot":"","sources":["../src/eval-worker.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,4EAA4E;AAC5E,6CAA6C;AAC7C,yDAAyD;AACzD,sBAAsB;AAEtB,OAAO,EAAE,YAAY,EAAE,WAAW;AAGlC,OAAO,EAAE,iBAAiB,EAAE,6BAAmB;AAC/C,OAAO,EAAE,sBAAsB,EAAE,mBAAe;AAIhD,QAAQ,CAAC;IACP,
|
|
1
|
+
{"version":3,"file":"eval-worker.mjs","sourceRoot":"","sources":["../src/eval-worker.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,4EAA4E;AAC5E,6CAA6C;AAC7C,yDAAyD;AACzD,sBAAsB;AAEtB,OAAO,EAAE,YAAY,EAAE,WAAW;AAGlC,OAAO,EAAE,iBAAiB,EAAE,6BAAmB;AAC/C,OAAO,EAAE,sBAAsB,EAAE,mBAAe;AAIhD,QAAQ,CAAC;IACP,WAAW,EAAE,QAAQ;IACrB,cAAc,EAAE,SAAS;I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`ses/lockdown` has a CommonJS entry point.\n// eslint-disable-next-line import-x/no-unassigned-import\nimport 'ses/lockdown';\n\nimport { readFileSync } from 'fs';\n\nimport type { HandlerType } from './handlers';\nimport { SNAP_EXPORT_NAMES } from './handlers';\nimport { generateMockEndowments } from './mock';\n\ndeclare let lockdown: any, Compartment: any;\n\nlockdown({\n errorTaming: 'unsafe',\n stackFiltering: 'verbose',\n overrideTaming: 'severe',\n localeTaming: 'unsafe',\n\n // We disable domain taming, because it does not work in certain cases when\n // running tests. This is unlikely to be a problem in production, because\n // Node.js domains are deprecated.\n domainTaming: 'unsafe',\n});\n\nconst snapFilePath = process.argv[2];\n\nconst snapModule: { exports?: any } = { exports: {} };\n\nconst compartment = new Compartment({\n ...generateMockEndowments(),\n module: snapModule,\n exports: snapModule.exports,\n});\n\n// Mirror BaseSnapExecutor\ncompartment.globalThis.self = compartment.globalThis;\ncompartment.globalThis.global = compartment.globalThis;\ncompartment.globalThis.window = compartment.globalThis;\n\ncompartment.evaluate(readFileSync(snapFilePath, 'utf8'));\n\nconst invalidExports = Object.keys(snapModule.exports).filter(\n (snapExport) => !SNAP_EXPORT_NAMES.includes(snapExport as HandlerType),\n);\n\nif (invalidExports.length > 0) {\n // eslint-disable-next-line no-console\n console.warn(`Invalid snap exports detected:\\n${invalidExports.join('\\n')}`);\n}\n\n// To ensure the worker exits we explicitly call exit here\n// If we didn't the eval would wait for timers set during Compartment eval\nprocess.exit(0);\n"]}
|
|
@@ -19,6 +19,7 @@ __exportStar(require("./errors.cjs"), exports);
|
|
|
19
19
|
__exportStar(require("./handlers/exports.cjs"), exports);
|
|
20
20
|
__exportStar(require("./handlers/types.cjs"), exports);
|
|
21
21
|
__exportStar(require("./iframe.cjs"), exports);
|
|
22
|
+
__exportStar(require("./json.cjs"), exports);
|
|
22
23
|
__exportStar(require("./logging.cjs"), exports);
|
|
23
24
|
__exportStar(require("./types.cjs"), exports);
|
|
24
25
|
//# sourceMappingURL=index.executionenv.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.executionenv.cjs","sourceRoot":"","sources":["../src/index.executionenv.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0EAA0E;AAC1E,+CAAyB;AACzB,yDAAmC;AACnC,uDAAiC;AACjC,+CAAyB;AACzB,gDAA0B;AAC1B,8CAAwB","sourcesContent":["// Special entrypoint for execution environments for bundle sizing reasons\nexport * from './errors';\nexport * from './handlers/exports';\nexport * from './handlers/types';\nexport * from './iframe';\nexport * from './logging';\nexport * from './types';\n"]}
|
|
1
|
+
{"version":3,"file":"index.executionenv.cjs","sourceRoot":"","sources":["../src/index.executionenv.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0EAA0E;AAC1E,+CAAyB;AACzB,yDAAmC;AACnC,uDAAiC;AACjC,+CAAyB;AACzB,6CAAuB;AACvB,gDAA0B;AAC1B,8CAAwB","sourcesContent":["// Special entrypoint for execution environments for bundle sizing reasons\nexport * from './errors';\nexport * from './handlers/exports';\nexport * from './handlers/types';\nexport * from './iframe';\nexport * from './json';\nexport * from './logging';\nexport * from './types';\n"]}
|
|
@@ -2,6 +2,7 @@ export * from "./errors.cjs";
|
|
|
2
2
|
export * from "./handlers/exports.cjs";
|
|
3
3
|
export * from "./handlers/types.cjs";
|
|
4
4
|
export * from "./iframe.cjs";
|
|
5
|
+
export * from "./json.cjs";
|
|
5
6
|
export * from "./logging.cjs";
|
|
6
7
|
export * from "./types.cjs";
|
|
7
8
|
//# sourceMappingURL=index.executionenv.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.executionenv.d.cts","sourceRoot":"","sources":["../src/index.executionenv.ts"],"names":[],"mappings":"AACA,6BAAyB;AACzB,uCAAmC;AACnC,qCAAiC;AACjC,6BAAyB;AACzB,8BAA0B;AAC1B,4BAAwB"}
|
|
1
|
+
{"version":3,"file":"index.executionenv.d.cts","sourceRoot":"","sources":["../src/index.executionenv.ts"],"names":[],"mappings":"AACA,6BAAyB;AACzB,uCAAmC;AACnC,qCAAiC;AACjC,6BAAyB;AACzB,2BAAuB;AACvB,8BAA0B;AAC1B,4BAAwB"}
|
|
@@ -2,6 +2,7 @@ export * from "./errors.mjs";
|
|
|
2
2
|
export * from "./handlers/exports.mjs";
|
|
3
3
|
export * from "./handlers/types.mjs";
|
|
4
4
|
export * from "./iframe.mjs";
|
|
5
|
+
export * from "./json.mjs";
|
|
5
6
|
export * from "./logging.mjs";
|
|
6
7
|
export * from "./types.mjs";
|
|
7
8
|
//# sourceMappingURL=index.executionenv.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.executionenv.d.mts","sourceRoot":"","sources":["../src/index.executionenv.ts"],"names":[],"mappings":"AACA,6BAAyB;AACzB,uCAAmC;AACnC,qCAAiC;AACjC,6BAAyB;AACzB,8BAA0B;AAC1B,4BAAwB"}
|
|
1
|
+
{"version":3,"file":"index.executionenv.d.mts","sourceRoot":"","sources":["../src/index.executionenv.ts"],"names":[],"mappings":"AACA,6BAAyB;AACzB,uCAAmC;AACnC,qCAAiC;AACjC,6BAAyB;AACzB,2BAAuB;AACvB,8BAA0B;AAC1B,4BAAwB"}
|
|
@@ -3,6 +3,7 @@ export * from "./errors.mjs";
|
|
|
3
3
|
export * from "./handlers/exports.mjs";
|
|
4
4
|
export * from "./handlers/types.mjs";
|
|
5
5
|
export * from "./iframe.mjs";
|
|
6
|
+
export * from "./json.mjs";
|
|
6
7
|
export * from "./logging.mjs";
|
|
7
8
|
export * from "./types.mjs";
|
|
8
9
|
//# sourceMappingURL=index.executionenv.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.executionenv.mjs","sourceRoot":"","sources":["../src/index.executionenv.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,6BAAyB;AACzB,uCAAmC;AACnC,qCAAiC;AACjC,6BAAyB;AACzB,8BAA0B;AAC1B,4BAAwB","sourcesContent":["// Special entrypoint for execution environments for bundle sizing reasons\nexport * from './errors';\nexport * from './handlers/exports';\nexport * from './handlers/types';\nexport * from './iframe';\nexport * from './logging';\nexport * from './types';\n"]}
|
|
1
|
+
{"version":3,"file":"index.executionenv.mjs","sourceRoot":"","sources":["../src/index.executionenv.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,6BAAyB;AACzB,uCAAmC;AACnC,qCAAiC;AACjC,6BAAyB;AACzB,2BAAuB;AACvB,8BAA0B;AAC1B,4BAAwB","sourcesContent":["// Special entrypoint for execution environments for bundle sizing reasons\nexport * from './errors';\nexport * from './handlers/exports';\nexport * from './handlers/types';\nexport * from './iframe';\nexport * from './json';\nexport * from './logging';\nexport * from './types';\n"]}
|
package/dist/json-rpc.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-rpc.cjs","sourceRoot":"","sources":["../src/json-rpc.ts"],"names":[],"mappings":";;;AAAA,2EAA8D;AAE9D,uDAO+B;
|
|
1
|
+
{"version":3,"file":"json-rpc.cjs","sourceRoot":"","sources":["../src/json-rpc.ts"],"names":[],"mappings":";;;AAAA,2EAA8D;AAE9D,uDAO+B;AAK/B,2CAIyB;AAEzB,MAAM,oBAAoB,GAAG,IAAA,mBAAK,EAChC,IAAA,oBAAM,EAAC,IAAA,oBAAM,GAAE,EAAE,gBAAgB,EAAE,CAAC,KAAK,EAAE,EAAE;IAC3C,MAAM,SAAS,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;IAC9C,IAAI,SAAS,GAAG,CAAC,EAAE,CAAC;QAClB,OAAO,sEAAsE,CAAC;IAChF,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC,CACH,CAAC;AAEW,QAAA,gBAAgB,GAAG,IAAA,oBAAM,EACpC,IAAA,oBAAM,EAAC;IACL,KAAK,EAAE,IAAA,sBAAQ,EAAC,IAAA,qBAAO,GAAE,CAAC;IAC1B,KAAK,EAA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,CAAC,CAAC;IAChD,CAAC;AACH,CAAC;AAVD,wDAUC","sourcesContent":["import { SubjectType } from '@metamask/permission-controller';\nimport type { Infer } from '@metamask/superstruct';\nimport {\n array,\n boolean,\n object,\n optional,\n refine,\n string,\n} from '@metamask/superstruct';\nimport type {\n AssertionErrorConstructor,\n JsonRpcSuccess,\n} from '@metamask/utils';\nimport {\n assertStruct,\n isJsonRpcFailure,\n isJsonRpcSuccess,\n} from '@metamask/utils';\n\nconst AllowedOriginsStruct = array(\n refine(string(), 'Allowed origin', (value) => {\n const wildcards = value.split('*').length - 1;\n if (wildcards > 2) {\n return 'No more than two wildcards (\"*\") are allowed in an origin specifier.';\n }\n\n return true;\n }),\n);\n\nexport const RpcOriginsStruct = refine(\n object({\n dapps: optional(boolean()),\n snaps: optional(boolean()),\n allowedOrigins: optional(AllowedOriginsStruct),\n }),\n 'RPC origins',\n (value) => {\n const hasOrigins = Boolean(\n value.snaps === true ||\n value.dapps === true ||\n (value.allowedOrigins && value.allowedOrigins.length > 0),\n );\n\n if (hasOrigins) {\n return true;\n }\n\n return 'Must specify at least one JSON-RPC origin.';\n },\n);\n\nexport type RpcOrigins = Infer<typeof RpcOriginsStruct>;\n\n/**\n * Asserts that the given value is a valid {@link RpcOrigins} object.\n *\n * @param value - The value to assert.\n * @param ErrorWrapper - An optional error wrapper to use. Defaults to\n * {@link AssertionError}.\n * @throws If the value is not a valid {@link RpcOrigins} object.\n */\nexport function assertIsRpcOrigins(\n value: unknown,\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is RpcOrigins {\n assertStruct(\n value,\n RpcOriginsStruct,\n 'Invalid JSON-RPC origins',\n ErrorWrapper,\n );\n}\n\nexport const KeyringOriginsStruct = object({\n allowedOrigins: optional(AllowedOriginsStruct),\n});\n\nexport type KeyringOrigins = Infer<typeof KeyringOriginsStruct>;\n\n/**\n * Assert that the given value is a valid {@link KeyringOrigins} object.\n *\n * @param value - The value to assert.\n * @param ErrorWrapper - An optional error wrapper to use. Defaults to\n * {@link AssertionError}.\n * @throws If the value is not a valid {@link KeyringOrigins} object.\n */\nexport function assertIsKeyringOrigins(\n value: unknown,\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is KeyringOrigins {\n assertStruct(\n value,\n KeyringOriginsStruct,\n 'Invalid keyring origins',\n ErrorWrapper,\n );\n}\n\n/**\n * Create regular expression for matching against an origin while allowing wildcards.\n *\n * The \"*\" symbol is treated as a wildcard and will match 0 or more characters.\n *\n * @param matcher - The string to create the regular expression with.\n * @returns The regular expression.\n */\nfunction createOriginRegExp(matcher: string) {\n // Escape potential Regex characters\n const escaped = matcher.replace(/[.*+?^${}()|[\\]\\\\]/gu, '\\\\$&');\n // Support wildcards\n const regex = escaped.replace(/\\\\\\*/gu, '.*');\n return RegExp(`^${regex}$`, 'u');\n}\n\n/**\n * Check whether an origin is allowed or not using a matcher string.\n *\n * The matcher string may be a specific origin to match or include wildcards.\n * The \"*\" symbol is treated as a wildcard and will match 0 or more characters.\n * Note: this means that https://*metamask.io matches both https://metamask.io\n * and https://snaps.metamask.io.\n *\n * @param matcher - The matcher string.\n * @param origin - The origin.\n * @returns Whether the origin is allowed.\n */\nfunction checkAllowedOrigin(matcher: string, origin: string) {\n // If the matcher is a single wildcard or identical to the origin we can return true immediately.\n if (matcher === '*' || matcher === origin) {\n return true;\n }\n\n const regex = createOriginRegExp(matcher);\n return regex.test(origin);\n}\n\n/**\n * Check if the given origin is allowed by the given JSON-RPC origins object.\n *\n * @param origins - The JSON-RPC origins object.\n * @param subjectType - The type of the origin.\n * @param origin - The origin to check.\n * @returns Whether the origin is allowed.\n */\nexport function isOriginAllowed(\n origins: RpcOrigins,\n subjectType: SubjectType,\n origin: string,\n) {\n // The MetaMask client is always allowed.\n if (origin === 'metamask') {\n return true;\n }\n\n // If the origin is in the `allowedOrigins` list, it is allowed.\n if (\n origins.allowedOrigins?.some((matcher) =>\n checkAllowedOrigin(matcher, origin),\n )\n ) {\n return true;\n }\n\n // If the origin is a website and `dapps` is true, it is allowed.\n if (subjectType === SubjectType.Website && origins.dapps) {\n return true;\n }\n\n // If the origin is a snap and `snaps` is true, it is allowed.\n return Boolean(subjectType === SubjectType.Snap && origins.snaps);\n}\n\n/**\n * Assert that the given value is a successful JSON-RPC response. If the value\n * is not a success response, an error is thrown. If the value is an JSON-RPC\n * error, the error message is included in the thrown error.\n *\n * @param value - The value to check.\n * @throws If the value is not a JSON-RPC success response.\n */\nexport function assertIsJsonRpcSuccess(\n value: unknown,\n): asserts value is JsonRpcSuccess {\n if (!isJsonRpcSuccess(value)) {\n if (isJsonRpcFailure(value)) {\n throw new Error(`JSON-RPC request failed: ${value.error.message}`);\n }\n\n throw new Error('Invalid JSON-RPC response.');\n }\n}\n"]}
|
package/dist/json-rpc.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SubjectType } from "@metamask/permission-controller";
|
|
2
2
|
import type { Infer } from "@metamask/superstruct";
|
|
3
|
-
import type { AssertionErrorConstructor,
|
|
3
|
+
import type { AssertionErrorConstructor, JsonRpcSuccess } from "@metamask/utils";
|
|
4
4
|
export declare const RpcOriginsStruct: import("@metamask/superstruct").Struct<{
|
|
5
5
|
snaps?: boolean | undefined;
|
|
6
6
|
dapps?: boolean | undefined;
|
|
@@ -52,5 +52,5 @@ export declare function isOriginAllowed(origins: RpcOrigins, subjectType: Subjec
|
|
|
52
52
|
* @param value - The value to check.
|
|
53
53
|
* @throws If the value is not a JSON-RPC success response.
|
|
54
54
|
*/
|
|
55
|
-
export declare function assertIsJsonRpcSuccess(value: unknown): asserts value is JsonRpcSuccess
|
|
55
|
+
export declare function assertIsJsonRpcSuccess(value: unknown): asserts value is JsonRpcSuccess;
|
|
56
56
|
//# sourceMappingURL=json-rpc.d.cts.map
|
package/dist/json-rpc.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-rpc.d.cts","sourceRoot":"","sources":["../src/json-rpc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,wCAAwC;AAC9D,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AASnD,OAAO,KAAK,EACV,yBAAyB,EACzB,
|
|
1
|
+
{"version":3,"file":"json-rpc.d.cts","sourceRoot":"","sources":["../src/json-rpc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,wCAAwC;AAC9D,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AASnD,OAAO,KAAK,EACV,yBAAyB,EACzB,cAAc,EACf,wBAAwB;AAkBzB,eAAO,MAAM,gBAAgB;;;;;;;;EAoB5B,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAExD;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,OAAO,EACd,YAAY,CAAC,EAAE,yBAAyB,GACvC,OAAO,CAAC,KAAK,IAAI,UAAU,CAO7B;AAED,eAAO,MAAM,oBAAoB;;;;EAE/B,CAAC;AAEH,MAAM,MAAM,cAAc,GAAG,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAEhE;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,OAAO,EACd,YAAY,CAAC,EAAE,yBAAyB,GACvC,OAAO,CAAC,KAAK,IAAI,cAAc,CAOjC;AAwCD;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,UAAU,EACnB,WAAW,EAAE,WAAW,EACxB,MAAM,EAAE,MAAM,WAuBf;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,OAAO,GACb,OAAO,CAAC,KAAK,IAAI,cAAc,CAQjC"}
|
package/dist/json-rpc.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SubjectType } from "@metamask/permission-controller";
|
|
2
2
|
import type { Infer } from "@metamask/superstruct";
|
|
3
|
-
import type { AssertionErrorConstructor,
|
|
3
|
+
import type { AssertionErrorConstructor, JsonRpcSuccess } from "@metamask/utils";
|
|
4
4
|
export declare const RpcOriginsStruct: import("@metamask/superstruct").Struct<{
|
|
5
5
|
snaps?: boolean | undefined;
|
|
6
6
|
dapps?: boolean | undefined;
|
|
@@ -52,5 +52,5 @@ export declare function isOriginAllowed(origins: RpcOrigins, subjectType: Subjec
|
|
|
52
52
|
* @param value - The value to check.
|
|
53
53
|
* @throws If the value is not a JSON-RPC success response.
|
|
54
54
|
*/
|
|
55
|
-
export declare function assertIsJsonRpcSuccess(value: unknown): asserts value is JsonRpcSuccess
|
|
55
|
+
export declare function assertIsJsonRpcSuccess(value: unknown): asserts value is JsonRpcSuccess;
|
|
56
56
|
//# sourceMappingURL=json-rpc.d.mts.map
|
package/dist/json-rpc.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-rpc.d.mts","sourceRoot":"","sources":["../src/json-rpc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,wCAAwC;AAC9D,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AASnD,OAAO,KAAK,EACV,yBAAyB,EACzB,
|
|
1
|
+
{"version":3,"file":"json-rpc.d.mts","sourceRoot":"","sources":["../src/json-rpc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,wCAAwC;AAC9D,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AASnD,OAAO,KAAK,EACV,yBAAyB,EACzB,cAAc,EACf,wBAAwB;AAkBzB,eAAO,MAAM,gBAAgB;;;;;;;;EAoB5B,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAExD;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,OAAO,EACd,YAAY,CAAC,EAAE,yBAAyB,GACvC,OAAO,CAAC,KAAK,IAAI,UAAU,CAO7B;AAED,eAAO,MAAM,oBAAoB;;;;EAE/B,CAAC;AAEH,MAAM,MAAM,cAAc,GAAG,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAEhE;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,OAAO,EACd,YAAY,CAAC,EAAE,yBAAyB,GACvC,OAAO,CAAC,KAAK,IAAI,cAAc,CAOjC;AAwCD;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,UAAU,EACnB,WAAW,EAAE,WAAW,EACxB,MAAM,EAAE,MAAM,WAuBf;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,OAAO,GACb,OAAO,CAAC,KAAK,IAAI,cAAc,CAQjC"}
|
package/dist/json-rpc.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-rpc.mjs","sourceRoot":"","sources":["../src/json-rpc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,wCAAwC;AAE9D,OAAO,EACL,KAAK,EACL,OAAO,EACP,MAAM,EACN,QAAQ,EACR,MAAM,EACN,MAAM,EACP,8BAA8B;
|
|
1
|
+
{"version":3,"file":"json-rpc.mjs","sourceRoot":"","sources":["../src/json-rpc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,wCAAwC;AAE9D,OAAO,EACL,KAAK,EACL,OAAO,EACP,MAAM,EACN,QAAQ,EACR,MAAM,EACN,MAAM,EACP,8BAA8B;AAK/B,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,EACjB,wBAAwB;AAEzB,MAAM,oBAAoB,GAAG,KAAK,CAChC,MAAM,CAAC,MAAM,EAAE,EAAE,gBAAgB,EAAE,CAAC,KAAK,EAAE,EAAE;IAC3C,MAAM,SAAS,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;IAC9C,IAAI,SAAS,GAAG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AAK,CAAC,EAAE,CAAC;YAC5B,MAAM,IAAI,KAAK,CAAC,4BAA4B,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QACrE,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;IAChD,CAAC;AACH,CAAC","sourcesContent":["import { SubjectType } from '@metamask/permission-controller';\nimport type { Infer } from '@metamask/superstruct';\nimport {\n array,\n boolean,\n object,\n optional,\n refine,\n string,\n} from '@metamask/superstruct';\nimport type {\n AssertionErrorConstructor,\n JsonRpcSuccess,\n} from '@metamask/utils';\nimport {\n assertStruct,\n isJsonRpcFailure,\n isJsonRpcSuccess,\n} from '@metamask/utils';\n\nconst AllowedOriginsStruct = array(\n refine(string(), 'Allowed origin', (value) => {\n const wildcards = value.split('*').length - 1;\n if (wildcards > 2) {\n return 'No more than two wildcards (\"*\") are allowed in an origin specifier.';\n }\n\n return true;\n }),\n);\n\nexport const RpcOriginsStruct = refine(\n object({\n dapps: optional(boolean()),\n snaps: optional(boolean()),\n allowedOrigins: optional(AllowedOriginsStruct),\n }),\n 'RPC origins',\n (value) => {\n const hasOrigins = Boolean(\n value.snaps === true ||\n value.dapps === true ||\n (value.allowedOrigins && value.allowedOrigins.length > 0),\n );\n\n if (hasOrigins) {\n return true;\n }\n\n return 'Must specify at least one JSON-RPC origin.';\n },\n);\n\nexport type RpcOrigins = Infer<typeof RpcOriginsStruct>;\n\n/**\n * Asserts that the given value is a valid {@link RpcOrigins} object.\n *\n * @param value - The value to assert.\n * @param ErrorWrapper - An optional error wrapper to use. Defaults to\n * {@link AssertionError}.\n * @throws If the value is not a valid {@link RpcOrigins} object.\n */\nexport function assertIsRpcOrigins(\n value: unknown,\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is RpcOrigins {\n assertStruct(\n value,\n RpcOriginsStruct,\n 'Invalid JSON-RPC origins',\n ErrorWrapper,\n );\n}\n\nexport const KeyringOriginsStruct = object({\n allowedOrigins: optional(AllowedOriginsStruct),\n});\n\nexport type KeyringOrigins = Infer<typeof KeyringOriginsStruct>;\n\n/**\n * Assert that the given value is a valid {@link KeyringOrigins} object.\n *\n * @param value - The value to assert.\n * @param ErrorWrapper - An optional error wrapper to use. Defaults to\n * {@link AssertionError}.\n * @throws If the value is not a valid {@link KeyringOrigins} object.\n */\nexport function assertIsKeyringOrigins(\n value: unknown,\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is KeyringOrigins {\n assertStruct(\n value,\n KeyringOriginsStruct,\n 'Invalid keyring origins',\n ErrorWrapper,\n );\n}\n\n/**\n * Create regular expression for matching against an origin while allowing wildcards.\n *\n * The \"*\" symbol is treated as a wildcard and will match 0 or more characters.\n *\n * @param matcher - The string to create the regular expression with.\n * @returns The regular expression.\n */\nfunction createOriginRegExp(matcher: string) {\n // Escape potential Regex characters\n const escaped = matcher.replace(/[.*+?^${}()|[\\]\\\\]/gu, '\\\\$&');\n // Support wildcards\n const regex = escaped.replace(/\\\\\\*/gu, '.*');\n return RegExp(`^${regex}$`, 'u');\n}\n\n/**\n * Check whether an origin is allowed or not using a matcher string.\n *\n * The matcher string may be a specific origin to match or include wildcards.\n * The \"*\" symbol is treated as a wildcard and will match 0 or more characters.\n * Note: this means that https://*metamask.io matches both https://metamask.io\n * and https://snaps.metamask.io.\n *\n * @param matcher - The matcher string.\n * @param origin - The origin.\n * @returns Whether the origin is allowed.\n */\nfunction checkAllowedOrigin(matcher: string, origin: string) {\n // If the matcher is a single wildcard or identical to the origin we can return true immediately.\n if (matcher === '*' || matcher === origin) {\n return true;\n }\n\n const regex = createOriginRegExp(matcher);\n return regex.test(origin);\n}\n\n/**\n * Check if the given origin is allowed by the given JSON-RPC origins object.\n *\n * @param origins - The JSON-RPC origins object.\n * @param subjectType - The type of the origin.\n * @param origin - The origin to check.\n * @returns Whether the origin is allowed.\n */\nexport function isOriginAllowed(\n origins: RpcOrigins,\n subjectType: SubjectType,\n origin: string,\n) {\n // The MetaMask client is always allowed.\n if (origin === 'metamask') {\n return true;\n }\n\n // If the origin is in the `allowedOrigins` list, it is allowed.\n if (\n origins.allowedOrigins?.some((matcher) =>\n checkAllowedOrigin(matcher, origin),\n )\n ) {\n return true;\n }\n\n // If the origin is a website and `dapps` is true, it is allowed.\n if (subjectType === SubjectType.Website && origins.dapps) {\n return true;\n }\n\n // If the origin is a snap and `snaps` is true, it is allowed.\n return Boolean(subjectType === SubjectType.Snap && origins.snaps);\n}\n\n/**\n * Assert that the given value is a successful JSON-RPC response. If the value\n * is not a success response, an error is thrown. If the value is an JSON-RPC\n * error, the error message is included in the thrown error.\n *\n * @param value - The value to check.\n * @throws If the value is not a JSON-RPC success response.\n */\nexport function assertIsJsonRpcSuccess(\n value: unknown,\n): asserts value is JsonRpcSuccess {\n if (!isJsonRpcSuccess(value)) {\n if (isJsonRpcFailure(value)) {\n throw new Error(`JSON-RPC request failed: ${value.error.message}`);\n }\n\n throw new Error('Invalid JSON-RPC response.');\n }\n}\n"]}
|
package/dist/json.cjs
CHANGED
|
@@ -23,12 +23,16 @@ exports.parseJson = parseJson;
|
|
|
23
23
|
*
|
|
24
24
|
* This may sometimes be preferred over `getJsonSize` for performance reasons.
|
|
25
25
|
*
|
|
26
|
+
* Note: This function does not encode the string to bytes, thus the input may
|
|
27
|
+
* be about 4x larger in practice. Use this function with caution.
|
|
28
|
+
*
|
|
26
29
|
* @param value - The JSON value to get the size of.
|
|
27
30
|
* @returns The size of the JSON value in bytes.
|
|
28
31
|
*/
|
|
29
32
|
function getJsonSizeUnsafe(value) {
|
|
30
33
|
const json = JSON.stringify(value);
|
|
31
|
-
|
|
34
|
+
// We intentionally don't use `TextEncoder` because of bad performance on React Native.
|
|
35
|
+
return json.length;
|
|
32
36
|
}
|
|
33
37
|
exports.getJsonSizeUnsafe = getJsonSizeUnsafe;
|
|
34
38
|
//# sourceMappingURL=json.cjs.map
|
package/dist/json.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json.cjs","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":";;;AACA,2CAA8C;AAE9C,yCAAyC;AAEzC;;;;;;;;;;GAUG;AACH,SAAgB,SAAS,CAA2B,IAAY;IAC9D,OAAO,IAAA,mBAAW,EAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;AAC7C,CAAC;AAFD,8BAEC;AAED
|
|
1
|
+
{"version":3,"file":"json.cjs","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":";;;AACA,2CAA8C;AAE9C,yCAAyC;AAEzC;;;;;;;;;;GAUG;AACH,SAAgB,SAAS,CAA2B,IAAY;IAC9D,OAAO,IAAA,mBAAW,EAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;AAC7C,CAAC;AAFD,8BAEC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,iBAAiB,CAAC,KAAW;IAC3C,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACnC,uFAAuF;IACvF,OAAO,IAAI,CAAC,MAAM,CAAC;AACrB,CAAC;AAJD,8CAIC","sourcesContent":["import type { Json } from '@metamask/utils';\nimport { getSafeJson } from '@metamask/utils';\n\n// TODO: Upstream this to @metamask/utils\n\n/**\n * Parse JSON safely.\n *\n * Does multiple kinds of validation and strips unwanted properties like\n * `__proto__` and `constructor`.\n *\n * @param json - A JSON string to be parsed.\n * @returns The parsed JSON object.\n * @template Type - The type of the JSON object. The type is not actually\n * checked, but it is used to infer the return type.\n */\nexport function parseJson<Type extends Json = Json>(json: string) {\n return getSafeJson<Type>(JSON.parse(json));\n}\n\n/**\n * Get the size of a JSON blob without validating that is valid JSON.\n *\n * This may sometimes be preferred over `getJsonSize` for performance reasons.\n *\n * Note: This function does not encode the string to bytes, thus the input may\n * be about 4x larger in practice. Use this function with caution.\n *\n * @param value - The JSON value to get the size of.\n * @returns The size of the JSON value in bytes.\n */\nexport function getJsonSizeUnsafe(value: Json): number {\n const json = JSON.stringify(value);\n // We intentionally don't use `TextEncoder` because of bad performance on React Native.\n return json.length;\n}\n"]}
|
package/dist/json.d.cts
CHANGED
|
@@ -16,6 +16,9 @@ export declare function parseJson<Type extends Json = Json>(json: string): Type;
|
|
|
16
16
|
*
|
|
17
17
|
* This may sometimes be preferred over `getJsonSize` for performance reasons.
|
|
18
18
|
*
|
|
19
|
+
* Note: This function does not encode the string to bytes, thus the input may
|
|
20
|
+
* be about 4x larger in practice. Use this function with caution.
|
|
21
|
+
*
|
|
19
22
|
* @param value - The JSON value to get the size of.
|
|
20
23
|
* @returns The size of the JSON value in bytes.
|
|
21
24
|
*/
|
package/dist/json.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json.d.cts","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAK5C;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,IAAI,SAAS,IAAI,GAAG,IAAI,EAAE,IAAI,EAAE,MAAM,QAE/D;AAED
|
|
1
|
+
{"version":3,"file":"json.d.cts","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAK5C;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,IAAI,SAAS,IAAI,GAAG,IAAI,EAAE,IAAI,EAAE,MAAM,QAE/D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,IAAI,GAAG,MAAM,CAIrD"}
|
package/dist/json.d.mts
CHANGED
|
@@ -16,6 +16,9 @@ export declare function parseJson<Type extends Json = Json>(json: string): Type;
|
|
|
16
16
|
*
|
|
17
17
|
* This may sometimes be preferred over `getJsonSize` for performance reasons.
|
|
18
18
|
*
|
|
19
|
+
* Note: This function does not encode the string to bytes, thus the input may
|
|
20
|
+
* be about 4x larger in practice. Use this function with caution.
|
|
21
|
+
*
|
|
19
22
|
* @param value - The JSON value to get the size of.
|
|
20
23
|
* @returns The size of the JSON value in bytes.
|
|
21
24
|
*/
|
package/dist/json.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json.d.mts","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAK5C;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,IAAI,SAAS,IAAI,GAAG,IAAI,EAAE,IAAI,EAAE,MAAM,QAE/D;AAED
|
|
1
|
+
{"version":3,"file":"json.d.mts","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAK5C;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,IAAI,SAAS,IAAI,GAAG,IAAI,EAAE,IAAI,EAAE,MAAM,QAE/D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,IAAI,GAAG,MAAM,CAIrD"}
|
package/dist/json.mjs
CHANGED
|
@@ -19,11 +19,15 @@ export function parseJson(json) {
|
|
|
19
19
|
*
|
|
20
20
|
* This may sometimes be preferred over `getJsonSize` for performance reasons.
|
|
21
21
|
*
|
|
22
|
+
* Note: This function does not encode the string to bytes, thus the input may
|
|
23
|
+
* be about 4x larger in practice. Use this function with caution.
|
|
24
|
+
*
|
|
22
25
|
* @param value - The JSON value to get the size of.
|
|
23
26
|
* @returns The size of the JSON value in bytes.
|
|
24
27
|
*/
|
|
25
28
|
export function getJsonSizeUnsafe(value) {
|
|
26
29
|
const json = JSON.stringify(value);
|
|
27
|
-
|
|
30
|
+
// We intentionally don't use `TextEncoder` because of bad performance on React Native.
|
|
31
|
+
return json.length;
|
|
28
32
|
}
|
|
29
33
|
//# sourceMappingURL=json.mjs.map
|
package/dist/json.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json.mjs","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,wBAAwB;AAE9C,yCAAyC;AAEzC;;;;;;;;;;GAUG;AACH,MAAM,UAAU,SAAS,CAA2B,IAAY;IAC9D,OAAO,WAAW,CAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;AAC7C,CAAC;AAED
|
|
1
|
+
{"version":3,"file":"json.mjs","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,wBAAwB;AAE9C,yCAAyC;AAEzC;;;;;;;;;;GAUG;AACH,MAAM,UAAU,SAAS,CAA2B,IAAY;IAC9D,OAAO,WAAW,CAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;AAC7C,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAW;IAC3C,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACnC,uFAAuF;IACvF,OAAO,IAAI,CAAC,MAAM,CAAC;AACrB,CAAC","sourcesContent":["import type { Json } from '@metamask/utils';\nimport { getSafeJson } from '@metamask/utils';\n\n// TODO: Upstream this to @metamask/utils\n\n/**\n * Parse JSON safely.\n *\n * Does multiple kinds of validation and strips unwanted properties like\n * `__proto__` and `constructor`.\n *\n * @param json - A JSON string to be parsed.\n * @returns The parsed JSON object.\n * @template Type - The type of the JSON object. The type is not actually\n * checked, but it is used to infer the return type.\n */\nexport function parseJson<Type extends Json = Json>(json: string) {\n return getSafeJson<Type>(JSON.parse(json));\n}\n\n/**\n * Get the size of a JSON blob without validating that is valid JSON.\n *\n * This may sometimes be preferred over `getJsonSize` for performance reasons.\n *\n * Note: This function does not encode the string to bytes, thus the input may\n * be about 4x larger in practice. Use this function with caution.\n *\n * @param value - The JSON value to get the size of.\n * @returns The size of the JSON value in bytes.\n */\nexport function getJsonSizeUnsafe(value: Json): number {\n const json = JSON.stringify(value);\n // We intentionally don't use `TextEncoder` because of bad performance on React Native.\n return json.length;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/snaps-utils",
|
|
3
|
-
"version": "9.2.
|
|
3
|
+
"version": "9.2.1",
|
|
4
4
|
"description": "A collection of utilities for MetaMask Snaps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -86,9 +86,9 @@
|
|
|
86
86
|
"@metamask/rpc-errors": "^7.0.2",
|
|
87
87
|
"@metamask/slip44": "^4.1.0",
|
|
88
88
|
"@metamask/snaps-registry": "^3.2.3",
|
|
89
|
-
"@metamask/snaps-sdk": "^6.22.
|
|
89
|
+
"@metamask/snaps-sdk": "^6.22.1",
|
|
90
90
|
"@metamask/superstruct": "^3.2.1",
|
|
91
|
-
"@metamask/utils": "^11.
|
|
91
|
+
"@metamask/utils": "^11.4.0",
|
|
92
92
|
"@noble/hashes": "^1.7.1",
|
|
93
93
|
"@scure/base": "^1.1.1",
|
|
94
94
|
"chalk": "^4.1.2",
|
|
@@ -100,7 +100,7 @@
|
|
|
100
100
|
"marked": "^12.0.1",
|
|
101
101
|
"rfdc": "^1.3.0",
|
|
102
102
|
"semver": "^7.5.4",
|
|
103
|
-
"ses": "^1.
|
|
103
|
+
"ses": "^1.12.0",
|
|
104
104
|
"validate-npm-package-name": "^5.0.0"
|
|
105
105
|
},
|
|
106
106
|
"devDependencies": {
|
|
@@ -109,14 +109,15 @@
|
|
|
109
109
|
"@metamask/post-message-stream": "^9.0.0",
|
|
110
110
|
"@swc/core": "1.3.78",
|
|
111
111
|
"@swc/jest": "^0.2.26",
|
|
112
|
+
"@testing-library/dom": "^10.4.0",
|
|
112
113
|
"@ts-bridge/cli": "^0.6.1",
|
|
113
114
|
"@types/jest": "^27.5.1",
|
|
114
115
|
"@types/luxon": "^3",
|
|
115
116
|
"@types/node": "18.14.2",
|
|
116
117
|
"@types/semver": "^7.5.0",
|
|
117
118
|
"@types/validate-npm-package-name": "^4.0.0",
|
|
118
|
-
"@vitest/browser": "^3.
|
|
119
|
-
"@vitest/coverage-istanbul": "3.
|
|
119
|
+
"@vitest/browser": "^3.1.1",
|
|
120
|
+
"@vitest/coverage-istanbul": "3.1.1",
|
|
120
121
|
"deepmerge": "^4.2.2",
|
|
121
122
|
"depcheck": "^1.4.7",
|
|
122
123
|
"eslint": "^9.11.0",
|
|
@@ -130,10 +131,10 @@
|
|
|
130
131
|
"rimraf": "^4.1.2",
|
|
131
132
|
"ts-node": "^10.9.1",
|
|
132
133
|
"typescript": "~5.3.3",
|
|
133
|
-
"vite": "^6.2.
|
|
134
|
+
"vite": "^6.2.6",
|
|
134
135
|
"vite-plugin-node-polyfills": "^0.23.0",
|
|
135
136
|
"vite-tsconfig-paths": "^4.0.5",
|
|
136
|
-
"vitest": "^3.
|
|
137
|
+
"vitest": "^3.1.1"
|
|
137
138
|
},
|
|
138
139
|
"engines": {
|
|
139
140
|
"node": "^18.16 || >=20"
|