Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
DuniterPy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
clients
python
DuniterPy
Commits
04ecedc2
Commit
04ecedc2
authored
3 years ago
by
Vincent Texier
Browse files
Options
Downloads
Patches
Plain Diff
[enh]
#173
: Implement Transaction.sign() and Transaction.check_signature()
parent
89bf76f2
No related branches found
No related tags found
2 merge requests
!157
v1.0.0rc0: merge dev into master
,
!156
Release v1.0.0rc0
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
duniterpy/documents/transaction.py
+18
-6
18 additions, 6 deletions
duniterpy/documents/transaction.py
tests/documents/test_transaction.py
+24
-0
24 additions, 0 deletions
tests/documents/test_transaction.py
with
42 additions
and
6 deletions
duniterpy/documents/transaction.py
+
18
−
6
View file @
04ecedc2
...
@@ -929,11 +929,17 @@ Currency: {1}
...
@@ -929,11 +929,17 @@ Currency: {1}
return
signed_raw
return
signed_raw
def
sign
(
self
,
key
:
SigningKey
)
->
None
:
def
sign
(
self
,
key
:
SigningKey
)
->
None
:
raise
Exception
(
"
sign() is not implemented, use multi_sign()
"
)
"""
Add a signature to the document from key
:param key: SigningKey instance
:return:
"""
self
.
multi_sign
(
key
)
def
multi_sign
(
self
,
keys
:
Union
[
SigningKey
,
List
[
SigningKey
]])
->
None
:
def
multi_sign
(
self
,
keys
:
Union
[
SigningKey
,
List
[
SigningKey
]])
->
None
:
"""
"""
Sign the current document with
multiple keys
Add signature(s) to the document from one key or a list of
multiple keys
:param keys: Libnacl key or list of them
:param keys: Libnacl key or list of them
"""
"""
...
@@ -945,12 +951,18 @@ Currency: {1}
...
@@ -945,12 +951,18 @@ Currency: {1}
logging
.
debug
(
"
Signature :
\n
%s
"
,
signature
.
decode
(
"
ascii
"
))
logging
.
debug
(
"
Signature :
\n
%s
"
,
signature
.
decode
(
"
ascii
"
))
self
.
signatures
.
append
(
signature
.
decode
(
"
ascii
"
))
self
.
signatures
.
append
(
signature
.
decode
(
"
ascii
"
))
def
check_signature
(
self
,
pubkey
:
str
):
def
check_signature
(
self
,
pubkey
:
str
)
->
bool
:
raise
Exception
(
"
check_signature() is not implemented, use check_signatures()
"
)
"""
Check if document is signed by pubkey
:param pubkey: Base58 pubkey
:return:
"""
return
self
.
check_signatures
(
pubkey
)
def
check_signatures
(
self
,
pubkeys
:
Union
[
str
,
List
[
str
]]):
def
check_signatures
(
self
,
pubkeys
:
Union
[
str
,
List
[
str
]])
->
bool
:
"""
"""
Check if the signatures matches
the pub
keys
Check if the signatures matches
a public key or a list of public
keys
:param pubkeys: Base58 public key or list of them
:param pubkeys: Base58 public key or list of them
...
...
This diff is collapsed.
Click to expand it.
tests/documents/test_transaction.py
+
24
−
0
View file @
04ecedc2
...
@@ -485,6 +485,30 @@ class TestTransaction(unittest.TestCase):
...
@@ -485,6 +485,30 @@ class TestTransaction(unittest.TestCase):
unlock2
=
Unlock
.
from_inline
(
"
0:SIG(0)
"
)
unlock2
=
Unlock
.
from_inline
(
"
0:SIG(0)
"
)
self
.
assertEqual
(
unlock1
,
unlock2
)
self
.
assertEqual
(
unlock1
,
unlock2
)
def
test_check_signature
(
self
):
# create 3 wallets
signing_key
=
SigningKey
.
from_credentials
(
"
1
"
,
"
1
"
)
issuer
=
signing_key
.
pubkey
transaction
=
Transaction
(
block_id
=
BlockID
(
8979
,
"
000041DF0CCA173F09B5FBA48F619D4BC934F12ADF1D0B798639EB2149C4A8CC
"
),
locktime
=
0
,
issuers
=
[
issuer
],
inputs
=
[
InputSource
.
from_inline
(
input_source_str
)],
unlocks
=
[
Unlock
(
index
=
0
,
parameters
=
[
SIGParameter
(
0
)])],
outputs
=
[
OutputSource
.
from_inline
(
output_source_str
)],
comment
=
""
,
currency
=
G1_TEST_CURRENCY_CODENAME
,
)
# multi-signature on the transaction
transaction
.
sign
(
signing_key
)
self
.
assertTrue
(
transaction
.
check_signature
(
issuer
))
def
test_check_signatures
(
self
):
def
test_check_signatures
(
self
):
# create 3 wallets
# create 3 wallets
signing_key_01
=
SigningKey
.
from_credentials
(
"
1
"
,
"
1
"
)
signing_key_01
=
SigningKey
.
from_credentials
(
"
1
"
,
"
1
"
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment