@metamask-previews/user-operation-controller 40.0.0-preview-d4351f75 → 40.0.0-preview-bf3ab7d

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 (63) hide show
  1. package/dist/UserOperationController.cjs +0 -4
  2. package/dist/UserOperationController.cjs.map +1 -1
  3. package/dist/UserOperationController.d.cts.map +1 -1
  4. package/dist/UserOperationController.d.mts.map +1 -1
  5. package/dist/UserOperationController.mjs +0 -4
  6. package/dist/UserOperationController.mjs.map +1 -1
  7. package/dist/helpers/Bundler.cjs +3 -5
  8. package/dist/helpers/Bundler.cjs.map +1 -1
  9. package/dist/helpers/Bundler.d.cts +2 -0
  10. package/dist/helpers/Bundler.d.cts.map +1 -1
  11. package/dist/helpers/Bundler.d.mts +2 -0
  12. package/dist/helpers/Bundler.d.mts.map +1 -1
  13. package/dist/helpers/Bundler.mjs +3 -5
  14. package/dist/helpers/Bundler.mjs.map +1 -1
  15. package/dist/helpers/PendingUserOperationTracker.cjs +1 -1
  16. package/dist/helpers/PendingUserOperationTracker.cjs.map +1 -1
  17. package/dist/helpers/PendingUserOperationTracker.d.cts +1 -1
  18. package/dist/helpers/PendingUserOperationTracker.d.cts.map +1 -1
  19. package/dist/helpers/PendingUserOperationTracker.d.mts +1 -1
  20. package/dist/helpers/PendingUserOperationTracker.d.mts.map +1 -1
  21. package/dist/helpers/PendingUserOperationTracker.mjs +1 -1
  22. package/dist/helpers/PendingUserOperationTracker.mjs.map +1 -1
  23. package/dist/helpers/SnapSmartContractAccount.cjs.map +1 -1
  24. package/dist/helpers/SnapSmartContractAccount.mjs.map +1 -1
  25. package/dist/types.cjs.map +1 -1
  26. package/dist/types.d.cts +3 -0
  27. package/dist/types.d.cts.map +1 -1
  28. package/dist/types.d.mts +3 -0
  29. package/dist/types.d.mts.map +1 -1
  30. package/dist/types.mjs.map +1 -1
  31. package/dist/utils/gas-fees.cjs +7 -0
  32. package/dist/utils/gas-fees.cjs.map +1 -1
  33. package/dist/utils/gas-fees.d.cts +1 -0
  34. package/dist/utils/gas-fees.d.cts.map +1 -1
  35. package/dist/utils/gas-fees.d.mts +1 -0
  36. package/dist/utils/gas-fees.d.mts.map +1 -1
  37. package/dist/utils/gas-fees.mjs +7 -0
  38. package/dist/utils/gas-fees.mjs.map +1 -1
  39. package/dist/utils/gas.cjs +2 -0
  40. package/dist/utils/gas.cjs.map +1 -1
  41. package/dist/utils/gas.d.cts +1 -0
  42. package/dist/utils/gas.d.cts.map +1 -1
  43. package/dist/utils/gas.d.mts +1 -0
  44. package/dist/utils/gas.d.mts.map +1 -1
  45. package/dist/utils/gas.mjs +2 -0
  46. package/dist/utils/gas.mjs.map +1 -1
  47. package/dist/utils/transaction.cjs +2 -0
  48. package/dist/utils/transaction.cjs.map +1 -1
  49. package/dist/utils/transaction.d.cts +1 -0
  50. package/dist/utils/transaction.d.cts.map +1 -1
  51. package/dist/utils/transaction.d.mts +1 -0
  52. package/dist/utils/transaction.d.mts.map +1 -1
  53. package/dist/utils/transaction.mjs +2 -0
  54. package/dist/utils/transaction.mjs.map +1 -1
  55. package/dist/utils/validation.cjs +8 -2
  56. package/dist/utils/validation.cjs.map +1 -1
  57. package/dist/utils/validation.d.cts +5 -0
  58. package/dist/utils/validation.d.cts.map +1 -1
  59. package/dist/utils/validation.d.mts +5 -0
  60. package/dist/utils/validation.d.mts.map +1 -1
  61. package/dist/utils/validation.mjs +8 -2
  62. package/dist/utils/validation.mjs.map +1 -1
  63. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"validation.cjs","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":";;;AACA,uDAW+B;AAC/B,6EAAmE;AACnE,2CAAoD;AAEpD,gDAA2C;AAW3C;;;GAGG;AACH,SAAgB,+BAA+B,CAC7C,OAAgC;IAEhC,MAAM,GAAG,GAAG,SAAS,EAAE,CAAC;IACxB,MAAM,eAAe,GAAG,qBAAqB,EAAE,CAAC;IAEhD,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;AAdD,8EAcC;AAED;;;;;GAKG;AACH,gFAAgF;AAChF,gEAAgE;AAChE,SAAS,QAAQ,CAAI,IAAa,EAAE,MAAiB,EAAE,OAAe;IACpE,IAAI,CAAC;QACH,IAAA,oBAAM,EAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,MAAM,GAAI,KAAqB;aAClC,QAAQ,EAAE;aACV,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE;YACf,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;gBACzB,OAAO,OAAO,CAAC,OAAO,CAAC;YACzB,CAAC;YAED,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,OAAO,CAAC,OAAO,EAAE,CAAC;QAC1D,CAAC,CAAC;aACD,IAAI,CAAC,IAAI,CAAC,CAAC;QAEd,MAAM,YAAY,GAAG,GAAG,OAAO,KAAK,MAAM,EAAE,CAAC;QAE7C,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC;IAChC,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,SAAS,SAAS;IAChB,OAAO,IAAA,oBAAM,EAAS,oBAAoB,EAAE,CAAC,KAAK,EAAE,EAAE,CACpD,IAAA,yBAAiB,EAAC,KAAK,CAAC,CACzB,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,SAAS,qBAAqB;IAC5B,OAAO,IAAA,oBAAM,EACX,0BAA0B,EAC1B,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,yBAAiB,EAAC,KAAK,CAAC,IAAI,KAAK,KAAK,uBAAW,CAC7D,CAAC;AACJ,CAAC","sourcesContent":["import type { Struct, StructError } from '@metamask/superstruct';\nimport {\n assert,\n boolean,\n define,\n enums,\n func,\n number,\n object,\n optional,\n refine,\n string,\n} from '@metamask/superstruct';\nimport { TransactionType } from '@metamask/transaction-controller';\nimport { isStrictHexString } from '@metamask/utils';\n\nimport { EMPTY_BYTES } from '../constants';\nimport type {\n PrepareUserOperationResponse,\n SignUserOperationResponse,\n UpdateUserOperationResponse,\n} from '../types';\nimport type {\n AddUserOperationOptions,\n AddUserOperationRequest,\n} from '../UserOperationController';\n\n/**\n * Validate a request to add a user operation.\n * @param request - The request to validate.\n */\nexport function validateAddUserOperationRequest(\n request: AddUserOperationRequest,\n) {\n const Hex = defineHex();\n const HexOrEmptyBytes = defineHexOrEmptyBytes();\n\n const ValidRequest = object({\n data: optional(HexOrEmptyBytes),\n from: Hex,\n maxFeePerGas: optional(Hex),\n maxPriorityFeePerGas: optional(Hex),\n to: optional(Hex),\n value: optional(Hex),\n });\n\n validate(request, ValidRequest, 'Invalid request to add user operation');\n}\n\n/**\n * Validate the options when adding a user operation.\n * @param options - The options to validate.\n */\nexport function validateAddUserOperationOptions(\n options: AddUserOperationOptions,\n) {\n const ValidOptions = object({\n networkClientId: string(),\n origin: string(),\n requireApproval: optional(boolean()),\n smartContractAccount: optional(\n object({\n prepareUserOperation: func(),\n updateUserOperation: func(),\n signUserOperation: func(),\n }),\n ),\n swaps: optional(\n object({\n approvalTxId: optional(string()),\n destinationTokenAddress: optional(string()),\n destinationTokenDecimals: optional(number()),\n destinationTokenSymbol: optional(string()),\n estimatedBaseFee: optional(string()),\n sourceTokenSymbol: optional(string()),\n swapMetaData: optional(object()),\n swapTokenValue: optional(string()),\n destinationTokenAmount: optional(string()),\n sourceTokenAddress: optional(string()),\n sourceTokenAmount: optional(string()),\n sourceTokenDecimals: optional(number()),\n swapAndSendRecipient: optional(string()),\n }),\n ),\n type: optional(enums(Object.values(TransactionType))),\n });\n\n validate(options, ValidOptions, 'Invalid options to add user operation');\n}\n\n/**\n * Validate the response from a smart contract account when preparing the user operation.\n * @param response - The response to validate.\n */\nexport function validatePrepareUserOperationResponse(\n response: PrepareUserOperationResponse,\n) {\n const Hex = defineHex();\n const HexOrEmptyBytes = defineHexOrEmptyBytes();\n\n const ValidResponse = refine(\n object({\n bundler: string(),\n callData: Hex,\n dummyPaymasterAndData: optional(HexOrEmptyBytes),\n dummySignature: optional(HexOrEmptyBytes),\n gas: optional(\n object({\n callGasLimit: Hex,\n preVerificationGas: Hex,\n verificationGasLimit: Hex,\n }),\n ),\n initCode: optional(HexOrEmptyBytes),\n nonce: Hex,\n sender: Hex,\n }),\n 'ValidPrepareUserOperationResponse',\n ({ gas, dummySignature }) => {\n if (!gas && (!dummySignature || dummySignature === EMPTY_BYTES)) {\n return 'Must specify dummySignature if not specifying gas';\n }\n\n /* istanbul ignore next */\n return true;\n },\n );\n\n validate(\n response,\n ValidResponse,\n 'Invalid response when preparing user operation',\n );\n}\n\n/**\n * Validate the response from a smart contract account when updating the user operation.\n * @param response - The response to validate.\n */\nexport function validateUpdateUserOperationResponse(\n response: UpdateUserOperationResponse,\n) {\n const ValidResponse = optional(\n object({\n paymasterAndData: optional(defineHexOrEmptyBytes()),\n callGasLimit: optional(defineHexOrEmptyBytes()),\n preVerificationGas: optional(defineHexOrEmptyBytes()),\n verificationGasLimit: optional(defineHexOrEmptyBytes()),\n }),\n );\n\n validate(\n response,\n ValidResponse,\n 'Invalid response when updating user operation',\n );\n}\n\n/**\n * Validate the response from a smart contract account when signing the user operation.\n * @param response - The response to validate.\n */\nexport function validateSignUserOperationResponse(\n response: SignUserOperationResponse,\n) {\n const Hex = defineHex();\n\n const ValidResponse = object({\n signature: Hex,\n });\n\n validate(\n response,\n ValidResponse,\n 'Invalid response when signing user operation',\n );\n}\n\n/**\n * Validate data against a struct.\n * @param data - The data to validate.\n * @param struct - The struct to validate against.\n * @param message - The message to throw if validation fails.\n */\n// TODO: Either fix this lint violation or explain why it's necessary to ignore.\n// eslint-disable-next-line @typescript-eslint/naming-convention\nfunction validate<T>(data: unknown, struct: Struct<T>, message: string) {\n try {\n assert(data, struct, message);\n } catch (error) {\n const causes = (error as StructError)\n .failures()\n .map((failure) => {\n if (!failure.path.length) {\n return failure.message;\n }\n\n return `${failure.path.join('.')} - ${failure.message}`;\n })\n .join('\\n');\n\n const finalMessage = `${message}\\n${causes}`;\n\n throw new Error(finalMessage);\n }\n}\n\n/**\n * Define the Hex type used by superstruct.\n * @returns The Hex superstruct type.\n */\nfunction defineHex() {\n return define<string>('Hexadecimal String', (value) =>\n isStrictHexString(value),\n );\n}\n\n/**\n * Define the HexOrEmptyBytes type used by superstruct.\n * @returns The HexOrEmptyBytes superstruct type.\n */\nfunction defineHexOrEmptyBytes() {\n return define<string>(\n 'Hexadecimal String or 0x',\n (value) => isStrictHexString(value) || value === EMPTY_BYTES,\n );\n}\n"]}
