github.com/hyperledger/aries-framework-go@v0.3.2/pkg/doc/cm/common.go (about) 1 /* 2 Copyright SecureKey Technologies Inc. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package cm 8 9 import "github.com/hyperledger/aries-framework-go/pkg/doc/presexch" 10 11 // hasAnyAlgorithmsOrProofTypes looks at the given Format object and determines if it has any algorithms or proof types 12 // listed. 13 func hasAnyAlgorithmsOrProofTypes(format presexch.Format) bool { 14 if anyJWTTypeHasAlgs(format) || anyLDPTypeHasProofTypes(format) { 15 return true 16 } 17 18 return false 19 } 20 21 func anyJWTTypeHasAlgs(format presexch.Format) bool { 22 if hasAnyAlgs(format.Jwt) || 23 hasAnyAlgs(format.JwtVC) || 24 hasAnyAlgs(format.JwtVP) { 25 return true 26 } 27 28 return false 29 } 30 31 func anyLDPTypeHasProofTypes(format presexch.Format) bool { 32 if hasAnyProofTypes(format.Ldp) || 33 hasAnyProofTypes(format.LdpVC) || 34 hasAnyProofTypes(format.LdpVP) { 35 return true 36 } 37 38 return false 39 } 40 41 func hasAnyAlgs(jwtType *presexch.JwtType) bool { 42 if jwtType != nil && len(jwtType.Alg) > 0 { 43 return true 44 } 45 46 return false 47 } 48 49 func hasAnyProofTypes(ldpType *presexch.LdpType) bool { 50 if ldpType != nil && len(ldpType.ProofType) > 0 { 51 return true 52 } 53 54 return false 55 } 56 57 func lookUpString(model map[string]interface{}, key string) (string, bool) { 58 raw, ok := model[key] 59 if !ok { 60 return "", false 61 } 62 63 val, ok := raw.(string) 64 65 return val, ok 66 } 67 68 func lookUpMap(model map[string]interface{}, key string) (map[string]interface{}, bool) { 69 raw, ok := model[key] 70 if !ok { 71 return nil, false 72 } 73 74 val, ok := raw.(map[string]interface{}) 75 76 return val, ok 77 } 78 79 func lookUpArray(model map[string]interface{}, key string) ([]interface{}, bool) { 80 raw, ok := model[key] 81 if !ok { 82 return nil, false 83 } 84 85 val, ok := raw.([]interface{}) 86 87 return val, ok 88 }