@nextera.one/tps-standard 0.5.33 → 0.6.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 (105) hide show
  1. package/CHANGELOG.md +88 -0
  2. package/README.md +133 -56
  3. package/dist/date.d.ts +54 -0
  4. package/dist/date.js +174 -0
  5. package/dist/date.js.map +1 -0
  6. package/dist/driver-manager.d.ts +34 -0
  7. package/dist/driver-manager.js +53 -0
  8. package/dist/driver-manager.js.map +1 -0
  9. package/dist/drivers/chinese.d.ts +25 -0
  10. package/dist/drivers/chinese.js +485 -0
  11. package/dist/drivers/chinese.js.map +1 -0
  12. package/dist/drivers/gregorian.d.ts +3 -5
  13. package/dist/drivers/gregorian.js +26 -19
  14. package/dist/drivers/gregorian.js.map +1 -1
  15. package/dist/drivers/hijri.d.ts +1 -16
  16. package/dist/drivers/hijri.js +9 -102
  17. package/dist/drivers/hijri.js.map +1 -1
  18. package/dist/drivers/holocene.d.ts +6 -3
  19. package/dist/drivers/holocene.js +7 -20
  20. package/dist/drivers/holocene.js.map +1 -1
  21. package/dist/drivers/julian.d.ts +3 -10
  22. package/dist/drivers/julian.js +11 -71
  23. package/dist/drivers/julian.js.map +1 -1
  24. package/dist/drivers/persian.d.ts +1 -6
  25. package/dist/drivers/persian.js +17 -92
  26. package/dist/drivers/persian.js.map +1 -1
  27. package/dist/drivers/tps.d.ts +11 -28
  28. package/dist/drivers/tps.js +8 -58
  29. package/dist/drivers/tps.js.map +1 -1
  30. package/dist/drivers/unix.d.ts +5 -6
  31. package/dist/drivers/unix.js +10 -32
  32. package/dist/drivers/unix.js.map +1 -1
  33. package/dist/esm/date.js +170 -0
  34. package/dist/esm/date.js.map +1 -0
  35. package/dist/esm/driver-manager.js +49 -0
  36. package/dist/esm/driver-manager.js.map +1 -0
  37. package/dist/esm/drivers/chinese.js +481 -0
  38. package/dist/esm/drivers/chinese.js.map +1 -0
  39. package/dist/esm/drivers/gregorian.js +160 -0
  40. package/dist/esm/drivers/gregorian.js.map +1 -0
  41. package/dist/esm/drivers/hijri.js +184 -0
  42. package/dist/esm/drivers/hijri.js.map +1 -0
  43. package/dist/esm/drivers/holocene.js +115 -0
  44. package/dist/esm/drivers/holocene.js.map +1 -0
  45. package/dist/esm/drivers/julian.js +161 -0
  46. package/dist/esm/drivers/julian.js.map +1 -0
  47. package/dist/esm/drivers/persian.js +190 -0
  48. package/dist/esm/drivers/persian.js.map +1 -0
  49. package/dist/esm/drivers/tps.js +181 -0
  50. package/dist/esm/drivers/tps.js.map +1 -0
  51. package/dist/esm/drivers/unix.js +50 -0
  52. package/dist/esm/drivers/unix.js.map +1 -0
  53. package/dist/esm/index.js +873 -0
  54. package/dist/esm/index.js.map +1 -0
  55. package/dist/esm/types.js +28 -0
  56. package/dist/esm/types.js.map +1 -0
  57. package/dist/esm/uid.js +221 -0
  58. package/dist/esm/uid.js.map +1 -0
  59. package/dist/esm/utils/calendar.js +126 -0
  60. package/dist/esm/utils/calendar.js.map +1 -0
  61. package/dist/esm/utils/env.js +76 -0
  62. package/dist/esm/utils/env.js.map +1 -0
  63. package/dist/esm/utils/timezone.js +168 -0
  64. package/dist/esm/utils/timezone.js.map +1 -0
  65. package/dist/esm/utils/tps-string.js +160 -0
  66. package/dist/esm/utils/tps-string.js.map +1 -0
  67. package/dist/index.d.ts +84 -466
  68. package/dist/index.js +430 -1095
  69. package/dist/index.js.map +1 -1
  70. package/dist/types.d.ts +103 -0
  71. package/dist/types.js +31 -0
  72. package/dist/types.js.map +1 -0
  73. package/dist/uid.d.ts +48 -0
  74. package/dist/uid.js +225 -0
  75. package/dist/uid.js.map +1 -0
  76. package/dist/utils/calendar.d.ts +55 -0
  77. package/dist/utils/calendar.js +136 -0
  78. package/dist/utils/calendar.js.map +1 -0
  79. package/dist/utils/env.d.ts +12 -0
  80. package/dist/utils/env.js +79 -0
  81. package/dist/utils/env.js.map +1 -0
  82. package/dist/utils/timezone.d.ts +32 -0
  83. package/dist/utils/timezone.js +173 -0
  84. package/dist/utils/timezone.js.map +1 -0
  85. package/dist/utils/tps-string.d.ts +12 -0
  86. package/dist/utils/tps-string.js +164 -0
  87. package/dist/utils/tps-string.js.map +1 -0
  88. package/package.json +20 -5
  89. package/src/date.ts +243 -0
  90. package/src/driver-manager.ts +54 -0
  91. package/src/drivers/chinese.ts +542 -0
  92. package/src/drivers/gregorian.ts +29 -27
  93. package/src/drivers/hijri.ts +13 -113
  94. package/src/drivers/holocene.ts +11 -12
  95. package/src/drivers/julian.ts +18 -72
  96. package/src/drivers/persian.ts +25 -92
  97. package/src/drivers/tps.ts +16 -55
  98. package/src/drivers/unix.ts +12 -33
  99. package/src/index.ts +384 -1556
  100. package/src/types.ts +131 -0
  101. package/src/uid.ts +308 -0
  102. package/src/utils/calendar.ts +161 -0
  103. package/src/utils/env.ts +88 -0
  104. package/src/utils/timezone.ts +182 -0
  105. package/src/utils/tps-string.ts +166 -0
