@volter/twin-tunnel 0.1.0 → 0.1.1

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.
@@ -169,7 +169,7 @@ function verifyJwt(token, secret, tunnelId, requireTid) {
169
169
  const payload = JSON.parse(Buffer.from(body, 'base64url').toString('utf8'));
170
170
  if (!payload || typeof payload !== 'object' || Array.isArray(payload))
171
171
  return false;
172
- const now = Math.floor(Date.now() / 1000);
172
+ const now = Math.floor(Date.parse(worldNow()) / 1000);
173
173
  if (payload.exp !== undefined && (typeof payload.exp !== 'number' || !Number.isFinite(payload.exp)))
174
174
  return false;
175
175
  if (payload.nbf !== undefined && (typeof payload.nbf !== 'number' || !Number.isFinite(payload.nbf)))
@@ -1103,7 +1103,7 @@ export function createTunnelTwinHandler(options = {}) {
1103
1103
  mintToken(tunnelId, payload = {}) {
1104
1104
  if (!jwtSecret)
1105
1105
  throw new Error('tunnel JWT auth is disabled');
1106
- return createTunnelTwinJwt({ sub: 'twin-local', tid: tunnelId, exp: Math.floor(Date.now() / 1000) + 3600, ...payload }, jwtSecret);
1106
+ return createTunnelTwinJwt({ sub: 'twin-local', tid: tunnelId, exp: Math.floor(Date.parse(worldNow()) / 1000) + 3600, ...payload }, jwtSecret);
1107
1107
  },
1108
1108
  stop() {
1109
1109
  clearInterval(claimHeartbeat);
@@ -1,5 +1,5 @@
1
1
  import { createHash, randomBytes, randomUUID } from 'node:crypto';
2
- import { appendAction, applyTwinWrite, listActions, projectResources, TwinActionPreconditionError } from '@volter/world-core';
2
+ import { appendAction, applyTwinWrite, listActions, projectResources, TwinActionPreconditionError, worldNow } from '@volter/world-core';
3
3
  const SERVICE = 'tunnel';
4
4
  /** Message discriminators implemented or deliberately inventoried by the owned relay protocol.
5
5
  * The capability manifest checks against this runtime-owned list; a test separately pins it to
@@ -21,7 +21,7 @@ function nextRev(id, root) {
21
21
  return max + 1;
22
22
  }
23
23
  async function writeTunnel(type, id, fields, operation, req, preconditions) {
24
- const occurredAt = req.occurredAt ?? new Date().toISOString();
24
+ const occurredAt = req.occurredAt ?? worldNow();
25
25
  await applyTwinWrite(SERVICE, {
26
26
  operation,
27
27
  subjectType: type,
@@ -147,7 +147,7 @@ export function revertTunnelRelayRegistration(tunnelId, registrationId, options
147
147
  op: 'revert',
148
148
  operation: 'relay.register.rollback',
149
149
  subject: registration.subject,
150
- occurredAt: options.occurredAt ?? new Date().toISOString(),
150
+ occurredAt: options.occurredAt ?? worldNow(),
151
151
  actor: { kind: 'system', id: 'tunnel-twin' },
152
152
  revertsActionId: registration.id,
153
153
  }, options.root);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volter/twin-tunnel",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Local Cloudflare Quick Tunnel control-plane and Volter relay twin with a genuine loopback HTTP data path.",
5
5
  "author": "Volter (https://github.com/volter-ai)",
6
6
  "license": "Apache-2.0",
@@ -33,7 +33,7 @@
33
33
  "postpack": "node ../../../scripts/publish/prepare-publish.mjs postpack"
34
34
  },
35
35
  "peerDependencies": {
36
- "@volter/world-core": "2.0.0"
36
+ "@volter/world-core": "2.0.1"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@types/bun": "^1.2.20",
@@ -41,7 +41,7 @@
41
41
  "@types/ws": "^8.18.1",
42
42
  "@volter/tunnel": "^2.0.5",
43
43
  "@volter/tunnel-core": "0.1.3",
44
- "@volter/world-core": "2.0.0",
44
+ "@volter/world-core": "2.0.1",
45
45
  "@volter/world-tooling": "0.1.0",
46
46
  "typescript": "^5.9.0"
47
47
  },
@@ -259,7 +259,7 @@ function verifyJwt(token: string, secret: string, tunnelId: string, requireTid:
259
259
  if (!constantEqual(signature, expected)) return false;
260
260
  const payload = JSON.parse(Buffer.from(body, 'base64url').toString('utf8')) as Record<string, unknown>;
261
261
  if (!payload || typeof payload !== 'object' || Array.isArray(payload)) return false;
262
- const now = Math.floor(Date.now() / 1000);
262
+ const now = Math.floor(Date.parse(worldNow()) / 1000);
263
263
  if (payload.exp !== undefined && (typeof payload.exp !== 'number' || !Number.isFinite(payload.exp))) return false;
264
264
  if (payload.nbf !== undefined && (typeof payload.nbf !== 'number' || !Number.isFinite(payload.nbf))) return false;
265
265
  if (typeof payload.exp === 'number' && payload.exp <= now) return false;
@@ -1092,7 +1092,7 @@ export function createTunnelTwinHandler(options: TunnelTwinOptions = {}) {
1092
1092
  },
1093
1093
  mintToken(tunnelId: string, payload: Record<string, unknown> = {}) {
1094
1094
  if (!jwtSecret) throw new Error('tunnel JWT auth is disabled');
1095
- return createTunnelTwinJwt({ sub: 'twin-local', tid: tunnelId, exp: Math.floor(Date.now() / 1000) + 3600, ...payload }, jwtSecret);
1095
+ return createTunnelTwinJwt({ sub: 'twin-local', tid: tunnelId, exp: Math.floor(Date.parse(worldNow()) / 1000) + 3600, ...payload }, jwtSecret);
1096
1096
  },
1097
1097
  stop() {
1098
1098
  clearInterval(claimHeartbeat);
@@ -1,5 +1,5 @@
1
1
  import { createHash, randomBytes, randomUUID } from 'node:crypto';
2
- import { appendAction, applyTwinWrite, listActions, projectResources, TwinActionPreconditionError, type TwinActionPrecondition } from '@volter/world-core';
2
+ import { appendAction, applyTwinWrite, listActions, projectResources, TwinActionPreconditionError, type TwinActionPrecondition, worldNow } from '@volter/world-core';
3
3
 
4
4
  const SERVICE = 'tunnel';
5
5
 
@@ -43,7 +43,7 @@ async function writeTunnel(
43
43
  req: TunnelRequest,
44
44
  preconditions?: TwinActionPrecondition[],
45
45
  ): Promise<void> {
46
- const occurredAt = req.occurredAt ?? new Date().toISOString();
46
+ const occurredAt = req.occurredAt ?? worldNow();
47
47
  await applyTwinWrite(SERVICE, {
48
48
  operation,
49
49
  subjectType: type,
@@ -215,7 +215,7 @@ export function revertTunnelRelayRegistration(
215
215
  op: 'revert',
216
216
  operation: 'relay.register.rollback',
217
217
  subject: registration.subject,
218
- occurredAt: options.occurredAt ?? new Date().toISOString(),
218
+ occurredAt: options.occurredAt ?? worldNow(),
219
219
  actor: { kind: 'system', id: 'tunnel-twin' },
220
220
  revertsActionId: registration.id,
221
221
  }, options.root);