-
Notifications
You must be signed in to change notification settings - Fork 2
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
f16cb65
commit 3fdff9a
Showing
14 changed files
with
126 additions
and
40 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
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,26 @@ | ||
import { Tendermint34Client } from '@cosmjs/tendermint-rpc'; | ||
import seedrandom from 'seedrandom'; | ||
|
||
const getTrueRandom = () => Math.random(); | ||
|
||
const uint8ArrayToHex = (array: Uint8Array): string => | ||
Array.from(array) | ||
.map((byte) => byte.toString(16).padStart(2, '0')) | ||
.join(''); | ||
|
||
const getPseudoRandom = async (neutronRpc: string) => { | ||
const client = await Tendermint34Client.connect(neutronRpc); | ||
const status = await client.status(); | ||
|
||
const blockHeight = Math.floor(status.syncInfo.latestBlockHeight / 100) * 100; | ||
const block = await client.block(blockHeight); | ||
const blockHash = block?.blockId?.hash; | ||
const hexHash = blockHash ? uint8ArrayToHex(blockHash) : undefined; | ||
|
||
client.disconnect(); | ||
|
||
const rng = seedrandom(hexHash); | ||
return rng(); | ||
}; | ||
|
||
export { getTrueRandom, getPseudoRandom }; |
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
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
Oops, something went wrong.