SDK/Reference

Sealed rooms

PREVIEW

Sealed-bid encoding, commitments, consent digests, Seal encryption and bid opening. Exported whole from loan-room.ts, room-open.ts and sealed.ts, plus three names from seal.ts.

Signatures below are copied from the source; descriptions are the source's own doc comments.

From loan-room.ts#

Exported by index.ts.

OFFER_PLAINTEXT_LEN#

TypeScript
export const OFFER_PLAINTEXT_LEN = 104;

OFFER_CT_LEN#

The v5 overhead was measured on a 36-byte identity; room ‖ "offers" is 38, and Seal carries the identity in the clear.

TypeScript
export const OFFER_CT_LEN = OFFER_PLAINTEXT_LEN + SEAL_OVERHEAD_T2 + 2;

SealedOpening#

TypeScript
export type SealedOpening = { rateBps: bigint; salt: Uint8Array; treasuryId: string; capId: string };

offerPlaintext#

TypeScript
export function offerPlaintext({ rateBps, salt, treasuryId, capId }: SealedOpening): Uint8Array

parseOfferPlaintext#

TypeScript
export function parseOfferPlaintext(bytes: Uint8Array): SealedOpening

offerCommitment#

loan_room::commitment_of: blake2b256(plaintext ‖ bcs(lender)).

TypeScript
export function offerCommitment(o: SealedOpening, lender: string): Uint8Array

consentDigest#

loan_room::consent_of: blake2b256(bcs(room) ‖ bcs(rate) ‖ salt).

TypeScript
export function consentDigest(roomId: string, rateBps: bigint, salt: Uint8Array): Uint8Array

consented#

take_consent's own test (treasury.move:416): the opening's cap holds the consent in the opening's treasury.

TypeScript
export async function consented(client: SuiGrpcClient, roomId: string, o: SealedOpening): Promise<boolean>

offersIdentity#

TypeScript
export function offersIdentity(roomId: string): string

OFFER_THRESHOLD#

TypeScript
export const OFFER_THRESHOLD = 2;

encryptOffer#

TypeScript
export async function encryptOffer(seal: SealClient, pkg: string, roomId: string, o: SealedOpening)

offerApproveTxBytes#

TypeScript
export function offerApproveTxBytes(client: SuiGrpcClient, pkg: string, loanCoin: string, roomId: string)

OpenFault#

TypeScript
export type OpenFault = "NO_ACCESS" | "BAD_SIGNATURE" | "KEY_SERVERS";

SealLike#

TypeScript
export type SealLike = Pick<SealClient, "fetchKeys" | "decrypt">;

Opened#

TypeScript
export type Opened =
  { ok: true; openings: (SealedOpening | null)[] } | { ok: false; fault: OpenFault; error: string };

openOffers#

One fetchKeys for the room's identity, then a local decrypt per ciphertext; null marks a ciphertext that does not open.

TypeScript
export async function openOffers(
  seal: SealLike,
  a: { roomId: string; session: SessionKey; txBytes: Uint8Array; ciphertexts: Uint8Array[] },
): Promise<Opened>

From room-open.ts#

Exported by index.ts.

RoomForOpening#

GET /v1/borrow/rooms/:id, as the browser receives it.

TypeScript
export type RoomForOpening = {
  nowMs: number;
  room: { id: string; closeMs: number; settleByMs: number; maxRateBps: number; amount: string };
  offers: { index: number; lender: string; commitment: string; ciphertext: string }[];
  seal: { pkg: string; loanCoin: string };
};

RankedOpening#

TypeScript
export type RankedOpening = {
  index: number;
  lender: string;
  rateBps: number;
  salt: string;
  treasuryId: string;
  capId: string;
};

OpenState#

TypeScript
export type OpenState =
  "NOT_CLOSED" | "SETTLE_WINDOW_CLOSED" | "NO_ACCESS" | "BAD_SIGNATURE" | "KEY_SERVERS_DOWN";

OpenResult#

TypeScript
export type OpenResult =
  | { ok: true; ranked: RankedOpening[]; unopened: number; attempts: number }
  | { ok: false; state: OpenState; error: string; attempts: number };

OpenDeps#

TypeScript
export type OpenDeps = {
  client: SuiGrpcClient;
  seal: SealLike;
  signer: Signer;
  now?: () => number;
  sleep?: (ms: number) => Promise<void>;
  maxAttempts?: number;
  baseDelayMs?: number;
  /** The seal_approve PTB the key servers dry-run; built against the fullnode unless given. */
  approve?: () => Promise<Uint8Array>;
  /** Whether the opening's lender consented on chain; reads the treasury's consents Table unless given. */
  consented?: (o: SealedOpening) => Promise<boolean>;
};

openRoomBids#

Runs where the borrower's key is: the browser with their passkey (one prompt signs the Seal session), or an agent process with its own key. Only openings matching an on-chain commitment and backed by their lender's on-chain consent come back, cheapest first.

TypeScript
export async function openRoomBids(deps: OpenDeps, r: RoomForOpening): Promise<OpenResult>

From sealed.ts#

Exported by index.ts.

RoomView#

TypeScript
export type RoomView = {
  id: string;
  amount: bigint;
  maxRateBps: number;
  termMs: number;
  closeMs: number;
  collateral: bigint;
};

Opening#

TypeScript
export type Opening = { rateBps: bigint; salt: Uint8Array; treasuryId: string; capId: string };

SealedOnChain#

TypeScript
export type SealedOnChain = { index: number; lender: string; commitment: string };

bidTerms#

Whether this lender's sealed bid can fill the room under its own mandate, as treasury::draw will check at settle.

TypeScript
export function bidTerms(
  p: LenderPolicy,
  room: RoomView,
  roomValue: bigint,
  outstanding: bigint,
  nowMs: number,
): { ok: true; rateBps: number; ltvBps: number } | { ok: false; reason: string }

rankOpenings#

Openings the borrower can prove against the room's commitments and its lender's on-chain consent (anyone can seal and commit to any plaintext), cheapest first, ties in placement order.

TypeScript
export function rankOpenings(
  onChain: SealedOnChain[],
  openings: Opening[],
  commit: (o: Opening, lender: string) => string,
  maxRateBps: number,
  consented: (o: Opening) => boolean,
): { index: number; opening: Opening }[]

From seal.ts#

Exported by index.ts.

TESTNET_KEY_SERVERS#

TypeScript
export const TESTNET_KEY_SERVERS = [
  "0x73d05d62c18d9374e3ea529e8e0ed6161da1a141a94d3f76ae3fe4e99356db75",
  "0xf5d14a81a982144ae441cd7d64b09027f116a468bd36e7eca494f750591623c8",
] as const;

SEAL_OVERHEAD_T2#

TypeScript
export const SEAL_OVERHEAD_T2 = 352;

sealClient#

Mysten's two testnet key servers, threshold 2 (loan-room.ts OFFER_THRESHOLD). Localnet has no key servers.

TypeScript
export function sealClient(client: SuiGrpcClient, extra: Pick<SealClientOptions, "fetch" | "timeout"> = {})