lotus/api/utils.go

29 lines
668 B
Go
Raw Permalink Normal View History

package api
import (
"context"
"github.com/filecoin-project/go-address"
2020-09-07 03:49:10 +00:00
"github.com/filecoin-project/go-state-types/crypto"
)
2020-02-25 21:09:22 +00:00
type SignFunc = func(context.Context, []byte) (*crypto.Signature, error)
2020-02-25 21:09:22 +00:00
type Signer func(context.Context, address.Address, []byte) (*crypto.Signature, error)
type Signable interface {
Sign(context.Context, SignFunc) error
}
func SignWith(ctx context.Context, signer Signer, addr address.Address, signable ...Signable) error {
for _, s := range signable {
2020-02-25 21:09:22 +00:00
err := s.Sign(ctx, func(ctx context.Context, b []byte) (*crypto.Signature, error) {
return signer(ctx, addr, b)
})
if err != nil {
return err
}
}
2019-10-22 10:09:36 +00:00
return nil
}