You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Replaces raw vat-global endowments with attenuated factories from
`@metamask/snaps-execution-environments/endowments`:
- Adds `setInterval`, `clearInterval`, `crypto`, `SubtleCrypto`, and
`Math` (with `crypto.getRandomValues`-sourced `Math.random`) to the
default allowlist.
- Replaces the raw `setTimeout`/`clearTimeout` and `Date` with the
monotonic, attenuated Snaps factories.
- Wires each factory's `teardownFunction` into `VatSupervisor.terminate`
via an aggregate teardown built on `Promise.allSettled`, so pending
timers and open resources are released even if one teardown rejects.
- Replaces the `DEFAULT_ALLOWED_GLOBALS` constant + `allowedGlobals`
constructor parameter with `createDefaultEndowments()` factory and
`makeAllowedGlobals` parameter; the factory is invoked once per
supervisor so state is isolated per vat.
NOTE: this change depends on the `/endowments` subpath export landing
in `@metamask/snaps-execution-environments` (MetaMask/snaps#3957).
The PR stays in draft until that is released; the `^11.1.0` version
pin is a placeholder and will be updated when the release ships.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: packages/kernel-test/src/vats/endowment-globals.ts
+32Lines changed: 32 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -62,13 +62,45 @@ export function buildRootObject(vatPowers: TestPowers) {
62
62
});
63
63
},
64
64
65
+
testInterval: async()=>{
66
+
returnnewPromise((resolve)=>{
67
+
lettickCount=0;
68
+
consthandle=setInterval(()=>{
69
+
tickCount+=1;
70
+
if(tickCount>=2){
71
+
clearInterval(handle);
72
+
tlog(`interval: ticks=${tickCount}`);
73
+
resolve(tickCount);
74
+
}
75
+
},10);
76
+
});
77
+
},
78
+
65
79
testDate: ()=>{
66
80
constnow=Date.now();
67
81
constisReal=!Number.isNaN(now)&&now>0;
68
82
tlog(`date: isReal=${String(isReal)}`);
69
83
returnisReal;
70
84
},
71
85
86
+
testCrypto: ()=>{
87
+
// A 16-byte buffer makes the all-zero coincidence vanishingly small
88
+
// (2^-128); a 4-byte buffer has a ~1-in-4-billion false-negative rate.
89
+
constbuffer=newUint8Array(16);
90
+
// eslint-disable-next-line n/no-unsupported-features/node-builtins -- `crypto` here is the vat endowment, not the Node global; the rule's engines check does not apply inside a SES Compartment.
Copy file name to clipboardExpand all lines: packages/ocap-kernel/CHANGELOG.md
+5Lines changed: 5 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
9
9
10
10
### Added
11
11
12
+
- Integrate Snaps attenuated endowment factories into vat globals ([#935](https://github.com/MetaMask/ocap-kernel/pull/935))
13
+
- Add `setInterval`, `clearInterval`, `crypto`, `SubtleCrypto`, and `Math` (crypto-backed `Math.random`) to the default vat endowments
14
+
- Swap raw `setTimeout`/`clearTimeout` and `Date` for attenuated versions from `@metamask/snaps-execution-environments`
15
+
- Wire factory `teardownFunction`s into `VatSupervisor.terminate()` so pending timers and other resources are released on vat termination
16
+
- Replace exported `DEFAULT_ALLOWED_GLOBALS` constant with `createDefaultEndowments()` factory and `VatEndowments` type; `VatSupervisor` now accepts `makeAllowedGlobals` in place of `allowedGlobals`
12
17
- Make vat global allowlist configurable and expand available endowments ([#933](https://github.com/MetaMask/ocap-kernel/pull/933))
13
18
- Export `DEFAULT_ALLOWED_GLOBALS` with `URL`, `URLSearchParams`, `atob`, `btoa`, `AbortController`, and `AbortSignal` in addition to the existing globals
14
19
- Accept optional `allowedGlobals` on `VatSupervisor` for custom allowlists
Copy file name to clipboardExpand all lines: packages/ocap-kernel/src/Kernel.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -232,7 +232,7 @@ export class Kernel {
232
232
* @param options.mnemonic - Optional BIP39 mnemonic for deriving the kernel identity.
233
233
* @param options.ioChannelFactory - Optional factory for creating IO channels.
234
234
* @param options.systemSubclusters - Optional array of system subcluster configurations.
235
-
* @param options.allowedGlobalNames - Optional list of allowed global names for vat endowments. When set, only these names from DEFAULT_ALLOWED_GLOBALS are available to vats.
235
+
* @param options.allowedGlobalNames - Optional list of allowed global names for vat endowments. When set, only these names from the `VatSupervisor`'s configured endowments (see `createDefaultEndowments`) are available to vats.
0 commit comments