|
| 1 | +# Sub Rosa Core v2 integration |
| 2 | + |
| 3 | +Load this reference when implementing the SDK flow. Keep secrets server-side |
| 4 | +unless a browser wallet owns the signing step. |
| 5 | + |
| 6 | +## Current testnet deployment |
| 7 | + |
| 8 | +```text |
| 9 | +RPC: https://soroban-testnet.stellar.org |
| 10 | +Network passphrase: Test SDF Network ; September 2015 |
| 11 | +Core v2 contract: CCOVGOQQZJKZ2R55GRWBLTJTGBAMSHXZVN3ICPG3WRVMLMM6RHISC5OV |
| 12 | +WASM SHA-256: 2c7bc6b4c91940ac185df38a3d0a8532b555140d818df94f03f894e5952ebf42 |
| 13 | +Drand: quicknet / bls-unchained-g1-rfc9380 |
| 14 | +``` |
| 15 | + |
| 16 | +Treat these as one deployment tuple. Reconfirm them against the project's |
| 17 | +current documentation before a new pilot. |
| 18 | + |
| 19 | +## Configure a client |
| 20 | + |
| 21 | +```ts |
| 22 | +import { SubRosaClient } from "@sub-rosa/sdk"; |
| 23 | + |
| 24 | +const client = new SubRosaClient({ |
| 25 | + rpcUrl: "https://soroban-testnet.stellar.org", |
| 26 | + networkPassphrase: "Test SDF Network ; September 2015", |
| 27 | + contractId: process.env.SUB_ROSA_CONTRACT_ID!, |
| 28 | + secretKey: process.env.STELLAR_SECRET, |
| 29 | +}); |
| 30 | +``` |
| 31 | + |
| 32 | +Omit `secretKey` for read-only clients. Browser applications may provide the |
| 33 | +generated `RoundContract` with wallet-backed `signTransaction` and |
| 34 | +`signAuthEntry` callbacks instead of exposing a secret. |
| 35 | + |
| 36 | +## Create an asset auction |
| 37 | + |
| 38 | +```ts |
| 39 | +import { |
| 40 | + createAssetAuctionRound, |
| 41 | + generateAuditorKeypair, |
| 42 | + quicknet, |
| 43 | + roundInSeconds, |
| 44 | + sealAssetBid, |
| 45 | +} from "@sub-rosa/sdk"; |
| 46 | + |
| 47 | +const drand = quicknet(); |
| 48 | +const chain = await drand.chain().info(); |
| 49 | +const revealRound = await roundInSeconds(drand, 300); |
| 50 | +const revealAt = Number(chain.genesis_time) + Number(chain.period) * revealRound; |
| 51 | +const auditor = generateAuditorKeypair(); |
| 52 | + |
| 53 | +const roundId = await createAssetAuctionRound(sellerClient, { |
| 54 | + itemRef, // 32-byte stable item reference |
| 55 | + paymentAsset: usdcSac, |
| 56 | + lotAsset: collectibleSac, |
| 57 | + lotAmount: 1n, |
| 58 | + fixedEscrow: 1_000_000_000n, |
| 59 | + revealRound, |
| 60 | + commitDeadline: revealAt - 15, |
| 61 | + revealDeadline: revealAt + 300, |
| 62 | + auditorPubkey: auditor.publicKey, |
| 63 | + maxParticipants: 10, |
| 64 | + eligibleParticipants: collectors, // omit for an open round |
| 65 | +}); |
| 66 | + |
| 67 | +const sealed = await sealAssetBid({ |
| 68 | + round: Number(revealRound), |
| 69 | + drand, |
| 70 | + amount: 700_000_000n, |
| 71 | + payload: new TextEncoder().encode(JSON.stringify({ termsVersion: 1 })), |
| 72 | +}); |
| 73 | + |
| 74 | +await bidderClient.submitV2({ |
| 75 | + roundId, |
| 76 | + sealed, |
| 77 | + escrow: 1_000_000_000n, |
| 78 | +}); |
| 79 | +``` |
| 80 | + |
| 81 | +The seller authorizes lot custody at creation. Every bidder locks the same |
| 82 | +`fixedEscrow`; the private bid must be less than or equal to it. Settlement |
| 83 | +atomically transfers the winning amount and lot, refunds the winner's surplus, |
| 84 | +and refunds losing bidders. |
| 85 | + |
| 86 | +## Create a sealed proposal round |
| 87 | + |
| 88 | +```ts |
| 89 | +import { createSealedProposalRound, sealProposal } from "@sub-rosa/sdk"; |
| 90 | + |
| 91 | +const roundId = await createSealedProposalRound(organizerClient, { |
| 92 | + itemRef, |
| 93 | + revealRound, |
| 94 | + commitDeadline, |
| 95 | + revealDeadline, |
| 96 | + auditorPubkey: auditor.publicKey, |
| 97 | + maxParticipants: 12, |
| 98 | + eligibleParticipants: providers, |
| 99 | +}); |
| 100 | + |
| 101 | +const sealed = await sealProposal({ |
| 102 | + round: Number(revealRound), |
| 103 | + drand, |
| 104 | + price: 25_000_000_000n, |
| 105 | + proposal: { |
| 106 | + timelineDays: 14, |
| 107 | + approach: "Manual review, fuzzing, and remediation report", |
| 108 | + metadata: { teamSize: "3", region: "EU" }, |
| 109 | + }, |
| 110 | +}); |
| 111 | + |
| 112 | +await providerClient.submitV2({ roundId, sealed, escrow: 0n }); |
| 113 | +``` |
| 114 | + |
| 115 | +The organizer compares revealed proposals and chooses off-chain. Do not imply |
| 116 | +that `LowestBid` makes the business decision; ReceiptOnly produces a canonical |
| 117 | +submission/reveal receipt and moves no assets. |
| 118 | + |
| 119 | +## Advance the lifecycle |
| 120 | + |
| 121 | +```ts |
| 122 | +import { fetchRoundSignature, openPayload } from "@sub-rosa/sdk"; |
| 123 | + |
| 124 | +const round = await keeperClient.getRoundV2(roundId); |
| 125 | +const signature = await fetchRoundSignature(drand, Number(round.reveal_round)); |
| 126 | +await keeperClient.openRevealV2(roundId, signature); |
| 127 | + |
| 128 | +for (const bidder of await keeperClient.getBiddersV2(roundId)) { |
| 129 | + const state = await keeperClient.getSubmissionV2(roundId, bidder); |
| 130 | + if (state.revealed_envelope) continue; |
| 131 | + |
| 132 | + const seal = await keeperClient.getSealV2(roundId, bidder); |
| 133 | + if (!seal) continue; |
| 134 | + const envelope = await openPayload(seal.ciphertext, drand); |
| 135 | + await keeperClient.revealV2({ roundId, bidder, envelope }); |
| 136 | +} |
| 137 | + |
| 138 | +await keeperClient.clearV2(roundId); // only after revealDeadline |
| 139 | +const finalRound = await keeperClient.getRoundV2(roundId); |
| 140 | +if (finalRound.status.tag === "Cleared" && finalRound.mode.tag === "Auction") { |
| 141 | + await keeperClient.settleV2(roundId); |
| 142 | +} |
| 143 | +``` |
| 144 | + |
| 145 | +Use the corresponding `preflightOpenRevealV2`, `preflightRevealV2`, |
| 146 | +`preflightClearV2`, and `preflightSettleV2` before wallet-backed calls. |
| 147 | + |
| 148 | +## Verify a receipt |
| 149 | + |
| 150 | +```ts |
| 151 | +import { serializeReceiptV2, verifyReceiptV2 } from "@sub-rosa/sdk"; |
| 152 | + |
| 153 | +const receipt = await reader.exportReceiptV2(roundId); |
| 154 | +const result = verifyReceiptV2(receipt); |
| 155 | +if (!result.valid) throw new Error(JSON.stringify(result.issues)); |
| 156 | + |
| 157 | +const canonicalJson = serializeReceiptV2(receipt); |
| 158 | +``` |
| 159 | + |
| 160 | +Store `canonicalJson`, round ID, network, contract ID, and transaction hashes. |
| 161 | +Requery the live contract when ledger provenance or receipt freshness matters. |
0 commit comments