@nullclear/shared 0.0.0-stage → 1.1.1

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/index.js ADDED
@@ -0,0 +1,216 @@
1
+ // src/chains.ts
2
+ var NULLCLEAR_TREASURY_ADDRESS = "0xB586eFcCa41dF27ad3873BEcA54da0c30bf04d5c";
3
+ var NULLCLEAR_ARBITER_ADDRESS = "0xfd74fF802EA0E735514C070AF04E0D6528deD145";
4
+ var BASE_MAINNET = {
5
+ name: "Base Mainnet",
6
+ chainId: 8453,
7
+ caip2: "eip155:8453",
8
+ erc8004Identity: "0x8004A169FB4a3325136EB29fA0ceB6D2e539a432",
9
+ erc8004Reputation: "0x8004BAa17C55a88189AE136b182e5fdA19dE9b63",
10
+ usdc: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
11
+ usdcDomain: {
12
+ name: "USD Coin",
13
+ version: "2",
14
+ chainId: 8453,
15
+ verifyingContract: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"
16
+ },
17
+ rpcUrl: "https://mainnet.base.org",
18
+ blockExplorer: "https://basescan.org"
19
+ };
20
+ var BASE_SEPOLIA = {
21
+ name: "Base Sepolia",
22
+ chainId: 84532,
23
+ caip2: "eip155:84532",
24
+ erc8004Identity: "0x8004A818BFB912233c491871b3d84c89A494BD9e",
25
+ erc8004Reputation: "0x8004B663056A597Dffe9eCcC1965A193B7388713",
26
+ usdc: "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
27
+ usdcDomain: {
28
+ name: "USDC",
29
+ version: "2",
30
+ chainId: 84532,
31
+ verifyingContract: "0x036CbD53842c5426634e7929541eC2318f3dCF7e"
32
+ },
33
+ rpcUrl: "https://sepolia.base.org",
34
+ blockExplorer: "https://sepolia.basescan.org"
35
+ };
36
+ var SUPPORTED_CHAINS = {
37
+ 8453: BASE_MAINNET,
38
+ 84532: BASE_SEPOLIA
39
+ };
40
+ var CAIP2_TO_CHAIN_ID = {
41
+ "eip155:8453": 8453,
42
+ "eip155:84532": 84532
43
+ };
44
+ function getChainConfig(chainIdOrCaip2) {
45
+ let chainId;
46
+ if (typeof chainIdOrCaip2 === "string") {
47
+ if (chainIdOrCaip2.startsWith("eip155:")) {
48
+ chainId = CAIP2_TO_CHAIN_ID[chainIdOrCaip2] ?? parseInt(chainIdOrCaip2.slice(7), 10);
49
+ } else {
50
+ chainId = parseInt(chainIdOrCaip2, 10);
51
+ }
52
+ } else {
53
+ chainId = chainIdOrCaip2;
54
+ }
55
+ const config = SUPPORTED_CHAINS[chainId];
56
+ if (!config) {
57
+ throw new Error(`Unsupported chain ID or CAIP-2 identifier: ${chainIdOrCaip2}`);
58
+ }
59
+ return config;
60
+ }
61
+
62
+ // src/erc8004-abi.ts
63
+ import { parseAbi } from "viem";
64
+ var ERC8004_IDENTITY_ABI = parseAbi([
65
+ "function register(string agentURI) external returns (uint256 agentId)",
66
+ "function ownerOf(uint256 tokenId) external view returns (address)",
67
+ "function tokenURI(uint256 tokenId) external view returns (string)",
68
+ "function getAgentWallet(uint256 agentId) external view returns (address)",
69
+ "event Registered(uint256 indexed agentId, string agentURI, address indexed owner)"
70
+ ]);
71
+ var ERC8004_REPUTATION_ABI = parseAbi([
72
+ "function giveFeedback(uint256 agentId, int128 value, uint8 valueDecimals, string tag1, string tag2, string endpoint, string feedbackURI, bytes32 feedbackHash) external",
73
+ "function getSummary(uint256 agentId, address[] clientAddresses, string tag1, string tag2) external view returns (uint64 count, int128 summaryValue, uint8 summaryValueDecimals)",
74
+ "function readFeedback(uint256 agentId, address clientAddress, uint64 feedbackIndex) external view returns (int128 value, uint8 valueDecimals, string tag1, string tag2, bool isRevoked)",
75
+ "event NewFeedback(uint256 indexed agentId, address indexed clientAddress, uint64 feedbackIndex, int128 value, uint8 valueDecimals, string indexed indexedTag1, string tag1, string tag2, string endpoint, string feedbackURI, bytes32 feedbackHash)"
76
+ ]);
77
+
78
+ // src/x402-types.ts
79
+ import { parseAbi as parseAbi2 } from "viem";
80
+ var EIP3009_ABI = parseAbi2([
81
+ "function transferWithAuthorization(address from, address to, uint256 value, uint256 validAfter, uint256 validBefore, bytes32 nonce, uint8 v, bytes32 r, bytes32 s) external"
82
+ ]);
83
+ var EIP3009_TYPES = {
84
+ TransferWithAuthorization: [
85
+ { name: "from", type: "address" },
86
+ { name: "to", type: "address" },
87
+ { name: "value", type: "uint256" },
88
+ { name: "validAfter", type: "uint256" },
89
+ { name: "validBefore", type: "uint256" },
90
+ { name: "nonce", type: "bytes32" }
91
+ ]
92
+ };
93
+ function encodeBase64Json(obj) {
94
+ const json = JSON.stringify(obj);
95
+ if (typeof Buffer !== "undefined") {
96
+ return Buffer.from(json, "utf-8").toString("base64");
97
+ }
98
+ return btoa(unescape(encodeURIComponent(json)));
99
+ }
100
+ function decodeBase64Json(base64) {
101
+ let json;
102
+ if (typeof Buffer !== "undefined") {
103
+ json = Buffer.from(base64, "base64").toString("utf-8");
104
+ } else {
105
+ json = decodeURIComponent(escape(atob(base64)));
106
+ }
107
+ return JSON.parse(json);
108
+ }
109
+
110
+ // src/eip712-kya.ts
111
+ var KYA_MANDATE_TYPES = {
112
+ CorporateMandate: [
113
+ { name: "corporateEntity", type: "string" },
114
+ { name: "entityRegistrationNumber", type: "string" },
115
+ { name: "agentId", type: "string" },
116
+ { name: "agentWallet", type: "address" },
117
+ { name: "maxTxLimitUsd", type: "uint256" },
118
+ { name: "liabilityCoverageUsd", type: "uint256" },
119
+ { name: "validUntil", type: "uint256" },
120
+ { name: "jurisdiction", type: "string" }
121
+ ]
122
+ };
123
+ var KYA_DOMAIN = {
124
+ name: "NullClear KYA Registry",
125
+ version: "1",
126
+ chainId: 8453
127
+ };
128
+ var ARBITER_ATTESTATION_TYPES = {
129
+ ClearingAttestation: [
130
+ { name: "clearingId", type: "string" },
131
+ { name: "buyer", type: "address" },
132
+ { name: "sellerAgentId", type: "string" },
133
+ { name: "amountAtomic", type: "uint256" },
134
+ { name: "feeAtomic", type: "uint256" },
135
+ { name: "responseHash", type: "bytes32" },
136
+ { name: "timestamp", type: "uint256" },
137
+ { name: "cleared", type: "bool" }
138
+ ]
139
+ };
140
+ var ARBITER_DOMAIN = {
141
+ name: "NullClear Arbiter",
142
+ version: "1",
143
+ chainId: 8453
144
+ };
145
+
146
+ // src/schemas.ts
147
+ import { z } from "zod";
148
+ var InvariantRuleSchema = z.object({
149
+ path: z.string(),
150
+ gt: z.number().optional(),
151
+ gte: z.number().optional(),
152
+ lt: z.number().optional(),
153
+ lte: z.number().optional(),
154
+ eq: z.union([z.string(), z.number(), z.boolean()]).optional(),
155
+ neq: z.union([z.string(), z.number(), z.boolean()]).optional(),
156
+ minLength: z.number().optional(),
157
+ maxLength: z.number().optional(),
158
+ pattern: z.string().optional(),
159
+ notContains: z.array(z.string()).optional(),
160
+ maxStalenessSeconds: z.number().optional()
161
+ });
162
+ var ValidationConfigSchema = z.object({
163
+ expectedStatus: z.array(z.number()).optional(),
164
+ jsonSchema: z.record(z.string(), z.unknown()).optional(),
165
+ requiredFields: z.array(z.string()).optional(),
166
+ sha256Match: z.string().optional(),
167
+ rejectRefusals: z.boolean().optional(),
168
+ invariants: z.array(InvariantRuleSchema).optional()
169
+ });
170
+ var FallbackTargetSchema = z.object({
171
+ targetUrl: z.string(),
172
+ sellerAgentId: z.string().optional(),
173
+ paymentSignatureHeader: z.string(),
174
+ headers: z.record(z.string(), z.string()).optional()
175
+ });
176
+ var SpendPolicySchema = z.object({
177
+ maxPerCallAtomic: z.string().optional(),
178
+ maxDailyWalletAtomic: z.string().optional()
179
+ });
180
+ var ClearRequestSchema = z.object({
181
+ targetUrl: z.string(),
182
+ method: z.enum(["GET", "POST", "PUT", "DELETE"]).optional().default("GET"),
183
+ headers: z.record(z.string(), z.string()).optional(),
184
+ body: z.unknown().optional(),
185
+ paymentSignatureHeader: z.string(),
186
+ sellerAgentId: z.string().optional(),
187
+ minTrustScore: z.number().optional().default(50),
188
+ twoPhaseRelease: z.boolean().optional().default(false),
189
+ validation: ValidationConfigSchema.optional(),
190
+ fallbacks: z.array(FallbackTargetSchema).max(3).optional(),
191
+ spendPolicy: SpendPolicySchema.optional()
192
+ });
193
+ export {
194
+ ARBITER_ATTESTATION_TYPES,
195
+ ARBITER_DOMAIN,
196
+ BASE_MAINNET,
197
+ BASE_SEPOLIA,
198
+ CAIP2_TO_CHAIN_ID,
199
+ ClearRequestSchema,
200
+ EIP3009_ABI,
201
+ EIP3009_TYPES,
202
+ ERC8004_IDENTITY_ABI,
203
+ ERC8004_REPUTATION_ABI,
204
+ FallbackTargetSchema,
205
+ InvariantRuleSchema,
206
+ KYA_DOMAIN,
207
+ KYA_MANDATE_TYPES,
208
+ NULLCLEAR_ARBITER_ADDRESS,
209
+ NULLCLEAR_TREASURY_ADDRESS,
210
+ SUPPORTED_CHAINS,
211
+ SpendPolicySchema,
212
+ ValidationConfigSchema,
213
+ decodeBase64Json,
214
+ encodeBase64Json,
215
+ getChainConfig
216
+ };
package/dist/index.mjs ADDED
@@ -0,0 +1,154 @@
1
+ // src/chains.ts
2
+ var BASE_MAINNET = {
3
+ name: "Base Mainnet",
4
+ chainId: 8453,
5
+ caip2: "eip155:8453",
6
+ erc8004Identity: "0x8004A169FB4a3325136EB29fA0ceB6D2e539a432",
7
+ erc8004Reputation: "0x8004BAa17C55a88189AE136b182e5fdA19dE9b63",
8
+ usdc: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
9
+ usdcDomain: {
10
+ name: "USD Coin",
11
+ version: "2",
12
+ chainId: 8453,
13
+ verifyingContract: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"
14
+ },
15
+ rpcUrl: "https://mainnet.base.org",
16
+ blockExplorer: "https://basescan.org"
17
+ };
18
+ var BASE_SEPOLIA = {
19
+ name: "Base Sepolia",
20
+ chainId: 84532,
21
+ caip2: "eip155:84532",
22
+ erc8004Identity: "0x8004A818BFB912233c491871b3d84c89A494BD9e",
23
+ erc8004Reputation: "0x8004B663056A597Dffe9eCcC1965A193B7388713",
24
+ usdc: "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
25
+ usdcDomain: {
26
+ name: "USDC",
27
+ version: "2",
28
+ chainId: 84532,
29
+ verifyingContract: "0x036CbD53842c5426634e7929541eC2318f3dCF7e"
30
+ },
31
+ rpcUrl: "https://sepolia.base.org",
32
+ blockExplorer: "https://sepolia.basescan.org"
33
+ };
34
+ var SUPPORTED_CHAINS = {
35
+ 8453: BASE_MAINNET,
36
+ 84532: BASE_SEPOLIA
37
+ };
38
+ var CAIP2_TO_CHAIN_ID = {
39
+ "eip155:8453": 8453,
40
+ "eip155:84532": 84532
41
+ };
42
+ function getChainConfig(chainIdOrCaip2) {
43
+ let chainId;
44
+ if (typeof chainIdOrCaip2 === "string") {
45
+ if (chainIdOrCaip2.startsWith("eip155:")) {
46
+ chainId = CAIP2_TO_CHAIN_ID[chainIdOrCaip2] ?? parseInt(chainIdOrCaip2.slice(7), 10);
47
+ } else {
48
+ chainId = parseInt(chainIdOrCaip2, 10);
49
+ }
50
+ } else {
51
+ chainId = chainIdOrCaip2;
52
+ }
53
+ const config = SUPPORTED_CHAINS[chainId];
54
+ if (!config) {
55
+ throw new Error(`Unsupported chain ID or CAIP-2 identifier: ${chainIdOrCaip2}`);
56
+ }
57
+ return config;
58
+ }
59
+
60
+ // src/erc8004-abi.ts
61
+ import { parseAbi } from "viem";
62
+ var ERC8004_IDENTITY_ABI = parseAbi([
63
+ "function register(string agentURI) external returns (uint256 agentId)",
64
+ "function ownerOf(uint256 tokenId) external view returns (address)",
65
+ "function tokenURI(uint256 tokenId) external view returns (string)",
66
+ "function getAgentWallet(uint256 agentId) external view returns (address)",
67
+ "event Registered(uint256 indexed agentId, string agentURI, address indexed owner)"
68
+ ]);
69
+ var ERC8004_REPUTATION_ABI = parseAbi([
70
+ "function giveFeedback(uint256 agentId, int128 value, uint8 valueDecimals, string tag1, string tag2, string endpoint, string feedbackURI, bytes32 feedbackHash) external",
71
+ "function getSummary(uint256 agentId, address[] clientAddresses, string tag1, string tag2) external view returns (uint64 count, int128 summaryValue, uint8 summaryValueDecimals)",
72
+ "function readFeedback(uint256 agentId, address clientAddress, uint64 feedbackIndex) external view returns (int128 value, uint8 valueDecimals, string tag1, string tag2, bool isRevoked)",
73
+ "event NewFeedback(uint256 indexed agentId, address indexed clientAddress, uint64 feedbackIndex, int128 value, uint8 valueDecimals, string indexed indexedTag1, string tag1, string tag2, string endpoint, string feedbackURI, bytes32 feedbackHash)"
74
+ ]);
75
+
76
+ // src/x402-types.ts
77
+ var EIP3009_TYPES = {
78
+ TransferWithAuthorization: [
79
+ { name: "from", type: "address" },
80
+ { name: "to", type: "address" },
81
+ { name: "value", type: "uint256" },
82
+ { name: "validAfter", type: "uint256" },
83
+ { name: "validBefore", type: "uint256" },
84
+ { name: "nonce", type: "bytes32" }
85
+ ]
86
+ };
87
+ function encodeBase64Json(obj) {
88
+ const json = JSON.stringify(obj);
89
+ if (typeof Buffer !== "undefined") {
90
+ return Buffer.from(json, "utf-8").toString("base64");
91
+ }
92
+ return btoa(unescape(encodeURIComponent(json)));
93
+ }
94
+ function decodeBase64Json(base64) {
95
+ let json;
96
+ if (typeof Buffer !== "undefined") {
97
+ json = Buffer.from(base64, "base64").toString("utf-8");
98
+ } else {
99
+ json = decodeURIComponent(escape(atob(base64)));
100
+ }
101
+ return JSON.parse(json);
102
+ }
103
+
104
+ // src/eip712-kya.ts
105
+ var KYA_MANDATE_TYPES = {
106
+ CorporateMandate: [
107
+ { name: "corporateEntity", type: "string" },
108
+ { name: "entityRegistrationNumber", type: "string" },
109
+ { name: "agentId", type: "string" },
110
+ { name: "agentWallet", type: "address" },
111
+ { name: "maxTxLimitUsd", type: "uint256" },
112
+ { name: "liabilityCoverageUsd", type: "uint256" },
113
+ { name: "validUntil", type: "uint256" },
114
+ { name: "jurisdiction", type: "string" }
115
+ ]
116
+ };
117
+ var KYA_DOMAIN = {
118
+ name: "NullClear KYA Registry",
119
+ version: "1",
120
+ chainId: 8453
121
+ };
122
+ var ARBITER_ATTESTATION_TYPES = {
123
+ ClearingAttestation: [
124
+ { name: "clearingId", type: "string" },
125
+ { name: "buyer", type: "address" },
126
+ { name: "sellerAgentId", type: "string" },
127
+ { name: "amountAtomic", type: "uint256" },
128
+ { name: "feeAtomic", type: "uint256" },
129
+ { name: "responseHash", type: "bytes32" },
130
+ { name: "timestamp", type: "uint256" },
131
+ { name: "cleared", type: "bool" }
132
+ ]
133
+ };
134
+ var ARBITER_DOMAIN = {
135
+ name: "NullClear Arbiter",
136
+ version: "1",
137
+ chainId: 8453
138
+ };
139
+ export {
140
+ ARBITER_ATTESTATION_TYPES,
141
+ ARBITER_DOMAIN,
142
+ BASE_MAINNET,
143
+ BASE_SEPOLIA,
144
+ CAIP2_TO_CHAIN_ID,
145
+ EIP3009_TYPES,
146
+ ERC8004_IDENTITY_ABI,
147
+ ERC8004_REPUTATION_ABI,
148
+ KYA_DOMAIN,
149
+ KYA_MANDATE_TYPES,
150
+ SUPPORTED_CHAINS,
151
+ decodeBase64Json,
152
+ encodeBase64Json,
153
+ getChainConfig
154
+ };
package/package.json CHANGED
@@ -1,6 +1,42 @@
1
1
  {
2
2
  "name": "@nullclear/shared",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "1.1.1",
4
+ "description": "Shared types, ABIs, crypto schemas and chain configurations for NullClear",
5
+ "license": "MIT",
6
+ "homepage": "https://nullclear.dev",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/Nullclear-Protocol/nullclear.git"
10
+ },
11
+ "type": "module",
12
+ "main": "./dist/index.cjs",
13
+ "module": "./dist/index.js",
14
+ "types": "./dist/index.d.ts",
15
+ "files": [
16
+ "dist",
17
+ "README.md"
18
+ ],
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "exports": {
23
+ ".": {
24
+ "types": "./dist/index.d.ts",
25
+ "import": "./dist/index.js",
26
+ "require": "./dist/index.cjs"
27
+ }
28
+ },
29
+ "dependencies": {
30
+ "viem": "^2.23.0",
31
+ "zod": "^3.24.2"
32
+ },
33
+ "devDependencies": {
34
+ "tsup": "^8.3.6",
35
+ "typescript": "^5.7.3"
36
+ },
37
+ "scripts": {
38
+ "build": "tsup src/index.ts --format esm,cjs --dts",
39
+ "typecheck": "tsc --noEmit",
40
+ "lint": "echo \"@nullclear/shared clean\""
41
+ }
6
42
  }