Summary
Consume the new optional discovery_url field from PymtHouse SignerSession exchange responses and use it as the default orchestrator discovery endpoint when building gateway tokens or returning exchange envelopes — mirroring how signer_url is already handled today.
Blocked by / pairs with: pymthouse/pymthouse#190
Motivation
Integrators using @pymthouse/builder-sdk to exchange pmth_* API keys for signer sessions often also need a discovery URL for livepeer-gateway (--discovery / gateway token discovery field). Today callers must hardcode or pass discovery explicitly in buildGatewayToken({ discovery: "…" }).
Once PymtHouse returns a platform-default (and optionally app-scoped) discovery_url on exchange, the SDK should:
- Parse and forward it on exchange response types.
- Use it as a fallback when the caller did not supply
discovery to buildGatewayToken / mintGatewayToken.
Current behavior
deviceExchangeResponseFromSignerSessionBody reads signer_url, validates with assertDirectSignerBaseUrl, and attaches it to DeviceExchangeResponse (src/signer/device-exchange.ts).
signerUrlFromExchangeResponse helper in src/signer/direct-signer.ts.
buildGatewayToken only sets bundle.discovery when input.discovery is explicitly provided (src/signer/gateway-token.ts).
mintGatewayToken passes through options.discovery unchanged; no exchange-derived default.
Proposed changes
1. Exchange response types
Add optional discovery_url to:
DeviceExchangeResponse (src/signer/types.ts)
SignerSession-shaped types in src/types.ts if applicable
Parse in deviceExchangeResponseFromSignerSessionBody (and any parallel parsers in device-exchange.ts / api-key-exchange.ts), similar to signer_url.
Validate as absolute http(s) URL (new helper, e.g. assertDiscoveryUrl — no dashboard-proxy rejection needed unlike signer_url).
2. Helper
Add discoveryUrlFromExchangeResponse alongside signerUrlFromExchangeResponse in src/signer/direct-signer.ts (or a small shared module).
3. Gateway token defaulting
When assembling gateway tokens from an exchange:
discovery: options.discovery ?? discoveryUrlFromExchangeResponse(session)
Apply in mintGatewayToken (apiKey source path) and facade handlers in api-key-exchange.ts.
Precedence: explicit caller discovery > exchange discovery_url > omit (current behavior).
4. Docs + tests
- README — document exchange
discovery_url and defaulting behavior
- Tests mirroring
signer_url coverage in api-key-exchange, device-exchange, gateway-token, direct-signer tests
Acceptance criteria
References
Summary
Consume the new optional
discovery_urlfield from PymtHouseSignerSessionexchange responses and use it as the default orchestrator discovery endpoint when building gateway tokens or returning exchange envelopes — mirroring howsigner_urlis already handled today.Blocked by / pairs with: pymthouse/pymthouse#190
Motivation
Integrators using
@pymthouse/builder-sdkto exchangepmth_*API keys for signer sessions often also need a discovery URL forlivepeer-gateway(--discovery/ gateway tokendiscoveryfield). Today callers must hardcode or pass discovery explicitly inbuildGatewayToken({ discovery: "…" }).Once PymtHouse returns a platform-default (and optionally app-scoped)
discovery_urlon exchange, the SDK should:discoverytobuildGatewayToken/mintGatewayToken.Current behavior
deviceExchangeResponseFromSignerSessionBodyreadssigner_url, validates withassertDirectSignerBaseUrl, and attaches it toDeviceExchangeResponse(src/signer/device-exchange.ts).signerUrlFromExchangeResponsehelper insrc/signer/direct-signer.ts.buildGatewayTokenonly setsbundle.discoverywheninput.discoveryis explicitly provided (src/signer/gateway-token.ts).mintGatewayTokenpasses throughoptions.discoveryunchanged; no exchange-derived default.Proposed changes
1. Exchange response types
Add optional
discovery_urlto:DeviceExchangeResponse(src/signer/types.ts)SignerSession-shaped types insrc/types.tsif applicableParse in
deviceExchangeResponseFromSignerSessionBody(and any parallel parsers indevice-exchange.ts/api-key-exchange.ts), similar tosigner_url.Validate as absolute
http(s)URL (new helper, e.g.assertDiscoveryUrl— no dashboard-proxy rejection needed unlikesigner_url).2. Helper
Add
discoveryUrlFromExchangeResponsealongsidesignerUrlFromExchangeResponseinsrc/signer/direct-signer.ts(or a small shared module).3. Gateway token defaulting
When assembling gateway tokens from an exchange:
discovery: options.discovery ?? discoveryUrlFromExchangeResponse(session)Apply in
mintGatewayToken(apiKey source path) and facade handlers inapi-key-exchange.ts.Precedence: explicit caller
discovery> exchangediscovery_url> omit (current behavior).4. Docs + tests
discovery_urland defaulting behaviorsigner_urlcoverage in api-key-exchange, device-exchange, gateway-token, direct-signer testsAcceptance criteria
discovery_urlparsed from PymtHouse signer-session JSON intoDeviceExchangeResponsediscovery_urldoes not fail exchange (field remains optional)buildGatewayToken/mintGatewayTokendefaultdiscoveryfrom exchange when not explicitly provideddiscoveryoption still wins over exchange defaultReferences
signer_urlpattern:src/signer/direct-signer.ts,src/signer/device-exchange.tssrc/signer/gateway-token.ts(GatewayTokenBundle.discovery)