summaryrefslogtreecommitdiff
path: root/frontend/beta/js/Clipperz/PM/Toll.js
Unidiff
Diffstat (limited to 'frontend/beta/js/Clipperz/PM/Toll.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/beta/js/Clipperz/PM/Toll.js15
1 files changed, 6 insertions, 9 deletions
diff --git a/frontend/beta/js/Clipperz/PM/Toll.js b/frontend/beta/js/Clipperz/PM/Toll.js
index 6d412c1..3a9b48f 100644
--- a/frontend/beta/js/Clipperz/PM/Toll.js
+++ b/frontend/beta/js/Clipperz/PM/Toll.js
@@ -1,152 +1,149 @@
1/* 1/*
2 2
3Copyright 2008-2011 Clipperz Srl 3Copyright 2008-2011 Clipperz Srl
4 4
5This file is part of Clipperz's Javascript Crypto Library. 5This file is part of Clipperz Community Edition.
6Javascript Crypto Library provides web developers with an extensive 6Clipperz Community Edition is an online password manager.
7and efficient set of cryptographic functions. The library aims to
8obtain maximum execution speed while preserving modularity and
9reusability.
10For further information about its features and functionalities please 7For further information about its features and functionalities please
11refer to http://www.clipperz.com 8refer to http://www.clipperz.com.
12 9
13* Javascript Crypto Library is free software: you can redistribute 10* Clipperz Community Edition is free software: you can redistribute
14 it and/or modify it under the terms of the GNU Affero General Public 11 it and/or modify it under the terms of the GNU Affero General Public
15 License as published by the Free Software Foundation, either version 12 License as published by the Free Software Foundation, either version
16 3 of the License, or (at your option) any later version. 13 3 of the License, or (at your option) any later version.
17 14
18* Javascript Crypto Library is distributed in the hope that it will 15* Clipperz Community Edition is distributed in the hope that it will
19 be useful, but WITHOUT ANY WARRANTY; without even the implied 16 be useful, but WITHOUT ANY WARRANTY; without even the implied
20 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 17 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21 See the GNU Affero General Public License for more details. 18 See the GNU Affero General Public License for more details.
22 19
23* You should have received a copy of the GNU Affero General Public 20* You should have received a copy of the GNU Affero General Public
24 License along with Javascript Crypto Library. If not, see 21 License along with Clipperz Community Edition. If not, see
25 <http://www.gnu.org/licenses/>. 22 <http://www.gnu.org/licenses/>.
26 23
27*/ 24*/
28 25
29if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } 26if (typeof(Clipperz) == 'undefined') { Clipperz = {}; }
30if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } 27if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; }
31 28
32//============================================================================= 29//=============================================================================
33 30
34Clipperz.PM.Toll = function(args) { 31Clipperz.PM.Toll = function(args) {
35 this._requestType = args.requestType; 32 this._requestType = args.requestType;
36 this._targetValue = args.targetValue; 33 this._targetValue = args.targetValue;
37 this._cost = args.cost; 34 this._cost = args.cost;
38 this._toll = null; 35 this._toll = null;
39 36
40 return this; 37 return this;
41} 38}
42 39
43Clipperz.PM.Toll.prototype = MochiKit.Base.update(null, { 40Clipperz.PM.Toll.prototype = MochiKit.Base.update(null, {
44 41
45 'toString': function() { 42 'toString': function() {
46 return "Clipperz.PM.Toll (" + this.requestType() + ": " + this.cost() + " - " + ((this.toll() == null)? 'UNPAID' : 'PAID') + ")"; 43 return "Clipperz.PM.Toll (" + this.requestType() + ": " + this.cost() + " - " + ((this.toll() == null)? 'UNPAID' : 'PAID') + ")";
47 }, 44 },
48 45
49 //------------------------------------------------------------------------- 46 //-------------------------------------------------------------------------
50 47
51 'requestType': function() { 48 'requestType': function() {
52 return this._requestType; 49 return this._requestType;
53 }, 50 },
54 51
55 //------------------------------------------------------------------------- 52 //-------------------------------------------------------------------------
56 53
57 'targetValue': function() { 54 'targetValue': function() {
58 return this._targetValue; 55 return this._targetValue;
59 }, 56 },
60 57
61 //------------------------------------------------------------------------- 58 //-------------------------------------------------------------------------
62 59
63 'cost': function() { 60 'cost': function() {
64 return this._cost; 61 return this._cost;
65 }, 62 },
66 63
67 //------------------------------------------------------------------------- 64 //-------------------------------------------------------------------------
68 65
69 'toll': function() { 66 'toll': function() {
70 return this._toll; 67 return this._toll;
71 }, 68 },
72 69
73 //========================================================================= 70 //=========================================================================
74 71
75 'prefixMatchingBits': function(aValue1, aValue2) { 72 'prefixMatchingBits': function(aValue1, aValue2) {
76 varresult; 73 varresult;
77 var i,c; 74 var i,c;
78 75
79 result = 0; 76 result = 0;
80 77
81 c = Math.min(aValue1.length(), aValue2.length()); 78 c = Math.min(aValue1.length(), aValue2.length());
82 i = 0; 79 i = 0;
83 while (i<c && (aValue1.byteAtIndex(i) == aValue2.byteAtIndex(i))) { 80 while (i<c && (aValue1.byteAtIndex(i) == aValue2.byteAtIndex(i))) {
84 result += 8; 81 result += 8;
85 i++; 82 i++;
86 } 83 }
87 84
88 if (i<c) { 85 if (i<c) {
89 varxorValue; 86 varxorValue;
90 87
91 xorValue = (aValue1.byteAtIndex(i) ^ aValue2.byteAtIndex(i)); 88 xorValue = (aValue1.byteAtIndex(i) ^ aValue2.byteAtIndex(i));
92 89
93 if (xorValue >= 128) { 90 if (xorValue >= 128) {
94 result += 0; 91 result += 0;
95 } else if (xorValue >= 64) { 92 } else if (xorValue >= 64) {
96 result += 1; 93 result += 1;
97 } else if (xorValue >= 32) { 94 } else if (xorValue >= 32) {
98 result += 2; 95 result += 2;
99 } else if (xorValue >= 16) { 96 } else if (xorValue >= 16) {
100 result += 3; 97 result += 3;
101 } else if (xorValue >= 8) { 98 } else if (xorValue >= 8) {
102 result += 4; 99 result += 4;
103 } else if (xorValue >= 4) { 100 } else if (xorValue >= 4) {
104 result += 5; 101 result += 5;
105 } else if (xorValue >= 2) { 102 } else if (xorValue >= 2) {
106 result += 6; 103 result += 6;
107 } else if (xorValue >= 1) { 104 } else if (xorValue >= 1) {
108 result += 7; 105 result += 7;
109 } 106 }
110 } 107 }
111 108
112 return result; 109 return result;
113 }, 110 },
114 111
115 //========================================================================= 112 //=========================================================================
116 113
117 'pay': function() { 114 'pay': function() {
118 varresult; 115 varresult;
119 vartargetData; 116 vartargetData;
120 vartargetMatchSize; 117 vartargetMatchSize;
121 var prefixMatchingBits; 118 var prefixMatchingBits;
122 varpayment; 119 varpayment;
123 var i; 120 var i;
124 121
125//MochiKit.Logging.logDebug(">>> Toll.pay"); 122//MochiKit.Logging.logDebug(">>> Toll.pay");
126 if (this.toll() == null) { 123 if (this.toll() == null) {
127 i = 0; 124 i = 0;
128//MochiKit.Logging.logDebug("--- Proxy.payToll - 1"); 125//MochiKit.Logging.logDebug("--- Proxy.payToll - 1");
129 targetData = new Clipperz.ByteArray("0x" + this.targetValue()); 126 targetData = new Clipperz.ByteArray("0x" + this.targetValue());
130//MochiKit.Logging.logDebug("--- Proxy.payToll - 2"); 127//MochiKit.Logging.logDebug("--- Proxy.payToll - 2");
131 targetMatchSize = this.cost(); 128 targetMatchSize = this.cost();
132//MochiKit.Logging.logDebug("--- Proxy.payToll - 3"); 129//MochiKit.Logging.logDebug("--- Proxy.payToll - 3");
133 130
134 payment = Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(32); 131 payment = Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(32);
135//MochiKit.Logging.logDebug("--- Proxy.payToll - 4"); 132//MochiKit.Logging.logDebug("--- Proxy.payToll - 4");
136 133
137 do { 134 do {
138 varpaymentData; 135 varpaymentData;
139 136
140//MochiKit.Logging.logDebug("--- Proxy.payToll - 5"); 137//MochiKit.Logging.logDebug("--- Proxy.payToll - 5");
141 //payment = Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(32); 138 //payment = Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(32);
142 payment.increment(); 139 payment.increment();
143//MochiKit.Logging.logDebug("--- Proxy.payToll - 6"); 140//MochiKit.Logging.logDebug("--- Proxy.payToll - 6");
144 paymentData = Clipperz.Crypto.SHA.sha256(payment); 141 paymentData = Clipperz.Crypto.SHA.sha256(payment);
145//MochiKit.Logging.logDebug("--- Proxy.payToll - 7"); 142//MochiKit.Logging.logDebug("--- Proxy.payToll - 7");
146 prefixMatchingBits = this.prefixMatchingBits(targetData, paymentData); 143 prefixMatchingBits = this.prefixMatchingBits(targetData, paymentData);
147//MochiKit.Logging.logDebug("--- Proxy.payToll - 8"); 144//MochiKit.Logging.logDebug("--- Proxy.payToll - 8");
148 i++; 145 i++;
149//MochiKit.Logging.logDebug("--- Proxy.payToll - 9"); 146//MochiKit.Logging.logDebug("--- Proxy.payToll - 9");
150 } while (prefixMatchingBits < targetMatchSize); 147 } while (prefixMatchingBits < targetMatchSize);
151//MochiKit.Logging.logDebug("--- Proxy.payToll - 10"); 148//MochiKit.Logging.logDebug("--- Proxy.payToll - 10");
152 149