Diffstat (limited to 'frontend/gamma/js/Clipperz/PM/Toll.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/gamma/js/Clipperz/PM/Toll.js | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/frontend/gamma/js/Clipperz/PM/Toll.js b/frontend/gamma/js/Clipperz/PM/Toll.js index a533f51..bb31c43 100644 --- a/frontend/gamma/js/Clipperz/PM/Toll.js +++ b/frontend/gamma/js/Clipperz/PM/Toll.js | |||
@@ -1,120 +1,117 @@ | |||
1 | /* | 1 | /* |
2 | 2 | ||
3 | Copyright 2008-2011 Clipperz Srl | 3 | Copyright 2008-2011 Clipperz Srl |
4 | 4 | ||
5 | This file is part of Clipperz's Javascript Crypto Library. | 5 | This file is part of Clipperz Community Edition. |
6 | Javascript Crypto Library provides web developers with an extensive | 6 | Clipperz Community Edition is an online password manager. |
7 | and efficient set of cryptographic functions. The library aims to | ||
8 | obtain maximum execution speed while preserving modularity and | ||
9 | reusability. | ||
10 | For further information about its features and functionalities please | 7 | For further information about its features and functionalities please |
11 | refer to http://www.clipperz.com | 8 | refer 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 | ||
29 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } | 26 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } |
30 | if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } | 27 | if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } |
31 | 28 | ||
32 | //============================================================================= | 29 | //============================================================================= |
33 | 30 | ||
34 | Clipperz.PM.Toll = function(args) { | 31 | Clipperz.PM.Toll = function(args) { |
35 | args = args || {}; | 32 | args = args || {}; |
36 | 33 | ||
37 | this._requestType = args.requestType; | 34 | this._requestType = args.requestType; |
38 | this._targetValue = args.targetValue; | 35 | this._targetValue = args.targetValue; |
39 | this._cost = args.cost; | 36 | this._cost = args.cost; |
40 | this._toll = null; | 37 | this._toll = null; |
41 | 38 | ||
42 | return this; | 39 | return this; |
43 | } | 40 | } |
44 | 41 | ||
45 | Clipperz.PM.Toll.prototype = MochiKit.Base.update(null, { | 42 | Clipperz.PM.Toll.prototype = MochiKit.Base.update(null, { |
46 | 43 | ||
47 | 'toString': function() { | 44 | 'toString': function() { |
48 | return "Clipperz.PM.Toll (" + this.requestType() + ": " + this.cost() + " - " + ((this.toll() == null)? 'UNPAID' : 'PAID') + ")"; | 45 | return "Clipperz.PM.Toll (" + this.requestType() + ": " + this.cost() + " - " + ((this.toll() == null)? 'UNPAID' : 'PAID') + ")"; |
49 | }, | 46 | }, |
50 | 47 | ||
51 | //------------------------------------------------------------------------- | 48 | //------------------------------------------------------------------------- |
52 | 49 | ||
53 | 'requestType': function() { | 50 | 'requestType': function() { |
54 | return this._requestType; | 51 | return this._requestType; |
55 | }, | 52 | }, |
56 | 53 | ||
57 | //------------------------------------------------------------------------- | 54 | //------------------------------------------------------------------------- |
58 | 55 | ||
59 | 'targetValue': function() { | 56 | 'targetValue': function() { |
60 | return this._targetValue; | 57 | return this._targetValue; |
61 | }, | 58 | }, |
62 | 59 | ||
63 | //------------------------------------------------------------------------- | 60 | //------------------------------------------------------------------------- |
64 | 61 | ||
65 | 'cost': function() { | 62 | 'cost': function() { |
66 | return this._cost; | 63 | return this._cost; |
67 | }, | 64 | }, |
68 | 65 | ||
69 | //------------------------------------------------------------------------- | 66 | //------------------------------------------------------------------------- |
70 | 67 | ||
71 | 'toll': function() { | 68 | 'toll': function() { |
72 | return this._toll; | 69 | return this._toll; |
73 | }, | 70 | }, |
74 | 71 | ||
75 | //------------------------------------------------------------------------- | 72 | //------------------------------------------------------------------------- |
76 | /* | 73 | /* |
77 | '__pay': function() { | 74 | '__pay': function() { |
78 | varresult; | 75 | varresult; |
79 | vartargetData; | 76 | vartargetData; |
80 | vartargetMatchSize; | 77 | vartargetMatchSize; |
81 | var prefixMatchingBits; | 78 | var prefixMatchingBits; |
82 | varpayment; | 79 | varpayment; |
83 | var i; | 80 | var i; |
84 | 81 | ||
85 | if (this.toll() == null) { | 82 | if (this.toll() == null) { |
86 | i = 0; | 83 | i = 0; |
87 | targetData = new Clipperz.ByteArray("0x" + this.targetValue()); | 84 | targetData = new Clipperz.ByteArray("0x" + this.targetValue()); |
88 | targetMatchSize = this.cost(); | 85 | targetMatchSize = this.cost(); |
89 | 86 | ||
90 | payment = Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(32); | 87 | payment = Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(32); |
91 | 88 | ||
92 | do { | 89 | do { |
93 | varpaymentData; | 90 | varpaymentData; |
94 | 91 | ||
95 | //payment = Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(32); | 92 | //payment = Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(32); |
96 | payment.increment(); | 93 | payment.increment(); |
97 | paymentData = Clipperz.Crypto.SHA.sha256(payment); | 94 | paymentData = Clipperz.Crypto.SHA.sha256(payment); |
98 | // prefixMatchingBits = this.prefixMatchingBits(targetData, paymentData); | 95 | // prefixMatchingBits = this.prefixMatchingBits(targetData, paymentData); |
99 | prefixMatchingBits = Clipperz.ByteArray.prefixMatchingBits(targetData, paymentData); | 96 | prefixMatchingBits = Clipperz.ByteArray.prefixMatchingBits(targetData, paymentData); |
100 | i++; | 97 | i++; |
101 | } while (prefixMatchingBits < targetMatchSize); | 98 | } while (prefixMatchingBits < targetMatchSize); |
102 | 99 | ||
103 | this._toll = payment.toHexString().substring(2) | 100 | this._toll = payment.toHexString().substring(2) |
104 | } | 101 | } |
105 | 102 | ||
106 | return this; | 103 | return this; |
107 | }, | 104 | }, |
108 | */ | 105 | */ |
109 | //------------------------------------------------------------------------- | 106 | //------------------------------------------------------------------------- |
110 | 107 | ||
111 | 'innerDeferredPay': function (aTargetValue, aCost, aPayment) { | 108 | 'innerDeferredPay': function (aTargetValue, aCost, aPayment) { |
112 | var deferredResult; | 109 | var deferredResult; |
113 | var result; | 110 | var result; |
114 | var payment; | 111 | var payment; |
115 | var i; | 112 | var i; |
116 | 113 | ||
117 | result = null; | 114 | result = null; |
118 | payment = aPayment; | 115 | payment = aPayment; |
119 | i = 0; | 116 | i = 0; |
120 | 117 | ||