github.com/hyperledger/aries-framework-go@v0.3.2/pkg/doc/jose/jwk/jwksupport/jwk.go (about) 1 /* 2 Copyright SecureKey Technologies Inc. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package jwksupport 8 9 import ( 10 "github.com/hyperledger/aries-framework-go/component/kmscrypto/doc/jose/jwk" 11 "github.com/hyperledger/aries-framework-go/component/kmscrypto/doc/jose/jwk/jwksupport" 12 "github.com/hyperledger/aries-framework-go/spi/crypto" 13 "github.com/hyperledger/aries-framework-go/spi/kms" 14 ) 15 16 // JWKFromKey creates a JWK from an opaque key struct. 17 // It's e.g. *ecdsa.PublicKey, *ecdsa.PrivateKey, ed25519.VerificationMethod, *bbs12381g2pub.PrivateKey or 18 // *bbs12381g2pub.PublicKey. 19 func JWKFromKey(opaqueKey interface{}) (*jwk.JWK, error) { 20 return jwksupport.JWKFromKey(opaqueKey) 21 } 22 23 // JWKFromX25519Key is similar to JWKFromKey but is specific to X25519 keys when using a public key as raw []byte. 24 // This builder function presets the curve and key type in the JWK. 25 // Using JWKFromKey for X25519 raw keys will not have these fields set and will not provide the right JWK output. 26 func JWKFromX25519Key(pubKey []byte) (*jwk.JWK, error) { 27 return jwksupport.JWKFromX25519Key(pubKey) 28 } 29 30 // PubKeyBytesToJWK converts marshalled bytes of keyType into JWK. 31 func PubKeyBytesToJWK(bytes []byte, keyType kms.KeyType) (*jwk.JWK, error) { // nolint:gocyclo 32 return jwksupport.PubKeyBytesToJWK(bytes, keyType) 33 } 34 35 // PublicKeyFromJWK builds a crypto.PublicKey from jwkKey. 36 func PublicKeyFromJWK(jwkKey *jwk.JWK) (*crypto.PublicKey, error) { 37 return jwksupport.PublicKeyFromJWK(jwkKey) 38 }