@fireproof/core 0.19.121 → 0.20.0-dev-preview-05
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/README.md +13 -12
- package/deno/index.d.ts +7 -0
- package/deno/index.js +66 -0
- package/deno/index.js.map +1 -0
- package/deno/metafile-esm.json +1 -0
- package/deno.json +2 -3
- package/index.cjs +1827 -1059
- package/index.cjs.map +1 -1
- package/index.d.cts +747 -334
- package/index.d.ts +747 -334
- package/index.js +1800 -1034
- package/index.js.map +1 -1
- package/metafile-cjs.json +1 -1
- package/metafile-esm.json +1 -1
- package/node/index.cjs +16 -293
- package/node/index.cjs.map +1 -1
- package/node/index.d.cts +4 -40
- package/node/index.d.ts +4 -40
- package/node/index.js +22 -237
- package/node/index.js.map +1 -1
- package/node/metafile-cjs.json +1 -1
- package/node/metafile-esm.json +1 -1
- package/package.json +14 -6
- package/react/index.cjs +22 -22
- package/react/index.cjs.map +1 -1
- package/react/index.d.cts +7 -7
- package/react/index.d.ts +7 -7
- package/react/index.js +22 -22
- package/react/index.js.map +1 -1
- package/react/metafile-cjs.json +1 -1
- package/react/metafile-esm.json +1 -1
- package/tests/blockstore/fp-envelope.test.ts-off +65 -0
- package/tests/blockstore/interceptor-gateway.test.ts +122 -0
- package/tests/blockstore/keyed-crypto-indexdb-file.test.ts +130 -0
- package/tests/blockstore/keyed-crypto.test.ts +73 -118
- package/tests/blockstore/loader.test.ts +18 -9
- package/tests/blockstore/store.test.ts +40 -31
- package/tests/blockstore/transaction.test.ts +14 -13
- package/tests/fireproof/all-gateway.test.ts +286 -216
- package/tests/fireproof/cars/bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i.ts +324 -316
- package/tests/fireproof/crdt.test.ts +78 -19
- package/tests/fireproof/fireproof.test.ts +111 -92
- package/tests/fireproof/hello.test.ts +21 -17
- package/tests/fireproof/indexer.test.ts +74 -50
- package/tests/fireproof/{database.test.ts → ledger.test.ts} +241 -45
- package/tests/fireproof/multiple-ledger.test.ts +2 -2
- package/tests/fireproof/utils.test.ts +47 -6
- package/tests/gateway/file/loader-config.test.ts +307 -0
- package/tests/gateway/fp-envelope-serialize.test.ts +256 -0
- package/tests/gateway/indexdb/loader-config.test.ts +79 -0
- package/tests/helpers.ts +44 -17
- package/tests/react/useFireproof.test.tsx +2 -2
- package/tests/www/gallery.html +2 -2
- package/tests/www/todo-aws.html +1 -1
- package/tests/www/todo-ipfs.html +1 -1
- package/tests/www/todo-local.html +1 -1
- package/tests/www/todo.html +25 -4
- package/web/index.cjs +102 -116
- package/web/index.cjs.map +1 -1
- package/web/index.d.cts +15 -29
- package/web/index.d.ts +15 -29
- package/web/index.js +91 -105
- package/web/index.js.map +1 -1
- package/web/metafile-cjs.json +1 -1
- package/web/metafile-esm.json +1 -1
- package/node/chunk-4A4RAVNS.js +0 -17
- package/node/chunk-4A4RAVNS.js.map +0 -1
- package/node/mem-filesystem-LPPT7QV5.js +0 -40
- package/node/mem-filesystem-LPPT7QV5.js.map +0 -1
- package/tests/fireproof/config.test.ts +0 -163
- /package/tests/blockstore/{fragment-gateway.test.ts → fragment-gateway.test.ts-off} +0 -0
@@ -0,0 +1,122 @@
|
|
1
|
+
import { Result, URI } from "@adviser/cement";
|
2
|
+
import { bs, fireproof, SuperThis } from "@fireproof/core";
|
3
|
+
|
4
|
+
class TestInterceptor extends bs.PassThroughGateway {
|
5
|
+
readonly fn = vitest.fn();
|
6
|
+
|
7
|
+
async buildUrl(sthis: SuperThis, baseUrl: URI, key: string): Promise<Result<bs.SerdeGatewayBuildUrlReturn>> {
|
8
|
+
const ret = await super.buildUrl(sthis, baseUrl, key);
|
9
|
+
this.fn("buildUrl", ret);
|
10
|
+
return ret;
|
11
|
+
}
|
12
|
+
|
13
|
+
async start(sthis: SuperThis, baseUrl: URI): Promise<Result<bs.SerdeGatewayStartReturn>> {
|
14
|
+
const ret = await super.start(sthis, baseUrl);
|
15
|
+
this.fn("start", ret);
|
16
|
+
return ret;
|
17
|
+
}
|
18
|
+
async close(sthis: SuperThis, baseUrl: URI): Promise<Result<bs.SerdeGatewayCloseReturn>> {
|
19
|
+
const ret = await super.close(sthis, baseUrl);
|
20
|
+
this.fn("close", ret);
|
21
|
+
return ret;
|
22
|
+
}
|
23
|
+
async delete(sthis: SuperThis, baseUrl: URI): Promise<Result<bs.SerdeGatewayDeleteReturn>> {
|
24
|
+
const ret = await super.delete(sthis, baseUrl);
|
25
|
+
this.fn("delete", ret);
|
26
|
+
return ret;
|
27
|
+
}
|
28
|
+
async destroy(sthis: SuperThis, baseUrl: URI): Promise<Result<bs.SerdeGatewayDestroyReturn>> {
|
29
|
+
const ret = await super.destroy(sthis, baseUrl);
|
30
|
+
this.fn("destroy", ret);
|
31
|
+
return ret;
|
32
|
+
}
|
33
|
+
async put<T>(sthis: SuperThis, url: URI, body: bs.FPEnvelope<T>): Promise<Result<bs.SerdeGatewayPutReturn<T>>> {
|
34
|
+
const ret = await super.put<T>(sthis, url, body);
|
35
|
+
this.fn("put", ret);
|
36
|
+
return ret;
|
37
|
+
}
|
38
|
+
async get<S>(sthis: SuperThis, url: URI): Promise<Result<bs.SerdeGatewayGetReturn<S>>> {
|
39
|
+
const ret = await super.get<S>(sthis, url);
|
40
|
+
this.fn("get", ret);
|
41
|
+
return ret;
|
42
|
+
}
|
43
|
+
async subscribe(
|
44
|
+
sthis: SuperThis,
|
45
|
+
url: URI,
|
46
|
+
callback: (meta: bs.FPEnvelopeMeta) => Promise<void>,
|
47
|
+
): Promise<Result<bs.SerdeGatewaySubscribeReturn>> {
|
48
|
+
const ret = await super.subscribe(sthis, url, callback);
|
49
|
+
this.fn("subscribe", ret);
|
50
|
+
return ret;
|
51
|
+
}
|
52
|
+
}
|
53
|
+
|
54
|
+
describe("InterceptorGateway", () => {
|
55
|
+
it("passthrough", async () => {
|
56
|
+
const gwi = new TestInterceptor();
|
57
|
+
const db = fireproof("interceptor-gateway", {
|
58
|
+
gatewayInterceptor: gwi,
|
59
|
+
});
|
60
|
+
expect(
|
61
|
+
await db.put({
|
62
|
+
_id: "foo",
|
63
|
+
foo: 4,
|
64
|
+
}),
|
65
|
+
);
|
66
|
+
expect(await db.get("foo")).toEqual({
|
67
|
+
_id: "foo",
|
68
|
+
foo: 4,
|
69
|
+
});
|
70
|
+
await db.close();
|
71
|
+
await db.destroy();
|
72
|
+
// await sleep(1000);
|
73
|
+
expect(gwi.fn.mock.calls.length).toBe(42);
|
74
|
+
// might be a stupid test
|
75
|
+
expect(gwi.fn.mock.calls.map((i) => i[0]).sort() /* not ok there are some operation */).toEqual(
|
76
|
+
[
|
77
|
+
"start",
|
78
|
+
"start",
|
79
|
+
"buildUrl",
|
80
|
+
"get",
|
81
|
+
"buildUrl",
|
82
|
+
"get",
|
83
|
+
"start",
|
84
|
+
"start",
|
85
|
+
"buildUrl",
|
86
|
+
"get",
|
87
|
+
"buildUrl",
|
88
|
+
"put",
|
89
|
+
"buildUrl",
|
90
|
+
"put",
|
91
|
+
"buildUrl",
|
92
|
+
"put",
|
93
|
+
"start",
|
94
|
+
"start",
|
95
|
+
"start",
|
96
|
+
"start",
|
97
|
+
"close",
|
98
|
+
"close",
|
99
|
+
"close",
|
100
|
+
"close",
|
101
|
+
"close",
|
102
|
+
"close",
|
103
|
+
"close",
|
104
|
+
"close",
|
105
|
+
"buildUrl",
|
106
|
+
"get",
|
107
|
+
"close",
|
108
|
+
"close",
|
109
|
+
"close",
|
110
|
+
"close",
|
111
|
+
"destroy",
|
112
|
+
"destroy",
|
113
|
+
"destroy",
|
114
|
+
"destroy",
|
115
|
+
"destroy",
|
116
|
+
"destroy",
|
117
|
+
"destroy",
|
118
|
+
"destroy",
|
119
|
+
].sort() /* not ok there are some operation */,
|
120
|
+
);
|
121
|
+
});
|
122
|
+
});
|
@@ -0,0 +1,130 @@
|
|
1
|
+
import { bs, PARAM, rt } from "@fireproof/core";
|
2
|
+
import { runtimeFn, toCryptoRuntime, URI } from "@adviser/cement";
|
3
|
+
import { base58btc } from "multiformats/bases/base58";
|
4
|
+
import { mockSuperThis } from "../helpers.js";
|
5
|
+
import { KeyBagProviderIndexDB } from "@fireproof/core/web";
|
6
|
+
|
7
|
+
describe("KeyBag indexdb and file", () => {
|
8
|
+
let url: URI;
|
9
|
+
const sthis = mockSuperThis();
|
10
|
+
beforeAll(async () => {
|
11
|
+
await sthis.start();
|
12
|
+
if (runtimeFn().isBrowser) {
|
13
|
+
url = URI.from("indexdb://fp-keybag");
|
14
|
+
} else {
|
15
|
+
url = URI.merge(`file://./dist/tests/key.bag`, sthis.env.get("FP_KEYBAG_URL"));
|
16
|
+
}
|
17
|
+
});
|
18
|
+
it("default-path", async () => {
|
19
|
+
const old = sthis.env.get("FP_KEYBAG_URL");
|
20
|
+
sthis.env.delete("FP_KEYBAG_URL");
|
21
|
+
const kb = await rt.kb.getKeyBag(sthis);
|
22
|
+
if (runtimeFn().isBrowser) {
|
23
|
+
expect(kb.rt.url.toString()).toBe(`indexdb://fp-keybag`);
|
24
|
+
} else {
|
25
|
+
expect(kb.rt.url.toString()).toBe(`file://${sthis.env.get("HOME")}/.fireproof/keybag`);
|
26
|
+
}
|
27
|
+
sthis.env.set("FP_KEYBAG_URL", old);
|
28
|
+
});
|
29
|
+
it("from env", async () => {
|
30
|
+
const old = sthis.env.get("FP_KEYBAG_URL");
|
31
|
+
sthis.env.set("FP_KEYBAG_URL", url.toString());
|
32
|
+
const kb = await rt.kb.getKeyBag(sthis);
|
33
|
+
expect(kb.rt.url.toString()).toBe(url.toString());
|
34
|
+
sthis.env.set("FP_KEYBAG_URL", old);
|
35
|
+
});
|
36
|
+
it("simple add", async () => {
|
37
|
+
const kb = await rt.kb.getKeyBag(sthis, {
|
38
|
+
url: url.toString(),
|
39
|
+
crypto: toCryptoRuntime({
|
40
|
+
randomBytes: (size) => new Uint8Array(size).map((_, i) => i),
|
41
|
+
}),
|
42
|
+
});
|
43
|
+
const name = "setkey" + Math.random();
|
44
|
+
expect((await kb.getNamedKey(name, true)).isErr()).toBeTruthy();
|
45
|
+
|
46
|
+
const key = base58btc.encode(kb.rt.crypto.randomBytes(kb.rt.keyLength));
|
47
|
+
const res = await kb.setNamedKey(name, key);
|
48
|
+
expect(res.isOk()).toBeTruthy();
|
49
|
+
expect((await kb.getNamedKey(name, true)).Ok()).toEqual(res.Ok());
|
50
|
+
|
51
|
+
const name2 = "implicit";
|
52
|
+
const created = await kb.getNamedKey(name2);
|
53
|
+
expect(created.isOk()).toBeTruthy();
|
54
|
+
|
55
|
+
expect((await kb.getNamedKey(name2)).Ok()).toEqual(created.Ok());
|
56
|
+
|
57
|
+
let diskBag: rt.kb.KeyItem;
|
58
|
+
let diskBag2: rt.kb.KeyItem;
|
59
|
+
const provider = await kb.rt.getBag();
|
60
|
+
if (runtimeFn().isBrowser) {
|
61
|
+
const p = provider as KeyBagProviderIndexDB;
|
62
|
+
diskBag = await p._prepare().then((db) => db.get("bag", name));
|
63
|
+
diskBag2 = await p._prepare().then((db) => db.get("bag", name2));
|
64
|
+
} else {
|
65
|
+
const p = provider as rt.gw.file.KeyBagProviderFile;
|
66
|
+
const { sysFS } = await p._prepare(name);
|
67
|
+
|
68
|
+
diskBag = await sysFS.readfile((await p._prepare(name)).fName).then((data) => {
|
69
|
+
return JSON.parse(sthis.txt.decode(data)) as rt.kb.KeyItem;
|
70
|
+
});
|
71
|
+
diskBag2 = await sysFS.readfile((await p._prepare(name2)).fName).then((data) => {
|
72
|
+
return JSON.parse(sthis.txt.decode(data)) as rt.kb.KeyItem;
|
73
|
+
});
|
74
|
+
}
|
75
|
+
expect(await kb.toKeyWithFingerPrint(diskBag.key)).toEqual(res);
|
76
|
+
expect(await kb.toKeyWithFingerPrint(diskBag2.key)).toEqual(created);
|
77
|
+
const algo = {
|
78
|
+
name: "AES-GCM",
|
79
|
+
iv: kb.rt.crypto.randomBytes(12),
|
80
|
+
tagLength: 128,
|
81
|
+
};
|
82
|
+
const data = kb.rt.crypto.randomBytes(122);
|
83
|
+
expect(await kb.rt.crypto.encrypt(algo, res.Ok().key, data)).toEqual(await kb.rt.crypto.encrypt(algo, created.Ok().key, data));
|
84
|
+
expect(await kb.rt.crypto.encrypt(algo, await kb.subtleKey(diskBag.key), data)).toEqual(
|
85
|
+
await kb.rt.crypto.encrypt(algo, created.Ok().key, data),
|
86
|
+
);
|
87
|
+
expect(await kb.rt.crypto.encrypt(algo, await kb.subtleKey(diskBag2.key), data)).toEqual(
|
88
|
+
await kb.rt.crypto.encrypt(algo, created.Ok().key, data),
|
89
|
+
);
|
90
|
+
});
|
91
|
+
});
|
92
|
+
|
93
|
+
describe("KeyedCryptoStore", () => {
|
94
|
+
let loader: bs.Loadable;
|
95
|
+
// let logger: Logger;
|
96
|
+
let baseUrl: URI;
|
97
|
+
const sthis = mockSuperThis();
|
98
|
+
beforeEach(async () => {
|
99
|
+
await sthis.start();
|
100
|
+
// logger = MockLogger().logger;
|
101
|
+
let kbUrl: URI;
|
102
|
+
if (runtimeFn().isBrowser) {
|
103
|
+
kbUrl = URI.from("indexdb://fp-keybag");
|
104
|
+
baseUrl = URI.from("indexdb://fp-keyed-crypto-store");
|
105
|
+
} else {
|
106
|
+
kbUrl = URI.merge(`file://./dist/tests/key.bag`, sthis.env.get("FP_KEYBAG_URL"));
|
107
|
+
baseUrl = URI.merge("file://./dist/tests/keyed-crypto-store", sthis.env.get("FP_STORAGE_URL"));
|
108
|
+
}
|
109
|
+
baseUrl = baseUrl.build().defParam(PARAM.NAME, "test").URI();
|
110
|
+
loader = {
|
111
|
+
keyBag: () => rt.kb.getKeyBag(sthis, { url: kbUrl }),
|
112
|
+
} as bs.Loadable;
|
113
|
+
});
|
114
|
+
it("no crypto", async () => {
|
115
|
+
const strt = bs.toStoreRuntime(sthis);
|
116
|
+
const url = baseUrl.build().setParam(PARAM.STORE_KEY, "insecure").URI();
|
117
|
+
|
118
|
+
for (const pstore of [
|
119
|
+
strt.makeDataStore({ sthis, url, loader }),
|
120
|
+
strt.makeMetaStore({ sthis, url, loader }),
|
121
|
+
strt.makeWALStore({ sthis, url, loader }),
|
122
|
+
]) {
|
123
|
+
const store = await pstore;
|
124
|
+
// await store.start();
|
125
|
+
const kc = await store.keyedCrypto();
|
126
|
+
expect(kc.constructor.name).toBe("noCrypto");
|
127
|
+
// expect(kc.isEncrypting).toBe(false);
|
128
|
+
}
|
129
|
+
});
|
130
|
+
});
|
@@ -1,18 +1,17 @@
|
|
1
|
-
import { bs, ensureSuperThis,
|
2
|
-
import { BuildURI,
|
1
|
+
import { bs, ensureSuperThis, PARAM, rt } from "@fireproof/core";
|
2
|
+
import { BuildURI, runtimeFn, toCryptoRuntime, URI } from "@adviser/cement";
|
3
3
|
import { base58btc } from "multiformats/bases/base58";
|
4
4
|
import { sha256 as hasher } from "multiformats/hashes/sha2";
|
5
5
|
import * as dagCodec from "@fireproof/vendor/@ipld/dag-cbor";
|
6
6
|
import type { KeyBagProviderIndexDB } from "@fireproof/core/web";
|
7
|
-
import
|
7
|
+
import { MockSuperThis, mockSuperThis } from "../helpers.js";
|
8
8
|
|
9
9
|
describe("KeyBag", () => {
|
10
10
|
let url: URI;
|
11
|
-
let sthis:
|
12
|
-
const mockLogger = MockLogger();
|
11
|
+
let sthis: MockSuperThis;
|
13
12
|
|
14
13
|
beforeEach(async () => {
|
15
|
-
sthis =
|
14
|
+
sthis = mockSuperThis();
|
16
15
|
await sthis.start();
|
17
16
|
if (runtimeFn().isBrowser) {
|
18
17
|
url = URI.from("indexdb://fp-keybag");
|
@@ -56,7 +55,7 @@ describe("KeyBag", () => {
|
|
56
55
|
});
|
57
56
|
sthis.env.set("FP_KEYBAG_URL", old);
|
58
57
|
await sthis.logger.Flush();
|
59
|
-
expect(
|
58
|
+
expect(sthis.ctx.logCollector.Logs()).toEqual([
|
60
59
|
{
|
61
60
|
level: "warn",
|
62
61
|
module: "KeyBag",
|
@@ -94,7 +93,10 @@ describe("KeyBag", () => {
|
|
94
93
|
diskBag = await p._prepare().then((db) => db.get("bag", name));
|
95
94
|
diskBag2 = await p._prepare().then((db) => db.get("bag", name2));
|
96
95
|
} else {
|
97
|
-
const p = provider as KeyBagProviderFile;
|
96
|
+
const p = provider as rt.gw.file.KeyBagProviderFile;
|
97
|
+
if (typeof p._prepare !== "function") {
|
98
|
+
return;
|
99
|
+
}
|
98
100
|
const { sysFS } = await p._prepare(name);
|
99
101
|
|
100
102
|
diskBag = await sysFS.readfile((await p._prepare(name)).fName).then((data) => {
|
@@ -123,99 +125,83 @@ describe("KeyBag", () => {
|
|
123
125
|
});
|
124
126
|
|
125
127
|
describe("KeyedCryptoStore", () => {
|
128
|
+
let loader: bs.Loadable;
|
126
129
|
let kb: rt.kb.KeyBag;
|
127
|
-
let logger: Logger;
|
130
|
+
// let logger: Logger;
|
128
131
|
let baseUrl: URI;
|
129
132
|
const sthis = ensureSuperThis();
|
130
133
|
beforeEach(async () => {
|
131
134
|
await sthis.start();
|
132
|
-
logger = MockLogger().logger;
|
133
|
-
let kbUrl: URI;
|
134
|
-
if (runtimeFn().isBrowser) {
|
135
|
-
|
136
|
-
|
135
|
+
// logger = MockLogger().logger;
|
136
|
+
// let kbUrl: URI;
|
137
|
+
// if (runtimeFn().isBrowser) {
|
138
|
+
// kbUrl = URI.from("indexdb://fp-keybag");
|
139
|
+
// baseUrl = URI.from("indexdb://fp-keyed-crypto-store");
|
140
|
+
// } else {
|
141
|
+
// kbUrl = URI.merge(`file://./dist/tests/key.bag`, sthis.env.get("FP_KEYBAG_URL"));
|
142
|
+
// baseUrl = URI.merge("file://./dist/tests/keyed-crypto-store", sthis.env.get("FP_STORAGE_URL"));
|
143
|
+
// }
|
144
|
+
// baseUrl = baseUrl.build().defParam(PARAM.NAME, "test").URI();
|
145
|
+
|
146
|
+
const envURL = sthis.env.get("FP_KEYBAG_URL");
|
147
|
+
if (envURL) {
|
148
|
+
baseUrl = bs.getDefaultURI(sthis, URI.from(envURL).protocol);
|
137
149
|
} else {
|
138
|
-
|
139
|
-
// baseUrl = URI.merge("file://./dist/tests/keyed-crypto-store", sthis.env.get("FP_STORAGE_URL"));
|
140
|
-
baseUrl = URI.from(sthis.env.get("FP_STORAGE_URL"));
|
150
|
+
baseUrl = bs.getDefaultURI(sthis);
|
141
151
|
}
|
142
|
-
|
143
|
-
|
144
|
-
|
152
|
+
baseUrl = baseUrl.build().setParam(PARAM.NAME, "test").URI();
|
153
|
+
kb = await rt.kb.getKeyBag(sthis, {});
|
154
|
+
loader = {
|
155
|
+
keyBag: async () => kb,
|
156
|
+
} as bs.Loadable;
|
145
157
|
});
|
146
158
|
it("no crypto", async () => {
|
147
|
-
const
|
148
|
-
|
149
|
-
name: "test",
|
150
|
-
ebOpts: {
|
151
|
-
keyBag: {
|
152
|
-
keyRuntime: kb.rt,
|
153
|
-
},
|
154
|
-
store: {
|
155
|
-
stores: {
|
156
|
-
base: baseUrl.build().setParam("storekey", "insecure"),
|
157
|
-
},
|
158
|
-
},
|
159
|
-
},
|
160
|
-
} as unknown as bs.Loadable;
|
161
|
-
const strt = bs.toStoreRuntime({}, sthis);
|
159
|
+
const strt = bs.toStoreRuntime(sthis);
|
160
|
+
const url = baseUrl.build().setParam(PARAM.STORE_KEY, "insecure").URI();
|
162
161
|
|
163
|
-
for (const pstore of [
|
162
|
+
for (const pstore of [
|
163
|
+
strt.makeDataStore({ sthis, url, loader }),
|
164
|
+
strt.makeMetaStore({ sthis, url, loader }),
|
165
|
+
strt.makeWALStore({ sthis, url, loader }),
|
166
|
+
]) {
|
164
167
|
const store = await pstore;
|
165
168
|
// await store.start();
|
166
169
|
const kc = await store.keyedCrypto();
|
167
170
|
expect(kc.constructor.name).toBe("noCrypto");
|
168
171
|
// expect(kc.isEncrypting).toBe(false);
|
172
|
+
expect(kc.constructor.name).toBe("noCrypto");
|
173
|
+
// expect(kc.isEncrypting).toBe(false);
|
169
174
|
}
|
170
175
|
});
|
171
176
|
|
172
177
|
it("create key", async () => {
|
173
|
-
const
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
store: {
|
181
|
-
stores: {
|
182
|
-
base: baseUrl,
|
183
|
-
},
|
184
|
-
},
|
185
|
-
},
|
186
|
-
} as unknown as bs.Loadable;
|
187
|
-
const strt = bs.toStoreRuntime({}, sthis);
|
188
|
-
for (const pstore of [strt.makeDataStore(loader), strt.makeMetaStore(loader), strt.makeWALStore(loader)]) {
|
189
|
-
const store = await bs.ensureStart(await pstore, logger);
|
178
|
+
const strt = bs.toStoreRuntime(sthis);
|
179
|
+
for (const pstore of [
|
180
|
+
strt.makeDataStore({ sthis, url: baseUrl, loader }),
|
181
|
+
strt.makeMetaStore({ sthis, url: baseUrl, loader }),
|
182
|
+
strt.makeWALStore({ sthis, url: baseUrl, loader }),
|
183
|
+
]) {
|
184
|
+
const store = await pstore; // await bs.ensureStart(await pstore, logger);
|
190
185
|
const kc = await store.keyedCrypto();
|
191
186
|
expect(kc.constructor.name).toBe("keyedCrypto");
|
192
187
|
// expect(kc.isEncrypting).toBe(true);
|
193
|
-
expect(store.url().getParam(
|
188
|
+
expect(store.url().getParam(PARAM.STORE_KEY)).toBe(`@test:${store.url().getParam(PARAM.STORE)}@`);
|
194
189
|
}
|
195
190
|
});
|
196
191
|
|
197
192
|
it("key ref keybag", async () => {
|
198
193
|
const key = base58btc.encode(kb.rt.crypto.randomBytes(kb.rt.keyLength));
|
199
194
|
const genKey = await kb.setNamedKey("@heute@", key);
|
200
|
-
const
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
store: {
|
208
|
-
stores: {
|
209
|
-
base: baseUrl.build().setParam("storekey", "@heute@").URI(),
|
210
|
-
},
|
211
|
-
},
|
212
|
-
},
|
213
|
-
} as unknown as bs.Loadable;
|
214
|
-
const strt = bs.toStoreRuntime({}, sthis);
|
215
|
-
for (const pstore of [strt.makeDataStore(loader), strt.makeMetaStore(loader), strt.makeWALStore(loader)]) {
|
195
|
+
const url = baseUrl.build().setParam(PARAM.STORE_KEY, "@heute@").URI();
|
196
|
+
const strt = bs.toStoreRuntime(sthis);
|
197
|
+
for (const pstore of [
|
198
|
+
strt.makeDataStore({ sthis, url, loader }),
|
199
|
+
strt.makeMetaStore({ sthis, url, loader }),
|
200
|
+
strt.makeWALStore({ sthis, url, loader }),
|
201
|
+
]) {
|
216
202
|
const store = await pstore;
|
217
203
|
// await store.start();
|
218
|
-
expect(store.url().getParam(
|
204
|
+
expect(store.url().getParam(PARAM.STORE_KEY)).toBe(`@heute@`);
|
219
205
|
const kc = await store.keyedCrypto();
|
220
206
|
expect(kc.constructor.name).toBe("keyedCrypto");
|
221
207
|
const testData = kb.rt.crypto.randomBytes(1024);
|
@@ -231,25 +217,17 @@ describe("KeyedCryptoStore", () => {
|
|
231
217
|
|
232
218
|
it("key", async () => {
|
233
219
|
const key = base58btc.encode(kb.rt.crypto.randomBytes(kb.rt.keyLength));
|
234
|
-
const
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
stores: {
|
243
|
-
base: BuildURI.from(baseUrl).setParam("storekey", key),
|
244
|
-
},
|
245
|
-
},
|
246
|
-
},
|
247
|
-
} as unknown as bs.Loadable;
|
248
|
-
const strt = bs.toStoreRuntime({}, sthis);
|
249
|
-
for (const pstore of [strt.makeDataStore(loader), strt.makeMetaStore(loader), strt.makeWALStore(loader)]) {
|
220
|
+
const strt = bs.toStoreRuntime(sthis);
|
221
|
+
const url = baseUrl.build().setParam(PARAM.STORE_KEY, key).URI();
|
222
|
+
for (const pstore of [
|
223
|
+
strt.makeDataStore({ sthis, url, loader }),
|
224
|
+
strt.makeMetaStore({ sthis, url, loader }),
|
225
|
+
strt.makeWALStore({ sthis, url, loader }),
|
226
|
+
]) {
|
227
|
+
// for (const pstore of [strt.makeDataStore(loader), strt.makeMetaStore(loader), strt.makeWALStore(loader)]) {
|
250
228
|
const store = await pstore;
|
251
229
|
// await store.start();
|
252
|
-
expect(store.url().getParam(
|
230
|
+
expect(store.url().getParam(PARAM.STORE_KEY)).toBe(key);
|
253
231
|
const kc = await store.keyedCrypto();
|
254
232
|
expect(kc.constructor.name).toBe("keyedCrypto");
|
255
233
|
const testData = kb.rt.crypto.randomBytes(1024);
|
@@ -268,14 +246,14 @@ describe("KeyedCrypto", () => {
|
|
268
246
|
let keyStr: string;
|
269
247
|
const sthis = ensureSuperThis();
|
270
248
|
beforeEach(async () => {
|
271
|
-
let url: URI;
|
272
|
-
if (runtimeFn().isBrowser) {
|
273
|
-
|
274
|
-
} else {
|
275
|
-
|
276
|
-
}
|
249
|
+
// let url: URI;
|
250
|
+
// if (runtimeFn().isBrowser) {
|
251
|
+
// url = URI.from("indexdb://fp-keybag");
|
252
|
+
// } else {
|
253
|
+
// url = URI.merge(`file://./dist/tests/key.bag`, sthis.env.get("FP_KEYBAG_URL"));
|
254
|
+
// }
|
277
255
|
kb = await rt.kb.getKeyBag(sthis, {
|
278
|
-
url,
|
256
|
+
// url,
|
279
257
|
});
|
280
258
|
keyStr = base58btc.encode(kb.rt.crypto.randomBytes(kb.rt.keyLength));
|
281
259
|
kycr = await rt.kc.keyedCryptoFactory(URI.from(`test://bla?storekey=${keyStr}`), kb, sthis);
|
@@ -309,26 +287,3 @@ describe("KeyedCrypto", () => {
|
|
309
287
|
expect(blk).toEqual(blk2);
|
310
288
|
});
|
311
289
|
});
|
312
|
-
|
313
|
-
// describe("KeyedCryptoStore RunLength", () => {
|
314
|
-
// const logger = MockLogger().logger;
|
315
|
-
// it("de/encode", () => {
|
316
|
-
// for (const data of [
|
317
|
-
// new Uint8Array(),
|
318
|
-
// new Uint8Array(10).fill(10),
|
319
|
-
// new Uint8Array(127).fill(127),
|
320
|
-
// new Uint8Array(128).fill(128),
|
321
|
-
// new Uint8Array(1024).fill(17),
|
322
|
-
// ]) {
|
323
|
-
// const res = rt.kc.encodeRunLength(data, logger);
|
324
|
-
// expect(res.length).toBeLessThanOrEqual(data.length + (data.length > 127 ? 4 : 1));
|
325
|
-
// for (let ofs = 0; ofs < 1024; ofs += 61) {
|
326
|
-
// const ofsRes = new Uint8Array([...new Uint8Array(ofs).fill(23), ...res]);
|
327
|
-
// const dec = rt.kc.decodeRunLength(ofsRes, ofs, logger);
|
328
|
-
// expect(dec.data).toEqual(data);
|
329
|
-
// expect(dec.data.length).toBe(data.length);
|
330
|
-
// expect(dec.next).toBe(ofs + data.length + (data.length > 127 ? 4 : 1));
|
331
|
-
// }
|
332
|
-
// }
|
333
|
-
// });
|
334
|
-
// });
|
@@ -4,16 +4,18 @@ import { BlockView } from "multiformats";
|
|
4
4
|
import { CID } from "multiformats/cid";
|
5
5
|
import { MemoryBlockstore } from "@fireproof/vendor/@web3-storage/pail/block";
|
6
6
|
import { CRDTMeta, IndexTransactionMeta, SuperThis, bs, ensureSuperThis, rt } from "@fireproof/core";
|
7
|
+
import { simpleBlockOpts } from "../helpers.js";
|
7
8
|
|
8
9
|
class MyMemoryBlockStore extends bs.EncryptedBlockstore {
|
9
10
|
readonly memblock = new MemoryBlockstore();
|
10
11
|
loader: bs.Loader;
|
11
12
|
constructor(sthis: SuperThis) {
|
12
|
-
const ebOpts =
|
13
|
-
|
14
|
-
|
13
|
+
const ebOpts = simpleBlockOpts(sthis, "MyMemoryBlockStore"); //, "MyMemoryBlockStore");
|
14
|
+
// const ebOpts = {
|
15
|
+
// name: "MyMemoryBlockStore",
|
16
|
+
// } as bs.BlockstoreOpts;
|
15
17
|
super(sthis, ebOpts);
|
16
|
-
this.loader = new bs.Loader(
|
18
|
+
this.loader = new bs.Loader(sthis, ebOpts);
|
17
19
|
}
|
18
20
|
ready(): Promise<void> {
|
19
21
|
return Promise.resolve();
|
@@ -62,7 +64,10 @@ describe("basic Loader simple", function () {
|
|
62
64
|
await sthis.start();
|
63
65
|
const mockM = new MyMemoryBlockStore(sthis);
|
64
66
|
t = new bs.CarTransaction(mockM as bs.EncryptedBlockstore);
|
65
|
-
loader = new bs.Loader(
|
67
|
+
loader = new bs.Loader(sthis, {
|
68
|
+
...simpleBlockOpts(sthis, testDbName),
|
69
|
+
public: true,
|
70
|
+
});
|
66
71
|
await loader.ready();
|
67
72
|
block = await rt.mf.block.encode({
|
68
73
|
value: { hello: "world" },
|
@@ -105,11 +110,15 @@ describe("basic Loader with two commits", function () {
|
|
105
110
|
await loader.destroy();
|
106
111
|
});
|
107
112
|
|
108
|
-
beforeEach(async
|
113
|
+
beforeEach(async () => {
|
109
114
|
await sthis.start();
|
110
115
|
const mockM = new MyMemoryBlockStore(sthis);
|
111
116
|
t = new bs.CarTransaction(mockM);
|
112
|
-
loader = new bs.Loader(
|
117
|
+
loader = new bs.Loader(sthis, {
|
118
|
+
...simpleBlockOpts(sthis, "test-loader-two-commit"),
|
119
|
+
public: true,
|
120
|
+
});
|
121
|
+
|
113
122
|
block = await rt.mf.block.encode({
|
114
123
|
value: { hello: "world" },
|
115
124
|
hasher,
|
@@ -211,7 +220,7 @@ describe("basic Loader with index commits", function () {
|
|
211
220
|
const name = "test-loader-index" + Math.random();
|
212
221
|
await sthis.start();
|
213
222
|
// t = new CarTransaction()
|
214
|
-
ib = new bs.EncryptedBlockstore(sthis,
|
223
|
+
ib = new bs.EncryptedBlockstore(sthis, simpleBlockOpts(sthis, name));
|
215
224
|
block = await rt.mf.block.encode({
|
216
225
|
value: { hello: "world" },
|
217
226
|
hasher,
|
@@ -255,7 +264,7 @@ describe("basic Loader with index commits", function () {
|
|
255
264
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
256
265
|
const reader = await ib.loader.loadCar(carCid![0]);
|
257
266
|
expect(reader).toBeTruthy();
|
258
|
-
const parsed = await bs.parseCarFile<IndexTransactionMeta>(reader,
|
267
|
+
const parsed = await bs.parseCarFile<IndexTransactionMeta>(reader, sthis.logger);
|
259
268
|
expect(parsed.cars).toBeTruthy();
|
260
269
|
expect(parsed.cars.length).toBe(0);
|
261
270
|
expect(parsed.meta).toBeTruthy();
|