tx: add tx_input_is_pegin/tx_is_input_pegin to determine pegin inputs
What changed, and why it matters
This commit is a routine API cleanup: it adds two new functions with clearer names for checking whether a transaction input is a 'pegin' (a special type of cross-chain input used in Elements-based blockchains), and marks the old function name as deprecated. The old function still works by calling the new one. There is no bug fix or security change visible in the code.
No security action required. This is a benign API renaming/deprecation. Consumers may optionally migrate from wally_tx_elements_input_is_pegin to wally_tx_input_is_pegin/wally_tx_is_input_pegin at their convenience.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch introduces wally_tx_input_is_pegin() and wally_tx_is_input_pegin() as replacements for wally_tx_elements_input_is_pegin(). The deprecated function is reimplemented as a thin wrapper around the new function, preserving identical behavior. Bindings (Java, Python, WASM/JS, TypeScript) and tests are updated to expose/use the new names. No logic changes, no memory safety fixes, and no validation changes are present.
Changed components
include/wally_transaction.hinclude/wally_transaction_members.hsrc/transaction.csrc/ctest/test_elements_tx.csrc/swig_java/jni_elements_extra.java_insrc/swig_java/swig.isrc/test/util.pysrc/wasm_package/src/functions.jssrc/wasm_package/src/index.d.tstools/wasm_exports.shInspect captured patch +48 / −16
### include/wally_transaction.h
@@ -1055,10 +1055,7 @@ WALLY_CORE_API int wally_tx_elements_input_init_alloc(
struct wally_tx_input **output);
/**
- * Determine if an input is a pegin.
- *
- * :param input: The input to check.
- * :param written: 1 if the input is a pegin, otherwise 0.
+ * Deprecated. Use `wally_tx_input_is_pegin`.
*/
WALLY_CORE_API int wally_tx_elements_input_is_pegin(
const struct wally_tx_input *input,
### include/wally_transaction_members.h
@@ -92,6 +92,8 @@ WALLY_CORE_API int wally_tx_get_num_outputs(const struct wally_tx *tx_in, size_t
/* Transaction Inputs */
+WALLY_CORE_API int wally_tx_input_is_pegin(const struct wally_tx_input *tx_in, size_t *written);
+
/**
* FIXED_SIZED_OUTPUT(len, bytes_out, WALLY_TXHASH_LEN)
*/
@@ -129,6 +131,7 @@ WALLY_CORE_API int wally_tx_get_input_issuance_amount_rangeproof(const struct wa
WALLY_CORE_API int wally_tx_get_input_issuance_amount_rangeproof_len(const struct wally_tx *tx_in, size_t index, size_t *written);
WALLY_CORE_API int wally_tx_get_input_inflation_keys_rangeproof(const struct wally_tx *tx_in, size_t index, unsigned char *bytes_out, size_t len, size_t *written);
WALLY_CORE_API int wally_tx_get_input_inflation_keys_rangeproof_len(const struct wally_tx *tx_in, size_t index, size_t *written);
+WALLY_CORE_API int wally_tx_is_input_pegin(const struct wally_tx *tx_in, size_t index, size_t *written);
WALLY_CORE_API int wally_tx_set_input_blinding_nonce(const struct wally_tx *tx_in, size_t index, const unsigned char *blinding_nonce, size_t blinding_nonce_len);
WALLY_CORE_API int wally_tx_set_input_entropy(const struct wally_tx *tx_in, size_t index, const unsigned char *entropy, size_t entropy_len);
### src/ctest/test_elements_tx.c
@@ -2,6 +2,7 @@
#include <wally_crypto.h>
#include <wally_transaction.h>
+#include <wally_transaction_members.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -235,7 +236,7 @@ static bool tx_pegin(const char *tx_hex, const char **tx_pegin_wit_hex, size_t n
in = &tx->inputs[0];
- ret = wally_tx_elements_input_is_pegin(in, &is_pegin);
+ ret = wally_tx_input_is_pegin(in, &is_pegin);
if (ret != WALLY_OK || !is_pegin)
return false;
### src/swig_java/jni_elements_extra.java_in
@@ -261,8 +261,17 @@
return tx_elements_input_init(jarg1, jarg2, jarg3, jarg4, null, null, null, null, null, null, null, null);
}
+ public final static boolean tx_input_is_pegin(final Object tx_input) {
+ return _tx_input_is_pegin(tx_input) != 0;
+ }
+
+ // TODO: Remove this wrapper in favour of tx_input_is_pegin
public final static boolean tx_elements_input_is_pegin(final Object tx_input) {
- return _tx_elements_input_is_pegin(tx_input) != 0;
+ return tx_input_is_pegin(tx_input);
+ }
+
+ public final static boolean tx_is_input_pegin(final Object tx, final long index) {
+ return _tx_is_input_pegin(tx, index) != 0;
}
public final static byte[] tx_input_get_blinding_nonce(Object tx_input) {
### src/swig_java/swig.i
@@ -1029,7 +1029,7 @@ static jobjectArray create_jstringArray(JNIEnv *jenv, char **p, size_t len) {
%returns_uint64(wally_tx_confidential_value_to_satoshi);
%returns_struct(wally_tx_elements_input_init_alloc, wally_tx_input);
%rename("tx_elements_input_init") wally_tx_elements_input_init_alloc;
-%rename("_tx_elements_input_is_pegin") wally_tx_elements_input_is_pegin;
+%rename("_tx_input_is_pegin") wally_tx_input_is_pegin;
%returns_size_t(_tx_elements_input_is_pegin);
%returns_void__(wally_tx_elements_input_issuance_set);
%returns_void__(wally_tx_elements_input_issuance_free);
@@ -1062,6 +1062,8 @@ static jobjectArray create_jstringArray(JNIEnv *jenv, char **p, size_t len) {
%rename("_tx_get_input_inflation_keys_rangeproof") wally_tx_get_input_inflation_keys_rangeproof;
%returns_size_t(_tx_get_input_inflation_keys_rangeproof);
%returns_size_t(wally_tx_get_input_inflation_keys_rangeproof_len);
+%rename("_tx_is_input_pegin") wally_tx_is_input_pegin;
+%returns_size_t(_tx_is_input_pegin);
%rename("_tx_get_input_script") wally_tx_get_input_script;
%returns_size_t(_tx_get_input_script);
%returns_size_t(wally_tx_get_input_script_len);
@@ -1393,6 +1395,7 @@ static jobjectArray create_jstringArray(JNIEnv *jenv, char **p, size_t len) {
%ignore wally_psbt_output_clear_asset_blinding_surjectionproof;
%ignore wally_psbt_output_get_blinding_status;
%ignore wally_psbt_output_set_taproot_internal_key;
+%ignore wally_tx_elements_input_is_pegin;
%include "../include/wally_core.h"
%include "../include/wally_address.h"
### src/test/util.py
@@ -1039,6 +1039,7 @@ class wally_psbt(Structure):
('wally_tx_input_get_witness', c_int, [POINTER(wally_tx_input), c_size_t, c_void_p, c_size_t, c_size_t_p]),
('wally_tx_input_get_witness_len', c_int, [POINTER(wally_tx_input), c_size_t, c_size_t_p]),
('wally_tx_input_get_witness_num_items', c_int, [POINTER(wally_tx_input), c_size_t_p]),
+ ('wally_tx_input_is_pegin', c_int, [POINTER(wally_tx_input), c_size_t_p]),
('wally_tx_input_set_blinding_nonce', c_int, [POINTER(wally_tx_input), c_void_p, c_size_t]),
('wally_tx_input_set_entropy', c_int, [POINTER(wally_tx_input), c_void_p, c_size_t]),
('wally_tx_input_set_index', c_int, [POINTER(wally_tx_input), c_uint32]),
@@ -1050,6 +1051,7 @@ class wally_psbt(Structure):
('wally_tx_input_set_sequence', c_int, [POINTER(wally_tx_input), c_uint32]),
('wally_tx_input_set_txhash', c_int, [POINTER(wally_tx_input), c_void_p, c_size_t]),
('wally_tx_input_set_witness', c_int, [POINTER(wally_tx_input), POINTER(wally_tx_witness_stack)]),
+ ('wally_tx_is_input_pegin', c_int, [POINTER(wally_tx), c_size_t, c_size_t_p]),
('wally_tx_output_get_asset', c_int, [POINTER(wally_tx_output), c_void_p, c_size_t]),
('wally_tx_output_get_asset_len', c_int, [POINTER(wally_tx_output), c_size_t_p]),
('wally_tx_output_get_nonce', c_int, [POINTER(wally_tx_output), c_void_p, c_size_t]),
### src/transaction.c
@@ -88,11 +88,6 @@ static bool is_valid_elements_tx_input(const struct wally_tx_input *input)
return is_valid_tx_input(input) && (input->features & WALLY_TX_IS_ELEMENTS);
}
-static bool is_valid_elements_tx_input_pegin(const struct wally_tx_input *input)
-{
- return is_valid_elements_tx_input(input) && (input->features & WALLY_TX_IS_PEGIN);
-}
-
static bool is_coinbase_bytes(const unsigned char *bytes, size_t bytes_len, uint32_t index)
{
return index == 0xffffffff && mem_is_zero(bytes, bytes_len);
@@ -2655,18 +2650,29 @@ int wally_tx_is_elements(const struct wally_tx *tx, size_t *written)
return WALLY_OK;
}
-int wally_tx_elements_input_is_pegin(const struct wally_tx_input *input,
- size_t *written)
+int wally_tx_input_is_pegin(const struct wally_tx_input *tx_in, size_t *written)
{
if (written)
*written = 0;
- if (!input || !written)
+ if (!tx_in || !written)
return WALLY_EINVAL;
- *written = is_valid_elements_tx_input_pegin(input);
+ if (is_valid_elements_tx_input(tx_in) &&
+ (tx_in->features & WALLY_TX_IS_PEGIN))
+ *written = 1;
+ else
+ *written = 0;
+
return WALLY_OK;
}
+/* TODO: Remove this deprecated call in favour of wally_tx_input_is_pegin */
+int wally_tx_elements_input_is_pegin(const struct wally_tx_input *tx_in,
+ size_t *written)
+{
+ return wally_tx_input_is_pegin(tx_in, written);
+}
+
int wally_tx_is_coinbase(const struct wally_tx *tx, size_t *written)
{
if (written)
@@ -3289,6 +3295,11 @@ TX_GET_I_ELEMENTS(input, inflation_keys_len)
TX_GET_I_ELEMENTS(input, inflation_keys_rangeproof_len)
TX_GET_I_ELEMENTS(input, issuance_amount_len)
TX_GET_I_ELEMENTS(input, issuance_amount_rangeproof_len)
+
+int wally_tx_is_input_pegin(const struct wally_tx *tx, size_t index, size_t *written)
+{
+ return wally_tx_input_is_pegin(tx_get_input(tx, index), written);
+}
#endif /* WALLY_ABI_NO_ELEMENTS */
TX_GET_B(output, script)
### src/wasm_package/src/functions.js
@@ -735,6 +735,7 @@ export const tx_input_get_txhash = wrap('wally_tx_input_get_txhash', [T.OpaqueRe
export const tx_input_get_witness_len = wrap('wally_tx_input_get_witness_len', [T.OpaqueRef, T.Int32, T.DestPtr(T.Int32)]);
export const tx_input_get_witness_num_items = wrap('wally_tx_input_get_witness_num_items', [T.OpaqueRef, T.DestPtr(T.Int32)]);
export const tx_input_init = wrap('wally_tx_input_init_alloc', [T.Bytes, T.Int32, T.Int32, T.Bytes, T.OpaqueRef, T.DestPtrPtr(T.OpaqueRef)]);
+export const tx_input_is_pegin = wrap('wally_tx_input_is_pegin', [T.OpaqueRef, T.DestPtr(T.Int32)]);
export const tx_input_set_blinding_nonce = wrap('wally_tx_input_set_blinding_nonce', [T.OpaqueRef, T.Bytes]);
export const tx_input_set_entropy = wrap('wally_tx_input_set_entropy', [T.OpaqueRef, T.Bytes]);
export const tx_input_set_index = wrap('wally_tx_input_set_index', [T.OpaqueRef, T.Int32]);
@@ -748,6 +749,7 @@ export const tx_input_set_txhash = wrap('wally_tx_input_set_txhash', [T.OpaqueRe
export const tx_input_set_witness = wrap('wally_tx_input_set_witness', [T.OpaqueRef, T.OpaqueRef]);
export const tx_is_coinbase = wrap('wally_tx_is_coinbase', [T.OpaqueRef, T.DestPtr(T.Int32)]);
export const tx_is_elements = wrap('wally_tx_is_elements', [T.OpaqueRef, T.DestPtr(T.Int32)]);
+export const tx_is_input_pegin = wrap('wally_tx_is_input_pegin', [T.OpaqueRef, T.Int32, T.DestPtr(T.Int32)]);
export const tx_output_clone = wrap('wally_tx_output_clone_alloc', [T.OpaqueRef, T.DestPtrPtr(T.OpaqueRef)]);
export const tx_output_clone_noalloc = wrap('wally_tx_output_clone', [T.OpaqueRef, T.OpaqueRef]);
export const tx_output_free = wrap('wally_tx_output_free', [T.OpaqueRef]);
### src/wasm_package/src/index.d.ts
@@ -695,6 +695,7 @@ export function tx_input_get_txhash(tx_input_in: Ref_wally_tx_input): Buffer;
export function tx_input_get_witness_len(tx_input_in: Ref_wally_tx_input, index: number): number;
export function tx_input_get_witness_num_items(tx_input_in: Ref_wally_tx_input): number;
export function tx_input_init(txhash: Buffer|Uint8Array|null, utxo_index: number, sequence: number, script: Buffer|Uint8Array|null, witness: Ref_wally_tx_witness_stack): Ref_wally_tx_input;
+export function tx_input_is_pegin(tx_in: Ref_wally_tx_input): number;
export function tx_input_set_blinding_nonce(tx_input_in: Ref_wally_tx_input, blinding_nonce: Buffer|Uint8Array|null): void;
export function tx_input_set_entropy(tx_input_in: Ref_wally_tx_input, entropy: Buffer|Uint8Array|null): void;
export function tx_input_set_index(tx_input: Ref_wally_tx_input, index: number): void;
@@ -708,6 +709,7 @@ export function tx_input_set_txhash(tx_input: Ref_wally_tx_input, txhash: Buffer
export function tx_input_set_witness(tx_input: Ref_wally_tx_input, witness: Ref_wally_tx_witness_stack): void;
export function tx_is_coinbase(tx: Ref_wally_tx): number;
export function tx_is_elements(tx: Ref_wally_tx): number;
+export function tx_is_input_pegin(tx_in: Ref_wally_tx, index: number): number;
export function tx_output_clone(tx_output_in: Ref_wally_tx_output): Ref_wally_tx_output;
export function tx_output_clone_noalloc(tx_output_in: Ref_wally_tx_output, output: Ref_wally_tx_output): void;
export function tx_output_free(output: Ref_wally_tx_output): void;
### tools/wasm_exports.sh
@@ -462,6 +462,7 @@ EXPORTED_FUNCTIONS="['_malloc','_free','_bip32_key_free' \
,'_wally_tx_input_get_witness_len' \
,'_wally_tx_input_get_witness_num_items' \
,'_wally_tx_input_init_alloc' \
+,'_wally_tx_input_is_pegin' \
,'_wally_tx_input_set_index' \
,'_wally_tx_input_set_script' \
,'_wally_tx_input_set_sequence' \
@@ -844,6 +845,7 @@ if [ -z "$DISABLE_ELEMENTS" ]; then
,'_wally_tx_input_set_issuance_amount' \
,'_wally_tx_input_set_issuance_amount_rangeproof' \
,'_wally_tx_is_elements' \
+,'_wally_tx_is_input_pegin' \
,'_wally_tx_output_get_asset' \
,'_wally_tx_output_get_asset_len' \
,'_wally_tx_output_get_nonce' \Why this scored 19/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.