Expand description
I4 (#1970): the typed TypeScript client for a context’s foreign callers,
workers/<context>/bynk-client.ts (design/archive/retired-tracks.md, interop track D3).
A Bynk caller of another context gets a typed call: the compiler builds the
path, stamps the contract hash, encodes the arguments and decodes the
result. This module gives a Worker that is not Bynk the same, as a module it
imports: one typed function per on call service a declared foreign caller
may call, the boundary types as TypeScript types, and the contract hashes
and wire version embedded as literals.
§One codec, one caller
Nothing here is a second implementation of the boundary. The codecs are the
ones a Bynk consumer generates for a callee’s types
(serialisation::emit_helpers_for_owner_qualified under a non-empty
qualifier, which inlines a transparent refinement and casts an opaque
one), each call goes through the runtime’s own callService, and the
encode and decode references at each call site come from the same
serialisation::serialise_expr_via / serialisation::deserialise_ref_via
the Bynk call site uses (emit.rs’s cross-context call lowering). The
runtime half ships as @bynk/wire-client, bundled from the runtime’s own
modules and versioned with the wire format (§11 Q7).
§Signing as a foreign caller
I3’s hand-off gives the foreign Worker its secret under the name a Bynk
caller holds its edge key by, BYNK_CALL_TO_<CALLEE>, and the callee’s
verifier checks a declared foreign caller’s name against its own secret
(__FOREIGN_CALLERS). So callService with the actor’s name as the caller
signs exactly the request the callee admits. The client asks for the
foreign Worker’s env (typed to require the secret) and its Service Binding.
§When it is emitted
Only for a context that declares at least one Foreign actor some on call
handler admits, and only with the services such an actor may call. A
context with no foreign caller has no one the client could sign as: an
undeclared caller holds no secret (§8 D2, §11 Q5).
Constants§
- CLIENT_
FILE - The file, beside the Worker’s
bynk-contracts.json. Hyphenated like the other compiler-written files there, so no Bynk unit can emit a module of the same name. - CLIENT_
PACKAGE - The runtime package the client imports (§11 Q7).
Functions§
- foreign_
contracts - The contract hash each declared foreign caller may call each service at:
actor → service → hash. What a foreign caller’s generated client embeds,
so what
bynk deploycompares a pin against. Empty when the context admits no foreign caller.