@peers-app/peers-sdk 0.14.0 → 0.15.0
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/context/data-context.d.ts +4 -4
- package/dist/context/data-context.js +1 -1
- package/dist/context/index.d.ts +3 -3
- package/dist/context/index.js +4 -0
- package/dist/context/user-context-singleton.js +13 -14
- package/dist/context/user-context.d.ts +4 -4
- package/dist/context/user-context.js +48 -31
- package/dist/data/assistants.d.ts +1 -1
- package/dist/data/assistants.js +35 -24
- package/dist/data/change-tracking.d.ts +8 -8
- package/dist/data/change-tracking.js +45 -39
- package/dist/data/channels.js +5 -5
- package/dist/data/data-locks.d.ts +2 -2
- package/dist/data/data-locks.js +21 -23
- package/dist/data/data-locks.test.js +73 -75
- package/dist/data/device-sync-info.d.ts +1 -1
- package/dist/data/device-sync-info.js +4 -4
- package/dist/data/devices.d.ts +1 -1
- package/dist/data/devices.js +9 -12
- package/dist/data/embeddings.js +14 -11
- package/dist/data/files/file-read-stream.d.ts +2 -2
- package/dist/data/files/file-read-stream.js +23 -14
- package/dist/data/files/file-write-stream.d.ts +2 -2
- package/dist/data/files/file-write-stream.js +8 -8
- package/dist/data/files/file.types.d.ts +2 -2
- package/dist/data/files/file.types.js +17 -11
- package/dist/data/files/files.d.ts +6 -6
- package/dist/data/files/files.js +17 -19
- package/dist/data/files/files.test.js +213 -214
- package/dist/data/files/index.d.ts +4 -4
- package/dist/data/files/index.js +4 -4
- package/dist/data/group-member-roles.js +2 -2
- package/dist/data/group-members.d.ts +5 -5
- package/dist/data/group-members.js +27 -18
- package/dist/data/group-members.test.js +73 -73
- package/dist/data/group-permissions.d.ts +3 -3
- package/dist/data/group-permissions.js +13 -11
- package/dist/data/group-share.d.ts +2 -2
- package/dist/data/group-share.js +29 -24
- package/dist/data/groups.d.ts +4 -4
- package/dist/data/groups.js +27 -19
- package/dist/data/groups.test.js +44 -44
- package/dist/data/index.d.ts +6 -6
- package/dist/data/index.js +6 -6
- package/dist/data/knowledge/peer-types.js +9 -9
- package/dist/data/messages.d.ts +5 -5
- package/dist/data/messages.js +43 -30
- package/dist/data/orm/client-proxy.data-source.d.ts +4 -4
- package/dist/data/orm/client-proxy.data-source.js +10 -12
- package/dist/data/orm/cursor.d.ts +1 -1
- package/dist/data/orm/cursor.js +2 -2
- package/dist/data/orm/cursor.test.js +92 -93
- package/dist/data/orm/data-query.d.ts +3 -3
- package/dist/data/orm/data-query.js +24 -18
- package/dist/data/orm/data-query.mongo.d.ts +1 -1
- package/dist/data/orm/data-query.mongo.js +49 -51
- package/dist/data/orm/data-query.mongo.test.js +173 -204
- package/dist/data/orm/data-query.sqlite.d.ts +1 -1
- package/dist/data/orm/data-query.sqlite.js +84 -73
- package/dist/data/orm/data-query.sqlite.test.js +164 -176
- package/dist/data/orm/data-query.test.js +216 -224
- package/dist/data/orm/decorators.js +3 -3
- package/dist/data/orm/dependency-injection.test.js +53 -56
- package/dist/data/orm/doc.d.ts +4 -4
- package/dist/data/orm/doc.js +17 -21
- package/dist/data/orm/event-registry.d.ts +1 -1
- package/dist/data/orm/event-registry.test.js +16 -16
- package/dist/data/orm/factory.d.ts +2 -2
- package/dist/data/orm/factory.js +33 -33
- package/dist/data/orm/index.d.ts +10 -10
- package/dist/data/orm/index.js +10 -10
- package/dist/data/orm/multi-cursors.d.ts +1 -1
- package/dist/data/orm/multi-cursors.js +6 -6
- package/dist/data/orm/multi-cursors.test.js +152 -144
- package/dist/data/orm/sql.data-source.d.ts +7 -7
- package/dist/data/orm/sql.data-source.js +88 -93
- package/dist/data/orm/sql.data-source.test.js +109 -101
- package/dist/data/orm/subscribable.data-source.d.ts +4 -4
- package/dist/data/orm/subscribable.data-source.js +5 -5
- package/dist/data/orm/table-container-events.test.js +34 -26
- package/dist/data/orm/table-container.d.ts +6 -6
- package/dist/data/orm/table-container.js +33 -21
- package/dist/data/orm/table-container.test.js +64 -53
- package/dist/data/orm/table-definitions.system.d.ts +3 -3
- package/dist/data/orm/table-definitions.system.js +3 -3
- package/dist/data/orm/table-definitions.type.d.ts +5 -5
- package/dist/data/orm/table-dependencies.d.ts +2 -2
- package/dist/data/orm/table.d.ts +5 -5
- package/dist/data/orm/table.event-source.test.js +105 -115
- package/dist/data/orm/table.js +35 -34
- package/dist/data/orm/types.d.ts +3 -3
- package/dist/data/orm/types.js +26 -25
- package/dist/data/orm/types.test.js +166 -92
- package/dist/data/package-permissions.d.ts +1 -1
- package/dist/data/package-permissions.js +2 -2
- package/dist/data/package-version-permissions.d.ts +1 -1
- package/dist/data/package-version-permissions.js +2 -2
- package/dist/data/package-versions.d.ts +9 -9
- package/dist/data/package-versions.js +47 -33
- package/dist/data/packages.d.ts +2 -2
- package/dist/data/packages.js +36 -18
- package/dist/data/packages.utils.d.ts +2 -2
- package/dist/data/packages.utils.js +4 -4
- package/dist/data/persistent-vars.d.ts +15 -15
- package/dist/data/persistent-vars.js +165 -154
- package/dist/data/table-definitions-table.d.ts +5 -5
- package/dist/data/table-definitions-table.js +13 -12
- package/dist/data/tool-tests.js +6 -6
- package/dist/data/tools.js +29 -19
- package/dist/data/user-permissions.d.ts +1 -1
- package/dist/data/user-permissions.js +5 -5
- package/dist/data/user-permissions.test.js +90 -88
- package/dist/data/user-trust-levels.js +10 -10
- package/dist/data/users.d.ts +4 -4
- package/dist/data/users.js +16 -15
- package/dist/data/voice-messages.d.ts +2 -2
- package/dist/data/voice-messages.js +13 -13
- package/dist/data/welcome-modal.pvar.js +3 -1
- package/dist/data/workflow-logs.js +26 -18
- package/dist/data/workflow-runs.d.ts +6 -6
- package/dist/data/workflow-runs.js +70 -44
- package/dist/data/workflows.d.ts +2 -2
- package/dist/data/workflows.js +7 -9
- package/dist/device/binary-peer-connection-v2.d.ts +7 -7
- package/dist/device/binary-peer-connection-v2.js +32 -28
- package/dist/device/binary-peer-connection-v2.test.js +80 -67
- package/dist/device/binary-peer-connection.d.ts +7 -7
- package/dist/device/binary-peer-connection.js +29 -28
- package/dist/device/binary-peer-connection.test.js +35 -31
- package/dist/device/connection.d.ts +5 -5
- package/dist/device/connection.js +59 -48
- package/dist/device/connection.test.js +74 -68
- package/dist/device/device-election.d.ts +2 -2
- package/dist/device/device-election.js +25 -20
- package/dist/device/device-election.test.js +35 -36
- package/dist/device/device.d.ts +2 -2
- package/dist/device/device.js +10 -4
- package/dist/device/device.test.js +16 -17
- package/dist/device/get-trust-level-fn.d.ts +2 -2
- package/dist/device/get-trust-level-fn.js +22 -11
- package/dist/device/get-trust-level-fn.test.js +58 -58
- package/dist/device/socket-io-binary-peer.d.ts +1 -1
- package/dist/device/socket-io-binary-peer.js +16 -13
- package/dist/device/socket.type.d.ts +2 -2
- package/dist/device/streamed-socket.d.ts +2 -2
- package/dist/device/streamed-socket.js +8 -8
- package/dist/device/streamed-socket.test.js +40 -40
- package/dist/device/tx-encoding.test.js +77 -77
- package/dist/events.d.ts +1 -1
- package/dist/events.js +5 -2
- package/dist/group-invite/group-invite.js +110 -19
- package/dist/group-invite/group-invite.pvars.d.ts +2 -2
- package/dist/group-invite/group-invite.pvars.js +21 -13
- package/dist/group-invite/group-invite.types.d.ts +1 -1
- package/dist/group-invite/index.d.ts +3 -3
- package/dist/group-invite/index.js +1 -1
- package/dist/index.d.ts +25 -24
- package/dist/index.js +30 -25
- package/dist/keys.d.ts +3 -3
- package/dist/keys.js +31 -30
- package/dist/keys.test.js +69 -61
- package/dist/logging/console-logger.d.ts +1 -1
- package/dist/logging/console-logger.js +35 -40
- package/dist/logging/console-logger.test.js +115 -115
- package/dist/logging/console-logs.table.d.ts +3 -3
- package/dist/logging/console-logs.table.js +28 -23
- package/dist/mentions.js +16 -12
- package/dist/observable.d.ts +2 -2
- package/dist/observable.js +15 -9
- package/dist/observable.test.js +47 -47
- package/dist/package-loader/get-require.js +3 -4
- package/dist/package-loader/package-loader.d.ts +2 -2
- package/dist/package-loader/package-loader.js +52 -34
- package/dist/peers-ui/peers-ui.d.ts +2 -2
- package/dist/peers-ui/peers-ui.js +2 -4
- package/dist/peers-ui/peers-ui.types.d.ts +3 -3
- package/dist/peers-ui/peers-ui.types.js +0 -1
- package/dist/rpc-types.d.ts +61 -59
- package/dist/rpc-types.js +61 -55
- package/dist/serial-json.d.ts +1 -1
- package/dist/serial-json.js +50 -43
- package/dist/serial-json.test.js +22 -22
- package/dist/system-ids.js +8 -8
- package/dist/tools/index.d.ts +1 -1
- package/dist/tools/tools-factory.d.ts +1 -1
- package/dist/tools/tools-factory.js +2 -2
- package/dist/types/assistant-runner-args.d.ts +3 -3
- package/dist/types/peer-device.d.ts +1 -1
- package/dist/types/peers-package.d.ts +3 -3
- package/dist/types/workflow-logger.d.ts +1 -1
- package/dist/types/workflow-run-context.d.ts +4 -4
- package/dist/types/workflow.d.ts +4 -4
- package/dist/types/workflow.js +27 -14
- package/dist/types/zod-types.d.ts +2 -1
- package/dist/types/zod-types.js +9 -3
- package/dist/user-connect/connection-code.d.ts +1 -1
- package/dist/user-connect/connection-code.js +7 -7
- package/dist/user-connect/connection-code.test.js +106 -106
- package/dist/user-connect/index.d.ts +3 -3
- package/dist/user-connect/index.js +1 -1
- package/dist/user-connect/user-connect.pvars.js +13 -11
- package/dist/user-connect/user-connect.types.d.ts +3 -3
- package/dist/users.query.d.ts +2 -2
- package/dist/users.query.js +40 -30
- package/dist/utils.d.ts +2 -2
- package/dist/utils.js +34 -32
- package/dist/utils.test.js +12 -8
- package/dist/workflow-log-formatter.d.ts +1 -1
- package/dist/workflow-log-formatter.js +17 -18
- package/package.json +14 -8
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
1
|
+
export * from "./group-invite";
|
|
2
|
+
export * from "./group-invite.pvars";
|
|
3
|
+
export * from "./group-invite.types";
|
|
@@ -15,5 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./group-invite"), exports);
|
|
18
|
-
__exportStar(require("./group-invite.types"), exports);
|
|
19
18
|
__exportStar(require("./group-invite.pvars"), exports);
|
|
19
|
+
__exportStar(require("./group-invite.types"), exports);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,40 +1,41 @@
|
|
|
1
1
|
export * from "./context";
|
|
2
|
-
export * from "./
|
|
3
|
-
export
|
|
4
|
-
export * from "./
|
|
5
|
-
export * from "./
|
|
6
|
-
export * from "./
|
|
7
|
-
export * from "./types/assistant-runner-args";
|
|
8
|
-
export * from "./types/field-type";
|
|
9
|
-
export * from "./types/peer-device";
|
|
10
|
-
export * from "./types/peers-package";
|
|
11
|
-
export * from "./types/workflow";
|
|
12
|
-
export * from "./types/workflow-logger";
|
|
13
|
-
export * from "./types/workflow-run-context";
|
|
14
|
-
export * from "./types/zod-types";
|
|
2
|
+
export * from "./data";
|
|
3
|
+
export { WorkflowLogs, getLogger, workflowLogSchema, type IWorkflowLog, } from "./data/workflow-logs";
|
|
4
|
+
export * as data from "./data";
|
|
5
|
+
export * from "./data/orm";
|
|
6
|
+
export * as orm from "./data/orm";
|
|
15
7
|
export * from "./device/binary-peer-connection-v2";
|
|
16
|
-
export * from "./device/socket-io-binary-peer";
|
|
17
8
|
export * from "./device/connection";
|
|
18
9
|
export * from "./device/device";
|
|
19
10
|
export * from "./device/device-election";
|
|
20
11
|
export * from "./device/get-trust-level-fn";
|
|
21
12
|
export * from "./device/socket.type";
|
|
13
|
+
export * from "./device/socket-io-binary-peer";
|
|
22
14
|
export * from "./device/tx-encoding";
|
|
23
|
-
export * from "./package-loader";
|
|
24
15
|
export * from "./events";
|
|
25
|
-
export * from "./
|
|
26
|
-
export * as data from "./data";
|
|
27
|
-
export * from "./data/orm";
|
|
28
|
-
export * as orm from "./data/orm";
|
|
29
|
-
export * from "./tools";
|
|
30
|
-
export * as tools from "./tools";
|
|
16
|
+
export * from "./group-invite";
|
|
31
17
|
export * from "./keys";
|
|
18
|
+
export * from "./logging";
|
|
32
19
|
export * from "./mentions";
|
|
33
20
|
export * from "./observable";
|
|
21
|
+
export * from "./package-loader";
|
|
22
|
+
export * from "./peers-ui/peers-ui";
|
|
23
|
+
export * from "./peers-ui/peers-ui.types";
|
|
34
24
|
export * from "./rpc-types";
|
|
35
25
|
export * from "./serial-json";
|
|
36
|
-
export * from "./
|
|
37
|
-
export * from "./
|
|
26
|
+
export * from "./system-ids";
|
|
27
|
+
export * from "./tools";
|
|
28
|
+
export * as tools from "./tools";
|
|
29
|
+
export * from "./types/app-nav";
|
|
30
|
+
export * from "./types/assistant-runner-args";
|
|
31
|
+
export * from "./types/field-type";
|
|
32
|
+
export * from "./types/peer-device";
|
|
33
|
+
export * from "./types/peers-package";
|
|
34
|
+
export * from "./types/workflow";
|
|
35
|
+
export * from "./types/workflow-logger";
|
|
36
|
+
export * from "./types/workflow-run-context";
|
|
37
|
+
export * from "./types/zod-types";
|
|
38
38
|
export * from "./user-connect";
|
|
39
|
-
export * from "./
|
|
39
|
+
export * from "./users.query";
|
|
40
|
+
export * from "./utils";
|
|
40
41
|
export * from "./workflow-log-formatter";
|
package/dist/index.js
CHANGED
|
@@ -14,44 +14,49 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.tools = exports.orm = exports.data = void 0;
|
|
17
|
+
exports.tools = exports.orm = exports.data = exports.workflowLogSchema = exports.getLogger = exports.WorkflowLogs = void 0;
|
|
18
18
|
__exportStar(require("./context"), exports);
|
|
19
|
-
__exportStar(require("./
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
__exportStar(require("./
|
|
27
|
-
|
|
28
|
-
__exportStar(require("./types/workflow"), exports);
|
|
29
|
-
__exportStar(require("./types/workflow-logger"), exports);
|
|
30
|
-
__exportStar(require("./types/workflow-run-context"), exports);
|
|
31
|
-
__exportStar(require("./types/zod-types"), exports);
|
|
19
|
+
__exportStar(require("./data"), exports);
|
|
20
|
+
// Root `.d.ts` lists these explicitly so IDEs see them (not only via `export *`).
|
|
21
|
+
var workflow_logs_1 = require("./data/workflow-logs");
|
|
22
|
+
Object.defineProperty(exports, "WorkflowLogs", { enumerable: true, get: function () { return workflow_logs_1.WorkflowLogs; } });
|
|
23
|
+
Object.defineProperty(exports, "getLogger", { enumerable: true, get: function () { return workflow_logs_1.getLogger; } });
|
|
24
|
+
Object.defineProperty(exports, "workflowLogSchema", { enumerable: true, get: function () { return workflow_logs_1.workflowLogSchema; } });
|
|
25
|
+
exports.data = require("./data");
|
|
26
|
+
__exportStar(require("./data/orm"), exports);
|
|
27
|
+
exports.orm = require("./data/orm");
|
|
32
28
|
__exportStar(require("./device/binary-peer-connection-v2"), exports);
|
|
33
|
-
__exportStar(require("./device/socket-io-binary-peer"), exports);
|
|
34
29
|
__exportStar(require("./device/connection"), exports);
|
|
35
30
|
__exportStar(require("./device/device"), exports);
|
|
36
31
|
__exportStar(require("./device/device-election"), exports);
|
|
37
32
|
__exportStar(require("./device/get-trust-level-fn"), exports);
|
|
38
33
|
__exportStar(require("./device/socket.type"), exports);
|
|
34
|
+
__exportStar(require("./device/socket-io-binary-peer"), exports);
|
|
39
35
|
__exportStar(require("./device/tx-encoding"), exports);
|
|
40
|
-
__exportStar(require("./package-loader"), exports);
|
|
41
36
|
__exportStar(require("./events"), exports);
|
|
42
|
-
__exportStar(require("./
|
|
43
|
-
exports.data = require("./data");
|
|
44
|
-
__exportStar(require("./data/orm"), exports);
|
|
45
|
-
exports.orm = require("./data/orm");
|
|
46
|
-
__exportStar(require("./tools"), exports);
|
|
47
|
-
exports.tools = require("./tools");
|
|
37
|
+
__exportStar(require("./group-invite"), exports);
|
|
48
38
|
__exportStar(require("./keys"), exports);
|
|
39
|
+
__exportStar(require("./logging"), exports);
|
|
49
40
|
__exportStar(require("./mentions"), exports);
|
|
50
41
|
__exportStar(require("./observable"), exports);
|
|
42
|
+
__exportStar(require("./package-loader"), exports);
|
|
43
|
+
__exportStar(require("./peers-ui/peers-ui"), exports);
|
|
44
|
+
__exportStar(require("./peers-ui/peers-ui.types"), exports);
|
|
51
45
|
__exportStar(require("./rpc-types"), exports);
|
|
52
46
|
__exportStar(require("./serial-json"), exports);
|
|
53
|
-
__exportStar(require("./
|
|
54
|
-
__exportStar(require("./
|
|
47
|
+
__exportStar(require("./system-ids"), exports);
|
|
48
|
+
__exportStar(require("./tools"), exports);
|
|
49
|
+
exports.tools = require("./tools");
|
|
50
|
+
__exportStar(require("./types/app-nav"), exports);
|
|
51
|
+
__exportStar(require("./types/assistant-runner-args"), exports);
|
|
52
|
+
__exportStar(require("./types/field-type"), exports);
|
|
53
|
+
__exportStar(require("./types/peer-device"), exports);
|
|
54
|
+
__exportStar(require("./types/peers-package"), exports);
|
|
55
|
+
__exportStar(require("./types/workflow"), exports);
|
|
56
|
+
__exportStar(require("./types/workflow-logger"), exports);
|
|
57
|
+
__exportStar(require("./types/workflow-run-context"), exports);
|
|
58
|
+
__exportStar(require("./types/zod-types"), exports);
|
|
55
59
|
__exportStar(require("./user-connect"), exports);
|
|
56
|
-
__exportStar(require("./
|
|
60
|
+
__exportStar(require("./users.query"), exports);
|
|
61
|
+
__exportStar(require("./utils"), exports);
|
|
57
62
|
__exportStar(require("./workflow-log-formatter"), exports);
|
package/dist/keys.d.ts
CHANGED
|
@@ -2,9 +2,9 @@ export declare function setPRNG(fn: (x: Uint8Array, n: number) => void): void;
|
|
|
2
2
|
export declare function hashValue(str: string): string;
|
|
3
3
|
export declare function hashBytes(buffer: Uint8Array): string;
|
|
4
4
|
export declare function stableStringify(obj: any): string;
|
|
5
|
-
export declare function hashObject(obj:
|
|
5
|
+
export declare function hashObject(obj: {
|
|
6
6
|
[key: string]: any;
|
|
7
|
-
})
|
|
7
|
+
}): string;
|
|
8
8
|
export declare function encodeBase64(data: Uint8Array): string;
|
|
9
9
|
export declare function decodeBase64(data: string): Uint8Array;
|
|
10
10
|
export declare function newToken(size?: number): string;
|
|
@@ -35,7 +35,7 @@ export declare function boxDataWithKeys(data: any, toPublicBoxKey: string, mySec
|
|
|
35
35
|
export declare function isBoxedData(data: any): boolean;
|
|
36
36
|
export declare function openBoxWithSecretKey(box: IDataBox, mySecretKey: string): any;
|
|
37
37
|
export declare function encryptData<T>(data: T, secretKey: string): string;
|
|
38
|
-
export declare function decryptData<T>(encryptedData: string, secretKey: string):
|
|
38
|
+
export declare function decryptData<T>(encryptedData: string, secretKey: string): T | null;
|
|
39
39
|
export type IObjectWithSignature<T> = T & {
|
|
40
40
|
signature: string;
|
|
41
41
|
};
|
package/dist/keys.js
CHANGED
|
@@ -25,14 +25,14 @@ exports.isObjectSignatureValid = isObjectSignatureValid;
|
|
|
25
25
|
exports.getPublicKeyFromObjectSignature = getPublicKeyFromObjectSignature;
|
|
26
26
|
const sha2_1 = require("@noble/hashes/sha2");
|
|
27
27
|
const buffer_1 = require("buffer");
|
|
28
|
+
const ed2curve = require("ed2curve");
|
|
28
29
|
const nacl = require("tweetnacl");
|
|
29
30
|
const utils = require("tweetnacl-util");
|
|
30
31
|
const tweetnacl_util_1 = require("tweetnacl-util");
|
|
31
|
-
const ed2curve = require("ed2curve");
|
|
32
32
|
const tx_encoding_1 = require("./device/tx-encoding");
|
|
33
33
|
const serial_json_1 = require("./serial-json");
|
|
34
34
|
globalThis.Buffer = buffer_1.Buffer; // shim for browsers/RN
|
|
35
|
-
const _stableStringify = require(
|
|
35
|
+
const _stableStringify = require("fast-json-stable-stringify");
|
|
36
36
|
function setPRNG(fn) {
|
|
37
37
|
nacl.setPRNG(fn);
|
|
38
38
|
}
|
|
@@ -43,12 +43,10 @@ function hashValue(str) {
|
|
|
43
43
|
const hash = (0, sha2_1.sha256)(new TextEncoder().encode(str));
|
|
44
44
|
return encodeBase64(hash);
|
|
45
45
|
}
|
|
46
|
-
;
|
|
47
46
|
function hashBytes(buffer) {
|
|
48
47
|
const hash = (0, sha2_1.sha256)(buffer);
|
|
49
48
|
return encodeBase64(hash);
|
|
50
49
|
}
|
|
51
|
-
;
|
|
52
50
|
function stableStringify(obj) {
|
|
53
51
|
return _stableStringify(obj);
|
|
54
52
|
}
|
|
@@ -60,15 +58,15 @@ function hashObject(obj) {
|
|
|
60
58
|
function encodeBase64(data) {
|
|
61
59
|
// return Buffer.from(data).toString("base64url"); // no padding by default
|
|
62
60
|
const str = utils.encodeBase64(data);
|
|
63
|
-
return str.replace(/\+/g,
|
|
61
|
+
return str.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
64
62
|
}
|
|
65
63
|
function decodeBase64(data) {
|
|
66
|
-
if (typeof data !==
|
|
64
|
+
if (typeof data !== "string") {
|
|
67
65
|
throw new TypeError(`decodeBase64 expected a string but received ${typeof data}`);
|
|
68
66
|
}
|
|
69
|
-
data = data.replace(/-/g,
|
|
67
|
+
data = data.replace(/-/g, "+").replace(/_/g, "/");
|
|
70
68
|
while (data.length % 4 !== 0) {
|
|
71
|
-
data +=
|
|
69
|
+
data += "=";
|
|
72
70
|
}
|
|
73
71
|
return utils.decodeBase64(data);
|
|
74
72
|
}
|
|
@@ -96,22 +94,22 @@ function hydrateKeys(secretKey) {
|
|
|
96
94
|
};
|
|
97
95
|
}
|
|
98
96
|
function signMessageWithSecretKey(msg, secretKey) {
|
|
99
|
-
|
|
97
|
+
const _secretKey = decodeBase64(secretKey);
|
|
100
98
|
const msgDecoded = (0, tweetnacl_util_1.decodeUTF8)(msg);
|
|
101
99
|
const msgSigned = nacl.sign(msgDecoded, _secretKey);
|
|
102
100
|
return encodeBase64(msgSigned);
|
|
103
101
|
}
|
|
104
102
|
function openMessageWithPublicKey(msg, publicKey) {
|
|
105
|
-
|
|
103
|
+
const _publicKey = decodeBase64(publicKey);
|
|
106
104
|
const msgDecoded = decodeBase64(msg);
|
|
107
105
|
const msgOpened = nacl.sign.open(msgDecoded, _publicKey);
|
|
108
106
|
if (!msgOpened) {
|
|
109
|
-
throw new Error(
|
|
107
|
+
throw new Error("Failed to open message");
|
|
110
108
|
}
|
|
111
109
|
return (0, tweetnacl_util_1.encodeUTF8)(msgOpened);
|
|
112
110
|
}
|
|
113
111
|
function signObjectWithSecretKey(obj, secretKey) {
|
|
114
|
-
|
|
112
|
+
const _secretKey = decodeBase64(secretKey);
|
|
115
113
|
if (obj === undefined) {
|
|
116
114
|
obj = { __isUndefined: true };
|
|
117
115
|
}
|
|
@@ -128,27 +126,27 @@ function signObjectWithSecretKey(obj, secretKey) {
|
|
|
128
126
|
};
|
|
129
127
|
}
|
|
130
128
|
function openSignedObject(signedObj) {
|
|
131
|
-
|
|
129
|
+
const _publicKey = decodeBase64(signedObj.publicKey);
|
|
132
130
|
const objStr = (0, serial_json_1.toJSONString)(signedObj.contents);
|
|
133
131
|
const objDecoded = (0, tweetnacl_util_1.decodeUTF8)(objStr);
|
|
134
132
|
const signature = decodeBase64(signedObj.signature);
|
|
135
133
|
const valid = nacl.sign.detached.verify(objDecoded, signature, _publicKey);
|
|
136
134
|
if (!valid) {
|
|
137
|
-
throw new Error(
|
|
135
|
+
throw new Error("Signature verification failed");
|
|
138
136
|
}
|
|
139
137
|
const result = signedObj.contents;
|
|
140
138
|
if (result?.__isUndefined && Object.keys(result).length === 1) {
|
|
141
|
-
// @ts-
|
|
139
|
+
// @ts-expect-error
|
|
142
140
|
return undefined;
|
|
143
141
|
}
|
|
144
142
|
if (result?.__isNull && Object.keys(result).length === 1) {
|
|
145
|
-
// @ts-
|
|
143
|
+
// @ts-expect-error
|
|
146
144
|
return null;
|
|
147
145
|
}
|
|
148
146
|
return signedObj.contents;
|
|
149
147
|
}
|
|
150
148
|
function boxDataWithKeys(data, toPublicBoxKey, mySecretKey) {
|
|
151
|
-
|
|
149
|
+
const _secretKey = decodeBase64(mySecretKey);
|
|
152
150
|
const curveSecret = ed2curve.convertSecretKey(_secretKey);
|
|
153
151
|
const boxKeyPair = nacl.box.keyPair.fromSecretKey(curveSecret);
|
|
154
152
|
const _toPublicBoxKey = decodeBase64(toPublicBoxKey);
|
|
@@ -162,10 +160,13 @@ function boxDataWithKeys(data, toPublicBoxKey, mySecretKey) {
|
|
|
162
160
|
};
|
|
163
161
|
}
|
|
164
162
|
function isBoxedData(data) {
|
|
165
|
-
return typeof data ===
|
|
163
|
+
return (typeof data === "object" &&
|
|
164
|
+
typeof data.contents === "string" &&
|
|
165
|
+
typeof data.nonce === "string" &&
|
|
166
|
+
typeof data.fromPublicKey === "string");
|
|
166
167
|
}
|
|
167
168
|
function openBoxWithSecretKey(box, mySecretKey) {
|
|
168
|
-
|
|
169
|
+
const _secretKey = decodeBase64(mySecretKey);
|
|
169
170
|
const curveSecret = ed2curve.convertSecretKey(_secretKey);
|
|
170
171
|
const boxKeyPair = nacl.box.keyPair.fromSecretKey(curveSecret);
|
|
171
172
|
const boxedData = decodeBase64(box.contents);
|
|
@@ -173,25 +174,25 @@ function openBoxWithSecretKey(box, mySecretKey) {
|
|
|
173
174
|
const _fromPublicBoxKey = decodeBase64(box.fromPublicKey);
|
|
174
175
|
const dataByteArray = nacl.box.open(boxedData, nonce, _fromPublicBoxKey, boxKeyPair.secretKey);
|
|
175
176
|
if (dataByteArray === null) {
|
|
176
|
-
throw new Error(
|
|
177
|
+
throw new Error("Message was null or verification failed");
|
|
177
178
|
}
|
|
178
179
|
return (0, tx_encoding_1.txDecode)(dataByteArray);
|
|
179
180
|
}
|
|
180
181
|
function encryptString(data, secretKey) {
|
|
181
|
-
|
|
182
|
+
const _secretKey = decodeBase64(secretKey);
|
|
182
183
|
const _data = (0, tweetnacl_util_1.decodeUTF8)(data);
|
|
183
184
|
const nonce = nacl.randomBytes(24);
|
|
184
185
|
const encryptedData = nacl.secretbox(_data, nonce, _secretKey.slice(0, 32));
|
|
185
186
|
return `${encodeBase64(encryptedData)}~${encodeBase64(nonce)}`;
|
|
186
187
|
}
|
|
187
188
|
function decryptString(data, secretKey) {
|
|
188
|
-
|
|
189
|
-
const [encryptedData, nonce] = data.split(
|
|
189
|
+
const _secretKey = decodeBase64(secretKey);
|
|
190
|
+
const [encryptedData, nonce] = data.split("~");
|
|
190
191
|
const _data = decodeBase64(encryptedData);
|
|
191
192
|
const _nonce = decodeBase64(nonce);
|
|
192
193
|
const decryptedData = nacl.secretbox.open(_data, _nonce, _secretKey.slice(0, 32));
|
|
193
194
|
if (decryptedData === null) {
|
|
194
|
-
throw new Error(
|
|
195
|
+
throw new Error("Failed to decrypt data");
|
|
195
196
|
}
|
|
196
197
|
return (0, tweetnacl_util_1.encodeUTF8)(decryptedData);
|
|
197
198
|
}
|
|
@@ -215,29 +216,29 @@ function addSignatureToObject(obj, secretKey) {
|
|
|
215
216
|
*/
|
|
216
217
|
function verifyObjectSignature(objectWithSignature) {
|
|
217
218
|
if (!objectWithSignature.signature) {
|
|
218
|
-
throw new Error(
|
|
219
|
+
throw new Error("Object has no signature to verify");
|
|
219
220
|
}
|
|
220
221
|
const objWithoutSignature = { ...objectWithSignature };
|
|
221
222
|
delete objWithoutSignature.signature;
|
|
222
|
-
const [objPublicKey, objSignature] = objectWithSignature.signature.split(
|
|
223
|
+
const [objPublicKey, objSignature] = objectWithSignature.signature.split(":");
|
|
223
224
|
const signedObject = {
|
|
224
225
|
contents: objWithoutSignature,
|
|
225
226
|
signature: objSignature,
|
|
226
|
-
publicKey: objPublicKey
|
|
227
|
+
publicKey: objPublicKey,
|
|
227
228
|
};
|
|
228
|
-
openSignedObject(signedObject); // will throw if invalid
|
|
229
|
+
openSignedObject(signedObject); // will throw if invalid
|
|
229
230
|
}
|
|
230
231
|
function isObjectSignatureValid(objectWithSignature) {
|
|
231
232
|
try {
|
|
232
233
|
verifyObjectSignature(objectWithSignature);
|
|
233
234
|
}
|
|
234
|
-
catch (
|
|
235
|
+
catch (_error) {
|
|
235
236
|
return false;
|
|
236
237
|
}
|
|
237
238
|
return true;
|
|
238
239
|
}
|
|
239
240
|
function getPublicKeyFromObjectSignature(objectWithSignature) {
|
|
240
|
-
const parts = objectWithSignature.signature?.split(
|
|
241
|
+
const parts = objectWithSignature.signature?.split(":");
|
|
241
242
|
if (!parts || parts.length !== 2) {
|
|
242
243
|
return undefined;
|
|
243
244
|
}
|
package/dist/keys.test.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const keys_1 = require("./keys");
|
|
4
|
-
describe(
|
|
5
|
-
it(
|
|
4
|
+
describe("keys", () => {
|
|
5
|
+
it("should allow creating a new key pair", () => {
|
|
6
6
|
const keys = (0, keys_1.newKeys)();
|
|
7
7
|
expect(keys.publicKey).toBeTruthy();
|
|
8
8
|
expect(keys.secretKey).toBeTruthy();
|
|
9
9
|
expect(keys.publicBoxKey).toBeTruthy();
|
|
10
10
|
});
|
|
11
|
-
describe(
|
|
12
|
-
it(
|
|
11
|
+
describe("message signing", () => {
|
|
12
|
+
it("should allow signing a message with a secret key and opening it with the corresponding public key", () => {
|
|
13
13
|
const keys = (0, keys_1.newKeys)();
|
|
14
|
-
const msg =
|
|
14
|
+
const msg = "hello world";
|
|
15
15
|
const signed = (0, keys_1.signMessageWithSecretKey)(msg, keys.secretKey);
|
|
16
16
|
expect(signed).toBeTruthy();
|
|
17
17
|
expect(signed).not.toEqual(msg);
|
|
@@ -19,26 +19,26 @@ describe('keys', () => {
|
|
|
19
19
|
expect(opened).toEqual(msg);
|
|
20
20
|
});
|
|
21
21
|
});
|
|
22
|
-
describe(
|
|
23
|
-
it(
|
|
22
|
+
describe("object signing", () => {
|
|
23
|
+
it("should allow signing an object with a secret key and opening it with the corresponding public key", () => {
|
|
24
24
|
const keys = (0, keys_1.newKeys)();
|
|
25
|
-
const obj = { hello:
|
|
25
|
+
const obj = { hello: "world" };
|
|
26
26
|
const signed = (0, keys_1.signObjectWithSecretKey)(obj, keys.secretKey);
|
|
27
27
|
expect(signed).toBeTruthy();
|
|
28
28
|
expect(signed).not.toEqual(obj);
|
|
29
29
|
const opened = (0, keys_1.openSignedObject)(signed);
|
|
30
30
|
expect(opened).toEqual(obj);
|
|
31
31
|
});
|
|
32
|
-
it(
|
|
32
|
+
it("should throw an error if the data changes after the signature", () => {
|
|
33
33
|
const keys = (0, keys_1.newKeys)();
|
|
34
|
-
const obj = { hello:
|
|
34
|
+
const obj = { hello: "world" };
|
|
35
35
|
const signed = (0, keys_1.signObjectWithSecretKey)(obj, keys.secretKey);
|
|
36
36
|
expect(signed).toBeTruthy();
|
|
37
|
-
signed.contents = { hello:
|
|
37
|
+
signed.contents = { hello: "world2" };
|
|
38
38
|
expect(signed).not.toEqual(obj);
|
|
39
39
|
expect(() => (0, keys_1.openSignedObject)(signed)).toThrow(/signature/i);
|
|
40
40
|
});
|
|
41
|
-
it(
|
|
41
|
+
it("should handle null and undefined gracefully", () => {
|
|
42
42
|
const keys = (0, keys_1.newKeys)();
|
|
43
43
|
const obj = undefined;
|
|
44
44
|
const signed = (0, keys_1.signObjectWithSecretKey)(obj, keys.secretKey);
|
|
@@ -47,7 +47,15 @@ describe('keys', () => {
|
|
|
47
47
|
const opened = (0, keys_1.openSignedObject)(signed);
|
|
48
48
|
expect(opened).toEqual(obj);
|
|
49
49
|
});
|
|
50
|
-
it.each([
|
|
50
|
+
it.each([
|
|
51
|
+
false,
|
|
52
|
+
true,
|
|
53
|
+
0,
|
|
54
|
+
1,
|
|
55
|
+
Math.PI,
|
|
56
|
+
"",
|
|
57
|
+
"s",
|
|
58
|
+
])(`should handle simple values: \`%s\``, (value) => {
|
|
51
59
|
const keys = (0, keys_1.newKeys)();
|
|
52
60
|
const signed = (0, keys_1.signObjectWithSecretKey)(value, keys.secretKey);
|
|
53
61
|
expect(signed).toBeTruthy();
|
|
@@ -56,46 +64,46 @@ describe('keys', () => {
|
|
|
56
64
|
expect(opened).toEqual(value);
|
|
57
65
|
});
|
|
58
66
|
});
|
|
59
|
-
describe(
|
|
60
|
-
it(
|
|
67
|
+
describe("message boxing", () => {
|
|
68
|
+
it("should allow boxing data with a public key so it can only be opened with the secret key", () => {
|
|
61
69
|
const from = (0, keys_1.newKeys)();
|
|
62
70
|
const to = (0, keys_1.newKeys)();
|
|
63
|
-
const msg =
|
|
71
|
+
const msg = "hello world";
|
|
64
72
|
const boxed = (0, keys_1.boxDataWithKeys)(msg, to.publicBoxKey, from.secretKey);
|
|
65
73
|
expect(boxed).toBeTruthy();
|
|
66
74
|
const opened = (0, keys_1.openBoxWithSecretKey)(boxed, to.secretKey);
|
|
67
75
|
expect(opened).toEqual(msg);
|
|
68
76
|
});
|
|
69
|
-
it(
|
|
77
|
+
it("should allow boxing objects", () => {
|
|
70
78
|
const from = (0, keys_1.newKeys)();
|
|
71
79
|
const to = (0, keys_1.newKeys)();
|
|
72
|
-
const msg = { hello:
|
|
80
|
+
const msg = { hello: "world" };
|
|
73
81
|
const boxed = (0, keys_1.boxDataWithKeys)(msg, to.publicBoxKey, from.secretKey);
|
|
74
82
|
expect(boxed).toBeTruthy();
|
|
75
83
|
const opened = (0, keys_1.openBoxWithSecretKey)(boxed, to.secretKey);
|
|
76
84
|
expect(opened).toEqual(msg);
|
|
77
85
|
});
|
|
78
86
|
});
|
|
79
|
-
describe(
|
|
80
|
-
it(
|
|
87
|
+
describe("message encryption", () => {
|
|
88
|
+
it("should allow encrypting a message with a secret key so it can only be decrypted with that same secret key", () => {
|
|
81
89
|
const keys = (0, keys_1.newKeys)();
|
|
82
|
-
const msg =
|
|
90
|
+
const msg = "hello world";
|
|
83
91
|
const boxed = (0, keys_1.encryptData)(msg, keys.secretKey);
|
|
84
92
|
expect(boxed).toBeTruthy();
|
|
85
93
|
const opened = (0, keys_1.decryptData)(boxed, keys.secretKey);
|
|
86
94
|
expect(opened).toEqual(msg);
|
|
87
95
|
});
|
|
88
|
-
it(
|
|
96
|
+
it("should allow encrypting objects", () => {
|
|
89
97
|
const keys = (0, keys_1.newKeys)();
|
|
90
|
-
const msg = { hello:
|
|
98
|
+
const msg = { hello: "world" };
|
|
91
99
|
const boxed = (0, keys_1.encryptData)(msg, keys.secretKey);
|
|
92
100
|
expect(boxed).toBeTruthy();
|
|
93
101
|
const opened = (0, keys_1.decryptData)(boxed, keys.secretKey);
|
|
94
102
|
expect(opened).toEqual(msg);
|
|
95
103
|
});
|
|
96
104
|
});
|
|
97
|
-
describe(
|
|
98
|
-
it(
|
|
105
|
+
describe("loading keys", () => {
|
|
106
|
+
it("should allow loading keys from a secret key", () => {
|
|
99
107
|
const keys = (0, keys_1.newKeys)();
|
|
100
108
|
const loadedKeys = (0, keys_1.hydrateKeys)(keys.secretKey);
|
|
101
109
|
expect(loadedKeys.secretKey).toEqual(keys.secretKey);
|
|
@@ -103,22 +111,22 @@ describe('keys', () => {
|
|
|
103
111
|
expect(loadedKeys.publicBoxKey).toEqual(keys.publicBoxKey);
|
|
104
112
|
});
|
|
105
113
|
});
|
|
106
|
-
describe(
|
|
107
|
-
it(
|
|
108
|
-
const data = Buffer.from(
|
|
114
|
+
describe("hashBytes", () => {
|
|
115
|
+
it("should hash buffer data consistently", () => {
|
|
116
|
+
const data = Buffer.from("Hello, World!", "utf8");
|
|
109
117
|
const hash1 = (0, keys_1.hashBytes)(data);
|
|
110
118
|
const hash2 = (0, keys_1.hashBytes)(data);
|
|
111
119
|
expect(hash1).toBe(hash2);
|
|
112
120
|
expect(hash1).toBeTruthy();
|
|
113
121
|
});
|
|
114
|
-
it(
|
|
115
|
-
const data1 = Buffer.from(
|
|
116
|
-
const data2 = Buffer.from(
|
|
122
|
+
it("should produce different hashes for different data", () => {
|
|
123
|
+
const data1 = Buffer.from("Hello, World!", "utf8");
|
|
124
|
+
const data2 = Buffer.from("Hello, World?", "utf8");
|
|
117
125
|
const hash1 = (0, keys_1.hashBytes)(data1);
|
|
118
126
|
const hash2 = (0, keys_1.hashBytes)(data2);
|
|
119
127
|
expect(hash1).not.toBe(hash2);
|
|
120
128
|
});
|
|
121
|
-
it(
|
|
129
|
+
it("should work with binary data", () => {
|
|
122
130
|
// Create binary data with all byte values
|
|
123
131
|
const binaryData = Buffer.alloc(256);
|
|
124
132
|
for (let i = 0; i < 256; i++) {
|
|
@@ -130,81 +138,81 @@ describe('keys', () => {
|
|
|
130
138
|
const hash2 = (0, keys_1.hashBytes)(binaryData);
|
|
131
139
|
expect(hash).toBe(hash2);
|
|
132
140
|
});
|
|
133
|
-
it(
|
|
134
|
-
const text =
|
|
135
|
-
const stringBuffer = Buffer.from(text,
|
|
141
|
+
it("should be equivalent to hashValue for string data", () => {
|
|
142
|
+
const text = "Hello, World!";
|
|
143
|
+
const stringBuffer = Buffer.from(text, "utf8");
|
|
136
144
|
const bufferHash = (0, keys_1.hashBytes)(stringBuffer);
|
|
137
145
|
const stringHash = (0, keys_1.hashValue)(text);
|
|
138
146
|
expect(bufferHash).toBe(stringHash);
|
|
139
147
|
});
|
|
140
|
-
it(
|
|
148
|
+
it("should handle empty buffer", () => {
|
|
141
149
|
const emptyBuffer = Buffer.alloc(0);
|
|
142
150
|
const hash = (0, keys_1.hashBytes)(emptyBuffer);
|
|
143
151
|
expect(hash).toBeTruthy();
|
|
144
152
|
});
|
|
145
|
-
it(
|
|
153
|
+
it("should handle large buffers", () => {
|
|
146
154
|
// 1MB of data
|
|
147
|
-
const largeBuffer = Buffer.alloc(1024 * 1024,
|
|
155
|
+
const largeBuffer = Buffer.alloc(1024 * 1024, "A");
|
|
148
156
|
const hash = (0, keys_1.hashBytes)(largeBuffer);
|
|
149
157
|
expect(hash).toBeTruthy();
|
|
150
158
|
});
|
|
151
159
|
});
|
|
152
|
-
describe(
|
|
153
|
-
it(
|
|
160
|
+
describe("object signature embedding", () => {
|
|
161
|
+
it("should add signature to object and verify it successfully", () => {
|
|
154
162
|
const keys = (0, keys_1.newKeys)();
|
|
155
|
-
const obj = { name:
|
|
163
|
+
const obj = { name: "test", value: 42 };
|
|
156
164
|
const signedObj = (0, keys_1.addSignatureToObject)(obj, keys.secretKey);
|
|
157
|
-
expect(signedObj).toHaveProperty(
|
|
158
|
-
expect(signedObj.name).toBe(
|
|
165
|
+
expect(signedObj).toHaveProperty("signature");
|
|
166
|
+
expect(signedObj.name).toBe("test");
|
|
159
167
|
expect(signedObj.value).toBe(42);
|
|
160
168
|
expect((0, keys_1.isObjectSignatureValid)(signedObj)).toBe(true);
|
|
161
169
|
});
|
|
162
|
-
it(
|
|
170
|
+
it("should fail verification if object is modified after signing", () => {
|
|
163
171
|
const keys = (0, keys_1.newKeys)();
|
|
164
|
-
const obj = { name:
|
|
172
|
+
const obj = { name: "test", value: 42 };
|
|
165
173
|
const signedObj = (0, keys_1.addSignatureToObject)(obj, keys.secretKey);
|
|
166
174
|
signedObj.value = 999; // modify after signing
|
|
167
175
|
expect((0, keys_1.isObjectSignatureValid)(signedObj)).toBe(false);
|
|
168
176
|
});
|
|
169
|
-
it(
|
|
177
|
+
it("should fail verification if signature is tampered with", () => {
|
|
170
178
|
const keys = (0, keys_1.newKeys)();
|
|
171
|
-
const obj = { name:
|
|
179
|
+
const obj = { name: "test", value: 42 };
|
|
172
180
|
const signedObj = (0, keys_1.addSignatureToObject)(obj, keys.secretKey);
|
|
173
|
-
signedObj.signature = signedObj.signature
|
|
181
|
+
signedObj.signature = `${signedObj.signature}tampered`;
|
|
174
182
|
expect((0, keys_1.isObjectSignatureValid)(signedObj)).toBe(false);
|
|
175
183
|
});
|
|
176
|
-
it(
|
|
184
|
+
it("should extract public key from signature", () => {
|
|
177
185
|
const keys = (0, keys_1.newKeys)();
|
|
178
|
-
const obj = { name:
|
|
186
|
+
const obj = { name: "test", value: 42 };
|
|
179
187
|
const signedObj = (0, keys_1.addSignatureToObject)(obj, keys.secretKey);
|
|
180
188
|
const extractedPublicKey = (0, keys_1.getPublicKeyFromObjectSignature)(signedObj);
|
|
181
189
|
expect(extractedPublicKey).toBe(keys.publicKey);
|
|
182
190
|
});
|
|
183
|
-
it(
|
|
184
|
-
const obj = { name:
|
|
191
|
+
it("should return undefined for malformed signature", () => {
|
|
192
|
+
const obj = { name: "test", value: 42, signature: "malformed" };
|
|
185
193
|
const extractedPublicKey = (0, keys_1.getPublicKeyFromObjectSignature)(obj);
|
|
186
194
|
expect(extractedPublicKey).toBeUndefined();
|
|
187
195
|
});
|
|
188
|
-
it(
|
|
196
|
+
it("should handle objects with existing signature property", () => {
|
|
189
197
|
const keys = (0, keys_1.newKeys)();
|
|
190
|
-
const obj = { name:
|
|
198
|
+
const obj = { name: "test", value: 42, signature: "old-signature" };
|
|
191
199
|
const signedObj = (0, keys_1.addSignatureToObject)(obj, keys.secretKey);
|
|
192
|
-
expect(signedObj.signature).not.toBe(
|
|
200
|
+
expect(signedObj.signature).not.toBe("old-signature");
|
|
193
201
|
expect((0, keys_1.isObjectSignatureValid)(signedObj)).toBe(true);
|
|
194
202
|
});
|
|
195
|
-
it(
|
|
203
|
+
it("should work with complex nested objects", () => {
|
|
196
204
|
const keys = (0, keys_1.newKeys)();
|
|
197
205
|
const obj = {
|
|
198
|
-
user: { name:
|
|
199
|
-
settings: { theme:
|
|
200
|
-
data: [1, 2, 3, { nested: true }]
|
|
206
|
+
user: { name: "Alice", age: 30 },
|
|
207
|
+
settings: { theme: "dark", notifications: true },
|
|
208
|
+
data: [1, 2, 3, { nested: true }],
|
|
201
209
|
};
|
|
202
210
|
const signedObj = (0, keys_1.addSignatureToObject)(obj, keys.secretKey);
|
|
203
211
|
expect((0, keys_1.isObjectSignatureValid)(signedObj)).toBe(true);
|
|
204
|
-
expect(signedObj.user.name).toBe(
|
|
212
|
+
expect(signedObj.user.name).toBe("Alice");
|
|
205
213
|
expect(signedObj.data[3].nested).toBe(true);
|
|
206
214
|
});
|
|
207
|
-
it(
|
|
215
|
+
it("should handle empty objects", () => {
|
|
208
216
|
const keys = (0, keys_1.newKeys)();
|
|
209
217
|
const obj = {};
|
|
210
218
|
const signedObj = (0, keys_1.addSignatureToObject)(obj, keys.secretKey);
|