@metamask/snaps-rpc-methods 8.0.0 → 9.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 (117) hide show
  1. package/CHANGELOG.md +15 -1
  2. package/dist/{chunk-MXCJWR45.mjs → chunk-2CTOCP34.mjs} +8 -8
  3. package/dist/chunk-2CTOCP34.mjs.map +1 -0
  4. package/dist/{chunk-TKXU7ZXP.mjs → chunk-2L2ATCIK.mjs} +2 -2
  5. package/dist/{chunk-YG7W4CDT.js → chunk-33MTKZ4H.js} +11 -4
  6. package/dist/chunk-33MTKZ4H.js.map +1 -0
  7. package/dist/{chunk-LGUJMQC7.js → chunk-4BPNRCZJ.js} +5 -4
  8. package/dist/chunk-4BPNRCZJ.js.map +1 -0
  9. package/dist/{chunk-WLDEPJGG.mjs → chunk-634BK2VP.mjs} +3 -3
  10. package/dist/chunk-634BK2VP.mjs.map +1 -0
  11. package/dist/{chunk-7OMVZR5X.mjs → chunk-CJPFADO7.mjs} +3 -3
  12. package/dist/{chunk-GP5KW5FU.js → chunk-D5WQBUZB.js} +2 -2
  13. package/dist/chunk-D5WQBUZB.js.map +1 -0
  14. package/dist/{chunk-IDZGMGIB.js → chunk-DLVPMPRZ.js} +8 -8
  15. package/dist/chunk-DLVPMPRZ.js.map +1 -0
  16. package/dist/{chunk-AOWUGDER.js → chunk-E27BGHCR.js} +3 -3
  17. package/dist/{chunk-Y4LNTDZ2.mjs → chunk-FR26QD3N.mjs} +3 -3
  18. package/dist/{chunk-YS6TYXCP.mjs → chunk-GVJLWGSI.mjs} +3 -3
  19. package/dist/chunk-GVJLWGSI.mjs.map +1 -0
  20. package/dist/{chunk-SU6KOIVB.mjs → chunk-I3QG3QZL.mjs} +6 -6
  21. package/dist/{chunk-GYZV5UBD.js → chunk-I7DR6BFO.js} +4 -4
  22. package/dist/chunk-I7DR6BFO.js.map +1 -0
  23. package/dist/{chunk-S7AR3ROH.js → chunk-IE6EHYEG.js} +3 -3
  24. package/dist/{chunk-Q5W3YGEB.js → chunk-IVD2ORDS.js} +3 -3
  25. package/dist/{chunk-IBV23QOX.mjs → chunk-KIXPIIY5.mjs} +2 -2
  26. package/dist/{chunk-AYJK7MSH.js → chunk-LLH2T5NT.js} +5 -5
  27. package/dist/{chunk-TNRH2LRU.mjs → chunk-LXJBBRQ4.mjs} +2 -2
  28. package/dist/{chunk-R2M4YLJ7.js → chunk-M2JQCKR7.js} +3 -3
  29. package/dist/{chunk-RZXF4KSR.js → chunk-O2VSIMDY.js} +11 -11
  30. package/dist/{chunk-EGKFC56F.js → chunk-QAKSH24Z.js} +8 -8
  31. package/dist/{chunk-6WUIFFMQ.mjs → chunk-R3DRYUNH.mjs} +5 -4
  32. package/dist/chunk-R3DRYUNH.mjs.map +1 -0
  33. package/dist/{chunk-JQ456NCC.mjs → chunk-S46RTIDR.mjs} +5 -5
  34. package/dist/{chunk-NESDQ4PF.mjs → chunk-TE4W25CA.mjs} +2 -2
  35. package/dist/{chunk-AMBEX4N4.mjs → chunk-TUIJOZXZ.mjs} +4 -4
  36. package/dist/{chunk-3LPBU737.js → chunk-UDB4MUXI.js} +2 -2
  37. package/dist/chunk-UDB4MUXI.js.map +1 -0
  38. package/dist/{chunk-6UY23OOZ.js → chunk-VBCE6VHM.js} +5 -5
  39. package/dist/{chunk-SGQXD5K7.mjs → chunk-W33UWNA2.mjs} +11 -4
  40. package/dist/chunk-W33UWNA2.mjs.map +1 -0
  41. package/dist/{chunk-4SQWLI2S.mjs → chunk-X247BMMW.mjs} +6 -6
  42. package/dist/chunk-X247BMMW.mjs.map +1 -0
  43. package/dist/{chunk-D6MUXDVI.js → chunk-XXSAESE7.js} +9 -9
  44. package/dist/index.js +16 -16
  45. package/dist/index.mjs +15 -15
  46. package/dist/permissions.js +10 -10
  47. package/dist/permissions.mjs +9 -9
  48. package/dist/permitted/createInterface.js +2 -2
  49. package/dist/permitted/createInterface.mjs +1 -1
  50. package/dist/permitted/handlers.js +6 -6
  51. package/dist/permitted/handlers.mjs +5 -5
  52. package/dist/permitted/index.js +8 -8
  53. package/dist/permitted/index.mjs +7 -7
  54. package/dist/permitted/invokeKeyring.js +3 -3
  55. package/dist/permitted/invokeKeyring.mjs +2 -2
  56. package/dist/permitted/invokeSnapSugar.js +2 -2
  57. package/dist/permitted/invokeSnapSugar.mjs +1 -1
  58. package/dist/permitted/middleware.js +8 -8
  59. package/dist/permitted/middleware.mjs +7 -7
  60. package/dist/permitted/updateInterface.js +2 -2
  61. package/dist/permitted/updateInterface.mjs +1 -1
  62. package/dist/restricted/caveats/index.js +5 -5
  63. package/dist/restricted/caveats/index.mjs +4 -4
  64. package/dist/restricted/dialog.js +2 -2
  65. package/dist/restricted/dialog.mjs +1 -1
  66. package/dist/restricted/getBip32Entropy.js +3 -3
  67. package/dist/restricted/getBip32Entropy.mjs +2 -2
  68. package/dist/restricted/getBip32PublicKey.js +3 -3
  69. package/dist/restricted/getBip32PublicKey.mjs +2 -2
  70. package/dist/restricted/getEntropy.js +3 -3
  71. package/dist/restricted/getEntropy.mjs +2 -2
  72. package/dist/restricted/index.js +9 -9
  73. package/dist/restricted/index.mjs +8 -8
  74. package/dist/restricted/manageState.js +3 -3
  75. package/dist/restricted/manageState.mjs +2 -2
  76. package/dist/tsconfig.build.tsbuildinfo +1 -1
  77. package/dist/types/permitted/createInterface.d.ts +41 -41
  78. package/dist/types/permitted/handlers.d.ts +2 -2
  79. package/dist/types/permitted/invokeSnapSugar.d.ts +12 -7
  80. package/dist/types/permitted/updateInterface.d.ts +42 -42
  81. package/dist/types/restricted/dialog.d.ts +316 -148
  82. package/dist/types/restricted/getBip32PublicKey.d.ts +2 -5
  83. package/dist/types/restricted/manageAccounts.d.ts +1 -1
  84. package/dist/types/utils.d.ts +7 -5
  85. package/dist/utils.js +2 -2
  86. package/dist/utils.mjs +1 -1
  87. package/package.json +4 -4
  88. package/dist/chunk-3LPBU737.js.map +0 -1
  89. package/dist/chunk-4SQWLI2S.mjs.map +0 -1
  90. package/dist/chunk-6WUIFFMQ.mjs.map +0 -1
  91. package/dist/chunk-GP5KW5FU.js.map +0 -1
  92. package/dist/chunk-GYZV5UBD.js.map +0 -1
  93. package/dist/chunk-IDZGMGIB.js.map +0 -1
  94. package/dist/chunk-LGUJMQC7.js.map +0 -1
  95. package/dist/chunk-MXCJWR45.mjs.map +0 -1
  96. package/dist/chunk-SGQXD5K7.mjs.map +0 -1
  97. package/dist/chunk-WLDEPJGG.mjs.map +0 -1
  98. package/dist/chunk-YG7W4CDT.js.map +0 -1
  99. package/dist/chunk-YS6TYXCP.mjs.map +0 -1
  100. /package/dist/{chunk-TKXU7ZXP.mjs.map → chunk-2L2ATCIK.mjs.map} +0 -0
  101. /package/dist/{chunk-7OMVZR5X.mjs.map → chunk-CJPFADO7.mjs.map} +0 -0
  102. /package/dist/{chunk-AOWUGDER.js.map → chunk-E27BGHCR.js.map} +0 -0
  103. /package/dist/{chunk-Y4LNTDZ2.mjs.map → chunk-FR26QD3N.mjs.map} +0 -0
  104. /package/dist/{chunk-SU6KOIVB.mjs.map → chunk-I3QG3QZL.mjs.map} +0 -0
  105. /package/dist/{chunk-S7AR3ROH.js.map → chunk-IE6EHYEG.js.map} +0 -0
  106. /package/dist/{chunk-Q5W3YGEB.js.map → chunk-IVD2ORDS.js.map} +0 -0
  107. /package/dist/{chunk-IBV23QOX.mjs.map → chunk-KIXPIIY5.mjs.map} +0 -0
  108. /package/dist/{chunk-AYJK7MSH.js.map → chunk-LLH2T5NT.js.map} +0 -0
  109. /package/dist/{chunk-TNRH2LRU.mjs.map → chunk-LXJBBRQ4.mjs.map} +0 -0
  110. /package/dist/{chunk-R2M4YLJ7.js.map → chunk-M2JQCKR7.js.map} +0 -0
  111. /package/dist/{chunk-RZXF4KSR.js.map → chunk-O2VSIMDY.js.map} +0 -0
  112. /package/dist/{chunk-EGKFC56F.js.map → chunk-QAKSH24Z.js.map} +0 -0
  113. /package/dist/{chunk-JQ456NCC.mjs.map → chunk-S46RTIDR.mjs.map} +0 -0
  114. /package/dist/{chunk-NESDQ4PF.mjs.map → chunk-TE4W25CA.mjs.map} +0 -0
  115. /package/dist/{chunk-AMBEX4N4.mjs.map → chunk-TUIJOZXZ.mjs.map} +0 -0
  116. /package/dist/{chunk-6UY23OOZ.js.map → chunk-VBCE6VHM.js.map} +0 -0
  117. /package/dist/{chunk-D6MUXDVI.js.map → chunk-XXSAESE7.js.map} +0 -0
