-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
923d4db
commit 5ebc99a
Showing
2 changed files
with
60 additions
and
43 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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { Bytes, Gadgets, UInt32, UInt8 } from 'o1js'; | ||
import { DynamicArray } from './dynamic-array.ts'; | ||
import { StaticArray } from './static-array.ts'; | ||
import * as nodeAssert from 'node:assert'; | ||
import { DynamicSHA256 } from './dynamic-sha256.ts'; | ||
|
||
const { SHA256 } = Gadgets; | ||
|
||
class DynamicBytes extends DynamicArray(UInt8, { maxLength: 500 }) { | ||
static fromString(s: string) { | ||
return DynamicBytes.from( | ||
[...new TextEncoder().encode(s)].map((t) => UInt8.from(t)) | ||
); | ||
} | ||
} | ||
|
||
let bytes = DynamicBytes.fromString(longString()); | ||
let staticBytes = Bytes.fromString(longString()); | ||
|
||
nodeAssert.deepStrictEqual( | ||
DynamicSHA256.padding(bytes).toValue().map(blockToHexBytes), | ||
SHA256.padding(staticBytes).map(blockToHexBytes) | ||
); | ||
nodeAssert.deepStrictEqual( | ||
DynamicSHA256.hash(bytes).toBytes(), | ||
SHA256.hash(staticBytes).toBytes() | ||
); | ||
|
||
function toHexBytes(uint32: bigint | UInt32) { | ||
return UInt32.from(uint32).toBigint().toString(16).padStart(8, '0'); | ||
} | ||
function blockToHexBytes(block: (bigint | UInt32)[] | StaticArray<UInt32>) { | ||
if (Array.isArray(block)) return block.map((uint32) => toHexBytes(uint32)); | ||
return blockToHexBytes((block as StaticArray).array); | ||
} | ||
|
||
function longString(): string { | ||
return ` | ||
Symbol.iterator | ||
The Symbol.iterator static data property represents the well-known symbol Symbol.iterator. The iterable protocol looks up this symbol for the method that returns the iterator for an object. In order for an object to be iterable, it must have an [Symbol.iterator] key. | ||
`; | ||
} |
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