Documentation
¶
Overview ¶
Copyright © 2018, 2019 Weald Technology Trading Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2018, 2019 Weald Technology Trading Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EncodeProof ¶
func VerifyProof ¶
VerifyProof verifies a Merkle tree proof for a piece of data using the default hash type. The proof and path are as per Merkle tree's GenerateProof(), and root is the root hash of the tree against which the proof is to be verified. Note that this does not require the Merkle tree to verify the proof, only its root; this allows for checking against historical trees without having to instantiate them.
This returns true if the proof is verified, otherwise false.
func VerifyProofUsing ¶
VerifyProofUsing verifies a Merkle tree proof for a piece of data using the provided hash type. The proof and is as per Merkle tree's GenerateProof(), and root is the root hash of the tree against which the proof is to be verified. Note that this does not require the Merkle tree to verify the proof, only its root; this allows for checking against historical trees without having to instantiate them.
This returns true if the proof is verified, otherwise false.
Types ¶
type BLAKE3 ¶
type BLAKE3 struct {
// contains filtered or unexported fields
}
func (*BLAKE3) HashLength ¶
HashLength returns the length of hashes generated by Hash() in bytes
type HashType ¶
type HashType interface { // Hash calculates the hash of a given input Hash([]byte, []byte) []byte // HashLength provides the length of the hash HashLength() int }
HashType defines the interface that must be supplied by hash functions
type MerkleTree ¶
type MerkleTree struct {
// contains filtered or unexported fields
}
MerkleTree is the structure for the Merkle tree.
func New ¶
func New(data [][]byte) (*MerkleTree, error)
New creates a new Merkle tree using the provided raw data and default hash type. data must contain at least one element for it to be valid.
func NewUsing ¶
func NewUsing(data [][]byte, hash HashType) (*MerkleTree, error)
NewUsing creates a new Merkle tree using the provided raw data and supplied hash type. data must contain at least one element for it to be valid.
func (*MerkleTree) EncodedProofLength ¶
func (t *MerkleTree) EncodedProofLength() int
EncodedProofLength returns the byte length of the proof for a piece of data. 4 bytes are for how many hashes are in the path, 8 bytes for embedding the index in the tree (see proof.go for details).
func (*MerkleTree) GenerateProof ¶
func (t *MerkleTree) GenerateProof(data []byte) (*Proof, error)
GenerateProof generates the proof for a piece of data. If the data is not present in the tree this will return an error. If the data is present in the tree this will return the hashes for each level in the tree and the index of the value in the tree
func (*MerkleTree) Root ¶
func (t *MerkleTree) Root() []byte
Root returns the Merkle root (hash of the root node) of the tree.