Browse Source

help dir and help.json auto created

release/v0.1
jl777 9 years ago
parent
commit
6f31f7be56
  1. 50
      deprecated/obsolete.h
  2. 358
      iguana/exchanges/bitcoin.c
  3. 5
      iguana/iguana777.h
  4. 43
      iguana/iguana_json.c
  5. 40
      iguana/iguana_pubkeys.c
  6. 3
      iguana/iguana_tx.c
  7. 9
      iguana/main.c
  8. 6
      iguana/ramchain_api.c

50
deprecated/obsolete.h

@ -12904,5 +12904,55 @@ len = 0;
}
return(len);
}
void pktest()
{
bits256 p,pub; uint8_t *data,*pubkey,sig[128],*sigptr; struct bp_key key; size_t pubk_len;
int32_t s,v,v2,v4=-99,v3=-99,datalen; uint32_t siglen; EC_KEY *KEY;
//bp_key_init(&key);
// bp_key_generate(&key);
OS_randombytes(p.bytes,sizeof(p));
data = (uint8_t *)"hello", datalen = (int32_t)strlen("hello");
//s = bp_sign(key.k,data,datalen,(void **)&sigptr,&siglen);
//sigptr = sig;
//siglen = iguana_sig(sig,sizeof(sig),data,datalen,p);
//const unsigned char *privkey;
//bp_privkey_set(&key,p.bytes,sizeof(p));
//bp_pubkey_get(&key,(void **)&pubkey,&pubk_len);
//memcpy(pub.bytes,pubkey+1,sizeof(pub));
KEY = bitcoin_privkeyset(&pub,p);
siglen = bitcoin_sign(sig,sizeof(sig),data,datalen,p);
s = siglen > 0;
// char str[65]; printf("siglen.%d pk_len.%ld %s\n",siglen,pubk_len,bits256_str(str,*(bits256 *)(pubkey+1)));
//s = ECDSA_sign(0,data,datalen,sig,&siglen,KEY);
v2 = bp_verify(KEY,data,datalen,sig,siglen);
//bp_pubkey_get(&key,(void **)&pubkey,&pubk_len);
//bp_key_init(&key);
v3 = bitcoin_verify(sig,siglen,data,datalen,pub);
//v = iguana_ver(sig,siglen,data,datalen,pub);
printf("s.%d siglen.%d v2.%d v3.%d v4.%d\n",s,siglen,v2,v3,v4);
getchar();
}
http://bitcoin.stackexchange.com/questions/3374/how-to-redeem-a-basic-tx
//msgtx->vins[i].scriptlen = scriptlen;
//printf("VINI.%d (%s)\n",vini,jprint(bitcoin_txjson(coin,msgtx),1));
//decode_hex(privkey.bytes,sizeof(privkey),"18E14A7B6A307F426A94F8114701E7C8E774E7F9A47E2C2035DB29A206321725");
//printf("privkey.%s\n",bits256_str(str,privkey));
//EC_KEY *KEY = bitcoin_privkeyset(&pkey,privkey);
char *refstr = "01000000\
01\
eccf7e3034189b851985d871f91384b8ee357cd47c3024736e5676eb2debb3f2\
01000000\
8c\
4930460221009e0339f72c793a89e664a8a932df073962a3f84eda0bd9e02084a6a9567f75aa022100bd9cbaca2e5ec195751efdfac164b76250b1e21302e51ca86dd7ebd7020cdc0601410450863ad64a87ae8a2fe83c1af1a8403cb53f53e486d8511dad8a04887e5b23522cd470243453a299fa9e77237716103abc11a1df38855ed6f2ee187e9c582ba6\
ffffffff\
01\
605af40500000000\
19\
76a914097072524438d003d23a2f23edb65aae1bb3e46988ac\
00000000";
#endif

358
iguana/exchanges/bitcoin.c

