github.com/voedger/voedger@v0.0.0-20240520144910-273e84102129/pkg/itokens/interface.go (about)

     1  /*
     2   * Copyright (c) 2021-present unTill Pro, Ltd.
     3   * @author Maxim Geraskin
     4   *
     5   */
     6  
     7  package itokens
     8  
     9  import (
    10  	"time"
    11  
    12  	"github.com/voedger/voedger/pkg/istructs"
    13  )
    14  
    15  type ITokens interface {
    16  
    17  	// Payload must be sent by reference
    18  	// All payload fields go to token payload
    19  	// Audience = payload.Type.package + payload.Type.Name
    20  	IssueToken(app istructs.AppQName, duration time.Duration, pointerToPayload interface{}) (token string, err error)
    21  
    22  	// Payload must be sent by reference
    23  	// payload MUST be a pointer to the struct of the type used in IssueToken (checked using Audience)
    24  	// Token is verified and its data is copied to *pointerToPayload
    25  	// ErrTokenExpired, ErrInvalidToken, ErrInvalidAudience might be returned
    26  	ValidateToken(token string, pointerToPayload interface{}) (gp istructs.GenericPayload, err error)
    27  
    28  	// CryptoHash256 must be a cryptographic hash function which produces a 256-bits hash
    29  	// Ref. https://en.wikipedia.org/wiki/Cryptographic_hash_function
    30  	// Ref. https://pkg.go.dev/crypto/sha256
    31  	CryptoHash256(data []byte) (hash [32]byte)
    32  }