@icp-sdk/vetkeys 0.6.0 → 0.7.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.
@@ -1,38 +1,8 @@
1
- import { TransportSecretKey as v, EncryptedVetKey as f, DerivedPublicKey as g, DerivedKeyMaterial as m } from "./index.es.js";
2
- import { A as w } from "./actor-CFYb2LZx.mjs";
3
- function y(r) {
4
- return new Promise((e, t) => {
5
- r.oncomplete = r.onsuccess = () => e(r.result), r.onabort = r.onerror = () => t(r.error);
6
- });
7
- }
8
- function h(r, e) {
9
- let t;
10
- const n = () => {
11
- if (t)
12
- return t;
13
- const a = indexedDB.open(r);
14
- return a.onupgradeneeded = () => a.result.createObjectStore(e), t = y(a), t.then((i) => {
15
- i.onclose = () => t = void 0;
16
- }, () => {
17
- t = void 0;
18
- }), t;
19
- };
20
- return (a, i) => n().then((s) => i(s.transaction(e, a).objectStore(e)));
21
- }
22
- let _;
23
- function p() {
24
- return _ || (_ = h("keyval-store", "keyval")), _;
25
- }
26
- function k(r, e = p()) {
27
- return e("readonly", (t) => y(t.get(r)));
28
- }
29
- function E(r, e, t = p()) {
30
- return t("readwrite", (n) => (n.put(e, r), y(n.transaction)));
31
- }
32
- function V(r = p()) {
33
- return r("readwrite", (e) => (e.clear(), y(e.transaction)));
34
- }
35
- class K {
1
+ import { T as u, E as p, a as d, D as h } from "./utils-CiynM__c.mjs";
2
+ import { createStore as v, get as g, set as f, clear as m } from "idb-keyval";
3
+ import { Actor as w } from "@icp-sdk/core/agent";
4
+ import "@icp-sdk/core/candid";
5
+ class k {
36
6
  #e = /* @__PURE__ */ new Map();
37
7
  get(e) {
38
8
  return Promise.resolve(this.#e.get(e));
@@ -54,19 +24,19 @@ class C {
54
24
  * supports only a single object store per database.
55
25
  */
56
26
  constructor(e = "ic-vetkeys") {
57
- this.#e = h(e, "derived-key-material");
27
+ this.#e = v(e, "derived-key-material");
58
28
  }
59
29
  async get(e) {
60
- return k(e, this.#e);
30
+ return g(e, this.#e);
61
31
  }
62
32
  async set(e, t) {
63
- await E(e, t, this.#e);
33
+ await f(e, t, this.#e);
64
34
  }
65
35
  async clear() {
66
- await V(this.#e);
36
+ await m(this.#e);
67
37
  }
68
38
  }
69
- const A = ({ IDL: r }) => {
39
+ const E = ({ IDL: r }) => {
70
40
  const e = r.Record({ inner: r.Vec(r.Nat8) }), t = r.Variant({
71
41
  Read: r.Null,
72
42
  ReadWrite: r.Null,
@@ -76,16 +46,16 @@ const A = ({ IDL: r }) => {
76
46
  keyvals: r.Vec(r.Tuple(e, e)),
77
47
  map_name: e,
78
48
  map_owner: r.Principal
79
- }), a = r.Variant({ Ok: r.Opt(e), Err: r.Text }), i = r.Variant({
49
+ }), a = r.Variant({ Ok: r.Opt(e), Err: r.Text }), s = r.Variant({
80
50
  Ok: r.Vec(r.Tuple(e, e)),
81
51
  Err: r.Text
82
- }), s = r.Variant({ Ok: e, Err: r.Text }), l = r.Variant({
52
+ }), i = r.Variant({ Ok: e, Err: r.Text }), l = r.Variant({
83
53
  Ok: r.Vec(r.Tuple(r.Principal, t)),
84
54
  Err: r.Text
85
55
  }), o = r.Variant({
86
56
  Ok: r.Opt(t),
87
57
  Err: r.Text
88
- }), u = r.Variant({ Ok: r.Vec(e), Err: r.Text });
58
+ }), y = r.Variant({ Ok: r.Vec(e), Err: r.Text });
89
59
  return r.Service({
90
60
  get_accessible_shared_map_names: r.Func(
91
61
  [],
@@ -116,12 +86,12 @@ const A = ({ IDL: r }) => {
116
86
  ),
117
87
  get_encrypted_values_for_map: r.Func(
118
88
  [r.Principal, e],
119
- [i],
89
+ [s],
120
90
  ["query"]
121
91
  ),
122
92
  get_encrypted_vetkey: r.Func(
123
93
  [r.Principal, e, e],
124
- [s],
94
+ [i],
125
95
  []
126
96
  ),
127
97
  get_owned_non_empty_map_names: r.Func(
@@ -150,7 +120,7 @@ const A = ({ IDL: r }) => {
150
120
  [a],
151
121
  []
152
122
  ),
153
- remove_map_values: r.Func([r.Principal, e], [u], []),
123
+ remove_map_values: r.Func([r.Principal, e], [y], []),
154
124
  remove_user: r.Func(
155
125
  [r.Principal, e, r.Principal],
156
126
  [o],
@@ -166,7 +136,7 @@ const A = ({ IDL: r }) => {
166
136
  class R {
167
137
  actor;
168
138
  constructor(e, t) {
169
- this.actor = w.createActor(A, {
139
+ this.actor = w.createActor(E, {
170
140
  agent: e,
171
141
  canisterId: t
172
142
  });
@@ -268,7 +238,7 @@ class O {
268
238
  * ```
269
239
  */
270
240
  constructor(e, t) {
271
- this.canisterClient = e, this.#e = t?.cache ?? new K();
241
+ this.canisterClient = e, this.#e = t?.cache ?? new k();
272
242
  }
273
243
  /**
274
244
  * Retrieves a list of maps that were shared with the user and the user still has access to.
@@ -302,19 +272,19 @@ class O {
302
272
  async getAllAccessibleValues() {
303
273
  const e = await this.canisterClient.get_all_accessible_encrypted_values(), t = [];
304
274
  for (const [n, a] of e) {
305
- const i = Uint8Array.from(n[1].inner), s = [];
275
+ const s = Uint8Array.from(n[1].inner), i = [];
306
276
  for (const [l, o] of a) {
307
- const u = Uint8Array.from(l.inner), d = await this.decryptFor(
277
+ const y = Uint8Array.from(l.inner), _ = await this.decryptFor(
308
278
  n[0],
309
- i,
310
- u,
279
+ s,
280
+ y,
311
281
  Uint8Array.from(o.inner)
312
282
  );
313
- s.push([u, d]);
283
+ i.push([y, _]);
314
284
  }
315
285
  t.push([
316
286
  [n[0], Uint8Array.from(n[1].inner)],
317
- s
287
+ i
318
288
  ]);
319
289
  }
320
290
  return t;
@@ -327,22 +297,22 @@ class O {
327
297
  async getAllAccessibleMaps() {
328
298
  const e = await this.canisterClient.get_all_accessible_encrypted_maps(), t = [];
329
299
  for (const n of e) {
330
- const a = Uint8Array.from(n.map_name.inner), i = [];
300
+ const a = Uint8Array.from(n.map_name.inner), s = [];
331
301
  for (const [
332
- s,
302
+ i,
333
303
  l
334
304
  ] of n.keyvals) {
335
- const o = Uint8Array.from(s.inner), u = await this.decryptFor(
305
+ const o = Uint8Array.from(i.inner), y = await this.decryptFor(
336
306
  n.map_owner,
337
307
  a,
338
308
  o,
339
309
  Uint8Array.from(l.inner)
340
310
  );
341
- i.push([o, u]);
311
+ s.push([o, y]);
342
312
  }
343
313
  t.push({
344
314
  accessControl: n.access_control,
345
- keyvals: i,
315
+ keyvals: s,
346
316
  mapName: a,
347
317
  mapOwner: n.map_owner
348
318
  });
@@ -399,22 +369,22 @@ class O {
399
369
  if ("Err" in n)
400
370
  throw Error(n.Err);
401
371
  const a = new Array();
402
- for (const [s, l] of n.Ok)
372
+ for (const [i, l] of n.Ok)
403
373
  a.push([
404
- Uint8Array.from(s.inner),
374
+ Uint8Array.from(i.inner),
405
375
  Uint8Array.from(l.inner)
406
376
  ]);
407
- const i = new Array();
408
- for (const [s, l] of n.Ok) {
409
- const o = Uint8Array.from(s.inner), u = await this.decryptFor(
377
+ const s = new Array();
378
+ for (const [i, l] of n.Ok) {
379
+ const o = Uint8Array.from(i.inner), y = await this.decryptFor(
410
380
  e,
411
381
  t,
412
382
  o,
413
383
  Uint8Array.from(l.inner)
414
384
  );
415
- i.push([o, u]);
385
+ s.push([o, y]);
416
386
  }
417
- return i;
387
+ return s;
418
388
  }
419
389
  /**
420
390
  * Stores an encrypted value in a map.
@@ -434,24 +404,24 @@ class O {
434
404
  * @throws Error if the operation fails
435
405
  */
436
406
  async setValue(e, t, n, a) {
437
- const i = await this.encryptFor(
407
+ const s = await this.encryptFor(
438
408
  e,
439
409
  t,
440
410
  n,
441
411
  a
442
- ), s = await this.canisterClient.insert_encrypted_value(
412
+ ), i = await this.canisterClient.insert_encrypted_value(
443
413
  e,
444
414
  c(t),
445
415
  c(n),
446
- { inner: i }
416
+ { inner: s }
447
417
  );
448
- if ("Err" in s)
449
- throw Error(s.Err);
450
- return s.Ok.length === 0 ? void 0 : await this.decryptFor(
418
+ if ("Err" in i)
419
+ throw Error(i.Err);
420
+ return i.Ok.length === 0 ? void 0 : await this.decryptFor(
451
421
  e,
452
422
  t,
453
423
  n,
454
- Uint8Array.from(s.Ok[0].inner)
424
+ Uint8Array.from(i.Ok[0].inner)
455
425
  );
456
426
  }
457
427
  /**
@@ -543,16 +513,16 @@ class O {
543
513
  * @throws Error if the operation fails
544
514
  */
545
515
  async setUserRights(e, t, n, a) {
546
- const i = await this.canisterClient.set_user_rights(
516
+ const s = await this.canisterClient.set_user_rights(
547
517
  e,
548
518
  c(t),
549
519
  n,
550
520
  a
551
521
  );
552
- if ("Err" in i) throw Error(i.Err);
553
- if (i.Ok.length > 1)
522
+ if ("Err" in s) throw Error(s.Err);
523
+ if (s.Ok.length > 1)
554
524
  throw Error("Unexpected result from set_user_rights");
555
- return i.Ok.length === 0 ? void 0 : i.Ok[0];
525
+ return s.Ok.length === 0 ? void 0 : s.Ok[0];
556
526
  }
557
527
  /**
558
528
  * Checks a user's access rights.
@@ -631,7 +601,7 @@ class O {
631
601
  * @throws Error if the operation fails
632
602
  */
633
603
  async getDerivedKeyMaterial(e, t) {
634
- const n = v.random(), a = await this.canisterClient.get_encrypted_vetkey(
604
+ const n = u.random(), a = await this.canisterClient.get_encrypted_vetkey(
635
605
  e,
636
606
  c(t),
637
607
  c(n.publicKeyBytes())
@@ -639,14 +609,14 @@ class O {
639
609
  if ("Err" in a)
640
610
  throw Error(a.Err);
641
611
  {
642
- const i = Uint8Array.from(a.Ok.inner), s = await this.getVetkeyVerificationKey(), l = new Uint8Array([
612
+ const s = Uint8Array.from(a.Ok.inner), i = await this.getVetkeyVerificationKey(), l = new Uint8Array([
643
613
  e.toUint8Array().length,
644
614
  ...e.toUint8Array(),
645
615
  ...t
646
- ]), o = f.deserialize(i), u = g.deserialize(s);
616
+ ]), o = p.deserialize(s), y = d.deserialize(i);
647
617
  return await o.decryptAndVerify(
648
618
  n,
649
- u,
619
+ y,
650
620
  l
651
621
  ).asDerivedKeyMaterial();
652
622
  }
@@ -687,19 +657,19 @@ class O {
687
657
  * @returns Promise resolving to the derived key material
688
658
  */
689
659
  async getDerivedKeyMaterialOrFetchIfNeeded(e, t) {
690
- const n = M(e, t), a = await this.#e.get(n);
660
+ const n = V(e, t), a = await this.#e.get(n);
691
661
  if (a)
692
- return await m.fromCryptoKey(
662
+ return await h.fromCryptoKey(
693
663
  a
694
664
  );
695
- const i = await this.getDerivedKeyMaterial(
665
+ const s = await this.getDerivedKeyMaterial(
696
666
  e,
697
667
  t
698
668
  );
699
669
  return await this.#e.set(
700
670
  n,
701
- i.getCryptoKey()
702
- ), i;
671
+ s.getCryptoKey()
672
+ ), s;
703
673
  }
704
674
  /**
705
675
  * Clears all cached derived key material.
@@ -716,10 +686,10 @@ class O {
716
686
  await this.#e.clear();
717
687
  }
718
688
  }
719
- function M(r, e) {
720
- return `${r.toString()}|${F(e)}`;
689
+ function V(r, e) {
690
+ return `${r.toString()}|${K(e)}`;
721
691
  }
722
- function F(r) {
692
+ function K(r) {
723
693
  let e = "";
724
694
  for (const t of r)
725
695
  e += t.toString(16).padStart(2, "0");
@@ -731,6 +701,6 @@ function c(r) {
731
701
  export {
732
702
  R as DefaultEncryptedMapsClient,
733
703
  O as EncryptedMaps,
734
- K as InMemoryDerivedKeyMaterialCache,
704
+ k as InMemoryDerivedKeyMaterialCache,
735
705
  C as IndexedDbDerivedKeyMaterialCache
736
706
  };