@pepu-chain/sdk 0.2.0 → 0.2.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/README.md +26 -2
- package/dist/aa/kernel.cjs +11 -9
- package/dist/aa/kernel.guard.js +15 -0
- package/dist/aa/kernel.js +5 -4
- package/dist/aa/react-direct.cjs +14 -12
- package/dist/aa/react-direct.cjs.map +1 -1
- package/dist/aa/react-direct.guard.js +15 -0
- package/dist/aa/react-direct.js +7 -6
- package/dist/aa/react-direct.js.map +1 -1
- package/dist/aa/react.cjs +7 -5
- package/dist/aa/react.cjs.map +1 -1
- package/dist/aa/react.d.cts +1 -1
- package/dist/aa/react.d.ts +1 -1
- package/dist/aa/react.guard.js +15 -0
- package/dist/aa/react.js +4 -3
- package/dist/aa/react.js.map +1 -1
- package/dist/aa.cjs +19 -18
- package/dist/aa.d.cts +1 -1
- package/dist/aa.d.ts +1 -1
- package/dist/aa.js +6 -5
- package/dist/chunk-4GEC7GUU.cjs +283 -0
- package/dist/chunk-4GEC7GUU.cjs.map +1 -0
- package/dist/{chunk-PHM3ZORG.cjs → chunk-4L4CHIXE.cjs} +9 -9
- package/dist/{chunk-PHM3ZORG.cjs.map → chunk-4L4CHIXE.cjs.map} +1 -1
- package/dist/{chunk-A5LP2UCS.cjs → chunk-65Y5UCQ7.cjs} +2 -276
- package/dist/chunk-65Y5UCQ7.cjs.map +1 -0
- package/dist/{chunk-MBA4CLA5.js → chunk-7PVR7QSE.js} +3 -3
- package/dist/{chunk-MBA4CLA5.js.map → chunk-7PVR7QSE.js.map} +1 -1
- package/dist/{chunk-7MNJF2OB.cjs → chunk-DNWWZWUW.cjs} +4 -4
- package/dist/{chunk-7MNJF2OB.cjs.map → chunk-DNWWZWUW.cjs.map} +1 -1
- package/dist/{chunk-D52PADVY.js → chunk-GFKIM7HT.js} +25 -2
- package/dist/chunk-GFKIM7HT.js.map +1 -0
- package/dist/{chunk-IY3ALPUJ.js → chunk-GIZNH65Q.js} +5 -273
- package/dist/chunk-GIZNH65Q.js.map +1 -0
- package/dist/{chunk-WANILJZQ.cjs → chunk-HTCX46RJ.cjs} +25 -2
- package/dist/chunk-HTCX46RJ.cjs.map +1 -0
- package/dist/{chunk-TIEAZYHF.cjs → chunk-K7JSQPZO.cjs} +8 -2
- package/dist/chunk-K7JSQPZO.cjs.map +1 -0
- package/dist/{chunk-FCXSP2YF.js → chunk-KJYNF5KH.js} +8 -3
- package/dist/chunk-KJYNF5KH.js.map +1 -0
- package/dist/{chunk-KVG3AYYR.js → chunk-NHPWXIA2.js} +4 -4
- package/dist/{chunk-KVG3AYYR.js.map → chunk-NHPWXIA2.js.map} +1 -1
- package/dist/{chunk-ZB6SVBK4.js → chunk-QIDMFFAQ.js} +4 -4
- package/dist/{chunk-ZB6SVBK4.js.map → chunk-QIDMFFAQ.js.map} +1 -1
- package/dist/{chunk-IB2FSPMJ.js → chunk-QZKUPCUD.js} +3 -3
- package/dist/{chunk-IB2FSPMJ.js.map → chunk-QZKUPCUD.js.map} +1 -1
- package/dist/{chunk-ET3P6TX6.cjs → chunk-RCMKPJZO.cjs} +4 -4
- package/dist/{chunk-ET3P6TX6.cjs.map → chunk-RCMKPJZO.cjs.map} +1 -1
- package/dist/chunk-RSPAN44L.js +276 -0
- package/dist/chunk-RSPAN44L.js.map +1 -0
- package/dist/{chunk-NVOPDXTA.cjs → chunk-UQH4ZAXD.cjs} +10 -10
- package/dist/{chunk-NVOPDXTA.cjs.map → chunk-UQH4ZAXD.cjs.map} +1 -1
- package/dist/{chunk-SLW7FRTL.cjs → chunk-VYMAZVIK.cjs} +52 -22
- package/dist/chunk-VYMAZVIK.cjs.map +1 -0
- package/dist/{chunk-KIIFL4VM.js → chunk-XR5ONV2Y.js} +42 -12
- package/dist/chunk-XR5ONV2Y.js.map +1 -0
- package/dist/combo/react.cjs +62 -13
- package/dist/combo/react.cjs.map +1 -1
- package/dist/combo/react.d.cts +14 -2
- package/dist/combo/react.d.ts +14 -2
- package/dist/combo/react.guard.js +15 -0
- package/dist/combo/react.js +58 -11
- package/dist/combo/react.js.map +1 -1
- package/dist/combo.cjs +45 -29
- package/dist/combo.cjs.map +1 -1
- package/dist/combo.d.cts +11 -0
- package/dist/combo.d.ts +11 -0
- package/dist/combo.guard.js +15 -0
- package/dist/combo.js +33 -18
- package/dist/combo.js.map +1 -1
- package/dist/index.cjs +28 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +6 -5
- package/dist/index.js.map +1 -1
- package/dist/paymaster.cjs +39 -38
- package/dist/paymaster.cjs.map +1 -1
- package/dist/paymaster.js +4 -3
- package/dist/paymaster.js.map +1 -1
- package/dist/privy/react.cjs +1 -0
- package/dist/privy/react.guard.js +15 -0
- package/dist/privy/server.cjs +1 -0
- package/dist/privy/server.guard.js +15 -0
- package/dist/privy/wagmi.guard.js +15 -0
- package/dist/react.cjs +6 -4
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.guard.js +15 -0
- package/dist/react.js +4 -3
- package/dist/react.js.map +1 -1
- package/dist/session/kernel.cjs +19 -17
- package/dist/session/kernel.guard.js +15 -0
- package/dist/session/kernel.js +6 -5
- package/dist/session/react.cjs +1 -0
- package/dist/session/react.guard.js +15 -0
- package/dist/session/server.cjs +1 -0
- package/dist/session/server.guard.js +15 -0
- package/dist/{status-DwkkOrGQ.d.ts → status-Dx9zAFo9.d.ts} +42 -10
- package/dist/{status-CmOsyPmO.d.cts → status-wgTM26V7.d.cts} +42 -10
- package/package.json +38 -2
- package/dist/chunk-A5LP2UCS.cjs.map +0 -1
- package/dist/chunk-D52PADVY.js.map +0 -1
- package/dist/chunk-FCXSP2YF.js.map +0 -1
- package/dist/chunk-IY3ALPUJ.js.map +0 -1
- package/dist/chunk-KIIFL4VM.js.map +0 -1
- package/dist/chunk-SLW7FRTL.cjs.map +0 -1
- package/dist/ch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EAAA,IAAI,CAAC,YAAA,EAAc,MAAM,IAAI,MAAM,qCAAqC,CAAA;AACxE,EAAA,OAAO,YAAA;AACT;AAeA,eAAsB,qBAAqB,CAAA,EAKe;AACxD,EAAA,MAAM,OAAA,GAAU,MAAM,aAAA,CAAc,CAAA,CAAE,cAAc,CAAA,CAAE,iBAAA,EAAmB,EAAE,QAAQ,CAAA;AACnF,EAAA,MAAM,OAAA,GAAU,MAAM,mBAAA,CAAoB;AAAA,IACxC,cAAc,CAAA,CAAE,YAAA;AAAA,IAChB,OAAO,CAAA,CAAE,KAAA;AAAA,IACT,OAAA,EAAS,EAAE,OAAA;AAAQ,GACpB,CAAA;AACD,EAAA,MAAM,QAAA,GAAW,MAAM,0BAAA,CAA2B,OAAgB,CAAA;AAClE,EAAA,OAAO,EAAE,QAAA,EAAU,aAAA,EAAe,OAAA,CAAQ,OAAA,EAAQ;AACpD;AAUA,eAAsB,yBAAyB,CAAA,EAIf;AAC9B,EAAA,MAAM,aAAA,GAAgB,MAAM,aAAA,CAAc,EAAE,QAAQ,mBAAA,CAAoB,CAAA,CAAE,iBAAiB,CAAA,EAAG,CAAA;AAC9F,EAAA,MAAM,UAAU,MAAM,4BAAA;AAAA,IACpB,EAAA,CAAG,EAAE,YAAY,CAAA;AAAA,IACjB,eAAA;AAAA,IACA,cAAA;AAAA,IACA,CAAA,CAAE,QAAA;AAAA,IACF;AAAA,GACF;AACA,EAAA,OAAO,OAAA;AACT","file":"chunk-KVG3AYYR.js","sourcesContent":["import type { Address, Hex } from \"viem\";\n\n/**\n * Server-side session records for the Kernel (on-chain) session flow, keyed by\n * Privy user id. Ported from templates/sponsored-session-app/lib/session-store.ts.\n *\n * WHAT IS STORED: the session private key (a hot key whose power is limited\n * ON-CHAIN by the call and timestamp policies until `validUntil`) and the\n * public approval. The owner's key never reaches the server.\n *\n * PRODUCTION: {@link createMemoryStore} is DEV-GRADE. It is lost on every\n * restart (the user simply starts a new session) and is not shared between\n * serverless instances. A production deployment must implement\n * {@link SessionStore} on a persistent database or KV AND keep\n * `sessionPrivateKey` encrypted at rest (KMS or an envelope key). Nothing else\n * in the SDK changes.\n */\nexport interface SessionRecord {\n userId: string;\n ownerAddress: Address;\n kernelAddress: Address;\n /** The session key's private half. Encrypt it at rest in any persistent store. */\n sessionPrivateKey: Hex;\n sessionKeyAddress: Address;\n permissionId: string;\n /** Unix seconds. The on-chain permission is invalid at and after this time. */\n validUntil: number;\n /** Present once the owner has signed the grant. */\n approval: string | null;\n /** Number of successful sponsored actions in this session. */\n actions: number;\n}\n\ntype MaybePromise<T> = T | Promise<T>;\n\n/**\n * Pluggable storage for {@link SessionRecord}s. Every method may be sync or\n * async. `tryLock` must be atomic per user: it returns `false` when an action\n * is already running for that user (a multi-instance deployment needs a\n * distributed lock, for example a Redis `SET NX PX`).\n */\nexport interface SessionStore {\n get(userId: string): MaybePromise<SessionRecord | undefined>;\n set(record: SessionRecord): MaybePromise<void>;\n delete(userId: string): MaybePromise<void>;\n tryLock(userId: string): MaybePromise<boolean>;\n unlock(userId: string): MaybePromise<void>;\n}\n\n/**\n * An in-memory {@link SessionStore} for development and tests. DEV-GRADE: not\n * persistent, not shared across instances, and the session key is held in\n * plaintext in process memory. Production needs an encrypted persistent store.\n *\n * @example\n * const store = createMemoryStore();\n */\nexport function createMemoryStore(): SessionStore {\n const records = new Map<string, SessionRecord>();\n const locks = new Set<string>();\n return {\n get: (userId) => records.get(userId),\n set: (record) => {\n records.set(record.userId, record);\n },\n delete: (userId) => {\n records.delete(userId);\n },\n tryLock: (userId) => {\n if (locks.has(userId)) return false;\n locks.add(userId);\n return true;\n },\n unlock: (userId) => {\n locks.delete(userId);\n },\n };\n}\n\n/**\n * True while the on-chain permission is still valid: approved and before expiry.\n *\n * @example\n * isLive(record, Math.floor(Date.now() / 1000));\n */\nexport function isLive(record: SessionRecord, nowSeconds: number): boolean {\n return record.approval !== null && nowSeconds < record.validUntil;\n}\n","import { deserializePermissionAccount, serializePermissionAccount, toPermissionValidator } from \"@zerodev/permissions\";\nimport type { Policy } from \"@zerodev/permissions\";\nimport { CallPolicyVersion, toCallPolicy, toTimestampPolicy } from \"@zerodev/permissions/policies\";\nimport { toECDSASigner, toEmptyECDSASigner } from \"@zerodev/permissions/signers\";\nimport type { createKernelAccount } from \"@zerodev/sdk\";\nimport type { Abi, Address, Hex, PublicClient } from \"viem\";\nimport { generatePrivateKey, privateKeyToAccount } from \"viem/accounts\";\n\nimport { ENTRY_POINT_V07 } from \"../aa/clients.js\";\nimport { KERNEL_VERSION, toPepuKernelAccount } from \"../aa/kernel.js\";\nimport type { KernelOwner, KernelSmartAccount } from \"../aa/kernel.js\";\nimport { assertCalls, findFunction } from \"./scope.js\";\nimport type { KernelSessionCall } from \"./scope.js\";\n\nexport { KERNEL_VERSION, getKernelAddress } from \"../aa/kernel.js\";\nexport type { KernelOwner, KernelSmartAccount } from \"../aa/kernel.js\";\nexport { createMemoryStore, isLive } from \"./store.js\";\nexport type { SessionRecord, SessionStore } from \"./store.js\";\nexport { checkApproval, describeKernelSessionScope, isCallInScope, parseApproval } from \"./scope.js\";\nexport type { ApprovalCheck, KernelSessionCall, KernelSessionScope, ParsedApproval } from \"./scope.js\";\n\n/**\n * `@pepu-chain/sdk/session/kernel`: on-chain session keys with ZeroDev Kernel\n * permissions. Extracted from templates/sponsored-session-app/lib/{kernel,\n * session-policy,approval}.ts and built on `toPepuKernelAccount`\n * (`plugins.regular`).\n *\n * The scope is enforced ON-CHAIN by ZeroDev's policy contracts, which the\n * user's Kernel account calls during UserOperation validation:\n *\n * - Call policy v0.0.4: only the listed targets and function selectors, with a\n * native value no larger than `valueLimit` (default 0).\n * - Timestamp policy: the permission is invalid outside `validAfter`..`validUntil`.\n *\n * A UserOperation outside this scope is rejected by the EntryPoint itself, no\n * matter who relays it or what the app backend does.\n *\n * Deployed on PEPU mainnet (eth_getCode verified 2026-10-02): Kernel v3.1\n * factory 0xaac5D4240AF87249B3f71BC8E4A2cae074A3E419, ECDSA validator\n * 0x845ADb2C711129d4f3966735eD98a9F09fC4cE57, ECDSA signer module\n * 0x6A6F069E2a08c2468e7724Ab3250CdBFBA14D4FF, call policy v0.0.4 and the\n * timestamp policy below. Call policy v0.0.5 is NOT deployed on PEPU, so the\n * version is pinned.\n *\n * Optional peers: `@zerodev/sdk`, `@zerodev/permissions`, `@zerodev/ecdsa-validator`.\n */\n\n/** Call policy v0.0.4. Pinned: v0.0.5 is not deployed on PEPU mainnet. */\nexport const CALL_POLICY_V0_0_4_ADDRESS: Address = \"0x9a52283276A0ec8740DF50bF01B28A80D880eaf2\";\n/** ZeroDev timestamp policy on PEPU mainnet. */\nexport const TIMESTAMP_POLICY_ADDRESS: Address = \"0xB9f8f524bE6EcD8C945b1b87f9ae5C192FdCE20F\";\n\n/**\n * Worst-case gas the paymaster policy service RESERVES per sponsored operation,\n * measured on PEPU mainnet with the sponsored-session-app template: the first\n * operation of a session (account deploy plus enabling the permission) about\n * 20.5 PEPU, later operations about 6.9 PEPU. The real first-session cost was\n * about 12.8 PEPU for two operations. Size per-user hourly and daily spend\n * caps above these, or users hit `trailing-hour spend ... would exceed cap`\n * after their first action.\n */\nexport const SESSION_GAS_RESERVATION_PEPU = { firstOperation: 20.5, laterOperation: 6.9 } as const;\n\ntype ZeroDevClient = Parameters<typeof createKernelAccount>[0];\n\n/** Type-level bridge for ZeroDev's own viem copy (same object at runtime). */\nfunction zd(client: PublicClient): ZeroDevClient {\n return client as unknown as ZeroDevClient;\n}\n\n/**\n * The on-chain policies for one session: call policy v0.0.4 plus the timestamp\n * policy. Pure and deterministic given its input. Only the named function\n * fragments go into the policy, which keeps the grant small.\n *\n * @example\n * const policies = buildKernelSessionPolicies({\n * calls: [{ target: tapScore, abi: tapScoreAbi, functionName: \"tap\" }],\n * validUntil: Math.floor(Date.now() / 1000) + 900,\n * });\n */\nexport function buildKernelSessionPolicies(p: {\n calls: readonly KernelSessionCall[];\n validUntil: number;\n validAfter?: number;\n}): Policy[] {\n assertCalls(p.calls);\n return [\n toCallPolicy({\n policyVersion: CallPolicyVersion.V0_0_4,\n permissions: p.calls.map((c) => ({\n target: c.target,\n valueLimit: c.valueLimit ?? 0n,\n abi: [findFunction(c)] as Abi,\n functionName: c.functionName,\n })),\n } as Parameters<typeof toCallPolicy>[0]),\n toTimestampPolicy({ validAfter: p.validAfter ?? 0, validUntil: p.validUntil }),\n ];\n}\n\n/**\n * A fresh random session key. SERVER ONLY: the private key must never reach\n * the browser. Only the address is sent to the owner for approval.\n *\n * @example\n * const { privateKey, address } = generateSessionKey();\n */\nexport function generateSessionKey(): { privateKey: Hex; address: Address } {\n const privateKey = generatePrivateKey();\n return { privateKey, address: privateKeyToAccount(privateKey).address };\n}\n\nfunction permissionFor(publicClient: PublicClient, sessionKeyAddress: Address, policies: Policy[]) {\n return toPermissionValidator(zd(publicClient), {\n entryPoint: ENTRY_POINT_V07,\n kernelVersion: KERNEL_VERSION,\n signer: toEmptyECDSASigner(sessionKeyAddress),\n policies,\n });\n}\n\n/**\n * The permission id the chain derives for this session key plus these\n * policies. The server compares it with a browser-supplied approval.\n *\n * @example\n * const permissionId = await expectedPermissionId({ publicClient, sessionKeyAddress, policies });\n */\nexport async function expectedPermissionId(p: {\n publicClient: PublicClient;\n sessionKeyAddress: Address;\n policies: Policy[];\n}): Promise<string> {\n const permission = await permissionFor(p.publicClient, p.sessionKeyAddress, p.policies);\n const { permissionId } = permission.getPluginSerializationParams();\n if (!permissionId) throw new Error(\"Could not derive the permission id.\");\n return permissionId;\n}\n\n/**\n * In the user's browser: the owner (the Privy embedded wallet, the only thing\n * that can authorize a session) signs ONE EIP-712 message that enables a\n * permission validator on their Kernel account. That signature is the whole\n * grant. It names the session key's public address (never its private key)\n * and the policies. The returned `approval` holds no secret: it is the enable\n * signature plus the policy parameters, useless without the session key.\n *\n * @example\n * const { approval, kernelAddress } = await approveKernelSession({\n * publicClient, owner: walletClient, sessionKeyAddress, policies,\n * });\n */\nexport async function approveKernelSession(p: {\n publicClient: PublicClient;\n owner: KernelOwner;\n sessionKeyAddress: Address;\n policies: Policy[];\n}): Promise<{ approval: string; kernelAddress: Address }> {\n const regular = await permissionFor(p.publicClient, p.sessionKeyAddress, p.policies);\n const account = await toPepuKernelAccount({\n publicClient: p.publicClient,\n owner: p.owner,\n plugins: { regular },\n });\n const approval = await serializePermissionAccount(account as never);\n return { approval, kernelAddress: account.address };\n}\n\n/**\n * On the server: rebuild the session's Kernel account from the approval and\n * the server-held session key (an ECDSA signer for that key). No owner\n * signature is involved. Pass the result to `createPepuSponsoredClient`.\n *\n * @example\n * const account = await loadKernelSessionAccount({ publicClient, approval, sessionPrivateKey });\n */\nexport async function loadKernelSessionAccount(p: {\n publicClient: PublicClient;\n approval: string;\n sessionPrivateKey: Hex;\n}): Promise<KernelSmartAccount> {\n const sessionSigner = await toECDSASigner({ signer: privateKeyToAccount(p.sessionPrivateKey) });\n const account = await deserializePermissionAccount(\n zd(p.publicClient),\n ENTRY_POINT_V07,\n KERNEL_VERSION,\n p.approval,\n sessionSigner,\n );\n return account as unknown as KernelSmartAccount;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/session/store.ts","../src/session/kernel.ts"],"names":[],"mappings":";;;;;;;;;AAyDO,SAAS,iBAAA,GAAkC;AAChD,EAAA,MAAM,OAAA,uBAAc,GAAA,EAA2B;AAC/C,EAAA,MAAM,KAAA,uBAAY,GAAA,EAAY;AAC9B,EAAA,OAAO;AAAA,IACL,GAAA,EAAK,CAAC,MAAA,KAAW,OAAA,CAAQ,IAAI,MAAM,CAAA;AAAA,IACnC,GAAA,EAAK,CAAC,MAAA,KAAW;AACf,MAAA,OAAA,CAAQ,GAAA,CAAI,MAAA,CAAO,MAAA,EAAQ,MAAM,CAAA;AAAA,IACnC,CAAA;AAAA,IACA,MAAA,EAAQ,CAAC,MAAA,KAAW;AAClB,MAAA,OAAA,CAAQ,OAAO,MAAM,CAAA;AAAA,IACvB,CAAA;AAAA,IACA,OAAA,EAAS,CAAC,MAAA,KAAW;AACnB,MA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,mBAAA,CAAoB,CAAA,CAAE,iBAAiB,CAAA,EAAG,CAAA;AAC9F,EAAA,MAAM,UAAU,MAAM,4BAAA;AAAA,IACpB,EAAA,CAAG,EAAE,YAAY,CAAA;AAAA,IACjB,eAAA;AAAA,IACA,cAAA;AAAA,IACA,CAAA,CAAE,QAAA;AAAA,IACF;AAAA,GACF;AACA,EAAA,OAAO,OAAA;AACT","file":"chunk-NHPWXIA2.js","sourcesContent":["import type { Address, Hex } from \"viem\";\n\n/**\n * Server-side session records for the Kernel (on-chain) session flow, keyed by\n * Privy user id. Ported from templates/sponsored-session-app/lib/session-store.ts.\n *\n * WHAT IS STORED: the session private key (a hot key whose power is limited\n * ON-CHAIN by the call and timestamp policies until `validUntil`) and the\n * public approval. The owner's key never reaches the server.\n *\n * PRODUCTION: {@link createMemoryStore} is DEV-GRADE. It is lost on every\n * restart (the user simply starts a new session) and is not shared between\n * serverless instances. A production deployment must implement\n * {@link SessionStore} on a persistent database or KV AND keep\n * `sessionPrivateKey` encrypted at rest (KMS or an envelope key). Nothing else\n * in the SDK changes.\n */\nexport interface SessionRecord {\n userId: string;\n ownerAddress: Address;\n kernelAddress: Address;\n /** The session key's private half. Encrypt it at rest in any persistent store. */\n sessionPrivateKey: Hex;\n sessionKeyAddress: Address;\n permissionId: string;\n /** Unix seconds. The on-chain permission is invalid at and after this time. */\n validUntil: number;\n /** Present once the owner has signed the grant. */\n approval: string | null;\n /** Number of successful sponsored actions in this session. */\n actions: number;\n}\n\ntype MaybePromise<T> = T | Promise<T>;\n\n/**\n * Pluggable storage for {@link SessionRecord}s. Every method may be sync or\n * async. `tryLock` must be atomic per user: it returns `false` when an action\n * is already running for that user (a multi-instance deployment needs a\n * distributed lock, for example a Redis `SET NX PX`).\n */\nexport interface SessionStore {\n get(userId: string): MaybePromise<SessionRecord | undefined>;\n set(record: SessionRecord): MaybePromise<void>;\n delete(userId: string): MaybePromise<void>;\n tryLock(userId: string): MaybePromise<boolean>;\n unlock(userId: string): MaybePromise<void>;\n}\n\n/**\n * An in-memory {@link SessionStore} for development and tests. DEV-GRADE: not\n * persistent, not shared across instances, and the session key is held in\n * plaintext in process memory. Production needs an encrypted persistent store.\n *\n * @example\n * const store = createMemoryStore();\n */\nexport function createMemoryStore(): SessionStore {\n const records = new Map<string, SessionRecord>();\n const locks = new Set<string>();\n return {\n get: (userId) => records.get(userId),\n set: (record) => {\n records.set(record.userId, record);\n },\n delete: (userId) => {\n records.delete(userId);\n },\n tryLock: (userId) => {\n if (locks.has(userId)) return false;\n locks.add(userId);\n return true;\n },\n unlock: (userId) => {\n locks.delete(userId);\n },\n };\n}\n\n/**\n * True while the on-chain permission is still valid: approved and before expiry.\n *\n * @example\n * isLive(record, Math.floor(Date.now() / 1000));\n */\nexport function isLive(record: SessionRecord, nowSeconds: number): boolean {\n return record.approval !== null && nowSeconds < record.validUntil;\n}\n","import { deserializePermissionAccount, serializePermissionAccount, toPermissionValidator } from \"@zerodev/permissions\";\nimport type { Policy } from \"@zerodev/permissions\";\nimport { CallPolicyVersion, toCallPolicy, toTimestampPolicy } from \"@zerodev/permissions/policies\";\nimport { toECDSASigner, toEmptyECDSASigner } from \"@zerodev/permissions/signers\";\nimport type { createKernelAccount } from \"@zerodev/sdk\";\nimport type { Abi, Address, Hex, PublicClient } from \"viem\";\nimport { generatePrivateKey, privateKeyToAccount } from \"viem/accounts\";\n\nimport { ENTRY_POINT_V07 } from \"../aa/clients.js\";\nimport { KERNEL_VERSION, toPepuKernelAccount } from \"../aa/kernel.js\";\nimport type { KernelOwner, KernelSmartAccount } from \"../aa/kernel.js\";\nimport { assertCalls, findFunction } from \"./scope.js\";\nimport type { KernelSessionCall } from \"./scope.js\";\n\nexport { KERNEL_VERSION, getKernelAddress } from \"../aa/kernel.js\";\nexport type { KernelOwner, KernelSmartAccount } from \"../aa/kernel.js\";\nexport { createMemoryStore, isLive } from \"./store.js\";\nexport type { SessionRecord, SessionStore } from \"./store.js\";\nexport { checkApproval, describeKernelSessionScope, isCallInScope, parseApproval } from \"./scope.js\";\nexport type { ApprovalCheck, KernelSessionCall, KernelSessionScope, ParsedApproval } from \"./scope.js\";\n\n/**\n * `@pepu-chain/sdk/session/kernel`: on-chain session keys with ZeroDev Kernel\n * permissions. Extracted from templates/sponsored-session-app/lib/{kernel,\n * session-policy,approval}.ts and built on `toPepuKernelAccount`\n * (`plugins.regular`).\n *\n * The scope is enforced ON-CHAIN by ZeroDev's policy contracts, which the\n * user's Kernel account calls during UserOperation validation:\n *\n * - Call policy v0.0.4: only the listed targets and function selectors, with a\n * native value no larger than `valueLimit` (default 0).\n * - Timestamp policy: the permission is invalid outside `validAfter`..`validUntil`.\n *\n * A UserOperation outside this scope is rejected by the EntryPoint itself, no\n * matter who relays it or what the app backend does.\n *\n * Deployed on PEPU mainnet (eth_getCode verified 2026-10-02): Kernel v3.1\n * factory 0xaac5D4240AF87249B3f71BC8E4A2cae074A3E419, ECDSA validator\n * 0x845ADb2C711129d4f3966735eD98a9F09fC4cE57, ECDSA signer module\n * 0x6A6F069E2a08c2468e7724Ab3250CdBFBA14D4FF, call policy v0.0.4 and the\n * timestamp policy below. Call policy v0.0.5 is NOT deployed on PEPU, so the\n * version is pinned.\n *\n * Optional peers: `@zerodev/sdk`, `@zerodev/permissions`, `@zerodev/ecdsa-validator`.\n */\n\n/** Call policy v0.0.4. Pinned: v0.0.5 is not deployed on PEPU mainnet. */\nexport const CALL_POLICY_V0_0_4_ADDRESS: Address = \"0x9a52283276A0ec8740DF50bF01B28A80D880eaf2\";\n/** ZeroDev timestamp policy on PEPU mainnet. */\nexport const TIMESTAMP_POLICY_ADDRESS: Address = \"0xB9f8f524bE6EcD8C945b1b87f9ae5C192FdCE20F\";\n\n/**\n * Worst-case gas the paymaster policy service RESERVES per sponsored operation,\n * measured on PEPU mainnet with the sponsored-session-app template: the first\n * operation of a session (account deploy plus enabling the permission) about\n * 20.5 PEPU, later operations about 6.9 PEPU. The real first-session cost was\n * about 12.8 PEPU for two operations. Size per-user hourly and daily spend\n * caps above these, or users hit `trailing-hour spend ... would exceed cap`\n * after their first action.\n */\nexport const SESSION_GAS_RESERVATION_PEPU = { firstOperation: 20.5, laterOperation: 6.9 } as const;\n\ntype ZeroDevClient = Parameters<typeof createKernelAccount>[0];\n\n/** Type-level bridge for ZeroDev's own viem copy (same object at runtime). */\nfunction zd(client: PublicClient): ZeroDevClient {\n return client as unknown as ZeroDevClient;\n}\n\n/**\n * The on-chain policies for one session: call policy v0.0.4 plus the timestamp\n * policy. Pure and deterministic given its input. Only the named function\n * fragments go into the policy, which keeps the grant small.\n *\n * @example\n * const policies = buildKernelSessionPolicies({\n * calls: [{ target: tapScore, abi: tapScoreAbi, functionName: \"tap\" }],\n * validUntil: Math.floor(Date.now() / 1000) + 900,\n * });\n */\nexport function buildKernelSessionPolicies(p: {\n calls: readonly KernelSessionCall[];\n validUntil: number;\n validAfter?: number;\n}): Policy[] {\n assertCalls(p.calls);\n return [\n toCallPolicy({\n policyVersion: CallPolicyVersion.V0_0_4,\n permissions: p.calls.map((c) => ({\n target: c.target,\n valueLimit: c.valueLimit ?? 0n,\n abi: [findFunction(c)] as Abi,\n functionName: c.functionName,\n })),\n } as Parameters<typeof toCallPolicy>[0]),\n toTimestampPolicy({ validAfter: p.validAfter ?? 0, validUntil: p.validUntil }),\n ];\n}\n\n/**\n * A fresh random session key. SERVER ONLY: the private key must never reach\n * the browser. Only the address is sent to the owner for approval.\n *\n * @example\n * const { privateKey, address } = generateSessionKey();\n */\nexport function generateSessionKey(): { privateKey: Hex; address: Address } {\n const privateKey = generatePrivateKey();\n return { privateKey, address: privateKeyToAccount(privateKey).address };\n}\n\nfunction permissionFor(publicClient: PublicClient, sessionKeyAddress: Address, policies: Policy[]) {\n return toPermissionValidator(zd(publicClient), {\n entryPoint: ENTRY_POINT_V07,\n kernelVersion: KERNEL_VERSION,\n signer: toEmptyECDSASigner(sessionKeyAddress),\n policies,\n });\n}\n\n/**\n * The permission id the chain derives for this session key plus these\n * policies. The server compares it with a browser-supplied approval.\n *\n * @example\n * const permissionId = await expectedPermissionId({ publicClient, sessionKeyAddress, policies });\n */\nexport async function expectedPermissionId(p: {\n publicClient: PublicClient;\n sessionKeyAddress: Address;\n policies: Policy[];\n}): Promise<string> {\n const permission = await permissionFor(p.publicClient, p.sessionKeyAddress, p.policies);\n const { permissionId } = permission.getPluginSerializationParams();\n if (!permissionId) throw new Error(\"Could not derive the permission id.\");\n return permissionId;\n}\n\n/**\n * In the user's browser: the owner (the Privy embedded wallet, the only thing\n * that can authorize a session) signs ONE EIP-712 message that enables a\n * permission validator on their Kernel account. That signature is the whole\n * grant. It names the session key's public address (never its private key)\n * and the policies. The returned `approval` holds no secret: it is the enable\n * signature plus the policy parameters, useless without the session key.\n *\n * @example\n * const { approval, kernelAddress } = await approveKernelSession({\n * publicClient, owner: walletClient, sessionKeyAddress, policies,\n * });\n */\nexport async function approveKernelSession(p: {\n publicClient: PublicClient;\n owner: KernelOwner;\n sessionKeyAddress: Address;\n policies: Policy[];\n}): Promise<{ approval: string; kernelAddress: Address }> {\n const regular = await permissionFor(p.publicClient, p.sessionKeyAddress, p.policies);\n const account = await toPepuKernelAccount({\n publicClient: p.publicClient,\n owner: p.owner,\n plugins: { regular },\n });\n const approval = await serializePermissionAccount(account as never);\n return { approval, kernelAddress: account.address };\n}\n\n/**\n * On the server: rebuild the session's Kernel account from the approval and\n * the server-held session key (an ECDSA signer for that key). No owner\n * signature is involved. Pass the result to `createPepuSponsoredClient`.\n *\n * @example\n * const account = await loadKernelSessionAccount({ publicClient, approval, sessionPrivateKey });\n */\nexport async function loadKernelSessionAccount(p: {\n publicClient: PublicClient;\n approval: string;\n sessionPrivateKey: Hex;\n}): Promise<KernelSmartAccount> {\n const sessionSigner = await toECDSASigner({ signer: privateKeyToAccount(p.sessionPrivateKey) });\n const account = await deserializePermissionAccount(\n zd(p.publicClient),\n ENTRY_POINT_V07,\n KERNEL_VERSION,\n p.approval,\n sessionSigner,\n );\n return account as unknown as KernelSmartAccount;\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ENTRY_POINT_V07, createPepuPaymasterClient, estimatePepuUserOpFees, requireBundlerUrl } from './chunk-
|
|
1
|
+
import { ENTRY_POINT_V07, createPepuPaymasterClient, estimatePepuUserOpFees, requireBundlerUrl } from './chunk-QZKUPCUD.js';
|
|
2
2
|
import { normalizeCalls } from './chunk-VBH3JLQ5.js';
|
|
3
|
-
import { describeUserOpFailure } from './chunk-
|
|
3
|
+
import { describeUserOpFailure } from './chunk-GFKIM7HT.js';
|
|
4
4
|
import { txUrl } from './chunk-J6UXXHBE.js';
|
|
5
5
|
import { resolvePepuEndpoints } from './chunk-XC4IBCI2.js';
|
|
6
6
|
import { pepuMainnet } from './chunk-VTQIHMF3.js';
|
|
@@ -85,5 +85,5 @@ async function sendSponsored(p) {
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
export { KERNEL_VERSION, createPepuSponsoredClient, getKernelAddress, sendSponsored, toPepuKernelAccount };
|
|
88
|
-
//# sourceMappingURL=chunk-
|
|
89
|
-
//# sourceMappingURL=chunk-
|
|
88
|
+
//# sourceMappingURL=chunk-QIDMFFAQ.js.map
|
|
89
|
+
//# sourceMappingURL=chunk-QIDMFFAQ.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/aa/kernel.ts"],"names":[],"mappings":";;;;;;;;;;AAiCO,IAAM,iBAAiB,SAAA,CAAU;AAUxC,SAAS,GAAG,MAAA,EAAqC;AAC/C,EAAA,OAAO,MAAA;AACT;AAUA,SAAS,mBAAA,GAAoC;AAC3C,EAAA,OAAO,kBAAA,CAAmB,EAAE,KAAA,EAAO,WAAA,EAAa,SAAA,EAAW,KAAK,oBAAA,EAAqB,CAAE,MAAM,CAAA,EAAG,CAAA;AAClG;AAWA,eAAsB,oBAAoB,CAAA,EAUV;AAC9B,EAAA,MAAM,OAAO,MAAM,sBAAA,CAAuB,EAAA,CAAG,CAAA,CAAE,YAAY,C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AQ,eAAA;AACxC,IAAA,OAAO;AAAA,MACL,UAAA;AAAA,MACA,eAAA;AAAA,MACA,SAAS,OAAA,CAAQ,OAAA;AAAA,MACjB,SAAA,EAAW,QAAQ,SAAA,IAAa,IAAA;AAAA,MAChC,kBAAkB,OAAA,CAAQ,aAAA;AAAA,MAC1B,WAAA,EAAa,KAAA,CAAM,WAAA,EAAa,eAAe;AAAA,KACjD;AAAA,EACF,SAAS,CAAA,EAAG;AACV,IAAA,MAAM,sBAAsB,CAAC,CAAA;AAAA,EAC/B;AACF","file":"chunk-ZB6SVBK4.js","sourcesContent":["/**\n * @pepu-chain/sdk/aa/kernel: Kernel v3.1 smart account plus sponsored-send\n * helpers for the \"direct\" transport (your own bundler and paymaster URLs).\n * Needs the optional peers `@zerodev/sdk` and `@zerodev/ecdsa-validator`.\n *\n * This is the only module in the SDK (with `session/kernel` and `combo`) that\n * imports ZeroDev. Ported from `templates/sponsored-session-app/lib/kernel.ts`\n * (Kernel v3.1 build, 20% fee headroom because Alto lacks\n * `zd_getUserOperationGasPrice`).\n *\n * Session keys: `toPepuKernelAccount` takes an optional `plugins.regular`\n * validator, which is the plug point WP-B6 (`/session/kernel`, `/combo`) uses\n * to add a permission validator on top of the ECDSA root.\n */\nimport { signerToEcdsaValidator } from \"@zerodev/ecdsa-validator\";\nimport { constants, createKernelAccount, createKernelAccountClient } from \"@zerodev/sdk\";\nimport type { Signer } from \"@zerodev/sdk/types\";\nimport { createPublicClient, http } from \"viem\";\nimport type { Address, Hex, LocalAccount, PublicClient, WalletClient } from \"viem\";\n\nimport { pepuMainnet } from \"../chains.js\";\nimport { resolvePepuEndpoints } from \"../endpoints.js\";\nimport { txUrl } from \"../explorer.js\";\nimport type { PaymasterContext } from \"../erc7677.js\";\nimport { normalizeCalls } from \"./calls.js\";\nimport { ENTRY_POINT_V07, createPepuPaymasterClient, estimatePepuUserOpFees, requireBundlerUrl } from \"./clients.js\";\nimport { describeUserOpFailure } from \"./describe.js\";\nimport type { Call } from \"./types.js\";\n\nexport type { Call } from \"./types.js\";\nexport { encodeKernelExecute } from \"./calls.js\";\n\n/** Kernel v3.1, the version deployed on PEPU mainnet (factory in the contract registry). */\nexport const KERNEL_VERSION = constants.KERNEL_V3_1;\n\ntype ZeroDevClient = Parameters<typeof createKernelAccount>[0];\ntype KernelAccountParams = Parameters<typeof createKernelAccount>[1];\n\n/**\n * The ZeroDev packages resolve their own copy of viem as a peer. In a monorepo\n * with several viem installs two identical `PublicClient` types are nominally\n * different; this is a type-level bridge only (same object at runtime).\n */\nfunction zd(client: PublicClient): ZeroDevClient {\n return client as unknown as ZeroDevClient;\n}\n\n/** The Kernel account type this module builds. */\nexport type KernelSmartAccount = Awaited<ReturnType<typeof createKernelAccount>>;\n/** The sponsored client type {@link createPepuSponsoredClient} returns. */\nexport type KernelAccountClient = ReturnType<typeof createKernelAccountClient>;\n\n/** Anything that can sign for the Kernel owner. */\nexport type KernelOwner = LocalAccount | Signer | WalletClient;\n\nfunction defaultPublicClient(): PublicClient {\n return createPublicClient({ chain: pepuMainnet, transport: http(resolvePepuEndpoints().rpcUrl) }) as PublicClient;\n}\n\n/**\n * Build a Kernel v3.1 smart account owned by `owner` (ECDSA root validator).\n * The address depends only on the owner and `index`, never on a session.\n * Pass `plugins.regular` to add a permission (session-key) validator on top\n * of the root; that is how `@pepu-chain/sdk/session/kernel` builds on this.\n *\n * @example\n * const account = await toPepuKernelAccount({ publicClient, owner: privateKeyToAccount(key) });\n */\nexport async function toPepuKernelAccount(p: {\n publicClient: PublicClient;\n owner: KernelOwner;\n index?: bigint;\n /**\n * `regular` is a ZeroDev validator plugin, for example the permission\n * validator from `@zerodev/permissions` (see `@pepu-chain/sdk/session/kernel`).\n * Typed as `object` so this entry does not need `@zerodev/permissions` types.\n */\n plugins?: { regular?: object };\n}): Promise<KernelSmartAccount> {\n const sudo = await signerToEcdsaValidator(zd(p.publicClient), {\n signer: p.owner as Signer,\n entryPoint: ENTRY_POINT_V07,\n kernelVersion: KERNEL_VERSION,\n });\n return createKernelAccount(zd(p.publicClient), {\n entryPoint: ENTRY_POINT_V07,\n kernelVersion: KERNEL_VERSION,\n plugins: { sudo, ...(p.plugins?.regular ? { regular: p.plugins.regular } : {}) },\n ...(p.index !== undefined ? { index: p.index } : {}),\n } as KernelAccountParams);\n}\n\nfunction toEmptyAccount(address: Address): LocalAccount {\n const refuse = async (): Promise<never> => {\n throw new Error(\"read-only account cannot sign\");\n };\n return {\n address,\n type: \"local\",\n source: \"custom\",\n publicKey: \"0x\" as Hex,\n signMessage: refuse,\n signTransaction: refuse,\n signTypedData: refuse,\n } as unknown as LocalAccount;\n}\n\n/**\n * The counterfactual Kernel address for an owner, with no signature needed.\n * Lifted from `templates/sponsored-session-app/lib/kernel.ts`.\n *\n * @example\n * const smartAccount = await getKernelAddress(publicClient, ownerAddress);\n */\nexport async function getKernelAddress(publicClient: PublicClient, owner: Address): Promise<Address> {\n const account = await toPepuKernelAccount({ publicClient, owner: toEmptyAccount(owner) });\n return account.address;\n}\n\n/**\n * A Kernel client that sends through YOUR bundler and has gas paid by YOUR\n * paymaster (ERC-7677). Fees come from the chain with 20% headroom.\n *\n * @example\n * const client = createPepuSponsoredClient({ account, paymasterContext: { privyAccessToken } });\n */\nexport function createPepuSponsoredClient(p: {\n account: KernelSmartAccount;\n bundlerUrl?: string;\n paymasterUrl?: string;\n /** Project client token; builds the ERC-7677 URL against the paymaster base when no URL is configured. */\n paymasterToken?: string;\n paymasterContext?: PaymasterContext;\n publicClient?: PublicClient;\n}): KernelAccountClient {\n const publicClient = p.publicClient ?? defaultPublicClient();\n const paymaster = createPepuPaymasterClient({\n ...(p.paymasterUrl !== undefined ? { paymasterUrl: p.paymasterUrl } : {}),\n ...(p.paymasterToken !== undefined ? { paymasterToken: p.paymasterToken } : {}),\n ...(p.paymasterContext ? { context: p.paymasterContext } : {}),\n });\n return createKernelAccountClient({\n account: p.account,\n chain: pepuMainnet,\n client: zd(publicClient),\n bundlerTransport: http(requireBundlerUrl(p.bundlerUrl)),\n paymaster,\n userOperation: { estimateFeesPerGas: async () => estimatePepuUserOpFees(publicClient) },\n } as unknown as Parameters<typeof createKernelAccountClient>[0]);\n}\n\n/** Result of {@link sendSponsored}. */\nexport interface SendSponsoredResult {\n userOpHash: Hex;\n transactionHash: Hex;\n success: boolean;\n paymaster: Address | null;\n actualGasCostWei: bigint;\n explorerUrl: string;\n}\n\n/**\n * Encode `calls`, send one UserOperation, wait for its receipt, and report\n * who paid. Failures are mapped through `describeUserOpFailure` (AAxx and\n * paymaster reasons become typed PepuErrors). Flow ported from\n * `sendSessionTap` in the sponsored-session-app template.\n *\n * @example\n * const r = await sendSponsored({ client, calls: [{ to, abi, functionName: \"tap\" }] });\n * console.log(r.paymaster, r.explorerUrl);\n */\nexport async function sendSponsored(p: {\n client: KernelAccountClient;\n calls: Call[];\n timeoutMs?: number;\n}): Promise<SendSponsoredResult> {\n const calls = normalizeCalls(p.calls);\n try {\n const account = p.client.account;\n if (!account) throw new Error(\"The Kernel client has no account.\");\n const callData = await account.encodeCalls(calls);\n const userOpHash = await p.client.sendUserOperation({ callData });\n const receipt = await p.client.waitForUserOperationReceipt({ hash: userOpHash, timeout: p.timeoutMs ?? 90_000 });\n const transactionHash = receipt.receipt.transactionHash;\n return {\n userOpHash,\n transactionHash,\n success: receipt.success,\n paymaster: receipt.paymaster ?? null,\n actualGasCostWei: receipt.actualGasCost,\n explorerUrl: txUrl(pepuMainnet, transactionHash),\n };\n } catch (e) {\n throw describeUserOpFailure(e);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/aa/kernel.ts"],"names":[],"mappings":";;;;;;;;;;AAiCO,IAAM,iBAAiB,SAAA,CAAU;AAUxC,SAAS,GAAG,MAAA,EAAqC;AAC/C,EAAA,OAAO,MAAA;AACT;AAUA,SAAS,mBAAA,GAAoC;AAC3C,EAAA,OAAO,kBAAA,CAAmB,EAAE,KAAA,EAAO,WAAA,EAAa,SAAA,EAAW,KAAK,oBAAA,EAAqB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2BAAA,CAA4B,EAAE,IAAA,EAAM,UAAA,EAAY,OAAA,EAAS,CAAA,CAAE,SAAA,IAAa,GAAA,EAAQ,CAAA;AAC/G,IAAA,MAAM,eAAA,GAAkB,QAAQ,OAAA,CAAQ,eAAA;AACxC,IAAA,OAAO;AAAA,MACL,UAAA;AAAA,MACA,eAAA;AAAA,MACA,SAAS,OAAA,CAAQ,OAAA;AAAA,MACjB,SAAA,EAAW,QAAQ,SAAA,IAAa,IAAA;AAAA,MAChC,kBAAkB,OAAA,CAAQ,aAAA;AAAA,MAC1B,WAAA,EAAa,KAAA,CAAM,WAAA,EAAa,eAAe;AAAA,KACjD;AAAA,EACF,SAAS,CAAA,EAAG;AACV,IAAA,MAAM,sBAAsB,CAAC,CAAA;AAAA,EAC/B;AACF","file":"chunk-QIDMFFAQ.js","sourcesContent":["/**\n * @pepu-chain/sdk/aa/kernel: Kernel v3.1 smart account plus sponsored-send\n * helpers for the \"direct\" transport (your own bundler and paymaster URLs).\n * Needs the optional peers `@zerodev/sdk` and `@zerodev/ecdsa-validator`.\n *\n * This is the only module in the SDK (with `session/kernel` and `combo`) that\n * imports ZeroDev. Ported from `templates/sponsored-session-app/lib/kernel.ts`\n * (Kernel v3.1 build, 20% fee headroom because Alto lacks\n * `zd_getUserOperationGasPrice`).\n *\n * Session keys: `toPepuKernelAccount` takes an optional `plugins.regular`\n * validator, which is the plug point WP-B6 (`/session/kernel`, `/combo`) uses\n * to add a permission validator on top of the ECDSA root.\n */\nimport { signerToEcdsaValidator } from \"@zerodev/ecdsa-validator\";\nimport { constants, createKernelAccount, createKernelAccountClient } from \"@zerodev/sdk\";\nimport type { Signer } from \"@zerodev/sdk/types\";\nimport { createPublicClient, http } from \"viem\";\nimport type { Address, Hex, LocalAccount, PublicClient, WalletClient } from \"viem\";\n\nimport { pepuMainnet } from \"../chains.js\";\nimport { resolvePepuEndpoints } from \"../endpoints.js\";\nimport { txUrl } from \"../explorer.js\";\nimport type { PaymasterContext } from \"../erc7677.js\";\nimport { normalizeCalls } from \"./calls.js\";\nimport { ENTRY_POINT_V07, createPepuPaymasterClient, estimatePepuUserOpFees, requireBundlerUrl } from \"./clients.js\";\nimport { describeUserOpFailure } from \"./describe.js\";\nimport type { Call } from \"./types.js\";\n\nexport type { Call } from \"./types.js\";\nexport { encodeKernelExecute } from \"./calls.js\";\n\n/** Kernel v3.1, the version deployed on PEPU mainnet (factory in the contract registry). */\nexport const KERNEL_VERSION = constants.KERNEL_V3_1;\n\ntype ZeroDevClient = Parameters<typeof createKernelAccount>[0];\ntype KernelAccountParams = Parameters<typeof createKernelAccount>[1];\n\n/**\n * The ZeroDev packages resolve their own copy of viem as a peer. In a monorepo\n * with several viem installs two identical `PublicClient` types are nominally\n * different; this is a type-level bridge only (same object at runtime).\n */\nfunction zd(client: PublicClient): ZeroDevClient {\n return client as unknown as ZeroDevClient;\n}\n\n/** The Kernel account type this module builds. */\nexport type KernelSmartAccount = Awaited<ReturnType<typeof createKernelAccount>>;\n/** The sponsored client type {@link createPepuSponsoredClient} returns. */\nexport type KernelAccountClient = ReturnType<typeof createKernelAccountClient>;\n\n/** Anything that can sign for the Kernel owner. */\nexport type KernelOwner = LocalAccount | Signer | WalletClient;\n\nfunction defaultPublicClient(): PublicClient {\n return createPublicClient({ chain: pepuMainnet, transport: http(resolvePepuEndpoints().rpcUrl) }) as PublicClient;\n}\n\n/**\n * Build a Kernel v3.1 smart account owned by `owner` (ECDSA root validator).\n * The address depends only on the owner and `index`, never on a session.\n * Pass `plugins.regular` to add a permission (session-key) validator on top\n * of the root; that is how `@pepu-chain/sdk/session/kernel` builds on this.\n *\n * @example\n * const account = await toPepuKernelAccount({ publicClient, owner: privateKeyToAccount(key) });\n */\nexport async function toPepuKernelAccount(p: {\n publicClient: PublicClient;\n owner: KernelOwner;\n index?: bigint;\n /**\n * `regular` is a ZeroDev validator plugin, for example the permission\n * validator from `@zerodev/permissions` (see `@pepu-chain/sdk/session/kernel`).\n * Typed as `object` so this entry does not need `@zerodev/permissions` types.\n */\n plugins?: { regular?: object };\n}): Promise<KernelSmartAccount> {\n const sudo = await signerToEcdsaValidator(zd(p.publicClient), {\n signer: p.owner as Signer,\n entryPoint: ENTRY_POINT_V07,\n kernelVersion: KERNEL_VERSION,\n });\n return createKernelAccount(zd(p.publicClient), {\n entryPoint: ENTRY_POINT_V07,\n kernelVersion: KERNEL_VERSION,\n plugins: { sudo, ...(p.plugins?.regular ? { regular: p.plugins.regular } : {}) },\n ...(p.index !== undefined ? { index: p.index } : {}),\n } as KernelAccountParams);\n}\n\nfunction toEmptyAccount(address: Address): LocalAccount {\n const refuse = async (): Promise<never> => {\n throw new Error(\"read-only account cannot sign\");\n };\n return {\n address,\n type: \"local\",\n source: \"custom\",\n publicKey: \"0x\" as Hex,\n signMessage: refuse,\n signTransaction: refuse,\n signTypedData: refuse,\n } as unknown as LocalAccount;\n}\n\n/**\n * The counterfactual Kernel address for an owner, with no signature needed.\n * Lifted from `templates/sponsored-session-app/lib/kernel.ts`.\n *\n * @example\n * const smartAccount = await getKernelAddress(publicClient, ownerAddress);\n */\nexport async function getKernelAddress(publicClient: PublicClient, owner: Address): Promise<Address> {\n const account = await toPepuKernelAccount({ publicClient, owner: toEmptyAccount(owner) });\n return account.address;\n}\n\n/**\n * A Kernel client that sends through YOUR bundler and has gas paid by YOUR\n * paymaster (ERC-7677). Fees come from the chain with 20% headroom.\n *\n * @example\n * const client = createPepuSponsoredClient({ account, paymasterContext: { privyAccessToken } });\n */\nexport function createPepuSponsoredClient(p: {\n account: KernelSmartAccount;\n bundlerUrl?: string;\n paymasterUrl?: string;\n /** Project client token; builds the ERC-7677 URL against the paymaster base when no URL is configured. */\n paymasterToken?: string;\n paymasterContext?: PaymasterContext;\n publicClient?: PublicClient;\n}): KernelAccountClient {\n const publicClient = p.publicClient ?? defaultPublicClient();\n const paymaster = createPepuPaymasterClient({\n ...(p.paymasterUrl !== undefined ? { paymasterUrl: p.paymasterUrl } : {}),\n ...(p.paymasterToken !== undefined ? { paymasterToken: p.paymasterToken } : {}),\n ...(p.paymasterContext ? { context: p.paymasterContext } : {}),\n });\n return createKernelAccountClient({\n account: p.account,\n chain: pepuMainnet,\n client: zd(publicClient),\n bundlerTransport: http(requireBundlerUrl(p.bundlerUrl)),\n paymaster,\n userOperation: { estimateFeesPerGas: async () => estimatePepuUserOpFees(publicClient) },\n } as unknown as Parameters<typeof createKernelAccountClient>[0]);\n}\n\n/** Result of {@link sendSponsored}. */\nexport interface SendSponsoredResult {\n userOpHash: Hex;\n transactionHash: Hex;\n success: boolean;\n paymaster: Address | null;\n actualGasCostWei: bigint;\n explorerUrl: string;\n}\n\n/**\n * Encode `calls`, send one UserOperation, wait for its receipt, and report\n * who paid. Failures are mapped through `describeUserOpFailure` (AAxx and\n * paymaster reasons become typed PepuErrors). Flow ported from\n * `sendSessionTap` in the sponsored-session-app template.\n *\n * @example\n * const r = await sendSponsored({ client, calls: [{ to, abi, functionName: \"tap\" }] });\n * console.log(r.paymaster, r.explorerUrl);\n */\nexport async function sendSponsored(p: {\n client: KernelAccountClient;\n calls: Call[];\n timeoutMs?: number;\n}): Promise<SendSponsoredResult> {\n const calls = normalizeCalls(p.calls);\n try {\n const account = p.client.account;\n if (!account) throw new Error(\"The Kernel client has no account.\");\n const callData = await account.encodeCalls(calls);\n const userOpHash = await p.client.sendUserOperation({ callData });\n const receipt = await p.client.waitForUserOperationReceipt({ hash: userOpHash, timeout: p.timeoutMs ?? 90_000 });\n const transactionHash = receipt.receipt.transactionHash;\n return {\n userOpHash,\n transactionHash,\n success: receipt.success,\n paymaster: receipt.paymaster ?? null,\n actualGasCostWei: receipt.actualGasCost,\n explorerUrl: txUrl(pepuMainnet, transactionHash),\n };\n } catch (e) {\n throw describeUserOpFailure(e);\n }\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { buildErc7677Url } from './chunk-
|
|
1
|
+
import { buildErc7677Url } from './chunk-RSPAN44L.js';
|
|
2
2
|
import { resolvePepuEndpoints, PEPU_ENV } from './chunk-XC4IBCI2.js';
|
|
3
3
|
import { pepuMainnet } from './chunk-VTQIHMF3.js';
|
|
4
4
|
import { PepuConfigError } from './chunk-6DSZ4Z2N.js';
|
|
@@ -62,5 +62,5 @@ function createPepuBundlerClient(o) {
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
export { ENTRY_POINT_V07, createPepuBundlerClient, createPepuPaymasterClient, estimatePepuUserOpFees, requireBundlerUrl };
|
|
65
|
-
//# sourceMappingURL=chunk-
|
|
66
|
-
//# sourceMappingURL=chunk-
|
|
65
|
+
//# sourceMappingURL=chunk-QZKUPCUD.js.map
|
|
66
|
+
//# sourceMappingURL=chunk-QZKUPCUD.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/aa/clients.ts"],"names":[],"mappings":";;;;;;;AAYO,IAAM,eAAA,GAAkB;AAAA,EAC7B,OAAA,EAAS,4CAAA;AAAA,EACT,OAAA,EAAS;AACX;AAGA,IAAM,gBAAA,GAAmB,GAAA;AACzB,IAAM,gBAAA,GAAmB,GAAA;AAWzB,eAAsB,uBACpB,YAAA,EACiE;AACjE,EAAA,MAAM,IAAA,GAAO,MAAM,YAAA,CAAa,kBAAA,EAAmB;AACnD,EAAA,OAAO;AAAA,IACL,YAAA,EAAe,IAAA,CAAK,YAAA,GAAe,gBAAA,GAAoB,gBAAA;AAAA,IACvD,sBAAsB,IAAA,CAAK;AAAA,GAC7B;AACF;AAGO,SAAS,kBAAkB,QAAA,EAA2B;AAC3D,EAAA,MAAM,EAAE,UAAA,EAAW,GAAI,oBAAA,CAAqB,QAAA,KAAa,MAAA,GAAY,EAAC,GAAI,EAAE,UAAA,EAAY,QAAA,EAAU,CAAA;AAClG,EAAA,IAAI,eAAe,IAAA,EAAM;AACvB,IAAA,MAAM,IAAI,eAAA,CAAgB,oBAAA,EAAsB,CAAA,oBAAA,EAAuB,QAAA,CAAS,UAAU,CAAA,oBAAA,CAAA,EAAwB;AAAA,MAChH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C,KAAK,OAAO,MAAA;AACjB,EAAA,OAAO;AAAA,IACL,GAAG,MAAA;AAAA,IACH,gBAAA,EAAkB,CAAC,CAAA,KAAM,MAAA,CAAO,gBAAA,CAAiB,EAAE,GAAG,CAAA,EAAG,OAAA,EAAS,CAAA,CAAE,OAAA,IAAW,GAAA,EAAK,CAAA;AAAA,IACpF,oBAAA,EAAsB,CAAC,CAAA,KAAM,MAAA,CAAO,oBAAA,CAAqB,EAAE,GAAG,CAAA,EAAG,OAAA,EAAS,CAAA,CAAE,OAAA,IAAW,GAAA,EAAK;AAAA,GAC9F;AACF;AAUO,SAAS,wBAAwB,CAAA,EAMtB;AAChB,EAAA,MAAM,MAAA,GAAS,sBAAqB,CAAE,MAAA;AACtC,EAAA,MAAM,YAAA,GAAe,CAAA,CAAE,YAAA,IAAgB,kBAAA,CAAmB,EAAE,KAAA,EAAO,WAAA,EAAa,SAAA,EAAW,IAAA,CAAK,MAAM,CAAA,EAAG,CAAA;AACzG,EAAA,OAAO,mBAAA,CAAoB;AAAA,IACzB,SAAS,CAAA,CAAE,OAAA;AAAA,IACX,KAAA,EAAO,WAAA;AAAA,IACP,MAAA,EAAQ,YAAA;AAAA,IACR,SAAA,EAAW,IAAA,CAAK,iBAAA,CAAkB,CAAA,CAAE,UAAU,CAAC,CAAA;AAAA,IAC/C,GAAI,EAAE,SAAA,GAAY,EAAE,WAAW,CAAA,CAAE,SAAA,KAAc,EAAC;AAAA,IAChD,GAAI,EAAE,gBAAA,GAAmB,EAAE,kBAAkB,CAAA,CAAE,gBAAA,KAAqB,EAAC;AAAA,IACrE,eAAe,EAAE,kBAAA,EAAoB,YAAY,sBAAA,CAAuB,YAAY,CAAA;AAAE,GACvF,CAAA;AACH","file":"chunk-QZKUPCUD.js","sourcesContent":["import { createPublicClient, http } from \"viem\";\nimport type { PublicClient } from \"viem\";\nimport { createBundlerClient, createPaymasterClient } from \"viem/account-abstraction\";\nimport type { BundlerClient, PaymasterClient, SmartAccount } from \"viem/account-abstraction\";\n\nimport { pepuMainnet } from \"../chains.js\";\nimport { PEPU_ENV, resolvePepuEndpoints } from \"../endpoints.js\";\nimport { PepuConfigError } from \"../errors.js\";\nimport type { PaymasterContext } from \"../erc7677.js\";\nimport { buildErc7677Url } from \"../paymaster/api.js\";\n\n/** EntryPoint v0.7, the only version PEPU's bundler and paymaster speak. */\nexport const ENTRY_POINT_V07 = {\n address: \"0x0000000071727De22E5E9d8BAf0edAc6f37da032\",\n version: \"0.7\",\n} as const;\n\n/** Fee headroom numerator/denominator: 12/10 = +20%. */\nconst FEE_HEADROOM_NUM = 12n;\nconst FEE_HEADROOM_DEN = 10n;\n\n/**\n * The Alto-compatible fee estimator: the chain's own `estimateFeesPerGas`,\n * with `maxFeePerGas` x 1.2. Alto does not implement ZeroDev's\n * `zd_getUserOperationGasPrice`, so the default estimator would fail.\n * Ported from `templates/sponsored-session-app/lib/kernel.ts`.\n *\n * @example\n * const fees = await estimatePepuUserOpFees(publicClient);\n */\nexport async function estimatePepuUserOpFees(\n publicClient: Pick<PublicClient, \"estimateFeesPerGas\">,\n): Promise<{ maxFeePerGas: bigint; maxPriorityFeePerGas: bigint }> {\n const fees = await publicClient.estimateFeesPerGas();\n return {\n maxFeePerGas: (fees.maxFeePerGas * FEE_HEADROOM_NUM) / FEE_HEADROOM_DEN,\n maxPriorityFeePerGas: fees.maxPriorityFeePerGas,\n };\n}\n\n/** Resolve the bundler URL or throw `CONFIG_MISSING_ENV` naming the variable. */\nexport function requireBundlerUrl(explicit?: string): string {\n const { bundlerUrl } = resolvePepuEndpoints(explicit === undefined ? {} : { bundlerUrl: explicit });\n if (bundlerUrl === null) {\n throw new PepuConfigError(\"CONFIG_MISSING_ENV\", `No bundler URL. Set ${PEPU_ENV.bundlerUrl} or pass bundlerUrl.`, {\n hint: \"The hosted PEPU bundler is the default; if it was cleared, set PEPU_BUNDLER_URL to https://bundler.pepeunchained.com or your own bundler.\",\n });\n }\n return bundlerUrl;\n}\n\n/**\n * Resolve the complete ERC-7677 paymaster URL or throw `CONFIG_MISSING_ENV`.\n * Order: `explicit` URL, then `PEPU_PAYMASTER_URL`, then `token` (a project client token, built against the\n * paymaster base: the hosted service unless a custom URL is configured). The hosted paymaster has no tokenless\n * ERC-7677 URL, because the token names the project (or free-tier app) that is billed.\n */\nexport function requirePaymasterUrl(explicit?: string, token?: string): string {\n const { paymasterUrl, paymasterBaseUrl } = resolvePepuEndpoints(explicit === undefined ? {} : { paymasterUrl: explicit });\n if (paymasterUrl !== null) return paymasterUrl;\n if (token !== undefined && token.trim() !== \"\" && paymasterBaseUrl !== null) {\n return buildErc7677Url({ baseUrl: paymasterBaseUrl, token });\n }\n throw new PepuConfigError(\"CONFIG_MISSING_ENV\", `No ERC-7677 paymaster URL. Set ${PEPU_ENV.paymasterUrl} or pass paymasterUrl / paymasterToken.`, {\n hint: \"The hosted paymaster (https://paymaster.pepeunchained.com) needs your project's client token: set PEPU_PAYMASTER_URL to https://paymaster.pepeunchained.com/v2/paymaster/<client token>.\",\n });\n}\n\n/**\n * An ERC-7677 paymaster client for PEPU (viem `createPaymasterClient`), using\n * the endpoints registry for the URL. A `context` (for example\n * `buildPaymasterContext({ privyAccessToken })`) is injected into every\n * `pm_getPaymasterStubData` and `pm_getPaymasterData` call unless the caller\n * passes one.\n *\n * @example\n * const paymaster = createPepuPaymasterClient({\n * context: buildPaymasterContext({ privyAccessToken }),\n * });\n */\nexport function createPepuPaymasterClient(\n o: { paymasterUrl?: string; paymasterToken?: string; context?: PaymasterContext } = {},\n): PaymasterClient {\n const client = createPaymasterClient({ transport: http(requirePaymasterUrl(o.paymasterUrl, o.paymasterToken)) });\n const ctx = o.context;\n if (!ctx) return client;\n return {\n ...client,\n getPaymasterData: (p) => client.getPaymasterData({ ...p, context: p.context ?? ctx }),\n getPaymasterStubData: (p) => client.getPaymasterStubData({ ...p, context: p.context ?? ctx }),\n };\n}\n\n/**\n * A viem bundler client for PEPU's bundler, with the fee estimator\n * pre-wired ({@link estimatePepuUserOpFees}).\n *\n * @example\n * const bundler = createPepuBundlerClient({ account, paymaster: createPepuPaymasterClient() });\n * const hash = await bundler.sendUserOperation({ calls: [{ to, data }] });\n */\nexport function createPepuBundlerClient(o: {\n bundlerUrl?: string;\n account: SmartAccount;\n paymaster?: PaymasterClient;\n paymasterContext?: PaymasterContext;\n publicClient?: PublicClient;\n}): BundlerClient {\n const rpcUrl = resolvePepuEndpoints().rpcUrl;\n const publicClient = o.publicClient ?? createPublicClient({ chain: pepuMainnet, transport: http(rpcUrl) });\n return createBundlerClient({\n account: o.account,\n chain: pepuMainnet,\n client: publicClient,\n transport: http(requireBundlerUrl(o.bundlerUrl)),\n ...(o.paymaster ? { paymaster: o.paymaster } : {}),\n ...(o.paymasterContext ? { paymasterContext: o.paymasterContext } : {}),\n userOperation: { estimateFeesPerGas: async () => estimatePepuUserOpFees(publicClient) },\n }) as BundlerClient;\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkK7JSQPZO_cjs = require('./chunk-K7JSQPZO.cjs');
|
|
4
4
|
var chunkDPCZJLB3_cjs = require('./chunk-DPCZJLB3.cjs');
|
|
5
5
|
var viem = require('viem');
|
|
6
6
|
|
|
@@ -19,7 +19,7 @@ function buildPaymasterContext(entries = {}) {
|
|
|
19
19
|
return context;
|
|
20
20
|
}
|
|
21
21
|
function buildParams(options) {
|
|
22
|
-
const entryPointEntry =
|
|
22
|
+
const entryPointEntry = chunkK7JSQPZO_cjs.getContract(chunkDPCZJLB3_cjs.pepuMainnet.id, "entryPoint07");
|
|
23
23
|
const entryPoint = options.entryPoint ?? (entryPointEntry?.status === "deployed" ? entryPointEntry.address : void 0);
|
|
24
24
|
if (!entryPoint) throw new Error("buildPaymasterRequest: no EntryPoint v0.7 address available.");
|
|
25
25
|
const chainId = viem.toHex(options.chainId ?? chunkDPCZJLB3_cjs.pepuMainnet.id);
|
|
@@ -45,5 +45,5 @@ function buildPaymasterDataRequest(options) {
|
|
|
45
45
|
exports.buildPaymasterContext = buildPaymasterContext;
|
|
46
46
|
exports.buildPaymasterDataRequest = buildPaymasterDataRequest;
|
|
47
47
|
exports.buildPaymasterStubDataRequest = buildPaymasterStubDataRequest;
|
|
48
|
-
//# sourceMappingURL=chunk-
|
|
49
|
-
//# sourceMappingURL=chunk-
|
|
48
|
+
//# sourceMappingURL=chunk-RCMKPJZO.cjs.map
|
|
49
|
+
//# sourceMappingURL=chunk-RCMKPJZO.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/erc7677.ts"],"names":["getContract","pepuMainnet","toHex"],"mappings":";;;;;;AAkGO,SAAS,qBAAA,CACd,OAAA,GAA6C,EAAC,EAC5B;AAClB,EAAA,MAAM,UAA4B,EAAC;AACnC,EAAA,KAAA,MAAW,CAAC,GAAA,EAAK,KAAK,KAAK,MAAA,CAAO,OAAA,CAAQ,OAAO,CAAA,EAAG;AAClD,IAAA,IAAI,UAAU,MAAA,EAAW;AACzB,IAAA,MAAM,OAAO,OAAO,KAAA;AACpB,IAAA,IAAI,IAAA,KAAS,QAAA,IAAY,IAAA,KAAS,UAAA,IAAc,SAAS,QAAA,EAAU;AACjE,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,CAAA,wBAAA,EAA2B,GAAG,CAAA,OAAA,EAAU,IAAI,CAAA,yEAAA;AAAA,OAC9C;AAAA,IACF;AACA,IAAA,OAAA,CAAQ,GAAG,CAAA,GAAI,KAAA;AAAA,EACjB;AACA,EAAA,OAAO,OAAA;AACT;AAYA,SAAS,YAAY,OAAA,EAA2D;AAC9E,EAAA,MAAM,eAAA,GAAkBA,6BAAA,CAAYC,6BAAA,CAAY,EAAA,EAAI,cAAc,CAAA;AAClE,EAAA,MAAM,aACJ,OAAA,CAAQ,UAAA,KACP,iBAAiB,MAAA,KAAW,UAAA,GAAa,gBAAgB,OAAA,GAAU,MAAA,CAAA;AACtE,EAAA,IAAI,CAAC,U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} from \"./chains.js\";\nimport { getContract } from \"./contracts.js\";\n\n/**\n * ERC-7677 paymaster web-service types, for the two JSON-RPC methods PEPU's\n * paymaster policy service implements: `pm_getPaymasterStubData` and\n * `pm_getPaymasterData`. See https://eips.ethereum.org/EIPS/eip-7677.\n *\n * Pure types plus a few tiny builders: no network, no secrets, safe in a\n * browser bundle. Quantities are `0x`-prefixed hex strings, as on the wire.\n *\n * Note this package never implies sponsorship is available to an app: see\n * `getSponsorshipStatus()`. These types describe the protocol only.\n */\n\n/** An ERC-4337 v0.7 UserOperation in its unpacked JSON-RPC shape. */\nexport interface Erc7677UserOperation {\n sender: Address;\n nonce: Hex;\n factory?: Address;\n factoryData?: Hex;\n callData: Hex;\n callGasLimit: Hex;\n verificationGasLimit: Hex;\n preVerificationGas: Hex;\n maxFeePerGas: Hex;\n maxPriorityFeePerGas: Hex;\n paymaster?: Address;\n paymasterVerificationGasLimit?: Hex;\n paymasterPostOpGasLimit?: Hex;\n paymasterData?: Hex;\n signature: Hex;\n}\n\n/** Paymaster-defined, JSON-serializable context (params[3]). */\nexport type PaymasterContext = Record<string, unknown>;\n\nexport type PaymasterRpcParams = readonly [\n userOperation: Partial<Erc7677UserOperation> & Pick<Erc7677UserOperation, \"sender\" | \"callData\">,\n entryPoint: Address,\n chainId: Hex,\n context?: PaymasterContext,\n];\n\nexport interface PaymasterStubDataRequest {\n jsonrpc: \"2.0\";\n id: number | string;\n method: \"pm_getPaymasterStubData\";\n params: PaymasterRpcParams;\n}\n\nexport interface PaymasterDataRequest {\n jsonrpc: \"2.0\";\n id: number | string;\n method: \"pm_getPaymasterData\";\n params: PaymasterRpcParams;\n}\n\n/** Result of `pm_getPaymasterStubData`. Stub values are for gas estimation only. */\nexport interface PaymasterStubDataResult {\n paymaster: Address;\n paymasterData: Hex;\n paymasterVerificationGasLimit?: Hex;\n paymasterPostOpGasLimit?: Hex;\n /** `true` when the stub values are also the final values. */\n isFinal?: boolean;\n sponsor?: { name: string; icon?: string };\n}\n\n/** Result of `pm_getPaymasterData`: the signed values to submit. */\nexport interface PaymasterDataResult {\n paymaster: Address;\n paymasterData: Hex;\n paymasterVerificationGasLimit?: Hex;\n paymasterPostOpGasLimit?: Hex;\n}\n\nexport interface PaymasterRpcError {\n code: number;\n message: string;\n /** PEPU's policy service puts the machine-readable denial reason in `data.reason`. */\n data?: { reason?: string } & Record<string, unknown>;\n}\n\nexport type PaymasterRpcResponse<TResult> =\n | { jsonrpc: \"2.0\"; id: number | string | null; result: TResult }\n | { jsonrpc: \"2.0\"; id: number | string | null; error: PaymasterRpcError };\n\n/**\n * Build a paymaster `context` object: drops `undefined` entries and throws on\n * anything that would not survive `JSON.stringify` (bigint, function, symbol),\n * so a bad value fails here instead of as an opaque RPC error. Returns `{}`\n * for no input. The context is paymaster-defined; PEPU's policy service\n * currently accepts and ignores it.\n */\nexport function buildPaymasterContext(\n entries: Readonly<Record<string, unknown>> = {},\n): PaymasterContext {\n const context: PaymasterContext = {};\n for (const [key, value] of Object.entries(entries)) {\n if (value === undefined) continue;\n const kind = typeof value;\n if (kind === \"bigint\" || kind === \"function\" || kind === \"symbol\") {\n throw new Error(\n `buildPaymasterContext: \"${key}\" is a ${kind}, which is not JSON-serializable. Convert it to a string or number first.`,\n );\n }\n context[key] = value;\n }\n return context;\n}\n\nexport interface BuildPaymasterRequestOptions {\n userOperation: PaymasterRpcParams[0];\n /** Defaults to PEPU mainnet's EntryPoint v0.7. */\n entryPoint?: Address;\n /** Defaults to 97741 (PEPU mainnet). */\n chainId?: number;\n context?: PaymasterContext;\n id?: number | string;\n}\n\nfunction buildParams(options: BuildPaymasterRequestOptions): PaymasterRpcParams {\n const entryPointEntry = getContract(pepuMainnet.id, \"entryPoint07\");\n const entryPoint =\n options.entryPoint ??\n (entryPointEntry?.status === \"deployed\" ? entryPointEntry.address : undefined);\n if (!entryPoint) throw new Error(\"buildPaymasterRequest: no EntryPoint v0.7 address available.\");\n const chainId = toHex(options.chainId ?? pepuMainnet.id);\n return options.context\n ? [options.userOperation, entryPoint, chainId, options.context]\n : [options.userOperation, entryPoint, chainId];\n}\n\n/** Build a `pm_getPaymasterStubData` JSON-RPC request body. */\nexport function buildPaymasterStubDataRequest(\n options: BuildPaymasterRequestOptions,\n): PaymasterStubDataRequest {\n return {\n jsonrpc: \"2.0\",\n id: options.id ?? 1,\n method: \"pm_getPaymasterStubData\",\n params: buildParams(options),\n };\n}\n\n/** Build a `pm_getPaymasterData` JSON-RPC request body. */\nexport function buildPaymasterDataRequest(\n options: BuildPaymasterRequestOptions,\n): PaymasterDataRequest {\n return {\n jsonrpc: \"2.0\",\n id: options.id ?? 1,\n method: \"pm_getPaymasterData\",\n params: buildParams(options),\n };\n}\n"]}
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import { paymasterReasonToError, mapPaymasterReason } from './chunk-GIZNH65Q.js';
|
|
2
|
+
import { PEPU_HOSTED, resolvePepuEndpoints } from './chunk-XC4IBCI2.js';
|
|
3
|
+
import { pepuMainnet } from './chunk-VTQIHMF3.js';
|
|
4
|
+
import { PepuConfigError, PepuPaymasterError } from './chunk-6DSZ4Z2N.js';
|
|
5
|
+
import { createSiweMessage } from 'viem/siwe';
|
|
6
|
+
import { isAddress, toHex } from 'viem';
|
|
7
|
+
|
|
8
|
+
var CLIENT_TOKEN_PREFIX = "ppt_";
|
|
9
|
+
var SERVER_KEY_PREFIX = "ppk_";
|
|
10
|
+
function credentialKind(credential) {
|
|
11
|
+
if (credential.startsWith(CLIENT_TOKEN_PREFIX)) return "client";
|
|
12
|
+
if (credential.startsWith(SERVER_KEY_PREFIX)) return "server";
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
function trimBase(url) {
|
|
16
|
+
return url.replace(/\/+$/, "");
|
|
17
|
+
}
|
|
18
|
+
function buildErc7677Url(options) {
|
|
19
|
+
const token = options.token.trim();
|
|
20
|
+
if (token === "") {
|
|
21
|
+
throw new PepuConfigError("CONFIG_MISSING_ENV", "buildErc7677Url needs a project client token or server key.");
|
|
22
|
+
}
|
|
23
|
+
if (credentialKind(token) === "server" && globalThis.window !== void 0) {
|
|
24
|
+
throw new PepuConfigError(
|
|
25
|
+
"CONFIG_SERVER_ONLY",
|
|
26
|
+
"Refusing to build an ERC-7677 URL from a server key (ppk_) in a browser: the URL embeds the secret. Use the client token (ppt_)."
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
let base;
|
|
30
|
+
try {
|
|
31
|
+
base = new URL(options.baseUrl);
|
|
32
|
+
} catch {
|
|
33
|
+
throw new PepuConfigError("CONFIG_BAD_URL", "buildErc7677Url: baseUrl is not a valid URL.");
|
|
34
|
+
}
|
|
35
|
+
if (base.protocol !== "http:" && base.protocol !== "https:") {
|
|
36
|
+
throw new PepuConfigError("CONFIG_BAD_URL", "buildErc7677Url: baseUrl must be an http(s) URL.");
|
|
37
|
+
}
|
|
38
|
+
const prefix = (options.version ?? 2) === 2 ? "/v2/paymaster/" : "/paymaster/";
|
|
39
|
+
return `${trimBase(options.baseUrl)}${prefix}${encodeURIComponent(token)}`;
|
|
40
|
+
}
|
|
41
|
+
function hostedErc7677Url(token) {
|
|
42
|
+
if (PEPU_HOSTED.paymasterBaseUrl === null) {
|
|
43
|
+
throw new PepuConfigError("CONFIG_MISSING_ENV", "No hosted paymaster base URL is set.");
|
|
44
|
+
}
|
|
45
|
+
return buildErc7677Url({ baseUrl: PEPU_HOSTED.paymasterBaseUrl, token });
|
|
46
|
+
}
|
|
47
|
+
function toQuantity(v) {
|
|
48
|
+
return typeof v === "bigint" ? toHex(v) : v;
|
|
49
|
+
}
|
|
50
|
+
function serializeUserOp(op) {
|
|
51
|
+
const out = {
|
|
52
|
+
sender: op.sender,
|
|
53
|
+
nonce: toQuantity(op.nonce),
|
|
54
|
+
callData: op.callData,
|
|
55
|
+
callGasLimit: toQuantity(op.callGasLimit),
|
|
56
|
+
verificationGasLimit: toQuantity(op.verificationGasLimit),
|
|
57
|
+
preVerificationGas: toQuantity(op.preVerificationGas),
|
|
58
|
+
maxFeePerGas: toQuantity(op.maxFeePerGas),
|
|
59
|
+
maxPriorityFeePerGas: toQuantity(op.maxPriorityFeePerGas)
|
|
60
|
+
};
|
|
61
|
+
if (op.factory !== void 0) out["factory"] = op.factory;
|
|
62
|
+
if (op.factoryData !== void 0) out["factoryData"] = op.factoryData;
|
|
63
|
+
return out;
|
|
64
|
+
}
|
|
65
|
+
function assertApproved(result) {
|
|
66
|
+
if (result.status === "approved") return result;
|
|
67
|
+
throw paymasterReasonToError(result.reason, result.message, result.detail ? { detail: result.detail } : void 0);
|
|
68
|
+
}
|
|
69
|
+
function retryAfter(res) {
|
|
70
|
+
const raw = res.headers.get("retry-after");
|
|
71
|
+
const n = raw === null ? NaN : Number(raw);
|
|
72
|
+
return Number.isFinite(n) ? n : void 0;
|
|
73
|
+
}
|
|
74
|
+
function isRecord(v) {
|
|
75
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
76
|
+
}
|
|
77
|
+
function missingBaseUrl() {
|
|
78
|
+
return new PepuConfigError(
|
|
79
|
+
"CONFIG_MISSING_ENV",
|
|
80
|
+
"No paymaster URL configured. Set PEPU_PAYMASTER_URL (or NEXT_PUBLIC_PEPU_PAYMASTER_URL), or pass baseUrl to createPaymasterApi."
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
function createPaymasterApi(options = {}) {
|
|
84
|
+
const resolved = options.baseUrl ?? resolvePepuEndpoints(options.env ? { env: options.env } : {}).paymasterBaseUrl;
|
|
85
|
+
if (resolved === null || resolved === void 0 || resolved.trim() === "") throw missingBaseUrl();
|
|
86
|
+
try {
|
|
87
|
+
const u = new URL(resolved);
|
|
88
|
+
if (u.protocol !== "http:" && u.protocol !== "https:") throw new Error("protocol");
|
|
89
|
+
} catch {
|
|
90
|
+
throw new PepuConfigError("CONFIG_BAD_URL", "The paymaster baseUrl is not a valid http(s) URL.");
|
|
91
|
+
}
|
|
92
|
+
const baseUrl = trimBase(resolved.trim());
|
|
93
|
+
const doFetch = options.fetch ?? ((...args) => fetch(...args));
|
|
94
|
+
const timeoutMs = options.timeoutMs ?? 15e3;
|
|
95
|
+
let sessionToken = options.sessionToken ?? null;
|
|
96
|
+
async function send(url, init) {
|
|
97
|
+
try {
|
|
98
|
+
return await doFetch(url, { ...init, signal: AbortSignal.timeout(timeoutMs) });
|
|
99
|
+
} catch (e) {
|
|
100
|
+
const timedOut = e instanceof Error && (e.name === "TimeoutError" || e.name === "AbortError");
|
|
101
|
+
throw new PepuPaymasterError(
|
|
102
|
+
"BUNDLER_UNREACHABLE",
|
|
103
|
+
timedOut ? "The paymaster did not answer in time." : "Could not reach the paymaster service.",
|
|
104
|
+
{ details: { path: new URL(url).pathname.replace(/\/(ppt_|ppk_)[^/]*/, "/<credential>") } }
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
async function readJson(res) {
|
|
109
|
+
const text = await res.text().catch(() => "");
|
|
110
|
+
if (text === "") return void 0;
|
|
111
|
+
try {
|
|
112
|
+
return JSON.parse(text);
|
|
113
|
+
} catch {
|
|
114
|
+
return void 0;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
function apiError(res, body, quiet) {
|
|
118
|
+
const rec = isRecord(body) ? body : {};
|
|
119
|
+
const errorCode = typeof rec["error"] === "string" ? rec["error"] : void 0;
|
|
120
|
+
const reason = typeof rec["reason"] === "string" ? rec["reason"] : void 0;
|
|
121
|
+
const serverMessage = typeof rec["message"] === "string" && !quiet ? rec["message"] : void 0;
|
|
122
|
+
const details = { status: res.status, error: errorCode, reason, retryAfterSeconds: retryAfter(res) };
|
|
123
|
+
const tagged = reason ?? errorCode;
|
|
124
|
+
let code;
|
|
125
|
+
if (res.status === 401 && errorCode === "unauthenticated") code = "PAYMASTER_SESSION_REQUIRED";
|
|
126
|
+
else if (tagged !== void 0 && mapPaymasterReason(tagged) !== "PAYMASTER_DENIED") code = mapPaymasterReason(tagged);
|
|
127
|
+
else if (res.status === 401 && errorCode !== "login_failed") code = "PAYMASTER_SESSION_REQUIRED";
|
|
128
|
+
else if (res.status === 401) code = "PAYMASTER_DENIED";
|
|
129
|
+
else if (res.status === 429) code = "PAYMASTER_RATE_LIMITED";
|
|
130
|
+
else if (res.status === 403) code = "PAYMASTER_DENIED";
|
|
131
|
+
else code = "PAYMASTER_API_ERROR";
|
|
132
|
+
const label = `Paymaster API ${res.status}${errorCode ? ` ${errorCode}` : ""}${reason && reason !== errorCode ? ` (${reason})` : ""}`;
|
|
133
|
+
return new PepuPaymasterError(code, serverMessage ? `${label}: ${serverMessage}` : `${label}.`, {
|
|
134
|
+
details,
|
|
135
|
+
...res.status === 429 || res.status === 503 ? { retryable: true } : {}
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
async function request(method, path, o = {}) {
|
|
139
|
+
const headers = { accept: "application/json" };
|
|
140
|
+
if (o.body !== void 0) headers["content-type"] = "application/json";
|
|
141
|
+
if (o.session) {
|
|
142
|
+
if (!sessionToken) {
|
|
143
|
+
throw new PepuPaymasterError("PAYMASTER_SESSION_REQUIRED", "This call needs a SIWE session. Call loginWithWallet() first.");
|
|
144
|
+
}
|
|
145
|
+
headers["authorization"] = `Bearer ${sessionToken}`;
|
|
146
|
+
}
|
|
147
|
+
let url = `${baseUrl}${path}`;
|
|
148
|
+
if (o.query) {
|
|
149
|
+
const qs = new URLSearchParams();
|
|
150
|
+
for (const [k, v] of Object.entries(o.query)) if (v !== void 0) qs.set(k, String(v));
|
|
151
|
+
const s = qs.toString();
|
|
152
|
+
if (s) url += `?${s}`;
|
|
153
|
+
}
|
|
154
|
+
const res = await send(url, { method, headers, ...o.body !== void 0 ? { body: JSON.stringify(o.body) } : {} });
|
|
155
|
+
const body = await readJson(res);
|
|
156
|
+
if (!res.ok) throw apiError(res, body, o.quietErrors === true);
|
|
157
|
+
return body;
|
|
158
|
+
}
|
|
159
|
+
async function sponsor(path, userOp, auth) {
|
|
160
|
+
if (!auth.apiKey) {
|
|
161
|
+
throw new PepuConfigError("CONFIG_MISSING_ENV", "sponsor needs auth.apiKey (the project server key or client token).");
|
|
162
|
+
}
|
|
163
|
+
const headers = {
|
|
164
|
+
accept: "application/json",
|
|
165
|
+
"content-type": "application/json",
|
|
166
|
+
"x-api-key": auth.apiKey
|
|
167
|
+
};
|
|
168
|
+
if (auth.privyAccessToken) headers["authorization"] = `Bearer ${auth.privyAccessToken}`;
|
|
169
|
+
if (auth.origin) headers["origin"] = auth.origin;
|
|
170
|
+
const res = await send(`${baseUrl}${path}`, {
|
|
171
|
+
method: "POST",
|
|
172
|
+
headers,
|
|
173
|
+
body: JSON.stringify({ userOp: serializeUserOp(userOp) })
|
|
174
|
+
});
|
|
175
|
+
const body = await readJson(res);
|
|
176
|
+
if (isRecord(body) && (body["status"] === "approved" || body["status"] === "denied")) {
|
|
177
|
+
return body;
|
|
178
|
+
}
|
|
179
|
+
throw apiError(res, body, false);
|
|
180
|
+
}
|
|
181
|
+
const projectPath = (id, sub = "") => {
|
|
182
|
+
if (!/^0x[0-9a-fA-F]{64}$/.test(id)) {
|
|
183
|
+
throw new PepuPaymasterError("PAYMASTER_DENIED", "projectId must be a 0x-prefixed 32-byte hex string.");
|
|
184
|
+
}
|
|
185
|
+
return `/v2/projects/${id}${sub}`;
|
|
186
|
+
};
|
|
187
|
+
const v1 = {
|
|
188
|
+
sponsor: async (userOp, auth) => {
|
|
189
|
+
if (!auth.privyAccessToken) {
|
|
190
|
+
throw new PepuPaymasterError(
|
|
191
|
+
"PAYMASTER_IDENTITY_REQUIRED",
|
|
192
|
+
"The v1 /sponsor endpoint requires the user's Privy access token (auth.privyAccessToken)."
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
return sponsor("/sponsor", userOp, auth);
|
|
196
|
+
},
|
|
197
|
+
health: async () => {
|
|
198
|
+
const res = await send(`${baseUrl}/health`, { method: "GET" });
|
|
199
|
+
const body = await readJson(res);
|
|
200
|
+
if (!res.ok) throw apiError(res, body, false);
|
|
201
|
+
return isRecord(body) ? body : { status: "ok" };
|
|
202
|
+
},
|
|
203
|
+
erc7677Url: (token) => buildErc7677Url({ baseUrl, token, version: 1 })
|
|
204
|
+
};
|
|
205
|
+
const v2 = {
|
|
206
|
+
sponsor: (userOp, auth) => sponsor("/v2/sponsor", userOp, auth),
|
|
207
|
+
erc7677Url: (token) => buildErc7677Url({ baseUrl, token, version: 2 }),
|
|
208
|
+
config: () => request("GET", "/v2/config"),
|
|
209
|
+
contract: () => request("GET", "/v2/contract"),
|
|
210
|
+
freeTier: () => request("GET", "/v2/free-tier"),
|
|
211
|
+
auth: {
|
|
212
|
+
nonce: () => request("GET", "/v2/auth/nonce"),
|
|
213
|
+
login: async (message, signature) => {
|
|
214
|
+
const r = await request("POST", "/v2/auth/login", { body: { message, signature } });
|
|
215
|
+
sessionToken = r.token;
|
|
216
|
+
return r;
|
|
217
|
+
},
|
|
218
|
+
logout: async () => {
|
|
219
|
+
await request("POST", "/v2/auth/logout", { session: true });
|
|
220
|
+
sessionToken = null;
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
me: () => request("GET", "/v2/me", { session: true }),
|
|
224
|
+
loginWithWallet: async (sign, o) => {
|
|
225
|
+
if (!isAddress(o.address, { strict: false })) {
|
|
226
|
+
throw new PepuPaymasterError("PAYMASTER_DENIED", "loginWithWallet: address is not a valid address.");
|
|
227
|
+
}
|
|
228
|
+
const { nonce } = await v2.auth.nonce();
|
|
229
|
+
const now = (o.now ?? Date.now)();
|
|
230
|
+
const message = createSiweMessage({
|
|
231
|
+
address: o.address,
|
|
232
|
+
chainId: o.chainId ?? pepuMainnet.id,
|
|
233
|
+
domain: o.domain,
|
|
234
|
+
nonce,
|
|
235
|
+
uri: o.uri ?? `https://${o.domain}`,
|
|
236
|
+
version: "1",
|
|
237
|
+
statement: o.statement ?? "Sign in to manage your PEPU gas sponsorship project. This does not move any funds.",
|
|
238
|
+
issuedAt: new Date(now),
|
|
239
|
+
expirationTime: new Date(now + (o.lifetimeSeconds ?? 300) * 1e3)
|
|
240
|
+
});
|
|
241
|
+
const signature = await sign(message);
|
|
242
|
+
return v2.auth.login(message, signature);
|
|
243
|
+
},
|
|
244
|
+
getSessionToken: () => sessionToken,
|
|
245
|
+
setSessionToken: (t) => {
|
|
246
|
+
sessionToken = t;
|
|
247
|
+
},
|
|
248
|
+
projects: {
|
|
249
|
+
prepare: (body) => request("POST", "/v2/projects/prepare", { session: true, body }),
|
|
250
|
+
register: (body) => request("POST", "/v2/projects", { session: true, body }),
|
|
251
|
+
list: () => request("GET", "/v2/projects", { session: true }),
|
|
252
|
+
get: async (id) => request("GET", projectPath(id), { session: true }),
|
|
253
|
+
rotateClientToken: async (id) => request("POST", projectPath(id, "/token/rotate"), { session: true }),
|
|
254
|
+
rotateServerKey: async (id) => request("POST", projectPath(id, "/server-key/rotate"), { session: true }),
|
|
255
|
+
updateSettings: async (id, body) => request("PATCH", projectPath(id, "/settings"), { session: true, body }),
|
|
256
|
+
usage: async (id, q = {}) => request("GET", projectPath(id, "/usage"), { session: true, query: { ...q } }),
|
|
257
|
+
events: async (id, q = {}) => request("GET", projectPath(id, "/events"), { session: true, query: { ...q } }),
|
|
258
|
+
allowlist: async (id) => request("GET", projectPath(id, "/allowlist"), { session: true })
|
|
259
|
+
},
|
|
260
|
+
request
|
|
261
|
+
};
|
|
262
|
+
return { baseUrl, v1, v2 };
|
|
263
|
+
}
|
|
264
|
+
function serializeAttestation(a) {
|
|
265
|
+
return {
|
|
266
|
+
appId: a.appId,
|
|
267
|
+
newOwner: a.newOwner,
|
|
268
|
+
nonce: a.nonce.toString(),
|
|
269
|
+
deadline: a.deadline.toString(),
|
|
270
|
+
signature: a.signature
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export { assertApproved, buildErc7677Url, createPaymasterApi, credentialKind, hostedErc7677Url, serializeAttestation };
|
|
275
|
+
//# sourceMappingURL=chunk-RSPAN44L.js.map
|
|
276
|
+
//# sourceMappingURL=chunk-RSPAN44L.js.map
|