@protontech/openpgp 4.10.6 → 5.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. package/README.md +311 -239
  2. package/dist/lightweight/bn.interface.min.mjs +3 -0
  3. package/dist/lightweight/bn.interface.min.mjs.map +1 -0
  4. package/dist/lightweight/bn.interface.mjs +340 -0
  5. package/dist/lightweight/bn.min.mjs +3 -0
  6. package/dist/lightweight/bn.min.mjs.map +1 -0
  7. package/dist/lightweight/bn.mjs +3434 -0
  8. package/dist/lightweight/elliptic.min.mjs +3 -0
  9. package/dist/lightweight/elliptic.min.mjs.map +1 -0
  10. package/dist/lightweight/elliptic.mjs +4313 -0
  11. package/dist/lightweight/openpgp.min.mjs +3 -0
  12. package/dist/lightweight/openpgp.min.mjs.map +1 -0
  13. package/dist/lightweight/openpgp.mjs +31379 -0
  14. package/dist/lightweight/ponyfill.es6.min.mjs +3 -0
  15. package/dist/lightweight/ponyfill.es6.min.mjs.map +1 -0
  16. package/dist/lightweight/ponyfill.es6.mjs +3831 -0
  17. package/dist/lightweight/web-streams-adapter.min.mjs +17 -0
  18. package/dist/lightweight/web-streams-adapter.min.mjs.map +1 -0
  19. package/dist/lightweight/web-streams-adapter.mjs +561 -0
  20. package/dist/node/openpgp.js +43947 -0
  21. package/dist/node/openpgp.min.js +17 -0
  22. package/dist/node/openpgp.min.js.map +1 -0
  23. package/dist/node/openpgp.min.mjs +17 -0
  24. package/dist/node/openpgp.min.mjs.map +1 -0
  25. package/dist/node/openpgp.mjs +43884 -0
  26. package/dist/openpgp.js +41082 -41563
  27. package/dist/openpgp.min.js +17 -2
  28. package/dist/openpgp.min.js.map +1 -0
  29. package/dist/openpgp.min.mjs +17 -0
  30. package/dist/openpgp.min.mjs.map +1 -0
  31. package/dist/openpgp.mjs +43872 -0
  32. package/lightweight/package.json +5 -0
  33. package/openpgp.d.ts +890 -0
  34. package/package.json +63 -57
  35. package/dist/compat/openpgp.js +0 -61067
  36. package/dist/compat/openpgp.min.js +0 -2
  37. package/dist/compat/openpgp.worker.js +0 -173
  38. package/dist/compat/openpgp.worker.min.js +0 -2
  39. package/dist/lightweight/elliptic.min.js +0 -5
  40. package/dist/lightweight/openpgp.js +0 -40024
  41. package/dist/lightweight/openpgp.min.js +0 -2
  42. package/dist/lightweight/openpgp.worker.js +0 -173
  43. package/dist/lightweight/openpgp.worker.min.js +0 -2
  44. package/dist/openpgp.worker.js +0 -173
  45. package/dist/openpgp.worker.min.js +0 -2
  46. package/src/cleartext.js +0 -220
  47. package/src/config/config.js +0 -224
  48. package/src/config/index.js +0 -7
  49. package/src/config/localStorage.js +0 -35
  50. package/src/crypto/aes_kw.js +0 -153
  51. package/src/crypto/cfb.js +0 -169
  52. package/src/crypto/cipher/aes.js +0 -27
  53. package/src/crypto/cipher/blowfish.js +0 -398
  54. package/src/crypto/cipher/cast5.js +0 -610
  55. package/src/crypto/cipher/des.js +0 -476
  56. package/src/crypto/cipher/index.js +0 -91
  57. package/src/crypto/cipher/twofish.js +0 -346
  58. package/src/crypto/cmac.js +0 -98
  59. package/src/crypto/crypto.js +0 -394
  60. package/src/crypto/eax.js +0 -172
  61. package/src/crypto/gcm.js +0 -141
  62. package/src/crypto/hash/index.js +0 -163
  63. package/src/crypto/hash/md5.js +0 -205
  64. package/src/crypto/index.js +0 -57
  65. package/src/crypto/ocb.js +0 -274
  66. package/src/crypto/pkcs1.js +0 -170
  67. package/src/crypto/pkcs5.js +0 -55
  68. package/src/crypto/public_key/dsa.js +0 -188
  69. package/src/crypto/public_key/elgamal.js +0 -137
  70. package/src/crypto/public_key/elliptic/curves.js +0 -385
  71. package/src/crypto/public_key/elliptic/ecdh.js +0 -414
  72. package/src/crypto/public_key/elliptic/ecdsa.js +0 -348
  73. package/src/crypto/public_key/elliptic/eddsa.js +0 -119
  74. package/src/crypto/public_key/elliptic/index.js +0 -34
  75. package/src/crypto/public_key/elliptic/indutnyKey.js +0 -85
  76. package/src/crypto/public_key/index.js +0 -28
  77. package/src/crypto/public_key/prime.js +0 -275
  78. package/src/crypto/public_key/rsa.js +0 -597
  79. package/src/crypto/random.js +0 -145
  80. package/src/crypto/signature.js +0 -137
  81. package/src/encoding/armor.js +0 -433
  82. package/src/encoding/base64.js +0 -96
  83. package/src/enums.js +0 -493
  84. package/src/hkp.js +0 -89
  85. package/src/index.js +0 -161
  86. package/src/key/factory.js +0 -326
  87. package/src/key/helper.js +0 -363
  88. package/src/key/index.js +0 -32
  89. package/src/key/key.js +0 -890
  90. package/src/key/subkey.js +0 -187
  91. package/src/key/user.js +0 -230
  92. package/src/keyring/index.js +0 -12
  93. package/src/keyring/keyring.js +0 -229
  94. package/src/keyring/localstore.js +0 -119
  95. package/src/lightweight_helper.js +0 -26
  96. package/src/message.js +0 -825
  97. package/src/openpgp.js +0 -717
  98. package/src/packet/all_packets.js +0 -116
  99. package/src/packet/clone.js +0 -189
  100. package/src/packet/compressed.js +0 -194
  101. package/src/packet/index.js +0 -20
  102. package/src/packet/literal.js +0 -168
  103. package/src/packet/marker.js +0 -62
  104. package/src/packet/one_pass_signature.js +0 -156
  105. package/src/packet/packet.js +0 -300
  106. package/src/packet/packetlist.js +0 -232
  107. package/src/packet/public_key.js +0 -280
  108. package/src/packet/public_key_encrypted_session_key.js +0 -156
  109. package/src/packet/public_subkey.js +0 -44
  110. package/src/packet/secret_key.js +0 -448
  111. package/src/packet/secret_subkey.js +0 -41
  112. package/src/packet/signature.js +0 -782
  113. package/src/packet/sym_encrypted_aead_protected.js +0 -189
  114. package/src/packet/sym_encrypted_integrity_protected.js +0 -139
  115. package/src/packet/sym_encrypted_session_key.js +0 -204
  116. package/src/packet/symmetrically_encrypted.js +0 -118
  117. package/src/packet/trust.js +0 -35
  118. package/src/packet/user_attribute.js +0 -94
  119. package/src/packet/userid.js +0 -87
  120. package/src/polyfills.js +0 -64
  121. package/src/signature.js +0 -73
  122. package/src/type/ecdh_symkey.js +0 -69
  123. package/src/type/kdf_params.js +0 -114
  124. package/src/type/keyid.js +0 -110
  125. package/src/type/mpi.js +0 -138
  126. package/src/type/oid.js +0 -110
  127. package/src/type/s2k.js +0 -203
  128. package/src/util.js +0 -836
  129. package/src/wkd.js +0 -88
  130. package/src/worker/async_proxy.js +0 -190
  131. package/src/worker/worker.js +0 -167
  132. package/test/crypto/aes_kw.js +0 -57
  133. package/test/crypto/cipher/aes.js +0 -86
  134. package/test/crypto/cipher/blowfish.js +0 -58
  135. package/test/crypto/cipher/cast5.js +0 -25
  136. package/test/crypto/cipher/des.js +0 -143
  137. package/test/crypto/cipher/index.js +0 -7
  138. package/test/crypto/cipher/twofish.js +0 -71
  139. package/test/crypto/crypto.js +0 -383
  140. package/test/crypto/eax.js +0 -150
  141. package/test/crypto/ecdh.js +0 -359
  142. package/test/crypto/elliptic.js +0 -251
  143. package/test/crypto/elliptic_data.js +0 -102
  144. package/test/crypto/hash/index.js +0 -5
  145. package/test/crypto/hash/md5.js +0 -16
  146. package/test/crypto/hash/ripemd.js +0 -14
  147. package/test/crypto/hash/sha.js +0 -20
  148. package/test/crypto/index.js +0 -14
  149. package/test/crypto/ocb.js +0 -183
  150. package/test/crypto/pkcs5.js +0 -39
  151. package/test/crypto/random.js +0 -79
  152. package/test/crypto/rsa.js +0 -180
  153. package/test/crypto/validate.js +0 -387
  154. package/test/general/armor.js +0 -408
  155. package/test/general/brainpool.js +0 -360
  156. package/test/general/decompression.js +0 -60
  157. package/test/general/ecc_nist.js +0 -115
  158. package/test/general/ecc_secp256k1.js +0 -242
  159. package/test/general/forwarding.js +0 -43
  160. package/test/general/hkp.js +0 -165
  161. package/test/general/index.js +0 -20
  162. package/test/general/key.js +0 -3402
  163. package/test/general/keyring.js +0 -336
  164. package/test/general/oid.js +0 -39
  165. package/test/general/openpgp.js +0 -2542
  166. package/test/general/packet.js +0 -937
  167. package/test/general/signature.js +0 -1665
  168. package/test/general/streaming.js +0 -944
  169. package/test/general/testInputs.js +0 -18
  170. package/test/general/util.js +0 -183
  171. package/test/general/wkd.js +0 -48
  172. package/test/general/x25519.js +0 -556
  173. package/test/unittests.js +0 -64
