open-index/open-npm huggingface dataset:
npm package: @safeguard-apis/sg-string
Description: SafeGuard request data stringifier library.
Latest version: 0.0.18

# SafeGuard Device Auth Request Data Stringifier

SafeGuard request data stringifier library.


## Installation

Using npm:
```shell
npm install --save @safeguard-apis/sg-string
```

or using yarn:

```shell
yarn add @safeguard-apis/sg-string
```


## Usage

```
import { RequestDataStringifier } from "@safeguard-apis/sg-string"

const stringifier = new RequestDataStringifier()
const requestData = {
  httpVerb: HTTP_VERB,
  domain: DOMAIN
}
const stringifiedRequest = stringifier.stringify(requestData)
```

## Contributing

### Setup development environment

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

#### Prerequisites

* [Docker](https://docs.docker.com/engine/installation/)
* [Docker-compose](https://docs.docker.com/compose/install/)

#### Install npm dependencies
```bash
docker-compose run --rm --no-deps app npm install
```

Now your local machine is ready for development and testing.

### Running the tests

```bash
docker-compose run --rm --no-deps app npm test
```

### Deployment

Pushes a commit to master with the message Release 1.2.3, the npm-publish action will create a new tag v1.2.3 and publish the package to the npm registry.
npm package: @safeheron/crypto-bip32
Description: HDKey in js(embrace bip32-secp256k1, bip32-ed25519)
Author: Max
Latest version: 2.0.1

# crypto-bip32-js
# Installation

```shell
npm install @safeheron/crypto-bip32
```

# Import Library

```javascript
import {Secp256k1HDKey, Ed25519HDKey} from "@safeheron/crypto-bip32";
```

# Examples

- Bip32-Ed25519
 
```javascript
let hdkey = Ed25519HDKey.fromMasterSeedHex("0102030405060708090A0B0C0D0E0F10")
console.log('xprv : ', hdkey.xprv)
// => 'eprv423G5rKnJnGfkFkLNqjCetZ2AQdKMX1zM5TwmcnG3tKbuQzjjiu668ZC4zRtC4rXtQuz1e99cHr94DJ1augEmmXAbcCA1cVxkRgNtasdc1c'
console.log('xpub:  ', hdkey.xpub)
// => 'epub8YjJEGN2T9xLdin8GVPo4JD8jS9FWrCtvP4j48pZUA7zjuFWN7igGdB4F39s7umSx7CoiLF13yzPL8sUJWL14sPkVMdY9VHQjZVeVQSjWPZ')

let childHdKey = rootHDKey.derive('m/44/60/0')
console.log('childxprv : ', childHdKey.xprv)
// => 'eprv48jMzZSh71Sx5s2eDB5nGq8bEteV8xskhQZKsnxqBQu579KZW7wuCQ36urdzveVUA1ZRLkgNWve4YgRhY1yjq8PQpLaFyp2UMxooAHUmpJm'
console.log('child.xpub:  ', childHdKey.xpub)
// => 'epub8fRQ8yUwFP8cyL4S6pkNgEnhovARJJ4fGiA7AK18bghTwdaL8WmVNtey5uWHTYN8V63YFCD8L1xW9YCoKd6vwd7jtzLnBfeGqJ4De4Fe9wB')

```

- Bip32-Secp256k1

```javascript
let hdkey = Secp256k1HDKey.fromMasterSeedHex("000102030405060708090a0b0c0d0e0f")
console.log('xprv : ', hdkey.xprv)
// => 'xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi'
console.log('xpub:  ', hdkey.xpub)
// => 'xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8')

let childHdKey = rootHDKey.derive("m/0'/1/2'/2")
console.log('childxprv : ', childHdKey.xprv)
// => 'xprvA2JDeKCSNNZky6uBCviVfJSKyQ1mDYahRjijr5idH2WwLsEd4Hsb2Tyh8RfQMuPh7f7RtyzTtdrbdqqsunu5Mm3wDvUAKRHSC34sJ7in334'
console.log('child.xpub:  ', childHdKey.xpub)
// => 'xpub6FHa3pjLCk84BayeJxFW2SP4XRrFd1JYnxeLeU8EqN3vDfZmbqBqaGJAyiLjTAwm6ZLRQUMv1ZACTj37sR62cfN7fe5JnJ7dh8zL4fiyLHV')

```
npm package: @safeheron/crypto-paillier
Description: Paillier's crypto scheme
Author: Max
Latest version: 1.0.0

# crypto-paillier-js
# Installation
```shell
npm install @safeheron/crypto-paillier
```

Import the library in code:
```javascript
import * as assert from "assert"
import * as BN from "bn.js"
import {Rand} from '@safeheron/crypto-rand'
import {PailPrivKey, PailPubKey, createPailKeyPair} from "@safeheron/crypto-paillier"
```

# Examples

## Encrypt and Decrypt

```javascript
let m = await Rand.randomBNLt(pub.n)
let r = await Rand.randomBNLtGCD(pub.n)
let c = await pub.encryptWithR(m, r)
let expected = await priv.decrypt(c)
assert(m.eq(expected), "should equal")
```
npm package: @safeheron/crypto-rand
Description: Generate random number
Author: Max
Latest version: 1.0.0

# crypto-rand-js

# Installation
```shell
npm install @safeheron/crypto-rand
```
Import the library in code:
```javascript
import {Rand, Prime} from "@safeheron/crypto-rand"
```

# Config Your Random Function

If you don't set a custom function, the library will use the random function of built-in library of NodeJS default.
```javascript
Rand.config_randomBytesImp(
    function (byteSize) {
        const crypto = require("crypto")
        return crypto.randomBytes(byteSize);
    }
);

Rand.config_randomPrimeImp(
    async function (byteSize: number): Promise<BN> {
        while (true) {
            let r = await Rand.randomBN(byteSize)
            if (Prime.isProbablyPrime(r)) {
                return r
            }
        }
    },
);

Rand.config_randomSafePrimeImp(
    async function (byteSize: number): Promise<BN> {
        throw "no implementation for randomSafePrime"
    },
);
```

# Examples

- Get a random array of "n" bytes.
```javascript
let r = await randomBytes(n)
```

- Get a random BN between 0 and 2^n(not included).
```javascript
let r = await randomBytes(n)
```

- Get a random BN between 2^(n-1) and 2^n(not included).
```javascript
let r = await randomBNStrict(n)
```

- Get a random prime between 0 and 2^n(not included).
```javascript
let r = await randomPrime(n)
```

- Get a random prime between 2^(n-1) and 2^n(not included).
```javascript
let r = await randomPrimeStrict(n)
```

- Get a random prime between 0 and 2^256(not included).
```javascript
let r = await randomPrime256Bit(n)
```

- Get a random prime between 2^255 and 2^256(not included).
```javascript
let r = await randomPrimeStrict256Bit(n)
```

- Get a random BN less than 'n'
```javascript
let r = await randomBNLt(n)
```

- (Deprecated)Get a random BN that is less than 'n' and is co-prime with 'n'.
```javascript
let r = await randomBNLtGCD(n)
```

- Get a random BN that is less than 'n' and is co-prime with 'n'.
```javascript
let r = await randomBNLtCoPrime(n)
```
npm package: @safeheron/crypto-zkp
Description: Zero knowledge proof
Author: Max
Latest version: 1.0.0

# crypto-zkp-js
# Installation
```shell
npm install @safeheron/crypto-zkp
```

Import the library in code:
```javascript
import {Ed25519SchnorrProof, Secp256k1SchnorrProof, HomoElGamalWitness, HomoElGamalStatement, HEGProof} from "@safeheron/crypto-zkp"
```

# Examples

## Schnorr proof on curve Secp2561

- Without external random number.
```javascript
let sk = await Rand.randomBNLt(Secp256k1.n)
let proof = await Secp256k1SchnorrProof.prove(sk)
assert(proof.verify())
```


- With external random number.
```javascript
let sk = await Rand.randomBNLt(Secp256k1.n)
let r = await Rand.randomBN(32)
let proof = Secp256k1SchnorrProof.proveWithR(sk, r)
assert(proof.verify())
```

## Schnorr proof on curve Secp2561

- Without external random number.
```javascript
let sk = await Rand.randomBNLt(Ed25519.curve.n)
let proof = await Ed25519SchnorrProof.prove(sk)
assert(proof.verify())
```


- With external random number.
```javascript
let sk = await Rand.randomBNLt(Ed25519.curve.n)
let r = await Rand.randomBN(32)
let proof = Ed25519SchnorrProof.proveWithR(sk, r)
assert(proof.verify())
```

## Proof of Homo ElGamal

```javascript
let r = await Rand.randomBN(32);
let x = await Rand.randomBN(32);
let witness = new HomoElGamalWitness(r,x);
let G = Ed25519.g;
let h = await Rand.randomBN(32);
let H = G.mul(h);
let y = await Rand.randomBN(32);
let Y = G.mul(y);
let D = H.mul(witness.x).add(Y.mul(witness.r));
let E = G.mul(witness.r);

let delta = new HomoElGamalStatement(G,H,Y,D,E);

let proof = await HEGProof.prove(witness, delta)
assert(proof.verify(delta))
```