@integraledger/profile-facilitator 0.4.0 → 0.5.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 (91) hide show
  1. package/CHANGELOG.md +107 -0
  2. package/README.md +781 -456
  3. package/dist/answers.d.ts +11 -4
  4. package/dist/answers.js +24 -0
  5. package/dist/core.d.ts +51 -0
  6. package/dist/core.js +758 -0
  7. package/dist/http.d.ts +20 -3
  8. package/dist/http.js +32 -7
  9. package/dist/index.d.ts +12 -36
  10. package/dist/index.js +9 -162
  11. package/dist/module.d.ts +372 -0
  12. package/dist/module.js +13 -0
  13. package/dist/modules/algorand/index.d.ts +22 -0
  14. package/dist/modules/algorand/index.js +247 -0
  15. package/dist/modules/algorand/own.d.ts +26 -0
  16. package/dist/modules/algorand/own.js +231 -0
  17. package/dist/modules/aptos/index.d.ts +23 -0
  18. package/dist/modules/aptos/index.js +232 -0
  19. package/dist/modules/cardano/index.d.ts +18 -0
  20. package/dist/modules/cardano/index.js +124 -0
  21. package/dist/modules/casper/index.d.ts +120 -0
  22. package/dist/modules/casper/index.js +442 -0
  23. package/dist/modules/concordium/index.d.ts +16 -0
  24. package/dist/modules/concordium/index.js +77 -0
  25. package/dist/modules/erc7710/index.d.ts +26 -0
  26. package/dist/modules/erc7710/index.js +220 -0
  27. package/dist/modules/evm/forms.d.ts +74 -0
  28. package/dist/modules/evm/forms.js +204 -0
  29. package/dist/modules/evm/index.d.ts +40 -0
  30. package/dist/modules/evm/index.js +154 -0
  31. package/dist/modules/evm/node.d.ts +29 -0
  32. package/dist/modules/evm/node.js +222 -0
  33. package/dist/modules/hedera/executor.d.ts +63 -0
  34. package/dist/modules/hedera/executor.js +343 -0
  35. package/dist/modules/hedera/index.d.ts +23 -0
  36. package/dist/modules/hedera/index.js +136 -0
  37. package/dist/modules/hedera/mirror.d.ts +32 -0
  38. package/dist/modules/hedera/mirror.js +111 -0
  39. package/dist/modules/index.d.ts +23 -0
  40. package/dist/modules/index.js +24 -0
  41. package/dist/modules/lnbtc/index.d.ts +10 -0
  42. package/dist/modules/lnbtc/index.js +112 -0
  43. package/dist/modules/near/index.d.ts +18 -0
  44. package/dist/modules/near/index.js +246 -0
  45. package/dist/modules/polkadot/index.d.ts +12 -0
  46. package/dist/modules/polkadot/index.js +149 -0
  47. package/dist/modules/polkadot/rail.d.ts +40 -0
  48. package/dist/{polkadot.js → modules/polkadot/rail.js} +214 -288
  49. package/dist/modules/solana/index.d.ts +60 -0
  50. package/dist/modules/solana/index.js +326 -0
  51. package/dist/modules/solana/reader.d.ts +25 -0
  52. package/dist/modules/solana/reader.js +194 -0
  53. package/dist/modules/solana/state.d.ts +6 -0
  54. package/dist/modules/solana/state.js +103 -0
  55. package/dist/modules/starknet/index.d.ts +35 -0
  56. package/dist/modules/starknet/index.js +548 -0
  57. package/dist/modules/starknet/node.d.ts +78 -0
  58. package/dist/modules/starknet/node.js +339 -0
  59. package/dist/modules/stellar/index.d.ts +44 -0
  60. package/dist/modules/stellar/index.js +481 -0
  61. package/dist/modules/stellar/node.d.ts +57 -0
  62. package/dist/modules/stellar/node.js +151 -0
  63. package/dist/modules/sui/index.d.ts +16 -0
  64. package/dist/modules/sui/index.js +310 -0
  65. package/dist/modules/sui/node.d.ts +49 -0
  66. package/dist/modules/sui/node.js +197 -0
  67. package/dist/modules/ton/index.d.ts +16 -0
  68. package/dist/modules/ton/index.js +73 -0
  69. package/dist/modules/tron/index.d.ts +12 -0
  70. package/dist/modules/tron/index.js +120 -0
  71. package/dist/modules/tron/rail.d.ts +32 -0
  72. package/dist/{tron.js → modules/tron/rail.js} +206 -195
  73. package/dist/modules/xrpl/index.d.ts +28 -0
  74. package/dist/modules/xrpl/index.js +299 -0
  75. package/dist/modules/xrpl/node.d.ts +52 -0
  76. package/dist/modules/xrpl/node.js +231 -0
  77. package/dist/modules/xrpl/upto.d.ts +5 -0
  78. package/dist/modules/xrpl/upto.js +269 -0
  79. package/dist/record.d.ts +131 -0
  80. package/dist/record.js +330 -0
  81. package/dist/unexpected.d.ts +3 -2
  82. package/dist/unexpected.js +2 -1
  83. package/dist/wrapper.d.ts +68 -0
  84. package/dist/wrapper.js +126 -0
  85. package/package.json +48 -12
  86. package/dist/polkadot.d.ts +0 -21
  87. package/dist/store.d.ts +0 -59
  88. package/dist/store.js +0 -103
  89. package/dist/tron.d.ts +0 -12
  90. /package/dist/{base58check.d.ts → modules/tron/base58check.d.ts} +0 -0
  91. /package/dist/{base58check.js → modules/tron/base58check.js} +0 -0