1
+ {"version":3,"file":"validation.cjs","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":";;;AACA,uDAW+B;AAC/B,6EAAmE;AACnE,2CAAoD;AAEpD,gDAA2C;AAW3C;;;;GAIG;AACH,SAAgB,+BAA+B,CAC7C,OAAgC;IAEhC,MAAM,GAAG,GAAG,SAAS,EAAE,CAAC;IACxB,MAAM,eAAe,GAAG,qBAAqB,EAAE,CAAC;IAEhD,MAAM,YAAY,GAAG,IAAA,oBAAM,EAAC;QAC1B,IAAI,EAAE,IAAA,sBAAQ,EAAC,eAAe,CAAC;QAC/B,IAAI,EAAE,GAAG;QACT,YAAY,EAAE,IAAA,sBAAQ,EAAC,GAAG,CAAC;QAC3B,oBAAoB,EAAE,IAAA,sBAAQ,EAAC,GAAG,CAAC;QACnC,EAAE,EAAE,IAAA,sBAAQ,EAAC,GAAG,CAAC;QACjB,KAAK,EAAE,IAAA,sBAAQ,EAAC,GAAG,CAAC;KACrB,CAAC,CAAC;IAEH,QAAQ,CAAC,OAAO,EAAE,YAAY,EAAE,uCAAuC,CAAC,CAAC;AAC3E,CAAC;AAhBD,0EAgBC;AAED;;;;GAIG;AACH,SAAgB,+BAA+B,CAC7C,OAAgC;IAEhC,MAAM,YAAY,GAAG,IAAA,oBAAM,EAAC;QAC1B,eAAe,EAAE,IAAA,oBAAM,GAAE;QACzB,M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C;QAEd,MAAM,YAAY,GAAG,GAAG,OAAO,KAAK,MAAM,EAAE,CAAC;QAE7C,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC;IAChC,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,SAAS,SAAS;IAChB,OAAO,IAAA,oBAAM,EAAS,oBAAoB,EAAE,CAAC,KAAK,EAAE,EAAE,CACpD,IAAA,yBAAiB,EAAC,KAAK,CAAC,CACzB,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,SAAS,qBAAqB;IAC5B,OAAO,IAAA,oBAAM,EACX,0BAA0B,EAC1B,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,yBAAiB,EAAC,KAAK,CAAC,IAAI,KAAK,KAAK,uBAAW,CAC7D,CAAC;AACJ,CAAC","sourcesContent":["import type { Struct, StructError } from '@metamask/superstruct';\nimport {\n assert,\n boolean,\n define,\n enums,\n func,\n number,\n object,\n optional,\n refine,\n string,\n} from '@metamask/superstruct';\nimport { TransactionType } from '@metamask/transaction-controller';\nimport { isStrictHexString } from '@metamask/utils';\n\nimport { EMPTY_BYTES } from '../constants';\nimport type {\n PrepareUserOperationResponse,\n SignUserOperationResponse,\n UpdateUserOperationResponse,\n} from '../types';\nimport type {\n AddUserOperationOptions,\n AddUserOperationRequest,\n} from '../UserOperationController';\n\n/**\n * Validate a request to add a user operation.\n *\n * @param request - The request to validate.\n */\nexport function validateAddUserOperationRequest(\n request: AddUserOperationRequest,\n) {\n const Hex = defineHex();\n const HexOrEmptyBytes = defineHexOrEmptyBytes();\n\n const ValidRequest = object({\n data: optional(HexOrEmptyBytes),\n from: Hex,\n maxFeePerGas: optional(Hex),\n maxPriorityFeePerGas: optional(Hex),\n to: optional(Hex),\n value: optional(Hex),\n });\n\n validate(request, ValidRequest, 'Invalid request to add user operation');\n}\n\n/**\n * Validate the options when adding a user operation.\n *\n * @param options - The options to validate.\n */\nexport function validateAddUserOperationOptions(\n options: AddUserOperationOptions,\n) {\n const ValidOptions = object({\n networkClientId: string(),\n origin: string(),\n requireApproval: optional(boolean()),\n smartContractAccount: optional(\n object({\n prepareUserOperation: func(),\n updateUserOperation: func(),\n signUserOperation: func(),\n }),\n ),\n swaps: optional(\n object({\n approvalTxId: optional(string()),\n destinationTokenAddress: optional(string()),\n destinationTokenDecimals: optional(number()),\n destinationTokenSymbol: optional(string()),\n estimatedBaseFee: optional(string()),\n sourceTokenSymbol: optional(string()),\n swapMetaData: optional(object()),\n swapTokenValue: optional(string()),\n destinationTokenAmount: optional(string()),\n sourceTokenAddress: optional(string()),\n sourceTokenAmount: optional(string()),\n sourceTokenDecimals: optional(number()),\n swapAndSendRecipient: optional(string()),\n }),\n ),\n type: optional(enums(Object.values(TransactionType))),\n });\n\n validate(options, ValidOptions, 'Invalid options to add user operation');\n}\n\n/**\n * Validate the response from a smart contract account when preparing the user operation.\n *\n * @param response - The response to validate.\n */\nexport function validatePrepareUserOperationResponse(\n response: PrepareUserOperationResponse,\n) {\n const Hex = defineHex();\n const HexOrEmptyBytes = defineHexOrEmptyBytes();\n\n const ValidResponse = refine(\n object({\n bundler: string(),\n callData: Hex,\n dummyPaymasterAndData: optional(HexOrEmptyBytes),\n dummySignature: optional(HexOrEmptyBytes),\n gas: optional(\n object({\n callGasLimit: Hex,\n preVerificationGas: Hex,\n verificationGasLimit: Hex,\n }),\n ),\n initCode: optional(HexOrEmptyBytes),\n nonce: Hex,\n sender: Hex,\n }),\n 'ValidPrepareUserOperationResponse',\n ({ gas, dummySignature }) => {\n if (!gas && (!dummySignature || dummySignature === EMPTY_BYTES)) {\n return 'Must specify dummySignature if not specifying gas';\n }\n\n /* istanbul ignore next */\n return true;\n },\n );\n\n validate(\n response,\n ValidResponse,\n 'Invalid response when preparing user operation',\n );\n}\n\n/**\n * Validate the response from a smart contract account when updating the user operation.\n *\n * @param response - The response to validate.\n */\nexport function validateUpdateUserOperationResponse(\n response: UpdateUserOperationResponse,\n) {\n const ValidResponse = optional(\n object({\n paymasterAndData: optional(defineHexOrEmptyBytes()),\n callGasLimit: optional(defineHexOrEmptyBytes()),\n preVerificationGas: optional(defineHexOrEmptyBytes()),\n verificationGasLimit: optional(defineHexOrEmptyBytes()),\n }),\n );\n\n validate(\n response,\n ValidResponse,\n 'Invalid response when updating user operation',\n );\n}\n\n/**\n * Validate the response from a smart contract account when signing the user operation.\n *\n * @param response - The response to validate.\n */\nexport function validateSignUserOperationResponse(\n response: SignUserOperationResponse,\n) {\n const Hex = defineHex();\n\n const ValidResponse = object({\n signature: Hex,\n });\n\n validate(\n response,\n ValidResponse,\n 'Invalid response when signing user operation',\n );\n}\n\n/**\n * Validate data against a struct.\n *\n * @param data - The data to validate.\n * @param struct - The struct to validate against.\n * @param message - The message to throw if validation fails.\n */\nfunction validate<T>(data: unknown, struct: Struct<T>, message: string) {\n try {\n assert(data, struct, message);\n } catch (error) {\n const causes = (error as StructError)\n .failures()\n .map((failure) => {\n if (!failure.path.length) {\n return failure.message;\n }\n\n return `${failure.path.join('.')} - ${failure.message}`;\n })\n .join('\\n');\n\n const finalMessage = `${message}\\n${causes}`;\n\n throw new Error(finalMessage);\n }\n}\n\n/**\n * Define the Hex type used by superstruct.\n *\n * @returns The Hex superstruct type.\n */\nfunction defineHex() {\n return define<string>('Hexadecimal String', (value) =>\n isStrictHexString(value),\n );\n}\n\n/**\n * Define the HexOrEmptyBytes type used by superstruct.\n *\n * @returns The HexOrEmptyBytes superstruct type.\n */\nfunction defineHexOrEmptyBytes() {\n return define<string>(\n 'Hexadecimal String or 0x',\n (value) => isStrictHexString(value) || value === EMPTY_BYTES,\n );\n}\n"]}
@@ -2,26 +2,31 @@ import type { PrepareUserOperationResponse, SignUserOperationResponse, UpdateUse
2
2
  import type { AddUserOperationOptions, AddUserOperationRequest } from "../UserOperationController.cjs";
3
3
  /**
4
4
  * Validate a request to add a user operation.
5
+ *
5
6
  * @param request - The request to validate.
6
7
  */
7
8
  export declare function validateAddUserOperationRequest(request: AddUserOperationRequest): void;
8
9
  /**
9
10
  * Validate the options when adding a user operation.
11
+ *
10
12
  * @param options - The options to validate.
11
13
  */
12
14
  export declare function validateAddUserOperationOptions(options: AddUserOperationOptions): void;
13
15
  /**
14
16
  * Validate the response from a smart contract account when preparing the user operation.
17
+ *
15
18
  * @param response - The response to validate.
16
19
  */
17
20
  export declare function validatePrepareUserOperationResponse(response: PrepareUserOperationResponse): void;
18
21
  /**
19
22
  * Validate the response from a smart contract account when updating the user operation.
23
+ *
20
24
  * @param response - The response to validate.
21
25
  */
22
26
  export declare function validateUpdateUserOperationResponse(response: UpdateUserOperationResponse): void;
23
27
  /**
24
28
  * Validate the response from a smart contract account when signing the user operation.
29
+ *
25
30
  * @param response - The response to validate.
26
31
  */
27
32
  export declare function validateSignUserOperationResponse(response: SignUserOperationResponse): void;
@@ -1 +1 @@
1
- {"version":3,"file":"validation.d.cts","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EACV,4BAA4B,EAC5B,yBAAyB,EACzB,2BAA2B,EAC5B,qBAAiB;AAClB,OAAO,KAAK,EACV,uBAAuB,EACvB,uBAAuB,EACxB,uCAAmC;AAEpC;;;GAGG;AACH,wBAAgB,+BAA+B,CAC7C,OAAO,EAAE,uBAAuB,QAejC;AAED;;;GAGG;AACH,wBAAgB,+BAA+B,CAC7C,OAAO,EAAE,uBAAuB,QAkCjC;AAED;;;GAGG;AACH,wBAAgB,oCAAoC,CAClD,QAAQ,EAAE,4BAA4B,QAsCvC;AAED;;;GAGG;AACH,wBAAgB,mCAAmC,CACjD,QAAQ,EAAE,2BAA2B,QAgBtC;AAED;;;GAGG;AACH,wBAAgB,iCAAiC,CAC/C,QAAQ,EAAE,yBAAyB,QAapC"}
1
+ {"version":3,"file":"validation.d.cts","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EACV,4BAA4B,EAC5B,yBAAyB,EACzB,2BAA2B,EAC5B,qBAAiB;AAClB,OAAO,KAAK,EACV,uBAAuB,EACvB,uBAAuB,EACxB,uCAAmC;AAEpC;;;;GAIG;AACH,wBAAgB,+BAA+B,CAC7C,OAAO,EAAE,uBAAuB,QAejC;AAED;;;;GAIG;AACH,wBAAgB,+BAA+B,CAC7C,OAAO,EAAE,uBAAuB,QAkCjC;AAED;;;;GAIG;AACH,wBAAgB,oCAAoC,CAClD,QAAQ,EAAE,4BAA4B,QAsCvC;AAED;;;;GAIG;AACH,wBAAgB,mCAAmC,CACjD,QAAQ,EAAE,2BAA2B,QAgBtC;AAED;;;;GAIG;AACH,wBAAgB,iCAAiC,CAC/C,QAAQ,EAAE,yBAAyB,QAapC"}
@@ -2,26 +2,31 @@ import type { PrepareUserOperationResponse, SignUserOperationResponse, UpdateUse
2
2
  import type { AddUserOperationOptions, AddUserOperationRequest } from "../UserOperationController.mjs";
3
3
  /**
4
4
  * Validate a request to add a user operation.
5
+ *
5
6
  * @param request - The request to validate.
6
7
  */
7
8
  export declare function validateAddUserOperationRequest(request: AddUserOperationRequest): void;
8
9
  /**
9
10
  * Validate the options when adding a user operation.
11
+ *
10
12
  * @param options - The options to validate.
11
13
  */
12
14
  export declare function validateAddUserOperationOptions(options: AddUserOperationOptions): void;
13
15
  /**
14
16
  * Validate the response from a smart contract account when preparing the user operation.
17
+ *
15
18
  * @param response - The response to validate.
16
19
  */
17
20
  export declare function validatePrepareUserOperationResponse(response: PrepareUserOperationResponse): void;
18
21
  /**
19
22
  * Validate the response from a smart contract account when updating the user operation.
23
+ *
20
24
  * @param response - The response to validate.
21
25
  */
22
26
  export declare function validateUpdateUserOperationResponse(response: UpdateUserOperationResponse): void;
23
27
  /**
24
28
  * Validate the response from a smart contract account when signing the user operation.
29
+ *
25
30
  * @param response - The response to validate.
26
31
  */
27
32
  export declare function validateSignUserOperationResponse(response: SignUserOperationResponse): void;
@@ -1 +1 @@
1
- {"version":3,"file":"validation.d.mts","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EACV,4BAA4B,EAC5B,yBAAyB,EACzB,2BAA2B,EAC5B,qBAAiB;AAClB,OAAO,KAAK,EACV,uBAAuB,EACvB,uBAAuB,EACxB,uCAAmC;AAEpC;;;GAGG;AACH,wBAAgB,+BAA+B,CAC7C,OAAO,EAAE,uBAAuB,QAejC;AAED;;;GAGG;AACH,wBAAgB,+BAA+B,CAC7C,OAAO,EAAE,uBAAuB,QAkCjC;AAED;;;GAGG;AACH,wBAAgB,oCAAoC,CAClD,QAAQ,EAAE,4BAA4B,QAsCvC;AAED;;;GAGG;AACH,wBAAgB,mCAAmC,CACjD,QAAQ,EAAE,2BAA2B,QAgBtC;AAED;;;GAGG;AACH,wBAAgB,iCAAiC,CAC/C,QAAQ,EAAE,yBAAyB,QAapC"}
1
+ {"version":3,"file":"validation.d.mts","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EACV,4BAA4B,EAC5B,yBAAyB,EACzB,2BAA2B,EAC5B,qBAAiB;AAClB,OAAO,KAAK,EACV,uBAAuB,EACvB,uBAAuB,EACxB,uCAAmC;AAEpC;;;;GAIG;AACH,wBAAgB,+BAA+B,CAC7C,OAAO,EAAE,uBAAuB,QAejC;AAED;;;;GAIG;AACH,wBAAgB,+BAA+B,CAC7C,OAAO,EAAE,uBAAuB,QAkCjC;AAED;;;;GAIG;AACH,wBAAgB,oCAAoC,CAClD,QAAQ,EAAE,4BAA4B,QAsCvC;AAED;;;;GAIG;AACH,wBAAgB,mCAAmC,CACjD,QAAQ,EAAE,2BAA2B,QAgBtC;AAED;;;;GAIG;AACH,wBAAgB,iCAAiC,CAC/C,QAAQ,EAAE,yBAAyB,QAapC"}
@@ -4,6 +4,7 @@ import { isStrictHexString } from "@metamask/utils";
4
4
  import { EMPTY_BYTES } from "../constants.mjs";
5
5
  /**
6
6
  * Validate a request to add a user operation.
7
+ *
7
8
  * @param request - The request to validate.
8
9
  */
9
10
  export function validateAddUserOperationRequest(request) {
@@ -21,6 +22,7 @@ export function validateAddUserOperationRequest(request) {
21
22
  }
22
23
  /**
23
24
  * Validate the options when adding a user operation.
25
+ *
24
26
  * @param options - The options to validate.
25
27
  */
26
28
  export function validateAddUserOperationOptions(options) {
@@ -54,6 +56,7 @@ export function validateAddUserOperationOptions(options) {
54
56
  }
55
57
  /**
56
58
  * Validate the response from a smart contract account when preparing the user operation.
59
+ *
57
60
  * @param response - The response to validate.
58
61
  */
59
62
  export function validatePrepareUserOperationResponse(response) {
@@ -83,6 +86,7 @@ export function validatePrepareUserOperationResponse(response) {
83
86
  }
84
87
  /**
85
88
  * Validate the response from a smart contract account when updating the user operation.
89
+ *
86
90
  * @param response - The response to validate.
87
91
  */
88
92
  export function validateUpdateUserOperationResponse(response) {
@@ -96,6 +100,7 @@ export function validateUpdateUserOperationResponse(response) {
96
100
  }
97
101
  /**
98
102
  * Validate the response from a smart contract account when signing the user operation.
103
+ *
99
104
  * @param response - The response to validate.
100
105
  */
101
106
  export function validateSignUserOperationResponse(response) {
@@ -107,12 +112,11 @@ export function validateSignUserOperationResponse(response) {
107
112
  }
108
113
  /**
109
114
  * Validate data against a struct.
115
+ *
110
116
  * @param data - The data to validate.
111
117
  * @param struct - The struct to validate against.
112
118
  * @param message - The message to throw if validation fails.
113
119
  */
114
- // TODO: Either fix this lint violation or explain why it's necessary to ignore.
115
- // eslint-disable-next-line @typescript-eslint/naming-convention
116
120
  function validate(data, struct, message) {
117
121
  try {
118
122
  assert(data, struct, message);
@@ -133,6 +137,7 @@ function validate(data, struct, message) {
133
137
  }
134
138
  /**
135
139
  * Define the Hex type used by superstruct.
140
+ *
136
141
  * @returns The Hex superstruct type.
137
142
  */
138
143
  function defineHex() {
@@ -140,6 +145,7 @@ function defineHex() {
140
145
  }
141
146
  /**
142
147
  * Define the HexOrEmptyBytes type used by superstruct.
148
+ *
143
149
  * @returns The HexOrEmptyBytes superstruct type.
144
150
  */
145
151
  function defineHexOrEmptyBytes() {
@@ -1 +1 @@
1
- {"version":3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,gFAAgF;AAChF,gEAAgE;AAChE,SAAS,QAAQ,CAAI,IAAa,EAAE,MAAiB,EAAE,OAAe;IACpE,IAAI,CAAC;QACH,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,MAAM,GAAI,KAAqB;aAClC,QAAQ,EAAE;aACV,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE;YACf,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;gBACzB,OAAO,OAAO,CAAC,OAAO,CAAC;YACzB,CAAC;YAED,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,OAAO,CAAC,OAAO,EAAE,CAAC;QAC1D,CAAC,CAAC;aACD,IAAI,CAAC,IAAI,CAAC,CAAC;QAEd,MAAM,YAAY,GAAG,GAAG,OAAO,KAAK,MAAM,EAAE,CAAC;QAE7C,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC;IAChC,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,SAAS,SAAS;IAChB,OAAO,MAAM,CAAS,oBAAoB,EAAE,CAAC,KAAK,EAAE,EAAE,CACpD,iBAAiB,CAAC,KAAK,CAAC,CACzB,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,SAAS,qBAAqB;IAC5B,OAAO,MAAM,CACX,0BAA0B,EAC1B,CAAC,KAAK,EAAE,EAAE,CAAC,iBAAiB,CAAC,KAAK,CAAC,IAAI,KAAK,KAAK,WAAW,CAC7D,CAAC;AACJ,CAAC","sourcesContent":["import type { Struct, StructError } from '@metamask/superstruct';\nimport {\n assert,\n boolean,\n define,\n enums,\n func,\n number,\n object,\n optional,\n refine,\n string,\n} from '@metamask/superstruct';\nimport { TransactionType } from '@metamask/transaction-controller';\nimport { isStrictHexString } from '@metamask/utils';\n\nimport { EMPTY_BYTES } from '../constants';\nimport type {\n PrepareUserOperationResponse,\n SignUserOperationResponse,\n UpdateUserOperationResponse,\n} from '../types';\nimport type {\n AddUserOperationOptions,\n AddUserOperationRequest,\n} from '../UserOperationController';\n\n/**\n * Validate a request to add a user operation.\n * @param request - The request to validate.\n */\nexport function validateAddUserOperationRequest(\n request: AddUserOperationRequest,\n) {\n const Hex = defineHex();\n const HexOrEmptyBytes = defineHexOrEmptyBytes();\n\n const ValidRequest = object({\n data: optional(HexOrEmptyBytes),\n from: Hex,\n maxFeePerGas: optional(Hex),\n maxPriorityFeePerGas: optional(Hex),\n to: optional(Hex),\n value: optional(Hex),\n });\n\n validate(request, ValidRequest, 'Invalid request to add user operation');\n}\n\n/**\n * Validate the options when adding a user operation.\n * @param options - The options to validate.\n */\nexport function validateAddUserOperationOptions(\n options: AddUserOperationOptions,\n) {\n const ValidOptions = object({\n networkClientId: string(),\n origin: string(),\n requireApproval: optional(boolean()),\n smartContractAccount: optional(\n object({\n prepareUserOperation: func(),\n updateUserOperation: func(),\n signUserOperation: func(),\n }),\n ),\n swaps: optional(\n object({\n approvalTxId: optional(string()),\n destinationTokenAddress: optional(string()),\n destinationTokenDecimals: optional(number()),\n destinationTokenSymbol: optional(string()),\n estimatedBaseFee: optional(string()),\n sourceTokenSymbol: optional(string()),\n swapMetaData: optional(object()),\n swapTokenValue: optional(string()),\n destinationTokenAmount: optional(string()),\n sourceTokenAddress: optional(string()),\n sourceTokenAmount: optional(string()),\n sourceTokenDecimals: optional(number()),\n swapAndSendRecipient: optional(string()),\n }),\n ),\n type: optional(enums(Object.values(TransactionType))),\n });\n\n validate(options, ValidOptions, 'Invalid options to add user operation');\n}\n\n/**\n * Validate the response from a smart contract account when preparing the user operation.\n * @param response - The response to validate.\n */\nexport function validatePrepareUserOperationResponse(\n response: PrepareUserOperationResponse,\n) {\n const Hex = defineHex();\n const HexOrEmptyBytes = defineHexOrEmptyBytes();\n\n const ValidResponse = refine(\n object({\n bundler: string(),\n callData: Hex,\n dummyPaymasterAndData: optional(HexOrEmptyBytes),\n dummySignature: optional(HexOrEmptyBytes),\n gas: optional(\n object({\n callGasLimit: Hex,\n preVerificationGas: Hex,\n verificationGasLimit: Hex,\n }),\n ),\n initCode: optional(HexOrEmptyBytes),\n nonce: Hex,\n sender: Hex,\n }),\n 'ValidPrepareUserOperationResponse',\n ({ gas, dummySignature }) => {\n if (!gas && (!dummySignature || dummySignature === EMPTY_BYTES)) {\n return 'Must specify dummySignature if not specifying gas';\n }\n\n /* istanbul ignore next */\n return true;\n },\n );\n\n validate(\n response,\n ValidResponse,\n 'Invalid response when preparing user operation',\n );\n}\n\n/**\n * Validate the response from a smart contract account when updating the user operation.\n * @param response - The response to validate.\n */\nexport function validateUpdateUserOperationResponse(\n response: UpdateUserOperationResponse,\n) {\n const ValidResponse = optional(\n object({\n paymasterAndData: optional(defineHexOrEmptyBytes()),\n callGasLimit: optional(defineHexOrEmptyBytes()),\n preVerificationGas: optional(defineHexOrEmptyBytes()),\n verificationGasLimit: optional(defineHexOrEmptyBytes()),\n }),\n );\n\n validate(\n response,\n ValidResponse,\n 'Invalid response when updating user operation',\n );\n}\n\n/**\n * Validate the response from a smart contract account when signing the user operation.\n * @param response - The response to validate.\n */\nexport function validateSignUserOperationResponse(\n response: SignUserOperationResponse,\n) {\n const Hex = defineHex();\n\n const ValidResponse = object({\n signature: Hex,\n });\n\n validate(\n response,\n ValidResponse,\n 'Invalid response when signing user operation',\n );\n}\n\n/**\n * Validate data against a struct.\n * @param data - The data to validate.\n * @param struct - The struct to validate against.\n * @param message - The message to throw if validation fails.\n */\n// TODO: Either fix this lint violation or explain why it's necessary to ignore.\n// eslint-disable-next-line @typescript-eslint/naming-convention\nfunction validate<T>(data: unknown, struct: Struct<T>, message: string) {\n try {\n assert(data, struct, message);\n } catch (error) {\n const causes = (error as StructError)\n .failures()\n .map((failure) => {\n if (!failure.path.length) {\n return failure.message;\n }\n\n return `${failure.path.join('.')} - ${failure.message}`;\n })\n .join('\\n');\n\n const finalMessage = `${message}\\n${causes}`;\n\n throw new Error(finalMessage);\n }\n}\n\n/**\n * Define the Hex type used by superstruct.\n * @returns The Hex superstruct type.\n */\nfunction defineHex() {\n return define<string>('Hexadecimal String', (value) =>\n isStrictHexString(value),\n );\n}\n\n/**\n * Define the HexOrEmptyBytes type used by superstruct.\n * @returns The HexOrEmptyBytes superstruct type.\n */\nfunction defineHexOrEmptyBytes() {\n return define<string>(\n 'Hexadecimal String or 0x',\n (value) => isStrictHexString(value) || value === EMPTY_BYTES,\n );\n}\n"]}
1
+ {"version":3,"file":"validation.mjs","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"AACA,OAAO,EACL,MAAM,EACN,OAAO,EACP,MAAM,EACN,KAAK,EACL,IAAI,EACJ,MAAM,EACN,MAAM,EACN,QAAQ,EACR,MAAM,EACN,MAAM,EACP,8BAA8B;AAC/B,OAAO,EAAE,eAAe,EAAE,yCAAyC;AACnE,OAAO,EAAE,iBAAiB,EAAE,wBAAwB;AAEpD,OAAO,EAAE,WAAW,EAAE,yBAAqB;AAW3C;;;;GAIG;AACH,MAAM,UAAU,+BAA+B,CAC7C,OAAgC;IAEhC,MAAM,GAAG,GAAG,SAAS,EAAE,CAAC;IACxB,MAAM,eAAe,GAAG,qBAAqB,EAAE,CAAC;IAEhD,MAAM,YAAY,GAAG,MAAM,CAAC;QAC1B,IAAI,EAAE,QAAQ,CAAC,eAAe,CAAC;QAC/B,IAAI,EAAE,GAAG;QACT,YAAY,EAAE,QAAQ,CAAC,GAAG,CAAC;QAC3B,oBAAoB,EAAE,QAAQ,CAAC,GAAG,CAAC;QACnC,EAAE,EAAE,QAAQ,CAAC,GAAG,CAAC;QACjB,KAAK,EAAE,QAAQ,CAAC,GAAG,CAAC;KACrB,CAAC,CAAC;IAEH,QAAQ,CAAC,OAAO,EAAE,YAAY,EAAE,uCAAuC,CAAC,CAAC;AAC3E,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,+BAA+B,CAC7C,OAAgC;IAEhC,MAAM,Y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EAAE,CAAC,iBAAiB,CAAC,KAAK,CAAC,IAAI,KAAK,KAAK,WAAW,CAC7D,CAAC;AACJ,CAAC","sourcesContent":["import type { Struct, StructError } from '@metamask/superstruct';\nimport {\n assert,\n boolean,\n define,\n enums,\n func,\n number,\n object,\n optional,\n refine,\n string,\n} from '@metamask/superstruct';\nimport { TransactionType } from '@metamask/transaction-controller';\nimport { isStrictHexString } from '@metamask/utils';\n\nimport { EMPTY_BYTES } from '../constants';\nimport type {\n PrepareUserOperationResponse,\n SignUserOperationResponse,\n UpdateUserOperationResponse,\n} from '../types';\nimport type {\n AddUserOperationOptions,\n AddUserOperationRequest,\n} from '../UserOperationController';\n\n/**\n * Validate a request to add a user operation.\n *\n * @param request - The request to validate.\n */\nexport function validateAddUserOperationRequest(\n request: AddUserOperationRequest,\n) {\n const Hex = defineHex();\n const HexOrEmptyBytes = defineHexOrEmptyBytes();\n\n const ValidRequest = object({\n data: optional(HexOrEmptyBytes),\n from: Hex,\n maxFeePerGas: optional(Hex),\n maxPriorityFeePerGas: optional(Hex),\n to: optional(Hex),\n value: optional(Hex),\n });\n\n validate(request, ValidRequest, 'Invalid request to add user operation');\n}\n\n/**\n * Validate the options when adding a user operation.\n *\n * @param options - The options to validate.\n */\nexport function validateAddUserOperationOptions(\n options: AddUserOperationOptions,\n) {\n const ValidOptions = object({\n networkClientId: string(),\n origin: string(),\n requireApproval: optional(boolean()),\n smartContractAccount: optional(\n object({\n prepareUserOperation: func(),\n updateUserOperation: func(),\n signUserOperation: func(),\n }),\n ),\n swaps: optional(\n object({\n approvalTxId: optional(string()),\n destinationTokenAddress: optional(string()),\n destinationTokenDecimals: optional(number()),\n destinationTokenSymbol: optional(string()),\n estimatedBaseFee: optional(string()),\n sourceTokenSymbol: optional(string()),\n swapMetaData: optional(object()),\n swapTokenValue: optional(string()),\n destinationTokenAmount: optional(string()),\n sourceTokenAddress: optional(string()),\n sourceTokenAmount: optional(string()),\n sourceTokenDecimals: optional(number()),\n swapAndSendRecipient: optional(string()),\n }),\n ),\n type: optional(enums(Object.values(TransactionType))),\n });\n\n validate(options, ValidOptions, 'Invalid options to add user operation');\n}\n\n/**\n * Validate the response from a smart contract account when preparing the user operation.\n *\n * @param response - The response to validate.\n */\nexport function validatePrepareUserOperationResponse(\n response: PrepareUserOperationResponse,\n) {\n const Hex = defineHex();\n const HexOrEmptyBytes = defineHexOrEmptyBytes();\n\n const ValidResponse = refine(\n object({\n bundler: string(),\n callData: Hex,\n dummyPaymasterAndData: optional(HexOrEmptyBytes),\n dummySignature: optional(HexOrEmptyBytes),\n gas: optional(\n object({\n callGasLimit: Hex,\n preVerificationGas: Hex,\n verificationGasLimit: Hex,\n }),\n ),\n initCode: optional(HexOrEmptyBytes),\n nonce: Hex,\n sender: Hex,\n }),\n 'ValidPrepareUserOperationResponse',\n ({ gas, dummySignature }) => {\n if (!gas && (!dummySignature || dummySignature === EMPTY_BYTES)) {\n return 'Must specify dummySignature if not specifying gas';\n }\n\n /* istanbul ignore next */\n return true;\n },\n );\n\n validate(\n response,\n ValidResponse,\n 'Invalid response when preparing user operation',\n );\n}\n\n/**\n * Validate the response from a smart contract account when updating the user operation.\n *\n * @param response - The response to validate.\n */\nexport function validateUpdateUserOperationResponse(\n response: UpdateUserOperationResponse,\n) {\n const ValidResponse = optional(\n object({\n paymasterAndData: optional(defineHexOrEmptyBytes()),\n callGasLimit: optional(defineHexOrEmptyBytes()),\n preVerificationGas: optional(defineHexOrEmptyBytes()),\n verificationGasLimit: optional(defineHexOrEmptyBytes()),\n }),\n );\n\n validate(\n response,\n ValidResponse,\n 'Invalid response when updating user operation',\n );\n}\n\n/**\n * Validate the response from a smart contract account when signing the user operation.\n *\n * @param response - The response to validate.\n */\nexport function validateSignUserOperationResponse(\n response: SignUserOperationResponse,\n) {\n const Hex = defineHex();\n\n const ValidResponse = object({\n signature: Hex,\n });\n\n validate(\n response,\n ValidResponse,\n 'Invalid response when signing user operation',\n );\n}\n\n/**\n * Validate data against a struct.\n *\n * @param data - The data to validate.\n * @param struct - The struct to validate against.\n * @param message - The message to throw if validation fails.\n */\nfunction validate<T>(data: unknown, struct: Struct<T>, message: string) {\n try {\n assert(data, struct, message);\n } catch (error) {\n const causes = (error as StructError)\n .failures()\n .map((failure) => {\n if (!failure.path.length) {\n return failure.message;\n }\n\n return `${failure.path.join('.')} - ${failure.message}`;\n })\n .join('\\n');\n\n const finalMessage = `${message}\\n${causes}`;\n\n throw new Error(finalMessage);\n }\n}\n\n/**\n * Define the Hex type used by superstruct.\n *\n * @returns The Hex superstruct type.\n */\nfunction defineHex() {\n return define<string>('Hexadecimal String', (value) =>\n isStrictHexString(value),\n );\n}\n\n/**\n * Define the HexOrEmptyBytes type used by superstruct.\n *\n * @returns The HexOrEmptyBytes superstruct type.\n */\nfunction defineHexOrEmptyBytes() {\n return define<string>(\n 'Hexadecimal String or 0x',\n (value) => isStrictHexString(value) || value === EMPTY_BYTES,\n );\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/user-operation-controller",
3
- "version": "40.0.0-preview-d4351f75",
3
+ "version": "40.0.0-preview-bf3ab7d",
4
4
  "description": "Creates user operations and manages their life cycle",
5
5
  "keywords": [
6
6
  "MetaMask",