@fireproof/core 0.20.0-dev-preview-24 → 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 +1 -1
- 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 +3 -3
- 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.js
CHANGED
@@ -24,26 +24,30 @@ import {
|
|
24
24
|
function isFalsy(value) {
|
25
25
|
return value === false && value === null && value === void 0;
|
26
26
|
}
|
27
|
-
var PARAM =
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
27
|
+
var PARAM = {
|
28
|
+
SUFFIX: "suffix",
|
29
|
+
URL_GEN: "urlGen",
|
30
|
+
// "urlGen" | "default"
|
31
|
+
STORE_KEY: "storekey",
|
32
|
+
STORE: "store",
|
33
|
+
KEY: "key",
|
34
|
+
INDEX: "index",
|
35
|
+
NAME: "name",
|
36
|
+
VERSION: "version",
|
37
|
+
RUNTIME: "runtime",
|
38
|
+
// "node" | "deno" | "browser"
|
39
|
+
FRAG_SIZE: "fragSize",
|
40
|
+
IV_VERIFY: "ivVerify",
|
41
|
+
IV_HASH: "ivHash",
|
42
|
+
FRAG_FID: "fid",
|
43
|
+
FRAG_OFS: "ofs",
|
44
|
+
FRAG_LEN: "len",
|
45
|
+
FRAG_HEAD: "headerSize",
|
46
|
+
EXTRACTKEY: "extractKey",
|
47
|
+
SELF_REFLECT: "selfReflect"
|
48
|
+
// if no subscribe in Gateway see your own META updates
|
49
|
+
// FS = "fs",
|
50
|
+
};
|
47
51
|
function throwFalsy(value) {
|
48
52
|
if (isFalsy(value)) {
|
49
53
|
throw new Error("value is Falsy");
|
@@ -266,7 +270,7 @@ function ensureLogger(sthis, componentName, ctx) {
|
|
266
270
|
return out;
|
267
271
|
}
|
268
272
|
function getStore(url, sthis, joiner) {
|
269
|
-
const store = url.getParam(
|
273
|
+
const store = url.getParam(PARAM.STORE);
|
270
274
|
switch (store) {
|
271
275
|
case "data":
|
272
276
|
case "wal":
|
@@ -278,17 +282,17 @@ function getStore(url, sthis, joiner) {
|
|
278
282
|
}
|
279
283
|
let name = store;
|
280
284
|
if (url.hasParam("index")) {
|
281
|
-
name = joiner(url.getParam(
|
285
|
+
name = joiner(url.getParam(PARAM.INDEX) || "idx", name);
|
282
286
|
}
|
283
287
|
return { store, name };
|
284
288
|
}
|
285
289
|
function getKey(url, logger) {
|
286
|
-
const result = url.getParam(
|
290
|
+
const result = url.getParam(PARAM.KEY);
|
287
291
|
if (!result) throw logger.Error().Str("url", url.toString()).Msg(`key not found`).AsError();
|
288
292
|
return result;
|
289
293
|
}
|
290
294
|
function getName(sthis, url) {
|
291
|
-
let result = url.getParam(
|
295
|
+
let result = url.getParam(PARAM.NAME);
|
292
296
|
if (!result) {
|
293
297
|
result = sthis.pathOps.dirname(url.pathname);
|
294
298
|
if (result.length === 0) {
|
@@ -528,7 +532,9 @@ __export(key_bag_exports, {
|
|
528
532
|
defaultKeyBagOpts: () => defaultKeyBagOpts,
|
529
533
|
defaultKeyBagUrl: () => defaultKeyBagUrl,
|
530
534
|
getKeyBag: () => getKeyBag,
|
531
|
-
|
535
|
+
keysByFingerprint: () => keysByFingerprint,
|
536
|
+
registerKeyBagProviderFactory: () => registerKeyBagProviderFactory,
|
537
|
+
toKeyWithFingerPrint: () => toKeyWithFingerPrint
|
532
538
|
});
|
533
539
|
import {
|
534
540
|
KeyedResolvOnce,
|
@@ -586,8 +592,8 @@ var KeyBagProviderFile = class {
|
|
586
592
|
throw this.logger.Error().Err(e).Str("file", ctx.dirName).Msg("read bag failed").AsError();
|
587
593
|
}
|
588
594
|
}
|
589
|
-
async set(
|
590
|
-
const ctx = await this._prepare(
|
595
|
+
async set(item) {
|
596
|
+
const ctx = await this._prepare(item.name);
|
591
597
|
const p = this.sthis.txt.encode(JSON.stringify(item, null, 2));
|
592
598
|
await ctx.sysFS.writefile(ctx.fName, p);
|
593
599
|
}
|
@@ -603,6 +609,17 @@ var KeyBagProviderMemory = class {
|
|
603
609
|
key(id) {
|
604
610
|
return `${this.url.pathname}/${id}`;
|
605
611
|
}
|
612
|
+
// async _prepare(id: string): Promise<KeyBagCtx> {
|
613
|
+
// await this.sthis.start();
|
614
|
+
// const sysFS = await sysFileSystemFactory(this.url);
|
615
|
+
// const dirName = this.url.pathname;
|
616
|
+
// await sysFS.mkdir(dirName, { recursive: true });
|
617
|
+
// return {
|
618
|
+
// dirName,
|
619
|
+
// sysFS,
|
620
|
+
// fName: this.sthis.pathOps.join(dirName, `${id.replace(/[^a-zA-Z0-9]/g, "_")}.json`),
|
621
|
+
// };
|
622
|
+
// }
|
606
623
|
async get(id) {
|
607
624
|
const binKeyItem = memoryKeyBag.get(this.key(id));
|
608
625
|
if (binKeyItem) {
|
@@ -611,34 +628,198 @@ var KeyBagProviderMemory = class {
|
|
611
628
|
}
|
612
629
|
return void 0;
|
613
630
|
}
|
614
|
-
async set(
|
631
|
+
async set(item) {
|
615
632
|
const p = this.sthis.txt.encode(JSON.stringify(item, null, 2));
|
616
|
-
memoryKeyBag.set(this.key(
|
633
|
+
memoryKeyBag.set(this.key(item.name), p);
|
617
634
|
}
|
618
635
|
};
|
619
636
|
|
620
637
|
// src/runtime/key-bag.ts
|
638
|
+
var keyWithFingerPrint = class {
|
639
|
+
#material;
|
640
|
+
constructor(kfp, material, def) {
|
641
|
+
this.kfp = kfp;
|
642
|
+
this.key = kfp.key;
|
643
|
+
this.fingerPrint = kfp.fingerPrint;
|
644
|
+
this.default = def;
|
645
|
+
if (material instanceof Uint8Array) {
|
646
|
+
this.#material = base58btc2.encode(material);
|
647
|
+
} else if (typeof material === "string") {
|
648
|
+
this.#material = material;
|
649
|
+
} else {
|
650
|
+
throw new Error("material must be string or Uint8Array");
|
651
|
+
}
|
652
|
+
}
|
653
|
+
extract() {
|
654
|
+
return this.kfp.extract();
|
655
|
+
}
|
656
|
+
async asV2StorageKeyItem() {
|
657
|
+
return {
|
658
|
+
default: this.default,
|
659
|
+
fingerPrint: this.fingerPrint,
|
660
|
+
key: this.#material
|
661
|
+
};
|
662
|
+
}
|
663
|
+
};
|
664
|
+
async function toKeyWithFingerPrint(keybag, materialStrOrUint8) {
|
665
|
+
let material;
|
666
|
+
if (typeof materialStrOrUint8 === "string") {
|
667
|
+
material = base58btc2.decode(materialStrOrUint8);
|
668
|
+
} else {
|
669
|
+
material = materialStrOrUint8;
|
670
|
+
}
|
671
|
+
const key = await keybag.subtleKey(material);
|
672
|
+
const fpr = await keybag.rt.crypto.digestSHA256(material);
|
673
|
+
return Result2.Ok({
|
674
|
+
key,
|
675
|
+
fingerPrint: base58btc2.encode(new Uint8Array(fpr)),
|
676
|
+
extract: async () => {
|
677
|
+
if (key.extractable) {
|
678
|
+
return {
|
679
|
+
key: material,
|
680
|
+
keyStr: base58btc2.encode(material)
|
681
|
+
};
|
682
|
+
}
|
683
|
+
throw new Error("Key is not extractable");
|
684
|
+
}
|
685
|
+
});
|
686
|
+
}
|
687
|
+
var keysByFingerprint = class _keysByFingerprint {
|
688
|
+
constructor(keyBag, name) {
|
689
|
+
this.keys = {};
|
690
|
+
this.keybag = keyBag;
|
691
|
+
this.name = name;
|
692
|
+
}
|
693
|
+
static async from(keyBag, named) {
|
694
|
+
const kbf = new _keysByFingerprint(keyBag, named.name);
|
695
|
+
for (const i of Object.entries(named.keys).reverse()) {
|
696
|
+
const result = await kbf.upsert(i[1].key, i[1].default, false);
|
697
|
+
if (result.isErr()) {
|
698
|
+
throw result;
|
699
|
+
}
|
700
|
+
if (result.Ok().modified) {
|
701
|
+
throw keyBag.logger.Error().Msg("KeyBag: keysByFingerprint: mismatch unexpected").AsError();
|
702
|
+
}
|
703
|
+
if (result.Ok().kfp.fingerPrint !== i[1].fingerPrint) {
|
704
|
+
throw keyBag.logger.Error().Any("fprs", {
|
705
|
+
fromStorage: i[1].fingerPrint,
|
706
|
+
calculated: result.Ok().kfp.fingerPrint
|
707
|
+
}).Msg("KeyBag: keysByFingerprint: mismatch").AsError();
|
708
|
+
}
|
709
|
+
}
|
710
|
+
return kbf;
|
711
|
+
}
|
712
|
+
async get(fingerPrint) {
|
713
|
+
if (fingerPrint instanceof Uint8Array) {
|
714
|
+
fingerPrint = base58btc2.encode(fingerPrint);
|
715
|
+
}
|
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();
|
722
|
+
}
|
723
|
+
return def;
|
724
|
+
}
|
725
|
+
async upsert(materialStrOrUint8, def, keyBagAction = true) {
|
726
|
+
const rKfp = await toKeyWithFingerPrint(this.keybag, materialStrOrUint8);
|
727
|
+
if (rKfp.isErr()) {
|
728
|
+
return Result2.Err(rKfp);
|
729
|
+
}
|
730
|
+
const kfp = rKfp.Ok();
|
731
|
+
const found = this.keys[kfp.fingerPrint];
|
732
|
+
if (found) {
|
733
|
+
if (found.default === def) {
|
734
|
+
return Result2.Ok({
|
735
|
+
modified: false,
|
736
|
+
kfp: found
|
737
|
+
});
|
738
|
+
}
|
739
|
+
}
|
740
|
+
if (def) {
|
741
|
+
for (const i of Object.values(this.keys)) {
|
742
|
+
i.default = false;
|
743
|
+
}
|
744
|
+
}
|
745
|
+
const out = new keyWithFingerPrint(kfp, materialStrOrUint8, def);
|
746
|
+
this.keys[kfp.fingerPrint] = out;
|
747
|
+
if (def) {
|
748
|
+
this.keys["*"] = out;
|
749
|
+
}
|
750
|
+
if (keyBagAction) {
|
751
|
+
this.keybag._upsertNamedKey(this);
|
752
|
+
}
|
753
|
+
return Result2.Ok({
|
754
|
+
modified: keyBagAction && true,
|
755
|
+
kfp: out
|
756
|
+
});
|
757
|
+
}
|
758
|
+
async asKeysItem() {
|
759
|
+
const my = { ...this.keys };
|
760
|
+
delete my["*"];
|
761
|
+
const kis = await Promise.all(Object.values(my).map((i) => i.asV2StorageKeyItem()));
|
762
|
+
return {
|
763
|
+
name: this.name,
|
764
|
+
keys: kis.reduce(
|
765
|
+
(acc, i) => {
|
766
|
+
acc[i.fingerPrint] = i;
|
767
|
+
return acc;
|
768
|
+
},
|
769
|
+
{}
|
770
|
+
)
|
771
|
+
};
|
772
|
+
}
|
773
|
+
// async extract() {
|
774
|
+
// const ext = new Uint8Array((await this.rt.crypto.exportKey("raw", named.key)) as ArrayBuffer);
|
775
|
+
// return {
|
776
|
+
// key: ext,
|
777
|
+
// keyStr: base58btc.encode(ext),
|
778
|
+
// };
|
779
|
+
// }
|
780
|
+
};
|
621
781
|
var KeyBag = class {
|
622
782
|
constructor(rt) {
|
623
|
-
this.rt = rt;
|
624
783
|
this._warnOnce = new ResolveOnce2();
|
625
784
|
this._seq = new ResolveSeq();
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
785
|
+
// async getNamedExtractableKey(name: string, failIfNotFound = false): Promise<Result<KeysByFingerprint>> {
|
786
|
+
// const ret = await this.getNamedKey(name, failIfNotFound);
|
787
|
+
// if (ret.isErr()) {
|
788
|
+
// return Result.Err(ret)
|
789
|
+
// }
|
790
|
+
// const named = ret.Ok();
|
791
|
+
// return Result.Ok({
|
792
|
+
// ...named,
|
793
|
+
// extract: async () => {
|
794
|
+
// const ext = new Uint8Array((await this.rt.crypto.exportKey("raw", named.key)) as ArrayBuffer);
|
795
|
+
// return {
|
796
|
+
// key: ext,
|
797
|
+
// keyStr: base58btc.encode(ext),
|
798
|
+
// };
|
799
|
+
// },
|
800
|
+
// });
|
801
|
+
// }
|
802
|
+
this._namedKeyCache = new KeyedResolvOnce();
|
803
|
+
this.rt = rt;
|
804
|
+
this.logger = ensureLogger(rt.sthis, "KeyBag");
|
630
805
|
}
|
631
|
-
async subtleKey(
|
632
|
-
const extractable = this.rt.url.getParam(
|
806
|
+
async subtleKey(materialStrOrUint8) {
|
807
|
+
const extractable = this.rt.url.getParam(PARAM.EXTRACTKEY) === "_deprecated_internal_api";
|
633
808
|
if (extractable) {
|
634
809
|
this._warnOnce.once(
|
635
810
|
() => this.logger.Warn().Msg("extractKey is enabled via _deprecated_internal_api --- handle keys safely!!!")
|
636
811
|
);
|
637
812
|
}
|
813
|
+
let material;
|
814
|
+
if (typeof materialStrOrUint8 === "string") {
|
815
|
+
material = base58btc2.decode(materialStrOrUint8);
|
816
|
+
} else {
|
817
|
+
material = materialStrOrUint8;
|
818
|
+
}
|
638
819
|
return await this.rt.crypto.importKey(
|
639
820
|
"raw",
|
640
821
|
// raw or jwk
|
641
|
-
|
822
|
+
material,
|
642
823
|
// hexStringToUint8Array(key), // raw data
|
643
824
|
"AES-GCM",
|
644
825
|
extractable,
|
@@ -646,7 +827,7 @@ var KeyBag = class {
|
|
646
827
|
);
|
647
828
|
}
|
648
829
|
async ensureKeyFromUrl(url, keyFactory) {
|
649
|
-
const storeKey = url.getParam(
|
830
|
+
const storeKey = url.getParam(PARAM.STORE_KEY);
|
650
831
|
if (storeKey === "insecure") {
|
651
832
|
return Result2.Ok(url);
|
652
833
|
}
|
@@ -656,7 +837,7 @@ var KeyBag = class {
|
|
656
837
|
if (ret.isErr()) {
|
657
838
|
return ret;
|
658
839
|
}
|
659
|
-
const urb = url.build().setParam(
|
840
|
+
const urb = url.build().setParam(PARAM.STORE_KEY, keyName);
|
660
841
|
return Result2.Ok(urb.URI());
|
661
842
|
}
|
662
843
|
if (storeKey.startsWith("@") && storeKey.endsWith("@")) {
|
@@ -667,63 +848,102 @@ var KeyBag = class {
|
|
667
848
|
}
|
668
849
|
return Result2.Ok(url);
|
669
850
|
}
|
670
|
-
async
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
851
|
+
async toKeysItem(ki) {
|
852
|
+
if (!ki) return void 0;
|
853
|
+
if ("key" in ki) {
|
854
|
+
const fpr = (await toKeyWithFingerPrint(this, ki.key)).Ok().fingerPrint;
|
855
|
+
return {
|
856
|
+
name: ki.name,
|
857
|
+
keys: {
|
858
|
+
[fpr]: {
|
859
|
+
key: ki.key,
|
860
|
+
fingerPrint: fpr,
|
861
|
+
default: true
|
862
|
+
}
|
863
|
+
}
|
864
|
+
};
|
865
|
+
}
|
866
|
+
let defKI;
|
867
|
+
let foundDefKI = false;
|
868
|
+
for (const i of Object.entries(ki.keys)) {
|
869
|
+
if (i[0] !== i[1].fingerPrint) {
|
870
|
+
delete ki.keys[i[0]];
|
871
|
+
ki.keys[i[1].fingerPrint] = i[1];
|
872
|
+
this.logger.Warn().Str("name", ki.name).Msg("fingerPrint mismatch fixed");
|
873
|
+
}
|
874
|
+
if (defKI === void 0) {
|
875
|
+
defKI = i[1];
|
876
|
+
}
|
877
|
+
if (!foundDefKI && i[1].default) {
|
878
|
+
defKI = i[1];
|
879
|
+
foundDefKI = true;
|
880
|
+
} else {
|
881
|
+
i[1].default = false;
|
882
|
+
}
|
883
|
+
}
|
884
|
+
if (defKI) {
|
885
|
+
ki.keys["*"] = defKI;
|
886
|
+
}
|
887
|
+
return {
|
888
|
+
name: ki.name,
|
889
|
+
keys: ki.keys
|
890
|
+
};
|
678
891
|
}
|
679
|
-
|
680
|
-
return this._seq.
|
892
|
+
flush() {
|
893
|
+
return this._seq.flush();
|
681
894
|
}
|
895
|
+
// async setNamedKey(name: string, key: string, def?: boolean): Promise<Result<KeysByFingerprint>> {
|
896
|
+
// return this._seq.add(() => this._upsertNamedKey(name, key, !!def));
|
897
|
+
// }
|
682
898
|
// avoid deadlock
|
683
|
-
async
|
684
|
-
const item = {
|
685
|
-
name,
|
686
|
-
key
|
687
|
-
};
|
899
|
+
async _upsertNamedKey(ksi) {
|
688
900
|
const bag = await this.rt.getBagProvider();
|
689
|
-
this.
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
async getNamedExtractableKey(name, failIfNotFound = false) {
|
694
|
-
const ret = await this.getNamedKey(name, failIfNotFound);
|
695
|
-
if (ret.isErr()) {
|
696
|
-
return ret;
|
697
|
-
}
|
698
|
-
const named = ret.Ok();
|
699
|
-
return Result2.Ok({
|
700
|
-
...named,
|
701
|
-
extract: async () => {
|
702
|
-
const ext = new Uint8Array(await this.rt.crypto.exportKey("raw", named.key));
|
703
|
-
return {
|
704
|
-
key: ext,
|
705
|
-
keyStr: base58btc2.encode(ext)
|
706
|
-
};
|
901
|
+
return this._seq.add(async () => {
|
902
|
+
const rKbf = await this._getNamedKey(ksi.name, true);
|
903
|
+
if (rKbf.isErr()) {
|
904
|
+
this._namedKeyCache.unget(ksi.name);
|
707
905
|
}
|
906
|
+
await bag.set(await ksi.asKeysItem());
|
907
|
+
return Result2.Ok(ksi);
|
708
908
|
});
|
709
909
|
}
|
710
|
-
async
|
711
|
-
|
712
|
-
|
910
|
+
async _getNamedKey(name, failIfNotFound, material) {
|
911
|
+
return await this._namedKeyCache.get(name).once(async () => {
|
912
|
+
const id = this.rt.sthis.nextId(4).str;
|
713
913
|
const bag = await this.rt.getBagProvider();
|
714
|
-
const named = await bag.get(name);
|
914
|
+
const named = await this.toKeysItem(await bag.get(name));
|
715
915
|
if (named) {
|
716
|
-
|
717
|
-
|
718
|
-
|
916
|
+
this.logger.Debug().Str("id", id).Str("name", name).Any("fprs", Object.keys(named.keys)).Msg("fingerPrint getNamedKey");
|
917
|
+
return Result2.Ok(await keysByFingerprint.from(this, named));
|
918
|
+
}
|
919
|
+
if (!named && failIfNotFound) {
|
920
|
+
this._namedKeyCache.unget(name);
|
921
|
+
return this.logger.Debug().Str("id", id).Str("name", name).Msg("failIfNotFound getNamedKey").ResultError();
|
719
922
|
}
|
720
|
-
|
721
|
-
|
722
|
-
|
923
|
+
const kp = new keysByFingerprint(this, name);
|
924
|
+
let keyMaterial;
|
925
|
+
if (!material) {
|
926
|
+
keyMaterial = this.rt.crypto.randomBytes(this.rt.keyLength);
|
927
|
+
} else {
|
928
|
+
if (typeof material === "string") {
|
929
|
+
keyMaterial = base58btc2.decode(material);
|
930
|
+
} else if (material instanceof Uint8Array) {
|
931
|
+
keyMaterial = material;
|
932
|
+
} else {
|
933
|
+
return this.logger.Error().Msg("material must be string or Uint8Array").ResultError();
|
934
|
+
}
|
935
|
+
}
|
936
|
+
const res = await kp.upsert(keyMaterial, true);
|
937
|
+
if (res.isErr()) {
|
938
|
+
return Result2.Err(res);
|
723
939
|
}
|
724
|
-
|
725
|
-
|
726
|
-
|
940
|
+
this.logger.Debug().Str("id", id).Str("name", name).Str("fpr", res.Ok().kfp.fingerPrint).Msg("createKey getNamedKey-post");
|
941
|
+
return Result2.Ok(kp);
|
942
|
+
});
|
943
|
+
}
|
944
|
+
async getNamedKey(name, failIfNotFound = false, material) {
|
945
|
+
return this._seq.add(async () => {
|
946
|
+
return await this._getNamedKey(name, failIfNotFound, material);
|
727
947
|
});
|
728
948
|
}
|
729
949
|
};
|
@@ -892,24 +1112,24 @@ var FileGateway = class {
|
|
892
1112
|
return exception2Result(async () => {
|
893
1113
|
await this.fs.start();
|
894
1114
|
const url = baseURL.build();
|
895
|
-
url.defParam(
|
1115
|
+
url.defParam(PARAM.VERSION, FILESTORE_VERSION);
|
896
1116
|
const dbUrl = await this.buildUrl(url.URI(), "dummy");
|
897
1117
|
const dbdirFile = this.getFilePath(dbUrl.Ok(), sthis);
|
898
1118
|
await this.fs.mkdir(sthis.pathOps.dirname(dbdirFile), { recursive: true });
|
899
1119
|
const dbroot = sthis.pathOps.dirname(dbdirFile);
|
900
1120
|
sthis.logger.Debug().Url(url.URI()).Str("dbroot", dbroot).Msg("start");
|
901
|
-
url.setParam(
|
1121
|
+
url.setParam(PARAM.VERSION, await this.getVersionFromFile(dbroot, sthis));
|
902
1122
|
return url.URI();
|
903
1123
|
});
|
904
1124
|
}
|
905
1125
|
async buildUrl(baseUrl, key) {
|
906
|
-
return Result3.Ok(baseUrl.build().setParam(
|
1126
|
+
return Result3.Ok(baseUrl.build().setParam(PARAM.KEY, key).URI());
|
907
1127
|
}
|
908
1128
|
async close() {
|
909
1129
|
return Result3.Ok(void 0);
|
910
1130
|
}
|
911
1131
|
getFilePath(url, sthis) {
|
912
|
-
const key = url.getParam(
|
1132
|
+
const key = url.getParam(PARAM.KEY);
|
913
1133
|
if (!key) throw sthis.logger.Error().Url(url).Msg(`key not found`).AsError();
|
914
1134
|
return sthis.pathOps.join(getPath(url, sthis), getFileName(url, sthis));
|
915
1135
|
}
|
@@ -965,7 +1185,7 @@ var FileGateway = class {
|
|
965
1185
|
return Result3.Ok(void 0);
|
966
1186
|
}
|
967
1187
|
async getPlain(iurl, key, sthis) {
|
968
|
-
const url = iurl.build().setParam(
|
1188
|
+
const url = iurl.build().setParam(PARAM.KEY, key).URI();
|
969
1189
|
const dbFile = sthis.pathOps.join(getPath(url, sthis), getFileName(url, sthis));
|
970
1190
|
sthis.logger.Debug().Url(url).Str("dbFile", dbFile).Msg("get");
|
971
1191
|
const buffer = await this.fs.readfile(dbFile);
|
@@ -991,10 +1211,10 @@ var MemoryGateway = class {
|
|
991
1211
|
this.sthis = sthis;
|
992
1212
|
}
|
993
1213
|
buildUrl(baseUrl, key) {
|
994
|
-
return Promise.resolve(Result4.Ok(baseUrl.build().setParam(
|
1214
|
+
return Promise.resolve(Result4.Ok(baseUrl.build().setParam(PARAM.KEY, key).URI()));
|
995
1215
|
}
|
996
1216
|
start(baseUrl) {
|
997
|
-
return Promise.resolve(Result4.Ok(baseUrl.build().setParam(
|
1217
|
+
return Promise.resolve(Result4.Ok(baseUrl.build().setParam(PARAM.VERSION, MEMORY_VERSION).URI()));
|
998
1218
|
}
|
999
1219
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
1000
1220
|
close(baseUrl) {
|
@@ -1022,7 +1242,7 @@ var MemoryGateway = class {
|
|
1022
1242
|
return Promise.resolve(Result4.Ok(void 0));
|
1023
1243
|
}
|
1024
1244
|
async getPlain(url, key) {
|
1025
|
-
const x = this.memorys.get(url.build().setParam(
|
1245
|
+
const x = this.memorys.get(url.build().setParam(PARAM.KEY, key).toString());
|
1026
1246
|
if (!x) {
|
1027
1247
|
return Result4.Err(new NotFoundError("not found"));
|
1028
1248
|
}
|
@@ -1035,18 +1255,17 @@ import { Result as Result7 } from "@adviser/cement";
|
|
1035
1255
|
|
1036
1256
|
// src/blockstore/fp-envelope.ts
|
1037
1257
|
import { Result as Result5 } from "@adviser/cement";
|
1038
|
-
var
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1044
|
-
})(FPEnvelopeType || {});
|
1258
|
+
var FPEnvelopeTypes = {
|
1259
|
+
CAR: "car",
|
1260
|
+
FILE: "file",
|
1261
|
+
META: "meta",
|
1262
|
+
WAL: "wal"
|
1263
|
+
};
|
1045
1264
|
function Car2FPMsg(fpcar) {
|
1046
|
-
return Result5.Ok({ type:
|
1265
|
+
return Result5.Ok({ type: FPEnvelopeTypes.CAR, payload: fpcar });
|
1047
1266
|
}
|
1048
1267
|
function File2FPMsg(fpfile) {
|
1049
|
-
return Result5.Ok({ type:
|
1268
|
+
return Result5.Ok({ type: FPEnvelopeTypes.FILE, payload: fpfile });
|
1050
1269
|
}
|
1051
1270
|
|
1052
1271
|
// src/runtime/gateways/fp-envelope-serialize.ts
|
@@ -1100,13 +1319,13 @@ async function fpSerialize(sthis, env, pencoder) {
|
|
1100
1319
|
...pencoder
|
1101
1320
|
};
|
1102
1321
|
switch (env.type) {
|
1103
|
-
case
|
1322
|
+
case FPEnvelopeTypes.FILE:
|
1104
1323
|
return encoder.file(sthis, env.payload);
|
1105
|
-
case
|
1324
|
+
case FPEnvelopeTypes.CAR:
|
1106
1325
|
return encoder.car(sthis, env.payload);
|
1107
|
-
case
|
1326
|
+
case FPEnvelopeTypes.WAL:
|
1108
1327
|
return encoder.wal(sthis, WALState2Serialized(sthis, env.payload));
|
1109
|
-
case
|
1328
|
+
case FPEnvelopeTypes.META:
|
1110
1329
|
return encoder.meta(sthis, await dbMetaEvent2Serialized(sthis, env.payload));
|
1111
1330
|
default:
|
1112
1331
|
throw sthis.logger.Error().Str("type", env.type).Msg("unsupported store").AsError();
|
@@ -1186,18 +1405,18 @@ async function fpDeserialize(sthis, url, intoRaw, pdecoder) {
|
|
1186
1405
|
...defaultDecoder,
|
1187
1406
|
...pdecoder
|
1188
1407
|
};
|
1189
|
-
switch (url.getParam(
|
1408
|
+
switch (url.getParam(PARAM.STORE)) {
|
1190
1409
|
case "data":
|
1191
|
-
if (url.getParam(
|
1192
|
-
return makeFPEnvelope(
|
1410
|
+
if (url.getParam(PARAM.SUFFIX) === ".car") {
|
1411
|
+
return makeFPEnvelope(FPEnvelopeTypes.CAR, await decoder.car(sthis, raw2));
|
1193
1412
|
}
|
1194
|
-
return makeFPEnvelope(
|
1413
|
+
return makeFPEnvelope(FPEnvelopeTypes.FILE, await decoder.file(sthis, raw2));
|
1195
1414
|
case "wal":
|
1196
|
-
return makeFPEnvelope(
|
1415
|
+
return makeFPEnvelope(FPEnvelopeTypes.WAL, await decode2WalState(sthis, await decoder.wal(sthis, raw2)));
|
1197
1416
|
case "meta":
|
1198
|
-
return makeFPEnvelope(
|
1417
|
+
return makeFPEnvelope(FPEnvelopeTypes.META, await decode2DbMetaEvents(sthis, await decoder.meta(sthis, raw2)));
|
1199
1418
|
default:
|
1200
|
-
return sthis.logger.Error().Str("store", url.getParam(
|
1419
|
+
return sthis.logger.Error().Str("store", url.getParam(PARAM.STORE)).Msg("unsupported store").ResultError();
|
1201
1420
|
}
|
1202
1421
|
}
|
1203
1422
|
|
@@ -1220,9 +1439,11 @@ var DefSerdeGateway = class {
|
|
1220
1439
|
const rUint8 = await fpSerialize(sthis, env, encoder);
|
1221
1440
|
if (rUint8.isErr()) return rUint8;
|
1222
1441
|
const ret = this.gw.put(url, rUint8.Ok(), sthis);
|
1223
|
-
if (env.type ===
|
1224
|
-
|
1225
|
-
|
1442
|
+
if (env.type === FPEnvelopeTypes.META) {
|
1443
|
+
const urlWithoutKey = url.build().delParam(PARAM.KEY).delParam(PARAM.SELF_REFLECT).toString();
|
1444
|
+
const subFn = this.subscribeFn.get(urlWithoutKey);
|
1445
|
+
if (subFn) {
|
1446
|
+
await subFn(rUint8.Ok());
|
1226
1447
|
}
|
1227
1448
|
}
|
1228
1449
|
return ret;
|
@@ -1243,7 +1464,12 @@ var DefSerdeGateway = class {
|
|
1243
1464
|
});
|
1244
1465
|
}
|
1245
1466
|
if (!this.gw.subscribe) {
|
1246
|
-
|
1467
|
+
if (!url.hasParam(PARAM.SELF_REFLECT)) {
|
1468
|
+
return Result7.Ok(() => {
|
1469
|
+
});
|
1470
|
+
}
|
1471
|
+
const urlWithoutKey = url.build().delParam(PARAM.KEY).delParam(PARAM.SELF_REFLECT).toString();
|
1472
|
+
this.subscribeFn.set(urlWithoutKey, rawCallback);
|
1247
1473
|
return Result7.Ok(() => {
|
1248
1474
|
this.subscribeFn.delete(url.toString());
|
1249
1475
|
});
|
@@ -1322,7 +1548,7 @@ function defaultGatewayFactoryItem() {
|
|
1322
1548
|
}
|
1323
1549
|
function defaultURI(sthis) {
|
1324
1550
|
const rt = runtimeFn3();
|
1325
|
-
return BuildURI.from("file://").pathname(`${sthis.env.get("HOME")}/.fireproof/${FILESTORE_VERSION.replace(/-.*$/, "")}`).setParam(
|
1551
|
+
return 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();
|
1326
1552
|
}
|
1327
1553
|
if (runtimeFn3().isNodeIsh || runtimeFn3().isDeno) {
|
1328
1554
|
registerStoreProtocol({
|
@@ -1339,7 +1565,7 @@ if (runtimeFn3().isBrowser) {
|
|
1339
1565
|
protocol: "indexeddb:",
|
1340
1566
|
isDefault: true,
|
1341
1567
|
defaultURI: () => {
|
1342
|
-
return BuildURI.from("indexeddb://").pathname("fp").setParam(
|
1568
|
+
return BuildURI.from("indexeddb://").pathname("fp").setParam(PARAM.VERSION, INDEXEDDB_VERSION).setParam(PARAM.RUNTIME, "browser").URI();
|
1343
1569
|
},
|
1344
1570
|
gateway: async () => {
|
1345
1571
|
const { GatewayImpl } = await import("@fireproof/core/indexeddb");
|
@@ -1905,7 +2131,7 @@ __export(blockstore_exports, {
|
|
1905
2131
|
DbMetaEventEqual: () => DbMetaEventEqual,
|
1906
2132
|
DbMetaEventsEqual: () => DbMetaEventsEqual,
|
1907
2133
|
EncryptedBlockstore: () => EncryptedBlockstore,
|
1908
|
-
|
2134
|
+
FPEnvelopeTypes: () => FPEnvelopeTypes,
|
1909
2135
|
File2FPMsg: () => File2FPMsg,
|
1910
2136
|
InterceptorGateway: () => InterceptorGateway,
|
1911
2137
|
Loader: () => Loader,
|
@@ -2794,12 +3020,12 @@ var generateIV = {
|
|
2794
3020
|
return hashArray;
|
2795
3021
|
},
|
2796
3022
|
verify: async function(ko, crypto, iv, data) {
|
2797
|
-
return ko.url.getParam(
|
3023
|
+
return ko.url.getParam(PARAM.IV_VERIFY) !== "disable" && UInt8ArrayEqual(iv, await this.calc(ko, crypto, data));
|
2798
3024
|
}
|
2799
3025
|
}
|
2800
3026
|
};
|
2801
3027
|
function getGenerateIVFn(url, opts) {
|
2802
|
-
const ivhash = opts.ivCalc || url.getParam(
|
3028
|
+
const ivhash = opts.ivCalc || url.getParam(PARAM.IV_HASH) || "hash";
|
2803
3029
|
return generateIV[ivhash] || generateIV["hash"];
|
2804
3030
|
}
|
2805
3031
|
var BlockIvKeyIdCodec = class {
|
@@ -2813,13 +3039,16 @@ var BlockIvKeyIdCodec = class {
|
|
2813
3039
|
async encode(data) {
|
2814
3040
|
const calcIv = this.iv || await getGenerateIVFn(this.ko.url, this.opts).calc(this.ko, this.ko.crypto, data);
|
2815
3041
|
const { iv } = this.ko.algo(calcIv);
|
2816
|
-
const
|
2817
|
-
|
2818
|
-
|
3042
|
+
const defKey = await this.ko.key.get();
|
3043
|
+
if (!defKey) {
|
3044
|
+
throw this.ko.logger.Error().Msg("default key not found").AsError();
|
3045
|
+
}
|
3046
|
+
const keyId = base58btc3.decode(defKey?.fingerPrint);
|
3047
|
+
this.ko.logger.Debug().Str("fp", defKey.fingerPrint).Msg("encode");
|
2819
3048
|
return CBOR.encode({
|
2820
3049
|
iv,
|
2821
3050
|
keyId,
|
2822
|
-
data: await this.ko._encrypt({ iv, bytes: data })
|
3051
|
+
data: await this.ko._encrypt({ iv, key: defKey.key, bytes: data })
|
2823
3052
|
});
|
2824
3053
|
}
|
2825
3054
|
async decode(abytes) {
|
@@ -2830,30 +3059,32 @@ var BlockIvKeyIdCodec = class {
|
|
2830
3059
|
bytes = new Uint8Array(abytes);
|
2831
3060
|
}
|
2832
3061
|
const { iv, keyId, data } = CBOR.decode(bytes);
|
2833
|
-
const
|
2834
|
-
|
2835
|
-
|
2836
|
-
throw this.ko.logger.Error().Str("fp", fprt).Str("keyId", base58btc3.encode(keyId)).Msg("keyId mismatch").AsError();
|
3062
|
+
const key = await this.ko.key.get(keyId);
|
3063
|
+
if (!key) {
|
3064
|
+
throw this.ko.logger.Error().Str("fp", base58btc3.encode(keyId)).Msg("keyId not found").AsError();
|
2837
3065
|
}
|
2838
|
-
const result = await this.ko._decrypt({ iv, bytes: data });
|
3066
|
+
const result = await this.ko._decrypt({ iv, key: key.key, bytes: data });
|
2839
3067
|
if (!this.opts?.noIVVerify && !await getGenerateIVFn(this.ko.url, this.opts).verify(this.ko, this.ko.crypto, iv, result)) {
|
2840
3068
|
throw this.ko.logger.Error().Msg("iv missmatch").AsError();
|
2841
3069
|
}
|
2842
3070
|
return result;
|
2843
3071
|
}
|
2844
3072
|
};
|
2845
|
-
var
|
3073
|
+
var cryptoAction = class {
|
2846
3074
|
constructor(url, key, cyopt, sthis) {
|
2847
3075
|
this.ivLength = 12;
|
2848
3076
|
this.isEncrypting = true;
|
2849
|
-
this.logger = ensureLogger(sthis, "
|
3077
|
+
this.logger = ensureLogger(sthis, "cryptoAction");
|
2850
3078
|
this.crypto = cyopt;
|
2851
3079
|
this.key = key;
|
2852
3080
|
this.url = url;
|
2853
3081
|
}
|
2854
|
-
|
2855
|
-
|
2856
|
-
}
|
3082
|
+
// keyByFingerPrint(id: Uint8Array | string): Promise<Result<KeyWithFingerPrint>> {
|
3083
|
+
// return this.key.get(id)
|
3084
|
+
// }
|
3085
|
+
// fingerPrint(): Promise<string> {
|
3086
|
+
// return this.key.get().then((k) => k.fingerPrint);
|
3087
|
+
// }
|
2857
3088
|
codec(iv, opts) {
|
2858
3089
|
return new BlockIvKeyIdCodec(this, iv, opts);
|
2859
3090
|
}
|
@@ -2865,13 +3096,11 @@ var keyedCrypto = class {
|
|
2865
3096
|
};
|
2866
3097
|
}
|
2867
3098
|
async _decrypt(data) {
|
2868
|
-
this.
|
2869
|
-
return new Uint8Array(await this.crypto.decrypt(this.algo(data.iv), this.key.key, data.bytes));
|
3099
|
+
return new Uint8Array(await this.crypto.decrypt(this.algo(data.iv), data.key, data.bytes));
|
2870
3100
|
}
|
2871
3101
|
async _encrypt(data) {
|
2872
|
-
this.logger.Debug().Len(data.bytes).Str("fp", this.key.fingerPrint).Msg("encrypting");
|
2873
3102
|
const a = this.algo(data.iv);
|
2874
|
-
return new Uint8Array(await this.crypto.encrypt(a,
|
3103
|
+
return new Uint8Array(await this.crypto.encrypt(a, data.key, data.bytes));
|
2875
3104
|
}
|
2876
3105
|
};
|
2877
3106
|
var nullCodec = class {
|
@@ -2895,6 +3124,18 @@ var noCrypto = class {
|
|
2895
3124
|
this._fingerPrint = "noCrypto:" + Math.random();
|
2896
3125
|
this.logger = ensureLogger(sthis, "noCrypto");
|
2897
3126
|
this.crypto = cyrt;
|
3127
|
+
this.key = {
|
3128
|
+
name: "noCrypto",
|
3129
|
+
get: () => {
|
3130
|
+
throw this.logger.Error().Msg("noCrypto.get not implemented").AsError();
|
3131
|
+
},
|
3132
|
+
upsert: () => {
|
3133
|
+
throw this.logger.Error().Msg("noCrypto.upsert not implemented").AsError();
|
3134
|
+
},
|
3135
|
+
asKeysItem: () => {
|
3136
|
+
throw this.logger.Error().Msg("noCrypto.asKeysItem not implemented").AsError();
|
3137
|
+
}
|
3138
|
+
};
|
2898
3139
|
this.url = url;
|
2899
3140
|
}
|
2900
3141
|
fingerPrint() {
|
@@ -2920,17 +3161,13 @@ var noCrypto = class {
|
|
2920
3161
|
}
|
2921
3162
|
};
|
2922
3163
|
async function keyedCryptoFactory(url, kb, sthis) {
|
2923
|
-
const storekey = url.getParam(
|
3164
|
+
const storekey = url.getParam(PARAM.STORE_KEY);
|
2924
3165
|
if (storekey && storekey !== "insecure") {
|
2925
|
-
|
3166
|
+
const rkey = await kb.getNamedKey(storekey, false);
|
2926
3167
|
if (rkey.isErr()) {
|
2927
|
-
|
2928
|
-
rkey = await kb.toKeyWithFingerPrint(storekey);
|
2929
|
-
} catch (e) {
|
2930
|
-
throw sthis.logger.Error().Err(e).Str("keybag", kb.rt.id()).Str("name", storekey).Msg("getNamedKey failed").AsError();
|
2931
|
-
}
|
3168
|
+
throw sthis.logger.Error().Str("keybag", kb.rt.id()).Str("name", storekey).Msg("getNamedKey failed").AsError();
|
2932
3169
|
}
|
2933
|
-
return new
|
3170
|
+
return new cryptoAction(url, rkey.Ok(), kb.rt.crypto, sthis);
|
2934
3171
|
}
|
2935
3172
|
return new noCrypto(url, kb.rt.crypto, sthis);
|
2936
3173
|
}
|
@@ -3095,7 +3332,7 @@ var BaseStoreImpl = class {
|
|
3095
3332
|
this.opts = opts;
|
3096
3333
|
this.loader = opts.loader;
|
3097
3334
|
this.sthis = sthis;
|
3098
|
-
const name = this._url.getParam(
|
3335
|
+
const name = this._url.getParam(PARAM.NAME);
|
3099
3336
|
if (!name) {
|
3100
3337
|
throw logger.Error().Url(this._url).Msg("missing name").AsError();
|
3101
3338
|
}
|
@@ -3120,7 +3357,7 @@ var BaseStoreImpl = class {
|
|
3120
3357
|
}
|
3121
3358
|
async start() {
|
3122
3359
|
this.logger.Debug().Str("storeType", this.storeType).Msg("starting-gateway-pre");
|
3123
|
-
this._url = this._url.build().setParam(
|
3360
|
+
this._url = this._url.build().setParam(PARAM.STORE, this.storeType).URI();
|
3124
3361
|
const res = await this.gateway.start({ loader: this.loader }, this._url);
|
3125
3362
|
if (res.isErr()) {
|
3126
3363
|
this.logger.Error().Result("gw-start", res).Msg("started-gateway");
|
@@ -3129,8 +3366,8 @@ var BaseStoreImpl = class {
|
|
3129
3366
|
this._url = res.Ok();
|
3130
3367
|
const kb = await this.loader.keyBag();
|
3131
3368
|
const skRes = await kb.ensureKeyFromUrl(this._url, () => {
|
3132
|
-
const idx = this._url.getParam(
|
3133
|
-
const storeKeyName = [this.url().getParam(
|
3369
|
+
const idx = this._url.getParam(PARAM.INDEX);
|
3370
|
+
const storeKeyName = [this.url().getParam(PARAM.NAME)];
|
3134
3371
|
if (idx) {
|
3135
3372
|
storeKeyName.push(idx);
|
3136
3373
|
}
|
@@ -3289,16 +3526,16 @@ var DataStoreImpl = class extends BaseStoreImpl {
|
|
3289
3526
|
throw this.logger.Error().Err(url.Err()).Ref("cid", car.cid).Msg("got error from gateway.buildUrl").AsError();
|
3290
3527
|
}
|
3291
3528
|
let fpMsg;
|
3292
|
-
switch (url.Ok().getParam(
|
3529
|
+
switch (url.Ok().getParam(PARAM.STORE)) {
|
3293
3530
|
case "data":
|
3294
|
-
if (url.Ok().getParam(
|
3531
|
+
if (url.Ok().getParam(PARAM.SUFFIX)) {
|
3295
3532
|
fpMsg = Car2FPMsg(car.bytes);
|
3296
3533
|
} else {
|
3297
3534
|
fpMsg = File2FPMsg(car.bytes);
|
3298
3535
|
}
|
3299
3536
|
break;
|
3300
3537
|
default:
|
3301
|
-
throw this.logger.Error().Str("store", url.Ok().getParam(
|
3538
|
+
throw this.logger.Error().Str("store", url.Ok().getParam(PARAM.STORE)).Msg("unexpected store").AsError();
|
3302
3539
|
}
|
3303
3540
|
if (fpMsg.isErr()) {
|
3304
3541
|
throw this.logger.Error().Err(fpMsg).Msg("got error from FPMsg2Car").AsError();
|
@@ -3542,7 +3779,7 @@ async function getStartedGateway(ctx, url) {
|
|
3542
3779
|
});
|
3543
3780
|
}
|
3544
3781
|
async function dataStoreFactory(sfi) {
|
3545
|
-
const storeUrl = sfi.url.build().setParam(
|
3782
|
+
const storeUrl = sfi.url.build().setParam(PARAM.STORE, "data").URI();
|
3546
3783
|
const rgateway = await getStartedGateway(sfi, storeUrl);
|
3547
3784
|
if (rgateway.isErr()) {
|
3548
3785
|
throw sfi.loader.sthis.logger.Error().Result("err", rgateway).Url(sfi.url).Msg("notfound").AsError();
|
@@ -3556,7 +3793,7 @@ async function dataStoreFactory(sfi) {
|
|
3556
3793
|
return store;
|
3557
3794
|
}
|
3558
3795
|
async function metaStoreFactory(sfi) {
|
3559
|
-
const storeUrl = sfi.url.build().setParam(
|
3796
|
+
const storeUrl = sfi.url.build().setParam(PARAM.STORE, "meta").URI();
|
3560
3797
|
const rgateway = await getStartedGateway(sfi, storeUrl);
|
3561
3798
|
if (rgateway.isErr()) {
|
3562
3799
|
throw sfi.loader.sthis.logger.Error().Result("err", rgateway).Url(sfi.url).Msg("notfound").AsError();
|
@@ -3570,7 +3807,7 @@ async function metaStoreFactory(sfi) {
|
|
3570
3807
|
return store;
|
3571
3808
|
}
|
3572
3809
|
async function WALStoreFactory(sfi) {
|
3573
|
-
const storeUrl = sfi.url.build().setParam(
|
3810
|
+
const storeUrl = sfi.url.build().setParam(PARAM.STORE, "wal").URI();
|
3574
3811
|
const rgateway = await getStartedGateway(sfi, storeUrl);
|
3575
3812
|
if (rgateway.isErr()) {
|
3576
3813
|
throw sfi.loader.sthis.logger.Error().Result("err", rgateway).Url(sfi.url).Msg("notfound").AsError();
|
@@ -3702,11 +3939,11 @@ var ConnectionBase = class {
|
|
3702
3939
|
if (!loader) throw this.logger.Error().Msg("connectMeta: loader is required").AsError();
|
3703
3940
|
this.loader = loader;
|
3704
3941
|
await this.onConnect();
|
3705
|
-
const metaUrl = this.url.build().defParam(
|
3942
|
+
const metaUrl = this.url.build().defParam(PARAM.STORE, "meta").URI();
|
3706
3943
|
const rgateway = await getStartedGateway({ loader }, metaUrl);
|
3707
3944
|
if (rgateway.isErr())
|
3708
3945
|
throw this.logger.Error().Result("err", rgateway).Url(metaUrl).Msg("connectMeta: gateway is required").AsError();
|
3709
|
-
const dbName = metaUrl.getParam(
|
3946
|
+
const dbName = metaUrl.getParam(PARAM.NAME);
|
3710
3947
|
if (!dbName) {
|
3711
3948
|
throw this.logger.Error().Url(metaUrl).Msg("connectMeta: dbName is required").AsError();
|
3712
3949
|
}
|
@@ -3738,11 +3975,11 @@ var ConnectionBase = class {
|
|
3738
3975
|
const loader = coerceLoader(refl);
|
3739
3976
|
if (!loader) throw this.logger.Error().Msg("connectStorage: loader is required").AsError();
|
3740
3977
|
this.loader = loader;
|
3741
|
-
const dataUrl = this.url.build().defParam(
|
3978
|
+
const dataUrl = this.url.build().defParam(PARAM.STORE, "data").URI();
|
3742
3979
|
const rgateway = await getStartedGateway({ loader }, dataUrl);
|
3743
3980
|
if (rgateway.isErr())
|
3744
3981
|
throw this.logger.Error().Result("err", rgateway).Url(dataUrl).Msg("connectStorage: gateway is required").AsError();
|
3745
|
-
const name = dataUrl.getParam(
|
3982
|
+
const name = dataUrl.getParam(PARAM.NAME);
|
3746
3983
|
if (!name) throw this.logger.Error().Url(dataUrl).Msg("connectStorage: name is required").AsError;
|
3747
3984
|
loader.remoteCarStore = await RemoteDataStore(loader.sthis, this.url, {
|
3748
3985
|
gateway: rgateway.Ok().gateway,
|
@@ -4463,7 +4700,7 @@ var LedgerImpl = class {
|
|
4463
4700
|
this.crdt.clock.onTock(() => this._no_update_notify());
|
4464
4701
|
}
|
4465
4702
|
get name() {
|
4466
|
-
return this.opts.storeUrls.data.data.getParam(
|
4703
|
+
return this.opts.storeUrls.data.data.getParam(PARAM.NAME) ?? "default";
|
4467
4704
|
}
|
4468
4705
|
addShell(shell) {
|
4469
4706
|
this.shells.add(shell);
|
@@ -4549,24 +4786,24 @@ var LedgerImpl = class {
|
|
4549
4786
|
};
|
4550
4787
|
function defaultURI2(sthis, curi, uri, store, ctx) {
|
4551
4788
|
ctx = ctx || {};
|
4552
|
-
const ret = (curi ? URI13.from(curi) : uri).build().setParam(
|
4553
|
-
if (!ret.hasParam(
|
4789
|
+
const ret = (curi ? URI13.from(curi) : uri).build().setParam(PARAM.STORE, store);
|
4790
|
+
if (!ret.hasParam(PARAM.NAME)) {
|
4554
4791
|
const name = sthis.pathOps.basename(ret.URI().pathname);
|
4555
4792
|
if (!name) {
|
4556
4793
|
throw sthis.logger.Error().Url(ret).Any("ctx", ctx).Msg("Ledger name is required").AsError();
|
4557
4794
|
}
|
4558
|
-
ret.setParam(
|
4795
|
+
ret.setParam(PARAM.NAME, name);
|
4559
4796
|
}
|
4560
4797
|
if (ctx.idx) {
|
4561
|
-
ret.defParam(
|
4562
|
-
ret.defParam(
|
4798
|
+
ret.defParam(PARAM.INDEX, "idx");
|
4799
|
+
ret.defParam(PARAM.STORE_KEY, `@${ret.getParam(PARAM.NAME)}-${store}-idx@`);
|
4563
4800
|
} else {
|
4564
|
-
ret.defParam(
|
4801
|
+
ret.defParam(PARAM.STORE_KEY, `@${ret.getParam(PARAM.NAME)}-${store}@`);
|
4565
4802
|
}
|
4566
4803
|
if (store === "data") {
|
4567
4804
|
if (ctx.file) {
|
4568
4805
|
} else {
|
4569
|
-
ret.defParam(
|
4806
|
+
ret.defParam(PARAM.SUFFIX, ".car");
|
4570
4807
|
}
|
4571
4808
|
}
|
4572
4809
|
return ret.URI();
|
@@ -4576,14 +4813,14 @@ function toStoreURIRuntime(sthis, name, sopts) {
|
|
4576
4813
|
if (!sopts.base) {
|
4577
4814
|
const fp_env = sthis.env.get("FP_STORAGE_URL");
|
4578
4815
|
if (fp_env) {
|
4579
|
-
sopts = { ...sopts, base: BuildURI2.from(fp_env).setParam(
|
4816
|
+
sopts = { ...sopts, base: BuildURI2.from(fp_env).setParam(PARAM.URL_GEN, "fromEnv") };
|
4580
4817
|
} else {
|
4581
|
-
sopts = { ...sopts, base: getDefaultURI(sthis).build().setParam(
|
4818
|
+
sopts = { ...sopts, base: getDefaultURI(sthis).build().setParam(PARAM.URL_GEN, "default") };
|
4582
4819
|
}
|
4583
4820
|
}
|
4584
4821
|
const bbase = BuildURI2.from(sopts.base);
|
4585
4822
|
if (name) {
|
4586
|
-
bbase.setParam(
|
4823
|
+
bbase.setParam(PARAM.NAME, name);
|
4587
4824
|
}
|
4588
4825
|
const base = bbase.URI();
|
4589
4826
|
return {
|
@@ -4620,9 +4857,11 @@ __export(runtime_exports, {
|
|
4620
4857
|
gw: () => gateways_exports,
|
4621
4858
|
kb: () => key_bag_exports,
|
4622
4859
|
kc: () => keyed_crypto_exports,
|
4860
|
+
keysByFingerprint: () => keysByFingerprint,
|
4623
4861
|
mf: () => wait_pr_multiformats_exports,
|
4624
4862
|
registerKeyBagProviderFactory: () => registerKeyBagProviderFactory,
|
4625
|
-
runtimeFn: () => runtimeFn4
|
4863
|
+
runtimeFn: () => runtimeFn4,
|
4864
|
+
toKeyWithFingerPrint: () => toKeyWithFingerPrint
|
4626
4865
|
});
|
4627
4866
|
|
4628
4867
|
// src/runtime/wait-pr-multiformats/index.ts
|
@@ -4659,7 +4898,7 @@ __export(file_exports, {
|
|
4659
4898
|
|
4660
4899
|
// src/version.ts
|
4661
4900
|
var PACKAGE_VERSION = Object.keys({
|
4662
|
-
"0.20.0-dev-preview-
|
4901
|
+
"0.20.0-dev-preview-25": "xxxx"
|
4663
4902
|
})[0];
|
4664
4903
|
export {
|
4665
4904
|
CRDTImpl,
|