publickey.min.js
5.8 KB
/**
* PublicKey.js - v0e011cb1
*
* @source https://github.com/diafygi/publickeyjs/blob/master/publickey.js
*
* @licstart The following is the entire license notice for the
* JavaScript code in this file.
*
* Copyright (c) 2015 Daniel Roesler
*
* The JavaScript code in this page is free software: you can
* redistribute it and/or modify it under the terms of the GNU
* General Public License (GNU GPL) as published by the Free Software
* Foundation, either version 3 of the License, or (at your option)
* any later version. The code is distributed WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
*
* As additional permission under GNU GPL version 3 section 7, you
* may distribute non-source (e.g., minimized or compacted) forms of
* that code without the copy of the GNU GPL normally required by
* section 4, provided you include this license notice and a URL
* through which recipients can access the Corresponding Source.
*
* @licend The above is the entire license notice
* for the JavaScript code in this file.
*/
"use strict";!function(e){function t(e){this.keyservers=e||i}var i=["https://keys.fedoraproject.org/","https://keybase.io/"];t.prototype.get=function(t,i,n,e){if((n=void 0===n?0:n)>=this.keyservers.length)return i(null,e||404);var s,e=this.keyservers[n],r=this;0===e.indexOf("https://keybase.io/")?(0===t.indexOf("0x")&&(t=t.substr(2)),(s=new XMLHttpRequest).open("get","https://keybase.io/_/api/1.0/user/lookup.json?fields=public_keys&key_fingerprint="+t),s.onload=function(){if(200!==s.status)return r.get(t,i,n+1,s.status);var e=JSON.parse(s.responseText);if(0!==e.status.code)return r.get(t,i,n+1,e.status.code);if(0===e.them.length)return r.get(t,i,n+1,404);e=e.them[0].public_keys.primary.bundle;return i(e,null)}):(0!==t.indexOf("0x")&&(t="0x"+t),(s=new XMLHttpRequest).open("get",e+"pks/lookup?op=get&options=mr&search="+t),s.onload=function(){return 200===s.status?i(s.responseText,null):r.get(t,i,n+1,s.status)}),s.send()},t.prototype.search=function(o,d,a,u,e){if(void 0===u&&(u=[]),(a=void 0===a?0:a)>=this.keyservers.length){if(0===u.length)return d(null,e||404);for(var t={},i=0;i<u.length;i++)if(void 0!==t[(l=u[i]).keyid])for(var n=0;n<l.uids.length;n++){for(var s=!1,r=0;r<t[l.keyid].uids.length;r++)if(t[l.keyid].uids[r].uid===l.uids[n]){s=!0;break}s||t[l.keyid].uids.push(l.uids[n])}else t[l.keyid]=l;for(var l,p=[],i=0;i<u.length;i++)void 0!==t[(l=u[i]).keyid]&&(p.push(t[l.keyid]),delete t[l.keyid]);return d(p,null)}var h,c=this.keyservers[a],v=this;0===c.indexOf("https://keybase.io/")?((h=new XMLHttpRequest).open("get","https://keybase.io/_/api/1.0/user/autocomplete.json?q="+encodeURIComponent(o)),h.onload=function(){if(200!==h.status)return v.search(o,d,a+1,u,h.status);var e=JSON.parse(h.responseText);if(0!==e.status.code)return v.search(o,d,a+1,u,e.status.code);if(0===e.completions.length)return v.search(o,d,a+1,u,404);for(var t=[],i=0;i<e.completions.length;i++){var n=e.completions[i].components;if(void 0!==n.key_fingerprint){var s={keyid:n.key_fingerprint.val.toUpperCase(),href:"https://keybase.io/"+n.username.val+"/key.asc",info:"https://keybase.io/"+n.username.val,algo:n.key_fingerprint.algo,keylen:n.key_fingerprint.nbits,creationdate:null,expirationdate:null,revoked:!1,disabled:!1,expired:!1,uids:[{uid:n.username.val+" on Keybase <https://keybase.io/"+n.username.val+">",creationdate:null,expirationdate:null,revoked:!1,disabled:!1,expired:!1}]};if(void 0!==n.full_name&&s.uids.push({uid:"Full Name: "+n.full_name.val,creationdate:null,expirationdate:null,revoked:!1,disabled:!1,expired:!1}),void 0!==n.twitter&&s.uids.push({uid:n.twitter.val+" on Twitter <https://twitter.com/"+n.twitter.val+">",creationdate:null,expirationdate:null,revoked:!1,disabled:!1,expired:!1}),void 0!==n.github&&s.uids.push({uid:n.github.val+" on Github <https://github.com/"+n.github.val+">",creationdate:null,expirationdate:null,revoked:!1,disabled:!1,expired:!1}),void 0!==n.reddit&&s.uids.push({uid:n.reddit.val+" on Github <https://reddit.com/u/"+n.reddit.val+">",creationdate:null,expirationdate:null,revoked:!1,disabled:!1,expired:!1}),void 0!==n.hackernews&&s.uids.push({uid:n.hackernews.val+" on Hacker News <https://news.ycombinator.com/user?id="+n.hackernews.val+">",creationdate:null,expirationdate:null,revoked:!1,disabled:!1,expired:!1}),void 0!==n.coinbase&&s.uids.push({uid:n.coinbase.val+" on Coinbase <https://www.coinbase.com/"+n.coinbase.val+">",creationdate:null,expirationdate:null,revoked:!1,disabled:!1,expired:!1}),void 0!==n.websites)for(var r=0;r<n.websites.length;r++)s.uids.push({uid:"Owns "+n.websites[r].val,creationdate:null,expirationdate:null,revoked:!1,disabled:!1,expired:!1});t.push(s)}}return u=u.concat(t),v.search(o,d,a+1,u,null)}):((h=new XMLHttpRequest).open("get",c+"pks/lookup?op=index&options=mr&fingerprint=on&search="+encodeURIComponent(o)),h.onload=function(){if(200!==h.status)return v.search(o,d,a+1,u,h.status);for(var e=[],t=h.responseText.split("\n"),i=void 0,n=0;n<t.length;n++){var s,r=t[n].trim();0==r.indexOf("pub:")&&(void 0!==i&&e.push(i),i={keyid:(s=r.split(":"))[1],href:c+"pks/lookup?op=get&options=mr&search=0x"+s[1],info:c+"pks/lookup?op=vindex&search=0x"+s[1],algo:""===s[2]?null:parseInt(s[2]),keylen:""===s[3]?null:parseInt(s[3]),creationdate:""===s[4]?null:parseInt(s[4]),expirationdate:""===s[5]?null:parseInt(s[5]),revoked:-1!==s[6].indexOf("r"),disabled:-1!==s[6].indexOf("d"),expired:-1!==s[6].indexOf("e"),uids:[]}),0==r.indexOf("uid:")&&(s=r.split(":"),i.uids.push({uid:decodeURIComponent(s[1]),creationdate:""===s[2]?null:parseInt(s[2]),expirationdate:""===s[3]?null:parseInt(s[3]),revoked:-1!==s[4].indexOf("r"),disabled:-1!==s[4].indexOf("d"),expired:-1!==s[4].indexOf("e")}))}return e.push(i),u=u.concat(e),v.search(o,d,a+1,u,null)}),h.send()},e.PublicKey=t}("undefined"==typeof exports?this:exports);