Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 4 additions & 2 deletions bip-0327/gen_vectors_helper.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from pathlib import Path

from reference import *

def gen_key_agg_vectors():
Expand All @@ -16,7 +18,7 @@ def gen_key_agg_vectors():
print(" tweak: ", tweak.hex().upper())

def check_sign_verify_vectors():
with open(os.path.join(sys.path[0], 'vectors', 'sign_verify_vectors.json')) as f:
with open(Path(__file__).parent / 'vectors' / 'sign_verify_vectors.json') as f:
test_data = json.load(f)
X = fromhex_all(test_data["pubkeys"])
pnonce = fromhex_all(test_data["pnonces"])
Expand Down Expand Up @@ -44,7 +46,7 @@ def check_sign_verify_vectors():
assert has_even_y(Q) and has_even_y(R)

def check_tweak_vectors():
with open(os.path.join(sys.path[0], 'vectors', 'tweak_vectors.json')) as f:
with open(Path(__file__).parent / 'vectors' / 'tweak_vectors.json') as f:
test_data = json.load(f)

X = fromhex_all(test_data["pubkeys"])
Expand Down
19 changes: 9 additions & 10 deletions bip-0327/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,7 @@ def partial_sig_agg(psigs: List[bytes], session_ctx: SessionContext) -> bytes:
#

import json
import os
import sys
from pathlib import Path

def fromhex_all(l):
return [bytes.fromhex(l_i) for l_i in l]
Expand Down Expand Up @@ -497,7 +496,7 @@ def get_error_details(test_case):
return exception, except_fn

def test_key_sort_vectors() -> None:
with open(os.path.join(sys.path[0], 'vectors', 'key_sort_vectors.json')) as f:
with open(Path(__file__).parent / 'vectors' / 'key_sort_vectors.json') as f:
test_data = json.load(f)

X = fromhex_all(test_data["pubkeys"])
Expand All @@ -506,7 +505,7 @@ def test_key_sort_vectors() -> None:
assert key_sort(X) == X_sorted

def test_key_agg_vectors() -> None:
with open(os.path.join(sys.path[0], 'vectors', 'key_agg_vectors.json')) as f:
with open(Path(__file__).parent / 'vectors' / 'key_agg_vectors.json') as f:
test_data = json.load(f)

X = fromhex_all(test_data["pubkeys"])
Expand All @@ -530,7 +529,7 @@ def test_key_agg_vectors() -> None:
assert_raises(exception, lambda: key_agg_and_tweak(pubkeys, tweaks, is_xonly), except_fn)

def test_nonce_gen_vectors() -> None:
with open(os.path.join(sys.path[0], 'vectors', 'nonce_gen_vectors.json')) as f:
with open(Path(__file__).parent / 'vectors' / 'nonce_gen_vectors.json') as f:
test_data = json.load(f)

for test_case in test_data["test_cases"]:
Expand All @@ -557,7 +556,7 @@ def get_value_maybe(key) -> Optional[bytes]:
assert nonce_gen_internal(rand_, sk, pk, aggpk, msg, extra_in) == (expected_secnonce, expected_pubnonce)

def test_nonce_agg_vectors() -> None:
with open(os.path.join(sys.path[0], 'vectors', 'nonce_agg_vectors.json')) as f:
with open(Path(__file__).parent / 'vectors' / 'nonce_agg_vectors.json') as f:
test_data = json.load(f)

pnonce = fromhex_all(test_data["pnonces"])
Expand All @@ -575,7 +574,7 @@ def test_nonce_agg_vectors() -> None:
assert_raises(exception, lambda: nonce_agg(pubnonces), except_fn)

def test_sign_verify_vectors() -> None:
with open(os.path.join(sys.path[0], 'vectors', 'sign_verify_vectors.json')) as f:
with open(Path(__file__).parent / 'vectors' / 'sign_verify_vectors.json') as f:
test_data = json.load(f)

sk = bytes.fromhex(test_data["sk"])
Expand Down Expand Up @@ -658,7 +657,7 @@ def test_sign_verify_vectors() -> None:
assert_raises(exception, lambda: partial_sig_verify(sig, pubnonces, pubkeys, [], [], msg, signer_index), except_fn)

def test_tweak_vectors() -> None:
with open(os.path.join(sys.path[0], 'vectors', 'tweak_vectors.json')) as f:
with open(Path(__file__).parent / 'vectors' / 'tweak_vectors.json') as f:
test_data = json.load(f)

sk = bytes.fromhex(test_data["sk"])
Expand Down Expand Up @@ -715,7 +714,7 @@ def test_tweak_vectors() -> None:
assert_raises(exception, lambda: sign(secnonce, sk, session_ctx), except_fn)

def test_det_sign_vectors() -> None:
with open(os.path.join(sys.path[0], 'vectors', 'det_sign_vectors.json')) as f:
with open(Path(__file__).parent / 'vectors' / 'det_sign_vectors.json') as f:
test_data = json.load(f)

sk = bytes.fromhex(test_data["sk"])
Expand Down Expand Up @@ -762,7 +761,7 @@ def test_det_sign_vectors() -> None:
assert_raises(exception, try_fn, except_fn)

def test_sig_agg_vectors() -> None:
with open(os.path.join(sys.path[0], 'vectors', 'sig_agg_vectors.json')) as f:
with open(Path(__file__).parent / 'vectors' / 'sig_agg_vectors.json') as f:
test_data = json.load(f)

X = fromhex_all(test_data["pubkeys"])
Expand Down