Skip to content
Snippets Groups Projects
Commit 7a4639c0 authored by inso's avatar inso
Browse files

Upgrade to last version

parent 2c30fdfd
No related branches found
No related tags found
No related merge requests found
......@@ -19,3 +19,5 @@
PROTOCOL_VERSION="1"
MANAGED_API=["BASIC_MERKLED_API"]
from . import api, documents, key
\ No newline at end of file
......@@ -141,4 +141,4 @@ class API(object):
for leaf in root['leaves'][begin:end]:
yield self.requests_get(path, leaf=leaf).json()['leaf']
from . import network, blockchain, tx, wot
from . import network, blockchain, tx, wot, node
......@@ -34,13 +34,20 @@ class Parameters(Blockchain):
class Membership(Blockchain):
"""POST a Membership document."""
"""GET/POST a Membership document."""
def __init__(self, connection_handler, search=None):
super().__init__(connection_handler)
self.search = search
def __post__(self, **kwargs):
assert 'membership' in kwargs
return self.requests_post('/membership', **kwargs).json()
def __get__(self, **kwargs):
assert self.search is not None
return self.requests_get('/memberships/%s' % self.search, **kwargs).json()
class Block(Blockchain):
"""GET/POST a block from/to the blockchain."""
......
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Authors:
# Caner Candan <caner@candan.fr>, http://caner.candan.fr
#
from .. import API, logging
logger = logging.getLogger("ucoin/node")
class Node(API):
def __init__(self, connection_handler, module='node'):
super(Node, self).__init__(connection_handler, module)
class Summary(Node):
"""GET Certification data over a member."""
def __init__(self, connection_handler, module='node'):
super(Summary, self).__init__(connection_handler, module)
def __get__(self, **kwargs):
return self.requests_get('/summary', **kwargs).json()
......@@ -37,6 +37,16 @@ class Add(WOT):
return self.requests_post('/add', **kwargs).json()
class Revoke(WOT):
"""POST Public key data."""
def __post__(self, **kwargs):
assert 'pubkey' in kwargs
assert 'self_' in kwargs
return self.requests_post('/revoke', **kwargs).json()
class Lookup(WOT):
"""GET Public key data."""
......
'''
"""
Created on 3 déc. 2014
@author: inso
'''
"""
import base58
import base64
import re
......@@ -23,10 +23,10 @@ class Document:
self.signatures = []
def sign(self, keys):
'''
"""
Sign the current document.
Warning : current signatures will be replaced with the new ones.
'''
"""
self.signatures = []
for key in keys:
signing = base64.b64encode(key.signature(bytes(self.raw(), 'ascii')))
......@@ -34,10 +34,10 @@ class Document:
self.signatures.append(signing.decode("ascii"))
def signed_raw(self):
'''
"""
If keys are None, returns the raw + current signatures
If keys are present, returns the raw signed by these keys
'''
"""
raw = self.raw()
signed = "\n".join(self.signatures)
signed_raw = raw + signed + "\n"
......
'''
"""
Created on 2 déc. 2014
@author: inso
'''
"""
from .. import PROTOCOL_VERSION
from . import Document
......@@ -15,7 +15,7 @@ import logging
class Block(Document):
'''
"""
Version: VERSION
Type: Block
Currency: CURRENCY
......@@ -52,7 +52,7 @@ Transactions:
COMPACT_TRANSACTION
...
BOTTOM_SIGNATURE
'''
"""
re_type = re.compile("Type: (Block)\n")
re_noonce = re.compile("Nonce: ([0-9]+)\n")
......@@ -82,9 +82,9 @@ BOTTOM_SIGNATURE
parameters, members_count, identities, joiners,
actives, leavers, excluded, certifications,
transactions, signature):
'''
"""
Constructor
'''
"""
super().__init__(version, currency, [signature])
self.noonce = noonce
self.number = number
......@@ -224,7 +224,7 @@ BOTTOM_SIGNATURE
for i in range(n, tx_max):
tx_lines += lines[n]
n = n + 1
transaction = Transaction.from_compact(version, tx_lines)
transaction = Transaction.from_compact(currency, tx_lines)
transactions.append(transaction)
signature = Block.re_signature.match(lines[n]).group(1)
......@@ -291,6 +291,6 @@ PreviousIssuer: {1}\n".format(self.prev_hash, self.prev_issuer)
doc += "Transactions:\n"
for transaction in self.transactions:
doc += "{0}\n".format(transaction.inline())
doc += "{0}\n".format(transaction.compact())
return doc
\ No newline at end of file
'''
"""
Created on 2 déc. 2014
@author: inso
'''
"""
import re
import base64
import logging
......@@ -11,9 +11,9 @@ from . import Document
class SelfCertification(Document):
'''
"""
A document discribing a self certification.
'''
"""
re_inline = re.compile("([1-9A-Za-z][^OIl]{42,45}):([A-Za-z0-9+/]+(?:=|==)?):([0-9]+):([^\n]+)\n")
re_uid = re.compile("UID:([^\n]+)\n")
......@@ -48,9 +48,9 @@ META:TS:{1}
class Certification(Document):
'''
"""
A document describing a certification.
'''
"""
re_inline = re.compile("([1-9A-Za-z][^OIl]{42,45}):\
([1-9A-Za-z][^OIl]{42,45}):([0-9]+):([A-Za-z0-9+/]+(?:=|==)?)\n")
......@@ -58,9 +58,9 @@ class Certification(Document):
def __init__(self, version, currency, pubkey_from, pubkey_to,
blocknumber, blockhash, signature):
'''
"""
Constructor
'''
"""
super().__init__(version, currency, [signature])
self.pubkey_from = pubkey_from
self.pubkey_to = pubkey_to
......@@ -85,10 +85,10 @@ class Certification(Document):
def sign(self, selfcert, keys):
'''
"""
Sign the current document.
Warning : current signatures will be replaced with the new ones.
'''
"""
self.signatures = []
for key in keys:
signing = base64.b64encode(key.signature(bytes(self.raw(selfcert), 'ascii')))
......@@ -105,3 +105,28 @@ class Certification(Document):
return "{0}:{1}:{2}:{3}".format(self.pubkey_from, self.pubkey_to,
self.blocknumber, self.signatures[0])
class Revocation(Document):
"""
A document describing a self-revocation.
"""
def __init__(self, version, currency, signature):
"""
Constructor
"""
super().__init__(version, currency, [signature])
def raw(self, selfcert):
return """{0}META:REVOKE
""".format(selfcert.signed_raw())
def sign(self, selfcert, keys):
"""
Sign the current document.
Warning : current signatures will be replaced with the new ones.
"""
self.signatures = []
for key in keys:
signing = base64.b64encode(key.signature(bytes(self.raw(selfcert), 'ascii')))
self.signatures.append(signing.decode("ascii"))
'''
"""
Created on 2 déc. 2014
@author: inso
'''
"""
from .. import PROTOCOL_VERSION
from . import Document
......@@ -10,7 +10,7 @@ import re
class Membership(Document):
'''
"""
This is a utility class to generate membership documents :
Version: VERSION
Type: Membership
......@@ -20,7 +20,7 @@ class Membership(Document):
Membership: MEMBERSHIP_TYPE
UserID: USER_ID
CertTS: CERTIFICATION_TS
'''
"""
# PUBLIC_KEY:SIGNATURE:NUMBER:HASH:TIMESTAMP:USER_ID
re_inline = re.compile("([1-9A-Za-z][^OIl]{42,45}):([A-Za-z0-9+/]+(?:=|==)?):\
......@@ -36,9 +36,9 @@ class Membership(Document):
def __init__(self, version, currency, issuer, block_number, block_hash,
membership_type, uid, cert_ts, signature):
'''
"""
Constructor
'''
"""
super().__init__(version, currency, [signature])
self.issuer = issuer
self.block_number = block_number
......
'''
"""
Created on 2 déc. 2014
@author: inso
'''
"""
import re
......
'''
"""
Created on 2 déc. 2014
@author: inso
'''
"""
import re
from . import Document
class Status(Document):
'''
"""
Version: VERSION
Type: Status
Currency: CURRENCY_NAME
......@@ -17,7 +17,7 @@ class Status(Document):
Block: BLOCK
From: SENDER
To: RECIPIENT
'''
"""
re_type = re.compile("Type: (Status)")
re_status = re.compile("Status: (NEW|NEW_BACK|UP|UP_BACK|DOWN)")
......@@ -27,9 +27,9 @@ class Status(Document):
def __init__(self, version, currency, status, blockid, sender,
recipient, signature):
'''
"""
Constructor
'''
"""
super().__init__(version, currency, [signature])
self.status = status
......@@ -70,12 +70,12 @@ class Status(Document):
sender, recipient, signature)
def raw(self):
return '''Version: {0}
return """Version: {0}
Type: Status
Currency: {1}
Status: {2}
Block: {3}
From: {4}
To: {5}
'''.format(self.version, self.currency, self.status,
""".format(self.version, self.currency, self.status,
self.blockid, self.sender, self.recipient)
'''
"""
Created on 2 déc. 2014
@author: inso
'''
"""
from . import Document
import re
import logging
class Transaction(Document):
'''
"""
Document format :
Version: VERSION
Type: Transaction
......@@ -37,10 +38,10 @@ PUBLIC_KEY:AMOUNT
COMMENT
SIGNATURE
...
'''
"""
re_type = re.compile("Type: (Transaction)\n")
re_header = re.compile("TX:([0-9])+:([0-9])+:([0-9])+:([0-9])+:(0|1)\n")
re_header = re.compile("TX:([0-9]+):([0-9]+):([0-9]+):([0-9]+):(0|1)\n")
re_issuers = re.compile("Issuers:\n")
re_inputs = re.compile("Inputs:\n")
re_outputs = re.compile("Outputs:\n")
......@@ -50,9 +51,9 @@ SIGNATURE
def __init__(self, version, currency, issuers, inputs, outputs,
comment, signatures):
'''
"""
Constructor
'''
"""
super().__init__(version, currency, signatures)
self.issuers = issuers
......@@ -180,9 +181,9 @@ Issuers:
return doc
def compact(self):
'''
"""
Return a transaction in its compact format.
'''
"""
"""TX:VERSION:NB_ISSUERS:NB_INPUTS:NB_OUTPUTS:HAS_COMMENT
PUBLIC_KEY:INDEX
...
......@@ -212,26 +213,26 @@ COMMENT
class SimpleTransaction(Transaction):
'''
"""
As transaction class, but for only one issuer.
...
'''
"""
def __init__(self, version, currency, issuer,
single_input, outputs, comment, signature):
'''
"""
Constructor
'''
"""
super().__init__(version, currency, [issuer], [single_input],
outputs, comment, [signature])
class InputSource():
'''
"""
A Transaction INPUT
Compact :
INDEX:SOURCE:FINGERPRINT:AMOUNT
'''
"""
re_inline = re.compile("([0-9]+):(D|T):([0-9]+):\
([0-9a-fA-F]{5,40}):([0-9]+)\n")
re_compact = re.compile("([0-9]+):(D|T):([0-9a-fA-F]{5,40}):([0-9]+)\n")
......@@ -277,9 +278,9 @@ class InputSource():
class OutputSource():
'''
"""
A Transaction OUTPUT
'''
"""
re_inline = re.compile("([1-9A-Za-z][^OIl]{42,45}):([0-9]+)")
def __init__(self, pubkey, amount):
......
'''
"""
Ucoin public and private keys
@author: inso
'''
"""
import base58
import base64
......
'''
"""
HD Wallet inspired from Bip32 wallets.
@author: inso
'''
'''
"""
"""
import os
import hmac
import hashlib
......@@ -375,4 +375,4 @@ if __name__ == "__main__":
print "* [Chain m/0/2147483647h/1/2147483646h/2]"
m = m.ChildKey(2)
m.dump()
'''
\ No newline at end of file
"""
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment