Skip to content
Merged
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ installed.
For non-development use, you can install wally with `pip` as follows:

```
pip install wallycore==0.9.1
pip install wallycore==0.9.2
```

For python development, you can build and install wally using:
Expand All @@ -132,7 +132,7 @@ You can also install the binary [wally releases](https://github.com/ElementsProj
using the released wheel files without having to compile the library, e.g.:

```
pip install wallycore-0.9.1-cp39-cp39m-linux_x86_64.whl
pip install wallycore-0.9.2-cp39-cp39m-linux_x86_64.whl
```

The script `tools/build_python_manylinux_wheels.sh` builds the Linux release files
Expand Down
2 changes: 1 addition & 1 deletion _CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.20)

project(
libwallycore
VERSION 0.9.1
VERSION 0.9.2
DESCRIPTION "A collection of useful primitives for cryptocurrency wallets"
LANGUAGES C
)
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
AC_PREREQ([2.60])
AC_INIT([libwallycore],[0.9.1])
AC_INIT([libwallycore],[0.9.2])
AC_CONFIG_AUX_DIR([tools/build-aux])
AC_CONFIG_MACRO_DIR([tools/build-aux/m4])
AC_CONFIG_SRCDIR([src/mnemonic.h])
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def extract_docs(infile, outfile):
# built documents.
#
# The short X.Y version.
version = u'0.9.1'
version = u'0.9.2'
# The full version, including alpha/beta/rc tags.
release = version

Expand Down
6 changes: 6 additions & 0 deletions include/wally.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1408,6 +1408,12 @@ inline int psbt_is_finalized(const PSBT& psbt, size_t* written) {
return ret;
}

template <class PSBT>
inline int psbt_is_input_finalized(const PSBT& psbt, size_t index, size_t* written) {
int ret = ::wally_psbt_is_input_finalized(detail::get_p(psbt), index, written);
return ret;
}

