@esseyonsui/sui-sdk-v3 0.2.1 → 0.3.2

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 (70) hide show
  1. package/dist/essey.d.ts +113 -23
  2. package/dist/essey.d.ts.map +1 -1
  3. package/dist/essey.js +512 -179
  4. package/dist/index.d.ts +1 -1
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/v3/collateral/bodies.d.ts +2 -1
  7. package/dist/v3/collateral/bodies.d.ts.map +1 -1
  8. package/dist/v3/collateral/bodies.js +5 -5
  9. package/dist/v3/collateral/local-health.d.ts +2 -2
  10. package/dist/v3/collateral/local-health.js +1 -1
  11. package/dist/v3/collateral/math.d.ts +8 -9
  12. package/dist/v3/collateral/math.d.ts.map +1 -1
  13. package/dist/v3/collateral/math.js +65 -13
  14. package/dist/v3/index.d.ts +1 -0
  15. package/dist/v3/index.d.ts.map +1 -1
  16. package/dist/v3/index.js +1 -0
  17. package/dist/v3/kinds.d.ts +5 -2
  18. package/dist/v3/kinds.d.ts.map +1 -1
  19. package/dist/v3/kinds.js +7 -1
  20. package/dist/v3/loans/bodies.d.ts +16 -0
  21. package/dist/v3/loans/bodies.d.ts.map +1 -1
  22. package/dist/v3/loans/bodies.js +13 -0
  23. package/dist/v3/loans/open-plan.d.ts +2 -0
  24. package/dist/v3/loans/open-plan.d.ts.map +1 -1
  25. package/dist/v3/loans/open-plan.js +1 -1
  26. package/dist/v3/loans/refi-plan.d.ts.map +1 -1
  27. package/dist/v3/loans/refi-plan.js +2 -4
  28. package/dist/v3/loans/settle-plan.d.ts +7 -2
  29. package/dist/v3/loans/settle-plan.d.ts.map +1 -1
  30. package/dist/v3/loans/settle-plan.js +15 -15
  31. package/dist/v3/memo.d.ts +68 -0
  32. package/dist/v3/memo.d.ts.map +1 -0
  33. package/dist/v3/memo.js +147 -0
  34. package/dist/v3/sales/auctioneer.d.ts +8 -3
  35. package/dist/v3/sales/auctioneer.d.ts.map +1 -1
  36. package/dist/v3/sales/auctioneer.js +22 -5
  37. package/dist/v3/sales/bid.d.ts +3 -0
  38. package/dist/v3/sales/bid.d.ts.map +1 -1
  39. package/dist/v3/sales/bid.js +3 -0
  40. package/dist/v3/sales/bodies.d.ts +14 -2
  41. package/dist/v3/sales/bodies.d.ts.map +1 -1
  42. package/dist/v3/sales/bodies.js +11 -2
  43. package/dist/v3/sales/index.d.ts +3 -0
  44. package/dist/v3/sales/index.d.ts.map +1 -1
  45. package/dist/v3/sales/index.js +3 -0
  46. package/dist/v3/sales/listing.d.ts +19 -0
  47. package/dist/v3/sales/listing.d.ts.map +1 -0
  48. package/dist/v3/sales/listing.js +41 -0
  49. package/dist/v3/sales/memo.d.ts +4 -0
  50. package/dist/v3/sales/memo.d.ts.map +1 -0
  51. package/dist/v3/sales/memo.js +6 -0
  52. package/dist/v3/sales/open-kind.d.ts +4 -1
  53. package/dist/v3/sales/open-kind.d.ts.map +1 -1
  54. package/dist/v3/sales/open-kind.js +4 -3
  55. package/dist/v3/sales/package-gate.d.ts +15 -0
  56. package/dist/v3/sales/package-gate.d.ts.map +1 -0
  57. package/dist/v3/sales/package-gate.js +25 -0
  58. package/dist/v3/sales/rows.d.ts +1 -0
  59. package/dist/v3/sales/rows.d.ts.map +1 -1
  60. package/dist/v3/sales/rows.js +3 -1
  61. package/dist/v3/sales/seller.d.ts +34 -10
  62. package/dist/v3/sales/seller.d.ts.map +1 -1
  63. package/dist/v3/sales/seller.js +43 -16
  64. package/dist/v3/stage1.d.ts +3 -3
  65. package/dist/v3/stage1.d.ts.map +1 -1
  66. package/dist/v3/stage1.js +3 -4
  67. package/dist/v3/time-grid.d.ts +12 -1
  68. package/dist/v3/time-grid.d.ts.map +1 -1
  69. package/dist/v3/time-grid.js +17 -2
  70. package/package.json +1 -1
@@ -61,25 +61,25 @@ export function interest(principal, rateBps, termMs) {
61
61
  owed: principal + num / INTEREST_DENOM,
62
62
  };
63
63
  }
