@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.
@@ -5,6 +5,8 @@ import { sha256 as hasher } from "multiformats/hashes/sha2";
5
5
  import * as dagCodec from "@ipld/dag-cbor";
6
6
  import type { KeyBagProviderIndexedDB } from "@fireproof/core/indexeddb";
7
7
  import { MockSuperThis, mockSuperThis } from "../helpers.js";
8
+ import { KeyWithFingerPrint } from "../../src/blockstore/types.js";
9
+ import { toKeyWithFingerPrint } from "../../src/runtime/key-bag.js";
8
10
 
9
11
  describe("KeyBag", () => {
10
12
  let url: URI;
@@ -45,11 +47,19 @@ describe("KeyBag", () => {
45
47
  const kb = await rt.kb.getKeyBag(sthis);
46
48
  const key = kb.rt.crypto.randomBytes(kb.rt.keyLength);
47
49
  const keyStr = base58btc.encode(key);
48
- const res = await kb.setNamedKey("extract.test", keyStr);
50
+ const keyName = "extract.test" + Math.random();
51
+ const res = await kb.getNamedKey(keyName, false, keyStr);
49
52
  expect(res.isOk()).toBeTruthy();
50
- const gkb = await kb.getNamedExtractableKey("extract.test", true);
53
+ const gkb = await kb.getNamedKey(keyName, true);
51
54
  expect(gkb.isOk()).toBeTruthy();
52
- expect(await gkb.Ok().extract()).toEqual({
55
+
56
+ expect(
57
+ await gkb
58
+ .Ok()
59
+ .get()
60
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
61
+ .then((i) => i!.extract()),
62
+ ).toEqual({
53
63
  key,
54
64
  keyStr,
55
65
  });
@@ -67,26 +77,23 @@ describe("KeyBag", () => {
67
77
  it("simple add", async () => {
68
78
  const kb = await rt.kb.getKeyBag(sthis, {
69
79
  url: url.toString(),
70
- crypto: toCryptoRuntime({
71
- randomBytes: (size) => new Uint8Array(size).map((_, i) => i),
72
- }),
73
80
  });
74
81
  const name = "setkey" + Math.random();
75
82
  expect((await kb.getNamedKey(name, true)).isErr()).toBeTruthy();
76
83
 
77
84
  const key = base58btc.encode(kb.rt.crypto.randomBytes(kb.rt.keyLength));
78
- const res = await kb.setNamedKey(name, key);
85
+ const res = await kb.getNamedKey(name, false, key);
79
86
  expect(res.isOk()).toBeTruthy();
80
87
  expect((await kb.getNamedKey(name, true)).Ok()).toEqual(res.Ok());
81
88
 
82
- const name2 = "implicit";
89
+ const name2 = "implicit" + Math.random();
83
90
  const created = await kb.getNamedKey(name2);
84
91
  expect(created.isOk()).toBeTruthy();
85
92
 
86
93
  expect((await kb.getNamedKey(name2)).Ok()).toEqual(created.Ok());
87
94
 
88
- let diskBag: rt.kb.KeyItem;
89
- let diskBag2: rt.kb.KeyItem;
95
+ let diskBag: rt.kb.KeysItem;
96
+ let diskBag2: rt.kb.KeysItem;
90
97
  const provider = await kb.rt.getBagProvider();
91
98
  if (runtimeFn().isBrowser) {
92
99
  const p = provider as KeyBagProviderIndexedDB;
@@ -100,28 +107,126 @@ describe("KeyBag", () => {
100
107
  const { sysFS } = await p._prepare(name);
101
108
 
102
109
  diskBag = await sysFS.readfile((await p._prepare(name)).fName).then((data) => {
103
- return JSON.parse(sthis.txt.decode(data)) as rt.kb.KeyItem;
110
+ return JSON.parse(sthis.txt.decode(data)) as rt.kb.KeysItem;
104
111
  });
105
112
  diskBag2 = await sysFS.readfile((await p._prepare(name2)).fName).then((data) => {
106
- return JSON.parse(sthis.txt.decode(data)) as rt.kb.KeyItem;
113
+ return JSON.parse(sthis.txt.decode(data)) as rt.kb.KeysItem;
107
114
  });
108
115
  }
109
- expect(await kb.toKeyWithFingerPrint(diskBag.key)).toEqual(res);
110
- expect(await kb.toKeyWithFingerPrint(diskBag2.key)).toEqual(created);
116
+ expect((await toKeyWithFingerPrint(kb, Object.values(diskBag.keys)[0].key)).Ok().fingerPrint).toEqual(
117
+ (await res.Ok().get())?.fingerPrint,
118
+ );
119
+ expect((await toKeyWithFingerPrint(kb, Object.values(diskBag2.keys)[0].key)).Ok().fingerPrint).toEqual(
120
+ (await created.Ok().get())?.fingerPrint,
121
+ );
111
122
  const algo = {
112
123
  name: "AES-GCM",
113
124
  iv: kb.rt.crypto.randomBytes(12),
114
125
  tagLength: 128,
115
126
  };
116
127
  const data = kb.rt.crypto.randomBytes(122);
117
- expect(await kb.rt.crypto.encrypt(algo, res.Ok().key, data)).toEqual(await kb.rt.crypto.encrypt(algo, created.Ok().key, data));
118
- expect(await kb.rt.crypto.encrypt(algo, await kb.subtleKey(diskBag.key), data)).toEqual(
119
- await kb.rt.crypto.encrypt(algo, created.Ok().key, data),
128
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
129
+ expect(await kb.rt.crypto.encrypt(algo, (await res.Ok().get())!.key, data))
130
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
131
+ .toEqual(await kb.rt.crypto.encrypt(algo, (await created.Ok().get())!.key, data));
132
+ const kf = (await created.Ok().get()) as KeyWithFingerPrint;
133
+ expect(await kb.rt.crypto.encrypt(algo, await kb.subtleKey(Object.values(diskBag.keys)[0].key), data)).toEqual(
134
+ await kb.rt.crypto.encrypt(algo, kf.key, data),
120
135
  );
121
- expect(await kb.rt.crypto.encrypt(algo, await kb.subtleKey(diskBag2.key), data)).toEqual(
122
- await kb.rt.crypto.encrypt(algo, created.Ok().key, data),
136
+ expect(await kb.rt.crypto.encrypt(algo, await kb.subtleKey(Object.values(diskBag2.keys)[0].key), data)).toEqual(
137
+ await kb.rt.crypto.encrypt(algo, kf.key, data),
123
138
  );
124
139
  });
140
+
141
+ it("default key", async () => {
142
+ const kb = await rt.kb.getKeyBag(sthis, {
143
+ url: url.build().setParam("extractKey", "_deprecated_internal_api"),
144
+ });
145
+ const name = "default-key" + Math.random();
146
+ const rMyKey = await kb.getNamedKey(name);
147
+
148
+ for (let i = 0; i < 10; ++i) {
149
+ expect(await kb.getNamedKey(name).then((i) => i.Ok().id)).toEqual(rMyKey.Ok().id);
150
+ }
151
+ expect(Object.keys((await kb.getNamedKey(name).then((i) => i.Ok().asKeysItem())).keys).length).toBe(1);
152
+
153
+ const myKey = (await rMyKey.Ok().get()) as KeyWithFingerPrint;
154
+ expect(myKey.fingerPrint).toMatch(/^z/);
155
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
156
+ await rMyKey.Ok().upsert((await myKey.extract())!.key);
157
+ const myKey1 = (await rMyKey.Ok().get()) as KeyWithFingerPrint;
158
+ expect(myKey.fingerPrint).toEqual(myKey1.fingerPrint);
159
+
160
+ expect(Object.keys((await kb.getNamedKey(name).then((i) => i.Ok().asKeysItem())).keys).length).toBe(1);
161
+
162
+ const rMyKey1 = await kb.getNamedKey(name);
163
+ expect(rMyKey1.Ok()).toEqual(rMyKey.Ok());
164
+ const res1 = await rMyKey1.Ok().upsert(kb.rt.crypto.randomBytes(kb.rt.keyLength));
165
+ expect(res1.isOk()).toBeTruthy();
166
+
167
+ const myKey2 = (await rMyKey1.Ok().get()) as KeyWithFingerPrint;
168
+ expect(myKey.fingerPrint).toEqual(myKey2.fingerPrint);
169
+ expect(Object.keys((await kb.getNamedKey(name).then((i) => i.Ok().asKeysItem())).keys).length).toBe(2);
170
+
171
+ const res = await rMyKey1.Ok().upsert(kb.rt.crypto.randomBytes(kb.rt.keyLength), true);
172
+ expect(res.isOk()).toBeTruthy();
173
+ const myKey3 = (await rMyKey.Ok().get()) as KeyWithFingerPrint;
174
+ expect(Object.keys((await kb.getNamedKey(name).then((i) => i.Ok().asKeysItem())).keys).length).toBe(3);
175
+
176
+ expect(myKey.fingerPrint).not.toEqual(myKey3.fingerPrint);
177
+ });
178
+
179
+ it("default and multiple fingerprints", async () => {
180
+ const kb = await rt.kb.getKeyBag(sthis, {
181
+ url: url.toString(),
182
+ crypto: toCryptoRuntime({
183
+ randomBytes: (size) => new Uint8Array(size).map((_, i) => i),
184
+ }),
185
+ });
186
+ const key = base58btc.encode(kb.rt.crypto.randomBytes(kb.rt.keyLength));
187
+ const name = "default-key" + Math.random();
188
+ const fpr = (await toKeyWithFingerPrint(kb, key)).Ok().fingerPrint;
189
+ const rMyKey = await kb.getNamedKey(name, false, key);
190
+ expect(rMyKey.isOk()).toBeTruthy();
191
+ const myKey = rMyKey.Ok();
192
+
193
+ const rUpsert1 = await myKey.upsert(key, true);
194
+ expect(rUpsert1.Ok().modified).toBeFalsy();
195
+
196
+ expect((await myKey.get())?.fingerPrint).toEqual(fpr);
197
+ expect((await myKey.get(fpr))?.fingerPrint).toEqual(fpr);
198
+
199
+ const keys = [{ key, fpr }];
200
+ for (let i = 0; i < 10; ++i) {
201
+ const key = base58btc.encode(kb.rt.crypto.randomBytes(kb.rt.keyLength));
202
+ const fpr = (await toKeyWithFingerPrint(kb, key)).Ok().fingerPrint;
203
+ keys.push({ key, fpr });
204
+ const rUpsert = await myKey.upsert(key, true);
205
+ expect(rUpsert.Ok().modified).toBeTruthy();
206
+ for (const { fpr } of keys) {
207
+ expect((await myKey.get(fpr))?.fingerPrint).toEqual(fpr);
208
+ }
209
+ expect((await myKey.get())?.fingerPrint).toEqual(fpr);
210
+ }
211
+ await kb.flush();
212
+ const provider = await kb.rt.getBagProvider();
213
+ let diskBag: rt.kb.KeysItem;
214
+ if (!("_prepare" in provider)) {
215
+ diskBag = (await provider.get(name)) as rt.kb.KeysItem;
216
+ } else {
217
+ if (runtimeFn().isBrowser) {
218
+ const p = provider as KeyBagProviderIndexedDB;
219
+ diskBag = await p._prepare().then((db) => db.get("bag", name));
220
+ } else {
221
+ const p = provider as rt.gw.file.KeyBagProviderFile;
222
+ const { sysFS } = await p._prepare(name);
223
+ diskBag = await sysFS.readfile((await p._prepare(name)).fName).then((data) => {
224
+ return JSON.parse(sthis.txt.decode(data)) as rt.kb.KeysItem;
225
+ });
226
+ }
227
+ }
228
+ expect(Object.values(diskBag.keys).length).toEqual(keys.length);
229
+ });
125
230
  });
126
231
 
127
232
  describe("KeyedCryptoStore", () => {
@@ -184,7 +289,7 @@ describe("KeyedCryptoStore", () => {
184
289
  ]) {
185
290
  const store = await pstore; // await bs.ensureStart(await pstore, logger);
186
291
  const kc = await store.keyedCrypto();
187
- expect(kc.constructor.name).toBe("keyedCrypto");
292
+ expect(kc.constructor.name).toBe("cryptoAction");
188
293
  // expect(kc.isEncrypting).toBe(true);
189
294
  expect(store.url().getParam(PARAM.STORE_KEY)).toBe(`@test:${store.url().getParam(PARAM.STORE)}@`);
190
295
  }
@@ -192,7 +297,7 @@ describe("KeyedCryptoStore", () => {
192
297
 
193
298
  it("key ref keybag", async () => {
194
299
  const key = base58btc.encode(kb.rt.crypto.randomBytes(kb.rt.keyLength));
195
- const genKey = await kb.setNamedKey("@heute@", key);
300
+ const genKey = await kb.getNamedKey("@heute@", false, key);
196
301
  const url = baseUrl.build().setParam(PARAM.STORE_KEY, "@heute@").URI();
197
302
  const strt = bs.toStoreRuntime(sthis);
198
303
  for (const pstore of [
@@ -204,13 +309,14 @@ describe("KeyedCryptoStore", () => {
204
309
  // await store.start();
205
310
  expect(store.url().getParam(PARAM.STORE_KEY)).toBe(`@heute@`);
206
311
  const kc = await store.keyedCrypto();
207
- expect(kc.constructor.name).toBe("keyedCrypto");
312
+ expect(kc.constructor.name).toBe("cryptoAction");
208
313
  const testData = kb.rt.crypto.randomBytes(1024);
209
314
  const iv = kb.rt.crypto.randomBytes(12);
210
- const blk = await kc._encrypt({ bytes: testData, iv });
315
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
316
+ const blk = await kc._encrypt({ bytes: testData, key: (await kc.key.get())!.key, iv });
211
317
  expect(blk).not.toEqual(testData);
212
- const fpkey = genKey.Ok();
213
- expect(fpkey.fingerPrint).toEqual(await kc.fingerPrint());
318
+ const fpkey = (await genKey.Ok().get()) as KeyWithFingerPrint;
319
+ expect(fpkey.fingerPrint).toEqual(fpkey.fingerPrint);
214
320
  const dec = new Uint8Array(await kc.crypto.decrypt(kc.algo(iv), fpkey.key, blk));
215
321
  expect(dec).toEqual(testData);
216
322
  }
@@ -230,12 +336,13 @@ describe("KeyedCryptoStore", () => {
230
336
  // await store.start();
231
337
  expect(store.url().getParam(PARAM.STORE_KEY)).toBe(key);
232
338
  const kc = await store.keyedCrypto();
233
- expect(kc.constructor.name).toBe("keyedCrypto");
339
+ expect(kc.constructor.name).toBe("cryptoAction");
234
340
  const testData = kb.rt.crypto.randomBytes(1024);
235
341
  const iv = kb.rt.crypto.randomBytes(12);
236
- const blk = await kc._encrypt({ bytes: testData, iv });
342
+ const ks = (await kc.key.get()) as KeyWithFingerPrint;
343
+ const blk = await kc._encrypt({ bytes: testData, key: ks.key, iv });
237
344
  expect(blk).not.toEqual(testData);
238
- const dec = await kc._decrypt({ bytes: blk, iv });
345
+ const dec = await kc._decrypt({ bytes: blk, key: ks.key, iv });
239
346
  expect(dec).toEqual(testData);
240
347
  }
241
348
  });
@@ -243,7 +350,7 @@ describe("KeyedCryptoStore", () => {
243
350
 
244
351
  describe("KeyedCrypto", () => {
245
352
  let kb: rt.kb.KeyBag;
246
- let kycr: bs.KeyedCrypto;
353
+ let kycr: bs.CryptoAction;
247
354
  let keyStr: string;
248
355
  const sthis = ensureSuperThis();
249
356
  beforeEach(async () => {
@@ -266,7 +373,8 @@ describe("KeyedCrypto", () => {
266
373
  const blk = (await codec.encode(testData)) as Uint8Array;
267
374
  const myDec = await rt.mf.block.decode<bs.IvKeyIdData, number, number>({ bytes: blk, hasher, codec: dagCodec });
268
375
  expect(myDec.value.iv).toEqual(iv);
269
- expect(base58btc.encode(myDec.value.keyId)).toEqual(await kycr.fingerPrint());
376
+ const kc = (await kycr.key.get()) as KeyWithFingerPrint;
377
+ expect(base58btc.encode(myDec.value.keyId)).toEqual(kc.fingerPrint);
270
378
  const dec = await codec.decode(blk);
271
379
  expect(dec).toEqual(testData);
272
380
  });
@@ -127,7 +127,7 @@ describe("noop Gateway", function () {
127
127
  const carUrl = await carGateway.buildUrl(ctx, carStore.url(), fileContent.cid);
128
128
  await carGateway.start(ctx, carStore.url());
129
129
  const carPutResult = await carGateway.put(ctx, carUrl.Ok(), {
130
- type: bs.FPEnvelopeType.CAR,
130
+ type: bs.FPEnvelopeTypes.CAR,
131
131
  payload: fileContent.block,
132
132
  });
133
133
  expect(carPutResult.isOk()).toBeTruthy();
@@ -137,7 +137,7 @@ describe("noop Gateway", function () {
137
137
  const carUrl = await carGateway.buildUrl(ctx, carStore.url(), fileContent.cid);
138
138
  await carGateway.start(ctx, carStore.url());
139
139
  await carGateway.put(ctx, carUrl.Ok(), {
140
- type: bs.FPEnvelopeType.CAR,
140
+ type: bs.FPEnvelopeTypes.CAR,
141
141
  payload: fileContent.block,
142
142
  });
143
143
  const carGetResult = await carGateway.get(ctx, carUrl.Ok());
@@ -150,7 +150,7 @@ describe("noop Gateway", function () {
150
150
  const carUrl = await carGateway.buildUrl(ctx, carStore.url(), fileContent.cid);
151
151
  await carGateway.start(ctx, carStore.url());
152
152
  await carGateway.put(ctx, carUrl.Ok(), {
153
- type: bs.FPEnvelopeType.CAR,
153
+ type: bs.FPEnvelopeTypes.CAR,
154
154
  payload: fileContent.block,
155
155
  });
156
156
  const carDeleteResult = await carGateway.delete(ctx, carUrl.Ok());
@@ -187,7 +187,7 @@ describe("noop Gateway", function () {
187
187
  const fileUrl = await fileGateway.buildUrl(ctx, fileStore.url(), fileContent.cid);
188
188
  await fileGateway.start(ctx, fileStore.url());
189
189
  const filePutResult = await fileGateway.put(ctx, fileUrl.Ok(), {
190
- type: bs.FPEnvelopeType.FILE,
190
+ type: bs.FPEnvelopeTypes.FILE,
191
191
  payload: fileContent.block,
192
192
  });
193
193
  expect(filePutResult.Ok()).toBeFalsy();
@@ -197,7 +197,7 @@ describe("noop Gateway", function () {
197
197
  const fileUrl = await fileGateway.buildUrl(ctx, fileStore.url(), fileContent.cid);
198
198
  await fileGateway.start(ctx, fileStore.url());
199
199
  await fileGateway.put(ctx, fileUrl.Ok(), {
200
- type: bs.FPEnvelopeType.FILE,
200
+ type: bs.FPEnvelopeTypes.FILE,
201
201
  payload: fileContent.block,
202
202
  });
203
203
  const fileGetResult = await fileGateway.get(ctx, fileUrl.Ok());
@@ -209,7 +209,7 @@ describe("noop Gateway", function () {
209
209
  const fileUrl = await fileGateway.buildUrl(ctx, fileStore.url(), fileContent.cid);
210
210
  await fileGateway.start(ctx, fileStore.url());
211
211
  await fileGateway.put(ctx, fileUrl.Ok(), {
212
- type: bs.FPEnvelopeType.FILE,
212
+ type: bs.FPEnvelopeTypes.FILE,
213
213
  payload: fileContent.block,
214
214
  });
215
215
  const fileDeleteResult = await fileGateway.delete(ctx, fileUrl.Ok());
@@ -236,7 +236,7 @@ describe("noop Gateway", function () {
236
236
  // const walTestDataString = JSON.stringify();
237
237
  // const walTestData = sthis.txt.encode(walTestDataString);
238
238
  const walPutResult = await walGateway.put(ctx, walUrl.Ok(), {
239
- type: bs.FPEnvelopeType.WAL,
239
+ type: bs.FPEnvelopeTypes.WAL,
240
240
  payload: {
241
241
  operations: [],
242
242
  noLoaderOps: [],
@@ -275,7 +275,7 @@ describe("noop Gateway", function () {
275
275
  // });
276
276
  // const walTestData = sthis.txt.encode(walTestDataString);
277
277
  await walGateway.put(ctx, walUrl.Ok(), {
278
- type: bs.FPEnvelopeType.WAL,
278
+ type: bs.FPEnvelopeTypes.WAL,
279
279
  payload: ref,
280
280
  });
281
281
  const walGetResult = await walGateway.get(ctx, walUrl.Ok());
@@ -308,7 +308,7 @@ describe("noop Gateway", function () {
308
308
  ],
309
309
  };
310
310
  await walGateway.put(ctx, walUrl.Ok(), {
311
- type: bs.FPEnvelopeType.WAL,
311
+ type: bs.FPEnvelopeTypes.WAL,
312
312
  payload: ref,
313
313
  });
314
314
  const walDeleteResult = await walGateway.delete(ctx, walUrl.Ok());
@@ -394,12 +394,16 @@ describe("noop Gateway subscribe", function () {
394
394
  let didCall = false;
395
395
  const p = new Future<void>();
396
396
 
397
- const metaSubscribeResult = (await metaGateway.subscribe(ctx, metaUrl.Ok(), async (data: bs.FPEnvelopeMeta) => {
398
- // const decodedData = sthis.txt.decode(data);
399
- expect(Array.isArray(data.payload)).toBeTruthy();
400
- didCall = true;
401
- p.resolve();
402
- })) as bs.UnsubscribeResult;
397
+ const metaSubscribeResult = (await metaGateway.subscribe(
398
+ ctx,
399
+ metaUrl.Ok().build().setParam(PARAM.SELF_REFLECT, "x").URI(),
400
+ async (data: bs.FPEnvelopeMeta) => {
401
+ // const decodedData = sthis.txt.decode(data);
402
+ expect(Array.isArray(data.payload)).toBeTruthy();
403
+ didCall = true;
404
+ p.resolve();
405
+ },
406
+ )) as bs.UnsubscribeResult;
403
407
  expect(metaSubscribeResult.isOk()).toBeTruthy();
404
408
  const ok = await db.put({ _id: "key1", hello: "world1" });
405
409
  expect(ok).toBeTruthy();
@@ -3,15 +3,13 @@ import { mockSuperThis, simpleCID } from "../helpers.js";
3
3
  import { BuildURI, Result } from "@adviser/cement";
4
4
  import { toJSON } from "multiformats/link";
5
5
 
6
- const FPEnvelopeType = bs.FPEnvelopeType;
7
-
8
6
  describe("storage-content", () => {
9
7
  const sthis = mockSuperThis();
10
8
  it("car", async () => {
11
9
  const raw = new Uint8Array([55, 56, 57]);
12
10
  const res = await rt.gw.fpDeserialize(sthis, BuildURI.from("http://x.com?store=data&suffix=.car").URI(), Result.Ok(raw));
13
11
  expect(res.isOk()).toBeTruthy();
14
- expect(res.unwrap().type).toEqual(FPEnvelopeType.CAR);
12
+ expect(res.unwrap().type).toEqual(bs.FPEnvelopeTypes.CAR);
15
13
  expect(res.unwrap().payload).toEqual(raw);
16
14
  });
17
15
 
@@ -19,7 +17,7 @@ describe("storage-content", () => {
19
17
  const raw = new Uint8Array([55, 56, 57]);
20
18
  const res = await rt.gw.fpDeserialize(sthis, BuildURI.from("http://x.com?store=data").URI(), Result.Ok(raw));
21
19
  expect(res.isOk()).toBeTruthy();
22
- expect(res.unwrap().type).toEqual(FPEnvelopeType.FILE);
20
+ expect(res.unwrap().type).toEqual(bs.FPEnvelopeTypes.FILE);
23
21
  expect(res.unwrap().payload).toEqual(raw);
24
22
  });
25
23
 
@@ -34,7 +32,7 @@ describe("storage-content", () => {
34
32
  const raw = sthis.txt.encode(JSON.stringify(ref));
35
33
  const res = await rt.gw.fpDeserialize(sthis, BuildURI.from("http://x.com?store=meta").URI(), Result.Ok(raw));
36
34
  expect(res.isOk()).toBeTruthy();
37
- expect(res.unwrap().type).toEqual(FPEnvelopeType.META);
35
+ expect(res.unwrap().type).toEqual(bs.FPEnvelopeTypes.META);
38
36
  const dbMetas = res.unwrap().payload as bs.DbMetaEvent[];
39
37
  expect(dbMetas.length).toBe(1);
40
38
  const dbMeta = dbMetas[0];
@@ -71,7 +69,7 @@ describe("storage-content", () => {
71
69
  const raw = sthis.txt.encode(JSON.stringify(ref));
72
70
  const res = await rt.gw.fpDeserialize(sthis, BuildURI.from("http://x.com?store=wal").URI(), Result.Ok(raw));
73
71
  expect(res.isOk()).toBeTruthy();
74
- expect(res.unwrap().type).toEqual(FPEnvelopeType.WAL);
72
+ expect(res.unwrap().type).toEqual(bs.FPEnvelopeTypes.WAL);
75
73
  const walstate = res.unwrap().payload as bs.WALState;
76
74
  expect(
77
75
  walstate.fileOperations.map((i) => ({
@@ -96,7 +94,7 @@ describe("de-serialize", () => {
96
94
  const sthis = mockSuperThis();
97
95
  it("car", async () => {
98
96
  const msg = {
99
- type: FPEnvelopeType.CAR,
97
+ type: bs.FPEnvelopeTypes.CAR,
100
98
  payload: new Uint8Array([55, 56, 57]),
101
99
  } satisfies bs.FPEnvelopeCar;
102
100
  const res = await rt.gw.fpSerialize(sthis, msg);
@@ -105,7 +103,7 @@ describe("de-serialize", () => {
105
103
 
106
104
  it("file", async () => {
107
105
  const msg = {
108
- type: FPEnvelopeType.FILE,
106
+ type: bs.FPEnvelopeTypes.FILE,
109
107
  payload: new Uint8Array([55, 56, 57]),
110
108
  } satisfies bs.FPEnvelopeFile;
111
109
  const res = await rt.gw.fpSerialize(sthis, msg);
@@ -114,7 +112,7 @@ describe("de-serialize", () => {
114
112
 
115
113
  it("meta", async () => {
116
114
  const msg = {
117
- type: FPEnvelopeType.META,
115
+ type: bs.FPEnvelopeTypes.META,
118
116
  payload: [
119
117
  await bs.createDbMetaEvent(
120
118
  sthis,
@@ -137,7 +135,7 @@ describe("de-serialize", () => {
137
135
 
138
136
  it("wal", async () => {
139
137
  const msg = {
140
- type: FPEnvelopeType.WAL,
138
+ type: bs.FPEnvelopeTypes.WAL,
141
139
  payload: {
142
140
  fileOperations: [
143
141
  {
@@ -171,7 +169,7 @@ describe("de-serialize", () => {
171
169
  const raw = new Uint8Array([55, 56, 57]);
172
170
  const res = await rt.gw.fpDeserialize(sthis, BuildURI.from("http://x.com?store=data&suffix=.car").URI(), Result.Ok(raw));
173
171
  expect(res.isOk()).toBeTruthy();
174
- expect(res.unwrap().type).toEqual(FPEnvelopeType.CAR);
172
+ expect(res.unwrap().type).toEqual(bs.FPEnvelopeTypes.CAR);
175
173
  expect(res.unwrap().payload).toEqual(raw);
176
174
  });
177
175
 
@@ -179,7 +177,7 @@ describe("de-serialize", () => {
179
177
  const raw = new Uint8Array([55, 56, 57]);
180
178
  const res = await rt.gw.fpDeserialize(sthis, BuildURI.from("http://x.com?store=data&suffix=.car").URI(), Promise.resolve(raw));
181
179
  expect(res.isOk()).toBeTruthy();
182
- expect(res.unwrap().type).toEqual(FPEnvelopeType.CAR);
180
+ expect(res.unwrap().type).toEqual(bs.FPEnvelopeTypes.CAR);
183
181
  expect(res.unwrap().payload).toEqual(raw);
184
182
  });
185
183
 
@@ -191,7 +189,7 @@ describe("de-serialize", () => {
191
189
  Promise.resolve(Result.Ok(raw)),
192
190
  );
193
191
  expect(res.isOk()).toBeTruthy();
194
- expect(res.unwrap().type).toEqual(FPEnvelopeType.CAR);
192
+ expect(res.unwrap().type).toEqual(bs.FPEnvelopeTypes.CAR);
195
193
  expect(res.unwrap().payload).toEqual(raw);
196
194
  });
197
195
 
@@ -218,7 +216,7 @@ describe("de-serialize", () => {
218
216
 
219
217
  it("attach Key to Meta", async () => {
220
218
  const msg = {
221
- type: FPEnvelopeType.META,
219
+ type: bs.FPEnvelopeTypes.META,
222
220
  payload: [
223
221
  await bs.createDbMetaEvent(
224
222
  sthis,