@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.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,200 @@ 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
|
+
this.id = keyBag.rt.sthis.nextId(4).str;
|
693
|
+
}
|
694
|
+
static async from(keyBag, named) {
|
695
|
+
const kbf = new _keysByFingerprint(keyBag, named.name);
|
696
|
+
for (const i of Object.entries(named.keys).reverse()) {
|
697
|
+
const result = await kbf.upsert(i[1].key, i[1].default, false);
|
698
|
+
if (result.isErr()) {
|
699
|
+
throw result;
|
700
|
+
}
|
701
|
+
if (result.Ok().modified) {
|
702
|
+
throw keyBag.logger.Error().Msg("KeyBag: keysByFingerprint: mismatch unexpected").AsError();
|
703
|
+
}
|
704
|
+
if (result.Ok().kfp.fingerPrint !== i[1].fingerPrint) {
|
705
|
+
throw keyBag.logger.Error().Any("fprs", {
|
706
|
+
fromStorage: i[1].fingerPrint,
|
707
|
+
calculated: result.Ok().kfp.fingerPrint
|
708
|
+
}).Msg("KeyBag: keysByFingerprint: mismatch").AsError();
|
709
|
+
}
|
710
|
+
}
|
711
|
+
return kbf;
|
712
|
+
}
|
713
|
+
async get(fingerPrint) {
|
714
|
+
if (fingerPrint instanceof Uint8Array) {
|
715
|
+
fingerPrint = base58btc2.encode(fingerPrint);
|
716
|
+
} else {
|
717
|
+
fingerPrint = fingerPrint || "*";
|
718
|
+
}
|
719
|
+
const found = this.keys[fingerPrint];
|
720
|
+
if (found) {
|
721
|
+
return found;
|
722
|
+
}
|
723
|
+
throw this.keybag.logger.Error().Msg("KeyBag: keysByFingerprint: no default").AsError();
|
724
|
+
}
|
725
|
+
async upsert(materialStrOrUint8, def, keyBagAction = true) {
|
726
|
+
def = !!def;
|
727
|
+
const rKfp = await toKeyWithFingerPrint(this.keybag, materialStrOrUint8);
|
728
|
+
if (rKfp.isErr()) {
|
729
|
+
return Result2.Err(rKfp);
|
730
|
+
}
|
731
|
+
const kfp = rKfp.Ok();
|
732
|
+
let found = this.keys[kfp.fingerPrint];
|
733
|
+
if (found) {
|
734
|
+
if (found.default === def) {
|
735
|
+
return Result2.Ok({
|
736
|
+
modified: false,
|
737
|
+
kfp: found
|
738
|
+
});
|
739
|
+
}
|
740
|
+
} else {
|
741
|
+
found = new keyWithFingerPrint(kfp, materialStrOrUint8, def);
|
742
|
+
}
|
743
|
+
if (def) {
|
744
|
+
for (const i of Object.values(this.keys)) {
|
745
|
+
i.default = false;
|
746
|
+
}
|
747
|
+
}
|
748
|
+
this.keys[kfp.fingerPrint] = found;
|
749
|
+
if (def) {
|
750
|
+
this.keys["*"] = found;
|
751
|
+
}
|
752
|
+
if (keyBagAction) {
|
753
|
+
this.keybag._upsertNamedKey(this);
|
754
|
+
}
|
755
|
+
return Result2.Ok({
|
756
|
+
modified: keyBagAction && true,
|
757
|
+
kfp: found
|
758
|
+
});
|
759
|
+
}
|
760
|
+
async asKeysItem() {
|
761
|
+
const my = { ...this.keys };
|
762
|
+
delete my["*"];
|
763
|
+
const kis = await Promise.all(Object.values(my).map((i) => i.asV2StorageKeyItem()));
|
764
|
+
return {
|
765
|
+
name: this.name,
|
766
|
+
keys: kis.reduce(
|
767
|
+
(acc, i) => {
|
768
|
+
acc[i.fingerPrint] = i;
|
769
|
+
return acc;
|
770
|
+
},
|
771
|
+
{}
|
772
|
+
)
|
773
|
+
};
|
774
|
+
}
|
775
|
+
// async extract() {
|
776
|
+
// const ext = new Uint8Array((await this.rt.crypto.exportKey("raw", named.key)) as ArrayBuffer);
|
777
|
+
// return {
|
778
|
+
// key: ext,
|
779
|
+
// keyStr: base58btc.encode(ext),
|
780
|
+
// };
|
781
|
+
// }
|
782
|
+
};
|
621
783
|
var KeyBag = class {
|
622
784
|
constructor(rt) {
|
623
|
-
this.rt = rt;
|
624
785
|
this._warnOnce = new ResolveOnce2();
|
625
786
|
this._seq = new ResolveSeq();
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
787
|
+
// async getNamedExtractableKey(name: string, failIfNotFound = false): Promise<Result<KeysByFingerprint>> {
|
788
|
+
// const ret = await this.getNamedKey(name, failIfNotFound);
|
789
|
+
// if (ret.isErr()) {
|
790
|
+
// return Result.Err(ret)
|
791
|
+
// }
|
792
|
+
// const named = ret.Ok();
|
793
|
+
// return Result.Ok({
|
794
|
+
// ...named,
|
795
|
+
// extract: async () => {
|
796
|
+
// const ext = new Uint8Array((await this.rt.crypto.exportKey("raw", named.key)) as ArrayBuffer);
|
797
|
+
// return {
|
798
|
+
// key: ext,
|
799
|
+
// keyStr: base58btc.encode(ext),
|
800
|
+
// };
|
801
|
+
// },
|
802
|
+
// });
|
803
|
+
// }
|
804
|
+
this._namedKeyCache = new KeyedResolvOnce();
|
805
|
+
this.rt = rt;
|
806
|
+
this.logger = ensureLogger(rt.sthis, "KeyBag");
|
630
807
|
}
|
631
|
-
async subtleKey(
|
632
|
-
const extractable = this.rt.url.getParam(
|
808
|
+
async subtleKey(materialStrOrUint8) {
|
809
|
+
const extractable = this.rt.url.getParam(PARAM.EXTRACTKEY) === "_deprecated_internal_api";
|
633
810
|
if (extractable) {
|
634
811
|
this._warnOnce.once(
|
635
812
|
() => this.logger.Warn().Msg("extractKey is enabled via _deprecated_internal_api --- handle keys safely!!!")
|
636
813
|
);
|
637
814
|
}
|
815
|
+
let material;
|
816
|
+
if (typeof materialStrOrUint8 === "string") {
|
817
|
+
material = base58btc2.decode(materialStrOrUint8);
|
818
|
+
} else {
|
819
|
+
material = materialStrOrUint8;
|
820
|
+
}
|
638
821
|
return await this.rt.crypto.importKey(
|
639
822
|
"raw",
|
640
823
|
// raw or jwk
|
641
|
-
|
824
|
+
material,
|
642
825
|
// hexStringToUint8Array(key), // raw data
|
643
826
|
"AES-GCM",
|
644
827
|
extractable,
|
@@ -646,7 +829,7 @@ var KeyBag = class {
|
|
646
829
|
);
|
647
830
|
}
|
648
831
|
async ensureKeyFromUrl(url, keyFactory) {
|
649
|
-
const storeKey = url.getParam(
|
832
|
+
const storeKey = url.getParam(PARAM.STORE_KEY);
|
650
833
|
if (storeKey === "insecure") {
|
651
834
|
return Result2.Ok(url);
|
652
835
|
}
|
@@ -656,7 +839,7 @@ var KeyBag = class {
|
|
656
839
|
if (ret.isErr()) {
|
657
840
|
return ret;
|
658
841
|
}
|
659
|
-
const urb = url.build().setParam(
|
842
|
+
const urb = url.build().setParam(PARAM.STORE_KEY, keyName);
|
660
843
|
return Result2.Ok(urb.URI());
|
661
844
|
}
|
662
845
|
if (storeKey.startsWith("@") && storeKey.endsWith("@")) {
|
@@ -667,63 +850,103 @@ var KeyBag = class {
|
|
667
850
|
}
|
668
851
|
return Result2.Ok(url);
|
669
852
|
}
|
670
|
-
async
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
853
|
+
async toKeysItem(ki) {
|
854
|
+
if (!ki) return void 0;
|
855
|
+
if ("key" in ki) {
|
856
|
+
const fpr = (await toKeyWithFingerPrint(this, ki.key)).Ok().fingerPrint;
|
857
|
+
return {
|
858
|
+
name: ki.name,
|
859
|
+
keys: {
|
860
|
+
[fpr]: {
|
861
|
+
key: ki.key,
|
862
|
+
fingerPrint: fpr,
|
863
|
+
default: true
|
864
|
+
}
|
865
|
+
}
|
866
|
+
};
|
867
|
+
}
|
868
|
+
let defKI;
|
869
|
+
let foundDefKI = false;
|
870
|
+
for (const i of Object.entries(ki.keys)) {
|
871
|
+
if (i[0] !== i[1].fingerPrint) {
|
872
|
+
delete ki.keys[i[0]];
|
873
|
+
ki.keys[i[1].fingerPrint] = i[1];
|
874
|
+
this.logger.Warn().Str("name", ki.name).Msg("fingerPrint mismatch fixed");
|
875
|
+
}
|
876
|
+
if (defKI === void 0) {
|
877
|
+
defKI = i[1];
|
878
|
+
}
|
879
|
+
if (!foundDefKI && i[1].default) {
|
880
|
+
defKI = i[1];
|
881
|
+
foundDefKI = true;
|
882
|
+
} else {
|
883
|
+
i[1].default = false;
|
884
|
+
}
|
885
|
+
}
|
886
|
+
if (defKI) {
|
887
|
+
ki.keys["*"] = defKI;
|
888
|
+
}
|
889
|
+
return {
|
890
|
+
name: ki.name,
|
891
|
+
keys: ki.keys
|
892
|
+
};
|
678
893
|
}
|
679
|
-
|
680
|
-
return this._seq.
|
894
|
+
flush() {
|
895
|
+
return this._seq.flush();
|
681
896
|
}
|
897
|
+
// async setNamedKey(name: string, key: string, def?: boolean): Promise<Result<KeysByFingerprint>> {
|
898
|
+
// return this._seq.add(() => this._upsertNamedKey(name, key, !!def));
|
899
|
+
// }
|
682
900
|
// avoid deadlock
|
683
|
-
async
|
684
|
-
const item = {
|
685
|
-
name,
|
686
|
-
key
|
687
|
-
};
|
901
|
+
async _upsertNamedKey(ksi) {
|
688
902
|
const bag = await this.rt.getBagProvider();
|
689
|
-
this.
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
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
|
-
};
|
903
|
+
return this._seq.add(async () => {
|
904
|
+
const rKbf = await this._getNamedKey(ksi.name, true);
|
905
|
+
if (rKbf.isErr()) {
|
906
|
+
this.logger.Error().Err(rKbf).Str("name", ksi.name).Msg("_upsertNamedKey: getNamedKey failed");
|
907
|
+
this._namedKeyCache.unget(ksi.name);
|
707
908
|
}
|
909
|
+
await bag.set(await ksi.asKeysItem());
|
910
|
+
return Result2.Ok(ksi);
|
708
911
|
});
|
709
912
|
}
|
710
|
-
async
|
711
|
-
|
712
|
-
|
913
|
+
async _getNamedKey(name, failIfNotFound, material) {
|
914
|
+
return await this._namedKeyCache.get(name).once(async () => {
|
915
|
+
const id = this.rt.sthis.nextId(4).str;
|
713
916
|
const bag = await this.rt.getBagProvider();
|
714
|
-
const named = await bag.get(name);
|
917
|
+
const named = await this.toKeysItem(await bag.get(name));
|
715
918
|
if (named) {
|
716
|
-
|
717
|
-
|
718
|
-
return fpr;
|
919
|
+
this.logger.Debug().Str("id", id).Str("name", name).Any("fprs", Object.keys(named.keys)).Msg("fingerPrint getNamedKey");
|
920
|
+
return Result2.Ok(await keysByFingerprint.from(this, named));
|
719
921
|
}
|
720
|
-
if (failIfNotFound) {
|
721
|
-
this.
|
722
|
-
return
|
922
|
+
if (!named && failIfNotFound) {
|
923
|
+
this._namedKeyCache.unget(name);
|
924
|
+
return this.logger.Debug().Str("id", id).Str("name", name).Msg("failIfNotFound getNamedKey").ResultError();
|
723
925
|
}
|
724
|
-
const
|
725
|
-
|
726
|
-
|
926
|
+
const kp = new keysByFingerprint(this, name);
|
927
|
+
let keyMaterial;
|
928
|
+
if (!material) {
|
929
|
+
keyMaterial = this.rt.crypto.randomBytes(this.rt.keyLength);
|
930
|
+
} else {
|
931
|
+
if (typeof material === "string") {
|
932
|
+
keyMaterial = base58btc2.decode(material);
|
933
|
+
} else if (material instanceof Uint8Array) {
|
934
|
+
keyMaterial = material;
|
935
|
+
} else {
|
936
|
+
return this.logger.Error().Msg("material must be string or Uint8Array").ResultError();
|
937
|
+
}
|
938
|
+
}
|
939
|
+
const res = await kp.upsert(keyMaterial, true);
|
940
|
+
if (res.isErr()) {
|
941
|
+
return Result2.Err(res);
|
942
|
+
}
|
943
|
+
this.logger.Debug().Str("id", id).Str("name", name).Str("fpr", res.Ok().kfp.fingerPrint).Msg("createKey getNamedKey-post");
|
944
|
+
return Result2.Ok(kp);
|
945
|
+
});
|
946
|
+
}
|
947
|
+
async getNamedKey(name, failIfNotFound = false, material) {
|
948
|
+
return this._seq.add(async () => {
|
949
|
+
return await this._getNamedKey(name, failIfNotFound, material);
|
727
950
|
});
|
728
951
|
}
|
729
952
|
};
|
@@ -892,24 +1115,24 @@ var FileGateway = class {
|
|
892
1115
|
return exception2Result(async () => {
|
893
1116
|
await this.fs.start();
|
894
1117
|
const url = baseURL.build();
|
895
|
-
url.defParam(
|
1118
|
+
url.defParam(PARAM.VERSION, FILESTORE_VERSION);
|
896
1119
|
const dbUrl = await this.buildUrl(url.URI(), "dummy");
|
897
1120
|
const dbdirFile = this.getFilePath(dbUrl.Ok(), sthis);
|
898
1121
|
await this.fs.mkdir(sthis.pathOps.dirname(dbdirFile), { recursive: true });
|
899
1122
|
const dbroot = sthis.pathOps.dirname(dbdirFile);
|
900
1123
|
sthis.logger.Debug().Url(url.URI()).Str("dbroot", dbroot).Msg("start");
|
901
|
-
url.setParam(
|
1124
|
+
url.setParam(PARAM.VERSION, await this.getVersionFromFile(dbroot, sthis));
|
902
1125
|
return url.URI();
|
903
1126
|
});
|
904
1127
|
}
|
905
1128
|
async buildUrl(baseUrl, key) {
|
906
|
-
return Result3.Ok(baseUrl.build().setParam(
|
1129
|
+
return Result3.Ok(baseUrl.build().setParam(PARAM.KEY, key).URI());
|
907
1130
|
}
|
908
1131
|
async close() {
|
909
1132
|
return Result3.Ok(void 0);
|
910
1133
|
}
|
911
1134
|
getFilePath(url, sthis) {
|
912
|
-
const key = url.getParam(
|
1135
|
+
const key = url.getParam(PARAM.KEY);
|
913
1136
|
if (!key) throw sthis.logger.Error().Url(url).Msg(`key not found`).AsError();
|
914
1137
|
return sthis.pathOps.join(getPath(url, sthis), getFileName(url, sthis));
|
915
1138
|
}
|
@@ -965,7 +1188,7 @@ var FileGateway = class {
|
|
965
1188
|
return Result3.Ok(void 0);
|
966
1189
|
}
|
967
1190
|
async getPlain(iurl, key, sthis) {
|
968
|
-
const url = iurl.build().setParam(
|
1191
|
+
const url = iurl.build().setParam(PARAM.KEY, key).URI();
|
969
1192
|
const dbFile = sthis.pathOps.join(getPath(url, sthis), getFileName(url, sthis));
|
970
1193
|
sthis.logger.Debug().Url(url).Str("dbFile", dbFile).Msg("get");
|
971
1194
|
const buffer = await this.fs.readfile(dbFile);
|
@@ -991,10 +1214,10 @@ var MemoryGateway = class {
|
|
991
1214
|
this.sthis = sthis;
|
992
1215
|
}
|
993
1216
|
buildUrl(baseUrl, key) {
|
994
|
-
return Promise.resolve(Result4.Ok(baseUrl.build().setParam(
|
1217
|
+
return Promise.resolve(Result4.Ok(baseUrl.build().setParam(PARAM.KEY, key).URI()));
|
995
1218
|
}
|
996
1219
|
start(baseUrl) {
|
997
|
-
return Promise.resolve(Result4.Ok(baseUrl.build().setParam(
|
1220
|
+
return Promise.resolve(Result4.Ok(baseUrl.build().setParam(PARAM.VERSION, MEMORY_VERSION).URI()));
|
998
1221
|
}
|
999
1222
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
1000
1223
|
close(baseUrl) {
|
@@ -1022,7 +1245,7 @@ var MemoryGateway = class {
|
|
1022
1245
|
return Promise.resolve(Result4.Ok(void 0));
|
1023
1246
|
}
|
1024
1247
|
async getPlain(url, key) {
|
1025
|
-
const x = this.memorys.get(url.build().setParam(
|
1248
|
+
const x = this.memorys.get(url.build().setParam(PARAM.KEY, key).toString());
|
1026
1249
|
if (!x) {
|
1027
1250
|
return Result4.Err(new NotFoundError("not found"));
|
1028
1251
|
}
|
@@ -1035,18 +1258,17 @@ import { Result as Result7 } from "@adviser/cement";
|
|
1035
1258
|
|
1036
1259
|
// src/blockstore/fp-envelope.ts
|
1037
1260
|
import { Result as Result5 } from "@adviser/cement";
|
1038
|
-
var
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1044
|
-
})(FPEnvelopeType || {});
|
1261
|
+
var FPEnvelopeTypes = {
|
1262
|
+
CAR: "car",
|
1263
|
+
FILE: "file",
|
1264
|
+
META: "meta",
|
1265
|
+
WAL: "wal"
|
1266
|
+
};
|
1045
1267
|
function Car2FPMsg(fpcar) {
|
1046
|
-
return Result5.Ok({ type:
|
1268
|
+
return Result5.Ok({ type: FPEnvelopeTypes.CAR, payload: fpcar });
|
1047
1269
|
}
|
1048
1270
|
function File2FPMsg(fpfile) {
|
1049
|
-
return Result5.Ok({ type:
|
1271
|
+
return Result5.Ok({ type: FPEnvelopeTypes.FILE, payload: fpfile });
|
1050
1272
|
}
|
1051
1273
|
|
1052
1274
|
// src/runtime/gateways/fp-envelope-serialize.ts
|
@@ -1100,13 +1322,13 @@ async function fpSerialize(sthis, env, pencoder) {
|
|
1100
1322
|
...pencoder
|
1101
1323
|
};
|
1102
1324
|
switch (env.type) {
|
1103
|
-
case
|
1325
|
+
case FPEnvelopeTypes.FILE:
|
1104
1326
|
return encoder.file(sthis, env.payload);
|
1105
|
-
case
|
1327
|
+
case FPEnvelopeTypes.CAR:
|
1106
1328
|
return encoder.car(sthis, env.payload);
|
1107
|
-
case
|
1329
|
+
case FPEnvelopeTypes.WAL:
|
1108
1330
|
return encoder.wal(sthis, WALState2Serialized(sthis, env.payload));
|
1109
|
-
case
|
1331
|
+
case FPEnvelopeTypes.META:
|
1110
1332
|
return encoder.meta(sthis, await dbMetaEvent2Serialized(sthis, env.payload));
|
1111
1333
|
default:
|
1112
1334
|
throw sthis.logger.Error().Str("type", env.type).Msg("unsupported store").AsError();
|
@@ -1186,18 +1408,18 @@ async function fpDeserialize(sthis, url, intoRaw, pdecoder) {
|
|
1186
1408
|
...defaultDecoder,
|
1187
1409
|
...pdecoder
|
1188
1410
|
};
|
1189
|
-
switch (url.getParam(
|
1411
|
+
switch (url.getParam(PARAM.STORE)) {
|
1190
1412
|
case "data":
|
1191
|
-
if (url.getParam(
|
1192
|
-
return makeFPEnvelope(
|
1413
|
+
if (url.getParam(PARAM.SUFFIX) === ".car") {
|
1414
|
+
return makeFPEnvelope(FPEnvelopeTypes.CAR, await decoder.car(sthis, raw2));
|
1193
1415
|
}
|
1194
|
-
return makeFPEnvelope(
|
1416
|
+
return makeFPEnvelope(FPEnvelopeTypes.FILE, await decoder.file(sthis, raw2));
|
1195
1417
|
case "wal":
|
1196
|
-
return makeFPEnvelope(
|
1418
|
+
return makeFPEnvelope(FPEnvelopeTypes.WAL, await decode2WalState(sthis, await decoder.wal(sthis, raw2)));
|
1197
1419
|
case "meta":
|
1198
|
-
return makeFPEnvelope(
|
1420
|
+
return makeFPEnvelope(FPEnvelopeTypes.META, await decode2DbMetaEvents(sthis, await decoder.meta(sthis, raw2)));
|
1199
1421
|
default:
|
1200
|
-
return sthis.logger.Error().Str("store", url.getParam(
|
1422
|
+
return sthis.logger.Error().Str("store", url.getParam(PARAM.STORE)).Msg("unsupported store").ResultError();
|
1201
1423
|
}
|
1202
1424
|
}
|
1203
1425
|
|
@@ -1220,9 +1442,11 @@ var DefSerdeGateway = class {
|
|
1220
1442
|
const rUint8 = await fpSerialize(sthis, env, encoder);
|
1221
1443
|
if (rUint8.isErr()) return rUint8;
|
1222
1444
|
const ret = this.gw.put(url, rUint8.Ok(), sthis);
|
1223
|
-
if (env.type ===
|
1224
|
-
|
1225
|
-
|
1445
|
+
if (env.type === FPEnvelopeTypes.META) {
|
1446
|
+
const urlWithoutKey = url.build().delParam(PARAM.KEY).delParam(PARAM.SELF_REFLECT).toString();
|
1447
|
+
const subFn = this.subscribeFn.get(urlWithoutKey);
|
1448
|
+
if (subFn) {
|
1449
|
+
await subFn(rUint8.Ok());
|
1226
1450
|
}
|
1227
1451
|
}
|
1228
1452
|
return ret;
|
@@ -1243,7 +1467,12 @@ var DefSerdeGateway = class {
|
|
1243
1467
|
});
|
1244
1468
|
}
|
1245
1469
|
if (!this.gw.subscribe) {
|
1246
|
-
|
1470
|
+
if (!url.hasParam(PARAM.SELF_REFLECT)) {
|
1471
|
+
return Result7.Ok(() => {
|
1472
|
+
});
|
1473
|
+
}
|
1474
|
+
const urlWithoutKey = url.build().delParam(PARAM.KEY).delParam(PARAM.SELF_REFLECT).toString();
|
1475
|
+
this.subscribeFn.set(urlWithoutKey, rawCallback);
|
1247
1476
|
return Result7.Ok(() => {
|
1248
1477
|
this.subscribeFn.delete(url.toString());
|
1249
1478
|
});
|
@@ -1322,7 +1551,7 @@ function defaultGatewayFactoryItem() {
|
|
1322
1551
|
}
|
1323
1552
|
function defaultURI(sthis) {
|
1324
1553
|
const rt = runtimeFn3();
|
1325
|
-
return BuildURI.from("file://").pathname(`${sthis.env.get("HOME")}/.fireproof/${FILESTORE_VERSION.replace(/-.*$/, "")}`).setParam(
|
1554
|
+
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
1555
|
}
|
1327
1556
|
if (runtimeFn3().isNodeIsh || runtimeFn3().isDeno) {
|
1328
1557
|
registerStoreProtocol({
|
@@ -1339,7 +1568,7 @@ if (runtimeFn3().isBrowser) {
|
|
1339
1568
|
protocol: "indexeddb:",
|
1340
1569
|
isDefault: true,
|
1341
1570
|
defaultURI: () => {
|
1342
|
-
return BuildURI.from("indexeddb://").pathname("fp").setParam(
|
1571
|
+
return BuildURI.from("indexeddb://").pathname("fp").setParam(PARAM.VERSION, INDEXEDDB_VERSION).setParam(PARAM.RUNTIME, "browser").URI();
|
1343
1572
|
},
|
1344
1573
|
gateway: async () => {
|
1345
1574
|
const { GatewayImpl } = await import("@fireproof/core/indexeddb");
|
@@ -1905,7 +2134,7 @@ __export(blockstore_exports, {
|
|
1905
2134
|
DbMetaEventEqual: () => DbMetaEventEqual,
|
1906
2135
|
DbMetaEventsEqual: () => DbMetaEventsEqual,
|
1907
2136
|
EncryptedBlockstore: () => EncryptedBlockstore,
|
1908
|
-
|
2137
|
+
FPEnvelopeTypes: () => FPEnvelopeTypes,
|
1909
2138
|
File2FPMsg: () => File2FPMsg,
|
1910
2139
|
InterceptorGateway: () => InterceptorGateway,
|
1911
2140
|
Loader: () => Loader,
|
@@ -2794,12 +3023,12 @@ var generateIV = {
|
|
2794
3023
|
return hashArray;
|
2795
3024
|
},
|
2796
3025
|
verify: async function(ko, crypto, iv, data) {
|
2797
|
-
return ko.url.getParam(
|
3026
|
+
return ko.url.getParam(PARAM.IV_VERIFY) !== "disable" && UInt8ArrayEqual(iv, await this.calc(ko, crypto, data));
|
2798
3027
|
}
|
2799
3028
|
}
|
2800
3029
|
};
|
2801
3030
|
function getGenerateIVFn(url, opts) {
|
2802
|
-
const ivhash = opts.ivCalc || url.getParam(
|
3031
|
+
const ivhash = opts.ivCalc || url.getParam(PARAM.IV_HASH) || "hash";
|
2803
3032
|
return generateIV[ivhash] || generateIV["hash"];
|
2804
3033
|
}
|
2805
3034
|
var BlockIvKeyIdCodec = class {
|
@@ -2813,13 +3042,16 @@ var BlockIvKeyIdCodec = class {
|
|
2813
3042
|
async encode(data) {
|
2814
3043
|
const calcIv = this.iv || await getGenerateIVFn(this.ko.url, this.opts).calc(this.ko, this.ko.crypto, data);
|
2815
3044
|
const { iv } = this.ko.algo(calcIv);
|
2816
|
-
const
|
2817
|
-
|
2818
|
-
|
3045
|
+
const defKey = await this.ko.key.get();
|
3046
|
+
if (!defKey) {
|
3047
|
+
throw this.ko.logger.Error().Msg("default key not found").AsError();
|
3048
|
+
}
|
3049
|
+
const keyId = base58btc3.decode(defKey?.fingerPrint);
|
3050
|
+
this.ko.logger.Debug().Str("fp", defKey.fingerPrint).Msg("encode");
|
2819
3051
|
return CBOR.encode({
|
2820
3052
|
iv,
|
2821
3053
|
keyId,
|
2822
|
-
data: await this.ko._encrypt({ iv, bytes: data })
|
3054
|
+
data: await this.ko._encrypt({ iv, key: defKey.key, bytes: data })
|
2823
3055
|
});
|
2824
3056
|
}
|
2825
3057
|
async decode(abytes) {
|
@@ -2830,30 +3062,32 @@ var BlockIvKeyIdCodec = class {
|
|
2830
3062
|
bytes = new Uint8Array(abytes);
|
2831
3063
|
}
|
2832
3064
|
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();
|
3065
|
+
const key = await this.ko.key.get(keyId);
|
3066
|
+
if (!key) {
|
3067
|
+
throw this.ko.logger.Error().Str("fp", base58btc3.encode(keyId)).Msg("keyId not found").AsError();
|
2837
3068
|
}
|
2838
|
-
const result = await this.ko._decrypt({ iv, bytes: data });
|
3069
|
+
const result = await this.ko._decrypt({ iv, key: key.key, bytes: data });
|
2839
3070
|
if (!this.opts?.noIVVerify && !await getGenerateIVFn(this.ko.url, this.opts).verify(this.ko, this.ko.crypto, iv, result)) {
|
2840
3071
|
throw this.ko.logger.Error().Msg("iv missmatch").AsError();
|
2841
3072
|
}
|
2842
3073
|
return result;
|
2843
3074
|
}
|
2844
3075
|
};
|
2845
|
-
var
|
3076
|
+
var cryptoAction = class {
|
2846
3077
|
constructor(url, key, cyopt, sthis) {
|
2847
3078
|
this.ivLength = 12;
|
2848
3079
|
this.isEncrypting = true;
|
2849
|
-
this.logger = ensureLogger(sthis, "
|
3080
|
+
this.logger = ensureLogger(sthis, "cryptoAction");
|
2850
3081
|
this.crypto = cyopt;
|
2851
3082
|
this.key = key;
|
2852
3083
|
this.url = url;
|
2853
3084
|
}
|
2854
|
-
|
2855
|
-
|
2856
|
-
}
|
3085
|
+
// keyByFingerPrint(id: Uint8Array | string): Promise<Result<KeyWithFingerPrint>> {
|
3086
|
+
// return this.key.get(id)
|
3087
|
+
// }
|
3088
|
+
// fingerPrint(): Promise<string> {
|
3089
|
+
// return this.key.get().then((k) => k.fingerPrint);
|
3090
|
+
// }
|
2857
3091
|
codec(iv, opts) {
|
2858
3092
|
return new BlockIvKeyIdCodec(this, iv, opts);
|
2859
3093
|
}
|
@@ -2865,13 +3099,11 @@ var keyedCrypto = class {
|
|
2865
3099
|
};
|
2866
3100
|
}
|
2867
3101
|
async _decrypt(data) {
|
2868
|
-
this.
|
2869
|
-
return new Uint8Array(await this.crypto.decrypt(this.algo(data.iv), this.key.key, data.bytes));
|
3102
|
+
return new Uint8Array(await this.crypto.decrypt(this.algo(data.iv), data.key, data.bytes));
|
2870
3103
|
}
|
2871
3104
|
async _encrypt(data) {
|
2872
|
-
this.logger.Debug().Len(data.bytes).Str("fp", this.key.fingerPrint).Msg("encrypting");
|
2873
3105
|
const a = this.algo(data.iv);
|
2874
|
-
return new Uint8Array(await this.crypto.encrypt(a,
|
3106
|
+
return new Uint8Array(await this.crypto.encrypt(a, data.key, data.bytes));
|
2875
3107
|
}
|
2876
3108
|
};
|
2877
3109
|
var nullCodec = class {
|
@@ -2895,6 +3127,19 @@ var noCrypto = class {
|
|
2895
3127
|
this._fingerPrint = "noCrypto:" + Math.random();
|
2896
3128
|
this.logger = ensureLogger(sthis, "noCrypto");
|
2897
3129
|
this.crypto = cyrt;
|
3130
|
+
this.key = {
|
3131
|
+
id: sthis.nextId().str,
|
3132
|
+
name: "noCrypto",
|
3133
|
+
get: () => {
|
3134
|
+
throw this.logger.Error().Msg("noCrypto.get not implemented").AsError();
|
3135
|
+
},
|
3136
|
+
upsert: () => {
|
3137
|
+
throw this.logger.Error().Msg("noCrypto.upsert not implemented").AsError();
|
3138
|
+
},
|
3139
|
+
asKeysItem: () => {
|
3140
|
+
throw this.logger.Error().Msg("noCrypto.asKeysItem not implemented").AsError();
|
3141
|
+
}
|
3142
|
+
};
|
2898
3143
|
this.url = url;
|
2899
3144
|
}
|
2900
3145
|
fingerPrint() {
|
@@ -2920,17 +3165,13 @@ var noCrypto = class {
|
|
2920
3165
|
}
|
2921
3166
|
};
|
2922
3167
|
async function keyedCryptoFactory(url, kb, sthis) {
|
2923
|
-
const storekey = url.getParam(
|
3168
|
+
const storekey = url.getParam(PARAM.STORE_KEY);
|
2924
3169
|
if (storekey && storekey !== "insecure") {
|
2925
|
-
|
3170
|
+
const rkey = await kb.getNamedKey(storekey, false);
|
2926
3171
|
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
|
-
}
|
3172
|
+
throw sthis.logger.Error().Str("keybag", kb.rt.id()).Str("name", storekey).Msg("getNamedKey failed").AsError();
|
2932
3173
|
}
|
2933
|
-
return new
|
3174
|
+
return new cryptoAction(url, rkey.Ok(), kb.rt.crypto, sthis);
|
2934
3175
|
}
|
2935
3176
|
return new noCrypto(url, kb.rt.crypto, sthis);
|
2936
3177
|
}
|
@@ -3095,7 +3336,7 @@ var BaseStoreImpl = class {
|
|
3095
3336
|
this.opts = opts;
|
3096
3337
|
this.loader = opts.loader;
|
3097
3338
|
this.sthis = sthis;
|
3098
|
-
const name = this._url.getParam(
|
3339
|
+
const name = this._url.getParam(PARAM.NAME);
|
3099
3340
|
if (!name) {
|
3100
3341
|
throw logger.Error().Url(this._url).Msg("missing name").AsError();
|
3101
3342
|
}
|
@@ -3120,7 +3361,7 @@ var BaseStoreImpl = class {
|
|
3120
3361
|
}
|
3121
3362
|
async start() {
|
3122
3363
|
this.logger.Debug().Str("storeType", this.storeType).Msg("starting-gateway-pre");
|
3123
|
-
this._url = this._url.build().setParam(
|
3364
|
+
this._url = this._url.build().setParam(PARAM.STORE, this.storeType).URI();
|
3124
3365
|
const res = await this.gateway.start({ loader: this.loader }, this._url);
|
3125
3366
|
if (res.isErr()) {
|
3126
3367
|
this.logger.Error().Result("gw-start", res).Msg("started-gateway");
|
@@ -3129,8 +3370,8 @@ var BaseStoreImpl = class {
|
|
3129
3370
|
this._url = res.Ok();
|
3130
3371
|
const kb = await this.loader.keyBag();
|
3131
3372
|
const skRes = await kb.ensureKeyFromUrl(this._url, () => {
|
3132
|
-
const idx = this._url.getParam(
|
3133
|
-
const storeKeyName = [this.url().getParam(
|
3373
|
+
const idx = this._url.getParam(PARAM.INDEX);
|
3374
|
+
const storeKeyName = [this.url().getParam(PARAM.NAME)];
|
3134
3375
|
if (idx) {
|
3135
3376
|
storeKeyName.push(idx);
|
3136
3377
|
}
|
@@ -3289,16 +3530,16 @@ var DataStoreImpl = class extends BaseStoreImpl {
|
|
3289
3530
|
throw this.logger.Error().Err(url.Err()).Ref("cid", car.cid).Msg("got error from gateway.buildUrl").AsError();
|
3290
3531
|
}
|
3291
3532
|
let fpMsg;
|
3292
|
-
switch (url.Ok().getParam(
|
3533
|
+
switch (url.Ok().getParam(PARAM.STORE)) {
|
3293
3534
|
case "data":
|
3294
|
-
if (url.Ok().getParam(
|
3535
|
+
if (url.Ok().getParam(PARAM.SUFFIX)) {
|
3295
3536
|
fpMsg = Car2FPMsg(car.bytes);
|
3296
3537
|
} else {
|
3297
3538
|
fpMsg = File2FPMsg(car.bytes);
|
3298
3539
|
}
|
3299
3540
|
break;
|
3300
3541
|
default:
|
3301
|
-
throw this.logger.Error().Str("store", url.Ok().getParam(
|
3542
|
+
throw this.logger.Error().Str("store", url.Ok().getParam(PARAM.STORE)).Msg("unexpected store").AsError();
|
3302
3543
|
}
|
3303
3544
|
if (fpMsg.isErr()) {
|
3304
3545
|
throw this.logger.Error().Err(fpMsg).Msg("got error from FPMsg2Car").AsError();
|
@@ -3542,7 +3783,7 @@ async function getStartedGateway(ctx, url) {
|
|
3542
3783
|
});
|
3543
3784
|
}
|
3544
3785
|
async function dataStoreFactory(sfi) {
|
3545
|
-
const storeUrl = sfi.url.build().setParam(
|
3786
|
+
const storeUrl = sfi.url.build().setParam(PARAM.STORE, "data").URI();
|
3546
3787
|
const rgateway = await getStartedGateway(sfi, storeUrl);
|
3547
3788
|
if (rgateway.isErr()) {
|
3548
3789
|
throw sfi.loader.sthis.logger.Error().Result("err", rgateway).Url(sfi.url).Msg("notfound").AsError();
|
@@ -3556,7 +3797,7 @@ async function dataStoreFactory(sfi) {
|
|
3556
3797
|
return store;
|
3557
3798
|
}
|
3558
3799
|
async function metaStoreFactory(sfi) {
|
3559
|
-
const storeUrl = sfi.url.build().setParam(
|
3800
|
+
const storeUrl = sfi.url.build().setParam(PARAM.STORE, "meta").URI();
|
3560
3801
|
const rgateway = await getStartedGateway(sfi, storeUrl);
|
3561
3802
|
if (rgateway.isErr()) {
|
3562
3803
|
throw sfi.loader.sthis.logger.Error().Result("err", rgateway).Url(sfi.url).Msg("notfound").AsError();
|
@@ -3570,7 +3811,7 @@ async function metaStoreFactory(sfi) {
|
|
3570
3811
|
return store;
|
3571
3812
|
}
|
3572
3813
|
async function WALStoreFactory(sfi) {
|
3573
|
-
const storeUrl = sfi.url.build().setParam(
|
3814
|
+
const storeUrl = sfi.url.build().setParam(PARAM.STORE, "wal").URI();
|
3574
3815
|
const rgateway = await getStartedGateway(sfi, storeUrl);
|
3575
3816
|
if (rgateway.isErr()) {
|
3576
3817
|
throw sfi.loader.sthis.logger.Error().Result("err", rgateway).Url(sfi.url).Msg("notfound").AsError();
|
@@ -3702,11 +3943,11 @@ var ConnectionBase = class {
|
|
3702
3943
|
if (!loader) throw this.logger.Error().Msg("connectMeta: loader is required").AsError();
|
3703
3944
|
this.loader = loader;
|
3704
3945
|
await this.onConnect();
|
3705
|
-
const metaUrl = this.url.build().defParam(
|
3946
|
+
const metaUrl = this.url.build().defParam(PARAM.STORE, "meta").URI();
|
3706
3947
|
const rgateway = await getStartedGateway({ loader }, metaUrl);
|
3707
3948
|
if (rgateway.isErr())
|
3708
3949
|
throw this.logger.Error().Result("err", rgateway).Url(metaUrl).Msg("connectMeta: gateway is required").AsError();
|
3709
|
-
const dbName = metaUrl.getParam(
|
3950
|
+
const dbName = metaUrl.getParam(PARAM.NAME);
|
3710
3951
|
if (!dbName) {
|
3711
3952
|
throw this.logger.Error().Url(metaUrl).Msg("connectMeta: dbName is required").AsError();
|
3712
3953
|
}
|
@@ -3738,11 +3979,11 @@ var ConnectionBase = class {
|
|
3738
3979
|
const loader = coerceLoader(refl);
|
3739
3980
|
if (!loader) throw this.logger.Error().Msg("connectStorage: loader is required").AsError();
|
3740
3981
|
this.loader = loader;
|
3741
|
-
const dataUrl = this.url.build().defParam(
|
3982
|
+
const dataUrl = this.url.build().defParam(PARAM.STORE, "data").URI();
|
3742
3983
|
const rgateway = await getStartedGateway({ loader }, dataUrl);
|
3743
3984
|
if (rgateway.isErr())
|
3744
3985
|
throw this.logger.Error().Result("err", rgateway).Url(dataUrl).Msg("connectStorage: gateway is required").AsError();
|
3745
|
-
const name = dataUrl.getParam(
|
3986
|
+
const name = dataUrl.getParam(PARAM.NAME);
|
3746
3987
|
if (!name) throw this.logger.Error().Url(dataUrl).Msg("connectStorage: name is required").AsError;
|
3747
3988
|
loader.remoteCarStore = await RemoteDataStore(loader.sthis, this.url, {
|
3748
3989
|
gateway: rgateway.Ok().gateway,
|
@@ -4463,7 +4704,7 @@ var LedgerImpl = class {
|
|
4463
4704
|
this.crdt.clock.onTock(() => this._no_update_notify());
|
4464
4705
|
}
|
4465
4706
|
get name() {
|
4466
|
-
return this.opts.storeUrls.data.data.getParam(
|
4707
|
+
return this.opts.storeUrls.data.data.getParam(PARAM.NAME) ?? "default";
|
4467
4708
|
}
|
4468
4709
|
addShell(shell) {
|
4469
4710
|
this.shells.add(shell);
|
@@ -4549,24 +4790,24 @@ var LedgerImpl = class {
|
|
4549
4790
|
};
|
4550
4791
|
function defaultURI2(sthis, curi, uri, store, ctx) {
|
4551
4792
|
ctx = ctx || {};
|
4552
|
-
const ret = (curi ? URI13.from(curi) : uri).build().setParam(
|
4553
|
-
if (!ret.hasParam(
|
4793
|
+
const ret = (curi ? URI13.from(curi) : uri).build().setParam(PARAM.STORE, store);
|
4794
|
+
if (!ret.hasParam(PARAM.NAME)) {
|
4554
4795
|
const name = sthis.pathOps.basename(ret.URI().pathname);
|
4555
4796
|
if (!name) {
|
4556
4797
|
throw sthis.logger.Error().Url(ret).Any("ctx", ctx).Msg("Ledger name is required").AsError();
|
4557
4798
|
}
|
4558
|
-
ret.setParam(
|
4799
|
+
ret.setParam(PARAM.NAME, name);
|
4559
4800
|
}
|
4560
4801
|
if (ctx.idx) {
|
4561
|
-
ret.defParam(
|
4562
|
-
ret.defParam(
|
4802
|
+
ret.defParam(PARAM.INDEX, "idx");
|
4803
|
+
ret.defParam(PARAM.STORE_KEY, `@${ret.getParam(PARAM.NAME)}-${store}-idx@`);
|
4563
4804
|
} else {
|
4564
|
-
ret.defParam(
|
4805
|
+
ret.defParam(PARAM.STORE_KEY, `@${ret.getParam(PARAM.NAME)}-${store}@`);
|
4565
4806
|
}
|
4566
4807
|
if (store === "data") {
|
4567
4808
|
if (ctx.file) {
|
4568
4809
|
} else {
|
4569
|
-
ret.defParam(
|
4810
|
+
ret.defParam(PARAM.SUFFIX, ".car");
|
4570
4811
|
}
|
4571
4812
|
}
|
4572
4813
|
return ret.URI();
|
@@ -4576,14 +4817,14 @@ function toStoreURIRuntime(sthis, name, sopts) {
|
|
4576
4817
|
if (!sopts.base) {
|
4577
4818
|
const fp_env = sthis.env.get("FP_STORAGE_URL");
|
4578
4819
|
if (fp_env) {
|
4579
|
-
sopts = { ...sopts, base: BuildURI2.from(fp_env).setParam(
|
4820
|
+
sopts = { ...sopts, base: BuildURI2.from(fp_env).setParam(PARAM.URL_GEN, "fromEnv") };
|
4580
4821
|
} else {
|
4581
|
-
sopts = { ...sopts, base: getDefaultURI(sthis).build().setParam(
|
4822
|
+
sopts = { ...sopts, base: getDefaultURI(sthis).build().setParam(PARAM.URL_GEN, "default") };
|
4582
4823
|
}
|
4583
4824
|
}
|
4584
4825
|
const bbase = BuildURI2.from(sopts.base);
|
4585
4826
|
if (name) {
|
4586
|
-
bbase.setParam(
|
4827
|
+
bbase.setParam(PARAM.NAME, name);
|
4587
4828
|
}
|
4588
4829
|
const base = bbase.URI();
|
4589
4830
|
return {
|
@@ -4620,9 +4861,11 @@ __export(runtime_exports, {
|
|
4620
4861
|
gw: () => gateways_exports,
|
4621
4862
|
kb: () => key_bag_exports,
|
4622
4863
|
kc: () => keyed_crypto_exports,
|
4864
|
+
keysByFingerprint: () => keysByFingerprint,
|
4623
4865
|
mf: () => wait_pr_multiformats_exports,
|
4624
4866
|
registerKeyBagProviderFactory: () => registerKeyBagProviderFactory,
|
4625
|
-
runtimeFn: () => runtimeFn4
|
4867
|
+
runtimeFn: () => runtimeFn4,
|
4868
|
+
toKeyWithFingerPrint: () => toKeyWithFingerPrint
|
4626
4869
|
});
|
4627
4870
|
|
4628
4871
|
// src/runtime/wait-pr-multiformats/index.ts
|
@@ -4659,7 +4902,7 @@ __export(file_exports, {
|
|
4659
4902
|
|
4660
4903
|
// src/version.ts
|
4661
4904
|
var PACKAGE_VERSION = Object.keys({
|
4662
|
-
"0.20.0-dev-preview-
|
4905
|
+
"0.20.0-dev-preview-26": "xxxx"
|
4663
4906
|
})[0];
|
4664
4907
|
export {
|
4665
4908
|
CRDTImpl,
|