From ee23207b8a9cf45408a4ce42c5791f572f2d52e5 Mon Sep 17 00:00:00 2001 From: Arnab Ghose Date: Mon, 31 Jul 2023 12:43:04 +0530 Subject: [PATCH] feat: added support for BBS+ Signature scheme --- cmd/hid-noded/cmd/debug_extensions.go | 80 ++++++++++++++++++++++++++- go.mod | 18 ++++-- go.sum | 39 ++++++++++--- tests/e2e/ssi_tests/e2e_tests.py | 62 +++++++++++++++++++++ tests/e2e/ssi_tests/generate_doc.py | 6 ++ tests/e2e/ssi_tests/run.py | 1 + tests/e2e/ssi_tests/utils.py | 2 + x/ssi/client/cli/tx_utils.go | 26 ++++++++- x/ssi/types/common.go | 6 +- x/ssi/types/diddoc_validation.go | 25 +++++++-- x/ssi/verification/crypto.go | 36 ++++++++++++ 11 files changed, 279 insertions(+), 22 deletions(-) diff --git a/cmd/hid-noded/cmd/debug_extensions.go b/cmd/hid-noded/cmd/debug_extensions.go index 1d6c68c..dd7ff10 100644 --- a/cmd/hid-noded/cmd/debug_extensions.go +++ b/cmd/hid-noded/cmd/debug_extensions.go @@ -3,6 +3,7 @@ package cmd import ( "crypto/ed25519" "crypto/rand" + "crypto/sha256" "encoding/base64" "encoding/hex" "encoding/json" @@ -11,6 +12,7 @@ import ( "github.com/btcsuite/btcutil/base58" "github.com/cosmos/cosmos-sdk/client" ethercrypto "github.com/ethereum/go-ethereum/crypto" + bbs "github.com/hyperledger/aries-framework-go/component/kmscrypto/crypto/primitive/bbs12381g2pub" hidnodecli "github.com/hypersign-protocol/hid-node/x/ssi/client/cli" "github.com/hypersign-protocol/hid-node/x/ssi/types" "github.com/multiformats/go-multibase" @@ -22,11 +24,25 @@ func extendDebug(debugCmd *cobra.Command) *cobra.Command { debugCmd.AddCommand( ed25519Cmd(), secp256k1Cmd(), + bbsCmd(), signSSIDocCmd(), ) return debugCmd } +func bbsCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "bbs", + Short: "bbs debug commands", + } + + cmd.AddCommand( + blsRandomCmd(), + ) + + return cmd +} + func secp256k1Cmd() *cobra.Command { cmd := &cobra.Command{ Use: "secp256k1", @@ -42,6 +58,56 @@ func secp256k1Cmd() *cobra.Command { return cmd } +func blsRandomCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "random", + Short: "Generate random blsBbs keypair", + RunE: func(cmd *cobra.Command, args []string) error { + pubKey, privKey, err := bbs.GenerateKeyPair(sha256.New, nil) + if err != nil { + return err + } + + // Convert Public Key Object to Multibase + pubKeyBytes, err := pubKey.Marshal() + if err != nil { + return err + } + + publicKeyMultibase, err := multibase.Encode(multibase.Base58BTC, pubKeyBytes) + if err != nil { + return err + } + + // Convert Private Object to Bytes + privKeyBytes, err := privKey.Marshal() + if err != nil { + return err + } + + keyInfo := struct { + PubKeyBase64 string `json:"pub_key_base_64"` + PubKeyMultibase string `json:"pub_key_multibase"` + PrivKeyBase64 string `json:"priv_key_base_64"` + }{ + PubKeyBase64: base64.StdEncoding.EncodeToString(pubKeyBytes), + PubKeyMultibase: publicKeyMultibase, + PrivKeyBase64: base64.StdEncoding.EncodeToString(privKeyBytes), + } + + keyInfoJson, err := json.Marshal(keyInfo) + if err != nil { + return err + } + + _, err = fmt.Fprintln(cmd.OutOrStdout(), string(keyInfoJson)) + return err + }, + } + + return cmd +} + func secp256k1RandomCmd() *cobra.Command { cmd := &cobra.Command{ Use: "random", @@ -214,8 +280,13 @@ func signSchemaDocCmd() *cobra.Command { if err != nil { return err } + case "bbs": + signature, err = hidnodecli.GetBBSSignature(argPrivateKey, schemaDocBytes) + if err != nil { + return err + } default: - panic("recieved unsupported signing-algo. Supported algorithms are: ['ed25519', 'secp256k1', 'recover-eth']") + panic("recieved unsupported signing-algo. Supported algorithms are: ['ed25519', 'secp256k1', 'recover-eth', 'bbs']") } _, err = fmt.Fprintln(cmd.OutOrStdout(), signature) @@ -266,8 +337,13 @@ func signCredStatusDocCmd() *cobra.Command { if err != nil { return err } + case "bbs": + signature, err = hidnodecli.GetBBSSignature(argPrivateKey, credStatusDocBytes) + if err != nil { + return err + } default: - panic("recieved unsupported signing-algo. Supported algorithms are: ['ed25519', 'secp256k1', 'recover-eth']") + panic("recieved unsupported signing-algo. Supported algorithms are: ['ed25519', 'secp256k1', 'recover-eth', 'bbs']") } _, err = fmt.Fprintln(cmd.OutOrStdout(), signature) diff --git a/go.mod b/go.mod index 5365d01..73822aa 100644 --- a/go.mod +++ b/go.mod @@ -9,9 +9,10 @@ require ( github.com/gogo/protobuf v1.3.3 github.com/gorilla/mux v1.8.0 github.com/grpc-ecosystem/grpc-gateway v1.16.0 + github.com/hyperledger/aries-framework-go/component/kmscrypto v0.0.0-20230727134633-020b60b288ed github.com/spf13/cast v1.5.0 github.com/spf13/cobra v1.6.0 - github.com/stretchr/testify v1.8.0 + github.com/stretchr/testify v1.8.1 github.com/tendermint/spm v0.1.9 github.com/tendermint/tendermint v0.34.23 github.com/tendermint/tm-db v0.6.7 @@ -21,20 +22,23 @@ require ( ) require ( - filippo.io/edwards25519 v1.0.0-beta.2 // indirect + filippo.io/edwards25519 v1.0.0 // indirect github.com/99designs/keyring v1.1.6 // indirect github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d // indirect github.com/DataDog/zstd v1.4.5 // indirect + github.com/IBM/mathlib v0.0.3-0.20230605104224-932ab92f2ce0 // indirect github.com/Workiva/go-datastructures v1.0.53 // indirect github.com/armon/go-metrics v0.4.0 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/bgentry/speakeasy v0.1.0 // indirect - github.com/btcsuite/btcd v0.22.1 // indirect + github.com/btcsuite/btcd v0.22.3 // indirect github.com/btcsuite/btcd/btcec/v2 v2.1.2 // indirect github.com/cespare/xxhash v1.1.0 // indirect github.com/cespare/xxhash/v2 v2.1.2 // indirect github.com/coinbase/rosetta-sdk-go v0.7.0 // indirect github.com/confio/ics23/go v0.7.0 // indirect + github.com/consensys/bavard v0.1.13 // indirect + github.com/consensys/gnark-crypto v0.9.1 // indirect github.com/cosmos/btcutil v1.0.4 // indirect github.com/cosmos/go-bip39 v1.0.0 // indirect github.com/cosmos/gorocksdb v1.2.0 // indirect @@ -70,11 +74,13 @@ require ( github.com/hashicorp/go-immutable-radix v1.3.1 // indirect github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect github.com/hashicorp/hcl v1.0.0 // indirect - github.com/hdevalence/ed25519consensus v0.0.0-20210204194344-59a8610d2b87 // indirect + github.com/hdevalence/ed25519consensus v0.1.0 // indirect + github.com/hyperledger/fabric-amcl v0.0.0-20230602173724-9e02669dceb2 // indirect github.com/improbable-eng/grpc-web v0.14.1 // indirect github.com/inconshreveable/mousetrap v1.0.1 // indirect github.com/jmhodges/levigo v1.0.0 // indirect github.com/keybase/go-keychain v0.0.0-20190712205309-48d3d31d256d // indirect + github.com/kilic/bls12-381 v0.1.0 // indirect github.com/klauspost/compress v1.15.11 // indirect github.com/lib/pq v1.10.6 // indirect github.com/libp2p/go-buffer-pool v0.1.0 // indirect @@ -86,7 +92,8 @@ require ( github.com/minio/highwayhash v1.0.2 // indirect github.com/mitchellh/go-homedir v1.1.0 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect - github.com/mr-tron/base58 v1.1.0 // indirect + github.com/mmcloughlin/addchain v0.4.0 // indirect + github.com/mr-tron/base58 v1.2.0 // indirect github.com/mtibben/percent v0.2.1 // indirect github.com/multiformats/go-base32 v0.0.3 // indirect github.com/multiformats/go-base36 v0.1.0 // indirect @@ -126,6 +133,7 @@ require ( gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect nhooyr.io/websocket v1.8.6 // indirect + rsc.io/tmplfunc v0.0.3 // indirect ) require ( diff --git a/go.sum b/go.sum index 2bd932c..00fa952 100644 --- a/go.sum +++ b/go.sum @@ -50,8 +50,9 @@ cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3f collectd.org v0.3.0/go.mod h1:A/8DzQBkF6abtvrT2j/AU/4tiBgJWYyh0y/oB/4MlWE= contrib.go.opencensus.io/exporter/stackdriver v0.13.4/go.mod h1:aXENhDJ1Y4lIg4EUaVTwzvYETVNZk10Pu26tevFKLUc= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= -filippo.io/edwards25519 v1.0.0-beta.2 h1:/BZRNzm8N4K4eWfK28dL4yescorxtO7YG1yun8fy+pI= filippo.io/edwards25519 v1.0.0-beta.2/go.mod h1:X+pm78QAUPtFLi1z9PYIlS/bdDnvbCOGKtZ+ACWEf7o= +filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= +filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= github.com/99designs/keyring v1.1.6 h1:kVDC2uCgVwecxCk+9zoCt2uEL6dt+dfVzMvGgnVcIuM= github.com/99designs/keyring v1.1.6/go.mod h1:16e0ds7LGQQcT59QqkTg72Hh5ShM51Byv5PEmW6uoRU= github.com/Antonboom/errname v0.1.4/go.mod h1:jRXo3m0E0EuCnK3wbsSVH3X55Z4iTDLl6ZfCxwFj4TM= @@ -85,6 +86,8 @@ github.com/DataDog/zstd v1.4.1/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t github.com/DataDog/zstd v1.4.5 h1:EndNeuB0l9syBZhut0wns3gV1hL8zX8LIu6ZiVHWLIQ= github.com/DataDog/zstd v1.4.5/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo= github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24/go.mod h1:4UJr5HIiMZrwgkSPdsjy2uOQExX/WEILpIrO9UPGuXs= +github.com/IBM/mathlib v0.0.3-0.20230605104224-932ab92f2ce0 h1:V3ElfC3Xs8bxJyc7VPcBQ9th6vyBBX8u/5bIUOXljk4= +github.com/IBM/mathlib v0.0.3-0.20230605104224-932ab92f2ce0/go.mod h1:k0NBSWMYVgaZ2keDuI8DSwdIEhUNhp8XnlVmm6Xwyuk= github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0= github.com/Masterminds/goutils v1.1.0/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU= github.com/Masterminds/semver v1.4.2/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y= @@ -179,8 +182,8 @@ github.com/btcsuite/btcd v0.0.0-20190315201642-aa6e0f35703c/go.mod h1:DrZx5ec/dm github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ= github.com/btcsuite/btcd v0.21.0-beta/go.mod h1:ZSWyehm27aAuS9bvkATT+Xte3hjHZ+MRgMY/8NJ7K94= github.com/btcsuite/btcd v0.22.0-beta/go.mod h1:9n5ntfhhHQBIhUvlhDvD3Qg6fRUj4jkN0VB8L8svzOA= -github.com/btcsuite/btcd v0.22.1 h1:CnwP9LM/M9xuRrGSCGeMVs9iv09uMqwsVX7EeIpgV2c= -github.com/btcsuite/btcd v0.22.1/go.mod h1:wqgTSL29+50LRkmOVknEdmt8ZojIzhuWvgu/iptuN7Y= +github.com/btcsuite/btcd v0.22.3 h1:kYNaWFvOw6xvqP0vR20RP1Zq1DVMBxEO8QN5d1/EfNg= +github.com/btcsuite/btcd v0.22.3/go.mod h1:wqgTSL29+50LRkmOVknEdmt8ZojIzhuWvgu/iptuN7Y= github.com/btcsuite/btcd/btcec/v2 v2.1.2 h1:YoYoC9J0jwfukodSBMzZYUVQ8PTiYg4BnOWiJVzTmLs= github.com/btcsuite/btcd/btcec/v2 v2.1.2/go.mod h1:ctjw4H1kknNJmRN4iP1R7bTQ+v3GJkZBd6mui8ZsAZE= github.com/btcsuite/btcd/chaincfg/chainhash v1.0.0/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc= @@ -229,7 +232,11 @@ github.com/coinbase/rosetta-sdk-go v0.6.10/go.mod h1:J/JFMsfcePrjJZkwQFLh+hJErkA github.com/coinbase/rosetta-sdk-go v0.7.0 h1:lmTO/JEpCvZgpbkOITL95rA80CPKb5CtMzLaqF2mCNg= github.com/coinbase/rosetta-sdk-go v0.7.0/go.mod h1:7nD3oBPIiHqhRprqvMgPoGxe/nyq3yftRmpsy29coWE= github.com/consensys/bavard v0.1.8-0.20210406032232-f3452dc9b572/go.mod h1:Bpd0/3mZuaj6Sj+PqrmIquiOKy397AKGThQPaGzNXAQ= +github.com/consensys/bavard v0.1.13 h1:oLhMLOFGTLdlda/kma4VOJazblc7IM5y5QPd2A/YjhQ= +github.com/consensys/bavard v0.1.13/go.mod h1:9ItSMtA/dXMAiL7BG6bqW2m3NdSEObYWoH223nGHukI= github.com/consensys/gnark-crypto v0.4.1-0.20210426202927-39ac3d4b3f1f/go.mod h1:815PAHg3wvysy0SyIqanF8gZ0Y1wjk/hrDHD/iT88+Q= +github.com/consensys/gnark-crypto v0.9.1 h1:mru55qKdWl3E035hAoh1jj9d7hVnYY5pfb6tmovSmII= +github.com/consensys/gnark-crypto v0.9.1/go.mod h1:a2DQL4+5ywF6safEeZFEPGRiiGbjzGFRUN2sg06VuU4= github.com/containerd/console v1.0.2/go.mod h1:ytZPjGgY2oeTkAONYafi2kSj0aYggsf8acV1PGKCbzQ= github.com/containerd/continuity v0.0.0-20190827140505-75bee3e2ccb6/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y= github.com/containerd/continuity v0.1.0/go.mod h1:ICJu0PwR54nI0yPEnJ6jcS+J7CZAUXrLh8lPo2knzsM= @@ -550,6 +557,7 @@ github.com/google/pprof v0.0.0-20201218002935-b9804c9f04c2/go.mod h1:kpwsk12EmLe github.com/google/pprof v0.0.0-20210122040257-d980be63207e/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210226084205-cbba55b83ad5/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk= github.com/google/trillian v1.3.11/go.mod h1:0tPraVHrSDkA3BO6vKX67zgLXs6SsOAbHEivX+9mPgw= github.com/google/uuid v0.0.0-20161128191214-064e2069ce9c/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= @@ -645,8 +653,9 @@ github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ= github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= -github.com/hdevalence/ed25519consensus v0.0.0-20210204194344-59a8610d2b87 h1:uUjLpLt6bVvZ72SQc/B4dXcPBw4Vgd7soowdRl52qEM= github.com/hdevalence/ed25519consensus v0.0.0-20210204194344-59a8610d2b87/go.mod h1:XGsKKeXxeRr95aEOgipvluMPlgjr7dGlk9ZTWOjcUcg= +github.com/hdevalence/ed25519consensus v0.1.0 h1:jtBwzzcHuTmFrQN6xQZn6CQEO/V9f7HsjsjeEZ6auqU= +github.com/hdevalence/ed25519consensus v0.1.0/go.mod h1:w3BHWjwJbFU29IRHL1Iqkw3sus+7FctEyM4RqDxYNzo= github.com/holiman/bloomfilter/v2 v2.0.3/go.mod h1:zpoh+gs7qcpqrHr3dB55AMiJwo0iURXE7ZOP9L9hSkA= github.com/holiman/uint256 v1.1.1/go.mod h1:y4ga/t+u+Xwd7CpDgZESaRcWy0I7XMlTMA25ApIH5Jw= github.com/holiman/uint256 v1.2.0/go.mod h1:y4ga/t+u+Xwd7CpDgZESaRcWy0I7XMlTMA25ApIH5Jw= @@ -657,6 +666,10 @@ github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmK github.com/huin/goupnp v1.0.0/go.mod h1:n9v9KO1tAxYH82qOn+UTIFQDmx5n1Zxd/ClZDMX7Bnc= github.com/huin/goupnp v1.0.3-0.20220313090229-ca81a64b4204/go.mod h1:ZxNlw5WqJj6wSsRK5+YfflQGXYfccj5VgQsMNixHM7Y= github.com/huin/goutil v0.0.0-20170803182201-1ca381bf3150/go.mod h1:PpLOETDnJ0o3iZrZfqZzyLl6l7F3c6L1oWn7OICBi6o= +github.com/hyperledger/aries-framework-go/component/kmscrypto v0.0.0-20230727134633-020b60b288ed h1:VhOlaHnE7mVmC7Up0K3pGeuimpsktHNZALECj21seF4= +github.com/hyperledger/aries-framework-go/component/kmscrypto v0.0.0-20230727134633-020b60b288ed/go.mod h1:nmT2WqhIs9Eyncdr9feYrUIy7ggf00bWnTzCN6/t8PY= +github.com/hyperledger/fabric-amcl v0.0.0-20230602173724-9e02669dceb2 h1:B1Nt8hKb//KvgGRprk0h1t4lCnwhE9/ryb1WqfZbV+M= +github.com/hyperledger/fabric-amcl v0.0.0-20230602173724-9e02669dceb2/go.mod h1:X+DIyUsaTmalOpmpQfIvFZjKHQedrURQ5t4YqquX7lE= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/imdario/mergo v0.3.4/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= @@ -724,6 +737,8 @@ github.com/karalabe/usb v0.0.0-20190919080040-51dc0efba356/go.mod h1:Od972xHfMJo github.com/karalabe/usb v0.0.2/go.mod h1:Od972xHfMJowv7NGVDiWVxk2zxnWgjLlJzE+F4F7AGU= github.com/keybase/go-keychain v0.0.0-20190712205309-48d3d31d256d h1:Z+RDyXzjKE0i2sTjZ/b1uxiGtPhFy34Ou/Tk0qwN0kM= github.com/keybase/go-keychain v0.0.0-20190712205309-48d3d31d256d/go.mod h1:JJNrCn9otv/2QP4D7SMJBgaleKpOf66PnW6F5WGNRIc= +github.com/kilic/bls12-381 v0.1.0 h1:encrdjqKMEvabVQ7qYOKu1OvhqpK4s47wDYtNiPtlp4= +github.com/kilic/bls12-381 v0.1.0/go.mod h1:vDTTHJONJ6G+P2R74EhnyotQDTliQDnFEwhdmfzw1ig= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/errcheck v1.6.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= @@ -760,6 +775,7 @@ github.com/labstack/echo/v4 v4.2.1/go.mod h1:AA49e0DZ8kk5jTOOCKNuPR6oTnBS0dYiM4F github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k= github.com/ldez/gomoddirectives v0.2.2/go.mod h1:cpgBogWITnCfRq2qGoDkKMEVSaarhdBr6g8G04uz6d0= github.com/ldez/tagliatelle v0.2.0/go.mod h1:8s6WJQwEYHbKZDsp/LjArytKOG8qaMrKQQ3mFukHs88= +github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c= github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8= github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= @@ -854,6 +870,9 @@ github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RR github.com/mitchellh/pointerstructure v1.2.0/go.mod h1:BRAsLI5zgXmw97Lf6s25bs8ohIXc3tViBH44KcwB2g4= github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= github.com/mitchellh/reflectwalk v1.0.1/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= +github.com/mmcloughlin/addchain v0.4.0 h1:SobOdjm2xLj1KkXN5/n0xTIWyZA2+s99UCY1iPfkHRY= +github.com/mmcloughlin/addchain v0.4.0/go.mod h1:A86O+tHqZLMNO4w6ZZ4FlVQEadcoqkyU72HC5wJ4RlU= +github.com/mmcloughlin/profile v0.1.1/go.mod h1:IhHD7q1ooxgwTgjxQYkACGA77oFTDdFVejUS1/tS/qU= github.com/moby/sys/mountinfo v0.4.1/go.mod h1:rEr8tzG/lsIZHBtN/JjGG+LMYx9eXgW2JI+6q0qou+A= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= @@ -867,8 +886,9 @@ github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwd github.com/moricho/tparallel v0.2.1/go.mod h1:fXEIZxG2vdfl0ZF8b42f5a78EhjjD5mX8qUplsoSU4k= github.com/mozilla/scribe v0.0.0-20180711195314-fb71baf557c1/go.mod h1:FIczTrinKo8VaLxe6PWTPEXRXDIHz2QAwiaBaP5/4a8= github.com/mozilla/tls-observatory v0.0.0-20210609171429-7bc42856d2e5/go.mod h1:FUqVoUPHSEdDR0MnFM3Dh8AU0pZHLXUD127SAJGER/s= -github.com/mr-tron/base58 v1.1.0 h1:Y51FGVJ91WBqCEabAi5OPUz38eAx8DakuAm5svLcsfQ= github.com/mr-tron/base58 v1.1.0/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8= +github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o= +github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= github.com/mrunalp/fileutils v0.5.0/go.mod h1:M1WthSahJixYnrXQl/DFQuteStB1weuxD2QJNHXfbSQ= github.com/mschoch/smat v0.0.0-20160514031455-90eadee771ae/go.mod h1:qAyveg+e4CE+eKJXWVjKXM4ck2QobLqTDytGJbLLhJg= github.com/mtibben/percent v0.2.1 h1:5gssi8Nqo8QU/r2pynCm+hBQHpkB/uNK7BJCFogWdzs= @@ -1164,8 +1184,9 @@ github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5J github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= -github.com/stretchr/objx v0.4.0 h1:M2gUjqZET1qApGOWNSnZ49BAIMX4F/1plDv3+l31EJ4= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v0.0.0-20170130113145-4d4bfba8f1d1/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.1.4/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.2.0/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= @@ -1176,8 +1197,9 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5 github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/subosito/gotenv v1.4.1 h1:jyEFiXpy21Wm81FBN71l9VoMMV8H8jG+qIK3GCpY6Qs= github.com/subosito/gotenv v1.4.1/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0= @@ -1535,6 +1557,7 @@ golang.org/x/sys v0.0.0-20200909081042-eff7692f9009/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200923182605-d9f96fdee20d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201101102859-da207088b7d1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210104204734-6f8348627aad/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -1872,5 +1895,7 @@ rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8 rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= +rsc.io/tmplfunc v0.0.3 h1:53XFQh69AfOa8Tw0Jm7t+GV7KZhOi6jzsCzTtKbMvzU= +rsc.io/tmplfunc v0.0.3/go.mod h1:AG3sTPzElb1Io3Yg4voV9AGZJuleGAwaVRxL9M49PhA= sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU= diff --git a/tests/e2e/ssi_tests/e2e_tests.py b/tests/e2e/ssi_tests/e2e_tests.py index 2139395..3cd8ed6 100644 --- a/tests/e2e/ssi_tests/e2e_tests.py +++ b/tests/e2e/ssi_tests/e2e_tests.py @@ -9,6 +9,68 @@ query_did, form_create_schema_tx, form_did_deactivate_tx_multisig, form_create_cred_status_tx from constants import DEFAULT_BLOCKCHAIN_ACCOUNT_NAME +def bbs_signature_test(): + print("\n--1. PASS: Create a DID using BLS12381G2 Key Pair--\n") + + kp_alice = generate_key_pair("bbs") + signers = [] + did_doc_string = generate_did_document(kp_alice, "bbs") + did_doc_alice = did_doc_string["id"] + signPair_alice = { + "kp": kp_alice, + "verificationMethodId": did_doc_string["verificationMethod"][0]["id"], + "signing_algo": "bbs" + } + signers.append(signPair_alice) + create_tx_cmd = form_did_create_tx_multisig(did_doc_string, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME) + run_blockchain_command(create_tx_cmd, f"Registering Alice's DID with Id: {did_doc_alice}") + + print("\n--2. PASS: Create a Schema using BLS12381G2 Key Pair--\n") + + schema_doc, schema_proof = generate_schema_document( + kp_alice, + did_doc_alice, + did_doc_string["verificationMethod"][0]["id"], + algo="bbs" + ) + create_schema_cmd = form_create_schema_tx( + schema_doc, + schema_proof, + DEFAULT_BLOCKCHAIN_ACCOUNT_NAME + ) + schema_doc_id = schema_doc["id"] + run_blockchain_command(create_schema_cmd, f"Registering Schema with Id: {schema_doc_id}") + + print("\n--3. PASS: Create a Credential Status using BLS12381G2 Key Pair--\n") + + cred_doc, cred_proof = generate_cred_status_document( + kp_alice, + did_doc_alice, + did_doc_string["verificationMethod"][0]["id"], + algo="bbs" + ) + register_cred_status_cmd = form_create_cred_status_tx( + cred_doc, + cred_proof, + DEFAULT_BLOCKCHAIN_ACCOUNT_NAME + ) + cred_id = cred_doc["claim"]["id"] + run_blockchain_command(register_cred_status_cmd, f"Registering Credential status with Id: {cred_id}") + + + print("\n--4. PASS: Update a DID using BLS12381G2 Key Pair--\n") + did_doc_string["context"] = ["http://example.com"] + signers = [] + signers.append(signPair_alice) + update_tx_cmd = form_did_update_tx_multisig(did_doc_string, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME) + run_blockchain_command(update_tx_cmd, f"Bob (non-controller) attempts to update Org DID with Id: {did_doc_alice}") + + print("\n--5. PASS: Deactivate a DID using BLS12381G2 Key Pair--\n") + signers = [] + signers.append(signPair_alice) + deactivate_tx_cmd = form_did_deactivate_tx_multisig(did_doc_alice, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME) + run_blockchain_command(deactivate_tx_cmd, f"Deactivation of Org's DID with Id: {did_doc_alice}") + def key_agrement_test(): print("\n--1. FAIL: Ed25519VerificationKey2020 based Verification Method ID being added to keyAgreement attribute--\n") diff --git a/tests/e2e/ssi_tests/generate_doc.py b/tests/e2e/ssi_tests/generate_doc.py index f668520..93a869e 100644 --- a/tests/e2e/ssi_tests/generate_doc.py +++ b/tests/e2e/ssi_tests/generate_doc.py @@ -27,6 +27,8 @@ def generate_did_document(key_pair, algo="ed25519", bech32prefix="hid", is_uuid= vm_type = "EcdsaSecp256k1VerificationKey2019" elif algo == "recover-eth": vm_type = "EcdsaSecp256k1RecoveryMethod2020" + elif algo == "bbs": + vm_type = "Bls12381G2Key2020" else: raise Exception("unknown signing algorithm: " + key_pair) @@ -92,6 +94,8 @@ def generate_schema_document(key_pair, schema_author, vm, signature=None, algo=" proof_type = "EcdsaSecp256k1Signature2019" elif algo == "recover-eth": proof_type = "EcdsaSecp256k1RecoverySignature2020" + elif algo == "bbs": + proof_type = "BbsBlsSignature2020" else: raise Exception("Invalid signing algo: " + algo) @@ -136,6 +140,8 @@ def generate_cred_status_document(key_pair, cred_author, vm, signature=None, alg proof_type = "EcdsaSecp256k1Signature2019" elif algo == "recover-eth": proof_type = "EcdsaSecp256k1RecoverySignature2020" + elif algo == "bbs": + proof_type = "BbsBlsSignature2020" else: raise Exception("Invalid signing algo: " + algo) diff --git a/tests/e2e/ssi_tests/run.py b/tests/e2e/ssi_tests/run.py index 76bd089..e6f791f 100644 --- a/tests/e2e/ssi_tests/run.py +++ b/tests/e2e/ssi_tests/run.py @@ -35,6 +35,7 @@ def run_all_tests(): method_specific_id_test() unique_wallet_address_test() key_agrement_test() + bbs_signature_test() print("============= 😃️ All test cases completed successfully ============== \n") diff --git a/tests/e2e/ssi_tests/utils.py b/tests/e2e/ssi_tests/utils.py index ed0ec9c..131bfd3 100644 --- a/tests/e2e/ssi_tests/utils.py +++ b/tests/e2e/ssi_tests/utils.py @@ -53,6 +53,8 @@ def generate_key_pair(algo="ed25519"): cmd = "hid-noded debug secp256k1 random" elif algo == "recover-eth": cmd = "hid-noded debug secp256k1 eth-hex-random" + elif algo == "bbs": + cmd = "hid-noded debug bbs random" else: raise Exception(algo + " is not a supported signing algorithm") result_str, _ = run_command(cmd) diff --git a/x/ssi/client/cli/tx_utils.go b/x/ssi/client/cli/tx_utils.go index 6c6c5c9..c9c8fd5 100644 --- a/x/ssi/client/cli/tx_utils.go +++ b/x/ssi/client/cli/tx_utils.go @@ -17,6 +17,8 @@ import ( etherhexutil "github.com/ethereum/go-ethereum/common/hexutil" ethercrypto "github.com/ethereum/go-ethereum/crypto" + bbs "github.com/hyperledger/aries-framework-go/component/kmscrypto/crypto/primitive/bbs12381g2pub" + "github.com/spf13/cobra" ) @@ -47,6 +49,23 @@ func extractDIDSigningElements(cmdArgs []string) ([]DIDSigningElements, error) { return didSigningElementsList, nil } +// GetBBSSignature signs a message and returns a BBS signature +func GetBBSSignature(privateKey string, message []byte) (string, error) { + privKeyBytes, err := base64.StdEncoding.DecodeString(privateKey) + if err != nil { + panic(err) + } + + bbsObj := bbs.New() + + signatureBytes, err := bbsObj.Sign([][]byte{message}, privKeyBytes) + if err != nil { + panic(err) + } + + return base64.StdEncoding.EncodeToString(signatureBytes), nil +} + func GetEthRecoverySignature(privateKey string, message []byte) (string, error) { // Decode key into bytes privKeyBytes, err := hex.DecodeString(privateKey) @@ -132,8 +151,13 @@ func getSignatures(cmd *cobra.Command, message []byte, cmdArgs []string) ([]*typ if err != nil { return nil, err } + case "bbs": + signInfoList[i].Signature, err = GetBBSSignature(didSigningElementsList[i].SignKey, message) + if err != nil { + return nil, err + } default: - return nil, fmt.Errorf("unsupported signing algorithm %s, supported signing algorithms: ['ed25519','secp256k1']", didSigningElementsList[i].SignAlgo) + return nil, fmt.Errorf("unsupported signing algorithm %s, supported signing algorithms: ['ed25519', 'secp256k1', 'recover-eth', 'bbs']", didSigningElementsList[i].SignAlgo) } } diff --git a/x/ssi/types/common.go b/x/ssi/types/common.go index b69bfb3..b2226fc 100644 --- a/x/ssi/types/common.go +++ b/x/ssi/types/common.go @@ -10,14 +10,16 @@ const EcdsaSecp256k1VerificationKey2019 = "EcdsaSecp256k1VerificationKey2019" const EcdsaSecp256k1RecoveryMethod2020 = "EcdsaSecp256k1RecoveryMethod2020" const X25519KeyAgreementKey2020 = "X25519KeyAgreementKey2020" const X25519KeyAgreementKeyEIP5630 = "X25519KeyAgreementKeyEIP5630" // TODO: Temporary spec name for KeyAgreement type from Metamask +const Bls12381G2Key2020 = "Bls12381G2Key2020" // Mapping between Verification Key and its corresponding Signature var VerificationKeySignatureMap = map[string]string{ Ed25519VerificationKey2020: "Ed25519Signature2020", EcdsaSecp256k1VerificationKey2019: "EcdsaSecp256k1Signature2019", EcdsaSecp256k1RecoveryMethod2020: "EcdsaSecp256k1RecoverySignature2020", - X25519KeyAgreementKey2020: "", // Authentication and Assertion are not allowed - X25519KeyAgreementKeyEIP5630: "", // Authentication and Assertion are not allowed + X25519KeyAgreementKey2020: "", // Authentication and Assertion are not allowed + X25519KeyAgreementKeyEIP5630: "", // Authentication and Assertion are not allowed + Bls12381G2Key2020: "BbsBlsSignature2020", } var supportedVerificationMethodTypes []string = func() []string { diff --git a/x/ssi/types/diddoc_validation.go b/x/ssi/types/diddoc_validation.go index 6c1ce5a..3014a84 100644 --- a/x/ssi/types/diddoc_validation.go +++ b/x/ssi/types/diddoc_validation.go @@ -172,8 +172,23 @@ func verificationKeyCheck(vm *VerificationMethod) error { vm.Type, ) } + case Bls12381G2Key2020: + if vm.GetBlockchainAccountId() != "" { + return fmt.Errorf( + "blockchainAccountId is currently not supported for verification method %s as it is of type %s", + vm.Id, + vm.Type, + ) + } + if vm.GetPublicKeyMultibase() == "" { + return fmt.Errorf( + "publicKeyMultibase cannot be empty for verification method %s as it is of type %s", + vm.Id, + vm.Type, + ) + } default: - return fmt.Errorf("unsupported verification method type: %v", supportedVerificationMethodTypes) + return fmt.Errorf("unsupported verification method type: %v. Supported verification method types are: %v", vm.Type, supportedVerificationMethodTypes) } // validate blockchainAccountId @@ -319,7 +334,7 @@ func validateVmRelationships(didDoc *Did) error { if err != nil { return fmt.Errorf("%s: %s", field, err) } - + if _, found := vmTypeMap[vmId]; !found { return fmt.Errorf( "%s: verification method id %s not found in verificationMethod list", @@ -327,11 +342,11 @@ func validateVmRelationships(didDoc *Did) error { vmId, ) } - + // keyAgreement field should harbour only those Verification Methods whose type is either X25519KeyAgreementKey2020 // or X25519KeyAgreementKeyEIP5630 if (vmTypeMap[vmId] == X25519KeyAgreementKey2020) || (vmTypeMap[vmId] == X25519KeyAgreementKeyEIP5630) { - if (field != "keyAgreement") { + if field != "keyAgreement" { return fmt.Errorf( "verification method id %v is of type %v which is not allowed in '%v' attribute", vmId, @@ -340,7 +355,7 @@ func validateVmRelationships(didDoc *Did) error { ) } } else { - if (field == "keyAgreement") { + if field == "keyAgreement" { return fmt.Errorf( "verification method id %v provided in '%v' attribute must be of type X25519KeyAgreementKey2020 or X25519KeyAgreementKeyEIP5630", vmId, diff --git a/x/ssi/verification/crypto.go b/x/ssi/verification/crypto.go index 09c72c7..ea56e7f 100644 --- a/x/ssi/verification/crypto.go +++ b/x/ssi/verification/crypto.go @@ -14,6 +14,9 @@ import ( etheraccounts "github.com/ethereum/go-ethereum/accounts" etherhexutil "github.com/ethereum/go-ethereum/common/hexutil" ethercrypto "github.com/ethereum/go-ethereum/crypto" + + // BBS+ Signatures + bbs "github.com/hyperledger/aries-framework-go/component/kmscrypto/crypto/primitive/bbs12381g2pub" ) func verifyAll(extendedVmList []*types.ExtendedVerificationMethod, ssiMsg types.SsiMsg) error { @@ -57,11 +60,44 @@ func verify(extendedVm *types.ExtendedVerificationMethod, ssiMsg types.SsiMsg) e return verifyX25519KeyAgreementKey2020Key(extendedVm) case types.X25519KeyAgreementKeyEIP5630: return verifyX25519KeyAgreementKeyEIP5630Key(extendedVm) + case types.Bls12381G2Key2020: + return verifyBls12381G2Key2020Key(extendedVm, docBytes) default: return fmt.Errorf("unsupported verification method: %s", extendedVm.Type) } } +// verifyBls12381G2Key2020Key verifies the verification key for verification method type Bls12381G2Key2020 +func verifyBls12381G2Key2020Key(extendedVm *types.ExtendedVerificationMethod, documentBytes []byte) error { + bbsObj := bbs.New() + + // Unlike in tranditional cryptographic algorithms where a message is signed as-is, the message in BBS+ Signature + // scheme is put in an array of byteArray, which is then signed. + // Refer here: https://github.com/hyperledger/aries-framework-go/blob/020b60b288ed8280c8b9ccfe40e31172733aae12/component/kmscrypto/crypto/primitive/bbs12381g2pub/bbs_test.go#L97 + msgFrame := [][]byte{ + documentBytes, + } + + // Decode Signature to Bytes + sigBytes, err := base64.StdEncoding.DecodeString(extendedVm.Signature) + if err != nil { + return err + } + + // Decode Public Key + _, pubKeyBytes, err := multibase.Decode(extendedVm.PublicKeyMultibase) + if err != nil { + return err + } + + // Verify the signature + if err := bbsObj.Verify(msgFrame, sigBytes, pubKeyBytes); err != nil { + return fmt.Errorf("signature could not be verified for verificationMethodId: %v", extendedVm.Id) + } + + return nil +} + // verifyEcdsaSecp256k1RecoveryMethod2020Key verifies the verification key for verification method type EcdsaSecp256k1RecoveryMethod2020 func verifyEcdsaSecp256k1RecoveryMethod2020Key(extendedVm *types.ExtendedVerificationMethod, documentBytes []byte) error { extractedCAIP10Prefix, err := getCAIP10Prefix(extendedVm.BlockchainAccountId)