Cardano.Cip30

CIP 30 support.

type alias WalletDescriptor =
{ id : String
, name : String
, icon : String
, apiVersion : String
, isEnabled : Bool
, supportedExtensions : List Int
}

The type returned when asking for available wallets.

type Wallet

Opaque Wallet object to be used for all API requests.

walletDescriptor : Wallet -> WalletDescriptor

Retrieve the descriptor associated with a [Wallet] object.

Retrieve the change address associated with a [Wallet] object.

Update the change address associated with a [Wallet] object.

type Request

Opaque type for requests to be sent to the wallets.

Encode a [Request] into a JS value that can be sent through a port.

type alias Paginate =
{ page : Int
, limit : Int
}

Paginate requests that may return many elements.

Typically the first request you have to send, to discover which wallets are installed.

Will typically be followed by a response of the [AvailableWallets] variant containing a [WalletDescriptor] for each discovered wallet.

{ id : String
, extensions : List Int
, watchInterval : Maybe Int
}

Enable an installed wallet.

Will typically be followed by a response of the [EnabledWallet] variant containing a [Wallet] to be stored in your model.

Optionally, you can watch for changes of the selected wallet at a regular interval (in seconds). Each time, the wallet will check the current change address and notify with a ChangeAddress API response if it has changed.

Get the list of extensions enabled by the wallet.

This feature isn't well supported yet by wallets (as of 2023-10).

Get the current network ID of the wallet.

-> { amount : Maybe Value
, paginate : Maybe Paginate
}

Get a list of UTxOs in the wallet.

getCollateral : Wallet -> { amount : Natural } -> Request

Get a list of UTxOs to be used for collateral.

You need to specify the amount of lovelace you need for collateral. More info about why that is in the CIP 30 spec.

Get the current wallet balance.

getUsedAddresses : Wallet -> { paginate : Maybe Paginate } -> Request

Get a list of used addresses from the wallet.

That list is wallet-dependent and may not contain all used addresses. Do not rely on this as a source of truth to get all addresses of a user.

Get a list of unused addresses.

Avoid this feature if possible. It is not consistent and not compatible with single-address wallets.

Get an address that can be used to send funds to this wallet.

Get addresses used to withdraw staking rewards.

signTx : Wallet -> { partialSign : Bool } -> Transaction -> Request

Sign a transaction.

signTxCbor : Wallet -> { partialSign : Bool } -> Bytes Transaction -> Request

Sign a transaction, already CBOR-encoded (to avoid deserialization-serialization mismatch).

type KeyType
= PaymentKey
| StakeKey

Key type used for data signature.

-> { networkId : NetworkId
, keyType : KeyType
, keyHash : Bytes CredentialHash
, payload : Bytes a
}

Sign an arbitrary payload with your wallet keys. You can provide one of your payment or stake credential handled by the wallet.

submitTx : Wallet -> Transaction -> Request

Encode a transaction and submit it via the wallet.

submitTxCbor : Wallet -> Bytes Transaction -> Request

Submit a transaction, already CBOR-encoded (to avoid deserialization-serialization mismatch).

apiRequest : Wallet -> Maybe Int -> String -> List Value -> Request

Make a CIP-30 API request.

This is mainly a helper function, exposed for implementors of extensions, like CIP-95.

type Response apiResponse
= AvailableWallets (List WalletDescriptor)
| EnabledWallet Wallet
| ApiResponse { walletId : String } apiResponse
| ApiError
{ walletId : Maybe String
, code : Int
, info : String
}
| UnhandledResponseType String

Response type for responses from the browser wallets.

= Extensions (List Int)
| NetworkId NetworkId
| WalletUtxos (List Utxo)
| Collateral (List Utxo)
| WalletBalance Value
| UsedAddresses (List Address)
| UnusedAddresses (List Address)
| ChangeAddress Address
| RewardAddresses (List Address)
| SignedTx (List VKeyWitness)
| SignedData DataSignature
| SubmittedTx (Bytes TransactionId)
| UnhandledApiResponse String

Response type for all API requests done through the api object returned when enabling a wallet.

type alias Utxo =
( OutputReference, Output )

UTxO type holding the reference and actual output.

type alias DataSignature =
{ signature : CborItem
, key : CborItem
}

Signature returned from the wallet after signing a payload with your stake key.

Dict Int (String -> Decoder apiResponse)
-> Decoder (Response apiResponse)

Decoder for the [Response] type.

apiDecoder : String -> Decoder ApiResponse

API response decoder for CIP-30. Intented to be provided as argument to the responseDecoder function.

utxoDecoder : Decoder Utxo

Decode UTxO pairs encoded as CBOR in a hex JSON field.

hexCborDecoder : Decoder a -> Decoder a

Helper function to decode CBOR as hex in JSON.

JSON decoder for an [Address] encoded as hexadecimal string.

dataSignatureDecoder : Decoder DataSignature

Helper function to decode data signatures.