-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Number64UintArray and tree_newTreeFromUint64Deltas (#159)
* Implement Number64UintArray and tree_newTreeFromUint64Deltas * Create a separate Number64ListType * Fix lint * Address PR comment: more comments * Use for(;;) pattern and update subtreeFillToContents perf test * Make hash object methods applicable to basic types Add optional tree_* hash object methods to BasicType Remove FieldInfo.isNumber64Type Remove separate number64_* functions Rename applyDeltas methods Co-authored-by: Cayman <[email protected]>
- Loading branch information
1 parent
0d95532
commit 45620b7
Showing
12 changed files
with
502 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ dist/ | |
lib/ | ||
node_modules/ | ||
.idea/ | ||
.vscode | ||
yarn-error.log | ||
|
||
test/spec-tests-data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,61 @@ | ||
/** @module ssz */ | ||
import SHA256 from "@chainsafe/as-sha256"; | ||
import SHA256, {HashObject} from "@chainsafe/as-sha256"; | ||
|
||
/** | ||
* Hash used for hashTreeRoot | ||
*/ | ||
export function hash(...inputs: Uint8Array[]): Uint8Array { | ||
return SHA256.digest(Buffer.concat(inputs)); | ||
} | ||
|
||
/** | ||
* A temporary HashObject is needed in a lot of places, this HashObject is then | ||
* applied to persistent-merkle-tree, it'll make a copy so it's safe to mutate it after that. | ||
* It means that we could use a shared HashObject instead of having to always allocate | ||
* a new one to save memory. This temporary HashObject is always allocated by cloneHashObject() | ||
* or newHashObject() below. | ||
**/ | ||
const sharedHashObject: HashObject = { | ||
h0: 0, | ||
h1: 0, | ||
h2: 0, | ||
h3: 0, | ||
h4: 0, | ||
h5: 0, | ||
h6: 0, | ||
h7: 0, | ||
}; | ||
|
||
/** | ||
* Clone a hash object using sharedHashObject, after doing this we usually | ||
* apply HashObject to the Tree which make a copy there so it's safe to mutate | ||
* this HashObject after that. | ||
**/ | ||
export function cloneHashObject(hashObject: HashObject): HashObject { | ||
sharedHashObject.h0 = hashObject.h0; | ||
sharedHashObject.h1 = hashObject.h1; | ||
sharedHashObject.h2 = hashObject.h2; | ||
sharedHashObject.h3 = hashObject.h3; | ||
sharedHashObject.h4 = hashObject.h4; | ||
sharedHashObject.h5 = hashObject.h5; | ||
sharedHashObject.h6 = hashObject.h6; | ||
sharedHashObject.h7 = hashObject.h7; | ||
return sharedHashObject; | ||
} | ||
|
||
/** | ||
* Reset and return sharedHashObject, after doing this we usually | ||
* apply HashObject to the Tree which make a copy there so it's safe to mutate | ||
* this HashObject after that. | ||
**/ | ||
export function newHashObject(): HashObject { | ||
sharedHashObject.h0 = 0; | ||
sharedHashObject.h1 = 0; | ||
sharedHashObject.h2 = 0; | ||
sharedHashObject.h3 = 0; | ||
sharedHashObject.h4 = 0; | ||
sharedHashObject.h5 = 0; | ||
sharedHashObject.h6 = 0; | ||
sharedHashObject.h7 = 0; | ||
return sharedHashObject; | ||
} |
Oops, something went wrong.