@esseyonsui/sui-sdk-v3 0.3.2 → 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/network.d.ts +2 -0
- package/dist/network.d.ts.map +1 -1
- package/dist/network.js +17 -3
- 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/relay/client.d.ts.map +1 -1
- package/dist/v3/relay/client.js +2 -2
- 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
package/dist/v3/sales/rows.js
CHANGED
|
@@ -1,100 +1,26 @@
|
|
|
1
1
|
import { poseidonHash } from "@mysten/sui/zklogin";
|
|
2
|
-
import { blake2b } from "@noble/hashes/blake2.js";
|
|
3
2
|
import { keccak_256 } from "@noble/hashes/sha3.js";
|
|
4
|
-
import { DOM_BID,
|
|
3
|
+
import { DOM_BID, R } from "../domains.js";
|
|
5
4
|
import { ENC_BYTES } from "../kinds.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export const SLOTS = 16;
|
|
13
|
-
/** `sale_room.move` BID_BLOB_LEN. */
|
|
14
|
-
export const BID_PLAIN_BYTES = 144;
|
|
15
|
-
const SBID_TAG = Buffer.from("ess3/sbid/", "ascii");
|
|
16
|
-
/** `sale_room.move` FIRST_BID_PAIRS: the first bid also reserves settlement's pair and the residual's. */
|
|
17
|
-
const FIRST_BID_PAIRS = 3;
|
|
18
|
-
const keccakModR = (bytes) => BigInt(`0x${Buffer.from(keccak_256(Uint8Array.from(bytes))).toString("hex")}`) % R;
|
|
19
|
-
export function padSlots(xs) {
|
|
20
|
-
if (xs.length > SLOTS)
|
|
21
|
-
throw new Error("a room holds at most 16 bids");
|
|
22
|
-
return Array.from({ length: SLOTS }, (_, i) => xs[i] ?? 0n);
|
|
5
|
+
import { bidBlind } from "../locks.js";
|
|
6
|
+
import { bcsBytes } from "./bcs.js";
|
|
7
|
+
/** The bid's keys from the note key at its reserved index: the offer `ns` (`offerKeys`) and a blind over it alone. */
|
|
8
|
+
export function bidSecrets(own) {
|
|
9
|
+
const ns = poseidonHash([own.sk, own.blinding, 3n]);
|
|
10
|
+
return { ownerSk: own.sk, ns, b: bidBlind(ns) };
|
|
23
11
|
}
|
|
24
|
-
|
|
12
|
+
function uleb(n) {
|
|
13
|
+
const out = [];
|
|
14
|
+
for (; n >= 0x80; n >>>= 7)
|
|
15
|
+
out.push((n & 0x7f) | 0x80);
|
|
16
|
+
return [...out, n];
|
|
17
|
+
}
|
|
18
|
+
/** `rows::enc_hash`: keccak256(bcs(encs)) read big-endian, mod R; every ciphertext is 128 bytes. */
|
|
25
19
|
export function encHash(encs) {
|
|
26
20
|
if (encs.some((e) => e.length !== ENC_BYTES))
|
|
27
21
|
throw new Error("a note ciphertext is 128 bytes");
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
/** E-2, `lib/lock.circom` Lock4, with the lock's nullifier N. */
|
|
31
|
-
export function lock4(field, ownerPk, ns, amount, b) {
|
|
32
|
-
const lock = lockOf(field, ownerPk, ns, amount, b);
|
|
33
|
-
return { lock, nullifier: poseidonHash([DOM_LNULL, ns, lock]) };
|
|
34
|
-
}
|
|
35
|
-
/** C §4.4: the winner's change, a lock whose `ns` and blinding both derive from the bid's `ns`. */
|
|
36
|
-
export function residualLock(field, ownerPk, ns, amount) {
|
|
37
|
-
const nsEff = poseidonHash([DOM_RESID, ns]);
|
|
38
|
-
const b = poseidonHash([DOM_RBLIND, ns]);
|
|
39
|
-
return { nsEff, b, ...lock4(field, ownerPk, nsEff, amount, b) };
|
|
22
|
+
const bytes = Uint8Array.from([...uleb(encs.length), ...encs.flatMap((e) => bcsBytes(e))]);
|
|
23
|
+
return BigInt(`0x${Buffer.from(keccak_256(bytes)).toString("hex")}`) % R;
|
|
40
24
|
}
|
|
25
|
+
/** PRV-24 A: `posted_commit = Poseidon3(DOM_BID, price, s*)`. */
|
|
41
26
|
export const bidCommit = (v, s) => poseidonHash([DOM_BID, v, s]);
|
|
42
|
-
/** `sale_room::ext_hash`: keccak256(bcs(ExtLockBid)) mod R, the digest read big-endian. */
|
|
43
|
-
export function bidExt(x) {
|
|
44
|
-
assertMemo(x.memo);
|
|
45
|
-
return keccakModR([
|
|
46
|
-
...bcsBytes(SBID_TAG),
|
|
47
|
-
...addressBytes(x.room, "room"),
|
|
48
|
-
...le(BigInt(x.seq), 8, "seq"),
|
|
49
|
-
...addressBytes(x.relayer, "relayer"),
|
|
50
|
-
...le(x.relayerFee, 8, "relayerFee"),
|
|
51
|
-
x.seq === 0 ? FIRST_BID_PAIRS : 1,
|
|
52
|
-
...le(x.commit, 32, "commit"),
|
|
53
|
-
...bcsBytes(blake2b(Uint8Array.from([...x.sealed, ...x.memo]), { dkLen: 32 })),
|
|
54
|
-
...le(encHash(x.encs), 32, "encHash"),
|
|
55
|
-
]);
|
|
56
|
-
}
|
|
57
|
-
const blake = (bytes) => blake2b(Uint8Array.from(bytes), { dkLen: 32 });
|
|
58
|
-
/** `sale_room::bid_key_id`: blake2b256("ess3/bid" ‖ bcs(sale_key) ‖ bcs(seq)), the Seal id `pin_bid` requires. */
|
|
59
|
-
export const bidKeyId = (saleKey, seq) => blake([...Buffer.from("ess3/bid", "ascii"), ...le(saleKey, 32, "saleKey"), ...le(seq, 8, "seq")]);
|
|
60
|
-
/** `pin_bid`'s aad: bcs(n0), the note the bid spends. */
|
|
61
|
-
export const bidAad = (n0) => Uint8Array.from(le(n0, 32, "n0"));
|
|
62
|
-
/** `membership::seal_bid(room, seq, viewer).bind`, the pass `seal_approve_bid` checks. */
|
|
63
|
-
export const sealBidBind = (room, seq, viewer) => blake([
|
|
64
|
-
...Buffer.from("essey-v3/seal/bid", "ascii"),
|
|
65
|
-
...addressBytes(room, "room"),
|
|
66
|
-
...le(seq, 8, "seq"),
|
|
67
|
-
...addressBytes(viewer, "viewer"),
|
|
68
|
-
]);
|
|
69
|
-
/** C §7.1 plaintext, in the order `sale_room::opens` peels it: v ‖ s ‖ ns ‖ amount ‖ b ‖ ownerPk. */
|
|
70
|
-
export function bidPlaintext(x) {
|
|
71
|
-
return Uint8Array.from([
|
|
72
|
-
...le(x.v, 8, "v"),
|
|
73
|
-
...le(x.s, 32, "s"),
|
|
74
|
-
...le(x.ns, 32, "ns"),
|
|
75
|
-
...le(x.amount, 8, "amount"),
|
|
76
|
-
...le(x.b, 32, "b"),
|
|
77
|
-
...le(notePk(x.ownerSk), 32, "ownerPk"),
|
|
78
|
-
]);
|
|
79
|
-
}
|
|
80
|
-
/** `sale_room::opens`: the opening when the plaintext gives both the commit and the lock. */
|
|
81
|
-
export function openBid(plain, field, commit, lock) {
|
|
82
|
-
if (plain?.length !== BID_PLAIN_BYTES)
|
|
83
|
-
return undefined;
|
|
84
|
-
const at = (from, size) => {
|
|
85
|
-
const be = Buffer.from(plain.subarray(from, from + size)).reverse();
|
|
86
|
-
return BigInt(`0x${be.toString("hex")}`);
|
|
87
|
-
};
|
|
88
|
-
const o = {
|
|
89
|
-
v: at(0, 8),
|
|
90
|
-
s: at(8, 32),
|
|
91
|
-
ns: at(40, 32),
|
|
92
|
-
amount: at(72, 8),
|
|
93
|
-
b: at(80, 32),
|
|
94
|
-
ownerPk: at(112, 32),
|
|
95
|
-
};
|
|
96
|
-
if ([o.s, o.ns, o.b, o.ownerPk].some((x) => x >= R))
|
|
97
|
-
return undefined;
|
|
98
|
-
const opens = bidCommit(o.v, o.s) === commit && lock4(field, o.ownerPk, o.ns, o.amount, o.b).lock === lock;
|
|
99
|
-
return opens ? o : undefined;
|
|
100
|
-
}
|
|
@@ -16,13 +16,11 @@ export type OpenArgs = {
|
|
|
16
16
|
};
|
|
17
17
|
sellerCommit: bigint;
|
|
18
18
|
sellerItemFallback: bigint;
|
|
19
|
-
boundsCommit: bigint;
|
|
20
19
|
postedCommit: bigint;
|
|
21
20
|
listing: Uint8Array;
|
|
22
21
|
memo: Uint8Array;
|
|
23
22
|
closeMs: bigint;
|
|
24
23
|
finishByMs: bigint;
|
|
25
|
-
maxBids: number;
|
|
26
24
|
};
|
|
27
25
|
/**
|
|
28
26
|
* `sale_room::check_grid` (44_041) counts the bid window from `round_up(chain now)`, so the open must land after
|
|
@@ -40,12 +38,11 @@ export declare function saleTimes(p: {
|
|
|
40
38
|
landFromMs: bigint;
|
|
41
39
|
landByMs: bigint;
|
|
42
40
|
};
|
|
43
|
-
/** `sale_room::open_args` (`sale_room.move
|
|
41
|
+
/** `sale_room::open_args` (lane S `sale_room.move` open_args), the bytes the seller pass signs. */
|
|
44
42
|
export declare function openArgs(p: OpenArgs): Uint8Array;
|
|
45
43
|
export type SaleSecrets = {
|
|
46
44
|
sellerSk: bigint;
|
|
47
45
|
sellerSecret: bigint;
|
|
48
|
-
boundsSalt: bigint;
|
|
49
46
|
postedSalt: bigint;
|
|
50
47
|
};
|
|
51
48
|
/** The seller's room secrets from the note key it reserved, so the seed alone reopens them. */
|
|
@@ -53,11 +50,10 @@ export declare function saleSecrets(own: {
|
|
|
53
50
|
sk: bigint;
|
|
54
51
|
blinding: bigint;
|
|
55
52
|
}): SaleSecrets;
|
|
56
|
-
/** The
|
|
53
|
+
/** The three commits `sale_room::open` stores. PRV-24 A: the posted commit is the price SaleSettle charges. */
|
|
57
54
|
export declare function openCommits(s: SaleSecrets, price: bigint): {
|
|
58
55
|
sellerCommit: bigint;
|
|
59
56
|
sellerItemFallback: bigint;
|
|
60
|
-
boundsCommit: bigint;
|
|
61
57
|
postedCommit: bigint;
|
|
62
58
|
};
|
|
63
59
|
//# sourceMappingURL=seller.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"seller.d.ts","sourceRoot":"","sources":["../../../src/v3/sales/seller.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"seller.d.ts","sourceRoot":"","sources":["../../../src/v3/sales/seller.ts"],"names":[],"mappings":"AAYA,yFAAyF;AACzF,eAAO,MAAM,YAAY,SAAU,CAAC;AAQpC;;;GAGG;AACH,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
|
2
2
|
import { blake2b } from "@noble/hashes/blake2.js";
|
|
3
|
-
import {
|
|
3
|
+
import { DOM_SELLER, R } from "../domains.js";
|
|
4
4
|
import { notePk } from "../notes/keys.js";
|
|
5
5
|
import { BID_WINDOW_STEPS, FINISH_WINDOW_STEPS } from "../time-grid.js";
|
|
6
6
|
import { addressBytes, bcsBytes, le } from "./bcs.js";
|
|
7
7
|
import { fallbackSalt, itemClaimCommit } from "./claim.js";
|
|
8
8
|
import { postedCommit } from "./listing.js";
|
|
9
9
|
import { assertMemo } from "./memo.js";
|
|
10
|
-
import { SLOTS } from "./rows.js";
|
|
11
10
|
/** `sale_room.move` CLOSE_STEP_MS: Move's grid, whatever step the config gives loans. */
|
|
12
11
|
export const SALE_STEP_MS = 300_000;
|
|
13
12
|
/** `sale_room.move` MAX_LISTING_LEN. */
|
|
@@ -44,20 +43,17 @@ export function saleTimes(p) {
|
|
|
44
43
|
const closeMs = base + bid * step;
|
|
45
44
|
return { closeMs, finishByMs: closeMs + finish * step, landFromMs: base - step + 1n, landByMs: base };
|
|
46
45
|
}
|
|
47
|
-
/** `sale_room::open_args` (`sale_room.move
|
|
46
|
+
/** `sale_room::open_args` (lane S `sale_room.move` open_args), the bytes the seller pass signs. */
|
|
48
47
|
export function openArgs(p) {
|
|
49
48
|
if (p.saleKey <= 0n || p.saleKey >= R)
|
|
50
49
|
throw new Error("saleKey is not a sale key");
|
|
51
50
|
for (const [what, x] of Object.entries({
|
|
52
51
|
sellerCommit: p.sellerCommit,
|
|
53
52
|
sellerItemFallback: p.sellerItemFallback,
|
|
54
|
-
boundsCommit: p.boundsCommit,
|
|
55
53
|
postedCommit: p.postedCommit,
|
|
56
54
|
}))
|
|
57
55
|
if (x < 0n || x >= R)
|
|
58
56
|
throw new Error(`${what} is not a field element`);
|
|
59
|
-
if (!Number.isInteger(p.maxBids) || p.maxBids < 1 || p.maxBids > SLOTS)
|
|
60
|
-
throw new Error("maxBids is not 1 to 16");
|
|
61
57
|
if (p.listing.length < 1 || p.listing.length > MAX_LISTING_BYTES)
|
|
62
58
|
throw new Error("the sealed listing is not 1 to 2048 bytes");
|
|
63
59
|
assertMemo(p.memo);
|
|
@@ -66,13 +62,11 @@ export function openArgs(p) {
|
|
|
66
62
|
...addressBytes(p.pool, "pool"),
|
|
67
63
|
...le(p.sellerCommit, 32, "sellerCommit"),
|
|
68
64
|
...le(p.sellerItemFallback, 32, "sellerItemFallback"),
|
|
69
|
-
...le(p.boundsCommit, 32, "boundsCommit"),
|
|
70
65
|
...le(p.postedCommit, 32, "postedCommit"),
|
|
71
66
|
...blake2b(p.listing, { dkLen: 32 }),
|
|
72
67
|
...p.memo,
|
|
73
68
|
...le(p.closeMs, 8, "closeMs"),
|
|
74
69
|
...le(p.finishByMs, 8, "finishByMs"),
|
|
75
|
-
...le(BigInt(p.maxBids), 8, "maxBids"),
|
|
76
70
|
...addressBytes(p.item.id, "item"),
|
|
77
71
|
...bcsBytes(Uint8Array.from(ascii(p.item.typeName))),
|
|
78
72
|
]);
|
|
@@ -80,15 +74,14 @@ export function openArgs(p) {
|
|
|
80
74
|
/** The seller's room secrets from the note key it reserved, so the seed alone reopens them. */
|
|
81
75
|
export function saleSecrets(own) {
|
|
82
76
|
const tagged = (t) => poseidonHash([own.sk, own.blinding, t]);
|
|
83
|
-
return { sellerSk: own.sk, sellerSecret: tagged(7n),
|
|
77
|
+
return { sellerSk: own.sk, sellerSecret: tagged(7n), postedSalt: tagged(9n) };
|
|
84
78
|
}
|
|
85
|
-
/** The
|
|
79
|
+
/** The three commits `sale_room::open` stores. PRV-24 A: the posted commit is the price SaleSettle charges. */
|
|
86
80
|
export function openCommits(s, price) {
|
|
87
81
|
const sellerPk = notePk(s.sellerSk);
|
|
88
82
|
return {
|
|
89
83
|
sellerCommit: poseidonHash([DOM_SELLER, sellerPk, poseidonHash([s.sellerSecret])]),
|
|
90
84
|
sellerItemFallback: itemClaimCommit(sellerPk, fallbackSalt(s.sellerSecret)),
|
|
91
|
-
boundsCommit: poseidonHash([DOM_BOUNDS, price, price, s.boundsSalt]),
|
|
92
85
|
postedCommit: postedCommit({ price, salt: s.postedSalt }),
|
|
93
86
|
};
|
|
94
87
|
}
|
package/dist/v3/stage1.d.ts
CHANGED
|
@@ -34,7 +34,6 @@ export type OpenRequest = {
|
|
|
34
34
|
round: bigint;
|
|
35
35
|
/** From the current `Round`. Null when that dynamic field was not supplied. */
|
|
36
36
|
closeMs: bigint | null;
|
|
37
|
-
offers: number | null;
|
|
38
37
|
loanCoin: CoinKey;
|
|
39
38
|
collateralCoin: CoinKey;
|
|
40
39
|
};
|
|
@@ -86,20 +85,16 @@ export type LoanOpening = {
|
|
|
86
85
|
request?: ReqOpening;
|
|
87
86
|
terms?: KeeperTerms;
|
|
88
87
|
};
|
|
89
|
-
/** D-SPEC §6.2:600. Public fields of a sealed sale room. */
|
|
88
|
+
/** D-SPEC §6.2:600. Public fields of a sealed sale room; since PRV-28 B+C a room holds no bid count. */
|
|
90
89
|
export type OpenSale = {
|
|
91
90
|
id: string;
|
|
92
91
|
coin: CoinKey;
|
|
93
92
|
state: number;
|
|
94
93
|
closeMs: bigint;
|
|
95
|
-
bids: number;
|
|
96
94
|
};
|
|
97
|
-
/** D-SPEC §6.2:600.
|
|
95
|
+
/** D-SPEC §6.2:600. */
|
|
98
96
|
export type MySaleView = OpenSale & {
|
|
99
97
|
finishByMs: bigint;
|
|
100
|
-
maxBids: bigint;
|
|
101
|
-
minPrice: bigint | null;
|
|
102
|
-
maxPrice: bigint | null;
|
|
103
98
|
};
|
|
104
99
|
/** D-SPEC §6.2:599. */
|
|
105
100
|
export type SaleOpenParams = {
|
|
@@ -111,7 +106,6 @@ export type SaleOpenParams = {
|
|
|
111
106
|
/** How long bids are taken, on the bid-window set of `sales/seller.ts` saleTimes. */
|
|
112
107
|
bidWindowMs: number;
|
|
113
108
|
finishWindowMs: number;
|
|
114
|
-
maxBids: number;
|
|
115
109
|
/** Absent: the relayer pays when one with an address is set up, else `submitSaleOpen` does. */
|
|
116
110
|
sponsored?: boolean;
|
|
117
111
|
};
|
|
@@ -147,8 +141,6 @@ export declare function assertCoin(coin: unknown): asserts coin is CoinKey;
|
|
|
147
141
|
export declare function poolId(config: V3Config, coin: CoinKey): string;
|
|
148
142
|
export declare function coinByPool(config: V3Config, pool: string): CoinKey;
|
|
149
143
|
export declare function requireSale(config: V3Config): void;
|
|
150
|
-
/** C-SPEC (`v3/docs/specs/C-SPEC.md:179`): Poseidon4(DOM_BOUNDS, lo, hi, boundsSalt). */
|
|
151
|
-
export declare function boundsCommit(lo: bigint, hi: bigint, salt: bigint): bigint;
|
|
152
144
|
/** D-SPEC §6.2:582. Opens one ciphertext. A commitment that does not rebuild is tampered. */
|
|
153
145
|
export declare function openPosition(coin: CoinKey, index: number, events: PoolEvents, seed: Uint8Array): PoolPosition;
|
|
154
146
|
/** D-SPEC §6.2:582. The same open, plus the commitment the chain published. */
|
|
@@ -176,24 +168,19 @@ export declare function summarizeRoom(config: V3Config, row: {
|
|
|
176
168
|
id: string;
|
|
177
169
|
json: unknown;
|
|
178
170
|
}): OpenSale;
|
|
179
|
-
/** D-SPEC §6.2:600.
|
|
180
|
-
export declare
|
|
171
|
+
/** D-SPEC §6.2:600. */
|
|
172
|
+
export declare const viewRoomObject: (config: V3Config, row: {
|
|
181
173
|
id: string;
|
|
182
174
|
json: unknown;
|
|
183
|
-
}
|
|
184
|
-
lo: bigint;
|
|
185
|
-
hi: bigint;
|
|
186
|
-
salt: bigint;
|
|
187
|
-
} | null): MySaleView;
|
|
175
|
+
}) => MySaleView;
|
|
188
176
|
/** D-SPEC §6.2:588. Refuses before any envelope is built. */
|
|
189
177
|
export declare function assertLoanOpen(p: LoanOpenParams): void;
|
|
190
|
-
/** D-SPEC §6.2:599. Copies each argument once.
|
|
178
|
+
/** D-SPEC §6.2:599. Copies each argument once. */
|
|
191
179
|
export declare function assertSaleOpen(p: SaleOpenParams): SaleOpenParams;
|
|
192
180
|
/**
|
|
193
|
-
* The room the sponsor named is this open: same coin pool, close
|
|
194
|
-
* (`sale_room.move:181-193`).
|
|
181
|
+
* The room the sponsor named is this open: same coin pool, close and finish window (`sale_room.move:98-113`).
|
|
195
182
|
*/
|
|
196
|
-
export declare function assertRoomMatches(config: V3Config, open: Pick<SaleOpenParams, "coin" | "finishWindowMs"
|
|
183
|
+
export declare function assertRoomMatches(config: V3Config, open: Pick<SaleOpenParams, "coin" | "finishWindowMs"> & {
|
|
197
184
|
closeMs: number;
|
|
198
185
|
}, row: {
|
|
199
186
|
id: string;
|
package/dist/v3/stage1.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stage1.d.ts","sourceRoot":"","sources":["../../src/v3/stage1.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"stage1.d.ts","sourceRoot":"","sources":["../../src/v3/stage1.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AAGlE,OAAO,EAAE,SAAS,EAAW,cAAc,EAAiB,MAAM,sBAAsB,CAAC;AAEzF,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,CAAC;AAErC,OAAO,EAIL,KAAK,WAAW,EAChB,KAAK,UAAU,EAChB,MAAM,0BAA0B,CAAC;AAElC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAIpD,OAAO,EAAsC,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAEtF;;;;;;;;;;;GAWG;AAEH,0FAA0F;AAC1F,MAAM,MAAM,YAAY,GAAG;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAE3E,8FAA8F;AAC9F,MAAM,MAAM,QAAQ,GAAG,YAAY,GAAG;IAAE,UAAU,EAAE,MA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I,EAAE,OAAO,CAAA;CAAE,GACjC,IAAI,CAKN;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,cAAc,GAAG,gBAAgB,CA6BvE"}
|
package/dist/v3/stage1.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { poseidonHash } from "@mysten/sui/zklogin";
|
|
2
1
|
import { COINS } from "../config.js";
|
|
3
2
|
import { EsseyError } from "../errors.js";
|
|
4
3
|
import { address, decimal } from "../network.js";
|
|
@@ -6,7 +5,7 @@ import { afterPage, covered, MAX_LIST_PAGES } from "./collateral/scan.js";
|
|
|
6
5
|
export { afterPage, MAX_LIST_PAGES };
|
|
7
6
|
import { localHealth } from "./collateral/local-health.js";
|
|
8
7
|
import { collNote, requestCommit, termsCommit, } from "./collateral/openings.js";
|
|
9
|
-
import {
|
|
8
|
+
import { R } from "./domains.js";
|
|
10
9
|
import { deriveNoteKey, noteEncKey } from "./notes/derive.js";
|
|
11
10
|
import { noteCommitment, noteNullifier, notePk } from "./notes/keys.js";
|
|
12
11
|
import { openOpening } from "./notes/opening.js";
|
|
@@ -27,7 +26,6 @@ export const LOAN_LIFECYCLE = [
|
|
|
27
26
|
"cancelled",
|
|
28
27
|
"refi",
|
|
29
28
|
];
|
|
30
|
-
const MAX_BIDS = 16;
|
|
31
29
|
function missing(what) {
|
|
32
30
|
throw new EsseyError("NOT_SET_UP", `missing config: ${what}`);
|
|
33
31
|
}
|
|
@@ -172,16 +170,6 @@ function u8(value, what) {
|
|
|
172
170
|
tampered();
|
|
173
171
|
return Number(n);
|
|
174
172
|
}
|
|
175
|
-
function count(value, what) {
|
|
176
|
-
const n = whole(value, what);
|
|
177
|
-
if (n > BigInt(Number.MAX_SAFE_INTEGER))
|
|
178
|
-
tampered();
|
|
179
|
-
return Number(n);
|
|
180
|
-
}
|
|
181
|
-
/** C-SPEC (`v3/docs/specs/C-SPEC.md:179`): Poseidon4(DOM_BOUNDS, lo, hi, boundsSalt). */
|
|
182
|
-
export function boundsCommit(lo, hi, salt) {
|
|
183
|
-
return poseidonHash([DOM_BOUNDS, lo, hi, salt]);
|
|
184
|
-
}
|
|
185
173
|
function opened(coin, index, events, seed) {
|
|
186
174
|
assertCoin(coin);
|
|
187
175
|
if (!Number.isSafeInteger(index) || index < 0)
|
|
@@ -256,17 +244,7 @@ function parseRound(value) {
|
|
|
256
244
|
if (value === undefined || value === null || tableHandle(value))
|
|
257
245
|
return null;
|
|
258
246
|
const round = record(value, "round");
|
|
259
|
-
|
|
260
|
-
const listed = Array.isArray(offers) ? offers.length : count(round.n_offers ?? 0, "n_offers");
|
|
261
|
-
if (Array.isArray(offers) &&
|
|
262
|
-
round.n_offers !== undefined &&
|
|
263
|
-
count(round.n_offers, "n_offers") !== offers.length)
|
|
264
|
-
tampered();
|
|
265
|
-
return {
|
|
266
|
-
reqCommit: whole(round.req_commit, "req_commit"),
|
|
267
|
-
closeMs: whole(round.close_ms, "close_ms"),
|
|
268
|
-
offers: listed,
|
|
269
|
-
};
|
|
247
|
+
return { reqCommit: whole(round.req_commit, "req_commit"), closeMs: whole(round.close_ms, "close_ms") };
|
|
270
248
|
}
|
|
271
249
|
function parseLoan(config, row) {
|
|
272
250
|
const loan = record(row.json, "loan");
|
|
@@ -282,7 +260,6 @@ function parseLoan(config, row) {
|
|
|
282
260
|
state,
|
|
283
261
|
round: whole(readOnce(loan, "round") ?? "0", "loan.round"),
|
|
284
262
|
closeMs: current?.closeMs ?? null,
|
|
285
|
-
offers: current?.offers ?? null,
|
|
286
263
|
loanCoin: coinByPool(config, String(readOnce(loan, "pool_l") ?? "")),
|
|
287
264
|
collateralCoin: coinByPool(config, String(readOnce(loan, "pool_c") ?? "")),
|
|
288
265
|
marketId: address(String(readOnce(loan, "market_id") ?? ""), "market"),
|
|
@@ -309,7 +286,6 @@ export function summarizeLoan(config, row) {
|
|
|
309
286
|
state: loan.state,
|
|
310
287
|
round: loan.round,
|
|
311
288
|
closeMs: loan.closeMs,
|
|
312
|
-
offers: loan.offers,
|
|
313
289
|
loanCoin: loan.loanCoin,
|
|
314
290
|
collateralCoin: loan.collateralCoin,
|
|
315
291
|
};
|
|
@@ -336,7 +312,6 @@ export function viewLoanObject(config, row, o) {
|
|
|
336
312
|
state: loan.state,
|
|
337
313
|
round: loan.round,
|
|
338
314
|
closeMs: loan.closeMs,
|
|
339
|
-
offers: loan.offers,
|
|
340
315
|
loanCoin: loan.loanCoin,
|
|
341
316
|
collateralCoin: loan.collateralCoin,
|
|
342
317
|
lifecycle: loan.lifecycle,
|
|
@@ -440,13 +415,6 @@ function ownData(obj, key) {
|
|
|
440
415
|
function parseRoom(config, row) {
|
|
441
416
|
requireSale(config);
|
|
442
417
|
const room = record(row.json, "room");
|
|
443
|
-
const bids = room.bids;
|
|
444
|
-
const listed = count(room.n_bids ?? (Array.isArray(bids) ? bids.length : 0), "n_bids");
|
|
445
|
-
if (Array.isArray(bids) && bids.length !== listed)
|
|
446
|
-
tampered();
|
|
447
|
-
const maxBids = whole(room.max_bids ?? "0", "max_bids");
|
|
448
|
-
if (maxBids < BigInt(listed))
|
|
449
|
-
tampered();
|
|
450
418
|
const closeMs = whole(room.close_ms ?? "0", "close_ms");
|
|
451
419
|
const finishByMs = whole(room.finish_by_ms ?? "0", "finish_by_ms");
|
|
452
420
|
if (closeMs > finishByMs)
|
|
@@ -456,45 +424,16 @@ function parseRoom(config, row) {
|
|
|
456
424
|
coin: coinByPool(config, String(room.pool_id ?? "")),
|
|
457
425
|
state: u8(room.state, "room.state"),
|
|
458
426
|
closeMs,
|
|
459
|
-
bids: listed,
|
|
460
427
|
finishByMs,
|
|
461
|
-
maxBids,
|
|
462
|
-
boundsCommit: whole(room.bounds_commit ?? "0", "bounds_commit"),
|
|
463
428
|
};
|
|
464
429
|
}
|
|
465
430
|
/** D-SPEC §6.2:600. */
|
|
466
431
|
export function summarizeRoom(config, row) {
|
|
467
432
|
const room = parseRoom(config, row);
|
|
468
|
-
return { id: room.id, coin: room.coin, state: room.state, closeMs: room.closeMs
|
|
469
|
-
}
|
|
470
|
-
/** D-SPEC §6.2:600. A bounds opening that misses `bounds_commit` is tampered (`C-SPEC.md:179`). */
|
|
471
|
-
export function viewRoomObject(config, row, bounds) {
|
|
472
|
-
const room = parseRoom(config, row);
|
|
473
|
-
let minPrice = null;
|
|
474
|
-
let maxPrice = null;
|
|
475
|
-
if (bounds) {
|
|
476
|
-
const box = plain(bounds);
|
|
477
|
-
const lo = ownBigint(box, "lo");
|
|
478
|
-
const hi = ownBigint(box, "hi");
|
|
479
|
-
const salt = ownBigint(box, "salt");
|
|
480
|
-
const commit = hashOrRefuse(() => boundsCommit(asField(lo), asField(hi), asField(salt)));
|
|
481
|
-
if (commit !== room.boundsCommit)
|
|
482
|
-
tampered();
|
|
483
|
-
minPrice = lo;
|
|
484
|
-
maxPrice = hi;
|
|
485
|
-
}
|
|
486
|
-
return {
|
|
487
|
-
id: room.id,
|
|
488
|
-
coin: room.coin,
|
|
489
|
-
state: room.state,
|
|
490
|
-
closeMs: room.closeMs,
|
|
491
|
-
bids: room.bids,
|
|
492
|
-
finishByMs: room.finishByMs,
|
|
493
|
-
maxBids: room.maxBids,
|
|
494
|
-
minPrice,
|
|
495
|
-
maxPrice,
|
|
496
|
-
};
|
|
433
|
+
return { id: room.id, coin: room.coin, state: room.state, closeMs: room.closeMs };
|
|
497
434
|
}
|
|
435
|
+
/** D-SPEC §6.2:600. */
|
|
436
|
+
export const viewRoomObject = (config, row) => parseRoom(config, row);
|
|
498
437
|
/** D-SPEC §6.2:588. Refuses before any envelope is built. */
|
|
499
438
|
export function assertLoanOpen(p) {
|
|
500
439
|
assertCoin(p.loanCoin);
|
|
@@ -512,7 +451,7 @@ export function assertLoanOpen(p) {
|
|
|
512
451
|
if (!Number.isInteger(p.offerWindowMs) || p.offerWindowMs <= 0)
|
|
513
452
|
throw new EsseyError("INVALID_ARGUMENT", "offerWindowMs must be above 0");
|
|
514
453
|
}
|
|
515
|
-
/** D-SPEC §6.2:599. Copies each argument once.
|
|
454
|
+
/** D-SPEC §6.2:599. Copies each argument once. */
|
|
516
455
|
export function assertSaleOpen(p) {
|
|
517
456
|
const open = snapshotSale(p);
|
|
518
457
|
assertCoin(open.coin);
|
|
@@ -526,8 +465,6 @@ export function assertSaleOpen(p) {
|
|
|
526
465
|
!Number.isInteger(open.finishWindowMs) ||
|
|
527
466
|
open.finishWindowMs <= 0)
|
|
528
467
|
throw new EsseyError("INVALID_ARGUMENT", "the bid and finish windows must be above 0");
|
|
529
|
-
if (!Number.isInteger(open.maxBids) || open.maxBids < 1 || open.maxBids > MAX_BIDS)
|
|
530
|
-
throw new EsseyError("INVALID_ARGUMENT", "maxBids is not 1..16");
|
|
531
468
|
return open;
|
|
532
469
|
}
|
|
533
470
|
function snapshotSale(p) {
|
|
@@ -541,21 +478,16 @@ function snapshotSale(p) {
|
|
|
541
478
|
price: ownBigint(o, "price"),
|
|
542
479
|
bidWindowMs: ownInt(o, "bidWindowMs"),
|
|
543
480
|
finishWindowMs: ownInt(o, "finishWindowMs"),
|
|
544
|
-
maxBids: ownInt(o, "maxBids"),
|
|
545
481
|
sponsored: ownFlag(o, "sponsored"),
|
|
546
482
|
};
|
|
547
483
|
}
|
|
548
484
|
/**
|
|
549
|
-
* The room the sponsor named is this open: same coin pool, close
|
|
550
|
-
* (`sale_room.move:181-193`).
|
|
485
|
+
* The room the sponsor named is this open: same coin pool, close and finish window (`sale_room.move:98-113`).
|
|
551
486
|
*/
|
|
552
487
|
export function assertRoomMatches(config, open, row) {
|
|
553
488
|
const room = parseRoom(config, row);
|
|
554
489
|
const finish = BigInt(open.closeMs) + BigInt(open.finishWindowMs);
|
|
555
|
-
if (room.coin !== open.coin ||
|
|
556
|
-
room.closeMs !== BigInt(open.closeMs) ||
|
|
557
|
-
room.finishByMs !== finish ||
|
|
558
|
-
room.maxBids !== BigInt(open.maxBids))
|
|
490
|
+
if (room.coin !== open.coin || room.closeMs !== BigInt(open.closeMs) || room.finishByMs !== finish)
|
|
559
491
|
throw new EsseyError("SERVICE_REFUSED", "unknown object: the room is not this open");
|
|
560
492
|
}
|
|
561
493
|
/**
|
package/package.json
CHANGED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
type Offers = {
|
|
2
|
-
offers: {
|
|
3
|
-
lock: string;
|
|
4
|
-
}[];
|
|
5
|
-
};
|
|
6
|
-
/**
|
|
7
|
-
* The round whose offers hold the lender's lock, newest first. Each lock commits to its round (`lockField`), so a
|
|
8
|
-
* reader that ignores `round` and returns the current one never matches an older round.
|
|
9
|
-
*/
|
|
10
|
-
export declare function lockRound(p: {
|
|
11
|
-
current: bigint;
|
|
12
|
-
currentRound: Offers;
|
|
13
|
-
round?: bigint;
|
|
14
|
-
readRound: (round: bigint) => Promise<Offers | null | undefined>;
|
|
15
|
-
lockAt: (round: bigint) => bigint;
|
|
16
|
-
}): Promise<{
|
|
17
|
-
round: bigint;
|
|
18
|
-
locks: bigint[];
|
|
19
|
-
slot: number;
|
|
20
|
-
}>;
|
|
21
|
-
export {};
|
|
22
|
-
//# sourceMappingURL=lock-round.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"lock-round.d.ts","sourceRoot":"","sources":["../../../src/v3/loans/lock-round.ts"],"names":[],"mappings":"AAEA,KAAK,MAAM,GAAG;IAAE,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;CAAE,CAAC;AAE7C;;;GAGG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAAE;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;IACjE,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;CACnC,GAAG,OAAO,CAAC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,EAAE,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAc5D"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { EsseyError } from "../../errors.js";
|
|
2
|
-
/**
|
|
3
|
-
* The round whose offers hold the lender's lock, newest first. Each lock commits to its round (`lockField`), so a
|
|
4
|
-
* reader that ignores `round` and returns the current one never matches an older round.
|
|
5
|
-
*/
|
|
6
|
-
export async function lockRound(p) {
|
|
7
|
-
if (p.round !== undefined && (p.round < 0n || p.round > p.current))
|
|
8
|
-
throw new EsseyError("INVALID_ARGUMENT", "refused: the round is not one of this loan's rounds");
|
|
9
|
-
const rounds = p.round !== undefined
|
|
10
|
-
? [p.round]
|
|
11
|
-
: Array.from({ length: Number(p.current) + 1 }, (_, i) => p.current - BigInt(i));
|
|
12
|
-
for (const round of rounds) {
|
|
13
|
-
const row = round === p.current ? p.currentRound : await p.readRound(round);
|
|
14
|
-
const locks = (row?.offers ?? []).map((o) => BigInt(o.lock));
|
|
15
|
-
const slot = locks.indexOf(p.lockAt(round));
|
|
16
|
-
if (slot >= 0)
|
|
17
|
-
return { round, locks, slot };
|
|
18
|
-
}
|
|
19
|
-
throw new EsseyError("SERVICE_REFUSED", "unknown object: the record's lock is in no round of this loan");
|
|
20
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import type { FeeCommitInput } from "../fees.ts";
|
|
2
|
-
import type { CircuitInput } from "../inputs.ts";
|
|
3
|
-
import { type BidSecrets } from "./rows.ts";
|
|
4
|
-
export type ReclaimParams = {
|
|
5
|
-
/** `SaleRoom` as read from chain: its `sale_key`, every bid's lock in seq order, and `residual`. */
|
|
6
|
-
room: {
|
|
7
|
-
saleKey: bigint;
|
|
8
|
-
locks: bigint[];
|
|
9
|
-
residual: bigint;
|
|
10
|
-
};
|
|
11
|
-
bid: BidSecrets;
|
|
12
|
-
/** "lock" returns the deposit. "residual" returns the winner's change: the deposit less the price. */
|
|
13
|
-
what: "lock" | "residual";
|
|
14
|
-
out: {
|
|
15
|
-
pk: bigint;
|
|
16
|
-
blinding: bigint;
|
|
17
|
-
};
|
|
18
|
-
relayer: string;
|
|
19
|
-
relayerFee: bigint;
|
|
20
|
-
/** `[out note, fee note]`, the order `reclaim` hands `room_insert`. */
|
|
21
|
-
encs: [Uint8Array, Uint8Array];
|
|
22
|
-
fee: FeeCommitInput;
|
|
23
|
-
eph: bigint;
|
|
24
|
-
};
|
|
25
|
-
/** The `u256` and `address` arguments of `sale_room::reclaim`, under Move's own names and in its order. */
|
|
26
|
-
export type ReclaimStatement = {
|
|
27
|
-
nullifier: bigint;
|
|
28
|
-
out_note: bigint;
|
|
29
|
-
fee_note: bigint;
|
|
30
|
-
eph_x: bigint;
|
|
31
|
-
eph_y: bigint;
|
|
32
|
-
fee_ct: bigint;
|
|
33
|
-
fee_commit: bigint;
|
|
34
|
-
relayer: string;
|
|
35
|
-
};
|
|
36
|
-
/**
|
|
37
|
-
* Witness for `circuits/v3/reclaim/reclaim.circom` over a sale room. Public signals, in order: hLock, residual, hCtx, N,
|
|
38
|
-
* hOut. The lock is rebuilt under this room's `sale_key`; a room that does not hold it is refused.
|
|
39
|
-
*/
|
|
40
|
-
export declare function reclaim(p: ReclaimParams): Promise<{
|
|
41
|
-
input: CircuitInput;
|
|
42
|
-
publics: bigint[];
|
|
43
|
-
statement: ReclaimStatement;
|
|
44
|
-
outAmt: bigint;
|
|
45
|
-
}>;
|
|
46
|
-
//# sourceMappingURL=reclaim.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"reclaim.d.ts","sourceRoot":"","sources":["../../../src/v3/sales/reclaim.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAKjD,OAAO,EAA8B,KAAK,UAAU,EAAE,MAAM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