@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
@@ -0,0 +1,15 @@
1
+ import { poseidonHash } from "@mysten/sui/zklogin";
2
+ import { DOM_LNULL, DOM_LOCK, DOM_LOCKB, DOM_ROUND } from "./domains.js";
3
+ import { noteCommitment } from "./notes/keys.js";
4
+ /** `loan::lock_field`: a loan round's lock field. A bid's field is the room's `sale_key`. */
5
+ export const lockField = (loanKey, round) => poseidonHash([DOM_ROUND, loanKey, round]);
6
+ /** `lib/lock.circom` Lock5: a note shape, so js4's first output with `outPk0 = lockPk` is the leaf. */
7
+ export function lock5(l) {
8
+ const lockPk = poseidonHash([DOM_LOCK, l.field, l.ownerPk, poseidonHash([l.ns]), l.unlockS]);
9
+ const lock = noteCommitment(l.amount, lockPk, l.b);
10
+ return { lockPk, lock, nullifier: poseidonHash([DOM_LNULL, l.ns, lock]) };
11
+ }
12
+ /** Ruling R5: an offer's blind binds the lender's enc point (`loan_settle.circom`, `loan_refi.circom`). */
13
+ export const offerBlind = (ns, encX, encY) => poseidonHash([DOM_LOCKB, ns, poseidonHash([encX, encY])]);
14
+ /** A bid's blind binds `ns` alone: no ECDH reads a bid key. */
15
+ export const bidBlind = (ns) => poseidonHash([DOM_LOCKB, ns]);
package/dist/v3/memo.d.ts CHANGED
@@ -24,12 +24,22 @@ export declare const memoAad: (slot: MemoSlot) => Uint8Array;
24
24
  export declare function sealMemo(key: Uint8Array, slot: MemoSlot, body: Uint8Array): Uint8Array;
25
25
  /** The body of a memo sealed for `slot` under `key`, its first `bodyLen` bytes; null for anyone else's memo. */
26
26
  export declare function openMemo(key: Uint8Array, slot: MemoSlot, memo: Uint8Array, bodyLen: number): Uint8Array | null;
