@haven_ai/sdk 0.0.0-dev.202609291912.efd0772 → 0.0.0-dev.202609291949.4e52d4b
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{base64-DyOPH887.d.cts → base64-VVxgYQAD.d.cts} +1 -1
- package/dist/{base64-DyOPH887.d.ts → base64-VVxgYQAD.d.ts} +1 -1
- package/dist/{chunk-MJ2IMB5H.cjs → chunk-J6SS36ZD.cjs} +189 -3
- package/dist/chunk-J6SS36ZD.cjs.map +1 -0
- package/dist/{chunk-6JQT7HNR.js → chunk-S35ZUPXQ.js} +179 -6
- package/dist/chunk-S35ZUPXQ.js.map +1 -0
- package/dist/edge.cjs +88 -88
- package/dist/edge.cjs.map +1 -1
- package/dist/edge.d.cts +172 -3
- package/dist/edge.d.ts +172 -3
- package/dist/edge.js +4 -53
- package/dist/edge.js.map +1 -1
- package/dist/index.cjs +220 -130
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +97 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-6JQT7HNR.js.map +0 -1
- package/dist/chunk-MJ2IMB5H.cjs.map +0 -1
|
@@ -2077,7 +2077,7 @@ declare function buildSweepAuthorizationMessage(auth: SweepAuthorization): strin
|
|
|
2077
2077
|
* This SDK's own version. Owned by `scripts/release-bump.mjs`, which rewrites
|
|
2078
2078
|
* it with the package version on every release — never hand-edit it.
|
|
2079
2079
|
*/
|
|
2080
|
-
declare const SDK_VERSION = "0.0.0-dev.
|
|
2080
|
+
declare const SDK_VERSION = "0.0.0-dev.202609291949.4e52d4b";
|
|
2081
2081
|
/** The request header every published Haven client sends. */
|
|
2082
2082
|
declare const HAVEN_CLIENT_HEADER = "X-Haven-Client";
|
|
2083
2083
|
/** `<package>/<version>` — the value of {@link HAVEN_CLIENT_HEADER}. */
|
|
@@ -2077,7 +2077,7 @@ declare function buildSweepAuthorizationMessage(auth: SweepAuthorization): strin
|
|
|
2077
2077
|
* This SDK's own version. Owned by `scripts/release-bump.mjs`, which rewrites
|
|
2078
2078
|
* it with the package version on every release — never hand-edit it.
|
|
2079
2079
|
*/
|
|
2080
|
-
declare const SDK_VERSION = "0.0.0-dev.
|
|
2080
|
+
declare const SDK_VERSION = "0.0.0-dev.202609291949.4e52d4b";
|
|
2081
2081
|
/** The request header every published Haven client sends. */
|
|
2082
2082
|
declare const HAVEN_CLIENT_HEADER = "X-Haven-Client";
|
|
2083
2083
|
/** `<package>/<version>` — the value of {@link HAVEN_CLIENT_HEADER}. */
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
var chunkSZHKBOCZ_cjs = require('./chunk-SZHKBOCZ.cjs');
|
|
4
4
|
var viem = require('viem');
|
|
5
5
|
var crypto = require('crypto');
|
|
6
|
+
var secp256k1 = require('@noble/curves/secp256k1');
|
|
7
|
+
var accounts = require('viem/accounts');
|
|
6
8
|
|
|
7
9
|
var TYPED_DATA_NOT_ALLOWED = "TYPED_DATA_NOT_ALLOWED";
|
|
8
10
|
var HavenTypedDataRefusedError = class extends chunkSZHKBOCZ_cjs.HavenSigningError {
|
|
@@ -785,7 +787,7 @@ function stableStringify2(value) {
|
|
|
785
787
|
}
|
|
786
788
|
|
|
787
789
|
// src/client-identity.ts
|
|
788
|
-
var SDK_VERSION = "0.0.0-dev.
|
|
790
|
+
var SDK_VERSION = "0.0.0-dev.202609291949.4e52d4b";
|
|
789
791
|
var HAVEN_CLIENT_HEADER = "X-Haven-Client";
|
|
790
792
|
function havenClientIdentity(pkg, version) {
|
|
791
793
|
return `${pkg}/${version}`;
|
|
@@ -807,6 +809,177 @@ function readClientUpdate(value) {
|
|
|
807
809
|
notes_url: typeof v.notes_url === "string" ? v.notes_url : null
|
|
808
810
|
};
|
|
809
811
|
}
|
|
812
|
+
var HALF_N = BigInt("0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0");
|
|
813
|
+
function hexBytes(value, bytes, what) {
|
|
814
|
+
if (!/^0x[0-9a-fA-F]+$/.test(value) || value.length !== 2 + bytes * 2) {
|
|
815
|
+
throw new Error(`${what} must be a 0x-prefixed ${bytes}-byte hex string`);
|
|
816
|
+
}
|
|
817
|
+
return value.slice(2);
|
|
818
|
+
}
|
|
819
|
+
function addressFromKey(privateKey) {
|
|
820
|
+
try {
|
|
821
|
+
return accounts.privateKeyToAddress(`0x${hexBytes(privateKey, 32, "private key")}`);
|
|
822
|
+
} catch (err) {
|
|
823
|
+
throw new chunkSZHKBOCZ_cjs.HavenSigningError(
|
|
824
|
+
`Invalid private key: ${err instanceof Error ? err.message : String(err)}`
|
|
825
|
+
);
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
function signHash(privateKey, hash) {
|
|
829
|
+
try {
|
|
830
|
+
const { r, s, recovery } = secp256k1.secp256k1.sign(hexBytes(hash, 32, "hash"), hexBytes(privateKey, 32, "private key"), { lowS: true });
|
|
831
|
+
return viem.serializeSignature({
|
|
832
|
+
r: `0x${r.toString(16).padStart(64, "0")}`,
|
|
833
|
+
s: `0x${s.toString(16).padStart(64, "0")}`,
|
|
834
|
+
yParity: recovery
|
|
835
|
+
});
|
|
836
|
+
} catch (err) {
|
|
837
|
+
throw new chunkSZHKBOCZ_cjs.HavenSigningError(
|
|
838
|
+
`Failed to sign hash: ${err instanceof Error ? err.message : String(err)}`
|
|
839
|
+
);
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
function verifySignature(hash, signature, expectedAddress) {
|
|
843
|
+
try {
|
|
844
|
+
const sig = hexBytes(signature, 65, "signature");
|
|
845
|
+
const hashHex = hexBytes(hash, 32, "hash");
|
|
846
|
+
if (BigInt(`0x${sig.slice(64, 128)}`) > HALF_N) return false;
|
|
847
|
+
const yParityOrV = Number.parseInt(sig.slice(128), 16);
|
|
848
|
+
const recoveryBit = yParityOrV === 0 || yParityOrV === 27 ? 0 : yParityOrV === 1 || yParityOrV === 28 ? 1 : -1;
|
|
849
|
+
if (recoveryBit < 0) return false;
|
|
850
|
+
const publicKey = secp256k1.secp256k1.Signature.fromCompact(sig.slice(0, 128)).addRecoveryBit(recoveryBit).recoverPublicKey(hashHex).toHex(false);
|
|
851
|
+
const recovered = accounts.publicKeyToAddress(`0x${publicKey}`);
|
|
852
|
+
return recovered.toLowerCase() === expectedAddress.toLowerCase();
|
|
853
|
+
} catch {
|
|
854
|
+
return false;
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
var TAX_DECLARATION_DOMAIN = { name: "x402 Tax Declaration", version: "1" };
|
|
858
|
+
var TAX_DECLARATION_PRIMARY_TYPE = "TaxDeclaration";
|
|
859
|
+
var TAX_DECLARATION_TYPES = {
|
|
860
|
+
TaxDeclaration: [
|
|
861
|
+
{ name: "version", type: "string" },
|
|
862
|
+
{ name: "jurisdiction", type: "string" },
|
|
863
|
+
{ name: "taxableStatus", type: "string" },
|
|
864
|
+
{ name: "taxId", type: "string" },
|
|
865
|
+
{ name: "validUntil", type: "uint256" },
|
|
866
|
+
{ name: "principalId", type: "string" },
|
|
867
|
+
{ name: "principalAttributionHash", type: "string" }
|
|
868
|
+
]
|
|
869
|
+
};
|
|
870
|
+
var X_TAX_DECLARATION_HEADER = "X-Tax-Declaration";
|
|
871
|
+
function validateContent(content) {
|
|
872
|
+
if (typeof content !== "object" || content === null || Array.isArray(content)) {
|
|
873
|
+
throw new chunkSZHKBOCZ_cjs.HavenSigningError("Tax declaration content must be an object.");
|
|
874
|
+
}
|
|
875
|
+
const record = content;
|
|
876
|
+
for (const field of ["principalId", "principalAttributionHash"]) {
|
|
877
|
+
if (record[field] !== void 0) {
|
|
878
|
+
throw new TaxDeclarationRefusedError(
|
|
879
|
+
`Tax declaration content arrives with ${field} already set; that field is computed locally from the delegate key and the accepted payment option, never accepted from Haven.`
|
|
880
|
+
);
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
const allowed = /* @__PURE__ */ new Set(["version", "jurisdiction", "taxableStatus", "taxId", "validUntil"]);
|
|
884
|
+
for (const key of Object.keys(record)) {
|
|
885
|
+
if (!allowed.has(key)) {
|
|
886
|
+
throw new TaxDeclarationRefusedError(
|
|
887
|
+
`Tax declaration content carries an unknown field '${key}'; the signed shape is built locally from the \xA72.1 fields only.`
|
|
888
|
+
);
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
const strings = ["version", "jurisdiction", "taxableStatus", "taxId"];
|
|
892
|
+
for (const key of strings) {
|
|
893
|
+
if (typeof record[key] !== "string" || record[key].length === 0) {
|
|
894
|
+
throw new TaxDeclarationRefusedError(
|
|
895
|
+
`Tax declaration content field '${key}' must be a non-empty string.`
|
|
896
|
+
);
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
if (typeof record.validUntil !== "number" || !Number.isInteger(record.validUntil) || record.validUntil <= 0) {
|
|
900
|
+
throw new TaxDeclarationRefusedError(
|
|
901
|
+
"Tax declaration content field 'validUntil' must be a positive integer (milliseconds)."
|
|
902
|
+
);
|
|
903
|
+
}
|
|
904
|
+
return {
|
|
905
|
+
version: record.version,
|
|
906
|
+
jurisdiction: record.jurisdiction,
|
|
907
|
+
taxableStatus: record.taxableStatus,
|
|
908
|
+
taxId: record.taxId,
|
|
909
|
+
validUntil: record.validUntil
|
|
910
|
+
};
|
|
911
|
+
}
|
|
912
|
+
function jcsCanonicalBytes(value) {
|
|
913
|
+
const keys = Object.keys(value).sort();
|
|
914
|
+
const members = keys.map((key) => `${JSON.stringify(key)}:${JSON.stringify(value[key])}`);
|
|
915
|
+
return `{${members.join(",")}}`;
|
|
916
|
+
}
|
|
917
|
+
function principalAttributionHash(principalId) {
|
|
918
|
+
const canonical = jcsCanonicalBytes({ principalId });
|
|
919
|
+
const hex2 = crypto.createHash("sha256").update(canonical, "utf8").digest("hex");
|
|
920
|
+
return `sha-256:${hex2}`;
|
|
921
|
+
}
|
|
922
|
+
function taxPrincipalId(network, delegateAddress) {
|
|
923
|
+
if (network.startsWith("eip155:")) {
|
|
924
|
+
return `did:pkh:${network}:${delegateAddress}`;
|
|
925
|
+
}
|
|
926
|
+
const chainId = chunkSZHKBOCZ_cjs.chainIdForNetwork(network);
|
|
927
|
+
if (chainId === void 0) {
|
|
928
|
+
throw new TaxDeclarationRefusedError(
|
|
929
|
+
`The accepted payment option's network '${network}' is not a CAIP-2 eip155 chain this SDK can name; refusing to build a tax principal without the settlement network.`
|
|
930
|
+
);
|
|
931
|
+
}
|
|
932
|
+
return `did:pkh:eip155:${chainId}:${delegateAddress}`;
|
|
933
|
+
}
|
|
934
|
+
function buildSignedTaxDeclaration(input) {
|
|
935
|
+
const content = validateContent(input.content);
|
|
936
|
+
const principalId = taxPrincipalId(input.network, addressFromKeyForTax(input.delegateKey));
|
|
937
|
+
const attributionHash = principalAttributionHash(principalId);
|
|
938
|
+
const declaration = { ...content, principalId, principalAttributionHash: attributionHash };
|
|
939
|
+
const message = { ...declaration, validUntil: BigInt(declaration.validUntil) };
|
|
940
|
+
const digest = viem.hashTypedData({
|
|
941
|
+
domain: TAX_DECLARATION_DOMAIN,
|
|
942
|
+
types: TAX_DECLARATION_TYPES,
|
|
943
|
+
primaryType: TAX_DECLARATION_PRIMARY_TYPE,
|
|
944
|
+
message
|
|
945
|
+
});
|
|
946
|
+
const signature = signHash(input.delegateKey, digest);
|
|
947
|
+
return { declaration, signature };
|
|
948
|
+
}
|
|
949
|
+
function verifyTaxDeclarationSignature(declaration, signature, expectedAddress) {
|
|
950
|
+
const message = { ...declaration, validUntil: BigInt(declaration.validUntil) };
|
|
951
|
+
const digest = viem.hashTypedData({
|
|
952
|
+
domain: TAX_DECLARATION_DOMAIN,
|
|
953
|
+
types: TAX_DECLARATION_TYPES,
|
|
954
|
+
primaryType: TAX_DECLARATION_PRIMARY_TYPE,
|
|
955
|
+
message
|
|
956
|
+
});
|
|
957
|
+
return verifySignature(digest, signature, expectedAddress);
|
|
958
|
+
}
|
|
959
|
+
function encodeTaxDeclarationHeader(result) {
|
|
960
|
+
const json = JSON.stringify({ ...result.declaration, signature: result.signature });
|
|
961
|
+
return base64Url(json);
|
|
962
|
+
}
|
|
963
|
+
function base64Url(value) {
|
|
964
|
+
const standard = typeof Buffer !== "undefined" ? Buffer.from(value, "utf8").toString("base64") : btoa(String.fromCharCode(...new TextEncoder().encode(value)));
|
|
965
|
+
return standard.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
966
|
+
}
|
|
967
|
+
function addressFromKeyForTax(delegateKey) {
|
|
968
|
+
try {
|
|
969
|
+
return addressFromKey(delegateKey);
|
|
970
|
+
} catch (err) {
|
|
971
|
+
throw new chunkSZHKBOCZ_cjs.HavenSigningError(
|
|
972
|
+
`Invalid delegate key for tax declaration signing: ${err instanceof Error ? err.message : String(err)}`
|
|
973
|
+
);
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
var TaxDeclarationRefusedError = class extends chunkSZHKBOCZ_cjs.HavenSigningError {
|
|
977
|
+
code = "TAX_DECLARATION_REFUSED";
|
|
978
|
+
constructor(message) {
|
|
979
|
+
super(message);
|
|
980
|
+
this.name = "TaxDeclarationRefusedError";
|
|
981
|
+
}
|
|
982
|
+
};
|
|
810
983
|
|
|
811
984
|
// src/next-step.ts
|
|
812
985
|
var NEXT_TOOL_SERVER_NAMES = {
|
|
@@ -1232,8 +1405,12 @@ exports.SWEEP_BASE_CHAIN_ID = SWEEP_BASE_CHAIN_ID;
|
|
|
1232
1405
|
exports.SWEEP_BASE_SEPOLIA_CHAIN_ID = SWEEP_BASE_SEPOLIA_CHAIN_ID;
|
|
1233
1406
|
exports.SWEEP_BASE_SEPOLIA_USDC_ADDRESS = SWEEP_BASE_SEPOLIA_USDC_ADDRESS;
|
|
1234
1407
|
exports.SWEEP_BASE_USDC_ADDRESS = SWEEP_BASE_USDC_ADDRESS;
|
|
1408
|
+
exports.TAX_DECLARATION_DOMAIN = TAX_DECLARATION_DOMAIN;
|
|
1409
|
+
exports.TAX_DECLARATION_PRIMARY_TYPE = TAX_DECLARATION_PRIMARY_TYPE;
|
|
1410
|
+
exports.TAX_DECLARATION_TYPES = TAX_DECLARATION_TYPES;
|
|
1235
1411
|
exports.TRANSFER_WITH_AUTHORIZATION_TYPES = TRANSFER_WITH_AUTHORIZATION_TYPES;
|
|
1236
1412
|
exports.TYPED_DATA_NOT_ALLOWED = TYPED_DATA_NOT_ALLOWED;
|
|
1413
|
+
exports.TaxDeclarationRefusedError = TaxDeclarationRefusedError;
|
|
1237
1414
|
exports.X402PaymentHeaderValidationError = X402PaymentHeaderValidationError;
|
|
1238
1415
|
exports.X402_LEGACY_PAYMENT_HEADER_NAME = X402_LEGACY_PAYMENT_HEADER_NAME;
|
|
1239
1416
|
exports.X402_MAX_AUTHORIZATION_WINDOW_SECONDS = X402_MAX_AUTHORIZATION_WINDOW_SECONDS;
|
|
@@ -1243,11 +1420,14 @@ exports.X402_PAYMENT_HEADER_NAMES_SENT = X402_PAYMENT_HEADER_NAMES_SENT;
|
|
|
1243
1420
|
exports.X402_PAYMENT_REQUIRED_HEADER_NAME = X402_PAYMENT_REQUIRED_HEADER_NAME;
|
|
1244
1421
|
exports.X402_PAYMENT_RESPONSE_HEADER_NAME = X402_PAYMENT_RESPONSE_HEADER_NAME;
|
|
1245
1422
|
exports.X402_SETTLEMENT_FORWARD_MARGIN_SECONDS = X402_SETTLEMENT_FORWARD_MARGIN_SECONDS;
|
|
1423
|
+
exports.X_TAX_DECLARATION_HEADER = X_TAX_DECLARATION_HEADER;
|
|
1424
|
+
exports.addressFromKey = addressFromKey;
|
|
1246
1425
|
exports.assertBoundDirectPaymentUserOp = assertBoundDirectPaymentUserOp;
|
|
1247
1426
|
exports.assertFundingLegPaysDelegate = assertFundingLegPaysDelegate;
|
|
1248
1427
|
exports.assertOwnSettlementChild = assertOwnSettlementChild;
|
|
1249
1428
|
exports.assertOwnTaskBudgetCloseUserOp = assertOwnTaskBudgetCloseUserOp;
|
|
1250
1429
|
exports.assertOwnTaskChild = assertOwnTaskChild;
|
|
1430
|
+
exports.buildSignedTaxDeclaration = buildSignedTaxDeclaration;
|
|
1251
1431
|
exports.buildSweepAuthorizationMessage = buildSweepAuthorizationMessage;
|
|
1252
1432
|
exports.buildSweepTypedData = buildSweepTypedData;
|
|
1253
1433
|
exports.buildX402ExpectedMessage = buildX402ExpectedMessage;
|
|
@@ -1260,6 +1440,7 @@ exports.defaultNextToolFor = defaultNextToolFor;
|
|
|
1260
1440
|
exports.encodeBase64Json = encodeBase64Json;
|
|
1261
1441
|
exports.encodeBase64Utf8 = encodeBase64Utf8;
|
|
1262
1442
|
exports.encodePaymentProof = encodePaymentProof;
|
|
1443
|
+
exports.encodeTaxDeclarationHeader = encodeTaxDeclarationHeader;
|
|
1263
1444
|
exports.hashDelegation = hashDelegation;
|
|
1264
1445
|
exports.havenClientIdentity = havenClientIdentity;
|
|
1265
1446
|
exports.isErc7710Option = isErc7710Option;
|
|
@@ -1270,6 +1451,7 @@ exports.normalizePaymentRequired = normalizePaymentRequired;
|
|
|
1270
1451
|
exports.parseNextTool = parseNextTool;
|
|
1271
1452
|
exports.parsePaymentRequired = parsePaymentRequired;
|
|
1272
1453
|
exports.parsePaymentRequiredResponse = parsePaymentRequiredResponse;
|
|
1454
|
+
exports.principalAttributionHash = principalAttributionHash;
|
|
1273
1455
|
exports.readClientUpdate = readClientUpdate;
|
|
1274
1456
|
exports.renderNextTool = renderNextTool;
|
|
1275
1457
|
exports.resolveTokenBySymbol = resolveTokenBySymbol;
|
|
@@ -1278,16 +1460,20 @@ exports.selectErc7710PaymentOption = selectErc7710PaymentOption;
|
|
|
1278
1460
|
exports.selectPaymentOption = selectPaymentOption;
|
|
1279
1461
|
exports.selectStandardPaymentOption = selectStandardPaymentOption;
|
|
1280
1462
|
exports.selectX402SettlementScheme = selectX402SettlementScheme;
|
|
1463
|
+
exports.signHash = signHash;
|
|
1281
1464
|
exports.sweepUsdcAddress = sweepUsdcAddress;
|
|
1282
1465
|
exports.sweepUsdcDomain = sweepUsdcDomain;
|
|
1466
|
+
exports.taxPrincipalId = taxPrincipalId;
|
|
1283
1467
|
exports.toStandardPaymentRequirements = toStandardPaymentRequirements;
|
|
1284
1468
|
exports.unsupportedNodeVersionMessage = unsupportedNodeVersionMessage;
|
|
1285
1469
|
exports.validateStandardX402PaymentHeader = validateStandardX402PaymentHeader;
|
|
1470
|
+
exports.verifySignature = verifySignature;
|
|
1471
|
+
exports.verifyTaxDeclarationSignature = verifyTaxDeclarationSignature;
|
|
1286
1472
|
exports.x402AssetTransferMethod = x402AssetTransferMethod;
|
|
1287
1473
|
exports.x402AuthorizationAmount = x402AuthorizationAmount;
|
|
1288
1474
|
exports.x402FacilitatorAddresses = x402FacilitatorAddresses;
|
|
1289
1475
|
exports.x402PaymentHeaderNamesFor = x402PaymentHeaderNamesFor;
|
|
1290
1476
|
exports.x402PaymentHeaderNamesSent = x402PaymentHeaderNamesSent;
|
|
1291
1477
|
exports.x402V2PaymentEnvelope = x402V2PaymentEnvelope;
|
|
1292
|
-
//# sourceMappingURL=chunk-
|
|
1293
|
-
//# sourceMappingURL=chunk-
|
|
1478
|
+
//# sourceMappingURL=chunk-J6SS36ZD.cjs.map
|
|
1479
|
+
//# sourceMappingURL=chunk-J6SS36ZD.cjs.map
|