@peers-app/peers-sdk 0.27.3 → 0.27.5

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 (272) 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/contract-transport.d.ts +2 -1
  4. package/dist/contracts/contract-transport.js +24 -2
  5. package/dist/contracts/create-local-consumer.js +16 -1
  6. package/dist/contracts/index.d.ts +2 -0
  7. package/dist/contracts/index.js +2 -0
  8. package/dist/contracts/system/index.d.ts +2 -0
  9. package/dist/contracts/system/index.js +2 -0
  10. package/dist/contracts/system/invites-contract.js +2 -1
  11. package/dist/contracts/system/sync-check-contract.d.ts +97 -0
  12. package/dist/contracts/system/sync-check-contract.js +115 -0
  13. package/dist/contracts/tool-arguments.d.ts +15 -0
  14. package/dist/contracts/tool-arguments.js +41 -0
  15. package/dist/contracts/tool-catalog-service.js +2 -12
  16. package/dist/contracts/tool-catalog.js +6 -2
  17. package/dist/data/change-tracking.d.ts +40 -0
  18. package/dist/data/change-tracking.js +89 -0
  19. package/dist/data/orm/types.d.ts +24 -7
  20. package/dist/data/orm/types.js +97 -24
  21. package/dist/define/manifest.js +6 -34
  22. package/dist/device/binary-peer-connection-v2.d.ts +7 -15
  23. package/dist/device/binary-peer-connection-v2.js +14 -30
  24. package/dist/device/connection.d.ts +34 -43
  25. package/dist/device/connection.js +188 -186
  26. package/dist/device/device.d.ts +1 -8
  27. package/dist/device/device.js +1 -30
  28. package/dist/device/socket.type.d.ts +6 -12
  29. package/dist/package-loader/package-loader.js +27 -22
  30. package/dist/system-ids.d.ts +5 -0
  31. package/dist/system-ids.js +6 -1
  32. package/package.json +4 -2
  33. package/dist/context/user-context-identity.test.d.ts +0 -1
  34. package/dist/context/user-context-identity.test.js +0 -220
  35. package/dist/contracts/__tests__/action-dispatch.test.d.ts +0 -1
  36. package/dist/contracts/__tests__/action-dispatch.test.js +0 -319
  37. package/dist/contracts/__tests__/also-implements.test.d.ts +0 -1
  38. package/dist/contracts/__tests__/also-implements.test.js +0 -110
  39. package/dist/contracts/__tests__/builder.test.d.ts +0 -1
  40. package/dist/contracts/__tests__/builder.test.js +0 -669
  41. package/dist/contracts/__tests__/contract-events.test.d.ts +0 -1
  42. package/dist/contracts/__tests__/contract-events.test.js +0 -199
  43. package/dist/contracts/__tests__/contract-observables.test.d.ts +0 -1
  44. package/dist/contracts/__tests__/contract-observables.test.js +0 -290
  45. package/dist/contracts/__tests__/contract-provider-router.test.d.ts +0 -1
  46. package/dist/contracts/__tests__/contract-provider-router.test.js +0 -315
  47. package/dist/contracts/__tests__/contract-proxy.test.d.ts +0 -1
  48. package/dist/contracts/__tests__/contract-proxy.test.js +0 -657
  49. package/dist/contracts/__tests__/contract-resolvers.test.d.ts +0 -1
  50. package/dist/contracts/__tests__/contract-resolvers.test.js +0 -758
  51. package/dist/contracts/__tests__/contract-subscription-lifecycle.test.d.ts +0 -1
  52. package/dist/contracts/__tests__/contract-subscription-lifecycle.test.js +0 -353
  53. package/dist/contracts/__tests__/contract-table-events.test.d.ts +0 -1
  54. package/dist/contracts/__tests__/contract-table-events.test.js +0 -209
  55. package/dist/contracts/__tests__/contract-transport.test.d.ts +0 -1
  56. package/dist/contracts/__tests__/contract-transport.test.js +0 -163
  57. package/dist/contracts/__tests__/extract.test.d.ts +0 -1
  58. package/dist/contracts/__tests__/extract.test.js +0 -145
  59. package/dist/contracts/__tests__/frozen-contracts.test.d.ts +0 -1
  60. package/dist/contracts/__tests__/frozen-contracts.test.js +0 -191
  61. package/dist/contracts/__tests__/generic-tool-dispatch.test.d.ts +0 -1
  62. package/dist/contracts/__tests__/generic-tool-dispatch.test.js +0 -130
  63. package/dist/contracts/__tests__/host-contract-client.test.d.ts +0 -1
  64. package/dist/contracts/__tests__/host-contract-client.test.js +0 -793
  65. package/dist/contracts/__tests__/host-contract-consumer.test.d.ts +0 -1
  66. package/dist/contracts/__tests__/host-contract-consumer.test.js +0 -163
  67. package/dist/contracts/__tests__/host-contract-transport.test.d.ts +0 -1
  68. package/dist/contracts/__tests__/host-contract-transport.test.js +0 -66
  69. package/dist/contracts/__tests__/integration.test.d.ts +0 -1
  70. package/dist/contracts/__tests__/integration.test.js +0 -348
  71. package/dist/contracts/__tests__/legacy-removal.test.d.ts +0 -1
  72. package/dist/contracts/__tests__/legacy-removal.test.js +0 -128
  73. package/dist/contracts/__tests__/persistent-registry.test.d.ts +0 -1
  74. package/dist/contracts/__tests__/persistent-registry.test.js +0 -109
  75. package/dist/contracts/__tests__/playground.test.d.ts +0 -1
  76. package/dist/contracts/__tests__/playground.test.js +0 -216
  77. package/dist/contracts/__tests__/registry.test.d.ts +0 -1
  78. package/dist/contracts/__tests__/registry.test.js +0 -238
  79. package/dist/contracts/__tests__/remote-contract-transport.test.d.ts +0 -1
  80. package/dist/contracts/__tests__/remote-contract-transport.test.js +0 -119
  81. package/dist/contracts/__tests__/system-contracts.test.d.ts +0 -1
  82. package/dist/contracts/__tests__/system-contracts.test.js +0 -247
  83. package/dist/contracts/__tests__/target-dispatch.d.ts +0 -11
  84. package/dist/contracts/__tests__/target-dispatch.js +0 -24
  85. package/dist/contracts/__tests__/tool-catalog-inventory.test.d.ts +0 -1
  86. package/dist/contracts/__tests__/tool-catalog-inventory.test.js +0 -44
  87. package/dist/contracts/__tests__/tool-catalog-service.test.d.ts +0 -1
  88. package/dist/contracts/__tests__/tool-catalog-service.test.js +0 -482
  89. package/dist/contracts/__tests__/tool-catalog.test.d.ts +0 -1
  90. package/dist/contracts/__tests__/tool-catalog.test.js +0 -1199
  91. package/dist/contracts/__tests__/validate.test.d.ts +0 -1
  92. package/dist/contracts/__tests__/validate.test.js +0 -991
  93. package/dist/contracts/__tests__/workflow-context.test.d.ts +0 -1
  94. package/dist/contracts/__tests__/workflow-context.test.js +0 -50
  95. package/dist/data/access-level.test.d.ts +0 -1
  96. package/dist/data/access-level.test.js +0 -53
  97. package/dist/data/change-tracking.test.d.ts +0 -1
  98. package/dist/data/change-tracking.test.js +0 -62
  99. package/dist/data/files/files.test.d.ts +0 -1
  100. package/dist/data/files/files.test.js +0 -770
  101. package/dist/data/group-members.test.d.ts +0 -1
  102. package/dist/data/group-members.test.js +0 -336
  103. package/dist/data/group-share.test.d.ts +0 -1
  104. package/dist/data/group-share.test.js +0 -110
  105. package/dist/data/groups.test.d.ts +0 -1
  106. package/dist/data/groups.test.js +0 -153
  107. package/dist/data/orm/cursor.test.d.ts +0 -1
  108. package/dist/data/orm/cursor.test.js +0 -314
  109. package/dist/data/orm/data-query.mongo.test.d.ts +0 -1
  110. package/dist/data/orm/data-query.mongo.test.js +0 -367
  111. package/dist/data/orm/data-query.sqlite.test.d.ts +0 -1
  112. package/dist/data/orm/data-query.sqlite.test.js +0 -365
  113. package/dist/data/orm/data-query.test.d.ts +0 -1
  114. package/dist/data/orm/data-query.test.js +0 -545
  115. package/dist/data/orm/dependency-injection.test.d.ts +0 -1
  116. package/dist/data/orm/dependency-injection.test.js +0 -171
  117. package/dist/data/orm/event-registry.test.d.ts +0 -1
  118. package/dist/data/orm/event-registry.test.js +0 -44
  119. package/dist/data/orm/multi-cursors.test.d.ts +0 -1
  120. package/dist/data/orm/multi-cursors.test.js +0 -463
  121. package/dist/data/orm/sql.data-source.test.d.ts +0 -1
  122. package/dist/data/orm/sql.data-source.test.js +0 -731
  123. package/dist/data/orm/table-container-events.test.d.ts +0 -1
  124. package/dist/data/orm/table-container-events.test.js +0 -101
  125. package/dist/data/orm/table-container.test.d.ts +0 -1
  126. package/dist/data/orm/table-container.test.js +0 -273
  127. package/dist/data/orm/table.event-source.test.d.ts +0 -1
  128. package/dist/data/orm/table.event-source.test.js +0 -331
  129. package/dist/data/orm/types.test.d.ts +0 -1
  130. package/dist/data/orm/types.test.js +0 -409
  131. package/dist/data/package-table-identity.test.d.ts +0 -1
  132. package/dist/data/package-table-identity.test.js +0 -46
  133. package/dist/data/package-version-permissions.test.d.ts +0 -1
  134. package/dist/data/package-version-permissions.test.js +0 -107
  135. package/dist/data/package-version-resolver.test.d.ts +0 -4
  136. package/dist/data/package-version-resolver.test.js +0 -543
  137. package/dist/data/package-versions.test.d.ts +0 -1
  138. package/dist/data/package-versions.test.js +0 -227
  139. package/dist/data/persistent-vars.conflict.test.d.ts +0 -1
  140. package/dist/data/persistent-vars.conflict.test.js +0 -126
  141. package/dist/data/persistent-vars.migration.test.d.ts +0 -1
  142. package/dist/data/persistent-vars.migration.test.js +0 -133
  143. package/dist/data/persistent-vars.package-scope.test.d.ts +0 -1
  144. package/dist/data/persistent-vars.package-scope.test.js +0 -27
  145. package/dist/data/sync-recovery-queue.test.d.ts +0 -1
  146. package/dist/data/sync-recovery-queue.test.js +0 -215
  147. package/dist/data/table-signing.test.d.ts +0 -1
  148. package/dist/data/table-signing.test.js +0 -118
  149. package/dist/data/tool-access.test.d.ts +0 -1
  150. package/dist/data/tool-access.test.js +0 -166
  151. package/dist/data/user-permissions.test.d.ts +0 -1
  152. package/dist/data/user-permissions.test.js +0 -305
  153. package/dist/data/user-trust-levels.test.d.ts +0 -1
  154. package/dist/data/user-trust-levels.test.js +0 -37
  155. package/dist/define/also-implements.test.d.ts +0 -1
  156. package/dist/define/also-implements.test.js +0 -123
  157. package/dist/define/declare-contract.test.d.ts +0 -1
  158. package/dist/define/declare-contract.test.js +0 -573
  159. package/dist/define/define.test.d.ts +0 -1
  160. package/dist/define/define.test.js +0 -1010
  161. package/dist/define/empty-fields.test.d.ts +0 -1
  162. package/dist/define/empty-fields.test.js +0 -55
  163. package/dist/define/events-observables.test.d.ts +0 -1
  164. package/dist/define/events-observables.test.js +0 -1013
  165. package/dist/define/serve-members.test.d.ts +0 -1
  166. package/dist/define/serve-members.test.js +0 -630
  167. package/dist/define/vars.test.d.ts +0 -1
  168. package/dist/define/vars.test.js +0 -39
  169. package/dist/device/binary-peer-connection-v2.test.d.ts +0 -1
  170. package/dist/device/binary-peer-connection-v2.test.js +0 -730
  171. package/dist/device/binary-peer-connection.d.ts +0 -58
  172. package/dist/device/binary-peer-connection.js +0 -516
  173. package/dist/device/binary-peer-connection.test.d.ts +0 -1
  174. package/dist/device/binary-peer-connection.test.js +0 -184
  175. package/dist/device/connection.test.d.ts +0 -1
  176. package/dist/device/connection.test.js +0 -613
  177. package/dist/device/device-election.test.d.ts +0 -1
  178. package/dist/device/device-election.test.js +0 -516
  179. package/dist/device/device.test.d.ts +0 -1
  180. package/dist/device/device.test.js +0 -243
  181. package/dist/device/frame-cipher.test.d.ts +0 -1
  182. package/dist/device/frame-cipher.test.js +0 -219
  183. package/dist/device/get-trust-level-fn.test.d.ts +0 -1
  184. package/dist/device/get-trust-level-fn.test.js +0 -685
  185. package/dist/device/streamed-socket.d.ts +0 -23
  186. package/dist/device/streamed-socket.js +0 -255
  187. package/dist/device/streamed-socket.test.d.ts +0 -1
  188. package/dist/device/streamed-socket.test.js +0 -216
  189. package/dist/device/tx-encoding.test.d.ts +0 -1
  190. package/dist/device/tx-encoding.test.js +0 -295
  191. package/dist/device-pairing/cpace.test.d.ts +0 -1
  192. package/dist/device-pairing/cpace.test.js +0 -116
  193. package/dist/device-pairing/device-pairing.test.d.ts +0 -1
  194. package/dist/device-pairing/device-pairing.test.js +0 -211
  195. package/dist/hlc.test.d.ts +0 -1
  196. package/dist/hlc.test.js +0 -45
  197. package/dist/host-credentials.test.d.ts +0 -1
  198. package/dist/host-credentials.test.js +0 -88
  199. package/dist/identity/account-email.test.d.ts +0 -1
  200. package/dist/identity/account-email.test.js +0 -59
  201. package/dist/identity/anchor-document.test.d.ts +0 -1
  202. package/dist/identity/anchor-document.test.js +0 -16
  203. package/dist/identity/anchor-resolution.test.d.ts +0 -1
  204. package/dist/identity/anchor-resolution.test.js +0 -130
  205. package/dist/identity/key-change.test.d.ts +0 -1
  206. package/dist/identity/key-change.test.js +0 -811
  207. package/dist/invites/group-approval.test.d.ts +0 -1
  208. package/dist/invites/group-approval.test.js +0 -223
  209. package/dist/invites/invite-token.test.d.ts +0 -1
  210. package/dist/invites/invite-token.test.js +0 -123
  211. package/dist/keys.test.d.ts +0 -1
  212. package/dist/keys.test.js +0 -336
  213. package/dist/logging/console-logger.test.d.ts +0 -1
  214. package/dist/logging/console-logger.test.js +0 -300
  215. package/dist/logging/console-logs.table.test.d.ts +0 -1
  216. package/dist/logging/console-logs.table.test.js +0 -156
  217. package/dist/observable.test.d.ts +0 -1
  218. package/dist/observable.test.js +0 -309
  219. package/dist/package-build/build-package.test.d.ts +0 -1
  220. package/dist/package-build/build-package.test.js +0 -204
  221. package/dist/package-build/contract-add.test.d.ts +0 -1
  222. package/dist/package-build/contract-add.test.js +0 -467
  223. package/dist/package-build/freeze-contracts.test.d.ts +0 -1
  224. package/dist/package-build/freeze-contracts.test.js +0 -355
  225. package/dist/package-installer/package-author-signing.test.d.ts +0 -1
  226. package/dist/package-installer/package-author-signing.test.js +0 -200
  227. package/dist/package-installer/package-cloner.test.d.ts +0 -1
  228. package/dist/package-installer/package-cloner.test.js +0 -278
  229. package/dist/package-installer/package-creator.test.d.ts +0 -1
  230. package/dist/package-installer/package-creator.test.js +0 -908
  231. package/dist/package-installer/package-dev-tools.test.d.ts +0 -1
  232. package/dist/package-installer/package-dev-tools.test.js +0 -64
  233. package/dist/package-installer/package-installer.test.d.ts +0 -1
  234. package/dist/package-installer/package-installer.test.js +0 -882
  235. package/dist/package-installer/package-propagation.test.d.ts +0 -1
  236. package/dist/package-installer/package-propagation.test.js +0 -1269
  237. package/dist/package-installer/package-publisher.test.d.ts +0 -1
  238. package/dist/package-installer/package-publisher.test.js +0 -153
  239. package/dist/package-installer/package-remote-checker.test.d.ts +0 -1
  240. package/dist/package-installer/package-remote-checker.test.js +0 -334
  241. package/dist/package-installer/package-seed-installer.test.d.ts +0 -1
  242. package/dist/package-installer/package-seed-installer.test.js +0 -123
  243. package/dist/package-installer/package-tarball.test.d.ts +0 -1
  244. package/dist/package-installer/package-tarball.test.js +0 -75
  245. package/dist/package-installer/peers-core-installer.test.d.ts +0 -1
  246. package/dist/package-installer/peers-core-installer.test.js +0 -49
  247. package/dist/package-installer/peers-core-trust-anchor.test.d.ts +0 -1
  248. package/dist/package-installer/peers-core-trust-anchor.test.js +0 -155
  249. package/dist/package-loader/contract-package-loader.test.d.ts +0 -1
  250. package/dist/package-loader/contract-package-loader.test.js +0 -274
  251. package/dist/package-loader/host-authority-loading.test.d.ts +0 -1
  252. package/dist/package-loader/host-authority-loading.test.js +0 -104
  253. package/dist/package-loader/host-dispatch-policy.test.d.ts +0 -1
  254. package/dist/package-loader/host-dispatch-policy.test.js +0 -56
  255. package/dist/package-loader/isolated-artifact.test.d.ts +0 -1
  256. package/dist/package-loader/isolated-artifact.test.js +0 -688
  257. package/dist/package-loader/isolated-persistent-var-gateway.test.d.ts +0 -1
  258. package/dist/package-loader/isolated-persistent-var-gateway.test.js +0 -56
  259. package/dist/package-loader/isolated-table-gateway.test.d.ts +0 -1
  260. package/dist/package-loader/isolated-table-gateway.test.js +0 -633
  261. package/dist/package-loader/package-loader.test.d.ts +0 -1
  262. package/dist/package-loader/package-loader.test.js +0 -1764
  263. package/dist/package-loader/resolve-consumed-contracts.test.d.ts +0 -1
  264. package/dist/package-loader/resolve-consumed-contracts.test.js +0 -166
  265. package/dist/serial-json.compat.test.d.ts +0 -1
  266. package/dist/serial-json.compat.test.js +0 -369
  267. package/dist/serial-json.test.d.ts +0 -1
  268. package/dist/serial-json.test.js +0 -401
  269. package/dist/testing/mock-host-contract.test.d.ts +0 -1
  270. package/dist/testing/mock-host-contract.test.js +0 -782
  271. package/dist/utils.test.d.ts +0 -1
  272. package/dist/utils.test.js +0 -232
