Skip to content

Commit

Permalink
updating readMe
Browse files Browse the repository at this point in the history
  • Loading branch information
Drazail committed Jul 15, 2022
1 parent 0f0c150 commit d9b8e67
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 23 deletions.
50 changes: 30 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# react-native-hash
# react-hash

## Getting started

Expand Down Expand Up @@ -32,7 +32,7 @@ const hmacAlgorithm = CONSTANTS.HmacAlgorithms.HmacSHA512;
# Cross Platform API


if you are using something besides react, `JSHash` and `JSHmac` are pure javaScript implementations and should work in any JS enviroment.
if you are using something besides react, as `JSHash` and `JSHmac` are pure javaScript implementations they should work in any JS enviroment.
***


Expand All @@ -56,7 +56,7 @@ JSHmac(message: string, secret: string, algorithm: string): Promise<string>;
#### Example :

```javascript
import { JSHash, JSHmac, CONSTANTS } from "react-native-hash";
import { JSHash, JSHmac, CONSTANTS } from "react-hash";

JSHash("message", CONSTANTS.HashAlgorithms.sha256)
.then(hash => console.log(hash))
Expand All @@ -75,35 +75,45 @@ JSHmac("message", "SecretKey", CONSTANTS.HmacAlgorithms.HmacSHA256)

Following hooks are available:

`interface useHash {
hashed: string;
setMessage: (message: string) => void;
setAlgo: (algo: string) => void;
}`

`interface useHmac {
hashed: string;
setMessage: (message: string) => void;
setAlgo: (algo: string) => void;
setSecret: (secret: string) => void;
}`
```javaScript
export function useHash(
hmacAlgo?: string = "MD5",
initialMessage: ?string = "hello World",
): [
hashed: string,
setMessage: (message: string) => Promise<void>,
setAlgo: (algo: string) => Promise<void>
];
```
```javaScript
export function useHmac(
hmacAlgo?: string = "HmacMD5",
initialMessage: ?string = "hello World",
initialSecret: ?string = "SecretKey"
): [
hashed: string,
setMessage: (message: string) => Promise<void>,
setAlgo: (algo: string) => Promise<void>,
setSecret: (secret: string) => Promise<void>
];
```
## Usage
```javaScript
const {hashed: hashedMessage, setMessage: setHashMessage, setAlgo: setHashAlgo} = useHash();
const {hmaced: hmac, setMessage: setHmacMessage, setAlgo: setHmacAlgo, setSecret: setHmacSecret} = useHmac();
const [hashedMessage, setHashMessage, setHashAlgo] = useHash();
const [hmac, setHmacMessage, setHmacAlgo, setHmacSecret] = useHmac();
```
`hashed` and `hmaced` will update after a call to one of the setters is resolved.
`hashedMessage` and `hmac` will update after a call to one of the setters is resolved.
note that all the setter functions in these two hooks are async and will return a `promise`.
note that all the setter functions of these two hooks are async and will return a `promise`.
---
#### Credits
JSHash and JSHMac functions use some Open Source code snippets. You can find the source code of their open source projects along with license information below. We acknowledge and are grateful to these developers for their contributions to open source.
Some modules of this package use Open Source code snippets. You can find the source code of their open source projects along with license information below. We acknowledge and are grateful to these developers for their contributions to open source.
- Project: crypto-es https://github.com/entronad/crypto-es
Expand Down
4 changes: 2 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function JSHmac(
): Promise<string>;

export function useHash(
hmacAlgo?: string = "MD5",
hmacAlgo?: CONSTANTS.HashAlgorithms = CONSTANTS.HashAlgorithms.md5,
initialMessage: ?string = "hello World",
): [
hashed: string,
Expand All @@ -43,7 +43,7 @@ export function useHash(
];

export function useHmac(
hmacAlgo?: string = "HmacMD5",
hmacAlgo?: CONSTANTS.HmacAlgorithms = CONSTANTS.HmacAlgorithms.HmacMD5,
initialMessage: ?string = "hello World",
initialSecret: ?string = "SecretKey"
): [
Expand Down
31 changes: 30 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,36 @@
{
"name": "react-hash",
"title": "React Hash",
"description": "A hashing library for react",
"version": "0.1.0",
"private": true,
"private": false,
"repository": {
"type": "git",
"url": "git+https://github.com/Drazail/react-hash.git",
"baseUrl": "https://github.com/Drazail/react-hash"
},
"keywords": [
"react",
"react-hash",
"hash",
"MD2",
"MD5",
"SHA-1",
"SHA-224",
"SHA-256",
"SHA-384",
"SHA-512",
"android",
"keccak",
"hash-algorithm",
"hmac"
],
"author": {
"name": "Drazail",
"email": "[email protected]"
},
"deprecated": false,
"license": "Apache-2.0",
"peerDependencies": {
"react": "^18.2.0"
},
Expand Down

0 comments on commit d9b8e67

Please sign in to comment.