Skip to content

Commit f0fe02c

Browse files
committed
fix: applied PR review changes
1 parent b79dcf4 commit f0fe02c

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,18 @@ Returns `null` if result is equal to `0`.
212212
- `Expected Private` if `!isPrivate(d)`
213213
- `Expected Tweak` if `tweak` is not in `[0...order - 1]`
214214

215+
### privateNegate (d)
216+
217+
```haskell
218+
privateNegate :: Buffer -> Buffer
219+
```
220+
221+
Returns the negation of d on the order n (`n - d`)
222+
223+
##### Throws:
224+
225+
- `Expected Private` if `!isPrivate(d)`
226+
215227
### xOnlyPointAddTweak (p, tweak)
216228

217229
```haskell

src/lib.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -421,14 +421,12 @@ pub extern "C" fn private_sub() -> i32 {
421421
#[allow(clippy::missing_panics_doc)]
422422
#[no_mangle]
423423
#[export_name = "privateNegate"]
424-
pub extern "C" fn private_key_negate() -> i32 {
424+
pub extern "C" fn private_negate() {
425425
unsafe {
426-
if secp256k1_ec_seckey_negate(secp256k1_context_no_precomp, PRIVATE_INPUT.as_mut_ptr()) == 1
427-
{
426+
assert_eq!(
427+
secp256k1_ec_seckey_negate(secp256k1_context_no_precomp, PRIVATE_INPUT.as_mut_ptr()),
428428
1
429-
} else {
430-
0
431-
}
429+
);
432430
}
433431
}
434432

src_ts/index.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -244,14 +244,13 @@ export function privateSub(
244244
}
245245
}
246246

247-
export function privateNegate(d: Uint8Array): Uint8Array | null {
247+
export function privateNegate(d: Uint8Array): Uint8Array {
248248
validate.validatePrivate(d);
249249

250250
try {
251251
PRIVATE_KEY_INPUT.set(d);
252-
return wasm.privateNegate() === 1
253-
? PRIVATE_KEY_INPUT.slice(0, validate.PRIVATE_KEY_SIZE)
254-
: null;
252+
wasm.privateNegate();
253+
return PRIVATE_KEY_INPUT.slice(0, validate.PRIVATE_KEY_SIZE);
255254
} finally {
256255
PRIVATE_KEY_INPUT.fill(0);
257256
}

src_ts/wasm_loader.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ interface Secp256k1WASM {
4848
pointMultiply: (p: number, outputlen: number) => number;
4949
privateAdd: () => number;
5050
privateSub: () => number;
51-
privateNegate: () => number;
51+
privateNegate: () => void;
5252
sign: (e: number) => void;
5353
signRecoverable: (e: number) => 0 | 1 | 2 | 3;
5454
signSchnorr: (e: number) => void;

0 commit comments

Comments
 (0)