@zyfai/sdk 1.4.0 → 1.8.0
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/README.md +118 -4
- package/dist/index.d.mts +275 -15
- package/dist/index.d.ts +275 -15
- package/dist/index.js +1149 -70
- package/dist/index.mjs +1148 -47
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -36,6 +36,7 @@ __export(index_exports, {
|
|
|
36
36
|
DATA_API_ENDPOINT: () => DATA_API_ENDPOINT,
|
|
37
37
|
DEFAULT_RELAY_SLIPPAGE_BPS: () => DEFAULT_RELAY_SLIPPAGE_BPS,
|
|
38
38
|
DEFAULT_TOKEN_ADDRESSES: () => DEFAULT_TOKEN_ADDRESSES,
|
|
39
|
+
ENTRY_POINT_V07_ADDRESS: () => ENTRY_POINT_V07_ADDRESS,
|
|
39
40
|
ERC7579_LAUNCHPAD_ADDRESS: () => ERC7579_LAUNCHPAD_ADDRESS,
|
|
40
41
|
EXECUTION_API_BASE_URLS: () => EXECUTION_API_BASE_URLS,
|
|
41
42
|
INTENT_EXECUTOR: () => INTENT_EXECUTOR,
|
|
@@ -58,7 +59,10 @@ __export(index_exports, {
|
|
|
58
59
|
WS_ENDPOINT: () => WS_ENDPOINT,
|
|
59
60
|
WS_URLS: () => WS_URLS,
|
|
60
61
|
ZyfaiSDK: () => ZyfaiSDK,
|
|
62
|
+
buildV1ChainSessions: () => buildV1ChainSessions,
|
|
61
63
|
createBankrProvider: () => createBankrProvider,
|
|
64
|
+
createSafeOwnerProvider: () => createSafeOwnerProvider,
|
|
65
|
+
decodeUserOperationCalls: () => decodeUserOperationCalls,
|
|
62
66
|
getChainConfig: () => getChainConfig,
|
|
63
67
|
getDataApiBaseUrl: () => getDataApiBaseUrl,
|
|
64
68
|
getDefaultTokenAddress: () => getDefaultTokenAddress,
|
|
@@ -66,9 +70,14 @@ __export(index_exports, {
|
|
|
66
70
|
getManagedAssets: () => getManagedAssets,
|
|
67
71
|
getSupportedChainIds: () => getSupportedChainIds,
|
|
68
72
|
getWsUrl: () => getWsUrl,
|
|
73
|
+
hashUserOperationV07: () => hashUserOperationV07,
|
|
74
|
+
hashV1SessionEnable: () => hashV1SessionEnable,
|
|
69
75
|
isSupportedChain: () => isSupportedChain,
|
|
76
|
+
parseUserOperationJson: () => parseUserOperationJson,
|
|
77
|
+
parseV1ChainSessions: () => parseV1ChainSessions,
|
|
70
78
|
resolveDepositRoute: () => resolveDepositRoute,
|
|
71
|
-
resolveRelaySlippageBps: () => resolveRelaySlippageBps
|
|
79
|
+
resolveRelaySlippageBps: () => resolveRelaySlippageBps,
|
|
80
|
+
serializeV1ChainSessions: () => serializeV1ChainSessions
|
|
72
81
|
});
|
|
73
82
|
module.exports = __toCommonJS(index_exports);
|
|
74
83
|
|
|
@@ -907,7 +916,7 @@ function isMainnetMinPortfolioExempt(chainId, ...addresses) {
|
|
|
907
916
|
|
|
908
917
|
// src/core/ZyfaiSDK.ts
|
|
909
918
|
var import_accounts2 = require("viem/accounts");
|
|
910
|
-
var
|
|
919
|
+
var import_viem8 = require("viem");
|
|
911
920
|
var import_relay_sdk2 = require("@relayprotocol/relay-sdk");
|
|
912
921
|
|
|
913
922
|
// src/config/chains.ts
|
|
@@ -1392,9 +1401,9 @@ function getManagedAssets() {
|
|
|
1392
1401
|
}
|
|
1393
1402
|
|
|
1394
1403
|
// src/utils/safe-account.ts
|
|
1395
|
-
var
|
|
1404
|
+
var import_module_sdk2 = require("@rhinestone/module-sdk");
|
|
1396
1405
|
var import_accounts = require("permissionless/accounts");
|
|
1397
|
-
var
|
|
1406
|
+
var import_viem6 = require("viem");
|
|
1398
1407
|
var import_account_abstraction = require("viem/account-abstraction");
|
|
1399
1408
|
|
|
1400
1409
|
// src/config/modules.ts
|
|
@@ -1415,6 +1424,142 @@ var POOL_MODULE_ADDRESSES = [
|
|
|
1415
1424
|
OWNABLE_VALIDATOR
|
|
1416
1425
|
];
|
|
1417
1426
|
|
|
1427
|
+
// src/utils/safe-signature.ts
|
|
1428
|
+
var import_module_sdk = require("@rhinestone/module-sdk");
|
|
1429
|
+
var import_viem5 = require("viem");
|
|
1430
|
+
var EMPTY_DATA = "0x";
|
|
1431
|
+
var SIGNATURE_LENGTH_BYTES = 65;
|
|
1432
|
+
function safeSigStaticPart(sig, dynamicOffset) {
|
|
1433
|
+
if (sig.isContractSignature) {
|
|
1434
|
+
return `${sig.signer.slice(2).padStart(64, "0")}${dynamicOffset ?? ""}00`;
|
|
1435
|
+
}
|
|
1436
|
+
return sig.data.slice(2);
|
|
1437
|
+
}
|
|
1438
|
+
function safeSigDynamicPart(sig) {
|
|
1439
|
+
if (!sig.isContractSignature) return "";
|
|
1440
|
+
const dynamicPartLength = (sig.data.slice(2).length / 2).toString(16).padStart(64, "0");
|
|
1441
|
+
return `${dynamicPartLength}${sig.data.slice(2)}`;
|
|
1442
|
+
}
|
|
1443
|
+
function buildSafeSignatureBytes(signatures) {
|
|
1444
|
+
const sorted = [...signatures].sort(
|
|
1445
|
+
(left, right) => left.signer.toLowerCase().localeCompare(right.signer.toLowerCase())
|
|
1446
|
+
);
|
|
1447
|
+
let signatureBytes = EMPTY_DATA.slice(2);
|
|
1448
|
+
let dynamicBytes = "";
|
|
1449
|
+
for (const signature of sorted) {
|
|
1450
|
+
if (signature.isContractSignature) {
|
|
1451
|
+
const dynamicPartPosition = (sorted.length * SIGNATURE_LENGTH_BYTES + dynamicBytes.length / 2).toString(16).padStart(64, "0");
|
|
1452
|
+
signatureBytes += safeSigStaticPart(signature, dynamicPartPosition);
|
|
1453
|
+
dynamicBytes += safeSigDynamicPart(signature);
|
|
1454
|
+
} else {
|
|
1455
|
+
signatureBytes += signature.data.slice(2);
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
return `0x${signatureBytes}${dynamicBytes}`;
|
|
1459
|
+
}
|
|
1460
|
+
function wrapNestedSafeOwnerSignature(parentSafe, rawSignature, validator) {
|
|
1461
|
+
const normalizedParent = (0, import_viem5.getAddress)(parentSafe);
|
|
1462
|
+
const normalizedValidator = (0, import_viem5.getAddress)(validator);
|
|
1463
|
+
const inner = rawSignature.toLowerCase().startsWith(normalizedValidator.toLowerCase()) ? `0x${rawSignature.slice(42)}` : rawSignature;
|
|
1464
|
+
const safeSignature = {
|
|
1465
|
+
signer: normalizedParent,
|
|
1466
|
+
data: inner,
|
|
1467
|
+
isContractSignature: true
|
|
1468
|
+
};
|
|
1469
|
+
return (0, import_viem5.concat)([
|
|
1470
|
+
normalizedValidator,
|
|
1471
|
+
buildSafeSignatureBytes([safeSignature])
|
|
1472
|
+
]);
|
|
1473
|
+
}
|
|
1474
|
+
function buildMultiChainSessionTypedData(params) {
|
|
1475
|
+
const smartSession = params.smartSessionAddress ?? import_module_sdk.SMART_SESSIONS_ADDRESS;
|
|
1476
|
+
return {
|
|
1477
|
+
domain: {
|
|
1478
|
+
name: "SmartSession",
|
|
1479
|
+
version: "1"
|
|
1480
|
+
},
|
|
1481
|
+
types: {
|
|
1482
|
+
PolicyData: [
|
|
1483
|
+
{ name: "policy", type: "address" },
|
|
1484
|
+
{ name: "initData", type: "bytes" }
|
|
1485
|
+
],
|
|
1486
|
+
ActionData: [
|
|
1487
|
+
{ name: "actionTargetSelector", type: "bytes4" },
|
|
1488
|
+
{ name: "actionTarget", type: "address" },
|
|
1489
|
+
{ name: "actionPolicies", type: "PolicyData[]" }
|
|
1490
|
+
],
|
|
1491
|
+
ERC7739Context: [
|
|
1492
|
+
{ name: "appDomainSeparator", type: "bytes32" },
|
|
1493
|
+
{ name: "contentName", type: "string[]" }
|
|
1494
|
+
],
|
|
1495
|
+
ERC7739Data: [
|
|
1496
|
+
{ name: "allowedERC7739Content", type: "ERC7739Context[]" },
|
|
1497
|
+
{ name: "erc1271Policies", type: "PolicyData[]" }
|
|
1498
|
+
],
|
|
1499
|
+
SignedPermissions: [
|
|
1500
|
+
{ name: "permitGenericPolicy", type: "bool" },
|
|
1501
|
+
{ name: "permitAdminAccess", type: "bool" },
|
|
1502
|
+
{ name: "ignoreSecurityAttestations", type: "bool" },
|
|
1503
|
+
{ name: "permitERC4337Paymaster", type: "bool" },
|
|
1504
|
+
{ name: "userOpPolicies", type: "PolicyData[]" },
|
|
1505
|
+
{ name: "erc7739Policies", type: "ERC7739Data" },
|
|
1506
|
+
{ name: "actions", type: "ActionData[]" }
|
|
1507
|
+
],
|
|
1508
|
+
SignedSession: [
|
|
1509
|
+
{ name: "account", type: "address" },
|
|
1510
|
+
{ name: "permissions", type: "SignedPermissions" },
|
|
1511
|
+
{ name: "sessionValidator", type: "address" },
|
|
1512
|
+
{ name: "sessionValidatorInitData", type: "bytes" },
|
|
1513
|
+
{ name: "salt", type: "bytes32" },
|
|
1514
|
+
{ name: "smartSession", type: "address" },
|
|
1515
|
+
{ name: "nonce", type: "uint256" }
|
|
1516
|
+
],
|
|
1517
|
+
ChainSession: [
|
|
1518
|
+
{ name: "chainId", type: "uint64" },
|
|
1519
|
+
{ name: "session", type: "SignedSession" }
|
|
1520
|
+
],
|
|
1521
|
+
MultiChainSession: [
|
|
1522
|
+
{ name: "sessionsAndChainIds", type: "ChainSession[]" }
|
|
1523
|
+
]
|
|
1524
|
+
},
|
|
1525
|
+
primaryType: "MultiChainSession",
|
|
1526
|
+
message: {
|
|
1527
|
+
sessionsAndChainIds: params.sessions.map((session, index) => ({
|
|
1528
|
+
chainId: BigInt(session.chainId),
|
|
1529
|
+
session: {
|
|
1530
|
+
account: params.childSafeAddress,
|
|
1531
|
+
permissions: {
|
|
1532
|
+
permitGenericPolicy: params.permitGenericPolicy,
|
|
1533
|
+
permitAdminAccess: false,
|
|
1534
|
+
ignoreSecurityAttestations: true,
|
|
1535
|
+
permitERC4337Paymaster: session.permitERC4337Paymaster,
|
|
1536
|
+
userOpPolicies: session.userOpPolicies,
|
|
1537
|
+
erc7739Policies: session.erc7739Policies,
|
|
1538
|
+
actions: session.actions
|
|
1539
|
+
},
|
|
1540
|
+
sessionValidator: session.sessionValidator,
|
|
1541
|
+
sessionValidatorInitData: session.sessionValidatorInitData,
|
|
1542
|
+
salt: session.salt,
|
|
1543
|
+
smartSession,
|
|
1544
|
+
nonce: params.sessionNonces[index]
|
|
1545
|
+
}
|
|
1546
|
+
}))
|
|
1547
|
+
}
|
|
1548
|
+
};
|
|
1549
|
+
}
|
|
1550
|
+
async function signMultiChainSessionTypedData(walletClient, typedData) {
|
|
1551
|
+
if (!walletClient.account) {
|
|
1552
|
+
throw new Error("Wallet not connected. Please connect your wallet first.");
|
|
1553
|
+
}
|
|
1554
|
+
return walletClient.signTypedData({
|
|
1555
|
+
account: walletClient.account,
|
|
1556
|
+
domain: typedData.domain,
|
|
1557
|
+
types: typedData.types,
|
|
1558
|
+
primaryType: typedData.primaryType,
|
|
1559
|
+
message: typedData.message
|
|
1560
|
+
});
|
|
1561
|
+
}
|
|
1562
|
+
|
|
1418
1563
|
// src/utils/safe-account.ts
|
|
1419
1564
|
var SAFE_7579_ADDRESS2 = "0x7579EE8307284F293B1927136486880611F20002";
|
|
1420
1565
|
var ERC7579_LAUNCHPAD_ADDRESS2 = "0x7579011aB74c46090561ea277Ba79D510c6C00ff";
|
|
@@ -1424,12 +1569,12 @@ var getSafeAccount = async (config) => {
|
|
|
1424
1569
|
if (!safeOwnerAddress) {
|
|
1425
1570
|
throw new Error("Safe owner address is required");
|
|
1426
1571
|
}
|
|
1427
|
-
const formattedOwnerAddress = (0,
|
|
1428
|
-
const ownableValidator = (0,
|
|
1572
|
+
const formattedOwnerAddress = (0, import_viem6.getAddress)(safeOwnerAddress);
|
|
1573
|
+
const ownableValidator = (0, import_module_sdk2.getOwnableValidator)({
|
|
1429
1574
|
owners: [formattedOwnerAddress],
|
|
1430
1575
|
threshold: 1
|
|
1431
1576
|
});
|
|
1432
|
-
const saltHex = (0,
|
|
1577
|
+
const saltHex = (0, import_viem6.fromHex)((0, import_viem6.toHex)(ACCOUNT_SALT), "bigint");
|
|
1433
1578
|
const tempOwner = {
|
|
1434
1579
|
address: formattedOwnerAddress,
|
|
1435
1580
|
type: "json-rpc"
|
|
@@ -1444,7 +1589,7 @@ var getSafeAccount = async (config) => {
|
|
|
1444
1589
|
},
|
|
1445
1590
|
safe4337ModuleAddress: SAFE_7579_ADDRESS2,
|
|
1446
1591
|
erc7579LaunchpadAddress: ERC7579_LAUNCHPAD_ADDRESS2,
|
|
1447
|
-
attesters: [
|
|
1592
|
+
attesters: [import_module_sdk2.RHINESTONE_ATTESTER_ADDRESS],
|
|
1448
1593
|
attestersThreshold: 1,
|
|
1449
1594
|
validators: [
|
|
1450
1595
|
{
|
|
@@ -1476,12 +1621,12 @@ var isSafeDeployed = async (address, publicClient) => {
|
|
|
1476
1621
|
}
|
|
1477
1622
|
};
|
|
1478
1623
|
var isOwnableValidatorOwner = async (safeAddress, userAddress, publicClient) => {
|
|
1479
|
-
const normalizedUser = (0,
|
|
1480
|
-
const normalizedSafe = (0,
|
|
1624
|
+
const normalizedUser = (0, import_viem6.getAddress)(userAddress);
|
|
1625
|
+
const normalizedSafe = (0, import_viem6.getAddress)(safeAddress);
|
|
1481
1626
|
const validatorAddresses = Array.from(
|
|
1482
1627
|
/* @__PURE__ */ new Set([
|
|
1483
|
-
(0,
|
|
1484
|
-
(0,
|
|
1628
|
+
(0, import_viem6.getAddress)(OWNABLE_VALIDATOR),
|
|
1629
|
+
(0, import_viem6.getAddress)(import_module_sdk2.OWNABLE_VALIDATOR_ADDRESS)
|
|
1485
1630
|
])
|
|
1486
1631
|
);
|
|
1487
1632
|
for (const validatorAddress of validatorAddresses) {
|
|
@@ -1492,7 +1637,7 @@ var isOwnableValidatorOwner = async (safeAddress, userAddress, publicClient) =>
|
|
|
1492
1637
|
functionName: "getOwners",
|
|
1493
1638
|
args: [normalizedSafe]
|
|
1494
1639
|
});
|
|
1495
|
-
if (owners.some((owner) => (0,
|
|
1640
|
+
if (owners.some((owner) => (0, import_viem6.getAddress)(owner) === normalizedUser)) {
|
|
1496
1641
|
return true;
|
|
1497
1642
|
}
|
|
1498
1643
|
} catch {
|
|
@@ -1579,12 +1724,24 @@ var deploySafeAccount = async (config) => {
|
|
|
1579
1724
|
}
|
|
1580
1725
|
};
|
|
1581
1726
|
var signSessionKey = async (config, sessions, allPublicClients, signingParams) => {
|
|
1582
|
-
const { owner, publicClient } = config;
|
|
1727
|
+
const { owner, publicClient, safeOwnerAddress } = config;
|
|
1583
1728
|
if (!owner || !owner.account) {
|
|
1584
1729
|
throw new Error("Wallet not connected. Please connect your wallet first.");
|
|
1585
1730
|
}
|
|
1731
|
+
const ownerAccountType = await getAccountType(
|
|
1732
|
+
safeOwnerAddress,
|
|
1733
|
+
publicClient
|
|
1734
|
+
);
|
|
1735
|
+
if (ownerAccountType === "Safe") {
|
|
1736
|
+
return signNestedOwnerSessionKey(
|
|
1737
|
+
config,
|
|
1738
|
+
sessions,
|
|
1739
|
+
allPublicClients,
|
|
1740
|
+
signingParams
|
|
1741
|
+
);
|
|
1742
|
+
}
|
|
1586
1743
|
const safeAccount = await getSafeAccount(config);
|
|
1587
|
-
const account = (0,
|
|
1744
|
+
const account = (0, import_module_sdk2.getAccount)({
|
|
1588
1745
|
address: safeAccount.address,
|
|
1589
1746
|
type: "safe"
|
|
1590
1747
|
});
|
|
@@ -1593,16 +1750,16 @@ var signSessionKey = async (config, sessions, allPublicClients, signingParams) =
|
|
|
1593
1750
|
sessions.map((session) => {
|
|
1594
1751
|
const sessionChainId = Number(session.chainId);
|
|
1595
1752
|
const client = clients.find((c) => c.chain?.id === sessionChainId) || publicClient;
|
|
1596
|
-
return (0,
|
|
1753
|
+
return (0, import_module_sdk2.getSessionNonce)({
|
|
1597
1754
|
client,
|
|
1598
1755
|
account,
|
|
1599
|
-
permissionId: (0,
|
|
1756
|
+
permissionId: (0, import_module_sdk2.getPermissionId)({
|
|
1600
1757
|
session
|
|
1601
1758
|
})
|
|
1602
1759
|
});
|
|
1603
1760
|
})
|
|
1604
1761
|
);
|
|
1605
|
-
const sessionDetails = await (0,
|
|
1762
|
+
const sessionDetails = await (0, import_module_sdk2.getEnableSessionDetails)({
|
|
1606
1763
|
sessions,
|
|
1607
1764
|
account,
|
|
1608
1765
|
clients,
|
|
@@ -1621,6 +1778,192 @@ var signSessionKey = async (config, sessions, allPublicClients, signingParams) =
|
|
|
1621
1778
|
sessionNonces
|
|
1622
1779
|
};
|
|
1623
1780
|
};
|
|
1781
|
+
async function signNestedOwnerSessionKey(config, sessions, allPublicClients, signingParams) {
|
|
1782
|
+
const { owner, publicClient, safeOwnerAddress } = config;
|
|
1783
|
+
const derivedChild = (await getSafeAccount(config)).address;
|
|
1784
|
+
const childSafeAddress = (0, import_viem6.getAddress)(
|
|
1785
|
+
config.childSafeAddress ?? derivedChild
|
|
1786
|
+
);
|
|
1787
|
+
const account = (0, import_module_sdk2.getAccount)({
|
|
1788
|
+
address: childSafeAddress,
|
|
1789
|
+
type: "safe"
|
|
1790
|
+
});
|
|
1791
|
+
const clients = allPublicClients || [publicClient];
|
|
1792
|
+
const sessionNonces = await Promise.all(
|
|
1793
|
+
sessions.map((session) => {
|
|
1794
|
+
const sessionChainId = Number(session.chainId);
|
|
1795
|
+
const client = clients.find((c) => c.chain?.id === sessionChainId) || publicClient;
|
|
1796
|
+
return (0, import_module_sdk2.getSessionNonce)({
|
|
1797
|
+
client,
|
|
1798
|
+
account,
|
|
1799
|
+
permissionId: (0, import_module_sdk2.getPermissionId)({
|
|
1800
|
+
session
|
|
1801
|
+
})
|
|
1802
|
+
});
|
|
1803
|
+
})
|
|
1804
|
+
);
|
|
1805
|
+
const permitGenericPolicy = signingParams?.permitGenericPolicy ?? true;
|
|
1806
|
+
const typedData = buildMultiChainSessionTypedData({
|
|
1807
|
+
childSafeAddress,
|
|
1808
|
+
sessions,
|
|
1809
|
+
sessionNonces,
|
|
1810
|
+
permitGenericPolicy
|
|
1811
|
+
});
|
|
1812
|
+
const sessionValidator = sessions[0]?.sessionValidator;
|
|
1813
|
+
if (!sessionValidator) {
|
|
1814
|
+
throw new Error(
|
|
1815
|
+
"Session configuration has no sessionValidator. The nested Safe signature cannot be routed to a validator."
|
|
1816
|
+
);
|
|
1817
|
+
}
|
|
1818
|
+
const rawSignature = await signMultiChainSessionTypedData(owner, typedData);
|
|
1819
|
+
const signature = wrapNestedSafeOwnerSignature(
|
|
1820
|
+
safeOwnerAddress,
|
|
1821
|
+
rawSignature,
|
|
1822
|
+
sessionValidator
|
|
1823
|
+
);
|
|
1824
|
+
return {
|
|
1825
|
+
signature,
|
|
1826
|
+
sessionNonces
|
|
1827
|
+
};
|
|
1828
|
+
}
|
|
1829
|
+
|
|
1830
|
+
// src/utils/nested-safe-deposit.ts
|
|
1831
|
+
var import_viem7 = require("viem");
|
|
1832
|
+
var NESTED_SAFE_DEPOSIT_TIMEOUT_MS = 20 * 60 * 1e3;
|
|
1833
|
+
var NESTED_SAFE_DEPOSIT_POLL_MS = 1e4;
|
|
1834
|
+
var NESTED_SAFE_RESUME_WINDOW_MS = 24 * 60 * 60 * 1e3;
|
|
1835
|
+
var SAFE_TX_SERVICE_NETWORK = {
|
|
1836
|
+
1: "eth",
|
|
1837
|
+
42161: "arb1",
|
|
1838
|
+
8453: "base",
|
|
1839
|
+
10: "oeth",
|
|
1840
|
+
59144: "linea",
|
|
1841
|
+
146: "sonic",
|
|
1842
|
+
9745: "plasma"
|
|
1843
|
+
};
|
|
1844
|
+
function safeTxServiceNetworkName(chainId) {
|
|
1845
|
+
return SAFE_TX_SERVICE_NETWORK[chainId];
|
|
1846
|
+
}
|
|
1847
|
+
function safeTxServiceNetworkNameOrThrow(chainId) {
|
|
1848
|
+
const networkName = safeTxServiceNetworkName(chainId);
|
|
1849
|
+
if (!networkName) {
|
|
1850
|
+
throw new Error(
|
|
1851
|
+
`Chain ${chainId} has no Safe Transaction Service. A nested Safe deposit cannot be tracked there.`
|
|
1852
|
+
);
|
|
1853
|
+
}
|
|
1854
|
+
return networkName;
|
|
1855
|
+
}
|
|
1856
|
+
async function assertParentSafeDeployedOnChain(parentSafe, publicClient, chainId) {
|
|
1857
|
+
const code = await publicClient.getCode({ address: (0, import_viem7.getAddress)(parentSafe) });
|
|
1858
|
+
if (!code || code === "0x") {
|
|
1859
|
+
throw new Error(
|
|
1860
|
+
`Parent Safe ${parentSafe} has no code on chain ${chainId}. Choose a chain where the Safe is deployed.`
|
|
1861
|
+
);
|
|
1862
|
+
}
|
|
1863
|
+
}
|
|
1864
|
+
function sameAddress(left, right) {
|
|
1865
|
+
if (!left || !right) return false;
|
|
1866
|
+
try {
|
|
1867
|
+
return (0, import_viem7.getAddress)(left) === (0, import_viem7.getAddress)(right);
|
|
1868
|
+
} catch {
|
|
1869
|
+
return false;
|
|
1870
|
+
}
|
|
1871
|
+
}
|
|
1872
|
+
function transferMatches(transaction, params) {
|
|
1873
|
+
if (!sameAddress(transaction.to, params.tokenAddress)) return false;
|
|
1874
|
+
if (transaction.isSuccessful === false) return false;
|
|
1875
|
+
const decoded = transaction.dataDecoded;
|
|
1876
|
+
if (decoded?.method?.toLowerCase() !== "transfer") return false;
|
|
1877
|
+
const parameters = decoded.parameters;
|
|
1878
|
+
if (!parameters) return false;
|
|
1879
|
+
const destination = parameters.find(
|
|
1880
|
+
(p) => (p.name === "to" || p.name === "dst" || p.name === "_to") && p.type === "address"
|
|
1881
|
+
);
|
|
1882
|
+
if (!sameAddress(destination?.value, params.childSafe)) return false;
|
|
1883
|
+
if (params.amount === void 0) return true;
|
|
1884
|
+
const valueParam = parameters.find(
|
|
1885
|
+
(p) => (p.name === "value" || p.name === "amount" || p.name === "_value" || p.name === "wad") && p.type.startsWith("uint")
|
|
1886
|
+
);
|
|
1887
|
+
if (!valueParam) return false;
|
|
1888
|
+
try {
|
|
1889
|
+
return BigInt(valueParam.value) === params.amount;
|
|
1890
|
+
} catch {
|
|
1891
|
+
return false;
|
|
1892
|
+
}
|
|
1893
|
+
}
|
|
1894
|
+
function isWithinWindow(transaction, since) {
|
|
1895
|
+
if (!since) return true;
|
|
1896
|
+
const stamp = transaction.executionDate ?? transaction.submissionDate;
|
|
1897
|
+
if (!stamp) return false;
|
|
1898
|
+
const at = Date.parse(stamp);
|
|
1899
|
+
return Number.isFinite(at) && at >= since.getTime();
|
|
1900
|
+
}
|
|
1901
|
+
async function findSafeTransferByHash(params) {
|
|
1902
|
+
const networkName = safeTxServiceNetworkNameOrThrow(params.chainId);
|
|
1903
|
+
const url = `https://api.safe.global/tx-service/${networkName}/api/v2/multisig-transactions/${params.safeTxHash}/`;
|
|
1904
|
+
const response = await fetch(url);
|
|
1905
|
+
if (!response.ok) return null;
|
|
1906
|
+
const transaction = await response.json();
|
|
1907
|
+
if (!transaction.safeTxHash) return null;
|
|
1908
|
+
if (transaction.isSuccessful === false) {
|
|
1909
|
+
throw new Error(
|
|
1910
|
+
`Safe transaction ${params.safeTxHash} on chain ${params.chainId} reverted on-chain. No deposit was registered.`
|
|
1911
|
+
);
|
|
1912
|
+
}
|
|
1913
|
+
return {
|
|
1914
|
+
safeTxHash: transaction.safeTxHash,
|
|
1915
|
+
transactionHash: transaction.transactionHash ?? null,
|
|
1916
|
+
isExecuted: transaction.isExecuted === true && !!transaction.transactionHash
|
|
1917
|
+
};
|
|
1918
|
+
}
|
|
1919
|
+
async function findSafeTransferProposal(params) {
|
|
1920
|
+
const networkName = safeTxServiceNetworkNameOrThrow(params.chainId);
|
|
1921
|
+
const url = `https://api.safe.global/tx-service/${networkName}/api/v2/safes/${(0, import_viem7.getAddress)(
|
|
1922
|
+
params.parentSafe
|
|
1923
|
+
)}/multisig-transactions/?ordering=-nonce`;
|
|
1924
|
+
const response = await fetch(url);
|
|
1925
|
+
if (!response.ok) return null;
|
|
1926
|
+
const body = await response.json();
|
|
1927
|
+
const match = (body.results ?? []).find(
|
|
1928
|
+
(transaction) => !!transaction.safeTxHash && isWithinWindow(transaction, params.since) && transferMatches(transaction, {
|
|
1929
|
+
childSafe: params.childSafe,
|
|
1930
|
+
tokenAddress: params.tokenAddress,
|
|
1931
|
+
amount: params.amount
|
|
1932
|
+
})
|
|
1933
|
+
);
|
|
1934
|
+
if (!match) return null;
|
|
1935
|
+
return {
|
|
1936
|
+
safeTxHash: match.safeTxHash,
|
|
1937
|
+
transactionHash: match.transactionHash ?? null,
|
|
1938
|
+
isExecuted: match.isExecuted === true && !!match.transactionHash
|
|
1939
|
+
};
|
|
1940
|
+
}
|
|
1941
|
+
async function waitForSafeTransferExecution(params) {
|
|
1942
|
+
safeTxServiceNetworkNameOrThrow(params.chainId);
|
|
1943
|
+
const timeoutMs = params.timeoutMs ?? NESTED_SAFE_DEPOSIT_TIMEOUT_MS;
|
|
1944
|
+
const pollMs = params.pollMs ?? NESTED_SAFE_DEPOSIT_POLL_MS;
|
|
1945
|
+
const started = Date.now();
|
|
1946
|
+
do {
|
|
1947
|
+
const proposal = params.safeTxHash ? await findSafeTransferByHash({
|
|
1948
|
+
chainId: params.chainId,
|
|
1949
|
+
safeTxHash: params.safeTxHash
|
|
1950
|
+
}) : await findSafeTransferProposal({
|
|
1951
|
+
parentSafe: params.parentSafe,
|
|
1952
|
+
childSafe: params.childSafe,
|
|
1953
|
+
chainId: params.chainId,
|
|
1954
|
+
tokenAddress: params.tokenAddress,
|
|
1955
|
+
amount: params.amount,
|
|
1956
|
+
since: params.since
|
|
1957
|
+
});
|
|
1958
|
+
if (proposal?.isExecuted && proposal.transactionHash) {
|
|
1959
|
+
return proposal.transactionHash;
|
|
1960
|
+
}
|
|
1961
|
+
await new Promise((resolve) => setTimeout(resolve, pollMs));
|
|
1962
|
+
} while (Date.now() - started < timeoutMs);
|
|
1963
|
+
throw new Error(
|
|
1964
|
+
`Timed out waiting for Safe transfer from parent ${params.parentSafe} to child ${params.childSafe} on chain ${params.chainId} for token ${params.tokenAddress} amount ${params.amount.toString()}${params.safeTxHash ? ` (safeTxHash ${params.safeTxHash})` : ""}. Call sendDeposit again once co-signers have executed the proposal; it resumes that transfer instead of proposing another.`
|
|
1965
|
+
);
|
|
1966
|
+
}
|
|
1624
1967
|
|
|
1625
1968
|
// src/utils/strategy.ts
|
|
1626
1969
|
var PUBLIC_STRATEGIES = `"conservative", "aggressive" or "yieldmaxxing"`;
|
|
@@ -2288,7 +2631,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2288
2631
|
}
|
|
2289
2632
|
this.httpClient.setAuthToken(session.accessToken);
|
|
2290
2633
|
this.authenticatedUserId = session.userId ?? "bearer-session";
|
|
2291
|
-
this.sessionEoa = session.eoa ? (0,
|
|
2634
|
+
this.sessionEoa = session.eoa ? (0, import_viem8.getAddress)(session.eoa) : null;
|
|
2292
2635
|
this.sessionChannel = session.channel;
|
|
2293
2636
|
this.isPredeployed = false;
|
|
2294
2637
|
this.predeployedResolved = false;
|
|
@@ -2337,19 +2680,28 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2337
2680
|
this.isPredeployed = loginResponse.predeployed || false;
|
|
2338
2681
|
this.predeployedResolved = true;
|
|
2339
2682
|
this.connectedSmartWallet = loginResponse.smartWallet || null;
|
|
2340
|
-
this.sessionEoa = (0,
|
|
2683
|
+
this.sessionEoa = (0, import_viem8.getAddress)(params.message.address);
|
|
2341
2684
|
this.sessionChannel = void 0;
|
|
2342
2685
|
return loginResponse;
|
|
2343
2686
|
}
|
|
2344
|
-
/**
|
|
2345
|
-
* Warn that a legacy method is deprecated in favor of sendDeposit.
|
|
2346
|
-
* Predeployed wallets no longer require deploySafe / createSessionKey.
|
|
2347
|
-
*/
|
|
2687
|
+
/** Warn that a deprecated compatibility method was called. */
|
|
2348
2688
|
warnDeprecatedOnboardingMethod(methodName) {
|
|
2349
2689
|
console.warn(
|
|
2350
2690
|
`[ZyfaiSDK] ${methodName}() is deprecated for partner integrations. Prefer sendDeposit() \u2014 predeployed Safes and session keys are handled automatically on first deposit.`
|
|
2351
2691
|
);
|
|
2352
2692
|
}
|
|
2693
|
+
/**
|
|
2694
|
+
* Warn only a pool wallet, which sendDeposit onboards on its own. A contract
|
|
2695
|
+
* owner is never predeployed and reaches these methods through sendDeposit,
|
|
2696
|
+
* so warning unconditionally tells that caller to use what it just called.
|
|
2697
|
+
* Call after authentication, once `isPredeployed` is resolved.
|
|
2698
|
+
*/
|
|
2699
|
+
warnPredeployedOnboardingMethod(methodName) {
|
|
2700
|
+
if (!this.isPredeployed) return;
|
|
2701
|
+
console.warn(
|
|
2702
|
+
`[ZyfaiSDK] ${methodName}() is not needed for a predeployed wallet \u2014 sendDeposit() deploys the Safe and enables the agent session on first deposit.`
|
|
2703
|
+
);
|
|
2704
|
+
}
|
|
2353
2705
|
/**
|
|
2354
2706
|
* Authenticate user with SIWE (Sign-In with Ethereum) & JWT token
|
|
2355
2707
|
* This is required for accessing user-specific endpoints like session-keys/config
|
|
@@ -2366,7 +2718,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2366
2718
|
return;
|
|
2367
2719
|
}
|
|
2368
2720
|
const walletClient = this.getWalletClient();
|
|
2369
|
-
const userAddress = (0,
|
|
2721
|
+
const userAddress = (0, import_viem8.getAddress)(walletClient.account.address);
|
|
2370
2722
|
const chainId = this.currentChainId || walletClient.chain?.id || 8453;
|
|
2371
2723
|
const challengeResponse = await this.httpClient.post(ENDPOINTS.AUTH_CHALLENGE, {});
|
|
2372
2724
|
let uri;
|
|
@@ -2744,10 +3096,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2744
3096
|
this.walletClient.chain?.id || 8453,
|
|
2745
3097
|
this.rpcUrls
|
|
2746
3098
|
);
|
|
2747
|
-
this.walletClient = (0,
|
|
3099
|
+
this.walletClient = (0, import_viem8.createWalletClient)({
|
|
2748
3100
|
account: newAddress,
|
|
2749
3101
|
chain: chainConfig.chain,
|
|
2750
|
-
transport: (0,
|
|
3102
|
+
transport: (0, import_viem8.custom)(this.currentProvider)
|
|
2751
3103
|
});
|
|
2752
3104
|
this.currentChainId = this.walletClient.chain?.id || null;
|
|
2753
3105
|
try {
|
|
@@ -2812,10 +3164,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2812
3164
|
}
|
|
2813
3165
|
this.signer = (0, import_accounts2.privateKeyToAccount)(privateKey);
|
|
2814
3166
|
this.currentChainId = chainId;
|
|
2815
|
-
this.walletClient = (0,
|
|
3167
|
+
this.walletClient = (0, import_viem8.createWalletClient)({
|
|
2816
3168
|
account: this.signer,
|
|
2817
3169
|
chain: chainConfig.chain,
|
|
2818
|
-
transport: (0,
|
|
3170
|
+
transport: (0, import_viem8.http)(chainConfig.rpcUrl)
|
|
2819
3171
|
});
|
|
2820
3172
|
connectedAddress = this.signer.address;
|
|
2821
3173
|
this.currentProvider = null;
|
|
@@ -2833,10 +3185,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2833
3185
|
if (!accounts || accounts.length === 0) {
|
|
2834
3186
|
throw new Error("No accounts found in wallet provider");
|
|
2835
3187
|
}
|
|
2836
|
-
this.walletClient = (0,
|
|
3188
|
+
this.walletClient = (0, import_viem8.createWalletClient)({
|
|
2837
3189
|
account: accounts[0],
|
|
2838
3190
|
chain: chainConfig.chain,
|
|
2839
|
-
transport: (0,
|
|
3191
|
+
transport: (0, import_viem8.custom)(provider)
|
|
2840
3192
|
});
|
|
2841
3193
|
connectedAddress = accounts[0];
|
|
2842
3194
|
this.currentProvider = provider;
|
|
@@ -2845,7 +3197,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2845
3197
|
provider.on("accountsChanged", this.handleAccountsChanged.bind(this));
|
|
2846
3198
|
}
|
|
2847
3199
|
} else if (provider.account && provider.transport) {
|
|
2848
|
-
this.walletClient = (0,
|
|
3200
|
+
this.walletClient = (0, import_viem8.createWalletClient)({
|
|
2849
3201
|
account: provider.account,
|
|
2850
3202
|
chain: chainConfig.chain,
|
|
2851
3203
|
transport: provider.transport
|
|
@@ -2906,10 +3258,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2906
3258
|
targetChainId,
|
|
2907
3259
|
this.rpcUrls
|
|
2908
3260
|
);
|
|
2909
|
-
return (0,
|
|
3261
|
+
return (0, import_viem8.createWalletClient)({
|
|
2910
3262
|
account: this.signer,
|
|
2911
3263
|
chain: targetChainConfig.chain,
|
|
2912
|
-
transport: (0,
|
|
3264
|
+
transport: (0, import_viem8.http)(targetChainConfig.rpcUrl)
|
|
2913
3265
|
});
|
|
2914
3266
|
} else {
|
|
2915
3267
|
if (!this.walletClient) {
|
|
@@ -2931,6 +3283,46 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2931
3283
|
* from the user record before allowing a transfer to an undeployed pool Safe.
|
|
2932
3284
|
* @private
|
|
2933
3285
|
*/
|
|
3286
|
+
/**
|
|
3287
|
+
* Deploy the child Zyfai Safe and session for a nested (contract) owner.
|
|
3288
|
+
* @private
|
|
3289
|
+
*/
|
|
3290
|
+
async ensureNestedOwnerReadyForDeposit(userAddress, chainId, strategy) {
|
|
3291
|
+
if (this.isPredeployed) return;
|
|
3292
|
+
const chainConfig = getChainConfig(chainId, this.rpcUrls);
|
|
3293
|
+
const ownerType = await getAccountType(
|
|
3294
|
+
userAddress,
|
|
3295
|
+
chainConfig.publicClient
|
|
3296
|
+
);
|
|
3297
|
+
if (ownerType !== "Safe") return;
|
|
3298
|
+
await assertParentSafeDeployedOnChain(
|
|
3299
|
+
userAddress,
|
|
3300
|
+
chainConfig.publicClient,
|
|
3301
|
+
chainId
|
|
3302
|
+
);
|
|
3303
|
+
const childAddress = await this.getSafeAddressFor(userAddress, chainId);
|
|
3304
|
+
if (!childAddress) {
|
|
3305
|
+
throw new Error("Child smart wallet address is not available");
|
|
3306
|
+
}
|
|
3307
|
+
const childDeployed = await isSafeDeployed(
|
|
3308
|
+
childAddress,
|
|
3309
|
+
chainConfig.publicClient
|
|
3310
|
+
);
|
|
3311
|
+
if (!childDeployed) {
|
|
3312
|
+
await this.deploySafe(userAddress, chainId, strategy, true);
|
|
3313
|
+
return;
|
|
3314
|
+
}
|
|
3315
|
+
if (!this.hasActiveSessionKey) {
|
|
3316
|
+
try {
|
|
3317
|
+
await this.createSessionKey(userAddress, chainId);
|
|
3318
|
+
} catch (sessionError) {
|
|
3319
|
+
console.warn(
|
|
3320
|
+
"Failed to create session key for nested owner:",
|
|
3321
|
+
sessionError.message
|
|
3322
|
+
);
|
|
3323
|
+
}
|
|
3324
|
+
}
|
|
3325
|
+
}
|
|
2934
3326
|
async hydrateSessionWallet() {
|
|
2935
3327
|
if (this.predeployedResolved || !this.sessionEoa) return;
|
|
2936
3328
|
const me = await this.httpClient.get(ENDPOINTS.USER_ME);
|
|
@@ -3015,9 +3407,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3015
3407
|
/**
|
|
3016
3408
|
* Deploy Safe Smart Wallet for a user
|
|
3017
3409
|
*
|
|
3018
|
-
*
|
|
3019
|
-
*
|
|
3020
|
-
* legacy
|
|
3410
|
+
* Not needed for a predeployed (pool) wallet: {@link ZyfaiSDK.sendDeposit} deploys the Safe and
|
|
3411
|
+
* enables the agent session on first deposit. Required for an owner that is not predeployed —
|
|
3412
|
+
* a contract owner such as a nested Safe, or a legacy self-deployed wallet — where `sendDeposit`
|
|
3413
|
+
* calls this method internally.
|
|
3021
3414
|
*
|
|
3022
3415
|
* @see {@link ZyfaiSDK.sendDeposit}
|
|
3023
3416
|
*
|
|
@@ -3031,16 +3424,15 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3031
3424
|
*
|
|
3032
3425
|
* @example
|
|
3033
3426
|
* ```typescript
|
|
3034
|
-
* // Preferred: sendDeposit handles
|
|
3427
|
+
* // Preferred: sendDeposit handles onboarding for every owner type
|
|
3035
3428
|
* const sent = await sdk.sendDeposit(userAddress, 8453, amount, "USDC");
|
|
3036
3429
|
* await sdk.waitForDepositCredit(sent.registration.id, 8453);
|
|
3037
3430
|
*
|
|
3038
|
-
* //
|
|
3431
|
+
* // Explicit: deploy with default conservative strategy
|
|
3039
3432
|
* await sdk.deploySafe(userAddress, 8453);
|
|
3040
3433
|
* ```
|
|
3041
3434
|
*/
|
|
3042
3435
|
async deploySafe(userAddress, chainId, strategy, createSessionKey) {
|
|
3043
|
-
this.warnDeprecatedOnboardingMethod("deploySafe");
|
|
3044
3436
|
try {
|
|
3045
3437
|
if (!userAddress) {
|
|
3046
3438
|
throw new Error("User address is required");
|
|
@@ -3049,6 +3441,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3049
3441
|
throw new Error(`Unsupported chain ID: ${chainId}`);
|
|
3050
3442
|
}
|
|
3051
3443
|
await this.authenticateUser();
|
|
3444
|
+
this.warnPredeployedOnboardingMethod("deploySafe");
|
|
3052
3445
|
if (this.isPredeployed && this.isConnectedUser(userAddress)) {
|
|
3053
3446
|
const predeployedAddress = await this.getSafeAddressFor(
|
|
3054
3447
|
userAddress,
|
|
@@ -3150,18 +3543,17 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3150
3543
|
};
|
|
3151
3544
|
} catch (error) {
|
|
3152
3545
|
console.error("Safe deployment failed:", error);
|
|
3153
|
-
throw new Error(
|
|
3154
|
-
`Safe deployment failed: ${error.message}. deploySafe() is deprecated \u2014 prefer sendDeposit() for predeployed wallet onboarding.`
|
|
3155
|
-
);
|
|
3546
|
+
throw new Error(`Safe deployment failed: ${error.message}`);
|
|
3156
3547
|
}
|
|
3157
3548
|
}
|
|
3158
3549
|
/**
|
|
3159
3550
|
* Create session key with auto-fetched configuration from Zyfai API
|
|
3160
3551
|
* This is the simplified method that automatically fetches session configuration
|
|
3161
3552
|
*
|
|
3162
|
-
*
|
|
3163
|
-
*
|
|
3164
|
-
*
|
|
3553
|
+
* Not needed for a predeployed (pool) wallet: its agent session is already enabled on-chain and
|
|
3554
|
+
* {@link ZyfaiSDK.sendDeposit} records it after the first deposit. Required for an owner that is
|
|
3555
|
+
* not predeployed — a contract owner such as a nested Safe, or a legacy self-deployed wallet —
|
|
3556
|
+
* where `sendDeposit` calls this method internally.
|
|
3165
3557
|
*
|
|
3166
3558
|
* @see {@link ZyfaiSDK.sendDeposit}
|
|
3167
3559
|
*
|
|
@@ -3173,18 +3565,18 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3173
3565
|
*
|
|
3174
3566
|
* @example
|
|
3175
3567
|
* ```typescript
|
|
3176
|
-
* // Preferred: sendDeposit handles session onboarding for
|
|
3568
|
+
* // Preferred: sendDeposit handles session onboarding for every owner type
|
|
3177
3569
|
* const sent = await sdk.sendDeposit(userAddress, 8453, amount, "USDC");
|
|
3178
3570
|
* await sdk.waitForDepositCredit(sent.registration.id, 8453);
|
|
3179
3571
|
*
|
|
3180
|
-
* //
|
|
3572
|
+
* // Explicit:
|
|
3181
3573
|
* const result = await sdk.createSessionKey(userAddress, 8453);
|
|
3182
3574
|
* ```
|
|
3183
3575
|
*/
|
|
3184
3576
|
async createSessionKey(userAddress, chainId) {
|
|
3185
|
-
this.warnDeprecatedOnboardingMethod("createSessionKey");
|
|
3186
3577
|
try {
|
|
3187
3578
|
await this.authenticateUser();
|
|
3579
|
+
this.warnPredeployedOnboardingMethod("createSessionKey");
|
|
3188
3580
|
if (!this.authenticatedUserId) {
|
|
3189
3581
|
throw new Error(
|
|
3190
3582
|
"User ID not available. Please ensure authentication completed successfully."
|
|
@@ -3229,6 +3621,12 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3229
3621
|
userAddress,
|
|
3230
3622
|
chainConfig.publicClient
|
|
3231
3623
|
);
|
|
3624
|
+
if (accountType === "Safe") {
|
|
3625
|
+
await this.assertOwnerSafeOnSessionChains(
|
|
3626
|
+
userAddress,
|
|
3627
|
+
sessions
|
|
3628
|
+
);
|
|
3629
|
+
}
|
|
3232
3630
|
const signingParams = {
|
|
3233
3631
|
permitGenericPolicy,
|
|
3234
3632
|
ignoreSecurityAttestations: accountType === "Safe"
|
|
@@ -3256,7 +3654,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3256
3654
|
};
|
|
3257
3655
|
} catch (error) {
|
|
3258
3656
|
throw new Error(
|
|
3259
|
-
`Failed to create session key: ${error.message}
|
|
3657
|
+
`Failed to create session key: ${error.message}`
|
|
3260
3658
|
);
|
|
3261
3659
|
}
|
|
3262
3660
|
}
|
|
@@ -3264,6 +3662,35 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3264
3662
|
* Internal method to sign session key
|
|
3265
3663
|
* @private
|
|
3266
3664
|
*/
|
|
3665
|
+
/**
|
|
3666
|
+
* A nested Safe owner signs one MultiChainSession covering every chain in the
|
|
3667
|
+
* session configuration, and the child validates that signature against the
|
|
3668
|
+
* owner through ERC-1271 on each of them. A chain where the owner has no code
|
|
3669
|
+
* would accept the signature nowhere, so refuse rather than sign it.
|
|
3670
|
+
*
|
|
3671
|
+
* The session list is not filtered here: the execution API rebuilds the digest
|
|
3672
|
+
* from its own configuration, so dropping a chain client-side would change the
|
|
3673
|
+
* hash and the signature would be rejected everywhere.
|
|
3674
|
+
* @private
|
|
3675
|
+
*/
|
|
3676
|
+
async assertOwnerSafeOnSessionChains(ownerAddress, sessions) {
|
|
3677
|
+
const chainIds = [
|
|
3678
|
+
...new Set(sessions.map((session) => Number(session.chainId)))
|
|
3679
|
+
].filter(isSupportedChain);
|
|
3680
|
+
const missing = [];
|
|
3681
|
+
await Promise.all(
|
|
3682
|
+
chainIds.map(async (id) => {
|
|
3683
|
+
const { publicClient } = getChainConfig(id, this.rpcUrls);
|
|
3684
|
+
const code = await publicClient.getCode({ address: ownerAddress });
|
|
3685
|
+
if (!code || code === "0x") missing.push(id);
|
|
3686
|
+
})
|
|
3687
|
+
);
|
|
3688
|
+
if (missing.length > 0) {
|
|
3689
|
+
throw new Error(
|
|
3690
|
+
`Owner Safe ${ownerAddress} has no code on chain(s) ${missing.sort((a, b) => a - b).join(", ")} covered by the session configuration. Deploy the Safe there, or restrict the user's chains, before signing the session.`
|
|
3691
|
+
);
|
|
3692
|
+
}
|
|
3693
|
+
}
|
|
3267
3694
|
async signSessionKey(userAddress, chainId, sessions, signingParams) {
|
|
3268
3695
|
try {
|
|
3269
3696
|
if (!userAddress) {
|
|
@@ -3277,14 +3704,13 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3277
3704
|
}
|
|
3278
3705
|
const walletClient = this.getWalletClient();
|
|
3279
3706
|
const chainConfig = getChainConfig(chainId, this.rpcUrls);
|
|
3280
|
-
|
|
3707
|
+
await this.hydrateSessionWallet();
|
|
3708
|
+
const childSafeAddress = await this.getSafeAddressFor(
|
|
3281
3709
|
userAddress,
|
|
3282
|
-
|
|
3710
|
+
chainId
|
|
3283
3711
|
);
|
|
3284
|
-
if (
|
|
3285
|
-
throw new Error(
|
|
3286
|
-
`Invalid account type for ${userAddress}. Must be an EOA.`
|
|
3287
|
-
);
|
|
3712
|
+
if (!childSafeAddress) {
|
|
3713
|
+
throw new Error("Child smart wallet address is not available");
|
|
3288
3714
|
}
|
|
3289
3715
|
const sessionChainIds = [
|
|
3290
3716
|
...new Set(sessions.map((s) => Number(s.chainId)))
|
|
@@ -3294,6 +3720,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3294
3720
|
{
|
|
3295
3721
|
owner: walletClient,
|
|
3296
3722
|
safeOwnerAddress: userAddress,
|
|
3723
|
+
childSafeAddress,
|
|
3297
3724
|
chain: chainConfig.chain,
|
|
3298
3725
|
publicClient: chainConfig.publicClient
|
|
3299
3726
|
},
|
|
@@ -3785,6 +4212,15 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3785
4212
|
throw new Error("Smart wallet address is not available");
|
|
3786
4213
|
}
|
|
3787
4214
|
const amountBigInt = BigInt(amount);
|
|
4215
|
+
const ownerType = await getAccountType(
|
|
4216
|
+
userAddress,
|
|
4217
|
+
chainConfig.publicClient
|
|
4218
|
+
);
|
|
4219
|
+
if (ownerType !== "EOA" && ownerType !== "Safe") {
|
|
4220
|
+
throw new Error(
|
|
4221
|
+
`Could not resolve the account type of ${userAddress} on chain ${chainId}: it is neither an EOA nor a Safe, or the RPC read failed. No deposit was sent.`
|
|
4222
|
+
);
|
|
4223
|
+
}
|
|
3788
4224
|
const [isDeployed, currentSafeBalance] = await Promise.all([
|
|
3789
4225
|
isSafeDeployed(safeAddress, chainConfig.publicClient),
|
|
3790
4226
|
minRequired !== void 0 ? chainConfig.publicClient.readContract({
|
|
@@ -3796,7 +4232,18 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3796
4232
|
this.prepareFirstDeposit(strategy)
|
|
3797
4233
|
]).then(([deployed, balance]) => [deployed, balance]);
|
|
3798
4234
|
if (!isDeployed) {
|
|
3799
|
-
if (
|
|
4235
|
+
if (ownerType === "Safe" && !this.isPredeployed) {
|
|
4236
|
+
await assertParentSafeDeployedOnChain(
|
|
4237
|
+
userAddress,
|
|
4238
|
+
chainConfig.publicClient,
|
|
4239
|
+
chainId
|
|
4240
|
+
);
|
|
4241
|
+
await this.ensureNestedOwnerReadyForDeposit(
|
|
4242
|
+
userAddress,
|
|
4243
|
+
chainId,
|
|
4244
|
+
strategy
|
|
4245
|
+
);
|
|
4246
|
+
} else if (!(this.isPredeployed && this.isConnectedUser(userAddress))) {
|
|
3800
4247
|
throw new Error(
|
|
3801
4248
|
`Safe not available for ${userAddress} on chain ${chainId}.`
|
|
3802
4249
|
);
|
|
@@ -3819,16 +4266,74 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3819
4266
|
);
|
|
3820
4267
|
}
|
|
3821
4268
|
}
|
|
4269
|
+
if (ownerType === "Safe" && isDeployed) {
|
|
4270
|
+
await assertParentSafeDeployedOnChain(
|
|
4271
|
+
userAddress,
|
|
4272
|
+
chainConfig.publicClient,
|
|
4273
|
+
chainId
|
|
4274
|
+
);
|
|
4275
|
+
await this.ensureNestedOwnerReadyForDeposit(
|
|
4276
|
+
userAddress,
|
|
4277
|
+
chainId,
|
|
4278
|
+
strategy
|
|
4279
|
+
);
|
|
4280
|
+
}
|
|
3822
4281
|
if (allowPermit && this.isPredeployed && this.isConnectedUser(userAddress)) {
|
|
3823
4282
|
const sponsored = await this.sendFirstPermitDeposit({
|
|
3824
|
-
owner: (0,
|
|
4283
|
+
owner: (0, import_viem8.getAddress)(userAddress),
|
|
3825
4284
|
safe: safeAddress,
|
|
3826
4285
|
chainId,
|
|
3827
|
-
token: (0,
|
|
4286
|
+
token: (0, import_viem8.getAddress)(token),
|
|
3828
4287
|
amount: amountBigInt
|
|
3829
4288
|
});
|
|
3830
4289
|
if (sponsored) return sponsored;
|
|
3831
4290
|
}
|
|
4291
|
+
if (ownerType === "Safe") {
|
|
4292
|
+
const since = new Date(Date.now() - NESTED_SAFE_RESUME_WINDOW_MS);
|
|
4293
|
+
const inFlight = await findSafeTransferProposal({
|
|
4294
|
+
parentSafe: userAddress,
|
|
4295
|
+
childSafe: safeAddress,
|
|
4296
|
+
chainId,
|
|
4297
|
+
tokenAddress: token,
|
|
4298
|
+
amount: amountBigInt,
|
|
4299
|
+
since
|
|
4300
|
+
});
|
|
4301
|
+
let safeTxHash = inFlight?.safeTxHash;
|
|
4302
|
+
if (!inFlight) {
|
|
4303
|
+
const proposed = await walletClient.writeContract({
|
|
4304
|
+
address: token,
|
|
4305
|
+
abi: erc20TransferWriteAbi(assetSymbol),
|
|
4306
|
+
functionName: "transfer",
|
|
4307
|
+
args: [safeAddress, amountBigInt],
|
|
4308
|
+
chain: chainConfig.chain,
|
|
4309
|
+
account: walletClient.account
|
|
4310
|
+
});
|
|
4311
|
+
safeTxHash = (await findSafeTransferByHash({ chainId, safeTxHash: proposed }))?.safeTxHash;
|
|
4312
|
+
}
|
|
4313
|
+
const executedHash = inFlight?.isExecuted && inFlight.transactionHash ? inFlight.transactionHash : await waitForSafeTransferExecution({
|
|
4314
|
+
parentSafe: userAddress,
|
|
4315
|
+
childSafe: safeAddress,
|
|
4316
|
+
chainId,
|
|
4317
|
+
tokenAddress: token,
|
|
4318
|
+
amount: amountBigInt,
|
|
4319
|
+
safeTxHash,
|
|
4320
|
+
since
|
|
4321
|
+
});
|
|
4322
|
+
const registration2 = await this.registerDeposit(
|
|
4323
|
+
chainId,
|
|
4324
|
+
executedHash,
|
|
4325
|
+
amount,
|
|
4326
|
+
token
|
|
4327
|
+
);
|
|
4328
|
+
return {
|
|
4329
|
+
success: true,
|
|
4330
|
+
txHash: executedHash,
|
|
4331
|
+
smartWallet: safeAddress,
|
|
4332
|
+
amount: amountBigInt.toString(),
|
|
4333
|
+
route: "direct",
|
|
4334
|
+
registration: registration2
|
|
4335
|
+
};
|
|
4336
|
+
}
|
|
3832
4337
|
const txHash = await walletClient.writeContract({
|
|
3833
4338
|
address: token,
|
|
3834
4339
|
abi: erc20TransferWriteAbi(assetSymbol),
|
|
@@ -3881,7 +4386,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3881
4386
|
* ```
|
|
3882
4387
|
*/
|
|
3883
4388
|
async getFirstPermitDepositStatus(userAddress) {
|
|
3884
|
-
if (!this.sessionEoa || !(0,
|
|
4389
|
+
if (!this.sessionEoa || !(0, import_viem8.isAddressEqual)((0, import_viem8.getAddress)(userAddress), this.sessionEoa)) {
|
|
3885
4390
|
throw new Error("userAddress does not match authenticated session EOA");
|
|
3886
4391
|
}
|
|
3887
4392
|
return (await this.getFirstPermitDepositAvailability()).intent;
|
|
@@ -4352,16 +4857,16 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4352
4857
|
method: "wallet_switchEthereumChain",
|
|
4353
4858
|
params: [{ chainId: `0x${originChainId.toString(16)}` }]
|
|
4354
4859
|
});
|
|
4355
|
-
const chain = isSupportedChain(originChainId) ? getChainConfig(originChainId, this.rpcUrls).chain : (0,
|
|
4860
|
+
const chain = isSupportedChain(originChainId) ? getChainConfig(originChainId, this.rpcUrls).chain : (0, import_viem8.defineChain)({
|
|
4356
4861
|
id: originChainId,
|
|
4357
4862
|
name: `Chain ${originChainId}`,
|
|
4358
4863
|
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
4359
4864
|
rpcUrls: { default: { http: ["http://127.0.0.1"] } }
|
|
4360
4865
|
});
|
|
4361
|
-
this.walletClient = (0,
|
|
4866
|
+
this.walletClient = (0, import_viem8.createWalletClient)({
|
|
4362
4867
|
account: this.walletClient.account,
|
|
4363
4868
|
chain,
|
|
4364
|
-
transport: (0,
|
|
4869
|
+
transport: (0, import_viem8.custom)(this.currentProvider)
|
|
4365
4870
|
});
|
|
4366
4871
|
if (isSupportedChain(originChainId)) {
|
|
4367
4872
|
this.currentChainId = originChainId;
|
|
@@ -4537,7 +5042,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4537
5042
|
safeAddress,
|
|
4538
5043
|
tokenAddress,
|
|
4539
5044
|
to: tokenAddress,
|
|
4540
|
-
data: (0,
|
|
5045
|
+
data: (0, import_viem8.encodeFunctionData)({
|
|
4541
5046
|
abi: ERC20_ABI,
|
|
4542
5047
|
functionName: "transfer",
|
|
4543
5048
|
args: [safeAddress, amountBigInt]
|
|
@@ -4566,7 +5071,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4566
5071
|
if (!userAddress) {
|
|
4567
5072
|
throw new Error("A user address is required");
|
|
4568
5073
|
}
|
|
4569
|
-
const owner = (0,
|
|
5074
|
+
const owner = (0, import_viem8.getAddress)(userAddress);
|
|
4570
5075
|
const chainId = 8453;
|
|
4571
5076
|
await this.hydrateSessionWallet();
|
|
4572
5077
|
const safe = await this.getSafeAddressFor(owner, chainId);
|
|
@@ -4588,7 +5093,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4588
5093
|
]).catch(() => {
|
|
4589
5094
|
throw new Error(`Safe ${safe} is not deployed on Base`);
|
|
4590
5095
|
});
|
|
4591
|
-
if (threshold !== 1n || !owners.some((o) => (0,
|
|
5096
|
+
if (threshold !== 1n || !owners.some((o) => (0, import_viem8.getAddress)(o) === owner)) {
|
|
4592
5097
|
throw new Error(
|
|
4593
5098
|
`${owner} cannot execute Safe ${safe} alone (not an owner, or threshold above 1)`
|
|
4594
5099
|
);
|
|
@@ -4677,7 +5182,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4677
5182
|
if (!userAddress) {
|
|
4678
5183
|
throw new Error("A user address is required");
|
|
4679
5184
|
}
|
|
4680
|
-
if (this.sessionEoa && (0,
|
|
5185
|
+
if (this.sessionEoa && (0, import_viem8.getAddress)(userAddress) !== this.sessionEoa) {
|
|
4681
5186
|
throw new Error("userAddress does not match authenticated session EOA");
|
|
4682
5187
|
}
|
|
4683
5188
|
}
|
|
@@ -4823,7 +5328,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4823
5328
|
*/
|
|
4824
5329
|
async prepareDeposit(params) {
|
|
4825
5330
|
const { userAddress, chainId, amount, asset } = params;
|
|
4826
|
-
if (this.sessionEoa && (0,
|
|
5331
|
+
if (this.sessionEoa && (0, import_viem8.getAddress)(userAddress) !== this.sessionEoa) {
|
|
4827
5332
|
throw new Error("userAddress does not match authenticated session EOA");
|
|
4828
5333
|
}
|
|
4829
5334
|
const setup = await this.ensureDepositProfileForPrepare({
|
|
@@ -6882,7 +7387,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
6882
7387
|
if (!tokenUriResponse.tokenUri) {
|
|
6883
7388
|
throw new Error("API did not return a tokenUri");
|
|
6884
7389
|
}
|
|
6885
|
-
const callData = (0,
|
|
7390
|
+
const callData = (0, import_viem8.encodeFunctionData)({
|
|
6886
7391
|
abi: IDENTITY_REGISTRY_ABI,
|
|
6887
7392
|
functionName: "register",
|
|
6888
7393
|
args: [tokenUriResponse.tokenUri]
|
|
@@ -7350,6 +7855,206 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
7350
7855
|
_ZyfaiSDK.IDENTITY_REGISTRY_CHAIN_IDS = [8453, 42161];
|
|
7351
7856
|
var ZyfaiSDK = _ZyfaiSDK;
|
|
7352
7857
|
|
|
7858
|
+
// src/utils/session-verification.ts
|
|
7859
|
+
var import_module_sdk3 = require("@rhinestone/module-sdk");
|
|
7860
|
+
var import_viem9 = require("viem");
|
|
7861
|
+
function buildV1ChainSessions(inputs) {
|
|
7862
|
+
const chainSessions = inputs.map(({ account, smartSession, nonce, session, permitGenericPolicy, permitAdminAccess, ignoreSecurityAttestations }) => ({
|
|
7863
|
+
chainId: session.chainId,
|
|
7864
|
+
session: {
|
|
7865
|
+
account,
|
|
7866
|
+
smartSession,
|
|
7867
|
+
nonce,
|
|
7868
|
+
sessionValidator: session.sessionValidator,
|
|
7869
|
+
sessionValidatorInitData: session.sessionValidatorInitData,
|
|
7870
|
+
salt: session.salt,
|
|
7871
|
+
permissions: {
|
|
7872
|
+
permitGenericPolicy,
|
|
7873
|
+
permitAdminAccess,
|
|
7874
|
+
ignoreSecurityAttestations,
|
|
7875
|
+
permitERC4337Paymaster: session.permitERC4337Paymaster,
|
|
7876
|
+
userOpPolicies: session.userOpPolicies,
|
|
7877
|
+
erc7739Policies: session.erc7739Policies,
|
|
7878
|
+
actions: session.actions
|
|
7879
|
+
}
|
|
7880
|
+
}
|
|
7881
|
+
}));
|
|
7882
|
+
validateV1ChainSessions(chainSessions);
|
|
7883
|
+
return chainSessions;
|
|
7884
|
+
}
|
|
7885
|
+
function validateV1ChainSessions(sessions) {
|
|
7886
|
+
const fail = () => {
|
|
7887
|
+
throw new Error("Invalid v1 chain session payload");
|
|
7888
|
+
};
|
|
7889
|
+
const address = (v) => typeof v === "string" && (0, import_viem9.isAddress)(v);
|
|
7890
|
+
const hex = (v, bytes) => typeof v === "string" && (0, import_viem9.isHex)(v, { strict: true }) && v.length % 2 === 0 && (bytes === void 0 || (0, import_viem9.size)(v) === bytes);
|
|
7891
|
+
const policies = (v) => Array.isArray(v) && v.every((p) => p && address(p.policy) && hex(p.initData));
|
|
7892
|
+
if (!Array.isArray(sessions) || !sessions.length) fail();
|
|
7893
|
+
for (const entry of sessions) {
|
|
7894
|
+
const s = entry?.session;
|
|
7895
|
+
const p = s?.permissions;
|
|
7896
|
+
if (typeof entry?.chainId !== "bigint" || entry.chainId < 0n || entry.chainId >= 2n ** 64n || !s || typeof s.nonce !== "bigint" || s.nonce < 0n || s.nonce >= 2n ** 256n || !address(s.account) || !address(s.smartSession) || !address(s.sessionValidator) || !hex(s.sessionValidatorInitData) || !hex(s.salt, 32) || !p || typeof p.permitGenericPolicy !== "boolean" || typeof p.permitAdminAccess !== "boolean" || typeof p.ignoreSecurityAttestations !== "boolean" || typeof p.permitERC4337Paymaster !== "boolean" || !policies(p.userOpPolicies) || !p.erc7739Policies || !policies(p.erc7739Policies.erc1271Policies) || !Array.isArray(p.erc7739Policies.allowedERC7739Content) || !p.erc7739Policies.allowedERC7739Content.every((c) => c && hex(c.appDomainSeparator, 32) && Array.isArray(c.contentName) && c.contentName.every((n) => typeof n === "string")) || !Array.isArray(p.actions) || !p.actions.every((a) => a && address(a.actionTarget) && hex(a.actionTargetSelector, 4) && policies(a.actionPolicies))) fail();
|
|
7897
|
+
}
|
|
7898
|
+
}
|
|
7899
|
+
function serializeV1ChainSessions(chainSessions) {
|
|
7900
|
+
validateV1ChainSessions(chainSessions);
|
|
7901
|
+
return JSON.stringify(chainSessions.map((entry) => ({
|
|
7902
|
+
...entry,
|
|
7903
|
+
chainId: entry.chainId.toString(),
|
|
7904
|
+
session: { ...entry.session, nonce: entry.session.nonce.toString() }
|
|
7905
|
+
})), null, 2);
|
|
7906
|
+
}
|
|
7907
|
+
function parseV1ChainSessions(json) {
|
|
7908
|
+
const parsed = JSON.parse(json);
|
|
7909
|
+
if (!Array.isArray(parsed) || !parsed.length) throw new Error("Invalid v1 chain session payload");
|
|
7910
|
+
const decimal = (v) => typeof v === "string" && /^(0|[1-9][0-9]*)$/.test(v);
|
|
7911
|
+
const sessions = parsed.map((entry) => {
|
|
7912
|
+
if (!entry || !decimal(entry.chainId) || !entry.session || !decimal(entry.session.nonce)) {
|
|
7913
|
+
throw new Error("Chain IDs and nonces must be decimal strings");
|
|
7914
|
+
}
|
|
7915
|
+
return { ...entry, chainId: BigInt(entry.chainId), session: { ...entry.session, nonce: BigInt(entry.session.nonce) } };
|
|
7916
|
+
});
|
|
7917
|
+
validateV1ChainSessions(sessions);
|
|
7918
|
+
return sessions;
|
|
7919
|
+
}
|
|
7920
|
+
function hashV1SessionEnable(chainSessions) {
|
|
7921
|
+
validateV1ChainSessions(chainSessions);
|
|
7922
|
+
const permissionEnableHash = (0, import_module_sdk3.hashChainSessions)(chainSessions);
|
|
7923
|
+
return { permissionEnableHash, personalSignDigest: (0, import_viem9.hashMessage)({ raw: permissionEnableHash }) };
|
|
7924
|
+
}
|
|
7925
|
+
|
|
7926
|
+
// src/utils/userop-verification.ts
|
|
7927
|
+
var import_viem10 = require("viem");
|
|
7928
|
+
var ENTRY_POINT_V07_ADDRESS = "0x0000000071727De22E5E9d8BAf0edAc6f37da032";
|
|
7929
|
+
var KNOWN_CALLS_ABI = (0, import_viem10.parseAbi)([
|
|
7930
|
+
"function setupSafe((address singleton, address[] owners, uint256 threshold, address setupTo, bytes setupData, address safe7579, (address module, bytes initData)[] validators, bytes callData) initData)",
|
|
7931
|
+
"function execute(bytes32 mode, bytes executionCalldata)",
|
|
7932
|
+
"function setRegistry(address registry, address[] attesters, uint8 threshold)",
|
|
7933
|
+
"function installModule(uint256 moduleTypeId, address module, bytes initData)",
|
|
7934
|
+
"function enableSessions((address sessionValidator, bytes sessionValidatorInitData, bytes32 salt, (address policy, bytes initData)[] userOpPolicies, ((bytes32 appDomainSeparator, string[] contentName)[] allowedERC7739Content, (address policy, bytes initData)[] erc1271Policies) erc7739Policies, (bytes4 actionTargetSelector, address actionTarget, (address policy, bytes initData)[] actionPolicies)[] actions, bool permitERC4337Paymaster)[] sessions)"
|
|
7935
|
+
]);
|
|
7936
|
+
var ERC7579_CALLTYPE_SINGLE = "0x00";
|
|
7937
|
+
var ERC7579_CALLTYPE_BATCH = "0x01";
|
|
7938
|
+
var INTEGER_FIELDS = [
|
|
7939
|
+
"nonce",
|
|
7940
|
+
"callGasLimit",
|
|
7941
|
+
"verificationGasLimit",
|
|
7942
|
+
"preVerificationGas",
|
|
7943
|
+
"maxFeePerGas",
|
|
7944
|
+
"maxPriorityFeePerGas",
|
|
7945
|
+
"paymasterVerificationGasLimit",
|
|
7946
|
+
"paymasterPostOpGasLimit"
|
|
7947
|
+
];
|
|
7948
|
+
function parseUserOperationJson(json) {
|
|
7949
|
+
const raw = JSON.parse(json);
|
|
7950
|
+
const fail = () => {
|
|
7951
|
+
throw new Error("Invalid user operation JSON");
|
|
7952
|
+
};
|
|
7953
|
+
if (!raw || typeof raw !== "object") fail();
|
|
7954
|
+
const input = raw;
|
|
7955
|
+
const integer = (v) => typeof v === "string" && /^(0|[1-9][0-9]*|0x[0-9a-fA-F]+)$/.test(v) ? BigInt(v) : fail();
|
|
7956
|
+
const bytes = (v) => typeof v === "string" && (0, import_viem10.isHex)(v, { strict: true }) && v.length % 2 === 0 ? v : fail();
|
|
7957
|
+
const address = (v) => typeof v === "string" && (0, import_viem10.isAddress)(v, { strict: false }) ? v : fail();
|
|
7958
|
+
const op = {
|
|
7959
|
+
sender: address(input.sender),
|
|
7960
|
+
nonce: integer(input.nonce),
|
|
7961
|
+
callData: bytes(input.callData),
|
|
7962
|
+
callGasLimit: integer(input.callGasLimit),
|
|
7963
|
+
verificationGasLimit: integer(input.verificationGasLimit),
|
|
7964
|
+
preVerificationGas: integer(input.preVerificationGas),
|
|
7965
|
+
maxFeePerGas: integer(input.maxFeePerGas),
|
|
7966
|
+
maxPriorityFeePerGas: integer(input.maxPriorityFeePerGas)
|
|
7967
|
+
};
|
|
7968
|
+
if (input.factory !== void 0 && input.factory !== null) {
|
|
7969
|
+
op.factory = address(input.factory);
|
|
7970
|
+
op.factoryData = bytes(input.factoryData ?? "0x");
|
|
7971
|
+
}
|
|
7972
|
+
if (input.paymaster !== void 0 && input.paymaster !== null) {
|
|
7973
|
+
op.paymaster = address(input.paymaster);
|
|
7974
|
+
op.paymasterVerificationGasLimit = integer(input.paymasterVerificationGasLimit ?? "0");
|
|
7975
|
+
op.paymasterPostOpGasLimit = integer(input.paymasterPostOpGasLimit ?? "0");
|
|
7976
|
+
op.paymasterData = bytes(input.paymasterData ?? "0x");
|
|
7977
|
+
}
|
|
7978
|
+
for (const field of INTEGER_FIELDS) {
|
|
7979
|
+
const value = op[field];
|
|
7980
|
+
if (value !== void 0 && value >= 2n ** 256n) fail();
|
|
7981
|
+
}
|
|
7982
|
+
return op;
|
|
7983
|
+
}
|
|
7984
|
+
var uint128 = (value) => (0, import_viem10.numberToHex)(value, { size: 16 });
|
|
7985
|
+
function hashUserOperationV07(userOp, chainId, entryPoint = ENTRY_POINT_V07_ADDRESS) {
|
|
7986
|
+
const initCode = userOp.factory ? (0, import_viem10.concat)([userOp.factory, userOp.factoryData ?? "0x"]) : "0x";
|
|
7987
|
+
const paymasterAndData = userOp.paymaster ? (0, import_viem10.concat)([
|
|
7988
|
+
userOp.paymaster,
|
|
7989
|
+
uint128(userOp.paymasterVerificationGasLimit ?? 0n),
|
|
7990
|
+
uint128(userOp.paymasterPostOpGasLimit ?? 0n),
|
|
7991
|
+
userOp.paymasterData ?? "0x"
|
|
7992
|
+
]) : "0x";
|
|
7993
|
+
const packed = (0, import_viem10.encodeAbiParameters)(
|
|
7994
|
+
[
|
|
7995
|
+
{ type: "address" },
|
|
7996
|
+
{ type: "uint256" },
|
|
7997
|
+
{ type: "bytes32" },
|
|
7998
|
+
{ type: "bytes32" },
|
|
7999
|
+
{ type: "bytes32" },
|
|
8000
|
+
{ type: "uint256" },
|
|
8001
|
+
{ type: "bytes32" },
|
|
8002
|
+
{ type: "bytes32" }
|
|
8003
|
+
],
|
|
8004
|
+
[
|
|
8005
|
+
userOp.sender,
|
|
8006
|
+
userOp.nonce,
|
|
8007
|
+
(0, import_viem10.keccak256)(initCode),
|
|
8008
|
+
(0, import_viem10.keccak256)(userOp.callData),
|
|
8009
|
+
(0, import_viem10.concat)([uint128(userOp.verificationGasLimit), uint128(userOp.callGasLimit)]),
|
|
8010
|
+
userOp.preVerificationGas,
|
|
8011
|
+
(0, import_viem10.concat)([uint128(userOp.maxPriorityFeePerGas), uint128(userOp.maxFeePerGas)]),
|
|
8012
|
+
(0, import_viem10.keccak256)(paymasterAndData)
|
|
8013
|
+
]
|
|
8014
|
+
);
|
|
8015
|
+
return (0, import_viem10.keccak256)(
|
|
8016
|
+
(0, import_viem10.encodeAbiParameters)(
|
|
8017
|
+
[{ type: "bytes32" }, { type: "address" }, { type: "uint256" }],
|
|
8018
|
+
[(0, import_viem10.keccak256)(packed), entryPoint, BigInt(chainId)]
|
|
8019
|
+
)
|
|
8020
|
+
);
|
|
8021
|
+
}
|
|
8022
|
+
function decodeCall(target, value, data) {
|
|
8023
|
+
const call = { target, value, selector: (0, import_viem10.size)(data) >= 4 ? (0, import_viem10.slice)(data, 0, 4) : "0x" };
|
|
8024
|
+
let decoded;
|
|
8025
|
+
try {
|
|
8026
|
+
decoded = (0, import_viem10.decodeFunctionData)({ abi: KNOWN_CALLS_ABI, data });
|
|
8027
|
+
} catch {
|
|
8028
|
+
return call;
|
|
8029
|
+
}
|
|
8030
|
+
call.functionName = decoded.functionName;
|
|
8031
|
+
call.args = decoded.args;
|
|
8032
|
+
if (decoded.functionName === "setupSafe") {
|
|
8033
|
+
const [initData] = decoded.args;
|
|
8034
|
+
call.calls = [decodeCall(target, 0n, initData.callData)];
|
|
8035
|
+
} else if (decoded.functionName === "execute") {
|
|
8036
|
+
const [mode, executionCalldata] = decoded.args;
|
|
8037
|
+
const callType = (0, import_viem10.slice)(mode, 0, 1);
|
|
8038
|
+
if (callType === ERC7579_CALLTYPE_BATCH) {
|
|
8039
|
+
const [executions] = (0, import_viem10.decodeAbiParameters)(
|
|
8040
|
+
[{ type: "tuple[]", components: [{ type: "address", name: "target" }, { type: "uint256", name: "value" }, { type: "bytes", name: "callData" }] }],
|
|
8041
|
+
executionCalldata
|
|
8042
|
+
);
|
|
8043
|
+
call.calls = executions.map((e) => decodeCall(e.target, e.value, e.callData));
|
|
8044
|
+
} else if (callType === ERC7579_CALLTYPE_SINGLE) {
|
|
8045
|
+
call.calls = [decodeCall(
|
|
8046
|
+
(0, import_viem10.slice)(executionCalldata, 0, 20),
|
|
8047
|
+
BigInt((0, import_viem10.slice)(executionCalldata, 20, 52)),
|
|
8048
|
+
(0, import_viem10.size)(executionCalldata) > 52 ? (0, import_viem10.slice)(executionCalldata, 52) : "0x"
|
|
8049
|
+
)];
|
|
8050
|
+
}
|
|
8051
|
+
}
|
|
8052
|
+
return call;
|
|
8053
|
+
}
|
|
8054
|
+
function decodeUserOperationCalls(userOp) {
|
|
8055
|
+
return decodeCall(userOp.sender, 0n, userOp.callData);
|
|
8056
|
+
}
|
|
8057
|
+
|
|
7353
8058
|
// src/providers/bankr.ts
|
|
7354
8059
|
function createBankrProvider(config) {
|
|
7355
8060
|
const {
|
|
@@ -7515,6 +8220,371 @@ function createBankrProvider(config) {
|
|
|
7515
8220
|
};
|
|
7516
8221
|
return provider;
|
|
7517
8222
|
}
|
|
8223
|
+
|
|
8224
|
+
// src/providers/safe-owner.ts
|
|
8225
|
+
var import_viem11 = require("viem");
|
|
8226
|
+
var EIP1271_MAGIC_VALUE = "0x1626ba7e";
|
|
8227
|
+
var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
8228
|
+
var SAFE_ABI2 = (0, import_viem11.parseAbi)([
|
|
8229
|
+
"function getThreshold() view returns (uint256)",
|
|
8230
|
+
"function getOwners() view returns (address[])",
|
|
8231
|
+
"function nonce() view returns (uint256)",
|
|
8232
|
+
"function getMessageHash(bytes message) view returns (bytes32)",
|
|
8233
|
+
"function getTransactionHash(address to, uint256 value, bytes data, uint8 operation, uint256 safeTxGas, uint256 baseGas, uint256 gasPrice, address gasToken, address refundReceiver, uint256 _nonce) view returns (bytes32)",
|
|
8234
|
+
"function execTransaction(address to, uint256 value, bytes data, uint8 operation, uint256 safeTxGas, uint256 baseGas, uint256 gasPrice, address gasToken, address refundReceiver, bytes signatures) payable returns (bool)",
|
|
8235
|
+
"function isValidSignature(bytes32 _dataHash, bytes _signature) view returns (bytes4)"
|
|
8236
|
+
]);
|
|
8237
|
+
async function createSafeOwnerProvider(config) {
|
|
8238
|
+
if (!(0, import_viem11.isAddress)(config.safeAddress)) {
|
|
8239
|
+
throw new Error("safeAddress must be an Ethereum address");
|
|
8240
|
+
}
|
|
8241
|
+
const safeAddress = (0, import_viem11.getAddress)(config.safeAddress);
|
|
8242
|
+
const publicClient = (0, import_viem11.createPublicClient)({
|
|
8243
|
+
chain: config.chain,
|
|
8244
|
+
transport: (0, import_viem11.http)()
|
|
8245
|
+
});
|
|
8246
|
+
const ownerWallet = await resolveOwnerWallet(config.owner, config.chain);
|
|
8247
|
+
const code = await publicClient.getCode({ address: safeAddress });
|
|
8248
|
+
if (!code || code === "0x") {
|
|
8249
|
+
throw new Error(
|
|
8250
|
+
`Safe ${safeAddress} has no code on chain ${config.chain.id}`
|
|
8251
|
+
);
|
|
8252
|
+
}
|
|
8253
|
+
const [threshold, owners] = await Promise.all([
|
|
8254
|
+
publicClient.readContract({
|
|
8255
|
+
address: safeAddress,
|
|
8256
|
+
abi: SAFE_ABI2,
|
|
8257
|
+
functionName: "getThreshold"
|
|
8258
|
+
}),
|
|
8259
|
+
publicClient.readContract({
|
|
8260
|
+
address: safeAddress,
|
|
8261
|
+
abi: SAFE_ABI2,
|
|
8262
|
+
functionName: "getOwners"
|
|
8263
|
+
})
|
|
8264
|
+
]);
|
|
8265
|
+
if (threshold !== 1n) {
|
|
8266
|
+
throw new Error(
|
|
8267
|
+
`Safe ${safeAddress} threshold is ${threshold.toString()}. createSafeOwnerProvider can execute only a threshold-1 Safe. For a multisig such as 2-of-4, connect the Safe with WalletConnect or the Safe App and pass that provider to connectAccount. sendDeposit waits while the other owners confirm.`
|
|
8268
|
+
);
|
|
8269
|
+
}
|
|
8270
|
+
const ownerAddress = ownerWallet.address;
|
|
8271
|
+
if (!owners.some((owner) => (0, import_viem11.getAddress)(owner) === ownerAddress)) {
|
|
8272
|
+
throw new Error(`${ownerAddress} is not an owner of Safe ${safeAddress}`);
|
|
8273
|
+
}
|
|
8274
|
+
const signSafeDigest = async (dataHash) => {
|
|
8275
|
+
const encoded = (0, import_viem11.encodeAbiParameters)([{ type: "bytes32" }], [dataHash]);
|
|
8276
|
+
const messageHash = await publicClient.readContract({
|
|
8277
|
+
address: safeAddress,
|
|
8278
|
+
abi: SAFE_ABI2,
|
|
8279
|
+
functionName: "getMessageHash",
|
|
8280
|
+
args: [encoded]
|
|
8281
|
+
});
|
|
8282
|
+
return ownerWallet.signHash(messageHash);
|
|
8283
|
+
};
|
|
8284
|
+
const probeHash = (0, import_viem11.hashMessage)("zyfai safe owner");
|
|
8285
|
+
const probeSignature = await signSafeDigest(probeHash);
|
|
8286
|
+
const magic = await publicClient.readContract({
|
|
8287
|
+
address: safeAddress,
|
|
8288
|
+
abi: SAFE_ABI2,
|
|
8289
|
+
functionName: "isValidSignature",
|
|
8290
|
+
args: [probeHash, probeSignature]
|
|
8291
|
+
});
|
|
8292
|
+
if (magic.toLowerCase() !== EIP1271_MAGIC_VALUE) {
|
|
8293
|
+
throw new Error(
|
|
8294
|
+
`Safe ${safeAddress} rejected the owner signature (isValidSignature returned ${magic})`
|
|
8295
|
+
);
|
|
8296
|
+
}
|
|
8297
|
+
const executeFromSafe = async (tx) => {
|
|
8298
|
+
const nonce = await publicClient.readContract({
|
|
8299
|
+
address: safeAddress,
|
|
8300
|
+
abi: SAFE_ABI2,
|
|
8301
|
+
functionName: "nonce"
|
|
8302
|
+
});
|
|
8303
|
+
const safeTxHash = await publicClient.readContract({
|
|
8304
|
+
address: safeAddress,
|
|
8305
|
+
abi: SAFE_ABI2,
|
|
8306
|
+
functionName: "getTransactionHash",
|
|
8307
|
+
args: [
|
|
8308
|
+
tx.to,
|
|
8309
|
+
tx.value,
|
|
8310
|
+
tx.data,
|
|
8311
|
+
0,
|
|
8312
|
+
0n,
|
|
8313
|
+
0n,
|
|
8314
|
+
0n,
|
|
8315
|
+
ZERO_ADDRESS,
|
|
8316
|
+
ZERO_ADDRESS,
|
|
8317
|
+
nonce
|
|
8318
|
+
]
|
|
8319
|
+
});
|
|
8320
|
+
const signature = await ownerWallet.signHash(safeTxHash);
|
|
8321
|
+
const data = (0, import_viem11.encodeFunctionData)({
|
|
8322
|
+
abi: SAFE_ABI2,
|
|
8323
|
+
functionName: "execTransaction",
|
|
8324
|
+
args: [
|
|
8325
|
+
tx.to,
|
|
8326
|
+
tx.value,
|
|
8327
|
+
tx.data,
|
|
8328
|
+
0,
|
|
8329
|
+
0n,
|
|
8330
|
+
0n,
|
|
8331
|
+
0n,
|
|
8332
|
+
ZERO_ADDRESS,
|
|
8333
|
+
ZERO_ADDRESS,
|
|
8334
|
+
signature
|
|
8335
|
+
]
|
|
8336
|
+
});
|
|
8337
|
+
const hash = await ownerWallet.sendTransaction({
|
|
8338
|
+
to: safeAddress,
|
|
8339
|
+
data,
|
|
8340
|
+
value: 0n
|
|
8341
|
+
});
|
|
8342
|
+
const receipt = await publicClient.waitForTransactionReceipt({ hash });
|
|
8343
|
+
if (receipt.status !== "success") {
|
|
8344
|
+
throw new Error(`Safe transaction reverted: ${hash}`);
|
|
8345
|
+
}
|
|
8346
|
+
return hash;
|
|
8347
|
+
};
|
|
8348
|
+
return {
|
|
8349
|
+
async request({ method, params }) {
|
|
8350
|
+
if (method === "eth_requestAccounts" || method === "eth_accounts") {
|
|
8351
|
+
return [safeAddress];
|
|
8352
|
+
}
|
|
8353
|
+
if (method === "personal_sign" || method === "eth_sign") {
|
|
8354
|
+
return signSafeDigest(personalSignDigest(params));
|
|
8355
|
+
}
|
|
8356
|
+
if (method === "eth_signTypedData_v4" || method === "eth_signTypedData") {
|
|
8357
|
+
return signSafeDigest(typedDataDigest(params));
|
|
8358
|
+
}
|
|
8359
|
+
if (method === "eth_sendTransaction" || method === "wallet_sendTransaction") {
|
|
8360
|
+
return executeFromSafe(readSafeTransaction(params));
|
|
8361
|
+
}
|
|
8362
|
+
return publicClient.request({
|
|
8363
|
+
method,
|
|
8364
|
+
params: params ?? []
|
|
8365
|
+
});
|
|
8366
|
+
}
|
|
8367
|
+
};
|
|
8368
|
+
}
|
|
8369
|
+
async function resolveOwnerWallet(owner, chain) {
|
|
8370
|
+
if (isHashSigner(owner)) {
|
|
8371
|
+
const address = (0, import_viem11.getAddress)(owner.address);
|
|
8372
|
+
const wallet = (0, import_viem11.createWalletClient)({
|
|
8373
|
+
account: owner,
|
|
8374
|
+
chain,
|
|
8375
|
+
transport: (0, import_viem11.http)()
|
|
8376
|
+
});
|
|
8377
|
+
return {
|
|
8378
|
+
address,
|
|
8379
|
+
signHash: (hash) => owner.sign({ hash }),
|
|
8380
|
+
signTypedData: (params) => signAccountTypedData(owner, params),
|
|
8381
|
+
sendTransaction: (tx) => wallet.sendTransaction({
|
|
8382
|
+
account: owner,
|
|
8383
|
+
chain,
|
|
8384
|
+
to: tx.to,
|
|
8385
|
+
data: tx.data,
|
|
8386
|
+
value: tx.value
|
|
8387
|
+
})
|
|
8388
|
+
};
|
|
8389
|
+
}
|
|
8390
|
+
if (isWalletClient(owner)) {
|
|
8391
|
+
const address = await walletClientAddress(owner);
|
|
8392
|
+
return {
|
|
8393
|
+
address,
|
|
8394
|
+
signHash: (hash) => signOwnerHash(looseRequest(owner.request), owner.account, address, hash),
|
|
8395
|
+
signTypedData: (params) => {
|
|
8396
|
+
const { domain, types, primaryType, message } = parseTypedDataPayload(params);
|
|
8397
|
+
return owner.signTypedData({
|
|
8398
|
+
account: owner.account ?? address,
|
|
8399
|
+
domain,
|
|
8400
|
+
types,
|
|
8401
|
+
primaryType,
|
|
8402
|
+
message
|
|
8403
|
+
});
|
|
8404
|
+
},
|
|
8405
|
+
sendTransaction: (tx) => owner.sendTransaction({
|
|
8406
|
+
account: owner.account ?? address,
|
|
8407
|
+
chain: owner.chain ?? chain,
|
|
8408
|
+
to: tx.to,
|
|
8409
|
+
data: tx.data,
|
|
8410
|
+
value: tx.value
|
|
8411
|
+
})
|
|
8412
|
+
};
|
|
8413
|
+
}
|
|
8414
|
+
if (isEip1193(owner)) {
|
|
8415
|
+
const address = await eip1193Address(owner);
|
|
8416
|
+
return {
|
|
8417
|
+
address,
|
|
8418
|
+
signHash: (hash) => signOwnerHash(looseRequest(owner.request), void 0, address, hash),
|
|
8419
|
+
signTypedData: async (params) => {
|
|
8420
|
+
const { requestPayload } = parseTypedDataPayload(params);
|
|
8421
|
+
const signature = await owner.request({
|
|
8422
|
+
method: "eth_signTypedData_v4",
|
|
8423
|
+
params: [address, JSON.stringify(requestPayload)]
|
|
8424
|
+
});
|
|
8425
|
+
if (typeof signature !== "string" || !signature.startsWith("0x")) {
|
|
8426
|
+
throw new Error("Owner wallet did not return a typed-data signature");
|
|
8427
|
+
}
|
|
8428
|
+
return signature;
|
|
8429
|
+
},
|
|
8430
|
+
sendTransaction: async (tx) => {
|
|
8431
|
+
const hash = await owner.request({
|
|
8432
|
+
method: "eth_sendTransaction",
|
|
8433
|
+
params: [
|
|
8434
|
+
{
|
|
8435
|
+
from: address,
|
|
8436
|
+
to: tx.to,
|
|
8437
|
+
data: tx.data,
|
|
8438
|
+
value: tx.value === 0n ? "0x0" : `0x${tx.value.toString(16)}`
|
|
8439
|
+
}
|
|
8440
|
+
]
|
|
8441
|
+
});
|
|
8442
|
+
if (typeof hash !== "string" || !hash.startsWith("0x")) {
|
|
8443
|
+
throw new Error("Owner wallet did not return a transaction hash");
|
|
8444
|
+
}
|
|
8445
|
+
return hash;
|
|
8446
|
+
}
|
|
8447
|
+
};
|
|
8448
|
+
}
|
|
8449
|
+
throw new Error(
|
|
8450
|
+
"owner must be a viem wallet client, an account that can sign hashes, or an EIP-1193 provider"
|
|
8451
|
+
);
|
|
8452
|
+
}
|
|
8453
|
+
function isWalletClient(owner) {
|
|
8454
|
+
return typeof owner === "object" && owner !== null && "transport" in owner && "sendTransaction" in owner && typeof owner.sendTransaction === "function";
|
|
8455
|
+
}
|
|
8456
|
+
function isHashSigner(owner) {
|
|
8457
|
+
return typeof owner === "object" && owner !== null && "address" in owner && "sign" in owner && typeof owner.sign === "function" && !("transport" in owner);
|
|
8458
|
+
}
|
|
8459
|
+
function isEip1193(owner) {
|
|
8460
|
+
return typeof owner === "object" && owner !== null && "request" in owner && typeof owner.request === "function" && !("transport" in owner) && !isHashSigner(owner);
|
|
8461
|
+
}
|
|
8462
|
+
function looseRequest(request) {
|
|
8463
|
+
return request;
|
|
8464
|
+
}
|
|
8465
|
+
async function walletClientAddress(owner) {
|
|
8466
|
+
if (owner.account?.address && (0, import_viem11.isAddress)(owner.account.address)) {
|
|
8467
|
+
return (0, import_viem11.getAddress)(owner.account.address);
|
|
8468
|
+
}
|
|
8469
|
+
return requestAccount(looseRequest(owner.request));
|
|
8470
|
+
}
|
|
8471
|
+
async function eip1193Address(owner) {
|
|
8472
|
+
return requestAccount(looseRequest(owner.request));
|
|
8473
|
+
}
|
|
8474
|
+
async function requestAccount(request) {
|
|
8475
|
+
const accounts = await request({ method: "eth_requestAccounts" });
|
|
8476
|
+
const first = Array.isArray(accounts) ? accounts[0] : void 0;
|
|
8477
|
+
if (typeof first !== "string" || !(0, import_viem11.isAddress)(first)) {
|
|
8478
|
+
throw new Error("Owner wallet did not return an account");
|
|
8479
|
+
}
|
|
8480
|
+
return (0, import_viem11.getAddress)(first);
|
|
8481
|
+
}
|
|
8482
|
+
async function signOwnerHash(request, account, address, hash) {
|
|
8483
|
+
if (account?.sign) {
|
|
8484
|
+
return account.sign({ hash });
|
|
8485
|
+
}
|
|
8486
|
+
const signature = await request({
|
|
8487
|
+
method: "personal_sign",
|
|
8488
|
+
params: [hash, address]
|
|
8489
|
+
});
|
|
8490
|
+
if (typeof signature !== "string" || !signature.startsWith("0x")) {
|
|
8491
|
+
throw new Error("Owner wallet did not return a signature");
|
|
8492
|
+
}
|
|
8493
|
+
return asSafeEthSign(signature);
|
|
8494
|
+
}
|
|
8495
|
+
function asSafeEthSign(signature) {
|
|
8496
|
+
const sig = (0, import_viem11.hexToSignature)(signature);
|
|
8497
|
+
const current = sig.v === void 0 ? sig.yParity === 1 ? 28 : 27 : Number(sig.v);
|
|
8498
|
+
const v = current >= 27 ? current + 4 : current + 31;
|
|
8499
|
+
return (0, import_viem11.signatureToHex)({ r: sig.r, s: sig.s, v: BigInt(v) });
|
|
8500
|
+
}
|
|
8501
|
+
function personalSignDigest(params) {
|
|
8502
|
+
const [first, second] = params ?? [];
|
|
8503
|
+
const message = typeof first === "string" && (0, import_viem11.isAddress)(first) ? second : first;
|
|
8504
|
+
const hex = typeof message === "string" && message.startsWith("0x") ? message : (0, import_viem11.stringToHex)(String(message ?? ""));
|
|
8505
|
+
return (0, import_viem11.hashMessage)({ raw: hex });
|
|
8506
|
+
}
|
|
8507
|
+
function parseTypedDataPayload(params) {
|
|
8508
|
+
const [first, second] = params ?? [];
|
|
8509
|
+
const payload = typeof first === "string" && (0, import_viem11.isAddress)(first) ? second : first;
|
|
8510
|
+
const parsed = typeof payload === "string" ? JSON.parse(payload) : payload;
|
|
8511
|
+
const types = { ...parsed.types };
|
|
8512
|
+
delete types.EIP712Domain;
|
|
8513
|
+
const domain = { ...parsed.domain ?? {} };
|
|
8514
|
+
if (typeof domain.chainId === "string") {
|
|
8515
|
+
domain.chainId = BigInt(domain.chainId);
|
|
8516
|
+
}
|
|
8517
|
+
const message = coerceEip712Value(
|
|
8518
|
+
parsed.primaryType,
|
|
8519
|
+
parsed.message,
|
|
8520
|
+
types
|
|
8521
|
+
);
|
|
8522
|
+
return {
|
|
8523
|
+
domain,
|
|
8524
|
+
types,
|
|
8525
|
+
primaryType: parsed.primaryType,
|
|
8526
|
+
message,
|
|
8527
|
+
requestPayload: parsed
|
|
8528
|
+
};
|
|
8529
|
+
}
|
|
8530
|
+
function typedDataDigest(params) {
|
|
8531
|
+
const { domain, types, primaryType, message } = parseTypedDataPayload(params);
|
|
8532
|
+
return (0, import_viem11.hashTypedData)({ domain, types, primaryType, message });
|
|
8533
|
+
}
|
|
8534
|
+
async function signAccountTypedData(account, params) {
|
|
8535
|
+
const { domain, types, primaryType, message } = parseTypedDataPayload(params);
|
|
8536
|
+
if (!account.signTypedData) {
|
|
8537
|
+
throw new Error("Owner account cannot sign typed data");
|
|
8538
|
+
}
|
|
8539
|
+
return account.signTypedData({
|
|
8540
|
+
domain,
|
|
8541
|
+
types,
|
|
8542
|
+
primaryType,
|
|
8543
|
+
message
|
|
8544
|
+
});
|
|
8545
|
+
}
|
|
8546
|
+
function coerceEip712Value(type, value, types) {
|
|
8547
|
+
if (value == null) return value;
|
|
8548
|
+
const array = type.match(/^(.*)\[(\d*)\]$/);
|
|
8549
|
+
if (array) {
|
|
8550
|
+
if (!Array.isArray(value)) return value;
|
|
8551
|
+
return value.map((item) => coerceEip712Value(array[1], item, types));
|
|
8552
|
+
}
|
|
8553
|
+
const struct = types[type];
|
|
8554
|
+
if (struct) {
|
|
8555
|
+
if (typeof value !== "object" || Array.isArray(value)) return value;
|
|
8556
|
+
const record = value;
|
|
8557
|
+
const next = {};
|
|
8558
|
+
for (const field of struct) {
|
|
8559
|
+
next[field.name] = coerceEip712Value(
|
|
8560
|
+
field.type,
|
|
8561
|
+
record[field.name],
|
|
8562
|
+
types
|
|
8563
|
+
);
|
|
8564
|
+
}
|
|
8565
|
+
return next;
|
|
8566
|
+
}
|
|
8567
|
+
if (/^u?int\d*$/.test(type)) {
|
|
8568
|
+
if (typeof value === "bigint") return value;
|
|
8569
|
+
if (typeof value === "string" || typeof value === "number") {
|
|
8570
|
+
return BigInt(value);
|
|
8571
|
+
}
|
|
8572
|
+
}
|
|
8573
|
+
return value;
|
|
8574
|
+
}
|
|
8575
|
+
function readSafeTransaction(params) {
|
|
8576
|
+
const tx = Array.isArray(params) ? params[0] : void 0;
|
|
8577
|
+
if (!tx?.to || !(0, import_viem11.isAddress)(tx.to)) {
|
|
8578
|
+
throw new Error("Safe transaction is missing a destination");
|
|
8579
|
+
}
|
|
8580
|
+
const data = typeof tx.data === "string" && tx.data.startsWith("0x") ? tx.data : "0x";
|
|
8581
|
+
let value = 0n;
|
|
8582
|
+
if (typeof tx.value === "bigint") value = tx.value;
|
|
8583
|
+
else if (typeof tx.value === "number" || typeof tx.value === "string") {
|
|
8584
|
+
value = BigInt(tx.value);
|
|
8585
|
+
}
|
|
8586
|
+
return { to: (0, import_viem11.getAddress)(tx.to), data, value };
|
|
8587
|
+
}
|
|
7518
8588
|
// Annotate the CommonJS export names for ESM import in node:
|
|
7519
8589
|
0 && (module.exports = {
|
|
7520
8590
|
ALLOWED_HISTORY_DAYS,
|
|
@@ -7523,6 +8593,7 @@ function createBankrProvider(config) {
|
|
|
7523
8593
|
DATA_API_ENDPOINT,
|
|
7524
8594
|
DEFAULT_RELAY_SLIPPAGE_BPS,
|
|
7525
8595
|
DEFAULT_TOKEN_ADDRESSES,
|
|
8596
|
+
ENTRY_POINT_V07_ADDRESS,
|
|
7526
8597
|
ERC7579_LAUNCHPAD_ADDRESS,
|
|
7527
8598
|
EXECUTION_API_BASE_URLS,
|
|
7528
8599
|
INTENT_EXECUTOR,
|
|
@@ -7545,7 +8616,10 @@ function createBankrProvider(config) {
|
|
|
7545
8616
|
WS_ENDPOINT,
|
|
7546
8617
|
WS_URLS,
|
|
7547
8618
|
ZyfaiSDK,
|
|
8619
|
+
buildV1ChainSessions,
|
|
7548
8620
|
createBankrProvider,
|
|
8621
|
+
createSafeOwnerProvider,
|
|
8622
|
+
decodeUserOperationCalls,
|
|
7549
8623
|
getChainConfig,
|
|
7550
8624
|
getDataApiBaseUrl,
|
|
7551
8625
|
getDefaultTokenAddress,
|
|
@@ -7553,7 +8627,12 @@ function createBankrProvider(config) {
|
|
|
7553
8627
|
getManagedAssets,
|
|
7554
8628
|
getSupportedChainIds,
|
|
7555
8629
|
getWsUrl,
|
|
8630
|
+
hashUserOperationV07,
|
|
8631
|
+
hashV1SessionEnable,
|
|
7556
8632
|
isSupportedChain,
|
|
8633
|
+
parseUserOperationJson,
|
|
8634
|
+
parseV1ChainSessions,
|
|
7557
8635
|
resolveDepositRoute,
|
|
7558
|
-
resolveRelaySlippageBps
|
|
8636
|
+
resolveRelaySlippageBps,
|
|
8637
|
+
serializeV1ChainSessions
|
|
7559
8638
|
});
|