Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #157 from PeculiarVentures/uodate-core
Browse files Browse the repository at this point in the history
Update core
  • Loading branch information
microshine committed Mar 23, 2020
2 parents 6c2e204 + cf529c4 commit 5bfa560
Show file tree
Hide file tree
Showing 88 changed files with 3,760 additions and 5,230 deletions.
6 changes: 4 additions & 2 deletions .npmignore
Expand Up @@ -8,8 +8,10 @@
build

test*.js
/test

# build
lib
/lib
ts*.json
**/*.map
**/*.map
rollup.config.js
2 changes: 0 additions & 2 deletions .travis.yml
@@ -1,6 +1,5 @@
language: node_js
node_js:
- "8"
- "10"
- "11"
- "12"
Expand Down Expand Up @@ -36,7 +35,6 @@ before_install:
- gcc --version

script:
- npm run build:source
- npm run coverage

after_success:
Expand Down
21 changes: 0 additions & 21 deletions .waiting.html

This file was deleted.

13 changes: 8 additions & 5 deletions README.md
Expand Up @@ -71,19 +71,22 @@ mocha
| AES-ECB <sub>2</sub> | X | | X | | X | X | |
| AES-GCM | X | | X | | X | X | |
| AES-KW | X | | X | | | X | |
| AES-CMAC | X | | X | X | | | |
| ECDSA | X | | X | X | | | |
| ECDH | X | | X | | | | X |
| HMAC | X | | X | X | | | |
| PBKDF2 | | | X | | | | X |
| DES-CBC | X | | X | | X | X | |
| DES-EDE3-CBC | X | | X | | X | X | |

<sub>2 ECB support is not defined by the WebCrypto specifications. Use of ECB in a safe way is hard, it was added for the purpose of enabling interoperability with an existing system. We recommend against its use unless needed for interoperability.</sub>

## Using

```javascript
var WebCrypto = require("node-webcrypto-ossl");
const { Crypto } = require("node-webcrypto-ossl");

var webcrypto = new WebCrypto();
const crypto = new Crypto();
```

## Elliptic curve secp256k1
Expand All @@ -97,9 +100,9 @@ var webcrypto = new WebCrypto();
To use KeyStorage you should init WebCrypto with `directory` option. If `directory` option is missing then `keyStorage` is `null`

```javascript
var WebCrypto = require("node-webcrypto-ossl");
const { Crypto } = require("node-webcrypto-ossl");

var webcrypto = new WebCrypto({
const crypto = new Crypto({
directory: "key_storage"
})
```
Expand All @@ -110,7 +113,7 @@ KeyStorage implements interface of [W3 Storage](https://developer.mozilla.org/en
var keyStorage = webcrypto.keyStorage;

// generating RSA key
webcrypto.subtle.generateKey({
crypto.subtle.generateKey({
name: "RSASSA-PKCS1-v1_5",
modulusLength: 1024,
publicExponent: new Uint8Array([1, 0, 1]),
Expand Down
50 changes: 50 additions & 0 deletions lib/crypto.ts
@@ -0,0 +1,50 @@
// Core
import * as crypto from "crypto";
import * as os from "os";
import * as path from "path";
import * as core from "webcrypto-core";

// Local
import { CryptoKeyStorage } from "./key_storage";
import { SubtleCrypto } from "./subtle";

export interface CryptoOptions {
directory?: string;
}

/**
* OpenSSL with WebCrypto Interface
*/
export class Crypto extends core.Crypto {

public keyStorage: CryptoKeyStorage;

public subtle = new SubtleCrypto();
/**
* Constructor
*/
constructor(options?: CryptoOptions) {
super();

this.keyStorage = new CryptoKeyStorage(this, options?.directory ?? path.join(os.homedir(), ".node-webcrypto-ossl"));
}

/**
* Generates cryptographically random values
* @param array Initialize array
*/
// Based on: https://github.com/KenanY/get-random-values
public getRandomValues<T extends ArrayBufferView>(array: T): T {
if (ArrayBuffer.isView(array)) {
if (array.byteLength > 65536) {
throw new core.OperationError(`Failed to execute 'getRandomValues' on 'Crypto': The ArrayBufferView's byte length (${array.byteLength}) exceeds the number of bytes of entropy available via this API (65536).`);
}
const bytes = crypto.randomBytes(array.byteLength);
(array as any).set(new (array.constructor as typeof Uint8Array)(bytes.buffer));
return array;
} else {
throw new core.OperationError(`Failed to execute 'getRandomValues' on 'Crypto': Expected ArrayBufferView for 'array' argument.`);
}
}

}
230 changes: 0 additions & 230 deletions lib/crypto/aes.ts

This file was deleted.

0 comments on commit 5bfa560

Please sign in to comment.