@integraledger/profile-facilitator 0.5.0 → 0.6.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 (55) hide show
  1. package/CHANGELOG.md +556 -0
  2. package/README.md +754 -111
  3. package/dist/core.d.ts +1 -1
  4. package/dist/core.js +683 -66
  5. package/dist/http.d.ts +19 -4
  6. package/dist/http.js +16 -6
  7. package/dist/module.d.ts +111 -24
  8. package/dist/module.js +39 -0
  9. package/dist/modules/algorand/index.js +1 -1
  10. package/dist/modules/aptos/index.js +1 -1
  11. package/dist/modules/cardano/index.js +1 -1
  12. package/dist/modules/casper/index.js +15 -3
  13. package/dist/modules/concordium/index.js +1 -1
  14. package/dist/modules/erc7710/index.d.ts +8 -5
  15. package/dist/modules/erc7710/index.js +1111 -34
  16. package/dist/modules/evm/escrow.d.ts +125 -0
  17. package/dist/modules/evm/escrow.js +619 -0
  18. package/dist/modules/evm/forms.d.ts +39 -11
  19. package/dist/modules/evm/forms.js +191 -25
  20. package/dist/modules/evm/index.d.ts +41 -6
  21. package/dist/modules/evm/index.js +1135 -20
  22. package/dist/modules/evm/node.d.ts +16 -1
  23. package/dist/modules/evm/node.js +181 -26
  24. package/dist/modules/evm/nonce-proof.d.ts +186 -0
  25. package/dist/modules/evm/nonce-proof.js +779 -0
  26. package/dist/modules/hedera/executor.js +1 -1
  27. package/dist/modules/hedera/index.js +1 -1
  28. package/dist/modules/lnbtc/index.js +3 -2
  29. package/dist/modules/near/index.js +1 -1
  30. package/dist/modules/polkadot/index.js +1 -1
  31. package/dist/modules/solana/index.d.ts +3 -0
  32. package/dist/modules/solana/index.js +119 -10
  33. package/dist/modules/solana/reader.d.ts +2 -1
  34. package/dist/modules/solana/reader.js +42 -4
  35. package/dist/modules/solana/upto-claim.d.ts +58 -0
  36. package/dist/modules/solana/upto-claim.js +269 -0
  37. package/dist/modules/starknet/index.js +9 -2
  38. package/dist/modules/stellar/index.d.ts +5 -0
  39. package/dist/modules/stellar/index.js +18 -8
  40. package/dist/modules/stellar/node.d.ts +7 -1
  41. package/dist/modules/stellar/node.js +51 -7
  42. package/dist/modules/sui/index.js +66 -20
  43. package/dist/modules/sui/node.d.ts +13 -0
  44. package/dist/modules/sui/node.js +60 -0
  45. package/dist/modules/ton/index.js +6 -2
  46. package/dist/modules/tron/index.js +1 -1
  47. package/dist/modules/xrpl/index.js +61 -12
  48. package/dist/modules/xrpl/node.d.ts +31 -2
  49. package/dist/modules/xrpl/node.js +88 -17
  50. package/dist/modules/xrpl/upto.js +106 -20
  51. package/dist/record.d.ts +52 -8
  52. package/dist/record.js +39 -5
  53. package/dist/wrapper.d.ts +7 -5
  54. package/dist/wrapper.js +7 -5
  55. package/package.json +4 -3
