Skip to content

Commit

Permalink
feat(blob): add blob structure
Browse files Browse the repository at this point in the history
  • Loading branch information
vgonkivs committed Apr 5, 2023
1 parent 18cb0c0 commit b1902af
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions blob/blob.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package blob

import (
"github.com/celestiaorg/celestia-app/x/blob/types"
"github.com/celestiaorg/nmt"
"github.com/celestiaorg/nmt/namespace"
)

// Commitment is a Merkle Root of the subtree built from shares of the Blob.
// It is computed by splitting the blob into shares and building the Merkle subtree to be included after Submit.
type Commitment []byte

// Proof is a collection of nmt.Proofs that verifies the inclusion of the data.
type Proof []nmt.Proof

// Blob represents any application-specific binary data that anyone can submit to Celestia.
type Blob struct {
*types.Blob

commitment Commitment
}

// NewBlob constructs a new blob from the provided namespace.ID and data.
func NewBlob(nID namespace.ID, data []byte) (*Blob, error) {
blob, err := types.NewBlob(nID, data)
if err != nil {
return nil, err
}

com, err := types.CreateCommitment(blob)
if err != nil {
return nil, err
}
return &Blob{Blob: blob, commitment: com}, nil
}

// NamespaceID returns blobs namespaceId.
func (b *Blob) NamespaceID() []byte {
return b.Blob.NamespaceId
}

// Data returns blobs raw data.
func (b *Blob) Data() []byte {
return b.Blob.Data
}

// Commitment returns the commitment of current blob.
func (b *Blob) Commitment() Commitment {
return b.commitment
}

// Version is the format that was used to encode Blob data and namespaceID into shares.
func (b *Blob) Version() uint32 {
return b.Blob.ShareVersion
}

0 comments on commit b1902af

Please sign in to comment.