github.com/vchain-us/vcn@v0.9.11-0.20210921212052-a2484d23c0b3/pkg/api/sign_options.go (about)

     1  /*
     2   * Copyright (c) 2018-2020 vChain, Inc. All Rights Reserved.
     3   * This software is released under GPL3.
     4   * The full license information can be found under:
     5   * https://www.gnu.org/licenses/gpl-3.0.en.html
     6   *
     7   */
     8  
     9  package api
    10  
    11  import (
    12  	"github.com/vchain-us/vcn/pkg/meta"
    13  )
    14  
    15  // SignOption is a functional option for signing operations
    16  type SignOption func(*signOpts) error
    17  
    18  type signOpts struct {
    19  	status     meta.Status
    20  	visibility meta.Visibility
    21  	keyin      string
    22  	passphrase string
    23  }
    24  
    25  func makeSignOpts(opts ...SignOption) (o *signOpts, err error) {
    26  	o = &signOpts{
    27  		status:     meta.StatusTrusted,
    28  		visibility: meta.VisibilityPrivate,
    29  	}
    30  
    31  	for _, option := range opts {
    32  		if option == nil {
    33  			continue
    34  		}
    35  		if err := option(o); err != nil {
    36  			return nil, err
    37  		}
    38  	}
    39  
    40  	return
    41  }
    42  
    43  // SignWithStatus returns the functional option for the given status.
    44  func SignWithStatus(status meta.Status) SignOption {
    45  	return func(o *signOpts) error {
    46  		o.status = status
    47  		return nil
    48  	}
    49  }
    50  
    51  // SignWithVisibility returns the functional option for the given visibility.
    52  func SignWithVisibility(visibility meta.Visibility) SignOption {
    53  	return func(o *signOpts) error {
    54  		o.visibility = visibility
    55  		return nil
    56  	}
    57  }
    58  
    59  // SignWithKey returns the functional option for the given keyin and passphrase.
    60  func SignWithKey(keyin, passphrase string) SignOption {
    61  	return func(o *signOpts) error {
    62  		o.keyin = keyin
    63  		o.passphrase = passphrase
    64  		return nil
    65  	}
    66  }