Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions src/ABC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,49 @@ tABC_CC ABC_CreateWallet(const char *szUserName,
return cc;
}

tABC_CC ABC_CreateSigsafeWallet(const char *szUserName,
const char *szPassword,
const char *szWalletName,
int currencyNum,
const char *szPubkey0,
const char *szPubkey1,
char **pszUUID,
tABC_Error *pError)
{
ABC_DebugLog("%s called", __FUNCTION__);

tABC_CC cc = ABC_CC_Ok;
ABC_SET_ERR_CODE(pError, ABC_CC_Ok);

AutoSyncKeys pKeys;
AutoU08Buf L1;
AutoU08Buf LP1;

ABC_CHECK_ASSERT(true == gbInitialized, ABC_CC_NotInitialized, "The core library has not been initalized");
ABC_CHECK_NULL(szUserName);
ABC_CHECK_ASSERT(strlen(szUserName) > 0, ABC_CC_Error, "No username provided");
ABC_CHECK_NULL(szWalletName);
ABC_CHECK_ASSERT(strlen(szWalletName) > 0, ABC_CC_Error, "No wallet name provided");

// get account keys:
ABC_CHECK_RET(ABC_LoginShimGetSyncKeys(szUserName, szPassword, &pKeys.get(), pError));
ABC_CHECK_RET(ABC_LoginShimGetServerKeys(szUserName, szPassword, &L1, &LP1, pError));

ABC_CHECK_RET(ABC_WalletCreate(pKeys, L1, LP1, szUserName, szWalletName,
currencyNum, pszUUID, pError));

// TODO:
// * WalletCreate does not know that this is a sig-safe wallet.
// Either parameterize WalletCreate to do the right thing,
// or copy-paste that function and modify it.
// * Add a field to the wallet info file,
// indicating that this is a Sigsafe wallet.
// * Hack the wallet address generator to only return the p2sh address
// if this is a Sigsafe wallet.

exit:
return cc;
}

/**
* Clear cached keys.
Expand Down Expand Up @@ -1748,6 +1791,74 @@ tABC_CC ABC_InitiateSendRequest(const char *szUserName,
return cc;
}

tABC_CC ABC_CreateSigsafeTX(const char *szUserName,
const char *szPassword,
const char *szWalletUUID,
const char *szDestAddress,
tABC_TxDetails *pDetails,
tABC_SigsafeTx **ppTx,
tABC_Error *pError)
{
ABC_DebugLog("%s called", __FUNCTION__);

tABC_CC cc = ABC_CC_Ok;
ABC_SET_ERR_CODE(pError, ABC_CC_Ok);

AutoSyncKeys pKeys;

ABC_CHECK_ASSERT(true == gbInitialized, ABC_CC_NotInitialized, "The core library has not been initalized");
ABC_CHECK_NULL(szUserName);
ABC_CHECK_NULL(szWalletUUID);
ABC_CHECK_NULL(pDetails);
ABC_CHECK_NULL(ppTx);

ABC_CHECK_RET(ABC_LoginShimGetSyncKeys(szUserName, szPassword, &pKeys.get(), pError));
// TODO: Actually generate this stuff!

exit:
return cc;
}

/**
* Signs and sends a SigSafe transaction.
* @param pDetails GUI-supplied transaction metadata.
* @param pTx a signed transaction returned from the device.
*/
tABC_CC ABC_CompleteSigsafeTX(const char *szUserName,
const char *szPassword,
const char *szWalletUUID,
tABC_TxDetails *pDetails,
tABC_SigsafeTx *pTx,
tABC_Error *pError)
{
ABC_DebugLog("%s called", __FUNCTION__);

tABC_CC cc = ABC_CC_Ok;
ABC_SET_ERR_CODE(pError, ABC_CC_Ok);

AutoSyncKeys pKeys;

ABC_CHECK_ASSERT(true == gbInitialized, ABC_CC_NotInitialized, "The core library has not been initalized");
ABC_CHECK_NULL(szUserName);
ABC_CHECK_NULL(szWalletUUID);
ABC_CHECK_NULL(pDetails);
ABC_CHECK_NULL(pTx);

ABC_CHECK_RET(ABC_LoginShimGetSyncKeys(szUserName, szPassword, &pKeys.get(), pError));
// TODO: Actually generate this stuff!

exit:
return cc;
}

void ABC_FreeSigsafeTx(tABC_SigsafeTx *pTx)
{
ABC_DebugLog("%s called", __FUNCTION__);

// TODO: fill this out once we understand what the fields are
// free(pTx->unsignedTX);
}

/**
* Initiates a transfer request.
*
Expand Down
62 changes: 62 additions & 0 deletions src/ABC.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,14 @@ typedef struct sABC_WalletInfo
unsigned archived;
/** wallet balance */
int64_t balanceSatoshi;

/** True if this is a Sigsafe multisig demo wallet. */
unsigned sigsafe;
// TODO:
// * Save this field to disk.
// * Have the UI check this field when sending money out,
// going down the NFC-tap route if it's set.

} tABC_WalletInfo;

/**
Expand Down Expand Up @@ -346,6 +354,15 @@ typedef struct sABC_TxDetails
unsigned int attributes;
} tABC_TxDetails;

typedef struct sABC_SigsafeTx
{
// TODO: Actually define what goes in here.
char *unsignedTX;
char *redeemScript;
int *n_inputs;
int *indices;
} tABC_SigsafeTx;

typedef struct sABC_TransferDetails
{
char *szSrcWalletUUID;
Expand Down Expand Up @@ -855,6 +872,21 @@ tABC_CC ABC_CreateWallet(const char *szUserName,
char **pszUuid,
tABC_Error *pError);

/**
* Creates a multi-sig wallet for the SigSafe demo.
* @param szPubkey0 The public key from the first NFC device.
* @param szPubkey1 The public key from the second NFC device.
* @param pszUUID The resulting wallet UUID. The caller frees this.
*/
tABC_CC ABC_CreateSigsafeWallet(const char *szUserName,
const char *szPassword,
const char *szWalletName,
int currencyNum,
const char *szPubkey0,
const char *szPubkey1,
char **pszUUID,
tABC_Error *pError);

tABC_CC ABC_GetWalletUUIDs(const char *szUserName,
const char *szPassword,
char ***paWalletUUID,
Expand Down Expand Up @@ -961,6 +993,36 @@ tABC_CC ABC_InitiateSendRequest(const char *szUserName,
char **szTxId,
tABC_Error *pError);

/**
* Creates an unsigned Sigsafe transaction.
* This does not write anything to the wallet database;
* the GUI is responsible for holding the transaction
* until the device signs it.
* @param pDetails GUI-supplied transaction metadata.
* @param ppTx the resulting unsigned transaction. The caller frees this.
*/
tABC_CC ABC_CreateSigsafeTX(const char *szUserName,
const char *szPassword,
const char *szWalletUUID,
const char *szDestAddress,
tABC_TxDetails *pDetails,
tABC_SigsafeTx **ppTx,
tABC_Error *pError);

/**
* Signs and sends a SigSafe transaction.
* @param pDetails GUI-supplied transaction metadata.
* @param pTx a signed transaction returned from the device.
*/
tABC_CC ABC_CompleteSigsafeTX(const char *szUserName,
const char *szPassword,
const char *szWalletUUID,
tABC_TxDetails *pDetails,
tABC_SigsafeTx *pTx,
tABC_Error *pError);

void ABC_FreeSigsafeTx(tABC_SigsafeTx *pTx);

tABC_CC ABC_InitiateTransfer(const char *szUserName,
const char *szPassword,
tABC_TransferDetails *pTransfer,
Expand Down