Changeset 272

Show
Ignore:
Timestamp:
04/23/09 15:14:19 (3 years ago)
Author:
ocjhb
Message:

first traces of working exchange

Location:
trunk/sandbox/jhb/oc2
Files:
7 modified

Legend:

Unmodified
Added
Removed
  • trunk/sandbox/jhb/oc2/documentation.py

    r271 r272  
    607607>>> bobport = 9091 
    608608>>> bobwallet = Wallet({}) 
    609  
     609>>> import test 
    610610>>> alicetid = wallet.makeSerial() 
    611611>>> bob = protocols.SumAnnounceListen(bobwallet) 
     
    650650 
    651651>>> bob = protocols.SpendListen(bobwallet) 
    652 >>> transport = transports.YieldTransport(bob.run,[]) 
     652>>> #transport = transports.YieldTransport(bob.run,[]) 
    653653>>> alice = protocols.SpendRequest(bob.run, wallet, 'foobar', [coin])  
    654654>>> alice.run() 
     
    667667True 
    668668 
     669Now, lets first pretend we are on Bobs side. Fix that later, but assume we  
     670received the coins, we know what cdd and mkc to use. We need to exchange now 
     671 
     672>>> coins = [coin] 
     673>>> key = mkc.publicKey 
     674>>> bobblank = bobwallet._makeBlank(cdd,mkc) 
     675>>> bobsecret, bobblind = key.blindBlank(bobblank) 
     676>>> blinds = [[mkc.keyId,bobblind]] 
     677>>> bobtid = wallet.makeSerial() 
     678 
     679>>> clientside = protocols.TransferRequest(transport,tid,blinds = blinds, coins = coins) 
     680>>> testserver.run_once(port,issuer=issuer,mint=mint) 
     681>>> text,value = clientside.run() 
     682>>> bobblank.signature = key.unblind(bobsecret,value[0]) 
     683>>> bobcoin = bobblank 
     684>>> key.verifyContainerSignature(bobcoin) 
     685True 
     686 
     687 
     688 
     689 
    669690############################################################################### 
    670691 
  • trunk/sandbox/jhb/oc2/messages.py

    r270 r272  
    6565 
    6666class TransferReject(Message): 
    67     pass 
     67    fields = Message.fields + [ 
     68        Field('transactionId'), 
     69        Field('reason'), 
     70    ] 
    6871 
    6972class TransferDelay(Message): 
  • trunk/sandbox/jhb/oc2/mint.py

    r271 r272  
    6161        message = authorizedMessage.message 
    6262        blinds = message.blinds 
     63        return self._mintBlinds(message) 
     64     
     65    def handleExchangeRequest(self,message): 
     66        #import pdb; pdb.set_trace() 
     67        coins = message.coins 
     68        blinds = message.blinds 
     69        payed = sum([int(coin.denomination) for coin in coins]) 
     70         
     71        amount = 0 
     72        for keyid,blind in blinds: 
     73            priv,pub,denomination,version = self.getMintKeyById(keyid) 
     74            amount += int(denomination) 
     75         
     76        if payed != amount: 
     77            reject = messages.TransferReject() 
     78            reject.reason = 'mismatch' 
     79            return reject 
     80 
     81        return self._mintBlinds(message) 
     82             
     83    def _mintBlinds(self,message): 
     84         
     85        blinds = message.blinds 
    6386        result = [] 
    6487        for keyid,blind in blinds: 
     
    77100         
    78101        return answer 
    79      
    80     def handleExchangeRequest(self,message): 
    81         coins = message.coins 
    82         blinds = message.blinds 
    83  
    84  
    85102 
    86103    def addToTransactions(self,transactionId,result): 
  • trunk/sandbox/jhb/oc2/protocols.py

    r271 r272  
    123123            if type(authorizedMessage) == messages.Error: 
    124124                return messages.TransferReject() 
    125             return self.mint.handleMintingRequest(authorizedMessage) 
     125            else: 
     126                return self.mint.handleMintingRequest(authorizedMessage) 
    126127         
    127128        elif requesttype == 'exchange': 
    128129            return self.mint.handleExchangeRequest(message) 
    129              
     130         
     131        else: 
     132            return messages.TransferReject() 
    130133 
    131134 
     
    228231class SpendListen(Protocol): 
    229232     
    230     def __init__(self,wallet): 
    231         self.wallet = wallet 
     233    def __init__(self,wallet,client=None): 
     234        self.wallet = wallet 
     235        self.client = client 
    232236     
    233237    def run(self,message=None): 
  • trunk/sandbox/jhb/oc2/rsa.py

    r263 r272  
    162162 
    163163def generate(bits):  #needed 
    164     return (dummypub,dummypriv) 
     164    #return (dummypub,dummypriv) 
    165165    p = getRandomPrime(bits/2, False) 
    166166    q = getRandomPrime(bits/2, False) 
  • trunk/sandbox/jhb/oc2/testclient.py

    r271 r272  
    11import BaseHTTPServer, threading 
    2 import protocols, issuer, mint, transports, urllib 
    3  
     2import protocols, transports, urllib 
    43 
    54class Handler(BaseHTTPServer.BaseHTTPRequestHandler): 
    65 
    76    def do_POST(self): 
    8         #print self.server 
     7         
     8        wallet = self.server.wallet 
     9        client = self.server.walletclient 
     10         
    911        if self.path == '/stop': 
    1012            raise 'foobar' 
     
    1315        data = urllib.unquote(data) 
    1416        message = transports.createMessage(data) 
    15         if message.header == 'AskLatestCDD': 
    16             protocol = protocols.GiveLatestCDD(self.issuer) 
    17         elif message.header == 'FetchMintKeys': 
    18             protocol = protocols.GiveMintKeys(self.issuer) 
    19         elif message.header == 'TransferRequest': 
    20             protocol = protocols.TransferHandling(self.mint,self.authorizer) 
    21         elif message.header == 'TransferResume': 
    22             protocol = protocols.TransferResumeHandling(self.issuer) 
     17         
     18        if message.header == 'SpendRequest': 
     19            protocol = protocols.SpendListen(wallet,client) 
    2320  
    2421        answer = protocol.run(message) 
     
    2926 
    3027 
     28class Client(object): 
    3129 
    32 def run_once(port,issuer=None,mint=None,authorizer=None): 
    33     import time 
    34     time.sleep(0.001) 
    35     Handler.issuer = issuer 
    36     Handler.mint = mint 
    37     Handler.authorizer = authorizer 
    38     httpd = BaseHTTPServer.HTTPServer(("", port), Handler) 
    39     import threading 
    40     t = threading.Thread(target=httpd.handle_request)      
    41     t.start() 
     30    def __init__(self,port,wallet=None): 
     31        self.wallet = wallet 
     32        self.port = port 
    4233 
     34    def http_run_once(self): 
     35        import time 
     36        time.sleep(0.001) 
     37        httpd = BaseHTTPServer.HTTPServer(("", self.port), Handler) 
     38        httpd.wallet = self.wallet 
     39        httpd.walletclient = self 
     40        import threading 
     41        t = threading.Thread(target=httpd.handle_request)      
     42        t.start() 
     43 
  • trunk/sandbox/jhb/oc2/wallet.py

    r270 r272  
    1414        blank.setNewSerial() 
    1515        return blank 
     16 
     17    def blanksFromCoins(self,coins): 
     18        pass 
    1619 
    1720    def makeSerial(self): 
     
    3841        return approval 
    3942         
    40  
     43