@pafi-dev/core 0.5.15 → 0.5.17

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/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Address, Hex, PublicClient, HttpTransport, WalletClient } from 'viem';
1
+ import { Address, Hex, TypedDataDomain, PublicClient, HttpTransport, WalletClient } from 'viem';
2
2
  import { P as PoolKey, C as ChainConfig, a as PafiSDKConfig, b as PointTokenDomainConfig, M as MintRequest, R as ReceiverConsent, E as EIP712Signature, S as SignatureVerification, B as BestQuote, Q as QuoteResult } from './types-JyuXUM8C.js';
3
3
  export { c as BurnRequest, I as Issuer, d as PathKey } from './types-JyuXUM8C.js';
4
4
  export { pointTokenAbi as POINT_TOKEN_V2_ABI, erc20Abi, issuerRegistryAbi, mintingOracleAbi, permit2Abi, pointTokenAbi, pointTokenFactoryAbi, universalRouterAbi, v4QuoterAbi } from './abi/index.js';
@@ -624,22 +624,67 @@ declare function assembleUserOperation(partial: PartialUserOperation, paymaster:
624
624
  paymasterPostOpGasLimit: bigint;
625
625
  }, signature: `0x${string}`): UserOperation;
626
626
 
627
+ declare const PACKED_USER_OPERATION_TYPES: {
628
+ readonly PackedUserOperation: readonly [{
629
+ readonly name: "sender";
630
+ readonly type: "address";
631
+ }, {
632
+ readonly name: "nonce";
633
+ readonly type: "uint256";
634
+ }, {
635
+ readonly name: "initCode";
636
+ readonly type: "bytes";
637
+ }, {
638
+ readonly name: "callData";
639
+ readonly type: "bytes";
640
+ }, {
641
+ readonly name: "accountGasLimits";
642
+ readonly type: "bytes32";
643
+ }, {
644
+ readonly name: "preVerificationGas";
645
+ readonly type: "uint256";
646
+ }, {
647
+ readonly name: "gasFees";
648
+ readonly type: "bytes32";
649
+ }, {
650
+ readonly name: "paymasterAndData";
651
+ readonly type: "bytes";
652
+ }];
653
+ };
654
+ type PackedUserOperationMessage = {
655
+ sender: Address;
656
+ nonce: bigint;
657
+ initCode: Hex;
658
+ callData: Hex;
659
+ accountGasLimits: Hex;
660
+ preVerificationGas: bigint;
661
+ gasFees: Hex;
662
+ paymasterAndData: Hex;
663
+ };
664
+ type UserOpTypedData = {
665
+ domain: TypedDataDomain;
666
+ types: typeof PACKED_USER_OPERATION_TYPES;
667
+ primaryType: "PackedUserOperation";
668
+ message: PackedUserOperationMessage;
669
+ };
627
670
  /**
628
- * ERC-4337 v0.8 UserOp hash — EIP-712 typed data with the
629
- * `PackedUserOperation` struct. Pimlico's `Simple7702Account` (impl
630
- * `0xe6Cae8...`) returns EntryPoint v0.8 from `entryPoint()`, which
631
- * computes hashes via EIP-712 (NOT v0.7's `keccak256(packed userOp +
632
- * entryPoint + chainId)`).
671
+ * Build the EIP-712 typed-data payload for an ERC-4337 v0.8 UserOp.
633
672
  *
634
- * The hash returned here is what the account's `_validateSignature`
635
- * recovers signer from. Pimlico's `Simple7702Account` uses
636
- * `MessageHashUtils.toEthSignedMessageHash(hash)` then ECDSA.recover
637
- * matching `personal_sign` on the client side.
673
+ * The deployed Pimlico `Simple7702Account` (impl `0xe6Cae8...`) validates
674
+ * the user's signature by calling `SignatureCheckerLib.isValidSignatureNow`
675
+ * with the **raw** userOpHash (no EIP-191 prefix). For an EOA signer this
676
+ * means `ecrecover(userOpHash, sig)` must equal the EOA address.
638
677
  *
639
- * Use on the **backend** (mobile prepare/submit) to compute the hash
640
- * before returning it to the mobile client for personal_sign.
678
+ * Because `userOpHash` is itself the EIP-712 typed digest of the
679
+ * `PackedUserOperation` struct, signing the typed data with
680
+ * `eth_signTypedData_v4` produces a signature whose recover-from-raw-digest
681
+ * == the userOpHash. That matches what the contract expects.
682
+ *
683
+ * Do NOT sign with `personal_sign` / `signMessage({ raw })` — that adds the
684
+ * EIP-191 prefix, which the contract does not undo, so recovery returns a
685
+ * different address and the bundler reverts with `AA24 signature error`.
641
686
  */