package/dist/index.d.ts CHANGED
@@ -2,237 +2,35 @@
2
2
  * TPS: Temporal Positioning System
3
3
  * The Universal Protocol for Space-Time Coordinates.
4
4
  * @packageDocumentation
5
- * @version 0.5.2
5
+ * @version 0.6.0
6
6
  * @license Apache-2.0
7
7
  * @copyright 2026 TPS Standards Working Group
8
8
  *
9
+ * v0.5.35 Changes:
10
+ * - Added TPS.now(), TPS.diff(), TPS.add() convenience methods
11
+ * - Added Chinese Lunisolar (chin) calendar driver
12
+ * - Added DriverManager (driver registry separated from TPS class)
13
+ * - Added timezone utility (src/utils/timezone.ts) with IANA + offset support
14
+ * - TPS.toDate() now respects ;tz= extensions when present
15
+ * - ESM dual-mode exports + browser IIFE bundle
16
+ *
9
17
  * v0.5.0 Changes:
10
18
  * - Added Actor anchor (A:) for provenance tracking
11
19
  * - Added Signature (!) for cryptographic verification
12
20
  * - Added structural anchors (bldg, floor, room, zone)
13
21
  * - Added geospatial cell systems (S2, H3, Plus Code, what3words)
14
22
  */
