@uniswap/smart-wallet-sdk
Version:
⚒️ An SDK for building applications with smart wallets on Uniswap
46 lines • 1.91 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Delegation = void 0;
const experimental_1 = require("viem/experimental");
const constants_1 = require("../constants");
class Delegation {
/**
* Recovers the signers of each authorization within the list sent in the transaction
* @dev this can also return just the contractAddress each signer is delegated to
* @param transaction : TransactionEIP7702
* @returns : Promise<RecoveredAuthorizationMap>
*/
static parseAuthorizationListFromTransaction(transaction) {
return this.parseAuthorizationList(transaction.authorizationList);
}
/**
* Recovers the signers of each authorization in the list
* @param authorizationList : SignedAuthorizationList
* @returns : Promise<RecoveredAuthorizationMap>
*/
static async parseAuthorizationList(authorizationList) {
// recover each authorization
const result = {};
for (const authorization of authorizationList) {
const signer = await (0, experimental_1.recoverAuthorizationAddress)({ authorization });
result[signer] = authorization;
}
return result;
}
/// Parses a delegation from an address's code
/// @dev will throw if the code is not a valid delegation per EIP7702 spec
static parseFromCode(code) {
if (code.length !== 48) {
throw new Error(`Invalid delegation length: ${code.length}`);
}
// parse out magic prefix which is 4 bytes
const magicPrefix = code.slice(0, 8);
if (magicPrefix !== constants_1.DELEGATION_MAGIC_PREFIX) {
throw new Error(`Invalid delegation magic prefix: ${magicPrefix}`);
}
const delegation = code.slice(8);
return `0x${delegation}`;
}
}
exports.Delegation = Delegation;
//# sourceMappingURL=delegation.js.map