642
- declare function computeUserOpHash(userOp: {
687
+ declare function buildUserOpTypedData(userOp: {
643
688
  sender: Address;
644
689
  nonce: bigint;
645
690
  callData: Hex;
@@ -652,7 +697,12 @@ declare function computeUserOpHash(userOp: {
652
697
  paymasterVerificationGasLimit?: bigint;
653
698
  paymasterPostOpGasLimit?: bigint;
654
699
  paymasterData?: Hex;
655
- }, chainId: number): Hex;
700
+ }, chainId: number): UserOpTypedData;
701
+ /**
702
+ * EIP-712 typed digest of an ERC-4337 v0.8 UserOp. Equals on-chain
703
+ * `EntryPoint.getUserOpHash(userOp)`.
704
+ */
705
+ declare function computeUserOpHash(userOp: Parameters<typeof buildUserOpTypedData>[0], chainId: number): Hex;
656
706
 
657
707
  /**
658
708
  * EIP-7702 delegate impls supported by the PAFI mobile prepare/submit
@@ -1508,4 +1558,4 @@ declare class PafiSDK {
1508
1558
  signLoginMessage(message: string): Promise<Hex>;
1509
1559
  }
1510
1560
 
1511
- export { ApiError, BATCH_EXECUTOR_7702_IMPL, BATCH_EXECUTOR_ABI, BATCH_EXECUTOR_ADDRESS_BASE_MAINNET, BATCH_EXECUTOR_ADDRESS_BASE_SEPOLIA, BROKER_HASHES, BestQuote, type BuildDelegationUserOpParams, type BuildPartialUserOpParams, type BuildPerpDepositViaRelayParams, type BuildPerpDepositWithGasDeductionParams, COMMON_POOLS, COMMON_TOKENS, CONTRACT_ADDRESSES, ChainConfig, type CheckEthAndBranchParams, ConfigurationError, type ContractAddresses, DUMMY_SIGNATURE_V07, type DelegateImpl, EIP712Signature, ENTRY_POINT_V07, ENTRY_POINT_V08, LoginMessageParams, MintRequest, type ModalOpenOptions, ORDERLY_RELAY_ABI, ORDERLY_VAULT_ABI, ORDERLY_VAULT_ADDRESSES, ORDERLY_VAULT_BASE_MAINNET, Operation, type OrderlyRelayDepositRequest, PAFI_SUBGRAPH_URL, PERMIT2_ADDRESS, POINT_TOKEN_FACTORY_ADDRESSES, POINT_TOKEN_IMPL_ADDRESSES, POINT_TOKEN_POOLS, type PafiProxyTransportParams, PafiSDK, PafiSDKConfig, PafiSDKError, type PafiWebModalAdapter, type PafiWebModalHandle, PartialUserOperation, type PaymasterConfig, PointTokenDomainConfig, PoolKey, QuoteResult, ReceiverConsent, SIMPLE_7702_IMPL_BASE_MAINNET, SUPPORTED_CHAINS, type SendWithPaymasterFallbackParams, type SignatureStruct, SignatureVerification, SigningError, SimulationError, type SmartAccountSender, type SponsorshipScenario, type SubmissionPath, SwapSimulationResult, TOKEN_HASHES, UNIVERSAL_ROUTER_ADDRESSES, UserOperation, V4_QUOTER_ADDRESSES, type VaultDepositFE, _resetPaymasterConfigForTests, assembleUserOperation, buildDelegationUserOp, buildPartialUserOperation, buildPerpDepositViaRelay, buildPerpDepositWithGasDeduction, burnRequestTypes, checkDelegation, checkEthAndBranch, computeAccountId, computeAuthorizationHash, computeUserOpHash, createPafiProxyTransport, decodeBatchExecuteCalls, detectDelegateImpl, encodeBatchExecute, erc20ApproveOp, erc20BurnOp, erc20TransferOp, fetchPafiPools, getAaNonce, getContractAddresses, getDummySignatureFor7702, getPafiWebModalAdapter, getPaymasterConfig, isDelegatedTo, isDelegatedToTarget, isPaymasterConfigured, isPaymasterError, mintRequestTypes, openPafiWebModal, openWebPopup, parseEip7702DelegatedAddress, rawCallOp, receiverConsentTypes, sendWithPaymasterFallback, serializeUserOpToJsonRpc, setPafiWebModalAdapter, setPaymasterConfig, webPopupAdapter };
1561
+ export { ApiError, BATCH_EXECUTOR_7702_IMPL, BATCH_EXECUTOR_ABI, BATCH_EXECUTOR_ADDRESS_BASE_MAINNET, BATCH_EXECUTOR_ADDRESS_BASE_SEPOLIA, BROKER_HASHES, BestQuote, type BuildDelegationUserOpParams, type BuildPartialUserOpParams, type BuildPerpDepositViaRelayParams, type BuildPerpDepositWithGasDeductionParams, COMMON_POOLS, COMMON_TOKENS, CONTRACT_ADDRESSES, ChainConfig, type CheckEthAndBranchParams, ConfigurationError, type ContractAddresses, DUMMY_SIGNATURE_V07, type DelegateImpl, EIP712Signature, ENTRY_POINT_V07, ENTRY_POINT_V08, LoginMessageParams, MintRequest, type ModalOpenOptions, ORDERLY_RELAY_ABI, ORDERLY_VAULT_ABI, ORDERLY_VAULT_ADDRESSES, ORDERLY_VAULT_BASE_MAINNET, Operation, type OrderlyRelayDepositRequest, PAFI_SUBGRAPH_URL, PERMIT2_ADDRESS, POINT_TOKEN_FACTORY_ADDRESSES, POINT_TOKEN_IMPL_ADDRESSES, POINT_TOKEN_POOLS, type PackedUserOperationMessage, type PafiProxyTransportParams, PafiSDK, PafiSDKConfig, PafiSDKError, type PafiWebModalAdapter, type PafiWebModalHandle, PartialUserOperation, type PaymasterConfig, PointTokenDomainConfig, PoolKey, QuoteResult, ReceiverConsent, SIMPLE_7702_IMPL_BASE_MAINNET, SUPPORTED_CHAINS, type SendWithPaymasterFallbackParams, type SignatureStruct, SignatureVerification, SigningError, SimulationError, type SmartAccountSender, type SponsorshipScenario, type SubmissionPath, SwapSimulationResult, TOKEN_HASHES, UNIVERSAL_ROUTER_ADDRESSES, type UserOpTypedData, UserOperation, V4_QUOTER_ADDRESSES, type VaultDepositFE, _resetPaymasterConfigForTests, assembleUserOperation, buildDelegationUserOp, buildPartialUserOperation, buildPerpDepositViaRelay, buildPerpDepositWithGasDeduction, buildUserOpTypedData, burnRequestTypes, checkDelegation, checkEthAndBranch, computeAccountId, computeAuthorizationHash, computeUserOpHash, createPafiProxyTransport, decodeBatchExecuteCalls, detectDelegateImpl, encodeBatchExecute, erc20ApproveOp, erc20BurnOp, erc20TransferOp, fetchPafiPools, getAaNonce, getContractAddresses, getDummySignatureFor7702, getPafiWebModalAdapter, getPaymasterConfig, isDelegatedTo, isDelegatedToTarget, isPaymasterConfigured, isPaymasterError, mintRequestTypes, openPafiWebModal, openWebPopup, parseEip7702DelegatedAddress, rawCallOp, receiverConsentTypes, sendWithPaymasterFallback, serializeUserOpToJsonRpc, setPafiWebModalAdapter, setPaymasterConfig, webPopupAdapter };
package/dist/index.js CHANGED
@@ -385,7 +385,19 @@ import {
385
385
  pad,
386
386
  toHex
387
387
  } from "viem";
388
- function computeUserOpHash(userOp, chainId) {
388
+ var PACKED_USER_OPERATION_TYPES = {
389
+ PackedUserOperation: [
390
+ { name: "sender", type: "address" },
391
+ { name: "nonce", type: "uint256" },
392
+ { name: "initCode", type: "bytes" },
393
+ { name: "callData", type: "bytes" },
394
+ { name: "accountGasLimits", type: "bytes32" },
395
+ { name: "preVerificationGas", type: "uint256" },
396
+ { name: "gasFees", type: "bytes32" },
397
+ { name: "paymasterAndData", type: "bytes" }
398
+ ]
399
+ };
400
+ function buildUserOpTypedData(userOp, chainId) {
389
401
  const accountGasLimits = pack128(
390
402
  userOp.verificationGasLimit,
391
403
  userOp.callGasLimit
@@ -397,25 +409,14 @@ function computeUserOpHash(userOp, chainId) {
397
409
  pad(toHex(userOp.paymasterPostOpGasLimit ?? 0n), { size: 16 }),
398
410
  userOp.paymasterData ?? "0x"
399
411
  ]) : "0x";
400
- return hashTypedData({
412
+ return {
401
413
  domain: {
402
414
  name: "ERC4337",
403
415
  version: "1",
404
416
  chainId,
405
417
  verifyingContract: ENTRY_POINT_V08
406
418
  },
407
- types: {
408
- PackedUserOperation: [
409
- { name: "sender", type: "address" },
410
- { name: "nonce", type: "uint256" },
411
- { name: "initCode", type: "bytes" },
412
- { name: "callData", type: "bytes" },
413
- { name: "accountGasLimits", type: "bytes32" },
414
- { name: "preVerificationGas", type: "uint256" },
415
- { name: "gasFees", type: "bytes32" },
416
- { name: "paymasterAndData", type: "bytes" }
417
- ]
418
- },
419
+ types: PACKED_USER_OPERATION_TYPES,
419
420
  primaryType: "PackedUserOperation",
420
421
  message: {
421
422
  sender: userOp.sender,
@@ -427,7 +428,11 @@ function computeUserOpHash(userOp, chainId) {
427
428
  gasFees,
428
429
  paymasterAndData
429
430
  }
430
- });
431
+ };
432
+ }
433
+ function computeUserOpHash(userOp, chainId) {
434
+ const td = buildUserOpTypedData(userOp, chainId);
435
+ return hashTypedData(td);
431
436
  }
432
437
  function pack128(hi, lo) {
433
438
  return `0x${(hi << 128n | lo).toString(16).padStart(64, "0")}`;
@@ -1143,6 +1148,7 @@ export {
1143
1148
  buildSwapFromQuote,
1144
1149
  buildSwapWithGasDeduction,
1145
1150
  buildUniversalRouterExecuteArgs,
1151
+ buildUserOpTypedData,
1146
1152
  buildV4SwapInput,
1147
1153
  burnRequestTypes,
1148
1154
  checkAllowance,