@esseyonsui/sui-sdk-v3 0.3.3 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/dist/config.d.ts +3 -0
  2. package/dist/config.d.ts.map +1 -1
  3. package/dist/config.js +1 -0
  4. package/dist/errors.d.ts +3 -1
  5. package/dist/errors.d.ts.map +1 -1
  6. package/dist/errors.js +5 -0
  7. package/dist/essey.d.ts +157 -131
  8. package/dist/essey.d.ts.map +1 -1
  9. package/dist/essey.js +641 -823
  10. package/dist/index.d.ts +1 -1
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +1 -1
  13. package/dist/v3/collateral/bodies.d.ts +23 -14
  14. package/dist/v3/collateral/bodies.d.ts.map +1 -1
  15. package/dist/v3/collateral/bodies.js +42 -35
  16. package/dist/v3/collateral/ext.d.ts +18 -13
  17. package/dist/v3/collateral/ext.d.ts.map +1 -1
  18. package/dist/v3/collateral/ext.js +5 -6
  19. package/dist/v3/collateral/health.d.ts +16 -10
  20. package/dist/v3/collateral/health.d.ts.map +1 -1
  21. package/dist/v3/collateral/health.js +55 -30
  22. package/dist/v3/collateral/math.d.ts +0 -2
  23. package/dist/v3/collateral/math.d.ts.map +1 -1
  24. package/dist/v3/collateral/math.js +0 -5
  25. package/dist/v3/collateral/openings.d.ts +5 -1
  26. package/dist/v3/collateral/openings.d.ts.map +1 -1
  27. package/dist/v3/collateral/openings.js +7 -12
  28. package/dist/v3/credential/membership.d.ts +16 -2
  29. package/dist/v3/credential/membership.d.ts.map +1 -1
  30. package/dist/v3/credential/membership.js +36 -3
  31. package/dist/v3/domains.d.ts +9 -0
  32. package/dist/v3/domains.d.ts.map +1 -1
  33. package/dist/v3/domains.js +5 -0
  34. package/dist/v3/fees.d.ts +13 -1
  35. package/dist/v3/fees.d.ts.map +1 -1
  36. package/dist/v3/fees.js +32 -2
  37. package/dist/v3/funds.d.ts +34 -0
  38. package/dist/v3/funds.d.ts.map +1 -0
  39. package/dist/v3/funds.js +60 -0
  40. package/dist/v3/keeper-payload.d.ts +29 -7
  41. package/dist/v3/keeper-payload.d.ts.map +1 -1
  42. package/dist/v3/keeper-payload.js +33 -22
  43. package/dist/v3/kinds.d.ts +6 -6
  44. package/dist/v3/kinds.d.ts.map +1 -1
  45. package/dist/v3/kinds.js +5 -13
  46. package/dist/v3/loans/bodies.d.ts +40 -68
  47. package/dist/v3/loans/bodies.d.ts.map +1 -1
  48. package/dist/v3/loans/bodies.js +50 -73
  49. package/dist/v3/loans/offer-payload.d.ts +109 -0
  50. package/dist/v3/loans/offer-payload.d.ts.map +1 -0
  51. package/dist/v3/loans/offer-payload.js +207 -0
  52. package/dist/v3/loans/offer-plan.d.ts +8 -60
  53. package/dist/v3/loans/offer-plan.d.ts.map +1 -1
  54. package/dist/v3/loans/offer-plan.js +19 -95
  55. package/dist/v3/loans/open-plan.d.ts +15 -5
  56. package/dist/v3/loans/open-plan.d.ts.map +1 -1
  57. package/dist/v3/loans/open-plan.js +18 -7
  58. package/dist/v3/loans/reclaim-plan.d.ts +31 -15
  59. package/dist/v3/loans/reclaim-plan.d.ts.map +1 -1
  60. package/dist/v3/loans/reclaim-plan.js +63 -32
  61. package/dist/v3/loans/refi-plan.d.ts +8 -34
  62. package/dist/v3/loans/refi-plan.d.ts.map +1 -1
  63. package/dist/v3/loans/refi-plan.js +30 -111
  64. package/dist/v3/loans/repay-plan.d.ts.map +1 -1
  65. package/dist/v3/loans/repay-plan.js +2 -2
  66. package/dist/v3/loans/settle-plan.d.ts +88 -53
  67. package/dist/v3/loans/settle-plan.d.ts.map +1 -1
  68. package/dist/v3/loans/settle-plan.js +141 -150
  69. package/dist/v3/locks.d.ts +21 -0
  70. package/dist/v3/locks.d.ts.map +1 -0
  71. package/dist/v3/locks.js +15 -0
  72. package/dist/v3/memo.d.ts +14 -4
  73. package/dist/v3/memo.d.ts.map +1 -1
  74. package/dist/v3/memo.js +14 -7
  75. package/dist/v3/notes/derive.d.ts +5 -0
  76. package/dist/v3/notes/derive.d.ts.map +1 -1
  77. package/dist/v3/notes/derive.js +5 -0
  78. package/dist/v3/pace.d.ts +0 -1
  79. package/dist/v3/pace.d.ts.map +1 -1
  80. package/dist/v3/pace.js +0 -1
  81. package/dist/v3/pads.d.ts +15 -0
  82. package/dist/v3/pads.d.ts.map +1 -0
  83. package/dist/v3/pads.js +25 -0
  84. package/dist/v3/prover.d.ts +1 -1
  85. package/dist/v3/prover.d.ts.map +1 -1
  86. package/dist/v3/prover.js +1 -0
  87. package/dist/v3/sales/auctioneer.d.ts +32 -27
  88. package/dist/v3/sales/auctioneer.d.ts.map +1 -1
  89. package/dist/v3/sales/auctioneer.js +67 -108
  90. package/dist/v3/sales/bid.d.ts +20 -49
  91. package/dist/v3/sales/bid.d.ts.map +1 -1
  92. package/dist/v3/sales/bid.js +28 -83
  93. package/dist/v3/sales/bodies.d.ts +4 -54
  94. package/dist/v3/sales/bodies.d.ts.map +1 -1
  95. package/dist/v3/sales/bodies.js +10 -52
  96. package/dist/v3/sales/claim.d.ts +0 -2
  97. package/dist/v3/sales/claim.d.ts.map +1 -1
  98. package/dist/v3/sales/claim.js +6 -8
  99. package/dist/v3/sales/index.d.ts +0 -1
  100. package/dist/v3/sales/index.d.ts.map +1 -1
  101. package/dist/v3/sales/index.js +0 -1
  102. package/dist/v3/sales/listing.d.ts +8 -6
  103. package/dist/v3/sales/listing.d.ts.map +1 -1
  104. package/dist/v3/sales/listing.js +27 -9
  105. package/dist/v3/sales/open-kind.d.ts +1 -3
  106. package/dist/v3/sales/open-kind.d.ts.map +1 -1
  107. package/dist/v3/sales/open-kind.js +2 -3
  108. package/dist/v3/sales/outcome.d.ts +5 -8
  109. package/dist/v3/sales/outcome.d.ts.map +1 -1
  110. package/dist/v3/sales/outcome.js +5 -9
  111. package/dist/v3/sales/package-gate.d.ts +3 -4
  112. package/dist/v3/sales/package-gate.d.ts.map +1 -1
  113. package/dist/v3/sales/package-gate.js +9 -7
  114. package/dist/v3/sales/rows.d.ts +9 -49
  115. package/dist/v3/sales/rows.d.ts.map +1 -1
  116. package/dist/v3/sales/rows.js +17 -91
  117. package/dist/v3/sales/seller.d.ts +2 -6
  118. package/dist/v3/sales/seller.d.ts.map +1 -1
  119. package/dist/v3/sales/seller.js +4 -11
  120. package/dist/v3/stage1.d.ts +8 -21
  121. package/dist/v3/stage1.d.ts.map +1 -1
  122. package/dist/v3/stage1.js +8 -76
  123. package/package.json +1 -1
  124. package/dist/v3/loans/lock-round.d.ts +0 -22
  125. package/dist/v3/loans/lock-round.d.ts.map +0 -1
  126. package/dist/v3/loans/lock-round.js +0 -20
  127. package/dist/v3/sales/reclaim.d.ts +0 -46
  128. package/dist/v3/sales/reclaim.d.ts.map +0 -1
  129. package/dist/v3/sales/reclaim.js +0 -57
