@agenticprimitives/delegation 0.1.0-alpha.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/LICENSE +21 -0
- package/README.md +46 -0
- package/dist/caveats.d.ts +50 -0
- package/dist/caveats.d.ts.map +1 -0
- package/dist/caveats.js +116 -0
- package/dist/caveats.js.map +1 -0
- package/dist/client.d.ts +18 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +57 -0
- package/dist/client.js.map +1 -0
- package/dist/evaluator.d.ts +15 -0
- package/dist/evaluator.d.ts.map +1 -0
- package/dist/evaluator.js +209 -0
- package/dist/evaluator.js.map +1 -0
- package/dist/hash.d.ts +45 -0
- package/dist/hash.d.ts.map +1 -0
- package/dist/hash.js +80 -0
- package/dist/hash.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/onchain.d.ts +8 -0
- package/dist/onchain.d.ts.map +1 -0
- package/dist/onchain.js +9 -0
- package/dist/onchain.js.map +1 -0
- package/dist/session-manager.d.ts +51 -0
- package/dist/session-manager.d.ts.map +1 -0
- package/dist/session-manager.js +259 -0
- package/dist/session-manager.js.map +1 -0
- package/dist/token.d.ts +158 -0
- package/dist/token.d.ts.map +1 -0
- package/dist/token.js +459 -0
- package/dist/token.js.map +1 -0
- package/dist/types.d.ts +162 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +66 -0
- package/spec.md +6 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Agentic Trust Labs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# @agenticprimitives/delegation
|
|
2
|
+
|
|
3
|
+
EIP-712 smart-account delegations spanning web app → agent → MCP. **Now also owns session lifecycle** — `SessionManager` binds a delegation to its session-signing key, persisted via `@agenticprimitives/key-custody` envelope encryption.
|
|
4
|
+
|
|
5
|
+
See [`spec.md`](./spec.md) → [`specs/202-delegation.md`](../../specs/202-delegation.md) for the full contract: 8 on-chain enforcers, 3 off-chain sentinels, token envelope, cross-delegation, two session variants.
|
|
6
|
+
|
|
7
|
+
## Quick start
|
|
8
|
+
|
|
9
|
+
Browser (issuance):
|
|
10
|
+
```ts
|
|
11
|
+
import { DelegationClient, buildMcpToolScopeCaveat, encodeTimestampTerms, buildCaveat } from '@agenticprimitives/delegation';
|
|
12
|
+
|
|
13
|
+
const client = new DelegationClient({ signer, smartAccount, chainId, delegationManager });
|
|
14
|
+
const delegation = await client.issueDelegation({
|
|
15
|
+
delegate: sessionKeyAddress,
|
|
16
|
+
caveats: [
|
|
17
|
+
buildCaveat(enforcers.timestamp, encodeTimestampTerms(now, now + 86400)),
|
|
18
|
+
buildMcpToolScopeCaveat(['get_profile', 'update_profile']),
|
|
19
|
+
],
|
|
20
|
+
});
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Node (session lifecycle):
|
|
24
|
+
```ts
|
|
25
|
+
import { SessionManager } from '@agenticprimitives/delegation';
|
|
26
|
+
|
|
27
|
+
const sessions = new SessionManager({ keyCustody, store, accountClient });
|
|
28
|
+
const { sessionId, sessionKeyAddress } = await sessions.init(userAccount, chainId);
|
|
29
|
+
// ... user signs delegation, posts back ...
|
|
30
|
+
await sessions.package(sessionId, signedDelegation);
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Node (token mint + verify):
|
|
34
|
+
```ts
|
|
35
|
+
import { mintDelegationToken, verifyDelegationToken } from '@agenticprimitives/delegation';
|
|
36
|
+
|
|
37
|
+
const { token } = await mintDelegationToken(claims, sessionAccount.signMessage);
|
|
38
|
+
// At the MCP:
|
|
39
|
+
const result = await verifyDelegationToken(token, { chainId, delegationManager, rpcUrl, audience, enforcerMap, jtiStore });
|
|
40
|
+
if ('error' in result) throw new Error(result.error);
|
|
41
|
+
const { principal, grants } = result;
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Status
|
|
45
|
+
|
|
46
|
+
Pre-alpha. Spec stable.
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { type Hex, type Address } from 'viem';
|
|
2
|
+
import type { Caveat, DataScopeGrant } from './types';
|
|
3
|
+
export declare const MCP_TOOL_SCOPE_ENFORCER: Address;
|
|
4
|
+
export declare const DATA_SCOPE_ENFORCER: Address;
|
|
5
|
+
export declare const DELEGATE_BINDING_ENFORCER: Address;
|
|
6
|
+
export declare function buildCaveat(enforcer: Address, terms: Hex, args?: Hex): Caveat;
|
|
7
|
+
export declare function encodeTimestampTerms(validAfter: number, validUntil: number): Hex;
|
|
8
|
+
export declare function encodeValueTerms(maxValue: bigint): Hex;
|
|
9
|
+
export declare function encodeAllowedTargetsTerms(targets: Address[]): Hex;
|
|
10
|
+
export declare function encodeAllowedMethodsTerms(selectors: Hex[]): Hex;
|
|
11
|
+
export declare function buildMcpToolScopeCaveat(allowedTools: string[]): Caveat;
|
|
12
|
+
export declare function buildDataScopeCaveat(grants: DataScopeGrant[]): Caveat;
|
|
13
|
+
export declare function buildDelegateBindingCaveat(delegateSmartAccount: Address, delegatePersonAgent: Address): Caveat;
|
|
14
|
+
export interface QuorumCaveatOpts {
|
|
15
|
+
/**
|
|
16
|
+
* Address of the deployed `QuorumEnforcer` contract for this chain.
|
|
17
|
+
* Read from `deployments-<network>.json` at the consumer-app layer
|
|
18
|
+
* — `@agenticprimitives/delegation` is chain-agnostic and never
|
|
19
|
+
* resolves addresses itself.
|
|
20
|
+
*/
|
|
21
|
+
enforcer: Address;
|
|
22
|
+
/** Addresses authorized to participate in the quorum. Sorted by the
|
|
23
|
+
* redeemer before signing (sorted-ascending is the anti-duplicate
|
|
24
|
+
* scheme); order at issuance time is irrelevant. */
|
|
25
|
+
signers: Address[];
|
|
26
|
+
/** Minimum number of signatures required at redemption. Spec 207
|
|
27
|
+
* § 5.1 default thresholds map naturally onto this value when the
|
|
28
|
+
* caveat is attached to a T3+ delegation. */
|
|
29
|
+
threshold: number;
|
|
30
|
+
/** Optional `ApprovedHashRegistry` for the v=1 pre-approved-hash
|
|
31
|
+
* signature path. Pass `0x0000…0` to forbid v=1 entirely. */
|
|
32
|
+
approvedHashRegistry: Address;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Build a `QuorumEnforcer` caveat. Pair with delegations whose
|
|
36
|
+
* `tool-policy.evaluateThresholdPolicy` decision has
|
|
37
|
+
* `requiresQuorum: true` (T3 Value and above). Without this caveat,
|
|
38
|
+
* `verifyDelegationToken({ requireQuorumForTier })` fails closed.
|
|
39
|
+
*
|
|
40
|
+
* Wire format of the terms blob exactly matches what
|
|
41
|
+
* `QuorumEnforcer.beforeHook` decodes:
|
|
42
|
+
* abi.encode(address[] signerSet, uint8 threshold, address approvedHashRegistry)
|
|
43
|
+
*
|
|
44
|
+
* The redeem-time `args` are caller-supplied at execution time, not
|
|
45
|
+
* at issuance — `mcp-runtime.withDelegation` (6c.4) constructs them
|
|
46
|
+
* from the user's signed payload + signature blob and forwards them
|
|
47
|
+
* into the on-chain caveat evaluation.
|
|
48
|
+
*/
|
|
49
|
+
export declare function buildQuorumCaveat(opts: QuorumCaveatOpts): Caveat;
|
|
50
|
+
//# sourceMappingURL=caveats.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"caveats.d.ts","sourceRoot":"","sources":["../src/caveats.ts"],"names":[],"mappings":"AAQA,OAAO,EAAuB,KAAK,GAAG,EAAE,KAAK,OAAO,EAAE,MAAM,MAAM,CAAC;AAEnE,OAAO,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAWtD,eAAO,MAAM,uBAAuB,EAAE,OAA2D,CAAC;AAClG,eAAO,MAAM,mBAAmB,EAAE,OAAuD,CAAC;AAC1F,eAAO,MAAM,yBAAyB,EAAE,OAA6D,CAAC;AAItG,wBAAgB,WAAW,CAAC,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,MAAM,CAE7E;AAID,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,GAAG,CAWhF;AAED,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,CAGtD;AAED,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,GAAG,CAGjE;AAED,wBAAgB,yBAAyB,CAAC,SAAS,EAAE,GAAG,EAAE,GAAG,GAAG,CAQ/D;AAID,wBAAgB,uBAAuB,CAAC,YAAY,EAAE,MAAM,EAAE,GAAG,MAAM,CAItE;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,cAAc,EAAE,GAAG,MAAM,CAgBrE;AAED,wBAAgB,0BAA0B,CACxC,oBAAoB,EAAE,OAAO,EAC7B,mBAAmB,EAAE,OAAO,GAC3B,MAAM,CAMR;AAWD,MAAM,WAAW,gBAAgB;IAC/B;;;;;OAKG;IACH,QAAQ,EAAE,OAAO,CAAC;IAClB;;yDAEqD;IACrD,OAAO,EAAE,OAAO,EAAE,CAAC;IACnB;;kDAE8C;IAC9C,SAAS,EAAE,MAAM,CAAC;IAClB;kEAC8D;IAC9D,oBAAoB,EAAE,OAAO,CAAC;CAC/B;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,gBAAgB,GAAG,MAAM,CAwBhE"}
|
package/dist/caveats.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// Caveat builders + ABI-encoded terms.
|
|
2
|
+
//
|
|
3
|
+
// Eight on-chain enforcers (TimestampEnforcer, ValueEnforcer, etc.) + three
|
|
4
|
+
// off-chain sentinels (MCP_TOOL_SCOPE, DATA_SCOPE, DELEGATE_BINDING) whose
|
|
5
|
+
// addresses are derived via keccak256('urn:smart-agent:<name>')[0:20]. The
|
|
6
|
+
// sentinels never live on-chain; their semantics live in this package's
|
|
7
|
+
// evaluator (off-chain only).
|
|
8
|
+
import { encodeAbiParameters } from 'viem';
|
|
9
|
+
import { keccak_256 } from '@noble/hashes/sha3';
|
|
10
|
+
// ─── Off-chain sentinel addresses ────────────────────────────────────────
|
|
11
|
+
function sentinelAddress(urn) {
|
|
12
|
+
const hash = keccak_256(new TextEncoder().encode(urn));
|
|
13
|
+
let hex = '0x';
|
|
14
|
+
for (const b of hash.slice(0, 20))
|
|
15
|
+
hex += b.toString(16).padStart(2, '0');
|
|
16
|
+
return hex;
|
|
17
|
+
}
|
|
18
|
+
export const MCP_TOOL_SCOPE_ENFORCER = sentinelAddress('urn:smart-agent:mcp-tool-scope');
|
|
19
|
+
export const DATA_SCOPE_ENFORCER = sentinelAddress('urn:smart-agent:data-scope');
|
|
20
|
+
export const DELEGATE_BINDING_ENFORCER = sentinelAddress('urn:smart-agent:delegate-binding');
|
|
21
|
+
// ─── Generic caveat builder ──────────────────────────────────────────────
|
|
22
|
+
export function buildCaveat(enforcer, terms, args) {
|
|
23
|
+
return { enforcer, terms, args: args ?? '0x' };
|
|
24
|
+
}
|
|
25
|
+
// ─── On-chain enforcer term encoders ─────────────────────────────────────
|
|
26
|
+
export function encodeTimestampTerms(validAfter, validUntil) {
|
|
27
|
+
if (!Number.isInteger(validAfter) || validAfter < 0) {
|
|
28
|
+
throw new Error('encodeTimestampTerms: validAfter must be a non-negative integer');
|
|
29
|
+
}
|
|
30
|
+
if (!Number.isInteger(validUntil) || validUntil <= validAfter) {
|
|
31
|
+
throw new Error('encodeTimestampTerms: validUntil must be > validAfter');
|
|
32
|
+
}
|
|
33
|
+
return encodeAbiParameters([{ type: 'uint256' }, { type: 'uint256' }], [BigInt(validAfter), BigInt(validUntil)]);
|
|
34
|
+
}
|
|
35
|
+
export function encodeValueTerms(maxValue) {
|
|
36
|
+
if (maxValue < 0n)
|
|
37
|
+
throw new Error('encodeValueTerms: maxValue must be non-negative');
|
|
38
|
+
return encodeAbiParameters([{ type: 'uint256' }], [maxValue]);
|
|
39
|
+
}
|
|
40
|
+
export function encodeAllowedTargetsTerms(targets) {
|
|
41
|
+
if (targets.length === 0)
|
|
42
|
+
throw new Error('encodeAllowedTargetsTerms: at least one target required');
|
|
43
|
+
return encodeAbiParameters([{ type: 'address[]' }], [targets]);
|
|
44
|
+
}
|
|
45
|
+
export function encodeAllowedMethodsTerms(selectors) {
|
|
46
|
+
if (selectors.length === 0)
|
|
47
|
+
throw new Error('encodeAllowedMethodsTerms: at least one selector required');
|
|
48
|
+
for (const s of selectors) {
|
|
49
|
+
if (!/^0x[0-9a-fA-F]{8}$/.test(s)) {
|
|
50
|
+
throw new Error(`encodeAllowedMethodsTerms: selector "${s}" must be 4 bytes (0x + 8 hex chars)`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return encodeAbiParameters([{ type: 'bytes4[]' }], [selectors]);
|
|
54
|
+
}
|
|
55
|
+
// ─── Off-chain sentinel caveat builders ──────────────────────────────────
|
|
56
|
+
export function buildMcpToolScopeCaveat(allowedTools) {
|
|
57
|
+
if (allowedTools.length === 0)
|
|
58
|
+
throw new Error('buildMcpToolScopeCaveat: at least one tool required');
|
|
59
|
+
const terms = encodeAbiParameters([{ type: 'string[]' }], [allowedTools]);
|
|
60
|
+
return { enforcer: MCP_TOOL_SCOPE_ENFORCER, terms, args: '0x' };
|
|
61
|
+
}
|
|
62
|
+
export function buildDataScopeCaveat(grants) {
|
|
63
|
+
if (grants.length === 0)
|
|
64
|
+
throw new Error('buildDataScopeCaveat: at least one grant required');
|
|
65
|
+
const terms = encodeAbiParameters([
|
|
66
|
+
{
|
|
67
|
+
type: 'tuple[]',
|
|
68
|
+
components: [
|
|
69
|
+
{ name: 'server', type: 'string' },
|
|
70
|
+
{ name: 'resources', type: 'string[]' },
|
|
71
|
+
{ name: 'fields', type: 'string[]' },
|
|
72
|
+
],
|
|
73
|
+
},
|
|
74
|
+
], [grants]);
|
|
75
|
+
return { enforcer: DATA_SCOPE_ENFORCER, terms, args: '0x' };
|
|
76
|
+
}
|
|
77
|
+
export function buildDelegateBindingCaveat(delegateSmartAccount, delegatePersonAgent) {
|
|
78
|
+
const terms = encodeAbiParameters([{ type: 'address' }, { type: 'address' }], [delegateSmartAccount, delegatePersonAgent]);
|
|
79
|
+
return { enforcer: DELEGATE_BINDING_ENFORCER, terms, args: '0x' };
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Build a `QuorumEnforcer` caveat. Pair with delegations whose
|
|
83
|
+
* `tool-policy.evaluateThresholdPolicy` decision has
|
|
84
|
+
* `requiresQuorum: true` (T3 Value and above). Without this caveat,
|
|
85
|
+
* `verifyDelegationToken({ requireQuorumForTier })` fails closed.
|
|
86
|
+
*
|
|
87
|
+
* Wire format of the terms blob exactly matches what
|
|
88
|
+
* `QuorumEnforcer.beforeHook` decodes:
|
|
89
|
+
* abi.encode(address[] signerSet, uint8 threshold, address approvedHashRegistry)
|
|
90
|
+
*
|
|
91
|
+
* The redeem-time `args` are caller-supplied at execution time, not
|
|
92
|
+
* at issuance — `mcp-runtime.withDelegation` (6c.4) constructs them
|
|
93
|
+
* from the user's signed payload + signature blob and forwards them
|
|
94
|
+
* into the on-chain caveat evaluation.
|
|
95
|
+
*/
|
|
96
|
+
export function buildQuorumCaveat(opts) {
|
|
97
|
+
if (!Array.isArray(opts.signers) || opts.signers.length === 0) {
|
|
98
|
+
throw new Error('buildQuorumCaveat: signers must be a non-empty array');
|
|
99
|
+
}
|
|
100
|
+
if (!Number.isInteger(opts.threshold) || opts.threshold < 1) {
|
|
101
|
+
throw new Error('buildQuorumCaveat: threshold must be an integer ≥ 1');
|
|
102
|
+
}
|
|
103
|
+
if (opts.threshold > opts.signers.length) {
|
|
104
|
+
throw new Error(`buildQuorumCaveat: threshold (${opts.threshold}) exceeds signer set size (${opts.signers.length})`);
|
|
105
|
+
}
|
|
106
|
+
if (opts.threshold > 255) {
|
|
107
|
+
throw new Error('buildQuorumCaveat: threshold exceeds uint8 bound (255)');
|
|
108
|
+
}
|
|
109
|
+
const terms = encodeAbiParameters([
|
|
110
|
+
{ type: 'address[]' },
|
|
111
|
+
{ type: 'uint8' },
|
|
112
|
+
{ type: 'address' },
|
|
113
|
+
], [opts.signers, opts.threshold, opts.approvedHashRegistry]);
|
|
114
|
+
return { enforcer: opts.enforcer, terms, args: '0x' };
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=caveats.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"caveats.js","sourceRoot":"","sources":["../src/caveats.ts"],"names":[],"mappings":"AAAA,uCAAuC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from '@agenticprimitives/types';
|
|
2
|
+
import type { Caveat, Delegation, DelegationClientOpts } from './types';
|
|
3
|
+
export declare class DelegationClient {
|
|
4
|
+
private readonly opts;
|
|
5
|
+
constructor(opts: DelegationClientOpts);
|
|
6
|
+
/**
|
|
7
|
+
* Build a Delegation, sign it via the user's signer, return the fully
|
|
8
|
+
* populated struct. `delegator` = the smart account address; the signer
|
|
9
|
+
* is the smart account's owner EOA.
|
|
10
|
+
*/
|
|
11
|
+
issueDelegation(params: {
|
|
12
|
+
delegate: Address;
|
|
13
|
+
caveats: Caveat[];
|
|
14
|
+
salt?: bigint;
|
|
15
|
+
authority?: Hex;
|
|
16
|
+
}): Promise<Delegation>;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAaxE,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAuB;gBAChC,IAAI,EAAE,oBAAoB;IAItC;;;;OAIG;IACG,eAAe,CAAC,MAAM,EAAE;QAC5B,QAAQ,EAAE,OAAO,CAAC;QAClB,OAAO,EAAE,MAAM,EAAE,CAAC;QAClB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,SAAS,CAAC,EAAE,GAAG,CAAC;KACjB,GAAG,OAAO,CAAC,UAAU,CAAC;CA6BxB"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// DelegationClient — browser-side issuance.
|
|
2
|
+
//
|
|
3
|
+
// Given a Signer (whose backing key is the smart account's owner EOA),
|
|
4
|
+
// the user signs an EIP-712 Delegation message via signTypedData. The
|
|
5
|
+
// resulting signature, paired with the Delegation struct, becomes a
|
|
6
|
+
// fully-formed Delegation that the DelegationManager + ERC-1271 path on
|
|
7
|
+
// the smart account can validate.
|
|
8
|
+
import { ROOT_AUTHORITY } from './types';
|
|
9
|
+
import { DELEGATION_EIP712_TYPES, delegationDomain } from './hash';
|
|
10
|
+
function randomSalt() {
|
|
11
|
+
const buf = new Uint8Array(32);
|
|
12
|
+
// 32-byte random; high bit cleared to keep BigInt sign-safe (uint256 still has full range).
|
|
13
|
+
globalThis.crypto.getRandomValues(buf);
|
|
14
|
+
let n = 0n;
|
|
15
|
+
for (const b of buf)
|
|
16
|
+
n = (n << 8n) | BigInt(b);
|
|
17
|
+
return n;
|
|
18
|
+
}
|
|
19
|
+
export class DelegationClient {
|
|
20
|
+
opts;
|
|
21
|
+
constructor(opts) {
|
|
22
|
+
this.opts = opts;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Build a Delegation, sign it via the user's signer, return the fully
|
|
26
|
+
* populated struct. `delegator` = the smart account address; the signer
|
|
27
|
+
* is the smart account's owner EOA.
|
|
28
|
+
*/
|
|
29
|
+
async issueDelegation(params) {
|
|
30
|
+
const salt = params.salt ?? randomSalt();
|
|
31
|
+
const authority = params.authority ?? ROOT_AUTHORITY;
|
|
32
|
+
const delegation = {
|
|
33
|
+
delegator: this.opts.smartAccount,
|
|
34
|
+
delegate: params.delegate,
|
|
35
|
+
authority,
|
|
36
|
+
caveats: params.caveats,
|
|
37
|
+
salt,
|
|
38
|
+
};
|
|
39
|
+
const signature = await this.opts.signer.signTypedData({
|
|
40
|
+
domain: delegationDomain(this.opts.chainId, this.opts.delegationManager),
|
|
41
|
+
types: DELEGATION_EIP712_TYPES,
|
|
42
|
+
primaryType: 'Delegation',
|
|
43
|
+
message: {
|
|
44
|
+
delegator: delegation.delegator,
|
|
45
|
+
delegate: delegation.delegate,
|
|
46
|
+
authority: delegation.authority,
|
|
47
|
+
caveats: delegation.caveats.map((c) => ({
|
|
48
|
+
enforcer: c.enforcer,
|
|
49
|
+
terms: c.terms,
|
|
50
|
+
})),
|
|
51
|
+
salt: delegation.salt,
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
return { ...delegation, signature };
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,EAAE;AACF,uEAAuE;AACvE,sEAAsE;AACtE,oEAAoE;AACpE,wEAAwE;AACxE,kCAAkC;AAIlC,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAEnE,SAAS,UAAU;IACjB,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC;IAC/B,4FAA4F;IAC5F,UAAU,CAAC,MAAM,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;IACvC,IAAI,CAAC,GAAG,EAAE,CAAC;IACX,KAAK,MAAM,CAAC,IAAI,GAAG;QAAE,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IAC/C,OAAO,CAAC,CAAC;AACX,CAAC;AAED,MAAM,OAAO,gBAAgB;IACV,IAAI,CAAuB;IAC5C,YAAY,IAA0B;QACpC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,eAAe,CAAC,MAKrB;QACC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,IAAI,UAAU,EAAE,CAAC;QACzC,MAAM,SAAS,GAAG,MAAM,CAAC,SAAS,IAAI,cAAc,CAAC;QACrD,MAAM,UAAU,GAAkC;YAChD,SAAS,EAAE,IAAI,CAAC,IAAI,CAAC,YAAY;YACjC,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,SAAS;YACT,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,IAAI;SACL,CAAC;QAEF,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC;YACrD,MAAM,EAAE,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC;YACxE,KAAK,EAAE,uBAAuB;YAC9B,WAAW,EAAE,YAAY;YACzB,OAAO,EAAE;gBACP,SAAS,EAAE,UAAU,CAAC,SAAS;gBAC/B,QAAQ,EAAE,UAAU,CAAC,QAAQ;gBAC7B,SAAS,EAAE,UAAU,CAAC,SAAS;gBAC/B,OAAO,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;oBACtC,QAAQ,EAAE,CAAC,CAAC,QAAQ;oBACpB,KAAK,EAAE,CAAC,CAAC,KAAK;iBACf,CAAC,CAAC;gBACH,IAAI,EAAE,UAAU,CAAC,IAAI;aACtB;SACF,CAAC,CAAC;QAEH,OAAO,EAAE,GAAG,UAAU,EAAE,SAAS,EAAE,CAAC;IACtC,CAAC;CACF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Caveat, CaveatContext, CaveatVerdict, EnforcerAddressMap, EvaluateOpts } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Evaluate every caveat in the array. Returns one verdict per caveat,
|
|
4
|
+
* in input order. Caller decides what to do on the first deny.
|
|
5
|
+
*
|
|
6
|
+
* Unknown enforcer addresses produce a deny verdict. No exceptions.
|
|
7
|
+
*
|
|
8
|
+
* **H7-B.2:** in strict mode (the default) caveats that need a context field
|
|
9
|
+
* the caller didn't supply return `{ allowed: false, reason: 'context-required ...' }`.
|
|
10
|
+
* Callers who will redeem the delegation on-chain (where the enforcer DOES
|
|
11
|
+
* fire) can opt into permissive evaluation via `opts.enforceOnChain = true`.
|
|
12
|
+
* Off-chain gates (MCP / A2A / session-token verify) MUST stay in strict mode.
|
|
13
|
+
*/
|
|
14
|
+
export declare function evaluateCaveats(caveats: Caveat[], ctx: CaveatContext, enforcerMap: EnforcerAddressMap, opts?: EvaluateOpts): CaveatVerdict[];
|
|
15
|
+
//# sourceMappingURL=evaluator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evaluator.d.ts","sourceRoot":"","sources":["../src/evaluator.ts"],"names":[],"mappings":"AA0BA,OAAO,KAAK,EACV,MAAM,EACN,aAAa,EACb,aAAa,EACb,kBAAkB,EAClB,YAAY,EACb,MAAM,SAAS,CAAC;AAgJjB;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,MAAM,EAAE,EACjB,GAAG,EAAE,aAAa,EAClB,WAAW,EAAE,kBAAkB,EAC/B,IAAI,GAAE,YAAiB,GACtB,aAAa,EAAE,CA2BjB"}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
// Caveat evaluator — fail-closed dispatcher.
|
|
2
|
+
//
|
|
3
|
+
// Each Caveat has an `enforcer` address that selects an evaluator function.
|
|
4
|
+
// Unknown enforcer addresses → reject (no permissive default). This is a
|
|
5
|
+
// CORE security invariant per spec 202 §11. Verbatim from smart-agent.
|
|
6
|
+
//
|
|
7
|
+
// **H7-B.2 strict-mode (PKG-DELEGATION-001 closure).** Three caveat types
|
|
8
|
+
// previously returned `allowed:true` when the context field they needed was
|
|
9
|
+
// missing ("enforced on-chain"). That is a BOUNDARY TRAP: a consumer using
|
|
10
|
+
// the evaluator off-chain (MCP gate, A2A pre-check, any non-redeem path)
|
|
11
|
+
// would silently permit the call. The fix:
|
|
12
|
+
//
|
|
13
|
+
// - **Strict mode is the default** (caller does NOT pass `enforceOnChain`):
|
|
14
|
+
// missing context for Value / AllowedTargets / AllowedMethods / inert
|
|
15
|
+
// on-chain-only enforcers → `{ allowed: false, reason: 'context-required' }`.
|
|
16
|
+
//
|
|
17
|
+
// - **Permissive mode** is opt-in by callers who can prove the call WILL be
|
|
18
|
+
// redeemed on-chain (so the on-chain enforcer fires): pass
|
|
19
|
+
// `{ enforceOnChain: true }` in `EvaluateOpts`. Missing context for the
|
|
20
|
+
// same caveats then returns `allowed: true` with reason 'enforced-on-chain'.
|
|
21
|
+
//
|
|
22
|
+
// `verifyDelegationToken` requires the opt-in (off-chain JTI / session-token
|
|
23
|
+
// gating is not an on-chain redeem). Off-chain pre-checks pass strict mode;
|
|
24
|
+
// on-chain redeem flows pass `{ enforceOnChain: true }`.
|
|
25
|
+
import { decodeAbiParameters } from 'viem';
|
|
26
|
+
import { MCP_TOOL_SCOPE_ENFORCER, DATA_SCOPE_ENFORCER, DELEGATE_BINDING_ENFORCER, } from './caveats';
|
|
27
|
+
function lower(a) {
|
|
28
|
+
return a?.toLowerCase();
|
|
29
|
+
}
|
|
30
|
+
/** Permissive when caller has opted into on-chain redeem; strict otherwise. */
|
|
31
|
+
function inertWhenAllowed(c, opts) {
|
|
32
|
+
if (opts.enforceOnChain) {
|
|
33
|
+
return { enforcer: c.enforcer, allowed: true, reason: 'enforced-on-chain' };
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
enforcer: c.enforcer,
|
|
37
|
+
allowed: false,
|
|
38
|
+
reason: 'context-required (caveat type is on-chain-only; set EvaluateOpts.enforceOnChain to opt in)',
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function evalTimestamp(c, ctx) {
|
|
42
|
+
try {
|
|
43
|
+
const [validAfter, validUntil] = decodeAbiParameters([{ type: 'uint256' }, { type: 'uint256' }], c.terms);
|
|
44
|
+
const ts = BigInt(ctx.timestamp);
|
|
45
|
+
if (ts < validAfter)
|
|
46
|
+
return { enforcer: c.enforcer, allowed: false, reason: 'before validAfter' };
|
|
47
|
+
// H7-D.10 / XPKG-001-sec: align with on-chain TimestampEnforcer.sol:28
|
|
48
|
+
// (`if (block.timestamp > validUntil) revert TimestampExpired()`). The
|
|
49
|
+
// boundary is INCLUSIVE — at ts == validUntil the on-chain enforcer
|
|
50
|
+
// accepts, so the off-chain pre-check MUST also accept (else a redeem
|
|
51
|
+
// that would land on-chain gets denied at the off-chain gate).
|
|
52
|
+
if (ts > validUntil)
|
|
53
|
+
return { enforcer: c.enforcer, allowed: false, reason: 'after validUntil' };
|
|
54
|
+
return { enforcer: c.enforcer, allowed: true };
|
|
55
|
+
}
|
|
56
|
+
catch (e) {
|
|
57
|
+
return { enforcer: c.enforcer, allowed: false, reason: `timestamp decode error: ${e instanceof Error ? e.message : e}` };
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function evalValue(c, ctx, opts) {
|
|
61
|
+
if (ctx.value === undefined)
|
|
62
|
+
return inertWhenAllowed(c, opts);
|
|
63
|
+
try {
|
|
64
|
+
const [maxValue] = decodeAbiParameters([{ type: 'uint256' }], c.terms);
|
|
65
|
+
if (ctx.value > maxValue)
|
|
66
|
+
return { enforcer: c.enforcer, allowed: false, reason: 'value over cap' };
|
|
67
|
+
return { enforcer: c.enforcer, allowed: true };
|
|
68
|
+
}
|
|
69
|
+
catch (e) {
|
|
70
|
+
return { enforcer: c.enforcer, allowed: false, reason: `value decode error: ${e instanceof Error ? e.message : e}` };
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function evalAllowedTargets(c, ctx, opts) {
|
|
74
|
+
if (!ctx.target)
|
|
75
|
+
return inertWhenAllowed(c, opts);
|
|
76
|
+
try {
|
|
77
|
+
const [targets] = decodeAbiParameters([{ type: 'address[]' }], c.terms);
|
|
78
|
+
const target = ctx.target.toLowerCase();
|
|
79
|
+
if (targets.some((t) => t.toLowerCase() === target))
|
|
80
|
+
return { enforcer: c.enforcer, allowed: true };
|
|
81
|
+
return { enforcer: c.enforcer, allowed: false, reason: 'target not in allowlist' };
|
|
82
|
+
}
|
|
83
|
+
catch (e) {
|
|
84
|
+
return { enforcer: c.enforcer, allowed: false, reason: `targets decode error: ${e instanceof Error ? e.message : e}` };
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function evalAllowedMethods(c, ctx, opts) {
|
|
88
|
+
if (!ctx.selector)
|
|
89
|
+
return inertWhenAllowed(c, opts);
|
|
90
|
+
try {
|
|
91
|
+
const [selectors] = decodeAbiParameters([{ type: 'bytes4[]' }], c.terms);
|
|
92
|
+
const sel = ctx.selector.toLowerCase();
|
|
93
|
+
if (selectors.some((s) => s.toLowerCase() === sel))
|
|
94
|
+
return { enforcer: c.enforcer, allowed: true };
|
|
95
|
+
return { enforcer: c.enforcer, allowed: false, reason: 'selector not in allowlist' };
|
|
96
|
+
}
|
|
97
|
+
catch (e) {
|
|
98
|
+
return { enforcer: c.enforcer, allowed: false, reason: `methods decode error: ${e instanceof Error ? e.message : e}` };
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function evalMcpToolScope(c, ctx) {
|
|
102
|
+
if (!ctx.mcpTool)
|
|
103
|
+
return { enforcer: c.enforcer, allowed: false, reason: 'no tool name in context' };
|
|
104
|
+
try {
|
|
105
|
+
const [tools] = decodeAbiParameters([{ type: 'string[]' }], c.terms);
|
|
106
|
+
if (tools.includes(ctx.mcpTool))
|
|
107
|
+
return { enforcer: c.enforcer, allowed: true };
|
|
108
|
+
return { enforcer: c.enforcer, allowed: false, reason: 'tool not in scope' };
|
|
109
|
+
}
|
|
110
|
+
catch (e) {
|
|
111
|
+
return { enforcer: c.enforcer, allowed: false, reason: `mcp-tool-scope decode error: ${e instanceof Error ? e.message : e}` };
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function evalInert(c, _ctx, opts) {
|
|
115
|
+
// DATA_SCOPE + DELEGATE_BINDING + on-chain-only enforcers (taskBinding,
|
|
116
|
+
// callDataHash, recovery, rateLimit) are evaluated outside this dispatcher
|
|
117
|
+
// (by verifyCrossDelegation or on-chain). In strict mode (H7-B.2) we refuse
|
|
118
|
+
// to give an "allowed" verdict unless the caller has opted into
|
|
119
|
+
// `enforceOnChain` — otherwise the verdict misleads any callsite that won't
|
|
120
|
+
// reach the on-chain enforcer (e.g. an MCP-only gate).
|
|
121
|
+
//
|
|
122
|
+
// Shape checks still run unconditionally — malformed terms must reject at
|
|
123
|
+
// the closest layer to discovery to keep downstream verifiers from having
|
|
124
|
+
// to defend against garbage. Per spec 202 § 11: fail-closed on shape.
|
|
125
|
+
const enforcerLower = c.enforcer.toLowerCase();
|
|
126
|
+
if (enforcerLower === DELEGATE_BINDING_ENFORCER.toLowerCase()) {
|
|
127
|
+
try {
|
|
128
|
+
// DelegateBinding terms = abi.encode(address, address) — EXACTLY
|
|
129
|
+
// 64 bytes (0x + 128 hex chars). We assert length explicitly:
|
|
130
|
+
// viem's decoder happily ignores trailing bytes, so a 16 KiB blob
|
|
131
|
+
// whose first 64 bytes encode two addresses would otherwise pass
|
|
132
|
+
// this shape check. The CLAUDE.md regression class.
|
|
133
|
+
const expectedHexLen = 2 + 64 * 2; // "0x" + 64 bytes
|
|
134
|
+
if (c.terms.length !== expectedHexLen) {
|
|
135
|
+
return {
|
|
136
|
+
enforcer: c.enforcer,
|
|
137
|
+
allowed: false,
|
|
138
|
+
reason: `delegate-binding: terms length ${c.terms.length} ≠ expected ${expectedHexLen} (abi.encode(address,address) is exactly 64 bytes)`,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
const [smartAccount, personAgent] = decodeAbiParameters([{ type: 'address' }, { type: 'address' }], c.terms);
|
|
142
|
+
if (smartAccount === '0x0000000000000000000000000000000000000000' ||
|
|
143
|
+
personAgent === '0x0000000000000000000000000000000000000000') {
|
|
144
|
+
return {
|
|
145
|
+
enforcer: c.enforcer,
|
|
146
|
+
allowed: false,
|
|
147
|
+
reason: 'delegate-binding: zero address in terms',
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
catch (e) {
|
|
152
|
+
return {
|
|
153
|
+
enforcer: c.enforcer,
|
|
154
|
+
allowed: false,
|
|
155
|
+
reason: `delegate-binding: malformed terms — ${e instanceof Error ? e.message : e}`,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
// Shape valid; allow only if caller opted into on-chain redeem.
|
|
160
|
+
return inertWhenAllowed(c, opts);
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Evaluate every caveat in the array. Returns one verdict per caveat,
|
|
164
|
+
* in input order. Caller decides what to do on the first deny.
|
|
165
|
+
*
|
|
166
|
+
* Unknown enforcer addresses produce a deny verdict. No exceptions.
|
|
167
|
+
*
|
|
168
|
+
* **H7-B.2:** in strict mode (the default) caveats that need a context field
|
|
169
|
+
* the caller didn't supply return `{ allowed: false, reason: 'context-required ...' }`.
|
|
170
|
+
* Callers who will redeem the delegation on-chain (where the enforcer DOES
|
|
171
|
+
* fire) can opt into permissive evaluation via `opts.enforceOnChain = true`.
|
|
172
|
+
* Off-chain gates (MCP / A2A / session-token verify) MUST stay in strict mode.
|
|
173
|
+
*/
|
|
174
|
+
export function evaluateCaveats(caveats, ctx, enforcerMap, opts = {}) {
|
|
175
|
+
// Build dispatch table keyed by lowercased enforcer address.
|
|
176
|
+
const dispatch = new Map();
|
|
177
|
+
if (enforcerMap.timestamp)
|
|
178
|
+
dispatch.set(lower(enforcerMap.timestamp), evalTimestamp);
|
|
179
|
+
if (enforcerMap.value)
|
|
180
|
+
dispatch.set(lower(enforcerMap.value), evalValue);
|
|
181
|
+
if (enforcerMap.allowedTargets)
|
|
182
|
+
dispatch.set(lower(enforcerMap.allowedTargets), evalAllowedTargets);
|
|
183
|
+
if (enforcerMap.allowedMethods)
|
|
184
|
+
dispatch.set(lower(enforcerMap.allowedMethods), evalAllowedMethods);
|
|
185
|
+
// Sentinels are constant addresses regardless of chain.
|
|
186
|
+
dispatch.set(MCP_TOOL_SCOPE_ENFORCER.toLowerCase(), evalMcpToolScope);
|
|
187
|
+
dispatch.set(DATA_SCOPE_ENFORCER.toLowerCase(), evalInert);
|
|
188
|
+
dispatch.set(DELEGATE_BINDING_ENFORCER.toLowerCase(), evalInert);
|
|
189
|
+
// On-chain-only enforcers are inert here (taskBinding, callDataHash, recovery, rateLimit).
|
|
190
|
+
if (enforcerMap.taskBinding)
|
|
191
|
+
dispatch.set(lower(enforcerMap.taskBinding), evalInert);
|
|
192
|
+
if (enforcerMap.callDataHash)
|
|
193
|
+
dispatch.set(lower(enforcerMap.callDataHash), evalInert);
|
|
194
|
+
if (enforcerMap.recovery)
|
|
195
|
+
dispatch.set(lower(enforcerMap.recovery), evalInert);
|
|
196
|
+
if (enforcerMap.rateLimit)
|
|
197
|
+
dispatch.set(lower(enforcerMap.rateLimit), evalInert);
|
|
198
|
+
const verdicts = [];
|
|
199
|
+
for (const c of caveats) {
|
|
200
|
+
const fn = dispatch.get(c.enforcer.toLowerCase());
|
|
201
|
+
if (!fn) {
|
|
202
|
+
verdicts.push({ enforcer: c.enforcer, allowed: false, reason: 'unknown enforcer' });
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
verdicts.push(fn(c, ctx, opts));
|
|
206
|
+
}
|
|
207
|
+
return verdicts;
|
|
208
|
+
}
|
|
209
|
+
//# sourceMappingURL=evaluator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evaluator.js","sourceRoot":"","sources":["../src/evaluator.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,EAAE;AACF,4EAA4E;AAC5E,yEAAyE;AACzE,uEAAuE;AACvE,EAAE;AACF,0EAA0E;AAC1E,4EAA4E;AAC5E,2EAA2E;AAC3E,yEAAyE;AACzE,2CAA2C;AAC3C,EAAE;AACF,8EAA8E;AAC9E,0EAA0E;AAC1E,kFAAkF;AAClF,EAAE;AACF,8EAA8E;AAC9E,+DAA+D;AAC/D,4EAA4E;AAC5E,iFAAiF;AACjF,EAAE;AACF,6EAA6E;AAC7E,4EAA4E;AAC5E,yDAAyD;AAEzD,OAAO,EAAE,mBAAmB,EAAgB,MAAM,MAAM,C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+
export declare const DELEGATION_EIP712_TYPES: {
|
|
4
|
+
readonly Delegation: readonly [{
|
|
5
|
+
readonly name: "delegator";
|
|
6
|
+
readonly type: "address";
|
|
7
|
+
}, {
|
|
8
|
+
readonly name: "delegate";
|
|
9
|
+
readonly type: "address";
|
|
10
|
+
}, {
|
|
11
|
+
readonly name: "authority";
|
|
12
|
+
readonly type: "bytes32";
|
|
13
|
+
}, {
|
|
14
|
+
readonly name: "caveats";
|
|
15
|
+
readonly type: "Caveat[]";
|
|
16
|
+
}, {
|
|
17
|
+
readonly name: "salt";
|
|
18
|
+
readonly type: "uint256";
|
|
19
|
+
}];
|
|
20
|
+
readonly Caveat: readonly [{
|
|
21
|
+
readonly name: "enforcer";
|
|
22
|
+
readonly type: "address";
|
|
23
|
+
}, {
|
|
24
|
+
readonly name: "terms";
|
|
25
|
+
readonly type: "bytes";
|
|
26
|
+
}];
|
|
27
|
+
};
|
|
28
|
+
export declare function delegationDomain(chainId: number, delegationManager: Address): {
|
|
29
|
+
name: string;
|
|
30
|
+
version: string;
|
|
31
|
+
chainId: number;
|
|
32
|
+
verifyingContract: `0x${string}`;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* EIP-712 hash of a Delegation. This is the value the smart-account owner
|
|
36
|
+
* signs (via signTypedData / personal_sign of the digest) and the value
|
|
37
|
+
* AgentDelegationManager validates via ERC-1271.
|
|
38
|
+
*/
|
|
39
|
+
export declare function hashDelegation(d: Delegation, chainId: number, delegationManager: Address): Hex;
|
|
40
|
+
/**
|
|
41
|
+
* keccak256 of the ABI-encoded caveat array. Mirrors what
|
|
42
|
+
* AgentDelegationManager computes for caveat enforcement bookkeeping.
|
|
43
|
+
*/
|
|
44
|
+
export declare function hashCaveats(caveats: Caveat[]): Hex;
|
|
45
|
+
//# sourceMappingURL=hash.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":"AAOA,OAAO,EAAiD,KAAK,GAAG,EAAE,KAAK,OAAO,EAAE,MAAM,MAAM,CAAC;AAC7F,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAKlD,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;CAkB1B,CAAC;AAEX,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,OAAO;;;;;EAO3E;AAWD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,OAAO,GAAG,GAAG,CAa9F;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,GAAG,CAclD"}
|