package/dist/answers.d.ts CHANGED
@@ -20,11 +20,12 @@ export interface FacilitatorRequest {
20
20
  }
21
21
  /**
22
22
  * The reasons a payment is refused. The x402 codes are the x402 specification's (§9); `invalid_transaction_state` in
23
- * a verify answer is a Tron transaction id the node or the store already holds. `unsupported_permission` and
24
- * `invalid_transaction` are this facilitator's: a Tron owner permission that does not accept the transaction's one
25
- * signature, and a transaction the node refuses in simulation or validation.
23
+ * a verify answer is an instrument the record or the chain already holds. `unsupported_permission`,
24
+ * `invalid_transaction` and `fee_budget_spent` are this facilitator's: a Tron owner permission that does not accept the
25
+ * transaction's signatures, a transaction the node refuses in simulation or validation, and a network whose fee budget
26
+ * is spent, so that nothing is sent. A published class's own reasons pass unchanged.
26
27
  */
27
- export type InvalidReason = "invalid_x402_version" | "unsupported_scheme" | "invalid_network" | "invalid_payment_requirements" | "invalid_payload" | "unsupported_permission" | "invalid_transaction" | "invalid_transaction_state" | "unexpected_verify_error";
28
+ export type InvalidReason = "invalid_x402_version" | "unsupported_scheme" | "invalid_network" | "invalid_payment_requirements" | "invalid_payload" | "unsupported_permission" | "invalid_transaction" | "invalid_transaction_state" | "fee_budget_spent" | "unexpected_verify_error";
28
29
  export type VerifyAnswer = {
29
30
  isValid: true;
30
31
  payer: string;
@@ -78,3 +79,9 @@ export declare function isObject(v: unknown): v is Record<string, unknown>;
78
79
  * request, or the reason it is refused.
79
80
  */
80
81
  export declare function readRequest(body: unknown): FacilitatorRequest | InvalidReason;
82
+ /**
83
+ * The shape checks of a request for any scheme: the versions, the objects a module reads, and the scheme and the
84
+ * network as strings. Returns the typed request, or the reason it is refused. Which scheme and network the settler
85
+ * serves is the core's to answer, from its configuration.
86
+ */
87
+ export declare function readShape(body: unknown): FacilitatorRequest | InvalidReason;
package/dist/answers.js CHANGED
@@ -82,3 +82,27 @@ export function readRequest(body) {
82
82
  return "invalid_network";
83
83
  return body;
84
84
  }
85
+ /**
86
+ * The shape checks of a request for any scheme: the versions, the objects a module reads, and the scheme and the
87
+ * network as strings. Returns the typed request, or the reason it is refused. Which scheme and network the settler
88
+ * serves is the core's to answer, from its configuration.
89
+ */
90
+ export function readShape(body) {
91
+ if (!isObject(body))
92
+ return "invalid_payload";
93
+ if (body["x402Version"] !== 2)
94
+ return "invalid_x402_version";
95
+ const p = body["paymentPayload"];
96
+ const r = body["paymentRequirements"];
97
+ if (!isObject(p) || !isObject(r))
98
+ return "invalid_payload";
99
+ if (p["x402Version"] !== 2)
100
+ return "invalid_x402_version";
101
+ if (!isObject(p["payload"]))
102
+ return "invalid_payload";
103
+ if (typeof r["scheme"] !== "string")
104
+ return "unsupported_scheme";
105
+ if (typeof r["network"] !== "string")
106
+ return "invalid_network";
107
+ return body;
108
+ }
package/dist/core.d.ts ADDED
@@ -0,0 +1,51 @@
1
+ import type { Network } from "@x402/core/types";
2
+ import type { ModuleName } from "./module.js";
3
+ import type { Listed, ModulesConfig } from "./modules/index.js";
4
+ /** One network's fee budget as the operator configures it: an amount of its fee asset over a period of seconds. */
5
+ export interface FeeBudgetConfig {
6
+ readonly network: Network;
7
+ /** In the smallest unit of the network's fee asset: a `bigint`, or its decimal digits. */
8
+ readonly amount: bigint | string;
9
+ readonly periodSeconds: number;
10
+ }
11
+ /** The members of the configuration the core reads; each listed module's own member is with them. */
12
+ export interface SettlerConfig {
13
+ /** "host:port" */
14
+ listen: string;
15
+ /** Postgres: the record, the fee count and the modules' durable state. */
16
+ store: {
17
+ url: string;
18
+ };
19
+ /** How long `/settle` waits for inclusion before answering `settlement_pending`; default 30 000. */
20
+ settleWaitMs: number;
21
+ /**
22
+ * The credential every call must present as `Authorization: Bearer <credential>`. A deployment with a module that
23
+ * holds a key does not start without one, since the caller names the payee and the amount and the key pays a fee
24
+ * for whatever is submitted. Its characters are those RFC 6750 admits in a bearer token.
25
+ */
26
+ credential?: string;
27
+ /** The fee budgets, at most one per network, each on a network a configured module serves. */
28
+ feeBudgets?: readonly FeeBudgetConfig[];
29
+ /**
30
+ * Receives every entry for the operator: what the facilitator saw that its answer does not carry, with `network`,
31
+ * `payer` and `transaction` naming the payment where they are known. `cause` is the error that caused the entry,
32
+ * when there is one; the answer to the client is the same either way, and carries nothing from it. Called once per
33
+ * entry; what it throws, or a promise it returns that rejects, goes to the default with an `operator-log-failed`
34
+ * entry. Default: one JSON line per entry on standard error, the cause as its `cause` (name, message, stack and its
35
+ * own `cause` chain).
36
+ */
37
+ operatorLog?: (entry: {
38
+ event: string;
39
+ network?: string;
40
+ payer?: string;
41
+ transaction?: string;
42
+ [field: string]: unknown;
43
+ }, cause?: unknown) => void;
44
+ }
45
+ /**
46
+ * Starts the settler with the modules of `list` that `c` names. The public start function passes the settler's own
47
+ * list; a test passes one of its own.
48
+ */
49
+ export declare function serveSettler<List extends readonly Listed<ModuleName, never>[]>(c: SettlerConfig & ModulesConfig<List>, list: List): Promise<{
50
+ close(): Promise<void>;
51
+ }>;