@@ -0,0 +1,125 @@
1
+ /**
2
+ * The read of an auth-capture escrow's later message: a capture, a void or a refund that x402's lifecycle manager sends
3
+ * on a payment an earlier hold opened in the commerce-payments escrow. lcp does not decode these messages, so the
4
+ * module reads them itself, from the escrow's own state and events, by the payment's hash as the escrow computes it.
5
+ *
6
+ * The escrow keeps, per payment, a capturable and a refundable amount. A capture moves its amount from the first to the
7
+ * second, a refund takes its amount from the second, a void and a reclaim empty the first. The capturable amount never
8
+ * rises again once a hold is made, and a capture or refund of zero reverts, so the pair the receiver authorizer signs as
9
+ * the message's expected amounts, once left, never returns. A capture or refund whose expected amounts still stand has
10
+ * not landed, and the escrow takes it as signed; one whose expected amounts no longer stand can never be taken as signed
11
+ * again. A void is in the same position while the capturable amount is above zero. The escrow itself does not compare
12
+ * a call with the expected amounts: the same capture or refund call sent twice executes twice, so it is the module that
13
+ * sends a message's call at most once (`unexecutedAt`).
14
+ */
15
+ import { type EvmReader, type Hex } from "@integraledger/lcp/evm";
16
+ import { type ChainRead, type X402Payment } from "../../module.js";
17
+ /** Whether call data is the escrow's `void`. */
18
+ export declare function isVoidCall(data: string): boolean;
19
+ /**
20
+ * A transaction the module signed for the message's own call (a capture's, not the void of its remainder) that may have
21
+ * been given to a node: its hash, and its sending account and nonce where the module still keeps its signed bytes.
22
+ */
23
+ export interface SignedCall {
24
+ readonly hash: string;
25
+ readonly from?: Hex;
26
+ readonly nonce?: bigint;
27
+ }
28
+ /** The most blocks one `eth_getLogs` call of the read asks for: nodes that bound a call's range take this many. */
29
+ export declare const LOG_SPAN = 2000n;
30
+ /**
31
+ * The read of an escrow's later message, at the mark `finalized`. `at.transaction` is the transaction the record names
32
+ * for the claim, the last one the module named before sending it; `at.from` the block the module read just before the
33
+ * claim (`escrowPosition`), after which anything the settler sent lands. In this order:
34
+ *
35
+ * - The transaction the record names, where the node shows its receipt: reverted, `failed` (`transaction-failed`),
36
+ * naming it; executed with the escrow's event of this message, `settled`, naming it. Either in a block above the
37
+ * finalized one is `pending` (`below-mark`). Where the node holds it unmined (it shows it with no block), `pending`
38
+ * (`below-mark`) naming it. Where the node shows it in a block and no receipt of it, it is not held: where the node
39
+ * shows it, or another signed at its nonce, in a block, `settled` where the finalized chain shows one of them
40
+ * executed with the message's event (`own`, below), naming that one; else the read goes on.
41
+ * - The `pending` transaction count of each of the gas key's own addresses (`keys`, the accounts that sign and send the
42
+ * escrow's calls, whatever contract `PaymentInfo.operator` names), then one block fixed (the latest) for the escrow's
43
+ * amounts for the payment and each address's mined count. Where the amounts are still those the message expects (for
44
+ * a void, a capturable amount above zero), the message has not landed: `pending` (`instrument-live`), so a held claim
45
+ * may send the identical message again, unless an address's pending count is above its mined count, a transaction
46
+ * the node held unmined, which may be this message: `pending` (`below-mark`), and nothing is sent. A send the node held when the
47
+ * pending count was read is either mined by the fixed block, its effect in the amounts, or counted unmined. An
48
+ * endpoint whose reads do not show a transaction it accepted cannot be told from one that holds none.
49
+ * - Otherwise the escrow's events for the payment after `from`, to the fixed block, asked for `LOG_SPAN` blocks at a
50
+ * time, are replayed from the amounts at `from`, which are those at the fixed block with the events since undone (no
51
+ * state older than the fixed block is read). Where the amounts at `from` show the message can never be taken as
52
+ * signed (`past`), `failed` (`before-position`) naming nothing, once `from` is at or below the finalized block, and
53
+ * `pending` (`below-mark`) before. The event of this message applied where its expected
54
+ * amounts stood is the message landing, `settled` naming its transaction; else the first event after which the
55
+ * message can never be taken as signed, `failed` (`instrument-consumed`) naming it; either above the finalized block
56
+ * is `pending` (`below-mark`). Where neither is found, or without `from`, `pending` (`search-incomplete`).
57
+ *
58
+ * A capture that also carries the void of the payment's remainder (`carriesVoid`) is `settled` only once
59
+ * that void is done: where its capture landed at or below the finalized block, the capturable amount at the finalized
60
+ * block is above zero, and no void the module sent for it was reverted (the transaction named last), it is `pending`:
61
+ * `below-mark` where the capturable amount at the latest block is zero or a transaction of the gas key is unmined, else
62
+ * `instrument-live`, so that a held claim sends the void (`voidOf`, `captureLanded`). A void the escrow reverted leaves
63
+ * the capture's own answer, `settled`. `voids` reads a capture as carrying that void where its row's claim carried it,
64
+ * whatever body is presented now.
65
+ *
66
+ * `own` is every transaction the module signed for the message's own call that may have been given to a node
67
+ * (`SignedCall`). The escrow takes a call whatever amounts the message expects, so one of them that executed is the
68
+ * message landing wherever the amounts stood, and no answer is `failed` for good while one of them may have executed
69
+ * the message or may still: `before-position` and `instrument-consumed` above are given only where, at one
70
+ * finalized block named by its hash, every one of them is shown unable to. Its nonce is not yet taken there (the key's
71
+ * count) and the amounts there let no call of the message execute any more (`never`); or its nonce is taken, and the
72
+ * finalized chain shows what took it: a receipt of one signed at that nonce that reverted, or another transaction of
73
+ * the key (`nonceProof`). Where the finalized chain shows one of them executed with the message's event (its receipt,
74
+ * or the events of the block that holds it, read by that block's hash, where the node shows no receipt), `settled`
75
+ * naming it. Otherwise `pending` (`below-mark`) naming the row's transaction: a lookup that finds nothing decides
76
+ * nothing.
77
+ *
78
+ * A node call that fails is `unreadable`, and nothing is sent on it.
79
+ */
80
+ export declare function escrowRead(reader: EvmReader, rpc: string, keys: readonly Hex[], p: X402Payment, at: {
81
+ readonly deadline: number;
82
+ readonly from?: unknown;
83
+ readonly transaction?: string;
84
+ }, voids?: boolean, own?: readonly SignedCall[]): Promise<ChainRead>;
85
+ /**
86
+ * For a capture whose receiver authorizer also signed the void of the payment's remainder: the one of `named`, the
87
+ * transactions earlier settles of its claim named, whose receipt shows the escrow's event of this capture, where one
88
+ * does; undefined otherwise, and for any other message.
89
+ */
90
+ export declare function captureLanded(reader: EvmReader, rpc: string, p: X402Payment, named: readonly string[], deadline: number, voids?: boolean): Promise<Hex | undefined>;
91
+ /**
92
+ * Whether a capture's payload also voids the payment's remainder, as x402's `AuthCaptureEvmScheme` of `@x402/evm`
93
+ * 2.31.0 reads it: a `voidAuthorizerSignature` that is not empty (the class tests it for truth), or, for a delegated
94
+ * receiver authorizer, `voidRemainder` true, which the class signs as a void beside the capture.
95
+ */
96
+ export declare function carriesVoid(body: Record<string, unknown>): boolean;
97
+ /**
98
+ * The void of the payment's remainder a capture carries (`carriesVoid`), as the lifecycle manager sends a void: its
99
+ * type, the payment, the salt nonce, and the receiver authorizer's signature of the void where the capture carries one;
100
+ * undefined for any other payload.
101
+ */
102
+ export declare function voidOf(p: X402Payment): X402Payment | undefined;
103
+ /** A block named by its hash, as EIP-1898 names one: the same answer on every node that holds it, or none. */
104
+ export interface FinalizedBlock {
105
+ readonly number: bigint;
106
+ readonly hash: Hex;
107
+ }
108
+ /** The block the node names `finalized`, by its number and hash. */
109
+ export declare function finalizedBlock(rpc: string, deadline: number): Promise<FinalizedBlock>;
110
+ /** `account`'s transaction count at the block `at`, named by its hash (EIP-1898), which must be canonical. */
111
+ export declare function countAt(rpc: string, account: Hex, at: FinalizedBlock, deadline: number): Promise<bigint>;
112
+ /**
113
+ * Whether the escrow's own state at the block `at`, named by its hash (EIP-1898), shows the message `p` unexecuted:
114
+ * the payment's pair (`capturableAmount`, `refundableAmount`) is the one the message expects, and for a void the
115
+ * capturable amount is above zero. The escrow's pair falls strictly (ordered by the capturable amount, then the
116
+ * refundable) with every call that executes, and a call that reverts leaves it: so a pair, once left, never returns,
117
+ * and the pair a message expects standing at a block shows that no execution of that message (of any copy of it) is
118
+ * in that block or before it. False where the payload is no capture, void or refund the escrow takes.
119
+ */
120
+ export declare function unexecutedAt(rpc: string, p: X402Payment, at: FinalizedBlock, deadline: number): Promise<boolean>;
121
+ /**
122
+ * The block an escrow's later message is read from: the latest block, read just before the settler claims the message,
123
+ * as a decimal string, so that anything the settler sends for it lands after it.
124
+ */
125
+ export declare function escrowPosition(rpc: string, deadline: number): Promise<string>;