@@ -97,10 +97,17 @@ const trace = makeTracer('SmrtWlt');
9797 * }} TryExitOfferAction
9898 */
9999
100+ /**
101+ * @typedef {{
102+ * method: 'evalExpr';
103+ * expr: string;
104+ * }} EvalExprAction
105+ */
106+
100107// Discriminated union. Possible future messages types:
101108// maybe suggestIssuer for https://github.com/Agoric/agoric-sdk/issues/6132
102109// setting petnames and adding brands for https://github.com/Agoric/agoric-sdk/issues/6126
103- /** @typedef {ExecuteOfferAction | TryExitOfferAction } BridgeAction */
110+ /** @typedef {ExecuteOfferAction | TryExitOfferAction | EvalExprAction } BridgeAction */
104111
105112/**
106113 * Purses is an array to support a future requirement of multiple purses per
@@ -477,6 +484,9 @@ export const prepareSmartWallet = (baggage, shared) => {
477484 executeOffer : M . call ( shape . OfferSpec ) . returns ( M . promise ( ) ) ,
478485 tryExitOffer : M . call ( M . scalar ( ) ) . returns ( M . promise ( ) ) ,
479486 } ) ,
487+ invoke : M . interface ( 'invoke' , {
488+ evalExpr : M . callWhen ( M . string ( ) ) . returns ( M . undefined ( ) ) ,
489+ } ) ,
480490 self : M . interface ( 'selfFacetI' , {
481491 handleBridgeAction : M . call ( shape . StringCapData , M . boolean ( ) ) . returns (
482492 M . promise ( ) ,
@@ -1035,6 +1045,22 @@ export const prepareSmartWallet = (baggage, shared) => {
10351045 } ,
10361046 } ,
10371047
1048+ invoke : {
1049+ /**
1050+ * @param {string } expr
1051+ */
1052+ async evalExpr ( expr ) {
1053+ trace ( 'TODO: validate Justin syntax' ) ;
1054+ trace ( 'evalExpr' , expr ) ;
1055+ // XXX worth using a nameHub vs. a mapStore?
1056+ const { nameHub, nameAdmin } = this . state . my ;
1057+ const endowments = { E, harden, assert, nameHub, nameAdmin } ;
1058+ const c = new Compartment ( endowments ) ;
1059+ const x = await c . evaluate ( expr ) ;
1060+ trace ( 'eval result' , x ) ;
1061+ } ,
1062+ } ,
1063+
10381064 self : {
10391065 /**
10401066 * Umarshals the actionCapData and delegates to the appropriate action
@@ -1075,6 +1101,9 @@ export const prepareSmartWallet = (baggage, shared) => {
10751101 assert ( canSpend , 'tryExitOffer requires spend authority' ) ;
10761102 return offers . tryExitOffer ( action . offerId ) ;
10771103 }
1104+ case 'evalExpr' : {
1105+ return facets . invoke . evalExpr ( action . expr ) ;
1106+ }
10781107 default : {
10791108 throw Fail `invalid handle bridge action ${ q ( action ) } ` ;
10801109 }
0 commit comments