Implement new Witness decoding function
diff --git a/js/WebSocketTransport.js b/js/WebSocketTransport.js
index 8e802af..7a06f1e 100644
--- a/js/WebSocketTransport.js
+++ b/js/WebSocketTransport.js
@@ -280,7 +280,7 @@
 		if (LOG > 3) console.log('ws.onopen: ReadyState: ' + this.readyState);
 
 		// Fetch ccndid now
-		var interest = new Interest(new Name(NDN.ccndIdFetcher));
+		var interest = new Interest(NDN.ccndIdFetcher);
 		interest.interestLifetime = 4000; // milliseconds
 		var subarray = encodeToBinaryInterest(interest);
 		
diff --git a/js/security/Witness.js b/js/security/Witness.js
index 3b88f06..1a8c5e0 100644
--- a/js/security/Witness.js
+++ b/js/security/Witness.js
@@ -13,17 +13,119 @@
 	this.path = new MerklePath();  // MerklePath
 };
 
+function parseOID(bytes, start, end) {
+    var s, n = 0, bits = 0;
+    for (var i = start; i < end; ++i) {
+        var v = bytes[i];
+        n = (n << 7) | (v & 0x7F);
+        bits += 7;
+        if (!(v & 0x80)) { // finished
+            if (s == undefined)
+                s = parseInt(n / 40) + "." + (n % 40);
+            else
+                s += "." + ((bits >= 31) ? "bigint" : n);
+            n = bits = 0;
+        }
+        s += String.fromCharCode();
+    }
+    return s;
+}
+
+function parseInteger(bytes, start, end) {
+    var n = 0;
+    for (var i = start; i < end; ++i)
+        n = (n << 8) | bytes[i];
+    return n;
+}
+
 Witness.prototype.decode = function(/* Uint8Array */ witness) {
+	/* The asn1.js decoder has some bug and 
+	 * cannot decode certain kind of witness.
+	 * So we use an alternative (and dirty) hack
+	 * to read witness from byte streams
+	 *      ------Wentao
+	 */
+	/*
 	var wit = DataUtils.toHex(witness).toLowerCase();
-	var der = Hex.decode(wit);
-	var asn1 = ASN1.decode(der);
+	try {
+		var der = Hex.decode(wit);
+		var asn1 = ASN1.decode(der);
+	}
+	catch (e) {
+		console.log(e);
+		console.log(wit);
+	}
 	//console.log(asn1.toPrettyString());
 	
 	this.oid = asn1.sub[0].sub[0].content();  // OID
+	//console.log(this.oid);
 	this.path.index = asn1.sub[1].sub[0].sub[0].content();  // index
+	//console.log(this.path.index);
 	for (i = 0; i < asn1.sub[1].sub[0].sub[1].sub.length; i++) {
 		pos = asn1.sub[1].sub[0].sub[1].sub[i].stream.pos;
 		str = wit.substring(2 * pos + 4, 2 * pos + 68);
 		this.path.digestList.push(str);  // digest hex string
+		//console.log(str);
+	}
+	*/
+	
+	// FIXME: Need to be fixed to support arbitrary ASN1 encoding,
+	// But do we really nned that????  -------Wentao
+	
+	// The structure of Witness is fixed as follows:
+	// SEQUENCE  (2 elem)
+	//   SEQUENCE  (1 elem)
+	//     OBJECT IDENTIFIER  1.2.840.113550.11.1.2.2
+	//   OCTET STRING  (1 elem)
+	//     SEQUENCE  (2 elem)
+	//       INTEGER  index
+	//       SEQUENCE  (n elem)
+	//         OCTET STRING(32 byte) 345FB4B5E9A1D2FF450ECA87EB87601683027A1A...
+	//         OCTET STRING(32 byte) DBCEE5B7A6C2B851B029324197DDBD9A655723DC...
+	//         OCTET STRING(32 byte) 4C79B2D256E4CD657A27F01DCB51AC3C56A24E71...
+	//         OCTET STRING(32 byte) 7F7FB169604A87EAC94378F0BDB4FC5D5899AB88...
+	//         ......
+	// Hence we can follow this structure to extract witness fields at fixed level
+	// Tag numbers for ASN1:
+	//    SEQUENCE            0x10
+	//    OCT STRING          0x04
+	//    INTEGER             0x02
+	//    OBJECT IDENTIFIER   0x06
+	var i = 0;
+	var step = 0;  // count of sequence tag
+	while (i < witness.length) {
+		var len = 0;
+		
+		if (witness[i] == 0x30) {
+			// Sequence (constructed)
+			// There is no primitive sequence in Witness
+			if ((witness[i + 1] & 0x80) != 0) {
+				len = witness[i+1] & 0x7F;
+			}
+			step++;
+		} else if (witness[i] == 0x06) {
+			// Decode OID
+			len = witness[i+1];  // XXX: OID will not be longer than 127 bytes
+			this.oid = parseOID(witness, i + 2, i + 2 + len);
+			//console.log(this.oid);
+		} else if (witness[i] == 0x02) {
+			// Decode node index
+			len = witness[i+1];  // XXX: index will not be longer than 127 bytes
+			this.path.index = parseInteger(witness, i + 2, i + 2 + len);
+			//console.log(this.path.index);
+		} else if (witness[i] == 0x04) {
+			if ((witness[i + 1] & 0x80) != 0) {
+				len = witness[i+1] & 0x7F;
+			} else {
+				len = witness[i+1];
+			}
+			if (step == 4) {
+				// Start to decode digest hex string
+				str = DataUtils.toHex(witness.subarray(i + 2, i + 2 + len));
+				this.path.digestList.push(str);  // digest hex string
+				//console.log(str);
+			}
+		}
+		i = i + 2 + len;
 	}
 };
diff --git a/js/testing/test-get-async.html b/js/testing/test-get-async.html
index e019537..4b6a37a 100644
--- a/js/testing/test-get-async.html
+++ b/js/testing/test-get-async.html
@@ -13,7 +13,7 @@
 	<script type="text/javascript" src="../tools/build/ndn-js.js"></script>

 

 	<script type="text/javascript">

-		var ndn = new NDN({port:9696});

+		var ndn = new NDN({port:9696,host:"localhost"});

         ndn.transport.connectWebSocket(ndn);

         

         ndn.onopen = function() {

diff --git a/js/testing/test-throughput-ws.html b/js/testing/test-throughput-ws.html
index 91dc359..14f9d39 100644
--- a/js/testing/test-throughput-ws.html
+++ b/js/testing/test-throughput-ws.html
@@ -42,6 +42,8 @@
 		    

 		    if (kind == Closure.UPCALL_CONTENT_BAD) {

 		    	console.log("NdnProtocol.ContentClosure: signature verification failed");

+		    	console.log(upcallInfo.contentObject.name.getName());

+		    	console.log(DataUtils.toHex(upcallInfo.contentObject.signature.Witness).toLowerCase());

 		    	return Closure.RESULT_OK;

 		    }

 		    

diff --git a/js/tools/build/make-js.sh b/js/tools/build/make-js.sh
index 5959d3a..49dda47 100755
--- a/js/tools/build/make-js.sh
+++ b/js/tools/build/make-js.sh
@@ -21,8 +21,6 @@
   ../../encoding/BinaryXMLStructureDecoder.js \
   ../../encoding/DataUtils.js \
   ../../encoding/EncodingUtils.js \
-  ../../encoding/ASN1/asn1.js \
-  ../../encoding/ASN1/hex.js \
   ../../security/KeyManager.js \
   ../../security/Witness.js \
   ../../securityLib/sha256.js \
diff --git a/js/tools/build/ndn-js-uncomp.js b/js/tools/build/ndn-js-uncomp.js
index a8762c7..bc92e99 100644
--- a/js/tools/build/ndn-js-uncomp.js
+++ b/js/tools/build/ndn-js-uncomp.js
@@ -346,7 +346,7 @@
 		if (LOG > 3) console.log('ws.onopen: ReadyState: ' + this.readyState);
 
 		// Fetch ccndid now
-		var interest = new Interest(new Name(NDN.ccndIdFetcher));
+		var interest = new Interest(NDN.ccndIdFetcher);
 		interest.interestLifetime = 4000; // milliseconds
 		var subarray = encodeToBinaryInterest(interest);
 		
@@ -4488,559 +4488,6 @@
 }
 
 
