Skip to content
This repository was archived by the owner on Jul 21, 2023. It is now read-only.

Commit 6ebc408

Browse files
docs: update the docs
1 parent 08c5df5 commit 6ebc408

File tree

3 files changed

+122
-80
lines changed

3 files changed

+122
-80
lines changed

API.md

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# API
2+
3+
## `hmac`
4+
5+
Exposes an interface to the Keyed-Hash Message Authentication Code (HMAC) as defined in U.S. Federal Information Processing Standards Publication 198. An HMAC is a cryptographic hash that uses a key to sign a message. The receiver verifies the hash by recomputing it using the same key.
6+
7+
### `create(hash, secret, callback)`
8+
9+
- `hash: String`
10+
- `secret: Buffer`
11+
- `callback: Function`
12+
13+
#### `digest(data, callback)`
14+
15+
- `data: Buffer`
16+
- `callback: Function`
17+
18+
## `aes`
19+
Expoes an interface to AES encryption (formerly Rijndael), as defined in U.S. Federal Information Processing Standards Publication 197.
20+
21+
This uses `CTR` mode.
22+
23+
### `create(key, iv, callback)`
24+
25+
- `key: Buffer` The key, if length `16` then `AES 128` is used. For length `32`, `AES 256` is used.
26+
- `iv: Buffer` Must have length `16`.
27+
- `callback: Function`
28+
29+
#### `encrypt(data, callback)`
30+
31+
- `data: Buffer`
32+
- `callback: Function`
33+
34+
#### `encrypt(data, callback)`
35+
36+
- `data: Buffer`
37+
- `callback: Function`
38+
39+
40+
## `webcrypto`
41+
42+
Depending on the environment this is either an instance of [node-webcrypto-ossl](https://github.com/PeculiarVentures/node-webcrypto-ossl) or the result of `window.crypto`.
43+
44+
## `keys`
45+
46+
## `generateKeyPair(type, bits, callback)`
47+
48+
- `type: String`, only `'RSA'` is currently supported
49+
- `bits: Number` Minimum of 1024
50+
- `callback: Function`
51+
52+
Generates a keypair of the given type and bitsize.
53+
54+
## `generateEphemeralKeyPair(curve, callback)`
55+
56+
- `curve: String`, one of `'P-256'`, `'P-384'`, `'P-521'` is currently supported
57+
- `callback: Function`
58+
59+
Generates an ephemeral public key and returns a function that will compute the shared secret key.
60+
61+
Focuses only on ECDH now, but can be made more general in the future.
62+
63+
Calls back with an object of the form
64+
65+
```js
66+
{
67+
key: Buffer,
68+
genSharedKey: Function
69+
}
70+
```
71+
72+
## `keyStretcher(cipherType, hashType, secret, callback)`
73+
74+
- `cipherType: String`, one of `'AES-128'`, `'AES-256'`, `'Blowfish'`
75+
- `hashType: String`, one of `'SHA1'`, `SHA256`, `SHA512`
76+
- `secret: Buffer`
77+
- `callback: Function`
78+
79+
Generates a set of keys for each party by stretching the shared key.
80+
81+
Calls back with an object of the form
82+
```js
83+
{
84+
k1: {
85+
iv: Buffer,
86+
cipherKey: Buffer,
87+
macKey: Buffer
88+
},
89+
k2: {
90+
iv: Buffer,
91+
cipherKey: Buffer,
92+
macKey: Buffer
93+
}
94+
}
95+
```
96+
## `marshalPublicKey(key[, type], callback)`
97+
98+
- `key: crypto.rsa.RsaPublicKey`
99+
- `type: String`, only `'RSA'` is currently supported
100+
101+
Converts a public key object into a protobuf serialized public key.
102+
103+
## `unmarshalPublicKey(buf)`
104+
105+
- `buf: Buffer`
106+
107+
Converts a protobuf serialized public key into its representative object.
108+
109+
## `marshalPrivateKey(key[, type])`
110+
111+
- `key: crypto.rsa.RsaPrivateKey`
112+
- `type: String`, only `'RSA'` is currently supported
113+
114+
Converts a private key object into a protobuf serialized private key.
115+
116+
## `unmarshalPrivateKey(buf, callback)`
117+
118+
- `buf: Buffer`
119+
- `callback: Function`
120+
121+
Converts a protobuf serialized private key into its representative object.

README.md

Lines changed: 1 addition & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,6 @@ needed for libp2p. This is based on this [go implementation](https://github.com/
2121
- [Usage](#usage)
2222
- [Example](#example)
2323
- [API](#api)
24-
- [`generateKeyPair(type, bits, cb)`](#generatekeypairtype-bits-cb)
25-
- [`generateEphemeralKeyPair(curve)`](#generateephemeralkeypaircurve)
26-
- [`keyStretcher(cipherType, hashType, secret)`](#keystretcherciphertype-hashtype-secret)
27-
- [`marshalPublicKey(key[, type])`](#marshalpublickeykey-type)
28-
- [`unmarshalPublicKey(buf)`](#unmarshalpublickeybuf)
29-
- [`marshalPrivateKey(key[, type])`](#marshalprivatekeykey-type)
30-
- [`unmarshalPrivateKey(buf)`](#unmarshalprivatekeybuf)
3124
- [Contribute](#contribute)
3225
- [License](#license)
3326

@@ -50,78 +43,7 @@ crypto.generateKeyPair('RSA', 2048, (err, key) => {
5043

5144
## API
5245

53-
### `generateKeyPair(type, bits, cb)`
54-
55-
- `type: String`, only `'RSA'` is currently supported
56-
- `bits: Number`
57-
- `cb: Function`
58-
59-
Generates a keypair of the given type and bitsize.
60-
61-
### `generateEphemeralKeyPair(curve)`
62-
63-
- `curve: String`, one of `'P-256'`, `'P-384'`, `'P-521'` is currently supported
64-
65-
Generates an ephemeral public key and returns a function that will compute the shared secret key.
66-
67-
Focuses only on ECDH now, but can be made more general in the future.
68-
69-
Returns an object of the form
70-
```js
71-
{
72-
key: Buffer,
73-
genSharedKey: Function
74-
}
75-
```
76-
77-
### `keyStretcher(cipherType, hashType, secret)`
78-
79-
- `cipherType: String`, one of `'AES-128'`, `'AES-256'`, `'Blowfish'`
80-
- `hashType: String`, one of `'SHA1'`, `SHA256`, `SHA512`
81-
- `secret: Buffer`
82-
83-
Generates a set of keys for each party by stretching the shared key.
84-
85-
Returns an object of the form
86-
```js
87-
{
88-
k1: {
89-
iv: Buffer,
90-
cipherKey: Buffer,
91-
macKey: Buffer
92-
},
93-
k2: {
94-
iv: Buffer,
95-
cipherKey: Buffer,
96-
macKey: Buffer
97-
}
98-
}
99-
```
100-
### `marshalPublicKey(key[, type])`
101-
102-
- `key: crypto.rsa.RsaPublicKey`
103-
- `type: String`, only `'RSA'` is currently supported
104-
105-
Converts a public key object into a protobuf serialized public key.
106-
107-
### `unmarshalPublicKey(buf)`
108-
109-
- `buf: Buffer`
110-
111-
Converts a protobuf serialized public key into its representative object.
112-
113-
### `marshalPrivateKey(key[, type])`
114-
115-
- `key: crypto.rsa.RsaPrivateKey`
116-
- `type: String`, only `'RSA'` is currently supported
117-
118-
Converts a private key object into a protobuf serialized private key.
119-
120-
### `unmarshalPrivateKey(buf)`
121-
122-
- `buf: Buffer`
123-
124-
Converts a protobuf serialized private key into its representative object.
46+
See [API.md](API.md)
12547

12648
## Contribute
12749

src/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const c = require('./crypto')
66

77
exports.hmac = c.hmac
88
exports.aes = c.aes
9-
exports.rsa = c.rsa
109
exports.webcrypto = c.webcrypto
1110

1211
const keys = exports.keys = require('./keys')

0 commit comments

Comments
 (0)