package/CHANGELOG.md CHANGED
@@ -6,6 +6,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [9.0.0]
10
+ ### Added
11
+ - Add support for BIP-32-Ed25519 / CIP-3 key derivation ([#2408](https://github.com/MetaMask/snaps/pull/2408))
12
+ - The `ed25519Bip32` curve is now supported for `snap_getBip32Entropy` and `snap_getBip32PublicKey`
13
+
14
+ ### Changed
15
+ - **BREAKING:** Use hooks in `wallet_invokeSnap` instead of remapping the request to `wallet_snap` ([#2406](https://github.com/MetaMask/snaps/pull/2406))
16
+
17
+ ## [8.1.0]
18
+ ### Added
19
+ - Add JSX support for custom UI ([#2258](https://github.com/MetaMask/snaps/pull/2258))
20
+
9
21
  ## [8.0.0]
10
22
  ### Changed
11
23
  - **BREAKING:** Refactor to support changes to encryption ([#2316](https://github.com/MetaMask/snaps/pull/2316))
@@ -130,7 +142,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
130
142
  - The version of the package no longer needs to match the version of all other
131
143
  MetaMask Snaps packages.
132
144
 
133
- [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@8.0.0...HEAD
145
+ [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@9.0.0...HEAD
146
+ [9.0.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@8.1.0...@metamask/snaps-rpc-methods@9.0.0
147
+ [8.1.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@8.0.0...@metamask/snaps-rpc-methods@8.1.0
134
148
  [8.0.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@7.0.2...@metamask/snaps-rpc-methods@8.0.0
135
149
  [7.0.2]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@7.0.1...@metamask/snaps-rpc-methods@7.0.2
136
150
  [7.0.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@7.0.0...@metamask/snaps-rpc-methods@7.0.1
@@ -4,18 +4,18 @@ import { isObject } from "@metamask/utils";
4
4
  var invokeSnapSugarHandler = {
5
5
  methodNames: ["wallet_invokeSnap"],
6
6
  implementation: invokeSnapSugar,
7
- hookNames: void 0
7
+ hookNames: {
8
+ invokeSnap: true
9
+ }
8
10
  };
9
- function invokeSnapSugar(req, _res, next, end) {
10
- let params;
11
+ async function invokeSnapSugar(req, res, _next, end, { invokeSnap }) {
11
12
  try {
12
- params = getValidatedParams(req.params);
13
+ const params = getValidatedParams(req.params);
14
+ res.result = await invokeSnap(params);
13
15
  } catch (error) {
14
16
  return end(error);
15
17
  }
16
- req.method = "wallet_snap";
17
- req.params = params;
18
- return next();
18
+ return end();
19
19
  }
20
20
  function getValidatedParams(params) {
21
21
  if (!isObject(params)) {
@@ -42,4 +42,4 @@ export {
42
42
  invokeSnapSugar,
43
43
  getValidatedParams
44
44
  };
45
- //# sourceMappingURL=chunk-MXCJWR45.mjs.map
45
+ //# sourceMappingURL=chunk-2CTOCP34.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/permitted/invokeSnapSugar.ts"],"sourcesContent":["import type {\n JsonRpcEngineEndCallback,\n JsonRpcEngineNextCallback,\n} from '@metamask/json-rpc-engine';\nimport type { PermittedHandlerExport } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type { InvokeSnapParams, InvokeSnapResult } from '@metamask/snaps-sdk';\nimport type { JsonRpcRequest, PendingJsonRpcResponse } from '@metamask/utils';\nimport { isObject } from '@metamask/utils';\n\n/**\n * `wallet_invokeSnap` attempts to invoke an RPC method of the specified Snap.\n */\nexport const invokeSnapSugarHandler: PermittedHandlerExport<\n InvokeSnapSugarHooks,\n InvokeSnapParams,\n InvokeSnapResult\n> = {\n methodNames: ['wallet_invokeSnap'],\n implementation: invokeSnapSugar,\n hookNames: {\n invokeSnap: true,\n },\n};\n\nexport type InvokeSnapSugarHooks = {\n invokeSnap: (params: InvokeSnapParams) => Promise<InvokeSnapResult>;\n};\n\n/**\n * The `wallet_invokeSnap` method implementation.\n * Effectively calls `wallet_snap` under the hood.\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.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param hooks - The RPC method hooks.\n * @param hooks.invokeSnap - A function to invoke a snap designated by its parameters,\n * bound to the requesting origin.\n * @returns Nothing.\n * @throws If the params are invalid.\n */\nexport async function invokeSnapSugar(\n req: JsonRpcRequest<InvokeSnapParams>,\n res: PendingJsonRpcResponse<InvokeSnapResult>,\n _next: JsonRpcEngineNextCallback,\n end: JsonRpcEngineEndCallback,\n { invokeSnap }: InvokeSnapSugarHooks,\n): Promise<void> {\n try {\n const params = getValidatedParams(req.params);\n res.result = await invokeSnap(params);\n } catch (error) {\n return end(error);\n }\n return end();\n}\n\n/**\n * Validates the wallet_invokeSnap 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 method parameter object.\n */\nexport function getValidatedParams(params: unknown): InvokeSnapParams {\n if (!isObject(params)) {\n throw rpcErrors.invalidParams({\n message: 'Expected params to be a single object.',\n });\n }\n\n const { snapId, request } = params;\n\n if (!snapId || typeof snapId !== 'string' || snapId === '') {\n throw rpcErrors.invalidParams({\n message: 'Must specify a valid snap ID.',\n });\n }\n\n if (!isObject(request)) {\n throw rpcErrors.invalidParams({\n message: 'Expected request to be a single object.',\n });\n }\n\n return params as InvokeSnapParams;\n}\n"],"mappings":";AAKA,SAAS,iBAAiB;AAG1B,SAAS,gBAAgB;AAKlB,IAAM,yBAIT;AAAA,EACF,aAAa,CAAC,mBAAmB;AAAA,EACjC,gBAAgB;AAAA,EAChB,WAAW;AAAA,IACT,YAAY;AAAA,EACd;AACF;AAoBA,eAAsB,gBACpB,KACA,KACA,OACA,KACA,EAAE,WAAW,GACE;AACf,MAAI;AACF,UAAM,SAAS,mBAAmB,IAAI,MAAM;AAC5C,QAAI,SAAS,MAAM,WAAW,MAAM;AAAA,EACtC,SAAS,OAAO;AACd,WAAO,IAAI,KAAK;AAAA,EAClB;AACA,SAAO,IAAI;AACb;AASO,SAAS,mBAAmB,QAAmC;AACpE,MAAI,CAAC,SAAS,MAAM,GAAG;AACrB,UAAM,UAAU,cAAc;AAAA,MAC5B,SAAS;AAAA,IACX,CAAC;AAAA,EACH;AAEA,QAAM,EAAE,QAAQ,QAAQ,IAAI;AAE5B,MAAI,CAAC,UAAU,OAAO,WAAW,YAAY,WAAW,IAAI;AAC1D,UAAM,UAAU,cAAc;AAAA,MAC5B,SAAS;AAAA,IACX,CAAC;AAAA,EACH;AAEA,MAAI,CAAC,SAAS,OAAO,GAAG;AACtB,UAAM,UAAU,cAAc;AAAA,MAC5B,SAAS;AAAA,IACX,CAAC;AAAA,EACH;AAEA,SAAO;AACT;","names":[]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getValidatedParams
3
- } from "./chunk-MXCJWR45.mjs";
3
+ } from "./chunk-2CTOCP34.mjs";
4
4
 
5
5
  // src/permitted/invokeKeyring.ts
6
6
  import { rpcErrors } from "@metamask/rpc-errors";
@@ -75,4 +75,4 @@ async function invokeKeyringImplementation(req, res, _next, end, {
75
75
  export {
76
76
  invokeKeyringHandler
77
77
  };
78
- //# sourceMappingURL=chunk-TKXU7ZXP.mjs.map
78
+ //# sourceMappingURL=chunk-2L2ATCIK.mjs.map
@@ -6,6 +6,7 @@ var _keytree = require('@metamask/key-tree');
6
6
 
7
7
 
8
8
 
9
+
9
10
  var _utils = require('@metamask/utils');
10
11
  var _sha3 = require('@noble/hashes/sha3');
11
12
  var HARDENED_VALUE = 2147483648;
@@ -54,10 +55,16 @@ async function deriveEntropy({
54
55
  return _utils.add0x.call(void 0, privateKey);
55
56
  }
56
57
  function getPathPrefix(curve) {
57
- if (curve === "secp256k1") {
58
- return "bip32";
58
+ switch (curve) {
59
+ case "secp256k1":
60
+ return "bip32";
61
+ case "ed25519":
62
+ return "slip10";
63
+ case "ed25519Bip32":
64
+ return "cip3";
65
+ default:
66
+ return _utils.assertExhaustive.call(void 0, curve);
59
67
  }
60
- return "slip10";
61
68
  }
62
69
  async function getNode({
63
70
  curve,
@@ -80,4 +87,4 @@ async function getNode({
80
87
 
81
88
 
82
89
  exports.selectHooks = selectHooks; exports.deriveEntropy = deriveEntropy; exports.getPathPrefix = getPathPrefix; exports.getNode = getNode;
83
- //# sourceMappingURL=chunk-YG7W4CDT.js.map
90
+ //# sourceMappingURL=chunk-33MTKZ4H.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils.ts"],"names":[],"mappings":";AAMA,SAAS,kBAAkB;AAG3B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,cAAc,iBAAiB;AAExC,IAAM,iBAAiB;AAuBhB,SAAS,YAId,OACA,WACmC;AACnC,MAAI,WAAW;AACb,WAAO,OAAO,KAAK,SAAS,EAAE;AAAA,MAC5B,CAAC,YAAY,cAAc;AACzB,cAAM,WAAW;AACjB,mBAAW,QAAQ,IAAI,MAAM,QAAQ;AACrC,eAAO;AAAA,MACT;AAAA,MACA,CAAC;AAAA,IACH;AAAA,EACF;AACA,SAAO;AACT;AASA,SAAS,uBAAuB,MAAuC;AACrE,QAAM,QAA6B,CAAC;AACpC,QAAM,OAAO,eAAe,IAAI;AAEhC,WAAS,QAAQ,GAAG,QAAQ,GAAG,SAAS;AACtC,UAAM,SAAS,KAAK,UAAU,QAAQ,CAAC;AAMvC,UAAM,aAAa,SAAS,oBAAoB;AAChD,UAAM,KAAK,SAAS,YAAY,cAAc,GAAY;AAAA,EAC5D;AAEA,SAAO;AACT;AAwCA,eAAsB,cAAc;AAAA,EAClC;AAAA,EACA,OAAO;AAAA,EACP;AAAA,EACA;AACF,GAAuC;AACrC,QAAM,aAAa,cAAc,KAAK;AACtC,QAAM,YAAY,cAAc,IAAI;AAGpC,QAAM,OAAO,UAAU,YAAY,CAAC,YAAY,UAAU,SAAS,CAAC,CAAC,CAAC;AACtE,QAAM,yBAAyB,uBAAuB,IAAI;AAG1D,QAAM,EAAE,WAAW,IAAI,MAAM,WAAW,mBAAmB;AAAA,IACzD,gBAAgB;AAAA,MACd;AAAA,MACA,SAAS,KAAK;AAAA,MACd,GAAG;AAAA,IACL;AAAA,IACA,OAAO;AAAA,EACT,CAAC;AAGD,SAAO,YAAY,+BAA+B;AAElD,SAAO,MAAM,UAAU;AACzB;AAiBO,SAAS,cACd,OAC6B;AAC7B,UAAQ,OAAO;AAAA,IACb,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT;AACE,aAAO,iBAAiB,KAAK;AAAA,EACjC;AACF;AAqBA,eAAsB,QAAQ;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AACF,GAAgB;AACd,QAAM,SAAS,cAAc,KAAK;AAElC,SAAO,MAAM,WAAW,mBAAmB;AAAA,IACzC;AAAA,IACA,gBAAgB;AAAA,MACd;AAAA,MACA,GAAI,KAAK,MAAM,CAAC,EAAE,IAAI,CAAC,UAAU,GAAG,MAAM,IAAI,KAAK,EAAE;AAAA,IAGvD;AAAA,EACF,CAAC;AACH","sourcesContent":["import type {\n HardenedBIP32Node,\n BIP32Node,\n SLIP10PathNode,\n SupportedCurve,\n} from '@metamask/key-tree';\nimport { SLIP10Node } from '@metamask/key-tree';\nimport type { MagicValue } from '@metamask/snaps-utils';\nimport type { Hex } from '@metamask/utils';\nimport {\n assertExhaustive,\n add0x,\n assert,\n concatBytes,\n createDataView,\n stringToBytes,\n} from '@metamask/utils';\nimport { keccak_256 as keccak256 } from '@noble/hashes/sha3';\n\nconst HARDENED_VALUE = 0x80000000;\n\n/**\n * Maps an interface with method hooks to an object, using the keys of the\n * interface, and `true` as value. This ensures that the `methodHooks` object\n * has the same values as the interface.\n */\nexport type MethodHooksObject<HooksType extends Record<string, unknown>> = {\n [Key in keyof HooksType]: true;\n};\n\n/**\n * Returns the subset of the specified `hooks` that are included in the\n * `hookNames` object. This is a Principle of Least Authority (POLA) measure\n * to ensure that each RPC method implementation only has access to the\n * API \"hooks\" it needs to do its job.\n *\n * @param hooks - The hooks to select from.\n * @param hookNames - The names of the hooks to select.\n * @returns The selected hooks.\n * @template Hooks - The hooks to select from.\n * @template HookName - The names of the hooks to select.\n */\nexport function selectHooks<\n Hooks extends Record<string, unknown>,\n HookName extends keyof Hooks,\n>(\n hooks: Hooks,\n hookNames?: Record<HookName, boolean>,\n): Pick<Hooks, HookName> | undefined {\n if (hookNames) {\n return Object.keys(hookNames).reduce<Partial<Pick<Hooks, HookName>>>(\n (hookSubset, _hookName) => {\n const hookName = _hookName as HookName;\n hookSubset[hookName] = hooks[hookName];\n return hookSubset;\n },\n {},\n ) as Pick<Hooks, HookName>;\n }\n return undefined;\n}\n\n/**\n * Get a BIP-32 derivation path array from a hash, which is compatible with\n * `@metamask/key-tree`. The hash is assumed to be 32 bytes long.\n *\n * @param hash - The hash to derive indices from.\n * @returns The derived indices as a {@link HardenedBIP32Node} array.\n */\nfunction getDerivationPathArray(hash: Uint8Array): HardenedBIP32Node[] {\n const array: HardenedBIP32Node[] = [];\n const view = createDataView(hash);\n\n for (let index = 0; index < 8; index++) {\n const uint32 = view.getUint32(index * 4);\n\n // This is essentially `index | 0x80000000`. Because JavaScript numbers are\n // signed, we use the bitwise unsigned right shift operator to ensure that\n // the result is a positive number.\n // eslint-disable-next-line no-bitwise\n const pathIndex = (uint32 | HARDENED_VALUE) >>> 0;\n array.push(`bip32:${pathIndex - HARDENED_VALUE}'` as const);\n }\n\n return array;\n}\n\ntype DeriveEntropyOptions = {\n /**\n * The input value to derive entropy from.\n */\n input: string;\n\n /**\n * An optional salt to use when deriving entropy.\n */\n salt?: string;\n\n /**\n * The mnemonic phrase to use for entropy derivation.\n */\n mnemonicPhrase: Uint8Array;\n\n /**\n * A hardened BIP-32 index, which is used to derive the root key from the\n * mnemonic phrase.\n */\n magic: MagicValue;\n};\n\n/**\n * Derive entropy from the given mnemonic phrase and salt.\n *\n * This is based on the reference implementation of\n * [SIP-6](https://metamask.github.io/SIPs/SIPS/sip-6).\n *\n * @param options - The options for entropy derivation.\n * @param options.input - The input value to derive entropy from.\n * @param options.salt - An optional salt to use when deriving entropy.\n * @param options.mnemonicPhrase - The mnemonic phrase to use for entropy\n * derivation.\n * @param options.magic - A hardened BIP-32 index, which is used to derive the\n * root key from the mnemonic phrase.\n * @returns The derived entropy.\n */\nexport async function deriveEntropy({\n input,\n salt = '',\n mnemonicPhrase,\n magic,\n}: DeriveEntropyOptions): Promise<Hex> {\n const inputBytes = stringToBytes(input);\n const saltBytes = stringToBytes(salt);\n\n // Get the derivation path from the snap ID.\n const hash = keccak256(concatBytes([inputBytes, keccak256(saltBytes)]));\n const computedDerivationPath = getDerivationPathArray(hash);\n\n // Derive the private key using BIP-32.\n const { privateKey } = await SLIP10Node.fromDerivationPath({\n derivationPath: [\n mnemonicPhrase,\n `bip32:${magic}`,\n ...computedDerivationPath,\n ],\n curve: 'secp256k1',\n });\n\n // This should never happen, but this keeps TypeScript happy.\n assert(privateKey, 'Failed to derive the entropy.');\n\n return add0x(privateKey);\n}\n\n/**\n * Get the path prefix to use for key derivation in `key-tree`. This assumes the\n * following:\n *\n * - The Secp256k1 curve always uses the BIP-32 specification.\n * - The Ed25519 curve always uses the SLIP-10 specification.\n * - The BIP-32-Ed25519 curve always uses the CIP-3 specification.\n *\n * While this does not matter in most situations (no known case at the time of\n * writing), `key-tree` requires a specific specification to be used.\n *\n * @param curve - The curve to get the path prefix for. The curve is NOT\n * validated by this function.\n * @returns The path prefix, i.e., `bip32` or `slip10`.\n */\nexport function getPathPrefix(\n curve: SupportedCurve,\n): 'bip32' | 'slip10' | 'cip3' {\n switch (curve) {\n case 'secp256k1':\n return 'bip32';\n case 'ed25519':\n return 'slip10';\n case 'ed25519Bip32':\n return 'cip3';\n default:\n return assertExhaustive(curve);\n }\n}\n\ntype GetNodeArgs = {\n curve: SupportedCurve;\n secretRecoveryPhrase: Uint8Array;\n path: string[];\n};\n\n/**\n * Get a `key-tree`-compatible node.\n *\n * Note: This function assumes that all the parameters have been validated\n * beforehand.\n *\n * @param options - The derivation options.\n * @param options.curve - The curve to use for derivation.\n * @param options.secretRecoveryPhrase - The secret recovery phrase to use for\n * derivation.\n * @param options.path - The derivation path to use as array, starting with an\n * \"m\" as the first item.\n */\nexport async function getNode({\n curve,\n secretRecoveryPhrase,\n path,\n}: GetNodeArgs) {\n const prefix = getPathPrefix(curve);\n\n return await SLIP10Node.fromDerivationPath({\n curve,\n derivationPath: [\n secretRecoveryPhrase,\n ...(path.slice(1).map((index) => `${prefix}:${index}`) as\n | BIP32Node[]\n | SLIP10PathNode[]),\n ],\n });\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkYG7W4CDTjs = require('./chunk-YG7W4CDT.js');
3
+ var _chunk33MTKZ4Hjs = require('./chunk-33MTKZ4H.js');
4
4
 
5
5
  // src/restricted/getBip32PublicKey.ts
6
6
  var _permissioncontroller = require('@metamask/permission-controller');
@@ -9,6 +9,7 @@ var _rpcerrors = require('@metamask/rpc-errors');
9
9
 
10
10
 
11
11
 
12
+
12
13
  var _snapsutils = require('@metamask/snaps-utils');
13
14
  var _utils = require('@metamask/utils');
14
15
  var _superstruct = require('superstruct');
@@ -16,7 +17,7 @@ var targetName = "snap_getBip32PublicKey";
16
17
  var Bip32PublicKeyArgsStruct = _snapsutils.bip32entropy.call(void 0,
17
18
  _superstruct.object.call(void 0, {
18
19
  path: _snapsutils.Bip32PathStruct,
19
- curve: _superstruct.enums.call(void 0, ["ed25519", "secp256k1"]),
20
+ curve: _snapsutils.CurveStruct,
20
21
  compressed: _superstruct.optional.call(void 0, _superstruct.boolean.call(void 0, ))
21
22
  })
22
23
  );
@@ -58,7 +59,7 @@ function getBip32PublicKeyImplementation({
58
59
  _rpcerrors.rpcErrors.invalidParams
59
60
  );
60
61
  const { params } = args;
61
- const node = await _chunkYG7W4CDTjs.getNode.call(void 0, {
62
+ const node = await _chunk33MTKZ4Hjs.getNode.call(void 0, {
62
63
  curve: params.curve,
63
64
  path: params.path,
64
65
  secretRecoveryPhrase: await getMnemonic()
@@ -75,4 +76,4 @@ function getBip32PublicKeyImplementation({
75
76
 
76
77
 
77
78
  exports.Bip32PublicKeyArgsStruct = Bip32PublicKeyArgsStruct; exports.getBip32PublicKeyBuilder = getBip32PublicKeyBuilder; exports.getBip32PublicKeyImplementation = getBip32PublicKeyImplementation;
78
- //# sourceMappingURL=chunk-LGUJMQC7.js.map
79
+ //# sourceMappingURL=chunk-4BPNRCZJ.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;AAEP,SAAS,oBAAoB;AAC7B,SAAS,SAAS,QAAQ,gBAAgB;AAK1C,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 type { NonEmptyArray } from '@metamask/utils';\nimport { assertStruct } from '@metamask/utils';\nimport { boolean, object, optional } from 'superstruct';\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,6 +1,6 @@
1
1
  // src/permitted/createInterface.ts
2
2
  import { rpcErrors } from "@metamask/rpc-errors";
3
- import { ComponentStruct } from "@metamask/snaps-sdk";
3
+ import { ComponentOrElementStruct } from "@metamask/snaps-sdk";
4
4
  import { StructError, create, object } from "superstruct";
5
5
  var hookNames = {
6
6
  createInterface: true
@@ -11,7 +11,7 @@ var createInterfaceHandler = {
11
11
  hookNames
12
12
  };
13
13
  var CreateInterfaceParametersStruct = object({
14
- ui: ComponentStruct
14
+ ui: ComponentOrElementStruct
15
15
  });
16
16
  async function getCreateInterfaceImplementation(req, res, _next, end, { createInterface }) {
17
17
  const { params } = req;
@@ -40,4 +40,4 @@ function getValidatedParams(params) {
40
40
  export {
41
41
  createInterfaceHandler
42
42
  };
43
- //# sourceMappingURL=chunk-WLDEPJGG.mjs.map
43
+ //# sourceMappingURL=chunk-634BK2VP.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/permitted/createInterface.ts"],"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 CreateInterfaceParams,\n CreateInterfaceResult,\n JsonRpcRequest,\n ComponentOrElement,\n} from '@metamask/snaps-sdk';\nimport { ComponentOrElementStruct } from '@metamask/snaps-sdk';\nimport { type InferMatching } from '@metamask/snaps-utils';\nimport type { PendingJsonRpcResponse } from '@metamask/utils';\nimport { StructError, create, object } from 'superstruct';\n\nimport type { MethodHooksObject } from '../utils';\n\nconst hookNames: MethodHooksObject<CreateInterfaceMethodHooks> = {\n createInterface: true,\n};\n\nexport type CreateInterfaceMethodHooks = {\n /**\n * @param ui - The UI components.\n * @returns The unique identifier of the interface.\n */\n createInterface: (ui: ComponentOrElement) => Promise<string>;\n};\n\nexport const createInterfaceHandler: PermittedHandlerExport<\n CreateInterfaceMethodHooks,\n CreateInterfaceParameters,\n CreateInterfaceResult\n> = {\n methodNames: ['snap_createInterface'],\n implementation: getCreateInterfaceImplementation,\n hookNames,\n};\n\nconst CreateInterfaceParametersStruct = object({\n ui: ComponentOrElementStruct,\n});\n\nexport type CreateInterfaceParameters = InferMatching<\n typeof CreateInterfaceParametersStruct,\n CreateInterfaceParams\n>;\n\n/**\n * The `snap_createInterface` 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.createInterface - The function to create the interface.\n * @returns Nothing.\n */\nasync function getCreateInterfaceImplementation(\n req: JsonRpcRequest<CreateInterfaceParameters>,\n res: PendingJsonRpcResponse<CreateInterfaceResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n { createInterface }: CreateInterfaceMethodHooks,\n): Promise<void> {\n const { params } = req;\n\n try {\n const validatedParams = getValidatedParams(params);\n\n const { ui } = validatedParams;\n\n res.result = await createInterface(ui);\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n\n/**\n * Validate the createInterface 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 createInterface method parameter object.\n */\nfunction getValidatedParams(params: unknown): CreateInterfaceParameters {\n try {\n return create(params, CreateInterfaceParametersStruct);\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"],"mappings":";AAEA,SAAS,iBAAiB;AAO1B,SAAS,gCAAgC;AAGzC,SAAS,aAAa,QAAQ,cAAc;AAI5C,IAAM,YAA2D;AAAA,EAC/D,iBAAiB;AACnB;AAUO,IAAM,yBAIT;AAAA,EACF,aAAa,CAAC,sBAAsB;AAAA,EACpC,gBAAgB;AAAA,EAChB;AACF;AAEA,IAAM,kCAAkC,OAAO;AAAA,EAC7C,IAAI;AACN,CAAC;AAmBD,eAAe,iCACb,KACA,KACA,OACA,KACA,EAAE,gBAAgB,GACH;AACf,QAAM,EAAE,OAAO,IAAI;AAEnB,MAAI;AACF,UAAM,kBAAkB,mBAAmB,MAAM;AAEjD,UAAM,EAAE,GAAG,IAAI;AAEf,QAAI,SAAS,MAAM,gBAAgB,EAAE;AAAA,EACvC,SAAS,OAAO;AACd,WAAO,IAAI,KAAK;AAAA,EAClB;AAEA,SAAO,IAAI;AACb;AASA,SAAS,mBAAmB,QAA4C;AACtE,MAAI;AACF,WAAO,OAAO,QAAQ,+BAA+B;AAAA,EACvD,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;","names":[]}
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  methodHandlers
3
- } from "./chunk-JQ456NCC.mjs";
3
+ } from "./chunk-S46RTIDR.mjs";
4
4
  import {
5
5
  selectHooks
6
- } from "./chunk-SGQXD5K7.mjs";
6
+ } from "./chunk-W33UWNA2.mjs";
7
7
 
8
8
  // src/permitted/middleware.ts
9
9
  import { rpcErrors } from "@metamask/rpc-errors";
@@ -36,4 +36,4 @@ function createSnapsMethodMiddleware(isSnap, hooks) {
36
36
  export {
37
37
  createSnapsMethodMiddleware
38
38
  };
39
- //# sourceMappingURL=chunk-7OMVZR5X.mjs.map
39
+ //# sourceMappingURL=chunk-CJPFADO7.mjs.map
@@ -12,7 +12,7 @@ var updateInterfaceHandler = {
12
12
  };
13
13
  var UpdateInterfaceParametersStruct = _superstruct.object.call(void 0, {
14
14
  id: _superstruct.string.call(void 0, ),
15
- ui: _snapssdk.ComponentStruct
15
+ ui: _snapssdk.ComponentOrElementStruct
16
16
  });
17
17
  async function getUpdateInterfaceImplementation(req, res, _next, end, { updateInterface }) {
18
18
  const { params } = req;
@@ -42,4 +42,4 @@ function getValidatedParams(params) {
42
42
 
43
43
 
44
44
  exports.updateInterfaceHandler = updateInterfaceHandler;
45
- //# sourceMappingURL=chunk-GP5KW5FU.js.map
45
+ //# sourceMappingURL=chunk-D5WQBUZB.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/permitted/updateInterface.ts"],"names":[],"mappings":";AAEA,SAAS,iBAAiB;AAO1B,SAAS,gCAAgC;AAGzC,SAAS,aAAa,QAAQ,QAAQ,cAAc;AAIpD,IAAM,YAA2D;AAAA,EAC/D,iBAAiB;AACnB;AAUO,IAAM,yBAIT;AAAA,EACF,aAAa,CAAC,sBAAsB;AAAA,EACpC,gBAAgB;AAAA,EAChB;AACF;AAEA,IAAM,kCAAkC,OAAO;AAAA,EAC7C,IAAI,OAAO;AAAA,EACX,IAAI;AACN,CAAC;AAmBD,eAAe,iCACb,KACA,KACA,OACA,KACA,EAAE,gBAAgB,GACH;AACf,QAAM,EAAE,OAAO,IAAI;AAEnB,MAAI;AACF,UAAM,kBAAkB,mBAAmB,MAAM;AAEjD,UAAM,EAAE,IAAI,GAAG,IAAI;AAEnB,UAAM,gBAAgB,IAAI,EAAE;AAC5B,QAAI,SAAS;AAAA,EACf,SAAS,OAAO;AACd,WAAO,IAAI,KAAK;AAAA,EAClB;AAEA,SAAO,IAAI;AACb;AASA,SAAS,mBAAmB,QAA4C;AACtE,MAAI;AACF,WAAO,OAAO,QAAQ,+BAA+B;AAAA,EACvD,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 UpdateInterfaceParams,\n UpdateInterfaceResult,\n JsonRpcRequest,\n ComponentOrElement,\n} from '@metamask/snaps-sdk';\nimport { ComponentOrElementStruct } from '@metamask/snaps-sdk';\nimport { type InferMatching } from '@metamask/snaps-utils';\nimport type { PendingJsonRpcResponse } from '@metamask/utils';\nimport { StructError, create, object, string } from 'superstruct';\n\nimport type { MethodHooksObject } from '../utils';\n\nconst hookNames: MethodHooksObject<UpdateInterfaceMethodHooks> = {\n updateInterface: true,\n};\n\nexport type UpdateInterfaceMethodHooks = {\n /**\n * @param id - The interface ID.\n * @param ui - The UI components.\n */\n updateInterface: (id: string, ui: ComponentOrElement) => Promise<void>;\n};\n\nexport const updateInterfaceHandler: PermittedHandlerExport<\n UpdateInterfaceMethodHooks,\n UpdateInterfaceParameters,\n UpdateInterfaceResult\n> = {\n methodNames: ['snap_updateInterface'],\n implementation: getUpdateInterfaceImplementation,\n hookNames,\n};\n\nconst UpdateInterfaceParametersStruct = object({\n id: string(),\n ui: ComponentOrElementStruct,\n});\n\nexport type UpdateInterfaceParameters = InferMatching<\n typeof UpdateInterfaceParametersStruct,\n UpdateInterfaceParams\n>;\n\n/**\n * The `snap_updateInterface` 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.updateInterface - The function to update the interface.\n * @returns Nothing.\n */\nasync function getUpdateInterfaceImplementation(\n req: JsonRpcRequest<UpdateInterfaceParameters>,\n res: PendingJsonRpcResponse<UpdateInterfaceResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n { updateInterface }: UpdateInterfaceMethodHooks,\n): Promise<void> {\n const { params } = req;\n\n try {\n const validatedParams = getValidatedParams(params);\n\n const { id, ui } = validatedParams;\n\n await updateInterface(id, ui);\n res.result = null;\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n\n/**\n * Validate the updateInterface 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 updateInterface method parameter object.\n */\nfunction getValidatedParams(params: unknown): UpdateInterfaceParameters {\n try {\n return create(params, UpdateInterfaceParametersStruct);\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"]}
@@ -4,18 +4,18 @@ var _utils = require('@metamask/utils');
4
4
  var invokeSnapSugarHandler = {
5
5
  methodNames: ["wallet_invokeSnap"],
6
6
  implementation: invokeSnapSugar,
7
- hookNames: void 0
7
+ hookNames: {
8
+ invokeSnap: true
9
+ }
8
10
  };
9
- function invokeSnapSugar(req, _res, next, end) {
10
- let params;
11
+ async function invokeSnapSugar(req, res, _next, end, { invokeSnap }) {
11
12
  try {
12
- params = getValidatedParams(req.params);
13
+ const params = getValidatedParams(req.params);
14
+ res.result = await invokeSnap(params);
13
15
  } catch (error) {
14
16
  return end(error);
15
17
  }
16
- req.method = "wallet_snap";
17
- req.params = params;
18
- return next();
18
+ return end();
19
19
  }
20
20
  function getValidatedParams(params) {
21
21
  if (!_utils.isObject.call(void 0, params)) {
@@ -42,4 +42,4 @@ function getValidatedParams(params) {
42
42
 
43
43
 
44
44
  exports.invokeSnapSugarHandler = invokeSnapSugarHandler; exports.invokeSnapSugar = invokeSnapSugar; exports.getValidatedParams = getValidatedParams;
45
- //# sourceMappingURL=chunk-IDZGMGIB.js.map
45
+ //# sourceMappingURL=chunk-DLVPMPRZ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/permitted/invokeSnapSugar.ts"],"names":[],"mappings":";AAKA,SAAS,iBAAiB;AAG1B,SAAS,gBAAgB;AAKlB,IAAM,yBAIT;AAAA,EACF,aAAa,CAAC,mBAAmB;AAAA,EACjC,gBAAgB;AAAA,EAChB,WAAW;AAAA,IACT,YAAY;AAAA,EACd;AACF;AAoBA,eAAsB,gBACpB,KACA,KACA,OACA,KACA,EAAE,WAAW,GACE;AACf,MAAI;AACF,UAAM,SAAS,mBAAmB,IAAI,MAAM;AAC5C,QAAI,SAAS,MAAM,WAAW,MAAM;AAAA,EACtC,SAAS,OAAO;AACd,WAAO,IAAI,KAAK;AAAA,EAClB;AACA,SAAO,IAAI;AACb;AASO,SAAS,mBAAmB,QAAmC;AACpE,MAAI,CAAC,SAAS,MAAM,GAAG;AACrB,UAAM,UAAU,cAAc;AAAA,MAC5B,SAAS;AAAA,IACX,CAAC;AAAA,EACH;AAEA,QAAM,EAAE,QAAQ,QAAQ,IAAI;AAE5B,MAAI,CAAC,UAAU,OAAO,WAAW,YAAY,WAAW,IAAI;AAC1D,UAAM,UAAU,cAAc;AAAA,MAC5B,SAAS;AAAA,IACX,CAAC;AAAA,EACH;AAEA,MAAI,CAAC,SAAS,OAAO,GAAG;AACtB,UAAM,UAAU,cAAc;AAAA,MAC5B,SAAS;AAAA,IACX,CAAC;AAAA,EACH;AAEA,SAAO;AACT","sourcesContent":["import type {\n JsonRpcEngineEndCallback,\n JsonRpcEngineNextCallback,\n} from '@metamask/json-rpc-engine';\nimport type { PermittedHandlerExport } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type { InvokeSnapParams, InvokeSnapResult } from '@metamask/snaps-sdk';\nimport type { JsonRpcRequest, PendingJsonRpcResponse } from '@metamask/utils';\nimport { isObject } from '@metamask/utils';\n\n/**\n * `wallet_invokeSnap` attempts to invoke an RPC method of the specified Snap.\n */\nexport const invokeSnapSugarHandler: PermittedHandlerExport<\n InvokeSnapSugarHooks,\n InvokeSnapParams,\n InvokeSnapResult\n> = {\n methodNames: ['wallet_invokeSnap'],\n implementation: invokeSnapSugar,\n hookNames: {\n invokeSnap: true,\n },\n};\n\nexport type InvokeSnapSugarHooks = {\n invokeSnap: (params: InvokeSnapParams) => Promise<InvokeSnapResult>;\n};\n\n/**\n * The `wallet_invokeSnap` method implementation.\n * Effectively calls `wallet_snap` under the hood.\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.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param hooks - The RPC method hooks.\n * @param hooks.invokeSnap - A function to invoke a snap designated by its parameters,\n * bound to the requesting origin.\n * @returns Nothing.\n * @throws If the params are invalid.\n */\nexport async function invokeSnapSugar(\n req: JsonRpcRequest<InvokeSnapParams>,\n res: PendingJsonRpcResponse<InvokeSnapResult>,\n _next: JsonRpcEngineNextCallback,\n end: JsonRpcEngineEndCallback,\n { invokeSnap }: InvokeSnapSugarHooks,\n): Promise<void> {\n try {\n const params = getValidatedParams(req.params);\n res.result = await invokeSnap(params);\n } catch (error) {\n return end(error);\n }\n return end();\n}\n\n/**\n * Validates the wallet_invokeSnap 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 method parameter object.\n */\nexport function getValidatedParams(params: unknown): InvokeSnapParams {\n if (!isObject(params)) {\n throw rpcErrors.invalidParams({\n message: 'Expected params to be a single object.',\n });\n }\n\n const { snapId, request } = params;\n\n if (!snapId || typeof snapId !== 'string' || snapId === '') {\n throw rpcErrors.invalidParams({\n message: 'Must specify a valid snap ID.',\n });\n }\n\n if (!isObject(request)) {\n throw rpcErrors.invalidParams({\n message: 'Expected request to be a single object.',\n });\n }\n\n return params as InvokeSnapParams;\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkIDZGMGIBjs = require('./chunk-IDZGMGIB.js');
3
+ var _chunkDLVPMPRZjs = require('./chunk-DLVPMPRZ.js');
4
4
 
5
5
  // src/permitted/invokeKeyring.ts
6
6
  var _rpcerrors = require('@metamask/rpc-errors');
@@ -25,7 +25,7 @@ async function invokeKeyringImplementation(req, res, _next, end, {
25
25
  }) {
26
26
  let params;
27
27
  try {
28
- params = _chunkIDZGMGIBjs.getValidatedParams.call(void 0, req.params);
28
+ params = _chunkDLVPMPRZjs.getValidatedParams.call(void 0, req.params);
29
29
  } catch (error) {
30
30
  return end(error);
31
31
  }
@@ -75,4 +75,4 @@ async function invokeKeyringImplementation(req, res, _next, end, {
75
75
 
76
76
 
77
77
  exports.invokeKeyringHandler = invokeKeyringHandler;
78
- //# sourceMappingURL=chunk-AOWUGDER.js.map
78
+ //# sourceMappingURL=chunk-E27BGHCR.js.map
@@ -15,10 +15,10 @@ import {
15
15
  } from "./chunk-LR7UR4YU.mjs";
16
16
  import {
17
17
  getBip32EntropyBuilder
18
- } from "./chunk-TNRH2LRU.mjs";
18
+ } from "./chunk-LXJBBRQ4.mjs";
19
19
  import {
20
20
  getBip32PublicKeyBuilder
21
- } from "./chunk-6WUIFFMQ.mjs";
21
+ } from "./chunk-R3DRYUNH.mjs";
22
22
  import {
23
23
  invokeSnapBuilder
24
24
  } from "./chunk-VVBTXSID.mjs";
@@ -40,4 +40,4 @@ export {
40
40
  caveatSpecifications,
41
41
  caveatMappers
42
42
  };
43
- //# sourceMappingURL=chunk-Y4LNTDZ2.mjs.map
43
+ //# sourceMappingURL=chunk-FR26QD3N.mjs.map
@@ -1,6 +1,6 @@
1
1
  // src/permitted/updateInterface.ts
2
2
  import { rpcErrors } from "@metamask/rpc-errors";
3
- import { ComponentStruct } from "@metamask/snaps-sdk";
3
+ import { ComponentOrElementStruct } from "@metamask/snaps-sdk";
4
4
  import { StructError, create, object, string } from "superstruct";
5
5
  var hookNames = {
6
6
  updateInterface: true
@@ -12,7 +12,7 @@ var updateInterfaceHandler = {
12
12
  };
13
13
  var UpdateInterfaceParametersStruct = object({
14
14
  id: string(),
15
- ui: ComponentStruct
15
+ ui: ComponentOrElementStruct
16
16
  });
17
17
  async function getUpdateInterfaceImplementation(req, res, _next, end, { updateInterface }) {
18
18
  const { params } = req;
@@ -42,4 +42,4 @@ function getValidatedParams(params) {
42
42
  export {
43
43
  updateInterfaceHandler
44
44
  };
45
- //# sourceMappingURL=chunk-YS6TYXCP.mjs.map
45
+ //# sourceMappingURL=chunk-GVJLWGSI.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/permitted/updateInterface.ts"],"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 UpdateInterfaceParams,\n UpdateInterfaceResult,\n JsonRpcRequest,\n ComponentOrElement,\n} from '@metamask/snaps-sdk';\nimport { ComponentOrElementStruct } from '@metamask/snaps-sdk';\nimport { type InferMatching } from '@metamask/snaps-utils';\nimport type { PendingJsonRpcResponse } from '@metamask/utils';\nimport { StructError, create, object, string } from 'superstruct';\n\nimport type { MethodHooksObject } from '../utils';\n\nconst hookNames: MethodHooksObject<UpdateInterfaceMethodHooks> = {\n updateInterface: true,\n};\n\nexport type UpdateInterfaceMethodHooks = {\n /**\n * @param id - The interface ID.\n * @param ui - The UI components.\n */\n updateInterface: (id: string, ui: ComponentOrElement) => Promise<void>;\n};\n\nexport const updateInterfaceHandler: PermittedHandlerExport<\n UpdateInterfaceMethodHooks,\n UpdateInterfaceParameters,\n UpdateInterfaceResult\n> = {\n methodNames: ['snap_updateInterface'],\n implementation: getUpdateInterfaceImplementation,\n hookNames,\n};\n\nconst UpdateInterfaceParametersStruct = object({\n id: string(),\n ui: ComponentOrElementStruct,\n});\n\nexport type UpdateInterfaceParameters = InferMatching<\n typeof UpdateInterfaceParametersStruct,\n UpdateInterfaceParams\n>;\n\n/**\n * The `snap_updateInterface` 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.updateInterface - The function to update the interface.\n * @returns Nothing.\n */\nasync function getUpdateInterfaceImplementation(\n req: JsonRpcRequest<UpdateInterfaceParameters>,\n res: PendingJsonRpcResponse<UpdateInterfaceResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n { updateInterface }: UpdateInterfaceMethodHooks,\n): Promise<void> {\n const { params } = req;\n\n try {\n const validatedParams = getValidatedParams(params);\n\n const { id, ui } = validatedParams;\n\n await updateInterface(id, ui);\n res.result = null;\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n\n/**\n * Validate the updateInterface 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 updateInterface method parameter object.\n */\nfunction getValidatedParams(params: unknown): UpdateInterfaceParameters {\n try {\n return create(params, UpdateInterfaceParametersStruct);\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"],"mappings":";AAEA,SAAS,iBAAiB;AAO1B,SAAS,gCAAgC;AAGzC,SAAS,aAAa,QAAQ,QAAQ,cAAc;AAIpD,IAAM,YAA2D;AAAA,EAC/D,iBAAiB;AACnB;AAUO,IAAM,yBAIT;AAAA,EACF,aAAa,CAAC,sBAAsB;AAAA,EACpC,gBAAgB;AAAA,EAChB;AACF;AAEA,IAAM,kCAAkC,OAAO;AAAA,EAC7C,IAAI,OAAO;AAAA,EACX,IAAI;AACN,CAAC;AAmBD,eAAe,iCACb,KACA,KACA,OACA,KACA,EAAE,gBAAgB,GACH;AACf,QAAM,EAAE,OAAO,IAAI;AAEnB,MAAI;AACF,UAAM,kBAAkB,mBAAmB,MAAM;AAEjD,UAAM,EAAE,IAAI,GAAG,IAAI;AAEnB,UAAM,gBAAgB,IAAI,EAAE;AAC5B,QAAI,SAAS;AAAA,EACf,SAAS,OAAO;AACd,WAAO,IAAI,KAAK;AAAA,EAClB;AAEA,SAAO,IAAI;AACb;AASA,SAAS,mBAAmB,QAA4C;AACtE,MAAI;AACF,WAAO,OAAO,QAAQ,+BAA+B;AAAA,EACvD,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;","names":[]}
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-LR7UR4YU.mjs";
4
4
  import {
5
5
  getEntropyBuilder
6
- } from "./chunk-IBV23QOX.mjs";
6
+ } from "./chunk-KIXPIIY5.mjs";
7
7
  import {
8
8
  getLocaleBuilder
9
9
  } from "./chunk-IZYMBIBD.mjs";
@@ -12,19 +12,19 @@ import {
12
12
  } from "./chunk-E6WUMFQT.mjs";
13
13
  import {
14
14
  manageStateBuilder
15
- } from "./chunk-NESDQ4PF.mjs";
15
+ } from "./chunk-TE4W25CA.mjs";
16
16
  import {
17
17
  notifyBuilder
18
18
  } from "./chunk-JWDQUKKU.mjs";
19
19
  import {
20
20
  dialogBuilder
21
- } from "./chunk-4SQWLI2S.mjs";
21
+ } from "./chunk-X247BMMW.mjs";
22
22
  import {
23
23
  getBip32EntropyBuilder
24
- } from "./chunk-TNRH2LRU.mjs";
24
+ } from "./chunk-LXJBBRQ4.mjs";
25
25
  import {
26
26
  getBip32PublicKeyBuilder
27
- } from "./chunk-6WUIFFMQ.mjs";
27
+ } from "./chunk-R3DRYUNH.mjs";
28
28
  import {
29
29
  invokeSnapBuilder
30
30
  } from "./chunk-VVBTXSID.mjs";
@@ -46,4 +46,4 @@ var restrictedMethodPermissionBuilders = {
46
46
  export {
47
47
  restrictedMethodPermissionBuilders
48
48
  };
49
- //# sourceMappingURL=chunk-SU6KOIVB.mjs.map
49
+ //# sourceMappingURL=chunk-I3QG3QZL.mjs.map
@@ -47,7 +47,7 @@ var BaseParamsStruct = _superstruct.type.call(void 0, {
47
47
  });
48
48
  var AlertParametersWithContentStruct = _superstruct.object.call(void 0, {
49
49
  type: _snapssdk.enumValue.call(void 0, _snapssdk.DialogType.Alert),
50
- content: _snapssdk.ComponentStruct
50
+ content: _snapssdk.ComponentOrElementStruct
51
51
  });
52
52
  var AlertParametersWithIdStruct = _superstruct.object.call(void 0, {
53
53
  type: _snapssdk.enumValue.call(void 0, _snapssdk.DialogType.Alert),
@@ -59,7 +59,7 @@ var AlertParametersStruct = _snapssdk.union.call(void 0, [
59
59
  ]);
60
60
  var ConfirmationParametersWithContentStruct = _superstruct.object.call(void 0, {
61
61
  type: _snapssdk.enumValue.call(void 0, _snapssdk.DialogType.Confirmation),
62
- content: _snapssdk.ComponentStruct
62
+ content: _snapssdk.ComponentOrElementStruct
63
63
  });
64
64
  var ConfirmationParametersWithIdStruct = _superstruct.object.call(void 0, {
65
65
  type: _snapssdk.enumValue.call(void 0, _snapssdk.DialogType.Confirmation),
@@ -71,7 +71,7 @@ var ConfirmationParametersStruct = _snapssdk.union.call(void 0, [
71
71
  ]);
72
72
  var PromptParametersWithContentStruct = _superstruct.object.call(void 0, {
73
73
  type: _snapssdk.enumValue.call(void 0, _snapssdk.DialogType.Prompt),
74
- content: _snapssdk.ComponentStruct,
74
+ content: _snapssdk.ComponentOrElementStruct,
75
75
  placeholder: PlaceholderStruct
76
76
  });
77
77
  var PromptParametersWithIdStruct = _superstruct.object.call(void 0, {
@@ -148,4 +148,4 @@ function getValidatedParams(params, struct) {
148
148
 
149
149
 
150
150
  exports.dialogBuilder = dialogBuilder; exports.getDialogImplementation = getDialogImplementation;
151
- //# sourceMappingURL=chunk-GYZV5UBD.js.map
151
+ //# sourceMappingURL=chunk-I7DR6BFO.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/restricted/dialog.ts"],"names":["methodHooks"],"mappings":";AAKA,SAAS,gBAAgB,mBAAmB;AAC5C,SAAS,iBAAiB;AAC1B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AASP,SAAS,mBAAmB;AAE5B,SAAS,mBAAuC;AAEhD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAIP,IAAM,aAAa;AAEnB,IAAM,oBAAoB,SAAS,KAAK,OAAO,GAAG,GAAG,EAAE,CAAC;AAoExD,IAAM,uBAIF,CAAC;AAAA,EACH,iBAAiB;AAAA,EACjB,aAAAA;AACF,MAAyC;AACvC,SAAO;AAAA,IACL,gBAAgB,eAAe;AAAA,IAC/B,YAAY;AAAA,IACZ;AAAA,IACA,sBAAsB,wBAAwBA,YAAW;AAAA,IACzD,cAAc,CAAC,YAAY,IAAI;AAAA,EACjC;AACF;AAEA,IAAM,cAAoD;AAAA,EACxD,YAAY;AAAA,EACZ,iBAAiB;AAAA,EACjB,cAAc;AAChB;AAEO,IAAM,gBAAgB,OAAO,OAAO;AAAA,EACzC,YAAY;AAAA,EACZ;AAAA,EACA;AACF,CAAU;AAIV,IAAM,mBAAmB,KAAK;AAAA,EAC5B,MAAM,MAAM,CAAC,WAAW,OAAO,WAAW,cAAc,WAAW,MAAM,CAAC;AAC5E,CAAC;AAED,IAAM,mCAAmC,OAAO;AAAA,EAC9C,MAAM,UAAU,WAAW,KAAK;AAAA,EAChC,SAAS;AACX,CAAC;AACD,IAAM,8BAA8B,OAAO;AAAA,EACzC,MAAM,UAAU,WAAW,KAAK;AAAA,EAChC,IAAI,OAAO;AACb,CAAC;AAED,IAAM,wBAAwB,MAAM;AAAA,EAClC;AAAA,EACA;AACF,CAAC;AAED,IAAM,0CAA0C,OAAO;AAAA,EACrD,MAAM,UAAU,WAAW,YAAY;AAAA,EACvC,SAAS;AACX,CAAC;AAED,IAAM,qCAAqC,OAAO;AAAA,EAChD,MAAM,UAAU,WAAW,YAAY;AAAA,EACvC,IAAI,OAAO;AACb,CAAC;AAED,IAAM,+BAA+B,MAAM;AAAA,EACzC;AAAA,EACA;AACF,CAAC;AAED,IAAM,oCAAoC,OAAO;AAAA,EAC/C,MAAM,UAAU,WAAW,MAAM;AAAA,EACjC,SAAS;AAAA,EACT,aAAa;AACf,CAAC;AAED,IAAM,+BAA+B,OAAO;AAAA,EAC1C,MAAM,UAAU,WAAW,MAAM;AAAA,EACjC,IAAI,OAAO;AAAA,EACX,aAAa;AACf,CAAC;AAED,IAAM,yBAAyB,MAAM;AAAA,EACnC;AAAA,EACA;AACF,CAAC;AAED,IAAM,yBAAyB,MAAM;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAOD,IAAM,UAAU;AAAA,EACd,CAAC,WAAW,KAAK,GAAG;AAAA,EACpB,CAAC,WAAW,YAAY,GAAG;AAAA,EAC3B,CAAC,WAAW,MAAM,GAAG;AACvB;AAaO,SAAS,wBAAwB;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AACF,GAAsB;AACpB,SAAO,eAAe,qBACpB,MACkC;AAClC,UAAM;AAAA,MACJ;AAAA,MACA,SAAS,EAAE,OAAO;AAAA,IACpB,IAAI;AAEJ,UAAM,gBAAgB,iBAAiB,MAAM;AAC7C,UAAM,kBAAkB,mBAAmB,QAAQ,QAAQ,aAAa,CAAC;AAEzE,UAAM,cACJ,gBAAgB,SAAS,WAAW,SAChC,gBAAgB,cAChB;AAEN,QAAI,YAAY,iBAAiB,SAAS,GAAG;AAC3C,YAAM,KAAK,MAAM;AAAA,QACf;AAAA,QACA,gBAAgB;AAAA,MAClB;AACA,aAAO,WAAW,QAAQ,eAAe,IAAI,WAAW;AAAA,IAC1D;AAIA,QAAI;AACF,mBAAa,QAAQ,gBAAgB,EAAE;AAAA,IACzC,SAAS,OAAO;AACd,YAAM,UAAU,cAAc;AAAA,QAC5B,SAAS,mBAAmB,MAAM,OAAO;AAAA,MAC3C,CAAC;AAAA,IACH;AAEA,WAAO,WAAW,QAAQ,eAAe,gBAAgB,IAAI,WAAW;AAAA,EAC1E;AACF;AASA,SAAS,iBAAiB,QAA6B;AACrD,MAAI;AACF,WAAO,OAAO,QAAQ,gBAAgB,EAAE;AAAA,EAC1C,SAAS,OAAO;AACd,UAAM,UAAU,cAAc;AAAA,MAC5B,SAAS,uCAAuC,OAAO;AAAA,QACrD;AAAA,MACF,EAAE,KAAK,IAAI,CAAC;AAAA,IACd,CAAC;AAAA,EACH;AACF;AAUA,SAAS,mBACP,QACA,QACkB;AAClB,MAAI;AACF,WAAO,YAAY,QAAQ,QAAQ,MAAM;AAAA,EAC3C,SAAS,OAAO;AACd,UAAM,UAAU,cAAc;AAAA,MAC5B,SAAS,mBAAmB,MAAM,OAAO;AAAA,IAC3C,CAAC;AAAA,EACH;AACF","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 EnumToUnion,\n Component,\n InterfaceState,\n SnapId,\n ComponentOrElement,\n} from '@metamask/snaps-sdk';\nimport { createUnion } from '@metamask/snaps-utils';\nimport type { InferMatching } from '@metamask/snaps-utils';\nimport { hasProperty, type NonEmptyArray } from '@metamask/utils';\nimport type { Infer, Struct } from 'superstruct';\nimport {\n create,\n enums,\n object,\n optional,\n size,\n string,\n type,\n} from 'superstruct';\n\nimport { type MethodHooksObject } from '../utils';\n\nconst methodName = 'snap_dialog';\n\nconst PlaceholderStruct = optional(size(string(), 1, 40));\n\nexport type Placeholder = Infer<typeof PlaceholderStruct>;\n\ntype ShowDialog = (\n snapId: string,\n type: EnumToUnion<DialogType>,\n id: string,\n placeholder?: Placeholder,\n) => Promise<null | boolean | string>;\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 snapId - The ID of the Snap that created the alert.\n * @param type - The dialog type.\n * @param id - The interface ID.\n * @param placeholder - The placeholder for the Prompt dialog input.\n */\n showDialog: ShowDialog;\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 showDialog: 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: enums([DialogType.Alert, DialogType.Confirmation, DialogType.Prompt]),\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 DialogParametersStruct = union([\n AlertParametersStruct,\n ConfirmationParametersStruct,\n PromptParametersStruct,\n]);\n\nexport type DialogParameters = InferMatching<\n typeof DialogParametersStruct,\n DialogParams\n>;\n\nconst structs = {\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.showDialog - A function that shows the specified dialog in the\n * MetaMask UI and returns the appropriate value for the dialog type.\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 showDialog,\n createInterface,\n getInterface,\n}: DialogMethodHooks) {\n return async function dialogImplementation(\n args: RestrictedMethodOptions<DialogParameters>,\n ): Promise<boolean | null | string> {\n const {\n params,\n context: { origin },\n } = args;\n\n const validatedType = getValidatedType(params);\n const validatedParams = getValidatedParams(params, structs[validatedType]);\n\n const placeholder =\n validatedParams.type === DialogType.Prompt\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 return showDialog(origin, validatedType, id, placeholder);\n }\n\n // Verify that the passed interface ID is valid.\n // This will throw if the interface ID is invalid (not created by the snap or doesn't exist)\n try {\n getInterface(origin, validatedParams.id);\n } catch (error) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}`,\n });\n }\n\n return showDialog(origin, validatedType, validatedParams.id, placeholder);\n };\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 {\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 * 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 struct - The struct to validate the params against.\n * @returns The validated confirm method parameter object.\n */\nfunction getValidatedParams(\n params: unknown,\n struct: Struct<any, any>,\n): DialogParameters {\n try {\n return createUnion(params, struct, 'type');\n } catch (error) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}`,\n });\n }\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkYG7W4CDTjs = require('./chunk-YG7W4CDT.js');
3
+ var _chunk33MTKZ4Hjs = require('./chunk-33MTKZ4H.js');
4
4
 
5
5
  // src/restricted/getBip32Entropy.ts
6
6
  var _permissioncontroller = require('@metamask/permission-controller');
@@ -41,7 +41,7 @@ function getBip32EntropyImplementation({
41
41
  await getUnlockPromise(true);
42
42
  const { params } = args;
43
43
  _utils.assert.call(void 0, params);
44
- const node = await _chunkYG7W4CDTjs.getNode.call(void 0, {
44
+ const node = await _chunk33MTKZ4Hjs.getNode.call(void 0, {
45
45
  curve: params.curve,
46
46
  path: params.path,
47
47
  secretRecoveryPhrase: await getMnemonic()
@@ -54,4 +54,4 @@ function getBip32EntropyImplementation({
54
54
 
55
55
 
56
56
  exports.getBip32EntropyBuilder = getBip32EntropyBuilder; exports.getBip32EntropyImplementation = getBip32EntropyImplementation;
57
- //# sourceMappingURL=chunk-S7AR3ROH.js.map
57
+ //# sourceMappingURL=chunk-IE6EHYEG.js.map
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkYG7W4CDTjs = require('./chunk-YG7W4CDT.js');
3
+ var _chunk33MTKZ4Hjs = require('./chunk-33MTKZ4H.js');
4
4
 
5
5
  // src/restricted/getEntropy.ts
6
6
  var _permissioncontroller = require('@metamask/permission-controller');
@@ -51,7 +51,7 @@ function getEntropyImplementation({
51
51
  );
52
52
  await getUnlockPromise(true);
53
53
  const mnemonicPhrase = await getMnemonic();
54
- return _chunkYG7W4CDTjs.deriveEntropy.call(void 0, {
54
+ return _chunk33MTKZ4Hjs.deriveEntropy.call(void 0, {
55
55
  input: origin,
56
56
  salt: params.salt,
57
57
  mnemonicPhrase,
@@ -64,4 +64,4 @@ function getEntropyImplementation({
64
64
 
65
65
 
66
66
  exports.GetEntropyArgsStruct = GetEntropyArgsStruct; exports.getEntropyBuilder = getEntropyBuilder;
67
- //# sourceMappingURL=chunk-Q5W3YGEB.js.map
67
+ //# sourceMappingURL=chunk-IVD2ORDS.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  deriveEntropy
3
- } from "./chunk-SGQXD5K7.mjs";
3
+ } from "./chunk-W33UWNA2.mjs";
4
4
 
5
5
  // src/restricted/getEntropy.ts
6
6
  import { PermissionType, SubjectType } from "@metamask/permission-controller";
@@ -64,4 +64,4 @@ export {
64
64
  GetEntropyArgsStruct,
65
65
  getEntropyBuilder
66
66
  };
67
- //# sourceMappingURL=chunk-IBV23QOX.mjs.map
67
+ //# sourceMappingURL=chunk-KIXPIIY5.mjs.map
@@ -15,10 +15,10 @@ var _chunkZPK4THX4js = require('./chunk-ZPK4THX4.js');
15
15
  var _chunkVUA6ICJOjs = require('./chunk-VUA6ICJO.js');
16
16
 
17
17
 
18
- var _chunkS7AR3ROHjs = require('./chunk-S7AR3ROH.js');
18
+ var _chunkIE6EHYEGjs = require('./chunk-IE6EHYEG.js');
19
19
 
20
20
 
21
- var _chunkLGUJMQC7js = require('./chunk-LGUJMQC7.js');
21
+ var _chunk4BPNRCZJjs = require('./chunk-4BPNRCZJ.js');
22
22
 
23
23
 
24
24
  var _chunkFFHVA6PPjs = require('./chunk-FFHVA6PP.js');
@@ -30,8 +30,8 @@ var caveatSpecifications = {
30
30
  ..._chunkZPK4THX4js.SnapIdsCaveatSpecification
31
31
  };
32
32
  var caveatMappers = {
33
- [_chunkS7AR3ROHjs.getBip32EntropyBuilder.targetName]: _chunkVHY3NATPjs.permittedDerivationPathsCaveatMapper,
34
- [_chunkLGUJMQC7js.getBip32PublicKeyBuilder.targetName]: _chunkVHY3NATPjs.permittedDerivationPathsCaveatMapper,
33
+ [_chunkIE6EHYEGjs.getBip32EntropyBuilder.targetName]: _chunkVHY3NATPjs.permittedDerivationPathsCaveatMapper,
34
+ [_chunk4BPNRCZJjs.getBip32PublicKeyBuilder.targetName]: _chunkVHY3NATPjs.permittedDerivationPathsCaveatMapper,
35
35
  [_chunkVUA6ICJOjs.getBip44EntropyBuilder.targetName]: _chunk2KTJCF3Cjs.permittedCoinTypesCaveatMapper,
36
36
  [_chunkFFHVA6PPjs.invokeSnapBuilder.targetName]: _chunkZPK4THX4js.snapIdsCaveatMapper
37
37
  };
@@ -40,4 +40,4 @@ var caveatMappers = {
40
40
 
41
41
 
42
42
  exports.caveatSpecifications = caveatSpecifications; exports.caveatMappers = caveatMappers;
43
- //# sourceMappingURL=chunk-AYJK7MSH.js.map
43
+ //# sourceMappingURL=chunk-LLH2T5NT.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getNode
3
- } from "./chunk-SGQXD5K7.mjs";
3
+ } from "./chunk-W33UWNA2.mjs";
4
4
 
5
5
  // src/restricted/getBip32Entropy.ts
6
6
  import { PermissionType, SubjectType } from "@metamask/permission-controller";
@@ -54,4 +54,4 @@ export {
54
54
  getBip32EntropyBuilder,
55
55
  getBip32EntropyImplementation
56
56
  };
57
- //# sourceMappingURL=chunk-TNRH2LRU.mjs.map
57
+ //# sourceMappingURL=chunk-LXJBBRQ4.mjs.map
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkYG7W4CDTjs = require('./chunk-YG7W4CDT.js');
3
+ var _chunk33MTKZ4Hjs = require('./chunk-33MTKZ4H.js');
4
4
 
5
5
  // src/restricted/manageState.ts
6
6
  var _permissioncontroller = require('@metamask/permission-controller');
@@ -38,7 +38,7 @@ async function getEncryptionEntropy({
38
38
  mnemonicPhrase,
39
39
  snapId
40
40
  }) {
41
- return await _chunkYG7W4CDTjs.deriveEntropy.call(void 0, {
41
+ return await _chunk33MTKZ4Hjs.deriveEntropy.call(void 0, {
42
42
  mnemonicPhrase,
43
43
  input: snapId,
44
44
  salt: STATE_ENCRYPTION_SALT,
@@ -140,4 +140,4 @@ function getValidatedParams(params, method, storageSizeLimit = STORAGE_SIZE_LIMI
140
140
 
141
141
 
142
142
  exports.STATE_ENCRYPTION_SALT = STATE_ENCRYPTION_SALT; exports.specificationBuilder = specificationBuilder; exports.manageStateBuilder = manageStateBuilder; exports.STORAGE_SIZE_LIMIT = STORAGE_SIZE_LIMIT; exports.getEncryptionEntropy = getEncryptionEntropy; exports.getManageStateImplementation = getManageStateImplementation; exports.getValidatedParams = getValidatedParams;
143
- //# sourceMappingURL=chunk-R2M4YLJ7.js.map
143
+ //# sourceMappingURL=chunk-M2JQCKR7.js.map