Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data Observation a = Observation {}
- data SignedMessage a = SignedMessage {
- osmSignature :: Signature
- osmMessageHash :: DatumHash
- osmDatum :: Datum
- data SignedMessageCheckError
- = SignatureMismatch Signature PaymentPubKey DatumHash
- | DatumMissing DatumHash
- | DecodingError
- | DatumNotEqualToExpected
- checkSignature :: DatumHash -> PaymentPubKey -> Signature -> Either SignedMessageCheckError ()
- checkHashConstraints :: FromData a => SignedMessage a -> Either SignedMessageCheckError (a, TxConstraints i o)
- checkHashOffChain :: FromData a => SignedMessage a -> Either SignedMessageCheckError a
- verifySignedMessageOffChain :: FromData a => PaymentPubKey -> SignedMessage a -> Either SignedMessageCheckError a
- verifySignedMessageOnChain :: FromData a => ScriptContext -> PaymentPubKey -> SignedMessage a -> Either SignedMessageCheckError a
- verifySignedMessageConstraints :: FromData a => PaymentPubKey -> SignedMessage a -> Either SignedMessageCheckError (a, TxConstraints i o)
- signMessage :: ToData a => a -> PaymentPrivateKey -> Passphrase -> SignedMessage a
- signObservation :: ToData a => POSIXTime -> a -> PaymentPrivateKey -> Passphrase -> SignedMessage (Observation a)
- signMessage' :: ToData a => a -> XPrv -> SignedMessage a
- signObservation' :: ToData a => POSIXTime -> a -> XPrv -> SignedMessage (Observation a)
Signed messages
This module provides a way to verify signed messages, and a type for observations (for example, the price of a commodity on a given date). Together, the two can be used to implement trusted oracles:
- The oracle observes a value, for example
Price
and constructs a valueo =
Observation
Price
. - The oracle then calls
signMessage
o pk
with its own private key to produce aSignedMessage
(
Observation
Price)
. - The signed message is passed to the contract as the redeemer of some
unspent output. Important: The redeeming transaction must include the
message
o
as a datum. This is because we can't hash anything in on-chain code, and therefore have to rely on the node to do it for us via the pending transaction's map of datum hashes to datums. (The constraints resolution mechanism takes care of including the message) - The contract then calls
checkSignature
to check the signature, and produces a constraint ensuring that the signed hash is really the hash of the datum.
data Observation a Source #
A value that was observed at a specific point in time
Instances
data SignedMessage a Source #
SignedMessage a
contains the signature of a hash of a Datum
.
The Datum
can be decoded to a value of type a
.
SignedMessage | |
|
Instances
Checking signed messages
data SignedMessageCheckError Source #
SignatureMismatch Signature PaymentPubKey DatumHash | The signature did not match the public key |
DatumMissing DatumHash | The datum was missing from the pending transaction |
DecodingError | The datum had the wrong shape |
DatumNotEqualToExpected | The datum that corresponds to the hash is wrong |
Instances
:: DatumHash | The hash of the message |
-> PaymentPubKey | The public key of the signatory |
-> Signature | The signed message |
-> Either SignedMessageCheckError () |
Verify the signature on a signed datum hash
:: FromData a | |
=> SignedMessage a | The signed message |
-> Either SignedMessageCheckError (a, TxConstraints i o) |
Extract the contents of the message and produce a constraint that checks
that the hash is correct. In off-chain code, where we check the hash
straightforwardly, checkHashOffChain
can be used instead of this.
checkHashOffChain :: FromData a => SignedMessage a -> Either SignedMessageCheckError a Source #
The off-chain version of checkHashConstraints
, using the hash function
directly instead of obtaining the hash from a ScriptContext
value
verifySignedMessageOffChain :: FromData a => PaymentPubKey -> SignedMessage a -> Either SignedMessageCheckError a Source #
Check the signature on a SignedMessage
and extract the contents of the
message.
verifySignedMessageOnChain :: FromData a => ScriptContext -> PaymentPubKey -> SignedMessage a -> Either SignedMessageCheckError a Source #
Check the signature on a SignedMessage
and extract the contents of the
message, using the pending transaction in lieu of a hash function. See
verifySignedMessageConstraints
for a version that does not require a
ScriptContext
value.
verifySignedMessageConstraints :: FromData a => PaymentPubKey -> SignedMessage a -> Either SignedMessageCheckError (a, TxConstraints i o) Source #
Check the signature on a SignedMessage
and extract the contents of the
message, producing a TxConstraint
value that ensures the hashes match
up.
Signing messages
signMessage :: ToData a => a -> PaymentPrivateKey -> Passphrase -> SignedMessage a Source #
Encode a message of type a
as a Data
value and sign the
hash of the datum.
signObservation :: ToData a => POSIXTime -> a -> PaymentPrivateKey -> Passphrase -> SignedMessage (Observation a) Source #
Encode an observation of a value of type a
that was made at the given time
Signing messages with no passphrase
signMessage' :: ToData a => a -> XPrv -> SignedMessage a Source #
Encode a message of type a
as a Data
value and sign the
hash of the datum.
signObservation' :: ToData a => POSIXTime -> a -> XPrv -> SignedMessage (Observation a) Source #
Encode an observation of a value of type a
that was made at the given time