@pushchain/ui-kit
Version:
Push Chain is a true universal L1 that is 100% EVM compatible. It allows developers to deploy once and make their apps instantly compatible with users from all other L1s (Ethereum, Solana, etc) with zero on-chain code change.
49 lines • 2.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.signAuthorizationWithEthersSigner = exports.normalizeSignedAuthorization = exports.EIP_7702_UNSUPPORTED_ERROR = void 0;
exports.EIP_7702_UNSUPPORTED_ERROR = 'Wallet does not support EIP-7702 authorization';
const normalizeSignedAuthorization = (authorization, { contractAddress, chainId, nonce }) => {
const signature = authorization.signature ?? authorization;
const resolvedChainId = authorization.chainId ?? chainId;
const resolvedNonce = authorization.nonce ?? nonce;
if (resolvedChainId === undefined ||
resolvedNonce === undefined ||
!signature.r ||
!signature.s ||
signature.yParity === undefined) {
throw new Error('Wallet returned an invalid EIP-7702 authorization');
}
return {
address: contractAddress,
chainId: Number(resolvedChainId),
nonce: Number(resolvedNonce),
r: signature.r,
s: signature.s,
yParity: Number(signature.yParity),
};
};
exports.normalizeSignedAuthorization = normalizeSignedAuthorization;
const signAuthorizationWithEthersSigner = async (signer, params) => {
if (typeof signer.authorize !== 'function') {
throw new Error(exports.EIP_7702_UNSUPPORTED_ERROR);
}
try {
const authorization = await signer.authorize({
address: params.contractAddress,
chainId: params.chainId,
nonce: params.nonce,
});
return (0, exports.normalizeSignedAuthorization)(authorization, params);
}
catch (error) {
const code = error?.code;
const message = error instanceof Error ? error.message : String(error);
if (code === 'UNSUPPORTED_OPERATION' ||
/authorization (?:is )?not (?:implemented|supported)/i.test(message)) {
throw new Error(exports.EIP_7702_UNSUPPORTED_ERROR);
}
throw error;
}
};
exports.signAuthorizationWithEthersSigner = signAuthorizationWithEthersSigner;
//# sourceMappingURL=signAuthorization.js.map