@keelcodes/manifest 0.1.0

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 ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Keel contributors
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,139 @@
1
+ # @keelcodes/manifest
2
+
3
+ Consume and produce **[ERC-8313 Protocol Interaction Manifests][erc8313]** (PIM).
4
+
5
+ A PIM is a machine-readable JSON document describing *how* to interact with a
6
+ smart-contract protocol — not just its ABI, but the ordered workflow that
7
+ fulfils a user intent. It is an **untrusted input**: it arrives from a dApp, a
8
+ registry or a peer agent, so it must be validated and graded before anything is
9
+ executed.
10
+
11
+ This package is the Keel side of that:
12
+
13
+ - **consume** — `validatePim` checks an untrusted document against the standard;
14
+ `trustLevelOf` verifies signatures and assigns a trust level.
15
+ - **produce** — `buildKeelPim` emits Keel's own manifest, describing the Keel
16
+ policy hook and the ERC-8312 bounded-action substrate.
17
+
18
+ Everything is a pure function (no I/O; `trustLevelOf` is async only because
19
+ signer recovery is). The same code runs in a wallet, an agent, an MCP server or
20
+ the bundled CLI.
21
+
22
+ ## What it validates
23
+
24
+ The nine mandatory top-level objects are always required:
25
+
26
+ `schemaVersion`, `metadata`, `contracts`, `types`, `lookups`, `calculations`,
27
+ `intents`, `ui`, `signatures`.
28
+
29
+ `validatePim` returns `{ valid, errors, warnings }`; `valid` is `true` only when
30
+ there are no `errors`. Key rules:
31
+
32
+ - `metadata`: all required fields, the `category` enum, a semver `pimVersion`,
33
+ and a non-empty `chainId`.
34
+ - `contracts.*`: exactly one of `address` / `lookup` (both or neither is an
35
+ error), the `role` enum, and a required `description`. A `lookup` must name an
36
+ entry in `lookups`.
37
+ - `lookups.*`: `contract` must resolve to `contracts`; `function`/`args`/
38
+ `returns` are required; `validate` assertions need at least one operator;
39
+ `selectCriterion` is only allowed alongside `select`.
40
+ - `types.*`: the `kind` enum and a required `fields` map.
41
+ - `calculations.*`: required `description`/`formula` (with a `set` instruction)
42
+ and the `precision` enum.
43
+ - `intents.*`: at least one intent, each with `description` / `requiredInputs` /
44
+ `steps`; step ids must start at 1 and not skip; `buildTransaction` steps need
45
+ a declared `contract`, a `function` and a `description`.
46
+ - `ui.intentDescriptions` must cover every named intent.
47
+ - Semantic gates: pass `{ now }` to reject an expired (or not-yet-valid) PIM, and
48
+ `{ chainId }` to reject one that does not scope the current network — both are
49
+ "execution engines MUST reject" rules in the standard.
50
+
51
+ ## Usage
52
+
53
+ ```ts
54
+ import { validatePim, trustLevelOf, buildKeelPim } from '@keelcodes/manifest';
55
+
56
+ const result = validatePim(untrusted, { now: Math.floor(Date.now() / 1000), chainId: 8453 });
57
+ if (!result.valid) throw new Error(JSON.stringify(result.errors));
58
+
59
+ const trust = await trustLevelOf(untrusted, {
60
+ protocolSigners: ['0x…'], // addresses on the protocol's website / ENS
61
+ knownCommunitySigners: ['0x…'],
62
+ walletVerifiedSigners: ['0x…'],
63
+ });
64
+
65
+ const keel = buildKeelPim({
66
+ policyHook: '0x…', // required, never defaulted
67
+ boundedActions: '0x…', // required, never defaulted
68
+ chainId: [8453],
69
+ });
70
+ ```
71
+
72
+ Keel's `buildKeelPim` output is asserted to pass `validatePim` in this package's
73
+ tests, so the manifest and the validator can never silently drift apart.
74
+
75
+ ## CLI
76
+
77
+ The consumer CLI reads the built package (`pnpm build` first) and needs no
78
+ third-party argument parser (`node:util` `parseArgs` only):
79
+
80
+ ```bash
81
+ pnpm --filter @keelcodes/manifest build
82
+
83
+ node scripts/pim.mjs validate scripts/fixtures/valid.pim.json # exits non-zero on any error
84
+ node scripts/pim.mjs validate /path/to/manifest.json --chain-id 8453 --now 1800000000
85
+ node scripts/pim.mjs inspect scripts/fixtures/valid.pim.json # protocol/chains/intents/trust/contracts
86
+ node scripts/pim.mjs keel --chain-id 8453 \
87
+ --policy-hook 0x1234567890abcdef1234567890abcdef12345678 \
88
+ --bounded-actions 0xabcdefabcdefabcdefabcdefabcdefabcdefabcd
89
+ ```
90
+
91
+ `validate` prints one `[severity] path: message` line per issue and exits `1`
92
+ when any error is present — suitable for CI or a wallet's pre-flight gate.
93
+
94
+ ## Trust levels
95
+
96
+ ERC-8313 defines four levels. This package assigns them from the `signatures`
97
+ section:
98
+
99
+ | Level | Name | Assigned when |
100
+ |---|---|---|
101
+ | 0 | Unverified | no signature, an unverifiable signature, or a verified signer that is in no known registry |
102
+ | 1 | Community | verified signature from a `knownCommunitySigners` address |
103
+ | 2 | Protocol Signed | verified signature from a `protocolSigners` address |
104
+ | 3 | Wallet Verified | verified signature from a `walletVerifiedSigners` address |
105
+
106
+ Registry membership is deliberately caller-supplied: a library cannot know which
107
+ address is "on the protocol's website" or "pinned by the wallet team". A
108
+ cryptographically valid signature that is in no registry still grades Level 0,
109
+ exactly as the standard's "signer address is unknown" criterion requires.
110
+
111
+ ### How a signature is verified
112
+
113
+ The standard says the signature is "of the keccak256 hash of the entire PIM
114
+ excluding the signatures section", with whitespace removed. It does **not** say
115
+ whether that hash is signed directly (raw digest) or wrapped in EIP-191. This
116
+ package tries both interpretations (`recoverAddress` and
117
+ `recoverMessageAddress`) and reports which one matched. It never reports a
118
+ signature as verified unless it actually recovers to the declared `signer`.
119
+
120
+ ## Unverified fields and honest boundaries
121
+
122
+ - Aligned with the **draft of 2026-06-19** (author Paul Angus Bark, [PR
123
+ #1836][pr]). Drafts change; treat this as a point-in-time implementation.
124
+ - **Step-level lookup reference is not pinned by the draft.** The standard says
125
+ lookups "are referenced by name in intent steps" but its all-step-types field
126
+ table does not name the field. Keel's own manifest uses `lookup: "<name>"` and
127
+ the validator only *warns* on a dangling reference — it never rejects a
128
+ manifest for using a different, spec-valid field name.
129
+ - **Signature payload style is ambiguous** (raw digest vs EIP-191), as described
130
+ above. Both are attempted; unverifiable signatures are reported as such.
131
+ - **Level 3 (Wallet Verified) is not derivable from the document.** The standard
132
+ defines it as an internal wallet decision; it can only be assigned when the
133
+ caller supplies the wallet's pinned signers.
134
+ - `buildKeelPim` **never fabricates addresses or signatures**: the hook/substrate
135
+ addresses are required arguments, and `signatures` is `[]` (Level 0 by
136
+ construction). Signing the manifest is a release-time step, not library logic.
137
+
138
+ [erc8313]: https://eips.ethereum.org/EIPS/eip-8313
139
+ [pr]: https://github.com/ethereum/ERCs/pull/1836
@@ -0,0 +1,23 @@
1
+ import type { Pim } from './types.js';
2
+ export interface BuildKeelPimOptions {
3
+ /** Deployed `KeelPolicyHook` address (ERC-7579 hook module). Required. */
4
+ policyHook: string;
5
+ /** Deployed `KeelBoundedActions` address (ERC-8312 substrate). Required. */
6
+ boundedActions: string;
7
+ /** Chains the addresses are valid on. Defaults to `[1, 56, 8453]`. */
8
+ chainId?: number[];
9
+ /** Semantic version of the manifest document. Defaults to `"1.0.0"`. */
10
+ pimVersion?: string;
11
+ /** Author website. Defaults to `"https://keel.codes"`. */
12
+ website?: string;
13
+ /** Optional validity window (unix seconds). */
14
+ validFrom?: number;
15
+ validUntil?: number;
16
+ }
17
+ /**
18
+ * Build Keel's PIM from the caller's deployed addresses.
19
+ *
20
+ * @throws {PimBuildError} when an address is missing or not a valid hex address.
21
+ */
22
+ export declare function buildKeelPim(options: BuildKeelPimOptions): Pim;
23
+ //# sourceMappingURL=build.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAc,GAAG,EAAsB,MAAM,YAAY,CAAC;AAEtE,MAAM,WAAW,mBAAmB;IAClC,0EAA0E;IAC1E,UAAU,EAAE,MAAM,CAAC;IACnB,4EAA4E;IAC5E,cAAc,EAAE,MAAM,CAAC;IACvB,sEAAsE;IACtE,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,wEAAwE;IACxE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,0DAA0D;IAC1D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,+CAA+C;IAC/C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAMD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,GAAG,CA8I9D"}
package/dist/build.js ADDED
@@ -0,0 +1,177 @@
1
+ // ============================================================================
2
+ // Keel's own ERC-8313 Protocol Interaction Manifest.
3
+ //
4
+ // This is the *producer* half of the package: a description of Keel's on-chain
5
+ // interaction surface, emitted by code so it can never drift from the packages
6
+ // it documents. The output is asserted to pass `validatePim` in the tests.
7
+ //
8
+ // Honesty boundaries baked in here:
9
+ // * Contract addresses are NEVER defaulted or hard-coded. The caller must
10
+ // supply the deployed `KeelPolicyHook` and `KeelBoundedActions` addresses;
11
+ // a missing/invalid address is a hard build error, not a placeholder.
12
+ // * `signatures` is `[]`. Keel does not sign its own PIM here, so the manifest
13
+ // is Level 0 (Unverified) by construction — the manifest must not pretend
14
+ // otherwise. Signing is a deployment/release-time step, not library logic.
15
+ // ============================================================================
16
+ import { isAddress } from 'viem';
17
+ import { PimBuildError } from './errors.js';
18
+ const DEFAULT_CHAIN_IDS = [1, 56, 8453];
19
+ const DEFAULT_PIM_VERSION = '1.0.0';
20
+ const DEFAULT_WEBSITE = 'https://keel.codes';
21
+ /**
22
+ * Build Keel's PIM from the caller's deployed addresses.
23
+ *
24
+ * @throws {PimBuildError} when an address is missing or not a valid hex address.
25
+ */
26
+ export function buildKeelPim(options) {
27
+ const policyHook = assertAddress(options.policyHook, 'policyHook');
28
+ const boundedActions = assertAddress(options.boundedActions, 'boundedActions');
29
+ const chainId = options.chainId ?? [...DEFAULT_CHAIN_IDS];
30
+ const metadata = {
31
+ protocol: 'Keel',
32
+ description: 'Keel is an ERC-7579 account-abstraction stack for autonomous agents: policy-bounded sessions enforced by an on-chain hook, escrowed by ERC-8312 bounded-action envelopes.',
33
+ category: 'other',
34
+ website: options.website ?? DEFAULT_WEBSITE,
35
+ author: 'Keel',
36
+ chainId,
37
+ pimVersion: options.pimVersion ?? DEFAULT_PIM_VERSION,
38
+ };
39
+ if (options.validFrom !== undefined)
40
+ metadata.validFrom = options.validFrom;
41
+ if (options.validUntil !== undefined)
42
+ metadata.validUntil = options.validUntil;
43
+ return {
44
+ schemaVersion: '1.0.0',
45
+ metadata,
46
+ contracts: {
47
+ // The hook is where the account's only execution path is gated; the
48
+ // substrate owns the cross-call aggregate budget.
49
+ policyHook: {
50
+ address: policyHook,
51
+ role: 'other',
52
+ description: 'KeelPolicyHook (ERC-7579 hook, module type 4): enforces the Keel policy DSL on the account and charges the bound ERC-8312 envelope.',
53
+ },
54
+ boundedActions: {
55
+ address: boundedActions,
56
+ role: 'registry',
57
+ description: 'KeelBoundedActions (ERC-8312 substrate): the envelope registry and cursor the account draws against.',
58
+ },
59
+ },
60
+ types: {
61
+ // Field-for-field mirror of IERC8312.Envelope.
62
+ Envelope: tuple('An ERC-8312 envelope: an immutable capability commitment plus a mutable aggregate-state commitment.', {
63
+ id: { type: 'bytes32', description: 'Deterministic envelope id.' },
64
+ principal: { type: 'address', description: 'Account the envelope is bound to.' },
65
+ capabilityRoot: { type: 'bytes32', description: 'keccak256 of the canonical capability encoding.' },
66
+ cursorRoot: { type: 'bytes32', description: 'keccak256 of the current cursor encoding.' },
67
+ createdAt: { type: 'uint64', unit: 'seconds', description: 'Registration timestamp.' },
68
+ expiresAt: { type: 'uint64', unit: 'seconds', description: 'Expiry timestamp; 0 means no expiry.' },
69
+ status: { type: 'uint8', description: 'IERC-8312 Status enum: 0 None, 1 Active, 2 Completed, 3 Contested, 4 Revoked, 5 Expired.' },
70
+ }),
71
+ // Field-for-field mirror of KeelBoundedActions.Cursor.
72
+ Cursor: tuple('The running aggregate state behind an envelope cursorRoot.', {
73
+ spent: { type: 'uint256', description: 'Total amount drawn so far.' },
74
+ draws: { type: 'uint256', description: 'Number of accepted draws.' },
75
+ lastAdvance: { type: 'uint256', unit: 'seconds', description: 'Timestamp of the last accepted draw.' },
76
+ }),
77
+ },
78
+ lookups: {
79
+ getCursor: lookup('Read the cursorRoot of an envelope.', 'boundedActions', 'getCursor', 'bytes32'),
80
+ getStatus: lookup('Read the effective lifecycle status of an envelope.', 'boundedActions', 'getStatus', 'uint8'),
81
+ isActive: lookup('Whether an envelope is Active and not expired.', 'boundedActions', 'isActive', 'bool'),
82
+ },
83
+ calculations: {},
84
+ intents: {
85
+ grantBoundedSession: {
86
+ description: 'Register a bounded-action envelope for the principal and bind it to the account session so the hook charges its aggregate budget.',
87
+ requiredInputs: ['principal', 'capabilityRoot', 'expiresAt', 'initData', 'sessionId'],
88
+ steps: [
89
+ {
90
+ id: 1,
91
+ action: 'buildTransaction',
92
+ description: 'Register the ERC-8312 envelope on the substrate.',
93
+ storeAs: 'envelopeId',
94
+ contract: 'boundedActions',
95
+ function: 'registerEnvelope',
96
+ args: {
97
+ principal: '{{principal}}',
98
+ capabilityRoot: '{{capabilityRoot}}',
99
+ expiresAt: '{{expiresAt}}',
100
+ initData: '{{initData}}',
101
+ },
102
+ },
103
+ {
104
+ id: 2,
105
+ action: 'buildTransaction',
106
+ description: 'Bind the envelope to the session so the hook charges it on the execution path.',
107
+ contract: 'policyHook',
108
+ function: 'bindEnvelope',
109
+ args: { sessionId: '{{sessionId}}', registry: '{{contracts.boundedActions.address}}', envelopeId: '{{envelopeId}}' },
110
+ },
111
+ ],
112
+ },
113
+ drawBoundedAction: {
114
+ description: 'Draw once against an active envelope, advancing its cursor by the requested amount.',
115
+ requiredInputs: ['envelopeId', 'amount', 'witness'],
116
+ steps: [
117
+ {
118
+ id: 1,
119
+ action: 'lookup',
120
+ lookup: 'isActive',
121
+ description: 'Fail fast unless the envelope is Active and unexpired.',
122
+ storeAs: 'active',
123
+ },
124
+ {
125
+ id: 2,
126
+ action: 'buildTransaction',
127
+ description: 'Advance the cursor by one accepted draw against the witness.',
128
+ contract: 'boundedActions',
129
+ function: 'advanceCursor',
130
+ args: { id: '{{envelopeId}}', witness: '{{witness}}' },
131
+ },
132
+ ],
133
+ },
134
+ readEnvelope: {
135
+ description: 'Read an envelope: its lifecycle status, cursor commitment and whether it is currently active.',
136
+ requiredInputs: ['envelopeId'],
137
+ steps: [
138
+ { id: 1, action: 'lookup', lookup: 'getStatus', description: 'Read the effective status.', storeAs: 'status' },
139
+ { id: 2, action: 'lookup', lookup: 'getCursor', description: 'Read the cursor commitment.', storeAs: 'cursor' },
140
+ { id: 3, action: 'lookup', lookup: 'isActive', description: 'Read whether the envelope is active.', storeAs: 'active' },
141
+ ],
142
+ },
143
+ },
144
+ ui: {
145
+ labels: {
146
+ principal: 'Principal',
147
+ capabilityRoot: 'Capability root',
148
+ expiresAt: 'Expires at',
149
+ envelopeId: 'Envelope',
150
+ amount: 'Draw amount',
151
+ status: 'Status',
152
+ cursor: 'Cursor',
153
+ active: 'Active',
154
+ },
155
+ intentDescriptions: {
156
+ grantBoundedSession: 'Grant a bounded session for {{principal}} until {{expiresAt}}.',
157
+ drawBoundedAction: 'Draw {{amount}} from envelope {{envelopeId}}.',
158
+ readEnvelope: 'Read envelope {{envelopeId}}.',
159
+ },
160
+ },
161
+ // Keel does not sign its own PIM: unsigned = Level 0 by construction.
162
+ signatures: [],
163
+ };
164
+ }
165
+ function tuple(description, fields) {
166
+ return { kind: 'tuple', description, fields };
167
+ }
168
+ function lookup(description, contract, fn, returns) {
169
+ return { description, contract, function: fn, args: { id: '{{envelopeId}}' }, returns };
170
+ }
171
+ function assertAddress(value, name) {
172
+ if (typeof value !== 'string' || !isAddress(value)) {
173
+ throw new PimBuildError(`"${name}" must be a valid 20-byte hex address, got ${JSON.stringify(value)}`);
174
+ }
175
+ return value;
176
+ }
177
+ //# sourceMappingURL=build.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build.js","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,qDAAqD;AACrD,EAAE;AACF,+EAA+E;AAC/E,+EAA+E;AAC/E,2EAA2E;AAC3E,EAAE;AACF,o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C,WAAmB,EAAE,MAAyB;IAC3D,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC;AAChD,CAAC;AAED,SAAS,MAAM,CACb,WAAmB,EACnB,QAAgB,EAChB,EAAU,EACV,OAAe;IAEf,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,gBAAgB,EAAE,EAAE,OAAO,EAAE,CAAC;AAC1F,CAAC;AAED,SAAS,aAAa,CAAC,KAAa,EAAE,IAAY;IAChD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;QACnD,MAAM,IAAI,aAAa,CAAC,IAAI,IAAI,8CAA8C,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACzG,CAAC;IACD,OAAO,KAAmB,CAAC;AAC7B,CAAC"}
@@ -0,0 +1,5 @@
1
+ /** Raised when a PIM cannot be built from the provided inputs (e.g. a bad address). */
2
+ export declare class PimBuildError extends Error {
3
+ constructor(message: string);
4
+ }
5
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,uFAAuF;AACvF,qBAAa,aAAc,SAAQ,KAAK;gBAC1B,OAAO,EAAE,MAAM;CAI5B"}
package/dist/errors.js ADDED
@@ -0,0 +1,8 @@
1
+ /** Raised when a PIM cannot be built from the provided inputs (e.g. a bad address). */
2
+ export class PimBuildError extends Error {
3
+ constructor(message) {
4
+ super(message);
5
+ this.name = 'PimBuildError';
6
+ }
7
+ }
8
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,uFAAuF;AACvF,MAAM,OAAO,aAAc,SAAQ,KAAK;IACtC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;IAC9B,CAAC;CACF"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @keelcodes/manifest
3
+ *
4
+ * ERC-8313 Protocol Interaction Manifest (PIM) — the consumer side (validate an
5
+ * untrusted manifest, grade its trust) and the producer side (emit Keel's own
6
+ * PIM). Pure functions, no I/O: the same code runs in a wallet, an agent, an MCP
7
+ * server or a CLI.
8
+ *
9
+ * Aligned with the draft of 2026-06-19 (author Paul Angus Bark, PR #1836). Where
10
+ * the draft does not pin a field, this package says so rather than guessing —
11
+ * see the README's "Unverified fields".
12
+ *
13
+ * @packageDocumentation
14
+ */
15
+ export { CALCULATION_PRECISIONS, CONTRACT_ROLES, FILTER_OPERATORS, PIM_CATEGORIES, PIM_SECTIONS, SELECT_MODES, STEP_ACTIONS, TYPE_KINDS, VALIDATE_OPERATORS, } from './types.js';
16
+ export type { CalculationPrecision, ContractRole, FilterOperator, Hex, HexAddress, Pim, PimCalculation, PimCategory, PimContract, PimField, PimIntent, PimIssue, PimLookup, PimMetadata, PimSection, PimSignature, PimStep, PimType, PimUi, PimValidateAssertion, SelectMode, SignatureType, StepAction, TypeKind, ValidateOperator, } from './types.js';
17
+ export { PIM_DRAFT, validatePim } from './validate.js';
18
+ export type { PimValidationOptions, PimValidationResult } from './validate.js';
19
+ export { TRUST_LEVELS, canonicalPimJson, pimDigest, trustLevelOf } from './trust.js';
20
+ export type { SignatureRecovery, SignatureScheme, TrustInfo, TrustLevel, TrustLevelDefinition, TrustLevelName, TrustOptions, } from './trust.js';
21
+ export { buildKeelPim } from './build.js';
22
+ export type { BuildKeelPimOptions } from './build.js';
23
+ export { PimBuildError } from './errors.js';
24
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EACL,sBAAsB,EACtB,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,kBAAkB,GACnB,MAAM,YAAY,CAAC;AACpB,YAAY,EACV,oBAAoB,EACpB,YAAY,EACZ,cAAc,EACd,GAAG,EACH,UAAU,EACV,GAAG,EACH,cAAc,EACd,WAAW,EACX,WAAW,EACX,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,SAAS,EACT,WAAW,EACX,UAAU,EACV,YAAY,EACZ,OAAO,EACP,OAAO,EACP,KAAK,EACL,oBAAoB,EACpB,UAAU,EACV,aAAa,EACb,UAAU,EACV,QAAQ,EACR,gBAAgB,GACjB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACvD,YAAY,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAE/E,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AACrF,YAAY,EACV,iBAAiB,EACjB,eAAe,EACf,SAAS,EACT,UAAU,EACV,oBAAoB,EACpB,cAAc,EACd,YAAY,GACb,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,YAAY,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEtD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @keelcodes/manifest
3
+ *
4
+ * ERC-8313 Protocol Interaction Manifest (PIM) — the consumer side (validate an
5
+ * untrusted manifest, grade its trust) and the producer side (emit Keel's own
6
+ * PIM). Pure functions, no I/O: the same code runs in a wallet, an agent, an MCP
7
+ * server or a CLI.
8
+ *
9
+ * Aligned with the draft of 2026-06-19 (author Paul Angus Bark, PR #1836). Where
10
+ * the draft does not pin a field, this package says so rather than guessing —
11
+ * see the README's "Unverified fields".
12
+ *
13
+ * @packageDocumentation
14
+ */
15
+ export { CALCULATION_PRECISIONS, CONTRACT_ROLES, FILTER_OPERATORS, PIM_CATEGORIES, PIM_SECTIONS, SELECT_MODES, STEP_ACTIONS, TYPE_KINDS, VALIDATE_OPERATORS, } from './types.js';
16
+ export { PIM_DRAFT, validatePim } from './validate.js';
17
+ export { TRUST_LEVELS, canonicalPimJson, pimDigest, trustLevelOf } from './trust.js';
18
+ export { buildKeelPim } from './build.js';
19
+ export { PimBuildError } from './errors.js';
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EACL,sBAAsB,EACtB,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,kBAAkB,GACnB,MAAM,YAAY,CAAC;AA6BpB,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAGvD,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAWrF,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAG1C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC"}