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