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 @@ ...@@ -19,3 +19,5 @@
PROTOCOL_VERSION="1" PROTOCOL_VERSION="1"
MANAGED_API=["BASIC_MERKLED_API"] MANAGED_API=["BASIC_MERKLED_API"]
from . import api, documents, key
\ No newline at end of file
...@@ -141,4 +141,4 @@ class API(object): ...@@ -141,4 +141,4 @@ class API(object):
for leaf in root['leaves'][begin:end]: for leaf in root['leaves'][begin:end]:
yield self.requests_get(path, leaf=leaf).json()['leaf'] 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): ...@@ -34,13 +34,20 @@ class Parameters(Blockchain):
class Membership(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): def __post__(self, **kwargs):
assert 'membership' in kwargs assert 'membership' in kwargs
return self.requests_post('/membership', **kwargs).json() 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): class Block(Blockchain):
"""GET/POST a block from/to the 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): ...@@ -37,6 +37,16 @@ class Add(WOT):
return self.requests_post('/add', **kwargs).json() 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): class Lookup(WOT):
"""GET Public key data.""" """GET Public key data."""
......
''' """
Created on 3 déc. 2014 Created on 3 déc. 2014
@author: inso @author: inso
''' """
import base58 import base58
import base64 import base64
import re import re
...@@ -23,10 +23,10 @@ class Document: ...@@ -23,10 +23,10 @@ class Document:
self.signatures = [] self.signatures = []
def sign(self, keys): def sign(self, keys):
''' """
Sign the current document. Sign the current document.
Warning : current signatures will be replaced with the new ones. Warning : current signatures will be replaced with the new ones.
''' """
self.signatures = [] self.signatures = []
for key in keys: for key in keys:
signing = base64.b64encode(key.signature(bytes(self.raw(), 'ascii'))) signing = base64.b64encode(key.signature(bytes(self.raw(), 'ascii')))
...@@ -34,10 +34,10 @@ class Document: ...@@ -34,10 +34,10 @@ class Document:
self.signatures.append(signing.decode("ascii")) self.signatures.append(signing.decode("ascii"))
def signed_raw(self): def signed_raw(self):
''' """
If keys are None, returns the raw + current signatures If keys are None, returns the raw + current signatures
If keys are present, returns the raw signed by these keys If keys are present, returns the raw signed by these keys
''' """
raw = self.raw() raw = self.raw()
signed = "\n".join(self.signatures) signed = "\n".join(self.signatures)
signed_raw = raw + signed + "\n" signed_raw = raw + signed + "\n"
......
''' """
Created on 2 déc. 2014 Created on 2 déc. 2014
@author: inso @author: inso
''' """
from .. import PROTOCOL_VERSION from .. import PROTOCOL_VERSION
from . import Document from . import Document
...@@ -15,7 +15,7 @@ import logging ...@@ -15,7 +15,7 @@ import logging
class Block(Document): class Block(Document):
''' """
Version: VERSION Version: VERSION
Type: Block Type: Block
Currency: CURRENCY Currency: CURRENCY
...@@ -52,7 +52,7 @@ Transactions: ...@@ -52,7 +52,7 @@ Transactions:
COMPACT_TRANSACTION COMPACT_TRANSACTION
... ...
BOTTOM_SIGNATURE BOTTOM_SIGNATURE
''' """
re_type = re.compile("Type: (Block)\n") re_type = re.compile("Type: (Block)\n")
re_noonce = re.compile("Nonce: ([0-9]+)\n") re_noonce = re.compile("Nonce: ([0-9]+)\n")
...@@ -82,9 +82,9 @@ BOTTOM_SIGNATURE ...@@ -82,9 +82,9 @@ BOTTOM_SIGNATURE
parameters, members_count, identities, joiners, parameters, members_count, identities, joiners,
actives, leavers, excluded, certifications, actives, leavers, excluded, certifications,
transactions, signature): transactions, signature):
''' """
Constructor Constructor
''' """
super().__init__(version, currency, [signature]) super().__init__(version, currency, [signature])
self.noonce = noonce self.noonce = noonce
self.number = number self.number = number
...@@ -224,7 +224,7 @@ BOTTOM_SIGNATURE ...@@ -224,7 +224,7 @@ BOTTOM_SIGNATURE
for i in range(n, tx_max): for i in range(n, tx_max):
tx_lines += lines[n] tx_lines += lines[n]
n = n + 1 n = n + 1
transaction = Transaction.from_compact(version, tx_lines) transaction = Transaction.from_compact(currency, tx_lines)
transactions.append(transaction) transactions.append(transaction)
signature = Block.re_signature.match(lines[n]).group(1) signature = Block.re_signature.match(lines[n]).group(1)
...@@ -291,6 +291,6 @@ PreviousIssuer: {1}\n".format(self.prev_hash, self.prev_issuer) ...@@ -291,6 +291,6 @@ PreviousIssuer: {1}\n".format(self.prev_hash, self.prev_issuer)
doc += "Transactions:\n" doc += "Transactions:\n"
for transaction in self.transactions: for transaction in self.transactions:
doc += "{0}\n".format(transaction.inline()) doc += "{0}\n".format(transaction.compact())
return doc return doc
\ No newline at end of file
''' """
Created on 2 déc. 2014 Created on 2 déc. 2014
@author: inso @author: inso
''' """
import re import re
import base64 import base64
import logging import logging
...@@ -11,9 +11,9 @@ from . import Document ...@@ -11,9 +11,9 @@ from . import Document
class SelfCertification(Document): class SelfCertification(Document):
''' """
A document discribing a self certification. 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_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") re_uid = re.compile("UID:([^\n]+)\n")
...@@ -48,9 +48,9 @@ META:TS:{1} ...@@ -48,9 +48,9 @@ META:TS:{1}
class Certification(Document): class Certification(Document):
''' """
A document describing a certification. A document describing a certification.
''' """
re_inline = re.compile("([1-9A-Za-z][^OIl]{42,45}):\ 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") ([1-9A-Za-z][^OIl]{42,45}):([0-9]+):([A-Za-z0-9+/]+(?:=|==)?)\n")
...@@ -58,9 +58,9 @@ class Certification(Document): ...@@ -58,9 +58,9 @@ class Certification(Document):
def __init__(self, version, currency, pubkey_from, pubkey_to, def __init__(self, version, currency, pubkey_from, pubkey_to,
blocknumber, blockhash, signature): blocknumber, blockhash, signature):
''' """
Constructor Constructor
''' """
super().__init__(version, currency, [signature]) super().__init__(version, currency, [signature])
self.pubkey_from = pubkey_from self.pubkey_from = pubkey_from
self.pubkey_to = pubkey_to self.pubkey_to = pubkey_to
...@@ -85,10 +85,10 @@ class Certification(Document): ...@@ -85,10 +85,10 @@ class Certification(Document):
def sign(self, selfcert, keys): def sign(self, selfcert, keys):
''' """
Sign the current document. Sign the current document.
Warning : current signatures will be replaced with the new ones. Warning : current signatures will be replaced with the new ones.
''' """
self.signatures = [] self.signatures = []
for key in keys: for key in keys:
signing = base64.b64encode(key.signature(bytes(self.raw(selfcert), 'ascii'))) signing = base64.b64encode(key.signature(bytes(self.raw(selfcert), 'ascii')))
...@@ -105,3 +105,28 @@ class Certification(Document): ...@@ -105,3 +105,28 @@ class Certification(Document):
return "{0}:{1}:{2}:{3}".format(self.pubkey_from, self.pubkey_to, return "{0}:{1}:{2}:{3}".format(self.pubkey_from, self.pubkey_to,
self.blocknumber, self.signatures[0]) 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 Created on 2 déc. 2014
@author: inso @author: inso
''' """
from .. import PROTOCOL_VERSION from .. import PROTOCOL_VERSION
from . import Document from . import Document
...@@ -10,7 +10,7 @@ import re ...@@ -10,7 +10,7 @@ import re
class Membership(Document): class Membership(Document):
''' """
This is a utility class to generate membership documents : This is a utility class to generate membership documents :
Version: VERSION Version: VERSION
Type: Membership Type: Membership
...@@ -20,7 +20,7 @@ class Membership(Document): ...@@ -20,7 +20,7 @@ class Membership(Document):
Membership: MEMBERSHIP_TYPE Membership: MEMBERSHIP_TYPE
UserID: USER_ID UserID: USER_ID
CertTS: CERTIFICATION_TS CertTS: CERTIFICATION_TS
''' """
# PUBLIC_KEY:SIGNATURE:NUMBER:HASH:TIMESTAMP:USER_ID # PUBLIC_KEY:SIGNATURE:NUMBER:HASH:TIMESTAMP:USER_ID
re_inline = re.compile("([1-9A-Za-z][^OIl]{42,45}):([A-Za-z0-9+/]+(?:=|==)?):\ re_inline = re.compile("([1-9A-Za-z][^OIl]{42,45}):([A-Za-z0-9+/]+(?:=|==)?):\
...@@ -36,9 +36,9 @@ class Membership(Document): ...@@ -36,9 +36,9 @@ class Membership(Document):
def __init__(self, version, currency, issuer, block_number, block_hash, def __init__(self, version, currency, issuer, block_number, block_hash,
membership_type, uid, cert_ts, signature): membership_type, uid, cert_ts, signature):
''' """
Constructor Constructor
''' """
super().__init__(version, currency, [signature]) super().__init__(version, currency, [signature])
self.issuer = issuer self.issuer = issuer
self.block_number = block_number self.block_number = block_number
......
''' """
Created on 2 déc. 2014 Created on 2 déc. 2014
@author: inso @author: inso
''' """
import re import re
......
''' """
Created on 2 déc. 2014 Created on 2 déc. 2014
@author: inso @author: inso
''' """
import re import re
from . import Document from . import Document
class Status(Document): class Status(Document):
''' """
Version: VERSION Version: VERSION
Type: Status Type: Status
Currency: CURRENCY_NAME Currency: CURRENCY_NAME
...@@ -17,7 +17,7 @@ class Status(Document): ...@@ -17,7 +17,7 @@ class Status(Document):
Block: BLOCK Block: BLOCK
From: SENDER From: SENDER
To: RECIPIENT To: RECIPIENT
''' """
re_type = re.compile("Type: (Status)") re_type = re.compile("Type: (Status)")
re_status = re.compile("Status: (NEW|NEW_BACK|UP|UP_BACK|DOWN)") re_status = re.compile("Status: (NEW|NEW_BACK|UP|UP_BACK|DOWN)")
...@@ -27,9 +27,9 @@ class Status(Document): ...@@ -27,9 +27,9 @@ class Status(Document):
def __init__(self, version, currency, status, blockid, sender, def __init__(self, version, currency, status, blockid, sender,
recipient, signature): recipient, signature):
''' """
Constructor Constructor
''' """
super().__init__(version, currency, [signature]) super().__init__(version, currency, [signature])
self.status = status self.status = status
...@@ -70,12 +70,12 @@ class Status(Document): ...@@ -70,12 +70,12 @@ class Status(Document):
sender, recipient, signature) sender, recipient, signature)
def raw(self): def raw(self):
return '''Version: {0} return """Version: {0}
Type: Status Type: Status
Currency: {1} Currency: {1}
Status: {2} Status: {2}
Block: {3} Block: {3}
From: {4} From: {4}
To: {5} To: {5}
'''.format(self.version, self.currency, self.status, """.format(self.version, self.currency, self.status,
self.blockid, self.sender, self.recipient) self.blockid, self.sender, self.recipient)
''' """
Created on 2 déc. 2014 Created on 2 déc. 2014
@author: inso @author: inso
''' """
from . import Document from . import Document
import re import re
import logging
class Transaction(Document): class Transaction(Document):
''' """
Document format : Document format :
Version: VERSION Version: VERSION
Type: Transaction Type: Transaction
...@@ -37,10 +38,10 @@ PUBLIC_KEY:AMOUNT ...@@ -37,10 +38,10 @@ PUBLIC_KEY:AMOUNT
COMMENT COMMENT
SIGNATURE SIGNATURE
... ...
''' """
re_type = re.compile("Type: (Transaction)\n") 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_issuers = re.compile("Issuers:\n")
re_inputs = re.compile("Inputs:\n") re_inputs = re.compile("Inputs:\n")
re_outputs = re.compile("Outputs:\n") re_outputs = re.compile("Outputs:\n")
...@@ -50,9 +51,9 @@ SIGNATURE ...@@ -50,9 +51,9 @@ SIGNATURE
def __init__(self, version, currency, issuers, inputs, outputs, def __init__(self, version, currency, issuers, inputs, outputs,
comment, signatures): comment, signatures):
''' """
Constructor Constructor
''' """
super().__init__(version, currency, signatures) super().__init__(version, currency, signatures)
self.issuers = issuers self.issuers = issuers
...@@ -180,9 +181,9 @@ Issuers: ...@@ -180,9 +181,9 @@ Issuers:
return doc return doc
def compact(self): def compact(self):
''' """
Return a transaction in its compact format. Return a transaction in its compact format.
''' """
"""TX:VERSION:NB_ISSUERS:NB_INPUTS:NB_OUTPUTS:HAS_COMMENT """TX:VERSION:NB_ISSUERS:NB_INPUTS:NB_OUTPUTS:HAS_COMMENT
PUBLIC_KEY:INDEX PUBLIC_KEY:INDEX
... ...
...@@ -212,26 +213,26 @@ COMMENT ...@@ -212,26 +213,26 @@ COMMENT
class SimpleTransaction(Transaction): class SimpleTransaction(Transaction):
''' """
As transaction class, but for only one issuer. As transaction class, but for only one issuer.
... ...
''' """
def __init__(self, version, currency, issuer, def __init__(self, version, currency, issuer,
single_input, outputs, comment, signature): single_input, outputs, comment, signature):
''' """
Constructor Constructor
''' """
super().__init__(version, currency, [issuer], [single_input], super().__init__(version, currency, [issuer], [single_input],
outputs, comment, [signature]) outputs, comment, [signature])
class InputSource(): class InputSource():
''' """
A Transaction INPUT A Transaction INPUT
Compact : Compact :
INDEX:SOURCE:FINGERPRINT:AMOUNT INDEX:SOURCE:FINGERPRINT:AMOUNT
''' """
re_inline = re.compile("([0-9]+):(D|T):([0-9]+):\ re_inline = re.compile("([0-9]+):(D|T):([0-9]+):\
([0-9a-fA-F]{5,40}):([0-9]+)\n") ([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") re_compact = re.compile("([0-9]+):(D|T):([0-9a-fA-F]{5,40}):([0-9]+)\n")
...@@ -277,9 +278,9 @@ class InputSource(): ...@@ -277,9 +278,9 @@ class InputSource():
class OutputSource(): class OutputSource():
''' """
A Transaction OUTPUT A Transaction OUTPUT
''' """
re_inline = re.compile("([1-9A-Za-z][^OIl]{42,45}):([0-9]+)") re_inline = re.compile("([1-9A-Za-z][^OIl]{42,45}):([0-9]+)")
def __init__(self, pubkey, amount): def __init__(self, pubkey, amount):
......
''' """
Ucoin public and private keys Ucoin public and private keys
@author: inso @author: inso
''' """
import base58 import base58
import base64 import base64
......
''' """
HD Wallet inspired from Bip32 wallets. HD Wallet inspired from Bip32 wallets.
@author: inso @author: inso
''' """
''' """
import os import os
import hmac import hmac
import hashlib import hashlib
...@@ -375,4 +375,4 @@ if __name__ == "__main__": ...@@ -375,4 +375,4 @@ if __name__ == "__main__":
print "* [Chain m/0/2147483647h/1/2147483646h/2]" print "* [Chain m/0/2147483647h/1/2147483646h/2]"
m = m.ChildKey(2) m = m.ChildKey(2)
m.dump() 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