-// ASN.1 JavaScript decoder
-// Copyright (c) 2008-2009 Lapo Luchini <lapo@lapo.it>
-
-// Permission to use, copy, modify, and/or distribute this software for any
-// purpose with or without fee is hereby granted, provided that the above
-// copyright notice and this permission notice appear in all copies.
-// 
-// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-
-function Stream(enc, pos) {
-    if (enc instanceof Stream) {
-        this.enc = enc.enc;
-        this.pos = enc.pos;
-    } else {
-        this.enc = enc;
-        this.pos = pos;
-    }
-}
-Stream.prototype.get = function(pos) {
-    if (pos == undefined)
-        pos = this.pos++;
-    if (pos >= this.enc.length)
-        throw 'Requesting byte offset ' + pos + ' on a stream of length ' + this.enc.length;
-    return this.enc[pos];
-}
-Stream.prototype.hexDigits = "0123456789ABCDEF";
-Stream.prototype.hexByte = function(b) {
-    return this.hexDigits.charAt((b >> 4) & 0xF) + this.hexDigits.charAt(b & 0xF);
-}
-Stream.prototype.hexDump = function(start, end) {
-    var s = "";
-    for (var i = start; i < end; ++i) {
-        s += this.hexByte(this.get(i));
-        switch (i & 0xF) {
-        case 0x7: s += "  "; break;
-        case 0xF: s += "\n"; break;
-        default:  s += " ";
-        }
-    }
-    return s;
-}
-Stream.prototype.parseStringISO = function(start, end) {
-    var s = "";
-    for (var i = start; i < end; ++i)
-        s += String.fromCharCode(this.get(i));
-    return s;
-}
-Stream.prototype.parseStringUTF = function(start, end) {
-    var s = "", c = 0;
-    for (var i = start; i < end; ) {
-        var c = this.get(i++);
-        if (c < 128)
-            s += String.fromCharCode(c);
-        else if ((c > 191) && (c < 224))
-            s += String.fromCharCode(((c & 0x1F) << 6) | (this.get(i++) & 0x3F));
-        else
-            s += String.fromCharCode(((c & 0x0F) << 12) | ((this.get(i++) & 0x3F) << 6) | (this.get(i++) & 0x3F));
-        //TODO: this doesn't check properly 'end', some char could begin before and end after
-    }
-    return s;
-}
-Stream.prototype.reTime = /^((?:1[89]|2\d)?\d\d)(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])([01]\d|2[0-3])(?:([0-5]\d)(?:([0-5]\d)(?:[.,](\d{1,3}))?)?)?(Z|[-+](?:[0]\d|1[0-2])([0-5]\d)?)?$/;
-Stream.prototype.parseTime = function(start, end) {
-    var s = this.parseStringISO(start, end);
-    var m = this.reTime.exec(s);
-    if (!m)
-        return "Unrecognized time: " + s;
-    s = m[1] + "-" + m[2] + "-" + m[3] + " " + m[4];
-    if (m[5]) {
-        s += ":" + m[5];
-        if (m[6]) {
-            s += ":" + m[6];
-            if (m[7])
-                s += "." + m[7];
-        }
-    }
-    if (m[8]) {
-        s += " UTC";
-        if (m[8] != 'Z') {
-            s += m[8];
-            if (m[9])
-                s += ":" + m[9];
-        }
-    }
-    return s;
-}
-Stream.prototype.parseInteger = function(start, end) {
-    //TODO support negative numbers
-    var len = end - start;
-    if (len > 4) {
-        len <<= 3;
-        var s = this.get(start);
-        if (s == 0)
-            len -= 8;
-        else
-            while (s < 128) {
-                s <<= 1;
-                --len;
-            }
-        return "(" + len + " bit)";
-    }
-    var n = 0;
-    for (var i = start; i < end; ++i)
-        n = (n << 8) | this.get(i);
-    return n;
-}
-Stream.prototype.parseBitString = function(start, end) {
-    var unusedBit = this.get(start);
-    var lenBit = ((end - start - 1) << 3) - unusedBit;
-    var s  = "(" + lenBit + " bit)";
-    if (lenBit <= 20) {
-        var skip = unusedBit;
-        s += " ";
-        for (var i = end - 1; i > start; --i) {
-            var b = this.get(i);
-            for (var j = skip; j < 8; ++j)
-                s += (b >> j) & 1 ? "1" : "0";
-            skip = 0;
-        }
-    }
-    return s;
-}
-Stream.prototype.parseOctetString = function(start, end) {
-    var len = end - start;
-    var s = "(" + len + " byte) ";
-    if (len > 20)
-        end = start + 20;
-    for (var i = start; i < end; ++i)
-        s += this.hexByte(this.get(i));
-    if (len > 20)
-        s += String.fromCharCode(8230); // ellipsis
-    return s;
-}
-Stream.prototype.parseOID = function(start, end) {
-    var s, n = 0, bits = 0;
-    for (var i = start; i < end; ++i) {
-        var v = this.get(i);
-        n = (n << 7) | (v & 0x7F);
-        bits += 7;
-        if (!(v & 0x80)) { // finished
-            if (s == undefined)
-                s = parseInt(n / 40) + "." + (n % 40);
-            else
-                s += "." + ((bits >= 31) ? "bigint" : n);
-            n = bits = 0;
-        }
-        s += String.fromCharCode();
-    }
-    return s;
-}
-
-function ASN1(stream, header, length, tag, sub) {
-    this.stream = stream;
-    this.header = header;
-    this.length = length;
-    this.tag = tag;
-    this.sub = sub;
-}
-ASN1.prototype.typeName = function() {
-    if (this.tag == undefined)
-        return "unknown";
-    var tagClass = this.tag >> 6;
-    var tagConstructed = (this.tag >> 5) & 1;
-    var tagNumber = this.tag & 0x1F;
-    switch (tagClass) {
-    case 0: // universal
-        switch (tagNumber) {
-        case 0x00: return "EOC";
-        case 0x01: return "BOOLEAN";
-        case 0x02: return "INTEGER";
-        case 0x03: return "BIT_STRING";
-        case 0x04: return "OCTET_STRING";
-        case 0x05: return "NULL";
-        case 0x06: return "OBJECT_IDENTIFIER";
-        case 0x07: return "ObjectDescriptor";
-        case 0x08: return "EXTERNAL";
-        case 0x09: return "REAL";
-        case 0x0A: return "ENUMERATED";
-        case 0x0B: return "EMBEDDED_PDV";
-        case 0x0C: return "UTF8String";
-        case 0x10: return "SEQUENCE";
-        case 0x11: return "SET";
-        case 0x12: return "NumericString";
-        case 0x13: return "PrintableString"; // ASCII subset
-        case 0x14: return "TeletexString"; // aka T61String
-        case 0x15: return "VideotexString";
-        case 0x16: return "IA5String"; // ASCII
-        case 0x17: return "UTCTime";
-        case 0x18: return "GeneralizedTime";
-        case 0x19: return "GraphicString";
-        case 0x1A: return "VisibleString"; // ASCII subset
-        case 0x1B: return "GeneralString";
-        case 0x1C: return "UniversalString";
-        case 0x1E: return "BMPString";
-        default: return "Universal_" + tagNumber.toString(16);
-        }
-    case 1: return "Application_" + tagNumber.toString(16);
-    case 2: return "[" + tagNumber + "]"; // Context
-    case 3: return "Private_" + tagNumber.toString(16);
-    }
-}
-ASN1.prototype.content = function() {
-    if (this.tag == undefined)
-        return null;
-    var tagClass = this.tag >> 6;
-    if (tagClass != 0) // universal
-        return (this.sub == null) ? null : "(" + this.sub.length + ")";
-    var tagNumber = this.tag & 0x1F;
-    var content = this.posContent();
-    var len = Math.abs(this.length);
-    switch (tagNumber) {
-    case 0x01: // BOOLEAN
-        return (this.stream.get(content) == 0) ? "false" : "true";
-    case 0x02: // INTEGER
-        return this.stream.parseInteger(content, content + len);
-    case 0x03: // BIT_STRING
-        return this.sub ? "(" + this.sub.length + " elem)" :
-            this.stream.parseBitString(content, content + len)
-    case 0x04: // OCTET_STRING
-        return this.sub ? "(" + this.sub.length + " elem)" :
-            this.stream.parseOctetString(content, content + len)
-    //case 0x05: // NULL
-    case 0x06: // OBJECT_IDENTIFIER
-        return this.stream.parseOID(content, content + len);
-    //case 0x07: // ObjectDescriptor
-    //case 0x08: // EXTERNAL
-    //case 0x09: // REAL
-    //case 0x0A: // ENUMERATED
-    //case 0x0B: // EMBEDDED_PDV
-    case 0x10: // SEQUENCE
-    case 0x11: // SET
-        return "(" + this.sub.length + " elem)";
-    case 0x0C: // UTF8String
-        return this.stream.parseStringUTF(content, content + len);
-    case 0x12: // NumericString
-    case 0x13: // PrintableString
-    case 0x14: // TeletexString
-    case 0x15: // VideotexString
-    case 0x16: // IA5String
-    //case 0x19: // GraphicString
-    case 0x1A: // VisibleString
-    //case 0x1B: // GeneralString
-    //case 0x1C: // UniversalString
-    //case 0x1E: // BMPString
-        return this.stream.parseStringISO(content, content + len);
-    case 0x17: // UTCTime
-    case 0x18: // GeneralizedTime
-        return this.stream.parseTime(content, content + len);
-    }
-    return null;
-}
-ASN1.prototype.toString = function() {
-    return this.typeName() + "@" + this.stream.pos + "[header:" + this.header + ",length:" + this.length + ",sub:" + ((this.sub == null) ? 'null' : this.sub.length) + "]";
-}
-ASN1.prototype.print = function(indent) {
-    if (indent == undefined) indent = '';
-    document.writeln(indent + this);
-    if (this.sub != null) {
-        indent += '  ';
-        for (var i = 0, max = this.sub.length; i < max; ++i)
-            this.sub[i].print(indent);
-    }
-}
-ASN1.prototype.toPrettyString = function(indent) {
-    if (indent == undefined) indent = '';
-    var s = indent + this.typeName() + " @" + this.stream.pos;
-    if (this.length >= 0)
-        s += "+";
-    s += this.length;
-    if (this.tag & 0x20)
-        s += " (constructed)";
-    else if (((this.tag == 0x03) || (this.tag == 0x04)) && (this.sub != null))
-        s += " (encapsulates)";
-    s += "\n";
-    if (this.sub != null) {
-        indent += '  ';
-        for (var i = 0, max = this.sub.length; i < max; ++i)
-            s += this.sub[i].toPrettyString(indent);
-    }
-    return s;
-}
-ASN1.prototype.toDOM = function() {
-    var node = document.createElement("div");
-    node.className = "node";
-    node.asn1 = this;
-    var head = document.createElement("div");
-    head.className = "head";
-    var s = this.typeName().replace(/_/g, " ");
-    head.innerHTML = s;
-    var content = this.content();
-    if (content != null) {
-        content = String(content).replace(/</g, "&lt;");
-        var preview = document.createElement("span");
-        preview.className = "preview";
-        preview.innerHTML = content;
-        head.appendChild(preview);
-    }
-    node.appendChild(head);
-    this.node = node;
-    this.head = head;
-    var value = document.createElement("div");
-    value.className = "value";
-    s = "Offset: " + this.stream.pos + "<br/>";
-    s += "Length: " + this.header + "+";
-    if (this.length >= 0)
-        s += this.length;
-    else
-        s += (-this.length) + " (undefined)";
-    if (this.tag & 0x20)
-        s += "<br/>(constructed)";
-    else if (((this.tag == 0x03) || (this.tag == 0x04)) && (this.sub != null))
-        s += "<br/>(encapsulates)";
-    //TODO if (this.tag == 0x03) s += "Unused bits: "
-    if (content != null) {
-        s += "<br/>Value:<br/><b>" + content + "</b>";
-        if ((typeof(oids) == 'object') && (this.tag == 0x06)) {
-            var oid = oids[content];
-            if (oid) {
-                if (oid.d) s += "<br/>" + oid.d;
-                if (oid.c) s += "<br/>" + oid.c;
-                if (oid.w) s += "<br/>(warning!)";
-            }
-        }
-    }
-    value.innerHTML = s;
-    node.appendChild(value);
-    var sub = document.createElement("div");
-    sub.className = "sub";
-    if (this.sub != null) {
-        for (var i = 0, max = this.sub.length; i < max; ++i)
-            sub.appendChild(this.sub[i].toDOM());
-    }
-    node.appendChild(sub);
-    head.switchNode = node;
-    head.onclick = function() {
-        var node = this.switchNode;
-        node.className = (node.className == "node collapsed") ? "node" : "node collapsed";
-    };
-    return node;
-}
-ASN1.prototype.posStart = function() {
-    return this.stream.pos;
-}
-ASN1.prototype.posContent = function() {
-    return this.stream.pos + this.header;
-}
-ASN1.prototype.posEnd = function() {
-    return this.stream.pos + this.header + Math.abs(this.length);
-}
-ASN1.prototype.fakeHover = function(current) {
-    this.node.className += " hover";
-    if (current)
-        this.head.className += " hover";
-}
-ASN1.prototype.fakeOut = function(current) {
-    var re = / ?hover/;
-    this.node.className = this.node.className.replace(re, "");
-    if (current)
-        this.head.className = this.head.className.replace(re, "");
-}
-ASN1.prototype.toHexDOM_sub = function(node, className, stream, start, end) {
-    if (start >= end)
-        return;
-    var sub = document.createElement("span");
-    sub.className = className;
-    sub.appendChild(document.createTextNode(
-        stream.hexDump(start, end)));
-    node.appendChild(sub);
-}
-ASN1.prototype.toHexDOM = function(root) {
-    var node = document.createElement("span");
-    node.className = 'hex';
-    if (root == undefined) root = node;
-    this.head.hexNode = node;
-    this.head.onmouseover = function() { this.hexNode.className = "hexCurrent"; }
-    this.head.onmouseout  = function() { this.hexNode.className = "hex"; }
-    node.asn1 = this;
-    node.onmouseover = function() {
-        var current = !root.selected;
-        if (current) {
-            root.selected = this.asn1;
-            this.className = "hexCurrent";
-        }
-        this.asn1.fakeHover(current);
-    }
-    node.onmouseout  = function() {
-        var current = (root.selected == this.asn1);
-        this.asn1.fakeOut(current);
-        if (current) {
-            root.selected = null;
-            this.className = "hex";
-        }
-    }
-    this.toHexDOM_sub(node, "tag", this.stream, this.posStart(), this.posStart() + 1);
-    this.toHexDOM_sub(node, (this.length >= 0) ? "dlen" : "ulen", this.stream, this.posStart() + 1, this.posContent());
-    if (this.sub == null)
-        node.appendChild(document.createTextNode(
-            this.stream.hexDump(this.posContent(), this.posEnd())));
-    else if (this.sub.length > 0) {
-        var first = this.sub[0];
-        var last = this.sub[this.sub.length - 1];
-        this.toHexDOM_sub(node, "intro", this.stream, this.posContent(), first.posStart());
-        for (var i = 0, max = this.sub.length; i < max; ++i)
-            node.appendChild(this.sub[i].toHexDOM(root));
-        this.toHexDOM_sub(node, "outro", this.stream, last.posEnd(), this.posEnd());
-    }
-    return node;
-}
-ASN1.decodeLength = function(stream) {
-    var buf = stream.get();
-    var len = buf & 0x7F;
-    if (len == buf)
-        return len;
-    if (len > 3)
-        throw "Length over 24 bits not supported at position " + (stream.pos - 1);
-    if (len == 0)
-        return -1; // undefined
-    buf = 0;
-    for (var i = 0; i < len; ++i)
-        buf = (buf << 8) | stream.get();
-    return buf;
-}
-ASN1.hasContent = function(tag, len, stream) {
-    if (tag & 0x20) // constructed
-        return true;
-    if ((tag < 0x03) || (tag > 0x04))
-        return false;
-    var p = new Stream(stream);
-    if (tag == 0x03) p.get(); // BitString unused bits, must be in [0, 7]
-    var subTag = p.get();
-    if ((subTag >> 6) & 0x01) // not (universal or context)
-        return false;
-    try {
-        var subLength = ASN1.decodeLength(p);
-        return ((p.pos - stream.pos) + subLength == len);
-    } catch (exception) {
-        return false;
-    }
-}
-ASN1.decode = function(stream) {
-    if (!(stream instanceof Stream))
-        stream = new Stream(stream, 0);
-    var streamStart = new Stream(stream);
-    var tag = stream.get();
-    var len = ASN1.decodeLength(stream);
-    var header = stream.pos - streamStart.pos;
-    var sub = null;
-    if (ASN1.hasContent(tag, len, stream)) {
-        // it has content, so we decode it
-        var start = stream.pos;
-        if (tag == 0x03) stream.get(); // skip BitString unused bits, must be in [0, 7]
-        sub = [];
-        if (len >= 0) {
-            // definite length
-            var end = start + len;
-            while (stream.pos < end)
-                sub[sub.length] = ASN1.decode(stream);
-            if (stream.pos != end)
-                throw "Content size is not correct for container starting at offset " + start;
-        } else {
-            // undefined length
-            try {
-                for (;;) {
-                    var s = ASN1.decode(stream);
-                    if (s.tag == 0)
-                        break;
-                    sub[sub.length] = s;
-                }
-                len = start - stream.pos;
-            } catch (e) {
-                throw "Exception while decoding undefined length content: " + e;
-            }
-        }
-    } else
-        stream.pos += len; // skip content
-    return new ASN1(streamStart, header, len, tag, sub);
-}
-/*
-ASN1.test = function() {
-    var test = [
-        { value: [0x27],                   expected: 0x27     },
-        { value: [0x81, 0xC9],             expected: 0xC9     },
-        { value: [0x83, 0xFE, 0xDC, 0xBA], expected: 0xFEDCBA },
-    ];
-    for (var i = 0, max = test.length; i < max; ++i) {
-        var pos = 0;
-        var stream = new Stream(test[i].value, 0);
-        var res = ASN1.decodeLength(stream);
-        if (res != test[i].expected)
-            document.write("In test[" + i + "] expected " + test[i].expected + " got " + res + "\n");
-    }
-}*/
-// Hex JavaScript decoder

