@pushchain/core 6.0.26 → 6.0.27-alpha.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/AGW.md +226 -0
- package/CHANGELOG.md +18 -0
- package/README.md +2 -0
- package/package.json +7 -1
- package/src/lib/agentic/agentic.d.ts +23 -0
- package/src/lib/agentic/agentic.js +51 -0
- package/src/lib/agentic/agentic.types.d.ts +414 -0
- package/src/lib/agentic/agentic.types.js +3 -0
- package/src/lib/agentic/capabilities.d.ts +37 -0
- package/src/lib/agentic/capabilities.js +64 -0
- package/src/lib/agentic/chain.d.ts +3 -0
- package/src/lib/agentic/chain.js +15 -0
- package/src/lib/agentic/codec/abi-layout.d.ts +20 -0
- package/src/lib/agentic/codec/abi-layout.js +168 -0
- package/src/lib/agentic/codec/defaults.d.ts +51 -0
- package/src/lib/agentic/codec/defaults.js +53 -0
- package/src/lib/agentic/codec/ids.d.ts +35 -0
- package/src/lib/agentic/codec/ids.js +74 -0
- package/src/lib/agentic/codec/native.d.ts +73 -0
- package/src/lib/agentic/codec/native.js +341 -0
- package/src/lib/agentic/codec/pins.d.ts +20 -0
- package/src/lib/agentic/codec/pins.js +29 -0
- package/src/lib/agentic/codec/rules.d.ts +45 -0
- package/src/lib/agentic/codec/rules.js +110 -0
- package/src/lib/agentic/codec/selectors.d.ts +19 -0
- package/src/lib/agentic/codec/selectors.js +60 -0
- package/src/lib/agentic/codec/session.d.ts +54 -0
- package/src/lib/agentic/codec/session.js +65 -0
- package/src/lib/agentic/codec/svm-accounts.d.ts +35 -0
- package/src/lib/agentic/codec/svm-accounts.js +68 -0
- package/src/lib/agentic/codec/svm-idl.d.ts +11 -0
- package/src/lib/agentic/codec/svm-idl.js +226 -0
- package/src/lib/agentic/codec/svm-terms.d.ts +157 -0
- package/src/lib/agentic/codec/svm-terms.js +246 -0
- package/src/lib/agentic/codec/universal-terms.d.ts +82 -0
- package/src/lib/agentic/codec/universal-terms.js +43 -0
- package/src/lib/agentic/codec/universal.d.ts +14 -0
- package/src/lib/agentic/codec/universal.js +173 -0
- package/src/lib/agentic/constants.d.ts +12 -0
- package/src/lib/agentic/constants.js +16 -0
- package/src/lib/agentic/context.d.ts +29 -0
- package/src/lib/agentic/context.js +56 -0
- package/src/lib/agentic/contracts/abi/v6/agent-validator.d.ts +105 -0
- package/src/lib/agentic/contracts/abi/v6/agent-validator.js +149 -0
- package/src/lib/agentic/contracts/abi/v6/agw-factory.d.ts +1146 -0
- package/src/lib/agentic/contracts/abi/v6/agw-factory.js +1499 -0
- package/src/lib/agentic/contracts/abi/v6/agw.d.ts +1306 -0
- package/src/lib/agentic/contracts/abi/v6/agw.js +1713 -0
- package/src/lib/agentic/contracts/abi/v6/index.d.ts +6 -0
- package/src/lib/agentic/contracts/abi/v6/index.js +17 -0
- package/src/lib/agentic/contracts/abi/v6/smart-session.d.ts +1493 -0
- package/src/lib/agentic/contracts/abi/v6/smart-session.js +1965 -0
- package/src/lib/agentic/contracts/abi/v6/universal-rules-policy.d.ts +1661 -0
- package/src/lib/agentic/contracts/abi/v6/universal-rules-policy.js +2187 -0
- package/src/lib/agentic/contracts/donut-v6.d.ts +11 -0
- package/src/lib/agentic/contracts/donut-v6.js +15 -0
- package/src/lib/agentic/contracts/prc20-metadata.d.ts +26 -0
- package/src/lib/agentic/contracts/prc20-metadata.js +87 -0
- package/src/lib/agentic/contracts/reader.d.ts +35 -0
- package/src/lib/agentic/contracts/reader.js +16 -0
- package/src/lib/agentic/contracts/v6.d.ts +5739 -0
- package/src/lib/agentic/contracts/v6.js +343 -0
- package/src/lib/agentic/deployments.d.ts +61 -0
- package/src/lib/agentic/deployments.js +203 -0
- package/src/lib/agentic/errors.d.ts +65 -0
- package/src/lib/agentic/errors.js +84 -0
- package/src/lib/agentic/execution/guards.d.ts +9 -0
- package/src/lib/agentic/execution/guards.js +30 -0
- package/src/lib/agentic/execution/outbound.d.ts +55 -0
- package/src/lib/agentic/execution/outbound.js +187 -0
- package/src/lib/agentic/execution/send.d.ts +9 -0
- package/src/lib/agentic/execution/send.js +268 -0
- package/src/lib/agentic/execution/svm-instruction.d.ts +24 -0
- package/src/lib/agentic/execution/svm-instruction.js +40 -0
- package/src/lib/agentic/execution/svm-outbound.d.ts +18 -0
- package/src/lib/agentic/execution/svm-outbound.js +86 -0
- package/src/lib/agentic/execution/svm-payload.d.ts +18 -0
- package/src/lib/agentic/execution/svm-payload.js +136 -0
- package/src/lib/agentic/execution/svm-public.d.ts +5 -0
- package/src/lib/agentic/execution/svm-public.js +176 -0
- package/src/lib/agentic/execution/svm-quote.d.ts +11 -0
- package/src/lib/agentic/execution/svm-quote.js +24 -0
- package/src/lib/agentic/execution/svm-send.d.ts +44 -0
- package/src/lib/agentic/execution/svm-send.js +87 -0
- package/src/lib/agentic/index.d.ts +5 -0
- package/src/lib/agentic/index.js +10 -0
- package/src/lib/agentic/management/common.d.ts +29 -0
- package/src/lib/agentic/management/common.js +116 -0
- package/src/lib/agentic/management/create.d.ts +4 -0
- package/src/lib/agentic/management/create.js +138 -0
- package/src/lib/agentic/management/duplicates.d.ts +4 -0
- package/src/lib/agentic/management/duplicates.js +20 -0
- package/src/lib/agentic/management/label.d.ts +3 -0
- package/src/lib/agentic/management/label.js +17 -0
- package/src/lib/agentic/management/prepare.d.ts +7 -0
- package/src/lib/agentic/management/prepare.js +95 -0
- package/src/lib/agentic/management/rules-write.d.ts +42 -0
- package/src/lib/agentic/management/rules-write.js +279 -0
- package/src/lib/agentic/management/svm-context.d.ts +25 -0
- package/src/lib/agentic/management/svm-context.js +55 -0
- package/src/lib/agentic/management/svm-metadata.d.ts +10 -0
- package/src/lib/agentic/management/svm-metadata.js +56 -0
- package/src/lib/agentic/management/svm-public.d.ts +6 -0
- package/src/lib/agentic/management/svm-public.js +125 -0
- package/src/lib/agentic/management/svm.d.ts +27 -0
- package/src/lib/agentic/management/svm.js +150 -0
- package/src/lib/agentic/presets/catalog.d.ts +26 -0
- package/src/lib/agentic/presets/catalog.js +307 -0
- package/src/lib/agentic/presets/index.d.ts +5 -0
- package/src/lib/agentic/presets/index.js +265 -0
- package/src/lib/agentic/presets/types.d.ts +48 -0
- package/src/lib/agentic/presets/types.js +3 -0
- package/src/lib/agentic/public-rule.d.ts +9 -0
- package/src/lib/agentic/public-rule.js +326 -0
- package/src/lib/agentic/reads/checkpoints.d.ts +17 -0
- package/src/lib/agentic/reads/checkpoints.js +109 -0
- package/src/lib/agentic/reads/rules.d.ts +42 -0
- package/src/lib/agentic/reads/rules.js +302 -0
- package/src/lib/agentic/reads/snapshot.d.ts +28 -0
- package/src/lib/agentic/reads/snapshot.js +85 -0
- package/src/lib/agentic/reads/svm.d.ts +17 -0
- package/src/lib/agentic/reads/svm.js +52 -0
- package/src/lib/agentic/reads/wallets.d.ts +25 -0
- package/src/lib/agentic/reads/wallets.js +122 -0
- package/src/lib/agentic/response.d.ts +41 -0
- package/src/lib/agentic/response.js +358 -0
- package/src/lib/agentic/revert.d.ts +7 -0
- package/src/lib/agentic/revert.js +102 -0
- package/src/lib/agentic/runtime.d.ts +58 -0
- package/src/lib/agentic/runtime.js +104 -0
- package/src/lib/agentic/utils.d.ts +57 -0
- package/src/lib/agentic/utils.js +165 -0
- package/src/lib/agentic/wallet.d.ts +32 -0
- package/src/lib/agentic/wallet.js +130 -0
- package/src/lib/constants/enums.d.ts +6 -3
- package/src/lib/constants/enums.js +6 -3
- package/src/lib/constants/index.d.ts +61 -4
- package/src/lib/constants/index.js +17 -3
- package/src/lib/constants/read-state.d.ts +9 -0
- package/src/lib/constants/read-state.js +13 -1
- package/src/lib/index.d.ts +8 -2
- package/src/lib/index.js +9 -1
- package/src/lib/orchestrator/internals/errors.d.ts +7 -0
- package/src/lib/orchestrator/internals/errors.js +13 -1
- package/src/lib/orchestrator/internals/execute-standard.d.ts +3 -1
- package/src/lib/orchestrator/internals/execute-standard.js +3 -3
- package/src/lib/orchestrator/internals/outbound-sync.js +52 -7
- package/src/lib/orchestrator/internals/push-chain-tx.d.ts +1 -1
- package/src/lib/orchestrator/internals/push-chain-tx.js +13 -1
- package/src/lib/orchestrator/orchestrator.d.ts +3 -0
- package/src/lib/orchestrator/orchestrator.js +13 -1
- package/src/lib/orchestrator/orchestrator.types.d.ts +8 -0
- package/src/lib/orchestrator/route-detector.js +3 -2
- package/src/lib/orchestrator/svm-idl/resolve.d.ts +2 -0
- package/src/lib/orchestrator/svm-idl/resolve.js +11 -1
- package/src/lib/progress-hook/progress-hook.js +63 -0
- package/src/lib/progress-hook/progress-hook.types.d.ts +10 -1
- package/src/lib/progress-hook/progress-hook.types.js +10 -0
- package/src/lib/push-chain/push-chain.d.ts +57 -15
- package/src/lib/push-chain/push-chain.js +66 -7
- package/src/lib/read-state/destination.js +6 -1
- package/src/lib/read-state/read-params.d.ts +3 -3
- package/src/lib/read-state/read-params.js +3 -2
- package/src/lib/read-state/read-state.types.d.ts +3 -1
- package/src/lib/read-state/read-tracker.js +2 -2
- package/src/lib/read-state/spec-builder.js +1 -1
- package/src/lib/universal/prc20-address.d.ts +15 -0
- package/src/lib/universal/prc20-address.js +135 -0
- package/src/lib/utils.d.ts +6 -13
- package/src/lib/utils.js +5 -128
- package/src/lib/vm-client/evm-client.js +34 -20
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isDynamic = isDynamic;
|
|
4
|
+
exports.headSize = headSize;
|
|
5
|
+
exports.isSingleWordStatic = isSingleWordStatic;
|
|
6
|
+
exports.argumentOffset = argumentOffset;
|
|
7
|
+
exports.encodeArgWord = encodeArgWord;
|
|
8
|
+
exports.rawOffset = rawOffset;
|
|
9
|
+
exports.argumentLocation = argumentLocation;
|
|
10
|
+
const viem_1 = require("viem");
|
|
11
|
+
const errors_1 = require("../errors");
|
|
12
|
+
/**
|
|
13
|
+
* ABI head layout for argument-position terms (native pins/amount, universal
|
|
14
|
+
* beneficiary). Contracts take ABSOLUTE byte offsets into calldata with the
|
|
15
|
+
* 4-byte selector included and read exactly one 32-byte word there, so only a
|
|
16
|
+
* single-word static elementary argument can be addressed. Preceding
|
|
17
|
+
* arguments may be dynamic (one head word: the offset pointer) or static
|
|
18
|
+
* tuples / fixed arrays (several head words); both are accounted for here.
|
|
19
|
+
*/
|
|
20
|
+
const UINT16_MAX = 0xffff;
|
|
21
|
+
function components(p) {
|
|
22
|
+
return p.components ?? [];
|
|
23
|
+
}
|
|
24
|
+
/** Parse a trailing fixed/dynamic array suffix: 'uint256[3]' → base 'uint256', length 3. */
|
|
25
|
+
function arraySuffix(type) {
|
|
26
|
+
const m = /^(.*)\[(\d*)\]$/.exec(type);
|
|
27
|
+
if (!m)
|
|
28
|
+
return null;
|
|
29
|
+
return { base: m[1], length: m[2] === '' ? null : Number(m[2]) };
|
|
30
|
+
}
|
|
31
|
+
function isDynamic(p) {
|
|
32
|
+
const arr = arraySuffix(p.type);
|
|
33
|
+
if (arr) {
|
|
34
|
+
if (arr.length === null)
|
|
35
|
+
return true;
|
|
36
|
+
return isDynamic({ ...p, type: arr.base });
|
|
37
|
+
}
|
|
38
|
+
if (p.type === 'bytes' || p.type === 'string')
|
|
39
|
+
return true;
|
|
40
|
+
if (p.type === 'tuple')
|
|
41
|
+
return components(p).some(isDynamic);
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
/** Bytes this parameter occupies in the head of an encoding. */
|
|
45
|
+
function headSize(p) {
|
|
46
|
+
if (isDynamic(p))
|
|
47
|
+
return 32;
|
|
48
|
+
const arr = arraySuffix(p.type);
|
|
49
|
+
if (arr && arr.length !== null) {
|
|
50
|
+
return arr.length * headSize({ ...p, type: arr.base });
|
|
51
|
+
}
|
|
52
|
+
if (p.type === 'tuple') {
|
|
53
|
+
return components(p).reduce((sum, c) => sum + headSize(c), 0);
|
|
54
|
+
}
|
|
55
|
+
return 32;
|
|
56
|
+
}
|
|
57
|
+
const ELEMENTARY = /^(address|bool|u?int(8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)?|bytes([1-9]|[12][0-9]|3[0-2]))$/;
|
|
58
|
+
function isSingleWordStatic(p) {
|
|
59
|
+
return ELEMENTARY.test(p.type);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Absolute calldata byte offset (selector included) of argument `arg`.
|
|
63
|
+
* Rejects out-of-range indexes and any argument that is not one static word.
|
|
64
|
+
*/
|
|
65
|
+
function argumentOffset(inputs, arg, what) {
|
|
66
|
+
if (!inputs) {
|
|
67
|
+
throw invalid(`${what} needs the function signature (e.g. 'supply(address,uint256,address,uint16)'), not a bare 4-byte selector`);
|
|
68
|
+
}
|
|
69
|
+
if (!Number.isInteger(arg) || arg < 0 || arg >= inputs.length) {
|
|
70
|
+
throw invalid(`${what} argument index ${arg} is out of range (0..${inputs.length - 1})`);
|
|
71
|
+
}
|
|
72
|
+
const target = inputs[arg];
|
|
73
|
+
if (!isSingleWordStatic(target)) {
|
|
74
|
+
throw invalid(`${what} argument ${arg} has type ${target.type}; only single-word static arguments can be pinned`);
|
|
75
|
+
}
|
|
76
|
+
let offset = 4;
|
|
77
|
+
for (let i = 0; i < arg; i++)
|
|
78
|
+
offset += headSize(inputs[i]);
|
|
79
|
+
if (offset + 32 > UINT16_MAX) {
|
|
80
|
+
throw invalid(`${what} argument ${arg} lies beyond the uint16 offset range`);
|
|
81
|
+
}
|
|
82
|
+
return offset;
|
|
83
|
+
}
|
|
84
|
+
/** Encode a pin's expected value as the exact 32-byte calldata word. */
|
|
85
|
+
function encodeArgWord(param, expected, what) {
|
|
86
|
+
try {
|
|
87
|
+
const isWord = typeof expected === 'string' && (0, viem_1.isHex)(expected) && expected.length === 66;
|
|
88
|
+
if (param.type === 'address' && !isWord) {
|
|
89
|
+
if (typeof expected !== 'string' ||
|
|
90
|
+
!(0, viem_1.isAddress)(expected, { strict: false })) {
|
|
91
|
+
throw new Error('expected an address');
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
else if (param.type.startsWith('bytes') && !isWord) {
|
|
95
|
+
if (typeof expected !== 'string' || !(0, viem_1.isHex)(expected))
|
|
96
|
+
throw new Error('expected hex');
|
|
97
|
+
}
|
|
98
|
+
// An already-encoded 32-byte word (as decoded rules return) is accepted
|
|
99
|
+
// when it is a canonical encoding of this argument type.
|
|
100
|
+
if (typeof expected === 'string' &&
|
|
101
|
+
(0, viem_1.isHex)(expected) &&
|
|
102
|
+
expected.length === 66 &&
|
|
103
|
+
param.type !== 'bytes32') {
|
|
104
|
+
const [value] = (0, viem_1.decodeAbiParameters)([param], expected);
|
|
105
|
+
if ((0, viem_1.encodeAbiParameters)([param], [value]).toLowerCase() !==
|
|
106
|
+
expected.toLowerCase()) {
|
|
107
|
+
throw new Error('word is not a canonical encoding');
|
|
108
|
+
}
|
|
109
|
+
return expected.toLowerCase();
|
|
110
|
+
}
|
|
111
|
+
return (0, viem_1.encodeAbiParameters)([param], [expected]);
|
|
112
|
+
}
|
|
113
|
+
catch (cause) {
|
|
114
|
+
throw invalid(`${what} expected value does not encode as ${param.type}: ${cause instanceof Error ? cause.message : String(cause)}`, cause);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/** Validate a raw calldata offset given directly (offset form). */
|
|
118
|
+
function rawOffset(offset, what) {
|
|
119
|
+
if (!Number.isInteger(offset) || offset < 4 || offset + 32 > UINT16_MAX) {
|
|
120
|
+
throw invalid(`${what} offset ${offset} must be an integer in [4, ${UINT16_MAX - 32}] (selector included)`);
|
|
121
|
+
}
|
|
122
|
+
return offset;
|
|
123
|
+
}
|
|
124
|
+
function invalid(message, cause) {
|
|
125
|
+
return new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.INVALID_RULE, message, { cause });
|
|
126
|
+
}
|
|
127
|
+
/** Absolute location of a scalar reached through static tuple/fixed-array indexes. */
|
|
128
|
+
function argumentLocation(inputs, arg, what) {
|
|
129
|
+
if (!inputs)
|
|
130
|
+
throw invalid(`${what} paths require a full function signature`);
|
|
131
|
+
const path = typeof arg === 'number' ? [arg] : arg;
|
|
132
|
+
if (!Array.isArray(path) ||
|
|
133
|
+
path.length === 0 ||
|
|
134
|
+
path.length > 16 ||
|
|
135
|
+
path.some((i) => !Number.isSafeInteger(i) || i < 0))
|
|
136
|
+
throw invalid(`${what} has an invalid argument path`);
|
|
137
|
+
if (path[0] >= inputs.length)
|
|
138
|
+
throw invalid(`${what} argument path is out of range`);
|
|
139
|
+
let offset = 4 + inputs.slice(0, path[0]).reduce((n, p) => n + headSize(p), 0);
|
|
140
|
+
let param = inputs[path[0]];
|
|
141
|
+
for (const index of path.slice(1)) {
|
|
142
|
+
if (isDynamic(param))
|
|
143
|
+
throw invalid(`${what} cannot descend into a dynamic argument`);
|
|
144
|
+
const arr = arraySuffix(param.type);
|
|
145
|
+
if (arr && arr.length !== null) {
|
|
146
|
+
if (!Number.isSafeInteger(arr.length) || index >= arr.length)
|
|
147
|
+
throw invalid(`${what} fixed-array index is out of range`);
|
|
148
|
+
const child = { ...param, type: arr.base };
|
|
149
|
+
offset += index * headSize(child);
|
|
150
|
+
param = child;
|
|
151
|
+
}
|
|
152
|
+
else if (param.type === 'tuple') {
|
|
153
|
+
const fields = components(param);
|
|
154
|
+
if (index >= fields.length)
|
|
155
|
+
throw invalid(`${what} tuple index is out of range`);
|
|
156
|
+
offset += fields.slice(0, index).reduce((n, p) => n + headSize(p), 0);
|
|
157
|
+
param = fields[index];
|
|
158
|
+
}
|
|
159
|
+
else
|
|
160
|
+
throw invalid(`${what} path descends into a scalar`);
|
|
161
|
+
}
|
|
162
|
+
if (!isSingleWordStatic(param) ||
|
|
163
|
+
!Number.isSafeInteger(offset) ||
|
|
164
|
+
offset + 32 > UINT16_MAX)
|
|
165
|
+
throw invalid(`${what} must identify one static ABI word within the uint16 offset range`);
|
|
166
|
+
return { offset, param };
|
|
167
|
+
}
|
|
168
|
+
//# sourceMappingURL=abi-layout.js.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE single home for omitted-limit defaults. Native PC defaults are zero as
|
|
3
|
+
* confirmed on October 7. Nothing else in the SDK may invent
|
|
4
|
+
* a fallback for these fields; update this table for future changes.
|
|
5
|
+
*
|
|
6
|
+
* Explicit zero always stays zero. In the native policy a zero value/amount
|
|
7
|
+
* cap forbids positive value/amount, while maxCalls = uint32 maximum means unlimited.
|
|
8
|
+
*/
|
|
9
|
+
export declare const UINT256_MAX: bigint;
|
|
10
|
+
export interface DefaultRow {
|
|
11
|
+
value: bigint;
|
|
12
|
+
meaning: string;
|
|
13
|
+
source: 'product' | 'v6';
|
|
14
|
+
}
|
|
15
|
+
export declare const AGENTIC_DEFAULTS: {
|
|
16
|
+
readonly native: {
|
|
17
|
+
readonly maxValuePerCall: {
|
|
18
|
+
readonly value: bigint;
|
|
19
|
+
readonly meaning: "no native value transfer";
|
|
20
|
+
readonly source: "product";
|
|
21
|
+
};
|
|
22
|
+
readonly maxValueTotal: {
|
|
23
|
+
readonly value: bigint;
|
|
24
|
+
readonly meaning: "no native value transfer";
|
|
25
|
+
readonly source: "product";
|
|
26
|
+
};
|
|
27
|
+
readonly amountMaxTotal: {
|
|
28
|
+
readonly value: bigint;
|
|
29
|
+
readonly meaning: "unlimited metered total";
|
|
30
|
+
readonly source: "product";
|
|
31
|
+
};
|
|
32
|
+
readonly maxCalls: {
|
|
33
|
+
readonly value: bigint;
|
|
34
|
+
readonly meaning: "unlimited calls until expiry";
|
|
35
|
+
readonly source: "product";
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
readonly universal: {
|
|
39
|
+
readonly assetMaxTotal: {
|
|
40
|
+
readonly value: bigint;
|
|
41
|
+
readonly meaning: "omitted or zero forbids token movement";
|
|
42
|
+
readonly source: "product";
|
|
43
|
+
};
|
|
44
|
+
readonly allowedCallMaxValue: {
|
|
45
|
+
readonly value: bigint;
|
|
46
|
+
readonly meaning: "no native value attached to the destination call";
|
|
47
|
+
readonly source: "product";
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
export declare function withDefault(value: bigint | undefined, row: DefaultRow): bigint;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AGENTIC_DEFAULTS = exports.UINT256_MAX = void 0;
|
|
4
|
+
exports.withDefault = withDefault;
|
|
5
|
+
/**
|
|
6
|
+
* THE single home for omitted-limit defaults. Native PC defaults are zero as
|
|
7
|
+
* confirmed on October 7. Nothing else in the SDK may invent
|
|
8
|
+
* a fallback for these fields; update this table for future changes.
|
|
9
|
+
*
|
|
10
|
+
* Explicit zero always stays zero. In the native policy a zero value/amount
|
|
11
|
+
* cap forbids positive value/amount, while maxCalls = uint32 maximum means unlimited.
|
|
12
|
+
*/
|
|
13
|
+
exports.UINT256_MAX = BigInt(2) ** BigInt(256) - BigInt(1);
|
|
14
|
+
exports.AGENTIC_DEFAULTS = {
|
|
15
|
+
native: {
|
|
16
|
+
maxValuePerCall: {
|
|
17
|
+
value: BigInt(0),
|
|
18
|
+
meaning: 'no native value transfer',
|
|
19
|
+
source: 'product',
|
|
20
|
+
},
|
|
21
|
+
maxValueTotal: {
|
|
22
|
+
value: BigInt(0),
|
|
23
|
+
meaning: 'no native value transfer',
|
|
24
|
+
source: 'product',
|
|
25
|
+
},
|
|
26
|
+
amountMaxTotal: {
|
|
27
|
+
value: exports.UINT256_MAX,
|
|
28
|
+
meaning: 'unlimited metered total',
|
|
29
|
+
source: 'product',
|
|
30
|
+
},
|
|
31
|
+
maxCalls: {
|
|
32
|
+
value: BigInt(0xffffffff),
|
|
33
|
+
meaning: 'unlimited calls until expiry',
|
|
34
|
+
source: 'product',
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
universal: {
|
|
38
|
+
assetMaxTotal: {
|
|
39
|
+
value: BigInt(0),
|
|
40
|
+
meaning: 'omitted or zero forbids token movement',
|
|
41
|
+
source: 'product',
|
|
42
|
+
},
|
|
43
|
+
allowedCallMaxValue: {
|
|
44
|
+
value: BigInt(0),
|
|
45
|
+
meaning: 'no native value attached to the destination call',
|
|
46
|
+
source: 'product',
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
function withDefault(value, row) {
|
|
51
|
+
return value === undefined ? row.value : value;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=defaults.js.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type Address, type Hex } from 'viem';
|
|
2
|
+
/**
|
|
3
|
+
* Pure identity helpers mirroring the pinned AGW generation (v6):
|
|
4
|
+
* smartsessions IdLib.toActionId / toConfigId / toPermissionId and
|
|
5
|
+
* AGWFactory._predict (OZ Clones immutable-args CREATE2).
|
|
6
|
+
* Every input that changes the result is explicit — validator, factory and
|
|
7
|
+
* implementation are internal generation context.
|
|
8
|
+
*/
|
|
9
|
+
/** keccak256(abi.encodePacked(address target, bytes4 selector)). */
|
|
10
|
+
export declare function actionId(target: Address, selector: Hex): Hex;
|
|
11
|
+
/** keccak256(abi.encodePacked(wallet, keccak256(abi.encodePacked(rulesId, actionId)))). */
|
|
12
|
+
export declare function configId(wallet: Address, rulesId: Hex, action: Hex): Hex;
|
|
13
|
+
/** sessionValidatorInitData for the agent validator: abi.encode(address agent). */
|
|
14
|
+
export declare function agentConfig(agent: Address): Hex;
|
|
15
|
+
/**
|
|
16
|
+
* The rules ID a grant produces:
|
|
17
|
+
* keccak256(abi.encode(validator, bytes abi.encode(agent), bytes32(grantNonce))).
|
|
18
|
+
* Chain is NOT part of the hash; records are keyed by wallet + rulesId.
|
|
19
|
+
*/
|
|
20
|
+
export declare function rulesId(ctx: {
|
|
21
|
+
validator: Address;
|
|
22
|
+
agent: Address;
|
|
23
|
+
grantNonce: bigint;
|
|
24
|
+
}): Hex;
|
|
25
|
+
/**
|
|
26
|
+
* Counterfactual wallet address: CREATE2 by the factory proxy of an OZ clone
|
|
27
|
+
* of `walletImplementation` with immutable args (owner ‖ factory), salt
|
|
28
|
+
* keccak256(abi.encode(owner, uint96 index)).
|
|
29
|
+
*/
|
|
30
|
+
export declare function deriveWallet(ctx: {
|
|
31
|
+
factory: Address;
|
|
32
|
+
walletImplementation: Address;
|
|
33
|
+
owner: Address;
|
|
34
|
+
index: bigint | number;
|
|
35
|
+
}): Address;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.actionId = actionId;
|
|
4
|
+
exports.configId = configId;
|
|
5
|
+
exports.agentConfig = agentConfig;
|
|
6
|
+
exports.rulesId = rulesId;
|
|
7
|
+
exports.deriveWallet = deriveWallet;
|
|
8
|
+
const viem_1 = require("viem");
|
|
9
|
+
const errors_1 = require("../errors");
|
|
10
|
+
/**
|
|
11
|
+
* Pure identity helpers mirroring the pinned AGW generation (v6):
|
|
12
|
+
* smartsessions IdLib.toActionId / toConfigId / toPermissionId and
|
|
13
|
+
* AGWFactory._predict (OZ Clones immutable-args CREATE2).
|
|
14
|
+
* Every input that changes the result is explicit — validator, factory and
|
|
15
|
+
* implementation are internal generation context.
|
|
16
|
+
*/
|
|
17
|
+
/** keccak256(abi.encodePacked(address target, bytes4 selector)). */
|
|
18
|
+
function actionId(target, selector) {
|
|
19
|
+
return (0, viem_1.keccak256)((0, viem_1.encodePacked)(['address', 'bytes4'], [target, selector]));
|
|
20
|
+
}
|
|
21
|
+
/** keccak256(abi.encodePacked(wallet, keccak256(abi.encodePacked(rulesId, actionId)))). */
|
|
22
|
+
function configId(wallet, rulesId, action) {
|
|
23
|
+
const inner = (0, viem_1.keccak256)((0, viem_1.encodePacked)(['bytes32', 'bytes32'], [rulesId, action]));
|
|
24
|
+
return (0, viem_1.keccak256)((0, viem_1.encodePacked)(['address', 'bytes32'], [wallet, inner]));
|
|
25
|
+
}
|
|
26
|
+
/** sessionValidatorInitData for the agent validator: abi.encode(address agent). */
|
|
27
|
+
function agentConfig(agent) {
|
|
28
|
+
return (0, viem_1.encodeAbiParameters)([{ type: 'address' }], [agent]);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The rules ID a grant produces:
|
|
32
|
+
* keccak256(abi.encode(validator, bytes abi.encode(agent), bytes32(grantNonce))).
|
|
33
|
+
* Chain is NOT part of the hash; records are keyed by wallet + rulesId.
|
|
34
|
+
*/
|
|
35
|
+
function rulesId(ctx) {
|
|
36
|
+
if (ctx.grantNonce < BigInt(0) || ctx.grantNonce >= BigInt(2) ** BigInt(64)) {
|
|
37
|
+
throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.INVALID_RULE, 'grantNonce must fit uint64');
|
|
38
|
+
}
|
|
39
|
+
return (0, viem_1.keccak256)((0, viem_1.encodeAbiParameters)([{ type: 'address' }, { type: 'bytes' }, { type: 'bytes32' }], [
|
|
40
|
+
ctx.validator,
|
|
41
|
+
agentConfig(ctx.agent),
|
|
42
|
+
(0, viem_1.numberToHex)(ctx.grantNonce, { size: 32 }),
|
|
43
|
+
]));
|
|
44
|
+
}
|
|
45
|
+
const UINT96_MAX = BigInt(2) ** BigInt(96) - BigInt(1);
|
|
46
|
+
/**
|
|
47
|
+
* Counterfactual wallet address: CREATE2 by the factory proxy of an OZ clone
|
|
48
|
+
* of `walletImplementation` with immutable args (owner ‖ factory), salt
|
|
49
|
+
* keccak256(abi.encode(owner, uint96 index)).
|
|
50
|
+
*/
|
|
51
|
+
function deriveWallet(ctx) {
|
|
52
|
+
const index = BigInt(ctx.index);
|
|
53
|
+
if (index < BigInt(0) || index > UINT96_MAX) {
|
|
54
|
+
throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.INVALID_RULE, 'wallet index must fit uint96');
|
|
55
|
+
}
|
|
56
|
+
const salt = (0, viem_1.keccak256)((0, viem_1.encodeAbiParameters)([{ type: 'address' }, { type: 'uint96' }], [ctx.owner, index]));
|
|
57
|
+
const args = (0, viem_1.encodePacked)(['address', 'address'], [ctx.owner, ctx.factory]);
|
|
58
|
+
const argsLength = (args.length - 2) / 2;
|
|
59
|
+
const initCode = (0, viem_1.concat)([
|
|
60
|
+
'0x61',
|
|
61
|
+
(0, viem_1.numberToHex)(argsLength + 0x2d, { size: 2 }),
|
|
62
|
+
'0x3d81600a3d39f3363d3d373d3d3d363d73',
|
|
63
|
+
ctx.walletImplementation,
|
|
64
|
+
'0x5af43d82803e903d91602b57fd5bf3',
|
|
65
|
+
args,
|
|
66
|
+
]);
|
|
67
|
+
return (0, viem_1.getAddress)((0, viem_1.getContractAddress)({
|
|
68
|
+
opcode: 'CREATE2',
|
|
69
|
+
from: ctx.factory,
|
|
70
|
+
salt,
|
|
71
|
+
bytecodeHash: (0, viem_1.keccak256)(initCode),
|
|
72
|
+
}));
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=ids.js.map
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { type ArgPinWire } from './pins';
|
|
2
|
+
import { type AbiParameter, type Address, type Hex } from 'viem';
|
|
3
|
+
import type { NativeAction, NativeRule, NativeSingleRule } from '../agentic.types';
|
|
4
|
+
import { type ParsedSelector } from './selectors';
|
|
5
|
+
/** URP native limits at v6 (Types.sol MAX_PINS, AGW MAX_NATIVE_ACTIONS). */
|
|
6
|
+
export declare const MAX_PINS = 8;
|
|
7
|
+
export declare const MAX_NATIVE_ACTIONS = 8;
|
|
8
|
+
/** NativeTerms in the pinned v6 Types.sol. */
|
|
9
|
+
export interface NativeTermsWire {
|
|
10
|
+
validUntil: number;
|
|
11
|
+
target: Address;
|
|
12
|
+
selector: Hex;
|
|
13
|
+
maxValuePerCall: bigint;
|
|
14
|
+
maxValueTotal: bigint;
|
|
15
|
+
amount: {
|
|
16
|
+
enabled: boolean;
|
|
17
|
+
offset: number;
|
|
18
|
+
maxPerCall: bigint;
|
|
19
|
+
maxTotal: bigint;
|
|
20
|
+
};
|
|
21
|
+
maxCalls: number;
|
|
22
|
+
pins: readonly ArgPinWire[];
|
|
23
|
+
}
|
|
24
|
+
export declare const NATIVE_TERMS_PARAM: AbiParameter;
|
|
25
|
+
export interface NativeEncodeContext {
|
|
26
|
+
/** Current unix time in seconds; grants with validUntil <= now are rejected. */
|
|
27
|
+
nowSeconds: number;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The actions a native rule allows: the single-action shorthand, or the
|
|
31
|
+
* explicit `actions` list (1..8). Each carries its effective `validUntil`.
|
|
32
|
+
*/
|
|
33
|
+
export declare function nativeActionsOf(rule: NativeRule): (NativeAction & {
|
|
34
|
+
validUntil: number;
|
|
35
|
+
})[];
|
|
36
|
+
/**
|
|
37
|
+
* Normalize and validate every action of a native rule into wire terms, in
|
|
38
|
+
* input order. (target, selector) pairs must be unique — the wallet refuses
|
|
39
|
+
* duplicates (DuplicateAction) because they share one action ID. Pure.
|
|
40
|
+
*/
|
|
41
|
+
export declare function nativeRuleToActionTerms(rule: NativeRule, ctx: NativeEncodeContext): {
|
|
42
|
+
terms: NativeTermsWire;
|
|
43
|
+
parsed: ParsedSelector;
|
|
44
|
+
}[];
|
|
45
|
+
/** Single-action convenience; multi-action rules use nativeRuleToActionTerms. */
|
|
46
|
+
export declare function nativeRuleToTerms(rule: NativeRule, ctx: NativeEncodeContext): {
|
|
47
|
+
terms: NativeTermsWire;
|
|
48
|
+
parsed: ParsedSelector;
|
|
49
|
+
};
|
|
50
|
+
/** Normalize and validate one native action into wire terms. Pure. */
|
|
51
|
+
export declare function nativeActionToTerms(rule: NativeAction & {
|
|
52
|
+
validUntil: number;
|
|
53
|
+
}, ctx: NativeEncodeContext): {
|
|
54
|
+
terms: NativeTermsWire;
|
|
55
|
+
parsed: ParsedSelector;
|
|
56
|
+
};
|
|
57
|
+
export declare function encodeNativeTerms(terms: NativeTermsWire): Hex;
|
|
58
|
+
export declare function decodeNativeTerms(body: Hex): NativeTermsWire;
|
|
59
|
+
/**
|
|
60
|
+
* Wire terms back to the public NativeRule shape. Stored terms carry calldata
|
|
61
|
+
* offsets and exact words but no ABI, so pins and amount are returned in the
|
|
62
|
+
* raw `offset` form (never a guessed argument index) and `selector` is the
|
|
63
|
+
* 4-byte hex. The result re-encodes to the same terms.
|
|
64
|
+
*/
|
|
65
|
+
export declare function nativeTermsToRule(terms: NativeTermsWire, agent: Address): NativeSingleRule;
|
|
66
|
+
/**
|
|
67
|
+
* Stored action terms back to a public NativeRule: the single-action
|
|
68
|
+
* shorthand for one action, otherwise `actions` in stored order. The rule's
|
|
69
|
+
* `validUntil` is the earliest action expiry; an action expiring later keeps
|
|
70
|
+
* its own `validUntil`, so the result re-encodes to identical terms.
|
|
71
|
+
*/
|
|
72
|
+
export declare function nativeActionTermsToRule(termsList: readonly NativeTermsWire[], agent: Address): NativeRule;
|
|
73
|
+
export declare function isUnlimited(value: bigint): boolean;
|