@haven_ai/sdk 0.6.0-alpha.0 → 0.8.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -16
- package/dist/{base64-cD9kR4JL.d.cts → base64-znjJJQqu.d.cts} +457 -18
- package/dist/{base64-cD9kR4JL.d.ts → base64-znjJJQqu.d.ts} +457 -18
- package/dist/{chunk-63GPTEEY.js → chunk-H4APV67M.js} +90 -9
- package/dist/chunk-H4APV67M.js.map +1 -0
- package/dist/{chunk-S42QSWJY.cjs → chunk-HX34HOW4.cjs} +93 -8
- package/dist/chunk-HX34HOW4.cjs.map +1 -0
- package/dist/{chunk-3WSEX3GW.js → chunk-UXULZ3ZY.js} +186 -17
- package/dist/chunk-UXULZ3ZY.js.map +1 -0
- package/dist/{chunk-CK4NLLMO.cjs → chunk-WJFDXCYP.cjs} +223 -40
- package/dist/chunk-WJFDXCYP.cjs.map +1 -0
- package/dist/edge.cjs +317 -106
- package/dist/edge.cjs.map +1 -1
- package/dist/edge.d.cts +268 -2
- package/dist/edge.d.ts +268 -2
- package/dist/edge.js +196 -45
- package/dist/edge.js.map +1 -1
- package/dist/index.cjs +957 -391
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +181 -40
- package/dist/index.d.ts +181 -40
- package/dist/index.js +658 -113
- package/dist/index.js.map +1 -1
- package/dist/test-support.cjs +18 -18
- package/dist/test-support.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-3WSEX3GW.js.map +0 -1
- package/dist/chunk-63GPTEEY.js.map +0 -1
- package/dist/chunk-CK4NLLMO.cjs.map +0 -1
- package/dist/chunk-S42QSWJY.cjs.map +0 -1
|
@@ -26,6 +26,9 @@ function connectorRerunCommand(args, options) {
|
|
|
26
26
|
const command = `npx ${flags}${connectorSpec(channel)}`;
|
|
27
27
|
return args ? `${command} ${args}` : command;
|
|
28
28
|
}
|
|
29
|
+
function connectorUpgradeCommand(options) {
|
|
30
|
+
return connectorRerunCommand("--doctor", { channel: options?.channel, npxFlags: "-y" });
|
|
31
|
+
}
|
|
29
32
|
|
|
30
33
|
// src/types.ts
|
|
31
34
|
var DEFAULT_CONFIRMATION_TIMEOUT_MS = 9e4;
|
|
@@ -71,7 +74,21 @@ var AgentPaymentPhase = {
|
|
|
71
74
|
* agent should stop, tell the user, and wait for the sweep flow to reclaim
|
|
72
75
|
* the funds.
|
|
73
76
|
*/
|
|
74
|
-
FundedButUnsettled: "funded_but_unsettled"
|
|
77
|
+
FundedButUnsettled: "funded_but_unsettled",
|
|
78
|
+
/**
|
|
79
|
+
* #3420: TERMINAL — a `submitted` erc7710 x402 intent whose settlement
|
|
80
|
+
* window AND the sweep's last attribution chance have both passed with no
|
|
81
|
+
* verified evidence. The sweep's tick (120s) only ever confirms a
|
|
82
|
+
* transaction mined inside the payment's own settlement window (the child
|
|
83
|
+
* delegation's on-chain `timestamp` caveat, plus the verifier's 120s
|
|
84
|
+
* clock-skew allowance), so once authorize + window + skew is behind the
|
|
85
|
+
* payment, no poll — and no sweep tick — can ever change the answer.
|
|
86
|
+
* The paired `next_action` is `stop_and_tell_user`: tell the user the goods
|
|
87
|
+
* were delivered but Haven holds no verified settlement evidence; reporting
|
|
88
|
+
* a real settlement hash (`haven_report_settlement_evidence`) still works
|
|
89
|
+
* at any age.
|
|
90
|
+
*/
|
|
91
|
+
DeliveredUnverified: "delivered_unverified"
|
|
75
92
|
};
|
|
76
93
|
var AgentPaymentNextAction = {
|
|
77
94
|
/** Sign with the delegate key and submit the payment to Haven. */
|
|
@@ -219,7 +236,8 @@ var AgentPaymentPhaseDescriptions = {
|
|
|
219
236
|
[AgentPaymentPhase.Expired]: "The payment expired before completion.",
|
|
220
237
|
[AgentPaymentPhase.Failed]: "Haven could not complete the payment; the agent should stop and surface the failure.",
|
|
221
238
|
[AgentPaymentPhase.InsufficientFunds]: "Pre-flight check determined the delegate balance plus the remaining on-chain budget cannot cover the requested amount, so no payment was created. The account must be funded or the agent budget raised before retrying.",
|
|
222
|
-
[AgentPaymentPhase.FundedButUnsettled]: "Haven's funding leg confirmed on-chain but the merchant rejected the x402 retry. The delegate wallet may hold stranded funds. The agent should stop and wait for the wallet owner to sweep the stranded funds back to the account."
|
|
239
|
+
[AgentPaymentPhase.FundedButUnsettled]: "Haven's funding leg confirmed on-chain but the merchant rejected the x402 retry. The delegate wallet may hold stranded funds. The agent should stop and wait for the wallet owner to sweep the stranded funds back to the account.",
|
|
240
|
+
[AgentPaymentPhase.DeliveredUnverified]: "Terminal: the merchant delivered the goods and the settlement window plus the sweep's last attribution chance have both passed with no verified on-chain evidence. The payment can no longer resolve by polling. Tell the user the goods were delivered but Haven holds no verified settlement evidence for this payment."
|
|
223
241
|
};
|
|
224
242
|
var AgentPaymentNextActionDescriptions = {
|
|
225
243
|
[AgentPaymentNextAction.SignAndSubmitPayment]: "Sign with the delegate key and submit the payment to Haven.",
|
|
@@ -354,6 +372,24 @@ var MerchantTimeoutError = class extends HavenApiError {
|
|
|
354
372
|
this.name = "MerchantTimeoutError";
|
|
355
373
|
}
|
|
356
374
|
};
|
|
375
|
+
var X402Erc7710AlreadySettledError = class extends HavenError {
|
|
376
|
+
constructor(paymentId, txHash, body) {
|
|
377
|
+
super(
|
|
378
|
+
`Payment ${paymentId} already settled on-chain (tx ${txHash}). Nothing was signed and nothing new was charged.`,
|
|
379
|
+
"PAYMENT_ALREADY_SETTLED",
|
|
380
|
+
void 0,
|
|
381
|
+
paymentId
|
|
382
|
+
);
|
|
383
|
+
this.paymentId = paymentId;
|
|
384
|
+
this.txHash = txHash;
|
|
385
|
+
this.body = body;
|
|
386
|
+
this.name = "X402Erc7710AlreadySettledError";
|
|
387
|
+
}
|
|
388
|
+
paymentId;
|
|
389
|
+
txHash;
|
|
390
|
+
body;
|
|
391
|
+
x402ErrorCode = "payment_already_settled";
|
|
392
|
+
};
|
|
357
393
|
var X402UnexpectedStatusError = class extends HavenApiError {
|
|
358
394
|
x402ErrorCode = "unexpected_non_402_status";
|
|
359
395
|
/**
|
|
@@ -400,6 +436,19 @@ var HavenPaymentStateError = class extends HavenApiError {
|
|
|
400
436
|
return this.state.nextAction;
|
|
401
437
|
}
|
|
402
438
|
};
|
|
439
|
+
var X402TaskBudgetMismatchError = class extends HavenError {
|
|
440
|
+
constructor(message, idempotencyKey, entryTaskBudgetId, requestedTaskBudgetId) {
|
|
441
|
+
super(message, "X402_TASK_BUDGET_MISMATCH");
|
|
442
|
+
this.idempotencyKey = idempotencyKey;
|
|
443
|
+
this.entryTaskBudgetId = entryTaskBudgetId;
|
|
444
|
+
this.requestedTaskBudgetId = requestedTaskBudgetId;
|
|
445
|
+
this.name = "X402TaskBudgetMismatchError";
|
|
446
|
+
}
|
|
447
|
+
idempotencyKey;
|
|
448
|
+
entryTaskBudgetId;
|
|
449
|
+
requestedTaskBudgetId;
|
|
450
|
+
x402ErrorCode = "task_budget_mismatch";
|
|
451
|
+
};
|
|
403
452
|
var HavenSigningError = class extends HavenError {
|
|
404
453
|
constructor(message) {
|
|
405
454
|
super(message, "SIGNING_ERROR");
|
|
@@ -424,7 +473,7 @@ var SignerRefusalCode = {
|
|
|
424
473
|
UnsupportedSweepBindingVersion: "UNSUPPORTED_SWEEP_BINDING_VERSION"
|
|
425
474
|
};
|
|
426
475
|
function signerUpdateFallback(channel = HAVEN_CONNECTOR_CHANNEL) {
|
|
427
|
-
return `Update @haven_ai/signer
|
|
476
|
+
return `Update @haven_ai/signer: run \`${connectorUpgradeCommand({ channel })}\` and then the repair line it prints, which reinstalls the pinned MCP runtime, then retry the same signing call. Nothing was signed or spent \u2014 the quote or payment this version came from is unaffected and does not need to be re-quoted.`;
|
|
428
477
|
}
|
|
429
478
|
var SIGNER_UPDATE_FALLBACK = signerUpdateFallback();
|
|
430
479
|
var HavenUnsupportedSignerVersionError = class extends HavenError {
|
|
@@ -451,6 +500,7 @@ var HavenTimeoutError = class extends HavenError {
|
|
|
451
500
|
}
|
|
452
501
|
};
|
|
453
502
|
var DIRECT_SIGN_CONTEXT_VERSION = 1;
|
|
503
|
+
var TASK_SIGN_CONTEXT_VERSION = 1;
|
|
454
504
|
var EIP712_DOMAIN_FIELDS = [
|
|
455
505
|
{ name: "name", type: "string" },
|
|
456
506
|
{ name: "version", type: "string" },
|
|
@@ -848,7 +898,7 @@ var REDEEM_DELEGATIONS_ABI = [
|
|
|
848
898
|
var SINGLE_DEFAULT_MODE = `0x${"00".repeat(32)}`;
|
|
849
899
|
function refuse3(detail) {
|
|
850
900
|
throw new HavenSigningError(
|
|
851
|
-
`Refusing to sign: this UserOperation's redeemDelegations call ${detail}. This signer only signs one of
|
|
901
|
+
`Refusing to sign: this UserOperation's redeemDelegations call ${detail}. This signer only signs one of three shapes: a single grant to the agent's own account, a self-delegated task-budget child redeemed under it (the two-link [task child, budget] chain), or a sub-budget grant redeemed under its parent's self-narrowing (the three-link [sub grant, parent child, budget] chain, #3330).`
|
|
852
902
|
);
|
|
853
903
|
}
|
|
854
904
|
function assertRedeemsOwnBudgetDelegation(redeemCalldata, ownAccount) {
|
|
@@ -892,9 +942,9 @@ function assertRedeemsOwnBudgetDelegation(redeemCalldata, ownAccount) {
|
|
|
892
942
|
"carries an EMPTY delegation chain \u2014 DelegationManager treats this as self-authorised and runs the paired execution as the account, with no caveat, budget or recipient pin"
|
|
893
943
|
);
|
|
894
944
|
}
|
|
895
|
-
if (delegations.length !== 1 && delegations.length !== 2) {
|
|
945
|
+
if (delegations.length !== 1 && delegations.length !== 2 && delegations.length !== 3) {
|
|
896
946
|
refuse3(
|
|
897
|
-
`carries a ${delegations.length}-link delegation chain, not the single budget grant
|
|
947
|
+
`carries a ${delegations.length}-link delegation chain, not the single budget grant, the two-link [task child, budget] chain, or the three-link [sub grant, parent child, budget] chain Haven emits`
|
|
898
948
|
);
|
|
899
949
|
}
|
|
900
950
|
const reEncodedContext = encodeAbiParameters(DELEGATION_ARRAY_PARAM, [delegations]);
|
|
@@ -926,6 +976,37 @@ function assertRedeemsOwnBudgetDelegation(redeemCalldata, ownAccount) {
|
|
|
926
976
|
}
|
|
927
977
|
return;
|
|
928
978
|
}
|
|
979
|
+
if (delegations.length === 3) {
|
|
980
|
+
if (leaf.delegator.toLowerCase() === ownAccount.toLowerCase()) {
|
|
981
|
+
refuse3(
|
|
982
|
+
"carries a three-link chain whose leaf is delegated by this signer's OWN account \u2014 a sub-budget grant always comes from the delegating agent, never from the sub-agent itself"
|
|
983
|
+
);
|
|
984
|
+
}
|
|
985
|
+
const parentChild = delegations[1];
|
|
986
|
+
const parentAccount = leaf.delegator;
|
|
987
|
+
if (parentChild.delegate.toLowerCase() !== parentAccount.toLowerCase()) {
|
|
988
|
+
refuse3(
|
|
989
|
+
`carries a three-link chain whose middle link delegates to ${parentChild.delegate}, not the delegating agent's account the leaf names as its delegator (${parentAccount})`
|
|
990
|
+
);
|
|
991
|
+
}
|
|
992
|
+
if (parentChild.delegator.toLowerCase() !== parentAccount.toLowerCase()) {
|
|
993
|
+
refuse3(
|
|
994
|
+
`carries a three-link chain whose middle link is delegated by ${parentChild.delegator}, not the delegating agent's own account (${parentAccount}) \u2014 the parent link is a self-delegated narrowing`
|
|
995
|
+
);
|
|
996
|
+
}
|
|
997
|
+
const budget = delegations[2];
|
|
998
|
+
if (budget.delegate.toLowerCase() !== parentAccount.toLowerCase()) {
|
|
999
|
+
refuse3(
|
|
1000
|
+
`carries a three-link chain whose budget link delegates to ${budget.delegate}, not the delegating agent's account (${parentAccount})`
|
|
1001
|
+
);
|
|
1002
|
+
}
|
|
1003
|
+
if (budget.delegator.toLowerCase() === parentAccount.toLowerCase()) {
|
|
1004
|
+
refuse3(
|
|
1005
|
+
"carries a three-link chain whose budget link is granted by the delegating agent's OWN account \u2014 a real budget delegation always comes from elsewhere"
|
|
1006
|
+
);
|
|
1007
|
+
}
|
|
1008
|
+
return;
|
|
1009
|
+
}
|
|
929
1010
|
const root = delegations[delegations.length - 1];
|
|
930
1011
|
if (root.delegator.toLowerCase() === ownAccount.toLowerCase()) {
|
|
931
1012
|
refuse3(
|
|
@@ -934,6 +1015,6 @@ function assertRedeemsOwnBudgetDelegation(redeemCalldata, ownAccount) {
|
|
|
934
1015
|
}
|
|
935
1016
|
}
|
|
936
1017
|
|
|
937
|
-
export { AGENT_PAYMENT_FAILURE_CODE_VALUES, AGENT_PAYMENT_NEXT_ACTION_VALUES, AGENT_PAYMENT_PHASE_VALUES, AGENT_PAYMENT_RAIL_VALUES, AgentPaymentFailureCode, AgentPaymentFailureCodeDescriptions, AgentPaymentFailureCodeSchema, AgentPaymentNextAction, AgentPaymentNextActionDescriptions, AgentPaymentNextActionSchema, AgentPaymentPhase, AgentPaymentPhaseDescriptions, AgentPaymentPhaseSchema, AgentPaymentRail, AgentPaymentRailDescriptions, AgentPaymentRailSchema, AgentPaymentWarningCode, CAVEAT_ENFORCERS, CONNECTOR_PACKAGE_NAME, DEFAULT_CONFIRMATION_TIMEOUT_MS, DELEGATION_MANAGER, DELEGATION_TUPLE_COMPONENTS, DIRECT_SIGN_CONTEXT_VERSION, ENTRY_POINT_V07, HAVEN_CONNECTOR_CHANNEL, HYBRID_DELEGATOR_DOMAIN_NAME, HYBRID_DELEGATOR_DOMAIN_VERSION, HYBRID_DELEGATOR_IMPLEMENTATION, HavenApiError, HavenError, HavenPaymentStateError, HavenSigningError, HavenTimeoutError, HavenUnsupportedSignerVersionError, HavenUserOpBindingError, HavenZeroSettlementHashError, MAX_SETTLEMENT_WINDOW_SECONDS, MerchantTimeoutError, PACKED_USER_OPERATION_FIELDS, REDEEM_DELEGATIONS_ABI, ROOT_AUTHORITY, SIGNER_UPDATE_FALLBACK, SIMPLE_FACTORY_ADDRESS, SINGLE_DEFAULT_MODE, SignerRefusalCode, X402AlreadySettledError, X402UnexpectedStatusError, assertRedeemsOwnBudgetDelegation, assertUserOpTypedDataBinding, chainIdForNetwork, connectorRerunCommand, connectorSpec, deriveDelegateAccountAddress, isConnectorChannel, isPackedUserOperationTypedData, isSettlementChildTypedData, packedUserOperationHash, resolveConnectorChannel, signerUpdateFallback, verifySettlementChild };
|
|
938
|
-
//# sourceMappingURL=chunk-
|
|
939
|
-
//# sourceMappingURL=chunk-
|
|
1018
|
+
export { AGENT_PAYMENT_FAILURE_CODE_VALUES, AGENT_PAYMENT_NEXT_ACTION_VALUES, AGENT_PAYMENT_PHASE_VALUES, AGENT_PAYMENT_RAIL_VALUES, AgentPaymentFailureCode, AgentPaymentFailureCodeDescriptions, AgentPaymentFailureCodeSchema, AgentPaymentNextAction, AgentPaymentNextActionDescriptions, AgentPaymentNextActionSchema, AgentPaymentPhase, AgentPaymentPhaseDescriptions, AgentPaymentPhaseSchema, AgentPaymentRail, AgentPaymentRailDescriptions, AgentPaymentRailSchema, AgentPaymentWarningCode, CAVEAT_ENFORCERS, CONNECTOR_PACKAGE_NAME, DEFAULT_CONFIRMATION_TIMEOUT_MS, DELEGATION_MANAGER, DELEGATION_TUPLE_COMPONENTS, DIRECT_SIGN_CONTEXT_VERSION, ENTRY_POINT_V07, HAVEN_CONNECTOR_CHANNEL, HYBRID_DELEGATOR_DOMAIN_NAME, HYBRID_DELEGATOR_DOMAIN_VERSION, HYBRID_DELEGATOR_IMPLEMENTATION, HavenApiError, HavenError, HavenPaymentStateError, HavenSigningError, HavenTimeoutError, HavenUnsupportedSignerVersionError, HavenUserOpBindingError, HavenZeroSettlementHashError, MAX_SETTLEMENT_WINDOW_SECONDS, MerchantTimeoutError, PACKED_USER_OPERATION_FIELDS, REDEEM_DELEGATIONS_ABI, ROOT_AUTHORITY, SIGNER_UPDATE_FALLBACK, SIMPLE_FACTORY_ADDRESS, SINGLE_DEFAULT_MODE, SignerRefusalCode, TASK_SIGN_CONTEXT_VERSION, X402AlreadySettledError, X402Erc7710AlreadySettledError, X402TaskBudgetMismatchError, X402UnexpectedStatusError, assertRedeemsOwnBudgetDelegation, assertUserOpTypedDataBinding, chainIdForNetwork, connectorRerunCommand, connectorSpec, connectorUpgradeCommand, deriveDelegateAccountAddress, isConnectorChannel, isPackedUserOperationTypedData, isSettlementChildTypedData, packedUserOperationHash, resolveConnectorChannel, signerUpdateFallback, verifySettlementChild };
|
|
1019
|
+
//# sourceMappingURL=chunk-H4APV67M.js.map
|
|
1020
|
+
//# sourceMappingURL=chunk-H4APV67M.js.map
|