27
- /** What the borrower's request memo holds: the loan key's note index, the locked amount and the borrower key. */
28
- export type RequestMemo = {
27
+ /** The loan key's note index, the locked amount and the borrower key: what every borrower memo starts with. */
28
+ export type BorrowerMemo = {
29
29
  keyIndex: number;
30
30
  collAmt: bigint;
31
31
  borrowerPk: bigint;
32
32
  };
33
+ /**
34
+ * The borrower's request memo of round 0 (`request::new_request`) or of a refi round (`refi::open_refi`). It carries
35
+ * the posted request too, so the borrower settles on its own request from the seed alone, with no Seal read of
36
+ * `req_sealed` (and so no funds proof).
37
+ */
38
+ export type RequestMemo = BorrowerMemo & {
39
+ principal: bigint;
40
+ maxRateBps: bigint;
41
+ termMs: bigint;
42
+ };
33
43
  /** A lender's `OfferRecord`, every field present. */
34
44
  export type OfferMemo = {
35
45
  noteIndex: number;
@@ -39,7 +49,7 @@ export type OfferMemo = {
39
49
  borrowerPk: bigint;
40
50
  };
41
51
  /** The borrower's record once settled. */
42
- export type SettleMemo = RequestMemo & {
52
+ export type SettleMemo = BorrowerMemo & {
43
53
  terms: KeeperTerms;
44
54
  };
45
55
  /** A seller's record: `saleSecrets` and the bounds salt derive from the note key at `noteIndex`; bounds are the price. */
@@ -62,7 +72,7 @@ export declare const sealSaleMemo: (key: Uint8Array, saleKey: bigint, m: SaleMem
62
72
  export declare const sealBidMemo: (key: Uint8Array, saleKey: bigint, m: BidMemo) => Uint8Array<ArrayBufferLike>;
63
73
  export declare function openSaleMemo(key: Uint8Array, saleKey: bigint, memo: Uint8Array): SaleMemo | null;
64
74
  export declare function openBidMemo(key: Uint8Array, saleKey: bigint, memo: Uint8Array): BidMemo | null;
65
- export declare function openRequestMemo(key: Uint8Array, loanKey: bigint, memo: Uint8Array): RequestMemo | null;
75
+ export declare function openRequestMemo(key: Uint8Array, loanKey: bigint, memo: Uint8Array, round?: bigint): RequestMemo | null;
66
76
  export declare function openOfferMemo(key: Uint8Array, loanKey: bigint, round: bigint, memo: Uint8Array): OfferMemo | null;
67
77
  export declare function openSettleMemo(key: Uint8Array, loanKey: bigint, round: bigint, memo: Uint8Array): SettleMemo | null;
68
78
  //# sourceMappingURL=memo.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"memo.d.ts","sourceRoot":"","sources":["../../src/v3/memo.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEvD,gHAAgH;AAChH,eAAO,MAAM,QAAQ,MAAM,CAAC;AAM5B,oGAAoG;AACpG,eAAO,MAAM,SAAS;;;;;;CAAgE,CAAC;AACvF,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,SAAS,CAAC,CAAC,MAAM,OAAO,SAAS,CAAC,CAAC;AAElE,yGAAyG;AACzG,MAAM,MAAM,QAAQ,GAAG;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAMtE,4EAA4E;AAC5E,eAAO,MAAM,OAAO,GAAI,MAAM,UAAU,KAAG,UAA0D,CAAC;AAYtG,8GAA8G;AAC9G,eAAO,MAAM,OAAO,GAAI,MAAM,QAAQ,KAAG,UAC8C,CAAC;AAExF,8FAA8F;AAC9F,wBAAgB,QAAQ,CAAC,GAAG,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,GAAG,UAAU,CAOtF;AAED,gHAAgH;AAChH,wBAAgB,QAAQ,CACtB,GAAG,EAAE,UAAU,EACf,IAAI,EAAE,QAAQ,EACd,IAAI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ACsD,CAAC;AAErG,eAAO,MAAM,aAAa,GAAI,GAAG,SAAS,4BAOtC,CAAC;AAEL,eAAO,MAAM,cAAc,GAAI,GAAG,UAAU,4BAWxC,CAAC;AAEL,yDAAyD;AACzD,eAAO,MAAM,YAAY,GAAI,KAAK,UAAU,EAAE,SAAS,MAAM,EAAE,GAAG,QAAQ,gCAKvE,CAAC;AAEJ,iDAAiD;AACjD,eAAO,MAAM,WAAW,GAAI,KAAK,UAAU,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,gCAKrE,CAAC;AAEJ,wBAAgB,YAAY,CAAC,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,QAAQ,GAAG,IAAI,CAKhG;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,OAAO,GAAG,IAAI,CAK9F;AAED,wBAAgB,eAAe,CAC7B,GAAG,EAAE,UAAU,EACf,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,UAAU,EAChB,KAAK,SAAK,GACT,WAAW,GAAG,IAAI,CAYpB;AAED,wBAAgB,aAAa,CAC3B,GAAG,EAAE,UAAU,EACf,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,UAAU,GACf,SAAS,GAAG,IAAI,CAWlB;AAED,wBAAgB,cAAc,CAC5B,GAAG,EAAE,UAAU,EACf,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,UAAU,GACf,UAAU,GAAG,IAAI,CAmBnB"}
package/dist/v3/memo.js CHANGED
@@ -53,7 +53,7 @@ export function openMemo(key, slot, memo, bodyLen) {
53
53
  return null;
54
54
  return plain.slice(HEADER, HEADER + bodyLen);
55
55
  }
56
- const REQUEST_BODY = 44;
56
+ const REQUEST_BODY = 68;
57
57
  const OFFER_BODY = 60;
58
58
  const SETTLE_BODY = 204;
59
59
  const SALE_BODY = 12;
@@ -66,8 +66,8 @@ function reader(bytes) {
66
66
  const take = (size) => fromBe(bytes.subarray(at, (at += size)));
67
67
  return { index: () => Number(take(4)), u64: () => take(8), field: () => take(32) };
68
68
  }
69
- const requestBody = (m) => [...index(m.keyIndex), ...u64(m.collAmt), ...field(m.borrowerPk)];
70
- export const requestMemoBody = (m) => Uint8Array.from(requestBody(m));
69
+ const borrowerBody = (m) => [...index(m.keyIndex), ...u64(m.collAmt), ...field(m.borrowerPk)];
70
+ export const requestMemoBody = (m) => Uint8Array.from([...borrowerBody(m), ...u64(m.principal), ...u64(m.maxRateBps), ...u64(m.termMs)]);
71
71
  export const offerMemoBody = (m) => Uint8Array.from([
72
72
  ...index(m.noteIndex),
73
73
  ...u64(m.principal),
@@ -76,7 +76,7 @@ export const offerMemoBody = (m) => Uint8Array.from([
76
76
  ...field(m.borrowerPk),
77
77
  ]);
78
78
  export const settleMemoBody = (m) => Uint8Array.from([
79
- ...requestBody(m),
79
+ ...borrowerBody(m),
80
80
  ...u64(m.terms.principal),
81
81
  ...u64(m.terms.rateBps),
82
82
  ...u64(m.terms.owed),
@@ -104,12 +104,19 @@ export function openBidMemo(key, saleKey, memo) {
104
104
  const r = reader(body);
105
105
  return { noteIndex: r.index(), v: r.u64(), amount: r.u64() };
106
106
  }
107
- export function openRequestMemo(key, loanKey, memo) {
108
- const body = openMemo(key, { kind: MEMO_KIND.request, key: loanKey, round: 0n }, memo, REQUEST_BODY);
107
+ export function openRequestMemo(key, loanKey, memo, round = 0n) {
108
+ const body = openMemo(key, { kind: MEMO_KIND.request, key: loanKey, round }, memo, REQUEST_BODY);
109
109
  if (!body)
110
110
  return null;
111
111
  const r = reader(body);
112
- return { keyIndex: r.index(), collAmt: r.u64(), borrowerPk: r.field() };
112
+ return {
113
+ keyIndex: r.index(),
114
+ collAmt: r.u64(),
115
+ borrowerPk: r.field(),
116
+ principal: r.u64(),
117
+ maxRateBps: r.u64(),
118
+ termMs: r.u64(),
119
+ };
113
120
  }
114
121
  export function openOfferMemo(key, loanKey, round, memo) {
115
122
  const body = openMemo(key, { kind: MEMO_KIND.offer, key: loanKey, round }, memo, OFFER_BODY);
@@ -16,6 +16,11 @@ export declare function receiveKey(seed: Uint8Array, index: number): {
16
16
  C: Uint8Array;
17
17
  D: Uint8Array;
18
18
  };
19
+ /** Z1 freeze §6.3: the key offers (or bids) to the request (or listing) of record `index` are sealed to. */
20
+ export declare function offerRecvKey(seed: Uint8Array, index: number): {
21
+ secret: Uint8Array;
22
+ pub: Uint8Array;
23
+ };
19
24
  /** D-SPEC:564, :596: the fresh one-time sender of deposit call `index`. */
20
25
  export declare function depositSigner(seed: Uint8Array, index: number): Ed25519Keypair;
21
26
  /** PRV-35: the single-use address sale item `index` (a claim, a badge, an item to sell) lands at and opens from. */
@@ -1 +1 @@
1
- {"version":3,"file":"derive.d.ts","sourceRoot":"","sources":["../../../src/v3/notes/derive.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAI9D,MAAM,MAAM,OAAO,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AAEvD,eAAO,MAAM,UAAU,KAAK,CAAC;AAoB7B,2HAA2H;AAC3H,wBAAgB,aAAa,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAEtE;AAED,sEAAsE;AACtE,wBAAgB,UAAU,CAAC,IAAI,EAAE,UAAU,GAAG;IAAE,MAAM,EAAE,UAAU,CAAC;IAAC,MAAM,EAAE,UAAU,CAAA;CAAE,CAKvF;AAED,oHAAoH;AACpH,wBAAgB,UAAU,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,GAAG;IAAE,CAAC,EAAE,UAAU,CAAC;IAAC,CAAC,EAAE,UAAU,CAAA;CAAE,CAM5F;AAED,2EAA2E;AAC3E,wBAAgB,aAAa,CAAC,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Key(seed, index) {
34
34
  const D = secp256k1.getPublicKey(d, true);
35
35
  return { C: secp256k1.getSharedSecret(noteEncKey(seed).encKey, D, true), D };
36
36
  }
37
+ /** Z1 freeze §6.3: the key offers (or bids) to the request (or listing) of record `index` are sealed to. */
38
+ export function offerRecvKey(seed, index) {
39
+ const secret = secp256k1.utils.randomSecretKey(digest(seed, "ess3/offer-recv/v1", u64be(index), secp256k1.lengths.seed));
40
+ return { secret, pub: secp256k1.getPublicKey(secret, true) };
41
+ }
37
42
  /** D-SPEC:564, :596: the fresh one-time sender of deposit call `index`. */
38
43
  export function depositSigner(seed, index) {
39
44
  return Ed25519Keypair.fromSecretKey(digest(seed, "ess3/signer", u64be(index), 32));
package/dist/v3/pace.d.ts CHANGED
@@ -8,7 +8,6 @@ export declare const PACED: {
8
8
  readonly collect_surplus: "long";
9
9
  readonly reclaim_offer: "long";
10
10
  readonly reclaim_collateral: "long";
11
- readonly sale_reclaim: "long";
12
11
  readonly repay: "medium";
13
12
  readonly release: "medium";
14
13
  readonly offer: "medium";
@@ -1 +1 @@
1
- {"version":3,"file":"pace.d.ts","sourceRoot":"","sources":["../../src/v3/pace.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAC;AAEpD,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;;;;;;CAoB4B,CAAC;AAE/C,MAAM,MAAM,WAAW,GAAG,MAAM,OAAO,KAAK,CAAC;AAE7C,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,SAAS,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAIvE,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,QAAQ,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAExD,iHAAiH;AACjH,MAAM,MAAM,KAAK,GAAG;IAAE,MAAM,EAAE,WAAW,CAAC;IAAC,OAAO,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,EACb,QAAQ,EAAE,QAAQ,GAAG,IAAI,EACzB,QAAQ,EAAE,MAAM,EAChB,IAAI,GAAE,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,MAAoB,GACvD,MAAM,CAYR"}
package/dist/v3/pace.js CHANGED
@@ -9,7 +9,6 @@ export const PACED = {
9
9
  collect_surplus: "long",
10
10
  reclaim_offer: "long",
11
11
  reclaim_collateral: "long",
12
- sale_reclaim: "long",
13
12
  repay: "medium",
14
13
  release: "medium",
15
14
  offer: "medium",
@@ -0,0 +1,15 @@
1
+ export type Pad = {
2
+ pk: bigint;
3
+ blinding: bigint;
4
+ leaf: bigint;
5
+ };
6
+ /** `lib/pad.circom` PadLeaf: `Note(0, pk, blinding)`, from a reserved note index so a recovered wallet knows it. */
7
+ export declare function padNote(seed: Uint8Array, index: number): Pad;
8
+ /** Two equal pad leaves in one transaction would fingerprint it on chain. */
9
+ export declare function assertDistinctPads(...leaves: bigint[]): void;
10
+ /** The two pads of one entry, each from its own freshly reserved note index. */
11
+ export declare function padPair(seed: Uint8Array, reserve: () => number): [Pad, Pad];
12
+ /** `lib/pad.circom` DummyNull. A fresh random seed per proof: a chosen dummy could squat a pending real nullifier. */
13
+ export declare const dummyNull: (seed: bigint) => bigint;
14
+ export declare const drawDummySeed: () => bigint;
15
+ //# sourceMappingURL=pads.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pads.d.ts","sourceRoot":"","sources":["../../src/v3/pads.ts"],"names":[],"mappings":"AAQA,MAAM,MAAM,GAAG,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjE,oHAAoH;AACpH,wBAAgB,OAAO,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,GAAG,GAAG,CAI5D;AAED,6EAA6E;AAC7E,wBAAgB,kBAAkB,CAAC,GAAG,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAE5D;AAED,gFAAgF;AAChF,wBAAgB,OAAO,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,MAAM,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAI3E;AAED,sHAAsH;AACtH,eAAO,MAAM,SAAS,GAAI,MAAM,MAAM,WAAoC,CAAC;AAE3E,eAAO,MAAM,aAAa,QAAO,MAA4D,CAAC"}
@@ -0,0 +1,25 @@
1
+ import { randomBytes } from "node:crypto";
2
+ import { poseidonHash } from "@mysten/sui/zklogin";
3
+ import { DOM_DUMMY, R } from "./domains.js";
4
+ import { deriveNoteKey } from "./notes/derive.js";
5
+ import { noteCommitment, notePk } from "./notes/keys.js";
6
+ /** `lib/pad.circom` PadLeaf: `Note(0, pk, blinding)`, from a reserved note index so a recovered wallet knows it. */
7
+ export function padNote(seed, index) {
8
+ const { sk, blinding } = deriveNoteKey(seed, index);
9
+ const pk = notePk(sk);
10
+ return { pk, blinding, leaf: noteCommitment(0n, pk, blinding) };
11
+ }
12
+ /** Two equal pad leaves in one transaction would fingerprint it on chain. */
13
+ export function assertDistinctPads(...leaves) {
14
+ if (new Set(leaves).size !== leaves.length)
15
+ throw new Error("the pads of one entry repeat a leaf");
16
+ }
17
+ /** The two pads of one entry, each from its own freshly reserved note index. */
18
+ export function padPair(seed, reserve) {
19
+ const pads = [padNote(seed, reserve()), padNote(seed, reserve())];
20
+ assertDistinctPads(pads[0].leaf, pads[1].leaf);
21
+ return pads;
22
+ }
23
+ /** `lib/pad.circom` DummyNull. A fresh random seed per proof: a chosen dummy could squat a pending real nullifier. */
24
+ export const dummyNull = (seed) => poseidonHash([DOM_DUMMY, seed]);
25
+ export const drawDummySeed = () => BigInt(`0x${randomBytes(32).toString("hex")}`) % R;
@@ -17,7 +17,7 @@ export declare const sha256Hex: (bytes: Uint8Array) => string;
17
17
  /** Downloads one artifact and refuses it unless its sha256 is the pinned one. */
18
18
  export declare function fetchPinned(fetch: Fetch, url: string, sha256: string): Promise<Uint8Array>;
19
19
  /** Circuits `Essey` proves. Each value is the public URL and the sha256 `fetchPinned` checks. */
20
- export declare const SDK_CIRCUITS: readonly ["membership", "deposit", "js4", "coll_lock", "health", "loan_offer", "loan_settle", "loan_repay", "reclaim", "reclaim_coll", "loan_refi", "lock_bid", "sale_settle", "item_claim"];
20
+ export declare const SDK_CIRCUITS: readonly ["membership", "deposit", "js4", "coll_lock", "health", "loan_offer", "loan_settle", "loan_repay", "reclaim", "reclaim_coll", "loan_refi", "lock_bid", "sale_settle", "item_claim", "funds_read"];
21
21
  export type PinnedArtifact = {
22
22
  url: string;
23
23
  sha256: string;
@@ -1 +1 @@
1
- {"version":3,"file":"prover.d.ts","sourceRoot":"","sources":["../../src/v3/prover.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,uEAAuE;AACvE,MAAM,MAAM,SAAS,GAAG;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,UAAU,CAAA;CAAE,CAAC;AAE/D,+EAA+E;AAC/E,MAAM,MAAM,aAAa,GAAG;IAC1B,SAAS,CAAC,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACrF,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG;IAAE,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;CAAE,CAAC;AAEtF,eAAO,MAAM,SAAS,GAAI,OAAO,UAAU,WAAqD,CAAC;AAEjG,iFAAiF;AACjF,wBAAsB,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG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U,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACrF,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG;IAAE,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;CAAE,CAAC;AAEtF,eAAO,MAAM,SAAS,GAAI,OAAO,UAAU,WAAqD,CAAC;AAEjG,iFAAiF;AACjF,wBAAsB,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAchG;AAED,iGAAiG;AACjG,eAAO,MAAM,YAAY,4MAgBf,CAAC;AAEX,MAAM,MAAM,cAAc,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAS7D,kFAAkF;AAClF,wBAAgB,WAAW,CACzB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,OAAO,EAAE,MAAM,GACd;IAAE,IAAI,EAAE,cAAc,CAAC;IAAC,IAAI,EAAE,cAAc,CAAA;CAAE,CAIhD;AAED,2EAA2E;AAC3E,wBAAsB,oBAAoB,CACxC,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,SAAS,CAAC,CAOpB;AAED,kEAAkE;AAClE,wBAAgB,aAAa,CAC3B,MAAM,EAAE,aAAa,EACrB,SAAS,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,SAAS,CAAC,GACjD,MAAM,CAcR"}
package/dist/v3/prover.js CHANGED
@@ -35,6 +35,7 @@ export const SDK_CIRCUITS = [
35
35
  "lock_bid",
36
36
  "sale_settle",
37
37
  "item_claim",
38
+ "funds_read",
38
39
  ];
39
40
  function pinnedFile(value, what) {
40
41
  const row = value;
@@ -1,58 +1,63 @@
1
1
  import { type FeeCommitInput } from "../fees.ts";
2
2
  import type { CircuitInput } from "../inputs.ts";
3
3
  export type PlanParams = {
4
- /** `SaleRoom` as read from chain: its `sale_key`, both commits, and each `BidEntry` in seq order. */
4
+ /** `SaleRoom` as read from chain. */
5
5
  room: {
6
6
  saleKey: bigint;
7
- boundsCommit: bigint;
7
+ postedCommit: bigint;
8
8
  sellerCommit: bigint;
9
- bids: {
10
- commit: bigint;
11
- lock: bigint;
12
- active: boolean;
13
- }[];
14
- /**
15
- * `SaleRoom.pick`: `finish` opens that slot alone (`sale_room.move:712-716`). `null` with no active bid is the
16
- * no-winner finish. `"legacy"` is a room of a previous sale package, whose `finish` opens every active bid.
17
- */
18
- pick: number | null | "legacy";
19
9
  };
20
- /** The decrypted sealed bid of each seq; absent where decryption gave nothing. Only the pick's is read. */
21
- plains: (Uint8Array | undefined)[];
10
+ /** The posted price and its salt `s*`, which open `posted_commit`. */
11
+ price: bigint;
12
+ postSalt: bigint;
22
13
  seller: {
23
14
  sellerSk: bigint;
24
15
  sellerSecret: bigint;
25
16
  };
26
- bounds: {
27
- lo: bigint;
28
- hi: bigint;
29
- salt: bigint;
17
+ /** One bid lock the seller's scan opened (`offer-payload.ts` scanLocks with `bidOpen`). */
18
+ bid: {
19
+ ownerPk: bigint;
20
+ ns: bigint;
21
+ b: bigint;
22
+ amount: bigint;
23
+ unlockS: bigint;
30
24
  };
31
- /** `[seller note, fee note]`, the order `finish` hands `room_insert`. */
32
- encs: [Uint8Array, Uint8Array];
25
+ lock: {
26
+ root: bigint;
27
+ index: bigint;
28
+ path: bigint[];
29
+ };
30
+ pad: {
31
+ pk: bigint;
32
+ blinding: bigint;
33
+ };
34
+ dummySeed: bigint;
35
+ /** `[seller note, fee note, change, pad]`, the order `finish` hands `room_apply`. */
36
+ encs: Uint8Array[];
33
37
  fee: FeeCommitInput;
34
38
  eph: bigint;
35
39
  };
36
40
  /** The `u256` arguments of `sale_room::finish`, under Move's own names and in its order. */
37
41
  export type SettleStatement = {
42
+ root: bigint;
43
+ n_lock: bigint;
44
+ n_dummy: bigint;
38
45
  seller_out: bigint;
39
46
  fee_out: bigint;
40
- residual: bigint;
47
+ change: bigint;
41
48
  item_claim: bigint;
42
- win_null: bigint;
49
+ pad: bigint;
43
50
  eph_x: bigint;
44
51
  eph_y: bigint;
45
52
  fee_ct: bigint;
46
53
  fee_commit: bigint;
47
54
  };
48
55
  /**
49
- * Witness for `circuits/v3/sale_settle/sale_settle.circom`. Public signals, in order: hSet, hLock, hCtx, hOut.
50
- * `slash` lists the opened bids whose plaintext does not open their commit and lock: the pick, or in a legacy room
51
- * any active bid, which the witness then leaves out of the mask. Either way it proves only once each is slashed.
52
- * hCtx carries relayer `NO_ADDRESS` and fee 0, the only pair `sale_room::finish` rebuilds.
56
+ * Witness for `circuits/v3/sale_settle/sale_settle.circom` (Z1 freeze §3.5). Public signals, in order: root, nLock,
57
+ * nDummy, hCtx, hOut. hCtx carries relayer `NO_ADDRESS` and fee 0, the only pair `sale_room::finish` rebuilds. The
58
+ * buyer's change is a note under its bid key with a blind only its `ns` opens, so the seller cannot spend it.
53
59
  */
54
60
  export declare function plan(p: PlanParams): Promise<{
55
- slash: number[];
56
61
  input: CircuitInput;
57
62
  publics: bigint[];
58
63
  statement: SettleStatement;
@@ -1 +1 @@
1
- {"version":3,"file":"auctioneer.d.ts","sourceRoot":"","sources":["../../../src/v3/sales/auctioneer.ts"],"names":[],"mappings":"AAMA,OAAO,EAAW,KAAK,cAAc,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAUjD,MAAM,MAAM,UAAU,GAAG;IACvB,qGAAqG;IACrG,IAAI,EAAE;QACJ,OAAO,EAAE,MAAM,CAAC;QAChB,YAAY,EAAE,MAAM,CAAC;QACrB,YAAY,EAAE,MAAM,CAAC;QACrB,IAAI,EAAE;YAAE,MAAM,EAAE,MAAM,CAAC;YAAC,IAA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AM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAYF;;;;GAIG;AACH,wBAAsB,IAAI,CAAC,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC;IACjD,KAAK,EAAE,YAAY,CAAC;IACpB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,SAAS,EAAE,eAAe,CAAC;IAC3B,+EAA+E;IAC/E,UAAU,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;CACjD,CAAC,CA4ED"}
@@ -1,107 +1,70 @@
1
1
  import { poseidonHash } from "@mysten/sui/zklogin";
2
2
  import { addrField } from "../addr-field.js";
3
- import { DOM_BOUNDS, DOM_DUMMY, DOM_LNULL, DOM_SBLIND, DOM_SELLER } from "../domains.js";
3
+ import { DOM_RBLIND, DOM_SBLIND, DOM_SELLER } from "../domains.js";
4
4
  import { NO_ADDRESS } from "../ext.js";
5
5
  import { feeWitness } from "../fee-witness.js";
6
- import { feeLane } from "../fees.js";
6
+ import { flatFeeLane, minHiddenBase } from "../fees.js";
7
+ import { lock5 } from "../locks.js";
7
8
  import { noteCommitment, notePk } from "../notes/keys.js";
8
- import { itemClaimCommit, noWinnerSalt, winnerSalt } from "./claim.js";
9
- import { encHash, lock4, openBid, padSlots, residualLock } from "./rows.js";
10
- /** `sale_settle.circom` VERSION and RULE_HIGHEST, the constants `rows::fold_settle_ctx` folds. */
11
- const VERSION = 3n;
12
- const RULE_HIGHEST = 1n;
13
- /** AuctionCore rule 1: the highest value in [lo, hi] wins, the earliest seq on a tie. -1 is no winner. */
14
- function pickWinner(opened, lo, hi) {
15
- let winner = -1;
16
- opened.forEach((o, i) => {
17
- if (!o || o.v < lo || o.v > hi)
18
- return;
19
- if (winner < 0 || o.v > opened[winner].v)
20
- winner = i;
21
- });
22
- return winner;
23
- }
24
- function winnerBranch(roomField, won) {
25
- return {
26
- residual: residualLock(roomField, won.ownerPk, won.ns, won.amount - won.v).lock,
27
- item_claim: itemClaimCommit(won.ownerPk, winnerSalt(won.ns)),
28
- win_null: lock4(roomField, won.ownerPk, won.ns, won.amount, won.b).nullifier,
29
- };
30
- }
31
- /** C §4.4, §4.6: with no winner the residual is a zero lock and the item claim is the seller's. */
32
- function dummyBranch(roomField, sellerPk, sellerSecret) {
33
- const ns = poseidonHash([DOM_DUMMY, sellerSecret]);
34
- const b = poseidonHash([DOM_DUMMY, poseidonHash([sellerSecret, roomField])]);
35
- return {
36
- residual: lock4(roomField, sellerPk, ns, 0n, b).lock,
37
- item_claim: itemClaimCommit(sellerPk, noWinnerSalt(sellerSecret, roomField)),
38
- win_null: poseidonHash([DOM_LNULL, poseidonHash([DOM_DUMMY, sellerSecret, roomField])]),
39
- };
40
- }
41
- /** The slots `finish` opens; refuses what `sale_room::settle_mask` would abort on. */
42
- function readable(room) {
43
- const { bids, pick } = room;
44
- if (pick === "legacy")
45
- return (i) => bids[i].active;
46
- if (pick === null) {
47
- if (bids.some((b) => b.active))
48
- throw new Error("refused: draw the pick first (finish aborts 44_040)");
49
- return () => false;
50
- }
51
- if (!Number.isInteger(pick) || !bids[pick]?.active)
52
- throw new Error("the pick is not an active bid");
53
- return (i) => i === pick;
54
- }
9
+ import { dummyNull } from "../pads.js";
10
+ import { itemClaimCommit, winnerSalt } from "./claim.js";
11
+ import { postedCommit } from "./listing.js";
12
+ import { encHash } from "./rows.js";
13
+ /** `sale_settle.circom` VERSION (4 since Z1), the constant `rows::fold_settle_ctx` folds. */
14
+ const VERSION = 4n;
15
+ const LEVELS = 20;
16
+ const rootOf = (leaf, index, path) => path.reduce((node, sib, k) => ((index >> BigInt(k)) & 1n ? poseidonHash([sib, node]) : poseidonHash([node, sib])), leaf);
17
+ const refuse = (why) => {
18
+ throw new Error(`refused: ${why}`);
19
+ };
55
20
  /**
56
- * Witness for `circuits/v3/sale_settle/sale_settle.circom`. Public signals, in order: hSet, hLock, hCtx, hOut.
57
- * `slash` lists the opened bids whose plaintext does not open their commit and lock: the pick, or in a legacy room
58
- * any active bid, which the witness then leaves out of the mask. Either way it proves only once each is slashed.
59
- * hCtx carries relayer `NO_ADDRESS` and fee 0, the only pair `sale_room::finish` rebuilds.
21
+ * Witness for `circuits/v3/sale_settle/sale_settle.circom` (Z1 freeze §3.5). Public signals, in order: root, nLock,
22
+ * nDummy, hCtx, hOut. hCtx carries relayer `NO_ADDRESS` and fee 0, the only pair `sale_room::finish` rebuilds. The
23
+ * buyer's change is a note under its bid key with a blind only its `ns` opens, so the seller cannot spend it.
60
24
  */
61
25
  export async function plan(p) {
62
- const { room, bounds } = p;
63
- const { sellerSecret } = p.seller;
64
- const sellerPk = notePk(p.seller.sellerSk);
65
- if (poseidonHash([DOM_BOUNDS, bounds.lo, bounds.hi, bounds.salt]) !== room.boundsCommit)
66
- throw new Error("the bounds do not open this room");
67
- if (poseidonHash([DOM_SELLER, sellerPk, poseidonHash([sellerSecret])]) !== room.sellerCommit)
68
- throw new Error("the seller keys do not open this room");
69
- const commits = padSlots(room.bids.map((b) => b.commit));
70
- const locks = padSlots(room.bids.map((b) => b.lock));
71
- const read = readable(room);
72
- const opened = room.bids.map((b, i) => read(i) ? openBid(p.plains[i], room.saleKey, b.commit, b.lock) : undefined);
73
- const slash = room.bids.flatMap((_, i) => (read(i) && !opened[i] ? [i] : []));
74
- const activeMask = typeof room.pick === "number"
75
- ? 1n << BigInt(room.pick)
76
- : opened.reduce((m, o, i) => (o ? m | (1n << BigInt(i)) : m), 0n);
77
- const w = pickWinner(opened, bounds.lo, bounds.hi);
78
- const won = opened[w];
79
- const price = won?.v ?? 0n;
80
- const lane = await feeLane({ ...p.fee, base: price, eph: p.eph });
81
- const branch = won ? winnerBranch(room.saleKey, won) : dummyBranch(room.saleKey, sellerPk, sellerSecret);
82
- const sBlind = poseidonHash([DOM_SBLIND, sellerSecret, room.saleKey]);
26
+ const { room, bid, seller } = p;
27
+ const sellerPk = notePk(seller.sellerSk);
28
+ if (postedCommit({ price: p.price, salt: p.postSalt }) !== room.postedCommit)
29
+ refuse("the price does not open this room's posted commit");
30
+ if (poseidonHash([DOM_SELLER, sellerPk, poseidonHash([seller.sellerSecret])]) !== room.sellerCommit)
31
+ refuse("the seller keys do not open this room");
32
+ if (p.price < minHiddenBase(p.fee))
33
+ refuse("the price is under 10 x the flat fee (no witness)");
34
+ if (bid.amount < p.price)
35
+ refuse("the bid does not cover the price");
36
+ if (p.lock.path.length !== LEVELS)
37
+ refuse("a lock path is 20 levels");
38
+ if (p.encs.length !== 4)
39
+ refuse("finish carries 4 ciphertexts");
40
+ const w = lock5({ field: room.saleKey, ...bid });
41
+ if (rootOf(w.lock, p.lock.index, p.lock.path) !== p.lock.root)
42
+ refuse("the bid lock is not under root");
43
+ const lane = await flatFeeLane({ ...p.fee, base: p.price, eph: p.eph });
44
+ const sBlind = poseidonHash([DOM_SBLIND, seller.sellerSecret, room.saleKey]);
45
+ const relayerField = addrField(NO_ADDRESS);
46
+ const enc = encHash(p.encs);
83
47
  const statement = {
84
- seller_out: noteCommitment(price - lane.fee, sellerPk, sBlind),
48
+ root: p.lock.root,
49
+ n_lock: w.nullifier,
50
+ n_dummy: dummyNull(p.dummySeed),
51
+ seller_out: noteCommitment(p.price - lane.fee, sellerPk, sBlind),
85
52
  fee_out: lane.fee_note,
86
- ...branch,
53
+ change: noteCommitment(bid.amount - p.price, bid.ownerPk, poseidonHash([DOM_RBLIND, bid.ns])),
54
+ item_claim: itemClaimCommit(bid.ownerPk, winnerSalt(bid.ns)),
55
+ pad: noteCommitment(0n, p.pad.pk, p.pad.blinding),
87
56
  eph_x: lane.ephX,
88
57
  eph_y: lane.ephY,
89
58
  fee_ct: lane.fee_ct,
90
59
  fee_commit: lane.fee_commit,
91
60
  };
92
- const n = BigInt(room.bids.length);
93
- const relayerField = addrField(NO_ADDRESS);
94
- const enc = encHash(p.encs);
95
61
  const s = statement;
96
62
  const hCtx = poseidonHash([
97
- n,
98
- activeMask,
99
- room.boundsCommit,
63
+ VERSION,
64
+ room.postedCommit,
100
65
  room.sellerCommit,
101
66
  lane.fee_commit,
102
- RULE_HIGHEST,
103
67
  room.saleKey,
104
- VERSION,
105
68
  relayerField,
106
69
  0n,
107
70
  enc,
@@ -109,39 +72,35 @@ export async function plan(p) {
109
72
  const hOut = poseidonHash([
110
73
  s.seller_out,
111
74
  s.fee_out,
112
- s.residual,
75
+ s.change,
113
76
  s.item_claim,
114
- s.win_null,
77
+ s.pad,
115
78
  s.eph_x,
116
79
  s.eph_y,
117
80
  s.fee_ct,
118
81
  ]);
119
82
  const input = {
120
- commits: commits.map(String),
121
- locks: locks.map(String),
122
- values: padSlots(opened.map((o) => o?.v ?? 0n)).map(String),
123
- salts: padSlots(opened.map((o) => o?.s ?? 0n)).map(String),
124
- n: n.toString(),
125
- activeMask: activeMask.toString(),
126
- lo: bounds.lo.toString(),
127
- hi: bounds.hi.toString(),
128
- boundsSalt: bounds.salt.toString(),
129
- hasWinner: won ? "1" : "0",
130
- winner: won ? w.toString() : "0",
131
- price: price.toString(),
132
- amount_w: (won?.amount ?? 0n).toString(),
133
- ownerPk_w: (won?.ownerPk ?? 0n).toString(),
134
- ns_w: (won?.ns ?? 0n).toString(),
135
- b_w: (won?.b ?? 0n).toString(),
136
- sellerPk: sellerPk.toString(),
137
- sellerSecret: sellerSecret.toString(),
83
+ price: p.price.toString(),
84
+ postSalt: p.postSalt.toString(),
138
85
  roomField: room.saleKey.toString(),
139
- ...feeWitness(p.fee, price, p.eph, lane),
86
+ sellerPk: sellerPk.toString(),
87
+ sellerSecret: seller.sellerSecret.toString(),
88
+ amount_w: bid.amount.toString(),
89
+ ownerPk_w: bid.ownerPk.toString(),
90
+ ns_w: bid.ns.toString(),
91
+ b_w: bid.b.toString(),
92
+ unlock_w: bid.unlockS.toString(),
93
+ lockIndex: p.lock.index.toString(),
94
+ lockPath: p.lock.path.map(String),
95
+ root: p.lock.root.toString(),
96
+ padPk: p.pad.pk.toString(),
97
+ padBlind: p.pad.blinding.toString(),
98
+ dummySeed: p.dummySeed.toString(),
140
99
  relayerField: relayerField.toString(),
141
100
  relayer_fee: "0",
142
101
  encHash: enc.toString(),
102
+ ...feeWitness(p.fee, p.price, p.eph, lane),
143
103
  };
144
- const sellerNote = { value: price - lane.fee, blinding: sBlind };
145
- const publics = [poseidonHash(commits), poseidonHash(locks), hCtx, hOut];
146
- return { slash, input, publics, statement, sellerNote };
104
+ const publics = [p.lock.root, s.n_lock, s.n_dummy, hCtx, hOut];
105
+ return { input, publics, statement, sellerNote: { value: p.price - lane.fee, blinding: sBlind } };
147
106
  }