@openllmsh/sdk 2.10.19-alpha.2 → 2.10.19-alpha.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.
@@ -26794,22 +26794,17 @@
26794
26794
  "deleted"
26795
26795
  ]
26796
26796
  },
26797
- "generation": {
26797
+ "public_ipv4": {
26798
26798
  "anyOf": [
26799
26799
  {
26800
- "type": "number"
26800
+ "type": "string"
26801
26801
  },
26802
26802
  {
26803
- "type": "string",
26804
- "enum": [
26805
- "Infinity",
26806
- "-Infinity",
26807
- "NaN"
26808
- ]
26803
+ "type": "null"
26809
26804
  }
26810
26805
  ]
26811
26806
  },
26812
- "public_ipv4": {
26807
+ "failure_code": {
26813
26808
  "anyOf": [
26814
26809
  {
26815
26810
  "type": "string"
@@ -26819,7 +26814,7 @@
26819
26814
  }
26820
26815
  ]
26821
26816
  },
26822
- "failure_code": {
26817
+ "key_id": {
26823
26818
  "anyOf": [
26824
26819
  {
26825
26820
  "type": "string"
@@ -26829,10 +26824,22 @@
26829
26824
  }
26830
26825
  ]
26831
26826
  },
26832
- "vault_key_id": {
26833
- "type": "string"
26827
+ "reset_epoch": {
26828
+ "anyOf": [
26829
+ {
26830
+ "type": "number"
26831
+ },
26832
+ {
26833
+ "type": "string",
26834
+ "enum": [
26835
+ "Infinity",
26836
+ "-Infinity",
26837
+ "NaN"
26838
+ ]
26839
+ }
26840
+ ]
26834
26841
  },
26835
- "key_id": {
26842
+ "subject_id": {
26836
26843
  "anyOf": [
26837
26844
  {
26838
26845
  "type": "string"
@@ -26845,6 +26852,9 @@
26845
26852
  "unlock_sent": {
26846
26853
  "type": "boolean"
26847
26854
  },
26855
+ "has_machine": {
26856
+ "type": "boolean"
26857
+ },
26848
26858
  "boot": {
26849
26859
  "anyOf": [
26850
26860
  {
@@ -26884,9 +26894,6 @@
26884
26894
  }
26885
26895
  ]
26886
26896
  },
26887
- "created_at": {
26888
- "type": "string"
26889
- },
26890
26897
  "updated_at": {
26891
26898
  "type": "string"
26892
26899
  }
@@ -26894,14 +26901,14 @@
26894
26901
  "required": [
26895
26902
  "id",
26896
26903
  "state",
26897
- "generation",
26898
26904
  "public_ipv4",
26899
26905
  "failure_code",
26900
- "vault_key_id",
26901
26906
  "key_id",
26907
+ "reset_epoch",
26908
+ "subject_id",
26902
26909
  "unlock_sent",
26910
+ "has_machine",
26903
26911
  "boot",
26904
- "created_at",
26905
26912
  "updated_at"
26906
26913
  ],
26907
26914
  "additionalProperties": false
@@ -26916,7 +26923,9 @@
26916
26923
  {
26917
26924
  "type": "string",
26918
26925
  "enum": [
26919
- "machine_gone"
26926
+ "machine_gone",
26927
+ "machine_moved",
26928
+ "no_machine_available"
26920
26929
  ]
26921
26930
  },
26922
26931
  {
@@ -27360,22 +27369,17 @@
27360
27369
  "deleted"
27361
27370
  ]
27362
27371
  },
27363
- "generation": {
27372
+ "public_ipv4": {
27364
27373
  "anyOf": [
27365
27374
  {
27366
- "type": "number"
27375
+ "type": "string"
27367
27376
  },
27368
27377
  {
27369
- "type": "string",
27370
- "enum": [
27371
- "Infinity",
27372
- "-Infinity",
27373
- "NaN"
27374
- ]
27378
+ "type": "null"
27375
27379
  }
27376
27380
  ]
27377
27381
  },
27378
- "public_ipv4": {
27382
+ "failure_code": {
27379
27383
  "anyOf": [
27380
27384
  {
27381
27385
  "type": "string"
@@ -27385,7 +27389,7 @@
27385
27389
  }
27386
27390
  ]
27387
27391
  },
27388
- "failure_code": {
27392
+ "key_id": {
27389
27393
  "anyOf": [
27390
27394
  {
27391
27395
  "type": "string"
@@ -27395,10 +27399,22 @@
27395
27399
  }
27396
27400
  ]
27397
27401
  },
27398
- "vault_key_id": {
27399
- "type": "string"
27402
+ "reset_epoch": {
27403
+ "anyOf": [
27404
+ {
27405
+ "type": "number"
27406
+ },
27407
+ {
27408
+ "type": "string",
27409
+ "enum": [
27410
+ "Infinity",
27411
+ "-Infinity",
27412
+ "NaN"
27413
+ ]
27414
+ }
27415
+ ]
27400
27416
  },
27401
- "key_id": {
27417
+ "subject_id": {
27402
27418
  "anyOf": [
27403
27419
  {
27404
27420
  "type": "string"
@@ -27411,6 +27427,9 @@
27411
27427
  "unlock_sent": {
27412
27428
  "type": "boolean"
27413
27429
  },
27430
+ "has_machine": {
27431
+ "type": "boolean"
27432
+ },
27414
27433
  "boot": {
27415
27434
  "anyOf": [
27416
27435
  {
@@ -27450,9 +27469,6 @@
27450
27469
  }
27451
27470
  ]
27452
27471
  },
27453
- "created_at": {
27454
- "type": "string"
27455
- },
27456
27472
  "updated_at": {
27457
27473
  "type": "string"
27458
27474
  }
@@ -27460,14 +27476,14 @@
27460
27476
  "required": [
27461
27477
  "id",
27462
27478
  "state",
27463
- "generation",
27464
27479
  "public_ipv4",
27465
27480
  "failure_code",
27466
- "vault_key_id",
27467
27481
  "key_id",
27482
+ "reset_epoch",
27483
+ "subject_id",
27468
27484
  "unlock_sent",
27485
+ "has_machine",
27469
27486
  "boot",
27470
- "created_at",
27471
27487
  "updated_at"
27472
27488
  ],
27473
27489
  "additionalProperties": false
@@ -27482,7 +27498,9 @@
27482
27498
  {
27483
27499
  "type": "string",
27484
27500
  "enum": [
27485
- "machine_gone"
27501
+ "machine_gone",
27502
+ "machine_moved",
27503
+ "no_machine_available"
27486
27504
  ]
27487
27505
  },
27488
27506
  {
@@ -27532,22 +27550,17 @@
27532
27550
  "deleted"
27533
27551
  ]
27534
27552
  },
27535
- "generation": {
27553
+ "public_ipv4": {
27536
27554
  "anyOf": [
27537
27555
  {
27538
- "type": "number"
27556
+ "type": "string"
27539
27557
  },
27540
27558
  {
27541
- "type": "string",
27542
- "enum": [
27543
- "Infinity",
27544
- "-Infinity",
27545
- "NaN"
27546
- ]
27559
+ "type": "null"
27547
27560
  }
27548
27561
  ]
27549
27562
  },
27550
- "public_ipv4": {
27563
+ "failure_code": {
27551
27564
  "anyOf": [
27552
27565
  {
27553
27566
  "type": "string"
@@ -27557,7 +27570,7 @@
27557
27570
  }
27558
27571
  ]
27559
27572
  },
27560
- "failure_code": {
27573
+ "key_id": {
27561
27574
  "anyOf": [
27562
27575
  {
27563
27576
  "type": "string"
@@ -27567,10 +27580,22 @@
27567
27580
  }
27568
27581
  ]
27569
27582
  },
27570
- "vault_key_id": {
27571
- "type": "string"
27583
+ "reset_epoch": {
27584
+ "anyOf": [
27585
+ {
27586
+ "type": "number"
27587
+ },
27588
+ {
27589
+ "type": "string",
27590
+ "enum": [
27591
+ "Infinity",
27592
+ "-Infinity",
27593
+ "NaN"
27594
+ ]
27595
+ }
27596
+ ]
27572
27597
  },
27573
- "key_id": {
27598
+ "subject_id": {
27574
27599
  "anyOf": [
27575
27600
  {
27576
27601
  "type": "string"
@@ -27583,6 +27608,9 @@
27583
27608
  "unlock_sent": {
27584
27609
  "type": "boolean"
27585
27610
  },
27611
+ "has_machine": {
27612
+ "type": "boolean"
27613
+ },
27586
27614
  "boot": {
27587
27615
  "anyOf": [
27588
27616
  {
@@ -27622,9 +27650,6 @@
27622
27650
  }
27623
27651
  ]
27624
27652
  },
27625
- "created_at": {
27626
- "type": "string"
27627
- },
27628
27653
  "updated_at": {
27629
27654
  "type": "string"
27630
27655
  }
@@ -27632,14 +27657,14 @@
27632
27657
  "required": [
27633
27658
  "id",
27634
27659
  "state",
27635
- "generation",
27636
27660
  "public_ipv4",
27637
27661
  "failure_code",
27638
- "vault_key_id",
27639
27662
  "key_id",
27663
+ "reset_epoch",
27664
+ "subject_id",
27640
27665
  "unlock_sent",
27666
+ "has_machine",
27641
27667
  "boot",
27642
- "created_at",
27643
27668
  "updated_at"
27644
27669
  ],
27645
27670
  "additionalProperties": false
@@ -27654,7 +27679,9 @@
27654
27679
  {
27655
27680
  "type": "string",
27656
27681
  "enum": [
27657
- "machine_gone"
27682
+ "machine_gone",
27683
+ "machine_moved",
27684
+ "no_machine_available"
27658
27685
  ]
27659
27686
  },
27660
27687
  {
@@ -28109,22 +28136,17 @@
28109
28136
  "deleted"
28110
28137
  ]
28111
28138
  },
28112
- "generation": {
28139
+ "public_ipv4": {
28113
28140
  "anyOf": [
28114
28141
  {
28115
- "type": "number"
28142
+ "type": "string"
28116
28143
  },
28117
28144
  {
28118
- "type": "string",
28119
- "enum": [
28120
- "Infinity",
28121
- "-Infinity",
28122
- "NaN"
28123
- ]
28145
+ "type": "null"
28124
28146
  }
28125
28147
  ]
28126
28148
  },
28127
- "public_ipv4": {
28149
+ "failure_code": {
28128
28150
  "anyOf": [
28129
28151
  {
28130
28152
  "type": "string"
@@ -28134,7 +28156,7 @@
28134
28156
  }
28135
28157
  ]
28136
28158
  },
28137
- "failure_code": {
28159
+ "key_id": {
28138
28160
  "anyOf": [
28139
28161
  {
28140
28162
  "type": "string"
@@ -28144,10 +28166,22 @@
28144
28166
  }
28145
28167
  ]
28146
28168
  },
28147
- "vault_key_id": {
28148
- "type": "string"
28169
+ "reset_epoch": {
28170
+ "anyOf": [
28171
+ {
28172
+ "type": "number"
28173
+ },
28174
+ {
28175
+ "type": "string",
28176
+ "enum": [
28177
+ "Infinity",
28178
+ "-Infinity",
28179
+ "NaN"
28180
+ ]
28181
+ }
28182
+ ]
28149
28183
  },
28150
- "key_id": {
28184
+ "subject_id": {
28151
28185
  "anyOf": [
28152
28186
  {
28153
28187
  "type": "string"
@@ -28160,6 +28194,9 @@
28160
28194
  "unlock_sent": {
28161
28195
  "type": "boolean"
28162
28196
  },
28197
+ "has_machine": {
28198
+ "type": "boolean"
28199
+ },
28163
28200
  "boot": {
28164
28201
  "anyOf": [
28165
28202
  {
@@ -28199,9 +28236,6 @@
28199
28236
  }
28200
28237
  ]
28201
28238
  },
28202
- "created_at": {
28203
- "type": "string"
28204
- },
28205
28239
  "updated_at": {
28206
28240
  "type": "string"
28207
28241
  }
@@ -28209,14 +28243,14 @@
28209
28243
  "required": [
28210
28244
  "id",
28211
28245
  "state",
28212
- "generation",
28213
28246
  "public_ipv4",
28214
28247
  "failure_code",
28215
- "vault_key_id",
28216
28248
  "key_id",
28249
+ "reset_epoch",
28250
+ "subject_id",
28217
28251
  "unlock_sent",
28252
+ "has_machine",
28218
28253
  "boot",
28219
- "created_at",
28220
28254
  "updated_at"
28221
28255
  ],
28222
28256
  "additionalProperties": false
@@ -28231,7 +28265,9 @@
28231
28265
  {
28232
28266
  "type": "string",
28233
28267
  "enum": [
28234
- "machine_gone"
28268
+ "machine_gone",
28269
+ "machine_moved",
28270
+ "no_machine_available"
28235
28271
  ]
28236
28272
  },
28237
28273
  {
@@ -28686,22 +28722,17 @@
28686
28722
  "deleted"
28687
28723
  ]
28688
28724
  },
28689
- "generation": {
28725
+ "public_ipv4": {
28690
28726
  "anyOf": [
28691
28727
  {
28692
- "type": "number"
28728
+ "type": "string"
28693
28729
  },
28694
28730
  {
28695
- "type": "string",
28696
- "enum": [
28697
- "Infinity",
28698
- "-Infinity",
28699
- "NaN"
28700
- ]
28731
+ "type": "null"
28701
28732
  }
28702
28733
  ]
28703
28734
  },
28704
- "public_ipv4": {
28735
+ "failure_code": {
28705
28736
  "anyOf": [
28706
28737
  {
28707
28738
  "type": "string"
@@ -28711,7 +28742,7 @@
28711
28742
  }
28712
28743
  ]
28713
28744
  },
28714
- "failure_code": {
28745
+ "key_id": {
28715
28746
  "anyOf": [
28716
28747
  {
28717
28748
  "type": "string"
@@ -28721,10 +28752,22 @@
28721
28752
  }
28722
28753
  ]
28723
28754
  },
28724
- "vault_key_id": {
28725
- "type": "string"
28755
+ "reset_epoch": {
28756
+ "anyOf": [
28757
+ {
28758
+ "type": "number"
28759
+ },
28760
+ {
28761
+ "type": "string",
28762
+ "enum": [
28763
+ "Infinity",
28764
+ "-Infinity",
28765
+ "NaN"
28766
+ ]
28767
+ }
28768
+ ]
28726
28769
  },
28727
- "key_id": {
28770
+ "subject_id": {
28728
28771
  "anyOf": [
28729
28772
  {
28730
28773
  "type": "string"
@@ -28737,6 +28780,9 @@
28737
28780
  "unlock_sent": {
28738
28781
  "type": "boolean"
28739
28782
  },
28783
+ "has_machine": {
28784
+ "type": "boolean"
28785
+ },
28740
28786
  "boot": {
28741
28787
  "anyOf": [
28742
28788
  {
@@ -28776,9 +28822,6 @@
28776
28822
  }
28777
28823
  ]
28778
28824
  },
28779
- "created_at": {
28780
- "type": "string"
28781
- },
28782
28825
  "updated_at": {
28783
28826
  "type": "string"
28784
28827
  }
@@ -28786,14 +28829,14 @@
28786
28829
  "required": [
28787
28830
  "id",
28788
28831
  "state",
28789
- "generation",
28790
28832
  "public_ipv4",
28791
28833
  "failure_code",
28792
- "vault_key_id",
28793
28834
  "key_id",
28835
+ "reset_epoch",
28836
+ "subject_id",
28794
28837
  "unlock_sent",
28838
+ "has_machine",
28795
28839
  "boot",
28796
- "created_at",
28797
28840
  "updated_at"
28798
28841
  ],
28799
28842
  "additionalProperties": false
@@ -28808,7 +28851,9 @@
28808
28851
  {
28809
28852
  "type": "string",
28810
28853
  "enum": [
28811
- "machine_gone"
28854
+ "machine_gone",
28855
+ "machine_moved",
28856
+ "no_machine_available"
28812
28857
  ]
28813
28858
  },
28814
28859
  {
@@ -29263,22 +29308,17 @@
29263
29308
  "deleted"
29264
29309
  ]
29265
29310
  },
29266
- "generation": {
29311
+ "public_ipv4": {
29267
29312
  "anyOf": [
29268
29313
  {
29269
- "type": "number"
29314
+ "type": "string"
29270
29315
  },
29271
29316
  {
29272
- "type": "string",
29273
- "enum": [
29274
- "Infinity",
29275
- "-Infinity",
29276
- "NaN"
29277
- ]
29317
+ "type": "null"
29278
29318
  }
29279
29319
  ]
29280
29320
  },
29281
- "public_ipv4": {
29321
+ "failure_code": {
29282
29322
  "anyOf": [
29283
29323
  {
29284
29324
  "type": "string"
@@ -29288,7 +29328,7 @@
29288
29328
  }
29289
29329
  ]
29290
29330
  },
29291
- "failure_code": {
29331
+ "key_id": {
29292
29332
  "anyOf": [
29293
29333
  {
29294
29334
  "type": "string"
@@ -29298,10 +29338,22 @@
29298
29338
  }
29299
29339
  ]
29300
29340
  },
29301
- "vault_key_id": {
29302
- "type": "string"
29341
+ "reset_epoch": {
29342
+ "anyOf": [
29343
+ {
29344
+ "type": "number"
29345
+ },
29346
+ {
29347
+ "type": "string",
29348
+ "enum": [
29349
+ "Infinity",
29350
+ "-Infinity",
29351
+ "NaN"
29352
+ ]
29353
+ }
29354
+ ]
29303
29355
  },
29304
- "key_id": {
29356
+ "subject_id": {
29305
29357
  "anyOf": [
29306
29358
  {
29307
29359
  "type": "string"
@@ -29314,6 +29366,9 @@
29314
29366
  "unlock_sent": {
29315
29367
  "type": "boolean"
29316
29368
  },
29369
+ "has_machine": {
29370
+ "type": "boolean"
29371
+ },
29317
29372
  "boot": {
29318
29373
  "anyOf": [
29319
29374
  {
@@ -29353,9 +29408,6 @@
29353
29408
  }
29354
29409
  ]
29355
29410
  },
29356
- "created_at": {
29357
- "type": "string"
29358
- },
29359
29411
  "updated_at": {
29360
29412
  "type": "string"
29361
29413
  }
@@ -29363,14 +29415,14 @@
29363
29415
  "required": [
29364
29416
  "id",
29365
29417
  "state",
29366
- "generation",
29367
29418
  "public_ipv4",
29368
29419
  "failure_code",
29369
- "vault_key_id",
29370
29420
  "key_id",
29421
+ "reset_epoch",
29422
+ "subject_id",
29371
29423
  "unlock_sent",
29424
+ "has_machine",
29372
29425
  "boot",
29373
- "created_at",
29374
29426
  "updated_at"
29375
29427
  ],
29376
29428
  "additionalProperties": false
@@ -29385,7 +29437,9 @@
29385
29437
  {
29386
29438
  "type": "string",
29387
29439
  "enum": [
29388
- "machine_gone"
29440
+ "machine_gone",
29441
+ "machine_moved",
29442
+ "no_machine_available"
29389
29443
  ]
29390
29444
  },
29391
29445
  {
@@ -55,6 +55,13 @@ export type TMintedApiKey = {
55
55
  * 6. shows `sk-llm-{id}.{secret_b64url}` once.
56
56
  */
57
57
  export declare const mintApiKey: (dek: Uint8Array, vaultVersion: number) => Promise<TMintedApiKey>;
58
+ /**
59
+ * {@link mintApiKey} with a caller-chosen `(id, secret)` — for a key that must
60
+ * be re-derivable (the Routebox's, from the seed). The DEK wrap and the sealed
61
+ * copy still use random nonces, so the row differs per call but the `sk-llm`
62
+ * string is the same. Never zeroes `apiKeySecret`.
63
+ */
64
+ export declare const mintApiKeyFrom: (dek: Uint8Array, vaultVersion: number, apiKeyId: string, apiKeySecret: Uint8Array) => Promise<TMintedApiKey>;
58
65
  /** The secret columns of an `api_keys` row re-wrapped under a new DEK. */
59
66
  export type TRewrappedApiKey = {
60
67
  readonly dek_for_key: string;
@@ -71,9 +71,17 @@ const newApiKeyId = () => toB64Url(randomBytes(OPENLLM_API_KEY_ID_BYTES));
71
71
  * vault_version }` to `/api/keys`,
72
72
  * 6. shows `sk-llm-{id}.{secret_b64url}` once.
73
73
  */
74
- export const mintApiKey = async (dek, vaultVersion) => {
75
- const apiKeyId = newApiKeyId();
76
- const apiKeySecret = randomBytes(OPENLLM_API_KEY_SECRET_BYTES);
74
+ export const mintApiKey = (dek, vaultVersion) => mintApiKeyFrom(dek, vaultVersion, newApiKeyId(), randomBytes(OPENLLM_API_KEY_SECRET_BYTES));
75
+ /**
76
+ * {@link mintApiKey} with a caller-chosen `(id, secret)` — for a key that must
77
+ * be re-derivable (the Routebox's, from the seed). The DEK wrap and the sealed
78
+ * copy still use random nonces, so the row differs per call but the `sk-llm`
79
+ * string is the same. Never zeroes `apiKeySecret`.
80
+ */
81
+ export const mintApiKeyFrom = async (dek, vaultVersion, apiKeyId, apiKeySecret) => {
82
+ if (apiKeySecret.length !== OPENLLM_API_KEY_SECRET_BYTES) {
83
+ throw new Error("API key secret must be 32 bytes");
84
+ }
77
85
  const wrapKey = await deriveApiWrapKey(apiKeySecret, apiKeyId);
78
86
  try {
79
87
  const nonce = randomBytes(NONCE_BYTES);
@@ -1,3 +1,16 @@
1
- export declare const ROUTEBOX_HOME_HKDF_INFO = "openllm-routebox-home-v1";
1
+ import type { TMintedApiKey } from "./api-key.js";
2
+ export declare const ROUTEBOX_HOME_HKDF_INFO = "openllm-routebox-home-v2";
3
+ export declare const ROUTEBOX_KEY_ID_HKDF_INFO = "openllm-routebox-key-id-v1";
4
+ export declare const ROUTEBOX_KEY_SECRET_HKDF_INFO = "openllm-routebox-key-secret-v1";
2
5
  /** Derive the box's home key; the caller must zero the returned bytes. */
3
- export declare const deriveRouteboxHomeKey: (controlSeed: Uint8Array, keyId: string) => Promise<Uint8Array>;
6
+ export declare const deriveRouteboxHomeKey: (controlSeed: Uint8Array, subjectId: string, epoch: number) => Promise<Uint8Array>;
7
+ /** The box's API key id, in the ordinary base64url key-id encoding. */
8
+ export declare const deriveRouteboxKeyId: (controlSeed: Uint8Array, subjectId: string, epoch: number) => Promise<string>;
9
+ /** The box's API key secret; the caller must zero the returned bytes. */
10
+ export declare const deriveRouteboxKeySecret: (controlSeed: Uint8Array, subjectId: string, epoch: number) => Promise<Uint8Array>;
11
+ /**
12
+ * Mint the box's API key deterministically: a normal `api_keys` row whose id
13
+ * and `sk-llm` string are the same every time for this seed and machine (only
14
+ * the DEK-wrap nonces are random).
15
+ */
16
+ export declare const mintRouteboxApiKey: (dek: Uint8Array, vaultVersion: number, controlSeed: Uint8Array, subjectId: string, epoch: number) => Promise<TMintedApiKey>;
@@ -1,35 +1,79 @@
1
1
  /**
2
- * The Routebox's home key: what opens its encrypted home (LUKS).
2
+ * The Routebox's keys, all derived from the account's device-control seed and
3
+ * the machine's GalaxyGate SUBJECT id (stable for the machine's life, across
4
+ * deployments, resets and re-claims):
3
5
  *
4
- * Derived from the box API key's DEVICE ANCHOR secret — the per-key pair
5
- * secret `HKDF(device-control seed, key id)` (`device-anchor.ts`) that every
6
- * anchored device already holds — under its own label, so the home key and the
7
- * anchor's other uses never coincide. The device-control seed is itself
8
- * `HKDF(vault seed)`, held by an unlocked browser and by nothing else: no API
9
- * key, daemon or server. So the home key is deterministic from the recovery
10
- * phrase, stored nowhere, re-derivable by the owner's browser after every
11
- * reboot, different for every key, and gone with a vault rotation. A box that
12
- * is reset or replaced gets a new key, so a new home key; deleting the key is
13
- * the revocation.
6
+ * - the box's API key id (10 bytes, the normal key-id encoding),
7
+ * - the box's API key secret (32 bytes),
8
+ * - the home key that opens its encrypted home (LUKS).
9
+ *
10
+ * all also depend on the box's reset epoch (see `saltOf`).
11
+ *
12
+ * Each is `HKDF-SHA256(seed, utf8(subject id), <own info>, n)`, so they never
13
+ * coincide. The device-control seed is itself `HKDF(vault seed)`, held by an
14
+ * unlocked browser and by nothing else: no API key, daemon or server. So any
15
+ * deployment, given the same user's phrase, rebuilds the same `sk-llm` and the
16
+ * same home key — the key already on the box keeps working after a takeover.
17
+ * Different subject or seed, different keys; a vault rotation changes the seed
18
+ * and so everything.
14
19
  *
15
20
  * Deliberately NOT re-exported from `vault/index.ts`: the `openllm` binary
16
- * imports that barrel, and a box only ever receives this key. Import it by
21
+ * imports that barrel, and a box only ever receives these keys. Import by
17
22
  * subpath: `@openllmsh/sdk/vault/routebox-key`.
18
23
  */
19
- import { hkdfSha256, zero } from "./crypto.js";
20
- import { deriveDevicePairSecret } from "./device-anchor.js";
24
+ import { OPENLLM_API_KEY_ID_BYTES, OPENLLM_API_KEY_SECRET_BYTES, } from "@openllmsh/sdk/protocol";
25
+ import { mintApiKeyFrom } from "./api-key.js";
26
+ import { hkdfSha256, toB64Url, zero } from "./crypto.js";
21
27
  import { DEVICE_CONTROL_SEED_BYTES } from "./device-control.js";
22
- export const ROUTEBOX_HOME_HKDF_INFO = "openllm-routebox-home-v1";
23
- /** Derive the box's home key; the caller must zero the returned bytes. */
24
- export const deriveRouteboxHomeKey = async (controlSeed, keyId) => {
28
+ export const ROUTEBOX_HOME_HKDF_INFO = "openllm-routebox-home-v2";
29
+ export const ROUTEBOX_KEY_ID_HKDF_INFO = "openllm-routebox-key-id-v1";
30
+ export const ROUTEBOX_KEY_SECRET_HKDF_INFO = "openllm-routebox-key-secret-v1";
31
+ /**
32
+ * The salt: the subject id and the box's reset epoch. A Reset increments the
33
+ * epoch, so it derives a NEW key id, secret and home key (an old `sk-llm` is
34
+ * never re-minted); a takeover reads the epoch from the machine's name and so
35
+ * rebuilds the same ones.
36
+ */
37
+ const saltOf = (subjectId, epoch) => {
38
+ if (!Number.isInteger(epoch) || epoch < 0) {
39
+ throw new Error("Routebox reset epoch must be a non-negative integer");
40
+ }
41
+ return new TextEncoder().encode(`${subjectId}|e${epoch}`);
42
+ };
43
+ const derive = async (controlSeed, subjectId, epoch, info, length) => {
25
44
  if (controlSeed.length !== DEVICE_CONTROL_SEED_BYTES) {
26
45
  throw new Error("invalid device-control seed length");
27
46
  }
28
- const pairSecret = await deriveDevicePairSecret(controlSeed, keyId);
47
+ if (subjectId.length === 0)
48
+ throw new Error("Routebox key needs a subject id");
49
+ return hkdfSha256(controlSeed, saltOf(subjectId, epoch), info, length);
50
+ };
51
+ /** Derive the box's home key; the caller must zero the returned bytes. */
52
+ export const deriveRouteboxHomeKey = (controlSeed, subjectId, epoch) => derive(controlSeed, subjectId, epoch, ROUTEBOX_HOME_HKDF_INFO, 32);
53
+ /** The box's API key id, in the ordinary base64url key-id encoding. */
54
+ export const deriveRouteboxKeyId = async (controlSeed, subjectId, epoch) => {
55
+ const bytes = await derive(controlSeed, subjectId, epoch, ROUTEBOX_KEY_ID_HKDF_INFO, OPENLLM_API_KEY_ID_BYTES);
56
+ try {
57
+ return toB64Url(bytes);
58
+ }
59
+ finally {
60
+ zero(bytes);
61
+ }
62
+ };
63
+ /** The box's API key secret; the caller must zero the returned bytes. */
64
+ export const deriveRouteboxKeySecret = (controlSeed, subjectId, epoch) => derive(controlSeed, subjectId, epoch, ROUTEBOX_KEY_SECRET_HKDF_INFO, OPENLLM_API_KEY_SECRET_BYTES);
65
+ /**
66
+ * Mint the box's API key deterministically: a normal `api_keys` row whose id
67
+ * and `sk-llm` string are the same every time for this seed and machine (only
68
+ * the DEK-wrap nonces are random).
69
+ */
70
+ export const mintRouteboxApiKey = async (dek, vaultVersion, controlSeed, subjectId, epoch) => {
71
+ const id = await deriveRouteboxKeyId(controlSeed, subjectId, epoch);
72
+ const secret = await deriveRouteboxKeySecret(controlSeed, subjectId, epoch);
29
73
  try {
30
- return await hkdfSha256(pairSecret, new Uint8Array(0), ROUTEBOX_HOME_HKDF_INFO, 32);
74
+ return await mintApiKeyFrom(dek, vaultVersion, id, secret);
31
75
  }
32
76
  finally {
33
- zero(pairSecret);
77
+ zero(secret);
34
78
  }
35
79
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openllmsh/sdk",
3
- "version": "2.10.19-alpha.2",
3
+ "version": "2.10.19-alpha.5",
4
4
  "private": false,
5
5
  "description": "The OpenLLM SDK: typed API contracts, wire-format adapters, the device tunnel, client-side vault crypto, the OpenAPI spec and MCP tools.",
6
6
  "keywords": [