@interncom/diplomatic 0.0.49 → 0.0.50
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 +1 -1
- package/dist/client.d.ts +8 -2
- package/dist/index.mjs +38 -11
- package/dist/shared/ops.d.ts +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IOp, KeyPair } from "./shared/types";
|
|
1
|
+
import type { GroupID, IOp, KeyPair } from "./shared/types";
|
|
2
2
|
import type { IClientStateStore, IDiplomaticClientState } from "./types";
|
|
3
3
|
import type { StateManager } from "./state";
|
|
4
4
|
export interface IDiplomaticClientParams {
|
|
@@ -38,6 +38,12 @@ export default class DiplomaticClient {
|
|
|
38
38
|
apply(op: IOp): Promise<void>;
|
|
39
39
|
export(filename: string, extension?: string): Promise<void>;
|
|
40
40
|
import: (file: File) => Promise<void>;
|
|
41
|
-
upsert<T>(type
|
|
41
|
+
upsert<T>({ type, body, eid, gid, version }: {
|
|
42
|
+
type: string;
|
|
43
|
+
body: T;
|
|
44
|
+
eid?: Uint8Array;
|
|
45
|
+
gid?: GroupID;
|
|
46
|
+
version: number;
|
|
47
|
+
}): Promise<void>;
|
|
42
48
|
delete<T>(type: string, eid: Uint8Array, version?: number): Promise<void>;
|
|
43
49
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -11323,9 +11323,10 @@ var Verb = /* @__PURE__ */ ((Verb2) => {
|
|
|
11323
11323
|
})(Verb || {});
|
|
11324
11324
|
|
|
11325
11325
|
// ../shared/ops.ts
|
|
11326
|
-
function genUpsertOp(eid, type, body, version = 0) {
|
|
11326
|
+
function genUpsertOp(eid, type, body, version = 0, gid) {
|
|
11327
11327
|
return {
|
|
11328
11328
|
eid,
|
|
11329
|
+
gid,
|
|
11329
11330
|
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
11330
11331
|
type,
|
|
11331
11332
|
verb: 1 /* UPSERT */,
|
|
@@ -11447,7 +11448,10 @@ var DiplomaticClient = class {
|
|
|
11447
11448
|
return;
|
|
11448
11449
|
}
|
|
11449
11450
|
this.hostURL = new URL(hostURL);
|
|
11450
|
-
this.hostKeyPair = await crypto_default.deriveEd25519KeyPair(
|
|
11451
|
+
this.hostKeyPair = await crypto_default.deriveEd25519KeyPair(
|
|
11452
|
+
this.seed,
|
|
11453
|
+
hostID
|
|
11454
|
+
);
|
|
11451
11455
|
}
|
|
11452
11456
|
// TODO: dedupe with loadHost.
|
|
11453
11457
|
async register(hostURL) {
|
|
@@ -11456,8 +11460,15 @@ var DiplomaticClient = class {
|
|
|
11456
11460
|
}
|
|
11457
11461
|
this.hostURL = new URL(hostURL);
|
|
11458
11462
|
const hostID = await api_default.getHostID(this.hostURL);
|
|
11459
|
-
this.hostKeyPair = await crypto_default.deriveEd25519KeyPair(
|
|
11460
|
-
|
|
11463
|
+
this.hostKeyPair = await crypto_default.deriveEd25519KeyPair(
|
|
11464
|
+
this.seed,
|
|
11465
|
+
hostID
|
|
11466
|
+
);
|
|
11467
|
+
await api_default.register(
|
|
11468
|
+
this.hostURL,
|
|
11469
|
+
this.hostKeyPair.publicKey,
|
|
11470
|
+
"tok123"
|
|
11471
|
+
);
|
|
11461
11472
|
await this.store.setHostURL(hostURL);
|
|
11462
11473
|
await this.store.setHostID(hostID);
|
|
11463
11474
|
this.emitUpdate();
|
|
@@ -11518,8 +11529,15 @@ var DiplomaticClient = class {
|
|
|
11518
11529
|
continue;
|
|
11519
11530
|
}
|
|
11520
11531
|
try {
|
|
11521
|
-
const cipher = await api_default.getDelta(
|
|
11522
|
-
|
|
11532
|
+
const cipher = await api_default.getDelta(
|
|
11533
|
+
hostURL,
|
|
11534
|
+
item.sha256,
|
|
11535
|
+
hostKeyPair
|
|
11536
|
+
);
|
|
11537
|
+
const packed = await crypto_default.decryptXSalsa20Poly1305Combined(
|
|
11538
|
+
cipher,
|
|
11539
|
+
encKey
|
|
11540
|
+
);
|
|
11523
11541
|
const op = decode(packed);
|
|
11524
11542
|
const sha256 = await crypto_default.sha256Hash(cipher);
|
|
11525
11543
|
await this.stateManager.apply(op);
|
|
@@ -11560,7 +11578,10 @@ var DiplomaticClient = class {
|
|
|
11560
11578
|
throw "No encryption key";
|
|
11561
11579
|
}
|
|
11562
11580
|
const packed = encode(op);
|
|
11563
|
-
const cipherOp = await crypto_default.encryptXSalsa20Poly1305Combined(
|
|
11581
|
+
const cipherOp = await crypto_default.encryptXSalsa20Poly1305Combined(
|
|
11582
|
+
packed,
|
|
11583
|
+
this.encKey
|
|
11584
|
+
);
|
|
11564
11585
|
const sha256 = await crypto_default.sha256Hash(cipherOp);
|
|
11565
11586
|
await this.store.enqueueUpload(sha256, cipherOp);
|
|
11566
11587
|
this.emitUpdate();
|
|
@@ -11583,7 +11604,10 @@ var DiplomaticClient = class {
|
|
|
11583
11604
|
for (const op of ops) {
|
|
11584
11605
|
zip.file(`${op.sha256}.op`, op.cipherOp);
|
|
11585
11606
|
}
|
|
11586
|
-
const blob = await zip.generateAsync({
|
|
11607
|
+
const blob = await zip.generateAsync({
|
|
11608
|
+
compression: "STORE",
|
|
11609
|
+
type: "blob"
|
|
11610
|
+
});
|
|
11587
11611
|
return (0, import_file_saver.saveAs)(blob, `${filename}.${extension}`);
|
|
11588
11612
|
}
|
|
11589
11613
|
import = async (file) => {
|
|
@@ -11599,7 +11623,10 @@ var DiplomaticClient = class {
|
|
|
11599
11623
|
continue;
|
|
11600
11624
|
}
|
|
11601
11625
|
const cipher = await zip.files[opFileName].async("uint8array");
|
|
11602
|
-
const packed = await crypto_default.decryptXSalsa20Poly1305Combined(
|
|
11626
|
+
const packed = await crypto_default.decryptXSalsa20Poly1305Combined(
|
|
11627
|
+
cipher,
|
|
11628
|
+
encKey
|
|
11629
|
+
);
|
|
11603
11630
|
const op = decode(packed);
|
|
11604
11631
|
const sha256 = await crypto_default.sha256Hash(cipher);
|
|
11605
11632
|
await this.stateManager.apply(op);
|
|
@@ -11607,9 +11634,9 @@ var DiplomaticClient = class {
|
|
|
11607
11634
|
this.emitUpdate();
|
|
11608
11635
|
}
|
|
11609
11636
|
};
|
|
11610
|
-
async upsert(type, body, eid, version = 0) {
|
|
11637
|
+
async upsert({ type, body, eid, gid, version = 0 }) {
|
|
11611
11638
|
const id = eid ?? await crypto_default.gen128BitRandomID();
|
|
11612
|
-
const op = genUpsertOp(id, type, body, version);
|
|
11639
|
+
const op = genUpsertOp(id, type, body, version, gid);
|
|
11613
11640
|
return this.apply(op);
|
|
11614
11641
|
}
|
|
11615
11642
|
async delete(type, eid, version = 0) {
|
package/dist/shared/ops.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IDeleteOp, type IOp, IUpsertOp } from
|
|
2
|
-
export declare function genUpsertOp<T>(eid: Uint8Array, type: string, body: T, version?: number): IUpsertOp;
|
|
1
|
+
import { type GroupID, type IDeleteOp, type IOp, type IUpsertOp } from "./types.ts";
|
|
2
|
+
export declare function genUpsertOp<T>(eid: Uint8Array, type: string, body: T, version?: number, gid?: GroupID): IUpsertOp;
|
|
3
3
|
export declare function genDeleteOp<T>(eid: Uint8Array, type: string, version?: number): IDeleteOp;
|
|
4
4
|
export declare function isOp(op: any): op is IOp;
|