{"version":3,"file":null,"sources":["../src/treeUtils.js","../src/parseChainscript.js","../src/ChainTree.js","../src/compactHash.js","../node_modules/deepmerge/index.js","../node_modules/rollup-plugin-node-globals/src/global.js","../node_modules/process-es6/browser.js","../node_modules/setimmediate/setImmediate.js","../node_modules/httpplease/plugins/jsonrequest.js","../node_modules/httpplease/plugins/jsonresponse.js","../node_modules/httpplease/plugins/json.js","../node_modules/httpplease/plugins/cleanurl.js","../node_modules/httpplease/lib/xhr-browser.js","../node_modules/httpplease/lib/utils/delay.js","../node_modules/httpplease/lib/request.js","../node_modules/xtend/index.js","../node_modules/httpplease/lib/utils/extractResponseProps.js","../node_modules/httpplease/lib/response.js","../node_modules/httpplease/lib/error.js","../node_modules/httpplease/lib/utils/once.js","../node_modules/httpplease/lib/index.js","../node_modules/stratumn-agent-client/lib/stratumn-agent-client.mjs","../src/resolveLinks.js","../src/wrap.js","../src/parseIfJson.js","../src/flatten.js","../src/tagsSet.js","../src/ChainTreeBuilder.js","../node_modules/canonical-json/index.js","../node_modules/js-sha256/src/sha256.js","../src/hashJson.js","../node_modules/buffer-es6/base64.js","../node_modules/buffer-es6/ieee754.js","../node_modules/buffer-es6/isArray.js","../node_modules/buffer-es6/index.js","../src/computeMerkleParent.js","../src/SegmentValidator.js","../src/ChainValidator.js","../src/MerklePathTree.js"],"sourcesContent":["/*\n Copyright 2017 Stratumn SAS. All rights reserved.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*/\n\nexport function makeLink(source, target, margin = 0) {\n const finalTarget = target || source;\n const targetX = finalTarget.x;\n const targetY = finalTarget.y - margin;\n return `M${source.y},${source.x}\n C${(source.y + targetY) / 2},${source.x} ${(source.y + targetY) / 2},\n ${targetX} ${targetY},${targetX}`;\n}\n\nexport function finalLink(d, margin) {\n return makeLink(d.source, d.target, margin);\n}\n\nexport function translate(x, y) {\n return `translate(${y}, ${x})`;\n}\n\nexport function stashPositions(nodes) {\n // Stash the old positions for transition.\n nodes.forEach(d => {\n d.x0 = d.x;\n d.y0 = d.y;\n });\n}\n","/*\n Copyright 2017 Stratumn SAS. All rights reserved.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*/\n\nimport { stratify } from 'd3-hierarchy';\n\nexport default function parseChainscript(chainscript) {\n return stratify()\n .id(d => d.meta.linkHash)\n .parentId(d => d.link.meta.prevLinkHash)(chainscript);\n}\n","/*\n Copyright 2017 Stratumn SAS. All rights reserved.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*/\n\nimport { makeLink, finalLink, translate } from './treeUtils';\nimport parseChainscript from './parseChainscript';\nimport { tree } from 'd3-hierarchy';\nimport { transition } from 'd3-transition';\nimport { easeLinear } from 'd3-ease';\nimport { select, selectAll, event } from 'd3-selection';\nimport { zoom } from 'd3-zoom';\nimport { max } from 'd3-array';\n\nconst margin = { top: 20, right: 120, bottom: 20, left: 120 };\nconst height = 800 - margin.top - margin.bottom;\n\nexport default class ChainTree {\n constructor(element) {\n this.tree = tree();\n\n this.svg = select(element).append('svg');\n this.innerG = this.svg.append('g');\n\n this.zoomed = () => this.innerG.attr('transform', event.transform);\n }\n\n display(chainscript, options) {\n if (chainscript && chainscript.length) {\n const root = parseChainscript(chainscript);\n this._update(root, options);\n } else {\n this._update(null, options);\n }\n }\n\n _update(root, options) {\n const self = this;\n const polygon = options.polygonSize;\n const nodes = root ? root.descendants() : [];\n const links = root ? root.links() : [];\n const maxDepth = max(nodes, x => x.depth) || 0;\n const computedWidth = Math.max(maxDepth * (polygon.width + options.getArrowLength()), 500);\n const treeTransition = transition()\n .duration(options.duration)\n .ease(easeLinear);\n\n const branchesCount = nodes.reduce(\n (pre, cur) => pre + (cur.children ? Math.max(cur.children.length - 1, 0) : 0),\n 1\n );\n const computedHeight = branchesCount * polygon.height * options.verticalSpacing;\n\n this.tree.size([computedHeight, computedWidth]);\n this.svg\n .attr('width',\n options.zoomable ? 1200 : computedWidth + margin.right + margin.left +\n options.getArrowLength())\n .attr('height',\n (options.zoomable ? height : computedHeight) + margin.top + margin.bottom);\n\n // Compute the new tree layout.\n if (root) {\n root.x0 = computedHeight / 2;\n root.y0 = 0;\n this.tree(root);\n root.each(node => { node.y += options.getArrowLength(); });\n }\n\n if (options.zoomable) {\n this.svg.call(zoom().on('zoom', this.zoomed));\n } else {\n this.svg.on('.zoom', null);\n }\n this.innerG.attr('transform', () => translate(margin.top, margin.left));\n\n // Update the links...\n const link = this.innerG.selectAll('path.link').data(links,\n function key(d) { return d ? d.target.id : this.id; });\n\n link.enter().insert('text')\n .attr('dx', polygon.width + 20)\n .attr('dy', '-0.3em')\n .append('textPath')\n .attr('class', 'textpath')\n .attr('xlink:href', d => `#link-${d.target.id}`)\n .text(options.getLinkText);\n\n // Enter any new links at the parent's previous position.\n link.enter().insert('path', 'g')\n .attr('class', 'link')\n .attr('id', d => `link-${d.target.id}`);\n\n const linkUpdate = this.innerG.selectAll('path.link:not(.init)').transition(treeTransition);\n\n // Transition links to their new position.\n linkUpdate.attr('d', d => finalLink(d, 15));\n\n link.exit().remove();\n\n // Update the nodes...\n const node = this.innerG.selectAll('g.node').data(nodes,\n function key(d) { return d ? d.id : this.id; });\n\n // Enter any new nodes at the parent's previous position.\n const nodeEnter = node.enter().append('g')\n .attr('class', d => ['node'].concat(d.data.link.meta.tags).join(' '))\n .attr('id', d => d.id)\n .attr('transform', d => {\n const origin = d.parent && d.parent.x0 ? d.parent : root;\n return translate(origin.x0, origin.y0);\n })\n .on('click', function onClick(d) {\n selectAll('g.node')\n .classed('selected', false);\n select(this)\n .classed('selected', true);\n options.onclick(d, () => {\n self.innerG.selectAll('g.node.selected').classed('selected', false);\n }, this);\n });\n\n nodeEnter.append('polygon').attr('points',\n `0,${polygon.height / 4} ${polygon.width / 2},${polygon.height / 2} ` +\n `${polygon.width},${polygon.height / 4} ${polygon.width},${-polygon.height / 4} ` +\n `${polygon.width / 2},${-polygon.height / 2} 0,${-polygon.height / 4}`);\n\n nodeEnter.append('rect')\n .attr('y', -(options.getBoxSize().height / 2))\n .attr('width', polygon.width)\n .attr('height', options.getBoxSize().height)\n .style('fill-opacity', 1e-6);\n\n nodeEnter.append('text')\n .attr('dx', 12)\n .attr('dy', 4)\n .attr('text-anchor', 'begin')\n .text(options.getSegmentText)\n .style('fill-opacity', 1e-6);\n\n // Transition nodes to their new position.\n const nodeUpdate = this.svg.selectAll('g.node').transition(treeTransition);\n\n nodeUpdate.attr('transform', d => translate(d.x, d.y));\n nodeUpdate.select('text').style('fill-opacity', 1);\n nodeUpdate.select('rect').style('fill-opacity', 1);\n\n // Transition exiting nodes to the parent's new position.\n const nodeExit = node.exit(); // .transition(treeTransition);\n nodeExit.select('text').style('fill-opacity', 1e-6);\n nodeExit.attr('transform', () => translate(0, 0)).remove();\n\n this._drawInit(root);\n }\n\n _drawInit(root) {\n this.innerG.append('path')\n .attr('class', 'link init')\n .attr('id', 'init-link')\n .attr('d', makeLink({ x: root.x, y: root.y0 }, root, 15));\n\n this.innerG.append('text')\n .attr('dx', 20)\n .attr('dy', '-0.3em')\n .append('textPath')\n .attr('class', 'textpath')\n .attr('xlink:href', '#init-link')\n .text('init');\n }\n}\n","/*\n Copyright 2017 Stratumn SAS. All rights reserved.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*/\n\nexport default function (hash) {\n return `${hash.slice(0, 3)}${hash.slice(hash.length - 3)}`;\n}\n","(function (root, factory) {\n if (typeof define === 'function' && define.amd) {\n define(factory);\n } else if (typeof exports === 'object') {\n module.exports = factory();\n } else {\n root.deepmerge = factory();\n }\n}(this, function () {\n\nreturn function deepmerge(target, src) {\n var array = Array.isArray(src);\n var dst = array && [] || {};\n\n if (array) {\n target = target || [];\n dst = dst.concat(target);\n src.forEach(function(e, i) {\n if (typeof dst[i] === 'undefined') {\n dst[i] = e;\n } else if (typeof e === 'object') {\n dst[i] = deepmerge(target[i], e);\n } else {\n if (target.indexOf(e) === -1) {\n dst.push(e);\n }\n }\n });\n } else {\n if (target && typeof target === 'object') {\n Object.keys(target).forEach(function (key) {\n dst[key] = target[key];\n })\n }\n Object.keys(src).forEach(function (key) {\n if (typeof src[key] !== 'object' || !src[key]) {\n dst[key] = src[key];\n }\n else {\n if (!target[key]) {\n dst[key] = src[key];\n } else {\n dst[key] = deepmerge(target[key], src[key]);\n }\n }\n });\n }\n\n return dst;\n}\n\n}));\n","export default typeof global !== \"undefined\" ? global :\n typeof self !== \"undefined\" ? self :\n typeof window !== \"undefined\" ? window : {}\n","// shim for using process in browser\n// based off https://github.com/defunctzombie/node-process/blob/master/browser.js\n\nfunction defaultSetTimout() {\n throw new Error('setTimeout has not been defined');\n}\nfunction defaultClearTimeout () {\n throw new Error('clearTimeout has not been defined');\n}\nvar cachedSetTimeout = defaultSetTimout;\nvar cachedClearTimeout = defaultClearTimeout;\nif (typeof global.setTimeout === 'function') {\n cachedSetTimeout = setTimeout;\n}\nif (typeof global.clearTimeout === 'function') {\n cachedClearTimeout = clearTimeout;\n}\n\nfunction runTimeout(fun) {\n if (cachedSetTimeout === setTimeout) {\n //normal enviroments in sane situations\n return setTimeout(fun, 0);\n }\n // if setTimeout wasn't available but was latter defined\n if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {\n cachedSetTimeout = setTimeout;\n return setTimeout(fun, 0);\n }\n try {\n // when when somebody has screwed with setTimeout but no I.E. maddness\n return cachedSetTimeout(fun, 0);\n } catch(e){\n try {\n // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally\n return cachedSetTimeout.call(null, fun, 0);\n } catch(e){\n // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error\n return cachedSetTimeout.call(this, fun, 0);\n }\n }\n\n\n}\nfunction runClearTimeout(marker) {\n if (cachedClearTimeout === clearTimeout) {\n //normal enviroments in sane situations\n return clearTimeout(marker);\n }\n // if clearTimeout wasn't available but was latter defined\n if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {\n cachedClearTimeout = clearTimeout;\n return clearTimeout(marker);\n }\n try {\n // when when somebody has screwed with setTimeout but no I.E. maddness\n return cachedClearTimeout(marker);\n } catch (e){\n try {\n // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally\n return cachedClearTimeout.call(null, marker);\n } catch (e){\n // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.\n // Some versions of I.E. have different rules for clearTimeout vs setTimeout\n return cachedClearTimeout.call(this, marker);\n }\n }\n\n\n\n}\nvar queue = [];\nvar draining = false;\nvar currentQueue;\nvar queueIndex = -1;\n\nfunction cleanUpNextTick() {\n if (!draining || !currentQueue) {\n return;\n }\n draining = false;\n if (currentQueue.length) {\n queue = currentQueue.concat(queue);\n } else {\n queueIndex = -1;\n }\n if (queue.length) {\n drainQueue();\n }\n}\n\nfunction drainQueue() {\n if (draining) {\n return;\n }\n var timeout = runTimeout(cleanUpNextTick);\n draining = true;\n\n var len = queue.length;\n while(len) {\n currentQueue = queue;\n queue = [];\n while (++queueIndex < len) {\n if (currentQueue) {\n currentQueue[queueIndex].run();\n }\n }\n queueIndex = -1;\n len = queue.length;\n }\n currentQueue = null;\n draining = false;\n runClearTimeout(timeout);\n}\nexport function nextTick(fun) {\n var args = new Array(arguments.length - 1);\n if (arguments.length > 1) {\n for (var i = 1; i < arguments.length; i++) {\n args[i - 1] = arguments[i];\n }\n }\n queue.push(new Item(fun, args));\n if (queue.length === 1 && !draining) {\n runTimeout(drainQueue);\n }\n}\n// v8 likes predictible objects\nfunction Item(fun, array) {\n this.fun = fun;\n this.array = array;\n}\nItem.prototype.run = function () {\n this.fun.apply(null, this.array);\n};\nexport var title = 'browser';\nexport var platform = 'browser';\nexport var browser = true;\nexport var env = {};\nexport var argv = [];\nexport var version = ''; // empty string to avoid regexp issues\nexport var versions = {};\nexport var release = {};\nexport var config = {};\n\nfunction noop() {}\n\nexport var on = noop;\nexport var addListener = noop;\nexport var once = noop;\nexport var off = noop;\nexport var removeListener = noop;\nexport var removeAllListeners = noop;\nexport var emit = noop;\n\nexport function binding(name) {\n throw new Error('process.binding is not supported');\n}\n\nexport function cwd () { return '/' }\nexport function chdir (dir) {\n throw new Error('process.chdir is not supported');\n};\nexport function umask() { return 0; }\n\n// from https://github.com/kumavis/browser-process-hrtime/blob/master/index.js\nvar performance = global.performance || {}\nvar performanceNow =\n performance.now ||\n performance.mozNow ||\n performance.msNow ||\n performance.oNow ||\n performance.webkitNow ||\n function(){ return (new Date()).getTime() }\n\n// generate timestamp or delta\n// see http://nodejs.org/api/process.html#process_process_hrtime\nexport function hrtime(previousTimestamp){\n var clocktime = performanceNow.call(performance)*1e-3\n var seconds = Math.floor(clocktime)\n var nanoseconds = Math.floor((clocktime%1)*1e9)\n if (previousTimestamp) {\n seconds = seconds - previousTimestamp[0]\n nanoseconds = nanoseconds - previousTimestamp[1]\n if (nanoseconds<0) {\n seconds--\n nanoseconds += 1e9\n }\n }\n return [seconds,nanoseconds]\n}\n\nvar startTime = new Date();\nexport function uptime() {\n var currentTime = new Date();\n var dif = currentTime - startTime;\n return dif / 1000;\n}\n\nexport default {\n nextTick: nextTick,\n title: title,\n browser: browser,\n env: env,\n argv: argv,\n version: version,\n versions: versions,\n on: on,\n addListener: addListener,\n once: once,\n off: off,\n removeListener: removeListener,\n removeAllListeners: removeAllListeners,\n emit: emit,\n binding: binding,\n cwd: cwd,\n chdir: chdir,\n umask: umask,\n hrtime: hrtime,\n platform: platform,\n release: release,\n config: config,\n uptime: uptime\n};\n","(function (global, undefined) {\n \"use strict\";\n\n if (global.setImmediate) {\n return;\n }\n\n var nextHandle = 1; // Spec says greater than zero\n var tasksByHandle = {};\n var currentlyRunningATask = false;\n var doc = global.document;\n var registerImmediate;\n\n function setImmediate(callback) {\n // Callback can either be a function or a string\n if (typeof callback !== \"function\") {\n callback = new Function(\"\" + callback);\n }\n // Copy function arguments\n var args = new Array(arguments.length - 1);\n for (var i = 0; i < args.length; i++) {\n args[i] = arguments[i + 1];\n }\n // Store and register the task\n var task = { callback: callback, args: args };\n tasksByHandle[nextHandle] = task;\n registerImmediate(nextHandle);\n return nextHandle++;\n }\n\n function clearImmediate(handle) {\n delete tasksByHandle[handle];\n }\n\n function run(task) {\n var callback = task.callback;\n var args = task.args;\n switch (args.length) {\n case 0:\n callback();\n break;\n case 1:\n callback(args[0]);\n break;\n case 2:\n callback(args[0], args[1]);\n break;\n case 3:\n callback(args[0], args[1], args[2]);\n break;\n default:\n callback.apply(undefined, args);\n break;\n }\n }\n\n function runIfPresent(handle) {\n // From the spec: \"Wait until any invocations of this algorithm started before this one have completed.\"\n // So if we're currently running a task, we'll need to delay this invocation.\n if (currentlyRunningATask) {\n // Delay by doing a setTimeout. setImmediate was tried instead, but in Firefox 7 it generated a\n // \"too much recursion\" error.\n setTimeout(runIfPresent, 0, handle);\n } else {\n var task = tasksByHandle[handle];\n if (task) {\n currentlyRunningATask = true;\n try {\n run(task);\n } finally {\n clearImmediate(handle);\n currentlyRunningATask = false;\n }\n }\n }\n }\n\n function installNextTickImplementation() {\n registerImmediate = function(handle) {\n process.nextTick(function () { runIfPresent(handle); });\n };\n }\n\n function canUsePostMessage() {\n // The test against `importScripts` prevents this implementation from being installed inside a web worker,\n // where `global.postMessage` means something completely different and can't be used for this purpose.\n if (global.postMessage && !global.importScripts) {\n var postMessageIsAsynchronous = true;\n var oldOnMessage = global.onmessage;\n global.onmessage = function() {\n postMessageIsAsynchronous = false;\n };\n global.postMessage(\"\", \"*\");\n global.onmessage = oldOnMessage;\n return postMessageIsAsynchronous;\n }\n }\n\n function installPostMessageImplementation() {\n // Installs an event handler on `global` for the `message` event: see\n // * https://developer.mozilla.org/en/DOM/window.postMessage\n // * http://www.whatwg.org/specs/web-apps/current-work/multipage/comms.html#crossDocumentMessages\n\n var messagePrefix = \"setImmediate$\" + Math.random() + \"$\";\n var onGlobalMessage = function(event) {\n if (event.source === global &&\n typeof event.data === \"string\" &&\n event.data.indexOf(messagePrefix) === 0) {\n runIfPresent(+event.data.slice(messagePrefix.length));\n }\n };\n\n if (global.addEventListener) {\n global.addEventListener(\"message\", onGlobalMessage, false);\n } else {\n global.attachEvent(\"onmessage\", onGlobalMessage);\n }\n\n registerImmediate = function(handle) {\n global.postMessage(messagePrefix + handle, \"*\");\n };\n }\n\n function installMessageChannelImplementation() {\n var channel = new MessageChannel();\n channel.port1.onmessage = function(event) {\n var handle = event.data;\n runIfPresent(handle);\n };\n\n registerImmediate = function(handle) {\n channel.port2.postMessage(handle);\n };\n }\n\n function installReadyStateChangeImplementation() {\n var html = doc.documentElement;\n registerImmediate = function(handle) {\n // Create a