Skip to content

Commit 019f473

Browse files
Merge pull request #275 from AlphaWallet/UEFA
first sprint of UEFA tsml ticket
2 parents 965f10c + d7312dd commit 019f473

File tree

4 files changed

+461
-0
lines changed

4 files changed

+461
-0
lines changed

examples/UEFA/Makefile

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
XMLSECTOOL=xmlsectool
2+
KEYSTORE=
3+
KEY=1
4+
KEYPASSWORD=
5+
SIGNATURE_ALGORITHM=rsa-sha256
6+
7+
help:
8+
# Needs a target, example: $$ make EntryToken.canonicalized.xml
9+
#
10+
# Let's say you have a TokenScript "EntryToken.xml"
11+
#- to validate and canonicalize, add 'canonicalized' in the filename
12+
@echo $$ make EntryToken.canonicalized.xml
13+
# - to sign, use tsml as file extension:
14+
@echo $$ make EntryToken.tsml
15+
16+
%.canonicalized.xml : %.xml
17+
# xmlsectool canonicalises automatically when needed, but leaving an xml:base attribute which creates trouble later.
18+
# xmlstarlet does it neatly
19+
# XML Canonicalization
20+
xmlstarlet c14n $^ > $@
21+
# xmlsectool validates too, albeit adding xml:base with breaks schema. Example:
22+
# JVMOPTS=-Djavax.xml.accessExternalDTD=all /opt/xmlsectool-2.0.0/xmlsectool.sh --validateSchema --xsd --schemaDirectory ../../schema --inFile $^
23+
# XML Validation
24+
# if INVALID, run validation again with xmllint to get meaningful error
25+
# then delete the canonicalized file
26+
-xmlstarlet val --xsd http://tokenscript.org/2019/10/tokenscript/tokenscript.xsd $@ || (mv $@ [email protected]; xmllint --noout --schema http://tokenscript.org/2019/10/tokenscript/tokenscript.xsd [email protected])
27+
28+
%.tsml: %.canonicalized.xml
29+
ifeq (,$(KEYSTORE))
30+
@echo ---------------- Keystore missing. Try this ----------------
31+
@echo $$ make KEYSTORE=shong.wang.p12 KEYPASSWORD=shong.wang $@
32+
@echo replace it with your .p12 file and your password
33+
rm $^
34+
else
35+
$(XMLSECTOOL) --sign --keyInfoKeyName 'Shong Wang' --digest SHA-256 --signatureAlgorithm http://www.w3.org/2001/04/xmldsig-more#$(SIGNATURE_ALGORITHM) --inFile $^ --outFile $@ --keystore $(KEYSTORE) --keystoreType PKCS12 --key $(KEY) --keyPassword $(KEYPASSWORD) --signaturePosition LAST
36+
# removing the canonicalized created for validation
37+
rm $^
38+
endif

examples/UEFA/UEFA.en.shtml