-// Copyright (c) 2008 Lapo Luchini <lapo@lapo.it>

-

-// Permission to use, copy, modify, and/or distribute this software for any

-// purpose with or without fee is hereby granted, provided that the above

-// copyright notice and this permission notice appear in all copies.

-// 

-// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES

-// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF

-// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR

-// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES

-// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN

-// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF

-// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

-

-Hex = {};

-

-Hex.decode = function(a) {

-    if (Hex.decoder == undefined) {

-        var hex = "0123456789ABCDEF";

-        var allow = " \f\n\r\t\u00A0\u2028\u2029";

-        var dec = [];

-        for (var i = 0; i < 16; ++i)

-            dec[hex.charAt(i)] = i;

-        hex = hex.toLowerCase();

-        for (var i = 10; i < 16; ++i)

-            dec[hex.charAt(i)] = i;

-        for (var i = 0; i < allow.length; ++i)

-            dec[allow.charAt(i)] = -1;

-        Hex.decoder = dec;

-    }

-    var out = [];

-    var bits = 0, char_count = 0;

-    for (var i = 0; i < a.length; ++i) {

-        var c = a.charAt(i);

-        if (c == '=')

-            break;

-        c = Hex.decoder[c];

-        if (c == -1)

-            continue;

-        if (c == undefined)

-            throw 'Illegal character at offset ' + i;

-        bits |= c;

-        if (++char_count >= 2) {

-            out[out.length] = bits;

-            bits = 0;

-            char_count = 0;

-        } else {

-            bits <<= 4;

-        }

-    }

-    if (char_count)

-        throw "Hex encoding incomplete: 4 bits missing";

-    return out;

-}

 /**
  * @author: Meki Cheraoui
  * See COPYING for copyright and distribution information.
@@ -5161,18 +4608,120 @@
 	this.path = new MerklePath();  // MerklePath
 };
 
+function parseOID(bytes, start, end) {
+    var s, n = 0, bits = 0;
+    for (var i = start; i < end; ++i) {
+        var v = bytes[i];
+        n = (n << 7) | (v & 0x7F);
+        bits += 7;
+        if (!(v & 0x80)) { // finished
+            if (s == undefined)
+                s = parseInt(n / 40) + "." + (n % 40);
+            else
+                s += "." + ((bits >= 31) ? "bigint" : n);
+            n = bits = 0;
+        }
+        s += String.fromCharCode();
+    }
+    return s;
+}
+
+function parseInteger(bytes, start, end) {
+    var n = 0;
+    for (var i = start; i < end; ++i)
+        n = (n << 8) | bytes[i];
+    return n;
+}
+
 Witness.prototype.decode = function(/* Uint8Array */ witness) {
+	/* The asn1.js decoder has some bug and 
+	 * cannot decode certain kind of witness.
+	 * So we use an alternative (and dirty) hack
+	 * to read witness from byte streams
+	 *      ------Wentao
+	 */
+	/*
 	var wit = DataUtils.toHex(witness).toLowerCase();
-	var der = Hex.decode(wit);
-	var asn1 = ASN1.decode(der);
+	try {
+		var der = Hex.decode(wit);
+		var asn1 = ASN1.decode(der);
+	}
+	catch (e) {
+		console.log(e);
+		console.log(wit);
+	}
 	//console.log(asn1.toPrettyString());
 	
 	this.oid = asn1.sub[0].sub[0].content();  // OID
+	//console.log(this.oid);
 	this.path.index = asn1.sub[1].sub[0].sub[0].content();  // index
+	//console.log(this.path.index);
 	for (i = 0; i < asn1.sub[1].sub[0].sub[1].sub.length; i++) {
 		pos = asn1.sub[1].sub[0].sub[1].sub[i].stream.pos;
 		str = wit.substring(2 * pos + 4, 2 * pos + 68);
 		this.path.digestList.push(str);  // digest hex string
+		//console.log(str);
+	}
+	*/
+	
+	// FIXME: Need to be fixed to support arbitrary ASN1 encoding,
+	// But do we really nned that????  -------Wentao
+	
+	// The structure of Witness is fixed as follows:
+	// SEQUENCE  (2 elem)
+	//   SEQUENCE  (1 elem)
+	//     OBJECT IDENTIFIER  1.2.840.113550.11.1.2.2
+	//   OCTET STRING  (1 elem)
+	//     SEQUENCE  (2 elem)
+	//       INTEGER  index
+	//       SEQUENCE  (n elem)
+	//         OCTET STRING(32 byte) 345FB4B5E9A1D2FF450ECA87EB87601683027A1A...
+	//         OCTET STRING(32 byte) DBCEE5B7A6C2B851B029324197DDBD9A655723DC...
+	//         OCTET STRING(32 byte) 4C79B2D256E4CD657A27F01DCB51AC3C56A24E71...
+	//         OCTET STRING(32 byte) 7F7FB169604A87EAC94378F0BDB4FC5D5899AB88...
+	//         ......
+	// Hence we can follow this structure to extract witness fields at fixed level
+	// Tag numbers for ASN1:
+	//    SEQUENCE            0x10
+	//    OCT STRING          0x04
+	//    INTEGER             0x02
+	//    OBJECT IDENTIFIER   0x06
+	var i = 0;
+	var step = 0;  // count of sequence tag
+	while (i < witness.length) {
+		var len = 0;
+		
+		if (witness[i] == 0x30) {
+			// Sequence (constructed)
+			// There is no primitive sequence in Witness
+			if ((witness[i + 1] & 0x80) != 0) {
+				len = witness[i+1] & 0x7F;
+			}
+			step++;
+		} else if (witness[i] == 0x06) {
+			// Decode OID
+			len = witness[i+1];  // XXX: OID will not be longer than 127 bytes
+			this.oid = parseOID(witness, i + 2, i + 2 + len);
+			//console.log(this.oid);
+		} else if (witness[i] == 0x02) {
+			// Decode node index
+			len = witness[i+1];  // XXX: index will not be longer than 127 bytes
+			this.path.index = parseInteger(witness, i + 2, i + 2 + len);
+			//console.log(this.path.index);
+		} else if (witness[i] == 0x04) {
+			if ((witness[i + 1] & 0x80) != 0) {
+				len = witness[i+1] & 0x7F;
+			} else {
+				len = witness[i+1];
+			}
+			if (step == 4) {
+				// Start to decode digest hex string
+				str = DataUtils.toHex(witness.subarray(i + 2, i + 2 + len));
+				this.path.digestList.push(str);  // digest hex string
+				//console.log(str);
+			}
+		}
+		i = i + 2 + len;
 	}
 };
 /*

diff --git a/js/tools/build/ndn-js.js b/js/tools/build/ndn-js.js
index cdeb725..36f2fd6 100644
--- a/js/tools/build/ndn-js.js
+++ b/js/tools/build/ndn-js.js
@@ -10,8 +10,8 @@
 new UpcallInfo(a,null,0,this.contentObject));d=new KeyStoreEntry(l.keyName,d,(new Date).getTime());NDN.addKeyEntry(d)}};if(d.signedInfo&&d.signedInfo.locator&&d.signature){3<LOG&&console.log("Key verification...");var j=DataUtils.toHex(d.signature.signature).toLowerCase(),l=d.signedInfo.locator;if(l.type==KeyLocatorType.KEYNAME)if(3<LOG&&console.log("KeyLocator contains KEYNAME"),l.keyName.contentName.match(d.name))3<LOG&&console.log("Content is key itself"),k=decodeSubjectPublicKeyInfo(d.content),
 k=k.verifyByteArray(d.rawSignatureData,f,j),f=!0==k?Closure.UPCALL_CONTENT:Closure.UPCALL_CONTENT_BAD,g.upcall(f,new UpcallInfo(a,null,0,d));else{var p=NDN.getKeyByName(l.keyName);p?(3<LOG&&console.log("Local key cache hit"),k=p.rsaKey,k=k.verifyByteArray(d.rawSignatureData,f,j),f=!0==k?Closure.UPCALL_CONTENT:Closure.UPCALL_CONTENT_BAD,g.upcall(f,new UpcallInfo(a,null,0,d))):(3<LOG&&console.log("Fetch key according to keylocator"),f=new k(d,g,l.keyName,j,f),d=new Interest(l.keyName.contentName.getPrefix(4)),
 d.interestLifetime=4,b.expressInterest(a,d,f))}else l.type==KeyLocatorType.KEY?(3<LOG&&console.log("Keylocator contains KEY"),k=!1,null==f&&(k=decodeSubjectPublicKeyInfo(d.signedInfo.locator.publicKey),k=k.verifyByteArray(d.rawSignatureData,f,j)),f=!0==k?Closure.UPCALL_CONTENT:Closure.UPCALL_CONTENT_BAD,g.upcall(Closure.UPCALL_CONTENT,new UpcallInfo(a,null,0,d))):(d=l.certificate,console.log("KeyLocator contains CERT"),console.log(d))}}}else console.log("Incoming packet is not Interest or ContentObject. Discard now.");
-delete c;delete b.structureDecoder;delete b.buffer;b.structureDecoder=new BinaryXMLStructureDecoder;b.buffer=new Uint8Array(b.maxBufferSize);b.bufferOffset=0}};this.ws.onopen=function(a){3<LOG&&console.log(a);3<LOG&&console.log("ws.onopen: WebSocket connection opened.");3<LOG&&console.log("ws.onopen: ReadyState: "+this.readyState);a=new Interest(new Name(NDN.ccndIdFetcher));a.interestLifetime=4E3;var a=encodeToBinaryInterest(a),d=new Uint8Array(a.length);d.set(a);b.ws.send(d.buffer)};this.ws.onerror=
-function(a){console.log("ws.onerror: ReadyState: "+this.readyState);console.log(a);console.log("ws.onerror: WebSocket error: "+a.data)};this.ws.onclose=function(){console.log("ws.onclose: WebSocket connection closed.");b.ws=null;a.readyStatus=NDN.CLOSED;a.onclose()}};
+delete c;delete b.structureDecoder;delete b.buffer;b.structureDecoder=new BinaryXMLStructureDecoder;b.buffer=new Uint8Array(b.maxBufferSize);b.bufferOffset=0}};this.ws.onopen=function(a){3<LOG&&console.log(a);3<LOG&&console.log("ws.onopen: WebSocket connection opened.");3<LOG&&console.log("ws.onopen: ReadyState: "+this.readyState);a=new Interest(NDN.ccndIdFetcher);a.interestLifetime=4E3;var a=encodeToBinaryInterest(a),d=new Uint8Array(a.length);d.set(a);b.ws.send(d.buffer)};this.ws.onerror=function(a){console.log("ws.onerror: ReadyState: "+
+this.readyState);console.log(a);console.log("ws.onerror: WebSocket error: "+a.data)};this.ws.onclose=function(){console.log("ws.onclose: WebSocket connection closed.");b.ws=null;a.readyStatus=NDN.CLOSED;a.onclose()}};
 WebSocketTransport.prototype.expressInterest=function(a,b,c){if(null!=this.ws){var d=encodeToBinaryInterest(b),e=new Uint8Array(d.length);e.set(d);var f=new PITEntry(b,c);NDN.PITTable.push(f);this.ws.send(e.buffer);3<LOG&&console.log("ws.send() returned.");c.timerID=setTimeout(function(){3<LOG&&console.log("Interest time out.");var d=NDN.PITTable.indexOf(f);0<=d&&NDN.PITTable.splice(d,1);c.upcall(Closure.UPCALL_INTEREST_TIMED_OUT,new UpcallInfo(a,b,0,null))},b.interestLifetime)}else console.log("WebSocket connection is not established.")};
 var CSTable=[],CSEntry=function(a,b){this.name=a;this.closure=b};function getEntryForRegisteredPrefix(a){for(var b=0;b<CSTable.length;b++)if(null!=CSTable[b].name.match(a))return CSTable[b];return null}
 WebSocketTransport.prototype.registerPrefix=function(a,b,c){if(null!=this.ws){if(null==this.ccndid)return console.log("ccnd node ID unkonwn. Cannot register prefix."),-1;var a=new ForwardingEntry("selfreg",b,null,null,3,2147483647),a=encodeForwardingEntry(a),d=new SignedInfo;d.setFields();a=new ContentObject(new Name,d,a,new Signature);a.sign();a=encodeToBinaryContentObject(a);a=new Name(["ccnx",this.ccndid,"selfreg",a]);a=new Interest(a);a.scope=1;d=encodeToBinaryInterest(a);a=new Uint8Array(d.length);
@@ -145,32 +145,11 @@
 e.subjectPublicKeyRSA.e.toString(16)+"<br/>";b+="<br/>";c=e.subjectPublicKeyRSA.verifyByteArray(a.rawSignatureData,c);2<LOG&&console.log("result is "+c);d=e.subjectPublicKeyRSA.n;e=e.subjectPublicKeyRSA.e;2<LOG&&console.log("PUBLIC KEY n after is ");2<LOG&&console.log(d);2<LOG&&console.log("EXPONENT e after is ");2<LOG&&console.log(e);b=c?b+"SIGNATURE VALID":b+"SIGNATURE INVALID";b+="<br />";b+="<br />"}if(null!=a.signedInfo&&null!=a.signedInfo.locator&&null!=a.signedInfo.locator.publicKey){var d=
 DataUtils.toHex(a.signedInfo.locator.publicKey).toLowerCase(),f=DataUtils.toString(a.signedInfo.locator.publicKey),c=DataUtils.toHex(a.signature.signature).toLowerCase(),e=DataUtils.toString(a.rawSignatureData),b=b+("Public key: "+d),b=b+"<br />",b=b+"<br />";2<LOG&&console.log(" ContentName + SignedInfo + Content = "+e);2<LOG&&console.log(" PublicKeyHex = "+d);2<LOG&&console.log(" PublicKeyString = "+f);2<LOG&&console.log(" Signature "+c);2<LOG&&console.log(" Signature NOW IS");2<LOG&&console.log(a.signature.signature);
 e=decodeSubjectPublicKeyInfo(a.signedInfo.locator.publicKey);b+="Public key (hex) modulus: "+e.n.toString(16)+"<br/>";b+="exponent: "+e.e.toString(16)+"<br/>";b+="<br/>";c=e.verifyByteArray(a.rawSignatureData,c);2<LOG&&console.log("PUBLIC KEY n after is ");2<LOG&&console.log(e.n);2<LOG&&console.log("EXPONENT e after is ");2<LOG&&console.log(e.e);b=c?b+"SIGNATURE VALID":b+"SIGNATURE INVALID";b+="<br />";b+="<br />"}}return b}
-function Stream(a,b){a instanceof Stream?(this.enc=a.enc,this.pos=a.pos):(this.enc=a,this.pos=b)}Stream.prototype.get=function(a){void 0==a&&(a=this.pos++);if(a>=this.enc.length)throw"Requesting byte offset "+a+" on a stream of length "+this.enc.length;return this.enc[a]};Stream.prototype.hexDigits="0123456789ABCDEF";Stream.prototype.hexByte=function(a){return this.hexDigits.charAt(a>>4&15)+this.hexDigits.charAt(a&15)};
-Stream.prototype.hexDump=function(a,b){for(var c="",d=a;d<b;++d)switch(c+=this.hexByte(this.get(d)),d&15){case 7:c+="  ";break;case 15:c+="\n";break;default:c+=" "}return c};Stream.prototype.parseStringISO=function(a,b){for(var c="",d=a;d<b;++d)c+=String.fromCharCode(this.get(d));return c};
-Stream.prototype.parseStringUTF=function(a,b){for(var c="",d=0,e=a;e<b;)d=this.get(e++),c=128>d?c+String.fromCharCode(d):191<d&&224>d?c+String.fromCharCode((d&31)<<6|this.get(e++)&63):c+String.fromCharCode((d&15)<<12|(this.get(e++)&63)<<6|this.get(e++)&63);return c};Stream.prototype.reTime=/^((?:1[89]|2\d)?\d\d)(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])([01]\d|2[0-3])(?:([0-5]\d)(?:([0-5]\d)(?:[.,](\d{1,3}))?)?)?(Z|[-+](?:[0]\d|1[0-2])([0-5]\d)?)?$/;
-Stream.prototype.parseTime=function(a,b){var c=this.parseStringISO(a,b),d=this.reTime.exec(c);if(!d)return"Unrecognized time: "+c;c=d[1]+"-"+d[2]+"-"+d[3]+" "+d[4];d[5]&&(c+=":"+d[5],d[6]&&(c+=":"+d[6],d[7]&&(c+="."+d[7])));d[8]&&(c+=" UTC","Z"!=d[8]&&(c+=d[8],d[9]&&(c+=":"+d[9])));return c};Stream.prototype.parseInteger=function(a,b){var c=b-a;if(4<c){var c=c<<3,d=this.get(a);if(0==d)c-=8;else for(;128>d;)d<<=1,--c;return"("+c+" bit)"}c=0;for(d=a;d<b;++d)c=c<<8|this.get(d);return c};
-Stream.prototype.parseBitString=function(a,b){var c=this.get(a),d=(b-a-1<<3)-c,e="("+d+" bit)";if(20>=d)for(var f=c,e=e+" ",c=b-1;c>a;--c){for(d=this.get(c);8>f;++f)e+=d>>f&1?"1":"0";f=0}return e};Stream.prototype.parseOctetString=function(a,b){var c=b-a,d="("+c+" byte) ";20<c&&(b=a+20);for(var e=a;e<b;++e)d+=this.hexByte(this.get(e));20<c&&(d+=String.fromCharCode(8230));return d};
-Stream.prototype.parseOID=function(a,b){for(var c,d=0,e=0,f=a;f<b;++f){var g=this.get(f),d=d<<7|g&127,e=e+7;g&128||(c=void 0==c?parseInt(d/40)+"."+d%40:c+("."+(31<=e?"bigint":d)),d=e=0);c+=String.fromCharCode()}return c};function ASN1(a,b,c,d,e){this.stream=a;this.header=b;this.length=c;this.tag=d;this.sub=e}
-ASN1.prototype.typeName=function(){if(void 0==this.tag)return"unknown";var a=this.tag&31;switch(this.tag>>6){case 0:switch(a){case 0:return"EOC";case 1:return"BOOLEAN";case 2:return"INTEGER";case 3:return"BIT_STRING";case 4:return"OCTET_STRING";case 5:return"NULL";case 6:return"OBJECT_IDENTIFIER";case 7:return"ObjectDescriptor";case 8:return"EXTERNAL";case 9:return"REAL";case 10:return"ENUMERATED";case 11:return"EMBEDDED_PDV";case 12:return"UTF8String";case 16:return"SEQUENCE";case 17:return"SET";
-case 18:return"NumericString";case 19:return"PrintableString";case 20:return"TeletexString";case 21:return"VideotexString";case 22:return"IA5String";case 23:return"UTCTime";case 24:return"GeneralizedTime";case 25:return"GraphicString";case 26:return"VisibleString";case 27:return"GeneralString";case 28:return"UniversalString";case 30:return"BMPString";default:return"Universal_"+a.toString(16)}case 1:return"Application_"+a.toString(16);case 2:return"["+a+"]";case 3:return"Private_"+a.toString(16)}};
-ASN1.prototype.content=function(){if(void 0==this.tag)return null;if(0!=this.tag>>6)return null==this.sub?null:"("+this.sub.length+")";var a=this.tag&31,b=this.posContent(),c=Math.abs(this.length);switch(a){case 1:return 0==this.stream.get(b)?"false":"true";case 2:return this.stream.parseInteger(b,b+c);case 3:return this.sub?"("+this.sub.length+" elem)":this.stream.parseBitString(b,b+c);case 4:return this.sub?"("+this.sub.length+" elem)":this.stream.parseOctetString(b,b+c);case 6:return this.stream.parseOID(b,
-b+c);case 16:case 17:return"("+this.sub.length+" elem)";case 12:return this.stream.parseStringUTF(b,b+c);case 18:case 19:case 20:case 21:case 22:case 26:return this.stream.parseStringISO(b,b+c);case 23:case 24:return this.stream.parseTime(b,b+c)}return null};ASN1.prototype.toString=function(){return this.typeName()+"@"+this.stream.pos+"[header:"+this.header+",length:"+this.length+",sub:"+(null==this.sub?"null":this.sub.length)+"]"};
-ASN1.prototype.print=function(a){void 0==a&&(a="");document.writeln(a+this);if(null!=this.sub)for(var a=a+"  ",b=0,c=this.sub.length;b<c;++b)this.sub[b].print(a)};
-ASN1.prototype.toPrettyString=function(a){void 0==a&&(a="");var b=a+this.typeName()+" @"+this.stream.pos;0<=this.length&&(b+="+");b+=this.length;if(this.tag&32)b+=" (constructed)";else if((3==this.tag||4==this.tag)&&null!=this.sub)b+=" (encapsulates)";b+="\n";if(null!=this.sub)for(var a=a+"  ",c=0,d=this.sub.length;c<d;++c)b+=this.sub[c].toPrettyString(a);return b};
-ASN1.prototype.toDOM=function(){var a=document.createElement("div");a.className="node";a.asn1=this;var b=document.createElement("div");b.className="head";var c=this.typeName().replace(/_/g," ");b.innerHTML=c;var d=this.content();null!=d&&(d=String(d).replace(/</g,"&lt;"),c=document.createElement("span"),c.className="preview",c.innerHTML=d,b.appendChild(c));a.appendChild(b);this.node=a;this.head=b;var e=document.createElement("div");e.className="value";c="Offset: "+this.stream.pos+"<br/>";c+="Length: "+
-this.header+"+";c=0<=this.length?c+this.length:c+(-this.length+" (undefined)");if(this.tag&32)c+="<br/>(constructed)";else if((3==this.tag||4==this.tag)&&null!=this.sub)c+="<br/>(encapsulates)";if(null!=d&&(c+="<br/>Value:<br/><b>"+d+"</b>","object"==typeof oids&&6==this.tag&&(d=oids[d])))d.d&&(c+="<br/>"+d.d),d.c&&(c+="<br/>"+d.c),d.w&&(c+="<br/>(warning!)");e.innerHTML=c;a.appendChild(e);c=document.createElement("div");c.className="sub";if(null!=this.sub){d=0;for(e=this.sub.length;d<e;++d)c.appendChild(this.sub[d].toDOM())}a.appendChild(c);
-b.switchNode=a;b.onclick=function(){var a=this.switchNode;a.className="node collapsed"==a.className?"node":"node collapsed"};return a};ASN1.prototype.posStart=function(){return this.stream.pos};ASN1.prototype.posContent=function(){return this.stream.pos+this.header};ASN1.prototype.posEnd=function(){return this.stream.pos+this.header+Math.abs(this.length)};ASN1.prototype.fakeHover=function(a){this.node.className+=" hover";a&&(this.head.className+=" hover")};
-ASN1.prototype.fakeOut=function(a){var b=/ ?hover/;this.node.className=this.node.className.replace(b,"");a&&(this.head.className=this.head.className.replace(b,""))};ASN1.prototype.toHexDOM_sub=function(a,b,c,d,e){if(!(d>=e)){var f=document.createElement("span");f.className=b;f.appendChild(document.createTextNode(c.hexDump(d,e)));a.appendChild(f)}};
-ASN1.prototype.toHexDOM=function(a){var b=document.createElement("span");b.className="hex";void 0==a&&(a=b);this.head.hexNode=b;this.head.onmouseover=function(){this.hexNode.className="hexCurrent"};this.head.onmouseout=function(){this.hexNode.className="hex"};b.asn1=this;b.onmouseover=function(){var b=!a.selected;b&&(a.selected=this.asn1,this.className="hexCurrent");this.asn1.fakeHover(b)};b.onmouseout=function(){var b=a.selected==this.asn1;this.asn1.fakeOut(b);b&&(a.selected=null,this.className=
-"hex")};this.toHexDOM_sub(b,"tag",this.stream,this.posStart(),this.posStart()+1);this.toHexDOM_sub(b,0<=this.length?"dlen":"ulen",this.stream,this.posStart()+1,this.posContent());if(null==this.sub)b.appendChild(document.createTextNode(this.stream.hexDump(this.posContent(),this.posEnd())));else if(0<this.sub.length){var c=this.sub[0],d=this.sub[this.sub.length-1];this.toHexDOM_sub(b,"intro",this.stream,this.posContent(),c.posStart());for(var c=0,e=this.sub.length;c<e;++c)b.appendChild(this.sub[c].toHexDOM(a));
-this.toHexDOM_sub(b,"outro",this.stream,d.posEnd(),this.posEnd())}return b};ASN1.decodeLength=function(a){var b=a.get(),c=b&127;if(c==b)return c;if(3<c)throw"Length over 24 bits not supported at position "+(a.pos-1);if(0==c)return-1;for(var d=b=0;d<c;++d)b=b<<8|a.get();return b};ASN1.hasContent=function(a,b,c){if(a&32)return!0;if(3>a||4<a)return!1;var d=new Stream(c);3==a&&d.get();if(d.get()>>6&1)return!1;try{var e=ASN1.decodeLength(d);return d.pos-c.pos+e==b}catch(f){return!1}};
-ASN1.decode=function(a){a instanceof Stream||(a=new Stream(a,0));var b=new Stream(a),c=a.get(),d=ASN1.decodeLength(a),e=a.pos-b.pos,f=null;if(ASN1.hasContent(c,d,a)){var g=a.pos;3==c&&a.get();f=[];if(0<=d){for(var j=g+d;a.pos<j;)f[f.length]=ASN1.decode(a);if(a.pos!=j)throw"Content size is not correct for container starting at offset "+g;}else try{for(;;){j=ASN1.decode(a);if(0==j.tag)break;f[f.length]=j}d=g-a.pos}catch(k){throw"Exception while decoding undefined length content: "+k;}}else a.pos+=d;
-return new ASN1(b,e,d,c,f)};
-Hex={decode:function(a){if(void 0==Hex.decoder){for(var b="0123456789ABCDEF",c=[],d=0;16>d;++d)c[b.charAt(d)]=d;b=b.toLowerCase();for(d=10;16>d;++d)c[b.charAt(d)]=d;for(d=0;8>d;++d)c[" \f\n\r\t\u00a0\u2028\u2029".charAt(d)]=-1;Hex.decoder=c}for(var b=[],e=c=0,d=0;d<a.length;++d){var f=a.charAt(d);if("="==f)break;f=Hex.decoder[f];if(-1!=f){if(void 0==f)throw"Illegal character at offset "+d;c|=f;2<=++e?(b[b.length]=c,e=c=0):c<<=4}}if(e)throw"Hex encoding incomplete: 4 bits missing";return b}};
-var KeyManager=function(){this.certificate="MIIBmzCCAQQCCQC32FyQa61S7jANBgkqhkiG9w0BAQUFADASMRAwDgYDVQQDEwdheGVsY2R2MB4XDTEyMDQyODIzNDQzN1oXDTEyMDUyODIzNDQzN1owEjEQMA4GA1UEAxMHYXhlbGNkdjCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA4X0wp9goqxuECxdULcr2IHr9Ih4Iaypg0Wy39URIup8/CLzQmdsh3RYqd55hqonu5VTTpH3iMLx6xZDVJAZ8OJi7pvXcQ2C4Re2kjL2c8SanI0RfDhlS1zJadfr1VhRPmpivcYawJ4aFuOLAi+qHFxtN7lhcGCgpW1OV60oXd58CAwEAATANBgkqhkiG9w0BAQUFAAOBgQDLOrA1fXzSrpftUB5Ro6DigX1Bjkf7F5Bkd69hSVp+jYeJFBBlsILQAfSxUZPQtD+2Yc3iCmSYNyxqu9PcufDRJlnvB7PG29+L3y9lR37tetzUV9eTscJ7rdp8Wt6AzpW32IJ/54yKNfP7S6ZIoIG+LP6EIxq6s8K1MXRt8uBJKw==";
-this.publicKey="30819F300D06092A864886F70D010101050003818D0030818902818100E17D30A7D828AB1B840B17542DCAF6207AFD221E086B2A60D16CB7F54448BA9F3F08BCD099DB21DD162A779E61AA89EEE554D3A47DE230BC7AC590D524067C3898BBA6F5DC4360B845EDA48CBD9CF126A723445F0E1952D7325A75FAF556144F9A98AF7186B0278685B8E2C08BEA87171B4DEE585C1828295B5395EB4A17779F0203010001";this.privateKey="MIICXQIBAAKBgQDhfTCn2CirG4QLF1QtyvYgev0iHghrKmDRbLf1REi6nz8IvNCZ2yHdFip3nmGqie7lVNOkfeIwvHrFkNUkBnw4mLum9dxDYLhF7aSMvZzxJqcjRF8OGVLXMlp1+vVWFE+amK9xhrAnhoW44sCL6ocXG03uWFwYKClbU5XrShd3nwIDAQABAoGAGkv6T6jC3WmhFZYL6CdCWvlc6gysmKrhjarrLTxgavtFY6R5g2ft5BXAsCCVbUkWxkIFSKqxpVNl0gKZCNGEzPDN6mHJOQI/h0rlxNIHAuGfoAbCzALnqmyZivhJAPGijAyKuU9tczsst5+Kpn+bn7ehzHQuj7iwJonS5WbojqECQQD851K8TpW2GrRizNgG4dx6orZxAaon/Jnl8lS7soXhllQty7qG+oDfzznmdMsiznCqEABzHUUKOVGE9RWPN3aRAkEA5D/w9N55d0ibnChFJlc8cUAoaqH+w+U3oQP2Lb6AZHJpLptN4y4b/uf5d4wYU5/i/gC7SSBH3wFhh9bjRLUDLwJAVOx8vN0Kqt7myfKNbCo19jxjVSlA8TKCn1Oznl/BU1I+rC4oUaEW25DjmX6IpAR8kq7S59ThVSCQPjxqY/A08QJBAIRaF2zGPITQk3r/VumemCvLWiRK/yG0noc9dtibqHOWbCtcXtOm/xDWjq+lis2i3ssOvYrvrv0/HcDY+Dv1An0CQQCLJtMsfSg4kvG/FRY5UMhtMuwo8ovYcMXt4Xv/LWaMhndD67b2UGawQCRqr5ghRTABWdDD/HuuMBjrkPsX0861"};
+var KeyManager=function(){this.certificate="MIIBmzCCAQQCCQC32FyQa61S7jANBgkqhkiG9w0BAQUFADASMRAwDgYDVQQDEwdheGVsY2R2MB4XDTEyMDQyODIzNDQzN1oXDTEyMDUyODIzNDQzN1owEjEQMA4GA1UEAxMHYXhlbGNkdjCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA4X0wp9goqxuECxdULcr2IHr9Ih4Iaypg0Wy39URIup8/CLzQmdsh3RYqd55hqonu5VTTpH3iMLx6xZDVJAZ8OJi7pvXcQ2C4Re2kjL2c8SanI0RfDhlS1zJadfr1VhRPmpivcYawJ4aFuOLAi+qHFxtN7lhcGCgpW1OV60oXd58CAwEAATANBgkqhkiG9w0BAQUFAAOBgQDLOrA1fXzSrpftUB5Ro6DigX1Bjkf7F5Bkd69hSVp+jYeJFBBlsILQAfSxUZPQtD+2Yc3iCmSYNyxqu9PcufDRJlnvB7PG29+L3y9lR37tetzUV9eTscJ7rdp8Wt6AzpW32IJ/54yKNfP7S6ZIoIG+LP6EIxq6s8K1MXRt8uBJKw==";this.publicKey=
+"30819F300D06092A864886F70D010101050003818D0030818902818100E17D30A7D828AB1B840B17542DCAF6207AFD221E086B2A60D16CB7F54448BA9F3F08BCD099DB21DD162A779E61AA89EEE554D3A47DE230BC7AC590D524067C3898BBA6F5DC4360B845EDA48CBD9CF126A723445F0E1952D7325A75FAF556144F9A98AF7186B0278685B8E2C08BEA87171B4DEE585C1828295B5395EB4A17779F0203010001";this.privateKey="MIICXQIBAAKBgQDhfTCn2CirG4QLF1QtyvYgev0iHghrKmDRbLf1REi6nz8IvNCZ2yHdFip3nmGqie7lVNOkfeIwvHrFkNUkBnw4mLum9dxDYLhF7aSMvZzxJqcjRF8OGVLXMlp1+vVWFE+amK9xhrAnhoW44sCL6ocXG03uWFwYKClbU5XrShd3nwIDAQABAoGAGkv6T6jC3WmhFZYL6CdCWvlc6gysmKrhjarrLTxgavtFY6R5g2ft5BXAsCCVbUkWxkIFSKqxpVNl0gKZCNGEzPDN6mHJOQI/h0rlxNIHAuGfoAbCzALnqmyZivhJAPGijAyKuU9tczsst5+Kpn+bn7ehzHQuj7iwJonS5WbojqECQQD851K8TpW2GrRizNgG4dx6orZxAaon/Jnl8lS7soXhllQty7qG+oDfzznmdMsiznCqEABzHUUKOVGE9RWPN3aRAkEA5D/w9N55d0ibnChFJlc8cUAoaqH+w+U3oQP2Lb6AZHJpLptN4y4b/uf5d4wYU5/i/gC7SSBH3wFhh9bjRLUDLwJAVOx8vN0Kqt7myfKNbCo19jxjVSlA8TKCn1Oznl/BU1I+rC4oUaEW25DjmX6IpAR8kq7S59ThVSCQPjxqY/A08QJBAIRaF2zGPITQk3r/VumemCvLWiRK/yG0noc9dtibqHOWbCtcXtOm/xDWjq+lis2i3ssOvYrvrv0/HcDY+Dv1An0CQQCLJtMsfSg4kvG/FRY5UMhtMuwo8ovYcMXt4Xv/LWaMhndD67b2UGawQCRqr5ghRTABWdDD/HuuMBjrkPsX0861"};
 KeyManager.prototype.verify=function(a,b){var c=this.certificate,d=new X509;d.readCertPEM(c);return d.subjectPublicKeyRSA.verifyString(a,b)};KeyManager.prototype.sign=function(a){var b=this.privateKey,c=new RSAKey;c.readPrivateKeyFromPEMString(b);return c.signString(a,"sha256")};var globalKeyManager=new KeyManager,MerklePath=function(){this.index=null;this.digestList=[]},Witness=function(){this.oid=null;this.path=new MerklePath};
-Witness.prototype.decode=function(a){var a=DataUtils.toHex(a).toLowerCase(),b=Hex.decode(a),b=ASN1.decode(b);this.oid=b.sub[0].sub[0].content();this.path.index=b.sub[1].sub[0].sub[0].content();for(i=0;i<b.sub[1].sub[0].sub[1].sub.length;i++)pos=b.sub[1].sub[0].sub[1].sub[i].stream.pos,str=a.substring(2*pos+4,2*pos+68),this.path.digestList.push(str)};var hexcase=0,b64pad="";function hex_sha256_from_bytes(a){return rstr2hex(binb2rstr(binb_sha256(byteArray2binb(a),8*a.length)))}
+function parseOID(a,b,c){for(var d,e=0,f=0;b<c;++b){var g=a[b],e=e<<7|g&127,f=f+7;g&128||(d=void 0==d?parseInt(e/40)+"."+e%40:d+("."+(31<=f?"bigint":e)),e=f=0);d+=String.fromCharCode()}return d}function parseInteger(a,b,c){for(var d=0;b<c;++b)d=d<<8|a[b];return d}
+Witness.prototype.decode=function(a){for(var b=0,c=0;b<a.length;){var d=0;48==a[b]?(0!=(a[b+1]&128)&&(d=a[b+1]&127),c++):6==a[b]?(d=a[b+1],this.oid=parseOID(a,b+2,b+2+d)):2==a[b]?(d=a[b+1],this.path.index=parseInteger(a,b+2,b+2+d)):4==a[b]&&(d=0!=(a[b+1]&128)?a[b+1]&127:a[b+1],4==c&&(str=DataUtils.toHex(a.subarray(b+2,b+2+d)),this.path.digestList.push(str)));b=b+2+d}};var hexcase=0,b64pad="";function hex_sha256_from_bytes(a){return rstr2hex(binb2rstr(binb_sha256(byteArray2binb(a),8*a.length)))}
 function hex_sha256(a){return rstr2hex(rstr_sha256(str2rstr_utf8(a)))}function b64_sha256(a){return rstr2b64(rstr_sha256(str2rstr_utf8(a)))}function any_sha256(a,b){return rstr2any(rstr_sha256(str2rstr_utf8(a)),b)}function hex_hmac_sha256(a,b){return rstr2hex(rstr_hmac_sha256(str2rstr_utf8(a),str2rstr_utf8(b)))}function b64_hmac_sha256(a,b){return rstr2b64(rstr_hmac_sha256(str2rstr_utf8(a),str2rstr_utf8(b)))}
 function any_hmac_sha256(a,b,c){return rstr2any(rstr_hmac_sha256(str2rstr_utf8(a),str2rstr_utf8(b)),c)}function sha256_vm_test(){return"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"==hex_sha256("abc").toLowerCase()}function rstr_sha256(a){return binb2rstr(binb_sha256(rstr2binb(a),8*a.length))}
 function rstr_hmac_sha256(a,b){var c=rstr2binb(a);16<c.length&&(c=binb_sha256(c,8*a.length));for(var d=Array(16),e=Array(16),f=0;16>f;f++)d[f]=c[f]^909522486,e[f]=c[f]^1549556828;c=binb_sha256(d.concat(rstr2binb(b)),512+8*b.length);return binb2rstr(binb_sha256(e.concat(c),768))}function rstr2hex(a){try{hexcase}catch(b){hexcase=0}for(var c=hexcase?"0123456789ABCDEF":"0123456789abcdef",d="",e,f=0;f<a.length;f++)e=a.charCodeAt(f),d+=c.charAt(e>>>4&15)+c.charAt(e&15);return d}