github.com/trustbloc/kms-go@v1.1.2/wrapper/websuite/websuite.go (about) 1 /* 2 Copyright Gen Digital Inc. All Rights Reserved. 3 SPDX-License-Identifier: Apache-2.0 4 */ 5 6 // Package websuite provides a wrapper.Suite implemented using web kms and web crypto clients. 7 package websuite 8 9 import ( 10 "net/http" 11 12 webcrypto "github.com/trustbloc/kms-go/crypto/webkms" 13 "github.com/trustbloc/kms-go/doc/jose/jwk" 14 "github.com/trustbloc/kms-go/kms/webkms" 15 wrapperapi "github.com/trustbloc/kms-go/wrapper/api" 16 ) 17 18 // NewWebCryptoSuite initializes an api.Suite using web kms and crypto 19 // clients, supporting all Suite APIs. 20 func NewWebCryptoSuite(endpoint string, httpClient *http.Client) wrapperapi.Suite { 21 km := webkms.New(endpoint, httpClient) 22 cr := webcrypto.New(endpoint, httpClient) 23 24 return &suite{ 25 km: km, 26 cr: cr, 27 } 28 } 29 30 type suite struct { 31 km *webkms.RemoteKMS 32 cr *webcrypto.RemoteCrypto 33 } 34 35 func (s *suite) KMSCryptoVerifier() (wrapperapi.KMSCryptoVerifier, error) { 36 return &kmsCrypto{ 37 km: s.km, 38 cr: s.cr, 39 }, nil 40 } 41 42 func (s *suite) KeyCreator() (wrapperapi.KeyCreator, error) { 43 return &kmsCrypto{ 44 km: s.km, 45 cr: s.cr, 46 }, nil 47 } 48 49 func (s *suite) KMSCrypto() (wrapperapi.KMSCrypto, error) { 50 return &kmsCrypto{ 51 km: s.km, 52 cr: s.cr, 53 }, nil 54 } 55 56 func (s *suite) FixedKeyCrypto(pub *jwk.JWK) (wrapperapi.FixedKeyCrypto, error) { 57 return makeFixedKey(pub.KeyID, s.km, s.cr) 58 } 59 60 func (s *suite) RawKeyCreator() (wrapperapi.RawKeyCreator, error) { 61 return &kmsCrypto{ 62 km: s.km, 63 cr: s.cr, 64 }, nil 65 } 66 67 func (s *suite) KMSCryptoSigner() (wrapperapi.KMSCryptoSigner, error) { 68 return &kmsCrypto{ 69 km: s.km, 70 cr: s.cr, 71 }, nil 72 } 73 74 func (s *suite) FixedKeySigner(kid string) (wrapperapi.FixedKeySigner, error) { 75 return makeFixedKey(kid, s.km, s.cr) 76 } 77 78 func (s *suite) KMSCryptoMultiSigner() (wrapperapi.KMSCryptoMultiSigner, error) { 79 return &kmsCrypto{ 80 km: s.km, 81 cr: s.cr, 82 }, nil 83 } 84 85 func (s *suite) FixedKeyMultiSigner(kid string) (wrapperapi.FixedKeyMultiSigner, error) { 86 return makeFixedKey(kid, s.km, s.cr) 87 } 88 89 func (s *suite) EncrypterDecrypter() (wrapperapi.EncrypterDecrypter, error) { 90 return &kmsCrypto{ 91 km: s.km, 92 cr: s.cr, 93 }, nil 94 }