@fireproof/core 0.20.0-dev-preview-24 → 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/deno.json +0 -1
- package/index.cjs +418 -175
- package/index.cjs.map +1 -1
- package/index.d.cts +126 -69
- package/index.d.ts +126 -69
- package/index.js +418 -175
- package/index.js.map +1 -1
- package/indexeddb/index.cjs +2 -2
- package/indexeddb/index.cjs.map +1 -1
- package/indexeddb/index.d.cts +2 -2
- package/indexeddb/index.d.ts +2 -2
- package/indexeddb/index.js +2 -2
- package/indexeddb/index.js.map +1 -1
- package/indexeddb/metafile-cjs.json +1 -1
- package/indexeddb/metafile-esm.json +1 -1
- package/metafile-cjs.json +1 -1
- package/metafile-esm.json +1 -1
- package/package.json +3 -3
- package/tests/blockstore/keyed-crypto-indexeddb-file.test.ts +20 -13
- package/tests/blockstore/keyed-crypto.test.ts +138 -30
- package/tests/fireproof/all-gateway.test.ts +19 -15
- package/tests/gateway/fp-envelope-serialize.test.ts +12 -14
package/index.cjs
CHANGED
@@ -80,26 +80,30 @@ var import_cement = require("@adviser/cement");
|
|
80
80
|
function isFalsy(value) {
|
81
81
|
return value === false && value === null && value === void 0;
|
82
82
|
}
|
83
|
-
var PARAM =
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
83
|
+
var PARAM = {
|
84
|
+
SUFFIX: "suffix",
|
85
|
+
URL_GEN: "urlGen",
|
86
|
+
// "urlGen" | "default"
|
87
|
+
STORE_KEY: "storekey",
|
88
|
+
STORE: "store",
|
89
|
+
KEY: "key",
|
90
|
+
INDEX: "index",
|
91
|
+
NAME: "name",
|
92
|
+
VERSION: "version",
|
93
|
+
RUNTIME: "runtime",
|
94
|
+
// "node" | "deno" | "browser"
|
95
|
+
FRAG_SIZE: "fragSize",
|
96
|
+
IV_VERIFY: "ivVerify",
|
97
|
+
IV_HASH: "ivHash",
|
98
|
+
FRAG_FID: "fid",
|
99
|
+
FRAG_OFS: "ofs",
|
100
|
+
FRAG_LEN: "len",
|
101
|
+
FRAG_HEAD: "headerSize",
|
102
|
+
EXTRACTKEY: "extractKey",
|
103
|
+
SELF_REFLECT: "selfReflect"
|
104
|
+
// if no subscribe in Gateway see your own META updates
|
105
|
+
// FS = "fs",
|
106
|
+
};
|
103
107
|
function throwFalsy(value) {
|
104
108
|
if (isFalsy(value)) {
|
105
109
|
throw new Error("value is Falsy");
|
@@ -322,7 +326,7 @@ function ensureLogger(sthis, componentName, ctx) {
|
|
322
326
|
return out;
|
323
327
|
}
|
324
328
|
function getStore(url, sthis, joiner) {
|
325
|
-
const store = url.getParam(
|
329
|
+
const store = url.getParam(PARAM.STORE);
|
326
330
|
switch (store) {
|
327
331
|
case "data":
|
328
332
|
case "wal":
|
@@ -334,17 +338,17 @@ function getStore(url, sthis, joiner) {
|
|
334
338
|
}
|
335
339
|
let name = store;
|
336
340
|
if (url.hasParam("index")) {
|
337
|
-
name = joiner(url.getParam(
|
341
|
+
name = joiner(url.getParam(PARAM.INDEX) || "idx", name);
|
338
342
|
}
|
339
343
|
return { store, name };
|
340
344
|
}
|
341
345
|
function getKey(url, logger) {
|
342
|
-
const result = url.getParam(
|
346
|
+
const result = url.getParam(PARAM.KEY);
|
343
347
|
if (!result) throw logger.Error().Str("url", url.toString()).Msg(`key not found`).AsError();
|
344
348
|
return result;
|
345
349
|
}
|
346
350
|
function getName(sthis, url) {
|
347
|
-
let result = url.getParam(
|
351
|
+
let result = url.getParam(PARAM.NAME);
|
348
352
|
if (!result) {
|
349
353
|
result = sthis.pathOps.dirname(url.pathname);
|
350
354
|
if (result.length === 0) {
|
@@ -584,7 +588,9 @@ __export(key_bag_exports, {
|
|
584
588
|
defaultKeyBagOpts: () => defaultKeyBagOpts,
|
585
589
|
defaultKeyBagUrl: () => defaultKeyBagUrl,
|
586
590
|
getKeyBag: () => getKeyBag,
|
587
|
-
|
591
|
+
keysByFingerprint: () => keysByFingerprint,
|
592
|
+
registerKeyBagProviderFactory: () => registerKeyBagProviderFactory,
|
593
|
+
toKeyWithFingerPrint: () => toKeyWithFingerPrint
|
588
594
|
});
|
589
595
|
var import_cement4 = require("@adviser/cement");
|
590
596
|
var import_base582 = require("multiformats/bases/base58");
|
@@ -634,8 +640,8 @@ var KeyBagProviderFile = class {
|
|
634
640
|
throw this.logger.Error().Err(e).Str("file", ctx.dirName).Msg("read bag failed").AsError();
|
635
641
|
}
|
636
642
|
}
|
637
|
-
async set(
|
638
|
-
const ctx = await this._prepare(
|
643
|
+
async set(item) {
|
644
|
+
const ctx = await this._prepare(item.name);
|
639
645
|
const p = this.sthis.txt.encode(JSON.stringify(item, null, 2));
|
640
646
|
await ctx.sysFS.writefile(ctx.fName, p);
|
641
647
|
}
|
@@ -651,6 +657,17 @@ var KeyBagProviderMemory = class {
|
|
651
657
|
key(id) {
|
652
658
|
return `${this.url.pathname}/${id}`;
|
653
659
|
}
|
660
|
+
// async _prepare(id: string): Promise<KeyBagCtx> {
|
661
|
+
// await this.sthis.start();
|
662
|
+
// const sysFS = await sysFileSystemFactory(this.url);
|
663
|
+
// const dirName = this.url.pathname;
|
664
|
+
// await sysFS.mkdir(dirName, { recursive: true });
|
665
|
+
// return {
|
666
|
+
// dirName,
|
667
|
+
// sysFS,
|
668
|
+
// fName: this.sthis.pathOps.join(dirName, `${id.replace(/[^a-zA-Z0-9]/g, "_")}.json`),
|
669
|
+
// };
|
670
|
+
// }
|
654
671
|
async get(id) {
|
655
672
|
const binKeyItem = memoryKeyBag.get(this.key(id));
|
656
673
|
if (binKeyItem) {
|
@@ -659,34 +676,200 @@ var KeyBagProviderMemory = class {
|
|
659
676
|
}
|
660
677
|
return void 0;
|
661
678
|
}
|
662
|
-
async set(
|
679
|
+
async set(item) {
|
663
680
|
const p = this.sthis.txt.encode(JSON.stringify(item, null, 2));
|
664
|
-
memoryKeyBag.set(this.key(
|
681
|
+
memoryKeyBag.set(this.key(item.name), p);
|
665
682
|
}
|
666
683
|
};
|
667
684
|
|
668
685
|
// src/runtime/key-bag.ts
|
686
|
+
var keyWithFingerPrint = class {
|
687
|
+
#material;
|
688
|
+
constructor(kfp, material, def) {
|
689
|
+
this.kfp = kfp;
|
690
|
+
this.key = kfp.key;
|
691
|
+
this.fingerPrint = kfp.fingerPrint;
|
692
|
+
this.default = def;
|
693
|
+
if (material instanceof Uint8Array) {
|
694
|
+
this.#material = import_base582.base58btc.encode(material);
|
695
|
+
} else if (typeof material === "string") {
|
696
|
+
this.#material = material;
|
697
|
+
} else {
|
698
|
+
throw new Error("material must be string or Uint8Array");
|
699
|
+
}
|
700
|
+
}
|
701
|
+
extract() {
|
702
|
+
return this.kfp.extract();
|
703
|
+
}
|
704
|
+
async asV2StorageKeyItem() {
|
705
|
+
return {
|
706
|
+
default: this.default,
|
707
|
+
fingerPrint: this.fingerPrint,
|
708
|
+
key: this.#material
|
709
|
+
};
|
710
|
+
}
|
711
|
+
};
|
712
|
+
async function toKeyWithFingerPrint(keybag, materialStrOrUint8) {
|
713
|
+
let material;
|
714
|
+
if (typeof materialStrOrUint8 === "string") {
|
715
|
+
material = import_base582.base58btc.decode(materialStrOrUint8);
|
716
|
+
} else {
|
717
|
+
material = materialStrOrUint8;
|
718
|
+
}
|
719
|
+
const key = await keybag.subtleKey(material);
|
720
|
+
const fpr = await keybag.rt.crypto.digestSHA256(material);
|
721
|
+
return import_cement4.Result.Ok({
|
722
|
+
key,
|
723
|
+
fingerPrint: import_base582.base58btc.encode(new Uint8Array(fpr)),
|
724
|
+
extract: async () => {
|
725
|
+
if (key.extractable) {
|
726
|
+
return {
|
727
|
+
key: material,
|
728
|
+
keyStr: import_base582.base58btc.encode(material)
|
729
|
+
};
|
730
|
+
}
|
731
|
+
throw new Error("Key is not extractable");
|
732
|
+
}
|
733
|
+
});
|
734
|
+
}
|
735
|
+
var keysByFingerprint = class _keysByFingerprint {
|
736
|
+
constructor(keyBag, name) {
|
737
|
+
this.keys = {};
|
738
|
+
this.keybag = keyBag;
|
739
|
+
this.name = name;
|
740
|
+
this.id = keyBag.rt.sthis.nextId(4).str;
|
741
|
+
}
|
742
|
+
static async from(keyBag, named) {
|
743
|
+
const kbf = new _keysByFingerprint(keyBag, named.name);
|
744
|
+
for (const i of Object.entries(named.keys).reverse()) {
|
745
|
+
const result = await kbf.upsert(i[1].key, i[1].default, false);
|
746
|
+
if (result.isErr()) {
|
747
|
+
throw result;
|
748
|
+
}
|
749
|
+
if (result.Ok().modified) {
|
750
|
+
throw keyBag.logger.Error().Msg("KeyBag: keysByFingerprint: mismatch unexpected").AsError();
|
751
|
+
}
|
752
|
+
if (result.Ok().kfp.fingerPrint !== i[1].fingerPrint) {
|
753
|
+
throw keyBag.logger.Error().Any("fprs", {
|
754
|
+
fromStorage: i[1].fingerPrint,
|
755
|
+
calculated: result.Ok().kfp.fingerPrint
|
756
|
+
}).Msg("KeyBag: keysByFingerprint: mismatch").AsError();
|
757
|
+
}
|
758
|
+
}
|
759
|
+
return kbf;
|
760
|
+
}
|
761
|
+
async get(fingerPrint) {
|
762
|
+
if (fingerPrint instanceof Uint8Array) {
|
763
|
+
fingerPrint = import_base582.base58btc.encode(fingerPrint);
|
764
|
+
} else {
|
765
|
+
fingerPrint = fingerPrint || "*";
|
766
|
+
}
|
767
|
+
const found = this.keys[fingerPrint];
|
768
|
+
if (found) {
|
769
|
+
return found;
|
770
|
+
}
|
771
|
+
throw this.keybag.logger.Error().Msg("KeyBag: keysByFingerprint: no default").AsError();
|
772
|
+
}
|
773
|
+
async upsert(materialStrOrUint8, def, keyBagAction = true) {
|
774
|
+
def = !!def;
|
775
|
+
const rKfp = await toKeyWithFingerPrint(this.keybag, materialStrOrUint8);
|
776
|
+
if (rKfp.isErr()) {
|
777
|
+
return import_cement4.Result.Err(rKfp);
|
778
|
+
}
|
779
|
+
const kfp = rKfp.Ok();
|
780
|
+
let found = this.keys[kfp.fingerPrint];
|
781
|
+
if (found) {
|
782
|
+
if (found.default === def) {
|
783
|
+
return import_cement4.Result.Ok({
|
784
|
+
modified: false,
|
785
|
+
kfp: found
|
786
|
+
});
|
787
|
+
}
|
788
|
+
} else {
|
789
|
+
found = new keyWithFingerPrint(kfp, materialStrOrUint8, def);
|
790
|
+
}
|
791
|
+
if (def) {
|
792
|
+
for (const i of Object.values(this.keys)) {
|
793
|
+
i.default = false;
|
794
|
+
}
|
795
|
+
}
|
796
|
+
this.keys[kfp.fingerPrint] = found;
|
797
|
+
if (def) {
|
798
|
+
this.keys["*"] = found;
|
799
|
+
}
|
800
|
+
if (keyBagAction) {
|
801
|
+
this.keybag._upsertNamedKey(this);
|
802
|
+
}
|
803
|
+
return import_cement4.Result.Ok({
|
804
|
+
modified: keyBagAction && true,
|
805
|
+
kfp: found
|
806
|
+
});
|
807
|
+
}
|
808
|
+
async asKeysItem() {
|
809
|
+
const my = { ...this.keys };
|
810
|
+
delete my["*"];
|
811
|
+
const kis = await Promise.all(Object.values(my).map((i) => i.asV2StorageKeyItem()));
|
812
|
+
return {
|
813
|
+
name: this.name,
|
814
|
+
keys: kis.reduce(
|
815
|
+
(acc, i) => {
|
816
|
+
acc[i.fingerPrint] = i;
|
817
|
+
return acc;
|
818
|
+
},
|
819
|
+
{}
|
820
|
+
)
|
821
|
+
};
|
822
|
+
}
|
823
|
+
// async extract() {
|
824
|
+
// const ext = new Uint8Array((await this.rt.crypto.exportKey("raw", named.key)) as ArrayBuffer);
|
825
|
+
// return {
|
826
|
+
// key: ext,
|
827
|
+
// keyStr: base58btc.encode(ext),
|
828
|
+
// };
|
829
|
+
// }
|
830
|
+
};
|
669
831
|
var KeyBag = class {
|
670
832
|
constructor(rt) {
|
671
|
-
this.rt = rt;
|
672
833
|
this._warnOnce = new import_cement4.ResolveOnce();
|
673
834
|
this._seq = new import_cement4.ResolveSeq();
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
835
|
+
// async getNamedExtractableKey(name: string, failIfNotFound = false): Promise<Result<KeysByFingerprint>> {
|
836
|
+
// const ret = await this.getNamedKey(name, failIfNotFound);
|
837
|
+
// if (ret.isErr()) {
|
838
|
+
// return Result.Err(ret)
|
839
|
+
// }
|
840
|
+
// const named = ret.Ok();
|
841
|
+
// return Result.Ok({
|
842
|
+
// ...named,
|
843
|
+
// extract: async () => {
|
844
|
+
// const ext = new Uint8Array((await this.rt.crypto.exportKey("raw", named.key)) as ArrayBuffer);
|
845
|
+
// return {
|
846
|
+
// key: ext,
|
847
|
+
// keyStr: base58btc.encode(ext),
|
848
|
+
// };
|
849
|
+
// },
|
850
|
+
// });
|
851
|
+
// }
|
852
|
+
this._namedKeyCache = new import_cement4.KeyedResolvOnce();
|
853
|
+
this.rt = rt;
|
854
|
+
this.logger = ensureLogger(rt.sthis, "KeyBag");
|
678
855
|
}
|
679
|
-
async subtleKey(
|
680
|
-
const extractable = this.rt.url.getParam(
|
856
|
+
async subtleKey(materialStrOrUint8) {
|
857
|
+
const extractable = this.rt.url.getParam(PARAM.EXTRACTKEY) === "_deprecated_internal_api";
|
681
858
|
if (extractable) {
|
682
859
|
this._warnOnce.once(
|
683
860
|
() => this.logger.Warn().Msg("extractKey is enabled via _deprecated_internal_api --- handle keys safely!!!")
|
684
861
|
);
|
685
862
|
}
|
863
|
+
let material;
|
864
|
+
if (typeof materialStrOrUint8 === "string") {
|
865
|
+
material = import_base582.base58btc.decode(materialStrOrUint8);
|
866
|
+
} else {
|
867
|
+
material = materialStrOrUint8;
|
868
|
+
}
|
686
869
|
return await this.rt.crypto.importKey(
|
687
870
|
"raw",
|
688
871
|
// raw or jwk
|
689
|
-
|
872
|
+
material,
|
690
873
|
// hexStringToUint8Array(key), // raw data
|
691
874
|
"AES-GCM",
|
692
875
|
extractable,
|
@@ -694,7 +877,7 @@ var KeyBag = class {
|
|
694
877
|
);
|
695
878
|
}
|
696
879
|
async ensureKeyFromUrl(url, keyFactory) {
|
697
|
-
const storeKey = url.getParam(
|
880
|
+
const storeKey = url.getParam(PARAM.STORE_KEY);
|
698
881
|
if (storeKey === "insecure") {
|
699
882
|
return import_cement4.Result.Ok(url);
|
700
883
|
}
|
@@ -704,7 +887,7 @@ var KeyBag = class {
|
|
704
887
|
if (ret.isErr()) {
|
705
888
|
return ret;
|
706
889
|
}
|
707
|
-
const urb = url.build().setParam(
|
890
|
+
const urb = url.build().setParam(PARAM.STORE_KEY, keyName);
|
708
891
|
return import_cement4.Result.Ok(urb.URI());
|
709
892
|
}
|
710
893
|
if (storeKey.startsWith("@") && storeKey.endsWith("@")) {
|
@@ -715,63 +898,103 @@ var KeyBag = class {
|
|
715
898
|
}
|
716
899
|
return import_cement4.Result.Ok(url);
|
717
900
|
}
|
718
|
-
async
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
901
|
+
async toKeysItem(ki) {
|
902
|
+
if (!ki) return void 0;
|
903
|
+
if ("key" in ki) {
|
904
|
+
const fpr = (await toKeyWithFingerPrint(this, ki.key)).Ok().fingerPrint;
|
905
|
+
return {
|
906
|
+
name: ki.name,
|
907
|
+
keys: {
|
908
|
+
[fpr]: {
|
909
|
+
key: ki.key,
|
910
|
+
fingerPrint: fpr,
|
911
|
+
default: true
|
912
|
+
}
|
913
|
+
}
|
914
|
+
};
|
915
|
+
}
|
916
|
+
let defKI;
|
917
|
+
let foundDefKI = false;
|
918
|
+
for (const i of Object.entries(ki.keys)) {
|
919
|
+
if (i[0] !== i[1].fingerPrint) {
|
920
|
+
delete ki.keys[i[0]];
|
921
|
+
ki.keys[i[1].fingerPrint] = i[1];
|
922
|
+
this.logger.Warn().Str("name", ki.name).Msg("fingerPrint mismatch fixed");
|
923
|
+
}
|
924
|
+
if (defKI === void 0) {
|
925
|
+
defKI = i[1];
|
926
|
+
}
|
927
|
+
if (!foundDefKI && i[1].default) {
|
928
|
+
defKI = i[1];
|
929
|
+
foundDefKI = true;
|
930
|
+
} else {
|
931
|
+
i[1].default = false;
|
932
|
+
}
|
933
|
+
}
|
934
|
+
if (defKI) {
|
935
|
+
ki.keys["*"] = defKI;
|
936
|
+
}
|
937
|
+
return {
|
938
|
+
name: ki.name,
|
939
|
+
keys: ki.keys
|
940
|
+
};
|
726
941
|
}
|
727
|
-
|
728
|
-
return this._seq.
|
942
|
+
flush() {
|
943
|
+
return this._seq.flush();
|
729
944
|
}
|
945
|
+
// async setNamedKey(name: string, key: string, def?: boolean): Promise<Result<KeysByFingerprint>> {
|
946
|
+
// return this._seq.add(() => this._upsertNamedKey(name, key, !!def));
|
947
|
+
// }
|
730
948
|
// avoid deadlock
|
731
|
-
async
|
732
|
-
const item = {
|
733
|
-
name,
|
734
|
-
key
|
735
|
-
};
|
949
|
+
async _upsertNamedKey(ksi) {
|
736
950
|
const bag = await this.rt.getBagProvider();
|
737
|
-
this.
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
const ret = await this.getNamedKey(name, failIfNotFound);
|
743
|
-
if (ret.isErr()) {
|
744
|
-
return ret;
|
745
|
-
}
|
746
|
-
const named = ret.Ok();
|
747
|
-
return import_cement4.Result.Ok({
|
748
|
-
...named,
|
749
|
-
extract: async () => {
|
750
|
-
const ext = new Uint8Array(await this.rt.crypto.exportKey("raw", named.key));
|
751
|
-
return {
|
752
|
-
key: ext,
|
753
|
-
keyStr: import_base582.base58btc.encode(ext)
|
754
|
-
};
|
951
|
+
return this._seq.add(async () => {
|
952
|
+
const rKbf = await this._getNamedKey(ksi.name, true);
|
953
|
+
if (rKbf.isErr()) {
|
954
|
+
this.logger.Error().Err(rKbf).Str("name", ksi.name).Msg("_upsertNamedKey: getNamedKey failed");
|
955
|
+
this._namedKeyCache.unget(ksi.name);
|
755
956
|
}
|
957
|
+
await bag.set(await ksi.asKeysItem());
|
958
|
+
return import_cement4.Result.Ok(ksi);
|
756
959
|
});
|
757
960
|
}
|
758
|
-
async
|
759
|
-
|
760
|
-
|
961
|
+
async _getNamedKey(name, failIfNotFound, material) {
|
962
|
+
return await this._namedKeyCache.get(name).once(async () => {
|
963
|
+
const id = this.rt.sthis.nextId(4).str;
|
761
964
|
const bag = await this.rt.getBagProvider();
|
762
|
-
const named = await bag.get(name);
|
965
|
+
const named = await this.toKeysItem(await bag.get(name));
|
763
966
|
if (named) {
|
764
|
-
|
765
|
-
|
766
|
-
return fpr;
|
967
|
+
this.logger.Debug().Str("id", id).Str("name", name).Any("fprs", Object.keys(named.keys)).Msg("fingerPrint getNamedKey");
|
968
|
+
return import_cement4.Result.Ok(await keysByFingerprint.from(this, named));
|
767
969
|
}
|
768
|
-
if (failIfNotFound) {
|
769
|
-
this.
|
770
|
-
return
|
970
|
+
if (!named && failIfNotFound) {
|
971
|
+
this._namedKeyCache.unget(name);
|
972
|
+
return this.logger.Debug().Str("id", id).Str("name", name).Msg("failIfNotFound getNamedKey").ResultError();
|
771
973
|
}
|
772
|
-
const
|
773
|
-
|
774
|
-
|
974
|
+
const kp = new keysByFingerprint(this, name);
|
975
|
+
let keyMaterial;
|
976
|
+
if (!material) {
|
977
|
+
keyMaterial = this.rt.crypto.randomBytes(this.rt.keyLength);
|
978
|
+
} else {
|
979
|
+
if (typeof material === "string") {
|
980
|
+
keyMaterial = import_base582.base58btc.decode(material);
|
981
|
+
} else if (material instanceof Uint8Array) {
|
982
|
+
keyMaterial = material;
|
983
|
+
} else {
|
984
|
+
return this.logger.Error().Msg("material must be string or Uint8Array").ResultError();
|
985
|
+
}
|
986
|
+
}
|
987
|
+
const res = await kp.upsert(keyMaterial, true);
|
988
|
+
if (res.isErr()) {
|
989
|
+
return import_cement4.Result.Err(res);
|
990
|
+
}
|
991
|
+
this.logger.Debug().Str("id", id).Str("name", name).Str("fpr", res.Ok().kfp.fingerPrint).Msg("createKey getNamedKey-post");
|
992
|
+
return import_cement4.Result.Ok(kp);
|
993
|
+
});
|
994
|
+
}
|
995
|
+
async getNamedKey(name, failIfNotFound = false, material) {
|
996
|
+
return this._seq.add(async () => {
|
997
|
+
return await this._getNamedKey(name, failIfNotFound, material);
|
775
998
|
});
|
776
999
|
}
|
777
1000
|
};
|
@@ -940,24 +1163,24 @@ var FileGateway = class {
|
|
940
1163
|
return (0, import_cement5.exception2Result)(async () => {
|
941
1164
|
await this.fs.start();
|
942
1165
|
const url = baseURL.build();
|
943
|
-
url.defParam(
|
1166
|
+
url.defParam(PARAM.VERSION, FILESTORE_VERSION);
|
944
1167
|
const dbUrl = await this.buildUrl(url.URI(), "dummy");
|
945
1168
|
const dbdirFile = this.getFilePath(dbUrl.Ok(), sthis);
|
946
1169
|
await this.fs.mkdir(sthis.pathOps.dirname(dbdirFile), { recursive: true });
|
947
1170
|
const dbroot = sthis.pathOps.dirname(dbdirFile);
|
948
1171
|
sthis.logger.Debug().Url(url.URI()).Str("dbroot", dbroot).Msg("start");
|
949
|
-
url.setParam(
|
1172
|
+
url.setParam(PARAM.VERSION, await this.getVersionFromFile(dbroot, sthis));
|
950
1173
|
return url.URI();
|
951
1174
|
});
|
952
1175
|
}
|
953
1176
|
async buildUrl(baseUrl, key) {
|
954
|
-
return import_cement5.Result.Ok(baseUrl.build().setParam(
|
1177
|
+
return import_cement5.Result.Ok(baseUrl.build().setParam(PARAM.KEY, key).URI());
|
955
1178
|
}
|
956
1179
|
async close() {
|
957
1180
|
return import_cement5.Result.Ok(void 0);
|
958
1181
|
}
|
959
1182
|
getFilePath(url, sthis) {
|
960
|
-
const key = url.getParam(
|
1183
|
+
const key = url.getParam(PARAM.KEY);
|
961
1184
|
if (!key) throw sthis.logger.Error().Url(url).Msg(`key not found`).AsError();
|
962
1185
|
return sthis.pathOps.join(getPath(url, sthis), getFileName(url, sthis));
|
963
1186
|
}
|
@@ -1013,7 +1236,7 @@ var FileGateway = class {
|
|
1013
1236
|
return import_cement5.Result.Ok(void 0);
|
1014
1237
|
}
|
1015
1238
|
async getPlain(iurl, key, sthis) {
|
1016
|
-
const url = iurl.build().setParam(
|
1239
|
+
const url = iurl.build().setParam(PARAM.KEY, key).URI();
|
1017
1240
|
const dbFile = sthis.pathOps.join(getPath(url, sthis), getFileName(url, sthis));
|
1018
1241
|
sthis.logger.Debug().Url(url).Str("dbFile", dbFile).Msg("get");
|
1019
1242
|
const buffer = await this.fs.readfile(dbFile);
|
@@ -1039,10 +1262,10 @@ var MemoryGateway = class {
|
|
1039
1262
|
this.sthis = sthis;
|
1040
1263
|
}
|
1041
1264
|
buildUrl(baseUrl, key) {
|
1042
|
-
return Promise.resolve(import_cement6.Result.Ok(baseUrl.build().setParam(
|
1265
|
+
return Promise.resolve(import_cement6.Result.Ok(baseUrl.build().setParam(PARAM.KEY, key).URI()));
|
1043
1266
|
}
|
1044
1267
|
start(baseUrl) {
|
1045
|
-
return Promise.resolve(import_cement6.Result.Ok(baseUrl.build().setParam(
|
1268
|
+
return Promise.resolve(import_cement6.Result.Ok(baseUrl.build().setParam(PARAM.VERSION, MEMORY_VERSION).URI()));
|
1046
1269
|
}
|
1047
1270
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
1048
1271
|
close(baseUrl) {
|
@@ -1070,7 +1293,7 @@ var MemoryGateway = class {
|
|
1070
1293
|
return Promise.resolve(import_cement6.Result.Ok(void 0));
|
1071
1294
|
}
|
1072
1295
|
async getPlain(url, key) {
|
1073
|
-
const x = this.memorys.get(url.build().setParam(
|
1296
|
+
const x = this.memorys.get(url.build().setParam(PARAM.KEY, key).toString());
|
1074
1297
|
if (!x) {
|
1075
1298
|
return import_cement6.Result.Err(new NotFoundError("not found"));
|
1076
1299
|
}
|
@@ -1083,18 +1306,17 @@ var import_cement9 = require("@adviser/cement");
|
|
1083
1306
|
|
1084
1307
|
// src/blockstore/fp-envelope.ts
|
1085
1308
|
var import_cement7 = require("@adviser/cement");
|
1086
|
-
var
|
1087
|
-
|
1088
|
-
|
1089
|
-
|
1090
|
-
|
1091
|
-
|
1092
|
-
})(FPEnvelopeType || {});
|
1309
|
+
var FPEnvelopeTypes = {
|
1310
|
+
CAR: "car",
|
1311
|
+
FILE: "file",
|
1312
|
+
META: "meta",
|
1313
|
+
WAL: "wal"
|
1314
|
+
};
|
1093
1315
|
function Car2FPMsg(fpcar) {
|
1094
|
-
return import_cement7.Result.Ok({ type:
|
1316
|
+
return import_cement7.Result.Ok({ type: FPEnvelopeTypes.CAR, payload: fpcar });
|
1095
1317
|
}
|
1096
1318
|
function File2FPMsg(fpfile) {
|
1097
|
-
return import_cement7.Result.Ok({ type:
|
1319
|
+
return import_cement7.Result.Ok({ type: FPEnvelopeTypes.FILE, payload: fpfile });
|
1098
1320
|
}
|
1099
1321
|
|
1100
1322
|
// src/runtime/gateways/fp-envelope-serialize.ts
|
@@ -1148,13 +1370,13 @@ async function fpSerialize(sthis, env, pencoder) {
|
|
1148
1370
|
...pencoder
|
1149
1371
|
};
|
1150
1372
|
switch (env.type) {
|
1151
|
-
case
|
1373
|
+
case FPEnvelopeTypes.FILE:
|
1152
1374
|
return encoder.file(sthis, env.payload);
|
1153
|
-
case
|
1375
|
+
case FPEnvelopeTypes.CAR:
|
1154
1376
|
return encoder.car(sthis, env.payload);
|
1155
|
-
case
|
1377
|
+
case FPEnvelopeTypes.WAL:
|
1156
1378
|
return encoder.wal(sthis, WALState2Serialized(sthis, env.payload));
|
1157
|
-
case
|
1379
|
+
case FPEnvelopeTypes.META:
|
1158
1380
|
return encoder.meta(sthis, await dbMetaEvent2Serialized(sthis, env.payload));
|
1159
1381
|
default:
|
1160
1382
|
throw sthis.logger.Error().Str("type", env.type).Msg("unsupported store").AsError();
|
@@ -1234,18 +1456,18 @@ async function fpDeserialize(sthis, url, intoRaw, pdecoder) {
|
|
1234
1456
|
...defaultDecoder,
|
1235
1457
|
...pdecoder
|
1236
1458
|
};
|
1237
|
-
switch (url.getParam(
|
1459
|
+
switch (url.getParam(PARAM.STORE)) {
|
1238
1460
|
case "data":
|
1239
|
-
if (url.getParam(
|
1240
|
-
return makeFPEnvelope(
|
1461
|
+
if (url.getParam(PARAM.SUFFIX) === ".car") {
|
1462
|
+
return makeFPEnvelope(FPEnvelopeTypes.CAR, await decoder.car(sthis, raw2));
|
1241
1463
|
}
|
1242
|
-
return makeFPEnvelope(
|
1464
|
+
return makeFPEnvelope(FPEnvelopeTypes.FILE, await decoder.file(sthis, raw2));
|
1243
1465
|
case "wal":
|
1244
|
-
return makeFPEnvelope(
|
1466
|
+
return makeFPEnvelope(FPEnvelopeTypes.WAL, await decode2WalState(sthis, await decoder.wal(sthis, raw2)));
|
1245
1467
|
case "meta":
|
1246
|
-
return makeFPEnvelope(
|
1468
|
+
return makeFPEnvelope(FPEnvelopeTypes.META, await decode2DbMetaEvents(sthis, await decoder.meta(sthis, raw2)));
|
1247
1469
|
default:
|
1248
|
-
return sthis.logger.Error().Str("store", url.getParam(
|
1470
|
+
return sthis.logger.Error().Str("store", url.getParam(PARAM.STORE)).Msg("unsupported store").ResultError();
|
1249
1471
|
}
|
1250
1472
|
}
|
1251
1473
|
|
@@ -1268,9 +1490,11 @@ var DefSerdeGateway = class {
|
|
1268
1490
|
const rUint8 = await fpSerialize(sthis, env, encoder);
|
1269
1491
|
if (rUint8.isErr()) return rUint8;
|
1270
1492
|
const ret = this.gw.put(url, rUint8.Ok(), sthis);
|
1271
|
-
if (env.type ===
|
1272
|
-
|
1273
|
-
|
1493
|
+
if (env.type === FPEnvelopeTypes.META) {
|
1494
|
+
const urlWithoutKey = url.build().delParam(PARAM.KEY).delParam(PARAM.SELF_REFLECT).toString();
|
1495
|
+
const subFn = this.subscribeFn.get(urlWithoutKey);
|
1496
|
+
if (subFn) {
|
1497
|
+
await subFn(rUint8.Ok());
|
1274
1498
|
}
|
1275
1499
|
}
|
1276
1500
|
return ret;
|
@@ -1291,7 +1515,12 @@ var DefSerdeGateway = class {
|
|
1291
1515
|
});
|
1292
1516
|
}
|
1293
1517
|
if (!this.gw.subscribe) {
|
1294
|
-
|
1518
|
+
if (!url.hasParam(PARAM.SELF_REFLECT)) {
|
1519
|
+
return import_cement9.Result.Ok(() => {
|
1520
|
+
});
|
1521
|
+
}
|
1522
|
+
const urlWithoutKey = url.build().delParam(PARAM.KEY).delParam(PARAM.SELF_REFLECT).toString();
|
1523
|
+
this.subscribeFn.set(urlWithoutKey, rawCallback);
|
1295
1524
|
return import_cement9.Result.Ok(() => {
|
1296
1525
|
this.subscribeFn.delete(url.toString());
|
1297
1526
|
});
|
@@ -1370,7 +1599,7 @@ function defaultGatewayFactoryItem() {
|
|
1370
1599
|
}
|
1371
1600
|
function defaultURI(sthis) {
|
1372
1601
|
const rt = (0, import_cement10.runtimeFn)();
|
1373
|
-
return import_cement10.BuildURI.from("file://").pathname(`${sthis.env.get("HOME")}/.fireproof/${FILESTORE_VERSION.replace(/-.*$/, "")}`).setParam(
|
1602
|
+
return import_cement10.BuildURI.from("file://").pathname(`${sthis.env.get("HOME")}/.fireproof/${FILESTORE_VERSION.replace(/-.*$/, "")}`).setParam(PARAM.VERSION, FILESTORE_VERSION).setParam(PARAM.URL_GEN, "default").setParam(PARAM.RUNTIME, rt.isNodeIsh ? "node" : rt.isDeno ? "deno" : "unknown").URI();
|
1374
1603
|
}
|
1375
1604
|
if ((0, import_cement10.runtimeFn)().isNodeIsh || (0, import_cement10.runtimeFn)().isDeno) {
|
1376
1605
|
registerStoreProtocol({
|
@@ -1387,7 +1616,7 @@ if ((0, import_cement10.runtimeFn)().isBrowser) {
|
|
1387
1616
|
protocol: "indexeddb:",
|
1388
1617
|
isDefault: true,
|
1389
1618
|
defaultURI: () => {
|
1390
|
-
return import_cement10.BuildURI.from("indexeddb://").pathname("fp").setParam(
|
1619
|
+
return import_cement10.BuildURI.from("indexeddb://").pathname("fp").setParam(PARAM.VERSION, INDEXEDDB_VERSION).setParam(PARAM.RUNTIME, "browser").URI();
|
1391
1620
|
},
|
1392
1621
|
gateway: async () => {
|
1393
1622
|
const { GatewayImpl } = await import("@fireproof/core/indexeddb");
|
@@ -1953,7 +2182,7 @@ __export(blockstore_exports, {
|
|
1953
2182
|
DbMetaEventEqual: () => DbMetaEventEqual,
|
1954
2183
|
DbMetaEventsEqual: () => DbMetaEventsEqual,
|
1955
2184
|
EncryptedBlockstore: () => EncryptedBlockstore,
|
1956
|
-
|
2185
|
+
FPEnvelopeTypes: () => FPEnvelopeTypes,
|
1957
2186
|
File2FPMsg: () => File2FPMsg,
|
1958
2187
|
InterceptorGateway: () => InterceptorGateway,
|
1959
2188
|
Loader: () => Loader,
|
@@ -2842,12 +3071,12 @@ var generateIV = {
|
|
2842
3071
|
return hashArray;
|
2843
3072
|
},
|
2844
3073
|
verify: async function(ko, crypto, iv, data) {
|
2845
|
-
return ko.url.getParam(
|
3074
|
+
return ko.url.getParam(PARAM.IV_VERIFY) !== "disable" && UInt8ArrayEqual(iv, await this.calc(ko, crypto, data));
|
2846
3075
|
}
|
2847
3076
|
}
|
2848
3077
|
};
|
2849
3078
|
function getGenerateIVFn(url, opts) {
|
2850
|
-
const ivhash = opts.ivCalc || url.getParam(
|
3079
|
+
const ivhash = opts.ivCalc || url.getParam(PARAM.IV_HASH) || "hash";
|
2851
3080
|
return generateIV[ivhash] || generateIV["hash"];
|
2852
3081
|
}
|
2853
3082
|
var BlockIvKeyIdCodec = class {
|
@@ -2861,13 +3090,16 @@ var BlockIvKeyIdCodec = class {
|
|
2861
3090
|
async encode(data) {
|
2862
3091
|
const calcIv = this.iv || await getGenerateIVFn(this.ko.url, this.opts).calc(this.ko, this.ko.crypto, data);
|
2863
3092
|
const { iv } = this.ko.algo(calcIv);
|
2864
|
-
const
|
2865
|
-
|
2866
|
-
|
3093
|
+
const defKey = await this.ko.key.get();
|
3094
|
+
if (!defKey) {
|
3095
|
+
throw this.ko.logger.Error().Msg("default key not found").AsError();
|
3096
|
+
}
|
3097
|
+
const keyId = import_base583.base58btc.decode(defKey?.fingerPrint);
|
3098
|
+
this.ko.logger.Debug().Str("fp", defKey.fingerPrint).Msg("encode");
|
2867
3099
|
return CBOR.encode({
|
2868
3100
|
iv,
|
2869
3101
|
keyId,
|
2870
|
-
data: await this.ko._encrypt({ iv, bytes: data })
|
3102
|
+
data: await this.ko._encrypt({ iv, key: defKey.key, bytes: data })
|
2871
3103
|
});
|
2872
3104
|
}
|
2873
3105
|
async decode(abytes) {
|
@@ -2878,30 +3110,32 @@ var BlockIvKeyIdCodec = class {
|
|
2878
3110
|
bytes = new Uint8Array(abytes);
|
2879
3111
|
}
|
2880
3112
|
const { iv, keyId, data } = CBOR.decode(bytes);
|
2881
|
-
const
|
2882
|
-
|
2883
|
-
|
2884
|
-
throw this.ko.logger.Error().Str("fp", fprt).Str("keyId", import_base583.base58btc.encode(keyId)).Msg("keyId mismatch").AsError();
|
3113
|
+
const key = await this.ko.key.get(keyId);
|
3114
|
+
if (!key) {
|
3115
|
+
throw this.ko.logger.Error().Str("fp", import_base583.base58btc.encode(keyId)).Msg("keyId not found").AsError();
|
2885
3116
|
}
|
2886
|
-
const result = await this.ko._decrypt({ iv, bytes: data });
|
3117
|
+
const result = await this.ko._decrypt({ iv, key: key.key, bytes: data });
|
2887
3118
|
if (!this.opts?.noIVVerify && !await getGenerateIVFn(this.ko.url, this.opts).verify(this.ko, this.ko.crypto, iv, result)) {
|
2888
3119
|
throw this.ko.logger.Error().Msg("iv missmatch").AsError();
|
2889
3120
|
}
|
2890
3121
|
return result;
|
2891
3122
|
}
|
2892
3123
|
};
|
2893
|
-
var
|
3124
|
+
var cryptoAction = class {
|
2894
3125
|
constructor(url, key, cyopt, sthis) {
|
2895
3126
|
this.ivLength = 12;
|
2896
3127
|
this.isEncrypting = true;
|
2897
|
-
this.logger = ensureLogger(sthis, "
|
3128
|
+
this.logger = ensureLogger(sthis, "cryptoAction");
|
2898
3129
|
this.crypto = cyopt;
|
2899
3130
|
this.key = key;
|
2900
3131
|
this.url = url;
|
2901
3132
|
}
|
2902
|
-
|
2903
|
-
|
2904
|
-
}
|
3133
|
+
// keyByFingerPrint(id: Uint8Array | string): Promise<Result<KeyWithFingerPrint>> {
|
3134
|
+
// return this.key.get(id)
|
3135
|
+
// }
|
3136
|
+
// fingerPrint(): Promise<string> {
|
3137
|
+
// return this.key.get().then((k) => k.fingerPrint);
|
3138
|
+
// }
|
2905
3139
|
codec(iv, opts) {
|
2906
3140
|
return new BlockIvKeyIdCodec(this, iv, opts);
|
2907
3141
|
}
|
@@ -2913,13 +3147,11 @@ var keyedCrypto = class {
|
|
2913
3147
|
};
|
2914
3148
|
}
|
2915
3149
|
async _decrypt(data) {
|
2916
|
-
this.
|
2917
|
-
return new Uint8Array(await this.crypto.decrypt(this.algo(data.iv), this.key.key, data.bytes));
|
3150
|
+
return new Uint8Array(await this.crypto.decrypt(this.algo(data.iv), data.key, data.bytes));
|
2918
3151
|
}
|
2919
3152
|
async _encrypt(data) {
|
2920
|
-
this.logger.Debug().Len(data.bytes).Str("fp", this.key.fingerPrint).Msg("encrypting");
|
2921
3153
|
const a = this.algo(data.iv);
|
2922
|
-
return new Uint8Array(await this.crypto.encrypt(a,
|
3154
|
+
return new Uint8Array(await this.crypto.encrypt(a, data.key, data.bytes));
|
2923
3155
|
}
|
2924
3156
|
};
|
2925
3157
|
var nullCodec = class {
|
@@ -2943,6 +3175,19 @@ var noCrypto = class {
|
|
2943
3175
|
this._fingerPrint = "noCrypto:" + Math.random();
|
2944
3176
|
this.logger = ensureLogger(sthis, "noCrypto");
|
2945
3177
|
this.crypto = cyrt;
|
3178
|
+
this.key = {
|
3179
|
+
id: sthis.nextId().str,
|
3180
|
+
name: "noCrypto",
|
3181
|
+
get: () => {
|
3182
|
+
throw this.logger.Error().Msg("noCrypto.get not implemented").AsError();
|
3183
|
+
},
|
3184
|
+
upsert: () => {
|
3185
|
+
throw this.logger.Error().Msg("noCrypto.upsert not implemented").AsError();
|
3186
|
+
},
|
3187
|
+
asKeysItem: () => {
|
3188
|
+
throw this.logger.Error().Msg("noCrypto.asKeysItem not implemented").AsError();
|
3189
|
+
}
|
3190
|
+
};
|
2946
3191
|
this.url = url;
|
2947
3192
|
}
|
2948
3193
|
fingerPrint() {
|
@@ -2968,17 +3213,13 @@ var noCrypto = class {
|
|
2968
3213
|
}
|
2969
3214
|
};
|
2970
3215
|
async function keyedCryptoFactory(url, kb, sthis) {
|
2971
|
-
const storekey = url.getParam(
|
3216
|
+
const storekey = url.getParam(PARAM.STORE_KEY);
|
2972
3217
|
if (storekey && storekey !== "insecure") {
|
2973
|
-
|
3218
|
+
const rkey = await kb.getNamedKey(storekey, false);
|
2974
3219
|
if (rkey.isErr()) {
|
2975
|
-
|
2976
|
-
rkey = await kb.toKeyWithFingerPrint(storekey);
|
2977
|
-
} catch (e) {
|
2978
|
-
throw sthis.logger.Error().Err(e).Str("keybag", kb.rt.id()).Str("name", storekey).Msg("getNamedKey failed").AsError();
|
2979
|
-
}
|
3220
|
+
throw sthis.logger.Error().Str("keybag", kb.rt.id()).Str("name", storekey).Msg("getNamedKey failed").AsError();
|
2980
3221
|
}
|
2981
|
-
return new
|
3222
|
+
return new cryptoAction(url, rkey.Ok(), kb.rt.crypto, sthis);
|
2982
3223
|
}
|
2983
3224
|
return new noCrypto(url, kb.rt.crypto, sthis);
|
2984
3225
|
}
|
@@ -3143,7 +3384,7 @@ var BaseStoreImpl = class {
|
|
3143
3384
|
this.opts = opts;
|
3144
3385
|
this.loader = opts.loader;
|
3145
3386
|
this.sthis = sthis;
|
3146
|
-
const name = this._url.getParam(
|
3387
|
+
const name = this._url.getParam(PARAM.NAME);
|
3147
3388
|
if (!name) {
|
3148
3389
|
throw logger.Error().Url(this._url).Msg("missing name").AsError();
|
3149
3390
|
}
|
@@ -3168,7 +3409,7 @@ var BaseStoreImpl = class {
|
|
3168
3409
|
}
|
3169
3410
|
async start() {
|
3170
3411
|
this.logger.Debug().Str("storeType", this.storeType).Msg("starting-gateway-pre");
|
3171
|
-
this._url = this._url.build().setParam(
|
3412
|
+
this._url = this._url.build().setParam(PARAM.STORE, this.storeType).URI();
|
3172
3413
|
const res = await this.gateway.start({ loader: this.loader }, this._url);
|
3173
3414
|
if (res.isErr()) {
|
3174
3415
|
this.logger.Error().Result("gw-start", res).Msg("started-gateway");
|
@@ -3177,8 +3418,8 @@ var BaseStoreImpl = class {
|
|
3177
3418
|
this._url = res.Ok();
|
3178
3419
|
const kb = await this.loader.keyBag();
|
3179
3420
|
const skRes = await kb.ensureKeyFromUrl(this._url, () => {
|
3180
|
-
const idx = this._url.getParam(
|
3181
|
-
const storeKeyName = [this.url().getParam(
|
3421
|
+
const idx = this._url.getParam(PARAM.INDEX);
|
3422
|
+
const storeKeyName = [this.url().getParam(PARAM.NAME)];
|
3182
3423
|
if (idx) {
|
3183
3424
|
storeKeyName.push(idx);
|
3184
3425
|
}
|
@@ -3337,16 +3578,16 @@ var DataStoreImpl = class extends BaseStoreImpl {
|
|
3337
3578
|
throw this.logger.Error().Err(url.Err()).Ref("cid", car.cid).Msg("got error from gateway.buildUrl").AsError();
|
3338
3579
|
}
|
3339
3580
|
let fpMsg;
|
3340
|
-
switch (url.Ok().getParam(
|
3581
|
+
switch (url.Ok().getParam(PARAM.STORE)) {
|
3341
3582
|
case "data":
|
3342
|
-
if (url.Ok().getParam(
|
3583
|
+
if (url.Ok().getParam(PARAM.SUFFIX)) {
|
3343
3584
|
fpMsg = Car2FPMsg(car.bytes);
|
3344
3585
|
} else {
|
3345
3586
|
fpMsg = File2FPMsg(car.bytes);
|
3346
3587
|
}
|
3347
3588
|
break;
|
3348
3589
|
default:
|
3349
|
-
throw this.logger.Error().Str("store", url.Ok().getParam(
|
3590
|
+
throw this.logger.Error().Str("store", url.Ok().getParam(PARAM.STORE)).Msg("unexpected store").AsError();
|
3350
3591
|
}
|
3351
3592
|
if (fpMsg.isErr()) {
|
3352
3593
|
throw this.logger.Error().Err(fpMsg).Msg("got error from FPMsg2Car").AsError();
|
@@ -3590,7 +3831,7 @@ async function getStartedGateway(ctx, url) {
|
|
3590
3831
|
});
|
3591
3832
|
}
|
3592
3833
|
async function dataStoreFactory(sfi) {
|
3593
|
-
const storeUrl = sfi.url.build().setParam(
|
3834
|
+
const storeUrl = sfi.url.build().setParam(PARAM.STORE, "data").URI();
|
3594
3835
|
const rgateway = await getStartedGateway(sfi, storeUrl);
|
3595
3836
|
if (rgateway.isErr()) {
|
3596
3837
|
throw sfi.loader.sthis.logger.Error().Result("err", rgateway).Url(sfi.url).Msg("notfound").AsError();
|
@@ -3604,7 +3845,7 @@ async function dataStoreFactory(sfi) {
|
|
3604
3845
|
return store;
|
3605
3846
|
}
|
3606
3847
|
async function metaStoreFactory(sfi) {
|
3607
|
-
const storeUrl = sfi.url.build().setParam(
|
3848
|
+
const storeUrl = sfi.url.build().setParam(PARAM.STORE, "meta").URI();
|
3608
3849
|
const rgateway = await getStartedGateway(sfi, storeUrl);
|
3609
3850
|
if (rgateway.isErr()) {
|
3610
3851
|
throw sfi.loader.sthis.logger.Error().Result("err", rgateway).Url(sfi.url).Msg("notfound").AsError();
|
@@ -3618,7 +3859,7 @@ async function metaStoreFactory(sfi) {
|
|
3618
3859
|
return store;
|
3619
3860
|
}
|
3620
3861
|
async function WALStoreFactory(sfi) {
|
3621
|
-
const storeUrl = sfi.url.build().setParam(
|
3862
|
+
const storeUrl = sfi.url.build().setParam(PARAM.STORE, "wal").URI();
|
3622
3863
|
const rgateway = await getStartedGateway(sfi, storeUrl);
|
3623
3864
|
if (rgateway.isErr()) {
|
3624
3865
|
throw sfi.loader.sthis.logger.Error().Result("err", rgateway).Url(sfi.url).Msg("notfound").AsError();
|
@@ -3750,11 +3991,11 @@ var ConnectionBase = class {
|
|
3750
3991
|
if (!loader) throw this.logger.Error().Msg("connectMeta: loader is required").AsError();
|
3751
3992
|
this.loader = loader;
|
3752
3993
|
await this.onConnect();
|
3753
|
-
const metaUrl = this.url.build().defParam(
|
3994
|
+
const metaUrl = this.url.build().defParam(PARAM.STORE, "meta").URI();
|
3754
3995
|
const rgateway = await getStartedGateway({ loader }, metaUrl);
|
3755
3996
|
if (rgateway.isErr())
|
3756
3997
|
throw this.logger.Error().Result("err", rgateway).Url(metaUrl).Msg("connectMeta: gateway is required").AsError();
|
3757
|
-
const dbName = metaUrl.getParam(
|
3998
|
+
const dbName = metaUrl.getParam(PARAM.NAME);
|
3758
3999
|
if (!dbName) {
|
3759
4000
|
throw this.logger.Error().Url(metaUrl).Msg("connectMeta: dbName is required").AsError();
|
3760
4001
|
}
|
@@ -3786,11 +4027,11 @@ var ConnectionBase = class {
|
|
3786
4027
|
const loader = coerceLoader(refl);
|
3787
4028
|
if (!loader) throw this.logger.Error().Msg("connectStorage: loader is required").AsError();
|
3788
4029
|
this.loader = loader;
|
3789
|
-
const dataUrl = this.url.build().defParam(
|
4030
|
+
const dataUrl = this.url.build().defParam(PARAM.STORE, "data").URI();
|
3790
4031
|
const rgateway = await getStartedGateway({ loader }, dataUrl);
|
3791
4032
|
if (rgateway.isErr())
|
3792
4033
|
throw this.logger.Error().Result("err", rgateway).Url(dataUrl).Msg("connectStorage: gateway is required").AsError();
|
3793
|
-
const name = dataUrl.getParam(
|
4034
|
+
const name = dataUrl.getParam(PARAM.NAME);
|
3794
4035
|
if (!name) throw this.logger.Error().Url(dataUrl).Msg("connectStorage: name is required").AsError;
|
3795
4036
|
loader.remoteCarStore = await RemoteDataStore(loader.sthis, this.url, {
|
3796
4037
|
gateway: rgateway.Ok().gateway,
|
@@ -4511,7 +4752,7 @@ var LedgerImpl = class {
|
|
4511
4752
|
this.crdt.clock.onTock(() => this._no_update_notify());
|
4512
4753
|
}
|
4513
4754
|
get name() {
|
4514
|
-
return this.opts.storeUrls.data.data.getParam(
|
4755
|
+
return this.opts.storeUrls.data.data.getParam(PARAM.NAME) ?? "default";
|
4515
4756
|
}
|
4516
4757
|
addShell(shell) {
|
4517
4758
|
this.shells.add(shell);
|
@@ -4597,24 +4838,24 @@ var LedgerImpl = class {
|
|
4597
4838
|
};
|
4598
4839
|
function defaultURI2(sthis, curi, uri, store, ctx) {
|
4599
4840
|
ctx = ctx || {};
|
4600
|
-
const ret = (curi ? import_cement20.URI.from(curi) : uri).build().setParam(
|
4601
|
-
if (!ret.hasParam(
|
4841
|
+
const ret = (curi ? import_cement20.URI.from(curi) : uri).build().setParam(PARAM.STORE, store);
|
4842
|
+
if (!ret.hasParam(PARAM.NAME)) {
|
4602
4843
|
const name = sthis.pathOps.basename(ret.URI().pathname);
|
4603
4844
|
if (!name) {
|
4604
4845
|
throw sthis.logger.Error().Url(ret).Any("ctx", ctx).Msg("Ledger name is required").AsError();
|
4605
4846
|
}
|
4606
|
-
ret.setParam(
|
4847
|
+
ret.setParam(PARAM.NAME, name);
|
4607
4848
|
}
|
4608
4849
|
if (ctx.idx) {
|
4609
|
-
ret.defParam(
|
4610
|
-
ret.defParam(
|
4850
|
+
ret.defParam(PARAM.INDEX, "idx");
|
4851
|
+
ret.defParam(PARAM.STORE_KEY, `@${ret.getParam(PARAM.NAME)}-${store}-idx@`);
|
4611
4852
|
} else {
|
4612
|
-
ret.defParam(
|
4853
|
+
ret.defParam(PARAM.STORE_KEY, `@${ret.getParam(PARAM.NAME)}-${store}@`);
|
4613
4854
|
}
|
4614
4855
|
if (store === "data") {
|
4615
4856
|
if (ctx.file) {
|
4616
4857
|
} else {
|
4617
|
-
ret.defParam(
|
4858
|
+
ret.defParam(PARAM.SUFFIX, ".car");
|
4618
4859
|
}
|
4619
4860
|
}
|
4620
4861
|
return ret.URI();
|
@@ -4624,14 +4865,14 @@ function toStoreURIRuntime(sthis, name, sopts) {
|
|
4624
4865
|
if (!sopts.base) {
|
4625
4866
|
const fp_env = sthis.env.get("FP_STORAGE_URL");
|
4626
4867
|
if (fp_env) {
|
4627
|
-
sopts = { ...sopts, base: import_cement20.BuildURI.from(fp_env).setParam(
|
4868
|
+
sopts = { ...sopts, base: import_cement20.BuildURI.from(fp_env).setParam(PARAM.URL_GEN, "fromEnv") };
|
4628
4869
|
} else {
|
4629
|
-
sopts = { ...sopts, base: getDefaultURI(sthis).build().setParam(
|
4870
|
+
sopts = { ...sopts, base: getDefaultURI(sthis).build().setParam(PARAM.URL_GEN, "default") };
|
4630
4871
|
}
|
4631
4872
|
}
|
4632
4873
|
const bbase = import_cement20.BuildURI.from(sopts.base);
|
4633
4874
|
if (name) {
|
4634
|
-
bbase.setParam(
|
4875
|
+
bbase.setParam(PARAM.NAME, name);
|
4635
4876
|
}
|
4636
4877
|
const base = bbase.URI();
|
4637
4878
|
return {
|
@@ -4668,9 +4909,11 @@ __export(runtime_exports, {
|
|
4668
4909
|
gw: () => gateways_exports,
|
4669
4910
|
kb: () => key_bag_exports,
|
4670
4911
|
kc: () => keyed_crypto_exports,
|
4912
|
+
keysByFingerprint: () => keysByFingerprint,
|
4671
4913
|
mf: () => wait_pr_multiformats_exports,
|
4672
4914
|
registerKeyBagProviderFactory: () => registerKeyBagProviderFactory,
|
4673
|
-
runtimeFn: () => import_cement21.runtimeFn
|
4915
|
+
runtimeFn: () => import_cement21.runtimeFn,
|
4916
|
+
toKeyWithFingerPrint: () => toKeyWithFingerPrint
|
4674
4917
|
});
|
4675
4918
|
|
4676
4919
|
// src/runtime/wait-pr-multiformats/index.ts
|
@@ -4707,6 +4950,6 @@ __export(file_exports, {
|
|
4707
4950
|
|
4708
4951
|
// src/version.ts
|
4709
4952
|
var PACKAGE_VERSION = Object.keys({
|
4710
|
-
"0.20.0-dev-preview-
|
4953
|
+
"0.20.0-dev-preview-26": "xxxx"
|
4711
4954
|
})[0];
|
4712
4955
|
//# sourceMappingURL=index.cjs.map
|