+147
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
<script type="text/javascript">
2+
(function() {
3+
'use strict'
4+
5+
function GeneralizedTime(generalizedTime) {
6+
this.rawData = generalizedTime;
7+
}
8+
9+
GeneralizedTime.prototype.getYear = function () {
10+
return parseInt(this.rawData.substring(0, 4), 10);
11+
}
12+
13+
GeneralizedTime.prototype.getMonth = function () {
14+
return parseInt(this.rawData.substring(4, 6), 10) - 1;
15+
}
16+
17+
GeneralizedTime.prototype.getDay = function () {
18+
return parseInt(this.rawData.substring(6, 8), 10)
19+
},
20+
21+
GeneralizedTime.prototype.getHours = function () {
22+
return parseInt(this.rawData.substring(8, 10), 10)
23+
},
24+
25+
GeneralizedTime.prototype.getMinutes = function () {
26+
var minutes = parseInt(this.rawData.substring(10, 12), 10)
27+
if (minutes) return minutes
28+
return 0
29+
},
30+
31+
GeneralizedTime.prototype.getSeconds = function () {
32+
var seconds = parseInt(this.rawData.substring(12, 14), 10)
33+
if (seconds) return seconds
34+
return 0
35+
},
36+
37+
GeneralizedTime.prototype.getMilliseconds = function () {
38+
var startIdx
39+
if (time.indexOf('.') !== -1) {
40+
startIdx = this.rawData.indexOf('.') + 1
41+
} else if (time.indexOf(',') !== -1) {
42+
startIdx = this.rawData.indexOf(',') + 1
43+
} else {
44+
return 0
45+
}
46+
47+
var stopIdx = time.length - 1
48+
var fraction = '0' + '.' + time.substring(startIdx, stopIdx)
49+
var ms = parseFloat(fraction) * 1000
50+
return ms
51+
},
52+
53+
GeneralizedTime.prototype.getTimeZone = function () {
54+
let time = this.rawData;
55+
var length = time.length
56+
var symbolIdx
57+
if (time.charAt(length - 1 ) === 'Z') return 0
58+
if (time.indexOf('+') !== -1) {
59+
symbolIdx = time.indexOf('+')
60+
} else if (time.indexOf('-') !== -1) {
61+
symbolIdx = time.indexOf('-')
62+
} else {
63+
return NaN
64+
}
65+
66+
var minutes = time.substring(symbolIdx + 2)
67+
var hours = time.substring(symbolIdx + 1, symbolIdx + 2)
68+
var one = (time.charAt(symbolIdx) === '+') ? 1 : -1
69+
70+
var intHr = one * parseInt(hours, 10) * 60 * 60 * 1000
71+
var intMin = one * parseInt(minutes, 10) * 60 * 1000
72+
var ms = minutes ? intHr + intMin : intHr
73+
return ms
74+
}
75+
76+
if (typeof exports === 'object') {
77+
module.exports = GeneralizedTime
78+
} else if (typeof define === 'function' &amp;&amp; define.amd) {
79+
define(GeneralizedTime)
80+
} else {
81+
window.GeneralizedTime = GeneralizedTime
82+
}
83+
}())
84+
</script>
85+
<script type="text/javascript"><![CDATA[
86+
class Token {
87+
constructor(tokenInstance) {
88+
this.props = tokenInstance
89+
}
90+
91+
formatGeneralizedTimeToDate(str) {
92+
const d = new GeneralizedTime(str)
93+
return new Date(d.getYear(), d.getMonth(), d.getDay(), d.getHours(), d.getMinutes(), d.getSeconds()).toLocaleDateString()
94+
}
95+
formatGeneralizedTimeToTime(str) {
96+
const d = new GeneralizedTime(str)
97+
return new Date(d.getYear(), d.getMonth(), d.getDay(), d.getHours(), d.getMinutes(), d.getSeconds()).toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'})
98+
}
99+
100+
render() {
101+
let time;
102+
let date;
103+
if (this.props.time == null) {
104+
time = ""
105+
date = ""
106+
} else {
107+
time = this.formatGeneralizedTimeToTime(this.props.time.generalizedTime)
108+
date = this.props.time == null ? "": this.formatGeneralizedTimeToDate(this.props.time.generalizedTime)
109+
}
110+
let redeemedMessage = "(Not redeemed)"
111+
if(this.props.redeemed) {
112+
redeemedMessage = "(Redeemed)"
113+
}
114+
return `<div>
115+
<div>
116+
<span class="tbml-count">x${this.props._count}</span>
117+
<span class="tbml-category">${this.props.category}</span>
118+
<span class="tbml-category">${redeemedMessage}</span>
119+
</div>
120+
<div>
121+
<span class="tbml-venue">${this.props.venue}</span>
122+
</div>
123+
<div style="margin: 0px; padding:0px; clear: both; height: 6px">
124+
&nbsp;
125+
</div>
126+
<div>
127+
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADkAAAA5CAYAAACMGIOFAAAABGdBTUEAALGPC/xhBQAABw9JREFUaAXtWt1vFFUUP3d224JVqHyVXTSCjzYVBFMx/eTJJ1tQ+yA+iBLEIDGa+CBP4h+gMcYXYgR8sDxUacs/YD8DkgjWBB+lpHa3hbZQpNDdzs71nNmZ3Xvv3PlYk+IWd5LNnM/fPWdm7p1zzyyDEo8DYzMvW2buFAB/Gl17qtuSH/YylguD6b58c2t2yTwLHJqBwVj1mvih3qYt06F+nMeyw6mv0e4gAJs04rGjfc31F8P8RL0hMmE055xZOfNHDryRA9Th79jyaPpwmB/pM0vml+j/Cvo+Tmfio/gRPo2TH4832uNjHFF8XZuSknz9l/ltnEPSdaazBdAk8n40RiXZqbyfn4pP41McfvY6eUlJWjwb94Bw8Mo8RrZAtVN5vZcGXxuH3ts7cPc1Xp1ZuNVg5HLrRR/D4NfPNydviDIdvX8k3SHKGRi3+1rrx0WZjt4/dnMXWLk6UdffmhgUeR29/2J6O5iwXdRZsdhCzfrN13obWNaV21ezc/TWE8xa/iI7l3obF4ZqfESkwwLjJAo+l4QaxrKsn0UxY3wQ+X2iTEfjPPsKOG9XdEzhvWzWOoSxfiYpLAswj2znUOosxKo+udCy+W+D7h5Y2VFcDI7g814tOZQ5Y+Ejpgsxnwd/D/MaofyMzPz0Cbx7z+uMV72Mw87s3PSnBuP81VWfTGACvBPnJG8UbRiwCW6ws6IsxmFQ5H1pw567BbVhwUSBCSBinJ3JGUyazwHmBRXFhc+rtFZwxg7h1HumYIT5xT3zkMHEhdaE5Fh0CKb+rV9fe+L7YGS9tq8tMYQa+hWOzuFUBzKFJCm/kt6ThoUuysFwWVREehZLHUmh8pKyyOjwdXEU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FQYxkX8NW9qA6i8D0KDztbtlzDgt5pQqlah0e9bedVe/BkE7aYj0uW6riQq5x3oSIYdyFN+IgE7kLUAajoxl1Ix30I3oWoxTnh0Gd63IWMB+1CetvCi3PCKqniIYdyP3QVT6Q5We6JhcVXSTLsCq0WfaSFh5KptD8AKu2PwMe60v4IvDzwUNsfuLdIBbU/MFTpm6YQ+hJW2L7tD8IVbIvkSrY/3ro0t26RZ6X2x3+x1apl1fM/7N14t5h1kdIVA5FXV4JxgD3gYfudSvujeBNWjKpUPCt2aR8ycOVOPuQLvmLDMVxyF7B3s84dAf/CsoDtod9cfrWdsY+/C/8HVfy/LmN347j8X8FmUoebjG3Aod3lV9sZc1GPq/ifIfhWlT5KPP4N9JQx0JLsoS9Ej1Jibi64qp7ub912rlCsdI2mDuKH3yN4u3eLc9R1WDVnnIMY61W6g5Qgxf0P/UFw0L/BhyIAAAAASUVORK5CYII=" class="data-icon"/>
128+
<span class="tbml-date">${date}</span>
129+
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACcAAAA5CAYAAAC1fzLeAAAABGdBTUEAALGPC/xhBQAABhdJREFUaAXtWWtsFFUUPnd2u22XYpCHbRcIEptYg6hBEoHYbTDiD4NteJn4SDQmEh8R0ISgJqLgH0kTFXzGPz4S/VMKtCA/0KhdEGIsig8iGgxpCrutUEgUtu0+5vqd2b27d7Y7uzOgZmM6yface893z/nmnjvTO/cIyl5r+2TV0KXB9ZLkXYLkAkk0TdmyclQI8ekkEXz0k5YpFwpsJZtr+6LBwbjcK6RohX+fDhZEw5LEd4LEgfpJDdvfWyiSym6wsuJI9IahS7GjkswOIrmsCDGG1UgpV100409yw8s1FJebSNIdhcTYRyYWxzQ7mMOqw9Fm5dt4+JSsSSepEwPnq84y8oEydpsZN4RE0CO2TocGc0imaCdzYohxYSD6HEk5T8cjff34HVU/IpHK22XzykODi/Lt0tqKQ4NIJc3Ko0RK+c3K/rwNGrhYnKCK9siZE1LS9QqAAc90h0OvqTbL9kj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EQinixHda5XClShYGYJM78UP3ZXmgq13ZNrv1gbAtOH5/SHaJYl8CR0+skjOXVPjGHf6xzn2XTwFyWQv1si9ZVVuWS5pgqhAE9Wh0O1RUW59oOnQ0JM3ESuNzRKKoz3wT8/gc7l1xzslgUrhomksmPsAYXKztXHqURaCoszq2R0jcWiV4EzirM8Y2h1lbNM3dKDWZj4mBs3HeCMJMv6MQwM6eCQVruRIz9sc2omXwP1Bx59sG+2K5f2ZgWsWy/xYlnDunKlyrZiFnphziXBWLd0814BnOvHcMwlu5pafxK2UtJrmqn0ukjeQxXqumHfJumYz3P0dqIT1u5Sim4nn5+INZXWErXwbqOgQN7WkJzcANS7y+lt/VGcdgtm0thcjYhjk+d3bjwg7li1OA/VX5ajc2kVczNgZyV970Qy7r52Nld3sIcmAtz4l7rae1aEjpRP6nxVtRFNyKpn+HlNZwfktEwMI3vry/qg2Jboa1cu84IvoUb6gJOL5VbwzKxOKaxkTkwF+Xvb7lWOHNlqS1ZAAAAAElFTkSuQmCC" class="data-icon"/>
130+
<span class="tbml-date">${this.props.countryA}-${this.props.countryB}</span>
131+
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAC0AAAA5CAYAAACiXaIXAAAABGdBTUEAALGPC/xhBQAABkxJREFUaAXtWl1sVEUUnnPv3UUoFEH52R9JTMAYTIkRkEJ3F2MwCC9gYFvaiARMfCMSozExGmp8MD5oQH1RjBCI9GeJGiEBAX96d9uA8qAkrUYMiL3blvJvS7vd7p3xzLaz3C47t9ttu90mTHIzM+fOOee7s2fONzMtkMFSdaZ1UX8c1mB3ISMEhHyiagB2WSHwc53f+3s6hiS48nDrm4yR9/BxpA+Y0D4iVwjZW+f3vAbYFligQo9uMBn9VggKsQZQdoYCnk8FNoUS9rroFG7N3rBig2CD0c0IK+JCAPI9mVZUMSNmUuugfLf7NAX64717KGPbhW9wFD8UWjXzBu9rAnDyJRAjtGz2bTFwIuugHv2HkFQYE7W/m09sEjTG+eQr90Hn6ze7P9P5mm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7TwEyHqvx6uMx9Wdi2q6WguVJotXcXLr5jGCYrKVMuzprmqkem7LcaPFQ2vxP7qXOj9d14tW1Bc6f1fs9prPhTMEUa0wWDMAOQSQnaNjz4fUac3qnGneNK3DpeAlDfDQVcqeyRYRLyIpKCRubTmsPRU3gmWZpkRMKWM2Kuq2psK7Gu8nK9DffSdMOojlsENwpE0Y8E7mYmu6+Xgm4Od5QhcSwdoszYjETC5IxYzeWVeuuSfkK/5iQ08GFcmkvh2uZWnIBr9QH3sH/TlMe0QmdmdA+QkptEdWVkzYyKWQgZ82QxikhBT3WwRiSTm+lGkG6PCtliv+sU/v36IB4cuzij5fqgfg/6OjFddR4Utu1qaXjwC8HyiLGJmQQNMS8a7cXF+FYo4E3dmuJuD28PyLbBx87PmL6TguZe6n3enzCuF1Tqbd7iae6Oz5cNZcMxRTICY7aguZ3BTX/rCGyO+1BpTI+751E4uA96FJM3ItVJOtPWf7NhUDAfAYwOwaJOQYYYLBpeV/6N7UW8j6eUjeW6QZCUef6d0IIInk8BQPKJr/C0iz6mPDiOcAdAMzILgW/n966FVHAzdjIEkDrvK8Wq820EfqGQQA7BAtDpdMJOq0z50jenq1idgrs55eMkeEuMWwfmvQ1wGYntgMPpWPJVqdew+v8fu3U3JdSdTg8AAAAASUVORK5CYII=" class="data-icon"/>
132+
<span class="tbml-date">M${this.props.match}</span>
133+
</div>
134+
<div>
135+
<span class="tbml-time">${time}, &nbsp;${this.props.locality}</span>
136+
</div>
137+
</div>`;
138+
}
139+
}
140+
141+
web3.tokens.dataChanged = (oldTokens, updatedTokens) => {
142+
const currentTokenInstance = web3.tokens.data.currentInstance;
143+
const domHtml = new Token(currentTokenInstance).render();
144+
document.getElementById('root').innerHTML = domHtml
145+
};
146+
]]></script>
147+
<div id="root"></div>

0 commit comments

Comments
 (0)