@fireproof/core 0.20.0-dev-preview-25 → 0.20.0-dev-preview-26

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.
package/index.d.cts CHANGED
@@ -113,10 +113,11 @@ declare class keysByFingerprint implements KeysByFingerprint {
113
113
  readonly keys: Record<string, keyWithFingerPrint>;
114
114
  readonly keybag: KeyBag;
115
115
  readonly name: string;
116
+ readonly id: string;
116
117
  static from(keyBag: KeyBag, named: KeysItem): Promise<KeysByFingerprint>;
117
118
  constructor(keyBag: KeyBag, name: string);
118
119
  get(fingerPrint?: Uint8Array | string): Promise<KeyWithFingerPrint | undefined>;
119
- upsert(materialStrOrUint8: string | Uint8Array, def: boolean, keyBagAction?: boolean): Promise<Result<KeyUpsertResult>>;
120
+ upsert(materialStrOrUint8: string | Uint8Array, def?: boolean, keyBagAction?: boolean): Promise<Result<KeyUpsertResult>>;
120
121
  asKeysItem(): Promise<KeysItem>;
121
122
  }
122
123
  declare class KeyBag {
@@ -463,9 +464,10 @@ interface KeyUpsertResult {
463
464
  readonly kfp: KeyWithFingerPrint;
464
465
  }
465
466
  interface KeysByFingerprint {
467
+ readonly id: string;
466
468
  readonly name: string;
467
469
  get(fingerPrint?: Uint8Array | string): Promise<KeyWithFingerPrint | undefined>;
468
- upsert(key: string | Uint8Array, def: boolean): Promise<Result<KeyUpsertResult>>;
470
+ upsert(key: string | Uint8Array, def?: boolean): Promise<Result<KeyUpsertResult>>;
469
471
  asKeysItem(): Promise<KeysItem>;
470
472
  }
471
473
  interface CryptoAction {
package/index.d.ts CHANGED
@@ -113,10 +113,11 @@ declare class keysByFingerprint implements KeysByFingerprint {
113
113
  readonly keys: Record<string, keyWithFingerPrint>;
114
114
  readonly keybag: KeyBag;
115
115
  readonly name: string;
116
+ readonly id: string;
116
117
  static from(keyBag: KeyBag, named: KeysItem): Promise<KeysByFingerprint>;
117
118
  constructor(keyBag: KeyBag, name: string);
118
119
  get(fingerPrint?: Uint8Array | string): Promise<KeyWithFingerPrint | undefined>;
119
- upsert(materialStrOrUint8: string | Uint8Array, def: boolean, keyBagAction?: boolean): Promise<Result<KeyUpsertResult>>;
120
+ upsert(materialStrOrUint8: string | Uint8Array, def?: boolean, keyBagAction?: boolean): Promise<Result<KeyUpsertResult>>;
120
121
  asKeysItem(): Promise<KeysItem>;
121
122
  }
122
123
  declare class KeyBag {
@@ -463,9 +464,10 @@ interface KeyUpsertResult {
463
464
  readonly kfp: KeyWithFingerPrint;
464
465
  }
465
466
  interface KeysByFingerprint {
467
+ readonly id: string;
466
468
  readonly name: string;
467
469
  get(fingerPrint?: Uint8Array | string): Promise<KeyWithFingerPrint | undefined>;
468
- upsert(key: string | Uint8Array, def: boolean): Promise<Result<KeyUpsertResult>>;
470
+ upsert(key: string | Uint8Array, def?: boolean): Promise<Result<KeyUpsertResult>>;
469
471
  asKeysItem(): Promise<KeysItem>;
470
472
  }
471
473
  interface CryptoAction {
package/index.js CHANGED
@@ -689,6 +689,7 @@ var keysByFingerprint = class _keysByFingerprint {
689
689
  this.keys = {};
690
690
  this.keybag = keyBag;
691
691
  this.name = name;
692
+ this.id = keyBag.rt.sthis.nextId(4).str;
692
693
  }
693
694
  static async from(keyBag, named) {
694
695
  const kbf = new _keysByFingerprint(keyBag, named.name);
@@ -712,23 +713,23 @@ var keysByFingerprint = class _keysByFingerprint {
712
713
  async get(fingerPrint) {
713
714
  if (fingerPrint instanceof Uint8Array) {
714
715
  fingerPrint = base58btc2.encode(fingerPrint);
716
+ } else {
717
+ fingerPrint = fingerPrint || "*";
715
718
  }
716
- if (fingerPrint) {
717
- return this.keys[fingerPrint];
718
- }
719
- const def = this.keys["*"];
720
- if (!def) {
721
- throw this.keybag.logger.Error().Msg("KeyBag: keysByFingerprint: no default").AsError();
719
+ const found = this.keys[fingerPrint];
720
+ if (found) {
721
+ return found;
722
722
  }
723
- return def;
723
+ throw this.keybag.logger.Error().Msg("KeyBag: keysByFingerprint: no default").AsError();
724
724
  }
725
725
  async upsert(materialStrOrUint8, def, keyBagAction = true) {
726
+ def = !!def;
726
727
  const rKfp = await toKeyWithFingerPrint(this.keybag, materialStrOrUint8);
727
728
  if (rKfp.isErr()) {
728
729
  return Result2.Err(rKfp);
729
730
  }
730
731
  const kfp = rKfp.Ok();
731
- const found = this.keys[kfp.fingerPrint];
732
+ let found = this.keys[kfp.fingerPrint];
732
733
  if (found) {
733
734
  if (found.default === def) {
734
735
  return Result2.Ok({
@@ -736,23 +737,24 @@ var keysByFingerprint = class _keysByFingerprint {
736
737
  kfp: found
737
738
  });
738
739
  }
740
+ } else {
741
+ found = new keyWithFingerPrint(kfp, materialStrOrUint8, def);
739
742
  }
740
743
  if (def) {
741
744
  for (const i of Object.values(this.keys)) {
742
745
  i.default = false;
743
746
  }
744
747
  }
745
- const out = new keyWithFingerPrint(kfp, materialStrOrUint8, def);
746
- this.keys[kfp.fingerPrint] = out;
748
+ this.keys[kfp.fingerPrint] = found;
747
749
  if (def) {
748
- this.keys["*"] = out;
750
+ this.keys["*"] = found;
749
751
  }
750
752
  if (keyBagAction) {
751
753
  this.keybag._upsertNamedKey(this);
752
754
  }
753
755
  return Result2.Ok({
754
756
  modified: keyBagAction && true,
755
- kfp: out
757
+ kfp: found
756
758
  });
757
759
  }
758
760
  async asKeysItem() {
@@ -901,6 +903,7 @@ var KeyBag = class {
901
903
  return this._seq.add(async () => {
902
904
  const rKbf = await this._getNamedKey(ksi.name, true);
903
905
  if (rKbf.isErr()) {
906
+ this.logger.Error().Err(rKbf).Str("name", ksi.name).Msg("_upsertNamedKey: getNamedKey failed");
904
907
  this._namedKeyCache.unget(ksi.name);
905
908
  }
906
909
  await bag.set(await ksi.asKeysItem());
@@ -3125,6 +3128,7 @@ var noCrypto = class {
3125
3128
  this.logger = ensureLogger(sthis, "noCrypto");
3126
3129
  this.crypto = cyrt;
3127
3130
  this.key = {
3131
+ id: sthis.nextId().str,
3128
3132
  name: "noCrypto",
3129
3133
  get: () => {
3130
3134
  throw this.logger.Error().Msg("noCrypto.get not implemented").AsError();
@@ -4898,7 +4902,7 @@ __export(file_exports, {
4898
4902
 
4899
4903
  // src/version.ts
4900
4904
  var PACKAGE_VERSION = Object.keys({
4901
- "0.20.0-dev-preview-25": "xxxx"
4905
+ "0.20.0-dev-preview-26": "xxxx"
4902
4906
  })[0];
4903
4907
  export {
4904
4908
  CRDTImpl,