@walletmesh/aztec-rpc-wallet 0.1.1 → 0.3.0

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.
Files changed (87) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +4 -4
  3. package/dist/.tsbuildinfo +1 -1
  4. package/dist/aztecRemoteWallet.d.ts +4 -8
  5. package/dist/aztecRemoteWallet.d.ts.map +1 -1
  6. package/dist/aztecRemoteWallet.js +5 -30
  7. package/dist/chainProvider.d.ts.map +1 -1
  8. package/dist/chainProvider.js +1 -1
  9. package/dist/contractArtifactCache.d.ts.map +1 -1
  10. package/dist/contractArtifactCache.js +20 -9
  11. package/dist/errors.d.ts.map +1 -1
  12. package/dist/errors.js +1 -1
  13. package/dist/handlers/aztecAccountWallet.d.ts.map +1 -1
  14. package/dist/handlers/aztecAccountWallet.js +12 -45
  15. package/dist/handlers/transactions.d.ts.map +1 -1
  16. package/dist/handlers/transactions.js +11 -3
  17. package/dist/serializers/account.d.ts +24 -24
  18. package/dist/serializers/account.d.ts.map +1 -1
  19. package/dist/serializers/account.js +51 -51
  20. package/dist/serializers/contract.d.ts +22 -76
  21. package/dist/serializers/contract.d.ts.map +1 -1
  22. package/dist/serializers/contract.js +68 -120
  23. package/dist/serializers/index.d.ts +0 -4
  24. package/dist/serializers/index.d.ts.map +1 -1
  25. package/dist/serializers/index.js +15 -20
  26. package/dist/serializers/log.d.ts +16 -16
  27. package/dist/serializers/log.d.ts.map +1 -1
  28. package/dist/serializers/log.js +66 -64
  29. package/dist/serializers/note.d.ts +18 -18
  30. package/dist/serializers/note.d.ts.map +1 -1
  31. package/dist/serializers/note.js +54 -51
  32. package/dist/serializers/transaction.d.ts +25 -26
  33. package/dist/serializers/transaction.d.ts.map +1 -1
  34. package/dist/serializers/transaction.js +92 -44
  35. package/dist/types.d.ts +8 -31
  36. package/dist/types.d.ts.map +1 -1
  37. package/dist/types.js +1 -1
  38. package/docs/README.md +264 -0
  39. package/docs/classes/AztecChainProvider.md +553 -0
  40. package/docs/classes/AztecChainWallet.md +409 -0
  41. package/docs/classes/AztecProvider.md +1112 -0
  42. package/docs/classes/AztecWalletError.md +213 -0
  43. package/docs/classes/ContractArtifactCache.md +81 -0
  44. package/docs/globals.md +34 -0
  45. package/docs/interfaces/AztecWalletBaseMethodMap.md +135 -0
  46. package/docs/interfaces/AztecWalletEventMap.md +17 -0
  47. package/docs/interfaces/AztecWalletMethodMap.md +1012 -0
  48. package/docs/type-aliases/AztecChainId.md +11 -0
  49. package/docs/type-aliases/AztecChainWalletMiddleware.md +13 -0
  50. package/docs/type-aliases/AztecWalletContext.md +29 -0
  51. package/docs/type-aliases/AztecWalletMethodHandler.md +37 -0
  52. package/docs/type-aliases/AztecWalletMiddleware.md +13 -0
  53. package/docs/type-aliases/AztecWalletRouterClient.md +13 -0
  54. package/docs/type-aliases/TransactionFunctionCall.md +33 -0
  55. package/docs/type-aliases/TransactionParams.md +27 -0
  56. package/docs/variables/AztecWalletErrorMap.md +13 -0
  57. package/package.json +11 -11
  58. package/src/aztecRemoteWallet.test.ts +23 -65
  59. package/src/aztecRemoteWallet.ts +8 -36
  60. package/src/chainProvider.test.ts +117 -38
  61. package/src/chainProvider.ts +1 -7
  62. package/src/contractArtifactCache.test.ts +28 -45
  63. package/src/contractArtifactCache.ts +20 -10
  64. package/src/errors.ts +0 -1
  65. package/src/handlers/aztecAccountWallet.test.ts +12 -86
  66. package/src/handlers/aztecAccountWallet.ts +20 -78
  67. package/src/handlers/transactions.ts +16 -2
  68. package/src/provider.test.ts +0 -2
  69. package/src/serializers/account.test.ts +19 -20
  70. package/src/serializers/account.ts +65 -65
  71. package/src/serializers/contract.test.ts +4 -140
  72. package/src/serializers/contract.ts +98 -176
  73. package/src/serializers/index.test.ts +30 -28
  74. package/src/serializers/index.ts +15 -33
  75. package/src/serializers/log.test.ts +42 -48
  76. package/src/serializers/log.ts +85 -83
  77. package/src/serializers/note.test.ts +43 -16
  78. package/src/serializers/note.ts +62 -63
  79. package/src/serializers/transaction.test.ts +48 -41
  80. package/src/serializers/transaction.ts +154 -66
  81. package/src/types.ts +8 -8
  82. package/src/wallet.test.ts +3 -3
  83. package/tsconfig.json +1 -1
  84. package/dist/serializers/transaction-utils.d.ts +0 -51
  85. package/dist/serializers/transaction-utils.d.ts.map +0 -1
  86. package/dist/serializers/transaction-utils.js +0 -94
  87. package/src/serializers/transaction-utils.ts +0 -161
