Changeset 272
- Timestamp:
- 04/23/09 15:14:19 (3 years ago)
- Location:
- trunk/sandbox/jhb/oc2
- Files:
-
- 7 modified
-
documentation.py (modified) (3 diffs)
-
messages.py (modified) (1 diff)
-
mint.py (modified) (2 diffs)
-
protocols.py (modified) (2 diffs)
-
rsa.py (modified) (1 diff)
-
testclient.py (modified) (3 diffs)
-
wallet.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/sandbox/jhb/oc2/documentation.py
r271 r272 607 607 >>> bobport = 9091 608 608 >>> bobwallet = Wallet({}) 609 609 >>> import test 610 610 >>> alicetid = wallet.makeSerial() 611 611 >>> bob = protocols.SumAnnounceListen(bobwallet) … … 650 650 651 651 >>> bob = protocols.SpendListen(bobwallet) 652 >>> transport = transports.YieldTransport(bob.run,[])652 >>> #transport = transports.YieldTransport(bob.run,[]) 653 653 >>> alice = protocols.SpendRequest(bob.run, wallet, 'foobar', [coin]) 654 654 >>> alice.run() … … 667 667 True 668 668 669 Now, lets first pretend we are on Bobs side. Fix that later, but assume we 670 received 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) 685 True 686 687 688 689 669 690 ############################################################################### 670 691 -
trunk/sandbox/jhb/oc2/messages.py
r270 r272 65 65 66 66 class TransferReject(Message): 67 pass 67 fields = Message.fields + [ 68 Field('transactionId'), 69 Field('reason'), 70 ] 68 71 69 72 class TransferDelay(Message): -
trunk/sandbox/jhb/oc2/mint.py
r271 r272 61 61 message = authorizedMessage.message 62 62 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 63 86 result = [] 64 87 for keyid,blind in blinds: … … 77 100 78 101 return answer 79 80 def handleExchangeRequest(self,message):81 coins = message.coins82 blinds = message.blinds83 84 85 102 86 103 def addToTransactions(self,transactionId,result): -
trunk/sandbox/jhb/oc2/protocols.py
r271 r272 123 123 if type(authorizedMessage) == messages.Error: 124 124 return messages.TransferReject() 125 return self.mint.handleMintingRequest(authorizedMessage) 125 else: 126 return self.mint.handleMintingRequest(authorizedMessage) 126 127 127 128 elif requesttype == 'exchange': 128 129 return self.mint.handleExchangeRequest(message) 129 130 131 else: 132 return messages.TransferReject() 130 133 131 134 … … 228 231 class SpendListen(Protocol): 229 232 230 def __init__(self,wallet): 231 self.wallet = wallet 233 def __init__(self,wallet,client=None): 234 self.wallet = wallet 235 self.client = client 232 236 233 237 def run(self,message=None): -
trunk/sandbox/jhb/oc2/rsa.py
r263 r272 162 162 163 163 def generate(bits): #needed 164 return (dummypub,dummypriv)164 #return (dummypub,dummypriv) 165 165 p = getRandomPrime(bits/2, False) 166 166 q = getRandomPrime(bits/2, False) -
trunk/sandbox/jhb/oc2/testclient.py
r271 r272 1 1 import BaseHTTPServer, threading 2 import protocols, issuer, mint, transports, urllib 3 2 import protocols, transports, urllib 4 3 5 4 class Handler(BaseHTTPServer.BaseHTTPRequestHandler): 6 5 7 6 def do_POST(self): 8 #print self.server 7 8 wallet = self.server.wallet 9 client = self.server.walletclient 10 9 11 if self.path == '/stop': 10 12 raise 'foobar' … … 13 15 data = urllib.unquote(data) 14 16 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) 23 20 24 21 answer = protocol.run(message) … … 29 26 30 27 28 class Client(object): 31 29 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 42 33 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 14 14 blank.setNewSerial() 15 15 return blank 16 17 def blanksFromCoins(self,coins): 18 pass 16 19 17 20 def makeSerial(self): … … 38 41 return approval 39 42 40 43
