quietgarden/elm-web3/1.0.0

NOTE: the latest version is 2.0.1

Unavailable. Nobody can download this version any more, with elm or with the Lamdera compiler: github.com/quietgarden/elm-web3 is gone (deleted or private); Software Heritage not asked yet (this run's --swh-calls were used up); no fork with tag 1.0.0 found (5 same-name repos checked); no cached copy. Use another version.

Details

Web3.Sign

EIP-712 typed data signing.

Build a typed data request, encode it for the JS port, decode the signature response.

import Dict
import Json.Encode as E
import Web3.Sign as Sign


permitDomain : Sign.Domain
permitDomain =
    { name = Just "MyToken"
    , version = Just "1"
    , chainId = Just 1
    , verifyingContract = Just tokenAddress
    , salt = Nothing
    }


permitTypes : Dict.Dict String (List Sign.TypeField)
permitTypes =
    Dict.fromList
        [ ( "Permit"
          , [ { name = "owner", typeName = "address" }
            , { name = "spender", typeName = "address" }
            , { name = "value", typeName = "uint256" }
            , { name = "nonce", typeName = "uint256" }
            , { name = "deadline", typeName = "uint256" }
            ]
          )
        ]


permitRequest : Sign.TypedData
permitRequest =
    Sign.typedData
        { domain = permitDomain
        , types = permitTypes
        , primaryType = "Permit"
        , message =
            E.object
                [ ( "owner", E.string "0x..." )
                , ( "spender", E.string "0x..." )
                , ( "value", E.string "1000000000000000000" )
                , ( "nonce", E.int 0 )
                , ( "deadline", E.int 9999999999 )
                ]
        }


-- Send via port:
--   web3Cmd (Sign.encode "permit-1" signerAddress permitRequest)
--
-- Receive via port:
--   D.decodeValue Sign.signatureDecoder incoming

An EIP-712 typed data signing request.

type alias Domain =
{ name : Maybe String
, version : Maybe String
, chainId : Maybe Int
, verifyingContract : Maybe Address
, salt : Maybe String
}

EIP-712 domain separator parameters. All fields are optional; include only those your contract's domain hash covers.

type alias TypeField =
{ name : String
, typeName : String
}

A single field in a struct type definition.

{ domain : Domain
, types : Dict String (List TypeField)
, primaryType : String
, message : Value
}

Construct a TypedData value.

encode : String -> Address -> TypedData -> Value

Encode a TypedData request as a port command.

web3Cmd (Sign.encode "my-id" signerAddress request)

The id is echoed back in the signed response so you can match responses to requests when multiple signing requests are in flight.

signatureDecoder : Decoder String

Decode the signed response from the JS port.

case D.decodeValue Sign.signatureDecoder incoming of
    Ok sig ->
        -- sig : String — the 0x-prefixed signature
    Err _ ->
        -- handle decode error