64
- /** The winner: the lowest rate of an active slot at or under the request's maximum, earliest on a tie. */
65
- export function lowestEligible(slots, maxRate) {
66
- let w = -1;
67
- slots.forEach((s, i) => {
68
- if (!s.active || !s.open || s.open.rateBps > maxRate)
69
- return;
70
- if (w < 0 || s.open.rateBps < slots[w].open.rateBps)
71
- w = i;
72
- });
73
- return w;
64
+ /**
65
+ * PRV-23 A: the winner is the round's pick, the one active slot. `loan::settle_rows` (`loan.move:507-513`) folds the
66
+ * pick's commit alone with `actMask = 1 << pick`, so a witness with any other active slot fails the proof.
67
+ */
68
+ export function pickedSlot(slots, maxRate) {
69
+ const live = slots.flatMap((s, i) => (s.active ? [i] : []));
70
+ if (live.length !== 1)
71
+ throw new Error("a settle witness has exactly one active slot, the pick");
72
+ const open = slots[live[0]].open;
73
+ if (!open || open.rateBps > maxRate)
74
+ throw new Error("no eligible offer");
75
+ return live[0];
74
76
  }
75
77
  /** Witness and Move arguments of `circuits/v3/loan_settle/loan_settle.circom` (`ref.mjs` loanSettleCase, round 0). */
76
78
  export async function loanSettle(p) {
77
79
  const { request: q, slots } = p;
78
80
  if (slots.length > SETTLE_SLOTS)
79
81
  throw new Error("more than 16 offers");
80
- const w = lowestEligible(slots, q.maxRateBps);
81
- if (w < 0)
82
- throw new Error("no eligible offer");
82
+ const w = pickedSlot(slots, q.maxRateBps);
83
83
  const win = slots[w].open;
84
84
  const field = lockField(p.loanKey, 0n);
85
85
  for (const s of slots) {
@@ -208,7 +208,7 @@ export function actionHash(blake, loanKey, nonce, kind, args) {
208
208
  }
209
209
  /** `settle::settle_args`: every argument in declaration order, shared objects by id, vectors and the proof as bcs. */
210
210
  export function settleArgs(a) {
211
- return cat(addressBytes(a.loan), addressBytes(a.poolL), bcsBytes(a.proof), le(a.termsCommit, 32), le(a.principalNote, 32), le(a.feeNote, 32), le(a.winNull, 32), cat(uleb(a.d.length), ...a.d.map((x) => le(x, 32))), le(a.ephX, 32), le(a.ephY, 32), le(a.feeCt, 32), bcsBytes(a.keeperCt), cat(uleb(a.encs.length), ...a.encs.map(bcsBytes)), le(a.nowS, 8));
211
+ return cat(addressBytes(a.loan), addressBytes(a.poolL), bcsBytes(a.proof), le(a.termsCommit, 32), le(a.principalNote, 32), le(a.feeNote, 32), le(a.winNull, 32), cat(uleb(a.d.length), ...a.d.map((x) => le(x, 32))), le(a.ephX, 32), le(a.ephY, 32), le(a.feeCt, 32), bcsBytes(a.keeperCt), cat(uleb(a.encs.length), ...a.encs.map(bcsBytes)), le(a.nowS, 8), bcsBytes(a.memo));
212
212
  }
213
213
  /** `membership::seal_offer(room, round, seq, viewer).bind`. */
214
214
  export const sealOfferBind = (blake, room, round, seq, viewer) => blake(cat(ascii("essey-v3/seal/offer"), addressBytes(room), le(round, 8), le(seq, 8), addressBytes(viewer)));
@@ -225,7 +225,7 @@ export const cancelRefiArgs = (loan, poolL) => cat(addressBytes(loan), addressBy
225
225
  export function settleRefiArgs(a) {
226
226
  const fields = (xs) => cat(uleb(xs.length), ...xs.map((x) => le(x, 32)));
227
227
  const blobs = (xs) => cat(uleb(xs.length), ...xs.map(bcsBytes));
228
- return cat(addressBytes(a.loan), addressBytes(a.poolL), addressBytes(a.market), a.reading, bcsBytes(a.proof), ...[a.termsCommit, a.borrowerNote, a.feeNote, a.winNull].map((x) => le(x, 32)), fields(a.d), ...[a.ephX, a.ephY, a.feeCt, a.payoffNote, a.pad].map((x) => le(x, 32)), fields(a.ephP), le(a.pClaim, 8), bcsBytes(a.keeperCt), blobs(a.encs), blobs(a.encsP), le(a.nowS, 8));
228
+ return cat(addressBytes(a.loan), addressBytes(a.poolL), addressBytes(a.market), a.reading, bcsBytes(a.proof), ...[a.termsCommit, a.borrowerNote, a.feeNote, a.winNull].map((x) => le(x, 32)), fields(a.d), ...[a.ephX, a.ephY, a.feeCt, a.payoffNote, a.pad].map((x) => le(x, 32)), fields(a.ephP), le(a.pClaim, 8), bcsBytes(a.keeperCt), blobs(a.encs), blobs(a.encsP), le(a.nowS, 8), bcsBytes(a.memo));
229
229
  }
230
230
  /** The bcs of `price::Reading`: the oracle type name, the feed id, spot, EMA, the exponent and `publish_s`. */
231
231
  export const readingBytes = (r) => cat(bcsBytes(ascii(r.oracle)), addressBytes(r.feedId), le(r.spot, 8), le(r.ema, 8), Uint8Array.of(Number(r.expo)), le(r.publishS, 8));
@@ -0,0 +1,68 @@
1
+ import type { KeeperTerms } from "./keeper-payload.ts";
2
+ /** `loan.move` `MEMO_LEN`: nonce 24 ‖ XChaCha20-Poly1305 of 344 plaintext bytes ‖ tag 16 (42_045 otherwise). */
3
+ export declare const MEMO_LEN = 384;
4
+ /** SCOPE-R1-MEMO D4: the slot a memo is sealed for. 5 and 6 are lane SDK-B's sale and bid memos. */
5
+ export declare const MEMO_KIND: {
6
+ readonly request: 1;
7
+ readonly offer: 2;
8
+ readonly settle: 3;
9
+ readonly sale: 5;
10
+ readonly bid: 6;
11
+ };
12
+ export type MemoKind = (typeof MEMO_KIND)[keyof typeof MEMO_KIND];
13
+ /** `key` is the loan key (or the sale key); `round` the loan round the memo belongs to, 0 for a sale. */
14
+ export type MemoSlot = {
15
+ kind: MemoKind;
16
+ key: bigint;
17
+ round: bigint;
18
+ };
19
+ /** SCOPE-R1-MEMO D1: HKDF-SHA256 of the seed under the memo's own label. */
20
+ export declare const memoKey: (seed: Uint8Array) => Uint8Array;
21
+ /** SCOPE-R1-MEMO D3: the label, the kind, the key and the round, so a memo opens only where it was sealed. */
22
+ export declare const memoAad: (slot: MemoSlot) => Uint8Array;
23
+ /** A fresh nonce per memo; `body` is zero-padded to 342 bytes behind the version and kind. */
24
+ export declare function sealMemo(key: Uint8Array, slot: MemoSlot, body: Uint8Array): Uint8Array;
25
+ /** The body of a memo sealed for `slot` under `key`, its first `bodyLen` bytes; null for anyone else's memo. */
26
+ export declare function openMemo(key: Uint8Array, slot: MemoSlot, memo: Uint8Array, bodyLen: number): Uint8Array | null;
27
+ /** What the borrower's request memo holds: the loan key's note index, the locked amount and the borrower key. */
28
+ export type RequestMemo = {
29
+ keyIndex: number;
30
+ collAmt: bigint;
31
+ borrowerPk: bigint;
32
+ };
33
+ /** A lender's `OfferRecord`, every field present. */
34
+ export type OfferMemo = {
35
+ noteIndex: number;
36
+ principal: bigint;
37
+ rateBps: bigint;
38
+ termMs: bigint;
39
+ borrowerPk: bigint;
40
+ };
41
+ /** The borrower's record once settled. */
42
+ export type SettleMemo = RequestMemo & {
43
+ terms: KeeperTerms;
44
+ };
45
+ /** A seller's record: `saleSecrets` and the bounds salt derive from the note key at `noteIndex`; bounds are the price. */
46
+ export type SaleMemo = {
47
+ noteIndex: number;
48
+ price: bigint;
49
+ };
50
+ /** A bidder's `BidRecord` without its room, which the memo's slot names. */
51
+ export type BidMemo = {
52
+ noteIndex: number;
53
+ v: bigint;
54
+ amount: bigint;
55
+ };
56
+ export declare const requestMemoBody: (m: RequestMemo) => Uint8Array<ArrayBuffer>;
57
+ export declare const offerMemoBody: (m: OfferMemo) => Uint8Array<ArrayBuffer>;
58
+ export declare const settleMemoBody: (m: SettleMemo) => Uint8Array<ArrayBuffer>;
59
+ /** The sale-open memo, sealed to the room's sale key. */
60
+ export declare const sealSaleMemo: (key: Uint8Array, saleKey: bigint, m: SaleMemo) => Uint8Array<ArrayBufferLike>;
61
+ /** A bid memo, sealed to the room's sale key. */
62
+ export declare const sealBidMemo: (key: Uint8Array, saleKey: bigint, m: BidMemo) => Uint8Array<ArrayBufferLike>;
63
+ export declare function openSaleMemo(key: Uint8Array, saleKey: bigint, memo: Uint8Array): SaleMemo | null;
64
+ export declare function openBidMemo(key: Uint8Array, saleKey: bigint, memo: Uint8Array): BidMemo | null;
65
+ export declare function openRequestMemo(key: Uint8Array, loanKey: bigint, memo: Uint8Array): RequestMemo | null;
66
+ export declare function openOfferMemo(key: Uint8Array, loanKey: bigint, round: bigint, memo: Uint8Array): OfferMemo | null;
67
+ export declare function openSettleMemo(key: Uint8Array, loanKey: bigint, round: bigint, memo: Uint8Array): SettleMemo | null;
68
+ //# sourceMappingURL=memo.d.ts.map
@@ -0,0 +1 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OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,UAAU,GACf,SAAS,GAAG,IAAI,CAWlB;AAED,wBAAgB,cAAc,CAC5B,GAAG,EAAE,UAAU,EACf,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,UAAU,GACf,UAAU,GAAG,IAAI,CAmBnB"}
@@ -0,0 +1,147 @@
1
+ import { randomBytes } from "node:crypto";
2
+ import { xchacha20poly1305 } from "@noble/ciphers/chacha.js";
3
+ import { hkdf } from "@noble/hashes/hkdf.js";
4
+ import { sha256 } from "@noble/hashes/sha2.js";
5
+ /** `loan.move` `MEMO_LEN`: nonce 24 ‖ XChaCha20-Poly1305 of 344 plaintext bytes ‖ tag 16 (42_045 otherwise). */
6
+ export const MEMO_LEN = 384;
7
+ const NONCE = 24;
8
+ const PLAIN = 344;
9
+ const VERSION = 1;
10
+ const HEADER = 2;
11
+ /** SCOPE-R1-MEMO D4: the slot a memo is sealed for. 5 and 6 are lane SDK-B's sale and bid memos. */
12
+ export const MEMO_KIND = { request: 1, offer: 2, settle: 3, sale: 5, bid: 6 };
13
+ const utf8 = (s) => new TextEncoder().encode(s);
14
+ const KEY_LABEL = utf8("essey-v3 record memo v1");
15
+ const AAD_LABEL = utf8("essey-v3 memo v1");
16
+ /** SCOPE-R1-MEMO D1: HKDF-SHA256 of the seed under the memo's own label. */
17
+ export const memoKey = (seed) => hkdf(sha256, seed, undefined, KEY_LABEL, 32);
18
+ function be(value, size) {
19
+ if (value < 0n || value >= 1n << BigInt(8 * size))
20
+ throw new Error(`a memo value does not fit ${size} bytes`);
21
+ const out = new Uint8Array(size);
22
+ for (let i = size - 1, v = value; i >= 0; i--, v >>= 8n)
23
+ out[i] = Number(v & 0xffn);
24
+ return out;
25
+ }
26
+ const fromBe = (bytes) => bytes.reduce((v, b) => (v << 8n) | BigInt(b), 0n);
27
+ /** SCOPE-R1-MEMO D3: the label, the kind, the key and the round, so a memo opens only where it was sealed. */
28
+ export const memoAad = (slot) => Uint8Array.from([...AAD_LABEL, slot.kind, ...be(slot.key, 32), ...be(slot.round, 8)]);
29
+ /** A fresh nonce per memo; `body` is zero-padded to 342 bytes behind the version and kind. */
30
+ export function sealMemo(key, slot, body) {
31
+ if (body.length > PLAIN - HEADER)
32
+ throw new Error("a memo body is over 342 bytes");
33
+ const plain = new Uint8Array(PLAIN);
34
+ plain.set([VERSION, slot.kind]);
35
+ plain.set(body, HEADER);
36
+ const nonce = randomBytes(NONCE);
37
+ return Uint8Array.from([...nonce, ...xchacha20poly1305(key, nonce, memoAad(slot)).encrypt(plain)]);
38
+ }
39
+ /** The body of a memo sealed for `slot` under `key`, its first `bodyLen` bytes; null for anyone else's memo. */
40
+ export function openMemo(key, slot, memo, bodyLen) {
41
+ if (memo.length !== MEMO_LEN)
42
+ return null;
43
+ let plain;
44
+ try {
45
+ plain = xchacha20poly1305(key, memo.subarray(0, NONCE), memoAad(slot)).decrypt(memo.subarray(NONCE));
46
+ }
47
+ catch {
48
+ return null;
49
+ }
50
+ if (plain[0] !== VERSION || plain[1] !== slot.kind)
51
+ return null;
52
+ if (plain.subarray(HEADER + bodyLen).some((b) => b !== 0))
53
+ return null;
54
+ return plain.slice(HEADER, HEADER + bodyLen);
55
+ }
56
+ const REQUEST_BODY = 44;
57
+ const OFFER_BODY = 60;
58
+ const SETTLE_BODY = 204;
59
+ const SALE_BODY = 12;
60
+ const BID_BODY = 20;
61
+ const index = (n) => be(BigInt(n), 4);
62
+ const u64 = (v) => be(v, 8);
63
+ const field = (v) => be(v, 32);
64
+ function reader(bytes) {
65
+ let at = 0;
66
+ const take = (size) => fromBe(bytes.subarray(at, (at += size)));
67
+ return { index: () => Number(take(4)), u64: () => take(8), field: () => take(32) };
68
+ }
69
+ const requestBody = (m) => [...index(m.keyIndex), ...u64(m.collAmt), ...field(m.borrowerPk)];
70
+ export const requestMemoBody = (m) => Uint8Array.from(requestBody(m));
71
+ export const offerMemoBody = (m) => Uint8Array.from([
72
+ ...index(m.noteIndex),
73
+ ...u64(m.principal),
74
+ ...u64(m.rateBps),
75
+ ...u64(m.termMs),
76
+ ...field(m.borrowerPk),
77
+ ]);
78
+ export const settleMemoBody = (m) => Uint8Array.from([
79
+ ...requestBody(m),
80
+ ...u64(m.terms.principal),
81
+ ...u64(m.terms.rateBps),
82
+ ...u64(m.terms.owed),
83
+ ...u64(m.terms.maturityS),
84
+ ...field(m.terms.lenderPk),
85
+ ...field(m.terms.lenderEncX),
86
+ ...field(m.terms.lenderEncY),
87
+ ...field(m.terms.salt),
88
+ ]);
89
+ /** The sale-open memo, sealed to the room's sale key. */
90
+ export const sealSaleMemo = (key, saleKey, m) => sealMemo(key, { kind: MEMO_KIND.sale, key: saleKey, round: 0n }, Uint8Array.from([...index(m.noteIndex), ...u64(m.price)]));
91
+ /** A bid memo, sealed to the room's sale key. */
92
+ export const sealBidMemo = (key, saleKey, m) => sealMemo(key, { kind: MEMO_KIND.bid, key: saleKey, round: 0n }, Uint8Array.from([...index(m.noteIndex), ...u64(m.v), ...u64(m.amount)]));
93
+ export function openSaleMemo(key, saleKey, memo) {
94
+ const body = openMemo(key, { kind: MEMO_KIND.sale, key: saleKey, round: 0n }, memo, SALE_BODY);
95
+ if (!body)
96
+ return null;
97
+ const r = reader(body);
98
+ return { noteIndex: r.index(), price: r.u64() };
99
+ }
100
+ export function openBidMemo(key, saleKey, memo) {
101
+ const body = openMemo(key, { kind: MEMO_KIND.bid, key: saleKey, round: 0n }, memo, BID_BODY);
102
+ if (!body)
103
+ return null;
104
+ const r = reader(body);
105
+ return { noteIndex: r.index(), v: r.u64(), amount: r.u64() };
106
+ }
107
+ export function openRequestMemo(key, loanKey, memo) {
108
+ const body = openMemo(key, { kind: MEMO_KIND.request, key: loanKey, round: 0n }, memo, REQUEST_BODY);
109
+ if (!body)
110
+ return null;
111
+ const r = reader(body);
112
+ return { keyIndex: r.index(), collAmt: r.u64(), borrowerPk: r.field() };
113
+ }
114
+ export function openOfferMemo(key, loanKey, round, memo) {
115
+ const body = openMemo(key, { kind: MEMO_KIND.offer, key: loanKey, round }, memo, OFFER_BODY);
116
+ if (!body)
117
+ return null;
118
+ const r = reader(body);
119
+ return {
120
+ noteIndex: r.index(),
121
+ principal: r.u64(),
122
+ rateBps: r.u64(),
123
+ termMs: r.u64(),
124
+ borrowerPk: r.field(),
125
+ };
126
+ }
127
+ export function openSettleMemo(key, loanKey, round, memo) {
128
+ const body = openMemo(key, { kind: MEMO_KIND.settle, key: loanKey, round }, memo, SETTLE_BODY);
129
+ if (!body)
130
+ return null;
131
+ const r = reader(body);
132
+ return {
133
+ keyIndex: r.index(),
134
+ collAmt: r.u64(),
135
+ borrowerPk: r.field(),
136
+ terms: {
137
+ principal: r.u64(),
138
+ rateBps: r.u64(),
139
+ owed: r.u64(),
140
+ maturityS: r.u64(),
141
+ lenderPk: r.field(),
142
+ lenderEncX: r.field(),
143
+ lenderEncY: r.field(),
144
+ salt: r.field(),
145
+ },
146
+ };
147
+ }
@@ -11,8 +11,13 @@ export type PlanParams = {
11
11
  lock: bigint;
12
12
  active: boolean;
13
13
  }[];
14
+ /**
15
+ * `SaleRoom.pick`: `finish` opens that slot alone (`sale_room.move:712-716`). `null` with no active bid is the
16
+ * no-winner finish. `"legacy"` is a room of a previous sale package, whose `finish` opens every active bid.
17
+ */
18
+ pick: number | null | "legacy";
14
19
  };
15
- /** The decrypted sealed bid of each seq; absent where decryption gave nothing. */
20
+ /** The decrypted sealed bid of each seq; absent where decryption gave nothing. Only the pick's is read. */
16
21
  plains: (Uint8Array | undefined)[];
17
22
  seller: {
18
23
  sellerSk: bigint;
@@ -42,8 +47,8 @@ export type SettleStatement = {
42
47
  };
43
48
  /**
44
49
  * Witness for `circuits/v3/sale_settle/sale_settle.circom`. Public signals, in order: hSet, hLock, hCtx, hOut.
45
- * `slash` lists the active bids whose plaintext does not open their commit and lock. The witness already
46
- * leaves them out of the mask, so it proves only once each has been slashed on chain.
50
+ * `slash` lists the opened bids whose plaintext does not open their commit and lock: the pick, or in a legacy room
51
+ * any active bid, which the witness then leaves out of the mask. Either way it proves only once each is slashed.
47
52
  * hCtx carries relayer `NO_ADDRESS` and fee 0, the only pair `sale_room::finish` rebuilds.
48
53
  */
49
54
  export declare function plan(p: PlanParams): Promise<{
@@ -1 +1 @@
1
- {"version":3,"file":"auctioneer.d.ts","sourceRoot":"","sources":["../../../src/v3/sales/auctioneer.ts"],"names":[],"mappings":"AAMA,OAAO,EAAW,KAAK,cAAc,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAUjD,MAAM,MAAM,UAAU,GAAG;IACvB,qGAAqG;IACrG,IAAI,EAAE;QACJ,OAAO,EAAE,MAAM,CAAC;QAChB,YAAY,EAAE,MAAM,CAAC;QACrB,YAAY,EAAE,MAAM,CAAC;QACrB,IAAI,EAAE;YAAE,MAAM,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAC;YAAC,MAAM,EAAE,OAAO,CAAA;SAAE,EAAE,CAAC;KAC3D,CAAC;IACF,kFAAkF;IAClF,MAAM,EAAE,CAAC,UAAU,GAAG,SAAS,CAAC,EAAE,CAAC;IACnC,MAAM,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAA;KAAE,CAAC;IACnD,MAAM,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IACjD,yEAAyE;IACzE,IAAI,EAAE,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IAC/B,GAAG,EAAE,cAAc,CAAC;IACpB,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,4FAA4F;AAC5F,MAAM,MAAM,eAAe,GAAG;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE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AAY,EAAE,MAAM,CAAA;KAAE,CAAC;IACnD,MAAM,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IACjD,yEAAyE;IACzE,IAAI,EAAE,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IAC/B,GAAG,EAAE,cAAc,CAAC;IACpB,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,4FAA4F;AAC5F,MAAM,MAAM,eAAe,GAAG;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AA6CF;;;;;GAKG;AACH,wBAAsB,IAAI,CAAC,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC;IACjD,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,KAAK,EAAE,YAAY,CAAC;IACpB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,SAAS,EAAE,eAAe,CAAC;IAC3B,+EAA+E;IAC/E,UAAU,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;CACjD,CAAC,CAyFD"}
@@ -38,10 +38,24 @@ function dummyBranch(roomField, sellerPk, sellerSecret) {
38
38
  win_null: poseidonHash([DOM_LNULL, poseidonHash([DOM_DUMMY, sellerSecret, roomField])]),
39
39
  };
40
40
  }
41
+ /** The slots `finish` opens; refuses what `sale_room::settle_mask` would abort on. */
42
+ function readable(room) {
43
+ const { bids, pick } = room;
44
+ if (pick === "legacy")
45
+ return (i) => bids[i].active;
46
+ if (pick === null) {
47
+ if (bids.some((b) => b.active))
48
+ throw new Error("refused: draw the pick first (finish aborts 44_040)");
49
+ return () => false;
50
+ }
51
+ if (!Number.isInteger(pick) || !bids[pick]?.active)
52
+ throw new Error("the pick is not an active bid");
53
+ return (i) => i === pick;
54
+ }
41
55
  /**
42
56
  * Witness for `circuits/v3/sale_settle/sale_settle.circom`. Public signals, in order: hSet, hLock, hCtx, hOut.
43
- * `slash` lists the active bids whose plaintext does not open their commit and lock. The witness already
44
- * leaves them out of the mask, so it proves only once each has been slashed on chain.
57
+ * `slash` lists the opened bids whose plaintext does not open their commit and lock: the pick, or in a legacy room
58
+ * any active bid, which the witness then leaves out of the mask. Either way it proves only once each is slashed.
45
59
  * hCtx carries relayer `NO_ADDRESS` and fee 0, the only pair `sale_room::finish` rebuilds.
46
60
  */
47
61
  export async function plan(p) {
@@ -54,9 +68,12 @@ export async function plan(p) {
54
68
  throw new Error("the seller keys do not open this room");
55
69
  const commits = padSlots(room.bids.map((b) => b.commit));
56
70
  const locks = padSlots(room.bids.map((b) => b.lock));
57
- const opened = room.bids.map((b, i) => b.active ? openBid(p.plains[i], room.saleKey, b.commit, b.lock) : undefined);
58
- const slash = room.bids.flatMap((b, i) => (b.active && !opened[i] ? [i] : []));
59
- const activeMask = opened.reduce((m, o, i) => (o ? m | (1n << BigInt(i)) : m), 0n);
71
+ const read = readable(room);
72
+ const opened = room.bids.map((b, i) => read(i) ? openBid(p.plains[i], room.saleKey, b.commit, b.lock) : undefined);
73
+ const slash = room.bids.flatMap((_, i) => (read(i) && !opened[i] ? [i] : []));
74
+ const activeMask = typeof room.pick === "number"
75
+ ? 1n << BigInt(room.pick)
76
+ : opened.reduce((m, o, i) => (o ? m | (1n << BigInt(i)) : m), 0n);
60
77
  const w = pickWinner(opened, bounds.lo, bounds.hi);
61
78
  const won = opened[w];
62
79
  const price = won?.v ?? 0n;
@@ -9,6 +9,7 @@ export type LockBidParams = {
9
9
  id: string;
10
10
  saleKey: bigint;
11
11
  seq: number;
12
+ postedCommit: bigint;
12
13
  };
13
14
  bid: BidSecrets;
14
15
  /** The amount of the change note is what conserves value; it is computed, never passed. */
@@ -20,6 +21,8 @@ export type LockBidParams = {
20
21
  relayerFee: bigint;
21
22
  /** The Seal object `sale_room::bid` pins. The proof binds its blake2b256. */
22
23
  sealed: Uint8Array;
24
+ /** The proof binds it with `sealed` (`sale_room::ext_hash`). */
25
+ memo: Uint8Array;
23
26
  /** `[enc_change, enc_fee]`. */
24
27
  encs: [Uint8Array, Uint8Array];
25
28
  fee: FeeCommitInput;
@@ -1 +1 @@
1
- {"version":3,"file":"bid.d.ts","sourceRoot":"","sources":["../../../src/v3/sales/bid.ts"],"names":[],"mappings":"AAIA,OAAO,EAAsB,KAAK,cAAc,EAAE,MAAM,YAAY,CAAC;AACrE,OAAO,EAAc,KAAK,YAAY,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAG7E,OAAO,EAAmC,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC;AAE7E,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;IAC5B,wGAAwG;IACxG,IAAI,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC;IACnD,GAAG,EAAE,UAAU,CAAC;IAChB,2FAA2F;IAC3F,MAAM,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;IACzC,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,6EAA6E;IAC7E,MAAM,EAAE,UAAU,CAAC;IACnB,+BAA+B;IAC/B,IAAI,EAAE,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IAC/B,GAAG,EAAE,cAAc,CAAC;IACpB,GAAG,EAAE,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AC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;IACzC,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,6EAA6E;IAC7E,MAAM,EAAE,UAAU,CAAC;IACnB,gEAAgE;IAChE,IAAI,EAAE,UAAU,CAAC;IACjB,+BAA+B;IAC/B,IAAI,EAAE,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IAC/B,GAAG,EAAE,cAAc,CAAC;IACpB,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,gHAAgH;AAChH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;;GAGG;AACH,wBAAsB,OAAO,CAC3B,CAAC,EAAE,aAAa,GACf,OAAO,CAAC;IAAE,KAAK,EAAE,YAAY,CAAC;IAAC,OAAO,EAAE,MAAM,EAAE,CAAC;IAAC,SAAS,EAAE,gBAAgB,CAAA;CAAE,CAAC,CAwElF"}
@@ -31,6 +31,8 @@ export async function lockBid(p) {
31
31
  const [n0, n1] = p.ins.map((n, i) => noteNullifier(commitments[i], n.sk, n.pathIndex));
32
32
  const ownerPk = notePk(bid.ownerSk);
33
33
  const commit = bidCommit(bid.v, bid.s);
34
+ if (commit !== room.postedCommit)
35
+ throw new Error("the bid is not the room's posted price (bid aborts 44_035)");
34
36
  const ext = bidExt({
35
37
  room: room.id,
36
38
  seq: room.seq,
@@ -38,6 +40,7 @@ export async function lockBid(p) {
38
40
  relayerFee: p.relayerFee,
39
41
  commit,
40
42
  sealed: p.sealed,
43
+ memo: p.memo,
41
44
  encs: p.encs,
42
45
  });
43
46
  const statement = {
@@ -12,12 +12,13 @@ export type BidBody = {
12
12
  proved: Proved;
13
13
  statement: LockBidStatement;
14
14
  sealed: Uint8Array;
15
+ memo: Uint8Array;
15
16
  /** `[enc_change, enc_fee]`. */
16
17
  encs: [Uint8Array, Uint8Array];
17
18
  relayerFee: bigint;
18
19
  wait: boolean;
19
20
  };
20
- /** `sale_bid` (kinds/sale.ts): the pass proof, then the LockBid proof; pays the pool constant (`sale_room.move:297`). */
21
+ /** `sale_bid` (kinds/sale.ts): the pass proof, then the LockBid proof; pays the pool constant (`sale_room.move:317`). */
21
22
  export declare function bidBody(p: BidBody): RelayBody;
22
23
  export type FinishBody = {
23
24
  pool: CoinKey;
@@ -31,6 +32,17 @@ export type FinishBody = {
31
32
  };
32
33
  /** `sale_finish` pays no relayer: SaleSettle binds relayer `@0x0` and fee 0 (`rows.move:13-16`). */
33
34
  export declare function finishBody(p: FinishBody): RelayBody;
35
+ export type PickBody = {
36
+ pool: CoinKey;
37
+ room: string;
38
+ wait: boolean;
39
+ };
40
+ /**
41
+ * `sale_pick`: `sale_room::pick` takes `Random` (0x8), so it must be the last call of its PTB and is relayed alone.
42
+ * No proof, no pass, no fee: anyone may draw once bidding has closed.
43
+ */
44
+ export declare function pickBody(p: PickBody): RelayBody;
45
+ /** `seq` must be the room's pick (44_039); a slash clears it, so `pick` draws again. */
34
46
  export type SlashBody = {
35
47
  pool: CoinKey;
36
48
  room: string;
@@ -58,7 +70,7 @@ export type ReclaimBody = {
58
70
  relayerFee: bigint;
59
71
  wait: boolean;
60
72
  };
61
- /** `sale_reclaim` pays the pool constant (`sale_room.move:495`); the statement's relayer is the envelope's signer. */
73
+ /** `sale_reclaim` pays the pool constant (`sale_room.move:522`); the statement's relayer is the envelope's signer. */
62
74
  export declare function reclaimBody(p: ReclaimBody): RelayBody;
63
75
  export type ClaimBody =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,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,gBAAgB,CAAC;IAC5B,8BAA8B;IAC9B,IAAI,EAAE,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,OAAO,CAAC;CACf,CAAC;AAEF,sHAAsH;AACtH,wBAAgB,WAAW,CAAC,CAAC,EAAE,WAAW,GAAG,SAAS,CAuBrD;AAED,MAAM,MAAM,SAAS,GAAG;IACtB,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,OAAO,CAAC;CACf,CAAC;AAEF,+GAA+G;AAC/G,wBAAgB,SAAS,CAAC,CAAC,EAAE,SAAS,GAAG,SAAS,CAajD;AAED,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,kEAAkE;IAClE,IAAI,EAAE,IAAI,CAAC;IACX,IAAI,EAAE,OAAO,CAAC;CACf,CAAC;AAEF,qCAAqC;AACrC,wBAAgB,UAAU,CAAC,CAAC,EAAE,UAAU,GAAG,SAAS,CASnD"}
@@ -1,10 +1,11 @@
1
1
  import { address } from "../../network.js";
2
2
  import { bytesOf, encOf, envelope, fieldOf, keyArgs, passArgs, proofOf, u64Of, } from "../body-args.js";
3
3
  import { VK } from "../kinds.js";
4
+ import { MEMO_LEN } from "./memo.js";
4
5
  /** `services/relayer-v3/src/field.ts` SEALED_REQ_MAX. */
5
6
  const SEALED_MAX = 1024;
6
7
  const fields = (rows) => Object.fromEntries(Object.entries(rows).map(([k, v]) => [k, fieldOf(v, k)]));
7
- /** `sale_bid` (kinds/sale.ts): the pass proof, then the LockBid proof; pays the pool constant (`sale_room.move:297`). */
8
+ /** `sale_bid` (kinds/sale.ts): the pass proof, then the LockBid proof; pays the pool constant (`sale_room.move:317`). */
8
9
  export function bidBody(p) {
9
10
  const { tag, expiryMs } = passArgs({ ...p.pass, n0: p.statement.n0 });
10
11
  return envelope("sale_bid", p.pool, [proofOf(VK.membership, p.pass.proved), proofOf(VK.lockBid, p.proved)], {
@@ -13,6 +14,7 @@ export function bidBody(p) {
13
14
  expiryMs,
14
15
  ...fields(p.statement),
15
16
  sealed: bytesOf(p.sealed, "sealed", 1, SEALED_MAX),
17
+ memo: bytesOf(p.memo, "memo", MEMO_LEN, MEMO_LEN),
16
18
  encChange: encOf(p.encs[0], "encChange"),
17
19
  encFee: encOf(p.encs[1], "encFee"),
18
20
  }, p.relayerFee, p.wait);
@@ -38,6 +40,13 @@ export function finishBody(p) {
38
40
  encFee: encOf(p.encs[1], "encFee"),
39
41
  }, 0n, p.wait);
40
42
  }
43
+ /**
44
+ * `sale_pick`: `sale_room::pick` takes `Random` (0x8), so it must be the last call of its PTB and is relayed alone.
45
+ * No proof, no pass, no fee: anyone may draw once bidding has closed.
46
+ */
47
+ export function pickBody(p) {
48
+ return envelope("sale_pick", p.pool, [], { room: address(p.room, "room") }, 0n, p.wait);
49
+ }
41
50
  /** `sale_slash` takes no proof and pays no relayer: the derived keys of bid `seq` are the authorization. */
42
51
  export function slashBody(p) {
43
52
  return envelope("sale_slash", p.pool, [], { room: address(p.room, "room"), seq: u64Of(p.seq, "seq"), ...keyArgs(p.keys) }, 0n, p.wait);
@@ -46,7 +55,7 @@ export function slashBody(p) {
46
55
  export function expireBody(p) {
47
56
  return envelope("sale_expire", p.pool, [], { room: address(p.room, "room"), vault: address(p.vault, "vault") }, 0n, p.wait);
48
57
  }
49
- /** `sale_reclaim` pays the pool constant (`sale_room.move:495`); the statement's relayer is the envelope's signer. */
58
+ /** `sale_reclaim` pays the pool constant (`sale_room.move:522`); the statement's relayer is the envelope's signer. */
50
59
  export function reclaimBody(p) {
51
60
  const s = p.statement;
52
61
  return envelope("sale_reclaim", p.pool, [proofOf(VK.reclaim, p.proved)], {
@@ -2,8 +2,11 @@ export * from "./auctioneer.ts";
2
2
  export * from "./bid.ts";
3
3
  export * from "./bodies.ts";
4
4
  export * from "./claim.ts";
5
+ export * from "./listing.ts";
6
+ export * from "./memo.ts";
5
7
  export * from "./open-kind.ts";
6
8
  export * from "./outcome.ts";
9
+ export * from "./package-gate.ts";
7
10
  export * from "./reclaim.ts";
8
11
  export * from "./rows.ts";
9
12
  export * from "./seller.ts";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/v3/sales/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/v3/sales/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC"}
@@ -2,8 +2,11 @@ export * from "./auctioneer.js";
2
2
  export * from "./bid.js";
3
3
  export * from "./bodies.js";
4
4
  export * from "./claim.js";
5
+ export * from "./listing.js";
6
+ export * from "./memo.js";
5
7
  export * from "./open-kind.js";
6
8
  export * from "./outcome.js";
9
+ export * from "./package-gate.js";
7
10
  export * from "./reclaim.js";
8
11
  export * from "./rows.js";
9
12
  export * from "./seller.js";
@@ -0,0 +1,19 @@
1
+ /** `sale_room.move` LISTING_BLOB_LEN: every listing pads to it, so its length says nothing. */
2
+ export declare const LISTING_PLAIN_BYTES = 1024;
3
+ export type Listing = {
4
+ price: bigint;
5
+ salt: bigint;
6
+ };
7
+ /** `sale_room::listing_key_id`: blake2b256("list3" ‖ bcs(sale_key)). */
8
+ export declare const listingKeyId: (saleKey: bigint) => Uint8Array;
9
+ /** PRV-24 A: the commit every bid of the room carries. */
10
+ export declare function postedCommit(l: Listing): bigint;
11
+ export declare const LISTING_VERSION = 1;
12
+ /** `version` u8 ‖ `price` u64 ‖ `s*` u256, little-endian, then zeros to 1024 bytes. */
13
+ export declare function listingPlaintext(l: Listing): Uint8Array;
14
+ /**
15
+ * The listing only if it is exactly what `listingPlaintext` writes and it opens the room's `posted_commit`. A
16
+ * listing of another layout version throws rather than reading as malformed.
17
+ */
18
+ export declare function readListing(plain: Uint8Array | undefined, posted: bigint): Listing | undefined;
19
+ //# sourceMappingURL=listing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"listing.d.ts","sourceRoot":"","sources":["../../../src/v3/sales/listing.ts"],"names":[],"mappings":"AAOA,+FAA+F;AAC/F,eAAO,MAAM,mBAAmB,OAAO,CAAC;AAExC,MAAM,MAAM,OAAO,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAEtD,wEAAwE;AACxE,eAAO,MAAM,YAAY,GAAI,SAAS,MAAM,KAAG,UAC6D,CAAC;AAE7G,0DAA0D;AAC1D,wBAAgB,YAAY,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,CAI/C;AAED,eAAO,MAAM,eAAe,IAAI,CAAC;AAEjC,uFAAuF;AACvF,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,OAAO,GAAG,UAAU,CAKvD;AAID;;;GAGG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAQ9F"}
@@ -0,0 +1,41 @@
1
+ import { blake2b } from "@noble/hashes/blake2.js";
2
+ import { R } from "../domains.js";
3
+ import { le } from "./bcs.js";
4
+ import { bidCommit } from "./rows.js";
5
+ /** `sale_room.move` LISTING_BLOB_LEN: every listing pads to it, so its length says nothing. */
6
+ export const LISTING_PLAIN_BYTES = 1024;
7
+ /** `sale_room::listing_key_id`: blake2b256("list3" ‖ bcs(sale_key)). */
8
+ export const listingKeyId = (saleKey) => blake2b(Uint8Array.from([...Buffer.from("list3", "ascii"), ...le(saleKey, 32, "saleKey")]), { dkLen: 32 });
9
+ /** PRV-24 A: the commit every bid of the room carries. */
10
+ export function postedCommit(l) {
11
+ if (l.price <= 0n)
12
+ throw new Error("the price must be above 0");
13
+ if (l.salt < 0n || l.salt >= R)
14
+ throw new Error("the salt is not a field element");
15
+ return bidCommit(l.price, l.salt);
16
+ }
17
+ export const LISTING_VERSION = 1;
18
+ /** `version` u8 ‖ `price` u64 ‖ `s*` u256, little-endian, then zeros to 1024 bytes. */
19
+ export function listingPlaintext(l) {
20
+ postedCommit(l);
21
+ const out = new Uint8Array(LISTING_PLAIN_BYTES);
22
+ out.set([LISTING_VERSION, ...le(l.price, 8, "price"), ...le(l.salt, 32, "salt")]);
23
+ return out;
24
+ }
25
+ const readLe = (bytes) => BigInt(`0x${Buffer.from(bytes).reverse().toString("hex")}`);
26
+ /**
27
+ * The listing only if it is exactly what `listingPlaintext` writes and it opens the room's `posted_commit`. A
28
+ * listing of another layout version throws rather than reading as malformed.
29
+ */
30
+ export function readListing(plain, posted) {
31
+ if (plain?.length !== LISTING_PLAIN_BYTES)
32
+ return undefined;
33
+ if (plain[0] !== LISTING_VERSION)
34
+ throw new Error(`refused: this listing uses layout version ${plain[0]}, which this SDK does not read`);
35
+ if (plain.subarray(41).some((b) => b !== 0))
36
+ return undefined;
37
+ const l = { price: readLe(plain.subarray(1, 9)), salt: readLe(plain.subarray(9, 41)) };
38
+ if (l.price === 0n || l.salt >= R)
39
+ return undefined;
40
+ return bidCommit(l.price, l.salt) === posted ? l : undefined;
41
+ }
@@ -0,0 +1,4 @@
1
+ /** `sale_room.move` MEMO_LEN. */
2
+ export declare const MEMO_LEN = 384;
3
+ export declare function assertMemo(memo: Uint8Array): void;
4
+ //# sourceMappingURL=memo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memo.d.ts","sourceRoot":"","sources":["../../../src/v3/sales/memo.ts"],"names":[],"mappings":"AAAA,iCAAiC;AACjC,eAAO,MAAM,QAAQ,MAAM,CAAC;AAE5B,wBAAgB,UAAU,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI,CAEjD"}
@@ -0,0 +1,6 @@
1
+ /** `sale_room.move` MEMO_LEN. */
2
+ export const MEMO_LEN = 384;
3
+ export function assertMemo(memo) {
4
+ if (memo.length !== MEMO_LEN)
5
+ throw new Error(`a memo is ${MEMO_LEN} bytes`);
6
+ }