github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/service/merkle.go (about)

     1  // Copyright 2017 Keybase, Inc. All rights reserved. Use of
     2  // this source code is governed by the included BSD license.
     3  
     4  package service
     5  
     6  import (
     7  	libkb "github.com/keybase/client/go/libkb"
     8  	keybase1 "github.com/keybase/client/go/protocol/keybase1"
     9  	rpc "github.com/keybase/go-framed-msgpack-rpc/rpc"
    10  	context "golang.org/x/net/context"
    11  	"time"
    12  )
    13  
    14  type MerkleHandler struct {
    15  	*BaseHandler
    16  	libkb.Contextified
    17  }
    18  
    19  func newMerkleHandler(xp rpc.Transporter, g *libkb.GlobalContext) *MerkleHandler {
    20  	return &MerkleHandler{
    21  		BaseHandler:  NewBaseHandler(g, xp),
    22  		Contextified: libkb.NewContextified(g),
    23  	}
    24  }
    25  
    26  func (h *MerkleHandler) GetCurrentMerkleRoot(ctx context.Context, freshnessMsec int) (ret keybase1.MerkleRootAndTime, err error) {
    27  	obj, err := h.G().MerkleClient.FetchRootFromServer(h.MetaContext(ctx), time.Duration(freshnessMsec)*time.Millisecond)
    28  	if err != nil {
    29  		return ret, err
    30  	}
    31  	return obj.ExportToAVDL(h.G()), nil
    32  }
    33  
    34  func (h *MerkleHandler) VerifyMerkleRootAndKBFS(ctx context.Context, arg keybase1.VerifyMerkleRootAndKBFSArg) (err error) {
    35  	m := libkb.NewMetaContext(ctx, h.G())
    36  	m = m.WithLogTag("MRKL")
    37  	defer m.Trace("MerkleHandler#VerifyMerkleRootAndKBFS", &err)()
    38  	err = libkb.VerifyMerkleRootAndKBFS(m, arg)
    39  	return err
    40  }