-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Condition and fulfillment in escrow #698
Open
ckeshava
wants to merge
7
commits into
XRPLF:main
Choose a base branch
from
ckeshava:conditionalEscrow
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1e39a97
utility function to generate condition and fulfillment for conditiona…
ckeshava f9c260e
include conditional escrow test case in snippets
ckeshava f2a3517
update CL
ckeshava 154ab1a
Merge branch 'main' into conditionalEscrow
ckeshava 1b14e39
include the new poetry.lock, to be consistent with the pyproject.toml…
ckeshava 111a6ff
Merge branch 'conditionalEscrow' of https://github.com/ckeshava/xrpl-…
ckeshava b60cf13
import TypedDict from typing_extensions, instead of importing from ty…
ckeshava File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,10 @@ | |
from __future__ import annotations # Requires Python 3.7+ | ||
|
||
from dataclasses import dataclass, field | ||
from typing import Dict, Optional | ||
from typing import Dict, Optional, TypedDict | ||
|
||
# CK: TODO Find a py.typed or library stub for cryptoconditions | ||
from cryptoconditions import PreimageSha256 # type: ignore | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please let me know if you have any ideas to get |
||
|
||
from xrpl.models.amounts import Amount | ||
from xrpl.models.required import REQUIRED | ||
|
@@ -81,3 +84,31 @@ def _get_errors(self: EscrowCreate) -> Dict[str, str]: | |
] = "The finish_after time must be before the cancel_after time." | ||
|
||
return errors | ||
|
||
|
||
class CryptoConditions(TypedDict): | ||
""" | ||
A typed-dictionary containing the condition and the fulfillment for | ||
conditional Escrows | ||
""" | ||
|
||
condition: str | ||
fulfillment: str | ||
|
||
|
||
def generate_escrow_cryptoconditions(secret: bytes) -> CryptoConditions: | ||
"""Generate a condition and fulfillment for escrows | ||
|
||
Args: | ||
secret: Cryptographic source of randomness used to generate the condition and | ||
fulfillment | ||
|
||
Returns: | ||
A pair of condition and fulfillment is returned | ||
|
||
""" | ||
fufill = PreimageSha256(preimage=secret) | ||
return { | ||
"condition": str.upper(fufill.condition_binary.hex()), | ||
"fulfillment": str.upper(fufill.serialize_binary().hex()), | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have empirically observed that the generated cryptographic condition always begins with
A0258020...
and ends with...810120
. I don't have statistical numbers to prove my point, but the outputs from this library do not appear random, despite varying secret inputs.