Skip to content
This repository was archived by the owner on Apr 30, 2025. It is now read-only.

Wyatt/aw signer refactor #78

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/aw-contracts-sdk/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# aw-contracts-sdk

This library was generated with [Nx](https://nx.dev).

## Building

Run `nx build aw-contracts-sdk` to build the library.

## Running unit tests

Run `nx test aw-contracts-sdk` to execute the unit tests via [Jest](https://jestjs.io).
19 changes: 19 additions & 0 deletions packages/aw-contracts-sdk/eslint.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const baseConfig = require('../../eslint.config.cjs');

module.exports = [
...baseConfig,
{
files: ['**/*.json'],
rules: {
'@nx/dependency-checks': [
'error',
{
ignoredFiles: ['{projectRoot}/eslint.config.{js,cjs,mjs}'],
},
],
},
languageOptions: {
parser: require('jsonc-eslint-parser'),
},
},
];
10 changes: 10 additions & 0 deletions packages/aw-contracts-sdk/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default {
displayName: 'aw-contracts-sdk',
preset: '../../jest.preset.js',
testEnvironment: 'node',
transform: {
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: 'test-output/jest/coverage',
};
21 changes: 21 additions & 0 deletions packages/aw-contracts-sdk/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "@lit-protocol/aw-contracts-sdk",
"version": "0.0.1",
"dependencies": {
"@lit-protocol/constants": "7.0.2",
"ethers": "5.7.2",
"tslib": "^2.3.0"
},
"type": "commonjs",
"main": "./dist/index.js",
"typings": "./dist/index.d.ts",
"files": [
"dist",
"!**/*.tsbuildinfo"
],
"nx": {
"sourceRoot": "packages/aw-contracts-sdk/src",
"projectType": "library",
"name": "aw-contracts-sdk"
}
}
2 changes: 2 additions & 0 deletions packages/aw-contracts-sdk/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './lib/pkp-tool-registry-contract';
export * from './lib/human-readable-abi';
76 changes: 76 additions & 0 deletions packages/aw-contracts-sdk/src/lib/human-readable-abi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
export const PKP_TOOL_REGISTRY_ABI = [
// Tool Facet Functions
'function registerTools(uint256 pkpTokenId, string[] calldata toolIpfsCids, bool enabled) external',
'function removeTools(uint256 pkpTokenId, string[] calldata toolIpfsCids) external',

'function enableTools(uint256 pkpTokenId, string[] calldata toolIpfsCids) external',
'function disableTools(uint256 pkpTokenId, string[] calldata toolIpfsCids) external',

'function permitToolsForDelegatees(uint256 pkpTokenId, string[] calldata toolIpfsCids, address[] calldata delegatees) external',
'function unpermitToolsForDelegatees(uint256 pkpTokenId, string[] calldata toolIpfsCids, address[] calldata delegatees) external',

'function getRegisteredTools(uint256 pkpTokenId, string[] calldata toolIpfsCids) external view returns (tuple(string toolIpfsCid, bool toolEnabled)[] memory toolsInfo)',
'function getAllRegisteredTools(uint256 pkpTokenId) external view returns (tuple(string toolIpfsCid, bool toolEnabled)[] memory toolsInfo)',
'function getRegisteredToolsAndDelegatees(uint256 pkpTokenId, string[] calldata toolIpfsCids) external view returns (tuple(string toolIpfsCid, bool toolEnabled, address[] delegatees, string[] delegateesPolicyIpfsCids, bool[] delegateesPolicyEnabled) memory toolInfo)',
'function getAllRegisteredToolsAndDelegatees(uint256 pkpTokenId) external view returns (tuple(string toolIpfsCid, bool toolEnabled, address[] delegatees, string[] delegateesPolicyIpfsCids, bool[] delegateesPolicyEnabled)[] memory toolsInfo)',
'function getToolsWithPolicy(uint256 pkpTokenId) external view returns (tuple(string toolIpfsCid, bool toolEnabled, address[] delegatees, string[] delegateesPolicyIpfsCids, bool[] delegateesPolicyEnabled)[] memory toolsInfo)',
'function getToolsWithoutPolicy(uint256 pkpTokenId) external view returns (tuple(string toolIpfsCid, bool toolEnabled, address[] delegatees)[] memory toolsWithoutPolicy)',

'function isToolRegistered(uint256 pkpTokenId, string calldata toolIpfsCid) external view returns (bool isRegistered, bool isEnabled)',
'function isToolPermittedForDelegatee(uint256 pkpTokenId, string calldata toolIpfsCid, address delegatee) external view returns (bool isPermitted, bool isEnabled)',
'function getPermittedToolsForDelegatee(uint256 pkpTokenId, address delegatee) external view returns (tuple(string toolIpfsCid, bool toolEnabled, address delegatee, string policyIpfsCid, bool policyEnabled)[] memory permittedTools)',

// Delegatee Facet Functions
'function addDelegatees(uint256 pkpTokenId, address[] calldata delegatees) external',
'function removeDelegatees(uint256 pkpTokenId, address[] calldata delegatees) external',
'function getDelegatees(uint256 pkpTokenId) external view returns (address[] memory)',
'function getDelegatedPkps(address delegatee) external view returns (uint256[] memory)',
'function isPkpDelegatee(uint256 pkpTokenId, address delegatee) external view returns (bool)',

// Policy Facet Functions
'function getToolPoliciesForDelegatees(uint256 pkpTokenId, string[] calldata toolIpfsCids, address[] calldata delegatees) external view returns (tuple(string toolIpfsCid, string policyIpfsCid, address delegatee, bool enabled)[] memory toolPolicies)',
'function setToolPoliciesForDelegatees(uint256 pkpTokenId, string[] calldata toolIpfsCids, address[] calldata delegatees, string[] calldata policyIpfsCids, bool enablePolicies) external',
'function removeToolPoliciesForDelegatees(uint256 pkpTokenId, string[] calldata toolIpfsCids, address[] calldata delegatees) external',
'function enableToolPoliciesForDelegatees(uint256 pkpTokenId, string[] calldata toolIpfsCids, address[] calldata delegatees) external',
'function disableToolPoliciesForDelegatees(uint256 pkpTokenId, string[] calldata toolIpfsCids, address[] calldata delegatees) external',

// Policy Parameter Facet Functions
'function getToolPolicyParameters(uint256 pkpTokenId, string calldata toolIpfsCid, address delegatee, string[] calldata parameterNames) external view returns (tuple(string name, bytes value)[] memory parameters)',
'function getAllToolPolicyParameters(uint256 pkpTokenId, string calldata toolIpfsCid, address delegatee) external view returns (tuple(string name, bytes value)[] memory parameters)',
'function setToolPolicyParametersForDelegatee(uint256 pkpTokenId, string calldata toolIpfsCid, address delegatee, string[] calldata parameterNames, bytes[] calldata parameterValues) external',
'function removeToolPolicyParametersForDelegatee(uint256 pkpTokenId, string calldata toolIpfsCid, address delegatee, string[] calldata parameterNames) external',

// Error Signatures
'error InvalidDelegatee()',
'error EmptyDelegatees()',
'error DelegateeAlreadyExists(uint256 pkpTokenId, address delegatee)',
'error DelegateeNotFound(uint256 pkpTokenId, address delegatee)',
'error EmptyIPFSCID()',
'error ToolNotFound(string toolIpfsCid)',
'error ToolAlreadyRegistered(string toolIpfsCid)',
'error ArrayLengthMismatch()',
'error InvalidPolicyParameters()',
'error PolicyParameterAlreadySet(string parameterName)',
'error InvalidPolicyValue()',
'error NoPolicySet(uint256 pkpTokenId, string toolIpfsCid, address delegatee)',
'error PolicyAlreadySet(uint256 pkpTokenId, string toolIpfsCid, address delegatee)',
'error PolicySameEnabledState(uint256 pkpTokenId, string toolIpfsCid, address delegatee)',
'error EmptyPolicyIPFSCID()',
'error NotPKPOwner()',

// Events
'event ToolsRegistered(uint256 indexed pkpTokenId, bool enabled, string[] toolIpfsCids)',
'event ToolsRemoved(uint256 indexed pkpTokenId, string[] toolIpfsCids)',
'event ToolsEnabled(uint256 indexed pkpTokenId, string[] toolIpfsCids)',
'event ToolsDisabled(uint256 indexed pkpTokenId, string[] toolIpfsCids)',
'event ToolsPermitted(uint256 indexed pkpTokenId, string[] toolIpfsCids, address[] delegatees)',
'event AddedDelegatees(uint256 indexed pkpTokenId, address[] delegatees)',
'event RemovedDelegatees(uint256 indexed pkpTokenId, address[] delegatees)',
'event ToolPoliciesSet(uint256 indexed pkpTokenId, string[] toolIpfsCids, address[] delegatees, string[] policyIpfsCids)',
'event ToolPoliciesRemoved(uint256 indexed pkpTokenId, string[] toolIpfsCids, address[] delegatees)',
'event PoliciesEnabled(uint256 indexed pkpTokenId, string[] toolIpfsCids, address[] delegatees)',
'event PoliciesDisabled(uint256 indexed pkpTokenId, string[] toolIpfsCids, address[] delegatees)',
'event PolicyParametersSet(uint256 indexed pkpTokenId, string toolIpfsCids, address delegatee, string[] parameterNames, bytes[] parameterValues)',
'event PolicyParametersRemoved(uint256 indexed pkpTokenId, string toolIpfsCids, address delegatee, string[] parameterNames)',
'event ToolsUnpermitted(uint256 indexed pkpTokenId, string[] toolIpfsCids, address[] delegatees)',
];
51 changes: 51 additions & 0 deletions packages/aw-contracts-sdk/src/lib/pkp-tool-registry-contract.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { LIT_RPC } from '@lit-protocol/constants';
import { ethers } from 'ethers';

import { PKP_TOOL_REGISTRY_ABI } from './human-readable-abi';

/**
* Configuration for the Tool Policy Registry contract.
* Includes the RPC URL and contract address for interacting with the registry.
*/
export interface ToolRegistryConfig {
/** The RPC URL for the blockchain network. */
rpcUrl: string;

/** The address of the Tool Policy Registry contract. */
contractAddress: string;
}

export const DEFAULT_REGISTRY_CONFIG: Record<string, ToolRegistryConfig> = {
'datil-dev': {
rpcUrl: LIT_RPC.CHRONICLE_YELLOWSTONE,
contractAddress: '0x2707eabb60D262024F8738455811a338B0ECd3EC',
},
'datil-test': {
rpcUrl: LIT_RPC.CHRONICLE_YELLOWSTONE,
contractAddress: '0x525bF2bEb622D7C05E979a8b3fFcDBBEF944450E',
},
datil: {
rpcUrl: LIT_RPC.CHRONICLE_YELLOWSTONE,
contractAddress: '0xBDEd44A02b64416C831A0D82a630488A854ab4b1',
},
} as const;

/**
* Creates a new instance of the PKP Tool Registry contract.
* @param config - The configuration for the Tool Policy Registry contract, includes the RPC URL and contract address.
* @param signer - An optional ethers.Signer instance for write operations.
* @returns A new instance of the PKP Tool Registry contract.
*/
export const getPkpToolRegistryContract = (
{ rpcUrl, contractAddress }: ToolRegistryConfig,
signer?: ethers.Signer
) => {
const contract = new ethers.Contract(
contractAddress,
PKP_TOOL_REGISTRY_ABI,
new ethers.providers.JsonRpcProvider(rpcUrl)
);

// Connect the signer to allow write operations
return signer ? contract.connect(signer) : contract;
};
13 changes: 13 additions & 0 deletions packages/aw-contracts-sdk/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "../../tsconfig.base.json",
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
]
}
16 changes: 16 additions & 0 deletions packages/aw-contracts-sdk/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"baseUrl": ".",
"rootDir": "src",
"outDir": "dist",
"tsBuildInfoFile": "dist/tsconfig.lib.tsbuildinfo",
"emitDeclarationOnly": false,
"module": "nodenext",
"moduleResolution": "nodenext",
"types": ["node"]
},
"include": ["src/**/*.ts"],
"references": [],
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"]
}
18 changes: 18 additions & 0 deletions packages/aw-contracts-sdk/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "./out-tsc/jest",
"types": ["jest", "node"]
},
"include": [
"jest.config.ts",
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.d.ts"
],
"references": [
{
"path": "./tsconfig.lib.json"
}
]
}
12 changes: 12 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
},
{
"path": "./packages/aw-tool-registry"
},
{
"path": "./packages/aw-contracts-sdk"
}
]
}