code: function hextoipv6(s) {
    if (! s.match(/^[0-9A-Fa-f]{32}$/))
      throw "malformed IPv6 address octet";
  
    // 1. downcase
    s = s.toLowerCase();
  
    // 2. split 4
    var a = s.match(/.{1,4}/g);
  
    // 3. trim leading 0
    for (var i = 0; i < 8; i++) {
      a[i] = a[i].replace(/^0+/, "");
      if (a[i] == '') a[i] = '0';
    }
    s = ":" + a.join(":") + ":";
  
    // 4. find shrinkables :0:0:...
    var aZero = s.match(/:(0:){2,}/g);
  
    // 5. no shrinkable
    if (aZero === null) return s.slice(1, -1);
  
    // 6. find max length :0:0:...
    var item = '';
    for (var i = 0; i < aZero.length; i++) {
      if (aZero[i].length > item.length) item = aZero[i];
    }
  
    // 7. shrink
    s = s.replace(item, '::');
    return s.slice(1, -1);
  }
docs: convert a 16 byte hexadecimal string to RFC 5952 canonicalized IPv6 address<br/>
  @name hextoipv6
  @function
  @param {String} s hexadecimal string of 16 byte IPv6 address
  @return {String} IPv6 address string canonicalized by RFC 5952
  @since jsrsasign 8.0.10 base64x 1.1.13
  @description
  This function converts a 16 byte hexadecimal string to
  <a href="https://tools.ietf.org/html/rfc5952">RFC 5952</a>
  canonicalized IPv6 address string.
  @example
  hextoip("871020010db8000000000000000000000004") &rarr "2001:db8::4"
  hextoip("871020010db8000000000000000000") &rarr raise exception
  hextoip("xyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyz") &rarr raise exception