Skip to content

Commit ff97c2b

Browse files
committed
Move to Api package and add native implementation
1 parent 93a3928 commit ff97c2b

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

cardano-wasm/cardano-wasm.cabal

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ executable cardano-wasm
4242
Cardano.Wasm.Internal.Api.GRPC
4343
Cardano.Wasm.Internal.Api.Info
4444
Cardano.Wasm.Internal.Api.InfoToTypeScript
45+
Cardano.Wasm.Internal.Api.Random
4546
Cardano.Wasm.Internal.Api.Tx
4647
Cardano.Wasm.Internal.Api.TypeScriptDefs
4748
Cardano.Wasm.Internal.Api.Wallet
4849
Cardano.Wasm.Internal.ExceptionHandling
4950
Cardano.Wasm.Internal.JavaScript.Bridge
5051
Cardano.Wasm.Internal.JavaScript.GRPC
5152
Cardano.Wasm.Internal.JavaScript.GRPCTypes
52-
Cardano.Wasm.Internal.JavaScript.Random
5353

5454
build-depends:
5555
aeson,
@@ -74,6 +74,9 @@ executable cardano-wasm
7474
base16-bytestring,
7575
ghc-experimental,
7676
utf8-string,
77+
else
78+
build-depends:
79+
crypton
7780

7881
test-suite cardano-wasm-golden
7982
type: exitcode-stdio-1.0

cardano-wasm/src/Cardano/Wasm/Internal/JavaScript/Random.hs renamed to cardano-wasm/src/Cardano/Wasm/Internal/Api/Random.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
{-# LANGUAGE CApiFFI #-}
22
{-# LANGUAGE CPP #-}
33

4-
module Cardano.Wasm.Internal.JavaScript.Random (getRandomBytes) where
4+
module Cardano.Wasm.Internal.Api.Random (getRandomBytes) where
55

66
#if !defined(wasm32_HOST_ARCH)
77

88
import Data.ByteString (ByteString)
9+
import Crypto.Random.Entropy (getEntropy)
910

1011
getRandomBytes :: Word -> IO ByteString
11-
getRandomBytes _ = error "getRandomBytes is not implemented for non-WASM targets"
12+
getRandomBytes n = getEntropy (fromIntegral n)
1213

1314
#else
1415

cardano-wasm/src/Cardano/Wasm/Internal/Api/Wallet.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ import Cardano.Api
3838
)
3939

4040
import Cardano.Crypto.Seed (mkSeedFromBytes)
41+
import Cardano.Wasm.Internal.Api.Random (getRandomBytes)
4142
import Cardano.Wasm.Internal.ExceptionHandling (rightOrError, toMonadFail)
42-
import Cardano.Wasm.Internal.JavaScript.Random (getRandomBytes)
4343

4444
import Data.Aeson ((.=))
4545
import Data.Aeson qualified as Aeson

0 commit comments

Comments
 (0)