Skip to content

Commit

Permalink
Deprecate randomNonce() and refactor using Salter().qb64 (WebOfTrust#768
Browse files Browse the repository at this point in the history
)

Co-authored-by: Rubel Hassan Mollik <[email protected]>
  • Loading branch information
rubelhassan and Rubel Hassan Mollik authored Apr 30, 2024
1 parent e414492 commit 06f1903
Show file tree
Hide file tree
Showing 15 changed files with 380 additions and 375 deletions.
4 changes: 2 additions & 2 deletions src/keri/app/cli/commands/ipex/agree.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from hio.base import doing

from keri.core import coring
from keri.core import signing

parser = argparse.ArgumentParser(description='Reply to IPEX offer message acknowledged willingness to accept offered '
'credential')
Expand All @@ -23,4 +23,4 @@ def nonce(tymth, tock=0.0):
"""
_ = (yield tock)

print(coring.randomNonce())
print(signing.Salter().qb64)
4 changes: 2 additions & 2 deletions src/keri/app/cli/commands/ipex/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from hio.base import doing

from keri.core import coring
from keri.core import signing

parser = argparse.ArgumentParser(description='Request a credential from another party by initiating an IPEX exchange')
parser.set_defaults(handler=lambda args: handler(args))
Expand All @@ -22,4 +22,4 @@ def nonce(tymth, tock=0.0):
"""
_ = (yield tock)

print(coring.randomNonce())
print(signing.Salter().qb64)
4 changes: 2 additions & 2 deletions src/keri/app/cli/commands/ipex/offer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from hio.base import doing

from keri.core import coring
from keri.core import signing

parser = argparse.ArgumentParser(description='Reply to IPEX apply message or initiate an IPEX exchange with an offer'
' for a credential with certain characteristics')
Expand All @@ -23,4 +23,4 @@ def nonce(tymth, tock=0.0):
"""
_ = (yield tock)

print(coring.randomNonce())
print(signing.Salter().qb64)
4 changes: 2 additions & 2 deletions src/keri/app/cli/commands/nonce.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import pysodium
from hio.base import doing

from keri.core import coring
from keri.core import signing

parser = argparse.ArgumentParser(description='Print a new random nonce')
parser.set_defaults(handler=lambda args: handler(args))
Expand All @@ -23,4 +23,4 @@ def nonce(tymth, tock=0.0):
"""
_ = (yield tock)

print(coring.randomNonce())
print(signing.Salter().qb64)
15 changes: 6 additions & 9 deletions src/keri/core/coring.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,24 +184,21 @@ def loads(raw, size=None, kind=Serials.json):
return ked


# ToDo: nonces only need 128 bits of entropy. a Salt is enough
# Just use Salter().qb64.
# Deprecated
# randomNonce() refactored to match Salter().qb64 and only used in coring to avoid circular dependencies
# use Salter().qb64 in other places

