@peers-app/peers-sdk 0.27.3 → 0.27.4

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.
Files changed (258) hide show
  1. package/dist/contracts/contract-proxy.d.ts +7 -0
  2. package/dist/contracts/contract-proxy.js +19 -2
  3. package/dist/contracts/create-local-consumer.js +16 -1
  4. package/dist/contracts/index.d.ts +2 -0
  5. package/dist/contracts/index.js +2 -0
  6. package/dist/contracts/system/index.d.ts +2 -0
  7. package/dist/contracts/system/index.js +2 -0
  8. package/dist/contracts/system/invites-contract.js +2 -1
  9. package/dist/contracts/system/sync-check-contract.d.ts +97 -0
  10. package/dist/contracts/system/sync-check-contract.js +115 -0
  11. package/dist/contracts/tool-arguments.d.ts +15 -0
  12. package/dist/contracts/tool-arguments.js +41 -0
  13. package/dist/contracts/tool-catalog-service.js +2 -12
  14. package/dist/data/change-tracking.d.ts +40 -0
  15. package/dist/data/change-tracking.js +89 -0
  16. package/dist/data/orm/types.d.ts +24 -7
  17. package/dist/data/orm/types.js +97 -24
  18. package/dist/define/manifest.js +6 -34
  19. package/dist/package-loader/package-loader.js +27 -22
  20. package/dist/system-ids.d.ts +5 -0
  21. package/dist/system-ids.js +6 -1
  22. package/package.json +4 -2
  23. package/dist/context/user-context-identity.test.d.ts +0 -1
  24. package/dist/context/user-context-identity.test.js +0 -220
  25. package/dist/contracts/__tests__/action-dispatch.test.d.ts +0 -1
  26. package/dist/contracts/__tests__/action-dispatch.test.js +0 -319
  27. package/dist/contracts/__tests__/also-implements.test.d.ts +0 -1
  28. package/dist/contracts/__tests__/also-implements.test.js +0 -110
  29. package/dist/contracts/__tests__/builder.test.d.ts +0 -1
  30. package/dist/contracts/__tests__/builder.test.js +0 -669
  31. package/dist/contracts/__tests__/contract-events.test.d.ts +0 -1
  32. package/dist/contracts/__tests__/contract-events.test.js +0 -199
  33. package/dist/contracts/__tests__/contract-observables.test.d.ts +0 -1
  34. package/dist/contracts/__tests__/contract-observables.test.js +0 -290
  35. package/dist/contracts/__tests__/contract-provider-router.test.d.ts +0 -1
  36. package/dist/contracts/__tests__/contract-provider-router.test.js +0 -315
  37. package/dist/contracts/__tests__/contract-proxy.test.d.ts +0 -1
  38. package/dist/contracts/__tests__/contract-proxy.test.js +0 -657
  39. package/dist/contracts/__tests__/contract-resolvers.test.d.ts +0 -1
  40. package/dist/contracts/__tests__/contract-resolvers.test.js +0 -758
  41. package/dist/contracts/__tests__/contract-subscription-lifecycle.test.d.ts +0 -1
  42. package/dist/contracts/__tests__/contract-subscription-lifecycle.test.js +0 -353
  43. package/dist/contracts/__tests__/contract-table-events.test.d.ts +0 -1
  44. package/dist/contracts/__tests__/contract-table-events.test.js +0 -209
  45. package/dist/contracts/__tests__/contract-transport.test.d.ts +0 -1
  46. package/dist/contracts/__tests__/contract-transport.test.js +0 -163
  47. package/dist/contracts/__tests__/extract.test.d.ts +0 -1
  48. package/dist/contracts/__tests__/extract.test.js +0 -145
  49. package/dist/contracts/__tests__/frozen-contracts.test.d.ts +0 -1
  50. package/dist/contracts/__tests__/frozen-contracts.test.js +0 -191
  51. package/dist/contracts/__tests__/generic-tool-dispatch.test.d.ts +0 -1
  52. package/dist/contracts/__tests__/generic-tool-dispatch.test.js +0 -130
  53. package/dist/contracts/__tests__/host-contract-client.test.d.ts +0 -1
  54. package/dist/contracts/__tests__/host-contract-client.test.js +0 -793
  55. package/dist/contracts/__tests__/host-contract-consumer.test.d.ts +0 -1
  56. package/dist/contracts/__tests__/host-contract-consumer.test.js +0 -163
  57. package/dist/contracts/__tests__/host-contract-transport.test.d.ts +0 -1
  58. package/dist/contracts/__tests__/host-contract-transport.test.js +0 -66
  59. package/dist/contracts/__tests__/integration.test.d.ts +0 -1
  60. package/dist/contracts/__tests__/integration.test.js +0 -348
  61. package/dist/contracts/__tests__/legacy-removal.test.d.ts +0 -1
  62. package/dist/contracts/__tests__/legacy-removal.test.js +0 -128
  63. package/dist/contracts/__tests__/persistent-registry.test.d.ts +0 -1
  64. package/dist/contracts/__tests__/persistent-registry.test.js +0 -109
  65. package/dist/contracts/__tests__/playground.test.d.ts +0 -1
  66. package/dist/contracts/__tests__/playground.test.js +0 -216
  67. package/dist/contracts/__tests__/registry.test.d.ts +0 -1
  68. package/dist/contracts/__tests__/registry.test.js +0 -238
  69. package/dist/contracts/__tests__/remote-contract-transport.test.d.ts +0 -1
  70. package/dist/contracts/__tests__/remote-contract-transport.test.js +0 -119
  71. package/dist/contracts/__tests__/system-contracts.test.d.ts +0 -1
  72. package/dist/contracts/__tests__/system-contracts.test.js +0 -247
  73. package/dist/contracts/__tests__/target-dispatch.d.ts +0 -11
  74. package/dist/contracts/__tests__/target-dispatch.js +0 -24
  75. package/dist/contracts/__tests__/tool-catalog-inventory.test.d.ts +0 -1
  76. package/dist/contracts/__tests__/tool-catalog-inventory.test.js +0 -44
  77. package/dist/contracts/__tests__/tool-catalog-service.test.d.ts +0 -1
  78. package/dist/contracts/__tests__/tool-catalog-service.test.js +0 -482
  79. package/dist/contracts/__tests__/tool-catalog.test.d.ts +0 -1
  80. package/dist/contracts/__tests__/tool-catalog.test.js +0 -1199
  81. package/dist/contracts/__tests__/validate.test.d.ts +0 -1
  82. package/dist/contracts/__tests__/validate.test.js +0 -991
  83. package/dist/contracts/__tests__/workflow-context.test.d.ts +0 -1
  84. package/dist/contracts/__tests__/workflow-context.test.js +0 -50
  85. package/dist/data/access-level.test.d.ts +0 -1
  86. package/dist/data/access-level.test.js +0 -53
  87. package/dist/data/change-tracking.test.d.ts +0 -1
  88. package/dist/data/change-tracking.test.js +0 -62
  89. package/dist/data/files/files.test.d.ts +0 -1
  90. package/dist/data/files/files.test.js +0 -770
  91. package/dist/data/group-members.test.d.ts +0 -1
  92. package/dist/data/group-members.test.js +0 -336
  93. package/dist/data/group-share.test.d.ts +0 -1
  94. package/dist/data/group-share.test.js +0 -110
  95. package/dist/data/groups.test.d.ts +0 -1
  96. package/dist/data/groups.test.js +0 -153
  97. package/dist/data/orm/cursor.test.d.ts +0 -1
  98. package/dist/data/orm/cursor.test.js +0 -314
  99. package/dist/data/orm/data-query.mongo.test.d.ts +0 -1
  100. package/dist/data/orm/data-query.mongo.test.js +0 -367
  101. package/dist/data/orm/data-query.sqlite.test.d.ts +0 -1
  102. package/dist/data/orm/data-query.sqlite.test.js +0 -365
  103. package/dist/data/orm/data-query.test.d.ts +0 -1
  104. package/dist/data/orm/data-query.test.js +0 -545
  105. package/dist/data/orm/dependency-injection.test.d.ts +0 -1
  106. package/dist/data/orm/dependency-injection.test.js +0 -171
  107. package/dist/data/orm/event-registry.test.d.ts +0 -1
  108. package/dist/data/orm/event-registry.test.js +0 -44
  109. package/dist/data/orm/multi-cursors.test.d.ts +0 -1
  110. package/dist/data/orm/multi-cursors.test.js +0 -463
  111. package/dist/data/orm/sql.data-source.test.d.ts +0 -1
  112. package/dist/data/orm/sql.data-source.test.js +0 -731
  113. package/dist/data/orm/table-container-events.test.d.ts +0 -1
  114. package/dist/data/orm/table-container-events.test.js +0 -101
  115. package/dist/data/orm/table-container.test.d.ts +0 -1
  116. package/dist/data/orm/table-container.test.js +0 -273
  117. package/dist/data/orm/table.event-source.test.d.ts +0 -1
  118. package/dist/data/orm/table.event-source.test.js +0 -331
  119. package/dist/data/orm/types.test.d.ts +0 -1
  120. package/dist/data/orm/types.test.js +0 -409
  121. package/dist/data/package-table-identity.test.d.ts +0 -1
  122. package/dist/data/package-table-identity.test.js +0 -46
  123. package/dist/data/package-version-permissions.test.d.ts +0 -1
  124. package/dist/data/package-version-permissions.test.js +0 -107
  125. package/dist/data/package-version-resolver.test.d.ts +0 -4
  126. package/dist/data/package-version-resolver.test.js +0 -543
  127. package/dist/data/package-versions.test.d.ts +0 -1
  128. package/dist/data/package-versions.test.js +0 -227
  129. package/dist/data/persistent-vars.conflict.test.d.ts +0 -1
  130. package/dist/data/persistent-vars.conflict.test.js +0 -126
  131. package/dist/data/persistent-vars.migration.test.d.ts +0 -1
  132. package/dist/data/persistent-vars.migration.test.js +0 -133
  133. package/dist/data/persistent-vars.package-scope.test.d.ts +0 -1
  134. package/dist/data/persistent-vars.package-scope.test.js +0 -27
  135. package/dist/data/sync-recovery-queue.test.d.ts +0 -1
  136. package/dist/data/sync-recovery-queue.test.js +0 -215
  137. package/dist/data/table-signing.test.d.ts +0 -1
  138. package/dist/data/table-signing.test.js +0 -118
  139. package/dist/data/tool-access.test.d.ts +0 -1
  140. package/dist/data/tool-access.test.js +0 -166
  141. package/dist/data/user-permissions.test.d.ts +0 -1
  142. package/dist/data/user-permissions.test.js +0 -305
  143. package/dist/data/user-trust-levels.test.d.ts +0 -1
  144. package/dist/data/user-trust-levels.test.js +0 -37
  145. package/dist/define/also-implements.test.d.ts +0 -1
  146. package/dist/define/also-implements.test.js +0 -123
  147. package/dist/define/declare-contract.test.d.ts +0 -1
  148. package/dist/define/declare-contract.test.js +0 -573
  149. package/dist/define/define.test.d.ts +0 -1
  150. package/dist/define/define.test.js +0 -1010
  151. package/dist/define/empty-fields.test.d.ts +0 -1
  152. package/dist/define/empty-fields.test.js +0 -55
  153. package/dist/define/events-observables.test.d.ts +0 -1
  154. package/dist/define/events-observables.test.js +0 -1013
  155. package/dist/define/serve-members.test.d.ts +0 -1
  156. package/dist/define/serve-members.test.js +0 -630
  157. package/dist/define/vars.test.d.ts +0 -1
  158. package/dist/define/vars.test.js +0 -39
  159. package/dist/device/binary-peer-connection-v2.test.d.ts +0 -1
  160. package/dist/device/binary-peer-connection-v2.test.js +0 -730
  161. package/dist/device/binary-peer-connection.test.d.ts +0 -1
  162. package/dist/device/binary-peer-connection.test.js +0 -184
  163. package/dist/device/connection.test.d.ts +0 -1
  164. package/dist/device/connection.test.js +0 -613
  165. package/dist/device/device-election.test.d.ts +0 -1
  166. package/dist/device/device-election.test.js +0 -516
  167. package/dist/device/device.test.d.ts +0 -1
  168. package/dist/device/device.test.js +0 -243
  169. package/dist/device/frame-cipher.test.d.ts +0 -1
  170. package/dist/device/frame-cipher.test.js +0 -219
  171. package/dist/device/get-trust-level-fn.test.d.ts +0 -1
  172. package/dist/device/get-trust-level-fn.test.js +0 -685
  173. package/dist/device/streamed-socket.test.d.ts +0 -1
  174. package/dist/device/streamed-socket.test.js +0 -216
  175. package/dist/device/tx-encoding.test.d.ts +0 -1
  176. package/dist/device/tx-encoding.test.js +0 -295
  177. package/dist/device-pairing/cpace.test.d.ts +0 -1
  178. package/dist/device-pairing/cpace.test.js +0 -116
  179. package/dist/device-pairing/device-pairing.test.d.ts +0 -1
  180. package/dist/device-pairing/device-pairing.test.js +0 -211
  181. package/dist/hlc.test.d.ts +0 -1
  182. package/dist/hlc.test.js +0 -45
  183. package/dist/host-credentials.test.d.ts +0 -1
  184. package/dist/host-credentials.test.js +0 -88
  185. package/dist/identity/account-email.test.d.ts +0 -1
  186. package/dist/identity/account-email.test.js +0 -59
  187. package/dist/identity/anchor-document.test.d.ts +0 -1
  188. package/dist/identity/anchor-document.test.js +0 -16
  189. package/dist/identity/anchor-resolution.test.d.ts +0 -1
  190. package/dist/identity/anchor-resolution.test.js +0 -130
  191. package/dist/identity/key-change.test.d.ts +0 -1
  192. package/dist/identity/key-change.test.js +0 -811
  193. package/dist/invites/group-approval.test.d.ts +0 -1
  194. package/dist/invites/group-approval.test.js +0 -223
  195. package/dist/invites/invite-token.test.d.ts +0 -1
  196. package/dist/invites/invite-token.test.js +0 -123
  197. package/dist/keys.test.d.ts +0 -1
  198. package/dist/keys.test.js +0 -336
  199. package/dist/logging/console-logger.test.d.ts +0 -1
  200. package/dist/logging/console-logger.test.js +0 -300
  201. package/dist/logging/console-logs.table.test.d.ts +0 -1
  202. package/dist/logging/console-logs.table.test.js +0 -156
  203. package/dist/observable.test.d.ts +0 -1
  204. package/dist/observable.test.js +0 -309
  205. package/dist/package-build/build-package.test.d.ts +0 -1
  206. package/dist/package-build/build-package.test.js +0 -204
  207. package/dist/package-build/contract-add.test.d.ts +0 -1
  208. package/dist/package-build/contract-add.test.js +0 -467
  209. package/dist/package-build/freeze-contracts.test.d.ts +0 -1
  210. package/dist/package-build/freeze-contracts.test.js +0 -355
  211. package/dist/package-installer/package-author-signing.test.d.ts +0 -1
  212. package/dist/package-installer/package-author-signing.test.js +0 -200
  213. package/dist/package-installer/package-cloner.test.d.ts +0 -1
  214. package/dist/package-installer/package-cloner.test.js +0 -278
  215. package/dist/package-installer/package-creator.test.d.ts +0 -1
  216. package/dist/package-installer/package-creator.test.js +0 -908
  217. package/dist/package-installer/package-dev-tools.test.d.ts +0 -1
  218. package/dist/package-installer/package-dev-tools.test.js +0 -64
  219. package/dist/package-installer/package-installer.test.d.ts +0 -1
  220. package/dist/package-installer/package-installer.test.js +0 -882
  221. package/dist/package-installer/package-propagation.test.d.ts +0 -1
  222. package/dist/package-installer/package-propagation.test.js +0 -1269
  223. package/dist/package-installer/package-publisher.test.d.ts +0 -1
  224. package/dist/package-installer/package-publisher.test.js +0 -153
  225. package/dist/package-installer/package-remote-checker.test.d.ts +0 -1
  226. package/dist/package-installer/package-remote-checker.test.js +0 -334
  227. package/dist/package-installer/package-seed-installer.test.d.ts +0 -1
  228. package/dist/package-installer/package-seed-installer.test.js +0 -123
  229. package/dist/package-installer/package-tarball.test.d.ts +0 -1
  230. package/dist/package-installer/package-tarball.test.js +0 -75
  231. package/dist/package-installer/peers-core-installer.test.d.ts +0 -1
  232. package/dist/package-installer/peers-core-installer.test.js +0 -49
  233. package/dist/package-installer/peers-core-trust-anchor.test.d.ts +0 -1
  234. package/dist/package-installer/peers-core-trust-anchor.test.js +0 -155
  235. package/dist/package-loader/contract-package-loader.test.d.ts +0 -1
  236. package/dist/package-loader/contract-package-loader.test.js +0 -274
  237. package/dist/package-loader/host-authority-loading.test.d.ts +0 -1
  238. package/dist/package-loader/host-authority-loading.test.js +0 -104
  239. package/dist/package-loader/host-dispatch-policy.test.d.ts +0 -1
  240. package/dist/package-loader/host-dispatch-policy.test.js +0 -56
  241. package/dist/package-loader/isolated-artifact.test.d.ts +0 -1
  242. package/dist/package-loader/isolated-artifact.test.js +0 -688
  243. package/dist/package-loader/isolated-persistent-var-gateway.test.d.ts +0 -1
  244. package/dist/package-loader/isolated-persistent-var-gateway.test.js +0 -56
  245. package/dist/package-loader/isolated-table-gateway.test.d.ts +0 -1
  246. package/dist/package-loader/isolated-table-gateway.test.js +0 -633
  247. package/dist/package-loader/package-loader.test.d.ts +0 -1
  248. package/dist/package-loader/package-loader.test.js +0 -1764
  249. package/dist/package-loader/resolve-consumed-contracts.test.d.ts +0 -1
  250. package/dist/package-loader/resolve-consumed-contracts.test.js +0 -166
  251. package/dist/serial-json.compat.test.d.ts +0 -1
  252. package/dist/serial-json.compat.test.js +0 -369
  253. package/dist/serial-json.test.d.ts +0 -1
  254. package/dist/serial-json.test.js +0 -401
  255. package/dist/testing/mock-host-contract.test.d.ts +0 -1
  256. package/dist/testing/mock-host-contract.test.js +0 -782
  257. package/dist/utils.test.d.ts +0 -1
  258. package/dist/utils.test.js +0 -232
