mppx 0.5.11 → 0.5.12
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 +8 -0
- package/dist/cli/cli.d.ts.map +1 -1
- package/dist/cli/cli.js +41 -16
- package/dist/cli/cli.js.map +1 -1
- package/dist/cli/config.d.ts +6 -4
- package/dist/cli/config.d.ts.map +1 -1
- package/dist/cli/config.js.map +1 -1
- package/dist/cli/internal.d.ts +8 -0
- package/dist/cli/internal.d.ts.map +1 -1
- package/dist/cli/internal.js +33 -3
- package/dist/cli/internal.js.map +1 -1
- package/dist/cli/plugins/plugin.d.ts +2 -0
- package/dist/cli/plugins/plugin.d.ts.map +1 -1
- package/dist/cli/plugins/stripe.d.ts.map +1 -1
- package/dist/cli/plugins/stripe.js +3 -0
- package/dist/cli/plugins/stripe.js.map +1 -1
- package/dist/cli/plugins/tempo.d.ts.map +1 -1
- package/dist/cli/plugins/tempo.js +3 -0
- package/dist/cli/plugins/tempo.js.map +1 -1
- package/dist/client/Mppx.d.ts +10 -1
- package/dist/client/Mppx.d.ts.map +1 -1
- package/dist/client/Mppx.js +17 -5
- package/dist/client/Mppx.js.map +1 -1
- package/dist/client/Transport.d.ts +2 -0
- package/dist/client/Transport.d.ts.map +1 -1
- package/dist/client/Transport.js +11 -0
- package/dist/client/Transport.js.map +1 -1
- package/dist/client/internal/Fetch.d.ts +3 -0
- package/dist/client/internal/Fetch.d.ts.map +1 -1
- package/dist/client/internal/Fetch.js +65 -19
- package/dist/client/internal/Fetch.js.map +1 -1
- package/dist/internal/AcceptPayment.d.ts +72 -0
- package/dist/internal/AcceptPayment.d.ts.map +1 -0
- package/dist/internal/AcceptPayment.js +185 -0
- package/dist/internal/AcceptPayment.js.map +1 -0
- package/dist/mcp-sdk/client/McpClient.d.ts.map +1 -1
- package/dist/mcp-sdk/client/McpClient.js +8 -4
- package/dist/mcp-sdk/client/McpClient.js.map +1 -1
- package/dist/server/Mppx.d.ts +1 -1
- package/dist/server/Mppx.d.ts.map +1 -1
- package/dist/server/Mppx.js +33 -24
- package/dist/server/Mppx.js.map +1 -1
- package/dist/stripe/internal/constants.d.ts +8 -0
- package/dist/stripe/internal/constants.d.ts.map +1 -0
- package/dist/stripe/internal/constants.js +8 -0
- package/dist/stripe/internal/constants.js.map +1 -0
- package/dist/stripe/server/Charge.d.ts.map +1 -1
- package/dist/stripe/server/Charge.js +23 -5
- package/dist/stripe/server/Charge.js.map +1 -1
- package/dist/tempo/Proof.d.ts +12 -0
- package/dist/tempo/Proof.d.ts.map +1 -0
- package/dist/tempo/Proof.js +10 -0
- package/dist/tempo/Proof.js.map +1 -0
- package/dist/tempo/index.d.ts +1 -0
- package/dist/tempo/index.d.ts.map +1 -1
- package/dist/tempo/index.js +1 -0
- package/dist/tempo/index.js.map +1 -1
- package/dist/tempo/internal/fee-payer.d.ts.map +1 -1
- package/dist/tempo/internal/fee-payer.js +5 -1
- package/dist/tempo/internal/fee-payer.js.map +1 -1
- package/dist/tempo/server/Charge.d.ts.map +1 -1
- package/dist/tempo/server/Charge.js +62 -3
- package/dist/tempo/server/Charge.js.map +1 -1
- package/dist/tempo/server/internal/html.gen.d.ts +1 -1
- package/dist/tempo/server/internal/html.gen.d.ts.map +1 -1
- package/dist/tempo/server/internal/html.gen.js +1 -1
- package/dist/tempo/server/internal/html.gen.js.map +1 -1
- package/package.json +2 -2
- package/src/cli/cli.test.ts +278 -0
- package/src/cli/cli.ts +47 -16
- package/src/cli/config.ts +10 -4
- package/src/cli/internal.ts +59 -3
- package/src/cli/plugins/plugin.ts +3 -0
- package/src/cli/plugins/stripe.ts +3 -0
- package/src/cli/plugins/tempo.ts +3 -0
- package/src/client/Mppx.test-d.ts +33 -0
- package/src/client/Mppx.test.ts +130 -1
- package/src/client/Mppx.ts +35 -5
- package/src/client/Transport.test.ts +88 -55
- package/src/client/Transport.ts +13 -0
- package/src/client/internal/Fetch.browser.test.ts +16 -13
- package/src/client/internal/Fetch.test.ts +307 -10
- package/src/client/internal/Fetch.ts +85 -19
- package/src/internal/AcceptPayment.test.ts +211 -0
- package/src/internal/AcceptPayment.ts +304 -0
- package/src/mcp-sdk/client/McpClient.ts +11 -5
- package/src/server/Mppx.test.ts +141 -44
- package/src/server/Mppx.ts +43 -23
- package/src/stripe/internal/constants.ts +7 -0
- package/src/stripe/server/Charge.ts +22 -4
- package/src/tempo/Proof.test-d.ts +13 -0
- package/src/tempo/Proof.test.ts +31 -0
- package/src/tempo/Proof.ts +13 -0
- package/src/tempo/client/SessionManager.test.ts +4 -7
- package/src/tempo/index.ts +1 -0
- package/src/tempo/internal/fee-payer.test.ts +1 -1
- package/src/tempo/internal/fee-payer.ts +5 -1
- package/src/tempo/server/Charge.test.ts +123 -0
- package/src/tempo/server/Charge.ts +74 -1
- package/src/tempo/server/internal/html.gen.ts +1 -1
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import * as SignatureEnvelope from 'ox/tempo/SignatureEnvelope'
|
|
1
2
|
import {
|
|
2
3
|
decodeFunctionData,
|
|
3
4
|
formatUnits,
|
|
5
|
+
hashTypedData,
|
|
4
6
|
keccak256,
|
|
5
7
|
parseEventLogs,
|
|
6
8
|
type TransactionReceipt,
|
|
@@ -227,7 +229,21 @@ export function charge<const parameters extends charge.Parameters>(
|
|
|
227
229
|
message: Proof.message(challenge.id),
|
|
228
230
|
signature: payload.signature as `0x${string}`,
|
|
229
231
|
})
|
|
230
|
-
if (!valid)
|
|
232
|
+
if (!valid) {
|
|
233
|
+
const proofSigner = recoverAuthorizedProofSigner({
|
|
234
|
+
chainId: resolvedChainId,
|
|
235
|
+
challengeId: challenge.id,
|
|
236
|
+
signature: payload.signature as `0x${string}`,
|
|
237
|
+
sourceAddress: source.address,
|
|
238
|
+
})
|
|
239
|
+
const authorized = proofSigner
|
|
240
|
+
? await isActiveAccessKey(client, {
|
|
241
|
+
accessKey: proofSigner,
|
|
242
|
+
account: source.address,
|
|
243
|
+
})
|
|
244
|
+
: false
|
|
245
|
+
if (!authorized) throw new MismatchError('Proof signature does not match source.', {})
|
|
246
|
+
}
|
|
231
247
|
|
|
232
248
|
if (proofStore && !(await markProofUsed(proofStore, challenge.id))) {
|
|
233
249
|
throw new VerificationFailedError({ reason: 'Proof credential has already been used' })
|
|
@@ -651,6 +667,63 @@ async function markProofUsed(
|
|
|
651
667
|
})
|
|
652
668
|
}
|
|
653
669
|
|
|
670
|
+
function recoverAuthorizedProofSigner(parameters: {
|
|
671
|
+
chainId: number
|
|
672
|
+
challengeId: string
|
|
673
|
+
signature: `0x${string}`
|
|
674
|
+
sourceAddress: `0x${string}`
|
|
675
|
+
}): `0x${string}` | null {
|
|
676
|
+
const { chainId, challengeId, signature, sourceAddress } = parameters
|
|
677
|
+
|
|
678
|
+
try {
|
|
679
|
+
const envelope = SignatureEnvelope.from(signature)
|
|
680
|
+
const proofHash = hashTypedData({
|
|
681
|
+
domain: Proof.domain(chainId),
|
|
682
|
+
types: Proof.types,
|
|
683
|
+
primaryType: 'Proof',
|
|
684
|
+
message: Proof.message(challengeId),
|
|
685
|
+
})
|
|
686
|
+
|
|
687
|
+
if (envelope.type === 'keychain') {
|
|
688
|
+
if (!TempoAddress.isEqual(envelope.userAddress, sourceAddress)) return null
|
|
689
|
+
|
|
690
|
+
const keychainPayload =
|
|
691
|
+
envelope.version === 'v2'
|
|
692
|
+
? keccak256(`0x04${proofHash.slice(2)}${sourceAddress.slice(2)}` as `0x${string}`)
|
|
693
|
+
: proofHash
|
|
694
|
+
|
|
695
|
+
const signer = SignatureEnvelope.extractAddress({
|
|
696
|
+
payload: keychainPayload,
|
|
697
|
+
signature: envelope.inner,
|
|
698
|
+
})
|
|
699
|
+
const valid = SignatureEnvelope.verify(envelope.inner, {
|
|
700
|
+
address: signer,
|
|
701
|
+
payload: keychainPayload,
|
|
702
|
+
})
|
|
703
|
+
if (!valid) return null
|
|
704
|
+
|
|
705
|
+
return signer
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
return SignatureEnvelope.extractAddress({ payload: proofHash, signature: envelope })
|
|
709
|
+
} catch {
|
|
710
|
+
return null
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
async function isActiveAccessKey(
|
|
715
|
+
client: Awaited<ReturnType<ReturnType<typeof Client.getResolver>>>,
|
|
716
|
+
parameters: { account: `0x${string}`; accessKey: `0x${string}` },
|
|
717
|
+
): Promise<boolean> {
|
|
718
|
+
try {
|
|
719
|
+
const metadata = await Actions.accessKey.getMetadata(client, parameters)
|
|
720
|
+
const nowSeconds = BigInt(Math.floor(Date.now() / 1000))
|
|
721
|
+
return !metadata.isRevoked && metadata.expiry > nowSeconds
|
|
722
|
+
} catch {
|
|
723
|
+
return false
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
|
|
654
727
|
/** @internal */
|
|
655
728
|
function toReceipt(receipt: TransactionReceipt) {
|
|
656
729
|
const { status, transactionHash } = receipt
|