@agirails/sdk 2.2.0 → 2.2.2
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/ACTPClient.d.ts +200 -0
- package/dist/ACTPClient.d.ts.map +1 -1
- package/dist/ACTPClient.js +266 -2
- package/dist/ACTPClient.js.map +1 -1
- package/dist/abi/ACTPKernel.json +16 -0
- package/dist/adapters/AdapterRegistry.d.ts +140 -0
- package/dist/adapters/AdapterRegistry.d.ts.map +1 -0
- package/dist/adapters/AdapterRegistry.js +166 -0
- package/dist/adapters/AdapterRegistry.js.map +1 -0
- package/dist/adapters/AdapterRouter.d.ts +165 -0
- package/dist/adapters/AdapterRouter.d.ts.map +1 -0
- package/dist/adapters/AdapterRouter.js +350 -0
- package/dist/adapters/AdapterRouter.js.map +1 -0
- package/dist/adapters/BaseAdapter.d.ts +17 -0
- package/dist/adapters/BaseAdapter.d.ts.map +1 -1
- package/dist/adapters/BaseAdapter.js +21 -0
- package/dist/adapters/BaseAdapter.js.map +1 -1
- package/dist/adapters/BasicAdapter.d.ts +72 -3
- package/dist/adapters/BasicAdapter.d.ts.map +1 -1
- package/dist/adapters/BasicAdapter.js +170 -2
- package/dist/adapters/BasicAdapter.js.map +1 -1
- package/dist/adapters/IAdapter.d.ts +230 -0
- package/dist/adapters/IAdapter.d.ts.map +1 -0
- package/dist/adapters/IAdapter.js +44 -0
- package/dist/adapters/IAdapter.js.map +1 -0
- package/dist/adapters/StandardAdapter.d.ts +70 -1
- package/dist/adapters/StandardAdapter.d.ts.map +1 -1
- package/dist/adapters/StandardAdapter.js +184 -0
- package/dist/adapters/StandardAdapter.js.map +1 -1
- package/dist/adapters/X402Adapter.d.ts +208 -0
- package/dist/adapters/X402Adapter.d.ts.map +1 -0
- package/dist/adapters/X402Adapter.js +423 -0
- package/dist/adapters/X402Adapter.js.map +1 -0
- package/dist/adapters/index.d.ts +8 -0
- package/dist/adapters/index.d.ts.map +1 -1
- package/dist/adapters/index.js +19 -1
- package/dist/adapters/index.js.map +1 -1
- package/dist/cli/commands/init.d.ts +4 -0
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +184 -4
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/config/networks.js +3 -3
- package/dist/config/networks.js.map +1 -1
- package/dist/erc8004/ERC8004Bridge.d.ts +155 -0
- package/dist/erc8004/ERC8004Bridge.d.ts.map +1 -0
- package/dist/erc8004/ERC8004Bridge.js +325 -0
- package/dist/erc8004/ERC8004Bridge.js.map +1 -0
- package/dist/erc8004/ReputationReporter.d.ts +223 -0
- package/dist/erc8004/ReputationReporter.d.ts.map +1 -0
- package/dist/erc8004/ReputationReporter.js +266 -0
- package/dist/erc8004/ReputationReporter.js.map +1 -0
- package/dist/erc8004/index.d.ts +36 -0
- package/dist/erc8004/index.d.ts.map +1 -0
- package/dist/erc8004/index.js +46 -0
- package/dist/erc8004/index.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -2
- package/dist/index.js.map +1 -1
- package/dist/protocol/ACTPKernel.d.ts +1 -1
- package/dist/protocol/ACTPKernel.d.ts.map +1 -1
- package/dist/protocol/ACTPKernel.js +16 -7
- package/dist/protocol/ACTPKernel.js.map +1 -1
- package/dist/runtime/BlockchainRuntime.d.ts.map +1 -1
- package/dist/runtime/BlockchainRuntime.js +2 -0
- package/dist/runtime/BlockchainRuntime.js.map +1 -1
- package/dist/runtime/IACTPRuntime.d.ts +6 -0
- package/dist/runtime/IACTPRuntime.d.ts.map +1 -1
- package/dist/runtime/MockRuntime.d.ts +12 -0
- package/dist/runtime/MockRuntime.d.ts.map +1 -1
- package/dist/runtime/MockRuntime.js +41 -0
- package/dist/runtime/MockRuntime.js.map +1 -1
- package/dist/runtime/types/MockState.d.ts +6 -0
- package/dist/runtime/types/MockState.d.ts.map +1 -1
- package/dist/runtime/types/MockState.js.map +1 -1
- package/dist/types/adapter.d.ts +359 -0
- package/dist/types/adapter.d.ts.map +1 -0
- package/dist/types/adapter.js +115 -0
- package/dist/types/adapter.js.map +1 -0
- package/dist/types/erc8004.d.ts +184 -0
- package/dist/types/erc8004.d.ts.map +1 -0
- package/dist/types/erc8004.js +132 -0
- package/dist/types/erc8004.js.map +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/transaction.d.ts +12 -0
- package/dist/types/transaction.d.ts.map +1 -1
- package/dist/types/x402.d.ts +162 -0
- package/dist/types/x402.d.ts.map +1 -0
- package/dist/types/x402.js +162 -0
- package/dist/types/x402.js.map +1 -0
- package/package.json +3 -2
- package/src/ACTPClient.ts +318 -2
- package/src/abi/ACTPKernel.json +16 -0
- package/src/adapters/AdapterRegistry.ts +173 -0
- package/src/adapters/AdapterRouter.ts +417 -0
- package/src/adapters/BaseAdapter.ts +25 -0
- package/src/adapters/BasicAdapter.ts +199 -3
- package/src/adapters/IAdapter.ts +292 -0
- package/src/adapters/StandardAdapter.ts +220 -1
- package/src/adapters/X402Adapter.ts +653 -0
- package/src/adapters/index.ts +27 -0
- package/src/cli/commands/init.ts +208 -3
- package/src/config/networks.ts +3 -3
- package/src/erc8004/ERC8004Bridge.ts +461 -0
- package/src/erc8004/ReputationReporter.ts +472 -0
- package/src/erc8004/index.ts +61 -0
- package/src/index.ts +43 -0
- package/src/protocol/ACTPKernel.ts +26 -7
- package/src/runtime/BlockchainRuntime.ts +2 -0
- package/src/runtime/IACTPRuntime.ts +6 -0
- package/src/runtime/MockRuntime.ts +42 -0
- package/src/runtime/types/MockState.ts +7 -0
- package/src/types/adapter.ts +296 -0
- package/src/types/erc8004.ts +293 -0
- package/src/types/index.ts +3 -0
- package/src/types/transaction.ts +12 -0
- package/src/types/x402.ts +219 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* ERC-8004 Trustless Agents - SDK Types
|
|
4
|
+
*
|
|
5
|
+
* Types and constants for ERC-8004 integration.
|
|
6
|
+
*
|
|
7
|
+
* SECURITY NOTES:
|
|
8
|
+
* - Identity Registry is read-only (safe, no gas)
|
|
9
|
+
* - Reputation Registry writes require gas (requester pays)
|
|
10
|
+
* - Replay protection via feedbackHash = keccak256(txId)
|
|
11
|
+
* - ERC-8004 restriction: feedback submitter ≠ agent owner
|
|
12
|
+
*
|
|
13
|
+
* @see https://eips.ethereum.org/EIPS/eip-8004
|
|
14
|
+
* @module types/erc8004
|
|
15
|
+
*/
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.ACTP_FEEDBACK_TAGS = exports.ERC8004_DEFAULT_RPC = exports.ERC8004_REPUTATION_ABI = exports.ERC8004_IDENTITY_ABI = exports.ERC8004_REPUTATION_REGISTRY = exports.ERC8004_IDENTITY_REGISTRY = exports.ERC8004Error = exports.ERC8004ErrorCode = void 0;
|
|
18
|
+
// ============================================================================
|
|
19
|
+
// Errors
|
|
20
|
+
// ============================================================================
|
|
21
|
+
/**
|
|
22
|
+
* ERC-8004 error codes.
|
|
23
|
+
*/
|
|
24
|
+
var ERC8004ErrorCode;
|
|
25
|
+
(function (ERC8004ErrorCode) {
|
|
26
|
+
// Identity errors
|
|
27
|
+
ERC8004ErrorCode["AGENT_NOT_FOUND"] = "AGENT_NOT_FOUND";
|
|
28
|
+
ERC8004ErrorCode["INVALID_AGENT_ID"] = "INVALID_AGENT_ID";
|
|
29
|
+
ERC8004ErrorCode["WALLET_NOT_FOUND"] = "WALLET_NOT_FOUND";
|
|
30
|
+
ERC8004ErrorCode["METADATA_FETCH_FAILED"] = "METADATA_FETCH_FAILED";
|
|
31
|
+
// Reputation errors
|
|
32
|
+
ERC8004ErrorCode["REPORT_FAILED"] = "REPORT_FAILED";
|
|
33
|
+
ERC8004ErrorCode["ALREADY_REPORTED"] = "ALREADY_REPORTED";
|
|
34
|
+
ERC8004ErrorCode["NOT_AUTHORIZED"] = "NOT_AUTHORIZED";
|
|
35
|
+
// Network errors
|
|
36
|
+
ERC8004ErrorCode["NETWORK_ERROR"] = "NETWORK_ERROR";
|
|
37
|
+
ERC8004ErrorCode["INVALID_NETWORK"] = "INVALID_NETWORK";
|
|
38
|
+
})(ERC8004ErrorCode || (exports.ERC8004ErrorCode = ERC8004ErrorCode = {}));
|
|
39
|
+
/**
|
|
40
|
+
* Custom error for ERC-8004 operations.
|
|
41
|
+
*/
|
|
42
|
+
class ERC8004Error extends Error {
|
|
43
|
+
constructor(message, code, agentId, cause) {
|
|
44
|
+
super(message);
|
|
45
|
+
this.code = code;
|
|
46
|
+
this.agentId = agentId;
|
|
47
|
+
this.cause = cause;
|
|
48
|
+
this.name = 'ERC8004Error';
|
|
49
|
+
// Maintain proper stack trace in V8
|
|
50
|
+
if (Error.captureStackTrace) {
|
|
51
|
+
Error.captureStackTrace(this, ERC8004Error);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.ERC8004Error = ERC8004Error;
|
|
56
|
+
// ============================================================================
|
|
57
|
+
// Registry Addresses
|
|
58
|
+
// ============================================================================
|
|
59
|
+
/**
|
|
60
|
+
* ERC-8004 Identity Registry addresses per network.
|
|
61
|
+
*
|
|
62
|
+
* Canonical CREATE2 addresses from: https://github.com/erc-8004/erc-8004-contracts
|
|
63
|
+
* Vanity prefix 0x8004 ensures same address across all EVM chains.
|
|
64
|
+
*/
|
|
65
|
+
exports.ERC8004_IDENTITY_REGISTRY = {
|
|
66
|
+
ethereum: '0x8004A169FB4a3325136EB29fA0ceB6D2e539a432', // Ethereum Mainnet
|
|
67
|
+
base: '0x8004A169FB4a3325136EB29fA0ceB6D2e539a432', // Base Mainnet
|
|
68
|
+
'base-sepolia': '0x8004A818BFB912233c491871b3d84c89A494BD9e', // Base Sepolia
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* ERC-8004 Reputation Registry addresses per network.
|
|
72
|
+
*
|
|
73
|
+
* Canonical CREATE2 addresses from: https://github.com/erc-8004/erc-8004-contracts
|
|
74
|
+
* Vanity prefix 0x8004 ensures same address across all EVM chains.
|
|
75
|
+
*/
|
|
76
|
+
exports.ERC8004_REPUTATION_REGISTRY = {
|
|
77
|
+
ethereum: '0x8004BAa17C55a88189AE136b182e5fdA19dE9b63', // Ethereum Mainnet
|
|
78
|
+
base: '0x8004BAa17C55a88189AE136b182e5fdA19dE9b63', // Base Mainnet
|
|
79
|
+
'base-sepolia': '0x8004B663056A597Dffe9eCcC1965A193B7388713', // Base Sepolia
|
|
80
|
+
};
|
|
81
|
+
// ============================================================================
|
|
82
|
+
// ABI Fragments (minimal, view-only for Bridge)
|
|
83
|
+
// ============================================================================
|
|
84
|
+
/**
|
|
85
|
+
* Minimal ABI for ERC-8004 Identity Registry.
|
|
86
|
+
* Only includes view functions needed by ERC8004Bridge.
|
|
87
|
+
*/
|
|
88
|
+
exports.ERC8004_IDENTITY_ABI = [
|
|
89
|
+
'function ownerOf(uint256 agentId) view returns (address)',
|
|
90
|
+
'function getAgentURI(uint256 agentId) view returns (string)',
|
|
91
|
+
'function balanceOf(address owner) view returns (uint256)',
|
|
92
|
+
'function tokenOfOwnerByIndex(address owner, uint256 index) view returns (uint256)',
|
|
93
|
+
];
|
|
94
|
+
/**
|
|
95
|
+
* Minimal ABI for ERC-8004 Reputation Registry.
|
|
96
|
+
* Includes both read and write functions.
|
|
97
|
+
*/
|
|
98
|
+
exports.ERC8004_REPUTATION_ABI = [
|
|
99
|
+
// Write
|
|
100
|
+
'function giveFeedback(uint256 agentId, int128 value, uint8 valueDecimals, string tag1, string tag2, string endpoint, string feedbackURI, bytes32 feedbackHash) external',
|
|
101
|
+
'function revokeLatest(uint256 agentId, uint64 feedbackIndex) external',
|
|
102
|
+
// Read
|
|
103
|
+
'function getSummary(uint256 agentId, address[] clientAddresses, string tag1, string tag2) view returns (uint256 count, int256 summaryValue, uint8 summaryValueDecimals)',
|
|
104
|
+
'function readFeedback(uint256 agentId, uint64 feedbackIndex) view returns (tuple(int128 value, uint8 valueDecimals, string tag1, string tag2, bool isRevoked, uint64 feedbackIndex))',
|
|
105
|
+
];
|
|
106
|
+
// ============================================================================
|
|
107
|
+
// Default RPC URLs
|
|
108
|
+
// ============================================================================
|
|
109
|
+
/**
|
|
110
|
+
* Default RPC URLs for each network.
|
|
111
|
+
* Used when no custom RPC is provided.
|
|
112
|
+
*/
|
|
113
|
+
exports.ERC8004_DEFAULT_RPC = {
|
|
114
|
+
ethereum: 'https://eth.llamarpc.com',
|
|
115
|
+
base: 'https://mainnet.base.org',
|
|
116
|
+
'base-sepolia': 'https://sepolia.base.org',
|
|
117
|
+
};
|
|
118
|
+
// ============================================================================
|
|
119
|
+
// ACTP-specific constants
|
|
120
|
+
// ============================================================================
|
|
121
|
+
/**
|
|
122
|
+
* ACTP feedback tags for ERC-8004 Reputation.
|
|
123
|
+
*/
|
|
124
|
+
exports.ACTP_FEEDBACK_TAGS = {
|
|
125
|
+
/** Successful settlement */
|
|
126
|
+
SETTLED: 'actp_settled',
|
|
127
|
+
/** Agent won dispute */
|
|
128
|
+
DISPUTE_WON: 'actp_dispute_won',
|
|
129
|
+
/** Agent lost dispute (requester won) */
|
|
130
|
+
DISPUTE_LOST: 'actp_dispute_lost',
|
|
131
|
+
};
|
|
132
|
+
//# sourceMappingURL=erc8004.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"erc8004.js","sourceRoot":"","sources":["../../src/types/erc8004.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;;AAgJH,+EAA+E;AAC/E,SAAS;AACT,+EAA+E;AAE/E;;GAEG;AACH,IAAY,gBAeX;AAfD,WAAY,gBAAgB;IAC1B,kBAAkB;IAClB,uDAAmC,CAAA;IACnC,yDAAqC,CAAA;IACrC,yDAAqC,CAAA;IACrC,mEAA+C,CAAA;IAE/C,oBAAoB;IACpB,mDAA+B,CAAA;IAC/B,yDAAqC,CAAA;I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K,sLAAsL;CAC9K,CAAC;AAEX,+EAA+E;AAC/E,mBAAmB;AACnB,+EAA+E;AAE/E;;;GAGG;AACU,QAAA,mBAAmB,GAAmC;IACjE,QAAQ,EAAE,0BAA0B;IACpC,IAAI,EAAE,0BAA0B;IAChC,cAAc,EAAE,0BAA0B;CAC3C,CAAC;AAEF,+EAA+E;AAC/E,0BAA0B;AAC1B,+EAA+E;AAE/E;;GAEG;AACU,QAAA,kBAAkB,GAAG;IAChC,4BAA4B;IAC5B,OAAO,EAAE,cAAc;IAEvB,wBAAwB;IACxB,WAAW,EAAE,kBAAkB;IAE/B,yCAAyC;IACzC,YAAY,EAAE,mBAAmB;CACzB,CAAC"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,OAAO,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,OAAO,CAAC;AACtB,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC"}
|
package/dist/types/index.js
CHANGED
|
@@ -24,6 +24,9 @@ __exportStar(require("./message"), exports);
|
|
|
24
24
|
__exportStar(require("./eip712"), exports);
|
|
25
25
|
__exportStar(require("./agent"), exports);
|
|
26
26
|
__exportStar(require("./did"), exports);
|
|
27
|
+
__exportStar(require("./adapter"), exports);
|
|
28
|
+
__exportStar(require("./x402"), exports);
|
|
29
|
+
__exportStar(require("./erc8004"), exports);
|
|
27
30
|
// Note: storage and archive types are not yet implemented in this version
|
|
28
31
|
// export * from './storage';
|
|
29
32
|
// export * from './archive';
|
package/dist/types/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;AAEH,0CAAwB;AACxB,gDAA8B;AAC9B,2CAAyB;AACzB,4CAA0B;AAC1B,2CAAyB;AACzB,0CAAwB;AACxB,wCAAsB;AACtB,0EAA0E;AAC1E,6BAA6B;AAC7B,6BAA6B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;AAEH,0CAAwB;AACxB,gDAA8B;AAC9B,2CAAyB;AACzB,4CAA0B;AAC1B,2CAAyB;AACzB,0CAAwB;AACxB,wCAAsB;AACtB,4CAA0B;AAC1B,yCAAuB;AACvB,4CAA0B;AAC1B,0EAA0E;AAC1E,6BAA6B;AAC7B,6BAA6B"}
|
|
@@ -19,6 +19,12 @@ export interface Transaction {
|
|
|
19
19
|
attestationUID: string;
|
|
20
20
|
metadata: string;
|
|
21
21
|
platformFeeBpsLocked: number;
|
|
22
|
+
/**
|
|
23
|
+
* ERC-8004 agent token ID (optional).
|
|
24
|
+
* 0 or undefined = not an ERC-8004 agent.
|
|
25
|
+
* See ADR-001 for architectural rationale.
|
|
26
|
+
*/
|
|
27
|
+
agentId?: string;
|
|
22
28
|
}
|
|
23
29
|
/**
|
|
24
30
|
* Parameters for creating a new transaction
|
|
@@ -30,6 +36,12 @@ export interface CreateTransactionParams {
|
|
|
30
36
|
deadline: number;
|
|
31
37
|
disputeWindow: number;
|
|
32
38
|
metadata?: string;
|
|
39
|
+
/**
|
|
40
|
+
* ERC-8004 agent token ID (optional).
|
|
41
|
+
* Set to 0 or omit if provider is not registered in ERC-8004 Identity Registry.
|
|
42
|
+
* See ADR-001 for architectural rationale.
|
|
43
|
+
*/
|
|
44
|
+
agentId?: string;
|
|
33
45
|
}
|
|
34
46
|
/**
|
|
35
47
|
* Dispute resolution split
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../../src/types/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,KAAK,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,oBAAoB,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../../src/types/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,KAAK,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,oBAAoB,EAAE,MAAM,CAAC;IAC7B;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,gBAAgB,EAAE,MAAM,CAAC;IACzB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,YAAY,EAAE,MAAM,CAAC;IACrB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,kBAAkB,EAAE,MAAM,CAAC;CAC5B"}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* X402 Protocol Types and Constants
|
|
3
|
+
*
|
|
4
|
+
* Defines types for the HTTP 402 Payment Required protocol implementation.
|
|
5
|
+
* X402 enables atomic, instant API payments - NO escrow, NO state machine.
|
|
6
|
+
*
|
|
7
|
+
* Key difference from ACTP:
|
|
8
|
+
* - ACTP: escrow → state machine → disputes → explicit release
|
|
9
|
+
* - x402: atomic payment → instant settlement → done
|
|
10
|
+
*
|
|
11
|
+
* Flow:
|
|
12
|
+
* 1. Client requests protected HTTPS endpoint → gets 402 response
|
|
13
|
+
* 2. Parse X-Payment-* headers (address, amount, network, deadline)
|
|
14
|
+
* 3. Execute atomic USDC transfer to provider (no escrow!)
|
|
15
|
+
* 4. Retry request with tx hash as proof
|
|
16
|
+
* 5. Return response - payment complete, no release needed
|
|
17
|
+
*
|
|
18
|
+
* Use x402 for: Simple API calls, instant delivery, low-value transactions
|
|
19
|
+
* Use ACTP for: Complex services, dispute protection, high-value transactions
|
|
20
|
+
*
|
|
21
|
+
* @module types/x402
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* Standard X402 payment headers sent in 402 responses.
|
|
25
|
+
*
|
|
26
|
+
* These headers inform the client how to pay for the requested resource.
|
|
27
|
+
*/
|
|
28
|
+
export declare const X402_HEADERS: {
|
|
29
|
+
/** Indicates payment is required (must be "true") */
|
|
30
|
+
readonly REQUIRED: "x-payment-required";
|
|
31
|
+
/** Provider's wallet address (0x-prefixed) */
|
|
32
|
+
readonly ADDRESS: "x-payment-address";
|
|
33
|
+
/** Amount in USDC wei (6 decimals) */
|
|
34
|
+
readonly AMOUNT: "x-payment-amount";
|
|
35
|
+
/** Network identifier (base-mainnet or base-sepolia) */
|
|
36
|
+
readonly NETWORK: "x-payment-network";
|
|
37
|
+
/** Token type (currently only USDC) */
|
|
38
|
+
readonly TOKEN: "x-payment-token";
|
|
39
|
+
/** Unix timestamp deadline for payment */
|
|
40
|
+
readonly DEADLINE: "x-payment-deadline";
|
|
41
|
+
/** Optional: Dispute window in seconds */
|
|
42
|
+
readonly DISPUTE_WINDOW: "x-dispute-window";
|
|
43
|
+
/** Optional: Service identifier for tracking */
|
|
44
|
+
readonly SERVICE_ID: "x-service-id";
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Proof headers sent when retrying with payment.
|
|
48
|
+
*
|
|
49
|
+
* After creating an ACTP transaction, the client includes these
|
|
50
|
+
* headers to prove payment was made.
|
|
51
|
+
*/
|
|
52
|
+
export declare const X402_PROOF_HEADERS: {
|
|
53
|
+
/** ACTP transaction ID (bytes32 hex) */
|
|
54
|
+
readonly TX_ID: "x-payment-tx-id";
|
|
55
|
+
/** ACTP escrow ID (bytes32 hex) */
|
|
56
|
+
readonly ESCROW_ID: "x-payment-escrow-id";
|
|
57
|
+
};
|
|
58
|
+
/** Supported networks for x402 payments */
|
|
59
|
+
export type X402Network = 'base-mainnet' | 'base-sepolia';
|
|
60
|
+
/** Supported tokens (currently only USDC) */
|
|
61
|
+
export type X402Token = 'USDC';
|
|
62
|
+
/**
|
|
63
|
+
* Parsed payment headers from HTTP 402 response.
|
|
64
|
+
*
|
|
65
|
+
* Contains all information needed to create an ACTP transaction
|
|
66
|
+
* for the requested resource.
|
|
67
|
+
*/
|
|
68
|
+
export interface X402PaymentHeaders {
|
|
69
|
+
/** Whether payment is required (always true for valid 402) */
|
|
70
|
+
required: boolean;
|
|
71
|
+
/** Provider's wallet address (0x-prefixed, 42 chars) */
|
|
72
|
+
paymentAddress: string;
|
|
73
|
+
/** Amount in USDC wei (6 decimals, as string) */
|
|
74
|
+
amount: string;
|
|
75
|
+
/** Target network */
|
|
76
|
+
network: X402Network;
|
|
77
|
+
/** Token type */
|
|
78
|
+
token: X402Token;
|
|
79
|
+
/** Unix timestamp deadline for accepting payment */
|
|
80
|
+
deadline: number;
|
|
81
|
+
/** Optional: Dispute window in seconds */
|
|
82
|
+
disputeWindow?: number;
|
|
83
|
+
/** Optional: Service identifier for tracking/debugging */
|
|
84
|
+
serviceId?: string;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Error codes for X402 protocol failures.
|
|
88
|
+
*
|
|
89
|
+
* Used to identify specific error types and enable proper error handling.
|
|
90
|
+
*/
|
|
91
|
+
export declare enum X402ErrorCode {
|
|
92
|
+
/** Response status was not 402 */
|
|
93
|
+
NOT_402_RESPONSE = "NOT_402_RESPONSE",
|
|
94
|
+
/** Required X-Payment-* headers are missing */
|
|
95
|
+
MISSING_HEADERS = "MISSING_HEADERS",
|
|
96
|
+
/** X-Payment-Amount is invalid (not a number, negative, etc.) */
|
|
97
|
+
INVALID_AMOUNT = "INVALID_AMOUNT",
|
|
98
|
+
/** X-Payment-Address is not a valid Ethereum address */
|
|
99
|
+
INVALID_ADDRESS = "INVALID_ADDRESS",
|
|
100
|
+
/** X-Payment-Network is not a recognized network */
|
|
101
|
+
INVALID_NETWORK = "INVALID_NETWORK",
|
|
102
|
+
/** Server's network doesn't match client's expected network */
|
|
103
|
+
NETWORK_MISMATCH = "NETWORK_MISMATCH",
|
|
104
|
+
/** Failed to create ACTP transaction or link escrow */
|
|
105
|
+
PAYMENT_FAILED = "PAYMENT_FAILED",
|
|
106
|
+
/** Retry request with proof headers failed */
|
|
107
|
+
RETRY_FAILED = "RETRY_FAILED",
|
|
108
|
+
/** X-Payment-Deadline has already passed */
|
|
109
|
+
DEADLINE_PASSED = "DEADLINE_PASSED",
|
|
110
|
+
/** HTTPS protocol required but HTTP used */
|
|
111
|
+
INSECURE_PROTOCOL = "INSECURE_PROTOCOL"
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Custom error for X402 protocol failures.
|
|
115
|
+
*
|
|
116
|
+
* Provides structured error information for debugging and error handling.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```typescript
|
|
120
|
+
* try {
|
|
121
|
+
* await x402Adapter.pay({ to: 'https://api.example.com', amount: '10' });
|
|
122
|
+
* } catch (error) {
|
|
123
|
+
* if (error instanceof X402Error) {
|
|
124
|
+
* if (error.code === X402ErrorCode.NETWORK_MISMATCH) {
|
|
125
|
+
* console.error('Wrong network:', error.message);
|
|
126
|
+
* }
|
|
127
|
+
* }
|
|
128
|
+
* }
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
export declare class X402Error extends Error {
|
|
132
|
+
readonly code: X402ErrorCode;
|
|
133
|
+
readonly response?: Response | undefined;
|
|
134
|
+
readonly name = "X402Error";
|
|
135
|
+
/**
|
|
136
|
+
* Creates a new X402Error.
|
|
137
|
+
*
|
|
138
|
+
* @param message - Human-readable error message
|
|
139
|
+
* @param code - Error code for programmatic handling
|
|
140
|
+
* @param response - Optional HTTP response that triggered the error
|
|
141
|
+
*/
|
|
142
|
+
constructor(message: string, code: X402ErrorCode, response?: Response | undefined);
|
|
143
|
+
/**
|
|
144
|
+
* Creates a detailed error message with code.
|
|
145
|
+
*/
|
|
146
|
+
toString(): string;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Type guard to check if an error is an X402Error.
|
|
150
|
+
*
|
|
151
|
+
* @param error - Error to check
|
|
152
|
+
* @returns True if error is X402Error
|
|
153
|
+
*/
|
|
154
|
+
export declare function isX402Error(error: unknown): error is X402Error;
|
|
155
|
+
/**
|
|
156
|
+
* Validates that a network string is a valid X402Network.
|
|
157
|
+
*
|
|
158
|
+
* @param network - Network string to validate
|
|
159
|
+
* @returns True if valid X402Network
|
|
160
|
+
*/
|
|
161
|
+
export declare function isValidX402Network(network: string): network is X402Network;
|
|
162
|
+
//# sourceMappingURL=x402.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"x402.d.ts","sourceRoot":"","sources":["../../src/types/x402.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAMH;;;;GAIG;AACH,eAAO,MAAM,YAAY;IACvB,qDAAqD;;IAErD,8CAA8C;;IAE9C,sCAAsC;;IAEtC,wDAAwD;;IAExD,uCAAuC;;IAEvC,0CAA0C;;IAE1C,0CAA0C;;IAE1C,gDAAgD;;CAExC,CAAC;AAEX;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB;IAC7B,wCAAwC;;IAExC,mCAAmC;;CAE3B,CAAC;AAMX,2CAA2C;AAC3C,MAAM,MAAM,WAAW,GAAG,cAAc,GAAG,cAAc,CAAC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GAAG,KAAK,IAAI,SAAS,CAE9D;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,IAAI,WAAW,CAE1E"}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* X402 Protocol Types and Constants
|
|
4
|
+
*
|
|
5
|
+
* Defines types for the HTTP 402 Payment Required protocol implementation.
|
|
6
|
+
* X402 enables atomic, instant API payments - NO escrow, NO state machine.
|
|
7
|
+
*
|
|
8
|
+
* Key difference from ACTP:
|
|
9
|
+
* - ACTP: escrow → state machine → disputes → explicit release
|
|
10
|
+
* - x402: atomic payment → instant settlement → done
|
|
11
|
+
*
|
|
12
|
+
* Flow:
|
|
13
|
+
* 1. Client requests protected HTTPS endpoint → gets 402 response
|
|
14
|
+
* 2. Parse X-Payment-* headers (address, amount, network, deadline)
|
|
15
|
+
* 3. Execute atomic USDC transfer to provider (no escrow!)
|
|
16
|
+
* 4. Retry request with tx hash as proof
|
|
17
|
+
* 5. Return response - payment complete, no release needed
|
|
18
|
+
*
|
|
19
|
+
* Use x402 for: Simple API calls, instant delivery, low-value transactions
|
|
20
|
+
* Use ACTP for: Complex services, dispute protection, high-value transactions
|
|
21
|
+
*
|
|
22
|
+
* @module types/x402
|
|
23
|
+
*/
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.isValidX402Network = exports.isX402Error = exports.X402Error = exports.X402ErrorCode = exports.X402_PROOF_HEADERS = exports.X402_HEADERS = void 0;
|
|
26
|
+
// ============================================================================
|
|
27
|
+
// X402 Header Constants
|
|
28
|
+
// ============================================================================
|
|
29
|
+
/**
|
|
30
|
+
* Standard X402 payment headers sent in 402 responses.
|
|
31
|
+
*
|
|
32
|
+
* These headers inform the client how to pay for the requested resource.
|
|
33
|
+
*/
|
|
34
|
+
exports.X402_HEADERS = {
|
|
35
|
+
/** Indicates payment is required (must be "true") */
|
|
36
|
+
REQUIRED: 'x-payment-required',
|
|
37
|
+
/** Provider's wallet address (0x-prefixed) */
|
|
38
|
+
ADDRESS: 'x-payment-address',
|
|
39
|
+
/** Amount in USDC wei (6 decimals) */
|
|
40
|
+
AMOUNT: 'x-payment-amount',
|
|
41
|
+
/** Network identifier (base-mainnet or base-sepolia) */
|
|
42
|
+
NETWORK: 'x-payment-network',
|
|
43
|
+
/** Token type (currently only USDC) */
|
|
44
|
+
TOKEN: 'x-payment-token',
|
|
45
|
+
/** Unix timestamp deadline for payment */
|
|
46
|
+
DEADLINE: 'x-payment-deadline',
|
|
47
|
+
/** Optional: Dispute window in seconds */
|
|
48
|
+
DISPUTE_WINDOW: 'x-dispute-window',
|
|
49
|
+
/** Optional: Service identifier for tracking */
|
|
50
|
+
SERVICE_ID: 'x-service-id',
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Proof headers sent when retrying with payment.
|
|
54
|
+
*
|
|
55
|
+
* After creating an ACTP transaction, the client includes these
|
|
56
|
+
* headers to prove payment was made.
|
|
57
|
+
*/
|
|
58
|
+
exports.X402_PROOF_HEADERS = {
|
|
59
|
+
/** ACTP transaction ID (bytes32 hex) */
|
|
60
|
+
TX_ID: 'x-payment-tx-id',
|
|
61
|
+
/** ACTP escrow ID (bytes32 hex) */
|
|
62
|
+
ESCROW_ID: 'x-payment-escrow-id',
|
|
63
|
+
};
|
|
64
|
+
// ============================================================================
|
|
65
|
+
// X402 Error Handling
|
|
66
|
+
// ============================================================================
|
|
67
|
+
/**
|
|
68
|
+
* Error codes for X402 protocol failures.
|
|
69
|
+
*
|
|
70
|
+
* Used to identify specific error types and enable proper error handling.
|
|
71
|
+
*/
|
|
72
|
+
var X402ErrorCode;
|
|
73
|
+
(function (X402ErrorCode) {
|
|
74
|
+
/** Response status was not 402 */
|
|
75
|
+
X402ErrorCode["NOT_402_RESPONSE"] = "NOT_402_RESPONSE";
|
|
76
|
+
/** Required X-Payment-* headers are missing */
|
|
77
|
+
X402ErrorCode["MISSING_HEADERS"] = "MISSING_HEADERS";
|
|
78
|
+
/** X-Payment-Amount is invalid (not a number, negative, etc.) */
|
|
79
|
+
X402ErrorCode["INVALID_AMOUNT"] = "INVALID_AMOUNT";
|
|
80
|
+
/** X-Payment-Address is not a valid Ethereum address */
|
|
81
|
+
X402ErrorCode["INVALID_ADDRESS"] = "INVALID_ADDRESS";
|
|
82
|
+
/** X-Payment-Network is not a recognized network */
|
|
83
|
+
X402ErrorCode["INVALID_NETWORK"] = "INVALID_NETWORK";
|
|
84
|
+
/** Server's network doesn't match client's expected network */
|
|
85
|
+
X402ErrorCode["NETWORK_MISMATCH"] = "NETWORK_MISMATCH";
|
|
86
|
+
/** Failed to create ACTP transaction or link escrow */
|
|
87
|
+
X402ErrorCode["PAYMENT_FAILED"] = "PAYMENT_FAILED";
|
|
88
|
+
/** Retry request with proof headers failed */
|
|
89
|
+
X402ErrorCode["RETRY_FAILED"] = "RETRY_FAILED";
|
|
90
|
+
/** X-Payment-Deadline has already passed */
|
|
91
|
+
X402ErrorCode["DEADLINE_PASSED"] = "DEADLINE_PASSED";
|
|
92
|
+
/** HTTPS protocol required but HTTP used */
|
|
93
|
+
X402ErrorCode["INSECURE_PROTOCOL"] = "INSECURE_PROTOCOL";
|
|
94
|
+
})(X402ErrorCode || (exports.X402ErrorCode = X402ErrorCode = {}));
|
|
95
|
+
/**
|
|
96
|
+
* Custom error for X402 protocol failures.
|
|
97
|
+
*
|
|
98
|
+
* Provides structured error information for debugging and error handling.
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```typescript
|
|
102
|
+
* try {
|
|
103
|
+
* await x402Adapter.pay({ to: 'https://api.example.com', amount: '10' });
|
|
104
|
+
* } catch (error) {
|
|
105
|
+
* if (error instanceof X402Error) {
|
|
106
|
+
* if (error.code === X402ErrorCode.NETWORK_MISMATCH) {
|
|
107
|
+
* console.error('Wrong network:', error.message);
|
|
108
|
+
* }
|
|
109
|
+
* }
|
|
110
|
+
* }
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
class X402Error extends Error {
|
|
114
|
+
/**
|
|
115
|
+
* Creates a new X402Error.
|
|
116
|
+
*
|
|
117
|
+
* @param message - Human-readable error message
|
|
118
|
+
* @param code - Error code for programmatic handling
|
|
119
|
+
* @param response - Optional HTTP response that triggered the error
|
|
120
|
+
*/
|
|
121
|
+
constructor(message, code, response) {
|
|
122
|
+
super(message);
|
|
123
|
+
this.code = code;
|
|
124
|
+
this.response = response;
|
|
125
|
+
this.name = 'X402Error';
|
|
126
|
+
// Maintains proper stack trace in V8 environments
|
|
127
|
+
if (Error.captureStackTrace) {
|
|
128
|
+
Error.captureStackTrace(this, X402Error);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Creates a detailed error message with code.
|
|
133
|
+
*/
|
|
134
|
+
toString() {
|
|
135
|
+
return `X402Error [${this.code}]: ${this.message}`;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
exports.X402Error = X402Error;
|
|
139
|
+
// ============================================================================
|
|
140
|
+
// Type Guards
|
|
141
|
+
// ============================================================================
|
|
142
|
+
/**
|
|
143
|
+
* Type guard to check if an error is an X402Error.
|
|
144
|
+
*
|
|
145
|
+
* @param error - Error to check
|
|
146
|
+
* @returns True if error is X402Error
|
|
147
|
+
*/
|
|
148
|
+
function isX402Error(error) {
|
|
149
|
+
return error instanceof X402Error;
|
|
150
|
+
}
|
|
151
|
+
exports.isX402Error = isX402Error;
|
|
152
|
+
/**
|
|
153
|
+
* Validates that a network string is a valid X402Network.
|
|
154
|
+
*
|
|
155
|
+
* @param network - Network string to validate
|
|
156
|
+
* @returns True if valid X402Network
|
|
157
|
+
*/
|
|
158
|
+
function isValidX402Network(network) {
|
|
159
|
+
return network === 'base-mainnet' || network === 'base-sepolia';
|
|
160
|
+
}
|
|
161
|
+
exports.isValidX402Network = isValidX402Network;
|
|
162
|
+
//# sourceMappingURL=x402.js.map
|
|
@@ -0,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AiBG;AACH,MAAa,SAAU,SAAQ,KAAK;IAGlC;;;;;;OAMG;IACH,YACE,OAAe,EACC,IAAmB,EACnB,QAAmB;QAEnC,KAAK,CAAC,OAAO,CAAC,CAAC;QAHC,SAAI,GAAJ,IAAI,CAAe;QACnB,aAAQ,GAAR,QAAQ,CAAW;QAZrB,SAAI,GAAG,WAAW,CAAC;QAgBjC,kDAAkD;QAClD,IAAI,KAAK,CAAC,iBAAiB,EAAE,CAAC;YAC5B,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QAC3C,CAAC;IACH,CAAC;IAED;;OAEG;IACH,QAAQ;QACN,OAAO,cAAc,IAAI,CAAC,IAAI,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;IACrD,CAAC;CACF;AA7BD,8BA6BC;AAED,+EAA+E;AAC/E,cAAc;AACd,+EAA+E;AAE/E;;;;;GAKG;AACH,SAAgB,WAAW,CAAC,KAAc;IACxC,OAAO,KAAK,YAAY,SAAS,CAAC;AACpC,CAAC;AAFD,kCAEC;AAED;;;;;GAKG;AACH,SAAgB,kBAAkB,CAAC,OAAe;IAChD,OAAO,OAAO,KAAK,cAAc,IAAI,OAAO,KAAK,cAAc,CAAC;AAClE,CAAC;AAFD,gDAEC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agirails/sdk",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.2",
|
|
4
4
|
"description": "AGIRAILS SDK for the ACTP (Agent Commerce Transaction Protocol) - Unified mock + blockchain support",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -79,7 +79,8 @@
|
|
|
79
79
|
"ethr-did-resolver": "11.0.5",
|
|
80
80
|
"fast-json-stable-stringify": "2.1.0",
|
|
81
81
|
"kubo-rpc-client": "3.0.1",
|
|
82
|
-
"proper-lockfile": "4.1.2"
|
|
82
|
+
"proper-lockfile": "4.1.2",
|
|
83
|
+
"zod": "^3.22.4"
|
|
83
84
|
},
|
|
84
85
|
"devDependencies": {
|
|
85
86
|
"@nomicfoundation/hardhat-ethers": "3.0.0",
|