@integraledger/terms 0.2.0 → 0.3.1

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 (44) hide show
  1. package/README.md +88 -52
  2. package/dist/agreement.d.ts +14 -4
  3. package/dist/agreement.js +139 -49
  4. package/dist/channels.d.ts +47 -14
  5. package/dist/channels.js +147 -74
  6. package/dist/gate.d.ts +37 -16
  7. package/dist/gate.js +69 -45
  8. package/dist/pairings/batch.d.ts +2 -5
  9. package/dist/pairings/batch.js +1 -11
  10. package/dist/pairings/card.js +0 -2
  11. package/dist/pairings/common.d.ts +17 -4
  12. package/dist/pairings/common.js +35 -4
  13. package/dist/pairings/lnbtc-request.d.ts +1 -1
  14. package/dist/pairings/lnbtc-request.js +14 -5
  15. package/dist/pairings/mpp-charge-hedera.d.ts +13 -11
  16. package/dist/pairings/mpp-charge-hedera.js +16 -14
  17. package/dist/pairings/mpp-charge-tempo-memo.d.ts +1 -9
  18. package/dist/pairings/mpp-charge-tempo-memo.js +3 -7
  19. package/dist/pairings/mpp-charge-tempo-push.d.ts +6 -1
  20. package/dist/pairings/mpp-charge-tempo-push.js +4 -13
  21. package/dist/pairings/mpp-charge-xrpl.js +3 -3
  22. package/dist/pairings/mpp-rails.d.ts +1 -1
  23. package/dist/pairings/mpp-session-hedera.js +3 -4
  24. package/dist/pairings/mpp-session-xrpl.js +3 -4
  25. package/dist/pairings/mpp.d.ts +14 -17
  26. package/dist/pairings/mpp.js +35 -114
  27. package/dist/pairings/protocol-groups.d.ts +1 -1
  28. package/dist/pairings/x402-account-rails.d.ts +1 -1
  29. package/dist/pairings/x402-batch-settlement-solana.d.ts +2 -0
  30. package/dist/pairings/x402-batch-settlement-solana.js +2 -1
  31. package/dist/pairings/x402-exact-hedera.d.ts +4 -1
  32. package/dist/pairings/x402-exact-hedera.js +5 -2
  33. package/dist/pairings/x402-exact-near.js +23 -2
  34. package/dist/pairings/x402-exact-solana.d.ts +4 -4
  35. package/dist/pairings/x402-exact-solana.js +3 -2
  36. package/dist/pairings/x402-exact-sui.js +3 -1
  37. package/dist/pairings/x402-exact-tvm.js +10 -2
  38. package/dist/pairings/x402-exact-xrpl.js +2 -4
  39. package/dist/pairings/x402-rail.d.ts +3 -2
  40. package/dist/pairings/x402-rail.js +1 -1
  41. package/dist/transact.d.ts +3 -2
  42. package/dist/transact.js +9 -6
  43. package/dist/types.d.ts +6 -16
  44. package/package.json +10 -12
package/dist/gate.js CHANGED
@@ -1,22 +1,24 @@
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";
9
- import { isRefusal, refuse } from "./pairings/common.js";
8
+ import { hash, hashEquals, isHttpsLink, isOtherSchemeLink, toBase64Url, } from "@integraledger/lcp/core";
9
+ import { fetchedOf, held, isRefusal, jsonSafe, refuse } from "./pairings/common.js";
10
10
  import { PIECES } from "./pairings/index.js";
11
11
  import { MAX_ATR_BYTES, } from "./types.js";
12
- const steps = (binding) => binding;
12
+ /** The binding's members, as the gate calls them. */
13
+ function steps(binding) {
14
+ return binding;
15
+ }
13
16
  /** A build refusal that means the pairing has nothing for the buyer to sign: the gate confirms only. */
14
17
  const NOTHING_TO_SIGN = /\/(no-signed-place|nothing-to-sign)$/;
15
18
  /** The most signer calls one payment takes: a funding and then a voucher. */
16
19
  const MAX_STEPS = 2;
17
20
  const FETCH_DEADLINE_MS = 10_000;
18
21
  const REF_BYTES = 24;
