diff --git a/README.md b/README.md index a0130d0..bde8bcc 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,47 @@ +# js2pysecrets + +[![codecov](https://codecov.io/gh/poing/JS2PySecrets/branch/main/graph/badge.svg?token=JS2PySecrets_token_here)](https://codecov.io/gh/poing/JS2PySecrets) +[![CI](https://github.com/poing/JS2PySecrets/actions/workflows/main.yml/badge.svg)](https://github.com/poing/JS2PySecrets/actions/workflows/main.yml) + +Awesome js2pysecrets created by poing + +## Status + +The project is intended to create a `Python` version that is compatible with `secrets.js`. It's currently in the **DEVELOPMENT** stage and the framework is being built to *effectively* test and run the `JavaScript` from within the `Python` environment. + +### Requirements + +The use this project in it's current state **and for testing**, `Node` is required on the system. This is used to run the `JavaScript`. + +## Install it from PyPI + +```bash +pip install js2pysecrets +``` + +## Usage + +```py +from js2pysecrets import BaseClass +from js2pysecrets import base_function + +BaseClass().base_method() +base_function() +``` + +```bash +$ python -m js2pysecrets +#or +$ js2pysecrets +``` + +## Development and Testing + +Read the [CONTRIBUTING.md](CONTRIBUTING.md) file. + + +---- # Python Project Template A low dependency and really simple to start project template for Python Projects. @@ -48,38 +91,3 @@ See also [❤️ Sponsor this project](https://github.com/sponsors/rochacbruno/) - - ---- -# js2pysecrets - -[![codecov](https://codecov.io/gh/poing/JS2PySecrets/branch/main/graph/badge.svg?token=JS2PySecrets_token_here)](https://codecov.io/gh/poing/JS2PySecrets) -[![CI](https://github.com/poing/JS2PySecrets/actions/workflows/main.yml/badge.svg)](https://github.com/poing/JS2PySecrets/actions/workflows/main.yml) - -Awesome js2pysecrets created by poing - -## Install it from PyPI - -```bash -pip install js2pysecrets -``` - -## Usage - -```py -from js2pysecrets import BaseClass -from js2pysecrets import base_function - -BaseClass().base_method() -base_function() -``` - -```bash -$ python -m js2pysecrets -#or -$ js2pysecrets -``` - -## Development - -Read the [CONTRIBUTING.md](CONTRIBUTING.md) file. diff --git a/gems/test_func.py b/gems/test_func.py index 222e8d7..d01d24f 100755 --- a/gems/test_func.py +++ b/gems/test_func.py @@ -25,3 +25,5 @@ def wrapper(*args, **kwargs): # Wrap the forTesting function with the inject_behavior decorator #forTesting = inject_behavior(forTesting) + +# Maybe can use the wrapper from the test_inject, setting the global HERE. diff --git a/gems/test_import2.py b/gems/test_import2.py index 79ac076..bc41a27 100755 --- a/gems/test_import2.py +++ b/gems/test_import2.py @@ -5,11 +5,25 @@ # test.py import json -from js2pysecrets import wrapper +import js2pysecrets +# from js2pysecrets import wrapper +# +# +# setup = [] +# main = {'function': 'getConfig', 'args': []} +# tasks = {'tasks': [{'setup': setup, 'start': main}]} +# json_data = json.dumps(tasks, indent=None) +# print(wrapper(json_data)) + +# print(js2pysecrets.share("ababab", 6, 3)) +# print(js2pysecrets.getConfig()) +# print(js2pysecrets._reset()) +# print(js2pysecrets.getConfig()) + +# data = js2pysecrets.random(64) +# print(js2pysecrets.str2hex(data)) +random = js2pysecrets.jsFunction('random', test=True) +print(random(32)) +print(js2pysecrets.random(32)) -setup = [] -main = {'function': 'getConfig', 'args': []} -tasks = {'tasks': [{'setup': setup, 'start': main}]} -json_data = json.dumps(tasks, indent=None) -print(wrapper(json_data)) \ No newline at end of file diff --git a/js2pysecrets/__init__.py b/js2pysecrets/__init__.py index 032ed84..b6c60ec 100644 --- a/js2pysecrets/__init__.py +++ b/js2pysecrets/__init__.py @@ -4,7 +4,10 @@ from .base import getConfig from .base import init from .base import share - +from .base import _reset +from .base import random +from .base import str2hex +from .base import jsFunction #with open("VERSION", "r") as version_file: # __version__ = version_file.read().strip() diff --git a/js2pysecrets/base.py b/js2pysecrets/base.py index a9ba97b..e1cb42c 100644 --- a/js2pysecrets/base.py +++ b/js2pysecrets/base.py @@ -1,32 +1,33 @@ import json -from .wrapper import wrapper +from .wrapper import wrapper # Import your wrapper function -def init(bits=None, rngType=None): - setup = [{'function': 'init', 'args': [bits]}] - main = {'function': None, 'args': []} - tasks = {'tasks': [{'start': main}]} - json_data = json.dumps(tasks, indent=None) - data = wrapper(json_data) - return data +class jsFunction: + def __init__(self, func_name, test=False): + self.func_name = func_name + self.test = test -def getConfig(): - setup = [] - main = {'function': 'getConfig', 'args': []} - tasks = {'tasks': [{'setup': setup, 'start': main}]} - json_data = json.dumps(tasks, indent=None) - data = wrapper(json_data) - return data + def __call__(self, *args, **kwargs): + result = { + 'function': self.func_name, + 'args': args + } -def share(secret, numShares, threshold, padLength=128): - setup = [ - {'function': 'setRNG', 'args': ['testRandom']}, - {'function': 'init', 'args': []}, - ] - main = {'function': 'share', 'args': [secret, numShares, threshold, padLength]} - tasks = {'tasks': [{'setup': setup, 'start': main}]} - json_data = json.dumps(tasks, indent=None) - data = wrapper(json_data) - return data + setup = [] # Keep the setup list + if self.test: + setup = [{'function': 'setRNG', 'args': ['testRandom']}] + main = {'function': self.func_name, 'args': args} + tasks = {'tasks': [{'setup': setup, 'start': main}]} + json_data = json.dumps(tasks, indent=None) + data = wrapper(json_data) + + return data - \ No newline at end of file +random = jsFunction('random') +share = jsFunction('share') +init = jsFunction('init') +getConfig = jsFunction('getConfig') +_reset = jsFunction('_reset') +setRNG = jsFunction('setRNG') +str2hex = jsFunction('str2hex') +hex2str = jsFunction('hex2str')