mppx 0.4.11 → 0.5.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.
- package/CHANGELOG.md +21 -0
- package/dist/Expires.d.ts +7 -0
- package/dist/Expires.d.ts.map +1 -1
- package/dist/Expires.js +21 -0
- package/dist/Expires.js.map +1 -1
- package/dist/internal/env.d.ts +1 -1
- package/dist/internal/env.d.ts.map +1 -1
- package/dist/internal/env.js +2 -6
- package/dist/internal/env.js.map +1 -1
- package/dist/internal/types.d.ts +23 -0
- package/dist/internal/types.d.ts.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 +55 -7
- package/dist/server/Mppx.js.map +1 -1
- package/dist/stripe/server/Charge.d.ts.map +1 -1
- package/dist/stripe/server/Charge.js +3 -3
- package/dist/stripe/server/Charge.js.map +1 -1
- package/dist/tempo/Methods.d.ts +18 -0
- package/dist/tempo/Methods.d.ts.map +1 -1
- package/dist/tempo/Methods.js +28 -3
- package/dist/tempo/Methods.js.map +1 -1
- package/dist/tempo/client/Charge.d.ts +24 -0
- package/dist/tempo/client/Charge.d.ts.map +1 -1
- package/dist/tempo/client/Charge.js +51 -9
- package/dist/tempo/client/Charge.js.map +1 -1
- package/dist/tempo/client/Methods.d.ts +18 -0
- package/dist/tempo/client/Methods.d.ts.map +1 -1
- package/dist/tempo/internal/account.d.ts +5 -11
- package/dist/tempo/internal/account.d.ts.map +1 -1
- package/dist/tempo/internal/charge.d.ts +20 -0
- package/dist/tempo/internal/charge.d.ts.map +1 -0
- package/dist/tempo/internal/charge.js +23 -0
- package/dist/tempo/internal/charge.js.map +1 -0
- package/dist/tempo/internal/fee-payer.d.ts.map +1 -1
- package/dist/tempo/internal/fee-payer.js +15 -3
- package/dist/tempo/internal/fee-payer.js.map +1 -1
- package/dist/tempo/internal/proof.d.ts +23 -0
- package/dist/tempo/internal/proof.d.ts.map +1 -0
- package/dist/tempo/internal/proof.js +17 -0
- package/dist/tempo/internal/proof.js.map +1 -0
- package/dist/tempo/server/Charge.d.ts +20 -2
- package/dist/tempo/server/Charge.d.ts.map +1 -1
- package/dist/tempo/server/Charge.js +180 -103
- package/dist/tempo/server/Charge.js.map +1 -1
- package/dist/tempo/server/Methods.d.ts +20 -2
- package/dist/tempo/server/Methods.d.ts.map +1 -1
- package/dist/tempo/server/Methods.js +4 -1
- package/dist/tempo/server/Methods.js.map +1 -1
- package/dist/tempo/server/Session.d.ts +9 -4
- package/dist/tempo/server/Session.d.ts.map +1 -1
- package/dist/tempo/server/Session.js +18 -3
- package/dist/tempo/server/Session.js.map +1 -1
- package/dist/tempo/session/Chain.d.ts +18 -2
- package/dist/tempo/session/Chain.d.ts.map +1 -1
- package/dist/tempo/session/Chain.js +18 -14
- package/dist/tempo/session/Chain.js.map +1 -1
- package/package.json +1 -1
- package/src/Expires.ts +25 -0
- package/src/cli/cli.test.ts +230 -1
- package/src/internal/env.test.ts +12 -12
- package/src/internal/env.ts +2 -6
- package/src/internal/types.ts +25 -0
- package/src/middlewares/elysia.test.ts +127 -4
- package/src/middlewares/express.test.ts +120 -54
- package/src/middlewares/hono.test.ts +73 -34
- package/src/middlewares/nextjs.test.ts +159 -36
- package/src/server/Mppx.test.ts +373 -0
- package/src/server/Mppx.ts +64 -10
- package/src/stripe/server/Charge.ts +3 -7
- package/src/tempo/Methods.test.ts +105 -0
- package/src/tempo/Methods.ts +54 -17
- package/src/tempo/client/Charge.ts +67 -11
- package/src/tempo/internal/account.ts +7 -14
- package/src/tempo/internal/charge.test.ts +66 -0
- package/src/tempo/internal/charge.ts +43 -0
- package/src/tempo/internal/fee-payer.test.ts +33 -14
- package/src/tempo/internal/fee-payer.ts +21 -6
- package/src/tempo/internal/proof.test.ts +36 -0
- package/src/tempo/internal/proof.ts +19 -0
- package/src/tempo/server/Charge.test.ts +593 -1
- package/src/tempo/server/Charge.ts +233 -126
- package/src/tempo/server/Methods.ts +4 -1
- package/src/tempo/server/Session.test.ts +1152 -54
- package/src/tempo/server/Session.ts +26 -17
- package/src/tempo/server/internal/transport.test.ts +32 -0
- package/src/tempo/session/Chain.test.ts +60 -5
- package/src/tempo/session/Chain.ts +30 -14
- package/src/tempo/session/Sse.test.ts +31 -0
|
@@ -70,17 +70,7 @@ describe('validateCalls', () => {
|
|
|
70
70
|
).not.toThrow()
|
|
71
71
|
})
|
|
72
72
|
|
|
73
|
-
test('
|
|
74
|
-
expect(() => validateCalls([], details)).toThrow(FeePayerValidationError)
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
test('error: rejects unknown selector', () => {
|
|
78
|
-
expect(() => validateCalls([{ data: '0xdeadbeef' as `0x${string}` }], details)).toThrow(
|
|
79
|
-
'disallowed call pattern',
|
|
80
|
-
)
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
test('error: rejects extra calls beyond allowed patterns', () => {
|
|
73
|
+
test('accepts multiple transfers after swap prefix', () => {
|
|
84
74
|
const swapSelector = Selectors.swapExactAmountOut
|
|
85
75
|
expect(() =>
|
|
86
76
|
validateCalls(
|
|
@@ -100,19 +90,48 @@ describe('validateCalls', () => {
|
|
|
100
90
|
data: encodeFunctionData({
|
|
101
91
|
abi: Abis.tip20,
|
|
102
92
|
functionName: 'transfer',
|
|
103
|
-
args: [bogus,
|
|
93
|
+
args: [bogus, 90n],
|
|
104
94
|
}),
|
|
105
95
|
},
|
|
106
96
|
{
|
|
107
97
|
data: encodeFunctionData({
|
|
108
98
|
abi: Abis.tip20,
|
|
109
|
-
functionName: '
|
|
110
|
-
args: [
|
|
99
|
+
functionName: 'transferWithMemo',
|
|
100
|
+
args: [
|
|
101
|
+
'0x0000000000000000000000000000000000000002',
|
|
102
|
+
10n,
|
|
103
|
+
'0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef',
|
|
104
|
+
],
|
|
111
105
|
}),
|
|
112
106
|
},
|
|
113
107
|
],
|
|
114
108
|
details,
|
|
115
109
|
),
|
|
110
|
+
).not.toThrow()
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
test('error: rejects empty calls', () => {
|
|
114
|
+
expect(() => validateCalls([], details)).toThrow(FeePayerValidationError)
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
test('error: rejects unknown selector', () => {
|
|
118
|
+
expect(() => validateCalls([{ data: '0xdeadbeef' as `0x${string}` }], details)).toThrow(
|
|
119
|
+
'disallowed call pattern',
|
|
120
|
+
)
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
test('error: rejects more than 11 transfers', () => {
|
|
124
|
+
expect(() =>
|
|
125
|
+
validateCalls(
|
|
126
|
+
Array.from({ length: 12 }, (_, index) => ({
|
|
127
|
+
data: encodeFunctionData({
|
|
128
|
+
abi: Abis.tip20,
|
|
129
|
+
functionName: 'transfer',
|
|
130
|
+
args: [`0x${(index + 1).toString(16).padStart(40, '0')}`, 100n],
|
|
131
|
+
}),
|
|
132
|
+
})),
|
|
133
|
+
details,
|
|
134
|
+
),
|
|
116
135
|
).toThrow('disallowed call pattern')
|
|
117
136
|
})
|
|
118
137
|
|
|
@@ -30,14 +30,29 @@ export function validateCalls(
|
|
|
30
30
|
calls: readonly { data?: `0x${string}` | undefined; to?: TempoAddress.Address | undefined }[],
|
|
31
31
|
details: Record<string, string>,
|
|
32
32
|
) {
|
|
33
|
+
if (calls.length === 0)
|
|
34
|
+
throw new FeePayerValidationError('disallowed call pattern in fee-payer transaction', details)
|
|
35
|
+
|
|
33
36
|
const callSelectors = calls.map((c) => c.data?.slice(0, 10))
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if (
|
|
37
|
+
const hasSwapPrefix = callSelectors[0] === Selectors.approve
|
|
38
|
+
|
|
39
|
+
if (hasSwapPrefix) {
|
|
40
|
+
if (callSelectors[1] !== Selectors.swapExactAmountOut)
|
|
41
|
+
throw new FeePayerValidationError('disallowed call pattern in fee-payer transaction', details)
|
|
42
|
+
} else if (callSelectors[0] === Selectors.swapExactAmountOut) {
|
|
43
|
+
throw new FeePayerValidationError('disallowed call pattern in fee-payer transaction', details)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const transferSelectors = callSelectors.slice(hasSwapPrefix ? 2 : 0)
|
|
47
|
+
if (
|
|
48
|
+
transferSelectors.length === 0 ||
|
|
49
|
+
transferSelectors.length > 11 ||
|
|
50
|
+
transferSelectors.some(
|
|
51
|
+
(selector) => selector !== Selectors.transfer && selector !== Selectors.transferWithMemo,
|
|
52
|
+
)
|
|
53
|
+
) {
|
|
40
54
|
throw new FeePayerValidationError('disallowed call pattern in fee-payer transaction', details)
|
|
55
|
+
}
|
|
41
56
|
|
|
42
57
|
// Validate approve spender and buy target are the DEX.
|
|
43
58
|
const approveCall = calls.find((c) => c.data?.slice(0, 10) === Selectors.approve)
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { describe, expect, test } from 'vp/test'
|
|
2
|
+
|
|
3
|
+
import * as Proof from './proof.js'
|
|
4
|
+
|
|
5
|
+
describe('Proof', () => {
|
|
6
|
+
test('types has Proof with challengeId field', () => {
|
|
7
|
+
expect(Proof.types).toEqual({
|
|
8
|
+
Proof: [{ name: 'challengeId', type: 'string' }],
|
|
9
|
+
})
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
test('domain returns EIP-712 domain with name, version, chainId', () => {
|
|
13
|
+
const d = Proof.domain(42431)
|
|
14
|
+
expect(d).toEqual({ name: 'MPP', version: '1', chainId: 42431 })
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
test('domain uses provided chainId', () => {
|
|
18
|
+
expect(Proof.domain(1).chainId).toBe(1)
|
|
19
|
+
expect(Proof.domain(99999).chainId).toBe(99999)
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
test('message wraps challengeId', () => {
|
|
23
|
+
expect(Proof.message('abc123')).toEqual({ challengeId: 'abc123' })
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
test('proofSource constructs did:pkh DID', () => {
|
|
27
|
+
expect(Proof.proofSource({ address: '0x1234567890abcdef', chainId: 42431 })).toBe(
|
|
28
|
+
'did:pkh:eip155:42431:0x1234567890abcdef',
|
|
29
|
+
)
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
test('proofSource preserves address casing', () => {
|
|
33
|
+
const address = '0xAbCdEf1234567890AbCdEf1234567890AbCdEf12'
|
|
34
|
+
expect(Proof.proofSource({ address, chainId: 1 })).toBe(`did:pkh:eip155:1:${address}`)
|
|
35
|
+
})
|
|
36
|
+
})
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** EIP-712 typed data types for proof credentials. */
|
|
2
|
+
export const types = {
|
|
3
|
+
Proof: [{ name: 'challengeId', type: 'string' }],
|
|
4
|
+
} as const
|
|
5
|
+
|
|
6
|
+
/** Constructs the EIP-712 domain for a proof credential. */
|
|
7
|
+
export function domain(chainId: number) {
|
|
8
|
+
return { name: 'MPP', version: '1', chainId } as const
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Constructs the EIP-712 message for a proof credential. */
|
|
12
|
+
export function message(challengeId: string) {
|
|
13
|
+
return { challengeId } as const
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Constructs the expected `did:pkh` source DID for a proof credential. */
|
|
17
|
+
export function proofSource(parameters: { address: string; chainId: number }): string {
|
|
18
|
+
return `did:pkh:eip155:${parameters.chainId}:${parameters.address}`
|
|
19
|
+
}
|