@capxul/mcp 2.1.1 → 2.3.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/dist/main.mjs +756 -732
- package/package.json +5 -5
package/dist/main.mjs
CHANGED
|
@@ -240,7 +240,7 @@ function normalizeEmail(email) {
|
|
|
240
240
|
}
|
|
241
241
|
//#endregion
|
|
242
242
|
//#region package.json
|
|
243
|
-
var version$2 = "2.
|
|
243
|
+
var version$2 = "2.3.0";
|
|
244
244
|
//#endregion
|
|
245
245
|
//#region ../../packages/errors/src/errors.ts
|
|
246
246
|
const CAPXUL_ERROR_CODES = [
|
|
@@ -1726,48 +1726,7 @@ function deriveCapxulOrgAddress(input) {
|
|
|
1726
1726
|
bytecodeHash: keccak256(concat([SAFE_PROXY_CREATION_CODE, encodeAbiParameters([{ type: "uint256" }], [BigInt(SAFE_L2_SINGLETON)])]))
|
|
1727
1727
|
}).toLowerCase();
|
|
1728
1728
|
}
|
|
1729
|
-
|
|
1730
|
-
//#region ../../packages/config/src/role-dsl.ts
|
|
1731
|
-
const USD_DECIMALS = 6;
|
|
1732
|
-
const USD_SCALE = 10n ** BigInt(USD_DECIMALS);
|
|
1733
|
-
const USD_DISPLAY_RE = /^\d+(?:\.\d{1,6})?$/;
|
|
1734
|
-
const USD_BASE_UNIT_RE = /^\d+$/;
|
|
1735
|
-
const EXEC_TRANSACTION_WITH_ROLE = "zodiac.roles.execTransactionWithRole";
|
|
1736
|
-
const ASSIGN_ROLES = "zodiac.roles.assignRoles";
|
|
1737
|
-
const SCOPE_TARGET = "zodiac.roles.scopeTarget";
|
|
1738
|
-
const OWNER_ROLE_LABEL = "Owner";
|
|
1739
|
-
const FOUNDER_BUDGET_ROLE_LABEL = "Founder Budget";
|
|
1740
|
-
const FOUNDER_BUDGET_LIMIT = {
|
|
1741
|
-
currency: "USD",
|
|
1742
|
-
value: "1000000000000",
|
|
1743
|
-
decimals: 6
|
|
1744
|
-
};
|
|
1745
|
-
function usd(value) {
|
|
1746
|
-
return {
|
|
1747
|
-
currency: "USD",
|
|
1748
|
-
value: usdDisplayToBaseUnits(value),
|
|
1749
|
-
decimals: USD_DECIMALS
|
|
1750
|
-
};
|
|
1751
|
-
}
|
|
1752
|
-
function usdDisplayToBaseUnits(value) {
|
|
1753
|
-
if (value.trim() !== value || !USD_DISPLAY_RE.test(value)) throw Errors.invalidInput("role.spend", "USD caps must be unsigned decimal strings with at most 6 fractional digits");
|
|
1754
|
-
const parts = value.split(".");
|
|
1755
|
-
const whole = parts[0] ?? "0";
|
|
1756
|
-
const fraction = parts[1] ?? "";
|
|
1757
|
-
return (BigInt(whole) * USD_SCALE + BigInt(fraction.padEnd(USD_DECIMALS, "0"))).toString();
|
|
1758
|
-
}
|
|
1759
|
-
function normalizeOrgRoleMoney(money, field) {
|
|
1760
|
-
if (money.currency !== "USD" || money.decimals !== USD_DECIMALS || !USD_BASE_UNIT_RE.test(money.value)) throw Errors.invalidInput(field, `must be USD base units with ${USD_DECIMALS} decimals`);
|
|
1761
|
-
return money;
|
|
1762
|
-
}
|
|
1763
|
-
function normalizeOrgRoleSpendCap(spend) {
|
|
1764
|
-
if (spend === void 0) return void 0;
|
|
1765
|
-
return {
|
|
1766
|
-
...spend.perTx === void 0 ? {} : { perTx: normalizeOrgRoleMoney(spend.perTx, "roles.spend.perTx") },
|
|
1767
|
-
...spend.perDay === void 0 ? {} : { perDay: normalizeOrgRoleMoney(spend.perDay, "roles.spend.perDay") },
|
|
1768
|
-
...spend.toRecipients === void 0 ? {} : { toRecipients: spend.toRecipients }
|
|
1769
|
-
};
|
|
1770
|
-
}
|
|
1729
|
+
10n ** BigInt(6);
|
|
1771
1730
|
function normalizeOrgRoleLabel(label) {
|
|
1772
1731
|
const normalized = label.trim().replace(/\s+/g, " ");
|
|
1773
1732
|
if (normalized.length === 0) throw Errors.invalidInput("role.label", "must be a non-empty role label");
|
|
@@ -1776,84 +1735,6 @@ function normalizeOrgRoleLabel(label) {
|
|
|
1776
1735
|
function orgRoleKeyForLabel(label) {
|
|
1777
1736
|
return keccak256(toBytes(normalizeOrgRoleLabel(label).toLowerCase()));
|
|
1778
1737
|
}
|
|
1779
|
-
function soloOrgRoleTemplate() {
|
|
1780
|
-
return [{
|
|
1781
|
-
label: "Owner",
|
|
1782
|
-
canManageMembers: true,
|
|
1783
|
-
canManageRoles: true
|
|
1784
|
-
}, {
|
|
1785
|
-
label: FOUNDER_BUDGET_ROLE_LABEL,
|
|
1786
|
-
spend: {
|
|
1787
|
-
perTx: FOUNDER_BUDGET_LIMIT,
|
|
1788
|
-
perDay: FOUNDER_BUDGET_LIMIT,
|
|
1789
|
-
toRecipients: "anyone"
|
|
1790
|
-
}
|
|
1791
|
-
}];
|
|
1792
|
-
}
|
|
1793
|
-
function startupOrgRoleTemplate() {
|
|
1794
|
-
return [
|
|
1795
|
-
...soloOrgRoleTemplate(),
|
|
1796
|
-
{
|
|
1797
|
-
label: "Finance Manager",
|
|
1798
|
-
spend: {
|
|
1799
|
-
perTx: usd("25000"),
|
|
1800
|
-
perDay: usd("100000"),
|
|
1801
|
-
toRecipients: "anyone"
|
|
1802
|
-
}
|
|
1803
|
-
},
|
|
1804
|
-
{
|
|
1805
|
-
label: "Team Lead",
|
|
1806
|
-
spend: {
|
|
1807
|
-
perTx: usd("5000"),
|
|
1808
|
-
perDay: usd("15000"),
|
|
1809
|
-
toRecipients: "anyone"
|
|
1810
|
-
}
|
|
1811
|
-
}
|
|
1812
|
-
];
|
|
1813
|
-
}
|
|
1814
|
-
function orgRoleTemplateDefinitions(template, customRoles = []) {
|
|
1815
|
-
switch (template) {
|
|
1816
|
-
case "Solo": return soloOrgRoleTemplate();
|
|
1817
|
-
case "Startup": return startupOrgRoleTemplate();
|
|
1818
|
-
case "Custom": return customRoles.length === 0 ? soloOrgRoleTemplate() : customRoles;
|
|
1819
|
-
default: return template;
|
|
1820
|
-
}
|
|
1821
|
-
}
|
|
1822
|
-
function compileOrgRoleDefinitions(definitions) {
|
|
1823
|
-
if (definitions.length === 0) throw Errors.invalidInput("roles", "must include at least one role");
|
|
1824
|
-
const seen = /* @__PURE__ */ new Set();
|
|
1825
|
-
const roles = definitions.map((definition) => {
|
|
1826
|
-
const label = normalizeOrgRoleLabel(definition.label);
|
|
1827
|
-
const roleKey = orgRoleKeyForLabel(label);
|
|
1828
|
-
if (seen.has(roleKey)) throw Errors.invalidInput("roles", `duplicate role label: ${label}`);
|
|
1829
|
-
seen.add(roleKey);
|
|
1830
|
-
const spend = normalizeOrgRoleSpendCap(definition.spend);
|
|
1831
|
-
const permissions = [];
|
|
1832
|
-
if (spend !== void 0 || label === OWNER_ROLE_LABEL) permissions.push(EXEC_TRANSACTION_WITH_ROLE);
|
|
1833
|
-
if (definition.canManageMembers === true) permissions.push(ASSIGN_ROLES);
|
|
1834
|
-
if (definition.canManageRoles === true) permissions.push(SCOPE_TARGET);
|
|
1835
|
-
return {
|
|
1836
|
-
label,
|
|
1837
|
-
roleKey,
|
|
1838
|
-
definition: {
|
|
1839
|
-
...definition,
|
|
1840
|
-
label,
|
|
1841
|
-
...spend === void 0 ? {} : { spend }
|
|
1842
|
-
},
|
|
1843
|
-
permissions,
|
|
1844
|
-
allowance: spend ?? null
|
|
1845
|
-
};
|
|
1846
|
-
});
|
|
1847
|
-
const manager = roles.find((role) => role.definition.canManageMembers === true);
|
|
1848
|
-
if (manager === void 0) throw Errors.invalidInput("roles.canManageMembers", "at least one role must compile to the on-chain member-management permission");
|
|
1849
|
-
return {
|
|
1850
|
-
roles,
|
|
1851
|
-
memberManagementRole: {
|
|
1852
|
-
roleKey: manager.roleKey,
|
|
1853
|
-
permission: ASSIGN_ROLES
|
|
1854
|
-
}
|
|
1855
|
-
};
|
|
1856
|
-
}
|
|
1857
1738
|
padHex(stringToHex("FM_DAILY"), {
|
|
1858
1739
|
size: 32,
|
|
1859
1740
|
dir: "right"
|
|
@@ -2357,6 +2238,7 @@ const ROLE_VIEW = {
|
|
|
2357
2238
|
"restricted",
|
|
2358
2239
|
"unset"
|
|
2359
2240
|
]),
|
|
2241
|
+
canSpend: z.boolean(),
|
|
2360
2242
|
canManageMembers: z.boolean(),
|
|
2361
2243
|
canManageRoles: z.boolean()
|
|
2362
2244
|
};
|
|
@@ -2364,16 +2246,15 @@ function registerOrgTools(server, deps) {
|
|
|
2364
2246
|
if (deps.paymentsEnabled !== true) return;
|
|
2365
2247
|
server.registerTool("org.create", {
|
|
2366
2248
|
title: "Create org",
|
|
2367
|
-
description: "Create an organization and its on-chain Org Safe. name is the display name; handle is a globally-unique handle (^[a-z0-9-]{3,32}$);
|
|
2249
|
+
description: "Create an organization and its on-chain Org Safe. name is the display name; handle is a globally-unique handle (^[a-z0-9-]{3,32}$); country is optional. Returns the org {orgId, name, handle, role} — never a Safe address. Consent scope: org:write (#522).",
|
|
2368
2250
|
inputSchema: {
|
|
2369
2251
|
sessionToken: z.string(),
|
|
2370
2252
|
name: z.string(),
|
|
2371
2253
|
handle: z.string(),
|
|
2372
|
-
template: z.enum(["Solo", "Startup"]).optional(),
|
|
2373
2254
|
country: z.string().optional()
|
|
2374
2255
|
},
|
|
2375
2256
|
outputSchema: ORG_VIEW
|
|
2376
|
-
}, ({ sessionToken, name, handle,
|
|
2257
|
+
}, ({ sessionToken, name, handle, country }) => guarded(async () => {
|
|
2377
2258
|
const entry = requireSession(deps, sessionToken);
|
|
2378
2259
|
if (entry === void 0) return errorResult(unknownSessionError$1());
|
|
2379
2260
|
const createOrg = entry.handle.createOrg;
|
|
@@ -2381,7 +2262,6 @@ function registerOrgTools(server, deps) {
|
|
|
2381
2262
|
const result = await createOrg({
|
|
2382
2263
|
name,
|
|
2383
2264
|
handle,
|
|
2384
|
-
...template === void 0 ? {} : { template },
|
|
2385
2265
|
...country === void 0 ? {} : { country }
|
|
2386
2266
|
});
|
|
2387
2267
|
return result.ok ? okResult({ ...result.value }) : errorResult(result.error);
|
|
@@ -2417,7 +2297,7 @@ function registerOrgTools(server, deps) {
|
|
|
2417
2297
|
}, "org.members", deps.onToolCall));
|
|
2418
2298
|
server.registerTool("org.roles", {
|
|
2419
2299
|
title: "List org roles",
|
|
2420
|
-
description: "List
|
|
2300
|
+
description: "List the roles a member can be invited into, with their spend caps and management permissions. Returns leak-safe roles {orgId, label, roleKey, perTxCap, perDayCap, recipientScope, canSpend, canManageMembers, canManageRoles} — the raw allowed-recipient address list is reduced to a recipientScope label, and canSpend true with null caps means unlimited spend authority. Consent scope: org:read (#522).",
|
|
2421
2301
|
inputSchema: {
|
|
2422
2302
|
sessionToken: z.string(),
|
|
2423
2303
|
orgId: z.string()
|
|
@@ -2492,6 +2372,7 @@ Object.fromEntries(SUPPORTED_CURRENCIES.map((currency) => [currency.code, curren
|
|
|
2492
2372
|
const EMAIL_RE$1 = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
2493
2373
|
const COUNTRY_CODE_RE = /^[A-Z]{2}$/;
|
|
2494
2374
|
const ACCOUNT_ID_RE = /^account_[0-9A-Za-z]+$/;
|
|
2375
|
+
const PARTY_ID_RE$1 = /^party_[0-9A-Za-z]+$/;
|
|
2495
2376
|
const APP_ID_RE = /^app_[0-7][0-9A-HJKMNP-TV-Z]{25}$/;
|
|
2496
2377
|
const WEI_RE = /^[0-9]+$/;
|
|
2497
2378
|
Math.floor(Number.MAX_SAFE_INTEGER / 1e3);
|
|
@@ -2510,6 +2391,13 @@ function toAccountId(raw) {
|
|
|
2510
2391
|
if (typeof raw !== "string" || !ACCOUNT_ID_RE.test(raw)) throw Errors.invalidInput("accountId", invalidValueReason("must be account_ plus an alphanumeric id", raw));
|
|
2511
2392
|
return raw;
|
|
2512
2393
|
}
|
|
2394
|
+
function toPartyId(raw) {
|
|
2395
|
+
if (typeof raw !== "string" || !PARTY_ID_RE$1.test(raw)) throw Errors.invalidInput("partyId", invalidValueReason("must be party_ plus an alphanumeric id", raw));
|
|
2396
|
+
return raw;
|
|
2397
|
+
}
|
|
2398
|
+
function toBudgetId(raw) {
|
|
2399
|
+
return toNonEmptyStringBrand(raw, "budgetId");
|
|
2400
|
+
}
|
|
2513
2401
|
function toOrgId(raw) {
|
|
2514
2402
|
return toNonEmptyStringBrand(raw, "orgId");
|
|
2515
2403
|
}
|
|
@@ -2807,7 +2695,8 @@ const CAPXUL_FUNCTIONS = {
|
|
|
2807
2695
|
listMembersByOrgId: "org/queries:listMembersByOrgId",
|
|
2808
2696
|
listMine: "org/queries:listMine",
|
|
2809
2697
|
listRolesByOrgId: "org/queries:listRolesByOrgId",
|
|
2810
|
-
loadByOrgId: "org/queries:loadByOrgId"
|
|
2698
|
+
loadByOrgId: "org/queries:loadByOrgId",
|
|
2699
|
+
me: "org/queries:me"
|
|
2811
2700
|
},
|
|
2812
2701
|
"smartAccount/actions": {
|
|
2813
2702
|
claim: "smartAccount/actions:claim",
|
|
@@ -2871,6 +2760,7 @@ const PAYMENT_ID_RE = /^payment_[0-9A-Za-z]+$/;
|
|
|
2871
2760
|
const PAYEE_ID_RE = /^payee_[0-9A-Za-z]+$/;
|
|
2872
2761
|
const ORG_ID_RE = /^org_[0-9A-Za-z]+$/;
|
|
2873
2762
|
const USER_ID_RE = /^user_[0-9A-Za-z]+$/;
|
|
2763
|
+
const PARTY_ID_RE = /^party_[0-9A-Za-z]+$/;
|
|
2874
2764
|
const HANDLE_RE = /^@?[a-z0-9][a-z0-9-]{2,31}$/;
|
|
2875
2765
|
const ORG_HANDLE_RE = /^[a-z0-9][a-z0-9-]{2,31}$/;
|
|
2876
2766
|
const EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
@@ -2879,6 +2769,7 @@ const PaymentIdSchema$1 = Schema.String.pipe(Schema.check(Schema.makeFilter((val
|
|
|
2879
2769
|
const PayeeIdSchema = Schema.String.pipe(Schema.check(Schema.makeFilter((value) => PAYEE_ID_RE.test(value), { message: "must be payee_ plus an alphanumeric id" })));
|
|
2880
2770
|
const OrgIdSchema = Schema.String.pipe(Schema.check(Schema.makeFilter((value) => ORG_ID_RE.test(value), { message: "must be org_ plus an alphanumeric id" })));
|
|
2881
2771
|
const UserIdSchema = Schema.String.pipe(Schema.check(Schema.makeFilter((value) => USER_ID_RE.test(value), { message: "must be user_ plus an alphanumeric id" })));
|
|
2772
|
+
const PartyIdSchema = Schema.String.pipe(Schema.check(Schema.makeFilter((value) => PARTY_ID_RE.test(value), { message: "must be party_ plus an alphanumeric id" })));
|
|
2882
2773
|
const DecimalStringSchema = Schema.String.pipe(Schema.check(Schema.makeFilter((value) => DECIMAL_STRING_RE.test(value), { message: "must be a non-negative decimal string" })));
|
|
2883
2774
|
const HandleValueSchema = Schema.String.pipe(Schema.check(Schema.makeFilter((value) => !EVM_ADDRESS_RE.test(value) && HANDLE_RE.test(value), { message: "must be a handle; raw addresses are not accepted" })));
|
|
2884
2775
|
const OrgHandleValueSchema = Schema.String.pipe(Schema.check(Schema.makeFilter((value) => !EVM_ADDRESS_RE.test(value) && ORG_HANDLE_RE.test(value), { message: "must be an org handle; raw addresses are not accepted" })));
|
|
@@ -3025,6 +2916,7 @@ const PaymentRecipient = Schema.Struct({
|
|
|
3025
2916
|
"capxulUserId",
|
|
3026
2917
|
"me",
|
|
3027
2918
|
"org",
|
|
2919
|
+
"party",
|
|
3028
2920
|
"external_address"
|
|
3029
2921
|
]),
|
|
3030
2922
|
label: Schema.String,
|
|
@@ -3071,6 +2963,10 @@ const PaymentRef = Schema.Union([
|
|
|
3071
2963
|
Schema.Struct({
|
|
3072
2964
|
kind: Schema.Literal("payeeId"),
|
|
3073
2965
|
payeeId: PayeeIdSchema
|
|
2966
|
+
}),
|
|
2967
|
+
Schema.Struct({
|
|
2968
|
+
kind: Schema.Literal("party"),
|
|
2969
|
+
partyId: PartyIdSchema
|
|
3074
2970
|
})
|
|
3075
2971
|
]);
|
|
3076
2972
|
const Payment = Schema.Struct({
|
|
@@ -4501,6 +4397,7 @@ const PAYMENT_OUTPUT = {
|
|
|
4501
4397
|
"capxulUserId",
|
|
4502
4398
|
"me",
|
|
4503
4399
|
"org",
|
|
4400
|
+
"party",
|
|
4504
4401
|
"external_address"
|
|
4505
4402
|
]),
|
|
4506
4403
|
label: z.string(),
|
|
@@ -4594,6 +4491,10 @@ const REF = z.union([
|
|
|
4594
4491
|
z.object({
|
|
4595
4492
|
kind: z.literal("payeeId"),
|
|
4596
4493
|
payeeId: z.string()
|
|
4494
|
+
}),
|
|
4495
|
+
z.object({
|
|
4496
|
+
kind: z.literal("party"),
|
|
4497
|
+
partyId: z.string()
|
|
4597
4498
|
})
|
|
4598
4499
|
]);
|
|
4599
4500
|
const TIMING = z.union([
|
|
@@ -4616,11 +4517,14 @@ const ADDRESS_BOOK_ENTRY = z.object({
|
|
|
4616
4517
|
relationship: z.array(z.enum([
|
|
4617
4518
|
"paid",
|
|
4618
4519
|
"paidBy",
|
|
4619
|
-
"
|
|
4520
|
+
"invoiced",
|
|
4521
|
+
"invoicedBy",
|
|
4620
4522
|
"member",
|
|
4621
|
-
"
|
|
4523
|
+
"manual",
|
|
4524
|
+
"employed"
|
|
4622
4525
|
])),
|
|
4623
|
-
hidden: z.boolean()
|
|
4526
|
+
hidden: z.boolean(),
|
|
4527
|
+
lastActivityAt: z.number()
|
|
4624
4528
|
});
|
|
4625
4529
|
const ACTOR_REQUEST = z.object({
|
|
4626
4530
|
id: z.string(),
|
|
@@ -4698,6 +4602,9 @@ function actor(kind, orgId) {
|
|
|
4698
4602
|
function orgIdArg(args) {
|
|
4699
4603
|
return typeof args === "object" && args !== null && "orgId" in args && typeof args.orgId === "string" ? args.orgId : void 0;
|
|
4700
4604
|
}
|
|
4605
|
+
function permissionIdArg(args) {
|
|
4606
|
+
return typeof args === "object" && args !== null && "permissionId" in args && typeof args.permissionId === "string" ? args.permissionId : void 0;
|
|
4607
|
+
}
|
|
4701
4608
|
function requireMethod(handle, method, domain) {
|
|
4702
4609
|
const value = handle[method];
|
|
4703
4610
|
if (value === void 0) return {
|
|
@@ -4769,7 +4676,7 @@ function registerAddressBookTools(server, deps, scope) {
|
|
|
4769
4676
|
}, (args) => withSession(deps, args.sessionToken, `${prefix}.get`, async (handle) => {
|
|
4770
4677
|
const method = requireMethod(handle, "addressBookGet", prefix);
|
|
4771
4678
|
if (!method.ok) return methodNotImplemented(prefix, "get");
|
|
4772
|
-
const res = await method.value(actor(scope, orgIdArg(args)), args.entryId);
|
|
4679
|
+
const res = await method.value(actor(scope, orgIdArg(args)), toPartyId(args.entryId));
|
|
4773
4680
|
return res.ok ? okResult({ entry: res.value }) : errorResult(res.error);
|
|
4774
4681
|
}));
|
|
4775
4682
|
server.registerTool(`${prefix}.add`, {
|
|
@@ -4803,7 +4710,7 @@ function registerAddressBookTools(server, deps, scope) {
|
|
|
4803
4710
|
}, (args) => withSession(deps, args.sessionToken, `${prefix}.${action}`, async (handle) => {
|
|
4804
4711
|
const method = requireMethod(handle, action === "hide" ? "addressBookHide" : "addressBookUnhide", prefix);
|
|
4805
4712
|
if (!method.ok) return methodNotImplemented(prefix, action);
|
|
4806
|
-
return result(await method.value(actor(scope, orgIdArg(args)), args.entryId));
|
|
4713
|
+
return result(await method.value(actor(scope, orgIdArg(args)), toPartyId(args.entryId)));
|
|
4807
4714
|
}));
|
|
4808
4715
|
server.registerTool(`${prefix}.label`, {
|
|
4809
4716
|
title: `${scope} address book label`,
|
|
@@ -4820,7 +4727,7 @@ function registerAddressBookTools(server, deps, scope) {
|
|
|
4820
4727
|
if (!method.ok) return methodNotImplemented(prefix, "label");
|
|
4821
4728
|
return result(await method.value({
|
|
4822
4729
|
actor: actor(scope, orgIdArg(args)),
|
|
4823
|
-
entryId: args.entryId,
|
|
4730
|
+
entryId: toPartyId(args.entryId),
|
|
4824
4731
|
label: args.label
|
|
4825
4732
|
}));
|
|
4826
4733
|
}));
|
|
@@ -4909,13 +4816,14 @@ function registerInboxTools(server, deps, scope) {
|
|
|
4909
4816
|
sessionToken: z.string(),
|
|
4910
4817
|
...scopeInput,
|
|
4911
4818
|
requestId: z.string(),
|
|
4912
|
-
timing: TIMING.optional()
|
|
4819
|
+
timing: TIMING.optional(),
|
|
4820
|
+
...scope === "org" ? { permissionId: z.string() } : {}
|
|
4913
4821
|
},
|
|
4914
4822
|
outputSchema: PAYMENT_OUTPUT
|
|
4915
4823
|
}, (args) => withSession(deps, args.sessionToken, `${prefix}.approve`, async (handle) => {
|
|
4916
4824
|
const method = requireMethod(handle, "inboxApprove", prefix);
|
|
4917
4825
|
if (!method.ok) return methodNotImplemented(prefix, "approve");
|
|
4918
|
-
return paymentResult(await method.value(actor(scope, orgIdArg(args)), args.requestId, args.timing));
|
|
4826
|
+
return paymentResult(await method.value(actor(scope, orgIdArg(args)), args.requestId, args.timing, permissionIdArg(args)));
|
|
4919
4827
|
}));
|
|
4920
4828
|
server.registerTool(`${prefix}.decline`, {
|
|
4921
4829
|
title: `${scope} inbox decline`,
|
|
@@ -5700,6 +5608,8 @@ const isRetryable = (failure) => {
|
|
|
5700
5608
|
return failure.code === "NETWORK_ERROR" || failure.code === "UNKNOWN";
|
|
5701
5609
|
};
|
|
5702
5610
|
const SIGNED_OUT = { phase: "signed_out" };
|
|
5611
|
+
/** Where every client starts. `SessionRestored` / `SessionAbsent` settle it. */
|
|
5612
|
+
const RESTORING = { phase: "restoring" };
|
|
5703
5613
|
const label = (state) => {
|
|
5704
5614
|
if (state.phase !== "authenticated") return state.phase;
|
|
5705
5615
|
if (state.account.at !== "claimed") return `authenticated:${state.account.at}`;
|
|
@@ -5714,6 +5624,8 @@ const EVENT_TAGS = [
|
|
|
5714
5624
|
"RestoreSession",
|
|
5715
5625
|
"ResumeOtpEntry",
|
|
5716
5626
|
"Reset",
|
|
5627
|
+
"SessionRestored",
|
|
5628
|
+
"SessionAbsent",
|
|
5717
5629
|
"EnsureAccount",
|
|
5718
5630
|
"ClaimAccount",
|
|
5719
5631
|
"RetryAccount",
|
|
@@ -5748,6 +5660,13 @@ const SESSION_EVENTS = [
|
|
|
5748
5660
|
"Reset"
|
|
5749
5661
|
];
|
|
5750
5662
|
const TRANSITION_TABLE = {
|
|
5663
|
+
restoring: [
|
|
5664
|
+
"SessionRestored",
|
|
5665
|
+
"SessionAbsent",
|
|
5666
|
+
"ReadSession",
|
|
5667
|
+
"RequestOtp",
|
|
5668
|
+
"Reset"
|
|
5669
|
+
],
|
|
5751
5670
|
signed_out: [
|
|
5752
5671
|
"RequestOtp",
|
|
5753
5672
|
"ReadSession",
|
|
@@ -5939,6 +5858,8 @@ const transition = (state, event, config = DEFAULT_CONFIG) => {
|
|
|
5939
5858
|
requestedAt: state.resume.requestedAt
|
|
5940
5859
|
} };
|
|
5941
5860
|
case "Reset": return { next: SIGNED_OUT };
|
|
5861
|
+
case "SessionRestored": return { next: authenticated(event.session, event.profileComplete, { at: "unknown" }) };
|
|
5862
|
+
case "SessionAbsent": return { next: SIGNED_OUT };
|
|
5942
5863
|
case "EnsureAccount":
|
|
5943
5864
|
if (config.requirement === "none") return WRONG;
|
|
5944
5865
|
return state.phase === "authenticated" ? { next: withAccount(state, {
|
|
@@ -6000,86 +5921,24 @@ const transition = (state, event, config = DEFAULT_CONFIG) => {
|
|
|
6000
5921
|
const PRIVATE_TAGS = new Set(PRIVATE_EVENT_TAGS);
|
|
6001
5922
|
const isPrivate = (event) => PRIVATE_TAGS.has(event._tag);
|
|
6002
5923
|
//#endregion
|
|
6003
|
-
//#region ../../packages/sdk/src/
|
|
6004
|
-
|
|
6005
|
-
|
|
6006
|
-
|
|
6007
|
-
|
|
6008
|
-
|
|
6009
|
-
|
|
6010
|
-
* `at new ClassName (url:line:col)`
|
|
6011
|
-
*/
|
|
6012
|
-
const V8_FRAME_RE = /^\s*at\s+(?:(.+?)\s+\()?(?:(.+?)(?::(\d+):(\d+))?|(.+?))\)?\s*$/;
|
|
6013
|
-
function isNonUrlName(name) {
|
|
6014
|
-
return name === "<anonymous>" || name.startsWith("eval") || name.startsWith("new ") || name.startsWith("async ");
|
|
5924
|
+
//#region ../../packages/sdk/src/surface/_shared/provisioning-telemetry.ts
|
|
5925
|
+
async function emitProvisioningTelemetry(telemetry, smartAccount) {
|
|
5926
|
+
if (telemetry === void 0) return;
|
|
5927
|
+
await Effect.runPromise(telemetry.emit({
|
|
5928
|
+
name: "provisioning_safe_created",
|
|
5929
|
+
props: { safe_address: smartAccount.smartAccountAddress }
|
|
5930
|
+
}).pipe(Effect.catch((cause) => Effect.sync(() => reportProvisioningTelemetryFailure("error", smartAccount, cause))), Effect.catchDefect((cause) => Effect.sync(() => reportProvisioningTelemetryFailure("defect", smartAccount, cause)))));
|
|
6015
5931
|
}
|
|
6016
|
-
|
|
6017
|
-
|
|
6018
|
-
|
|
6019
|
-
|
|
6020
|
-
|
|
6021
|
-
|
|
6022
|
-
|
|
6023
|
-
* - `at async functionName (url:line:col)`
|
|
6024
|
-
* - `at new ClassName (url:line:col)`
|
|
6025
|
-
* - Native frames: `at Array.forEach (<anonymous>)`
|
|
6026
|
-
*/
|
|
6027
|
-
function parseV8StackFrames(error) {
|
|
6028
|
-
const stack = error.stack;
|
|
6029
|
-
if (stack === void 0 || stack === null || stack === "") return [];
|
|
6030
|
-
const lines = stack.split("\n");
|
|
6031
|
-
const frames = [];
|
|
6032
|
-
for (const line of lines) {
|
|
6033
|
-
const trimmed = line.trim();
|
|
6034
|
-
if (!trimmed.startsWith("at ")) continue;
|
|
6035
|
-
const match = V8_FRAME_RE.exec(trimmed);
|
|
6036
|
-
if (match === null) continue;
|
|
6037
|
-
if (match[1] !== void 0) frames.push({
|
|
6038
|
-
function: match[1],
|
|
6039
|
-
filename: match[2],
|
|
6040
|
-
lineno: match[3] !== void 0 ? Number(match[3]) : null,
|
|
6041
|
-
colno: match[4] !== void 0 ? Number(match[4]) : null
|
|
6042
|
-
});
|
|
6043
|
-
else if (match[2] !== void 0 && !isNonUrlName(match[2])) frames.push({
|
|
6044
|
-
function: "<anonymous>",
|
|
6045
|
-
filename: match[2],
|
|
6046
|
-
lineno: match[3] !== void 0 ? Number(match[3]) : null,
|
|
6047
|
-
colno: match[4] !== void 0 ? Number(match[4]) : null
|
|
6048
|
-
});
|
|
6049
|
-
else frames.push({
|
|
6050
|
-
function: match[1] ?? match[2] ?? match[5] ?? "<anonymous>",
|
|
6051
|
-
filename: match[2] ?? match[5] ?? "<anonymous>",
|
|
6052
|
-
lineno: match[3] !== void 0 ? Number(match[3]) : null,
|
|
6053
|
-
colno: match[4] !== void 0 ? Number(match[4]) : null
|
|
6054
|
-
});
|
|
6055
|
-
}
|
|
6056
|
-
return frames;
|
|
5932
|
+
function reportProvisioningTelemetryFailure(kind, smartAccount, cause) {
|
|
5933
|
+
if (!isProvisioningTelemetryDebugEnabled()) return;
|
|
5934
|
+
globalThis.console?.warn?.("[capxul] provisioning telemetry dropped", {
|
|
5935
|
+
kind,
|
|
5936
|
+
safeAddress: smartAccount.smartAccountAddress,
|
|
5937
|
+
cause
|
|
5938
|
+
});
|
|
6057
5939
|
}
|
|
6058
|
-
|
|
6059
|
-
|
|
6060
|
-
/**
|
|
6061
|
-
* Build PostHog's `$exception_list` (always a single entry). Error Tracking
|
|
6062
|
-
* groups on `type`, so it is ALWAYS present (the CapxulError code) — the
|
|
6063
|
-
* previous `[{ frames }]` shape omitted it and PostHog dropped the event as
|
|
6064
|
-
* "missing field `type`". When the error has no parseable stack, a synthetic
|
|
6065
|
-
* boundary frame stands in so the event still ingests as a real Issue (#1031).
|
|
6066
|
-
*/
|
|
6067
|
-
function buildExceptionList(input) {
|
|
6068
|
-
const frames = input.frames.length > 0 ? input.frames : [{
|
|
6069
|
-
filename: SDK_BOUNDARY_FILENAME,
|
|
6070
|
-
function: input.operation ?? "unknown",
|
|
6071
|
-
lineno: 1,
|
|
6072
|
-
colno: 1
|
|
6073
|
-
}];
|
|
6074
|
-
return [{
|
|
6075
|
-
type: input.type,
|
|
6076
|
-
value: input.value,
|
|
6077
|
-
mechanism: {
|
|
6078
|
-
handled: true,
|
|
6079
|
-
type: "capxul_sdk_boundary"
|
|
6080
|
-
},
|
|
6081
|
-
stacktrace: { frames }
|
|
6082
|
-
}];
|
|
5940
|
+
function isProvisioningTelemetryDebugEnabled() {
|
|
5941
|
+
return globalThis.process?.env?.CAPXUL_DEBUG_TELEMETRY === "1";
|
|
6083
5942
|
}
|
|
6084
5943
|
//#endregion
|
|
6085
5944
|
//#region ../../packages/sdk/src/telemetry/get-failure-mode.ts
|
|
@@ -6112,94 +5971,43 @@ function getFailureMode(error) {
|
|
|
6112
5971
|
if (details === void 0) return void 0;
|
|
6113
5972
|
return isFailureMode(details.failure_mode) ? details.failure_mode : void 0;
|
|
6114
5973
|
}
|
|
6115
|
-
/**
|
|
6116
|
-
* Resolve the canonical {@link FailureMode} for a `$exception`, guaranteeing a
|
|
6117
|
-
* taxonomy member is always returned — never `undefined`, never a free string.
|
|
6118
|
-
*
|
|
6119
|
-
* Resolution order:
|
|
6120
|
-
* 1. the structured mode on the error's `details.failure_mode` (already guarded);
|
|
6121
|
-
* 2. a caller-supplied `contextFailureMode`, but ONLY when it passes the same
|
|
6122
|
-
* runtime membership check — the static `FailureMode` type is erased at
|
|
6123
|
-
* runtime, so an operation string (e.g. `"signer-get-address"`) injected via
|
|
6124
|
-
* a JS caller or `as` cast is rejected here rather than leaking to telemetry;
|
|
6125
|
-
* 3. `"unknown"` otherwise, so an unclassifiable error is still tagged with a
|
|
6126
|
-
* canonical value instead of being emitted with no `failure_mode` at all.
|
|
6127
|
-
*/
|
|
6128
|
-
function resolveFailureMode(error, contextFailureMode) {
|
|
6129
|
-
return getFailureMode(error) ?? (isFailureMode(contextFailureMode) ? contextFailureMode : "unknown");
|
|
6130
|
-
}
|
|
6131
5974
|
//#endregion
|
|
6132
|
-
//#region ../../packages/sdk/src/
|
|
6133
|
-
/** Fixed, leak-safe message — the raw error message may carry PII and never ships. */
|
|
6134
|
-
const EXCEPTION_MESSAGE = "Capxul SDK operation failed";
|
|
5975
|
+
//#region ../../packages/sdk/src/signer.ts
|
|
6135
5976
|
/**
|
|
6136
|
-
*
|
|
6137
|
-
*
|
|
6138
|
-
*
|
|
6139
|
-
* Parses stack traces into `$exception_list` format, extracts structured
|
|
6140
|
-
* metadata from CapxulError objects, and supplements with context props.
|
|
6141
|
-
* Fire-and-forget: telemetry defects are silently swallowed.
|
|
6142
|
-
* Returns `Effect<void, never>` for use in Effect pipelines; the underlying
|
|
6143
|
-
* adapter work is synchronous, so callers outside Effect contexts can
|
|
6144
|
-
* use `Effect.runSync`.
|
|
5977
|
+
* The readiness store a signer reports when it runs no readiness cycle. It
|
|
5978
|
+
* fails CLOSED: a node key signer or an injected wallet never claims `ready`,
|
|
5979
|
+
* so a gate that reads this never opens on a guess.
|
|
6145
5980
|
*/
|
|
6146
|
-
|
|
6147
|
-
|
|
6148
|
-
|
|
6149
|
-
|
|
6150
|
-
const errorCode = capxulError?.code ?? context?.capxul_error_code ?? "UNKNOWN";
|
|
6151
|
-
const props = {
|
|
6152
|
-
capxul_error_code: errorCode,
|
|
6153
|
-
$exception_type: errorCode,
|
|
6154
|
-
$exception_message: EXCEPTION_MESSAGE,
|
|
6155
|
-
$exception_list: buildExceptionList({
|
|
6156
|
-
type: errorCode,
|
|
6157
|
-
value: EXCEPTION_MESSAGE,
|
|
6158
|
-
...context?.operation === void 0 ? {} : { operation: context.operation },
|
|
6159
|
-
frames
|
|
6160
|
-
}),
|
|
6161
|
-
layer: capxulError?.layer ?? context?.layer,
|
|
6162
|
-
operation: context?.operation,
|
|
6163
|
-
provider: context?.provider,
|
|
6164
|
-
failure_mode: resolveFailureMode(error, context?.failure_mode)
|
|
6165
|
-
};
|
|
6166
|
-
if (capxulError?.details !== void 0) props.details = JSON.stringify(capxulError.details);
|
|
6167
|
-
for (const key of Object.keys(props)) if (props[key] === void 0) delete props[key];
|
|
6168
|
-
return telemetry.emit({
|
|
6169
|
-
name: "$exception",
|
|
6170
|
-
props
|
|
6171
|
-
});
|
|
6172
|
-
}).pipe(Effect.flatten), () => Effect.void);
|
|
6173
|
-
}
|
|
5981
|
+
const UNOBSERVABLE_SIGNER_STATUS = {
|
|
5982
|
+
status: () => "unknown",
|
|
5983
|
+
subscribe: () => () => void 0
|
|
5984
|
+
};
|
|
6174
5985
|
/**
|
|
6175
|
-
*
|
|
6176
|
-
*
|
|
6177
|
-
* hooks before throwing) can report errors without awaiting.
|
|
5986
|
+
* Walk an error and its `cause` links once each. A self-referential chain
|
|
5987
|
+
* terminates. Both signer predicates read the chain, so they read it here.
|
|
6178
5988
|
*/
|
|
6179
|
-
function
|
|
6180
|
-
|
|
6181
|
-
|
|
6182
|
-
|
|
6183
|
-
|
|
6184
|
-
|
|
6185
|
-
|
|
6186
|
-
|
|
6187
|
-
|
|
6188
|
-
|
|
6189
|
-
|
|
6190
|
-
|
|
6191
|
-
|
|
6192
|
-
|
|
6193
|
-
|
|
6194
|
-
|
|
6195
|
-
|
|
6196
|
-
|
|
6197
|
-
|
|
6198
|
-
|
|
6199
|
-
}
|
|
6200
|
-
}
|
|
6201
|
-
function isProvisioningTelemetryDebugEnabled() {
|
|
6202
|
-
return globalThis.process?.env?.CAPXUL_DEBUG_TELEMETRY === "1";
|
|
5989
|
+
function* causeChain(cause) {
|
|
5990
|
+
const seen = /* @__PURE__ */ new Set();
|
|
5991
|
+
let current = cause;
|
|
5992
|
+
while (typeof current === "object" && current !== null && !seen.has(current)) {
|
|
5993
|
+
seen.add(current);
|
|
5994
|
+
yield current;
|
|
5995
|
+
current = current.cause;
|
|
5996
|
+
}
|
|
5997
|
+
}
|
|
5998
|
+
/** Fold a signer throw into the public error contract. */
|
|
5999
|
+
function signerFailure(source, operation, cause) {
|
|
6000
|
+
let failureMode;
|
|
6001
|
+
for (const link of causeChain(cause)) {
|
|
6002
|
+
if (link instanceof CapxulError && link.code === "SIGNER_REJECTED") return link;
|
|
6003
|
+
failureMode = getFailureMode(link) ?? failureMode;
|
|
6004
|
+
const error = link;
|
|
6005
|
+
if (error.code === 4001 || error.error === "passkey_user_cancelled") return Errors.signerRejected({
|
|
6006
|
+
source,
|
|
6007
|
+
cause
|
|
6008
|
+
});
|
|
6009
|
+
}
|
|
6010
|
+
return Errors.providerError("signer", operation, cause, failureMode === void 0 ? void 0 : { failure_mode: failureMode });
|
|
6203
6011
|
}
|
|
6204
6012
|
//#endregion
|
|
6205
6013
|
//#region ../../packages/sdk/src/internal/invocation-observation.ts
|
|
@@ -6762,7 +6570,7 @@ const accountStatusProgram = Effect.gen(function* () {
|
|
|
6762
6570
|
};
|
|
6763
6571
|
const signerAddress = yield* Effect.tryPromise({
|
|
6764
6572
|
try: () => signer.getAddress(),
|
|
6765
|
-
catch: (cause) =>
|
|
6573
|
+
catch: (cause) => signerFailure(signer.source, "getAddress", cause)
|
|
6766
6574
|
});
|
|
6767
6575
|
return {
|
|
6768
6576
|
status: "accountProviderReady",
|
|
@@ -7265,55 +7073,42 @@ function makeActorRelationshipMethods(deps) {
|
|
|
7265
7073
|
const fns = actorScopeContract;
|
|
7266
7074
|
return {
|
|
7267
7075
|
addressBook: {
|
|
7268
|
-
list: (options) => mapOk$1(awaitableConvex(options?.signal, "addressBook.list", () => convexCall.query(fns.addressBookList, {
|
|
7269
|
-
|
|
7270
|
-
|
|
7271
|
-
|
|
7272
|
-
|
|
7273
|
-
|
|
7274
|
-
|
|
7275
|
-
|
|
7276
|
-
},
|
|
7076
|
+
list: (input, options) => mapOk$1("addressBook.list", awaitableConvex(options?.signal, "addressBook.list", () => convexCall.query(fns.addressBookList, {
|
|
7077
|
+
actor,
|
|
7078
|
+
...input?.includeHidden === void 0 ? {} : { includeHidden: input.includeHidden }
|
|
7079
|
+
})), (entries) => entries.map(mapAddressBookEntry)),
|
|
7080
|
+
get: (entryId, options) => mapOk$1("addressBook.get", awaitableConvex(options?.signal, "addressBook.get", () => convexCall.query(fns.addressBookGet, {
|
|
7081
|
+
actor,
|
|
7082
|
+
partyId: entryId
|
|
7083
|
+
})), (entry) => entry === null ? null : mapAddressBookEntry(entry)),
|
|
7277
7084
|
add: async (input, options) => {
|
|
7278
7085
|
const ref = normalizeRefForBackend$1(input.ref, "ref");
|
|
7279
7086
|
if (!ref.ok) return ref;
|
|
7280
|
-
return mapOk$1(await awaitableConvex(options?.signal, "addressBook.add", () => convexCall.mutation(fns.addressBookAdd, {
|
|
7087
|
+
return mapOk$1("addressBook.add", await awaitableConvex(options?.signal, "addressBook.add", () => convexCall.mutation(fns.addressBookAdd, {
|
|
7281
7088
|
actor,
|
|
7282
7089
|
ref: ref.value,
|
|
7283
7090
|
...input.label === void 0 ? {} : { label: input.label }
|
|
7284
7091
|
})), mapAddressBookEntry);
|
|
7285
7092
|
},
|
|
7286
|
-
hide:
|
|
7287
|
-
|
|
7288
|
-
|
|
7289
|
-
|
|
7290
|
-
|
|
7291
|
-
|
|
7292
|
-
|
|
7293
|
-
},
|
|
7294
|
-
|
|
7295
|
-
|
|
7296
|
-
|
|
7297
|
-
|
|
7298
|
-
|
|
7299
|
-
ref: ref.value
|
|
7300
|
-
})), mapAddressBookEntry);
|
|
7301
|
-
},
|
|
7302
|
-
label: async (input, options) => {
|
|
7303
|
-
const ref = refFromEntryId(input.entryId);
|
|
7304
|
-
if (!ref.ok) return ref;
|
|
7305
|
-
return mapOk$1(await awaitableConvex(options?.signal, "addressBook.label", () => convexCall.mutation(fns.addressBookLabel, {
|
|
7306
|
-
actor,
|
|
7307
|
-
ref: ref.value,
|
|
7308
|
-
label: input.label
|
|
7309
|
-
})), mapAddressBookEntry);
|
|
7310
|
-
}
|
|
7093
|
+
hide: (entryId, options) => mapOk$1("addressBook.hide", awaitableConvex(options?.signal, "addressBook.hide", () => convexCall.mutation(fns.addressBookHide, {
|
|
7094
|
+
actor,
|
|
7095
|
+
partyId: entryId
|
|
7096
|
+
})), mapAddressBookEntry),
|
|
7097
|
+
unhide: (entryId, options) => mapOk$1("addressBook.unhide", awaitableConvex(options?.signal, "addressBook.unhide", () => convexCall.mutation(fns.addressBookUnhide, {
|
|
7098
|
+
actor,
|
|
7099
|
+
partyId: entryId
|
|
7100
|
+
})), mapAddressBookEntry),
|
|
7101
|
+
label: (input, options) => mapOk$1("addressBook.label", awaitableConvex(options?.signal, "addressBook.label", () => convexCall.mutation(fns.addressBookLabel, {
|
|
7102
|
+
actor,
|
|
7103
|
+
partyId: input.entryId,
|
|
7104
|
+
label: input.label
|
|
7105
|
+
})), mapAddressBookEntry)
|
|
7311
7106
|
},
|
|
7312
7107
|
requests: {
|
|
7313
7108
|
issue: async (input, options) => {
|
|
7314
7109
|
const payer = normalizeRefForBackend$1(input.payer, "payer");
|
|
7315
7110
|
if (!payer.ok) return payer;
|
|
7316
|
-
return mapOk$1(await awaitableConvex(options?.signal, "requests.issue", () => convexCall.mutation(fns.requestsIssue, {
|
|
7111
|
+
return mapOk$1("requests.issue", await awaitableConvex(options?.signal, "requests.issue", () => convexCall.mutation(fns.requestsIssue, {
|
|
7317
7112
|
actor,
|
|
7318
7113
|
payer: payer.value,
|
|
7319
7114
|
amount: input.amount,
|
|
@@ -7322,18 +7117,18 @@ function makeActorRelationshipMethods(deps) {
|
|
|
7322
7117
|
...input.expiresAt === void 0 ? {} : { expiresAt: input.expiresAt }
|
|
7323
7118
|
})), (request) => mapActorRequest(request, input.payer));
|
|
7324
7119
|
},
|
|
7325
|
-
list: (options) => mapOk$1(awaitableConvex(options?.signal, "requests.list", () => convexCall.query(fns.requestsList, { actor })), (requests) => requests.map((request) => mapActorRequest(request))),
|
|
7326
|
-
get: (requestId, options) => mapOk$1(awaitableConvex(options?.signal, "requests.get", () => convexCall.query(fns.requestsGet, {
|
|
7120
|
+
list: (options) => mapOk$1("requests.list", awaitableConvex(options?.signal, "requests.list", () => convexCall.query(fns.requestsList, { actor })), (requests) => requests.map((request) => mapActorRequest(request))),
|
|
7121
|
+
get: (requestId, options) => mapOk$1("requests.get", awaitableConvex(options?.signal, "requests.get", () => convexCall.query(fns.requestsGet, {
|
|
7327
7122
|
actor,
|
|
7328
7123
|
paymentRequestId: requestId
|
|
7329
7124
|
})), (request) => request === null ? null : mapActorRequest(request)),
|
|
7330
|
-
cancel: (requestId, options) => mapOk$1(awaitableConvex(options?.signal, "requests.cancel", () => convexCall.mutation(fns.requestsCancel, {
|
|
7125
|
+
cancel: (requestId, options) => mapOk$1("requests.cancel", awaitableConvex(options?.signal, "requests.cancel", () => convexCall.mutation(fns.requestsCancel, {
|
|
7331
7126
|
actor,
|
|
7332
7127
|
paymentRequestId: requestId
|
|
7333
7128
|
})), (request) => mapActorRequest(request))
|
|
7334
7129
|
},
|
|
7335
7130
|
inbox: {
|
|
7336
|
-
list: (options) => mapOk$1(awaitableConvex(options?.signal, "inbox.list", () => convexCall.query(fns.inboxList, { actor })), (items) => items.map(mapInboxItem)),
|
|
7131
|
+
list: (options) => mapOk$1("inbox.list", awaitableConvex(options?.signal, "inbox.list", () => convexCall.query(fns.inboxList, { actor })), (items) => items.map(mapInboxItem)),
|
|
7337
7132
|
approve: async (input, options) => {
|
|
7338
7133
|
const result = await awaitableConvex(options?.signal, "inbox.approve", () => convexCall.mutation(fns.inboxApprove, {
|
|
7339
7134
|
actor,
|
|
@@ -7344,7 +7139,7 @@ function makeActorRelationshipMethods(deps) {
|
|
|
7344
7139
|
if (!result.ok) return result;
|
|
7345
7140
|
return mapApprovedInboxPayment(result.value, input);
|
|
7346
7141
|
},
|
|
7347
|
-
decline: (requestId, options) => mapOk$1(awaitableConvex(options?.signal, "inbox.decline", () => convexCall.mutation(fns.inboxDecline, {
|
|
7142
|
+
decline: (requestId, options) => mapOk$1("inbox.decline", awaitableConvex(options?.signal, "inbox.decline", () => convexCall.mutation(fns.inboxDecline, {
|
|
7348
7143
|
actor,
|
|
7349
7144
|
paymentRequestId: requestId
|
|
7350
7145
|
})), mapInboxItem)
|
|
@@ -7412,30 +7207,52 @@ function missingConvexCall(operation) {
|
|
|
7412
7207
|
error: Errors.providerError("convex", operation, "ConvexCallPort is required")
|
|
7413
7208
|
});
|
|
7414
7209
|
}
|
|
7415
|
-
|
|
7210
|
+
/**
|
|
7211
|
+
* Project a successful backend reply, WITHOUT leaving the result boundary.
|
|
7212
|
+
*
|
|
7213
|
+
* The projection can refuse: `mapAddressBookEntry` proves the entry id is a
|
|
7214
|
+
* `PartyId` rather than trusting the wire, and `toPartyId` throws on a
|
|
7215
|
+
* malformed one. Every verb on this surface returns `CapxulResult`, so that
|
|
7216
|
+
* throw has to become a value here — otherwise a malformed reply rejects the
|
|
7217
|
+
* promise and the caller's `if (!result.ok)` never runs (ADR-0023: errors are
|
|
7218
|
+
* values, and a code crosses the seam).
|
|
7219
|
+
*/
|
|
7220
|
+
async function mapOk$1(operation, resultOrPromise, f) {
|
|
7416
7221
|
const result = await resultOrPromise;
|
|
7417
7222
|
if (!result.ok) return result;
|
|
7418
|
-
|
|
7419
|
-
|
|
7420
|
-
|
|
7421
|
-
|
|
7223
|
+
try {
|
|
7224
|
+
return {
|
|
7225
|
+
ok: true,
|
|
7226
|
+
value: f(result.value)
|
|
7227
|
+
};
|
|
7228
|
+
} catch (cause) {
|
|
7229
|
+
return {
|
|
7230
|
+
ok: false,
|
|
7231
|
+
error: cause instanceof CapxulError ? cause : Errors.providerError("convex", operation, cause)
|
|
7232
|
+
};
|
|
7233
|
+
}
|
|
7422
7234
|
}
|
|
7423
7235
|
const awaitableConvex = runIfActive;
|
|
7236
|
+
const ADDRESS_BOOK_RELATIONSHIPS = [
|
|
7237
|
+
"paid",
|
|
7238
|
+
"paidBy",
|
|
7239
|
+
"invoiced",
|
|
7240
|
+
"invoicedBy",
|
|
7241
|
+
"member",
|
|
7242
|
+
"manual",
|
|
7243
|
+
"employed"
|
|
7244
|
+
];
|
|
7245
|
+
function isAddressBookRelationship(value) {
|
|
7246
|
+
return ADDRESS_BOOK_RELATIONSHIPS.includes(value);
|
|
7247
|
+
}
|
|
7424
7248
|
function mapAddressBookEntry(entry) {
|
|
7425
|
-
const relationship = /* @__PURE__ */ new Set();
|
|
7426
|
-
for (const edge of entry.edges) {
|
|
7427
|
-
if (edge === "paid") relationship.add("paid");
|
|
7428
|
-
if (edge === "paidBy") relationship.add("paidBy");
|
|
7429
|
-
if (edge === "requested" || edge === "requestedBy") relationship.add("requested");
|
|
7430
|
-
if (edge === "member") relationship.add("member");
|
|
7431
|
-
if (edge === "employee") relationship.add("employee");
|
|
7432
|
-
}
|
|
7433
7249
|
return {
|
|
7434
|
-
id: entry.id,
|
|
7250
|
+
id: toPartyId(entry.id),
|
|
7435
7251
|
ref: entry.ref,
|
|
7436
|
-
label: entry.label
|
|
7437
|
-
relationship:
|
|
7438
|
-
hidden: entry.hidden
|
|
7252
|
+
label: entry.label,
|
|
7253
|
+
relationship: entry.relationship.filter(isAddressBookRelationship),
|
|
7254
|
+
hidden: entry.hidden,
|
|
7255
|
+
lastActivityAt: entry.lastActivityAt
|
|
7439
7256
|
};
|
|
7440
7257
|
}
|
|
7441
7258
|
function mapActorRequest(request, payer) {
|
|
@@ -7529,8 +7346,14 @@ function mapInboxStatus(status) {
|
|
|
7529
7346
|
}
|
|
7530
7347
|
function normalizeRefForBackend$1(ref, field) {
|
|
7531
7348
|
try {
|
|
7532
|
-
if (typeof ref === "string")
|
|
7533
|
-
|
|
7349
|
+
if (typeof ref === "string") return {
|
|
7350
|
+
ok: false,
|
|
7351
|
+
error: Errors.invalidInput(field, "recipient must be a typed Ref variant")
|
|
7352
|
+
};
|
|
7353
|
+
if (typeof ref !== "object" || ref === null || !("kind" in ref)) return {
|
|
7354
|
+
ok: false,
|
|
7355
|
+
error: Errors.invalidInput(field, "recipient must be a typed Ref variant")
|
|
7356
|
+
};
|
|
7534
7357
|
switch (ref.kind) {
|
|
7535
7358
|
case "handle": return {
|
|
7536
7359
|
ok: true,
|
|
@@ -7567,55 +7390,22 @@ function normalizeRefForBackend$1(ref, field) {
|
|
|
7567
7390
|
payeeId: nonEmptyRefValue$1(ref.payeeId, "payeeId")
|
|
7568
7391
|
}
|
|
7569
7392
|
};
|
|
7570
|
-
|
|
7393
|
+
case "party": return {
|
|
7394
|
+
ok: true,
|
|
7395
|
+
value: {
|
|
7396
|
+
kind: "party",
|
|
7397
|
+
partyId: toPartyId(ref.partyId)
|
|
7398
|
+
}
|
|
7399
|
+
};
|
|
7400
|
+
default: return {
|
|
7401
|
+
ok: false,
|
|
7402
|
+
error: Errors.invalidInput(field, "recipient must be a known Ref variant")
|
|
7403
|
+
};
|
|
7571
7404
|
}
|
|
7572
7405
|
} catch (cause) {
|
|
7573
|
-
if (cause instanceof Error && "code" in cause) return {
|
|
7574
|
-
ok: false,
|
|
7575
|
-
error: cause
|
|
7576
|
-
};
|
|
7577
7406
|
return {
|
|
7578
7407
|
ok: false,
|
|
7579
|
-
error: Errors.invalidInput(field, "recipient must be a typed Ref variant")
|
|
7580
|
-
};
|
|
7581
|
-
}
|
|
7582
|
-
}
|
|
7583
|
-
function refFromEntryId(entryId) {
|
|
7584
|
-
try {
|
|
7585
|
-
const parsed = JSON.parse(entryId);
|
|
7586
|
-
if (typeof parsed === "object" && parsed !== null && "kind" in parsed) return normalizeRefForBackend$1(parsed, "entryId");
|
|
7587
|
-
} catch {}
|
|
7588
|
-
const separator = entryId.indexOf(":");
|
|
7589
|
-
if (separator === -1) return {
|
|
7590
|
-
ok: false,
|
|
7591
|
-
error: Errors.invalidInput("entryId", "must be an address-book entry id")
|
|
7592
|
-
};
|
|
7593
|
-
const prefix = entryId.slice(0, separator);
|
|
7594
|
-
const value = entryId.slice(separator + 1);
|
|
7595
|
-
switch (prefix) {
|
|
7596
|
-
case "email": return normalizeRefForBackend$1({
|
|
7597
|
-
kind: "email",
|
|
7598
|
-
email: value
|
|
7599
|
-
}, "entryId");
|
|
7600
|
-
case "user": return normalizeRefForBackend$1({
|
|
7601
|
-
kind: "capxulUserId",
|
|
7602
|
-
capxulUserId: value
|
|
7603
|
-
}, "entryId");
|
|
7604
|
-
case "org": return normalizeRefForBackend$1({
|
|
7605
|
-
kind: "orgHandle",
|
|
7606
|
-
orgHandle: value
|
|
7607
|
-
}, "entryId");
|
|
7608
|
-
case "payee": return normalizeRefForBackend$1({
|
|
7609
|
-
kind: "payeeId",
|
|
7610
|
-
payeeId: value
|
|
7611
|
-
}, "entryId");
|
|
7612
|
-
case "handle": return normalizeRefForBackend$1({
|
|
7613
|
-
kind: "handle",
|
|
7614
|
-
handle: value
|
|
7615
|
-
}, "entryId");
|
|
7616
|
-
default: return {
|
|
7617
|
-
ok: false,
|
|
7618
|
-
error: Errors.invalidInput("entryId", "must be an address-book entry id")
|
|
7408
|
+
error: cause instanceof CapxulError ? cause : Errors.invalidInput(field, "recipient must be a typed Ref variant")
|
|
7619
7409
|
};
|
|
7620
7410
|
}
|
|
7621
7411
|
}
|
|
@@ -7629,15 +7419,6 @@ function handleRefValue$1(value, field) {
|
|
|
7629
7419
|
const trimmed = nonEmptyRefValue$1(value, field);
|
|
7630
7420
|
return trimmed.startsWith("@") ? trimmed.slice(1) : trimmed;
|
|
7631
7421
|
}
|
|
7632
|
-
function refLabel(ref) {
|
|
7633
|
-
switch (ref.kind) {
|
|
7634
|
-
case "handle": return ref.handle;
|
|
7635
|
-
case "email": return ref.email;
|
|
7636
|
-
case "orgHandle": return ref.orgHandle;
|
|
7637
|
-
case "capxulUserId": return ref.capxulUserId;
|
|
7638
|
-
case "payeeId": return ref.payeeId;
|
|
7639
|
-
}
|
|
7640
|
-
}
|
|
7641
7422
|
//#endregion
|
|
7642
7423
|
//#region ../../packages/sdk/src/surface/account.ts
|
|
7643
7424
|
const provisioningPhase = (state) => {
|
|
@@ -7660,6 +7441,10 @@ const actorFailure = (failure) => new CapxulError(failure.reason === "WORK_DIED"
|
|
|
7660
7441
|
...failure.details === void 0 ? {} : { details: failure.details },
|
|
7661
7442
|
layer: "identity"
|
|
7662
7443
|
});
|
|
7444
|
+
const accountFailureResult = (error) => ({
|
|
7445
|
+
ok: false,
|
|
7446
|
+
error
|
|
7447
|
+
});
|
|
7663
7448
|
function makeAccountMethods(deps) {
|
|
7664
7449
|
toChainId(deps.chainId);
|
|
7665
7450
|
const requirement = deps.requirement;
|
|
@@ -7802,26 +7587,16 @@ function makeAccountMethods(deps) {
|
|
|
7802
7587
|
value: provisioningPhase(deps.actor.snapshot())
|
|
7803
7588
|
};
|
|
7804
7589
|
};
|
|
7805
|
-
const reportAndReturn = (error, operation = "getLifecycle") => {
|
|
7806
|
-
if (deps.telemetry) captureExceptionSync(deps.telemetry, error, {
|
|
7807
|
-
layer: "account",
|
|
7808
|
-
operation
|
|
7809
|
-
});
|
|
7810
|
-
return {
|
|
7811
|
-
ok: false,
|
|
7812
|
-
error
|
|
7813
|
-
};
|
|
7814
|
-
};
|
|
7815
7590
|
const resolveLifecycle = async () => {
|
|
7816
7591
|
const phase = provisioningPhase(deps.actor.snapshot());
|
|
7817
7592
|
const status = await getStatus();
|
|
7818
|
-
if (!status.ok) return
|
|
7593
|
+
if (!status.ok) return accountFailureResult(status.error);
|
|
7819
7594
|
let accountId;
|
|
7820
7595
|
if (status.value.status !== "notAuthenticated" && (phase.status === "ready" || isRequirementMet(status.value, requirement))) {
|
|
7821
7596
|
const accountReadPort = deps.accountReadPort;
|
|
7822
|
-
if (accountReadPort === void 0) return
|
|
7597
|
+
if (accountReadPort === void 0) return accountFailureResult(Errors.invalidInput("account", "accountReadPort is required to resolve ready lifecycle"));
|
|
7823
7598
|
const account = await runPortEffect(accountReadPort.readBalance({ chainId: toChainId(deps.chainId) }));
|
|
7824
|
-
if (!account.ok) return
|
|
7599
|
+
if (!account.ok) return accountFailureResult(account.error);
|
|
7825
7600
|
accountId = String(account.value.id);
|
|
7826
7601
|
}
|
|
7827
7602
|
return {
|
|
@@ -7840,10 +7615,10 @@ function makeAccountMethods(deps) {
|
|
|
7840
7615
|
if (typeof resetSession === "function") try {
|
|
7841
7616
|
resetSession.call(deps.signer);
|
|
7842
7617
|
} catch (cause) {
|
|
7843
|
-
return
|
|
7618
|
+
return accountFailureResult(signerFailure(deps.signer.source, "resetSession", cause));
|
|
7844
7619
|
}
|
|
7845
7620
|
const retried = await drive({ _tag: "RetryAccount" });
|
|
7846
|
-
if (!retried.ok) return
|
|
7621
|
+
if (!retried.ok) return accountFailureResult(retried.error);
|
|
7847
7622
|
return resolveLifecycle();
|
|
7848
7623
|
};
|
|
7849
7624
|
return {
|
|
@@ -7996,7 +7771,7 @@ function cancelled(operation) {
|
|
|
7996
7771
|
function isAborted$2(signal) {
|
|
7997
7772
|
return signal?.aborted === true;
|
|
7998
7773
|
}
|
|
7999
|
-
async function signerCall(operation, run) {
|
|
7774
|
+
async function signerCall(source, operation, run) {
|
|
8000
7775
|
try {
|
|
8001
7776
|
return {
|
|
8002
7777
|
ok: true,
|
|
@@ -8005,7 +7780,7 @@ async function signerCall(operation, run) {
|
|
|
8005
7780
|
} catch (cause) {
|
|
8006
7781
|
return {
|
|
8007
7782
|
ok: false,
|
|
8008
|
-
error:
|
|
7783
|
+
error: signerFailure(source, operation, cause)
|
|
8009
7784
|
};
|
|
8010
7785
|
}
|
|
8011
7786
|
}
|
|
@@ -8017,7 +7792,7 @@ async function executePersonalPayment(deps, payment, signal, requestKey) {
|
|
|
8017
7792
|
ok: false,
|
|
8018
7793
|
error: Errors.notAuthenticated()
|
|
8019
7794
|
};
|
|
8020
|
-
const signerAddress = await signerCall("getAddress", () => deps.signer.getAddress());
|
|
7795
|
+
const signerAddress = await signerCall(deps.signer.source, "getAddress", () => deps.signer.getAddress());
|
|
8021
7796
|
if (!signerAddress.ok) return signerAddress;
|
|
8022
7797
|
const expectedSafe = deriveCapxulSafeAddress({ email: session.email });
|
|
8023
7798
|
const resolvedRequestKey = requestKey ?? `pay_${crypto.randomUUID()}`;
|
|
@@ -8036,7 +7811,7 @@ async function executePersonalPayment(deps, payment, signal, requestKey) {
|
|
|
8036
7811
|
paymentId: prepared.value.paymentId
|
|
8037
7812
|
});
|
|
8038
7813
|
if (isAborted$2(signal)) return cancelled("payments.pay");
|
|
8039
|
-
const signature = await signerCall("signUserOpHash", () => deps.signer.signUserOpHash(prepared.value.digest));
|
|
7814
|
+
const signature = await signerCall(deps.signer.source, "signUserOpHash", () => deps.signer.signUserOpHash(prepared.value.digest));
|
|
8040
7815
|
if (!signature.ok) return signature;
|
|
8041
7816
|
if (isAborted$2(signal)) return cancelled("payments.pay");
|
|
8042
7817
|
return runIfActive(void 0, "payments.submitExecution", () => deps.convexCall.action(deps.functions.submitPaymentExecution, { input: {
|
|
@@ -8049,12 +7824,6 @@ async function executePersonalPayment(deps, payment, signal, requestKey) {
|
|
|
8049
7824
|
function isAborted$1(signal) {
|
|
8050
7825
|
return signal?.aborted === true;
|
|
8051
7826
|
}
|
|
8052
|
-
function signerFailure(operation, cause) {
|
|
8053
|
-
return {
|
|
8054
|
-
ok: false,
|
|
8055
|
-
error: cause instanceof CapxulError ? cause : Errors.providerError("wallet-signer", operation, cause)
|
|
8056
|
-
};
|
|
8057
|
-
}
|
|
8058
7827
|
/** Return one stable fingerprint for one JSON payment intent. */
|
|
8059
7828
|
async function fingerprintPaymentIntent(intent) {
|
|
8060
7829
|
const canonical = JSON.stringify(intent, (_key, value) => value !== null && typeof value === "object" && !Array.isArray(value) ? Object.fromEntries(Object.entries(value).sort(([left], [right]) => left.localeCompare(right))) : value);
|
|
@@ -8075,7 +7844,10 @@ async function executePrepared(deps, prepare, expectedRequest, signal) {
|
|
|
8075
7844
|
try {
|
|
8076
7845
|
signerAddress = await deps.signer.getAddress();
|
|
8077
7846
|
} catch (cause) {
|
|
8078
|
-
return
|
|
7847
|
+
return {
|
|
7848
|
+
ok: false,
|
|
7849
|
+
error: signerFailure(deps.signer.source, "getAddress", cause)
|
|
7850
|
+
};
|
|
8079
7851
|
}
|
|
8080
7852
|
const prepared = await prepare(signerAddress);
|
|
8081
7853
|
if (!prepared.ok) return prepared;
|
|
@@ -8096,7 +7868,10 @@ async function executePrepared(deps, prepare, expectedRequest, signal) {
|
|
|
8096
7868
|
try {
|
|
8097
7869
|
signature = await deps.signer.signUserOpHash(prepared.value.digest);
|
|
8098
7870
|
} catch (cause) {
|
|
8099
|
-
return
|
|
7871
|
+
return {
|
|
7872
|
+
ok: false,
|
|
7873
|
+
error: signerFailure(deps.signer.source, "signUserOpHash", cause)
|
|
7874
|
+
};
|
|
8100
7875
|
}
|
|
8101
7876
|
if (isAborted$1(signal)) return {
|
|
8102
7877
|
ok: false,
|
|
@@ -8195,36 +7970,36 @@ async function paymentRequestKeyLifecycle(operation, intent, provided) {
|
|
|
8195
7970
|
key: provided,
|
|
8196
7971
|
finish: async () => void 0
|
|
8197
7972
|
};
|
|
8198
|
-
const slot = `capxul.payment.request-key.v3:${await fingerprintPaymentIntent({
|
|
8199
|
-
operation,
|
|
8200
|
-
intent
|
|
8201
|
-
})}`;
|
|
8202
|
-
if (typeof window === "undefined") {
|
|
8203
|
-
const attemptId = randomPaymentRequestKey();
|
|
8204
|
-
const state = memoryPaymentRequestKeys.get(slot) ?? {
|
|
8205
|
-
key: randomPaymentRequestKey(),
|
|
8206
|
-
active: [],
|
|
8207
|
-
resolved: false
|
|
8208
|
-
};
|
|
8209
|
-
state.active.push(attemptId);
|
|
8210
|
-
memoryPaymentRequestKeys.set(slot, state);
|
|
8211
|
-
let finished = false;
|
|
8212
|
-
return {
|
|
8213
|
-
key: state.key,
|
|
8214
|
-
finish: async (succeeded) => {
|
|
8215
|
-
if (finished) return;
|
|
8216
|
-
finished = true;
|
|
8217
|
-
const attemptIndex = state.active.indexOf(attemptId);
|
|
8218
|
-
if (attemptIndex < 0) return;
|
|
8219
|
-
state.active.splice(attemptIndex, 1);
|
|
8220
|
-
state.resolved = succeeded;
|
|
8221
|
-
if (state.active.length === 0 && state.resolved) memoryPaymentRequestKeys.delete(slot);
|
|
8222
|
-
}
|
|
8223
|
-
};
|
|
8224
|
-
}
|
|
8225
7973
|
let releaseAttemptLock;
|
|
8226
7974
|
let forgetPagehideRelease;
|
|
8227
7975
|
try {
|
|
7976
|
+
const slot = `capxul.payment.request-key.v3:${await fingerprintPaymentIntent({
|
|
7977
|
+
operation,
|
|
7978
|
+
intent
|
|
7979
|
+
})}`;
|
|
7980
|
+
if (typeof window === "undefined") {
|
|
7981
|
+
const attemptId = randomPaymentRequestKey();
|
|
7982
|
+
const state = memoryPaymentRequestKeys.get(slot) ?? {
|
|
7983
|
+
key: randomPaymentRequestKey(),
|
|
7984
|
+
active: [],
|
|
7985
|
+
resolved: false
|
|
7986
|
+
};
|
|
7987
|
+
state.active.push(attemptId);
|
|
7988
|
+
memoryPaymentRequestKeys.set(slot, state);
|
|
7989
|
+
let finished = false;
|
|
7990
|
+
return {
|
|
7991
|
+
key: state.key,
|
|
7992
|
+
finish: async (succeeded) => {
|
|
7993
|
+
if (finished) return;
|
|
7994
|
+
finished = true;
|
|
7995
|
+
const attemptIndex = state.active.indexOf(attemptId);
|
|
7996
|
+
if (attemptIndex < 0) return;
|
|
7997
|
+
state.active.splice(attemptIndex, 1);
|
|
7998
|
+
state.resolved = succeeded;
|
|
7999
|
+
if (state.active.length === 0 && state.resolved) memoryPaymentRequestKeys.delete(slot);
|
|
8000
|
+
}
|
|
8001
|
+
};
|
|
8002
|
+
}
|
|
8228
8003
|
const attemptId = randomPaymentRequestKey();
|
|
8229
8004
|
releaseAttemptLock = await holdPaymentAttemptLock(paymentAttemptLockName(slot, attemptId));
|
|
8230
8005
|
forgetPagehideRelease = releasePaymentAttemptOnPagehide(releaseAttemptLock);
|
|
@@ -8279,13 +8054,20 @@ async function paymentRequestKeyLifecycle(operation, intent, provided) {
|
|
|
8279
8054
|
throw Errors.providerError("sdk", "paymentRequestKey", cause);
|
|
8280
8055
|
}
|
|
8281
8056
|
}
|
|
8057
|
+
function paymentSubmissionFailure(cause) {
|
|
8058
|
+
return {
|
|
8059
|
+
ok: false,
|
|
8060
|
+
error: cause instanceof CapxulError ? cause : Errors.unknown(cause)
|
|
8061
|
+
};
|
|
8062
|
+
}
|
|
8282
8063
|
async function waitForPaymentSubmission(submission, signal, operation, onCancel = () => false) {
|
|
8283
|
-
|
|
8284
|
-
if (signal
|
|
8064
|
+
const foldedSubmission = submission.catch((cause) => paymentSubmissionFailure(cause));
|
|
8065
|
+
if (signal === void 0) return foldedSubmission;
|
|
8066
|
+
if (signal.aborted) return onCancel() ? foldedSubmission : {
|
|
8285
8067
|
ok: false,
|
|
8286
8068
|
error: Errors.cancelled({ operation })
|
|
8287
8069
|
};
|
|
8288
|
-
return new Promise((resolve
|
|
8070
|
+
return new Promise((resolve) => {
|
|
8289
8071
|
const onAbort = () => {
|
|
8290
8072
|
signal.removeEventListener("abort", onAbort);
|
|
8291
8073
|
if (!onCancel()) resolve({
|
|
@@ -8294,12 +8076,9 @@ async function waitForPaymentSubmission(submission, signal, operation, onCancel
|
|
|
8294
8076
|
});
|
|
8295
8077
|
};
|
|
8296
8078
|
signal.addEventListener("abort", onAbort, { once: true });
|
|
8297
|
-
|
|
8079
|
+
foldedSubmission.then((result) => {
|
|
8298
8080
|
signal.removeEventListener("abort", onAbort);
|
|
8299
8081
|
resolve(result);
|
|
8300
|
-
}, (cause) => {
|
|
8301
|
-
signal.removeEventListener("abort", onAbort);
|
|
8302
|
-
reject(cause instanceof Error ? cause : new Error(String(cause)));
|
|
8303
8082
|
});
|
|
8304
8083
|
});
|
|
8305
8084
|
}
|
|
@@ -8344,7 +8123,7 @@ function makeFinancialOpsMethods(deps) {
|
|
|
8344
8123
|
} catch (cause) {
|
|
8345
8124
|
return {
|
|
8346
8125
|
ok: false,
|
|
8347
|
-
error: cause instanceof CapxulError ? cause : Errors.
|
|
8126
|
+
error: cause instanceof CapxulError ? cause : Errors.unknown(cause)
|
|
8348
8127
|
};
|
|
8349
8128
|
}
|
|
8350
8129
|
const sharedKey = `${requestKeyScope}:${requestKey.key}`;
|
|
@@ -8392,7 +8171,10 @@ function makeFinancialOpsMethods(deps) {
|
|
|
8392
8171
|
try {
|
|
8393
8172
|
await requestKey.finish(false);
|
|
8394
8173
|
} catch {}
|
|
8395
|
-
|
|
8174
|
+
return {
|
|
8175
|
+
ok: false,
|
|
8176
|
+
error: cause instanceof CapxulError ? cause : Errors.unknown(cause)
|
|
8177
|
+
};
|
|
8396
8178
|
}
|
|
8397
8179
|
release(false);
|
|
8398
8180
|
try {
|
|
@@ -8416,11 +8198,25 @@ function makeFinancialOpsMethods(deps) {
|
|
|
8416
8198
|
const runLifecycle = async (intent, signal) => {
|
|
8417
8199
|
const execution = lifecycleDependencies();
|
|
8418
8200
|
if (!execution.ok) return execution;
|
|
8419
|
-
|
|
8420
|
-
const
|
|
8421
|
-
if (
|
|
8422
|
-
|
|
8423
|
-
|
|
8201
|
+
try {
|
|
8202
|
+
const submitted = await executePaymentLifecycle(execution.value, intent, signal);
|
|
8203
|
+
if (!submitted.ok) return submitted;
|
|
8204
|
+
const payments = submitted.value.payments;
|
|
8205
|
+
const payment = payments[0];
|
|
8206
|
+
if (payment === void 0 || payments.length !== 1) return {
|
|
8207
|
+
ok: false,
|
|
8208
|
+
error: Errors.unknown()
|
|
8209
|
+
};
|
|
8210
|
+
return {
|
|
8211
|
+
ok: true,
|
|
8212
|
+
value: normalizePaymentTiming(payment)
|
|
8213
|
+
};
|
|
8214
|
+
} catch (cause) {
|
|
8215
|
+
return {
|
|
8216
|
+
ok: false,
|
|
8217
|
+
error: cause instanceof CapxulError ? cause : Errors.unknown(cause)
|
|
8218
|
+
};
|
|
8219
|
+
}
|
|
8424
8220
|
};
|
|
8425
8221
|
return {
|
|
8426
8222
|
me: {
|
|
@@ -8471,9 +8267,10 @@ function makeFinancialOpsMethods(deps) {
|
|
|
8471
8267
|
value: resolvedTargetFromPayee(reference, payee.value)
|
|
8472
8268
|
};
|
|
8473
8269
|
}
|
|
8270
|
+
case "party":
|
|
8474
8271
|
case "destination": return Promise.resolve({
|
|
8475
8272
|
ok: false,
|
|
8476
|
-
error: Errors.notImplemented("targets",
|
|
8273
|
+
error: Errors.notImplemented("targets", `resolve.${reference.kind}`)
|
|
8477
8274
|
});
|
|
8478
8275
|
}
|
|
8479
8276
|
} },
|
|
@@ -8607,8 +8404,14 @@ function handleRefValue(value, field) {
|
|
|
8607
8404
|
}
|
|
8608
8405
|
function refFromTargetReference(reference, field) {
|
|
8609
8406
|
try {
|
|
8610
|
-
if (typeof reference === "string")
|
|
8611
|
-
|
|
8407
|
+
if (typeof reference === "string") return {
|
|
8408
|
+
ok: false,
|
|
8409
|
+
error: Errors.invalidInput(field, "target must be a typed TargetReference variant")
|
|
8410
|
+
};
|
|
8411
|
+
if (typeof reference !== "object" || reference === null || !("kind" in reference)) return {
|
|
8412
|
+
ok: false,
|
|
8413
|
+
error: Errors.invalidInput(field, "target must be a typed TargetReference variant")
|
|
8414
|
+
};
|
|
8612
8415
|
switch (reference.kind) {
|
|
8613
8416
|
case "handle": return {
|
|
8614
8417
|
ok: true,
|
|
@@ -8638,20 +8441,26 @@ function refFromTargetReference(reference, field) {
|
|
|
8638
8441
|
payeeId: reference.id
|
|
8639
8442
|
}
|
|
8640
8443
|
};
|
|
8444
|
+
case "party": return {
|
|
8445
|
+
ok: true,
|
|
8446
|
+
value: {
|
|
8447
|
+
kind: "party",
|
|
8448
|
+
partyId: reference.partyId
|
|
8449
|
+
}
|
|
8450
|
+
};
|
|
8641
8451
|
case "destination": return {
|
|
8642
8452
|
ok: false,
|
|
8643
8453
|
error: Errors.notImplemented("targets", "reference.destination")
|
|
8644
8454
|
};
|
|
8645
|
-
default:
|
|
8455
|
+
default: return {
|
|
8456
|
+
ok: false,
|
|
8457
|
+
error: Errors.invalidInput(field, "target must be a known TargetReference variant")
|
|
8458
|
+
};
|
|
8646
8459
|
}
|
|
8647
8460
|
} catch (cause) {
|
|
8648
|
-
if (cause instanceof Error && "code" in cause) return {
|
|
8649
|
-
ok: false,
|
|
8650
|
-
error: cause
|
|
8651
|
-
};
|
|
8652
8461
|
return {
|
|
8653
8462
|
ok: false,
|
|
8654
|
-
error: Errors.invalidInput(field, "target must be a typed TargetReference variant")
|
|
8463
|
+
error: cause instanceof CapxulError ? cause : Errors.invalidInput(field, "target must be a typed TargetReference variant")
|
|
8655
8464
|
};
|
|
8656
8465
|
}
|
|
8657
8466
|
}
|
|
@@ -8705,6 +8514,10 @@ function targetReferenceFromBackendRef(ref) {
|
|
|
8705
8514
|
kind: "payee",
|
|
8706
8515
|
id: ref.payeeId
|
|
8707
8516
|
};
|
|
8517
|
+
case "party": return {
|
|
8518
|
+
kind: "party",
|
|
8519
|
+
partyId: ref.partyId
|
|
8520
|
+
};
|
|
8708
8521
|
case "capxulUserId": throw Errors.notImplemented("targets", "reference.capxulUserId");
|
|
8709
8522
|
}
|
|
8710
8523
|
}
|
|
@@ -8791,8 +8604,14 @@ function normalizeDestinationRefForBackend(ref, field) {
|
|
|
8791
8604
|
}
|
|
8792
8605
|
function normalizeRefForBackend(ref, field) {
|
|
8793
8606
|
try {
|
|
8794
|
-
if (typeof ref === "string")
|
|
8795
|
-
|
|
8607
|
+
if (typeof ref === "string") return {
|
|
8608
|
+
ok: false,
|
|
8609
|
+
error: Errors.invalidInput(field, "recipient must be a typed Ref variant")
|
|
8610
|
+
};
|
|
8611
|
+
if (typeof ref !== "object" || ref === null || !("kind" in ref)) return {
|
|
8612
|
+
ok: false,
|
|
8613
|
+
error: Errors.invalidInput(field, "recipient must be a typed Ref variant")
|
|
8614
|
+
};
|
|
8796
8615
|
switch (ref.kind) {
|
|
8797
8616
|
case "handle": return {
|
|
8798
8617
|
ok: true,
|
|
@@ -8829,16 +8648,22 @@ function normalizeRefForBackend(ref, field) {
|
|
|
8829
8648
|
payeeId: nonEmptyRefValue(ref.payeeId, "payeeId")
|
|
8830
8649
|
}
|
|
8831
8650
|
};
|
|
8832
|
-
|
|
8651
|
+
case "party": return {
|
|
8652
|
+
ok: true,
|
|
8653
|
+
value: {
|
|
8654
|
+
kind: "party",
|
|
8655
|
+
partyId: toPartyId(ref.partyId)
|
|
8656
|
+
}
|
|
8657
|
+
};
|
|
8658
|
+
default: return {
|
|
8659
|
+
ok: false,
|
|
8660
|
+
error: Errors.invalidInput(field, "recipient must be a known Ref variant")
|
|
8661
|
+
};
|
|
8833
8662
|
}
|
|
8834
8663
|
} catch (cause) {
|
|
8835
|
-
if (cause instanceof Error && "code" in cause) return {
|
|
8836
|
-
ok: false,
|
|
8837
|
-
error: cause
|
|
8838
|
-
};
|
|
8839
8664
|
return {
|
|
8840
8665
|
ok: false,
|
|
8841
|
-
error: Errors.invalidInput(field, "recipient must be a typed Ref variant")
|
|
8666
|
+
error: cause instanceof CapxulError ? cause : Errors.invalidInput(field, "recipient must be a typed Ref variant")
|
|
8842
8667
|
};
|
|
8843
8668
|
}
|
|
8844
8669
|
}
|
|
@@ -8857,11 +8682,10 @@ function mapOk(result, f) {
|
|
|
8857
8682
|
value: f(result.value)
|
|
8858
8683
|
};
|
|
8859
8684
|
} catch (cause) {
|
|
8860
|
-
|
|
8685
|
+
return {
|
|
8861
8686
|
ok: false,
|
|
8862
|
-
error: cause
|
|
8687
|
+
error: cause instanceof CapxulError ? cause : Errors.unknown(cause)
|
|
8863
8688
|
};
|
|
8864
|
-
throw cause;
|
|
8865
8689
|
}
|
|
8866
8690
|
}
|
|
8867
8691
|
//#endregion
|
|
@@ -9029,7 +8853,7 @@ async function recoverRawDigestSigner(input) {
|
|
|
9029
8853
|
}
|
|
9030
8854
|
//#endregion
|
|
9031
8855
|
//#region ../../packages/sdk/package.json
|
|
9032
|
-
var version = "2.
|
|
8856
|
+
var version = "2.3.0";
|
|
9033
8857
|
//#endregion
|
|
9034
8858
|
//#region ../../packages/observability/src/engineering.ts
|
|
9035
8859
|
const SAFE_TRACED_HEADER_NAMES = [
|
|
@@ -13126,9 +12950,27 @@ function mapToCapxulError(operation, err) {
|
|
|
13126
12950
|
function mapToConvexCallError(operation, err) {
|
|
13127
12951
|
return convexCallErrorFromCapxul(operation, mapToCapxulError(operation, err));
|
|
13128
12952
|
}
|
|
12953
|
+
const TRANSPORT_ERROR_CODES = new Set([
|
|
12954
|
+
"EAI_AGAIN",
|
|
12955
|
+
"ECONNREFUSED",
|
|
12956
|
+
"ECONNRESET",
|
|
12957
|
+
"ENOTFOUND",
|
|
12958
|
+
"EPIPE",
|
|
12959
|
+
"ETIMEDOUT",
|
|
12960
|
+
"UND_ERR_CONNECT_TIMEOUT",
|
|
12961
|
+
"UND_ERR_HEADERS_TIMEOUT",
|
|
12962
|
+
"UND_ERR_SOCKET"
|
|
12963
|
+
]);
|
|
13129
12964
|
function isTransportError(err) {
|
|
13130
|
-
const
|
|
13131
|
-
|
|
12965
|
+
const seen = /* @__PURE__ */ new Set();
|
|
12966
|
+
let current = err;
|
|
12967
|
+
while (current !== void 0 && !seen.has(current)) {
|
|
12968
|
+
seen.add(current);
|
|
12969
|
+
const code = current.code;
|
|
12970
|
+
if (current.name === "FetchError" || current.name === "NetworkError" || typeof code === "string" && TRANSPORT_ERROR_CODES.has(code)) return true;
|
|
12971
|
+
current = current.cause instanceof Error ? current.cause : void 0;
|
|
12972
|
+
}
|
|
12973
|
+
return false;
|
|
13132
12974
|
}
|
|
13133
12975
|
//#endregion
|
|
13134
12976
|
//#region ../../packages/sdk/src/ports/identity.ts
|
|
@@ -13467,6 +13309,7 @@ function parseRoleDefinition(json) {
|
|
|
13467
13309
|
...raw.spend.perDay === void 0 ? {} : { perDay: parseRoleMoney(raw.spend.perDay, "perDay") },
|
|
13468
13310
|
...raw.spend.toRecipients === void 0 ? {} : { toRecipients: parseRoleRecipients(raw.spend.toRecipients) }
|
|
13469
13311
|
} },
|
|
13312
|
+
...typeof raw.canSpend === "boolean" ? { canSpend: raw.canSpend } : {},
|
|
13470
13313
|
...typeof raw.canManageMembers === "boolean" ? { canManageMembers: raw.canManageMembers } : {},
|
|
13471
13314
|
...typeof raw.canManageRoles === "boolean" ? { canManageRoles: raw.canManageRoles } : {}
|
|
13472
13315
|
};
|
|
@@ -13619,7 +13462,7 @@ var ConvexOrganizationSetupAdapter = class {
|
|
|
13619
13462
|
if (!lifecycle.ok) return lifecycle;
|
|
13620
13463
|
const orgId = parseOrgId("startOrResume", result.value.orgId);
|
|
13621
13464
|
if (!orgId.ok) return orgId;
|
|
13622
|
-
if (String(orgId.value) !== String(lifecycle.value.orgId)) return fail$
|
|
13465
|
+
if (String(orgId.value) !== String(lifecycle.value.orgId)) return fail$1(Errors.invalidInput("orgId", "Organization lifecycle scope does not match"));
|
|
13623
13466
|
return {
|
|
13624
13467
|
ok: true,
|
|
13625
13468
|
value: {
|
|
@@ -13637,7 +13480,7 @@ var ConvexOrganizationSetupAdapter = class {
|
|
|
13637
13480
|
async authorizeAndSubmitBootstrap(input) {
|
|
13638
13481
|
const cancelled = cancellation(input.signal);
|
|
13639
13482
|
if (cancelled !== void 0) return cancelled;
|
|
13640
|
-
const signerAddress = await signerResult("getAddress", () => this.#signer.getAddress());
|
|
13483
|
+
const signerAddress = await signerResult(this.#signer.source, "getAddress", () => this.#signer.getAddress());
|
|
13641
13484
|
if (!signerAddress.ok) return signerAddress;
|
|
13642
13485
|
const prepared = await runCall("prepareBootstrap", this.#convex.action(this.#fns.prepareBootstrap, copyInvocationObservation(input, {
|
|
13643
13486
|
orgId: input.orgId,
|
|
@@ -13649,7 +13492,7 @@ var ConvexOrganizationSetupAdapter = class {
|
|
|
13649
13492
|
if (!authority.ok) return authority;
|
|
13650
13493
|
const cancelledAfterPrepare = cancellation(input.signal);
|
|
13651
13494
|
if (cancelledAfterPrepare !== void 0) return cancelledAfterPrepare;
|
|
13652
|
-
const signature = await signerResult("signUserOpHash", () => this.#signer.signUserOpHash(prepared.value.digest));
|
|
13495
|
+
const signature = await signerResult(this.#signer.source, "signUserOpHash", () => this.#signer.signUserOpHash(prepared.value.digest));
|
|
13653
13496
|
if (!signature.ok) return signature;
|
|
13654
13497
|
const cancelledAfterSign = cancellation(input.signal);
|
|
13655
13498
|
if (cancelledAfterSign !== void 0) return cancelledAfterSign;
|
|
@@ -13693,7 +13536,7 @@ var ConvexOrganizationSetupAdapter = class {
|
|
|
13693
13536
|
async loadLifecycle(input) {
|
|
13694
13537
|
const result = await runCall("loadLifecycle", this.#convex.query(this.#fns.load, input));
|
|
13695
13538
|
if (!result.ok) return result;
|
|
13696
|
-
if (result.value === null) return fail$
|
|
13539
|
+
if (result.value === null) return fail$1(Errors.invalidInput("orgId", "Organization lifecycle was not found"));
|
|
13697
13540
|
return parseLifecycle("loadLifecycle", result.value);
|
|
13698
13541
|
}
|
|
13699
13542
|
async retry(input) {
|
|
@@ -13738,7 +13581,7 @@ function resetSignerSession(signer) {
|
|
|
13738
13581
|
value: void 0
|
|
13739
13582
|
};
|
|
13740
13583
|
} catch (cause) {
|
|
13741
|
-
return fail$
|
|
13584
|
+
return fail$1(signerFailure(signer.source, "resetSession", cause));
|
|
13742
13585
|
}
|
|
13743
13586
|
}
|
|
13744
13587
|
async function runCall(operation, effect) {
|
|
@@ -13747,9 +13590,9 @@ async function runCall(operation, effect) {
|
|
|
13747
13590
|
return Result.isSuccess(result) ? {
|
|
13748
13591
|
ok: true,
|
|
13749
13592
|
value: result.success
|
|
13750
|
-
} : fail$
|
|
13593
|
+
} : fail$1(publicError(operation, result.failure));
|
|
13751
13594
|
} catch (cause) {
|
|
13752
|
-
return fail$
|
|
13595
|
+
return fail$1(publicError(operation, cause));
|
|
13753
13596
|
}
|
|
13754
13597
|
}
|
|
13755
13598
|
function publicError(operation, cause) {
|
|
@@ -13760,14 +13603,14 @@ function publicError(operation, cause) {
|
|
|
13760
13603
|
}
|
|
13761
13604
|
return Errors.providerError("convex-organization", operation, cause);
|
|
13762
13605
|
}
|
|
13763
|
-
async function signerResult(operation, run) {
|
|
13606
|
+
async function signerResult(source, operation, run) {
|
|
13764
13607
|
try {
|
|
13765
13608
|
return {
|
|
13766
13609
|
ok: true,
|
|
13767
13610
|
value: await run()
|
|
13768
13611
|
};
|
|
13769
13612
|
} catch (cause) {
|
|
13770
|
-
return fail$
|
|
13613
|
+
return fail$1(signerFailure(source, operation, cause));
|
|
13771
13614
|
}
|
|
13772
13615
|
}
|
|
13773
13616
|
function validatePreparedAuthorities(prepared, signerAddress) {
|
|
@@ -13776,10 +13619,10 @@ function validatePreparedAuthorities(prepared, signerAddress) {
|
|
|
13776
13619
|
const founder = prepared.founderPersonalAccount.toLowerCase();
|
|
13777
13620
|
const organization = prepared.organizationAccountAddress.toLowerCase();
|
|
13778
13621
|
const sender = prepared.userOp.sender.toLowerCase();
|
|
13779
|
-
if (preparedSigner !== signer) return fail$
|
|
13780
|
-
if (founder === signer || organization === signer || organization === founder) return fail$
|
|
13781
|
-
if (sender !== founder) return fail$
|
|
13782
|
-
if (!/^0x[0-9a-fA-F]{64}$/u.test(prepared.digest)) return fail$
|
|
13622
|
+
if (preparedSigner !== signer) return fail$1(Errors.invalidInput("signerAddress", "Prepared signer does not match configured signer"));
|
|
13623
|
+
if (founder === signer || organization === signer || organization === founder) return fail$1(Errors.invalidInput("organizationAuthority", "Signer EOA, founder Account, and Organization Account must be distinct"));
|
|
13624
|
+
if (sender !== founder) return fail$1(Errors.invalidInput("userOp.sender", "Bootstrap sender must be the founder Account"));
|
|
13625
|
+
if (!/^0x[0-9a-fA-F]{64}$/u.test(prepared.digest)) return fail$1(Errors.invalidInput("digest", "Prepared bootstrap digest must be 32-byte hex"));
|
|
13783
13626
|
return {
|
|
13784
13627
|
ok: true,
|
|
13785
13628
|
value: void 0
|
|
@@ -13804,7 +13647,7 @@ function parseLifecycle(operation, wire) {
|
|
|
13804
13647
|
}
|
|
13805
13648
|
};
|
|
13806
13649
|
if (wire.status === "failed") {
|
|
13807
|
-
if (!isSetupStep(wire.at)) return fail$
|
|
13650
|
+
if (!isSetupStep(wire.at)) return fail$1(Errors.invalidInput("lifecycle.at", "Unknown setup step"));
|
|
13808
13651
|
return {
|
|
13809
13652
|
ok: true,
|
|
13810
13653
|
value: {
|
|
@@ -13816,7 +13659,7 @@ function parseLifecycle(operation, wire) {
|
|
|
13816
13659
|
}
|
|
13817
13660
|
};
|
|
13818
13661
|
}
|
|
13819
|
-
if (!isSetupStep(wire.step)) return fail$
|
|
13662
|
+
if (!isSetupStep(wire.step)) return fail$1(Errors.invalidInput("lifecycle.step", `Unknown setup step from ${operation}`));
|
|
13820
13663
|
return {
|
|
13821
13664
|
ok: true,
|
|
13822
13665
|
value: {
|
|
@@ -13833,16 +13676,16 @@ function parseOrgId(operation, value) {
|
|
|
13833
13676
|
value: toOrgId(value)
|
|
13834
13677
|
};
|
|
13835
13678
|
} catch (cause) {
|
|
13836
|
-
return fail$
|
|
13679
|
+
return fail$1(Errors.providerError("convex-organization", operation, cause));
|
|
13837
13680
|
}
|
|
13838
13681
|
}
|
|
13839
13682
|
function isSetupStep(value) {
|
|
13840
13683
|
return value === "preparingFounderAccount" || value === "awaitingFounderAuthorization" || value === "submittingBootstrap" || value === "confirmingBootstrap";
|
|
13841
13684
|
}
|
|
13842
13685
|
function cancellation(signal) {
|
|
13843
|
-
return signal?.aborted ? fail$
|
|
13686
|
+
return signal?.aborted ? fail$1(Errors.cancelled({ operation: "organization.setup" })) : void 0;
|
|
13844
13687
|
}
|
|
13845
|
-
function fail$
|
|
13688
|
+
function fail$1(error) {
|
|
13846
13689
|
return {
|
|
13847
13690
|
ok: false,
|
|
13848
13691
|
error
|
|
@@ -37195,6 +37038,10 @@ var y = class y {
|
|
|
37195
37038
|
function openfortProviderError(operation, cause) {
|
|
37196
37039
|
return cause instanceof CapxulError ? cause : Errors.providerError("openfort", operation, cause, { failure_mode: "unknown" });
|
|
37197
37040
|
}
|
|
37041
|
+
/** Build a named PROVIDER_ERROR. The assembled Core SDK boundary reports it. */
|
|
37042
|
+
function failOpenfort(operation, failure_mode, cause) {
|
|
37043
|
+
return Errors.providerError("openfort", operation, cause, { failure_mode });
|
|
37044
|
+
}
|
|
37198
37045
|
/**
|
|
37199
37046
|
* True when the browser cannot perform Web Crypto — sandboxed iframes, headless
|
|
37200
37047
|
* agent browsers, or non-HTTPS origins. OpenFort's embedded-wallet `configure`
|
|
@@ -37231,30 +37078,77 @@ function clearStaleOpenfortBrowserStorage(publishableKey) {
|
|
|
37231
37078
|
if (scope === void 0) return;
|
|
37232
37079
|
for (const key of OPENFORT_BROWSER_STORAGE_KEYS) localStorage.removeItem(`${scope}.${key}`);
|
|
37233
37080
|
}
|
|
37081
|
+
/**
|
|
37082
|
+
* The Openfort error code that names the stale-user class (#1435).
|
|
37083
|
+
* `getThirdPartyAuthToken` skips `authenticateThirdParty` while a `userId` sits
|
|
37084
|
+
* in scoped storage. A purged `userId` therefore pins every later call to a 401
|
|
37085
|
+
* that `extractApiError` reports as `USER_NOT_FOUND`.
|
|
37086
|
+
*
|
|
37087
|
+
* The set holds one member on purpose. Session-expiry codes (`SESSION_EXPIRED`,
|
|
37088
|
+
* `NOT_LOGGED_IN`, `INVALID_TOKEN`, `REFRESH_TOKEN_ERROR`) are a different
|
|
37089
|
+
* cause, and a bare 401 is a different cause again: `app-env-allowlist` is a
|
|
37090
|
+
* 401 by definition (`packages/errors/src/errors.ts:80-81`). Healing those and
|
|
37091
|
+
* tagging them `stale-openfort-cache` would delete the triage signal the tag
|
|
37092
|
+
* exists to carry.
|
|
37093
|
+
*/
|
|
37094
|
+
const STALE_USER_ERROR_CODES = new Set(["USER_NOT_FOUND"]);
|
|
37095
|
+
/**
|
|
37096
|
+
* The one predicate that opens the heal. It reads the Openfort error code and
|
|
37097
|
+
* never the message text (ADR-0023 R4). It walks the cause chain the way
|
|
37098
|
+
* `isTransportError` walks it in the Convex transport adapter.
|
|
37099
|
+
*
|
|
37100
|
+
* Known ceiling (#1435): a 401 that carries no recognized code is NOT healed.
|
|
37101
|
+
* `extractApiError` keeps the status only on `AuthenticationError`, so such a
|
|
37102
|
+
* payload is reachable. Add the code a live payload shows; do not add a message
|
|
37103
|
+
* match, because that trades one bug class for an ADR-0023 R4 violation.
|
|
37104
|
+
*/
|
|
37105
|
+
function isStaleUserSignal(cause) {
|
|
37106
|
+
for (const link of causeChain(cause)) {
|
|
37107
|
+
const error = link;
|
|
37108
|
+
if (typeof error.error === "string" && STALE_USER_ERROR_CODES.has(error.error) || typeof error.code === "string" && STALE_USER_ERROR_CODES.has(error.code)) return true;
|
|
37109
|
+
}
|
|
37110
|
+
return false;
|
|
37111
|
+
}
|
|
37234
37112
|
function createOpenfortBrowserSignerFromBootstrap(bootstrap, options = {}) {
|
|
37235
37113
|
const diagnostic = options.diagnostic;
|
|
37236
|
-
const telemetry = options.telemetry;
|
|
37237
37114
|
const authBaseUrl = normalizeBetterAuthBaseUrl(bootstrap.authBaseUrl);
|
|
37115
|
+
let currentStatus = "unknown";
|
|
37116
|
+
const statusListeners = /* @__PURE__ */ new Set();
|
|
37117
|
+
function setStatus(next) {
|
|
37118
|
+
if (currentStatus === next) return;
|
|
37119
|
+
currentStatus = next;
|
|
37120
|
+
for (const listener of statusListeners) try {
|
|
37121
|
+
listener(next);
|
|
37122
|
+
} catch {
|
|
37123
|
+
statusListeners.delete(listener);
|
|
37124
|
+
diagnostic?.trace("openfort.signerStatusListener", {
|
|
37125
|
+
ok: false,
|
|
37126
|
+
failure_mode: "unknown"
|
|
37127
|
+
});
|
|
37128
|
+
}
|
|
37129
|
+
}
|
|
37130
|
+
const statusStore = {
|
|
37131
|
+
status: () => currentStatus,
|
|
37132
|
+
subscribe: (listener) => {
|
|
37133
|
+
statusListeners.add(listener);
|
|
37134
|
+
return () => {
|
|
37135
|
+
statusListeners.delete(listener);
|
|
37136
|
+
};
|
|
37137
|
+
}
|
|
37138
|
+
};
|
|
37238
37139
|
/**
|
|
37239
37140
|
* Closes the black hole: when the browser has no Web Crypto, OpenFort's
|
|
37240
37141
|
* `configure` would resolve to no address and the failure would be reported
|
|
37241
|
-
* as `unknown`. Detect it before any network
|
|
37242
|
-
* `no-secure-context` on a PROVIDER_ERROR scoped to `configure
|
|
37243
|
-
*
|
|
37142
|
+
* as `unknown`. Detect it before any network or wallet work. Tag it
|
|
37143
|
+
* `no-secure-context` on a PROVIDER_ERROR scoped to `configure`. Add a
|
|
37144
|
+
* DiagnosticPort breadcrumb. The assembled Core SDK boundary reports it.
|
|
37244
37145
|
*/
|
|
37245
37146
|
function failNoSecureContext() {
|
|
37246
37147
|
diagnostic?.trace("openfort.configure", {
|
|
37247
37148
|
ok: false,
|
|
37248
37149
|
failure_mode: "no-secure-context"
|
|
37249
37150
|
});
|
|
37250
|
-
|
|
37251
|
-
if (telemetry) captureExceptionSync(telemetry, error, {
|
|
37252
|
-
layer: "openfort",
|
|
37253
|
-
operation: "configure",
|
|
37254
|
-
provider: "openfort",
|
|
37255
|
-
failure_mode: "no-secure-context"
|
|
37256
|
-
});
|
|
37257
|
-
throw error;
|
|
37151
|
+
throw failOpenfort("configure", "no-secure-context", /* @__PURE__ */ new Error("Web Crypto unavailable: browser is not a secure context"));
|
|
37258
37152
|
}
|
|
37259
37153
|
function betterAuthSessionUrl() {
|
|
37260
37154
|
return `${authBaseUrl}/get-session`;
|
|
@@ -37305,6 +37199,39 @@ function createOpenfortBrowserSignerFromBootstrap(bootstrap, options = {}) {
|
|
|
37305
37199
|
getAccessToken: fetchBetterAuthAccessToken
|
|
37306
37200
|
}
|
|
37307
37201
|
});
|
|
37202
|
+
async function configureEmbeddedWallet(encryptionSession) {
|
|
37203
|
+
await openfort.embeddedWallet.configure({
|
|
37204
|
+
accountType: N$1.EOA,
|
|
37205
|
+
chainType: c$6.EVM,
|
|
37206
|
+
recoveryParams: {
|
|
37207
|
+
recoveryMethod: e$10.AUTOMATIC,
|
|
37208
|
+
encryptionSession
|
|
37209
|
+
}
|
|
37210
|
+
});
|
|
37211
|
+
}
|
|
37212
|
+
/**
|
|
37213
|
+
* ONE heal cycle on the stale-user rejection (#1435). Clear the scoped
|
|
37214
|
+
* storage that pins the dead `userId`, run the existing configure path — it
|
|
37215
|
+
* re-runs third-party auth against the live Better Auth session now that no
|
|
37216
|
+
* `userId` is cached — and retry the read once. Exactly one cycle: a second
|
|
37217
|
+
* rejection is terminal and carries `failure_mode: "stale-openfort-cache"`.
|
|
37218
|
+
* The caller stays in `recovering` throughout; only the outcome moves it.
|
|
37219
|
+
*/
|
|
37220
|
+
async function healStaleOpenfortCache(encryptionSession) {
|
|
37221
|
+
try {
|
|
37222
|
+
clearStaleOpenfortBrowserStorage(bootstrap.openfortPublishableKey);
|
|
37223
|
+
diagnostic?.trace("openfort.storageCleared", { beforeConfigure: false });
|
|
37224
|
+
await configureEmbeddedWallet(encryptionSession);
|
|
37225
|
+
await openfort.embeddedWallet.get();
|
|
37226
|
+
} catch (cause) {
|
|
37227
|
+
diagnostic?.trace("openfort.staleCacheHeal", {
|
|
37228
|
+
ok: false,
|
|
37229
|
+
failure_mode: "stale-openfort-cache"
|
|
37230
|
+
});
|
|
37231
|
+
throw failOpenfort("get", "stale-openfort-cache", cause);
|
|
37232
|
+
}
|
|
37233
|
+
diagnostic?.trace("openfort.staleCacheHeal", { ok: true });
|
|
37234
|
+
}
|
|
37308
37235
|
let walletReadyPromise = null;
|
|
37309
37236
|
function startWalletReady() {
|
|
37310
37237
|
return (async () => {
|
|
@@ -37369,14 +37296,7 @@ function createOpenfortBrowserSignerFromBootstrap(bootstrap, options = {}) {
|
|
|
37369
37296
|
clearStaleOpenfortBrowserStorage(bootstrap.openfortPublishableKey);
|
|
37370
37297
|
diagnostic?.trace("openfort.storageCleared", { beforeConfigure: true });
|
|
37371
37298
|
try {
|
|
37372
|
-
await
|
|
37373
|
-
accountType: N$1.EOA,
|
|
37374
|
-
chainType: c$6.EVM,
|
|
37375
|
-
recoveryParams: {
|
|
37376
|
-
recoveryMethod: e$10.AUTOMATIC,
|
|
37377
|
-
encryptionSession: encryptionBody.sessionId
|
|
37378
|
-
}
|
|
37379
|
-
});
|
|
37299
|
+
await configureEmbeddedWallet(encryptionBody.sessionId);
|
|
37380
37300
|
diagnostic?.trace("openfort.configure", { ok: true });
|
|
37381
37301
|
} catch (cause) {
|
|
37382
37302
|
diagnostic?.trace("openfort.configure", {
|
|
@@ -37390,20 +37310,36 @@ function createOpenfortBrowserSignerFromBootstrap(bootstrap, options = {}) {
|
|
|
37390
37310
|
await openfort.embeddedWallet.get();
|
|
37391
37311
|
diagnostic?.trace("openfort.get", { ok: true });
|
|
37392
37312
|
} catch (cause) {
|
|
37313
|
+
if (!isStaleUserSignal(cause)) {
|
|
37314
|
+
diagnostic?.trace("openfort.get", {
|
|
37315
|
+
ok: false,
|
|
37316
|
+
failure_mode: "unknown"
|
|
37317
|
+
});
|
|
37318
|
+
throw openfortProviderError("get", cause);
|
|
37319
|
+
}
|
|
37393
37320
|
diagnostic?.trace("openfort.get", {
|
|
37394
37321
|
ok: false,
|
|
37395
|
-
failure_mode: "
|
|
37322
|
+
failure_mode: "stale-openfort-cache"
|
|
37396
37323
|
});
|
|
37397
|
-
|
|
37324
|
+
await healStaleOpenfortCache(encryptionBody.sessionId);
|
|
37398
37325
|
}
|
|
37399
37326
|
})();
|
|
37400
37327
|
}
|
|
37401
37328
|
async function ensureOpenfortWalletReady() {
|
|
37402
|
-
|
|
37329
|
+
let joined = walletReadyPromise;
|
|
37330
|
+
if (joined === null) {
|
|
37331
|
+
joined = startWalletReady();
|
|
37332
|
+
walletReadyPromise = joined;
|
|
37333
|
+
setStatus("recovering");
|
|
37334
|
+
}
|
|
37403
37335
|
try {
|
|
37404
|
-
await
|
|
37336
|
+
await joined;
|
|
37337
|
+
if (walletReadyPromise === joined) setStatus("ready");
|
|
37405
37338
|
} catch (cause) {
|
|
37406
|
-
walletReadyPromise
|
|
37339
|
+
if (walletReadyPromise === joined) {
|
|
37340
|
+
walletReadyPromise = null;
|
|
37341
|
+
setStatus("unavailable");
|
|
37342
|
+
}
|
|
37407
37343
|
throw cause;
|
|
37408
37344
|
}
|
|
37409
37345
|
}
|
|
@@ -37413,6 +37349,7 @@ function createOpenfortBrowserSignerFromBootstrap(bootstrap, options = {}) {
|
|
|
37413
37349
|
});
|
|
37414
37350
|
return {
|
|
37415
37351
|
...signer,
|
|
37352
|
+
statusStore,
|
|
37416
37353
|
getAddress: async () => {
|
|
37417
37354
|
try {
|
|
37418
37355
|
const address = await signer.getAddress();
|
|
@@ -37430,6 +37367,7 @@ function createOpenfortBrowserSignerFromBootstrap(bootstrap, options = {}) {
|
|
|
37430
37367
|
walletReadyPromise = null;
|
|
37431
37368
|
clearStaleOpenfortBrowserStorage(bootstrap.openfortPublishableKey);
|
|
37432
37369
|
signer.resetAddressCache();
|
|
37370
|
+
setStatus("unknown");
|
|
37433
37371
|
}
|
|
37434
37372
|
};
|
|
37435
37373
|
}
|
|
@@ -37448,6 +37386,8 @@ const IDENTITY_SLOT = {
|
|
|
37448
37386
|
const IDENTITY_SLOT_BY_EVENT = {
|
|
37449
37387
|
ReadSession: IDENTITY_SLOT.session,
|
|
37450
37388
|
RestoreSession: IDENTITY_SLOT.session,
|
|
37389
|
+
SessionRestored: IDENTITY_SLOT.session,
|
|
37390
|
+
SessionAbsent: IDENTITY_SLOT.session,
|
|
37451
37391
|
SessionRead: IDENTITY_SLOT.session,
|
|
37452
37392
|
SessionReadFailed: IDENTITY_SLOT.session,
|
|
37453
37393
|
RequestOtp: IDENTITY_SLOT.auth,
|
|
@@ -37513,7 +37453,7 @@ const modelSession = (session) => ({
|
|
|
37513
37453
|
});
|
|
37514
37454
|
const claimAccount = (input, authUserId, signer) => call("smart-account.claim", Effect.tryPromise({
|
|
37515
37455
|
try: () => signer.getAddress(),
|
|
37516
|
-
catch: (cause) =>
|
|
37456
|
+
catch: (cause) => signerFailure(signer.source, "getAddress", cause)
|
|
37517
37457
|
}).pipe(Effect.flatMap((signerAddress) => input.ports.smartAccount.claim({
|
|
37518
37458
|
authUserId: toAuthUserId(authUserId),
|
|
37519
37459
|
chainId: toChainId(input.chainId),
|
|
@@ -37759,7 +37699,7 @@ const identitySpec = (input, sessionStore = { current: null }) => {
|
|
|
37759
37699
|
};
|
|
37760
37700
|
return {
|
|
37761
37701
|
machine: "identity",
|
|
37762
|
-
initial:
|
|
37702
|
+
initial: RESTORING,
|
|
37763
37703
|
label,
|
|
37764
37704
|
slot: identitySlot,
|
|
37765
37705
|
transition: (state, event) => transition(state, event, config),
|
|
@@ -37895,7 +37835,7 @@ const bootIdentityFlow = (input, options = {}) => Effect.gen(function* () {
|
|
|
37895
37835
|
sessionStore.current = null;
|
|
37896
37836
|
}) : Effect.void)),
|
|
37897
37837
|
restoreAuthSession: (session, controls) => actor.ask({
|
|
37898
|
-
_tag: "RestoreSession",
|
|
37838
|
+
_tag: actor.snapshot().phase === "restoring" ? "SessionRestored" : "RestoreSession",
|
|
37899
37839
|
session: modelSession(session),
|
|
37900
37840
|
profileComplete: false
|
|
37901
37841
|
}, controls).pipe(Effect.tap(() => Effect.sync(() => {
|
|
@@ -37933,13 +37873,13 @@ const ask = (actor, event, controls, wrongState) => actor.ask(event, controls).p
|
|
|
37933
37873
|
*/
|
|
37934
37874
|
const getSessionProgramWithOptions = (options) => Effect.gen(function* () {
|
|
37935
37875
|
const deps = yield* CapxulDepsTag;
|
|
37936
|
-
const cached = yield* deps.authCache.getSession.pipe(Effect.mapError((e) => Errors.providerError("auth-cache", "getSession", e)));
|
|
37876
|
+
const cached = yield* deps.authCache.getSession.pipe(Effect.mapError((e) => Errors.providerError("auth-cache", "getSession", e)), Effect.catch((failure) => deps.actor.snapshot().phase === "restoring" ? Effect.succeed(null) : Effect.fail(failure)));
|
|
37937
37877
|
const observed = deps.actor.snapshot();
|
|
37938
37878
|
const actorState = observed.phase;
|
|
37939
37879
|
if (observed.phase === "faulted") return yield* Effect.fail(publicIdentityFailure(observed.failure));
|
|
37940
37880
|
if (cached === null && (actorState === "otp_pending" || actorState === "otp_sending" || actorState === "otp_verifying")) return null;
|
|
37941
|
-
if (cached !== null && actorState
|
|
37942
|
-
if (cached !== null
|
|
37881
|
+
if (cached !== null && !(actorState === "signed_out" || actorState === "restoring")) return cached;
|
|
37882
|
+
if (cached !== null) {
|
|
37943
37883
|
yield* deps.actor.restoreAuthSession(cached, depsRequestOptions(deps, options)).pipe(Effect.mapError(actorError));
|
|
37944
37884
|
return cached;
|
|
37945
37885
|
}
|
|
@@ -38042,6 +37982,7 @@ const signInProgram = (input, options) => Effect.gen(function* () {
|
|
|
38042
37982
|
}, depsRequestOptions(deps, options), {
|
|
38043
37983
|
method: "signIn",
|
|
38044
37984
|
validStates: [
|
|
37985
|
+
"restoring",
|
|
38045
37986
|
"signed_out",
|
|
38046
37987
|
"otp_pending",
|
|
38047
37988
|
"faulted"
|
|
@@ -38065,7 +38006,7 @@ const signInProgram = (input, options) => Effect.gen(function* () {
|
|
|
38065
38006
|
const signOutProgramWithOptions = (options) => Effect.gen(function* () {
|
|
38066
38007
|
const deps = yield* CapxulDepsTag;
|
|
38067
38008
|
let phase = deps.actor.snapshot().phase;
|
|
38068
|
-
if (phase === "signed_out") {
|
|
38009
|
+
if (phase === "signed_out" || phase === "restoring") {
|
|
38069
38010
|
const cached = yield* deps.authCache.getSession.pipe(Effect.mapError((e) => Errors.providerError("auth-cache", "getSession", e)));
|
|
38070
38011
|
if (cached !== null) {
|
|
38071
38012
|
yield* deps.actor.restoreAuthSession(cached, depsRequestOptions(deps, options)).pipe(Effect.mapError(actorError));
|
|
@@ -38441,6 +38382,32 @@ function makeSystemMethods(deps) {
|
|
|
38441
38382
|
return { health: (nonce, options) => runIfActive(options?.signal, "system.health", () => deps.convexCall.query(healthQuery, { nonce })) };
|
|
38442
38383
|
}
|
|
38443
38384
|
//#endregion
|
|
38385
|
+
//#region ../../packages/sdk/src/contract/org.ts
|
|
38386
|
+
const orgReadContract = { me: makeFunctionReference(CAPXUL_FUNCTIONS["org/queries"].me) };
|
|
38387
|
+
//#endregion
|
|
38388
|
+
//#region ../../packages/sdk/src/surface/org-me.ts
|
|
38389
|
+
function toBudget(wire) {
|
|
38390
|
+
return {
|
|
38391
|
+
id: toBudgetId(wire.id),
|
|
38392
|
+
label: wire.label,
|
|
38393
|
+
limit: wire.limitRaw === null ? null : fromWei(wire.limitRaw, wire.decimals, wire.currency)
|
|
38394
|
+
};
|
|
38395
|
+
}
|
|
38396
|
+
function toOrgMe(wire) {
|
|
38397
|
+
return {
|
|
38398
|
+
role: wire.role === null ? null : { label: wire.role.label },
|
|
38399
|
+
capabilities: {
|
|
38400
|
+
canManagePeople: wire.capabilities.canManagePeople,
|
|
38401
|
+
canSpend: wire.capabilities.canSpend
|
|
38402
|
+
},
|
|
38403
|
+
budgets: wire.budgets.map(toBudget),
|
|
38404
|
+
observedAt: wire.observedAt
|
|
38405
|
+
};
|
|
38406
|
+
}
|
|
38407
|
+
function makeOrgMeMethod(deps, orgId) {
|
|
38408
|
+
return (options) => runIfActive(options?.signal, "org.me", () => Effect.map(deps.convexCall.query(orgReadContract.me, { orgId }), toOrgMe));
|
|
38409
|
+
}
|
|
38410
|
+
//#endregion
|
|
38444
38411
|
//#region ../../packages/sdk/src/contract/permission.ts
|
|
38445
38412
|
const permissionContract = { read: makeFunctionReference(CAPXUL_FUNCTIONS["permission/queries"].read) };
|
|
38446
38413
|
//#endregion
|
|
@@ -38448,12 +38415,6 @@ const permissionContract = { read: makeFunctionReference(CAPXUL_FUNCTIONS["permi
|
|
|
38448
38415
|
function isAborted(signal) {
|
|
38449
38416
|
return signal?.aborted === true;
|
|
38450
38417
|
}
|
|
38451
|
-
function fail$1(cause, operation) {
|
|
38452
|
-
return {
|
|
38453
|
-
ok: false,
|
|
38454
|
-
error: cause instanceof CapxulError ? cause : Errors.providerError("wallet-signer", operation, cause)
|
|
38455
|
-
};
|
|
38456
|
-
}
|
|
38457
38418
|
async function execute(deps, orgId, command, signal) {
|
|
38458
38419
|
if (isAborted(signal)) return {
|
|
38459
38420
|
ok: false,
|
|
@@ -38472,7 +38433,10 @@ async function execute(deps, orgId, command, signal) {
|
|
|
38472
38433
|
try {
|
|
38473
38434
|
signerAddress = await deps.signer.getAddress();
|
|
38474
38435
|
} catch (cause) {
|
|
38475
|
-
return
|
|
38436
|
+
return {
|
|
38437
|
+
ok: false,
|
|
38438
|
+
error: signerFailure(deps.signer.source, "getAddress", cause)
|
|
38439
|
+
};
|
|
38476
38440
|
}
|
|
38477
38441
|
const executionFns = deps.executionFunctions ?? moneyExecutionContract;
|
|
38478
38442
|
const prepared = await runIfActive(signal, "permissions.prepareExecution", () => deps.convexCall.action(executionFns.preparePermissionExecution, { input: {
|
|
@@ -38494,7 +38458,10 @@ async function execute(deps, orgId, command, signal) {
|
|
|
38494
38458
|
try {
|
|
38495
38459
|
signature = await deps.signer.signUserOpHash(prepared.value.digest);
|
|
38496
38460
|
} catch (cause) {
|
|
38497
|
-
return
|
|
38461
|
+
return {
|
|
38462
|
+
ok: false,
|
|
38463
|
+
error: signerFailure(deps.signer.source, "signUserOpHash", cause)
|
|
38464
|
+
};
|
|
38498
38465
|
}
|
|
38499
38466
|
if (isAborted(signal)) return {
|
|
38500
38467
|
ok: false,
|
|
@@ -38572,7 +38539,7 @@ function makeOrganizationPaymentsMethods(deps, orgId) {
|
|
|
38572
38539
|
} catch (cause) {
|
|
38573
38540
|
return {
|
|
38574
38541
|
ok: false,
|
|
38575
|
-
error: cause instanceof CapxulError ? cause : Errors.
|
|
38542
|
+
error: cause instanceof CapxulError ? cause : Errors.unknown(cause)
|
|
38576
38543
|
};
|
|
38577
38544
|
}
|
|
38578
38545
|
const flightKey = `${requestKeyScope}:${operation}:${requestKey.key}`;
|
|
@@ -38619,16 +38586,16 @@ function makeOrganizationPaymentsMethods(deps, orgId) {
|
|
|
38619
38586
|
try {
|
|
38620
38587
|
await requestKey.finish(false);
|
|
38621
38588
|
} catch {}
|
|
38622
|
-
|
|
38589
|
+
return {
|
|
38590
|
+
ok: false,
|
|
38591
|
+
error: cause instanceof CapxulError ? cause : Errors.unknown(cause)
|
|
38592
|
+
};
|
|
38623
38593
|
}
|
|
38624
38594
|
release(false);
|
|
38625
38595
|
try {
|
|
38626
38596
|
await requestKey.finish(result.ok);
|
|
38627
38597
|
} catch {}
|
|
38628
|
-
return result.
|
|
38629
|
-
ok: true,
|
|
38630
|
-
value: result.value.payments.map((payment) => normalizePaymentTiming(payment))
|
|
38631
|
-
} : result;
|
|
38598
|
+
return mapOk(result, (value) => value.payments.map((payment) => normalizePaymentTiming(payment)));
|
|
38632
38599
|
};
|
|
38633
38600
|
return {
|
|
38634
38601
|
pay: async (input, options) => {
|
|
@@ -38798,38 +38765,6 @@ function hermeticOrgView(input) {
|
|
|
38798
38765
|
logoUrl: null
|
|
38799
38766
|
};
|
|
38800
38767
|
}
|
|
38801
|
-
function moneyFromConfig(input) {
|
|
38802
|
-
return {
|
|
38803
|
-
currency: toCurrencyCode(input.currency),
|
|
38804
|
-
value: input.value,
|
|
38805
|
-
decimals: input.decimals
|
|
38806
|
-
};
|
|
38807
|
-
}
|
|
38808
|
-
function recipientsFromConfig(toRecipients) {
|
|
38809
|
-
if (toRecipients === void 0 || toRecipients === "anyone") return toRecipients;
|
|
38810
|
-
return toRecipients.map((recipient) => toAddress(recipient));
|
|
38811
|
-
}
|
|
38812
|
-
function roleDefinitionFromConfig(definition) {
|
|
38813
|
-
const toRecipients = recipientsFromConfig(definition.spend?.toRecipients);
|
|
38814
|
-
return {
|
|
38815
|
-
label: definition.label,
|
|
38816
|
-
...definition.spend === void 0 ? {} : { spend: {
|
|
38817
|
-
...definition.spend.perTx === void 0 ? {} : { perTx: moneyFromConfig(definition.spend.perTx) },
|
|
38818
|
-
...definition.spend.perDay === void 0 ? {} : { perDay: moneyFromConfig(definition.spend.perDay) },
|
|
38819
|
-
...toRecipients === void 0 ? {} : { toRecipients }
|
|
38820
|
-
} },
|
|
38821
|
-
...definition.canManageMembers === void 0 ? {} : { canManageMembers: definition.canManageMembers },
|
|
38822
|
-
...definition.canManageRoles === void 0 ? {} : { canManageRoles: definition.canManageRoles }
|
|
38823
|
-
};
|
|
38824
|
-
}
|
|
38825
|
-
function startupRoleViews(orgId) {
|
|
38826
|
-
return compileOrgRoleDefinitions(orgRoleTemplateDefinitions("Startup")).roles.map((role) => ({
|
|
38827
|
-
orgId,
|
|
38828
|
-
label: role.label,
|
|
38829
|
-
roleKey: toRoleKey(role.roleKey),
|
|
38830
|
-
definition: roleDefinitionFromConfig(role.definition)
|
|
38831
|
-
}));
|
|
38832
|
-
}
|
|
38833
38768
|
function hermeticMember(input) {
|
|
38834
38769
|
return {
|
|
38835
38770
|
orgId: input.orgId,
|
|
@@ -38931,7 +38866,7 @@ function listRolesProgram(orgId) {
|
|
|
38931
38866
|
return Effect.gen(function* () {
|
|
38932
38867
|
const deps = yield* OrgDepsTag;
|
|
38933
38868
|
if (deps.orgPort !== void 0) return yield* deps.orgPort.listRoles({ orgId }).pipe(Effect.mapError((error) => error.publicError));
|
|
38934
|
-
return
|
|
38869
|
+
return [];
|
|
38935
38870
|
});
|
|
38936
38871
|
}
|
|
38937
38872
|
function listMembersProgram(orgId) {
|
|
@@ -39096,6 +39031,7 @@ function makeOrgMethods(deps) {
|
|
|
39096
39031
|
},
|
|
39097
39032
|
...convexCall === void 0 ? {} : { convexCall }
|
|
39098
39033
|
}),
|
|
39034
|
+
me: convexCall === void 0 ? orgMeUnavailable : makeOrgMeMethod({ convexCall }, String(orgId)),
|
|
39099
39035
|
async getLifecycle(options) {
|
|
39100
39036
|
if (options?.signal?.aborted) return {
|
|
39101
39037
|
ok: false,
|
|
@@ -39243,6 +39179,10 @@ function makeNotImplementedOrganizationPaymentsMethods() {
|
|
|
39243
39179
|
payBatch: organizationPaymentExecutionUnavailable
|
|
39244
39180
|
};
|
|
39245
39181
|
}
|
|
39182
|
+
const orgMeUnavailable = () => Promise.resolve({
|
|
39183
|
+
ok: false,
|
|
39184
|
+
error: Errors.notImplemented("org", "me")
|
|
39185
|
+
});
|
|
39246
39186
|
const permissionExecutionUnavailable = () => Promise.resolve({
|
|
39247
39187
|
ok: false,
|
|
39248
39188
|
error: Errors.notImplemented("permissions", "executionComposition")
|
|
@@ -39379,18 +39319,104 @@ function detectAuthCacheAdapter() {
|
|
|
39379
39319
|
return new InMemoryAuthCacheAdapter();
|
|
39380
39320
|
}
|
|
39381
39321
|
//#endregion
|
|
39322
|
+
//#region ../../packages/sdk/src/telemetry/capture-exception.ts
|
|
39323
|
+
/** Fixed, leak-safe message — the raw error message may carry PII and never ships. */
|
|
39324
|
+
const EXCEPTION_MESSAGE = "Capxul SDK operation failed";
|
|
39325
|
+
//#endregion
|
|
39382
39326
|
//#region ../../packages/sdk/src/observation.ts
|
|
39383
39327
|
const SDK_VERSION$1 = version;
|
|
39328
|
+
/** @internal Observe public result methods at the assembled Core SDK boundary. */
|
|
39329
|
+
function observeSdkClient(client, adapter, snapshot) {
|
|
39330
|
+
if (adapter === void 0) return client;
|
|
39331
|
+
const objectProxies = /* @__PURE__ */ new WeakMap();
|
|
39332
|
+
const proxyTargets = /* @__PURE__ */ new WeakMap();
|
|
39333
|
+
const functionWrappers = /* @__PURE__ */ new WeakMap();
|
|
39334
|
+
const wrapObject = (target, path, internal = false) => {
|
|
39335
|
+
const cacheKey = `${internal ? "internal" : "public"}:${path.join(".")}`;
|
|
39336
|
+
let targetProxies = objectProxies.get(target);
|
|
39337
|
+
const cached = targetProxies?.get(cacheKey);
|
|
39338
|
+
if (cached !== void 0) return cached;
|
|
39339
|
+
const proxy = new Proxy(target, { get(currentTarget, property, receiver) {
|
|
39340
|
+
const value = Reflect.get(currentTarget, property, receiver);
|
|
39341
|
+
if (typeof property !== "string") return value;
|
|
39342
|
+
if (path.length === 0 && property === "_internal" && isPlainObject(value)) return wrapObject(value, ["_internal"], true);
|
|
39343
|
+
if (internal && property !== "accounts") return value;
|
|
39344
|
+
return wrapValue(value, [...path, property], currentTarget);
|
|
39345
|
+
} });
|
|
39346
|
+
proxyTargets.set(proxy, target);
|
|
39347
|
+
if (targetProxies === void 0) {
|
|
39348
|
+
targetProxies = /* @__PURE__ */ new Map();
|
|
39349
|
+
objectProxies.set(target, targetProxies);
|
|
39350
|
+
}
|
|
39351
|
+
targetProxies.set(cacheKey, proxy);
|
|
39352
|
+
return proxy;
|
|
39353
|
+
};
|
|
39354
|
+
const wrapValue = (value, path, owner) => {
|
|
39355
|
+
if (typeof value === "function") {
|
|
39356
|
+
const callable = value;
|
|
39357
|
+
const operation = path.join(".");
|
|
39358
|
+
let ownerWrappers = functionWrappers.get(owner);
|
|
39359
|
+
if (ownerWrappers === void 0) {
|
|
39360
|
+
ownerWrappers = /* @__PURE__ */ new Map();
|
|
39361
|
+
functionWrappers.set(owner, ownerWrappers);
|
|
39362
|
+
}
|
|
39363
|
+
const cached = ownerWrappers.get(operation);
|
|
39364
|
+
if (cached !== void 0) return cached;
|
|
39365
|
+
let wrapped;
|
|
39366
|
+
wrapped = new Proxy(callable, {
|
|
39367
|
+
apply(currentTarget, thisArg, args) {
|
|
39368
|
+
const invocation = resolveInvocationSnapshot(adapter, snapshot);
|
|
39369
|
+
let output;
|
|
39370
|
+
try {
|
|
39371
|
+
output = Reflect.apply(currentTarget, unwrapReceiver(thisArg), args);
|
|
39372
|
+
} catch (cause) {
|
|
39373
|
+
report(adapter, "exception", operation, cause, invocation);
|
|
39374
|
+
throw cause;
|
|
39375
|
+
}
|
|
39376
|
+
if (isPromiseLike(output)) return Promise.resolve(output).then((result) => processOutput(result, path, invocation), (cause) => {
|
|
39377
|
+
report(adapter, "exception", operation, cause, invocation);
|
|
39378
|
+
throw cause;
|
|
39379
|
+
});
|
|
39380
|
+
return processOutput(output, path, invocation);
|
|
39381
|
+
},
|
|
39382
|
+
get(currentTarget, property) {
|
|
39383
|
+
if (property === "bind") return Function.prototype.bind.bind(wrapped);
|
|
39384
|
+
if (property === "call") return Function.prototype.call.bind(wrapped);
|
|
39385
|
+
if (property === "apply") return Function.prototype.apply.bind(wrapped);
|
|
39386
|
+
const attached = Reflect.get(currentTarget, property, currentTarget);
|
|
39387
|
+
if (typeof property !== "string") return attached;
|
|
39388
|
+
return wrapValue(attached, [...path, property], currentTarget);
|
|
39389
|
+
}
|
|
39390
|
+
});
|
|
39391
|
+
proxyTargets.set(wrapped, callable);
|
|
39392
|
+
ownerWrappers.set(operation, wrapped);
|
|
39393
|
+
return wrapped;
|
|
39394
|
+
}
|
|
39395
|
+
return isPlainObject(value) ? wrapObject(value, path) : value;
|
|
39396
|
+
};
|
|
39397
|
+
const processOutput = (output, path, invocation) => {
|
|
39398
|
+
if (isFailedResult(output)) {
|
|
39399
|
+
report(adapter, "operation", path.join("."), output.error, invocation);
|
|
39400
|
+
return output;
|
|
39401
|
+
}
|
|
39402
|
+
if (isCapxulResult(output)) return output;
|
|
39403
|
+
return isPlainObject(output) ? wrapObject(output, path) : output;
|
|
39404
|
+
};
|
|
39405
|
+
return wrapObject(client, []);
|
|
39406
|
+
function unwrapReceiver(receiver) {
|
|
39407
|
+
return (typeof receiver === "object" || typeof receiver === "function") && receiver !== null ? proxyTargets.get(receiver) ?? receiver : receiver;
|
|
39408
|
+
}
|
|
39409
|
+
}
|
|
39384
39410
|
/** @internal Reports a factory-level typed failure without changing its identity. */
|
|
39385
39411
|
function observeFailedResult(result, adapter, operation) {
|
|
39386
|
-
if (adapter !== void 0 && isFailedResult(result)) report(adapter, "operation", operation, result.error,
|
|
39412
|
+
if (adapter !== void 0 && isFailedResult(result)) report(adapter, "operation", operation, result.error, resolveAdapterSnapshot(adapter));
|
|
39387
39413
|
return result;
|
|
39388
39414
|
}
|
|
39389
|
-
function report(adapter, kind, operation, cause,
|
|
39415
|
+
function report(adapter, kind, operation, cause, invocation) {
|
|
39390
39416
|
const operationName = normalizeOperation(operation);
|
|
39391
39417
|
const kindName = normalizeErrorKind(errorKind(cause));
|
|
39392
39418
|
const context = sanitizeObservationContext({
|
|
39393
|
-
...
|
|
39419
|
+
...invocation.context,
|
|
39394
39420
|
...isCapxulError(cause) && cause.correlationId !== void 0 ? { correlationId: cause.correlationId } : {}
|
|
39395
39421
|
});
|
|
39396
39422
|
const failure = markFailureInvocationSnapshot({
|
|
@@ -39400,13 +39426,27 @@ function report(adapter, kind, operation, cause, invocationContext) {
|
|
|
39400
39426
|
errorKind: kindName,
|
|
39401
39427
|
...context === void 0 ? {} : { context }
|
|
39402
39428
|
}, {
|
|
39403
|
-
active:
|
|
39429
|
+
active: invocation.active,
|
|
39404
39430
|
...context === void 0 ? {} : { context }
|
|
39405
39431
|
});
|
|
39406
39432
|
try {
|
|
39407
39433
|
ignoreDeliveryFailure(kind === "operation" ? adapter.captureOperationFailure(failure) : adapter.captureException(failure));
|
|
39408
39434
|
} catch {}
|
|
39409
39435
|
}
|
|
39436
|
+
function resolveInvocationSnapshot(adapter, snapshot) {
|
|
39437
|
+
if (snapshot !== void 0) try {
|
|
39438
|
+
const captured = snapshot();
|
|
39439
|
+
if (captured !== void 0) return captured;
|
|
39440
|
+
} catch {}
|
|
39441
|
+
return resolveAdapterSnapshot(adapter);
|
|
39442
|
+
}
|
|
39443
|
+
function resolveAdapterSnapshot(adapter) {
|
|
39444
|
+
const context = resolveAdapterContext(adapter);
|
|
39445
|
+
return context === void 0 ? { active: false } : {
|
|
39446
|
+
active: true,
|
|
39447
|
+
context
|
|
39448
|
+
};
|
|
39449
|
+
}
|
|
39410
39450
|
function resolveAdapterContext(adapter) {
|
|
39411
39451
|
try {
|
|
39412
39452
|
return adapter.resolveContext?.();
|
|
@@ -39474,6 +39514,8 @@ const APPLIED_ACTION_BY_EVENT = {
|
|
|
39474
39514
|
RestoreSession: "none",
|
|
39475
39515
|
ResumeOtpEntry: "none",
|
|
39476
39516
|
Reset: "none",
|
|
39517
|
+
SessionRestored: "none",
|
|
39518
|
+
SessionAbsent: "none",
|
|
39477
39519
|
EnsureAccount: "none",
|
|
39478
39520
|
ClaimAccount: "none",
|
|
39479
39521
|
RetryAccount: "none",
|
|
@@ -39574,6 +39616,7 @@ function withAdapterClose(client, closeAdapter) {
|
|
|
39574
39616
|
};
|
|
39575
39617
|
}
|
|
39576
39618
|
function assembleCapxulClient(input) {
|
|
39619
|
+
const observation = input;
|
|
39577
39620
|
const authCache = input.authCache ?? detectAuthCacheAdapter();
|
|
39578
39621
|
const effectRunner = input.effectRunner ?? {
|
|
39579
39622
|
runSync: Effect.runSync,
|
|
@@ -39587,7 +39630,7 @@ function assembleCapxulClient(input) {
|
|
|
39587
39630
|
...input.signer === void 0 ? {} : { signer: input.signer },
|
|
39588
39631
|
...input.organizationSetup === void 0 ? {} : { organizationSetup: input.organizationSetup },
|
|
39589
39632
|
...input.otpTtlMs === void 0 ? {} : { otpTtlMs: input.otpTtlMs }
|
|
39590
|
-
}), scope)),
|
|
39633
|
+
}), scope)), observation.hostObservationSnapshot);
|
|
39591
39634
|
const unsubscribeProductTelemetry = actor.subscribeTransitions((record) => {
|
|
39592
39635
|
effectRunner.runPromise(executeIdentityProductObservation(input.ports.telemetry, record, actor.snapshot())).catch(() => {});
|
|
39593
39636
|
});
|
|
@@ -39636,7 +39679,11 @@ function assembleCapxulClient(input) {
|
|
|
39636
39679
|
...input.invokeTimeoutMs === void 0 ? {} : { invokeTimeoutMs: input.invokeTimeoutMs },
|
|
39637
39680
|
afterVerifyOtp: async () => {
|
|
39638
39681
|
const browserSigner = input.signer;
|
|
39639
|
-
if (browserSigner !== void 0 && "resetSession" in browserSigner && typeof browserSigner.resetSession === "function")
|
|
39682
|
+
if (browserSigner !== void 0 && "resetSession" in browserSigner && typeof browserSigner.resetSession === "function") try {
|
|
39683
|
+
browserSigner.resetSession();
|
|
39684
|
+
} catch (cause) {
|
|
39685
|
+
throw signerFailure(browserSigner.source, "resetSession", cause);
|
|
39686
|
+
}
|
|
39640
39687
|
await detectPendingOrgInvitations?.();
|
|
39641
39688
|
kickProvisioning?.();
|
|
39642
39689
|
}
|
|
@@ -39742,7 +39789,7 @@ function assembleCapxulClient(input) {
|
|
|
39742
39789
|
};
|
|
39743
39790
|
}
|
|
39744
39791
|
};
|
|
39745
|
-
return {
|
|
39792
|
+
return observeSdkClient({
|
|
39746
39793
|
auth,
|
|
39747
39794
|
smartAccount,
|
|
39748
39795
|
identity,
|
|
@@ -39764,6 +39811,7 @@ function assembleCapxulClient(input) {
|
|
|
39764
39811
|
createOrg: orgMethods.createOrg,
|
|
39765
39812
|
orgs: orgMethods.orgs,
|
|
39766
39813
|
org: orgMethods.org,
|
|
39814
|
+
signer: input.signer?.statusStore ?? UNOBSERVABLE_SIGNER_STATUS,
|
|
39767
39815
|
_internal: {
|
|
39768
39816
|
identity: identityRuntime,
|
|
39769
39817
|
bootstrap: input.bootstrap,
|
|
@@ -39772,7 +39820,7 @@ function assembleCapxulClient(input) {
|
|
|
39772
39820
|
telemetry: input.ports.telemetry,
|
|
39773
39821
|
close: stopActor
|
|
39774
39822
|
}
|
|
39775
|
-
};
|
|
39823
|
+
}, observation.failureObservation, observation.hostObservationSnapshot);
|
|
39776
39824
|
}
|
|
39777
39825
|
function withHostObservation(actor, snapshot) {
|
|
39778
39826
|
if (snapshot === void 0) return actor;
|
|
@@ -40090,16 +40138,24 @@ function refreshConvexAuthOnSession(authClient, refresh) {
|
|
|
40090
40138
|
* particular object rather than on the auth seam itself. Here it wraps
|
|
40091
40139
|
* `AuthClientPort.signOut`, so it holds for every route to a sign-out.
|
|
40092
40140
|
*
|
|
40093
|
-
*
|
|
40094
|
-
*
|
|
40095
|
-
* to `tap` would silently strand an Openfort session on the error path.
|
|
40141
|
+
* Capture the sign-out exit before reset. This preserves the old `try/finally`
|
|
40142
|
+
* order and keeps a reset failure in the typed error channel.
|
|
40096
40143
|
*/
|
|
40097
40144
|
function resetSignerSessionOnSignOut(authClient, resetRef) {
|
|
40098
40145
|
return {
|
|
40099
40146
|
...authClient,
|
|
40100
|
-
signOut: (options) =>
|
|
40101
|
-
|
|
40102
|
-
|
|
40147
|
+
signOut: (options) => Effect.gen(function* () {
|
|
40148
|
+
const exit = yield* Effect.exit(authClient.signOut(options));
|
|
40149
|
+
yield* Effect.try({
|
|
40150
|
+
try: () => resetRef.current?.(),
|
|
40151
|
+
catch: (cause) => new AuthClientError({
|
|
40152
|
+
operation: "signOut",
|
|
40153
|
+
kind: "signer",
|
|
40154
|
+
cause
|
|
40155
|
+
})
|
|
40156
|
+
});
|
|
40157
|
+
return yield* exit;
|
|
40158
|
+
})
|
|
40103
40159
|
};
|
|
40104
40160
|
}
|
|
40105
40161
|
async function createCapxulClient(input) {
|
|
@@ -40125,14 +40181,15 @@ async function createCapxulClient(input) {
|
|
|
40125
40181
|
if (signer === void 0 && runtime === "browser") signer = createOpenfortBrowserSignerFromBootstrap({
|
|
40126
40182
|
...adapters.value.bootstrap,
|
|
40127
40183
|
authBaseUrl: resolvedAuthBaseUrl
|
|
40128
|
-
}, {
|
|
40129
|
-
diagnostic: new ConsoleDiagnosticAdapter(),
|
|
40130
|
-
telemetry: adapters.value.ports.telemetry
|
|
40131
|
-
});
|
|
40184
|
+
}, { diagnostic: new ConsoleDiagnosticAdapter() });
|
|
40132
40185
|
if (signer !== void 0 && "resetSession" in signer) {
|
|
40133
|
-
const { resetSession } = signer;
|
|
40186
|
+
const { resetSession, source } = signer;
|
|
40134
40187
|
resetSignerSession.current = () => {
|
|
40135
|
-
|
|
40188
|
+
try {
|
|
40189
|
+
resetSession();
|
|
40190
|
+
} catch (cause) {
|
|
40191
|
+
throw signerFailure(source, "resetSession", cause);
|
|
40192
|
+
}
|
|
40136
40193
|
};
|
|
40137
40194
|
}
|
|
40138
40195
|
const client = assembleCapxulClient({
|
|
@@ -40150,6 +40207,7 @@ async function createCapxulClient(input) {
|
|
|
40150
40207
|
...input.signal === void 0 ? {} : { signal: input.signal },
|
|
40151
40208
|
...input.otpTtlMs === void 0 ? {} : { otpTtlMs: input.otpTtlMs },
|
|
40152
40209
|
invokeTimeoutMs: input.invokeTimeoutMs ?? 3e4,
|
|
40210
|
+
...input.observability?.failures === void 0 && input.observation === void 0 ? {} : { failureObservation: input.observability?.failures ?? input.observation },
|
|
40153
40211
|
...input.observability === void 0 ? {} : { hostObservationSnapshot: () => snapshotHostObservability(input.observability) },
|
|
40154
40212
|
effectRunner: {
|
|
40155
40213
|
runSync: Effect.runSyncWith(adapters.value.context),
|
|
@@ -40159,7 +40217,11 @@ async function createCapxulClient(input) {
|
|
|
40159
40217
|
const upstreamClose = adapters.value.close;
|
|
40160
40218
|
const close = idempotentClose(async () => {
|
|
40161
40219
|
try {
|
|
40162
|
-
if ("resetSession" in
|
|
40220
|
+
if (signer !== void 0 && "resetSession" in signer) try {
|
|
40221
|
+
signer.resetSession();
|
|
40222
|
+
} catch (cause) {
|
|
40223
|
+
throw signerFailure(signer.source, "resetSession", cause);
|
|
40224
|
+
}
|
|
40163
40225
|
} finally {
|
|
40164
40226
|
await Promise.all([client._internal.close?.(), upstreamClose()]);
|
|
40165
40227
|
}
|
|
@@ -40326,7 +40388,7 @@ function idempotentClose(close) {
|
|
|
40326
40388
|
/**
|
|
40327
40389
|
* Test/e2e-only client factory for the live Org Safe deploy lane (#327).
|
|
40328
40390
|
*
|
|
40329
|
-
* Org deployment port factories and RPC/deployer/
|
|
40391
|
+
* Org deployment port factories and RPC/deployer/bundler config must not
|
|
40330
40392
|
* appear on the public consumer or `@capxul/sdk/production` adapter input.
|
|
40331
40393
|
* Live proofs import this module explicitly instead of threading deploy
|
|
40332
40394
|
* plumbing through the product API.
|
|
@@ -42177,12 +42239,6 @@ const envFields = {
|
|
|
42177
42239
|
"required": false,
|
|
42178
42240
|
"example": "alchemy_test"
|
|
42179
42241
|
},
|
|
42180
|
-
ALCHEMY_GAS_POLICY_ID: {
|
|
42181
|
-
"runtime": "server",
|
|
42182
|
-
"kind": "nonempty",
|
|
42183
|
-
"required": false,
|
|
42184
|
-
"example": "policy_test"
|
|
42185
|
-
},
|
|
42186
42242
|
ALCHEMY_WEBHOOK_SIGNING_KEY: {
|
|
42187
42243
|
"runtime": "server",
|
|
42188
42244
|
"kind": "nonempty",
|
|
@@ -42201,6 +42257,12 @@ const envFields = {
|
|
|
42201
42257
|
"required": true,
|
|
42202
42258
|
"example": "https://sepolia.base.org"
|
|
42203
42259
|
},
|
|
42260
|
+
BASE_SEPOLIA_BUNDLER_RPC_URL: {
|
|
42261
|
+
"runtime": "server",
|
|
42262
|
+
"kind": "url",
|
|
42263
|
+
"required": false,
|
|
42264
|
+
"example": "https://aa-gateway.example.test/token"
|
|
42265
|
+
},
|
|
42204
42266
|
CONVEX_SITE_URL: {
|
|
42205
42267
|
"runtime": "server",
|
|
42206
42268
|
"kind": "url",
|
|
@@ -42295,16 +42357,15 @@ function makeBaseSepoliaPublicClient(rpcUrl) {
|
|
|
42295
42357
|
* UserOperations on Base Sepolia. Identical shape across both adapters.
|
|
42296
42358
|
*/
|
|
42297
42359
|
function makeSponsoredBundlerClient(input) {
|
|
42298
|
-
const paymaster = createPaymasterClient({ transport: http(input.
|
|
42360
|
+
const paymaster = createPaymasterClient({ transport: http(input.bundlerRpcUrl) });
|
|
42299
42361
|
return createBundlerClient({
|
|
42300
42362
|
chain: baseSepolia,
|
|
42301
42363
|
client: input.publicClient,
|
|
42302
|
-
transport: http(input.
|
|
42364
|
+
transport: http(input.bundlerRpcUrl),
|
|
42303
42365
|
paymaster: {
|
|
42304
42366
|
getPaymasterData: paymaster.getPaymasterData,
|
|
42305
42367
|
getPaymasterStubData: paymaster.getPaymasterStubData
|
|
42306
|
-
}
|
|
42307
|
-
paymasterContext: { policyId: input.gasPolicyId }
|
|
42368
|
+
}
|
|
42308
42369
|
});
|
|
42309
42370
|
}
|
|
42310
42371
|
/** Assert the RPC endpoint actually serves Base Sepolia (guards a wrong RPC URL). */
|
|
@@ -42404,14 +42465,14 @@ var LiveOrgDeploymentAdapter = class {
|
|
|
42404
42465
|
#convex;
|
|
42405
42466
|
#deployer;
|
|
42406
42467
|
#rpcUrl;
|
|
42407
|
-
#
|
|
42468
|
+
#bundlerRpcUrl;
|
|
42408
42469
|
#receiptTimeoutMs;
|
|
42409
42470
|
#sendOrgProxyDeployUserOperation;
|
|
42410
42471
|
constructor(deps) {
|
|
42411
42472
|
this.#convex = deps.convex;
|
|
42412
42473
|
this.#deployer = privateKeyToAccount(deps.privateKey);
|
|
42413
42474
|
this.#rpcUrl = deps.rpcUrl;
|
|
42414
|
-
this.#
|
|
42475
|
+
this.#bundlerRpcUrl = deps.bundlerRpcUrl;
|
|
42415
42476
|
this.#receiptTimeoutMs = deps.receiptTimeoutMs ?? DEFAULT_RECEIPT_TIMEOUT_MS;
|
|
42416
42477
|
this.#sendOrgProxyDeployUserOperation = deps.sendOrgProxyDeployUserOperation;
|
|
42417
42478
|
}
|
|
@@ -42420,7 +42481,6 @@ var LiveOrgDeploymentAdapter = class {
|
|
|
42420
42481
|
name: input.input.name,
|
|
42421
42482
|
handle: input.input.handle,
|
|
42422
42483
|
template: input.input.template,
|
|
42423
|
-
...input.input.roles === void 0 ? {} : { roles: input.input.roles },
|
|
42424
42484
|
country: input.input.country ?? null
|
|
42425
42485
|
}).pipe(Effect.mapError((error) => orgErrorFromCapxul("createOrg", error.publicError, error)), Effect.flatMap((wire) => Effect.tryPromise({
|
|
42426
42486
|
try: () => this.#deployAndRead(wire),
|
|
@@ -42549,8 +42609,7 @@ var LiveOrgDeploymentAdapter = class {
|
|
|
42549
42609
|
});
|
|
42550
42610
|
const bundler = makeSponsoredBundlerClient({
|
|
42551
42611
|
publicClient: input.publicClient,
|
|
42552
|
-
|
|
42553
|
-
gasPolicyId: this.#gasPolicyId
|
|
42612
|
+
bundlerRpcUrl: this.#bundlerRpcUrl
|
|
42554
42613
|
});
|
|
42555
42614
|
const userOpHash = await bundler.sendUserOperation({
|
|
42556
42615
|
account: founderSafe,
|
|
@@ -42560,10 +42619,12 @@ var LiveOrgDeploymentAdapter = class {
|
|
|
42560
42619
|
data: createProxyCall
|
|
42561
42620
|
}]
|
|
42562
42621
|
});
|
|
42563
|
-
|
|
42622
|
+
const receipt = await bundler.waitForUserOperationReceipt({
|
|
42564
42623
|
hash: userOpHash,
|
|
42565
42624
|
timeout: this.#receiptTimeoutMs
|
|
42566
|
-
})
|
|
42625
|
+
});
|
|
42626
|
+
if (!receipt.success) throw Errors.providerError("permissionless-org-deployment", "createProxyWithNonce", "Org Safe proxy creation UserOperation failed");
|
|
42627
|
+
await input.publicClient.waitForTransactionReceipt({ hash: receipt.receipt.transactionHash });
|
|
42567
42628
|
}
|
|
42568
42629
|
async #readBalance(publicClient, wire) {
|
|
42569
42630
|
const money = fromWei((await publicClient.readContract({
|
|
@@ -42619,12 +42680,18 @@ const BUNDLER_RPC_METHODS = new Set([
|
|
|
42619
42680
|
"eth_getUserOperationReceipt",
|
|
42620
42681
|
"eth_getUserOperationByHash",
|
|
42621
42682
|
"pm_getPaymasterStubData",
|
|
42622
|
-
"pm_getPaymasterData"
|
|
42623
|
-
"alchemy_requestGasAndPaymasterAndData"
|
|
42683
|
+
"pm_getPaymasterData"
|
|
42624
42684
|
]);
|
|
42685
|
+
function providerFor(method) {
|
|
42686
|
+
return BUNDLER_RPC_METHODS.has(method) ? "account-abstraction" : "alchemy";
|
|
42687
|
+
}
|
|
42688
|
+
function accountAbstractionUrl(chainId) {
|
|
42689
|
+
if (chainId !== 84532) throw Errors.invalidInput("chainId", `owned account-abstraction rail supports Base Sepolia; got ${String(chainId)}`);
|
|
42690
|
+
return requireEnvOrThrow("BASE_SEPOLIA_BUNDLER_RPC_URL");
|
|
42691
|
+
}
|
|
42625
42692
|
function rethrowProvider(method) {
|
|
42626
42693
|
return (e) => {
|
|
42627
|
-
throw Errors.providerError(
|
|
42694
|
+
throw Errors.providerError(providerFor(method), method, e);
|
|
42628
42695
|
};
|
|
42629
42696
|
}
|
|
42630
42697
|
function parseAlchemyQuantity(value, operation, field) {
|
|
@@ -42635,7 +42702,7 @@ function parseAlchemyQuantity(value, operation, field) {
|
|
|
42635
42702
|
}
|
|
42636
42703
|
}
|
|
42637
42704
|
function providerValue(value, pattern, operation, field) {
|
|
42638
|
-
if (typeof value !== "string" || !pattern.test(value)) throw Errors.providerError(
|
|
42705
|
+
if (typeof value !== "string" || !pattern.test(value)) throw Errors.providerError(providerFor(operation), operation, `invalid ${field}`);
|
|
42639
42706
|
return value.toLowerCase();
|
|
42640
42707
|
}
|
|
42641
42708
|
function providerAddress(value, operation, field) {
|
|
@@ -42648,9 +42715,8 @@ function providerData(value, operation, field) {
|
|
|
42648
42715
|
return providerValue(value, EVEN_DATA_HEX, operation, field);
|
|
42649
42716
|
}
|
|
42650
42717
|
/**
|
|
42651
|
-
* Construct the
|
|
42652
|
-
*
|
|
42653
|
-
* routes by method.
|
|
42718
|
+
* Construct the node RPC URL for a given chain. Account-abstraction methods
|
|
42719
|
+
* use the separate owned gateway URL.
|
|
42654
42720
|
*/
|
|
42655
42721
|
function alchemyUrl(chainId) {
|
|
42656
42722
|
switch (chainId) {
|
|
@@ -42673,14 +42739,14 @@ function isValidJsonRpcEnvelope(value) {
|
|
|
42673
42739
|
function isValidJsonRpcError(value) {
|
|
42674
42740
|
return isRecord(value) && typeof value.code === "number" && Number.isInteger(value.code) && typeof value.message === "string";
|
|
42675
42741
|
}
|
|
42676
|
-
var
|
|
42742
|
+
var DefinitiveUserOperationRpcRejection = class extends Error {
|
|
42677
42743
|
constructor() {
|
|
42678
|
-
super("
|
|
42679
|
-
this.name = "
|
|
42744
|
+
super("The bundler returned an explicit JSON-RPC rejection");
|
|
42745
|
+
this.name = "DefinitiveUserOperationRpcRejection";
|
|
42680
42746
|
}
|
|
42681
42747
|
};
|
|
42682
42748
|
async function alchemyRpc(chainId, method, params, timeoutMs, externalSignal) {
|
|
42683
|
-
const bundlerUrl =
|
|
42749
|
+
const bundlerUrl = BUNDLER_RPC_METHODS.has(method) ? accountAbstractionUrl(chainId) : void 0;
|
|
42684
42750
|
const evidenceUrl = chainId === 84532 && EVIDENCE_RPC_METHODS.has(method) ? optionalEnv("BASE_SEPOLIA_EVIDENCE_RPC_URL") : void 0;
|
|
42685
42751
|
const url = bundlerUrl?.replace(/\/+$/u, "") ?? evidenceUrl?.replace(/\/+$/u, "") ?? alchemyUrl(chainId);
|
|
42686
42752
|
const timeoutSignal = timeoutMs === void 0 ? void 0 : AbortSignal.timeout(timeoutMs);
|
|
@@ -42698,35 +42764,35 @@ async function alchemyRpc(chainId, method, params, timeoutMs, externalSignal) {
|
|
|
42698
42764
|
}).catch(rethrowProvider(method));
|
|
42699
42765
|
if (!res.ok) {
|
|
42700
42766
|
const body = await res.text().catch(() => "<no body>");
|
|
42701
|
-
throw Errors.providerError(
|
|
42767
|
+
throw Errors.providerError(providerFor(method), `${method} ${res.status}`, body);
|
|
42702
42768
|
}
|
|
42703
42769
|
let json;
|
|
42704
42770
|
try {
|
|
42705
42771
|
json = await res.json();
|
|
42706
42772
|
} catch (cause) {
|
|
42707
|
-
throw Errors.providerError(
|
|
42773
|
+
throw Errors.providerError(providerFor(method), `${method} json`, cause);
|
|
42708
42774
|
}
|
|
42709
|
-
if (!isValidJsonRpcEnvelope(json)) throw Errors.providerError(
|
|
42775
|
+
if (!isValidJsonRpcEnvelope(json)) throw Errors.providerError(providerFor(method), method, "malformed JSON-RPC envelope");
|
|
42710
42776
|
if (json.error !== void 0) {
|
|
42711
|
-
if (!isValidJsonRpcError(json.error)) throw Errors.providerError(
|
|
42712
|
-
throw Errors.providerError(
|
|
42777
|
+
if (!isValidJsonRpcError(json.error)) throw Errors.providerError(providerFor(method), method, "malformed JSON-RPC error");
|
|
42778
|
+
throw Errors.providerError(providerFor(method), method, method === "eth_sendUserOperation" ? new DefinitiveUserOperationRpcRejection() : json.error.message);
|
|
42713
42779
|
}
|
|
42714
|
-
if (json.result === void 0) throw Errors.providerError(
|
|
42780
|
+
if (json.result === void 0) throw Errors.providerError(providerFor(method), method, "missing result");
|
|
42715
42781
|
return json.result;
|
|
42716
42782
|
}
|
|
42717
42783
|
function parseReceiptLogs(raw) {
|
|
42718
42784
|
if (raw === void 0 || raw === null) return [];
|
|
42719
|
-
if (!Array.isArray(raw)) throw Errors.providerError("
|
|
42785
|
+
if (!Array.isArray(raw)) throw Errors.providerError("account-abstraction", "eth_getUserOperationReceipt", "logs is not an array");
|
|
42720
42786
|
return raw.map((entry) => {
|
|
42721
|
-
if (typeof entry !== "object" || entry === null || typeof entry.address !== "string" || !Array.isArray(entry.topics) || typeof entry.data !== "string") throw Errors.providerError("
|
|
42787
|
+
if (typeof entry !== "object" || entry === null || typeof entry.address !== "string" || !Array.isArray(entry.topics) || typeof entry.data !== "string") throw Errors.providerError("account-abstraction", "eth_getUserOperationReceipt", `malformed receipt log: ${JSON.stringify(entry)}`);
|
|
42722
42788
|
const log = entry;
|
|
42723
42789
|
const operation = "eth_getUserOperationReceipt";
|
|
42724
|
-
if (log.logIndex !== void 0 && typeof log.logIndex !== "string") throw Errors.providerError(
|
|
42725
|
-
if (log.blockNumber !== void 0 && typeof log.blockNumber !== "string") throw Errors.providerError(
|
|
42726
|
-
if (log.blockHash !== void 0 && typeof log.blockHash !== "string") throw Errors.providerError(
|
|
42727
|
-
if (log.transactionHash !== void 0 && typeof log.transactionHash !== "string") throw Errors.providerError(
|
|
42728
|
-
if (log.transactionIndex !== void 0 && typeof log.transactionIndex !== "string") throw Errors.providerError(
|
|
42729
|
-
if (log.removed !== void 0 && typeof log.removed !== "boolean") throw Errors.providerError(
|
|
42790
|
+
if (log.logIndex !== void 0 && typeof log.logIndex !== "string") throw Errors.providerError(providerFor(operation), operation, "invalid logIndex");
|
|
42791
|
+
if (log.blockNumber !== void 0 && typeof log.blockNumber !== "string") throw Errors.providerError(providerFor(operation), operation, "invalid blockNumber");
|
|
42792
|
+
if (log.blockHash !== void 0 && typeof log.blockHash !== "string") throw Errors.providerError(providerFor(operation), operation, "invalid blockHash");
|
|
42793
|
+
if (log.transactionHash !== void 0 && typeof log.transactionHash !== "string") throw Errors.providerError(providerFor(operation), operation, "invalid transactionHash");
|
|
42794
|
+
if (log.transactionIndex !== void 0 && typeof log.transactionIndex !== "string") throw Errors.providerError(providerFor(operation), operation, "invalid transactionIndex");
|
|
42795
|
+
if (log.removed !== void 0 && typeof log.removed !== "boolean") throw Errors.providerError(providerFor(operation), operation, "invalid removed");
|
|
42730
42796
|
return {
|
|
42731
42797
|
address: providerAddress(log.address, operation, "log address"),
|
|
42732
42798
|
topics: log.topics.map((topic, index) => providerBytes32(topic, operation, `topic ${String(index)}`)),
|
|
@@ -42743,7 +42809,7 @@ function parseReceiptLogs(raw) {
|
|
|
42743
42809
|
async function fetchUserOperationReceipt(args) {
|
|
42744
42810
|
const raw = await alchemyRpc(args.chainId, "eth_getUserOperationReceipt", [args.userOpHash]);
|
|
42745
42811
|
if (raw === null) return null;
|
|
42746
|
-
if (typeof raw !== "object" || typeof raw.userOpHash !== "string" || typeof raw.sender !== "string" || typeof raw.success !== "boolean" || typeof raw.receipt !== "object" || typeof raw.receipt.blockNumber !== "string" || typeof raw.receipt.blockHash !== "string" || typeof raw.receipt.transactionHash !== "string" || typeof raw.receipt.transactionIndex !== "string") throw Errors.providerError("
|
|
42812
|
+
if (typeof raw !== "object" || typeof raw.userOpHash !== "string" || typeof raw.sender !== "string" || typeof raw.success !== "boolean" || typeof raw.receipt !== "object" || typeof raw.receipt.blockNumber !== "string" || typeof raw.receipt.blockHash !== "string" || typeof raw.receipt.transactionHash !== "string" || typeof raw.receipt.transactionIndex !== "string") throw Errors.providerError("account-abstraction", "eth_getUserOperationReceipt", `unexpected shape: ${JSON.stringify(raw)}`);
|
|
42747
42813
|
return {
|
|
42748
42814
|
userOpHash: providerBytes32(raw.userOpHash, "eth_getUserOperationReceipt", "userOpHash"),
|
|
42749
42815
|
sender: providerAddress(raw.sender, "eth_getUserOperationReceipt", "sender"),
|
|
@@ -42763,15 +42829,15 @@ async function fetchUserOperationReceipt(args) {
|
|
|
42763
42829
|
* (would silently round under `parseInt` per `.claude/rules/numeric-parsing.md`).
|
|
42764
42830
|
*/
|
|
42765
42831
|
function hexToSafeInteger(hex, op) {
|
|
42766
|
-
if (typeof hex !== "string" || !QUANTITY_HEX.test(hex)) throw Errors.providerError(
|
|
42832
|
+
if (typeof hex !== "string" || !QUANTITY_HEX.test(hex)) throw Errors.providerError(providerFor(op), op, `expected a canonical hex quantity, got ${String(hex)}`);
|
|
42767
42833
|
let big;
|
|
42768
42834
|
try {
|
|
42769
42835
|
big = BigInt(hex);
|
|
42770
42836
|
} catch (cause) {
|
|
42771
|
-
throw Errors.providerError(
|
|
42837
|
+
throw Errors.providerError(providerFor(op), op, `invalid hex integer: ${hex} (${String(cause)})`);
|
|
42772
42838
|
}
|
|
42773
42839
|
const n = Number(big);
|
|
42774
|
-
if (!Number.isSafeInteger(n)) throw Errors.providerError(
|
|
42840
|
+
if (!Number.isSafeInteger(n)) throw Errors.providerError(providerFor(op), op, `hex value ${hex} exceeds MAX_SAFE_INTEGER`);
|
|
42775
42841
|
return n;
|
|
42776
42842
|
}
|
|
42777
42843
|
/**
|
|
@@ -42869,13 +42935,13 @@ async function fetchUserOperationFees(args) {
|
|
|
42869
42935
|
}
|
|
42870
42936
|
async function estimateUserOperationGas(args) {
|
|
42871
42937
|
const raw = await alchemyRpc(args.chainId, "eth_estimateUserOperationGas", [args.userOp, ENTRY_POINT_07_ADDRESS]);
|
|
42872
|
-
if (typeof raw !== "object" || typeof raw.preVerificationGas !== "string" || typeof raw.verificationGasLimit !== "string" || typeof raw.callGasLimit !== "string") throw Errors.providerError("
|
|
42938
|
+
if (typeof raw !== "object" || typeof raw.preVerificationGas !== "string" || typeof raw.verificationGasLimit !== "string" || typeof raw.callGasLimit !== "string") throw Errors.providerError("account-abstraction", "eth_estimateUserOperationGas", `unexpected shape: ${JSON.stringify(raw)}`);
|
|
42873
42939
|
return raw;
|
|
42874
42940
|
}
|
|
42875
42941
|
function optionalPaymasterHex(raw, method, field) {
|
|
42876
42942
|
const value = raw[field];
|
|
42877
42943
|
if (value === void 0) return void 0;
|
|
42878
|
-
if (typeof value !== "string" || !isHex(value)) throw Errors.providerError("
|
|
42944
|
+
if (typeof value !== "string" || !isHex(value)) throw Errors.providerError("account-abstraction", method, `unexpected ${field}: expected hex string`);
|
|
42879
42945
|
return value;
|
|
42880
42946
|
}
|
|
42881
42947
|
function definedPaymasterFields(result) {
|
|
@@ -42886,19 +42952,14 @@ function definedPaymasterFields(result) {
|
|
|
42886
42952
|
...result.paymasterPostOpGasLimit === void 0 ? {} : { paymasterPostOpGasLimit: result.paymasterPostOpGasLimit }
|
|
42887
42953
|
};
|
|
42888
42954
|
}
|
|
42889
|
-
function requiredRpcHex(raw, method, field) {
|
|
42890
|
-
const value = raw[field];
|
|
42891
|
-
if (typeof value !== "string" || !isHex(value)) throw Errors.providerError("alchemy", method, `unexpected ${field}: expected hex string`);
|
|
42892
|
-
return value;
|
|
42893
|
-
}
|
|
42894
42955
|
async function paymasterRpc(method, args) {
|
|
42895
42956
|
const raw = await alchemyRpc(args.chainId, method, [
|
|
42896
42957
|
args.userOp,
|
|
42897
42958
|
ENTRY_POINT_07_ADDRESS,
|
|
42898
42959
|
toHex(args.chainId),
|
|
42899
|
-
{
|
|
42960
|
+
{}
|
|
42900
42961
|
]);
|
|
42901
|
-
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) throw Errors.providerError("
|
|
42962
|
+
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) throw Errors.providerError("account-abstraction", method, `unexpected shape: ${JSON.stringify(raw)}`);
|
|
42902
42963
|
const result = raw;
|
|
42903
42964
|
const paymaster = optionalPaymasterHex(result, method, "paymaster");
|
|
42904
42965
|
const paymasterData = optionalPaymasterHex(result, method, "paymasterData");
|
|
@@ -42919,40 +42980,8 @@ function getPaymasterStubData(args) {
|
|
|
42919
42980
|
function getPaymasterData(args) {
|
|
42920
42981
|
return paymasterRpc("pm_getPaymasterData", args);
|
|
42921
42982
|
}
|
|
42922
|
-
/**
|
|
42923
|
-
async function requestGasAndPaymasterAndData(args) {
|
|
42924
|
-
const { signature, ...userOperation } = args.userOp;
|
|
42925
|
-
const method = "alchemy_requestGasAndPaymasterAndData";
|
|
42926
|
-
const raw = await alchemyRpc(args.chainId, method, [{
|
|
42927
|
-
policyId: args.policyId,
|
|
42928
|
-
entryPoint: ENTRY_POINT_07_ADDRESS,
|
|
42929
|
-
dummySignature: signature,
|
|
42930
|
-
userOperation
|
|
42931
|
-
}]);
|
|
42932
|
-
if (!isRecord(raw)) throw Errors.providerError("alchemy", method, `unexpected shape: ${JSON.stringify(raw)}`);
|
|
42933
|
-
const paymaster = optionalPaymasterHex(raw, method, "paymaster");
|
|
42934
|
-
const paymasterData = optionalPaymasterHex(raw, method, "paymasterData");
|
|
42935
|
-
if (paymaster === void 0 || paymasterData === void 0) throw Errors.providerError("alchemy", method, "missing paymaster sponsorship");
|
|
42936
|
-
const paymasterVerificationGasLimit = optionalPaymasterHex(raw, method, "paymasterVerificationGasLimit");
|
|
42937
|
-
const paymasterPostOpGasLimit = optionalPaymasterHex(raw, method, "paymasterPostOpGasLimit");
|
|
42938
|
-
return {
|
|
42939
|
-
paymaster,
|
|
42940
|
-
paymasterData,
|
|
42941
|
-
preVerificationGas: requiredRpcHex(raw, method, "preVerificationGas"),
|
|
42942
|
-
verificationGasLimit: requiredRpcHex(raw, method, "verificationGasLimit"),
|
|
42943
|
-
callGasLimit: requiredRpcHex(raw, method, "callGasLimit"),
|
|
42944
|
-
maxFeePerGas: requiredRpcHex(raw, method, "maxFeePerGas"),
|
|
42945
|
-
maxPriorityFeePerGas: requiredRpcHex(raw, method, "maxPriorityFeePerGas"),
|
|
42946
|
-
...paymasterVerificationGasLimit === void 0 ? {} : { paymasterVerificationGasLimit },
|
|
42947
|
-
...paymasterPostOpGasLimit === void 0 ? {} : { paymasterPostOpGasLimit }
|
|
42948
|
-
};
|
|
42949
|
-
}
|
|
42950
|
-
/** Select the hosted BSO method or the devnet ERC-7677 flow. */
|
|
42983
|
+
/** Sponsor one Base Sepolia UserOperation through the owned ERC-7677 gateway. */
|
|
42951
42984
|
async function sponsorUserOperation(args) {
|
|
42952
|
-
if (args.chainId !== 84532 || optionalEnv("BASE_SEPOLIA_BUNDLER_RPC_URL") === void 0) return {
|
|
42953
|
-
...args.userOp,
|
|
42954
|
-
...await requestGasAndPaymasterAndData(args)
|
|
42955
|
-
};
|
|
42956
42985
|
let request = args.userOp;
|
|
42957
42986
|
request = {
|
|
42958
42987
|
...request,
|
|
@@ -42982,7 +43011,7 @@ async function sponsorUserOperation(args) {
|
|
|
42982
43011
|
userOp: request
|
|
42983
43012
|
}))
|
|
42984
43013
|
};
|
|
42985
|
-
if (request.paymaster === void 0 || request.paymasterData === void 0) throw Errors.providerError("
|
|
43014
|
+
if (request.paymaster === void 0 || request.paymasterData === void 0) throw Errors.providerError("account-abstraction", "pm_getPaymasterData", "missing paymaster sponsorship");
|
|
42986
43015
|
return {
|
|
42987
43016
|
...request,
|
|
42988
43017
|
paymaster: request.paymaster,
|
|
@@ -42992,17 +43021,17 @@ async function sponsorUserOperation(args) {
|
|
|
42992
43021
|
/** Submit the signed UserOperation through the bundler — returns the userOpHash. */
|
|
42993
43022
|
async function sendUserOperation(args) {
|
|
42994
43023
|
const hash = await alchemyRpc(args.chainId, "eth_sendUserOperation", [args.userOp, ENTRY_POINT_07_ADDRESS]);
|
|
42995
|
-
if (typeof hash !== "string" || !TX_HASH_HEX.test(hash)) throw Errors.providerError("
|
|
43024
|
+
if (typeof hash !== "string" || !TX_HASH_HEX.test(hash)) throw Errors.providerError("account-abstraction", "eth_sendUserOperation", `unexpected hash: ${String(hash)}; expected 0x-prefixed 32-byte hex`);
|
|
42996
43025
|
return hash;
|
|
42997
43026
|
}
|
|
42998
43027
|
//#endregion
|
|
42999
43028
|
//#region ../../packages/backend/convex/smartAccount/deploy.ts
|
|
43000
43029
|
function rpcQuantityToBigInt(value, field) {
|
|
43001
|
-
if (!/^0x[0-9a-fA-F]+$/.test(value)) throw Errors.providerError("
|
|
43030
|
+
if (!/^0x[0-9a-fA-F]+$/.test(value)) throw Errors.providerError("account-abstraction", "buildDeploymentUserOp", `invalid ${field} hex: ${value}`);
|
|
43002
43031
|
try {
|
|
43003
43032
|
return BigInt(value);
|
|
43004
43033
|
} catch (cause) {
|
|
43005
|
-
throw Errors.providerError("
|
|
43034
|
+
throw Errors.providerError("account-abstraction", "buildDeploymentUserOp", `invalid ${field} hex: ${value} (${String(cause)})`);
|
|
43006
43035
|
}
|
|
43007
43036
|
}
|
|
43008
43037
|
/** Attach the packed owner signature to a wire UserOp for the bundler RPC. */
|
|
@@ -43032,7 +43061,7 @@ function toRpcUserOp(op, signature) {
|
|
|
43032
43061
|
* which passes v1-pinned owner factory args).
|
|
43033
43062
|
*/
|
|
43034
43063
|
async function buildSponsoredSafeUserOp(input) {
|
|
43035
|
-
const { chainId, sender, factoryArgs, callData
|
|
43064
|
+
const { chainId, sender, factoryArgs, callData } = input;
|
|
43036
43065
|
const nonce = await fetchEntryPointNonce({
|
|
43037
43066
|
chainId,
|
|
43038
43067
|
sender
|
|
@@ -43055,10 +43084,9 @@ async function buildSponsoredSafeUserOp(input) {
|
|
|
43055
43084
|
};
|
|
43056
43085
|
request = await sponsorUserOperation({
|
|
43057
43086
|
chainId,
|
|
43058
|
-
userOp: request
|
|
43059
|
-
policyId
|
|
43087
|
+
userOp: request
|
|
43060
43088
|
});
|
|
43061
|
-
if (request.paymaster === void 0 || request.paymasterData === void 0) throw Errors.providerError("
|
|
43089
|
+
if (request.paymaster === void 0 || request.paymasterData === void 0) throw Errors.providerError("account-abstraction", "sponsorUserOperation", "missing paymaster sponsorship");
|
|
43062
43090
|
const userOp = {
|
|
43063
43091
|
sender,
|
|
43064
43092
|
nonce: toHex(nonce),
|
|
@@ -43206,8 +43234,7 @@ function makeSettlementPort(route) {
|
|
|
43206
43234
|
const built = await maybeMapRevert(() => buildUserOp({
|
|
43207
43235
|
chainId,
|
|
43208
43236
|
sender: safeAddress,
|
|
43209
|
-
callData: input.callData
|
|
43210
|
-
policyId: input.policyId
|
|
43237
|
+
callData: input.callData
|
|
43211
43238
|
}), input.method, mapReverts);
|
|
43212
43239
|
const packedSignature = packSafe4337OwnerSignature({ signature: await input.signer.signUserOpHash(built.digest) });
|
|
43213
43240
|
const userOpHash = await maybeMapRevert(() => submitUserOp({
|
|
@@ -43233,8 +43260,8 @@ function makeSettlementPort(route) {
|
|
|
43233
43260
|
};
|
|
43234
43261
|
}
|
|
43235
43262
|
if (Date.now() > deadline) {
|
|
43236
|
-
if (mapReverts) throw Errors.providerTimeout("
|
|
43237
|
-
throw Errors.providerError("
|
|
43263
|
+
if (mapReverts) throw Errors.providerTimeout("account-abstraction", "eth_getUserOperationReceipt", waitReceiptMs);
|
|
43264
|
+
throw Errors.providerError("account-abstraction", "eth_getUserOperationReceipt", "receipt timeout");
|
|
43238
43265
|
}
|
|
43239
43266
|
await sleep(pollIntervalMs);
|
|
43240
43267
|
}
|
|
@@ -43287,7 +43314,6 @@ async function submitFromMemberSafe(input) {
|
|
|
43287
43314
|
const submitted = await (input.deps.port ?? directBaseSettlementPort()).submitAndConfirm({
|
|
43288
43315
|
signer: input.deps.signer,
|
|
43289
43316
|
payerEmail: input.email,
|
|
43290
|
-
policyId: input.deps.policyId,
|
|
43291
43317
|
callData: input.callData,
|
|
43292
43318
|
method: input.operation,
|
|
43293
43319
|
mapReverts: true,
|
|
@@ -43334,6 +43360,7 @@ function toMcpRoleView(view) {
|
|
|
43334
43360
|
perTxCap: toMcpMoney(spend?.perTx),
|
|
43335
43361
|
perDayCap: toMcpMoney(spend?.perDay),
|
|
43336
43362
|
recipientScope,
|
|
43363
|
+
canSpend: view.definition.canSpend === true || spend !== void 0,
|
|
43337
43364
|
canManageMembers: view.definition.canManageMembers ?? false,
|
|
43338
43365
|
canManageRoles: view.definition.canManageRoles ?? false
|
|
43339
43366
|
};
|
|
@@ -43593,9 +43620,10 @@ function makeSdkClientFactory(config, options = { mode: { mode: "live" } }) {
|
|
|
43593
43620
|
actorRequestsGet: (actor, requestId) => actorBundle(client, actor).requests.get(requestId),
|
|
43594
43621
|
actorRequestsCancel: (actor, requestId) => actorBundle(client, actor).requests.cancel(requestId),
|
|
43595
43622
|
inboxList: (actor) => actorBundle(client, actor).inbox.list(),
|
|
43596
|
-
inboxApprove: (actor, requestId, timing) => actorBundle(client, actor).inbox.approve({
|
|
43623
|
+
inboxApprove: (actor, requestId, timing, permissionId) => actorBundle(client, actor).inbox.approve({
|
|
43597
43624
|
requestId,
|
|
43598
|
-
...timing === void 0 ? {} : { timing }
|
|
43625
|
+
...timing === void 0 ? {} : { timing },
|
|
43626
|
+
...permissionId === void 0 ? {} : { permissionId }
|
|
43599
43627
|
}),
|
|
43600
43628
|
inboxDecline: (actor, requestId) => actorBundle(client, actor).inbox.decline(requestId),
|
|
43601
43629
|
addDestination: (input) => client.destinations.add({
|
|
@@ -43618,7 +43646,7 @@ function makeSdkClientFactory(config, options = { mode: { mode: "live" } }) {
|
|
|
43618
43646
|
const res = await client.createOrg({
|
|
43619
43647
|
name: input.name,
|
|
43620
43648
|
handle: input.handle,
|
|
43621
|
-
template:
|
|
43649
|
+
template: "Solo",
|
|
43622
43650
|
...input.country === void 0 ? {} : { country: input.country }
|
|
43623
43651
|
});
|
|
43624
43652
|
return res.ok ? {
|
|
@@ -43645,16 +43673,12 @@ function makeSdkClientFactory(config, options = { mode: { mode: "live" } }) {
|
|
|
43645
43673
|
};
|
|
43646
43674
|
}
|
|
43647
43675
|
function buildDevOrgPort(input) {
|
|
43648
|
-
const gasPolicyId = requireDevEnv(input.env, "ALCHEMY_GAS_POLICY_ID");
|
|
43649
43676
|
return new LiveOrgDeploymentAdapter({
|
|
43650
43677
|
convex: input.convex,
|
|
43651
43678
|
privateKey: requireDevEnv(input.env, "DEPLOYER_PRIVATE_KEY"),
|
|
43652
43679
|
rpcUrl: requireDevEnv(input.env, "BASE_SEPOLIA_RPC_URL"),
|
|
43653
|
-
|
|
43654
|
-
sendOrgProxyDeployUserOperation: makeDevSignerOrgProxyDeploySender({
|
|
43655
|
-
signer: input.signer,
|
|
43656
|
-
policyId: gasPolicyId
|
|
43657
|
-
})
|
|
43680
|
+
bundlerRpcUrl: requireDevEnv(input.env, "BASE_SEPOLIA_BUNDLER_RPC_URL"),
|
|
43681
|
+
sendOrgProxyDeployUserOperation: makeDevSignerOrgProxyDeploySender({ signer: input.signer })
|
|
43658
43682
|
});
|
|
43659
43683
|
}
|
|
43660
43684
|
function requireDevEnv(env, name) {
|
|
@@ -43664,7 +43688,7 @@ function requireDevEnv(env, name) {
|
|
|
43664
43688
|
}
|
|
43665
43689
|
/** True iff the on-chain org-deployment seam env is fully present. */
|
|
43666
43690
|
function hasOrgDeploymentEnv(env) {
|
|
43667
|
-
return (env.DEPLOYER_PRIVATE_KEY?.trim().length ?? 0) > 0 && (env.BASE_SEPOLIA_RPC_URL?.trim().length ?? 0) > 0 && (env.
|
|
43691
|
+
return (env.DEPLOYER_PRIVATE_KEY?.trim().length ?? 0) > 0 && (env.BASE_SEPOLIA_RPC_URL?.trim().length ?? 0) > 0 && (env.BASE_SEPOLIA_BUNDLER_RPC_URL?.trim().length ?? 0) > 0;
|
|
43668
43692
|
}
|
|
43669
43693
|
function createDevSignerSessionStorage() {
|
|
43670
43694
|
const values = /* @__PURE__ */ new Map();
|