{"modulePath":"github.com/data-preservation-programs/singularity","version":"v1.0.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package util\n\n## Constants\n\n```go\nconst BatchSize = 100\n```\n\n## Variables\n\n```go\nvar ErrNotImplemented = errors.New(\"not implemented\")\n```\n\n## Functions\n\n```go\nfunc ChunkSlice[T any](slice []T, chunkSize int) [][]T\n```\nChunkSlice is a generic function that takes a slice of any type and an integer as input. It divides the input slice into packJobs of size 'chunkSize' and returns a 2D slice. If 'chunkSize' is less than or equal to zero, it returns an empty 2D slice.\n\nParameters:\n\n  - slice: A slice of any type that needs to be chunked.\n  - chunkSize: The size of each packJob. Must be a positive integer.\n\nReturns:\n\n  - A 2D slice where each inner slice is of length 'chunkSize'. The last inner slice may be shorter if the length of 'slice' is not a multiple of 'chunkSize'.\n\n```go\nfunc GenerateCarHeader(root cid.Cid) ([]byte, error)\n```\nGenerateCarHeader generates the CAR (Content Addressable aRchive) format header based on the given root CID (Content Identifier).\n\nParameters:\n\n  - root: The root CID of the MerkleDag that the CAR file represents.\n\nReturns:\n\n  - \\[]byte: The byte representation of the CAR header.\n  - error: An error that can occur during the header generation process, or nil if successful.\n\n```go\nfunc GenerateNewPeer() ([]byte, []byte, peer.ID, error)\n```\nGenerateNewPeer is a function that generates a new peer for the IPFS network. It generates a new Ed25519 key pair using a secure random source and derives a peer ID from the public key. It then marshals the private and public keys into byte slices.\n\nReturns:\n\n\tThe private key as a byte slice, the public key as a byte slice, the peer ID, and an error if the operation failed.\n\tIf any of the operations (key generation, peer ID derivation, key marshalling) fail, it returns an error wrapped with a descriptive message.\n\n```go\nfunc GetLotusHeadTime(ctx context.Context, lotusAPI string, lotusToken string) (time.Time, error)\n```\nGetLotusHeadTime retrieves the timestamp of the latest block in the Lotus API and returns it as a time.Time value.\n\n```go\nfunc InitHost(opts []libp2p.Option, listenAddrs ...multiaddr.Multiaddr) (host.Host, error)\n```\nInitHost initializes a new libp2p host with the provided options and listen addresses.\n\nParameters:\n\n  - opts: A slice of libp2p options to configure the host.\n  - listenAddrs: A variadic list of multiaddresses for the host to listen on.\n\nReturns:\n\n 1. A libp2p host instance that represents the initialized host.\n 2. An error, which will be non-nil if any error occurred during host initialization.\n\n```go\nfunc IsAcceptedPieceCID(pieceCID cid.Cid) bool\n```\nIsAcceptedPieceCID returns true for legacy CommP CIDs and CommPv2 CIDs.\n\n```go\nfunc IsAllDigits(s string) bool\n```\nIsAllDigits is a function that checks if a string contains only digits.\n\n```go\nfunc IsDuplicateKeyError(err error) bool\n```\n\n```go\nfunc IsPowerOfTwo(x uint64) bool\n```\nIsPowerOfTwo returns true if x is a power of two.\n\n```go\nfunc NewLotusClient(lotusAPI string, lotusToken string) jsonrpc.RPCClient\n```\nNewLotusClient is a function that creates a new JSON-RPC client for interacting with a Lotus node. It takes the Lotus API endpoint and an optional Lotus token as input. If the Lotus token is provided, it is included in the 'Authorization' header of the JSON-RPC requests.\n\nParameters:\n\n  - lotusAPI: The Lotus API endpoint. Must be a valid URL.\n  - lotusToken: An optional Lotus token. If provided, it is included in the 'Authorization' header of the JSON-RPC requests.\n\nReturns:\n\n\tA JSON-RPC client configured to interact with the specified Lotus node. If a Lotus token is provided, the client includes it in the 'Authorization' header of its requests.\n\n```go\nfunc NextPowerOfTwo(x uint64) uint64\n```\nNextPowerOfTwo calculates the smallest power of two that is greater than or equal to x. If x is already a power of two, it returns x. For x equal to 0, the result is 1.\n\nParameters:\n\n  - x: The input value for which the next power of two needs to be calculated.\n\nReturns: The smallest power of two that is greater than or equal to x.\n\n```go\nfunc RandomName() string\n```\n\n## Types\n\n```go\ntype AggregateError struct {\n\tErrors []error\n}\n```\n\n```go\nfunc (a AggregateError) As(err interface{}) bool\n```\n\n```go\nfunc (a AggregateError) Error() string\n```\n\n```go\nfunc (a AggregateError) Format(s fmt.State, verb rune)\n```\n\n```go\nfunc (a AggregateError) Is(err error) bool\n```\n\n```go\nfunc (a AggregateError) Unwrap() error\n```\n\n","path":"github.com/data-preservation-programs/singularity/util","name":"util","synopsis":"","isRedistributable":true}
