Skip to content

Commit

Permalink
Testing and updated the readme
Browse files Browse the repository at this point in the history
  • Loading branch information
poing committed Jan 22, 2024
1 parent 39c5df6 commit 9b49c1f
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 68 deletions.
78 changes: 43 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.


<!-- DELETE THE LINES ABOVE THIS AND WRITE YOUR PROJECT README BELOW -->
----
# Python Project Template

A low dependency and really simple to start project template for Python Projects.
Expand Down Expand Up @@ -48,38 +91,3 @@ See also
[❤️ Sponsor this project](https://github.com/sponsors/rochacbruno/)

<!-- DELETE THE LINES ABOVE THIS AND WRITE YOUR PROJECT README BELOW -->

---
# 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.
2 changes: 2 additions & 0 deletions gems/test_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
26 changes: 20 additions & 6 deletions gems/test_import2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
5 changes: 4 additions & 1 deletion js2pysecrets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
53 changes: 27 additions & 26 deletions js2pysecrets/base.py
Original file line number Diff line number Diff line change
@@ -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


random = jsFunction('random')
share = jsFunction('share')
init = jsFunction('init')
getConfig = jsFunction('getConfig')
_reset = jsFunction('_reset')
setRNG = jsFunction('setRNG')
str2hex = jsFunction('str2hex')
hex2str = jsFunction('hex2str')

0 comments on commit 9b49c1f

Please sign in to comment.