mppx 0.21.0 → 0.21.2
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/CHANGELOG.md +19 -0
- package/dist/Errors.d.ts +55 -0
- package/dist/Errors.js +48 -0
- package/dist/Html.d.ts +1 -1
- package/dist/Html.js +2 -2
- package/dist/Method.d.ts +1 -1
- package/dist/cli/cli.js +138 -138
- package/dist/cli/internal.js +1 -1
- package/dist/cli/plugins/evm.js +1 -1
- package/dist/cli/plugins/index.js +13 -13
- package/dist/cli/plugins/x402.js +1 -1
- package/dist/cli/utils.d.ts +2 -45
- package/dist/cli/utils.js +2 -79
- package/dist/cli/validate/index.js +5 -2
- package/dist/cli/validate/payment.d.ts +1 -1
- package/dist/cli/validate/payment.js +3 -3
- package/dist/cli/validate/print.d.ts +12 -0
- package/dist/cli/validate/print.js +35 -0
- package/dist/client/core.d.ts +6 -0
- package/dist/client/core.js +6 -0
- package/dist/client/index.d.ts +2 -8
- package/dist/client/index.js +2 -6
- package/dist/client/internal/protocols/Shared.js +1 -1
- package/dist/client/internal/protocols/X402.js +3 -3
- package/dist/evm/client/Charge.js +1 -1
- package/dist/evm/index.d.ts +1 -1
- package/dist/evm/server/Charge.js +1 -1
- package/dist/integrations/x402/Evm.js +1 -1
- package/dist/integrations/x402/Negotiator.js +1 -1
- package/dist/internal/AcceptPayment.js +1 -1
- package/dist/internal/CredentialExpiry.js +1 -1
- package/dist/{mcp/internal/Credential.d.ts → internal/McpCredential.d.ts} +2 -2
- package/dist/{mcp/internal/Credential.js → internal/McpCredential.js} +2 -2
- package/dist/{server/internal → internal}/challengeMeta.js +1 -1
- package/dist/{server/internal → internal}/html/config.d.ts +2 -2
- package/dist/internal/pc.d.ts +46 -0
- package/dist/internal/pc.js +80 -0
- package/dist/internal/version.d.ts +2 -2
- package/dist/internal/version.js +1 -1
- package/dist/{x402 → internal/x402}/Header.js +1 -1
- package/dist/{x402 → internal/x402}/Siwx.d.ts +2 -2
- package/dist/{x402 → internal/x402}/Siwx.js +2 -2
- package/dist/{x402 → internal/x402}/Types.d.ts +1 -1
- package/dist/{x402 → internal/x402}/Types.js +1 -1
- package/dist/mcp/server/index.d.ts +1 -1
- package/dist/mcp/server/index.js +1 -1
- package/dist/server/Mppx.d.ts +1 -1
- package/dist/server/Mppx.js +6 -6
- package/dist/server/Transport.d.ts +2 -2
- package/dist/server/Transport.js +4 -4
- package/dist/server/index.d.ts +1 -8
- package/dist/server/index.js +1 -8
- package/dist/{mcp/server/Transport.d.ts → server/internal/mcpSdk.d.ts} +2 -2
- package/dist/{mcp/server/Transport.js → server/internal/mcpSdk.js} +3 -3
- package/dist/stripe/server/Charge.d.ts +1 -1
- package/dist/stripe/server/internal/html.gen.js +1 -1
- package/dist/tempo/Methods.d.ts +3 -0
- package/dist/tempo/Methods.js +3 -1
- package/dist/tempo/client/Charge.js +1 -1
- package/dist/tempo/client/Methods.d.ts +3 -0
- package/dist/tempo/client/index.d.ts +3 -0
- package/dist/tempo/client/index.js +1 -0
- package/dist/tempo/internal/configurable-account.d.ts +26 -0
- package/dist/tempo/internal/configurable-account.js +77 -0
- package/dist/tempo/internal/signature.d.ts +15 -0
- package/dist/tempo/internal/signature.js +43 -0
- package/dist/tempo/server/Charge.d.ts +1 -1
- package/dist/tempo/server/Charge.js +1 -1
- package/dist/tempo/server/Methods.d.ts +139 -4
- package/dist/tempo/server/internal/html.gen.js +1 -1
- package/dist/tempo/session/client/ChannelOps.d.ts +29 -0
- package/dist/tempo/session/client/ChannelOps.js +108 -3
- package/dist/tempo/session/client/CredentialState.d.ts +6 -0
- package/dist/tempo/session/client/CredentialState.js +29 -4
- package/dist/tempo/session/client/Session.d.ts +3 -0
- package/dist/tempo/session/client/SessionManager.js +4 -0
- package/dist/tempo/session/precompile/Chain.d.ts +35 -1
- package/dist/tempo/session/precompile/Chain.js +52 -0
- package/dist/tempo/session/precompile/Voucher.d.ts +46 -5
- package/dist/tempo/session/precompile/Voucher.js +78 -29
- package/dist/tempo/session/precompile/escrow.abi.d.ts +79 -0
- package/dist/tempo/session/precompile/escrow.abi.js +38 -0
- package/dist/tempo/session/server/ChannelStore.d.ts +27 -0
- package/dist/tempo/session/server/ChannelStore.js +24 -3
- package/dist/tempo/session/server/CredentialVerification.d.ts +7 -1
- package/dist/tempo/session/server/CredentialVerification.js +91 -12
- package/dist/tempo/session/server/RequestState.d.ts +2 -0
- package/dist/tempo/session/server/RequestState.js +1 -0
- package/dist/tempo/session/server/Session.d.ts +11 -0
- package/dist/tempo/session/server/Session.js +10 -2
- package/dist/tempo/session/server/SponsorshipLimit.d.ts +11 -3
- package/dist/tempo/session/server/SponsorshipLimit.js +36 -4
- package/dist/tempo/subscription/KeyAuthorization.js +6 -2
- package/dist/{cli/validate → validation}/challenge.d.ts +1 -1
- package/dist/{cli/validate → validation}/challenge.js +4 -4
- package/dist/validation/core.d.ts +29 -2
- package/dist/validation/core.js +41 -10
- package/dist/{cli/validate → validation}/helpers.d.ts +0 -10
- package/dist/{cli/validate → validation}/helpers.js +1 -35
- package/dist/validation/index.d.ts +2 -2
- package/dist/validation/index.js +1 -1
- package/dist/x402/Assets.d.ts +1 -1
- package/dist/x402/client/Exact.d.ts +1 -1
- package/dist/x402/client/Exact.js +2 -2
- package/dist/x402/index.d.ts +4 -4
- package/dist/x402/index.js +4 -4
- package/dist/x402/internal/RouteBinding.d.ts +1 -1
- package/dist/x402/mcp.js +2 -2
- package/dist/x402/server/EvmCharge.d.ts +2 -2
- package/dist/x402/server/EvmCharge.js +4 -4
- package/dist/x402/server/Facilitator.d.ts +1 -1
- package/dist/x402/server/Facilitator.js +1 -1
- package/dist/x402/tempo.d.ts +48 -0
- package/dist/x402/tempo.js +68 -0
- package/package.json +21 -1
- /package/dist/{server/internal → internal}/challengeMeta.d.ts +0 -0
- /package/dist/{server/internal → internal}/html/compose.main.gen.d.ts +0 -0
- /package/dist/{server/internal → internal}/html/compose.main.gen.js +0 -0
- /package/dist/{server/internal → internal}/html/config.js +0 -0
- /package/dist/{server/internal → internal}/html/constants.d.ts +0 -0
- /package/dist/{server/internal → internal}/html/constants.js +0 -0
- /package/dist/{server/internal → internal}/html/serviceWorker.client.d.ts +0 -0
- /package/dist/{server/internal → internal}/html/serviceWorker.client.js +0 -0
- /package/dist/{server/internal → internal}/html/serviceWorker.gen.d.ts +0 -0
- /package/dist/{server/internal → internal}/html/serviceWorker.gen.js +0 -0
- /package/dist/{x402/internal → internal/x402}/ChallengeBrand.d.ts +0 -0
- /package/dist/{x402/internal → internal/x402}/ChallengeBrand.js +0 -0
- /package/dist/{x402 → internal/x402}/Header.d.ts +0 -0
- /package/dist/{cli/validate → validation}/discovery.d.ts +0 -0
- /package/dist/{cli/validate → validation}/discovery.js +0 -0
- /package/dist/{cli/validate → validation}/messages.d.ts +0 -0
- /package/dist/{cli/validate → validation}/messages.js +0 -0
|
@@ -3,6 +3,8 @@ import { hashTypedData } from 'viem';
|
|
|
3
3
|
import { signTypedData } from 'viem/actions';
|
|
4
4
|
import { Account as TempoAccount } from 'viem/tempo';
|
|
5
5
|
import * as TempoAddress from '../../internal/address.js';
|
|
6
|
+
import * as ConfigurableAccount from '../../internal/configurable-account.js';
|
|
7
|
+
import { isLowS, toLowS } from '../../internal/signature.js';
|
|
6
8
|
import { uint96 } from './Protocol.js';
|
|
7
9
|
/** Must match the on-chain TIP-20 channel reserve DOMAIN_SEPARATOR name. */
|
|
8
10
|
const DOMAIN_NAME = 'TIP20 Channel Reserve';
|
|
@@ -64,8 +66,49 @@ function getVoucherPayload(verifyingContract, chainId, voucher) {
|
|
|
64
66
|
},
|
|
65
67
|
});
|
|
66
68
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
+
/**
|
|
70
|
+
* Verifies a canonical serialized signature against one expected signer under the TIP-1034 and
|
|
71
|
+
* TIP-1166 rules. Keychain signatures are always rejected.
|
|
72
|
+
*/
|
|
73
|
+
function verifySignerSignature(signature, payload, expectedSigner, options) {
|
|
74
|
+
const envelope = parseCanonicalEnvelope(signature);
|
|
75
|
+
if (!envelope)
|
|
76
|
+
return false;
|
|
77
|
+
return verifySignerEnvelope(envelope, payload, expectedSigner, options);
|
|
78
|
+
}
|
|
79
|
+
/** Parses a serialized signature envelope, or returns undefined unless it is canonical. */
|
|
80
|
+
function parseCanonicalEnvelope(signature) {
|
|
81
|
+
const envelope = SignatureEnvelope.from(signature);
|
|
82
|
+
if (SignatureEnvelope.serialize(envelope).toLowerCase() !== signature.toLowerCase())
|
|
83
|
+
return undefined;
|
|
84
|
+
return envelope;
|
|
85
|
+
}
|
|
86
|
+
/** Verifies a parsed canonical signature envelope against one expected signer. */
|
|
87
|
+
function verifySignerEnvelope(envelope, payload, expectedSigner, options) {
|
|
88
|
+
if (envelope.type === 'configurable') {
|
|
89
|
+
if (!options.configurable)
|
|
90
|
+
return false;
|
|
91
|
+
return ConfigurableAccount.verify(envelope, {
|
|
92
|
+
account: expectedSigner,
|
|
93
|
+
commitment: options.openingCommitment,
|
|
94
|
+
payload,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
if (!ConfigurableAccount.isPrimitiveEnvelope(envelope.type))
|
|
98
|
+
return false;
|
|
99
|
+
// Tempo settlement rejects high-s signatures, so a voucher carrying one could never be collected.
|
|
100
|
+
if (!isLowS(envelope))
|
|
101
|
+
return false;
|
|
102
|
+
// A channel whose signer had a config commitment at open accepts only that config's approvals.
|
|
103
|
+
if (!ConfigurableAccount.isZeroCommitment(options.openingCommitment))
|
|
104
|
+
return false;
|
|
105
|
+
const signer = SignatureEnvelope.extractAddress({ payload, signature: envelope });
|
|
106
|
+
const valid = SignatureEnvelope.verify(envelope, { address: signer, payload });
|
|
107
|
+
return valid && TempoAddress.isEqual(signer, expectedSigner);
|
|
108
|
+
}
|
|
109
|
+
/** Returns whether an account signs with a TIP-1166 configurable account (`0x05`) signature. */
|
|
110
|
+
export function isConfigurableAccount(account) {
|
|
111
|
+
return account.source === 'configurable';
|
|
69
112
|
}
|
|
70
113
|
/** Detects a viem/tempo access key account the same way `Account.signVoucher` does. */
|
|
71
114
|
function isAccessKeyAccount(account) {
|
|
@@ -105,9 +148,9 @@ export async function signVoucher(client, account, voucher, verifyingContract, c
|
|
|
105
148
|
});
|
|
106
149
|
})();
|
|
107
150
|
const envelope = SignatureEnvelope.from(signature);
|
|
108
|
-
if (!isPrimitiveEnvelope(envelope.type))
|
|
109
|
-
throw new Error(`TIP-1034 vouchers require a TIP-1020 primitive signature; received "${envelope.type}".`);
|
|
110
|
-
return SignatureEnvelope.serialize(envelope);
|
|
151
|
+
if (!ConfigurableAccount.isPrimitiveEnvelope(envelope.type) && envelope.type !== 'configurable')
|
|
152
|
+
throw new Error(`TIP-1034 vouchers require a TIP-1020 primitive or TIP-1166 configurable account signature; received "${envelope.type}".`);
|
|
153
|
+
return SignatureEnvelope.serialize(toLowS(envelope));
|
|
111
154
|
}
|
|
112
155
|
/**
|
|
113
156
|
* Signs a distinct EIP-712 authorization for cooperatively closing a channel.
|
|
@@ -130,22 +173,29 @@ export async function signCloseAuthorization(client, account, authorization, ver
|
|
|
130
173
|
message: authorization,
|
|
131
174
|
});
|
|
132
175
|
const envelope = SignatureEnvelope.from(signature);
|
|
133
|
-
if (!isPrimitiveEnvelope(envelope.type))
|
|
134
|
-
throw new Error(`TIP-1034 close authorizations require a TIP-1020 primitive signature; received "${envelope.type}".`);
|
|
135
|
-
return SignatureEnvelope.serialize(envelope);
|
|
176
|
+
if (!ConfigurableAccount.isPrimitiveEnvelope(envelope.type) && envelope.type !== 'configurable')
|
|
177
|
+
throw new Error(`TIP-1034 close authorizations require a TIP-1020 primitive or TIP-1166 configurable account signature; received "${envelope.type}".`);
|
|
178
|
+
return SignatureEnvelope.serialize(toLowS(envelope));
|
|
136
179
|
}
|
|
137
|
-
/**
|
|
138
|
-
|
|
180
|
+
/**
|
|
181
|
+
* Verifies that a cooperative-close signature belongs to a channel authority.
|
|
182
|
+
*
|
|
183
|
+
* `options` applies the TIP-1166 configurable account rules of {@link verifyVoucher}; the
|
|
184
|
+
* defaults accept only TIP-1020 primitive signatures.
|
|
185
|
+
*/
|
|
186
|
+
export function verifyCloseAuthorization(escrowContract, chainId, authorization, expectedSigners, options = {}) {
|
|
139
187
|
try {
|
|
140
|
-
const envelope = SignatureEnvelope.from(authorization.signature);
|
|
141
|
-
if (!isPrimitiveEnvelope(envelope.type))
|
|
142
|
-
return false;
|
|
143
|
-
if (SignatureEnvelope.serialize(envelope).toLowerCase() !== authorization.signature.toLowerCase())
|
|
144
|
-
return false;
|
|
145
188
|
const payload = getCloseAuthorizationPayload(escrowContract, chainId, authorization);
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
|
|
189
|
+
const { voucherSigner, ...voucherOptions } = options;
|
|
190
|
+
// Parse once: every candidate checks the same envelope.
|
|
191
|
+
const envelope = parseCanonicalEnvelope(authorization.signature);
|
|
192
|
+
if (!envelope)
|
|
193
|
+
return false;
|
|
194
|
+
return expectedSigners.some((expected) => verifySignerEnvelope(envelope, payload, expected,
|
|
195
|
+
// The opening commitment binds only the voucher signer's config. Another candidate's
|
|
196
|
+
// configurable signature could only be checked against its version-zero config, which a
|
|
197
|
+
// later rotation supersedes, so it is rejected.
|
|
198
|
+
!voucherSigner || TempoAddress.isEqual(expected, voucherSigner) ? voucherOptions : {}));
|
|
149
199
|
}
|
|
150
200
|
catch {
|
|
151
201
|
return false;
|
|
@@ -154,20 +204,19 @@ export function verifyCloseAuthorization(escrowContract, chainId, authorization,
|
|
|
154
204
|
/**
|
|
155
205
|
* Verify a voucher signature matches the expected signer.
|
|
156
206
|
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
207
|
+
* By default, accepts canonical TIP-1020 primitive signatures only. Keychain wrappers,
|
|
208
|
+
* configurable account signatures, and magic-suffixed encodings are rejected.
|
|
209
|
+
*
|
|
210
|
+
* With `options.configurable`, also applies TIP-1166: a configurable account (`0x05`)
|
|
211
|
+
* signature is accepted when it names `expectedSigner`, its owner approvals reach the
|
|
212
|
+
* threshold, and its config commitment equals `options.openingCommitment` or, when the channel
|
|
213
|
+
* has no opening commitment, its config is the version-zero config that derives `expectedSigner`. A
|
|
214
|
+
* nonzero `openingCommitment` rejects primitive signatures.
|
|
159
215
|
*/
|
|
160
|
-
export function verifyVoucher(escrowContract, chainId, voucher, expectedSigner) {
|
|
216
|
+
export function verifyVoucher(escrowContract, chainId, voucher, expectedSigner, options = {}) {
|
|
161
217
|
try {
|
|
162
|
-
const envelope = SignatureEnvelope.from(voucher.signature);
|
|
163
|
-
if (!isPrimitiveEnvelope(envelope.type))
|
|
164
|
-
return false;
|
|
165
|
-
if (SignatureEnvelope.serialize(envelope).toLowerCase() !== voucher.signature.toLowerCase())
|
|
166
|
-
return false;
|
|
167
218
|
const payload = getVoucherPayload(escrowContract, chainId, voucher);
|
|
168
|
-
|
|
169
|
-
const valid = SignatureEnvelope.verify(envelope, { address: signer, payload });
|
|
170
|
-
return valid && TempoAddress.isEqual(signer, expectedSigner);
|
|
219
|
+
return verifySignerSignature(voucher.signature, payload, expectedSigner, options);
|
|
171
220
|
}
|
|
172
221
|
catch {
|
|
173
222
|
return false;
|
|
@@ -372,6 +372,46 @@ export declare const escrowAbi: readonly [{
|
|
|
372
372
|
readonly outputs: readonly [{
|
|
373
373
|
readonly type: 'bytes32';
|
|
374
374
|
}];
|
|
375
|
+
}, {
|
|
376
|
+
readonly type: 'function';
|
|
377
|
+
readonly name: 'verifyVoucher';
|
|
378
|
+
readonly stateMutability: 'view';
|
|
379
|
+
readonly inputs: readonly [{
|
|
380
|
+
readonly name: 'descriptor';
|
|
381
|
+
readonly type: 'tuple';
|
|
382
|
+
readonly components: readonly [{
|
|
383
|
+
readonly name: 'payer';
|
|
384
|
+
readonly type: 'address';
|
|
385
|
+
}, {
|
|
386
|
+
readonly name: 'payee';
|
|
387
|
+
readonly type: 'address';
|
|
388
|
+
}, {
|
|
389
|
+
readonly name: 'operator';
|
|
390
|
+
readonly type: 'address';
|
|
391
|
+
}, {
|
|
392
|
+
readonly name: 'token';
|
|
393
|
+
readonly type: 'address';
|
|
394
|
+
}, {
|
|
395
|
+
readonly name: 'salt';
|
|
396
|
+
readonly type: 'bytes32';
|
|
397
|
+
}, {
|
|
398
|
+
readonly name: 'authorizedSigner';
|
|
399
|
+
readonly type: 'address';
|
|
400
|
+
}, {
|
|
401
|
+
readonly name: 'expiringNonceHash';
|
|
402
|
+
readonly type: 'bytes32';
|
|
403
|
+
}];
|
|
404
|
+
}, {
|
|
405
|
+
readonly name: 'cumulativeAmount';
|
|
406
|
+
readonly type: 'uint96';
|
|
407
|
+
}, {
|
|
408
|
+
readonly name: 'signature';
|
|
409
|
+
readonly type: 'bytes';
|
|
410
|
+
}];
|
|
411
|
+
readonly outputs: readonly [{
|
|
412
|
+
readonly name: 'valid';
|
|
413
|
+
readonly type: 'bool';
|
|
414
|
+
}];
|
|
375
415
|
}, {
|
|
376
416
|
readonly type: 'function';
|
|
377
417
|
readonly name: 'domainSeparator';
|
|
@@ -414,6 +454,21 @@ export declare const escrowAbi: readonly [{
|
|
|
414
454
|
readonly name: 'deposit';
|
|
415
455
|
readonly type: 'uint96';
|
|
416
456
|
}];
|
|
457
|
+
}, {
|
|
458
|
+
readonly type: 'event';
|
|
459
|
+
readonly name: 'OpeningCommitmentRecorded';
|
|
460
|
+
readonly inputs: readonly [{
|
|
461
|
+
readonly name: 'channelId';
|
|
462
|
+
readonly type: 'bytes32';
|
|
463
|
+
readonly indexed: true;
|
|
464
|
+
}, {
|
|
465
|
+
readonly name: 'signer';
|
|
466
|
+
readonly type: 'address';
|
|
467
|
+
readonly indexed: true;
|
|
468
|
+
}, {
|
|
469
|
+
readonly name: 'commitment';
|
|
470
|
+
readonly type: 'bytes32';
|
|
471
|
+
}];
|
|
417
472
|
}, {
|
|
418
473
|
readonly type: 'event';
|
|
419
474
|
readonly name: 'Settled';
|
|
@@ -518,5 +573,29 @@ export declare const escrowAbi: readonly [{
|
|
|
518
573
|
readonly type: 'address';
|
|
519
574
|
readonly indexed: true;
|
|
520
575
|
}];
|
|
576
|
+
}, {
|
|
577
|
+
readonly type: 'error';
|
|
578
|
+
readonly name: 'RootKeyRetired';
|
|
579
|
+
readonly inputs: readonly [{
|
|
580
|
+
readonly name: 'account';
|
|
581
|
+
readonly type: 'address';
|
|
582
|
+
}];
|
|
583
|
+
}, {
|
|
584
|
+
readonly type: 'error';
|
|
585
|
+
readonly name: 'SignerConfigChanged';
|
|
586
|
+
readonly inputs: readonly [{
|
|
587
|
+
readonly name: 'signer';
|
|
588
|
+
readonly type: 'address';
|
|
589
|
+
}];
|
|
590
|
+
}, {
|
|
591
|
+
readonly type: 'error';
|
|
592
|
+
readonly name: 'SaltNotSignerCommitment';
|
|
593
|
+
readonly inputs: readonly [{
|
|
594
|
+
readonly name: 'signer';
|
|
595
|
+
readonly type: 'address';
|
|
596
|
+
}, {
|
|
597
|
+
readonly name: 'commitment';
|
|
598
|
+
readonly type: 'bytes32';
|
|
599
|
+
}];
|
|
521
600
|
}];
|
|
522
601
|
//# sourceMappingURL=escrow.abi.d.ts.map
|
|
@@ -145,6 +145,17 @@ export const escrowAbi = [
|
|
|
145
145
|
],
|
|
146
146
|
outputs: [{ type: 'bytes32' }],
|
|
147
147
|
},
|
|
148
|
+
{
|
|
149
|
+
type: 'function',
|
|
150
|
+
name: 'verifyVoucher',
|
|
151
|
+
stateMutability: 'view',
|
|
152
|
+
inputs: [
|
|
153
|
+
channelDescriptorInput,
|
|
154
|
+
{ name: 'cumulativeAmount', type: 'uint96' },
|
|
155
|
+
{ name: 'signature', type: 'bytes' },
|
|
156
|
+
],
|
|
157
|
+
outputs: [{ name: 'valid', type: 'bool' }],
|
|
158
|
+
},
|
|
148
159
|
{
|
|
149
160
|
type: 'function',
|
|
150
161
|
name: 'domainSeparator',
|
|
@@ -167,6 +178,15 @@ export const escrowAbi = [
|
|
|
167
178
|
{ name: 'deposit', type: 'uint96' },
|
|
168
179
|
],
|
|
169
180
|
},
|
|
181
|
+
{
|
|
182
|
+
type: 'event',
|
|
183
|
+
name: 'OpeningCommitmentRecorded',
|
|
184
|
+
inputs: [
|
|
185
|
+
{ name: 'channelId', type: 'bytes32', indexed: true },
|
|
186
|
+
{ name: 'signer', type: 'address', indexed: true },
|
|
187
|
+
{ name: 'commitment', type: 'bytes32' },
|
|
188
|
+
],
|
|
189
|
+
},
|
|
170
190
|
{
|
|
171
191
|
type: 'event',
|
|
172
192
|
name: 'Settled',
|
|
@@ -220,5 +240,23 @@ export const escrowAbi = [
|
|
|
220
240
|
{ name: 'payee', type: 'address', indexed: true },
|
|
221
241
|
],
|
|
222
242
|
},
|
|
243
|
+
{
|
|
244
|
+
type: 'error',
|
|
245
|
+
name: 'RootKeyRetired',
|
|
246
|
+
inputs: [{ name: 'account', type: 'address' }],
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
type: 'error',
|
|
250
|
+
name: 'SignerConfigChanged',
|
|
251
|
+
inputs: [{ name: 'signer', type: 'address' }],
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
type: 'error',
|
|
255
|
+
name: 'SaltNotSignerCommitment',
|
|
256
|
+
inputs: [
|
|
257
|
+
{ name: 'signer', type: 'address' },
|
|
258
|
+
{ name: 'commitment', type: 'bytes32' },
|
|
259
|
+
],
|
|
260
|
+
},
|
|
223
261
|
];
|
|
224
262
|
//# sourceMappingURL=escrow.abi.js.map
|
|
@@ -6,6 +6,7 @@ import type * as Chain from '../precompile/Chain.js';
|
|
|
6
6
|
import type * as PrecompileChannel from '../precompile/Channel.js';
|
|
7
7
|
import type { SessionReceipt, SessionSignedVoucher } from '../precompile/Protocol.js';
|
|
8
8
|
import { type SignedVoucher } from '../precompile/Protocol.js';
|
|
9
|
+
import * as Voucher from '../precompile/Voucher.js';
|
|
9
10
|
import type { SessionMethodDetails } from './RequestState.js';
|
|
10
11
|
/**
|
|
11
12
|
* State for an on-chain payment channel, including per-session accounting.
|
|
@@ -91,6 +92,11 @@ export type OpenChannelStateParameters = {
|
|
|
91
92
|
escrow: Address;
|
|
92
93
|
/** Transaction-bound expiring nonce hash from the open call. */
|
|
93
94
|
expiringNonceHash: Hex;
|
|
95
|
+
/**
|
|
96
|
+
* TIP-1166 signer config commitment the escrow recorded at open (`OpeningCommitmentRecorded`).
|
|
97
|
+
* Omitted when the signer had no config commitment.
|
|
98
|
+
*/
|
|
99
|
+
openingCommitment?: Hex | undefined;
|
|
94
100
|
/** Initial or highest accepted cumulative voucher amount. */
|
|
95
101
|
cumulativeAmount: bigint;
|
|
96
102
|
/** Voucher signature for `cumulativeAmount`. */
|
|
@@ -193,6 +199,12 @@ export type VerifyAndAcceptVoucherParameters = {
|
|
|
193
199
|
methodDetails: SessionMethodDetails;
|
|
194
200
|
/** Minimum allowed voucher delta in raw units. */
|
|
195
201
|
minVoucherDelta: bigint;
|
|
202
|
+
/**
|
|
203
|
+
* Whether to accept TIP-1166 configurable account (`0x05`) vouchers, checked against the
|
|
204
|
+
* channel's `openingCommitment`.
|
|
205
|
+
* @default false
|
|
206
|
+
*/
|
|
207
|
+
configurableVouchers?: boolean | undefined;
|
|
196
208
|
/** Whether this presentation must advance the accepted voucher. */
|
|
197
209
|
requireAdvance?: boolean | undefined;
|
|
198
210
|
/** Server channel store. */
|
|
@@ -234,6 +246,11 @@ export interface PrecompileBackendState {
|
|
|
234
246
|
operator: Address;
|
|
235
247
|
/** Salt used to derive the channel's identity. */
|
|
236
248
|
salt: Hex;
|
|
249
|
+
/**
|
|
250
|
+
* TIP-1166 signer config commitment the escrow recorded at open. Missing (as in records stored
|
|
251
|
+
* before TIP-1166) means the signer had no config commitment, so the opening commitment is zero.
|
|
252
|
+
*/
|
|
253
|
+
openingCommitment?: Hex | undefined;
|
|
237
254
|
}
|
|
238
255
|
/** Common persisted state for every session channel backend. */
|
|
239
256
|
export interface BaseState {
|
|
@@ -416,6 +433,16 @@ export declare function reconcileExpiredPendingClose(parameters: {
|
|
|
416
433
|
export declare function markPendingClose(parameters: MarkPendingCloseParameters): PendingCloseUpdate;
|
|
417
434
|
/** Finalizes local channel state after a successful close transaction. */
|
|
418
435
|
export declare function finalizeClosedChannelState(parameters: FinalizeClosedChannelParameters): State | null;
|
|
436
|
+
/**
|
|
437
|
+
* Returns the TIP-1166 opening commitment stored for a precompile channel. Also reads the
|
|
438
|
+
* `signerSnapshot` key that state stored before it was renamed to `openingCommitment`.
|
|
439
|
+
*/
|
|
440
|
+
export declare function resolveOpeningCommitment(channel: State): Hex | undefined;
|
|
441
|
+
/**
|
|
442
|
+
* Resolves the TIP-1166 voucher verification options for a stored channel. Without
|
|
443
|
+
* `configurableVouchers`, only primitive voucher signatures are accepted, as before TIP-1166.
|
|
444
|
+
*/
|
|
445
|
+
export declare function resolveVoucherOptions(channel: State, configurableVouchers: boolean | undefined): Voucher.VerifyVoucherOptions;
|
|
419
446
|
/** Loads a precompile-backed channel or throws a verification error. */
|
|
420
447
|
export declare function loadPrecompileChannel(parameters: LoadPrecompileChannelParameters): Promise<StoredPrecompileChannel>;
|
|
421
448
|
/** Verifies a cumulative voucher without changing persisted channel state. */
|
|
@@ -64,7 +64,7 @@ export function resolvePrecompileChannelIdentity(parameters) {
|
|
|
64
64
|
/** Builds the persisted state for a verified precompile channel open. */
|
|
65
65
|
export function openChannelState(parameters) {
|
|
66
66
|
const { authorizedSigner, chainId, channelId, current, descriptor, escrow, expiringNonceHash } = parameters;
|
|
67
|
-
const { state } = parameters;
|
|
67
|
+
const { openingCommitment, state } = parameters;
|
|
68
68
|
const { cumulativeAmount, signature } = parameters;
|
|
69
69
|
const highestVoucher = resolveHighestVoucher({
|
|
70
70
|
channelId,
|
|
@@ -83,6 +83,7 @@ export function openChannelState(parameters) {
|
|
|
83
83
|
escrow,
|
|
84
84
|
expiringNonceHash,
|
|
85
85
|
}),
|
|
86
|
+
...(openingCommitment ? { openingCommitment } : {}),
|
|
86
87
|
closeRequestedAt: onChain.closeRequestedAt,
|
|
87
88
|
deposit: onChain.deposit,
|
|
88
89
|
settledOnChain: onChain.settledOnChain,
|
|
@@ -302,6 +303,26 @@ export function finalizeClosedChannelState(parameters) {
|
|
|
302
303
|
highestVoucher: highestVoucher.highestVoucher,
|
|
303
304
|
};
|
|
304
305
|
}
|
|
306
|
+
/**
|
|
307
|
+
* Returns the TIP-1166 opening commitment stored for a precompile channel. Also reads the
|
|
308
|
+
* `signerSnapshot` key that state stored before it was renamed to `openingCommitment`.
|
|
309
|
+
*/
|
|
310
|
+
export function resolveOpeningCommitment(channel) {
|
|
311
|
+
if (!isPrecompileState(channel))
|
|
312
|
+
return undefined;
|
|
313
|
+
return (channel.openingCommitment ?? channel.signerSnapshot);
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Resolves the TIP-1166 voucher verification options for a stored channel. Without
|
|
317
|
+
* `configurableVouchers`, only primitive voucher signatures are accepted, as before TIP-1166.
|
|
318
|
+
*/
|
|
319
|
+
export function resolveVoucherOptions(channel, configurableVouchers) {
|
|
320
|
+
const openingCommitment = resolveOpeningCommitment(channel);
|
|
321
|
+
return {
|
|
322
|
+
...(configurableVouchers ? { configurable: true } : {}),
|
|
323
|
+
...(openingCommitment ? { openingCommitment } : {}),
|
|
324
|
+
};
|
|
325
|
+
}
|
|
305
326
|
/** Loads a precompile-backed channel or throws a verification error. */
|
|
306
327
|
export async function loadPrecompileChannel(parameters) {
|
|
307
328
|
const { channelId, chainId, descriptor, escrow, store } = parameters;
|
|
@@ -317,7 +338,7 @@ export async function loadPrecompileChannel(parameters) {
|
|
|
317
338
|
}
|
|
318
339
|
/** Verifies a cumulative voucher without changing persisted channel state. */
|
|
319
340
|
export async function validateVoucher(parameters) {
|
|
320
|
-
const { minVoucherDelta, channel, voucher, channelState, methodDetails } = parameters;
|
|
341
|
+
const { configurableVouchers, minVoucherDelta, channel, voucher, channelState, methodDetails } = parameters;
|
|
321
342
|
validateChannelState(channelState);
|
|
322
343
|
if (voucher.cumulativeAmount > channelState.deposit)
|
|
323
344
|
throw new AmountExceedsDepositError({ reason: 'voucher amount exceeds on-chain deposit' });
|
|
@@ -325,7 +346,7 @@ export async function validateVoucher(parameters) {
|
|
|
325
346
|
throw new VerificationFailedError({
|
|
326
347
|
reason: 'voucher cumulativeAmount must be strictly greater than highest accepted voucher',
|
|
327
348
|
});
|
|
328
|
-
const valid = await Voucher.verifyVoucher(methodDetails.escrowContract, methodDetails.chainId, voucher, channel.authorizedSigner);
|
|
349
|
+
const valid = await Voucher.verifyVoucher(methodDetails.escrowContract, methodDetails.chainId, voucher, channel.authorizedSigner, resolveVoucherOptions(channel, configurableVouchers));
|
|
329
350
|
if (!valid)
|
|
330
351
|
throw new InvalidSignatureError({ reason: 'invalid voucher signature' });
|
|
331
352
|
if (voucher.cumulativeAmount <= channelState.settled)
|
|
@@ -73,6 +73,12 @@ export type BroadcastCredentialPayloadParameters = {
|
|
|
73
73
|
feePayerPolicy?: Partial<FeePayer.Policy> | undefined;
|
|
74
74
|
/** Optional fee token override for sponsored management and settlement transactions. */
|
|
75
75
|
feeToken?: Address | undefined;
|
|
76
|
+
/**
|
|
77
|
+
* Whether to accept TIP-1166 configurable account (`0x05`) vouchers and close authorizations.
|
|
78
|
+
* See `session.Parameters.configurableVouchers`.
|
|
79
|
+
* @default false
|
|
80
|
+
*/
|
|
81
|
+
configurableVouchers?: boolean | undefined;
|
|
76
82
|
/** Last successful on-chain refresh timestamp per channel ID. */
|
|
77
83
|
lastOnChainVerified: Map<Hex, number>;
|
|
78
84
|
/** Minimum allowed voucher delta in raw units. */
|
|
@@ -116,7 +122,7 @@ export type VoucherCredentialActionParameters = BroadcastCredentialActionParamet
|
|
|
116
122
|
/** Inputs for broadcasting and settling a cooperative close credential. */
|
|
117
123
|
export type CloseCredentialActionParameters = BroadcastCredentialActionParameters<'close'>;
|
|
118
124
|
/** Inputs for validating a session credential without applying its state transition. */
|
|
119
|
-
export type ValidateCredentialPayloadParameters = Pick<BroadcastCredentialPayloadParameters, 'account' | 'channelStateTtl' | 'chainId' | 'client' | 'credentialSource' | 'escrow' | 'expectedOperator' | 'feePayer' | 'feePayerPolicy' | 'feeToken' | 'lastOnChainVerified' | 'minVoucherDelta' | 'payload' | 'store' | 'challenge' | 'voucherStateMaxAge'> & {
|
|
125
|
+
export type ValidateCredentialPayloadParameters = Pick<BroadcastCredentialPayloadParameters, 'account' | 'channelStateTtl' | 'chainId' | 'client' | 'configurableVouchers' | 'credentialSource' | 'escrow' | 'expectedOperator' | 'feePayer' | 'feePayerPolicy' | 'feeToken' | 'lastOnChainVerified' | 'minVoucherDelta' | 'payload' | 'store' | 'challenge' | 'voucherStateMaxAge'> & {
|
|
120
126
|
/** Allows terminal broadcast to recover accepted funds before rejecting a pending close. */
|
|
121
127
|
allowPendingClose?: boolean | undefined;
|
|
122
128
|
};
|