@etherspot/prime-sdk
Version:
Etherspot Prime (Account Abstraction) SDK
65 lines (64 loc) • 3.06 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getVerifyingPaymaster = exports.VerifyingPaymasterAPI = void 0;
const ethers_1 = require("ethers");
const cross_fetch_1 = __importDefault(require("cross-fetch"));
const calcPreVerificationGas_1 = require("./calcPreVerificationGas");
const PaymasterAPI_1 = require("./PaymasterAPI");
const OperationUtils_1 = require("../common/OperationUtils");
const DUMMY_PAYMASTER_AND_DATA = '0x0101010101010101010101010101010101010101000000000000000000000000000000000000000000000000000001010101010100000000000000000000000000000000000000000000000000000000000000000101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101';
class VerifyingPaymasterAPI extends PaymasterAPI_1.PaymasterAPI {
constructor(paymasterUrl, entryPoint, context) {
super();
this.paymasterUrl = paymasterUrl;
this.entryPoint = entryPoint;
this.context = context;
}
async getPaymasterAndData(userOp) {
var _a;
try {
await ethers_1.ethers.utils.resolveProperties(userOp);
}
catch (_) { }
const pmOp = {
sender: userOp.sender,
nonce: userOp.nonce,
initCode: userOp.initCode,
callData: userOp.callData,
callGasLimit: userOp.callGasLimit,
verificationGasLimit: userOp.verificationGasLimit,
maxFeePerGas: userOp.maxFeePerGas,
maxPriorityFeePerGas: userOp.maxPriorityFeePerGas,
paymasterAndData: DUMMY_PAYMASTER_AND_DATA,
signature: (_a = userOp.signature) !== null && _a !== void 0 ? _a : '0x',
};
const op = await ethers_1.ethers.utils.resolveProperties(pmOp);
op.preVerificationGas = (0, calcPreVerificationGas_1.calcPreVerificationGas)(op);
op.paymasterAndData = '0x';
const paymasterAndData = await (0, cross_fetch_1.default)(this.paymasterUrl, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({ params: [await (0, OperationUtils_1.toJSON)(op), this.entryPoint, this.context], jsonrpc: '2', id: 2 }),
})
.then(async (res) => {
const response = await await res.json();
if (response.error) {
throw new Error(response.error);
}
return response;
})
.catch((err) => {
throw new Error(err.message);
});
return paymasterAndData;
}
}
exports.VerifyingPaymasterAPI = VerifyingPaymasterAPI;
const getVerifyingPaymaster = (paymasterUrl, entryPoint, context) => new VerifyingPaymasterAPI(paymasterUrl, entryPoint, context);
exports.getVerifyingPaymaster = getVerifyingPaymaster;
;