@lit-protocol/vincent-app-sdk 0.0.4-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 +207 -0
- package/CONTRIBUTING.md +114 -0
- package/README.md +216 -0
- package/dist/package.json +86 -0
- package/dist/src/abilityClient/constants.d.ts +2 -0
- package/dist/src/abilityClient/constants.d.ts.map +1 -0
- package/dist/src/abilityClient/constants.js +5 -0
- package/dist/src/abilityClient/constants.js.map +1 -0
- package/dist/src/abilityClient/execute/generateVincentAbilitySessionSigs.d.ts +8 -0
- package/dist/src/abilityClient/execute/generateVincentAbilitySessionSigs.d.ts.map +1 -0
- package/dist/src/abilityClient/execute/generateVincentAbilitySessionSigs.js +33 -0
- package/dist/src/abilityClient/execute/generateVincentAbilitySessionSigs.js.map +1 -0
- package/dist/src/abilityClient/execute/resultCreators.d.ts +71 -0
- package/dist/src/abilityClient/execute/resultCreators.d.ts.map +1 -0
- package/dist/src/abilityClient/execute/resultCreators.js +57 -0
- package/dist/src/abilityClient/execute/resultCreators.js.map +1 -0
- package/dist/src/abilityClient/execute/types.d.ts +38 -0
- package/dist/src/abilityClient/execute/types.d.ts.map +1 -0
- package/dist/src/abilityClient/execute/types.js +4 -0
- package/dist/src/abilityClient/execute/types.js.map +1 -0
- package/dist/src/abilityClient/index.d.ts +19 -0
- package/dist/src/abilityClient/index.d.ts.map +1 -0
- package/dist/src/abilityClient/index.js +26 -0
- package/dist/src/abilityClient/index.js.map +1 -0
- package/dist/src/abilityClient/precheck/resultCreators.d.ts +71 -0
- package/dist/src/abilityClient/precheck/resultCreators.d.ts.map +1 -0
- package/dist/src/abilityClient/precheck/resultCreators.js +57 -0
- package/dist/src/abilityClient/precheck/resultCreators.js.map +1 -0
- package/dist/src/abilityClient/precheck/runPolicyPrechecks.d.ts +14 -0
- package/dist/src/abilityClient/precheck/runPolicyPrechecks.d.ts.map +1 -0
- package/dist/src/abilityClient/precheck/runPolicyPrechecks.js +98 -0
- package/dist/src/abilityClient/precheck/runPolicyPrechecks.js.map +1 -0
- package/dist/src/abilityClient/precheck/types.d.ts +82 -0
- package/dist/src/abilityClient/precheck/types.d.ts.map +1 -0
- package/dist/src/abilityClient/precheck/types.js +4 -0
- package/dist/src/abilityClient/precheck/types.js.map +1 -0
- package/dist/src/abilityClient/typeGuards.d.ts +28 -0
- package/dist/src/abilityClient/typeGuards.d.ts.map +1 -0
- package/dist/src/abilityClient/typeGuards.js +67 -0
- package/dist/src/abilityClient/typeGuards.js.map +1 -0
- package/dist/src/abilityClient/types.d.ts +50 -0
- package/dist/src/abilityClient/types.d.ts.map +1 -0
- package/dist/src/abilityClient/types.js +4 -0
- package/dist/src/abilityClient/types.js.map +1 -0
- package/dist/src/abilityClient/vincentAbilityClient.d.ts +76 -0
- package/dist/src/abilityClient/vincentAbilityClient.d.ts.map +1 -0
- package/dist/src/abilityClient/vincentAbilityClient.js +285 -0
- package/dist/src/abilityClient/vincentAbilityClient.js.map +1 -0
- package/dist/src/expressMiddleware/express.d.ts +63 -0
- package/dist/src/expressMiddleware/express.d.ts.map +1 -0
- package/dist/src/expressMiddleware/express.js +125 -0
- package/dist/src/expressMiddleware/express.js.map +1 -0
- package/dist/src/expressMiddleware/index.d.ts +14 -0
- package/dist/src/expressMiddleware/index.d.ts.map +1 -0
- package/dist/src/expressMiddleware/index.js +17 -0
- package/dist/src/expressMiddleware/index.js.map +1 -0
- package/dist/src/expressMiddleware/types.d.ts +31 -0
- package/dist/src/expressMiddleware/types.d.ts.map +1 -0
- package/dist/src/expressMiddleware/types.js +3 -0
- package/dist/src/expressMiddleware/types.js.map +1 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +3 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/internal/LitNodeClient/LitNodeClientInstance.d.ts +14 -0
- package/dist/src/internal/LitNodeClient/LitNodeClientInstance.d.ts.map +1 -0
- package/dist/src/internal/LitNodeClient/LitNodeClientInstance.js +67 -0
- package/dist/src/internal/LitNodeClient/LitNodeClientInstance.js.map +1 -0
- package/dist/src/internal/LitNodeClient/getLitNodeClient.d.ts +7 -0
- package/dist/src/internal/LitNodeClient/getLitNodeClient.d.ts.map +1 -0
- package/dist/src/internal/LitNodeClient/getLitNodeClient.js +25 -0
- package/dist/src/internal/LitNodeClient/getLitNodeClient.js.map +1 -0
- package/dist/src/jwt/accessors.d.ts +8 -0
- package/dist/src/jwt/accessors.d.ts.map +1 -0
- package/dist/src/jwt/accessors.js +15 -0
- package/dist/src/jwt/accessors.js.map +1 -0
- package/dist/src/jwt/core/create.d.ts +24 -0
- package/dist/src/jwt/core/create.d.ts.map +1 -0
- package/dist/src/jwt/core/create.js +95 -0
- package/dist/src/jwt/core/create.js.map +1 -0
- package/dist/src/jwt/core/isExpired.d.ts +9 -0
- package/dist/src/jwt/core/isExpired.d.ts.map +1 -0
- package/dist/src/jwt/core/isExpired.js +20 -0
- package/dist/src/jwt/core/isExpired.js.map +1 -0
- package/dist/src/jwt/core/utils/base64.d.ts +14 -0
- package/dist/src/jwt/core/utils/base64.d.ts.map +1 -0
- package/dist/src/jwt/core/utils/base64.js +54 -0
- package/dist/src/jwt/core/utils/base64.js.map +1 -0
- package/dist/src/jwt/core/utils/definedObject.d.ts +2 -0
- package/dist/src/jwt/core/utils/definedObject.d.ts.map +1 -0
- package/dist/src/jwt/core/utils/definedObject.js +7 -0
- package/dist/src/jwt/core/utils/definedObject.js.map +1 -0
- package/dist/src/jwt/core/utils/index.d.ts +5 -0
- package/dist/src/jwt/core/utils/index.d.ts.map +1 -0
- package/dist/src/jwt/core/utils/index.js +12 -0
- package/dist/src/jwt/core/utils/index.js.map +1 -0
- package/dist/src/jwt/core/utils/processJWTSignature.d.ts +8 -0
- package/dist/src/jwt/core/utils/processJWTSignature.d.ts.map +1 -0
- package/dist/src/jwt/core/utils/processJWTSignature.js +14 -0
- package/dist/src/jwt/core/utils/processJWTSignature.js.map +1 -0
- package/dist/src/jwt/core/utils/splitJWT.d.ts +11 -0
- package/dist/src/jwt/core/utils/splitJWT.d.ts.map +1 -0
- package/dist/src/jwt/core/utils/splitJWT.js +21 -0
- package/dist/src/jwt/core/utils/splitJWT.js.map +1 -0
- package/dist/src/jwt/core/utils/validateJWTTime.d.ts +12 -0
- package/dist/src/jwt/core/utils/validateJWTTime.d.ts.map +1 -0
- package/dist/src/jwt/core/utils/validateJWTTime.js +24 -0
- package/dist/src/jwt/core/utils/validateJWTTime.js.map +1 -0
- package/dist/src/jwt/core/validate.d.ts +29 -0
- package/dist/src/jwt/core/validate.d.ts.map +1 -0
- package/dist/src/jwt/core/validate.js +143 -0
- package/dist/src/jwt/core/validate.js.map +1 -0
- package/dist/src/jwt/index.d.ts +21 -0
- package/dist/src/jwt/index.d.ts.map +1 -0
- package/dist/src/jwt/index.js +32 -0
- package/dist/src/jwt/index.js.map +1 -0
- package/dist/src/jwt/typeGuards.d.ts +14 -0
- package/dist/src/jwt/typeGuards.d.ts.map +1 -0
- package/dist/src/jwt/typeGuards.js +32 -0
- package/dist/src/jwt/typeGuards.js.map +1 -0
- package/dist/src/jwt/types.d.ts +82 -0
- package/dist/src/jwt/types.d.ts.map +1 -0
- package/dist/src/jwt/types.js +3 -0
- package/dist/src/jwt/types.js.map +1 -0
- package/dist/src/type-inference-verification/ability-client-inference.d.ts +3 -0
- package/dist/src/type-inference-verification/ability-client-inference.d.ts.map +1 -0
- package/dist/src/type-inference-verification/ability-client-inference.js +220 -0
- package/dist/src/type-inference-verification/ability-client-inference.js.map +1 -0
- package/dist/src/utils/delegation.d.ts +7 -0
- package/dist/src/utils/delegation.d.ts.map +1 -0
- package/dist/src/utils/delegation.js +18 -0
- package/dist/src/utils/delegation.js.map +1 -0
- package/dist/src/utils/index.d.ts +3 -0
- package/dist/src/utils/index.d.ts.map +1 -0
- package/dist/src/utils/index.js +6 -0
- package/dist/src/utils/index.js.map +1 -0
- package/dist/src/utils/typedocRoot.d.ts +7 -0
- package/dist/src/utils/typedocRoot.d.ts.map +1 -0
- package/dist/src/utils/typedocRoot.js +13 -0
- package/dist/src/utils/typedocRoot.js.map +1 -0
- package/dist/src/utils/types.d.ts +15 -0
- package/dist/src/utils/types.d.ts.map +1 -0
- package/dist/src/utils/types.js +3 -0
- package/dist/src/utils/types.js.map +1 -0
- package/dist/src/webAuthClient/app.d.ts +7 -0
- package/dist/src/webAuthClient/app.d.ts.map +1 -0
- package/dist/src/webAuthClient/app.js +39 -0
- package/dist/src/webAuthClient/app.js.map +1 -0
- package/dist/src/webAuthClient/constants.d.ts +3 -0
- package/dist/src/webAuthClient/constants.d.ts.map +1 -0
- package/dist/src/webAuthClient/constants.js +6 -0
- package/dist/src/webAuthClient/constants.js.map +1 -0
- package/dist/src/webAuthClient/index.d.ts +13 -0
- package/dist/src/webAuthClient/index.d.ts.map +1 -0
- package/dist/src/webAuthClient/index.js +15 -0
- package/dist/src/webAuthClient/index.js.map +1 -0
- package/dist/src/webAuthClient/internal/index.d.ts +3 -0
- package/dist/src/webAuthClient/internal/index.d.ts.map +1 -0
- package/dist/src/webAuthClient/internal/index.js +7 -0
- package/dist/src/webAuthClient/internal/index.js.map +1 -0
- package/dist/src/webAuthClient/internal/uriHelpers.d.ts +15 -0
- package/dist/src/webAuthClient/internal/uriHelpers.d.ts.map +1 -0
- package/dist/src/webAuthClient/internal/uriHelpers.js +38 -0
- package/dist/src/webAuthClient/internal/uriHelpers.js.map +1 -0
- package/dist/src/webAuthClient/types.d.ts +109 -0
- package/dist/src/webAuthClient/types.d.ts.map +1 -0
- package/dist/src/webAuthClient/types.js +3 -0
- package/dist/src/webAuthClient/types.js.map +1 -0
- package/package.json +82 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
import type { BaseAbilityContext, SchemaValidationError } from '@lit-protocol/vincent-ability-sdk';
|
|
3
|
+
import type { VincentPolicy } from '@lit-protocol/vincent-ability-sdk/internal';
|
|
4
|
+
/** @category Interfaces */
|
|
5
|
+
export interface AbilityPrecheckResponseSuccess<Result, Policies extends Record<string, any>> {
|
|
6
|
+
success: true;
|
|
7
|
+
result: Result;
|
|
8
|
+
context?: BaseAbilityContext<PolicyPrecheckResultContext<Policies>>;
|
|
9
|
+
}
|
|
10
|
+
/** @category Interfaces */
|
|
11
|
+
export interface AbilityPrecheckResponseSuccessNoResult<Policies extends Record<string, any>> {
|
|
12
|
+
success: true;
|
|
13
|
+
result?: never;
|
|
14
|
+
context?: BaseAbilityContext<PolicyPrecheckResultContext<Policies>>;
|
|
15
|
+
}
|
|
16
|
+
/** @category Interfaces */
|
|
17
|
+
export interface AbilityPrecheckResponseFailure<Result, Policies extends Record<string, any>> {
|
|
18
|
+
success: false;
|
|
19
|
+
runtimeError?: string;
|
|
20
|
+
schemaValidationError?: SchemaValidationError;
|
|
21
|
+
result: Result;
|
|
22
|
+
context?: BaseAbilityContext<PolicyPrecheckResultContext<Policies>>;
|
|
23
|
+
}
|
|
24
|
+
/** @category Interfaces */
|
|
25
|
+
export interface AbilityPrecheckResponseFailureNoResult<Policies extends Record<string, any>> {
|
|
26
|
+
success: false;
|
|
27
|
+
runtimeError?: string;
|
|
28
|
+
schemaValidationError?: SchemaValidationError;
|
|
29
|
+
result?: never;
|
|
30
|
+
context?: BaseAbilityContext<PolicyPrecheckResultContext<Policies>>;
|
|
31
|
+
}
|
|
32
|
+
/** @category Interfaces */
|
|
33
|
+
export type AbilityPrecheckResponse<SuccessSchema extends z.ZodType | undefined, FailSchema extends z.ZodType | undefined, Policies extends Record<string, any>> = (SuccessSchema extends z.ZodType ? AbilityPrecheckResponseSuccess<z.infer<SuccessSchema>, Policies> : AbilityPrecheckResponseSuccessNoResult<Policies>) | (FailSchema extends z.ZodType ? AbilityPrecheckResponseFailure<z.infer<FailSchema>, Policies> : AbilityPrecheckResponseFailureNoResult<Policies>);
|
|
34
|
+
export interface RemoteVincentAbilityExecutionResult<SuccessSchema extends z.ZodType | undefined, FailSchema extends z.ZodType | undefined, Policies extends Record<string, any>> {
|
|
35
|
+
abilityExecutionResult: AbilityPrecheckResponse<SuccessSchema, FailSchema, Policies>;
|
|
36
|
+
abilityContext: BaseAbilityContext<PolicyPrecheckResultContext<Policies>>;
|
|
37
|
+
}
|
|
38
|
+
export type PolicyPrecheckResultContext<Policies extends Record<string, {
|
|
39
|
+
vincentPolicy: VincentPolicy<any, any, any, any, any, any, any, any, any, any>;
|
|
40
|
+
/** @hidden */
|
|
41
|
+
__schemaTypes?: {
|
|
42
|
+
policyAbilityParamsSchema: z.ZodType;
|
|
43
|
+
userParamsSchema?: z.ZodType;
|
|
44
|
+
evalAllowResultSchema?: z.ZodType;
|
|
45
|
+
evalDenyResultSchema?: z.ZodType;
|
|
46
|
+
commitParamsSchema?: z.ZodType;
|
|
47
|
+
commitAllowResultSchema?: z.ZodType;
|
|
48
|
+
commitDenyResultSchema?: z.ZodType;
|
|
49
|
+
evaluate?: Function;
|
|
50
|
+
precheck?: Function;
|
|
51
|
+
commit?: Function;
|
|
52
|
+
};
|
|
53
|
+
}>> = {
|
|
54
|
+
evaluatedPolicies: Array<keyof Policies>;
|
|
55
|
+
} & ({
|
|
56
|
+
allow: true;
|
|
57
|
+
allowedPolicies: {
|
|
58
|
+
[PolicyKey in keyof Policies]?: {
|
|
59
|
+
result: Policies[PolicyKey]['__schemaTypes'] extends {
|
|
60
|
+
precheckAllowResultSchema: infer Schema;
|
|
61
|
+
} ? Schema extends z.ZodType ? z.infer<Schema> : never : never;
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
deniedPolicy?: never;
|
|
65
|
+
} | {
|
|
66
|
+
allow: false;
|
|
67
|
+
deniedPolicy: {
|
|
68
|
+
runtimeError?: string;
|
|
69
|
+
packageName: keyof Policies;
|
|
70
|
+
result: (Policies[Extract<keyof Policies, string>]['__schemaTypes'] extends {
|
|
71
|
+
precheckDenyResultSchema: infer Schema;
|
|
72
|
+
} ? Schema extends z.ZodType ? z.infer<Schema> : undefined : undefined) | undefined;
|
|
73
|
+
};
|
|
74
|
+
allowedPolicies?: {
|
|
75
|
+
[PolicyKey in keyof Policies]?: {
|
|
76
|
+
result: Policies[PolicyKey]['__schemaTypes'] extends {
|
|
77
|
+
precheckAllowResultSchema: infer Schema;
|
|
78
|
+
} ? Schema extends z.ZodType ? z.infer<Schema> : never : never;
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
});
|
|
82
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/abilityClient/precheck/types.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,OAAO,KAAK,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AACnG,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4CAA4C,CAAC;AAIhF,2BAA2B;AAC3B,MAAM,WAAW,8BAA8B,CAAC,MAAM,EAAE,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAC1F,OAAO,EAAE,IAAI,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,kBAAkB,CAAC,2BAA2B,CAAC,QAAQ,CAAC,CAAC,CAAC;CACrE;AAED,2BAA2B;AAC3B,MAAM,WAAW,sCAAsC,CAAC,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAC1F,OAAO,EAAE,IAAI,CAAC;IACd,MAAM,CAAC,EAAE,KAAK,CAAC;IACf,OAAO,CAAC,EAAE,kBAAkB,CAAC,2BAA2B,CAAC,QAAQ,CAAC,CAAC,CAAC;CACrE;AAED,2BAA2B;AAC3B,MAAM,WAAW,8BAA8B,CAAC,MAAM,EAAE,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAC1F,OAAO,EAAE,KAAK,CAAC;IACf,Y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AM,CAAC,GACf,KAAK,GACP,KAAK,CAAC;SACX;KACF,CAAC;IACF,YAAY,CAAC,EAAE,KAAK,CAAC;CACtB,GACD;IACE,KAAK,EAAE,KAAK,CAAC;IACb,YAAY,EAAE;QACZ,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,WAAW,EAAE,MAAM,QAAQ,CAAC;QAC5B,MAAM,EACF,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,eAAe,CAAC,SAAS;YAClE,wBAAwB,EAAE,MAAM,MAAM,CAAC;SACxC,GACG,MAAM,SAAS,CAAC,CAAC,OAAO,GACtB,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,GACf,SAAS,GACX,SAAS,CAAC,GACd,SAAS,CAAC;KACf,CAAC;IACF,eAAe,CAAC,EAAE;SACf,SAAS,IAAI,MAAM,QAAQ,CAAC,CAAC,EAAE;YAC9B,MAAM,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC,eAAe,CAAC,SAAS;gBACnD,yBAAyB,EAAE,MAAM,MAAM,CAAC;aACzC,GACG,MAAM,SAAS,CAAC,CAAC,OAAO,GACtB,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,GACf,KAAK,GACP,KAAK,CAAC;SACX;KACF,CAAC;CACH,CACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/abilityClient/precheck/types.ts"],"names":[],"mappings":";AAAA,0CAA0C"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { RemoteVincentAbilityExecutionResult, AbilityExecuteResponse, AbilityExecuteResponseFailure, AbilityExecuteResponseFailureNoResult, AbilityExecuteResponseSuccess, AbilityExecuteResponseSuccessNoResult } from './execute/types';
|
|
2
|
+
/** Type guard function that returns true only if the passed value is a successful ability response
|
|
3
|
+
* @category API
|
|
4
|
+
* */
|
|
5
|
+
export declare function isAbilityResponseSuccess(value: unknown): value is AbilityExecuteResponseSuccess<any, Record<string, any>> | AbilityExecuteResponseSuccessNoResult<Record<string, any>>;
|
|
6
|
+
/** Type guard function that returns true only if the passed value is a failure ability response
|
|
7
|
+
* @category API */
|
|
8
|
+
export declare function isAbilityResponseFailure(value: unknown): value is AbilityExecuteResponseFailure<any, Record<string, any>> | AbilityExecuteResponseFailureNoResult<Record<string, any>>;
|
|
9
|
+
/** Type guard function that returns true only if the passed value is a failure ability response that was a runtime error
|
|
10
|
+
* This could be caused by code `throw()`ing an error from inside ability or policy code, or by errors encountered in the
|
|
11
|
+
* Vincent SDK wrapping code that handles the execution of the ability/policies.
|
|
12
|
+
*
|
|
13
|
+
* This could also be the result of a schema validation error -- use {@link isAbilityResponseSchemaValidationFailure} to check
|
|
14
|
+
* to see if have a data validation error.
|
|
15
|
+
*
|
|
16
|
+
* @category API*/
|
|
17
|
+
export declare function isAbilityResponseRuntimeFailure(value: unknown): value is AbilityExecuteResponseFailureNoResult<Record<string, any>>;
|
|
18
|
+
/** Type guard function that returns true only if the passed value is a failure ability response that was caused by
|
|
19
|
+
* a schema parsing failure. All data inputs and outputs to / from Vincent Abilities and Policies is validated using ZOD schemas.
|
|
20
|
+
*
|
|
21
|
+
* If this returns true, you can parse the `schemaValidationError` property in the response - it is a ZodError object.
|
|
22
|
+
* @category API */
|
|
23
|
+
export declare function isAbilityResponseSchemaValidationFailure(value: unknown): value is AbilityExecuteResponseFailureNoResult<Record<string, any>>;
|
|
24
|
+
/** @hidden */
|
|
25
|
+
export declare function isAbilityResponse(value: unknown): value is AbilityExecuteResponse<any, any, Record<string, any>>;
|
|
26
|
+
/** @hidden */
|
|
27
|
+
export declare function isRemoteVincentAbilityExecutionResult(value: unknown): value is RemoteVincentAbilityExecutionResult<any, any, Record<any, any>>;
|
|
28
|
+
//# sourceMappingURL=typeGuards.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typeGuards.d.ts","sourceRoot":"","sources":["../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+1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// src/lib/abilityClient/typeGuards.ts
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.isAbilityResponseSuccess = isAbilityResponseSuccess;
|
|
5
|
+
exports.isAbilityResponseFailure = isAbilityResponseFailure;
|
|
6
|
+
exports.isAbilityResponseRuntimeFailure = isAbilityResponseRuntimeFailure;
|
|
7
|
+
exports.isAbilityResponseSchemaValidationFailure = isAbilityResponseSchemaValidationFailure;
|
|
8
|
+
exports.isAbilityResponse = isAbilityResponse;
|
|
9
|
+
exports.isRemoteVincentAbilityExecutionResult = isRemoteVincentAbilityExecutionResult;
|
|
10
|
+
/** Type guard function that returns true only if the passed value is a successful ability response
|
|
11
|
+
* @category API
|
|
12
|
+
* */
|
|
13
|
+
function isAbilityResponseSuccess(value) {
|
|
14
|
+
return (typeof value === 'object' &&
|
|
15
|
+
value !== null &&
|
|
16
|
+
'success' in value &&
|
|
17
|
+
value.success === true);
|
|
18
|
+
}
|
|
19
|
+
/** Type guard function that returns true only if the passed value is a failure ability response
|
|
20
|
+
* @category API */
|
|
21
|
+
function isAbilityResponseFailure(value) {
|
|
22
|
+
return (typeof value === 'object' &&
|
|
23
|
+
value !== null &&
|
|
24
|
+
'success' in value &&
|
|
25
|
+
value.success === false);
|
|
26
|
+
}
|
|
27
|
+
/** Type guard function that returns true only if the passed value is a failure ability response that was a runtime error
|
|
28
|
+
* This could be caused by code `throw()`ing an error from inside ability or policy code, or by errors encountered in the
|
|
29
|
+
* Vincent SDK wrapping code that handles the execution of the ability/policies.
|
|
30
|
+
*
|
|
31
|
+
* This could also be the result of a schema validation error -- use {@link isAbilityResponseSchemaValidationFailure} to check
|
|
32
|
+
* to see if have a data validation error.
|
|
33
|
+
*
|
|
34
|
+
* @category API*/
|
|
35
|
+
function isAbilityResponseRuntimeFailure(value) {
|
|
36
|
+
if (!isAbilityResponseFailure(value))
|
|
37
|
+
return false;
|
|
38
|
+
return 'runtimeError' in value && typeof value.runtimeError === 'string';
|
|
39
|
+
}
|
|
40
|
+
/** Type guard function that returns true only if the passed value is a failure ability response that was caused by
|
|
41
|
+
* a schema parsing failure. All data inputs and outputs to / from Vincent Abilities and Policies is validated using ZOD schemas.
|
|
42
|
+
*
|
|
43
|
+
* If this returns true, you can parse the `schemaValidationError` property in the response - it is a ZodError object.
|
|
44
|
+
* @category API */
|
|
45
|
+
function isAbilityResponseSchemaValidationFailure(value) {
|
|
46
|
+
if (!isAbilityResponseFailure(value))
|
|
47
|
+
return false;
|
|
48
|
+
return ('schemaValidationError' in value && typeof value.schemaValidationError === 'object');
|
|
49
|
+
}
|
|
50
|
+
/** @hidden */
|
|
51
|
+
function isAbilityResponse(value) {
|
|
52
|
+
return (typeof value === 'object' &&
|
|
53
|
+
value !== null &&
|
|
54
|
+
'success' in value &&
|
|
55
|
+
typeof value.success === 'boolean');
|
|
56
|
+
}
|
|
57
|
+
/** @hidden */
|
|
58
|
+
function isRemoteVincentAbilityExecutionResult(value) {
|
|
59
|
+
return (typeof value === 'object' &&
|
|
60
|
+
value !== null &&
|
|
61
|
+
'abilityExecutionResult' in value &&
|
|
62
|
+
'abilityContext' in value &&
|
|
63
|
+
isAbilityResponse(value.abilityExecutionResult) &&
|
|
64
|
+
typeof value.abilityContext === 'object' &&
|
|
65
|
+
value.abilityContext !== null);
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=typeGuards.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typeGuards.js","sourceRoot":"","sources":["../../../src/abilityClient/typeGuards.ts"],"names":[],"mappings":";AAAA,sCAAsC;;AActC,4DAWC;AAID,4DAWC;AAUD,0EAMC;AAOD,4FAOC;AAGD,8CASC;AAGD,sFAYC;AAtFD;;KAEK;AACL,SAAgB,wBAAwB,CACtC,KAAc;IAId,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,SAAS,IAAI,KA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0 +1,50 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
import type { BaseAbilityContext } from '@lit-protocol/vincent-ability-sdk';
|
|
3
|
+
import type { AbilityExecuteResponse } from './execute/types';
|
|
4
|
+
import type { AbilityPrecheckResponse } from './precheck/types';
|
|
5
|
+
export { type BaseAbilityContext };
|
|
6
|
+
/**
|
|
7
|
+
* The Vincent Ability Client is used to interact with Vincent abilities.
|
|
8
|
+
*
|
|
9
|
+
* - Precheck ability parameters and policies
|
|
10
|
+
* - Execute abilities remotely
|
|
11
|
+
*
|
|
12
|
+
* @typeParam AbilityParamsSchema {@removeTypeParameterCompletely}
|
|
13
|
+
* @typeParam PoliciesByPackageName {@removeTypeParameterCompletely}
|
|
14
|
+
* @typeParam ExecuteSuccessSchema {@removeTypeParameterCompletely}
|
|
15
|
+
* @typeParam ExecuteFailSchema {@removeTypeParameterCompletely}
|
|
16
|
+
* @typeParam PrecheckSuccessSchema {@removeTypeParameterCompletely}
|
|
17
|
+
* @typeParam PrecheckFailSchema {@removeTypeParameterCompletely}
|
|
18
|
+
*
|
|
19
|
+
* @category Interfaces
|
|
20
|
+
*/
|
|
21
|
+
export interface VincentAbilityClient<AbilityParamsSchema extends z.ZodType, PoliciesByPackageName extends Record<string, any>, ExecuteSuccessSchema extends z.ZodType = z.ZodUndefined, ExecuteFailSchema extends z.ZodType = z.ZodUndefined, PrecheckSuccessSchema extends z.ZodType = z.ZodUndefined, PrecheckFailSchema extends z.ZodType = z.ZodUndefined> {
|
|
22
|
+
/**
|
|
23
|
+
* Performs a precheck of the ability parameters and policies.
|
|
24
|
+
*
|
|
25
|
+
* This method validates the ability parameters and checks if the policies allow the ability to be executed.
|
|
26
|
+
*
|
|
27
|
+
* @param rawAbilityParams - The parameters to be passed to the ability
|
|
28
|
+
* @param context - The context for the ability execution, including the delegator PKP Ethereum address
|
|
29
|
+
* @returns A promise that resolves to a AbilityResponse containing the precheck result
|
|
30
|
+
*/
|
|
31
|
+
precheck(rawAbilityParams: z.infer<AbilityParamsSchema>, context: AbilityClientContext & {
|
|
32
|
+
rpcUrl?: string;
|
|
33
|
+
}): Promise<AbilityPrecheckResponse<PrecheckSuccessSchema, PrecheckFailSchema, PoliciesByPackageName>>;
|
|
34
|
+
/**
|
|
35
|
+
* Executes the ability with the given parameters.
|
|
36
|
+
*
|
|
37
|
+
* This method validates the ability parameters, executes the ability remotely, and returns the result.
|
|
38
|
+
*
|
|
39
|
+
* @param rawAbilityParams - The parameters to be passed to the ability
|
|
40
|
+
* @param context - The context for the ability execution, including the delegator PKP Ethereum address
|
|
41
|
+
* @returns A promise that resolves to a AbilityResponse containing the execution result
|
|
42
|
+
*
|
|
43
|
+
*/
|
|
44
|
+
execute(rawAbilityParams: z.infer<AbilityParamsSchema>, context: AbilityClientContext): Promise<AbilityExecuteResponse<ExecuteSuccessSchema, ExecuteFailSchema, PoliciesByPackageName>>;
|
|
45
|
+
}
|
|
46
|
+
/** @category Interfaces */
|
|
47
|
+
export interface AbilityClientContext {
|
|
48
|
+
delegatorPkpEthAddress: string;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/abilityClient/types.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AAE5E,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAEhE,OAAO,EAAE,KAAK,kBAAkB,EAAE,CAAC;AAEnC;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,oBAAoB,CACnC,mBAAmB,SAAS,CAAC,CAAC,OAAO,EACrC,qBAAqB,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACjD,oBAAoB,SAAS,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,YAAY,EACvD,iBAAiB,SAAS,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,YAAY,EACpD,qBAAqB,SAAS,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,YAAY,EACxD,kBAAkB,SAAS,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,YAAY;IAErD;;;;;;;;OAQG;IACH,QAAQ,CACN,gBAAgB,EAAE,CAAC,CAAC,KAAK,CAAC,mBAAmB,CAAC,EAC9C,OAAO,EAAE,oBAAoB,GAAG;QAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,GACA,OAAO,CACR,uBAAuB,CAAC,qBAAqB,EAAE,kBAAkB,EAAE,qBAAqB,CAAC,CAC1F,CAAC;IAEF;;;;;;;;;OASG;IACH,OAAO,CACL,gBAAgB,EAAE,CAAC,CAAC,KAAK,CAAC,mBAAmB,CAAC,EAC9C,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CACR,sBAAsB,CAAC,oBAAoB,EAAE,iBAAiB,EAAE,qBAAqB,CAAC,CACvF,CAAC;CACH;AAED,2BAA2B;AAC3B,MAAM,WAAW,oBAAoB;IACnC,sBAAsB,EAAE,MAAM,CAAC;CAChC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/abilityClient/types.ts"],"names":[],"mappings":";AAAA,iCAAiC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { ethers } from 'ethers';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import type { BundledVincentAbility, VincentAbility } from '@lit-protocol/vincent-ability-sdk';
|
|
4
|
+
import type { AbilityPolicyMap } from '@lit-protocol/vincent-ability-sdk/internal';
|
|
5
|
+
import type { VincentAbilityClient } from './types';
|
|
6
|
+
/** A VincentAbilityClient provides a type-safe interface for executing abilities, for both `precheck()`
|
|
7
|
+
* and `execute()` functionality.
|
|
8
|
+
*
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { disconnectVincentAbilityClients, getVincentAbilityClient, isAbilityResponseFailure } from '@lit-protocol/vincent-app-sdk/abilityClient';
|
|
11
|
+
* import { bundledVincentAbility as uniswapBundledAbility } from '@lit-protocol/vincent-ability-uniswap-swap';
|
|
12
|
+
* import { delegateeEthersSigner } = from './ethersSigner';
|
|
13
|
+
* import { ETH_RPC_URL, BASE_RPC_URL } from './rpcConfigs';
|
|
14
|
+
*
|
|
15
|
+
* const uniswapAbilityClient = getVincentAbilityClient({
|
|
16
|
+
* bundledVincentAbility: uniswapBundledAbility,
|
|
17
|
+
* ethersSigner: delegateeEthersSigner,
|
|
18
|
+
* });
|
|
19
|
+
*
|
|
20
|
+
* // First, call `precheck()` to get a best-estimate result indicating that the ability execution in the LIT action runtime will not fail
|
|
21
|
+
* const precheckResult = await uniswapSwapAbilityClient.precheck({
|
|
22
|
+
* ethRpcUrl: ETH_RPC_URL,
|
|
23
|
+
* rpcUrlForUniswap: BASE_RPC_URL,
|
|
24
|
+
* chainIdForUniswap: 8453, // Base
|
|
25
|
+
* tokenInAddress: '0x4200000000000000000000000000000000000006', // WETH
|
|
26
|
+
* tokenInDecimals: 18,
|
|
27
|
+
* tokenInAmount: 0.0000077,
|
|
28
|
+
* tokenOutAddress: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', // USDC on Base
|
|
29
|
+
* tokenOutDecimals: 8,
|
|
30
|
+
* },
|
|
31
|
+
* {
|
|
32
|
+
* delegatorPkpEthAddress: '0x123456789123456789123456789...',
|
|
33
|
+
* });
|
|
34
|
+
*
|
|
35
|
+
* const uniswapSwapExecutionResult = await uniswapSwapAbilityClient.execute({
|
|
36
|
+
* ethRpcUrl: ETH_RPC_URL,
|
|
37
|
+
* rpcUrlForUniswap: BASE_RPC_URL,
|
|
38
|
+
* chainIdForUniswap: 8453,
|
|
39
|
+
* tokenInAddress: '0x4200000000000000000000000000000000000006', // WETH
|
|
40
|
+
* tokenInDecimals: 18,
|
|
41
|
+
* tokenInAmount: 0.0000077,
|
|
42
|
+
* tokenOutAddress: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', // USDC on Base
|
|
43
|
+
* tokenOutDecimals: 8,
|
|
44
|
+
* },
|
|
45
|
+
* {
|
|
46
|
+
* delegatorPkpEthAddress: '0x123456789123456789123456789...',
|
|
47
|
+
* });
|
|
48
|
+
*
|
|
49
|
+
* if(isAbilityResponseFailure(uniswapSwapExecutionResult)) {
|
|
50
|
+
* ...handle failure
|
|
51
|
+
* } else {
|
|
52
|
+
* ...handle result
|
|
53
|
+
* }
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @typeParam IpfsCid {@removeTypeParameterCompletely}
|
|
57
|
+
* @typeParam AbilityParamsSchema {@removeTypeParameterCompletely}
|
|
58
|
+
* @typeParam PkgNames {@removeTypeParameterCompletely}
|
|
59
|
+
* @typeParam PolicyMap {@removeTypeParameterCompletely}
|
|
60
|
+
* @typeParam PoliciesByPackageName {@removeTypeParameterCompletely}
|
|
61
|
+
* @typeParam ExecuteSuccessSchema {@removeTypeParameterCompletely}
|
|
62
|
+
* @typeParam ExecuteFailSchema {@removeTypeParameterCompletely}
|
|
63
|
+
* @typeParam PrecheckSuccessSchema {@removeTypeParameterCompletely}
|
|
64
|
+
* @typeParam PrecheckFailSchema {@removeTypeParameterCompletely}
|
|
65
|
+
*
|
|
66
|
+
* @param params
|
|
67
|
+
* @param params.ethersSigner - An ethers signer that has been configured with your delegatee key
|
|
68
|
+
* @param params.bundledVincentAbility - The bundled vincent ability that you want to interact with
|
|
69
|
+
*
|
|
70
|
+
* @category API
|
|
71
|
+
* */
|
|
72
|
+
export declare function getVincentAbilityClient<const IpfsCid extends string, AbilityParamsSchema extends z.ZodType, PkgNames extends string, PolicyMap extends AbilityPolicyMap<any, PkgNames>, PoliciesByPackageName extends PolicyMap['policyByPackageName'], ExecuteSuccessSchema extends z.ZodType = z.ZodUndefined, ExecuteFailSchema extends z.ZodType = z.ZodUndefined, PrecheckSuccessSchema extends z.ZodType = z.ZodUndefined, PrecheckFailSchema extends z.ZodType = z.ZodUndefined>(params: {
|
|
73
|
+
bundledVincentAbility: BundledVincentAbility<VincentAbility<AbilityParamsSchema, PkgNames, PolicyMap, PoliciesByPackageName, ExecuteSuccessSchema, ExecuteFailSchema, PrecheckSuccessSchema, PrecheckFailSchema, any, any>, IpfsCid>;
|
|
74
|
+
ethersSigner: ethers.Signer;
|
|
75
|
+
}): VincentAbilityClient<AbilityParamsSchema, PoliciesByPackageName, ExecuteSuccessSchema, ExecuteFailSchema, PrecheckSuccessSchema, PrecheckFailSchema>;
|
|
76
|
+
//# sourceMappingURL=vincentAbilityClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vincentAbilityClient.d.ts","sourceRoot":"","sources":["../../../src/abilityClient/vincentAbilityClient.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAC/F,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4CAA4C,CAAC;AAcnF,OAAO,KAAK,EAAwB,oBAAoB,EAAE,MAAM,SAAS,CAAC;AA2B1E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAiEK;AACL,wBAAgB,uBAAuB,CACrC,KAAK,CAAC,OAAO,SAAS,MAAM,EAC5B,mBAAmB,SAAS,CAAC,CAAC,OAAO,EACrC,QAAQ,SAAS,MAAM,EACvB,SAAS,SAAS,gBAAgB,CAAC,GAAG,EAAE,QAAQ,CAAC,EACjD,qBAAqB,SAAS,SAAS,CAAC,qBAAqB,CAAC,EAC9D,oBAAoB,SAAS,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,YAAY,EACvD,iBAAiB,SAAS,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,YAAY,EACpD,qBAAqB,SAAS,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,YAAY,EACxD,kBAAkB,SAAS,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,YAAY,EACrD,MAAM,EAAE;IACR,qBAAqB,EAAE,qBAAqB,CAC1C,cAAc,CACZ,mBAAmB,EACnB,QAAQ,EACR,SAAS,EACT,qBAAqB,EACrB,oBAAoB,EACpB,iBAAiB,EACjB,qBAAqB,EACrB,kBAAkB,EAClB,GAAG,EACH,GAAG,CACJ,EACD,OAAO,CACR,CAAC;IACF,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC;CAC7B,GAAG,oBAAoB,CACtB,mBAAmB,EACnB,qBAAqB,EACrB,oBAAoB,EACpB,iBAAiB,EACjB,qBAAqB,EACrB,kBAAkB,CACnB,CAmWA"}
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// src/abilityClient/vincentAbilityClient.ts
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.getVincentAbilityClient = getVincentAbilityClient;
|
|
5
|
+
const ethers_1 = require("ethers");
|
|
6
|
+
const zod_1 = require("zod");
|
|
7
|
+
const constants_1 = require("@lit-protocol/constants");
|
|
8
|
+
const internal_1 = require("@lit-protocol/vincent-ability-sdk/internal");
|
|
9
|
+
const getLitNodeClient_1 = require("../internal/LitNodeClient/getLitNodeClient");
|
|
10
|
+
const generateVincentAbilitySessionSigs_1 = require("./execute/generateVincentAbilitySessionSigs");
|
|
11
|
+
const resultCreators_1 = require("./execute/resultCreators");
|
|
12
|
+
const resultCreators_2 = require("./precheck/resultCreators");
|
|
13
|
+
const runPolicyPrechecks_1 = require("./precheck/runPolicyPrechecks");
|
|
14
|
+
const typeGuards_1 = require("./typeGuards");
|
|
15
|
+
const YELLOWSTONE_RPC_URL = 'https://yellowstone-rpc.litprotocol.com/';
|
|
16
|
+
const bigintReplacer = (key, value) => {
|
|
17
|
+
return typeof value === 'bigint' ? value.toString() : value;
|
|
18
|
+
};
|
|
19
|
+
/** A VincentAbilityClient provides a type-safe interface for executing abilities, for both `precheck()`
|
|
20
|
+
* and `execute()` functionality.
|
|
21
|
+
*
|
|
22
|
+
* ```typescript
|
|
23
|
+
* import { disconnectVincentAbilityClients, getVincentAbilityClient, isAbilityResponseFailure } from '@lit-protocol/vincent-app-sdk/abilityClient';
|
|
24
|
+
* import { bundledVincentAbility as uniswapBundledAbility } from '@lit-protocol/vincent-ability-uniswap-swap';
|
|
25
|
+
* import { delegateeEthersSigner } = from './ethersSigner';
|
|
26
|
+
* import { ETH_RPC_URL, BASE_RPC_URL } from './rpcConfigs';
|
|
27
|
+
*
|
|
28
|
+
* const uniswapAbilityClient = getVincentAbilityClient({
|
|
29
|
+
* bundledVincentAbility: uniswapBundledAbility,
|
|
30
|
+
* ethersSigner: delegateeEthersSigner,
|
|
31
|
+
* });
|
|
32
|
+
*
|
|
33
|
+
* // First, call `precheck()` to get a best-estimate result indicating that the ability execution in the LIT action runtime will not fail
|
|
34
|
+
* const precheckResult = await uniswapSwapAbilityClient.precheck({
|
|
35
|
+
* ethRpcUrl: ETH_RPC_URL,
|
|
36
|
+
* rpcUrlForUniswap: BASE_RPC_URL,
|
|
37
|
+
* chainIdForUniswap: 8453, // Base
|
|
38
|
+
* tokenInAddress: '0x4200000000000000000000000000000000000006', // WETH
|
|
39
|
+
* tokenInDecimals: 18,
|
|
40
|
+
* tokenInAmount: 0.0000077,
|
|
41
|
+
* tokenOutAddress: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', // USDC on Base
|
|
42
|
+
* tokenOutDecimals: 8,
|
|
43
|
+
* },
|
|
44
|
+
* {
|
|
45
|
+
* delegatorPkpEthAddress: '0x123456789123456789123456789...',
|
|
46
|
+
* });
|
|
47
|
+
*
|
|
48
|
+
* const uniswapSwapExecutionResult = await uniswapSwapAbilityClient.execute({
|
|
49
|
+
* ethRpcUrl: ETH_RPC_URL,
|
|
50
|
+
* rpcUrlForUniswap: BASE_RPC_URL,
|
|
51
|
+
* chainIdForUniswap: 8453,
|
|
52
|
+
* tokenInAddress: '0x4200000000000000000000000000000000000006', // WETH
|
|
53
|
+
* tokenInDecimals: 18,
|
|
54
|
+
* tokenInAmount: 0.0000077,
|
|
55
|
+
* tokenOutAddress: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', // USDC on Base
|
|
56
|
+
* tokenOutDecimals: 8,
|
|
57
|
+
* },
|
|
58
|
+
* {
|
|
59
|
+
* delegatorPkpEthAddress: '0x123456789123456789123456789...',
|
|
60
|
+
* });
|
|
61
|
+
*
|
|
62
|
+
* if(isAbilityResponseFailure(uniswapSwapExecutionResult)) {
|
|
63
|
+
* ...handle failure
|
|
64
|
+
* } else {
|
|
65
|
+
* ...handle result
|
|
66
|
+
* }
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* @typeParam IpfsCid {@removeTypeParameterCompletely}
|
|
70
|
+
* @typeParam AbilityParamsSchema {@removeTypeParameterCompletely}
|
|
71
|
+
* @typeParam PkgNames {@removeTypeParameterCompletely}
|
|
72
|
+
* @typeParam PolicyMap {@removeTypeParameterCompletely}
|
|
73
|
+
* @typeParam PoliciesByPackageName {@removeTypeParameterCompletely}
|
|
74
|
+
* @typeParam ExecuteSuccessSchema {@removeTypeParameterCompletely}
|
|
75
|
+
* @typeParam ExecuteFailSchema {@removeTypeParameterCompletely}
|
|
76
|
+
* @typeParam PrecheckSuccessSchema {@removeTypeParameterCompletely}
|
|
77
|
+
* @typeParam PrecheckFailSchema {@removeTypeParameterCompletely}
|
|
78
|
+
*
|
|
79
|
+
* @param params
|
|
80
|
+
* @param params.ethersSigner - An ethers signer that has been configured with your delegatee key
|
|
81
|
+
* @param params.bundledVincentAbility - The bundled vincent ability that you want to interact with
|
|
82
|
+
*
|
|
83
|
+
* @category API
|
|
84
|
+
* */
|
|
85
|
+
function getVincentAbilityClient(params) {
|
|
86
|
+
var _a, _b;
|
|
87
|
+
const { bundledVincentAbility, ethersSigner } = params;
|
|
88
|
+
const { ipfsCid, vincentAbility, vincentAbilityApiVersion } = bundledVincentAbility;
|
|
89
|
+
(0, internal_1.assertSupportedAbilityVersion)(vincentAbilityApiVersion);
|
|
90
|
+
const network = constants_1.LIT_NETWORK.Datil;
|
|
91
|
+
const executeSuccessSchema = ((_a = vincentAbility.__schemaTypes.executeSuccessSchema) !== null && _a !== void 0 ? _a : zod_1.z.undefined());
|
|
92
|
+
const executeFailSchema = ((_b = vincentAbility.__schemaTypes.executeFailSchema) !== null && _b !== void 0 ? _b : zod_1.z.undefined());
|
|
93
|
+
return {
|
|
94
|
+
async precheck(rawAbilityParams, { rpcUrl, delegatorPkpEthAddress, }) {
|
|
95
|
+
console.log('precheck', { rawAbilityParams, delegatorPkpEthAddress, rpcUrl });
|
|
96
|
+
const delegateePkpEthAddress = ethers_1.ethers.utils.getAddress(await ethersSigner.getAddress());
|
|
97
|
+
// This will be populated further during execution; if an error is encountered, it'll include as much data as we can give the caller.
|
|
98
|
+
const baseContext = {
|
|
99
|
+
delegation: {
|
|
100
|
+
delegateeAddress: delegateePkpEthAddress,
|
|
101
|
+
// delegatorPkpInfo: null,
|
|
102
|
+
},
|
|
103
|
+
abilityIpfsCid: ipfsCid,
|
|
104
|
+
// appId: undefined,
|
|
105
|
+
// appVersion: undefined,
|
|
106
|
+
};
|
|
107
|
+
const parsedParams = (0, internal_1.validateOrFail)(rawAbilityParams, vincentAbility.abilityParamsSchema, 'precheck', 'input');
|
|
108
|
+
if ((0, typeGuards_1.isAbilityResponseFailure)(parsedParams)) {
|
|
109
|
+
return (0, resultCreators_2.createAbilityPrecheckResponseFailureNoResult)({
|
|
110
|
+
...parsedParams,
|
|
111
|
+
context: baseContext,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
const userPkpInfo = await (0, internal_1.getPkpInfo)({
|
|
115
|
+
litPubkeyRouterAddress: internal_1.LIT_DATIL_PUBKEY_ROUTER_ADDRESS,
|
|
116
|
+
yellowstoneRpcUrl: rpcUrl !== null && rpcUrl !== void 0 ? rpcUrl : YELLOWSTONE_RPC_URL,
|
|
117
|
+
pkpEthAddress: delegatorPkpEthAddress,
|
|
118
|
+
});
|
|
119
|
+
baseContext.delegation.delegatorPkpInfo = userPkpInfo;
|
|
120
|
+
console.log('userPkpInfo', userPkpInfo);
|
|
121
|
+
const { decodedPolicies, appId, appVersion } = await (0, internal_1.getPoliciesAndAppVersion)({
|
|
122
|
+
delegationRpcUrl: rpcUrl !== null && rpcUrl !== void 0 ? rpcUrl : YELLOWSTONE_RPC_URL,
|
|
123
|
+
appDelegateeAddress: delegateePkpEthAddress,
|
|
124
|
+
agentWalletPkpEthAddress: delegatorPkpEthAddress,
|
|
125
|
+
abilityIpfsCid: ipfsCid,
|
|
126
|
+
});
|
|
127
|
+
baseContext.appId = appId.toNumber();
|
|
128
|
+
baseContext.appVersion = appVersion.toNumber();
|
|
129
|
+
console.log('Fetched policies and app info', { decodedPolicies, appId, appVersion });
|
|
130
|
+
const baseAbilityContext = await (0, runPolicyPrechecks_1.runAbilityPolicyPrechecks)({
|
|
131
|
+
bundledVincentAbility,
|
|
132
|
+
abilityParams: parsedParams,
|
|
133
|
+
decodedPolicies,
|
|
134
|
+
context: {
|
|
135
|
+
...baseContext,
|
|
136
|
+
rpcUrl,
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
if (!vincentAbility.precheck) {
|
|
140
|
+
console.log('No ability precheck defined - returning baseContext policy evaluation results', {
|
|
141
|
+
rawAbilityParams,
|
|
142
|
+
delegatorPkpEthAddress,
|
|
143
|
+
rpcUrl,
|
|
144
|
+
});
|
|
145
|
+
if (!baseAbilityContext.policiesContext.allow) {
|
|
146
|
+
return (0, resultCreators_2.createAbilityPrecheckResponseFailureNoResult)({
|
|
147
|
+
context: baseAbilityContext,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
return (0, resultCreators_2.createAbilityPrecheckResponseSuccessNoResult)({
|
|
151
|
+
context: baseAbilityContext,
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
console.log('Executing ability precheck');
|
|
155
|
+
const precheckResult = await vincentAbility.precheck({ abilityParams: parsedParams }, baseAbilityContext);
|
|
156
|
+
if ((0, typeGuards_1.isAbilityResponseSchemaValidationFailure)(precheckResult) ||
|
|
157
|
+
(0, typeGuards_1.isAbilityResponseRuntimeFailure)(precheckResult)) {
|
|
158
|
+
console.log('Detected runtime or schema validation error in abilityPrecheckResult - returning as-is:', JSON.stringify({
|
|
159
|
+
isAbilityResponseRuntimeFailure: (0, typeGuards_1.isAbilityResponseRuntimeFailure)(precheckResult),
|
|
160
|
+
isAbilityResponseSchemaValidationFailure: (0, typeGuards_1.isAbilityResponseSchemaValidationFailure)(precheckResult),
|
|
161
|
+
precheckResult,
|
|
162
|
+
}, bigintReplacer));
|
|
163
|
+
// Runtime errors and schema validation errors will not have results; return them as-is.
|
|
164
|
+
return precheckResult;
|
|
165
|
+
}
|
|
166
|
+
console.log('precheckResult()', JSON.stringify(precheckResult, bigintReplacer));
|
|
167
|
+
return {
|
|
168
|
+
...precheckResult,
|
|
169
|
+
context: baseAbilityContext,
|
|
170
|
+
};
|
|
171
|
+
},
|
|
172
|
+
async execute(rawAbilityParams, context) {
|
|
173
|
+
const parsedParams = (0, internal_1.validateOrFail)(rawAbilityParams, vincentAbility.abilityParamsSchema, 'execute', 'input');
|
|
174
|
+
if ((0, typeGuards_1.isAbilityResponseFailure)(parsedParams)) {
|
|
175
|
+
return {
|
|
176
|
+
...parsedParams,
|
|
177
|
+
context,
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
const litNodeClient = await (0, getLitNodeClient_1.getLitNodeClientInstance)({ network });
|
|
181
|
+
const sessionSigs = await (0, generateVincentAbilitySessionSigs_1.generateVincentAbilitySessionSigs)({ ethersSigner, litNodeClient });
|
|
182
|
+
const result = await litNodeClient.executeJs({
|
|
183
|
+
ipfsId: ipfsCid,
|
|
184
|
+
sessionSigs,
|
|
185
|
+
jsParams: {
|
|
186
|
+
abilityParams: parsedParams,
|
|
187
|
+
context,
|
|
188
|
+
vincentAbilityApiVersion,
|
|
189
|
+
},
|
|
190
|
+
});
|
|
191
|
+
const { success, response } = result;
|
|
192
|
+
console.log('executeResult - raw result from `litNodeClient.executeJs()', {
|
|
193
|
+
response,
|
|
194
|
+
success,
|
|
195
|
+
});
|
|
196
|
+
if (success !== true) {
|
|
197
|
+
return (0, resultCreators_1.createAbilityExecuteResponseFailureNoResult)({
|
|
198
|
+
runtimeError: `Remote ability failed with unknown error: ${JSON.stringify(response, bigintReplacer, 2)}`,
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
let parsedResult = response;
|
|
202
|
+
if (typeof response === 'string') {
|
|
203
|
+
// lit-node-client returns a string if no signed data, even if the result could be JSON.parse'd :(
|
|
204
|
+
try {
|
|
205
|
+
parsedResult = JSON.parse(response);
|
|
206
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
207
|
+
}
|
|
208
|
+
catch (e) {
|
|
209
|
+
return (0, resultCreators_1.createAbilityExecuteResponseFailureNoResult)({
|
|
210
|
+
runtimeError: `Remote ability failed with unknown error: ${JSON.stringify(response, bigintReplacer)}`,
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
if (!(0, typeGuards_1.isRemoteVincentAbilityExecutionResult)(parsedResult)) {
|
|
215
|
+
console.log('Result from `executeJs` was valid JSON, but not a vincentAbilityExecutionResult', { parsedResult, success });
|
|
216
|
+
return (0, resultCreators_1.createAbilityExecuteResponseFailureNoResult)({
|
|
217
|
+
runtimeError: `Remote ability failed with unknown error: ${JSON.stringify(parsedResult, bigintReplacer)}`,
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
const remoteVincentAbilityResult = parsedResult;
|
|
221
|
+
console.log('Parsed executeJs vincentAbilityExecutionResult:', JSON.stringify(parsedResult, bigintReplacer));
|
|
222
|
+
const { abilityContext, abilityExecutionResult } = remoteVincentAbilityResult;
|
|
223
|
+
if ((0, typeGuards_1.isAbilityResponseSchemaValidationFailure)(abilityExecutionResult) ||
|
|
224
|
+
(0, typeGuards_1.isAbilityResponseRuntimeFailure)(abilityExecutionResult)) {
|
|
225
|
+
console.log('Detected runtime or schema validation error in abilityExecutionResult - returning as-is:', JSON.stringify({
|
|
226
|
+
isAbilityResponseRuntimeFailure: (0, typeGuards_1.isAbilityResponseRuntimeFailure)(abilityExecutionResult),
|
|
227
|
+
isAbilityResponseSchemaValidationFailure: (0, typeGuards_1.isAbilityResponseSchemaValidationFailure)(abilityExecutionResult),
|
|
228
|
+
abilityExecutionResult,
|
|
229
|
+
}, bigintReplacer));
|
|
230
|
+
// Runtime errors and schema validation errors will not have results; return them as-is.
|
|
231
|
+
return (0, resultCreators_1.createAbilityExecuteResponseFailureNoResult)({
|
|
232
|
+
...(abilityExecutionResult.runtimeError
|
|
233
|
+
? { runtimeError: abilityExecutionResult.runtimeError }
|
|
234
|
+
: {}),
|
|
235
|
+
...(abilityExecutionResult.schemaValidationError
|
|
236
|
+
? { schemaValidationError: abilityExecutionResult.schemaValidationError }
|
|
237
|
+
: {}),
|
|
238
|
+
context: remoteVincentAbilityResult.abilityContext,
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
// Policy eval happens before `execute()` is ever called
|
|
242
|
+
// As a result, when policies return a `deny` result, there will be no ability result
|
|
243
|
+
// so we need to skip trying to run result through the success/fail schema logic
|
|
244
|
+
if (!abilityContext.policiesContext.allow) {
|
|
245
|
+
return (0, resultCreators_1.createAbilityExecuteResponseFailureNoResult)({
|
|
246
|
+
context: abilityContext,
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
const resultSchemaDetails = (0, internal_1.getSchemaForAbilityResult)({
|
|
250
|
+
value: abilityExecutionResult,
|
|
251
|
+
successResultSchema: executeSuccessSchema,
|
|
252
|
+
failureResultSchema: executeFailSchema,
|
|
253
|
+
});
|
|
254
|
+
const { schemaToUse, parsedType } = resultSchemaDetails;
|
|
255
|
+
console.log(`Parsing ability result using the ${parsedType} Zod schema`);
|
|
256
|
+
// Parse returned result using appropriate execute zod schema
|
|
257
|
+
const executeResult = (0, internal_1.validateOrFail)(abilityExecutionResult.result, schemaToUse, 'execute', 'output');
|
|
258
|
+
console.log('Zod parse result:', executeResult);
|
|
259
|
+
if ((0, typeGuards_1.isAbilityResponseFailure)(executeResult)) {
|
|
260
|
+
// Parsing the result threw a zodError
|
|
261
|
+
return executeResult;
|
|
262
|
+
}
|
|
263
|
+
console.log('Raw abilityExecutionResult was:', abilityExecutionResult);
|
|
264
|
+
// We parsed the result -- it may be a success or a failure; return appropriately.
|
|
265
|
+
if ((0, typeGuards_1.isAbilityResponseFailure)(abilityExecutionResult)) {
|
|
266
|
+
return (0, resultCreators_1.createAbilityExecuteResponseFailure)({
|
|
267
|
+
...(abilityExecutionResult.runtimeError
|
|
268
|
+
? { runtimeError: abilityExecutionResult.runtimeError }
|
|
269
|
+
: {}),
|
|
270
|
+
...(abilityExecutionResult.schemaValidationError
|
|
271
|
+
? { schemaValidationError: abilityExecutionResult.schemaValidationError }
|
|
272
|
+
: {}),
|
|
273
|
+
result: executeResult,
|
|
274
|
+
context: remoteVincentAbilityResult.abilityContext,
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
const res = executeResult;
|
|
278
|
+
return (0, resultCreators_1.createAbilityExecuteResponseSuccess)({
|
|
279
|
+
result: res,
|
|
280
|
+
context: remoteVincentAbilityResult.abilityContext,
|
|
281
|
+
});
|
|
282
|
+
},
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
//# sourceMappingURL=vincentAbilityClient.js.map
|