Skip to content

Commit c7fb036

Browse files
committed
allow to configure the number of public digits/bits
1 parent 8de9f44 commit c7fb036

File tree

5 files changed

+31
-6
lines changed

5 files changed

+31
-6
lines changed

include/wally_elements.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ WALLY_CORE_API int wally_asset_rangeproof(
7474
const unsigned char *generator,
7575
size_t generator_len,
7676
uint64_t min_value,
77+
int exp,
78+
int min_bits,
7779
unsigned char *bytes_out,
7880
size_t len,
7981
size_t *written);

src/elements.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ int wally_asset_rangeproof(uint64_t value,
129129
const unsigned char *commitment, size_t commitment_len,
130130
const unsigned char *extra, size_t extra_len,
131131
const unsigned char *generator, size_t generator_len,
132-
uint64_t min_value, unsigned char *bytes_out, size_t len,
132+
uint64_t min_value, int exp, int min_bits,
133+
unsigned char *bytes_out, size_t len,
133134
size_t *written)
134135
{
135136
const secp256k1_context *ctx = secp_ctx();
@@ -157,6 +158,8 @@ int wally_asset_rangeproof(uint64_t value,
157158
/* FIXME: Is there an upper size limit on the extra commitment? */
158159
(extra_len && !extra) ||
159160
min_value > 0x7ffffffffffffffful ||
161+
exp < -1 || exp > 18 ||
162+
min_bits < 0 || min_bits > 64 ||
160163
get_generator(ctx, generator, generator_len, &gen) != WALLY_OK)
161164
goto cleanup;
162165

@@ -175,10 +178,8 @@ int wally_asset_rangeproof(uint64_t value,
175178
memcpy(message + ASSET_TAG_LEN, abf, ASSET_TAG_LEN);
176179

177180
*written = ASSET_RANGEPROOF_MAX_LEN;
178-
/* FIXME: This only allows 32 bit values. The caller should be able to
179-
* pass in the maximum value allowed */
180181
if (secp256k1_rangeproof_sign(ctx, bytes_out, written, min_value, &commit,
181-
vbf, nonce_sha.u.u8, 0, 32, value,
182+
vbf, nonce_sha.u.u8, exp, min_bits, value,
182183
message, sizeof(message),
183184
extra, extra_len,
184185
&gen))

src/swig_java/jni_elements_extra.java_in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515

1616
public final static byte[] asset_rangeproof(long jarg1, byte[] jarg2, byte[] jarg3, byte[] jarg4,
1717
byte[] jarg5, byte[] jarg6, byte[] jarg7, byte[] jarg8,
18-
byte[] jarg9, int jarg10) {
18+
byte[] jarg9, int jarg10, int jarg11, int jarg12) {
1919
final byte[] buf = new byte[ASSET_RANGEPROOF_MAX_LEN];
2020
final int len = asset_rangeproof(jarg1, jarg2, jarg3, jarg4, jarg5, jarg6, jarg7, jarg8,
21-
jarg9, jarg10, buf);
21+
jarg9, jarg10, jarg11, jarg12, buf);
2222
return trimBuffer(buf, len);
2323
}
2424

src/wrap_js/makewrappers/templates/nan.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,23 @@
115115
return value;
116116
}
117117
118+
static int32_t GetInt32(Nan::NAN_METHOD_ARGS_TYPE info, int n, int& ret)
119+
{
120+
int value = 0;
121+
if (ret == WALLY_OK) {
122+
if (!IsValid(info[n]) || !info[n]->IsInt32())
123+
ret = WALLY_EINVAL;
124+
else {
125+
Nan::Maybe<int32_t> m = Nan::To<int32_t>(info[n]);
126+
if (IsValid(m))
127+
value = m.FromJust();
128+
else
129+
ret = WALLY_EINVAL;
130+
}
131+
}
132+
return value;
133+
}
134+
118135
// uint64_t values are expected as an 8 byte buffer of big endian bytes
119136
struct LocalUInt64 : public LocalBuffer {
120137
LocalUInt64(Nan::NAN_METHOD_ARGS_TYPE info, int n, int& ret)
@@ -239,6 +256,9 @@ def _generate_nan(funcname, f):
239256
elif arg.startswith('uint32_t'):
240257
input_args.append('uint32_t arg%s = GetUInt32(info, %s, ret);' % (i, i))
241258
args.append('arg%s' % i)
259+
elif arg.startswith('int'):
260+
input_args.append('int32_t arg%s = GetInt32(info, %s, ret);' % (i, i))
261+
args.append('arg%s' % i)
242262
elif arg.startswith('string'):
243263
args.append('*Nan::Utf8String(info[%s])' % i)
244264
elif arg.startswith('const_uint64s'):

src/wrap_js/makewrappers/wrap.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ def __init__(self, arguments, out_size=None, wally_name=None, nodejs_append_allo
196196
'const_bytes[extra_in]',
197197
'const_bytes[generator]',
198198
'uint64_t[min_value]',
199+
'int[exp]',
200+
'int[min_bits]',
199201
'out_bytes_sized',
200202
], out_size='5134')),
201203
('wally_asset_surjectionproof', F([

0 commit comments

Comments
 (0)