@fireproof/core 0.20.0-dev-preview-23 → 0.20.0-dev-preview-25
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 +2 -2
- package/index.cjs +414 -175
- package/index.cjs.map +1 -1
- package/index.d.cts +124 -69
- package/index.d.ts +124 -69
- package/index.js +414 -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 +4 -4
- package/tests/blockstore/keyed-crypto-indexeddb-file.test.ts +20 -13
- package/tests/blockstore/keyed-crypto.test.ts +100 -27
- 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,198 @@ 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
|
+
}
|
741
|
+
static async from(keyBag, named) {
|
742
|
+
const kbf = new _keysByFingerprint(keyBag, named.name);
|
743
|
+
for (const i of Object.entries(named.keys).reverse()) {
|
744
|
+
const result = await kbf.upsert(i[1].key, i[1].default, false);
|
745
|
+
if (result.isErr()) {
|
746
|
+
throw result;
|
747
|
+
}
|
748
|
+
if (result.Ok().modified) {
|
749
|
+
throw keyBag.logger.Error().Msg("KeyBag: keysByFingerprint: mismatch unexpected").AsError();
|
750
|
+
}
|
751
|
+
if (result.Ok().kfp.fingerPrint !== i[1].fingerPrint) {
|
752
|
+
throw keyBag.logger.Error().Any("fprs", {
|
753
|
+
fromStorage: i[1].fingerPrint,
|
754
|
+
calculated: result.Ok().kfp.fingerPrint
|
755
|
+
}).Msg("KeyBag: keysByFingerprint: mismatch").AsError();
|
756
|
+
}
|
757
|
+
}
|
758
|
+
return kbf;
|
759
|
+
}
|
760
|
+
async get(fingerPrint) {
|
761
|
+
if (fingerPrint instanceof Uint8Array) {
|
762
|
+
fingerPrint = import_base582.base58btc.encode(fingerPrint);
|
763
|
+
}
|
764
|
+
if (fingerPrint) {
|
765
|
+
return this.keys[fingerPrint];
|
766
|
+
}
|
767
|
+
const def = this.keys["*"];
|
768
|
+
if (!def) {
|
769
|
+
throw this.keybag.logger.Error().Msg("KeyBag: keysByFingerprint: no default").AsError();
|
770
|
+
}
|
771
|
+
return def;
|
772
|
+
}
|
773
|
+
async upsert(materialStrOrUint8, def, keyBagAction = true) {
|
774
|
+
const rKfp = await toKeyWithFingerPrint(this.keybag, materialStrOrUint8);
|
775
|
+
if (rKfp.isErr()) {
|
776
|
+
return import_cement4.Result.Err(rKfp);
|
777
|
+
}
|
778
|
+
const kfp = rKfp.Ok();
|
779
|
+
const found = this.keys[kfp.fingerPrint];
|
780
|
+
if (found) {
|
781
|
+
if (found.default === def) {
|
782
|
+
return import_cement4.Result.Ok({
|
783
|
+
modified: false,
|
784
|
+
kfp: found
|
785
|
+
});
|
786
|
+
}
|
787
|
+
}
|
788
|
+
if (def) {
|
789
|
+
for (const i of Object.values(this.keys)) {
|
790
|
+
i.default = false;
|
791
|
+
}
|
792
|
+
}
|
793
|
+
const out = new keyWithFingerPrint(kfp, materialStrOrUint8, def);
|
794
|
+
this.keys[kfp.fingerPrint] = out;
|
795
|
+
if (def) {
|
796
|
+
this.keys["*"] = out;
|
797
|
+
}
|
798
|
+
if (keyBagAction) {
|
799
|
+
this.keybag._upsertNamedKey(this);
|
800
|
+
}
|
801
|
+
return import_cement4.Result.Ok({
|
802
|
+
modified: keyBagAction && true,
|
803
|
+
kfp: out
|
804
|
+
});
|
805
|
+
}
|
806
|
+
async asKeysItem() {
|
807
|
+
const my = { ...this.keys };
|
808
|
+
delete my["*"];
|
809
|
+
const kis = await Promise.all(Object.values(my).map((i) => i.asV2StorageKeyItem()));
|
810
|
+
return {
|
811
|
+
name: this.name,
|
812
|
+
keys: kis.reduce(
|
813
|
+
(acc, i) => {
|
814
|
+
acc[i.fingerPrint] = i;
|
815
|
+
return acc;
|
816
|
+
},
|
817
|
+
{}
|
818
|
+
)
|
819
|
+
};
|
820
|
+
}
|
821
|
+
// async extract() {
|
822
|
+
// const ext = new Uint8Array((await this.rt.crypto.exportKey("raw", named.key)) as ArrayBuffer);
|
823
|
+
// return {
|
824
|
+
// key: ext,
|
825
|
+
// keyStr: base58btc.encode(ext),
|
826
|
+
// };
|
827
|
+
// }
|
828
|
+
};
|
669
829
|
var KeyBag = class {
|
670
830
|
constructor(rt) {
|
671
|
-
this.rt = rt;
|
672
831
|
this._warnOnce = new import_cement4.ResolveOnce();
|
673
832
|
this._seq = new import_cement4.ResolveSeq();
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
833
|
+
// async getNamedExtractableKey(name: string, failIfNotFound = false): Promise<Result<KeysByFingerprint>> {
|
834
|
+
// const ret = await this.getNamedKey(name, failIfNotFound);
|
835
|
+
// if (ret.isErr()) {
|
836
|
+
// return Result.Err(ret)
|
837
|
+
// }
|
838
|
+
// const named = ret.Ok();
|
839
|
+
// return Result.Ok({
|
840
|
+
// ...named,
|
841
|
+
// extract: async () => {
|
842
|
+
// const ext = new Uint8Array((await this.rt.crypto.exportKey("raw", named.key)) as ArrayBuffer);
|
843
|
+
// return {
|
844
|
+
// key: ext,
|
845
|
+
// keyStr: base58btc.encode(ext),
|
846
|
+
// };
|
847
|
+
// },
|
848
|
+
// });
|
849
|
+
// }
|
850
|
+
this._namedKeyCache = new import_cement4.KeyedResolvOnce();
|
851
|
+
this.rt = rt;
|
852
|
+
this.logger = ensureLogger(rt.sthis, "KeyBag");
|
678
853
|
}
|
679
|
-
async subtleKey(
|
680
|
-
const extractable = this.rt.url.getParam(
|
854
|
+
async subtleKey(materialStrOrUint8) {
|
855
|
+
const extractable = this.rt.url.getParam(PARAM.EXTRACTKEY) === "_deprecated_internal_api";
|
681
856
|
if (extractable) {
|
682
857
|
this._warnOnce.once(
|
683
858
|
() => this.logger.Warn().Msg("extractKey is enabled via _deprecated_internal_api --- handle keys safely!!!")
|
684
859
|
);
|
685
860
|
}
|
861
|
+
let material;
|
862
|
+
if (typeof materialStrOrUint8 === "string") {
|
863
|
+
material = import_base582.base58btc.decode(materialStrOrUint8);
|
864
|
+
} else {
|
865
|
+
material = materialStrOrUint8;
|
866
|
+
}
|
686
867
|
return await this.rt.crypto.importKey(
|
687
868
|
"raw",
|
688
869
|
// raw or jwk
|
689
|
-
|
870
|
+
material,
|
690
871
|
// hexStringToUint8Array(key), // raw data
|
691
872
|
"AES-GCM",
|
692
873
|
extractable,
|
@@ -694,7 +875,7 @@ var KeyBag = class {
|
|
694
875
|
);
|
695
876
|
}
|
696
877
|
async ensureKeyFromUrl(url, keyFactory) {
|
697
|
-
const storeKey = url.getParam(
|
878
|
+
const storeKey = url.getParam(PARAM.STORE_KEY);
|
698
879
|
if (storeKey === "insecure") {
|
699
880
|
return import_cement4.Result.Ok(url);
|
700
881
|
}
|
@@ -704,7 +885,7 @@ var KeyBag = class {
|
|
704
885
|
if (ret.isErr()) {
|
705
886
|
return ret;
|
706
887
|
}
|
707
|
-
const urb = url.build().setParam(
|
888
|
+
const urb = url.build().setParam(PARAM.STORE_KEY, keyName);
|
708
889
|
return import_cement4.Result.Ok(urb.URI());
|
709
890
|
}
|
710
891
|
if (storeKey.startsWith("@") && storeKey.endsWith("@")) {
|
@@ -715,63 +896,102 @@ var KeyBag = class {
|
|
715
896
|
}
|
716
897
|
return import_cement4.Result.Ok(url);
|
717
898
|
}
|
718
|
-
async
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
899
|
+
async toKeysItem(ki) {
|
900
|
+
if (!ki) return void 0;
|
901
|
+
if ("key" in ki) {
|
902
|
+
const fpr = (await toKeyWithFingerPrint(this, ki.key)).Ok().fingerPrint;
|
903
|
+
return {
|
904
|
+
name: ki.name,
|
905
|
+
keys: {
|
906
|
+
[fpr]: {
|
907
|
+
key: ki.key,
|
908
|
+
fingerPrint: fpr,
|
909
|
+
default: true
|
910
|
+
}
|
911
|
+
}
|
912
|
+
};
|
913
|
+
}
|
914
|
+
let defKI;
|
915
|
+
let foundDefKI = false;
|
916
|
+
for (const i of Object.entries(ki.keys)) {
|
917
|
+
if (i[0] !== i[1].fingerPrint) {
|
918
|
+
delete ki.keys[i[0]];
|
919
|
+
ki.keys[i[1].fingerPrint] = i[1];
|
920
|
+
this.logger.Warn().Str("name", ki.name).Msg("fingerPrint mismatch fixed");
|
921
|
+
}
|
922
|
+
if (defKI === void 0) {
|
923
|
+
defKI = i[1];
|
924
|
+
}
|
925
|
+
if (!foundDefKI && i[1].default) {
|
926
|
+
defKI = i[1];
|
927
|
+
foundDefKI = true;
|
928
|
+
} else {
|
929
|
+
i[1].default = false;
|
930
|
+
}
|
931
|
+
}
|
932
|
+
if (defKI) {
|
933
|
+
ki.keys["*"] = defKI;
|
934
|
+
}
|
935
|
+
return {
|
936
|
+
name: ki.name,
|
937
|
+
keys: ki.keys
|
938
|
+
};
|
726
939
|
}
|
727
|
-
|
728
|
-
return this._seq.
|
940
|
+
flush() {
|
941
|
+
return this._seq.flush();
|
729
942
|
}
|
943
|
+
// async setNamedKey(name: string, key: string, def?: boolean): Promise<Result<KeysByFingerprint>> {
|
944
|
+
// return this._seq.add(() => this._upsertNamedKey(name, key, !!def));
|
945
|
+
// }
|
730
946
|
// avoid deadlock
|
731
|
-
async
|
732
|
-
const item = {
|
733
|
-
name,
|
734
|
-
key
|
735
|
-
};
|
947
|
+
async _upsertNamedKey(ksi) {
|
736
948
|
const bag = await this.rt.getBagProvider();
|
737
|
-
this.
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
async getNamedExtractableKey(name, failIfNotFound = false) {
|
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
|
-
};
|
949
|
+
return this._seq.add(async () => {
|
950
|
+
const rKbf = await this._getNamedKey(ksi.name, true);
|
951
|
+
if (rKbf.isErr()) {
|
952
|
+
this._namedKeyCache.unget(ksi.name);
|
755
953
|
}
|
954
|
+
await bag.set(await ksi.asKeysItem());
|
955
|
+
return import_cement4.Result.Ok(ksi);
|
756
956
|
});
|
757
957
|
}
|
758
|
-
async
|
759
|
-
|
760
|
-
|
958
|
+
async _getNamedKey(name, failIfNotFound, material) {
|
959
|
+
return await this._namedKeyCache.get(name).once(async () => {
|
960
|
+
const id = this.rt.sthis.nextId(4).str;
|
761
961
|
const bag = await this.rt.getBagProvider();
|
762
|
-
const named = await bag.get(name);
|
962
|
+
const named = await this.toKeysItem(await bag.get(name));
|
763
963
|
if (named) {
|
764
|
-
|
765
|
-
|
766
|
-
|
964
|
+
this.logger.Debug().Str("id", id).Str("name", name).Any("fprs", Object.keys(named.keys)).Msg("fingerPrint getNamedKey");
|
965
|
+
return import_cement4.Result.Ok(await keysByFingerprint.from(this, named));
|
966
|
+
}
|
967
|
+
if (!named && failIfNotFound) {
|
968
|
+
this._namedKeyCache.unget(name);
|
969
|
+
return this.logger.Debug().Str("id", id).Str("name", name).Msg("failIfNotFound getNamedKey").ResultError();
|
767
970
|
}
|
768
|
-
|
769
|
-
|
770
|
-
|
971
|
+
const kp = new keysByFingerprint(this, name);
|
972
|
+
let keyMaterial;
|
973
|
+
if (!material) {
|
974
|
+
keyMaterial = this.rt.crypto.randomBytes(this.rt.keyLength);
|
975
|
+
} else {
|
976
|
+
if (typeof material === "string") {
|
977
|
+
keyMaterial = import_base582.base58btc.decode(material);
|
978
|
+
} else if (material instanceof Uint8Array) {
|
979
|
+
keyMaterial = material;
|
980
|
+
} else {
|
981
|
+
return this.logger.Error().Msg("material must be string or Uint8Array").ResultError();
|
982
|
+
}
|
983
|
+
}
|
984
|
+
const res = await kp.upsert(keyMaterial, true);
|
985
|
+
if (res.isErr()) {
|
986
|
+
return import_cement4.Result.Err(res);
|
771
987
|
}
|
772
|
-
|
773
|
-
|
774
|
-
|
988
|
+
this.logger.Debug().Str("id", id).Str("name", name).Str("fpr", res.Ok().kfp.fingerPrint).Msg("createKey getNamedKey-post");
|
989
|
+
return import_cement4.Result.Ok(kp);
|
990
|
+
});
|
991
|
+
}
|
992
|
+
async getNamedKey(name, failIfNotFound = false, material) {
|
993
|
+
return this._seq.add(async () => {
|
994
|
+
return await this._getNamedKey(name, failIfNotFound, material);
|
775
995
|
});
|
776
996
|
}
|
777
997
|
};
|
@@ -940,24 +1160,24 @@ var FileGateway = class {
|
|
940
1160
|
return (0, import_cement5.exception2Result)(async () => {
|
941
1161
|
await this.fs.start();
|
942
1162
|
const url = baseURL.build();
|
943
|
-
url.defParam(
|
1163
|
+
url.defParam(PARAM.VERSION, FILESTORE_VERSION);
|
944
1164
|
const dbUrl = await this.buildUrl(url.URI(), "dummy");
|
945
1165
|
const dbdirFile = this.getFilePath(dbUrl.Ok(), sthis);
|
946
1166
|
await this.fs.mkdir(sthis.pathOps.dirname(dbdirFile), { recursive: true });
|
947
1167
|
const dbroot = sthis.pathOps.dirname(dbdirFile);
|
948
1168
|
sthis.logger.Debug().Url(url.URI()).Str("dbroot", dbroot).Msg("start");
|
949
|
-
url.setParam(
|
1169
|
+
url.setParam(PARAM.VERSION, await this.getVersionFromFile(dbroot, sthis));
|
950
1170
|
return url.URI();
|
951
1171
|
});
|
952
1172
|
}
|
953
1173
|
async buildUrl(baseUrl, key) {
|
954
|
-
return import_cement5.Result.Ok(baseUrl.build().setParam(
|
1174
|
+
return import_cement5.Result.Ok(baseUrl.build().setParam(PARAM.KEY, key).URI());
|
955
1175
|
}
|
956
1176
|
async close() {
|
957
1177
|
return import_cement5.Result.Ok(void 0);
|
958
1178
|
}
|
959
1179
|
getFilePath(url, sthis) {
|
960
|
-
const key = url.getParam(
|
1180
|
+
const key = url.getParam(PARAM.KEY);
|
961
1181
|
if (!key) throw sthis.logger.Error().Url(url).Msg(`key not found`).AsError();
|
962
1182
|
return sthis.pathOps.join(getPath(url, sthis), getFileName(url, sthis));
|
963
1183
|
}
|
@@ -1013,7 +1233,7 @@ var FileGateway = class {
|
|
1013
1233
|
return import_cement5.Result.Ok(void 0);
|
1014
1234
|
}
|
1015
1235
|
async getPlain(iurl, key, sthis) {
|
1016
|
-
const url = iurl.build().setParam(
|
1236
|
+
const url = iurl.build().setParam(PARAM.KEY, key).URI();
|
1017
1237
|
const dbFile = sthis.pathOps.join(getPath(url, sthis), getFileName(url, sthis));
|
1018
1238
|
sthis.logger.Debug().Url(url).Str("dbFile", dbFile).Msg("get");
|
1019
1239
|
const buffer = await this.fs.readfile(dbFile);
|
@@ -1039,10 +1259,10 @@ var MemoryGateway = class {
|
|
1039
1259
|
this.sthis = sthis;
|
1040
1260
|
}
|
1041
1261
|
buildUrl(baseUrl, key) {
|
1042
|
-
return Promise.resolve(import_cement6.Result.Ok(baseUrl.build().setParam(
|
1262
|
+
return Promise.resolve(import_cement6.Result.Ok(baseUrl.build().setParam(PARAM.KEY, key).URI()));
|
1043
1263
|
}
|
1044
1264
|
start(baseUrl) {
|
1045
|
-
return Promise.resolve(import_cement6.Result.Ok(baseUrl.build().setParam(
|
1265
|
+
return Promise.resolve(import_cement6.Result.Ok(baseUrl.build().setParam(PARAM.VERSION, MEMORY_VERSION).URI()));
|
1046
1266
|
}
|
1047
1267
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
1048
1268
|
close(baseUrl) {
|
@@ -1070,7 +1290,7 @@ var MemoryGateway = class {
|
|
1070
1290
|
return Promise.resolve(import_cement6.Result.Ok(void 0));
|
1071
1291
|
}
|
1072
1292
|
async getPlain(url, key) {
|
1073
|
-
const x = this.memorys.get(url.build().setParam(
|
1293
|
+
const x = this.memorys.get(url.build().setParam(PARAM.KEY, key).toString());
|
1074
1294
|
if (!x) {
|
1075
1295
|
return import_cement6.Result.Err(new NotFoundError("not found"));
|
1076
1296
|
}
|
@@ -1083,18 +1303,17 @@ var import_cement9 = require("@adviser/cement");
|
|
1083
1303
|
|
1084
1304
|
// src/blockstore/fp-envelope.ts
|
1085
1305
|
var import_cement7 = require("@adviser/cement");
|
1086
|
-
var
|
1087
|
-
|
1088
|
-
|
1089
|
-
|
1090
|
-
|
1091
|
-
|
1092
|
-
})(FPEnvelopeType || {});
|
1306
|
+
var FPEnvelopeTypes = {
|
1307
|
+
CAR: "car",
|
1308
|
+
FILE: "file",
|
1309
|
+
META: "meta",
|
1310
|
+
WAL: "wal"
|
1311
|
+
};
|
1093
1312
|
function Car2FPMsg(fpcar) {
|
1094
|
-
return import_cement7.Result.Ok({ type:
|
1313
|
+
return import_cement7.Result.Ok({ type: FPEnvelopeTypes.CAR, payload: fpcar });
|
1095
1314
|
}
|
1096
1315
|
function File2FPMsg(fpfile) {
|
1097
|
-
return import_cement7.Result.Ok({ type:
|
1316
|
+
return import_cement7.Result.Ok({ type: FPEnvelopeTypes.FILE, payload: fpfile });
|
1098
1317
|
}
|
1099
1318
|
|
1100
1319
|
// src/runtime/gateways/fp-envelope-serialize.ts
|
@@ -1148,13 +1367,13 @@ async function fpSerialize(sthis, env, pencoder) {
|
|
1148
1367
|
...pencoder
|
1149
1368
|
};
|
1150
1369
|
switch (env.type) {
|
1151
|
-
case
|
1370
|
+
case FPEnvelopeTypes.FILE:
|
1152
1371
|
return encoder.file(sthis, env.payload);
|
1153
|
-
case
|
1372
|
+
case FPEnvelopeTypes.CAR:
|
1154
1373
|
return encoder.car(sthis, env.payload);
|
1155
|
-
case
|
1374
|
+
case FPEnvelopeTypes.WAL:
|
1156
1375
|
return encoder.wal(sthis, WALState2Serialized(sthis, env.payload));
|
1157
|
-
case
|
1376
|
+
case FPEnvelopeTypes.META:
|
1158
1377
|
return encoder.meta(sthis, await dbMetaEvent2Serialized(sthis, env.payload));
|
1159
1378
|
default:
|
1160
1379
|
throw sthis.logger.Error().Str("type", env.type).Msg("unsupported store").AsError();
|
@@ -1234,18 +1453,18 @@ async function fpDeserialize(sthis, url, intoRaw, pdecoder) {
|
|
1234
1453
|
...defaultDecoder,
|
1235
1454
|
...pdecoder
|
1236
1455
|
};
|
1237
|
-
switch (url.getParam(
|
1456
|
+
switch (url.getParam(PARAM.STORE)) {
|
1238
1457
|
case "data":
|
1239
|
-
if (url.getParam(
|
1240
|
-
return makeFPEnvelope(
|
1458
|
+
if (url.getParam(PARAM.SUFFIX) === ".car") {
|
1459
|
+
return makeFPEnvelope(FPEnvelopeTypes.CAR, await decoder.car(sthis, raw2));
|
1241
1460
|
}
|
1242
|
-
return makeFPEnvelope(
|
1461
|
+
return makeFPEnvelope(FPEnvelopeTypes.FILE, await decoder.file(sthis, raw2));
|
1243
1462
|
case "wal":
|
1244
|
-
return makeFPEnvelope(
|
1463
|
+
return makeFPEnvelope(FPEnvelopeTypes.WAL, await decode2WalState(sthis, await decoder.wal(sthis, raw2)));
|
1245
1464
|
case "meta":
|
1246
|
-
return makeFPEnvelope(
|
1465
|
+
return makeFPEnvelope(FPEnvelopeTypes.META, await decode2DbMetaEvents(sthis, await decoder.meta(sthis, raw2)));
|
1247
1466
|
default:
|
1248
|
-
return sthis.logger.Error().Str("store", url.getParam(
|
1467
|
+
return sthis.logger.Error().Str("store", url.getParam(PARAM.STORE)).Msg("unsupported store").ResultError();
|
1249
1468
|
}
|
1250
1469
|
}
|
1251
1470
|
|
@@ -1268,9 +1487,11 @@ var DefSerdeGateway = class {
|
|
1268
1487
|
const rUint8 = await fpSerialize(sthis, env, encoder);
|
1269
1488
|
if (rUint8.isErr()) return rUint8;
|
1270
1489
|
const ret = this.gw.put(url, rUint8.Ok(), sthis);
|
1271
|
-
if (env.type ===
|
1272
|
-
|
1273
|
-
|
1490
|
+
if (env.type === FPEnvelopeTypes.META) {
|
1491
|
+
const urlWithoutKey = url.build().delParam(PARAM.KEY).delParam(PARAM.SELF_REFLECT).toString();
|
1492
|
+
const subFn = this.subscribeFn.get(urlWithoutKey);
|
1493
|
+
if (subFn) {
|
1494
|
+
await subFn(rUint8.Ok());
|
1274
1495
|
}
|
1275
1496
|
}
|
1276
1497
|
return ret;
|
@@ -1291,7 +1512,12 @@ var DefSerdeGateway = class {
|
|
1291
1512
|
});
|
1292
1513
|
}
|
1293
1514
|
if (!this.gw.subscribe) {
|
1294
|
-
|
1515
|
+
if (!url.hasParam(PARAM.SELF_REFLECT)) {
|
1516
|
+
return import_cement9.Result.Ok(() => {
|
1517
|
+
});
|
1518
|
+
}
|
1519
|
+
const urlWithoutKey = url.build().delParam(PARAM.KEY).delParam(PARAM.SELF_REFLECT).toString();
|
1520
|
+
this.subscribeFn.set(urlWithoutKey, rawCallback);
|
1295
1521
|
return import_cement9.Result.Ok(() => {
|
1296
1522
|
this.subscribeFn.delete(url.toString());
|
1297
1523
|
});
|
@@ -1370,7 +1596,7 @@ function defaultGatewayFactoryItem() {
|
|
1370
1596
|
}
|
1371
1597
|
function defaultURI(sthis) {
|
1372
1598
|
const rt = (0, import_cement10.runtimeFn)();
|
1373
|
-
return import_cement10.BuildURI.from("file://").pathname(`${sthis.env.get("HOME")}/.fireproof/${FILESTORE_VERSION.replace(/-.*$/, "")}`).setParam(
|
1599
|
+
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
1600
|
}
|
1375
1601
|
if ((0, import_cement10.runtimeFn)().isNodeIsh || (0, import_cement10.runtimeFn)().isDeno) {
|
1376
1602
|
registerStoreProtocol({
|
@@ -1387,7 +1613,7 @@ if ((0, import_cement10.runtimeFn)().isBrowser) {
|
|
1387
1613
|
protocol: "indexeddb:",
|
1388
1614
|
isDefault: true,
|
1389
1615
|
defaultURI: () => {
|
1390
|
-
return import_cement10.BuildURI.from("indexeddb://").pathname("fp").setParam(
|
1616
|
+
return import_cement10.BuildURI.from("indexeddb://").pathname("fp").setParam(PARAM.VERSION, INDEXEDDB_VERSION).setParam(PARAM.RUNTIME, "browser").URI();
|
1391
1617
|
},
|
1392
1618
|
gateway: async () => {
|
1393
1619
|
const { GatewayImpl } = await import("@fireproof/core/indexeddb");
|
@@ -1953,7 +2179,7 @@ __export(blockstore_exports, {
|
|
1953
2179
|
DbMetaEventEqual: () => DbMetaEventEqual,
|
1954
2180
|
DbMetaEventsEqual: () => DbMetaEventsEqual,
|
1955
2181
|
EncryptedBlockstore: () => EncryptedBlockstore,
|
1956
|
-
|
2182
|
+
FPEnvelopeTypes: () => FPEnvelopeTypes,
|
1957
2183
|
File2FPMsg: () => File2FPMsg,
|
1958
2184
|
InterceptorGateway: () => InterceptorGateway,
|
1959
2185
|
Loader: () => Loader,
|
@@ -2842,12 +3068,12 @@ var generateIV = {
|
|
2842
3068
|
return hashArray;
|
2843
3069
|
},
|
2844
3070
|
verify: async function(ko, crypto, iv, data) {
|
2845
|
-
return ko.url.getParam(
|
3071
|
+
return ko.url.getParam(PARAM.IV_VERIFY) !== "disable" && UInt8ArrayEqual(iv, await this.calc(ko, crypto, data));
|
2846
3072
|
}
|
2847
3073
|
}
|
2848
3074
|
};
|
2849
3075
|
function getGenerateIVFn(url, opts) {
|
2850
|
-
const ivhash = opts.ivCalc || url.getParam(
|
3076
|
+
const ivhash = opts.ivCalc || url.getParam(PARAM.IV_HASH) || "hash";
|
2851
3077
|
return generateIV[ivhash] || generateIV["hash"];
|
2852
3078
|
}
|
2853
3079
|
var BlockIvKeyIdCodec = class {
|
@@ -2861,13 +3087,16 @@ var BlockIvKeyIdCodec = class {
|
|
2861
3087
|
async encode(data) {
|
2862
3088
|
const calcIv = this.iv || await getGenerateIVFn(this.ko.url, this.opts).calc(this.ko, this.ko.crypto, data);
|
2863
3089
|
const { iv } = this.ko.algo(calcIv);
|
2864
|
-
const
|
2865
|
-
|
2866
|
-
|
3090
|
+
const defKey = await this.ko.key.get();
|
3091
|
+
if (!defKey) {
|
3092
|
+
throw this.ko.logger.Error().Msg("default key not found").AsError();
|
3093
|
+
}
|
3094
|
+
const keyId = import_base583.base58btc.decode(defKey?.fingerPrint);
|
3095
|
+
this.ko.logger.Debug().Str("fp", defKey.fingerPrint).Msg("encode");
|
2867
3096
|
return CBOR.encode({
|
2868
3097
|
iv,
|
2869
3098
|
keyId,
|
2870
|
-
data: await this.ko._encrypt({ iv, bytes: data })
|
3099
|
+
data: await this.ko._encrypt({ iv, key: defKey.key, bytes: data })
|
2871
3100
|
});
|
2872
3101
|
}
|
2873
3102
|
async decode(abytes) {
|
@@ -2878,30 +3107,32 @@ var BlockIvKeyIdCodec = class {
|
|
2878
3107
|
bytes = new Uint8Array(abytes);
|
2879
3108
|
}
|
2880
3109
|
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();
|
3110
|
+
const key = await this.ko.key.get(keyId);
|
3111
|
+
if (!key) {
|
3112
|
+
throw this.ko.logger.Error().Str("fp", import_base583.base58btc.encode(keyId)).Msg("keyId not found").AsError();
|
2885
3113
|
}
|
2886
|
-
const result = await this.ko._decrypt({ iv, bytes: data });
|
3114
|
+
const result = await this.ko._decrypt({ iv, key: key.key, bytes: data });
|
2887
3115
|
if (!this.opts?.noIVVerify && !await getGenerateIVFn(this.ko.url, this.opts).verify(this.ko, this.ko.crypto, iv, result)) {
|
2888
3116
|
throw this.ko.logger.Error().Msg("iv missmatch").AsError();
|
2889
3117
|
}
|
2890
3118
|
return result;
|
2891
3119
|
}
|
2892
3120
|
};
|
2893
|
-
var
|
3121
|
+
var cryptoAction = class {
|
2894
3122
|
constructor(url, key, cyopt, sthis) {
|
2895
3123
|
this.ivLength = 12;
|
2896
3124
|
this.isEncrypting = true;
|
2897
|
-
this.logger = ensureLogger(sthis, "
|
3125
|
+
this.logger = ensureLogger(sthis, "cryptoAction");
|
2898
3126
|
this.crypto = cyopt;
|
2899
3127
|
this.key = key;
|
2900
3128
|
this.url = url;
|
2901
3129
|
}
|
2902
|
-
|
2903
|
-
|
2904
|
-
}
|
3130
|
+
// keyByFingerPrint(id: Uint8Array | string): Promise<Result<KeyWithFingerPrint>> {
|
3131
|
+
// return this.key.get(id)
|
3132
|
+
// }
|
3133
|
+
// fingerPrint(): Promise<string> {
|
3134
|
+
// return this.key.get().then((k) => k.fingerPrint);
|
3135
|
+
// }
|
2905
3136
|
codec(iv, opts) {
|
2906
3137
|
return new BlockIvKeyIdCodec(this, iv, opts);
|
2907
3138
|
}
|
@@ -2913,13 +3144,11 @@ var keyedCrypto = class {
|
|
2913
3144
|
};
|
2914
3145
|
}
|
2915
3146
|
async _decrypt(data) {
|
2916
|
-
this.
|
2917
|
-
return new Uint8Array(await this.crypto.decrypt(this.algo(data.iv), this.key.key, data.bytes));
|
3147
|
+
return new Uint8Array(await this.crypto.decrypt(this.algo(data.iv), data.key, data.bytes));
|
2918
3148
|
}
|
2919
3149
|
async _encrypt(data) {
|
2920
|
-
this.logger.Debug().Len(data.bytes).Str("fp", this.key.fingerPrint).Msg("encrypting");
|
2921
3150
|
const a = this.algo(data.iv);
|
2922
|
-
return new Uint8Array(await this.crypto.encrypt(a,
|
3151
|
+
return new Uint8Array(await this.crypto.encrypt(a, data.key, data.bytes));
|
2923
3152
|
}
|
2924
3153
|
};
|
2925
3154
|
var nullCodec = class {
|
@@ -2943,6 +3172,18 @@ var noCrypto = class {
|
|
2943
3172
|
this._fingerPrint = "noCrypto:" + Math.random();
|
2944
3173
|
this.logger = ensureLogger(sthis, "noCrypto");
|
2945
3174
|
this.crypto = cyrt;
|
3175
|
+
this.key = {
|
3176
|
+
name: "noCrypto",
|
3177
|
+
get: () => {
|
3178
|
+
throw this.logger.Error().Msg("noCrypto.get not implemented").AsError();
|
3179
|
+
},
|
3180
|
+
upsert: () => {
|
3181
|
+
throw this.logger.Error().Msg("noCrypto.upsert not implemented").AsError();
|
3182
|
+
},
|
3183
|
+
asKeysItem: () => {
|
3184
|
+
throw this.logger.Error().Msg("noCrypto.asKeysItem not implemented").AsError();
|
3185
|
+
}
|
3186
|
+
};
|
2946
3187
|
this.url = url;
|
2947
3188
|
}
|
2948
3189
|
fingerPrint() {
|
@@ -2968,17 +3209,13 @@ var noCrypto = class {
|
|
2968
3209
|
}
|
2969
3210
|
};
|
2970
3211
|
async function keyedCryptoFactory(url, kb, sthis) {
|
2971
|
-
const storekey = url.getParam(
|
3212
|
+
const storekey = url.getParam(PARAM.STORE_KEY);
|
2972
3213
|
if (storekey && storekey !== "insecure") {
|
2973
|
-
|
3214
|
+
const rkey = await kb.getNamedKey(storekey, false);
|
2974
3215
|
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
|
-
}
|
3216
|
+
throw sthis.logger.Error().Str("keybag", kb.rt.id()).Str("name", storekey).Msg("getNamedKey failed").AsError();
|
2980
3217
|
}
|
2981
|
-
return new
|
3218
|
+
return new cryptoAction(url, rkey.Ok(), kb.rt.crypto, sthis);
|
2982
3219
|
}
|
2983
3220
|
return new noCrypto(url, kb.rt.crypto, sthis);
|
2984
3221
|
}
|
@@ -3143,7 +3380,7 @@ var BaseStoreImpl = class {
|
|
3143
3380
|
this.opts = opts;
|
3144
3381
|
this.loader = opts.loader;
|
3145
3382
|
this.sthis = sthis;
|
3146
|
-
const name = this._url.getParam(
|
3383
|
+
const name = this._url.getParam(PARAM.NAME);
|
3147
3384
|
if (!name) {
|
3148
3385
|
throw logger.Error().Url(this._url).Msg("missing name").AsError();
|
3149
3386
|
}
|
@@ -3168,7 +3405,7 @@ var BaseStoreImpl = class {
|
|
3168
3405
|
}
|
3169
3406
|
async start() {
|
3170
3407
|
this.logger.Debug().Str("storeType", this.storeType).Msg("starting-gateway-pre");
|
3171
|
-
this._url = this._url.build().setParam(
|
3408
|
+
this._url = this._url.build().setParam(PARAM.STORE, this.storeType).URI();
|
3172
3409
|
const res = await this.gateway.start({ loader: this.loader }, this._url);
|
3173
3410
|
if (res.isErr()) {
|
3174
3411
|
this.logger.Error().Result("gw-start", res).Msg("started-gateway");
|
@@ -3177,8 +3414,8 @@ var BaseStoreImpl = class {
|
|
3177
3414
|
this._url = res.Ok();
|
3178
3415
|
const kb = await this.loader.keyBag();
|
3179
3416
|
const skRes = await kb.ensureKeyFromUrl(this._url, () => {
|
3180
|
-
const idx = this._url.getParam(
|
3181
|
-
const storeKeyName = [this.url().getParam(
|
3417
|
+
const idx = this._url.getParam(PARAM.INDEX);
|
3418
|
+
const storeKeyName = [this.url().getParam(PARAM.NAME)];
|
3182
3419
|
if (idx) {
|
3183
3420
|
storeKeyName.push(idx);
|
3184
3421
|
}
|
@@ -3337,16 +3574,16 @@ var DataStoreImpl = class extends BaseStoreImpl {
|
|
3337
3574
|
throw this.logger.Error().Err(url.Err()).Ref("cid", car.cid).Msg("got error from gateway.buildUrl").AsError();
|
3338
3575
|
}
|
3339
3576
|
let fpMsg;
|
3340
|
-
switch (url.Ok().getParam(
|
3577
|
+
switch (url.Ok().getParam(PARAM.STORE)) {
|
3341
3578
|
case "data":
|
3342
|
-
if (url.Ok().getParam(
|
3579
|
+
if (url.Ok().getParam(PARAM.SUFFIX)) {
|
3343
3580
|
fpMsg = Car2FPMsg(car.bytes);
|
3344
3581
|
} else {
|
3345
3582
|
fpMsg = File2FPMsg(car.bytes);
|
3346
3583
|
}
|
3347
3584
|
break;
|
3348
3585
|
default:
|
3349
|
-
throw this.logger.Error().Str("store", url.Ok().getParam(
|
3586
|
+
throw this.logger.Error().Str("store", url.Ok().getParam(PARAM.STORE)).Msg("unexpected store").AsError();
|
3350
3587
|
}
|
3351
3588
|
if (fpMsg.isErr()) {
|
3352
3589
|
throw this.logger.Error().Err(fpMsg).Msg("got error from FPMsg2Car").AsError();
|
@@ -3590,7 +3827,7 @@ async function getStartedGateway(ctx, url) {
|
|
3590
3827
|
});
|
3591
3828
|
}
|
3592
3829
|
async function dataStoreFactory(sfi) {
|
3593
|
-
const storeUrl = sfi.url.build().setParam(
|
3830
|
+
const storeUrl = sfi.url.build().setParam(PARAM.STORE, "data").URI();
|
3594
3831
|
const rgateway = await getStartedGateway(sfi, storeUrl);
|
3595
3832
|
if (rgateway.isErr()) {
|
3596
3833
|
throw sfi.loader.sthis.logger.Error().Result("err", rgateway).Url(sfi.url).Msg("notfound").AsError();
|
@@ -3604,7 +3841,7 @@ async function dataStoreFactory(sfi) {
|
|
3604
3841
|
return store;
|
3605
3842
|
}
|
3606
3843
|
async function metaStoreFactory(sfi) {
|
3607
|
-
const storeUrl = sfi.url.build().setParam(
|
3844
|
+
const storeUrl = sfi.url.build().setParam(PARAM.STORE, "meta").URI();
|
3608
3845
|
const rgateway = await getStartedGateway(sfi, storeUrl);
|
3609
3846
|
if (rgateway.isErr()) {
|
3610
3847
|
throw sfi.loader.sthis.logger.Error().Result("err", rgateway).Url(sfi.url).Msg("notfound").AsError();
|
@@ -3618,7 +3855,7 @@ async function metaStoreFactory(sfi) {
|
|
3618
3855
|
return store;
|
3619
3856
|
}
|
3620
3857
|
async function WALStoreFactory(sfi) {
|
3621
|
-
const storeUrl = sfi.url.build().setParam(
|
3858
|
+
const storeUrl = sfi.url.build().setParam(PARAM.STORE, "wal").URI();
|
3622
3859
|
const rgateway = await getStartedGateway(sfi, storeUrl);
|
3623
3860
|
if (rgateway.isErr()) {
|
3624
3861
|
throw sfi.loader.sthis.logger.Error().Result("err", rgateway).Url(sfi.url).Msg("notfound").AsError();
|
@@ -3750,11 +3987,11 @@ var ConnectionBase = class {
|
|
3750
3987
|
if (!loader) throw this.logger.Error().Msg("connectMeta: loader is required").AsError();
|
3751
3988
|
this.loader = loader;
|
3752
3989
|
await this.onConnect();
|
3753
|
-
const metaUrl = this.url.build().defParam(
|
3990
|
+
const metaUrl = this.url.build().defParam(PARAM.STORE, "meta").URI();
|
3754
3991
|
const rgateway = await getStartedGateway({ loader }, metaUrl);
|
3755
3992
|
if (rgateway.isErr())
|
3756
3993
|
throw this.logger.Error().Result("err", rgateway).Url(metaUrl).Msg("connectMeta: gateway is required").AsError();
|
3757
|
-
const dbName = metaUrl.getParam(
|
3994
|
+
const dbName = metaUrl.getParam(PARAM.NAME);
|
3758
3995
|
if (!dbName) {
|
3759
3996
|
throw this.logger.Error().Url(metaUrl).Msg("connectMeta: dbName is required").AsError();
|
3760
3997
|
}
|
@@ -3786,11 +4023,11 @@ var ConnectionBase = class {
|
|
3786
4023
|
const loader = coerceLoader(refl);
|
3787
4024
|
if (!loader) throw this.logger.Error().Msg("connectStorage: loader is required").AsError();
|
3788
4025
|
this.loader = loader;
|
3789
|
-
const dataUrl = this.url.build().defParam(
|
4026
|
+
const dataUrl = this.url.build().defParam(PARAM.STORE, "data").URI();
|
3790
4027
|
const rgateway = await getStartedGateway({ loader }, dataUrl);
|
3791
4028
|
if (rgateway.isErr())
|
3792
4029
|
throw this.logger.Error().Result("err", rgateway).Url(dataUrl).Msg("connectStorage: gateway is required").AsError();
|
3793
|
-
const name = dataUrl.getParam(
|
4030
|
+
const name = dataUrl.getParam(PARAM.NAME);
|
3794
4031
|
if (!name) throw this.logger.Error().Url(dataUrl).Msg("connectStorage: name is required").AsError;
|
3795
4032
|
loader.remoteCarStore = await RemoteDataStore(loader.sthis, this.url, {
|
3796
4033
|
gateway: rgateway.Ok().gateway,
|
@@ -4511,7 +4748,7 @@ var LedgerImpl = class {
|
|
4511
4748
|
this.crdt.clock.onTock(() => this._no_update_notify());
|
4512
4749
|
}
|
4513
4750
|
get name() {
|
4514
|
-
return this.opts.storeUrls.data.data.getParam(
|
4751
|
+
return this.opts.storeUrls.data.data.getParam(PARAM.NAME) ?? "default";
|
4515
4752
|
}
|
4516
4753
|
addShell(shell) {
|
4517
4754
|
this.shells.add(shell);
|
@@ -4597,24 +4834,24 @@ var LedgerImpl = class {
|
|
4597
4834
|
};
|
4598
4835
|
function defaultURI2(sthis, curi, uri, store, ctx) {
|
4599
4836
|
ctx = ctx || {};
|
4600
|
-
const ret = (curi ? import_cement20.URI.from(curi) : uri).build().setParam(
|
4601
|
-
if (!ret.hasParam(
|
4837
|
+
const ret = (curi ? import_cement20.URI.from(curi) : uri).build().setParam(PARAM.STORE, store);
|
4838
|
+
if (!ret.hasParam(PARAM.NAME)) {
|
4602
4839
|
const name = sthis.pathOps.basename(ret.URI().pathname);
|
4603
4840
|
if (!name) {
|
4604
4841
|
throw sthis.logger.Error().Url(ret).Any("ctx", ctx).Msg("Ledger name is required").AsError();
|
4605
4842
|
}
|
4606
|
-
ret.setParam(
|
4843
|
+
ret.setParam(PARAM.NAME, name);
|
4607
4844
|
}
|
4608
4845
|
if (ctx.idx) {
|
4609
|
-
ret.defParam(
|
4610
|
-
ret.defParam(
|
4846
|
+
ret.defParam(PARAM.INDEX, "idx");
|
4847
|
+
ret.defParam(PARAM.STORE_KEY, `@${ret.getParam(PARAM.NAME)}-${store}-idx@`);
|
4611
4848
|
} else {
|
4612
|
-
ret.defParam(
|
4849
|
+
ret.defParam(PARAM.STORE_KEY, `@${ret.getParam(PARAM.NAME)}-${store}@`);
|
4613
4850
|
}
|
4614
4851
|
if (store === "data") {
|
4615
4852
|
if (ctx.file) {
|
4616
4853
|
} else {
|
4617
|
-
ret.defParam(
|
4854
|
+
ret.defParam(PARAM.SUFFIX, ".car");
|
4618
4855
|
}
|
4619
4856
|
}
|
4620
4857
|
return ret.URI();
|
@@ -4624,14 +4861,14 @@ function toStoreURIRuntime(sthis, name, sopts) {
|
|
4624
4861
|
if (!sopts.base) {
|
4625
4862
|
const fp_env = sthis.env.get("FP_STORAGE_URL");
|
4626
4863
|
if (fp_env) {
|
4627
|
-
sopts = { ...sopts, base: import_cement20.BuildURI.from(fp_env).setParam(
|
4864
|
+
sopts = { ...sopts, base: import_cement20.BuildURI.from(fp_env).setParam(PARAM.URL_GEN, "fromEnv") };
|
4628
4865
|
} else {
|
4629
|
-
sopts = { ...sopts, base: getDefaultURI(sthis).build().setParam(
|
4866
|
+
sopts = { ...sopts, base: getDefaultURI(sthis).build().setParam(PARAM.URL_GEN, "default") };
|
4630
4867
|
}
|
4631
4868
|
}
|
4632
4869
|
const bbase = import_cement20.BuildURI.from(sopts.base);
|
4633
4870
|
if (name) {
|
4634
|
-
bbase.setParam(
|
4871
|
+
bbase.setParam(PARAM.NAME, name);
|
4635
4872
|
}
|
4636
4873
|
const base = bbase.URI();
|
4637
4874
|
return {
|
@@ -4668,9 +4905,11 @@ __export(runtime_exports, {
|
|
4668
4905
|
gw: () => gateways_exports,
|
4669
4906
|
kb: () => key_bag_exports,
|
4670
4907
|
kc: () => keyed_crypto_exports,
|
4908
|
+
keysByFingerprint: () => keysByFingerprint,
|
4671
4909
|
mf: () => wait_pr_multiformats_exports,
|
4672
4910
|
registerKeyBagProviderFactory: () => registerKeyBagProviderFactory,
|
4673
|
-
runtimeFn: () => import_cement21.runtimeFn
|
4911
|
+
runtimeFn: () => import_cement21.runtimeFn,
|
4912
|
+
toKeyWithFingerPrint: () => toKeyWithFingerPrint
|
4674
4913
|
});
|
4675
4914
|
|
4676
4915
|
// src/runtime/wait-pr-multiformats/index.ts
|
@@ -4707,6 +4946,6 @@ __export(file_exports, {
|
|
4707
4946
|
|
4708
4947
|
// src/version.ts
|
4709
4948
|
var PACKAGE_VERSION = Object.keys({
|
4710
|
-
"0.20.0-dev-preview-
|
4949
|
+
"0.20.0-dev-preview-25": "xxxx"
|
4711
4950
|
})[0];
|
4712
4951
|
//# sourceMappingURL=index.cjs.map
|