Raw HTTP private flows
These recipes use fetch or curl against the hosted API and the relayer, and @mysten/sui to sign. They do not import @esseyonsui/sui-sdk or @esseyonsui/sui-mcp. Proving uses snarkjs and the public packages @esseyonsui/proving-keys-testonly and @esseyonsui/settle-keys-testonly. Seal uses @mysten/seal. Poseidon uses poseidonHash from @mysten/sui/zklogin. Notes, salts, spend keys and nullSecret are created in this process and are never sent to the API. A body field named secret, nullSecret, spendKey, privateKey, encKey or seed is refused with 400.
API=https://sui-agent-prototype-production.up.railway.app
RELAYER=https://essey-relayer-production.up.railway.app
GRPC=https://fullnode.testnet.sui.io:443
GRAPHQL=https://graphql.testnet.sui.io/graphqlPublic fullnode JSON-RPC is deprecated (Method not found). Reads and simulations use gRPC. Event scans use GraphQL.
Is the id file. Fee floors: 10000000 on /relay/sui, 10000 on /relay/usdc and /relay/usdsui. Paths are relayer.paths on that config. There is no relayer kind repay_v2.
Sign an unsigned transaction#
Needs no session. The response is { ok, encoding: "sui-transaction-json", bytes, calls }. bytes is base64 of the transaction JSON. Shared-object versions are filled when you build against a fullnode. You pay gas.
import { Transaction } from "@mysten/sui/transactions";
import { SuiGrpcClient } from "@mysten/sui/grpc";
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
const keypair = Ed25519Keypair.fromSecretKey(process.env.SUI_SECRET_KEY!);
const client = new SuiGrpcClient({ network: "testnet", baseUrl: "https://fullnode.testnet.sui.io:443" });
const tx = Transaction.from(new TextDecoder().decode(Buffer.from(built.bytes, "base64")));
tx.setSender(keypair.toSuiAddress());
tx.setGasBudget(100_000_000);
const bytes = await tx.build({ client });
const { signature } = await keypair.signTransaction(bytes);
const landed = await client.executeTransaction({ transaction: bytes, signatures: [signature] });calls names the Move functions in the transaction, for example pool::deposit or room::settle. A relay response is { ok, encoding: "relay", url, body }. POST body to url as JSON. The relayer rebuilds the Move call. It refuses raw txBytes.
Omit paymentId or collateralId and the builder withdraws Balance<T> from the sender with 0x2::coin::redeem_funds. The withdrawal is a FundsWithdrawal; coin::from_balance does not accept it. A deposit splits amount + insertFee off that coin and coin::destroy_zero drops the empty coin left behind. Set the sender before build({ client }). That spends the address balance, which is where sui client faucet credits SUI, so a SUI deposit, SUI collateral on a USDC or tUSDsui loan, and a SUI address bid do not need a coin object. Pass the id only when the coins already sit in an object. A deposit still needs amount + insertFee. Read insert_fee with client.getObject({ objectId: poolId, include: { json: true } }); the field is insert_fee.
Local steps#
Install snarkjs@0.7.6, @noble/curves, @noble/hashes, @noble/ciphers, @mysten/sui, @mysten/seal, @mysten/bcs. Download keys (TEST-ONLY, single party):
https://cdn.jsdelivr.net/npm/@esseyonsui/proving-keys-testonly@0.1.0/membership/membership.wasm
https://cdn.jsdelivr.net/npm/@esseyonsui/proving-keys-testonly@0.1.0/membership/membership.zkey
https://cdn.jsdelivr.net/npm/@esseyonsui/proving-keys-testonly@0.1.0/spend/transaction2.wasm
https://cdn.jsdelivr.net/npm/@esseyonsui/proving-keys-testonly@0.1.0/spend/final.zkey
https://cdn.jsdelivr.net/npm/@esseyonsui/settle-keys-testonly@0.1.0/settle/settle.wasm
https://cdn.jsdelivr.net/npm/@esseyonsui/settle-keys-testonly@0.1.0/settle/settle.zkeyThe circuit file names are membership.wasm, transaction2.wasm and settle.wasm. The field modulus R is 21888242871839275222246405745257275088548364400416034343698204186575808495617. The proof-bytes modulus Q is 21888242871839275222246405745257275088696311157297823662689037894645226208583.
import { xchacha20poly1305 } from "@noble/ciphers/chacha.js";
import { secp256k1 } from "@noble/curves/secp256k1.js";
import { bytesToNumberBE, numberToBytesBE } from "@noble/curves/utils.js";
import { blake2b } from "@noble/hashes/blake2.js";
import { hkdf } from "@noble/hashes/hkdf.js";
import { sha256 } from "@noble/hashes/sha2.js";
import { keccak_256 } from "@noble/hashes/sha3.js";
import { concatBytes, randomBytes } from "@noble/hashes/utils.js";
import { poseidonHash } from "@mysten/sui/zklogin";
import { bcs } from "@mysten/sui/bcs";
import * as snarkjs from "snarkjs";
const R = 21888242871839275222246405745257275088548364400416034343698204186575808495617n;
const Q = 21888242871839275222246405745257275088696311157297823662689037894645226208583n;
const hash = poseidonHash;
const randomField = () => bytesToNumberBE(randomBytes(31));
export function deriveKeys(seed: Uint8Array) {
const domain = (tag: string, n: number) =>
blake2b(concatBytes(seed, new TextEncoder().encode(tag)), { dkLen: n });
const spendKey = bytesToNumberBE(domain("spend", 32)) % R;
const encKey = secp256k1.utils.randomSecretKey(domain("enc", secp256k1.lengths.seed!));
return {
spendKey,
pubkey: hash([spendKey]),
encKey,
encPub: secp256k1.getPublicKey(encKey, true),
claimKey: domain("claim", 32),
refundKey: domain("refund", 32),
};
}
export const commitmentOf = (amount: bigint, pubkey: bigint, blinding: bigint) =>
hash([amount, pubkey, blinding]);
export function encryptOpening(amount: bigint, blinding: bigint, encPub: Uint8Array) {
const ephemeral = secp256k1.utils.randomSecretKey();
const nonce = randomBytes(24);
const plain = concatBytes(numberToBytesBE(amount, 32), numberToBytesBE(blinding, 32));
const shared = secp256k1.getSharedSecret(ephemeral, encPub, true).slice(1);
const key = hkdf(sha256, shared, undefined, new TextEncoder().encode("sale-room-pool-note-v1"), 32);
return concatBytes(
secp256k1.getPublicKey(ephemeral, true),
nonce,
xchacha20poly1305(key, nonce).encrypt(plain),
);
}
export function decryptOpening(blob: Uint8Array, encKey: Uint8Array) {
try {
const nonce = blob.slice(33, 57);
const shared = secp256k1.getSharedSecret(encKey, blob.slice(0, 33), true).slice(1);
const key = hkdf(sha256, shared, undefined, new TextEncoder().encode("sale-room-pool-note-v1"), 32);
const plain = xchacha20poly1305(key, nonce).decrypt(blob.slice(57));
return { amount: bytesToNumberBE(plain.slice(0, 32)), blinding: bytesToNumberBE(plain.slice(32)) };
} catch {
return null;
}
}
const ZERO = BigInt(`0x${Buffer.from(keccak_256(new TextEncoder().encode("tornado"))).toString("hex")}`) % R;
export function merkle(commitments: { index: number; commitment: bigint }[], levels = 20) {
const zeros = [ZERO];
for (let l = 1; l <= levels; l++) zeros.push(hash([zeros[l - 1], zeros[l - 1]]));
const layers = [new Map(commitments.map((e) => [e.index, e.commitment]))];
for (let l = 0; l < levels; l++) {
const below = layers[l];
const at = (i: number) => below.get(i) ?? zeros[l];
const parents = new Set([...below.keys()].map((i) => i >> 1));
layers.push(new Map([...parents].map((p) => [p, hash([at(2 * p), at(2 * p + 1)])])));
}
const node = (l: number, i: number) => layers[l].get(i) ?? zeros[l];
return {
root: node(levels, 0),
path(index: number) {
return layers.slice(0, levels).map((_, l) => node(l, (index >> l) ^ 1));
},
};
}Scan refund notes with GraphQL, not JSON-RPC. POST https://graphql.testnet.sui.io/graphql:
query ($t: String!, $after: String) {
events(filter: { type: $t }, first: 50, after: $after) {
pageInfo {
hasNextPage
endCursor
}
nodes {
contents {
type {
repr
}
json
}
}
}
}$t is ${privacyPkg}::pool::NewCommitment, then ${privacyPkg}::pool::NewNullifier. BCS layout of the JSON is pool, commitment (u256), index (u64), encrypted_output, and for a nullifier pool plus nullifier. Decrypt a non-empty encrypted_output with decryptOpening. A change note's pubkey is hash([spendKey]). A refund note is not that leaf. Collect, expire and cancel insert the refund with room_absorb and an empty encrypted_output. The opening is the bid or offer's enc_out2, published on the spend's output leaf. refundSpendKey is bytesToNumberBE(blake2b(concat(utf8("sale-room-refund-key-v1"), u256be(blinding)), { key: refundKey, dkLen: 32 })) % R, and refundPubkey is hash([refundSpendKey]). Worked example: enc_out2 decrypts to amount 1000 and blinding 5. The refund commitment is Poseidon(1000, refundPubkey, 5). Find the later NewCommitment with that commitment and an empty encrypted_output. Spend that index. The leaf that carried enc_out2 is the spend output, not the refund. A spent note is one whose nullifier appears in NewNullifier. Nullifier of a note at leaf index with spend key k is hash([commitment, index, hash([k, commitment, index])]).
Membership. Draw two 31-byte field elements once and store them. Send the issuer only hash([secret, nullSecret]) as decimal commitment to POST $API/v1/private/credential (session) or POST $API/v1/agent/credential. The issuer never sees nullSecret.
function halves(id: string): [bigint, bigint] {
const hex = id.replace(/^0x/, "").padStart(64, "0");
return [BigInt(`0x${hex.slice(32)}`), BigInt(`0x${hex.slice(0, 32)}`)];
}
function le(x: bigint, n: number) {
const out = new Uint8Array(n);
for (let i = 0; i < n; i++) out[i] = Number((x >> BigInt(8 * i)) & 0xffn);
return out;
}
function g1([x, y]: string[]) {
const b = le(BigInt(x), 32);
if (BigInt(y) > Q - BigInt(y)) b[31] |= 0x80;
return b;
}
function g2([[x0, x1], [y0, y1]]: string[][]) {
const b = new Uint8Array([...le(BigInt(x0), 32), ...le(BigInt(x1), 32)]);
const [c0, c1] = [BigInt(y0), BigInt(y1)];
const [n0, n1] = [(Q - c0) % Q, (Q - c1) % Q];
if (c1 > n1 || (c1 === n1 && c0 > n0)) b[63] |= 0x80;
return b;
}
export function proofBytes(p: { pi_a: string[]; pi_b: string[][]; pi_c: string[] }) {
return new Uint8Array([...g1(p.pi_a), ...g2(p.pi_b), ...g1(p.pi_c)]);
}Membership groth16.fullProve input, every value a decimal string. domain is 1 when the pass is bound to the sender (pool::deposit, room::bid) and 2 when it is bound to a spend nullifier n0 (bid, bid_v2, loan_offer_v2, settle_relayed_v2). bind is the sender address, or n0 as 32-byte hex. tag is hash([nullSecret, roomLo, roomHi, nonce]). ctx is hash([domain, roomLo, roomHi, bindLo, bindHi]).
{
"tag": "1",
"ctx": "2",
"expiry": "1893456000000",
"epoch": "0",
"issuerAx": "3",
"issuerAy": "4",
"secret": "5",
"nullSecret": "6",
"roomLo": "7",
"roomHi": "8",
"domain": "1",
"bindLo": "9",
"bindHi": "10",
"sigR8x": "11",
"sigR8y": "12",
"sigS": "13",
"nonce": "0"
}The issuer credential supplies expiry, epoch, issuerAx, issuerAy, sigR8x, sigR8y, sigS. Pass proof on the API is 0x plus hex of proofBytes. tag is the decimal tag.
Spend circuit transaction2.wasm. Two inputs. A zero-amount input skips the Merkle check. Public signals are [root, publicAmount, extDataHash, n0, n1, c0, c1]. publicAmount and extDataHash are the formulas in Encodings, not free strings. The object below is only the key names; use spendCircuitInput in the module for a witness that verifies.
{
"root": "1",
"publicAmount": "21888242871839275222246405745257275088548364400416034343698204186575808495554",
"extDataHash": "7209644016733748867780436273506248026287657487222802159374523464102794627734",
"inputNullifier": ["4", "5"],
"inAmount": ["6", "0"],
"inPrivateKey": ["7", "8"],
"inBlinding": ["9", "10"],
"inPathIndices": ["0", "0"],
"inPathElements": [["0"], ["0"]],
"outputCommitment": ["11", "12"],
"outAmount": ["13", "0"],
"outPubkey": ["14", "15"],
"outBlinding": ["16", "17"]
}inPathElements is length 20 per input on the live pools (levels 20). A withdraw that spends the whole note uses two zero outputs (amount 0, pubkey 0, blinding 0) and pays no insert fee. Anything with change pays one insert fee, and a pool bid pays two (change and refund).
Settle(16), settle.wasm. Pad commits, values and salts to 16 with "0". rule is "1" for a sale (highest price wins) and "2" for a loan (lowest rate wins). room is the room id as a decimal field: the 32-byte id interpreted as an integer, reduced mod R only if you are matching field_of; the chain uses the id's integer mod R. n is the real count before padding.
{
"commits": ["1", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"],
"n": "1",
"lo": "0",
"hi": "1000",
"rule": "1",
"hasWinner": "1",
"winner": "0",
"winValue": "1000",
"room": "2",
"values": ["1000", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"],
"salts": ["3", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"]
}proof on a settle body is 128 bytes from proofBytes. Losing values stay in values and salts on this machine. Only winner, winValue and the proof are posted.
Seal a v1 address bid. Identity is the room id's 32 bytes then the ASCII bytes of bids (hex of the address with no 0x, then hex of bids). data is BCS u64 of the price. aad is the bidder address bytes. threshold 2. packageId is packages.saleRoom. Key servers are seal.saleKeyServers. The third server's aggregator is https://seal-aggregator-testnet.mystenlabs.com. Use DemType.Hmac256Ctr from @mysten/seal.
import { DemType, SealClient, SessionKey } from "@mysten/seal";
const { encryptedObject } = await seal.encrypt({
threshold: 2,
packageId: salePkg,
id: roomId.replace(/^0x/, "") + Buffer.from("bids").toString("hex"),
data: bcs.u64().serialize(price).toBytes(),
aad: Buffer.from(bidder.replace(/^0x/, ""), "hex"),
demType: DemType.Hmac256Ctr,
});A wallet-room offer identity is the room id's bytes then ASCII offers. Plaintext is BCS { rate_bps: u64, salt: 32 bytes, treasury_id: address, cap_id: address } and is 104 bytes. The ciphertext length the room was opened with is that plus the threshold-2 Seal overhead. essey_wallet_loan_open uses the same length the chain expects. Opening bids is seal_approve (loan_room::seal_approve for a wallet room, room::seal_approve for a v1 sale) dry-run as onlyTransactionKind, then SessionKey.create and fetchKeys / decrypt. Finish shares are seal.getDerivedKeys on the bid identity, two of the three servers.
Encodings#
Every number below was computed from the inputs named in the same paragraph. R is 21888242871839275222246405745257275088548364400416034343698204186575808495617. Poseidon is poseidonHash from @mysten/sui/zklogin (circomlib BN254, the same function sui::poseidon::poseidon_bn254 uses). ZERO_NOTE, Poseidon(0, 0, 0), is 5317387130258456662214331362918410991734007599705406860481038345552731150762.
publicAmount is pool.move's negate. A total of 0 stays 0. Any other total t is (R - (t mod R)) mod R, which is how a withdrawal is a negative field element. Worked example: amount 53 and fee 10, both outputs ZERO_NOTE, insert fee 0, so t = 63 and publicAmount = 21888242871839275222246405745257275088548364400416034343698204186575808495554 (R - 63). pairs is 0 only when both outputs are ZERO_NOTE, and 1 otherwise. Two real outputs are still pairs 1. pool::room_spend requires pairs == 1 and aborts EBidExitForm (14) when both outputs are ZERO_NOTE, so a bid or offer cannot be a full exit. A valid bid or offer pays two insert fees: t = maxPrice + fee + 2 * insertFee, which is (pairs + 1) * insertFee at pairs 1. With max 100, fee 10 and insert fee 7, t = 124 and publicAmount = 21888242871839275222246405745257275088548364400416034343698204186575808495493 (R - 124). Insert fee 0 makes the same total as a pairs-0 spend, t = 110 and publicAmount = 21888242871839275222246405745257275088548364400416034343698204186575808495507, and the chain still rejects the pairs-0 bid. That bid's extDataHash is 2659964546278599045575256356103521763085008727196645260634573817239871701333. Recompute it from these inputs: room 0x2222222222222222222222222222222222222222222222222222222222222222, relayer 0x3333333333333333333333333333333333333333333333333333333333333333, fee 10, refund pubkey 17, refund blinding 19, encOut1 0x01, encOut2 0x02, and sealed_hash = blake2b-256 of the salePayloadV2 worked example below (commit 7, claim address 0x11…11, claim key thirty-two 0x09 bytes, n0 = 5, sealed 0x030405). The extDataHash example's output commitments are ZERO_NOTE; use it for the hash, not as a bid to submit.
extDataHash is keccak256 of the BCS ExtData enum, read as a big-endian integer, then mod R. Variant 0 is Withdraw { recipient, amount, relayer, fee, enc_out1, enc_out2 }. Variant 1 is Bid { room, sealed_hash, relayer, fee, refund_pubkey, refund_blinding, enc_out1, enc_out2 }. sealed_hash is blake2b-256 of the ciphertext for a v1 bid, and of the payload below (not the ciphertext) for bid_v2 and loan_offer_v2. The same withdraw (recipient 0x11…11, relayer 0x33…33, encOut1 0x01, encOut2 empty) encodes as
0x001111111111111111111111111111111111111111111111111111111111111111350000000000000033333333333333333333333333333333333333333333333333333333333333330a00000000000000010100and extDataHash = 7209644016733748867780436273506248026287657487222802159374523464102794627734.
A note commitment is Poseidon(amount, pubkey, blinding). A nullifier is Poseidon(commitment, index, Poseidon(spendKey, commitment, index)), and pubkey is Poseidon(spendKey). The note ciphertext is ephemeralCompressedPub (33) || nonce (24) || XChaCha20-Poly1305(hkdf-sha256(x-coordinate of the shared secret), info utf8 "sale-room-pool-note-v1") of u256be(amount) || u256be(blinding). Scan NewCommitment and decrypt with the static encKey from the seed. A refund note's spend key is blake2b-256(key = refundKey, utf8("sale-room-refund-key-v1") || u256be(blinding)) mod R, and its pubkey is Poseidon of that key. Keys from one 32-byte seed: spendKey = blake2b-256(seed || utf8("spend")) mod R, encKey an secp256k1 secret from blake2b-256(seed || utf8("enc")), claimKey = blake2b-256(seed || utf8("claim")), refundKey = blake2b-256(seed || utf8("refund")).
claimCommit for a v2 winner is blake2b-256 of the 32-byte claim address followed by a 32-byte salt. The salt is blake2b-256 with key claimKey of utf8("sale-room-claim-salt-v1") || u256be(n0). Worked example: claimKey thirty-two 0x09 bytes, n0 = 5, claim address 0x11…11. Salt 0x514942b383089cb3e9fb80fed05ae80a012cf16135bc5cf85d42111690fa02c0. Commitment 0x7c4202f8875ce924ef92385ed81939107c19054670b9a306652e5509efaac660.
salePayloadV2 is the byte string the v2 spend proof binds (the blake2b input above is this payload, not the Seal ciphertext):
utf8("essey.sale_room.v2/bid") || bcs(u256 commit) || bcs(vector<u8> claimCommit) || bcs(vector<u8> sealed)Worked example: commit 7, the claim commitment above, sealed bytes 0x030405. Payload
0x65737365792e73616c655f726f6f6d2e76322f6269640700000000000000000000000000000000000000000000000000000000000000207c4202f8875ce924ef92385ed81939107c19054670b9a306652e5509efaac66003030405loan_offer_v2 binds the same way with utf8("essey.private_loan.v2/offer") || bcs(u256 commit) || bcs(u256 repayPubkey) || bcs(u256 repayBlinding) || bcs(vector<u8> sealed).
A v2 sealed opening is 40 bytes: bcs(u64 value) || bcs(u256 salt). Its commitment is Poseidon(value, salt). Worked example: value 1000, salt 5, plaintext 0xe8030000000000000500000000000000000000000000000000000000000000000000000000000000, commitment 5333190578403422383263446341891171521604439722452288110175786231604645350573.
The Seal identity is room id bytes (32) || utf8("bid") or utf8("offer") || bcs(u64 seq). Pass that hex, with no 0x, as id to seal.encrypt. Package id is saleRoomV2.pkg or privateLoanV2.pkg. Threshold 2. DemType.Hmac256Ctr. The three keyServers from that section, in order. AAD for a pool entry is bcs(u256 n0). Worked example: room 0x22…22, seq 7. Bid identity 0x22222222222222222222222222222222222222222222222222222222222222226269640700000000000000. Offer identity 0x22222222222222222222222222222222222222222222222222222222222222226f666665720700000000000000.
After the room's close, the seller (a sale) or the borrower (a loan) opens the entries. Build onlyTransactionKind bytes of one seal_approve per seq and give them to Seal:
import { DemType, SealClient, SessionKey } from "@mysten/seal";
import { Transaction } from "@mysten/sui/transactions";
import { SuiGrpcClient } from "@mysten/sui/grpc";
import { normalizeSuiAddress, toHex } from "@mysten/sui/utils";
const client = new SuiGrpcClient({ network: "testnet", baseUrl: "https://fullnode.testnet.sui.io:443" });
const priv = (await (await fetch(API + "/v1/private/config")).json()).private;
const servers = priv.saleRoomV2.keyServers as string[];
const COMMITTEE = "0xb012378c9f3799fb5b1a7083da74a4069e3c3f1c93de0b27212a5799ce1e1e98";
const serverConfigs = servers.map((id) =>
normalizeSuiAddress(id) === COMMITTEE
? { objectId: id, weight: 1, aggregatorUrl: "https://seal-aggregator-testnet.mystenlabs.com" }
: { objectId: id, weight: 1 },
);
const threshold = priv.saleRoomV2.threshold as number;
const sessionKey = await SessionKey.create({
address: keypair.toSuiAddress(),
packageId: pkg,
ttlMin: 10,
signer: keypair,
suiClient: client,
});
const tx = new Transaction();
tx.moveCall({
target: `${pkg}::room::seal_approve`,
typeArguments: kind === "bid" ? [itemType, coinType] : [collateralType, loanType],
arguments: [
tx.pure.vector("u8", Array.from(entryKeyId(roomId, kind, seq))),
tx.object(roomId),
tx.object("0x6"),
],
});
const txBytes = await tx.build({ client, onlyTransactionKind: true });
const seal = new SealClient({ suiClient: client, serverConfigs, verifyKeyServers: false });
await seal.fetchKeys({ ids: [toHex(entryKeyId(roomId, kind, seq))], txBytes, sessionKey, threshold });
const plain = await seal.decrypt({ data: ciphertext, sessionKey, txBytes });serverConfigs is one entry per id in saleRoomV2.keyServers (the same three as seal.saleKeyServers), each weight: 1. The committee server 0xb012…1e98 also needs aggregatorUrl. threshold is saleRoomV2.threshold (2). A wallet-room offer uses seal.loanKeyServers instead, the first two, still weight 1 and threshold 2.
seal_approve takes the identity bytes, the room, and 0x6 (Clock). The sale's type arguments are the item type and the coin type. The loan's are the collateral type and the loan type. Only the seller, after close, can open bids. Only the borrower, after close, can open offers.
Settle(16) reads the room with client.getObject({ objectId, include: { json: true } }). A v2 sale's json fields are min_price (lo), max_price (hi), and bids[].commit in vector order (commits). n is bids.length before you pad commits, values, and salts to 16 with 0. rule is 1 (highest price). A v2 loan's fields are offers[].commit, lo is 0, hi is max_rate_bps, and rule is 2 (lowest rate). hasWinner is 1 when you are proving a winner. winner is the index in that vector. winValue is the winning price or rate. Read bids or offers before finish or settle. The room clears those vectors afterwards, and the commits are no longer on the object.
room is not the address string and not the membership halves. It is BigInt(normalizeSuiAddress(roomId)) % R (fieldOfId). Worked example, room 0x22…22: one sale bid commit 7, min_price 1, max_price 100, so n = 1, lo = 1, hi = 100, rule = 1, room = 15438945231642159389809464667825054380435997955418741871927677867721750618658. The same room as a loan with one offer commit 9 and max_rate_bps 800 is n = 1, lo = 0, hi = 800, rule = 2, and the same room.
settleActionV2 is what a relayed borrower pass binds as n0 (domain 2). Compute it before proving the pass. It does not need a server round-trip:
args = bcs(u64 winner) || bcs(u64 rateBps) || bcs(u256 principalPubkey) || bcs(u256 principalBlinding) || bcs(vector encNote) || bcs(vector proof)
preimage = utf8("essey.private_loan.v2/settle/") || room id bytes || bcs(u64 nonce) || args
action = int_be(blake2b-256(preimage)) mod RWorked example: room 0x22…22, nonce 4, winner 1, rate 900, pubkey 11, blinding 13, encNote 0x010203, proof 128 bytes of 0x07. action = 7052235562413244789951315181561993613525160744539715246743871119279889558980.
A v1 shielded bid seals 40 bytes: bcs(u64 price) || claimCommit. The Seal id is the room's bid key, room id bytes || utf8("bids"), not the nullifier. The AAD is bcs(u256 n0), the spend's first nullifier, and that is what ties the ciphertext to this bid. The claim salt never leaves this process: claimSalt(claimKey, n0) from the module, then claimCommit(claimTo, salt). The winner passes that same salt to sale-v1-claim or essey_sale_claim_v1. Worked example, price 1000 and the claim commitment above: plaintext 0xe8030000000000007c4202f8875ce924ef92385ed81939107c19054670b9a306652e5509efaac660 (40 bytes). Room 0x22…22 bid key 0x222222222222222222222222222222222222222222222222222222222222222262696473. AAD for n0 = 5 is 0x0500000000000000000000000000000000000000000000000000000000000000.
The module below is the whole encoding. Copy it. It imports only @mysten/sui and @noble/hashes.
// essey-http-local
// Byte layouts for a raw HTTP client. Imports: @mysten/sui, @noble/*, nothing from Essey.
import { bcs } from "@mysten/sui/bcs";
import { fromHex, normalizeSuiAddress, toHex } from "@mysten/sui/utils";
import { poseidonHash } from "@mysten/sui/zklogin";
import { blake2b } from "@noble/hashes/blake2.js";
import { keccak_256 } from "@noble/hashes/sha3.js";
export const R = 21888242871839275222246405745257275088548364400416034343698204186575808495617n;
export const hash = poseidonHash;
const utf8 = (s) => new TextEncoder().encode(s);
const cat = (...parts) => {
const out = new Uint8Array(parts.reduce((s, p) => s + p.length, 0));
let o = 0;
for (const p of parts) (out.set(p, o), (o += p.length));
return out;
};
const u64le = (n) => bcs.u64().serialize(n).toBytes();
const u256le = (n) => bcs.u256().serialize(n).toBytes();
const bytesBcs = (b) => bcs.byteVector().serialize(b).toBytes();
const addrBytes = (id) => fromHex(normalizeSuiAddress(id));
const beInt = (bytes) => BigInt(`0x${toHex(bytes)}`);
/** pool.move ExtData. Withdraw is variant 0, Bid is variant 1. sealed_hash is blake2b-256 of the sealed bytes
* for a v1 bid, and of the payload (not the ciphertext) for a v2 bid or offer. */
const ExtData = bcs.enum("ExtData", {
Withdraw: bcs.struct("Withdraw", {
recipient: bcs.Address,
amount: bcs.u64(),
relayer: bcs.Address,
fee: bcs.u64(),
enc_out1: bcs.byteVector(),
enc_out2: bcs.byteVector(),
}),
Bid: bcs.struct("Bid", {
room: bcs.Address,
sealed_hash: bcs.byteVector(),
relayer: bcs.Address,
fee: bcs.u64(),
refund_pubkey: bcs.u256(),
refund_blinding: bcs.u256(),
enc_out1: bcs.byteVector(),
enc_out2: bcs.byteVector(),
}),
});
export function withdrawExtBytes(ext) {
return ExtData.serialize({
Withdraw: {
recipient: ext.recipient,
amount: ext.amount,
relayer: ext.relayer,
fee: ext.fee,
enc_out1: ext.encOut1,
enc_out2: ext.encOut2,
},
}).toBytes();
}
export function bidExtBytes(ext, sealedOrPayload) {
return ExtData.serialize({
Bid: {
room: ext.room,
sealed_hash: blake2b(sealedOrPayload, { dkLen: 32 }),
relayer: ext.relayer,
fee: ext.fee,
refund_pubkey: ext.refundPubkey,
refund_blinding: ext.refundBlinding,
enc_out1: ext.encOut1,
enc_out2: ext.encOut2,
},
}).toBytes();
}
/** keccak256 of the BCS ExtData, as a big-endian integer, reduced mod R. */
export const extDataHash = (bytes) => beInt(keccak_256(bytes)) % R;
/** pool.move negate: zero stays 0. Any other total is R - (total mod R), the field form of a negative public amount. */
export const publicAmount = (total) => (R - (total % R)) % R;
export const ZERO_NOTE = hash([0n, 0n, 0n]);
export const pairsOf = (c0, c1) => (c0 === ZERO_NOTE && c1 === ZERO_NOTE ? 0n : 1n);
/** A withdraw's public amount: negate(amount + fee + pairs * insertFee). A full exit has pairs 0. */
export function withdrawPublicAmount(ext, c0, c1, insertFee) {
return publicAmount(ext.amount + ext.fee + pairsOf(c0, c1) * insertFee);
}
/** A bid or offer must have pairs 1. room_spend aborts 14 (EBidExitForm) when both outputs are ZERO_NOTE. It pays the refund pair too: negate(max + fee + (pairs + 1) * insertFee), two insert fees when pairs is 1. */
export function bidPublicAmount(maxOrPrincipal, fee, c0, c1, insertFee) {
return publicAmount(maxOrPrincipal + fee + (pairsOf(c0, c1) + 1n) * insertFee);
}
/** blake2b-256(claimTo address bytes || salt). salt is 32 bytes. */
export function claimCommit(claimTo, salt) {
return blake2b(cat(addrBytes(claimTo), salt), { dkLen: 32 });
}
/** salt = blake2b-256(key=claimKey, utf8("sale-room-claim-salt-v1") || u256be(n0)). */
export function claimSalt(claimKey, n0) {
const tag = utf8("sale-room-claim-salt-v1");
const n = u256be(n0);
return blake2b(cat(tag, n), { key: claimKey, dkLen: 32 });
}
function u256be(n) {
const out = new Uint8Array(32);
let x = n;
for (let i = 31; i >= 0; i--) {
out[i] = Number(x & 0xffn);
x >>= 8n;
}
return out;
}
/** essey.sale_room.v2/bid || bcs(u256 commit) || bcs(vector claimCommit) || bcs(vector sealed). */
export function salePayloadV2(commit, claimCommitBytes, sealed) {
return cat(utf8("essey.sale_room.v2/bid"), u256le(commit), bytesBcs(claimCommitBytes), bytesBcs(sealed));
}
/** essey.private_loan.v2/offer || bcs(commit) || bcs(repayPubkey) || bcs(repayBlinding) || bcs(vector sealed). */
export function loanPayloadV2(commit, repayPubkey, repayBlinding, sealed) {
return cat(
utf8("essey.private_loan.v2/offer"),
u256le(commit),
u256le(repayPubkey),
u256le(repayBlinding),
bytesBcs(sealed),
);
}
/** blake2b-256(utf8("essey.private_loan.v2/settle/") || room id bytes || bcs(u64 nonce) || args) as an integer mod R.
* args = bcs(u64 winner) || bcs(u64 rateBps) || bcs(u256 pubkey) || bcs(u256 blinding) || bcs(vector encNote) || bcs(vector proof). */
export function settleActionV2(roomId, nonce, a) {
const args = cat(
u64le(a.winner),
u64le(a.rateBps),
u256le(a.principalPubkey),
u256le(a.principalBlinding),
bytesBcs(a.encNote),
bytesBcs(a.proof),
);
const pre = cat(utf8("essey.private_loan.v2/settle/"), addrBytes(roomId), u64le(nonce), args);
return beInt(blake2b(pre, { dkLen: 32 })) % R;
}
/** room id bytes || utf8("bid"|"offer") || bcs(u64 seq). Seal's id is this hex with no 0x. */
export function entryKeyId(roomId, kind, seq) {
return cat(addrBytes(roomId), utf8(kind), u64le(seq));
}
/** 40 bytes: bcs(u64 value) || bcs(u256 salt). Commitment is Poseidon(value, salt). */
export function plaintextV2(value, salt) {
return cat(u64le(value), u256le(salt));
}
export const commitV2 = (value, salt) => hash([value, salt]);
/** AAD on a pool entry: bcs(u256 n0). */
export const poolAadV2 = (n0) => u256le(n0);
export function nullifierOf(note, index, spendKey) {
const commitment = hash([note.amount, note.pubkey, note.blinding]);
const signature = hash([spendKey, commitment, BigInt(index)]);
return hash([commitment, BigInt(index), signature]);
}
/** A zero-amount witness. Merkle checks are off when the amount is 0, so the path is twenty zeros. */
export function zeroSpendInput() {
const k0 = 1n;
const k1 = 2n;
const notes = [
{ amount: 0n, pubkey: hash([k0]), blinding: 3n, key: k0 },
{ amount: 0n, pubkey: hash([k1]), blinding: 4n, key: k1 },
];
const zeros = Array(20).fill("0");
const n0 = nullifierOf(notes[0], 0, k0);
const n1 = nullifierOf(notes[1], 0, k1);
const c0 = ZERO_NOTE;
const c1 = ZERO_NOTE;
return { notes, n0, n1, c0, c1, zeros };
}
/** v1 shielded bid plaintext: bcs(u64 price) || claimCommit. 40 bytes. */
export function shieldedBidPlaintext(price, claimCommitBytes) {
return cat(u64le(price), claimCommitBytes);
}
/** Seal id for every v1 bid, address or pool: room id bytes || utf8("bids"). Hex, no 0x. */
export function v1BidKeyId(roomId) {
return cat(addrBytes(roomId), utf8("bids"));
}
/** AAD on a v1 pool bid: bcs(u256 n0), the spend's first nullifier. An address bid's AAD is the bidder address. */
export const v1PoolBidAad = (n0) => u256le(n0);
/** Room id as the Settle(16) `room` input: the 32-byte address as an integer, reduced mod R. Not the membership halves. */
export function fieldOfId(roomId) {
return BigInt(normalizeSuiAddress(roomId)) % R;
}
/** v2 sale finish. `commits` are `bids[].commit` in order. `n` is that length, before padding to 16. */
export function saleSettlePublic(room) {
return {
commits: room.commits,
n: BigInt(room.commits.length),
lo: room.minPrice,
hi: room.maxPrice,
rule: 1n,
room: fieldOfId(room.id),
};
}
/** v2 loan settle. `commits` are `offers[].commit` in order. `lo` is 0. `hi` is `max_rate_bps`. Rule 2 is lowest wins. */
export function loanSettlePublic(room) {
return {
commits: room.commits,
n: BigInt(room.commits.length),
lo: 0n,
hi: room.maxRateBps,
rule: 2n,
room: fieldOfId(room.id),
};
}
export function spendCircuitInput(pub, ins) {
return {
root: "0",
publicAmount: pub.publicAmount.toString(),
extDataHash: pub.extDataHash.toString(),
inputNullifier: [ins.n0.toString(), ins.n1.toString()],
inAmount: ["0", "0"],
inPrivateKey: [ins.notes[0].key.toString(), ins.notes[1].key.toString()],
inBlinding: [ins.notes[0].blinding.toString(), ins.notes[1].blinding.toString()],
inPathIndices: ["0", "0"],
inPathElements: [ins.zeros, ins.zeros],
outputCommitment: [ins.c0.toString(), ins.c1.toString()],
outAmount: ["0", "0"],
outPubkey: ["0", "0"],
outBlinding: ["0", "0"],
};
}Recipes#
Each chain step is POST $API/v1/private/tx/<action>. Replace the ids with yours. coin is USDC, USDSUI or SUI.
Shielded pool#
Deposit, one coin at a time. Local: deriveKeys, blinding = randomField(), enc = encryptOpening(amount, blinding, encPub), membership proof bound to the sender (domain 1) for the pool id.
pool-deposit
{
"coin": "USDC",
"amount": "1000000",
"insertFee": "10000",
"paymentId": "0xCOIN",
"holder": "0xYOU",
"pubkey": "PUBKEY_DECIMAL",
"blinding": "BLINDING_DECIMAL",
"encNote": "0xCIPHERTEXT",
"pass": { "tag": "TAG", "expiryMs": "1893456000000", "proof": "0xPROOF128" },
"nonce": "1"
}Repeat with "coin": "USDSUI" and "coin": "SUI". The call list includes pool::deposit. insertFee is the pool's insert_fee. USDC and tUSDsui are 10000. SUI is 100000000 (0.1 SUI). A copied 1 does not match the pool, and the deposit aborts. The USDC and tUSDsui minimum is 10000. The SUI minimum is 1000000. Read insert_fee off the pool object when you are not sure.
Borrower exit and lender or bidder withdraw are both relayer kind: "withdraw". The notes must exceed the relayer fee: ext.amount is what the recipient receives, and 0 is refused ZERO_WITHDRAW by POST /v1/private/tx/pool-exit, pool-withdraw, and the relayer. An exit spends notes that sum exactly to amount + fee and uses two zero outputs, so encOut1 and encOut2 are 0x. A partial withdraw keeps a change note and sets encOut1 to that opening. Build the spend proof locally. The API stamps the relayer address and checks the fee floor.
pool-exit and pool-withdraw
{
"coin": "USDC",
"proof": {
"pi_a": ["1", "2", "1"],
"pi_b": [
["1", "2"],
["3", "4"],
["1", "0"]
],
"pi_c": ["1", "2", "1"]
},
"publicSignals": ["1", "2", "3", "4", "5", "6", "7"],
"ext": { "recipient": "0xYOU", "amount": "1000000", "fee": "10000", "encOut1": "0x", "encOut2": "0x" }
}POST the returned body to the returned url.
v2 sale#
sale-v2-open mints a demo badge and opens the room. shieldedOnly defaults to true. closeMs must be in the future and at most 30 days ahead (2592000000 ms). Further out aborts EBadParams (10). finishWindowMs is at least 1800000. sale-v2-open maxBids is 1 to 16. 17 or more aborts EBadParams (10), because the Settle(16) proof has 16 slots. sale-v1-open uses the same closeMs and finishWindowMs bounds, and its maxBids is 1 to 50. 2000000000000 is past the 30-day cap.
const body = {
coin: "USDC",
minPrice: "1",
maxPrice: "1000000",
closeMs: String(Date.now() + 3_600_000),
finishWindowMs: "1800000",
maxBids: "4",
};sale-v2-attest after a sender-bound membership proof for the new room id. sale-v2-bid is the relay body: the spend proof, ext (room, fee, refund pubkey and blinding, both ciphertexts), sealed, commit, claimCommit (32 bytes), member bound to the spend's n0. Repeat the open and the bid for USDSUI and SUI.
The seller finishes. The winner claims: the item and the change go only to the claimTo sealed in that bid. A loser collects: collect re-enters that bid's deposit as its refund note. The chain accepts claim and collect from any sender; the prize still goes only to claimTo.
sale-v2-cancel while the room has no bids: { "coin", "roomId", "itemType", "seller" }. sale-v2-finish after close, with the Settle(16) proof you computed locally: { "coin", "roomId", "itemType", "hasWinner": true, "winner": "0", "price": "1000000", "proof": "0xPROOF128" }. sale-v2-collect is { "coin", "roomId", "itemType" }. sale-v2-claim is { "coin", "roomId", "itemType", "claimTo", "salt" } and salt is 32 bytes. sale-v2-expire after the finish window is { "coin", "roomId", "itemType" }. Expire returns deposits and does not open losing prices.
v2 loan#
loan-v2-open. Forward USDC and forward tUSDsui take SUI collateral. Inverse SUI ("coin": "SUI") takes tUSDsui collateral. Omit collateralId to draw that collateral from the sender's address balance. Size it from POST /v1/borrow/quote with {collateral, amount} before opening. That route needs a session: without one it answers 401 NO_SESSION. Sign in, then send Authorization: Bearer <token>. market.ltvBps is the cap, and LTV_TOO_HIGH means the room will abort EOverLtv (14). These sizes cleared that check: principal 100000 (0.1 USDC), collateral 400000000 (0.4 SUI), maxRateBps 5000, termMs 3600000. The contract minimum for offerWindowMs is 60000, and the maximum is 7 days (604800000 ms). 600000 is recommended. One SUI against 1 USDC is over the limit at the current oracle.
{
"coin": "USDC",
"collateral": "400000000",
"principal": "100000",
"maxRateBps": "5000",
"termMs": "3600000",
"offerWindowMs": "600000"
}loan-v2-attest is a sender-bound pass for the room. loan-v2-offer is the relay body loan_offer_v2: the same spend fields as a bid, plus commit, repayPubkey, repayBlinding, member bound to n0. Do this for USDC, tUSDsui and SUI.
The borrower settles (loan-v2-settle, or the relayer with the borrower's pass on loan-v2-settle-relayed). After repay, default or liquidation the lender recovers the note (recoverRoomNote or essey_shielded_recover). A repay note is the loan coin. A default or liquidation note is the seized collateral, in that coin's pool (SUI, when the loan coin was USDC).
loan-v2-settle is the borrower signing room::settle with the 128-byte proof. loan-v2-settle-relayed returns kind: "settle_relayed_v2". The API hashes settleActionV2 from the public fields. Your pass was proved with domain 2 and n0 equal to that action. Losing rates are not in the body.
{
"coin": "USDC",
"roomId": "0xROOM",
"nonce": "0",
"winner": "0",
"rateBps": "500",
"principalPubkey": "2",
"principalBlinding": "3",
"encNote": "0xNOTE",
"proof": "0xPROOF128",
"pass": { "tag": "7", "expiryMs": "1893456000000", "proof": "0xPASS128" }
}loan-v2-cancel is { "coin", "roomId" }. loan-v2-repay is a public coin, not a relayer kind: { "coin", "roomId", "paymentId", "lenderEnc" }. lenderEnc is stored as the repay note's encrypted_output. The lender's encPub is not on the room, and any non-empty bytes are accepted. The lender does not decrypt those bytes. After settle the room's lender_pubkey and lender_blinding are the winning offer's repay opening, and PrivateLoanRepaid carries the amount and lender_note. Recover with those public fields (recoverRoomNote or essey_shielded_recover). An empty lenderEnc is refused. The same public opening makes the winning lender's repay note linkable to the settled room. Losing offers stay sealed. loan-v2-claim-default after maturity plus graceMs (300000) is { "coin", "roomId", "lenderEnc" }. The call is room::claim_default.
v1 sale#
Finish publishes every bid price. Prefer the v2 sale when the losing prices must stay sealed. The order is required: sale-v1-open, then sale-v1-attest, then a bid. Every bid aborts 23 until room::attest_seller lands. The package is packages.saleRoom from GET /v1/private/config, the same id GET /v1/config does not replace. MCP: essey_sale_open_v1, essey_sale_attest_v1, essey_sale_bid_address_v1 or essey_sale_bid_v1, then essey_sale_finish_v1 or essey_sale_expire_v1, then essey_sale_collect_v1, and the shielded winner essey_sale_claim_v1.
sale-v1-open is the same JSON shape as sale-v2-open, with maxBids 1 to 50 instead of 1 to 16. sale-v1-attest is { "coin", "roomId", "itemType", "pass" } with a sender-bound pass for the room id. sale-v1-bid is an address bid. You Seal the price to the bid key (v1BidKeyId) with the bidder address as AAD, and pass the ciphertext. seller must not be holder. paymentId is a coin of at least maxPrice.
{
"coin": "USDC",
"roomId": "0xROOM",
"seller": "0xSELLER",
"holder": "0xYOU",
"maxPrice": "1000000",
"paymentId": "0xCOIN",
"itemType": "0xSALE::demo::Badge",
"sealed": "0xSEALED",
"pass": { "tag": "7", "expiryMs": "1893456000000", "proof": "0xPASS128" }
}sale-v1-pool-bid is relay kind: "bid" for USDC, tUSDsui or SUI, after attest. Seal shieldedBidPlaintext(price, claimCommit) under v1BidKeyId(room) with AAD v1PoolBidAad(n0). Keep the claim salt. The body is the spend fields of sale-v2-bid without claimCommit. sale-v1-finish takes the two Seal derived keys you fetched locally:
{
"coin": "USDC",
"roomId": "0xROOM",
"itemType": "0xSALE::demo::Badge",
"indices": [0, 1],
"derived": ["0xSHARE0", "0xSHARE1"]
}sale-v1-expire is { "coin", "roomId", "itemType" }. sale-v1-collect is the same shape, after finish or expire, and repeats until the pending credit is gone. sale-v1-claim is { "coin", "roomId", "itemType", "claimTo", "salt" } where salt is the 32-byte claim salt kept from the winning shielded bid. sale-v2-claim refuses an itemType from the v1 sale package.
Upkeep dry-run#
Needs no session and signs nothing. Read each loan and room with client.getObject({ objectId, include: { json: true } }) and post the public fields. loanIds limits the report to those ids; every id must also be in loans. repayLeadMs defaults to 3600000. graceMs defaults to 300000. repayByMs, when set and already past, plans a repay of every open loan, including a pool loan whose maturityMs is 0.
curl -s -X POST $API/v1/upkeep/dry-run \
-H 'content-type: application/json' \
-d '{"address":"0xYOU","nowMs":1800000000000,"loans":[{"id":"0xLOAN","state":"open","maturityMs":1800000060000,"owed":"100","lenderId":"0xLENDER"}],"rooms":[{"id":"0xROOM","state":"open","closeMs":1799990000000,"settleByMs":1799999000000,"offerCount":0}]}'{
"ok": true,
"dryRun": true,
"signed": false,
"address": "0xYOU",
"nowMs": 1800000000000,
"repayLeadMs": 3600000,
"graceMs": 300000,
"actions": [
{ "job": "repay", "outcome": "planned", "loanId": "0xLOAN", "text": "repay 100 before it is due" },
{
"job": "warning",
"outcome": "warning",
"loanId": "0xLOAN",
"code": "REPAY_DUE",
"text": "loan 0xLOAN is inside the repay lead"
},
{
"job": "room-refund",
"outcome": "planned",
"roomId": "0xROOM",
"text": "the settle window has passed: refund returns the collateral"
},
{
"job": "warning",
"outcome": "warning",
"roomId": "0xROOM",
"code": "ROOM_REFUNDABLE",
"text": "the time to pick a bid has passed"
}
]
}job is repay, claim-surplus (states liquidated, written-off, defaulted), collect-default (the address is lenderId and nowMs is past maturity plus grace), room-refund, or warning. Warning codes are REPAY_DUE, CLAIM_SURPLUS, DEFAULT_DUE, ROOM_REFUNDABLE, and SETTLE_WINDOW_CLOSING. A missing address or a loan id that is not in loans is 400 with { "ok": false, "error" }. The body never contains transaction bytes.
Relayer#
Post JSON to https://essey-relayer-production.up.railway.app plus relayer.paths from GET /v1/private/config: /relay/sui, /relay/usdc, /relay/usdsui. Content-Type: application/json. Fee floors are 10000000 on /relay/sui and 10000 on the other two. Omit kind only for a classic bid. There is no repay_v2. kind=repay is the v1 shielded repay. A v2 loan repay is the public loan-v2-repay transaction above, not a relayer kind.
A success is:
{ "ok": true, "digest": "BASE58_DIGEST" }A refusal before execute is submitted: false. An error after execute is submitted: true: the spend may have landed, so do not rebuild it until you have read the chain.
{ "ok": false, "error": "fee below MIN_FEE", "submitted": false }{ "ok": false, "error": "dry run failed: MoveAbort 11", "submitted": false }{ "ok": false, "error": "timeout waiting for effects", "submitted": true }{
"ok": false,
"error": "kind: expected bid, withdraw, loan_offer, settle_relayed, repay, bid_v2, loan_offer_v2, or settle_relayed_v2 (omit kind only for a bid)",
"submitted": false
}{
"ok": false,
"error": "raw txBytes are not executed; post kind=settle_relayed or kind=repay with the checked fields (bid, withdraw, and loan_offer are unchanged)",
"submitted": false
}{
"ok": false,
"error": "kind=repay_coin spends a public loan coin this relayer does not hold. Post kind=repay with a shielded spend of the room's owed",
"submitted": false
}{
"ok": false,
"error": "kind=repay_relayed is not a contract function; private_room repay is the relayed repayment (anyone, proof-bound to the room's owed). Post kind=repay",
"submitted": false
}{
"ok": false,
"error": "kind=settle is the borrower's own sender path (private_room settle). This relayer submits kind=settle_relayed only",
"submitted": false
}{ "ok": false, "error": "ext.relayer is not this relayer", "submitted": false }Returns { "ok": true, "kinds": ["bid", "withdraw", "loan_offer", "settle_relayed", "repay", "bid_v2", "loan_offer_v2", "settle_relayed_v2"] }.
bid (sale_room::room::pool_bid). member is required. gate is null while Access is PUBLIC.
{
"kind": "bid",
"proof": {
"pi_a": ["1", "2", "1"],
"pi_b": [
["3", "4"],
["5", "6"],
["1", "0"]
],
"pi_c": ["7", "8", "1"],
"protocol": "groth16",
"curve": "bn128"
},
"publicSignals": ["11", "22", "33", "12", "13", "14", "15"],
"ext": {
"room": "0x2222222222222222222222222222222222222222222222222222222222222222",
"relayer": "0x1111111111111111111111111111111111111111111111111111111111111111",
"fee": "10000000",
"refundPubkey": "17",
"refundBlinding": "19",
"encOut1": "0x01",
"encOut2": "0x02"
},
"sealed": "0x03",
"member": {
"tag": "7",
"expiryMs": "1893456000000",
"proof": "0xabababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababab"
},
"gate": null
}withdraw (pool::withdraw). A full exit uses two zero outputs, so encOut1 and encOut2 are 0x.
{
"kind": "withdraw",
"proof": {
"pi_a": ["1", "2", "1"],
"pi_b": [
["3", "4"],
["5", "6"],
["1", "0"]
],
"pi_c": ["7", "8", "1"],
"protocol": "groth16",
"curve": "bn128"
},
"publicSignals": ["11", "22", "33", "12", "13", "14", "15"],
"ext": {
"recipient": "0x3333333333333333333333333333333333333333333333333333333333333333",
"amount": "1000000",
"relayer": "0x1111111111111111111111111111111111111111111111111111111111111111",
"fee": "10000",
"encOut1": "0x01",
"encOut2": "0x02"
}
}loan_offer (private_room::room::offer). v1 settle publishes every losing rate. Open loan_offer_v2 for a new loan.
{
"kind": "loan_offer",
"proof": {
"pi_a": ["1", "2", "1"],
"pi_b": [
["3", "4"],
["5", "6"],
["1", "0"]
],
"pi_c": ["7", "8", "1"],
"protocol": "groth16",
"curve": "bn128"
},
"publicSignals": ["11", "22", "33", "12", "13", "14", "15"],
"ext": {
"room": "0x2222222222222222222222222222222222222222222222222222222222222222",
"relayer": "0x1111111111111111111111111111111111111111111111111111111111111111",
"fee": "10000",
"refundPubkey": "17",
"refundBlinding": "19",
"encOut1": "0x01",
"encOut2": "0x02"
},
"sealed": "0x03",
"commit": "0x1111111111111111111111111111111111111111111111111111111111111111",
"repayPubkey": "31",
"repayBlinding": "37",
"member": { "tag": "7", "expiryMs": "1893456000000", "proof": "0xab" },
"gate": null
}settle_relayed (private_room::room::settle_relayed). rates and salts are every opening. That is why a new loan uses settle_relayed_v2.
{
"kind": "settle_relayed",
"sender": "0x1111111111111111111111111111111111111111111111111111111111111111",
"room": "0x2222222222222222222222222222222222222222222222222222222222222222",
"nonce": "0",
"action": "3",
"pass": {
"tag": "7",
"expiryMs": "1893456000000",
"proof": "0xabababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababab"
},
"rates": ["900"],
"salts": ["0x11111111111111111111111111111111"],
"principalPubkey": "11",
"principalBlinding": "13",
"encNote": "0x010203"
}repay (private_room::room::repay). Do not send refundPubkey or refundBlinding.
{
"kind": "repay",
"proof": {
"pi_a": ["1", "2", "1"],
"pi_b": [
["3", "4"],
["5", "6"],
["1", "0"]
],
"pi_c": ["7", "8", "1"],
"protocol": "groth16",
"curve": "bn128"
},
"publicSignals": ["11", "22", "33", "12", "13", "14", "15"],
"ext": {
"room": "0x2222222222222222222222222222222222222222222222222222222222222222",
"relayer": "0x1111111111111111111111111111111111111111111111111111111111111111",
"fee": "10000",
"encOut1": "0x01",
"encOut2": "0x02"
},
"lenderEnc": "0x03"
}bid_v2 (sale_room_v2::room::pool_bid). commit is the decimal field Poseidon(price, salt). claimCommit is 32 bytes.
{
"kind": "bid_v2",
"proof": {
"pi_a": ["1", "2", "1"],
"pi_b": [
["3", "4"],
["5", "6"],
["1", "0"]
],
"pi_c": ["7", "8", "1"],
"protocol": "groth16",
"curve": "bn128"
},
"publicSignals": ["11", "22", "33", "12", "13", "14", "15"],
"ext": {
"room": "0x2222222222222222222222222222222222222222222222222222222222222222",
"relayer": "0x1111111111111111111111111111111111111111111111111111111111111111",
"fee": "10000000",
"refundPubkey": "17",
"refundBlinding": "19",
"encOut1": "0x01",
"encOut2": "0x02"
},
"sealed": "0x03",
"commit": "23",
"claimCommit": "0x2929292929292929292929292929292929292929292929292929292929292929",
"member": { "tag": "7", "expiryMs": "1893456000000", "proof": "0xab" },
"gate": null
}loan_offer_v2 (private_room_v2::room::offer). commit is Poseidon(rateBps, salt).
{
"kind": "loan_offer_v2",
"proof": {
"pi_a": ["1", "2", "1"],
"pi_b": [
["3", "4"],
["5", "6"],
["1", "0"]
],
"pi_c": ["7", "8", "1"],
"protocol": "groth16",
"curve": "bn128"
},
"publicSignals": ["11", "22", "33", "12", "13", "14", "15"],
"ext": {
"room": "0x2222222222222222222222222222222222222222222222222222222222222222",
"relayer": "0x1111111111111111111111111111111111111111111111111111111111111111",
"fee": "10000",
"refundPubkey": "17",
"refundBlinding": "19",
"encOut1": "0x01",
"encOut2": "0x02"
},
"sealed": "0x03",
"commit": "23",
"repayPubkey": "31",
"repayBlinding": "37",
"member": { "tag": "7", "expiryMs": "1893456000000", "proof": "0xab" },
"gate": null
}settle_relayed_v2 (private_room_v2::room::settle_relayed). Only the winner and the winning rate. The pass is bound to action.
{
"kind": "settle_relayed_v2",
"room": "0x2222222222222222222222222222222222222222222222222222222222222222",
"nonce": "0",
"action": "3",
"pass": {
"tag": "7",
"expiryMs": "1893456000000",
"proof": "0xabababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababab"
},
"winner": "0",
"rateBps": "900",
"principalPubkey": "11",
"principalBlinding": "13",
"encNote": "0x010203",
"proof": "0xabababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababab"
}