@keelcodes/migrate 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,170 @@
1
+ # @keelcodes/migrate
2
+
3
+ Lazy, **dual-module migration** tooling for ERC-7579 session validators.
4
+
5
+ The account is already an ERC-7579 account — only the *module* changes. That means
6
+ no account migration, no key rotation and no asset movement: the account address,
7
+ its owner and its balances are untouched. The operator needs exactly three things,
8
+ and this package is those three:
9
+
10
+ - **Version routing** — session records carry a `module_version`; new sessions go
11
+ to the new module while in-flight ones keep their old encoding.
12
+ - **A migration state machine** — `not-migrated → migrating → migrated`, with
13
+ `exception` for a failed probe and explicit `retry` / `rollback`.
14
+ - **The probe** — the two on-chain assertions that catch a silent, AA24-class
15
+ no-op install *before* traffic is cut over.
16
+
17
+ It has **no runtime dependencies** (only `vitest` for its own tests), so it can be
18
+ dropped into a relay, a migration script or a CI job.
19
+
20
+ ## Why lazy
21
+
22
+ Rewriting every session record up front means a flag day, a maintenance window and
23
+ a rollback plan you will probably never test. Instead:
24
+
25
+ - A record written **before** the version column existed has no `moduleVersion`.
26
+ It routes to the registry's **default** generation and keeps working until it
27
+ expires or is revoked — no backfill required.
28
+ - A record that **does** carry a version routes to that exact generation, so old
29
+ encodings keep validating while the fleet moves over.
30
+ - The cut-over, when it happens, is on the session-rotation path: *revoke or
31
+ rotate is the migration*.
32
+
33
+ ## Routing
34
+
35
+ ```ts
36
+ import { createModuleRegistry, routeSession } from '@keelcodes/migrate';
37
+
38
+ const registry = createModuleRegistry([
39
+ // oldest first — the last descriptor becomes the default
40
+ { version: 'v1', address: '0x…', encoding: 'payload', multiSession: false, enforcedLimits: false },
41
+ { version: 'v2', address: '0x…', encoding: 'onchain', multiSession: true, enforcedLimits: true },
42
+ ]);
43
+
44
+ routeSession(registry, { id: 's-1' }); // → v2 (default, legacy record)
45
+ routeSession(registry, { id: 's-2', moduleVersion: 'v1' }); // → v1 (in-flight)
46
+ routeSession(registry, { id: 's-3', moduleVersion: 'v9' }); // throws unknown-module-version
47
+ ```
48
+
49
+ `ModuleDescriptor` records what the router must know about one generation: its
50
+ `encoding` (`onchain` on OxaChain, `payload` elsewhere), whether it allows more
51
+ than one session per account (`multiSession`) and whether spend limits are
52
+ enforced **on-chain** rather than off-chain only (`enforcedLimits`).
53
+
54
+ ## The probe (silent AA24)
55
+
56
+ Installing a module and having it *enforce* something are two different facts. An
57
+ install can register a module on the account (`isModuleInstalled == true`) while
58
+ the module's own `onInstall` silently no-ops — a mismatched `initData` layout, or
59
+ a value it ignored. Nothing reverts, the account looks configured, and the module
60
+ enforces nothing.
61
+
62
+ The probe therefore asserts **both** halves:
63
+
64
+ | Half | Reads |
65
+ |---|---|
66
+ | `isModuleInstalled` | the **account**: `isModuleInstalled(moduleTypeId, module, 0x)` |
67
+ | `isModuleInitialized` | the **module**: `IModule.isInitialized(account)` |
68
+
69
+ ```ts
70
+ import { probeModule } from '@keelcodes/migrate';
71
+
72
+ const result = await probeModule(probe, { account, module, moduleTypeId: 4n });
73
+ // { installed: true, initialized: false, ok: false,
74
+ // reason: 'module is installed but isInitialized() is false — silent no-op install (AA24-class)' }
75
+ ```
76
+
77
+ `ok` is only true when **both** hold. `ModuleProbe` is a port — back it with viem
78
+ in production and a fake in tests.
79
+
80
+ ## Rehearsal on a fork
81
+
82
+ Rehearse the probe against a real chain **before** pointing it at production,
83
+ with no credentials and no real transactions. `@keelcodes/adapters` ships a
84
+ viem-backed `ModuleProbe` whose shape matches this package's port, so the two
85
+ compose without migrate taking on a viem dependency:
86
+
87
+ ```ts
88
+ import { createPublicClient, http } from 'viem';
89
+ import { bsc } from 'viem/chains';
90
+ import { createViemModuleProbe } from '@keelcodes/adapters';
91
+ import { probeModule } from '@keelcodes/migrate';
92
+
93
+ const client = createPublicClient({ chain: bsc, transport: http() });
94
+ const probe = createViemModuleProbe(client); // structurally a ModuleProbe
95
+
96
+ await probeModule(probe, { account, module, moduleTypeId: 4n });
97
+ ```
98
+
99
+ `createViemModuleProbe` reads `isModuleInstalled` from the **account** and
100
+ `isInitialized` from the **module**; a module that does not implement
101
+ `isInitialized` resolves to `false` rather than throwing, so the probe returns the
102
+ AA24 reason above instead of crashing.
103
+
104
+ The adapters package also ships a drill that forks BSC, validates the real address
105
+ book and runs both the positive and negative probe paths against a freshly
106
+ deployed hook — writing only to the fork:
107
+
108
+ ```bash
109
+ pnpm --filter @keelcodes/adapters build # the drill loads the built package
110
+ pnpm --filter @keelcodes/adapters fork-drill
111
+ ```
112
+
113
+ `BSC_RPC_URL` overrides the default fork source
114
+ (`https://bsc-dataseed.bnbchain.org`); anvil listens on port 8546. The drill exits
115
+ non-zero if any real address has lost its code or an assertion fails, and always
116
+ tears the fork down.
117
+
118
+ ## The state machine
119
+
120
+ ```
121
+ not-migrated --begin--> migrating --confirm--> migrated
122
+ | ^
123
+ fail | | retry
124
+ v |
125
+ exception --rollback--> not-migrated
126
+ ```
127
+
128
+ - Only `begin` is reachable from `not-migrated`.
129
+ - `migrated` is **terminal**: once both probes pass, the cut-over is one-way.
130
+ - A failed probe lands in `exception`, never in `migrated` — the account keeps
131
+ running the old module until an operator `retry`s or `rollback`s.
132
+ - `confirm` **requires** a passing probe result; confirming without one throws
133
+ `probe-failed`.
134
+
135
+ `applyMigrationAction` is a pure reducer (never mutates); `migrateSession` runs one
136
+ whole step — `begin`, probe, then `confirm` on success or `fail` into `exception`:
137
+
138
+ ```ts
139
+ import { migrateSession } from '@keelcodes/migrate';
140
+
141
+ const next = await migrateSession({
142
+ record: { account, sessionId, fromVersion: 'v1', toVersion: 'v2', status: 'not-migrated', updatedAt },
143
+ probe,
144
+ probeArgs: { account, module: v2Module, moduleTypeId: 4n },
145
+ at: new Date().toISOString(),
146
+ });
147
+ // status: 'migrated' on a clean probe, 'exception' otherwise
148
+ ```
149
+
150
+ ## Errors
151
+
152
+ Every failure is a `MigrationError` with a stable `code`:
153
+
154
+ | code | when |
155
+ |---|---|
156
+ | `unknown-module-version` | a session references a version the registry does not know |
157
+ | `duplicate-module-version` | two descriptors share a version |
158
+ | `no-default-version` | the registry is empty, or its default is unregistered |
159
+ | `invalid-transition` | the action is not reachable from the current status |
160
+ | `probe-failed` | `confirm` was called with a missing or failing probe |
161
+
162
+ ## Develop
163
+
164
+ ```bash
165
+ pnpm --filter @keelcodes/migrate test
166
+ pnpm --filter @keelcodes/migrate typecheck
167
+ ```
168
+
169
+ The migration plan itself (dual-module, grey release, rollback) is in
170
+ [`docs/KEEL_PLAN.md`](../../docs/KEEL_PLAN.md) §7.
@@ -0,0 +1,6 @@
1
+ export type MigrationErrorCode = 'unknown-module-version' | 'duplicate-module-version' | 'no-default-version' | 'invalid-transition' | 'probe-failed';
2
+ export declare class MigrationError extends Error {
3
+ readonly code: MigrationErrorCode;
4
+ constructor(code: MigrationErrorCode, message: string);
5
+ }
6
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,kBAAkB,GAC1B,wBAAwB,GACxB,0BAA0B,GAC1B,oBAAoB,GACpB,oBAAoB,GACpB,cAAc,CAAC;AAEnB,qBAAa,cAAe,SAAQ,KAAK;IACvC,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAC;gBAEtB,IAAI,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM;CAKtD"}
package/dist/errors.js ADDED
@@ -0,0 +1,9 @@
1
+ export class MigrationError extends Error {
2
+ code;
3
+ constructor(code, message) {
4
+ super(message);
5
+ this.name = 'MigrationError';
6
+ this.code = code;
7
+ }
8
+ }
9
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAOA,MAAM,OAAO,cAAe,SAAQ,KAAK;IAC9B,IAAI,CAAqB;IAElC,YAAY,IAAwB,EAAE,OAAe;QACnD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @keelcodes/migrate
3
+ *
4
+ * Lazy migration tooling for ERC-7579 session validators.
5
+ *
6
+ * The account is already ERC-7579 — only the *module* changes. That means no
7
+ * account migration, no key rotation, no asset movement: the account address,
8
+ * owner and balances are untouched. What the operator needs is three things,
9
+ * and this package is exactly those three:
10
+ *
11
+ * - **Version routing** — session records carry a `module_version`; new sessions
12
+ * go to the new module while in-flight ones keep their old encoding.
13
+ * - **A migration state machine** — `not-migrated → migrating → migrated`, with
14
+ * `exception` for a failed probe and explicit `retry` / `rollback`.
15
+ * - **The probe** — the two on-chain assertions that catch a silent, AA24-class
16
+ * no-op install before traffic is cut over.
17
+ */
18
+ export { MigrationError } from './errors.js';
19
+ export type { MigrationErrorCode } from './errors.js';
20
+ export { createModuleRegistry, routeSession } from './routing.js';
21
+ export type { CreateModuleRegistryOptions, ModuleDescriptor, ModuleRegistry, ModuleVersion, SessionRecord, ValidationEncoding, } from './routing.js';
22
+ export { probeModule } from './probe.js';
23
+ export type { ModuleProbe, ProbeArgs, ProbeResult } from './probe.js';
24
+ export { applyMigrationAction, canApplyMigrationAction, isTerminalMigrationStatus, migrateSession, } from './migration.js';
25
+ export type { MigrateSessionArgs, MigrationAction, MigrationActionInput, MigrationRecord, MigrationStatus, } from './migration.js';
26
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,YAAY,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEtD,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAClE,YAAY,EACV,2BAA2B,EAC3B,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,aAAa,EACb,kBAAkB,GACnB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,YAAY,EAAE,WAAW,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEtE,OAAO,EACL,oBAAoB,EACpB,uBAAuB,EACvB,yBAAyB,EACzB,cAAc,GACf,MAAM,gBAAgB,CAAC;AACxB,YAAY,EACV,kBAAkB,EAClB,eAAe,EACf,oBAAoB,EACpB,eAAe,EACf,eAAe,GAChB,MAAM,gBAAgB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @keelcodes/migrate
3
+ *
4
+ * Lazy migration tooling for ERC-7579 session validators.
5
+ *
6
+ * The account is already ERC-7579 — only the *module* changes. That means no
7
+ * account migration, no key rotation, no asset movement: the account address,
8
+ * owner and balances are untouched. What the operator needs is three things,
9
+ * and this package is exactly those three:
10
+ *
11
+ * - **Version routing** — session records carry a `module_version`; new sessions
12
+ * go to the new module while in-flight ones keep their old encoding.
13
+ * - **A migration state machine** — `not-migrated → migrating → migrated`, with
14
+ * `exception` for a failed probe and explicit `retry` / `rollback`.
15
+ * - **The probe** — the two on-chain assertions that catch a silent, AA24-class
16
+ * no-op install before traffic is cut over.
17
+ */
18
+ export { MigrationError } from './errors.js';
19
+ export { createModuleRegistry, routeSession } from './routing.js';
20
+ export { probeModule } from './probe.js';
21
+ export { applyMigrationAction, canApplyMigrationAction, isTerminalMigrationStatus, migrateSession, } from './migration.js';
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAG7C,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAUlE,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAGzC,OAAO,EACL,oBAAoB,EACpB,uBAAuB,EACvB,yBAAyB,EACzB,cAAc,GACf,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,59 @@
1
+ import { type ModuleProbe, type ProbeArgs, type ProbeResult } from './probe.js';
2
+ import type { ModuleVersion } from './routing.js';
3
+ /**
4
+ * The lazy-migration state machine.
5
+ *
6
+ * ```
7
+ * not-migrated --begin--> migrating --confirm--> migrated
8
+ * | ^
9
+ * fail | | retry
10
+ * v |
11
+ * exception --rollback--> not-migrated
12
+ * ```
13
+ *
14
+ * Only `begin` is reachable from `not-migrated`, and `migrated` is terminal: a
15
+ * migration is a one-way cut-over once both probes pass. A failed probe lands in
16
+ * `exception`, never in `migrated` — the account keeps running the old module
17
+ * until an operator retries or rolls back.
18
+ */
19
+ export type MigrationStatus = 'not-migrated' | 'migrating' | 'migrated' | 'exception';
20
+ export type MigrationAction = 'begin' | 'confirm' | 'fail' | 'retry' | 'rollback';
21
+ export interface MigrationRecord {
22
+ account: string;
23
+ sessionId: string;
24
+ fromVersion: ModuleVersion;
25
+ toVersion: ModuleVersion;
26
+ status: MigrationStatus;
27
+ /** ISO-8601 timestamp of the last transition. */
28
+ updatedAt: string;
29
+ reason?: string;
30
+ }
31
+ export declare function isTerminalMigrationStatus(status: MigrationStatus): boolean;
32
+ export declare function canApplyMigrationAction(status: MigrationStatus, action: MigrationAction): boolean;
33
+ export interface MigrationActionInput {
34
+ /** ISO-8601 timestamp of this transition. */
35
+ at: string;
36
+ /** Required by `confirm` — the double-probe outcome. */
37
+ probe?: ProbeResult;
38
+ /** Recorded by `fail` / `rollback`. */
39
+ reason?: string;
40
+ }
41
+ /** Applies one action, returning the next record. Pure — never mutates. */
42
+ export declare function applyMigrationAction(record: MigrationRecord, action: MigrationAction, input: MigrationActionInput): MigrationRecord;
43
+ export interface MigrateSessionArgs {
44
+ record: MigrationRecord;
45
+ probe: ModuleProbe;
46
+ /** Passed straight to the probe: the account + module that must be live. */
47
+ probeArgs: ProbeArgs;
48
+ /** ISO-8601 timestamp for every transition in this run. */
49
+ at: string;
50
+ }
51
+ /**
52
+ * One lazy migration step: `begin`, run the double probe, then `confirm` on
53
+ * success or `fail` into `exception`.
54
+ *
55
+ * This is the "revoke or rotate *is* the migration" path — invoked when a session
56
+ * is rotated or revoked, so nothing is paid for until a legacy session is touched.
57
+ */
58
+ export declare function migrateSession(args: MigrateSessionArgs): Promise<MigrationRecord>;
59
+ //# sourceMappingURL=migration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migration.d.ts","sourceRoot":"","sources":["../src/migration.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,KAAK,WAAW,EAAE,KAAK,SAAS,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAC7F,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,eAAe,GAAG,cAAc,GAAG,WAAW,GAAG,UAAU,GAAG,WAAW,CAAC;AAEtF,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,GAAG,OAAO,GAAG,UAAU,CAAC;AASlF,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,aAAa,CAAC;IAC3B,SAAS,EAAE,aAAa,CAAC;IACzB,MAAM,EAAE,eAAe,CAAC;IACxB,iDAAiD;IACjD,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAE1E;AAED,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,eAAe,EAAE,MAAM,EAAE,eAAe,GAAG,OAAO,CAEjG;AAED,MAAM,WAAW,oBAAoB;IACnC,6CAA6C;IAC7C,EAAE,EAAE,MAAM,CAAC;IACX,wDAAwD;IACxD,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,uCAAuC;IACvC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,2EAA2E;AAC3E,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,eAAe,EACvB,MAAM,EAAE,eAAe,EACvB,KAAK,EAAE,oBAAoB,GAC1B,eAAe,CA6BjB;AAED,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,eAAe,CAAC;IACxB,KAAK,EAAE,WAAW,CAAC;IACnB,4EAA4E;IAC5E,SAAS,EAAE,SAAS,CAAC;IACrB,2DAA2D;IAC3D,EAAE,EAAE,MAAM,CAAC;CACZ;AAED;;;;;;GAMG;AACH,wBAAsB,cAAc,CAAC,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,eAAe,CAAC,CAOvF"}
@@ -0,0 +1,56 @@
1
+ import { MigrationError } from './errors.js';
2
+ import { probeModule } from './probe.js';
3
+ const TRANSITIONS = {
4
+ 'not-migrated': ['begin'],
5
+ migrating: ['confirm', 'fail'],
6
+ exception: ['retry', 'rollback'],
7
+ migrated: [],
8
+ };
9
+ export function isTerminalMigrationStatus(status) {
10
+ return TRANSITIONS[status].length === 0;
11
+ }
12
+ export function canApplyMigrationAction(status, action) {
13
+ return TRANSITIONS[status].includes(action);
14
+ }
15
+ /** Applies one action, returning the next record. Pure — never mutates. */
16
+ export function applyMigrationAction(record, action, input) {
17
+ if (!TRANSITIONS[record.status].includes(action)) {
18
+ throw new MigrationError('invalid-transition', `migration ${record.account}/${record.sessionId} is ${record.status}; cannot ${action}`);
19
+ }
20
+ switch (action) {
21
+ case 'begin':
22
+ case 'retry':
23
+ return { ...record, status: 'migrating', updatedAt: input.at, reason: undefined };
24
+ case 'confirm': {
25
+ if (input.probe === undefined || !input.probe.ok) {
26
+ const reason = input.probe === undefined ? 'no probe result supplied' : input.probe.reason;
27
+ throw new MigrationError('probe-failed', `cannot confirm migration: ${reason ?? 'probe failed'}`);
28
+ }
29
+ return { ...record, status: 'migrated', updatedAt: input.at, reason: undefined };
30
+ }
31
+ case 'fail':
32
+ return {
33
+ ...record,
34
+ status: 'exception',
35
+ updatedAt: input.at,
36
+ reason: input.reason ?? 'migration failed',
37
+ };
38
+ case 'rollback':
39
+ return { ...record, status: 'not-migrated', updatedAt: input.at, reason: input.reason };
40
+ }
41
+ }
42
+ /**
43
+ * One lazy migration step: `begin`, run the double probe, then `confirm` on
44
+ * success or `fail` into `exception`.
45
+ *
46
+ * This is the "revoke or rotate *is* the migration" path — invoked when a session
47
+ * is rotated or revoked, so nothing is paid for until a legacy session is touched.
48
+ */
49
+ export async function migrateSession(args) {
50
+ const migrating = applyMigrationAction(args.record, 'begin', { at: args.at });
51
+ const result = await probeModule(args.probe, args.probeArgs);
52
+ return result.ok
53
+ ? applyMigrationAction(migrating, 'confirm', { at: args.at, probe: result })
54
+ : applyMigrationAction(migrating, 'fail', { at: args.at, reason: result.reason });
55
+ }
56
+ //# sourceMappingURL=migration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migration.js","sourceRoot":"","sources":["../src/migration.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * The migration probe: the two on-chain assertions that separate "the module is
3
+ * registered" from "the module actually enforces something".
4
+ *
5
+ * An install can register a module on the account (`isModuleInstalled == true`)
6
+ * while the module's own `onInstall` silently no-ops — a mismatched `initData`
7
+ * layout, or a value it ignored. Nothing reverts, the account looks configured,
8
+ * and the module enforces nothing. Cutting traffic over on that state is an
9
+ * AA24-class silent failure, so both halves must be asserted.
10
+ */
11
+ export interface ModuleProbe {
12
+ /** ERC-7579 `isModuleInstalled(moduleTypeId, module, additionalContext)` on the account. */
13
+ isModuleInstalled(args: {
14
+ account: string;
15
+ module: string;
16
+ moduleTypeId: bigint;
17
+ }): Promise<boolean>;
18
+ /** ERC-7579 `IModule.isInitialized(smartAccount)` on the module. */
19
+ isModuleInitialized(module: string, account: string): Promise<boolean>;
20
+ }
21
+ export interface ProbeArgs {
22
+ account: string;
23
+ module: string;
24
+ moduleTypeId: bigint;
25
+ }
26
+ export interface ProbeResult {
27
+ installed: boolean;
28
+ initialized: boolean;
29
+ ok: boolean;
30
+ /** Why the probe failed, when it did. */
31
+ reason?: string;
32
+ }
33
+ /** Reads both halves of the probe; `ok` only when both hold. */
34
+ export declare function probeModule(probe: ModuleProbe, args: ProbeArgs): Promise<ProbeResult>;
35
+ //# sourceMappingURL=probe.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"probe.d.ts","sourceRoot":"","sources":["../src/probe.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,WAAW,WAAW;IAC1B,4FAA4F;IAC5F,iBAAiB,CAAC,IAAI,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACrG,oEAAoE;IACpE,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACxE;AAED,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,OAAO,CAAC;IACnB,WAAW,EAAE,OAAO,CAAC;IACrB,EAAE,EAAE,OAAO,CAAC;IACZ,yCAAyC;IACzC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,gEAAgE;AAChE,wBAAsB,WAAW,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,WAAW,CAAC,CAsB3F"}
package/dist/probe.js ADDED
@@ -0,0 +1,23 @@
1
+ /** Reads both halves of the probe; `ok` only when both hold. */
2
+ export async function probeModule(probe, args) {
3
+ const installed = await probe.isModuleInstalled(args);
4
+ if (!installed) {
5
+ return {
6
+ installed: false,
7
+ initialized: false,
8
+ ok: false,
9
+ reason: 'module is not installed on the account',
10
+ };
11
+ }
12
+ const initialized = await probe.isModuleInitialized(args.module, args.account);
13
+ if (!initialized) {
14
+ return {
15
+ installed: true,
16
+ initialized: false,
17
+ ok: false,
18
+ reason: 'module is installed but isInitialized() is false — silent no-op install (AA24-class)',
19
+ };
20
+ }
21
+ return { installed: true, initialized: true, ok: true };
22
+ }
23
+ //# sourceMappingURL=probe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"probe.js","sourceRoot":"","sources":["../src/probe.ts"],"names":[],"mappings":"AA+BA,gEAAgE;AAChE,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,KAAkB,EAAE,IAAe;IACnE,MAAM,SAAS,GAAG,MAAM,KAAK,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;IACtD,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO;YACL,SAAS,EAAE,KAAK;YAChB,WAAW,EAAE,KAAK;YAClB,EAAE,EAAE,KAAK;YACT,MAAM,EAAE,wCAAwC;SACjD,CAAC;IACJ,CAAC;IAED,MAAM,WAAW,GAAG,MAAM,KAAK,CAAC,mBAAmB,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IAC/E,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO;YACL,SAAS,EAAE,IAAI;YACf,WAAW,EAAE,KAAK;YAClB,EAAE,EAAE,KAAK;YACT,MAAM,EAAE,sFAAsF;SAC/F,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;AAC1D,CAAC"}
@@ -0,0 +1,47 @@
1
+ /** A module generation. Mirrors the `module_version` column in the session store. */
2
+ export type ModuleVersion = string;
3
+ /** How a session's `validateUserOp` payload is signed. */
4
+ export type ValidationEncoding = 'onchain' | 'payload';
5
+ /** What the router needs to know about one module generation. */
6
+ export interface ModuleDescriptor {
7
+ version: ModuleVersion;
8
+ /** Deployed module address, when known. */
9
+ address?: string;
10
+ encoding: ValidationEncoding;
11
+ /** Whether this generation allows more than one session per account. */
12
+ multiSession: boolean;
13
+ /** Whether spend limits are enforced on-chain, not off-chain only. */
14
+ enforcedLimits: boolean;
15
+ }
16
+ export interface ModuleRegistry {
17
+ readonly defaultVersion: ModuleVersion;
18
+ get(version: ModuleVersion): ModuleDescriptor | undefined;
19
+ list(): readonly ModuleDescriptor[];
20
+ /** The generation new sessions are written to. */
21
+ default(): ModuleDescriptor;
22
+ }
23
+ export interface CreateModuleRegistryOptions {
24
+ /**
25
+ * Generation new (version-less) sessions route to. Defaults to the last
26
+ * descriptor added, so callers can list generations oldest-first and let the
27
+ * newest win.
28
+ */
29
+ defaultVersion?: ModuleVersion;
30
+ }
31
+ /** Builds a registry from module descriptors, oldest generation first. */
32
+ export declare function createModuleRegistry(descriptors: readonly ModuleDescriptor[], options?: CreateModuleRegistryOptions): ModuleRegistry;
33
+ /** A session record as stored by the relay; the version column may be absent. */
34
+ export interface SessionRecord {
35
+ id: string;
36
+ /** Absent on records written before the version column existed. */
37
+ moduleVersion?: ModuleVersion;
38
+ }
39
+ /**
40
+ * Routes a session to its module generation.
41
+ *
42
+ * A version-less record (pre-backfill) routes to the default generation — the
43
+ * "lazy" half of lazy migration: legacy sessions are never rewritten, they just
44
+ * keep working until they expire or are revoked.
45
+ */
46
+ export declare function routeSession(registry: ModuleRegistry, session: SessionRecord): ModuleDescriptor;
47
+ //# sourceMappingURL=routing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routing.d.ts","sourceRoot":"","sources":["../src/routing.ts"],"names":[],"mappings":"AAEA,qFAAqF;AACrF,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC;AAEnC,0DAA0D;AAC1D,MAAM,MAAM,kBAAkB,GAAG,SAAS,GAAG,SAAS,CAAC;AAEvD,iEAAiE;AACjE,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,aAAa,CAAC;IACvB,2CAA2C;IAC3C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,wEAAwE;IACxE,YAAY,EAAE,OAAO,CAAC;IACtB,sEAAsE;IACtE,cAAc,EAAE,OAAO,CAAC;CACzB;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,cAAc,EAAE,aAAa,CAAC;IACvC,GAAG,CAAC,OAAO,EAAE,aAAa,GAAG,gBAAgB,GAAG,SAAS,CAAC;IAC1D,IAAI,IAAI,SAAS,gBAAgB,EAAE,CAAC;IACpC,kDAAkD;IAClD,OAAO,IAAI,gBAAgB,CAAC;CAC7B;AAED,MAAM,WAAW,2BAA2B;IAC1C;;;;OAIG;IACH,cAAc,CAAC,EAAE,aAAa,CAAC;CAChC;AAED,0EAA0E;AAC1E,wBAAgB,oBAAoB,CAClC,WAAW,EAAE,SAAS,gBAAgB,EAAE,EACxC,OAAO,GAAE,2BAAgC,GACxC,cAAc,CAyBhB;AAED,iFAAiF;AACjF,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,mEAAmE;IACnE,aAAa,CAAC,EAAE,aAAa,CAAC;CAC/B;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,cAAc,EAAE,OAAO,EAAE,aAAa,GAAG,gBAAgB,CAW/F"}
@@ -0,0 +1,42 @@
1
+ import { MigrationError } from './errors.js';
2
+ /** Builds a registry from module descriptors, oldest generation first. */
3
+ export function createModuleRegistry(descriptors, options = {}) {
4
+ if (descriptors.length === 0) {
5
+ throw new MigrationError('no-default-version', 'a module registry needs at least one descriptor');
6
+ }
7
+ const byVersion = new Map();
8
+ for (const descriptor of descriptors) {
9
+ if (byVersion.has(descriptor.version)) {
10
+ throw new MigrationError('duplicate-module-version', `module version ${descriptor.version} registered twice`);
11
+ }
12
+ byVersion.set(descriptor.version, descriptor);
13
+ }
14
+ const defaultVersion = options.defaultVersion ?? descriptors[descriptors.length - 1].version;
15
+ const defaultDescriptor = byVersion.get(defaultVersion);
16
+ if (defaultDescriptor === undefined) {
17
+ throw new MigrationError('no-default-version', `default version ${defaultVersion} is not registered`);
18
+ }
19
+ return {
20
+ defaultVersion,
21
+ get: (version) => byVersion.get(version),
22
+ list: () => [...byVersion.values()],
23
+ default: () => defaultDescriptor,
24
+ };
25
+ }
26
+ /**
27
+ * Routes a session to its module generation.
28
+ *
29
+ * A version-less record (pre-backfill) routes to the default generation — the
30
+ * "lazy" half of lazy migration: legacy sessions are never rewritten, they just
31
+ * keep working until they expire or are revoked.
32
+ */
33
+ export function routeSession(registry, session) {
34
+ if (session.moduleVersion === undefined)
35
+ return registry.default();
36
+ const descriptor = registry.get(session.moduleVersion);
37
+ if (descriptor === undefined) {
38
+ throw new MigrationError('unknown-module-version', `session ${session.id} references unregistered module version ${session.moduleVersion}`);
39
+ }
40
+ return descriptor;
41
+ }
42
+ //# sourceMappingURL=routing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routing.js","sourceRoot":"","sources":["../src/routing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAqC7C,0EAA0E;AAC1E,MAAM,UAAU,oBAAoB,CAClC,WAAwC,EACxC,UAAuC,EAAE;IAEzC,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,cAAc,CAAC,oBAAoB,EAAE,iDAAiD,CAAC,CAAC;IACpG,CAAC;IAED,MAAM,SAAS,GAAG,IAAI,GAAG,EAAmC,CAAC;IAC7D,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;QACrC,IAAI,SAAS,CAAC,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;YACtC,MAAM,IAAI,cAAc,CAAC,0BAA0B,EAAE,kBAAkB,UAAU,CAAC,OAAO,mBAAmB,CAAC,CAAC;QAChH,CAAC;QACD,SAAS,CAAC,GAAG,CAAC,UAAU,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;IAChD,CAAC;IAED,MAAM,cAAc,GAAG,OAAO,CAAC,cAAc,IAAI,WAAW,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,CAAE,CAAC,OAAO,CAAC;IAC9F,MAAM,iBAAiB,GAAG,SAAS,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IACxD,IAAI,iBAAiB,KAAK,SAAS,EAAE,CAAC;QACpC,MAAM,IAAI,cAAc,CAAC,oBAAoB,EAAE,mBAAmB,cAAc,oBAAoB,CAAC,CAAC;IACxG,CAAC;IAED,OAAO;QACL,cAAc;QACd,GAAG,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC;QACxC,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC;QACnC,OAAO,EAAE,GAAG,EAAE,CAAC,iBAAiB;KACjC,CAAC;AACJ,CAAC;AASD;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,QAAwB,EAAE,OAAsB;IAC3E,IAAI,OAAO,CAAC,aAAa,KAAK,SAAS;QAAE,OAAO,QAAQ,CAAC,OAAO,EAAE,CAAC;IAEnE,MAAM,UAAU,GAAG,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IACvD,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;QAC7B,MAAM,IAAI,cAAc,CACtB,wBAAwB,EACxB,WAAW,OAAO,CAAC,EAAE,2CAA2C,OAAO,CAAC,aAAa,EAAE,CACxF,CAAC;IACJ,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@keelcodes/migrate",
3
+ "version": "0.1.0",
4
+ "description": "Lazy, dual-module migration tooling for ERC-7579 session validators: version routing, a migration state machine and the silent-AA24 probe.",
5
+ "license": "Apache-2.0",
6
+ "homepage": "https://keel.codes",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/keelcodes/keel.git",
10
+ "directory": "packages/migrate"
11
+ },
12
+ "type": "module",
13
+ "main": "./dist/index.js",
14
+ "types": "./dist/index.d.ts",
15
+ "exports": {
16
+ ".": {
17
+ "types": "./dist/index.d.ts",
18
+ "import": "./dist/index.js"
19
+ }
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "README.md"
24
+ ],
25
+ "sideEffects": false,
26
+ "devDependencies": {
27
+ "vitest": "^2.1.4"
28
+ },
29
+ "publishConfig": {
30
+ "access": "public"
31
+ },
32
+ "engines": {
33
+ "node": ">=20"
34
+ },
35
+ "keywords": [
36
+ "erc-7579",
37
+ "erc-4337",
38
+ "session-key",
39
+ "module-migration",
40
+ "account-abstraction",
41
+ "agent"
42
+ ],
43
+ "scripts": {
44
+ "build": "tsc -p tsconfig.json",
45
+ "typecheck": "tsc -p tsconfig.json --noEmit",
46
+ "test": "vitest run",
47
+ "clean": "rm -rf dist"
48
+ }
49
+ }