15
- export declare const DefaultCalendars: {
16
- readonly TPS: "tps";
17
- readonly GREG: "greg";
18
- readonly HIJ: "hij";
19
- readonly PER: "per";
20
- readonly JUL: "jul";
21
- readonly HOLO: "holo";
22
- readonly UNIX: "unix";
23
- };
24
- /**
25
- * Specifies the direction of the time-component hierarchy when serializing or
26
- * deserializing a TPS string. The default is `'descending'` (millennium → … →
27
- * second), but `'ascending'` produces the reverse order.
28
- */
29
- export declare enum TimeOrder {
30
- DESC = "desc",
31
- ASC = "asc"
32
- }
33
- export interface TPSComponents {
34
- calendar: string;
35
- millennium: number;
36
- century: number;
37
- year: number;
38
- month: number;
39
- day: number;
40
- hour: number;
41
- minute: number;
42
- second: number;
43
- /** Sub-second precision (0–999). Encoded as the last `m` token. */
44
- millisecond: number;
45
- unixSeconds?: number;
46
- latitude?: number;
47
- longitude?: number;
48
- altitude?: number;
49
- /** Google S2 cell ID (hierarchical, prefix-searchable) */
50
- s2Cell?: string;
51
- /** Uber H3 cell ID (hexagonal grid) */
52
- h3Cell?: string;
53
- /** Open Location Code / Plus Code */
54
- plusCode?: string;
55
- /** what3words address (e.g. "filled.count.soap") */
56
- what3words?: string;
57
- /** Physical building identifier */
58
- building?: string;
59
- /** Vertical division (level) */
60
- floor?: string;
61
- /** Enclosed space identifier */
62
- room?: string;
63
- /** Logical area within building */
64
- zone?: string;
65
- /** Raw pre-@ space anchor (e.g. adm:city:SA:riyadh, node:api-1, net:ip4:203.0.113.10) */
66
- spaceAnchor?: string;
67
- /** Technical missing data (e.g. server log without GPS) */
68
- isUnknownLocation?: boolean;
69
- /** Removed for legal/security reasons (e.g. GDPR) */
70
- isRedactedLocation?: boolean;
71
- /** Masked by user preference (e.g. "Don't show my location") */
72
- isHiddenLocation?: boolean;
73
- /** Actor anchor - identifies observer/witness (e.g. "did:web:sensor.example.com", "node:gateway-01") */
74
- actor?: string;
75
- /** Verification hash appended to time (e.g. "sha256:8f3e2a...") */
76
- signature?: string;
77
- extensions?: Record<string, string>;
78
- order?: TimeOrder;
79
- }
80
- /**
81
- * Interface for Calendar Driver plugins.
82
- * Implementations provide conversion logic to/from Gregorian and support for
83
- * external calendar libraries.
84
- *
85
- * @example Using a driver to parse a Hijri date string
86
- * ```ts
87
- * const driver = TPS.getDriver('hij');
88
- * if (driver?.parseDate) {
89
- * const components = driver.parseDate('1447-07-21');
90
- * const gregDate = driver.toGregorian(components);
91
- * const tpsString = TPS.fromDate(gregDate, 'hij');
92
- * }
93
- * ```
94
- *
95
- * @example Wrapping an external library (moment-hijri)
96
- * ```ts
97
- * import moment from 'moment-hijri';
98
- *
99
- * class HijriDriver implements CalendarDriver {
100
- * readonly code = 'hij';
101
- *
102
- * parseDate(input: string, format?: string): Partial<TPSComponents> {
103
- * const m = moment(input, format || 'iYYYY-iMM-iDD');
104
- * return {
105
- * calendar: 'hij',
106
- * year: m.iYear(),
107
- * month: m.iMonth() + 1,
108
- * day: m.iDate()
109
- * };
110
- * }
111
- *
112
- * fromGregorian(date: Date): Partial<TPSComponents> {
113
- * const m = moment(date);
114
- * return {
115
- * calendar: 'hij',
116
- * year: m.iYear(),
117
- * month: m.iMonth() + 1,
118
- * day: m.iDate(),
119
- * hour: m.hour(),
120
- * minute: m.minute(),
121
- * second: m.second()
122
- * };
123
- * }
124
- *
125
- * // ... other methods
126
- * }
127
- * ```
128
- */
129
- export interface CalendarDriver {
130
- /** The calendar code this driver handles (e.g., 'hij', 'jul'). */
131
- readonly code: string;
132
- /**
133
- * Human-readable name for this calendar (optional).
134
- * @example "Hijri (Islamic)"
135
- */
136
- readonly name?: string;
137
- /**
138
- * Converts a Date to this calendar's components.
139
- * @param date - The Gregorian Date object.
140
- * @returns Partial TPS components for year, month, day, etc.
141
- */
142
- getComponentsFromDate(date: Date): Partial<TPSComponents>;
143
- /**
144
- * Converts this calendar's components to a Date.
145
- * @param components - Partial TPS components (year, month, day, etc.).
146
- * @returns A JavaScript Date object.
147
- */
148
- getDateFromComponents(components: Partial<TPSComponents>): Date;
149
- /**
150
- * Generates a TPS time string for this calendar from a Date.
151
- * @param date - The Gregorian Date object.
152
- * @returns A TPS time string (e.g., "T:hij.y1447.m07.d21...").
153
- */
154
- getFromDate(date: Date): string;
155
- /**
156
- * Parse a calendar-specific date string into TPS components.
157
- * This allows drivers to handle native date formats from external libraries.
158
- *
159
- * @param input - Date string in calendar-native format (e.g., '1447-07-21' for Hijri)
160
- * @param format - Optional format string (driver-specific, e.g., 'iYYYY-iMM-iDD')
161
- * @returns Partial TPS components
162
- *
163
- * @example
164
- * ```ts
165
- * // Hijri driver
166
- * driver.parseDate('1447-07-21'); // → { year: 1447, month: 7, day: 21, calendar: 'hij' }
167
- *
168
- * // With time
169
- * driver.parseDate('1447-07-21 14:30:00'); // → { year: 1447, month: 7, day: 21, hour: 14, ... }
170
- * ```
171
- */
172
- parseDate(input: string, format?: string): Partial<TPSComponents>;
173
- /**
174
- * Format TPS components to a calendar-specific date string.
175
- * Inverse of parseDate().
176
- *
177
- * @param components - TPS components to format
178
- * @param format - Optional format string (driver-specific)
179
- * @returns Formatted date string in calendar-native format
180
- *
181
- * @example
182
- * ```ts
183
- * driver.format({ year: 1447, month: 7, day: 21 }); // → '1447-07-21'
184
- * driver.format({ year: 1447, month: 7, day: 21 }, 'short'); // → '21/7/1447'
185
- * ```
186
- */
187
- format(components: Partial<TPSComponents>, format?: string): string;
188
- /**
189
- * Validate a calendar-specific date string or components.
190
- *
191
- * @param input - Date string or components to validate
192
- * @returns true if valid for this calendar
193
- *
194
- * @example
195
- * ```ts
196
- * driver.validate('1447-13-01'); // → false (month 13 invalid)
197
- * driver.validate({ year: 1447, month: 7, day: 31 }); // → false (Rajab has 30 days)
198
- * ```
199
- */
200
- validate(input: string | Partial<TPSComponents>): boolean;
201
- /**
202
- * Get calendar metadata (month names, day names, etc.).
203
- * Useful for UI rendering.
204
- *
205
- * @example
206
- * ```ts
207
- * driver.getMetadata().monthNames
208
- * // → ['Muharram', 'Safar', 'Rabi I', ...]
209
- * ```
210
- */
211
- getMetadata(): CalendarMetadata;
212
- }
213
- /**
214
- * Metadata about a calendar system.
215
- */
216
- export interface CalendarMetadata {
217
- /** Human-readable calendar name */
218
- name: string;
219
- /** Month names in order (1-12 or 1-13) */
220
- monthNames?: string[];
221
- /** Short month names */
222
- monthNamesShort?: string[];
223
- /** Day of week names (Sunday=0 or locale-specific) */
224
- dayNames?: string[];
225
- /** Short day names */
226
- dayNamesShort?: string[];
227
- /** Whether this calendar is lunar-based */
228
- isLunar?: boolean;
229
- /** Number of months per year */
230
- monthsPerYear?: number;
231
- /** Epoch year (for reference) */
232
- epochYear?: number;
233
- }
23
+ export * from "./types";
24
+ export * from "./uid";
25
+ export * from "./date";
26
+ export { Env } from "./utils/env";
27
+ export { DriverManager } from "./driver-manager";
28
+ export { utcToLocal, localToUtc, getOffsetString } from "./utils/timezone";
29
+ import { DriverManager } from "./driver-manager";
30
+ import { CalendarDriver, TPSComponents, TimeOrder } from "./types";
234
31
  export declare class TPS {
235
- private static readonly drivers;
32
+ /** Shared DriverManager instance — use TPS.driverManager for direct access. */
33
+ static readonly driverManager: DriverManager;
236
34
  /**
237
35
  * Registers a calendar driver plugin.
238
36
  * @param driver - The driver instance to register.
@@ -359,215 +157,83 @@ export declare class TPS {
359
157
  */
360
158
  static formatCalendarDate(calendar: string, components: Partial<TPSComponents>, format?: string): string;
361
159
  /**
362
- * Generate the canonical `T:` time string for a set of components. The
363
- * `order` field (or `comp.order`) controls whether tokens are emitted in
364
- * ascending or descending hierarchy; if undefined the default
365
- * `'descending'` orientation is used.
366
- *
367
- * Drivers may ignore this helper and produce their own time strings if they
368
- * implement custom ordering logic.
369
- */
370
- static buildTimePart(comp: TPSComponents): string;
371
- /**
372
- * Parse the *time* portion of a TPS string (optionally beginning with
373
- * `T:`) into components and determine the component ordering. This helper
374
- * accepts tokens in **any** sequence and will return an `order` value of
375
- * `'ascending'` or `'descending'`.
376
- *
377
- * The caller is responsible for stripping off a leading signature or other
378
- * trailer characters; this method will drop anything after `!`, `;`, `?` or
379
- * `#`.
380
- *
381
- * ### `m`-token disambiguation
382
- * All four of millennium (rank 8), month (rank 5), minute (rank 2) and
383
- * millisecond (rank 0) share the single-character prefix `m`. They are told
384
- * apart by their **position relative to the neighbouring tokens**. The
385
- * algorithm is:
386
- *
387
- * 1. Pre-scan the non-`m` tokens (c, y, d, h, s) whose ranks are fixed to
388
- * determine whether the string is ascending or descending.
389
- * 2. While iterating, track `lastAssignedRank` – the rank of the most
390
- * recently processed token (m or non-m).
391
- * 3. When an `m` token is encountered, derive its rank from `lastAssignedRank`
392
- * and the detected order:
393
- * - **DESC** null → 8 (mill) | rank > 5 → 5 (month) | rank > 2 → 2 (min) | else → 0 (ms)
394
- * - **ASC** null → 0 (ms) | rank < 2 → 2 (min) | rank < 5 → 5 (month) | else → 8 (mill)
395
- *
396
- * @param input - Time fragment (e.g. `"T:greg.m3.c1.y26"` or `"greg.m0.s25.m30"`)
397
- */
398
- static parseTimeString(input: string): {
399
- components: Partial<TPSComponents>;
400
- order: TimeOrder;
401
- } | null;
402
- private static _mapGroupsToComponents;
403
- }
404
- /**
405
- * Decoded result from TPSUID7RB binary format.
406
- */
407
- export type TPSUID7RBDecodeResult = {
408
- /** Version identifier */
409
- version: "tpsuid7rb";
410
- /** Epoch milliseconds (UTC) */
411
- epochMs: number;
412
- /** Whether the TPS payload was compressed */
413
- compressed: boolean;
414
- /** 32-bit nonce for collision prevention */
415
- nonce: number;
416
- /** The original TPS string (exact reconstruction) */
417
- tps: string;
418
- };
419
- /**
420
- * Encoding options for TPSUID7RB.
421
- */
422
- export type TPSUID7RBEncodeOptions = {
423
- /** Enable zlib compression of TPS payload */
424
- compress?: boolean;
425
- /** Override epoch milliseconds (default: parsed from TPS) */
426
- epochMs?: number;
427
- };
428
- /**
429
- * TPS-UID v1 — Temporal Positioning System Identifier (Binary Reversible)
430
- *
431
- * A time-first, reversible identifier that binds an event to a TPS coordinate.
432
- * Unlike UUIDs, TPS-UID identifies events in spacetime and allows exact
433
- * reconstruction of the original TPS string.
434
- *
435
- * Binary Schema (all integers big-endian):
436
- * ```
437
- * MAGIC 4 bytes "TPU7"
438
- * VER 1 byte 0x01
439
- * FLAGS 1 byte bit0 = compression flag
440
- * TIME 6 bytes epoch_ms (48-bit unsigned)
441
- * NONCE 4 bytes 32-bit random
442
- * LEN varint length of TPS payload
443
- * TPS bytes UTF-8 TPS string (raw or zlib-compressed)
444
- * ```
445
- *
446
- * @example
447
- * ```ts
448
- * const tps = 'tps://31.95,35.91@T:greg.m3.c1.y26.m01.d09';
449
- *
450
- * // Encode to binary
451
- * const bytes = TPSUID7RB.encodeBinary(tps);
452
- *
453
- * // Encode to base64url string
454
- * const id = TPSUID7RB.encodeBinaryB64(tps);
455
- * // → "tpsuid7rb_AFRQV..."
456
- *
457
- * // Decode back to original TPS
458
- * const decoded = TPSUID7RB.decodeBinaryB64(id);
459
- * console.log(decoded.tps); // exact original TPS
460
- * ```
461
- */
462
- export declare class TPSUID7RB {
463
- /** Magic bytes: "TPU7" */
464
- private static readonly MAGIC;
465
- /** Version 1 */
466
- private static readonly VER;
467
- /** String prefix for base64url encoded form */
468
- private static readonly PREFIX;
469
- /** Regex for validating base64url encoded form */
470
- static readonly REGEX: RegExp;
471
- /**
472
- * Encode TPS string to binary bytes (Uint8Array).
473
- * This is the canonical form for hashing, signing, and storage.
474
- *
475
- * @param tps - The TPS string to encode
476
- * @param opts - Encoding options (compress, epochMs override)
477
- * @returns Binary TPS-UID as Uint8Array
478
- */
479
- static encodeBinary(tps: string, opts?: TPSUID7RBEncodeOptions): Uint8Array;
480
- /**
481
- * Decode binary bytes back to original TPS string.
160
+ * Returns a TPS time string for the current moment.
161
+ * Shorthand for `TPS.fromDate(new Date(), calendar, opts)`.
482
162
  *
483
- * @param bytes - Binary TPS-UID
484
- * @returns Decoded result with original TPS string
485
- */
486
- static decodeBinary(bytes: Uint8Array): TPSUID7RBDecodeResult;
487
- /**
488
- * Encode TPS to base64url string with prefix.
489
- * This is the transport/storage form.
163
+ * @param calendar - Calendar code. Defaults to 'greg'.
164
+ * @param opts - Optional `order` (ASC/DESC) parameter.
165
+ * @returns TPS time string.
490
166
  *
491
- * @param tps - The TPS string to encode
492
- * @param opts - Encoding options
493
- * @returns Base64url encoded TPS-UID with prefix
167
+ * @example
168
+ * ```ts
169
+ * TPS.now(); // "T:greg.m3.c1.y26.m3.d4.h06.m30.s00.m0"
170
+ * TPS.now('hij'); // "T:hij.y1447.m09.d05.h06.m30.s00"
171
+ * ```
494
172
  */
495
- static encodeBinaryB64(tps: string, opts?: TPSUID7RBEncodeOptions): string;
173
+ static now(calendar?: string, opts?: {
174
+ order?: TimeOrder;
175
+ }): string;
496
176
  /**
497
- * Decode base64url string back to original TPS string.
177
+ * Returns the difference in milliseconds between two TPS strings.
178
+ * The result is `t2 - t1`; negative if t1 is after t2.
498
179
  *
499
- * @param id - Base64url encoded TPS-UID with prefix
500
- * @returns Decoded result with original TPS string
501
- */
502
- static decodeBinaryB64(id: string): TPSUID7RBDecodeResult;
503
- /**
504
- * Validate base64url encoded TPS-UID format.
505
- * Note: This validates shape only; binary decode is authoritative.
180
+ * @param t1 - First TPS string (subtracted from t2).
181
+ * @param t2 - Second TPS string.
182
+ * @returns Milliseconds between the two moments, or NaN on parse failure.
506
183
  *
507
- * @param id - String to validate
508
- * @returns true if format is valid
184
+ * @example
185
+ * ```ts
186
+ * const ms = TPS.diff('T:greg.m3.c1.y26.m1.d1.h0.m0.s0.m0',
187
+ * 'T:greg.m3.c1.y26.m1.d2.h0.m0.s0.m0');
188
+ * // 86_400_000 (one day)
189
+ * ```
509
190
  */
510
- static validateBinaryB64(id: string): boolean;
191
+ static diff(t1: string, t2: string): number;
511
192
  /**
512
- * Generate a TPS-UID from the current time and optional location.
193
+ * Returns a new TPS string shifted by the given duration.
194
+ * The result is in the same calendar as the original string.
513
195
  *
514
- * @param opts - Generation options
515
- * @returns Base64url encoded TPS-UID
516
- */
517
- static generate(opts?: {
518
- latitude?: number;
519
- longitude?: number;
520
- altitude?: number;
521
- compress?: boolean;
522
- order?: TimeOrder;
523
- }): string;
524
- /**
525
- * Generate a TPS string from a Date and optional location.
526
- */
527
- /**
528
- * Parse epoch milliseconds from a TPS string.
529
- * Supports both URI format (tps://...) and time-only format (T:greg...)
530
- */
531
- static epochMsFromTPSString(tps: string): number;
532
- /** Write 48-bit unsigned integer (big-endian) */
533
- private static writeU48;
534
- /** Read 48-bit unsigned integer (big-endian) */
535
- private static readU48;
536
- /** Encode unsigned integer as LEB128 varint */
537
- private static uvarintEncode;
538
- /** Decode LEB128 varint */
539
- private static uvarintDecode;
540
- /** Encode bytes to base64url (no padding) */
541
- private static base64UrlEncode;
542
- /** Decode base64url to bytes */
543
- private static base64UrlDecode;
544
- /** Compress using zlib deflate raw */
545
- private static deflateRaw;
546
- /** Decompress using zlib inflate raw */
547
- private static inflateRaw;
548
- /**
549
- * Seal (sign) a TPS string to create a cryptographically verifiable TPS-UID.
550
- * This appends an Ed25519 signature to the binary form.
196
+ * @param tpsStr - Source TPS string.
197
+ * @param duration - Object with optional `days`, `hours`, `minutes`, `seconds`, `milliseconds`.
198
+ * @returns Shifted TPS string, or null if the input is invalid.
551
199
  *
552
- * @param tps - The TPS string to seal
553
- * @param privateKey - Ed25519 private key (hex or buffer)
554
- * @param opts - Encoding options
555
- * @returns Sealed binary TPS-UID
200
+ * @example
201
+ * ```ts
202
+ * const t = 'T:greg.m3.c1.y26.m1.d9.h14.m30.s25.m0';
203
+ * TPS.add(t, { days: 7 }); // one week later
204
+ * TPS.add(t, { hours: -2 }); // two hours earlier
205
+ * ```
556
206
  */
557
- static seal(tps: string, privateKey: string | Buffer | Uint8Array, opts?: TPSUID7RBEncodeOptions): Uint8Array;
207
+ static add(tpsStr: string, duration: {
208
+ days?: number;
209
+ hours?: number;
210
+ minutes?: number;
211
+ seconds?: number;
212
+ milliseconds?: number;
213
+ }): string | null;
214
+ private static _mapGroupsToComponents;
558
215
  /**
559
- * Verify a sealed TPS-UID and decode it.
560
- * Throws if signature is invalid or not sealed.
561
- *
562
- * @param sealedBytes - The binary sealed TPS-UID
563
- * @param publicKey - Ed25519 public key (hex or buffer) to verify against
564
- * @returns Decoded result
565
- */
566
- static verifyAndDecode(sealedBytes: Uint8Array, publicKey: string | Buffer | Uint8Array): TPSUID7RBDecodeResult;
567
- private static signEd25519;
568
- private static verifyEd25519;
569
- /** Generate cryptographically secure random bytes */
570
- private static randomBytes;
216
+ * Parses a multi-layer location string (before @T:) into component fields.
217
+ * Layers are `;`-separated. Each layer is identified by its prefix token.
218
+ *
219
+ * Supported layers:
220
+ * L:lat,lon[,altm] — GPS
221
+ * L:~|L:-|L:redacted — Privacy markers
222
+ * P:cc=JO,ci=AMM,... — Place (country/city codes and names)
223
+ * S2:token — S2 cell
224
+ * H3:token — H3 cell
225
+ * 3W:word.word.word — What3Words
226
+ * plus:token — Plus Code
227
+ * net:ip4:x.x.x.x — IPv4
228
+ * net:ip6:x::x — IPv6
229
+ * node:name — Logical node/host
230
+ * bldg:name — Building
231
+ * floor:x — Floor
232
+ * room:x — Room
233
+ * door:x — Door
234
+ * zone:x — Zone
235
+ */
236
+ private static _parseLocationLayers;
571
237
  }
