secrets.js
function combine(at, shares){
	var setBits, share, x = [], y = [], result = '', idx;	
	
	for(var i=0, len = shares.length; i<len; i++){
		share = processShare(shares[i]);
		if(typeof setBits === 'undefined'){
			setBits = share['bits'];
		}else if(share['bits'] !== setBits){
			throw new Error('Mismatched shares: Different bit settings.')
		}
		
		if(config.bits !== setBits){
			init(setBits);
		}
		
		if(inArray(x, share['id'])){ // repeated x value?
			continue;
		}
	
		idx = x.push(share['id']) - 1;
		share = split(hex2bin(share['value']));
		for(var j=0, len2 = share.length; j<len2; j++){
			y[j] = y[j] || [];
			y[j][idx] = share[j];
		}
	}
	
	for(var i=0, len=y.length; i<len; i++){
		result = padLeft(lagrange(at, x, y[i]).toString(2)) + result;
	}

	if(at===0){// reconstructing the secret
		var idx = result.indexOf('1'); //find the first 1
		return bin2hex(result.slice(idx+1));
	}else{// generating a new share
		return bin2hex(result);
	}
}
function combine(at, shares){
	var setBits, share, x = [], y = [], result = '', idx;	
	
	for(var i=0, len = shares.length; i<len; i++){
		share = processShare(shares[i]);
		if(typeof setBits === 'undefined'){
			setBits = share['bits'];
		}else if(share['bits'] !== setBits){
			throw new Error('Mismatched shares: Different bit settings.')
		}
		
		if(config.bits !== setBits){
			init(setBits);
		}
		
		if(inArray(x, share['id'])){ // repeated x value?
			continue;
		}
	
		idx = x.push(share['id']) - 1;
		share = split(hex2bin(share['value']));
		for(var j=0, len2 = share.length; j<len2; j++){
			y[j] = y[j] || [];
			y[j][idx] = share[j];
		}
	}
	
	for(var i=0, len=y.length; i<len; i++){
		result = padLeft(lagrange(at, x, y[i]).toString(2)) + result;
	}

	if(at===0){// reconstructing the secret
		var idx = result.indexOf('1'); //find the first 1
		return bin2hex(result.slice(idx+1));
	}else{// generating a new share
		return bin2hex(result);
	}
}
function combine ( at , shares ) { var setBits , share , x = [ ] , y = [ ] , result = '' , idx ; for ( var i = 0 , len = shares . length ; i < len ; i ++ ) { share = processShare ( shares [ i ] ) ; if ( typeof setBits === 'undefined' ) { setBits = share [ 'bits' ] ; } else if ( share [ 'bits' ] !== setBits ) { throw new Error ( 'Mismatched shares: Different bit settings.' ) } if ( config . bits !== setBits ) { init ( setBits ) ; } if ( inArray ( x , share [ 'id' ] ) ) { // repeated x value? continue ; } idx = x . push ( share [ 'id' ] ) - 1 ; share = split ( hex2bin ( share [ 'value' ] ) ) ; for ( var j = 0 , len2 = share . length ; j < len2 ; j ++ ) { y [ j ] = y [ j ] || [ ] ; y [ j ] [ idx ] = share [ j ] ; } } for ( var i = 0 , len = y . length ; i < len ; i ++ ) { result = padLeft ( lagrange ( at , x , y [ i ] ) . toString ( 2 ) ) + result ; } if ( at === 0 ) { // reconstructing the secret var idx = result . indexOf ( '1' ) ; //find the first 1 return bin2hex ( result . slice ( idx + 1 ) ) ; } else { // generating a new share return bin2hex ( result ) ; } }
Protected method that evaluates the Lagrange interpolation polynomial at x=`at` for individual config.bits-length segments of each share in the `shares` Array. Each share is expressed in base `inputRadix`. The output is expressed in base `outputRadix'
Protected method that evaluates the Lagrange interpolation polynomial at x = at for individual config . bits - length segments of each share in the shares Array . Each share is expressed in base inputRadix . The output is expressed in base outputRadix