@ -15,9 +15,6 @@
#include "bitcoin.h"
//void bu_Hash4(unsigned char *md32,const void *data,size_t data_len);
//cstring *bn_getvch(const BIGNUM *v);
static const char base58_chars[] = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
void bn_mpi2bn(BIGNUM *vo,uint8_t *data,int32_t datalen)
@ -49,7 +46,7 @@ int32_t bn_bn2mpi(uint8_t *data,const BIGNUM *v)
return(sz);
}
char *bitcoin_base58(char *coinaddr,uint8_t *data_,int32_t datalen)
char *bitcoin_base58encode(char *coinaddr,uint8_t *data_,int32_t datalen)
{
BIGNUM bn58,bn0,bn,dv,rem; BN_CTX *ctx; uint32_t i,n,flag=0; uint8_t swapbuf[512],rs[512];
const uint8_t *data = (void *)data_;
@ -94,73 +91,185 @@ char *bitcoin_base58(char *coinaddr,uint8_t *data_,int32_t datalen)
return(0);
}
char *bitcoin_address(char *coinaddr,uint8_t addrtype,uint8_t pubkey[33])
int32_t bitcoin_base58decode(uint8_t *data,char *coinaddr)
{
uint32_t zeroes,be_sz=0,i,len; const char *p,*p1; BIGNUM bn58,bn,bnChar; uint8_t revdata[64]; BN_CTX *ctx;
ctx = BN_CTX_new();
BN_init(&bn58), BN_init(&bn), BN_init(&bnChar);
BN_set_word(&bn58,58), BN_set_word(&bn,0);
while ( isspace(*coinaddr) )
coinaddr++;
for (p=coinaddr; *p; p++)
{
p1 = strchr(base58_chars,*p);
if ( p1 == 0 )
{
while (isspace((uint32_t)*p))
p++;
if ( *p != '\0' )
goto out;
break;
}
BN_set_word(&bnChar,(int32_t)(p1 - base58_chars));
if ( BN_mul(&bn,&bn,&bn58,ctx) == 0 || BN_add(&bn,&bn,&bnChar) == 0 )
goto out;
}
len = bn_bn2mpi(revdata,&bn);
if ( len >= 2 && revdata[len - 1] == 0 && revdata[len - 2] >= 0x80 )
len--;
zeroes = 0;
for (p=coinaddr; *p==base58_chars[0]; p++)
zeroes++;
be_sz = (uint32_t)len + (uint32_t)zeroes;
memset(data,0,be_sz);
for (i=0; i<len; i++)
data[i + zeroes] = revdata[be_sz - 1 - i];
out:
BN_clear_free(&bn58), BN_clear_free(&bn), BN_clear_free(&bnChar);
BN_CTX_free(ctx);
return(be_sz);
}
int32_t bitcoin_addr2rmd160(uint8_t *addrtypep,uint8_t rmd160[20],char *coinaddr)
{
bits256 hash; uint8_t buf[25]; int32_t len;
memset(rmd160,0,20);
*addrtypep = 0;
if ( (len= bitcoin_base58decode(buf,coinaddr)) >= 4 )
{
// validate with trailing hash, then remove hash
hash = bits256_doublesha256(0,buf,len - 4);
if ( (buf[len - 4]&0xff) == hash.bytes[31] && (buf[len - 3]&0xff) == hash.bytes[30] &&(buf[len - 2]&0xff) == hash.bytes[29] &&(buf[len - 1]&0xff) == hash.bytes[28] )
{
*addrtypep = buf[0];
memcpy(rmd160,buf+1,20);
return(20);
}
else
{
char str[65]; printf("checkhash mismatch %02x %02x %02x %02x vs %02x %02x %02x %02x (%s)\n",buf[len - 4]&0xff,buf[len - 3]&0xff,buf[len - 2]&0xff,buf[len - 1]&0xff,hash.bytes[31],hash.bytes[30],hash.bytes[29],hash.bytes[28],bits256_str(str,hash));
}
}
return(0);
}
char *bitcoin_address(char *coinaddr,uint8_t addrtype,uint8_t *pubkey,int32_t len)
{
int32_t i; uint8_t data[25]; bits256 hash; char checkaddr[65];
vcalc_sha256(0,hash.bytes,pubkey,33);
vcalc_sha256(0,hash.bytes,pubkey,len);
calc_rmd160(0,data+1,hash.bytes,sizeof(hash));
btc_convrmd160(checkaddr,addrtype,data+1);
for (i=0; i<20; i++)
printf("%02x",data[i+1]);
printf(" RMD160 len.%d\n",len);
data[0] = addrtype;
hash = bits256_doublesha256(0,data,21);
for (i=0; i<4; i++)
data[21+i] = hash.bytes[31-i];
if ( (coinaddr= bitcoin_base58(coinaddr,data,25)) != 0 )
printf("checkaddr.(%s) vs coinaddr.(%s)\n",checkaddr,coinaddr);
if ( (coinaddr= bitcoin_base58encode(coinaddr,data,25)) != 0 )
{
uint8_t checktype,rmd160[20];
bitcoin_addr2rmd160(&checktype,rmd160,coinaddr);
printf("checkaddr.(%s) vs coinaddr.(%s) %02x vs [%02x] memcmp.%d\n",checkaddr,coinaddr,addrtype,checktype,memcmp(rmd160,data+1,20));
}
return(coinaddr);
}
EC_KEY *bitcoin_key()
EC_KEY *bitcoin_privkeyset(uint8_t *oddevenp,bits256 *pubkeyp,bits256 privkey)
{
return(EC_KEY_new_by_curve_name(NID_secp256k1));
BIGNUM *bn; BN_CTX *ctx = NULL; uint8_t *ptr,tmp[33]; EC_POINT *pub_key = NULL; const EC_GROUP *group;
EC_KEY *KEY = EC_KEY_new_by_curve_name(NID_secp256k1);
*oddevenp = 0;
EC_KEY_set_conv_form(KEY,POINT_CONVERSION_COMPRESSED);
{
if ( (group= EC_KEY_get0_group(KEY)) != 0 && (ctx= BN_CTX_new()) != 0 )
{
if ( (pub_key= EC_POINT_new(group)) != 0 )
{
if ( (bn= BN_bin2bn(privkey.bytes,sizeof(privkey),BN_new())) != 0 )
{
if ( EC_POINT_mul(group,pub_key,bn,NULL,NULL,ctx) > 0 )
{
EC_KEY_set_private_key(KEY,bn);
EC_KEY_set_public_key(KEY,pub_key);
ptr = tmp;
i2o_ECPublicKey(KEY,&ptr);
*oddevenp = tmp[0];
memcpy(pubkeyp->bytes,&tmp[1],sizeof(*pubkeyp));
}
BN_clear_free(bn);
}
EC_POINT_free(pub_key);
}
BN_CTX_free(ctx);
}
}
return(KEY);
}
void bitcoin_keyfree(EC_KEY *key)
bits256 bitcoin_pubkey(uint8_t *data,bits256 privkey)
{
if ( key != 0 )
EC_KEY_free(key);
uint8_t oddeven; bits256 pubkey;
EC_KEY *KEY;
if ( (KEY= bitcoin_privkeyset(&oddeven,&pubkey,privkey)) != 0 )
{
data[0] = oddeven;
memcpy(data+1,pubkey.bytes,sizeof(pubkey));
EC_KEY_free(KEY);
}
return(pubkey);
}
int32_t bitcoin_pubkeyset(EC_KEY **keyp,uint8_t *pubkey,int32_t pk_len)
int32_t bitcoin_sign(uint8_t *sig,int32_t maxlen,uint8_t *data,int32_t datalen,bits256 privkey)
{
//const unsigned char *pubkey = pubkey_;
if ( o2i_ECPublicKey(keyp,(void *)&pubkey,pk_len) == 0 )
return(-1);
if ( pk_len == 33 )
EC_KEY_set_conv_form(*keyp,POINT_CONVERSION_COMPRESSED), printf("compressed key\n");
return(0);
uint32_t siglen; EC_KEY *KEY; uint8_t oddeven; bits256 pubkey; int32_t retval = -1;
if ( (KEY= bitcoin_privkeyset(&oddeven,&pubkey,privkey)) != 0 )
{
if ( ECDSA_sign(0,data,datalen,sig,&siglen,KEY) > 0 && siglen <= maxlen )
retval = siglen;
EC_KEY_free(KEY);
}
return(retval);
}
int32_t bitcoin_verify(EC_KEY *key_,uint8_t *data,int32_t datalen,uint8_t *sig_,int32_t siglen)
{
int32_t bp_verify(EC_KEY *key, const void *data, size_t data_len,const void *sig_, size_t sig_len);
int32_t bp_sign(EC_KEY *key, const void *data, size_t data_len,void **sig_, size_t *sig_len_);
uint8_t newsig[256],*sig = newsig; size_t newlen;
uint8_t pubkey[33]; EC_KEY *key;
key = bitcoin_key();
decode_hex(pubkey,sizeof(pubkey),"03506a52e95cdfbb9d17d702af6259ba7de8b7a604007999e0266edbf6e4bb6974");
bitcoin_pubkeyset(&key,pubkey,sizeof(pubkey));
if ( bp_sign(key,data,datalen,(void **)&sig,&newlen) != 0 )
printf("got new sig\n");
else printf("sig error\n");
printf("siglen.%ld\n",newlen);
if ( bp_verify(key,data,datalen,newsig,newlen) != 0 )
return(0);
else return(-1);
/*const uint8_t *sig = (void *)sig_; ECDSA_SIG *esig; int32_t x,retval = -1;
if ( (esig= ECDSA_SIG_new()) != 0 )
int32_t bitcoin_verify(uint8_t *sig,int32_t siglen,uint8_t *data,int32_t datalen,EC_KEY *KEY,uint8_t *pubkey,int32_t len)
{
ECDSA_SIG *esig; int32_t retval = -1; uint8_t tmp[33],*ptr,*sigptr = sig; EC_KEY *origkey = KEY;
if ( (esig= ECDSA_SIG_new()) != 0 )
{
if ( d2i_ECDSA_SIG(&esig,&sig,siglen) != 0 )
if ( d2i_ECDSA_SIG(&esig,(const uint8_t **)&sigptr,siglen) != 0 )
{
if ( (x= ECDSA_do_verify(data,datalen,esig,key)) == 1 )
retval = 0;
printf("bitcoin_verify x.%d\n",x);
if ( KEY != 0 || (KEY= EC_KEY_new_by_curve_name(NID_secp256k1)) != 0 )
{
EC_KEY_set_conv_form(KEY,POINT_CONVERSION_COMPRESSED);
if ( len == 32 )
{
memcpy(tmp+1,pubkey,len);
for (tmp[0]=2; tmp[0]<=3; tmp[0]++)
{
ptr = tmp;
o2i_ECPublicKey(&KEY,(const uint8_t **)&ptr,33);
if ( ECDSA_do_verify(data,datalen,esig,KEY) > 0 )
{
retval = 0;
break;
}
}
}
else
{
ptr = pubkey;
o2i_ECPublicKey(&KEY,(const uint8_t **)&ptr,len);
if ( ECDSA_do_verify(data,datalen,esig,KEY) > 0 )
retval = 0;
}
if ( origkey == 0 )
EC_KEY_free(KEY);
}
}
ECDSA_SIG_free(esig);
}
return(retval);*/
return(retval);
}
int32_t bitcoin_standardspend(uint8_t *script,int32_t n,uint8_t rmd160[20])
@ -535,15 +644,15 @@ bits256 iguana_parsetxobj(struct iguana_info *coin,uint8_t *serialized,int32_t m
return(txid);
}
char *iguana_rawtxbytes(struct iguana_info *coin,cJSON *json,uint8_t *data,int32_t datalen)
char *iguana_rawtxbytes(struct iguana_info *coin,uint8_t *serialized,int32_t datalen,cJSON *json,struct iguana_msgtx *msgtx)
{
int32_t n; char *txbytes,vpnstr[64]; struct iguana_msgtx tx;
int32_t n; char *txbytes,vpnstr[64];
vpnstr[0] = 0;
//char str[65]; printf("%d of %d: %s\n",i,msg.txn_count,bits256_str(str,tx.txid));
if ( (n= iguana_rwmsgtx(coin,0,json,data,datalen,&tx,&tx.txid,vpnstr)) > 0 )
if ( (n= iguana_rwmsgtx(coin,1,json,serialized,datalen,msgtx,&msgtx->txid,vpnstr)) > 0 )
{
txbytes = malloc(n*2+1);
init_hexbytes_noT(txbytes,data,n);
init_hexbytes_noT(txbytes,serialized,n);
return(txbytes);
}
return(0);
@ -562,68 +671,131 @@ cJSON *bitcoin_txjson(struct iguana_info *coin,struct iguana_msgtx *msgtx)
return(json);
}
int32_t bitcoin_verifyvins(struct iguana_info *coin,int32_t *scriptlens,struct iguana_msgtx *msgtx,uint8_t *serialized,int32_t maxsize,char *pubkeystr)
int32_t bitcoin_outputscript(struct iguana_info *coin,char *pubkeys[],int32_t *scriptlenp,uint8_t *scriptspace,bits256 txid,int32_t vout)
{
struct iguana_txid T,*tx; int32_t height,numpubs = 1; char asmstr[8192]; struct iguana_msgvout v;
if ( 0 )
{
*scriptlenp = 0;
if ( (tx= iguana_txidfind(coin,&height,&T,txid)) != 0 )
{
*scriptlenp = iguana_voutset(coin,scriptspace,asmstr,height,&v,tx,vout);
return(numpubs);
}
}
//char *str = "2103506a52e95cdfbb9d17d702af6259ba7de8b7a604007999e0266edbf6e4bb6974ac";
char *str = "76a914010966776006953d5567439e5e39f86a0d273bee88ac";
*scriptlenp = (int32_t)strlen(str) >> 1;
decode_hex(scriptspace,*scriptlenp,str);
//pubkeys[0] = clonestr("03506a52e95cdfbb9d17d702af6259ba7de8b7a604007999e0266edbf6e4bb6974");
pubkeys[0] = clonestr("0450863ad64a87ae8a2fe83c1af1a8403cb53f53e486d8511dad8a04887e5b23522cd470243453a299fa9e77237716103abc11a1df38855ed6f2ee187e9c582ba6");
return(numpubs);
}
int32_t bitcoin_hashtype(uint8_t *script,int32_t scriptlen,uint8_t *pk_script,int32_t pk_scriptlen)
{
char txidstr[128],sigstr[256],coinaddr[64],vpnstr[64]; uint8_t *sig,pubkey[33];
EC_KEY *key; int32_t n2,i,scriptlen,vini=0,siglen,numvins,hashtype; bits256 txid,sigtxid;
return(SIGHASH_ALL);
}
struct vin_signer { bits256 privkey; uint8_t siglen,sig[80],pubkey[65]; };
struct vin_info
{
struct iguana_msgvin vin;
int32_t M,N,validmask,voutlen;
struct vin_signer signers[16];
uint8_t voutscript[];
};
int32_t bitcoin_verifyvins(struct iguana_info *coin,int32_t *scriptlens,struct iguana_msgtx *msgtx,uint8_t *serialized,int32_t maxsize,bits256 myprivkey)
{
char txidstr[128],bigstr[2560],coinaddr[64],vpnstr[64],str[65],*pubkeys[16];
uint8_t *sig,mypubkey[128],pubkey[128],sigspace[8192],*saveinput,scriptspace[8192];
bits256 txid,sigtxid,revsigtxid,mypub;
int32_t n2,i,j,numpubs,plen,scriptlen,vini=0,siglen,numvins,hashtype,myvin = 1;
vpnstr[0] = 0;
memset(pubkeys,0,sizeof(pubkeys));
numvins = msgtx->tx_in;
decode_hex(pubkey,sizeof(pubkey),pubkeystr);
mypub = bitcoin_pubkey(mypubkey,myprivkey);
for (vini=0; vini<numvins; vini++)
{
for (i=0; i<numvins; i++)
msgtx->vins[i].scriptlen = 0;
i = vini;
scriptlen = msgtx->vins[i].scriptlen = scriptlens[vini];
printf("VINI.%d (%s)\n",vini,jprint(bitcoin_txjson(coin,msgtx),1));
sig = &msgtx->vins[i].script[1];
siglen = msgtx->vins[i].script[0];
hashtype = sig[siglen-1];
bitcoin_address(coinaddr,coin->chain->pubtype,pubkey);
if ( (key= bitcoin_key()) != 0 )
saveinput = msgtx->vins[vini].script;
sig = &msgtx->vins[vini].script[1];
siglen = msgtx->vins[vini].script[0];
numpubs = bitcoin_outputscript(coin,pubkeys,&scriptlen,scriptspace,msgtx->vins[vini].prev_hash,msgtx->vins[vini].prev_vout);
msgtx->vins[vini].scriptlen = scriptlen;
msgtx->vins[vini].script = scriptspace;
for (j=0; j<numpubs; j++)
{
if ( bitcoin_pubkeyset(&key,pubkey,33) < 0 )
plen = (int32_t)strlen(pubkeys[j]);
plen >>= 1;
decode_hex(pubkey,plen,pubkeys[j]);
bitcoin_address(coinaddr,coin->chain->pubtype,pubkey,plen);
n2 = iguana_rwmsgtx(coin,1,0,serialized,maxsize,msgtx,&txid,vpnstr);
hashtype = bitcoin_hashtype(saveinput,scriptlens[vini],scriptspace,scriptlen);
msgtx->vins[vini].script = saveinput;
if ( n2 > 0 )
{
printf("cant set pubkey.(%s) %s\n",pubkeystr,coinaddr);
bitcoin_keyfree(key);
return(-1);
}
printf("vini.%d: scriptlen.%d siglen.%d hashtype.%d coinaddr.%s\n",vini,scriptlen,siglen,hashtype,coinaddr);
}
else
{
printf("cant get bitcoin_key\n");
bitcoin_keyfree(key);
return(-1);
n2 += iguana_rwnum(1,&serialized[n2],sizeof(hashtype),&hashtype);
revsigtxid = bits256_doublesha256(txidstr,serialized,n2);
for (i=0; i<sizeof(revsigtxid); i++)
sigtxid.bytes[31-i] = revsigtxid.bytes[i];
if ( 1 && myvin != 0 )
{
sig = sigspace;
siglen = bitcoin_sign(sig,sizeof(sigspace),sigtxid.bytes,sizeof(sigtxid),myprivkey);
printf("plen.%d siglen.%d %s\n",plen,siglen,bits256_str(str,myprivkey));
msgtx->vins[vini].scriptlen = siglen + plen + 2;
msgtx->vins[vini].script[0] = siglen;
memcpy(msgtx->vins[vini].script+1,sigspace,siglen);
msgtx->vins[vini].script[siglen + 1] = plen;
memcpy(msgtx->vins[vini].script+1+siglen+1,pubkey,plen);
cJSON *j = cJSON_CreateObject();
char *txstr = iguana_rawtxbytes(coin,malloc(10000),10000,j,msgtx);
printf("SIGNEDTX.(%s) %s\n",txstr,jprint(j,0));
siglen++;
//printf("retjson.(%s) %p\n",jprint(retjson,0),retjson);
}
if ( bitcoin_verify(sig,siglen-1,sigtxid.bytes,sizeof(sigtxid),0,pubkey,plen) < 0 )
{
init_hexbytes_noT(bigstr,serialized,n2);
printf("(%s) doesnt verify hash2.%s\n",bigstr,bits256_str(str,sigtxid));
return(-1);
} else printf("SIG.%d VERIFIED\n",vini);
} else return(-1);
}
if ( (n2= iguana_rwmsgtx(coin,1,0,serialized,maxsize,msgtx,&txid,vpnstr)) > 0 )
{
n2 += iguana_rwnum(1,&serialized[n2],sizeof(hashtype),&hashtype);
sigtxid = bits256_doublesha256(txidstr,serialized,n2);
if ( bitcoin_verify(key,sigtxid.bytes,sizeof(sigtxid),sig,siglen-1) < 0 )
{
init_hexbytes_noT(sigstr,sig,siglen);
printf("othersig.(%s) doesnt verify\n",sigstr);
bitcoin_keyfree(key);
return(-1);
} else printf("SIG.%d VERIFIED\n",vini);
// 483045022100f86ab6815d1c22bf9f0fb6c389b558eb644159462054039d393cdba6e480a952022079b7f804c48a0ef5de68bc4be4c18cd5ea947763f4d5f6d415092f8dc00ee1aa01
} else return(-1);
bitcoin_keyfree(key);
}
return(0);
}
//printf("privkey.%s\n",bits256_str(str,privkey));
//EC_KEY *KEY = bitcoin_privkeyset(&pkey,privkey);
char *refstr = "01000000\
01\
eccf7e3034189b851985d871f91384b8ee357cd47c3024736e5676eb2debb3f2\
01000000\
8c\
4930460221009e0339f72c793a89e664a8a932df073962a3f84eda0bd9e02084a6a9567f75aa022100bd9cbaca2e5ec195751efdfac164b76250b1e21302e51ca86dd7ebd7020cdc0601410450863ad64a87ae8a2fe83c1af1a8403cb53f53e486d8511dad8a04887e5b23522cd470243453a299fa9e77237716103abc11a1df38855ed6f2ee187e9c582ba6\
ffffffff\
01\
605af40500000000\
19\
76a914097072524438d003d23a2f23edb65aae1bb3e46988ac\
00000000";
int32_t bitcoin_verifytx(struct iguana_info *coin,char *rawtxstr)
{
int32_t i,len,maxsize,*scriptlens,numvins,retval = -1; uint8_t *serialized,*serialized2;
struct iguana_msgtx msgtx; bits256 txid; char vpnstr[64];
struct iguana_msgtx msgtx; bits256 txid,myprivkey; char vpnstr[64];
len = (int32_t)strlen(rawtxstr);
maxsize = len + 32768;
serialized = calloc(1,maxsize);
serialized2 = calloc(1,maxsize);
len >>= 1;
vpnstr[0] = 0;
decode_hex(myprivkey.bytes,sizeof(myprivkey),"18E14A7B6A307F426A94F8114701E7C8E774E7F9A47E2C2035DB29A206321725");
decode_hex(serialized,len,rawtxstr);
memset(&msgtx,0,sizeof(msgtx));
if ( iguana_rwmsgtx(coin,0,0,serialized,maxsize,&msgtx,&txid,vpnstr) > 0 )
@ -632,7 +804,7 @@ int32_t bitcoin_verifytx(struct iguana_info *coin,char *rawtxstr)
scriptlens = calloc(numvins,sizeof(*scriptlens));
for (i=0; i<numvins; i++)
scriptlens[i] = msgtx.vins[i].scriptlen;
if ( bitcoin_verifyvins(coin,scriptlens,&msgtx,serialized2,maxsize,"03506a52e95cdfbb9d17d702af6259ba7de8b7a604007999e0266edbf6e4bb6974") == 0 )
if ( bitcoin_verifyvins(coin,scriptlens,&msgtx,serialized2,maxsize,myprivkey) == 0 )
retval = 0;
free(scriptlens);
}
@ -642,14 +814,16 @@ int32_t bitcoin_verifytx(struct iguana_info *coin,char *rawtxstr)
cJSON *bitcoin_txtest(struct iguana_info *coin,char *rawtxstr,bits256 txid)
{
struct iguana_msgtx msgtx; char str[65],str2[65]; bits256 checktxid,blockhash;
struct iguana_msgtx msgtx; char str[65],str2[65]; bits256 checktxid,blockhash,myprivkey;
cJSON *retjson,*txjson; uint8_t *serialized,*serialized2; struct iguana_txid T,*tp;
char vpnstr[64]; int32_t n,i,*scriptlens,height,n2,maxsize,len = (int32_t)strlen(rawtxstr);
rawtxstr = refstr;
maxsize = len + 32768;
serialized = calloc(1,maxsize);
serialized2 = calloc(1,maxsize);
len >>= 1;
vpnstr[0] = 0;
decode_hex(myprivkey.bytes,sizeof(myprivkey),"18E14A7B6A307F426A94F8114701E7C8E774E7F9A47E2C2035DB29A206321725");
memset(&msgtx,0,sizeof(msgtx));
if ( len < maxsize )
{
@ -665,7 +839,7 @@ cJSON *bitcoin_txtest(struct iguana_info *coin,char *rawtxstr,bits256 txid)
scriptlens = calloc(msgtx.tx_in,sizeof(*scriptlens));
for (i=0; i<msgtx.tx_in; i++)
scriptlens[i] = msgtx.vins[i].scriptlen;
if ( bitcoin_verifyvins(coin,scriptlens,&msgtx,serialized2,maxsize,"03506a52e95cdfbb9d17d702af6259ba7de8b7a604007999e0266edbf6e4bb6974") < 0 )
if ( bitcoin_verifyvins(coin,scriptlens,&msgtx,serialized2,maxsize,myprivkey) < 0 )
printf("sig verification error\n");
else printf("sigs verified\n");
for (i=0; i<msgtx.tx_in; i++)

5
iguana/iguana777.h

@ -717,7 +717,7 @@ bits256 iguana_chaingenesis(int32_t version,uint32_t timestamp,uint32_t nBits,ui
int32_t iguana_send_ConnectTo(struct iguana_info *coin,struct iguana_peer *addr);
cJSON *iguana_txjson(struct iguana_info *coin,struct iguana_txid *tx,int32_t height);
char *iguana_txscan(struct iguana_info *coin,cJSON *json,uint8_t *data,int32_t recvlen,bits256 txid);
char *iguana_rawtxbytes(struct iguana_info *coin,cJSON *json,uint8_t *data,int32_t datalen);
char *iguana_rawtxbytes(struct iguana_info *coin,uint8_t *serialized,int32_t datalen,cJSON *json,struct iguana_msgtx *msgtx);
int32_t iguana_send_VPNversion(struct iguana_info *coin,struct iguana_peer *addr,uint64_t myservices);
void exchanges777_init(struct supernet_info *myinfo,cJSON *exchanges,int32_t sleepflag);
int32_t iguana_rwvout(int32_t rwflag,struct OS_memspace *mem,uint8_t *serialized,struct iguana_msgvout *msg);
@ -727,7 +727,8 @@ int32_t iguana_ramtxbytes(struct iguana_info *coin,uint8_t *serialized,int32_t m
cJSON *bitcoin_txtest(struct iguana_info *coin,char *rawtxstr,bits256 txid);
cJSON *iguana_blockjson(struct iguana_info *coin,struct iguana_block *block,int32_t txidsflag);
int32_t iguana_sig(uint8_t *sig,int32_t maxsize,uint8_t *data,int32_t datalen,bits256 privkey);
int32_t iguana_ver(uint8_t *sig,int32_t maxsize,uint8_t *data,int32_t datalen,bits256 pubkey);
int32_t iguana_ver(uint8_t *sig,int32_t siglen,uint8_t *data,int32_t datalen,bits256 pubkey);
//int32_t iguana_ver(uint8_t *sig,int32_t siglen,uint8_t *data,int32_t datalen,uint8_t *pubkey);
extern queue_t bundlesQ;

43
iguana/iguana_json.c

@ -319,16 +319,47 @@ int32_t pretty_form(FILE *fp,char *formheader,char *formfooter,char *fieldtempla
return(size);
}
void update_docjson(cJSON *docjson,char *agent,char *method)
{
cJSON *item = 0; long allocsize; char *docstr,fname[512],stubstr[4096]; FILE *fp;
if ( agent != 0 && method != 0 )
{
sprintf(stubstr,"{\"agent\":\"%s\",\"method\":\"%s\",\"help\":\"put helpful info here\",\"teststatus\":[{\"tester\":\"bob\",\"result\":\"put result here\",\"notes\":\"put useful notes here\",\"automated\":\"notyet\",\"sourcefile\":\"%s_%s_test.py\"}]}",agent,method,agent,method);
sprintf(fname,"help/%s_%s.json",agent,method);
if ( (docstr= OS_filestr(&allocsize,fname)) != 0 )
{
if ( (item= cJSON_Parse(docstr)) == 0 )
printf("WARNING: cant parse %s\n",fname);
free(docstr);
}
else if ( (fp= fopen(fname,"w")) != 0 )
{
if ( (item= cJSON_Parse(stubstr)) == 0 )
printf("WARNING: cant parse stubstr %s\n",stubstr);
else
{
fprintf(fp,"%s\n",stubstr);
fclose(fp);
}
}
if ( item == 0 )
item = cJSON_Parse(stubstr);
if ( item != 0 )
jaddi(docjson,item);
}
}
int32_t pretty_forms(char *fname,char *agentstr)
{
char *str,*header,*footer,*formheader,*formfooter,*field; long allocsize; FILE *fp;
int32_t i,n,len,err=0,size = 0; cJSON *helpjson,*array,*item;
char *str,*header,*footer,*formheader,*formfooter,*field,*docstr; long allocsize; FILE *fp,*docfp;
int32_t i,n,len,err=0,size = 0; cJSON *helpjson,*array,*item,*docjson;
header = OS_filestr(&allocsize,"header.html"); if ( allocsize > MAX_TEMPLATESIZE ) err++;
footer = OS_filestr(&allocsize,"footer.html"); if ( allocsize > MAX_TEMPLATESIZE ) err++;
formheader = OS_filestr(&allocsize,"formheader.html"); if ( allocsize > MAX_TEMPLATESIZE ) err++;
formfooter = OS_filestr(&allocsize,"formfooter.html"); if ( allocsize > MAX_TEMPLATESIZE ) err++;
field = OS_filestr(&allocsize,"field.html"); if ( allocsize > MAX_TEMPLATESIZE ) err++;
fp = fopen(fname,"w");
docjson = cJSON_CreateArray();
if ( fp != 0 && err == 0 && header != 0 && footer != 0 && formheader != 0 && formfooter != 0 && field != 0 )
{
//HTML_EMIT(header,strlen(header));
@ -342,6 +373,7 @@ int32_t pretty_forms(char *fname,char *agentstr)
{
item = jitem(array,i);
str = jstr(item,"agent");
update_docjson(docjson,str,jstr(item,"method"));
if ( agentstr == 0 || agentstr[0] == 0 || (str != 0 && strcmp(str,agentstr) == 0) )
{
len = pretty_form(fp,formheader,formfooter,field,str!=0?str:"agent",item);
@ -356,6 +388,13 @@ int32_t pretty_forms(char *fname,char *agentstr)
fclose(fp);
//HTML_EMIT(footer,strlen(footer));
}
if ( docjson != 0 && (docfp= fopen("help.json","w")) != 0 )
{
docstr = jprint(docjson,1);
fprintf(docfp,"%s\n",docstr);
fclose(docfp);
free(docstr);
}
if ( header != 0 ) free(header);
if ( footer != 0 ) free(footer);
if ( formheader != 0 ) free(formheader);

40
iguana/iguana_pubkeys.c

@ -429,6 +429,7 @@ bool bp_privkey_set(struct bp_key *key, const void *privkey_, size_t pk_len)
const unsigned char *privkey = privkey_;
if (!d2i_ECPrivateKey(&key->k, &privkey, pk_len))
return false;
if (!EC_KEY_check_key(key->k))
return false;
@ -806,13 +807,23 @@ struct iguana_waddress *iguana_waddresscalc(uint8_t pubtype,uint8_t wiftype,stru
return(0);
}
int32_t iguana_ver(uint8_t *sig,int32_t siglen,uint8_t *data,int32_t datalen,bits256 pubkey)
int32_t iguana_ver(uint8_t *sig,int32_t siglen,uint8_t *data,int32_t datalen,bits256 pub)
{
struct bp_key key;
if ( bp_key_init(&key) != 0 && bp_pubkey_set(&key,pubkey.bytes,sizeof(pubkey)) != 0 )
struct bp_key key; uint8_t pubkey[33];
memcpy(pubkey+1,pub.bytes,sizeof(pub));
if ( bp_key_init(&key) != 0 )
{
if ( bp_verify(key.k,data,datalen,sig,siglen) != 0 )
return(0);
for (pubkey[0]=2; pubkey[0]<=3; pubkey[0]++)
{
if ( bp_pubkey_set(&key,pubkey,33) != 0 )
{
if ( bp_verify(key.k,data,datalen,sig,siglen) != 0 )
{
printf("verified.[%d]\n",pubkey[0]);
return(0);
}
}
}
}
return(-1);
}
@ -827,8 +838,9 @@ int32_t iguana_sig(uint8_t *sig,int32_t maxsize,uint8_t *data,int32_t datalen,bi
if ( siglen < maxsize && sigptr != 0 )
{
memcpy(sig,sigptr,siglen);
free(sigptr);
return((int32_t)siglen);
} else free(sigptr);
}
}
}
return(-1);
@ -1204,19 +1216,3 @@ cJSON *iguana_pubkeyjson(struct iguana_info *coin,char *pubkeystr)
cJSON *json = cJSON_CreateObject();
return(json);
}
void pktest()
{
bits256 p; uint8_t privkey,*pubkey,sig[128]; struct bp_key key; size_t pk_len,pubk_len; int32_t siglen;
bp_key_init(&key);
bp_key_generate(&key);
OS_randombytes(p.bytes,sizeof(privkey));
bp_privkey_set(&key,p.bytes,sizeof(privkey));
//bp_privkey_get(&key,(void **)&privkey,&pk_len);
bp_pubkey_get(&key,(void **)&pubkey,&pubk_len);
printf("pk_len.%ld\n",pubk_len);
siglen = iguana_sig(sig,sizeof(sig),(uint8_t *)"hello",(int32_t)strlen("hello"),p);
printf("siglen.%d\n",siglen);
//iguana_ver(uint8_t *sig,int32_t siglen,uint8_t *data,int32_t datalen,bits256 pubkey)
}

3
iguana/iguana_tx.c

@ -46,7 +46,7 @@ int32_t iguana_voutset(struct iguana_info *coin,uint8_t *scriptspace,char *asmst
struct iguana_unspent *u,*U; uint32_t unspentind,scriptlen = 0; struct iguana_bundle *bp; char coinaddr[65];
struct iguana_ramchaindata *rdata; struct iguana_pkhash *P,*p;
memset(vout,0,sizeof(*vout));
if ( height >= 0 && height < coin->chain->bundlesize*coin->bundlescount && (bp= coin->bundles[height / coin->chain->bundlesize]) != 0 && (rdata= bp->ramchain.H.data) != 0 )
if ( height >= 0 && height < coin->chain->bundlesize*coin->bundlescount && (bp= coin->bundles[height / coin->chain->bundlesize]) != 0 && (rdata= bp->ramchain.H.data) != 0 && i < tx->numvouts )
{
U = (void *)(long)((long)rdata + rdata->Uoffset);
P = (void *)(long)((long)rdata + rdata->Poffset);
@ -56,6 +56,7 @@ int32_t iguana_voutset(struct iguana_info *coin,uint8_t *scriptspace,char *asmst
printf("iguana_voutset: txidind mismatch %d vs %d || %d vs %d || (%d vs %d)\n",u->txidind,u->txidind,u->vout,i,u->hdrsi,height / coin->chain->bundlesize);
p = &P[u->pkind];
vout->value = u->value;
vout->pk_script = scriptspace;
scriptlen = iguana_scriptgen(coin,coinaddr,scriptspace,asmstr,p->rmd160,u->type,i);
}
vout->pk_scriptlen = scriptlen;

9
iguana/main.c

@ -310,8 +310,6 @@ void iguana_main(void *arg)
if ( ismainnet != 0 )
strcat(myinfo->NXTAPIURL,"7876/nxt");
else strcat(myinfo->NXTAPIURL,"6876/nxt");
void pktest();
pktest();
signal(SIGINT,sigint_func);
signal(SIGILL,sigillegal_func);
signal(SIGHUP,sighangup_func);
@ -326,6 +324,7 @@ void iguana_main(void *arg)
iguana_chaingenesis(1,1317972665,0x1e0ffff0,2084524493,bits256_conv("97ddfbbae6be97fd6cdf3e7ca13232a3afff2353e29badfab7f73011edd4ced9")); // LTC
iguana_initQ(&helperQ,"helperQ");
OS_ensure_directory("help");
OS_ensure_directory("confs");
OS_ensure_directory("DB"), OS_ensure_directory("DB/ECB");
OS_ensure_directory("tmp");
@ -347,15 +346,15 @@ void iguana_main(void *arg)
category_init(&MYINFO);
if ( (coinargs= SuperNET_keysinit(&MYINFO,arg)) != 0 )
iguana_launch(iguana_coinadd("BTCD"),"iguana_coins",iguana_coins,coinargs,IGUANA_PERMTHREAD);
else if ( 1 )
else if ( 0 )
{
#ifdef __APPLE__
sleep(1);
char *str;
strcpy(MYINFO.rpcsymbol,"BTCD");
strcpy(MYINFO.rpcsymbol,"BTC");
iguana_launchcoin(MYINFO.rpcsymbol,cJSON_Parse("{}"));
if ( 0 && (str= SuperNET_JSON(&MYINFO,cJSON_Parse("{\"wallet\":\"password\",\"agent\":\"iguana\",\"method\":\"addcoin\",\"services\":128,\"maxpeers\":3,\"newcoin\":\"BTCD\",\"active\":0}"),0)) != 0 )
if ( 0 && (str= SuperNET_JSON(&MYINFO,cJSON_Parse("{\"wallet\":\"password\",\"agent\":\"iguana\",\"method\":\"addcoin\",\"services\":128,\"maxpeers\":3,\"newcoin\":\"BTC\",\"active\":0}"),0)) != 0 )
{
printf("got.(%s)\n",str);
free(str);

6
iguana/ramchain_api.c

@ -186,12 +186,12 @@ HASH_AND_INT(ramchain,getrawtransaction,txid,verbose)
STRING_ARG(ramchain,decoderawtransaction,rawtx)
{
char *str; uint8_t *data; int32_t datalen; cJSON *retjson = cJSON_CreateObject();
uint8_t *data; int32_t datalen; cJSON *retjson = cJSON_CreateObject(); // struct iguana_msgtx msgtx;
datalen = (int32_t)strlen(rawtx) >> 1;
data = malloc(datalen);
decode_hex(data,datalen,rawtx);
if ( (str= iguana_rawtxbytes(coin,retjson,data,datalen)) != 0 )
free(str);
//if ( (str= iguana_rawtxbytes(coin,data,datalen,retjson,&msgtx)) != 0 )
// free(str);
free(data);
return(jprint(retjson,1));
}

Loading…
Cancel
Save