@relai-team/access-sdk 0.20.2 → 0.20.3
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.
- package/dist/index.cjs +60 -45
- package/dist/index.d.cts +29 -1
- package/dist/index.d.ts +29 -1
- package/dist/index.js +60 -46
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -755,6 +755,42 @@ init_errors();
|
|
|
755
755
|
// src/unlock.ts
|
|
756
756
|
init_errors();
|
|
757
757
|
|
|
758
|
+
// src/transport/notify.ts
|
|
759
|
+
var REJECT_REASONS = [
|
|
760
|
+
"B64",
|
|
761
|
+
"UNTAGGED",
|
|
762
|
+
"FORMAT",
|
|
763
|
+
"KEYVERSION",
|
|
764
|
+
"TAG",
|
|
765
|
+
"NONCE",
|
|
766
|
+
"LOCKED",
|
|
767
|
+
"ROTATE",
|
|
768
|
+
"NOTREADY"
|
|
769
|
+
];
|
|
770
|
+
function isRetryableRejectReason(reason) {
|
|
771
|
+
return reason === "NOTREADY";
|
|
772
|
+
}
|
|
773
|
+
function needsFreshNonce(reason) {
|
|
774
|
+
return reason === "NONCE";
|
|
775
|
+
}
|
|
776
|
+
function parseNotifyLine(line) {
|
|
777
|
+
const trimmed = line.trim();
|
|
778
|
+
if (trimmed.startsWith("NONCE ")) {
|
|
779
|
+
const nonce = trimmed.slice("NONCE ".length).trim();
|
|
780
|
+
return { kind: "nonce", nonceB64Url: nonce };
|
|
781
|
+
}
|
|
782
|
+
if (trimmed.startsWith("[AUTH] ACCEPT ")) {
|
|
783
|
+
return { kind: "accept", command: trimmed.slice("[AUTH] ACCEPT ".length).trim() };
|
|
784
|
+
}
|
|
785
|
+
if (trimmed.startsWith("[AUTH] REJECT ")) {
|
|
786
|
+
const rest = trimmed.slice("[AUTH] REJECT ".length).trim();
|
|
787
|
+
const [reason, ...verbParts] = rest.split(/\s+/);
|
|
788
|
+
const verbHint = verbParts.length > 0 ? verbParts.join(" ") : void 0;
|
|
789
|
+
return { kind: "reject", reason: reason ?? "", verbHint };
|
|
790
|
+
}
|
|
791
|
+
return { kind: "passthrough", raw: trimmed };
|
|
792
|
+
}
|
|
793
|
+
|
|
758
794
|
// src/parent-resolve.ts
|
|
759
795
|
var WRONG_PARENT = "TAG";
|
|
760
796
|
function isWrongParentReject(reason) {
|
|
@@ -811,6 +847,7 @@ function orderCandidates(input) {
|
|
|
811
847
|
var MAX_PARENT_ATTEMPTS = 6;
|
|
812
848
|
|
|
813
849
|
// src/unlock.ts
|
|
850
|
+
var MAX_NONCE_RETRIES = 1;
|
|
814
851
|
async function deliverOpen(deps, open, opts) {
|
|
815
852
|
const { transport } = opts;
|
|
816
853
|
const grant = open.grant;
|
|
@@ -826,20 +863,30 @@ async function deliverOpen(deps, open, opts) {
|
|
|
826
863
|
const session = await transport.connect(handle);
|
|
827
864
|
let keep = false;
|
|
828
865
|
try {
|
|
829
|
-
|
|
866
|
+
const authenticated = grant.algorithm === "relai-hmac-sha256-16-v1";
|
|
830
867
|
let keyVersion;
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
token =
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
868
|
+
let ack;
|
|
869
|
+
let staleNonces = 0;
|
|
870
|
+
for (; ; ) {
|
|
871
|
+
let token = grant.token;
|
|
872
|
+
if (authenticated) {
|
|
873
|
+
const nonce = await transport.requestNonce(session);
|
|
874
|
+
const minted = await deps.grants.mint(grant.grant_id, nonce);
|
|
875
|
+
token = minted.token;
|
|
876
|
+
keyVersion = minted.key_version;
|
|
877
|
+
}
|
|
878
|
+
if (!token) {
|
|
879
|
+
throw new exports.RelaiError(
|
|
880
|
+
`Grant ${grant.grant_id} has no token to deliver (algorithm ${grant.algorithm}).`
|
|
881
|
+
);
|
|
882
|
+
}
|
|
883
|
+
ack = await transport.sendCommand(session, token);
|
|
884
|
+
if (!ack.accepted && authenticated && needsFreshNonce(ack.rejectReason ?? "") && staleNonces < MAX_NONCE_RETRIES) {
|
|
885
|
+
staleNonces += 1;
|
|
886
|
+
continue;
|
|
887
|
+
}
|
|
888
|
+
break;
|
|
841
889
|
}
|
|
842
|
-
const ack = await transport.sendCommand(session, token);
|
|
843
890
|
if (!ack.accepted && isWrongParentReject(ack.rejectReason ?? "")) {
|
|
844
891
|
return null;
|
|
845
892
|
}
|
|
@@ -1273,39 +1320,6 @@ function serialMatches(advertised, granted) {
|
|
|
1273
1320
|
return advertised.toUpperCase() === granted.toUpperCase();
|
|
1274
1321
|
}
|
|
1275
1322
|
|
|
1276
|
-
// src/transport/notify.ts
|
|
1277
|
-
var REJECT_REASONS = [
|
|
1278
|
-
"B64",
|
|
1279
|
-
"UNTAGGED",
|
|
1280
|
-
"FORMAT",
|
|
1281
|
-
"KEYVERSION",
|
|
1282
|
-
"TAG",
|
|
1283
|
-
"NONCE",
|
|
1284
|
-
"LOCKED",
|
|
1285
|
-
"ROTATE",
|
|
1286
|
-
"NOTREADY"
|
|
1287
|
-
];
|
|
1288
|
-
function isRetryableRejectReason(reason) {
|
|
1289
|
-
return reason === "NOTREADY";
|
|
1290
|
-
}
|
|
1291
|
-
function parseNotifyLine(line) {
|
|
1292
|
-
const trimmed = line.trim();
|
|
1293
|
-
if (trimmed.startsWith("NONCE ")) {
|
|
1294
|
-
const nonce = trimmed.slice("NONCE ".length).trim();
|
|
1295
|
-
return { kind: "nonce", nonceB64Url: nonce };
|
|
1296
|
-
}
|
|
1297
|
-
if (trimmed.startsWith("[AUTH] ACCEPT ")) {
|
|
1298
|
-
return { kind: "accept", command: trimmed.slice("[AUTH] ACCEPT ".length).trim() };
|
|
1299
|
-
}
|
|
1300
|
-
if (trimmed.startsWith("[AUTH] REJECT ")) {
|
|
1301
|
-
const rest = trimmed.slice("[AUTH] REJECT ".length).trim();
|
|
1302
|
-
const [reason, ...verbParts] = rest.split(/\s+/);
|
|
1303
|
-
const verbHint = verbParts.length > 0 ? verbParts.join(" ") : void 0;
|
|
1304
|
-
return { kind: "reject", reason: reason ?? "", verbHint };
|
|
1305
|
-
}
|
|
1306
|
-
return { kind: "passthrough", raw: trimmed };
|
|
1307
|
-
}
|
|
1308
|
-
|
|
1309
1323
|
// src/transport/ble.ts
|
|
1310
1324
|
var RELAI_UART_SERVICE = "0000ff00-0000-1000-8000-00805f9b34fb";
|
|
1311
1325
|
var RELAI_RX_CHAR = "0000ff02-0000-1000-8000-00805f9b34fb";
|
|
@@ -1613,6 +1627,7 @@ exports.asPaymentRequired = asPaymentRequired;
|
|
|
1613
1627
|
exports.deliverOpen = deliverOpen;
|
|
1614
1628
|
exports.isRetryableRejectReason = isRetryableRejectReason;
|
|
1615
1629
|
exports.isStripePublishableKey = isStripePublishableKey;
|
|
1630
|
+
exports.needsFreshNonce = needsFreshNonce;
|
|
1616
1631
|
exports.parseAdvertisedSerial = parseAdvertisedSerial;
|
|
1617
1632
|
exports.parseNotifyLine = parseNotifyLine;
|
|
1618
1633
|
exports.presentRelaiPaymentSheet = presentRelaiPaymentSheet;
|
package/dist/index.d.cts
CHANGED
|
@@ -1531,6 +1531,34 @@ declare const REJECT_REASONS: readonly ["B64", "UNTAGGED", "FORMAT", "KEYVERSION
|
|
|
1531
1531
|
* caller" rather than to an infinite retry loop.
|
|
1532
1532
|
*/
|
|
1533
1533
|
declare function isRetryableRejectReason(reason: string): boolean;
|
|
1534
|
+
/**
|
|
1535
|
+
* Does this rejection mean "challenge again", rather than "stop"?
|
|
1536
|
+
*
|
|
1537
|
+
* ONLY `NONCE`, and the reason is in the firmware: a Parent holds ONE
|
|
1538
|
+
* outstanding challenge nonce (`CommandAuth.cpp`). Two phones at the same tower
|
|
1539
|
+
* seconds apart means the second `CHALLENGE` overwrites the first's nonce, and
|
|
1540
|
+
* the first phone's token is then refused as a replay it never attempted.
|
|
1541
|
+
* Nothing is wrong with the key, the grant or the radio: a fresh
|
|
1542
|
+
* challenge-mint-write round succeeds.
|
|
1543
|
+
*
|
|
1544
|
+
* DISTINCT FROM `isRetryableRejectReason`, which is about sending the SAME
|
|
1545
|
+
* bytes again after a pause (`NOTREADY`, where the Parent's key store had not
|
|
1546
|
+
* finished loading). This one needs NEW bytes, because the old token is bound
|
|
1547
|
+
* to a nonce the Parent has already discarded, so resending it can only fail
|
|
1548
|
+
* the same way.
|
|
1549
|
+
*
|
|
1550
|
+
* IT ALSO MEANS THE PARENT IS THE RIGHT ONE. The firmware verifies in a fixed
|
|
1551
|
+
* order (format, key version, tag, then nonce), so a command that reaches the
|
|
1552
|
+
* nonce check has already proved its tag against this Parent's key. A `NONCE`
|
|
1553
|
+
* rejection can only come from the Parent the grant names, which is why the
|
|
1554
|
+
* retry stays on the same session instead of resuming the search.
|
|
1555
|
+
*
|
|
1556
|
+
* SAFE TO RETRY, which is the question worth asking of any retry on a door.
|
|
1557
|
+
* `[AUTH] ACCEPT` is emitted at verify time, before the lock is touched, so a
|
|
1558
|
+
* `REJECT NONCE` means nothing moved and a second attempt cannot open a
|
|
1559
|
+
* compartment twice.
|
|
1560
|
+
*/
|
|
1561
|
+
declare function needsFreshNonce(reason: string): boolean;
|
|
1534
1562
|
/** Parse one already-decoded (plain-text) notify line. */
|
|
1535
1563
|
declare function parseNotifyLine(line: string): NotifyLine;
|
|
1536
1564
|
|
|
@@ -1738,4 +1766,4 @@ declare class RelaiTransportError extends RelaiError {
|
|
|
1738
1766
|
constructor(message: string);
|
|
1739
1767
|
}
|
|
1740
1768
|
|
|
1741
|
-
export { type AccessLinkTarget, AccessLinksModule, type AnyWebhookEvent, type ApiEnvironment, type ApiErrorBody, AppModule, type AppSelf, AuthModule, type BleDeviceLike, type BleManagerLike, BleTransport, type BleTransportOptions, type CommandAck, type DayWindow, type DeliverOptions, type DiscoveredParent, type EndUser, type EndUserPage, EndUsersModule, type ExchangeZone, type ExchangeZoneDetail, type ExchangeZonePage, ExchangeZonesModule, type GrantAlgorithm, GrantsModule, type HandoffMode, type Intent, Intents, type KeyValueStorage, type Me, MemoryTelemetryQueue, MemoryTokenStorage, type MintedCommand, type NotifyLine, type Open, type OperatingHours, type Order, type OrderPage, type OrderStatusFields, OrdersModule, type OverrideLink, OverrideLinksModule, type ParentTransport, type PaymentRequiredDetails, PushModule, type PushPlatform, type QueuedTelemetry, REJECT_REASONS, RELAI_RX_CHAR, RELAI_TX_CHAR, RELAI_UART_SERVICE, type RecipientMatch, RecipientsModule, RelaiApiError, RelaiClient, type RelaiClientOptions, RelaiConfigError, RelaiError, type RelaiErrorContext, RelaiLateFeeDue, RelaiMissingKeyError, RelaiNetworkError, RelaiTransportError, RelaiUnlockRejected, type SandboxFault, type SandboxFaultResult, SandboxModule, type SelfBillingChoice, type Session, SimAuthenticatedTransport, type SimAuthenticatedTransportOptions, type SimulatedParentConfig, SimulatedTransport, StorageTelemetryQueue, type StorageTelemetryQueueOptions, type StripeSdk, type TelemetryAction, type TelemetryEvent, TelemetryModule, type TelemetryPayload, type TelemetryQueue, TelemetryUploader, type TokenPair, type TokenStorage, type Tower, type TowerNode, type TowerTelemetry, type UnlockDeps, type UnlockGrant, type UnlockInput, type UnlockResult, type VerifyWebhookInput, type WebhookEvent, type WebhookEventOf, type WebhookEventType, type WebhookPayloads, asPaymentRequired, deliverOpen, isRetryableRejectReason, isStripePublishableKey, parseAdvertisedSerial, parseNotifyLine, presentRelaiPaymentSheet, serialMatches, verifyWebhook };
|
|
1769
|
+
export { type AccessLinkTarget, AccessLinksModule, type AnyWebhookEvent, type ApiEnvironment, type ApiErrorBody, AppModule, type AppSelf, AuthModule, type BleDeviceLike, type BleManagerLike, BleTransport, type BleTransportOptions, type CommandAck, type DayWindow, type DeliverOptions, type DiscoveredParent, type EndUser, type EndUserPage, EndUsersModule, type ExchangeZone, type ExchangeZoneDetail, type ExchangeZonePage, ExchangeZonesModule, type GrantAlgorithm, GrantsModule, type HandoffMode, type Intent, Intents, type KeyValueStorage, type Me, MemoryTelemetryQueue, MemoryTokenStorage, type MintedCommand, type NotifyLine, type Open, type OperatingHours, type Order, type OrderPage, type OrderStatusFields, OrdersModule, type OverrideLink, OverrideLinksModule, type ParentTransport, type PaymentRequiredDetails, PushModule, type PushPlatform, type QueuedTelemetry, REJECT_REASONS, RELAI_RX_CHAR, RELAI_TX_CHAR, RELAI_UART_SERVICE, type RecipientMatch, RecipientsModule, RelaiApiError, RelaiClient, type RelaiClientOptions, RelaiConfigError, RelaiError, type RelaiErrorContext, RelaiLateFeeDue, RelaiMissingKeyError, RelaiNetworkError, RelaiTransportError, RelaiUnlockRejected, type SandboxFault, type SandboxFaultResult, SandboxModule, type SelfBillingChoice, type Session, SimAuthenticatedTransport, type SimAuthenticatedTransportOptions, type SimulatedParentConfig, SimulatedTransport, StorageTelemetryQueue, type StorageTelemetryQueueOptions, type StripeSdk, type TelemetryAction, type TelemetryEvent, TelemetryModule, type TelemetryPayload, type TelemetryQueue, TelemetryUploader, type TokenPair, type TokenStorage, type Tower, type TowerNode, type TowerTelemetry, type UnlockDeps, type UnlockGrant, type UnlockInput, type UnlockResult, type VerifyWebhookInput, type WebhookEvent, type WebhookEventOf, type WebhookEventType, type WebhookPayloads, asPaymentRequired, deliverOpen, isRetryableRejectReason, isStripePublishableKey, needsFreshNonce, parseAdvertisedSerial, parseNotifyLine, presentRelaiPaymentSheet, serialMatches, verifyWebhook };
|
package/dist/index.d.ts
CHANGED
|
@@ -1531,6 +1531,34 @@ declare const REJECT_REASONS: readonly ["B64", "UNTAGGED", "FORMAT", "KEYVERSION
|
|
|
1531
1531
|
* caller" rather than to an infinite retry loop.
|
|
1532
1532
|
*/
|
|
1533
1533
|
declare function isRetryableRejectReason(reason: string): boolean;
|
|
1534
|
+
/**
|
|
1535
|
+
* Does this rejection mean "challenge again", rather than "stop"?
|
|
1536
|
+
*
|
|
1537
|
+
* ONLY `NONCE`, and the reason is in the firmware: a Parent holds ONE
|
|
1538
|
+
* outstanding challenge nonce (`CommandAuth.cpp`). Two phones at the same tower
|
|
1539
|
+
* seconds apart means the second `CHALLENGE` overwrites the first's nonce, and
|
|
1540
|
+
* the first phone's token is then refused as a replay it never attempted.
|
|
1541
|
+
* Nothing is wrong with the key, the grant or the radio: a fresh
|
|
1542
|
+
* challenge-mint-write round succeeds.
|
|
1543
|
+
*
|
|
1544
|
+
* DISTINCT FROM `isRetryableRejectReason`, which is about sending the SAME
|
|
1545
|
+
* bytes again after a pause (`NOTREADY`, where the Parent's key store had not
|
|
1546
|
+
* finished loading). This one needs NEW bytes, because the old token is bound
|
|
1547
|
+
* to a nonce the Parent has already discarded, so resending it can only fail
|
|
1548
|
+
* the same way.
|
|
1549
|
+
*
|
|
1550
|
+
* IT ALSO MEANS THE PARENT IS THE RIGHT ONE. The firmware verifies in a fixed
|
|
1551
|
+
* order (format, key version, tag, then nonce), so a command that reaches the
|
|
1552
|
+
* nonce check has already proved its tag against this Parent's key. A `NONCE`
|
|
1553
|
+
* rejection can only come from the Parent the grant names, which is why the
|
|
1554
|
+
* retry stays on the same session instead of resuming the search.
|
|
1555
|
+
*
|
|
1556
|
+
* SAFE TO RETRY, which is the question worth asking of any retry on a door.
|
|
1557
|
+
* `[AUTH] ACCEPT` is emitted at verify time, before the lock is touched, so a
|
|
1558
|
+
* `REJECT NONCE` means nothing moved and a second attempt cannot open a
|
|
1559
|
+
* compartment twice.
|
|
1560
|
+
*/
|
|
1561
|
+
declare function needsFreshNonce(reason: string): boolean;
|
|
1534
1562
|
/** Parse one already-decoded (plain-text) notify line. */
|
|
1535
1563
|
declare function parseNotifyLine(line: string): NotifyLine;
|
|
1536
1564
|
|
|
@@ -1738,4 +1766,4 @@ declare class RelaiTransportError extends RelaiError {
|
|
|
1738
1766
|
constructor(message: string);
|
|
1739
1767
|
}
|
|
1740
1768
|
|
|
1741
|
-
export { type AccessLinkTarget, AccessLinksModule, type AnyWebhookEvent, type ApiEnvironment, type ApiErrorBody, AppModule, type AppSelf, AuthModule, type BleDeviceLike, type BleManagerLike, BleTransport, type BleTransportOptions, type CommandAck, type DayWindow, type DeliverOptions, type DiscoveredParent, type EndUser, type EndUserPage, EndUsersModule, type ExchangeZone, type ExchangeZoneDetail, type ExchangeZonePage, ExchangeZonesModule, type GrantAlgorithm, GrantsModule, type HandoffMode, type Intent, Intents, type KeyValueStorage, type Me, MemoryTelemetryQueue, MemoryTokenStorage, type MintedCommand, type NotifyLine, type Open, type OperatingHours, type Order, type OrderPage, type OrderStatusFields, OrdersModule, type OverrideLink, OverrideLinksModule, type ParentTransport, type PaymentRequiredDetails, PushModule, type PushPlatform, type QueuedTelemetry, REJECT_REASONS, RELAI_RX_CHAR, RELAI_TX_CHAR, RELAI_UART_SERVICE, type RecipientMatch, RecipientsModule, RelaiApiError, RelaiClient, type RelaiClientOptions, RelaiConfigError, RelaiError, type RelaiErrorContext, RelaiLateFeeDue, RelaiMissingKeyError, RelaiNetworkError, RelaiTransportError, RelaiUnlockRejected, type SandboxFault, type SandboxFaultResult, SandboxModule, type SelfBillingChoice, type Session, SimAuthenticatedTransport, type SimAuthenticatedTransportOptions, type SimulatedParentConfig, SimulatedTransport, StorageTelemetryQueue, type StorageTelemetryQueueOptions, type StripeSdk, type TelemetryAction, type TelemetryEvent, TelemetryModule, type TelemetryPayload, type TelemetryQueue, TelemetryUploader, type TokenPair, type TokenStorage, type Tower, type TowerNode, type TowerTelemetry, type UnlockDeps, type UnlockGrant, type UnlockInput, type UnlockResult, type VerifyWebhookInput, type WebhookEvent, type WebhookEventOf, type WebhookEventType, type WebhookPayloads, asPaymentRequired, deliverOpen, isRetryableRejectReason, isStripePublishableKey, parseAdvertisedSerial, parseNotifyLine, presentRelaiPaymentSheet, serialMatches, verifyWebhook };
|
|
1769
|
+
export { type AccessLinkTarget, AccessLinksModule, type AnyWebhookEvent, type ApiEnvironment, type ApiErrorBody, AppModule, type AppSelf, AuthModule, type BleDeviceLike, type BleManagerLike, BleTransport, type BleTransportOptions, type CommandAck, type DayWindow, type DeliverOptions, type DiscoveredParent, type EndUser, type EndUserPage, EndUsersModule, type ExchangeZone, type ExchangeZoneDetail, type ExchangeZonePage, ExchangeZonesModule, type GrantAlgorithm, GrantsModule, type HandoffMode, type Intent, Intents, type KeyValueStorage, type Me, MemoryTelemetryQueue, MemoryTokenStorage, type MintedCommand, type NotifyLine, type Open, type OperatingHours, type Order, type OrderPage, type OrderStatusFields, OrdersModule, type OverrideLink, OverrideLinksModule, type ParentTransport, type PaymentRequiredDetails, PushModule, type PushPlatform, type QueuedTelemetry, REJECT_REASONS, RELAI_RX_CHAR, RELAI_TX_CHAR, RELAI_UART_SERVICE, type RecipientMatch, RecipientsModule, RelaiApiError, RelaiClient, type RelaiClientOptions, RelaiConfigError, RelaiError, type RelaiErrorContext, RelaiLateFeeDue, RelaiMissingKeyError, RelaiNetworkError, RelaiTransportError, RelaiUnlockRejected, type SandboxFault, type SandboxFaultResult, SandboxModule, type SelfBillingChoice, type Session, SimAuthenticatedTransport, type SimAuthenticatedTransportOptions, type SimulatedParentConfig, SimulatedTransport, StorageTelemetryQueue, type StorageTelemetryQueueOptions, type StripeSdk, type TelemetryAction, type TelemetryEvent, TelemetryModule, type TelemetryPayload, type TelemetryQueue, TelemetryUploader, type TokenPair, type TokenStorage, type Tower, type TowerNode, type TowerTelemetry, type UnlockDeps, type UnlockGrant, type UnlockInput, type UnlockResult, type VerifyWebhookInput, type WebhookEvent, type WebhookEventOf, type WebhookEventType, type WebhookPayloads, asPaymentRequired, deliverOpen, isRetryableRejectReason, isStripePublishableKey, needsFreshNonce, parseAdvertisedSerial, parseNotifyLine, presentRelaiPaymentSheet, serialMatches, verifyWebhook };
|
package/dist/index.js
CHANGED
|
@@ -592,6 +592,42 @@ var TelemetryUploader = class {
|
|
|
592
592
|
}
|
|
593
593
|
};
|
|
594
594
|
|
|
595
|
+
// src/transport/notify.ts
|
|
596
|
+
var REJECT_REASONS = [
|
|
597
|
+
"B64",
|
|
598
|
+
"UNTAGGED",
|
|
599
|
+
"FORMAT",
|
|
600
|
+
"KEYVERSION",
|
|
601
|
+
"TAG",
|
|
602
|
+
"NONCE",
|
|
603
|
+
"LOCKED",
|
|
604
|
+
"ROTATE",
|
|
605
|
+
"NOTREADY"
|
|
606
|
+
];
|
|
607
|
+
function isRetryableRejectReason(reason) {
|
|
608
|
+
return reason === "NOTREADY";
|
|
609
|
+
}
|
|
610
|
+
function needsFreshNonce(reason) {
|
|
611
|
+
return reason === "NONCE";
|
|
612
|
+
}
|
|
613
|
+
function parseNotifyLine(line) {
|
|
614
|
+
const trimmed = line.trim();
|
|
615
|
+
if (trimmed.startsWith("NONCE ")) {
|
|
616
|
+
const nonce = trimmed.slice("NONCE ".length).trim();
|
|
617
|
+
return { kind: "nonce", nonceB64Url: nonce };
|
|
618
|
+
}
|
|
619
|
+
if (trimmed.startsWith("[AUTH] ACCEPT ")) {
|
|
620
|
+
return { kind: "accept", command: trimmed.slice("[AUTH] ACCEPT ".length).trim() };
|
|
621
|
+
}
|
|
622
|
+
if (trimmed.startsWith("[AUTH] REJECT ")) {
|
|
623
|
+
const rest = trimmed.slice("[AUTH] REJECT ".length).trim();
|
|
624
|
+
const [reason, ...verbParts] = rest.split(/\s+/);
|
|
625
|
+
const verbHint = verbParts.length > 0 ? verbParts.join(" ") : void 0;
|
|
626
|
+
return { kind: "reject", reason: reason ?? "", verbHint };
|
|
627
|
+
}
|
|
628
|
+
return { kind: "passthrough", raw: trimmed };
|
|
629
|
+
}
|
|
630
|
+
|
|
595
631
|
// src/parent-resolve.ts
|
|
596
632
|
var WRONG_PARENT = "TAG";
|
|
597
633
|
function isWrongParentReject(reason) {
|
|
@@ -648,6 +684,7 @@ function orderCandidates(input) {
|
|
|
648
684
|
var MAX_PARENT_ATTEMPTS = 6;
|
|
649
685
|
|
|
650
686
|
// src/unlock.ts
|
|
687
|
+
var MAX_NONCE_RETRIES = 1;
|
|
651
688
|
async function deliverOpen(deps, open, opts) {
|
|
652
689
|
const { transport } = opts;
|
|
653
690
|
const grant = open.grant;
|
|
@@ -663,20 +700,30 @@ async function deliverOpen(deps, open, opts) {
|
|
|
663
700
|
const session = await transport.connect(handle);
|
|
664
701
|
let keep = false;
|
|
665
702
|
try {
|
|
666
|
-
|
|
703
|
+
const authenticated = grant.algorithm === "relai-hmac-sha256-16-v1";
|
|
667
704
|
let keyVersion;
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
token =
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
705
|
+
let ack;
|
|
706
|
+
let staleNonces = 0;
|
|
707
|
+
for (; ; ) {
|
|
708
|
+
let token = grant.token;
|
|
709
|
+
if (authenticated) {
|
|
710
|
+
const nonce = await transport.requestNonce(session);
|
|
711
|
+
const minted = await deps.grants.mint(grant.grant_id, nonce);
|
|
712
|
+
token = minted.token;
|
|
713
|
+
keyVersion = minted.key_version;
|
|
714
|
+
}
|
|
715
|
+
if (!token) {
|
|
716
|
+
throw new RelaiError(
|
|
717
|
+
`Grant ${grant.grant_id} has no token to deliver (algorithm ${grant.algorithm}).`
|
|
718
|
+
);
|
|
719
|
+
}
|
|
720
|
+
ack = await transport.sendCommand(session, token);
|
|
721
|
+
if (!ack.accepted && authenticated && needsFreshNonce(ack.rejectReason ?? "") && staleNonces < MAX_NONCE_RETRIES) {
|
|
722
|
+
staleNonces += 1;
|
|
723
|
+
continue;
|
|
724
|
+
}
|
|
725
|
+
break;
|
|
678
726
|
}
|
|
679
|
-
const ack = await transport.sendCommand(session, token);
|
|
680
727
|
if (!ack.accepted && isWrongParentReject(ack.rejectReason ?? "")) {
|
|
681
728
|
return null;
|
|
682
729
|
}
|
|
@@ -1103,39 +1150,6 @@ function serialMatches(advertised, granted) {
|
|
|
1103
1150
|
return advertised.toUpperCase() === granted.toUpperCase();
|
|
1104
1151
|
}
|
|
1105
1152
|
|
|
1106
|
-
// src/transport/notify.ts
|
|
1107
|
-
var REJECT_REASONS = [
|
|
1108
|
-
"B64",
|
|
1109
|
-
"UNTAGGED",
|
|
1110
|
-
"FORMAT",
|
|
1111
|
-
"KEYVERSION",
|
|
1112
|
-
"TAG",
|
|
1113
|
-
"NONCE",
|
|
1114
|
-
"LOCKED",
|
|
1115
|
-
"ROTATE",
|
|
1116
|
-
"NOTREADY"
|
|
1117
|
-
];
|
|
1118
|
-
function isRetryableRejectReason(reason) {
|
|
1119
|
-
return reason === "NOTREADY";
|
|
1120
|
-
}
|
|
1121
|
-
function parseNotifyLine(line) {
|
|
1122
|
-
const trimmed = line.trim();
|
|
1123
|
-
if (trimmed.startsWith("NONCE ")) {
|
|
1124
|
-
const nonce = trimmed.slice("NONCE ".length).trim();
|
|
1125
|
-
return { kind: "nonce", nonceB64Url: nonce };
|
|
1126
|
-
}
|
|
1127
|
-
if (trimmed.startsWith("[AUTH] ACCEPT ")) {
|
|
1128
|
-
return { kind: "accept", command: trimmed.slice("[AUTH] ACCEPT ".length).trim() };
|
|
1129
|
-
}
|
|
1130
|
-
if (trimmed.startsWith("[AUTH] REJECT ")) {
|
|
1131
|
-
const rest = trimmed.slice("[AUTH] REJECT ".length).trim();
|
|
1132
|
-
const [reason, ...verbParts] = rest.split(/\s+/);
|
|
1133
|
-
const verbHint = verbParts.length > 0 ? verbParts.join(" ") : void 0;
|
|
1134
|
-
return { kind: "reject", reason: reason ?? "", verbHint };
|
|
1135
|
-
}
|
|
1136
|
-
return { kind: "passthrough", raw: trimmed };
|
|
1137
|
-
}
|
|
1138
|
-
|
|
1139
1153
|
// src/transport/ble.ts
|
|
1140
1154
|
var RELAI_UART_SERVICE = "0000ff00-0000-1000-8000-00805f9b34fb";
|
|
1141
1155
|
var RELAI_RX_CHAR = "0000ff02-0000-1000-8000-00805f9b34fb";
|
|
@@ -1411,4 +1425,4 @@ var Intents = {
|
|
|
1411
1425
|
MakeAvailable: "make_available"
|
|
1412
1426
|
};
|
|
1413
1427
|
|
|
1414
|
-
export { AccessLinksModule, AppModule, AuthModule, BleTransport, EndUsersModule, ExchangeZonesModule, GrantsModule, Intents, MemoryTelemetryQueue, MemoryTokenStorage, OrdersModule, OverrideLinksModule, PushModule, REJECT_REASONS, RELAI_RX_CHAR, RELAI_TX_CHAR, RELAI_UART_SERVICE, RecipientsModule, RelaiClient, SandboxModule, SimAuthenticatedTransport, SimulatedTransport, StorageTelemetryQueue, TelemetryModule, TelemetryUploader, deliverOpen, isRetryableRejectReason, parseAdvertisedSerial, parseNotifyLine, serialMatches, verifyWebhook };
|
|
1428
|
+
export { AccessLinksModule, AppModule, AuthModule, BleTransport, EndUsersModule, ExchangeZonesModule, GrantsModule, Intents, MemoryTelemetryQueue, MemoryTokenStorage, OrdersModule, OverrideLinksModule, PushModule, REJECT_REASONS, RELAI_RX_CHAR, RELAI_TX_CHAR, RELAI_UART_SERVICE, RecipientsModule, RelaiClient, SandboxModule, SimAuthenticatedTransport, SimulatedTransport, StorageTelemetryQueue, TelemetryModule, TelemetryUploader, deliverOpen, isRetryableRejectReason, needsFreshNonce, parseAdvertisedSerial, parseNotifyLine, serialMatches, verifyWebhook };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@relai-team/access-sdk",
|
|
3
|
-
"version": "0.20.
|
|
3
|
+
"version": "0.20.3",
|
|
4
4
|
"description": "Official Relai Access SDK, open Relai Exchange Zone nodes over BLE, backed by the Relai Access platform (server-owns-trust).",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"type": "module",
|