diff --git a/cmd/issuer-agent/wasm/go.sum b/cmd/issuer-agent/wasm/go.sum index ab3151c0..ebc04960 100644 --- a/cmd/issuer-agent/wasm/go.sum +++ b/cmd/issuer-agent/wasm/go.sum @@ -114,6 +114,7 @@ github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35 h1:J9b7z+QKAm github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35/go.mod h1:prYjPmNq4d1NPVmpShWobRqXY3q7Vp+80DqgxxUrUIA= github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik= github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= +github.com/skip2/go-qrcode v0.0.0-20191027152451-9434209cb086/go.mod h1:PLPIyL7ikehBD1OAjmKKiOEhbvWyHGaNDjquXMcYABo= github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/square/go-jose/v3 v3.0.0-20191119004800-96c717272387 h1:PjfQbTWDEoNh4v+4NNirclXoCIxjjLXsqSAP1iYxuOM= diff --git a/cmd/rp-agent/wasm/go.sum b/cmd/rp-agent/wasm/go.sum index ab3151c0..ebc04960 100644 --- a/cmd/rp-agent/wasm/go.sum +++ b/cmd/rp-agent/wasm/go.sum @@ -114,6 +114,7 @@ github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35 h1:J9b7z+QKAm github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35/go.mod h1:prYjPmNq4d1NPVmpShWobRqXY3q7Vp+80DqgxxUrUIA= github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik= github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= +github.com/skip2/go-qrcode v0.0.0-20191027152451-9434209cb086/go.mod h1:PLPIyL7ikehBD1OAjmKKiOEhbvWyHGaNDjquXMcYABo= github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/square/go-jose/v3 v3.0.0-20191119004800-96c717272387 h1:PjfQbTWDEoNh4v+4NNirclXoCIxjjLXsqSAP1iYxuOM= diff --git a/cmd/user-agent/wasm/go.sum b/cmd/user-agent/wasm/go.sum index a16ad05f..701ebbcb 100644 --- a/cmd/user-agent/wasm/go.sum +++ b/cmd/user-agent/wasm/go.sum @@ -117,6 +117,7 @@ github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35 h1:J9b7z+QKAm github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35/go.mod h1:prYjPmNq4d1NPVmpShWobRqXY3q7Vp+80DqgxxUrUIA= github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik= github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= +github.com/skip2/go-qrcode v0.0.0-20191027152451-9434209cb086/go.mod h1:PLPIyL7ikehBD1OAjmKKiOEhbvWyHGaNDjquXMcYABo= github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/square/go-jose/v3 v3.0.0-20191119004800-96c717272387 h1:PjfQbTWDEoNh4v+4NNirclXoCIxjjLXsqSAP1iYxuOM= diff --git a/cmd/user-agent/web/src/App.vue b/cmd/user-agent/web/src/App.vue index 825e40b7..134343e8 100644 --- a/cmd/user-agent/web/src/App.vue +++ b/cmd/user-agent/web/src/App.vue @@ -10,6 +10,7 @@ SPDX-License-Identifier: Apache-2.0
  • Homepage
  • Accept Invitation
  • Register Wallet
  • +
  • My Credentials
  • diff --git a/cmd/user-agent/web/src/router/index.js b/cmd/user-agent/web/src/router/index.js index e128eb12..cba8bb25 100644 --- a/cmd/user-agent/web/src/router/index.js +++ b/cmd/user-agent/web/src/router/index.js @@ -31,6 +31,11 @@ export default new Router({ path: "/GetVC", component: () => import("@/views/GetVC") }, + { + name: "myVC", + path: "/MyVC", + component: () => import("@/views/myVC") + }, { name: "registerWallet", path: "/RegisterWallet", diff --git a/cmd/user-agent/web/src/views/myVC.vue b/cmd/user-agent/web/src/views/myVC.vue new file mode 100644 index 00000000..486c64ee --- /dev/null +++ b/cmd/user-agent/web/src/views/myVC.vue @@ -0,0 +1,51 @@ +/* +Copyright SecureKey Technologies Inc. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + + + diff --git a/go.mod b/go.mod index 942b575e..6a978de1 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,6 @@ go 1.13 require ( github.com/hyperledger/aries-framework-go v0.1.2 + github.com/skip2/go-qrcode v0.0.0-20191027152451-9434209cb086 github.com/stretchr/testify v1.4.0 - ) diff --git a/go.sum b/go.sum index a06b9b0e..55350916 100644 --- a/go.sum +++ b/go.sum @@ -66,7 +66,9 @@ github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/hyperledger/aries-framework-go v0.1.2-0.20200220221823-fb5c1d69a845 h1:bWjirDFdao/xtNxXWrZYoSaM+v2hMfPP9r/dtPcFHII= github.com/hyperledger/aries-framework-go v0.1.2-0.20200220221823-fb5c1d69a845/go.mod h1:/Fy3iGC4G2sD4HgKDC17CGcLLFFBTTgR5lEp2INNXbw= +github.com/hyperledger/aries-framework-go v0.1.2-0.20200226031908-1aef12b7b826 h1:SKdGTcCWO5FyNh2eUdL0b00sN11UOCBBqd8mutCesYY= github.com/hyperledger/aries-framework-go v0.1.2-0.20200226031908-1aef12b7b826/go.mod h1:e2VM3jE+OQgICspFVhUkV6n1MmiHXaD+6xG7TxdHaGI= +github.com/hyperledger/aries-framework-go v0.1.2 h1:7KIj/6Z9xYb+M951/GlIE48LqFAVbTBju1rB/e4zCgk= github.com/hyperledger/aries-framework-go v0.1.2/go.mod h1:p7zzPz5BTer52kgbbEaLuNFtZ83Q7GnW1cUnKkIRDc0= github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= @@ -104,6 +106,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35 h1:J9b7z+QKAmPf4YLrFg6oQUotqHQeUNWwkvo7jZp1GLU= github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35/go.mod h1:prYjPmNq4d1NPVmpShWobRqXY3q7Vp+80DqgxxUrUIA= github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= +github.com/skip2/go-qrcode v0.0.0-20191027152451-9434209cb086 h1:RYiqpb2ii2Z6J4x0wxK46kvPBbFuZcdhS+CIztmYgZs= +github.com/skip2/go-qrcode v0.0.0-20191027152451-9434209cb086/go.mod h1:PLPIyL7ikehBD1OAjmKKiOEhbvWyHGaNDjquXMcYABo= github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/square/go-jose/v3 v3.0.0-20191119004800-96c717272387 h1:PjfQbTWDEoNh4v+4NNirclXoCIxjjLXsqSAP1iYxuOM= diff --git a/pkg/store/vc/store.go b/pkg/store/vc/store.go index f0992085..ecde6e59 100644 --- a/pkg/store/vc/store.go +++ b/pkg/store/vc/store.go @@ -8,10 +8,13 @@ SPDX-License-Identifier: Apache-2.0 package vc import ( + "encoding/base64" "fmt" "strings" "syscall/js" + qrcode "github.com/skip2/go-qrcode" + "github.com/hyperledger/aries-framework-go/pkg/doc/verifiable" "github.com/hyperledger/aries-framework-go/pkg/storage" verifiablestore "github.com/hyperledger/aries-framework-go/pkg/store/verifiable" @@ -19,6 +22,7 @@ import ( const ( friendlyNamePreFix = "fr_" + responseType = "Response" ) type provider interface { @@ -46,6 +50,7 @@ func RegisterHandleJSCallback(ctx provider) error { js.Global().Set("storeVC", js.FuncOf(c.storeVC)) js.Global().Set("populateVC", js.FuncOf(c.populateVC)) js.Global().Set("getVC", js.FuncOf(c.getVC)) + js.Global().Set("createQRCode", js.FuncOf(c.createQRCode)) return nil } @@ -60,7 +65,7 @@ func (c *callback) storeVC(this js.Value, inputs []js.Value) interface{} { // https://github.com/golang/go/issues/26382 go func() { m := make(map[string]interface{}) - m["dataType"] = "Response" + m["dataType"] = responseType m["data"] = "success" vcData := inputs[0].Get("credential").Get("data").String() vc, err := verifiable.NewUnverifiedCredential([]byte(vcData)) @@ -108,7 +113,7 @@ func (c *callback) getVC(this js.Value, inputs []js.Value) interface{} { // https://github.com/golang/go/issues/26382 go func() { m := make(map[string]interface{}) - m["dataType"] = "Response" + m["dataType"] = responseType vcID, err := c.vcFriendlyNameStore.Get(friendlyNamePreFix + inputs[1].String()) if err != nil { @@ -137,3 +142,56 @@ func (c *callback) getVC(this js.Value, inputs []js.Value) interface{} { return nil } + +func (c *callback) createQRCode(this js.Value, inputs []js.Value) interface{} { + // https://github.com/golang/go/issues/26382 + // todo unit-test this function https://github.com/trustbloc/edge-agent/issues/54 + go func() { + m := make(map[string]interface{}) + m["dataType"] = responseType + + vcID, err := c.vcFriendlyNameStore.Get(friendlyNamePreFix + inputs[0].String()) + if err != nil { + m["data"] = fmt.Sprintf("failed to get in vc friendly name store: %s", err.Error()) + return + } + + vc, err := c.store.GetVC(string(vcID)) + if err != nil { + m["data"] = fmt.Sprintf("failed to get in vc store: %s", err.Error()) + return + } + vcBytes, err := vc.MarshalJSON() + if err != nil { + m["data"] = fmt.Sprintf("failed to marshal vc: %s", err.Error()) + return + } + generateQRCode(string(vcBytes)) + }() + + return nil +} + +func generateQRCode(data string) { + var generateQRCode js.Func + + document := js.Global().Get("document") + + generateQRCode = js.FuncOf(func(this js.Value, args []js.Value) interface{} { + if len(data) > 0 { + fmt.Println("Building QR Code for", data) + + png, err := qrcode.Encode(data, qrcode.Medium, 256) + if err != nil { + fmt.Println("Failed generating QR Code. Error=", err.Error()) + } + + b64Encoded := base64.StdEncoding.EncodeToString(png) + image := document.Call("getElementById", "qr-result") + image.Call("setAttribute", "src", "data:image/png;base64, "+b64Encoded) + } + return nil + }) + + document.Call("getElementById", "getVCBtn").Call("addEventListener", "click", generateQRCode) +}