@peers-app/peers-sdk 0.27.4 → 0.28.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.
Files changed (92) hide show
  1. package/dist/context/user-context.d.ts +7 -1
  2. package/dist/context/user-context.js +4 -9
  3. package/dist/contracts/contract-proxy.d.ts +5 -0
  4. package/dist/contracts/contract-proxy.js +2 -2
  5. package/dist/contracts/contract-resolvers.d.ts +2 -2
  6. package/dist/contracts/contract-resolvers.js +14 -15
  7. package/dist/contracts/contract-transport.d.ts +2 -1
  8. package/dist/contracts/contract-transport.js +24 -2
  9. package/dist/contracts/system/network-contracts.d.ts +1 -1
  10. package/dist/contracts/tool-catalog-service.js +1 -1
  11. package/dist/contracts/tool-catalog.js +6 -2
  12. package/dist/data/assistants.d.ts +3 -3
  13. package/dist/data/authority-write-checks.d.ts +42 -0
  14. package/dist/data/authority-write-checks.js +324 -0
  15. package/dist/data/change-tracking.d.ts +4 -4
  16. package/dist/data/create-group.js +1 -0
  17. package/dist/data/devices.d.ts +27 -4
  18. package/dist/data/devices.js +31 -0
  19. package/dist/data/group-authority.d.ts +111 -0
  20. package/dist/data/group-authority.js +281 -0
  21. package/dist/data/group-members.d.ts +8 -2
  22. package/dist/data/group-members.js +41 -18
  23. package/dist/data/group-permissions.d.ts +15 -31
  24. package/dist/data/group-permissions.js +25 -95
  25. package/dist/data/group-resign.d.ts +38 -0
  26. package/dist/data/group-resign.js +71 -0
  27. package/dist/data/groups.d.ts +11 -0
  28. package/dist/data/groups.js +31 -13
  29. package/dist/data/index.d.ts +3 -0
  30. package/dist/data/index.js +3 -0
  31. package/dist/data/invites.d.ts +14 -0
  32. package/dist/data/orm/index.d.ts +1 -0
  33. package/dist/data/orm/index.js +1 -0
  34. package/dist/data/orm/sql.data-source.d.ts +2 -2
  35. package/dist/data/orm/sql.data-source.js +8 -9
  36. package/dist/data/orm/table-container.js +14 -8
  37. package/dist/data/orm/write-checks.d.ts +89 -0
  38. package/dist/data/orm/write-checks.js +115 -0
  39. package/dist/data/package-table-identity.d.ts +6 -0
  40. package/dist/data/package-table-identity.js +51 -0
  41. package/dist/data/package-version-resolver.d.ts +15 -0
  42. package/dist/data/package-version-resolver.js +58 -3
  43. package/dist/data/package-versions.d.ts +20 -14
  44. package/dist/data/package-versions.js +15 -9
  45. package/dist/data/packages.d.ts +6 -1
  46. package/dist/data/packages.js +15 -20
  47. package/dist/data/persistent-vars.js +2 -39
  48. package/dist/data/sync-recovery-queue.d.ts +4 -4
  49. package/dist/data/sync-recovery-queue.js +7 -1
  50. package/dist/data/tool-access-approvals.d.ts +3 -3
  51. package/dist/data/user-permissions.d.ts +33 -2
  52. package/dist/data/user-permissions.js +87 -10
  53. package/dist/data/users.d.ts +49 -12
  54. package/dist/data/users.js +21 -1
  55. package/dist/data/workflows.d.ts +1 -1
  56. package/dist/device/binary-peer-connection-v2.d.ts +8 -16
  57. package/dist/device/binary-peer-connection-v2.js +15 -31
  58. package/dist/device/connection.d.ts +35 -44
  59. package/dist/device/connection.js +188 -186
  60. package/dist/device/device.d.ts +1 -8
  61. package/dist/device/device.js +1 -30
  62. package/dist/device/frame-cipher.d.ts +1 -1
  63. package/dist/device/frame-cipher.js +1 -1
  64. package/dist/device/get-trust-level-fn.js +3 -6
  65. package/dist/device/socket.type.d.ts +6 -12
  66. package/dist/device-pairing/types.d.ts +26 -26
  67. package/dist/identity/user-row-change.d.ts +3 -1
  68. package/dist/identity/user-row-change.js +33 -18
  69. package/dist/invites/group-approval.js +23 -24
  70. package/dist/invites/invite-messages.d.ts +250 -28
  71. package/dist/invites/invite-token.d.ts +18 -0
  72. package/dist/invites/invite-token.js +2 -0
  73. package/dist/keys.d.ts +7 -0
  74. package/dist/keys.js +27 -0
  75. package/dist/package-installer/package-installer.d.ts +1 -1
  76. package/dist/package-installer/package-installer.js +8 -3
  77. package/dist/package-installer/package-propagation.d.ts +2 -0
  78. package/dist/package-installer/package-propagation.js +20 -38
  79. package/dist/package-installer/package-remote-checker.js +15 -3
  80. package/dist/package-loader/isolated-artifact.js +0 -2
  81. package/dist/package-loader/package-loader.js +6 -0
  82. package/dist/types/peer-device.d.ts +2 -0
  83. package/dist/types/workflow.d.ts +2 -2
  84. package/package.json +1 -1
  85. package/dist/data/package-permissions.d.ts +0 -14
  86. package/dist/data/package-permissions.js +0 -26
  87. package/dist/data/package-version-permissions.d.ts +0 -14
  88. package/dist/data/package-version-permissions.js +0 -30
  89. package/dist/device/binary-peer-connection.d.ts +0 -58
  90. package/dist/device/binary-peer-connection.js +0 -516
  91. package/dist/device/streamed-socket.d.ts +0 -23
  92. package/dist/device/streamed-socket.js +0 -255