def randomNonce():
""" Generate a random ed25519 seed and encode as qb64
""" Generate a random 128 bits salt and encode as qb64
Returns:
str: qb64 encoded ed25519 random seed
str: qb64 encoded 128 bits random salt
"""
preseed = pysodium.randombytes(pysodium.crypto_sign_SEEDBYTES)
seedqb64 = Matter(raw=preseed, code=MtrDex.Ed25519_Seed).qb64
preseed = pysodium.randombytes(pysodium.crypto_pwhash_SALTBYTES)
seedqb64 = Matter(raw=preseed, code=MtrDex.Salt_128).qb64
return seedqb64





# secret derivation security tier
Tierage = namedtuple("Tierage", 'low med high')

Expand Down
3 changes: 2 additions & 1 deletion src/keri/vdr/eventing.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from ..core import serdering, coring, indexing
from ..core.coring import (MtrDex, Serials, versify, Prefixer,
Ilks, Seqner, Verfer, Number)
from ..core.signing import (Salter,)
from ..core.eventing import SealEvent, ample, TraitDex, verifySigs
from ..db import basing, dbing
from ..db.dbing import dgKey, snKey
Expand Down Expand Up @@ -90,7 +91,7 @@ def incept(
if toad != 0: # invalid toad
raise ValueError("Invalid toad = {} for baks = {}".format(toad, baks))

nonce = nonce if nonce is not None else coring.randomNonce()
nonce = nonce if nonce is not None else Salter().qb64
ked = dict(v=vs, # version string
t=ilk,
d="",
Expand Down
4 changes: 2 additions & 2 deletions tests/app/test_connecting.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from keri import kering
from keri.app import connecting, habbing
from keri.core import coring
from keri.core import signing


def test_organizer():
Expand Down Expand Up @@ -144,7 +144,7 @@ def test_organizer():
'zip': '08807'}

# Update the Jen's data signature by signing garbage
nonce = coring.randomNonce()
nonce = signing.Salter().qb64
cigar = hby.signator.sign(ser=nonce.encode("utf-8"))
hby.db.ccigs.pin(keys=(jen,), val=cigar)
with pytest.raises(kering.ValidationError):
Expand Down
14 changes: 7 additions & 7 deletions tests/app/test_grouping.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,14 +701,14 @@ def test_multisig_registry_incept(mockHelpingNowUTC, mockCoringRandomNonce):
usage="Issue vLEI Credentials")

assert exn.ked["r"] == '/multisig/vcp'
assert exn.saidb == b'ECKiNFo7fpG4vS5tUeja3EvOqT8ctq4AW8E3HKsP7dJo'
assert atc == (b'-FABEH__mobl7NDyyQCB1DoLK-OPSueraPtZAlWEjfOYkaba0AAAAAAAAAAAAAAA'
b'AAAAAAAAEH__mobl7NDyyQCB1DoLK-OPSueraPtZAlWEjfOYkaba-AABAABh6d0m'
b'lebT57L8o2si7DfEvPCoXJP0ekPiBqkzQns3-P7dz36MPXhjNFW6xRRdUstDLAZe'
b'BEqBxBCltMpTZGsD-LAa5AACAA-e-anc-AABAAD2mK9ICW9x1-0NZGkEDOcAbZ58'
b'VWK9LOTwyN2lSfHr2zY638P1SBStoh8mjgy7nOTGMyujOXMKvF_ZDeQ_ISYA')
assert exn.saidb == b'EJN27EYqgxTS2NCHdnjE-CU0UikV5a1Cw5OZdv-g0jQ6'
assert atc == (b'-FABEDEf72ZZ9mhpT1Xz-_YkXl7cg93sjZUFLIsxaFNTbXQO0AAAAAAAAAAAAAAA'
b'AAAAAAAAEDEf72ZZ9mhpT1Xz-_YkXl7cg93sjZUFLIsxaFNTbXQO-AABAABsPiWf'
b'UE9L7D9KBVOYMg1rt88gK9DBkiBYb21xMR0YH7sCT0hqwX9y8CM5Y6jQwzz3NqqN'
b'-aJWShzz1mbtb5AG-LAa5AACAA-e-anc-AABAABXlwkzbp_tC4MEbx1Uyny1o7dB'
b'GHrYjU3u90Mhv2GtrIGG-7va1jZnlXef2R_LM4TRN8_XjmpLv1skcJaM90UB')
data = exn.ked["a"]
assert data == {'gid': 'EERn_laF0qwP8zTBGL86LbF84J0Yh2IvQSRskH3BZZiy',
assert data == {'gid': 'EEVG5a8c88Fg9vH-6zQP6gJdc4LxVbUTRydx-JhpDcob',
'usage': 'Issue vLEI Credentials'}
assert "vcp" in exn.ked["e"]
assert "anc" in exn.ked["e"]
Expand Down
Loading

0 comments on commit 06f1903

Please sign in to comment.