deterministic-dice 2.0.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -3
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,QAAQ,CAAS;gBAEb,UAAU,EAAE,MAAM;IAO9B;;OAEG;IACH,IAAI,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM;IAevB,OAAO,CAAC,UAAU;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,QAAQ,CAAS;gBAEb,UAAU,EAAE,MAAM;IAO9B;;OAEG;IACH,IAAI,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM;IAevB,OAAO,CAAC,UAAU;CAcnB;AAED,eAAe,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { bytesToHex } from "@noble/hashes/utils";
|
|
1
|
+
import { keccak_256 } from "@noble/hashes/sha3";
|
|
2
|
+
import { bytesToHex, hexToBytes } from "@noble/hashes/utils";
|
|
3
3
|
/**
|
|
4
4
|
* Deterministic random number generator seeded by a bytes32 hash.
|
|
5
5
|
*/
|
|
@@ -29,7 +29,9 @@ export class DeterministicDice {
|
|
|
29
29
|
let result = 0;
|
|
30
30
|
for (let i = 0; i < count; i++) {
|
|
31
31
|
if (this.position >= this.entropy.length) {
|
|
32
|
-
|
|
32
|
+
// Convert hex string to bytes, hash the raw bytes (for Solidity parity)
|
|
33
|
+
const bytes = hexToBytes(this.entropy);
|
|
34
|
+
this.entropy = bytesToHex(keccak_256(bytes));
|
|
33
35
|
this.position = 0;
|
|
34
36
|
}
|
|
35
37
|
result = (result << 4) + parseInt(this.entropy[this.position], 16);
|