@metamask-previews/user-operation-controller 40.0.0-preview-9941fe9 → 40.0.0-preview-ba016213

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 +4 -0
  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 +4 -0
  6. package/dist/UserOperationController.mjs.map +1 -1
  7. package/dist/helpers/Bundler.cjs +5 -3
  8. package/dist/helpers/Bundler.cjs.map +1 -1
  9. package/dist/helpers/Bundler.d.cts +0 -2
  10. package/dist/helpers/Bundler.d.cts.map +1 -1
  11. package/dist/helpers/Bundler.d.mts +0 -2
  12. package/dist/helpers/Bundler.d.mts.map +1 -1
  13. package/dist/helpers/Bundler.mjs +5 -3
  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 +0 -3
  27. package/dist/types.d.cts.map +1 -1
  28. package/dist/types.d.mts +0 -3
  29. package/dist/types.d.mts.map +1 -1
  30. package/dist/types.mjs.map +1 -1
  31. package/dist/utils/gas-fees.cjs +0 -7
  32. package/dist/utils/gas-fees.cjs.map +1 -1
  33. package/dist/utils/gas-fees.d.cts +0 -1
  34. package/dist/utils/gas-fees.d.cts.map +1 -1
  35. package/dist/utils/gas-fees.d.mts +0 -1
  36. package/dist/utils/gas-fees.d.mts.map +1 -1
  37. package/dist/utils/gas-fees.mjs +0 -7
  38. package/dist/utils/gas-fees.mjs.map +1 -1
  39. package/dist/utils/gas.cjs +0 -2
  40. package/dist/utils/gas.cjs.map +1 -1
  41. package/dist/utils/gas.d.cts +0 -1
  42. package/dist/utils/gas.d.cts.map +1 -1
  43. package/dist/utils/gas.d.mts +0 -1
  44. package/dist/utils/gas.d.mts.map +1 -1
  45. package/dist/utils/gas.mjs +0 -2
  46. package/dist/utils/gas.mjs.map +1 -1
  47. package/dist/utils/transaction.cjs +0 -2
  48. package/dist/utils/transaction.cjs.map +1 -1
  49. package/dist/utils/transaction.d.cts +0 -1
  50. package/dist/utils/transaction.d.cts.map +1 -1
  51. package/dist/utils/transaction.d.mts +0 -1
  52. package/dist/utils/transaction.d.mts.map +1 -1
  53. package/dist/utils/transaction.mjs +0 -2
  54. package/dist/utils/transaction.mjs.map +1 -1
  55. package/dist/utils/validation.cjs +2 -8
  56. package/dist/utils/validation.cjs.map +1 -1
  57. package/dist/utils/validation.d.cts +0 -5
  58. package/dist/utils/validation.d.cts.map +1 -1
  59. package/dist/utils/validation.d.mts +0 -5
  60. package/dist/utils/validation.d.mts.map +1 -1
  61. package/dist/utils/validation.mjs +2 -8
  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;;;;GAIG;AACH,SAAgB,+BAA+B,CAC7C,OAAgC;IAEhC,MAAM,GAAG,GAAG,SAAS,EAAE,CAAC;IACxB,MAAM,eAAe,GAAG,qBAAqB,EAAE,CAAC;IAEhD,MA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AC;AAdD,8EAcC;AAED;;;;;;GAMG;AACH,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;;;;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"]}
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,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;;;GAGG;AACH,SAAgB,+BAA+B,CAC7C,OAAgC;IAEhC,MAAM,YAAY,GAAG,IAAA,oBAAM,EAAC;QAC1B,eAAe,EAAE,IAAA,oBAAM,GAAE;QACzB,MAAM,EAAE,IAAA,oBAAM,GAAE;QAChB,eAAe,EAAE,IAAA,sBAAQ,EA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AK,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"]}
@@ -2,31 +2,26 @@ 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
- *
6
5
  * @param request - The request to validate.
7
6
  */
8
7
  export declare function validateAddUserOperationRequest(request: AddUserOperationRequest): void;
9
8
  /**
10
9
  * Validate the options when adding a user operation.
11
- *
12
10
  * @param options - The options to validate.
13
11
  */
14
12
  export declare function validateAddUserOperationOptions(options: AddUserOperationOptions): void;
15
13
  /**
16
14
  * Validate the response from a smart contract account when preparing the user operation.
17
- *
18
15
  * @param response - The response to validate.
19
16
  */
20
17
  export declare function validatePrepareUserOperationResponse(response: PrepareUserOperationResponse): void;
21
18
  /**
22
19
  * Validate the response from a smart contract account when updating the user operation.
23
- *
24
20
  * @param response - The response to validate.
25
21
  */
26
22
  export declare function validateUpdateUserOperationResponse(response: UpdateUserOperationResponse): void;
27
23
  /**
28
24
  * Validate the response from a smart contract account when signing the user operation.
29
- *
30
25
  * @param response - The response to validate.
31
26
  */
