Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions packages/snaps-execution-environments/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ([#3957](https://github.com/MetaMask/snaps/pull/3957))
- Exports endowment factory modules: `timeout`, `interval`, `date`, `textEncoder`, `textDecoder`, `crypto`, `math`

## [11.0.2]

### Changed
Expand Down
1 change: 1 addition & 0 deletions packages/snaps-execution-environments/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
10 changes: 10 additions & 0 deletions packages/snaps-execution-environments/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
29 changes: 29 additions & 0 deletions packages/snaps-execution-environments/src/endowments.ts
Original file line number Diff line number Diff line change
@@ -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';
1 change: 1 addition & 0 deletions packages/snaps-execution-environments/vitest.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -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/**',
Expand Down
Loading