@integraledger/terms 0.1.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 (171) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +539 -0
  3. package/dist/agreement.d.ts +23 -0
  4. package/dist/agreement.js +264 -0
  5. package/dist/channels.d.ts +49 -0
  6. package/dist/channels.js +395 -0
  7. package/dist/gate.d.ts +69 -0
  8. package/dist/gate.js +347 -0
  9. package/dist/index.d.ts +5 -0
  10. package/dist/index.js +4 -0
  11. package/dist/pairings/ack-payment-request.d.ts +1 -0
  12. package/dist/pairings/ack-payment-request.js +12 -0
  13. package/dist/pairings/acp-checkout-delegated.d.ts +2 -0
  14. package/dist/pairings/acp-checkout-delegated.js +28 -0
  15. package/dist/pairings/acp-checkout-undelegated.d.ts +1 -0
  16. package/dist/pairings/acp-checkout-undelegated.js +11 -0
  17. package/dist/pairings/ap2-checkout-mandate.d.ts +2 -0
  18. package/dist/pairings/ap2-checkout-mandate.js +23 -0
  19. package/dist/pairings/batch.d.ts +29 -0
  20. package/dist/pairings/batch.js +83 -0
  21. package/dist/pairings/card-mastercard-vi-autonomous.d.ts +1 -0
  22. package/dist/pairings/card-mastercard-vi-autonomous.js +3 -0
  23. package/dist/pairings/card-mastercard-vi-immediate.d.ts +1 -0
  24. package/dist/pairings/card-mastercard-vi-immediate.js +3 -0
  25. package/dist/pairings/card-seller-reference.d.ts +1 -0
  26. package/dist/pairings/card-seller-reference.js +3 -0
  27. package/dist/pairings/card-visa-tap.d.ts +1 -0
  28. package/dist/pairings/card-visa-tap.js +3 -0
  29. package/dist/pairings/card.d.ts +7 -0
  30. package/dist/pairings/card.js +68 -0
  31. package/dist/pairings/common.d.ts +54 -0
  32. package/dist/pairings/common.js +134 -0
  33. package/dist/pairings/evm-x402.d.ts +3 -0
  34. package/dist/pairings/evm-x402.js +49 -0
  35. package/dist/pairings/index.d.ts +3 -0
  36. package/dist/pairings/index.js +134 -0
  37. package/dist/pairings/lightning.d.ts +17 -0
  38. package/dist/pairings/lightning.js +112 -0
  39. package/dist/pairings/lnbtc-request.d.ts +24 -0
  40. package/dist/pairings/lnbtc-request.js +175 -0
  41. package/dist/pairings/mpp-charge-card.d.ts +1 -0
  42. package/dist/pairings/mpp-charge-card.js +3 -0
  43. package/dist/pairings/mpp-charge-evm-authorization.d.ts +1 -0
  44. package/dist/pairings/mpp-charge-evm-authorization.js +3 -0
  45. package/dist/pairings/mpp-charge-evm-hash.d.ts +1 -0
  46. package/dist/pairings/mpp-charge-evm-hash.js +3 -0
  47. package/dist/pairings/mpp-charge-evm-permit2.d.ts +1 -0
  48. package/dist/pairings/mpp-charge-evm-permit2.js +3 -0
  49. package/dist/pairings/mpp-charge-evm-transaction.d.ts +1 -0
  50. package/dist/pairings/mpp-charge-evm-transaction.js +3 -0
  51. package/dist/pairings/mpp-charge-hedera.d.ts +23 -0
  52. package/dist/pairings/mpp-charge-hedera.js +137 -0
  53. package/dist/pairings/mpp-charge-nearintents.d.ts +2 -0
  54. package/dist/pairings/mpp-charge-nearintents.js +19 -0
  55. package/dist/pairings/mpp-charge-solana.d.ts +1 -0
  56. package/dist/pairings/mpp-charge-solana.js +25 -0
  57. package/dist/pairings/mpp-charge-stellar.d.ts +1 -0
  58. package/dist/pairings/mpp-charge-stellar.js +16 -0
  59. package/dist/pairings/mpp-charge-stripe.d.ts +1 -0
  60. package/dist/pairings/mpp-charge-stripe.js +3 -0
  61. package/dist/pairings/mpp-charge-tempo-memo.d.ts +9 -0
  62. package/dist/pairings/mpp-charge-tempo-memo.js +10 -0
  63. package/dist/pairings/mpp-charge-tempo-push.d.ts +12 -0
  64. package/dist/pairings/mpp-charge-tempo-push.js +21 -0
  65. package/dist/pairings/mpp-charge-usdc-evm.d.ts +1 -0
  66. package/dist/pairings/mpp-charge-usdc-evm.js +6 -0
  67. package/dist/pairings/mpp-charge-usdc-gateway.d.ts +2 -0
  68. package/dist/pairings/mpp-charge-usdc-gateway.js +33 -0
  69. package/dist/pairings/mpp-charge-usdc-solana.d.ts +1 -0
  70. package/dist/pairings/mpp-charge-usdc-solana.js +25 -0
  71. package/dist/pairings/mpp-charge-usdc-stacks.d.ts +1 -0
  72. package/dist/pairings/mpp-charge-usdc-stacks.js +17 -0
  73. package/dist/pairings/mpp-charge-xrpl.d.ts +1 -0
  74. package/dist/pairings/mpp-charge-xrpl.js +20 -0
  75. package/dist/pairings/mpp-confirm-only.d.ts +2 -0
  76. package/dist/pairings/mpp-confirm-only.js +21 -0
  77. package/dist/pairings/mpp-rails.d.ts +48 -0
  78. package/dist/pairings/mpp-rails.js +71 -0
  79. package/dist/pairings/mpp-session-evm.d.ts +1 -0
  80. package/dist/pairings/mpp-session-evm.js +3 -0
  81. package/dist/pairings/mpp-session-hedera.d.ts +2 -0
  82. package/dist/pairings/mpp-session-hedera.js +41 -0
  83. package/dist/pairings/mpp-session-solana.d.ts +1 -0
  84. package/dist/pairings/mpp-session-solana.js +60 -0
  85. package/dist/pairings/mpp-session-tempo.d.ts +1 -0
  86. package/dist/pairings/mpp-session-tempo.js +3 -0
  87. package/dist/pairings/mpp-session-xrpl.d.ts +1 -0
  88. package/dist/pairings/mpp-session-xrpl.js +42 -0
  89. package/dist/pairings/mpp-session.d.ts +5 -0
  90. package/dist/pairings/mpp-session.js +65 -0
  91. package/dist/pairings/mpp-subscription-stripe.d.ts +1 -0
  92. package/dist/pairings/mpp-subscription-stripe.js +6 -0
  93. package/dist/pairings/mpp-subscription-tempo.d.ts +2 -0
  94. package/dist/pairings/mpp-subscription-tempo.js +2 -0
  95. package/dist/pairings/mpp.d.ts +43 -0
  96. package/dist/pairings/mpp.js +194 -0
  97. package/dist/pairings/protocol-groups.d.ts +17 -0
  98. package/dist/pairings/protocol-groups.js +27 -0
  99. package/dist/pairings/ucp-booking-ap2-mandate.d.ts +1 -0
  100. package/dist/pairings/ucp-booking-ap2-mandate.js +3 -0
  101. package/dist/pairings/ucp-booking-unsigned.d.ts +1 -0
  102. package/dist/pairings/ucp-booking-unsigned.js +3 -0
  103. package/dist/pairings/ucp-checkout-ap2-mandate.d.ts +1 -0
  104. package/dist/pairings/ucp-checkout-ap2-mandate.js +3 -0
  105. package/dist/pairings/ucp-checkout-unsigned.d.ts +1 -0
  106. package/dist/pairings/ucp-checkout-unsigned.js +3 -0
  107. package/dist/pairings/ucp.d.ts +5 -0
  108. package/dist/pairings/ucp.js +35 -0
  109. package/dist/pairings/x402-account-rails.d.ts +25 -0
  110. package/dist/pairings/x402-account-rails.js +52 -0
  111. package/dist/pairings/x402-auth-capture-eip155-eip3009.d.ts +1 -0
  112. package/dist/pairings/x402-auth-capture-eip155-eip3009.js +3 -0
  113. package/dist/pairings/x402-auth-capture-eip155-permit2.d.ts +1 -0
  114. package/dist/pairings/x402-auth-capture-eip155-permit2.js +3 -0
  115. package/dist/pairings/x402-batch-settlement-cloudflare.d.ts +2 -0
  116. package/dist/pairings/x402-batch-settlement-cloudflare.js +21 -0
  117. package/dist/pairings/x402-batch-settlement-eip155.d.ts +2 -0
  118. package/dist/pairings/x402-batch-settlement-eip155.js +32 -0
  119. package/dist/pairings/x402-batch-settlement-solana.d.ts +2 -0
  120. package/dist/pairings/x402-batch-settlement-solana.js +55 -0
  121. package/dist/pairings/x402-exact-algorand.d.ts +1 -0
  122. package/dist/pairings/x402-exact-algorand.js +37 -0
  123. package/dist/pairings/x402-exact-aptos.d.ts +1 -0
  124. package/dist/pairings/x402-exact-aptos.js +9 -0
  125. package/dist/pairings/x402-exact-cardano.d.ts +1 -0
  126. package/dist/pairings/x402-exact-cardano.js +7 -0
  127. package/dist/pairings/x402-exact-casper.d.ts +2 -0
  128. package/dist/pairings/x402-exact-casper.js +21 -0
  129. package/dist/pairings/x402-exact-ccd.d.ts +2 -0
  130. package/dist/pairings/x402-exact-ccd.js +20 -0
  131. package/dist/pairings/x402-exact-eip155-eip3009.d.ts +1 -0
  132. package/dist/pairings/x402-exact-eip155-eip3009.js +3 -0
  133. package/dist/pairings/x402-exact-eip155-erc7710-salt.d.ts +1 -0
  134. package/dist/pairings/x402-exact-eip155-erc7710-salt.js +3 -0
  135. package/dist/pairings/x402-exact-eip155-erc7710.d.ts +1 -0
  136. package/dist/pairings/x402-exact-eip155-erc7710.js +3 -0
  137. package/dist/pairings/x402-exact-eip155-permit2.d.ts +1 -0
  138. package/dist/pairings/x402-exact-eip155-permit2.js +3 -0
  139. package/dist/pairings/x402-exact-hedera-transfer-executor.d.ts +1 -0
  140. package/dist/pairings/x402-exact-hedera-transfer-executor.js +23 -0
  141. package/dist/pairings/x402-exact-hedera.d.ts +3 -0
  142. package/dist/pairings/x402-exact-hedera.js +46 -0
  143. package/dist/pairings/x402-exact-near.d.ts +2 -0
  144. package/dist/pairings/x402-exact-near.js +34 -0
  145. package/dist/pairings/x402-exact-polkadot-lcp-assets-remark.d.ts +2 -0
  146. package/dist/pairings/x402-exact-polkadot-lcp-assets-remark.js +20 -0
  147. package/dist/pairings/x402-exact-solana.d.ts +11 -0
  148. package/dist/pairings/x402-exact-solana.js +36 -0
  149. package/dist/pairings/x402-exact-starknet.d.ts +2 -0
  150. package/dist/pairings/x402-exact-starknet.js +20 -0
  151. package/dist/pairings/x402-exact-stellar.d.ts +1 -0
  152. package/dist/pairings/x402-exact-stellar.js +17 -0
  153. package/dist/pairings/x402-exact-sui.d.ts +1 -0
  154. package/dist/pairings/x402-exact-sui.js +10 -0
  155. package/dist/pairings/x402-exact-tron-lcp-trc20-memo.d.ts +2 -0
  156. package/dist/pairings/x402-exact-tron-lcp-trc20-memo.js +45 -0
  157. package/dist/pairings/x402-exact-tvm.d.ts +2 -0
  158. package/dist/pairings/x402-exact-tvm.js +35 -0
  159. package/dist/pairings/x402-exact-xrpl.d.ts +1 -0
  160. package/dist/pairings/x402-exact-xrpl.js +27 -0
  161. package/dist/pairings/x402-rail.d.ts +31 -0
  162. package/dist/pairings/x402-rail.js +65 -0
  163. package/dist/pairings/x402-upto-eip155-permit2.d.ts +1 -0
  164. package/dist/pairings/x402-upto-eip155-permit2.js +3 -0
  165. package/dist/pairings/x402-upto-solana.d.ts +1 -0
  166. package/dist/pairings/x402-upto-solana.js +42 -0
  167. package/dist/transact.d.ts +20 -0
  168. package/dist/transact.js +53 -0
  169. package/dist/types.d.ts +169 -0
  170. package/dist/types.js +2 -0
  171. package/package.json +64 -0
