@metamask/snaps-rpc-methods 9.1.4 → 10.0.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 (140) hide show
  1. package/CHANGELOG.md +18 -1
  2. package/dist/{chunk-KIXPIIY5.mjs → chunk-2RDYC42U.mjs} +2 -2
  3. package/dist/chunk-2RDYC42U.mjs.map +1 -0
  4. package/dist/{chunk-4BPNRCZJ.js → chunk-4PWFZPJC.js} +2 -2
  5. package/dist/chunk-4PWFZPJC.js.map +1 -0
  6. package/dist/{chunk-B53MDMPL.js → chunk-4TUORIA6.js} +6 -6
  7. package/dist/{chunk-IC5BIIRG.js → chunk-6VJVURH5.js} +11 -11
  8. package/dist/{chunk-QKZO7EUA.js → chunk-756OQVOC.js} +2 -2
  9. package/dist/chunk-756OQVOC.js.map +1 -0
  10. package/dist/{chunk-4W7U4OH6.js → chunk-7CV677MM.js} +2 -2
  11. package/dist/chunk-7CV677MM.js.map +1 -0
  12. package/dist/{chunk-3XL562LA.mjs → chunk-7P6TF6CE.mjs} +10 -6
  13. package/dist/chunk-7P6TF6CE.mjs.map +1 -0
  14. package/dist/{chunk-P74WXDY4.js → chunk-A6H6I4VH.js} +9 -2
  15. package/dist/{chunk-P74WXDY4.js.map → chunk-A6H6I4VH.js.map} +1 -1
  16. package/dist/{chunk-QSVAU6X4.js → chunk-ATBKAX2S.js} +3 -3
  17. package/dist/{chunk-43UTAOW7.mjs → chunk-BSAXPL2T.mjs} +3 -3
  18. package/dist/{chunk-I7DR6BFO.js → chunk-ELCOEVKA.js} +65 -20
  19. package/dist/chunk-ELCOEVKA.js.map +1 -0
  20. package/dist/{chunk-NP3KGMVC.js → chunk-EOXTZF5U.js} +2 -2
  21. package/dist/chunk-EOXTZF5U.js.map +1 -0
  22. package/dist/{chunk-R4PZNFIL.mjs → chunk-FJ7COFRJ.mjs} +2 -2
  23. package/dist/chunk-FJ7COFRJ.mjs.map +1 -0
  24. package/dist/{chunk-PCIEMFOB.mjs → chunk-FNUO7MQ4.mjs} +6 -6
  25. package/dist/{chunk-I6FU5MGE.mjs → chunk-GPV4ETUH.mjs} +2 -2
  26. package/dist/chunk-GPV4ETUH.mjs.map +1 -0
  27. package/dist/{chunk-NE55M45Y.js → chunk-H6X3CWWQ.js} +2 -2
  28. package/dist/chunk-H6X3CWWQ.js.map +1 -0
  29. package/dist/{chunk-O2VSIMDY.js → chunk-HZQ34FQT.js} +14 -14
  30. package/dist/{chunk-O2VSIMDY.js.map → chunk-HZQ34FQT.js.map} +1 -1
  31. package/dist/{chunk-OHEJDJNV.mjs → chunk-I2P65KBQ.mjs} +2 -2
  32. package/dist/chunk-I2P65KBQ.mjs.map +1 -0
  33. package/dist/chunk-MC2Z4NF6.mjs +45 -0
  34. package/dist/chunk-MC2Z4NF6.mjs.map +1 -0
  35. package/dist/{chunk-PPR53SPJ.js → chunk-OI33OL7K.js} +2 -2
  36. package/dist/chunk-OI33OL7K.js.map +1 -0
  37. package/dist/{chunk-I3QG3QZL.mjs → chunk-SYB5TG5O.mjs} +10 -10
  38. package/dist/{chunk-I3QG3QZL.mjs.map → chunk-SYB5TG5O.mjs.map} +1 -1
  39. package/dist/{chunk-X247BMMW.mjs → chunk-TQCUJQHY.mjs} +64 -19
  40. package/dist/chunk-TQCUJQHY.mjs.map +1 -0
  41. package/dist/{chunk-TJYMYQAB.mjs → chunk-TVC3E5LI.mjs} +2 -2
  42. package/dist/chunk-TVC3E5LI.mjs.map +1 -0
  43. package/dist/{chunk-D5WQBUZB.js → chunk-U6TJQLNV.js} +2 -2
  44. package/dist/chunk-U6TJQLNV.js.map +1 -0
  45. package/dist/chunk-UCWANXBZ.js +45 -0
  46. package/dist/chunk-UCWANXBZ.js.map +1 -0
  47. package/dist/{chunk-F3VP6B2X.js → chunk-UF3UJTY3.js} +13 -9
  48. package/dist/chunk-UF3UJTY3.js.map +1 -0
  49. package/dist/{chunk-GVJLWGSI.mjs → chunk-UY4DUF53.mjs} +2 -2
  50. package/dist/chunk-UY4DUF53.mjs.map +1 -0
  51. package/dist/{chunk-R3DRYUNH.mjs → chunk-VYII7C3J.mjs} +2 -2
  52. package/dist/chunk-VYII7C3J.mjs.map +1 -0
  53. package/dist/{chunk-WEUKWKAQ.mjs → chunk-XGMYBPQR.mjs} +2 -2
  54. package/dist/chunk-XGMYBPQR.mjs.map +1 -0
  55. package/dist/{chunk-E6WUMFQT.mjs → chunk-Z6YFGWHN.mjs} +9 -2
  56. package/dist/chunk-Z6YFGWHN.mjs.map +1 -0
  57. package/dist/{chunk-IVD2ORDS.js → chunk-ZKISN6YP.js} +2 -2
  58. package/dist/chunk-ZKISN6YP.js.map +1 -0
  59. package/dist/{chunk-T3O2PFSR.mjs → chunk-ZXDCQWMJ.mjs} +2 -2
  60. package/dist/index.js +21 -17
  61. package/dist/index.js.map +1 -1
  62. package/dist/index.mjs +20 -16
  63. package/dist/index.mjs.map +1 -1
  64. package/dist/permissions.js +11 -11
  65. package/dist/permissions.mjs +10 -10
  66. package/dist/permitted/createInterface.js +2 -2
  67. package/dist/permitted/createInterface.mjs +1 -1
  68. package/dist/permitted/getFile.js +2 -2
  69. package/dist/permitted/getFile.mjs +1 -1
  70. package/dist/permitted/getInterfaceState.js +2 -2
  71. package/dist/permitted/getInterfaceState.mjs +1 -1
  72. package/dist/permitted/handlers.js +7 -6
  73. package/dist/permitted/handlers.mjs +6 -5
  74. package/dist/permitted/index.js +8 -7
  75. package/dist/permitted/index.mjs +7 -6
  76. package/dist/permitted/middleware.js +8 -7
  77. package/dist/permitted/middleware.mjs +7 -6
  78. package/dist/permitted/resolveInterface.js +7 -0
  79. package/dist/permitted/resolveInterface.js.map +1 -0
  80. package/dist/permitted/resolveInterface.mjs +7 -0
  81. package/dist/permitted/resolveInterface.mjs.map +1 -0
  82. package/dist/permitted/updateInterface.js +2 -2
  83. package/dist/permitted/updateInterface.mjs +1 -1
  84. package/dist/restricted/caveats/index.js +5 -5
  85. package/dist/restricted/caveats/index.mjs +4 -4
  86. package/dist/restricted/caveats/permittedDerivationPaths.js +2 -2
  87. package/dist/restricted/caveats/permittedDerivationPaths.mjs +1 -1
  88. package/dist/restricted/caveats/snapIds.js +2 -2
  89. package/dist/restricted/caveats/snapIds.mjs +1 -1
  90. package/dist/restricted/dialog.js +4 -2
  91. package/dist/restricted/dialog.mjs +3 -1
  92. package/dist/restricted/getBip32PublicKey.js +2 -2
  93. package/dist/restricted/getBip32PublicKey.mjs +1 -1
  94. package/dist/restricted/getEntropy.js +2 -2
  95. package/dist/restricted/getEntropy.mjs +1 -1
  96. package/dist/restricted/index.js +13 -10
  97. package/dist/restricted/index.mjs +12 -9
  98. package/dist/restricted/manageAccounts.js +2 -2
  99. package/dist/restricted/manageAccounts.mjs +1 -1
  100. package/dist/tsconfig.build.tsbuildinfo +1 -1
  101. package/dist/types/permitted/createInterface.d.ts +4 -4
  102. package/dist/types/permitted/getFile.d.ts +3 -3
  103. package/dist/types/permitted/getInterfaceState.d.ts +2 -2
  104. package/dist/types/permitted/handlers.d.ts +2 -1
  105. package/dist/types/permitted/index.d.ts +2 -1
  106. package/dist/types/permitted/resolveInterface.d.ts +21 -0
  107. package/dist/types/permitted/updateInterface.d.ts +4 -4
  108. package/dist/types/restricted/dialog.d.ts +353 -24
  109. package/dist/types/restricted/getBip32PublicKey.d.ts +4 -4
  110. package/dist/types/restricted/getEntropy.d.ts +4 -4
  111. package/dist/types/restricted/index.d.ts +3 -1
  112. package/dist/types/restricted/manageAccounts.d.ts +1 -1
  113. package/package.json +9 -9
  114. package/dist/chunk-3XL562LA.mjs.map +0 -1
  115. package/dist/chunk-4BPNRCZJ.js.map +0 -1
  116. package/dist/chunk-4W7U4OH6.js.map +0 -1
  117. package/dist/chunk-D5WQBUZB.js.map +0 -1
  118. package/dist/chunk-E6WUMFQT.mjs.map +0 -1
  119. package/dist/chunk-F3VP6B2X.js.map +0 -1
  120. package/dist/chunk-GVJLWGSI.mjs.map +0 -1
  121. package/dist/chunk-I6FU5MGE.mjs.map +0 -1
  122. package/dist/chunk-I7DR6BFO.js.map +0 -1
  123. package/dist/chunk-IVD2ORDS.js.map +0 -1
  124. package/dist/chunk-KIXPIIY5.mjs.map +0 -1
  125. package/dist/chunk-NE55M45Y.js.map +0 -1
  126. package/dist/chunk-NP3KGMVC.js.map +0 -1
  127. package/dist/chunk-OHEJDJNV.mjs.map +0 -1
  128. package/dist/chunk-PPR53SPJ.js.map +0 -1
  129. package/dist/chunk-QKZO7EUA.js.map +0 -1
  130. package/dist/chunk-R3DRYUNH.mjs.map +0 -1
  131. package/dist/chunk-R4PZNFIL.mjs.map +0 -1
  132. package/dist/chunk-TJYMYQAB.mjs.map +0 -1
  133. package/dist/chunk-WEUKWKAQ.mjs.map +0 -1
  134. package/dist/chunk-X247BMMW.mjs.map +0 -1
  135. /package/dist/{chunk-B53MDMPL.js.map → chunk-4TUORIA6.js.map} +0 -0
  136. /package/dist/{chunk-IC5BIIRG.js.map → chunk-6VJVURH5.js.map} +0 -0
  137. /package/dist/{chunk-QSVAU6X4.js.map → chunk-ATBKAX2S.js.map} +0 -0
  138. /package/dist/{chunk-43UTAOW7.mjs.map → chunk-BSAXPL2T.mjs.map} +0 -0
  139. /package/dist/{chunk-PCIEMFOB.mjs.map → chunk-FNUO7MQ4.mjs.map} +0 -0
  140. /package/dist/{chunk-T3O2PFSR.mjs.map → chunk-ZXDCQWMJ.mjs.map} +0 -0
