@integraledger/terms 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/README.md +135 -65
  2. package/dist/agreement.d.ts +21 -17
  3. package/dist/agreement.js +279 -85
  4. package/dist/channels.d.ts +35 -12
  5. package/dist/channels.js +152 -70
  6. package/dist/gate.d.ts +41 -18
  7. package/dist/gate.js +81 -47
  8. package/dist/index.d.ts +1 -1
  9. package/dist/pairings/batch.d.ts +2 -5
  10. package/dist/pairings/batch.js +3 -13
  11. package/dist/pairings/card.js +0 -2
  12. package/dist/pairings/common.d.ts +7 -1
  13. package/dist/pairings/common.js +17 -2
  14. package/dist/pairings/evm-x402.js +3 -3
  15. package/dist/pairings/lightning.js +1 -1
  16. package/dist/pairings/lnbtc-request.d.ts +1 -1
  17. package/dist/pairings/lnbtc-request.js +1 -1
  18. package/dist/pairings/mpp-charge-hedera.d.ts +7 -7
  19. package/dist/pairings/mpp-charge-hedera.js +1 -1
  20. package/dist/pairings/mpp-charge-stellar.js +1 -1
  21. package/dist/pairings/mpp-charge-tempo-memo.d.ts +1 -9
  22. package/dist/pairings/mpp-charge-tempo-memo.js +3 -7
  23. package/dist/pairings/mpp-charge-tempo-push.d.ts +0 -1
  24. package/dist/pairings/mpp-charge-tempo-push.js +2 -10
  25. package/dist/pairings/mpp-charge-xrpl.js +3 -3
  26. package/dist/pairings/mpp-rails.d.ts +1 -1
  27. package/dist/pairings/mpp-session-solana.js +2 -2
  28. package/dist/pairings/mpp-session-xrpl.js +3 -4
  29. package/dist/pairings/mpp-session.js +1 -1
  30. package/dist/pairings/mpp.d.ts +12 -16
  31. package/dist/pairings/mpp.js +32 -109
  32. package/dist/pairings/protocol-groups.d.ts +1 -1
  33. package/dist/pairings/x402-account-rails.d.ts +1 -1
  34. package/dist/pairings/x402-batch-settlement-eip155.js +1 -1
  35. package/dist/pairings/x402-batch-settlement-solana.d.ts +2 -0
  36. package/dist/pairings/x402-batch-settlement-solana.js +3 -2
  37. package/dist/pairings/x402-exact-casper.js +3 -3
  38. package/dist/pairings/x402-exact-ccd.js +3 -3
  39. package/dist/pairings/x402-exact-hedera.d.ts +4 -1
  40. package/dist/pairings/x402-exact-hedera.js +5 -2
  41. package/dist/pairings/x402-exact-solana.d.ts +4 -4
  42. package/dist/pairings/x402-exact-solana.js +3 -2
  43. package/dist/pairings/x402-exact-stellar.js +1 -1
  44. package/dist/pairings/x402-exact-sui.js +3 -1
  45. package/dist/pairings/x402-exact-tvm.js +10 -2
  46. package/dist/pairings/x402-exact-xrpl.js +2 -4
  47. package/dist/pairings/x402-rail.d.ts +1 -1
  48. package/dist/transact.d.ts +14 -9
  49. package/dist/transact.js +30 -24
  50. package/dist/types.d.ts +43 -18
  51. package/package.json +11 -12
package/dist/gate.js CHANGED
@@ -1,31 +1,35 @@
1
1
  /**
2
2
  * The buyer gate. `confirm` reads the offer, fetches the ATR from the seller's link, compares its SHA-256 with the
3
3
  * advertised hash, and only on a match builds the signing request with the hash it computed. `finish` completes the
4
- * payment with the signature and returns it only when what was signed carries the hash of these bytes, or, for a pairing
5
- * whose proof is the agreement payment, completes it without that reading. `check` confirms a payment held later against
6
- * kept bytes.
4
+ * payment with the signature and returns it only when the pairing's `bound` reads the hash of these bytes from the
5
+ * completed payment, or, for a pairing whose proof is the agreement payment, completes it without that reading. `check`
6
+ * confirms a payment held later against kept bytes.
7
7
  */
8
- import { hash, hashEquals, isHttpsLink, isOtherSchemeLink } from "@integraledger/lcp";
8
+ import { hash, hashEquals, isHttpsLink, isOtherSchemeLink, toBase64Url, } from "@integraledger/lcp/core";
9
+ import { isRefusal, refuse } from "./pairings/common.js";
9
10
  import { PIECES } from "./pairings/index.js";
10
11
  import { MAX_ATR_BYTES, } from "./types.js";
11
- const steps = (binding) => binding;
12
+ /** The binding's members, as the gate calls them. */
13
+ function steps(binding) {
14
+ return binding;
15
+ }
12
16
  /** A build refusal that means the pairing has nothing for the buyer to sign: the gate confirms only. */
13
17
  const NOTHING_TO_SIGN = /\/(no-signed-place|nothing-to-sign)$/;
14
18
  /** The most signer calls one payment takes: a funding and then a voucher. */
