Skip to content
Snippets Groups Projects
Commit bef67c11 authored by Millicent Billette's avatar Millicent Billette
Browse files

vanityLike.mjs improved to find perfect debugSeed

parent 6f3ec9aa
No related branches found
No related tags found
No related merge requests found
import * as app from "../src/crypto.mjs";
// For thread use : https://github.com/darionco/WebCPU
const fillChr=' ';
function f(size,str){ // format
const toFill = size-str.length;
if(toFill>0) return fillChr.substring(0,toFill)+str;
return str;
}
function main() {
for (let x = 1; true; x++) {
const strX = ('' + x).replace(/0/g, '');
if (
app.pubKey2checksum('pubKey' + strX) !== app.pubKey2checksum('pubKey' + strX, false, true)
&&
app.pubKey2checksum('pubKey' + strX, true) !== app.pubKey2checksum('pubKey' + strX, true, true)
/*&&
app.pubKey2checksum('pubKey'+strX).includes('11')
&&
app.pubKey2checksum('pubKey'+strX,true).includes('11')
*/
) {
console.log('pubKey' + strX,
app.pubKey2checksum('pubKey' + strX),
app.pubKey2checksum('pubKey' + strX, false, true),
app.pubKey2checksum('pubKey' + strX, true),
app.pubKey2checksum('pubKey' + strX, true, true)
);
console.log('11111111111111111111111pubKey49311',
app.pubKey2checksum('11111111111111111111111pubKey49311'),
app.pubKey2checksum('11111111111111111111111pubKey49311', false, true),
app.pubKey2checksum('11111111111111111111111pubKey49311', true),
app.pubKey2checksum('11111111111111111111111pubKey49311', true, true)
);
return 'pubKey' + strX;
let PARALLEL_INDEX = 0;
if(process.argv[2]) PARALLEL_INDEX = parseInt(process.argv[2]);
const PARALLEL_THREAD = 4;
const startTime = Date.now(); // performance.now()
let partialLevel = 0;
for (let x = PARALLEL_INDEX; true; x+=PARALLEL_THREAD) {
const strX = ('vanityDebugSeed' + x).replace(/0/g, 'z');
const keys = app.raw2b58(app.seed2keyPair(app.b58pubKey2bin(strX)));
let pubKey = keys.publicKey;
if(pubKey[0]==='1'){
pubKey = app.b58.encode(app.sliceInitialsZero(app.b58pubKey2bin(pubKey)));
const now = Date.now(); // performance.now()
const elapsed = f(7,''+Math.trunc((now-startTime)/1000));
const speed = f(5,''+Math.trunc((x/PARALLEL_THREAD)/((now-startTime)/1000)));
if(partialLevel<2){
partialLevel=1;
console.log(`${speed}/s écoulé: ${elapsed}s seed:${f(44,strX)} pubKey:${f(44,pubKey)}`);
}
if(pubKey.length===42){
if(partialLevel<3){
partialLevel=2;
console.log(`${speed}/s écoulé: ${elapsed}s seed:${f(44,strX)} pubKey:${f(44,pubKey)}`);
}
if(app.pubKey2checksum(pubKey)[0]==='1'){
if(partialLevel<4){
partialLevel=3;
console.log(`${speed}/s écoulé: ${elapsed}s seed:${f(44,strX)} pubKey:${f(44,pubKey)} chk: ${app.pubKey2checksum(pubKey)} ${app.pubKey2checksum(pubKey, false, true)}`);
}
if(app.pubKey2checksum(pubKey,true)[0]==='1'){
console.log(`${speed}/s écoulé: ${elapsed}s seed:${f(44,strX)} pubKey:${f(44,pubKey)
} chk: ${app.pubKey2checksum(pubKey)} ${app.pubKey2checksum(pubKey, false, true)
} ${app.pubKey2checksum(pubKey,true)} ${app.pubKey2checksum(pubKey,true, true)}`);
return;
}
}
}
}
if (strX.includes('99999')) console.log('pubKey' + strX);
}
}
main();
// 111111111111111111111111111194999 BswTw MRTt8 6WCPk P3g1N 3kVZx 29cPB oTPUq 8rk41 gup
// 111111111111111111111111111111451 12rxvfozNLMgzH5j8sQZUCZKSMh5NGBYqaqXiSq5ifCE 7T5 7T5 7T5 7T5
// 161/s écoulé: 105s seed:171z8 pubKey:MKZWhcbCVoxLrUyZGKTQQDJwkg3CyxDJEf1NFfUdgk
// 161/s écoulé: 105s seed:171z8 pubKey: MKZWh cbCVo xLrUy ZGKTQ QDJwk g3Cyx DJEf1 NFfUd gk
......@@ -19,7 +19,9 @@ An ubiquitous static javascript lib for Ǧ1 / Duniter ecosystem with reliability
- [x] Unit tested
- [x] Tracked quality metrics
- [x] Static package with no-dependency
- [x] modern esm import/export
- [x] import only what you need*
*modern esm import/export & high modularity improve tree-shaking
## Usage
......
......@@ -21,7 +21,7 @@ export async function idSecPass2rawAll(idSec, pass) {
};
}
function raw2b58(raws) {
export function raw2b58(raws) {
const result = {};
for (const r in raws) result[r] = b58.encode(raws[r]);
return result;
......@@ -60,15 +60,18 @@ export function pubKey2checksum(b58pubKey, b58viewDependant = false, checksumWit
else binPubKey = b58pubKey2bin(b58pubKey);
const hash = sha256.digest(sha256.digest(binPubKey));
if (checksumWithoutLeadingZero) {
let zero = 0
while (hash[zero] === 0) zero++;
const shorterHash = hash.slice(zero);
const shorterHash = sliceInitialsZero(hash);
return b58.encode(shorterHash).substr(0, 3);
}
return b58.encode(hash).substr(0, 3);
}
export function sliceInitialsZero(array){
let zero = 0
while (array[zero] === 0) zero++;
return array.slice(zero);
}
function b58pubKey2bin(b58pubKey) {
export function b58pubKey2bin(b58pubKey) {
const binPubKey = new Uint8Array(32);
const decoded = b58.decode(b58pubKey);
binPubKey.set(decoded, 32 - decoded.length);
......
......@@ -71,3 +71,6 @@ test('checkKey false 11111111111111111111111pubKey49311:2p7', t => t.throws(() =
test('checkKey false pubKey49311:111', t => t.throws(() => app.checkKey('pubKey49311:111')));
test('checkKey false 0pubKey49311:any', t => t.throws(() => app.checkKey('0pubKey49311:any')));
test('pubKey2checksum 11111111111111111111111pubKey49311 : 14R', t => t.is(app.pubKey2checksum('11111111111111111111111pubKey49311'), '14R'));
test('pubKey2checksum pubKey49311 : 14R', t => t.is(app.pubKey2checksum('pubKey49311'), '14R'));
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment