Skip to content
Dan Connolly edited this page May 15, 2020 · 2 revisions

Suppose Bob is the salesman for Widget Inc. He persuades Alice to buy a widget. Bob hands Alice a Widget Order Form with a money-receiving capability. It is important to Bob that Alice use the form he gives her, because this particular form (which Bob got from Widget Inc.) remembers that Bob is the salesman who should get the commission. It is important to Alice that she know for sure that, even though she got the order-form from Bob, this is really a Widget Inc. order form, and not something Bob whipped up that will transfer her money directly to his own account. In this case, Alice wants to have Widget Inc. vouch for the order-form she received from Bob. She does this using an Inspector that she gets directly from Widget Inc. The Inspector is the public part of a notary/inspector pair of objects that provide verification of the originator of an object. To be vouchable, the orderForm must implement the startVouch method as shown here:

import harden from "@agoric/harden"

function makeNotary()  {
  const nonObject = {};
  function unvouchedException(obj) {throw(`Object not vouchable: $obj`);}
  let vouchableObject = nonObject;
  const inspector = harden({
    vouch(obj) {
      vouchableObject = nonObject;
      try {
	obj.startVouch();
	if (vouchableObject === nonObject) {
	  return unvouchedException(obj)
	} else {
	  const vouchedObject = vouchableObject;
	  vouchableObject = nonObject;
	  return vouchedObject;
	}
      } catch (err) {unvouchedException(obj);}
    }
  });
  const notary = harden({
    startVouch(obj) { vouchableObject = obj;},
    getInspector()  {return inspector;}
  });
  return notary;
}

We can see that an original painting tests as authentic while a forgery does not (it throws):

const nedNotaryNotPublished = makeNotary();

function makeAuthenticPainting() {
  const originalPainting = {
    stuff: "isn't this pretty?",
    startVouch() {
      nedNotaryNotPublished.startVouch(originalPainting)
    }
  };
  return originalPainting;
}

const p1 = makeAuthenticPainting();
const forgery1 = { stuff: "isn't this pretty?"};


const nedInspectorPublic = nedNotaryNotPublished.getInspector();


console.log('original ok?')
nedInspectorPublic.vouch(p1);
console.log('original ok!')

console.log('forgery ok?')
nedInspectorPublic.vouch(forgery1); // throws
console.log('forgery ok!')

References

Clone this wiki locally