Skip to content

CIP-0008: Allow for signing with stake key directly #154

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

Merged
merged 1 commit into from
Jan 27, 2023

Conversation

thaddeusdiamond
Copy link
Contributor

@thaddeusdiamond thaddeusdiamond commented Jan 24, 2023

CIP-0008: Allow for signing with stake key directly
In the browser, if a user specifies the stake key as part of CIP-0030
the message returned in JSON has the COSE key as the staking key. The
verify() method correctly detects this, but the sign() method does not.
This change detects if a stake SigningKey type was passed in and if so,
sign with a stake key.

Sample behavior:

[00:28:29 01/24 thaddeuss-mbp] hacker:~/workspaces/wildtangz/cardano-vending-machine$ python3
Python 3.8.1 (v3.8.1:1b293b6006, Dec 18 2019, 14:08:53)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

import pycardano
skey = pycardano.key.StakeSigningKey.load('/var/folders/qz/ldnst4y96_z436s0ptw0vyp40000gn/T/cardano-vm-test-eobtvu6g/buyers/buyer.stake.skey')
sign_addr = pycardano.cip.cip8.verify(pycardano.cip.cip8.sign('hello', skey, attach_cose_key=False, network=pycardano.network.Network.TESTNET))['signing_address']
sign_addr
stake_test1uq5xgs974dna05tjc5pr8sfq5cc4hzludaz7z4e4vpx6p0gkrzzmd

The old behavior resulted in output of 'addr_test1vq5xgs974dna05tjc5pr8sfq5cc4hzludaz7z4e4vpx6p0gktu6v8'

[ Documentation: pydoc updates ]
[ Testing: python -m build, manual test in CLI ]
[ Code Review: https://github.com//pull/154 ]

@thaddeusdiamond
Copy link
Contributor Author

Let me know if the versioning update I put in here is not correct I am not certain on your version conventions.

@thaddeusdiamond
Copy link
Contributor Author

Tagging @cffls for review when you have a moment.

Copy link
Collaborator

@cffls cffls left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @thaddeusdiamond , thank you so much for your contribution, and apologies for the delayed response. The PR looks good to me. Also, it would be great if you can add a unit test for it. Thank you!

pyproject.toml Outdated
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pycardano"
version = "0.7.2"
version = "0.7.3"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually update version in a different workflow outside of feature PR. Let's remove this line of change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment on lines 50 to 53
if isinstance(signing_key, StakeSigningKey) or isinstance(signing_key, StakeExtendedSigningKey):
address = Address(payment_part=None, staking_part=verification_key.hash(), network=network)
else:
address = Address(payment_part=verification_key.hash(), staking_part=None, network=network)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change looks good to me. Could you add a unit test for it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@codecov-commenter
Copy link

codecov-commenter commented Jan 27, 2023

Codecov Report

Merging #154 (8eed562) into main (3527aa4) will increase coverage by 0.01%.
The diff coverage is 100.00%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##             main     #154      +/-   ##
==========================================
+ Coverage   86.44%   86.46%   +0.01%     
==========================================
  Files          26       26              
  Lines        2752     2755       +3     
  Branches      651      652       +1     
==========================================
+ Hits         2379     2382       +3     
  Misses        281      281              
  Partials       92       92              
Impacted Files Coverage Δ
pycardano/cip/cip8.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@thaddeusdiamond
Copy link
Contributor Author

No worries on delay just checking in! See the new commit for the unit tests and version removal.

In the browser, if a user specifies the stake key as part of CIP-0030
the message returned in JSON has the COSE key as the staking key.  The
verify() method correctly detects this, but the sign() method does not.
This change detects if a stake SigningKey type was passed in and if so,
sign with a stake key.

Sample behavior:

[00:28:29 01/24 thaddeuss-mbp] hacker:~/workspaces/wildtangz/cardano-vending-machine$ python3
Python 3.8.1 (v3.8.1:1b293b6006, Dec 18 2019, 14:08:53)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pycardano
>>> skey = pycardano.key.StakeSigningKey.load('/var/folders/qz/ldnst4y96_z436s0ptw0vyp40000gn/T/cardano-vm-test-eobtvu6g/buyers/buyer.stake.skey')
>>> sign_addr = pycardano.cip.cip8.verify(pycardano.cip.cip8.sign('hello', skey, attach_cose_key=False, network=pycardano.network.Network.TESTNET))['signing_address']
>>> sign_addr
stake_test1uq5xgs974dna05tjc5pr8sfq5cc4hzludaz7z4e4vpx6p0gkrzzmd

The old behavior resulted in output of 'addr_test1vq5xgs974dna05tjc5pr8sfq5cc4hzludaz7z4e4vpx6p0gktu6v8'

[ Documentation: pydoc updates ]
[ Testing: python -m build, manual test in CLI ]
[ Code Review: Python-Cardano#154 ]
@thaddeusdiamond
Copy link
Contributor Author

Didn't realize you used black, that's why tests failed. Ran black and repushed commit.

Copy link
Collaborator

@cffls cffls left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you for adding tests and fixing the code format!

@cffls cffls merged commit 62898ce into Python-Cardano:main Jan 27, 2023
@cffls cffls added the enhancement New feature or request label Feb 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants