Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first sprint of UEFA tsml ticket #275

Merged
merged 1 commit into from
Nov 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions examples/UEFA/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
XMLSECTOOL=xmlsectool
KEYSTORE=
KEY=1
KEYPASSWORD=
SIGNATURE_ALGORITHM=rsa-sha256

help:
# Needs a target, example: $$ make EntryToken.canonicalized.xml
#
# Let's say you have a TokenScript "EntryToken.xml"
#- to validate and canonicalize, add 'canonicalized' in the filename
@echo $$ make EntryToken.canonicalized.xml
# - to sign, use tsml as file extension:
@echo $$ make EntryToken.tsml

%.canonicalized.xml : %.xml
# xmlsectool canonicalises automatically when needed, but leaving an xml:base attribute which creates trouble later.
# xmlstarlet does it neatly
# XML Canonicalization
xmlstarlet c14n $^ > $@
# xmlsectool validates too, albeit adding xml:base with breaks schema. Example:
# JVMOPTS=-Djavax.xml.accessExternalDTD=all /opt/xmlsectool-2.0.0/xmlsectool.sh --validateSchema --xsd --schemaDirectory ../../schema --inFile $^
# XML Validation
# if INVALID, run validation again with xmllint to get meaningful error
# then delete the canonicalized file
-xmlstarlet val --xsd http://tokenscript.org/2019/10/tokenscript/tokenscript.xsd $@ || (mv $@ $@.INVALID; xmllint --noout --schema http://tokenscript.org/2019/10/tokenscript/tokenscript.xsd $@.INVALID)

