From 0a2d464cad2c90115147779c64c30f7f963c657a Mon Sep 17 00:00:00 2001 From: Dimitris Marlagkoutsos Date: Tue, 14 Apr 2026 17:02:11 +0200 Subject: [PATCH 1/3] feat: Export endowment factories via sub-path Add `@metamask/snaps-execution-environments/endowments` sub-path export that exposes generic endowment factory modules (timeout, interval, date, textEncoder, textDecoder, crypto, math) for reuse in other SES-based projects like ocap-kernel. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../snaps-execution-environments/CHANGELOG.md | 5 ++++ .../snaps-execution-environments/package.json | 10 +++++++ .../src/endowments.ts | 29 +++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 packages/snaps-execution-environments/src/endowments.ts diff --git a/packages/snaps-execution-environments/CHANGELOG.md b/packages/snaps-execution-environments/CHANGELOG.md index 8e9ebbffe5..3ef46a8e85 100644 --- a/packages/snaps-execution-environments/CHANGELOG.md +++ b/packages/snaps-execution-environments/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- Export endowment factories via `@metamask/snaps-execution-environments/endowments` sub-path ([#XXXX](https://github.com/MetaMask/snaps/pull/XXXX)) + - Exports endowment factory modules: `timeout`, `interval`, `date`, `textEncoder`, `textDecoder`, `crypto`, `math` + ## [11.0.2] ### Changed diff --git a/packages/snaps-execution-environments/package.json b/packages/snaps-execution-environments/package.json index 5d9624f09b..948b05fe83 100644 --- a/packages/snaps-execution-environments/package.json +++ b/packages/snaps-execution-environments/package.json @@ -28,6 +28,16 @@ "default": "./dist/index.cjs" } }, + "./endowments": { + "import": { + "types": "./dist/endowments.d.mts", + "default": "./dist/endowments.mjs" + }, + "require": { + "types": "./dist/endowments.d.cts", + "default": "./dist/endowments.cjs" + } + }, "./node-process": "./dist/webpack/node-process/bundle.js", "./node-thread": "./dist/webpack/node-thread/bundle.js", "./package.json": "./package.json" diff --git a/packages/snaps-execution-environments/src/endowments.ts b/packages/snaps-execution-environments/src/endowments.ts new file mode 100644 index 0000000000..aa74ef0928 --- /dev/null +++ b/packages/snaps-execution-environments/src/endowments.ts @@ -0,0 +1,29 @@ +/** + * Public endowment factory exports for use outside the Snaps ecosystem. + * + * Each module provides a `names` array and a `factory` function. Call + * `factory()` to obtain hardened endowment values (and an optional + * `teardownFunction` for timer-based endowments). + * + * @example + * ```ts + * import { timeout, date } from '@metamask/snaps-execution-environments/endowments'; + * + * const timers = timeout.factory(); + * // { setTimeout, clearTimeout, teardownFunction } + * + * const dateEndowment = date.factory(); + * // { Date } (with noise-added Date.now) + * ``` + * + * @module endowments + */ + +// Individual endowment factory modules +export { default as timeout } from './common/endowments/timeout'; +export { default as interval } from './common/endowments/interval'; +export { default as date } from './common/endowments/date'; +export { default as textEncoder } from './common/endowments/textEncoder'; +export { default as textDecoder } from './common/endowments/textDecoder'; +export { default as crypto } from './common/endowments/crypto'; +export { default as math } from './common/endowments/math'; From 28e1e991b788340c0c08058021203ef65f9e63f2 Mon Sep 17 00:00:00 2001 From: Dimitris Marlagkoutsos Date: Tue, 14 Apr 2026 17:02:42 +0200 Subject: [PATCH 2/3] chore: Update changelog PR number to #3957 Co-Authored-By: Claude Opus 4.6 (1M context) --- packages/snaps-execution-environments/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/snaps-execution-environments/CHANGELOG.md b/packages/snaps-execution-environments/CHANGELOG.md index 3ef46a8e85..1bb5612594 100644 --- a/packages/snaps-execution-environments/CHANGELOG.md +++ b/packages/snaps-execution-environments/CHANGELOG.md @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- Export endowment factories via `@metamask/snaps-execution-environments/endowments` sub-path ([#XXXX](https://github.com/MetaMask/snaps/pull/XXXX)) +- Export endowment factories via `@metamask/snaps-execution-environments/endowments` sub-path ([#3957](https://github.com/MetaMask/snaps/pull/3957)) - Exports endowment factory modules: `timeout`, `interval`, `date`, `textEncoder`, `textDecoder`, `crypto`, `math` ## [11.0.2] From bf365e79d14993f1c63e16df8ea123830ee9ea50 Mon Sep 17 00:00:00 2001 From: Dimitris Marlagkoutsos Date: Tue, 14 Apr 2026 18:40:22 +0200 Subject: [PATCH 3/3] fix: Exclude endowments barrel from coverage The endowments.ts barrel file is a pure re-export module with no logic to test, matching the existing exclusion pattern for index.ts. Co-Authored-By: Claude Opus 4.6 (1M context) --- packages/snaps-execution-environments/jest.config.js | 1 + packages/snaps-execution-environments/vitest.config.mts | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/snaps-execution-environments/jest.config.js b/packages/snaps-execution-environments/jest.config.js index 3680265193..9a0b30256f 100644 --- a/packages/snaps-execution-environments/jest.config.js +++ b/packages/snaps-execution-environments/jest.config.js @@ -10,6 +10,7 @@ module.exports = deepmerge(baseConfig, { coverageReporters: ['html', 'json-summary', 'json'], coveragePathIgnorePatterns: [ './src/index.ts', + './src/endowments.ts', './src/iframe/index.ts', './src/offscreen/index.ts', './src/webworker/executor/index.ts', diff --git a/packages/snaps-execution-environments/vitest.config.mts b/packages/snaps-execution-environments/vitest.config.mts index e33858818a..9af51d76c4 100644 --- a/packages/snaps-execution-environments/vitest.config.mts +++ b/packages/snaps-execution-environments/vitest.config.mts @@ -114,6 +114,7 @@ export default defineConfig({ // The files to exclude from the coverage report. exclude: [ 'src/**/index.ts', + 'src/endowments.ts', 'src/**/*.d.ts', 'src/**/*.test.ts', 'src/**/test-utils/**',