@@ -0,0 +1,20 @@
1
+ import { inputsOf, refuse } from "./common.js";
2
+ import { completeWith, hexDigits, mppRailPiece, XRPL_ADDRESS } from "./mpp-rails.js";
3
+ const PAIRING = "mpp/charge/xrpl";
4
+ function inputs(_request, given) {
5
+ return inputsOf(given, PAIRING, { fee: "decimal", sequence: "uint", lastLedgerSequence: "uint" });
6
+ }
7
+ /** The signed blob's hex digits, from `0x` hex. */
8
+ function blob(signature) {
9
+ return hexDigits(signature) ?? refuse("mpp/credential-malformed");
10
+ }
11
+ export const mppChargeXrpl = mppRailPiece({
12
+ pairing: PAIRING,
13
+ namespace: "xrpl",
14
+ address: XRPL_ADDRESS,
15
+ payer: "account",
16
+ now: false,
17
+ inputs,
18
+ revive: (c) => c,
19
+ complete: completeWith(blob),
20
+ });
@@ -0,0 +1,2 @@
1
+ import type { BuyerPiece } from "../types.js";
2
+ export declare function mppConfirmOnlyPiece(pairing: string): BuyerPiece;
@@ -0,0 +1,21 @@
1
+ import { isObject, refuse } from "./common.js";
2
+ import { offers } from "./mpp.js";
3
+ const nothingToSign = () => refuse("mpp/nothing-to-sign");
4
+ export function mppConfirmOnlyPiece(pairing) {
5
+ return Object.freeze({
6
+ choose(read, _account, _inputs, now, ref) {
7
+ const offer = read.offer;
8
+ const challenges = isObject(offer) && Array.isArray(offer["challenges"]) ? offer["challenges"] : [];
9
+ const challenge = challenges.find((c) => offers(c, pairing));
10
+ if (challenge === undefined)
11
+ return refuse("mpp/no-payable-option");
12
+ return { pairing, choice: { challenge: challenge, now }, ref };
13
+ },
14
+ choice(chosen) {
15
+ const c = isObject(chosen) && isObject(chosen.choice) ? chosen.choice : undefined;
16
+ return c === undefined || !isObject(c["challenge"]) ? refuse("mpp/choice-malformed") : c;
17
+ },
18
+ request: () => nothingToSign(),
19
+ complete: async () => nothingToSign(),
20
+ });
21
+ }
@@ -0,0 +1,48 @@
1
+ /**
2
+ * The buyer pieces shared by MPP's charges and sessions on Hedera, Solana, Stellar, XRPL and NEAR Intents: the first
3
+ * challenge, in document order, that offers the pairing on the account's CAIP-2 network, as MPP's `network` reads it;
4
+ * the buyer's own inputs beside it as JSON; the build's request exactly as built; and the credential the signer's
5
+ * answer completes.
6
+ */
7
+ import type { Json, Refusal } from "@integraledger/lcp";
8
+ import { type MppChallenge } from "@integraledger/lcp/mpp";
9
+ import type { BuyerPiece, Choose, Chosen, Inputs, Next, Presented, Signature, SigningRequest } from "../types.js";
10
+ export declare const HEDERA_EVM_ADDRESS: RegExp;
11
+ export declare const XRPL_ADDRESS: RegExp;
12
+ export declare const STELLAR_ACCOUNT: RegExp;
13
+ /** One MPP rail pairing's buyer piece, described by what differs between pairings. */
14
+ export interface MppRail {
15
+ pairing: string;
16
+ /** The account's CAIP-2 namespace, or null where the challenge's network alone decides. */
17
+ namespace: string | null;
18
+ /** The form of the account's address. */
19
+ address: RegExp;
20
+ /** The choice field the account's address fills, or null when the build takes none. */
21
+ payer: string | null;
22
+ /** True when the build takes `now`. */
23
+ now: boolean;
24
+ /** The buyer's own values the build takes beside the challenge, as JSON, or the refusal naming the first missing. */
25
+ inputs(request: Record<string, unknown>, given: Inputs): Record<string, Json> | Refusal;
26
+ /** The choice as the build takes it: integers as bigints where the build names bigints. */
27
+ revive(choice: Record<string, unknown>): unknown;
28
+ /** The request handed to the signer. */
29
+ request?(unsigned: unknown): SigningRequest | Refusal;
30
+ /** The challenge's network where the account's own network is the configured one, in place of MPP's `network`. */
31
+ network?(challenge: MppChallenge, accountNetwork: string): string | Refusal;
32
+ /** The credential the signer's answer completes, or the next request of an opening signed in steps. */
33
+ complete(unsigned: unknown, signature: Signature, chosen: Chosen): Promise<Presented | Next | Refusal>;
34
+ }
35
+ /** The first challenge offering the pairing on the account's network, with the choice the build takes. */
36
+ export declare function railChoose(rail: MppRail): Choose;
37
+ /** The build's request, exactly as built. */
38
+ export declare function builtRequest(unsigned: unknown): SigningRequest | Refusal;
39
+ /** The buyer piece for one MPP rail pairing. */
40
+ export declare function mppRailPiece(rail: MppRail): BuyerPiece;
41
+ /** A 64-byte signature given as `0x` hex, as bytes. */
42
+ export declare function signature64(signature: Signature): Uint8Array | Refusal;
43
+ /** Hex digits of a `0x` hex answer, without the prefix. */
44
+ export declare function hexDigits(v: unknown): string | undefined;
45
+ /** The credential of a build whose `complete` takes the signer's answer as given, converted by `answer`. */
46
+ export declare function completeWith(answer: (s: Signature) => unknown): MppRail["complete"];
47
+ /** A session opening's choice as the build takes it, with `deposit` as a bigint where the choice carries one. */
48
+ export declare function sessionRevive(c: Record<string, unknown>): unknown;
@@ -0,0 +1,71 @@
1
+ import { network } from "@integraledger/lcp/mpp";
2
+ import { accountOf, bytesOf, isObject, isRefusal, refuse } from "./common.js";
3
+ import { mppChoice, offers, requestOf } from "./mpp.js";
4
+ export const HEDERA_EVM_ADDRESS = /^0x[0-9a-fA-F]{40}$/;
5
+ export const XRPL_ADDRESS = /^r[1-9A-HJ-NP-Za-km-z]{24,34}$/;
6
+ export const STELLAR_ACCOUNT = /^G[A-Z2-7]{55}$/;
7
+ /** The first challenge offering the pairing on the account's network, with the choice the build takes. */
8
+ export function railChoose(rail) {
9
+ return (read, account, inputs, now, ref) => {
10
+ const a = accountOf(account);
11
+ if (a === undefined || (rail.namespace !== null && a.namespace !== rail.namespace) || !rail.address.test(a.address)) {
12
+ return refuse("mpp/no-payable-option");
13
+ }
14
+ const offer = read.offer;
15
+ const challenges = isObject(offer) && Array.isArray(offer["challenges"]) ? offer["challenges"] : [];
16
+ const networkOf = rail.network ?? ((c) => network(c));
17
+ const challenge = challenges.find((c) => offers(c, rail.pairing) && networkOf(c, a.network) === a.network);
18
+ if (challenge === undefined)
19
+ return refuse("mpp/no-payable-option");
20
+ const given = rail.inputs(requestOf(challenge) ?? {}, inputs);
21
+ if (isRefusal(given))
22
+ return given;
23
+ const choice = {
24
+ challenge: challenge,
25
+ ...(rail.payer !== null ? { [rail.payer]: a.address } : {}),
26
+ ...(rail.now ? { now } : {}),
27
+ ...given,
28
+ };
29
+ return { pairing: rail.pairing, choice, ref };
30
+ };
31
+ }
32
+ /** The build's request, exactly as built. */
33
+ export function builtRequest(unsigned) {
34
+ const u = unsigned;
35
+ return isObject(u) && isObject(u.request) ? u.request : refuse("mpp/request-malformed");
36
+ }
37
+ /** The buyer piece for one MPP rail pairing. */
38
+ export function mppRailPiece(rail) {
39
+ return Object.freeze({
40
+ choose: railChoose(rail),
41
+ choice(chosen) {
42
+ const c = isObject(chosen) && isObject(chosen.choice) ? chosen.choice : undefined;
43
+ if (c === undefined || !isObject(c["challenge"]))
44
+ return refuse("mpp/choice-malformed");
45
+ return rail.revive(c);
46
+ },
47
+ request: rail.request ?? builtRequest,
48
+ complete: rail.complete,
49
+ });
50
+ }
51
+ /** A 64-byte signature given as `0x` hex, as bytes. */
52
+ export function signature64(signature) {
53
+ return bytesOf(signature, 64) ?? refuse("mpp/credential-malformed");
54
+ }
55
+ /** Hex digits of a `0x` hex answer, without the prefix. */
56
+ export function hexDigits(v) {
57
+ return typeof v === "string" && bytesOf(v) !== undefined && v.length > 2 ? v.slice(2) : undefined;
58
+ }
59
+ /** The credential of a build whose `complete` takes the signer's answer as given, converted by `answer`. */
60
+ export function completeWith(answer) {
61
+ return async (unsigned, signature) => {
62
+ const a = answer(signature);
63
+ if (isRefusal(a))
64
+ return a;
65
+ return (await unsigned.complete(a));
66
+ };
67
+ }
68
+ /** A session opening's choice as the build takes it, with `deposit` as a bigint where the choice carries one. */
69
+ export function sessionRevive(c) {
70
+ return mppChoice({ pairing: "", choice: c, ref: "" });
71
+ }
@@ -0,0 +1 @@
1
+ export declare const mppSessionEvm: import("../types.js").BuyerPiece;
@@ -0,0 +1,3 @@
1
+ /** The buyer piece for `mpp/session/evm`: the funding, then the first voucher. */
2
+ import { mppSessionPiece } from "./mpp-session.js";
3
+ export const mppSessionEvm = mppSessionPiece("mpp/session/evm");
@@ -0,0 +1,2 @@
1
+ import type { BuyerPiece } from "../types.js";
2
+ export declare const mppSessionHedera: BuyerPiece;
@@ -0,0 +1,41 @@
1
+ import { bigintOf, inputsOf, isObject, isRefusal, refuse } from "./common.js";
2
+ import { HEDERA_EVM_ADDRESS, mppRailPiece, sessionRevive } from "./mpp-rails.js";
3
+ const PAIRING = "mpp/session/hedera";
4
+ async function complete(unsigned, signature, _chosen) {
5
+ if (!isObject(signature) || typeof signature["openTx"] !== "string" || typeof signature["signature"] !== "string") {
6
+ return refuse("mpp/credential-malformed");
7
+ }
8
+ const credential = unsigned.complete({
9
+ openTx: signature["openTx"],
10
+ signature: signature["signature"],
11
+ });
12
+ if (isRefusal(credential))
13
+ return credential;
14
+ const landed = signature["landed"];
15
+ if (landed === undefined)
16
+ return credential;
17
+ if (!isObject(landed) || typeof landed["transaction"] !== "string" || !Array.isArray(landed["logs"])) {
18
+ return refuse("mpp/credential-malformed");
19
+ }
20
+ const blockNumber = bigintOf(landed["blockNumber"]);
21
+ if (blockNumber === undefined)
22
+ return refuse("mpp/credential-malformed");
23
+ return { ...credential, landed: { transaction: landed["transaction"], blockNumber, logs: landed["logs"] } };
24
+ }
25
+ export const mppSessionHedera = Object.freeze({
26
+ ...mppRailPiece({
27
+ pairing: PAIRING,
28
+ namespace: "hedera",
29
+ address: HEDERA_EVM_ADDRESS,
30
+ payer: "from",
31
+ now: true,
32
+ inputs: (_request, given) => inputsOf(given, PAIRING, { deposit: "decimal" }),
33
+ revive: sessionRevive,
34
+ complete,
35
+ }),
36
+ moves: () => true,
37
+ sent(signed) {
38
+ const { landed: _landed, ...credential } = signed;
39
+ return credential;
40
+ },
41
+ });
@@ -0,0 +1 @@
1
+ export declare const mppSessionSolana: import("../types.js").BuyerPiece;
@@ -0,0 +1,60 @@
1
+ import { sessionProof } from "@integraledger/lcp/svm";
2
+ import { choiceOf, inputsOf, isObject, refuse } from "./common.js";
3
+ import { requestOf } from "./mpp.js";
4
+ import { completeWith, mppRailPiece, sessionRevive } from "./mpp-rails.js";
5
+ import { SOLANA_ADDRESS } from "./x402-exact-solana.js";
6
+ const PAIRING = "mpp/session/solana";
7
+ /** Base58 of a 64-byte Ed25519 signature. */
8
+ const SIGNATURE_BASE58 = /^[1-9A-HJ-NP-Za-km-z]{64,88}$/;
9
+ const completeOpen = completeWith((s) => (isObject(s) ? s : refuse("mpp/credential-malformed")));
10
+ /** The challenge and payer of the choice, when its challenge asks for the operator mode's session proof. */
11
+ function operatorMode(chosen) {
12
+ const c = choiceOf(chosen);
13
+ const challenge = c?.["challenge"];
14
+ if (!isObject(challenge))
15
+ return refuse("mpp/choice-malformed");
16
+ const details = requestOf(challenge)?.["methodDetails"];
17
+ if (!isObject(details) || details["voucherSigner"] !== "operator")
18
+ return null;
19
+ const payer = c?.["from"];
20
+ if (typeof challenge.id !== "string" || typeof payer !== "string")
21
+ return refuse("mpp/choice-malformed");
22
+ return { challenge: challenge, payer };
23
+ }
24
+ /**
25
+ * The open payload alone completes the credential, unless the challenge asks for the operator mode's session proof:
26
+ * then the open payload asks for the proof's signature next, and `[open, proofSignature]` completes the credential
27
+ * with `authentication` = `{type: "proof", challengeId, payer, signature}`.
28
+ */
29
+ async function complete(unsigned, signature, chosen) {
30
+ const mode = operatorMode(chosen);
31
+ if (mode === null)
32
+ return completeOpen(unsigned, signature, chosen);
33
+ if ("refused" in mode)
34
+ return mode;
35
+ if (isObject(signature)) {
36
+ const channelId = signature["channelId"];
37
+ if (typeof channelId !== "string" || !SOLANA_ADDRESS.test(channelId))
38
+ return refuse("mpp/credential-malformed");
39
+ const message = sessionProof({ channelId, payer: mode.payer, challengeId: mode.challenge.id });
40
+ return { next: { kind: "ed25519-raw", message, signer: mode.payer } };
41
+ }
42
+ if (!Array.isArray(signature) || signature.length !== 2)
43
+ return refuse("mpp/credential-malformed");
44
+ const [open, proof] = signature;
45
+ if (!isObject(open) || typeof proof !== "string" || !SIGNATURE_BASE58.test(proof)) {
46
+ return refuse("mpp/credential-malformed");
47
+ }
48
+ const authentication = { type: "proof", challengeId: mode.challenge.id, payer: mode.payer, signature: proof };
49
+ return completeOpen(unsigned, { ...open, authentication }, chosen);
50
+ }
51
+ export const mppSessionSolana = mppRailPiece({
52
+ pairing: PAIRING,
53
+ namespace: "solana",
54
+ address: SOLANA_ADDRESS,
55
+ payer: "from",
56
+ now: true,
57
+ inputs: (_request, given) => inputsOf(given, PAIRING, { deposit: "optional-decimal" }),
58
+ revive: sessionRevive,
59
+ complete,
60
+ });
@@ -0,0 +1 @@
1
+ export declare const mppSessionTempo: import("../types.js").BuyerPiece;
@@ -0,0 +1,3 @@
1
+ /** The buyer piece for `mpp/session/tempo`: the signed Tempo open transaction, then the first voucher. */
2
+ import { mppSessionPiece } from "./mpp-session.js";
3
+ export const mppSessionTempo = mppSessionPiece("mpp/session/tempo");
@@ -0,0 +1 @@
1
+ export declare const mppSessionXrpl: import("../types.js").BuyerPiece;
@@ -0,0 +1,42 @@
1
+ import { inputsOf, isObject, isRefusal, refuse } from "./common.js";
2
+ import { completeWith, hexDigits, mppRailPiece, sessionRevive, XRPL_ADDRESS } from "./mpp-rails.js";
3
+ const PAIRING = "mpp/session/xrpl";
4
+ function inputs(_request, given) {
5
+ const read = inputsOf(given, PAIRING, { deposit: "decimal", xrpl: "object" });
6
+ if (isRefusal(read))
7
+ return read;
8
+ const x = inputsOf(read["xrpl"], PAIRING, {
9
+ publicKey: "hex",
10
+ settleDelay: "uint",
11
+ fee: "decimal",
12
+ sequence: "uint",
13
+ lastLedgerSequence: "uint",
14
+ cancelAfter: "optional-uint",
15
+ });
16
+ if (isRefusal(x))
17
+ return x;
18
+ const publicKey = hexDigits(x["publicKey"]);
19
+ if (publicKey === undefined)
20
+ return refuse("mpp/input-missing");
21
+ return { ...read, xrpl: { ...x, publicKey } };
22
+ }
23
+ /** `{signedBlob, claimSignature}` as the build's hex digits, from `0x` hex. */
24
+ function answer(signature) {
25
+ if (!isObject(signature))
26
+ return refuse("mpp/credential-malformed");
27
+ const signedBlob = hexDigits(signature["signedBlob"]);
28
+ const claimSignature = hexDigits(signature["claimSignature"]);
29
+ if (signedBlob === undefined || claimSignature === undefined)
30
+ return refuse("mpp/credential-malformed");
31
+ return { signedBlob, claimSignature };
32
+ }
33
+ export const mppSessionXrpl = mppRailPiece({
34
+ pairing: PAIRING,
35
+ namespace: "xrpl",
36
+ address: XRPL_ADDRESS,
37
+ payer: "from",
38
+ now: true,
39
+ inputs,
40
+ revive: sessionRevive,
41
+ complete: completeWith(answer),
42
+ });
@@ -0,0 +1,5 @@
1
+ import type { BuyerPiece } from "../types.js";
2
+ /** A buyer piece for an MPP session pairing. */
3
+ export declare function mppSessionPiece(pairing: string): BuyerPiece;
4
+ /** The buyer piece for `mpp/subscription/tempo`: the root key signs the key authorization's digest. */
5
+ export declare const mppSubscriptionPiece: BuyerPiece;
@@ -0,0 +1,65 @@
1
+ import { optionalInputs } from "./batch.js";
2
+ import { broadcasts, isRefusal, refuse } from "./common.js";
3
+ import { mppChoice, mppChoose, mppComplete, mppRequest } from "./mpp.js";
4
+ const EVM_ADDRESS = /^0x[0-9a-fA-F]{40}$/;
5
+ const CREDENTIAL_TYPE = /^(authorization|permit2|hash)$/;
6
+ /**
7
+ * The first challenge offering `pairing` on the account's chain, with `deposit` and the optional `authorizedSigner`,
8
+ * `credentialType` and `tokenDomain` inputs.
9
+ */
10
+ function sessionChoose(pairing) {
11
+ const choose = mppChoose(pairing, { deposit: "decimal" });
12
+ return (read, account, inputs, now, ref, doc) => {
13
+ const chosen = choose(read, account, inputs, now, ref, doc);
14
+ if (isRefusal(chosen))
15
+ return chosen;
16
+ const given = optionalInputs(inputs, "mpp", {
17
+ authorizedSigner: EVM_ADDRESS,
18
+ credentialType: CREDENTIAL_TYPE,
19
+ tokenDomain: "object",
20
+ });
21
+ if (isRefusal(given))
22
+ return given;
23
+ return { ...chosen, choice: { ...chosen.choice, ...given } };
24
+ };
25
+ }
26
+ /** The funding request, exactly as built. */
27
+ function fundingRequest(unsigned) {
28
+ return unsigned.funding;
29
+ }
30
+ /**
31
+ * With the funding answer alone, the next request: the voucher over the channel the funding opens. With the list
32
+ * `[funded, voucherSignature]`, the credential.
33
+ */
34
+ async function sessionComplete(unsigned, signature) {
35
+ const u = unsigned;
36
+ if (typeof signature === "string") {
37
+ const voucher = u.voucher(signature);
38
+ if ("refused" in voucher)
39
+ return voucher;
40
+ return { next: { kind: "eip712", typedData: voucher } };
41
+ }
42
+ if (!Array.isArray(signature) || signature.length !== 2)
43
+ return refuse("mpp/credential-malformed");
44
+ const [funded, voucherSignature] = signature;
45
+ if (typeof funded !== "string" || typeof voucherSignature !== "string")
46
+ return refuse("mpp/credential-malformed");
47
+ return u.complete(funded, voucherSignature);
48
+ }
49
+ /** A buyer piece for an MPP session pairing. */
50
+ export function mppSessionPiece(pairing) {
51
+ return Object.freeze({
52
+ choose: sessionChoose(pairing),
53
+ choice: mppChoice,
54
+ request: fundingRequest,
55
+ complete: sessionComplete,
56
+ moves: broadcasts,
57
+ });
58
+ }
59
+ /** The buyer piece for `mpp/subscription/tempo`: the root key signs the key authorization's digest. */
60
+ export const mppSubscriptionPiece = Object.freeze({
61
+ choose: mppChoose("mpp/subscription/tempo", {}),
62
+ choice: mppChoice,
63
+ request: mppRequest,
64
+ complete: mppComplete,
65
+ });
@@ -0,0 +1 @@
1
+ export declare const mppSubscriptionStripe: import("../types.js").BuyerPiece;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * The buyer piece for `mpp/subscription/stripe`: nothing the buyer's Stripe payment method signs carries the hash; the
3
+ * gate confirms only.
4
+ */
5
+ import { mppConfirmOnlyPiece } from "./mpp-confirm-only.js";
6
+ export const mppSubscriptionStripe = mppConfirmOnlyPiece("mpp/subscription/stripe");
@@ -0,0 +1,2 @@
1
+ /** The buyer piece for `mpp/subscription/tempo`: the root key signs the key authorization's digest. */
2
+ export { mppSubscriptionPiece as mppSubscriptionTempo } from "./mpp-session.js";
@@ -0,0 +1,2 @@
1
+ /** The buyer piece for `mpp/subscription/tempo`: the root key signs the key authorization's digest. */
2
+ export { mppSubscriptionPiece as mppSubscriptionTempo } from "./mpp-session.js";
@@ -0,0 +1,43 @@
1
+ /**
2
+ * The buyer pieces shared by MPP's pairings: the first challenge, in document order, that offers the pairing on the
3
+ * signer's chain; the build's request exactly as built; and the credential the signer's answer completes.
4
+ */
5
+ import type { AtrHash, Refusal } from "@integraledger/lcp";
6
+ import { type MppChallenge, type MppUnsigned } from "@integraledger/lcp/mpp";
7
+ import type { BuyerPiece, Choose, Chosen, Presented, Signature, SigningRequest } from "../types.js";
8
+ import { inputsOf } from "./common.js";
9
+ type Spec = Parameters<typeof inputsOf>[2];
10
+ /** The request a challenge carries, decoded from base64url JSON, or undefined. */
11
+ export declare function requestOf(c: MppChallenge): Record<string, unknown> | undefined;
12
+ /** Whether a placed challenge offers the pairing, by the protocol package's `pairingsOfPlaced`. */
13
+ export declare function offers(c: MppChallenge, pairing: string): boolean;
14
+ /**
15
+ * The first challenge offering `pairing` on the account's EVM network, as MPP's `network` reads it, with the choice
16
+ * MPP's build takes: the challenge, `from`, `now`, and the buyer's own inputs named in `spec`.
17
+ */
18
+ export declare function mppChoose(pairing: string, spec: Spec, accept?: (c: MppChallenge) => Refusal | null): Choose;
19
+ /** The choice as MPP's build takes it, with `deposit` as a bigint where the choice carries one. */
20
+ export declare function mppChoice(chosen: Chosen): unknown;
21
+ /** The build's request, exactly as built. */
22
+ export declare function mppRequest(unsigned: unknown): SigningRequest | Refusal;
23
+ /** The credential for a one-value answer: a signature, a signed transaction or a transaction hash, as `0x` hex. */
24
+ export declare function mppComplete(unsigned: unknown, signature: Signature): Promise<Presented | Refusal>;
25
+ /** A buyer piece for an MPP charge pairing whose answer is one value. */
26
+ export declare function mppChargePiece(pairing: string, spec: Spec, accept?: (c: MppChallenge) => Refusal | null): BuyerPiece;
27
+ /** Accepts a Tempo challenge whose splits are well formed and leave the primary recipient more than zero. */
28
+ export declare function acceptSplits(c: MppChallenge): Refusal | null;
29
+ type TempoBinding = {
30
+ build(choice: never, h: AtrHash): Promise<MppUnsigned | Refusal>;
31
+ };
32
+ /**
33
+ * A Tempo charge's build. Without splits it is the binding's own `tempo-call`. With splits it is `tempo-calls`: the
34
+ * binding's primary call, carrying its attribution memo, for `amount` less the splits, then one call per split in
35
+ * array order, `transferWithMemo` where the split names a memo and `transfer` otherwise, all on `currency`.
36
+ */
37
+ export declare function tempoBuild(binding: TempoBinding): NonNullable<BuyerPiece["build"]>;
38
+ /**
39
+ * The credential for a pushed Tempo transfer: the answer is `{hash, landed?: {transaction, blockNumber, logs}}`, the
40
+ * hash the signer broadcast and, where the signer gives it, its landed receipt, which carries the memo `bound` reads.
41
+ */
42
+ export declare function pushComplete(unsigned: unknown, signature: Signature): Promise<Presented | Refusal>;
43
+ export {};