Attestations need to work with the following systems:
- SmartContract (read-only)
- Web Sites (mostly read-only)
- TokenScript engine (like αWallet, read and write)
- Supernode (or any server that openly deals with attestations defined by TS)
The first two can probably use compile-time ASN.1 modules. As they probably already know what kind of tokens they are dealing with, they can compile the parsing code from the TokkenScrip they already have.
The latter two has to deal with TokenScripts not known at the time of deployment and has to parse DER-encoded attestations using modules supplied by TokenScript at runtime.
I experimented with supplying module at runtime. The following experiment is done with Python. Not very portable to iOS/Android but it gives an idea of what could be done with an interpreted language.
First, translate a module in ASN.X to code (with XSLT). This one has a Record
type which has an id
, a room
number and a house
number.
<?xml version="1.0"?>
<asnx:module xmlns:asnx="urn:ietf:params:xml:ns:asnx"
tagDefault="explicit">
<namedType name="Record">
<type>
<sequence>
<element name="id" type="Integer"/>
<optional>
<element name="room">
<type>
<tagged number="0" tagging="explicit" type="Integer"/>
</type>
</optional>
<element name="house">
<type>
<tagged number="1" tagging="explicit" type="Integer"/>
<default literalValue="0"/>
</type>
</element>
</sequence>
</type>
</namedType>
The translated Python code is
Record.componentType = NamedTypes(
NamedType('id', Integer()),
OptionalNamedType(
'room', Integer().subtype(
implicitTag=Tag(tagClassContext, tagFormatSimple, 0)
)
),
DefaultedNamedType(
'house', Integer(0).subtype(
implicitTag=Tag(tagClassContext, tagFormatSimple, 1)
)
)
)
Then, enclose this translated Python code-segment into a string, to demonstrate that they can be used at runtime:
from pyasn1.type.univ import Sequence, Integer
from pyasn1.type.namedtype import NamedType, NamedTypes, OptionalNamedType, DefaultedNamedType
from pyasn1.type.tag import Tag, tagFormatSimple, tagClassContext
class Record(Sequence):
pass
asn1sequence = """
Record.componentType = NamedTypes(
NamedType('id', Integer()),
OptionalNamedType(
'room', Integer().subtype(
implicitTag=Tag(tagClassContext, tagFormatSimple, 0)
)
),
DefaultedNamedType(
'house', Integer(0).subtype(
implicitTag=Tag(tagClassContext, tagFormatSimple, 1)
)
)
)
"""
exec(asn1sequence)
print(Record.componentType)
The code outputs (with Python 3.8) the definition of the module, which shows it's ready to be used at runtime:
<NamedTypes object at 0x7f6132f27760 types <NamedType object at 0x7f6132f15850 type id=<Integer schema object at 0x7f6132fd40d0 tagSet <TagSet object at 0x7f6132f45550 tags 0:0:2>>>
<OptionalNamedType object at 0x7f6132f15a00 type room=<Integer schema object at 0x7f6132f27a90 tagSet <TagSet object at 0x7f6132f27b20 tags 128:0:0>>>
<DefaultedNamedType object at 0x7f6132f27130 type house=<Integer value object at 0x7f6132f31a60 tagSet <TagSet object at 0x7f6132f38070 tags 128:0:1> payload [0]>>>