572
238
  /**
573
239
  * `TpsDate` is a Date-like wrapper with native TPS conversion helpers.
@@ -579,51 +245,3 @@ export declare class TPSUID7RB {
579
245
  * - `new TpsDate(tpsString)`
580
246
  * - `new TpsDate(year, monthIndex, day?, hour?, minute?, second?, ms?)`
581
247
  */
582
- export declare class TpsDate {
583
- private readonly internal;
584
- private getTpsComponents;
585
- private getTpsFullYear;
586
- constructor();
587
- constructor(value: string | number | Date | TpsDate);
588
- constructor(year: number, monthIndex: number, day?: number, hours?: number, minutes?: number, seconds?: number, ms?: number);
589
- private static looksLikeTPS;
590
- static now(): number;
591
- static parse(input: string): number;
592
- static UTC(year: number, monthIndex: number, day?: number, hours?: number, minutes?: number, seconds?: number, ms?: number): number;
593
- static fromTPS(tps: string): TpsDate;
594
- toGregorianDate(): Date;
595
- toDate(): Date;
596
- toTPS(calendar?: string, opts?: {
597
- order?: TimeOrder;
598
- }): string;
599
- toTPSURI(calendar?: string, opts?: {
600
- order?: TimeOrder;
601
- latitude?: number;
602
- longitude?: number;
603
- altitude?: number;
604
- isUnknownLocation?: boolean;
605
- isHiddenLocation?: boolean;
606
- isRedactedLocation?: boolean;
607
- }): string;
608
- getTime(): number;
609
- valueOf(): number;
610
- toString(): string;
611
- toISOString(): string;
612
- toUTCString(): string;
613
- toJSON(): string | null;
614
- getFullYear(): number;
615
- getUTCFullYear(): number;
616
- getMonth(): number;
617
- getUTCMonth(): number;
618
- getDate(): number;
619
- getUTCDate(): number;
620
- getHours(): number;
621
- getUTCHours(): number;
622
- getMinutes(): number;
623
- getUTCMinutes(): number;
624
- getSeconds(): number;
625
- getUTCSeconds(): number;
626
- getMilliseconds(): number;
627
- getUTCMilliseconds(): number;
628
- [Symbol.toPrimitive](hint: string): string | number;
629
- }