@wasit-dev/core 0.8.0-beta.1 → 0.8.0-beta.3
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.
- package/README.md +13 -2
- package/dist/baseline.d.ts +3 -1
- package/dist/baseline.js +23 -9
- package/dist/check.d.ts +1 -1
- package/dist/ci-report.js +20 -8
- package/dist/config-writer.d.ts +96 -0
- package/dist/config-writer.js +281 -0
- package/dist/guard/budget.d.ts +7 -4
- package/dist/guard/budget.js +11 -4
- package/dist/guard/ci-event.d.ts +6 -0
- package/dist/guard/ci-event.js +7 -3
- package/dist/guard/ci-mainnet.d.ts +59 -0
- package/dist/guard/ci-mainnet.js +149 -0
- package/dist/guard/horizon.d.ts +30 -0
- package/dist/guard/horizon.js +107 -0
- package/dist/guard/mainnet-optin.d.ts +3 -1
- package/dist/guard/mainnet-optin.js +8 -2
- package/dist/guard/mainnet-payer.d.ts +66 -0
- package/dist/guard/mainnet-payer.js +92 -0
- package/dist/guard/mainnet-plan.d.ts +133 -0
- package/dist/guard/mainnet-plan.js +208 -0
- package/dist/guard/mainnet-run.d.ts +87 -0
- package/dist/guard/mainnet-run.js +225 -0
- package/dist/guard/networks.d.ts +9 -8
- package/dist/guard/networks.js +21 -10
- package/dist/guard/optin.d.ts +106 -0
- package/dist/guard/optin.js +202 -0
- package/dist/guard/run-ledger.d.ts +212 -0
- package/dist/guard/run-ledger.js +426 -0
- package/dist/guard/run-lock.d.ts +62 -0
- package/dist/guard/run-lock.js +172 -0
- package/dist/guard/signed-terms.d.ts +135 -0
- package/dist/guard/signed-terms.js +252 -0
- package/dist/index.d.ts +18 -7
- package/dist/index.js +19 -5
- package/dist/mpp/channel-credential.d.ts +13 -1
- package/dist/mpp/channel-credential.js +18 -2
- package/dist/mpp/channel.d.ts +6 -0
- package/dist/mpp/channel.js +7 -3
- package/dist/mpp/charge.d.ts +31 -1
- package/dist/mpp/charge.js +74 -20
- package/dist/mpp/plan.d.ts +77 -0
- package/dist/mpp/plan.js +188 -0
- package/dist/mpp/suite.d.ts +6 -0
- package/dist/mpp/suite.js +2 -1
- package/dist/route-reader.d.ts +124 -0
- package/dist/route-reader.js +349 -0
- package/dist/wallet.d.ts +58 -1
- package/dist/wallet.js +128 -0
- package/dist/x402/chains/stellar.d.ts +39 -4
- package/dist/x402/chains/stellar.js +224 -19
- package/dist/x402/chains/svm.js +6 -2
- package/dist/x402/chains/types.d.ts +44 -2
- package/dist/x402/plan.d.ts +102 -0
- package/dist/x402/plan.js +380 -6
- package/dist/x402/rejected-request.d.ts +10 -0
- package/dist/x402/rejected-request.js +18 -0
- package/dist/x402/simulator.d.ts +34 -0
- package/dist/x402/simulator.js +461 -50
- package/package.json +9 -9
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The signed-terms gate (spec B17.2): what the payer's key signs is checked,
|
|
3
|
+
* not only what the x402 client was asked to pay.
|
|
4
|
+
*
|
|
5
|
+
* L2 checks the terms Wasit hands the client: the pin, the plan, the $1 and
|
|
6
|
+
* the run's cap. On Stellar the client then builds the transfer by simulating
|
|
7
|
+
* it on the RPC and signs the authorization entries the simulation returns
|
|
8
|
+
* (`@x402/stellar` `ExactStellarScheme.createPaymentPayload`, through
|
|
9
|
+
* `AssembledTransaction.signAuthEntries`). The RPC chooses the contract, the
|
|
10
|
+
* function, the arguments, the sub-invocations, how many entries name the
|
|
11
|
+
* payer and the ledger the expiration is counted from. So the payer's signer
|
|
12
|
+
* is wrapped: each request to sign is decoded, and the key signs only when the
|
|
13
|
+
* preimage, which is exactly what the signature covers, authorizes
|
|
14
|
+
* `transfer(payer, payTo, amount)` on the asset that was checked, on the run's
|
|
15
|
+
* network, with no further call, once per payment, and expires no later than
|
|
16
|
+
* the payment's lifetime allows. Otherwise nothing is signed.
|
|
17
|
+
*
|
|
18
|
+
* What the cap then rests on: a signature authorizes that one transfer, once
|
|
19
|
+
* (its nonce), whoever submits it. The expiration bound keeps a signature from
|
|
20
|
+
* outliving the run; the cap does not depend on it.
|
|
21
|
+
*/
|
|
22
|
+
import { xdr } from "@stellar/stellar-sdk";
|
|
23
|
+
/** What one payment may be signed for: the terms L2 checked and charged. */
|
|
24
|
+
export interface SigningTerms {
|
|
25
|
+
/** The run's CAIP-2 network. */
|
|
26
|
+
readonly network: string;
|
|
27
|
+
/** The payer's address, derived from the key Wasit holds. */
|
|
28
|
+
readonly payer: string;
|
|
29
|
+
/** The asset contract that was checked. */
|
|
30
|
+
readonly asset: string;
|
|
31
|
+
/** The payee that was checked. */
|
|
32
|
+
readonly payTo: string;
|
|
33
|
+
/** The amount charged to the run, in base units. */
|
|
34
|
+
readonly amount: string;
|
|
35
|
+
/** The latest ledger (the chain's unit) the signature may stay valid to. */
|
|
36
|
+
readonly maxExpiration: number;
|
|
37
|
+
}
|
|
38
|
+
/** A signature the gate let through, with the preimage it covers (base64 XDR). */
|
|
39
|
+
export interface SignedRecord {
|
|
40
|
+
readonly preimage: string;
|
|
41
|
+
readonly signature: Buffer;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* One payment's permission to sign. `preparePayment` arms it with the terms
|
|
45
|
+
* it checked, right before the client builds the payment; the payer's signer
|
|
46
|
+
* takes the terms once. A request to sign before it is armed, or a second one
|
|
47
|
+
* in the same payment, is refused.
|
|
48
|
+
*/
|
|
49
|
+
export declare class SigningGate {
|
|
50
|
+
#private;
|
|
51
|
+
arm(terms: SigningTerms): void;
|
|
52
|
+
/** The terms it was armed with, if any. */
|
|
53
|
+
get terms(): SigningTerms | undefined;
|
|
54
|
+
/** Called by the signer before it signs: the terms, once. */
|
|
55
|
+
take(): SigningTerms;
|
|
56
|
+
/** Called by the signer after it signed. */
|
|
57
|
+
record(signed: SignedRecord): void;
|
|
58
|
+
/** The signature it let through, if any. */
|
|
59
|
+
get signed(): SignedRecord | undefined;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The two forms of Soroban authorization preimage Wasit signs (CAP-71-02,
|
|
63
|
+
* final, protocol 27):
|
|
64
|
+
*
|
|
65
|
+
* - `address`: `ENVELOPE_TYPE_SOROBAN_AUTHORIZATION`, the payload of the
|
|
66
|
+
* legacy address credential (`SOROBAN_CREDENTIALS_ADDRESS`);
|
|
67
|
+
* - `address-v2`: `ENVELOPE_TYPE_SOROBAN_AUTHORIZATION_WITH_ADDRESS`, the same
|
|
68
|
+
* fields plus the signer's address, the payload of
|
|
69
|
+
* `SOROBAN_CREDENTIALS_ADDRESS_V2`. The CAP gives V2 the same semantics as
|
|
70
|
+
* the legacy credential; only the payload differs, and it binds the address.
|
|
71
|
+
* `@stellar/stellar-sdk` 17 simulates with V2 by default (`useUpgradedAuth`).
|
|
72
|
+
*
|
|
73
|
+
* The delegated form (`SOROBAN_CREDENTIALS_ADDRESS_WITH_DELEGATES`) signs the
|
|
74
|
+
* same `address-v2` payload, and the preimage alone does not tell the two
|
|
75
|
+
* apart. So when the RPC's simulation hands the payer a delegated entry, the
|
|
76
|
+
* key does sign: the signature is the one an honest V2 entry for that same
|
|
77
|
+
* transfer would carry (one transfer of the checked amount to the checked
|
|
78
|
+
* payee, once by its nonce, within the expiry, and counted in the cap like
|
|
79
|
+
* every signature). What is sent is then held to the form the preimage names
|
|
80
|
+
* (`stellar.ts`, `bind`), and a delegated credential is refused there as
|
|
81
|
+
* signed and not sent.
|
|
82
|
+
*/
|
|
83
|
+
export type StellarPreimageForm = "address" | "address-v2";
|
|
84
|
+
export interface StellarPreimage {
|
|
85
|
+
readonly form: StellarPreimageForm;
|
|
86
|
+
readonly networkId: Buffer;
|
|
87
|
+
readonly nonce: string;
|
|
88
|
+
readonly signatureExpirationLedger: number;
|
|
89
|
+
readonly invocation: xdr.SorobanAuthorizedInvocation;
|
|
90
|
+
/** The signer's address the payload binds: only in the `address-v2` form; undefined if it does not decode. */
|
|
91
|
+
readonly address?: string | undefined;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* The preimage `preimage` (base64 XDR), read in one of the two forms Wasit
|
|
95
|
+
* signs; undefined when it does not decode or is another form.
|
|
96
|
+
*/
|
|
97
|
+
export declare function readStellarPreimage(preimage: string): StellarPreimage | undefined;
|
|
98
|
+
/**
|
|
99
|
+
* The ledger a signature the gate let through expires at, decoded from the
|
|
100
|
+
* preimage the key signed (spec B5: the expiry is read, never computed);
|
|
101
|
+
* undefined when it does not decode as one of the two forms Wasit signs.
|
|
102
|
+
*/
|
|
103
|
+
export declare function expirationOfSigned(record: SignedRecord): number | undefined;
|
|
104
|
+
/**
|
|
105
|
+
* The run's first reading of the chain's latest unit (a ledger on Stellar),
|
|
106
|
+
* and when it was read on a monotonic clock. A signature made later may stay
|
|
107
|
+
* valid only for the units that can have closed since, plus its lifetime: so
|
|
108
|
+
* an RPC that answers a later ledger after this reading cannot stretch it.
|
|
109
|
+
*/
|
|
110
|
+
export declare class SigningAnchor {
|
|
111
|
+
#private;
|
|
112
|
+
get reading(): {
|
|
113
|
+
readonly unit: number;
|
|
114
|
+
readonly at: number;
|
|
115
|
+
} | undefined;
|
|
116
|
+
/** Keeps the first reading only. `at` is `performance.now()` milliseconds. */
|
|
117
|
+
set(unit: number, at?: number): void;
|
|
118
|
+
/**
|
|
119
|
+
* The latest unit a signature made `now` may expire at, for a lifetime of
|
|
120
|
+
* `lifetimeSeconds`, with units of `unitSeconds` (the shortest a unit takes:
|
|
121
|
+
* a faster chain only tightens the bound) and 2 units of slack.
|
|
122
|
+
*/
|
|
123
|
+
maxExpiration(unitSeconds: number, lifetimeSeconds: number, now?: number): number;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Throws, so that nothing is signed, unless the Soroban authorization preimage
|
|
127
|
+
* `preimage` (base64 XDR, as the SDK hands it to the signer) authorizes exactly
|
|
128
|
+
* `transfer(payer, payTo, amount)` on `asset`, on the run's network, with no
|
|
129
|
+
* sub-invocation, expiring no later than `maxExpiration`.
|
|
130
|
+
*
|
|
131
|
+
* Two forms are signed (see {@link StellarPreimageForm}): the address
|
|
132
|
+
* credential's and the address-bound one, whose address must be the payer's.
|
|
133
|
+
* Any other form is refused, as is anything that does not decode.
|
|
134
|
+
*/
|
|
135
|
+
export declare function checkStellarPreimage(preimage: string, terms: SigningTerms): StellarPreimageForm;
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The signed-terms gate (spec B17.2): what the payer's key signs is checked,
|
|
3
|
+
* not only what the x402 client was asked to pay.
|
|
4
|
+
*
|
|
5
|
+
* L2 checks the terms Wasit hands the client: the pin, the plan, the $1 and
|
|
6
|
+
* the run's cap. On Stellar the client then builds the transfer by simulating
|
|
7
|
+
* it on the RPC and signs the authorization entries the simulation returns
|
|
8
|
+
* (`@x402/stellar` `ExactStellarScheme.createPaymentPayload`, through
|
|
9
|
+
* `AssembledTransaction.signAuthEntries`). The RPC chooses the contract, the
|
|
10
|
+
* function, the arguments, the sub-invocations, how many entries name the
|
|
11
|
+
* payer and the ledger the expiration is counted from. So the payer's signer
|
|
12
|
+
* is wrapped: each request to sign is decoded, and the key signs only when the
|
|
13
|
+
* preimage, which is exactly what the signature covers, authorizes
|
|
14
|
+
* `transfer(payer, payTo, amount)` on the asset that was checked, on the run's
|
|
15
|
+
* network, with no further call, once per payment, and expires no later than
|
|
16
|
+
* the payment's lifetime allows. Otherwise nothing is signed.
|
|
17
|
+
*
|
|
18
|
+
* What the cap then rests on: a signature authorizes that one transfer, once
|
|
19
|
+
* (its nonce), whoever submits it. The expiration bound keeps a signature from
|
|
20
|
+
* outliving the run; the cap does not depend on it.
|
|
21
|
+
*/
|
|
22
|
+
import { performance } from "node:perf_hooks";
|
|
23
|
+
import { Address, hash, scValToNative, xdr } from "@stellar/stellar-sdk";
|
|
24
|
+
import { networkPassphrase } from "../mpp/network.js";
|
|
25
|
+
import { PaymentGuardRefusedError, shown } from "./budget.js";
|
|
26
|
+
function refuse(message, options = {}) {
|
|
27
|
+
return new PaymentGuardRefusedError("signed-terms", message, options);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* One payment's permission to sign. `preparePayment` arms it with the terms
|
|
31
|
+
* it checked, right before the client builds the payment; the payer's signer
|
|
32
|
+
* takes the terms once. A request to sign before it is armed, or a second one
|
|
33
|
+
* in the same payment, is refused.
|
|
34
|
+
*/
|
|
35
|
+
export class SigningGate {
|
|
36
|
+
#terms;
|
|
37
|
+
#taken = false;
|
|
38
|
+
#signed;
|
|
39
|
+
arm(terms) {
|
|
40
|
+
if (this.#terms !== undefined)
|
|
41
|
+
throw new Error("A signing gate is armed once, for one payment.");
|
|
42
|
+
this.#terms = terms;
|
|
43
|
+
}
|
|
44
|
+
/** The terms it was armed with, if any. */
|
|
45
|
+
get terms() {
|
|
46
|
+
return this.#terms;
|
|
47
|
+
}
|
|
48
|
+
/** Called by the signer before it signs: the terms, once. */
|
|
49
|
+
take() {
|
|
50
|
+
if (this.#terms === undefined) {
|
|
51
|
+
throw refuse("The payer's key was asked to sign when Wasit expected no signature.");
|
|
52
|
+
}
|
|
53
|
+
if (this.#taken) {
|
|
54
|
+
// The first signature was made: the refusal must not say nothing was signed.
|
|
55
|
+
throw refuse("The x402 client asked the payer's key for a second signature in one payment; Wasit signs one per payment.", { signed: true });
|
|
56
|
+
}
|
|
57
|
+
this.#taken = true;
|
|
58
|
+
return this.#terms;
|
|
59
|
+
}
|
|
60
|
+
/** Called by the signer after it signed. */
|
|
61
|
+
record(signed) {
|
|
62
|
+
if (this.#signed !== undefined)
|
|
63
|
+
throw new Error("A signing gate records one signature.");
|
|
64
|
+
this.#signed = signed;
|
|
65
|
+
}
|
|
66
|
+
/** The signature it let through, if any. */
|
|
67
|
+
get signed() {
|
|
68
|
+
return this.#signed;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The preimage `preimage` (base64 XDR), read in one of the two forms Wasit
|
|
73
|
+
* signs; undefined when it does not decode or is another form.
|
|
74
|
+
*/
|
|
75
|
+
export function readStellarPreimage(preimage) {
|
|
76
|
+
let decoded;
|
|
77
|
+
try {
|
|
78
|
+
decoded = xdr.HashIdPreimage.fromXDR(preimage, "base64");
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
switch (decoded.switch().name) {
|
|
84
|
+
case "envelopeTypeSorobanAuthorization": {
|
|
85
|
+
const value = decoded.sorobanAuthorization();
|
|
86
|
+
return {
|
|
87
|
+
form: "address",
|
|
88
|
+
networkId: Buffer.from(value.networkId()),
|
|
89
|
+
nonce: value.nonce().toString(),
|
|
90
|
+
signatureExpirationLedger: value.signatureExpirationLedger(),
|
|
91
|
+
invocation: value.invocation(),
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
case "envelopeTypeSorobanAuthorizationWithAddress": {
|
|
95
|
+
const value = decoded.sorobanAuthorizationWithAddress();
|
|
96
|
+
let address;
|
|
97
|
+
try {
|
|
98
|
+
address = Address.fromScAddress(value.address()).toString();
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
address = undefined;
|
|
102
|
+
}
|
|
103
|
+
return {
|
|
104
|
+
form: "address-v2",
|
|
105
|
+
networkId: Buffer.from(value.networkId()),
|
|
106
|
+
nonce: value.nonce().toString(),
|
|
107
|
+
signatureExpirationLedger: value.signatureExpirationLedger(),
|
|
108
|
+
invocation: value.invocation(),
|
|
109
|
+
address,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
default:
|
|
113
|
+
return undefined;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* The ledger a signature the gate let through expires at, decoded from the
|
|
118
|
+
* preimage the key signed (spec B5: the expiry is read, never computed);
|
|
119
|
+
* undefined when it does not decode as one of the two forms Wasit signs.
|
|
120
|
+
*/
|
|
121
|
+
export function expirationOfSigned(record) {
|
|
122
|
+
return readStellarPreimage(record.preimage)?.signatureExpirationLedger;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* The run's first reading of the chain's latest unit (a ledger on Stellar),
|
|
126
|
+
* and when it was read on a monotonic clock. A signature made later may stay
|
|
127
|
+
* valid only for the units that can have closed since, plus its lifetime: so
|
|
128
|
+
* an RPC that answers a later ledger after this reading cannot stretch it.
|
|
129
|
+
*/
|
|
130
|
+
export class SigningAnchor {
|
|
131
|
+
#reading;
|
|
132
|
+
get reading() {
|
|
133
|
+
return this.#reading;
|
|
134
|
+
}
|
|
135
|
+
/** Keeps the first reading only. `at` is `performance.now()` milliseconds. */
|
|
136
|
+
set(unit, at = performance.now()) {
|
|
137
|
+
if (this.#reading === undefined)
|
|
138
|
+
this.#reading = { unit, at };
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* The latest unit a signature made `now` may expire at, for a lifetime of
|
|
142
|
+
* `lifetimeSeconds`, with units of `unitSeconds` (the shortest a unit takes:
|
|
143
|
+
* a faster chain only tightens the bound) and 2 units of slack.
|
|
144
|
+
*/
|
|
145
|
+
maxExpiration(unitSeconds, lifetimeSeconds, now = performance.now()) {
|
|
146
|
+
const reading = this.#reading;
|
|
147
|
+
if (reading === undefined)
|
|
148
|
+
throw new Error("The anchor has no reading yet.");
|
|
149
|
+
if (typeof lifetimeSeconds !== "number" || !Number.isFinite(lifetimeSeconds) || lifetimeSeconds <= 0) {
|
|
150
|
+
throw refuse(`The payment's lifetime (${shown(lifetimeSeconds)} s) is not a positive number of seconds, so how long its ` +
|
|
151
|
+
`signature would stay valid cannot be bounded.`);
|
|
152
|
+
}
|
|
153
|
+
const elapsed = Math.max(0, now - reading.at);
|
|
154
|
+
return reading.unit + Math.ceil(elapsed / (unitSeconds * 1000)) + Math.ceil(lifetimeSeconds / unitSeconds) + 2;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
const ASKED = "The authorization the x402 client asked the payer to sign";
|
|
158
|
+
function addressOf(value) {
|
|
159
|
+
if (value.switch().name !== "scvAddress")
|
|
160
|
+
return undefined;
|
|
161
|
+
try {
|
|
162
|
+
return Address.fromScVal(value).toString();
|
|
163
|
+
}
|
|
164
|
+
catch {
|
|
165
|
+
return undefined;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Throws, so that nothing is signed, unless the Soroban authorization preimage
|
|
170
|
+
* `preimage` (base64 XDR, as the SDK hands it to the signer) authorizes exactly
|
|
171
|
+
* `transfer(payer, payTo, amount)` on `asset`, on the run's network, with no
|
|
172
|
+
* sub-invocation, expiring no later than `maxExpiration`.
|
|
173
|
+
*
|
|
174
|
+
* Two forms are signed (see {@link StellarPreimageForm}): the address
|
|
175
|
+
* credential's and the address-bound one, whose address must be the payer's.
|
|
176
|
+
* Any other form is refused, as is anything that does not decode.
|
|
177
|
+
*/
|
|
178
|
+
export function checkStellarPreimage(preimage, terms) {
|
|
179
|
+
let decoded;
|
|
180
|
+
try {
|
|
181
|
+
decoded = xdr.HashIdPreimage.fromXDR(preimage, "base64");
|
|
182
|
+
}
|
|
183
|
+
catch {
|
|
184
|
+
throw refuse(`${ASKED} does not decode as a Soroban authorization.`);
|
|
185
|
+
}
|
|
186
|
+
const authorization = readStellarPreimage(preimage);
|
|
187
|
+
if (authorization === undefined) {
|
|
188
|
+
throw refuse(`${ASKED} is a form of authorization Wasit does not sign (${decoded.switch().name}; it signs the address ` +
|
|
189
|
+
`credential and the address-bound one only).`);
|
|
190
|
+
}
|
|
191
|
+
if (authorization.form === "address-v2" && authorization.address !== terms.payer) {
|
|
192
|
+
throw refuse(`${ASKED} binds the signature to ${authorization.address === undefined ? "an address that does not decode" : shown(authorization.address)}, ` +
|
|
193
|
+
`not to the payer.`);
|
|
194
|
+
}
|
|
195
|
+
const networkId = hash(Buffer.from(networkPassphrase(terms.network)));
|
|
196
|
+
if (!authorization.networkId.equals(networkId)) {
|
|
197
|
+
throw refuse(`${ASKED} is for another network than this run's (${terms.network}).`);
|
|
198
|
+
}
|
|
199
|
+
const invocation = authorization.invocation;
|
|
200
|
+
const fn = invocation.function();
|
|
201
|
+
if (fn.switch().name !== "sorobanAuthorizedFunctionTypeContractFn") {
|
|
202
|
+
throw refuse(`${ASKED} is not a contract call.`);
|
|
203
|
+
}
|
|
204
|
+
const call = fn.contractFn();
|
|
205
|
+
let contract;
|
|
206
|
+
try {
|
|
207
|
+
contract = Address.fromScAddress(call.contractAddress()).toString();
|
|
208
|
+
}
|
|
209
|
+
catch {
|
|
210
|
+
throw refuse(`${ASKED} calls a contract whose address does not decode.`);
|
|
211
|
+
}
|
|
212
|
+
if (contract !== terms.asset) {
|
|
213
|
+
throw refuse(`${ASKED} calls the contract ${shown(contract)}, not the asset ${terms.asset} that was checked.`);
|
|
214
|
+
}
|
|
215
|
+
const name = call.functionName().toString();
|
|
216
|
+
if (name !== "transfer") {
|
|
217
|
+
throw refuse(`${ASKED} calls ${shown(name)} instead of transfer.`);
|
|
218
|
+
}
|
|
219
|
+
const args = call.args();
|
|
220
|
+
if (args.length !== 3) {
|
|
221
|
+
throw refuse(`${ASKED} gives transfer ${args.length} arguments instead of 3 (from, to, amount).`);
|
|
222
|
+
}
|
|
223
|
+
const from = addressOf(args[0]);
|
|
224
|
+
if (from !== terms.payer) {
|
|
225
|
+
throw refuse(`${ASKED} transfers from ${from === undefined ? "something that is not an address" : shown(from)}, not from the payer.`);
|
|
226
|
+
}
|
|
227
|
+
const to = addressOf(args[1]);
|
|
228
|
+
if (to !== terms.payTo) {
|
|
229
|
+
throw refuse(`${ASKED} pays ${to === undefined ? "something that is not an address" : shown(to)}, not ${terms.payTo}, ` +
|
|
230
|
+
`the payee that was checked.`);
|
|
231
|
+
}
|
|
232
|
+
if (!/^[1-9][0-9]*$/.test(terms.amount)) {
|
|
233
|
+
throw refuse(`The amount checked for this payment (${shown(terms.amount)}) is not a positive number of base units.`);
|
|
234
|
+
}
|
|
235
|
+
if (args[2].switch().name !== "scvI128") {
|
|
236
|
+
throw refuse(`${ASKED} gives the amount as ${args[2].switch().name}, not as the i128 of base units transfer takes.`);
|
|
237
|
+
}
|
|
238
|
+
const amount = scValToNative(args[2]);
|
|
239
|
+
if (amount !== BigInt(terms.amount)) {
|
|
240
|
+
throw refuse(`${ASKED} is for ${shown(String(amount))} base units, not the ${terms.amount} that was checked.`);
|
|
241
|
+
}
|
|
242
|
+
const further = invocation.subInvocations().length;
|
|
243
|
+
if (further !== 0) {
|
|
244
|
+
throw refuse(`${ASKED} also authorizes ${further} further call${further === 1 ? "" : "s"} beside the transfer.`);
|
|
245
|
+
}
|
|
246
|
+
const expiration = authorization.signatureExpirationLedger;
|
|
247
|
+
if (expiration > terms.maxExpiration) {
|
|
248
|
+
throw refuse(`${ASKED} stays valid until ledger ${expiration}, past ledger ${terms.maxExpiration}, the latest this ` +
|
|
249
|
+
`payment's lifetime allows.`);
|
|
250
|
+
}
|
|
251
|
+
return authorization.form;
|
|
252
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,10 @@ export { MARKDOWN_VALUE_MAX, sanitizeForMarkdown, sanitizeText } from "./sanitiz
|
|
|
4
4
|
export type { MarkdownOptions, SanitizeOptions } from "./sanitize.js";
|
|
5
5
|
export { CONFIG_VERSION, ConfigError, describeRun, headerEnvName, headersFromEnv, isLoopbackUrl, joinTarget, parseConfig, readConfigFile, resolveRun, urlOrigin, validateConfig, } from "./config.js";
|
|
6
6
|
export type { ChannelExpectation, ConfigIssue, EndpointConfig, EnvironmentConfig, JsonValue, PinConfig, ReadyConfig, RejectConfig, ResolvedEndpoint, ResolvedReject, ResolvedRun, RunSelection, ServiceConfig, WasitConfig, } from "./config.js";
|
|
7
|
+
export { ConfigWriteError, writeConfigText } from "./config-writer.js";
|
|
8
|
+
export type { ConfigWriteInput, ConfigWriteOptions, ConfigWriteResult, InitEndpointInput, InitEnvironmentInput, InitRejectInput, InitServiceInput, } from "./config-writer.js";
|
|
9
|
+
export { ROUTE_READ_TIMEOUT_MS, chooseOffer, describeOffer, interpretRouteAnswer, readRoute } from "./route-reader.js";
|
|
10
|
+
export type { OfferChoice, OfferWanted, ReadRouteOptions, RouteAnswer, RouteOffer, RouteProtocol, RouteReading, } from "./route-reader.js";
|
|
7
11
|
export { buildEndpointReport, buildRunReport, checkGroup, describeTotals, endpointOutcome, paymentGroupUnsupported, exitCodeForEndpoint, groupCounts, redactReport, redactValue, reportTotals, paymentChecksSkipped, skippedPaymentChecks, toGradedRun, } from "./report.js";
|
|
8
12
|
export type { CheckGroup, EndpointInput, EndpointOutcome, EndpointReport, GroupCounts, RunReport, RunReportInput, RunTotals, } from "./report.js";
|
|
9
13
|
export { readBuildCommit, readPackageVersion, readToolVersions } from "./versions.js";
|
|
@@ -21,23 +25,30 @@ export type { CheckCatalogueEntry, ProtocolId } from "./catalogue.js";
|
|
|
21
25
|
export * from "./errors.js";
|
|
22
26
|
export { NETWORK_CLASSES, PaymentNetworkRefusedError, assertPaymentNetworkAllowed, networkClass, } from "./guard/networks.js";
|
|
23
27
|
export type { NetworkClass, PaymentProtocol } from "./guard/networks.js";
|
|
24
|
-
export {
|
|
25
|
-
export type
|
|
28
|
+
export { MainnetJobRefusedError, assertMainnetJob, isLocalHost, mainnetJobRefusals, type MainnetJob } from "./guard/ci-mainnet.js";
|
|
29
|
+
export { MAINNET_PAYER_MAX_BASE_UNITS, MAINNET_PAYER_MAX_USD, MainnetPayerRefusedError, assertMainnetPayerBalance, type MainnetPayerAccount, type MainnetPayerRefusal, } from "./guard/mainnet-payer.js";
|
|
30
|
+
export { MAINNET_RUN_LOCK_FILE, MainnetRunLockedError, acquireMainnetRunLock, type LockHolder, type MainnetRunLock, } from "./guard/run-lock.js";
|
|
31
|
+
export { MAINNET_ANCHOR_MAX_GAP_LEDGERS, MAINNET_MAX_TIMEOUT_SECONDS, MAINNET_USDC, MainnetPlanRefusedError, PUBNET_HORIZON_URL, assertAnchorNearHorizon, assertBalancesAgree, assertMainnetDecimals, assertMainnetOption, assertMainnetPin, horizonBalances, parseHorizonAmount, type ClassicAsset, type HorizonBalances, type MainnetOption, type MainnetPlanRefusal, } from "./guard/mainnet-plan.js";
|
|
32
|
+
export { readHorizonAccount, readHorizonLatestLedger } from "./guard/horizon.js";
|
|
33
|
+
export { RUN_LEDGER_FORMAT, RunLedger, RunLedgerError, ledgerConsistency, openAuthorizationsUntil, runLedgerFileName, type LedgerBalances, type LedgerConsistency, type LedgerEntry, type LedgerEntryHandle, type LedgerEntryState, type LedgerResult, type LedgerVerdict, type PaymentLedger, type RunLedgerHeader, } from "./guard/run-ledger.js";
|
|
26
34
|
export { RPC_LOCK_VARIABLE, describeRpcInUse, readRpcLock, rpcInUse } from "./guard/rpc-in-use.js";
|
|
27
35
|
export { RpcIdentityError, assertRpcServesNetwork } from "./guard/rpc-identity.js";
|
|
28
36
|
export type { RpcInUse, RpcSource } from "./guard/rpc-in-use.js";
|
|
29
|
-
export { inGithubActions, payerKeyVariables, paymentEventGate, readGithubEvent } from "./guard/ci-event.js";
|
|
37
|
+
export { githubDefaultBranch, inGithubActions, payerKeyVariables, paymentEventGate, readGithubEvent } from "./guard/ci-event.js";
|
|
30
38
|
export type { PaymentEventGate } from "./guard/ci-event.js";
|
|
31
39
|
export { PER_PAYMENT_CAP_USD, PER_RUN_CAP_USD, PaymentGuardRefusedError, RunBudget, formatUsd, } from "./guard/budget.js";
|
|
32
40
|
export type { GuardRefusal, PinTerms, PlannedSignature } from "./guard/budget.js";
|
|
33
|
-
export { describePlan, planX402Run } from "./x402/plan.js";
|
|
34
|
-
export type { EndpointPlan, EndpointPlanStatus, PlannedOption, RunPlan, X402PlanOptions } from "./x402/plan.js";
|
|
41
|
+
export { describePlan, mainnetFirstLine, mainnetOpeningLine, planMainnetDryRun, planX402Run } from "./x402/plan.js";
|
|
42
|
+
export type { EndpointPlan, EndpointPlanStatus, MainnetDryRunOptions, MainnetFunding, MainnetReadings, PlannedOption, RunPlan, X402PlanOptions, } from "./x402/plan.js";
|
|
43
|
+
export { MAINNET_PAYER_KEY_ENV, MainnetRunRefusedError, closeMainnetRun, openMainnetOptIn, type MainnetCloseOptions, type MainnetCloseResult, type MainnetOptInInput, type MainnetRunRefusal, } from "./guard/mainnet-run.js";
|
|
44
|
+
export type { MainnetFrontEnd, MainnetOptIn } from "./guard/optin.js";
|
|
35
45
|
export * from "./x402/simulator.js";
|
|
36
46
|
export * from "./mpp/channel.js";
|
|
37
47
|
export * from "./mpp/charge.js";
|
|
38
48
|
export * from "./mpp/charge-suite.js";
|
|
39
49
|
export * from "./mpp/suite.js";
|
|
40
|
-
export {
|
|
41
|
-
export
|
|
50
|
+
export { MPP_CHARGE_SCHEME, assertMppPaymentRpc, combinePaymentPlan, describePaymentPlan, planMppChargeEndpoint, planPaymentRun, plannedChargeOf, type MppChargePlanInput, type PaymentRunPlanOptions, } from "./mpp/plan.js";
|
|
51
|
+
export { addTestnetUsdc, createUsdcTrustline, describeTransactionError, fundWithFriendbot, generateCommitmentKey, generateTestnetWallet, getTestnetWalletStatus, publicKeyFromSecret, sendUsdcFromDistributor, swapQuoteFrom, testnetUsdcAsset, TESTNET_SWAP_XLM, TESTNET_USDC_ISSUER, usdcSetupTransaction, } from "./wallet.js";
|
|
52
|
+
export type { AssetBalance, FriendbotOutcome, GeneratedCommitmentKey, GeneratedWallet, SwapPathRecord, UsdcSetupOutcome, UsdcSwapQuote, WalletStatus, } from "./wallet.js";
|
|
42
53
|
export { paymentChainFor, paymentNetworks } from "./x402/chains/index.js";
|
|
43
54
|
export type { PaymentChain } from "./x402/chains/index.js";
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,10 @@ export { SKIP_KINDS, checkStatus, errored, fixFor, quoteValue, skipped, skippedD
|
|
|
3
3
|
export { MARKDOWN_VALUE_MAX, sanitizeForMarkdown, sanitizeText } from "./sanitize.js";
|
|
4
4
|
// wasit.config.json, version 1.
|
|
5
5
|
export { CONFIG_VERSION, ConfigError, describeRun, headerEnvName, headersFromEnv, isLoopbackUrl, joinTarget, parseConfig, readConfigFile, resolveRun, urlOrigin, validateConfig, } from "./config.js";
|
|
6
|
+
// The config writer of `wasit init`: data that is certain in, a config `wasit run` accepts out.
|
|
7
|
+
export { ConfigWriteError, writeConfigText } from "./config-writer.js";
|
|
8
|
+
// What `wasit init` reads from a route: one unpaid request, and the one way to pay it writes.
|
|
9
|
+
export { ROUTE_READ_TIMEOUT_MS, chooseOffer, describeOffer, interpretRouteAnswer, readRoute } from "./route-reader.js";
|
|
6
10
|
// The run report, the endpoint outcome and the versions a result names.
|
|
7
11
|
export { buildEndpointReport, buildRunReport, checkGroup, describeTotals, endpointOutcome, paymentGroupUnsupported, exitCodeForEndpoint, groupCounts, redactReport, redactValue, reportTotals, paymentChecksSkipped, skippedPaymentChecks, toGradedRun, } from "./report.js";
|
|
8
12
|
export { readBuildCommit, readPackageVersion, readToolVersions } from "./versions.js";
|
|
@@ -17,26 +21,36 @@ export { CHECK_CATALOGUE, PROTOCOL_IDS, catalogueEntry, docsUrlFor } from "./cat
|
|
|
17
21
|
export * from "./errors.js";
|
|
18
22
|
// L0, the network guard every signing entry point runs.
|
|
19
23
|
export { NETWORK_CLASSES, PaymentNetworkRefusedError, assertPaymentNetworkAllowed, networkClass, } from "./guard/networks.js";
|
|
20
|
-
|
|
21
|
-
|
|
24
|
+
export { MainnetJobRefusedError, assertMainnetJob, isLocalHost, mainnetJobRefusals } from "./guard/ci-mainnet.js";
|
|
25
|
+
// The mainnet payer's $10 and the lock of a mainnet run (spec B17.5): rules that only refuse; the opt-in and its plan call them.
|
|
26
|
+
export { MAINNET_PAYER_MAX_BASE_UNITS, MAINNET_PAYER_MAX_USD, MainnetPayerRefusedError, assertMainnetPayerBalance, } from "./guard/mainnet-payer.js";
|
|
27
|
+
export { MAINNET_RUN_LOCK_FILE, MainnetRunLockedError, acquireMainnetRunLock, } from "./guard/run-lock.js";
|
|
28
|
+
// L1's mainnet rules and the two reads on public Horizon (spec B3, B4, B17.2): rules that only refuse; the plan and the close call them.
|
|
29
|
+
export { MAINNET_ANCHOR_MAX_GAP_LEDGERS, MAINNET_MAX_TIMEOUT_SECONDS, MAINNET_USDC, MainnetPlanRefusedError, PUBNET_HORIZON_URL, assertAnchorNearHorizon, assertBalancesAgree, assertMainnetDecimals, assertMainnetOption, assertMainnetPin, horizonBalances, parseHorizonAmount, } from "./guard/mainnet-plan.js";
|
|
30
|
+
export { readHorizonAccount, readHorizonLatestLedger } from "./guard/horizon.js";
|
|
31
|
+
// The run ledger (spec B5): every signature's intent written before the key signs, then its outcome.
|
|
32
|
+
export { RUN_LEDGER_FORMAT, RunLedger, RunLedgerError, ledgerConsistency, openAuthorizationsUntil, runLedgerFileName, } from "./guard/run-ledger.js";
|
|
22
33
|
// Which RPC a result read the chain through, and the MCP server's start-up RPC lock (D-023c).
|
|
23
34
|
export { RPC_LOCK_VARIABLE, describeRpcInUse, readRpcLock, rpcInUse } from "./guard/rpc-in-use.js";
|
|
24
35
|
export { RpcIdentityError, assertRpcServesNetwork } from "./guard/rpc-identity.js";
|
|
25
36
|
// Which GitHub events may run the payment tier (D-022a), and which key variables are set.
|
|
26
|
-
export { inGithubActions, payerKeyVariables, paymentEventGate, readGithubEvent } from "./guard/ci-event.js";
|
|
37
|
+
export { githubDefaultBranch, inGithubActions, payerKeyVariables, paymentEventGate, readGithubEvent } from "./guard/ci-event.js";
|
|
27
38
|
// L1 and L2: the plan, and the caps every signature is charged against.
|
|
28
39
|
export { PER_PAYMENT_CAP_USD, PER_RUN_CAP_USD, PaymentGuardRefusedError, RunBudget, formatUsd, } from "./guard/budget.js";
|
|
29
|
-
export { describePlan, planX402Run } from "./x402/plan.js";
|
|
40
|
+
export { describePlan, mainnetFirstLine, mainnetOpeningLine, planMainnetDryRun, planX402Run } from "./x402/plan.js";
|
|
41
|
+
// The mainnet opt-in (spec B5): made by openMainnetOptIn only, for one run. The type is exported, the class is not.
|
|
42
|
+
export { MAINNET_PAYER_KEY_ENV, MainnetRunRefusedError, closeMainnetRun, openMainnetOptIn, } from "./guard/mainnet-run.js";
|
|
30
43
|
export * from "./x402/simulator.js";
|
|
31
44
|
export * from "./mpp/channel.js";
|
|
32
45
|
export * from "./mpp/charge.js";
|
|
33
46
|
export * from "./mpp/charge-suite.js";
|
|
34
47
|
export * from "./mpp/suite.js";
|
|
48
|
+
export { MPP_CHARGE_SCHEME, assertMppPaymentRpc, combinePaymentPlan, describePaymentPlan, planMppChargeEndpoint, planPaymentRun, plannedChargeOf, } from "./mpp/plan.js";
|
|
35
49
|
// Wallet tooling is exported by name rather than with `export *`: it is a
|
|
36
50
|
// convenience layer for setting up testnet keys, not part of the check
|
|
37
51
|
// surface, and naming each entry keeps the rest of wallet.ts free to change
|
|
38
52
|
// without that being a breaking change to @wasit-dev/core.
|
|
39
|
-
export { createUsdcTrustline, describeTransactionError, fundWithFriendbot, generateCommitmentKey, generateTestnetWallet, getTestnetWalletStatus, publicKeyFromSecret, sendUsdcFromDistributor, testnetUsdcAsset, TESTNET_USDC_ISSUER, } from "./wallet.js";
|
|
53
|
+
export { addTestnetUsdc, createUsdcTrustline, describeTransactionError, fundWithFriendbot, generateCommitmentKey, generateTestnetWallet, getTestnetWalletStatus, publicKeyFromSecret, sendUsdcFromDistributor, swapQuoteFrom, testnetUsdcAsset, TESTNET_SWAP_XLM, TESTNET_USDC_ISSUER, usdcSetupTransaction, } from "./wallet.js";
|
|
40
54
|
// Which networks the x402 payment checks pay on, and which payer key each
|
|
41
55
|
// reads: front ends pick the key by the run's network.
|
|
42
56
|
export { paymentChainFor, paymentNetworks } from "./x402/chains/index.js";
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* amounts, so they assemble credentials directly.
|
|
10
10
|
*/
|
|
11
11
|
import { Challenge } from "mppx";
|
|
12
|
-
import { MalformedResponseError } from "../errors.js";
|
|
12
|
+
import { CheckSetupError, MalformedResponseError } from "../errors.js";
|
|
13
13
|
export type ChannelAction = "voucher" | "close";
|
|
14
14
|
export declare class ChannelChallengeError extends MalformedResponseError {
|
|
15
15
|
constructor(message: string);
|
|
@@ -70,6 +70,18 @@ export interface BuildChannelCredentialParams {
|
|
|
70
70
|
readonly network: string;
|
|
71
71
|
readonly rpcUrl?: string;
|
|
72
72
|
readonly action?: ChannelAction;
|
|
73
|
+
/**
|
|
74
|
+
* The only channel a commitment may be signed for (`wasit run`: the config's
|
|
75
|
+
* `channel`). A challenge that names another channel gets no signature.
|
|
76
|
+
*/
|
|
77
|
+
readonly onlyChannel?: string;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* A challenge names another channel than the one the run signs for. A setup
|
|
81
|
+
* error: the check that hit it has no verdict, and nothing was signed.
|
|
82
|
+
*/
|
|
83
|
+
export declare class OtherChannelRefusedError extends CheckSetupError {
|
|
84
|
+
constructor(named: string, onlyChannel: string);
|
|
73
85
|
}
|
|
74
86
|
/** Signs `amount` for this challenge's channel and serialises the credential. */
|
|
75
87
|
export declare function buildChannelCredential(parameters: BuildChannelCredentialParams): Promise<{
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
* amounts, so they assemble credentials directly.
|
|
10
10
|
*/
|
|
11
11
|
import { Challenge, Credential } from "mppx";
|
|
12
|
-
import { MalformedResponseError, fetchTarget } from "../errors.js";
|
|
12
|
+
import { CheckSetupError, MalformedResponseError, fetchTarget } from "../errors.js";
|
|
13
|
+
import { shown } from "../guard/budget.js";
|
|
13
14
|
import { signChannelCommitment } from "./channel-commitment.js";
|
|
14
15
|
import { networkPassphrase, resolveRpcUrl } from "./network.js";
|
|
15
16
|
import { assertPaymentNetworkAllowed } from "../guard/networks.js";
|
|
@@ -104,11 +105,26 @@ export function serializeChannelCredential(parameters) {
|
|
|
104
105
|
payload: { action, amount: amount.toString(), signature },
|
|
105
106
|
}));
|
|
106
107
|
}
|
|
108
|
+
/**
|
|
109
|
+
* A challenge names another channel than the one the run signs for. A setup
|
|
110
|
+
* error: the check that hit it has no verdict, and nothing was signed.
|
|
111
|
+
*/
|
|
112
|
+
export class OtherChannelRefusedError extends CheckSetupError {
|
|
113
|
+
constructor(named, onlyChannel) {
|
|
114
|
+
super(`The route's challenge names the channel ${shown(named)}, and this run signs commitments for its ` +
|
|
115
|
+
`configured channel ${onlyChannel} only. Nothing was signed.`);
|
|
116
|
+
this.name = "OtherChannelRefusedError";
|
|
117
|
+
}
|
|
118
|
+
}
|
|
107
119
|
/** Signs `amount` for this challenge's channel and serialises the credential. */
|
|
108
120
|
export async function buildChannelCredential(parameters) {
|
|
109
|
-
const { challenge, amount, commitmentSecretHex, network, rpcUrl, action } = parameters;
|
|
121
|
+
const { challenge, amount, commitmentSecretHex, network, rpcUrl, action, onlyChannel } = parameters;
|
|
110
122
|
// L0 at the signature itself, whoever calls it.
|
|
111
123
|
assertPaymentNetworkAllowed("mpp-channel", network);
|
|
124
|
+
// The channel, at the signature too: the service may name another one in any fresh challenge.
|
|
125
|
+
if (onlyChannel !== undefined && challenge.channelContract !== onlyChannel) {
|
|
126
|
+
throw new OtherChannelRefusedError(challenge.channelContract, onlyChannel);
|
|
127
|
+
}
|
|
112
128
|
const signature = await signChannelCommitment({
|
|
113
129
|
channelContract: challenge.channelContract,
|
|
114
130
|
amount,
|
package/dist/mpp/channel.d.ts
CHANGED
|
@@ -26,6 +26,12 @@ export interface MppChannelCheckOptions {
|
|
|
26
26
|
network: string;
|
|
27
27
|
/** Overrides the default RPC endpoint for the network. */
|
|
28
28
|
rpcUrl?: string;
|
|
29
|
+
/**
|
|
30
|
+
* The only channel a commitment is signed for (`wasit run`: the config's
|
|
31
|
+
* `channel`). A fresh challenge that names another gets no signature, and the
|
|
32
|
+
* check has no verdict.
|
|
33
|
+
*/
|
|
34
|
+
onlyChannel?: string;
|
|
29
35
|
}
|
|
30
36
|
/**
|
|
31
37
|
* Explains a replay that did not get HTTP 402.
|
package/dist/mpp/channel.js
CHANGED
|
@@ -100,7 +100,7 @@ const SETUP_ATTEMPTS = 3;
|
|
|
100
100
|
* @throws {CheckSetupError} No attempt was accepted, so the check has no verdict.
|
|
101
101
|
*/
|
|
102
102
|
async function advanceCumulative(options) {
|
|
103
|
-
const { target, commitmentSecretHex, network, rpcUrl } = options;
|
|
103
|
+
const { target, commitmentSecretHex, network, rpcUrl, onlyChannel } = options;
|
|
104
104
|
const refusals = [];
|
|
105
105
|
for (let attempt = 1; attempt <= SETUP_ATTEMPTS; attempt += 1) {
|
|
106
106
|
const challenge = await fetchChannelChallenge(target);
|
|
@@ -111,6 +111,7 @@ async function advanceCumulative(options) {
|
|
|
111
111
|
commitmentSecretHex,
|
|
112
112
|
network,
|
|
113
113
|
rpcUrl,
|
|
114
|
+
...(onlyChannel === undefined ? {} : { onlyChannel }),
|
|
114
115
|
});
|
|
115
116
|
const submission = await submitCredential(target, credential);
|
|
116
117
|
if (submission.status === 200)
|
|
@@ -142,7 +143,7 @@ async function advanceCumulative(options) {
|
|
|
142
143
|
export async function runMppChannelOrderingCheck(options) {
|
|
143
144
|
const id = "MPP-11";
|
|
144
145
|
const name = "Cumulative Commitment Ordering";
|
|
145
|
-
const { target, commitmentSecretHex, network, rpcUrl } = options;
|
|
146
|
+
const { target, commitmentSecretHex, network, rpcUrl, onlyChannel } = options;
|
|
146
147
|
const refused = refusedNetwork(id, name, network);
|
|
147
148
|
if (refused)
|
|
148
149
|
return refused;
|
|
@@ -156,6 +157,7 @@ export async function runMppChannelOrderingCheck(options) {
|
|
|
156
157
|
commitmentSecretHex,
|
|
157
158
|
network,
|
|
158
159
|
rpcUrl,
|
|
160
|
+
...(onlyChannel === undefined ? {} : { onlyChannel }),
|
|
159
161
|
})).credential);
|
|
160
162
|
if (equal.status !== 402) {
|
|
161
163
|
return failure(id, name, `A commitment equal to the current cumulative (${baseline}) was not rejected — ` +
|
|
@@ -183,6 +185,7 @@ export async function runMppChannelOrderingCheck(options) {
|
|
|
183
185
|
commitmentSecretHex,
|
|
184
186
|
network,
|
|
185
187
|
rpcUrl,
|
|
188
|
+
...(onlyChannel === undefined ? {} : { onlyChannel }),
|
|
186
189
|
})).credential);
|
|
187
190
|
if (short.status !== 402) {
|
|
188
191
|
return failure(id, name, `A commitment that advances but under-covers the request price ` +
|
|
@@ -287,7 +290,7 @@ function sleep(ms) {
|
|
|
287
290
|
export async function runMppChannelCloseCheck(options) {
|
|
288
291
|
const id = "MPP-13";
|
|
289
292
|
const name = "Close Settlement";
|
|
290
|
-
const { target, commitmentSecretHex, network, rpcUrl, expectedChannel, allowDestructive = false, closePollAttempts = 6, closePollDelayMs = 2_000, } = options;
|
|
293
|
+
const { target, commitmentSecretHex, network, rpcUrl, onlyChannel, expectedChannel, allowDestructive = false, closePollAttempts = 6, closePollDelayMs = 2_000, } = options;
|
|
291
294
|
// Before the destructive switch is even looked at: a close on a network
|
|
292
295
|
// that is not a test network is refused, enabled or not.
|
|
293
296
|
const refused = refusedNetwork(id, name, network);
|
|
@@ -334,6 +337,7 @@ export async function runMppChannelCloseCheck(options) {
|
|
|
334
337
|
network,
|
|
335
338
|
rpcUrl,
|
|
336
339
|
action: "close",
|
|
340
|
+
...(onlyChannel === undefined ? {} : { onlyChannel }),
|
|
337
341
|
});
|
|
338
342
|
const closed = await submitCredential(target, credential);
|
|
339
343
|
if (closed.status !== 200) {
|