@fidesbuild/sub 0.0.0-stage → 0.2.1

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/dist/abis.js ADDED
@@ -0,0 +1,3 @@
1
+ // Generated by scripts/export-sub-abis.js — do not edit.
2
+ export const fidesAccountV2Abi = [{ "type": "receive", "stateMutability": "payable" }, { "type": "function", "name": "LONG_FLAG", "inputs": [], "outputs": [{ "name": "", "type": "uint192", "internalType": "uint192" }], "stateMutability": "view" }, { "type": "function", "name": "actionsInPeriod", "inputs": [{ "name": "fidesId", "type": "bytes32", "internalType": "bytes32" }, { "name": "period", "type": "uint256", "internalType": "uint256" }], "outputs": [{ "name": "", "type": "uint256", "internalType": "uint256" }], "stateMutability": "view" }, { "type": "function", "name": "actionsUsed", "inputs": [{ "name": "fidesId", "type": "bytes32", "internalType": "bytes32" }], "outputs": [{ "name": "", "type": "uint256", "internalType": "uint256" }], "stateMutability": "view" }, { "type": "function", "name": "execute", "inputs": [{ "name": "fides", "type": "tuple", "internalType": "struct Fides", "components": [{ "name": "version", "type": "uint16", "internalType": "uint16" }, { "name": "chainId", "type": "uint256", "internalType": "uint256" }, { "name": "account", "type": "address", "internalType": "address" }, { "name": "owner", "type": "address", "internalType": "address" }, { "name": "agent", "type": "address", "internalType": "address" }, { "name": "validAfter", "type": "uint64", "internalType": "uint64" }, { "name": "validUntil", "type": "uint64", "internalType": "uint64" }, { "name": "targets", "type": "tuple[]", "internalType": "struct TargetRule[]", "components": [{ "name": "target", "type": "address", "internalType": "address" }, { "name": "selectors", "type": "bytes4[]", "internalType": "bytes4[]" }] }, { "name": "assets", "type": "tuple[]", "internalType": "struct AssetRule[]", "components": [{ "name": "asset", "type": "address", "internalType": "address" }, { "name": "maxOutflow", "type": "uint256", "internalType": "uint256" }] }, { "name": "services", "type": "tuple[]", "internalType": "struct ServiceRule[]", "components": [{ "name": "serviceId", "type": "string", "internalType": "string" }, { "name": "maxSpend", "type": "uint256", "internalType": "uint256" }, { "name": "allowedActions", "type": "string[]", "internalType": "string[]" }] }, { "name": "maxNativeValue", "type": "uint256", "internalType": "uint256" }, { "name": "spendLimits", "type": "tuple[]", "internalType": "struct SpendLimit[]", "components": [{ "name": "asset", "type": "address", "internalType": "address" }, { "name": "amount", "type": "uint256", "internalType": "uint256" }] }, { "name": "maxActions", "type": "uint256", "internalType": "uint256" }, { "name": "nonceSpace", "type": "uint192", "internalType": "uint192" }, { "name": "salt", "type": "bytes32", "internalType": "bytes32" }] }, { "name": "ownerSignature", "type": "bytes", "internalType": "bytes" }, { "name": "bundle", "type": "tuple", "internalType": "struct Bundle", "components": [{ "name": "fidesId", "type": "bytes32", "internalType": "bytes32" }, { "name": "nonce", "type": "uint256", "internalType": "uint256" }, { "name": "mode", "type": "uint8", "internalType": "enum ExecutionMode" }, { "name": "calls", "type": "tuple[]", "internalType": "struct Call[]", "components": [{ "name": "target", "type": "address", "internalType": "address" }, { "name": "value", "type": "uint256", "internalType": "uint256" }, { "name": "data", "type": "bytes", "internalType": "bytes" }] }] }, { "name": "agentSignature", "type": "bytes", "internalType": "bytes" }], "outputs": [{ "name": "results", "type": "bytes[]", "internalType": "bytes[]" }], "stateMutability": "nonpayable" }, { "type": "function", "name": "executeLong", "inputs": [{ "name": "fides", "type": "tuple", "internalType": "struct Fides", "components": [{ "name": "version", "type": "uint16", "internalType": "uint16" }, { "name": "chainId", "type": "uint256", "internalType": "uint256" }, { "name": "account", "type": "address", "internalType": "address" }, { "name": "owner", "type": "address", "internalType": "address" }, { "name": "agent", "type": "address", "internalType": "address" }, { "name": "validAfter", "type": "uint64", "internalType": "uint64" }, { "name": "validUntil", "type": "uint64", "internalType": "uint64" }, { "name": "targets", "type": "tuple[]", "internalType": "struct TargetRule[]", "components": [{ "name": "target", "type": "address", "internalType": "address" }, { "name": "selectors", "type": "bytes4[]", "internalType": "bytes4[]" }] }, { "name": "assets", "type": "tuple[]", "internalType": "struct AssetRule[]", "components": [{ "name": "asset", "type": "address", "internalType": "address" }, { "name": "maxOutflow", "type": "uint256", "internalType": "uint256" }] }, { "name": "services", "type": "tuple[]", "internalType": "struct ServiceRule[]", "components": [{ "name": "serviceId", "type": "string", "internalType": "string" }, { "name": "maxSpend", "type": "uint256", "internalType": "uint256" }, { "name": "allowedActions", "type": "string[]", "internalType": "string[]" }] }, { "name": "maxNativeValue", "type": "uint256", "internalType": "uint256" }, { "name": "spendLimits", "type": "tuple[]", "internalType": "struct SpendLimit[]", "components": [{ "name": "asset", "type": "address", "internalType": "address" }, { "name": "amount", "type": "uint256", "internalType": "uint256" }] }, { "name": "maxActions", "type": "uint256", "internalType": "uint256" }, { "name": "nonceSpace", "type": "uint192", "internalType": "uint192" }, { "name": "salt", "type": "bytes32", "internalType": "bytes32" }] }, { "name": "ownerSignature", "type": "bytes", "internalType": "bytes" }, { "name": "terms", "type": "tuple", "internalType": "struct LongTerms", "components": [{ "name": "period", "type": "uint64", "internalType": "uint64" }, { "name": "perPeriod", "type": "tuple[]", "internalType": "struct SpendLimit[]", "components": [{ "name": "asset", "type": "address", "internalType": "address" }, { "name": "amount", "type": "uint256", "internalType": "uint256" }] }, { "name": "maxActionsPerPeriod", "type": "uint256", "internalType": "uint256" }] }, { "name": "bundle", "type": "tuple", "internalType": "struct Bundle", "components": [{ "name": "fidesId", "type": "bytes32", "internalType": "bytes32" }, { "name": "nonce", "type": "uint256", "internalType": "uint256" }, { "name": "mode", "type": "uint8", "internalType": "enum ExecutionMode" }, { "name": "calls", "type": "tuple[]", "internalType": "struct Call[]", "components": [{ "name": "target", "type": "address", "internalType": "address" }, { "name": "value", "type": "uint256", "internalType": "uint256" }, { "name": "data", "type": "bytes", "internalType": "bytes" }] }] }, { "name": "agentSignature", "type": "bytes", "internalType": "bytes" }], "outputs": [{ "name": "results", "type": "bytes[]", "internalType": "bytes[]" }], "stateMutability": "nonpayable" }, { "type": "function", "name": "executeSub", "inputs": [{ "name": "fides", "type": "tuple", "internalType": "struct Fides", "components": [{ "name": "version", "type": "uint16", "internalType": "uint16" }, { "name": "chainId", "type": "uint256", "internalType": "uint256" }, { "name": "account", "type": "address", "internalType": "address" }, { "name": "owner", "type": "address", "internalType": "address" }, { "name": "agent", "type": "address", "internalType": "address" }, { "name": "validAfter", "type": "uint64", "internalType": "uint64" }, { "name": "validUntil", "type": "uint64", "internalType": "uint64" }, { "name": "targets", "type": "tuple[]", "internalType": "struct TargetRule[]", "components": [{ "name": "target", "type": "address", "internalType": "address" }, { "name": "selectors", "type": "bytes4[]", "internalType": "bytes4[]" }] }, { "name": "assets", "type": "tuple[]", "internalType": "struct AssetRule[]", "components": [{ "name": "asset", "type": "address", "internalType": "address" }, { "name": "maxOutflow", "type": "uint256", "internalType": "uint256" }] }, { "name": "services", "type": "tuple[]", "internalType": "struct ServiceRule[]", "components": [{ "name": "serviceId", "type": "string", "internalType": "string" }, { "name": "maxSpend", "type": "uint256", "internalType": "uint256" }, { "name": "allowedActions", "type": "string[]", "internalType": "string[]" }] }, { "name": "maxNativeValue", "type": "uint256", "internalType": "uint256" }, { "name": "spendLimits", "type": "tuple[]", "internalType": "struct SpendLimit[]", "components": [{ "name": "asset", "type": "address", "internalType": "address" }, { "name": "amount", "type": "uint256", "internalType": "uint256" }] }, { "name": "maxActions", "type": "uint256", "internalType": "uint256" }, { "name": "nonceSpace", "type": "uint192", "internalType": "uint192" }, { "name": "salt", "type": "bytes32", "internalType": "bytes32" }] }, { "name": "ownerSignature", "type": "bytes", "internalType": "bytes" }, { "name": "sub", "type": "tuple", "internalType": "struct SubFides", "components": [{ "name": "parentFidesId", "type": "bytes32", "internalType": "bytes32" }, { "name": "agent", "type": "address", "internalType": "address" }, { "name": "validAfter", "type": "uint64", "internalType": "uint64" }, { "name": "validUntil", "type": "uint64", "internalType": "uint64" }, { "name": "targets", "type": "tuple[]", "internalType": "struct TargetRule[]", "components": [{ "name": "target", "type": "address", "internalType": "address" }, { "name": "selectors", "type": "bytes4[]", "internalType": "bytes4[]" }] }, { "name": "spendLimits", "type": "tuple[]", "internalType": "struct SpendLimit[]", "components": [{ "name": "asset", "type": "address", "internalType": "address" }, { "name": "amount", "type": "uint256", "internalType": "uint256" }] }, { "name": "maxNativeValue", "type": "uint256", "internalType": "uint256" }, { "name": "maxActions", "type": "uint256", "internalType": "uint256" }, { "name": "salt", "type": "bytes32", "internalType": "bytes32" }] }, { "name": "parentAgentSignature", "type": "bytes", "internalType": "bytes" }, { "name": "bundle", "type": "tuple", "internalType": "struct Bundle", "components": [{ "name": "fidesId", "type": "bytes32", "internalType": "bytes32" }, { "name": "nonce", "type": "uint256", "internalType": "uint256" }, { "name": "mode", "type": "uint8", "internalType": "enum ExecutionMode" }, { "name": "calls", "type": "tuple[]", "internalType": "struct Call[]", "components": [{ "name": "target", "type": "address", "internalType": "address" }, { "name": "value", "type": "uint256", "internalType": "uint256" }, { "name": "data", "type": "bytes", "internalType": "bytes" }] }] }, { "name": "childSignature", "type": "bytes", "internalType": "bytes" }], "outputs": [{ "name": "results", "type": "bytes[]", "internalType": "bytes[]" }], "stateMutability": "nonpayable" }, { "type": "function", "name": "initialize", "inputs": [{ "name": "owner_", "type": "address", "internalType": "address" }], "outputs": [], "stateMutability": "nonpayable" }, { "type": "function", "name": "isNonceUsed", "inputs": [{ "name": "fidesId", "type": "bytes32", "internalType": "bytes32" }, { "name": "nonce", "type": "uint256", "internalType": "uint256" }], "outputs": [{ "name": "", "type": "bool", "internalType": "bool" }], "stateMutability": "view" }, { "type": "function", "name": "nativeUsed", "inputs": [{ "name": "fidesId", "type": "bytes32", "internalType": "bytes32" }], "outputs": [{ "name": "", "type": "uint256", "internalType": "uint256" }], "stateMutability": "view" }, { "type": "function", "name": "owner", "inputs": [], "outputs": [{ "name": "", "type": "address", "internalType": "address" }], "stateMutability": "view" }, { "type": "function", "name": "ownerExecute", "inputs": [{ "name": "target", "type": "address", "internalType": "address" }, { "name": "value", "type": "uint256", "internalType": "uint256" }, { "name": "data", "type": "bytes", "internalType": "bytes" }], "outputs": [{ "name": "ret", "type": "bytes", "internalType": "bytes" }], "stateMutability": "nonpayable" }, { "type": "function", "name": "policy", "inputs": [], "outputs": [{ "name": "", "type": "address", "internalType": "contract FidesPolicy" }], "stateMutability": "view" }, { "type": "function", "name": "revocation", "inputs": [], "outputs": [{ "name": "", "type": "address", "internalType": "contract FidesRevocation" }], "stateMutability": "view" }, { "type": "function", "name": "spent", "inputs": [{ "name": "fidesId", "type": "bytes32", "internalType": "bytes32" }, { "name": "asset", "type": "address", "internalType": "address" }], "outputs": [{ "name": "", "type": "uint256", "internalType": "uint256" }], "stateMutability": "view" }, { "type": "function", "name": "spentInPeriod", "inputs": [{ "name": "fidesId", "type": "bytes32", "internalType": "bytes32" }, { "name": "period", "type": "uint256", "internalType": "uint256" }, { "name": "asset", "type": "address", "internalType": "address" }], "outputs": [{ "name": "", "type": "uint256", "internalType": "uint256" }], "stateMutability": "view" }, { "type": "function", "name": "staged", "inputs": [], "outputs": [{ "name": "", "type": "address", "internalType": "contract FidesStagedVerifier" }], "stateMutability": "view" }, { "type": "function", "name": "verifier", "inputs": [], "outputs": [{ "name": "", "type": "address", "internalType": "contract FidesVerifier" }], "stateMutability": "view" }, { "type": "event", "name": "BundleExecuted", "inputs": [{ "name": "fidesId", "type": "bytes32", "indexed": true, "internalType": "bytes32" }, { "name": "bundleHash", "type": "bytes32", "indexed": true, "internalType": "bytes32" }, { "name": "mode", "type": "uint8", "indexed": false, "internalType": "enum ExecutionMode" }, { "name": "succeeded", "type": "uint256", "indexed": false, "internalType": "uint256" }, { "name": "failed", "type": "uint256", "indexed": false, "internalType": "uint256" }], "anonymous": false }, { "type": "event", "name": "CallResult", "inputs": [{ "name": "bundleHash", "type": "bytes32", "indexed": true, "internalType": "bytes32" }, { "name": "index", "type": "uint256", "indexed": false, "internalType": "uint256" }, { "name": "success", "type": "bool", "indexed": false, "internalType": "bool" }], "anonymous": false }, { "type": "event", "name": "FidesExecuted", "inputs": [{ "name": "fidesId", "type": "bytes32", "indexed": true, "internalType": "bytes32" }, { "name": "bundleHash", "type": "bytes32", "indexed": true, "internalType": "bytes32" }, { "name": "agent", "type": "address", "indexed": true, "internalType": "address" }, { "name": "actionCount", "type": "uint256", "indexed": false, "internalType": "uint256" }], "anonymous": false }, { "type": "event", "name": "LongFidesExecuted", "inputs": [{ "name": "fidesId", "type": "bytes32", "indexed": true, "internalType": "bytes32" }, { "name": "period", "type": "uint256", "indexed": true, "internalType": "uint256" }, { "name": "bundleHash", "type": "bytes32", "indexed": true, "internalType": "bytes32" }], "anonymous": false }, { "type": "event", "name": "SpendRecorded", "inputs": [{ "name": "fidesId", "type": "bytes32", "indexed": true, "internalType": "bytes32" }, { "name": "asset", "type": "address", "indexed": true, "internalType": "address" }, { "name": "amount", "type": "uint256", "indexed": false, "internalType": "uint256" }, { "name": "total", "type": "uint256", "indexed": false, "internalType": "uint256" }], "anonymous": false }, { "type": "event", "name": "SubFidesExecuted", "inputs": [{ "name": "parentFidesId", "type": "bytes32", "indexed": true, "internalType": "bytes32" }, { "name": "subFidesId", "type": "bytes32", "indexed": true, "internalType": "bytes32" }, { "name": "bundleHash", "type": "bytes32", "indexed": true, "internalType": "bytes32" }, { "name": "childAgent", "type": "address", "indexed": false, "internalType": "address" }], "anonymous": false }, { "type": "error", "name": "AlreadyInitialized", "inputs": [] }, { "type": "error", "name": "AssetOutflowExceeded", "inputs": [{ "name": "asset", "type": "address", "internalType": "address" }] }, { "type": "error", "name": "FidesExpired", "inputs": [] }, { "type": "error", "name": "FidesRevoked", "inputs": [] }, { "type": "error", "name": "InvalidAgentSignature", "inputs": [] }, { "type": "error", "name": "InvalidOwner", "inputs": [] }, { "type": "error", "name": "InvalidOwnerSignature", "inputs": [] }, { "type": "error", "name": "InvalidParentAgentSignature", "inputs": [] }, { "type": "error", "name": "InvalidPeriod", "inputs": [] }, { "type": "error", "name": "LongFidesRequiresExecuteLong", "inputs": [] }, { "type": "error", "name": "NonceAlreadyUsed", "inputs": [] }, { "type": "error", "name": "NonceOutsidePeriod", "inputs": [] }, { "type": "error", "name": "NotALongFides", "inputs": [] }, { "type": "error", "name": "NotOwner", "inputs": [] }, { "type": "error", "name": "OwnerCallFailed", "inputs": [] }, { "type": "error", "name": "OwnerMismatch", "inputs": [] }, { "type": "error", "name": "ParentActionLimitExceeded", "inputs": [] }, { "type": "error", "name": "ParentNativeValueExceeded", "inputs": [] }, { "type": "error", "name": "PeriodActionLimitExceeded", "inputs": [] }, { "type": "error", "name": "PeriodSpendExceeded", "inputs": [{ "name": "asset", "type": "address", "internalType": "address" }] }, { "type": "error", "name": "Reentrancy", "inputs": [] }, { "type": "error", "name": "SpendLimitExceeded", "inputs": [{ "name": "asset", "type": "address", "internalType": "address" }] }, { "type": "error", "name": "SubFidesRevoked", "inputs": [] }, { "type": "error", "name": "TermsMismatch", "inputs": [] }, { "type": "error", "name": "WrongAccount", "inputs": [] }, { "type": "error", "name": "WrongFides", "inputs": [] }, { "type": "error", "name": "WrongParent", "inputs": [] }];
3
+ export const fidesSubVerifierAbi = [{ "type": "function", "name": "checkSubset", "inputs": [{ "name": "parent", "type": "tuple", "internalType": "struct Fides", "components": [{ "name": "version", "type": "uint16", "internalType": "uint16" }, { "name": "chainId", "type": "uint256", "internalType": "uint256" }, { "name": "account", "type": "address", "internalType": "address" }, { "name": "owner", "type": "address", "internalType": "address" }, { "name": "agent", "type": "address", "internalType": "address" }, { "name": "validAfter", "type": "uint64", "internalType": "uint64" }, { "name": "validUntil", "type": "uint64", "internalType": "uint64" }, { "name": "targets", "type": "tuple[]", "internalType": "struct TargetRule[]", "components": [{ "name": "target", "type": "address", "internalType": "address" }, { "name": "selectors", "type": "bytes4[]", "internalType": "bytes4[]" }] }, { "name": "assets", "type": "tuple[]", "internalType": "struct AssetRule[]", "components": [{ "name": "asset", "type": "address", "internalType": "address" }, { "name": "maxOutflow", "type": "uint256", "internalType": "uint256" }] }, { "name": "services", "type": "tuple[]", "internalType": "struct ServiceRule[]", "components": [{ "name": "serviceId", "type": "string", "internalType": "string" }, { "name": "maxSpend", "type": "uint256", "internalType": "uint256" }, { "name": "allowedActions", "type": "string[]", "internalType": "string[]" }] }, { "name": "maxNativeValue", "type": "uint256", "internalType": "uint256" }, { "name": "spendLimits", "type": "tuple[]", "internalType": "struct SpendLimit[]", "components": [{ "name": "asset", "type": "address", "internalType": "address" }, { "name": "amount", "type": "uint256", "internalType": "uint256" }] }, { "name": "maxActions", "type": "uint256", "internalType": "uint256" }, { "name": "nonceSpace", "type": "uint192", "internalType": "uint192" }, { "name": "salt", "type": "bytes32", "internalType": "bytes32" }] }, { "name": "child", "type": "tuple", "internalType": "struct SubFides", "components": [{ "name": "parentFidesId", "type": "bytes32", "internalType": "bytes32" }, { "name": "agent", "type": "address", "internalType": "address" }, { "name": "validAfter", "type": "uint64", "internalType": "uint64" }, { "name": "validUntil", "type": "uint64", "internalType": "uint64" }, { "name": "targets", "type": "tuple[]", "internalType": "struct TargetRule[]", "components": [{ "name": "target", "type": "address", "internalType": "address" }, { "name": "selectors", "type": "bytes4[]", "internalType": "bytes4[]" }] }, { "name": "spendLimits", "type": "tuple[]", "internalType": "struct SpendLimit[]", "components": [{ "name": "asset", "type": "address", "internalType": "address" }, { "name": "amount", "type": "uint256", "internalType": "uint256" }] }, { "name": "maxNativeValue", "type": "uint256", "internalType": "uint256" }, { "name": "maxActions", "type": "uint256", "internalType": "uint256" }, { "name": "salt", "type": "bytes32", "internalType": "bytes32" }] }], "outputs": [], "stateMutability": "pure" }, { "type": "function", "name": "domainSeparator", "inputs": [], "outputs": [{ "name": "", "type": "bytes32", "internalType": "bytes32" }], "stateMutability": "view" }, { "type": "function", "name": "hashLongTerms", "inputs": [{ "name": "t", "type": "tuple", "internalType": "struct LongTerms", "components": [{ "name": "period", "type": "uint64", "internalType": "uint64" }, { "name": "perPeriod", "type": "tuple[]", "internalType": "struct SpendLimit[]", "components": [{ "name": "asset", "type": "address", "internalType": "address" }, { "name": "amount", "type": "uint256", "internalType": "uint256" }] }, { "name": "maxActionsPerPeriod", "type": "uint256", "internalType": "uint256" }] }], "outputs": [{ "name": "", "type": "bytes32", "internalType": "bytes32" }], "stateMutability": "pure" }, { "type": "function", "name": "hashSubFides", "inputs": [{ "name": "s", "type": "tuple", "internalType": "struct SubFides", "components": [{ "name": "parentFidesId", "type": "bytes32", "internalType": "bytes32" }, { "name": "agent", "type": "address", "internalType": "address" }, { "name": "validAfter", "type": "uint64", "internalType": "uint64" }, { "name": "validUntil", "type": "uint64", "internalType": "uint64" }, { "name": "targets", "type": "tuple[]", "internalType": "struct TargetRule[]", "components": [{ "name": "target", "type": "address", "internalType": "address" }, { "name": "selectors", "type": "bytes4[]", "internalType": "bytes4[]" }] }, { "name": "spendLimits", "type": "tuple[]", "internalType": "struct SpendLimit[]", "components": [{ "name": "asset", "type": "address", "internalType": "address" }, { "name": "amount", "type": "uint256", "internalType": "uint256" }] }, { "name": "maxNativeValue", "type": "uint256", "internalType": "uint256" }, { "name": "maxActions", "type": "uint256", "internalType": "uint256" }, { "name": "salt", "type": "bytes32", "internalType": "bytes32" }] }], "outputs": [{ "name": "", "type": "bytes32", "internalType": "bytes32" }], "stateMutability": "view" }, { "type": "error", "name": "ChildActionsExceedParent", "inputs": [] }, { "type": "error", "name": "ChildLimitExceedsParent", "inputs": [{ "name": "asset", "type": "address", "internalType": "address" }] }, { "type": "error", "name": "ChildNativeValueExceedsParent", "inputs": [] }, { "type": "error", "name": "ChildOutlivesParent", "inputs": [] }, { "type": "error", "name": "ChildSelectorNotInParent", "inputs": [{ "name": "target", "type": "address", "internalType": "address" }, { "name": "selector", "type": "bytes4", "internalType": "bytes4" }] }, { "type": "error", "name": "ChildTargetNotInParent", "inputs": [{ "name": "target", "type": "address", "internalType": "address" }] }];
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/guide.js ADDED
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env node
2
+ // npx @fidesbuild/sub — what SUB-FIDES is, and the fastest way to try it.
3
+ const say = (s = '') => console.log(s);
4
+ say(`
5
+ SUB-FIDES: agents hiring agents, inside limits none of them can break.
6
+
7
+ An agent working under a FIDES hands another agent a slice of it: its own budget, contracts and expiry.
8
+ The child can never go past its slice, everything it spends also counts against the parent, and the
9
+ owner or the parent agent can revoke it at any time.
10
+
11
+ Try it, guided, in one folder:
12
+
13
+ npm install @fidesbuild/sdk viem
14
+ npx @fidesbuild/sdk init
15
+ npm start the tour: sign, fund, then every example, including
16
+ npm run delegate this agent hands a second agent a slice, and it spends inside it
17
+
18
+ In your own code:
19
+
20
+ import { createSubClient, SubFidesKit, SubAgent } from "@fidesbuild/sub"
21
+
22
+ const client = createSubClient({ chainId: 4663, rpc }) // V2 accounts, which can delegate
23
+ const sub = await SubFidesKit.sign(
24
+ SubFidesKit.create(parentFides, { agent: childAddress, spend: [{ asset: USDG, amount }], expiry }),
25
+ parentAgent, client, parentFides)
26
+ await SubFidesKit.register("https://api.fidesbuilder.xyz", parentFides, sub) // the child finds it by address
27
+
28
+ const child = new SubAgent({ client, parent: parentFides, sub, agent: childKey, api: "https://api.fidesbuilder.xyz" })
29
+ await child.execute(await child.plan(actions)) // no gas: the relayer pays
30
+
31
+ Also in the app (tick "Allow this agent to hand out SUB-FIDES") and in Claude ("give 0x… 0.1 USDG for 30 minutes").
32
+ Docs: https://fidesbuilder.xyz/docs/#/sub
33
+ `);
34
+ export {};
@@ -0,0 +1,214 @@
1
+ import { type Address, type Hex, type LocalAccount } from 'viem';
2
+ import { type ActionInput, type Bundle, type Fides, type Plan, type SignedFides, type SpendLimit, type TargetRule } from '@fidesbuild/core';
3
+ import { type FidesClient, type FidesAddresses } from '@fidesbuild/sdk';
4
+ import { fidesAccountV2Abi, fidesSubVerifierAbi } from './abis.ts';
5
+ export { fidesAccountV2Abi, fidesSubVerifierAbi };
6
+ export type SubFides = {
7
+ parentFidesId: Hex;
8
+ agent: Address;
9
+ validAfter: bigint;
10
+ validUntil: bigint;
11
+ targets: TargetRule[];
12
+ spendLimits: SpendLimit[];
13
+ maxNativeValue: bigint;
14
+ maxActions: bigint;
15
+ salt: Hex;
16
+ };
17
+ /** A SUB-FIDES signed by the parent agent. `verifier` is the SUB-FIDES verifier it was signed against. */
18
+ export type SignedSubFides = SubFides & {
19
+ id: Hex;
20
+ signature: Hex;
21
+ verifier: Address;
22
+ };
23
+ export type SubAddresses = {
24
+ subVerifier: Address;
25
+ accountImplementation: Address;
26
+ factory: Address;
27
+ };
28
+ /** The SUB-FIDES contracts by chain ID. */
29
+ export declare const subDeployments: Record<number, SubAddresses>;
30
+ export declare class SubFidesError extends Error {
31
+ code: string;
32
+ constructor(code: string, message: string);
33
+ }
34
+ export declare const SUB_FIDES_TYPES: {
35
+ readonly SubFides: readonly [{
36
+ readonly name: 'parentFidesId';
37
+ readonly type: 'bytes32';
38
+ }, {
39
+ readonly name: 'agent';
40
+ readonly type: 'address';
41
+ }, {
42
+ readonly name: 'validAfter';
43
+ readonly type: 'uint64';
44
+ }, {
45
+ readonly name: 'validUntil';
46
+ readonly type: 'uint64';
47
+ }, {
48
+ readonly name: 'targets';
49
+ readonly type: 'TargetRule[]';
50
+ }, {
51
+ readonly name: 'spendLimits';
52
+ readonly type: 'SpendLimit[]';
53
+ }, {
54
+ readonly name: 'maxNativeValue';
55
+ readonly type: 'uint256';
56
+ }, {
57
+ readonly name: 'maxActions';
58
+ readonly type: 'uint256';
59
+ }, {
60
+ readonly name: 'salt';
61
+ readonly type: 'bytes32';
62
+ }];
63
+ readonly TargetRule: readonly [{
64
+ readonly name: 'target';
65
+ readonly type: 'address';
66
+ }, {
67
+ readonly name: 'selectors';
68
+ readonly type: 'bytes4[]';
69
+ }];
70
+ readonly SpendLimit: readonly [{
71
+ readonly name: 'asset';
72
+ readonly type: 'address';
73
+ }, {
74
+ readonly name: 'amount';
75
+ readonly type: 'uint256';
76
+ }];
77
+ };
78
+ export declare const subMessage: (s: SubFides) => SubFides;
79
+ export declare const subFidesTypedData: (s: SubFides, chainId: bigint | number, subVerifier: Address) => {
80
+ readonly domain: {
81
+ readonly name: 'FIDES';
82
+ readonly version: '1';
83
+ readonly chainId: number;
84
+ readonly verifyingContract: `0x${string}`;
85
+ };
86
+ readonly types: {
87
+ readonly SubFides: readonly [{
88
+ readonly name: 'parentFidesId';
89
+ readonly type: 'bytes32';
90
+ }, {
91
+ readonly name: 'agent';
92
+ readonly type: 'address';
93
+ }, {
94
+ readonly name: 'validAfter';
95
+ readonly type: 'uint64';
96
+ }, {
97
+ readonly name: 'validUntil';
98
+ readonly type: 'uint64';
99
+ }, {
100
+ readonly name: 'targets';
101
+ readonly type: 'TargetRule[]';
102
+ }, {
103
+ readonly name: 'spendLimits';
104
+ readonly type: 'SpendLimit[]';
105
+ }, {
106
+ readonly name: 'maxNativeValue';
107
+ readonly type: 'uint256';
108
+ }, {
109
+ readonly name: 'maxActions';
110
+ readonly type: 'uint256';
111
+ }, {
112
+ readonly name: 'salt';
113
+ readonly type: 'bytes32';
114
+ }];
115
+ readonly TargetRule: readonly [{
116
+ readonly name: 'target';
117
+ readonly type: 'address';
118
+ }, {
119
+ readonly name: 'selectors';
120
+ readonly type: 'bytes4[]';
121
+ }];
122
+ readonly SpendLimit: readonly [{
123
+ readonly name: 'asset';
124
+ readonly type: 'address';
125
+ }, {
126
+ readonly name: 'amount';
127
+ readonly type: 'uint256';
128
+ }];
129
+ };
130
+ readonly primaryType: 'SubFides';
131
+ readonly message: SubFides;
132
+ };
133
+ /** The SUB-FIDES ID: the digest the parent agent signs, as FidesStagedVerifier.hashSubFides computes it. */
134
+ export declare const hashSubFides: (s: SubFides, chainId: bigint | number, subVerifier: Address) => Hex;
135
+ /** A client whose factory makes V2 FIDES Accounts, the kind that can delegate with SUB-FIDES. */
136
+ export declare function createSubClient(opts: {
137
+ chainId: number;
138
+ rpc: string | string[];
139
+ addresses?: Partial<SubAddresses>;
140
+ base?: FidesAddresses;
141
+ }): FidesClient & {
142
+ sub: SubAddresses;
143
+ };
144
+ /** Throws unless everything the child may do, the parent may do. The same rules the contract enforces. */
145
+ export declare function checkSubset(parent: Fides, child: SubFides): void;
146
+ export type SubParams = {
147
+ /** The child agent's address. */
148
+ agent: Address;
149
+ /** What the child may spend, per token. Must fit inside the parent's limits. */
150
+ spend: SpendLimit[];
151
+ /** The contracts and functions the child may call. Defaults to the parent's. */
152
+ targets?: TargetRule[];
153
+ /** Unix seconds. Defaults to the parent's expiry, and can never be later. */
154
+ expiry?: number | bigint;
155
+ validAfter?: number | bigint;
156
+ /** Defaults to the smaller of 20 and the parent's action limit. */
157
+ maxActions?: bigint;
158
+ maxNativeValue?: bigint;
159
+ salt?: Hex;
160
+ };
161
+ export declare const SubFidesKit: {
162
+ /** A SUB-FIDES under `parent`, checked to fit inside it. Sign it with the parent's agent key. */
163
+ create(parent: SignedFides, p: SubParams): SubFides;
164
+ /** The parent agent signs, handing the child its slice of the parent's authority. */
165
+ sign(sub: SubFides, parentAgent: LocalAccount, client: FidesClient & {
166
+ sub: SubAddresses;
167
+ }, parent: SignedFides): Promise<SignedSubFides>;
168
+ /** Whether the owner or the parent agent has revoked this SUB-FIDES, or the owner has revoked the parent. */
169
+ isRevoked(client: FidesClient, parent: SignedFides, sub: SignedSubFides): Promise<boolean>;
170
+ /** Shares a signed SUB-FIDES with a FIDES API, which checks it, so the child agent can find it without a file. */
171
+ register(api: string, parent: SignedFides, sub: SignedSubFides): Promise<{
172
+ id: Hex;
173
+ parentFidesId: Hex;
174
+ agent: Address;
175
+ }>;
176
+ /** Ends a child's authority. The owner or the parent agent can do it; the signer pays the gas. */
177
+ revoke(client: FidesClient, sub: SignedSubFides, signer: LocalAccount): Promise<`0x${string}`>;
178
+ };
179
+ export type SubPlan = {
180
+ plan: Plan;
181
+ bundle: Bundle | null;
182
+ bundleHash: Hex | null;
183
+ };
184
+ export type SubResult = {
185
+ status: 'EXECUTED' | 'REVERTED' | 'NOTHING_TO_SEND';
186
+ txHash?: Hex;
187
+ error?: string;
188
+ };
189
+ /** A child agent acting under a SUB-FIDES. Bundles go through a FIDES API's relayer (`api`), or a `relayer` key
190
+ * you hold; either pays the gas and has no authority. */
191
+ export declare class SubAgent {
192
+ #private;
193
+ constructor(opts: {
194
+ client: FidesClient;
195
+ parent: SignedFides;
196
+ sub: SignedSubFides;
197
+ agent: LocalAccount;
198
+ relayer?: LocalAccount;
199
+ api?: string;
200
+ });
201
+ /** Checks every action against the SUB-FIDES, and signs one bundle of the authorized onchain writes. Sends nothing. */
202
+ plan(actions: ActionInput[]): Promise<SubPlan>;
203
+ /** Runs the bundle against the chain without sending it. Returns the contract's reason if it would fail. */
204
+ simulate(p: SubPlan): Promise<{
205
+ success: boolean;
206
+ reason?: string;
207
+ }>;
208
+ /** Sends the bundle through the parent's FIDES Account. */
209
+ execute(p: SubPlan): Promise<SubResult>;
210
+ }
211
+ /** Verifies with the deployed SUB-FIDES verifier that the ID computed here is the one the contract computes. */
212
+ export declare const subIdOnchain: (client: FidesClient & {
213
+ sub: SubAddresses;
214
+ }, s: SubFides) => Promise<Hex>;
package/dist/index.js ADDED
@@ -0,0 +1,203 @@
1
+ // @fidesbuild/sub — Release 02, SUB-FIDES: scoped agent-to-agent delegation.
2
+ //
3
+ // An agent working under a FIDES hands part of its authority to another agent. The child gets its own
4
+ // budget, contracts, expiry, action limit and nonces, and can never exceed the parent: the contract
5
+ // checks the child is a subset of the parent on every execution, counts everything the child does
6
+ // against the parent too, and stops the child the moment the parent (or the child) is revoked.
7
+ //
8
+ // A SUB-FIDES needs a parent FIDES on a V2 FIDES Account, made by the SUB-FIDES factory. Use
9
+ // createSubClient() so Fides.create, deployAccount and the Builder all use that factory.
10
+ import { hashTypedData, BaseError, ContractFunctionRevertedError } from 'viem';
11
+ import { buildPlan, bundleTypedData, hashBundle, fidesMessage, isWrite, toJson, fromJson } from '@fidesbuild/core';
12
+ import { createFidesClient, deployments } from '@fidesbuild/sdk';
13
+ import { fidesRevocationAbi } from '@fidesbuild/contracts';
14
+ import { fidesAccountV2Abi, fidesSubVerifierAbi } from './abis.js';
15
+ export { fidesAccountV2Abi, fidesSubVerifierAbi };
16
+ /** The SUB-FIDES contracts by chain ID. */
17
+ export const subDeployments = {
18
+ // Robinhood Chain mainnet, deployed 2026-10-23, verified on Sourcify
19
+ 4663: { subVerifier: '0x7e774D60516E0078b705F675C226F9de5520Fe14', accountImplementation: '0x118546920812BaC2487f57a2E35F2eCf200dAE38', factory: '0xf72344916Ed31e21b8e7649646591d36D58532Dd' },
20
+ };
21
+ export class SubFidesError extends Error {
22
+ code;
23
+ constructor(code, message) { super(message); this.code = code; }
24
+ }
25
+ const SUB_FIELDS = ['parentFidesId', 'agent', 'validAfter', 'validUntil', 'targets', 'spendLimits', 'maxNativeValue', 'maxActions', 'salt'];
26
+ export const SUB_FIDES_TYPES = {
27
+ SubFides: [
28
+ { name: 'parentFidesId', type: 'bytes32' }, { name: 'agent', type: 'address' }, { name: 'validAfter', type: 'uint64' }, { name: 'validUntil', type: 'uint64' },
29
+ { name: 'targets', type: 'TargetRule[]' }, { name: 'spendLimits', type: 'SpendLimit[]' }, { name: 'maxNativeValue', type: 'uint256' }, { name: 'maxActions', type: 'uint256' }, { name: 'salt', type: 'bytes32' },
30
+ ],
31
+ TargetRule: [{ name: 'target', type: 'address' }, { name: 'selectors', type: 'bytes4[]' }],
32
+ SpendLimit: [{ name: 'asset', type: 'address' }, { name: 'amount', type: 'uint256' }],
33
+ };
34
+ export const subMessage = (s) => Object.fromEntries(SUB_FIELDS.map((k) => [k, s[k]]));
35
+ export const subFidesTypedData = (s, chainId, subVerifier) => ({ domain: { name: 'FIDES', version: '1', chainId: Number(chainId), verifyingContract: subVerifier }, types: SUB_FIDES_TYPES, primaryType: 'SubFides', message: subMessage(s) });
36
+ /** The SUB-FIDES ID: the digest the parent agent signs, as FidesStagedVerifier.hashSubFides computes it. */
37
+ export const hashSubFides = (s, chainId, subVerifier) => hashTypedData(subFidesTypedData(s, chainId, subVerifier));
38
+ /** A client whose factory makes V2 FIDES Accounts, the kind that can delegate with SUB-FIDES. */
39
+ export function createSubClient(opts) {
40
+ const sub = { ...subDeployments[opts.chainId], ...opts.addresses };
41
+ if (!sub.subVerifier || !sub.factory)
42
+ throw new SubFidesError('NOT_DEPLOYED', `SUB-FIDES is not deployed on chain ${opts.chainId}. Pass its addresses.`);
43
+ const base = opts.base ?? deployments[opts.chainId];
44
+ if (!base)
45
+ throw new SubFidesError('NOT_DEPLOYED', `FIDES is not deployed on chain ${opts.chainId}.`);
46
+ const client = createFidesClient({ chainId: opts.chainId, rpc: opts.rpc, addresses: { ...base, factory: sub.factory, accountImplementation: sub.accountImplementation } });
47
+ return Object.assign(client, { sub });
48
+ }
49
+ const same = (a, b) => a.toLowerCase() === b.toLowerCase();
50
+ /** Throws unless everything the child may do, the parent may do. The same rules the contract enforces. */
51
+ export function checkSubset(parent, child) {
52
+ if (child.validAfter < parent.validAfter || child.validUntil > parent.validUntil)
53
+ throw new SubFidesError('CHILD_OUTLIVES_PARENT', 'The SUB-FIDES must start no earlier and end no later than its parent.');
54
+ if (child.maxNativeValue > parent.maxNativeValue)
55
+ throw new SubFidesError('CHILD_NATIVE_VALUE_EXCEEDS_PARENT', 'The SUB-FIDES allows more ETH value than its parent.');
56
+ if (child.maxActions > parent.maxActions)
57
+ throw new SubFidesError('CHILD_ACTIONS_EXCEED_PARENT', 'The SUB-FIDES allows more actions than its parent.');
58
+ for (const t of child.targets) {
59
+ const rule = parent.targets.find((p) => same(p.target, t.target));
60
+ if (!rule)
61
+ throw new SubFidesError('CHILD_TARGET_NOT_IN_PARENT', `The parent does not allow the contract ${t.target}.`);
62
+ for (const s of t.selectors)
63
+ if (!rule.selectors.some((p) => same(p, s)))
64
+ throw new SubFidesError('CHILD_SELECTOR_NOT_IN_PARENT', `The parent does not allow function ${s} on ${t.target}.`);
65
+ }
66
+ for (const l of child.spendLimits) {
67
+ const p = parent.spendLimits.find((x) => same(x.asset, l.asset));
68
+ if (!p || l.amount > p.amount)
69
+ throw new SubFidesError('CHILD_LIMIT_EXCEEDS_PARENT', `The SUB-FIDES may spend more of ${l.asset} than its parent.`);
70
+ }
71
+ }
72
+ const randomHex32 = () => `0x${[...crypto.getRandomValues(new Uint8Array(32))].map((b) => b.toString(16).padStart(2, '0')).join('')}`;
73
+ export const SubFidesKit = {
74
+ /** A SUB-FIDES under `parent`, checked to fit inside it. Sign it with the parent's agent key. */
75
+ create(parent, p) {
76
+ const sub = {
77
+ parentFidesId: parent.id,
78
+ agent: p.agent,
79
+ validAfter: BigInt(p.validAfter ?? parent.validAfter),
80
+ validUntil: BigInt(p.expiry ?? parent.validUntil),
81
+ targets: p.targets ?? parent.targets,
82
+ spendLimits: p.spend,
83
+ maxNativeValue: p.maxNativeValue ?? 0n,
84
+ maxActions: p.maxActions ?? (parent.maxActions < 20n ? parent.maxActions : 20n),
85
+ salt: p.salt ?? randomHex32(),
86
+ };
87
+ checkSubset(parent, sub);
88
+ return sub;
89
+ },
90
+ /** The parent agent signs, handing the child its slice of the parent's authority. */
91
+ async sign(sub, parentAgent, client, parent) {
92
+ if (!same(parentAgent.address, parent.agent))
93
+ throw new SubFidesError('WRONG_PARENT_AGENT', 'Only the agent named in the parent FIDES can delegate from it.');
94
+ if (sub.parentFidesId !== parent.id)
95
+ throw new SubFidesError('WRONG_PARENT', 'This SUB-FIDES names a different parent.');
96
+ checkSubset(parent, sub);
97
+ const typed = subFidesTypedData(sub, client.chainId, client.sub.subVerifier);
98
+ const signature = await parentAgent.signTypedData(typed);
99
+ return { ...sub, id: hashSubFides(sub, client.chainId, client.sub.subVerifier), signature, verifier: client.sub.subVerifier };
100
+ },
101
+ /** Whether the owner or the parent agent has revoked this SUB-FIDES, or the owner has revoked the parent. */
102
+ async isRevoked(client, parent, sub) {
103
+ const r = (who, id) => client.public.readContract({ address: client.addresses.revocation, abi: fidesRevocationAbi, functionName: 'isRevoked', args: [who, id] });
104
+ const [p, so, sa] = await Promise.all([r(parent.owner, parent.id), r(parent.owner, sub.id), r(parent.agent, sub.id)]);
105
+ return p || so || sa;
106
+ },
107
+ /** Shares a signed SUB-FIDES with a FIDES API, which checks it, so the child agent can find it without a file. */
108
+ async register(api, parent, sub) {
109
+ const res = await fetch(api.replace(/\/$/, '') + '/v1/sub/verify', { method: 'POST', headers: { 'content-type': 'application/json' }, body: toJson({ parent, sub }) });
110
+ const json = fromJson(await res.text());
111
+ if (!res.ok || json?.error)
112
+ throw new SubFidesError(json?.error?.code ?? 'REGISTER_FAILED', json?.error?.message ?? `HTTP ${res.status}`);
113
+ return json;
114
+ },
115
+ /** Ends a child's authority. The owner or the parent agent can do it; the signer pays the gas. */
116
+ async revoke(client, sub, signer) {
117
+ const hash = await client.wallet(signer).writeContract({ address: client.addresses.revocation, abi: fidesRevocationAbi, functionName: 'revoke', args: [sub.id], chain: null, account: signer });
118
+ await client.public.waitForTransactionReceipt({ hash });
119
+ return hash;
120
+ },
121
+ };
122
+ /** The SUB-FIDES as the scope the Builder plans against: the parent with the child's narrower rules. */
123
+ function scopeOf(parent, sub) {
124
+ return { ...parent, agent: sub.agent, validAfter: sub.validAfter, validUntil: sub.validUntil, targets: sub.targets, spendLimits: sub.spendLimits, maxActions: sub.maxActions, maxNativeValue: sub.maxNativeValue, id: sub.id };
125
+ }
126
+ function revertName(err) {
127
+ if (err instanceof BaseError) {
128
+ const r = err.walk((e) => e instanceof ContractFunctionRevertedError);
129
+ if (r?.data?.errorName)
130
+ return r.data.errorName;
131
+ return err.shortMessage;
132
+ }
133
+ return String(err?.message ?? err);
134
+ }
135
+ /** A child agent acting under a SUB-FIDES. Bundles go through a FIDES API's relayer (`api`), or a `relayer` key
136
+ * you hold; either pays the gas and has no authority. */
137
+ export class SubAgent {
138
+ #client;
139
+ #parent;
140
+ #sub;
141
+ #agent;
142
+ #relayer;
143
+ #api;
144
+ constructor(opts) {
145
+ if (!opts.relayer && !opts.api)
146
+ throw new SubFidesError('NO_RELAYER', 'Pass api (a FIDES API with a relayer) or relayer (a key that pays the gas).');
147
+ if (!same(opts.agent.address, opts.sub.agent))
148
+ throw new SubFidesError('WRONG_AGENT', 'The agent key is not the one named in the SUB-FIDES.');
149
+ this.#client = opts.client;
150
+ this.#parent = opts.parent;
151
+ this.#sub = opts.sub;
152
+ this.#agent = opts.agent;
153
+ this.#relayer = opts.relayer;
154
+ this.#api = opts.api?.replace(/\/$/, '');
155
+ }
156
+ /** Checks every action against the SUB-FIDES, and signs one bundle of the authorized onchain writes. Sends nothing. */
157
+ async plan(actions) {
158
+ const plan = buildPlan(scopeOf(this.#parent, this.#sub), actions);
159
+ const writes = plan.actions.filter((a) => a.decision === 'AUTHORIZED' && isWrite(a));
160
+ if (!writes.length)
161
+ return { plan, bundle: null, bundleHash: null };
162
+ const nonce = BigInt.asUintN(64, BigInt(`0x${[...crypto.getRandomValues(new Uint8Array(8))].map((b) => b.toString(16).padStart(2, '0')).join('')}`));
163
+ const bundle = { fidesId: this.#sub.id, nonce, mode: 0, calls: writes.map((a) => ({ target: a.target, value: BigInt(a.value || 0), data: (a.payload ?? '0x') })) };
164
+ return { plan, bundle, bundleHash: hashBundle(bundle, this.#client.chainId, this.#parent.verifier) };
165
+ }
166
+ #args = async (bundle) => {
167
+ const childSignature = await this.#agent.signTypedData(bundleTypedData(bundle, this.#client.chainId, this.#parent.verifier));
168
+ return [fidesMessage(this.#parent), this.#parent.signature, subMessage(this.#sub), this.#sub.signature, bundle, childSignature];
169
+ };
170
+ /** Runs the bundle against the chain without sending it. Returns the contract's reason if it would fail. */
171
+ async simulate(p) {
172
+ if (!p.bundle)
173
+ return { success: false, reason: 'NOTHING_TO_SEND' };
174
+ try {
175
+ await this.#client.public.simulateContract({ address: this.#parent.account, abi: fidesAccountV2Abi, functionName: 'executeSub', args: (await this.#args(p.bundle)), account: this.#relayer?.address ?? this.#parent.account });
176
+ return { success: true };
177
+ }
178
+ catch (err) {
179
+ return { success: false, reason: revertName(err) };
180
+ }
181
+ }
182
+ /** Sends the bundle through the parent's FIDES Account. */
183
+ async execute(p) {
184
+ if (!p.bundle)
185
+ return { status: 'NOTHING_TO_SEND' };
186
+ const sim = await this.simulate(p);
187
+ if (!sim.success)
188
+ return { status: 'REVERTED', error: sim.reason };
189
+ if (this.#api) {
190
+ const [, , , , bundle, childSignature] = await this.#args(p.bundle);
191
+ const res = await fetch(this.#api + '/v1/sub/execute', { method: 'POST', headers: { 'content-type': 'application/json' }, body: toJson({ parent: this.#parent, sub: this.#sub, bundle, childSignature }) });
192
+ const out = fromJson(await res.text());
193
+ if (!res.ok || out?.error)
194
+ return { status: 'REVERTED', error: out?.error?.message ?? `HTTP ${res.status}` };
195
+ return out.status === 'EXECUTED' ? { status: 'EXECUTED', txHash: out.txHash } : { status: 'REVERTED', txHash: out.txHash, error: out.error };
196
+ }
197
+ const txHash = await this.#client.wallet(this.#relayer).writeContract({ address: this.#parent.account, abi: fidesAccountV2Abi, functionName: 'executeSub', args: (await this.#args(p.bundle)), chain: null, account: this.#relayer });
198
+ const rc = await this.#client.public.waitForTransactionReceipt({ hash: txHash });
199
+ return rc.status === 'success' ? { status: 'EXECUTED', txHash } : { status: 'REVERTED', txHash, error: 'reverted onchain' };
200
+ }
201
+ }
202
+ /** Verifies with the deployed SUB-FIDES verifier that the ID computed here is the one the contract computes. */
203
+ export const subIdOnchain = (client, s) => client.public.readContract({ address: client.sub.subVerifier, abi: fidesSubVerifierAbi, functionName: 'hashSubFides', args: [subMessage(s)] });
package/package.json CHANGED
@@ -1,6 +1,40 @@
1
1
  {
2
2
  "name": "@fidesbuild/sub",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.2.1",
4
+ "description": "FIDES SUB-FIDES: scoped agent-to-agent delegation. An agent hands part of its FIDES to another agent, who can never exceed it.",
5
+ "keywords": [
6
+ "fides",
7
+ "agents",
8
+ "transaction-builder",
9
+ "delegation",
10
+ "sub-fides",
11
+ "robinhood-chain",
12
+ "eip-712"
13
+ ],
14
+ "homepage": "https://fidesbuilder.xyz/docs",
15
+ "license": "MIT",
16
+ "type": "module",
17
+ "exports": {
18
+ ".": {
19
+ "types": "./dist/index.d.ts",
20
+ "default": "./dist/index.js"
21
+ }
22
+ },
23
+ "bin": {
24
+ "fides-sub": "./dist/guide.js"
25
+ },
26
+ "files": [
27
+ "dist",
28
+ "!dist/*.tsbuildinfo",
29
+ "!dist/.tsbuildinfo"
30
+ ],
31
+ "publishConfig": {
32
+ "access": "public"
33
+ },
34
+ "dependencies": {
35
+ "@fidesbuild/contracts": "0.2.0",
36
+ "@fidesbuild/core": "0.2.0",
37
+ "@fidesbuild/sdk": "0.2.1",
38
+ "viem": "^2.21.0"
39
+ }
6
40
  }