@@ -1,5 +1,5 @@
1
1
  import { describe, expect, it, vi, beforeEach } from 'vitest';
2
- import type { AccountWallet, PXE, TxHash } from '@aztec/aztec.js';
2
+ import type { AccountWallet, PXE } from '@aztec/aztec.js';
3
3
  import { JSONRPCWalletClient } from '@walletmesh/router';
4
4
  import { AztecChainWallet } from './wallet.js';
5
5
  import { ContractArtifactCache } from './contractArtifactCache.js';
@@ -36,7 +36,7 @@ describe('AztecChainWallet', () => {
36
36
  aztecWallet = new AztecChainWallet(pxe, wallet, transport);
37
37
 
38
38
  // Setup fallback handler and serializer
39
- const mockHandler = vi.fn().mockImplementation(async (context, method, params) => {
39
+ const mockHandler = vi.fn().mockImplementation(async (context, method, _params) => {
40
40
  if (!isAztecWalletContext(context)) {
41
41
  throw new AztecWalletError('unknownInternalError', 'Invalid context');
42
42
  }
@@ -249,7 +249,7 @@ describe('AztecChainWallet', () => {
249
249
  };
250
250
 
251
251
  // Setup request handler to throw error for invalid method
252
- const handleRequest = async (msg: unknown) => {
252
+ const handleRequest = async (_msg: unknown) => {
253
253
  throw new AztecWalletError('invalidRequest', 'Invalid method');
254
254
  };
255
255
 
package/tsconfig.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "extends": "../tsconfig.base.json",
2
+ "extends": "../../tsconfig.json",
3
3
  "compilerOptions": {
4
4
  "rootDir": "src",
5
5
  "outDir": "dist",
@@ -1,51 +0,0 @@
1
- /**
2
- * @module transaction-utils
3
- * Utilities for serializing and deserializing Aztec transaction execution requests.
4
- * These utilities handle the conversion between native Aztec types and JSON-RPC compatible formats.
5
- */
6
- import type { ExecutionRequestInit } from '@aztec/aztec.js/entrypoint';
7
- /**
8
- * Serializes an ExecutionRequestInit object to a string for JSON-RPC transport.
9
- * This function converts a native Aztec transaction execution request into a format
10
- * that can be safely transmitted over JSON-RPC, handling the conversion of complex
11
- * types like addresses, field elements, and function selectors to strings.
12
- *
13
- * Note: The fee payment method is not serialized as it contains async methods.
14
- * The deserializer will use a default NoFeePaymentMethod which should be replaced
15
- * by the caller with an appropriate implementation.
16
- *
17
- * @param init - The ExecutionRequestInit object to serialize, containing:
18
- * - calls: Array of function calls to execute
19
- * - fee: Gas settings and payment method
20
- * - authWitnesses: Optional authentication proofs
21
- * - hashedArguments: Optional pre-hashed arguments
22
- * - nonce: Optional transaction nonce
23
- * - cancellable: Optional cancellation flag
24
- * @returns A JSON string representation of the serialized data, with all complex
25
- * Aztec types converted to string representations
26
- * @throws If any of the complex types cannot be serialized
27
- */
28
- export declare function serializeExecutionRequestInit(init: ExecutionRequestInit): string;
29
- /**
30
- * Deserializes a string into an ExecutionRequestInit object for use in the Aztec protocol.
31
- * This function reconstructs a native Aztec transaction execution request from its
32
- * JSON-RPC serialized form, converting string representations back into their
33
- * appropriate Aztec types.
34
- *
35
- * Note: A default NoFeePaymentMethod is used for the fee payment method.
36
- * The caller should override this with the appropriate implementation based on
37
- * their fee payment requirements.
38
- *
39
- * @param data - The serialized string data containing:
40
- * - calls: Array of serialized function calls
41
- * - fee: Serialized gas settings
42
- * - authWitnesses: Optional serialized authentication proofs
43
- * - hashedArguments: Optional serialized hashed arguments
44
- * - nonce: Optional serialized nonce
45
- * - cancellable: Optional cancellation flag
46
- * @returns The deserialized ExecutionRequestInit object with all string representations
47
- * converted back to their native Aztec types
48
- * @throws If any of the serialized data cannot be properly deserialized into valid Aztec types
49
- */
50
- export declare function deserializeExecutionRequestInit(data: string): ExecutionRequestInit;
51
- //# sourceMappingURL=transaction-utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"transaction-utils.d.ts","sourceRoot":"","sources":["../../src/serializers/transaction-utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAiDvE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,6BAA6B,CAAC,IAAI,EAAE,oBAAoB,GAAG,MAAM,CAiChF;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,+BAA+B,CAAC,IAAI,EAAE,MAAM,GAAG,oBAAoB,CAyBlF"}
@@ -1,94 +0,0 @@
1
- /**
2
- * @module transaction-utils
3
- * Utilities for serializing and deserializing Aztec transaction execution requests.
4
- * These utilities handle the conversion between native Aztec types and JSON-RPC compatible formats.
5
- */
6
- import { HashedValues, FunctionCall, AuthWitness } from '@aztec/circuit-types';
7
- import { AztecAddress, Fr, FunctionSelector, GasSettings } from '@aztec/circuits.js';
8
- import { NoFeePaymentMethod } from '@aztec/aztec.js';
9
- /**
10
- * Serializes an ExecutionRequestInit object to a string for JSON-RPC transport.
11
- * This function converts a native Aztec transaction execution request into a format
12
- * that can be safely transmitted over JSON-RPC, handling the conversion of complex
13
- * types like addresses, field elements, and function selectors to strings.
14
- *
15
- * Note: The fee payment method is not serialized as it contains async methods.
16
- * The deserializer will use a default NoFeePaymentMethod which should be replaced
17
- * by the caller with an appropriate implementation.
18
- *
19
- * @param init - The ExecutionRequestInit object to serialize, containing:
20
- * - calls: Array of function calls to execute
21
- * - fee: Gas settings and payment method
22
- * - authWitnesses: Optional authentication proofs
23
- * - hashedArguments: Optional pre-hashed arguments
24
- * - nonce: Optional transaction nonce
25
- * - cancellable: Optional cancellation flag
26
- * @returns A JSON string representation of the serialized data, with all complex
27
- * Aztec types converted to string representations
28
- * @throws If any of the complex types cannot be serialized
29
- */
30
- export function serializeExecutionRequestInit(init) {
31
- const serialized = {
32
- calls: init.calls.map((call) => ({
33
- name: call.name,
34
- to: call.to.toString(),
35
- selector: call.selector.toString(),
36
- type: call.type,
37
- isStatic: call.isStatic,
38
- args: call.args.map((arg) => arg.toString()),
39
- returnTypes: call.returnTypes,
40
- })),
41
- fee: {
42
- gasSettings: init.fee.gasSettings.toBuffer().toString('base64'),
43
- },
44
- };
45
- if (init.authWitnesses) {
46
- serialized.authWitnesses = init.authWitnesses.map((w) => w.toString());
47
- }
48
- if (init.hashedArguments) {
49
- serialized.hashedArguments = init.hashedArguments.map((ha) => ha.toBuffer().toString('base64'));
50
- }
51
- if (init.nonce) {
52
- serialized.nonce = init.nonce.toString();
53
- }
54
- if (init.cancellable !== undefined) {
55
- serialized.cancellable = init.cancellable;
56
- }
57
- return JSON.stringify(serialized);
58
- }
59
- /**
60
- * Deserializes a string into an ExecutionRequestInit object for use in the Aztec protocol.
61
- * This function reconstructs a native Aztec transaction execution request from its
62
- * JSON-RPC serialized form, converting string representations back into their
63
- * appropriate Aztec types.
64
- *
65
- * Note: A default NoFeePaymentMethod is used for the fee payment method.
66
- * The caller should override this with the appropriate implementation based on
67
- * their fee payment requirements.
68
- *
69
- * @param data - The serialized string data containing:
70
- * - calls: Array of serialized function calls
71
- * - fee: Serialized gas settings
72
- * - authWitnesses: Optional serialized authentication proofs
73
- * - hashedArguments: Optional serialized hashed arguments
74
- * - nonce: Optional serialized nonce
75
- * - cancellable: Optional cancellation flag
76
- * @returns The deserialized ExecutionRequestInit object with all string representations
77
- * converted back to their native Aztec types
78
- * @throws If any of the serialized data cannot be properly deserialized into valid Aztec types
79
- */
80
- export function deserializeExecutionRequestInit(data) {
81
- const parsed = JSON.parse(data);
82
- return {
83
- calls: parsed.calls.map((call) => new FunctionCall(call.name, AztecAddress.fromString(call.to), FunctionSelector.fromString(call.selector), call.type, call.isStatic, call.args.map((arg) => Fr.fromString(arg)), call.returnTypes)),
84
- fee: {
85
- gasSettings: GasSettings.fromBuffer(Buffer.from(parsed.fee.gasSettings, 'base64')),
86
- paymentMethod: new NoFeePaymentMethod(), // Default, caller should override
87
- },
88
- authWitnesses: parsed.authWitnesses?.map((w) => AuthWitness.fromString(w)),
89
- hashedArguments: parsed.hashedArguments?.map((ha) => HashedValues.fromBuffer(Buffer.from(ha, 'base64'))),
90
- nonce: parsed.nonce ? Fr.fromString(parsed.nonce) : undefined,
91
- cancellable: parsed.cancellable,
92
- };
93
- }
94
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHJhbnNhY3Rpb24tdXRpbHMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvc2VyaWFsaXplcnMvdHJhbnNhY3Rpb24tdXRpbHMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7R0FJRztBQUVILE9BQU8sRUFBRSxZQUFZLEVBQUUsWUFBWSxFQUFFLFdBQVcsRUFBRSxNQUFNLHNCQUFzQixDQUFDO0FBQy9FLE9BQU8sRUFBRSxZQUFZLEVBQUUsRUFBRSxFQUFFLGdCQUFnQixFQUFFLFdBQVcsRUFBRSxNQUFNLG9CQUFvQixDQUFDO0FBR3JGLE9BQU8sRUFBRSxrQkFBa0IsRUFBRSxNQUFNLGlCQUFpQixDQUFDO0FBZ0RyRDs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7R0FvQkc7QUFDSCxNQUFNLFVBQVUsNkJBQTZCLENBQUMsSUFBMEI7SUFDdEUsTUFBTSxVQUFVLEdBQW1DO1FBQ2pELEtBQUssRUFBRSxJQUFJLENBQUMsS0FBSyxDQUFDLEdBQUcsQ0FBQyxDQUFDLElBQUksRUFBRSxFQUFFLENBQUMsQ0FBQztZQUMvQixJQUFJLEVBQUUsSUFBSSxDQUFDLElBQUk7WUFDZixFQUFFLEVBQUUsSUFBSSxDQUFDLEVBQUUsQ0FBQyxRQUFRLEVBQUU7WUFDdEIsUUFBUSxFQUFFLElBQUksQ0FBQyxRQUFRLENBQUMsUUFBUSxFQUFFO1lBQ2xDLElBQUksRUFBRSxJQUFJLENBQU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QWEsRUFBRSxNQUFNLENBQUMsYUFBYSxFQUFFLEdBQUcsQ0FBQyxDQUFDLENBQUMsRUFBRSxFQUFFLENBQUMsV0FBVyxDQUFDLFVBQVUsQ0FBQyxDQUFDLENBQUMsQ0FBQztRQUMxRSxlQUFlLEVBQUUsTUFBTSxDQUFDLGVBQWUsRUFBRSxHQUFHLENBQUMsQ0FBQyxFQUFFLEVBQUUsRUFBRSxDQUFDLFlBQVksQ0FBQyxVQUFVLENBQUMsTUFBTSxDQUFDLElBQUksQ0FBQyxFQUFFLEVBQUUsUUFBUSxDQUFDLENBQUMsQ0FBQztRQUN4RyxLQUFLLEVBQUUsTUFBTSxDQUFDLEtBQUssQ0FBQyxDQUFDLENBQUMsRUFBRSxDQUFDLFVBQVUsQ0FBQyxNQUFNLENBQUMsS0FBSyxDQUFDLENBQUMsQ0FBQyxDQUFDLFNBQVM7UUFDN0QsV0FBVyxFQUFFLE1BQU0sQ0FBQyxXQUFXO0tBQ2hDLENBQUM7QUFDSixDQUFDIn0=
@@ -1,161 +0,0 @@
1
- /**
2
- * @module transaction-utils
3
- * Utilities for serializing and deserializing Aztec transaction execution requests.
4
- * These utilities handle the conversion between native Aztec types and JSON-RPC compatible formats.
5
- */
6
-
7
- import { HashedValues, FunctionCall, AuthWitness } from '@aztec/circuit-types';
8
- import { AztecAddress, Fr, FunctionSelector, GasSettings } from '@aztec/circuits.js';
9
- import type { FunctionType, AbiType } from '@aztec/foundation/abi';
10
- import type { ExecutionRequestInit } from '@aztec/aztec.js/entrypoint';
11
- import { NoFeePaymentMethod } from '@aztec/aztec.js';
12
-
13
- /**
14
- * Interface representing the serialized form of a function call.
15
- * This structure maps the native FunctionCall type to a JSON-serializable format
16
- * where complex Aztec types are converted to strings.
17
- *
18
- * @property name - The name of the function being called
19
- * @property to - The target contract address as a string
20
- * @property selector - The function selector as a string
21
- * @property type - The function type (public/private)
22
- * @property isStatic - Whether the function is static (read-only)
23
- * @property args - Array of function arguments as strings
24
- * @property returnTypes - Array of return type definitions
25
- */
26
- interface SerializedFunctionCall {
27
- name: string;
28
- to: string;
29
- selector: string;
30
- type: FunctionType;
31
- isStatic: boolean;
32
- args: string[];
33
- returnTypes: AbiType[];
34
- }
35
-
36
- /**
37
- * Interface representing the serialized form of an execution request initialization.
38
- * This structure maps the ExecutionRequestInit type to a JSON-serializable format
39
- * where complex Aztec types are converted to strings.
40
- *
41
- * @property calls - Array of serialized function calls
42
- * @property authWitnesses - Optional array of authentication witness strings
43
- * @property hashedArguments - Optional array of hashed argument values as base64 strings
44
- * @property fee - Fee settings including gas configuration
45
- * @property nonce - Optional transaction nonce as a string
46
- * @property cancellable - Optional flag indicating if the transaction can be cancelled
47
- */
48
- interface SerializedExecutionRequestInit {
49
- calls: SerializedFunctionCall[];
50
- authWitnesses?: string[];
51
- hashedArguments?: string[];
52
- fee: {
53
- gasSettings: string;
54
- };
55
- nonce?: string;
56
- cancellable?: boolean;
57
- }
58
-
59
- /**
60
- * Serializes an ExecutionRequestInit object to a string for JSON-RPC transport.
61
- * This function converts a native Aztec transaction execution request into a format
62
- * that can be safely transmitted over JSON-RPC, handling the conversion of complex
63
- * types like addresses, field elements, and function selectors to strings.
64
- *
65
- * Note: The fee payment method is not serialized as it contains async methods.
66
- * The deserializer will use a default NoFeePaymentMethod which should be replaced
67
- * by the caller with an appropriate implementation.
68
- *
69
- * @param init - The ExecutionRequestInit object to serialize, containing:
70
- * - calls: Array of function calls to execute
71
- * - fee: Gas settings and payment method
72
- * - authWitnesses: Optional authentication proofs
73
- * - hashedArguments: Optional pre-hashed arguments
74
- * - nonce: Optional transaction nonce
75
- * - cancellable: Optional cancellation flag
76
- * @returns A JSON string representation of the serialized data, with all complex
77
- * Aztec types converted to string representations
78
- * @throws If any of the complex types cannot be serialized
79
- */
80
- export function serializeExecutionRequestInit(init: ExecutionRequestInit): string {
81
- const serialized: SerializedExecutionRequestInit = {
82
- calls: init.calls.map((call) => ({
83
- name: call.name,
84
- to: call.to.toString(),
85
- selector: call.selector.toString(),
86
- type: call.type,
87
- isStatic: call.isStatic,
88
- args: call.args.map((arg) => arg.toString()),
89
- returnTypes: call.returnTypes,
90
- })),
91
- fee: {
92
- gasSettings: init.fee.gasSettings.toBuffer().toString('base64'),
93
- },
94
- };
95
-
96
- if (init.authWitnesses) {
97
- serialized.authWitnesses = init.authWitnesses.map((w) => w.toString());
98
- }
99
-
100
- if (init.hashedArguments) {
101
- serialized.hashedArguments = init.hashedArguments.map((ha) => ha.toBuffer().toString('base64'));
102
- }
103
-
104
- if (init.nonce) {
105
- serialized.nonce = init.nonce.toString();
106
- }
107
-
108
- if (init.cancellable !== undefined) {
109
- serialized.cancellable = init.cancellable;
110
- }
111
-
112
- return JSON.stringify(serialized);
113
- }
114
-
115
- /**
116
- * Deserializes a string into an ExecutionRequestInit object for use in the Aztec protocol.
117
- * This function reconstructs a native Aztec transaction execution request from its
118
- * JSON-RPC serialized form, converting string representations back into their
119
- * appropriate Aztec types.
120
- *
121
- * Note: A default NoFeePaymentMethod is used for the fee payment method.
122
- * The caller should override this with the appropriate implementation based on
123
- * their fee payment requirements.
124
- *
125
- * @param data - The serialized string data containing:
126
- * - calls: Array of serialized function calls
127
- * - fee: Serialized gas settings
128
- * - authWitnesses: Optional serialized authentication proofs
129
- * - hashedArguments: Optional serialized hashed arguments
130
- * - nonce: Optional serialized nonce
131
- * - cancellable: Optional cancellation flag
132
- * @returns The deserialized ExecutionRequestInit object with all string representations
133
- * converted back to their native Aztec types
134
- * @throws If any of the serialized data cannot be properly deserialized into valid Aztec types
135
- */
136
- export function deserializeExecutionRequestInit(data: string): ExecutionRequestInit {
137
- const parsed: SerializedExecutionRequestInit = JSON.parse(data);
138
-
139
- return {
140
- calls: parsed.calls.map(
141
- (call) =>
142
- new FunctionCall(
143
- call.name,
144
- AztecAddress.fromString(call.to),
145
- FunctionSelector.fromString(call.selector),
146
- call.type,
147
- call.isStatic,
148
- call.args.map((arg) => Fr.fromString(arg)),
149
- call.returnTypes,
150
- ),
151
- ),
152
- fee: {
153
- gasSettings: GasSettings.fromBuffer(Buffer.from(parsed.fee.gasSettings, 'base64')),
154
- paymentMethod: new NoFeePaymentMethod(), // Default, caller should override
155
- },
156
- authWitnesses: parsed.authWitnesses?.map((w) => AuthWitness.fromString(w)),
157
- hashedArguments: parsed.hashedArguments?.map((ha) => HashedValues.fromBuffer(Buffer.from(ha, 'base64'))),
158
- nonce: parsed.nonce ? Fr.fromString(parsed.nonce) : undefined,
159
- cancellable: parsed.cancellable,
160
- };
161
- }