proofsvc

package
v1.27.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 10, 2025 License: Apache-2.0, MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const AddressCacheSize = 1000
View Source
const AddressCacheTTL = 5 * time.Minute
View Source
const NonceExpiry = 60 * time.Second
View Source
const SkewAllowance = 5 * time.Second

Variables

View Source
var MaxRetryTime = 30 * time.Minute

Functions

func CheckAvailability

func CheckAvailability() (bool, error)

func CreateWorkAsk

func CreateWorkAsk(ctx context.Context, resolver *AddressResolver, signer address.Address, price abi.TokenAmount) (int64, error)

func GetProof

func GetProof(cid cid.Cid) ([]byte, error)

func GetProofStatus

func GetProofStatus(ctx context.Context, requestCid cid.Cid) (common.ProofResponse, error)

GetProofStatus checks the status of a proof request by ID

func PollWork

func PollWork(address string) (common.WorkResponse, error)

func RequestProof

func RequestProof(request common.ProofRequest) (bool, error)

RequestProof submits a proof request to the service

func RespondWork

func RespondWork(ctx context.Context, resolver *AddressResolver, address address.Address, rcid string, proof []byte) (common.ProofReward, bool, error)

func Sign

func Sign(ctx context.Context, resolver *AddressResolver, signer address.Address, dst string, data []byte, nonceTime time.Time) (string, error)

Sign creates a signature for the given data using the provided wallet API and returns it as hex

func TokenAmountFromNfil

func TokenAmountFromNfil(nfil NFilAmount) abi.TokenAmount

TokenAmountFromNfil converts a nanoFIL (nFIL) amount to attoFIL.

func UploadProofData

func UploadProofData(ctx context.Context, proofData []byte) (cid.Cid, error)

UploadProofData uploads proof data to the service and returns the CID

func Verify

func Verify(ctx context.Context, resolver *AddressResolver, nonceCache *NonceCache, signer address.Address, data []byte, sig *Signature) (bool, error)

Verify verifies a signature against the given data using the provided resolver and nonce cache

func VerifyHexSig

func VerifyHexSig(ctx context.Context, resolver *AddressResolver, nonceCache *NonceCache, signer address.Address, dst string, data []byte, hexSig string) error

VerifyHexSig deserializes a hex-encoded signature and verifies it

func WaitForProof

func WaitForProof(request common.ProofRequest) ([]byte, error)

WaitForProof submits a proof request and waits for the result

func WithdrawAsk

func WithdrawAsk(ctx context.Context, resolver *AddressResolver, signer address.Address, askID int64) error

Types

type AddressCacheEntry

type AddressCacheEntry struct {
	AccountKey address.Address
	ExpiresAt  time.Time
}

AddressCacheEntry holds cached address resolution with TTL

type AddressResolver

type AddressResolver struct {
	// contains filtered or unexported fields
}

AddressResolver provides cached StateAccountKey lookups

func NewAddressResolver

func NewAddressResolver(wallet WalletAPI) (*AddressResolver, error)

NewAddressResolver creates a new cached address resolver

func (*AddressResolver) ResolveAccountKey

func (ar *AddressResolver) ResolveAccountKey(ctx context.Context, addr address.Address) (address.Address, error)

ResolveAccountKey resolves an address to its account key with caching

type ClientPaymentStatus

type ClientPaymentStatus struct {
	Found                bool   `json:"found"`
	Nonce                int64  `json:"nonce"`
	CumulativeAmountNFil int64  `json:"cumulative_amount_nfil"`
	AmountNFil           int64  `json:"amount_nfil"`
	Signature            []byte `json:"signature"`
	CreatedAt            string `json:"created_at"`
}

ClientPaymentStatus represents the payment status for a client wallet as returned by the backend /client/payment/status/{wallet-id} endpoint.

func GetClientPaymentStatus

func GetClientPaymentStatus(walletID abi.ActorID) (*ClientPaymentStatus, error)

GetClientPaymentStatus retrieves the latest payment status for a given wallet ID.

type NFilAmount

type NFilAmount = int64

func NfilFromTokenAmount

func NfilFromTokenAmount(tokenAmount abi.TokenAmount) (NFilAmount, error)

NfilFromTokenAmount converts a token amount in attoFIL to nanoFIL (nFIL). It returns an error if the token amount is not divisible by 1 nFIL.

type NonceCache

type NonceCache struct {
	// contains filtered or unexported fields
}

NonceCache provides thread-safe replay protection using rotating time buckets

func NewNonceCache

func NewNonceCache() *NonceCache

NewNonceCache creates a new NonceCache instance

func (*NonceCache) AddNonce

func (nc *NonceCache) AddNonce(accountKey address.Address, nonceID uint64, nonceTime time.Time) bool

AddNonce adds a nonce to the current time bucket, returns false if already exists or invalid

type NonceKey

type NonceKey struct {
	AccountKey string // canonical account key string for consistent hashing
	NonceID    uint64
}

NonceKey represents a unique combination of account key and nonce ID

type PriceResponse

type PriceResponse struct {
	Price               int64 `json:"price_nfil"`
	PriceNfilBase       int64 `json:"price_nfil_base"`
	PriceNfilServiceFee int64 `json:"price_nfil_service_fee"`
	FeeNum              int64 `json:"fee_num"`
	FeeDenom            int64 `json:"fee_denom"`
	Epoch               int64 `json:"epoch"`
}

func GetCurrentPrice

func GetCurrentPrice() (PriceResponse, error)

GetCurrentPrice retrieves the current price for proof generation from the service

type Signature

type Signature struct {
	NonceTime uint64 // unix timestamp
	NonceID   uint64
	Sig       []byte
}

func (*Signature) MarshalCBOR

func (t *Signature) MarshalCBOR(w io.Writer) error

func (*Signature) UnmarshalCBOR

func (t *Signature) UnmarshalCBOR(r io.Reader) (err error)

type SignedMsg

type SignedMsg struct {
	Data []byte

	Signer address.Address
	Sig    Signature
}

SignedMsg is the signed payload, Sig.Sig = nil for signing bytes

func (*SignedMsg) MarshalCBOR

func (t *SignedMsg) MarshalCBOR(w io.Writer) error

func (*SignedMsg) SigningBytes

func (s *SignedMsg) SigningBytes() []byte

func (*SignedMsg) UnmarshalCBOR

func (t *SignedMsg) UnmarshalCBOR(r io.Reader) (err error)

type Tos

type Tos struct {
	Provider string `json:"provider"`
	Client   string `json:"client"`
}

func GetTos

func GetTos() Tos

type WalletAPI

type WalletAPI interface {
	StateAccountKey(context.Context, address.Address, types.TipSetKey) (address.Address, error)
	WalletSign(context.Context, address.Address, []byte) (*crypto.Signature, error)
	WalletVerify(context.Context, address.Address, []byte, *crypto.Signature) (bool, error)
}

WalletAPI defines the interface for wallet operations

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL