|
|
@ -310,16 +310,64 @@ int32_t _SuperNET_encryptjson(struct supernet_info *myinfo,char *destfname,char |
|
|
|
return(0); |
|
|
|
} |
|
|
|
|
|
|
|
int32_t LP_wifstr_valid(char *symbol,char *wifstr); |
|
|
|
int32_t curve25519_donna(uint8_t *mypublic,const uint8_t *secret,const uint8_t *basepoint); |
|
|
|
|
|
|
|
static const char base58_chars[] = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; |
|
|
|
|
|
|
|
int32_t iguana_wifstr_valid(char *wifstr) |
|
|
|
{ |
|
|
|
bits256 privkey,cmpkey; uint8_t wiftype; char cmpstr[128],cmpstr2[128]; int32_t i,len,n,a,A; |
|
|
|
if ( (len= (int32_t)strlen(wifstr)) < 50 || len > 54 ) |
|
|
|
{ |
|
|
|
//printf("len.%d is wrong for wif %s\n",len,wifstr);
|
|
|
|
return(0); |
|
|
|
} |
|
|
|
memset(privkey.bytes,0,sizeof(privkey)); |
|
|
|
memset(cmpkey.bytes,0,sizeof(cmpkey)); |
|
|
|
for (i=n=a=A=0; wifstr[i]!=0; i++) |
|
|
|
{ |
|
|
|
if ( strchr(base58_chars,wifstr[i]) == 0 ) |
|
|
|
return(0); |
|
|
|
if ( wifstr[i] >= '1' && wifstr[i] <= '9' ) |
|
|
|
n++; |
|
|
|
else if ( wifstr[i] >= 'A' && wifstr[i] <= 'Z' ) |
|
|
|
A++; |
|
|
|
else if ( wifstr[i] >= 'a' && wifstr[i] <= 'z' ) |
|
|
|
a++; |
|
|
|
} |
|
|
|
if ( n == 0 || A == 0 || a == 0 ) |
|
|
|
return(0); |
|
|
|
if ( A > 5*a || a > 5*A || a > n*20 || A > n*20 ) // unlikely it is a real wif
|
|
|
|
{ |
|
|
|
printf("reject wif %s due to n.%d a.%d A.%d (%d %d %d %d)\n",wifstr,n,a,A,A > 5*a,a < 5*A,a > n*20,A > n*20); |
|
|
|
return(0); |
|
|
|
} |
|
|
|
bitcoin_wif2priv(&wiftype,&privkey,wifstr); |
|
|
|
bitcoin_priv2wif(cmpstr,privkey,wiftype); |
|
|
|
if ( strcmp(cmpstr,wifstr) == 0 ) |
|
|
|
{ |
|
|
|
//printf("%s is valid wif\n",wifstr);
|
|
|
|
return(1); |
|
|
|
} |
|
|
|
else if ( bits256_nonz(privkey) != 0 ) |
|
|
|
{ |
|
|
|
bitcoin_wif2priv(&wiftype,&cmpkey,cmpstr); |
|
|
|
bitcoin_priv2wiflong(cmpstr2,privkey,wiftype); |
|
|
|
if ( bits256_cmp(privkey,cmpkey) == 0 ) |
|
|
|
return(1); |
|
|
|
char str[65],str2[65]; printf("mismatched wifstr %s -> %s -> %s %s %s\n",wifstr,bits256_str(str,privkey),cmpstr,bits256_str(str2,cmpkey),cmpstr2); |
|
|
|
} |
|
|
|
char str[65]; printf("%s is not a wif, privkey.%s\n",wifstr,bits256_str(str,privkey)); |
|
|
|
return(0); |
|
|
|
} |
|
|
|
|
|
|
|
void SuperNET_setkeys(struct supernet_info *myinfo,void *pass,int32_t passlen,int32_t dosha256) |
|
|
|
{ |
|
|
|
static uint8_t basepoint[32] = {9}; bits256 hash; uint8_t addrtype,usedwif = 0; |
|
|
|
if ( dosha256 != 0 ) |
|
|
|
{ |
|
|
|
memcpy(myinfo->secret,pass,passlen+1); |
|
|
|
if ( LP_wifstr_valid("KMD",pass) > 0 ) |
|
|
|
if ( iguana_wifstr_valid((char *)pass) > 0 ) |
|
|
|
{ |
|
|
|
usedwif = 1; |
|
|
|
bitcoin_wif2priv(&addrtype,&myinfo->persistent_priv,(char *)pass); |
|
|
|