Skip to content

Instantly share code, notes, and snippets.

@james-iohk
Last active January 13, 2023 10:57
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save james-iohk/4b54ceefbc3ad3d6fdbc49350bd5b6a8 to your computer and use it in GitHub Desktop.
Plutus SECP256k1 Examples
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
module EcdsaPolicy (writeSerialisedScript) where
import Cardano.Api (PlutusScript, PlutusScriptV2,
writeFileTextEnvelope)
import Cardano.Api.Shelley (PlutusScript (..))
import Codec.Serialise (serialise)
import qualified Data.ByteString.Lazy as LBS
import qualified Data.ByteString.Short as SBS
import Data.Functor (void)
import qualified Ledger.Typed.Scripts as Scripts
import qualified Plutus.V2.Ledger.Api as PlutusV2
import qualified PlutusTx
import qualified PlutusTx.Builtins as BI
import PlutusTx.Prelude as P hiding (Semigroup (..), unless, (.))
import Prelude (IO, (.))
{-# INLINABLE mkVerifyEcdsaPolicy #-}
mkVerifyEcdsaPolicy :: (BI.BuiltinByteString, BI.BuiltinByteString, BI.BuiltinByteString)
-> PlutusV2.ScriptContext
-> Bool
mkVerifyEcdsaPolicy (v, m, s) _sc = BI.verifyEcdsaSecp256k1Signature v m s
verifyEcdsaPolicy :: PlutusV2.MintingPolicy
verifyEcdsaPolicy = PlutusV2.mkMintingPolicyScript $$(PlutusTx.compile [||wrap||])
where
wrap = Scripts.mkUntypedMintingPolicy mkVerifyEcdsaPolicy
verifyEcdsaPolicyScript :: PlutusScript PlutusScriptV2
verifyEcdsaPolicyScript = PlutusScriptSerialised
$ SBS.toShort
. LBS.toStrict
$ serialise
$ PlutusV2.unMintingPolicyScript verifyEcdsaPolicy
writeSerialisedScript :: IO ()
writeSerialisedScript = void $ writeFileTextEnvelope "ecdsa-secp256k1-policy.plutus" Nothing verifyEcdsaPolicyScript
{
"type": "PlutusScriptV2",
"description": "",
"cborHex": "5907c35907c00100003232323233223232323232323232323322323232323222323253353322350022223335734666ed000c00800406c068c8c8c8cccd5cd19b8735573aa00690001199911091998008020018011bae35742a0066eb8d5d0a8011bae357426ae8940088c98c8070cd5ce00e80e00d09aba25001135573ca00226ea8010cccd5cd19b8735573aa0049000119910919800801801191919191919191919191919191999ab9a3370e6aae754031200023333333333332222222222221233333333333300100d00c00b00a00900800700600500400300233501401535742a01866a02802a6ae85402ccd4050058d5d0a805199aa80c3ae501735742a012666aa030eb9405cd5d0a80419a80a00f9aba150073335501802075a6ae854018c8c8c8cccd5cd19b8735573aa00490001199109198008018011919191999ab9a3370e6aae754009200023322123300100300233502a75a6ae854008c0acd5d09aba2500223263202f33573806005e05a26aae7940044dd50009aba150023232323333573466e1cd55cea8012400046644246600200600466a054eb4d5d0a80118159aba135744a004464c6405e66ae700c00bc0b44d55cf280089baa001357426ae8940088c98c80accd5ce01601581489aab9e5001137540026ae854014cd4051d71aba150043335501801c200135742a006666aa030eb88004d5d0a801180f1aba135744a004464c6404e66ae700a009c0944d5d1280089aba25001135744a00226ae8940044d5d1280089aba25001135744a00226ae8940044d5d1280089aba25001135573ca00226ea8004d5d0a80118071aba135744a004464c6403266ae7006806405c40604c98c8060cd5ce2490350543500018135573ca00226ea800448c88c008dd6000990009aa80b111999aab9f0012500a233500930043574200460066ae880080588c8c8cccd5cd19b8735573aa004900011991091980080180118061aba150023005357426ae8940088c98c8058cd5ce00b80b00a09aab9e5001137540024646464646666ae68cdc39aab9d5004480008cccc888848cccc00401401000c008c8c8c8cccd5cd19b8735573aa0049000119910919800801801180a9aba1500233500f014357426ae8940088c98c806ccd5ce00e00d80c89aab9e5001137540026ae854010ccd54021d728039aba150033232323333573466e1d4005200423212223002004357426aae79400c8cccd5cd19b875002480088c84888c004010dd71aba135573ca00846666ae68cdc3a801a400042444006464c6403a66ae7007807406c0680644d55cea80089baa00135742a00466a016eb8d5d09aba2500223263201733573803002e02a26ae8940044d5d1280089aab9e500113754002266aa002eb9d6889119118011bab00132001355013223233335573e0044a010466a00e66442466002006004600c6aae754008c014d55cf280118021aba200301413574200222440042442446600200800624464646666ae68cdc3a800a40004642446004006600a6ae84d55cf280191999ab9a3370ea0049001109100091931900919ab9c01301201000f135573aa00226ea80048c8c8cccd5cd19b875001480188c848888c010014c01cd5d09aab9e500323333573466e1d400920042321222230020053009357426aae7940108cccd5cd19b875003480088c848888c004014c01cd5d09aab9e500523333573466e1d40112000232122223003005375c6ae84d55cf280311931900919ab9c01301201000f00e00d135573aa00226ea80048c8c8cccd5cd19b8735573aa004900011991091980080180118029aba15002375a6ae84d5d1280111931900719ab9c00f00e00c135573ca00226ea80048c8cccd5cd19b8735573aa002900011bae357426aae7940088c98c8030cd5ce00680600509baa001232323232323333573466e1d4005200c21222222200323333573466e1d4009200a21222222200423333573466e1d400d2008233221222222233001009008375c6ae854014dd69aba135744a00a46666ae68cdc3a8022400c4664424444444660040120106eb8d5d0a8039bae357426ae89401c8cccd5cd19b875005480108cc8848888888cc018024020c030d5d0a8049bae357426ae8940248cccd5cd19b875006480088c848888888c01c020c034d5d09aab9e500b23333573466e1d401d2000232122222223005008300e357426aae7940308c98c8054cd5ce00b00a80980900880800780700689aab9d5004135573ca00626aae7940084d55cf280089baa0012323232323333573466e1d400520022333222122333001005004003375a6ae854010dd69aba15003375a6ae84d5d1280191999ab9a3370ea0049000119091180100198041aba135573ca00c464c6401c66ae7003c03803002c4d55cea80189aba25001135573ca00226ea80048c8c8cccd5cd19b875001480088c8488c00400cdd71aba135573ca00646666ae68cdc3a8012400046424460040066eb8d5d09aab9e500423263200b33573801801601201026aae7540044dd500089119191999ab9a3370ea00290021091100091999ab9a3370ea00490011190911180180218031aba135573ca00846666ae68cdc3a801a400042444004464c6401866ae700340300280240204d55cea80089baa0012323333573466e1d40052002200523333573466e1d40092000200523263200833573801201000c00a26aae74dd5000891001091000a4c240029210350543100112323001001223300330020020011"
}
{"constructor":0,"fields":[{"bytes":"0392d7b94bc6a11c335a043ee1ff326b6eacee6230d3685861cd62bce350a172e0"},{"bytes":"16e0bf1f85594a11e75030981c0b670370b3ad83a43f49ae58a2fd6f6513cde9"},{"bytes":"5fb12954b28be6456feb080cfb8467b6f5677f62eb9ad231de7a575f4b6857512754fb5ef7e0e60e270832e7bb0e2f0dc271012fa9c46c02504aa0e798be6295"}]}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
module SchnorrPolicy (writeSerialisedScript) where
import Cardano.Api (PlutusScript, PlutusScriptV2,
writeFileTextEnvelope)
import Cardano.Api.Shelley (PlutusScript (..))
import Codec.Serialise (serialise)
import qualified Data.ByteString.Lazy as LBS
import qualified Data.ByteString.Short as SBS
import Data.Functor (void)
import qualified Ledger.Typed.Scripts as Scripts
import qualified Plutus.V2.Ledger.Api as PlutusV2
import qualified PlutusTx
import qualified PlutusTx.Builtins as BI
import PlutusTx.Prelude as P hiding (Semigroup (..), unless, (.))
import Prelude (IO, (.))
{-# INLINABLE mkVerifySchnorrPolicy #-}
mkVerifySchnorrPolicy :: (BI.BuiltinByteString, BI.BuiltinByteString, BI.BuiltinByteString)
-> PlutusV2.ScriptContext
-> Bool
mkVerifySchnorrPolicy (v, m, s) _sc = BI.verifySchnorrSecp256k1Signature v m s
verifySchnorrPolicy :: PlutusV2.MintingPolicy
verifySchnorrPolicy = PlutusV2.mkMintingPolicyScript $$(PlutusTx.compile [||wrap||])
where
wrap = Scripts.mkUntypedMintingPolicy mkVerifySchnorrPolicy
verifySchnorrPolicyScript :: PlutusScript PlutusScriptV2
verifySchnorrPolicyScript = PlutusScriptSerialised
$ SBS.toShort
. LBS.toStrict
$ serialise
$ PlutusV2.unMintingPolicyScript verifySchnorrPolicy
writeSerialisedScript :: IO ()
writeSerialisedScript = void $ writeFileTextEnvelope "schnorr-secp256k1-policy.plutus" Nothing verifySchnorrPolicyScript
{
"type": "PlutusScriptV2",
"description": "",
"cborHex": "5907c35907c00100003232323233223232323232323232323322323232323222323253353322350022223335734666ed400c00800406c068c8c8c8cccd5cd19b8735573aa00690001199911091998008020018011bae35742a0066eb8d5d0a8011bae357426ae8940088c98c8070cd5ce00e80e00d09aba25001135573ca00226ea8010cccd5cd19b8735573aa0049000119910919800801801191919191919191919191919191999ab9a3370e6aae754031200023333333333332222222222221233333333333300100d00c00b00a00900800700600500400300233501401535742a01866a02802a6ae85402ccd4050058d5d0a805199aa80c3ae501735742a012666aa030eb9405cd5d0a80419a80a00f9aba150073335501802075a6ae854018c8c8c8cccd5cd19b8735573aa00490001199109198008018011919191999ab9a3370e6aae754009200023322123300100300233502a75a6ae854008c0acd5d09aba2500223263202f33573806005e05a26aae7940044dd50009aba150023232323333573466e1cd55cea8012400046644246600200600466a054eb4d5d0a80118159aba135744a004464c6405e66ae700c00bc0b44d55cf280089baa001357426ae8940088c98c80accd5ce01601581489aab9e5001137540026ae854014cd4051d71aba150043335501801c200135742a006666aa030eb88004d5d0a801180f1aba135744a004464c6404e66ae700a009c0944d5d1280089aba25001135744a00226ae8940044d5d1280089aba25001135744a00226ae8940044d5d1280089aba25001135573ca00226ea8004d5d0a80118071aba135744a004464c6403266ae7006806405c40604c98c8060cd5ce2490350543500018135573ca00226ea800448c88c008dd6000990009aa80b111999aab9f0012500a233500930043574200460066ae880080588c8c8cccd5cd19b8735573aa004900011991091980080180118061aba150023005357426ae8940088c98c8058cd5ce00b80b00a09aab9e5001137540024646464646666ae68cdc39aab9d5004480008cccc888848cccc00401401000c008c8c8c8cccd5cd19b8735573aa0049000119910919800801801180a9aba1500233500f014357426ae8940088c98c806ccd5ce00e00d80c89aab9e5001137540026ae854010ccd54021d728039aba150033232323333573466e1d4005200423212223002004357426aae79400c8cccd5cd19b875002480088c84888c004010dd71aba135573ca00846666ae68cdc3a801a400042444006464c6403a66ae7007807406c0680644d55cea80089baa00135742a00466a016eb8d5d09aba2500223263201733573803002e02a26ae8940044d5d1280089aab9e500113754002266aa002eb9d6889119118011bab00132001355013223233335573e0044a010466a00e66442466002006004600c6aae754008c014d55cf280118021aba200301413574200222440042442446600200800624464646666ae68cdc3a800a40004642446004006600a6ae84d55cf280191999ab9a3370ea0049001109100091931900919ab9c01301201000f135573aa00226ea80048c8c8cccd5cd19b875001480188c848888c010014c01cd5d09aab9e500323333573466e1d400920042321222230020053009357426aae7940108cccd5cd19b875003480088c848888c004014c01cd5d09aab9e500523333573466e1d40112000232122223003005375c6ae84d55cf280311931900919ab9c01301201000f00e00d135573aa00226ea80048c8c8cccd5cd19b8735573aa004900011991091980080180118029aba15002375a6ae84d5d1280111931900719ab9c00f00e00c135573ca00226ea80048c8cccd5cd19b8735573aa002900011bae357426aae7940088c98c8030cd5ce00680600509baa001232323232323333573466e1d4005200c21222222200323333573466e1d4009200a21222222200423333573466e1d400d2008233221222222233001009008375c6ae854014dd69aba135744a00a46666ae68cdc3a8022400c4664424444444660040120106eb8d5d0a8039bae357426ae89401c8cccd5cd19b875005480108cc8848888888cc018024020c030d5d0a8049bae357426ae8940248cccd5cd19b875006480088c848888888c01c020c034d5d09aab9e500b23333573466e1d401d2000232122222223005008300e357426aae7940308c98c8054cd5ce00b00a80980900880800780700689aab9d5004135573ca00626aae7940084d55cf280089baa0012323232323333573466e1d400520022333222122333001005004003375a6ae854010dd69aba15003375a6ae84d5d1280191999ab9a3370ea0049000119091180100198041aba135573ca00c464c6401c66ae7003c03803002c4d55cea80189aba25001135573ca00226ea80048c8c8cccd5cd19b875001480088c8488c00400cdd71aba135573ca00646666ae68cdc3a8012400046424460040066eb8d5d09aab9e500423263200b33573801801601201026aae7540044dd500089119191999ab9a3370ea00290021091100091999ab9a3370ea00490011190911180180218031aba135573ca00846666ae68cdc3a801a400042444004464c6401866ae700340300280240204d55cea80089baa0012323333573466e1d40052002200523333573466e1d40092000200523263200833573801201000c00a26aae74dd5000891001091000a4c240029210350543100112323001001223300330020020011"
}
{"constructor":0,"fields":[{"bytes":"599de3e582e2a3779208a210dfeae8f330b9af00a47a7fb22e9bb8ef596f301b"},{"bytes":"30303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030"},{"bytes":"5a56da88e6fd8419181dec4d3dd6997bab953d2fc71ab65e23cfc9e7e3d1a310613454a60f6703819a39fdac2a410a094442afd1fc083354443e8d8bb4461a9b"}]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment