@opendatalabs/vana-sdk 0.1.0-alpha.a260bf0 → 0.1.0-alpha.a27f5bd
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/controllers/base.cjs +33 -0
- package/dist/controllers/base.cjs.map +1 -1
- package/dist/controllers/base.d.ts +10 -0
- package/dist/controllers/base.js +33 -0
- package/dist/controllers/base.js.map +1 -1
- package/dist/controllers/data.cjs +23 -16
- package/dist/controllers/data.cjs.map +1 -1
- package/dist/controllers/data.d.ts +9 -9
- package/dist/controllers/data.js +23 -16
- package/dist/controllers/data.js.map +1 -1
- package/dist/controllers/permissions.cjs +143 -70
- package/dist/controllers/permissions.cjs.map +1 -1
- package/dist/controllers/permissions.d.ts +20 -11
- package/dist/controllers/permissions.js +143 -70
- package/dist/controllers/permissions.js.map +1 -1
- package/dist/core.cjs +4 -1
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.ts +2 -1
- package/dist/core.js +4 -1
- package/dist/core.js.map +1 -1
- package/dist/index.node.cjs +2 -0
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.d.ts +27 -4
- package/dist/index.node.js +2 -0
- package/dist/index.node.js.map +1 -1
- package/dist/server/relayerHandler.cjs +132 -92
- package/dist/server/relayerHandler.cjs.map +1 -1
- package/dist/server/relayerHandler.d.ts +3 -1
- package/dist/server/relayerHandler.js +132 -92
- package/dist/server/relayerHandler.js.map +1 -1
- package/dist/types/config.cjs.map +1 -1
- package/dist/types/config.d.ts +32 -0
- package/dist/types/config.js.map +1 -1
- package/dist/types/controller-context.cjs.map +1 -1
- package/dist/types/controller-context.d.ts +3 -1
- package/dist/types/generics.cjs.map +1 -1
- package/dist/types/generics.d.ts +1 -1
- package/dist/types/index.cjs.map +1 -1
- package/dist/types/index.d.ts +3 -2
- package/dist/types/index.js.map +1 -1
- package/dist/types/operations.cjs.map +1 -1
- package/dist/types/operations.d.ts +46 -0
- package/dist/types/operations.js.map +1 -1
- package/dist/types/relayer.cjs.map +1 -1
- package/dist/types/relayer.d.ts +22 -3
- package/dist/utils/ipfs.cjs +2 -4
- package/dist/utils/ipfs.cjs.map +1 -1
- package/dist/utils/ipfs.d.ts +1 -1
- package/dist/utils/ipfs.js +2 -4
- package/dist/utils/ipfs.js.map +1 -1
- package/package.json +3 -1
|
@@ -75,6 +75,39 @@ class BaseController {
|
|
|
75
75
|
);
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Helper to safely spread transaction options for viem compatibility.
|
|
80
|
+
* Handles EIP-1559 vs legacy gas pricing correctly.
|
|
81
|
+
*
|
|
82
|
+
* @param options - Transaction options to spread
|
|
83
|
+
* @returns Properly formatted options for viem
|
|
84
|
+
* @internal
|
|
85
|
+
*/
|
|
86
|
+
spreadTransactionOptions(options) {
|
|
87
|
+
if (!options) return {};
|
|
88
|
+
const baseOptions = {
|
|
89
|
+
...options.nonce !== void 0 && { nonce: options.nonce },
|
|
90
|
+
...options.gas !== void 0 && { gas: options.gas }
|
|
91
|
+
};
|
|
92
|
+
if (options.maxFeePerGas !== void 0 || options.maxPriorityFeePerGas !== void 0) {
|
|
93
|
+
return {
|
|
94
|
+
...baseOptions,
|
|
95
|
+
...options.maxFeePerGas !== void 0 && {
|
|
96
|
+
maxFeePerGas: options.maxFeePerGas
|
|
97
|
+
},
|
|
98
|
+
...options.maxPriorityFeePerGas !== void 0 && {
|
|
99
|
+
maxPriorityFeePerGas: options.maxPriorityFeePerGas
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
if (options.gasPrice !== void 0) {
|
|
104
|
+
return {
|
|
105
|
+
...baseOptions,
|
|
106
|
+
gasPrice: options.gasPrice
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
return baseOptions;
|
|
110
|
+
}
|
|
78
111
|
}
|
|
79
112
|
// Annotate the CommonJS export names for ESM import in node:
|
|
80
113
|
0 && (module.exports = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/controllers/base.ts"],"sourcesContent":["/**\n * Base controller class providing common functionality for all controllers.\n *\n * @remarks\n * This abstract class establishes the foundation for all Vana SDK controllers,\n * providing shared utilities like wallet validation and context management.\n * All controllers should extend this base class to ensure consistency and\n * shared behavior across the SDK.\n *\n * The class follows the Single Responsibility Principle by handling only\n * the core controller concerns while leaving specific functionality to\n * implementing classes.\n *\n * @category Controllers\n */\n\nimport type { WalletClient } from \"viem\";\nimport type { ControllerContext } from \"../types/controller-context\";\nimport { ReadOnlyError } from \"../errors\";\n\n/**\n * Abstract base controller that all Vana SDK controllers extend.\n *\n * @remarks\n * Provides common functionality and patterns used across all controllers,\n * including wallet validation and context management. This ensures\n * consistency and reduces code duplication throughout the SDK.\n *\n * Key features:\n * - Wallet client validation with TypeScript assertion signatures\n * - Consistent error handling for read-only scenarios\n * - Shared context management patterns\n * - Type-safe wallet operations\n *\n * @example\n * ```typescript\n * class MyController extends BaseController {\n * async performWalletOperation() {\n * this.assertWallet(); // Ensures wallet is available\n * // Now this.context.walletClient is guaranteed to be available\n * const address = await this.context.walletClient.getAddresses();\n * return address[0];\n * }\n * }\n * ```\n */\nexport abstract class BaseController {\n /**\n * Creates a new controller instance with the provided context.\n *\n * @param context - The controller context containing clients and configuration\n */\n constructor(protected readonly context: ControllerContext) {}\n\n /**\n * Asserts that a wallet client with an account is available for operations requiring signing.\n *\n * @remarks\n * This method uses TypeScript assertion signatures to narrow the type of\n * `this.context` to guarantee that `walletClient` with an account is available\n * after the call succeeds. This provides compile-time safety for wallet operations\n * while enabling clear error messages for read-only scenarios.\n *\n * The assertion signature ensures that after calling this method,\n * TypeScript knows that `this.context.walletClient` is definitely available\n * with a configured account.\n *\n * @throws {ReadOnlyError} When no wallet client is configured\n * @throws {Error} When wallet client exists but no account is configured\n *\n * @example\n * ```typescript\n * async performWalletOperation() {\n * this.assertWallet(); // Type assertion + runtime check\n *\n * // TypeScript now knows walletClient and account are available\n * const account = this.context.walletClient.account;\n * const address = typeof account === 'string' ? account : account.address;\n * }\n * ```\n */\n protected assertWallet(): asserts this is {\n context: ControllerContext & { walletClient: WalletClient };\n } {\n if (!this.context.walletClient) {\n // Get the calling method name from the stack trace for better error messages\n const stack = new Error().stack;\n const callingMethod =\n stack?.split(\"\\n\")[2]?.match(/at \\w+\\.(\\w+)/)?.[1] ?? \"this operation\";\n\n throw new ReadOnlyError(\n callingMethod,\n \"Initialize the SDK with a walletClient to perform this operation\",\n );\n }\n\n if (!this.context.walletClient.account) {\n // Get the calling method name from the stack trace for better error messages\n const stack = new Error().stack;\n const callingMethod =\n stack?.split(\"\\n\")[2]?.match(/at \\w+\\.(\\w+)/)?.[1] ?? \"this operation\";\n\n throw new Error(\n `No wallet account connected. Cannot perform ${callingMethod} without an account.`,\n );\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
1
|
+
{"version":3,"sources":["../../src/controllers/base.ts"],"sourcesContent":["/**\n * Base controller class providing common functionality for all controllers.\n *\n * @remarks\n * This abstract class establishes the foundation for all Vana SDK controllers,\n * providing shared utilities like wallet validation and context management.\n * All controllers should extend this base class to ensure consistency and\n * shared behavior across the SDK.\n *\n * The class follows the Single Responsibility Principle by handling only\n * the core controller concerns while leaving specific functionality to\n * implementing classes.\n *\n * @category Controllers\n */\n\nimport type { WalletClient } from \"viem\";\nimport type { ControllerContext } from \"../types/controller-context\";\nimport type { TransactionOptions } from \"../types/operations\";\nimport { ReadOnlyError } from \"../errors\";\n\n/**\n * Abstract base controller that all Vana SDK controllers extend.\n *\n * @remarks\n * Provides common functionality and patterns used across all controllers,\n * including wallet validation and context management. This ensures\n * consistency and reduces code duplication throughout the SDK.\n *\n * Key features:\n * - Wallet client validation with TypeScript assertion signatures\n * - Consistent error handling for read-only scenarios\n * - Shared context management patterns\n * - Type-safe wallet operations\n *\n * @example\n * ```typescript\n * class MyController extends BaseController {\n * async performWalletOperation() {\n * this.assertWallet(); // Ensures wallet is available\n * // Now this.context.walletClient is guaranteed to be available\n * const address = await this.context.walletClient.getAddresses();\n * return address[0];\n * }\n * }\n * ```\n */\nexport abstract class BaseController {\n /**\n * Creates a new controller instance with the provided context.\n *\n * @param context - The controller context containing clients and configuration\n */\n constructor(protected readonly context: ControllerContext) {}\n\n /**\n * Asserts that a wallet client with an account is available for operations requiring signing.\n *\n * @remarks\n * This method uses TypeScript assertion signatures to narrow the type of\n * `this.context` to guarantee that `walletClient` with an account is available\n * after the call succeeds. This provides compile-time safety for wallet operations\n * while enabling clear error messages for read-only scenarios.\n *\n * The assertion signature ensures that after calling this method,\n * TypeScript knows that `this.context.walletClient` is definitely available\n * with a configured account.\n *\n * @throws {ReadOnlyError} When no wallet client is configured\n * @throws {Error} When wallet client exists but no account is configured\n *\n * @example\n * ```typescript\n * async performWalletOperation() {\n * this.assertWallet(); // Type assertion + runtime check\n *\n * // TypeScript now knows walletClient and account are available\n * const account = this.context.walletClient.account;\n * const address = typeof account === 'string' ? account : account.address;\n * }\n * ```\n */\n protected assertWallet(): asserts this is {\n context: ControllerContext & { walletClient: WalletClient };\n } {\n if (!this.context.walletClient) {\n // Get the calling method name from the stack trace for better error messages\n const stack = new Error().stack;\n const callingMethod =\n stack?.split(\"\\n\")[2]?.match(/at \\w+\\.(\\w+)/)?.[1] ?? \"this operation\";\n\n throw new ReadOnlyError(\n callingMethod,\n \"Initialize the SDK with a walletClient to perform this operation\",\n );\n }\n\n if (!this.context.walletClient.account) {\n // Get the calling method name from the stack trace for better error messages\n const stack = new Error().stack;\n const callingMethod =\n stack?.split(\"\\n\")[2]?.match(/at \\w+\\.(\\w+)/)?.[1] ?? \"this operation\";\n\n throw new Error(\n `No wallet account connected. Cannot perform ${callingMethod} without an account.`,\n );\n }\n }\n\n /**\n * Helper to safely spread transaction options for viem compatibility.\n * Handles EIP-1559 vs legacy gas pricing correctly.\n *\n * @param options - Transaction options to spread\n * @returns Properly formatted options for viem\n * @internal\n */\n protected spreadTransactionOptions(options?: TransactionOptions) {\n if (!options) return {};\n\n const baseOptions: any = {\n ...(options.nonce !== undefined && { nonce: options.nonce }),\n ...(options.gas !== undefined && { gas: options.gas }),\n };\n\n // EIP-1559 and legacy gasPrice are mutually exclusive in viem\n // If EIP-1559 params are provided, use them and exclude gasPrice\n if (\n options.maxFeePerGas !== undefined ||\n options.maxPriorityFeePerGas !== undefined\n ) {\n return {\n ...baseOptions,\n ...(options.maxFeePerGas !== undefined && {\n maxFeePerGas: options.maxFeePerGas,\n }),\n ...(options.maxPriorityFeePerGas !== undefined && {\n maxPriorityFeePerGas: options.maxPriorityFeePerGas,\n }),\n };\n }\n\n // Otherwise, use legacy gasPrice if provided\n if (options.gasPrice !== undefined) {\n return {\n ...baseOptions,\n gasPrice: options.gasPrice,\n };\n }\n\n return baseOptions;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAmBA,oBAA8B;AA4BvB,MAAe,eAAe;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMnC,YAA+B,SAA4B;AAA5B;AAAA,EAA6B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA6BlD,eAER;AACA,QAAI,CAAC,KAAK,QAAQ,cAAc;AAE9B,YAAM,QAAQ,IAAI,MAAM,EAAE;AAC1B,YAAM,gBACJ,OAAO,MAAM,IAAI,EAAE,CAAC,GAAG,MAAM,eAAe,IAAI,CAAC,KAAK;AAExD,YAAM,IAAI;AAAA,QACR;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAEA,QAAI,CAAC,KAAK,QAAQ,aAAa,SAAS;AAEtC,YAAM,QAAQ,IAAI,MAAM,EAAE;AAC1B,YAAM,gBACJ,OAAO,MAAM,IAAI,EAAE,CAAC,GAAG,MAAM,eAAe,IAAI,CAAC,KAAK;AAExD,YAAM,IAAI;AAAA,QACR,+CAA+C,aAAa;AAAA,MAC9D;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUU,yBAAyB,SAA8B;AAC/D,QAAI,CAAC,QAAS,QAAO,CAAC;AAEtB,UAAM,cAAmB;AAAA,MACvB,GAAI,QAAQ,UAAU,UAAa,EAAE,OAAO,QAAQ,MAAM;AAAA,MAC1D,GAAI,QAAQ,QAAQ,UAAa,EAAE,KAAK,QAAQ,IAAI;AAAA,IACtD;AAIA,QACE,QAAQ,iBAAiB,UACzB,QAAQ,yBAAyB,QACjC;AACA,aAAO;AAAA,QACL,GAAG;AAAA,QACH,GAAI,QAAQ,iBAAiB,UAAa;AAAA,UACxC,cAAc,QAAQ;AAAA,QACxB;AAAA,QACA,GAAI,QAAQ,yBAAyB,UAAa;AAAA,UAChD,sBAAsB,QAAQ;AAAA,QAChC;AAAA,MACF;AAAA,IACF;AAGA,QAAI,QAAQ,aAAa,QAAW;AAClC,aAAO;AAAA,QACL,GAAG;AAAA,QACH,UAAU,QAAQ;AAAA,MACpB;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AACF;","names":[]}
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import type { WalletClient } from "viem";
|
|
17
17
|
import type { ControllerContext } from "../types/controller-context";
|
|
18
|
+
import type { TransactionOptions } from "../types/operations";
|
|
18
19
|
/**
|
|
19
20
|
* Abstract base controller that all Vana SDK controllers extend.
|
|
20
21
|
*
|
|
@@ -81,4 +82,13 @@ export declare abstract class BaseController {
|
|
|
81
82
|
walletClient: WalletClient;
|
|
82
83
|
};
|
|
83
84
|
};
|
|
85
|
+
/**
|
|
86
|
+
* Helper to safely spread transaction options for viem compatibility.
|
|
87
|
+
* Handles EIP-1559 vs legacy gas pricing correctly.
|
|
88
|
+
*
|
|
89
|
+
* @param options - Transaction options to spread
|
|
90
|
+
* @returns Properly formatted options for viem
|
|
91
|
+
* @internal
|
|
92
|
+
*/
|
|
93
|
+
protected spreadTransactionOptions(options?: TransactionOptions): any;
|
|
84
94
|
}
|
package/dist/controllers/base.js
CHANGED
|
@@ -52,6 +52,39 @@ class BaseController {
|
|
|
52
52
|
);
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Helper to safely spread transaction options for viem compatibility.
|
|
57
|
+
* Handles EIP-1559 vs legacy gas pricing correctly.
|
|
58
|
+
*
|
|
59
|
+
* @param options - Transaction options to spread
|
|
60
|
+
* @returns Properly formatted options for viem
|
|
61
|
+
* @internal
|
|
62
|
+
*/
|
|
63
|
+
spreadTransactionOptions(options) {
|
|
64
|
+
if (!options) return {};
|
|
65
|
+
const baseOptions = {
|
|
66
|
+
...options.nonce !== void 0 && { nonce: options.nonce },
|
|
67
|
+
...options.gas !== void 0 && { gas: options.gas }
|
|
68
|
+
};
|
|
69
|
+
if (options.maxFeePerGas !== void 0 || options.maxPriorityFeePerGas !== void 0) {
|
|
70
|
+
return {
|
|
71
|
+
...baseOptions,
|
|
72
|
+
...options.maxFeePerGas !== void 0 && {
|
|
73
|
+
maxFeePerGas: options.maxFeePerGas
|
|
74
|
+
},
|
|
75
|
+
...options.maxPriorityFeePerGas !== void 0 && {
|
|
76
|
+
maxPriorityFeePerGas: options.maxPriorityFeePerGas
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
if (options.gasPrice !== void 0) {
|
|
81
|
+
return {
|
|
82
|
+
...baseOptions,
|
|
83
|
+
gasPrice: options.gasPrice
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
return baseOptions;
|
|
87
|
+
}
|
|
55
88
|
}
|
|
56
89
|
export {
|
|
57
90
|
BaseController
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/controllers/base.ts"],"sourcesContent":["/**\n * Base controller class providing common functionality for all controllers.\n *\n * @remarks\n * This abstract class establishes the foundation for all Vana SDK controllers,\n * providing shared utilities like wallet validation and context management.\n * All controllers should extend this base class to ensure consistency and\n * shared behavior across the SDK.\n *\n * The class follows the Single Responsibility Principle by handling only\n * the core controller concerns while leaving specific functionality to\n * implementing classes.\n *\n * @category Controllers\n */\n\nimport type { WalletClient } from \"viem\";\nimport type { ControllerContext } from \"../types/controller-context\";\nimport { ReadOnlyError } from \"../errors\";\n\n/**\n * Abstract base controller that all Vana SDK controllers extend.\n *\n * @remarks\n * Provides common functionality and patterns used across all controllers,\n * including wallet validation and context management. This ensures\n * consistency and reduces code duplication throughout the SDK.\n *\n * Key features:\n * - Wallet client validation with TypeScript assertion signatures\n * - Consistent error handling for read-only scenarios\n * - Shared context management patterns\n * - Type-safe wallet operations\n *\n * @example\n * ```typescript\n * class MyController extends BaseController {\n * async performWalletOperation() {\n * this.assertWallet(); // Ensures wallet is available\n * // Now this.context.walletClient is guaranteed to be available\n * const address = await this.context.walletClient.getAddresses();\n * return address[0];\n * }\n * }\n * ```\n */\nexport abstract class BaseController {\n /**\n * Creates a new controller instance with the provided context.\n *\n * @param context - The controller context containing clients and configuration\n */\n constructor(protected readonly context: ControllerContext) {}\n\n /**\n * Asserts that a wallet client with an account is available for operations requiring signing.\n *\n * @remarks\n * This method uses TypeScript assertion signatures to narrow the type of\n * `this.context` to guarantee that `walletClient` with an account is available\n * after the call succeeds. This provides compile-time safety for wallet operations\n * while enabling clear error messages for read-only scenarios.\n *\n * The assertion signature ensures that after calling this method,\n * TypeScript knows that `this.context.walletClient` is definitely available\n * with a configured account.\n *\n * @throws {ReadOnlyError} When no wallet client is configured\n * @throws {Error} When wallet client exists but no account is configured\n *\n * @example\n * ```typescript\n * async performWalletOperation() {\n * this.assertWallet(); // Type assertion + runtime check\n *\n * // TypeScript now knows walletClient and account are available\n * const account = this.context.walletClient.account;\n * const address = typeof account === 'string' ? account : account.address;\n * }\n * ```\n */\n protected assertWallet(): asserts this is {\n context: ControllerContext & { walletClient: WalletClient };\n } {\n if (!this.context.walletClient) {\n // Get the calling method name from the stack trace for better error messages\n const stack = new Error().stack;\n const callingMethod =\n stack?.split(\"\\n\")[2]?.match(/at \\w+\\.(\\w+)/)?.[1] ?? \"this operation\";\n\n throw new ReadOnlyError(\n callingMethod,\n \"Initialize the SDK with a walletClient to perform this operation\",\n );\n }\n\n if (!this.context.walletClient.account) {\n // Get the calling method name from the stack trace for better error messages\n const stack = new Error().stack;\n const callingMethod =\n stack?.split(\"\\n\")[2]?.match(/at \\w+\\.(\\w+)/)?.[1] ?? \"this operation\";\n\n throw new Error(\n `No wallet account connected. Cannot perform ${callingMethod} without an account.`,\n );\n }\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/controllers/base.ts"],"sourcesContent":["/**\n * Base controller class providing common functionality for all controllers.\n *\n * @remarks\n * This abstract class establishes the foundation for all Vana SDK controllers,\n * providing shared utilities like wallet validation and context management.\n * All controllers should extend this base class to ensure consistency and\n * shared behavior across the SDK.\n *\n * The class follows the Single Responsibility Principle by handling only\n * the core controller concerns while leaving specific functionality to\n * implementing classes.\n *\n * @category Controllers\n */\n\nimport type { WalletClient } from \"viem\";\nimport type { ControllerContext } from \"../types/controller-context\";\nimport type { TransactionOptions } from \"../types/operations\";\nimport { ReadOnlyError } from \"../errors\";\n\n/**\n * Abstract base controller that all Vana SDK controllers extend.\n *\n * @remarks\n * Provides common functionality and patterns used across all controllers,\n * including wallet validation and context management. This ensures\n * consistency and reduces code duplication throughout the SDK.\n *\n * Key features:\n * - Wallet client validation with TypeScript assertion signatures\n * - Consistent error handling for read-only scenarios\n * - Shared context management patterns\n * - Type-safe wallet operations\n *\n * @example\n * ```typescript\n * class MyController extends BaseController {\n * async performWalletOperation() {\n * this.assertWallet(); // Ensures wallet is available\n * // Now this.context.walletClient is guaranteed to be available\n * const address = await this.context.walletClient.getAddresses();\n * return address[0];\n * }\n * }\n * ```\n */\nexport abstract class BaseController {\n /**\n * Creates a new controller instance with the provided context.\n *\n * @param context - The controller context containing clients and configuration\n */\n constructor(protected readonly context: ControllerContext) {}\n\n /**\n * Asserts that a wallet client with an account is available for operations requiring signing.\n *\n * @remarks\n * This method uses TypeScript assertion signatures to narrow the type of\n * `this.context` to guarantee that `walletClient` with an account is available\n * after the call succeeds. This provides compile-time safety for wallet operations\n * while enabling clear error messages for read-only scenarios.\n *\n * The assertion signature ensures that after calling this method,\n * TypeScript knows that `this.context.walletClient` is definitely available\n * with a configured account.\n *\n * @throws {ReadOnlyError} When no wallet client is configured\n * @throws {Error} When wallet client exists but no account is configured\n *\n * @example\n * ```typescript\n * async performWalletOperation() {\n * this.assertWallet(); // Type assertion + runtime check\n *\n * // TypeScript now knows walletClient and account are available\n * const account = this.context.walletClient.account;\n * const address = typeof account === 'string' ? account : account.address;\n * }\n * ```\n */\n protected assertWallet(): asserts this is {\n context: ControllerContext & { walletClient: WalletClient };\n } {\n if (!this.context.walletClient) {\n // Get the calling method name from the stack trace for better error messages\n const stack = new Error().stack;\n const callingMethod =\n stack?.split(\"\\n\")[2]?.match(/at \\w+\\.(\\w+)/)?.[1] ?? \"this operation\";\n\n throw new ReadOnlyError(\n callingMethod,\n \"Initialize the SDK with a walletClient to perform this operation\",\n );\n }\n\n if (!this.context.walletClient.account) {\n // Get the calling method name from the stack trace for better error messages\n const stack = new Error().stack;\n const callingMethod =\n stack?.split(\"\\n\")[2]?.match(/at \\w+\\.(\\w+)/)?.[1] ?? \"this operation\";\n\n throw new Error(\n `No wallet account connected. Cannot perform ${callingMethod} without an account.`,\n );\n }\n }\n\n /**\n * Helper to safely spread transaction options for viem compatibility.\n * Handles EIP-1559 vs legacy gas pricing correctly.\n *\n * @param options - Transaction options to spread\n * @returns Properly formatted options for viem\n * @internal\n */\n protected spreadTransactionOptions(options?: TransactionOptions) {\n if (!options) return {};\n\n const baseOptions: any = {\n ...(options.nonce !== undefined && { nonce: options.nonce }),\n ...(options.gas !== undefined && { gas: options.gas }),\n };\n\n // EIP-1559 and legacy gasPrice are mutually exclusive in viem\n // If EIP-1559 params are provided, use them and exclude gasPrice\n if (\n options.maxFeePerGas !== undefined ||\n options.maxPriorityFeePerGas !== undefined\n ) {\n return {\n ...baseOptions,\n ...(options.maxFeePerGas !== undefined && {\n maxFeePerGas: options.maxFeePerGas,\n }),\n ...(options.maxPriorityFeePerGas !== undefined && {\n maxPriorityFeePerGas: options.maxPriorityFeePerGas,\n }),\n };\n }\n\n // Otherwise, use legacy gasPrice if provided\n if (options.gasPrice !== undefined) {\n return {\n ...baseOptions,\n gasPrice: options.gasPrice,\n };\n }\n\n return baseOptions;\n }\n}\n"],"mappings":"AAmBA,SAAS,qBAAqB;AA4BvB,MAAe,eAAe;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMnC,YAA+B,SAA4B;AAA5B;AAAA,EAA6B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA6BlD,eAER;AACA,QAAI,CAAC,KAAK,QAAQ,cAAc;AAE9B,YAAM,QAAQ,IAAI,MAAM,EAAE;AAC1B,YAAM,gBACJ,OAAO,MAAM,IAAI,EAAE,CAAC,GAAG,MAAM,eAAe,IAAI,CAAC,KAAK;AAExD,YAAM,IAAI;AAAA,QACR;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAEA,QAAI,CAAC,KAAK,QAAQ,aAAa,SAAS;AAEtC,YAAM,QAAQ,IAAI,MAAM,EAAE;AAC1B,YAAM,gBACJ,OAAO,MAAM,IAAI,EAAE,CAAC,GAAG,MAAM,eAAe,IAAI,CAAC,KAAK;AAExD,YAAM,IAAI;AAAA,QACR,+CAA+C,aAAa;AAAA,MAC9D;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUU,yBAAyB,SAA8B;AAC/D,QAAI,CAAC,QAAS,QAAO,CAAC;AAEtB,UAAM,cAAmB;AAAA,MACvB,GAAI,QAAQ,UAAU,UAAa,EAAE,OAAO,QAAQ,MAAM;AAAA,MAC1D,GAAI,QAAQ,QAAQ,UAAa,EAAE,KAAK,QAAQ,IAAI;AAAA,IACtD;AAIA,QACE,QAAQ,iBAAiB,UACzB,QAAQ,yBAAyB,QACjC;AACA,aAAO;AAAA,QACL,GAAG;AAAA,QACH,GAAI,QAAQ,iBAAiB,UAAa;AAAA,UACxC,cAAc,QAAQ;AAAA,QACxB;AAAA,QACA,GAAI,QAAQ,yBAAyB,UAAa;AAAA,UAChD,sBAAsB,QAAQ;AAAA,QAChC;AAAA,MACF;AAAA,IACF;AAGA,QAAI,QAAQ,aAAa,QAAW;AAClC,aAAO;AAAA,QACL,GAAG;AAAA,QACH,UAAU,QAAQ;AAAA,MACpB;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AACF;","names":[]}
|
|
@@ -1373,7 +1373,7 @@ class DataController extends import_base.BaseController {
|
|
|
1373
1373
|
* console.log(`File ${fileId} registered with schema in tx ${transactionHash}`);
|
|
1374
1374
|
* ```
|
|
1375
1375
|
*/
|
|
1376
|
-
async registerFileWithSchema(url, schemaId) {
|
|
1376
|
+
async registerFileWithSchema(url, schemaId, options) {
|
|
1377
1377
|
this.assertWallet();
|
|
1378
1378
|
try {
|
|
1379
1379
|
const chainId = this.context.publicClient.chain?.id;
|
|
@@ -1391,7 +1391,8 @@ class DataController extends import_base.BaseController {
|
|
|
1391
1391
|
functionName: "addFileWithSchema",
|
|
1392
1392
|
args: [url, BigInt(schemaId)],
|
|
1393
1393
|
account,
|
|
1394
|
-
chain: this.context.walletClient.chain ?? null
|
|
1394
|
+
chain: this.context.walletClient.chain ?? null,
|
|
1395
|
+
...this.spreadTransactionOptions(options)
|
|
1395
1396
|
});
|
|
1396
1397
|
const { tx } = await import("../utils/transactionHelpers");
|
|
1397
1398
|
return tx({
|
|
@@ -1429,7 +1430,7 @@ class DataController extends import_base.BaseController {
|
|
|
1429
1430
|
* with specific permissions on the DataRegistry contract. It can be used
|
|
1430
1431
|
* by both direct transactions and relayer services.
|
|
1431
1432
|
*/
|
|
1432
|
-
async addFileWithPermissions(url, ownerAddress, permissions = []) {
|
|
1433
|
+
async addFileWithPermissions(url, ownerAddress, permissions = [], options) {
|
|
1433
1434
|
this.assertWallet();
|
|
1434
1435
|
try {
|
|
1435
1436
|
const chainId = this.context.publicClient.chain?.id;
|
|
@@ -1447,7 +1448,8 @@ class DataController extends import_base.BaseController {
|
|
|
1447
1448
|
functionName: "addFileWithPermissions",
|
|
1448
1449
|
args: [url, ownerAddress, permissions],
|
|
1449
1450
|
account,
|
|
1450
|
-
chain: this.context.walletClient.chain ?? null
|
|
1451
|
+
chain: this.context.walletClient.chain ?? null,
|
|
1452
|
+
...this.spreadTransactionOptions(options)
|
|
1451
1453
|
});
|
|
1452
1454
|
const { tx } = await import("../utils/transactionHelpers");
|
|
1453
1455
|
return tx({
|
|
@@ -1502,7 +1504,7 @@ class DataController extends import_base.BaseController {
|
|
|
1502
1504
|
* console.log(`File ${result.fileId} registered in tx ${result.hash}`);
|
|
1503
1505
|
* ```
|
|
1504
1506
|
*/
|
|
1505
|
-
async addFileWithPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0) {
|
|
1507
|
+
async addFileWithPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0, options) {
|
|
1506
1508
|
this.assertWallet();
|
|
1507
1509
|
try {
|
|
1508
1510
|
let encryptedPermissions = [];
|
|
@@ -1536,7 +1538,8 @@ class DataController extends import_base.BaseController {
|
|
|
1536
1538
|
url,
|
|
1537
1539
|
ownerAddress,
|
|
1538
1540
|
encryptedPermissions,
|
|
1539
|
-
schemaId
|
|
1541
|
+
schemaId,
|
|
1542
|
+
options
|
|
1540
1543
|
);
|
|
1541
1544
|
} catch (error) {
|
|
1542
1545
|
console.error("Failed to add file with permissions and schema:", error);
|
|
@@ -1583,7 +1586,7 @@ class DataController extends import_base.BaseController {
|
|
|
1583
1586
|
* console.log(`File registered in tx ${result.hash}`);
|
|
1584
1587
|
* ```
|
|
1585
1588
|
*/
|
|
1586
|
-
async addFileWithEncryptedPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0) {
|
|
1589
|
+
async addFileWithEncryptedPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0, options) {
|
|
1587
1590
|
try {
|
|
1588
1591
|
const chainId = this.context.publicClient.chain?.id;
|
|
1589
1592
|
if (!chainId) {
|
|
@@ -1600,7 +1603,8 @@ class DataController extends import_base.BaseController {
|
|
|
1600
1603
|
functionName: "addFileWithPermissionsAndSchema",
|
|
1601
1604
|
args: [url, ownerAddress, permissions, BigInt(schemaId)],
|
|
1602
1605
|
account,
|
|
1603
|
-
chain: this.context.walletClient.chain ?? null
|
|
1606
|
+
chain: this.context.walletClient.chain ?? null,
|
|
1607
|
+
...this.spreadTransactionOptions(options)
|
|
1604
1608
|
});
|
|
1605
1609
|
const { tx } = await import("../utils/transactionHelpers");
|
|
1606
1610
|
return tx({
|
|
@@ -1648,7 +1652,7 @@ class DataController extends import_base.BaseController {
|
|
|
1648
1652
|
* console.log(`Refiner ${result.refinerId} created`);
|
|
1649
1653
|
* ```
|
|
1650
1654
|
*/
|
|
1651
|
-
async addRefiner(params) {
|
|
1655
|
+
async addRefiner(params, options) {
|
|
1652
1656
|
this.assertWallet();
|
|
1653
1657
|
try {
|
|
1654
1658
|
const chainId = this.context.publicClient.chain?.id;
|
|
@@ -1674,7 +1678,8 @@ class DataController extends import_base.BaseController {
|
|
|
1674
1678
|
params.refinementInstructionUrl
|
|
1675
1679
|
],
|
|
1676
1680
|
account,
|
|
1677
|
-
chain: this.context.walletClient.chain ?? null
|
|
1681
|
+
chain: this.context.walletClient.chain ?? null,
|
|
1682
|
+
...this.spreadTransactionOptions(options)
|
|
1678
1683
|
});
|
|
1679
1684
|
const { tx } = await import("../utils/transactionHelpers");
|
|
1680
1685
|
const txResult = tx({
|
|
@@ -1874,7 +1879,7 @@ class DataController extends import_base.BaseController {
|
|
|
1874
1879
|
* console.log(`Schema updated in tx ${result.transactionHash}`);
|
|
1875
1880
|
* ```
|
|
1876
1881
|
*/
|
|
1877
|
-
async updateSchemaId(params) {
|
|
1882
|
+
async updateSchemaId(params, options) {
|
|
1878
1883
|
this.assertWallet();
|
|
1879
1884
|
try {
|
|
1880
1885
|
const chainId = this.context.publicClient.chain?.id;
|
|
@@ -1894,7 +1899,8 @@ class DataController extends import_base.BaseController {
|
|
|
1894
1899
|
functionName: "updateSchemaId",
|
|
1895
1900
|
args: [BigInt(params.refinerId), BigInt(params.newSchemaId)],
|
|
1896
1901
|
account,
|
|
1897
|
-
chain: this.context.walletClient.chain ?? null
|
|
1902
|
+
chain: this.context.walletClient.chain ?? null,
|
|
1903
|
+
...this.spreadTransactionOptions(options)
|
|
1898
1904
|
});
|
|
1899
1905
|
await this.context.publicClient.waitForTransactionReceipt({ hash });
|
|
1900
1906
|
return {
|
|
@@ -2100,10 +2106,10 @@ class DataController extends import_base.BaseController {
|
|
|
2100
2106
|
* console.log(`Transaction: ${result.transactionHash}`);
|
|
2101
2107
|
* ```
|
|
2102
2108
|
*/
|
|
2103
|
-
async addPermissionToFile(params) {
|
|
2109
|
+
async addPermissionToFile(params, options) {
|
|
2104
2110
|
this.assertWallet();
|
|
2105
2111
|
const { fileId, account, publicKey } = params;
|
|
2106
|
-
return await this.submitFilePermission(fileId, account, publicKey);
|
|
2112
|
+
return await this.submitFilePermission(fileId, account, publicKey, options);
|
|
2107
2113
|
}
|
|
2108
2114
|
/**
|
|
2109
2115
|
* Submits a file permission transaction to the blockchain.
|
|
@@ -2133,7 +2139,7 @@ class DataController extends import_base.BaseController {
|
|
|
2133
2139
|
* console.log(`Permission granted with ID: ${result.permissionId}`);
|
|
2134
2140
|
* ```
|
|
2135
2141
|
*/
|
|
2136
|
-
async submitFilePermission(fileId, account, publicKey) {
|
|
2142
|
+
async submitFilePermission(fileId, account, publicKey, options) {
|
|
2137
2143
|
this.assertWallet();
|
|
2138
2144
|
try {
|
|
2139
2145
|
const userEncryptionKey = await (0, import_encryption.generateEncryptionKey)(
|
|
@@ -2160,7 +2166,8 @@ class DataController extends import_base.BaseController {
|
|
|
2160
2166
|
functionName: "addFilePermission",
|
|
2161
2167
|
args: [BigInt(fileId), account, encryptedKey],
|
|
2162
2168
|
account: walletAccount,
|
|
2163
|
-
chain: this.context.walletClient.chain ?? null
|
|
2169
|
+
chain: this.context.walletClient.chain ?? null,
|
|
2170
|
+
...this.spreadTransactionOptions(options)
|
|
2164
2171
|
});
|
|
2165
2172
|
const { tx } = await import("../utils/transactionHelpers");
|
|
2166
2173
|
return tx({
|