15
19
  const MAX_STEPS = 2;
16
20
  const FETCH_DEADLINE_MS = 10_000;
17
21
  const REF_BYTES = 24;
18
- const BASE64URL = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
19
22
  const DECIMAL = /^[0-9]+$/;
20
23
  export function declined(code, detail) {
21
24
  return { decline: { code, detail } };
22
25
  }
23
- function isRefusal(v) {
24
- return typeof v === "object" && v !== null && v.refused === true;
25
- }
26
26
  export function isObject(v) {
27
27
  return typeof v === "object" && v !== null && !Array.isArray(v);
28
28
  }
29
+ /** Whether a signer's `account` is a string, the form every pairing reads its payer from. */
30
+ export function hasAccount(signer) {
31
+ return typeof signer?.account === "string";
32
+ }
29
33
  /** The pairing's namespace: its id up to the first `/`. */
30
34
  export function namespaceOf(binding) {
31
35
  return String(binding.id).split("/")[0];
@@ -50,21 +54,41 @@ export function unsupported(binding) {
50
54
  const tooLarge = () => declined("atr-too-large", `The ATR is larger than ${MAX_ATR_BYTES} bytes.`);
51
55
  /** 24 random bytes as unpadded base64url: 32 characters from `[A-Za-z0-9_-]`. */
52
56
  export function newRef() {
53
- const b = crypto.getRandomValues(new Uint8Array(REF_BYTES));
54
- let s = "";
55
- for (let i = 0; i < b.length; i += 3) {
56
- const n = (b[i] << 16) | (b[i + 1] << 8) | b[i + 2];
57
- s += BASE64URL[(n >> 18) & 63] + BASE64URL[(n >> 12) & 63] + BASE64URL[(n >> 6) & 63] + BASE64URL[n & 63];
58
- }
59
- return s;
57
+ return toBase64Url(crypto.getRandomValues(new Uint8Array(REF_BYTES)));
60
58
  }
61
59
  /** Whether an answer to a `redirect: "manual"` request is a redirect: a 3xx status, or the opaque form a browser gives. */
62
60
  export function redirected(response) {
63
61
  return response.type === "opaqueredirect" || (response.status >= 300 && response.status <= 399);
64
62
  }
63
+ /** The request header that asks for the body with no content coding, so the bytes hashed are the bytes sent. */
64
+ export const IDENTITY = { "Accept-Encoding": "identity" };
65
+ /** HTTP whitespace, as the Fetch standard names it: tab, LF, CR and space. */
66
+ const HTTP_WHITESPACE = "\t\n\r ";
67
+ /**
68
+ * A header value without its leading and trailing HTTP whitespace, as Fetch normalizes one. Any other character stays,
69
+ * so a value it surrounds is read as written.
70
+ */
71
+ export function trimHttpWhitespace(value) {
72
+ let start = 0;
73
+ let end = value.length;
74
+ while (start < end && HTTP_WHITESPACE.includes(value[start]))
75
+ start++;
76
+ while (end > start && HTTP_WHITESPACE.includes(value[end - 1]))
77
+ end--;
78
+ return value.slice(start, end);
79
+ }
80
+ /**
81
+ * Whether a `Content-Encoding` value names no coding: absent, empty, or `identity`, surrounding spaces, tabs, CRs and
82
+ * LFs aside.
83
+ */
84
+ export function isIdentity(contentEncoding) {
85
+ const v = trimHttpWhitespace(contentEncoding ?? "").toLowerCase();
86
+ return v === "" || v === "identity";
87
+ }
65
88
  /**
66
- * One GET of the link, with no redirect followed, one 10-second deadline over headers and body, and at most
67
- * `MAX_ATR_BYTES` read. A redirect, like any status but 200, is `atr-unfetchable`. A declared or streamed length over the
89
+ * One GET of the link, asking for the identity coding, with no redirect followed, one 10-second deadline over headers
90
+ * and body, and at most `MAX_ATR_BYTES` read. A redirect, like any status but 200, is `atr-unfetchable`, and so is a 200
91
+ * whose `Content-Encoding` names any coding: its body is never read or decoded. A declared or streamed length over the
68
92
  * bound cancels the body. The bytes are returned exactly as received.
69
93
  */
70
94
  async function fetchAtr(fetch, link) {
@@ -79,7 +103,7 @@ async function fetchAtr(fetch, link) {
79
103
  let whole = false;
80
104
  try {
81
105
  const response = await Promise.race([
82
- fetch(link, { method: "GET", redirect: "manual", signal: controller.signal }),
106
+ fetch(link, { method: "GET", redirect: "manual", signal: controller.signal, headers: { ...IDENTITY } }),
83
107
  deadline,
84
108
  ]);
85
109
  body = response.body;
@@ -87,7 +111,11 @@ async function fetchAtr(fetch, link) {
87
111
  return declined("atr-unfetchable", "The link answered with a redirect.");
88
112
  if (response.status !== 200)
89
113
  return declined("atr-unfetchable", `The link answered status ${response.status}.`);
90
- const declared = response.headers.get("content-length")?.trim();
114
+ if (!isIdentity(response.headers.get("content-encoding"))) {
115
+ return declined("atr-unfetchable", "The link served a content coding other than identity.");
116
+ }
117
+ const length = response.headers.get("content-length");
118
+ const declared = length === null ? undefined : trimHttpWhitespace(length);
91
119
  if (declared !== undefined && DECIMAL.test(declared) && Number(declared) > MAX_ATR_BYTES)
92
120
  return tooLarge();
93
121
  if (body === null) {
@@ -141,13 +169,18 @@ function cancel(s) {
141
169
  }
142
170
  /**
143
171
  * Reads the offer, chooses the option, fetches the ATR and compares its SHA-256 with the advertised hash. Only on a
144
- * match does it build, with the hash it computed. A pairing whose build has nothing for the buyer to sign returns
145
- * `request: null`: the comparison is the whole of the buyer's step.
172
+ * match does it build, with the hash it computed. `request` is what the signer is handed, or `null` when nothing is
173
+ * handed to the signer: the pairing has nothing for the buyer to sign, or the build is itself the payment, which
174
+ * `finish` completes with no signature. For a pairing whose payment is not itself a public proof, `chosen.agreement` is
175
+ * the agreement URL the offer names. `inputs` that is not an object is declined `no-payable-option` with
176
+ * `<namespace>/input-malformed` before the offer is read.
146
177
  */
147
178
  export async function confirm(doc, binding, account, fetch, inputs = {}) {
148
179
  const piece = pieceOf(binding);
149
180
  if (piece === undefined)
150
181
  return unsupported(binding);
182
+ if (!isObject(inputs))
183
+ return declined("no-payable-option", `${namespaceOf(binding)}/input-malformed`);
151
184
  const b = steps(binding);
152
185
  const read = b.read(doc);
153
186
  if (isRefusal(read))
@@ -156,9 +189,10 @@ export async function confirm(doc, binding, account, fetch, inputs = {}) {
156
189
  if (agreement !== undefined && typeof agreement !== "string") {
157
190
  return declined("offer-unreadable", "The offer names an agreement URL that is not a string.");
158
191
  }
159
- const chosen = await piece.choose(read, account, isObject(inputs) ? inputs : {}, Math.floor(Date.now() / 1000), newRef(), doc);
160
- if (isRefusal(chosen))
161
- return declined("no-payable-option", chosen.code);
192
+ const choice = await piece.choose(read, account, inputs, Math.floor(Date.now() / 1000), newRef(), doc);
193
+ if (isRefusal(choice))
194
+ return declined("no-payable-option", choice.code);
195
+ const chosen = agreement === undefined ? choice : { ...choice, agreement };
162
196
  if (!isHttpsLink(read.link))
163
197
  return declined("link-not-https", linkRefusal(binding, read.link));
164
198
  const bytes = await fetchAtr(fetch, read.link);
@@ -172,16 +206,15 @@ export async function confirm(doc, binding, account, fetch, inputs = {}) {
172
206
  return declined("agreement-not-offered", "The pairing's payment carries no public proof and the offer names no agreement URL.");
173
207
  }
174
208
  const unsigned = await buildWith(piece, b, chosen, computed, bytes);
175
- const withAgreement = agreement === undefined ? {} : { agreement };
176
209
  if (isRefusal(unsigned)) {
177
210
  if (NOTHING_TO_SIGN.test(unsigned.code))
178
- return { chosen, request: null, bytes, h: computed, ...withAgreement };
211
+ return { chosen, request: null, bytes, h: computed };
179
212
  return declined("offer-unreadable", unsigned.code);
180
213
  }
181
214
  const request = piece.request(unsigned);
182
215
  if (isRefusal(request))
183
216
  return declined("offer-unreadable", request.code);
184
- return { chosen, request, bytes, h: computed, ...withAgreement };
217
+ return { chosen, request, bytes, h: computed };
185
218
  }
186
219
  /** The pairing's build over the choice the piece revives from `chosen`. */
187
220
  async function buildWith(piece, b, chosen, h, bytes) {
@@ -192,16 +225,17 @@ async function buildWith(piece, b, chosen, h, bytes) {
192
225
  return await (piece.build !== undefined ? piece.build(choice, h) : b.build(choice, h));
193
226
  }
194
227
  catch {
195
- return { refused: true, code: `${b.id.split("/")[0]}/build-failed` };
228
+ return refuse(`${b.id.split("/")[0]}/build-failed`);
196
229
  }
197
230
  }
198
231
  /**
199
- * Rebuilds the payment from `chosen` and the bytes, joins the signer's answer, and returns the payment only when what
200
- * was signed carries the hash of these bytes. For a pairing whose payment is not a public proof and whose `bound` finds
201
- * no signed place for the hash, the proof is the agreement payment, and the completed payment is returned as it is.
202
- * Where the signer moved the payment itself, a decline keeps it as `moved`. Where the completion carried the landed
203
- * receipt `bound` reads and the payment sent leaves it out, `landed` is returned beside the payment as JSON, each integer
204
- * a decimal string, so `check` and `openChannel` can later read the payment with it.
232
+ * Rebuilds the payment from `chosen` and the bytes, joins the signer's answer, and returns the payment only when the
233
+ * pairing's `bound` reads the hash of these bytes from the completed payment. For a pairing whose payment is not a
234
+ * public proof and whose `bound` finds no signed place for the hash, the proof is the agreement payment, and the
235
+ * completed payment is returned as it is. Where the signer moved the payment itself, a decline keeps it as `moved`.
236
+ * Where the completion carried the landed receipt `bound` reads and the payment sent leaves it out, `landed` is
237
+ * returned beside the payment as JSON, each integer a decimal string, so `check` and `openChannel` can later read the
238
+ * payment with it.
205
239
  */
206
240
  export async function finish(bytes, chosen, signature, binding) {
207
241
  const piece = pieceOf(binding);
@@ -237,7 +271,7 @@ export async function finish(bytes, chosen, signature, binding) {
237
271
  const inside = await boundOf(b, signed);
238
272
  const onAgreement = !isPublicProof(binding) && isRefusal(inside) && NOTHING_TO_SIGN.test(inside.code);
239
273
  if (!onAgreement && (isRefusal(inside) || !hashEquals(inside, h))) {
240
- return keep(declined("signed-not-bound", "What was signed does not carry the hash of these bytes."), sent);
274
+ return keep(declined("signed-not-bound", "The pairing does not read the hash of the compared bytes from the payment."), sent);
241
275
  }
242
276
  const landed = sent !== signed && isObject(signed) ? jsonSafe(signed.landed) : undefined;
243
277
  return landed === undefined ? { signed: sent, h } : { signed: sent, landed, h };
@@ -267,34 +301,34 @@ async function boundOf(b, presented) {
267
301
  return await b.bound(presented);
268
302
  }
269
303
  catch {
270
- return { refused: true, code: "bound-failed" };
304
+ return refuse("bound-failed");
271
305
  }
272
306
  }
273
- /** Confirms that a payment held later carries, inside what was signed, the hash of the kept bytes. */
307
+ /**
308
+ * Confirms that the ATR hash the pairing reads from a payment held later is the SHA-256 of the kept bytes. A payment
309
+ * from which the pairing reads no ATR hash is declined `signed-not-bound`.
310
+ */
274
311
  export async function check(bytes, presented, binding) {
275
312
  if (bytes.length > MAX_ATR_BYTES)
276
313
  return tooLarge();
277
314
  const h = await hash(bytes);
278
315
  const b = await boundOf(steps(binding), presented);
279
316
  if (isRefusal(b) || !hashEquals(b, h)) {
280
- return declined("signed-not-bound", "The payment does not carry the hash of these bytes.");
317
+ return declined("signed-not-bound", "The pairing does not read the hash of the compared bytes from the payment.");
281
318
  }
282
319
  return { h };
283
320
  }
284
321
  /**
285
- * Chooses, builds and signs one payment for a read the caller has already compared: the signer is called once, or,
286
- * for a pairing signed in steps, once per step in order, and the payment is returned only through `finish`.
322
+ * Builds and signs the payment `chosen` names, with the hash of `bytes`: the signer is called once, or, for a pairing
323
+ * signed in steps, once per step in order, and the payment is returned only through `finish`. `signed` is null where the
324
+ * pairing has nothing for the buyer to sign.
287
325
  */
288
- export async function pay(binding, read, doc, signer, inputs, bytes) {
326
+ export async function pay(binding, chosen, signer, bytes) {
289
327
  const piece = pieceOf(binding);
290
328
  if (piece === undefined)
291
329
  return unsupported(binding);
292
- const b = steps(binding);
293
- const chosen = await piece.choose(read, signer.account, isObject(inputs) ? inputs : {}, Math.floor(Date.now() / 1000), newRef(), doc);
294
- if (isRefusal(chosen))
295
- return declined("no-payable-option", chosen.code);
296
330
  const h = await hash(bytes);
297
- const unsigned = await buildWith(piece, b, chosen, h, bytes);
331
+ const unsigned = await buildWith(piece, steps(binding), chosen, h, bytes);
298
332
  if (isRefusal(unsigned)) {
299
333
  if (NOTHING_TO_SIGN.test(unsigned.code))
300
334
  return { signed: null, h };
package/dist/index.d.ts CHANGED
@@ -2,4 +2,4 @@ export { agree } from "./agreement.js";
2
2
  export { openChannel, recordCharge, within, type ChannelHold } from "./channels.js";
3
3
  export { check, confirm, finish } from "./gate.js";
4
4
  export { transact } from "./transact.js";
5
- export type { AgreementReceipt, Binding, Chosen, DeclineCode, Declined, Fetch, Inputs, Presented, Reason, Signature, Signer, SigningRequest, TransactOptions, } from "./types.js";
5
+ export type { AgreeOptions, AgreementPayment, AgreementReceipt, Binding, Chosen, DeclineCode, Declined, Fetch, Inputs, Presented, Reason, Signature, Signer, SigningRequest, ToApprove, TransactOptions, } from "./types.js";
@@ -3,13 +3,10 @@
3
3
  * built, and the payment the list of answers completes, with the payment
4
4
  * identifier appended where the challenge advertises it.
5
5
  */
6
- import type { Json, Refusal } from "@integraledger/lcp";
6
+ import type { Json, Refusal } from "@integraledger/lcp/core";
7
7
  import type { PaymentRequirements } from "@integraledger/lcp/x402";
8
8
  import type { Chosen, Inputs, Presented, Signature, SigningRequest } from "../types.js";
9
- /**
10
- * The deposit: `extra.minDeposit` when the option carries one, else the buyer's `deposit` input. A deposit above the
11
- * buyer's `maxDeposit` input, when given, is refused.
12
- */
9
+ /** The deposit: `extra.minDeposit` when the option carries one, else the buyer's `deposit` input. */
13
10
  export declare function depositOf(accepted: PaymentRequirements, inputs: Inputs): string | Refusal;
14
11
  /** `n` bytes from the platform's CSPRNG. */
15
12
  export declare function randomBytes(n: number): Uint8Array;
@@ -1,20 +1,10 @@
1
- import { bigintOf, choiceOf, hexOf, isObject, refuse, withPaymentIdentifier } from "./common.js";
2
- /**
3
- * The deposit: `extra.minDeposit` when the option carries one, else the buyer's `deposit` input. A deposit above the
4
- * buyer's `maxDeposit` input, when given, is refused.
5
- */
1
+ import { bigintOf, choiceOf, hexOf, isObject, isRefusal, refuse, withPaymentIdentifier } from "./common.js";
2
+ /** The deposit: `extra.minDeposit` when the option carries one, else the buyer's `deposit` input. */
6
3
  export function depositOf(accepted, inputs) {
7
4
  const min = isObject(accepted.extra) ? accepted.extra["minDeposit"] : undefined;
8
5
  const deposit = min !== undefined ? bigintOf(min) : bigintOf(inputs["deposit"]);
9
6
  if (deposit === undefined)
10
7
  return refuse(min !== undefined ? "x402/option-malformed" : "x402/input-missing");
11
- if (inputs["maxDeposit"] !== undefined) {
12
- const max = bigintOf(inputs["maxDeposit"]);
13
- if (max === undefined)
14
- return refuse("x402/input-missing");
15
- if (deposit > max)
16
- return refuse("x402/deposit-above-maximum");
17
- }
18
8
  return deposit.toString();
19
9
  }
20
10
  /** `n` bytes from the platform's CSPRNG. */
@@ -47,7 +37,7 @@ export async function batchComplete(unsigned, signature, chosen) {
47
37
  return refuse("x402/signature-malformed");
48
38
  }
49
39
  const signed = u.complete(signature);
50
- if ("refused" in signed)
40
+ if (isRefusal(signed))
51
41
  return signed;
52
42
  return withPaymentIdentifier(signed, choiceOf(chosen)?.["required"], chosen.ref);
53
43
  }
@@ -6,8 +6,6 @@ function chooseDoc(_read, account, _inputs, _now, _ref, doc) {
6
6
  const unnamed = unnamedBuyer(account, NS);
7
7
  if (unnamed !== undefined)
8
8
  return unnamed;
9
- if (doc === undefined)
10
- return refuse("card/document-missing");
11
9
  return { doc: doc };
12
10
  }
13
11
  function docOf(chosen) {
@@ -2,10 +2,16 @@
2
2
  * What the buyer pieces share: the CAIP-10 account, the first x402 option on the account's network, the payment
3
3
  * identifier the x402 client writes, and the JSON forms of byte strings and integers.
4
4
  */
5
- import type { Json, Refusal } from "@integraledger/lcp";
5
+ import { type Json, type Refusal } from "@integraledger/lcp/core";
6
6
  import type { PaymentRequired, PaymentRequirements, X402Offer } from "@integraledger/lcp/x402";
7
7
  import type { Chosen, Inputs, Read } from "../types.js";
8
+ /** A refusal with `code`, made by the gate. */
8
9
  export declare function refuse(code: string): Refusal;
10
+ /**
11
+ * True for a refusal any installed copy of the protocol package made (its `isRefusal`, which reads the package's mark)
12
+ * or the gate made (`refuse`). The mark and membership, not shape, make a value one of them: a value from a seller, a
13
+ * signer or a caller that is shaped `{ refused: true, … }` is never passed on as a refusal.
14
+ */
9
15
  export declare function isRefusal(v: unknown): v is Refusal;
10
16
  export declare function isObject(v: unknown): v is Record<string, unknown>;
11
17
  /**
@@ -1,12 +1,27 @@
1
+ /**
2
+ * What the buyer pieces share: the CAIP-10 account, the first x402 option on the account's network, the payment
3
+ * identifier the x402 client writes, and the JSON forms of byte strings and integers.
4
+ */
5
+ import { isRefusal as isLcpRefusal } from "@integraledger/lcp/core";
1
6
  const CAIP10 = /^([-a-z0-9]{3,8}):([-_a-zA-Z0-9]{1,32}):([-.%a-zA-Z0-9]{1,128})$/;
2
7
  const PAYMENT_IDENTIFIER = "payment-identifier";
3
8
  const HEX = /^0x(?:[0-9a-fA-F]{2})*$/;
4
9
  const DECIMAL = /^[0-9]{1,78}$/;
10
+ /** Every refusal the gate makes. Membership, not shape, is what makes a value one of them. */
11
+ const made = new WeakSet();
12
+ /** A refusal with `code`, made by the gate. */
5
13
  export function refuse(code) {
6
- return { refused: true, code };
14
+ const r = { refused: true, code };
15
+ made.add(r);
16
+ return r;
7
17
  }
18
+ /**
19
+ * True for a refusal any installed copy of the protocol package made (its `isRefusal`, which reads the package's mark)
20
+ * or the gate made (`refuse`). The mark and membership, not shape, make a value one of them: a value from a seller, a
21
+ * signer or a caller that is shaped `{ refused: true, … }` is never passed on as a refusal.
22
+ */
8
23
  export function isRefusal(v) {
9
- return typeof v === "object" && v !== null && v.refused === true;
24
+ return isLcpRefusal(v) || (typeof v === "object" && v !== null && made.has(v));
10
25
  }
11
26
  export function isObject(v) {
12
27
  return typeof v === "object" && v !== null && !Array.isArray(v);
@@ -1,4 +1,4 @@
1
- import { choiceOf, firstOption, isObject, refuse, withPaymentIdentifier, x402Chosen } from "./common.js";
1
+ import { choiceOf, firstOption, isObject, isRefusal, refuse, withPaymentIdentifier, x402Chosen } from "./common.js";
2
2
  const EVM_ADDRESS = /^0x[0-9a-fA-F]{40}$/;
3
3
  /** An EIP-712 signing request, from either form of an EVM x402 build. */
4
4
  function request(unsigned) {
@@ -29,7 +29,7 @@ async function complete(unsigned, signature, chosen) {
29
29
  delegator: delegator,
30
30
  });
31
31
  }
32
- if ("refused" in signed)
32
+ if (isRefusal(signed))
33
33
  return signed;
34
34
  return withPaymentIdentifier(signed, choiceOf(chosen)?.["required"], chosen.ref);
35
35
  }
@@ -38,7 +38,7 @@ export function evmX402Piece(pairing) {
38
38
  return Object.freeze({
39
39
  choose(read, account, _inputs, now, ref) {
40
40
  const o = firstOption(read, account, "eip155", pairing, EVM_ADDRESS);
41
- if ("refused" in o)
41
+ if (isRefusal(o))
42
42
  return refuse("x402/no-payable-option");
43
43
  return x402Chosen(pairing, { required: o.required, accepted: o.accepted, from: o.address, now }, ref);
44
44
  },
@@ -41,7 +41,7 @@ export function lnbtcPiece(pairing, named) {
41
41
  return Object.freeze({
42
42
  async choose(read, account, inputs, _now, ref) {
43
43
  const o = firstOption(read, account, "lnbtc", pairing);
44
- if ("refused" in o)
44
+ if (isRefusal(o))
45
45
  return refuse("x402/no-payable-option");
46
46
  const request = isObject(inputs) ? inputs["request"] : undefined;
47
47
  if (request === undefined)
@@ -9,7 +9,7 @@
9
9
  * - `mcp:1`: `{server, name, arguments?, meta?}`, `server` the MCP server's URI as the buyer's own configuration spells
10
10
  * it, `name` and `arguments` the `tools/call` params, `meta` its `params._meta`.
11
11
  */
12
- import { type Json, type Refusal } from "@integraledger/lcp";
12
+ import { type Json, type Refusal } from "@integraledger/lcp/core";
13
13
  /**
14
14
  * The binding object of the buyer's own `request` under a profile and its parameters, the profile being the one the
15
15
  * request's transport uses: `http:1` for an HTTP request, `mcp:1` for a `tools/call`.
@@ -9,7 +9,7 @@
9
9
  * - `mcp:1`: `{server, name, arguments?, meta?}`, `server` the MCP server's URI as the buyer's own configuration spells
10
10
  * it, `name` and `arguments` the `tools/call` params, `meta` its `params._meta`.
11
11
  */
12
- import { canonicalJson, hash } from "@integraledger/lcp";
12
+ import { canonicalJson, hash } from "@integraledger/lcp/core";
13
13
  import { decodeBolt11, invoiceH } from "@integraledger/lcp/lightning";
14
14
  import { bytesOf, isObject, isRefusal, refuse } from "./common.js";
15
15
  const HTTP_DOMAIN = "x402:exact:lnbtc:bolt11:http:1";
@@ -3,14 +3,14 @@
3
3
  * challenge, handed to the payer as `hedera-body`. The node, the valid start, the maximum fee, the optional client id
4
4
  * and the optional `credentialType` are the buyer's. A challenge that names no `chainId` is read on the account's own
5
5
  * network.
6
- * - `credentialType` `transaction` (the default, pull): the signer answers `{publicKey, signature, type}`, and the
7
- * credential is `{challenge, payload: {type: "transaction", transaction}}`, the signed body in base64.
8
- * - `credentialType` `hash` (push): the build's request carries `broadcast: true`; the signer signs and broadcasts the body and
9
- * answers `{transactionId}`, which must name the body's payer and valid start. The credential is `{challenge,
10
- * payload: {type: "hash", transactionId}}`, and `landed` beside it holds the network and the body's memo, which
11
- * `bound` reads. The signer moves the payment, so a decline keeps it.
6
+ * - `credentialType` `hash` (push, the default when none is named): the build's request carries `broadcast: true`; the
7
+ * signer signs and broadcasts the body and answers `{transactionId}`, which must name the body's payer and valid
8
+ * start. The credential is `{challenge, payload: {type: "hash", transactionId}}`, and `landed` beside it holds the
9
+ * network and the body's memo, which `bound` reads. The signer moves the payment, so a decline keeps it.
10
+ * - `credentialType` `transaction` (pull): the signer answers `{publicKey, signature, type}`, and the credential is
11
+ * `{challenge, payload: {type: "transaction", transaction}}`, the signed body in base64.
12
12
  */
13
- import type { AtrHash } from "@integraledger/lcp";
13
+ import type { AtrHash } from "@integraledger/lcp/core";
14
14
  import type { BuyerPiece } from "../types.js";
15
15
  /**
16
16
  * The binding's build, called with the chosen challenge's id and realm, its decoded request, and the payer's values,
@@ -46,7 +46,7 @@ function answer(signature) {
46
46
  }
47
47
  return { publicKey, signature: bytes, type: type };
48
48
  }
49
- const isPush = (c) => c?.["credentialType"] === "hash";
49
+ const isPush = (c) => c !== undefined && c["credentialType"] !== "transaction";
50
50
  /** The push answer's transaction id, when it names the body's payer and valid start. */
51
51
  function pushedId(signature, c) {
52
52
  const id = isObject(signature) ? signature["transactionId"] : undefined;
@@ -8,7 +8,7 @@ export const mppChargeStellar = mppRailPiece({
8
8
  pairing: PAIRING,
9
9
  namespace: "stellar",
10
10
  address: STELLAR_ACCOUNT,
11
- payer: null,
11
+ payer: "payer",
12
12
  now: true,
13
13
  inputs,
14
14
  revive: (c) => c,
@@ -1,9 +1 @@
1
- export declare const mppChargeTempoMemo: Readonly<{
2
- choose(read: import("../types.js").Read, account: string, inputs: import("../types.js").Inputs, now: number, ref: string, doc: unknown): ReturnType<import("../types.js").Choose> | Promise<ReturnType<import("../types.js").Choose>>;
3
- choice(chosen: import("../types.js").Chosen, bytes: Uint8Array): unknown;
4
- request(unsigned: unknown): import("../types.js").SigningRequest | null | import("@integraledger/lcp").Refusal;
5
- complete(unsigned: unknown, signature: import("../types.js").Signature, chosen: import("../types.js").Chosen): Promise<import("../types.js").Presented | import("../types.js").Next | import("@integraledger/lcp").Refusal>;
6
- sent?(signed: import("../types.js").Presented): import("../types.js").Presented;
7
- moves?(request: import("../types.js").SigningRequest): boolean;
8
- build: (choice: unknown, h: import("@integraledger/lcp").AtrHash) => Promise<unknown>;
9
- }>;
1
+ export declare const mppChargeTempoMemo: import("../types.js").BuyerPiece;
@@ -1,10 +1,6 @@
1
1
  /**
2
2
  * The buyer piece for `mpp/charge/tempo/memo`: the answer is the signed `0x76` transaction; `clientId` is optional.
3
- * With splits, the transaction carries one call per recipient.
3
+ * The build is the protocol package's: with splits, its `tempo-calls` request holds one call per recipient.
4
4
  */
5
- import { tempoMemo } from "@integraledger/lcp/mpp";
6
- import { acceptSplits, mppChargePiece, tempoBuild } from "./mpp.js";
7
- export const mppChargeTempoMemo = Object.freeze({
8
- ...mppChargePiece("mpp/charge/tempo/memo", { clientId: "optional-string" }, acceptSplits),
9
- build: tempoBuild(tempoMemo),
10
- });
5
+ import { mppChargePiece } from "./mpp.js";
6
+ export const mppChargeTempoMemo = mppChargePiece("mpp/charge/tempo/memo", { clientId: "optional-string" });
@@ -4,7 +4,6 @@ import { mppChoice, mppRequest, pushComplete } from "./mpp.js";
4
4
  export declare const mppChargeTempoPush: Readonly<{
5
5
  choose: import("../types.js").Choose;
6
6
  choice: typeof mppChoice;
7
- build: (choice: unknown, h: import("../types.js").AtrHash) => Promise<unknown>;
8
7
  request: typeof mppRequest;
9
8
  complete: typeof pushComplete;
10
9
  moves: typeof broadcasts;
@@ -1,16 +1,8 @@
1
- /**
2
- * The buyer piece for `mpp/charge/tempo/push`: the signer broadcasts and answers the hash with its landed receipt, which
3
- * `bound` reads for the memo. The payment sent is the credential without the landed receipt. The signer moves the
4
- * payment, so a decline keeps it. With splits, the
5
- * transaction carries one call per recipient.
6
- */
7
- import { tempoPush } from "@integraledger/lcp/mpp";
8
1
  import { broadcasts } from "./common.js";
9
- import { acceptSplits, mppChoice, mppChoose, mppRequest, pushComplete, tempoBuild } from "./mpp.js";
2
+ import { mppChoice, mppChoose, mppRequest, pushComplete } from "./mpp.js";
10
3
  export const mppChargeTempoPush = Object.freeze({
11
- choose: mppChoose("mpp/charge/tempo/push", { clientId: "optional-string" }, acceptSplits),
4
+ choose: mppChoose("mpp/charge/tempo/push", { clientId: "optional-string" }),
12
5
  choice: mppChoice,
13
- build: tempoBuild(tempoPush),
14
6
  request: mppRequest,
15
7
  complete: pushComplete,
16
8
  moves: broadcasts,
@@ -1,12 +1,12 @@
1
1
  import { inputsOf, refuse } from "./common.js";
2
- import { completeWith, hexDigits, mppRailPiece, XRPL_ADDRESS } from "./mpp-rails.js";
2
+ import { completeWith, mppRailPiece, XRPL_ADDRESS } from "./mpp-rails.js";
3
3
  const PAIRING = "mpp/charge/xrpl";
4
4
  function inputs(_request, given) {
5
5
  return inputsOf(given, PAIRING, { fee: "decimal", sequence: "uint", lastLedgerSequence: "uint" });
6
6
  }
7
- /** The signed blob's hex digits, from `0x` hex. */
7
+ /** The signed blob as given: the build's `complete` reads it as hex digits without `0x`. */
8
8
  function blob(signature) {
9
- return hexDigits(signature) ?? refuse("mpp/credential-malformed");
9
+ return typeof signature === "string" ? signature : refuse("mpp/credential-malformed");
10
10
  }
11
11
  export const mppChargeXrpl = mppRailPiece({
12
12
  pairing: PAIRING,
@@ -4,7 +4,7 @@
4
4
  * the buyer's own inputs beside it as JSON; the build's request exactly as built; and the credential the signer's
5
5
  * answer completes.
6
6
  */
7
- import type { Json, Refusal } from "@integraledger/lcp";
7
+ import type { Json, Refusal } from "@integraledger/lcp/core";
8
8
  import { type MppChallenge } from "@integraledger/lcp/mpp";
9
9
  import type { BuyerPiece, Choose, Chosen, Inputs, Next, Presented, Signature, SigningRequest } from "../types.js";
10
10
  export declare const HEDERA_EVM_ADDRESS: RegExp;
@@ -1,5 +1,5 @@
1
1
  import { sessionProof } from "@integraledger/lcp/svm";
2
- import { choiceOf, inputsOf, isObject, refuse } from "./common.js";
2
+ import { choiceOf, inputsOf, isObject, isRefusal, refuse } from "./common.js";
3
3
  import { requestOf } from "./mpp.js";
4
4
  import { completeWith, mppRailPiece, sessionRevive } from "./mpp-rails.js";
5
5
  import { SOLANA_ADDRESS } from "./x402-exact-solana.js";
@@ -30,7 +30,7 @@ async function complete(unsigned, signature, chosen) {
30
30
  const mode = operatorMode(chosen);
31
31
  if (mode === null)
32
32
  return completeOpen(unsigned, signature, chosen);
33
- if ("refused" in mode)
33
+ if (isRefusal(mode))
34
34
  return mode;
35
35
  if (isObject(signature)) {
36
36
  const channelId = signature["channelId"];
@@ -20,13 +20,12 @@ function inputs(_request, given) {
20
20
  return refuse("mpp/input-missing");
21
21
  return { ...read, xrpl: { ...x, publicKey } };
22
22
  }
23
- /** `{signedBlob, claimSignature}` as the build's hex digits, from `0x` hex. */
23
+ /** `{signedBlob, claimSignature}` as given: the build's `complete` reads each as hex digits without `0x`. */
24
24
  function answer(signature) {
25
25
  if (!isObject(signature))
26
26
  return refuse("mpp/credential-malformed");
27
- const signedBlob = hexDigits(signature["signedBlob"]);
28
- const claimSignature = hexDigits(signature["claimSignature"]);
29
- if (signedBlob === undefined || claimSignature === undefined)
27
+ const { signedBlob, claimSignature } = signature;
28
+ if (typeof signedBlob !== "string" || typeof claimSignature !== "string")
30
29
  return refuse("mpp/credential-malformed");
31
30
  return { signedBlob, claimSignature };
32
31
  }
@@ -35,7 +35,7 @@ async function sessionComplete(unsigned, signature) {
35
35
  const u = unsigned;
36
36
  if (typeof signature === "string") {
37
37
  const voucher = u.voucher(signature);
38
- if ("refused" in voucher)
38
+ if (isRefusal(voucher))
39
39
  return voucher;
40
40
  return { next: { kind: "eip712", typedData: voucher } };
41
41
  }