@capxul/mcp 2.1.0 → 2.2.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 +844 -965
- 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.2.0";
|
|
244
244
|
//#endregion
|
|
245
245
|
//#region ../../packages/errors/src/errors.ts
|
|
246
246
|
const CAPXUL_ERROR_CODES = [
|
|
@@ -492,8 +492,6 @@ function isExactTransferTokenAllowed(tokenAddress) {
|
|
|
492
492
|
//#region ../../packages/config/src/org-payments.ts
|
|
493
493
|
/** Zodiac MultiSendCallOnly module on Base Sepolia. */
|
|
494
494
|
const MULTI_SEND_CALL_ONLY = "0x9641d764fc13c8b624c04430c7356c1c7c8102e2";
|
|
495
|
-
/** CapxulPayments proxy on Base Sepolia. */
|
|
496
|
-
const CAPXUL_PAYMENTS_ADDRESS = "0xe740ea65521edc9bef0ea75d30b5334711db99f4";
|
|
497
495
|
const SAFE4337_EXECUTE_USEROP_ABI = [{
|
|
498
496
|
type: "function",
|
|
499
497
|
name: "executeUserOpWithErrorString",
|
|
@@ -523,12 +521,7 @@ function normalizeAddress(address, field) {
|
|
|
523
521
|
if (!isAddress(address)) throw new RangeError(`${field} must be a valid EVM address`);
|
|
524
522
|
return address.toLowerCase();
|
|
525
523
|
}
|
|
526
|
-
/**
|
|
527
|
-
* Wrap an org Roles `execTransactionWithRole` call (from `*RoleSpendCall` /
|
|
528
|
-
* `*RoleBatchSpendCall`) into the member Safe's `executeUserOpWithErrorString`
|
|
529
|
-
* (operation = CALL into the Roles module) — the full Safe callData a sponsored
|
|
530
|
-
* UserOp from the member's personal Safe carries (G4 · #547).
|
|
531
|
-
*/
|
|
524
|
+
/** Wrap a Zodiac Roles call for a member Safe. */
|
|
532
525
|
function buildOrgRoleSpendPersonalCallData(roleSpendCall) {
|
|
533
526
|
return encodeFunctionData({
|
|
534
527
|
abi: SAFE4337_EXECUTE_USEROP_ABI,
|
|
@@ -541,162 +534,6 @@ function buildOrgRoleSpendPersonalCallData(roleSpendCall) {
|
|
|
541
534
|
]
|
|
542
535
|
});
|
|
543
536
|
}
|
|
544
|
-
const CAPXUL_PAYMENTS_COMMITMENT_ABI = [
|
|
545
|
-
{
|
|
546
|
-
type: "function",
|
|
547
|
-
name: "createCommitment",
|
|
548
|
-
stateMutability: "nonpayable",
|
|
549
|
-
inputs: [
|
|
550
|
-
{
|
|
551
|
-
name: "token",
|
|
552
|
-
type: "address"
|
|
553
|
-
},
|
|
554
|
-
{
|
|
555
|
-
name: "recipient",
|
|
556
|
-
type: "address"
|
|
557
|
-
},
|
|
558
|
-
{
|
|
559
|
-
name: "totalAmount",
|
|
560
|
-
type: "uint256"
|
|
561
|
-
},
|
|
562
|
-
{
|
|
563
|
-
name: "startTime",
|
|
564
|
-
type: "uint48"
|
|
565
|
-
},
|
|
566
|
-
{
|
|
567
|
-
name: "cliffTime",
|
|
568
|
-
type: "uint48"
|
|
569
|
-
},
|
|
570
|
-
{
|
|
571
|
-
name: "endTime",
|
|
572
|
-
type: "uint48"
|
|
573
|
-
},
|
|
574
|
-
{
|
|
575
|
-
name: "documentHash",
|
|
576
|
-
type: "bytes32"
|
|
577
|
-
},
|
|
578
|
-
{
|
|
579
|
-
name: "paymentType",
|
|
580
|
-
type: "uint8"
|
|
581
|
-
}
|
|
582
|
-
],
|
|
583
|
-
outputs: [{
|
|
584
|
-
name: "commitmentId",
|
|
585
|
-
type: "uint256"
|
|
586
|
-
}]
|
|
587
|
-
},
|
|
588
|
-
{
|
|
589
|
-
type: "function",
|
|
590
|
-
name: "claim",
|
|
591
|
-
stateMutability: "nonpayable",
|
|
592
|
-
inputs: [{
|
|
593
|
-
name: "commitmentId",
|
|
594
|
-
type: "uint256"
|
|
595
|
-
}],
|
|
596
|
-
outputs: []
|
|
597
|
-
},
|
|
598
|
-
{
|
|
599
|
-
type: "function",
|
|
600
|
-
name: "cancel",
|
|
601
|
-
stateMutability: "nonpayable",
|
|
602
|
-
inputs: [{
|
|
603
|
-
name: "commitmentId",
|
|
604
|
-
type: "uint256"
|
|
605
|
-
}, {
|
|
606
|
-
name: "documentHash",
|
|
607
|
-
type: "bytes32"
|
|
608
|
-
}],
|
|
609
|
-
outputs: []
|
|
610
|
-
},
|
|
611
|
-
{
|
|
612
|
-
type: "function",
|
|
613
|
-
name: "redirect",
|
|
614
|
-
stateMutability: "nonpayable",
|
|
615
|
-
inputs: [
|
|
616
|
-
{
|
|
617
|
-
name: "commitmentId",
|
|
618
|
-
type: "uint256"
|
|
619
|
-
},
|
|
620
|
-
{
|
|
621
|
-
name: "newRecipient",
|
|
622
|
-
type: "address"
|
|
623
|
-
},
|
|
624
|
-
{
|
|
625
|
-
name: "newDocumentHash",
|
|
626
|
-
type: "bytes32"
|
|
627
|
-
}
|
|
628
|
-
],
|
|
629
|
-
outputs: []
|
|
630
|
-
},
|
|
631
|
-
{
|
|
632
|
-
type: "function",
|
|
633
|
-
name: "claimableAmount",
|
|
634
|
-
stateMutability: "view",
|
|
635
|
-
inputs: [{
|
|
636
|
-
name: "commitmentId",
|
|
637
|
-
type: "uint256"
|
|
638
|
-
}],
|
|
639
|
-
outputs: [{
|
|
640
|
-
name: "",
|
|
641
|
-
type: "uint256"
|
|
642
|
-
}]
|
|
643
|
-
},
|
|
644
|
-
{
|
|
645
|
-
type: "function",
|
|
646
|
-
name: "commitments",
|
|
647
|
-
stateMutability: "view",
|
|
648
|
-
inputs: [{
|
|
649
|
-
name: "",
|
|
650
|
-
type: "uint256"
|
|
651
|
-
}],
|
|
652
|
-
outputs: [
|
|
653
|
-
{
|
|
654
|
-
name: "creator",
|
|
655
|
-
type: "address"
|
|
656
|
-
},
|
|
657
|
-
{
|
|
658
|
-
name: "token",
|
|
659
|
-
type: "address"
|
|
660
|
-
},
|
|
661
|
-
{
|
|
662
|
-
name: "recipient",
|
|
663
|
-
type: "address"
|
|
664
|
-
},
|
|
665
|
-
{
|
|
666
|
-
name: "totalAmount",
|
|
667
|
-
type: "uint256"
|
|
668
|
-
},
|
|
669
|
-
{
|
|
670
|
-
name: "claimed",
|
|
671
|
-
type: "uint256"
|
|
672
|
-
},
|
|
673
|
-
{
|
|
674
|
-
name: "startTime",
|
|
675
|
-
type: "uint48"
|
|
676
|
-
},
|
|
677
|
-
{
|
|
678
|
-
name: "cliffTime",
|
|
679
|
-
type: "uint48"
|
|
680
|
-
},
|
|
681
|
-
{
|
|
682
|
-
name: "endTime",
|
|
683
|
-
type: "uint48"
|
|
684
|
-
},
|
|
685
|
-
{
|
|
686
|
-
name: "documentHash",
|
|
687
|
-
type: "bytes32"
|
|
688
|
-
},
|
|
689
|
-
{
|
|
690
|
-
name: "paymentType",
|
|
691
|
-
type: "uint8"
|
|
692
|
-
},
|
|
693
|
-
{
|
|
694
|
-
name: "cancelled",
|
|
695
|
-
type: "bool"
|
|
696
|
-
}
|
|
697
|
-
]
|
|
698
|
-
}
|
|
699
|
-
];
|
|
700
537
|
//#endregion
|
|
701
538
|
//#region ../../packages/config/src/safe.ts
|
|
702
539
|
const BASE_SEPOLIA_CHAIN_ID = 84532;
|
|
@@ -1048,348 +885,6 @@ function normalizeBindingEmail(email) {
|
|
|
1048
885
|
return normalizeSafeSaltEmail(email);
|
|
1049
886
|
}
|
|
1050
887
|
//#endregion
|
|
1051
|
-
//#region ../../packages/config/src/route.ts
|
|
1052
|
-
/** USDX on Base Sepolia — the only settlement token in v1. */
|
|
1053
|
-
const USDX_BASE_SEPOLIA_TOKEN = {
|
|
1054
|
-
chainId: BASE_SEPOLIA_CHAIN_ID,
|
|
1055
|
-
address: USDX_ADDRESS_BASE_SEPOLIA,
|
|
1056
|
-
decimals: 6
|
|
1057
|
-
};
|
|
1058
|
-
/**
|
|
1059
|
-
* The `direct-base` settlement route: USDX on Base Sepolia, settled directly
|
|
1060
|
-
* through the `CapxulPayments` contract. This is the ONLY route implemented in
|
|
1061
|
-
* D1; the `Route` shape is the seam future provider routes slot into.
|
|
1062
|
-
*/
|
|
1063
|
-
const DIRECT_BASE_ROUTE = {
|
|
1064
|
-
kind: "direct-base",
|
|
1065
|
-
token: USDX_BASE_SEPOLIA_TOKEN,
|
|
1066
|
-
chainId: USDX_BASE_SEPOLIA_TOKEN.chainId,
|
|
1067
|
-
verifyingContract: CAPXUL_PAYMENTS_ADDRESS
|
|
1068
|
-
};
|
|
1069
|
-
USDX_BASE_SEPOLIA_TOKEN.chainId;
|
|
1070
|
-
const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
1071
|
-
const ORG_HANDLE_REGEX = /^[a-z0-9-]{3,32}$/;
|
|
1072
|
-
const ADDRESS_REGEX = /^0x[0-9a-f]{40}$/;
|
|
1073
|
-
const safeSetupAbi = [{
|
|
1074
|
-
type: "function",
|
|
1075
|
-
name: "setup",
|
|
1076
|
-
stateMutability: "nonpayable",
|
|
1077
|
-
inputs: [
|
|
1078
|
-
{
|
|
1079
|
-
name: "_owners",
|
|
1080
|
-
type: "address[]"
|
|
1081
|
-
},
|
|
1082
|
-
{
|
|
1083
|
-
name: "_threshold",
|
|
1084
|
-
type: "uint256"
|
|
1085
|
-
},
|
|
1086
|
-
{
|
|
1087
|
-
name: "to",
|
|
1088
|
-
type: "address"
|
|
1089
|
-
},
|
|
1090
|
-
{
|
|
1091
|
-
name: "data",
|
|
1092
|
-
type: "bytes"
|
|
1093
|
-
},
|
|
1094
|
-
{
|
|
1095
|
-
name: "fallbackHandler",
|
|
1096
|
-
type: "address"
|
|
1097
|
-
},
|
|
1098
|
-
{
|
|
1099
|
-
name: "paymentToken",
|
|
1100
|
-
type: "address"
|
|
1101
|
-
},
|
|
1102
|
-
{
|
|
1103
|
-
name: "payment",
|
|
1104
|
-
type: "uint256"
|
|
1105
|
-
},
|
|
1106
|
-
{
|
|
1107
|
-
name: "paymentReceiver",
|
|
1108
|
-
type: "address"
|
|
1109
|
-
}
|
|
1110
|
-
],
|
|
1111
|
-
outputs: []
|
|
1112
|
-
}];
|
|
1113
|
-
const enableModulesAbi$1 = [{
|
|
1114
|
-
type: "function",
|
|
1115
|
-
name: "enableModules",
|
|
1116
|
-
stateMutability: "nonpayable",
|
|
1117
|
-
inputs: [{
|
|
1118
|
-
name: "modules",
|
|
1119
|
-
type: "address[]"
|
|
1120
|
-
}],
|
|
1121
|
-
outputs: []
|
|
1122
|
-
}];
|
|
1123
|
-
const multiSendAbi$1 = [{
|
|
1124
|
-
type: "function",
|
|
1125
|
-
name: "multiSend",
|
|
1126
|
-
stateMutability: "payable",
|
|
1127
|
-
inputs: [{
|
|
1128
|
-
name: "transactions",
|
|
1129
|
-
type: "bytes"
|
|
1130
|
-
}],
|
|
1131
|
-
outputs: []
|
|
1132
|
-
}];
|
|
1133
|
-
/**
|
|
1134
|
-
* Normalize an org handle for both salting and storage (D10a — trim +
|
|
1135
|
-
* lowercase). Idempotent: `normalizeOrgHandle(normalizeOrgHandle(x)) ===
|
|
1136
|
-
* normalizeOrgHandle(x)`.
|
|
1137
|
-
*
|
|
1138
|
-
* @param handle - The raw org handle
|
|
1139
|
-
* @returns The trimmed, lowercased handle
|
|
1140
|
-
*/
|
|
1141
|
-
function normalizeOrgHandle(handle) {
|
|
1142
|
-
return handle.trim().toLowerCase();
|
|
1143
|
-
}
|
|
1144
|
-
/**
|
|
1145
|
-
* Validate an org handle against the D10a rule `^[a-z0-9-]{3,32}$` over its
|
|
1146
|
-
* NORMALIZED form. Returns the normalized handle on success; throws a typed
|
|
1147
|
-
* `INVALID_INPUT` `CapxulError` (field `orgHandle`) on failure — never a raw
|
|
1148
|
-
* `Error`, so SDK / backend boundary handlers can route on the code.
|
|
1149
|
-
*
|
|
1150
|
-
* @param handle - The raw org handle
|
|
1151
|
-
* @returns The normalized, validated handle
|
|
1152
|
-
*/
|
|
1153
|
-
function validateOrgHandle(handle) {
|
|
1154
|
-
const normalized = normalizeOrgHandle(handle);
|
|
1155
|
-
if (!ORG_HANDLE_REGEX.test(normalized)) throw Errors.invalidInput("orgHandle", `must match ^[a-z0-9-]{3,32}$ after trim+lowercase, got ${handle}`);
|
|
1156
|
-
return normalized;
|
|
1157
|
-
}
|
|
1158
|
-
/**
|
|
1159
|
-
* Compute the deterministic Org Safe salt nonce for a `(namespace, email,
|
|
1160
|
-
* orgHandle)` triple (D10a). The salt nonce is the `bigint` reading of
|
|
1161
|
-
* `keccak256(namespace + ":" + normalizeSafeSaltEmail(email) + ":" +
|
|
1162
|
-
* normalizeOrgHandle(orgHandle))`.
|
|
1163
|
-
*
|
|
1164
|
-
* Keyed on email + handle, NOT the signer — so the Org address survives signer
|
|
1165
|
-
* rotation (D7). Namespace defaults to `CAPXUL_ORG_SALT_NAMESPACE`.
|
|
1166
|
-
*
|
|
1167
|
-
* @param input.email - The founder email to derive the salt nonce from
|
|
1168
|
-
* @param input.orgHandle - The org handle (normalized internally)
|
|
1169
|
-
* @param input.namespace - Optional namespace override
|
|
1170
|
-
* @returns The Capxul-namespaced Org salt nonce as a `bigint`
|
|
1171
|
-
*/
|
|
1172
|
-
function computeCapxulOrgSaltNonce(input) {
|
|
1173
|
-
const namespace = input.namespace ?? "capxul:org:v1";
|
|
1174
|
-
const normalizedEmail = normalizeSafeSaltEmail(input.email);
|
|
1175
|
-
const normalizedHandle = normalizeOrgHandle(input.orgHandle);
|
|
1176
|
-
return BigInt(keccak256(toBytes(`${namespace}:${normalizedEmail}:${normalizedHandle}`)));
|
|
1177
|
-
}
|
|
1178
|
-
/**
|
|
1179
|
-
* Pure derivation of the Org Safe v1.4.1 (SafeL2) + 4337-module-enabled
|
|
1180
|
-
* counterfactual address for a Capxul `(founderPersonalSafe, email, orgHandle)`
|
|
1181
|
-
* triple (D10a). Mirrors `deriveCapxulSafeAddress` byte-for-byte except the salt
|
|
1182
|
-
* nonce (Org-namespaced, keyed on email+handle) and the initializer owner
|
|
1183
|
-
* (the founder's PERSONAL Safe address, passed in directly — D7).
|
|
1184
|
-
*
|
|
1185
|
-
* Returns the lowercased `0x` + 40 hex string (raw — no brand applied; callers
|
|
1186
|
-
* brand at their own boundary). Throws a typed `INVALID_INPUT` `CapxulError`
|
|
1187
|
-
* (field `orgHandle`) if the handle is malformed.
|
|
1188
|
-
*
|
|
1189
|
-
* Canonical conformance: `packages/config/tests/org-safe-address-conformance.test.ts`
|
|
1190
|
-
* pins the matrix against Safes actually deployed on Base Sepolia.
|
|
1191
|
-
*/
|
|
1192
|
-
/**
|
|
1193
|
-
* Build the EXACT Org Safe `setup()` initializer calldata (D10a). This is the
|
|
1194
|
-
* single source of truth for the initializer bytes: `deriveCapxulOrgAddress`
|
|
1195
|
-
* hashes it into the CREATE2 salt, and the live Org deploy adapter passes the
|
|
1196
|
-
* IDENTICAL bytes to `SafeProxyFactory.createProxyWithNonce` — so the deployed
|
|
1197
|
-
* address provably equals the counterfactual byte-for-byte.
|
|
1198
|
-
*
|
|
1199
|
-
* `setup([founderPersonalSafe], 1, MULTI_SEND, <enableModules([SAFE_4337_MODULE])
|
|
1200
|
-
* MultiSend>, SAFE_4337_MODULE, 0, 0, 0)` — owner is the founder's PERSONAL Safe
|
|
1201
|
-
* (D7), the 4337 module is enabled via the same MultiSend lane as the personal
|
|
1202
|
-
* Safe. NO Zodiac Roles / Allowance at setup() (S1 decision A — those land in S2).
|
|
1203
|
-
*
|
|
1204
|
-
* Validates (and lowercases) `founderPersonalSafe`; throws a typed INVALID_INPUT
|
|
1205
|
-
* (`founderPersonalSafe`) on a malformed address.
|
|
1206
|
-
*
|
|
1207
|
-
* @param input.founderPersonalSafe - The founder's personal Safe address (owner)
|
|
1208
|
-
* @returns The `0x`-prefixed `setup()` calldata
|
|
1209
|
-
*/
|
|
1210
|
-
function buildCapxulOrgInitializer(input) {
|
|
1211
|
-
const founderPersonalSafe = input.founderPersonalSafe.toLowerCase();
|
|
1212
|
-
if (!ADDRESS_REGEX.test(founderPersonalSafe)) throw Errors.invalidInput("founderPersonalSafe", `must be 0x + 40 hex chars, got ${input.founderPersonalSafe}`);
|
|
1213
|
-
const enableModulesCall = encodeFunctionData({
|
|
1214
|
-
abi: enableModulesAbi$1,
|
|
1215
|
-
functionName: "enableModules",
|
|
1216
|
-
args: [[SAFE_4337_MODULE]]
|
|
1217
|
-
});
|
|
1218
|
-
const setupData = encodeFunctionData({
|
|
1219
|
-
abi: multiSendAbi$1,
|
|
1220
|
-
functionName: "multiSend",
|
|
1221
|
-
args: [encodePacked([
|
|
1222
|
-
"uint8",
|
|
1223
|
-
"address",
|
|
1224
|
-
"uint256",
|
|
1225
|
-
"uint256",
|
|
1226
|
-
"bytes"
|
|
1227
|
-
], [
|
|
1228
|
-
1,
|
|
1229
|
-
SAFE_MODULE_SETUP,
|
|
1230
|
-
0n,
|
|
1231
|
-
BigInt((enableModulesCall.length - 2) / 2),
|
|
1232
|
-
enableModulesCall
|
|
1233
|
-
])]
|
|
1234
|
-
});
|
|
1235
|
-
return encodeFunctionData({
|
|
1236
|
-
abi: safeSetupAbi,
|
|
1237
|
-
functionName: "setup",
|
|
1238
|
-
args: [
|
|
1239
|
-
[founderPersonalSafe],
|
|
1240
|
-
1n,
|
|
1241
|
-
MULTI_SEND,
|
|
1242
|
-
setupData,
|
|
1243
|
-
SAFE_4337_MODULE,
|
|
1244
|
-
ZERO_ADDRESS,
|
|
1245
|
-
0n,
|
|
1246
|
-
ZERO_ADDRESS
|
|
1247
|
-
]
|
|
1248
|
-
});
|
|
1249
|
-
}
|
|
1250
|
-
function deriveCapxulOrgAddress(input) {
|
|
1251
|
-
const orgHandle = validateOrgHandle(input.orgHandle);
|
|
1252
|
-
const initializer = buildCapxulOrgInitializer({ founderPersonalSafe: input.founderPersonalSafe });
|
|
1253
|
-
const saltNonce = computeCapxulOrgSaltNonce({
|
|
1254
|
-
email: input.email,
|
|
1255
|
-
orgHandle
|
|
1256
|
-
});
|
|
1257
|
-
return getContractAddress({
|
|
1258
|
-
opcode: "CREATE2",
|
|
1259
|
-
from: SAFE_PROXY_FACTORY,
|
|
1260
|
-
salt: keccak256(encodePacked(["bytes32", "uint256"], [keccak256(initializer), saltNonce])),
|
|
1261
|
-
bytecodeHash: keccak256(concat([SAFE_PROXY_CREATION_CODE, encodeAbiParameters([{ type: "uint256" }], [BigInt(SAFE_L2_SINGLETON)])]))
|
|
1262
|
-
}).toLowerCase();
|
|
1263
|
-
}
|
|
1264
|
-
//#endregion
|
|
1265
|
-
//#region ../../packages/config/src/role-dsl.ts
|
|
1266
|
-
const USD_DECIMALS = 6;
|
|
1267
|
-
const USD_SCALE = 10n ** BigInt(USD_DECIMALS);
|
|
1268
|
-
const USD_DISPLAY_RE = /^\d+(?:\.\d{1,6})?$/;
|
|
1269
|
-
const USD_BASE_UNIT_RE = /^\d+$/;
|
|
1270
|
-
const EXEC_TRANSACTION_WITH_ROLE = "zodiac.roles.execTransactionWithRole";
|
|
1271
|
-
const ASSIGN_ROLES = "zodiac.roles.assignRoles";
|
|
1272
|
-
const SCOPE_TARGET = "zodiac.roles.scopeTarget";
|
|
1273
|
-
const OWNER_ROLE_LABEL = "Owner";
|
|
1274
|
-
const FOUNDER_BUDGET_ROLE_LABEL = "Founder Budget";
|
|
1275
|
-
const FOUNDER_BUDGET_LIMIT = {
|
|
1276
|
-
currency: "USD",
|
|
1277
|
-
value: "1000000000000",
|
|
1278
|
-
decimals: 6
|
|
1279
|
-
};
|
|
1280
|
-
function usd(value) {
|
|
1281
|
-
return {
|
|
1282
|
-
currency: "USD",
|
|
1283
|
-
value: usdDisplayToBaseUnits(value),
|
|
1284
|
-
decimals: USD_DECIMALS
|
|
1285
|
-
};
|
|
1286
|
-
}
|
|
1287
|
-
function usdDisplayToBaseUnits(value) {
|
|
1288
|
-
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");
|
|
1289
|
-
const parts = value.split(".");
|
|
1290
|
-
const whole = parts[0] ?? "0";
|
|
1291
|
-
const fraction = parts[1] ?? "";
|
|
1292
|
-
return (BigInt(whole) * USD_SCALE + BigInt(fraction.padEnd(USD_DECIMALS, "0"))).toString();
|
|
1293
|
-
}
|
|
1294
|
-
function normalizeOrgRoleMoney(money, field) {
|
|
1295
|
-
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`);
|
|
1296
|
-
return money;
|
|
1297
|
-
}
|
|
1298
|
-
function normalizeOrgRoleSpendCap(spend) {
|
|
1299
|
-
if (spend === void 0) return void 0;
|
|
1300
|
-
return {
|
|
1301
|
-
...spend.perTx === void 0 ? {} : { perTx: normalizeOrgRoleMoney(spend.perTx, "roles.spend.perTx") },
|
|
1302
|
-
...spend.perDay === void 0 ? {} : { perDay: normalizeOrgRoleMoney(spend.perDay, "roles.spend.perDay") },
|
|
1303
|
-
...spend.toRecipients === void 0 ? {} : { toRecipients: spend.toRecipients }
|
|
1304
|
-
};
|
|
1305
|
-
}
|
|
1306
|
-
function normalizeOrgRoleLabel(label) {
|
|
1307
|
-
const normalized = label.trim().replace(/\s+/g, " ");
|
|
1308
|
-
if (normalized.length === 0) throw Errors.invalidInput("role.label", "must be a non-empty role label");
|
|
1309
|
-
return normalized;
|
|
1310
|
-
}
|
|
1311
|
-
function orgRoleKeyForLabel(label) {
|
|
1312
|
-
return keccak256(toBytes(normalizeOrgRoleLabel(label).toLowerCase()));
|
|
1313
|
-
}
|
|
1314
|
-
function soloOrgRoleTemplate() {
|
|
1315
|
-
return [{
|
|
1316
|
-
label: "Owner",
|
|
1317
|
-
canManageMembers: true,
|
|
1318
|
-
canManageRoles: true
|
|
1319
|
-
}, {
|
|
1320
|
-
label: FOUNDER_BUDGET_ROLE_LABEL,
|
|
1321
|
-
spend: {
|
|
1322
|
-
perTx: FOUNDER_BUDGET_LIMIT,
|
|
1323
|
-
perDay: FOUNDER_BUDGET_LIMIT,
|
|
1324
|
-
toRecipients: "anyone"
|
|
1325
|
-
}
|
|
1326
|
-
}];
|
|
1327
|
-
}
|
|
1328
|
-
function startupOrgRoleTemplate() {
|
|
1329
|
-
return [
|
|
1330
|
-
...soloOrgRoleTemplate(),
|
|
1331
|
-
{
|
|
1332
|
-
label: "Finance Manager",
|
|
1333
|
-
spend: {
|
|
1334
|
-
perTx: usd("25000"),
|
|
1335
|
-
perDay: usd("100000"),
|
|
1336
|
-
toRecipients: "anyone"
|
|
1337
|
-
}
|
|
1338
|
-
},
|
|
1339
|
-
{
|
|
1340
|
-
label: "Team Lead",
|
|
1341
|
-
spend: {
|
|
1342
|
-
perTx: usd("5000"),
|
|
1343
|
-
perDay: usd("15000"),
|
|
1344
|
-
toRecipients: "anyone"
|
|
1345
|
-
}
|
|
1346
|
-
}
|
|
1347
|
-
];
|
|
1348
|
-
}
|
|
1349
|
-
function orgRoleTemplateDefinitions(template, customRoles = []) {
|
|
1350
|
-
switch (template) {
|
|
1351
|
-
case "Solo": return soloOrgRoleTemplate();
|
|
1352
|
-
case "Startup": return startupOrgRoleTemplate();
|
|
1353
|
-
case "Custom": return customRoles.length === 0 ? soloOrgRoleTemplate() : customRoles;
|
|
1354
|
-
default: return template;
|
|
1355
|
-
}
|
|
1356
|
-
}
|
|
1357
|
-
function compileOrgRoleDefinitions(definitions) {
|
|
1358
|
-
if (definitions.length === 0) throw Errors.invalidInput("roles", "must include at least one role");
|
|
1359
|
-
const seen = /* @__PURE__ */ new Set();
|
|
1360
|
-
const roles = definitions.map((definition) => {
|
|
1361
|
-
const label = normalizeOrgRoleLabel(definition.label);
|
|
1362
|
-
const roleKey = orgRoleKeyForLabel(label);
|
|
1363
|
-
if (seen.has(roleKey)) throw Errors.invalidInput("roles", `duplicate role label: ${label}`);
|
|
1364
|
-
seen.add(roleKey);
|
|
1365
|
-
const spend = normalizeOrgRoleSpendCap(definition.spend);
|
|
1366
|
-
const permissions = [];
|
|
1367
|
-
if (spend !== void 0 || label === OWNER_ROLE_LABEL) permissions.push(EXEC_TRANSACTION_WITH_ROLE);
|
|
1368
|
-
if (definition.canManageMembers === true) permissions.push(ASSIGN_ROLES);
|
|
1369
|
-
if (definition.canManageRoles === true) permissions.push(SCOPE_TARGET);
|
|
1370
|
-
return {
|
|
1371
|
-
label,
|
|
1372
|
-
roleKey,
|
|
1373
|
-
definition: {
|
|
1374
|
-
...definition,
|
|
1375
|
-
label,
|
|
1376
|
-
...spend === void 0 ? {} : { spend }
|
|
1377
|
-
},
|
|
1378
|
-
permissions,
|
|
1379
|
-
allowance: spend ?? null
|
|
1380
|
-
};
|
|
1381
|
-
});
|
|
1382
|
-
const manager = roles.find((role) => role.definition.canManageMembers === true);
|
|
1383
|
-
if (manager === void 0) throw Errors.invalidInput("roles.canManageMembers", "at least one role must compile to the on-chain member-management permission");
|
|
1384
|
-
return {
|
|
1385
|
-
roles,
|
|
1386
|
-
memberManagementRole: {
|
|
1387
|
-
roleKey: manager.roleKey,
|
|
1388
|
-
permission: ASSIGN_ROLES
|
|
1389
|
-
}
|
|
1390
|
-
};
|
|
1391
|
-
}
|
|
1392
|
-
//#endregion
|
|
1393
888
|
//#region ../../packages/config/src/capxul-payments-v2.ts
|
|
1394
889
|
/** The exact compiled CapxulPaymentsV2 ABI. */
|
|
1395
890
|
const CAPXUL_PAYMENTS_V2_ABI = [
|
|
@@ -2015,6 +1510,350 @@ const CAPXUL_PAYMENTS_V2_ABI = [
|
|
|
2015
1510
|
inputs: []
|
|
2016
1511
|
}
|
|
2017
1512
|
];
|
|
1513
|
+
/** Immutable CapxulPaymentsV2 deployment on Base Sepolia. */
|
|
1514
|
+
const CAPXUL_PAYMENTS_V2_ADDRESS = "0xA3ACDD016f706eD432A9a0545C45F0943f996b60";
|
|
1515
|
+
//#endregion
|
|
1516
|
+
//#region ../../packages/config/src/route.ts
|
|
1517
|
+
/** USDX on Base Sepolia — the only settlement token in v1. */
|
|
1518
|
+
const USDX_BASE_SEPOLIA_TOKEN = {
|
|
1519
|
+
chainId: BASE_SEPOLIA_CHAIN_ID,
|
|
1520
|
+
address: USDX_ADDRESS_BASE_SEPOLIA,
|
|
1521
|
+
decimals: 6
|
|
1522
|
+
};
|
|
1523
|
+
/**
|
|
1524
|
+
* The `direct-base` settlement route: USDX on Base Sepolia, settled directly
|
|
1525
|
+
* through the `CapxulPayments` contract. This is the ONLY route implemented in
|
|
1526
|
+
* D1; the `Route` shape is the seam future provider routes slot into.
|
|
1527
|
+
*/
|
|
1528
|
+
const DIRECT_BASE_ROUTE = {
|
|
1529
|
+
kind: "direct-base",
|
|
1530
|
+
token: USDX_BASE_SEPOLIA_TOKEN,
|
|
1531
|
+
chainId: USDX_BASE_SEPOLIA_TOKEN.chainId,
|
|
1532
|
+
verifyingContract: CAPXUL_PAYMENTS_V2_ADDRESS
|
|
1533
|
+
};
|
|
1534
|
+
USDX_BASE_SEPOLIA_TOKEN.chainId;
|
|
1535
|
+
const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
1536
|
+
const ORG_HANDLE_REGEX = /^[a-z0-9-]{3,32}$/;
|
|
1537
|
+
const ADDRESS_REGEX = /^0x[0-9a-f]{40}$/;
|
|
1538
|
+
const safeSetupAbi = [{
|
|
1539
|
+
type: "function",
|
|
1540
|
+
name: "setup",
|
|
1541
|
+
stateMutability: "nonpayable",
|
|
1542
|
+
inputs: [
|
|
1543
|
+
{
|
|
1544
|
+
name: "_owners",
|
|
1545
|
+
type: "address[]"
|
|
1546
|
+
},
|
|
1547
|
+
{
|
|
1548
|
+
name: "_threshold",
|
|
1549
|
+
type: "uint256"
|
|
1550
|
+
},
|
|
1551
|
+
{
|
|
1552
|
+
name: "to",
|
|
1553
|
+
type: "address"
|
|
1554
|
+
},
|
|
1555
|
+
{
|
|
1556
|
+
name: "data",
|
|
1557
|
+
type: "bytes"
|
|
1558
|
+
},
|
|
1559
|
+
{
|
|
1560
|
+
name: "fallbackHandler",
|
|
1561
|
+
type: "address"
|
|
1562
|
+
},
|
|
1563
|
+
{
|
|
1564
|
+
name: "paymentToken",
|
|
1565
|
+
type: "address"
|
|
1566
|
+
},
|
|
1567
|
+
{
|
|
1568
|
+
name: "payment",
|
|
1569
|
+
type: "uint256"
|
|
1570
|
+
},
|
|
1571
|
+
{
|
|
1572
|
+
name: "paymentReceiver",
|
|
1573
|
+
type: "address"
|
|
1574
|
+
}
|
|
1575
|
+
],
|
|
1576
|
+
outputs: []
|
|
1577
|
+
}];
|
|
1578
|
+
const enableModulesAbi$1 = [{
|
|
1579
|
+
type: "function",
|
|
1580
|
+
name: "enableModules",
|
|
1581
|
+
stateMutability: "nonpayable",
|
|
1582
|
+
inputs: [{
|
|
1583
|
+
name: "modules",
|
|
1584
|
+
type: "address[]"
|
|
1585
|
+
}],
|
|
1586
|
+
outputs: []
|
|
1587
|
+
}];
|
|
1588
|
+
const multiSendAbi$1 = [{
|
|
1589
|
+
type: "function",
|
|
1590
|
+
name: "multiSend",
|
|
1591
|
+
stateMutability: "payable",
|
|
1592
|
+
inputs: [{
|
|
1593
|
+
name: "transactions",
|
|
1594
|
+
type: "bytes"
|
|
1595
|
+
}],
|
|
1596
|
+
outputs: []
|
|
1597
|
+
}];
|
|
1598
|
+
/**
|
|
1599
|
+
* Normalize an org handle for both salting and storage (D10a — trim +
|
|
1600
|
+
* lowercase). Idempotent: `normalizeOrgHandle(normalizeOrgHandle(x)) ===
|
|
1601
|
+
* normalizeOrgHandle(x)`.
|
|
1602
|
+
*
|
|
1603
|
+
* @param handle - The raw org handle
|
|
1604
|
+
* @returns The trimmed, lowercased handle
|
|
1605
|
+
*/
|
|
1606
|
+
function normalizeOrgHandle(handle) {
|
|
1607
|
+
return handle.trim().toLowerCase();
|
|
1608
|
+
}
|
|
1609
|
+
/**
|
|
1610
|
+
* Validate an org handle against the D10a rule `^[a-z0-9-]{3,32}$` over its
|
|
1611
|
+
* NORMALIZED form. Returns the normalized handle on success; throws a typed
|
|
1612
|
+
* `INVALID_INPUT` `CapxulError` (field `orgHandle`) on failure — never a raw
|
|
1613
|
+
* `Error`, so SDK / backend boundary handlers can route on the code.
|
|
1614
|
+
*
|
|
1615
|
+
* @param handle - The raw org handle
|
|
1616
|
+
* @returns The normalized, validated handle
|
|
1617
|
+
*/
|
|
1618
|
+
function validateOrgHandle(handle) {
|
|
1619
|
+
const normalized = normalizeOrgHandle(handle);
|
|
1620
|
+
if (!ORG_HANDLE_REGEX.test(normalized)) throw Errors.invalidInput("orgHandle", `must match ^[a-z0-9-]{3,32}$ after trim+lowercase, got ${handle}`);
|
|
1621
|
+
return normalized;
|
|
1622
|
+
}
|
|
1623
|
+
/**
|
|
1624
|
+
* Compute the deterministic Org Safe salt nonce for a `(namespace, email,
|
|
1625
|
+
* orgHandle)` triple (D10a). The salt nonce is the `bigint` reading of
|
|
1626
|
+
* `keccak256(namespace + ":" + normalizeSafeSaltEmail(email) + ":" +
|
|
1627
|
+
* normalizeOrgHandle(orgHandle))`.
|
|
1628
|
+
*
|
|
1629
|
+
* Keyed on email + handle, NOT the signer — so the Org address survives signer
|
|
1630
|
+
* rotation (D7). Namespace defaults to `CAPXUL_ORG_SALT_NAMESPACE`.
|
|
1631
|
+
*
|
|
1632
|
+
* @param input.email - The founder email to derive the salt nonce from
|
|
1633
|
+
* @param input.orgHandle - The org handle (normalized internally)
|
|
1634
|
+
* @param input.namespace - Optional namespace override
|
|
1635
|
+
* @returns The Capxul-namespaced Org salt nonce as a `bigint`
|
|
1636
|
+
*/
|
|
1637
|
+
function computeCapxulOrgSaltNonce(input) {
|
|
1638
|
+
const namespace = input.namespace ?? "capxul:org:v1";
|
|
1639
|
+
const normalizedEmail = normalizeSafeSaltEmail(input.email);
|
|
1640
|
+
const normalizedHandle = normalizeOrgHandle(input.orgHandle);
|
|
1641
|
+
return BigInt(keccak256(toBytes(`${namespace}:${normalizedEmail}:${normalizedHandle}`)));
|
|
1642
|
+
}
|
|
1643
|
+
/**
|
|
1644
|
+
* Pure derivation of the Org Safe v1.4.1 (SafeL2) + 4337-module-enabled
|
|
1645
|
+
* counterfactual address for a Capxul `(founderPersonalSafe, email, orgHandle)`
|
|
1646
|
+
* triple (D10a). Mirrors `deriveCapxulSafeAddress` byte-for-byte except the salt
|
|
1647
|
+
* nonce (Org-namespaced, keyed on email+handle) and the initializer owner
|
|
1648
|
+
* (the founder's PERSONAL Safe address, passed in directly — D7).
|
|
1649
|
+
*
|
|
1650
|
+
* Returns the lowercased `0x` + 40 hex string (raw — no brand applied; callers
|
|
1651
|
+
* brand at their own boundary). Throws a typed `INVALID_INPUT` `CapxulError`
|
|
1652
|
+
* (field `orgHandle`) if the handle is malformed.
|
|
1653
|
+
*
|
|
1654
|
+
* Canonical conformance: `packages/config/tests/org-safe-address-conformance.test.ts`
|
|
1655
|
+
* pins the matrix against Safes actually deployed on Base Sepolia.
|
|
1656
|
+
*/
|
|
1657
|
+
/**
|
|
1658
|
+
* Build the EXACT Org Safe `setup()` initializer calldata (D10a). This is the
|
|
1659
|
+
* single source of truth for the initializer bytes: `deriveCapxulOrgAddress`
|
|
1660
|
+
* hashes it into the CREATE2 salt, and the live Org deploy adapter passes the
|
|
1661
|
+
* IDENTICAL bytes to `SafeProxyFactory.createProxyWithNonce` — so the deployed
|
|
1662
|
+
* address provably equals the counterfactual byte-for-byte.
|
|
1663
|
+
*
|
|
1664
|
+
* `setup([founderPersonalSafe], 1, MULTI_SEND, <enableModules([SAFE_4337_MODULE])
|
|
1665
|
+
* MultiSend>, SAFE_4337_MODULE, 0, 0, 0)` — owner is the founder's PERSONAL Safe
|
|
1666
|
+
* (D7), the 4337 module is enabled via the same MultiSend lane as the personal
|
|
1667
|
+
* Safe. NO Zodiac Roles / Allowance at setup() (S1 decision A — those land in S2).
|
|
1668
|
+
*
|
|
1669
|
+
* Validates (and lowercases) `founderPersonalSafe`; throws a typed INVALID_INPUT
|
|
1670
|
+
* (`founderPersonalSafe`) on a malformed address.
|
|
1671
|
+
*
|
|
1672
|
+
* @param input.founderPersonalSafe - The founder's personal Safe address (owner)
|
|
1673
|
+
* @returns The `0x`-prefixed `setup()` calldata
|
|
1674
|
+
*/
|
|
1675
|
+
function buildCapxulOrgInitializer(input) {
|
|
1676
|
+
const founderPersonalSafe = input.founderPersonalSafe.toLowerCase();
|
|
1677
|
+
if (!ADDRESS_REGEX.test(founderPersonalSafe)) throw Errors.invalidInput("founderPersonalSafe", `must be 0x + 40 hex chars, got ${input.founderPersonalSafe}`);
|
|
1678
|
+
const enableModulesCall = encodeFunctionData({
|
|
1679
|
+
abi: enableModulesAbi$1,
|
|
1680
|
+
functionName: "enableModules",
|
|
1681
|
+
args: [[SAFE_4337_MODULE]]
|
|
1682
|
+
});
|
|
1683
|
+
const setupData = encodeFunctionData({
|
|
1684
|
+
abi: multiSendAbi$1,
|
|
1685
|
+
functionName: "multiSend",
|
|
1686
|
+
args: [encodePacked([
|
|
1687
|
+
"uint8",
|
|
1688
|
+
"address",
|
|
1689
|
+
"uint256",
|
|
1690
|
+
"uint256",
|
|
1691
|
+
"bytes"
|
|
1692
|
+
], [
|
|
1693
|
+
1,
|
|
1694
|
+
SAFE_MODULE_SETUP,
|
|
1695
|
+
0n,
|
|
1696
|
+
BigInt((enableModulesCall.length - 2) / 2),
|
|
1697
|
+
enableModulesCall
|
|
1698
|
+
])]
|
|
1699
|
+
});
|
|
1700
|
+
return encodeFunctionData({
|
|
1701
|
+
abi: safeSetupAbi,
|
|
1702
|
+
functionName: "setup",
|
|
1703
|
+
args: [
|
|
1704
|
+
[founderPersonalSafe],
|
|
1705
|
+
1n,
|
|
1706
|
+
MULTI_SEND,
|
|
1707
|
+
setupData,
|
|
1708
|
+
SAFE_4337_MODULE,
|
|
1709
|
+
ZERO_ADDRESS,
|
|
1710
|
+
0n,
|
|
1711
|
+
ZERO_ADDRESS
|
|
1712
|
+
]
|
|
1713
|
+
});
|
|
1714
|
+
}
|
|
1715
|
+
function deriveCapxulOrgAddress(input) {
|
|
1716
|
+
const orgHandle = validateOrgHandle(input.orgHandle);
|
|
1717
|
+
const initializer = buildCapxulOrgInitializer({ founderPersonalSafe: input.founderPersonalSafe });
|
|
1718
|
+
const saltNonce = computeCapxulOrgSaltNonce({
|
|
1719
|
+
email: input.email,
|
|
1720
|
+
orgHandle
|
|
1721
|
+
});
|
|
1722
|
+
return getContractAddress({
|
|
1723
|
+
opcode: "CREATE2",
|
|
1724
|
+
from: SAFE_PROXY_FACTORY,
|
|
1725
|
+
salt: keccak256(encodePacked(["bytes32", "uint256"], [keccak256(initializer), saltNonce])),
|
|
1726
|
+
bytecodeHash: keccak256(concat([SAFE_PROXY_CREATION_CODE, encodeAbiParameters([{ type: "uint256" }], [BigInt(SAFE_L2_SINGLETON)])]))
|
|
1727
|
+
}).toLowerCase();
|
|
1728
|
+
}
|
|
1729
|
+
//#endregion
|
|
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
|
+
}
|
|
1771
|
+
function normalizeOrgRoleLabel(label) {
|
|
1772
|
+
const normalized = label.trim().replace(/\s+/g, " ");
|
|
1773
|
+
if (normalized.length === 0) throw Errors.invalidInput("role.label", "must be a non-empty role label");
|
|
1774
|
+
return normalized;
|
|
1775
|
+
}
|
|
1776
|
+
function orgRoleKeyForLabel(label) {
|
|
1777
|
+
return keccak256(toBytes(normalizeOrgRoleLabel(label).toLowerCase()));
|
|
1778
|
+
}
|
|
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
|
+
}
|
|
2018
1857
|
padHex(stringToHex("FM_DAILY"), {
|
|
2019
1858
|
size: 32,
|
|
2020
1859
|
dir: "right"
|
|
@@ -2653,6 +2492,7 @@ Object.fromEntries(SUPPORTED_CURRENCIES.map((currency) => [currency.code, curren
|
|
|
2653
2492
|
const EMAIL_RE$1 = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
2654
2493
|
const COUNTRY_CODE_RE = /^[A-Z]{2}$/;
|
|
2655
2494
|
const ACCOUNT_ID_RE = /^account_[0-9A-Za-z]+$/;
|
|
2495
|
+
const PARTY_ID_RE$1 = /^party_[0-9A-Za-z]+$/;
|
|
2656
2496
|
const APP_ID_RE = /^app_[0-7][0-9A-HJKMNP-TV-Z]{25}$/;
|
|
2657
2497
|
const WEI_RE = /^[0-9]+$/;
|
|
2658
2498
|
Math.floor(Number.MAX_SAFE_INTEGER / 1e3);
|
|
@@ -2671,6 +2511,10 @@ function toAccountId(raw) {
|
|
|
2671
2511
|
if (typeof raw !== "string" || !ACCOUNT_ID_RE.test(raw)) throw Errors.invalidInput("accountId", invalidValueReason("must be account_ plus an alphanumeric id", raw));
|
|
2672
2512
|
return raw;
|
|
2673
2513
|
}
|
|
2514
|
+
function toPartyId(raw) {
|
|
2515
|
+
if (typeof raw !== "string" || !PARTY_ID_RE$1.test(raw)) throw Errors.invalidInput("partyId", invalidValueReason("must be party_ plus an alphanumeric id", raw));
|
|
2516
|
+
return raw;
|
|
2517
|
+
}
|
|
2674
2518
|
function toOrgId(raw) {
|
|
2675
2519
|
return toNonEmptyStringBrand(raw, "orgId");
|
|
2676
2520
|
}
|
|
@@ -3027,11 +2871,12 @@ const EVM_ADDRESS_RE = /^0x[a-fA-F0-9]{40}$/;
|
|
|
3027
2871
|
* envelopes carrying it — so it MUST stay byte-identical across both. Exported
|
|
3028
2872
|
* once here to remove the drift risk of a mirrored declaration.
|
|
3029
2873
|
*/
|
|
3030
|
-
const PAYMENT_DOCUMENT_VERIFYING_CONTRACT = "
|
|
2874
|
+
const PAYMENT_DOCUMENT_VERIFYING_CONTRACT = "0xA3ACDD016f706eD432A9a0545C45F0943f996b60";
|
|
3031
2875
|
const PAYMENT_ID_RE = /^payment_[0-9A-Za-z]+$/;
|
|
3032
2876
|
const PAYEE_ID_RE = /^payee_[0-9A-Za-z]+$/;
|
|
3033
2877
|
const ORG_ID_RE = /^org_[0-9A-Za-z]+$/;
|
|
3034
2878
|
const USER_ID_RE = /^user_[0-9A-Za-z]+$/;
|
|
2879
|
+
const PARTY_ID_RE = /^party_[0-9A-Za-z]+$/;
|
|
3035
2880
|
const HANDLE_RE = /^@?[a-z0-9][a-z0-9-]{2,31}$/;
|
|
3036
2881
|
const ORG_HANDLE_RE = /^[a-z0-9][a-z0-9-]{2,31}$/;
|
|
3037
2882
|
const EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
@@ -3040,6 +2885,7 @@ const PaymentIdSchema$1 = Schema.String.pipe(Schema.check(Schema.makeFilter((val
|
|
|
3040
2885
|
const PayeeIdSchema = Schema.String.pipe(Schema.check(Schema.makeFilter((value) => PAYEE_ID_RE.test(value), { message: "must be payee_ plus an alphanumeric id" })));
|
|
3041
2886
|
const OrgIdSchema = Schema.String.pipe(Schema.check(Schema.makeFilter((value) => ORG_ID_RE.test(value), { message: "must be org_ plus an alphanumeric id" })));
|
|
3042
2887
|
const UserIdSchema = Schema.String.pipe(Schema.check(Schema.makeFilter((value) => USER_ID_RE.test(value), { message: "must be user_ plus an alphanumeric id" })));
|
|
2888
|
+
const PartyIdSchema = Schema.String.pipe(Schema.check(Schema.makeFilter((value) => PARTY_ID_RE.test(value), { message: "must be party_ plus an alphanumeric id" })));
|
|
3043
2889
|
const DecimalStringSchema = Schema.String.pipe(Schema.check(Schema.makeFilter((value) => DECIMAL_STRING_RE.test(value), { message: "must be a non-negative decimal string" })));
|
|
3044
2890
|
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" })));
|
|
3045
2891
|
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" })));
|
|
@@ -3186,6 +3032,7 @@ const PaymentRecipient = Schema.Struct({
|
|
|
3186
3032
|
"capxulUserId",
|
|
3187
3033
|
"me",
|
|
3188
3034
|
"org",
|
|
3035
|
+
"party",
|
|
3189
3036
|
"external_address"
|
|
3190
3037
|
]),
|
|
3191
3038
|
label: Schema.String,
|
|
@@ -3232,6 +3079,10 @@ const PaymentRef = Schema.Union([
|
|
|
3232
3079
|
Schema.Struct({
|
|
3233
3080
|
kind: Schema.Literal("payeeId"),
|
|
3234
3081
|
payeeId: PayeeIdSchema
|
|
3082
|
+
}),
|
|
3083
|
+
Schema.Struct({
|
|
3084
|
+
kind: Schema.Literal("party"),
|
|
3085
|
+
partyId: PartyIdSchema
|
|
3235
3086
|
})
|
|
3236
3087
|
]);
|
|
3237
3088
|
const Payment = Schema.Struct({
|
|
@@ -4662,6 +4513,7 @@ const PAYMENT_OUTPUT = {
|
|
|
4662
4513
|
"capxulUserId",
|
|
4663
4514
|
"me",
|
|
4664
4515
|
"org",
|
|
4516
|
+
"party",
|
|
4665
4517
|
"external_address"
|
|
4666
4518
|
]),
|
|
4667
4519
|
label: z.string(),
|
|
@@ -4755,6 +4607,10 @@ const REF = z.union([
|
|
|
4755
4607
|
z.object({
|
|
4756
4608
|
kind: z.literal("payeeId"),
|
|
4757
4609
|
payeeId: z.string()
|
|
4610
|
+
}),
|
|
4611
|
+
z.object({
|
|
4612
|
+
kind: z.literal("party"),
|
|
4613
|
+
partyId: z.string()
|
|
4758
4614
|
})
|
|
4759
4615
|
]);
|
|
4760
4616
|
const TIMING = z.union([
|
|
@@ -4777,11 +4633,14 @@ const ADDRESS_BOOK_ENTRY = z.object({
|
|
|
4777
4633
|
relationship: z.array(z.enum([
|
|
4778
4634
|
"paid",
|
|
4779
4635
|
"paidBy",
|
|
4780
|
-
"
|
|
4636
|
+
"invoiced",
|
|
4637
|
+
"invoicedBy",
|
|
4781
4638
|
"member",
|
|
4782
|
-
"
|
|
4639
|
+
"manual",
|
|
4640
|
+
"employed"
|
|
4783
4641
|
])),
|
|
4784
|
-
hidden: z.boolean()
|
|
4642
|
+
hidden: z.boolean(),
|
|
4643
|
+
lastActivityAt: z.number()
|
|
4785
4644
|
});
|
|
4786
4645
|
const ACTOR_REQUEST = z.object({
|
|
4787
4646
|
id: z.string(),
|
|
@@ -4859,6 +4718,9 @@ function actor(kind, orgId) {
|
|
|
4859
4718
|
function orgIdArg(args) {
|
|
4860
4719
|
return typeof args === "object" && args !== null && "orgId" in args && typeof args.orgId === "string" ? args.orgId : void 0;
|
|
4861
4720
|
}
|
|
4721
|
+
function permissionIdArg(args) {
|
|
4722
|
+
return typeof args === "object" && args !== null && "permissionId" in args && typeof args.permissionId === "string" ? args.permissionId : void 0;
|
|
4723
|
+
}
|
|
4862
4724
|
function requireMethod(handle, method, domain) {
|
|
4863
4725
|
const value = handle[method];
|
|
4864
4726
|
if (value === void 0) return {
|
|
@@ -4930,7 +4792,7 @@ function registerAddressBookTools(server, deps, scope) {
|
|
|
4930
4792
|
}, (args) => withSession(deps, args.sessionToken, `${prefix}.get`, async (handle) => {
|
|
4931
4793
|
const method = requireMethod(handle, "addressBookGet", prefix);
|
|
4932
4794
|
if (!method.ok) return methodNotImplemented(prefix, "get");
|
|
4933
|
-
const res = await method.value(actor(scope, orgIdArg(args)), args.entryId);
|
|
4795
|
+
const res = await method.value(actor(scope, orgIdArg(args)), toPartyId(args.entryId));
|
|
4934
4796
|
return res.ok ? okResult({ entry: res.value }) : errorResult(res.error);
|
|
4935
4797
|
}));
|
|
4936
4798
|
server.registerTool(`${prefix}.add`, {
|
|
@@ -4964,7 +4826,7 @@ function registerAddressBookTools(server, deps, scope) {
|
|
|
4964
4826
|
}, (args) => withSession(deps, args.sessionToken, `${prefix}.${action}`, async (handle) => {
|
|
4965
4827
|
const method = requireMethod(handle, action === "hide" ? "addressBookHide" : "addressBookUnhide", prefix);
|
|
4966
4828
|
if (!method.ok) return methodNotImplemented(prefix, action);
|
|
4967
|
-
return result(await method.value(actor(scope, orgIdArg(args)), args.entryId));
|
|
4829
|
+
return result(await method.value(actor(scope, orgIdArg(args)), toPartyId(args.entryId)));
|
|
4968
4830
|
}));
|
|
4969
4831
|
server.registerTool(`${prefix}.label`, {
|
|
4970
4832
|
title: `${scope} address book label`,
|
|
@@ -4981,7 +4843,7 @@ function registerAddressBookTools(server, deps, scope) {
|
|
|
4981
4843
|
if (!method.ok) return methodNotImplemented(prefix, "label");
|
|
4982
4844
|
return result(await method.value({
|
|
4983
4845
|
actor: actor(scope, orgIdArg(args)),
|
|
4984
|
-
entryId: args.entryId,
|
|
4846
|
+
entryId: toPartyId(args.entryId),
|
|
4985
4847
|
label: args.label
|
|
4986
4848
|
}));
|
|
4987
4849
|
}));
|
|
@@ -5070,13 +4932,14 @@ function registerInboxTools(server, deps, scope) {
|
|
|
5070
4932
|
sessionToken: z.string(),
|
|
5071
4933
|
...scopeInput,
|
|
5072
4934
|
requestId: z.string(),
|
|
5073
|
-
timing: TIMING.optional()
|
|
4935
|
+
timing: TIMING.optional(),
|
|
4936
|
+
...scope === "org" ? { permissionId: z.string() } : {}
|
|
5074
4937
|
},
|
|
5075
4938
|
outputSchema: PAYMENT_OUTPUT
|
|
5076
4939
|
}, (args) => withSession(deps, args.sessionToken, `${prefix}.approve`, async (handle) => {
|
|
5077
4940
|
const method = requireMethod(handle, "inboxApprove", prefix);
|
|
5078
4941
|
if (!method.ok) return methodNotImplemented(prefix, "approve");
|
|
5079
|
-
return paymentResult(await method.value(actor(scope, orgIdArg(args)), args.requestId, args.timing));
|
|
4942
|
+
return paymentResult(await method.value(actor(scope, orgIdArg(args)), args.requestId, args.timing, permissionIdArg(args)));
|
|
5080
4943
|
}));
|
|
5081
4944
|
server.registerTool(`${prefix}.decline`, {
|
|
5082
4945
|
title: `${scope} inbox decline`,
|
|
@@ -6161,86 +6024,24 @@ const transition = (state, event, config = DEFAULT_CONFIG) => {
|
|
|
6161
6024
|
const PRIVATE_TAGS = new Set(PRIVATE_EVENT_TAGS);
|
|
6162
6025
|
const isPrivate = (event) => PRIVATE_TAGS.has(event._tag);
|
|
6163
6026
|
//#endregion
|
|
6164
|
-
//#region ../../packages/sdk/src/
|
|
6165
|
-
|
|
6166
|
-
|
|
6167
|
-
|
|
6168
|
-
|
|
6169
|
-
|
|
6170
|
-
|
|
6171
|
-
* `at new ClassName (url:line:col)`
|
|
6172
|
-
*/
|
|
6173
|
-
const V8_FRAME_RE = /^\s*at\s+(?:(.+?)\s+\()?(?:(.+?)(?::(\d+):(\d+))?|(.+?))\)?\s*$/;
|
|
6174
|
-
function isNonUrlName(name) {
|
|
6175
|
-
return name === "<anonymous>" || name.startsWith("eval") || name.startsWith("new ") || name.startsWith("async ");
|
|
6027
|
+
//#region ../../packages/sdk/src/surface/_shared/provisioning-telemetry.ts
|
|
6028
|
+
async function emitProvisioningTelemetry(telemetry, smartAccount) {
|
|
6029
|
+
if (telemetry === void 0) return;
|
|
6030
|
+
await Effect.runPromise(telemetry.emit({
|
|
6031
|
+
name: "provisioning_safe_created",
|
|
6032
|
+
props: { safe_address: smartAccount.smartAccountAddress }
|
|
6033
|
+
}).pipe(Effect.catch((cause) => Effect.sync(() => reportProvisioningTelemetryFailure("error", smartAccount, cause))), Effect.catchDefect((cause) => Effect.sync(() => reportProvisioningTelemetryFailure("defect", smartAccount, cause)))));
|
|
6176
6034
|
}
|
|
6177
|
-
|
|
6178
|
-
|
|
6179
|
-
|
|
6180
|
-
|
|
6181
|
-
|
|
6182
|
-
|
|
6183
|
-
|
|
6184
|
-
* - `at async functionName (url:line:col)`
|
|
6185
|
-
* - `at new ClassName (url:line:col)`
|
|
6186
|
-
* - Native frames: `at Array.forEach (<anonymous>)`
|
|
6187
|
-
*/
|
|
6188
|
-
function parseV8StackFrames(error) {
|
|
6189
|
-
const stack = error.stack;
|
|
6190
|
-
if (stack === void 0 || stack === null || stack === "") return [];
|
|
6191
|
-
const lines = stack.split("\n");
|
|
6192
|
-
const frames = [];
|
|
6193
|
-
for (const line of lines) {
|
|
6194
|
-
const trimmed = line.trim();
|
|
6195
|
-
if (!trimmed.startsWith("at ")) continue;
|
|
6196
|
-
const match = V8_FRAME_RE.exec(trimmed);
|
|
6197
|
-
if (match === null) continue;
|
|
6198
|
-
if (match[1] !== void 0) frames.push({
|
|
6199
|
-
function: match[1],
|
|
6200
|
-
filename: match[2],
|
|
6201
|
-
lineno: match[3] !== void 0 ? Number(match[3]) : null,
|
|
6202
|
-
colno: match[4] !== void 0 ? Number(match[4]) : null
|
|
6203
|
-
});
|
|
6204
|
-
else if (match[2] !== void 0 && !isNonUrlName(match[2])) frames.push({
|
|
6205
|
-
function: "<anonymous>",
|
|
6206
|
-
filename: match[2],
|
|
6207
|
-
lineno: match[3] !== void 0 ? Number(match[3]) : null,
|
|
6208
|
-
colno: match[4] !== void 0 ? Number(match[4]) : null
|
|
6209
|
-
});
|
|
6210
|
-
else frames.push({
|
|
6211
|
-
function: match[1] ?? match[2] ?? match[5] ?? "<anonymous>",
|
|
6212
|
-
filename: match[2] ?? match[5] ?? "<anonymous>",
|
|
6213
|
-
lineno: match[3] !== void 0 ? Number(match[3]) : null,
|
|
6214
|
-
colno: match[4] !== void 0 ? Number(match[4]) : null
|
|
6215
|
-
});
|
|
6216
|
-
}
|
|
6217
|
-
return frames;
|
|
6035
|
+
function reportProvisioningTelemetryFailure(kind, smartAccount, cause) {
|
|
6036
|
+
if (!isProvisioningTelemetryDebugEnabled()) return;
|
|
6037
|
+
globalThis.console?.warn?.("[capxul] provisioning telemetry dropped", {
|
|
6038
|
+
kind,
|
|
6039
|
+
safeAddress: smartAccount.smartAccountAddress,
|
|
6040
|
+
cause
|
|
6041
|
+
});
|
|
6218
6042
|
}
|
|
6219
|
-
|
|
6220
|
-
|
|
6221
|
-
/**
|
|
6222
|
-
* Build PostHog's `$exception_list` (always a single entry). Error Tracking
|
|
6223
|
-
* groups on `type`, so it is ALWAYS present (the CapxulError code) — the
|
|
6224
|
-
* previous `[{ frames }]` shape omitted it and PostHog dropped the event as
|
|
6225
|
-
* "missing field `type`". When the error has no parseable stack, a synthetic
|
|
6226
|
-
* boundary frame stands in so the event still ingests as a real Issue (#1031).
|
|
6227
|
-
*/
|
|
6228
|
-
function buildExceptionList(input) {
|
|
6229
|
-
const frames = input.frames.length > 0 ? input.frames : [{
|
|
6230
|
-
filename: SDK_BOUNDARY_FILENAME,
|
|
6231
|
-
function: input.operation ?? "unknown",
|
|
6232
|
-
lineno: 1,
|
|
6233
|
-
colno: 1
|
|
6234
|
-
}];
|
|
6235
|
-
return [{
|
|
6236
|
-
type: input.type,
|
|
6237
|
-
value: input.value,
|
|
6238
|
-
mechanism: {
|
|
6239
|
-
handled: true,
|
|
6240
|
-
type: "capxul_sdk_boundary"
|
|
6241
|
-
},
|
|
6242
|
-
stacktrace: { frames }
|
|
6243
|
-
}];
|
|
6043
|
+
function isProvisioningTelemetryDebugEnabled() {
|
|
6044
|
+
return globalThis.process?.env?.CAPXUL_DEBUG_TELEMETRY === "1";
|
|
6244
6045
|
}
|
|
6245
6046
|
//#endregion
|
|
6246
6047
|
//#region ../../packages/sdk/src/telemetry/get-failure-mode.ts
|
|
@@ -6273,94 +6074,25 @@ function getFailureMode(error) {
|
|
|
6273
6074
|
if (details === void 0) return void 0;
|
|
6274
6075
|
return isFailureMode(details.failure_mode) ? details.failure_mode : void 0;
|
|
6275
6076
|
}
|
|
6276
|
-
/**
|
|
6277
|
-
* Resolve the canonical {@link FailureMode} for a `$exception`, guaranteeing a
|
|
6278
|
-
* taxonomy member is always returned — never `undefined`, never a free string.
|
|
6279
|
-
*
|
|
6280
|
-
* Resolution order:
|
|
6281
|
-
* 1. the structured mode on the error's `details.failure_mode` (already guarded);
|
|
6282
|
-
* 2. a caller-supplied `contextFailureMode`, but ONLY when it passes the same
|
|
6283
|
-
* runtime membership check — the static `FailureMode` type is erased at
|
|
6284
|
-
* runtime, so an operation string (e.g. `"signer-get-address"`) injected via
|
|
6285
|
-
* a JS caller or `as` cast is rejected here rather than leaking to telemetry;
|
|
6286
|
-
* 3. `"unknown"` otherwise, so an unclassifiable error is still tagged with a
|
|
6287
|
-
* canonical value instead of being emitted with no `failure_mode` at all.
|
|
6288
|
-
*/
|
|
6289
|
-
function resolveFailureMode(error, contextFailureMode) {
|
|
6290
|
-
return getFailureMode(error) ?? (isFailureMode(contextFailureMode) ? contextFailureMode : "unknown");
|
|
6291
|
-
}
|
|
6292
6077
|
//#endregion
|
|
6293
|
-
//#region ../../packages/sdk/src/
|
|
6294
|
-
/**
|
|
6295
|
-
|
|
6296
|
-
|
|
6297
|
-
|
|
6298
|
-
|
|
6299
|
-
|
|
6300
|
-
|
|
6301
|
-
|
|
6302
|
-
|
|
6303
|
-
|
|
6304
|
-
|
|
6305
|
-
|
|
6306
|
-
|
|
6307
|
-
function captureException(telemetry, error, context) {
|
|
6308
|
-
return Effect.catchDefect(Effect.sync(() => {
|
|
6309
|
-
const frames = error instanceof Error ? parseV8StackFrames(error) : [];
|
|
6310
|
-
const capxulError = isCapxulError(error) ? error : null;
|
|
6311
|
-
const errorCode = capxulError?.code ?? context?.capxul_error_code ?? "UNKNOWN";
|
|
6312
|
-
const props = {
|
|
6313
|
-
capxul_error_code: errorCode,
|
|
6314
|
-
$exception_type: errorCode,
|
|
6315
|
-
$exception_message: EXCEPTION_MESSAGE,
|
|
6316
|
-
$exception_list: buildExceptionList({
|
|
6317
|
-
type: errorCode,
|
|
6318
|
-
value: EXCEPTION_MESSAGE,
|
|
6319
|
-
...context?.operation === void 0 ? {} : { operation: context.operation },
|
|
6320
|
-
frames
|
|
6321
|
-
}),
|
|
6322
|
-
layer: capxulError?.layer ?? context?.layer,
|
|
6323
|
-
operation: context?.operation,
|
|
6324
|
-
provider: context?.provider,
|
|
6325
|
-
failure_mode: resolveFailureMode(error, context?.failure_mode)
|
|
6326
|
-
};
|
|
6327
|
-
if (capxulError?.details !== void 0) props.details = JSON.stringify(capxulError.details);
|
|
6328
|
-
for (const key of Object.keys(props)) if (props[key] === void 0) delete props[key];
|
|
6329
|
-
return telemetry.emit({
|
|
6330
|
-
name: "$exception",
|
|
6331
|
-
props
|
|
6078
|
+
//#region ../../packages/sdk/src/signer.ts
|
|
6079
|
+
/** Fold a signer throw into the public error contract. */
|
|
6080
|
+
function signerFailure(source, operation, cause) {
|
|
6081
|
+
const seen = /* @__PURE__ */ new Set();
|
|
6082
|
+
let failureMode;
|
|
6083
|
+
let current = cause;
|
|
6084
|
+
while (typeof current === "object" && current !== null && !seen.has(current)) {
|
|
6085
|
+
seen.add(current);
|
|
6086
|
+
if (current instanceof CapxulError && current.code === "SIGNER_REJECTED") return current;
|
|
6087
|
+
failureMode = getFailureMode(current) ?? failureMode;
|
|
6088
|
+
const error = current;
|
|
6089
|
+
if (error.code === 4001 || error.error === "passkey_user_cancelled") return Errors.signerRejected({
|
|
6090
|
+
source,
|
|
6091
|
+
cause
|
|
6332
6092
|
});
|
|
6333
|
-
|
|
6334
|
-
}
|
|
6335
|
-
|
|
6336
|
-
* Synchronous fire-and-forget capture. Runs the Effect inline with
|
|
6337
|
-
* `Effect.runSync` so callers outside an Effect context (e.g. React
|
|
6338
|
-
* hooks before throwing) can report errors without awaiting.
|
|
6339
|
-
*/
|
|
6340
|
-
function captureExceptionSync(telemetry, error, context) {
|
|
6341
|
-
try {
|
|
6342
|
-
Effect.runSync(captureException(telemetry, error, context));
|
|
6343
|
-
} catch {}
|
|
6344
|
-
}
|
|
6345
|
-
//#endregion
|
|
6346
|
-
//#region ../../packages/sdk/src/surface/_shared/provisioning-telemetry.ts
|
|
6347
|
-
async function emitProvisioningTelemetry(telemetry, smartAccount) {
|
|
6348
|
-
if (telemetry === void 0) return;
|
|
6349
|
-
await Effect.runPromise(telemetry.emit({
|
|
6350
|
-
name: "provisioning_safe_created",
|
|
6351
|
-
props: { safe_address: smartAccount.smartAccountAddress }
|
|
6352
|
-
}).pipe(Effect.catch((cause) => Effect.sync(() => reportProvisioningTelemetryFailure("error", smartAccount, cause))), Effect.catchDefect((cause) => Effect.sync(() => reportProvisioningTelemetryFailure("defect", smartAccount, cause)))));
|
|
6353
|
-
}
|
|
6354
|
-
function reportProvisioningTelemetryFailure(kind, smartAccount, cause) {
|
|
6355
|
-
if (!isProvisioningTelemetryDebugEnabled()) return;
|
|
6356
|
-
globalThis.console?.warn?.("[capxul] provisioning telemetry dropped", {
|
|
6357
|
-
kind,
|
|
6358
|
-
safeAddress: smartAccount.smartAccountAddress,
|
|
6359
|
-
cause
|
|
6360
|
-
});
|
|
6361
|
-
}
|
|
6362
|
-
function isProvisioningTelemetryDebugEnabled() {
|
|
6363
|
-
return globalThis.process?.env?.CAPXUL_DEBUG_TELEMETRY === "1";
|
|
6093
|
+
current = error.cause;
|
|
6094
|
+
}
|
|
6095
|
+
return Errors.providerError("signer", operation, cause, failureMode === void 0 ? void 0 : { failure_mode: failureMode });
|
|
6364
6096
|
}
|
|
6365
6097
|
//#endregion
|
|
6366
6098
|
//#region ../../packages/sdk/src/internal/invocation-observation.ts
|
|
@@ -6923,7 +6655,7 @@ const accountStatusProgram = Effect.gen(function* () {
|
|
|
6923
6655
|
};
|
|
6924
6656
|
const signerAddress = yield* Effect.tryPromise({
|
|
6925
6657
|
try: () => signer.getAddress(),
|
|
6926
|
-
catch: (cause) =>
|
|
6658
|
+
catch: (cause) => signerFailure(signer.source, "getAddress", cause)
|
|
6927
6659
|
});
|
|
6928
6660
|
return {
|
|
6929
6661
|
status: "accountProviderReady",
|
|
@@ -7426,55 +7158,42 @@ function makeActorRelationshipMethods(deps) {
|
|
|
7426
7158
|
const fns = actorScopeContract;
|
|
7427
7159
|
return {
|
|
7428
7160
|
addressBook: {
|
|
7429
|
-
list: (options) => mapOk$1(awaitableConvex(options?.signal, "addressBook.list", () => convexCall.query(fns.addressBookList, {
|
|
7430
|
-
|
|
7431
|
-
|
|
7432
|
-
|
|
7433
|
-
|
|
7434
|
-
|
|
7435
|
-
|
|
7436
|
-
|
|
7437
|
-
},
|
|
7161
|
+
list: (input, options) => mapOk$1("addressBook.list", awaitableConvex(options?.signal, "addressBook.list", () => convexCall.query(fns.addressBookList, {
|
|
7162
|
+
actor,
|
|
7163
|
+
...input?.includeHidden === void 0 ? {} : { includeHidden: input.includeHidden }
|
|
7164
|
+
})), (entries) => entries.map(mapAddressBookEntry)),
|
|
7165
|
+
get: (entryId, options) => mapOk$1("addressBook.get", awaitableConvex(options?.signal, "addressBook.get", () => convexCall.query(fns.addressBookGet, {
|
|
7166
|
+
actor,
|
|
7167
|
+
partyId: entryId
|
|
7168
|
+
})), (entry) => entry === null ? null : mapAddressBookEntry(entry)),
|
|
7438
7169
|
add: async (input, options) => {
|
|
7439
7170
|
const ref = normalizeRefForBackend$1(input.ref, "ref");
|
|
7440
7171
|
if (!ref.ok) return ref;
|
|
7441
|
-
return mapOk$1(await awaitableConvex(options?.signal, "addressBook.add", () => convexCall.mutation(fns.addressBookAdd, {
|
|
7172
|
+
return mapOk$1("addressBook.add", await awaitableConvex(options?.signal, "addressBook.add", () => convexCall.mutation(fns.addressBookAdd, {
|
|
7442
7173
|
actor,
|
|
7443
7174
|
ref: ref.value,
|
|
7444
7175
|
...input.label === void 0 ? {} : { label: input.label }
|
|
7445
7176
|
})), mapAddressBookEntry);
|
|
7446
7177
|
},
|
|
7447
|
-
hide:
|
|
7448
|
-
|
|
7449
|
-
|
|
7450
|
-
|
|
7451
|
-
|
|
7452
|
-
|
|
7453
|
-
|
|
7454
|
-
},
|
|
7455
|
-
|
|
7456
|
-
|
|
7457
|
-
|
|
7458
|
-
|
|
7459
|
-
|
|
7460
|
-
ref: ref.value
|
|
7461
|
-
})), mapAddressBookEntry);
|
|
7462
|
-
},
|
|
7463
|
-
label: async (input, options) => {
|
|
7464
|
-
const ref = refFromEntryId(input.entryId);
|
|
7465
|
-
if (!ref.ok) return ref;
|
|
7466
|
-
return mapOk$1(await awaitableConvex(options?.signal, "addressBook.label", () => convexCall.mutation(fns.addressBookLabel, {
|
|
7467
|
-
actor,
|
|
7468
|
-
ref: ref.value,
|
|
7469
|
-
label: input.label
|
|
7470
|
-
})), mapAddressBookEntry);
|
|
7471
|
-
}
|
|
7178
|
+
hide: (entryId, options) => mapOk$1("addressBook.hide", awaitableConvex(options?.signal, "addressBook.hide", () => convexCall.mutation(fns.addressBookHide, {
|
|
7179
|
+
actor,
|
|
7180
|
+
partyId: entryId
|
|
7181
|
+
})), mapAddressBookEntry),
|
|
7182
|
+
unhide: (entryId, options) => mapOk$1("addressBook.unhide", awaitableConvex(options?.signal, "addressBook.unhide", () => convexCall.mutation(fns.addressBookUnhide, {
|
|
7183
|
+
actor,
|
|
7184
|
+
partyId: entryId
|
|
7185
|
+
})), mapAddressBookEntry),
|
|
7186
|
+
label: (input, options) => mapOk$1("addressBook.label", awaitableConvex(options?.signal, "addressBook.label", () => convexCall.mutation(fns.addressBookLabel, {
|
|
7187
|
+
actor,
|
|
7188
|
+
partyId: input.entryId,
|
|
7189
|
+
label: input.label
|
|
7190
|
+
})), mapAddressBookEntry)
|
|
7472
7191
|
},
|
|
7473
7192
|
requests: {
|
|
7474
7193
|
issue: async (input, options) => {
|
|
7475
7194
|
const payer = normalizeRefForBackend$1(input.payer, "payer");
|
|
7476
7195
|
if (!payer.ok) return payer;
|
|
7477
|
-
return mapOk$1(await awaitableConvex(options?.signal, "requests.issue", () => convexCall.mutation(fns.requestsIssue, {
|
|
7196
|
+
return mapOk$1("requests.issue", await awaitableConvex(options?.signal, "requests.issue", () => convexCall.mutation(fns.requestsIssue, {
|
|
7478
7197
|
actor,
|
|
7479
7198
|
payer: payer.value,
|
|
7480
7199
|
amount: input.amount,
|
|
@@ -7483,18 +7202,18 @@ function makeActorRelationshipMethods(deps) {
|
|
|
7483
7202
|
...input.expiresAt === void 0 ? {} : { expiresAt: input.expiresAt }
|
|
7484
7203
|
})), (request) => mapActorRequest(request, input.payer));
|
|
7485
7204
|
},
|
|
7486
|
-
list: (options) => mapOk$1(awaitableConvex(options?.signal, "requests.list", () => convexCall.query(fns.requestsList, { actor })), (requests) => requests.map((request) => mapActorRequest(request))),
|
|
7487
|
-
get: (requestId, options) => mapOk$1(awaitableConvex(options?.signal, "requests.get", () => convexCall.query(fns.requestsGet, {
|
|
7205
|
+
list: (options) => mapOk$1("requests.list", awaitableConvex(options?.signal, "requests.list", () => convexCall.query(fns.requestsList, { actor })), (requests) => requests.map((request) => mapActorRequest(request))),
|
|
7206
|
+
get: (requestId, options) => mapOk$1("requests.get", awaitableConvex(options?.signal, "requests.get", () => convexCall.query(fns.requestsGet, {
|
|
7488
7207
|
actor,
|
|
7489
7208
|
paymentRequestId: requestId
|
|
7490
7209
|
})), (request) => request === null ? null : mapActorRequest(request)),
|
|
7491
|
-
cancel: (requestId, options) => mapOk$1(awaitableConvex(options?.signal, "requests.cancel", () => convexCall.mutation(fns.requestsCancel, {
|
|
7210
|
+
cancel: (requestId, options) => mapOk$1("requests.cancel", awaitableConvex(options?.signal, "requests.cancel", () => convexCall.mutation(fns.requestsCancel, {
|
|
7492
7211
|
actor,
|
|
7493
7212
|
paymentRequestId: requestId
|
|
7494
7213
|
})), (request) => mapActorRequest(request))
|
|
7495
7214
|
},
|
|
7496
7215
|
inbox: {
|
|
7497
|
-
list: (options) => mapOk$1(awaitableConvex(options?.signal, "inbox.list", () => convexCall.query(fns.inboxList, { actor })), (items) => items.map(mapInboxItem)),
|
|
7216
|
+
list: (options) => mapOk$1("inbox.list", awaitableConvex(options?.signal, "inbox.list", () => convexCall.query(fns.inboxList, { actor })), (items) => items.map(mapInboxItem)),
|
|
7498
7217
|
approve: async (input, options) => {
|
|
7499
7218
|
const result = await awaitableConvex(options?.signal, "inbox.approve", () => convexCall.mutation(fns.inboxApprove, {
|
|
7500
7219
|
actor,
|
|
@@ -7505,7 +7224,7 @@ function makeActorRelationshipMethods(deps) {
|
|
|
7505
7224
|
if (!result.ok) return result;
|
|
7506
7225
|
return mapApprovedInboxPayment(result.value, input);
|
|
7507
7226
|
},
|
|
7508
|
-
decline: (requestId, options) => mapOk$1(awaitableConvex(options?.signal, "inbox.decline", () => convexCall.mutation(fns.inboxDecline, {
|
|
7227
|
+
decline: (requestId, options) => mapOk$1("inbox.decline", awaitableConvex(options?.signal, "inbox.decline", () => convexCall.mutation(fns.inboxDecline, {
|
|
7509
7228
|
actor,
|
|
7510
7229
|
paymentRequestId: requestId
|
|
7511
7230
|
})), mapInboxItem)
|
|
@@ -7573,30 +7292,52 @@ function missingConvexCall(operation) {
|
|
|
7573
7292
|
error: Errors.providerError("convex", operation, "ConvexCallPort is required")
|
|
7574
7293
|
});
|
|
7575
7294
|
}
|
|
7576
|
-
|
|
7295
|
+
/**
|
|
7296
|
+
* Project a successful backend reply, WITHOUT leaving the result boundary.
|
|
7297
|
+
*
|
|
7298
|
+
* The projection can refuse: `mapAddressBookEntry` proves the entry id is a
|
|
7299
|
+
* `PartyId` rather than trusting the wire, and `toPartyId` throws on a
|
|
7300
|
+
* malformed one. Every verb on this surface returns `CapxulResult`, so that
|
|
7301
|
+
* throw has to become a value here — otherwise a malformed reply rejects the
|
|
7302
|
+
* promise and the caller's `if (!result.ok)` never runs (ADR-0023: errors are
|
|
7303
|
+
* values, and a code crosses the seam).
|
|
7304
|
+
*/
|
|
7305
|
+
async function mapOk$1(operation, resultOrPromise, f) {
|
|
7577
7306
|
const result = await resultOrPromise;
|
|
7578
7307
|
if (!result.ok) return result;
|
|
7579
|
-
|
|
7580
|
-
|
|
7581
|
-
|
|
7582
|
-
|
|
7308
|
+
try {
|
|
7309
|
+
return {
|
|
7310
|
+
ok: true,
|
|
7311
|
+
value: f(result.value)
|
|
7312
|
+
};
|
|
7313
|
+
} catch (cause) {
|
|
7314
|
+
return {
|
|
7315
|
+
ok: false,
|
|
7316
|
+
error: cause instanceof CapxulError ? cause : Errors.providerError("convex", operation, cause)
|
|
7317
|
+
};
|
|
7318
|
+
}
|
|
7583
7319
|
}
|
|
7584
7320
|
const awaitableConvex = runIfActive;
|
|
7321
|
+
const ADDRESS_BOOK_RELATIONSHIPS = [
|
|
7322
|
+
"paid",
|
|
7323
|
+
"paidBy",
|
|
7324
|
+
"invoiced",
|
|
7325
|
+
"invoicedBy",
|
|
7326
|
+
"member",
|
|
7327
|
+
"manual",
|
|
7328
|
+
"employed"
|
|
7329
|
+
];
|
|
7330
|
+
function isAddressBookRelationship(value) {
|
|
7331
|
+
return ADDRESS_BOOK_RELATIONSHIPS.includes(value);
|
|
7332
|
+
}
|
|
7585
7333
|
function mapAddressBookEntry(entry) {
|
|
7586
|
-
const relationship = /* @__PURE__ */ new Set();
|
|
7587
|
-
for (const edge of entry.edges) {
|
|
7588
|
-
if (edge === "paid") relationship.add("paid");
|
|
7589
|
-
if (edge === "paidBy") relationship.add("paidBy");
|
|
7590
|
-
if (edge === "requested" || edge === "requestedBy") relationship.add("requested");
|
|
7591
|
-
if (edge === "member") relationship.add("member");
|
|
7592
|
-
if (edge === "employee") relationship.add("employee");
|
|
7593
|
-
}
|
|
7594
7334
|
return {
|
|
7595
|
-
id: entry.id,
|
|
7335
|
+
id: toPartyId(entry.id),
|
|
7596
7336
|
ref: entry.ref,
|
|
7597
|
-
label: entry.label
|
|
7598
|
-
relationship:
|
|
7599
|
-
hidden: entry.hidden
|
|
7337
|
+
label: entry.label,
|
|
7338
|
+
relationship: entry.relationship.filter(isAddressBookRelationship),
|
|
7339
|
+
hidden: entry.hidden,
|
|
7340
|
+
lastActivityAt: entry.lastActivityAt
|
|
7600
7341
|
};
|
|
7601
7342
|
}
|
|
7602
7343
|
function mapActorRequest(request, payer) {
|
|
@@ -7690,8 +7431,14 @@ function mapInboxStatus(status) {
|
|
|
7690
7431
|
}
|
|
7691
7432
|
function normalizeRefForBackend$1(ref, field) {
|
|
7692
7433
|
try {
|
|
7693
|
-
if (typeof ref === "string")
|
|
7694
|
-
|
|
7434
|
+
if (typeof ref === "string") return {
|
|
7435
|
+
ok: false,
|
|
7436
|
+
error: Errors.invalidInput(field, "recipient must be a typed Ref variant")
|
|
7437
|
+
};
|
|
7438
|
+
if (typeof ref !== "object" || ref === null || !("kind" in ref)) return {
|
|
7439
|
+
ok: false,
|
|
7440
|
+
error: Errors.invalidInput(field, "recipient must be a typed Ref variant")
|
|
7441
|
+
};
|
|
7695
7442
|
switch (ref.kind) {
|
|
7696
7443
|
case "handle": return {
|
|
7697
7444
|
ok: true,
|
|
@@ -7728,55 +7475,22 @@ function normalizeRefForBackend$1(ref, field) {
|
|
|
7728
7475
|
payeeId: nonEmptyRefValue$1(ref.payeeId, "payeeId")
|
|
7729
7476
|
}
|
|
7730
7477
|
};
|
|
7731
|
-
|
|
7478
|
+
case "party": return {
|
|
7479
|
+
ok: true,
|
|
7480
|
+
value: {
|
|
7481
|
+
kind: "party",
|
|
7482
|
+
partyId: toPartyId(ref.partyId)
|
|
7483
|
+
}
|
|
7484
|
+
};
|
|
7485
|
+
default: return {
|
|
7486
|
+
ok: false,
|
|
7487
|
+
error: Errors.invalidInput(field, "recipient must be a known Ref variant")
|
|
7488
|
+
};
|
|
7732
7489
|
}
|
|
7733
7490
|
} catch (cause) {
|
|
7734
|
-
if (cause instanceof Error && "code" in cause) return {
|
|
7735
|
-
ok: false,
|
|
7736
|
-
error: cause
|
|
7737
|
-
};
|
|
7738
7491
|
return {
|
|
7739
7492
|
ok: false,
|
|
7740
|
-
error: Errors.invalidInput(field, "recipient must be a typed Ref variant")
|
|
7741
|
-
};
|
|
7742
|
-
}
|
|
7743
|
-
}
|
|
7744
|
-
function refFromEntryId(entryId) {
|
|
7745
|
-
try {
|
|
7746
|
-
const parsed = JSON.parse(entryId);
|
|
7747
|
-
if (typeof parsed === "object" && parsed !== null && "kind" in parsed) return normalizeRefForBackend$1(parsed, "entryId");
|
|
7748
|
-
} catch {}
|
|
7749
|
-
const separator = entryId.indexOf(":");
|
|
7750
|
-
if (separator === -1) return {
|
|
7751
|
-
ok: false,
|
|
7752
|
-
error: Errors.invalidInput("entryId", "must be an address-book entry id")
|
|
7753
|
-
};
|
|
7754
|
-
const prefix = entryId.slice(0, separator);
|
|
7755
|
-
const value = entryId.slice(separator + 1);
|
|
7756
|
-
switch (prefix) {
|
|
7757
|
-
case "email": return normalizeRefForBackend$1({
|
|
7758
|
-
kind: "email",
|
|
7759
|
-
email: value
|
|
7760
|
-
}, "entryId");
|
|
7761
|
-
case "user": return normalizeRefForBackend$1({
|
|
7762
|
-
kind: "capxulUserId",
|
|
7763
|
-
capxulUserId: value
|
|
7764
|
-
}, "entryId");
|
|
7765
|
-
case "org": return normalizeRefForBackend$1({
|
|
7766
|
-
kind: "orgHandle",
|
|
7767
|
-
orgHandle: value
|
|
7768
|
-
}, "entryId");
|
|
7769
|
-
case "payee": return normalizeRefForBackend$1({
|
|
7770
|
-
kind: "payeeId",
|
|
7771
|
-
payeeId: value
|
|
7772
|
-
}, "entryId");
|
|
7773
|
-
case "handle": return normalizeRefForBackend$1({
|
|
7774
|
-
kind: "handle",
|
|
7775
|
-
handle: value
|
|
7776
|
-
}, "entryId");
|
|
7777
|
-
default: return {
|
|
7778
|
-
ok: false,
|
|
7779
|
-
error: Errors.invalidInput("entryId", "must be an address-book entry id")
|
|
7493
|
+
error: cause instanceof CapxulError ? cause : Errors.invalidInput(field, "recipient must be a typed Ref variant")
|
|
7780
7494
|
};
|
|
7781
7495
|
}
|
|
7782
7496
|
}
|
|
@@ -7790,15 +7504,6 @@ function handleRefValue$1(value, field) {
|
|
|
7790
7504
|
const trimmed = nonEmptyRefValue$1(value, field);
|
|
7791
7505
|
return trimmed.startsWith("@") ? trimmed.slice(1) : trimmed;
|
|
7792
7506
|
}
|
|
7793
|
-
function refLabel(ref) {
|
|
7794
|
-
switch (ref.kind) {
|
|
7795
|
-
case "handle": return ref.handle;
|
|
7796
|
-
case "email": return ref.email;
|
|
7797
|
-
case "orgHandle": return ref.orgHandle;
|
|
7798
|
-
case "capxulUserId": return ref.capxulUserId;
|
|
7799
|
-
case "payeeId": return ref.payeeId;
|
|
7800
|
-
}
|
|
7801
|
-
}
|
|
7802
7507
|
//#endregion
|
|
7803
7508
|
//#region ../../packages/sdk/src/surface/account.ts
|
|
7804
7509
|
const provisioningPhase = (state) => {
|
|
@@ -7821,6 +7526,10 @@ const actorFailure = (failure) => new CapxulError(failure.reason === "WORK_DIED"
|
|
|
7821
7526
|
...failure.details === void 0 ? {} : { details: failure.details },
|
|
7822
7527
|
layer: "identity"
|
|
7823
7528
|
});
|
|
7529
|
+
const accountFailureResult = (error) => ({
|
|
7530
|
+
ok: false,
|
|
7531
|
+
error
|
|
7532
|
+
});
|
|
7824
7533
|
function makeAccountMethods(deps) {
|
|
7825
7534
|
toChainId(deps.chainId);
|
|
7826
7535
|
const requirement = deps.requirement;
|
|
@@ -7963,26 +7672,16 @@ function makeAccountMethods(deps) {
|
|
|
7963
7672
|
value: provisioningPhase(deps.actor.snapshot())
|
|
7964
7673
|
};
|
|
7965
7674
|
};
|
|
7966
|
-
const reportAndReturn = (error, operation = "getLifecycle") => {
|
|
7967
|
-
if (deps.telemetry) captureExceptionSync(deps.telemetry, error, {
|
|
7968
|
-
layer: "account",
|
|
7969
|
-
operation
|
|
7970
|
-
});
|
|
7971
|
-
return {
|
|
7972
|
-
ok: false,
|
|
7973
|
-
error
|
|
7974
|
-
};
|
|
7975
|
-
};
|
|
7976
7675
|
const resolveLifecycle = async () => {
|
|
7977
7676
|
const phase = provisioningPhase(deps.actor.snapshot());
|
|
7978
7677
|
const status = await getStatus();
|
|
7979
|
-
if (!status.ok) return
|
|
7678
|
+
if (!status.ok) return accountFailureResult(status.error);
|
|
7980
7679
|
let accountId;
|
|
7981
7680
|
if (status.value.status !== "notAuthenticated" && (phase.status === "ready" || isRequirementMet(status.value, requirement))) {
|
|
7982
7681
|
const accountReadPort = deps.accountReadPort;
|
|
7983
|
-
if (accountReadPort === void 0) return
|
|
7682
|
+
if (accountReadPort === void 0) return accountFailureResult(Errors.invalidInput("account", "accountReadPort is required to resolve ready lifecycle"));
|
|
7984
7683
|
const account = await runPortEffect(accountReadPort.readBalance({ chainId: toChainId(deps.chainId) }));
|
|
7985
|
-
if (!account.ok) return
|
|
7684
|
+
if (!account.ok) return accountFailureResult(account.error);
|
|
7986
7685
|
accountId = String(account.value.id);
|
|
7987
7686
|
}
|
|
7988
7687
|
return {
|
|
@@ -8001,10 +7700,10 @@ function makeAccountMethods(deps) {
|
|
|
8001
7700
|
if (typeof resetSession === "function") try {
|
|
8002
7701
|
resetSession.call(deps.signer);
|
|
8003
7702
|
} catch (cause) {
|
|
8004
|
-
return
|
|
7703
|
+
return accountFailureResult(signerFailure(deps.signer.source, "resetSession", cause));
|
|
8005
7704
|
}
|
|
8006
7705
|
const retried = await drive({ _tag: "RetryAccount" });
|
|
8007
|
-
if (!retried.ok) return
|
|
7706
|
+
if (!retried.ok) return accountFailureResult(retried.error);
|
|
8008
7707
|
return resolveLifecycle();
|
|
8009
7708
|
};
|
|
8010
7709
|
return {
|
|
@@ -8157,7 +7856,7 @@ function cancelled(operation) {
|
|
|
8157
7856
|
function isAborted$2(signal) {
|
|
8158
7857
|
return signal?.aborted === true;
|
|
8159
7858
|
}
|
|
8160
|
-
async function signerCall(operation, run) {
|
|
7859
|
+
async function signerCall(source, operation, run) {
|
|
8161
7860
|
try {
|
|
8162
7861
|
return {
|
|
8163
7862
|
ok: true,
|
|
@@ -8166,7 +7865,7 @@ async function signerCall(operation, run) {
|
|
|
8166
7865
|
} catch (cause) {
|
|
8167
7866
|
return {
|
|
8168
7867
|
ok: false,
|
|
8169
|
-
error:
|
|
7868
|
+
error: signerFailure(source, operation, cause)
|
|
8170
7869
|
};
|
|
8171
7870
|
}
|
|
8172
7871
|
}
|
|
@@ -8178,7 +7877,7 @@ async function executePersonalPayment(deps, payment, signal, requestKey) {
|
|
|
8178
7877
|
ok: false,
|
|
8179
7878
|
error: Errors.notAuthenticated()
|
|
8180
7879
|
};
|
|
8181
|
-
const signerAddress = await signerCall("getAddress", () => deps.signer.getAddress());
|
|
7880
|
+
const signerAddress = await signerCall(deps.signer.source, "getAddress", () => deps.signer.getAddress());
|
|
8182
7881
|
if (!signerAddress.ok) return signerAddress;
|
|
8183
7882
|
const expectedSafe = deriveCapxulSafeAddress({ email: session.email });
|
|
8184
7883
|
const resolvedRequestKey = requestKey ?? `pay_${crypto.randomUUID()}`;
|
|
@@ -8197,7 +7896,7 @@ async function executePersonalPayment(deps, payment, signal, requestKey) {
|
|
|
8197
7896
|
paymentId: prepared.value.paymentId
|
|
8198
7897
|
});
|
|
8199
7898
|
if (isAborted$2(signal)) return cancelled("payments.pay");
|
|
8200
|
-
const signature = await signerCall("signUserOpHash", () => deps.signer.signUserOpHash(prepared.value.digest));
|
|
7899
|
+
const signature = await signerCall(deps.signer.source, "signUserOpHash", () => deps.signer.signUserOpHash(prepared.value.digest));
|
|
8201
7900
|
if (!signature.ok) return signature;
|
|
8202
7901
|
if (isAborted$2(signal)) return cancelled("payments.pay");
|
|
8203
7902
|
return runIfActive(void 0, "payments.submitExecution", () => deps.convexCall.action(deps.functions.submitPaymentExecution, { input: {
|
|
@@ -8210,11 +7909,11 @@ async function executePersonalPayment(deps, payment, signal, requestKey) {
|
|
|
8210
7909
|
function isAborted$1(signal) {
|
|
8211
7910
|
return signal?.aborted === true;
|
|
8212
7911
|
}
|
|
8213
|
-
|
|
8214
|
-
|
|
8215
|
-
|
|
8216
|
-
|
|
8217
|
-
|
|
7912
|
+
/** Return one stable fingerprint for one JSON payment intent. */
|
|
7913
|
+
async function fingerprintPaymentIntent(intent) {
|
|
7914
|
+
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);
|
|
7915
|
+
if (canonical === void 0) throw new TypeError("Payment intent must be JSON data");
|
|
7916
|
+
return keccak256(toBytes(canonical));
|
|
8218
7917
|
}
|
|
8219
7918
|
async function executePrepared(deps, prepare, expectedRequest, signal) {
|
|
8220
7919
|
if (isAborted$1(signal)) return {
|
|
@@ -8230,11 +7929,14 @@ async function executePrepared(deps, prepare, expectedRequest, signal) {
|
|
|
8230
7929
|
try {
|
|
8231
7930
|
signerAddress = await deps.signer.getAddress();
|
|
8232
7931
|
} catch (cause) {
|
|
8233
|
-
return
|
|
7932
|
+
return {
|
|
7933
|
+
ok: false,
|
|
7934
|
+
error: signerFailure(deps.signer.source, "getAddress", cause)
|
|
7935
|
+
};
|
|
8234
7936
|
}
|
|
8235
7937
|
const prepared = await prepare(signerAddress);
|
|
8236
7938
|
if (!prepared.ok) return prepared;
|
|
8237
|
-
if (
|
|
7939
|
+
if (await fingerprintPaymentIntent(prepared.value.request) !== await fingerprintPaymentIntent(expectedRequest)) return {
|
|
8238
7940
|
ok: false,
|
|
8239
7941
|
error: Errors.invalidInput("payment", "prepared command mismatch")
|
|
8240
7942
|
};
|
|
@@ -8251,7 +7953,10 @@ async function executePrepared(deps, prepare, expectedRequest, signal) {
|
|
|
8251
7953
|
try {
|
|
8252
7954
|
signature = await deps.signer.signUserOpHash(prepared.value.digest);
|
|
8253
7955
|
} catch (cause) {
|
|
8254
|
-
return
|
|
7956
|
+
return {
|
|
7957
|
+
ok: false,
|
|
7958
|
+
error: signerFailure(deps.signer.source, "signUserOpHash", cause)
|
|
7959
|
+
};
|
|
8255
7960
|
}
|
|
8256
7961
|
if (isAborted$1(signal)) return {
|
|
8257
7962
|
ok: false,
|
|
@@ -8350,36 +8055,36 @@ async function paymentRequestKeyLifecycle(operation, intent, provided) {
|
|
|
8350
8055
|
key: provided,
|
|
8351
8056
|
finish: async () => void 0
|
|
8352
8057
|
};
|
|
8353
|
-
const slot = `capxul.payment.request-key.v3:${await fingerprintPaymentIntent({
|
|
8354
|
-
operation,
|
|
8355
|
-
intent
|
|
8356
|
-
})}`;
|
|
8357
|
-
if (typeof window === "undefined") {
|
|
8358
|
-
const attemptId = randomPaymentRequestKey();
|
|
8359
|
-
const state = memoryPaymentRequestKeys.get(slot) ?? {
|
|
8360
|
-
key: randomPaymentRequestKey(),
|
|
8361
|
-
active: [],
|
|
8362
|
-
resolved: false
|
|
8363
|
-
};
|
|
8364
|
-
state.active.push(attemptId);
|
|
8365
|
-
memoryPaymentRequestKeys.set(slot, state);
|
|
8366
|
-
let finished = false;
|
|
8367
|
-
return {
|
|
8368
|
-
key: state.key,
|
|
8369
|
-
finish: async (succeeded) => {
|
|
8370
|
-
if (finished) return;
|
|
8371
|
-
finished = true;
|
|
8372
|
-
const attemptIndex = state.active.indexOf(attemptId);
|
|
8373
|
-
if (attemptIndex < 0) return;
|
|
8374
|
-
state.active.splice(attemptIndex, 1);
|
|
8375
|
-
state.resolved = succeeded;
|
|
8376
|
-
if (state.active.length === 0 && state.resolved) memoryPaymentRequestKeys.delete(slot);
|
|
8377
|
-
}
|
|
8378
|
-
};
|
|
8379
|
-
}
|
|
8380
8058
|
let releaseAttemptLock;
|
|
8381
8059
|
let forgetPagehideRelease;
|
|
8382
8060
|
try {
|
|
8061
|
+
const slot = `capxul.payment.request-key.v3:${await fingerprintPaymentIntent({
|
|
8062
|
+
operation,
|
|
8063
|
+
intent
|
|
8064
|
+
})}`;
|
|
8065
|
+
if (typeof window === "undefined") {
|
|
8066
|
+
const attemptId = randomPaymentRequestKey();
|
|
8067
|
+
const state = memoryPaymentRequestKeys.get(slot) ?? {
|
|
8068
|
+
key: randomPaymentRequestKey(),
|
|
8069
|
+
active: [],
|
|
8070
|
+
resolved: false
|
|
8071
|
+
};
|
|
8072
|
+
state.active.push(attemptId);
|
|
8073
|
+
memoryPaymentRequestKeys.set(slot, state);
|
|
8074
|
+
let finished = false;
|
|
8075
|
+
return {
|
|
8076
|
+
key: state.key,
|
|
8077
|
+
finish: async (succeeded) => {
|
|
8078
|
+
if (finished) return;
|
|
8079
|
+
finished = true;
|
|
8080
|
+
const attemptIndex = state.active.indexOf(attemptId);
|
|
8081
|
+
if (attemptIndex < 0) return;
|
|
8082
|
+
state.active.splice(attemptIndex, 1);
|
|
8083
|
+
state.resolved = succeeded;
|
|
8084
|
+
if (state.active.length === 0 && state.resolved) memoryPaymentRequestKeys.delete(slot);
|
|
8085
|
+
}
|
|
8086
|
+
};
|
|
8087
|
+
}
|
|
8383
8088
|
const attemptId = randomPaymentRequestKey();
|
|
8384
8089
|
releaseAttemptLock = await holdPaymentAttemptLock(paymentAttemptLockName(slot, attemptId));
|
|
8385
8090
|
forgetPagehideRelease = releasePaymentAttemptOnPagehide(releaseAttemptLock);
|
|
@@ -8434,13 +8139,20 @@ async function paymentRequestKeyLifecycle(operation, intent, provided) {
|
|
|
8434
8139
|
throw Errors.providerError("sdk", "paymentRequestKey", cause);
|
|
8435
8140
|
}
|
|
8436
8141
|
}
|
|
8142
|
+
function paymentSubmissionFailure(cause) {
|
|
8143
|
+
return {
|
|
8144
|
+
ok: false,
|
|
8145
|
+
error: cause instanceof CapxulError ? cause : Errors.unknown(cause)
|
|
8146
|
+
};
|
|
8147
|
+
}
|
|
8437
8148
|
async function waitForPaymentSubmission(submission, signal, operation, onCancel = () => false) {
|
|
8438
|
-
|
|
8439
|
-
if (signal
|
|
8149
|
+
const foldedSubmission = submission.catch((cause) => paymentSubmissionFailure(cause));
|
|
8150
|
+
if (signal === void 0) return foldedSubmission;
|
|
8151
|
+
if (signal.aborted) return onCancel() ? foldedSubmission : {
|
|
8440
8152
|
ok: false,
|
|
8441
8153
|
error: Errors.cancelled({ operation })
|
|
8442
8154
|
};
|
|
8443
|
-
return new Promise((resolve
|
|
8155
|
+
return new Promise((resolve) => {
|
|
8444
8156
|
const onAbort = () => {
|
|
8445
8157
|
signal.removeEventListener("abort", onAbort);
|
|
8446
8158
|
if (!onCancel()) resolve({
|
|
@@ -8449,21 +8161,12 @@ async function waitForPaymentSubmission(submission, signal, operation, onCancel
|
|
|
8449
8161
|
});
|
|
8450
8162
|
};
|
|
8451
8163
|
signal.addEventListener("abort", onAbort, { once: true });
|
|
8452
|
-
|
|
8164
|
+
foldedSubmission.then((result) => {
|
|
8453
8165
|
signal.removeEventListener("abort", onAbort);
|
|
8454
8166
|
resolve(result);
|
|
8455
|
-
}, (cause) => {
|
|
8456
|
-
signal.removeEventListener("abort", onAbort);
|
|
8457
|
-
reject(cause instanceof Error ? cause : new Error(String(cause)));
|
|
8458
8167
|
});
|
|
8459
8168
|
});
|
|
8460
8169
|
}
|
|
8461
|
-
/** Return one stable fingerprint for one JSON payment intent. */
|
|
8462
|
-
async function fingerprintPaymentIntent(intent) {
|
|
8463
|
-
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);
|
|
8464
|
-
if (canonical === void 0) throw new TypeError("Payment intent must be JSON data");
|
|
8465
|
-
return keccak256(toBytes(canonical));
|
|
8466
|
-
}
|
|
8467
8170
|
function paymentExecutionIntent(input) {
|
|
8468
8171
|
if (actorReferenceToBackend(input.actor)?.kind === "org") return {
|
|
8469
8172
|
ok: false,
|
|
@@ -8505,7 +8208,7 @@ function makeFinancialOpsMethods(deps) {
|
|
|
8505
8208
|
} catch (cause) {
|
|
8506
8209
|
return {
|
|
8507
8210
|
ok: false,
|
|
8508
|
-
error: cause instanceof CapxulError ? cause : Errors.
|
|
8211
|
+
error: cause instanceof CapxulError ? cause : Errors.unknown(cause)
|
|
8509
8212
|
};
|
|
8510
8213
|
}
|
|
8511
8214
|
const sharedKey = `${requestKeyScope}:${requestKey.key}`;
|
|
@@ -8553,7 +8256,10 @@ function makeFinancialOpsMethods(deps) {
|
|
|
8553
8256
|
try {
|
|
8554
8257
|
await requestKey.finish(false);
|
|
8555
8258
|
} catch {}
|
|
8556
|
-
|
|
8259
|
+
return {
|
|
8260
|
+
ok: false,
|
|
8261
|
+
error: cause instanceof CapxulError ? cause : Errors.unknown(cause)
|
|
8262
|
+
};
|
|
8557
8263
|
}
|
|
8558
8264
|
release(false);
|
|
8559
8265
|
try {
|
|
@@ -8577,11 +8283,25 @@ function makeFinancialOpsMethods(deps) {
|
|
|
8577
8283
|
const runLifecycle = async (intent, signal) => {
|
|
8578
8284
|
const execution = lifecycleDependencies();
|
|
8579
8285
|
if (!execution.ok) return execution;
|
|
8580
|
-
|
|
8581
|
-
const
|
|
8582
|
-
if (
|
|
8583
|
-
|
|
8584
|
-
|
|
8286
|
+
try {
|
|
8287
|
+
const submitted = await executePaymentLifecycle(execution.value, intent, signal);
|
|
8288
|
+
if (!submitted.ok) return submitted;
|
|
8289
|
+
const payments = submitted.value.payments;
|
|
8290
|
+
const payment = payments[0];
|
|
8291
|
+
if (payment === void 0 || payments.length !== 1) return {
|
|
8292
|
+
ok: false,
|
|
8293
|
+
error: Errors.unknown()
|
|
8294
|
+
};
|
|
8295
|
+
return {
|
|
8296
|
+
ok: true,
|
|
8297
|
+
value: normalizePaymentTiming(payment)
|
|
8298
|
+
};
|
|
8299
|
+
} catch (cause) {
|
|
8300
|
+
return {
|
|
8301
|
+
ok: false,
|
|
8302
|
+
error: cause instanceof CapxulError ? cause : Errors.unknown(cause)
|
|
8303
|
+
};
|
|
8304
|
+
}
|
|
8585
8305
|
};
|
|
8586
8306
|
return {
|
|
8587
8307
|
me: {
|
|
@@ -8632,9 +8352,10 @@ function makeFinancialOpsMethods(deps) {
|
|
|
8632
8352
|
value: resolvedTargetFromPayee(reference, payee.value)
|
|
8633
8353
|
};
|
|
8634
8354
|
}
|
|
8355
|
+
case "party":
|
|
8635
8356
|
case "destination": return Promise.resolve({
|
|
8636
8357
|
ok: false,
|
|
8637
|
-
error: Errors.notImplemented("targets",
|
|
8358
|
+
error: Errors.notImplemented("targets", `resolve.${reference.kind}`)
|
|
8638
8359
|
});
|
|
8639
8360
|
}
|
|
8640
8361
|
} },
|
|
@@ -8768,8 +8489,14 @@ function handleRefValue(value, field) {
|
|
|
8768
8489
|
}
|
|
8769
8490
|
function refFromTargetReference(reference, field) {
|
|
8770
8491
|
try {
|
|
8771
|
-
if (typeof reference === "string")
|
|
8772
|
-
|
|
8492
|
+
if (typeof reference === "string") return {
|
|
8493
|
+
ok: false,
|
|
8494
|
+
error: Errors.invalidInput(field, "target must be a typed TargetReference variant")
|
|
8495
|
+
};
|
|
8496
|
+
if (typeof reference !== "object" || reference === null || !("kind" in reference)) return {
|
|
8497
|
+
ok: false,
|
|
8498
|
+
error: Errors.invalidInput(field, "target must be a typed TargetReference variant")
|
|
8499
|
+
};
|
|
8773
8500
|
switch (reference.kind) {
|
|
8774
8501
|
case "handle": return {
|
|
8775
8502
|
ok: true,
|
|
@@ -8799,20 +8526,26 @@ function refFromTargetReference(reference, field) {
|
|
|
8799
8526
|
payeeId: reference.id
|
|
8800
8527
|
}
|
|
8801
8528
|
};
|
|
8529
|
+
case "party": return {
|
|
8530
|
+
ok: true,
|
|
8531
|
+
value: {
|
|
8532
|
+
kind: "party",
|
|
8533
|
+
partyId: reference.partyId
|
|
8534
|
+
}
|
|
8535
|
+
};
|
|
8802
8536
|
case "destination": return {
|
|
8803
8537
|
ok: false,
|
|
8804
8538
|
error: Errors.notImplemented("targets", "reference.destination")
|
|
8805
8539
|
};
|
|
8806
|
-
default:
|
|
8540
|
+
default: return {
|
|
8541
|
+
ok: false,
|
|
8542
|
+
error: Errors.invalidInput(field, "target must be a known TargetReference variant")
|
|
8543
|
+
};
|
|
8807
8544
|
}
|
|
8808
8545
|
} catch (cause) {
|
|
8809
|
-
if (cause instanceof Error && "code" in cause) return {
|
|
8810
|
-
ok: false,
|
|
8811
|
-
error: cause
|
|
8812
|
-
};
|
|
8813
8546
|
return {
|
|
8814
8547
|
ok: false,
|
|
8815
|
-
error: Errors.invalidInput(field, "target must be a typed TargetReference variant")
|
|
8548
|
+
error: cause instanceof CapxulError ? cause : Errors.invalidInput(field, "target must be a typed TargetReference variant")
|
|
8816
8549
|
};
|
|
8817
8550
|
}
|
|
8818
8551
|
}
|
|
@@ -8866,6 +8599,10 @@ function targetReferenceFromBackendRef(ref) {
|
|
|
8866
8599
|
kind: "payee",
|
|
8867
8600
|
id: ref.payeeId
|
|
8868
8601
|
};
|
|
8602
|
+
case "party": return {
|
|
8603
|
+
kind: "party",
|
|
8604
|
+
partyId: ref.partyId
|
|
8605
|
+
};
|
|
8869
8606
|
case "capxulUserId": throw Errors.notImplemented("targets", "reference.capxulUserId");
|
|
8870
8607
|
}
|
|
8871
8608
|
}
|
|
@@ -8952,8 +8689,14 @@ function normalizeDestinationRefForBackend(ref, field) {
|
|
|
8952
8689
|
}
|
|
8953
8690
|
function normalizeRefForBackend(ref, field) {
|
|
8954
8691
|
try {
|
|
8955
|
-
if (typeof ref === "string")
|
|
8956
|
-
|
|
8692
|
+
if (typeof ref === "string") return {
|
|
8693
|
+
ok: false,
|
|
8694
|
+
error: Errors.invalidInput(field, "recipient must be a typed Ref variant")
|
|
8695
|
+
};
|
|
8696
|
+
if (typeof ref !== "object" || ref === null || !("kind" in ref)) return {
|
|
8697
|
+
ok: false,
|
|
8698
|
+
error: Errors.invalidInput(field, "recipient must be a typed Ref variant")
|
|
8699
|
+
};
|
|
8957
8700
|
switch (ref.kind) {
|
|
8958
8701
|
case "handle": return {
|
|
8959
8702
|
ok: true,
|
|
@@ -8990,16 +8733,22 @@ function normalizeRefForBackend(ref, field) {
|
|
|
8990
8733
|
payeeId: nonEmptyRefValue(ref.payeeId, "payeeId")
|
|
8991
8734
|
}
|
|
8992
8735
|
};
|
|
8993
|
-
|
|
8736
|
+
case "party": return {
|
|
8737
|
+
ok: true,
|
|
8738
|
+
value: {
|
|
8739
|
+
kind: "party",
|
|
8740
|
+
partyId: toPartyId(ref.partyId)
|
|
8741
|
+
}
|
|
8742
|
+
};
|
|
8743
|
+
default: return {
|
|
8744
|
+
ok: false,
|
|
8745
|
+
error: Errors.invalidInput(field, "recipient must be a known Ref variant")
|
|
8746
|
+
};
|
|
8994
8747
|
}
|
|
8995
8748
|
} catch (cause) {
|
|
8996
|
-
if (cause instanceof Error && "code" in cause) return {
|
|
8997
|
-
ok: false,
|
|
8998
|
-
error: cause
|
|
8999
|
-
};
|
|
9000
8749
|
return {
|
|
9001
8750
|
ok: false,
|
|
9002
|
-
error: Errors.invalidInput(field, "recipient must be a typed Ref variant")
|
|
8751
|
+
error: cause instanceof CapxulError ? cause : Errors.invalidInput(field, "recipient must be a typed Ref variant")
|
|
9003
8752
|
};
|
|
9004
8753
|
}
|
|
9005
8754
|
}
|
|
@@ -9018,11 +8767,10 @@ function mapOk(result, f) {
|
|
|
9018
8767
|
value: f(result.value)
|
|
9019
8768
|
};
|
|
9020
8769
|
} catch (cause) {
|
|
9021
|
-
|
|
8770
|
+
return {
|
|
9022
8771
|
ok: false,
|
|
9023
|
-
error: cause
|
|
8772
|
+
error: cause instanceof CapxulError ? cause : Errors.unknown(cause)
|
|
9024
8773
|
};
|
|
9025
|
-
throw cause;
|
|
9026
8774
|
}
|
|
9027
8775
|
}
|
|
9028
8776
|
//#endregion
|
|
@@ -9190,7 +8938,7 @@ async function recoverRawDigestSigner(input) {
|
|
|
9190
8938
|
}
|
|
9191
8939
|
//#endregion
|
|
9192
8940
|
//#region ../../packages/sdk/package.json
|
|
9193
|
-
var version = "2.
|
|
8941
|
+
var version = "2.2.0";
|
|
9194
8942
|
//#endregion
|
|
9195
8943
|
//#region ../../packages/observability/src/engineering.ts
|
|
9196
8944
|
const SAFE_TRACED_HEADER_NAMES = [
|
|
@@ -13287,9 +13035,27 @@ function mapToCapxulError(operation, err) {
|
|
|
13287
13035
|
function mapToConvexCallError(operation, err) {
|
|
13288
13036
|
return convexCallErrorFromCapxul(operation, mapToCapxulError(operation, err));
|
|
13289
13037
|
}
|
|
13038
|
+
const TRANSPORT_ERROR_CODES = new Set([
|
|
13039
|
+
"EAI_AGAIN",
|
|
13040
|
+
"ECONNREFUSED",
|
|
13041
|
+
"ECONNRESET",
|
|
13042
|
+
"ENOTFOUND",
|
|
13043
|
+
"EPIPE",
|
|
13044
|
+
"ETIMEDOUT",
|
|
13045
|
+
"UND_ERR_CONNECT_TIMEOUT",
|
|
13046
|
+
"UND_ERR_HEADERS_TIMEOUT",
|
|
13047
|
+
"UND_ERR_SOCKET"
|
|
13048
|
+
]);
|
|
13290
13049
|
function isTransportError(err) {
|
|
13291
|
-
const
|
|
13292
|
-
|
|
13050
|
+
const seen = /* @__PURE__ */ new Set();
|
|
13051
|
+
let current = err;
|
|
13052
|
+
while (current !== void 0 && !seen.has(current)) {
|
|
13053
|
+
seen.add(current);
|
|
13054
|
+
const code = current.code;
|
|
13055
|
+
if (current.name === "FetchError" || current.name === "NetworkError" || typeof code === "string" && TRANSPORT_ERROR_CODES.has(code)) return true;
|
|
13056
|
+
current = current.cause instanceof Error ? current.cause : void 0;
|
|
13057
|
+
}
|
|
13058
|
+
return false;
|
|
13293
13059
|
}
|
|
13294
13060
|
//#endregion
|
|
13295
13061
|
//#region ../../packages/sdk/src/ports/identity.ts
|
|
@@ -13780,7 +13546,7 @@ var ConvexOrganizationSetupAdapter = class {
|
|
|
13780
13546
|
if (!lifecycle.ok) return lifecycle;
|
|
13781
13547
|
const orgId = parseOrgId("startOrResume", result.value.orgId);
|
|
13782
13548
|
if (!orgId.ok) return orgId;
|
|
13783
|
-
if (String(orgId.value) !== String(lifecycle.value.orgId)) return fail$
|
|
13549
|
+
if (String(orgId.value) !== String(lifecycle.value.orgId)) return fail$1(Errors.invalidInput("orgId", "Organization lifecycle scope does not match"));
|
|
13784
13550
|
return {
|
|
13785
13551
|
ok: true,
|
|
13786
13552
|
value: {
|
|
@@ -13798,7 +13564,7 @@ var ConvexOrganizationSetupAdapter = class {
|
|
|
13798
13564
|
async authorizeAndSubmitBootstrap(input) {
|
|
13799
13565
|
const cancelled = cancellation(input.signal);
|
|
13800
13566
|
if (cancelled !== void 0) return cancelled;
|
|
13801
|
-
const signerAddress = await signerResult("getAddress", () => this.#signer.getAddress());
|
|
13567
|
+
const signerAddress = await signerResult(this.#signer.source, "getAddress", () => this.#signer.getAddress());
|
|
13802
13568
|
if (!signerAddress.ok) return signerAddress;
|
|
13803
13569
|
const prepared = await runCall("prepareBootstrap", this.#convex.action(this.#fns.prepareBootstrap, copyInvocationObservation(input, {
|
|
13804
13570
|
orgId: input.orgId,
|
|
@@ -13810,7 +13576,7 @@ var ConvexOrganizationSetupAdapter = class {
|
|
|
13810
13576
|
if (!authority.ok) return authority;
|
|
13811
13577
|
const cancelledAfterPrepare = cancellation(input.signal);
|
|
13812
13578
|
if (cancelledAfterPrepare !== void 0) return cancelledAfterPrepare;
|
|
13813
|
-
const signature = await signerResult("signUserOpHash", () => this.#signer.signUserOpHash(prepared.value.digest));
|
|
13579
|
+
const signature = await signerResult(this.#signer.source, "signUserOpHash", () => this.#signer.signUserOpHash(prepared.value.digest));
|
|
13814
13580
|
if (!signature.ok) return signature;
|
|
13815
13581
|
const cancelledAfterSign = cancellation(input.signal);
|
|
13816
13582
|
if (cancelledAfterSign !== void 0) return cancelledAfterSign;
|
|
@@ -13854,7 +13620,7 @@ var ConvexOrganizationSetupAdapter = class {
|
|
|
13854
13620
|
async loadLifecycle(input) {
|
|
13855
13621
|
const result = await runCall("loadLifecycle", this.#convex.query(this.#fns.load, input));
|
|
13856
13622
|
if (!result.ok) return result;
|
|
13857
|
-
if (result.value === null) return fail$
|
|
13623
|
+
if (result.value === null) return fail$1(Errors.invalidInput("orgId", "Organization lifecycle was not found"));
|
|
13858
13624
|
return parseLifecycle("loadLifecycle", result.value);
|
|
13859
13625
|
}
|
|
13860
13626
|
async retry(input) {
|
|
@@ -13899,7 +13665,7 @@ function resetSignerSession(signer) {
|
|
|
13899
13665
|
value: void 0
|
|
13900
13666
|
};
|
|
13901
13667
|
} catch (cause) {
|
|
13902
|
-
return fail$
|
|
13668
|
+
return fail$1(signerFailure(signer.source, "resetSession", cause));
|
|
13903
13669
|
}
|
|
13904
13670
|
}
|
|
13905
13671
|
async function runCall(operation, effect) {
|
|
@@ -13908,9 +13674,9 @@ async function runCall(operation, effect) {
|
|
|
13908
13674
|
return Result.isSuccess(result) ? {
|
|
13909
13675
|
ok: true,
|
|
13910
13676
|
value: result.success
|
|
13911
|
-
} : fail$
|
|
13677
|
+
} : fail$1(publicError(operation, result.failure));
|
|
13912
13678
|
} catch (cause) {
|
|
13913
|
-
return fail$
|
|
13679
|
+
return fail$1(publicError(operation, cause));
|
|
13914
13680
|
}
|
|
13915
13681
|
}
|
|
13916
13682
|
function publicError(operation, cause) {
|
|
@@ -13921,14 +13687,14 @@ function publicError(operation, cause) {
|
|
|
13921
13687
|
}
|
|
13922
13688
|
return Errors.providerError("convex-organization", operation, cause);
|
|
13923
13689
|
}
|
|
13924
|
-
async function signerResult(operation, run) {
|
|
13690
|
+
async function signerResult(source, operation, run) {
|
|
13925
13691
|
try {
|
|
13926
13692
|
return {
|
|
13927
13693
|
ok: true,
|
|
13928
13694
|
value: await run()
|
|
13929
13695
|
};
|
|
13930
13696
|
} catch (cause) {
|
|
13931
|
-
return fail$
|
|
13697
|
+
return fail$1(signerFailure(source, operation, cause));
|
|
13932
13698
|
}
|
|
13933
13699
|
}
|
|
13934
13700
|
function validatePreparedAuthorities(prepared, signerAddress) {
|
|
@@ -13937,10 +13703,10 @@ function validatePreparedAuthorities(prepared, signerAddress) {
|
|
|
13937
13703
|
const founder = prepared.founderPersonalAccount.toLowerCase();
|
|
13938
13704
|
const organization = prepared.organizationAccountAddress.toLowerCase();
|
|
13939
13705
|
const sender = prepared.userOp.sender.toLowerCase();
|
|
13940
|
-
if (preparedSigner !== signer) return fail$
|
|
13941
|
-
if (founder === signer || organization === signer || organization === founder) return fail$
|
|
13942
|
-
if (sender !== founder) return fail$
|
|
13943
|
-
if (!/^0x[0-9a-fA-F]{64}$/u.test(prepared.digest)) return fail$
|
|
13706
|
+
if (preparedSigner !== signer) return fail$1(Errors.invalidInput("signerAddress", "Prepared signer does not match configured signer"));
|
|
13707
|
+
if (founder === signer || organization === signer || organization === founder) return fail$1(Errors.invalidInput("organizationAuthority", "Signer EOA, founder Account, and Organization Account must be distinct"));
|
|
13708
|
+
if (sender !== founder) return fail$1(Errors.invalidInput("userOp.sender", "Bootstrap sender must be the founder Account"));
|
|
13709
|
+
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"));
|
|
13944
13710
|
return {
|
|
13945
13711
|
ok: true,
|
|
13946
13712
|
value: void 0
|
|
@@ -13965,7 +13731,7 @@ function parseLifecycle(operation, wire) {
|
|
|
13965
13731
|
}
|
|
13966
13732
|
};
|
|
13967
13733
|
if (wire.status === "failed") {
|
|
13968
|
-
if (!isSetupStep(wire.at)) return fail$
|
|
13734
|
+
if (!isSetupStep(wire.at)) return fail$1(Errors.invalidInput("lifecycle.at", "Unknown setup step"));
|
|
13969
13735
|
return {
|
|
13970
13736
|
ok: true,
|
|
13971
13737
|
value: {
|
|
@@ -13977,7 +13743,7 @@ function parseLifecycle(operation, wire) {
|
|
|
13977
13743
|
}
|
|
13978
13744
|
};
|
|
13979
13745
|
}
|
|
13980
|
-
if (!isSetupStep(wire.step)) return fail$
|
|
13746
|
+
if (!isSetupStep(wire.step)) return fail$1(Errors.invalidInput("lifecycle.step", `Unknown setup step from ${operation}`));
|
|
13981
13747
|
return {
|
|
13982
13748
|
ok: true,
|
|
13983
13749
|
value: {
|
|
@@ -13994,16 +13760,16 @@ function parseOrgId(operation, value) {
|
|
|
13994
13760
|
value: toOrgId(value)
|
|
13995
13761
|
};
|
|
13996
13762
|
} catch (cause) {
|
|
13997
|
-
return fail$
|
|
13763
|
+
return fail$1(Errors.providerError("convex-organization", operation, cause));
|
|
13998
13764
|
}
|
|
13999
13765
|
}
|
|
14000
13766
|
function isSetupStep(value) {
|
|
14001
13767
|
return value === "preparingFounderAccount" || value === "awaitingFounderAuthorization" || value === "submittingBootstrap" || value === "confirmingBootstrap";
|
|
14002
13768
|
}
|
|
14003
13769
|
function cancellation(signal) {
|
|
14004
|
-
return signal?.aborted ? fail$
|
|
13770
|
+
return signal?.aborted ? fail$1(Errors.cancelled({ operation: "organization.setup" })) : void 0;
|
|
14005
13771
|
}
|
|
14006
|
-
function fail$
|
|
13772
|
+
function fail$1(error) {
|
|
14007
13773
|
return {
|
|
14008
13774
|
ok: false,
|
|
14009
13775
|
error
|
|
@@ -37394,28 +37160,20 @@ function clearStaleOpenfortBrowserStorage(publishableKey) {
|
|
|
37394
37160
|
}
|
|
37395
37161
|
function createOpenfortBrowserSignerFromBootstrap(bootstrap, options = {}) {
|
|
37396
37162
|
const diagnostic = options.diagnostic;
|
|
37397
|
-
const telemetry = options.telemetry;
|
|
37398
37163
|
const authBaseUrl = normalizeBetterAuthBaseUrl(bootstrap.authBaseUrl);
|
|
37399
37164
|
/**
|
|
37400
37165
|
* Closes the black hole: when the browser has no Web Crypto, OpenFort's
|
|
37401
37166
|
* `configure` would resolve to no address and the failure would be reported
|
|
37402
37167
|
* as `unknown`. Detect it before any network/wallet work, tag it
|
|
37403
37168
|
* `no-secure-context` on a PROVIDER_ERROR scoped to `configure`, breadcrumb
|
|
37404
|
-
* it via DiagnosticPort
|
|
37169
|
+
* it via DiagnosticPort. The assembled Core SDK boundary reports the error.
|
|
37405
37170
|
*/
|
|
37406
37171
|
function failNoSecureContext() {
|
|
37407
37172
|
diagnostic?.trace("openfort.configure", {
|
|
37408
37173
|
ok: false,
|
|
37409
37174
|
failure_mode: "no-secure-context"
|
|
37410
37175
|
});
|
|
37411
|
-
|
|
37412
|
-
if (telemetry) captureExceptionSync(telemetry, error, {
|
|
37413
|
-
layer: "openfort",
|
|
37414
|
-
operation: "configure",
|
|
37415
|
-
provider: "openfort",
|
|
37416
|
-
failure_mode: "no-secure-context"
|
|
37417
|
-
});
|
|
37418
|
-
throw error;
|
|
37176
|
+
throw Errors.providerError("openfort", "configure", /* @__PURE__ */ new Error("Web Crypto unavailable: browser is not a secure context"), { failure_mode: "no-secure-context" });
|
|
37419
37177
|
}
|
|
37420
37178
|
function betterAuthSessionUrl() {
|
|
37421
37179
|
return `${authBaseUrl}/get-session`;
|
|
@@ -37674,7 +37432,7 @@ const modelSession = (session) => ({
|
|
|
37674
37432
|
});
|
|
37675
37433
|
const claimAccount = (input, authUserId, signer) => call("smart-account.claim", Effect.tryPromise({
|
|
37676
37434
|
try: () => signer.getAddress(),
|
|
37677
|
-
catch: (cause) =>
|
|
37435
|
+
catch: (cause) => signerFailure(signer.source, "getAddress", cause)
|
|
37678
37436
|
}).pipe(Effect.flatMap((signerAddress) => input.ports.smartAccount.claim({
|
|
37679
37437
|
authUserId: toAuthUserId(authUserId),
|
|
37680
37438
|
chainId: toChainId(input.chainId),
|
|
@@ -38609,12 +38367,6 @@ const permissionContract = { read: makeFunctionReference(CAPXUL_FUNCTIONS["permi
|
|
|
38609
38367
|
function isAborted(signal) {
|
|
38610
38368
|
return signal?.aborted === true;
|
|
38611
38369
|
}
|
|
38612
|
-
function fail$1(cause, operation) {
|
|
38613
|
-
return {
|
|
38614
|
-
ok: false,
|
|
38615
|
-
error: cause instanceof CapxulError ? cause : Errors.providerError("wallet-signer", operation, cause)
|
|
38616
|
-
};
|
|
38617
|
-
}
|
|
38618
38370
|
async function execute(deps, orgId, command, signal) {
|
|
38619
38371
|
if (isAborted(signal)) return {
|
|
38620
38372
|
ok: false,
|
|
@@ -38633,7 +38385,10 @@ async function execute(deps, orgId, command, signal) {
|
|
|
38633
38385
|
try {
|
|
38634
38386
|
signerAddress = await deps.signer.getAddress();
|
|
38635
38387
|
} catch (cause) {
|
|
38636
|
-
return
|
|
38388
|
+
return {
|
|
38389
|
+
ok: false,
|
|
38390
|
+
error: signerFailure(deps.signer.source, "getAddress", cause)
|
|
38391
|
+
};
|
|
38637
38392
|
}
|
|
38638
38393
|
const executionFns = deps.executionFunctions ?? moneyExecutionContract;
|
|
38639
38394
|
const prepared = await runIfActive(signal, "permissions.prepareExecution", () => deps.convexCall.action(executionFns.preparePermissionExecution, { input: {
|
|
@@ -38655,7 +38410,10 @@ async function execute(deps, orgId, command, signal) {
|
|
|
38655
38410
|
try {
|
|
38656
38411
|
signature = await deps.signer.signUserOpHash(prepared.value.digest);
|
|
38657
38412
|
} catch (cause) {
|
|
38658
|
-
return
|
|
38413
|
+
return {
|
|
38414
|
+
ok: false,
|
|
38415
|
+
error: signerFailure(deps.signer.source, "signUserOpHash", cause)
|
|
38416
|
+
};
|
|
38659
38417
|
}
|
|
38660
38418
|
if (isAborted(signal)) return {
|
|
38661
38419
|
ok: false,
|
|
@@ -38733,7 +38491,7 @@ function makeOrganizationPaymentsMethods(deps, orgId) {
|
|
|
38733
38491
|
} catch (cause) {
|
|
38734
38492
|
return {
|
|
38735
38493
|
ok: false,
|
|
38736
|
-
error: cause instanceof CapxulError ? cause : Errors.
|
|
38494
|
+
error: cause instanceof CapxulError ? cause : Errors.unknown(cause)
|
|
38737
38495
|
};
|
|
38738
38496
|
}
|
|
38739
38497
|
const flightKey = `${requestKeyScope}:${operation}:${requestKey.key}`;
|
|
@@ -38780,16 +38538,16 @@ function makeOrganizationPaymentsMethods(deps, orgId) {
|
|
|
38780
38538
|
try {
|
|
38781
38539
|
await requestKey.finish(false);
|
|
38782
38540
|
} catch {}
|
|
38783
|
-
|
|
38541
|
+
return {
|
|
38542
|
+
ok: false,
|
|
38543
|
+
error: cause instanceof CapxulError ? cause : Errors.unknown(cause)
|
|
38544
|
+
};
|
|
38784
38545
|
}
|
|
38785
38546
|
release(false);
|
|
38786
38547
|
try {
|
|
38787
38548
|
await requestKey.finish(result.ok);
|
|
38788
38549
|
} catch {}
|
|
38789
|
-
return result.
|
|
38790
|
-
ok: true,
|
|
38791
|
-
value: result.value.payments.map((payment) => normalizePaymentTiming(payment))
|
|
38792
|
-
} : result;
|
|
38550
|
+
return mapOk(result, (value) => value.payments.map((payment) => normalizePaymentTiming(payment)));
|
|
38793
38551
|
};
|
|
38794
38552
|
return {
|
|
38795
38553
|
pay: async (input, options) => {
|
|
@@ -39540,18 +39298,104 @@ function detectAuthCacheAdapter() {
|
|
|
39540
39298
|
return new InMemoryAuthCacheAdapter();
|
|
39541
39299
|
}
|
|
39542
39300
|
//#endregion
|
|
39301
|
+
//#region ../../packages/sdk/src/telemetry/capture-exception.ts
|
|
39302
|
+
/** Fixed, leak-safe message — the raw error message may carry PII and never ships. */
|
|
39303
|
+
const EXCEPTION_MESSAGE = "Capxul SDK operation failed";
|
|
39304
|
+
//#endregion
|
|
39543
39305
|
//#region ../../packages/sdk/src/observation.ts
|
|
39544
39306
|
const SDK_VERSION$1 = version;
|
|
39307
|
+
/** @internal Observe public result methods at the assembled Core SDK boundary. */
|
|
39308
|
+
function observeSdkClient(client, adapter, snapshot) {
|
|
39309
|
+
if (adapter === void 0) return client;
|
|
39310
|
+
const objectProxies = /* @__PURE__ */ new WeakMap();
|
|
39311
|
+
const proxyTargets = /* @__PURE__ */ new WeakMap();
|
|
39312
|
+
const functionWrappers = /* @__PURE__ */ new WeakMap();
|
|
39313
|
+
const wrapObject = (target, path, internal = false) => {
|
|
39314
|
+
const cacheKey = `${internal ? "internal" : "public"}:${path.join(".")}`;
|
|
39315
|
+
let targetProxies = objectProxies.get(target);
|
|
39316
|
+
const cached = targetProxies?.get(cacheKey);
|
|
39317
|
+
if (cached !== void 0) return cached;
|
|
39318
|
+
const proxy = new Proxy(target, { get(currentTarget, property, receiver) {
|
|
39319
|
+
const value = Reflect.get(currentTarget, property, receiver);
|
|
39320
|
+
if (typeof property !== "string") return value;
|
|
39321
|
+
if (path.length === 0 && property === "_internal" && isPlainObject(value)) return wrapObject(value, ["_internal"], true);
|
|
39322
|
+
if (internal && property !== "accounts") return value;
|
|
39323
|
+
return wrapValue(value, [...path, property], currentTarget);
|
|
39324
|
+
} });
|
|
39325
|
+
proxyTargets.set(proxy, target);
|
|
39326
|
+
if (targetProxies === void 0) {
|
|
39327
|
+
targetProxies = /* @__PURE__ */ new Map();
|
|
39328
|
+
objectProxies.set(target, targetProxies);
|
|
39329
|
+
}
|
|
39330
|
+
targetProxies.set(cacheKey, proxy);
|
|
39331
|
+
return proxy;
|
|
39332
|
+
};
|
|
39333
|
+
const wrapValue = (value, path, owner) => {
|
|
39334
|
+
if (typeof value === "function") {
|
|
39335
|
+
const callable = value;
|
|
39336
|
+
const operation = path.join(".");
|
|
39337
|
+
let ownerWrappers = functionWrappers.get(owner);
|
|
39338
|
+
if (ownerWrappers === void 0) {
|
|
39339
|
+
ownerWrappers = /* @__PURE__ */ new Map();
|
|
39340
|
+
functionWrappers.set(owner, ownerWrappers);
|
|
39341
|
+
}
|
|
39342
|
+
const cached = ownerWrappers.get(operation);
|
|
39343
|
+
if (cached !== void 0) return cached;
|
|
39344
|
+
let wrapped;
|
|
39345
|
+
wrapped = new Proxy(callable, {
|
|
39346
|
+
apply(currentTarget, thisArg, args) {
|
|
39347
|
+
const invocation = resolveInvocationSnapshot(adapter, snapshot);
|
|
39348
|
+
let output;
|
|
39349
|
+
try {
|
|
39350
|
+
output = Reflect.apply(currentTarget, unwrapReceiver(thisArg), args);
|
|
39351
|
+
} catch (cause) {
|
|
39352
|
+
report(adapter, "exception", operation, cause, invocation);
|
|
39353
|
+
throw cause;
|
|
39354
|
+
}
|
|
39355
|
+
if (isPromiseLike(output)) return Promise.resolve(output).then((result) => processOutput(result, path, invocation), (cause) => {
|
|
39356
|
+
report(adapter, "exception", operation, cause, invocation);
|
|
39357
|
+
throw cause;
|
|
39358
|
+
});
|
|
39359
|
+
return processOutput(output, path, invocation);
|
|
39360
|
+
},
|
|
39361
|
+
get(currentTarget, property) {
|
|
39362
|
+
if (property === "bind") return Function.prototype.bind.bind(wrapped);
|
|
39363
|
+
if (property === "call") return Function.prototype.call.bind(wrapped);
|
|
39364
|
+
if (property === "apply") return Function.prototype.apply.bind(wrapped);
|
|
39365
|
+
const attached = Reflect.get(currentTarget, property, currentTarget);
|
|
39366
|
+
if (typeof property !== "string") return attached;
|
|
39367
|
+
return wrapValue(attached, [...path, property], currentTarget);
|
|
39368
|
+
}
|
|
39369
|
+
});
|
|
39370
|
+
proxyTargets.set(wrapped, callable);
|
|
39371
|
+
ownerWrappers.set(operation, wrapped);
|
|
39372
|
+
return wrapped;
|
|
39373
|
+
}
|
|
39374
|
+
return isPlainObject(value) ? wrapObject(value, path) : value;
|
|
39375
|
+
};
|
|
39376
|
+
const processOutput = (output, path, invocation) => {
|
|
39377
|
+
if (isFailedResult(output)) {
|
|
39378
|
+
report(adapter, "operation", path.join("."), output.error, invocation);
|
|
39379
|
+
return output;
|
|
39380
|
+
}
|
|
39381
|
+
if (isCapxulResult(output)) return output;
|
|
39382
|
+
return isPlainObject(output) ? wrapObject(output, path) : output;
|
|
39383
|
+
};
|
|
39384
|
+
return wrapObject(client, []);
|
|
39385
|
+
function unwrapReceiver(receiver) {
|
|
39386
|
+
return (typeof receiver === "object" || typeof receiver === "function") && receiver !== null ? proxyTargets.get(receiver) ?? receiver : receiver;
|
|
39387
|
+
}
|
|
39388
|
+
}
|
|
39545
39389
|
/** @internal Reports a factory-level typed failure without changing its identity. */
|
|
39546
39390
|
function observeFailedResult(result, adapter, operation) {
|
|
39547
|
-
if (adapter !== void 0 && isFailedResult(result)) report(adapter, "operation", operation, result.error,
|
|
39391
|
+
if (adapter !== void 0 && isFailedResult(result)) report(adapter, "operation", operation, result.error, resolveAdapterSnapshot(adapter));
|
|
39548
39392
|
return result;
|
|
39549
39393
|
}
|
|
39550
|
-
function report(adapter, kind, operation, cause,
|
|
39394
|
+
function report(adapter, kind, operation, cause, invocation) {
|
|
39551
39395
|
const operationName = normalizeOperation(operation);
|
|
39552
39396
|
const kindName = normalizeErrorKind(errorKind(cause));
|
|
39553
39397
|
const context = sanitizeObservationContext({
|
|
39554
|
-
...
|
|
39398
|
+
...invocation.context,
|
|
39555
39399
|
...isCapxulError(cause) && cause.correlationId !== void 0 ? { correlationId: cause.correlationId } : {}
|
|
39556
39400
|
});
|
|
39557
39401
|
const failure = markFailureInvocationSnapshot({
|
|
@@ -39561,13 +39405,27 @@ function report(adapter, kind, operation, cause, invocationContext) {
|
|
|
39561
39405
|
errorKind: kindName,
|
|
39562
39406
|
...context === void 0 ? {} : { context }
|
|
39563
39407
|
}, {
|
|
39564
|
-
active:
|
|
39408
|
+
active: invocation.active,
|
|
39565
39409
|
...context === void 0 ? {} : { context }
|
|
39566
39410
|
});
|
|
39567
39411
|
try {
|
|
39568
39412
|
ignoreDeliveryFailure(kind === "operation" ? adapter.captureOperationFailure(failure) : adapter.captureException(failure));
|
|
39569
39413
|
} catch {}
|
|
39570
39414
|
}
|
|
39415
|
+
function resolveInvocationSnapshot(adapter, snapshot) {
|
|
39416
|
+
if (snapshot !== void 0) try {
|
|
39417
|
+
const captured = snapshot();
|
|
39418
|
+
if (captured !== void 0) return captured;
|
|
39419
|
+
} catch {}
|
|
39420
|
+
return resolveAdapterSnapshot(adapter);
|
|
39421
|
+
}
|
|
39422
|
+
function resolveAdapterSnapshot(adapter) {
|
|
39423
|
+
const context = resolveAdapterContext(adapter);
|
|
39424
|
+
return context === void 0 ? { active: false } : {
|
|
39425
|
+
active: true,
|
|
39426
|
+
context
|
|
39427
|
+
};
|
|
39428
|
+
}
|
|
39571
39429
|
function resolveAdapterContext(adapter) {
|
|
39572
39430
|
try {
|
|
39573
39431
|
return adapter.resolveContext?.();
|
|
@@ -39735,6 +39593,7 @@ function withAdapterClose(client, closeAdapter) {
|
|
|
39735
39593
|
};
|
|
39736
39594
|
}
|
|
39737
39595
|
function assembleCapxulClient(input) {
|
|
39596
|
+
const observation = input;
|
|
39738
39597
|
const authCache = input.authCache ?? detectAuthCacheAdapter();
|
|
39739
39598
|
const effectRunner = input.effectRunner ?? {
|
|
39740
39599
|
runSync: Effect.runSync,
|
|
@@ -39748,7 +39607,7 @@ function assembleCapxulClient(input) {
|
|
|
39748
39607
|
...input.signer === void 0 ? {} : { signer: input.signer },
|
|
39749
39608
|
...input.organizationSetup === void 0 ? {} : { organizationSetup: input.organizationSetup },
|
|
39750
39609
|
...input.otpTtlMs === void 0 ? {} : { otpTtlMs: input.otpTtlMs }
|
|
39751
|
-
}), scope)),
|
|
39610
|
+
}), scope)), observation.hostObservationSnapshot);
|
|
39752
39611
|
const unsubscribeProductTelemetry = actor.subscribeTransitions((record) => {
|
|
39753
39612
|
effectRunner.runPromise(executeIdentityProductObservation(input.ports.telemetry, record, actor.snapshot())).catch(() => {});
|
|
39754
39613
|
});
|
|
@@ -39797,7 +39656,11 @@ function assembleCapxulClient(input) {
|
|
|
39797
39656
|
...input.invokeTimeoutMs === void 0 ? {} : { invokeTimeoutMs: input.invokeTimeoutMs },
|
|
39798
39657
|
afterVerifyOtp: async () => {
|
|
39799
39658
|
const browserSigner = input.signer;
|
|
39800
|
-
if (browserSigner !== void 0 && "resetSession" in browserSigner && typeof browserSigner.resetSession === "function")
|
|
39659
|
+
if (browserSigner !== void 0 && "resetSession" in browserSigner && typeof browserSigner.resetSession === "function") try {
|
|
39660
|
+
browserSigner.resetSession();
|
|
39661
|
+
} catch (cause) {
|
|
39662
|
+
throw signerFailure(browserSigner.source, "resetSession", cause);
|
|
39663
|
+
}
|
|
39801
39664
|
await detectPendingOrgInvitations?.();
|
|
39802
39665
|
kickProvisioning?.();
|
|
39803
39666
|
}
|
|
@@ -39903,7 +39766,7 @@ function assembleCapxulClient(input) {
|
|
|
39903
39766
|
};
|
|
39904
39767
|
}
|
|
39905
39768
|
};
|
|
39906
|
-
return {
|
|
39769
|
+
return observeSdkClient({
|
|
39907
39770
|
auth,
|
|
39908
39771
|
smartAccount,
|
|
39909
39772
|
identity,
|
|
@@ -39933,7 +39796,7 @@ function assembleCapxulClient(input) {
|
|
|
39933
39796
|
telemetry: input.ports.telemetry,
|
|
39934
39797
|
close: stopActor
|
|
39935
39798
|
}
|
|
39936
|
-
};
|
|
39799
|
+
}, observation.failureObservation, observation.hostObservationSnapshot);
|
|
39937
39800
|
}
|
|
39938
39801
|
function withHostObservation(actor, snapshot) {
|
|
39939
39802
|
if (snapshot === void 0) return actor;
|
|
@@ -40251,16 +40114,24 @@ function refreshConvexAuthOnSession(authClient, refresh) {
|
|
|
40251
40114
|
* particular object rather than on the auth seam itself. Here it wraps
|
|
40252
40115
|
* `AuthClientPort.signOut`, so it holds for every route to a sign-out.
|
|
40253
40116
|
*
|
|
40254
|
-
*
|
|
40255
|
-
*
|
|
40256
|
-
* to `tap` would silently strand an Openfort session on the error path.
|
|
40117
|
+
* Capture the sign-out exit before reset. This preserves the old `try/finally`
|
|
40118
|
+
* order and keeps a reset failure in the typed error channel.
|
|
40257
40119
|
*/
|
|
40258
40120
|
function resetSignerSessionOnSignOut(authClient, resetRef) {
|
|
40259
40121
|
return {
|
|
40260
40122
|
...authClient,
|
|
40261
|
-
signOut: (options) =>
|
|
40262
|
-
|
|
40263
|
-
|
|
40123
|
+
signOut: (options) => Effect.gen(function* () {
|
|
40124
|
+
const exit = yield* Effect.exit(authClient.signOut(options));
|
|
40125
|
+
yield* Effect.try({
|
|
40126
|
+
try: () => resetRef.current?.(),
|
|
40127
|
+
catch: (cause) => new AuthClientError({
|
|
40128
|
+
operation: "signOut",
|
|
40129
|
+
kind: "signer",
|
|
40130
|
+
cause
|
|
40131
|
+
})
|
|
40132
|
+
});
|
|
40133
|
+
return yield* exit;
|
|
40134
|
+
})
|
|
40264
40135
|
};
|
|
40265
40136
|
}
|
|
40266
40137
|
async function createCapxulClient(input) {
|
|
@@ -40286,14 +40157,15 @@ async function createCapxulClient(input) {
|
|
|
40286
40157
|
if (signer === void 0 && runtime === "browser") signer = createOpenfortBrowserSignerFromBootstrap({
|
|
40287
40158
|
...adapters.value.bootstrap,
|
|
40288
40159
|
authBaseUrl: resolvedAuthBaseUrl
|
|
40289
|
-
}, {
|
|
40290
|
-
diagnostic: new ConsoleDiagnosticAdapter(),
|
|
40291
|
-
telemetry: adapters.value.ports.telemetry
|
|
40292
|
-
});
|
|
40160
|
+
}, { diagnostic: new ConsoleDiagnosticAdapter() });
|
|
40293
40161
|
if (signer !== void 0 && "resetSession" in signer) {
|
|
40294
|
-
const { resetSession } = signer;
|
|
40162
|
+
const { resetSession, source } = signer;
|
|
40295
40163
|
resetSignerSession.current = () => {
|
|
40296
|
-
|
|
40164
|
+
try {
|
|
40165
|
+
resetSession();
|
|
40166
|
+
} catch (cause) {
|
|
40167
|
+
throw signerFailure(source, "resetSession", cause);
|
|
40168
|
+
}
|
|
40297
40169
|
};
|
|
40298
40170
|
}
|
|
40299
40171
|
const client = assembleCapxulClient({
|
|
@@ -40311,6 +40183,7 @@ async function createCapxulClient(input) {
|
|
|
40311
40183
|
...input.signal === void 0 ? {} : { signal: input.signal },
|
|
40312
40184
|
...input.otpTtlMs === void 0 ? {} : { otpTtlMs: input.otpTtlMs },
|
|
40313
40185
|
invokeTimeoutMs: input.invokeTimeoutMs ?? 3e4,
|
|
40186
|
+
...input.observability?.failures === void 0 && input.observation === void 0 ? {} : { failureObservation: input.observability?.failures ?? input.observation },
|
|
40314
40187
|
...input.observability === void 0 ? {} : { hostObservationSnapshot: () => snapshotHostObservability(input.observability) },
|
|
40315
40188
|
effectRunner: {
|
|
40316
40189
|
runSync: Effect.runSyncWith(adapters.value.context),
|
|
@@ -40320,7 +40193,11 @@ async function createCapxulClient(input) {
|
|
|
40320
40193
|
const upstreamClose = adapters.value.close;
|
|
40321
40194
|
const close = idempotentClose(async () => {
|
|
40322
40195
|
try {
|
|
40323
|
-
if ("resetSession" in
|
|
40196
|
+
if (signer !== void 0 && "resetSession" in signer) try {
|
|
40197
|
+
signer.resetSession();
|
|
40198
|
+
} catch (cause) {
|
|
40199
|
+
throw signerFailure(signer.source, "resetSession", cause);
|
|
40200
|
+
}
|
|
40324
40201
|
} finally {
|
|
40325
40202
|
await Promise.all([client._internal.close?.(), upstreamClose()]);
|
|
40326
40203
|
}
|
|
@@ -42936,7 +42813,7 @@ function hexToSafeInteger(hex, op) {
|
|
|
42936
42813
|
return n;
|
|
42937
42814
|
}
|
|
42938
42815
|
/**
|
|
42939
|
-
* Read the on-chain `commitments(id)` struct from
|
|
42816
|
+
* Read the on-chain `commitments(id)` struct from CapxulPaymentsV2 via `eth_call`.
|
|
42940
42817
|
* Used to bind lifecycle evidence (claim/cancel/redirect) to the actual on-chain
|
|
42941
42818
|
* STATE — `requireSuccessfulUserOp` proves a UserOp succeeded from the expected
|
|
42942
42819
|
* Safe, but only this state read proves the UserOp performed the expected op on
|
|
@@ -42945,12 +42822,12 @@ function hexToSafeInteger(hex, op) {
|
|
|
42945
42822
|
*/
|
|
42946
42823
|
async function fetchCommitmentState(args) {
|
|
42947
42824
|
const data = encodeFunctionData({
|
|
42948
|
-
abi:
|
|
42825
|
+
abi: CAPXUL_PAYMENTS_V2_ABI,
|
|
42949
42826
|
functionName: "commitments",
|
|
42950
42827
|
args: [args.onchainCommitmentId]
|
|
42951
42828
|
});
|
|
42952
42829
|
const raw = await alchemyRpc(args.chainId, "eth_call", [{
|
|
42953
|
-
to:
|
|
42830
|
+
to: CAPXUL_PAYMENTS_V2_ADDRESS,
|
|
42954
42831
|
data
|
|
42955
42832
|
}, "latest"]);
|
|
42956
42833
|
if (typeof raw !== "string" || !raw.startsWith("0x")) throw Errors.providerError("alchemy", "eth_call commitments", `unexpected shape: ${String(raw)}`);
|
|
@@ -42958,25 +42835,26 @@ async function fetchCommitmentState(args) {
|
|
|
42958
42835
|
let decoded;
|
|
42959
42836
|
try {
|
|
42960
42837
|
decoded = decodeFunctionResult({
|
|
42961
|
-
abi:
|
|
42838
|
+
abi: CAPXUL_PAYMENTS_V2_ABI,
|
|
42962
42839
|
functionName: "commitments",
|
|
42963
42840
|
data: raw
|
|
42964
42841
|
});
|
|
42965
42842
|
} catch (cause) {
|
|
42966
42843
|
throw Errors.providerError("alchemy", "eth_call commitments", `decode failed: ${String(cause)}`);
|
|
42967
42844
|
}
|
|
42968
|
-
const [
|
|
42845
|
+
const [settlementId, creator, recipient, token, totalAmount, claimed, startTime, cliffTime, endTime, kind, documentHash, cancelled] = decoded;
|
|
42969
42846
|
return {
|
|
42847
|
+
settlementId,
|
|
42970
42848
|
creator,
|
|
42971
|
-
token,
|
|
42972
42849
|
recipient,
|
|
42850
|
+
token,
|
|
42973
42851
|
totalAmount,
|
|
42974
42852
|
claimed,
|
|
42975
42853
|
startTime: Number(startTime),
|
|
42976
42854
|
cliffTime: Number(cliffTime),
|
|
42977
42855
|
endTime: Number(endTime),
|
|
42978
42856
|
documentHash,
|
|
42979
|
-
|
|
42857
|
+
kind: Number(kind),
|
|
42980
42858
|
cancelled
|
|
42981
42859
|
};
|
|
42982
42860
|
}
|
|
@@ -43753,9 +43631,10 @@ function makeSdkClientFactory(config, options = { mode: { mode: "live" } }) {
|
|
|
43753
43631
|
actorRequestsGet: (actor, requestId) => actorBundle(client, actor).requests.get(requestId),
|
|
43754
43632
|
actorRequestsCancel: (actor, requestId) => actorBundle(client, actor).requests.cancel(requestId),
|
|
43755
43633
|
inboxList: (actor) => actorBundle(client, actor).inbox.list(),
|
|
43756
|
-
inboxApprove: (actor, requestId, timing) => actorBundle(client, actor).inbox.approve({
|
|
43634
|
+
inboxApprove: (actor, requestId, timing, permissionId) => actorBundle(client, actor).inbox.approve({
|
|
43757
43635
|
requestId,
|
|
43758
|
-
...timing === void 0 ? {} : { timing }
|
|
43636
|
+
...timing === void 0 ? {} : { timing },
|
|
43637
|
+
...permissionId === void 0 ? {} : { permissionId }
|
|
43759
43638
|
}),
|
|
43760
43639
|
inboxDecline: (actor, requestId) => actorBundle(client, actor).inbox.decline(requestId),
|
|
43761
43640
|
addDestination: (input) => client.destinations.add({
|