@interncom/diplomatic 0.0.36 → 0.0.38
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/dist/idbStore.d.ts +1 -0
- package/dist/index.mjs +21 -6
- package/dist/localStorageStore.d.ts +1 -0
- package/dist/memoryStore.d.ts +1 -0
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
package/dist/idbStore.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ declare class IDBStore implements IClientStateStore {
|
|
|
28
28
|
numDownloads: () => Promise<number>;
|
|
29
29
|
storeOp: (sha256: Uint8Array, cipherOp: Uint8Array) => Promise<void>;
|
|
30
30
|
clearOp: (sha256: Uint8Array) => Promise<void>;
|
|
31
|
+
hasOp: (sha256: Uint8Array) => Promise<boolean>;
|
|
31
32
|
}
|
|
32
33
|
export declare const idbStore: IDBStore;
|
|
33
34
|
export {};
|
package/dist/index.mjs
CHANGED
|
@@ -199,6 +199,10 @@ var LocalStorageStore = class {
|
|
|
199
199
|
const hex = btoh(sha256);
|
|
200
200
|
this.ops.delete(hex);
|
|
201
201
|
};
|
|
202
|
+
hasOp = async (sha256) => {
|
|
203
|
+
const hex = btoh(sha256);
|
|
204
|
+
return this.ops.has(hex);
|
|
205
|
+
};
|
|
202
206
|
};
|
|
203
207
|
var localStorageStore = new LocalStorageStore();
|
|
204
208
|
|
|
@@ -546,6 +550,11 @@ var IDBStore = class {
|
|
|
546
550
|
const hex = btoh(sha256);
|
|
547
551
|
await db.delete("ops", hex);
|
|
548
552
|
};
|
|
553
|
+
hasOp = async (sha256) => {
|
|
554
|
+
const hex = btoh(sha256);
|
|
555
|
+
const op = await db.get("ops", hex);
|
|
556
|
+
return op !== void 0;
|
|
557
|
+
};
|
|
549
558
|
};
|
|
550
559
|
var idbStore = new IDBStore();
|
|
551
560
|
|
|
@@ -8990,7 +8999,7 @@ var DiplomaticClient = class {
|
|
|
8990
8999
|
return [];
|
|
8991
9000
|
}
|
|
8992
9001
|
const lastFetchedAt = await this.store.getLastFetchedAt();
|
|
8993
|
-
const begin =
|
|
9002
|
+
const begin = /* @__PURE__ */ new Date(0);
|
|
8994
9003
|
const { hostURL, hostKeyPair } = this;
|
|
8995
9004
|
const resp = await api_default.listDeltas(hostURL, begin, hostKeyPair);
|
|
8996
9005
|
for (const item of resp.deltas) {
|
|
@@ -9007,13 +9016,19 @@ var DiplomaticClient = class {
|
|
|
9007
9016
|
const items = await this.store.listDownloads();
|
|
9008
9017
|
items.sort((i1, i2) => i1.recordedAt.getTime() - i2.recordedAt.getTime());
|
|
9009
9018
|
for (const item of items) {
|
|
9010
|
-
|
|
9011
|
-
|
|
9012
|
-
|
|
9019
|
+
if (await this.store.hasOp(item.sha256)) {
|
|
9020
|
+
console.log("already got it skipping");
|
|
9021
|
+
await this.store.dequeueDownload(item.sha256);
|
|
9022
|
+
this.emitUpdate();
|
|
9023
|
+
continue;
|
|
9024
|
+
}
|
|
9013
9025
|
try {
|
|
9026
|
+
const cipher = await api_default.getDelta(hostURL, item.sha256, hostKeyPair);
|
|
9027
|
+
const packed = await crypto_default.decryptXSalsa20Poly1305Combined(cipher, encKey);
|
|
9028
|
+
const op = decode(packed);
|
|
9014
9029
|
const sha256 = await crypto_default.sha256Hash(cipher);
|
|
9015
|
-
await this.store.storeOp(sha256, cipher);
|
|
9016
9030
|
await this.stateManager.apply(op);
|
|
9031
|
+
await this.store.storeOp(sha256, cipher);
|
|
9017
9032
|
await this.store.dequeueDownload(sha256);
|
|
9018
9033
|
this.emitUpdate();
|
|
9019
9034
|
} catch {
|
|
@@ -9052,11 +9067,11 @@ var DiplomaticClient = class {
|
|
|
9052
9067
|
const packed = encode(op);
|
|
9053
9068
|
const cipherOp = await crypto_default.encryptXSalsa20Poly1305Combined(packed, this.encKey);
|
|
9054
9069
|
const sha256 = await crypto_default.sha256Hash(cipherOp);
|
|
9055
|
-
await this.store.storeOp(sha256, cipherOp);
|
|
9056
9070
|
await this.store.enqueueUpload(sha256, cipherOp);
|
|
9057
9071
|
this.emitUpdate();
|
|
9058
9072
|
try {
|
|
9059
9073
|
await this.stateManager.apply(op);
|
|
9074
|
+
await this.store.storeOp(sha256, cipherOp);
|
|
9060
9075
|
} catch (err) {
|
|
9061
9076
|
await this.store.dequeueUpload(sha256);
|
|
9062
9077
|
this.emitUpdate();
|
|
@@ -26,6 +26,7 @@ declare class LocalStorageStore implements IClientStateStore {
|
|
|
26
26
|
ops: Map<string, Uint8Array>;
|
|
27
27
|
storeOp: (sha256: Uint8Array, cipherOp: Uint8Array) => Promise<void>;
|
|
28
28
|
clearOp: (sha256: Uint8Array) => Promise<void>;
|
|
29
|
+
hasOp: (sha256: Uint8Array) => Promise<boolean>;
|
|
29
30
|
}
|
|
30
31
|
export declare const localStorageStore: LocalStorageStore;
|
|
31
32
|
export {};
|
package/dist/memoryStore.d.ts
CHANGED
|
@@ -30,6 +30,7 @@ declare class MemoryStore implements IClientStateStore {
|
|
|
30
30
|
ops: Map<string, Uint8Array>;
|
|
31
31
|
storeOp: (sha256: Uint8Array, cipherOp: Uint8Array) => Promise<void>;
|
|
32
32
|
clearOp: (sha256: Uint8Array) => Promise<void>;
|
|
33
|
+
hasOp: (sha256: Uint8Array) => Promise<boolean>;
|
|
33
34
|
}
|
|
34
35
|
export declare const memoryStore: MemoryStore;
|
|
35
36
|
export {};
|
package/dist/types.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export interface IClientStateStore {
|
|
|
21
21
|
numDownloads: () => Promise<number>;
|
|
22
22
|
storeOp: (sha256: Uint8Array, cipherOp: Uint8Array) => Promise<void>;
|
|
23
23
|
clearOp: (sha256: Uint8Array) => Promise<void>;
|
|
24
|
+
hasOp: (sha256: Uint8Array) => Promise<boolean>;
|
|
24
25
|
}
|
|
25
26
|
export interface IDiplomaticClientState {
|
|
26
27
|
hasSeed: boolean;
|