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 CHANGED
@@ -1,4 +1,4 @@
1
- # deterministic-dice
1
+ # 🎲 deterministic-dice
2
2
 
3
3
  Deterministic random number generator seeded by a bytes32 hash.
4
4
 
@@ -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;CAYnB;AAED,eAAe,iBAAiB,CAAC"}
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 { sha256 } from "@noble/hashes/sha256";
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
- this.entropy = bytesToHex(sha256(this.entropy));
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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "deterministic-dice",
3
- "version": "2.0.0",
3
+ "version": "3.0.0",
4
4
  "description": "Deterministic random number generator seeded by a bytes32 hash",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",