@substrate-system/keys 0.2.43 → 0.3.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 (47) hide show
  1. package/README.md +95 -10
  2. package/dist/_base.cjs +103 -25
  3. package/dist/_base.cjs.map +2 -2
  4. package/dist/_base.d.ts +53 -6
  5. package/dist/_base.d.ts.map +1 -1
  6. package/dist/_base.js +103 -25
  7. package/dist/_base.js.map +2 -2
  8. package/dist/_base.min.cjs +1 -1
  9. package/dist/_base.min.cjs.map +3 -3
  10. package/dist/_base.min.js +2 -2
  11. package/dist/_base.min.js.map +4 -4
  12. package/dist/browser/index.js +134 -65
  13. package/dist/browser/index.min.js +2 -2
  14. package/dist/ecc/index.cjs +4 -13
  15. package/dist/ecc/index.cjs.map +2 -2
  16. package/dist/ecc/index.d.ts +5 -2
  17. package/dist/ecc/index.d.ts.map +1 -1
  18. package/dist/ecc/index.js +4 -13
  19. package/dist/ecc/index.js.map +2 -2
  20. package/dist/ecc/index.min.cjs +1 -1
  21. package/dist/ecc/index.min.cjs.map +3 -3
  22. package/dist/ecc/index.min.js +2 -2
  23. package/dist/ecc/index.min.js.map +3 -3
  24. package/dist/errors.cjs +10 -0
  25. package/dist/errors.cjs.map +2 -2
  26. package/dist/errors.d.ts +8 -0
  27. package/dist/errors.d.ts.map +1 -1
  28. package/dist/errors.js +10 -0
  29. package/dist/errors.js.map +2 -2
  30. package/dist/errors.min.cjs +1 -1
  31. package/dist/errors.min.cjs.map +3 -3
  32. package/dist/errors.min.js +1 -1
  33. package/dist/errors.min.js.map +3 -3
  34. package/dist/index.min.js +2 -2
  35. package/dist/index.min.js.map +4 -4
  36. package/dist/meta.json +23 -16
  37. package/dist/rsa/index.cjs +0 -5
  38. package/dist/rsa/index.cjs.map +2 -2
  39. package/dist/rsa/index.d.ts +1 -2
  40. package/dist/rsa/index.d.ts.map +1 -1
  41. package/dist/rsa/index.js +0 -5
  42. package/dist/rsa/index.js.map +2 -2
  43. package/dist/rsa/index.min.cjs +1 -1
  44. package/dist/rsa/index.min.cjs.map +3 -3
  45. package/dist/rsa/index.min.js +2 -2
  46. package/dist/rsa/index.min.js.map +4 -4
  47. package/package.json +1 -1
