(function () {
function yell (err) { throw err }
// Fetch the specified number of random names, and turn that into a person
function fetchPeople (total) {
return fetch(`http://randomuser.me/api/?nat=us&results=${total}`, {headers: 'Accept: application/json'}).then(function (response) {
return response.json().then(function (data) {
return data.results.map(function (item, index) {
// Third person should be 1024 bits, as according to demo
return new Person(item.user, (index + 1) % 3 ? 2048 : 1024)
}).catch(yell)
}).catch(yell)
}).catch(yell)
}
// Person class for managing a person and generating their key pair
class Person {
// Apply the persons details from the API, and their nbits
constructor (details, nbits) {
this.details = details
this.code = `${details.name.first} ${details.name.last} <${details.email}>`
this.nbits = nbits
}
// Generate a key pair for the person
// and keep track of the status via a element injected into the parent element
// return a promise once done
generateKeyPair (parentElement) {
var person = this
var status = document.createElement('div')
parentElement.appendChild(status)
return new Promise(function (resolve) {
function progress (o) {
/*
guess
hunting for a prime ...739
confirming prime candidate 50%
found a prime
*/
var message
switch ( o.what ) {
case 'guess':
message = 'guess'
break
case 'fermat':
message = `hunting for a prime ...${o.p.toString().substr(-3)}`
break
case 'mr':
var percent = Math.floor(o.i / o.total * 100)
message = `confirming prime candidate ${percent}%`
break
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.