How to use the ses.makeSESRootRealm function in ses

To help you get started, we’ve selected a few ses examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github agoric-labs / PlaygroundVat / test / test-vat.js View on Github external
test('confineVatSource', t => {
  const s = SES.makeSESRootRealm({ consoleMode: 'allow' });
  const s1code = funcToSource(s1);
  // console.log(`source: ${s1code}`);
  const req = s.makeRequire({ '@agoric/nat': Nat, '@agoric/harden': true });
  const e = confineVatSource(s, req, `${s1code}`).default();
  t.equal(e.increment(), 1);
  t.equal(e.increment(), 2);
  t.equal(e.decrement(), 1);
  t.end();
});
github agoric-labs / PlaygroundVat / test / test-marshal.js View on Github external
test('marshal', async t => {
  const s = SES.makeSESRootRealm({
    consoleMode: 'allow',
    errorStackMode: 'allow',
  });
  const code = await bundleCode(require.resolve('../src/vat/webkey'));
  const req = s.makeRequire({ '@agoric/nat': Nat, '@agoric/harden': true });
  const e = confineVatSource(s, req, code);
  const endowments = makeVatEndowments(s, req, null, null);
  /* eslint-disable-next-line no-unused-vars */
  const { hash58: hash58Endowed } = endowments;

  function helpers() {
    /* eslint-disable-next-line global-require, import/no-unresolved */
    const harden = require('@agoric/harden');
    function serializer(x) {
      console.log(x);
    }
github agoric-labs / PlaygroundVat / test / test-endowments.js View on Github external
test('hash58', t => {
  const s = SES.makeSESRootRealm({
    consoleMode: 'allow',
    errorStackMode: 'allow',
  });
  const req = s.makeRequire({ '@agoric/nat': Nat, '@agoric/harden': true });
  const e = makeVatEndowments(s, req, null, null);
  // test vectors from python and electrum/lib/address.py Base58 class
  // Base58.encode(hashlib.sha256(s).digest()[:16])
  t.equal(e.hash58(''), 'V7jseQevszwMPhi4evidTR');
  t.equal(e.hash58(''), 'V7jseQevszwMPhi4evidTR'); // stable
  t.equal(e.hash58('a'), 'S1yrYnjHbfbiTySsN9h1eC');
  let xyz100 = '';
  for (let i = 0; i < 100; i += 1) {
    xyz100 += 'xyz';
  }
  t.equal(e.hash58(xyz100), 'LkLiePjfKWZzhQgmcEPT8j');
  t.end();
github MetaMask / snaps-cli / src / commands.js View on Github external
async function snapEval (argv) {
  const { bundle } = argv
  await validateFilePath(bundle)
  try {
    const s = SES.makeSESRootRealm({consoleMode: 'allow', errorStackMode: 'allow', mathRandomMode: 'allow'})
    const result = s.evaluate(fs.readFileSync(bundle), {
      // TODO: mock wallet properly
      wallet: { registerRpcMessageHandler: () => true },
      console
    })
    if (!result) {
      throw new Error(`SES.evaluate returned falsy value.`)
    }
    console.log(`Eval Success: evaluated '${bundle}' in SES!`)
  } catch (err) {
    logError(`Snap evaluation error: ${err.message}`, err)
    process.exit(1)
  }
  return true
}
github agoric-labs / PlaygroundVat / src / main.js View on Github external
export function makeRealm() {
  const mode = { consoleMode: 'allow' };
  // mode.errorStackMode = 'allow'; // debug only
  const s = SES.makeSESRootRealm(mode);
  return s;
}
github nomic-io / modbox / src / vm.js View on Github external
function createModule (code, opts = {}) {
  // TODO: ensure args are valid

  // TODO: find good default
  opts.memoryLimit = opts.memoryLimit || 10e6

  let memoryMeter = new MemoryMeter()
  let realm = makeSESRootRealm({
    consoleMode: opts.allowConsole ? 'allow' : false
  })

  // run prelude code inside realm
  let {
    module,
    functionConstructors,
    iteratedMethods,
    RegExp,
    stringRepeat
  } = realm.evaluate(prelude)

  let aborting = false
  let burnHandler = (value) => {
    // throw if a previous burn handler already errored
    // TODO: find better way to abort?
github jimpick / cabal-ses-bot / ses-bot.js View on Github external
import PQueue from 'p-queue'
import mkdirp from 'mkdirp'
import makeRootBotEndowments from './root-bot-mixin'
import makeUtilsEndowments from './mixins/utils'

const readdir = util.promisify(fs.readdir)
const readFile = util.promisify(fs.readFile)
const writeFile = util.promisify(fs.writeFile)

class SesBot extends EventEmitter {}

const sesBot = new SesBot()

const debugLog = debug('ses-bot')

const r = SES.makeSESRootRealm()

function buildBotKernelSrc () {
  let def, log, debugLog

  function kernel () {
    let messageCounter = 0
    let processes = []
    let state = []
    let refs = []
    let storageDir

    const definitions = {
      setStorageDir: dir => storageDir = dir,
      register,
      loadBotsFromDisk,
      send,

ses

Hardened JavaScript for Fearless Cooperation

Apache-2.0
Latest version published 1 month ago

Package Health Score

87 / 100
Full package analysis

Popular ses functions