package/README.md CHANGED
@@ -55,11 +55,13 @@ See also, [the API docs generated from typescript](https://substrate-system.gith
55
55
  + [`keys.DID`](#keysdid)
56
56
  + [`keys.getDeviceName` / `keys.deviceName`](#keysgetdevicename--keysdevicename)
57
57
  + [`keys.hasPersisted`](#keyshaspersisted)
58
+ + [`keys.destroyed`](#keysdestroyed)
58
59
  + [`keys.publicExchangeKey`](#keyspublicexchangekey)
59
60
  + [`keys.publicExchangeKeyAsString()`](#keyspublicexchangekeyasstring)
60
61
  + [`keys.publicWriteKey`](#keyspublicwritekey)
61
62
  + [`keys.publicWriteKeyAsString()`](#keyspublicwritekeyasstring)
62
63
  * [Delete a keypair](#delete-a-keypair)
64
+ + [`Keys.delete()`](#keysdelete)
63
65
  * [Sign and Verify Something](#sign-and-verify-something)
64
66
  * [encrypt something](#encrypt-something)
65
67
  + [`keys.encrypt` methods](#keysencrypt-methods)
@@ -268,13 +270,11 @@ ECC is now supported in all major browsers.
268
270
  ```js
269
271
  import { EccKeys, verify } from '@substrate-system/keys/ecc'
270
272
 
271
- const keys = await EccKeys.create()
272
-
273
- // save the keys to indexedDB
274
- await keys.persist()
273
+ // create a keypair, and save it to indexedDB
274
+ const keys = await EccKeys.load()
275
275
 
276
276
  // ... sometime in the future ...
277
- // get our keys from indexedDB
277
+ // get the same keys back from indexedDB
278
278
  const keysAgain = await EccKeys.load()
279
279
 
280
280
  console.assert(keys.DID === keysAgain.DID) // true
@@ -441,8 +441,15 @@ const name = await keys.deviceName
441
441
 
442
442
  #### `keys.hasPersisted`
443
443
 
444
- A flag indicating whether `.persist` has been called, meaning that these keys
445
- are saved in `indexedDB`.
444
+ A flag indicating whether these keys are saved in `indexedDB`. It is `true`
445
+ after `.persist`, and after any `.load` that did not opt out with
446
+ `{ persist: false }`.
447
+
448
+ #### `keys.destroyed`
449
+
450
+ A flag indicating whether [`.delete`](#delete-a-keypair) has been called. A
451
+ destroyed keypair is terminal -- the key material is gone, and any use of it
452
+ throws a `KeysDeletedError`.
446
453
 
447
454
  #### `keys.publicExchangeKey`
448
455
 
@@ -476,10 +483,69 @@ Get the public signing key as a string.
476
483
 
477
484
  ### Delete a keypair
478
485
 
479
- Delete the keys from `indexedDB`.
486
+ Delete the keypair. This deletes the keys from `indexedDB`, drops the
487
+ in-memory key material, and clears the instance cache, so `load` will not
488
+ hand these keys out again.
489
+
490
+ ```js
491
+ await keys.delete()
492
+ ```
493
+
494
+ `delete` is terminal. Afterwards the instance is `destroyed`, and using it
495
+ throws a `KeysDeletedError`. That includes `persist`, so the common
496
+ "make sure my keys are saved" guard cannot write a deleted keypair back
497
+ into `indexedDB`.
480
498
 
481
499
  ```js
482
500
  await keys.delete()
501
+
502
+ keys.destroyed // => true
503
+
504
+ // all of these throw
505
+ keys.publicExchangeKey
506
+ await keys.sign('hello')
507
+ await keys.encrypt('hello')
508
+ if (!keys.hasPersisted) await keys.persist()
509
+ ```
510
+
511
+ The names deleted are the ones the instance was loaded with, so keys
512
+ loaded under custom names delete the custom entries.
513
+
514
+ ```js
515
+ const keys = await EccKeys.load({
516
+ encryptionKeyName: 'my-exchange-key',
517
+ writeKeyName: 'my-write-key'
518
+ })
519
+
520
+ // deletes 'my-exchange-key' and 'my-write-key'
521
+ await keys.delete()
522
+ ```
523
+
524
+ #### `Keys.delete()`
525
+
526
+ Delete a stored keypair without loading it first. This is the companion to
527
+ the static `exist` method. It deletes the given entries from `indexedDB`,
528
+ and destroys the cached instance if there is one for those names.
529
+
530
+ ```ts
531
+ {
532
+ static async delete (opts?:{
533
+ encryptionKeyName?:string,
534
+ writeKeyName?:string
535
+ }):Promise<void>
536
+ }
537
+ ```
538
+
539
+ ```js
540
+ import { EccKeys } from '@substrate-system/keys/ecc'
541
+
542
+ await EccKeys.delete()
543
+
544
+ // or, if you used custom names
545
+ await EccKeys.delete({
546
+ encryptionKeyName: 'my-exchange-key',
547
+ writeKeyName: 'my-write-key'
548
+ })
483
549
  ```
484
550
 
485
551
  --------------------------------------------------------------------------
@@ -722,6 +788,10 @@ class EccKeys { // or RsaKeys
722
788
  }
723
789
  ```
724
790
 
791
+ You only need this for keys made with [`.create`](#create-a-new-keys-instance), or
792
+ for a [`.load`](#static-load) that opted out with `{ persist: false }`.
793
+ Otherwise `.load` has already saved them.
794
+
725
795
  #### `.persist` example
726
796
  ```js
727
797
  import { EccKeys } from '@substrate-system/keys/ecc'
@@ -736,6 +806,11 @@ await keys.persist()
736
806
  Create a `Keys` instance from data saved to `indexedDB`. Pass in different
737
807
  `indexedDB` key names for the keys if you need to.
738
808
 
809
+ If there is nothing saved yet, `.load` creates a new keypair *and saves it*,
810
+ so the keys you get back are durable -- reload the page, call `.load` again,
811
+ and you get the same identity. There is no separate `.persist` step to
812
+ remember. Pass `{ persist: false }` if you want the old two-step behavior.
813
+
739
814
  #### `static .load`
740
815
  ```ts
741
816
  class EccKeys { // or RsaKeys
@@ -744,6 +819,7 @@ class EccKeys { // or RsaKeys
744
819
  writeKeyName?:string,
745
820
  session?:boolean,
746
821
  extractable?:boolean,
822
+ persist?:boolean,
747
823
  }):Promise<EccKeys>
748
824
  }
749
825
  ```
@@ -754,6 +830,7 @@ class EccKeys { // or RsaKeys
754
830
  - `writeKeyName` (optional, string): Custom name for the signing key in `indexedDB`
755
831
  - `session` (optional, boolean): If `true`, creates session-only keys if no keys exist in `indexedDB`
756
832
  - `extractable` (optional, boolean): If `true` and keys don't exist in `indexedDB`, new keys will be created as extractable. Defaults to `false`.
833
+ - `persist` (optional, boolean): Save the keys to `indexedDB` before returning. Defaults to `true`. Session keys are never written, so `session: true` wins over this.
757
834
 
758
835
  #### example
759
836
 
@@ -761,8 +838,10 @@ class EccKeys { // or RsaKeys
761
838
  import { EccKeys } from '@substrate-system/keys/ecc'
762
839
  // or: import { RsaKeys } from '@substrate-system/keys/rsa'
763
840
 
764
- // Load existing keys from indexedDB, or create new non-extractable ones
841
+ // Load existing keys from indexedDB, or create and save new
842
+ // non-extractable ones
765
843
  const newKeys = await EccKeys.load()
844
+ console.log(newKeys.hasPersisted) // true
766
845
 
767
846
  // Load with custom options
768
847
  const customKeys = await EccKeys.load({
@@ -770,6 +849,11 @@ const customKeys = await EccKeys.load({
770
849
  writeKeyName: 'my-custom-signing-key',
771
850
  extractable: true // If keys don't exist, create them as extractable
772
851
  })
852
+
853
+ // Opt out of saving -- you are responsible for calling `.persist`
854
+ const unsaved = await EccKeys.load({ persist: false })
855
+ console.log(unsaved.hasPersisted) // false
856
+ await unsaved.persist()
773
857
  ```
774
858
 
775
859
 
@@ -1029,7 +1113,8 @@ const decrypted = await keys.decrypt(encrypted)
1029
1113
 
1030
1114
  Create a keypair, but do not save it in `indexedDB`, even if you call `persist`.
1031
1115
  Pass `true` as the session parameter to `.create` or
1032
- pass `{ session: true }` to `.load`.
1116
+ pass `{ session: true }` to `.load`. Session keys are never written to
1117
+ `indexedDB`, so `session: true` beats the `persist` default in `.load`.
1033
1118
 
1034
1119
  ```js
1035
1120
  import { EccKeys } from '@substrate-system/keys/ecc'
package/dist/_base.cjs CHANGED
@@ -23,6 +23,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
23
23
  var base_exports = {};
24
24
  __export(base_exports, {
25
25
  AbstractKeys: () => AbstractKeys,
26
+ KeysDeletedError: () => import_errors.KeysDeletedError,
26
27
  encryptKeyTo: () => encryptKeyTo,
27
28
  encryptTo: () => encryptTo,
28
29
  getDeviceName: () => getDeviceName,
@@ -36,22 +37,48 @@ var import_idb_keyval = require("idb-keyval");
36
37
  var import_aes = require("./aes/index.js");
37
38
  var import_util = require("./util.js");
38
39
  var import_crypto = require("./crypto.js");
40
+ var import_errors = require("./errors.js");
39
41
  __reExport(base_exports, require("./constants.js"), module.exports);
40
42
  var import_crypto2 = require("./crypto.js");
41
43
  const _AbstractKeys = class _AbstractKeys {
42
- // a cache for indexedDB
43
44
  constructor(opts) {
44
45
  __publicField(this, "DID");
45
- __publicField(this, "exchangeKey");
46
- __publicField(this, "writeKey");
47
46
  __publicField(this, "hasPersisted");
48
47
  __publicField(this, "isSessionOnly");
48
+ /**
49
+ * Have these keys been deleted? A deleted keypair is terminal -- the key
50
+ * material is gone, and any use of it throws.
51
+ */
52
+ __publicField(this, "destroyed");
53
+ /**
54
+ * The `indexedDB` names this keypair was loaded from, and the names
55
+ * `persist` and `delete` will use.
56
+ */
57
+ __publicField(this, "exchangeKeyName");
58
+ __publicField(this, "writeKeyName");
59
+ // a cache for indexedDB
60
+ // the key material -- read it via the `exchangeKey`/`writeKey` getters,
61
+ // which throw if this instance was deleted
62
+ __publicField(this, "_exchangeKey");
63
+ __publicField(this, "_writeKey");
49
64
  const { keys } = opts;
65
+ const ctor = this.constructor;
50
66
  this.DID = opts.did;
51
- this.exchangeKey = keys.exchange;
52
- this.writeKey = keys.write;
67
+ this._exchangeKey = keys.exchange;
68
+ this._writeKey = keys.write;
53
69
  this.hasPersisted = opts.hasPersisted;
54
70
  this.isSessionOnly = !!opts.isSessionOnly;
71
+ this.destroyed = false;
72
+ this.exchangeKeyName = opts.exchangeKeyName || ctor.EXCHANGE_KEY_NAME;
73
+ this.writeKeyName = opts.writeKeyName || ctor.WRITE_KEY_NAME;
74
+ }
75
+ get exchangeKey() {
76
+ if (this.destroyed || !this._exchangeKey) throw new import_errors.KeysDeletedError();
77
+ return this._exchangeKey;
78
+ }
79
+ get writeKey() {
80
+ if (this.destroyed || !this._writeKey) throw new import_errors.KeysDeletedError();
81
+ return this._writeKey;
55
82
  }
56
83
  publicExchangeKeyAsString(format) {
57
84
  return this.publicExchangeKey.asString(format);
@@ -104,24 +131,64 @@ const _AbstractKeys = class _AbstractKeys {
104
131
  * Save this keys instance to `indexedDB`.
105
132
  */
106
133
  async persist() {
134
+ if (this.destroyed) throw new import_errors.KeysDeletedError();
107
135
  if (this.isSessionOnly) return;
108
- const exchange = this.constructor.EXCHANGE_KEY_NAME;
109
- const write = this.constructor.WRITE_KEY_NAME;
110
136
  await Promise.all([
111
- (0, import_idb_keyval.set)(exchange, this.exchangeKey),
112
- (0, import_idb_keyval.set)(write, this.writeKey)
137
+ (0, import_idb_keyval.set)(this.exchangeKeyName, this.exchangeKey),
138
+ (0, import_idb_keyval.set)(this.writeKeyName, this.writeKey)
113
139
  ]);
114
140
  this.hasPersisted = true;
115
141
  }
116
142
  /**
117
- * Delete the keys stored in indexedDB.
143
+ * Delete this keypair. This deletes the keys from indexedDB, drops the
144
+ * in-memory key material, and clears the instance cache, so `load` will
145
+ * not hand out these keys again.
146
+ *
147
+ * After this, the instance is `destroyed` -- using it throws
148
+ * a `KeysDeletedError`.
118
149
  */
119
150
  async delete() {
120
- await (0, import_idb_keyval.delMany)([
121
- this.constructor.EXCHANGE_KEY_NAME,
122
- this.constructor.WRITE_KEY_NAME
123
- ]);
151
+ const exchangeName = this.exchangeKeyName;
152
+ const writeName = this.writeKeyName;
153
+ await (0, import_idb_keyval.delMany)([exchangeName, writeName]);
154
+ const ctor = this.constructor;
155
+ ctor._invalidate(exchangeName, writeName);
156
+ this._destroy();
157
+ }
158
+ /**
159
+ * Drop the in-memory key material. Internal -- call `delete` instead.
160
+ */
161
+ _destroy() {
162
+ this.destroyed = true;
124
163
  this.hasPersisted = false;
164
+ this._exchangeKey = null;
165
+ this._writeKey = null;
166
+ }
167
+ /**
168
+ * If the cached instance was loaded from the given names, then its keys
169
+ * are gone too. Destroy it, and clear the cache. Internal.
170
+ */
171
+ static _invalidate(exchangeName, writeName) {
172
+ const cached = this._instance;
173
+ if (!cached) return;
174
+ if (cached.exchangeKeyName !== exchangeName) return;
175
+ if (cached.writeKeyName !== writeName) return;
176
+ cached._destroy();
177
+ this._instance = null;
178
+ }
179
+ /**
180
+ * Delete a stored keypair without loading it first. Deletes the keys from
181
+ * indexedDB, and destroys the cached instance, if there is one for
182
+ * these names.
183
+ *
184
+ * @param {{ encryptionKeyName, writeKeyName }} [opts] The indexedDB names
185
+ * to delete. Defaults to this class's names.
186
+ */
187
+ static async delete(opts = {}) {
188
+ const exchangeName = opts.encryptionKeyName || this.EXCHANGE_KEY_NAME;
189
+ const writeName = opts.writeKeyName || this.WRITE_KEY_NAME;
190
+ await (0, import_idb_keyval.delMany)([exchangeName, writeName]);
191
+ this._invalidate(exchangeName, writeName);
125
192
  }
126
193
  /**
127
194
  * Return a 32-character, DNS friendly hash of the public signing key.
@@ -166,22 +233,30 @@ const _AbstractKeys = class _AbstractKeys {
166
233
  * Restore some keys from indexedDB, or create a new keypair if it doesn't
167
234
  * exist yet.
168
235
  *
169
- * @param {{ encryptionKeyName, signingKeyName, session }} opts Strings to
170
- * use as keys in indexedDB, and a session boolean, is this in memory
171
- * only? Or can it be persisted.
236
+ * By default this saves the keys to `indexedDB` before returning, so the
237
+ * keypair you get back survives a page reload. Pass `{ persist: false }`
238
+ * to skip that and call `.persist()` yourself. Session keys are never
239
+ * written to `indexedDB`, so `{ session: true }` wins over `persist`.
240
+ *
241
+ * @param {{ encryptionKeyName, signingKeyName, session, persist }} opts
242
+ * Strings to use as keys in indexedDB, a session boolean -- is this in
243
+ * memory only? Or can it be persisted -- and a persist boolean.
172
244
  * @returns {Promise<AbstractKeys>}
173
245
  */
174
246
  static async load(opts = {
175
247
  session: false
176
248
  }) {
177
- if (this._instance) return this._instance;
249
+ const shouldPersist = opts.persist !== false;
250
+ const exchangeKeyName = opts.encryptionKeyName || this.EXCHANGE_KEY_NAME;
251
+ const writeKeyName = opts.writeKeyName || this.WRITE_KEY_NAME;
252
+ const cached = this._instance;
253
+ if (cached && !cached.destroyed && cached.exchangeKeyName === exchangeKeyName && cached.writeKeyName === writeKeyName) {
254
+ if (shouldPersist && !cached.hasPersisted) await cached.persist();
255
+ return cached;
256
+ }
178
257
  let hasPersisted = true;
179
- let exchangeKeys = await (0, import_idb_keyval.get)(
180
- opts.encryptionKeyName || this.EXCHANGE_KEY_NAME
181
- );
182
- let writeKeys = await (0, import_idb_keyval.get)(
183
- opts.writeKeyName || this.WRITE_KEY_NAME
184
- );
258
+ let exchangeKeys = await (0, import_idb_keyval.get)(exchangeKeyName);
259
+ let writeKeys = await (0, import_idb_keyval.get)(writeKeyName);
185
260
  if (!exchangeKeys) {
186
261
  hasPersisted = false;
187
262
  exchangeKeys = await this._createExchangeKeys(opts.extractable);
@@ -199,9 +274,12 @@ const _AbstractKeys = class _AbstractKeys {
199
274
  keys: { exchange: exchangeKeys, write: writeKeys },
200
275
  did,
201
276
  hasPersisted,
202
- isSessionOnly: !!opts.session
277
+ isSessionOnly: !!opts.session,
278
+ exchangeKeyName,
279
+ writeKeyName
203
280
  });
204
281
  this._instance = keys;
282
+ if (shouldPersist && !hasPersisted) await keys.persist();
205
283
  return keys;
206
284
  }
207
285
  };
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/_base.ts"],
4
- "sourcesContent": ["import { fromString, type SupportedEncodings, toString } from 'uint8arrays'\nimport { get, set, delMany } from 'idb-keyval'\nimport type {\n CharSize,\n Msg,\n SymmKeyLength,\n DID,\n SymmKey,\n} from './types.js'\nimport { AES } from './aes/index.js'\nimport {\n toBase64,\n joinBufs,\n sha256,\n} from './util.js'\nimport {\n rsaOperations,\n publicKeyToDid,\n getPublicKeyAsArrayBuffer,\n} from './crypto.js'\n\nexport { publicKeyToDid, getPublicKeyAsArrayBuffer }\nexport * from './constants.js'\nexport type { DID }\nexport { getPublicKeyAsUint8Array } from './crypto.js'\nexport type SerializedKeys = {\n DID:DID;\n pulicExchangeKey:string;\n}\n\nexport interface RsaEncryptor {\n (\n content:string|Uint8Array,\n recipient?:CryptoKey|string,\n aesKey?:SymmKey|Uint8Array|string,\n keysize?:SymmKeyLength\n ):Promise<Uint8Array>\n}\n\nexport interface EccEncryptor {\n (\n content:string|Uint8Array,\n recipient?:CryptoKey|string,\n info?:string,\n aesKey?:SymmKey|Uint8Array|string,\n keysize?:SymmKeyLength\n ):Promise<Uint8Array>\n}\n\nexport interface RsaEncryptorAsString {\n (\n content:string|Uint8Array,\n recipient?:CryptoKey|string,\n aesKey?:SymmKey|Uint8Array|string,\n keysize?:SymmKeyLength\n ):Promise<string>\n}\n\nexport interface EccEncryptorAsString {\n (\n content:string|Uint8Array,\n recipient?:CryptoKey|string,\n info?:string,\n aesKey?:SymmKey|Uint8Array|string,\n keysize?:SymmKeyLength\n ):Promise<string>\n}\n\n// Type helpers to constrain implementations\nexport type RsaKeysType = AbstractKeys & {\n encrypt: RsaEncryptor;\n encryptAsString: RsaEncryptorAsString;\n}\n\nexport type EccKeysType = AbstractKeys & {\n encrypt: EccEncryptor;\n encryptAsString: EccEncryptorAsString;\n}\n\n/**\n * Args to constructor.\n */\nexport type KeyArgs = {\n keys:{ exchange:CryptoKeyPair, write:CryptoKeyPair };\n did:DID;\n hasPersisted:boolean;\n isSessionOnly?:boolean; // in memory only?\n exchangeKeyName?:string;\n writeKeyName?:string;\n}\n\n/**\n * The class that extends AbstractKeys\n */\ninterface ChildKeys<T extends AbstractKeys = AbstractKeys> {\n new (opts:KeyArgs):T;\n _instance:T;\n TYPE:'ecc'|'rsa';\n INFO:string;\n _createExchangeKeys(extractable?:boolean):Promise<CryptoKeyPair>\n _createWriteKeys(extractable?:boolean):Promise<CryptoKeyPair>\n}\n\n/**\n * The parent key. Doesn't implement the encrypt/sign functions.\n */\nexport abstract class AbstractKeys {\n DID:DID\n exchangeKey:CryptoKeyPair\n writeKey:CryptoKeyPair\n hasPersisted:boolean\n isSessionOnly:boolean\n // type:'ecc'|'rsa'\n static EXCHANGE_KEY_NAME:string // needs to be defined by child class\n static WRITE_KEY_NAME:string\n static _instance // a cache for indexedDB\n\n constructor (opts:KeyArgs) {\n const { keys } = opts\n this.DID = opts.did\n this.exchangeKey = keys.exchange\n this.writeKey = keys.write\n this.hasPersisted = opts.hasPersisted\n this.isSessionOnly = !!opts.isSessionOnly\n }\n\n /**\n * By default, encrypt the given data to yourself, as a \"note to self\".\n */\n abstract encrypt (\n content:string|Uint8Array,\n recipient?:CryptoKey|string|null,\n aesKeyOrInfo?:SymmKey|Uint8Array|string|null,\n keysizeOrAesKey?:SymmKeyLength|SymmKey|Uint8Array|string|null,\n keysize?:SymmKeyLength|null\n ):Promise<Uint8Array>\n\n abstract encryptAsString (\n content:string|Uint8Array,\n recipient?:CryptoKey|string|null,\n aesKeyOrInfo?:SymmKey|Uint8Array|string|null,\n keysizeOrAesKey?:SymmKeyLength|SymmKey|Uint8Array|string|null,\n keysize?:SymmKeyLength|null\n ):Promise<string>\n\n abstract decrypt(\n msg:string|Uint8Array|ArrayBuffer,\n publicKeyOrKeysize?:CryptoKey|string|SymmKeyLength|null,\n aesAlgorithm?:string|null,\n ):Promise<ArrayBuffer|Uint8Array>\n\n abstract decryptAsString(\n msg:string|Uint8Array|ArrayBuffer,\n publicKeyOrKeysize?:CryptoKey|string|SymmKeyLength|null,\n aesAlgorithm?:string|null,\n ):Promise<string>\n\n abstract sign(msg:Msg, charsize?:CharSize):Promise<Uint8Array>\n abstract signAsString(msg:string, charsize?:CharSize):Promise<string>\n\n publicExchangeKeyAsString (format?:SupportedEncodings):Promise<string> {\n return this.publicExchangeKey.asString(format)\n }\n\n publicWriteKeyAsString (format?:SupportedEncodings):Promise<string> {\n return this.publicWriteKey.asString(format)\n }\n\n get publicWriteKey () {\n const publicKey = this.writeKey.publicKey\n return Object.assign(publicKey, {\n asString: async (format?:SupportedEncodings):Promise<string> => {\n const arrayBuffer = await getPublicKeyAsArrayBuffer(this.writeKey)\n const uint8Array = new Uint8Array(arrayBuffer)\n return format ? toString(uint8Array, format) : toBase64(uint8Array)\n }\n })\n }\n\n get publicExchangeKey () {\n const publicKey = this.exchangeKey.publicKey\n return Object.assign(publicKey, {\n asString: async (format?: SupportedEncodings): Promise<string> => {\n const arrayBuffer = await getPublicKeyAsArrayBuffer(this.exchangeKey)\n const uint8Array = new Uint8Array(arrayBuffer)\n return format ? toString(uint8Array, format) : toBase64(uint8Array)\n }\n })\n }\n\n get privateWriteKey ():CryptoKey {\n return this.writeKey.privateKey\n }\n\n get privateExchangeKey ():CryptoKey {\n return this.exchangeKey.privateKey\n }\n\n /**\n * The machine-readable name for this keypair.\n */\n get deviceName ():Promise<string> {\n return AbstractKeys.deviceName(this.DID)\n }\n\n /**\n * Return a 32-character, DNS-friendly hash of the given DID.\n *\n * @param {DID} did A DID format string\n * @returns {string} 32 character, base32 hash of the DID\n */\n static deviceName (did:DID):Promise<string> {\n return getDeviceName(did)\n }\n\n /**\n * Get the relevant AES key.\n * - if this is an ECC keypair, then use DHKE with the given public key\n * - if this is RSA, use your private key to decrypt the given AES key\n */\n abstract getAesKey (\n publicKey?:CryptoKey|string|null,\n info?:string|null\n ):Promise<CryptoKey>\n\n /**\n * Save this keys instance to `indexedDB`.\n */\n async persist ():Promise<void> {\n if (this.isSessionOnly) return\n\n const exchange = (this.constructor as typeof AbstractKeys).EXCHANGE_KEY_NAME\n const write = (this.constructor as typeof AbstractKeys).WRITE_KEY_NAME\n\n await Promise.all([\n set(exchange, this.exchangeKey),\n set(write, this.writeKey)\n ])\n\n this.hasPersisted = true\n }\n\n /**\n * Delete the keys stored in indexedDB.\n */\n async delete ():Promise<void> {\n await delMany([\n (this.constructor as typeof AbstractKeys).EXCHANGE_KEY_NAME,\n (this.constructor as typeof AbstractKeys).WRITE_KEY_NAME,\n ])\n this.hasPersisted = false\n }\n\n abstract toJson (format?:SupportedEncodings):Promise<{\n DID:DID;\n publicExchangeKey:string;\n }>\n\n /**\n * Return a 32-character, DNS friendly hash of the public signing key.\n *\n * @returns {Promise<string>}\n */\n async getDeviceName ():Promise<string> {\n return AbstractKeys.deviceName(this.DID)\n }\n\n static _createExchangeKeys (_extractable?:boolean):Promise<CryptoKeyPair> {\n throw new Error('The child should implement this')\n }\n\n static _createWriteKeys (_extractable?:boolean):Promise<CryptoKeyPair> {\n throw new Error('The child should implement this')\n }\n\n static async create<T extends AbstractKeys> (\n this:ChildKeys,\n session?:boolean,\n extractable?:boolean,\n keys?:{\n exchangeKeys?:CryptoKeyPair|null,\n writeKeys?:CryptoKeyPair|null,\n }\n ):Promise<T> {\n // encryption\n const exchange = keys?.exchangeKeys || await this._createExchangeKeys(\n extractable\n )\n // signatures\n const write = keys?.writeKeys || await this._createWriteKeys(extractable)\n\n const publicSigningKey = await getPublicKeyAsArrayBuffer(write)\n const did = await publicKeyToDid(\n new Uint8Array(publicSigningKey),\n this.TYPE === 'ecc' ? 'ed25519' : 'rsa'\n )\n\n const keysInstance = new this({\n keys: { exchange, write },\n did,\n hasPersisted: false,\n isSessionOnly: !!session\n })\n\n this._instance = keysInstance\n\n return keysInstance as T\n }\n\n static async exist (opts:{\n encryptionKeyName?:string,\n writeKeyName?:string\n } = {}):Promise<boolean> {\n const keys = await get(opts.writeKeyName || this.WRITE_KEY_NAME)\n const excahngeKeys = await get(opts.encryptionKeyName || this.EXCHANGE_KEY_NAME)\n if (!keys || !excahngeKeys) return false\n return true\n }\n\n /**\n * Restore some keys from indexedDB, or create a new keypair if it doesn't\n * exist yet.\n *\n * @param {{ encryptionKeyName, signingKeyName, session }} opts Strings to\n * use as keys in indexedDB, and a session boolean, is this in memory\n * only? Or can it be persisted.\n * @returns {Promise<AbstractKeys>}\n */\n static async load<T extends AbstractKeys = AbstractKeys> (\n this:ChildKeys & typeof AbstractKeys,\n opts:Partial<{\n encryptionKeyName:string,\n writeKeyName:string,\n session:boolean,\n extractable:boolean,\n }> = {\n session: false,\n }\n ):Promise<T> {\n if (this._instance) return this._instance // cache\n\n let hasPersisted = true\n let exchangeKeys:CryptoKeyPair|undefined = await get(\n opts.encryptionKeyName || this.EXCHANGE_KEY_NAME\n )\n let writeKeys:CryptoKeyPair|undefined = await get(\n opts.writeKeyName || this.WRITE_KEY_NAME\n )\n\n if (!exchangeKeys) {\n hasPersisted = false\n exchangeKeys = await this._createExchangeKeys(opts.extractable)\n }\n if (!writeKeys) {\n hasPersisted = false\n writeKeys = await this._createWriteKeys(opts.extractable)\n }\n\n const publicSigningKey = await getPublicKeyAsArrayBuffer(writeKeys)\n const did = await publicKeyToDid(\n new Uint8Array(publicSigningKey),\n this.TYPE === 'ecc' ? 'ed25519' : 'rsa'\n )\n\n const keys = new this({\n keys: { exchange: exchangeKeys, write: writeKeys },\n did,\n hasPersisted,\n isSessionOnly: !!opts.session\n }) as T\n\n this._instance = keys\n return keys\n }\n}\n\n/**\n * Encrypt the given message to the given public key. If an AES key is not\n * provided, one will be created. Use an AES key to encrypt the given\n * content, then we encrypt the AES key to the given public key.\n *\n * @param {{ content, publicKey }} opts The content to encrypt and\n * public key to encrypt to\n * @param {SymmKey|Uint8Array|string} [aesKey] An optional AES key to encrypt\n * to the given public key\n * @returns {Promise<ArrayBuffer>} The encrypted AES key, concattenated with\n * the encrypted content.\n */\nexport async function encryptTo (\n opts:{ content:string|Uint8Array; publicKey:CryptoKey|string; },\n aesKey?:SymmKey|Uint8Array|string,\n):Promise<ArrayBuffer> {\n const { content, publicKey } = opts\n const key = aesKey || await AES.create()\n const encryptedContent = await AES.encrypt(\n typeof content === 'string' ? fromString(content) : content,\n typeof key === 'string' ? await AES.import(key) : key,\n )\n const encryptedKey = await encryptKeyTo({ key, publicKey })\n\n return joinBufs(encryptedKey, encryptedContent)\n}\n\n/**\n * Encrypt the given AES key to the given public key. Return the encrypted AES\n * key concattenated with the cipher text.\n *\n * @param { content, publicKey } opts The content to encrypt and key to\n * encrypt to.\n * @param {SymmKey|Uint8Array|string} [aesKey] Optional -- the AES key. One will\n * be created if not passed in.\n * @returns {Promise<string>} The encrypted AES key concattenated with the\n * cipher text.\n */\nencryptTo.asString = async function (\n opts:{ content:string|Uint8Array; publicKey:CryptoKey|string },\n aesKey?:SymmKey|Uint8Array|string\n):Promise<string> {\n const joined = await encryptTo(opts, aesKey)\n return toString(new Uint8Array(joined), 'base64pad')\n}\n\nexport async function encryptKeyTo ({ key, publicKey }:{\n key:string|Uint8Array|CryptoKey;\n publicKey:CryptoKey|Uint8Array|string;\n}, format:'arraybuffer'):Promise<ArrayBuffer>\n\nexport async function encryptKeyTo ({ key, publicKey }:{\n key:string|Uint8Array|CryptoKey;\n publicKey:CryptoKey|Uint8Array|string;\n}, format:'uint8array'):Promise<Uint8Array>\n\nexport async function encryptKeyTo ({ key, publicKey }:{\n key:string|Uint8Array|CryptoKey;\n publicKey:CryptoKey|Uint8Array|string;\n}, format?:undefined):Promise<Uint8Array>\n\n/**\n * Encrypt the given content to the given public key. This is RSA encryption,\n * and should be used only to encrypt AES keys.\n *\n * @param {{ content, publicKey }} params The content to encrypt, and public key\n * to encrypt it to.\n * @returns {Promise<Uint8Array>}\n */\nexport async function encryptKeyTo ({ key, publicKey }:{\n key:string|Uint8Array|CryptoKey;\n publicKey:CryptoKey|Uint8Array|string;\n}, format?:'uint8array'|'arraybuffer'):Promise<Uint8Array|ArrayBuffer> {\n let _key:Uint8Array|string\n if (key instanceof CryptoKey) {\n _key = await AES.export(key)\n } else {\n _key = key\n }\n\n const buf = await rsaOperations.encrypt(_key, publicKey)\n if (format && format === 'arraybuffer') return buf\n return new Uint8Array(buf)\n}\n\nencryptKeyTo.asString = async function ({ key, publicKey }:{\n key:string|Uint8Array|CryptoKey;\n publicKey:CryptoKey|string|Uint8Array;\n}, format?:SupportedEncodings):Promise<string> {\n const asArr = await encryptKeyTo({ key, publicKey })\n return format ? toString(asArr, format) : toBase64(asArr)\n}\n\n// /**\n// * Decrypt the given message with the given key. We expect the `iv` to be\n// * prefixed to the encrypted message.\n// * @param msg The message to decrypt\n// * @param key The key to decrypt with\n// * @param opts Optional args for algorithm and stuff\n// * @returns {Promise<ArrayBuffer>}\n// */\n// async function decryptBytes (\n// msg:Msg,\n// key:CryptoKey|string,\n// opts?:Partial<{\n// alg:SymmAlgorithm;\n// length: SymmKeyLength;\n// iv: ArrayBuffer;\n// }>\n// ):Promise<ArrayBuffer> {\n// const cipherText = normalizeBase64ToBuf(msg)\n// const importedKey = typeof key === 'string' ?\n// await importKey(key, opts) :\n// key\n// // `iv` is prefixed to the cypher text\n// const iv = cipherText.slice(0, IV_LENGTH)\n// const cipherBytes = cipherText.slice(IV_LENGTH)\n// const msgBuff = await webcrypto.subtle.decrypt({\n// name: DEFAULT_SYMM_ALGORITHM,\n// iv\n// }, importedKey, cipherBytes)\n\n// return msgBuff\n// }\n\nexport async function getDeviceName (did:DID|string) {\n const hashedUsername = await sha256(\n new TextEncoder().encode(did.normalize('NFD'))\n )\n\n return toString(hashedUsername, 'base32').slice(0, 32)\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAA8D;AAC9D,wBAAkC;AAQlC,iBAAoB;AACpB,kBAIO;AACP,oBAIO;AAGP,yBAAc,2BAtBd;AAwBA,IAAAA,iBAAyC;AAkFlC,MAAe,gBAAf,MAAe,cAAa;AAAA;AAAA,EAW/B,YAAa,MAAc;AAV3B;AACA;AACA;AACA;AACA;AAOI,UAAM,EAAE,KAAK,IAAI;AACjB,SAAK,MAAM,KAAK;AAChB,SAAK,cAAc,KAAK;AACxB,SAAK,WAAW,KAAK;AACrB,SAAK,eAAe,KAAK;AACzB,SAAK,gBAAgB,CAAC,CAAC,KAAK;AAAA,EAChC;AAAA,EAoCA,0BAA2B,QAA4C;AACnE,WAAO,KAAK,kBAAkB,SAAS,MAAM;AAAA,EACjD;AAAA,EAEA,uBAAwB,QAA4C;AAChE,WAAO,KAAK,eAAe,SAAS,MAAM;AAAA,EAC9C;AAAA,EAEA,IAAI,iBAAkB;AAClB,UAAM,YAAY,KAAK,SAAS;AAChC,WAAO,OAAO,OAAO,WAAW;AAAA,MAC5B,UAAU,8BAAO,WAA+C;AAC5D,cAAM,cAAc,UAAM,yCAA0B,KAAK,QAAQ;AACjE,cAAM,aAAa,IAAI,WAAW,WAAW;AAC7C,eAAO,aAAS,6BAAS,YAAY,MAAM,QAAI,sBAAS,UAAU;AAAA,MACt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AO;AAAA,EACX;AAEA,QAAM,MAAM,MAAM,4BAAc,QAAQ,MAAM,SAAS;AACvD,MAAI,UAAU,WAAW,cAAe,QAAO;AAC/C,SAAO,IAAI,WAAW,GAAG;AAC7B;AAdsB;AAgBtB,aAAa,WAAW,eAAgB,EAAE,KAAK,UAAU,GAGtD,QAA4C;AAC3C,QAAM,QAAQ,MAAM,aAAa,EAAE,KAAK,UAAU,CAAC;AACnD,SAAO,aAAS,6BAAS,OAAO,MAAM,QAAI,sBAAS,KAAK;AAC5D;AAkCA,eAAsB,cAAe,KAAgB;AACjD,QAAM,iBAAiB,UAAM;AAAA,IACzB,IAAI,YAAY,EAAE,OAAO,IAAI,UAAU,KAAK,CAAC;AAAA,EACjD;AAEA,aAAO,6BAAS,gBAAgB,QAAQ,EAAE,MAAM,GAAG,EAAE;AACzD;AANsB;",
4
+ "sourcesContent": ["import { fromString, type SupportedEncodings, toString } from 'uint8arrays'\nimport { get, set, delMany } from 'idb-keyval'\nimport type {\n CharSize,\n Msg,\n SymmKeyLength,\n DID,\n SymmKey,\n} from './types.js'\nimport { AES } from './aes/index.js'\nimport {\n toBase64,\n joinBufs,\n sha256,\n} from './util.js'\nimport {\n rsaOperations,\n publicKeyToDid,\n getPublicKeyAsArrayBuffer,\n} from './crypto.js'\nimport { KeysDeletedError } from './errors.js'\n\nexport { publicKeyToDid, getPublicKeyAsArrayBuffer }\nexport { KeysDeletedError }\nexport * from './constants.js'\nexport type { DID }\nexport { getPublicKeyAsUint8Array } from './crypto.js'\nexport type SerializedKeys = {\n DID:DID;\n pulicExchangeKey:string;\n}\n\nexport interface RsaEncryptor {\n (\n content:string|Uint8Array,\n recipient?:CryptoKey|string,\n aesKey?:SymmKey|Uint8Array|string,\n keysize?:SymmKeyLength\n ):Promise<Uint8Array>\n}\n\nexport interface EccEncryptor {\n (\n content:string|Uint8Array,\n recipient?:CryptoKey|string,\n info?:string,\n aesKey?:SymmKey|Uint8Array|string,\n keysize?:SymmKeyLength\n ):Promise<Uint8Array>\n}\n\nexport interface RsaEncryptorAsString {\n (\n content:string|Uint8Array,\n recipient?:CryptoKey|string,\n aesKey?:SymmKey|Uint8Array|string,\n keysize?:SymmKeyLength\n ):Promise<string>\n}\n\nexport interface EccEncryptorAsString {\n (\n content:string|Uint8Array,\n recipient?:CryptoKey|string,\n info?:string,\n aesKey?:SymmKey|Uint8Array|string,\n keysize?:SymmKeyLength\n ):Promise<string>\n}\n\n// Type helpers to constrain implementations\nexport type RsaKeysType = AbstractKeys & {\n encrypt: RsaEncryptor;\n encryptAsString: RsaEncryptorAsString;\n}\n\nexport type EccKeysType = AbstractKeys & {\n encrypt: EccEncryptor;\n encryptAsString: EccEncryptorAsString;\n}\n\n/**\n * Args to constructor.\n */\nexport type KeyArgs = {\n keys:{ exchange:CryptoKeyPair, write:CryptoKeyPair };\n did:DID;\n hasPersisted:boolean;\n isSessionOnly?:boolean; // in memory only?\n exchangeKeyName?:string;\n writeKeyName?:string;\n}\n\n/**\n * The class that extends AbstractKeys\n */\ninterface ChildKeys<T extends AbstractKeys = AbstractKeys> {\n new (opts:KeyArgs):T;\n _instance:T;\n TYPE:'ecc'|'rsa';\n INFO:string;\n _createExchangeKeys(extractable?:boolean):Promise<CryptoKeyPair>\n _createWriteKeys(extractable?:boolean):Promise<CryptoKeyPair>\n}\n\n/**\n * The parent key. Doesn't implement the encrypt/sign functions.\n */\nexport abstract class AbstractKeys {\n DID:DID\n hasPersisted:boolean\n isSessionOnly:boolean\n /**\n * Have these keys been deleted? A deleted keypair is terminal -- the key\n * material is gone, and any use of it throws.\n */\n destroyed:boolean\n /**\n * The `indexedDB` names this keypair was loaded from, and the names\n * `persist` and `delete` will use.\n */\n readonly exchangeKeyName:string\n readonly writeKeyName:string\n // type:'ecc'|'rsa'\n static EXCHANGE_KEY_NAME:string // needs to be defined by child class\n static WRITE_KEY_NAME:string\n static _instance // a cache for indexedDB\n\n // the key material -- read it via the `exchangeKey`/`writeKey` getters,\n // which throw if this instance was deleted\n protected _exchangeKey:CryptoKeyPair|null\n protected _writeKey:CryptoKeyPair|null\n\n constructor (opts:KeyArgs) {\n const { keys } = opts\n const ctor = this.constructor as typeof AbstractKeys\n this.DID = opts.did\n this._exchangeKey = keys.exchange\n this._writeKey = keys.write\n this.hasPersisted = opts.hasPersisted\n this.isSessionOnly = !!opts.isSessionOnly\n this.destroyed = false\n this.exchangeKeyName = opts.exchangeKeyName || ctor.EXCHANGE_KEY_NAME\n this.writeKeyName = opts.writeKeyName || ctor.WRITE_KEY_NAME\n }\n\n get exchangeKey ():CryptoKeyPair {\n if (this.destroyed || !this._exchangeKey) throw new KeysDeletedError()\n return this._exchangeKey\n }\n\n get writeKey ():CryptoKeyPair {\n if (this.destroyed || !this._writeKey) throw new KeysDeletedError()\n return this._writeKey\n }\n\n /**\n * By default, encrypt the given data to yourself, as a \"note to self\".\n */\n abstract encrypt (\n content:string|Uint8Array,\n recipient?:CryptoKey|string|null,\n aesKeyOrInfo?:SymmKey|Uint8Array|string|null,\n keysizeOrAesKey?:SymmKeyLength|SymmKey|Uint8Array|string|null,\n keysize?:SymmKeyLength|null\n ):Promise<Uint8Array>\n\n abstract encryptAsString (\n content:string|Uint8Array,\n recipient?:CryptoKey|string|null,\n aesKeyOrInfo?:SymmKey|Uint8Array|string|null,\n keysizeOrAesKey?:SymmKeyLength|SymmKey|Uint8Array|string|null,\n keysize?:SymmKeyLength|null\n ):Promise<string>\n\n abstract decrypt(\n msg:string|Uint8Array|ArrayBuffer,\n publicKeyOrKeysize?:CryptoKey|string|SymmKeyLength|null,\n aesAlgorithm?:string|null,\n ):Promise<ArrayBuffer|Uint8Array>\n\n abstract decryptAsString(\n msg:string|Uint8Array|ArrayBuffer,\n publicKeyOrKeysize?:CryptoKey|string|SymmKeyLength|null,\n aesAlgorithm?:string|null,\n ):Promise<string>\n\n abstract sign(msg:Msg, charsize?:CharSize):Promise<Uint8Array>\n abstract signAsString(msg:string, charsize?:CharSize):Promise<string>\n\n publicExchangeKeyAsString (format?:SupportedEncodings):Promise<string> {\n return this.publicExchangeKey.asString(format)\n }\n\n publicWriteKeyAsString (format?:SupportedEncodings):Promise<string> {\n return this.publicWriteKey.asString(format)\n }\n\n get publicWriteKey () {\n const publicKey = this.writeKey.publicKey\n return Object.assign(publicKey, {\n asString: async (format?:SupportedEncodings):Promise<string> => {\n const arrayBuffer = await getPublicKeyAsArrayBuffer(this.writeKey)\n const uint8Array = new Uint8Array(arrayBuffer)\n return format ? toString(uint8Array, format) : toBase64(uint8Array)\n }\n })\n }\n\n get publicExchangeKey () {\n const publicKey = this.exchangeKey.publicKey\n return Object.assign(publicKey, {\n asString: async (format?: SupportedEncodings): Promise<string> => {\n const arrayBuffer = await getPublicKeyAsArrayBuffer(this.exchangeKey)\n const uint8Array = new Uint8Array(arrayBuffer)\n return format ? toString(uint8Array, format) : toBase64(uint8Array)\n }\n })\n }\n\n get privateWriteKey ():CryptoKey {\n return this.writeKey.privateKey\n }\n\n get privateExchangeKey ():CryptoKey {\n return this.exchangeKey.privateKey\n }\n\n /**\n * The machine-readable name for this keypair.\n */\n get deviceName ():Promise<string> {\n return AbstractKeys.deviceName(this.DID)\n }\n\n /**\n * Return a 32-character, DNS-friendly hash of the given DID.\n *\n * @param {DID} did A DID format string\n * @returns {string} 32 character, base32 hash of the DID\n */\n static deviceName (did:DID):Promise<string> {\n return getDeviceName(did)\n }\n\n /**\n * Get the relevant AES key.\n * - if this is an ECC keypair, then use DHKE with the given public key\n * - if this is RSA, use your private key to decrypt the given AES key\n */\n abstract getAesKey (\n publicKey?:CryptoKey|string|null,\n info?:string|null\n ):Promise<CryptoKey>\n\n /**\n * Save this keys instance to `indexedDB`.\n */\n async persist ():Promise<void> {\n if (this.destroyed) throw new KeysDeletedError()\n if (this.isSessionOnly) return\n\n await Promise.all([\n set(this.exchangeKeyName, this.exchangeKey),\n set(this.writeKeyName, this.writeKey)\n ])\n\n this.hasPersisted = true\n }\n\n /**\n * Delete this keypair. This deletes the keys from indexedDB, drops the\n * in-memory key material, and clears the instance cache, so `load` will\n * not hand out these keys again.\n *\n * After this, the instance is `destroyed` -- using it throws\n * a `KeysDeletedError`.\n */\n async delete ():Promise<void> {\n const exchangeName = this.exchangeKeyName\n const writeName = this.writeKeyName\n await delMany([exchangeName, writeName])\n const ctor = this.constructor as typeof AbstractKeys\n ctor._invalidate(exchangeName, writeName)\n this._destroy()\n }\n\n /**\n * Drop the in-memory key material. Internal -- call `delete` instead.\n */\n _destroy ():void {\n this.destroyed = true\n this.hasPersisted = false\n this._exchangeKey = null\n this._writeKey = null\n }\n\n /**\n * If the cached instance was loaded from the given names, then its keys\n * are gone too. Destroy it, and clear the cache. Internal.\n */\n static _invalidate (exchangeName:string, writeName:string):void {\n const cached:AbstractKeys|null = this._instance\n if (!cached) return\n if (cached.exchangeKeyName !== exchangeName) return\n if (cached.writeKeyName !== writeName) return\n cached._destroy()\n this._instance = null\n }\n\n /**\n * Delete a stored keypair without loading it first. Deletes the keys from\n * indexedDB, and destroys the cached instance, if there is one for\n * these names.\n *\n * @param {{ encryptionKeyName, writeKeyName }} [opts] The indexedDB names\n * to delete. Defaults to this class's names.\n */\n static async delete (opts:{\n encryptionKeyName?:string,\n writeKeyName?:string\n } = {}):Promise<void> {\n const exchangeName = opts.encryptionKeyName || this.EXCHANGE_KEY_NAME\n const writeName = opts.writeKeyName || this.WRITE_KEY_NAME\n await delMany([exchangeName, writeName])\n this._invalidate(exchangeName, writeName)\n }\n\n abstract toJson (format?:SupportedEncodings):Promise<{\n DID:DID;\n publicExchangeKey:string;\n }>\n\n /**\n * Return a 32-character, DNS friendly hash of the public signing key.\n *\n * @returns {Promise<string>}\n */\n async getDeviceName ():Promise<string> {\n return AbstractKeys.deviceName(this.DID)\n }\n\n static _createExchangeKeys (_extractable?:boolean):Promise<CryptoKeyPair> {\n throw new Error('The child should implement this')\n }\n\n static _createWriteKeys (_extractable?:boolean):Promise<CryptoKeyPair> {\n throw new Error('The child should implement this')\n }\n\n static async create<T extends AbstractKeys> (\n this:ChildKeys,\n session?:boolean,\n extractable?:boolean,\n keys?:{\n exchangeKeys?:CryptoKeyPair|null,\n writeKeys?:CryptoKeyPair|null,\n }\n ):Promise<T> {\n // encryption\n const exchange = keys?.exchangeKeys || await this._createExchangeKeys(\n extractable\n )\n // signatures\n const write = keys?.writeKeys || await this._createWriteKeys(extractable)\n\n const publicSigningKey = await getPublicKeyAsArrayBuffer(write)\n const did = await publicKeyToDid(\n new Uint8Array(publicSigningKey),\n this.TYPE === 'ecc' ? 'ed25519' : 'rsa'\n )\n\n const keysInstance = new this({\n keys: { exchange, write },\n did,\n hasPersisted: false,\n isSessionOnly: !!session\n })\n\n this._instance = keysInstance\n\n return keysInstance as T\n }\n\n static async exist (opts:{\n encryptionKeyName?:string,\n writeKeyName?:string\n } = {}):Promise<boolean> {\n const keys = await get(opts.writeKeyName || this.WRITE_KEY_NAME)\n const excahngeKeys = await get(opts.encryptionKeyName || this.EXCHANGE_KEY_NAME)\n if (!keys || !excahngeKeys) return false\n return true\n }\n\n /**\n * Restore some keys from indexedDB, or create a new keypair if it doesn't\n * exist yet.\n *\n * By default this saves the keys to `indexedDB` before returning, so the\n * keypair you get back survives a page reload. Pass `{ persist: false }`\n * to skip that and call `.persist()` yourself. Session keys are never\n * written to `indexedDB`, so `{ session: true }` wins over `persist`.\n *\n * @param {{ encryptionKeyName, signingKeyName, session, persist }} opts\n * Strings to use as keys in indexedDB, a session boolean -- is this in\n * memory only? Or can it be persisted -- and a persist boolean.\n * @returns {Promise<AbstractKeys>}\n */\n static async load<T extends AbstractKeys = AbstractKeys> (\n this:ChildKeys & typeof AbstractKeys,\n opts:Partial<{\n encryptionKeyName:string,\n writeKeyName:string,\n session:boolean,\n extractable:boolean,\n persist:boolean,\n }> = {\n session: false,\n }\n ):Promise<T> {\n const shouldPersist = opts.persist !== false\n const exchangeKeyName = opts.encryptionKeyName || this.EXCHANGE_KEY_NAME\n const writeKeyName = opts.writeKeyName || this.WRITE_KEY_NAME\n\n // cache -- only if it is for the same indexedDB entries\n const cached:AbstractKeys|null = this._instance\n if (\n cached &&\n !cached.destroyed &&\n cached.exchangeKeyName === exchangeKeyName &&\n cached.writeKeyName === writeKeyName\n ) {\n if (shouldPersist && !cached.hasPersisted) await cached.persist()\n return cached as T\n }\n\n let hasPersisted = true\n let exchangeKeys:CryptoKeyPair|undefined = await get(exchangeKeyName)\n let writeKeys:CryptoKeyPair|undefined = await get(writeKeyName)\n\n if (!exchangeKeys) {\n hasPersisted = false\n exchangeKeys = await this._createExchangeKeys(opts.extractable)\n }\n if (!writeKeys) {\n hasPersisted = false\n writeKeys = await this._createWriteKeys(opts.extractable)\n }\n\n const publicSigningKey = await getPublicKeyAsArrayBuffer(writeKeys)\n const did = await publicKeyToDid(\n new Uint8Array(publicSigningKey),\n this.TYPE === 'ecc' ? 'ed25519' : 'rsa'\n )\n\n const keys = new this({\n keys: { exchange: exchangeKeys, write: writeKeys },\n did,\n hasPersisted,\n isSessionOnly: !!opts.session,\n exchangeKeyName,\n writeKeyName\n }) as T\n\n this._instance = keys\n if (shouldPersist && !hasPersisted) await keys.persist()\n return keys\n }\n}\n\n/**\n * Encrypt the given message to the given public key. If an AES key is not\n * provided, one will be created. Use an AES key to encrypt the given\n * content, then we encrypt the AES key to the given public key.\n *\n * @param {{ content, publicKey }} opts The content to encrypt and\n * public key to encrypt to\n * @param {SymmKey|Uint8Array|string} [aesKey] An optional AES key to encrypt\n * to the given public key\n * @returns {Promise<ArrayBuffer>} The encrypted AES key, concattenated with\n * the encrypted content.\n */\nexport async function encryptTo (\n opts:{ content:string|Uint8Array; publicKey:CryptoKey|string; },\n aesKey?:SymmKey|Uint8Array|string,\n):Promise<ArrayBuffer> {\n const { content, publicKey } = opts\n const key = aesKey || await AES.create()\n const encryptedContent = await AES.encrypt(\n typeof content === 'string' ? fromString(content) : content,\n typeof key === 'string' ? await AES.import(key) : key,\n )\n const encryptedKey = await encryptKeyTo({ key, publicKey })\n\n return joinBufs(encryptedKey, encryptedContent)\n}\n\n/**\n * Encrypt the given AES key to the given public key. Return the encrypted AES\n * key concattenated with the cipher text.\n *\n * @param { content, publicKey } opts The content to encrypt and key to\n * encrypt to.\n * @param {SymmKey|Uint8Array|string} [aesKey] Optional -- the AES key. One will\n * be created if not passed in.\n * @returns {Promise<string>} The encrypted AES key concattenated with the\n * cipher text.\n */\nencryptTo.asString = async function (\n opts:{ content:string|Uint8Array; publicKey:CryptoKey|string },\n aesKey?:SymmKey|Uint8Array|string\n):Promise<string> {\n const joined = await encryptTo(opts, aesKey)\n return toString(new Uint8Array(joined), 'base64pad')\n}\n\nexport async function encryptKeyTo ({ key, publicKey }:{\n key:string|Uint8Array|CryptoKey;\n publicKey:CryptoKey|Uint8Array|string;\n}, format:'arraybuffer'):Promise<ArrayBuffer>\n\nexport async function encryptKeyTo ({ key, publicKey }:{\n key:string|Uint8Array|CryptoKey;\n publicKey:CryptoKey|Uint8Array|string;\n}, format:'uint8array'):Promise<Uint8Array>\n\nexport async function encryptKeyTo ({ key, publicKey }:{\n key:string|Uint8Array|CryptoKey;\n publicKey:CryptoKey|Uint8Array|string;\n}, format?:undefined):Promise<Uint8Array>\n\n/**\n * Encrypt the given content to the given public key. This is RSA encryption,\n * and should be used only to encrypt AES keys.\n *\n * @param {{ content, publicKey }} params The content to encrypt, and public key\n * to encrypt it to.\n * @returns {Promise<Uint8Array>}\n */\nexport async function encryptKeyTo ({ key, publicKey }:{\n key:string|Uint8Array|CryptoKey;\n publicKey:CryptoKey|Uint8Array|string;\n}, format?:'uint8array'|'arraybuffer'):Promise<Uint8Array|ArrayBuffer> {\n let _key:Uint8Array|string\n if (key instanceof CryptoKey) {\n _key = await AES.export(key)\n } else {\n _key = key\n }\n\n const buf = await rsaOperations.encrypt(_key, publicKey)\n if (format && format === 'arraybuffer') return buf\n return new Uint8Array(buf)\n}\n\nencryptKeyTo.asString = async function ({ key, publicKey }:{\n key:string|Uint8Array|CryptoKey;\n publicKey:CryptoKey|string|Uint8Array;\n}, format?:SupportedEncodings):Promise<string> {\n const asArr = await encryptKeyTo({ key, publicKey })\n return format ? toString(asArr, format) : toBase64(asArr)\n}\n\n// /**\n// * Decrypt the given message with the given key. We expect the `iv` to be\n// * prefixed to the encrypted message.\n// * @param msg The message to decrypt\n// * @param key The key to decrypt with\n// * @param opts Optional args for algorithm and stuff\n// * @returns {Promise<ArrayBuffer>}\n// */\n// async function decryptBytes (\n// msg:Msg,\n// key:CryptoKey|string,\n// opts?:Partial<{\n// alg:SymmAlgorithm;\n// length: SymmKeyLength;\n// iv: ArrayBuffer;\n// }>\n// ):Promise<ArrayBuffer> {\n// const cipherText = normalizeBase64ToBuf(msg)\n// const importedKey = typeof key === 'string' ?\n// await importKey(key, opts) :\n// key\n// // `iv` is prefixed to the cypher text\n// const iv = cipherText.slice(0, IV_LENGTH)\n// const cipherBytes = cipherText.slice(IV_LENGTH)\n// const msgBuff = await webcrypto.subtle.decrypt({\n// name: DEFAULT_SYMM_ALGORITHM,\n// iv\n// }, importedKey, cipherBytes)\n\n// return msgBuff\n// }\n\nexport async function getDeviceName (did:DID|string) {\n const hashedUsername = await sha256(\n new TextEncoder().encode(did.normalize('NFD'))\n )\n\n return toString(hashedUsername, 'base32').slice(0, 32)\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAA8D;AAC9D,wBAAkC;AAQlC,iBAAoB;AACpB,kBAIO;AACP,oBAIO;AACP,oBAAiC;AAIjC,yBAAc,2BAxBd;AA0BA,IAAAA,iBAAyC;AAkFlC,MAAe,gBAAf,MAAe,cAAa;AAAA,EAyB/B,YAAa,MAAc;AAxB3B;AACA;AACA;AAKA;AAAA;AAAA;AAAA;AAAA;AAKA;AAAA;AAAA;AAAA;AAAA,wBAAS;AACT,wBAAS;AAQT;AAAA;AAAA;AAAA,wBAAU;AACV,wBAAU;AAGN,UAAM,EAAE,KAAK,IAAI;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;",
6
6
  "names": ["import_crypto"]
7
7
  }
package/dist/_base.d.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  import { type SupportedEncodings } from 'uint8arrays';
2
2
  import type { CharSize, Msg, SymmKeyLength, DID, SymmKey } from './types.js';
3
3
  import { publicKeyToDid, getPublicKeyAsArrayBuffer } from './crypto.js';
4
+ import { KeysDeletedError } from './errors.js';
4
5
  export { publicKeyToDid, getPublicKeyAsArrayBuffer };
6
+ export { KeysDeletedError };
5
7
  export * from './constants.js';
6
8
  export type { DID };
7
9
  export { getPublicKeyAsUint8Array } from './crypto.js';
@@ -59,14 +61,27 @@ interface ChildKeys<T extends AbstractKeys = AbstractKeys> {
59
61
  */
60
62
  export declare abstract class AbstractKeys {
61
63
  DID: DID;
62
- exchangeKey: CryptoKeyPair;
63
- writeKey: CryptoKeyPair;
64
64
  hasPersisted: boolean;
65
65
  isSessionOnly: boolean;
66
+ /**
67
+ * Have these keys been deleted? A deleted keypair is terminal -- the key
68
+ * material is gone, and any use of it throws.
69
+ */
70
+ destroyed: boolean;
71
+ /**
72
+ * The `indexedDB` names this keypair was loaded from, and the names
73
+ * `persist` and `delete` will use.
74
+ */
75
+ readonly exchangeKeyName: string;
76
+ readonly writeKeyName: string;
66
77
  static EXCHANGE_KEY_NAME: string;
67
78
  static WRITE_KEY_NAME: string;
68
79
  static _instance: any;
80
+ protected _exchangeKey: CryptoKeyPair | null;
81
+ protected _writeKey: CryptoKeyPair | null;
69
82
  constructor(opts: KeyArgs);
83
+ get exchangeKey(): CryptoKeyPair;
84
+ get writeKey(): CryptoKeyPair;
70
85
  /**
71
86
  * By default, encrypt the given data to yourself, as a "note to self".
72
87
  */
@@ -108,9 +123,35 @@ export declare abstract class AbstractKeys {
108
123
  */
109
124
  persist(): Promise<void>;
110
125
  /**
111
- * Delete the keys stored in indexedDB.
126
+ * Delete this keypair. This deletes the keys from indexedDB, drops the
127
+ * in-memory key material, and clears the instance cache, so `load` will
128
+ * not hand out these keys again.
129
+ *
130
+ * After this, the instance is `destroyed` -- using it throws
131
+ * a `KeysDeletedError`.
112
132
  */
113
133
  delete(): Promise<void>;
134
+ /**
135
+ * Drop the in-memory key material. Internal -- call `delete` instead.
136
+ */
137
+ _destroy(): void;
138
+ /**
139
+ * If the cached instance was loaded from the given names, then its keys
140
+ * are gone too. Destroy it, and clear the cache. Internal.
141
+ */
142
+ static _invalidate(exchangeName: string, writeName: string): void;
143
+ /**
144
+ * Delete a stored keypair without loading it first. Deletes the keys from
145
+ * indexedDB, and destroys the cached instance, if there is one for
146
+ * these names.
147
+ *
148
+ * @param {{ encryptionKeyName, writeKeyName }} [opts] The indexedDB names
149
+ * to delete. Defaults to this class's names.
150
+ */
151
+ static delete(opts?: {
152
+ encryptionKeyName?: string;
153
+ writeKeyName?: string;
154
+ }): Promise<void>;
114
155
  abstract toJson(format?: SupportedEncodings): Promise<{
115
156
  DID: DID;
116
157
  publicExchangeKey: string;
@@ -135,9 +176,14 @@ export declare abstract class AbstractKeys {
135
176
  * Restore some keys from indexedDB, or create a new keypair if it doesn't
136
177
  * exist yet.
137
178
  *
138
- * @param {{ encryptionKeyName, signingKeyName, session }} opts Strings to
139
- * use as keys in indexedDB, and a session boolean, is this in memory
140
- * only? Or can it be persisted.
179
+ * By default this saves the keys to `indexedDB` before returning, so the
180
+ * keypair you get back survives a page reload. Pass `{ persist: false }`
181
+ * to skip that and call `.persist()` yourself. Session keys are never
182
+ * written to `indexedDB`, so `{ session: true }` wins over `persist`.
183
+ *
184
+ * @param {{ encryptionKeyName, signingKeyName, session, persist }} opts
185
+ * Strings to use as keys in indexedDB, a session boolean -- is this in
186
+ * memory only? Or can it be persisted -- and a persist boolean.
141
187
  * @returns {Promise<AbstractKeys>}
142
188
  */
143
189
  static load<T extends AbstractKeys = AbstractKeys>(this: ChildKeys & typeof AbstractKeys, opts?: Partial<{
@@ -145,6 +191,7 @@ export declare abstract class AbstractKeys {
145
191
  writeKeyName: string;
146
192
  session: boolean;
147
193
  extractable: boolean;
194
+ persist: boolean;
148
195
  }>): Promise<T>;
149
196
  }
150
197
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"_base.d.ts","sourceRoot":"","sources":["../src/_base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,kBAAkB,EAAY,MAAM,aAAa,CAAA;AAE3E,OAAO,KAAK,EACR,QAAQ,EACR,GAAG,EACH,aAAa,EACb,GAAG,EACH,OAAO,EACV,MAAM,YAAY,CAAA;AAOnB,OAAO,EAEH,cAAc,EACd,yBAAyB,EAC5B,MAAM,aAAa,CAAA;AAEpB,OAAO,EAAE,cAAc,EAAE,yBAAyB,EAAE,CAAA;AACpD,cAAc,gBAAgB,CAAA;AAC9B,YAAY,EAAE,GAAG,EAAE,CAAA;AACnB,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAA;AACtD,MAAM,MAAM,cAAc,GAAG;IACzB,GAAG,EAAC,GAAG,CAAC;IACR,gBAAgB,EAAC,MAAM,CAAC;CAC3B,CAAA;AAED,MAAM,WAAW,YAAY;IACzB,CACI,OAAO,EAAC,MAAM,GAAC,UAAU,EACzB,SAAS,CAAC,EAAC,SAAS,GAAC,MAAM,EAC3B,MAAM,CAAC,EAAC,OAAO,GAAC,UAAU,GAAC,MAAM,EACjC,OAAO,CAAC,EAAC,aAAa,GACxB,OAAO,CAAC,UAAU,CAAC,CAAA;CACxB;AAED,MAAM,WAAW,YAAY;IACzB,CACI,OAAO,EAAC,MAAM,GAAC,UAAU,EACzB,SAAS,CAAC,EAAC,SAAS,GAAC,MAAM,EAC3B,IAAI,CAAC,EAAC,MAAM,EACZ,MAAM,CAAC,EAAC,OAAO,GAAC,UAAU,GAAC,MAAM,EACjC,OAAO,CAAC,EAAC,aAAa,GACxB,OAAO,CAAC,UAAU,CAAC,CAAA;CACxB;AAED,MAAM,WAAW,oBAAoB;IACjC,CACI,OAAO,EAAC,MAAM,GAAC,UAAU,EACzB,SAAS,CAAC,EAAC,SAAS,GAAC,MAAM,EAC3B,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