@@ -1 +0,0 @@
1
- export {};
@@ -1,216 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const msgpack_1 = require("@msgpack/msgpack");
4
- const utils_1 = require("../utils");
5
- const streamed_socket_1 = require("./streamed-socket");
6
- const tx_encoding_1 = require("./tx-encoding");
7
- // Helper to decode the binary chunk format
8
- function decodeChunk(bytes) {
9
- const view = new DataView(bytes.buffer, bytes.byteOffset);
10
- const metadataLength = view.getUint32(0, false);
11
- const metadataBytes = bytes.subarray(4, 4 + metadataLength);
12
- const metadata = (0, msgpack_1.decode)(metadataBytes);
13
- const data = bytes.subarray(4 + metadataLength);
14
- return { ...metadata, data };
15
- }
16
- function createMockSocket() {
17
- const emittedEvents = [];
18
- const socket = {
19
- id: (0, utils_1.newid)(),
20
- emit(eventName, args, callback) {
21
- emittedEvents.push({ eventName, args, callback });
22
- },
23
- on(_eventName, _handler) {
24
- // Simple mock - we'll manually trigger events in tests
25
- },
26
- removeAllListeners(_eventName) {
27
- // Simple mock
28
- },
29
- disconnect() {
30
- // Simple mock - we'll assume the socket is disconnected
31
- },
32
- };
33
- return {
34
- socket,
35
- getEmittedEvents: () => emittedEvents,
36
- };
37
- }
38
- describe("StreamedSocket", () => {
39
- it("should emit a single chunk for small messages", () => {
40
- const mock = createMockSocket();
41
- const streamedSocket = new streamed_socket_1.StreamedSocket(mock.socket, 1000); // Large chunk size
42
- const testData = { message: "hello" };
43
- streamedSocket.emit("test-event", testData, () => { });
44
- // Should emit a single chunk
45
- const emittedEvents = mock.getEmittedEvents();
46
- expect(emittedEvents).toHaveLength(1);
47
- const chunkEvent = emittedEvents[0];
48
- expect(chunkEvent.eventName).toBe("__streamed-socket-chunk");
49
- // Args should be a Uint8Array (binary encoded chunk)
50
- expect(chunkEvent.args).toBeInstanceOf(Uint8Array);
51
- // Decode the binary chunk
52
- const decodedChunk = decodeChunk(chunkEvent.args);
53
- expect(decodedChunk.messageId).toBeTruthy();
54
- expect(decodedChunk.chunkIndex).toBe(0);
55
- expect(decodedChunk.totalChunks).toBe(1);
56
- expect(decodedChunk.eventName).toBe("test-event");
57
- // Decode the actual data
58
- const decoded = (0, tx_encoding_1.txDecode)(decodedChunk.data);
59
- expect(decoded).toEqual(testData);
60
- });
61
- it("should emit multiple chunks for large messages", () => {
62
- const mock = createMockSocket();
63
- const streamedSocket = new streamed_socket_1.StreamedSocket(mock.socket, 256); // Small chunk size to force chunking
64
- // Create a large test object
65
- const testData = {
66
- message: "x".repeat(200),
67
- array: [1, 2, 3, 4, 5],
68
- nested: { deep: "value" },
69
- };
70
- streamedSocket.emit("test-event", testData, () => { });
71
- const emittedEvents = mock.getEmittedEvents();
72
- expect(emittedEvents.length).toBeGreaterThan(1);
73
- // Decode all chunks
74
- const decodedChunks = emittedEvents.map((event) => {
75
- expect(event.args).toBeInstanceOf(Uint8Array);
76
- return decodeChunk(event.args);
77
- });
78
- // Verify first chunk has metadata
79
- const firstChunk = decodedChunks[0];
80
- expect(firstChunk.eventName).toBe("test-event");
81
- expect(firstChunk.totalChunks).toBe(emittedEvents.length);
82
- expect(firstChunk.chunkIndex).toBe(0);
83
- // Verify all chunks have the same messageId
84
- const messageId = firstChunk.messageId;
85
- decodedChunks.forEach((chunk) => {
86
- expect(chunk.messageId).toBe(messageId);
87
- });
88
- // Verify chunks are in order
89
- decodedChunks.forEach((chunk, index) => {
90
- expect(chunk.chunkIndex).toBe(index);
91
- });
92
- // Verify all chunk data are Uint8Arrays
93
- decodedChunks.forEach((chunk) => {
94
- expect(chunk.data).toBeInstanceOf(Uint8Array);
95
- });
96
- // Reassemble chunks and verify data integrity
97
- const reassembled = new Uint8Array(decodedChunks.reduce((sum, chunk) => sum + chunk.data.length, 0));
98
- let offset = 0;
99
- for (const chunk of decodedChunks) {
100
- reassembled.set(chunk.data, offset);
101
- offset += chunk.data.length;
102
- }
103
- const decoded = (0, tx_encoding_1.txDecode)(reassembled);
104
- expect(decoded).toEqual(testData);
105
- });
106
- it("should handle binary data in messages", () => {
107
- const mock = createMockSocket();
108
- const streamedSocket = new streamed_socket_1.StreamedSocket(mock.socket, 1000);
109
- const testData = {
110
- binaryData: new Uint8Array([1, 2, 3, 4, 5]),
111
- metadata: { name: "test" },
112
- };
113
- streamedSocket.emit("test-event", testData, () => { });
114
- const emittedEvents = mock.getEmittedEvents();
115
- expect(emittedEvents).toHaveLength(1);
116
- const decodedChunk = decodeChunk(emittedEvents[0].args);
117
- const decoded = (0, tx_encoding_1.txDecode)(decodedChunk.data);
118
- expect(decoded.binaryData).toBeInstanceOf(Uint8Array);
119
- expect(decoded.binaryData).toEqual(testData.binaryData);
120
- expect(decoded.metadata).toEqual(testData.metadata);
121
- });
122
- it("should handle special types in messages", () => {
123
- const mock = createMockSocket();
124
- const streamedSocket = new streamed_socket_1.StreamedSocket(mock.socket, 1000);
125
- const testData = {
126
- date: new Date("2023-01-01T00:00:00.000Z"),
127
- nan: NaN,
128
- infinity: Infinity,
129
- undef: undefined,
130
- nullVal: null,
131
- };
132
- streamedSocket.emit("test-event", testData, () => { });
133
- const emittedEvents = mock.getEmittedEvents();
134
- expect(emittedEvents).toHaveLength(1);
135
- const decodedChunk = decodeChunk(emittedEvents[0].args);
136
- const decoded = (0, tx_encoding_1.txDecode)(decodedChunk.data);
137
- expect(decoded.date).toBeInstanceOf(Date);
138
- expect(decoded.date.toISOString()).toBe("2023-01-01T00:00:00.000Z");
139
- expect(Number.isNaN(decoded.nan)).toBe(true);
140
- expect(decoded.infinity).toBe(Infinity);
141
- expect(decoded.undef).toBeUndefined();
142
- expect(decoded.nullVal).toBeNull();
143
- });
144
- it("should demonstrate msgpack efficiency: structured data vs JSON string (uncompressed)", () => {
145
- const mock1 = createMockSocket();
146
- const mock2 = createMockSocket();
147
- const streamedSocket1 = new streamed_socket_1.StreamedSocket(mock1.socket, 1000000); // Large chunk to avoid splitting
148
- const streamedSocket2 = new streamed_socket_1.StreamedSocket(mock2.socket, 1000000);
149
- // Create a small structured object that won't trigger compression (< 1024 bytes)
150
- const smallObject = {
151
- users: Array.from({ length: 5 }, (_, i) => ({
152
- id: i + 1000000, // Use larger numbers to make JSON less compressible
153
- name: `User${i}_${Math.random().toString(36).substring(7)}`, // Add randomness
154
- email: `user${i}@example.com`,
155
- score: Math.random() * 1000,
156
- active: i % 2 === 0,
157
- })),
158
- };
159
- // Convert to JSON string
160
- const jsonString = JSON.stringify(smallObject);
161
- console.log(`Original JSON string size: ${jsonString.length} bytes`);
162
- // Send as structured object (msgpack can optimize)
163
- streamedSocket1.emit("test-object", smallObject, () => { });
164
- // Send as JSON string (msgpack treats it as opaque string)
165
- streamedSocket2.emit("test-string", { jsonPayload: jsonString }, () => { });
166
- const objectEvents = mock1.getEmittedEvents();
167
- const stringEvents = mock2.getEmittedEvents();
168
- expect(objectEvents).toHaveLength(1);
169
- expect(stringEvents).toHaveLength(1);
170
- // Decode and measure sizes
171
- const objectChunk = decodeChunk(objectEvents[0].args);
172
- const stringChunk = decodeChunk(stringEvents[0].args);
173
- const objectSize = objectChunk.data.length;
174
- const stringSize = stringChunk.data.length;
175
- console.log(`Msgpack with structured data: ${objectSize} bytes (${((1 - objectSize / jsonString.length) * 100).toFixed(1)}% reduction from JSON)`);
176
- console.log(`Msgpack with JSON string: ${stringSize} bytes (${((1 - stringSize / jsonString.length) * 100).toFixed(1)}% reduction from JSON)`);
177
- console.log(`Efficiency gain: structured data is ${((1 - objectSize / stringSize) * 100).toFixed(1)}% smaller than JSON string`);
178
- // Msgpack should be more efficient with structured data than with a JSON string
179
- expect(objectSize).toBeLessThan(stringSize);
180
- // Structured data should be at least 10% more efficient
181
- const efficiency = (1 - objectSize / stringSize) * 100;
182
- expect(efficiency).toBeGreaterThan(10);
183
- // Verify data integrity
184
- const decodedObject = (0, tx_encoding_1.txDecode)(objectChunk.data);
185
- const decodedString = (0, tx_encoding_1.txDecode)(stringChunk.data);
186
- expect(decodedObject.users).toHaveLength(5);
187
- expect(decodedString.jsonPayload).toBe(jsonString);
188
- });
189
- it("should demonstrate compression effectiveness for large repetitive data", () => {
190
- const mock = createMockSocket();
191
- const streamedSocket = new streamed_socket_1.StreamedSocket(mock.socket, 1000000);
192
- // Create large repetitive object that will compress well
193
- const largeObject = {
194
- data: Array.from({ length: 200 }, () => ({
195
- type: "event",
196
- status: "active",
197
- category: "user_action",
198
- timestamp: new Date("2024-01-01"),
199
- metadata: { app: "test", version: "1.0.0" },
200
- })),
201
- };
202
- const jsonString = JSON.stringify(largeObject);
203
- console.log(`Large repetitive data - JSON size: ${jsonString.length} bytes`);
204
- streamedSocket.emit("test-compressed", largeObject, () => { });
205
- const events = mock.getEmittedEvents();
206
- const chunk = decodeChunk(events[0].args);
207
- console.log(`After msgpack + compression: ${chunk.data.length} bytes`);
208
- console.log(`Compression ratio: ${((1 - chunk.data.length / jsonString.length) * 100).toFixed(1)}% reduction`);
209
- // Should achieve significant compression (>80% reduction)
210
- expect(chunk.data.length).toBeLessThan(jsonString.length * 0.2);
211
- // Verify data integrity
212
- const decoded = (0, tx_encoding_1.txDecode)(chunk.data);
213
- expect(decoded.data).toHaveLength(200);
214
- expect(decoded.data[0].type).toBe("event");
215
- });
216
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,295 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const msgpack_1 = require("@msgpack/msgpack");
4
- const serial_json_1 = require("../serial-json");
5
- const tx_encoding_1 = require("./tx-encoding");
6
- describe("tx-encode-decode", () => {
7
- describe("txEncode and txDecode", () => {
8
- it("should encode and decode simple objects", () => {
9
- const testObj = {
10
- name: "test",
11
- number: 42,
12
- bool: true,
13
- str: "hello world",
14
- };
15
- const encoded = (0, tx_encoding_1.txEncode)(testObj);
16
- expect(encoded).toBeInstanceOf(Uint8Array);
17
- expect(encoded.length).toBeGreaterThan(0);
18
- const decoded = (0, tx_encoding_1.txDecode)(encoded);
19
- expect(decoded).toEqual(testObj);
20
- });
21
- it("should encode and decode arrays", () => {
22
- const testArray = [1, 2, 3, "four", { five: 5 }];
23
- const encoded = (0, tx_encoding_1.txEncode)(testArray);
24
- const decoded = (0, tx_encoding_1.txDecode)(encoded);
25
- expect(decoded).toEqual(testArray);
26
- });
27
- it("should encode and decode nested objects", () => {
28
- const testObj = {
29
- level1: {
30
- level2: {
31
- level3: {
32
- value: "deep nested value",
33
- number: 123,
34
- },
35
- array: [1, 2, 3],
36
- },
37
- },
38
- };
39
- const encoded = (0, tx_encoding_1.txEncode)(testObj);
40
- const decoded = (0, tx_encoding_1.txDecode)(encoded);
41
- expect(decoded).toEqual(testObj);
42
- });
43
- it("should encode and decode special types (dates, etc.)", () => {
44
- const testObj = {
45
- date: new Date("2023-01-01T00:00:00.000Z"),
46
- nan: NaN,
47
- infinity: Infinity,
48
- negInfinity: -Infinity,
49
- undef: undefined,
50
- nullVal: null,
51
- };
52
- const encoded = (0, tx_encoding_1.txEncode)(testObj);
53
- const decoded = (0, tx_encoding_1.txDecode)(encoded);
54
- expect(decoded.date).toBeInstanceOf(Date);
55
- expect(decoded.date.toISOString()).toBe("2023-01-01T00:00:00.000Z");
56
- expect(Number.isNaN(decoded.nan)).toBe(true);
57
- expect(decoded.infinity).toBe(Infinity);
58
- expect(decoded.negInfinity).toBe(-Infinity);
59
- expect(decoded.undef).toBeUndefined();
60
- expect(decoded.nullVal).toBeNull();
61
- });
62
- it("should encode and decode Uint8Array", () => {
63
- const testObj = {
64
- data: new Uint8Array([72, 101, 108, 108, 111]),
65
- metadata: { size: 5 },
66
- };
67
- const encoded = (0, tx_encoding_1.txEncode)(testObj);
68
- const decoded = (0, tx_encoding_1.txDecode)(encoded);
69
- expect(decoded.data).toBeInstanceOf(Uint8Array);
70
- expect(decoded.data).toEqual(testObj.data);
71
- expect(decoded.metadata).toEqual(testObj.metadata);
72
- });
73
- it("should encode and decode Buffer", () => {
74
- const testObj = {
75
- buffer: Buffer.from("Hello Buffer"),
76
- name: "test",
77
- };
78
- const encoded = (0, tx_encoding_1.txEncode)(testObj);
79
- const decoded = (0, tx_encoding_1.txDecode)(encoded);
80
- expect(Buffer.isBuffer(decoded.buffer)).toBe(true);
81
- expect(decoded.buffer).toEqual(testObj.buffer);
82
- expect(decoded.name).toBe("test");
83
- });
84
- });
85
- describe("compression threshold", () => {
86
- it("should not compress small payloads (< 1024 bytes)", () => {
87
- const smallObj = { message: "small" };
88
- const encoded = (0, tx_encoding_1.txEncode)(smallObj);
89
- // First byte is the flag
90
- expect(encoded[0]).toBe(0); // flag = 0 means not compressed
91
- });
92
- it("should compress large payloads (> 1024 bytes)", () => {
93
- // Create an object that will exceed 8KB when msgpack-encoded
94
- // msgpack is more compact than JSON, so we need significantly more data
95
- // A string of 20,000 chars is roughly 20KB in JSON, but msgpack uses length prefix + bytes
96
- // So we need even more to ensure msgpack encoding exceeds 8KB
97
- const largeObj = {
98
- data: "x".repeat(30000),
99
- array: Array.from({ length: 1000 }, (_, i) => ({
100
- id: i,
101
- value: `item ${i} with some extra text to make it larger and ensure we exceed the threshold`,
102
- nested: { prop: `nested value ${i}` },
103
- })),
104
- };
105
- const encoded = (0, tx_encoding_1.txEncode)(largeObj);
106
- // Verify the encoded size (without flag byte) exceeds 8KB threshold
107
- const encodedSize = encoded.length - 1; // subtract flag byte
108
- expect(encodedSize).toBeGreaterThan(8 * 1024);
109
- // First byte is the flag
110
- expect(encoded[0]).toBe(1); // flag = 1 means compressed
111
- // Verify it can still be decoded correctly
112
- const decoded = (0, tx_encoding_1.txDecode)(encoded);
113
- expect(decoded).toEqual(largeObj);
114
- });
115
- it("should have smaller encoded size for large compressible data", () => {
116
- // Create data that exceeds 8KB when msgpack-encoded and compresses well
117
- // Use data with some repetition but also enough variety to ensure msgpack size is large
118
- const largeRepetitiveObj = {
119
- data: "repeat ".repeat(10000), // Highly repetitive string - will compress well
120
- values: Array.from({ length: 5000 }, (_, i) => `item ${i} with some text that repeats to create compressible data pattern`),
121
- };
122
- // First, verify the msgpack-encoded size exceeds 8KB threshold
123
- const noCycles = (0, serial_json_1.toJSON)(largeRepetitiveObj);
124
- const msgpackEncoded = (0, msgpack_1.encode)(noCycles);
125
- expect(msgpackEncoded.length).toBeGreaterThan(8 * 1024);
126
- const encoded = (0, tx_encoding_1.txEncode)(largeRepetitiveObj);
127
- // Verify compression flag is set (means compression was applied)
128
- expect(encoded[0]).toBe(1); // flag = 1 means compressed
129
- // Compressed size should be significantly smaller than the raw msgpack data
130
- const compressedSize = encoded.length - 1; // subtract flag byte
131
- expect(compressedSize).toBeLessThan(msgpackEncoded.length * 0.8); // Should be at least 20% smaller
132
- // Verify correctness
133
- const decoded = (0, tx_encoding_1.txDecode)(encoded);
134
- expect(decoded).toEqual(largeRepetitiveObj);
135
- });
136
- });
137
- describe("error handling", () => {
138
- it("should throw error on empty payload", () => {
139
- const emptyPayload = new Uint8Array(0);
140
- expect(() => (0, tx_encoding_1.txDecode)(emptyPayload)).toThrow("Empty payload");
141
- });
142
- it("should throw error on unknown flag", () => {
143
- // Create a payload with an invalid flag (2)
144
- const invalidPayload = new Uint8Array([2, 0, 0, 0]);
145
- expect(() => (0, tx_encoding_1.txDecode)(invalidPayload)).toThrow("Unknown tx flag: 2");
146
- });
147
- it("should throw error on unknown flag (255)", () => {
148
- const invalidPayload = new Uint8Array([255, 0, 0, 0]);
149
- expect(() => (0, tx_encoding_1.txDecode)(invalidPayload)).toThrow("Unknown tx flag: 255");
150
- });
151
- });
152
- describe("untrusted input", () => {
153
- afterEach(() => {
154
- delete Object.prototype.polluted;
155
- });
156
- it("does not let a decoded message write onto Object.prototype", () => {
157
- const decoded = (0, tx_encoding_1.txDecode)((0, tx_encoding_1.txEncode)({ __this_ref: "__proto__", polluted: "yes" }));
158
- expect({}.polluted).toBeUndefined();
159
- expect(decoded).toEqual({ polluted: "yes" });
160
- });
161
- });
162
- describe("round-trip consistency", () => {
163
- it("should handle empty objects", () => {
164
- const emptyObj = {};
165
- const encoded = (0, tx_encoding_1.txEncode)(emptyObj);
166
- const decoded = (0, tx_encoding_1.txDecode)(encoded);
167
- expect(decoded).toEqual(emptyObj);
168
- });
169
- it("should handle empty arrays", () => {
170
- const emptyArray = [];
171
- const encoded = (0, tx_encoding_1.txEncode)(emptyArray);
172
- const decoded = (0, tx_encoding_1.txDecode)(encoded);
173
- expect(decoded).toEqual(emptyArray);
174
- });
175
- it("should handle strings with special characters", () => {
176
- const testObj = {
177
- emoji: "🚀🎉",
178
- unicode: "Hello 世界",
179
- special: "line1\nline2\ttab",
180
- quotes: 'He said "hello"',
181
- };
182
- const encoded = (0, tx_encoding_1.txEncode)(testObj);
183
- const decoded = (0, tx_encoding_1.txDecode)(encoded);
184
- expect(decoded).toEqual(testObj);
185
- });
186
- it("should handle very large numbers", () => {
187
- const testObj = {
188
- maxSafeInt: Number.MAX_SAFE_INTEGER,
189
- minSafeInt: Number.MIN_SAFE_INTEGER,
190
- large: 9007199254740991,
191
- small: -9007199254740991,
192
- };
193
- const encoded = (0, tx_encoding_1.txEncode)(testObj);
194
- const decoded = (0, tx_encoding_1.txDecode)(encoded);
195
- expect(decoded).toEqual(testObj);
196
- });
197
- it("should handle mixed type arrays", () => {
198
- const testArray = [
199
- 1,
200
- "string",
201
- true,
202
- null,
203
- undefined,
204
- { obj: "value" },
205
- [1, 2, 3],
206
- new Date("2023-01-01"),
207
- new Uint8Array([1, 2, 3]),
208
- ];
209
- const encoded = (0, tx_encoding_1.txEncode)(testArray);
210
- const decoded = (0, tx_encoding_1.txDecode)(encoded);
211
- expect(decoded[0]).toBe(1);
212
- expect(decoded[1]).toBe("string");
213
- expect(decoded[2]).toBe(true);
214
- expect(decoded[3]).toBeNull();
215
- expect(decoded[4]).toBeUndefined();
216
- expect(decoded[5]).toEqual({ obj: "value" });
217
- expect(decoded[6]).toEqual([1, 2, 3]);
218
- expect(decoded[7]).toBeInstanceOf(Date);
219
- expect(decoded[8]).toBeInstanceOf(Uint8Array);
220
- expect(decoded[8]).toEqual(new Uint8Array([1, 2, 3]));
221
- });
222
- it("should handle objects with circular references removed by toJSON", () => {
223
- // toJSON handles circular references, so this should work
224
- const obj = { name: "test" };
225
- obj.self = obj; // circular reference
226
- const encoded = (0, tx_encoding_1.txEncode)(obj);
227
- const decoded = (0, tx_encoding_1.txDecode)(encoded);
228
- // The circular reference should be handled by toJSON/fromJSON
229
- expect(decoded).toHaveProperty("name", "test");
230
- expect(decoded).toHaveProperty("self");
231
- expect(decoded.self).toBe(decoded); // self-reference restored
232
- });
233
- it("should preserve data integrity across multiple encode/decode cycles", () => {
234
- const original = {
235
- id: 123,
236
- name: "multi-cycle test",
237
- data: new Uint8Array([1, 2, 3, 4, 5]),
238
- timestamp: new Date("2023-06-15T12:00:00.000Z"),
239
- };
240
- // Encode and decode multiple times
241
- let current = original;
242
- for (let i = 0; i < 5; i++) {
243
- const encoded = (0, tx_encoding_1.txEncode)(current);
244
- current = (0, tx_encoding_1.txDecode)(encoded);
245
- }
246
- expect(current.id).toBe(original.id);
247
- expect(current.name).toBe(original.name);
248
- expect(current.data).toEqual(original.data);
249
- expect(current.timestamp).toEqual(original.timestamp);
250
- });
251
- });
252
- describe("payload structure", () => {
253
- it("should have flag byte as first byte", () => {
254
- const testObj = { test: "value" };
255
- const encoded = (0, tx_encoding_1.txEncode)(testObj);
256
- // First byte should be 0 or 1
257
- expect(encoded[0]).toBeGreaterThanOrEqual(0);
258
- expect(encoded[0]).toBeLessThanOrEqual(1);
259
- });
260
- it("should have body after flag byte", () => {
261
- const testObj = { test: "value" };
262
- const encoded = (0, tx_encoding_1.txEncode)(testObj);
263
- // Should have at least 2 bytes (flag + body)
264
- expect(encoded.length).toBeGreaterThan(1);
265
- });
266
- });
267
- describe("edge cases", () => {
268
- it("should handle objects at exactly 1024 bytes threshold", () => {
269
- // Create an object that when msgpack-encoded is very close to 1024 bytes
270
- // This is tricky to get exact, so we just verify it works
271
- const testObj = {
272
- data: "x".repeat(1000),
273
- };
274
- const encoded = (0, tx_encoding_1.txEncode)(testObj);
275
- const decoded = (0, tx_encoding_1.txDecode)(encoded);
276
- expect(decoded).toEqual(testObj);
277
- });
278
- it("should handle primitive values", () => {
279
- expect((0, tx_encoding_1.txDecode)((0, tx_encoding_1.txEncode)(42))).toBe(42);
280
- expect((0, tx_encoding_1.txDecode)((0, tx_encoding_1.txEncode)("string"))).toBe("string");
281
- expect((0, tx_encoding_1.txDecode)((0, tx_encoding_1.txEncode)(true))).toBe(true);
282
- expect((0, tx_encoding_1.txDecode)((0, tx_encoding_1.txEncode)(false))).toBe(false);
283
- expect((0, tx_encoding_1.txDecode)((0, tx_encoding_1.txEncode)(null))).toBe(null);
284
- });
285
- it("should handle objects with only undefined values", () => {
286
- const testObj = {
287
- a: undefined,
288
- b: undefined,
289
- };
290
- const encoded = (0, tx_encoding_1.txEncode)(testObj);
291
- const decoded = (0, tx_encoding_1.txDecode)(encoded);
292
- expect(decoded).toEqual(testObj);
293
- });
294
- });
295
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,116 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const cpace_1 = require("./cpace");
4
- // Test vectors from draft-irtf-cfrg-cpace, "CPace using group X25519 and hash SHA-512".
5
- const VECTOR = {
6
- PRS: "50617373776F7264",
7
- CI: "0B415F696E69746961746F720B425F726573706F6E646572",
8
- sid: "7E4B4791D6A8EF019B936C79FB7F2C57",
9
- g: "D04BF6D41F6A289632A2E929FA29BEBD51092512A7829FDDE7D314B62F05A73F",
10
- ya: "21B4F4BD9E64ED355C3EB676A28EBEDAF6D8F17BDC365995B319097153044080",
11
- ADa: "414461",
12
- Ya: "1D13C89278CDADD826F6D8D7F887701430F8380DDC17611CDD6DC989CE0C9F32",
13
- yb: "848B0779FF415F0AF4EA14DF9DD1D3C29AC41D836C7808896C4EBA19C51AC40A",
14
- ADb: "414462",
15
- Yb: "248CCCF6D5CDC3646F0AD593F9E6CEF4E69D4945F8372E623512ECEA32185623",
16
- K: "5B067EFFBDC0B2A0E1D907B21EBB25CFEDB96A852179A847C37E43EE71322C6B",
17
- ISK_IR: "6E19B875F7A561D6B3CA3DBB9EF42AC55DE3E717881018204B8922B4D5E53BB2AA82C300BEA7B65D2B671DA71922DDF6472301B79BC270ADFA8BF413285F2263",
18
- };
19
- // scalar_mult_vfy vectors: low-order (and non-canonical low-order) inputs abort; the rest
20
- // must produce the draft's exact outputs, proving bit #255 is cleared before the ladder.
21
- const VFY_SCALAR = "AF46E36BF0527C9D3B16154B82465EDD62144C0AC1FC5A18506A2244BA449AFF";
22
- const LOW_ORDER_POINTS = [
23
- "0000000000000000000000000000000000000000000000000000000000000000",
24
- "0100000000000000000000000000000000000000000000000000000000000000",
25
- "ECFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7F",
26
- "E0EB7A7C3B41B8AE1656E3FAF19FC46ADA098DEB9C32B1FD866205165F49B800",
27
- "5F9C95BCA3508C24B1D0B1559C83EF5B04445CC4581C8E86D8224EDDD09F1157",
28
- "EDFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7F",
29
- "EEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7F",
30
- ];
31
- const NON_CANONICAL_POINTS = [
32
- [
33
- "DAFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
34
- "D8E2C776BBACD510D09FD9278B7EDCD25FC5AE9ADFBA3B6E040E8D3B71B21806",
35
- ],
36
- [
37
- "DBFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
38
- "C85C655EBE8BE44BA9C0FFDE69F2FE10194458D137F09BBFF725CE58803CDB38",
39
- ],
40
- [
41
- "D9FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
42
- "DB64DAFA9B8FDD136914E61461935FE92AA372CB056314E1231BC4EC12417456",
43
- ],
44
- [
45
- "CDEB7A7C3B41B8AE1656E3FAF19FC46ADA098DEB9C32B1FD866205165F49B880",
46
- "E062DCD5376D58297BE2618C7498F55BAA07D7E03184E8AADA20BCA28888BF7A",
47
- ],
48
- [
49
- "4C9C95BCA3508C24B1D0B1559C83EF5B04445CC4581C8E86D8224EDDD09F11D7",
50
- "993C6AD11C4C29DA9A56F7691FD0FF8D732E49DE6250B6C2E80003FF4629A175",
51
- ],
52
- ];
53
- function hex(value) {
54
- return Uint8Array.from(Buffer.from(value, "hex"));
55
- }
56
- function toHex(value) {
57
- return Buffer.from(value).toString("hex").toUpperCase();
58
- }
59
- describe("cpace string utilities", () => {
60
- it("matches prepend_len and lv_cat vectors", () => {
61
- expect(toHex((0, cpace_1.cpacePrependLength)(new Uint8Array(0)))).toBe("00");
62
- expect(toHex((0, cpace_1.cpacePrependLength)(Buffer.from("1234")))).toBe("0431323334");
63
- expect(toHex((0, cpace_1.cpacePrependLength)(new Uint8Array(128))).slice(0, 4)).toBe("8001");
64
- expect(toHex((0, cpace_1.cpaceLvCat)(Buffer.from("1234"), Buffer.from("5"), new Uint8Array(0), Buffer.from("678")))).toBe("043132333401350003363738");
65
- });
66
- it("matches transcript_ir vector", () => {
67
- expect(toHex((0, cpace_1.cpaceTranscript)(Buffer.from("123"), Buffer.from("PartyA"), Buffer.from("234"), Buffer.from("PartyB")))).toBe("03313233065061727479410332333406506172747942");
68
- });
69
- });
70
- describe("cpace CPace255 vectors", () => {
71
- it("derives the generator string and secret generator", () => {
72
- const generatorString = (0, cpace_1.cpaceGeneratorString)(hex(VECTOR.PRS), hex(VECTOR.CI), hex(VECTOR.sid));
73
- expect(generatorString).toHaveLength(170);
74
- expect(toHex(generatorString).startsWith("0843506163653235350850617373776F72646D00")).toBe(true);
75
- expect(toHex((0, cpace_1.cpaceCalculateGenerator)(hex(VECTOR.PRS), hex(VECTOR.CI), hex(VECTOR.sid)))).toBe(VECTOR.g);
76
- });
77
- it("derives both shares, the shared point, and the initiator/responder ISK", () => {
78
- const parameters = {
79
- password: hex(VECTOR.PRS),
80
- channelId: hex(VECTOR.CI),
81
- sessionId: hex(VECTOR.sid),
82
- initiatorAd: hex(VECTOR.ADa),
83
- responderAd: hex(VECTOR.ADb),
84
- };
85
- const initiator = (0, cpace_1.cpaceStart)("initiator", parameters, hex(VECTOR.ya));
86
- const responder = (0, cpace_1.cpaceStart)("responder", parameters, hex(VECTOR.yb));
87
- expect(toHex(initiator.share)).toBe(VECTOR.Ya);
88
- expect(toHex(responder.share)).toBe(VECTOR.Yb);
89
- expect(toHex((0, cpace_1.cpaceScalarMultVerify)(hex(VECTOR.ya), hex(VECTOR.Yb)))).toBe(VECTOR.K);
90
- expect(toHex((0, cpace_1.cpaceDeriveIsk)(hex(VECTOR.K), hex(VECTOR.sid), (0, cpace_1.cpaceTranscript)(hex(VECTOR.Ya), hex(VECTOR.ADa), hex(VECTOR.Yb), hex(VECTOR.ADb))))).toBe(VECTOR.ISK_IR);
91
- const initiatorIsk = toHex(initiator.finish(hex(VECTOR.Yb)));
92
- const responderIsk = toHex(responder.finish(hex(VECTOR.Ya)));
93
- expect(initiatorIsk).toBe(VECTOR.ISK_IR);
94
- expect(responderIsk).toBe(VECTOR.ISK_IR);
95
- });
96
- it("rejects low-order points and clears bit #255 of non-canonical inputs", () => {
97
- for (const point of LOW_ORDER_POINTS) {
98
- expect(() => (0, cpace_1.cpaceScalarMultVerify)(hex(VFY_SCALAR), hex(point))).toThrow(/low-order/);
99
- }
100
- for (const [point, expected] of NON_CANONICAL_POINTS) {
101
- expect(toHex((0, cpace_1.cpaceScalarMultVerify)(hex(VFY_SCALAR), hex(point)))).toBe(expected);
102
- }
103
- });
104
- it("produces unrelated keys for different passwords and identical keys for the same password", () => {
105
- const shared = { channelId: Buffer.from("channel"), sessionId: new Uint8Array(0) };
106
- const good = (0, cpace_1.cpaceStart)("initiator", { ...shared, password: Buffer.from("guitar-revenge") });
107
- const right = (0, cpace_1.cpaceStart)("responder", { ...shared, password: Buffer.from("guitar-revenge") });
108
- const wrong = (0, cpace_1.cpaceStart)("responder", { ...shared, password: Buffer.from("guitar-reward") });
109
- const rightShare = Uint8Array.from(right.share);
110
- const wrongShare = Uint8Array.from(wrong.share);
111
- const goodShare = Uint8Array.from(good.share);
112
- expect(toHex(right.finish(goodShare))).toBe(toHex(good.finish(rightShare)));
113
- const second = (0, cpace_1.cpaceStart)("initiator", { ...shared, password: Buffer.from("guitar-revenge") });
114
- expect(toHex(wrong.finish(Uint8Array.from(second.share)))).not.toBe(toHex(second.finish(wrongShare)));
115
- });
116
- });
@@ -1 +0,0 @@
1
- export {};