wspr: Add addToRoots() for js

MultiPart: 2/2

Change-Id: Id8693636f776b665703c3e83c2314d7bcd213a7b
diff --git a/services/wspr/internal/app/app.go b/services/wspr/internal/app/app.go
index 8293a67..d9d87cf 100644
--- a/services/wspr/internal/app/app.go
+++ b/services/wspr/internal/app/app.go
@@ -762,23 +762,34 @@
 // PutToBlessingStore puts a blessing with the provided name to the blessing store
 // with the specified blessing pattern.
 func (c *Controller) PutToBlessingStore(_ *context.T, _ rpc.ServerCall, handle principal.BlessingsHandle, pattern security.BlessingPattern) (*principal.JsBlessings, error) {
-	var inputBlessing security.Blessings
-	if inputBlessing = c.GetBlessings(handle); inputBlessing.IsZero() {
+	var inputBlessings security.Blessings
+	if inputBlessings = c.GetBlessings(handle); inputBlessings.IsZero() {
 		return nil, verror.New(invalidBlessingsHandle, nil, handle)
 	}
 
 	p := v23.GetPrincipal(c.ctx)
-	outBlessing, err := p.BlessingStore().Set(inputBlessing, security.BlessingPattern(pattern))
+	outBlessings, err := p.BlessingStore().Set(inputBlessings, security.BlessingPattern(pattern))
 	if err != nil {
 		return nil, err
 	}
 
-	if outBlessing.IsZero() {
+	if outBlessings.IsZero() {
 		return nil, nil
 	}
 
-	jsBlessing := principal.ConvertBlessingsToHandle(outBlessing, c.blessingsCache.GetOrAddHandle(outBlessing))
-	return jsBlessing, nil
+	jsBlessings := principal.ConvertBlessingsToHandle(outBlessings, c.blessingsCache.GetOrAddHandle(outBlessings))
+	return jsBlessings, nil
+}
+
+// AddToRoots adds the provided blessing as a root.
+func (c *Controller) AddToRoots(_ *context.T, _ rpc.ServerCall, handle principal.BlessingsHandle) error {
+	var inputBlessings security.Blessings
+	if inputBlessings = c.GetBlessings(handle); inputBlessings.IsZero() {
+		return verror.New(invalidBlessingsHandle, nil, handle)
+	}
+
+	p := v23.GetPrincipal(c.ctx)
+	return p.AddToRoots(inputBlessings)
 }
 
 func (c *Controller) GetDefaultBlessings(*context.T, rpc.ServerCall) (*principal.JsBlessings, error) {
diff --git a/services/wspr/internal/app/controller.vdl b/services/wspr/internal/app/controller.vdl
index ff4f1c0..85c911a 100644
--- a/services/wspr/internal/app/controller.vdl
+++ b/services/wspr/internal/app/controller.vdl
@@ -32,6 +32,8 @@
 	BlessSelf(name string, caveats []security.Caveat) (string, principal.BlessingsHandle | error)
 	// PutToBlessingStore puts the specified blessing to the blessing store under the provided pattern.
 	PutToBlessingStore(blessingHandle principal.BlessingsHandle, pattern security.BlessingPattern) (?principal.JsBlessings | error)
+	// AddToRoots adds the provided blessing as a root.
+	AddToRoots(blessingHandle principal.BlessingsHandle) error
 
 	// RemoteBlessings fetches the remote blessings for a given name and method.
 	RemoteBlessings(name, method string) ([]string | error)
diff --git a/services/wspr/internal/app/controller.vdl.go b/services/wspr/internal/app/controller.vdl.go
index 2e059d8..5d5d920 100644
--- a/services/wspr/internal/app/controller.vdl.go
+++ b/services/wspr/internal/app/controller.vdl.go
@@ -41,6 +41,8 @@
 	BlessSelf(ctx *context.T, name string, caveats []security.Caveat, opts ...rpc.CallOpt) (string, principal.BlessingsHandle, error)
 	// PutToBlessingStore puts the specified blessing to the blessing store under the provided pattern.
 	PutToBlessingStore(ctx *context.T, blessingHandle principal.BlessingsHandle, pattern security.BlessingPattern, opts ...rpc.CallOpt) (*principal.JsBlessings, error)
+	// AddToRoots adds the provided blessing as a root.
+	AddToRoots(ctx *context.T, blessingHandle principal.BlessingsHandle, opts ...rpc.CallOpt) error
 	// RemoteBlessings fetches the remote blessings for a given name and method.
 	RemoteBlessings(ctx *context.T, name string, method string, opts ...rpc.CallOpt) ([]string, error)
 	// Signature fetches the signature for a given name.
@@ -104,6 +106,11 @@
 	return
 }
 
+func (c implControllerClientStub) AddToRoots(ctx *context.T, i0 principal.BlessingsHandle, opts ...rpc.CallOpt) (err error) {
+	err = v23.GetClient(ctx).Call(ctx, c.name, "AddToRoots", []interface{}{i0}, nil, opts...)
+	return
+}
+
 func (c implControllerClientStub) RemoteBlessings(ctx *context.T, i0 string, i1 string, opts ...rpc.CallOpt) (o0 []string, err error) {
 	err = v23.GetClient(ctx).Call(ctx, c.name, "RemoteBlessings", []interface{}{i0, i1}, []interface{}{&o0}, opts...)
 	return
@@ -141,6 +148,8 @@
 	BlessSelf(ctx *context.T, call rpc.ServerCall, name string, caveats []security.Caveat) (string, principal.BlessingsHandle, error)
 	// PutToBlessingStore puts the specified blessing to the blessing store under the provided pattern.
 	PutToBlessingStore(ctx *context.T, call rpc.ServerCall, blessingHandle principal.BlessingsHandle, pattern security.BlessingPattern) (*principal.JsBlessings, error)
+	// AddToRoots adds the provided blessing as a root.
+	AddToRoots(ctx *context.T, call rpc.ServerCall, blessingHandle principal.BlessingsHandle) error
 	// RemoteBlessings fetches the remote blessings for a given name and method.
 	RemoteBlessings(ctx *context.T, call rpc.ServerCall, name string, method string) ([]string, error)
 	// Signature fetches the signature for a given name.
@@ -216,6 +225,10 @@
 	return s.impl.PutToBlessingStore(ctx, call, i0, i1)
 }
 
+func (s implControllerServerStub) AddToRoots(ctx *context.T, call rpc.ServerCall, i0 principal.BlessingsHandle) error {
+	return s.impl.AddToRoots(ctx, call, i0)
+}
+
 func (s implControllerServerStub) RemoteBlessings(ctx *context.T, call rpc.ServerCall, i0 string, i1 string) ([]string, error) {
 	return s.impl.RemoteBlessings(ctx, call, i0, i1)
 }
@@ -320,6 +333,13 @@
 			},
 		},
 		{
+			Name: "AddToRoots",
+			Doc:  "// AddToRoots adds the provided blessing as a root.",
+			InArgs: []rpc.ArgDesc{
+				{"blessingHandle", ``}, // principal.BlessingsHandle
+			},
+		},
+		{
 			Name: "RemoteBlessings",
 			Doc:  "// RemoteBlessings fetches the remote blessings for a given name and method.",
 			InArgs: []rpc.ArgDesc{
diff --git a/services/wspr/internal/app/messaging.go b/services/wspr/internal/app/messaging.go
index 4b3c75a..4a9e4d8 100644
--- a/services/wspr/internal/app/messaging.go
+++ b/services/wspr/internal/app/messaging.go
@@ -73,7 +73,7 @@
 	// A request to remove a name from server.
 	RemoveName = 19
 
-	// A request to get the remove blessings of a server.
+	// A request to get the remote blessings of a server.
 	RemoteBlessings = 20
 
 	// A response to a caveat validation request.