@capxul/mcp 1.0.0-alpha.17 → 1.0.0-alpha.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -62
- package/dist/{alchemy-rpc-mjuofdCf.mjs → alchemy-rpc-BORldDgR.mjs} +23 -3
- package/dist/alchemy-rpc-BiJgkVvc.mjs +2 -0
- package/dist/main.mjs +969 -479
- package/dist/src-CIqRZpwl.mjs +2 -0
- package/dist/{src-BDIKpZXn.mjs → src-DM3bg5NZ.mjs} +912 -785
- package/package.json +14 -14
- package/dist/alchemy-rpc-DxVP2GsG.mjs +0 -2
- package/dist/src-BmSYoMhj.mjs +0 -2
package/dist/main.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { $ as
|
|
3
|
-
import { a as fetchEntryPointNonce, c as fetchUserOperationReceipt, d as sendUserOperation, i as fetchCommitmentState, l as getPaymasterData, n as estimateUserOperationGas, o as fetchErc20Balance, s as fetchUserOperationFees, u as getPaymasterStubData } from "./alchemy-rpc-
|
|
2
|
+
import { $ as buildCapxulCommitmentRedirectCallData, A as SAFE_MODULE_SETUP, C as BASE_SEPOLIA_CHAIN_ID, D as MULTI_SEND, F as deriveCapxulSafeAddress, H as safe4337StubSignature, K as ERC20_APPROVE_ABI, M as SAFE_PROXY_FACTORY, N as buildSafeMultiSendExecTransactionCall, O as SAFE_4337_MODULE, P as computeCapxulSafeSaltNonce, Q as buildCapxulCommitmentClaimCallData, R as packSafe4337OwnerSignature, S as normalizeBindingEmail, U as CAPXUL_PAYMENTS_ADDRESS, V as safe4337SafeOpDigest, Z as buildCapxulCommitmentCancelCallData, a as computeOrgRolesModuleAddress, at as buildOrgRoleSpendPersonalCallData, ct as isExactTransferTokenAllowed, dt as Errors, et as buildCapxulCreateCommitmentPersonalCallData, g as deriveCapxulOrgAddress, h as computeCapxulOrgSaltNonce, i as buildOrgRolesDeployCalls, it as buildOrgPersonalMultiCallData, k as SAFE_L2_SINGLETON, l as orgRoleKeyForLabel, lt as decodeConvexError, m as buildCapxulOrgInitializer, nt as buildCapxulPaymentsRoleBatchSpendCall, pt as isCapxulError, r as buildOrgRoleAssignmentCall, s as compileOrgRoleDefinitions, st as USDX_ADDRESS_BASE_SEPOLIA, tt as buildCapxulPaymentsPersonalSendCallData, u as orgRoleTemplateDefinitions, ut as CapxulError, y as DIRECT_BASE_ROUTE } from "./src-DM3bg5NZ.mjs";
|
|
3
|
+
import { a as fetchEntryPointNonce, c as fetchUserOperationReceipt, d as sendUserOperation, i as fetchCommitmentState, l as getPaymasterData, n as estimateUserOperationGas, o as fetchErc20Balance, s as fetchUserOperationFees, u as getPaymasterStubData } from "./alchemy-rpc-BORldDgR.mjs";
|
|
4
4
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
5
5
|
import { createHash, randomBytes } from "node:crypto";
|
|
6
6
|
import { createServer } from "node:http";
|
|
7
7
|
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
8
8
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
9
|
-
import { concat, concatHex, createPublicClient, createWalletClient, custom, decodeAbiParameters, decodeFunctionData, encodeAbiParameters, encodeFunctionData, encodePacked, formatUnits, getAddress, getContractAddress, hashMessage, hashTypedData, hexToBigInt, http, keccak256, pad,
|
|
9
|
+
import { concat, concatHex, createPublicClient, createWalletClient, custom, decodeAbiParameters, decodeFunctionData, encodeAbiParameters, encodeFunctionData, encodePacked, formatUnits, getAddress, getContractAddress, hashMessage, hashTypedData, hexToBigInt, http, keccak256, pad, parseUnits, recoverAddress, size, slice, stringToHex, toBytes, toHex, zeroAddress } from "viem";
|
|
10
10
|
import { z } from "zod";
|
|
11
11
|
import { Schema, TreeFormatter } from "@effect/schema";
|
|
12
12
|
import { Context, Data, Deferred, Duration, Effect, Either, Exit, Layer, Ref, Request, Scope } from "effect";
|
|
@@ -232,7 +232,7 @@ function normalizeEmail(email) {
|
|
|
232
232
|
}
|
|
233
233
|
//#endregion
|
|
234
234
|
//#region package.json
|
|
235
|
-
var version$1 = "1.0.0-alpha.
|
|
235
|
+
var version$1 = "1.0.0-alpha.19";
|
|
236
236
|
//#endregion
|
|
237
237
|
//#region src/tool-result.ts
|
|
238
238
|
function okResult(structured) {
|
|
@@ -1152,7 +1152,7 @@ const PaymentSource = Schema.Union(Schema.Struct({
|
|
|
1152
1152
|
* `hashLineItems` (payment-document-hash.ts) into the Invoice `lineItemsHash`,
|
|
1153
1153
|
* and Σ(quantity × unitMinor) MUST equal the invoice `amount`. The hash binds
|
|
1154
1154
|
* the documentHash to the exact items; the sum-check makes the items add up to
|
|
1155
|
-
* the amount due. See the
|
|
1155
|
+
* the amount due. See the financial-operations contract in `packages/wire/CONTEXT.md`.
|
|
1156
1156
|
*/
|
|
1157
1157
|
const LineItem = Schema.Struct({
|
|
1158
1158
|
description: Schema.String,
|
|
@@ -1609,6 +1609,22 @@ function redactError(error, operation, replace) {
|
|
|
1609
1609
|
};
|
|
1610
1610
|
}
|
|
1611
1611
|
//#endregion
|
|
1612
|
+
//#region ../../packages/wire/src/secret-material.ts
|
|
1613
|
+
const SENSITIVE_MATERIAL_PATTERNS = [
|
|
1614
|
+
/0x[a-fA-F0-9]{40,}/u,
|
|
1615
|
+
/(?:^|[^a-fA-F0-9])[a-fA-F0-9]{64}(?:$|[^a-fA-F0-9])/u,
|
|
1616
|
+
/eyJ[A-Za-z0-9_-]*\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+/u,
|
|
1617
|
+
/(?:(?:sk|pk|rk)_(?:live|test)|(?:phc|phx|ghp|gho|ghu|ghs|ghr|whsec)_|github_pat_|xox[baprs]-|AKIA[0-9A-Z]{16}|AIza)[A-Za-z0-9_-]*/iu
|
|
1618
|
+
];
|
|
1619
|
+
/**
|
|
1620
|
+
* Reject: does the value carry any known secret material? Best effort — callers
|
|
1621
|
+
* drop the whole value on a match; a false negative is a leak, a false positive
|
|
1622
|
+
* merely omits an observation field.
|
|
1623
|
+
*/
|
|
1624
|
+
function containsSensitiveMaterial(value) {
|
|
1625
|
+
return SENSITIVE_MATERIAL_PATTERNS.some((pattern) => pattern.test(value));
|
|
1626
|
+
}
|
|
1627
|
+
//#endregion
|
|
1612
1628
|
//#region ../../packages/wire/src/observation-context.ts
|
|
1613
1629
|
/** Single bounded HTTP carrier used before a Convex action envelope exists. */
|
|
1614
1630
|
const OBSERVATION_CONTEXT_HEADER = "x-capxul-observation-context";
|
|
@@ -1642,10 +1658,6 @@ const FIELD_RULES = {
|
|
|
1642
1658
|
pattern: /^anon_[A-Za-z0-9-]+$/u
|
|
1643
1659
|
}
|
|
1644
1660
|
};
|
|
1645
|
-
const EMBEDDED_WALLET_MATERIAL = /0x[a-fA-F0-9]{40,}/u;
|
|
1646
|
-
const RAW_PRIVATE_KEY_MATERIAL = /(?:^|[^a-fA-F0-9])[a-fA-F0-9]{64}(?:$|[^a-fA-F0-9])/u;
|
|
1647
|
-
const COMPACT_JWT = /eyJ[A-Za-z0-9_-]*\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+/u;
|
|
1648
|
-
const KNOWN_CREDENTIAL_PREFIX = /(?:(?:sk|pk|rk)_(?:live|test)|(?:phc|phx|ghp|gho|ghu|ghs|ghr|whsec)_|github_pat_|xox[baprs]-|AKIA[0-9A-Z]{16}|AIza)[A-Za-z0-9_-]*/iu;
|
|
1649
1661
|
/**
|
|
1650
1662
|
* Copy only the canonical allowlist and silently omit malformed/sensitive
|
|
1651
1663
|
* values. Observation metadata is best effort and may never reject a domain
|
|
@@ -1672,9 +1684,6 @@ function isSafeField(field, value) {
|
|
|
1672
1684
|
const rule = FIELD_RULES[field];
|
|
1673
1685
|
return value.length > 0 && value.length <= rule.maxLength && value === value.trim() && !value.includes("://") && !containsSensitiveMaterial(value) && rule.pattern.test(value);
|
|
1674
1686
|
}
|
|
1675
|
-
function containsSensitiveMaterial(value) {
|
|
1676
|
-
return EMBEDDED_WALLET_MATERIAL.test(value) || RAW_PRIVATE_KEY_MATERIAL.test(value) || COMPACT_JWT.test(value) || KNOWN_CREDENTIAL_PREFIX.test(value);
|
|
1677
|
-
}
|
|
1678
1687
|
//#endregion
|
|
1679
1688
|
//#region src/payment-wire.ts
|
|
1680
1689
|
const MONEY_RE$1 = /^\s*([0-9]+(?:\.[0-9]+)?)\s+([A-Za-z][A-Za-z0-9]*)\s*$/;
|
|
@@ -5032,10 +5041,10 @@ function makeAccountMethods(deps) {
|
|
|
5032
5041
|
value: await lane.retryProvisioning()
|
|
5033
5042
|
};
|
|
5034
5043
|
};
|
|
5035
|
-
const reportAndReturn = (error) => {
|
|
5044
|
+
const reportAndReturn = (error, operation = "getLifecycle") => {
|
|
5036
5045
|
if (deps.telemetry) captureExceptionSync(deps.telemetry, error, {
|
|
5037
5046
|
layer: "account",
|
|
5038
|
-
operation
|
|
5047
|
+
operation
|
|
5039
5048
|
});
|
|
5040
5049
|
return {
|
|
5041
5050
|
ok: false,
|
|
@@ -5066,6 +5075,12 @@ function makeAccountMethods(deps) {
|
|
|
5066
5075
|
};
|
|
5067
5076
|
const getLifecycle = () => resolveLifecycle();
|
|
5068
5077
|
const retrySetup = async () => {
|
|
5078
|
+
const resetSession = deps.signer?.resetSession;
|
|
5079
|
+
if (typeof resetSession === "function") try {
|
|
5080
|
+
resetSession.call(deps.signer);
|
|
5081
|
+
} catch (cause) {
|
|
5082
|
+
return reportAndReturn(cause instanceof CapxulError ? cause : Errors.providerError("openfort", "resetSession", cause, { failure_mode: "unknown" }), "retrySetup");
|
|
5083
|
+
}
|
|
5069
5084
|
await lane.retryProvisioning();
|
|
5070
5085
|
return resolveLifecycle();
|
|
5071
5086
|
};
|
|
@@ -5259,7 +5274,7 @@ async function recoverRawDigestSigner(input) {
|
|
|
5259
5274
|
}
|
|
5260
5275
|
//#endregion
|
|
5261
5276
|
//#region ../../packages/sdk/package.json
|
|
5262
|
-
var version = "1.0.0-alpha.
|
|
5277
|
+
var version = "1.0.0-alpha.19";
|
|
5263
5278
|
//#endregion
|
|
5264
5279
|
//#region ../../packages/sdk/src/ports/auth-client.ts
|
|
5265
5280
|
var AuthClientError = class extends Data.TaggedError("AuthClientError") {};
|
|
@@ -6576,24 +6591,6 @@ const envFields = {
|
|
|
6576
6591
|
"required": false,
|
|
6577
6592
|
"example": "development"
|
|
6578
6593
|
},
|
|
6579
|
-
AUTH_DEV_OTP: {
|
|
6580
|
-
"runtime": "server",
|
|
6581
|
-
"kind": "nonempty",
|
|
6582
|
-
"required": false,
|
|
6583
|
-
"example": "000000"
|
|
6584
|
-
},
|
|
6585
|
-
SENTRY_DSN: {
|
|
6586
|
-
"runtime": "server",
|
|
6587
|
-
"kind": "url",
|
|
6588
|
-
"required": false,
|
|
6589
|
-
"example": "https://public@example.ingest.sentry.io/1"
|
|
6590
|
-
},
|
|
6591
|
-
POSTHOG_API_KEY: {
|
|
6592
|
-
"runtime": "server",
|
|
6593
|
-
"kind": "nonempty",
|
|
6594
|
-
"required": false,
|
|
6595
|
-
"example": "phx_test"
|
|
6596
|
-
},
|
|
6597
6594
|
POSTHOG_PROJECT_TOKEN: {
|
|
6598
6595
|
"runtime": "server",
|
|
6599
6596
|
"kind": "nonempty",
|
|
@@ -6624,24 +6621,12 @@ const envFields = {
|
|
|
6624
6621
|
"required": false,
|
|
6625
6622
|
"example": "12345"
|
|
6626
6623
|
},
|
|
6627
|
-
POSTHOG_ENV_ID: {
|
|
6628
|
-
"runtime": "server",
|
|
6629
|
-
"kind": "nonempty",
|
|
6630
|
-
"required": false,
|
|
6631
|
-
"example": "12345"
|
|
6632
|
-
},
|
|
6633
6624
|
SENDER_EMAIL: {
|
|
6634
6625
|
"runtime": "server",
|
|
6635
6626
|
"kind": "email",
|
|
6636
6627
|
"required": false,
|
|
6637
6628
|
"example": "noreply@capxul.test"
|
|
6638
6629
|
},
|
|
6639
|
-
SHIELD_API_URL: {
|
|
6640
|
-
"runtime": "server",
|
|
6641
|
-
"kind": "url",
|
|
6642
|
-
"required": false,
|
|
6643
|
-
"example": "https://api.shield.test"
|
|
6644
|
-
},
|
|
6645
6630
|
ALCHEMY_API_KEY: {
|
|
6646
6631
|
"runtime": "server",
|
|
6647
6632
|
"kind": "nonempty",
|
|
@@ -6660,24 +6645,6 @@ const envFields = {
|
|
|
6660
6645
|
"required": true,
|
|
6661
6646
|
"example": "alchemy_hmac"
|
|
6662
6647
|
},
|
|
6663
|
-
ALCHEMY_AUTH_TOKEN: {
|
|
6664
|
-
"runtime": "server",
|
|
6665
|
-
"kind": "nonempty",
|
|
6666
|
-
"required": false,
|
|
6667
|
-
"example": "alchemy_auth"
|
|
6668
|
-
},
|
|
6669
|
-
ALCHEMY_WEBHOOK_ID: {
|
|
6670
|
-
"runtime": "server",
|
|
6671
|
-
"kind": "nonempty",
|
|
6672
|
-
"required": false,
|
|
6673
|
-
"example": "wh_123"
|
|
6674
|
-
},
|
|
6675
|
-
GOLDSKY_WEBHOOK_SECRET: {
|
|
6676
|
-
"runtime": "server",
|
|
6677
|
-
"kind": "nonempty",
|
|
6678
|
-
"required": false,
|
|
6679
|
-
"example": "goldsky_secret"
|
|
6680
|
-
},
|
|
6681
6648
|
DEPLOYER_PRIVATE_KEY: {
|
|
6682
6649
|
"runtime": "server",
|
|
6683
6650
|
"kind": "privateKey",
|
|
@@ -6934,7 +6901,7 @@ function fromWei(rawBalance, decimals, currency) {
|
|
|
6934
6901
|
}
|
|
6935
6902
|
//#endregion
|
|
6936
6903
|
//#region ../../packages/sdk/src/adapters/account-read/ConvexAccountAdapter.ts
|
|
6937
|
-
const DEFAULT_FUNCTIONS$
|
|
6904
|
+
const DEFAULT_FUNCTIONS$5 = {
|
|
6938
6905
|
readBalance: makeFunctionReference("account/actions:readBalance"),
|
|
6939
6906
|
faucetMint: makeFunctionReference("account/actions:faucetMint")
|
|
6940
6907
|
};
|
|
@@ -6943,7 +6910,7 @@ var ConvexAccountAdapter = class {
|
|
|
6943
6910
|
#fns;
|
|
6944
6911
|
constructor(deps) {
|
|
6945
6912
|
this.#convex = deps.convex;
|
|
6946
|
-
this.#fns = deps.functions ?? DEFAULT_FUNCTIONS$
|
|
6913
|
+
this.#fns = deps.functions ?? DEFAULT_FUNCTIONS$5;
|
|
6947
6914
|
}
|
|
6948
6915
|
readBalance(input) {
|
|
6949
6916
|
return this.#convex.action(this.#fns.readBalance, { chainId: wireChainId(input.chainId) }).pipe(Effect.mapError((error) => accountReadErrorFromCapxul("readBalance", error.publicError, error)), Effect.flatMap((wire) => brandAccountEffect("readBalance", wire)), Effect.catchAllDefect((cause) => Effect.fail(accountReadErrorFromUnknown("readBalance", cause))));
|
|
@@ -6996,7 +6963,7 @@ function subAccountErrorFromCapxul(operation, error, cause = error) {
|
|
|
6996
6963
|
var SubAccountPortTag = class extends Context.Tag("@capxul/sdk/ports/SubAccountPort")() {};
|
|
6997
6964
|
//#endregion
|
|
6998
6965
|
//#region ../../packages/sdk/src/adapters/sub-account/ConvexSubAccountAdapter.ts
|
|
6999
|
-
const DEFAULT_FUNCTIONS$
|
|
6966
|
+
const DEFAULT_FUNCTIONS$4 = {
|
|
7000
6967
|
create: makeFunctionReference("subAccount/mutations:create"),
|
|
7001
6968
|
get: makeFunctionReference("subAccount/queries:get"),
|
|
7002
6969
|
list: makeFunctionReference("subAccount/queries:list"),
|
|
@@ -7011,7 +6978,7 @@ var ConvexSubAccountAdapter = class {
|
|
|
7011
6978
|
constructor(deps) {
|
|
7012
6979
|
this.#convex = deps.convex;
|
|
7013
6980
|
this.#chainId = deps.chainId;
|
|
7014
|
-
this.#fns = deps.functions ?? DEFAULT_FUNCTIONS$
|
|
6981
|
+
this.#fns = deps.functions ?? DEFAULT_FUNCTIONS$4;
|
|
7015
6982
|
}
|
|
7016
6983
|
create(input) {
|
|
7017
6984
|
return this.#runMutation("create", this.#fns.create, {
|
|
@@ -7095,7 +7062,7 @@ function smartAccountErrorFromCapxul(operation, error, cause = error) {
|
|
|
7095
7062
|
var SmartAccountPortTag = class extends Context.Tag("@capxul/sdk/ports/SmartAccountPort")() {};
|
|
7096
7063
|
//#endregion
|
|
7097
7064
|
//#region ../../packages/sdk/src/adapters/smart-account/ConvexSmartAccountAdapter.ts
|
|
7098
|
-
const DEFAULT_FUNCTIONS$
|
|
7065
|
+
const DEFAULT_FUNCTIONS$3 = {
|
|
7099
7066
|
loadByAuthUserId: makeFunctionReference("smartAccount/queries:loadByAuthUserId"),
|
|
7100
7067
|
loadBySmartAccountAddress: makeFunctionReference("smartAccount/queries:loadBySmartAccountAddress"),
|
|
7101
7068
|
provision: makeFunctionReference("smartAccount/mutations:provision"),
|
|
@@ -7107,7 +7074,7 @@ var ConvexSmartAccountAdapter = class {
|
|
|
7107
7074
|
#fns;
|
|
7108
7075
|
constructor(deps) {
|
|
7109
7076
|
this.#convex = deps.convex;
|
|
7110
|
-
this.#fns = deps.functions ?? DEFAULT_FUNCTIONS$
|
|
7077
|
+
this.#fns = deps.functions ?? DEFAULT_FUNCTIONS$3;
|
|
7111
7078
|
}
|
|
7112
7079
|
loadByAuthUserId(authUserId) {
|
|
7113
7080
|
return this.#convex.query(this.#fns.loadByAuthUserId, { authUserId }).pipe(Effect.mapError((error) => smartAccountErrorFromCapxul("loadByAuthUserId", error.publicError, error)), Effect.flatMap((row) => brandSmartAccountEffect("loadByAuthUserId", row)), Effect.catchAllDefect((cause) => Effect.fail(smartAccountErrorFromUnknown("loadByAuthUserId", cause))));
|
|
@@ -7182,100 +7149,550 @@ function smartAccountErrorFromUnknown(operation, cause) {
|
|
|
7182
7149
|
toAddress("0xa6b71e26c5e0845f74c812102ca7114b6a896ab2");
|
|
7183
7150
|
keccak256("0x");
|
|
7184
7151
|
//#endregion
|
|
7185
|
-
//#region ../../packages/
|
|
7186
|
-
|
|
7187
|
-
|
|
7188
|
-
|
|
7189
|
-
|
|
7190
|
-
|
|
7191
|
-
|
|
7192
|
-
|
|
7193
|
-
|
|
7194
|
-
|
|
7195
|
-
|
|
7196
|
-
|
|
7197
|
-
|
|
7198
|
-
|
|
7199
|
-
|
|
7200
|
-
|
|
7201
|
-
|
|
7202
|
-
|
|
7203
|
-
|
|
7204
|
-
|
|
7205
|
-
|
|
7206
|
-
|
|
7207
|
-
|
|
7208
|
-
|
|
7209
|
-
|
|
7210
|
-
|
|
7211
|
-
|
|
7212
|
-
|
|
7213
|
-
|
|
7214
|
-
|
|
7215
|
-
|
|
7216
|
-
|
|
7217
|
-
|
|
7218
|
-
|
|
7219
|
-
|
|
7220
|
-
|
|
7221
|
-
|
|
7222
|
-
|
|
7223
|
-
|
|
7224
|
-
|
|
7225
|
-
|
|
7226
|
-
|
|
7227
|
-
|
|
7228
|
-
|
|
7229
|
-
|
|
7230
|
-
|
|
7231
|
-
|
|
7232
|
-
|
|
7233
|
-
|
|
7234
|
-
|
|
7235
|
-
|
|
7152
|
+
//#region ../../packages/sdk/src/ports/org.ts
|
|
7153
|
+
var OrgError = class extends Data.TaggedError("OrgError") {};
|
|
7154
|
+
function orgErrorFromCapxul(operation, error, cause = error) {
|
|
7155
|
+
return new OrgError({
|
|
7156
|
+
operation,
|
|
7157
|
+
publicCode: error.code,
|
|
7158
|
+
publicError: error,
|
|
7159
|
+
cause,
|
|
7160
|
+
...error.details === void 0 ? {} : { details: error.details }
|
|
7161
|
+
});
|
|
7162
|
+
}
|
|
7163
|
+
Context.Tag("@capxul/sdk/ports/OrgPort")();
|
|
7164
|
+
Context.Tag("@capxul/sdk/ports/OrgRolesDeploymentPort")();
|
|
7165
|
+
Context.Tag("@capxul/sdk/ports/OrgSpendPort")();
|
|
7166
|
+
//#endregion
|
|
7167
|
+
//#region ../../packages/sdk/src/adapters/org/parse.ts
|
|
7168
|
+
/**
|
|
7169
|
+
* Map a `WireOrg` + its (separately read) treasury `Account` into the branded
|
|
7170
|
+
* `OrgView`. The viewer role is projected by the authenticated backend read;
|
|
7171
|
+
* it must never be inferred from Organization ownership. Brands at the read
|
|
7172
|
+
* edge: `orgId`, `safeAddress`.
|
|
7173
|
+
*/
|
|
7174
|
+
function brandOrgView(wire, treasury, viewerRole) {
|
|
7175
|
+
return {
|
|
7176
|
+
id: toOrgId(wire.orgId),
|
|
7177
|
+
name: wire.name,
|
|
7178
|
+
handle: wire.slug,
|
|
7179
|
+
safeAddress: toAddress(wire.safeAddress.toLowerCase()),
|
|
7180
|
+
role: viewerRole,
|
|
7181
|
+
treasury
|
|
7182
|
+
};
|
|
7183
|
+
}
|
|
7184
|
+
/**
|
|
7185
|
+
* Build the Org treasury `Account` from the raw on-chain `balanceOf` integer
|
|
7186
|
+
* (the D3 RPC read). `available === balance` for a treasury with no envelope
|
|
7187
|
+
* partition yet (a fresh Org reads back $0).
|
|
7188
|
+
*/
|
|
7189
|
+
function brandOrgTreasury(input) {
|
|
7190
|
+
return {
|
|
7191
|
+
id: toAccountId(`account_${orgIdBody(input.orgId)}`),
|
|
7192
|
+
balance: input.money,
|
|
7193
|
+
available: input.money
|
|
7194
|
+
};
|
|
7195
|
+
}
|
|
7196
|
+
function brandOrgRole(wire) {
|
|
7197
|
+
return {
|
|
7198
|
+
orgId: toOrgId(wire.orgId),
|
|
7199
|
+
label: wire.label,
|
|
7200
|
+
roleKey: toRoleKey(wire.roleKey),
|
|
7201
|
+
definition: parseRoleDefinition(wire.definitionJson)
|
|
7202
|
+
};
|
|
7203
|
+
}
|
|
7204
|
+
function brandOrgMember(wire) {
|
|
7205
|
+
return {
|
|
7206
|
+
orgId: toOrgId(wire.orgId),
|
|
7207
|
+
email: toEmail(wire.email),
|
|
7208
|
+
name: wire.name,
|
|
7209
|
+
personalSafeAddress: wire.personalSafeAddress === null ? null : toAddress(wire.personalSafeAddress),
|
|
7210
|
+
role: wire.role,
|
|
7211
|
+
roleKey: wire.roleKey === null ? null : toRoleKey(wire.roleKey),
|
|
7212
|
+
status: wire.status,
|
|
7213
|
+
grantTxHash: wire.grantTxHash,
|
|
7214
|
+
revokeTxHash: wire.revokeTxHash
|
|
7215
|
+
};
|
|
7216
|
+
}
|
|
7217
|
+
function parseRoleDefinition(json) {
|
|
7218
|
+
let raw;
|
|
7219
|
+
try {
|
|
7220
|
+
const parsed = JSON.parse(json);
|
|
7221
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) throw new Error("expected object");
|
|
7222
|
+
raw = parsed;
|
|
7223
|
+
} catch (err) {
|
|
7224
|
+
throw new Error(`Invalid role definition: malformed JSON - ${err instanceof Error ? err.message : String(err)}`, { cause: err });
|
|
7225
|
+
}
|
|
7226
|
+
if (typeof raw.label !== "string" || raw.label.trim().length === 0) throw new Error("Invalid role definition: missing label");
|
|
7227
|
+
return {
|
|
7228
|
+
label: raw.label,
|
|
7229
|
+
...raw.spend === void 0 ? {} : { spend: {
|
|
7230
|
+
...raw.spend.perTx === void 0 ? {} : { perTx: parseRoleMoney(raw.spend.perTx, "perTx") },
|
|
7231
|
+
...raw.spend.perDay === void 0 ? {} : { perDay: parseRoleMoney(raw.spend.perDay, "perDay") },
|
|
7232
|
+
...raw.spend.toRecipients === void 0 ? {} : { toRecipients: parseRoleRecipients(raw.spend.toRecipients) }
|
|
7233
|
+
} },
|
|
7234
|
+
...raw.subAccounts === void 0 ? {} : { subAccounts: parseRoleSubAccounts(raw.subAccounts) },
|
|
7235
|
+
...typeof raw.canManageMembers === "boolean" ? { canManageMembers: raw.canManageMembers } : {},
|
|
7236
|
+
...typeof raw.canManageRoles === "boolean" ? { canManageRoles: raw.canManageRoles } : {}
|
|
7237
|
+
};
|
|
7238
|
+
}
|
|
7239
|
+
function parseRoleMoney(raw, field) {
|
|
7240
|
+
if (typeof raw.currency !== "string" || typeof raw.value !== "string" || !/^\d+$/.test(raw.value) || raw.decimals !== 6) throw new Error(`Invalid role money: ${field}`);
|
|
7241
|
+
return {
|
|
7242
|
+
currency: toCurrencyCode(raw.currency),
|
|
7243
|
+
value: raw.value,
|
|
7244
|
+
decimals: raw.decimals
|
|
7245
|
+
};
|
|
7246
|
+
}
|
|
7247
|
+
function parseRoleRecipients(raw) {
|
|
7248
|
+
if (raw === "anyone") return "anyone";
|
|
7249
|
+
if (!Array.isArray(raw)) throw new Error("Invalid role definition: toRecipients must be \"anyone\" or an array");
|
|
7250
|
+
return raw.map((recipient) => {
|
|
7251
|
+
if (typeof recipient !== "string") throw new Error("Invalid role definition: toRecipients must be \"anyone\" or an array");
|
|
7252
|
+
return toAddress(recipient);
|
|
7253
|
+
});
|
|
7254
|
+
}
|
|
7255
|
+
function parseRoleSubAccounts(raw) {
|
|
7256
|
+
if (raw.scope === "all") return { scope: "all" };
|
|
7257
|
+
if (!Array.isArray(raw.scope)) throw new Error("Invalid role definition: subAccounts.scope must be \"all\" or an array");
|
|
7258
|
+
return { scope: raw.scope.map((subAccountId) => {
|
|
7259
|
+
if (typeof subAccountId !== "string") throw new Error("Invalid role definition: subAccounts.scope must be \"all\" or an array");
|
|
7260
|
+
return toSubAccountId(subAccountId);
|
|
7261
|
+
}) };
|
|
7262
|
+
}
|
|
7263
|
+
/** Strip the `org_` prefix + non-alphanumerics so the body re-seeds `account_`. */
|
|
7264
|
+
function orgIdBody(orgId) {
|
|
7265
|
+
const underscore = orgId.indexOf("_");
|
|
7266
|
+
const cleaned = (underscore < 0 ? orgId : orgId.slice(underscore + 1)).replace(/[^0-9A-Za-z]/g, "");
|
|
7267
|
+
return cleaned.length > 0 ? cleaned : "0";
|
|
7268
|
+
}
|
|
7269
|
+
//#endregion
|
|
7270
|
+
//#region ../../packages/sdk/src/adapters/org/ConvexOrganizationAdapter.ts
|
|
7271
|
+
const DEFAULT_FUNCTIONS$2 = {
|
|
7272
|
+
listAll: makeFunctionReference("org/queries:listAll"),
|
|
7273
|
+
listRoles: makeFunctionReference("org/queries:listRolesByOrgId"),
|
|
7274
|
+
listMembers: makeFunctionReference("org/queries:listMembersByOrgId"),
|
|
7275
|
+
readTreasury: makeFunctionReference("org/actions:readTreasury"),
|
|
7276
|
+
inviteMember: makeFunctionReference("org/actions:inviteMember"),
|
|
7277
|
+
resendInvite: makeFunctionReference("org/mutations:resendInviteToken"),
|
|
7278
|
+
detectInvitations: makeFunctionReference("org/actions:detectAndAcceptPendingInvitations")
|
|
7236
7279
|
};
|
|
7237
|
-
|
|
7238
|
-
|
|
7239
|
-
|
|
7240
|
-
|
|
7241
|
-
|
|
7242
|
-
|
|
7243
|
-
|
|
7244
|
-
|
|
7245
|
-
|
|
7246
|
-
|
|
7247
|
-
|
|
7248
|
-
}
|
|
7249
|
-
|
|
7250
|
-
|
|
7251
|
-
|
|
7252
|
-
|
|
7253
|
-
})
|
|
7254
|
-
const
|
|
7255
|
-
|
|
7256
|
-
|
|
7257
|
-
|
|
7258
|
-
|
|
7259
|
-
|
|
7260
|
-
|
|
7261
|
-
|
|
7262
|
-
|
|
7263
|
-
|
|
7264
|
-
|
|
7265
|
-
|
|
7266
|
-
|
|
7267
|
-
|
|
7268
|
-
}
|
|
7269
|
-
|
|
7270
|
-
|
|
7271
|
-
|
|
7272
|
-
|
|
7273
|
-
|
|
7274
|
-
|
|
7275
|
-
|
|
7276
|
-
|
|
7277
|
-
|
|
7278
|
-
|
|
7280
|
+
/**
|
|
7281
|
+
* Standard production Organization read adapter. It intentionally has no
|
|
7282
|
+
* deployer/RPC/test configuration: authenticated Convex actions own live chain
|
|
7283
|
+
* reads, while the lifecycle adapter owns the single sponsored bootstrap.
|
|
7284
|
+
*/
|
|
7285
|
+
var ConvexOrganizationAdapter = class {
|
|
7286
|
+
#convex;
|
|
7287
|
+
#fns;
|
|
7288
|
+
constructor(input) {
|
|
7289
|
+
this.#convex = input.convex;
|
|
7290
|
+
this.#fns = input.functions ?? DEFAULT_FUNCTIONS$2;
|
|
7291
|
+
}
|
|
7292
|
+
createOrg(_input) {
|
|
7293
|
+
return Effect.fail(orgErrorFromCapxul("createOrg", Errors.notImplemented("organizationSetup", "use onboarding.completeOrganization")));
|
|
7294
|
+
}
|
|
7295
|
+
listOrgs(_input) {
|
|
7296
|
+
return this.#convex.query(this.#fns.listAll, {}).pipe(Effect.mapError((error) => orgErrorFromCapxul("listOrgs", error.publicError, error)), Effect.flatMap((wires) => Effect.forEach(wires, (wire) => this.#readTreasuryWire(wire.orgId).pipe(Effect.map((treasury) => {
|
|
7297
|
+
const viewerRole = wire.viewerRole.trim();
|
|
7298
|
+
if (viewerRole.length === 0) throw Errors.wrongState({
|
|
7299
|
+
method: "listOrgs",
|
|
7300
|
+
currentState: "viewerRoleMissing",
|
|
7301
|
+
validStates: ["activeViewerRole"]
|
|
7302
|
+
});
|
|
7303
|
+
return brandOrgView(wire, treasury, viewerRole);
|
|
7304
|
+
})))), Effect.catchAllDefect((cause) => Effect.fail(toOrgError$1("listOrgs", cause))));
|
|
7305
|
+
}
|
|
7306
|
+
readTreasury(input) {
|
|
7307
|
+
return this.#readTreasuryWire(String(input.orgId)).pipe(Effect.catchAllDefect((cause) => Effect.fail(toOrgError$1("readTreasury", cause))));
|
|
7308
|
+
}
|
|
7309
|
+
listRoles(input) {
|
|
7310
|
+
return this.#convex.query(this.#fns.listRoles, { orgId: input.orgId }).pipe(Effect.mapError((error) => orgErrorFromCapxul("listRoles", error.publicError, error)), Effect.flatMap((rows) => rows.length === 0 ? Effect.fail(partialOrgTruth("listRoles", "activeRoleMissing")) : Effect.succeed(rows.map(brandOrgRole))), Effect.catchAllDefect((cause) => Effect.fail(toOrgError$1("listRoles", cause))));
|
|
7311
|
+
}
|
|
7312
|
+
listMembers(input) {
|
|
7313
|
+
return this.#convex.query(this.#fns.listMembers, { orgId: input.orgId }).pipe(Effect.mapError((error) => orgErrorFromCapxul("listMembers", error.publicError, error)), Effect.flatMap((rows) => rows.length === 0 ? Effect.fail(partialOrgTruth("listMembers", "activeMemberMissing")) : Effect.succeed(rows.map(brandOrgMember))), Effect.catchAllDefect((cause) => Effect.fail(toOrgError$1("listMembers", cause))));
|
|
7314
|
+
}
|
|
7315
|
+
pendingMembers(input) {
|
|
7316
|
+
return this.listMembers(input).pipe(Effect.map((members) => members.filter((member) => member.status === "pending" || member.status === "pending_safe" || member.status === "pending_grant")));
|
|
7317
|
+
}
|
|
7318
|
+
inviteMember(input) {
|
|
7319
|
+
return this.#convex.action(this.#fns.inviteMember, {
|
|
7320
|
+
orgId: input.orgId,
|
|
7321
|
+
email: input.input.email,
|
|
7322
|
+
role: input.input.role
|
|
7323
|
+
}).pipe(Effect.mapError((error) => orgErrorFromCapxul("inviteMember", error.publicError, error)), Effect.map(brandOrgMember), Effect.catchAllDefect((cause) => Effect.fail(toOrgError$1("inviteMember", cause))));
|
|
7324
|
+
}
|
|
7325
|
+
resendInviteToken(input) {
|
|
7326
|
+
return this.#convex.mutation(this.#fns.resendInvite, {
|
|
7327
|
+
orgId: input.orgId,
|
|
7328
|
+
email: input.email
|
|
7329
|
+
}).pipe(Effect.mapError((error) => orgErrorFromCapxul("resendInviteToken", error.publicError, error)), Effect.map(brandOrgMember), Effect.catchAllDefect((cause) => Effect.fail(toOrgError$1("resendInviteToken", cause))));
|
|
7330
|
+
}
|
|
7331
|
+
detectAndAcceptPendingInvitations(_input) {
|
|
7332
|
+
return this.#convex.action(this.#fns.detectInvitations, {}).pipe(Effect.mapError((error) => orgErrorFromCapxul("detectAndAcceptPendingInvitations", error.publicError, error)), Effect.map((result) => ({ matched: result.matched.map(toOrgId) })), Effect.catchAllDefect((cause) => Effect.fail(toOrgError$1("detectAndAcceptPendingInvitations", cause))));
|
|
7333
|
+
}
|
|
7334
|
+
#readTreasuryWire(orgId) {
|
|
7335
|
+
return this.#convex.action(this.#fns.readTreasury, { orgId }).pipe(Effect.mapError((error) => orgErrorFromCapxul("readTreasury", error.publicError, error)), Effect.map((wire) => {
|
|
7336
|
+
if (wire.orgId !== orgId) throw Errors.invalidInput("orgId", "Organization treasury scope does not match");
|
|
7337
|
+
const balance = fromWei(wire.rawBalance, wire.decimals, wire.currency);
|
|
7338
|
+
const available = fromWei(wire.rawAvailableBalance, wire.decimals, wire.currency);
|
|
7339
|
+
return {
|
|
7340
|
+
...brandOrgTreasury({
|
|
7341
|
+
orgId: wire.orgId,
|
|
7342
|
+
money: balance
|
|
7343
|
+
}),
|
|
7344
|
+
available
|
|
7345
|
+
};
|
|
7346
|
+
}));
|
|
7347
|
+
}
|
|
7348
|
+
};
|
|
7349
|
+
function toOrgError$1(operation, cause) {
|
|
7350
|
+
if (cause instanceof CapxulError) return orgErrorFromCapxul(operation, cause);
|
|
7351
|
+
return orgErrorFromCapxul(operation, Errors.providerError("convex", operation, cause), cause);
|
|
7352
|
+
}
|
|
7353
|
+
function partialOrgTruth(operation, currentState) {
|
|
7354
|
+
return orgErrorFromCapxul(operation, Errors.wrongState({
|
|
7355
|
+
method: operation,
|
|
7356
|
+
currentState,
|
|
7357
|
+
validStates: ["completeProductionOrganizationTruth"]
|
|
7358
|
+
}));
|
|
7359
|
+
}
|
|
7360
|
+
//#endregion
|
|
7361
|
+
//#region ../../packages/sdk/src/adapters/org/ConvexOrganizationSetupAdapter.ts
|
|
7362
|
+
const DEFAULT_FUNCTIONS$1 = {
|
|
7363
|
+
startOrResume: makeFunctionReference("org/lifecycle:startOrResume"),
|
|
7364
|
+
prepareFounderAccount: makeFunctionReference("org/actions:prepareFounderAccount"),
|
|
7365
|
+
prepareBootstrap: makeFunctionReference("org/actions:prepareBootstrap"),
|
|
7366
|
+
submitBootstrap: makeFunctionReference("org/actions:submitBootstrap"),
|
|
7367
|
+
resumeBootstrapSubmission: makeFunctionReference("org/actions:resumeBootstrapSubmission"),
|
|
7368
|
+
confirmBootstrap: makeFunctionReference("org/actions:confirmBootstrap"),
|
|
7369
|
+
recordFailure: makeFunctionReference("org/lifecycle:recordFailure"),
|
|
7370
|
+
load: makeFunctionReference("org/lifecycle:load"),
|
|
7371
|
+
retry: makeFunctionReference("org/lifecycle:retry")
|
|
7372
|
+
};
|
|
7373
|
+
/** Durable Organization setup capability composed by the standard client. */
|
|
7374
|
+
var ConvexOrganizationSetupAdapter = class {
|
|
7375
|
+
#convex;
|
|
7376
|
+
#signer;
|
|
7377
|
+
#fns;
|
|
7378
|
+
constructor(input) {
|
|
7379
|
+
this.#convex = input.convex;
|
|
7380
|
+
this.#signer = input.signer;
|
|
7381
|
+
this.#fns = input.functions ?? DEFAULT_FUNCTIONS$1;
|
|
7382
|
+
}
|
|
7383
|
+
async startOrResume(input) {
|
|
7384
|
+
const result = await runCall("startOrResume", this.#convex.mutation(this.#fns.startOrResume, input));
|
|
7385
|
+
if (!result.ok) return result;
|
|
7386
|
+
const lifecycle = parseLifecycle("startOrResume", result.value.lifecycle);
|
|
7387
|
+
if (!lifecycle.ok) return lifecycle;
|
|
7388
|
+
const orgId = parseOrgId("startOrResume", result.value.orgId);
|
|
7389
|
+
if (!orgId.ok) return orgId;
|
|
7390
|
+
if (String(orgId.value) !== String(lifecycle.value.orgId)) return fail$2(Errors.invalidInput("orgId", "Organization lifecycle scope does not match"));
|
|
7391
|
+
return {
|
|
7392
|
+
ok: true,
|
|
7393
|
+
value: {
|
|
7394
|
+
orgId: orgId.value,
|
|
7395
|
+
lifecycle: lifecycle.value
|
|
7396
|
+
}
|
|
7397
|
+
};
|
|
7398
|
+
}
|
|
7399
|
+
prepareFounderAccount(input) {
|
|
7400
|
+
return this.#lifecycleAction("prepareFounderAccount", input, () => this.#convex.action(this.#fns.prepareFounderAccount, { orgId: input.orgId }));
|
|
7401
|
+
}
|
|
7402
|
+
async authorizeAndSubmitBootstrap(input) {
|
|
7403
|
+
const cancelled = cancellation(input.signal);
|
|
7404
|
+
if (cancelled !== void 0) return cancelled;
|
|
7405
|
+
const signerAddress = await signerResult("getAddress", () => this.#signer.getAddress());
|
|
7406
|
+
if (!signerAddress.ok) return signerAddress;
|
|
7407
|
+
const prepared = await runCall("prepareBootstrap", this.#convex.action(this.#fns.prepareBootstrap, {
|
|
7408
|
+
orgId: input.orgId,
|
|
7409
|
+
signerAddress: signerAddress.value
|
|
7410
|
+
}));
|
|
7411
|
+
if (!prepared.ok) return prepared;
|
|
7412
|
+
const authority = validatePreparedAuthorities(prepared.value, signerAddress.value);
|
|
7413
|
+
if (!authority.ok) return authority;
|
|
7414
|
+
const cancelledAfterPrepare = cancellation(input.signal);
|
|
7415
|
+
if (cancelledAfterPrepare !== void 0) return cancelledAfterPrepare;
|
|
7416
|
+
const signature = await signerResult("signUserOpHash", () => this.#signer.signUserOpHash(prepared.value.digest));
|
|
7417
|
+
if (!signature.ok) return signature;
|
|
7418
|
+
const cancelledAfterSign = cancellation(input.signal);
|
|
7419
|
+
if (cancelledAfterSign !== void 0) return cancelledAfterSign;
|
|
7420
|
+
const submitted = await runCall("submitBootstrap", this.#convex.action(this.#fns.submitBootstrap, {
|
|
7421
|
+
orgId: input.orgId,
|
|
7422
|
+
signerAddress: signerAddress.value,
|
|
7423
|
+
signature: signature.value,
|
|
7424
|
+
userOp: prepared.value.userOp
|
|
7425
|
+
}));
|
|
7426
|
+
if (!submitted.ok) return submitted;
|
|
7427
|
+
return parseLifecycle("submitBootstrap", submitted.value);
|
|
7428
|
+
}
|
|
7429
|
+
resumeSubmittedBootstrap(input) {
|
|
7430
|
+
return this.#lifecycleAction("resumeBootstrapSubmission", input, () => this.#convex.action(this.#fns.resumeBootstrapSubmission, { orgId: input.orgId }));
|
|
7431
|
+
}
|
|
7432
|
+
confirmSubmittedBootstrap(input) {
|
|
7433
|
+
return this.#lifecycleAction("confirmBootstrap", input, () => this.#convex.action(this.#fns.confirmBootstrap, { orgId: input.orgId }));
|
|
7434
|
+
}
|
|
7435
|
+
async recordFailure(input) {
|
|
7436
|
+
const errorProvider = input.error.details?.provider;
|
|
7437
|
+
const errorOperation = input.error.details?.operation;
|
|
7438
|
+
const result = await runCall("recordFailure", this.#convex.mutation(this.#fns.recordFailure, {
|
|
7439
|
+
orgId: input.orgId,
|
|
7440
|
+
errorCode: input.error.code,
|
|
7441
|
+
...typeof errorProvider === "string" && typeof errorOperation === "string" ? {
|
|
7442
|
+
errorProvider,
|
|
7443
|
+
errorOperation
|
|
7444
|
+
} : {},
|
|
7445
|
+
retryable: input.retryable
|
|
7446
|
+
}));
|
|
7447
|
+
return result.ok ? parseLifecycle("recordFailure", result.value) : result;
|
|
7448
|
+
}
|
|
7449
|
+
async loadLifecycle(input) {
|
|
7450
|
+
const result = await runCall("loadLifecycle", this.#convex.query(this.#fns.load, input));
|
|
7451
|
+
if (!result.ok) return result;
|
|
7452
|
+
if (result.value === null) return fail$2(Errors.invalidInput("orgId", "Organization lifecycle was not found"));
|
|
7453
|
+
return parseLifecycle("loadLifecycle", result.value);
|
|
7454
|
+
}
|
|
7455
|
+
async retry(input) {
|
|
7456
|
+
const cancelled = cancellation(input.signal);
|
|
7457
|
+
if (cancelled !== void 0) return cancelled;
|
|
7458
|
+
const current = await this.loadLifecycle({ orgId: input.orgId });
|
|
7459
|
+
if (!current.ok) return current;
|
|
7460
|
+
if (current.value.status === "failed" && current.value.retryable && (current.value.at === "awaitingFounderAuthorization" || current.value.at === "submittingBootstrap")) {
|
|
7461
|
+
const reset = resetSignerSession(this.#signer);
|
|
7462
|
+
if (!reset.ok) return reset;
|
|
7463
|
+
}
|
|
7464
|
+
const result = await runCall("retry", this.#convex.mutation(this.#fns.retry, { orgId: input.orgId }));
|
|
7465
|
+
if (!result.ok) return result;
|
|
7466
|
+
return parseLifecycle("retry", result.value);
|
|
7467
|
+
}
|
|
7468
|
+
async #lifecycleAction(operation, input, call) {
|
|
7469
|
+
const cancelled = cancellation(input.signal);
|
|
7470
|
+
if (cancelled !== void 0) return cancelled;
|
|
7471
|
+
const result = await runCall(operation, call());
|
|
7472
|
+
if (!result.ok) return result;
|
|
7473
|
+
const cancelledAfter = cancellation(input.signal);
|
|
7474
|
+
if (cancelledAfter !== void 0) return cancelledAfter;
|
|
7475
|
+
return parseLifecycle(operation, result.value);
|
|
7476
|
+
}
|
|
7477
|
+
};
|
|
7478
|
+
function resetSignerSession(signer) {
|
|
7479
|
+
const resetSession = signer.resetSession;
|
|
7480
|
+
if (typeof resetSession !== "function") return {
|
|
7481
|
+
ok: true,
|
|
7482
|
+
value: void 0
|
|
7483
|
+
};
|
|
7484
|
+
try {
|
|
7485
|
+
resetSession.call(signer);
|
|
7486
|
+
return {
|
|
7487
|
+
ok: true,
|
|
7488
|
+
value: void 0
|
|
7489
|
+
};
|
|
7490
|
+
} catch (cause) {
|
|
7491
|
+
return fail$2(cause instanceof CapxulError ? cause : Errors.providerError("openfort", "resetSession", cause, { failure_mode: "unknown" }));
|
|
7492
|
+
}
|
|
7493
|
+
}
|
|
7494
|
+
async function runCall(operation, effect) {
|
|
7495
|
+
try {
|
|
7496
|
+
const result = await Effect.runPromise(Effect.either(effect));
|
|
7497
|
+
return Either.isRight(result) ? {
|
|
7498
|
+
ok: true,
|
|
7499
|
+
value: result.right
|
|
7500
|
+
} : fail$2(publicError(operation, result.left));
|
|
7501
|
+
} catch (cause) {
|
|
7502
|
+
return fail$2(publicError(operation, cause));
|
|
7503
|
+
}
|
|
7504
|
+
}
|
|
7505
|
+
function publicError(operation, cause) {
|
|
7506
|
+
if (cause instanceof CapxulError) return cause;
|
|
7507
|
+
if (typeof cause === "object" && cause !== null) {
|
|
7508
|
+
const carried = cause.publicError;
|
|
7509
|
+
if (carried instanceof CapxulError) return carried;
|
|
7510
|
+
}
|
|
7511
|
+
return Errors.providerError("convex-organization", operation, cause);
|
|
7512
|
+
}
|
|
7513
|
+
async function signerResult(operation, run) {
|
|
7514
|
+
try {
|
|
7515
|
+
return {
|
|
7516
|
+
ok: true,
|
|
7517
|
+
value: await run()
|
|
7518
|
+
};
|
|
7519
|
+
} catch (cause) {
|
|
7520
|
+
return fail$2(cause instanceof CapxulError ? cause : Errors.providerError("organization-signer", operation, cause));
|
|
7521
|
+
}
|
|
7522
|
+
}
|
|
7523
|
+
function validatePreparedAuthorities(prepared, signerAddress) {
|
|
7524
|
+
const signer = signerAddress.toLowerCase();
|
|
7525
|
+
const preparedSigner = prepared.signerAddress.toLowerCase();
|
|
7526
|
+
const founder = prepared.founderPersonalAccount.toLowerCase();
|
|
7527
|
+
const organization = prepared.organizationAccountAddress.toLowerCase();
|
|
7528
|
+
const sender = prepared.userOp.sender.toLowerCase();
|
|
7529
|
+
if (preparedSigner !== signer) return fail$2(Errors.invalidInput("signerAddress", "Prepared signer does not match configured signer"));
|
|
7530
|
+
if (founder === signer || organization === signer || organization === founder) return fail$2(Errors.invalidInput("organizationAuthority", "Signer EOA, founder Account, and Organization Account must be distinct"));
|
|
7531
|
+
if (sender !== founder) return fail$2(Errors.invalidInput("userOp.sender", "Bootstrap sender must be the founder Account"));
|
|
7532
|
+
if (!/^0x[0-9a-fA-F]{64}$/u.test(prepared.digest)) return fail$2(Errors.invalidInput("digest", "Prepared bootstrap digest must be 32-byte hex"));
|
|
7533
|
+
return {
|
|
7534
|
+
ok: true,
|
|
7535
|
+
value: void 0
|
|
7536
|
+
};
|
|
7537
|
+
}
|
|
7538
|
+
function parseLifecycle(operation, wire) {
|
|
7539
|
+
const orgId = parseOrgId(operation, wire.orgId);
|
|
7540
|
+
if (!orgId.ok) return orgId;
|
|
7541
|
+
if (wire.status === "loading") return {
|
|
7542
|
+
ok: true,
|
|
7543
|
+
value: {
|
|
7544
|
+
status: "loading",
|
|
7545
|
+
orgId: orgId.value
|
|
7546
|
+
}
|
|
7547
|
+
};
|
|
7548
|
+
if (wire.status === "ready") return {
|
|
7549
|
+
ok: true,
|
|
7550
|
+
value: {
|
|
7551
|
+
status: "ready",
|
|
7552
|
+
orgId: orgId.value,
|
|
7553
|
+
canTransact: true
|
|
7554
|
+
}
|
|
7555
|
+
};
|
|
7556
|
+
if (wire.status === "failed") {
|
|
7557
|
+
if (!isSetupStep(wire.at)) return fail$2(Errors.invalidInput("lifecycle.at", "Unknown setup step"));
|
|
7558
|
+
return {
|
|
7559
|
+
ok: true,
|
|
7560
|
+
value: {
|
|
7561
|
+
status: "failed",
|
|
7562
|
+
orgId: orgId.value,
|
|
7563
|
+
at: wire.at,
|
|
7564
|
+
error: new CapxulError(wire.error.code, wire.error.message),
|
|
7565
|
+
retryable: wire.retryable
|
|
7566
|
+
}
|
|
7567
|
+
};
|
|
7568
|
+
}
|
|
7569
|
+
if (!isSetupStep(wire.step)) return fail$2(Errors.invalidInput("lifecycle.step", `Unknown setup step from ${operation}`));
|
|
7570
|
+
return {
|
|
7571
|
+
ok: true,
|
|
7572
|
+
value: {
|
|
7573
|
+
status: "settingUp",
|
|
7574
|
+
orgId: orgId.value,
|
|
7575
|
+
step: wire.step
|
|
7576
|
+
}
|
|
7577
|
+
};
|
|
7578
|
+
}
|
|
7579
|
+
function parseOrgId(operation, value) {
|
|
7580
|
+
try {
|
|
7581
|
+
return {
|
|
7582
|
+
ok: true,
|
|
7583
|
+
value: toOrgId(value)
|
|
7584
|
+
};
|
|
7585
|
+
} catch (cause) {
|
|
7586
|
+
return fail$2(Errors.providerError("convex-organization", operation, cause));
|
|
7587
|
+
}
|
|
7588
|
+
}
|
|
7589
|
+
function isSetupStep(value) {
|
|
7590
|
+
return value === "preparingFounderAccount" || value === "awaitingFounderAuthorization" || value === "submittingBootstrap" || value === "confirmingBootstrap";
|
|
7591
|
+
}
|
|
7592
|
+
function cancellation(signal) {
|
|
7593
|
+
return signal?.aborted ? fail$2(Errors.cancelled({ operation: "organization.setup" })) : void 0;
|
|
7594
|
+
}
|
|
7595
|
+
function fail$2(error) {
|
|
7596
|
+
return {
|
|
7597
|
+
ok: false,
|
|
7598
|
+
error
|
|
7599
|
+
};
|
|
7600
|
+
}
|
|
7601
|
+
//#endregion
|
|
7602
|
+
//#region ../../packages/observability/src/index.ts
|
|
7603
|
+
const PII = Schema.String.pipe(Schema.brand("PII"));
|
|
7604
|
+
const OptionalString = Schema.optional(Schema.String);
|
|
7605
|
+
const AddressSchema = Schema.String.pipe(Schema.transform(Schema.String, {
|
|
7606
|
+
decode: (value) => value.toLowerCase(),
|
|
7607
|
+
encode: (value) => value
|
|
7608
|
+
}), Schema.filter((value) => EVM_ADDRESS_RE$1.test(value), { message: () => "must be 0x + 40 hex chars" }));
|
|
7609
|
+
const AppIdSchema = Schema.String.pipe(Schema.filter((value) => APP_ID_RE.test(value), { message: () => "must be app_ plus a ULID" }));
|
|
7610
|
+
const BlockNumberSchema = Schema.Number.pipe(Schema.filter((value) => Number.isSafeInteger(value) && value >= 0, { message: () => "must be a non-negative safe integer" }));
|
|
7611
|
+
const ChainIdSchema = Schema.Number.pipe(Schema.filter((value) => Number.isSafeInteger(value) && value > 0, { message: () => "must be a positive safe integer" }));
|
|
7612
|
+
const DurationMsSchema = Schema.Number.pipe(Schema.filter((value) => Number.isSafeInteger(value) && value >= 0, { message: () => "must be a non-negative safe integer" }));
|
|
7613
|
+
const EpochMsSchema = Schema.Number.pipe(Schema.filter((value) => Number.isSafeInteger(value) && value >= 0, { message: () => "must be a non-negative safe integer" }));
|
|
7614
|
+
const PublishableKeyIdSchema = Schema.String.pipe(Schema.filter((value) => value.length > 0, { message: () => "must be a non-empty string" }));
|
|
7615
|
+
const TxHashSchema = Schema.String.pipe(Schema.filter((value) => BYTES32_RE$2.test(value), { message: () => "must be 0x + 64 hex chars" }));
|
|
7616
|
+
const ACCOUNT_ID_TELEMETRY_RE = /^account_[0-9A-Za-z]+$/;
|
|
7617
|
+
const SUBACCOUNT_ID_TELEMETRY_RE = /^subaccount_[0-9A-Za-z]+$/;
|
|
7618
|
+
const WEI_AMOUNT_TELEMETRY_RE = /^[0-9]+$/;
|
|
7619
|
+
const AccountIdSchema = Schema.String.pipe(Schema.filter((value) => ACCOUNT_ID_TELEMETRY_RE.test(value), { message: () => "must be account_ plus an alphanumeric id" }));
|
|
7620
|
+
const SubAccountIdSchema = Schema.String.pipe(Schema.filter((value) => SUBACCOUNT_ID_TELEMETRY_RE.test(value), { message: () => "must be subaccount_ plus an alphanumeric id" }));
|
|
7621
|
+
const WeiAmountSchema = Schema.String.pipe(Schema.filter((value) => WEI_AMOUNT_TELEMETRY_RE.test(value), { message: () => "must be a non-negative integer string" }));
|
|
7622
|
+
const CurrencyCodeSchema = Schema.String.pipe(Schema.filter((value) => value.length > 0, { message: () => "must be a non-empty currency code" }));
|
|
7623
|
+
const BalanceBucketSchema = Schema.Literal("zero", "nonzero");
|
|
7624
|
+
const TransferDirectionSchema = Schema.Literal("add", "out", "between");
|
|
7625
|
+
const SubAccountOpSchema = Schema.Literal("create", "rename", "delete");
|
|
7626
|
+
const OptionalAccountId = Schema.optional(AccountIdSchema);
|
|
7627
|
+
const OptionalSubAccountId = Schema.optional(SubAccountIdSchema);
|
|
7628
|
+
const OptionalWeiAmount = Schema.optional(WeiAmountSchema);
|
|
7629
|
+
const OptionalCurrencyCode = Schema.optional(CurrencyCodeSchema);
|
|
7630
|
+
const OptionalBalanceBucket = Schema.optional(BalanceBucketSchema);
|
|
7631
|
+
const OptionalTransferDirection = Schema.optional(TransferDirectionSchema);
|
|
7632
|
+
const OptionalSubAccountOp = Schema.optional(SubAccountOpSchema);
|
|
7633
|
+
const OptionalTrue = Schema.optional(Schema.Literal(true));
|
|
7634
|
+
const OptionalAddress = Schema.optional(AddressSchema);
|
|
7635
|
+
const OptionalAppId = Schema.optional(AppIdSchema);
|
|
7636
|
+
const OptionalBlockNumber = Schema.optional(BlockNumberSchema);
|
|
7637
|
+
const OptionalChainId = Schema.optional(ChainIdSchema);
|
|
7638
|
+
const OptionalDurationMs = Schema.optional(DurationMsSchema);
|
|
7639
|
+
const OptionalEpochMs = Schema.optional(EpochMsSchema);
|
|
7640
|
+
const OptionalPublishableKeyId = Schema.optional(PublishableKeyIdSchema);
|
|
7641
|
+
const OptionalTxHash = Schema.optional(TxHashSchema);
|
|
7642
|
+
const PAYMENT_ID_TELEMETRY_RE = /^payment_[0-9A-Za-z]+$/;
|
|
7643
|
+
const PAYEE_ID_TELEMETRY_RE = /^payee_[0-9A-Za-z]+$/;
|
|
7644
|
+
const PaymentIdTelemetrySchema = Schema.String.pipe(Schema.filter((value) => PAYMENT_ID_TELEMETRY_RE.test(value), { message: () => "must be payment_ plus an alphanumeric id" }));
|
|
7645
|
+
const PayeeIdTelemetrySchema = Schema.String.pipe(Schema.filter((value) => PAYEE_ID_TELEMETRY_RE.test(value), { message: () => "must be payee_ plus an alphanumeric id" }));
|
|
7646
|
+
const DocumentHashSchema = Schema.String.pipe(Schema.filter((value) => BYTES32_RE$2.test(value), { message: () => "must be 0x + 64 hex chars" }));
|
|
7647
|
+
const TelemetryEnvelopeProps = {
|
|
7648
|
+
capxul_e2e_run_id: OptionalString,
|
|
7649
|
+
correlationId: OptionalString,
|
|
7650
|
+
capxulEnv: OptionalString,
|
|
7651
|
+
sdkVersion: OptionalString,
|
|
7652
|
+
producer: OptionalString
|
|
7653
|
+
};
|
|
7654
|
+
const AuthOtpRequestedProps = Schema.Struct({
|
|
7655
|
+
...TelemetryEnvelopeProps,
|
|
7656
|
+
email: Schema.optional(PII),
|
|
7657
|
+
email_domain: OptionalString
|
|
7658
|
+
});
|
|
7659
|
+
const AuthOtpDeliveredProps = Schema.Struct({
|
|
7660
|
+
...TelemetryEnvelopeProps,
|
|
7661
|
+
durationMs: OptionalDurationMs,
|
|
7662
|
+
email: Schema.optional(PII),
|
|
7663
|
+
email_domain: OptionalString,
|
|
7664
|
+
resendMessageId: OptionalString
|
|
7665
|
+
});
|
|
7666
|
+
const AuthOtpExpiredProps = Schema.Struct({
|
|
7667
|
+
...TelemetryEnvelopeProps,
|
|
7668
|
+
email: Schema.optional(PII),
|
|
7669
|
+
email_domain: OptionalString
|
|
7670
|
+
});
|
|
7671
|
+
const AuthVerifiedProps = Schema.Struct({
|
|
7672
|
+
...TelemetryEnvelopeProps,
|
|
7673
|
+
auth_type: OptionalString
|
|
7674
|
+
});
|
|
7675
|
+
const AuthFailedProps = Schema.Struct({
|
|
7676
|
+
...TelemetryEnvelopeProps,
|
|
7677
|
+
email: Schema.optional(PII),
|
|
7678
|
+
auth_type: OptionalString,
|
|
7679
|
+
reason: OptionalString
|
|
7680
|
+
});
|
|
7681
|
+
const AuthSignedOutProps = Schema.Struct(TelemetryEnvelopeProps);
|
|
7682
|
+
const ProvisioningSafeCreatedProps = Schema.Struct({
|
|
7683
|
+
...TelemetryEnvelopeProps,
|
|
7684
|
+
safe_address: OptionalAddress
|
|
7685
|
+
});
|
|
7686
|
+
const ProvisioningSafeConfirmedProps = Schema.Struct({
|
|
7687
|
+
...TelemetryEnvelopeProps,
|
|
7688
|
+
chainId: OptionalChainId,
|
|
7689
|
+
deployedAt: OptionalEpochMs,
|
|
7690
|
+
deployedAtBlock: OptionalBlockNumber,
|
|
7691
|
+
deployTxHash: OptionalTxHash,
|
|
7692
|
+
durationMs: OptionalDurationMs,
|
|
7693
|
+
safe_address: OptionalAddress,
|
|
7694
|
+
userOpHash: OptionalTxHash
|
|
7695
|
+
});
|
|
7279
7696
|
const BootstrapResolvedProps = Schema.Struct({
|
|
7280
7697
|
...TelemetryEnvelopeProps,
|
|
7281
7698
|
applicationId: OptionalAppId,
|
|
@@ -8022,6 +8439,9 @@ function transportErrorFromThrown(operation, request, cause) {
|
|
|
8022
8439
|
}
|
|
8023
8440
|
//#endregion
|
|
8024
8441
|
//#region ../../packages/sdk/src/openfort/create-openfort-browser-signer.ts
|
|
8442
|
+
function openfortProviderError(operation, cause) {
|
|
8443
|
+
return cause instanceof CapxulError ? cause : Errors.providerError("openfort", operation, cause, { failure_mode: "unknown" });
|
|
8444
|
+
}
|
|
8025
8445
|
/**
|
|
8026
8446
|
* True when the browser cannot perform Web Crypto — sandboxed iframes, headless
|
|
8027
8447
|
* agent browsers, or non-HTTPS origins. OpenFort's embedded-wallet `configure`
|
|
@@ -8090,21 +8510,39 @@ function createOpenfortBrowserSignerFromBootstrap(bootstrap, options = {}) {
|
|
|
8090
8510
|
return `${authBaseUrl}/encryption-session`;
|
|
8091
8511
|
}
|
|
8092
8512
|
async function fetchBetterAuthAccessToken() {
|
|
8093
|
-
|
|
8094
|
-
|
|
8513
|
+
try {
|
|
8514
|
+
const response = await fetch(betterAuthSessionUrl(), { credentials: "include" });
|
|
8515
|
+
if (!response.ok) {
|
|
8516
|
+
diagnostic?.trace("openfort.token", {
|
|
8517
|
+
ok: false,
|
|
8518
|
+
tokenPresent: false,
|
|
8519
|
+
httpStatus: response.status,
|
|
8520
|
+
failure_mode: "unknown"
|
|
8521
|
+
});
|
|
8522
|
+
return null;
|
|
8523
|
+
}
|
|
8524
|
+
const token = (await response.json()).session?.token?.trim();
|
|
8525
|
+
if (token === void 0 || token.length === 0) {
|
|
8526
|
+
diagnostic?.trace("openfort.token", {
|
|
8527
|
+
ok: false,
|
|
8528
|
+
tokenPresent: false,
|
|
8529
|
+
failure_mode: "unknown"
|
|
8530
|
+
});
|
|
8531
|
+
return null;
|
|
8532
|
+
}
|
|
8533
|
+
diagnostic?.trace("openfort.token", {
|
|
8534
|
+
ok: true,
|
|
8535
|
+
tokenPresent: true
|
|
8536
|
+
});
|
|
8537
|
+
return token;
|
|
8538
|
+
} catch (cause) {
|
|
8095
8539
|
diagnostic?.trace("openfort.token", {
|
|
8540
|
+
ok: false,
|
|
8096
8541
|
tokenPresent: false,
|
|
8097
|
-
|
|
8542
|
+
failure_mode: "unknown"
|
|
8098
8543
|
});
|
|
8099
|
-
|
|
8100
|
-
}
|
|
8101
|
-
const token = (await response.json()).session?.token?.trim();
|
|
8102
|
-
if (token === void 0 || token.length === 0) {
|
|
8103
|
-
diagnostic?.trace("openfort.token", { tokenPresent: false });
|
|
8104
|
-
return null;
|
|
8544
|
+
throw openfortProviderError("token", cause);
|
|
8105
8545
|
}
|
|
8106
|
-
diagnostic?.trace("openfort.token", { tokenPresent: true });
|
|
8107
|
-
return token;
|
|
8108
8546
|
}
|
|
8109
8547
|
const openfort = new Openfort({
|
|
8110
8548
|
baseConfiguration: { publishableKey: bootstrap.openfortPublishableKey },
|
|
@@ -8120,25 +8558,60 @@ function createOpenfortBrowserSignerFromBootstrap(bootstrap, options = {}) {
|
|
|
8120
8558
|
if (isInsecureBrowserContext()) failNoSecureContext();
|
|
8121
8559
|
await openfort.waitForInitialization();
|
|
8122
8560
|
const accessToken = await fetchBetterAuthAccessToken();
|
|
8123
|
-
if (accessToken === null) throw
|
|
8124
|
-
|
|
8125
|
-
|
|
8126
|
-
|
|
8127
|
-
|
|
8128
|
-
|
|
8129
|
-
|
|
8130
|
-
|
|
8131
|
-
|
|
8132
|
-
|
|
8133
|
-
|
|
8561
|
+
if (accessToken === null) throw openfortProviderError("token", /* @__PURE__ */ new Error("Better Auth access token unavailable for Openfort"));
|
|
8562
|
+
let encryptionResponse;
|
|
8563
|
+
try {
|
|
8564
|
+
encryptionResponse = await fetch(encryptionSessionUrl(), {
|
|
8565
|
+
method: "POST",
|
|
8566
|
+
credentials: "include",
|
|
8567
|
+
headers: {
|
|
8568
|
+
Authorization: `Bearer ${accessToken}`,
|
|
8569
|
+
"Content-Type": "application/json"
|
|
8570
|
+
},
|
|
8571
|
+
body: JSON.stringify({})
|
|
8572
|
+
});
|
|
8573
|
+
} catch (cause) {
|
|
8574
|
+
diagnostic?.trace("openfort.encryptionSession", {
|
|
8575
|
+
ok: false,
|
|
8576
|
+
failure_mode: "unknown"
|
|
8577
|
+
});
|
|
8578
|
+
throw openfortProviderError("encryptionSession", cause);
|
|
8579
|
+
}
|
|
8134
8580
|
if (!encryptionResponse.ok) {
|
|
8135
|
-
|
|
8136
|
-
|
|
8581
|
+
diagnostic?.trace("openfort.encryptionSession", {
|
|
8582
|
+
ok: false,
|
|
8583
|
+
httpStatus: encryptionResponse.status,
|
|
8584
|
+
failure_mode: "unknown"
|
|
8585
|
+
});
|
|
8586
|
+
throw Errors.providerError("openfort", "encryptionSession", /* @__PURE__ */ new Error(`Openfort encryption session failed (${encryptionResponse.status})`), { failure_mode: "unknown" });
|
|
8587
|
+
}
|
|
8588
|
+
let encryptionBody;
|
|
8589
|
+
try {
|
|
8590
|
+
encryptionBody = await encryptionResponse.json();
|
|
8591
|
+
if (typeof encryptionBody.sessionId !== "string" || encryptionBody.sessionId.length === 0) throw new Error("Openfort encryption session response missing sessionId");
|
|
8592
|
+
} catch (cause) {
|
|
8593
|
+
diagnostic?.trace("openfort.encryptionSession", {
|
|
8594
|
+
ok: false,
|
|
8595
|
+
httpStatus: encryptionResponse.status,
|
|
8596
|
+
failure_mode: "unknown"
|
|
8597
|
+
});
|
|
8598
|
+
throw openfortProviderError("encryptionSession", cause);
|
|
8599
|
+
}
|
|
8600
|
+
diagnostic?.trace("openfort.encryptionSession", {
|
|
8601
|
+
ok: true,
|
|
8602
|
+
httpStatus: encryptionResponse.status
|
|
8603
|
+
});
|
|
8604
|
+
let embeddedState;
|
|
8605
|
+
try {
|
|
8606
|
+
embeddedState = await openfort.embeddedWallet.getEmbeddedState();
|
|
8607
|
+
diagnostic?.trace("openfort.embeddedState", { state: embeddedState });
|
|
8608
|
+
} catch (cause) {
|
|
8609
|
+
diagnostic?.trace("openfort.embeddedState", {
|
|
8610
|
+
ok: false,
|
|
8611
|
+
failure_mode: "unknown"
|
|
8612
|
+
});
|
|
8613
|
+
throw openfortProviderError("embeddedState", cause);
|
|
8137
8614
|
}
|
|
8138
|
-
const encryptionBody = await encryptionResponse.json();
|
|
8139
|
-
if (typeof encryptionBody.sessionId !== "string" || encryptionBody.sessionId.length === 0) throw Errors.providerError("openfort", "encryptionSession", /* @__PURE__ */ new Error("Openfort encryption session response missing sessionId"));
|
|
8140
|
-
const embeddedState = await openfort.embeddedWallet.getEmbeddedState();
|
|
8141
|
-
diagnostic?.trace("openfort.embeddedState", { state: embeddedState });
|
|
8142
8615
|
if (embeddedState !== EmbeddedState.READY) {
|
|
8143
8616
|
clearStaleOpenfortBrowserStorage(bootstrap.openfortPublishableKey);
|
|
8144
8617
|
diagnostic?.trace("openfort.storageCleared", { beforeConfigure: true });
|
|
@@ -8155,9 +8628,9 @@ function createOpenfortBrowserSignerFromBootstrap(bootstrap, options = {}) {
|
|
|
8155
8628
|
} catch (cause) {
|
|
8156
8629
|
diagnostic?.trace("openfort.configure", {
|
|
8157
8630
|
ok: false,
|
|
8158
|
-
|
|
8631
|
+
failure_mode: "unknown"
|
|
8159
8632
|
});
|
|
8160
|
-
throw cause;
|
|
8633
|
+
throw openfortProviderError("configure", cause);
|
|
8161
8634
|
}
|
|
8162
8635
|
}
|
|
8163
8636
|
try {
|
|
@@ -8166,9 +8639,9 @@ function createOpenfortBrowserSignerFromBootstrap(bootstrap, options = {}) {
|
|
|
8166
8639
|
} catch (cause) {
|
|
8167
8640
|
diagnostic?.trace("openfort.get", {
|
|
8168
8641
|
ok: false,
|
|
8169
|
-
|
|
8642
|
+
failure_mode: "unknown"
|
|
8170
8643
|
});
|
|
8171
|
-
throw cause;
|
|
8644
|
+
throw openfortProviderError("get", cause);
|
|
8172
8645
|
}
|
|
8173
8646
|
})();
|
|
8174
8647
|
}
|
|
@@ -8187,6 +8660,19 @@ function createOpenfortBrowserSignerFromBootstrap(bootstrap, options = {}) {
|
|
|
8187
8660
|
});
|
|
8188
8661
|
return {
|
|
8189
8662
|
...signer,
|
|
8663
|
+
getAddress: async () => {
|
|
8664
|
+
try {
|
|
8665
|
+
const address = await signer.getAddress();
|
|
8666
|
+
diagnostic?.trace("openfort.address", { ok: true });
|
|
8667
|
+
return address;
|
|
8668
|
+
} catch (cause) {
|
|
8669
|
+
diagnostic?.trace("openfort.address", {
|
|
8670
|
+
ok: false,
|
|
8671
|
+
failure_mode: "unknown"
|
|
8672
|
+
});
|
|
8673
|
+
throw openfortProviderError("getAddress", cause);
|
|
8674
|
+
}
|
|
8675
|
+
},
|
|
8190
8676
|
resetSession: () => {
|
|
8191
8677
|
walletReadyPromise = null;
|
|
8192
8678
|
clearStaleOpenfortBrowserStorage(bootstrap.openfortPublishableKey);
|
|
@@ -10668,6 +11154,80 @@ function listOrgsProgram() {
|
|
|
10668
11154
|
});
|
|
10669
11155
|
}
|
|
10670
11156
|
//#endregion
|
|
11157
|
+
//#region ../../packages/sdk/src/client/org-lifecycle.ts
|
|
11158
|
+
function fail$1(error) {
|
|
11159
|
+
return {
|
|
11160
|
+
ok: false,
|
|
11161
|
+
error
|
|
11162
|
+
};
|
|
11163
|
+
}
|
|
11164
|
+
function validateOrganizationLifecycleScope(orgId, lifecycle) {
|
|
11165
|
+
if (String(lifecycle.orgId) !== String(orgId)) return fail$1(Errors.invalidInput("orgId", "Organization lifecycle scope does not match"));
|
|
11166
|
+
return {
|
|
11167
|
+
ok: true,
|
|
11168
|
+
value: lifecycle
|
|
11169
|
+
};
|
|
11170
|
+
}
|
|
11171
|
+
/** Advance only the steps still required by one durable Organization lane. */
|
|
11172
|
+
async function advanceOrganizationSetup(setup, orgId, initial, signal) {
|
|
11173
|
+
const scopedInitial = validateOrganizationLifecycleScope(orgId, initial);
|
|
11174
|
+
if (!scopedInitial.ok) return scopedInitial;
|
|
11175
|
+
let lifecycle = scopedInitial.value;
|
|
11176
|
+
for (let transition = 0; transition < 3; transition += 1) {
|
|
11177
|
+
if (lifecycle.status !== "settingUp") return {
|
|
11178
|
+
ok: true,
|
|
11179
|
+
value: lifecycle
|
|
11180
|
+
};
|
|
11181
|
+
const currentStep = lifecycle.step;
|
|
11182
|
+
if (signal?.aborted) return recordSetupFailure(setup, orgId, Errors.cancelled({ operation: "organization.setup" }), true);
|
|
11183
|
+
const stepInput = {
|
|
11184
|
+
orgId,
|
|
11185
|
+
...signal === void 0 ? {} : { signal }
|
|
11186
|
+
};
|
|
11187
|
+
const next = lifecycle.step === "preparingFounderAccount" ? await setup.prepareFounderAccount(stepInput) : lifecycle.step === "awaitingFounderAuthorization" ? await setup.authorizeAndSubmitBootstrap(stepInput) : lifecycle.step === "submittingBootstrap" ? await setup.resumeSubmittedBootstrap(stepInput) : await setup.confirmSubmittedBootstrap(stepInput);
|
|
11188
|
+
if (!next.ok) {
|
|
11189
|
+
if (next.error.code === "CANCELLED") return recordSetupFailure(setup, orgId, next.error, true);
|
|
11190
|
+
if (next.error.code === "PROVIDER_ERROR") return recordSetupFailure(setup, orgId, next.error, isRetryableProviderFailure(next.error));
|
|
11191
|
+
return next;
|
|
11192
|
+
}
|
|
11193
|
+
const scopedNext = validateOrganizationLifecycleScope(orgId, next.value);
|
|
11194
|
+
if (!scopedNext.ok) return scopedNext;
|
|
11195
|
+
lifecycle = scopedNext.value;
|
|
11196
|
+
if (currentStep === "confirmingBootstrap") return {
|
|
11197
|
+
ok: true,
|
|
11198
|
+
value: lifecycle
|
|
11199
|
+
};
|
|
11200
|
+
}
|
|
11201
|
+
if (lifecycle.status !== "settingUp" || lifecycle.step === "confirmingBootstrap") return {
|
|
11202
|
+
ok: true,
|
|
11203
|
+
value: lifecycle
|
|
11204
|
+
};
|
|
11205
|
+
return fail$1(Errors.wrongState({
|
|
11206
|
+
method: "organization.setup",
|
|
11207
|
+
currentState: lifecycle.step,
|
|
11208
|
+
validStates: [
|
|
11209
|
+
"confirmingBootstrap",
|
|
11210
|
+
"ready",
|
|
11211
|
+
"failed"
|
|
11212
|
+
]
|
|
11213
|
+
}));
|
|
11214
|
+
}
|
|
11215
|
+
async function recordSetupFailure(setup, orgId, error, retryable) {
|
|
11216
|
+
const recorded = await setup.recordFailure({
|
|
11217
|
+
orgId,
|
|
11218
|
+
error,
|
|
11219
|
+
retryable
|
|
11220
|
+
});
|
|
11221
|
+
if (!recorded.ok) return recorded;
|
|
11222
|
+
const scopedRecorded = validateOrganizationLifecycleScope(orgId, recorded.value);
|
|
11223
|
+
if (!scopedRecorded.ok) return scopedRecorded;
|
|
11224
|
+
return fail$1(error);
|
|
11225
|
+
}
|
|
11226
|
+
function isRetryableProviderFailure(error) {
|
|
11227
|
+
const mode = error.details?.failure_mode;
|
|
11228
|
+
return mode !== "auth-origin-mismatch" && mode !== "app-env-allowlist" && mode !== "no-secure-context";
|
|
11229
|
+
}
|
|
11230
|
+
//#endregion
|
|
10671
11231
|
//#region ../../packages/sdk/src/client/org.ts
|
|
10672
11232
|
/**
|
|
10673
11233
|
* Org method surface (canon §C2/§C3, D13). S1 (#274) wires `createOrg` /
|
|
@@ -10716,6 +11276,36 @@ function makeOrgMethods(deps) {
|
|
|
10716
11276
|
},
|
|
10717
11277
|
...convexCall === void 0 ? {} : { convexCall }
|
|
10718
11278
|
}),
|
|
11279
|
+
async getLifecycle(options) {
|
|
11280
|
+
if (options?.signal?.aborted) return {
|
|
11281
|
+
ok: false,
|
|
11282
|
+
error: Errors.cancelled({ operation: "org.getLifecycle" })
|
|
11283
|
+
};
|
|
11284
|
+
if (deps.organizationSetup === void 0) return {
|
|
11285
|
+
ok: false,
|
|
11286
|
+
error: Errors.notImplemented("organizationSetup", "getLifecycle")
|
|
11287
|
+
};
|
|
11288
|
+
const loaded = await deps.organizationSetup.loadLifecycle({ orgId });
|
|
11289
|
+
if (!loaded.ok) return loaded;
|
|
11290
|
+
return validateOrganizationLifecycleScope(orgId, loaded.value);
|
|
11291
|
+
},
|
|
11292
|
+
async retrySetup(options) {
|
|
11293
|
+
if (options?.signal?.aborted) return {
|
|
11294
|
+
ok: false,
|
|
11295
|
+
error: Errors.cancelled({ operation: "org.retrySetup" })
|
|
11296
|
+
};
|
|
11297
|
+
const setup = deps.organizationSetup;
|
|
11298
|
+
if (setup === void 0) return {
|
|
11299
|
+
ok: false,
|
|
11300
|
+
error: Errors.notImplemented("organizationSetup", "retrySetup")
|
|
11301
|
+
};
|
|
11302
|
+
const retried = await setup.retry({
|
|
11303
|
+
orgId,
|
|
11304
|
+
...options?.signal === void 0 ? {} : { signal: options.signal }
|
|
11305
|
+
});
|
|
11306
|
+
if (!retried.ok) return retried;
|
|
11307
|
+
return advanceOrganizationSetup(setup, orgId, retried.value, options?.signal);
|
|
11308
|
+
},
|
|
10719
11309
|
profile: {
|
|
10720
11310
|
get(_options) {
|
|
10721
11311
|
if (_options?.signal?.aborted) return Promise.resolve({
|
|
@@ -10749,12 +11339,12 @@ function makeOrgMethods(deps) {
|
|
|
10749
11339
|
ok: false,
|
|
10750
11340
|
error: treasury.error
|
|
10751
11341
|
};
|
|
10752
|
-
const
|
|
10753
|
-
if (!
|
|
11342
|
+
const orgList = await toCapxulResult(listOrgsProgram(), layer);
|
|
11343
|
+
if (!orgList.ok) return {
|
|
10754
11344
|
ok: false,
|
|
10755
|
-
error:
|
|
11345
|
+
error: orgList.error
|
|
10756
11346
|
};
|
|
10757
|
-
const org =
|
|
11347
|
+
const org = orgList.value.find((candidate) => candidate.id === orgId);
|
|
10758
11348
|
return {
|
|
10759
11349
|
ok: true,
|
|
10760
11350
|
value: {
|
|
@@ -10942,7 +11532,6 @@ function normalizePaymentTiming(payment) {
|
|
|
10942
11532
|
}
|
|
10943
11533
|
//#endregion
|
|
10944
11534
|
//#region ../../packages/sdk/src/flows/onboarding.ts
|
|
10945
|
-
const DEFAULT_ORG_TEMPLATE = "Startup";
|
|
10946
11535
|
async function runCompletePersonalOnboarding(ops, input) {
|
|
10947
11536
|
const validated = validatePersonalInput(input);
|
|
10948
11537
|
if (!validated.ok) return validated;
|
|
@@ -10966,11 +11555,13 @@ async function runCompletePersonalOnboarding(ops, input) {
|
|
|
10966
11555
|
value: { lifecycle: lifecycle.value }
|
|
10967
11556
|
};
|
|
10968
11557
|
}
|
|
10969
|
-
async function runCompleteOrganizationOnboarding(ops, input) {
|
|
11558
|
+
async function runCompleteOrganizationOnboarding(ops, input, options) {
|
|
10970
11559
|
const validated = validateOrganizationInput(input);
|
|
10971
11560
|
if (!validated.ok) return validated;
|
|
10972
11561
|
const session = await ops.currentSession();
|
|
10973
11562
|
if (session === null) return fail(Errors.notAuthenticated());
|
|
11563
|
+
const setup = ops.organizationSetup;
|
|
11564
|
+
if (setup === void 0) return fail(Errors.notImplemented("organizationSetup", "completeOrganization"));
|
|
10974
11565
|
const written = await ops.completeIdentityOnboarding({
|
|
10975
11566
|
authUserId: session.authUserId,
|
|
10976
11567
|
email: session.email,
|
|
@@ -10978,22 +11569,29 @@ async function runCompleteOrganizationOnboarding(ops, input) {
|
|
|
10978
11569
|
country: validated.value.country
|
|
10979
11570
|
});
|
|
10980
11571
|
if (!written.ok) return fail(written.error);
|
|
10981
|
-
const
|
|
10982
|
-
if (!provisioned.ok) return fail(provisioned.error);
|
|
10983
|
-
const org = await ops.createOrg({
|
|
11572
|
+
const started = await setup.startOrResume({
|
|
10984
11573
|
name: validated.value.organizationName,
|
|
10985
11574
|
handle: validated.value.handle,
|
|
10986
|
-
template: DEFAULT_ORG_TEMPLATE,
|
|
10987
11575
|
country: validated.value.country
|
|
10988
11576
|
});
|
|
10989
|
-
if (!
|
|
10990
|
-
|
|
10991
|
-
|
|
10992
|
-
|
|
11577
|
+
if (!started.ok) return fail(started.error);
|
|
11578
|
+
const lifecycle = await advanceOrganizationSetup(setup, started.value.orgId, started.value.lifecycle, options?.signal);
|
|
11579
|
+
if (!lifecycle.ok) {
|
|
11580
|
+
const error = lifecycle.error;
|
|
11581
|
+
return fail(new CapxulError(error.code, error.message, {
|
|
11582
|
+
cause: error.cause,
|
|
11583
|
+
details: {
|
|
11584
|
+
...error.details,
|
|
11585
|
+
orgId: started.value.orgId
|
|
11586
|
+
},
|
|
11587
|
+
...error.correlationId === void 0 ? {} : { correlationId: error.correlationId },
|
|
11588
|
+
...error.layer === void 0 ? {} : { layer: error.layer }
|
|
11589
|
+
}));
|
|
11590
|
+
}
|
|
10993
11591
|
return {
|
|
10994
11592
|
ok: true,
|
|
10995
11593
|
value: {
|
|
10996
|
-
|
|
11594
|
+
orgId: started.value.orgId,
|
|
10997
11595
|
lifecycle: lifecycle.value
|
|
10998
11596
|
}
|
|
10999
11597
|
};
|
|
@@ -11084,8 +11682,7 @@ function fail(error) {
|
|
|
11084
11682
|
* Onboarding method surface. The thin namespace over the `flows/onboarding.ts`
|
|
11085
11683
|
* choreography: it adds the `signal`-abort pre-check and delegates to the run
|
|
11086
11684
|
* functions. The `OnboardingOps` seam is supplied by `assembleCapxulClient`
|
|
11087
|
-
* (real ops
|
|
11088
|
-
* (in-memory double).
|
|
11685
|
+
* (real identity/Account ops plus Organization setup capability) or by tests.
|
|
11089
11686
|
*/
|
|
11090
11687
|
function makeOnboardingMethods(ops) {
|
|
11091
11688
|
return {
|
|
@@ -11101,7 +11698,7 @@ function makeOnboardingMethods(ops) {
|
|
|
11101
11698
|
ok: false,
|
|
11102
11699
|
error: Errors.cancelled({ operation: "onboarding.completeOrganization" })
|
|
11103
11700
|
});
|
|
11104
|
-
return runCompleteOrganizationOnboarding(ops, input);
|
|
11701
|
+
return runCompleteOrganizationOnboarding(ops, input, options);
|
|
11105
11702
|
}
|
|
11106
11703
|
};
|
|
11107
11704
|
}
|
|
@@ -11222,6 +11819,7 @@ function detectAuthCacheAdapter() {
|
|
|
11222
11819
|
}
|
|
11223
11820
|
//#endregion
|
|
11224
11821
|
//#region ../../packages/sdk/src/client/create-capxul-client.ts
|
|
11822
|
+
const GET_ORGANIZATION_SETUP_PROOF_RECEIPT = makeFunctionReference("org/lifecycle:getProofReceipt");
|
|
11225
11823
|
function assembleCapxulClient(input) {
|
|
11226
11824
|
const authCache = input.authCache ?? detectAuthCacheAdapter();
|
|
11227
11825
|
const layer = Layer.mergeAll(Layer.succeed(AuthClientPortTag, input.ports.authClient), Layer.succeed(ClockPortTag, input.ports.clock), Layer.succeed(TelemetryPortTag, input.ports.telemetry));
|
|
@@ -11288,7 +11886,8 @@ function assembleCapxulClient(input) {
|
|
|
11288
11886
|
...selectedOrgPort === void 0 ? {} : { orgPort: selectedOrgPort },
|
|
11289
11887
|
...input.orgRolesDeploymentPort === void 0 ? {} : { orgRolesDeploymentPort: input.orgRolesDeploymentPort },
|
|
11290
11888
|
...input.orgSpendPort === void 0 ? {} : { orgSpendPort: input.orgSpendPort },
|
|
11291
|
-
convexCall: input.ports.convexCall
|
|
11889
|
+
convexCall: input.ports.convexCall,
|
|
11890
|
+
...input.organizationSetup === void 0 ? {} : { organizationSetup: input.organizationSetup }
|
|
11292
11891
|
});
|
|
11293
11892
|
if (selectedOrgPort !== void 0) detectPendingOrgInvitations = async () => {
|
|
11294
11893
|
await orgMethods.orgs.detectAndAcceptPendingInvitations();
|
|
@@ -11311,7 +11910,7 @@ function assembleCapxulClient(input) {
|
|
|
11311
11910
|
triggerProvisioning: () => account._internal.provision(),
|
|
11312
11911
|
kickProvisioning: () => kickProvisioning?.(),
|
|
11313
11912
|
readLifecycle: () => account.getLifecycle(),
|
|
11314
|
-
|
|
11913
|
+
...input.organizationSetup === void 0 ? {} : { organizationSetup: input.organizationSetup }
|
|
11315
11914
|
});
|
|
11316
11915
|
return {
|
|
11317
11916
|
auth,
|
|
@@ -11344,6 +11943,7 @@ function assembleCapxulClient(input) {
|
|
|
11344
11943
|
},
|
|
11345
11944
|
bootstrap: input.bootstrap,
|
|
11346
11945
|
accounts: { fund: accounts.fund },
|
|
11946
|
+
organizationSetup: { getProofReceipt: (orgId) => runPortEffect(input.ports.convexCall.query(GET_ORGANIZATION_SETUP_PROOF_RECEIPT, { orgId })) },
|
|
11347
11947
|
telemetry: input.ports.telemetry
|
|
11348
11948
|
}
|
|
11349
11949
|
};
|
|
@@ -11351,6 +11951,34 @@ function assembleCapxulClient(input) {
|
|
|
11351
11951
|
//#endregion
|
|
11352
11952
|
//#region ../../packages/sdk/src/observation.ts
|
|
11353
11953
|
const SDK_VERSION$1 = version;
|
|
11954
|
+
/**
|
|
11955
|
+
* Fan one SDK failure out to several adapters (issue #877). The SDK's own
|
|
11956
|
+
* first-party relay and an optional host-provided adapter both observe the same
|
|
11957
|
+
* failure. Order matters for `resolveContext`: the FIRST adapter that returns a
|
|
11958
|
+
* context wins, so pass the host adapter first to keep its call-start snapshot.
|
|
11959
|
+
* Each capture is isolated — a throwing adapter never blocks its peers or the
|
|
11960
|
+
* SDK. Returns `undefined` when no adapters are present (zero observation work).
|
|
11961
|
+
*/
|
|
11962
|
+
function composeObservationAdapters(...adapters) {
|
|
11963
|
+
const present = adapters.filter((adapter) => adapter !== void 0);
|
|
11964
|
+
if (present.length === 0) return void 0;
|
|
11965
|
+
if (present.length === 1) return present[0];
|
|
11966
|
+
const fanOut = (select) => {
|
|
11967
|
+
for (const adapter of present) try {
|
|
11968
|
+
ignoreDeliveryFailure(select(adapter));
|
|
11969
|
+
} catch {}
|
|
11970
|
+
};
|
|
11971
|
+
return {
|
|
11972
|
+
resolveContext: () => {
|
|
11973
|
+
for (const adapter of present) try {
|
|
11974
|
+
const context = adapter.resolveContext?.();
|
|
11975
|
+
if (context !== void 0) return context;
|
|
11976
|
+
} catch {}
|
|
11977
|
+
},
|
|
11978
|
+
captureOperationFailure: (failure) => fanOut((adapter) => adapter.captureOperationFailure(failure)),
|
|
11979
|
+
captureException: (failure) => fanOut((adapter) => adapter.captureException(failure))
|
|
11980
|
+
};
|
|
11981
|
+
}
|
|
11354
11982
|
/** @internal Decorates public client method bundles at the owning SDK boundary. */
|
|
11355
11983
|
function observeSdkClient(client, adapter) {
|
|
11356
11984
|
if (adapter === void 0) return client;
|
|
@@ -11454,7 +12082,7 @@ function report(adapter, kind, operation, cause, invocationContext) {
|
|
|
11454
12082
|
}
|
|
11455
12083
|
function resolveAdapterContext(adapter) {
|
|
11456
12084
|
try {
|
|
11457
|
-
return
|
|
12085
|
+
return adapter.resolveContext?.();
|
|
11458
12086
|
} catch {
|
|
11459
12087
|
return;
|
|
11460
12088
|
}
|
|
@@ -11500,6 +12128,43 @@ function isCapxulResult(value) {
|
|
|
11500
12128
|
function isFailedResult(value) {
|
|
11501
12129
|
return isCapxulResult(value) && value.ok === false && "error" in value;
|
|
11502
12130
|
}
|
|
12131
|
+
//#endregion
|
|
12132
|
+
//#region ../../packages/sdk/src/observation-relay.ts
|
|
12133
|
+
/**
|
|
12134
|
+
* Build the SDK-owned first-party relay adapter. Both capture entry points send
|
|
12135
|
+
* the same redacted envelope fire-and-forget; delivery is fully isolated from
|
|
12136
|
+
* the SDK's `CapxulResult` and can never throw into the caller.
|
|
12137
|
+
*/
|
|
12138
|
+
function createCapxulFirstPartyRelay(options) {
|
|
12139
|
+
const fetchImpl = options.fetch ?? resolveGlobalFetch();
|
|
12140
|
+
const send = (failure) => {
|
|
12141
|
+
if (fetchImpl === void 0) return;
|
|
12142
|
+
try {
|
|
12143
|
+
const headers = { "content-type": "application/json" };
|
|
12144
|
+
const encodedContext = encodeObservationContextHeader(failure.context);
|
|
12145
|
+
if (encodedContext !== void 0) headers[OBSERVATION_CONTEXT_HEADER] = encodedContext;
|
|
12146
|
+
const body = JSON.stringify({
|
|
12147
|
+
operation: failure.operation,
|
|
12148
|
+
error_kind: failure.errorKind,
|
|
12149
|
+
sdk_version: failure.sdkVersion
|
|
12150
|
+
});
|
|
12151
|
+
Promise.resolve(fetchImpl(options.ingestUrl, {
|
|
12152
|
+
method: "POST",
|
|
12153
|
+
headers,
|
|
12154
|
+
body,
|
|
12155
|
+
keepalive: true
|
|
12156
|
+
})).catch(() => void 0);
|
|
12157
|
+
} catch {}
|
|
12158
|
+
};
|
|
12159
|
+
return {
|
|
12160
|
+
captureOperationFailure: send,
|
|
12161
|
+
captureException: send
|
|
12162
|
+
};
|
|
12163
|
+
}
|
|
12164
|
+
function resolveGlobalFetch() {
|
|
12165
|
+
const candidate = globalThis.fetch;
|
|
12166
|
+
return typeof candidate === "function" ? candidate : void 0;
|
|
12167
|
+
}
|
|
11503
12168
|
const SDK_VERSION = version;
|
|
11504
12169
|
const collectProductionFlowPorts = Effect.gen(function* () {
|
|
11505
12170
|
const authClient = yield* AuthClientPortTag;
|
|
@@ -11787,7 +12452,7 @@ async function createCapxulClient(input) {
|
|
|
11787
12452
|
...input.authBaseUrl === void 0 ? {} : { override: input.authBaseUrl }
|
|
11788
12453
|
});
|
|
11789
12454
|
let signer = input.signer;
|
|
11790
|
-
if (signer === void 0 &&
|
|
12455
|
+
if (signer === void 0 && runtime === "browser") signer = createOpenfortBrowserSignerFromBootstrap({
|
|
11791
12456
|
...adapters.value.bootstrap,
|
|
11792
12457
|
authBaseUrl: resolvedAuthBaseUrl
|
|
11793
12458
|
});
|
|
@@ -11797,23 +12462,33 @@ async function createCapxulClient(input) {
|
|
|
11797
12462
|
authCache: adapters.value.ports.authCache,
|
|
11798
12463
|
requirement: input.requirement ?? "none",
|
|
11799
12464
|
...signer === void 0 ? {} : { signer },
|
|
12465
|
+
orgPort: new ConvexOrganizationAdapter({ convex: adapters.value.ports.convexCall }),
|
|
12466
|
+
...signer === void 0 ? {} : { organizationSetup: new ConvexOrganizationSetupAdapter({
|
|
12467
|
+
convex: adapters.value.ports.convexCall,
|
|
12468
|
+
signer
|
|
12469
|
+
}) },
|
|
11800
12470
|
...input.signal === void 0 ? {} : { signal: input.signal },
|
|
11801
12471
|
...input.otpTtlMs === void 0 ? {} : { otpTtlMs: input.otpTtlMs },
|
|
11802
12472
|
invokeTimeoutMs: input.invokeTimeoutMs ?? 3e4
|
|
11803
12473
|
}), signer);
|
|
11804
12474
|
const upstreamClose = adapters.value.close;
|
|
12475
|
+
const value = {
|
|
12476
|
+
...client,
|
|
12477
|
+
_internal: {
|
|
12478
|
+
...client._internal,
|
|
12479
|
+
close: async () => {
|
|
12480
|
+
if ("resetSession" in (signer ?? {})) signer.resetSession();
|
|
12481
|
+
await upstreamClose();
|
|
12482
|
+
}
|
|
12483
|
+
}
|
|
12484
|
+
};
|
|
12485
|
+
const relay = runtime === "browser" ? createCapxulFirstPartyRelay({
|
|
12486
|
+
ingestUrl: deriveObserveIngestUrl(adapters.value.bootstrap),
|
|
12487
|
+
...input.fetch === void 0 ? {} : { fetch: input.fetch }
|
|
12488
|
+
}) : void 0;
|
|
11805
12489
|
return {
|
|
11806
12490
|
ok: true,
|
|
11807
|
-
value: observeSdkClient(
|
|
11808
|
-
...client,
|
|
11809
|
-
_internal: {
|
|
11810
|
-
...client._internal,
|
|
11811
|
-
close: async () => {
|
|
11812
|
-
if ("resetSession" in (signer ?? {})) signer.resetSession();
|
|
11813
|
-
await upstreamClose();
|
|
11814
|
-
}
|
|
11815
|
-
}
|
|
11816
|
-
}, input.observation)
|
|
12491
|
+
value: observeSdkClient(value, composeObservationAdapters(input.observation, relay))
|
|
11817
12492
|
};
|
|
11818
12493
|
} catch (cause) {
|
|
11819
12494
|
await adapters.value.close().catch(() => void 0);
|
|
@@ -11855,6 +12530,38 @@ function resolveInput(input) {
|
|
|
11855
12530
|
};
|
|
11856
12531
|
}
|
|
11857
12532
|
}
|
|
12533
|
+
/**
|
|
12534
|
+
* Address of the Capxul client-relay ingest endpoint (Pipe 1, issue #877). The
|
|
12535
|
+
* HTTP router that serves `/v1/client/observe` lives on the deployment's
|
|
12536
|
+
* `.convex.site` host, while the bootstrap-resolved `convexUrl` is the sibling
|
|
12537
|
+
* `.convex.cloud` (WebSocket/query) host — the same deterministic pairing
|
|
12538
|
+
* `mintQuickstartKey` inverts. For any standard Convex deployment (including
|
|
12539
|
+
* production) rewriting the suffix targets the router directly with no host
|
|
12540
|
+
* proxy, so it is the primary rule.
|
|
12541
|
+
*
|
|
12542
|
+
* `siteBaseUrl` is deliberately NOT the primary source: it is an app-configured
|
|
12543
|
+
* field that defaults to a placeholder (`https://capxul.local`, see
|
|
12544
|
+
* `credentials/applications.ts`) for registered applications, so trusting it
|
|
12545
|
+
* outright would POST to a dead host for the common case. It is only consulted
|
|
12546
|
+
* as a fallback for a custom-domain `convexUrl` (no deterministic `.convex.site`
|
|
12547
|
+
* sibling) when it carries a real, non-placeholder origin.
|
|
12548
|
+
*/
|
|
12549
|
+
function deriveObserveIngestUrl(bootstrap) {
|
|
12550
|
+
const convexUrl = bootstrap.convexUrl.replace(/\/+$/, "");
|
|
12551
|
+
if (convexUrl.endsWith(".convex.cloud")) return `${convexUrl.replace(/\.convex\.cloud$/, ".convex.site")}/v1/client/observe`;
|
|
12552
|
+
return `${(usableSiteOrigin(bootstrap.siteBaseUrl) ?? convexUrl).replace(/\/+$/, "")}/v1/client/observe`;
|
|
12553
|
+
}
|
|
12554
|
+
/** A configured `siteBaseUrl` usable as a router host, or `undefined` if it is the placeholder. */
|
|
12555
|
+
function usableSiteOrigin(siteBaseUrl) {
|
|
12556
|
+
try {
|
|
12557
|
+
const url = new URL(siteBaseUrl);
|
|
12558
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") return void 0;
|
|
12559
|
+
if (url.hostname === "capxul.local") return void 0;
|
|
12560
|
+
return url.origin;
|
|
12561
|
+
} catch {
|
|
12562
|
+
return;
|
|
12563
|
+
}
|
|
12564
|
+
}
|
|
11858
12565
|
function detectRuntime() {
|
|
11859
12566
|
const globalAny = globalThis;
|
|
11860
12567
|
return globalAny.window !== void 0 || globalAny.document !== void 0 ? "browser" : "node";
|
|
@@ -12463,7 +13170,7 @@ async function signUserOperation(parameters) {
|
|
|
12463
13170
|
}
|
|
12464
13171
|
//#endregion
|
|
12465
13172
|
//#region ../../node_modules/.pnpm/permissionless@0.3.4_viem@2.53.1_typescript@5.9.2_zod@4.4.3_/node_modules/permissionless/_esm/accounts/safe/toSafeSmartAccount.js
|
|
12466
|
-
const multiSendAbi
|
|
13173
|
+
const multiSendAbi = [{
|
|
12467
13174
|
inputs: [{
|
|
12468
13175
|
internalType: "bytes",
|
|
12469
13176
|
name: "transactions",
|
|
@@ -12947,7 +13654,7 @@ const encodeInternalTransaction = (tx) => {
|
|
|
12947
13654
|
};
|
|
12948
13655
|
const encodeMultiSend = (txs) => {
|
|
12949
13656
|
return encodeFunctionData({
|
|
12950
|
-
abi: multiSendAbi
|
|
13657
|
+
abi: multiSendAbi,
|
|
12951
13658
|
functionName: "multiSend",
|
|
12952
13659
|
args: [`0x${txs.map((tx) => encodeInternalTransaction(tx)).join("")}`]
|
|
12953
13660
|
});
|
|
@@ -13472,7 +14179,7 @@ async function toSafeSmartAccount(parameters) {
|
|
|
13472
14179
|
const data = decoded.args[2];
|
|
13473
14180
|
if (to === multiSendCallOnlyAddress) {
|
|
13474
14181
|
const dataToDecode = decodeFunctionData({
|
|
13475
|
-
abi: multiSendAbi
|
|
14182
|
+
abi: multiSendAbi,
|
|
13476
14183
|
data
|
|
13477
14184
|
}).args[0];
|
|
13478
14185
|
const transactions = [];
|
|
@@ -13661,123 +14368,6 @@ async function toSafeSmartAccount(parameters) {
|
|
|
13661
14368
|
}
|
|
13662
14369
|
});
|
|
13663
14370
|
}
|
|
13664
|
-
//#endregion
|
|
13665
|
-
//#region ../../packages/sdk/src/ports/org.ts
|
|
13666
|
-
var OrgError = class extends Data.TaggedError("OrgError") {};
|
|
13667
|
-
function orgErrorFromCapxul(operation, error, cause = error) {
|
|
13668
|
-
return new OrgError({
|
|
13669
|
-
operation,
|
|
13670
|
-
publicCode: error.code,
|
|
13671
|
-
publicError: error,
|
|
13672
|
-
cause,
|
|
13673
|
-
...error.details === void 0 ? {} : { details: error.details }
|
|
13674
|
-
});
|
|
13675
|
-
}
|
|
13676
|
-
Context.Tag("@capxul/sdk/ports/OrgPort")();
|
|
13677
|
-
Context.Tag("@capxul/sdk/ports/OrgRolesDeploymentPort")();
|
|
13678
|
-
Context.Tag("@capxul/sdk/ports/OrgSpendPort")();
|
|
13679
|
-
//#endregion
|
|
13680
|
-
//#region ../../packages/sdk/src/adapters/org/parse.ts
|
|
13681
|
-
/**
|
|
13682
|
-
* Map a `WireOrg` + its (separately read) treasury `Account` into the branded
|
|
13683
|
-
* `OrgView`. The founder is the creator → `Owner` role within their own org
|
|
13684
|
-
* (D6/D7). Brands at the read edge: `orgId`, `safeAddress`.
|
|
13685
|
-
*/
|
|
13686
|
-
function brandOrgView(wire, treasury) {
|
|
13687
|
-
return {
|
|
13688
|
-
id: toOrgId(wire.orgId),
|
|
13689
|
-
name: wire.name,
|
|
13690
|
-
handle: wire.slug,
|
|
13691
|
-
safeAddress: toAddress(wire.safeAddress.toLowerCase()),
|
|
13692
|
-
role: "Owner",
|
|
13693
|
-
treasury
|
|
13694
|
-
};
|
|
13695
|
-
}
|
|
13696
|
-
/**
|
|
13697
|
-
* Build the Org treasury `Account` from the raw on-chain `balanceOf` integer
|
|
13698
|
-
* (the D3 RPC read). `available === balance` for a treasury with no envelope
|
|
13699
|
-
* partition yet (a fresh Org reads back $0).
|
|
13700
|
-
*/
|
|
13701
|
-
function brandOrgTreasury(input) {
|
|
13702
|
-
return {
|
|
13703
|
-
id: toAccountId(`account_${orgIdBody(input.orgId)}`),
|
|
13704
|
-
balance: input.money,
|
|
13705
|
-
available: input.money
|
|
13706
|
-
};
|
|
13707
|
-
}
|
|
13708
|
-
function brandOrgRole(wire) {
|
|
13709
|
-
return {
|
|
13710
|
-
orgId: toOrgId(wire.orgId),
|
|
13711
|
-
label: wire.label,
|
|
13712
|
-
roleKey: toRoleKey(wire.roleKey),
|
|
13713
|
-
definition: parseRoleDefinition(wire.definitionJson)
|
|
13714
|
-
};
|
|
13715
|
-
}
|
|
13716
|
-
function brandOrgMember(wire) {
|
|
13717
|
-
return {
|
|
13718
|
-
orgId: toOrgId(wire.orgId),
|
|
13719
|
-
email: toEmail(wire.email),
|
|
13720
|
-
name: wire.name,
|
|
13721
|
-
personalSafeAddress: wire.personalSafeAddress === null ? null : toAddress(wire.personalSafeAddress),
|
|
13722
|
-
role: wire.role,
|
|
13723
|
-
roleKey: wire.roleKey === null ? null : toRoleKey(wire.roleKey),
|
|
13724
|
-
status: wire.status,
|
|
13725
|
-
grantTxHash: wire.grantTxHash,
|
|
13726
|
-
revokeTxHash: wire.revokeTxHash
|
|
13727
|
-
};
|
|
13728
|
-
}
|
|
13729
|
-
function parseRoleDefinition(json) {
|
|
13730
|
-
let raw;
|
|
13731
|
-
try {
|
|
13732
|
-
const parsed = JSON.parse(json);
|
|
13733
|
-
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) throw new Error("expected object");
|
|
13734
|
-
raw = parsed;
|
|
13735
|
-
} catch (err) {
|
|
13736
|
-
throw new Error(`Invalid role definition: malformed JSON - ${err instanceof Error ? err.message : String(err)}`);
|
|
13737
|
-
}
|
|
13738
|
-
if (typeof raw.label !== "string" || raw.label.trim().length === 0) throw new Error("Invalid role definition: missing label");
|
|
13739
|
-
return {
|
|
13740
|
-
label: raw.label,
|
|
13741
|
-
...raw.spend === void 0 ? {} : { spend: {
|
|
13742
|
-
...raw.spend.perTx === void 0 ? {} : { perTx: parseRoleMoney(raw.spend.perTx, "perTx") },
|
|
13743
|
-
...raw.spend.perDay === void 0 ? {} : { perDay: parseRoleMoney(raw.spend.perDay, "perDay") },
|
|
13744
|
-
...raw.spend.toRecipients === void 0 ? {} : { toRecipients: parseRoleRecipients(raw.spend.toRecipients) }
|
|
13745
|
-
} },
|
|
13746
|
-
...raw.subAccounts === void 0 ? {} : { subAccounts: parseRoleSubAccounts(raw.subAccounts) },
|
|
13747
|
-
...typeof raw.canManageMembers === "boolean" ? { canManageMembers: raw.canManageMembers } : {},
|
|
13748
|
-
...typeof raw.canManageRoles === "boolean" ? { canManageRoles: raw.canManageRoles } : {}
|
|
13749
|
-
};
|
|
13750
|
-
}
|
|
13751
|
-
function parseRoleMoney(raw, field) {
|
|
13752
|
-
if (typeof raw.currency !== "string" || typeof raw.value !== "string" || !/^\d+$/.test(raw.value) || raw.decimals !== 6) throw new Error(`Invalid role money: ${field}`);
|
|
13753
|
-
return {
|
|
13754
|
-
currency: toCurrencyCode(raw.currency),
|
|
13755
|
-
value: raw.value,
|
|
13756
|
-
decimals: raw.decimals
|
|
13757
|
-
};
|
|
13758
|
-
}
|
|
13759
|
-
function parseRoleRecipients(raw) {
|
|
13760
|
-
if (raw === "anyone") return "anyone";
|
|
13761
|
-
if (!Array.isArray(raw)) throw new Error("Invalid role definition: toRecipients must be \"anyone\" or an array");
|
|
13762
|
-
return raw.map((recipient) => {
|
|
13763
|
-
if (typeof recipient !== "string") throw new Error("Invalid role definition: toRecipients must be \"anyone\" or an array");
|
|
13764
|
-
return toAddress(recipient);
|
|
13765
|
-
});
|
|
13766
|
-
}
|
|
13767
|
-
function parseRoleSubAccounts(raw) {
|
|
13768
|
-
if (raw.scope === "all") return { scope: "all" };
|
|
13769
|
-
if (!Array.isArray(raw.scope)) throw new Error("Invalid role definition: subAccounts.scope must be \"all\" or an array");
|
|
13770
|
-
return { scope: raw.scope.map((subAccountId) => {
|
|
13771
|
-
if (typeof subAccountId !== "string") throw new Error("Invalid role definition: subAccounts.scope must be \"all\" or an array");
|
|
13772
|
-
return toSubAccountId(subAccountId);
|
|
13773
|
-
}) };
|
|
13774
|
-
}
|
|
13775
|
-
/** Strip the `org_` prefix + non-alphanumerics so the body re-seeds `account_`. */
|
|
13776
|
-
function orgIdBody(orgId) {
|
|
13777
|
-
const underscore = orgId.indexOf("_");
|
|
13778
|
-
const cleaned = (underscore < 0 ? orgId : orgId.slice(underscore + 1)).replace(/[^0-9A-Za-z]/g, "");
|
|
13779
|
-
return cleaned.length > 0 ? cleaned : "0";
|
|
13780
|
-
}
|
|
13781
14371
|
toDurationMs(12e4);
|
|
13782
14372
|
/** The viem `entryPoint` v0.7 descriptor shared by every live deploy. */
|
|
13783
14373
|
const ENTRY_POINT_07 = {
|
|
@@ -13840,8 +14430,8 @@ const orgListMembersByOrgIdQuery = makeFunctionReference("org/queries:listMember
|
|
|
13840
14430
|
//#endregion
|
|
13841
14431
|
//#region ../../packages/sdk/src/__e2e__/live-org-deployment.ts
|
|
13842
14432
|
/**
|
|
13843
|
-
* E2E ONLY: live Base Sepolia Org Safe deploy adapter (
|
|
13844
|
-
* `
|
|
14433
|
+
* E2E ONLY: live Base Sepolia Org Safe deploy adapter (see
|
|
14434
|
+
* `packages/sdk/CONTEXT.md`). Implements the
|
|
13845
14435
|
* SDK-side `OrgPort` for the S1 capstone. Do not import from production SDK
|
|
13846
14436
|
* code — it reads deploy env (`DEPLOYER_PRIVATE_KEY`, `BASE_SEPOLIA_RPC_URL`)
|
|
13847
14437
|
* and sends real on-chain transactions.
|
|
@@ -13904,67 +14494,6 @@ const erc20BalanceOfAbi = [{
|
|
|
13904
14494
|
type: "uint256"
|
|
13905
14495
|
}]
|
|
13906
14496
|
}];
|
|
13907
|
-
const safeExecTransactionAbi = [{
|
|
13908
|
-
type: "function",
|
|
13909
|
-
name: "execTransaction",
|
|
13910
|
-
stateMutability: "payable",
|
|
13911
|
-
inputs: [
|
|
13912
|
-
{
|
|
13913
|
-
name: "to",
|
|
13914
|
-
type: "address"
|
|
13915
|
-
},
|
|
13916
|
-
{
|
|
13917
|
-
name: "value",
|
|
13918
|
-
type: "uint256"
|
|
13919
|
-
},
|
|
13920
|
-
{
|
|
13921
|
-
name: "data",
|
|
13922
|
-
type: "bytes"
|
|
13923
|
-
},
|
|
13924
|
-
{
|
|
13925
|
-
name: "operation",
|
|
13926
|
-
type: "uint8"
|
|
13927
|
-
},
|
|
13928
|
-
{
|
|
13929
|
-
name: "safeTxGas",
|
|
13930
|
-
type: "uint256"
|
|
13931
|
-
},
|
|
13932
|
-
{
|
|
13933
|
-
name: "baseGas",
|
|
13934
|
-
type: "uint256"
|
|
13935
|
-
},
|
|
13936
|
-
{
|
|
13937
|
-
name: "gasPrice",
|
|
13938
|
-
type: "uint256"
|
|
13939
|
-
},
|
|
13940
|
-
{
|
|
13941
|
-
name: "gasToken",
|
|
13942
|
-
type: "address"
|
|
13943
|
-
},
|
|
13944
|
-
{
|
|
13945
|
-
name: "refundReceiver",
|
|
13946
|
-
type: "address"
|
|
13947
|
-
},
|
|
13948
|
-
{
|
|
13949
|
-
name: "signatures",
|
|
13950
|
-
type: "bytes"
|
|
13951
|
-
}
|
|
13952
|
-
],
|
|
13953
|
-
outputs: [{
|
|
13954
|
-
name: "success",
|
|
13955
|
-
type: "bool"
|
|
13956
|
-
}]
|
|
13957
|
-
}];
|
|
13958
|
-
const multiSendAbi = [{
|
|
13959
|
-
type: "function",
|
|
13960
|
-
name: "multiSend",
|
|
13961
|
-
stateMutability: "payable",
|
|
13962
|
-
inputs: [{
|
|
13963
|
-
name: "transactions",
|
|
13964
|
-
type: "bytes"
|
|
13965
|
-
}],
|
|
13966
|
-
outputs: []
|
|
13967
|
-
}];
|
|
13968
14497
|
const rolesExecTransactionWithRoleVerificationAbi = [{
|
|
13969
14498
|
type: "function",
|
|
13970
14499
|
name: "execTransactionWithRole",
|
|
@@ -14005,9 +14534,7 @@ const rolesExecTransactionWithRoleVerificationAbi = [{
|
|
|
14005
14534
|
inputs: []
|
|
14006
14535
|
}];
|
|
14007
14536
|
const DEFAULT_RECEIPT_TIMEOUT_MS = 12e4;
|
|
14008
|
-
const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
14009
14537
|
const SAFE_OPERATION_CALL = 0;
|
|
14010
|
-
const SAFE_OPERATION_DELEGATECALL = 1;
|
|
14011
14538
|
const ASSIGN_ROLES_PERMISSION = "zodiac.roles.assignRoles";
|
|
14012
14539
|
var LiveOrgDeploymentAdapter = class {
|
|
14013
14540
|
#convex;
|
|
@@ -14188,7 +14715,7 @@ var LiveOrgDeploymentAdapter = class {
|
|
|
14188
14715
|
});
|
|
14189
14716
|
const [deployModuleCall, ...orgSafeCalls] = deployment.calls;
|
|
14190
14717
|
if (deployModuleCall === void 0) throw Errors.providerError("permissionless-org-roles-deployment", "deployRoles", "Zodiac Roles deployment builder returned no calls");
|
|
14191
|
-
const calls = [deployModuleCall,
|
|
14718
|
+
const calls = [deployModuleCall, buildSafeMultiSendExecTransactionCall({
|
|
14192
14719
|
safeAddress: toViemHexAddress(wire.safeAddress),
|
|
14193
14720
|
ownerAddress: toViemHexAddress(wire.ownerPersonalSafeAddress),
|
|
14194
14721
|
calls: orgSafeCalls
|
|
@@ -14382,7 +14909,7 @@ async function isContractDeployed(publicClient, address) {
|
|
|
14382
14909
|
return code !== void 0 && code !== "0x";
|
|
14383
14910
|
}
|
|
14384
14911
|
function wireToOrgView(wire, treasury) {
|
|
14385
|
-
return brandOrgView(wire, treasury);
|
|
14912
|
+
return brandOrgView(wire, treasury, "Owner");
|
|
14386
14913
|
}
|
|
14387
14914
|
function deriveLiveSpendAuthority(input) {
|
|
14388
14915
|
if (input.org === null) return inactiveSpendAuthority();
|
|
@@ -14411,9 +14938,9 @@ function spendAuthorityFromRole(role, roleLabel) {
|
|
|
14411
14938
|
activeMember: true,
|
|
14412
14939
|
subAccountBalanceRaw: "100000000000",
|
|
14413
14940
|
recipients: spend?.toRecipients ?? "anyone",
|
|
14414
|
-
subAccounts: subAccountScope ===
|
|
14941
|
+
subAccounts: subAccountScope === "all" ? { scope: "all" } : {
|
|
14415
14942
|
scope: "only",
|
|
14416
|
-
subAccountIds: subAccountScope
|
|
14943
|
+
subAccountIds: subAccountScope?.map(toSubAccountId) ?? []
|
|
14417
14944
|
},
|
|
14418
14945
|
...spend?.perTx === void 0 ? {} : { perTxCapRaw: spend.perTx.value },
|
|
14419
14946
|
...spend?.perDay === void 0 ? {} : { perDayCapRaw: spend.perDay.value },
|
|
@@ -14457,51 +14984,6 @@ async function verifyOrgRoleRevokedOnChain(input) {
|
|
|
14457
14984
|
}
|
|
14458
14985
|
throw Errors.providerError("permissionless-org-roles", "verifyRevoke", "revoked member can still execute its former Zodiac role");
|
|
14459
14986
|
}
|
|
14460
|
-
function buildOrgSafeExecTransactionCall(input) {
|
|
14461
|
-
const data = encodeFunctionData({
|
|
14462
|
-
abi: multiSendAbi,
|
|
14463
|
-
functionName: "multiSend",
|
|
14464
|
-
args: [concat(input.calls.map(encodeMultiSendCallTransaction))]
|
|
14465
|
-
});
|
|
14466
|
-
return {
|
|
14467
|
-
to: input.safeAddress,
|
|
14468
|
-
data: encodeFunctionData({
|
|
14469
|
-
abi: safeExecTransactionAbi,
|
|
14470
|
-
functionName: "execTransaction",
|
|
14471
|
-
args: [
|
|
14472
|
-
MULTI_SEND,
|
|
14473
|
-
0n,
|
|
14474
|
-
data,
|
|
14475
|
-
SAFE_OPERATION_DELEGATECALL,
|
|
14476
|
-
0n,
|
|
14477
|
-
0n,
|
|
14478
|
-
0n,
|
|
14479
|
-
ZERO_ADDRESS,
|
|
14480
|
-
ZERO_ADDRESS,
|
|
14481
|
-
prevalidatedSafeSignature(input.ownerAddress)
|
|
14482
|
-
]
|
|
14483
|
-
}),
|
|
14484
|
-
value: 0n
|
|
14485
|
-
};
|
|
14486
|
-
}
|
|
14487
|
-
function encodeMultiSendCallTransaction(call) {
|
|
14488
|
-
return encodePacked([
|
|
14489
|
-
"uint8",
|
|
14490
|
-
"address",
|
|
14491
|
-
"uint256",
|
|
14492
|
-
"uint256",
|
|
14493
|
-
"bytes"
|
|
14494
|
-
], [
|
|
14495
|
-
SAFE_OPERATION_CALL,
|
|
14496
|
-
call.to,
|
|
14497
|
-
call.value,
|
|
14498
|
-
BigInt((call.data.length - 2) / 2),
|
|
14499
|
-
call.data
|
|
14500
|
-
]);
|
|
14501
|
-
}
|
|
14502
|
-
function prevalidatedSafeSignature(ownerAddress) {
|
|
14503
|
-
return `${padHex(ownerAddress, { size: 32 })}${"0".repeat(64)}01`;
|
|
14504
|
-
}
|
|
14505
14987
|
function requireActiveRole(roles, label) {
|
|
14506
14988
|
const role = roles.find((candidate) => candidate.status === "active" && candidate.label === label);
|
|
14507
14989
|
if (role === void 0) throw Errors.invalidInput("role", `active org role not found: ${label}`);
|
|
@@ -14770,28 +15252,36 @@ async function buildSponsoredSafeUserOp(input) {
|
|
|
14770
15252
|
};
|
|
14771
15253
|
return {
|
|
14772
15254
|
userOp,
|
|
14773
|
-
digest:
|
|
14774
|
-
userOp
|
|
14775
|
-
sender: userOp.sender,
|
|
14776
|
-
nonce,
|
|
14777
|
-
...userOp.factory === void 0 ? {} : { factory: userOp.factory },
|
|
14778
|
-
...userOp.factoryData === void 0 ? {} : { factoryData: userOp.factoryData },
|
|
14779
|
-
callData: userOp.callData,
|
|
14780
|
-
callGasLimit: rpcQuantityToBigInt(userOp.callGasLimit, "callGasLimit"),
|
|
14781
|
-
verificationGasLimit: rpcQuantityToBigInt(userOp.verificationGasLimit, "verificationGasLimit"),
|
|
14782
|
-
preVerificationGas: rpcQuantityToBigInt(userOp.preVerificationGas, "preVerificationGas"),
|
|
14783
|
-
maxFeePerGas: rpcQuantityToBigInt(userOp.maxFeePerGas, "maxFeePerGas"),
|
|
14784
|
-
maxPriorityFeePerGas: rpcQuantityToBigInt(userOp.maxPriorityFeePerGas, "maxPriorityFeePerGas"),
|
|
14785
|
-
paymaster: userOp.paymaster,
|
|
14786
|
-
...userOp.paymasterVerificationGasLimit === void 0 ? {} : { paymasterVerificationGasLimit: rpcQuantityToBigInt(userOp.paymasterVerificationGasLimit, "paymasterVerificationGasLimit") },
|
|
14787
|
-
...userOp.paymasterPostOpGasLimit === void 0 ? {} : { paymasterPostOpGasLimit: rpcQuantityToBigInt(userOp.paymasterPostOpGasLimit, "paymasterPostOpGasLimit") },
|
|
14788
|
-
paymasterData: userOp.paymasterData
|
|
14789
|
-
},
|
|
15255
|
+
digest: deploymentUserOpDigest({
|
|
15256
|
+
userOp,
|
|
14790
15257
|
chainId
|
|
14791
15258
|
}),
|
|
14792
15259
|
safeAddress: sender
|
|
14793
15260
|
};
|
|
14794
15261
|
}
|
|
15262
|
+
/** Recompute the SafeOp digest from the exact wire operation submitted by a client. */
|
|
15263
|
+
function deploymentUserOpDigest(input) {
|
|
15264
|
+
const { userOp, chainId } = input;
|
|
15265
|
+
return safe4337SafeOpDigest({
|
|
15266
|
+
userOp: {
|
|
15267
|
+
sender: userOp.sender,
|
|
15268
|
+
nonce: rpcQuantityToBigInt(userOp.nonce, "nonce"),
|
|
15269
|
+
...userOp.factory === void 0 ? {} : { factory: userOp.factory },
|
|
15270
|
+
...userOp.factoryData === void 0 ? {} : { factoryData: userOp.factoryData },
|
|
15271
|
+
callData: userOp.callData,
|
|
15272
|
+
callGasLimit: rpcQuantityToBigInt(userOp.callGasLimit, "callGasLimit"),
|
|
15273
|
+
verificationGasLimit: rpcQuantityToBigInt(userOp.verificationGasLimit, "verificationGasLimit"),
|
|
15274
|
+
preVerificationGas: rpcQuantityToBigInt(userOp.preVerificationGas, "preVerificationGas"),
|
|
15275
|
+
maxFeePerGas: rpcQuantityToBigInt(userOp.maxFeePerGas, "maxFeePerGas"),
|
|
15276
|
+
maxPriorityFeePerGas: rpcQuantityToBigInt(userOp.maxPriorityFeePerGas, "maxPriorityFeePerGas"),
|
|
15277
|
+
paymaster: userOp.paymaster,
|
|
15278
|
+
...userOp.paymasterVerificationGasLimit === void 0 ? {} : { paymasterVerificationGasLimit: rpcQuantityToBigInt(userOp.paymasterVerificationGasLimit, "paymasterVerificationGasLimit") },
|
|
15279
|
+
...userOp.paymasterPostOpGasLimit === void 0 ? {} : { paymasterPostOpGasLimit: rpcQuantityToBigInt(userOp.paymasterPostOpGasLimit, "paymasterPostOpGasLimit") },
|
|
15280
|
+
paymasterData: userOp.paymasterData
|
|
15281
|
+
},
|
|
15282
|
+
chainId
|
|
15283
|
+
});
|
|
15284
|
+
}
|
|
14795
15285
|
//#endregion
|
|
14796
15286
|
//#region src/settlement-port.ts
|
|
14797
15287
|
const ADDRESS_RE$1 = /^0x[0-9a-fA-F]{40}$/;
|
|
@@ -15507,8 +15997,8 @@ async function executeCommitmentRedirect(input) {
|
|
|
15507
15997
|
*/
|
|
15508
15998
|
async function fetchCommitmentCreatedIdFromLogs(input) {
|
|
15509
15999
|
const { keccak256, toBytes } = await import("viem");
|
|
15510
|
-
const { fetchCommitmentCreatedLog } = await import("./alchemy-rpc-
|
|
15511
|
-
const { CAPXUL_PAYMENTS_ADDRESS } = await import("./src-
|
|
16000
|
+
const { fetchCommitmentCreatedLog } = await import("./alchemy-rpc-BiJgkVvc.mjs");
|
|
16001
|
+
const { CAPXUL_PAYMENTS_ADDRESS } = await import("./src-CIqRZpwl.mjs");
|
|
15512
16002
|
const topic0 = keccak256(toBytes("CommitmentCreated(uint256,address,address,address,uint256,uint48,uint48,uint48,bytes32,uint8)"));
|
|
15513
16003
|
const idTopic = (await fetchCommitmentCreatedLog({
|
|
15514
16004
|
chainId: input.chainId,
|