@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.
- package/dist/config.d.ts +3 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +1 -0
- package/dist/errors.d.ts +3 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +5 -0
- package/dist/essey.d.ts +157 -131
- package/dist/essey.d.ts.map +1 -1
- package/dist/essey.js +641 -823
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/v3/collateral/bodies.d.ts +23 -14
- package/dist/v3/collateral/bodies.d.ts.map +1 -1
- package/dist/v3/collateral/bodies.js +42 -35
- package/dist/v3/collateral/ext.d.ts +18 -13
- package/dist/v3/collateral/ext.d.ts.map +1 -1
- package/dist/v3/collateral/ext.js +5 -6
- package/dist/v3/collateral/health.d.ts +16 -10
- package/dist/v3/collateral/health.d.ts.map +1 -1
- package/dist/v3/collateral/health.js +55 -30
- package/dist/v3/collateral/math.d.ts +0 -2
- package/dist/v3/collateral/math.d.ts.map +1 -1
- package/dist/v3/collateral/math.js +0 -5
- package/dist/v3/collateral/openings.d.ts +5 -1
- package/dist/v3/collateral/openings.d.ts.map +1 -1
- package/dist/v3/collateral/openings.js +7 -12
- package/dist/v3/credential/membership.d.ts +16 -2
- package/dist/v3/credential/membership.d.ts.map +1 -1
- package/dist/v3/credential/membership.js +36 -3
- package/dist/v3/domains.d.ts +9 -0
- package/dist/v3/domains.d.ts.map +1 -1
- package/dist/v3/domains.js +5 -0
- package/dist/v3/fees.d.ts +13 -1
- package/dist/v3/fees.d.ts.map +1 -1
- package/dist/v3/fees.js +32 -2
- package/dist/v3/funds.d.ts +34 -0
- package/dist/v3/funds.d.ts.map +1 -0
- package/dist/v3/funds.js +60 -0
- package/dist/v3/keeper-payload.d.ts +29 -7
- package/dist/v3/keeper-payload.d.ts.map +1 -1
- package/dist/v3/keeper-payload.js +33 -22
- package/dist/v3/kinds.d.ts +6 -6
- package/dist/v3/kinds.d.ts.map +1 -1
- package/dist/v3/kinds.js +5 -13
- package/dist/v3/loans/bodies.d.ts +40 -68
- package/dist/v3/loans/bodies.d.ts.map +1 -1
- package/dist/v3/loans/bodies.js +50 -73
- package/dist/v3/loans/offer-payload.d.ts +109 -0
- package/dist/v3/loans/offer-payload.d.ts.map +1 -0
- package/dist/v3/loans/offer-payload.js +207 -0
- package/dist/v3/loans/offer-plan.d.ts +8 -60
- package/dist/v3/loans/offer-plan.d.ts.map +1 -1
- package/dist/v3/loans/offer-plan.js +19 -95
- package/dist/v3/loans/open-plan.d.ts +15 -5
- package/dist/v3/loans/open-plan.d.ts.map +1 -1
- package/dist/v3/loans/open-plan.js +18 -7
- package/dist/v3/loans/reclaim-plan.d.ts +31 -15
- package/dist/v3/loans/reclaim-plan.d.ts.map +1 -1
- package/dist/v3/loans/reclaim-plan.js +63 -32
- package/dist/v3/loans/refi-plan.d.ts +8 -34
- package/dist/v3/loans/refi-plan.d.ts.map +1 -1
- package/dist/v3/loans/refi-plan.js +30 -111
- package/dist/v3/loans/repay-plan.d.ts.map +1 -1
- package/dist/v3/loans/repay-plan.js +2 -2
- package/dist/v3/loans/settle-plan.d.ts +88 -53
- package/dist/v3/loans/settle-plan.d.ts.map +1 -1
- package/dist/v3/loans/settle-plan.js +141 -150
- package/dist/v3/locks.d.ts +21 -0
- package/dist/v3/locks.d.ts.map +1 -0
- package/dist/v3/locks.js +15 -0
- package/dist/v3/memo.d.ts +14 -4
- package/dist/v3/memo.d.ts.map +1 -1
- package/dist/v3/memo.js +14 -7
- package/dist/v3/notes/derive.d.ts +5 -0
- package/dist/v3/notes/derive.d.ts.map +1 -1
- package/dist/v3/notes/derive.js +5 -0
- package/dist/v3/pace.d.ts +0 -1
- package/dist/v3/pace.d.ts.map +1 -1
- package/dist/v3/pace.js +0 -1
- package/dist/v3/pads.d.ts +15 -0
- package/dist/v3/pads.d.ts.map +1 -0
- package/dist/v3/pads.js +25 -0
- package/dist/v3/prover.d.ts +1 -1
- package/dist/v3/prover.d.ts.map +1 -1
- package/dist/v3/prover.js +1 -0
- package/dist/v3/sales/auctioneer.d.ts +32 -27
- package/dist/v3/sales/auctioneer.d.ts.map +1 -1
- package/dist/v3/sales/auctioneer.js +67 -108
- package/dist/v3/sales/bid.d.ts +20 -49
- package/dist/v3/sales/bid.d.ts.map +1 -1
- package/dist/v3/sales/bid.js +28 -83
- package/dist/v3/sales/bodies.d.ts +4 -54
- package/dist/v3/sales/bodies.d.ts.map +1 -1
- package/dist/v3/sales/bodies.js +10 -52
- package/dist/v3/sales/claim.d.ts +0 -2
- package/dist/v3/sales/claim.d.ts.map +1 -1
- package/dist/v3/sales/claim.js +6 -8
- package/dist/v3/sales/index.d.ts +0 -1
- package/dist/v3/sales/index.d.ts.map +1 -1
- package/dist/v3/sales/index.js +0 -1
- package/dist/v3/sales/listing.d.ts +8 -6
- package/dist/v3/sales/listing.d.ts.map +1 -1
- package/dist/v3/sales/listing.js +27 -9
- package/dist/v3/sales/open-kind.d.ts +1 -3
- package/dist/v3/sales/open-kind.d.ts.map +1 -1
- package/dist/v3/sales/open-kind.js +2 -3
- package/dist/v3/sales/outcome.d.ts +5 -8
- package/dist/v3/sales/outcome.d.ts.map +1 -1
- package/dist/v3/sales/outcome.js +5 -9
- package/dist/v3/sales/package-gate.d.ts +3 -4
- package/dist/v3/sales/package-gate.d.ts.map +1 -1
- package/dist/v3/sales/package-gate.js +9 -7
- package/dist/v3/sales/rows.d.ts +9 -49
- package/dist/v3/sales/rows.d.ts.map +1 -1
- package/dist/v3/sales/rows.js +17 -91
- package/dist/v3/sales/seller.d.ts +2 -6
- package/dist/v3/sales/seller.d.ts.map +1 -1
- package/dist/v3/sales/seller.js +4 -11
- package/dist/v3/stage1.d.ts +8 -21
- package/dist/v3/stage1.d.ts.map +1 -1
- package/dist/v3/stage1.js +8 -76
- package/package.json +1 -1
- package/dist/v3/loans/lock-round.d.ts +0 -22
- package/dist/v3/loans/lock-round.d.ts.map +0 -1
- package/dist/v3/loans/lock-round.js +0 -20
- package/dist/v3/sales/reclaim.d.ts +0 -46
- package/dist/v3/sales/reclaim.d.ts.map +0 -1
- package/dist/v3/sales/reclaim.js +0 -57
|
@@ -28,8 +28,6 @@ export declare function collFor(value: bigint, price: bigint, s: Scale): {
|
|
|
28
28
|
};
|
|
29
29
|
/** `heartbeat_floor` (`liquidation.move:475-484`): floor(rung(min(spot, ema)) · (10000 - 500) / 10000). */
|
|
30
30
|
export declare const heartbeatFloor: (r: Pick<Reading, "spot" | "ema">) => bigint;
|
|
31
|
-
/** DECISION-R1-MIGRATION A: a retired-package loan's floor, the pre-R1 `heartbeat_floor` at bucket 1, unsnapped. */
|
|
32
|
-
export declare function legacyHeartbeatFloor(r: Pick<Reading, "spot" | "ema">): bigint;
|
|
33
31
|
/** `liquidation.move` `HB_EXPIRY_STEP_MS`: a heartbeat expiry is on this step (43_005). */
|
|
34
32
|
export declare const COVER_STEP_MS = 300000n;
|
|
35
33
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"math.d.ts","sourceRoot":"","sources":["../../../src/v3/collateral/math.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,OAAO,OAAO,CAAC;AAC5B,eAAO,MAAM,WAAW,OAAO,CAAC;AA+ChC,yGAAyG;AACzG,MAAM,MAAM,KAAK,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjE,MAAM,MAAM,OAAO,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAOlE,oHAAoH;AACpH,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,EAAE,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AAC;AAErG;;;GAGG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,EAAE,KAAK,GAAG;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAMxF;AAYD,2GAA2G;AAC3G,eAAO,MAAM,cAAc,GAAI,GAAG,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,CAAC,KAAG,MACV,CAAC;AAEzD,2FAA2F;AAC3F,eAAO,MAAM,aAAa,UAAW,CAAC;AAGtC;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAIpE;AAED,kIAAkI;AAClI,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAGvE"}
|
|
@@ -82,11 +82,6 @@ function floorRung(r) {
|
|
|
82
82
|
}
|
|
83
83
|
/** `heartbeat_floor` (`liquidation.move:475-484`): floor(rung(min(spot, ema)) · (10000 - 500) / 10000). */
|
|
84
84
|
export const heartbeatFloor = (r) => (floorRung(r) * (BPS_DENOM - HB_STEP_BPS)) / BPS_DENOM;
|
|
85
|
-
/** DECISION-R1-MIGRATION A: a retired-package loan's floor, the pre-R1 `heartbeat_floor` at bucket 1, unsnapped. */
|
|
86
|
-
export function legacyHeartbeatFloor(r) {
|
|
87
|
-
const low = r.spot < r.ema ? r.spot : r.ema;
|
|
88
|
-
return (low * (BPS_DENOM - HB_STEP_BPS)) / BPS_DENOM;
|
|
89
|
-
}
|
|
90
85
|
/** `liquidation.move` `HB_EXPIRY_STEP_MS`: a heartbeat expiry is on this step (43_005). */
|
|
91
86
|
export const COVER_STEP_MS = 300000n;
|
|
92
87
|
const COVER_AHEAD_MS = 82800000n;
|
|
@@ -18,7 +18,11 @@ export declare const collLockPk: (loanKey: bigint, borrowerPk: bigint) => bigint
|
|
|
18
18
|
export declare const collNote: (o: Omit<CollOpening, "nonce">) => bigint;
|
|
19
19
|
/** `OutBlind(i)` of `health.circom:45-56`: a borrower or lender can always recompute an output's blinding. */
|
|
20
20
|
export declare const outputBlind: (collBlind: bigint, i: 0 | 1, nonce: bigint) => bigint;
|
|
21
|
-
/** `
|
|
21
|
+
/** `lib/terms2.circom` TermsRest: the half of the terms a keeper never opens (freeze D4a). */
|
|
22
|
+
export declare const termsRest: (t: Pick<KeeperTerms, "principal" | "rateBps" | "lenderEncX" | "lenderEncY" | "salt">) => bigint;
|
|
23
|
+
/** `lib/terms2.circom` TermsOuter over `hRest`. */
|
|
24
|
+
export declare const termsOuter: (t: Pick<KeeperTerms, "owed" | "maturityS" | "lenderPk">, borrowerPk: bigint, hRest: bigint) => bigint;
|
|
25
|
+
/** `lib/terms2.circom` Terms2. */
|
|
22
26
|
export declare const termsCommit: (t: KeeperTerms, borrowerPk: bigint) => bigint;
|
|
23
27
|
/** `health.circom:238-244`. */
|
|
24
28
|
export declare const requestCommit: (q: ReqOpening, borrowerPk: bigint, note: bigint) => bigint;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openings.d.ts","sourceRoot":"","sources":["../../../src/v3/collateral/openings.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAGxD,kFAAkF;AAClF,MAAM,MAAM,WAAW,GAAG;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjG,qFAAqF;AACrF,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3G,mDAAmD;AACnD,eAAO,MAAM,UAAU,GACrB,GAAG,IAAI,CAAC,WAAW,EAAE,MAAM,GAAG,WAAW,GAAG,UAAU,CAAC,EACvD,YAAY,MAAM,EAClB,OAAO,MAAM,WACmE,CAAC;AAEnF,kCAAkC;AAClC,eAAO,MAAM,WAAW,GAAI,GAAG,WAAW,EAAE,YAAY,MAAM,WAA4C,CAAC;AAE3G,+BAA+B;AAC/B,eAAO,MAAM,aAAa,GAAI,GAAG,UAAU,EAAE,YAAY,MAAM,EAAE,MAAM,MAAM,WACE,CAAC;AAEhF,4FAA4F;AAC5F,eAAO,MAAM,QAAQ,GAAI,GAAG,WAAW,EAAE,cAAU,KAAG,WAKpD,CAAC"}
|
|
@@ -1,22 +1,17 @@
|
|
|
1
1
|
import { poseidonHash } from "@mysten/sui/zklogin";
|
|
2
|
-
import { DOM_BLIND, DOM_LOCK_COLL } from "../domains.js";
|
|
2
|
+
import { DOM_BLIND, DOM_LOCK_COLL, DOM_TERMS, DOM_TREST } from "../domains.js";
|
|
3
3
|
import { noteCommitment } from "../notes/keys.js";
|
|
4
4
|
/** E-1 (`circuits/v3/lib/lock.circom` CollLockNote): a pk nobody holds a key for. */
|
|
5
5
|
export const collLockPk = (loanKey, borrowerPk) => poseidonHash([DOM_LOCK_COLL, loanKey, borrowerPk, 0n]);
|
|
6
6
|
export const collNote = (o) => noteCommitment(o.amount, collLockPk(o.loanKey, o.borrowerPk), o.blinding);
|
|
7
7
|
/** `OutBlind(i)` of `health.circom:45-56`: a borrower or lender can always recompute an output's blinding. */
|
|
8
8
|
export const outputBlind = (collBlind, i, nonce) => poseidonHash([DOM_BLIND, collBlind, BigInt(i), nonce]);
|
|
9
|
-
/** `
|
|
10
|
-
export const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
borrowerPk,
|
|
16
|
-
t.lenderPk,
|
|
17
|
-
poseidonHash([t.lenderEncX, t.lenderEncY]),
|
|
18
|
-
t.salt,
|
|
19
|
-
]);
|
|
9
|
+
/** `lib/terms2.circom` TermsRest: the half of the terms a keeper never opens (freeze D4a). */
|
|
10
|
+
export const termsRest = (t) => poseidonHash([DOM_TREST, t.principal, t.rateBps, poseidonHash([t.lenderEncX, t.lenderEncY]), t.salt]);
|
|
11
|
+
/** `lib/terms2.circom` TermsOuter over `hRest`. */
|
|
12
|
+
export const termsOuter = (t, borrowerPk, hRest) => poseidonHash([DOM_TERMS, t.owed, t.maturityS, borrowerPk, t.lenderPk, hRest]);
|
|
13
|
+
/** `lib/terms2.circom` Terms2. */
|
|
14
|
+
export const termsCommit = (t, borrowerPk) => termsOuter(t, borrowerPk, termsRest(t));
|
|
20
15
|
/** `health.circom:238-244`. */
|
|
21
16
|
export const requestCommit = (q, borrowerPk, note) => poseidonHash([q.principal, q.maxRateBps, q.termMs, borrowerPk, note, q.salt]);
|
|
22
17
|
/** The lock a HEARTBEAT, or a TOPUP of `added`, leaves behind (`health.circom:354-373`). */
|
|
@@ -33,7 +33,21 @@ export declare function offerRoom(loanKey: bigint, round: bigint): string;
|
|
|
33
33
|
export declare function memberCommitment(s: MemberSecrets): bigint;
|
|
34
34
|
export declare function credentialMessage(commitment: bigint, expiryMs: bigint, epoch: bigint, role: Credential["role"]): bigint;
|
|
35
35
|
export declare function memberTag(nullSecret: bigint, room: string, nonce?: bigint): bigint;
|
|
36
|
-
/**
|
|
37
|
-
|
|
36
|
+
/**
|
|
37
|
+
* PRV-33, Erik's rate-lane row: `lane = window * 2^16 + slot` with `slot < RATE_K`, so one member has exactly K
|
|
38
|
+
* unlinkable fee-params tags per hour. Strict v3api refuses a lane outside the current or previous window and a
|
|
39
|
+
* repeated tag.
|
|
40
|
+
*/
|
|
41
|
+
export declare const RATE_K = 60;
|
|
42
|
+
export declare const RATE_WINDOW_MS = 3600000;
|
|
43
|
+
export declare function rateLane(nowMs: number, slot: number): bigint;
|
|
44
|
+
/** Memory only. Slots are drawn without repeat, so the slot v3api sees says nothing about how many came before. */
|
|
45
|
+
export declare class RateSlots {
|
|
46
|
+
private readonly draw;
|
|
47
|
+
private window;
|
|
48
|
+
private free;
|
|
49
|
+
constructor(draw?: (below: number) => number);
|
|
50
|
+
take(nowMs: number): bigint;
|
|
51
|
+
}
|
|
38
52
|
export declare function passCtx(domain: bigint, room: string, bind: string): bigint;
|
|
39
53
|
//# sourceMappingURL=membership.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"membership.d.ts","sourceRoot":"","sources":["../../../src/v3/credential/membership.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"membership.d.ts","sourceRoot":"","sources":["../../../src/v3/credential/membership.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,aAAa,KAAK,CAAC;AAChC,eAAO,MAAM,YAAY,KAAK,CAAC;AAC/B,eAAO,MAAM,aAAa,KAAK,CAAC;AAEhC,wFAAwF;AACxF,MAAM,MAAM,aAAa,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC;AAEnE,4DAA4D;AAC5D,MAAM,MAAM,UAAU,GAAG;IACvB,GAAG,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC7C,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC;IACrC,IAAI,EAAE,QAAQ,GAAG,QAAQ,CAAC;CAC3B,CAAC;AAEF,8GAA8G;AAC9G,eAAO,MAAM,eAAe,QAAyD,CAAC;AAEtF,kGAAkG;AAClG,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAGtD;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAEhE;AAED,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,aAAa,GAAG,MAAM,CAEzD;AAKD,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,UAAU,CAAC,MAAM,CAAC,GACvB,MAAM,CAER;AAED,wBAAgB,SAAS,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,SAAK,GAAG,MAAM,CAE9E;AAED;;;;GAIG;AACH,eAAO,MAAM,MAAM,KAAK,CAAC;AACzB,eAAO,MAAM,cAAc,UAAY,CAAC;AAGxC,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAI5D;AAED,mHAAmH;AACnH,qBAAa,SAAS;IAIR,OAAO,CAAC,QAAQ,CAAC,IAAI;IAHjC,OAAO,CAAC,MAAM,CAAM;IACpB,OAAO,CAAC,IAAI,CAAgB;gBAEC,IAAI,GAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAoC;IAE1F,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;CAW5B;AAED,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAE1E"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { randomInt } from "node:crypto";
|
|
1
2
|
import { poseidonHash } from "@mysten/sui/zklogin";
|
|
3
|
+
import { EsseyError } from "../../errors.js";
|
|
2
4
|
import { DOM_ROUND, FEE_PARAMS_DOMAIN } from "../domains.js";
|
|
3
5
|
export const DOMAIN_SENDER = 1n;
|
|
4
6
|
export const DOMAIN_SPEND = 2n;
|
|
@@ -29,9 +31,40 @@ export function credentialMessage(commitment, expiryMs, epoch, role) {
|
|
|
29
31
|
export function memberTag(nullSecret, room, nonce = 0n) {
|
|
30
32
|
return poseidonHash([nullSecret, ...halves(room), nonce]);
|
|
31
33
|
}
|
|
32
|
-
/**
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
/**
|
|
35
|
+
* PRV-33, Erik's rate-lane row: `lane = window * 2^16 + slot` with `slot < RATE_K`, so one member has exactly K
|
|
36
|
+
* unlinkable fee-params tags per hour. Strict v3api refuses a lane outside the current or previous window and a
|
|
37
|
+
* repeated tag.
|
|
38
|
+
*/
|
|
39
|
+
export const RATE_K = 60;
|
|
40
|
+
export const RATE_WINDOW_MS = 3_600_000;
|
|
41
|
+
const SLOT_BITS = 16n;
|
|
42
|
+
export function rateLane(nowMs, slot) {
|
|
43
|
+
if (!Number.isSafeInteger(nowMs) || nowMs < 0)
|
|
44
|
+
throw new Error("nowMs is not a time");
|
|
45
|
+
if (!Number.isInteger(slot) || slot < 0 || slot >= RATE_K)
|
|
46
|
+
throw new Error("slot is not a rate slot");
|
|
47
|
+
return (BigInt(Math.floor(nowMs / RATE_WINDOW_MS)) << SLOT_BITS) + BigInt(slot);
|
|
48
|
+
}
|
|
49
|
+
/** Memory only. Slots are drawn without repeat, so the slot v3api sees says nothing about how many came before. */
|
|
50
|
+
export class RateSlots {
|
|
51
|
+
draw;
|
|
52
|
+
window = -1;
|
|
53
|
+
free = [];
|
|
54
|
+
constructor(draw = (below) => randomInt(below)) {
|
|
55
|
+
this.draw = draw;
|
|
56
|
+
}
|
|
57
|
+
take(nowMs) {
|
|
58
|
+
const window = Math.floor(nowMs / RATE_WINDOW_MS);
|
|
59
|
+
if (window !== this.window) {
|
|
60
|
+
this.window = window;
|
|
61
|
+
this.free = Array.from({ length: RATE_K }, (_, i) => i);
|
|
62
|
+
}
|
|
63
|
+
if (this.free.length === 0)
|
|
64
|
+
throw new EsseyError("RATE_LIMITED", `refused: all ${RATE_K} fee-params lanes of this hour are used`);
|
|
65
|
+
const [slot] = this.free.splice(this.draw(this.free.length), 1);
|
|
66
|
+
return rateLane(nowMs, slot);
|
|
67
|
+
}
|
|
35
68
|
}
|
|
36
69
|
export function passCtx(domain, room, bind) {
|
|
37
70
|
return poseidonHash([domain, ...halves(room), ...halves(bind)]);
|
package/dist/v3/domains.d.ts
CHANGED
|
@@ -100,6 +100,15 @@ export declare const DOM_CL: bigint;
|
|
|
100
100
|
export declare const DOM_KPR: bigint;
|
|
101
101
|
export declare const DOM_SALEKEY: bigint;
|
|
102
102
|
export declare const DOM_CNULL: bigint;
|
|
103
|
+
/** `circuits/v3/lib/domains_z1.circom`: Terms2's two tags and the lock blind's (freeze §2, ruling R5). */
|
|
104
|
+
export declare const Z1_TAGS: {
|
|
105
|
+
readonly DOM_TERMS: "ess3/terms";
|
|
106
|
+
readonly DOM_TREST: "ess3/trest";
|
|
107
|
+
readonly DOM_LOCKB: "ess3/lockb";
|
|
108
|
+
};
|
|
109
|
+
export declare const DOM_TERMS: bigint;
|
|
110
|
+
export declare const DOM_TREST: bigint;
|
|
111
|
+
export declare const DOM_LOCKB: bigint;
|
|
103
112
|
export declare const DOMAINS: {
|
|
104
113
|
readonly DOM_LOCK: bigint;
|
|
105
114
|
readonly DOM_LNULL: bigint;
|
package/dist/v3/domains.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"domains.d.ts","sourceRoot":"","sources":["../../src/v3/domains.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,CAAC,iFAAQ,CAAC;AAGvB,eAAO,MAAM,WAAW,QAAQ,CAAC;AAEjC;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,iFACkD,CAAC;AAEjF;;;;GAIG;AACH,eAAO,MAAM,aAAa,iFAAiF,CAAC;AAE5G;;;GAGG;AACH,eAAO,MAAM,YAAY,iFAAiF,CAAC;AAE3G,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAS9C;AAED,eAAO,MAAM,IAAI;;;;;;;;;;;;;;;;;;;;;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M,OAAO;;;;CAAyF,CAAC;AAC9G,eAAO,MAAM,SAAS,QAAgC,CAAC;AACvD,eAAO,MAAM,SAAS,QAAgC,CAAC;AACvD,eAAO,MAAM,SAAS,QAAgC,CAAC;AAEvD,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyCV,CAAC;AAEX,wBAAgB,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAI5C"}
|
package/dist/v3/domains.js
CHANGED
|
@@ -113,6 +113,11 @@ export const DOM_CL = tagToField(TAGS.DOM_CL);
|
|
|
113
113
|
export const DOM_KPR = tagToField(TAGS.DOM_KPR);
|
|
114
114
|
export const DOM_SALEKEY = tagToField(TAGS.DOM_SALEKEY);
|
|
115
115
|
export const DOM_CNULL = tagToField(TAGS.DOM_CNULL);
|
|
116
|
+
/** `circuits/v3/lib/domains_z1.circom`: Terms2's two tags and the lock blind's (freeze §2, ruling R5). */
|
|
117
|
+
export const Z1_TAGS = { DOM_TERMS: "ess3/terms", DOM_TREST: "ess3/trest", DOM_LOCKB: "ess3/lockb" };
|
|
118
|
+
export const DOM_TERMS = tagToField(Z1_TAGS.DOM_TERMS);
|
|
119
|
+
export const DOM_TREST = tagToField(Z1_TAGS.DOM_TREST);
|
|
120
|
+
export const DOM_LOCKB = tagToField(Z1_TAGS.DOM_LOCKB);
|
|
116
121
|
export const DOMAINS = {
|
|
117
122
|
DOM_LOCK,
|
|
118
123
|
DOM_LNULL,
|
package/dist/v3/fees.d.ts
CHANGED
|
@@ -42,10 +42,22 @@ export type FeeLaneResult = FeeOf & {
|
|
|
42
42
|
};
|
|
43
43
|
export declare function assertU64(name: string, n: bigint): void;
|
|
44
44
|
export declare function feeOf({ base, bps, min, max }: FeeRates): FeeOf;
|
|
45
|
-
export declare function assertFeeConfig(bps: bigint, min: bigint, max: bigint): void;
|
|
45
|
+
export declare function assertFeeConfig(bps: bigint, min: bigint, max: bigint, lane?: FeeLane): void;
|
|
46
|
+
/** The smallest principal, refinance principal, sale price or early-reclaimed lock a hidden fee config proves. */
|
|
47
|
+
export declare const minHiddenBase: (fee: Pick<FeeCommitInput, "bps" | "min">) => bigint;
|
|
46
48
|
export declare function feeCommit(input: FeeCommitInput): bigint;
|
|
47
49
|
export declare function fieldAdd(a: bigint, b: bigint): bigint;
|
|
48
50
|
export declare function feeLane(input: FeeLaneInput): Promise<FeeLaneResult>;
|
|
51
|
+
/**
|
|
52
|
+
* `lib/fee_flat.circom` FeeFlat (Z1 PRV-02 O1): F is `fee_min` of the opening, charged when `on` and the rate flag
|
|
53
|
+
* are both set. A live opening with `min != max` has no witness, and the 10% rule makes `10 F` the smallest base.
|
|
54
|
+
*/
|
|
55
|
+
export declare function flatFeeOf({ on, base, bps, min, max }: FeeRates & {
|
|
56
|
+
on: boolean;
|
|
57
|
+
}): FeeOf;
|
|
58
|
+
export declare function flatFeeLane(input: FeeLaneInput & {
|
|
59
|
+
on?: boolean;
|
|
60
|
+
}): Promise<FeeLaneResult>;
|
|
49
61
|
/**
|
|
50
62
|
* `circuits/v3/lib/ecdh_blind.circom` outside the fee lane: `E = e·Base8` and `S = e·Pub`, refused where that
|
|
51
63
|
* circuit has no witness. Health TOPUP delivers the new collateral amount to the lender through it.
|
package/dist/v3/fees.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fees.d.ts","sourceRoot":"","sources":["../../src/v3/fees.ts"],"names":[],"mappings":"AAOA,OAAO,EAAuB,WAAW,EAAK,MAAM,cAAc,CAAC;AAKnE,eAAO,MAAM,SAAS,SAAU,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,CAAC;AACvB,eAAO,MAAM,WAAW,OAAO,CAAC;AAKhC,MAAM,MAAM,QAAQ,GAAG;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;A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;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC,CAKvF;AAED;;;;GAIG;AACH,MAAM,MAAM,OAAO,GAAG,QAAQ,GAAG,MAAM,CAAC;AAExC,oGAAoG;AACpG,MAAM,MAAM,UAAU,GAAG;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,GAAG,cAAc,CAoB3F"}
|
package/dist/v3/fees.js
CHANGED
|
@@ -50,16 +50,25 @@ export function feeOf({ base, bps, min, max }) {
|
|
|
50
50
|
// floor(base * bps / 10000). That holds if bps is 0 (the fee is forced to 0),
|
|
51
51
|
// max is 0 (the cap is 0), or min is 0 (the clamp never raises q).
|
|
52
52
|
// Any other triple takes the whole base on base = 1, which is above 10%.
|
|
53
|
-
|
|
53
|
+
// The hidden lane is FeeFlat (Z1 PRV-02 O1): a live config is flat (min == max = F) and the 10% rule refuses a
|
|
54
|
+
// base under 10 F instead of the config (`minHiddenBase`).
|
|
55
|
+
export function assertFeeConfig(bps, min, max, lane = "edge") {
|
|
54
56
|
assertU64("fee_bps", bps);
|
|
55
57
|
assertU64("fee_min", min);
|
|
56
58
|
assertU64("fee_max", max);
|
|
57
59
|
if (bps > MAX_FEE_BPS)
|
|
58
60
|
throw new Error("refused: fee rate above 1000");
|
|
61
|
+
if (lane === "hidden") {
|
|
62
|
+
if (bps > 0n && min !== max)
|
|
63
|
+
throw new Error("refused: a live hidden fee config is not flat");
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
59
66
|
if (bps > 0n && min > 0n && max > 0n) {
|
|
60
67
|
throw new Error("refused: fee min and max can push the fee above the rate cap");
|
|
61
68
|
}
|
|
62
69
|
}
|
|
70
|
+
/** The smallest principal, refinance principal, sale price or early-reclaimed lock a hidden fee config proves. */
|
|
71
|
+
export const minHiddenBase = (fee) => fee.bps === 0n ? 0n : 10n * fee.min;
|
|
63
72
|
// Poseidon9(DOM_FEE, bps, min, max, pk, tX, tY, salt, version). Hash only.
|
|
64
73
|
// The point is not checked here, so a commit can be compared with the chain
|
|
65
74
|
// even when the circuit would refuse the point.
|
|
@@ -91,6 +100,28 @@ export function fieldAdd(a, b) {
|
|
|
91
100
|
// identity ephemeral, which covers a zero scalar and the subgroup order.
|
|
92
101
|
// Boris decision Nov 10: zero ephemeral rejected.
|
|
93
102
|
export async function feeLane(input) {
|
|
103
|
+
return laneOf(input, feeOf(input));
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* `lib/fee_flat.circom` FeeFlat (Z1 PRV-02 O1): F is `fee_min` of the opening, charged when `on` and the rate flag
|
|
107
|
+
* are both set. A live opening with `min != max` has no witness, and the 10% rule makes `10 F` the smallest base.
|
|
108
|
+
*/
|
|
109
|
+
export function flatFeeOf({ on, base, bps, min, max }) {
|
|
110
|
+
assertU64("base", base);
|
|
111
|
+
assertU64("fee_min", min);
|
|
112
|
+
assertU64("fee_max", max);
|
|
113
|
+
if (bps < 0n || bps > MAX_FEE_BPS)
|
|
114
|
+
throw new Error("fee_bps is above 1000");
|
|
115
|
+
const live = on && bps !== 0n;
|
|
116
|
+
if (live && min !== max)
|
|
117
|
+
throw new Error("refused: a live hidden fee needs fee_min == fee_max");
|
|
118
|
+
const fee = live ? min : 0n;
|
|
119
|
+
return { q: 0n, r: 0n, fee, cap: fee, lo: fee };
|
|
120
|
+
}
|
|
121
|
+
export async function flatFeeLane(input) {
|
|
122
|
+
return laneOf(input, flatFeeOf({ ...input, on: input.on ?? true }));
|
|
123
|
+
}
|
|
124
|
+
async function laneOf(input, math) {
|
|
94
125
|
assertField("eph", input.eph);
|
|
95
126
|
if (input.eph === 0n)
|
|
96
127
|
throw new Error("ephemeral is zero");
|
|
@@ -100,7 +131,6 @@ export async function feeLane(input) {
|
|
|
100
131
|
const subOrder = BigInt(curve.subOrder.toString());
|
|
101
132
|
if (input.eph % subOrder === 0n)
|
|
102
133
|
throw new Error("ephemeral is a multiple of the subgroup order");
|
|
103
|
-
const math = feeOf(input);
|
|
104
134
|
if (math.fee * BPS_DENOM > input.base * MAX_FEE_BPS)
|
|
105
135
|
throw new Error("fee is above the rate cap");
|
|
106
136
|
const pub = [curve.F.e(input.tx), curve.F.e(input.ty)];
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type FeeCommitInput } from "./fees.ts";
|
|
2
|
+
import type { CircuitInput } from "./inputs.ts";
|
|
3
|
+
export declare const FUNDS_READ_KIND = 31;
|
|
4
|
+
export declare const FUNDS_LEVELS = 20;
|
|
5
|
+
/** `membership::funds_bind`: blake2b256("essey-v3/seal/funds" ‖ seal bind ‖ bcs(nonce)); lo = bytes 16..32, hi = 0..16. */
|
|
6
|
+
export declare function fundsBind(sealBind: Uint8Array, nonce: bigint): {
|
|
7
|
+
bindLo: bigint;
|
|
8
|
+
bindHi: bigint;
|
|
9
|
+
};
|
|
10
|
+
/** The floor `funds_read.circom` holds a note to: `10 * fee_min` of the opening the policy's fee commit binds. */
|
|
11
|
+
export declare const fundsFloor: (fee: Pick<FeeCommitInput, "min">) => bigint;
|
|
12
|
+
/** The largest own note at or over the floor, or null: a member without one is refused before any proof. */
|
|
13
|
+
export declare function fundsNote<N extends {
|
|
14
|
+
value: bigint;
|
|
15
|
+
}>(owned: N[], floor: bigint): N | null;
|
|
16
|
+
export type FundsReadParams = {
|
|
17
|
+
note: {
|
|
18
|
+
amount: bigint;
|
|
19
|
+
sk: bigint;
|
|
20
|
+
blinding: bigint;
|
|
21
|
+
index: number;
|
|
22
|
+
};
|
|
23
|
+
path: bigint[];
|
|
24
|
+
root: bigint;
|
|
25
|
+
fee: FeeCommitInput;
|
|
26
|
+
sealBind: Uint8Array;
|
|
27
|
+
nonce: bigint;
|
|
28
|
+
};
|
|
29
|
+
/** Witness for `circuits/v3/funds_read/funds_read.circom` (freeze §3.9). Publics: root, fee_commit, bindLo, bindHi. */
|
|
30
|
+
export declare function fundsRead(p: FundsReadParams): {
|
|
31
|
+
input: CircuitInput;
|
|
32
|
+
publics: bigint[];
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=funds.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"funds.d.ts","sourceRoot":"","sources":["../../src/v3/funds.ts"],"names":[],"mappings":"AAGA,OAAO,EAAa,KAAK,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGhD,eAAO,MAAM,eAAe,KAAK,CAAC;AAClC,eAAO,MAAM,YAAY,KAAK,CAAC;AAS/B,2HAA2H;AAC3H,wBAAgB,SAAS,CAAC,QAAQ,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAIjG;AAED,kHAAkH;AAClH,eAAO,MAAM,UAAU,GAAI,KAAK,IAAI,CAAC,cAAc,EAAE,KAAK,CAAC,WAAkB,CAAC;AAE9E,4GAA4G;AAC5G,wBAAgB,SAAS,CAAC,CAAC,SAAS;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,GAAG,IAAI,CAG1F;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IACtE,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,cAAc,CAAC;IACpB,QAAQ,EAAE,UAAU,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,uHAAuH;AACvH,wBAAgB,SAAS,CAAC,CAAC,EAAE,eAAe,GAAG;IAAE,KAAK,EAAE,YAAY,CAAC;IAAC,OAAO,EAAE,MAAM,EAAE,CAAA;CAAE,CAgCxF"}
|
package/dist/v3/funds.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { blake2b } from "@noble/hashes/blake2.js";
|
|
2
|
+
import { poseidonHash } from "@mysten/sui/zklogin";
|
|
3
|
+
import { feeCommit } from "./fees.js";
|
|
4
|
+
import { noteCommitment, notePk } from "./notes/keys.js";
|
|
5
|
+
export const FUNDS_READ_KIND = 31;
|
|
6
|
+
export const FUNDS_LEVELS = 20;
|
|
7
|
+
const SEAL_FUNDS = new TextEncoder().encode("essey-v3/seal/funds");
|
|
8
|
+
const beNum = (b) => BigInt(`0x${Buffer.from(b).toString("hex")}`);
|
|
9
|
+
function u256le(x) {
|
|
10
|
+
return Uint8Array.from({ length: 32 }, (_, i) => Number((x >> BigInt(8 * i)) & 0xffn));
|
|
11
|
+
}
|
|
12
|
+
/** `membership::funds_bind`: blake2b256("essey-v3/seal/funds" ‖ seal bind ‖ bcs(nonce)); lo = bytes 16..32, hi = 0..16. */
|
|
13
|
+
export function fundsBind(sealBind, nonce) {
|
|
14
|
+
if (sealBind.length !== 32)
|
|
15
|
+
throw new Error("the seal bind is not 32 bytes");
|
|
16
|
+
const d = blake2b(Uint8Array.from([...SEAL_FUNDS, ...sealBind, ...u256le(nonce)]), { dkLen: 32 });
|
|
17
|
+
return { bindLo: beNum(d.subarray(16, 32)), bindHi: beNum(d.subarray(0, 16)) };
|
|
18
|
+
}
|
|
19
|
+
/** The floor `funds_read.circom` holds a note to: `10 * fee_min` of the opening the policy's fee commit binds. */
|
|
20
|
+
export const fundsFloor = (fee) => 10n * fee.min;
|
|
21
|
+
/** The largest own note at or over the floor, or null: a member without one is refused before any proof. */
|
|
22
|
+
export function fundsNote(owned, floor) {
|
|
23
|
+
const fit = owned.filter((n) => n.value > 0n && n.value >= floor);
|
|
24
|
+
return fit.reduce((best, n) => (best === null || n.value > best.value ? n : best), null);
|
|
25
|
+
}
|
|
26
|
+
/** Witness for `circuits/v3/funds_read/funds_read.circom` (freeze §3.9). Publics: root, fee_commit, bindLo, bindHi. */
|
|
27
|
+
export function fundsRead(p) {
|
|
28
|
+
if (p.path.length !== FUNDS_LEVELS)
|
|
29
|
+
throw new Error("the path is not 20 levels");
|
|
30
|
+
if (p.note.amount === 0n)
|
|
31
|
+
throw new Error("refused: a zero note proves no funds");
|
|
32
|
+
if (p.note.amount < fundsFloor(p.fee))
|
|
33
|
+
throw new Error("refused: no note of at least 10 F in this coin");
|
|
34
|
+
const commit = feeCommit(p.fee);
|
|
35
|
+
const { bindLo, bindHi } = fundsBind(p.sealBind, p.nonce);
|
|
36
|
+
const leaf = noteCommitment(p.note.amount, notePk(p.note.sk), p.note.blinding);
|
|
37
|
+
const top = p.path.reduce((node, sib, k) => ((p.note.index >> k) & 1 ? poseidonHash([sib, node]) : poseidonHash([node, sib])), leaf);
|
|
38
|
+
if (top !== p.root)
|
|
39
|
+
throw new Error("the note is not under the root");
|
|
40
|
+
const input = {
|
|
41
|
+
root: p.root.toString(),
|
|
42
|
+
fee_commit: commit.toString(),
|
|
43
|
+
bindLo: bindLo.toString(),
|
|
44
|
+
bindHi: bindHi.toString(),
|
|
45
|
+
amount: p.note.amount.toString(),
|
|
46
|
+
sk: p.note.sk.toString(),
|
|
47
|
+
blinding: p.note.blinding.toString(),
|
|
48
|
+
pathIndices: p.note.index.toString(),
|
|
49
|
+
pathElements: p.path.map(String),
|
|
50
|
+
fee_bps: p.fee.bps.toString(),
|
|
51
|
+
fee_min: p.fee.min.toString(),
|
|
52
|
+
fee_max: p.fee.max.toString(),
|
|
53
|
+
fee_pk: p.fee.pk.toString(),
|
|
54
|
+
tX: p.fee.tx.toString(),
|
|
55
|
+
tY: p.fee.ty.toString(),
|
|
56
|
+
fee_salt: p.fee.salt.toString(),
|
|
57
|
+
cfg_version: p.fee.version.toString(),
|
|
58
|
+
};
|
|
59
|
+
return { input, publics: [p.root, commit, bindLo, bindHi] };
|
|
60
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
export declare const KEEPER_FIELDS_LEN =
|
|
1
|
+
export declare const KEEPER_FIELDS_LEN = 194;
|
|
2
2
|
export declare const KEEPER_PLAIN_LEN = 288;
|
|
3
3
|
export declare const FLAG_TERMS = 1;
|
|
4
|
+
/** The whole terms: what the borrower and the lender hold, never a keeper. */
|
|
4
5
|
export type KeeperTerms = {
|
|
5
6
|
principal: bigint;
|
|
6
7
|
rateBps: bigint;
|
|
@@ -11,9 +12,26 @@ export type KeeperTerms = {
|
|
|
11
12
|
lenderEncY: bigint;
|
|
12
13
|
salt: bigint;
|
|
13
14
|
};
|
|
14
|
-
/**
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
/**
|
|
16
|
+
* PRV-25 (c), Z1 D18: what a seizure folds of the terms. `hRest` stands for the principal, the rate, the lender's
|
|
17
|
+
* enc point and the salt (`circuits/v3/lib/terms2.circom` TermsRest), so a keeper never learns them.
|
|
18
|
+
*/
|
|
19
|
+
export type KeeperView = {
|
|
20
|
+
owed: bigint;
|
|
21
|
+
maturityS: bigint;
|
|
22
|
+
lenderPk: bigint;
|
|
23
|
+
hRest: bigint;
|
|
24
|
+
};
|
|
25
|
+
/** A clear terms flag: `keeper.move` opens rebuilds the commit from the zero block, hRest 0 included. */
|
|
26
|
+
export declare const NO_VIEW: KeeperView;
|
|
27
|
+
export declare const keeperView: (t: KeeperTerms) => KeeperView;
|
|
28
|
+
/** The terms commit a keeper rebuilds from its view alone, as `keeper.move` opens does. */
|
|
29
|
+
export declare const viewCommit: (v: KeeperView, borrowerPk: bigint) => bigint;
|
|
30
|
+
/** What a seizure's witness takes as terms: the view's fields, and 0 for every field `hRest` stands for. */
|
|
31
|
+
export declare const viewTerms: (v: KeeperView) => KeeperTerms;
|
|
32
|
+
/** The plaintext layout version (B §7.3), `keeper.move` LAYOUT. It is not the on-chain `keeper_ct_version`, which counts rewrites. */
|
|
33
|
+
export declare const KEEPER_LAYOUT_VERSION = 2;
|
|
34
|
+
/** `terms` absent means the flag is clear and the 80-byte terms block is zero. */
|
|
17
35
|
export type KeeperPayload = {
|
|
18
36
|
version: number;
|
|
19
37
|
loanKey: bigint;
|
|
@@ -21,7 +39,11 @@ export type KeeperPayload = {
|
|
|
21
39
|
collAmt: bigint;
|
|
22
40
|
collBlind: bigint;
|
|
23
41
|
nonceAtCt: bigint;
|
|
24
|
-
terms?:
|
|
42
|
+
terms?: KeeperView;
|
|
43
|
+
};
|
|
44
|
+
/** A writer holds the whole terms; only their keeper view is written. */
|
|
45
|
+
export type KeeperPayloadInput = Omit<KeeperPayload, "terms"> & {
|
|
46
|
+
terms?: KeeperTerms | KeeperView;
|
|
25
47
|
};
|
|
26
48
|
export type DecodedKeeperPayload = {
|
|
27
49
|
ok: true;
|
|
@@ -30,7 +52,7 @@ export type DecodedKeeperPayload = {
|
|
|
30
52
|
ok: false;
|
|
31
53
|
error: string;
|
|
32
54
|
};
|
|
33
|
-
/** Field elements and u64 are big-endian. Always 288 bytes:
|
|
34
|
-
export declare function encodeKeeperPayload(p:
|
|
55
|
+
/** Field elements and u64 are big-endian. Always 288 bytes: 194 of fields, 94 of zero pad (`keeper.move` opens). */
|
|
56
|
+
export declare function encodeKeeperPayload(p: KeeperPayloadInput): Uint8Array;
|
|
35
57
|
export declare function decodeKeeperPayload(bytes: Uint8Array): DecodedKeeperPayload;
|
|
36
58
|
//# sourceMappingURL=keeper-payload.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keeper-payload.d.ts","sourceRoot":"","sources":["../../src/v3/keeper-payload.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"keeper-payload.d.ts","sourceRoot":"","sources":["../../src/v3/keeper-payload.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,iBAAiB,MAAM,CAAC;AACrC,eAAO,MAAM,gBAAgB,MAAM,CAAC;AACpC,eAAO,MAAM,UAAU,IAAI,CAAC;AAK5B,8EAA8E;AAC9E,MAAM,MAAM,WAAW,GAAG;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAE9F,yGAAyG;AACzG,eAAO,MAAM,OAAO,EAAE,UAAiE,CAAC;AAExF,eAAO,MAAM,UAAU,GAAI,GAAG,WAAW,KAAG,UAK1C,CAAC;AAEH,2FAA2F;AAC3F,eAAO,MAAM,UAAU,GAAI,GAAG,UAAU,EAAE,YAAY,MAAM,WAAuC,CAAC;AAEpG,4GAA4G;AAC5G,eAAO,MAAM,SAAS,GAAI,GAAG,UAAU,KAAG,WASxC,CAAC;AAEH,sIAAsI;AACtI,eAAO,MAAM,qBAAqB,IAAI,CAAC;AAEvC,kFAAkF;AAClF,MAAM,MAAM,aAAa,GAAG;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,UAAU,CAAC;CACpB,CAAC;AAEF,yEAAyE;AACzE,MAAM,MAAM,kBAAkB,GAAG,IAAI,CAAC,aAAa,EAAE,OAAO,CAAC,GAAG;IAAE,KAAK,CAAC,EAAE,WAAW,GAAG,UAAU,CAAA;CAAE,CAAC;AAErG,MAAM,MAAM,oBAAoB,GAAG;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,OAAO,EAAE,aAAa,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAgDvG,oHAAoH;AACpH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,kBAAkB,GAAG,UAAU,CAgBrE;AAQD,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,UAAU,GAAG,oBAAoB,CAyB3E"}
|
|
@@ -1,11 +1,33 @@
|
|
|
1
|
+
import { termsOuter, termsRest } from "./collateral/openings.js";
|
|
1
2
|
import { R } from "./domains.js";
|
|
2
|
-
export const KEEPER_FIELDS_LEN =
|
|
3
|
+
export const KEEPER_FIELDS_LEN = 194;
|
|
3
4
|
export const KEEPER_PLAIN_LEN = 288;
|
|
4
5
|
export const FLAG_TERMS = 1;
|
|
5
6
|
const TERMS_AT = 114;
|
|
6
7
|
const U64_MAX = (1n << 64n) - 1n;
|
|
7
|
-
/**
|
|
8
|
-
export const
|
|
8
|
+
/** A clear terms flag: `keeper.move` opens rebuilds the commit from the zero block, hRest 0 included. */
|
|
9
|
+
export const NO_VIEW = { owed: 0n, maturityS: 0n, lenderPk: 0n, hRest: 0n };
|
|
10
|
+
export const keeperView = (t) => ({
|
|
11
|
+
owed: t.owed,
|
|
12
|
+
maturityS: t.maturityS,
|
|
13
|
+
lenderPk: t.lenderPk,
|
|
14
|
+
hRest: termsRest(t),
|
|
15
|
+
});
|
|
16
|
+
/** The terms commit a keeper rebuilds from its view alone, as `keeper.move` opens does. */
|
|
17
|
+
export const viewCommit = (v, borrowerPk) => termsOuter(v, borrowerPk, v.hRest);
|
|
18
|
+
/** What a seizure's witness takes as terms: the view's fields, and 0 for every field `hRest` stands for. */
|
|
19
|
+
export const viewTerms = (v) => ({
|
|
20
|
+
principal: 0n,
|
|
21
|
+
rateBps: 0n,
|
|
22
|
+
owed: v.owed,
|
|
23
|
+
maturityS: v.maturityS,
|
|
24
|
+
lenderPk: v.lenderPk,
|
|
25
|
+
lenderEncX: 0n,
|
|
26
|
+
lenderEncY: 0n,
|
|
27
|
+
salt: 0n,
|
|
28
|
+
});
|
|
29
|
+
/** The plaintext layout version (B §7.3), `keeper.move` LAYOUT. It is not the on-chain `keeper_ct_version`, which counts rewrites. */
|
|
30
|
+
export const KEEPER_LAYOUT_VERSION = 2;
|
|
9
31
|
class Writer {
|
|
10
32
|
out = new Uint8Array(KEEPER_PLAIN_LEN);
|
|
11
33
|
at = 0;
|
|
@@ -50,7 +72,8 @@ class Reader {
|
|
|
50
72
|
return value;
|
|
51
73
|
}
|
|
52
74
|
}
|
|
53
|
-
|
|
75
|
+
const viewOf = (t) => ("hRest" in t ? t : keeperView(t));
|
|
76
|
+
/** Field elements and u64 are big-endian. Always 288 bytes: 194 of fields, 94 of zero pad (`keeper.move` opens). */
|
|
54
77
|
export function encodeKeeperPayload(p) {
|
|
55
78
|
const w = new Writer();
|
|
56
79
|
w.u8(p.version, "version");
|
|
@@ -62,27 +85,15 @@ export function encodeKeeperPayload(p) {
|
|
|
62
85
|
w.u64(p.nonceAtCt, "nonceAtCt");
|
|
63
86
|
if (!p.terms)
|
|
64
87
|
return w.out;
|
|
65
|
-
|
|
66
|
-
w.u64(
|
|
67
|
-
w.u64(
|
|
68
|
-
w.
|
|
69
|
-
w.field(
|
|
70
|
-
w.field(p.terms.lenderEncX, "lenderEncX");
|
|
71
|
-
w.field(p.terms.lenderEncY, "lenderEncY");
|
|
72
|
-
w.field(p.terms.salt, "salt");
|
|
88
|
+
const t = viewOf(p.terms);
|
|
89
|
+
w.u64(t.owed, "owed");
|
|
90
|
+
w.u64(t.maturityS, "maturityS");
|
|
91
|
+
w.field(t.lenderPk, "lenderPk");
|
|
92
|
+
w.field(t.hRest, "hRest");
|
|
73
93
|
return w.out;
|
|
74
94
|
}
|
|
75
95
|
function readTerms(r) {
|
|
76
|
-
return {
|
|
77
|
-
principal: r.u64(),
|
|
78
|
-
rateBps: r.u64(),
|
|
79
|
-
owed: r.u64(),
|
|
80
|
-
maturityS: r.u64(),
|
|
81
|
-
lenderPk: r.field("lenderPk"),
|
|
82
|
-
lenderEncX: r.field("lenderEncX"),
|
|
83
|
-
lenderEncY: r.field("lenderEncY"),
|
|
84
|
-
salt: r.field("salt"),
|
|
85
|
-
};
|
|
96
|
+
return { owed: r.u64(), maturityS: r.u64(), lenderPk: r.field("lenderPk"), hRest: r.field("hRest") };
|
|
86
97
|
}
|
|
87
98
|
const allZero = (bytes) => bytes.every((byte) => byte === 0);
|
|
88
99
|
export function decodeKeeperPayload(bytes) {
|
package/dist/v3/kinds.d.ts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
/** Verifier kind ids, the global namespace of master §2.3. */
|
|
1
|
+
/** Verifier kind ids, the global namespace of master §2.3. Z1 retired 1 (lock_bid) and 12 (loan_offer). */
|
|
2
2
|
export declare const VK: {
|
|
3
|
-
readonly lockBid: 1;
|
|
4
3
|
readonly saleSettle: 2;
|
|
5
4
|
readonly reclaim: 3;
|
|
6
5
|
readonly itemClaim: 4;
|
|
7
6
|
readonly js4: 10;
|
|
8
7
|
readonly deposit: 11;
|
|
9
|
-
readonly loanOffer: 12;
|
|
10
8
|
readonly loanSettle: 13;
|
|
11
9
|
readonly loanRepay: 14;
|
|
12
10
|
readonly loanRefi: 15;
|
|
@@ -14,12 +12,14 @@ export declare const VK: {
|
|
|
14
12
|
readonly reclaimColl: 17;
|
|
15
13
|
readonly health: 20;
|
|
16
14
|
readonly membership: 30;
|
|
15
|
+
readonly fundsRead: 31;
|
|
17
16
|
};
|
|
18
17
|
/**
|
|
19
|
-
* The relayed kinds of master §2.6
|
|
20
|
-
*
|
|
18
|
+
* The relayed kinds of master §2.6 that target the current packages; the relayer's `_previous` twins drain the
|
|
19
|
+
* R1 packages and are not built here. Deposit and sale open are sponsored edges, not relay kinds. Z1: an offer or a
|
|
20
|
+
* bid is a `transfer`, and `loan_reclaim` is the one reclaim for both.
|
|
21
21
|
*/
|
|
22
|
-
export declare const RELAY_KINDS: readonly ["transfer", "withdraw", "loan_open", "
|
|
22
|
+
export declare const RELAY_KINDS: readonly ["transfer", "withdraw", "loan_open", "loan_settle", "loan_repay", "loan_reclaim", "loan_reclaim_coll", "loan_cancel", "loan_cancel_refi", "loan_refinance", "loan_settle_refi", "loan_ct_fault", "loan_heartbeat", "loan_topup", "loan_topup_borrower", "loan_liquidate", "loan_claim_default", "loan_release", "loan_fault_liquidate", "sale_finish", "sale_expire", "sale_claim_item", "sale_cancel"];
|
|
23
23
|
export type RelayKind = (typeof RELAY_KINDS)[number];
|
|
24
24
|
/** E-27: every note ciphertext is exactly 128 bytes. */
|
|
25
25
|
export declare const ENC_BYTES = 128;
|
package/dist/v3/kinds.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kinds.d.ts","sourceRoot":"","sources":["../../src/v3/kinds.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"kinds.d.ts","sourceRoot":"","sources":["../../src/v3/kinds.ts"],"names":[],"mappings":"AAAA,2GAA2G;AAC3G,eAAO,MAAM,EAAE;;;;;;;;;;;;;;CAcL,CAAC;AAEX;;;;GAIG;AACH,eAAO,MAAM,WAAW,mZAwBd,CAAC;AAEX,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAErD,wDAAwD;AACxD,eAAO,MAAM,SAAS,MAAM,CAAC"}
|