@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/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { COINS, parseConfig, type CoinKey, type V3Config } from "./config.ts";
2
- export { ESSEY_ERROR_CODES, EsseyError, isEsseyError, type EsseyErrorCode } from "./errors.ts";
2
+ export { ESSEY_ERROR_CODES, EsseyError, isEsseyError, RETIRED_GENERATION_PEERS, type EsseyErrorCode, } from "./errors.ts";
3
3
  export { FIXED_HEADERS, fixedHeaders } from "./network.ts";
4
4
  export { Essey, type Collected, type ConnectOptions, type Cover, type CredentialInfo, type EsseyIo, type ExitResult, type OpenQuote, type Payees, type Payout, type Pending, type Recovered, type RecoveredRecords, type Renewal, type SaleOpenTx, type SaleRecord, type SpendOptions, type Staged, } from "./essey.ts";
5
5
  export type { KeeperActions, KeeperBadge, KeeperIo, KeeperQueue, KeeperSection, KeeperVerdict, KeeperVia, Unjudged, } from "./keeper.ts";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AA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iBAAiB,EACjB,UAAU,EACV,YAAY,EACZ,wBAAwB,EACxB,KAAK,cAAc,GACpB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,EACL,KAAK,EACL,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,KAAK,KAAK,EACV,KAAK,cAAc,EACnB,KAAK,OAAO,EACZ,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,MAAM,EACX,KAAK,MAAM,EACX,KAAK,OAAO,EACZ,KAAK,SAAS,EACd,KAAK,gBAAgB,EACrB,KAAK,OAAO,EACZ,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,MAAM,GACZ,MAAM,YAAY,CAAC;AACpB,YAAY,EACV,aAAa,EACb,WAAW,EACX,QAAQ,EACR,WAAW,EACX,aAAa,EACb,aAAa,EACb,SAAS,EACT,QAAQ,GACT,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACrF,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAClF,YAAY,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACvD,YAAY,EACV,WAAW,EACX,cAAc,EACd,UAAU,EACV,UAAU,EACV,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,QAAQ,EACR,gBAAgB,EAChB,cAAc,EACd,cAAc,GACf,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,MAAM,eAAe,CAAC"}
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export { COINS, parseConfig } from "./config.js";
2
- export { ESSEY_ERROR_CODES, EsseyError, isEsseyError } from "./errors.js";
2
+ export { ESSEY_ERROR_CODES, EsseyError, isEsseyError, RETIRED_GENERATION_PEERS, } from "./errors.js";
3
3
  export { FIXED_HEADERS, fixedHeaders } from "./network.js";
4
4
  export { Essey, } from "./essey.js";
5
5
  export * as v3 from "./v3/index.js";
@@ -1,9 +1,15 @@
1
1
  import type { CoinKey } from "../../config.ts";
2
2
  import { type Proved, type RelayBody } from "../bodies.ts";
3
- import type { SeizeEncs } from "./ext.ts";
3
+ import type { Encs4 } from "./ext.ts";
4
4
  import type { HealthStatement } from "./health.ts";
5
5
  type Args = Record<string, string>;
