-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
107 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
module Cardano.Core.Integrity ( | ||
pisScriptCredential, | ||
pisPubKeyCredential, | ||
pdeserializeCredential, | ||
) where | ||
|
||
import Plutarch.Core.List | ||
import Plutarch.Prelude | ||
|
||
-- | Check that a data-encoded Credential is a ScriptCredential. | ||
-- This does not guarantee that the data-encoded term is structurally a valid Credential. | ||
-- So this should only be used if the data-encoded term is known to be a Credential. | ||
-- If the term is obtained from relevant fields of the ScriptContext or TxInfo, then this check is safe | ||
-- because the ledger guarantees the structural validity of the Credential. | ||
pisScriptCredential :: Term s (PAsData PCredential) -> Term s PBool | ||
pisScriptCredential cred = (pfstBuiltin # (pasConstr # pforgetData cred)) #== 1 | ||
|
||
-- | Check if the provided data-encoded Credential is a PubKeyCredential. | ||
-- This does not guarantee that the data-encoded term is structurally a valid Credential. | ||
-- So this should only be used if the data-encoded term is known to be a Credential. | ||
-- If the term is obtained from relevant fields of the ScriptContext or TxInfo, then this check is safe | ||
-- because the ledger guarantees the structural validity of the Credential. | ||
pisPubKeyCredential :: Term s (PAsData PCredential) -> Term s PBool | ||
pisPubKeyCredential cred = (pfstBuiltin # (pasConstr # pforgetData cred)) #== 0 | ||
|
||
-- | Check if the provided data-encoded term has the expected builtin data representation of a credential. | ||
pdeserializeCredential :: Term s (PAsData PCredential) -> Term s (PAsData PCredential) | ||
pdeserializeCredential term = | ||
plet (pasConstr # pforgetData term) $ \constrPair -> | ||
plet (pfstBuiltin # constrPair) $ \constrIdx -> | ||
pif (plengthBS # (pasByteStr # (pheadSingleton # (psndBuiltin # constrPair))) #== 28) | ||
( | ||
pcond | ||
[ ( constrIdx #== 0 , term) | ||
, ( constrIdx #== 1 , term) | ||
] | ||
(ptraceInfoError "Invalid credential") | ||
) | ||
perror |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters