github.com/hyperledger/aries-framework-go@v0.3.2/pkg/internal/ursautil/utils.go (about)

     1  //go:build ursa
     2  // +build ursa
     3  
     4  /*
     5  Copyright Avast Software. All Rights Reserved.
     6  
     7  SPDX-License-Identifier: Apache-2.0
     8  */
     9  
    10  package ursautil
    11  
    12  import (
    13  	"github.com/hyperledger/ursa-wrapper-go/pkg/libursa/ursa"
    14  )
    15  
    16  // BuildSchema is used for building a schema and a non-schema for a CredDef.
    17  func BuildSchema(attrs []string) (*ursa.CredentialSchemaHandle, *ursa.NonCredentialSchemaHandle, error) {
    18  	schemaBuilder, err := ursa.NewCredentialSchemaBuilder()
    19  	if err != nil {
    20  		return nil, nil, err
    21  	}
    22  
    23  	for _, attr := range attrs {
    24  		err = schemaBuilder.AddAttr(attr)
    25  		if err != nil {
    26  			return nil, nil, err
    27  		}
    28  	}
    29  
    30  	schema, err := schemaBuilder.Finalize()
    31  	if err != nil {
    32  		return nil, nil, err
    33  	}
    34  
    35  	nonSchemaBuilder, err := ursa.NewNonCredentialSchemaBuilder()
    36  	if err != nil {
    37  		return nil, nil, err
    38  	}
    39  
    40  	err = nonSchemaBuilder.AddAttr("master_secret")
    41  	if err != nil {
    42  		return nil, nil, err
    43  	}
    44  
    45  	nonSchema, err := nonSchemaBuilder.Finalize()
    46  	if err != nil {
    47  		return nil, nil, err
    48  	}
    49  
    50  	return schema, nonSchema, nil
    51  }
    52  
    53  // BuildValues is used for building blinded values.
    54  func BuildValues(values map[string]interface{}, masterSecretStr *string) (*ursa.CredentialValues, error) {
    55  	valuesBuilder, err := ursa.NewValueBuilder()
    56  	if err != nil {
    57  		return nil, err
    58  	}
    59  
    60  	if masterSecretStr != nil {
    61  		err = valuesBuilder.AddDecHidden("master_secret", *masterSecretStr)
    62  		if err != nil {
    63  			return nil, err
    64  		}
    65  	}
    66  
    67  	for k, v := range values {
    68  		_, enc := ursa.EncodeValue(v)
    69  
    70  		err = valuesBuilder.AddDecKnown(k, enc)
    71  		if err != nil {
    72  			return nil, err
    73  		}
    74  	}
    75  
    76  	credentialValues, err := valuesBuilder.Finalize()
    77  	if err != nil {
    78  		return nil, err
    79  	}
    80  
    81  	return credentialValues, nil
    82  }