@fireproof/core-test 0.23.0 → 0.23.1-dev-issue-1057
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/blockstore/interceptor-gateway.test.js.map +1 -1
- package/blockstore/keyed-crypto-indexeddb-file.test.js.map +1 -1
- package/blockstore/keyed-crypto.test.js.map +1 -1
- package/blockstore/loader.test.js.map +1 -1
- package/blockstore/standalone.test.js.map +1 -1
- package/blockstore/store.test.js.map +1 -1
- package/blockstore/transaction.test.js.map +1 -1
- package/fireproof/all-gateway.test.js.map +1 -1
- package/fireproof/attachable.test.js.map +1 -1
- package/fireproof/cars/bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i.js.map +1 -1
- package/fireproof/charwise-boolean.test.js.map +1 -1
- package/fireproof/compact-strategy.test.js.map +1 -1
- package/fireproof/concurrent.test.js.map +1 -1
- package/fireproof/crdt.test.js.map +1 -1
- package/fireproof/database.test.js.map +1 -1
- package/fireproof/deleted-docs-handling.test.js.map +1 -1
- package/fireproof/fireproof.test.fixture.js.map +1 -1
- package/fireproof/fireproof.test.js.map +1 -1
- package/fireproof/hello.test.js.map +1 -1
- package/fireproof/indexer.test.js.map +1 -1
- package/fireproof/multiple-ledger.test.js.map +1 -1
- package/fireproof/query-docs.test.js.map +1 -1
- package/fireproof/query-limit-issue.test.js.map +1 -1
- package/fireproof/query-property-inconsistency.test.js.map +1 -1
- package/fireproof/query-result-properties.test.js.map +1 -1
- package/fireproof/stable-cid.test.js.map +1 -1
- package/fireproof/utils.test.js.map +1 -1
- package/gateway/file/loader-config.test.js.map +1 -1
- package/gateway/indexeddb/create-db-on-write.test.js.map +1 -1
- package/gateway/indexeddb/loader-config.test.js.map +1 -1
- package/global-setup.js.map +1 -1
- package/helpers.js.map +1 -1
- package/package.json +19 -19
- package/protocols/cloud/msger.test.js.map +1 -1
- package/runtime/fp-envelope-serialize.test.js.map +1 -1
- package/runtime/key-bag.test.js.map +1 -1
- package/runtime/meta-key-hack.test.js.map +1 -1
- package/setup.file.js.map +1 -1
- package/setup.indexeddb.js.map +1 -1
- package/setup.memory.js.map +1 -1
- package/vitest.config.js.map +1 -1
- package/vitest.file.config.js.map +1 -1
- package/vitest.indexeddb.config.js.map +1 -1
- package/vitest.memory.config.js.map +1 -1
- package/blockstore/fp-envelope.test.ts-off +0 -65
- package/blockstore/fragment-gateway.test.ts-off +0 -106
- package/blockstore/interceptor-gateway.test.ts +0 -259
- package/blockstore/keyed-crypto-indexeddb-file.test.ts +0 -134
- package/blockstore/keyed-crypto.test.ts +0 -381
- package/blockstore/loader.test.ts +0 -313
- package/blockstore/standalone.test.ts +0 -156
- package/blockstore/store.test.ts +0 -199
- package/blockstore/transaction.test.ts +0 -132
- package/fireproof/all-gateway.test.ts +0 -477
- package/fireproof/attachable.test.ts +0 -677
- package/fireproof/cars/bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i.car +0 -0
- package/fireproof/cars/bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i.ts +0 -324
- package/fireproof/charwise-boolean.test.ts +0 -68
- package/fireproof/compact-strategy.test.ts +0 -40
- package/fireproof/concurrent.test.ts +0 -37
- package/fireproof/crdt.test.ts +0 -572
- package/fireproof/database.test.ts +0 -772
- package/fireproof/deleted-docs-handling.test.ts +0 -112
- package/fireproof/fireproof.test.fixture.ts +0 -133
- package/fireproof/fireproof.test.ts +0 -767
- package/fireproof/hello.test.ts +0 -75
- package/fireproof/indexer.test.ts +0 -459
- package/fireproof/multiple-ledger.test.ts +0 -67
- package/fireproof/query-docs.test.ts +0 -117
- package/fireproof/query-limit-issue.test.ts +0 -147
- package/fireproof/query-property-inconsistency.test.ts +0 -90
- package/fireproof/query-result-properties.test.ts +0 -43
- package/fireproof/stable-cid.test.ts +0 -72
- package/fireproof/utils.test.ts +0 -137
- package/gateway/file/loader-config.test.ts +0 -309
- package/gateway/indexeddb/create-db-on-write.test.ts +0 -202
- package/gateway/indexeddb/loader-config.test.ts +0 -80
- package/global-setup.ts +0 -11
- package/helpers.ts +0 -177
- package/protocols/cloud/msger.test.ts +0 -559
- package/runtime/fp-envelope-serialize.test.ts +0 -266
- package/runtime/key-bag.test.ts +0 -243
- package/runtime/meta-key-hack.test.ts +0 -103
- package/setup.file.ts +0 -1
- package/setup.indexeddb.ts +0 -0
- package/setup.memory.ts +0 -2
- package/tsconfig.json +0 -18
- package/vitest.config.ts +0 -8
- package/vitest.file.config.ts +0 -11
- package/vitest.indexeddb.config.ts +0 -34
- package/vitest.memory.config.ts +0 -24
|
@@ -1,259 +0,0 @@
|
|
|
1
|
-
import { BuildURI, Result, URI } from "@adviser/cement";
|
|
2
|
-
import { fireproof, SuperThis } from "@fireproof/core";
|
|
3
|
-
import * as bs from "@fireproof/core-types-blockstore";
|
|
4
|
-
import { describe, expect, it, vitest } from "vitest";
|
|
5
|
-
import { PassThroughGateway, URIInterceptor } from "@fireproof/core-gateways-base";
|
|
6
|
-
import { MemoryGateway } from "@fireproof/core-gateways-memory";
|
|
7
|
-
import { registerStoreProtocol } from "@fireproof/core-blockstore";
|
|
8
|
-
|
|
9
|
-
class TestInterceptor extends PassThroughGateway {
|
|
10
|
-
readonly fn = vitest.fn();
|
|
11
|
-
|
|
12
|
-
async buildUrl(ctx: bs.SerdeGatewayCtx, baseUrl: URI, key: string): Promise<Result<bs.SerdeGatewayBuildUrlReturn>> {
|
|
13
|
-
const ret = await super.buildUrl(ctx, baseUrl, key);
|
|
14
|
-
this.fn("buildUrl", ret);
|
|
15
|
-
return ret;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
async start(ctx: bs.SerdeGatewayCtx, baseUrl: URI): Promise<Result<bs.SerdeGatewayStartReturn>> {
|
|
19
|
-
const ret = await super.start(ctx, baseUrl);
|
|
20
|
-
this.fn("start", ret);
|
|
21
|
-
return ret;
|
|
22
|
-
}
|
|
23
|
-
async close(ctx: bs.SerdeGatewayCtx, baseUrl: URI): Promise<Result<bs.SerdeGatewayCloseReturn>> {
|
|
24
|
-
const ret = await super.close(ctx, baseUrl);
|
|
25
|
-
this.fn("close", ret);
|
|
26
|
-
return ret;
|
|
27
|
-
}
|
|
28
|
-
async delete(ctx: bs.SerdeGatewayCtx, baseUrl: URI): Promise<Result<bs.SerdeGatewayDeleteReturn>> {
|
|
29
|
-
const ret = await super.delete(ctx, baseUrl);
|
|
30
|
-
this.fn("delete", ret);
|
|
31
|
-
return ret;
|
|
32
|
-
}
|
|
33
|
-
async destroy(ctx: bs.SerdeGatewayCtx, baseUrl: URI): Promise<Result<bs.SerdeGatewayDestroyReturn>> {
|
|
34
|
-
const ret = await super.destroy(ctx, baseUrl);
|
|
35
|
-
this.fn("destroy", ret);
|
|
36
|
-
return ret;
|
|
37
|
-
}
|
|
38
|
-
async put<T>(ctx: bs.SerdeGatewayCtx, url: URI, body: bs.FPEnvelope<T>): Promise<Result<bs.SerdeGatewayPutReturn<T>>> {
|
|
39
|
-
const ret = await super.put<T>(ctx, url, body);
|
|
40
|
-
this.fn("put", ret);
|
|
41
|
-
return ret;
|
|
42
|
-
}
|
|
43
|
-
async get<S>(ctx: bs.SerdeGatewayCtx, url: URI): Promise<Result<bs.SerdeGatewayGetReturn<S>>> {
|
|
44
|
-
const ret = await super.get<S>(ctx, url);
|
|
45
|
-
this.fn("get", ret);
|
|
46
|
-
return ret;
|
|
47
|
-
}
|
|
48
|
-
async subscribe(
|
|
49
|
-
ctx: bs.SerdeGatewayCtx,
|
|
50
|
-
url: URI,
|
|
51
|
-
callback: (meta: bs.FPEnvelopeMeta) => Promise<void>,
|
|
52
|
-
): Promise<Result<bs.SerdeGatewaySubscribeReturn>> {
|
|
53
|
-
const ret = await super.subscribe(ctx, url, callback);
|
|
54
|
-
this.fn("subscribe", ret);
|
|
55
|
-
return ret;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export class URITrackGateway implements bs.Gateway {
|
|
60
|
-
readonly uris: Set<string>;
|
|
61
|
-
readonly memgw: MemoryGateway;
|
|
62
|
-
|
|
63
|
-
constructor(sthis: SuperThis, memorys: Map<string, Uint8Array>, uris: Set<string>) {
|
|
64
|
-
this.memgw = new MemoryGateway(sthis, memorys);
|
|
65
|
-
this.uris = uris;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
uriAdd(uri: URI) {
|
|
69
|
-
if (!uri.getParam("itis")) {
|
|
70
|
-
throw new Error("itis not set");
|
|
71
|
-
}
|
|
72
|
-
if (this.uris.has(uri.toString())) {
|
|
73
|
-
throw new Error(`uri already added:${uri.toString()}`);
|
|
74
|
-
}
|
|
75
|
-
this.uris.add(uri.toString());
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
buildUrl(baseUrl: URI, key: string): Promise<Result<URI>> {
|
|
79
|
-
this.uriAdd(baseUrl);
|
|
80
|
-
return this.memgw.buildUrl(baseUrl, key);
|
|
81
|
-
}
|
|
82
|
-
start(baseUrl: URI): Promise<Result<URI>> {
|
|
83
|
-
this.uriAdd(baseUrl);
|
|
84
|
-
return this.memgw.start(baseUrl);
|
|
85
|
-
}
|
|
86
|
-
close(uri: URI): Promise<bs.VoidResult> {
|
|
87
|
-
this.uriAdd(uri);
|
|
88
|
-
return this.memgw.close(uri);
|
|
89
|
-
}
|
|
90
|
-
destroy(baseUrl: URI): Promise<bs.VoidResult> {
|
|
91
|
-
this.uriAdd(baseUrl);
|
|
92
|
-
return this.memgw.destroy(baseUrl);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
put(url: URI, bytes: Uint8Array, sthis: SuperThis): Promise<bs.VoidResult> {
|
|
96
|
-
// console.log("put", url.getParam(PARAM.KEY), url.toString());
|
|
97
|
-
this.uriAdd(url);
|
|
98
|
-
return this.memgw.put(url.build().cleanParams("itis").URI(), bytes, sthis);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
async get(url: URI, sthis: SuperThis): Promise<bs.GetResult> {
|
|
102
|
-
this.uriAdd(url);
|
|
103
|
-
const ret = await this.memgw.get(url.build().cleanParams("itis").URI(), sthis);
|
|
104
|
-
// if (ret.isErr()) {
|
|
105
|
-
// console.log("get-err", url.getParam(PARAM.KEY), url.toString());
|
|
106
|
-
// }
|
|
107
|
-
return ret;
|
|
108
|
-
}
|
|
109
|
-
delete(url: URI): Promise<bs.VoidResult> {
|
|
110
|
-
this.uriAdd(url);
|
|
111
|
-
return this.memgw.delete(url);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
115
|
-
subscribe(url: URI, callback: (meta: Uint8Array) => void, sthis: SuperThis): Promise<bs.UnsubscribeResult> {
|
|
116
|
-
this.uriAdd(url);
|
|
117
|
-
return Promise.resolve(
|
|
118
|
-
Result.Ok(() => {
|
|
119
|
-
/* noop */
|
|
120
|
-
}),
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
async getPlain(url: URI, key: string): Promise<Result<Uint8Array>> {
|
|
125
|
-
this.uriAdd(url);
|
|
126
|
-
return this.memgw.getPlain(url, key);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
describe("InterceptorGateway", () => {
|
|
131
|
-
it("passthrough", async () => {
|
|
132
|
-
const gwi = new TestInterceptor();
|
|
133
|
-
const db = fireproof("interceptor-gateway", {
|
|
134
|
-
gatewayInterceptor: gwi,
|
|
135
|
-
});
|
|
136
|
-
expect(
|
|
137
|
-
await db.put({
|
|
138
|
-
_id: "foo",
|
|
139
|
-
foo: 4,
|
|
140
|
-
}),
|
|
141
|
-
);
|
|
142
|
-
expect(await db.get("foo")).toEqual({
|
|
143
|
-
_id: "foo",
|
|
144
|
-
foo: 4,
|
|
145
|
-
});
|
|
146
|
-
await db.close();
|
|
147
|
-
await db.destroy();
|
|
148
|
-
// await sleep(1000);
|
|
149
|
-
expect(gwi.fn.mock.calls.length).toBe(54);
|
|
150
|
-
// might be a stupid test
|
|
151
|
-
expect(gwi.fn.mock.calls.map((i) => i[0]).sort() /* not ok there are some operation */).toEqual(
|
|
152
|
-
[
|
|
153
|
-
"start",
|
|
154
|
-
"start",
|
|
155
|
-
"buildUrl",
|
|
156
|
-
"get",
|
|
157
|
-
"buildUrl",
|
|
158
|
-
"buildUrl",
|
|
159
|
-
"buildUrl",
|
|
160
|
-
"buildUrl",
|
|
161
|
-
"buildUrl",
|
|
162
|
-
"buildUrl",
|
|
163
|
-
"buildUrl",
|
|
164
|
-
"buildUrl",
|
|
165
|
-
"get",
|
|
166
|
-
"get",
|
|
167
|
-
"start",
|
|
168
|
-
"start",
|
|
169
|
-
"buildUrl",
|
|
170
|
-
"get",
|
|
171
|
-
"get",
|
|
172
|
-
"buildUrl",
|
|
173
|
-
"put",
|
|
174
|
-
"put",
|
|
175
|
-
"buildUrl",
|
|
176
|
-
"put",
|
|
177
|
-
"buildUrl",
|
|
178
|
-
"put",
|
|
179
|
-
"put",
|
|
180
|
-
"put",
|
|
181
|
-
"put",
|
|
182
|
-
"put",
|
|
183
|
-
"start",
|
|
184
|
-
"start",
|
|
185
|
-
"start",
|
|
186
|
-
"start",
|
|
187
|
-
"close",
|
|
188
|
-
"close",
|
|
189
|
-
"close",
|
|
190
|
-
"close",
|
|
191
|
-
"buildUrl",
|
|
192
|
-
"get",
|
|
193
|
-
"close",
|
|
194
|
-
"close",
|
|
195
|
-
"close",
|
|
196
|
-
"close",
|
|
197
|
-
"destroy",
|
|
198
|
-
"destroy",
|
|
199
|
-
"destroy",
|
|
200
|
-
"destroy",
|
|
201
|
-
"destroy",
|
|
202
|
-
"destroy",
|
|
203
|
-
"destroy",
|
|
204
|
-
"destroy",
|
|
205
|
-
"subscribe",
|
|
206
|
-
"subscribe",
|
|
207
|
-
].sort() /* not ok there are some operation */,
|
|
208
|
-
);
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
it("use the uri-interceptor", async () => {
|
|
212
|
-
let callCount = 0;
|
|
213
|
-
const gwUris = new Set<string>();
|
|
214
|
-
const unreg = registerStoreProtocol({
|
|
215
|
-
protocol: "uriTest:",
|
|
216
|
-
isDefault: false,
|
|
217
|
-
defaultURI: () => {
|
|
218
|
-
return BuildURI.from("uriTest://").pathname("ram").URI();
|
|
219
|
-
},
|
|
220
|
-
gateway: async (sthis) => {
|
|
221
|
-
return new URITrackGateway(sthis, new Map<string, Uint8Array>(), gwUris);
|
|
222
|
-
},
|
|
223
|
-
});
|
|
224
|
-
const db = fireproof("interceptor-gateway", {
|
|
225
|
-
storeUrls: {
|
|
226
|
-
base: "uriTest://inspector-gateway",
|
|
227
|
-
},
|
|
228
|
-
gatewayInterceptor: URIInterceptor.withMapper(async (uri: URI) =>
|
|
229
|
-
uri
|
|
230
|
-
.build()
|
|
231
|
-
.setParam("itis", "" + ++callCount)
|
|
232
|
-
.URI(),
|
|
233
|
-
),
|
|
234
|
-
});
|
|
235
|
-
await Promise.all(
|
|
236
|
-
Array(5)
|
|
237
|
-
.fill(0)
|
|
238
|
-
.map((_, i) => db.put({ _id: "foo" + i, foo: i })),
|
|
239
|
-
);
|
|
240
|
-
expect((await db.allDocs<{ foo: number }>()).rows.map((i) => i.value.foo)).toEqual(
|
|
241
|
-
Array(5)
|
|
242
|
-
.fill(0)
|
|
243
|
-
.map((_, i) => i),
|
|
244
|
-
);
|
|
245
|
-
await db.close();
|
|
246
|
-
expect(callCount).toBe(gwUris.size);
|
|
247
|
-
expect(
|
|
248
|
-
Array.from(gwUris)
|
|
249
|
-
.map((i) => URI.from(i).getParam("itis"))
|
|
250
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
251
|
-
.sort((a, b) => +a! - +b!),
|
|
252
|
-
).toEqual(
|
|
253
|
-
Array(gwUris.size)
|
|
254
|
-
.fill(1)
|
|
255
|
-
.map((_, i) => "" + (i + 1)),
|
|
256
|
-
);
|
|
257
|
-
unreg();
|
|
258
|
-
});
|
|
259
|
-
});
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import { runtimeFn, toCryptoRuntime, URI } from "@adviser/cement";
|
|
2
|
-
import { base58btc } from "multiformats/bases/base58";
|
|
3
|
-
import { mockLoader, mockSuperThis } from "../helpers.js";
|
|
4
|
-
import { ensureSuperThis } from "@fireproof/core-runtime";
|
|
5
|
-
import { V2KeysItem, PARAM } from "@fireproof/core-types-base";
|
|
6
|
-
import { describe, beforeAll, it, expect, beforeEach } from "vitest";
|
|
7
|
-
import { coerceMaterial, getKeyBag, toKeyWithFingerPrint } from "@fireproof/core-keybag";
|
|
8
|
-
import { KeyBagProviderIndexedDB } from "@fireproof/core-gateways-indexeddb";
|
|
9
|
-
import { KeyBagProviderFile } from "@fireproof/core-gateways-file";
|
|
10
|
-
import { KeyWithFingerPrint, Loadable } from "@fireproof/core-types-blockstore";
|
|
11
|
-
import { createAttachedStores } from "@fireproof/core-blockstore";
|
|
12
|
-
|
|
13
|
-
describe("KeyBag indexeddb and file", () => {
|
|
14
|
-
let url: URI;
|
|
15
|
-
const sthis = mockSuperThis();
|
|
16
|
-
beforeAll(async () => {
|
|
17
|
-
await sthis.start();
|
|
18
|
-
if (runtimeFn().isBrowser) {
|
|
19
|
-
url = URI.from("indexeddb://fp-keybag");
|
|
20
|
-
} else {
|
|
21
|
-
url = URI.merge(`file://./dist/tests/key.bag`, sthis.env.get("FP_KEYBAG_URL"));
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
it("default-path", async () => {
|
|
25
|
-
const old = sthis.env.get("FP_KEYBAG_URL");
|
|
26
|
-
sthis.env.delete("FP_KEYBAG_URL");
|
|
27
|
-
const kb = await getKeyBag(sthis);
|
|
28
|
-
if (runtimeFn().isBrowser) {
|
|
29
|
-
expect(kb.rt.url.toString()).toBe(`indexeddb://fp-keybag`);
|
|
30
|
-
} else {
|
|
31
|
-
expect(kb.rt.url.toString()).toBe(`file://${sthis.env.get("HOME")}/.fireproof/keybag`);
|
|
32
|
-
}
|
|
33
|
-
sthis.env.set("FP_KEYBAG_URL", old);
|
|
34
|
-
});
|
|
35
|
-
it("from env", async () => {
|
|
36
|
-
const old = sthis.env.get("FP_KEYBAG_URL");
|
|
37
|
-
sthis.env.set("FP_KEYBAG_URL", url.toString());
|
|
38
|
-
const kb = await getKeyBag(sthis);
|
|
39
|
-
expect(kb.rt.url.toString()).toBe(url.toString());
|
|
40
|
-
sthis.env.set("FP_KEYBAG_URL", old);
|
|
41
|
-
});
|
|
42
|
-
it("simple add", async () => {
|
|
43
|
-
const kb = await getKeyBag(sthis, {
|
|
44
|
-
url: url.toString(),
|
|
45
|
-
crypto: toCryptoRuntime({
|
|
46
|
-
randomBytes: (size) => new Uint8Array(size).map((_, i) => i),
|
|
47
|
-
}),
|
|
48
|
-
});
|
|
49
|
-
const name = "setkey" + Math.random();
|
|
50
|
-
expect((await kb.getNamedKey(name, true)).isErr()).toBeTruthy();
|
|
51
|
-
|
|
52
|
-
const key = base58btc.encode(kb.rt.crypto.randomBytes(kb.rt.keyLength));
|
|
53
|
-
const res = await kb.getNamedKey(name, false, key);
|
|
54
|
-
expect(res.isOk()).toBeTruthy();
|
|
55
|
-
expect((await kb.getNamedKey(name, true)).Ok()).toEqual(res.Ok());
|
|
56
|
-
|
|
57
|
-
const name2 = "implicit" + Math.random();
|
|
58
|
-
const created = await kb.getNamedKey(name2);
|
|
59
|
-
expect(created.isOk()).toBeTruthy();
|
|
60
|
-
|
|
61
|
-
expect((await kb.getNamedKey(name2)).Ok()).toEqual(created.Ok());
|
|
62
|
-
|
|
63
|
-
let diskBag: V2KeysItem;
|
|
64
|
-
let diskBag2: V2KeysItem;
|
|
65
|
-
const provider = await kb.rt.getBagProvider();
|
|
66
|
-
if (runtimeFn().isBrowser) {
|
|
67
|
-
const p = provider as KeyBagProviderIndexedDB;
|
|
68
|
-
diskBag = await p._prepare().then((db) => db.get("bag", name));
|
|
69
|
-
diskBag2 = await p._prepare().then((db) => db.get("bag", name2));
|
|
70
|
-
} else {
|
|
71
|
-
const p = provider as KeyBagProviderFile;
|
|
72
|
-
const { sysFS } = await p._prepare(name);
|
|
73
|
-
|
|
74
|
-
diskBag = await sysFS.readfile((await p._prepare(name)).fName).then((data) => {
|
|
75
|
-
return JSON.parse(sthis.txt.decode(data)) as V2KeysItem;
|
|
76
|
-
});
|
|
77
|
-
diskBag2 = await sysFS.readfile((await p._prepare(name2)).fName).then((data) => {
|
|
78
|
-
return JSON.parse(sthis.txt.decode(data)) as V2KeysItem;
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
expect((await toKeyWithFingerPrint(kb, coerceMaterial(kb, Object.values(diskBag.keys)[0].key), true)).Ok().fingerPrint).toEqual(
|
|
82
|
-
(await res.Ok().get())?.fingerPrint,
|
|
83
|
-
);
|
|
84
|
-
expect(
|
|
85
|
-
(await toKeyWithFingerPrint(kb, coerceMaterial(kb, Object.values(diskBag2.keys)[0].key), true)).Ok().fingerPrint,
|
|
86
|
-
).toEqual((await created.Ok().get())?.fingerPrint);
|
|
87
|
-
const algo = {
|
|
88
|
-
name: "AES-GCM",
|
|
89
|
-
iv: kb.rt.crypto.randomBytes(12),
|
|
90
|
-
tagLength: 128,
|
|
91
|
-
};
|
|
92
|
-
const data = kb.rt.crypto.randomBytes(122);
|
|
93
|
-
const rkc = (await res.Ok().get()) as KeyWithFingerPrint;
|
|
94
|
-
const ckc = (await created.Ok().get()) as KeyWithFingerPrint;
|
|
95
|
-
expect(await kb.rt.crypto.encrypt(algo, rkc.key, data)).toEqual(await kb.rt.crypto.encrypt(algo, ckc.key, data));
|
|
96
|
-
expect(await kb.rt.crypto.encrypt(algo, await kb.subtleKey(Object.values(diskBag.keys)[0].key), data)).toEqual(
|
|
97
|
-
await kb.rt.crypto.encrypt(algo, ckc.key, data),
|
|
98
|
-
);
|
|
99
|
-
expect(await kb.rt.crypto.encrypt(algo, await kb.subtleKey(Object.values(diskBag2.keys)[0].key), data)).toEqual(
|
|
100
|
-
await kb.rt.crypto.encrypt(algo, ckc.key, data),
|
|
101
|
-
);
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
describe("KeyedCryptoStore", () => {
|
|
106
|
-
let loader: Loadable;
|
|
107
|
-
// let logger: Logger;
|
|
108
|
-
let baseUrl: URI;
|
|
109
|
-
const sthis = ensureSuperThis();
|
|
110
|
-
beforeEach(async () => {
|
|
111
|
-
await sthis.start();
|
|
112
|
-
// logger = MockLogger().logger;
|
|
113
|
-
// let kbUrl: URI;
|
|
114
|
-
if (runtimeFn().isBrowser) {
|
|
115
|
-
// kbUrl = URI.from("indexeddb://fp-keybag");
|
|
116
|
-
baseUrl = URI.from("indexeddb://fp-keyed-crypto-store");
|
|
117
|
-
} else {
|
|
118
|
-
// kbUrl = URI.merge(`file://./dist/tests/key.bag`, sthis.env.get("FP_KEYBAG_URL"));
|
|
119
|
-
baseUrl = URI.merge("file://./dist/tests/keyed-crypto-store", sthis.env.get("FP_STORAGE_URL"));
|
|
120
|
-
}
|
|
121
|
-
baseUrl = baseUrl.build().defParam(PARAM.NAME, "test").URI();
|
|
122
|
-
loader = mockLoader(sthis);
|
|
123
|
-
});
|
|
124
|
-
it("no crypto", async () => {
|
|
125
|
-
const url = baseUrl.build().setParam(PARAM.STORE_KEY, "insecure").URI();
|
|
126
|
-
for (const pstore of (await createAttachedStores(url, loader, "insecure")).stores.baseStores) {
|
|
127
|
-
const store = await pstore;
|
|
128
|
-
// await store.start();
|
|
129
|
-
const kc = await store.keyedCrypto();
|
|
130
|
-
expect(kc.constructor.name).toBe("noCrypto");
|
|
131
|
-
// expect(kc.isEncrypting).toBe(false);
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
});
|