6
- /** What a CollLock proof spends and makes: `note` is the collateral note at open and the added note in a top-up. */
6
+ type Rename = (name: string) => string;
7
+ /** `pads.ts` assertDistinctPads, as the body refusal every hidden entry shares. */
8
+ export declare function distinctPads(...pads: bigint[]): void;
9
+ /**
10
+ * What a CollLock proof spends and makes: `note` is the collateral note at open and the added note in a top-up.
11
+ * `pad0`, `pad1` are the padded circuit's two zero notes (freeze ruling Q1).
12
+ */
7
13
  export type CollLockSpend = {
8
14
  root: bigint;
9
15
  n0: bigint;
@@ -11,6 +17,8 @@ export type CollLockSpend = {
11
17
  note: bigint;
12
18
  change: bigint;
13
19
  feeNote: bigint;
20
+ pad0: bigint;
21
+ pad1: bigint;
14
22
  ephX: bigint;
15
23
  ephY: bigint;
16
24
  feeCt: bigint;
@@ -24,36 +32,37 @@ export type HealthBody = {
24
32
  statement: HealthStatement;
25
33
  wait: boolean;
26
34
  };
35
+ /** Z1-LEAF-MAP.md: every collateral entry hands `pool::room_apply` four ciphertexts, `enc0..enc3` in leaf order. */
36
+ export declare function encArgs(encs: Encs4): Args;
37
+ export declare function healthArgs(s: HealthStatement, key?: Rename): Args;
27
38
  /**
28
- * The `liquidation::lock_collateral` slice of a `loan_open` envelope (`liquidation.move:62-87`): the CollLock
29
- * spend, the keeper ciphertext, the claimed price and the Health OPEN rows. The request half is the loans module's.
39
+ * The `liquidation::lock_collateral` slice of a `loan_open` envelope: the padded CollLock spend, the four inserted
40
+ * ciphertexts `[change, fee_note, pad0, pad1]`, the keeper ciphertext, the claimed price and the Health OPEN rows.
41
+ * The request half is the loans module's.
30
42
  */
31
43
  export declare function openLockArgs(p: {
32
44
  lock: CollLockSpend;
33
- encs: [Uint8Array, Uint8Array];
45
+ encs: Encs4;
34
46
  keeperCt: Uint8Array;
35
47
  pClaim: bigint;
36
48
  statement: HealthStatement;
37
49
  priceUpdate: Uint8Array;
38
50
  }): Args;
39
- /** `encs` pairs with `[out0, fee_note]`. */
51
+ /** `encs` pairs with `[out0, fee_note, out1, out2]`. */
40
52
  export declare function release(p: HealthBody & {
41
- encs: [Uint8Array, Uint8Array];
53
+ encs: Encs4;
42
54
  }): RelayBody;
43
55
  export declare function heartbeat(p: HealthBody & {
44
- encs: [Uint8Array, Uint8Array];
56
+ encs: Encs4;
45
57
  expiryMs: bigint;
46
58
  priceUpdate: Uint8Array;
47
- /** DECISION-R1-MIGRATION A: a retired-package loan, whose pre-R1 `heartbeat` still takes bucket `k` 1. */
48
- retired?: boolean;
49
59
  }): RelayBody;
50
- /** `lockEncs` pairs with the spend's `[change, fee_note]`, `encs` with the re-locked `[out0, fee_note]`. */
60
+ /** `encs` pairs with the top-up's inserted `[change, out0, pad0, pad1]` (Z1-LEAF-MAP.md, top-up row). */
51
61
  export declare function topup(p: HealthBody & {
52
62
  lock: CollLockSpend;
53
63
  lockProved: Proved;
54
- lockEncs: [Uint8Array, Uint8Array];
55
64
  keeperCt: Uint8Array;
56
- encs: [Uint8Array, Uint8Array];
65
+ encs: Encs4;
57
66
  }): RelayBody;
58
67
  /** `loan_topup_borrower`: the borrower pass (proof 0, `tag`, `expiryMs`, `passN0`), then `topup` unchanged. */
59
68
  export declare function topupBorrower(p: Parameters<typeof topup>[0] & {
@@ -65,7 +74,7 @@ export declare function topupBorrower(p: Parameters<typeof topup>[0] & {
65
74
  };
66
75
  }): RelayBody;
67
76
  type SeizeBody = HealthBody & {
68
- encs: SeizeEncs;
77
+ encs: Encs4;
69
78
  pSpot: bigint;
70
79
  pEma: bigint;
71
80
  priceUpdate: Uint8Array;
@@ -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S,CAaX;AAED,KAAK,SAAS,GAAG,UAAU,GAAG;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,UAAU,CAAA;CAAE,CAAC;AAYpG,eAAO,MAAM,SAAS,GAAI,GAAG,SAAS,KAAG,SACkB,CAAC;AAE5D,eAAO,MAAM,cAAc,GAAI,GAAG,SAAS,KAAG,SACmB,CAAC;AAElE,eAAO,MAAM,YAAY,GAAI,GAAG,SAAS,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,KAAG,SACkC,CAAC"}
@@ -3,18 +3,23 @@ import { address } from "../../network.js";
3
3
  import { wireProof } from "../bodies.js";
4
4
  import { assertU64 } from "../fees.js";
5
5
  import { ENC_BYTES, VK } from "../kinds.js";
6
+ import { assertDistinctPads } from "../pads.js";
6
7
  import { COVER_STEP_MS } from "./math.js";
7
8
  const OUTS = ["out0", "out1", "out2", "feeNote"];
8
- const DELIVERY = ["ephX", "ephY", "feeCt", "lEx", "lEy", "lCt"];
9
+ const DELIVERY = ["ephX", "ephY", "feeCt", "lEx", "lEy", "lCt", "nDummy0", "nDummy1"];
10
+ /** `pads.ts` assertDistinctPads, as the body refusal every hidden entry shares. */
11
+ export function distinctPads(...pads) {
12
+ try {
13
+ assertDistinctPads(...pads);
14
+ }
15
+ catch (err) {
16
+ throw new EsseyError("INVALID_ARGUMENT", err.message);
17
+ }
18
+ }
9
19
  const invalid = (what) => {
10
20
  throw new EsseyError("INVALID_ARGUMENT", what);
11
21
  };
12
22
  const hex = (bytes) => `0x${Buffer.from(bytes).toString("hex")}`;
13
- function enc(bytes, what) {
14
- if (bytes.length !== ENC_BYTES)
15
- invalid(`${what} is not a 128-byte note ciphertext`);
16
- return hex(bytes);
17
- }
18
23
  function u64(value, what) {
19
24
  try {
20
25
  assertU64(what, value);
@@ -25,15 +30,26 @@ function u64(value, what) {
25
30
  return value.toString();
26
31
  }
27
32
  const prefixed = (prefix) => (name) => `${prefix}${name[0].toUpperCase()}${name.slice(1)}`;
28
- function healthArgs(s, key = (name) => name) {
29
- if (s.outs.length !== OUTS.length || s.delivery.length !== DELIVERY.length)
30
- invalid("a health statement has 4 outs and 6 delivery rows");
33
+ /** Z1-LEAF-MAP.md: every collateral entry hands `pool::room_apply` four ciphertexts, `enc0..enc3` in leaf order. */
34
+ export function encArgs(encs) {
35
+ if (encs?.length !== 4)
36
+ invalid("a collateral entry carries 4 note ciphertexts");
37
+ return Object.fromEntries(encs.map((e, i) => {
38
+ if (e.length !== ENC_BYTES)
39
+ invalid(`enc${i} is not a 128-byte note ciphertext`);
40
+ return [`enc${i}`, hex(e)];
41
+ }));
42
+ }
43
+ export function healthArgs(s, key = (name) => name) {
44
+ if (s.outs?.length !== OUTS.length || s.delivery?.length !== DELIVERY.length)
45
+ invalid("a health statement has 4 outs and 8 delivery rows");
31
46
  return Object.fromEntries([
32
47
  ...OUTS.map((name, i) => [key(name), s.outs[i].toString()]),
33
48
  ...DELIVERY.map((name, i) => [key(name), s.delivery[i].toString()]),
34
49
  ]);
35
50
  }
36
- function lockArgs(lock, noteKey, encs) {
51
+ function lockArgs(lock, noteKey) {
52
+ distinctPads(lock.pad0, lock.pad1);
37
53
  return {
38
54
  root: lock.root.toString(),
39
55
  nullifier0: lock.n0.toString(),
@@ -41,11 +57,11 @@ function lockArgs(lock, noteKey, encs) {
41
57
  [noteKey]: lock.note.toString(),
42
58
  change: lock.change.toString(),
43
59
  feeNote: lock.feeNote.toString(),
60
+ pad0: lock.pad0.toString(),
61
+ pad1: lock.pad1.toString(),
44
62
  ephX: lock.ephX.toString(),
45
63
  ephY: lock.ephY.toString(),
46
64
  feeCt: lock.feeCt.toString(),
47
- encChange: enc(encs[0], "encChange"),
48
- encFee: enc(encs[1], "encFee"),
49
65
  };
50
66
  }
51
67
  function body(kind, p, proofs, args) {
@@ -61,47 +77,41 @@ function body(kind, p, proofs, args) {
61
77
  }
62
78
  const healthProof = (p) => wireProof(VK.health, p.proved);
63
79
  /**
64
- * The `liquidation::lock_collateral` slice of a `loan_open` envelope (`liquidation.move:62-87`): the CollLock
65
- * spend, the keeper ciphertext, the claimed price and the Health OPEN rows. The request half is the loans module's.
80
+ * The `liquidation::lock_collateral` slice of a `loan_open` envelope: the padded CollLock spend, the four inserted
81
+ * ciphertexts `[change, fee_note, pad0, pad1]`, the keeper ciphertext, the claimed price and the Health OPEN rows.
82
+ * The request half is the loans module's.
66
83
  */
67
84
  export function openLockArgs(p) {
68
85
  return {
69
- ...lockArgs(p.lock, "collNote", p.encs),
86
+ ...lockArgs(p.lock, "collNote"),
87
+ ...encArgs(p.encs),
70
88
  keeperCt: hex(p.keeperCt),
71
89
  pClaim: u64(p.pClaim, "pClaim"),
72
90
  ...healthArgs(p.statement, prefixed("open")),
73
91
  priceUpdate: hex(p.priceUpdate),
74
92
  };
75
93
  }
76
- /** `encs` pairs with `[out0, fee_note]`. */
94
+ /** `encs` pairs with `[out0, fee_note, out1, out2]`. */
77
95
  export function release(p) {
78
- return body("loan_release", p, [healthProof(p)], {
79
- ...healthArgs(p.statement),
80
- encOut: enc(p.encs[0], "encOut"),
81
- encFee: enc(p.encs[1], "encFee"),
82
- });
96
+ return body("loan_release", p, [healthProof(p)], { ...healthArgs(p.statement), ...encArgs(p.encs) });
83
97
  }
84
98
  export function heartbeat(p) {
85
99
  if (p.expiryMs % COVER_STEP_MS !== 0n)
86
100
  invalid("expiryMs is not on the 5-minute cover step");
87
- return body(p.retired ? "loan_heartbeat_previous" : "loan_heartbeat", p, [healthProof(p)], {
101
+ return body("loan_heartbeat", p, [healthProof(p)], {
88
102
  ...healthArgs(p.statement),
89
- encOut: enc(p.encs[0], "encOut"),
90
- encFee: enc(p.encs[1], "encFee"),
91
- ...(p.retired ? { k: "1" } : {}),
103
+ ...encArgs(p.encs),
92
104
  expiryMs: u64(p.expiryMs, "expiryMs"),
93
105
  priceUpdate: hex(p.priceUpdate),
94
106
  });
95
107
  }
96
- /** `lockEncs` pairs with the spend's `[change, fee_note]`, `encs` with the re-locked `[out0, fee_note]`. */
108
+ /** `encs` pairs with the top-up's inserted `[change, out0, pad0, pad1]` (Z1-LEAF-MAP.md, top-up row). */
97
109
  export function topup(p) {
98
- const toppedUp = prefixed("topup");
99
110
  return body("loan_topup", p, [wireProof(VK.collLock, p.lockProved), healthProof(p)], {
100
- ...lockArgs(p.lock, "addNote", p.lockEncs),
111
+ ...lockArgs(p.lock, "addNote"),
101
112
  keeperCt: hex(p.keeperCt),
102
- ...healthArgs(p.statement, toppedUp),
103
- [toppedUp("encOut")]: enc(p.encs[0], "encOut"),
104
- [toppedUp("encFee")]: enc(p.encs[1], "encFee"),
113
+ ...healthArgs(p.statement, prefixed("topup")),
114
+ ...encArgs(p.encs),
105
115
  });
106
116
  }
107
117
  /** `loan_topup_borrower`: the borrower pass (proof 0, `tag`, `expiryMs`, `passN0`), then `topup` unchanged. */
@@ -122,10 +132,7 @@ export function topupBorrower(p) {
122
132
  function seizeArgs(p) {
123
133
  return {
124
134
  ...healthArgs(p.statement),
125
- encLender: enc(p.encs[0], "encLender"),
126
- encFee: enc(p.encs[1], "encFee"),
127
- encBorrower: enc(p.encs[2], "encBorrower"),
128
- encKeeper: enc(p.encs[3], "encKeeper"),
135
+ ...encArgs(p.encs),
129
136
  pSpot: u64(p.pSpot, "pSpot"),
130
137
  pEma: u64(p.pEma, "pEma"),
131
138
  priceUpdate: hex(p.priceUpdate),
@@ -4,18 +4,23 @@ export type LoanIds = {
4
4
  poolC: string;
5
5
  market: string;
6
6
  };
7
- /** `liquidation::open_ext`: the keeper ciphertext, then the CollLock spend's two note ciphertexts. */
8
- export declare const openExt: (ids: LoanIds, keeperCt: Uint8Array, encChange: Uint8Array, encFee: Uint8Array) => bigint;
9
- /** `encs` pairs with `[out0, fee_note]`, the order `room_insert` takes them. */
10
- export declare const releaseExt: (ids: LoanIds, encs: [Uint8Array, Uint8Array]) => bigint;
11
- export declare const heartbeatExt: (ids: LoanIds, encs: [Uint8Array, Uint8Array]) => bigint;
12
- /** `liquidation::topup_ext`: the new keeper ciphertext, the spend's `[change, fee_note]`, then the re-locked pair. */
13
- export declare const topupExt: (ids: LoanIds, keeperCt: Uint8Array, encChange: Uint8Array, encFee: Uint8Array, encs: [Uint8Array, Uint8Array]) => bigint;
7
+ /**
8
+ * The four note ciphertexts of one collateral entry, in the leaf order `pool::room_apply` takes them
9
+ * (`/root/scopes/V3-PRIVACY-CYCLE3/Z1-LEAF-MAP.md`): open `[change, fee_note, pad0, pad1]`, top-up
10
+ * `[change, out0, pad0, pad1]`, every Health-only entry `[out0, fee_note, out1, out2]`.
11
+ */
12
+ export type Encs4 = [Uint8Array, Uint8Array, Uint8Array, Uint8Array];
13
+ /** Kept for the seizure callers: a seizure's four are lender, fee, borrower, keeper. */
14
+ export type SeizeEncs = Encs4;
15
+ /** `liquidation::open_ext`: the keeper ciphertext, then the four inserted ciphertexts. */
16
+ export declare const openExt: (ids: LoanIds, keeperCt: Uint8Array, encs: Encs4) => bigint;
17
+ export declare const releaseExt: (ids: LoanIds, encs: Encs4) => bigint;
18
+ export declare const heartbeatExt: (ids: LoanIds, encs: Encs4) => bigint;
19
+ /** `liquidation::topup_ext`: the new keeper ciphertext, then the four inserted ciphertexts. */
20
+ export declare const topupExt: (ids: LoanIds, keeperCt: Uint8Array, encs: Encs4) => bigint;
14
21
  /** `liquidation::topup_by_borrower_ext`: `topupExt`'s preimage under `HEXT_TOPUP_BY_BORROWER`. */
15
- export declare const topupByBorrowerExt: (ids: LoanIds, keeperCt: Uint8Array, encChange: Uint8Array, encFee: Uint8Array, encs: [Uint8Array, Uint8Array]) => bigint;
16
- /** A seizure inserts `[out0, fee_note, out1, out2]`: lender, fee, borrower, keeper (`liquidation.move:437`). */
17
- export type SeizeEncs = [Uint8Array, Uint8Array, Uint8Array, Uint8Array];
18
- export declare const liquidateExt: (ids: LoanIds, encs: SeizeEncs) => bigint;
19
- export declare const defaultExt: (ids: LoanIds, encs: SeizeEncs) => bigint;
20
- export declare const faultExt: (ids: LoanIds, encs: SeizeEncs) => bigint;
22
+ export declare const topupByBorrowerExt: (ids: LoanIds, keeperCt: Uint8Array, encs: Encs4) => bigint;
23
+ export declare const liquidateExt: (ids: LoanIds, encs: Encs4) => bigint;
24
+ export declare const defaultExt: (ids: LoanIds, encs: Encs4) => bigint;
25
+ export declare const faultExt: (ids: LoanIds, encs: Encs4) => bigint;
21
26
  //# sourceMappingURL=ext.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ext.d.ts","sourceRoot":"","sources":["../../../src/v3/collateral/ext.ts"],"names":[],"mappings":"AAEA,uEAAuE;AACvE,MAAM,MAAM,OAAO,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAWtE,sGAAsG;AACtG,eAAO,MAAM,OAAO,GAAI,KAAK,OAAO,EAAE,UAAU,UAAU,EAAE,WAAW,UAAU,EAAE,QAAQ,UAAU,WACjD,CAAC;AAErD,gFAAgF;AAChF,eAAO,MAAM,UAAU,GAAI,KAAK,OAAO,EAAE,MAAM,CAAC,UAAU,EAAE,UAAU,CAAC,WAAiC,CAAC;AAEzG,eAAO,MAAM,YAAY,GAAI,KAAK,OAAO,EAAE,MAAM,CAAC,UAAU,EAAE,UAAU,CAAC,WAAmC,CAAC;AAE7G,sHAAsH;AACtH,eAAO,MAAM,QAAQ,GACnB,KAAK,OAAO,EACZ,UAAU,UAAU,EACpB,WAAW,UAAU,EACrB,QAAQ,UAAU,EAClB,MAAM,CAAC,UAAU,EAAE,UAAU,CAAC,WACiC,CAAC;AAElE,kGAAkG;AAClG,eAAO,MAAM,kBAAkB,GAC7B,KAAK,OAAO,EACZ,UAAU,UAAU,EACpB,WAAW,UAAU,EACrB,QAAQ,UAAU,EAClB,MAAM,CAAC,UAAU,EAAE,UAAU,CAAC,WAC6C,CAAC;AAE9E,gHAAgH;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AM,KAAK,WAAmC,CAAC;AAE1F,eAAO,MAAM,UAAU,GAAI,KAAK,OAAO,EAAE,MAAM,KAAK,WAAiC,CAAC;AAEtF,eAAO,MAAM,QAAQ,GAAI,KAAK,OAAO,EAAE,MAAM,KAAK,WAA+B,CAAC"}
@@ -5,15 +5,14 @@ const MODE_DEFAULT = 5;
5
5
  const MODE_RELEASE = 6;
6
6
  const MODE_FAULT = 7;
7
7
  const ext = (mode, ids, cts) => healthExt(mode, ids.loan, ids.poolC, ids.market, cts);
8
- /** `liquidation::open_ext`: the keeper ciphertext, then the CollLock spend's two note ciphertexts. */
9
- export const openExt = (ids, keeperCt, encChange, encFee) => ext(MODE_OPEN, ids, [keeperCt, encChange, encFee]);
10
- /** `encs` pairs with `[out0, fee_note]`, the order `room_insert` takes them. */
8
+ /** `liquidation::open_ext`: the keeper ciphertext, then the four inserted ciphertexts. */
9
+ export const openExt = (ids, keeperCt, encs) => ext(MODE_OPEN, ids, [keeperCt, ...encs]);
11
10
  export const releaseExt = (ids, encs) => ext(MODE_RELEASE, ids, encs);
12
11
  export const heartbeatExt = (ids, encs) => ext(MODE_HEARTBEAT, ids, encs);
13
- /** `liquidation::topup_ext`: the new keeper ciphertext, the spend's `[change, fee_note]`, then the re-locked pair. */
14
- export const topupExt = (ids, keeperCt, encChange, encFee, encs) => ext(MODE_TOPUP, ids, [keeperCt, encChange, encFee, ...encs]);
12
+ /** `liquidation::topup_ext`: the new keeper ciphertext, then the four inserted ciphertexts. */
13
+ export const topupExt = (ids, keeperCt, encs) => ext(MODE_TOPUP, ids, [keeperCt, ...encs]);
15
14
  /** `liquidation::topup_by_borrower_ext`: `topupExt`'s preimage under `HEXT_TOPUP_BY_BORROWER`. */
16
- export const topupByBorrowerExt = (ids, keeperCt, encChange, encFee, encs) => ext(HEXT_TOPUP_BY_BORROWER, ids, [keeperCt, encChange, encFee, ...encs]);
15
+ export const topupByBorrowerExt = (ids, keeperCt, encs) => ext(HEXT_TOPUP_BY_BORROWER, ids, [keeperCt, ...encs]);
17
16
  export const liquidateExt = (ids, encs) => ext(MODE_LIQUIDATE, ids, encs);
18
17
  export const defaultExt = (ids, encs) => ext(MODE_DEFAULT, ids, encs);
19
18
  export const faultExt = (ids, encs) => ext(MODE_FAULT, ids, encs);
@@ -13,7 +13,7 @@ export declare const MODE: {
13
13
  readonly RELEASE: 6;
14
14
  readonly FAULT: 7;
15
15
  };
16
- export declare const HEALTH_VERSION = 1n;
16
+ export declare const HEALTH_VERSION = 2n;
17
17
  /** What `health::rows` folds for the loan: its market's decimals, its stored rates, and `loan::keeper_bps(mode)`. */
18
18
  export type HealthRisk = {
19
19
  cDec: bigint;
@@ -23,6 +23,10 @@ export type HealthRisk = {
23
23
  bonusBps: bigint;
24
24
  keeperBps: bigint;
25
25
  };
26
+ export type PadKey = {
27
+ pk: bigint;
28
+ blinding: bigint;
29
+ };
26
30
  type Common = {
27
31
  opening: CollOpening;
28
32
  risk: HealthRisk;
@@ -33,6 +37,12 @@ type Common = {
33
37
  extHash: bigint;
34
38
  fee: FeeCommitInput;
35
39
  eph: bigint;
40
+ /** Freeze §3.4 item 3: out1 and out2 outside a seizure are zero notes under these keys (never a constant leaf). */
41
+ pads: readonly [PadKey, PadKey];
42
+ /** Random per proof: their `DummyNull`s are `delivery[6..8]`, nullifiers the pool stores. */
43
+ dummySeeds: readonly [bigint, bigint];
44
+ /** Terms2's inner hash, for a prover holding only the outer terms (a keeper). TOPUP opens it from the terms. */
45
+ hRest?: bigint;
36
46
  };
37
47
  export type HealthParams = Common & ({
38
48
  mode: typeof MODE.OPEN;
@@ -51,10 +61,7 @@ export type HealthParams = Common & ({
51
61
  } | {
52
62
  mode: typeof MODE.LIQUIDATE | typeof MODE.DEFAULT | typeof MODE.FAULT;
53
63
  terms: KeeperTerms;
54
- keeper: {
55
- pk: bigint;
56
- blinding: bigint;
57
- };
64
+ keeper: PadKey;
58
65
  });
59
66
  export type HealthStatement = {
60
67
  rows: {
@@ -64,8 +71,8 @@ export type HealthStatement = {
64
71
  };
65
72
  /** The entry's `outs`: out0, out1, out2, fee_note. */
66
73
  outs: [bigint, bigint, bigint, bigint];
67
- /** The entry's `delivery`: ephX, ephY, fee_ct, lEx, lEy, lCt. */
68
- delivery: [bigint, bigint, bigint, bigint, bigint, bigint];
74
+ /** The entry's `delivery`: ephX, ephY, fee_ct, lEx, lEy, lCt, nDummy0, nDummy1. */
75
+ delivery: [bigint, bigint, bigint, bigint, bigint, bigint, bigint, bigint];
69
76
  };
70
77
  /** `notes` are the openings of out0, out1 and out2. They never go on the wire. */
71
78
  export type Health = {
@@ -83,7 +90,8 @@ export declare function seizeIsLast(leafCount: bigint, index: bigint, out: 0 | 1
83
90
  /**
84
91
  * A seizure's split of the lock (B §5.5, `health.circom:303-346`): what the seizer proves, and what the lender and the
85
92
  * borrower recompute afterwards from the claimed `p_spot` the seizing call took. FAULT seizes the whole lock and runs
86
- * the price chain on (debt 0, price 1), so pass `owed` 0 and `pSpot` 1 with it.
93
+ * the price chain on (debt 0, price 1), so pass `owed` 0 and `pSpot` 1 with it. Seizures pay no protocol fee (Erik
94
+ * FLAT-FEE row; `health.circom` `lane.base <== 0`).
87
95
  */
88
96
  export declare function seizeSplit(p: {
89
97
  owed: bigint;
@@ -91,7 +99,6 @@ export declare function seizeSplit(p: {
91
99
  pSpot: bigint;
92
100
  expo: bigint;
93
101
  risk: HealthRisk;
94
- fee: Pick<FeeCommitInput, "bps" | "min" | "max">;
95
102
  fault?: boolean;
96
103
  }): {
97
104
  prodT: bigint;
@@ -101,7 +108,6 @@ export declare function seizeSplit(p: {
101
108
  r: bigint;
102
109
  };
103
110
  seize: bigint;
104
- pf: bigint;
105
111
  prodK: bigint;
106
112
  kf: bigint;
107
113
  toLender: bigint;
@@ -1 +1 @@
1
- {"version":3,"file":"health.d.ts","sourceRoot":"","sources":["../../../src/v3/collateral/health.ts"],"names":[],"mappings":"AAKA,OAAO,EAA6D,KAAK,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5G,O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,EAAE,MAAM,CAAC,GACxC,OAAO,CAAC,MAAM,CAAC,CAGjB;AAKD,6GAA6G;AAC7G,wBAAgB,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,OAAO,CAEjF;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,UAAU,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;;;;;;;;;;;;EAQA;AAED,0GAA0G;AAC1G,wBAAgB,QAAQ,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,EAAE,IAAI,EAAE,MAAM,GAAG,UAAU,CAKzG;AAkED,4FAA4F;AAC5F,wBAAsB,MAAM,CAAC,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAqJ7D"}
@@ -2,10 +2,11 @@ import { poseidonHash } from "@mysten/sui/zklogin";
2
2
  import { EsseyError } from "../../errors.js";
3
3
  import { MODE_OPEN, MODE_TOPUP } from "../ext.js";
4
4
  import { R } from "../domains.js";
5
- import { BPS_DENOM, assertU64, ecdhBlind, feeLane, feeOf, fieldAdd } from "../fees.js";
5
+ import { BPS_DENOM, assertU64, ecdhBlind, feeLane, fieldAdd } from "../fees.js";
6
6
  import { noteCommitment } from "../notes/keys.js";
7
+ import { dummyNull } from "../pads.js";
7
8
  import { GRACE_S, collFor, overLine, valueAt } from "./math.js";
8
- import { collLockPk, outputBlind, requestCommit, termsCommit, } from "./openings.js";
9
+ import { collLockPk, outputBlind, requestCommit, termsOuter, termsRest, } from "./openings.js";
9
10
  export const MODE = {
10
11
  OPEN: MODE_OPEN,
11
12
  HEARTBEAT: 2,
@@ -15,7 +16,7 @@ export const MODE = {
15
16
  RELEASE: 6,
16
17
  FAULT: 7,
17
18
  };
18
- export const HEALTH_VERSION = 1n;
19
+ export const HEALTH_VERSION = 2n;
19
20
  /**
20
21
  * Outside TOPUP the lender delivery runs on Base8 and its rows are the identity (`health.circom:383-394`), so
21
22
  * the scalar hides nothing. This is the one every stored fixture proves with (`circuits/v3/health/ref.mjs:49`).
@@ -43,7 +44,7 @@ export async function lenderAmount(encSk, [lEx, lEy, lCt]) {
43
44
  const { sx } = await ecdhBlind(lEx, lEy, encSk);
44
45
  return (lCt - lenderMask(sx) + R) % R;
45
46
  }
46
- /** A seize inserts `[out 0, out 3, out 1, out 2]` (`move/v3/loan/sources/liquidation.move:445-446`). */
47
+ /** A seize inserts `[out 0, out 3, out 1, out 2]` (Z1-LEAF-MAP.md, seizure row). */
47
48
  const SEIZE_LEAF_AT = { 0: 0, 1: 2 };
48
49
  /** Whether the pool's last leaf is still the one closing the seize that inserted output `out` at `index`. */
49
50
  export function seizeIsLast(leafCount, index, out) {
@@ -52,17 +53,17 @@ export function seizeIsLast(leafCount, index, out) {
52
53
  /**
53
54
  * A seizure's split of the lock (B §5.5, `health.circom:303-346`): what the seizer proves, and what the lender and the
54
55
  * borrower recompute afterwards from the claimed `p_spot` the seizing call took. FAULT seizes the whole lock and runs
55
- * the price chain on (debt 0, price 1), so pass `owed` 0 and `pSpot` 1 with it.
56
+ * the price chain on (debt 0, price 1), so pass `owed` 0 and `pSpot` 1 with it. Seizures pay no protocol fee (Erik
57
+ * FLAT-FEE row; `health.circom` `lane.base <== 0`).
56
58
  */
57
59
  export function seizeSplit(p) {
58
60
  const prodT = p.owed * (BPS_DENOM + p.risk.bonusBps);
59
61
  const target = prodT / BPS_DENOM;
60
62
  const seizeR = collFor(target, p.pSpot, { cDec: p.risk.cDec, lDec: p.risk.lDec, expo: p.expo });
61
63
  const seize = p.fault || seizeR.q >= p.avail ? p.avail : seizeR.q;
62
- const pf = feeOf({ base: seize, bps: p.fee.bps, min: p.fee.min, max: p.fee.max }).fee;
63
64
  const prodK = seize * p.risk.keeperBps;
64
65
  const kf = prodK / BPS_DENOM;
65
- return { prodT, target, seizeR, seize, pf, prodK, kf, toLender: seize - pf - kf, surplus: p.avail - seize };
66
+ return { prodT, target, seizeR, seize, prodK, kf, toLender: seize - kf, surplus: p.avail - seize };
66
67
  }
67
68
  /** `loan::keeper_bps`: the liquidation rate in LIQUIDATE and FAULT, the default rate in DEFAULT, or 0. */
68
69
  export function loanRisk(rates, decimals, mode) {
@@ -91,6 +92,9 @@ function assertRanges(p, principal, terms, addAmount) {
91
92
  for (const [name, value] of Object.entries({ ltvBps, liqBps, bonusBps, keeperBps }))
92
93
  if (value < 0n || value > MAX_BPS)
93
94
  throw new Error(`${name} is not in 0..10000`);
95
+ for (const [name, value] of Object.entries({ dummySeed0: p.dummySeeds[0], dummySeed1: p.dummySeeds[1] }))
96
+ if (value < 0n || value >= R)
97
+ throw new Error(`${name} is not a field element`);
94
98
  }
95
99
  /** The per-mode constraints of `health.circom:281-299`: a witness that breaks one has no proof. */
96
100
  function assertProvable(p, principal, terms, spot, ema) {
@@ -110,6 +114,15 @@ function assertProvable(p, principal, terms, spot, ema) {
110
114
  if (mode === MODE.DEFAULT && p.timeS < due)
111
115
  refuse("INVALID_ARGUMENT", "maturity plus grace has not passed");
112
116
  }
117
+ /** TOPUP opens `hRest` (`health.circom` `s3 * (hRest - rest.out) === 0`); a stated one must agree. */
118
+ function restOf(p, terms) {
119
+ if (p.mode === MODE.OPEN)
120
+ return 0n;
121
+ const opened = termsRest(terms);
122
+ if (p.mode === MODE.TOPUP && p.hRest !== undefined && p.hRest !== opened)
123
+ refuse("INVALID_ARGUMENT", "a top-up's terms do not open the stated hRest");
124
+ return p.hRest ?? opened;
125
+ }
113
126
  function feeInputs(fee, eph, lane) {
114
127
  return {
115
128
  fee_bps: fee.bps.toString(),
@@ -135,7 +148,8 @@ export async function health(p) {
135
148
  const request = p.mode === MODE.OPEN ? p.request : NO_REQUEST;
136
149
  const principal = p.mode === MODE.OPEN ? request.principal : terms.principal;
137
150
  const add = p.mode === MODE.TOPUP ? p.add : { amount: 0n, blinding: 0n, ephL: IDLE_EPH_L };
138
- const keeper = seizing ? p.keeper : { pk: 0n, blinding: 0n };
151
+ const [pad1, pad2] = p.pads;
152
+ const out2Key = seizing ? p.keeper : pad2;
139
153
  assertRanges(p, principal, terms, add.amount);
140
154
  if (priced && price.spot === 0n)
141
155
  refuse("INVALID_ARGUMENT", "a seizure needs a spot price");
@@ -147,33 +161,35 @@ export async function health(p) {
147
161
  refuse("INVALID_ARGUMENT", "the fee and keeper rates exceed the bonus");
148
162
  const lockPk = collLockPk(o.loanKey, o.borrowerPk);
149
163
  const note = noteCommitment(o.amount, lockPk, o.blinding);
150
- const commitIn = mode === MODE.OPEN ? requestCommit(request, o.borrowerPk, note) : termsCommit(terms, o.borrowerPk);
164
+ const hRest = restOf(p, terms);
165
+ const commitIn = mode === MODE.OPEN ? requestCommit(request, o.borrowerPk, note) : termsOuter(terms, o.borrowerPk, hRest);
151
166
  const { prodT, target, seizeR, seize, prodK, kf } = seizeSplit({
152
167
  owed: priced ? terms.owed : 0n,
153
168
  avail: seizing ? o.amount : 0n,
154
169
  pSpot: priced ? price.spot : 1n,
155
170
  expo: price.expo,
156
171
  risk,
157
- fee: p.fee,
158
172
  fault: mode === MODE.FAULT,
159
173
  });
160
- const lane = await feeLane({ ...p.fee, base: seize, eph: p.eph });
161
- const toLender = seize - lane.fee - kf;
162
- if (toLender < 0n)
163
- refuse("INVALID_ARGUMENT", "the fee and the keeper fee exceed the seized amount");
174
+ const lane = await feeLane({ ...p.fee, base: 0n, eph: p.eph });
175
+ const toLender = seize - kf;
164
176
  const avail = o.amount + add.amount;
165
177
  assertU64("collAmt + addAmt", avail);
166
178
  const bD0 = outputBlind(o.blinding, 0, o.nonce);
167
- let notes = [NO_NOTE, NO_NOTE, NO_NOTE];
179
+ const padNotes = [
180
+ { amount: 0n, pk: pad1.pk, blinding: pad1.blinding },
181
+ { amount: 0n, pk: out2Key.pk, blinding: out2Key.blinding },
182
+ ];
183
+ let notes = [NO_NOTE, ...padNotes];
168
184
  if (mode === MODE.HEARTBEAT || mode === MODE.TOPUP)
169
- notes = [{ amount: avail, pk: lockPk, blinding: bD0 }, NO_NOTE, NO_NOTE];
185
+ notes = [{ amount: avail, pk: lockPk, blinding: bD0 }, ...padNotes];
170
186
  if (mode === MODE.RELEASE)
171
- notes = [{ amount: avail, pk: o.borrowerPk, blinding: bD0 }, NO_NOTE, NO_NOTE];
187
+ notes = [{ amount: avail, pk: o.borrowerPk, blinding: bD0 }, ...padNotes];
172
188
  if (seizing)
173
189
  notes = [
174
190
  { amount: toLender, pk: terms.lenderPk, blinding: bD0 },
175
191
  { amount: avail - seize, pk: o.borrowerPk, blinding: outputBlind(o.blinding, 1, o.nonce) },
176
- { amount: kf, pk: keeper.pk, blinding: keeper.blinding },
192
+ { amount: kf, pk: out2Key.pk, blinding: out2Key.blinding },
177
193
  ];
178
194
  const [out0, out1, out2] = notes.map((n) => noteCommitment(n.amount, n.pk, n.blinding));
179
195
  const addCommit = mode === MODE.TOPUP ? noteCommitment(add.amount, lockPk, add.blinding) : 0n;
@@ -182,28 +198,32 @@ export async function health(p) {
182
198
  const k = await ecdhBlind(terms.lenderEncX, terms.lenderEncY, add.ephL);
183
199
  lender = [k.ephX, k.ephY, fieldAdd(notes[0].amount, lenderMask(k.sx))];
184
200
  }
201
+ const hP = poseidonHash([
202
+ risk.cDec,
203
+ risk.lDec,
204
+ risk.ltvBps,
205
+ risk.liqBps,
206
+ risk.bonusBps,
207
+ risk.keeperBps,
208
+ p.timeS,
209
+ o.nonce,
210
+ ]);
185
211
  const s = [
186
212
  BigInt(mode),
187
213
  o.loanKey,
188
214
  note,
189
215
  commitIn,
190
216
  addCommit,
191
- risk.cDec,
192
- risk.lDec,
193
- risk.ltvBps,
194
- risk.liqBps,
195
- risk.bonusBps,
196
217
  lane.fee_commit,
197
- risk.keeperBps,
198
218
  p.fee.version,
199
219
  p.extHash,
200
- p.timeS,
201
- o.nonce,
220
+ hP,
202
221
  ];
203
222
  const outs = [out0, out1, out2, lane.fee_note];
204
- const delivery = [lane.ephX, lane.ephY, lane.fee_ct, ...lender];
223
+ const dummies = p.dummySeeds.map(dummyNull);
224
+ const delivery = [lane.ephX, lane.ephY, lane.fee_ct, ...lender, ...dummies];
205
225
  const a = [price.spot, price.ema, price.expo, ...outs, HEALTH_VERSION];
206
- const d = [...delivery, 0n, 0n];
226
+ const d = [...delivery];
207
227
  const input = {
208
228
  mode: mode.toString(),
209
229
  loanKey: o.loanKey.toString(),
@@ -218,6 +238,7 @@ export async function health(p) {
218
238
  lenderEncX: terms.lenderEncX.toString(),
219
239
  lenderEncY: terms.lenderEncY.toString(),
220
240
  salt_t: terms.salt.toString(),
241
+ hRest: hRest.toString(),
221
242
  max_rate_bps: request.maxRateBps.toString(),
222
243
  term_ms: request.termMs.toString(),
223
244
  salt_req: request.salt.toString(),
@@ -235,8 +256,12 @@ export async function health(p) {
235
256
  p_ema: price.ema.toString(),
236
257
  time_s: p.timeS.toString(),
237
258
  nonce: o.nonce.toString(),
238
- keeperPk: keeper.pk.toString(),
239
- keeperBlind: keeper.blinding.toString(),
259
+ keeperPk: out2Key.pk.toString(),
260
+ keeperBlind: out2Key.blinding.toString(),
261
+ padPk1: pad1.pk.toString(),
262
+ padBlind1: pad1.blinding.toString(),
263
+ dummySeed0: p.dummySeeds[0].toString(),
264
+ dummySeed1: p.dummySeeds[1].toString(),
240
265
  extHash: p.extHash.toString(),
241
266
  eL: add.ephL.toString(),
242
267
  q_spot: spot.q.toString(),