merked/dag~ DAG

new DAG(shards, optionsopt)

Given a list of uniform buffers, construct a Merkle Tree.

Parameters:
NameTypeAttributesDescription
shardsArray.<Buffer>

Uniform shards to compose an entry

optionsmodule:merked/dag~DAG~Options<optional>

Methods

toArray() → {Array.<Buffer>}

Get the underlying shard array.

Returns:
Type: 
Array.<Buffer>

toMetadata(nameopt) → {module:merked/dag~DAG~Metadata}

Export a serializable metadata object

Parameters:
NameTypeAttributesDefaultDescription
namestring<optional>
"blob"

Application-specific tag or filename

(static) DEFAULT_OPTS(shards) → {module:merked/dag~DAG~Options}

Computes the default options for DAG instance given a shard array.

Parameters:
NameTypeDescription
shardsArray.<Buffer>

Array of buffers to use as hashed leaf input

(static) fromBuffer(buffer, sliceSizeopt, hashFuncopt, padLastSliceopt, randomFillopt) → {DAG}

Construct a DAG from a Buffer.

Parameters:
NameTypeAttributesDefaultDescription
bufferBuffer

Raw input bytes

sliceSizenumber<optional>
{DAG.DEFAULT_INPUT_SIZE}

Split buffer into uniform chunks

hashFuncfunction<optional>
{module:merked/tree~MerkleTree.DEFAULT_HASH_FUNC}

Hash function to use

padLastSliceboolean<optional>
false

If true, pad the final slice before hashing

randomFillboolean<optional>
false

If true, pad with random bytes (will always result in a different tree)

Returns:
Type: 
DAG

(static) randomFill(numBytes) → {Buffer}

Get a buffer filled with random bytes - used to pad last shard.

Parameters:
NameTypeDescription
numBytesnumber

Size of buffer to create

Returns:
Type: 
Buffer

Type Definitions

Metadata

Type:
  • object
Properties
NameTypeDescription
nstring

Application-specific name

lArray.<string>

Input leaves as hex

rstring

Root merkle node as hex

snumber

Index where content ends and padding begins

Options

Type:
  • object
Properties
NameTypeDescription
sliceIndexnumber

Where original input becomes padding

hashFuncfunction

Hash function to use for module:merked/tree~MerkleTree