Skip to content

Commit

Permalink
Remove generateSigners function and refactor with Salter().signers() (W…
Browse files Browse the repository at this point in the history
…ebOfTrust#778)

Co-authored-by: Rubel Hassan Mollik <[email protected]>
  • Loading branch information
rubelhassan and Rubel Hassan Mollik authored May 7, 2024
1 parent 3f624aa commit 4622388
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 56 deletions.
3 changes: 1 addition & 2 deletions src/keri/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@

from .coring import Tholder
from .indexing import Indexer, Siger, IdrDex, IdxSigDex
from .signing import (Signer, Salter, Cipher, Encrypter, Decrypter,
generateSigners, )
from .signing import (Signer, Salter, Cipher, Encrypter, Decrypter, )
38 changes: 0 additions & 38 deletions src/keri/core/signing.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,44 +25,6 @@
ECDSA_256k1_SEEDBYTES = 32


# deprecated use Salter.signers instead
def generateSigners(raw=None, count=8, transferable=True):
"""Returns list of Signers for Ed25519
Deprecated, use Salter.signers instead.
Use this when simply need valid AIDs but not when need valid controller
contexts. In the latter case use openHby or openHab which create databases.
Parameters:
raw (bytes): 16 byte long salt cryptomatter from which seeds
for Signers in list are derived
random salt created if not provided
count is number of signers in list
transferable is boolean true means signer.verfer code is transferable
non-transferable otherwise
"""
if not raw:
raw = pysodium.randombytes(pysodium.crypto_pwhash_SALTBYTES)

signers = []
for i in range(count):
path = f"{i:x}"
# algorithm default is argon2id
seed = pysodium.crypto_pwhash(outlen=32,
passwd=path,
salt=raw,
opslimit=2, # pysodium.crypto_pwhash_OPSLIMIT_INTERACTIVE,
memlimit=67108864, # pysodium.crypto_pwhash_MEMLIMIT_INTERACTIVE,
alg=pysodium.crypto_pwhash_ALG_ARGON2ID13)

signers.append(Signer(raw=seed, transferable=transferable))

return signers




class Signer(Matter):
"""
Signer is Matter subclass with method to create signature of serialization
Expand Down
8 changes: 4 additions & 4 deletions tests/core/test_eventing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2453,7 +2453,7 @@ def test_keyeventsequence_0():
"""
# create signers
salt = b'g\x15\x89\x1a@\xa4\xa47\x07\xb9Q\xb8\x18\xcdJW'
signers = core.generateSigners(raw=salt, count=8, transferable=True)
signers = core.Salter(raw=salt).signers(count=8)

pubkeys = [signer.verfer.qb64 for signer in signers]
assert pubkeys == ['DErocgXD2RGSyvn3MObcx59jeOsEQhv2TqHirVkzrp0Q',
Expand Down Expand Up @@ -2723,7 +2723,7 @@ def test_keyeventsequence_1():

# create signers
salt = b'g\x15\x89\x1a@\xa4\xa47\x07\xb9Q\xb8\x18\xcdJW'
signers = core.generateSigners(raw=salt, count=8, transferable=True)
signers = core.Salter(raw=salt).signers(count=8)

pubkeys = [signer.verfer.qb64 for signer in signers]
assert pubkeys == ['DErocgXD2RGSyvn3MObcx59jeOsEQhv2TqHirVkzrp0Q',
Expand Down Expand Up @@ -2820,7 +2820,7 @@ def test_multisig_digprefix():

# create signers
salt = b'g\x15\x89\x1a@\xa4\xa47\x07\xb9Q\xb8\x18\xcdJW'
signers = core.generateSigners(raw=salt, count=8, transferable=True)
signers = core.Salter(raw=salt).signers(count=8)

pubkeys = [signer.verfer.qb64 for signer in signers]
assert pubkeys == ['DErocgXD2RGSyvn3MObcx59jeOsEQhv2TqHirVkzrp0Q',
Expand Down Expand Up @@ -2974,7 +2974,7 @@ def test_recovery():
"""
# create signers
salt = b'g\x15\x89\x1a@\xa4\xa47\x07\xb9Q\xb8\x18\xcdJW'
signers = core.generateSigners(raw=salt, count=8, transferable=True)
signers = core.Salter(raw=salt).signers(count=8)

with openDB(name="controller") as conlgr, openDB(name="validator") as vallgr:
event_digs = [] # list of event digs in sequence to verify against database
Expand Down
17 changes: 5 additions & 12 deletions tests/core/test_signing.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,14 @@


import pysodium

import pytest

from keri import kering

from keri.help import helping

from keri import core
from keri.core import (Tiers, )
from keri.core import (Matter, MtrDex, Cigar, Verfer, Prefixer)
from keri.core import (Indexer, IdrDex, )
from keri.core import (Signer, generateSigners, Salter,
from keri.core import (Matter, MtrDex, Cigar, Verfer, Prefixer)
from keri.core import (Signer, Salter,
Cipher, Encrypter, Decrypter, )

from keri.core import (Tiers, )


def test_signer():
Expand Down Expand Up @@ -381,21 +375,20 @@ def test_signer():
""" Done Test """


# deprecated uses Salter.signers() instead
def test_generatesigners():
"""
Test the support function genSigners
"""
signers = generateSigners(count=2, transferable=False)
signers = Salter().signers(count=2, temp=True, transferable=False)
assert len(signers) == 2
for signer in signers:
assert signer.verfer.code == MtrDex.Ed25519N

# raw = pysodium.randombytes(pysodium.crypto_pwhash_SALTBYTES) # raw salt
raw = b'g\x15\x89\x1a@\xa4\xa47\x07\xb9Q\xb8\x18\xcdJW'
assert len(raw) == 16
signers = generateSigners(raw=raw, count=4) # default is transferable
signers = Salter(raw=raw).signers(count=4)
assert len(signers) == 4
for signer in signers:
assert signer.code == MtrDex.Ed25519_Seed
Expand Down

0 comments on commit 4622388

Please sign in to comment.