package/dist/v3/stage1.js CHANGED
@@ -1,4 +1,3 @@
1
- import { poseidonHash } from "@mysten/sui/zklogin";
2
1
  import { COINS } from "../config.js";
3
2
  import { EsseyError } from "../errors.js";
4
3
  import { address, decimal } from "../network.js";
@@ -6,7 +5,7 @@ import { afterPage, covered, MAX_LIST_PAGES } from "./collateral/scan.js";
6
5
  export { afterPage, MAX_LIST_PAGES };
7
6
  import { localHealth } from "./collateral/local-health.js";
8
7
  import { collNote, requestCommit, termsCommit, } from "./collateral/openings.js";
9
- import { DOM_BOUNDS, R } from "./domains.js";
8
+ import { R } from "./domains.js";
10
9
  import { deriveNoteKey, noteEncKey } from "./notes/derive.js";
11
10
  import { noteCommitment, noteNullifier, notePk } from "./notes/keys.js";
12
11
  import { openOpening } from "./notes/opening.js";
@@ -27,7 +26,6 @@ export const LOAN_LIFECYCLE = [
27
26
  "cancelled",
28
27
  "refi",
29
28
  ];
30
- const MAX_BIDS = 16;
31
29
  function missing(what) {
32
30
  throw new EsseyError("NOT_SET_UP", `missing config: ${what}`);
33
31
  }
