@haven_ai/sdk 0.0.0-dev.202609232125.72f3d20 → 0.0.0-dev.202609241802.ea320de
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 +9 -3
- package/dist/{base64-CNakwKE8.d.cts → base64-CPxbmyU9.d.cts} +80 -17
- package/dist/{base64-CNakwKE8.d.ts → base64-CPxbmyU9.d.ts} +80 -17
- package/dist/{chunk-7FXW3IKZ.js → chunk-FR5R26V3.js} +139 -8
- package/dist/chunk-FR5R26V3.js.map +1 -0
- package/dist/{chunk-AS6BCA42.cjs → chunk-M57KOLAN.cjs} +147 -7
- package/dist/chunk-M57KOLAN.cjs.map +1 -0
- package/dist/edge.cjs +50 -26
- package/dist/edge.d.cts +2 -1
- package/dist/edge.d.ts +2 -1
- package/dist/edge.js +2 -2
- package/dist/index.cjs +291 -252
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -7
- package/dist/index.d.ts +10 -7
- package/dist/index.js +11 -8
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
- package/dist/chunk-7FXW3IKZ.js.map +0 -1
- package/dist/chunk-AS6BCA42.cjs.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var crypto = require('crypto');
|
|
4
3
|
var viem = require('viem');
|
|
4
|
+
var crypto = require('crypto');
|
|
5
5
|
|
|
6
6
|
// src/connector-channel.ts
|
|
7
7
|
var CONNECTOR_PACKAGE_NAME = "@haven_ai/connect";
|
|
@@ -115,9 +115,9 @@ var AgentPaymentNextAction = {
|
|
|
115
115
|
*/
|
|
116
116
|
FundAccountOrRaiseAllowance: "fund_account_or_raise_allowance",
|
|
117
117
|
/**
|
|
118
|
-
* The delegate wallet may hold funds that were sent from the
|
|
119
|
-
* settled to the merchant. The wallet owner should initiate
|
|
120
|
-
* return those funds to
|
|
118
|
+
* The delegate wallet may hold funds that were sent from the agent's Haven
|
|
119
|
+
* account but never settled to the merchant. The wallet owner should initiate
|
|
120
|
+
* a sweep to return those funds to that account.
|
|
121
121
|
*/
|
|
122
122
|
SweepStrandedFunds: "sweep_stranded_funds",
|
|
123
123
|
/**
|
|
@@ -191,7 +191,7 @@ var AgentPaymentFailureCode = {
|
|
|
191
191
|
MerchantNotReady: "MERCHANT_NOT_READY"
|
|
192
192
|
};
|
|
193
193
|
var AgentPaymentRail = {
|
|
194
|
-
/** Standard Haven payment from the user's
|
|
194
|
+
/** Standard Haven payment from the user's account, redeemed through the agent's budget delegation. */
|
|
195
195
|
Direct: "direct",
|
|
196
196
|
/** x402 HTTP 402 payment flow with a Haven funding leg and merchant retry leg. */
|
|
197
197
|
X402: "x402",
|
|
@@ -453,6 +453,137 @@ var HavenTimeoutError = class extends HavenError {
|
|
|
453
453
|
this.name = "HavenTimeoutError";
|
|
454
454
|
}
|
|
455
455
|
};
|
|
456
|
+
var DIRECT_SIGN_CONTEXT_VERSION = 1;
|
|
457
|
+
var EIP712_DOMAIN_FIELDS = [
|
|
458
|
+
{ name: "name", type: "string" },
|
|
459
|
+
{ name: "version", type: "string" },
|
|
460
|
+
{ name: "chainId", type: "uint256" },
|
|
461
|
+
{ name: "verifyingContract", type: "address" }
|
|
462
|
+
];
|
|
463
|
+
var ENTRY_POINT_V07 = "0x0000000071727De22E5E9d8BAf0edAc6f37da032";
|
|
464
|
+
var HYBRID_DELEGATOR_DOMAIN_NAME = "HybridDeleGator";
|
|
465
|
+
var HYBRID_DELEGATOR_DOMAIN_VERSION = "1";
|
|
466
|
+
var PACKED_USER_OPERATION_FIELDS = [
|
|
467
|
+
{ name: "sender", type: "address" },
|
|
468
|
+
{ name: "nonce", type: "uint256" },
|
|
469
|
+
{ name: "initCode", type: "bytes" },
|
|
470
|
+
{ name: "callData", type: "bytes" },
|
|
471
|
+
{ name: "accountGasLimits", type: "bytes32" },
|
|
472
|
+
{ name: "preVerificationGas", type: "uint256" },
|
|
473
|
+
{ name: "gasFees", type: "bytes32" },
|
|
474
|
+
{ name: "paymasterAndData", type: "bytes" },
|
|
475
|
+
{ name: "entryPoint", type: "address" }
|
|
476
|
+
];
|
|
477
|
+
var HavenUserOpBindingError = class extends HavenError {
|
|
478
|
+
constructor(message) {
|
|
479
|
+
super(message, "USEROP_BINDING_MISMATCH");
|
|
480
|
+
this.name = "HavenUserOpBindingError";
|
|
481
|
+
}
|
|
482
|
+
};
|
|
483
|
+
function isPackedUserOperationTypedData(value) {
|
|
484
|
+
return typeof value === "object" && value !== null && value.primaryType === "PackedUserOperation";
|
|
485
|
+
}
|
|
486
|
+
var HEX = /^0x[0-9a-fA-F]*$/;
|
|
487
|
+
var BYTES32 = /^0x[0-9a-fA-F]{64}$/;
|
|
488
|
+
function refuse(detail) {
|
|
489
|
+
throw new HavenUserOpBindingError(
|
|
490
|
+
`Refusing to sign: this UserOperation typed data does not match its payload_hash (${detail}). The payload was altered between the Haven result and this call \u2014 sign by payment_id so the signer fetches the exact bytes, or pass typed_data_b64 from the result unchanged.`
|
|
491
|
+
);
|
|
492
|
+
}
|
|
493
|
+
function hexField(message, key, pattern) {
|
|
494
|
+
const value = message[key];
|
|
495
|
+
if (typeof value !== "string" || !pattern.test(value)) refuse(`message.${key} is not well-formed`);
|
|
496
|
+
return value;
|
|
497
|
+
}
|
|
498
|
+
function uintField(message, key) {
|
|
499
|
+
const value = message[key];
|
|
500
|
+
try {
|
|
501
|
+
if (typeof value === "bigint") return value;
|
|
502
|
+
if (typeof value === "string" && /^(0x[0-9a-fA-F]+|[0-9]+)$/.test(value) || typeof value === "number") {
|
|
503
|
+
const n = BigInt(value);
|
|
504
|
+
if (n >= 0n) return n;
|
|
505
|
+
}
|
|
506
|
+
} catch {
|
|
507
|
+
}
|
|
508
|
+
return refuse(`message.${key} is not an unsigned integer`);
|
|
509
|
+
}
|
|
510
|
+
function addressField(value, where) {
|
|
511
|
+
if (typeof value !== "string" || !viem.isAddress(value, { strict: false })) refuse(`${where} is not an address`);
|
|
512
|
+
return viem.getAddress(value);
|
|
513
|
+
}
|
|
514
|
+
function packedUserOperationHash(typedData) {
|
|
515
|
+
if (!isPackedUserOperationTypedData(typedData)) refuse("primaryType is not PackedUserOperation");
|
|
516
|
+
const td = typedData;
|
|
517
|
+
const message = td.message;
|
|
518
|
+
if (!message || typeof message !== "object") refuse("message is missing");
|
|
519
|
+
const chainId = uintField({ chainId: td.domain?.chainId }, "chainId");
|
|
520
|
+
const inner = viem.keccak256(
|
|
521
|
+
viem.encodeAbiParameters(
|
|
522
|
+
[
|
|
523
|
+
{ type: "address" },
|
|
524
|
+
{ type: "uint256" },
|
|
525
|
+
{ type: "bytes32" },
|
|
526
|
+
{ type: "bytes32" },
|
|
527
|
+
{ type: "bytes32" },
|
|
528
|
+
{ type: "uint256" },
|
|
529
|
+
{ type: "bytes32" },
|
|
530
|
+
{ type: "bytes32" }
|
|
531
|
+
],
|
|
532
|
+
[
|
|
533
|
+
addressField(message.sender, "message.sender"),
|
|
534
|
+
uintField(message, "nonce"),
|
|
535
|
+
viem.keccak256(hexField(message, "initCode", HEX)),
|
|
536
|
+
viem.keccak256(hexField(message, "callData", HEX)),
|
|
537
|
+
hexField(message, "accountGasLimits", BYTES32),
|
|
538
|
+
uintField(message, "preVerificationGas"),
|
|
539
|
+
hexField(message, "gasFees", BYTES32),
|
|
540
|
+
viem.keccak256(hexField(message, "paymasterAndData", HEX))
|
|
541
|
+
]
|
|
542
|
+
)
|
|
543
|
+
);
|
|
544
|
+
return viem.keccak256(
|
|
545
|
+
viem.encodeAbiParameters(
|
|
546
|
+
[{ type: "bytes32" }, { type: "address" }, { type: "uint256" }],
|
|
547
|
+
[inner, addressField(message.entryPoint, "message.entryPoint"), chainId]
|
|
548
|
+
)
|
|
549
|
+
);
|
|
550
|
+
}
|
|
551
|
+
function assertUserOpTypedDataBinding(typedData, payloadHash) {
|
|
552
|
+
if (typeof payloadHash !== "string" || !BYTES32.test(payloadHash)) refuse("payload_hash is not a 32-byte hex string");
|
|
553
|
+
if (!isPackedUserOperationTypedData(typedData)) refuse("primaryType is not PackedUserOperation");
|
|
554
|
+
const td = typedData;
|
|
555
|
+
const domain = td.domain ?? {};
|
|
556
|
+
const message = td.message ?? {};
|
|
557
|
+
if (domain.name !== HYBRID_DELEGATOR_DOMAIN_NAME) refuse("domain.name is not HybridDeleGator");
|
|
558
|
+
if (domain.version !== HYBRID_DELEGATOR_DOMAIN_VERSION) refuse("domain.version is not 1");
|
|
559
|
+
if (addressField(domain.verifyingContract, "domain.verifyingContract") !== addressField(message.sender, "message.sender")) {
|
|
560
|
+
refuse("domain.verifyingContract is not message.sender");
|
|
561
|
+
}
|
|
562
|
+
if (addressField(message.entryPoint, "message.entryPoint") !== viem.getAddress(ENTRY_POINT_V07)) {
|
|
563
|
+
refuse("message.entryPoint is not the v0.7 EntryPoint");
|
|
564
|
+
}
|
|
565
|
+
const fields = (td.types ?? {}).PackedUserOperation;
|
|
566
|
+
if (!Array.isArray(fields) || fields.length !== PACKED_USER_OPERATION_FIELDS.length || fields.some(
|
|
567
|
+
(f, i) => !f || f.name !== PACKED_USER_OPERATION_FIELDS[i].name || f.type !== PACKED_USER_OPERATION_FIELDS[i].type
|
|
568
|
+
)) {
|
|
569
|
+
refuse("types.PackedUserOperation is not the HybridDeleGator field list");
|
|
570
|
+
}
|
|
571
|
+
const extraTypes = Object.keys(td.types ?? {}).filter((k) => k !== "PackedUserOperation" && k !== "EIP712Domain");
|
|
572
|
+
if (extraTypes.length > 0) refuse(`unexpected types: ${extraTypes.join(", ")}`);
|
|
573
|
+
const domainKeys = Object.keys(domain).sort();
|
|
574
|
+
if (domainKeys.join(",") !== [...EIP712_DOMAIN_FIELDS.map((f) => f.name)].sort().join(",")) {
|
|
575
|
+
refuse(`domain keys are not exactly ${EIP712_DOMAIN_FIELDS.map((f) => f.name).join(", ")}`);
|
|
576
|
+
}
|
|
577
|
+
const declaredDomain = (td.types ?? {}).EIP712Domain;
|
|
578
|
+
if (declaredDomain !== void 0 && (!Array.isArray(declaredDomain) || declaredDomain.length !== EIP712_DOMAIN_FIELDS.length || declaredDomain.some(
|
|
579
|
+
(f, i) => !f || f.name !== EIP712_DOMAIN_FIELDS[i].name || f.type !== EIP712_DOMAIN_FIELDS[i].type
|
|
580
|
+
))) {
|
|
581
|
+
refuse("types.EIP712Domain is not the canonical name/version/chainId/verifyingContract list");
|
|
582
|
+
}
|
|
583
|
+
const recomputed = packedUserOperationHash(typedData);
|
|
584
|
+
if (recomputed.toLowerCase() !== payloadHash.toLowerCase()) refuse("recomputed UserOperation hash differs");
|
|
585
|
+
return recomputed;
|
|
586
|
+
}
|
|
456
587
|
|
|
457
588
|
// src/base64.ts
|
|
458
589
|
function normalizeBase64(value) {
|
|
@@ -1182,19 +1313,25 @@ exports.AgentPaymentWarningCode = AgentPaymentWarningCode;
|
|
|
1182
1313
|
exports.CONNECTOR_PACKAGE_NAME = CONNECTOR_PACKAGE_NAME;
|
|
1183
1314
|
exports.DEFAULT_CONFIRMATION_TIMEOUT_MS = DEFAULT_CONFIRMATION_TIMEOUT_MS;
|
|
1184
1315
|
exports.DEFAULT_NEXT_TOOL_BY_ACTION = DEFAULT_NEXT_TOOL_BY_ACTION;
|
|
1316
|
+
exports.DIRECT_SIGN_CONTEXT_VERSION = DIRECT_SIGN_CONTEXT_VERSION;
|
|
1317
|
+
exports.ENTRY_POINT_V07 = ENTRY_POINT_V07;
|
|
1185
1318
|
exports.ERC7710_ASSET_TRANSFER_METHOD = ERC7710_ASSET_TRANSFER_METHOD;
|
|
1186
1319
|
exports.HAVEN_CONNECTOR_CHANNEL = HAVEN_CONNECTOR_CHANNEL;
|
|
1187
1320
|
exports.HAVEN_MINIMUM_NODE_VERSION = HAVEN_MINIMUM_NODE_VERSION;
|
|
1321
|
+
exports.HYBRID_DELEGATOR_DOMAIN_NAME = HYBRID_DELEGATOR_DOMAIN_NAME;
|
|
1322
|
+
exports.HYBRID_DELEGATOR_DOMAIN_VERSION = HYBRID_DELEGATOR_DOMAIN_VERSION;
|
|
1188
1323
|
exports.HavenApiError = HavenApiError;
|
|
1189
1324
|
exports.HavenError = HavenError;
|
|
1190
1325
|
exports.HavenPaymentStateError = HavenPaymentStateError;
|
|
1191
1326
|
exports.HavenSigningError = HavenSigningError;
|
|
1192
1327
|
exports.HavenTimeoutError = HavenTimeoutError;
|
|
1193
1328
|
exports.HavenUnsupportedSignerVersionError = HavenUnsupportedSignerVersionError;
|
|
1329
|
+
exports.HavenUserOpBindingError = HavenUserOpBindingError;
|
|
1194
1330
|
exports.HavenZeroSettlementHashError = HavenZeroSettlementHashError;
|
|
1195
1331
|
exports.MerchantTimeoutError = MerchantTimeoutError;
|
|
1196
1332
|
exports.NEXT_TOOL_SERVER_NAMES = NEXT_TOOL_SERVER_NAMES;
|
|
1197
1333
|
exports.NEXT_TOOL_SERVER_ROLES = NEXT_TOOL_SERVER_ROLES;
|
|
1334
|
+
exports.PACKED_USER_OPERATION_FIELDS = PACKED_USER_OPERATION_FIELDS;
|
|
1198
1335
|
exports.SIGNER_UPDATE_FALLBACK = SIGNER_UPDATE_FALLBACK;
|
|
1199
1336
|
exports.SWEEP_BASE_CHAIN_ID = SWEEP_BASE_CHAIN_ID;
|
|
1200
1337
|
exports.SWEEP_BASE_SEPOLIA_CHAIN_ID = SWEEP_BASE_SEPOLIA_CHAIN_ID;
|
|
@@ -1213,6 +1350,7 @@ exports.X402_PAYMENT_HEADER_NAMES_SENT = X402_PAYMENT_HEADER_NAMES_SENT;
|
|
|
1213
1350
|
exports.X402_PAYMENT_REQUIRED_HEADER_NAME = X402_PAYMENT_REQUIRED_HEADER_NAME;
|
|
1214
1351
|
exports.X402_PAYMENT_RESPONSE_HEADER_NAME = X402_PAYMENT_RESPONSE_HEADER_NAME;
|
|
1215
1352
|
exports.X402_SETTLEMENT_FORWARD_MARGIN_SECONDS = X402_SETTLEMENT_FORWARD_MARGIN_SECONDS;
|
|
1353
|
+
exports.assertUserOpTypedDataBinding = assertUserOpTypedDataBinding;
|
|
1216
1354
|
exports.buildSweepAuthorizationMessage = buildSweepAuthorizationMessage;
|
|
1217
1355
|
exports.buildSweepTypedData = buildSweepTypedData;
|
|
1218
1356
|
exports.buildX402ExpectedMessage = buildX402ExpectedMessage;
|
|
@@ -1229,9 +1367,11 @@ exports.encodeBase64Utf8 = encodeBase64Utf8;
|
|
|
1229
1367
|
exports.encodePaymentProof = encodePaymentProof;
|
|
1230
1368
|
exports.isConnectorChannel = isConnectorChannel;
|
|
1231
1369
|
exports.isErc7710Option = isErc7710Option;
|
|
1370
|
+
exports.isPackedUserOperationTypedData = isPackedUserOperationTypedData;
|
|
1232
1371
|
exports.isSupportedNodeVersion = isSupportedNodeVersion;
|
|
1233
1372
|
exports.isSweepableChain = isSweepableChain;
|
|
1234
1373
|
exports.normalizePaymentRequired = normalizePaymentRequired;
|
|
1374
|
+
exports.packedUserOperationHash = packedUserOperationHash;
|
|
1235
1375
|
exports.parseNextTool = parseNextTool;
|
|
1236
1376
|
exports.parsePaymentRequired = parsePaymentRequired;
|
|
1237
1377
|
exports.parsePaymentRequiredResponse = parsePaymentRequiredResponse;
|
|
@@ -1254,5 +1394,5 @@ exports.x402FacilitatorAddresses = x402FacilitatorAddresses;
|
|
|
1254
1394
|
exports.x402PaymentHeaderNamesFor = x402PaymentHeaderNamesFor;
|
|
1255
1395
|
exports.x402PaymentHeaderNamesSent = x402PaymentHeaderNamesSent;
|
|
1256
1396
|
exports.x402V2PaymentEnvelope = x402V2PaymentEnvelope;
|
|
1257
|
-
//# sourceMappingURL=chunk-
|
|
1258
|
-
//# sourceMappingURL=chunk-
|
|
1397
|
+
//# sourceMappingURL=chunk-M57KOLAN.cjs.map
|
|
1398
|
+
//# sourceMappingURL=chunk-M57KOLAN.cjs.map
|