// GetVDRPublicKeysFromFile get public keys from file.
GetVDRPublicKeysFromFile get public keys from file.
// GetVDRPublicKeysFromFile get public keys from file .
func GetVDRPublicKeysFromFile(publicKeyFilePath string) (*docdid.Doc, error) { 
	pkData, err := ioutil.ReadFile(filepath.Clean(publicKeyFilePath))
	if err != nil {
		return nil, fmt.Errorf("failed to public key file '%s' : %w", publicKeyFilePath, err)
	}
	var publicKeys []PublicKey
	if err := json.Unmarshal(pkData, &publicKeys); err != nil {
		return nil, err
	}
	didDoc := &docdid.Doc{}
	for _, v := range publicKeys {
		if (v.JWKPath == "") == (v.B58Key == "") {
			return nil, fmt.Errorf("public key needs exactly one of jwkPath and b58Key")
		}
		var vm *docdid.VerificationMethod
		if v.JWKPath != "" {
			jwkData, err := ioutil.ReadFile(filepath.Clean(v.JWKPath))
			if err != nil {
				return nil, fmt.Errorf("failed to read jwk file '%s' : %w", v.JWKPath, err)
			}
			var jwk jwk2.JWK
			if errUnmarshal := jwk.UnmarshalJSON(jwkData); errUnmarshal != nil {
				return nil, fmt.Errorf("failed to unmarshal to jwk: %w", errUnmarshal)
			}
			vm, err = docdid.NewVerificationMethodFromJWK(v.ID, v.Type, "", &jwk)
			if err != nil {
				return nil, err
			}
		} else if v.B58Key != "" {
			vm = docdid.NewVerificationMethodFromBytes(v.ID, v.Type, "", base58.Decode(v.B58Key))
		}
		for _, p := range v.Purposes {
			switch p {
			case doc.KeyPurposeAuthentication:
				didDoc.Authentication = append(didDoc.Authentication,
					*docdid.NewReferencedVerification(vm, docdid.Authentication))
			case doc.KeyPurposeAssertionMethod:
				didDoc.AssertionMethod = append(didDoc.AssertionMethod,
					*docdid.NewReferencedVerification(vm, docdid.AssertionMethod))
			case doc.KeyPurposeKeyAgreement:
				didDoc.KeyAgreement = append(didDoc.KeyAgreement,
					*docdid.NewReferencedVerification(vm, docdid.KeyAgreement))
			case doc.KeyPurposeCapabilityDelegation:
				didDoc.CapabilityInvocation = append(didDoc.CapabilityInvocation,
					*docdid.NewReferencedVerification(vm, docdid.CapabilityDelegation))
			case doc.KeyPurposeCapabilityInvocation:
				didDoc.CapabilityDelegation = append(didDoc.CapabilityDelegation,
					*docdid.NewReferencedVerification(vm, docdid.CapabilityInvocation))
			default:
				return nil, fmt.Errorf("public key purpose %s not supported", p)
			}
		}
	}
	return didDoc, nil
}
func GetVDRPublicKeysFromFile ( publicKeyFilePath string ) ( * docdid . Doc , error ) { pkData , err := ioutil . ReadFile ( filepath . Clean ( publicKeyFilePath ) ) if err != nil { return nil , fmt . Errorf ( " " , publicKeyFilePath , err ) } var publicKeys [ ] PublicKey if err := json . Unmarshal ( pkData , & publicKeys ) ; err != nil { return nil , err } didDoc := & docdid . Doc { } for _ , v := range publicKeys { if ( v . JWKPath == " " ) == ( v . B58Key == " " ) { return nil , fmt . Errorf ( " " ) } var vm * docdid . VerificationMethod if v . JWKPath != " " { jwkData , err := ioutil . ReadFile ( filepath . Clean ( v . JWKPath ) ) if err != nil { return nil , fmt . Errorf ( " " , v . JWKPath , err ) } var jwk jwk2 . JWK if errUnmarshal := jwk . UnmarshalJSON ( jwkData ) ; errUnmarshal != nil { return nil , fmt . Errorf ( " " , errUnmarshal ) } vm , err = docdid . NewVerificationMethodFromJWK ( v . ID , v . Type , " " , & jwk ) if err != nil { return nil , err } } else if v . B58Key != " " { vm = docdid . NewVerificationMethodFromBytes ( v . ID , v . Type , " " , base58 . Decode ( v . B58Key ) ) } for _ , p := range v . Purposes { switch p { case doc . KeyPurposeAuthentication : didDoc . Authentication = append ( didDoc . Authentication , * docdid . NewReferencedVerification ( vm , docdid . Authentication ) ) case doc . KeyPurposeAssertionMethod : didDoc . AssertionMethod = append ( didDoc . AssertionMethod , * docdid . NewReferencedVerification ( vm , docdid . AssertionMethod ) ) case doc . KeyPurposeKeyAgreement : didDoc . KeyAgreement = append ( didDoc . KeyAgreement , * docdid . NewReferencedVerification ( vm , docdid . KeyAgreement ) ) case doc . KeyPurposeCapabilityDelegation : didDoc . CapabilityInvocation = append ( didDoc . CapabilityInvocation , * docdid . NewReferencedVerification ( vm , docdid . CapabilityDelegation ) ) case doc . KeyPurposeCapabilityInvocation : didDoc . CapabilityDelegation = append ( didDoc . CapabilityDelegation , * docdid . NewReferencedVerification ( vm , docdid . CapabilityInvocation ) ) default : return nil , fmt . Errorf ( " " , p ) } } } return didDoc , nil }
GetVDRPublicKeysFromFile get public keys from file.
GetVDRPublicKeysFromFile get public keys from file .
//nolint:gocyclo,cyclop,funlen