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

     1  /*
     2  Copyright SecureKey Technologies Inc. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package jsonld
     8  
     9  import (
    10  	"github.com/piprate/json-gold/ld"
    11  
    12  	"github.com/hyperledger/aries-framework-go/component/models/ld/processor"
    13  )
    14  
    15  // ErrInvalidRDFFound is returned when normalized view contains invalid RDF.
    16  var ErrInvalidRDFFound = processor.ErrInvalidRDFFound
    17  
    18  // ProcessorOpts are the options for JSON LD operations on docs (like canonicalization or compacting).
    19  type ProcessorOpts = processor.Opts
    20  
    21  // WithRemoveAllInvalidRDF option for removing all invalid RDF dataset from normalize document.
    22  func WithRemoveAllInvalidRDF() ProcessorOpts {
    23  	return processor.WithRemoveAllInvalidRDF()
    24  }
    25  
    26  // WithFrameBlankNodes option for transforming blank node identifiers into nodes.
    27  // For example, _:c14n0 is transformed into <urn:bnid:_:c14n0>.
    28  func WithFrameBlankNodes() ProcessorOpts {
    29  	return processor.WithFrameBlankNodes()
    30  }
    31  
    32  // WithDocumentLoader option is for passing custom JSON-LD document loader.
    33  func WithDocumentLoader(loader ld.DocumentLoader) ProcessorOpts {
    34  	return processor.WithDocumentLoader(loader)
    35  }
    36  
    37  // WithExternalContext option is for definition of external context when doing JSON-LD operations.
    38  func WithExternalContext(context ...string) ProcessorOpts {
    39  	return processor.WithExternalContext(context...)
    40  }
    41  
    42  // WithValidateRDF option validates result view and fails if any invalid RDF dataset found.
    43  // This option will take precedence when used in conjunction with 'WithRemoveAllInvalidRDF' option.
    44  func WithValidateRDF() ProcessorOpts {
    45  	return processor.WithValidateRDF()
    46  }
    47  
    48  // Processor is JSON-LD processor for aries.
    49  // processing mode JSON-LD 1.0 {RFC: https://www.w3.org/TR/2014/REC-json-ld-20140116}
    50  type Processor = processor.Processor
    51  
    52  // NewProcessor returns new JSON-LD processor for aries.
    53  func NewProcessor(algorithm string) *Processor {
    54  	return processor.NewProcessor(algorithm)
    55  }
    56  
    57  // Default returns new JSON-LD processor with default RDF dataset algorithm.
    58  func Default() *Processor {
    59  	return processor.Default()
    60  }
    61  
    62  // AppendExternalContexts appends external context(s) to the JSON-LD context which can have one
    63  // or several contexts already.
    64  func AppendExternalContexts(context interface{}, extraContexts ...string) []interface{} {
    65  	return processor.AppendExternalContexts(context, extraContexts...)
    66  }
    67  
    68  // TransformBlankNode replaces blank node identifiers in the RDF statements.
    69  // For example, transform from "_:c14n0" to "urn:bnid:_:c14n0".
    70  func TransformBlankNode(row string) string {
    71  	return processor.TransformBlankNode(row)
    72  }