inline int psbt_output_clear_amount(struct wally_psbt_output* output) {
int ret = ::wally_psbt_output_clear_amount(output);
return ret;
Expand Down
12 changes: 12 additions & 0 deletions include/wally_psbt.h
Original file line number Diff line number Diff line change
Expand Up @@ -1958,6 +1958,18 @@ WALLY_CORE_API int wally_psbt_is_finalized(
const struct wally_psbt *psbt,
size_t *written);

/**
* Determine if a given PSBT input is finalized.
*
* :param psbt: The PSBT to check.
* :param index: The zero-based index of the input to check.
* :param written: On success, set to one if the input is finalized, otherwise zero.
*/
WALLY_CORE_API int wally_psbt_is_input_finalized(
const struct wally_psbt *psbt,
size_t index,
size_t *written);

/**
* Set the global transaction for a PSBT.
*
Expand Down
8 changes: 2 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def call(cmd):

kwargs = {
'name': 'wallycore',
'version': '0.9.1',
'version': '0.9.2',
'description': 'libwally Bitcoin library',
'long_description': 'Python bindings for the libwally Bitcoin library',
'url': 'https://github.com/ElementsProject/libwally-core',
Expand All @@ -109,11 +109,7 @@ def call(cmd):

'License :: OSI Approved :: MIT License',

'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3',
],
'keywords': 'Bitcoin wallet BIP32 BIP38 BIP39 secp256k1',
'project_urls': {
Expand Down
1 change: 1 addition & 0 deletions src/bip85.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "ccan/ccan/crypto/sha512/sha512.h"
#include <include/wally_bip32.h>
#include <include/wally_bip39.h>
#include <include/wally_bip85.h>
#include <include/wally_crypto.h>

/* Bip85 path element values */
Expand Down
5 changes: 5 additions & 0 deletions src/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,9 @@ const struct wally_map_item *map_find_equal_integer(const struct wally_map *lhs,
/* Clamp initial witness stack allocation sizing */
#define MAX_WITNESS_ITEMS_ALLOC 100u /* Non-Taproot standardness limit */

/* Absolute maximum number of inputs and outputs for BTC.
* Liquid numbers are smaller; we use the upper limit */
#define TX_MAX_INPUTS (TX_MAX_INPUTS_ALLOC * 10)
#define TX_MAX_OUTPUTS (TX_MAX_OUTPUTS_ALLOC * 10)

#endif /* LIBWALLY_INTERNAL_H */
61 changes: 42 additions & 19 deletions src/psbt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1077,16 +1077,19 @@ static int psbt_output_free(struct wally_psbt_output *output, bool free_parent)
return WALLY_OK;
}

static int wally_psbt_init(uint32_t version, size_t num_inputs, size_t num_outputs,
size_t num_unknowns, uint32_t flags,
struct wally_psbt *psbt_out)
static int psbt_init(uint32_t version, size_t num_inputs, size_t num_outputs,
size_t num_unknowns, uint32_t flags,
size_t max_num_inputs, size_t max_num_outputs,
struct wally_psbt *psbt_out)
{
int ret;

if (psbt_out)
wally_clear(psbt_out, sizeof(*psbt_out));
if ((version != PSBT_0 && version != PSBT_2) || !psbt_out)
return WALLY_EINVAL; /* Only v0/v2 are specified/supported */
if (num_inputs > TX_MAX_INPUTS || num_outputs > TX_MAX_OUTPUTS)
return WALLY_EINVAL; /* Resulting tx could not fit in a block */
#ifdef BUILD_ELEMENTS
if (flags & ~WALLY_PSBT_INIT_PSET ||
(flags & WALLY_PSBT_INIT_PSET && version != PSBT_2))
Expand All @@ -1097,13 +1100,13 @@ static int wally_psbt_init(uint32_t version, size_t num_inputs, size_t num_outpu
#endif /* BUILD_ELEMENTS */

if (num_inputs) {
if (num_inputs > TX_MAX_INPUTS_ALLOC)
num_inputs = TX_MAX_INPUTS_ALLOC;
if (num_inputs > max_num_inputs)
num_inputs = max_num_inputs;
psbt_out->inputs = wally_calloc(num_inputs * sizeof(struct wally_psbt_input));
}
if (num_outputs) {
if (num_outputs > TX_MAX_OUTPUTS_ALLOC)
num_outputs = TX_MAX_OUTPUTS_ALLOC;
if (num_outputs > max_num_outputs)
num_outputs = max_num_outputs;
psbt_out->outputs = wally_calloc(num_outputs * sizeof(struct wally_psbt_output));
}

Expand Down Expand Up @@ -1142,21 +1145,32 @@ static int wally_psbt_init(uint32_t version, size_t num_inputs, size_t num_outpu
return WALLY_OK;
}

int wally_psbt_init_alloc(uint32_t version, size_t num_inputs, size_t num_outputs,
size_t num_unknowns, uint32_t flags, struct wally_psbt **output)
static int psbt_init_alloc(uint32_t version, size_t num_inputs, size_t num_outputs,
size_t num_unknowns, uint32_t flags,
size_t max_num_inputs, size_t max_num_outputs,
struct wally_psbt **output)
{
int ret;

OUTPUT_CHECK;
OUTPUT_ALLOC(struct wally_psbt);
ret = wally_psbt_init(version, num_inputs, num_outputs, num_unknowns, flags, *output);
ret = psbt_init(version, num_inputs, num_outputs, num_unknowns, flags,
max_num_inputs, max_num_outputs, *output);
if (ret != WALLY_OK) {
wally_free(*output);
*output = NULL;
}
return ret;
}

int wally_psbt_init_alloc(uint32_t version, size_t num_inputs, size_t num_outputs,
size_t num_unknowns, uint32_t flags, struct wally_psbt **output)
{
return psbt_init_alloc(version, num_inputs, num_outputs, num_unknowns,
flags, TX_MAX_INPUTS_ALLOC, TX_MAX_OUTPUTS_ALLOC,
output);
}

int wally_psbt_from_tx(const struct wally_tx *tx, uint32_t version,
uint32_t flags, struct wally_psbt **output)
{
Expand All @@ -1167,8 +1181,8 @@ int wally_psbt_from_tx(const struct wally_tx *tx, uint32_t version,
*output = NULL;
if (!tx || !output || (version == WALLY_PSBT_VERSION_2 && tx->version < 2u))
return WALLY_EINVAL;
ret = wally_psbt_init_alloc(version, tx->num_inputs, tx->num_outputs, 0,
flags, output);
ret = psbt_init_alloc(version, tx->num_inputs, tx->num_outputs, 0, flags,
tx->num_inputs, tx->num_outputs, output);
if (ret == WALLY_OK && version == WALLY_PSBT_VERSION_0)
ret = wally_psbt_set_global_tx(*output, tx);
else {
Expand Down Expand Up @@ -1399,6 +1413,12 @@ int wally_psbt_is_finalized(const struct wally_psbt *psbt,
return WALLY_OK;
}

int wally_psbt_is_input_finalized(const struct wally_psbt *psbt,
size_t index, size_t *written)
{
return wally_psbt_input_is_finalized(psbt_get_input(psbt, index), written);
}

static int psbt_set_global_tx(struct wally_psbt *psbt, struct wally_tx *tx, bool do_clone)
{
struct wally_tx *new_tx = NULL;
Expand Down Expand Up @@ -2588,7 +2608,8 @@ int wally_psbt_from_bytes(const unsigned char *bytes, size_t len,
ret = WALLY_EINVAL; /* Tx version must be >= 2 */
else {
struct wally_psbt tmp;
ret = wally_psbt_init((*output)->version, input_count, output_count, 0, 0, &tmp);
ret = psbt_init((*output)->version, input_count, output_count,
0, 0, input_count, output_count, &tmp);
if (ret == WALLY_OK) {
/* Steal the allocated input/output arrays */
(*output)->inputs = tmp.inputs;
Expand Down Expand Up @@ -3967,12 +3988,14 @@ int wally_psbt_clone_alloc(const struct wally_psbt *psbt, uint32_t flags,

ret = wally_psbt_is_elements(psbt, &is_pset);
if (ret == WALLY_OK)
ret = wally_psbt_init_alloc(psbt->version,
psbt->inputs_allocation_len,
psbt->outputs_allocation_len,
psbt->unknowns.items_allocation_len,
is_pset ? WALLY_PSBT_INIT_PSET : 0,
output);
ret = psbt_init_alloc(psbt->version,
psbt->inputs_allocation_len,
psbt->outputs_allocation_len,
psbt->unknowns.items_allocation_len,
is_pset ? WALLY_PSBT_INIT_PSET : 0,
psbt->inputs_allocation_len,
psbt->outputs_allocation_len,
output);
if (ret == WALLY_OK) {
(*output)->tx_version = psbt->tx_version;
psbt_claim_allocated_inputs(*output, psbt->num_inputs, psbt->num_outputs);
Expand Down
1 change: 1 addition & 0 deletions src/swig_java/swig.i
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,7 @@ static jobjectArray create_jstringArray(JNIEnv *jenv, char **p, size_t len) {
%rename("psbt_init") wally_psbt_init_alloc;
%returns_size_t(wally_psbt_is_elements);
%returns_size_t(wally_psbt_is_finalized);
%returns_size_t(wally_psbt_is_input_finalized);
%returns_void__(wally_psbt_remove_input);
%returns_void__(wally_psbt_remove_output);
%returns_void__(wally_psbt_set_pset_modifiable_flags);
Expand Down
1 change: 1 addition & 0 deletions src/test/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ class wally_psbt(Structure):
('wally_psbt_input_taproot_keypath_add', c_int, [POINTER(wally_psbt_input), c_void_p, c_size_t, c_void_p, c_size_t, c_void_p, c_size_t, POINTER(c_uint32), c_size_t]),
('wally_psbt_is_elements', c_int, [POINTER(wally_psbt), c_size_t_p]),
('wally_psbt_is_finalized', c_int, [POINTER(wally_psbt), c_size_t_p]),
('wally_psbt_is_input_finalized', c_int, [POINTER(wally_psbt), c_size_t, c_size_t_p]),
('wally_psbt_output_clear_amount', c_int, [POINTER(wally_psbt_output)]),
('wally_psbt_output_clear_asset', c_int, [POINTER(wally_psbt_output)]),
('wally_psbt_output_clear_asset_blinding_surjectionproof', c_int, [POINTER(wally_psbt_output)]),
Expand Down
35 changes: 26 additions & 9 deletions src/transaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -1133,25 +1133,30 @@ int wally_tx_output_free(struct wally_tx_output *output)
return tx_output_free(output, true);
}

int wally_tx_init_alloc(uint32_t version, uint32_t locktime,
size_t inputs_allocation_len,
size_t outputs_allocation_len,
struct wally_tx **output)
static int tx_init_alloc(uint32_t version, uint32_t locktime,
size_t inputs_allocation_len,
size_t outputs_allocation_len,
size_t max_inputs_allocation_len,
size_t max_outputs_allocation_len,
struct wally_tx **output)
{
struct wally_tx_input *new_inputs = NULL;
struct wally_tx_output *new_outputs = NULL;

OUTPUT_CHECK;
if (inputs_allocation_len > TX_MAX_INPUTS ||
outputs_allocation_len > TX_MAX_OUTPUTS)
return WALLY_EINVAL; /* Tx cannot fit in a block: invalid */
OUTPUT_ALLOC(struct wally_tx);

if (inputs_allocation_len) {
if (inputs_allocation_len > TX_MAX_INPUTS_ALLOC)
inputs_allocation_len = TX_MAX_INPUTS_ALLOC;
if (inputs_allocation_len > max_inputs_allocation_len)
inputs_allocation_len = max_inputs_allocation_len;
new_inputs = wally_calloc(inputs_allocation_len * sizeof(struct wally_tx_input));
}
if (outputs_allocation_len) {
if (outputs_allocation_len > TX_MAX_OUTPUTS_ALLOC)
outputs_allocation_len = TX_MAX_OUTPUTS_ALLOC;
if (outputs_allocation_len > max_outputs_allocation_len)
outputs_allocation_len = max_outputs_allocation_len;
new_outputs = wally_calloc(outputs_allocation_len * sizeof(struct wally_tx_output));
}
if ((inputs_allocation_len && !new_inputs) ||
Expand All @@ -1174,6 +1179,16 @@ int wally_tx_init_alloc(uint32_t version, uint32_t locktime,
return WALLY_OK;
}

int wally_tx_init_alloc(uint32_t version, uint32_t locktime,
size_t inputs_allocation_len,
size_t outputs_allocation_len,
struct wally_tx **output)
{
return tx_init_alloc(version, locktime,
inputs_allocation_len, outputs_allocation_len,
TX_MAX_INPUTS_ALLOC, TX_MAX_OUTPUTS_ALLOC, output);
}

static int tx_free(struct wally_tx *tx, bool free_parent)
{
size_t i;
Expand Down Expand Up @@ -2962,7 +2977,9 @@ static int tx_from_bytes(const unsigned char *bytes, size_t bytes_len,
&expect_witnesses) != WALLY_OK)
return WALLY_EINVAL;

ret = wally_tx_init_alloc(0, 0, num_inputs, num_outputs, output);
/* Allow pre-allocating all inputs as we have already analyzed the tx */
ret = tx_init_alloc(0, 0, num_inputs, num_outputs,
num_inputs, num_outputs, output);
if (ret != WALLY_OK)
return ret;

Expand Down
4 changes: 2 additions & 2 deletions src/wasm_package/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/wasm_package/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wallycore",
"version": "0.9.1",
"version": "0.9.2",
"description": "JavaScript bindings for libwally",
"main": "src/index.js",
"type": "module",
Expand Down
1 change: 0 additions & 1 deletion src/wasm_package/src/const.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ export const EC_XONLY_PUBLIC_KEY_LEN = 32;
export const HASH160_LEN = 20;
export const HMAC_SHA256_LEN = 32;
export const HMAC_SHA512_LEN = 64;
export const LIBWALLY_CORE_PSBT_MEMBERS_H = 1;
export const PBKDF2_HMAC_SHA256_LEN = 32;
export const PBKDF2_HMAC_SHA512_LEN = 64;
export const RIPEMD160_LEN = 20;
Expand Down
1 change: 1 addition & 0 deletions src/wasm_package/src/functions.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/wasm_package/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ export function psbt_input_set_witness_utxo_from_tx(input: Ref_wally_psbt_input,
export function psbt_input_taproot_keypath_add(input: Ref_wally_psbt_input, pub_key: Buffer|Uint8Array, tapleaf_hashes: Buffer|Uint8Array, fingerprint: Buffer|Uint8Array, child_path: Uint32Array|number[]): void;
export function psbt_is_elements(psbt: Ref_wally_psbt): number;
export function psbt_is_finalized(psbt: Ref_wally_psbt): number;
export function psbt_is_input_finalized(psbt: Ref_wally_psbt, index: number): number;
export function psbt_output_clear_amount(output: Ref_wally_psbt_output): void;
export function psbt_output_clear_asset(output: Ref_wally_psbt_output): void;
export function psbt_output_clear_asset_blinding_surjectionproof(output: Ref_wally_psbt_output): void;
Expand Down
1 change: 1 addition & 0 deletions tools/update_wasm_package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Extract WALLY_ constants into const.js
(echo '// AUTOGENERATED by update_wasm_package.sh' \
&& egrep -r '#define [^ (]* ' include/*.h \
| grep -v '#define LIBWALLY_CORE_' \
| grep -v '#define OP_' \
| sed -r 's~.*#define ([^ ]*) *~export const \1 = ~; s~( /\*)| *$~;\1~' \
| LC_ALL=C sort \
Expand Down
1 change: 1 addition & 0 deletions tools/wasm_exports.sh
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ EXPORTED_FUNCTIONS="['_malloc','_free','_bip32_key_free' \
,'_wally_psbt_input_taproot_keypath_add' \
,'_wally_psbt_is_elements' \
,'_wally_psbt_is_finalized' \
,'_wally_psbt_is_input_finalized' \
,'_wally_psbt_output_clear_amount' \
,'_wally_psbt_output_find_keypath' \
,'_wally_psbt_output_find_unknown' \
Expand Down