@@ -14,8 +14,8 @@ export interface RPCSendOptions {
14
14
  /** Arm the outbound frame cipher with these keys right after this reply frame has been sent. */
15
15
  armFrameCipherAfter?: FrameKeys;
16
16
  }
17
- /** Reply callback handed to RPC handlers. */
18
- export type RPCCallback = (error?: any, result?: any, sendOptions?: RPCSendOptions) => void;
17
+ /** Reply callback handed to RPC handlers; async transports resolve after sending the reply. */
18
+ export type RPCCallback = (error?: any, result?: any, sendOptions?: RPCSendOptions) => void | Promise<void>;
19
19
  /** Which direction(s) of the frame cipher to arm. */
20
20
  export type FrameCipherDirection = "both" | "send" | "receive";
21
21
  /**
@@ -40,11 +40,6 @@ export type TransportType = "ws" | "wrtc" | "unknown";
40
40
  export interface ISocket {
41
41
  id?: string;
42
42
  connected?: boolean;
43
- /**
44
- * @deprecated No longer needed - all sockets handle their own encoding.
45
- * Kept temporarily for backwards compatibility during v1->v2 transition.
46
- */
47
- handlesOwnEncoding?: boolean;
48
43
  /**
49
44
  * Transport type for this socket. Used to optimize chunk sizes for raw byte streaming.
50
45
  * - 'wrtc': WebRTC (64KB max due to SCTP limits)
@@ -82,8 +77,8 @@ export interface ISocket {
82
77
  /**
83
78
  * Arms the per-connection frame cipher (see `frame-cipher.ts`). Sockets that
84
79
  * implement this seal every outbound frame and require every inbound frame to
85
- * be sealed once the corresponding direction is armed. `Connection` only
86
- * advertises `frameCrypto` support in its handshake when this is present.
80
+ * be sealed once the corresponding direction is armed. `Connection` refuses
81
+ * to run a handshake on a socket without it.
87
82
  * @param keys - This peer's send and receive keys
88
83
  * @param direction - Defaults to `"both"`. The handshake server arms
89
84
  * `"receive"` first and lets the reply's {@link RPCSendOptions} arm send.
@@ -94,9 +89,8 @@ export interface ISocket {
94
89
  /**
95
90
  * Controls delivery of inbound plaintext `STREAM_*` frames. Sockets start
96
91
  * permissive so bare transports keep working; `Connection` turns this off on
97
- * construction and only turns it back on for a verified legacy peer. Sealed
98
- * stream frames are always delivered because arming implies a completed
99
- * handshake.
92
+ * construction. Sealed stream frames are always delivered because arming
93
+ * implies a completed handshake.
100
94
  */
