bitcoin/BRWallet.c
// signs any inputs in tx that can be signed using private keys from the wallet
// forkId is 0 for bitcoin, 0x40 for b-cash
// seed is the master private key (wallet seed) corresponding to the master public key given when the wallet was created
// returns true if all inputs were signed, or false if there was an error or not all inputs were able to be signed
signs any inputs in tx that can be signed using private keys from the wallet
forkId is 0 for bitcoin, 0x40 for b-cash
seed is the master private key (wallet seed) corresponding to the master public key given when the wallet was created
returns true if all inputs were signed, or false if there was an error or not all inputs were able to be signed
signs any inputs in tx that can be signed using private keys from the wallet forkId is 0 for bitcoin 0x40 for b - cash seed is the master private key ( wallet seed ) corresponding to the master public key given when the wallet was created returns true if all inputs were signed or false if there was an error or not all inputs were able to be signed
int BRWalletSignTransaction(BRWallet *wallet, BRTransaction *tx, uint8_t forkId, const void *seed, size_t seedLen)
{
    uint32_t j, internalIdx[tx->inCount], externalIdx[tx->inCount];
    size_t i, internalCount = 0, externalCount = 0;
    int r = 0;
    assert(wallet != NULL);
    assert(tx != NULL);
    pthread_mutex_lock(&wallet->lock);
    for (i = 0; tx && i < tx->inCount; i++) {
        const uint8_t *pkh = BRScriptPKH(tx->inputs[i].script, tx->inputs[i].scriptLen);
        for (j = (uint32_t)array_count(wallet->internalChain); pkh && j > 0; j--) {
            if (UInt160Eq(UInt160Get(pkh), wallet->internalChain[j - 1])) internalIdx[internalCount++] = j - 1;
        }
        for (j = (uint32_t)array_count(wallet->externalChain); pkh && j > 0; j--) {
            if (UInt160Eq(UInt160Get(pkh), wallet->externalChain[j - 1])) externalIdx[externalCount++] = j - 1;
        }
    }
    pthread_mutex_unlock(&wallet->lock);
    BRKey keys[internalCount + externalCount];
    if (seed) {
        BRBIP32PrivKeyList(keys, internalCount, seed, seedLen, SEQUENCE_INTERNAL_CHAIN, internalIdx);
        BRBIP32PrivKeyList(&keys[internalCount], externalCount, seed, seedLen, SEQUENCE_EXTERNAL_CHAIN, externalIdx);
        seed = NULL;
        if (tx) r = BRTransactionSign(tx, forkId, keys, internalCount + externalCount);
        for (i = 0; i < internalCount + externalCount; i++) BRKeyClean(&keys[i]);
    }
    else r = -1; 
    return r;
}
int BRWalletSignTransaction ( BRWallet * wallet , BRTransaction * tx , uint8_t forkId , const void * seed , size_t seedLen ) { uint32_t j , internalIdx [ tx -> inCount ] , externalIdx [ tx -> inCount ] ; size_t i , internalCount = 0 , externalCount = 0 ; int r = 0 ; assert ( wallet != NULL ) ; assert ( tx != NULL ) ; pthread_mutex_lock ( & wallet -> lock ) ; for ( i = 0 ; tx && i < tx -> inCount ; i ++ ) { const uint8_t * pkh = BRScriptPKH ( tx -> inputs [ i ] . script , tx -> inputs [ i ] . scriptLen ) ; for ( j = ( uint32_t ) array_count ( wallet -> internalChain ) ; pkh && j > 0 ; j -- ) { if ( UInt160Eq ( UInt160Get ( pkh ) , wallet -> internalChain [ j - 1 ] ) ) internalIdx [ internalCount ++ ] = j - 1 ; } for ( j = ( uint32_t ) array_count ( wallet -> externalChain ) ; pkh && j > 0 ; j -- ) { if ( UInt160Eq ( UInt160Get ( pkh ) , wallet -> externalChain [ j - 1 ] ) ) externalIdx [ externalCount ++ ] = j - 1 ; } } pthread_mutex_unlock ( & wallet -> lock ) ; BRKey keys [ internalCount + externalCount ] ; if ( seed ) { BRBIP32PrivKeyList ( keys , internalCount , seed , seedLen , SEQUENCE_INTERNAL_CHAIN , internalIdx ) ; BRBIP32PrivKeyList ( & keys [ internalCount ] , externalCount , seed , seedLen , SEQUENCE_EXTERNAL_CHAIN , externalIdx ) ; seed = NULL ; if ( tx ) r = BRTransactionSign ( tx , forkId , keys , internalCount + externalCount ) ; for ( i = 0 ; i < internalCount + externalCount ; i ++ ) BRKeyClean ( & keys [ i ] ) ; } else r = -1 ; return r ; }
signs any inputs in tx that can be signed using private keys from the wallet
forkId is 0 for bitcoin, 0x40 for b-cash
seed is the master private key (wallet seed) corresponding to the master public key given when the wallet was created
returns true if all inputs were signed, or false if there was an error or not all inputs were able to be signed
signs any inputs in tx that can be signed using private keys from the wallet forkId is 0 for bitcoin 0x40 for b - cash seed is the master private key ( wallet seed ) corresponding to the master public key given when the wallet was created returns true if all inputs were signed or false if there was an error or not all inputs were able to be signed
// TODO: XXX wipe seed callback // user canceled authentication