@uniswap/smart-wallet-sdk
Version:
⚒️ An SDK for building applications with smart wallets on Uniswap
42 lines • 1.76 kB
JavaScript
import { recoverAuthorizationAddress } from 'viem/experimental';
import { DELEGATION_MAGIC_PREFIX } from '../constants';
export 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 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 !== DELEGATION_MAGIC_PREFIX) {
throw new Error(`Invalid delegation magic prefix: ${magicPrefix}`);
}
const delegation = code.slice(8);
return `0x${delegation}`;
}
}
//# sourceMappingURL=delegation.js.map