package/CHANGELOG.md CHANGED
@@ -6,6 +6,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [10.0.0]
10
+ ### Added
11
+ - **BREAKING:** `snap_dialog` now takes the `requestUserApproval` hook ([#2509](https://github.com/metamask/snaps/pull/2509))
12
+ - It should bind to the `addAndShowRequest` method of the `ApprovalController`.
13
+ - Add type `DialogApprovalTypes` and object `DIALOG_APPROVAL_TYPES`.
14
+
15
+ ### Changed
16
+ - Bump `@metamask/key-tree` from `^9.1.1` to `^9.1.2` ([#2445](https://github.com/MetaMask/snaps/pull/2445))
17
+ - Bump `@metamask/permission-controller` from `^10.0.0` to `^10.0.1` ([#2445](https://github.com/MetaMask/snaps/pull/2445))
18
+ - Bump `@metamask/rpc-errors` from `^6.2.1` to `^6.3.1` ([#2445](https://github.com/MetaMask/snaps/pull/2445))
19
+ - Bump `@metamask/utils` from `^8.3.0` to `^9.1.0` ([#2445](https://github.com/MetaMask/snaps/pull/2445))
20
+
21
+ ### Fixed
22
+ - Replace `superstruct` with ESM-compatible `@metamask/superstruct` `^3.1.0` ([#2445](https://github.com/MetaMask/snaps/pull/2445))
23
+ - This fixes the issue of this package being unusable by any TypeScript project that uses `Node16` or `NodeNext` as its `moduleResolution` option.
24
+
9
25
  ## [9.1.4]
10
26
  ### Changed
11
27
  - Bump MetaMask dependencies ([#2516](https://github.com/MetaMask/snaps/pull/2516))
@@ -162,7 +178,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
162
178
  - The version of the package no longer needs to match the version of all other
163
179
  MetaMask Snaps packages.
164
180
 
165
- [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@9.1.4...HEAD
181
+ [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@10.0.0...HEAD
182
+ [10.0.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@9.1.4...@metamask/snaps-rpc-methods@10.0.0
166
183
  [9.1.4]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@9.1.3...@metamask/snaps-rpc-methods@9.1.4
167
184
  [9.1.3]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@9.1.2...@metamask/snaps-rpc-methods@9.1.3
168
185
  [9.1.2]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@9.1.1...@metamask/snaps-rpc-methods@9.1.2
@@ -6,8 +6,8 @@ import {
6
6
  import { PermissionType, SubjectType } from "@metamask/permission-controller";
7
7
  import { rpcErrors } from "@metamask/rpc-errors";
8
8
  import { SIP_6_MAGIC_VALUE } from "@metamask/snaps-utils";
9
+ import { literal, object, optional, string } from "@metamask/superstruct";
9
10
  import { assertStruct } from "@metamask/utils";
10
- import { literal, object, optional, string } from "superstruct";
11
11
  var targetName = "snap_getEntropy";
12
12
  var GetEntropyArgsStruct = object({
13
13
  version: literal(1),
@@ -64,4 +64,4 @@ export {
64
64
  GetEntropyArgsStruct,
65
65
  getEntropyBuilder
66
66
  };
67
- //# sourceMappingURL=chunk-KIXPIIY5.mjs.map
67
+ //# sourceMappingURL=chunk-2RDYC42U.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/restricted/getEntropy.ts"],"sourcesContent":["import type {\n PermissionSpecificationBuilder,\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type { GetEntropyParams, GetEntropyResult } from '@metamask/snaps-sdk';\nimport { SIP_6_MAGIC_VALUE } from '@metamask/snaps-utils';\nimport type { Infer } from '@metamask/superstruct';\nimport { literal, object, optional, string } from '@metamask/superstruct';\nimport type { NonEmptyArray } from '@metamask/utils';\nimport { assertStruct } from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\nimport { deriveEntropy } from '../utils';\n\nconst targetName = 'snap_getEntropy';\n\ntype GetEntropySpecificationBuilderOptions = {\n allowedCaveats?: Readonly<NonEmptyArray<string>> | null;\n methodHooks: GetEntropyHooks;\n};\n\ntype GetEntropySpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof targetName;\n methodImplementation: ReturnType<typeof getEntropyImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\nexport const GetEntropyArgsStruct = object({\n version: literal(1),\n salt: optional(string()),\n});\n\n/**\n * @property version - The version of the `snap_getEntropy` method. This must be\n * the numeric literal `1`.\n * @property salt - A string to use as the salt when deriving the entropy. If\n * omitted, the salt will be an empty string.\n */\nexport type GetEntropyArgs = Infer<typeof GetEntropyArgsStruct>;\n\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n GetEntropySpecificationBuilderOptions,\n GetEntropySpecification\n> = ({\n allowedCaveats = null,\n methodHooks,\n}: GetEntropySpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName,\n allowedCaveats,\n methodImplementation: getEntropyImplementation(methodHooks),\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<GetEntropyHooks> = {\n getMnemonic: true,\n getUnlockPromise: true,\n};\n\nexport const getEntropyBuilder = Object.freeze({\n targetName,\n specificationBuilder,\n methodHooks,\n} as const);\n\nexport type GetEntropyHooks = {\n /**\n * @returns The mnemonic of the user's primary keyring.\n */\n getMnemonic: () => Promise<Uint8Array>;\n\n /**\n * Waits for the extension to be unlocked.\n *\n * @returns A promise that resolves once the extension is unlocked.\n */\n getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;\n};\n\n/**\n * Builds the method implementation for `snap_getEntropy`. The implementation\n * is based on the reference implementation of\n * [SIP-6](https://metamask.github.io/SIPs/SIPS/sip-6).\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.getMnemonic - The method to get the mnemonic of the user's\n * primary keyring.\n * @param hooks.getUnlockPromise - The method to get a promise that resolves\n * once the extension is unlocked.\n * @returns The method implementation.\n */\nfunction getEntropyImplementation({\n getMnemonic,\n getUnlockPromise,\n}: GetEntropyHooks) {\n return async function getEntropy(\n options: RestrictedMethodOptions<GetEntropyParams>,\n ): Promise<GetEntropyResult> {\n const {\n params,\n context: { origin },\n } = options;\n\n assertStruct(\n params,\n GetEntropyArgsStruct,\n 'Invalid \"snap_getEntropy\" parameters',\n rpcErrors.invalidParams,\n );\n\n await getUnlockPromise(true);\n const mnemonicPhrase = await getMnemonic();\n\n return deriveEntropy({\n input: origin,\n salt: params.salt,\n mnemonicPhrase,\n magic: SIP_6_MAGIC_VALUE,\n });\n };\n}\n"],"mappings":";;;;;AAKA,SAAS,gBAAgB,mBAAmB;AAC5C,SAAS,iBAAiB;AAE1B,SAAS,yBAAyB;AAElC,SAAS,SAAS,QAAQ,UAAU,cAAc;AAElD,SAAS,oBAAoB;AAK7B,IAAM,aAAa;AAcZ,IAAM,uBAAuB,OAAO;AAAA,EACzC,SAAS,QAAQ,CAAC;AAAA,EAClB,MAAM,SAAS,OAAO,CAAC;AACzB,CAAC;AAUD,IAAM,uBAIF,CAAC;AAAA,EACH,iBAAiB;AAAA,EACjB,aAAAA;AACF,MAA6C;AAC3C,SAAO;AAAA,IACL,gBAAgB,eAAe;AAAA,IAC/B;AAAA,IACA;AAAA,IACA,sBAAsB,yBAAyBA,YAAW;AAAA,IAC1D,cAAc,CAAC,YAAY,IAAI;AAAA,EACjC;AACF;AAEA,IAAM,cAAkD;AAAA,EACtD,aAAa;AAAA,EACb,kBAAkB;AACpB;AAEO,IAAM,oBAAoB,OAAO,OAAO;AAAA,EAC7C;AAAA,EACA;AAAA,EACA;AACF,CAAU;AA4BV,SAAS,yBAAyB;AAAA,EAChC;AAAA,EACA;AACF,GAAoB;AAClB,SAAO,eAAe,WACpB,SAC2B;AAC3B,UAAM;AAAA,MACJ;AAAA,MACA,SAAS,EAAE,OAAO;AAAA,IACpB,IAAI;AAEJ;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA,UAAU;AAAA,IACZ;AAEA,UAAM,iBAAiB,IAAI;AAC3B,UAAM,iBAAiB,MAAM,YAAY;AAEzC,WAAO,cAAc;AAAA,MACnB,OAAO;AAAA,MACP,MAAM,OAAO;AAAA,MACb;AAAA,MACA,OAAO;AAAA,IACT,CAAC;AAAA,EACH;AACF;","names":["methodHooks"]}
@@ -11,8 +11,8 @@ var _rpcerrors = require('@metamask/rpc-errors');
11
11
 
12
12
 
13
13
  var _snapsutils = require('@metamask/snaps-utils');
14
+ var _superstruct = require('@metamask/superstruct');
14
15
  var _utils = require('@metamask/utils');
15
- var _superstruct = require('superstruct');
16
16
  var targetName = "snap_getBip32PublicKey";
17
17
  var Bip32PublicKeyArgsStruct = _snapsutils.bip32entropy.call(void 0,
18
18
  _superstruct.object.call(void 0, {
@@ -76,4 +76,4 @@ function getBip32PublicKeyImplementation({
76
76
 
77
77
 
78
78
  exports.Bip32PublicKeyArgsStruct = Bip32PublicKeyArgsStruct; exports.getBip32PublicKeyBuilder = getBip32PublicKeyBuilder; exports.getBip32PublicKeyImplementation = getBip32PublicKeyImplementation;
79
- //# sourceMappingURL=chunk-4BPNRCZJ.js.map
79
+ //# sourceMappingURL=chunk-4PWFZPJC.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/restricted/getBip32PublicKey.ts"],"names":["methodHooks"],"mappings":";;;;;AAMA,SAAS,gBAAgB,mBAAmB;AAC5C,SAAS,iBAAiB;AAK1B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,SAAS,QAAQ,gBAAgB;AAE1C,SAAS,oBAAoB;AAK7B,IAAM,aAAa;AA4BZ,IAAM,2BAA2B;AAAA,EACtC,OAAO;AAAA,IACL,MAAM;AAAA,IACN,OAAO;AAAA,IACP,YAAY,SAAS,QAAQ,CAAC;AAAA,EAChC,CAAC;AACH;AAWA,IAAM,uBAIF,CAAC,EAAE,aAAAA,aAAY,MAAoD;AACrE,SAAO;AAAA,IACL,gBAAgB,eAAe;AAAA,IAC/B;AAAA,IACA,gBAAgB,CAAC,eAAe,wBAAwB;AAAA,IACxD,sBAAsB,gCAAgCA,YAAW;AAAA,IACjE,WAAW,CAAC,EAAE,QAAQ,MAAM;AAC1B,UACE,SAAS,WAAW,KACpB,QAAQ,CAAC,EAAE,SAAS,eAAe,0BACnC;AACA,cAAM,UAAU,cAAc;AAAA,UAC5B,SAAS,sBAAsB,eAAe,wBAAwB;AAAA,QACxE,CAAC;AAAA,MACH;AAAA,IACF;AAAA,IACA,cAAc,CAAC,YAAY,IAAI;AAAA,EACjC;AACF;AAEA,IAAM,cAA+D;AAAA,EACnE,aAAa;AAAA,EACb,kBAAkB;AACpB;AAEO,IAAM,2BAA2B,OAAO,OAAO;AAAA,EACpD;AAAA,EACA;AAAA,EACA;AACF,CAAU;AAYH,SAAS,gCAAgC;AAAA,EAC9C;AAAA,EACA;AACF,GAAiC;AAC/B,SAAO,eAAe,kBACpB,MACkC;AAClC,UAAM,iBAAiB,IAAI;AAE3B;AAAA,MACE,KAAK;AAAA,MACL;AAAA,MACA;AAAA,MACA,UAAU;AAAA,IACZ;AAEA,UAAM,EAAE,OAAO,IAAI;AACnB,UAAM,OAAO,MAAM,QAAQ;AAAA,MACzB,OAAO,OAAO;AAAA,MACd,MAAM,OAAO;AAAA,MACb,sBAAsB,MAAM,YAAY;AAAA,IAC1C,CAAC;AAED,QAAI,OAAO,YAAY;AACrB,aAAO,KAAK;AAAA,IACd;AAEA,WAAO,KAAK;AAAA,EACd;AACF","sourcesContent":["import type {\n PermissionSpecificationBuilder,\n PermissionValidatorConstraint,\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type {\n GetBip32PublicKeyParams,\n GetBip32PublicKeyResult,\n} from '@metamask/snaps-sdk';\nimport {\n bip32entropy,\n Bip32PathStruct,\n CurveStruct,\n SnapCaveatType,\n} from '@metamask/snaps-utils';\nimport { boolean, object, optional } from '@metamask/superstruct';\nimport type { NonEmptyArray } from '@metamask/utils';\nimport { assertStruct } from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\nimport { getNode } from '../utils';\n\nconst targetName = 'snap_getBip32PublicKey';\n\nexport type GetBip32PublicKeyMethodHooks = {\n /**\n * @returns The mnemonic of the user's primary keyring.\n */\n getMnemonic: () => Promise<Uint8Array>;\n\n /**\n * Waits for the extension to be unlocked.\n *\n * @returns A promise that resolves once the extension is unlocked.\n */\n getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;\n};\n\ntype GetBip32PublicKeySpecificationBuilderOptions = {\n methodHooks: GetBip32PublicKeyMethodHooks;\n};\n\ntype GetBip32PublicKeySpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof targetName;\n methodImplementation: ReturnType<typeof getBip32PublicKeyImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n validator: PermissionValidatorConstraint;\n}>;\n\nexport const Bip32PublicKeyArgsStruct = bip32entropy(\n object({\n path: Bip32PathStruct,\n curve: CurveStruct,\n compressed: optional(boolean()),\n }),\n);\n\n/**\n * The specification builder for the `snap_getBip32PublicKey` permission.\n * `snap_getBip32PublicKey` lets the Snap retrieve public keys for a particular\n * BIP-32 node.\n *\n * @param options - The specification builder options.\n * @param options.methodHooks - The RPC method hooks needed by the method implementation.\n * @returns The specification for the `snap_getBip32PublicKey` permission.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n GetBip32PublicKeySpecificationBuilderOptions,\n GetBip32PublicKeySpecification\n> = ({ methodHooks }: GetBip32PublicKeySpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName,\n allowedCaveats: [SnapCaveatType.PermittedDerivationPaths],\n methodImplementation: getBip32PublicKeyImplementation(methodHooks),\n validator: ({ caveats }) => {\n if (\n caveats?.length !== 1 ||\n caveats[0].type !== SnapCaveatType.PermittedDerivationPaths\n ) {\n throw rpcErrors.invalidParams({\n message: `Expected a single \"${SnapCaveatType.PermittedDerivationPaths}\" caveat.`,\n });\n }\n },\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<GetBip32PublicKeyMethodHooks> = {\n getMnemonic: true,\n getUnlockPromise: true,\n};\n\nexport const getBip32PublicKeyBuilder = Object.freeze({\n targetName,\n specificationBuilder,\n methodHooks,\n} as const);\n\n/**\n * Builds the method implementation for `snap_getBip32PublicKey`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.getMnemonic - A function to retrieve the Secret Recovery Phrase of the user.\n * @param hooks.getUnlockPromise - A function that resolves once the MetaMask extension is unlocked\n * and prompts the user to unlock their MetaMask if it is locked.\n * @returns The method implementation which returns a public key.\n * @throws If the params are invalid.\n */\nexport function getBip32PublicKeyImplementation({\n getMnemonic,\n getUnlockPromise,\n}: GetBip32PublicKeyMethodHooks) {\n return async function getBip32PublicKey(\n args: RestrictedMethodOptions<GetBip32PublicKeyParams>,\n ): Promise<GetBip32PublicKeyResult> {\n await getUnlockPromise(true);\n\n assertStruct(\n args.params,\n Bip32PublicKeyArgsStruct,\n 'Invalid BIP-32 public key params',\n rpcErrors.invalidParams,\n );\n\n const { params } = args;\n const node = await getNode({\n curve: params.curve,\n path: params.path,\n secretRecoveryPhrase: await getMnemonic(),\n });\n\n if (params.compressed) {\n return node.compressedPublicKey;\n }\n\n return node.publicKey;\n };\n}\n"]}
@@ -1,9 +1,9 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkO2VSIMDYjs = require('./chunk-O2VSIMDY.js');
3
+ var _chunkHZQ34FQTjs = require('./chunk-HZQ34FQT.js');
4
4
 
5
5
 
6
- var _chunkIC5BIIRGjs = require('./chunk-IC5BIIRG.js');
6
+ var _chunk6VJVURH5js = require('./chunk-6VJVURH5.js');
7
7
 
8
8
 
9
9
  var _chunk33MTKZ4Hjs = require('./chunk-33MTKZ4H.js');
@@ -17,8 +17,8 @@ var _utils = require('@metamask/utils');
17
17
  function processSnapPermissions(initialPermissions) {
18
18
  return Object.fromEntries(
19
19
  Object.entries(initialPermissions).map(([initialPermission, value]) => {
20
- if (_utils.hasProperty.call(void 0, _chunkIC5BIIRGjs.caveatMappers, initialPermission)) {
21
- return [initialPermission, _chunkIC5BIIRGjs.caveatMappers[initialPermission](value)];
20
+ if (_utils.hasProperty.call(void 0, _chunk6VJVURH5js.caveatMappers, initialPermission)) {
21
+ return [initialPermission, _chunk6VJVURH5js.caveatMappers[initialPermission](value)];
22
22
  } else if (_utils.hasProperty.call(void 0, _chunkKRSIAVUJjs.endowmentCaveatMappers, initialPermission)) {
23
23
  return [
24
24
  initialPermission,
@@ -38,7 +38,7 @@ var buildSnapEndowmentSpecifications = (excludedEndowments) => Object.values(_ch
38
38
  }
39
39
  return allSpecifications;
40
40
  }, {});
41
- var buildSnapRestrictedMethodSpecifications = (excludedPermissions, hooks) => Object.values(_chunkO2VSIMDYjs.restrictedMethodPermissionBuilders).reduce((specifications, { targetName, specificationBuilder, methodHooks }) => {
41
+ var buildSnapRestrictedMethodSpecifications = (excludedPermissions, hooks) => Object.values(_chunkHZQ34FQTjs.restrictedMethodPermissionBuilders).reduce((specifications, { targetName, specificationBuilder, methodHooks }) => {
42
42
  if (!excludedPermissions.includes(targetName)) {
43
43
  specifications[targetName] = specificationBuilder({
44
44
  // @ts-expect-error The selectHooks type is wonky
@@ -56,4 +56,4 @@ var buildSnapRestrictedMethodSpecifications = (excludedPermissions, hooks) => Ob
56
56
 
57
57
 
58
58
  exports.processSnapPermissions = processSnapPermissions; exports.buildSnapEndowmentSpecifications = buildSnapEndowmentSpecifications; exports.buildSnapRestrictedMethodSpecifications = buildSnapRestrictedMethodSpecifications;
59
- //# sourceMappingURL=chunk-B53MDMPL.js.map
59
+ //# sourceMappingURL=chunk-4TUORIA6.js.map
@@ -5,39 +5,39 @@ var _chunkI3G6S6MJjs = require('./chunk-I3G6S6MJ.js');
5
5
 
6
6
 
7
7
 
8
- var _chunkQKZO7EUAjs = require('./chunk-QKZO7EUA.js');
8
+ var _chunk756OQVOCjs = require('./chunk-756OQVOC.js');
9
9
 
10
10
 
11
11
 
12
- var _chunkNE55M45Yjs = require('./chunk-NE55M45Y.js');
12
+ var _chunkH6X3CWWQjs = require('./chunk-H6X3CWWQ.js');
13
13
 
14
14
 
15
- var _chunkVUA6ICJOjs = require('./chunk-VUA6ICJO.js');
15
+ var _chunk4PWFZPJCjs = require('./chunk-4PWFZPJC.js');
16
16
 
17
17
 
18
- var _chunkIE6EHYEGjs = require('./chunk-IE6EHYEG.js');
18
+ var _chunkVUA6ICJOjs = require('./chunk-VUA6ICJO.js');
19
19
 
20
20
 
21
- var _chunk4BPNRCZJjs = require('./chunk-4BPNRCZJ.js');
21
+ var _chunkIE6EHYEGjs = require('./chunk-IE6EHYEG.js');
22
22
 
23
23
 
24
24
  var _chunkFFHVA6PPjs = require('./chunk-FFHVA6PP.js');
25
25
 
26
26
  // src/restricted/caveats/index.ts
27
27
  var caveatSpecifications = {
28
- ..._chunkQKZO7EUAjs.PermittedDerivationPathsCaveatSpecification,
28
+ ..._chunk756OQVOCjs.PermittedDerivationPathsCaveatSpecification,
29
29
  ..._chunkI3G6S6MJjs.PermittedCoinTypesCaveatSpecification,
30
- ..._chunkNE55M45Yjs.SnapIdsCaveatSpecification
30
+ ..._chunkH6X3CWWQjs.SnapIdsCaveatSpecification
31
31
  };
32
32
  var caveatMappers = {
33
- [_chunkIE6EHYEGjs.getBip32EntropyBuilder.targetName]: _chunkQKZO7EUAjs.permittedDerivationPathsCaveatMapper,
34
- [_chunk4BPNRCZJjs.getBip32PublicKeyBuilder.targetName]: _chunkQKZO7EUAjs.permittedDerivationPathsCaveatMapper,
33
+ [_chunkIE6EHYEGjs.getBip32EntropyBuilder.targetName]: _chunk756OQVOCjs.permittedDerivationPathsCaveatMapper,
34
+ [_chunk4PWFZPJCjs.getBip32PublicKeyBuilder.targetName]: _chunk756OQVOCjs.permittedDerivationPathsCaveatMapper,
35
35
  [_chunkVUA6ICJOjs.getBip44EntropyBuilder.targetName]: _chunkI3G6S6MJjs.permittedCoinTypesCaveatMapper,
36
- [_chunkFFHVA6PPjs.invokeSnapBuilder.targetName]: _chunkNE55M45Yjs.snapIdsCaveatMapper
36
+ [_chunkFFHVA6PPjs.invokeSnapBuilder.targetName]: _chunkH6X3CWWQjs.snapIdsCaveatMapper
37
37
  };
38
38
 
39
39
 
40
40
 
41
41
 
42
42
  exports.caveatSpecifications = caveatSpecifications; exports.caveatMappers = caveatMappers;
43
- //# sourceMappingURL=chunk-IC5BIIRG.js.map
43
+ //# sourceMappingURL=chunk-6VJVURH5.js.map
@@ -5,8 +5,8 @@ var _rpcerrors = require('@metamask/rpc-errors');
5
5
 
6
6
 
7
7
  var _snapsutils = require('@metamask/snaps-utils');
8
+ var _superstruct = require('@metamask/superstruct');
8
9
  var _utils = require('@metamask/utils');
9
- var _superstruct = require('superstruct');
10
10
  function permittedDerivationPathsCaveatMapper(value) {
11
11
  return {
12
12
  caveats: [
@@ -64,4 +64,4 @@ var PermittedDerivationPathsCaveatSpecification = {
64
64
 
65
65
 
66
66
  exports.permittedDerivationPathsCaveatMapper = permittedDerivationPathsCaveatMapper; exports.validateBIP32Path = validateBIP32Path; exports.validateBIP32CaveatPaths = validateBIP32CaveatPaths; exports.PermittedDerivationPathsCaveatSpecification = PermittedDerivationPathsCaveatSpecification;
67
- //# sourceMappingURL=chunk-QKZO7EUA.js.map
67
+ //# sourceMappingURL=chunk-756OQVOC.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/restricted/caveats/permittedDerivationPaths.ts"],"names":[],"mappings":";AAKA,SAAS,gBAAgB,iBAAiB;AAE1C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,OAAO,MAAM,YAAY;AAElC,SAAS,oBAAoB;AAUtB,SAAS,qCACd,OACuC;AACvC,SAAO;AAAA,IACL,SAAS;AAAA,MACP;AAAA,QACE,MAAM,eAAe;AAAA,QACrB;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAWO,SAAS,kBACd,OAC+B;AAC/B;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA,UAAU;AAAA,EACZ;AACF;AASO,SAAS,yBACd,QACkD;AAClD;AAAA,IACE;AAAA,IACA,KAAK,EAAE,OAAO,KAAK,MAAM,kBAAkB,GAAG,GAAG,QAAQ,EAAE,CAAC;AAAA,IAC5D;AAAA,IACA,UAAU;AAAA,EACZ;AACF;AAEO,IAAM,8CAGT;AAAA,EACF,CAAC,eAAe,wBAAwB,GAAG,OAAO,OAAO;AAAA,IACvD,MAAM,eAAe;AAAA,IACrB,WAAW,CAAC,QAAQ,WAAW;AAC7B,aAAO,OAAO,SAAS;AACrB,cAAM,EAAE,OAAO,IAAI;AACnB,0BAAkB,MAAM;AAExB,cAAM,OAAQ,OAAO,MAAyB;AAAA,UAC5C,CAAC,eACC;AAAA,YACE,OAAO,KAAK,MAAM,GAAG,WAAW,KAAK,MAAM;AAAA,YAC3C,WAAW;AAAA,UACb,KAAK,WAAW,UAAU,OAAO;AAAA,QACrC;AAEA,YAAI,CAAC,MAAM;AACT,gBAAM,eAAe,aAAa;AAAA,YAChC,SACE;AAAA,UACJ,CAAC;AAAA,QACH;AAEA,eAAO,MAAM,OAAO,IAAI;AAAA,MAC1B;AAAA,IACF;AAAA,IACA,WAAW,CAAC,WAAW,yBAAyB,MAAM;AAAA,EACxD,CAAC;AACH","sourcesContent":["import type {\n Caveat,\n PermissionConstraint,\n RestrictedMethodCaveatSpecificationConstraint,\n} from '@metamask/permission-controller';\nimport { providerErrors, rpcErrors } from '@metamask/rpc-errors';\nimport type { Bip32Entropy } from '@metamask/snaps-utils';\nimport {\n SnapCaveatType,\n Bip32EntropyStruct,\n isEqual,\n} from '@metamask/snaps-utils';\nimport { array, size, type } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\nimport { assertStruct } from '@metamask/utils';\n\n/**\n * Map a raw value from the `initialPermissions` to a caveat specification.\n * Note that this function does not do any validation, that's handled by the\n * PermissionsController when the permission is requested.\n *\n * @param value - The raw value from the `initialPermissions`.\n * @returns The caveat specification.\n */\nexport function permittedDerivationPathsCaveatMapper(\n value: Json,\n): Pick<PermissionConstraint, 'caveats'> {\n return {\n caveats: [\n {\n type: SnapCaveatType.PermittedDerivationPaths,\n value,\n },\n ],\n };\n}\n\n/**\n * Validate a caveat path object. The object must consist of a `path` array and\n * a `curve` string. Paths must start with `m`, and must contain at\n * least two indices. If `ed25519` is used, this checks if all the path indices\n * are hardened.\n *\n * @param value - The value to validate.\n * @throws If the value is invalid.\n */\nexport function validateBIP32Path(\n value: unknown,\n): asserts value is Bip32Entropy {\n assertStruct(\n value,\n Bip32EntropyStruct,\n 'Invalid BIP-32 entropy path definition',\n rpcErrors.invalidParams,\n );\n}\n\n/**\n * Validate the path values associated with a caveat. This validates that the\n * value is a non-empty array with valid derivation paths and curves.\n *\n * @param caveat - The caveat to validate.\n * @throws If the value is invalid.\n */\nexport function validateBIP32CaveatPaths(\n caveat: Caveat<string, any>,\n): asserts caveat is Caveat<string, Bip32Entropy[]> {\n assertStruct(\n caveat,\n type({ value: size(array(Bip32EntropyStruct), 1, Infinity) }),\n 'Invalid BIP-32 entropy caveat',\n rpcErrors.internal,\n );\n}\n\nexport const PermittedDerivationPathsCaveatSpecification: Record<\n SnapCaveatType.PermittedDerivationPaths,\n RestrictedMethodCaveatSpecificationConstraint\n> = {\n [SnapCaveatType.PermittedDerivationPaths]: Object.freeze({\n type: SnapCaveatType.PermittedDerivationPaths,\n decorator: (method, caveat) => {\n return async (args) => {\n const { params } = args;\n validateBIP32Path(params);\n\n const path = (caveat.value as Bip32Entropy[]).find(\n (caveatPath) =>\n isEqual(\n params.path.slice(0, caveatPath.path.length),\n caveatPath.path,\n ) && caveatPath.curve === params.curve,\n );\n\n if (!path) {\n throw providerErrors.unauthorized({\n message:\n 'The requested path is not permitted. Allowed paths must be specified in the snap manifest.',\n });\n }\n\n return await method(args);\n };\n },\n validator: (caveat) => validateBIP32CaveatPaths(caveat),\n }),\n};\n"]}
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/permitted/getInterfaceState.ts
2
2
  var _rpcerrors = require('@metamask/rpc-errors');
3
- var _superstruct = require('superstruct');
3
+ var _superstruct = require('@metamask/superstruct');
4
4
  var hookNames = {
5
5
  getInterfaceState: true
6
6
  };
@@ -39,4 +39,4 @@ function getValidatedParams(params) {
39
39
 
40
40
 
41
41
  exports.getInterfaceStateHandler = getInterfaceStateHandler;
42
- //# sourceMappingURL=chunk-4W7U4OH6.js.map
42
+ //# sourceMappingURL=chunk-7CV677MM.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/permitted/getInterfaceState.ts"],"names":[],"mappings":";AAEA,SAAS,iBAAiB;AAQ1B,SAAS,aAAa,QAAQ,QAAQ,cAAc;AAKpD,IAAM,YAA6D;AAAA,EACjE,mBAAmB;AACrB;AAUO,IAAM,2BAIT;AAAA,EACF,aAAa,CAAC,wBAAwB;AAAA,EACtC,gBAAgB;AAAA,EAChB;AACF;AAEA,IAAM,oCAAoC,OAAO;AAAA,EAC/C,IAAI,OAAO;AACb,CAAC;AAmBD,SAAS,mCACP,KACA,KACA,OACA,KACA,EAAE,kBAAkB,GACd;AACN,QAAM,EAAE,OAAO,IAAI;AAEnB,MAAI;AACF,UAAM,kBAAkB,mBAAmB,MAAM;AAEjD,UAAM,EAAE,GAAG,IAAI;AAEf,QAAI,SAAS,kBAAkB,EAAE;AAAA,EACnC,SAAS,OAAO;AACd,WAAO,IAAI,KAAK;AAAA,EAClB;AAEA,SAAO,IAAI;AACb;AASA,SAAS,mBAAmB,QAA8C;AACxE,MAAI;AACF,WAAO,OAAO,QAAQ,iCAAiC;AAAA,EACzD,SAAS,OAAO;AACd,QAAI,iBAAiB,aAAa;AAChC,YAAM,UAAU,cAAc;AAAA,QAC5B,SAAS,mBAAmB,MAAM,OAAO;AAAA,MAC3C,CAAC;AAAA,IACH;AAEA,UAAM,UAAU,SAAS;AAAA,EAC3B;AACF","sourcesContent":["import type { JsonRpcEngineEndCallback } from '@metamask/json-rpc-engine';\nimport type { PermittedHandlerExport } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type {\n GetInterfaceStateParams,\n GetInterfaceStateResult,\n InterfaceState,\n JsonRpcRequest,\n} from '@metamask/snaps-sdk';\nimport { type InferMatching } from '@metamask/snaps-utils';\nimport { StructError, create, object, string } from '@metamask/superstruct';\nimport type { PendingJsonRpcResponse } from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\n\nconst hookNames: MethodHooksObject<GetInterfaceStateMethodHooks> = {\n getInterfaceState: true,\n};\n\nexport type GetInterfaceStateMethodHooks = {\n /**\n * @param id - The interface ID.\n * @returns The interface state.\n */\n getInterfaceState: (id: string) => InterfaceState;\n};\n\nexport const getInterfaceStateHandler: PermittedHandlerExport<\n GetInterfaceStateMethodHooks,\n GetInterfaceStateParameters,\n GetInterfaceStateResult\n> = {\n methodNames: ['snap_getInterfaceState'],\n implementation: getGetInterfaceStateImplementation,\n hookNames,\n};\n\nconst GetInterfaceStateParametersStruct = object({\n id: string(),\n});\n\nexport type GetInterfaceStateParameters = InferMatching<\n typeof GetInterfaceStateParametersStruct,\n GetInterfaceStateParams\n>;\n\n/**\n * The `snap_getInterfaceState` method implementation.\n *\n * @param req - The JSON-RPC request object.\n * @param res - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param hooks - The RPC method hooks.\n * @param hooks.getInterfaceState - The function to get the interface state.\n * @returns Noting.\n */\nfunction getGetInterfaceStateImplementation(\n req: JsonRpcRequest<GetInterfaceStateParameters>,\n res: PendingJsonRpcResponse<GetInterfaceStateResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n { getInterfaceState }: GetInterfaceStateMethodHooks,\n): void {\n const { params } = req;\n\n try {\n const validatedParams = getValidatedParams(params);\n\n const { id } = validatedParams;\n\n res.result = getInterfaceState(id);\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n\n/**\n * Validate the getInterfaceState method `params` and returns them cast to the correct\n * type. Throws if validation fails.\n *\n * @param params - The unvalidated params object from the method request.\n * @returns The validated getInterfaceState method parameter object.\n */\nfunction getValidatedParams(params: unknown): GetInterfaceStateParameters {\n try {\n return create(params, GetInterfaceStateParametersStruct);\n } catch (error) {\n if (error instanceof StructError) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}.`,\n });\n }\n /* istanbul ignore next */\n throw rpcErrors.internal();\n }\n}\n"]}
@@ -7,12 +7,15 @@ import {
7
7
  import {
8
8
  requestSnapsHandler
9
9
  } from "./chunk-MXPVC2XP.mjs";
10
+ import {
11
+ resolveInterfaceHandler
12
+ } from "./chunk-MC2Z4NF6.mjs";
10
13
  import {
11
14
  updateInterfaceHandler
12
- } from "./chunk-GVJLWGSI.mjs";
15
+ } from "./chunk-UY4DUF53.mjs";
13
16
  import {
14
17
  createInterfaceHandler
15
- } from "./chunk-WEUKWKAQ.mjs";
18
+ } from "./chunk-XGMYBPQR.mjs";
16
19
  import {
17
20
  getAllSnapsHandler
18
21
  } from "./chunk-UB3733UY.mjs";
@@ -21,10 +24,10 @@ import {
21
24
  } from "./chunk-62URQ5VS.mjs";
22
25
  import {
23
26
  getFileHandler
24
- } from "./chunk-I6FU5MGE.mjs";
27
+ } from "./chunk-GPV4ETUH.mjs";
25
28
  import {
26
29
  getInterfaceStateHandler
27
- } from "./chunk-TJYMYQAB.mjs";
30
+ } from "./chunk-TVC3E5LI.mjs";
28
31
  import {
29
32
  getSnapsHandler
30
33
  } from "./chunk-CH5O2YCX.mjs";
@@ -40,7 +43,8 @@ var methodHandlers = {
40
43
  snap_getFile: getFileHandler,
41
44
  snap_createInterface: createInterfaceHandler,
42
45
  snap_updateInterface: updateInterfaceHandler,
43
- snap_getInterfaceState: getInterfaceStateHandler
46
+ snap_getInterfaceState: getInterfaceStateHandler,
47
+ snap_resolveInterface: resolveInterfaceHandler
44
48
  };
45
49
  var handlers = Object.values(methodHandlers);
46
50
 
@@ -48,4 +52,4 @@ export {
48
52
  methodHandlers,
49
53
  handlers
50
54
  };
51
- //# sourceMappingURL=chunk-3XL562LA.mjs.map
55
+ //# sourceMappingURL=chunk-7P6TF6CE.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/permitted/handlers.ts"],"sourcesContent":["import { createInterfaceHandler } from './createInterface';\nimport { getAllSnapsHandler } from './getAllSnaps';\nimport { getClientStatusHandler } from './getClientStatus';\nimport { getFileHandler } from './getFile';\nimport { getInterfaceStateHandler } from './getInterfaceState';\nimport { getSnapsHandler } from './getSnaps';\nimport { invokeKeyringHandler } from './invokeKeyring';\nimport { invokeSnapSugarHandler } from './invokeSnapSugar';\nimport { requestSnapsHandler } from './requestSnaps';\nimport { resolveInterfaceHandler } from './resolveInterface';\nimport { updateInterfaceHandler } from './updateInterface';\n\n/* eslint-disable @typescript-eslint/naming-convention */\nexport const methodHandlers = {\n wallet_getAllSnaps: getAllSnapsHandler,\n wallet_getSnaps: getSnapsHandler,\n wallet_requestSnaps: requestSnapsHandler,\n wallet_invokeSnap: invokeSnapSugarHandler,\n wallet_invokeKeyring: invokeKeyringHandler,\n snap_getClientStatus: getClientStatusHandler,\n snap_getFile: getFileHandler,\n snap_createInterface: createInterfaceHandler,\n snap_updateInterface: updateInterfaceHandler,\n snap_getInterfaceState: getInterfaceStateHandler,\n snap_resolveInterface: resolveInterfaceHandler,\n};\n/* eslint-enable @typescript-eslint/naming-convention */\n\nexport const handlers = Object.values(methodHandlers);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAaO,IAAM,iBAAiB;AAAA,EAC5B,oBAAoB;AAAA,EACpB,iBAAiB;AAAA,EACjB,qBAAqB;AAAA,EACrB,mBAAmB;AAAA,EACnB,sBAAsB;AAAA,EACtB,sBAAsB;AAAA,EACtB,cAAc;AAAA,EACd,sBAAsB;AAAA,EACtB,sBAAsB;AAAA,EACtB,wBAAwB;AAAA,EACxB,uBAAuB;AACzB;AAGO,IAAM,WAAW,OAAO,OAAO,cAAc;","names":[]}
@@ -1,7 +1,14 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/restricted/manageAccounts.ts
2
2
  var _permissioncontroller = require('@metamask/permission-controller');
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+ var _superstruct = require('@metamask/superstruct');
3
11
  var _utils = require('@metamask/utils');
4
- var _superstruct = require('superstruct');
5
12
  var SnapMessageStruct = _superstruct.union.call(void 0, [
6
13
  _superstruct.object.call(void 0, {
7
14
  method: _superstruct.string.call(void 0, )
@@ -51,4 +58,4 @@ var manageAccountsBuilder = Object.freeze({
51
58
 
52
59
 
53
60
  exports.methodName = methodName; exports.specificationBuilder = specificationBuilder; exports.manageAccountsImplementation = manageAccountsImplementation; exports.manageAccountsBuilder = manageAccountsBuilder;
54
- //# sourceMappingURL=chunk-P74WXDY4.js.map
61
+ //# sourceMappingURL=chunk-A6H6I4VH.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/restricted/manageAccounts.ts"],"names":[],"mappings":";AAKA,SAAS,aAAa,sBAAsB;AAO5C,SAAS,kBAAkB;AAC3B,SAAS,QAAQ,QAAQ,QAAQ,OAAO,OAAO,cAAc;AAE7D,IAAM,oBAAoB,MAAM;AAAA,EAC9B,OAAO;AAAA,IACL,QAAQ,OAAO;AAAA,EACjB,CAAC;AAAA,EACD,OAAO;AAAA,IACL,QAAQ,OAAO;AAAA,IACf,QAAQ,MAAM,CAAC,MAAM,UAAU,GAAG,OAAO,OAAO,GAAG,UAAU,CAAC,CAAC;AAAA,EACjE,CAAC;AACH,CAAC;AAIM,IAAM,aAAa;AAmCnB,IAAM,uBAIT,CAAC;AAAA,EACH,iBAAiB;AAAA,EACjB;AACF,MAAiD;AAC/C,SAAO;AAAA,IACL,gBAAgB,eAAe;AAAA,IAC/B,YAAY;AAAA,IACZ;AAAA,IACA,sBAAsB,6BAA6B,WAAW;AAAA,IAC9D,cAAc,CAAC,YAAY,IAAI;AAAA,EACjC;AACF;AAWO,SAAS,6BAA6B;AAAA,EAC3C;AACF,GAA8B;AAC5B,SAAO,eAAe,eACpB,SAC+B;AAC/B,UAAM;AAAA,MACJ,SAAS,EAAE,OAAO;AAAA,MAClB;AAAA,IACF,IAAI;AAEJ,WAAO,QAAQ,iBAAiB;AAChC,UAAM,UAAU,MAAM,eAAe,MAAM;AAC3C,WAAO,MAAM,QAAQ,yBAAyB,QAAQ,MAAM;AAAA,EAC9D;AACF;AAEO,IAAM,wBAAwB,OAAO,OAAO;AAAA,EACjD,YAAY;AAAA,EACZ;AAAA,EACA,aAAa;AAAA,IACX,gBAAgB;AAAA,EAClB;AACF,CAAU","sourcesContent":["import type {\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n PermissionSpecificationBuilder,\n} from '@metamask/permission-controller';\nimport { SubjectType, PermissionType } from '@metamask/permission-controller';\nimport type {\n ManageAccountsParams,\n ManageAccountsResult,\n} from '@metamask/snaps-sdk';\nimport type { InferMatching } from '@metamask/snaps-utils';\nimport type { Json, NonEmptyArray } from '@metamask/utils';\nimport { JsonStruct } from '@metamask/utils';\nimport { assert, string, object, union, array, record } from 'superstruct';\n\nconst SnapMessageStruct = union([\n object({\n method: string(),\n }),\n object({\n method: string(),\n params: union([array(JsonStruct), record(string(), JsonStruct)]),\n }),\n]);\n\ntype Message = InferMatching<typeof SnapMessageStruct, ManageAccountsParams>;\n\nexport const methodName = 'snap_manageAccounts';\n\nexport type ManageAccountsMethodHooks = {\n /**\n * Gets the snap keyring implementation.\n */\n getSnapKeyring: (snapOrigin: string) => Promise<{\n handleKeyringSnapMessage: (\n snapId: string,\n message: Message,\n ) => Promise<Json>;\n }>;\n};\n\ntype ManageAccountsSpecificationBuilderOptions = {\n allowedCaveats?: Readonly<NonEmptyArray<string>> | null;\n methodHooks: ManageAccountsMethodHooks;\n};\n\ntype ManageAccountsSpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof methodName;\n methodImplementation: ReturnType<typeof manageAccountsImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\n/**\n * The specification builder for the `snap_manageAccounts` permission.\n * `snap_manageAccounts` lets the Snap manage a set of accounts via a custom keyring.\n *\n * @param options - The specification builder options.\n * @param options.allowedCaveats - The optional allowed caveats for the permission.\n * @param options.methodHooks - The RPC method hooks needed by the method implementation.\n * @returns The specification for the `snap_manageAccounts` permission.\n */\nexport const specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n ManageAccountsSpecificationBuilderOptions,\n ManageAccountsSpecification\n> = ({\n allowedCaveats = null,\n methodHooks,\n}: ManageAccountsSpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName: methodName,\n allowedCaveats,\n methodImplementation: manageAccountsImplementation(methodHooks),\n subjectTypes: [SubjectType.Snap],\n };\n};\n\n/**\n * Builds the method implementation for `snap_manageAccounts`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.getSnapKeyring - A function to get the snap keyring.\n * @returns The method implementation which either returns `null` for a\n * successful state update/deletion or returns the decrypted state.\n * @throws If the params are invalid.\n */\nexport function manageAccountsImplementation({\n getSnapKeyring,\n}: ManageAccountsMethodHooks) {\n return async function manageAccounts(\n options: RestrictedMethodOptions<ManageAccountsParams>,\n ): Promise<ManageAccountsResult> {\n const {\n context: { origin },\n params,\n } = options;\n\n assert(params, SnapMessageStruct);\n const keyring = await getSnapKeyring(origin);\n return await keyring.handleKeyringSnapMessage(origin, params);\n };\n}\n\nexport const manageAccountsBuilder = Object.freeze({\n targetName: methodName,\n specificationBuilder,\n methodHooks: {\n getSnapKeyring: true,\n },\n} as const);\n"]}
1
+ {"version":3,"sources":["../src/restricted/manageAccounts.ts"],"names":[],"mappings":";AAKA,SAAS,aAAa,sBAAsB;AAM5C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,kBAAkB;AAE3B,IAAM,oBAAoB,MAAM;AAAA,EAC9B,OAAO;AAAA,IACL,QAAQ,OAAO;AAAA,EACjB,CAAC;AAAA,EACD,OAAO;AAAA,IACL,QAAQ,OAAO;AAAA,IACf,QAAQ,MAAM,CAAC,MAAM,UAAU,GAAG,OAAO,OAAO,GAAG,UAAU,CAAC,CAAC;AAAA,EACjE,CAAC;AACH,CAAC;AAIM,IAAM,aAAa;AAmCnB,IAAM,uBAIT,CAAC;AAAA,EACH,iBAAiB;AAAA,EACjB;AACF,MAAiD;AAC/C,SAAO;AAAA,IACL,gBAAgB,eAAe;AAAA,IAC/B,YAAY;AAAA,IACZ;AAAA,IACA,sBAAsB,6BAA6B,WAAW;AAAA,IAC9D,cAAc,CAAC,YAAY,IAAI;AAAA,EACjC;AACF;AAWO,SAAS,6BAA6B;AAAA,EAC3C;AACF,GAA8B;AAC5B,SAAO,eAAe,eACpB,SAC+B;AAC/B,UAAM;AAAA,MACJ,SAAS,EAAE,OAAO;AAAA,MAClB;AAAA,IACF,IAAI;AAEJ,WAAO,QAAQ,iBAAiB;AAChC,UAAM,UAAU,MAAM,eAAe,MAAM;AAC3C,WAAO,MAAM,QAAQ,yBAAyB,QAAQ,MAAM;AAAA,EAC9D;AACF;AAEO,IAAM,wBAAwB,OAAO,OAAO;AAAA,EACjD,YAAY;AAAA,EACZ;AAAA,EACA,aAAa;AAAA,IACX,gBAAgB;AAAA,EAClB;AACF,CAAU","sourcesContent":["import type {\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n PermissionSpecificationBuilder,\n} from '@metamask/permission-controller';\nimport { SubjectType, PermissionType } from '@metamask/permission-controller';\nimport type {\n ManageAccountsParams,\n ManageAccountsResult,\n} from '@metamask/snaps-sdk';\nimport type { InferMatching } from '@metamask/snaps-utils';\nimport {\n assert,\n string,\n object,\n union,\n array,\n record,\n} from '@metamask/superstruct';\nimport type { Json, NonEmptyArray } from '@metamask/utils';\nimport { JsonStruct } from '@metamask/utils';\n\nconst SnapMessageStruct = union([\n object({\n method: string(),\n }),\n object({\n method: string(),\n params: union([array(JsonStruct), record(string(), JsonStruct)]),\n }),\n]);\n\ntype Message = InferMatching<typeof SnapMessageStruct, ManageAccountsParams>;\n\nexport const methodName = 'snap_manageAccounts';\n\nexport type ManageAccountsMethodHooks = {\n /**\n * Gets the snap keyring implementation.\n */\n getSnapKeyring: (snapOrigin: string) => Promise<{\n handleKeyringSnapMessage: (\n snapId: string,\n message: Message,\n ) => Promise<Json>;\n }>;\n};\n\ntype ManageAccountsSpecificationBuilderOptions = {\n allowedCaveats?: Readonly<NonEmptyArray<string>> | null;\n methodHooks: ManageAccountsMethodHooks;\n};\n\ntype ManageAccountsSpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof methodName;\n methodImplementation: ReturnType<typeof manageAccountsImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\n/**\n * The specification builder for the `snap_manageAccounts` permission.\n * `snap_manageAccounts` lets the Snap manage a set of accounts via a custom keyring.\n *\n * @param options - The specification builder options.\n * @param options.allowedCaveats - The optional allowed caveats for the permission.\n * @param options.methodHooks - The RPC method hooks needed by the method implementation.\n * @returns The specification for the `snap_manageAccounts` permission.\n */\nexport const specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n ManageAccountsSpecificationBuilderOptions,\n ManageAccountsSpecification\n> = ({\n allowedCaveats = null,\n methodHooks,\n}: ManageAccountsSpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName: methodName,\n allowedCaveats,\n methodImplementation: manageAccountsImplementation(methodHooks),\n subjectTypes: [SubjectType.Snap],\n };\n};\n\n/**\n * Builds the method implementation for `snap_manageAccounts`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.getSnapKeyring - A function to get the snap keyring.\n * @returns The method implementation which either returns `null` for a\n * successful state update/deletion or returns the decrypted state.\n * @throws If the params are invalid.\n */\nexport function manageAccountsImplementation({\n getSnapKeyring,\n}: ManageAccountsMethodHooks) {\n return async function manageAccounts(\n options: RestrictedMethodOptions<ManageAccountsParams>,\n ): Promise<ManageAccountsResult> {\n const {\n context: { origin },\n params,\n } = options;\n\n assert(params, SnapMessageStruct);\n const keyring = await getSnapKeyring(origin);\n return await keyring.handleKeyringSnapMessage(origin, params);\n };\n}\n\nexport const manageAccountsBuilder = Object.freeze({\n targetName: methodName,\n specificationBuilder,\n methodHooks: {\n getSnapKeyring: true,\n },\n} as const);\n"]}
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkF3VP6B2Xjs = require('./chunk-F3VP6B2X.js');
3
+ var _chunkUF3UJTY3js = require('./chunk-UF3UJTY3.js');
4
4
 
5
5
 
6
6
  var _chunk33MTKZ4Hjs = require('./chunk-33MTKZ4H.js');
@@ -10,7 +10,7 @@ var _rpcerrors = require('@metamask/rpc-errors');
10
10
  var _snapsutils = require('@metamask/snaps-utils');
11
11
  function createSnapsMethodMiddleware(isSnap, hooks) {
12
12
  return async function methodMiddleware(request, response, next, end) {
13
- const handler = _chunkF3VP6B2Xjs.methodHandlers[request.method];
13
+ const handler = _chunkUF3UJTY3js.methodHandlers[request.method];
14
14
  if (handler) {
15
15
  if (String.prototype.startsWith.call(request.method, "snap_") && !isSnap) {
16
16
  return end(_rpcerrors.rpcErrors.methodNotFound());
@@ -36,4 +36,4 @@ function createSnapsMethodMiddleware(isSnap, hooks) {
36
36
 
37
37
 
38
38
  exports.createSnapsMethodMiddleware = createSnapsMethodMiddleware;
39
- //# sourceMappingURL=chunk-QSVAU6X4.js.map
39
+ //# sourceMappingURL=chunk-ATBKAX2S.js.map
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  restrictedMethodPermissionBuilders
3
- } from "./chunk-I3QG3QZL.mjs";
3
+ } from "./chunk-SYB5TG5O.mjs";
4
4
  import {
5
5
  caveatMappers
6
- } from "./chunk-PCIEMFOB.mjs";
6
+ } from "./chunk-FNUO7MQ4.mjs";
7
7
  import {
8
8
  selectHooks
9
9
  } from "./chunk-W33UWNA2.mjs";
@@ -56,4 +56,4 @@ export {
56
56
  buildSnapEndowmentSpecifications,
57
57
  buildSnapRestrictedMethodSpecifications
58
58
  };
59
- //# sourceMappingURL=chunk-43UTAOW7.mjs.map
59
+ //# sourceMappingURL=chunk-BSAXPL2T.mjs.map
@@ -8,7 +8,6 @@ var _rpcerrors = require('@metamask/rpc-errors');
8
8
 
9
9
  var _snapssdk = require('@metamask/snaps-sdk');
10
10
  var _snapsutils = require('@metamask/snaps-utils');
11
- var _utils = require('@metamask/utils');
12
11
 
13
12
 
14
13
 
@@ -17,8 +16,15 @@ var _utils = require('@metamask/utils');
17
16
 
18
17
 
19
18
 
20
- var _superstruct = require('superstruct');
19
+ var _superstruct = require('@metamask/superstruct');
20
+ var _utils = require('@metamask/utils');
21
21
  var methodName = "snap_dialog";
22
+ var DIALOG_APPROVAL_TYPES = {
23
+ [_snapssdk.DialogType.Alert]: `${methodName}:alert`,
24
+ [_snapssdk.DialogType.Confirmation]: `${methodName}:confirmation`,
25
+ [_snapssdk.DialogType.Prompt]: `${methodName}:prompt`,
26
+ default: methodName
27
+ };
22
28
  var PlaceholderStruct = _superstruct.optional.call(void 0, _superstruct.size.call(void 0, _superstruct.string.call(void 0, ), 1, 40));
23
29
  var specificationBuilder = ({
24
30
  allowedCaveats = null,
@@ -33,7 +39,7 @@ var specificationBuilder = ({
33
39
  };
34
40
  };
35
41
  var methodHooks = {
36
- showDialog: true,
42
+ requestUserApproval: true,
37
43
  createInterface: true,
38
44
  getInterface: true
39
45
  };
@@ -43,7 +49,9 @@ var dialogBuilder = Object.freeze({
43
49
  methodHooks
44
50
  });
45
51
  var BaseParamsStruct = _superstruct.type.call(void 0, {
46
- type: _superstruct.enums.call(void 0, [_snapssdk.DialogType.Alert, _snapssdk.DialogType.Confirmation, _snapssdk.DialogType.Prompt])
52
+ type: _superstruct.optional.call(void 0,
53
+ _superstruct.enums.call(void 0, [_snapssdk.DialogType.Alert, _snapssdk.DialogType.Confirmation, _snapssdk.DialogType.Prompt])
54
+ )
47
55
  });
48
56
  var AlertParametersWithContentStruct = _superstruct.object.call(void 0, {
49
57
  type: _snapssdk.enumValue.call(void 0, _snapssdk.DialogType.Alert),
@@ -83,10 +91,21 @@ var PromptParametersStruct = _snapssdk.union.call(void 0, [
83
91
  PromptParametersWithContentStruct,
84
92
  PromptParametersWithIdStruct
85
93
  ]);
94
+ var DefaultParametersWithContentStruct = _superstruct.object.call(void 0, {
95
+ content: _snapssdk.ComponentOrElementStruct
96
+ });
97
+ var DefaultParametersWithIdStruct = _superstruct.object.call(void 0, {
98
+ id: _superstruct.string.call(void 0, )
99
+ });
100
+ var DefaultParametersStruct = _snapssdk.union.call(void 0, [
101
+ DefaultParametersWithContentStruct,
102
+ DefaultParametersWithIdStruct
103
+ ]);
86
104
  var DialogParametersStruct = _snapssdk.union.call(void 0, [
87
105
  AlertParametersStruct,
88
106
  ConfirmationParametersStruct,
89
- PromptParametersStruct
107
+ PromptParametersStruct,
108
+ DefaultParametersStruct
90
109
  ]);
91
110
  var structs = {
92
111
  [_snapssdk.DialogType.Alert]: AlertParametersStruct,
@@ -94,7 +113,7 @@ var structs = {
94
113
  [_snapssdk.DialogType.Prompt]: PromptParametersStruct
95
114
  };
96
115
  function getDialogImplementation({
97
- showDialog,
116
+ requestUserApproval,
98
117
  createInterface,
99
118
  getInterface
100
119
  }) {
@@ -103,26 +122,48 @@ function getDialogImplementation({
103
122
  params,
104
123
  context: { origin }
105
124
  } = args;
125
+ if (!_utils.isObject.call(void 0, params)) {
126
+ throw _rpcerrors.rpcErrors.invalidParams({
127
+ message: "Invalid params: Expected params to be a single object."
128
+ });
129
+ }
106
130
  const validatedType = getValidatedType(params);
107
- const validatedParams = getValidatedParams(params, structs[validatedType]);
108
- const placeholder = validatedParams.type === _snapssdk.DialogType.Prompt ? validatedParams.placeholder : void 0;
131
+ const approvalType = validatedType ? DIALOG_APPROVAL_TYPES[validatedType] : DIALOG_APPROVAL_TYPES.default;
132
+ const validatedParams = getValidatedParams(params, validatedType);
133
+ const placeholder = isPromptDialog(validatedParams) ? validatedParams.placeholder : void 0;
109
134
  if (_utils.hasProperty.call(void 0, validatedParams, "content")) {
110
135
  const id = await createInterface(
111
136
  origin,
112
137
  validatedParams.content
113
138
  );
114
- return showDialog(origin, validatedType, id, placeholder);
115
- }
116
- try {
117
- getInterface(origin, validatedParams.id);
118
- } catch (error) {
119
- throw _rpcerrors.rpcErrors.invalidParams({
120
- message: `Invalid params: ${error.message}`
139
+ return requestUserApproval({
140
+ id: validatedType ? void 0 : id,
141
+ origin,
142
+ type: approvalType,
143
+ requestData: { id, placeholder }
121
144
  });
122
145
  }
123
- return showDialog(origin, validatedType, validatedParams.id, placeholder);
146
+ validateInterface(origin, validatedParams.id, getInterface);
147
+ return requestUserApproval({
148
+ id: validatedType ? void 0 : validatedParams.id,
149
+ origin,
150
+ type: approvalType,
151
+ requestData: { id: validatedParams.id, placeholder }
152
+ });
124
153
  };
125
154
  }
155
+ function validateInterface(origin, id, getInterface) {
156
+ try {
157
+ getInterface(origin, id);
158
+ } catch (error) {
159
+ throw _rpcerrors.rpcErrors.invalidParams({
160
+ message: `Invalid params: ${error.message}`
161
+ });
162
+ }
163
+ }
164
+ function getDialogType(params) {
165
+ return _utils.hasProperty.call(void 0, params, "type") ? params.type : void 0;
166
+ }
126
167
  function getValidatedType(params) {
127
168
  try {
128
169
  return _superstruct.create.call(void 0, params, BaseParamsStruct).type;
@@ -134,9 +175,12 @@ function getValidatedType(params) {
134
175
  });
135
176
  }
136
177
  }
137
- function getValidatedParams(params, struct) {
178
+ function isPromptDialog(params) {
179
+ return getDialogType(params) === _snapssdk.DialogType.Prompt;
180
+ }
181
+ function getValidatedParams(params, validatedType) {
138
182
  try {
139
- return _snapsutils.createUnion.call(void 0, params, struct, "type");
183
+ return validatedType ? _snapsutils.createUnion.call(void 0, params, structs[validatedType], "type") : _superstruct.create.call(void 0, params, DefaultParametersStruct);
140
184
  } catch (error) {
141
185
  throw _rpcerrors.rpcErrors.invalidParams({
142
186
  message: `Invalid params: ${error.message}`
@@ -147,5 +191,6 @@ function getValidatedParams(params, struct) {
147
191
 
148
192
 
149
193
 
150
- exports.dialogBuilder = dialogBuilder; exports.getDialogImplementation = getDialogImplementation;
151
- //# sourceMappingURL=chunk-I7DR6BFO.js.map
194
+
195
+ exports.DIALOG_APPROVAL_TYPES = DIALOG_APPROVAL_TYPES; exports.dialogBuilder = dialogBuilder; exports.getDialogImplementation = getDialogImplementation;
196
+ //# sourceMappingURL=chunk-ELCOEVKA.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/restricted/dialog.ts"],"names":["methodHooks"],"mappings":"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","sourcesContent":["import type {\n PermissionSpecificationBuilder,\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport {\n DialogType,\n enumValue,\n union,\n ComponentOrElementStruct,\n} from '@metamask/snaps-sdk';\nimport type {\n DialogParams,\n Component,\n InterfaceState,\n SnapId,\n PromptDialog,\n ComponentOrElement,\n} from '@metamask/snaps-sdk';\nimport type { InferMatching } from '@metamask/snaps-utils';\nimport { createUnion } from '@metamask/snaps-utils';\nimport type { Infer, Struct } from '@metamask/superstruct';\nimport {\n create,\n enums,\n object,\n optional,\n size,\n string,\n type,\n} from '@metamask/superstruct';\nimport type { Json, NonEmptyArray } from '@metamask/utils';\nimport { hasProperty, isObject } from '@metamask/utils';\n\nimport { type MethodHooksObject } from '../utils';\n\nconst methodName = 'snap_dialog';\n\nexport type DialogApprovalTypes = Record<DialogType, string> & {\n default: string;\n};\n\nexport const DIALOG_APPROVAL_TYPES = {\n [DialogType.Alert]: `${methodName}:alert`,\n [DialogType.Confirmation]: `${methodName}:confirmation`,\n [DialogType.Prompt]: `${methodName}:prompt`,\n default: methodName,\n};\n\nconst PlaceholderStruct = optional(size(string(), 1, 40));\n\nexport type Placeholder = Infer<typeof PlaceholderStruct>;\n\ntype RequestUserApprovalOptions = {\n id?: string;\n origin: string;\n type: string;\n requestData: {\n id: string;\n placeholder?: string;\n };\n};\n\ntype RequestUserApproval = (\n opts: RequestUserApprovalOptions,\n) => Promise<boolean | null | string | Json>;\n\ntype CreateInterface = (\n snapId: string,\n content: ComponentOrElement,\n) => Promise<string>;\n\ntype GetInterface = (\n snapId: string,\n id: string,\n) => { content: ComponentOrElement; snapId: SnapId; state: InterfaceState };\n\nexport type DialogMethodHooks = {\n /**\n * @param opts - The `requestUserApproval` options.\n * @param opts.id - The approval ID. If not provided, a new approval ID will be generated.\n * @param opts.origin - The origin of the request. In this case, the Snap ID.\n * @param opts.type - The type of the approval request.\n * @param opts.requestData - The data of the approval request.\n * @param opts.requestData.id - The ID of the interface.\n * @param opts.requestData.placeholder - The placeholder of the `Prompt` dialog.\n */\n requestUserApproval: RequestUserApproval;\n\n /**\n * @param snapId - The Snap ID creating the interface.\n * @param content - The content of the interface.\n */\n createInterface: CreateInterface;\n /**\n * @param snapId - The SnapId requesting the interface.\n * @param id - The interface ID.\n */\n getInterface: GetInterface;\n};\n\ntype DialogSpecificationBuilderOptions = {\n allowedCaveats?: Readonly<NonEmptyArray<string>> | null;\n methodHooks: DialogMethodHooks;\n};\n\ntype DialogSpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof methodName;\n methodImplementation: ReturnType<typeof getDialogImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\n/**\n * The specification builder for the `snap_dialog` permission. `snap_dialog`\n * lets the Snap display one of the following dialogs to the user:\n * - An alert, for displaying information.\n * - A confirmation, for accepting or rejecting some action.\n * - A prompt, for inputting some information.\n *\n * @param options - The specification builder options.\n * @param options.allowedCaveats - The optional allowed caveats for the\n * permission.\n * @param options.methodHooks - The RPC method hooks needed by the method\n * implementation.\n * @returns The specification for the `snap_dialog` permission.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n DialogSpecificationBuilderOptions,\n DialogSpecification\n> = ({\n allowedCaveats = null,\n methodHooks,\n}: DialogSpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName: methodName,\n allowedCaveats,\n methodImplementation: getDialogImplementation(methodHooks),\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<DialogMethodHooks> = {\n requestUserApproval: true,\n createInterface: true,\n getInterface: true,\n};\n\nexport const dialogBuilder = Object.freeze({\n targetName: methodName,\n specificationBuilder,\n methodHooks,\n} as const);\n\n// Note: We use `type` here instead of `object` because `type` does not validate\n// the keys of the object, which is what we want.\nconst BaseParamsStruct = type({\n type: optional(\n enums([DialogType.Alert, DialogType.Confirmation, DialogType.Prompt]),\n ),\n});\n\nconst AlertParametersWithContentStruct = object({\n type: enumValue(DialogType.Alert),\n content: ComponentOrElementStruct,\n});\nconst AlertParametersWithIdStruct = object({\n type: enumValue(DialogType.Alert),\n id: string(),\n});\n\nconst AlertParametersStruct = union([\n AlertParametersWithContentStruct,\n AlertParametersWithIdStruct,\n]);\n\nconst ConfirmationParametersWithContentStruct = object({\n type: enumValue(DialogType.Confirmation),\n content: ComponentOrElementStruct,\n});\n\nconst ConfirmationParametersWithIdStruct = object({\n type: enumValue(DialogType.Confirmation),\n id: string(),\n});\n\nconst ConfirmationParametersStruct = union([\n ConfirmationParametersWithContentStruct,\n ConfirmationParametersWithIdStruct,\n]);\n\nconst PromptParametersWithContentStruct = object({\n type: enumValue(DialogType.Prompt),\n content: ComponentOrElementStruct,\n placeholder: PlaceholderStruct,\n});\n\nconst PromptParametersWithIdStruct = object({\n type: enumValue(DialogType.Prompt),\n id: string(),\n placeholder: PlaceholderStruct,\n});\n\nconst PromptParametersStruct = union([\n PromptParametersWithContentStruct,\n PromptParametersWithIdStruct,\n]);\n\nconst DefaultParametersWithContentStruct = object({\n content: ComponentOrElementStruct,\n});\n\nconst DefaultParametersWithIdStruct = object({\n id: string(),\n});\n\nconst DefaultParametersStruct = union([\n DefaultParametersWithContentStruct,\n DefaultParametersWithIdStruct,\n]);\n\nconst DialogParametersStruct = union([\n AlertParametersStruct,\n ConfirmationParametersStruct,\n PromptParametersStruct,\n DefaultParametersStruct,\n]);\n\nexport type DialogParameters = InferMatching<\n typeof DialogParametersStruct,\n DialogParams\n>;\n\nconst structs: Record<DialogType, Struct<any, any>> = {\n [DialogType.Alert]: AlertParametersStruct,\n [DialogType.Confirmation]: ConfirmationParametersStruct,\n [DialogType.Prompt]: PromptParametersStruct,\n};\n\n/**\n * Builds the method implementation for `snap_dialog`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.requestUserApproval - A function that creates a new Approval in the ApprovalController.\n * This function should return a Promise that resolves with the appropriate value when the user has approved or rejected the request.\n * @param hooks.createInterface - A function that creates the interface in SnapInterfaceController.\n * @param hooks.getInterface - A function that gets an interface from SnapInterfaceController.\n * @returns The method implementation which return value depends on the dialog\n * type, valid return types are: string, boolean, null.\n */\nexport function getDialogImplementation({\n requestUserApproval,\n createInterface,\n getInterface,\n}: DialogMethodHooks) {\n return async function dialogImplementation(\n args: RestrictedMethodOptions<DialogParameters>,\n ): Promise<boolean | null | string | Json> {\n const {\n params,\n context: { origin },\n } = args;\n\n if (!isObject(params)) {\n throw rpcErrors.invalidParams({\n message: 'Invalid params: Expected params to be a single object.',\n });\n }\n\n const validatedType = getValidatedType(params);\n\n const approvalType = validatedType\n ? DIALOG_APPROVAL_TYPES[validatedType]\n : DIALOG_APPROVAL_TYPES.default;\n\n const validatedParams = getValidatedParams(params, validatedType);\n const placeholder = isPromptDialog(validatedParams)\n ? validatedParams.placeholder\n : undefined;\n\n if (hasProperty(validatedParams, 'content')) {\n const id = await createInterface(\n origin,\n validatedParams.content as Component,\n );\n\n return requestUserApproval({\n id: validatedType ? undefined : id,\n origin,\n type: approvalType,\n requestData: { id, placeholder },\n });\n }\n\n validateInterface(origin, validatedParams.id, getInterface);\n\n return requestUserApproval({\n id: validatedType ? undefined : validatedParams.id,\n origin,\n type: approvalType,\n requestData: { id: validatedParams.id, placeholder },\n });\n };\n}\n/**\n * Validate that the interface ID is valid.\n *\n * @param origin - The origin of the request.\n * @param id - The interface ID.\n * @param getInterface - The function to get the interface.\n */\nfunction validateInterface(\n origin: string,\n id: string,\n getInterface: GetInterface,\n) {\n try {\n getInterface(origin, id);\n } catch (error) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}`,\n });\n }\n}\n\n/**\n * Gets the dialog type from the dialog parameters.\n *\n * @param params - The dialog parameters.\n * @returns The dialog type.\n */\nfunction getDialogType(params: DialogParameters): DialogType | undefined {\n return hasProperty(params, 'type') ? (params.type as DialogType) : undefined;\n}\n\n/**\n * Get the validated type of the dialog parameters. Throws an error if the type\n * is invalid.\n *\n * @param params - The parameters to validate.\n * @returns The validated type of the dialog parameters.\n */\nfunction getValidatedType(params: unknown): DialogType | undefined {\n try {\n return create(params, BaseParamsStruct).type;\n } catch (error) {\n throw rpcErrors.invalidParams({\n message: `The \"type\" property must be one of: ${Object.values(\n DialogType,\n ).join(', ')}.`,\n });\n }\n}\n\n/**\n * Checks if the dialog parameters are for a prompt dialog.\n *\n * @param params - The dialog parameters.\n * @returns `true` if the dialog parameters are for a prompt dialog, `false` otherwise.\n */\nfunction isPromptDialog(params: DialogParameters): params is PromptDialog {\n return getDialogType(params) === DialogType.Prompt;\n}\n\n/**\n * Validates the confirm method `params` and returns them cast to the correct\n * type. Throws if validation fails.\n *\n * @param params - The unvalidated params object from the method request.\n * @param validatedType - The validated dialog type.\n * @returns The validated confirm method parameter object.\n */\nfunction getValidatedParams(\n params: unknown,\n validatedType: DialogType | undefined,\n): DialogParameters {\n try {\n return validatedType\n ? createUnion(params, structs[validatedType], 'type')\n : create(params, DefaultParametersStruct);\n } catch (error) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}`,\n });\n }\n}\n"]}
@@ -1,8 +1,8 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/permitted/getFile.ts
2
2
  var _rpcerrors = require('@metamask/rpc-errors');
3
3
  var _snapssdk = require('@metamask/snaps-sdk');
4
+ var _superstruct = require('@metamask/superstruct');
4
5
  var _utils = require('@metamask/utils');
5
- var _superstruct = require('superstruct');
6
6
  var GetFileArgsStruct = _superstruct.object.call(void 0, {
7
7
  path: _superstruct.string.call(void 0, ),
8
8
  encoding: _superstruct.optional.call(void 0,
@@ -44,4 +44,4 @@ async function implementation(req, res, _next, end, { getSnapFile }) {
44
44
 
45
45
 
46
46
  exports.GetFileArgsStruct = GetFileArgsStruct; exports.getFileHandler = getFileHandler;
47
- //# sourceMappingURL=chunk-NP3KGMVC.js.map
47
+ //# sourceMappingURL=chunk-EOXTZF5U.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/permitted/getFile.ts"],"names":[],"mappings":";AAEA,SAAS,iBAAiB;AAE1B,SAAS,uBAAuB,iBAAiB;AAEjD,SAAS,QAAQ,UAAU,QAAQ,aAAa;AAEhD,SAAS,oBAAoB;AAItB,IAAM,oBAAoB,OAAO;AAAA,EACtC,MAAM,OAAO;AAAA,EACb,UAAU;AAAA,IACR,MAAM;AAAA,MACJ,UAAU,sBAAsB,MAAM;AAAA,MACtC,UAAU,sBAAsB,GAAG;AAAA,MACnC,UAAU,sBAAsB,IAAI;AAAA,IACtC,CAAC;AAAA,EACH;AACF,CAAC;AAOD,IAAM,YAA6C;AAAA,EACjD,aAAa;AACf;AAEO,IAAM,iBAIT;AAAA,EACF,aAAa,CAAC,cAAc;AAAA,EAC5B;AAAA,EACA;AACF;AAqBA,eAAe,eACb,KACA,KACA,OACA,KACA,EAAE,YAAY,GACC;AACf,QAAM,EAAE,OAAO,IAAI;AAEnB;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA,UAAU;AAAA,EACZ;AAEA,MAAI;AACF,QAAI,SAAS,MAAM;AAAA,MACjB,OAAO;AAAA,MACP,OAAO,YAAY,sBAAsB;AAAA,IAC3C;AAAA,EACF,SAAS,OAAO;AACd,WAAO,IAAI,KAAK;AAAA,EAClB;AAEA,SAAO,IAAI;AACb","sourcesContent":["import type { JsonRpcEngineEndCallback } from '@metamask/json-rpc-engine';\nimport type { PermittedHandlerExport } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type { GetFileParams, GetFileResult } from '@metamask/snaps-sdk';\nimport { AuxiliaryFileEncoding, enumValue } from '@metamask/snaps-sdk';\nimport type { InferMatching } from '@metamask/snaps-utils';\nimport { object, optional, string, union } from '@metamask/superstruct';\nimport type { PendingJsonRpcResponse, JsonRpcRequest } from '@metamask/utils';\nimport { assertStruct } from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\n\nexport const GetFileArgsStruct = object({\n path: string(),\n encoding: optional(\n union([\n enumValue(AuxiliaryFileEncoding.Base64),\n enumValue(AuxiliaryFileEncoding.Hex),\n enumValue(AuxiliaryFileEncoding.Utf8),\n ]),\n ),\n});\n\nexport type InferredGetFileParams = InferMatching<\n typeof GetFileArgsStruct,\n GetFileParams\n>;\n\nconst hookNames: MethodHooksObject<GetFileHooks> = {\n getSnapFile: true,\n};\n\nexport const getFileHandler: PermittedHandlerExport<\n GetFileHooks,\n InferredGetFileParams,\n string\n> = {\n methodNames: ['snap_getFile'],\n implementation,\n hookNames,\n};\n\nexport type GetFileHooks = {\n getSnapFile: (\n path: InferredGetFileParams['path'],\n encoding: InferredGetFileParams['encoding'],\n ) => Promise<string>;\n};\n\n/**\n * The `snap_getFile` method implementation.\n *\n * @param req - The JSON-RPC request object.\n * @param res - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param hooks - The RPC method hooks.\n * @param hooks.getSnapFile - The function to load a static snap file.\n * @returns Nothing.\n */\nasync function implementation(\n req: JsonRpcRequest<InferredGetFileParams>,\n res: PendingJsonRpcResponse<GetFileResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n { getSnapFile }: GetFileHooks,\n): Promise<void> {\n const { params } = req;\n\n assertStruct(\n params,\n GetFileArgsStruct,\n 'Invalid \"snap_getFile\" parameters',\n rpcErrors.invalidParams,\n );\n\n try {\n res.result = await getSnapFile(\n params.path,\n params.encoding ?? AuxiliaryFileEncoding.Base64,\n );\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n"]}
@@ -1,8 +1,8 @@
1
1
  // src/restricted/caveats/snapIds.ts
2
2
  import { rpcErrors } from "@metamask/rpc-errors";
3
3
  import { SnapCaveatType, SnapIdsStruct } from "@metamask/snaps-utils";
4
+ import { type } from "@metamask/superstruct";
4
5
  import { hasProperty, assertStruct } from "@metamask/utils";
5
- import { type } from "superstruct";
6
6
  function snapIdsCaveatMapper(value) {
7
7
  return {
8
8
  caveats: [
@@ -51,4 +51,4 @@ export {
51
51
  validateSnapIdsCaveat,
52
52
  SnapIdsCaveatSpecification
53
53
  };
54
- //# sourceMappingURL=chunk-R4PZNFIL.mjs.map
54
+ //# sourceMappingURL=chunk-FJ7COFRJ.mjs.map