101
95
  setPlaintextStreamsAllowed?(allowed: boolean): void;
102
96
  }
@@ -9,6 +9,7 @@ const contract_resolvers_1 = require("../contracts/contract-resolvers");
9
9
  const contract_transport_1 = require("../contracts/contract-transport");
10
10
  const registry_1 = require("../contracts/registry");
11
11
  const remote_contract_transport_1 = require("../contracts/remote-contract-transport");
12
+ const tool_arguments_1 = require("../contracts/tool-arguments");
12
13
  const tool_catalog_1 = require("../contracts/tool-catalog");
13
14
  const files_1 = require("../data/files");
14
15
  const package_version_resolver_1 = require("../data/package-version-resolver");
@@ -412,7 +413,7 @@ class PackageLoader {
412
413
  (0, contract_resolvers_1.getContractResolver)(implementation.contractId, implementation.version, providerPackageId, this.dataContext) !== resolver)
413
414
  throw new contract_provider_router_1.RetiredContractProviderEndpointError(guardedEndpoint);
414
415
  };
415
- const endpoint = (0, contract_proxy_1.createContractProviderEndpoint)(this.guardResolutionTools(localResolution, request, assertProviderCurrent), {
416
+ const endpoint = (0, contract_proxy_1.createContractProviderEndpoint)(this.guardResolutionTools(localResolution, request, assertProviderCurrent, providerPackageId), {
416
417
  dispatchTool: (target, args, context) => this.dispatchToolFromProvider(providerPackageId, target, args, context),
417
418
  context: request.context,
418
419
  notify: (notification) => request.notify({
@@ -435,29 +436,33 @@ class PackageLoader {
435
436
  };
436
437
  return guardedEndpoint;
437
438
  }
438
- guardResolutionTools(resolution, request, assertProviderCurrent) {
439
- const guard = (instances) => instances &&
440
- Object.fromEntries(Object.entries(instances).map(([name, instance]) => [
441
- name,
442
- {
443
- ...instance,
444
- // The dispatcher awaits authorization before calling toolFn. Check again
445
- // here so those awaits cannot retain old code. Once provider code has
446
- // started, its nested action errors must not request a router replay.
447
- toolFn: async (...args) => {
448
- await this.toolCatalog.assertTargetUsable({
449
- contractId: request.contractId,
450
- version: request.version,
451
- toolName: name,
452
- });
453
- assertProviderCurrent();
454
- return instance.toolFn(...args);
455
- },
456
- },
457
- ]));
439
+ guardResolutionTools(resolution, request, assertProviderCurrent, providerPackageId) {
440
+ // The version the caller asked for: each run's arguments are checked against its tools.
441
+ const definition = (providerPackageId &&
442
+ this.contractRegistry.getProviderDefinition(request.contractId, request.version, providerPackageId)) ||
443
+ this.contractRegistry.getDefinition(request.contractId, request.version);
458
444
  return {
459
445
  ...resolution,
460
- tools: guard(resolution.tools),
446
+ invokeTool: async (name, args) => {
447
+ // Authorization may await; retire old code before checking its schema or running it.
448
+ // Nested action errors after this point must not request a router replay.
449
+ await this.toolCatalog.assertTargetUsable({
450
+ contractId: request.contractId,
451
+ version: request.version,
452
+ toolName: name,
453
+ });
454
+ assertProviderCurrent();
455
+ const tool = resolution.tools?.[name];
456
+ if (!tool)
457
+ throw new Error(`Contract ${request.contractId} does not provide tool '${name}'`);
458
+ const member = definition?.tools.find((tool) => tool.name === name);
459
+ if (definition && !member)
460
+ throw new Error(`Contract ${request.contractId} does not declare tool '${name}'`);
461
+ const inputFields = member?.inputFields ?? tool.tool.inputSchema?.fields;
462
+ if (inputFields?.length)
463
+ (0, tool_arguments_1.checkToolArguments)(inputFields, args[0], name);
464
+ return tool.toolFn(...args);
465
+ },
461
466
  };
462
467
  }
463
468
  /**
@@ -71,6 +71,11 @@ export declare const networkControlContractId = "00ms1yb50yj9w5qbytl69qfht";
71
71
  * provide status and relay tools, while Electron also implements local updates.
72
72
  */
73
73
  export declare const appUpdatesContractId = "00mvczoafequsatpfjaj3r4g8";
74
+ /**
75
+ * Contract id for **System Sync Check**: the daily check that finds changes another device has
76
+ * and this one is missing. `countChanges` is remotely callable by group Readers.
77
+ */
78
+ export declare const syncCheckContractId = "00mvrnfgmc14ea0ktkr86vjd2";
74
79
  /**
75
80
  * Contract id for the local-only tool-access approval control surface.
76
81
  * Not available over device-to-device connections.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hostShellContractId = exports.packagesContractId = exports.desktopToolsContractId = exports.hostToolsContractId = exports.toolCatalogContractId = exports.schedulerToolIds = exports.schedulerContractId = exports.contractCatalogToolIds = exports.contractCatalogContractId = exports.httpToolIds = exports.httpContractId = exports.localFoldersToolIds = exports.localFoldersContractId = exports.identityToolIds = exports.identityContractId = exports.invitesToolIds = exports.invitesContractId = exports.toolAccessControlToolIds = exports.toolAccessControlContractId = exports.appUpdatesContractId = exports.networkControlContractId = exports.networkDiagnosticsContractId = exports.deviceOperationsContractId = exports.logsContractId = exports.peersSystemPackageId = exports.peersCoreRevokedPublishPublicKeys = exports.peersCorePublishPublicKey = exports.peersCorePackageRepoUrl = exports.peersCorePackageId = exports.createGroupToolId = exports.queryDatabaseToolId = exports.runWorkflowToolId = exports.defaultSendMessageToolId = exports.defaultAssistantRunnerToolId = exports.adminAssistantId = exports.openCodeAssistantId = exports.defaultAssistantId = exports.peersRootUserId = void 0;
3
+ exports.hostShellContractId = exports.packagesContractId = exports.desktopToolsContractId = exports.hostToolsContractId = exports.toolCatalogContractId = exports.schedulerToolIds = exports.schedulerContractId = exports.contractCatalogToolIds = exports.contractCatalogContractId = exports.httpToolIds = exports.httpContractId = exports.localFoldersToolIds = exports.localFoldersContractId = exports.identityToolIds = exports.identityContractId = exports.invitesToolIds = exports.invitesContractId = exports.toolAccessControlToolIds = exports.toolAccessControlContractId = exports.syncCheckContractId = exports.appUpdatesContractId = exports.networkControlContractId = exports.networkDiagnosticsContractId = exports.deviceOperationsContractId = exports.logsContractId = exports.peersSystemPackageId = exports.peersCoreRevokedPublishPublicKeys = exports.peersCorePublishPublicKey = exports.peersCorePackageRepoUrl = exports.peersCorePackageId = exports.createGroupToolId = exports.queryDatabaseToolId = exports.runWorkflowToolId = exports.defaultSendMessageToolId = exports.defaultAssistantRunnerToolId = exports.adminAssistantId = exports.openCodeAssistantId = exports.defaultAssistantId = exports.peersRootUserId = void 0;
4
4
  /** Stable user ID that owns built-in Peers system records. */
5
5
  exports.peersRootUserId = "000peers0user000000000001";
6
6
  /** Default assistant used when no user-selected assistant is available. */
@@ -78,6 +78,11 @@ exports.networkControlContractId = "00ms1yb50yj9w5qbytl69qfht";
78
78
  * provide status and relay tools, while Electron also implements local updates.
79
79
  */
80
80
  exports.appUpdatesContractId = "00mvczoafequsatpfjaj3r4g8";
81
+ /**
82
+ * Contract id for **System Sync Check**: the daily check that finds changes another device has
83
+ * and this one is missing. `countChanges` is remotely callable by group Readers.
84
+ */
85
+ exports.syncCheckContractId = "00mvrnfgmc14ea0ktkr86vjd2";
81
86
  /**
82
87
  * Contract id for the local-only tool-access approval control surface.
83
88
  * Not available over device-to-device connections.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peers-app/peers-sdk",
3
- "version": "0.27.3",
3
+ "version": "0.27.5",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/peers-app/peers-sdk.git"
@@ -16,7 +16,9 @@
16
16
  "dist",
17
17
  "define",
18
18
  "testing",
19
- "bin"
19
+ "bin",
20
+ "!dist/**/*.test.*",
21
+ "!dist/**/__tests__"
20
22
  ],
21
23
  "publishConfig": {
22
24
  "access": "public"
@@ -1 +0,0 @@
1
- import "../identity/user-row-change";
@@ -1,220 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const SQLiteDB = require("better-sqlite3");
4
- const sql_data_source_1 = require("../data/orm/sql.data-source");
5
- const user_permissions_1 = require("../data/user-permissions");
6
- const users_1 = require("../data/users");
7
- const anchor_document_1 = require("../identity/anchor-document");
8
- const anchor_resolution_1 = require("../identity/anchor-resolution");
9
- const key_change_1 = require("../identity/key-change");
10
- const keys_1 = require("../keys");
11
- const utils_1 = require("../utils");
12
- const user_context_1 = require("./user-context");
13
- const user_context_singleton_1 = require("./user-context-singleton");
14
- // Installs the UsersTable guard.
15
- require("../identity/user-row-change");
16
- class DBHarness {
17
- _db = null;
18
- get db() {
19
- if (!this._db) {
20
- this._db = new SQLiteDB(":memory:");
21
- this._db.pragma("journal_mode = WAL");
22
- }
23
- return this._db;
24
- }
25
- async get(sql, params = []) {
26
- return this.db.prepare(sql).get(params);
27
- }
28
- async all(sql, params = []) {
29
- return this.db.prepare(sql).all(params);
30
- }
31
- async exec(sql, params = []) {
32
- const result = this.db.prepare(sql).run(params);
33
- return { changes: result.changes };
34
- }
35
- async close() {
36
- this._db?.close();
37
- this._db = null;
38
- }
39
- }
40
- describe("UserContext.syncUserAndGroupObjects and the profile row's key", () => {
41
- const anchor = {
42
- type: "https",
43
- url: "https://example.com/.well-known/peers-identity.json",
44
- };
45
- // The process-wide user context can be installed once, so one context serves every case;
46
- // each case starts by writing the profile row it needs (the owner's own row is unrestricted).
47
- const db = new DBHarness();
48
- const userId = (0, utils_1.newid)();
49
- let userContext;
50
- beforeAll(async () => {
51
- const dataSourceFactory = (metaData, schema) => new sql_data_source_1.SQLDataSource(db, metaData, schema);
52
- userContext = new user_context_1.UserContext(userId, dataSourceFactory, true);
53
- await userContext.loadingPromise;
54
- userContext.deviceId((0, utils_1.newid)());
55
- (0, user_context_singleton_1.setUserContext)(userContext);
56
- });
57
- afterEach(() => {
58
- (0, anchor_resolution_1.setAnchorFetcher)(undefined);
59
- });
60
- afterAll(async () => {
61
- userContext.dispose();
62
- await db.close();
63
- });
64
- function document(publicKey, authorizedBy) {
65
- return {
66
- outcome: "document",
67
- document: {
68
- version: 1,
69
- userId,
70
- keys: [{ publicKey, issuedAt: "2026-10-03T18:00:00.000Z", authorizedBy }],
71
- anchors: [anchor],
72
- updatedAt: "2026-10-03T18:00:00.000Z",
73
- },
74
- };
75
- }
76
- it("signs a fresh profile with the device key", async () => {
77
- const keys = (0, keys_1.newKeys)();
78
- await userContext.syncUserAndGroupObjects(userId, keys);
79
- const me = await (0, users_1.Users)(userContext.userDataContext).get(userId);
80
- expect(me?.publicKey).toBe(keys.publicKey);
81
- expect(() => (0, user_permissions_1.verifyUserSignature)(me)).not.toThrow();
82
- });
83
- it("re-signs a profile the anchors say this device's key succeeded", async () => {
84
- // A rotation stored the new secret and then stopped before re-signing the row, or an
85
- // operator replaced the secret in credentials.json after publishing the key. The anchors
86
- // list the device key with the old key's co-signature, so the row follows the device.
87
- const k1 = (0, keys_1.newKeys)();
88
- const k2 = (0, keys_1.newKeys)();
89
- await (0, users_1.Users)(userContext.userDataContext).save((0, user_permissions_1.signUserObject)({
90
- userId,
91
- name: "Alice",
92
- publicKey: k1.publicKey,
93
- publicBoxKey: k1.publicBoxKey,
94
- anchors: [anchor],
95
- }, k1.secretKey));
96
- const succession = (0, anchor_document_1.signSuccession)({
97
- purpose: "peers-key-succession",
98
- userId,
99
- publicKey: k2.publicKey,
100
- issuedAt: "2026-10-03T18:00:00.000Z",
101
- }, k1.secretKey);
102
- (0, anchor_resolution_1.setAnchorFetcher)(async () => document(k2.publicKey, { publicKey: succession.publicKey, signature: succession.signature }));
103
- await userContext.syncUserAndGroupObjects(userId, k2);
104
- const me = await (0, users_1.Users)(userContext.userDataContext).get(userId);
105
- expect(me?.publicKey).toBe(k2.publicKey);
106
- expect(me?.publicBoxKey).toBe(k2.publicBoxKey);
107
- expect(me?.name).toBe("Alice");
108
- expect(me?.anchors).toEqual([anchor]);
109
- expect(() => (0, user_permissions_1.verifyUserSignature)(me)).not.toThrow();
110
- });
111
- it("does not put the device key back over a row the anchors still confirm", async () => {
112
- // The row holds K2 and the anchors list only K2: this device's K1 was rotated away. The
113
- // row must not be re-signed with K1, or the device would publish a retired key.
114
- const k1 = (0, keys_1.newKeys)();
115
- const k2 = (0, keys_1.newKeys)();
116
- const row = (0, user_permissions_1.signUserObject)({
117
- userId,
118
- name: "Alice",
119
- publicKey: k2.publicKey,
120
- publicBoxKey: k2.publicBoxKey,
121
- anchors: [anchor],
122
- }, k2.secretKey);
123
- await (0, users_1.Users)(userContext.userDataContext).save(row);
124
- (0, anchor_resolution_1.setAnchorFetcher)(async () => document(k2.publicKey));
125
- await userContext.syncUserAndGroupObjects(userId, k1);
126
- const me = await (0, users_1.Users)(userContext.userDataContext).get(userId);
127
- expect(me?.publicKey).toBe(k2.publicKey);
128
- expect(me?.signature).toBe(row.signature);
129
- });
130
- it("leaves the row alone while the anchors have not answered", async () => {
131
- const k1 = (0, keys_1.newKeys)();
132
- const k2 = (0, keys_1.newKeys)();
133
- const row = (0, user_permissions_1.signUserObject)({
134
- userId,
135
- name: "Alice",
136
- publicKey: k1.publicKey,
137
- publicBoxKey: k1.publicBoxKey,
138
- anchors: [anchor],
139
- }, k1.secretKey);
140
- await (0, users_1.Users)(userContext.userDataContext).save(row);
141
- (0, anchor_resolution_1.setAnchorFetcher)(async () => ({ outcome: "abstain" }));
142
- await userContext.syncUserAndGroupObjects(userId, k2);
143
- const me = await (0, users_1.Users)(userContext.userDataContext).get(userId);
144
- expect(me?.publicKey).toBe(k1.publicKey);
145
- expect(me?.signature).toBe(row.signature);
146
- });
147
- describe("the rotated-away notice", () => {
148
- const noticeFor = (oldKey, newKey) => ({
149
- userId,
150
- oldPublicKey: oldKey,
151
- newPublicKey: newKey,
152
- detectedAt: "2026-10-03T18:00:00.000Z",
153
- });
154
- afterEach(async () => {
155
- await key_change_1.identityRotatedAwayVar.loadingPromise;
156
- (0, key_change_1.identityRotatedAwayVar)(null);
157
- });
158
- it("is cleared once this device holds the key the anchors confirmed", async () => {
159
- // The device was told its K1 was rotated away, then paired again onto the same
160
- // database and now holds K2. The banner must not outlive the problem.
161
- const k1 = (0, keys_1.newKeys)();
162
- const k2 = (0, keys_1.newKeys)();
163
- await (0, users_1.Users)(userContext.userDataContext).save((0, user_permissions_1.signUserObject)({
164
- userId,
165
- name: "Alice",
166
- publicKey: k2.publicKey,
167
- publicBoxKey: k2.publicBoxKey,
168
- anchors: [anchor],
169
- }, k2.secretKey));
170
- await key_change_1.identityRotatedAwayVar.loadingPromise;
171
- (0, key_change_1.identityRotatedAwayVar)(noticeFor(k1.publicKey, k2.publicKey));
172
- await userContext.syncUserAndGroupObjects(userId, k2);
173
- expect((0, key_change_1.identityRotatedAwayVar)()).toBeNull();
174
- });
175
- it("is cleared when the anchors confirm the key this device now holds", async () => {
176
- // Paired again after a further rotation: the notice names K2, the device holds K3, and
177
- // the row on disk is still K1 until the anchors answer.
178
- const k1 = (0, keys_1.newKeys)();
179
- const k2 = (0, keys_1.newKeys)();
180
- const k3 = (0, keys_1.newKeys)();
181
- await (0, users_1.Users)(userContext.userDataContext).save((0, user_permissions_1.signUserObject)({
182
- userId,
183
- name: "Alice",
184
- publicKey: k1.publicKey,
185
- publicBoxKey: k1.publicBoxKey,
186
- anchors: [anchor],
187
- }, k1.secretKey));
188
- const succession = (0, anchor_document_1.signSuccession)({
189
- purpose: "peers-key-succession",
190
- userId,
191
- publicKey: k3.publicKey,
192
- issuedAt: "2026-10-03T18:00:00.000Z",
193
- }, k1.secretKey);
194
- (0, anchor_resolution_1.setAnchorFetcher)(async () => document(k3.publicKey, {
195
- publicKey: succession.publicKey,
196
- signature: succession.signature,
197
- }));
198
- await key_change_1.identityRotatedAwayVar.loadingPromise;
199
- (0, key_change_1.identityRotatedAwayVar)(noticeFor(k1.publicKey, k2.publicKey));
200
- await userContext.syncUserAndGroupObjects(userId, k3);
201
- expect((0, key_change_1.identityRotatedAwayVar)()).toBeNull();
202
- });
203
- it("stays on a device that still holds the retired key", async () => {
204
- const k1 = (0, keys_1.newKeys)();
205
- const k2 = (0, keys_1.newKeys)();
206
- await (0, users_1.Users)(userContext.userDataContext).save((0, user_permissions_1.signUserObject)({
207
- userId,
208
- name: "Alice",
209
- publicKey: k1.publicKey,
210
- publicBoxKey: k1.publicBoxKey,
211
- anchors: [anchor],
212
- }, k1.secretKey));
213
- await key_change_1.identityRotatedAwayVar.loadingPromise;
214
- const notice = noticeFor(k1.publicKey, k2.publicKey);
215
- (0, key_change_1.identityRotatedAwayVar)(notice);
216
- await userContext.syncUserAndGroupObjects(userId, k1);
217
- expect((0, key_change_1.identityRotatedAwayVar)()).toEqual(notice);
218
- });
219
- });
220
- });
@@ -1 +0,0 @@
1
- export {};