32
27
  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;;;;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"}
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"}
@@ -2,31 +2,26 @@ 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
- *
6
5
  * @param request - The request to validate.
7
6
  */
8
7
  export declare function validateAddUserOperationRequest(request: AddUserOperationRequest): void;
9
8
  /**
10
9
  * Validate the options when adding a user operation.
11
- *
12
10
  * @param options - The options to validate.
13
11
  */
14
12
  export declare function validateAddUserOperationOptions(options: AddUserOperationOptions): void;
15
13
  /**
16
14
  * Validate the response from a smart contract account when preparing the user operation.
17
- *
18
15
  * @param response - The response to validate.
19
16
  */
20
17
  export declare function validatePrepareUserOperationResponse(response: PrepareUserOperationResponse): void;
21
18
  /**
22
19
  * Validate the response from a smart contract account when updating the user operation.
23
- *
24
20
  * @param response - The response to validate.
25
21
  */
26
22
  export declare function validateUpdateUserOperationResponse(response: UpdateUserOperationResponse): void;
27
23
  /**
28
24
  * Validate the response from a smart contract account when signing the user operation.
29
- *
30
25
  * @param response - The response to validate.
31
26
  */
32
27
  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;;;;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"}
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"}
@@ -4,7 +4,6 @@ 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
- *
8
7
  * @param request - The request to validate.
9
8
  */
10
9
  export function validateAddUserOperationRequest(request) {
@@ -22,7 +21,6 @@ export function validateAddUserOperationRequest(request) {
22
21
  }
23
22
  /**
24
23
  * Validate the options when adding a user operation.
25
- *
26
24
  * @param options - The options to validate.
27
25
  */
28
26
  export function validateAddUserOperationOptions(options) {
@@ -56,7 +54,6 @@ export function validateAddUserOperationOptions(options) {
56
54
  }
57
55
  /**
58
56
  * Validate the response from a smart contract account when preparing the user operation.
59
- *
60
57
  * @param response - The response to validate.
61
58
  */
62
59
  export function validatePrepareUserOperationResponse(response) {
@@ -86,7 +83,6 @@ export function validatePrepareUserOperationResponse(response) {
86
83
  }
87
84
  /**
88
85
  * Validate the response from a smart contract account when updating the user operation.
89
- *
90
86
  * @param response - The response to validate.
91
87
  */
92
88
  export function validateUpdateUserOperationResponse(response) {
@@ -100,7 +96,6 @@ export function validateUpdateUserOperationResponse(response) {
100
96
  }
101
97
  /**
102
98
  * Validate the response from a smart contract account when signing the user operation.
103
- *
104
99
  * @param response - The response to validate.
105
100
  */
106
101
  export function validateSignUserOperationResponse(response) {
@@ -112,11 +107,12 @@ export function validateSignUserOperationResponse(response) {
112
107
  }
113
108
  /**
114
109
  * Validate data against a struct.
115
- *
116
110
  * @param data - The data to validate.
117
111
  * @param struct - The struct to validate against.
118
112
  * @param message - The message to throw if validation fails.
119
113
  */
114
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
115
+ // eslint-disable-next-line @typescript-eslint/naming-convention
120
116
  function validate(data, struct, message) {
121
117
  try {
122
118
  assert(data, struct, message);
@@ -137,7 +133,6 @@ function validate(data, struct, message) {
137
133
  }
138
134
  /**
139
135
  * Define the Hex type used by superstruct.
140
- *
141
136
  * @returns The Hex superstruct type.
142
137
  */
143
138
  function defineHex() {
@@ -145,7 +140,6 @@ function defineHex() {
145
140
  }
146
141
  /**
147
142
  * Define the HexOrEmptyBytes type used by superstruct.
148
- *
149
143
  * @returns The HexOrEmptyBytes superstruct type.
150
144
  */
151
145
  function defineHexOrEmptyBytes() {
@@ -1 +1 @@
1
- {"version":3,"file":"validation.mjs","sourceRoot":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AAI,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;;;;GAIG;AACH,SAAS,SAAS;IAChB,OAAO,MAAM,CAAS,oBAAoB,EAAE,CAAC,KAAK,EAAE,EAAE,CACpD,iBAAiB,CAAC,KAAK,CAAC,CACzB,CAAC;AACJ,CAAC;AAED;;;;GAIG;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 *\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"]}
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;;;GAGG;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;;;GAGG;AACH,MAAM,UAAU,+BAA+B,CAC7C,OAAgC;IAEhC,MAAM,YAAY,GAAG,MAAM,CAAC;QAC1B,eAAe,EAAE,MAAM,EAAE;QACzB,MAAM,EAAE,MAAM,EAAE;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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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/user-operation-controller",
3
- "version": "40.0.0-preview-9941fe9",
3
+ "version": "40.0.0-preview-ba016213",
4
4
  "description": "Creates user operations and manages their life cycle",
5
5
  "keywords": [
6
6
  "MetaMask",