github.com/hyperledger/aries-framework-go@v0.3.2/pkg/doc/verifiable/credential_bbs.go (about)

     1  /*
     2  Copyright SecureKey Technologies Inc. All Rights Reserved.
     3  SPDX-License-Identifier: Apache-2.0
     4  */
     5  
     6  package verifiable
     7  
     8  import (
     9  	"encoding/json"
    10  	"errors"
    11  	"fmt"
    12  
    13  	"github.com/hyperledger/aries-framework-go/pkg/doc/signature/suite/bbsblssignatureproof2020"
    14  	jsonutil "github.com/hyperledger/aries-framework-go/pkg/doc/util/json"
    15  )
    16  
    17  // GenerateBBSSelectiveDisclosure generate BBS+ selective disclosure from one BBS+ signature.
    18  func (vc *Credential) GenerateBBSSelectiveDisclosure(revealDoc map[string]interface{},
    19  	nonce []byte, opts ...CredentialOpt) (*Credential, error) {
    20  	if len(vc.Proofs) == 0 {
    21  		return nil, errors.New("expected at least one proof present")
    22  	}
    23  
    24  	vcOpts := getCredentialOpts(opts)
    25  	jsonldProcessorOpts := mapJSONLDProcessorOpts(&vcOpts.jsonldCredentialOpts)
    26  
    27  	if vcOpts.publicKeyFetcher == nil {
    28  		return nil, errors.New("public key fetcher is not defined")
    29  	}
    30  
    31  	suite := bbsblssignatureproof2020.New()
    32  
    33  	vcDoc, err := jsonutil.ToMap(vc)
    34  	if err != nil {
    35  		return nil, err
    36  	}
    37  
    38  	keyResolver := &keyResolverAdapter{vcOpts.publicKeyFetcher}
    39  
    40  	vcWithSelectiveDisclosureDoc, err := suite.SelectiveDisclosure(vcDoc, revealDoc, nonce,
    41  		keyResolver, jsonldProcessorOpts...)
    42  	if err != nil {
    43  		return nil, fmt.Errorf("create VC selective disclosure: %w", err)
    44  	}
    45  
    46  	vcWithSelectiveDisclosureBytes, err := json.Marshal(vcWithSelectiveDisclosureDoc)
    47  	if err != nil {
    48  		return nil, err
    49  	}
    50  
    51  	opts = append(opts, WithDisabledProofCheck())
    52  
    53  	return ParseCredential(vcWithSelectiveDisclosureBytes, opts...)
    54  }