@@ -172,16 +170,6 @@ function u8(value, what) {
172
170
  tampered();
173
171
  return Number(n);
174
172
  }
175
- function count(value, what) {
176
- const n = whole(value, what);
177
- if (n > BigInt(Number.MAX_SAFE_INTEGER))
178
- tampered();
179
- return Number(n);
180
- }
181
- /** C-SPEC (`v3/docs/specs/C-SPEC.md:179`): Poseidon4(DOM_BOUNDS, lo, hi, boundsSalt). */
182
- export function boundsCommit(lo, hi, salt) {
183
- return poseidonHash([DOM_BOUNDS, lo, hi, salt]);
184
- }
185
173
  function opened(coin, index, events, seed) {
186
174
  assertCoin(coin);
187
175
  if (!Number.isSafeInteger(index) || index < 0)
@@ -256,17 +244,7 @@ function parseRound(value) {
256
244
  if (value === undefined || value === null || tableHandle(value))
257
245
  return null;
258
246
  const round = record(value, "round");
259
- const offers = round.offers;
260
- const listed = Array.isArray(offers) ? offers.length : count(round.n_offers ?? 0, "n_offers");
261
- if (Array.isArray(offers) &&
262
- round.n_offers !== undefined &&
263
- count(round.n_offers, "n_offers") !== offers.length)
264
- tampered();
265
- return {
266
- reqCommit: whole(round.req_commit, "req_commit"),
267
- closeMs: whole(round.close_ms, "close_ms"),
268
- offers: listed,
269
- };
247
+ return { reqCommit: whole(round.req_commit, "req_commit"), closeMs: whole(round.close_ms, "close_ms") };
270
248
  }
271
249
  function parseLoan(config, row) {
272
250
  const loan = record(row.json, "loan");
@@ -282,7 +260,6 @@ function parseLoan(config, row) {
282
260
  state,
283
261
  round: whole(readOnce(loan, "round") ?? "0", "loan.round"),
284
262
  closeMs: current?.closeMs ?? null,
285
- offers: current?.offers ?? null,
286
263
  loanCoin: coinByPool(config, String(readOnce(loan, "pool_l") ?? "")),
287
264
  collateralCoin: coinByPool(config, String(readOnce(loan, "pool_c") ?? "")),
288
265
  marketId: address(String(readOnce(loan, "market_id") ?? ""), "market"),
@@ -309,7 +286,6 @@ export function summarizeLoan(config, row) {
309
286
  state: loan.state,
310
287
  round: loan.round,
311
288
  closeMs: loan.closeMs,
312
- offers: loan.offers,
313
289
  loanCoin: loan.loanCoin,
314
290
  collateralCoin: loan.collateralCoin,
315
291
  };
@@ -336,7 +312,6 @@ export function viewLoanObject(config, row, o) {
336
312
  state: loan.state,
337
313
  round: loan.round,
338
314
  closeMs: loan.closeMs,
339
- offers: loan.offers,
340
315
  loanCoin: loan.loanCoin,
341
316
  collateralCoin: loan.collateralCoin,
342
317
  lifecycle: loan.lifecycle,
@@ -440,13 +415,6 @@ function ownData(obj, key) {
440
415
  function parseRoom(config, row) {
441
416
  requireSale(config);
442
417
  const room = record(row.json, "room");
443
- const bids = room.bids;
444
- const listed = count(room.n_bids ?? (Array.isArray(bids) ? bids.length : 0), "n_bids");
445
- if (Array.isArray(bids) && bids.length !== listed)
446
- tampered();
447
- const maxBids = whole(room.max_bids ?? "0", "max_bids");
448
- if (maxBids < BigInt(listed))
449
- tampered();
450
418
  const closeMs = whole(room.close_ms ?? "0", "close_ms");
451
419
  const finishByMs = whole(room.finish_by_ms ?? "0", "finish_by_ms");
452
420
  if (closeMs > finishByMs)
@@ -456,45 +424,16 @@ function parseRoom(config, row) {
456
424
  coin: coinByPool(config, String(room.pool_id ?? "")),
457
425
  state: u8(room.state, "room.state"),
458
426
  closeMs,
459
- bids: listed,
460
427
  finishByMs,
461
- maxBids,
462
- boundsCommit: whole(room.bounds_commit ?? "0", "bounds_commit"),
463
428
  };
464
429
  }
465
430
  /** D-SPEC §6.2:600. */
466
431
  export function summarizeRoom(config, row) {
467
432
  const room = parseRoom(config, row);
468
- return { id: room.id, coin: room.coin, state: room.state, closeMs: room.closeMs, bids: room.bids };
469
- }
470
- /** D-SPEC §6.2:600. A bounds opening that misses `bounds_commit` is tampered (`C-SPEC.md:179`). */
471
- export function viewRoomObject(config, row, bounds) {
472
- const room = parseRoom(config, row);
473
- let minPrice = null;
474
- let maxPrice = null;
475
- if (bounds) {
476
- const box = plain(bounds);
477
- const lo = ownBigint(box, "lo");
478
- const hi = ownBigint(box, "hi");
479
- const salt = ownBigint(box, "salt");
480
- const commit = hashOrRefuse(() => boundsCommit(asField(lo), asField(hi), asField(salt)));
481
- if (commit !== room.boundsCommit)
482
- tampered();
483
- minPrice = lo;
484
- maxPrice = hi;
485
- }
486
- return {
487
- id: room.id,
488
- coin: room.coin,
489
- state: room.state,
490
- closeMs: room.closeMs,
491
- bids: room.bids,
492
- finishByMs: room.finishByMs,
493
- maxBids: room.maxBids,
494
- minPrice,
495
- maxPrice,
496
- };
433
+ return { id: room.id, coin: room.coin, state: room.state, closeMs: room.closeMs };
497
434
  }
435
+ /** D-SPEC §6.2:600. */
436
+ export const viewRoomObject = (config, row) => parseRoom(config, row);
498
437
  /** D-SPEC §6.2:588. Refuses before any envelope is built. */
499
438
  export function assertLoanOpen(p) {
500
439
  assertCoin(p.loanCoin);
@@ -512,7 +451,7 @@ export function assertLoanOpen(p) {
512
451
  if (!Number.isInteger(p.offerWindowMs) || p.offerWindowMs <= 0)
513
452
  throw new EsseyError("INVALID_ARGUMENT", "offerWindowMs must be above 0");
514
453
  }
515
- /** D-SPEC §6.2:599. Copies each argument once. `maxBids` is `sale_room.move`'s 1..16. */
454
+ /** D-SPEC §6.2:599. Copies each argument once. */
516
455
  export function assertSaleOpen(p) {
517
456
  const open = snapshotSale(p);
518
457
  assertCoin(open.coin);
@@ -526,8 +465,6 @@ export function assertSaleOpen(p) {
526
465
  !Number.isInteger(open.finishWindowMs) ||
527
466
  open.finishWindowMs <= 0)
528
467
  throw new EsseyError("INVALID_ARGUMENT", "the bid and finish windows must be above 0");
529
- if (!Number.isInteger(open.maxBids) || open.maxBids < 1 || open.maxBids > MAX_BIDS)
530
- throw new EsseyError("INVALID_ARGUMENT", "maxBids is not 1..16");
531
468
  return open;
532
469
  }
533
470
  function snapshotSale(p) {
@@ -541,21 +478,16 @@ function snapshotSale(p) {
541
478
  price: ownBigint(o, "price"),
542
479
  bidWindowMs: ownInt(o, "bidWindowMs"),
543
480
  finishWindowMs: ownInt(o, "finishWindowMs"),
544
- maxBids: ownInt(o, "maxBids"),
545
481
  sponsored: ownFlag(o, "sponsored"),
546
482
  };
547
483
  }
548
484
  /**
549
- * The room the sponsor named is this open: same coin pool, close, finish window and max bids
550
- * (`sale_room.move:181-193`).
485
+ * The room the sponsor named is this open: same coin pool, close and finish window (`sale_room.move:98-113`).
551
486
  */
552
487
  export function assertRoomMatches(config, open, row) {
553
488
  const room = parseRoom(config, row);
554
489
  const finish = BigInt(open.closeMs) + BigInt(open.finishWindowMs);
555
- if (room.coin !== open.coin ||
556
- room.closeMs !== BigInt(open.closeMs) ||
557
- room.finishByMs !== finish ||
558
- room.maxBids !== BigInt(open.maxBids))
490
+ if (room.coin !== open.coin || room.closeMs !== BigInt(open.closeMs) || room.finishByMs !== finish)
559
491
  throw new EsseyError("SERVICE_REFUSED", "unknown object: the room is not this open");
560
492
  }
561
493
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@esseyonsui/sui-sdk-v3",
3
- "version": "0.3.3",
3
+ "version": "0.4.0",
4
4
  "private": false,
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -1,22 +0,0 @@
1
- type Offers = {
2
- offers: {
3
- lock: string;
4
- }[];
5
- };
6
- /**
7
- * The round whose offers hold the lender's lock, newest first. Each lock commits to its round (`lockField`), so a
8
- * reader that ignores `round` and returns the current one never matches an older round.
9
- */
10
- export declare function lockRound(p: {
11
- current: bigint;
12
- currentRound: Offers;
13
- round?: bigint;
14
- readRound: (round: bigint) => Promise<Offers | null | undefined>;
15
- lockAt: (round: bigint) => bigint;
16
- }): Promise<{
17
- round: bigint;
18
- locks: bigint[];
19
- slot: number;
20
- }>;
21
- export {};
22
- //# sourceMappingURL=lock-round.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"lock-round.d.ts","sourceRoot":"","sources":["../../../src/v3/loans/lock-round.ts"],"names":[],"mappings":"AAEA,KAAK,MAAM,GAAG;IAAE,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;CAAE,CAAC;AAE7C;;;GAGG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAAE;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;IACjE,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;CACnC,GAAG,OAAO,CAAC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,EAAE,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAc5D"}
@@ -1,20 +0,0 @@
1
- import { EsseyError } from "../../errors.js";
2
- /**
3
- * The round whose offers hold the lender's lock, newest first. Each lock commits to its round (`lockField`), so a
4
- * reader that ignores `round` and returns the current one never matches an older round.
5
- */
6
- export async function lockRound(p) {
7
- if (p.round !== undefined && (p.round < 0n || p.round > p.current))
8
- throw new EsseyError("INVALID_ARGUMENT", "refused: the round is not one of this loan's rounds");
9
- const rounds = p.round !== undefined
10
- ? [p.round]
11
- : Array.from({ length: Number(p.current) + 1 }, (_, i) => p.current - BigInt(i));
12
- for (const round of rounds) {
13
- const row = round === p.current ? p.currentRound : await p.readRound(round);
14
- const locks = (row?.offers ?? []).map((o) => BigInt(o.lock));
15
- const slot = locks.indexOf(p.lockAt(round));
16
- if (slot >= 0)
17
- return { round, locks, slot };
18
- }
19
- throw new EsseyError("SERVICE_REFUSED", "unknown object: the record's lock is in no round of this loan");
20
- }
@@ -1,46 +0,0 @@
1
- import type { FeeCommitInput } from "../fees.ts";
2
- import type { CircuitInput } from "../inputs.ts";
3
- import { type BidSecrets } from "./rows.ts";
4
- export type ReclaimParams = {
5
- /** `SaleRoom` as read from chain: its `sale_key`, every bid's lock in seq order, and `residual`. */
6
- room: {
7
- saleKey: bigint;
8
- locks: bigint[];
9
- residual: bigint;
10
- };
11
- bid: BidSecrets;
12
- /** "lock" returns the deposit. "residual" returns the winner's change: the deposit less the price. */
13
- what: "lock" | "residual";
14
- out: {
15
- pk: bigint;
16
- blinding: bigint;
17
- };
18
- relayer: string;
19
- relayerFee: bigint;
20
- /** `[out note, fee note]`, the order `reclaim` hands `room_insert`. */
21
- encs: [Uint8Array, Uint8Array];
22
- fee: FeeCommitInput;
23
- eph: bigint;
24
- };
25
- /** The `u256` and `address` arguments of `sale_room::reclaim`, under Move's own names and in its order. */
26
- export type ReclaimStatement = {
27
- nullifier: bigint;
28
- out_note: bigint;
29
- fee_note: bigint;
30
- eph_x: bigint;
31
- eph_y: bigint;
32
- fee_ct: bigint;
33
- fee_commit: bigint;
34
- relayer: string;
35
- };
36
- /**
37
- * Witness for `circuits/v3/reclaim/reclaim.circom` over a sale room. Public signals, in order: hLock, residual, hCtx, N,
38
- * hOut. The lock is rebuilt under this room's `sale_key`; a room that does not hold it is refused.
39
- */
40
- export declare function reclaim(p: ReclaimParams): Promise<{
41
- input: CircuitInput;
42
- publics: bigint[];
43
- statement: ReclaimStatement;
44
- outAmt: bigint;
45
- }>;
46
- //# sourceMappingURL=reclaim.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"reclaim.d.ts","sourceRoot":"","sources":["../../../src/v3/sales/reclaim.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAKjD,OAAO,EAA8B,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC;AAExE,MAAM,MAAM,aAAa,GAAG;IAC1B,oGAAoG;IACpG,IAAI,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,EAAE,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;IAC7D,GAAG,EAAE,UAAU,CAAC;IAChB,sGAAsG;IACtG,IAAI,EAAE,MAAM,GAAG,UAAU,CAAC;IAC1B,GAAG,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,uEAAuE;IACvE,IAAI,EAAE,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IAC/B,GAAG,EAAE,cAAc,CAAC;IACpB,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,2GAA2G;AAC3G,MAAM,MAAM,gBAAgB,GAAG;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF;;;GAGG;AACH,wBAAsB,OAAO,CAC3B,CAAC,EAAE,aAAa,GACf,OAAO,CAAC;IAAE,KAAK,EAAE,YAAY,CAAC;IAAC,OAAO,EAAE,MAAM,EAAE,CAAC;IAAC,SAAS,EAAE,gBAAgB,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CA0ClG"}
@@ -1,57 +0,0 @@
1
- import { address } from "../../network.js";
2
- import { ENC_BYTES } from "../kinds.js";
3
- import { reclaimLock } from "../loans/reclaim-plan.js";
4
- import { notePk } from "../notes/keys.js";
5
- import { SLOTS, lock4, residualLock } from "./rows.js";
6
- /**
7
- * Witness for `circuits/v3/reclaim/reclaim.circom` over a sale room. Public signals, in order: hLock, residual, hCtx, N,
8
- * hOut. The lock is rebuilt under this room's `sale_key`; a room that does not hold it is refused.
9
- */
10
- export async function reclaim(p) {
11
- const { room, bid } = p;
12
- if (p.relayerFee > 0n && BigInt(p.relayer) === 0n)
13
- throw new Error("a relayer fee needs a relayer");
14
- if (room.locks.length > SLOTS)
15
- throw new Error("a room holds at most 16 bids");
16
- if (p.encs.some((e) => e.length !== ENC_BYTES))
17
- throw new Error("a note ciphertext is 128 bytes");
18
- const ownerPk = notePk(bid.ownerSk);
19
- const change = p.what === "residual";
20
- const amount = change ? bid.amount - bid.v : bid.amount;
21
- const own = change
22
- ? residualLock(room.saleKey, ownerPk, bid.ns, amount)
23
- : { nsEff: bid.ns, b: bid.b, ...lock4(room.saleKey, ownerPk, bid.ns, amount, bid.b) };
24
- const residualSlot = own.lock === room.residual ? SLOTS : -1;
25
- const slot = change ? residualSlot : room.locks.indexOf(own.lock);
26
- if (slot < 0)
27
- throw new Error("this room does not hold the lock");
28
- if (amount < p.relayerFee)
29
- throw new Error("the lock does not cover the relayer fee");
30
- const w = await reclaimLock({
31
- locks: room.locks,
32
- slot,
33
- field: room.saleKey,
34
- amount,
35
- ownerSk: bid.ownerSk,
36
- ns: own.nsEff,
37
- b: own.b,
38
- out: p.out,
39
- relayer: p.relayer,
40
- relayerFee: p.relayerFee,
41
- encs: p.encs,
42
- fee: p.fee,
43
- eph: p.eph,
44
- residual: room.residual,
45
- });
46
- const statement = {
47
- nullifier: w.n,
48
- out_note: w.outNote,
49
- fee_note: w.feeNote,
50
- eph_x: w.ephX,
51
- eph_y: w.ephY,
52
- fee_ct: w.feeCt,
53
- fee_commit: w.feeCommit,
54
- relayer: address(p.relayer, "relayer"),
55
- };
56
- return { input: w.input, publics: w.publics, statement, outAmt: w.outAmt };
57
- }