@@ -8,12 +8,10 @@ export type GetTrustLevel = (deviceInfo: IDeviceInfo, registerNew?: boolean) =>
8
8
  * Authenticated RPC connection between two Peers devices.
9
9
  *
10
10
  * The handshake (`doHandshake` on the client, `completeHandshake` on the
11
- * server) authenticates both identities with signed, boxed messages. When both
12
- * sockets support it, the handshake also agrees on per-connection frame-cipher
13
- * keys (`frame-cipher.ts`) and arms the socket, after which every frame on the
14
- * wire is sealed and the legacy per-message sign+box envelope is skipped.
15
- * Against a peer that does not advertise `frameCrypto` the connection falls
16
- * back to the legacy behaviour and logs a warning.
11
+ * server) authenticates both identities with signed, boxed messages and agrees
12
+ * on per-connection frame-cipher keys (`frame-cipher.ts`), then arms the
13
+ * socket: every frame after the handshake is sealed. A peer that does not
14
+ * offer frame encryption (a build before 0.25.7) is refused.
17
15
  */
18
16
  export declare class Connection {
19
17
  readonly localDevice: Device;
@@ -21,23 +19,9 @@ export declare class Connection {
21
19
  protected readonly getTrustLevel: GetTrustLevel;
22
20
  private _verified;
23
21
  private _remoteDeviceInfo;
24
- /**
25
- * @deprecated Legacy transport classification, only consulted when the frame
26
- * cipher is not armed. Removed once legacy peers are no longer supported.
27
- */
28
- secureLocal: boolean;
29
- /** @deprecated See {@link Connection.secureLocal}. */
30
- secureRemote: boolean;
31
- /**
32
- * Legacy per-message encryption override. Ignored once the frame cipher is
33
- * armed. `"dont-encrypt-traffic-after-handshake"` is honoured only under
34
- * `NODE_ENV=test`.
35
- * @deprecated Removed with the legacy path.
36
- */
37
- overrideEncryption?: "encrypt-traffic-regardless-of-protocol" | "dont-encrypt-traffic-after-handshake";
38
22
  /** Trust assigned to the remote identity once the handshake completes. */
39
23
  trustLevel: TrustLevel;
40
- /** Server-side hook fired shortly after a successful handshake. */
24
+ /** Server-side hook fired shortly after the successful handshake reply has been sent. */
41
25
  onHandshakeComplete: ((deviceInfo: IDeviceInfo) => void) | undefined;
42
26
  /** RPC timeout for {@link Connection.emit}. */
43
27
  timeoutMs: number;
@@ -53,34 +37,26 @@ export declare class Connection {
53
37
  private pendingClientHandshake;
54
38
  /** Server side: keys to arm for sending right after the handshake response frame. */
55
39
  private pendingSendArm;
40
+ /** Bumped by every {@link Connection.reset}, so a handshake can tell it was cut short. */
41
+ private handshakeGeneration;
56
42
  constructor(socket: ISocket, localDevice: Device, localDeviceServerAddresses?: string[] | undefined, getTrustLevel?: GetTrustLevel);
57
43
  /** True once the remote identity has been authenticated by the handshake. */
58
44
  get verified(): boolean;
59
45
  /** True when every frame on this connection is sealed by the frame cipher. */
60
46
  get frameCipherArmed(): boolean;
61
- /**
62
- * Whether to apply the legacy per-message envelope (sign + box) to RPC payloads.
63
- *
64
- * Always false once the frame cipher is armed: the frame layer already gives
65
- * confidentiality, integrity, and sender binding for every frame. Otherwise
66
- * (legacy peer) the transport classification below applies:
67
- * - skipped when both sides agreed the transport is secure (`secureLocal && secureRemote`)
68
- * - applied on plain `ws` / `http`
69
- */
70
- get encryptTraffic(): boolean;
71
47
  /** Copy of the authenticated remote device identity (empty before the handshake). */
72
48
  get remoteDeviceInfo(): {
73
49
  publicKey: string;
74
50
  userId: string;
75
- deviceId: string;
76
51
  publicBoxKey: string;
52
+ deviceId: string;
77
53
  userName?: string | undefined;
78
54
  deviceName?: string | undefined;
79
55
  };
80
56
  /** Socket ID shared by both ends; also the frame-cipher AAD and HKDF salt. */
81
57
  get connectionId(): string;
82
- private get supportsFrameCrypto();
83
- private warnLegacyPeer;
58
+ /** The socket's frame-cipher arming; throws when the transport can't encrypt frames. */
59
+ private requireFrameCipher;
84
60
  private readonly handleCompleteHandshakeRPC;
85
61
  /**
86
62
  * Get connection throughput stats with calculated rates.
@@ -105,10 +81,15 @@ export declare class Connection {
105
81
  exposeRPC<T extends Function>(fn: T): void;
106
82
  /** Calls a remote RPC handler and resolves with its result (rejects on error or timeout). */
107
83
  emit<T = any>(eventName: string, ...args: any): Promise<T>;
84
+ /**
85
+ * Sends one RPC. `onReply`, when given, runs synchronously while the reply frame is
86
+ * processed, before any later frame from the peer; its return value (or throw) settles
87
+ * the call.
88
+ */
89
+ private request;
108
90
  /**
109
91
  * Registers an RPC handler. Events other than the handshake set are rejected
110
- * until the connection is verified; payloads use the legacy envelope only
111
- * when {@link Connection.encryptTraffic} is true.
92
+ * until the connection is verified.
112
93
  */
113
94
  on(eventName: string, handler: Function): void;
114
95
  /** Removes RPC handlers for `eventName`, or all handlers when omitted. */
@@ -120,26 +101,36 @@ export declare class Connection {
120
101
  */
121
102
  reset(): void;
122
103
  /**
123
- * Client side: builds the signed handshake (advertising frame-cipher support
124
- * with a fresh ephemeral key when the socket can arm one) and boxes it to the
125
- * remote device.
104
+ * Client side: builds the signed handshake (offering frame encryption with a
105
+ * fresh ephemeral key) and boxes it to the remote device.
126
106
  */
127
107
  initiateHandshake(serverAddress: string, remoteDeviceInfo?: IDeviceInfo): IDataBox;
128
108
  /**
129
109
  * Server side: verifies the client's handshake, resolves trust, and returns
130
- * the (unsigned) response for the caller to sign and box. When the client
131
- * offered `frameCrypto` and this socket can arm a cipher, derives the frame
110
+ * the (unsigned) response for the caller to sign and box. Derives the frame
132
111
  * keys, arms the receive direction immediately, and schedules the send
133
112
  * direction to arm right after the response frame (see
134
- * {@link Connection.handleCompleteHandshakeRPC}).
113
+ * {@link Connection.handleCompleteHandshakeRPC}). A client that does not
114
+ * offer frame encryption is refused.
135
115
  */
136
116
  completeHandshake(boxedHandshake: IDataBox): Promise<IDeviceHandshake>;
137
117
  /**
138
118
  * Client side: runs the full handshake against `remoteAddress`. On success
139
- * the remote identity is verified and, if both sockets support it, the
140
- * frame cipher is armed in both directions before this resolves.
119
+ * the remote identity is verified and the frame cipher is armed in both
120
+ * directions before this resolves.
141
121
  */
142
122
  doHandshake(remoteAddress: string): Promise<IDeviceHandshake>;
123
+ /**
124
+ * Client side: checks the server's handshake reply, arms the frame cipher, and records the
125
+ * verified identity. Runs synchronously while the reply frame is processed, so a sealed
126
+ * frame read right after it finds the cipher armed and the connection verified.
127
+ */
128
+ private acceptHandshakeReply;
129
+ /**
130
+ * Throws when the connection was reset or closed after the handshake started: a handshake
131
+ * cut short must fail, not finish on a dead or reused connection.
132
+ */
133
+ private assertHandshakeCurrent;
143
134
  /**
144
135
  * Resets this side and asks the remote to do the same. The remote call is a courtesy: a
145
136
  * peer that is not a server has no `reset` handler, and a peer we just refused may already