%.tsml: %.canonicalized.xml
ifeq (,$(KEYSTORE))
@echo ---------------- Keystore missing. Try this ----------------
@echo $$ make KEYSTORE=shong.wang.p12 KEYPASSWORD=shong.wang $@
@echo replace it with your .p12 file and your password
rm $^
else
$(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
# removing the canonicalized created for validation
rm $^
endif
147 changes: 147 additions & 0 deletions examples/UEFA/UEFA.en.shtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
<script type="text/javascript">
(function() {
'use strict'

function GeneralizedTime(generalizedTime) {
this.rawData = generalizedTime;
}

GeneralizedTime.prototype.getYear = function () {
return parseInt(this.rawData.substring(0, 4), 10);
}

GeneralizedTime.prototype.getMonth = function () {
return parseInt(this.rawData.substring(4, 6), 10) - 1;
}

GeneralizedTime.prototype.getDay = function () {
return parseInt(this.rawData.substring(6, 8), 10)
},

GeneralizedTime.prototype.getHours = function () {
return parseInt(this.rawData.substring(8, 10), 10)
},

GeneralizedTime.prototype.getMinutes = function () {
var minutes = parseInt(this.rawData.substring(10, 12), 10)
if (minutes) return minutes
return 0
},

GeneralizedTime.prototype.getSeconds = function () {
var seconds = parseInt(this.rawData.substring(12, 14), 10)
if (seconds) return seconds
return 0
},

GeneralizedTime.prototype.getMilliseconds = function () {
var startIdx
if (time.indexOf('.') !== -1) {
startIdx = this.rawData.indexOf('.') + 1
} else if (time.indexOf(',') !== -1) {
startIdx = this.rawData.indexOf(',') + 1
} else {
return 0
}

var stopIdx = time.length - 1
var fraction = '0' + '.' + time.substring(startIdx, stopIdx)
var ms = parseFloat(fraction) * 1000
return ms
},

GeneralizedTime.prototype.getTimeZone = function () {
let time = this.rawData;
var length = time.length
var symbolIdx
if (time.charAt(length - 1 ) === 'Z') return 0
if (time.indexOf('+') !== -1) {
symbolIdx = time.indexOf('+')
} else if (time.indexOf('-') !== -1) {
symbolIdx = time.indexOf('-')
} else {
return NaN
}

var minutes = time.substring(symbolIdx + 2)
var hours = time.substring(symbolIdx + 1, symbolIdx + 2)
var one = (time.charAt(symbolIdx) === '+') ? 1 : -1

var intHr = one * parseInt(hours, 10) * 60 * 60 * 1000
var intMin = one * parseInt(minutes, 10) * 60 * 1000
var ms = minutes ? intHr + intMin : intHr
return ms
}

if (typeof exports === 'object') {
module.exports = GeneralizedTime
} else if (typeof define === 'function' &amp;&amp; define.amd) {
define(GeneralizedTime)
} else {
window.GeneralizedTime = GeneralizedTime
}
}())
</script>
<script type="text/javascript"><![CDATA[
class Token {
constructor(tokenInstance) {
this.props = tokenInstance
}

formatGeneralizedTimeToDate(str) {
const d = new GeneralizedTime(str)
return new Date(d.getYear(), d.getMonth(), d.getDay(), d.getHours(), d.getMinutes(), d.getSeconds()).toLocaleDateString()
}
formatGeneralizedTimeToTime(str) {
const d = new GeneralizedTime(str)
return new Date(d.getYear(), d.getMonth(), d.getDay(), d.getHours(), d.getMinutes(), d.getSeconds()).toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'})
}

render() {
let time;
let date;
if (this.props.time == null) {
time = ""
date = ""
} else {
time = this.formatGeneralizedTimeToTime(this.props.time.generalizedTime)
date = this.props.time == null ? "": this.formatGeneralizedTimeToDate(this.props.time.generalizedTime)
}
let redeemedMessage = "(Not redeemed)"
if(this.props.redeemed) {
redeemedMessage = "(Redeemed)"
}
return `<div>
<div>
<span class="tbml-count">x${this.props._count}</span>
<span class="tbml-category">${this.props.category}</span>
<span class="tbml-category">${redeemedMessage}</span>
</div>
<div>
<span class="tbml-venue">${this.props.venue}</span>
</div>
<div style="margin: 0px; padding:0px; clear: both; height: 6px">
&nbsp;
</div>
<div>
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADkAAAA5CAYAAACMGIOFAAAABGdBTUEAALGPC/xhBQAABw9JREFUaAXtWt1vFFUUP3d224JVqHyVXTSCjzYVBFMx/eTJJ1tQ+yA+iBLEIDGa+CBP4h+gMcYXYgR8sDxUacs/YD8DkgjWBB+lpHa3hbZQpNDdzs71nNmZ3Xvv3PlYk+IWd5L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j8X8FmUoebjG3Aod3lV9sZc1GPq/ifIfhWlT5KPP4N9JQx0JLsoS9Ej1Jibi64qp7ub912rlCsdI2mDuKH3yN4u3eLc9R1WDVnnIMY61W6g5Qgxf0P/UFw0L/BhyIAAAAASUVORK5CYII=" class="data-icon"/>
<span class="tbml-date">${date}</span>
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACcAAAA5CAYAAAC1fzLeAAAABGdBTUEAALGPC/xhBQAABhdJREFUaAXtWWtsFFUUPnd2u22XYpCHbRcIEptYg6hBEoHYbTDiD4NteJn4SDQmEh8R0ISgJqLgH0kTFXzGPz4S/VMKtCA/0KhdEGIsig8iGgxpCrutUEgUtu0+5vqd2b27d7Y7uzOgZmM6yface893z/nmnjvTO/cIyl5r+2TV0KXB9ZLkXYLkAkk0TdmyclQI8ekkEXz0k5YpFwpsJZtr+6LBwbjcK6RohX+fDhZEw5LEd4LEgfpJDdvfWyiSym6wsuJI9IahS7GjkswOIrmsCDGG1UgpV100409yw8s1FJebSNIdhcTYRyYWxzQ7mMOqw9Fm5dt4+JSsSSepEwPnq84y8oEydpsZN4RE0CO2TocGc0imaCdzYohxYSD6HEk5T8cjff34HVU/IpHK22XzykODi/Lt0tqKQ4NIJc3Ko0RK+c3K/rwNGrhYnKCK9siZE1LS9QqAAc90h0OvqTbL9kj0HczAY1rfSV/N5EW7b7tqWOsbp97XF50ev0TfYkauVUb4fxf+H1dtlvD/NPy/qvqEoF+7wzObec3NVZ2Qo4GWxh1a21KlUfUyBoxo/U3m6F971xz+o0nrs6lsi8dpn50YjbAvGxCNbMxRrd/i5MesBXKdINApRDrXzio9t8+IYobxsNBmZUOqFidSyeNtkejbSMDn1Yb8iW1jpsDalXfC9oTNd2ZgB/tSPpTkmG2RMyNYm9ZaU+P8ClBOYppfbO+NTsFMrFPYjBO5AWQ2jOVuCbRxZf4qJOgL4409LQ0v4dXh+rJeJW7R3a2h9YKMbYhUGNvZBbA8pjvcuA7rzf04ePREjhl0tzY+W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JzcANS7y+lt/VGcdgtm0thcjYhjk+d3bjwg7li1OA/VX5ajc2kVczNgZyV970Qy7r52Nld3sIcmAtz4l7rae1aEjpRP6nxVtRFNyKpn+HlNZwfktEwMI3vry/qg2Jboa1cu84IvoUb6gJOL5VbwzKxOKaxkTkwF+Xvb7lWOHNlqS1ZAAAAAElFTkSuQmCC" class="data-icon"/>
<span class="tbml-date">${this.props.countryA}-${this.props.countryB}</span>
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAC0AAAA5CAYAAACiXaIXAAAABGdBTUEAALGPC/xhBQAABkxJREFUaAXtWl1sVEUUnnPv3UUoFEH52R9JTMAYTIkRkEJ3F2MwCC9gYFvaiARMfCMSozExGmp8MD5oQH1RjBCI9GeJGiEBAX96d9uA8qAkrUYMiL3blvJvS7vd7p3xzLaz3C47t9ttu90mTHIzM+fOOee7s2fONzMtkMFSdaZ1UX8c1mB3ISMEhHyiagB2WSHwc53f+3s6hiS48nDrm4yR9/BxpA+Y0D4iVwjZW+f3vAbYFligQo9uMBn9VggKsQZQdoYCnk8FNoUS9rroFG7N3rBig2CD0c0IK+JCAPI9mVZUMSNmUuugfLf7NAX64717KGPbhW9wFD8UWjXzBu9rAnDyJRAjtGz2bTFwIuugHv2HkFQYE7W/m09sEjTG+eQr90Hn6ze7P9P5mmnNzlGwmTnZjehO5KKVuJIvak7nhzWl867Y6eTjnS1oct34DrPOWpF4+uPxF186a5QcXOG9LsAF9fangSXWY5J3CtmIayAmUCVct9p9MhtdKeiKiFFqmmztECOMuHr6yCsoe5/Lg02dC0miL4JM5CC4ccm5JFVNskU31tQGvD8MZ8dmITJ3JmUgd+WKGX98LDdZCUJKMvlMl0lBA3ngDNJ6b7oCAfVHIZs733MKxzSI/mhqtNMyVdUOZ2NDGh61vjltm/XoDpzZfUj10zFm+Y+4J+R3fyMMf7II+rD9TFX41ixVieW8rQUtYVrXibAvq6WgucKRgKc2eO7GcYjFSojivBRa9XA0k6HD/gdvZpKPl8wWNHc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utu1qaXjwC8HyiLGJmQQNMS8a7cXF+FYo4E3dmuJuD28PyLbBx87PmL6TguZe6n3enzCuF1Tqbd7iae6Oz5cNZcMxRTICY7aguZ3BTX/rCGyO+1BpTI+751E4uA96FJM3ItVJOtPWf7NhUDAfAYwOwaJOQYYYLBpeV/6N7UW8j6eUjeW6QZCUef6d0IIInk8BQPKJr/C0iz6mPDiOcAdAMzILgW/n966FVHAzdjIEkDrvK8Wq820EfqGQQA7BAtDpdMJOq0z50jenq1idgrs55eMkeEuMWwfmvQ1wGYntgMPpWPJVqdew+v8fu3U3JdSdTg8AAAAASUVORK5CYII=" class="data-icon"/>
<span class="tbml-date">M${this.props.match}</span>
</div>
<div>
<span class="tbml-time">${time}, &nbsp;${this.props.locality}</span>
</div>
</div>`;
}
}

web3.tokens.dataChanged = (oldTokens, updatedTokens) => {
const currentTokenInstance = web3.tokens.data.currentInstance;
const domHtml = new Token(currentTokenInstance).render();
document.getElementById('root').innerHTML = domHtml
};
]]></script>
<div id="root"></div>
Loading