new DAG(shards, optionsopt)
Given a list of uniform buffers, construct a Merkle Tree.
Name | Type | Attributes | Description |
---|---|---|---|
shards | Array.<Buffer> | Uniform shards to compose an entry | |
options | module:merked/dag~DAG~Options | <optional> |
- Source
Methods
toArray() → {Array.<Buffer>}
Get the underlying shard array.
- Source
- Type:
- Array.<Buffer>
toMetadata(nameopt) → {module:merked/dag~DAG~Metadata}
Export a serializable metadata object
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
name | string | <optional> | "blob" | Application-specific tag or filename |
- Source
(static) DEFAULT_OPTS(shards) → {module:merked/dag~DAG~Options}
Computes the default options for DAG instance given a shard array.
Name | Type | Description |
---|---|---|
shards | Array.<Buffer> | Array of buffers to use as hashed leaf input |
- Source
(static) fromBuffer(buffer, sliceSizeopt, hashFuncopt, padLastSliceopt, randomFillopt) → {DAG}
Construct a DAG from a Buffer.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
buffer | Buffer | Raw input bytes | ||
sliceSize | number | <optional> | {DAG.DEFAULT_INPUT_SIZE} | Split buffer into uniform chunks |
hashFunc | function | <optional> | {module:merked/tree~MerkleTree.DEFAULT_HASH_FUNC} | Hash function to use |
padLastSlice | boolean | <optional> | false | If true, pad the final slice before hashing |
randomFill | boolean | <optional> | false | If true, pad with random bytes (will always result in a different tree) |
- Source
- Type:
- DAG
(static) randomFill(numBytes) → {Buffer}
Get a buffer filled with random bytes - used to pad last shard.
Name | Type | Description |
---|---|---|
numBytes | number | Size of buffer to create |
- Source
- Type:
- Buffer
Type Definitions
Metadata
- object
Name | Type | Description |
---|---|---|
n | string | Application-specific name |
l | Array.<string> | Input leaves as hex |
r | string | Root merkle node as hex |
s | number | Index where content ends and padding begins |
- Source
Options
- object
Name | Type | Description |
---|---|---|
sliceIndex | number | Where original input becomes padding |
hashFunc | function | Hash function to use for module:merked/tree~MerkleTree |
- Source