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

add release, subdomains and renew for ENS #258

Closed
wants to merge 10 commits into from
157 changes: 157 additions & 0 deletions examples/ENS/ENS.xml
@@ -0,0 +1,157 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE token [
<!ENTITY style SYSTEM "shared.css">
<!ENTITY release.en SYSTEM "release.en.shtml">
<!ENTITY subdomain.en SYSTEM "subdomain.en.shtml">
<!ENTITY renew.en SYSTEM "renew.en.shtml">
<!ENTITY bundle.en SYSTEM "bundle.js">
]>
<ts:token xmlns:ts="http://tokenscript.org/2019/10/tokenscript"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:xml="http://www.w3.org/XML/1998/namespace"
xsi:schemaLocation="http://tokenscript.org/2019/10/tokenscript http://tokenscript.org/2019/10/tokenscript.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
custodian="false"
>
<ts:name>
<ts:plurals xml:lang="en">
<ts:string quantity="one">ENS</ts:string>
</ts:plurals>
</ts:name>
<ts:contract interface="erc721" name="ENS">
<ts:address network="1">0xFaC7BEA255a6990f749363002136aF6556b31e04</ts:address>
</ts:contract>
<ts:contract name="registrar">
<ts:address network="1">0xF0AD5cAd05e10572EfcEB849f6Ff0c68f9700455</ts:address>
<ts:data objectClass="ENSName">
<ts:string name="name" />
<ts:bytes32 name="label" />
<ts:address name="owner"/>
<ts:uint name="cost"/>
<ts:uint name="expires"/>
</ts:data>
</ts:contract>
<ts:origins>
<!-- Define the contract which holds the token that the user will use -->
<ts:ethereum contract="ENS">
</ts:ethereum>
</ts:origins>

<ts:attribute-types>
<ts:attribute-type id="name" syntax="1.3.6.1.4.1.1466.115.121.1.15">
<ts:origins>
<ts:ethereum event="EventRegistered" filter="label=${tokenId}" value="name"/>
</ts:origins>
</ts:attribute-type>
</ts:attribute-types>
<ts:cards>

<ts:action>
<ts:name>
<ts:string xml:lang="en">Refund</ts:string>
</ts:name>
<ts:transaction>
<ts:ethereum function="releaseDeed" contract="ENS">
<ts:data>
<ts:bytes32 ref="tokenId"/>
</ts:data>
</ts:ethereum>
</ts:transaction>
<style type="text/css">&style;</style>
<ts:view xml:lang="en">&release.en;</ts:view>
</ts:action>

<ts:action>
<ts:name>
<ts:string xml:lang="en">Renew</ts:string>
</ts:name>

<ts:attribute-type id="renewalPricePerYear" syntax="1.3.6.1.4.1.1466.115.121.1.36">
<ts:name>
<ts:string xml:lang="en">renewal price per year</ts:string>
</ts:name>
<ts:origins>
<ts:ethereum function="rentPrice" contract="registrar" as="uint">
<ts:data>
<ts:string ref="ensName"/>
<ts:uint256>31540000</ts:uint256>
</ts:data>
</ts:ethereum>
</ts:origins>
</ts:attribute-type>

<ts:transaction>
<ts:ethereum function="renew" contract="registrar" as="uint">
<ts:value ref="renewalPricePerYear"/>
<ts:data>
<ts:string ref="ensName"/>
<ts:uint256>31540000</ts:uint256>
</ts:data>
</ts:ethereum>
</ts:transaction>

<style type="text/css">&style;</style>
<ts:view xml:lang="en">&renew.en;</ts:view>
</ts:action>


<ts:action>
<ts:name>
<ts:string xml:lang="en">Subdomain</ts:string>
</ts:name>

<ts:attribute-type id="subdomainHash" syntax="1.3.6.1.4.1.1466.115.121.1.36">
<ts:name>
<ts:string xml:lang="en">subdomainHash</ts:string>
</ts:name>
<ts:origins>
<ts:user-entry as="bytes"/>
</ts:origins>
</ts:attribute-type>

<ts:attribute-type id="owner" syntax="1.3.6.1.4.1.1466.115.121.1.36">
<ts:name>
<ts:string xml:lang="en">owner</ts:string>
</ts:name>
<ts:origins>
<ts:user-entry as="address"/>
</ts:origins>
</ts:attribute-type>

<ts:transaction>
<ts:ethereum function="setSubnodeOwner" contract="ENS">
<ts:data>
<ts:bytes32 ref="tokenId"/>
<ts:bytes32 ref="subdomainHash"/>
<ts:address ref="owner"/>
</ts:data>
</ts:ethereum>
</ts:transaction>

<style type="text/css">&style;</style>
<ts:view xml:lang="en">&subdomain.en;</ts:view>
</ts:action>

</ts:cards>

<ts:attribute-types>

<ts:attribute-type id="nameExpires" syntax="1.3.6.1.4.1.1466.115.121.1.36">
<ts:origins>
<ts:ethereum function="nameExpires" contract="ENS" as="uint">
<ts:data>
<ts:uint256 ref="tokenId"/>
</ts:data>
</ts:ethereum>
</ts:origins>
</ts:attribute-type>

<ts:attribute-type id="ensName" syntax="1.3.6.1.4.1.1466.115.121.1.36">
<ts:origins>
<ts:user-entry as="utf8"/>
</ts:origins>
</ts:attribute-type>

</ts:attribute-types>

</ts:token>
38 changes: 38 additions & 0 deletions examples/ENS/Makefile
@@ -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
4,218 changes: 4,218 additions & 0 deletions examples/ENS/bundle.js

Large diffs are not rendered by default.