github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/protocol/keybase1/merkle.go (about)

     1  // Auto-generated to Go types and interfaces using avdl-compiler v1.4.10 (https://github.com/keybase/node-avdl-compiler)
     2  //   Input file: avdl/keybase1/merkle.avdl
     3  
     4  package keybase1
     5  
     6  import (
     7  	"github.com/keybase/go-framed-msgpack-rpc/rpc"
     8  	context "golang.org/x/net/context"
     9  	"time"
    10  )
    11  
    12  type MerkleRootAndTime struct {
    13  	Root       MerkleRootV2 `codec:"root" json:"root"`
    14  	UpdateTime Time         `codec:"updateTime" json:"updateTime"`
    15  	FetchTime  Time         `codec:"fetchTime" json:"fetchTime"`
    16  }
    17  
    18  func (o MerkleRootAndTime) DeepCopy() MerkleRootAndTime {
    19  	return MerkleRootAndTime{
    20  		Root:       o.Root.DeepCopy(),
    21  		UpdateTime: o.UpdateTime.DeepCopy(),
    22  		FetchTime:  o.FetchTime.DeepCopy(),
    23  	}
    24  }
    25  
    26  type KBFSRootHash []byte
    27  
    28  func (o KBFSRootHash) DeepCopy() KBFSRootHash {
    29  	return (func(x []byte) []byte {
    30  		if x == nil {
    31  			return nil
    32  		}
    33  		return append([]byte{}, x...)
    34  	})(o)
    35  }
    36  
    37  type KBFSRoot struct {
    38  	TreeID MerkleTreeID `codec:"treeID" json:"treeID"`
    39  	Root   KBFSRootHash `codec:"root" json:"root"`
    40  }
    41  
    42  func (o KBFSRoot) DeepCopy() KBFSRoot {
    43  	return KBFSRoot{
    44  		TreeID: o.TreeID.DeepCopy(),
    45  		Root:   o.Root.DeepCopy(),
    46  	}
    47  }
    48  
    49  type GetCurrentMerkleRootArg struct {
    50  	FreshnessMsec int `codec:"freshnessMsec" json:"freshnessMsec"`
    51  }
    52  
    53  type VerifyMerkleRootAndKBFSArg struct {
    54  	Root             MerkleRootV2 `codec:"root" json:"root"`
    55  	ExpectedKBFSRoot KBFSRoot     `codec:"expectedKBFSRoot" json:"expectedKBFSRoot"`
    56  }
    57  
    58  type MerkleInterface interface {
    59  	// GetCurrentMerkleRoot gets the current-most Merkle root from the keybase server.
    60  	// The caller can specify how stale a result can be with freshnessMsec.
    61  	// If 0 is specified, then any amount of staleness is OK. If -1 is specified, then
    62  	// we force a GET and a round-trip.
    63  	GetCurrentMerkleRoot(context.Context, int) (MerkleRootAndTime, error)
    64  	// VerifyMerkleRootAndKBFS checks that the given merkle root is indeed a valid
    65  	// root of the keybase server's Merkle tree, and that the given KBFS root
    66  	// is included in that global root.
    67  	VerifyMerkleRootAndKBFS(context.Context, VerifyMerkleRootAndKBFSArg) error
    68  }
    69  
    70  func MerkleProtocol(i MerkleInterface) rpc.Protocol {
    71  	return rpc.Protocol{
    72  		Name: "keybase.1.merkle",
    73  		Methods: map[string]rpc.ServeHandlerDescription{
    74  			"getCurrentMerkleRoot": {
    75  				MakeArg: func() interface{} {
    76  					var ret [1]GetCurrentMerkleRootArg
    77  					return &ret
    78  				},
    79  				Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
    80  					typedArgs, ok := args.(*[1]GetCurrentMerkleRootArg)
    81  					if !ok {
    82  						err = rpc.NewTypeError((*[1]GetCurrentMerkleRootArg)(nil), args)
    83  						return
    84  					}
    85  					ret, err = i.GetCurrentMerkleRoot(ctx, typedArgs[0].FreshnessMsec)
    86  					return
    87  				},
    88  			},
    89  			"verifyMerkleRootAndKBFS": {
    90  				MakeArg: func() interface{} {
    91  					var ret [1]VerifyMerkleRootAndKBFSArg
    92  					return &ret
    93  				},
    94  				Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
    95  					typedArgs, ok := args.(*[1]VerifyMerkleRootAndKBFSArg)
    96  					if !ok {
    97  						err = rpc.NewTypeError((*[1]VerifyMerkleRootAndKBFSArg)(nil), args)
    98  						return
    99  					}
   100  					err = i.VerifyMerkleRootAndKBFS(ctx, typedArgs[0])
   101  					return
   102  				},
   103  			},
   104  		},
   105  	}
   106  }
   107  
   108  type MerkleClient struct {
   109  	Cli rpc.GenericClient
   110  }
   111  
   112  // GetCurrentMerkleRoot gets the current-most Merkle root from the keybase server.
   113  // The caller can specify how stale a result can be with freshnessMsec.
   114  // If 0 is specified, then any amount of staleness is OK. If -1 is specified, then
   115  // we force a GET and a round-trip.
   116  func (c MerkleClient) GetCurrentMerkleRoot(ctx context.Context, freshnessMsec int) (res MerkleRootAndTime, err error) {
   117  	__arg := GetCurrentMerkleRootArg{FreshnessMsec: freshnessMsec}
   118  	err = c.Cli.Call(ctx, "keybase.1.merkle.getCurrentMerkleRoot", []interface{}{__arg}, &res, 0*time.Millisecond)
   119  	return
   120  }
   121  
   122  // VerifyMerkleRootAndKBFS checks that the given merkle root is indeed a valid
   123  // root of the keybase server's Merkle tree, and that the given KBFS root
   124  // is included in that global root.
   125  func (c MerkleClient) VerifyMerkleRootAndKBFS(ctx context.Context, __arg VerifyMerkleRootAndKBFSArg) (err error) {
   126  	err = c.Cli.Call(ctx, "keybase.1.merkle.verifyMerkleRootAndKBFS", []interface{}{__arg}, nil, 0*time.Millisecond)
   127  	return
   128  }