@lit-protocol/vincent-ability-sdk 0.0.1-ea
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/CHANGELOG.md +64 -0
- package/CONTRIBUTING.md +117 -0
- package/README.md +213 -0
- package/dist/package.json +44 -0
- package/dist/src/index.d.ts +15 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +21 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/internal.d.ts +12 -0
- package/dist/src/internal.d.ts.map +1 -0
- package/dist/src/internal.js +32 -0
- package/dist/src/internal.js.map +1 -0
- package/dist/src/lib/abilityCore/abilityConfig/context/abilityContext.d.ts +28 -0
- package/dist/src/lib/abilityCore/abilityConfig/context/abilityContext.d.ts.map +1 -0
- package/dist/src/lib/abilityCore/abilityConfig/context/abilityContext.js +51 -0
- package/dist/src/lib/abilityCore/abilityConfig/context/abilityContext.js.map +1 -0
- package/dist/src/lib/abilityCore/abilityConfig/context/resultCreators.d.ts +18 -0
- package/dist/src/lib/abilityCore/abilityConfig/context/resultCreators.d.ts.map +1 -0
- package/dist/src/lib/abilityCore/abilityConfig/context/resultCreators.js +48 -0
- package/dist/src/lib/abilityCore/abilityConfig/context/resultCreators.js.map +1 -0
- package/dist/src/lib/abilityCore/abilityConfig/context/types.d.ts +31 -0
- package/dist/src/lib/abilityCore/abilityConfig/context/types.d.ts.map +1 -0
- package/dist/src/lib/abilityCore/abilityConfig/context/types.js +9 -0
- package/dist/src/lib/abilityCore/abilityConfig/context/types.js.map +1 -0
- package/dist/src/lib/abilityCore/abilityConfig/types.d.ts +20 -0
- package/dist/src/lib/abilityCore/abilityConfig/types.d.ts.map +1 -0
- package/dist/src/lib/abilityCore/abilityConfig/types.js +4 -0
- package/dist/src/lib/abilityCore/abilityConfig/types.js.map +1 -0
- package/dist/src/lib/abilityCore/bundledAbility/bundledAbility.d.ts +5 -0
- package/dist/src/lib/abilityCore/bundledAbility/bundledAbility.d.ts.map +1 -0
- package/dist/src/lib/abilityCore/bundledAbility/bundledAbility.js +21 -0
- package/dist/src/lib/abilityCore/bundledAbility/bundledAbility.js.map +1 -0
- package/dist/src/lib/abilityCore/bundledAbility/types.d.ts +18 -0
- package/dist/src/lib/abilityCore/bundledAbility/types.d.ts.map +1 -0
- package/dist/src/lib/abilityCore/bundledAbility/types.js +4 -0
- package/dist/src/lib/abilityCore/bundledAbility/types.js.map +1 -0
- package/dist/src/lib/abilityCore/helpers/getMappedAbilityPolicyParams.d.ts +5 -0
- package/dist/src/lib/abilityCore/helpers/getMappedAbilityPolicyParams.d.ts.map +1 -0
- package/dist/src/lib/abilityCore/helpers/getMappedAbilityPolicyParams.js +18 -0
- package/dist/src/lib/abilityCore/helpers/getMappedAbilityPolicyParams.js.map +1 -0
- package/dist/src/lib/abilityCore/helpers/getPkpInfo.d.ts +10 -0
- package/dist/src/lib/abilityCore/helpers/getPkpInfo.d.ts.map +1 -0
- package/dist/src/lib/abilityCore/helpers/getPkpInfo.js +26 -0
- package/dist/src/lib/abilityCore/helpers/getPkpInfo.js.map +1 -0
- package/dist/src/lib/abilityCore/helpers/index.d.ts +5 -0
- package/dist/src/lib/abilityCore/helpers/index.d.ts.map +1 -0
- package/dist/src/lib/abilityCore/helpers/index.js +12 -0
- package/dist/src/lib/abilityCore/helpers/index.js.map +1 -0
- package/dist/src/lib/abilityCore/helpers/resultCreators.d.ts +21 -0
- package/dist/src/lib/abilityCore/helpers/resultCreators.d.ts.map +1 -0
- package/dist/src/lib/abilityCore/helpers/resultCreators.js +48 -0
- package/dist/src/lib/abilityCore/helpers/resultCreators.js.map +1 -0
- package/dist/src/lib/abilityCore/helpers/supportedPoliciesForAbility.d.ts +55 -0
- package/dist/src/lib/abilityCore/helpers/supportedPoliciesForAbility.d.ts.map +1 -0
- package/dist/src/lib/abilityCore/helpers/supportedPoliciesForAbility.js +68 -0
- package/dist/src/lib/abilityCore/helpers/supportedPoliciesForAbility.js.map +1 -0
- package/dist/src/lib/abilityCore/helpers/typeGuards.d.ts +8 -0
- package/dist/src/lib/abilityCore/helpers/typeGuards.d.ts.map +1 -0
- package/dist/src/lib/abilityCore/helpers/typeGuards.js +28 -0
- package/dist/src/lib/abilityCore/helpers/typeGuards.js.map +1 -0
- package/dist/src/lib/abilityCore/helpers/validatePolicies.d.ts +24 -0
- package/dist/src/lib/abilityCore/helpers/validatePolicies.d.ts.map +1 -0
- package/dist/src/lib/abilityCore/helpers/validatePolicies.js +31 -0
- package/dist/src/lib/abilityCore/helpers/validatePolicies.js.map +1 -0
- package/dist/src/lib/abilityCore/helpers/zod.d.ts +43 -0
- package/dist/src/lib/abilityCore/helpers/zod.d.ts.map +1 -0
- package/dist/src/lib/abilityCore/helpers/zod.js +70 -0
- package/dist/src/lib/abilityCore/helpers/zod.js.map +1 -0
- package/dist/src/lib/abilityCore/vincentAbility.d.ts +54 -0
- package/dist/src/lib/abilityCore/vincentAbility.d.ts.map +1 -0
- package/dist/src/lib/abilityCore/vincentAbility.js +162 -0
- package/dist/src/lib/abilityCore/vincentAbility.js.map +1 -0
- package/dist/src/lib/assertSupportedAbilityVersion.d.ts +2 -0
- package/dist/src/lib/assertSupportedAbilityVersion.d.ts.map +1 -0
- package/dist/src/lib/assertSupportedAbilityVersion.js +15 -0
- package/dist/src/lib/assertSupportedAbilityVersion.js.map +1 -0
- package/dist/src/lib/constants.d.ts +2 -0
- package/dist/src/lib/constants.d.ts.map +1 -0
- package/dist/src/lib/constants.js +5 -0
- package/dist/src/lib/constants.js.map +1 -0
- package/dist/src/lib/handlers/constants.d.ts +2 -0
- package/dist/src/lib/handlers/constants.d.ts.map +1 -0
- package/dist/src/lib/handlers/constants.js +6 -0
- package/dist/src/lib/handlers/constants.js.map +1 -0
- package/dist/src/lib/handlers/evaluatePolicies.d.ts +11 -0
- package/dist/src/lib/handlers/evaluatePolicies.d.ts.map +1 -0
- package/dist/src/lib/handlers/evaluatePolicies.js +110 -0
- package/dist/src/lib/handlers/evaluatePolicies.js.map +1 -0
- package/dist/src/lib/handlers/vincentAbilityHandler.d.ts +15 -0
- package/dist/src/lib/handlers/vincentAbilityHandler.d.ts.map +1 -0
- package/dist/src/lib/handlers/vincentAbilityHandler.js +160 -0
- package/dist/src/lib/handlers/vincentAbilityHandler.js.map +1 -0
- package/dist/src/lib/handlers/vincentPolicyHandler.d.ts +13 -0
- package/dist/src/lib/handlers/vincentPolicyHandler.d.ts.map +1 -0
- package/dist/src/lib/handlers/vincentPolicyHandler.js +70 -0
- package/dist/src/lib/handlers/vincentPolicyHandler.js.map +1 -0
- package/dist/src/lib/policyCore/bundledPolicy/bundledPolicy.d.ts +5 -0
- package/dist/src/lib/policyCore/bundledPolicy/bundledPolicy.d.ts.map +1 -0
- package/dist/src/lib/policyCore/bundledPolicy/bundledPolicy.js +21 -0
- package/dist/src/lib/policyCore/bundledPolicy/bundledPolicy.js.map +1 -0
- package/dist/src/lib/policyCore/bundledPolicy/types.d.ts +17 -0
- package/dist/src/lib/policyCore/bundledPolicy/types.d.ts.map +1 -0
- package/dist/src/lib/policyCore/bundledPolicy/types.js +4 -0
- package/dist/src/lib/policyCore/bundledPolicy/types.js.map +1 -0
- package/dist/src/lib/policyCore/helpers/index.d.ts +5 -0
- package/dist/src/lib/policyCore/helpers/index.d.ts.map +1 -0
- package/dist/src/lib/policyCore/helpers/index.js +16 -0
- package/dist/src/lib/policyCore/helpers/index.js.map +1 -0
- package/dist/src/lib/policyCore/helpers/resultCreators.d.ts +38 -0
- package/dist/src/lib/policyCore/helpers/resultCreators.d.ts.map +1 -0
- package/dist/src/lib/policyCore/helpers/resultCreators.js +89 -0
- package/dist/src/lib/policyCore/helpers/resultCreators.js.map +1 -0
- package/dist/src/lib/policyCore/helpers/typeGuards.d.ts +7 -0
- package/dist/src/lib/policyCore/helpers/typeGuards.d.ts.map +1 -0
- package/dist/src/lib/policyCore/helpers/typeGuards.js +23 -0
- package/dist/src/lib/policyCore/helpers/typeGuards.js.map +1 -0
- package/dist/src/lib/policyCore/helpers/zod.d.ts +55 -0
- package/dist/src/lib/policyCore/helpers/zod.d.ts.map +1 -0
- package/dist/src/lib/policyCore/helpers/zod.js +82 -0
- package/dist/src/lib/policyCore/helpers/zod.js.map +1 -0
- package/dist/src/lib/policyCore/index.d.ts +3 -0
- package/dist/src/lib/policyCore/index.d.ts.map +1 -0
- package/dist/src/lib/policyCore/index.js +8 -0
- package/dist/src/lib/policyCore/index.js.map +1 -0
- package/dist/src/lib/policyCore/policyConfig/context/policyConfigContext.d.ts +12 -0
- package/dist/src/lib/policyCore/policyConfig/context/policyConfigContext.d.ts.map +1 -0
- package/dist/src/lib/policyCore/policyConfig/context/policyConfigContext.js +20 -0
- package/dist/src/lib/policyCore/policyConfig/context/policyConfigContext.js.map +1 -0
- package/dist/src/lib/policyCore/policyConfig/context/resultCreators.d.ts +6 -0
- package/dist/src/lib/policyCore/policyConfig/context/resultCreators.d.ts.map +1 -0
- package/dist/src/lib/policyCore/policyConfig/context/resultCreators.js +30 -0
- package/dist/src/lib/policyCore/policyConfig/context/resultCreators.js.map +1 -0
- package/dist/src/lib/policyCore/policyConfig/context/types.d.ts +24 -0
- package/dist/src/lib/policyCore/policyConfig/context/types.d.ts.map +1 -0
- package/dist/src/lib/policyCore/policyConfig/context/types.js +5 -0
- package/dist/src/lib/policyCore/policyConfig/context/types.js.map +1 -0
- package/dist/src/lib/policyCore/policyConfig/types.d.ts +46 -0
- package/dist/src/lib/policyCore/policyConfig/types.d.ts.map +1 -0
- package/dist/src/lib/policyCore/policyConfig/types.js +3 -0
- package/dist/src/lib/policyCore/policyConfig/types.js.map +1 -0
- package/dist/src/lib/policyCore/policyParameters/getOnchainPolicyParams.d.ts +17 -0
- package/dist/src/lib/policyCore/policyParameters/getOnchainPolicyParams.d.ts.map +1 -0
- package/dist/src/lib/policyCore/policyParameters/getOnchainPolicyParams.js +54 -0
- package/dist/src/lib/policyCore/policyParameters/getOnchainPolicyParams.js.map +1 -0
- package/dist/src/lib/policyCore/vincentPolicy.d.ts +92 -0
- package/dist/src/lib/policyCore/vincentPolicy.d.ts.map +1 -0
- package/dist/src/lib/policyCore/vincentPolicy.js +242 -0
- package/dist/src/lib/policyCore/vincentPolicy.js.map +1 -0
- package/dist/src/lib/types.d.ts +260 -0
- package/dist/src/lib/types.d.ts.map +1 -0
- package/dist/src/lib/types.js +4 -0
- package/dist/src/lib/types.js.map +1 -0
- package/dist/src/lib/utils.d.ts +2 -0
- package/dist/src/lib/utils.d.ts.map +1 -0
- package/dist/src/lib/utils.js +8 -0
- package/dist/src/lib/utils.js.map +1 -0
- package/dist/src/type-inference-verification/ability-definition-tests.d.ts +702 -0
- package/dist/src/type-inference-verification/ability-definition-tests.d.ts.map +1 -0
- package/dist/src/type-inference-verification/ability-definition-tests.js +203 -0
- package/dist/src/type-inference-verification/ability-definition-tests.js.map +1 -0
- package/dist/src/type-inference-verification/ability-lifecycle-inference.d.ts +2 -0
- package/dist/src/type-inference-verification/ability-lifecycle-inference.d.ts.map +1 -0
- package/dist/src/type-inference-verification/ability-lifecycle-inference.js +109 -0
- package/dist/src/type-inference-verification/ability-lifecycle-inference.js.map +1 -0
- package/dist/src/type-inference-verification/ability-lifecycle-succeed-fail-tests.d.ts +923 -0
- package/dist/src/type-inference-verification/ability-lifecycle-succeed-fail-tests.d.ts.map +1 -0
- package/dist/src/type-inference-verification/ability-lifecycle-succeed-fail-tests.js +196 -0
- package/dist/src/type-inference-verification/ability-lifecycle-succeed-fail-tests.js.map +1 -0
- package/dist/src/type-inference-verification/allow-deny-test-cases-ability.d.ts +4305 -0
- package/dist/src/type-inference-verification/allow-deny-test-cases-ability.d.ts.map +1 -0
- package/dist/src/type-inference-verification/allow-deny-test-cases-ability.js +644 -0
- package/dist/src/type-inference-verification/allow-deny-test-cases-ability.js.map +1 -0
- package/dist/src/type-inference-verification/allow-deny-test-cases.d.ts +646 -0
- package/dist/src/type-inference-verification/allow-deny-test-cases.d.ts.map +1 -0
- package/dist/src/type-inference-verification/allow-deny-test-cases.js +264 -0
- package/dist/src/type-inference-verification/allow-deny-test-cases.js.map +1 -0
- package/dist/src/type-inference-verification/context-switching-tests.d.ts +637 -0
- package/dist/src/type-inference-verification/context-switching-tests.d.ts.map +1 -0
- package/dist/src/type-inference-verification/context-switching-tests.js +229 -0
- package/dist/src/type-inference-verification/context-switching-tests.js.map +1 -0
- package/dist/src/type-inference-verification/create-policy-map-from-tool-policies.d.ts +2 -0
- package/dist/src/type-inference-verification/create-policy-map-from-tool-policies.d.ts.map +1 -0
- package/dist/src/type-inference-verification/create-policy-map-from-tool-policies.js +56 -0
- package/dist/src/type-inference-verification/create-policy-map-from-tool-policies.js.map +1 -0
- package/dist/src/type-inference-verification/create-vincent-ability-policy.d.ts +2 -0
- package/dist/src/type-inference-verification/create-vincent-ability-policy.d.ts.map +1 -0
- package/dist/src/type-inference-verification/create-vincent-ability-policy.js +49 -0
- package/dist/src/type-inference-verification/create-vincent-ability-policy.js.map +1 -0
- package/dist/src/type-inference-verification/create-vincent-ability.d.ts +250 -0
- package/dist/src/type-inference-verification/create-vincent-ability.d.ts.map +1 -0
- package/dist/src/type-inference-verification/create-vincent-ability.js +68 -0
- package/dist/src/type-inference-verification/create-vincent-ability.js.map +1 -0
- package/dist/src/type-inference-verification/parameter-inference-tests-tool.d.ts +1710 -0
- package/dist/src/type-inference-verification/parameter-inference-tests-tool.d.ts.map +1 -0
- package/dist/src/type-inference-verification/parameter-inference-tests-tool.js +537 -0
- package/dist/src/type-inference-verification/parameter-inference-tests-tool.js.map +1 -0
- package/dist/src/type-inference-verification/parameter-inference-tests.d.ts +456 -0
- package/dist/src/type-inference-verification/parameter-inference-tests.d.ts.map +1 -0
- package/dist/src/type-inference-verification/parameter-inference-tests.js +179 -0
- package/dist/src/type-inference-verification/parameter-inference-tests.js.map +1 -0
- package/dist/src/type-inference-verification/playground.d.ts +1556 -0
- package/dist/src/type-inference-verification/playground.d.ts.map +1 -0
- package/dist/src/type-inference-verification/playground.js +473 -0
- package/dist/src/type-inference-verification/playground.js.map +1 -0
- package/dist/src/type-inference-verification/schema-test.d.ts +470 -0
- package/dist/src/type-inference-verification/schema-test.d.ts.map +1 -0
- package/dist/src/type-inference-verification/schema-test.js +252 -0
- package/dist/src/type-inference-verification/schema-test.js.map +1 -0
- package/package.json +43 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# 2.0.0 (2025-08-01)
|
|
2
|
+
|
|
3
|
+
### 🚀 Features
|
|
4
|
+
|
|
5
|
+
- Add descriptions on abilities and their api interface params ([0b8ff1e3](https://github.com/LIT-Protocol/Vincent/commit/0b8ff1e3))
|
|
6
|
+
|
|
7
|
+
### 🩹 Fixes
|
|
8
|
+
|
|
9
|
+
- Making api version property in bundled things to ease its discovery and usage when validating its compatibility ([aa81d087](https://github.com/LIT-Protocol/Vincent/commit/aa81d087))
|
|
10
|
+
- ### Implement supported Vincent Ability API range ([14f0ece1](https://github.com/LIT-Protocol/Vincent/commit/14f0ece1))
|
|
11
|
+
|
|
12
|
+
Added basic Ability API handling to ensure abilities & policies are only used by compatible abilities and policies, and with the correct version of the vincentAbilityClient / app-sdk
|
|
13
|
+
|
|
14
|
+
- Added a new jsParam when VincentAbilityClient calls an ability, `vincentAbilityApiVersion`
|
|
15
|
+
- LIT action wrappers for abilities + policies compare `vincentAbilityApiVersion` to match the major semver range the handler was built with from the ability-sdk
|
|
16
|
+
- vincentAbilityHandler() is responsible for passing along the value when it evaluates supported policies
|
|
17
|
+
|
|
18
|
+
### ⚠️ Breaking Changes
|
|
19
|
+
|
|
20
|
+
- Add support for vincent-contract-sdk using CBOR2 encoded policy parameters ([819fcd11](https://github.com/LIT-Protocol/Vincent/commit/819fcd11))
|
|
21
|
+
- ### `error` is now `runtimeError` and can only be set by `throw ...` ([04f1ca20](https://github.com/LIT-Protocol/Vincent/commit/04f1ca20))
|
|
22
|
+
|
|
23
|
+
- Previously, if you had not defined a `deny` or `fail` schema, you could call `deny()` or `fail()` with a string
|
|
24
|
+
- That string would end up in the ability/policy response as the `error` property instead of `result`
|
|
25
|
+
- This was problematic because there was no consistent way to identify _un-handled_ error vs. _explicitly returned fail/deny results_
|
|
26
|
+
- If you don't define a deny or fail schema, you can no longer call those methods with a string.
|
|
27
|
+
- `error` is now `runtimeError`, and is _only_ set if a lifecycle method `throw`s an Error - in that case it will be the `message` property of the error
|
|
28
|
+
- If you want to be able to return simple errors in your _result_, you can define a simple deny or fail schema like `z.object({ error: z.string() }`
|
|
29
|
+
|
|
30
|
+
- ### Add support for explicit `schemaValidationError` ([337a4bde](https://github.com/LIT-Protocol/Vincent/commit/337a4bde))
|
|
31
|
+
|
|
32
|
+
- Previously, a failure to validate either input or results of lifecycle method would result in `result: { zodError }` being returned
|
|
33
|
+
- Now, `result` will be `undefined` and there will be an explicit `schemaValidationError` in the result of the ability / policy
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
export interface SchemaValidationError {
|
|
37
|
+
zodError: ZodError<unknown>; // The result of `zod.safeParse().error`
|
|
38
|
+
phase: string; // Policies: `precheck`|`evaluate`|`commit` - Abilities: `precheck` | `execute`
|
|
39
|
+
stage: string; // `input` | `output`
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### 🧱 Updated Dependencies
|
|
44
|
+
|
|
45
|
+
- Updated contracts-sdk to 1.0.0
|
|
46
|
+
|
|
47
|
+
### ❤️ Thank You
|
|
48
|
+
|
|
49
|
+
- Daryl Collins
|
|
50
|
+
- FedericoAmura @FedericoAmura
|
|
51
|
+
|
|
52
|
+
## 1.0.2 (2025-07-08)
|
|
53
|
+
|
|
54
|
+
### 🩹 Fixes
|
|
55
|
+
|
|
56
|
+
- - Correct type of `PolicyEvaluationResultContext.deniedPolicy` so that `error` is a sibling of `result` ([edc609f5](https://github.com/LIT-Protocol/Vincent/commit/edc609f5))
|
|
57
|
+
- - Fixed a case where a deny response from a policy could be returned without being parsed by its deny result schema ([27a35240](https://github.com/LIT-Protocol/Vincent/commit/27a35240))
|
|
58
|
+
- - Fixed incorrect handling of failure results that resulted in `success: true` responses from abilities that returned fail results ([51087e71](https://github.com/LIT-Protocol/Vincent/commit/51087e71))
|
|
59
|
+
- - Fixed `undefined` being returned to caller instead of the correct `error` string in cases where no fail result schema was defined and an explicit string was passed to `fail()` ([e8f1316a](https://github.com/LIT-Protocol/Vincent/commit/e8f1316a))
|
|
60
|
+
- - Fixed ability result typeguard functions incorrectly returning `false` when they were provided outputs with no `result` (e.g. no return value schema is defined for the lifecycle method) ([cf542969](https://github.com/LIT-Protocol/Vincent/commit/cf542969))
|
|
61
|
+
|
|
62
|
+
### ❤️ Thank You
|
|
63
|
+
|
|
64
|
+
- Daryl Collins
|
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# Contributing to Vincent Ability SDK
|
|
2
|
+
|
|
3
|
+
This document provides guidelines for contributing to the Vincent Ability SDK project.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The Vincent Ability SDK is an SDK exposing utilities to develop Vincent abilities and policies. It provides a type-safe lifecycle system for defining and composing policies and abilities, with strong TypeScript inference support throughout.
|
|
8
|
+
|
|
9
|
+
## Setup
|
|
10
|
+
|
|
11
|
+
1. Follow the global setup instructions in the repository root [CONTRIBUTING.md](../../../CONTRIBUTING.md).
|
|
12
|
+
2. Install dependencies:
|
|
13
|
+
```bash
|
|
14
|
+
pnpm install
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Development Workflow
|
|
18
|
+
|
|
19
|
+
### Building
|
|
20
|
+
|
|
21
|
+
Build the SDK:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
nx build ability-sdk
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Type Checking
|
|
28
|
+
|
|
29
|
+
Run type checking:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pnpm typecheck
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Watch Mode for Type Checking
|
|
36
|
+
|
|
37
|
+
Run type checking in watch mode:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
pnpm watch:type-tests
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Project Structure
|
|
44
|
+
|
|
45
|
+
- `src/`: Source code
|
|
46
|
+
- `lib/`
|
|
47
|
+
- `type-inference-verification/`
|
|
48
|
+
|
|
49
|
+
## SDK Development Guidelines
|
|
50
|
+
|
|
51
|
+
1. Maintain strong TypeScript typing throughout the codebase
|
|
52
|
+
2. Use Zod for schema validation
|
|
53
|
+
3. Design APIs that are intuitive and easy to use
|
|
54
|
+
4. Provide comprehensive documentation for all public APIs
|
|
55
|
+
5. Write unit tests for all functionality
|
|
56
|
+
6. Ensure backward compatibility when making changes
|
|
57
|
+
|
|
58
|
+
## Core Concepts
|
|
59
|
+
|
|
60
|
+
The SDK is built around these core concepts:
|
|
61
|
+
|
|
62
|
+
- **Policies**: Encapsulate decision logic (precheck, evaluate, commit) and define their input/output schemas.
|
|
63
|
+
- **Abilities**: Orchestrate multiple policies and expose `precheck` and `execute` lifecycle methods.
|
|
64
|
+
|
|
65
|
+
## Testing
|
|
66
|
+
|
|
67
|
+
Write unit tests for all functionality:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
pnpm test
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Documentation
|
|
74
|
+
|
|
75
|
+
- Document all public APIs with JSDoc comments
|
|
76
|
+
- Update README.md when adding new features
|
|
77
|
+
- Provide examples for common use cases
|
|
78
|
+
|
|
79
|
+
## Pull Request Process
|
|
80
|
+
|
|
81
|
+
1. Ensure your code follows the coding standards
|
|
82
|
+
2. Update documentation if necessary
|
|
83
|
+
3. Include tests for new functionality
|
|
84
|
+
4. Link any related issues in your pull request description
|
|
85
|
+
5. Request a review from a maintainer
|
|
86
|
+
|
|
87
|
+
## For AI Editors and IDEs
|
|
88
|
+
|
|
89
|
+
When working with AI-powered editors like Cursor, GitHub Copilot, or other AI assistants in this project directory, please note:
|
|
90
|
+
|
|
91
|
+
### Context Priority
|
|
92
|
+
|
|
93
|
+
1. **Primary Context**: When working within the ability-sdk project directory, AI editors should prioritize this CONTRIBUTING.md file and the project's README.md for specific guidance on the Ability SDK.
|
|
94
|
+
|
|
95
|
+
2. **Secondary Context**: The root-level CONTRIBUTING.md and README.md files provide important context about how this SDK fits into the broader Vincent ecosystem.
|
|
96
|
+
|
|
97
|
+
### Key Files for Ability SDK Context
|
|
98
|
+
|
|
99
|
+
- `/packages/libs/ability-sdk/README.md`: Overview of the Ability SDK project
|
|
100
|
+
- `/packages/libs/ability-sdk/CONTRIBUTING.md`: This file, with Ability SDK-specific contribution guidelines
|
|
101
|
+
- `/packages/libs/ability-sdk/src/`: Source code for the Ability SDK
|
|
102
|
+
|
|
103
|
+
### Related Projects
|
|
104
|
+
|
|
105
|
+
The Ability SDK is a core component that is used by:
|
|
106
|
+
|
|
107
|
+
- `policy-spending-limit`: For implementing spending limit policies
|
|
108
|
+
- `ability-erc20-approval`: For implementing ERC20 approval abilities
|
|
109
|
+
- `ability-uniswap-swap`: For implementing Uniswap swap abilities
|
|
110
|
+
|
|
111
|
+
When working on Ability SDK code, consider these consumers for context, and focus on maintaining backward compatibility and strong type safety.
|
|
112
|
+
|
|
113
|
+
## Additional Resources
|
|
114
|
+
|
|
115
|
+
- [Vincent Documentation](https://docs.heyvincent.ai/)
|
|
116
|
+
- [TypeScript Documentation](https://www.typescriptlang.org/docs/)
|
|
117
|
+
- [Zod Documentation](https://zod.dev/)
|
package/README.md
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
# ability-sdk
|
|
2
|
+
|
|
3
|
+
This library was generated with [Nx](https://nx.dev).
|
|
4
|
+
|
|
5
|
+
## Building
|
|
6
|
+
|
|
7
|
+
Run `nx build ability-sdk` to build the library.
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
# Vincent Policy & Ability SDK
|
|
12
|
+
|
|
13
|
+
This library provides a type-safe lifecycle system for defining and composing **policies** and **abilities**, with strong TypeScript inference support throughout.
|
|
14
|
+
|
|
15
|
+
## 🧩 Core Concepts
|
|
16
|
+
|
|
17
|
+
- **Policies** encapsulate decision logic (precheck, evaluate, commit) and define their input/output schemas.
|
|
18
|
+
- **Abilities** orchestrate multiple policies and expose `precheck` and `execute` lifecycle methods.
|
|
19
|
+
- **Context injection** provides `allow()` / `deny()` and `succeed()` / `fail()` methods, with schema-safe return typing.
|
|
20
|
+
- All inference is preserved automatically using `createVincentPolicy`, `createVincentAbilityPolicy`, and `createVincentAbility`.
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
### 🔁 Calling `commit()` on a Policy from within a Ability
|
|
25
|
+
|
|
26
|
+
Policies can define a `commit()` lifecycle method to finalize changes once an ability executes successfully. These `commit()` functions are injected automatically into the `allowedPolicies` object of the `AbilityContext`.
|
|
27
|
+
|
|
28
|
+
### Example Policy (max daily spend)
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import { z } from 'zod';
|
|
32
|
+
import { createVincentPolicy } from '@lit-protocol/vincent-ability-sdk';
|
|
33
|
+
|
|
34
|
+
import { getAmountSpentToday, adjustDailySpendAmount } from '@my-org/spending-limit-client';
|
|
35
|
+
|
|
36
|
+
export const dailySpendPolicy = createVincentPolicy({
|
|
37
|
+
ipfsCid: 'policy-committable',
|
|
38
|
+
packageName: '@lit-protocol/max-spend-policy',
|
|
39
|
+
|
|
40
|
+
abilityParamsSchema: z.object({
|
|
41
|
+
buySomething: z.boolean(),
|
|
42
|
+
buyAmount: z.number(),
|
|
43
|
+
}),
|
|
44
|
+
userParamsSchema: z.object({
|
|
45
|
+
perBuyLimit: z.number(),
|
|
46
|
+
maxAmountPerDay: z.number(),
|
|
47
|
+
}),
|
|
48
|
+
|
|
49
|
+
evalAllowResultSchema: z.object({
|
|
50
|
+
ok: z.boolean(),
|
|
51
|
+
amountRemaining: z.number(),
|
|
52
|
+
amountToSpend: z.number(),
|
|
53
|
+
}),
|
|
54
|
+
evalDenyResultSchema: z.union([
|
|
55
|
+
z.object({
|
|
56
|
+
reason: z.literal('Buy amount request exceeds per-buy limit'),
|
|
57
|
+
buyAmount: z.number(),
|
|
58
|
+
}),
|
|
59
|
+
z.object({
|
|
60
|
+
reason: z.enum(['Buy amount request exceeds max amount per day']),
|
|
61
|
+
buyAmount: z.number(),
|
|
62
|
+
amountSpentToday: z.number(),
|
|
63
|
+
amountRemaining: z.number(),
|
|
64
|
+
}),
|
|
65
|
+
]),
|
|
66
|
+
|
|
67
|
+
commitParamsSchema: z.object({ amountSpent: z.number() }),
|
|
68
|
+
commitAllowResultSchema: z.object({
|
|
69
|
+
transactionId: z.string(),
|
|
70
|
+
timestamp: z.number(),
|
|
71
|
+
}),
|
|
72
|
+
commitDenyResultSchema: z.object({
|
|
73
|
+
errorCode: z.number().optional(),
|
|
74
|
+
message: z.string(),
|
|
75
|
+
}),
|
|
76
|
+
|
|
77
|
+
evaluate: async ({ abilityParams, userParams }, context) => {
|
|
78
|
+
const { maxAmountPerDay, perBuyLimit } = userParams;
|
|
79
|
+
const { buyAmount } = abilityParams;
|
|
80
|
+
|
|
81
|
+
if (buyAmount > perBuyLimit) {
|
|
82
|
+
return context.deny({
|
|
83
|
+
reason: 'Buy amount request exceeds per-buy limit',
|
|
84
|
+
buyAmount,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const amountSpentToday = await getAmountSpentToday(context.delegation.delegator);
|
|
89
|
+
const amountRemaining = maxAmountPerDay - amountSpentToday;
|
|
90
|
+
|
|
91
|
+
if (buyAmount > amountRemaining) {
|
|
92
|
+
return context.deny({
|
|
93
|
+
reason: 'Buy amount request exceeds max amount per day',
|
|
94
|
+
amountSpentToday,
|
|
95
|
+
buyAmount,
|
|
96
|
+
amountRemaining,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return context.allow({
|
|
101
|
+
ok: true,
|
|
102
|
+
amountRemaining,
|
|
103
|
+
amountToSpend: buyAmount,
|
|
104
|
+
});
|
|
105
|
+
},
|
|
106
|
+
|
|
107
|
+
commit: async ({ amountSpent }, context) => {
|
|
108
|
+
try {
|
|
109
|
+
const spendCommitResult: { transactionId: string; timestamp: number } =
|
|
110
|
+
await adjustDailySpendAmount(context.delegation.delegator, amountSpent);
|
|
111
|
+
|
|
112
|
+
return context.allow(spendCommitResult);
|
|
113
|
+
} catch (e: unknown) {
|
|
114
|
+
if (e instanceof Error) {
|
|
115
|
+
if ('errorCode' in e) {
|
|
116
|
+
return context.deny({
|
|
117
|
+
errorCode: e.errorCode as number,
|
|
118
|
+
message: e.message,
|
|
119
|
+
});
|
|
120
|
+
} else {
|
|
121
|
+
return context.deny({ message: e.message });
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return context.deny({ message: String(e) });
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
### Example Ability - Uniswap
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
import { z } from 'zod';
|
|
137
|
+
|
|
138
|
+
import {
|
|
139
|
+
createVincentAbilityPolicy,
|
|
140
|
+
createVincentAbility,
|
|
141
|
+
} from '@lit-protocol/vincent-ability-sdk';
|
|
142
|
+
|
|
143
|
+
import { dailySpendPolicy } from '@lit-protocol/max-spend-policy';
|
|
144
|
+
|
|
145
|
+
import uniswapV3Client from '@uniswap/v3-sdk';
|
|
146
|
+
|
|
147
|
+
const abilityParamsSchema = z.object({
|
|
148
|
+
buy: z.boolean(),
|
|
149
|
+
buyAmount: z.number(),
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
export const myTokenSwapAbility = createVincentAbility({
|
|
153
|
+
packageName: 'tokenswapability',
|
|
154
|
+
abilityDescription: 'Token Swap Ability',
|
|
155
|
+
|
|
156
|
+
abilityParamsSchema,
|
|
157
|
+
|
|
158
|
+
supportedPolicies: [
|
|
159
|
+
createVincentAbilityPolicy({
|
|
160
|
+
abilityParamsSchema,
|
|
161
|
+
PolicyConfig: dailySpendPolicy,
|
|
162
|
+
abilityParameterMappings: { buy: 'buyAmount' },
|
|
163
|
+
}),
|
|
164
|
+
],
|
|
165
|
+
executeSuccessSchema: z.object({
|
|
166
|
+
message: z.string(),
|
|
167
|
+
amountSpent: z.number().optional(),
|
|
168
|
+
spendCommitResult: z
|
|
169
|
+
.object({
|
|
170
|
+
transactionId: z.string(),
|
|
171
|
+
timestamp: z.number(),
|
|
172
|
+
})
|
|
173
|
+
.optional(),
|
|
174
|
+
}),
|
|
175
|
+
|
|
176
|
+
executeFailSchema: z.object({ error: z.string(), message: z.string() }),
|
|
177
|
+
|
|
178
|
+
async execute(abilityParams, { succeed, fail, policiesContext }) {
|
|
179
|
+
const spendPolicyContext = policiesContext.allowedPolicies['@lit-protocol/max-spend-policy'];
|
|
180
|
+
|
|
181
|
+
const amountSpent: number = await uniswapV3Client.performSwap({});
|
|
182
|
+
|
|
183
|
+
if (spendPolicyContext) {
|
|
184
|
+
const spendCommitResult = await spendPolicyContext.commit({
|
|
185
|
+
amountSpent,
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
if (!spendCommitResult.allow) {
|
|
189
|
+
return fail({
|
|
190
|
+
error: `Policy commit denied with code ${spendCommitResult.result.errorCode}`,
|
|
191
|
+
message: 'Ability executed but policy commit denied',
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (spendCommitResult.allow) {
|
|
196
|
+
return succeed({
|
|
197
|
+
amountSpent,
|
|
198
|
+
spendCommitResult: spendCommitResult.result,
|
|
199
|
+
message: 'Ability executed and spending limit policy commit completed',
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return succeed({
|
|
205
|
+
message: 'Ability executed for user without enabled spending limit',
|
|
206
|
+
});
|
|
207
|
+
},
|
|
208
|
+
});
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## 🧠 Tip
|
|
212
|
+
|
|
213
|
+
Ability and policy authors should export the result of `createVincentPolicy()` / `createVincentAbility()`
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lit-protocol/vincent-ability-sdk",
|
|
3
|
+
"version": "0.0.1-ea",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"@lit-protocol/vincent-contracts-sdk": "workspace:*",
|
|
9
|
+
"ethers": "5.8.0",
|
|
10
|
+
"semver": "^7.7.2",
|
|
11
|
+
"tslib": "^2.8.1",
|
|
12
|
+
"zod": "^3.25.64"
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"watch:type-tests": "chokidar 'src/**/*' --initial --await-write-finish --delay 100 --silent -c './scripts/run-typecheck.sh'",
|
|
16
|
+
"typecheck": "./scripts/precommit-check.sh"
|
|
17
|
+
},
|
|
18
|
+
"main": "./dist/src/index.js",
|
|
19
|
+
"types": "./dist/src/index.d.ts",
|
|
20
|
+
"files": [
|
|
21
|
+
"dist/**",
|
|
22
|
+
"*.md"
|
|
23
|
+
],
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"require": "./dist/src/index.js",
|
|
27
|
+
"import": "./dist/src/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./internal": {
|
|
30
|
+
"require": "./dist/src/internal.js",
|
|
31
|
+
"import": "./dist/src/internal.js"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@types/semver": "^7.7.0",
|
|
36
|
+
"chokidar-cli": "^3.0.0",
|
|
37
|
+
"jsonc-eslint-parser": "^2.4.0",
|
|
38
|
+
"typedoc": "0.27.9",
|
|
39
|
+
"typedoc-material-theme": "1.3.0",
|
|
40
|
+
"typedoc-plugin-extras": "^4.0.0",
|
|
41
|
+
"typedoc-plugin-zod": "^1.4.1"
|
|
42
|
+
},
|
|
43
|
+
"type": "commonjs"
|
|
44
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { createVincentPolicy, createVincentAbilityPolicy } from './lib/policyCore/vincentPolicy';
|
|
2
|
+
export { createVincentAbility } from './lib/abilityCore/vincentAbility';
|
|
3
|
+
export { VINCENT_TOOL_API_VERSION } from './lib/constants';
|
|
4
|
+
export { vincentPolicyHandler } from './lib/handlers/vincentPolicyHandler';
|
|
5
|
+
export { vincentAbilityHandler } from './lib/handlers/vincentAbilityHandler';
|
|
6
|
+
export { asBundledVincentAbility } from './lib/abilityCore/bundledAbility/bundledAbility';
|
|
7
|
+
export { asBundledVincentPolicy } from './lib/policyCore/bundledPolicy/bundledPolicy';
|
|
8
|
+
export { supportedPoliciesForAbility } from './lib/abilityCore/helpers/supportedPoliciesForAbility';
|
|
9
|
+
export type { BundledVincentPolicy } from './lib/policyCore/bundledPolicy/types';
|
|
10
|
+
export type { BundledVincentAbility } from './lib/abilityCore/bundledAbility/types';
|
|
11
|
+
export type { PolicyConfigLifecycleFunction, PolicyConfigCommitFunction, } from './lib/policyCore/policyConfig/types';
|
|
12
|
+
export type { PolicyContext } from './lib/policyCore/policyConfig/context/types';
|
|
13
|
+
export type { VincentAbilityPolicy, BaseContext, PolicyEvaluationResultContext, VincentAbility, AbilityConsumerContext, PolicyConsumerContext, SchemaValidationError, } from './lib/types';
|
|
14
|
+
export type { BaseAbilityContext } from './lib/abilityCore/abilityConfig/context/types';
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,0BAA0B,EAAE,MAAM,gCAAgC,CAAC;AACjG,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AACxE,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAE3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAC3E,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AAE7E,OAAO,EAAE,uBAAuB,EAAE,MAAM,iDAAiD,CAAC;AAC1F,OAAO,EAAE,sBAAsB,EAAE,MAAM,8CAA8C,CAAC;AACtF,OAAO,EAAE,2BAA2B,EAAE,MAAM,uDAAuD,CAAC;AAEpG,YAAY,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AACjF,YAAY,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAC;AACpF,YAAY,EACV,6BAA6B,EAC7B,0BAA0B,GAC3B,MAAM,qCAAqC,CAAC;AAC7C,YAAY,EAAE,aAAa,EAAE,MAAM,6CAA6C,CAAC;AAEjF,YAAY,EACV,oBAAoB,EACpB,WAAW,EACX,6BAA6B,EAC7B,cAAc,EACd,sBAAsB,EACtB,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,aAAa,CAAC;AAErB,YAAY,EAAE,kBAAkB,EAAE,MAAM,+CAA+C,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.supportedPoliciesForAbility = exports.asBundledVincentPolicy = exports.asBundledVincentAbility = exports.vincentAbilityHandler = exports.vincentPolicyHandler = exports.VINCENT_TOOL_API_VERSION = exports.createVincentAbility = exports.createVincentAbilityPolicy = exports.createVincentPolicy = void 0;
|
|
4
|
+
var vincentPolicy_1 = require("./lib/policyCore/vincentPolicy");
|
|
5
|
+
Object.defineProperty(exports, "createVincentPolicy", { enumerable: true, get: function () { return vincentPolicy_1.createVincentPolicy; } });
|
|
6
|
+
Object.defineProperty(exports, "createVincentAbilityPolicy", { enumerable: true, get: function () { return vincentPolicy_1.createVincentAbilityPolicy; } });
|
|
7
|
+
var vincentAbility_1 = require("./lib/abilityCore/vincentAbility");
|
|
8
|
+
Object.defineProperty(exports, "createVincentAbility", { enumerable: true, get: function () { return vincentAbility_1.createVincentAbility; } });
|
|
9
|
+
var constants_1 = require("./lib/constants");
|
|
10
|
+
Object.defineProperty(exports, "VINCENT_TOOL_API_VERSION", { enumerable: true, get: function () { return constants_1.VINCENT_TOOL_API_VERSION; } });
|
|
11
|
+
var vincentPolicyHandler_1 = require("./lib/handlers/vincentPolicyHandler");
|
|
12
|
+
Object.defineProperty(exports, "vincentPolicyHandler", { enumerable: true, get: function () { return vincentPolicyHandler_1.vincentPolicyHandler; } });
|
|
13
|
+
var vincentAbilityHandler_1 = require("./lib/handlers/vincentAbilityHandler");
|
|
14
|
+
Object.defineProperty(exports, "vincentAbilityHandler", { enumerable: true, get: function () { return vincentAbilityHandler_1.vincentAbilityHandler; } });
|
|
15
|
+
var bundledAbility_1 = require("./lib/abilityCore/bundledAbility/bundledAbility");
|
|
16
|
+
Object.defineProperty(exports, "asBundledVincentAbility", { enumerable: true, get: function () { return bundledAbility_1.asBundledVincentAbility; } });
|
|
17
|
+
var bundledPolicy_1 = require("./lib/policyCore/bundledPolicy/bundledPolicy");
|
|
18
|
+
Object.defineProperty(exports, "asBundledVincentPolicy", { enumerable: true, get: function () { return bundledPolicy_1.asBundledVincentPolicy; } });
|
|
19
|
+
var supportedPoliciesForAbility_1 = require("./lib/abilityCore/helpers/supportedPoliciesForAbility");
|
|
20
|
+
Object.defineProperty(exports, "supportedPoliciesForAbility", { enumerable: true, get: function () { return supportedPoliciesForAbility_1.supportedPoliciesForAbility; } });
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,gEAAiG;AAAxF,oHAAA,mBAAmB,OAAA;AAAE,2HAAA,0BAA0B,OAAA;AACxD,mEAAwE;AAA/D,sHAAA,oBAAoB,OAAA;AAC7B,6CAA2D;AAAlD,qHAAA,wBAAwB,OAAA;AAEjC,4EAA2E;AAAlE,4HAAA,oBAAoB,OAAA;AAC7B,8EAA6E;AAApE,8HAAA,qBAAqB,OAAA;AAE9B,kFAA0F;AAAjF,yHAAA,uBAAuB,OAAA;AAChC,8EAAsF;AAA7E,uHAAA,sBAAsB,OAAA;AAC/B,qGAAoG;AAA3F,0IAAA,2BAA2B,OAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { getPkpInfo } from './lib/abilityCore/helpers';
|
|
2
|
+
export type { AbilityPolicyMap } from './lib/abilityCore/helpers';
|
|
3
|
+
export { validatePolicies } from './lib/abilityCore/helpers/validatePolicies';
|
|
4
|
+
export { createAbilitySuccessResult } from './lib/abilityCore/helpers/resultCreators';
|
|
5
|
+
export { getSchemaForAbilityResult, validateOrFail } from './lib/abilityCore/helpers/zod';
|
|
6
|
+
export { isAbilityFailureResult } from './lib/abilityCore/helpers/typeGuards';
|
|
7
|
+
export type { AbilityResultFailure, VincentPolicy } from './lib/types';
|
|
8
|
+
export { assertSupportedAbilityVersion } from './lib/assertSupportedAbilityVersion';
|
|
9
|
+
export { getPoliciesAndAppVersion } from './lib/policyCore/policyParameters/getOnchainPolicyParams';
|
|
10
|
+
export { createDenyResult, getSchemaForPolicyResponseResult, isPolicyAllowResponse, isPolicyDenyResponse, validateOrDeny, } from './lib/policyCore/helpers';
|
|
11
|
+
export { LIT_DATIL_PUBKEY_ROUTER_ADDRESS } from './lib/handlers/constants';
|
|
12
|
+
//# sourceMappingURL=internal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../src/internal.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,YAAY,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAElE,OAAO,EAAE,gBAAgB,EAAE,MAAM,4CAA4C,CAAC;AAC9E,OAAO,EAAE,0BAA0B,EAAE,MAAM,0CAA0C,CAAC;AACtF,OAAO,EAAE,yBAAyB,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC1F,OAAO,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;AAC9E,YAAY,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEvE,OAAO,EAAE,6BAA6B,EAAE,MAAM,qCAAqC,CAAC;AAGpF,OAAO,EAAE,wBAAwB,EAAE,MAAM,0DAA0D,CAAC;AAGpG,OAAO,EACL,gBAAgB,EAChB,gCAAgC,EAChC,qBAAqB,EACrB,oBAAoB,EACpB,cAAc,GACf,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAAE,+BAA+B,EAAE,MAAM,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// src/internal.ts
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.LIT_DATIL_PUBKEY_ROUTER_ADDRESS = exports.validateOrDeny = exports.isPolicyDenyResponse = exports.isPolicyAllowResponse = exports.getSchemaForPolicyResponseResult = exports.createDenyResult = exports.getPoliciesAndAppVersion = exports.assertSupportedAbilityVersion = exports.isAbilityFailureResult = exports.validateOrFail = exports.getSchemaForAbilityResult = exports.createAbilitySuccessResult = exports.validatePolicies = exports.getPkpInfo = void 0;
|
|
5
|
+
// Ability Core - Context + Helpers
|
|
6
|
+
var helpers_1 = require("./lib/abilityCore/helpers");
|
|
7
|
+
Object.defineProperty(exports, "getPkpInfo", { enumerable: true, get: function () { return helpers_1.getPkpInfo; } });
|
|
8
|
+
var validatePolicies_1 = require("./lib/abilityCore/helpers/validatePolicies");
|
|
9
|
+
Object.defineProperty(exports, "validatePolicies", { enumerable: true, get: function () { return validatePolicies_1.validatePolicies; } });
|
|
10
|
+
var resultCreators_1 = require("./lib/abilityCore/helpers/resultCreators");
|
|
11
|
+
Object.defineProperty(exports, "createAbilitySuccessResult", { enumerable: true, get: function () { return resultCreators_1.createAbilitySuccessResult; } });
|
|
12
|
+
var zod_1 = require("./lib/abilityCore/helpers/zod");
|
|
13
|
+
Object.defineProperty(exports, "getSchemaForAbilityResult", { enumerable: true, get: function () { return zod_1.getSchemaForAbilityResult; } });
|
|
14
|
+
Object.defineProperty(exports, "validateOrFail", { enumerable: true, get: function () { return zod_1.validateOrFail; } });
|
|
15
|
+
var typeGuards_1 = require("./lib/abilityCore/helpers/typeGuards");
|
|
16
|
+
Object.defineProperty(exports, "isAbilityFailureResult", { enumerable: true, get: function () { return typeGuards_1.isAbilityFailureResult; } });
|
|
17
|
+
var assertSupportedAbilityVersion_1 = require("./lib/assertSupportedAbilityVersion");
|
|
18
|
+
Object.defineProperty(exports, "assertSupportedAbilityVersion", { enumerable: true, get: function () { return assertSupportedAbilityVersion_1.assertSupportedAbilityVersion; } });
|
|
19
|
+
// Policy Core - Parameter Loading + Decoding
|
|
20
|
+
var getOnchainPolicyParams_1 = require("./lib/policyCore/policyParameters/getOnchainPolicyParams");
|
|
21
|
+
Object.defineProperty(exports, "getPoliciesAndAppVersion", { enumerable: true, get: function () { return getOnchainPolicyParams_1.getPoliciesAndAppVersion; } });
|
|
22
|
+
// Policy Core - Evaluation Helpers
|
|
23
|
+
var helpers_2 = require("./lib/policyCore/helpers");
|
|
24
|
+
Object.defineProperty(exports, "createDenyResult", { enumerable: true, get: function () { return helpers_2.createDenyResult; } });
|
|
25
|
+
Object.defineProperty(exports, "getSchemaForPolicyResponseResult", { enumerable: true, get: function () { return helpers_2.getSchemaForPolicyResponseResult; } });
|
|
26
|
+
Object.defineProperty(exports, "isPolicyAllowResponse", { enumerable: true, get: function () { return helpers_2.isPolicyAllowResponse; } });
|
|
27
|
+
Object.defineProperty(exports, "isPolicyDenyResponse", { enumerable: true, get: function () { return helpers_2.isPolicyDenyResponse; } });
|
|
28
|
+
Object.defineProperty(exports, "validateOrDeny", { enumerable: true, get: function () { return helpers_2.validateOrDeny; } });
|
|
29
|
+
// Constants
|
|
30
|
+
var constants_1 = require("./lib/handlers/constants");
|
|
31
|
+
Object.defineProperty(exports, "LIT_DATIL_PUBKEY_ROUTER_ADDRESS", { enumerable: true, get: function () { return constants_1.LIT_DATIL_PUBKEY_ROUTER_ADDRESS; } });
|
|
32
|
+
//# sourceMappingURL=internal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../src/internal.ts"],"names":[],"mappings":";AAAA,kBAAkB;;;AAElB,mCAAmC;AAEnC,qDAAuD;AAA9C,qGAAA,UAAU,OAAA;AAGnB,+EAA8E;AAArE,oHAAA,gBAAgB,OAAA;AACzB,2EAAsF;AAA7E,4HAAA,0BAA0B,OAAA;AACnC,qDAA0F;AAAjF,gHAAA,yBAAyB,OAAA;AAAE,qGAAA,cAAc,OAAA;AAClD,mEAA8E;AAArE,oHAAA,sBAAsB,OAAA;AAG/B,qFAAoF;AAA3E,8IAAA,6BAA6B,OAAA;AAEtC,6CAA6C;AAC7C,mGAAoG;AAA3F,kIAAA,wBAAwB,OAAA;AAEjC,mCAAmC;AACnC,oDAMkC;AALhC,2GAAA,gBAAgB,OAAA;AAChB,2HAAA,gCAAgC,OAAA;AAChC,gHAAA,qBAAqB,OAAA;AACrB,+GAAA,oBAAoB,OAAA;AACpB,yGAAA,cAAc,OAAA;AAGhB,YAAY;AACZ,sDAA2E;AAAlE,4HAAA,+BAA+B,OAAA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
import type { PolicyEvaluationResultContext, AbilityExecutionPolicyContext, AbilityExecutionPolicyEvaluationResult, VincentPolicy } from '../../../types';
|
|
3
|
+
import type { BaseAbilityContext, AbilityContext } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* Builds an execution-time AbilityContext for use inside `execute()` lifecycle methods.
|
|
6
|
+
* It upgrades the incoming external policy context with `commit()` methods derived
|
|
7
|
+
* from the ability's supported policies and schema definitions. Ensures commit calls
|
|
8
|
+
* are fully typed and validated internally.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createExecutionAbilityContext<PolicyMapByPackageName extends Record<string, any>>(params: {
|
|
11
|
+
baseContext: BaseAbilityContext<AbilityExecutionPolicyEvaluationResult<PolicyMapByPackageName>>;
|
|
12
|
+
policiesByPackageName: PolicyMapByPackageName;
|
|
13
|
+
}): AbilityContext<any, any, AbilityExecutionPolicyContext<PolicyMapByPackageName>>;
|
|
14
|
+
/**
|
|
15
|
+
* Builds a precheck-time AbilityContext for use inside `precheck()` lifecycle methods.
|
|
16
|
+
* It includes only the evaluated policy metadata and denies commit access,
|
|
17
|
+
* ensuring developers don’t call commit prematurely. Enforces policy result typing.
|
|
18
|
+
*/
|
|
19
|
+
export declare function createPrecheckAbilityContext<PolicyMapByPackageName extends Record<string, {
|
|
20
|
+
__schemaTypes: {
|
|
21
|
+
evalAllowResultSchema?: z.ZodType;
|
|
22
|
+
evalDenyResultSchema?: z.ZodType;
|
|
23
|
+
};
|
|
24
|
+
vincentPolicy: VincentPolicy<any, any, any, any, any, any, any, any, any, any, any, any, any>;
|
|
25
|
+
}>>(params: {
|
|
26
|
+
baseContext: BaseAbilityContext<PolicyEvaluationResultContext<PolicyMapByPackageName>>;
|
|
27
|
+
}): AbilityContext<any, any, PolicyEvaluationResultContext<PolicyMapByPackageName>>;
|
|
28
|
+
//# sourceMappingURL=abilityContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abilityContext.d.ts","sourceRoot":"","sources":["../../../../../../src/lib/abilityCore/abilityConfig/context/abilityContext.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,OAAO,KAAK,EACV,6BAA6B,EAC7B,6BAA6B,EAC7B,sCAAsC,EACtC,aAAa,EACd,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAIlE;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAC3C,sBAAsB,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAClD,MAAM,EAAE;IACR,WAAW,EAAE,kBAAkB,CAAC,sCAAsC,CAAC,sBAAsB,CAAC,CAAC,CAAC;IAChG,qBAAqB,EAAE,sBAAsB,CAAC;CAC/C,GAAG,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,6BAA6B,CAAC,sBAAsB,CAAC,CAAC,CA8BlF;AAED;;;;GAIG;AACH,wBAAgB,4BAA4B,CAC1C,sBAAsB,SAAS,MAAM,CACnC,MAAM,EACN;IACE,aAAa,EAAE;QACb,qBAAqB,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC;QAClC,oBAAoB,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC;KAClC,CAAC;IACF,aAAa,EAAE,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;CAC/F,CACF,EACD,MAAM,EAAE;IACR,WAAW,EAAE,kBAAkB,CAAC,6BAA6B,CAAC,sBAAsB,CAAC,CAAC,CAAC;CACxF,GAAG,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,6BAA6B,CAAC,sBAAsB,CAAC,CAAC,CAQlF"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// src/lib/abilityCore/abilityConfig/context/abilityContext.ts
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.createExecutionAbilityContext = createExecutionAbilityContext;
|
|
5
|
+
exports.createPrecheckAbilityContext = createPrecheckAbilityContext;
|
|
6
|
+
const resultCreators_1 = require("./resultCreators");
|
|
7
|
+
/**
|
|
8
|
+
* Builds an execution-time AbilityContext for use inside `execute()` lifecycle methods.
|
|
9
|
+
* It upgrades the incoming external policy context with `commit()` methods derived
|
|
10
|
+
* from the ability's supported policies and schema definitions. Ensures commit calls
|
|
11
|
+
* are fully typed and validated internally.
|
|
12
|
+
*/
|
|
13
|
+
function createExecutionAbilityContext(params) {
|
|
14
|
+
const { baseContext, policiesByPackageName } = params;
|
|
15
|
+
const allowedPolicies = {};
|
|
16
|
+
for (const key of Object.keys(policiesByPackageName)) {
|
|
17
|
+
const k = key;
|
|
18
|
+
const entry = baseContext.policiesContext.allowedPolicies[k];
|
|
19
|
+
if (!entry)
|
|
20
|
+
continue;
|
|
21
|
+
allowedPolicies[k] = {
|
|
22
|
+
...entry,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
const upgradedPoliciesContext = {
|
|
26
|
+
evaluatedPolicies: baseContext.policiesContext.evaluatedPolicies,
|
|
27
|
+
allow: true,
|
|
28
|
+
deniedPolicy: undefined,
|
|
29
|
+
allowedPolicies,
|
|
30
|
+
};
|
|
31
|
+
return {
|
|
32
|
+
...baseContext,
|
|
33
|
+
policiesContext: upgradedPoliciesContext,
|
|
34
|
+
succeed: resultCreators_1.createSuccess,
|
|
35
|
+
fail: resultCreators_1.createFailure,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Builds a precheck-time AbilityContext for use inside `precheck()` lifecycle methods.
|
|
40
|
+
* It includes only the evaluated policy metadata and denies commit access,
|
|
41
|
+
* ensuring developers don’t call commit prematurely. Enforces policy result typing.
|
|
42
|
+
*/
|
|
43
|
+
function createPrecheckAbilityContext(params) {
|
|
44
|
+
const { baseContext } = params;
|
|
45
|
+
return {
|
|
46
|
+
...baseContext,
|
|
47
|
+
succeed: resultCreators_1.createSuccess,
|
|
48
|
+
fail: resultCreators_1.createFailure,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=abilityContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abilityContext.js","sourceRoot":"","sources":["../../../../../../src/lib/abilityCore/abilityConfig/context/abilityContext.ts"],"names":[],"mappings":";AAAA,8DAA8D;;AAqB9D,sEAmCC;AAOD,oEAqBC;AAvED,qDAAgE;AAEhE;;;;;GAKG;AACH,SAAgB,6BAA6B,CAE3C,MAGD;IACC,MAAM,EAAE,WAAW,EAAE,qBAAqB,EAAE,GAAG,MAAM,CAAC;IAEtD,MAAM,eAAe,GACnB,EAA8E,CAAC;IAEjF,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,qBAAqB,CAAC,EAAE,CAAC;QACrD,MAAM,CAAC,GAAG,GAAmC,CAAC;QAC9C,MAAM,KAAK,GAAG,WAAW,CAAC,eAAe,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;QAE7D,IAAI,CAAC,KAAK;YAAE,SAAS;QAEpB,eAAuB,CAAC,CAAC,CAAC,GAAG;YAC5B,GAAG,KAAK;SACT,CAAC;IACJ,CAAC;IAED,MAAM,uBAAuB,GAA0D;QACrF,iBAAiB,EAAE,WAAW,CAAC,eAAe,CAAC,iBAAiB;QAChE,KAAK,EAAE,IAAI;QACX,YAAY,EAAE,SAAkB;QAChC,eAAe;KAChB,CAAC;IAEF,OAAO;QACL,GAAG,WAAW;QACd,eAAe,EAAE,uBAAuB;QACxC,OAAO,EAAE,8BAA4E;QACrF,IAAI,EAAE,8BAAyE;KAChF,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,SAAgB,4BAA4B,CAW1C,MAED;IACC,MAAM,EAAE,WAAW,EAAE,GAAG,MAAM,CAAC;IAE/B,OAAO;QACL,GAAG,WAAW;QACd,OAAO,EAAE,8BAA4E;QACrF,IAAI,EAAE,8BAAyE;KAChF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ContextSuccess, ContextSuccessNoResult, ContextFailure, ContextFailureNoResult } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Wraps a success result with payload
|
|
4
|
+
*/
|
|
5
|
+
export declare function createSuccess<T>(result: T): ContextSuccess<T>;
|
|
6
|
+
/**
|
|
7
|
+
* Wraps a success result without payload
|
|
8
|
+
*/
|
|
9
|
+
export declare function createSuccessNoResult(): ContextSuccessNoResult;
|
|
10
|
+
/**
|
|
11
|
+
* Wraps a failure result with payload
|
|
12
|
+
*/
|
|
13
|
+
export declare function createFailure<T>(result: T): ContextFailure<T>;
|
|
14
|
+
/**
|
|
15
|
+
* Wraps a failure result without payload
|
|
16
|
+
*/
|
|
17
|
+
export declare function createFailureNoResult(): ContextFailureNoResult;
|
|
18
|
+
//# sourceMappingURL=resultCreators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resultCreators.d.ts","sourceRoot":"","sources":["../../../../../../src/lib/abilityCore/abilityConfig/context/resultCreators.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,cAAc,EACd,sBAAsB,EACtB,cAAc,EACd,sBAAsB,EACvB,MAAM,SAAS,CAAC;AAIjB;;GAEG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,CAM7D;AAED;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,sBAAsB,CAK9D;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,CAM7D;AAED;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,sBAAsB,CAM9D"}
|