mppx 0.4.12 → 0.5.1
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 +12 -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/cli/account.d.ts.map +1 -1
- package/dist/cli/account.js +12 -2
- package/dist/cli/account.js.map +1 -1
- package/dist/server/Mppx.js +6 -5
- 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 +3 -0
- package/dist/tempo/Methods.d.ts.map +1 -1
- package/dist/tempo/Methods.js +1 -0
- package/dist/tempo/Methods.js.map +1 -1
- package/dist/tempo/client/Charge.d.ts +3 -0
- package/dist/tempo/client/Charge.d.ts.map +1 -1
- package/dist/tempo/client/Charge.js +18 -2
- package/dist/tempo/client/Charge.js.map +1 -1
- package/dist/tempo/client/Methods.d.ts +3 -0
- package/dist/tempo/client/Methods.d.ts.map +1 -1
- package/dist/tempo/internal/proof.d.ts +29 -0
- package/dist/tempo/internal/proof.d.ts.map +1 -0
- package/dist/tempo/internal/proof.js +32 -0
- package/dist/tempo/internal/proof.js.map +1 -0
- package/dist/tempo/server/Charge.d.ts +11 -3
- package/dist/tempo/server/Charge.d.ts.map +1 -1
- package/dist/tempo/server/Charge.js +54 -4
- package/dist/tempo/server/Charge.js.map +1 -1
- package/dist/tempo/server/Methods.d.ts +3 -0
- package/dist/tempo/server/Methods.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/Expires.ts +25 -0
- package/src/cli/account.ts +13 -2
- package/src/cli/cli.test.ts +230 -1
- package/src/middlewares/elysia.test.ts +130 -9
- package/src/middlewares/express.test.ts +123 -59
- package/src/middlewares/hono.test.ts +81 -39
- package/src/middlewares/nextjs.test.ts +162 -41
- package/src/server/Mppx.test.ts +86 -0
- package/src/server/Mppx.ts +5 -5
- package/src/stripe/server/Charge.ts +3 -7
- package/src/tempo/Methods.test.ts +26 -0
- package/src/tempo/Methods.ts +1 -0
- package/src/tempo/client/Charge.ts +26 -3
- package/src/tempo/internal/charge.test.ts +66 -0
- package/src/tempo/internal/proof.test.ts +83 -0
- package/src/tempo/internal/proof.ts +35 -0
- package/src/tempo/server/Charge.test.ts +660 -1
- package/src/tempo/server/Charge.ts +80 -5
- package/src/tempo/server/Session.test.ts +1123 -53
- package/src/tempo/server/internal/transport.test.ts +32 -0
- package/src/tempo/session/Chain.test.ts +35 -0
- package/src/tempo/session/Sse.test.ts +31 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { isAddress, type Address } from 'viem'
|
|
2
|
+
|
|
3
|
+
/** EIP-712 typed data types for proof credentials. */
|
|
4
|
+
export const types = {
|
|
5
|
+
Proof: [{ name: 'challengeId', type: 'string' }],
|
|
6
|
+
} as const
|
|
7
|
+
|
|
8
|
+
/** Constructs the EIP-712 domain for a proof credential. */
|
|
9
|
+
export function domain(chainId: number) {
|
|
10
|
+
return { name: 'MPP', version: '1', chainId } as const
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Constructs the EIP-712 message for a proof credential. */
|
|
14
|
+
export function message(challengeId: string) {
|
|
15
|
+
return { challengeId } as const
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Constructs the expected `did:pkh` source DID for a proof credential. */
|
|
19
|
+
export function proofSource(parameters: { address: string; chainId: number }): string {
|
|
20
|
+
return `did:pkh:eip155:${parameters.chainId}:${parameters.address}`
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Parses a proof credential `did:pkh:eip155` source DID. */
|
|
24
|
+
export function parseProofSource(source: string): { address: Address; chainId: number } | null {
|
|
25
|
+
const match = /^did:pkh:eip155:(0|[1-9]\d*):([^:]+)$/.exec(source)
|
|
26
|
+
if (!match) return null
|
|
27
|
+
|
|
28
|
+
const chainIdText = match[1]!
|
|
29
|
+
const address = match[2]!
|
|
30
|
+
const chainId = Number(chainIdText)
|
|
31
|
+
if (!Number.isSafeInteger(chainId)) return null
|
|
32
|
+
if (!isAddress(address)) return null
|
|
33
|
+
|
|
34
|
+
return { address: address as Address, chainId }
|
|
35
|
+
}
|