blob: 3b88f06abb010eb9a1415659bc34aa951d7347d1 [file] [log] [blame]
Wentao Shang882e34e2013-01-05 02:49:51 -08001/**
2 * @author: Wentao Shang
3 * See COPYING for copyright and distribution information.
4 */
5
6var MerklePath = function MerkelPath() {
7 this.index = null; // int
8 this.digestList = []; // array of hex string
9};
10
11var Witness = function Witness() {
12 this.oid = null; // string
13 this.path = new MerklePath(); // MerklePath
14};
15
16Witness.prototype.decode = function(/* Uint8Array */ witness) {
17 var wit = DataUtils.toHex(witness).toLowerCase();
18 var der = Hex.decode(wit);
19 var asn1 = ASN1.decode(der);
20 //console.log(asn1.toPrettyString());
21
22 this.oid = asn1.sub[0].sub[0].content(); // OID
23 this.path.index = asn1.sub[1].sub[0].sub[0].content(); // index
24 for (i = 0; i < asn1.sub[1].sub[0].sub[1].sub.length; i++) {
25 pos = asn1.sub[1].sub[0].sub[1].sub[i].stream.pos;
26 str = wit.substring(2 * pos + 4, 2 * pos + 68);
27 this.path.digestList.push(str); // digest hex string
28 }
29};