19
- const BASE64URL = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
20
22
  const DECIMAL = /^[0-9]+$/;
21
23
  export function declined(code, detail) {
22
24
  return { decline: { code, detail } };
@@ -24,6 +26,10 @@ export function declined(code, detail) {
24
26
  export function isObject(v) {
25
27
  return typeof v === "object" && v !== null && !Array.isArray(v);
26
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
+ }
27
33
  /** The pairing's namespace: its id up to the first `/`. */
28
34
  export function namespaceOf(binding) {
29
35
  return String(binding.id).split("/")[0];
@@ -48,13 +54,7 @@ export function unsupported(binding) {
48
54
  const tooLarge = () => declined("atr-too-large", `The ATR is larger than ${MAX_ATR_BYTES} bytes.`);
49
55
  /** 24 random bytes as unpadded base64url: 32 characters from `[A-Za-z0-9_-]`. */
50
56
  export function newRef() {
51
- const b = crypto.getRandomValues(new Uint8Array(REF_BYTES));
52
- let s = "";
53
- for (let i = 0; i < b.length; i += 3) {
54
- const n = (b[i] << 16) | (b[i + 1] << 8) | b[i + 2];
55
- s += BASE64URL[(n >> 18) & 63] + BASE64URL[(n >> 12) & 63] + BASE64URL[(n >> 6) & 63] + BASE64URL[n & 63];
56
- }
57
- return s;
57
+ return toBase64Url(crypto.getRandomValues(new Uint8Array(REF_BYTES)));
58
58
  }
59
59
  /** Whether an answer to a `redirect: "manual"` request is a redirect: a 3xx status, or the opaque form a browser gives. */
60
60
  export function redirected(response) {
@@ -62,9 +62,27 @@ export function redirected(response) {
62
62
  }
63
63
  /** The request header that asks for the body with no content coding, so the bytes hashed are the bytes sent. */
64
64
  export const IDENTITY = { "Accept-Encoding": "identity" };
65
- /** Whether a `Content-Encoding` value names no coding: absent, empty, or `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
+ */
66
84
  export function isIdentity(contentEncoding) {
67
- const v = (contentEncoding ?? "").trim().toLowerCase();
85
+ const v = trimHttpWhitespace(contentEncoding ?? "").toLowerCase();
68
86
  return v === "" || v === "identity";
69
87
  }
70
88
  /**
@@ -96,7 +114,8 @@ async function fetchAtr(fetch, link) {
96
114
  if (!isIdentity(response.headers.get("content-encoding"))) {
97
115
  return declined("atr-unfetchable", "The link served a content coding other than identity.");
98
116
  }
99
- const declared = response.headers.get("content-length")?.trim();
117
+ const length = response.headers.get("content-length");
118
+ const declared = length === null ? undefined : trimHttpWhitespace(length);
100
119
  if (declared !== undefined && DECIMAL.test(declared) && Number(declared) > MAX_ATR_BYTES)
101
120
  return tooLarge();
102
121
  if (body === null) {
@@ -150,14 +169,18 @@ function cancel(s) {
150
169
  }
151
170
  /**
152
171
  * Reads the offer, chooses the option, fetches the ATR and compares its SHA-256 with the advertised hash. Only on a
153
- * match does it build, with the hash it computed. A pairing whose build has nothing for the buyer to sign returns
154
- * `request: null`: the comparison is the whole of the buyer's step. For a pairing whose payment is not itself a public
155
- * proof, `chosen.agreement` is the agreement URL the offer names.
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.
156
177
  */
157
178
  export async function confirm(doc, binding, account, fetch, inputs = {}) {
158
179
  const piece = pieceOf(binding);
159
180
  if (piece === undefined)
160
181
  return unsupported(binding);
182
+ if (!isObject(inputs))
183
+ return declined("no-payable-option", `${namespaceOf(binding)}/input-malformed`);
161
184
  const b = steps(binding);
162
185
  const read = b.read(doc);
163
186
  if (isRefusal(read))
@@ -166,7 +189,7 @@ export async function confirm(doc, binding, account, fetch, inputs = {}) {
166
189
  if (agreement !== undefined && typeof agreement !== "string") {
167
190
  return declined("offer-unreadable", "The offer names an agreement URL that is not a string.");
168
191
  }
169
- const choice = await piece.choose(read, account, isObject(inputs) ? inputs : {}, Math.floor(Date.now() / 1000), newRef(), doc);
192
+ const choice = await piece.choose(read, account, inputs, Math.floor(Date.now() / 1000), newRef(), doc);
170
193
  if (isRefusal(choice))
171
194
  return declined("no-payable-option", choice.code);
172
195
  const chosen = agreement === undefined ? choice : { ...choice, agreement };
@@ -206,12 +229,13 @@ async function buildWith(piece, b, chosen, h, bytes) {
206
229
  }
207
230
  }
208
231
  /**
209
- * Rebuilds the payment from `chosen` and the bytes, joins the signer's answer, and returns the payment only when what
210
- * was signed carries the hash of these bytes. For a pairing whose payment is not a public proof and whose `bound` finds
211
- * no signed place for the hash, the proof is the agreement payment, and the completed payment is returned as it is.
212
- * Where the signer moved the payment itself, a decline keeps it as `moved`. Where the completion carried the landed
213
- * receipt `bound` reads and the payment sent leaves it out, `landed` is returned beside the payment as JSON, each integer
214
- * 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.
215
239
  */
216
240
  export async function finish(bytes, chosen, signature, binding) {
217
241
  const piece = pieceOf(binding);
@@ -247,23 +271,11 @@ export async function finish(bytes, chosen, signature, binding) {
247
271
  const inside = await boundOf(b, signed);
248
272
  const onAgreement = !isPublicProof(binding) && isRefusal(inside) && NOTHING_TO_SIGN.test(inside.code);
249
273
  if (!onAgreement && (isRefusal(inside) || !hashEquals(inside, h))) {
250
- 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);
251
275
  }
252
- const landed = sent !== signed && isObject(signed) ? jsonSafe(signed.landed) : undefined;
276
+ const landed = sent !== signed ? jsonSafe(fetchedOf(signed)) : undefined;
253
277
  return landed === undefined ? { signed: sent, h } : { signed: sent, landed, h };
254
278
  }
255
- /** A value as JSON, each bigint as its decimal string; undefined when it is undefined or has no JSON form. */
256
- function jsonSafe(v) {
257
- if (v === undefined)
258
- return undefined;
259
- try {
260
- const text = JSON.stringify(v, (_k, x) => (typeof x === "bigint" ? x.toString() : x));
261
- return text === undefined ? undefined : JSON.parse(text);
262
- }
263
- catch {
264
- return undefined;
265
- }
266
- }
267
279
  /** Whether the signer, handed the build's first request, moves the payment itself. */
268
280
  function movesWith(piece, unsigned) {
269
281
  if (piece.moves === undefined)
@@ -280,14 +292,26 @@ async function boundOf(b, presented) {
280
292
  return refuse("bound-failed");
281
293
  }
282
294
  }
283
- /** Confirms that a payment held later carries, inside what was signed, the hash of the kept bytes. */
284
- export async function check(bytes, presented, binding) {
295
+ /**
296
+ * Confirms that the ATR hash the pairing reads from a payment held later is the SHA-256 of the kept bytes, with the
297
+ * `landed` receipt `finish` or `transact` returned beside the payment, where it returned one, held under the payment's
298
+ * own `FETCHED` member as `bound` reads it. The caller passes as `landed` only the receipt its own reader read for the
299
+ * payment, as `finish` or `transact` returned it, never a value another party sent. A `landed` of `null` is no
300
+ * receipt: the payment is read alone, as without one. A payment from which the pairing reads no ATR hash is declined
301
+ * `signed-not-bound`, as is a `landed` receipt that is not a JSON object beside a payment that is one. A `landed`
302
+ * member of the payment's own is not read.
303
+ */
304
+ export async function check(bytes, presented, binding, landed) {
285
305
  if (bytes.length > MAX_ATR_BYTES)
286
306
  return tooLarge();
307
+ const read = landed === null ? undefined : landed;
308
+ if (read !== undefined && (!isObject(read) || !isObject(presented))) {
309
+ return declined("signed-not-bound", "The landed receipt is not a JSON object beside the payment.");
310
+ }
287
311
  const h = await hash(bytes);
288
- const b = await boundOf(steps(binding), presented);
312
+ const b = await boundOf(steps(binding), read === undefined ? presented : held(presented, read));
289
313
  if (isRefusal(b) || !hashEquals(b, h)) {
290
- return declined("signed-not-bound", "The payment does not carry the hash of these bytes.");
314
+ return declined("signed-not-bound", "The pairing does not read the hash of the compared bytes from the payment.");
291
315
  }
292
316
  return { h };
293
317
  }
@@ -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
1
  import { bigintOf, choiceOf, hexOf, isObject, isRefusal, 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
- */
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. */
@@ -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) {
@@ -1,18 +1,31 @@
1
1
  /**
2
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.
3
+ * identifier the x402 client writes, the read held under a payment's own `FETCHED` member, and the JSON forms of
4
+ * values, byte strings and integers.
4
5
  */
5
- import { type Json, type Refusal } from "@integraledger/lcp";
6
+ import { type Json, type Refusal } from "@integraledger/lcp/core";
6
7
  import type { PaymentRequired, PaymentRequirements, X402Offer } from "@integraledger/lcp/x402";
7
8
  import type { Chosen, Inputs, Read } from "../types.js";
8
9
  /** A refusal with `code`, made by the gate. */
9
10
  export declare function refuse(code: string): Refusal;
10
11
  /**
11
- * True for a refusal the protocol package made (its `isRefusal`) or the gate made (`refuse`). A value from a seller,
12
- * a signer or a caller that is shaped `{ refused: true, … }` is neither, so it is never passed on as a refusal.
12
+ * True for a refusal any installed copy of the protocol package made (its `isRefusal`, which reads the package's mark)
13
+ * or the gate made (`refuse`). The mark and membership, not shape, make a value one of them: a value from a seller, a
14
+ * signer or a caller that is shaped `{ refused: true, … }` is never passed on as a refusal.
13
15
  */
14
16
  export declare function isRefusal(v: unknown): v is Refusal;
15
17
  export declare function isObject(v: unknown): v is Record<string, unknown>;
18
+ /**
19
+ * The read held under the payment's own `FETCHED` member (`@integraledger/lcp`'s symbol, which no wire form carries),
20
+ * or undefined. A string-keyed member such as `landed` is never read.
21
+ */
22
+ export declare function fetchedOf(c: unknown): unknown;
23
+ /** The payment with `read` held under its own `FETCHED` member. */
24
+ export declare function held<T extends object>(c: T, read: unknown): T;
25
+ /** The payment without what is held under its own `FETCHED` member: its string-keyed members, as it is sent. */
26
+ export declare function withoutFetched<T extends object>(c: T): T;
27
+ /** A value as JSON, each bigint as its decimal string; undefined when it is undefined or has no JSON form. */
28
+ export declare function jsonSafe(v: unknown): Json | undefined;
16
29
  /**
17
30
  * A CAIP-10 account's namespace, its CAIP-2 network and its address, percent-decoded (CAIP-10's escape). An `eip155`
18
31
  * address is taken as written: the gate's account form for EVM is `^eip155:([0-9]+):(0x[0-9a-fA-F]{40})$`, which has no escape.
@@ -1,8 +1,10 @@
1
1
  /**
2
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.
3
+ * identifier the x402 client writes, the read held under a payment's own `FETCHED` member, and the JSON forms of
4
+ * values, byte strings and integers.
4
5
  */
5
- import { isRefusal as isLcpRefusal } from "@integraledger/lcp";
6
+ import { isRefusal as isLcpRefusal } from "@integraledger/lcp/core";
7
+ import { FETCHED } from "@integraledger/lcp/mpp";
6
8
  const CAIP10 = /^([-a-z0-9]{3,8}):([-_a-zA-Z0-9]{1,32}):([-.%a-zA-Z0-9]{1,128})$/;
7
9
  const PAYMENT_IDENTIFIER = "payment-identifier";
8
10
  const HEX = /^0x(?:[0-9a-fA-F]{2})*$/;
@@ -16,8 +18,9 @@ export function refuse(code) {
16
18
  return r;
17
19
  }
18
20
  /**
19
- * True for a refusal the protocol package made (its `isRefusal`) or the gate made (`refuse`). A value from a seller,
20
- * a signer or a caller that is shaped `{ refused: true, … }` is neither, so it is never passed on as a refusal.
21
+ * True for a refusal any installed copy of the protocol package made (its `isRefusal`, which reads the package's mark)
22
+ * or the gate made (`refuse`). The mark and membership, not shape, make a value one of them: a value from a seller, a
23
+ * signer or a caller that is shaped `{ refused: true, … }` is never passed on as a refusal.
21
24
  */
22
25
  export function isRefusal(v) {
23
26
  return isLcpRefusal(v) || (typeof v === "object" && v !== null && made.has(v));
@@ -25,6 +28,34 @@ export function isRefusal(v) {
25
28
  export function isObject(v) {
26
29
  return typeof v === "object" && v !== null && !Array.isArray(v);
27
30
  }
31
+ /**
32
+ * The read held under the payment's own `FETCHED` member (`@integraledger/lcp`'s symbol, which no wire form carries),
33
+ * or undefined. A string-keyed member such as `landed` is never read.
34
+ */
35
+ export function fetchedOf(c) {
36
+ return isObject(c) && Object.hasOwn(c, FETCHED) ? c[FETCHED] : undefined;
37
+ }
38
+ /** The payment with `read` held under its own `FETCHED` member. */
39
+ export function held(c, read) {
40
+ return { ...c, [FETCHED]: read };
41
+ }
42
+ /** The payment without what is held under its own `FETCHED` member: its string-keyed members, as it is sent. */
43
+ export function withoutFetched(c) {
44
+ const { [FETCHED]: _read, ...sent } = c;
45
+ return sent;
46
+ }
47
+ /** A value as JSON, each bigint as its decimal string; undefined when it is undefined or has no JSON form. */
48
+ export function jsonSafe(v) {
49
+ if (v === undefined)
50
+ return undefined;
51
+ try {
52
+ const text = JSON.stringify(v, (_k, x) => (typeof x === "bigint" ? x.toString() : x));
53
+ return text === undefined ? undefined : JSON.parse(text);
54
+ }
55
+ catch {
56
+ return undefined;
57
+ }
58
+ }
28
59
  /**
29
60
  * A CAIP-10 account's namespace, its CAIP-2 network and its address, percent-decoded (CAIP-10's escape). An `eip155`
30
61
  * address is taken as written: the gate's account form for EVM is `^eip155:([0-9]+):(0x[0-9a-fA-F]{40})$`, which has no escape.
@@ -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, readUrl } 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";
@@ -43,9 +43,15 @@ async function valueHash(bytes) {
43
43
  b.set(bytes, 1);
44
44
  return sha256Hex(b);
45
45
  }
46
- /** An absolute `http` or `https` URL in ASCII syntax, with a host, and no fragment or user information. */
46
+ /**
47
+ * An absolute `http` or `https` URL in ASCII syntax, with a host, and no fragment or user information, that the WHATWG
48
+ * URL Standard's basic URL parser reads, with no base, as lcp's `readUrl` reads it.
49
+ */
47
50
  function isTargetUri(url) {
48
- return typeof url === "string" && ASCII_URI.test(url) && HTTP_TARGET.test(url) && URL.canParse(url);
51
+ if (typeof url !== "string" || !ASCII_URI.test(url) || !HTTP_TARGET.test(url))
52
+ return false;
53
+ const scheme = readUrl(url)?.scheme;
54
+ return scheme === "http" || scheme === "https";
49
55
  }
50
56
  /** Strictly ascending and without duplicates, by UTF-16 code units, which is RFC 8785's member order. */
51
57
  function ascending(names) {
@@ -117,9 +123,12 @@ async function mcpBinding(params, request) {
117
123
  }
118
124
  return { domain: MCP_DOMAIN, server, method: "tools/call", name, arguments: args, metadata: bound };
119
125
  }
120
- /** An absolute URI in ASCII syntax, with no user information and no fragment. */
126
+ /**
127
+ * An absolute URI in ASCII syntax, with no user information and no fragment, that the WHATWG URL Standard's basic URL
128
+ * parser reads, with no base, as lcp's `readUrl` reads it.
129
+ */
121
130
  function isAbsoluteUri(v) {
122
- return typeof v === "string" && ASCII_URI.test(v) && ABSOLUTE_URI.test(v) && !USERINFO.test(v) && URL.canParse(v);
131
+ return typeof v === "string" && ASCII_URI.test(v) && ABSOLUTE_URI.test(v) && !USERINFO.test(v) && readUrl(v) !== null;
123
132
  }
124
133
  /**
125
134
  * The binding object of the buyer's own `request` under a profile and its parameters, the profile being the one the
@@ -3,21 +3,23 @@
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}}`, with its landed read held under
9
+ * the payment's own `FETCHED` member: the network and the body's memo, which `bound` reads. The signer moves the
10
+ * payment, so a decline keeps it.
11
+ * - `credentialType` `transaction` (pull): the signer answers `{publicKey, signature, type}`, and the credential is
12
+ * `{challenge, payload: {type: "transaction", transaction}}`, the signed body in base64.
12
13
  */
13
- import type { AtrHash } from "@integraledger/lcp";
14
+ import type { AtrHash } from "@integraledger/lcp/core";
14
15
  import type { BuyerPiece } from "../types.js";
15
16
  /**
16
- * The binding's build, called with the chosen challenge's id and realm, its decoded request, and the payer's values,
17
- * `credentialType` among them. The body carries no hash of its own: the challenge's id derives from it, and `bound`
18
- * reads it from there.
17
+ * The binding's build, called with the chosen challenge, the payer's values, `credentialType` among them, and H. The
18
+ * binding holds the challenge as `bound` holds an echoed one, with `bound`'s code for each fault, and refuses one whose
19
+ * id does not derive from H with `mpp/id-not-ours`. The body carries no hash of its own: the challenge's id derives
20
+ * from it, and `bound` reads it from there.
19
21
  */
20
- export declare function buildHederaCharge(choice: unknown, _h: AtrHash): Promise<unknown>;
22
+ export declare function buildHederaCharge(choice: unknown, h: AtrHash): Promise<unknown>;
21
23
  export declare const mppChargeHedera: BuyerPiece & {
22
24
  build(choice: unknown, h: AtrHash): Promise<unknown>;
23
25
  };
@@ -1,5 +1,5 @@
1
1
  import { attributionMemo, chargeHedera } from "@integraledger/lcp/mpp";
2
- import { accountOf, bigintOf, broadcasts, bytesOf, choiceOf, inputsOf, isObject, isRefusal, refuse } from "./common.js";
2
+ import { accountOf, bigintOf, broadcasts, bytesOf, choiceOf, held, inputsOf, isObject, isRefusal, refuse, withoutFetched, } from "./common.js";
3
3
  import { requestOf } from "./mpp.js";
4
4
  import { mppRailPiece, railChoose } from "./mpp-rails.js";
5
5
  import { HEDERA_ENTITY } from "./x402-exact-hedera.js";
@@ -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;
@@ -73,7 +73,7 @@ async function complete(unsigned, signature, chosen) {
73
73
  return transactionId;
74
74
  const clientId = typeof c["clientId"] === "string" ? c["clientId"] : undefined;
75
75
  const memo = attributionMemo(String(challenge["realm"]), String(challenge["id"]), clientId);
76
- return { challenge: echoed, payload: { type: "hash", transactionId }, landed: { network: c["network"], memo } };
76
+ return held({ challenge: echoed, payload: { type: "hash", transactionId } }, { network: c["network"], memo });
77
77
  }
78
78
  const a = answer(signature);
79
79
  if (isRefusal(a))
@@ -84,25 +84,26 @@ async function complete(unsigned, signature, chosen) {
84
84
  return { challenge: echoed, payload: { type: "transaction", transaction } };
85
85
  }
86
86
  /**
87
- * The binding's build, called with the chosen challenge's id and realm, its decoded request, and the payer's values,
88
- * `credentialType` among them. The body carries no hash of its own: the challenge's id derives from it, and `bound`
89
- * reads it from there.
87
+ * The binding's build, called with the chosen challenge, the payer's values, `credentialType` among them, and H. The
88
+ * binding holds the challenge as `bound` holds an echoed one, with `bound`'s code for each fault, and refuses one whose
89
+ * id does not derive from H with `mpp/id-not-ours`. The body carries no hash of its own: the challenge's id derives
90
+ * from it, and `bound` reads it from there.
90
91
  */
91
- export async function buildHederaCharge(choice, _h) {
92
+ export async function buildHederaCharge(choice, h) {
92
93
  if (isRefusal(choice))
93
94
  return choice;
94
95
  const c = choice;
95
- const request = requestOf(c.challenge);
96
- if (request === undefined || typeof c.challenge.id !== "string")
96
+ if (requestOf(c.challenge) === undefined || typeof c.challenge.id !== "string")
97
97
  return refuse("mpp/choice-malformed");
98
- return chargeHedera.build({ id: c.challenge.id, realm: c.challenge.realm }, request, {
98
+ return chargeHedera.build({
99
+ challenge: c.challenge,
99
100
  payer: c.payer,
100
101
  node: c.node,
101
102
  validStart: c.validStart,
102
103
  maxFee: c.maxFee,
103
104
  ...(c.clientId !== undefined ? { clientId: c.clientId } : {}),
104
105
  ...(c.credentialType !== undefined ? { credentialType: c.credentialType } : {}),
105
- });
106
+ }, h);
106
107
  }
107
108
  const spec = {
108
109
  pairing: PAIRING,
@@ -117,7 +118,9 @@ const spec = {
117
118
  };
118
119
  const rail = mppRailPiece(spec);
119
120
  const railChosen = railChoose(spec);
120
- /** The choice, with the account's network, which the challenge's network equals, for a push credential's `landed`. */
121
+ /**
122
+ * The choice, with the account's network, which the challenge's network equals, for a push credential's landed read.
123
+ */
121
124
  function choose(...args) {
122
125
  const chosen = railChosen(...args);
123
126
  if (isRefusal(chosen))
@@ -131,7 +134,6 @@ export const mppChargeHedera = Object.freeze({
131
134
  build: buildHederaCharge,
132
135
  moves: broadcasts,
133
136
  sent(signed) {
134
- const { landed: _landed, ...credential } = signed;
135
- return credential;
137
+ return withoutFetched(signed);
136
138
  },
137
139
  });
@@ -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" });
@@ -1,10 +1,15 @@
1
+ /**
2
+ * The buyer piece for `mpp/charge/tempo/push`: the signer broadcasts and answers the hash with its landed receipt, held
3
+ * under the payment's own `FETCHED` member, where `bound` reads it for the memo. The payment sent is the credential
4
+ * without it. The signer moves the payment, so a decline keeps it. The build is the protocol package's: with splits,
5
+ * its `tempo-calls` request holds one call per recipient.
6
+ */
1
7
  import type { Presented } from "../types.js";
2
8
  import { broadcasts } from "./common.js";
3
9
  import { mppChoice, mppRequest, pushComplete } from "./mpp.js";
4
10
  export declare const mppChargeTempoPush: Readonly<{
5
11
  choose: import("../types.js").Choose;
6
12
  choice: typeof mppChoice;
7
- build: (choice: unknown, h: import("../types.js").AtrHash) => Promise<unknown>;
8
13
  request: typeof mppRequest;
9
14
  complete: typeof pushComplete;
10
15
  moves: typeof broadcasts;
@@ -1,21 +1,12 @@
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
- import { broadcasts } from "./common.js";
9
- import { acceptSplits, mppChoice, mppChoose, mppRequest, pushComplete, tempoBuild } from "./mpp.js";
1
+ import { broadcasts, withoutFetched } from "./common.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,
17
9
  sent(signed) {
18
- const { landed: _landed, ...credential } = signed;
19
- return credential;
10
+ return withoutFetched(signed);
20
11
  },
21
12
  });
@@ -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;