package/README.md CHANGED
@@ -1,28 +1,26 @@
1
- OpenPGP.js [![Build Status](https://travis-ci.org/openpgpjs/openpgpjs.svg?branch=master)](https://travis-ci.org/openpgpjs/openpgpjs) [![BrowserStack Status](https://automate.browserstack.com/badge.svg?badge_key=eEkxVVM1TytwOGJNWEdnTjk4Y0VNUUNyR3pXcEtJUGRXOVFBRjVNT1JpUT0tLTZYUlZaMWdtQWs4Z0ROS3grRXc2bFE9PQ==--4a9cac0d6ea009d81aff66de0dbb239edd1aef3c)](https://automate.browserstack.com/public-build/eEkxVVM1TytwOGJNWEdnTjk4Y0VNUUNyR3pXcEtJUGRXOVFBRjVNT1JpUT0tLTZYUlZaMWdtQWs4Z0ROS3grRXc2bFE9PQ==--4a9cac0d6ea009d81aff66de0dbb239edd1aef3c) [![Join the chat on Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/openpgpjs/openpgpjs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
1
+ OpenPGP.js [![BrowserStack Status](https://automate.browserstack.com/badge.svg?badge_key=N1l2eHFOanVBMU9wYWxJM3ZnWERnc1lidkt5UkRqa3BralV3SWVhOGpGTT0tLVljSjE4Z3dzVmdiQjl6RWgxb2c3T2c9PQ==--5864052cd523f751b6b907d547ac9c4c5f88c8a3)](https://automate.browserstack.com/public-build/N1l2eHFOanVBMU9wYWxJM3ZnWERnc1lidkt5UkRqa3BralV3SWVhOGpGTT0tLVljSjE4Z3dzVmdiQjl6RWgxb2c3T2c9PQ==--5864052cd523f751b6b907d547ac9c4c5f88c8a3) [![Join the chat on Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/openpgpjs/openpgpjs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
2
2
  ==========
3
3
 
4
- [OpenPGP.js](https://openpgpjs.org/) is a JavaScript implementation of the OpenPGP protocol. This is defined in [RFC 4880](https://tools.ietf.org/html/rfc4880).
4
+ [OpenPGP.js](https://openpgpjs.org/) is a JavaScript implementation of the OpenPGP protocol. It implements [RFC4880](https://tools.ietf.org/html/rfc4880) and parts of [RFC4880bis](https://tools.ietf.org/html/draft-ietf-openpgp-rfc4880bis-10).
5
5
 
6
- <!-- markdown-toc start - Don't edit this section. Run M-x markdown-toc-generate-toc again -->
7
6
  **Table of Contents**
8
7
 
9
8
  - [OpenPGP.js](#openpgpjs)
10
9
  - [Platform Support](#platform-support)
11
10
  - [Performance](#performance)
12
11
  - [Getting started](#getting-started)
13
- - [Npm](#npm)
14
- - [Bower](#bower)
12
+ - [Node.js](#nodejs)
13
+ - [Deno (experimental)](#deno-experimental)
14
+ - [Browser (webpack)](#browser-webpack)
15
+ - [Browser (plain files)](#browser-plain-files)
15
16
  - [Examples](#examples)
16
- - [Set up](#set-up)
17
17
  - [Encrypt and decrypt *Uint8Array* data with a password](#encrypt-and-decrypt-uint8array-data-with-a-password)
18
18
  - [Encrypt and decrypt *String* data with PGP keys](#encrypt-and-decrypt-string-data-with-pgp-keys)
19
- - [Encrypt with compression](#encrypt-with-compression)
19
+ - [Encrypt symmetrically with compression](#encrypt-symmetrically-with-compression)
20
20
  - [Streaming encrypt *Uint8Array* data with a password](#streaming-encrypt-uint8array-data-with-a-password)
21
21
  - [Streaming encrypt and decrypt *String* data with PGP keys](#streaming-encrypt-and-decrypt-string-data-with-pgp-keys)
22
22
  - [Generate new key pair](#generate-new-key-pair)
23
23
  - [Revoke a key](#revoke-a-key)
24
- - [Lookup public key on HKP server](#lookup-public-key-on-hkp-server)
25
- - [Upload public key to HKP server](#upload-public-key-to-hkp-server)
26
24
  - [Sign and verify cleartext messages](#sign-and-verify-cleartext-messages)
27
25
  - [Create and verify *detached* signatures](#create-and-verify-detached-signatures)
28
26
  - [Streaming sign and verify *Uint8Array* data](#streaming-sign-and-verify-uint8array-data)
@@ -32,17 +30,12 @@ OpenPGP.js [![Build Status](https://travis-ci.org/openpgpjs/openpgpjs.svg?branch
32
30
  - [Development](#development)
33
31
  - [How do I get involved?](#how-do-i-get-involved)
34
32
  - [License](#license)
35
- - [Resources](#resources)
36
-
37
- <!-- markdown-toc end -->
38
33
 
39
34
  ### Platform Support
40
35
 
41
- * The `dist/openpgp.min.js` bundle works well with recent versions of Chrome, Firefox, Safari and Edge. It also works in Node.js 8+.
42
-
43
- * The `dist/compat/openpgp.min.js` bundle also works with Internet Explorer 11 and old versions of Safari. Please note that this bundle overwrites the global `Promise` with a polyfill version even in some cases where it already exists, which may cause issues. It also adds some built-in prototype functions if they don't exist, such as `Array.prototype.includes`.
36
+ * The `dist/openpgp.min.js` bundle works well with recent versions of Chrome, Firefox, Safari and Edge.
44
37
 
45
- * If you wish, you could even load one or the other depending on which browser the user is using. However, if you're using the Web Worker, keep in mind that you also need to pass `{ path: 'compat/openpgp.worker.min.js' }` to `initWorker` whenever you load `compat/openpgp.min.js`.
38
+ * The `dist/node/openpgp.min.js` bundle works well in Node.js. It is used by default when you `require('openpgp')` in Node.js.
46
39
 
47
40
  * Currently, Chrome, Safari and Edge have partial implementations of the
48
41
  [Streams specification](https://streams.spec.whatwg.org/), and Firefox
@@ -60,119 +53,150 @@ library to convert back and forth between them.
60
53
 
61
54
  ### Performance
62
55
 
63
- * Version 3.0.0 of the library introduces support for public-key cryptography using [elliptic curves](https://wiki.gnupg.org/ECC). We use native implementations on browsers and Node.js when available or [Elliptic](https://github.com/indutny/elliptic) otherwise. Elliptic curve cryptography provides stronger security per bits of key, which allows for much faster operations. Currently the following curves are supported (* = when available):
56
+ * Version 3.0.0 of the library introduces support for public-key cryptography using [elliptic curves](https://wiki.gnupg.org/ECC). We use native implementations on browsers and Node.js when available. Elliptic curve cryptography provides stronger security per bits of key, which allows for much faster operations. Currently the following curves are supported:
64
57
 
58
+ | Curve | Encryption | Signature | NodeCrypto | WebCrypto | Constant-Time |
59
+ |:---------------:|:----------:|:---------:|:----------:|:---------:|:-----------------:|
60
+ | curve25519 | ECDH | N/A | No | No | Algorithmically** |
61
+ | ed25519 | N/A | EdDSA | No | No | Algorithmically** |
62
+ | p256 | ECDH | ECDSA | Yes* | Yes* | If native*** |
63
+ | p384 | ECDH | ECDSA | Yes* | Yes* | If native*** |
64
+ | p521 | ECDH | ECDSA | Yes* | Yes* | If native*** |
65
+ | brainpoolP256r1 | ECDH | ECDSA | Yes* | No | If native*** |
66
+ | brainpoolP384r1 | ECDH | ECDSA | Yes* | No | If native*** |
67
+ | brainpoolP512r1 | ECDH | ECDSA | Yes* | No | If native*** |
68
+ | secp256k1 | ECDH | ECDSA | Yes* | No | If native*** |
65
69
 
66
- | Curve | Encryption | Signature | Elliptic | NodeCrypto | WebCrypto |
67
- |:--------------- |:----------:|:---------:|:--------:|:----------:|:---------:|
68
- | p256 | ECDH | ECDSA | Yes | Yes* | Yes* |
69
- | p384 | ECDH | ECDSA | Yes | Yes* | Yes* |
70
- | p521 | ECDH | ECDSA | Yes | Yes* | Yes* |
71
- | secp256k1 | ECDH | ECDSA | Yes | Yes* | No |
72
- | brainpoolP256r1 | ECDH | ECDSA | Yes | Yes* | No |
73
- | brainpoolP384r1 | ECDH | ECDSA | Yes | Yes* | No |
74
- | brainpoolP512r1 | ECDH | ECDSA | Yes | Yes* | No |
75
- | curve25519 | ECDH | N/A | Yes | No | No |
76
- | ed25519 | N/A | EdDSA | Yes | No | No |
70
+ \* when available
71
+ \** the curve25519 and ed25519 implementations are algorithmically constant-time, but may not be constant-time after optimizations of the JavaScript compiler
72
+ \*** these curves are only constant-time if the underlying native implementation is available and constant-time
77
73
 
78
74
  * Version 2.x of the library has been built from the ground up with Uint8Arrays. This allows for much better performance and memory usage than strings.
79
75
 
80
- * If the user's browser supports [native WebCrypto](https://caniuse.com/#feat=cryptography) via the `window.crypto.subtle` API, this will be used. Under Node.js the native [crypto module](https://nodejs.org/api/crypto.html#crypto_crypto) is used. This can be deactivated by setting `openpgp.config.use_native = false`.
76
+ * If the user's browser supports [native WebCrypto](https://caniuse.com/#feat=cryptography) via the `window.crypto.subtle` API, this will be used. Under Node.js the native [crypto module](https://nodejs.org/api/crypto.html#crypto_crypto) is used.
81
77
 
82
- * The library implements the [IETF proposal](https://tools.ietf.org/html/draft-ietf-openpgp-rfc4880bis-07) for authenticated encryption using native AES-EAX, OCB, or GCM. This makes symmetric encryption up to 30x faster on supported platforms. Since the specification has not been finalized and other OpenPGP implementations haven't adopted it yet, the feature is currently behind a flag. **Note: activating this setting can break compatibility with other OpenPGP implementations, and also with future versions of OpenPGP.js. Don't use it with messages you want to store on disk or in a database.** You can enable it by setting `openpgp.config.aead_protect = true`.
78
+ * The library implements the [IETF proposal](https://tools.ietf.org/html/draft-ietf-openpgp-rfc4880bis-10) for authenticated encryption using native AES-EAX, OCB, or GCM. This makes symmetric encryption up to 30x faster on supported platforms. Since the specification has not been finalized and other OpenPGP implementations haven't adopted it yet, the feature is currently behind a flag. **Note: activating this setting can break compatibility with other OpenPGP implementations, and also with future versions of OpenPGP.js. Don't use it with messages you want to store on disk or in a database.** You can enable it by setting `openpgp.config.aeadProtect = true`.
83
79
 
84
80
  You can change the AEAD mode by setting one of the following options:
85
81
 
86
82
  ```
87
- openpgp.config.aead_mode = openpgp.enums.aead.eax // Default, native
88
- openpgp.config.aead_mode = openpgp.enums.aead.ocb // Non-native
89
- openpgp.config.aead_mode = openpgp.enums.aead.experimental_gcm // **Non-standard**, fastest
83
+ openpgp.config.preferredAEADAlgorithm = openpgp.enums.aead.eax // Default, native
84
+ openpgp.config.preferredAEADAlgorithm = openpgp.enums.aead.ocb // Non-native
85
+ openpgp.config.preferredAEADAlgorithm = openpgp.enums.aead.experimentalGCM // **Non-standard**, fastest
90
86
  ```
91
87
 
92
- * For environments that don't provide native crypto, the library falls back to [asm.js](https://caniuse.com/#feat=asmjs) implementations of AES, SHA-1, and SHA-256. We use [Rusha](https://github.com/srijs/rusha) and [asmCrypto Lite](https://github.com/openpgpjs/asmcrypto-lite) (a minimal subset of asmCrypto.js built specifically for OpenPGP.js).
88
+ * For environments that don't provide native crypto, the library falls back to [asm.js](https://caniuse.com/#feat=asmjs) implementations of AES, SHA-1, and SHA-256.
93
89
 
94
90
 
95
91
  ### Getting started
96
92
 
97
- #### Npm
93
+ #### Node.js
98
94
 
99
- npm install --save openpgp
95
+ Install OpenPGP.js using npm and save it in your dependencies:
100
96
 
101
- #### Bower
102
-
103
- bower install --save openpgp
97
+ ```sh
98
+ npm install --save openpgp
99
+ ```
104
100
 
105
- Or just fetch a minified build under [dist](https://github.com/openpgpjs/openpgpjs/tree/master/dist).
101
+ And import it as a CommonJS module:
106
102
 
103
+ ```js
104
+ const openpgp = require('openpgp');
105
+ ```
107
106
 
108
- ### Examples
107
+ Or as an ES6 module, from an .mjs file:
109
108
 
110
- Here are some examples of how to use the v2.x+ API. For more elaborate examples and working code, please check out the [public API unit tests](https://github.com/openpgpjs/openpgpjs/blob/master/test/general/openpgp.js). If you're upgrading from v1.x it might help to check out the [documentation](https://github.com/openpgpjs/openpgpjs#documentation).
109
+ ```js
110
+ import * as openpgp from 'openpgp';
111
+ ```
111
112
 
112
- #### Set up
113
+ #### Deno (experimental)
113
114
 
114
- ##### Node.js
115
+ Import as an ES6 module, using /dist/openpgp.mjs.
115
116
 
116
117
  ```js
117
- const openpgp = require('openpgp');
118
+ import * as openpgp from './openpgpjs/dist/openpgp.mjs';
118
119
  ```
119
120
 
120
- ##### Browser
121
+ #### Browser (webpack)
121
122
 
122
- Copy `dist/openpgp.min.js` or `dist/compat/openpgp.min.js` (depending on the browser support you need, see [Platform Support](#platform-support)) to your project folder, and load it in a script tag:
123
+ Install OpenPGP.js using npm and save it in your devDependencies:
123
124
 
124
- ```html
125
- <script src="openpgp.min.js"></script>
125
+ ```sh
126
+ npm install --save-dev openpgp
126
127
  ```
127
128
 
128
- If you want to use the built-in Web Worker, to offload cryptographic operations off the main thread:
129
+ And import it as an ES6 module:
129
130
 
130
131
  ```js
131
- await openpgp.initWorker({ path: 'openpgp.worker.js' }); // set the relative web worker path
132
+ import * as openpgp from 'openpgp';
132
133
  ```
133
134
 
134
- On logout, be sure to destroy the worker again, to clear private keys from memory:
135
+ You can also only import the functions you need, as follows:
135
136
 
136
137
  ```js
137
- await openpgp.destroyWorker();
138
+ import { readMessage, decrypt } from 'openpgp';
138
139
  ```
139
140
 
140
- Alternatively, you can also implement a Web Worker in your application and load OpenPGP.js from there. This can be more performant if you store or fetch keys and messages directly inside the Worker, so that they don't have to be `postMessage`d there.
141
-
142
- If you want to use the lightweight build (which is smaller, and lazily loads non-default curves on demand), copy `dist/lightweight/openpgp.min.js` and `dist/lightweight/elliptic.min.js`, load the former in a script tag, and point `openpgp.config.indutny_elliptic_path` to the latter:
141
+ Or, if you want to use the lightweight build (which is smaller, and lazily loads non-default curves on demand):
143
142
 
144
- ```html
145
- <script src="lightweight/openpgp.min.js"></script>
146
- <script>
147
- openpgp.config.indutny_elliptic_path = 'lightweight/elliptic.min.js';
148
- </script>
143
+ ```js
144
+ import * as openpgp from 'openpgp/lightweight';
149
145
  ```
150
146
 
151
- To test whether the lazy loading works, try:
147
+ To test whether the lazy loading works, try to generate a key with a non-standard curve:
152
148
 
153
149
  ```js
154
- await openpgp.generateKey({ curve: 'brainpoolP512r1', userIds: [{ name: 'Test', email: 'test@test.com' }] });
150
+ import { generateKey } from 'openpgp/lightweight';
151
+ await generateKey({ curve: 'brainpoolP512r1', userIDs: [{ name: 'Test', email: 'test@test.com' }] });
155
152
  ```
156
153
 
157
154
  For more examples of how to generate a key, see [Generate new key pair](#generate-new-key-pair). It is recommended to use `curve25519` instead of `brainpoolP512r1` by default.
158
155
 
156
+
157
+ #### Browser (plain files)
158
+
159
+ Grab `openpgp.min.js` from [unpkg.com/openpgp/dist](https://unpkg.com/openpgp/dist/), and load it in a script tag:
160
+
161
+ ```html
162
+ <script src="openpgp.min.js"></script>
163
+ ```
164
+
165
+ Or, to load OpenPGP.js as an ES6 module, grab `openpgp.min.mjs` from [unpkg.com/openpgp/dist](https://unpkg.com/openpgp/dist/), and import it as follows:
166
+
167
+ ```html
168
+ <script type="module">
169
+ import * as openpgp from './openpgp.min.mjs';
170
+ </script>
171
+ ```
172
+
173
+ To offload cryptographic operations off the main thread, you can implement a Web Worker in your application and load OpenPGP.js from there. For an example Worker implementation, see `test/worker/worker_example.js`.
174
+
175
+ ### Examples
176
+
177
+ Here are some examples of how to use OpenPGP.js v5. For more elaborate examples and working code, please check out the [public API unit tests](https://github.com/openpgpjs/openpgpjs/blob/main/test/general/openpgp.js). If you're upgrading from v4 it might help to check out the [changelog](https://github.com/openpgpjs/openpgpjs/wiki/V5-Changelog) and [documentation](https://github.com/openpgpjs/openpgpjs#documentation).
178
+
159
179
  #### Encrypt and decrypt *Uint8Array* data with a password
160
180
 
161
- Encryption will use the algorithm specified in config.encryption_cipher (defaults to aes256), and decryption will use the algorithm used for encryption.
181
+ Encryption will use the algorithm specified in config.preferredSymmetricAlgorithm (defaults to aes256), and decryption will use the algorithm used for encryption.
162
182
 
163
183
  ```js
164
184
  (async () => {
165
- const { message } = await openpgp.encrypt({
166
- message: openpgp.message.fromBinary(new Uint8Array([0x01, 0x01, 0x01])), // input as Message object
167
- passwords: ['secret stuff'], // multiple passwords possible
168
- armor: false // don't ASCII armor (for Uint8Array output)
185
+ const message = await openpgp.createMessage({ binary: new Uint8Array([0x01, 0x01, 0x01]) });
186
+ const encrypted = await openpgp.encrypt({
187
+ message, // input as Message object
188
+ passwords: ['secret stuff'], // multiple passwords possible
189
+ format: 'binary' // don't ASCII armor (for Uint8Array output)
169
190
  });
170
- const encrypted = message.packets.write(); // get raw encrypted packets as Uint8Array
191
+ console.log(encrypted); // Uint8Array
171
192
 
193
+ const encryptedMessage = await openpgp.readMessage({
194
+ binaryMessage: encrypted // parse encrypted bytes
195
+ });
172
196
  const { data: decrypted } = await openpgp.decrypt({
173
- message: await openpgp.message.read(encrypted), // parse encrypted bytes
174
- passwords: ['secret stuff'], // decrypt with password
175
- format: 'binary' // output as Uint8Array
197
+ message: encryptedMessage,
198
+ passwords: ['secret stuff'], // decrypt with password
199
+ format: 'binary' // output as Uint8Array
176
200
  });
177
201
  console.log(decrypted); // Uint8Array([0x01, 0x01, 0x01])
178
202
  })();
@@ -180,14 +204,12 @@ Encryption will use the algorithm specified in config.encryption_cipher (default
180
204
 
181
205
  #### Encrypt and decrypt *String* data with PGP keys
182
206
 
183
- Encryption will use the algorithm preferred by the public key (defaults to aes256 for keys generated in OpenPGP.js), and decryption will use the algorithm used for encryption.
207
+ Encryption will use the algorithm preferred by the public (encryption) key (defaults to aes256 for keys generated in OpenPGP.js), and decryption will use the algorithm used for encryption.
184
208
 
185
209
  ```js
186
210
  const openpgp = require('openpgp'); // use as CommonJS, AMD, ES6 module or via window.openpgp
187
211
 
188
212
  (async () => {
189
- await openpgp.initWorker({ path: 'openpgp.worker.js' }); // set the relative web worker path
190
-
191
213
  // put keys in backtick (``) to avoid errors caused by spaces or tabs
192
214
  const publicKeyArmored = `-----BEGIN PGP PUBLIC KEY BLOCK-----
193
215
  ...
@@ -197,25 +219,40 @@ const openpgp = require('openpgp'); // use as CommonJS, AMD, ES6 module or via w
197
219
  -----END PGP PRIVATE KEY BLOCK-----`; // encrypted private key
198
220
  const passphrase = `yourPassphrase`; // what the private key is encrypted with
199
221
 
200
- const { keys: [privateKey] } = await openpgp.key.readArmored(privateKeyArmored);
201
- await privateKey.decrypt(passphrase);
222
+ const publicKey = await openpgp.readKey({ armoredKey: publicKeyArmored });
223
+
224
+ const privateKey = await openpgp.decryptKey({
225
+ privateKey: await openpgp.readPrivateKey({ armoredKey: privateKeyArmored }),
226
+ passphrase
227
+ });
202
228
 
203
- const { data: encrypted } = await openpgp.encrypt({
204
- message: openpgp.message.fromText('Hello, World!'), // input as Message object
205
- publicKeys: (await openpgp.key.readArmored(publicKeyArmored)).keys, // for encryption
206
- privateKeys: [privateKey] // for signing (optional)
229
+ const encrypted = await openpgp.encrypt({
230
+ message: await openpgp.createMessage({ text: 'Hello, World!' }), // input as Message object
231
+ encryptionKeys: publicKey,
232
+ signingKeys: privateKey // optional
207
233
  });
208
234
  console.log(encrypted); // '-----BEGIN PGP MESSAGE ... END PGP MESSAGE-----'
209
- const { data: decrypted } = await openpgp.decrypt({
210
- message: await openpgp.message.readArmored(encrypted), // parse armored message
211
- publicKeys: (await openpgp.key.readArmored(publicKeyArmored)).keys, // for verification (optional)
212
- privateKeys: [privateKey] // for decryption
235
+
236
+ const message = await openpgp.readMessage({
237
+ armoredMessage: encrypted // parse armored message
238
+ });
239
+ const { data: decrypted, signatures } = await openpgp.decrypt({
240
+ message,
241
+ verificationKeys: publicKey, // optional
242
+ decryptionKeys: privateKey
213
243
  });
214
244
  console.log(decrypted); // 'Hello, World!'
245
+ // check signature validity (signed messages only)
246
+ try {
247
+ await signatures[0].verified; // throws on invalid signature
248
+ console.log('Signature is valid');
249
+ } catch (e) {
250
+ throw new Error('Signature could not be verified: ' + e.message);
251
+ }
215
252
  })();
216
253
  ```
217
254
 
218
- Encrypt with multiple public keys:
255
+ Encrypt to multiple public keys:
219
256
 
220
257
  ```js
221
258
  (async () => {
@@ -231,49 +268,88 @@ Encrypt with multiple public keys:
231
268
  ...
232
269
  -----END PGP PRIVATE KEY BLOCK-----`; // encrypted private key
233
270
  const passphrase = `yourPassphrase`; // what the private key is encrypted with
234
- const message = 'Hello, World!';
271
+ const plaintext = 'Hello, World!';
235
272
 
236
- const { keys: [privateKey] } = await openpgp.key.readArmored(privateKeyArmored);
237
- await privateKey.decrypt(passphrase)
273
+ const publicKeys = await Promise.all(publicKeysArmored.map(armoredKey => openpgp.readKey({ armoredKey })));
238
274
 
239
- const publicKeys = await Promise.all(publicKeysArmored.map(async (key) => {
240
- return (await openpgp.key.readArmored(key)).keys[0];
241
- }));
275
+ const privateKey = await openpgp.decryptKey({
276
+ privateKey: await openpgp.readKey({ armoredKey: privateKeyArmored }),
277
+ passphrase
278
+ });
242
279
 
243
- const { data: encrypted } = await openpgp.encrypt({
244
- message: openpgp.message.fromText(message), // input as Message object
245
- publicKeys, // for encryption
246
- privateKeys: [privateKey] // for signing (optional)
280
+ const message = await openpgp.createMessage({ text: plaintext });
281
+ const encrypted = await openpgp.encrypt({
282
+ message, // input as Message object
283
+ encryptionKeys: publicKeys,
284
+ signingKeys: privateKey // optional
247
285
  });
248
286
  console.log(encrypted); // '-----BEGIN PGP MESSAGE ... END PGP MESSAGE-----'
249
287
  })();
250
288
  ```
251
289
 
252
- #### Encrypt with compression
290
+ If you expect an encrypted message to be signed with one of the public keys you have, and do not want to trust the decrypted data otherwise, you can pass the decryption option `expectSigned = true`, so that the decryption operation will fail if no valid signature is found:
291
+ ```js
292
+ (async () => {
293
+ // put keys in backtick (``) to avoid errors caused by spaces or tabs
294
+ const publicKeyArmored = `-----BEGIN PGP PUBLIC KEY BLOCK-----
295
+ ...
296
+ -----END PGP PUBLIC KEY BLOCK-----`;
297
+ const privateKeyArmored = `-----BEGIN PGP PRIVATE KEY BLOCK-----
298
+ ...
299
+ -----END PGP PRIVATE KEY BLOCK-----`; // encrypted private key
300
+ const passphrase = `yourPassphrase`; // what the private key is encrypted with
301
+
302
+ const publicKey = await openpgp.readKey({ armoredKey: publicKeyArmored });
303
+
304
+ const privateKey = await openpgp.decryptKey({
305
+ privateKey: await openpgp.readPrivateKey({ armoredKey: privateKeyArmored }),
306
+ passphrase
307
+ });
308
+
309
+ const encryptedAndSignedMessage = `-----BEGIN PGP MESSAGE-----
310
+ ...
311
+ -----END PGP MESSAGE-----`;
312
+
313
+ const message = await openpgp.readMessage({
314
+ armoredMessage: encryptedAndSignedMessage // parse armored message
315
+ });
316
+ // decryption will fail if all signatures are invalid or missing
317
+ const { data: decrypted, signatures } = await openpgp.decrypt({
318
+ message,
319
+ decryptionKeys: privateKey,
320
+ expectSigned: true,
321
+ verificationKeys: publicKey, // mandatory with expectSigned=true
322
+ });
323
+ console.log(decrypted); // 'Hello, World!'
324
+ })();
325
+ ```
253
326
 
254
- By default, `encrypt` will not use any compression. It's possible to override that behavior in two ways:
327
+ #### Encrypt symmetrically with compression
255
328
 
256
- Either set the `compression` parameter in the options object when calling `encrypt`.
329
+ By default, `encrypt` will not use any compression when encrypting symmetrically only (i.e. when no `encryptionKeys` are given).
330
+ It's possible to change that behaviour by enabling compression through the config, either for the single encryption:
257
331
 
258
332
  ```js
259
333
  (async () => {
334
+ const message = await openpgp.createMessage({ binary: new Uint8Array([0x01, 0x02, 0x03]) }); // or createMessage({ text: 'string' })
260
335
  const encrypted = await openpgp.encrypt({
261
- message: openpgp.message.fromBinary(new Uint8Array([0x01, 0x02, 0x03])), // or .fromText('string')
262
- passwords: ['secret stuff'], // multiple passwords possible
263
- compression: openpgp.enums.compression.zip // compress the data with zip
336
+ message,
337
+ passwords: ['secret stuff'], // multiple passwords possible
338
+ config: { preferredCompressionAlgorithm: openpgp.enums.compression.zlib } // compress the data with zlib
264
339
  });
265
340
  })();
266
341
  ```
267
342
 
268
- Or, override the config to enable compression:
269
-
343
+ or by changing the default global configuration:
270
344
  ```js
271
- openpgp.config.compression = openpgp.enums.compression.zlib;
345
+ openpgp.config.preferredCompressionAlgorithm = openpgp.enums.compression.zlib
272
346
  ```
273
347
 
274
348
  Where the value can be any of:
275
349
  * `openpgp.enums.compression.zip`
276
350
  * `openpgp.enums.compression.zlib`
351
+ * `openpgp.enums.compression.uncompressed` (default)
352
+
277
353
 
278
354
 
279
355
  #### Streaming encrypt *Uint8Array* data with a password
@@ -287,33 +363,29 @@ Where the value can be any of:
287
363
  }
288
364
  });
289
365
 
290
- const { message } = await openpgp.encrypt({
291
- message: openpgp.message.fromBinary(readableStream), // input as Message object
292
- passwords: ['secret stuff'], // multiple passwords possible
293
- armor: false // don't ASCII armor (for Uint8Array output)
366
+ const message = await openpgp.createMessage({ binary: readableStream });
367
+ const encrypted = await openpgp.encrypt({
368
+ message, // input as Message object
369
+ passwords: ['secret stuff'], // multiple passwords possible
370
+ format: 'binary' // don't ASCII armor (for Uint8Array output)
294
371
  });
295
- const encrypted = message.packets.write(); // get raw encrypted packets as ReadableStream<Uint8Array>
372
+ console.log(encrypted); // raw encrypted packets as ReadableStream<Uint8Array>
296
373
 
297
374
  // Either pipe the above stream somewhere, pass it to another function,
298
375
  // or read it manually as follows:
299
- const reader = openpgp.stream.getReader(encrypted);
300
- while (true) {
301
- const { done, value } = await reader.read();
302
- if (done) break;
303
- console.log('new chunk:', value); // Uint8Array
376
+ for await (const chunk of encrypted) {
377
+ console.log('new chunk:', chunk); // Uint8Array
304
378
  }
305
-
306
- // Or, in Node.js, you can pipe the above stream as follows:
307
- const nodeStream = openpgp.stream.webToNode(encrypted);
308
- nodeStream.pipe(nodeWritableStream);
309
379
  })();
310
380
  ```
311
381
 
312
- For more information on creating ReadableStreams, see [the MDN Documentation on `new
313
- ReadableStream()`](https://developer.mozilla.org/docs/Web/API/ReadableStream/ReadableStream).
314
- For more information on reading streams using `openpgp.stream`, see the documentation of
315
- [the web-stream-tools dependency](https://openpgpjs.org/web-stream-tools/), particularly
316
- its [Reader class](https://openpgpjs.org/web-stream-tools/Reader.html).
382
+ For more information on using ReadableStreams, see [the MDN Documentation on the
383
+ Streams API](https://developer.mozilla.org/en-US/docs/Web/API/Streams_API).
384
+
385
+ You can also pass a [Node.js `Readable`
386
+ stream](https://nodejs.org/api/stream.html#stream_class_stream_readable), in
387
+ which case OpenPGP.js will return a Node.js `Readable` stream as well, which you
388
+ can `.pipe()` to a `Writable` stream, for example.
317
389
 
318
390
 
319
391
  #### Streaming encrypt and decrypt *String* data with PGP keys
@@ -323,13 +395,17 @@ its [Reader class](https://openpgpjs.org/web-stream-tools/Reader.html).
323
395
  const publicKeyArmored = `-----BEGIN PGP PUBLIC KEY BLOCK-----
324
396
  ...
325
397
  -----END PGP PUBLIC KEY BLOCK-----`; // Public key
326
- const [privateKeyArmored] = `-----BEGIN PGP PRIVATE KEY BLOCK-----
398
+ const privateKeyArmored = `-----BEGIN PGP PRIVATE KEY BLOCK-----
327
399
  ...
328
400
  -----END PGP PRIVATE KEY BLOCK-----`; // Encrypted private key
329
401
  const passphrase = `yourPassphrase`; // Password that private key is encrypted with
330
402
 
331
- const privateKey = (await openpgp.key.readArmored([privateKeyArmored])).keys[0];
332
- await privateKey.decrypt(passphrase);
403
+ const publicKey = await openpgp.readKey({ armoredKey: publicKeyArmored });
404
+
405
+ const privateKey = await openpgp.decryptKey({
406
+ privateKey: await openpgp.readPrivateKey({ armoredKey: privateKeyArmored }),
407
+ passphrase
408
+ });
333
409
 
334
410
  const readableStream = new ReadableStream({
335
411
  start(controller) {
@@ -339,53 +415,64 @@ its [Reader class](https://openpgpjs.org/web-stream-tools/Reader.html).
339
415
  });
340
416
 
341
417
  const encrypted = await openpgp.encrypt({
342
- message: openpgp.message.fromText(readableStream), // input as Message object
343
- publicKeys: (await openpgp.key.readArmored(publicKeyArmored)).keys, // for encryption
344
- privateKeys: [privateKey] // for signing (optional)
418
+ message: await openpgp.createMessage({ text: readableStream }), // input as Message object
419
+ encryptionKeys: publicKey,
420
+ signingKeys: privateKey // optional
345
421
  });
346
- const ciphertext = encrypted.data; // ReadableStream containing '-----BEGIN PGP MESSAGE ... END PGP MESSAGE-----'
422
+ console.log(encrypted); // ReadableStream containing '-----BEGIN PGP MESSAGE ... END PGP MESSAGE-----'
347
423
 
424
+ const message = await openpgp.readMessage({
425
+ armoredMessage: encrypted // parse armored message
426
+ });
348
427
  const decrypted = await openpgp.decrypt({
349
- message: await openpgp.message.readArmored(ciphertext), // parse armored message
350
- publicKeys: (await openpgp.key.readArmored(publicKeyArmored)).keys, // for verification (optional)
351
- privateKeys: [privateKey] // for decryption
428
+ message,
429
+ verificationKeys: publicKey, // optional
430
+ decryptionKeys: privateKey
352
431
  });
353
- const plaintext = await openpgp.stream.readToEnd(decrypted.data); // 'Hello, World!'
432
+ const chunks = [];
433
+ for await (const chunk of decrypted.data) {
434
+ chunks.push(chunk);
435
+ }
436
+ const plaintext = chunks.join('');
437
+ console.log(plaintext); // 'Hello, World!'
354
438
  })();
355
439
  ```
356
440
 
357
441
 
358
442
  #### Generate new key pair
359
443
 
360
- ECC keys:
444
+ ECC keys (smaller and faster to generate):
361
445
 
362
- Possible values for `curve` are: `curve25519`, `ed25519`, `p256`, `p384`, `p521`, `secp256k1`,
363
- `brainpoolP256r1`, `brainpoolP384r1`, or `brainpoolP512r1`.
446
+ Possible values for `curve` are: `curve25519`, `ed25519`, `p256`, `p384`, `p521`,
447
+ `brainpoolP256r1`, `brainpoolP384r1`, `brainpoolP512r1`, and `secp256k1`.
364
448
  Note that both the `curve25519` and `ed25519` options generate a primary key for signing using Ed25519
365
449
  and a subkey for encryption using Curve25519.
366
450
 
367
451
  ```js
368
452
  (async () => {
369
- const { privateKeyArmored, publicKeyArmored, revocationCertificate } = await openpgp.generateKey({
370
- userIds: [{ name: 'Jon Smith', email: 'jon@example.com' }], // you can pass multiple user IDs
371
- curve: 'ed25519', // ECC curve name
372
- passphrase: 'super long and hard to guess secret' // protects the private key
453
+ const { privateKey, publicKey, revocationCertificate } = await openpgp.generateKey({
454
+ type: 'ecc', // Type of the key, defaults to ECC
455
+ curve: 'curve25519', // ECC curve name, defaults to curve25519
456
+ userIDs: [{ name: 'Jon Smith', email: 'jon@example.com' }], // you can pass multiple user IDs
457
+ passphrase: 'super long and hard to guess secret', // protects the private key
458
+ format: 'armored' // output key format, defaults to 'armored' (other options: 'binary' or 'object')
373
459
  });
374
460
 
375
- console.log(privateKeyArmored); // '-----BEGIN PGP PRIVATE KEY BLOCK ... '
376
- console.log(publicKeyArmored); // '-----BEGIN PGP PUBLIC KEY BLOCK ... '
461
+ console.log(privateKey); // '-----BEGIN PGP PRIVATE KEY BLOCK ... '
462
+ console.log(publicKey); // '-----BEGIN PGP PUBLIC KEY BLOCK ... '
377
463
  console.log(revocationCertificate); // '-----BEGIN PGP PUBLIC KEY BLOCK ... '
378
464
  })();
379
465
  ```
380
466
 
381
- RSA keys:
467
+ RSA keys (increased compatibility):
382
468
 
383
469
  ```js
384
470
  (async () => {
385
- const key = await openpgp.generateKey({
386
- userIds: [{ name: 'Jon Smith', email: 'jon@example.com' }], // you can pass multiple user IDs
387
- rsaBits: 4096, // RSA key size
388
- passphrase: 'super long and hard to guess secret' // protects the private key
471
+ const { privateKey, publicKey } = await openpgp.generateKey({
472
+ type: 'rsa', // Type of the key
473
+ rsaBits: 4096, // RSA key size (defaults to 4096 bits)
474
+ userIDs: [{ name: 'Jon Smith', email: 'jon@example.com' }], // you can pass multiple user IDs
475
+ passphrase: 'super long and hard to guess secret' // protects the private key
389
476
  });
390
477
  })();
391
478
  ```
@@ -395,9 +482,10 @@ RSA keys:
395
482
  Using a revocation certificate:
396
483
  ```js
397
484
  (async () => {
398
- const { publicKeyArmored: revokedKeyArmored } = await openpgp.revokeKey({
399
- key: (await openpgp.key.readArmored(publicKeyArmored)).keys[0],
400
- revocationCertificate
485
+ const { publicKey: revokedKeyArmored } = await openpgp.revokeKey({
486
+ key: await openpgp.readKey({ armoredKey: publicKeyArmored }),
487
+ revocationCertificate,
488
+ format: 'armored' // output armored keys
401
489
  });
402
490
  console.log(revokedKeyArmored); // '-----BEGIN PGP PUBLIC KEY BLOCK ... '
403
491
  })();
@@ -406,36 +494,11 @@ Using a revocation certificate:
406
494
  Using the private key:
407
495
  ```js
408
496
  (async () => {
409
- const { publicKeyArmored, publicKey } = await openpgp.revokeKey({
410
- key: (await openpgp.key.readArmored(privateKeyArmored)).keys[0]
497
+ const { publicKey: revokedKeyArmored } = await openpgp.revokeKey({
498
+ key: await openpgp.readKey({ armoredKey: privateKeyArmored }),
499
+ format: 'armored' // output armored keys
411
500
  });
412
- })();
413
- ```
414
-
415
- #### Lookup public key on HKP server
416
-
417
- ```js
418
- (async () => {
419
- var hkp = new openpgp.HKP(); // Defaults to https://keyserver.ubuntu.com, or pass another keyserver URL as a string
420
-
421
- let publicKeyArmored = await hkp.lookup({
422
- query: 'alice@example.com'
423
- });
424
- var { keys: [publicKey] } = await openpgp.key.readArmored(publicKeyArmored);
425
- })();
426
- ```
427
-
428
- #### Upload public key to HKP server
429
-
430
- ```js
431
- (async () => {
432
- var hkp = new openpgp.HKP('https://pgp.mit.edu');
433
-
434
- var publicKeyArmored = `-----BEGIN PGP PUBLIC KEY BLOCK-----
435
- ...
436
- -----END PGP PUBLIC KEY BLOCK-----`;
437
-
438
- await hkp.upload(publicKeyArmored);
501
+ console.log(revokedKeyArmored); // '-----BEGIN PGP PUBLIC KEY BLOCK ... '
439
502
  })();
440
503
  ```
441
504
 
@@ -451,24 +514,33 @@ Using the private key:
451
514
  -----END PGP PRIVATE KEY BLOCK-----`; // encrypted private key
452
515
  const passphrase = `yourPassphrase`; // what the private key is encrypted with
453
516
 
454
- const { keys: [privateKey] } = await openpgp.key.readArmored(privateKeyArmored);
455
- await privateKey.decrypt(passphrase);
517
+ const publicKey = await openpgp.readKey({ armoredKey: publicKeyArmored });
518
+
519
+ const privateKey = await openpgp.decryptKey({
520
+ privateKey: await openpgp.readPrivateKey({ armoredKey: privateKeyArmored }),
521
+ passphrase
522
+ });
456
523
 
457
- const { data: cleartext } = await openpgp.sign({
458
- message: openpgp.cleartext.fromText('Hello, World!'), // CleartextMessage or Message object
459
- privateKeys: [privateKey] // for signing
524
+ const unsignedMessage = await openpgp.createCleartextMessage({ text: 'Hello, World!' });
525
+ const cleartextMessage = await openpgp.sign({
526
+ message: unsignedMessage, // CleartextMessage or Message object
527
+ signingKeys: privateKey
460
528
  });
461
- console.log(cleartext); // '-----BEGIN PGP SIGNED MESSAGE ... END PGP SIGNATURE-----'
529
+ console.log(cleartextMessage); // '-----BEGIN PGP SIGNED MESSAGE ... END PGP SIGNATURE-----'
462
530
 
463
- const verified = await openpgp.verify({
464
- message: await openpgp.cleartext.readArmored(cleartext), // parse armored message
465
- publicKeys: (await openpgp.key.readArmored(publicKeyArmored)).keys // for verification
531
+ const signedMessage = await openpgp.readCleartextMessage({
532
+ cleartextMessage // parse armored message
466
533
  });
467
- const { valid } = verified.signatures[0];
468
- if (valid) {
469
- console.log('signed by key id ' + verified.signatures[0].keyid.toHex());
470
- } else {
471
- throw new Error('signature could not be verified');
534
+ const verificationResult = await openpgp.verify({
535
+ message: signedMessage,
536
+ verificationKeys: publicKey
537
+ });
538
+ const { verified, keyID } = verificationResult.signatures[0];
539
+ try {
540
+ await verified; // throws on invalid signature
541
+ console.log('Signed by key id ' + keyID.toHex());
542
+ } catch (e) {
543
+ throw new Error('Signature could not be verified: ' + e.message);
472
544
  }
473
545
  })();
474
546
  ```
@@ -485,26 +557,35 @@ Using the private key:
485
557
  -----END PGP PRIVATE KEY BLOCK-----`; // encrypted private key
486
558
  const passphrase = `yourPassphrase`; // what the private key is encrypted with
487
559
 
488
- const { keys: [privateKey] } = await openpgp.key.readArmored(privateKeyArmored);
489
- await privateKey.decrypt(passphrase);
560
+ const publicKey = await openpgp.readKey({ armoredKey: publicKeyArmored });
561
+
562
+ const privateKey = await openpgp.decryptKey({
563
+ privateKey: await openpgp.readPrivateKey({ armoredKey: privateKeyArmored }),
564
+ passphrase
565
+ });
490
566
 
491
- const { signature: detachedSignature } = await openpgp.sign({
492
- message: openpgp.cleartext.fromText('Hello, World!'), // CleartextMessage or Message object
493
- privateKeys: [privateKey], // for signing
567
+ const message = await openpgp.createMessage({ text: 'Hello, World!' });
568
+ const detachedSignature = await openpgp.sign({
569
+ message, // Message object
570
+ signingKeys: privateKey,
494
571
  detached: true
495
572
  });
496
573
  console.log(detachedSignature);
497
574
 
498
- const verified = await openpgp.verify({
499
- message: openpgp.cleartext.fromText('Hello, World!'), // CleartextMessage or Message object
500
- signature: await openpgp.signature.readArmored(detachedSignature), // parse detached signature
501
- publicKeys: (await openpgp.key.readArmored(publicKeyArmored)).keys // for verification
575
+ const signature = await openpgp.readSignature({
576
+ armoredSignature: detachedSignature // parse detached signature
502
577
  });
503
- const { valid } = verified.signatures[0];
504
- if (valid) {
505
- console.log('signed by key id ' + verified.signatures[0].keyid.toHex());
506
- } else {
507
- throw new Error('signature could not be verified');
578
+ const verificationResult = await openpgp.verify({
579
+ message, // Message object
580
+ signature,
581
+ verificationKeys: publicKey
582
+ });
583
+ const { verified, keyID } = verificationResult.signatures[0];
584
+ try {
585
+ await verified; // throws on invalid signature
586
+ console.log('Signed by key id ' + keyID.toHex());
587
+ } catch (e) {
588
+ throw new Error('Signature could not be verified: ' + e.message);
508
589
  }
509
590
  })();
510
591
  ```
@@ -528,39 +609,40 @@ Using the private key:
528
609
  -----END PGP PRIVATE KEY BLOCK-----`; // encrypted private key
529
610
  const passphrase = `yourPassphrase`; // what the private key is encrypted with
530
611
 
531
- const { keys: [privateKey] } = await openpgp.key.readArmored(privateKeyArmored);
532
- await privateKey.decrypt(passphrase);
612
+ const privateKey = await openpgp.decryptKey({
613
+ privateKey: await openpgp.readPrivateKey({ armoredKey: privateKeyArmored }),
614
+ passphrase
615
+ });
533
616
 
534
- const { data: signatureArmored } = await openpgp.sign({
535
- message: openpgp.message.fromBinary(readableStream), // or .fromText(readableStream: ReadableStream<String>)
536
- privateKeys: [privateKey] // for signing
617
+ const message = await openpgp.createMessage({ binary: readableStream }); // or createMessage({ text: ReadableStream<String> })
618
+ const signatureArmored = await openpgp.sign({
619
+ message,
620
+ signingKeys: privateKey
537
621
  });
538
622
  console.log(signatureArmored); // ReadableStream containing '-----BEGIN PGP MESSAGE ... END PGP MESSAGE-----'
539
623
 
540
- const verified = await openpgp.verify({
541
- message: await openpgp.message.readArmored(signatureArmored), // parse armored signature
542
- publicKeys: (await openpgp.key.readArmored(publicKeyArmored)).keys // for verification
624
+ const verificationResult = await openpgp.verify({
625
+ message: await openpgp.readMessage({ armoredMessage: signatureArmored }), // parse armored signature
626
+ verificationKeys: await openpgp.readKey({ armoredKey: publicKeyArmored })
543
627
  });
544
628
 
545
- await openpgp.stream.readToEnd(verified.data);
546
- // Note: you *have* to read `verified.data` in some way or other,
629
+ for await (const chunk of verificationResult.data) {}
630
+ // Note: you *have* to read `verificationResult.data` in some way or other,
547
631
  // even if you don't need it, as that is what triggers the
548
632
  // verification of the data.
549
633
 
550
- const { valid } = verified.signatures[0];
551
- if (valid) {
552
- console.log('signed by key id ' + verified.signatures[0].keyid.toHex());
553
- } else {
554
- throw new Error('signature could not be verified');
634
+ try {
635
+ await verificationResult.signatures[0].verified; // throws on invalid signature
636
+ console.log('Signed by key id ' + verificationResult.signatures[0].keyID.toHex());
637
+ } catch (e) {
638
+ throw new Error('Signature could not be verified: ' + e.message);
555
639
  }
556
640
  })();
557
641
  ```
558
642
 
559
643
  ### Documentation
560
644
 
561
- A jsdoc build of our code comments is available at [doc/index.html](https://openpgpjs.org/openpgpjs/doc/index.html). Public calls should generally be made through the OpenPGP object [doc/openpgp.html](https://openpgpjs.org/openpgpjs/doc/module-openpgp.html).
562
-
563
- For the documentation of `openpgp.stream`, see the documentation of [the web-stream-tools dependency](https://openpgpjs.org/web-stream-tools/).
645
+ The full documentation is available at [openpgpjs.org](https://docs.openpgpjs.org/).
564
646
 
565
647
  ### Security Audit
566
648
 
@@ -578,9 +660,9 @@ To create your own build of the library, just run the following command after cl
578
660
 
579
661
  npm install && npm test
580
662
 
581
- For debugging browser errors, you can open `test/unittests.html` in a browser or, after running the following command, open [`http://localhost:3000/test/unittests.html`](http://localhost:3000/test/unittests.html):
663
+ For debugging browser errors, you can run `npm start` and open [`http://localhost:8080/test/unittests.html`](http://localhost:8080/test/unittests.html) in a browser, or run the following command:
582
664
 
583
- grunt browsertest
665
+ npm run browsertest
584
666
 
585
667
  ### How do I get involved?
586
668
 
@@ -589,13 +671,3 @@ You want to help, great! It's probably best to send us a message on [Gitter](htt
589
671
  ### License
590
672
 
591
673
  [GNU Lesser General Public License](https://www.gnu.org/licenses/lgpl-3.0.en.html) (3.0 or any later version). Please take a look at the [LICENSE](LICENSE) file for more information.
592
-
593
- ### Resources
594
-
595
- Below is a collection of resources, many of these were projects that were in someway a precursor to the current OpenPGP.js project. If you'd like to add your link here, please do so in a pull request or email to the list.
596
-
597
- * [https://www.hanewin.net/encrypt/](https://www.hanewin.net/encrypt/)
598
- * [https://github.com/seancolyer/gmail-crypt](https://github.com/seancolyer/gmail-crypt)
599
- * [https://github.com/mete0r/jspg](https://github.com/mete0r/jspg)
600
- * [https://github.com/GPGTools/Mobile/wiki/Introduction](https://github.com/GPGTools/Mobile/wiki/Introduction)
601
- * [https://github.com/gmontalvoriv/mailock](https://github.com/gmontalvoriv/mailock)