@metamask/snaps-utils 9.1.0 → 9.2.1

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 (149) hide show
  1. package/CHANGELOG.md +18 -1
  2. package/dist/cronjob.d.cts +9 -9
  3. package/dist/cronjob.d.mts +9 -9
  4. package/dist/eval-worker.cjs +4 -5
  5. package/dist/eval-worker.cjs.map +1 -1
  6. package/dist/eval-worker.mjs +3 -4
  7. package/dist/eval-worker.mjs.map +1 -1
  8. package/dist/handlers/asset-historical-price.cjs +25 -0
  9. package/dist/handlers/asset-historical-price.cjs.map +1 -0
  10. package/dist/handlers/asset-historical-price.d.cts +37 -0
  11. package/dist/handlers/asset-historical-price.d.cts.map +1 -0
  12. package/dist/handlers/asset-historical-price.d.mts +37 -0
  13. package/dist/handlers/asset-historical-price.d.mts.map +1 -0
  14. package/dist/handlers/asset-historical-price.mjs +22 -0
  15. package/dist/handlers/asset-historical-price.mjs.map +1 -0
  16. package/dist/handlers/assets-conversion.cjs +38 -0
  17. package/dist/handlers/assets-conversion.cjs.map +1 -0
  18. package/dist/handlers/assets-conversion.d.cts +90 -0
  19. package/dist/handlers/assets-conversion.d.cts.map +1 -0
  20. package/dist/handlers/assets-conversion.d.mts +90 -0
  21. package/dist/handlers/assets-conversion.d.mts.map +1 -0
  22. package/dist/handlers/assets-conversion.mjs +35 -0
  23. package/dist/handlers/assets-conversion.mjs.map +1 -0
  24. package/dist/handlers/exports.cjs +113 -0
  25. package/dist/handlers/exports.cjs.map +1 -0
  26. package/dist/handlers/exports.d.cts +81 -0
  27. package/dist/handlers/exports.d.cts.map +1 -0
  28. package/dist/handlers/exports.d.mts +81 -0
  29. package/dist/handlers/exports.d.mts.map +1 -0
  30. package/dist/{handlers.mjs → handlers/exports.mjs} +10 -45
  31. package/dist/handlers/exports.mjs.map +1 -0
  32. package/dist/handlers/home-page.cjs +16 -0
  33. package/dist/handlers/home-page.cjs.map +1 -0
  34. package/dist/handlers/home-page.d.cts +268 -0
  35. package/dist/handlers/home-page.d.cts.map +1 -0
  36. package/dist/handlers/home-page.d.mts +268 -0
  37. package/dist/handlers/home-page.d.mts.map +1 -0
  38. package/dist/handlers/home-page.mjs +13 -0
  39. package/dist/handlers/home-page.mjs.map +1 -0
  40. package/dist/handlers/index.cjs +26 -0
  41. package/dist/handlers/index.cjs.map +1 -0
  42. package/dist/handlers/index.d.cts +10 -0
  43. package/dist/handlers/index.d.cts.map +1 -0
  44. package/dist/handlers/index.d.mts +10 -0
  45. package/dist/handlers/index.d.mts.map +1 -0
  46. package/dist/handlers/index.mjs +10 -0
  47. package/dist/handlers/index.mjs.map +1 -0
  48. package/dist/handlers/name-lookup.cjs +21 -0
  49. package/dist/handlers/name-lookup.cjs.map +1 -0
  50. package/dist/handlers/name-lookup.d.cts +67 -0
  51. package/dist/handlers/name-lookup.d.cts.map +1 -0
  52. package/dist/handlers/name-lookup.d.mts +67 -0
  53. package/dist/handlers/name-lookup.d.mts.map +1 -0
  54. package/dist/handlers/name-lookup.mjs +18 -0
  55. package/dist/handlers/name-lookup.mjs.map +1 -0
  56. package/dist/handlers/settings-page.cjs +6 -0
  57. package/dist/handlers/settings-page.cjs.map +1 -0
  58. package/dist/handlers/settings-page.d.cts +90 -0
  59. package/dist/handlers/settings-page.d.cts.map +1 -0
  60. package/dist/handlers/settings-page.d.mts +90 -0
  61. package/dist/handlers/settings-page.d.mts.map +1 -0
  62. package/dist/handlers/settings-page.mjs +3 -0
  63. package/dist/handlers/settings-page.mjs.map +1 -0
  64. package/dist/handlers/signature.cjs +6 -0
  65. package/dist/handlers/signature.cjs.map +1 -0
  66. package/dist/handlers/signature.d.cts +92 -0
  67. package/dist/handlers/signature.d.cts.map +1 -0
  68. package/dist/handlers/signature.d.mts +92 -0
  69. package/dist/handlers/signature.d.mts.map +1 -0
  70. package/dist/handlers/signature.mjs +3 -0
  71. package/dist/handlers/signature.mjs.map +1 -0
  72. package/dist/handlers/transaction.cjs +19 -0
  73. package/dist/handlers/transaction.cjs.map +1 -0
  74. package/dist/handlers/transaction.d.cts +280 -0
  75. package/dist/handlers/transaction.d.cts.map +1 -0
  76. package/dist/handlers/transaction.d.mts +280 -0
  77. package/dist/handlers/transaction.d.mts.map +1 -0
  78. package/dist/handlers/transaction.mjs +16 -0
  79. package/dist/handlers/transaction.mjs.map +1 -0
  80. package/dist/{handler-types.cjs → handlers/types.cjs} +3 -3
  81. package/dist/handlers/types.cjs.map +1 -0
  82. package/dist/{handler-types.d.mts → handlers/types.d.cts} +22 -2
  83. package/dist/handlers/types.d.cts.map +1 -0
  84. package/dist/{handler-types.d.cts → handlers/types.d.mts} +22 -2
  85. package/dist/handlers/types.d.mts.map +1 -0
  86. package/dist/{handler-types.mjs → handlers/types.mjs} +2 -2
  87. package/dist/handlers/types.mjs.map +1 -0
  88. package/dist/iframe.test.browser.cjs +20 -19
  89. package/dist/iframe.test.browser.cjs.map +1 -1
  90. package/dist/iframe.test.browser.mjs +2 -1
  91. package/dist/iframe.test.browser.mjs.map +1 -1
  92. package/dist/index.cjs +2 -2
  93. package/dist/index.cjs.map +1 -1
  94. package/dist/index.d.cts +2 -2
  95. package/dist/index.d.cts.map +1 -1
  96. package/dist/index.d.mts +2 -2
  97. package/dist/index.d.mts.map +1 -1
  98. package/dist/index.executionenv.cjs +3 -2
  99. package/dist/index.executionenv.cjs.map +1 -1
  100. package/dist/index.executionenv.d.cts +3 -2
  101. package/dist/index.executionenv.d.cts.map +1 -1
  102. package/dist/index.executionenv.d.mts +3 -2
  103. package/dist/index.executionenv.d.mts.map +1 -1
  104. package/dist/index.executionenv.mjs +3 -2
  105. package/dist/index.executionenv.mjs.map +1 -1
  106. package/dist/index.mjs +2 -2
  107. package/dist/index.mjs.map +1 -1
  108. package/dist/json-rpc.cjs.map +1 -1
  109. package/dist/json-rpc.d.cts +2 -2
  110. package/dist/json-rpc.d.cts.map +1 -1
  111. package/dist/json-rpc.d.mts +2 -2
  112. package/dist/json-rpc.d.mts.map +1 -1
  113. package/dist/json-rpc.mjs.map +1 -1
  114. package/dist/json.cjs +5 -1
  115. package/dist/json.cjs.map +1 -1
  116. package/dist/json.d.cts +3 -0
  117. package/dist/json.d.cts.map +1 -1
  118. package/dist/json.d.mts +3 -0
  119. package/dist/json.d.mts.map +1 -1
  120. package/dist/json.mjs +5 -1
  121. package/dist/json.mjs.map +1 -1
  122. package/dist/localization.d.cts +5 -5
  123. package/dist/localization.d.mts +5 -5
  124. package/dist/manifest/validation.d.cts +12 -12
  125. package/dist/manifest/validation.d.mts +12 -12
  126. package/dist/time.cjs +34 -0
  127. package/dist/time.cjs.map +1 -0
  128. package/dist/time.d.cts +9 -0
  129. package/dist/time.d.cts.map +1 -0
  130. package/dist/time.d.mts +9 -0
  131. package/dist/time.d.mts.map +1 -0
  132. package/dist/time.mjs +31 -0
  133. package/dist/time.mjs.map +1 -0
  134. package/dist/types.d.cts +2 -2
  135. package/dist/types.d.cts.map +1 -1
  136. package/dist/types.d.mts +2 -2
  137. package/dist/types.d.mts.map +1 -1
  138. package/package.json +17 -24
  139. package/dist/handler-types.cjs.map +0 -1
  140. package/dist/handler-types.d.cts.map +0 -1
  141. package/dist/handler-types.d.mts.map +0 -1
  142. package/dist/handler-types.mjs.map +0 -1
  143. package/dist/handlers.cjs +0 -148
  144. package/dist/handlers.cjs.map +0 -1
  145. package/dist/handlers.d.cts +0 -887
  146. package/dist/handlers.d.cts.map +0 -1
  147. package/dist/handlers.d.mts +0 -887
  148. package/dist/handlers.d.mts.map +0 -1
  149. package/dist/handlers.mjs.map +0 -1
package/dist/index.d.cts CHANGED
@@ -13,8 +13,7 @@ export * from "./default-endowments.cjs";
13
13
  export * from "./derivation-paths.cjs";
14
14
  export * from "./entropy.cjs";
15
15
  export * from "./errors.cjs";
16
- export * from "./handlers.cjs";
17
- export * from "./handler-types.cjs";
16
+ export * from "./handlers/index.cjs";
18
17
  export * from "./iframe.cjs";
19
18
  export * from "./json.cjs";
20
19
  export * from "./json-rpc.cjs";
@@ -26,6 +25,7 @@ export * from "./platform-version.cjs";
26
25
  export * from "./snaps.cjs";
27
26
  export * from "./strings.cjs";
28
27
  export * from "./structs.cjs";
28
+ export * from "./time.cjs";
29
29
  export * from "./types.cjs";
30
30
  export * from "./ui.cjs";
31
31
  export * from "./url.cjs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mCAA+B;AAC/B,4BAAwB;AACxB,sCAAkC;AAClC,6BAAyB;AACzB,4BAAwB;AACxB,8BAA0B;AAC1B,+BAA2B;AAC3B,gCAA4B;AAC5B,8BAA0B;AAC1B,+BAA2B;AAC3B,iCAA6B;AAC7B,yCAAqC;AACrC,uCAAmC;AACnC,8BAA0B;AAC1B,6BAAyB;AACzB,+BAA2B;AAC3B,oCAAgC;AAChC,6BAAyB;AACzB,2BAAuB;AACvB,+BAA2B;AAC3B,mCAA+B;AAC/B,8BAA0B;AAC1B,qCAA2B;AAC3B,2BAAuB;AACvB,uCAAmC;AACnC,4BAAwB;AACxB,8BAA0B;AAC1B,8BAA0B;AAC1B,4BAAwB;AACxB,yBAAqB;AACrB,0BAAsB;AACtB,iCAA6B;AAC7B,+BAA2B;AAC3B,yCAA+B;AAC/B,mCAA+B"}
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mCAA+B;AAC/B,4BAAwB;AACxB,sCAAkC;AAClC,6BAAyB;AACzB,4BAAwB;AACxB,8BAA0B;AAC1B,+BAA2B;AAC3B,gCAA4B;AAC5B,8BAA0B;AAC1B,+BAA2B;AAC3B,iCAA6B;AAC7B,yCAAqC;AACrC,uCAAmC;AACnC,8BAA0B;AAC1B,6BAAyB;AACzB,qCAA2B;AAC3B,6BAAyB;AACzB,2BAAuB;AACvB,+BAA2B;AAC3B,mCAA+B;AAC/B,8BAA0B;AAC1B,qCAA2B;AAC3B,2BAAuB;AACvB,uCAAmC;AACnC,4BAAwB;AACxB,8BAA0B;AAC1B,8BAA0B;AAC1B,2BAAuB;AACvB,4BAAwB;AACxB,yBAAqB;AACrB,0BAAsB;AACtB,iCAA6B;AAC7B,+BAA2B;AAC3B,yCAA+B;AAC/B,mCAA+B"}
package/dist/index.d.mts CHANGED
@@ -13,8 +13,7 @@ export * from "./default-endowments.mjs";
13
13
  export * from "./derivation-paths.mjs";
14
14
  export * from "./entropy.mjs";
15
15
  export * from "./errors.mjs";
16
- export * from "./handlers.mjs";
17
- export * from "./handler-types.mjs";
16
+ export * from "./handlers/index.mjs";
18
17
  export * from "./iframe.mjs";
19
18
  export * from "./json.mjs";
20
19
  export * from "./json-rpc.mjs";
@@ -26,6 +25,7 @@ export * from "./platform-version.mjs";
26
25
  export * from "./snaps.mjs";
27
26
  export * from "./strings.mjs";
28
27
  export * from "./structs.mjs";
28
+ export * from "./time.mjs";
29
29
  export * from "./types.mjs";
30
30
  export * from "./ui.mjs";
31
31
  export * from "./url.mjs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mCAA+B;AAC/B,4BAAwB;AACxB,sCAAkC;AAClC,6BAAyB;AACzB,4BAAwB;AACxB,8BAA0B;AAC1B,+BAA2B;AAC3B,gCAA4B;AAC5B,8BAA0B;AAC1B,+BAA2B;AAC3B,iCAA6B;AAC7B,yCAAqC;AACrC,uCAAmC;AACnC,8BAA0B;AAC1B,6BAAyB;AACzB,+BAA2B;AAC3B,oCAAgC;AAChC,6BAAyB;AACzB,2BAAuB;AACvB,+BAA2B;AAC3B,mCAA+B;AAC/B,8BAA0B;AAC1B,qCAA2B;AAC3B,2BAAuB;AACvB,uCAAmC;AACnC,4BAAwB;AACxB,8BAA0B;AAC1B,8BAA0B;AAC1B,4BAAwB;AACxB,yBAAqB;AACrB,0BAAsB;AACtB,iCAA6B;AAC7B,+BAA2B;AAC3B,yCAA+B;AAC/B,mCAA+B"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mCAA+B;AAC/B,4BAAwB;AACxB,sCAAkC;AAClC,6BAAyB;AACzB,4BAAwB;AACxB,8BAA0B;AAC1B,+BAA2B;AAC3B,gCAA4B;AAC5B,8BAA0B;AAC1B,+BAA2B;AAC3B,iCAA6B;AAC7B,yCAAqC;AACrC,uCAAmC;AACnC,8BAA0B;AAC1B,6BAAyB;AACzB,qCAA2B;AAC3B,6BAAyB;AACzB,2BAAuB;AACvB,+BAA2B;AAC3B,mCAA+B;AAC/B,8BAA0B;AAC1B,qCAA2B;AAC3B,2BAAuB;AACvB,uCAAmC;AACnC,4BAAwB;AACxB,8BAA0B;AAC1B,8BAA0B;AAC1B,2BAAuB;AACvB,4BAAwB;AACxB,yBAAqB;AACrB,0BAAsB;AACtB,iCAA6B;AAC7B,+BAA2B;AAC3B,yCAA+B;AAC/B,mCAA+B"}
@@ -16,9 +16,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  // Special entrypoint for execution environments for bundle sizing reasons
18
18
  __exportStar(require("./errors.cjs"), exports);
19
- __exportStar(require("./handlers.cjs"), exports);
20
- __exportStar(require("./handler-types.cjs"), exports);
19
+ __exportStar(require("./handlers/exports.cjs"), exports);
20
+ __exportStar(require("./handlers/types.cjs"), exports);
21
21
  __exportStar(require("./iframe.cjs"), exports);
22
+ __exportStar(require("./json.cjs"), exports);
22
23
  __exportStar(require("./logging.cjs"), exports);
23
24
  __exportStar(require("./types.cjs"), exports);
24
25
  //# sourceMappingURL=index.executionenv.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.executionenv.cjs","sourceRoot":"","sources":["../src/index.executionenv.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0EAA0E;AAC1E,+CAAyB;AACzB,iDAA2B;AAC3B,sDAAgC;AAChC,+CAAyB;AACzB,gDAA0B;AAC1B,8CAAwB","sourcesContent":["// Special entrypoint for execution environments for bundle sizing reasons\nexport * from './errors';\nexport * from './handlers';\nexport * from './handler-types';\nexport * from './iframe';\nexport * from './logging';\nexport * from './types';\n"]}
1
+ {"version":3,"file":"index.executionenv.cjs","sourceRoot":"","sources":["../src/index.executionenv.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0EAA0E;AAC1E,+CAAyB;AACzB,yDAAmC;AACnC,uDAAiC;AACjC,+CAAyB;AACzB,6CAAuB;AACvB,gDAA0B;AAC1B,8CAAwB","sourcesContent":["// Special entrypoint for execution environments for bundle sizing reasons\nexport * from './errors';\nexport * from './handlers/exports';\nexport * from './handlers/types';\nexport * from './iframe';\nexport * from './json';\nexport * from './logging';\nexport * from './types';\n"]}
@@ -1,7 +1,8 @@
1
1
  export * from "./errors.cjs";
2
- export * from "./handlers.cjs";
3
- export * from "./handler-types.cjs";
2
+ export * from "./handlers/exports.cjs";
3
+ export * from "./handlers/types.cjs";
4
4
  export * from "./iframe.cjs";
5
+ export * from "./json.cjs";
5
6
  export * from "./logging.cjs";
6
7
  export * from "./types.cjs";
7
8
  //# sourceMappingURL=index.executionenv.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.executionenv.d.cts","sourceRoot":"","sources":["../src/index.executionenv.ts"],"names":[],"mappings":"AACA,6BAAyB;AACzB,+BAA2B;AAC3B,oCAAgC;AAChC,6BAAyB;AACzB,8BAA0B;AAC1B,4BAAwB"}
1
+ {"version":3,"file":"index.executionenv.d.cts","sourceRoot":"","sources":["../src/index.executionenv.ts"],"names":[],"mappings":"AACA,6BAAyB;AACzB,uCAAmC;AACnC,qCAAiC;AACjC,6BAAyB;AACzB,2BAAuB;AACvB,8BAA0B;AAC1B,4BAAwB"}
@@ -1,7 +1,8 @@
1
1
  export * from "./errors.mjs";
2
- export * from "./handlers.mjs";
3
- export * from "./handler-types.mjs";
2
+ export * from "./handlers/exports.mjs";
3
+ export * from "./handlers/types.mjs";
4
4
  export * from "./iframe.mjs";
5
+ export * from "./json.mjs";
5
6
  export * from "./logging.mjs";
6
7
  export * from "./types.mjs";
7
8
  //# sourceMappingURL=index.executionenv.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.executionenv.d.mts","sourceRoot":"","sources":["../src/index.executionenv.ts"],"names":[],"mappings":"AACA,6BAAyB;AACzB,+BAA2B;AAC3B,oCAAgC;AAChC,6BAAyB;AACzB,8BAA0B;AAC1B,4BAAwB"}
1
+ {"version":3,"file":"index.executionenv.d.mts","sourceRoot":"","sources":["../src/index.executionenv.ts"],"names":[],"mappings":"AACA,6BAAyB;AACzB,uCAAmC;AACnC,qCAAiC;AACjC,6BAAyB;AACzB,2BAAuB;AACvB,8BAA0B;AAC1B,4BAAwB"}
@@ -1,8 +1,9 @@
1
1
  // Special entrypoint for execution environments for bundle sizing reasons
2
2
  export * from "./errors.mjs";
3
- export * from "./handlers.mjs";
4
- export * from "./handler-types.mjs";
3
+ export * from "./handlers/exports.mjs";
4
+ export * from "./handlers/types.mjs";
5
5
  export * from "./iframe.mjs";
6
+ export * from "./json.mjs";
6
7
  export * from "./logging.mjs";
7
8
  export * from "./types.mjs";
8
9
  //# sourceMappingURL=index.executionenv.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.executionenv.mjs","sourceRoot":"","sources":["../src/index.executionenv.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,6BAAyB;AACzB,+BAA2B;AAC3B,oCAAgC;AAChC,6BAAyB;AACzB,8BAA0B;AAC1B,4BAAwB","sourcesContent":["// Special entrypoint for execution environments for bundle sizing reasons\nexport * from './errors';\nexport * from './handlers';\nexport * from './handler-types';\nexport * from './iframe';\nexport * from './logging';\nexport * from './types';\n"]}
1
+ {"version":3,"file":"index.executionenv.mjs","sourceRoot":"","sources":["../src/index.executionenv.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,6BAAyB;AACzB,uCAAmC;AACnC,qCAAiC;AACjC,6BAAyB;AACzB,2BAAuB;AACvB,8BAA0B;AAC1B,4BAAwB","sourcesContent":["// Special entrypoint for execution environments for bundle sizing reasons\nexport * from './errors';\nexport * from './handlers/exports';\nexport * from './handlers/types';\nexport * from './iframe';\nexport * from './json';\nexport * from './logging';\nexport * from './types';\n"]}
package/dist/index.mjs CHANGED
@@ -12,8 +12,7 @@ export * from "./default-endowments.mjs";
12
12
  export * from "./derivation-paths.mjs";
13
13
  export * from "./entropy.mjs";
14
14
  export * from "./errors.mjs";
15
- export * from "./handlers.mjs";
16
- export * from "./handler-types.mjs";
15
+ export * from "./handlers/index.mjs";
17
16
  export * from "./iframe.mjs";
18
17
  export * from "./json.mjs";
19
18
  export * from "./json-rpc.mjs";
@@ -25,6 +24,7 @@ export * from "./platform-version.mjs";
25
24
  export * from "./snaps.mjs";
26
25
  export * from "./strings.mjs";
27
26
  export * from "./structs.mjs";
27
+ export * from "./time.mjs";
28
28
  export * from "./types.mjs";
29
29
  export * from "./ui.mjs";
30
30
  export * from "./url.mjs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,4BAAwB;AACxB,sCAAkC;AAClC,6BAAyB;AACzB,4BAAwB;AACxB,8BAA0B;AAC1B,+BAA2B;AAC3B,gCAA4B;AAC5B,8BAA0B;AAC1B,+BAA2B;AAC3B,iCAA6B;AAC7B,yCAAqC;AACrC,uCAAmC;AACnC,8BAA0B;AAC1B,6BAAyB;AACzB,+BAA2B;AAC3B,oCAAgC;AAChC,6BAAyB;AACzB,2BAAuB;AACvB,+BAA2B;AAC3B,mCAA+B;AAC/B,8BAA0B;AAC1B,qCAA2B;AAC3B,2BAAuB;AACvB,uCAAmC;AACnC,4BAAwB;AACxB,8BAA0B;AAC1B,8BAA0B;AAC1B,4BAAwB;AACxB,yBAAqB;AACrB,0BAAsB;AACtB,iCAA6B;AAC7B,+BAA2B;AAC3B,yCAA+B","sourcesContent":["export type * from './account';\nexport * from './array';\nexport * from './auxiliary-files';\nexport * from './base64';\nexport * from './bytes';\nexport * from './caveats';\nexport * from './checksum';\nexport * from './constants';\nexport * from './cronjob';\nexport * from './currency';\nexport * from './deep-clone';\nexport * from './default-endowments';\nexport * from './derivation-paths';\nexport * from './entropy';\nexport * from './errors';\nexport * from './handlers';\nexport * from './handler-types';\nexport * from './iframe';\nexport * from './json';\nexport * from './json-rpc';\nexport * from './localization';\nexport * from './logging';\nexport * from './manifest';\nexport * from './path';\nexport * from './platform-version';\nexport * from './snaps';\nexport * from './strings';\nexport * from './structs';\nexport * from './types';\nexport * from './ui';\nexport * from './url';\nexport * from './validation';\nexport * from './versions';\nexport * from './virtual-file';\nexport type * from './promise';\n"]}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,4BAAwB;AACxB,sCAAkC;AAClC,6BAAyB;AACzB,4BAAwB;AACxB,8BAA0B;AAC1B,+BAA2B;AAC3B,gCAA4B;AAC5B,8BAA0B;AAC1B,+BAA2B;AAC3B,iCAA6B;AAC7B,yCAAqC;AACrC,uCAAmC;AACnC,8BAA0B;AAC1B,6BAAyB;AACzB,qCAA2B;AAC3B,6BAAyB;AACzB,2BAAuB;AACvB,+BAA2B;AAC3B,mCAA+B;AAC/B,8BAA0B;AAC1B,qCAA2B;AAC3B,2BAAuB;AACvB,uCAAmC;AACnC,4BAAwB;AACxB,8BAA0B;AAC1B,8BAA0B;AAC1B,2BAAuB;AACvB,4BAAwB;AACxB,yBAAqB;AACrB,0BAAsB;AACtB,iCAA6B;AAC7B,+BAA2B;AAC3B,yCAA+B","sourcesContent":["export type * from './account';\nexport * from './array';\nexport * from './auxiliary-files';\nexport * from './base64';\nexport * from './bytes';\nexport * from './caveats';\nexport * from './checksum';\nexport * from './constants';\nexport * from './cronjob';\nexport * from './currency';\nexport * from './deep-clone';\nexport * from './default-endowments';\nexport * from './derivation-paths';\nexport * from './entropy';\nexport * from './errors';\nexport * from './handlers';\nexport * from './iframe';\nexport * from './json';\nexport * from './json-rpc';\nexport * from './localization';\nexport * from './logging';\nexport * from './manifest';\nexport * from './path';\nexport * from './platform-version';\nexport * from './snaps';\nexport * from './strings';\nexport * from './structs';\nexport * from './time';\nexport * from './types';\nexport * from './ui';\nexport * from './url';\nexport * from './validation';\nexport * from './versions';\nexport * from './virtual-file';\nexport type * from './promise';\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"json-rpc.cjs","sourceRoot":"","sources":["../src/json-rpc.ts"],"names":[],"mappings":";;;AAAA,2EAA8D;AAE9D,uDAO+B;AAM/B,2CAIyB;AAEzB,MAAM,oBAAoB,GAAG,IAAA,mBAAK,EAChC,IAAA,oBAAM,EAAC,IAAA,oBAAM,GAAE,EAAE,gBAAgB,EAAE,CAAC,KAAK,EAAE,EAAE;IAC3C,MAAM,SAAS,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;IAC9C,IAAI,SAAS,GAAG,CAAC,EAAE,CAAC;QAClB,OAAO,sEAAsE,CAAC;IAChF,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC,CACH,CAAC;AAEW,QAAA,gBAAgB,GAAG,IAAA,oBAAM,EACpC,IAAA,oBAAM,EAAC;IACL,KAAK,EAAE,IAAA,sBAAQ,EAAC,IAAA,qBAAO,GAAE,CAAC;IAC1B,KAAK,EAAE,IAAA,sBAAQ,EAAC,IAAA,qBAAO,GAAE,CAAC;IAC1B,cAAc,EAAE,IAAA,sBAAQ,EAAC,oBAAoB,CAAC;CAC/C,CAAC,EACF,aAAa,EACb,CAAC,KAAK,EAAE,EAAE;IACR,MAAM,UAAU,GAAG,OAAO,CACxB,KAAK,CAAC,KAAK,KAAK,IAAI;QAClB,KAAK,CAAC,KAAK,KAAK,IAAI;QACpB,CAAC,KAAK,CAAC,cAAc,IAAI,KAAK,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC,CAAC,CAC5D,CAAC;IAEF,IAAI,UAAU,EAAE,CAAC;QAC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MAAc;IAEd,yCAAyC;IACzC,IAAI,MAAM,KAAK,UAAU,EAAE,CAAC;QAC1B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,gEAAgE;IAChE,IACE,OAAO,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CACvC,kBAAkB,CAAC,OAAO,EAAE,MAAM,CAAC,CACpC,EACD,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,iEAAiE;IACjE,IAAI,WAAW,KAAK,mCAAW,CAAC,OAAO,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;QACzD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,8DAA8D;IAC9D,OAAO,OAAO,CAAC,WAAW,KAAK,mCAAW,CAAC,IAAI,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC;AACpE,CAAC;AA1BD,0CA0BC;AAED;;;;;;;GAOG;AACH,SAAgB,sBAAsB,CACpC,KAAc;IAEd,IAAI,CAAC,IAAA,wBAAgB,EAAC,KAAK,CAAC,EAAE,CAAC;QAC7B,IAAI,IAAA,wBAAgB,EAAC,KAAK,CAAC,EAAE,CAAC;YAC5B,MAAM,IAAI,KAAK,CAAC,4BAA4B,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QACrE,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;IAChD,CAAC;AACH,CAAC;AAVD,wDAUC","sourcesContent":["import { SubjectType } from '@metamask/permission-controller';\nimport type { Infer } from '@metamask/superstruct';\nimport {\n array,\n boolean,\n object,\n optional,\n refine,\n string,\n} from '@metamask/superstruct';\nimport type {\n AssertionErrorConstructor,\n Json,\n JsonRpcSuccess,\n} from '@metamask/utils';\nimport {\n assertStruct,\n isJsonRpcFailure,\n isJsonRpcSuccess,\n} from '@metamask/utils';\n\nconst AllowedOriginsStruct = array(\n refine(string(), 'Allowed origin', (value) => {\n const wildcards = value.split('*').length - 1;\n if (wildcards > 2) {\n return 'No more than two wildcards (\"*\") are allowed in an origin specifier.';\n }\n\n return true;\n }),\n);\n\nexport const RpcOriginsStruct = refine(\n object({\n dapps: optional(boolean()),\n snaps: optional(boolean()),\n allowedOrigins: optional(AllowedOriginsStruct),\n }),\n 'RPC origins',\n (value) => {\n const hasOrigins = Boolean(\n value.snaps === true ||\n value.dapps === true ||\n (value.allowedOrigins && value.allowedOrigins.length > 0),\n );\n\n if (hasOrigins) {\n return true;\n }\n\n return 'Must specify at least one JSON-RPC origin.';\n },\n);\n\nexport type RpcOrigins = Infer<typeof RpcOriginsStruct>;\n\n/**\n * Asserts that the given value is a valid {@link RpcOrigins} object.\n *\n * @param value - The value to assert.\n * @param ErrorWrapper - An optional error wrapper to use. Defaults to\n * {@link AssertionError}.\n * @throws If the value is not a valid {@link RpcOrigins} object.\n */\nexport function assertIsRpcOrigins(\n value: unknown,\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is RpcOrigins {\n assertStruct(\n value,\n RpcOriginsStruct,\n 'Invalid JSON-RPC origins',\n ErrorWrapper,\n );\n}\n\nexport const KeyringOriginsStruct = object({\n allowedOrigins: optional(AllowedOriginsStruct),\n});\n\nexport type KeyringOrigins = Infer<typeof KeyringOriginsStruct>;\n\n/**\n * Assert that the given value is a valid {@link KeyringOrigins} object.\n *\n * @param value - The value to assert.\n * @param ErrorWrapper - An optional error wrapper to use. Defaults to\n * {@link AssertionError}.\n * @throws If the value is not a valid {@link KeyringOrigins} object.\n */\nexport function assertIsKeyringOrigins(\n value: unknown,\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is KeyringOrigins {\n assertStruct(\n value,\n KeyringOriginsStruct,\n 'Invalid keyring origins',\n ErrorWrapper,\n );\n}\n\n/**\n * Create regular expression for matching against an origin while allowing wildcards.\n *\n * The \"*\" symbol is treated as a wildcard and will match 0 or more characters.\n *\n * @param matcher - The string to create the regular expression with.\n * @returns The regular expression.\n */\nfunction createOriginRegExp(matcher: string) {\n // Escape potential Regex characters\n const escaped = matcher.replace(/[.*+?^${}()|[\\]\\\\]/gu, '\\\\$&');\n // Support wildcards\n const regex = escaped.replace(/\\\\\\*/gu, '.*');\n return RegExp(`^${regex}$`, 'u');\n}\n\n/**\n * Check whether an origin is allowed or not using a matcher string.\n *\n * The matcher string may be a specific origin to match or include wildcards.\n * The \"*\" symbol is treated as a wildcard and will match 0 or more characters.\n * Note: this means that https://*metamask.io matches both https://metamask.io\n * and https://snaps.metamask.io.\n *\n * @param matcher - The matcher string.\n * @param origin - The origin.\n * @returns Whether the origin is allowed.\n */\nfunction checkAllowedOrigin(matcher: string, origin: string) {\n // If the matcher is a single wildcard or identical to the origin we can return true immediately.\n if (matcher === '*' || matcher === origin) {\n return true;\n }\n\n const regex = createOriginRegExp(matcher);\n return regex.test(origin);\n}\n\n/**\n * Check if the given origin is allowed by the given JSON-RPC origins object.\n *\n * @param origins - The JSON-RPC origins object.\n * @param subjectType - The type of the origin.\n * @param origin - The origin to check.\n * @returns Whether the origin is allowed.\n */\nexport function isOriginAllowed(\n origins: RpcOrigins,\n subjectType: SubjectType,\n origin: string,\n) {\n // The MetaMask client is always allowed.\n if (origin === 'metamask') {\n return true;\n }\n\n // If the origin is in the `allowedOrigins` list, it is allowed.\n if (\n origins.allowedOrigins?.some((matcher) =>\n checkAllowedOrigin(matcher, origin),\n )\n ) {\n return true;\n }\n\n // If the origin is a website and `dapps` is true, it is allowed.\n if (subjectType === SubjectType.Website && origins.dapps) {\n return true;\n }\n\n // If the origin is a snap and `snaps` is true, it is allowed.\n return Boolean(subjectType === SubjectType.Snap && origins.snaps);\n}\n\n/**\n * Assert that the given value is a successful JSON-RPC response. If the value\n * is not a success response, an error is thrown. If the value is an JSON-RPC\n * error, the error message is included in the thrown error.\n *\n * @param value - The value to check.\n * @throws If the value is not a JSON-RPC success response.\n */\nexport function assertIsJsonRpcSuccess(\n value: unknown,\n): asserts value is JsonRpcSuccess<Json> {\n if (!isJsonRpcSuccess(value)) {\n if (isJsonRpcFailure(value)) {\n throw new Error(`JSON-RPC request failed: ${value.error.message}`);\n }\n\n throw new Error('Invalid JSON-RPC response.');\n }\n}\n"]}
1
+ {"version":3,"file":"json-rpc.cjs","sourceRoot":"","sources":["../src/json-rpc.ts"],"names":[],"mappings":";;;AAAA,2EAA8D;AAE9D,uDAO+B;AAK/B,2CAIyB;AAEzB,MAAM,oBAAoB,GAAG,IAAA,mBAAK,EAChC,IAAA,oBAAM,EAAC,IAAA,oBAAM,GAAE,EAAE,gBAAgB,EAAE,CAAC,KAAK,EAAE,EAAE;IAC3C,MAAM,SAAS,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;IAC9C,IAAI,SAAS,GAAG,CAAC,EAAE,CAAC;QAClB,OAAO,sEAAsE,CAAC;IAChF,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC,CACH,CAAC;AAEW,QAAA,gBAAgB,GAAG,IAAA,oBAAM,EACpC,IAAA,oBAAM,EAAC;IACL,KAAK,EAAE,IAAA,sBAAQ,EAAC,IAAA,qBAAO,GAAE,CAAC;IAC1B,KAAK,EAAE,IAAA,sBAAQ,EAAC,IAAA,qBAAO,GAAE,CAAC;IAC1B,cAAc,EAAE,IAAA,sBAAQ,EAAC,oBAAoB,CAAC;CAC/C,CAAC,EACF,aAAa,EACb,CAAC,KAAK,EAAE,EAAE;IACR,MAAM,UAAU,GAAG,OAAO,CACxB,KAAK,CAAC,KAAK,KAAK,IAAI;QAClB,KAAK,CAAC,KAAK,KAAK,IAAI;QACpB,CAAC,KAAK,CAAC,cAAc,IAAI,KAAK,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC,CAAC,CAC5D,CAAC;IAEF,IAAI,UAAU,EAAE,CAAC;QACf,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,4CAA4C,CAAC;AACtD,CAAC,CACF,CAAC;AAIF;;;;;;;GAOG;AACH,SAAgB,kBAAkB,CAChC,KAAc,EACd,YAAwC;I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E,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CACvC,kBAAkB,CAAC,OAAO,EAAE,MAAM,CAAC,CACpC,EACD,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,iEAAiE;IACjE,IAAI,WAAW,KAAK,mCAAW,CAAC,OAAO,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;QACzD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,8DAA8D;IAC9D,OAAO,OAAO,CAAC,WAAW,KAAK,mCAAW,CAAC,IAAI,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC;AACpE,CAAC;AA1BD,0CA0BC;AAED;;;;;;;GAOG;AACH,SAAgB,sBAAsB,CACpC,KAAc;IAEd,IAAI,CAAC,IAAA,wBAAgB,EAAC,KAAK,CAAC,EAAE,CAAC;QAC7B,IAAI,IAAA,wBAAgB,EAAC,KAAK,CAAC,EAAE,CAAC;YAC5B,MAAM,IAAI,KAAK,CAAC,4BAA4B,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QACrE,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;IAChD,CAAC;AACH,CAAC;AAVD,wDAUC","sourcesContent":["import { SubjectType } from '@metamask/permission-controller';\nimport type { Infer } from '@metamask/superstruct';\nimport {\n array,\n boolean,\n object,\n optional,\n refine,\n string,\n} from '@metamask/superstruct';\nimport type {\n AssertionErrorConstructor,\n JsonRpcSuccess,\n} from '@metamask/utils';\nimport {\n assertStruct,\n isJsonRpcFailure,\n isJsonRpcSuccess,\n} from '@metamask/utils';\n\nconst AllowedOriginsStruct = array(\n refine(string(), 'Allowed origin', (value) => {\n const wildcards = value.split('*').length - 1;\n if (wildcards > 2) {\n return 'No more than two wildcards (\"*\") are allowed in an origin specifier.';\n }\n\n return true;\n }),\n);\n\nexport const RpcOriginsStruct = refine(\n object({\n dapps: optional(boolean()),\n snaps: optional(boolean()),\n allowedOrigins: optional(AllowedOriginsStruct),\n }),\n 'RPC origins',\n (value) => {\n const hasOrigins = Boolean(\n value.snaps === true ||\n value.dapps === true ||\n (value.allowedOrigins && value.allowedOrigins.length > 0),\n );\n\n if (hasOrigins) {\n return true;\n }\n\n return 'Must specify at least one JSON-RPC origin.';\n },\n);\n\nexport type RpcOrigins = Infer<typeof RpcOriginsStruct>;\n\n/**\n * Asserts that the given value is a valid {@link RpcOrigins} object.\n *\n * @param value - The value to assert.\n * @param ErrorWrapper - An optional error wrapper to use. Defaults to\n * {@link AssertionError}.\n * @throws If the value is not a valid {@link RpcOrigins} object.\n */\nexport function assertIsRpcOrigins(\n value: unknown,\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is RpcOrigins {\n assertStruct(\n value,\n RpcOriginsStruct,\n 'Invalid JSON-RPC origins',\n ErrorWrapper,\n );\n}\n\nexport const KeyringOriginsStruct = object({\n allowedOrigins: optional(AllowedOriginsStruct),\n});\n\nexport type KeyringOrigins = Infer<typeof KeyringOriginsStruct>;\n\n/**\n * Assert that the given value is a valid {@link KeyringOrigins} object.\n *\n * @param value - The value to assert.\n * @param ErrorWrapper - An optional error wrapper to use. Defaults to\n * {@link AssertionError}.\n * @throws If the value is not a valid {@link KeyringOrigins} object.\n */\nexport function assertIsKeyringOrigins(\n value: unknown,\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is KeyringOrigins {\n assertStruct(\n value,\n KeyringOriginsStruct,\n 'Invalid keyring origins',\n ErrorWrapper,\n );\n}\n\n/**\n * Create regular expression for matching against an origin while allowing wildcards.\n *\n * The \"*\" symbol is treated as a wildcard and will match 0 or more characters.\n *\n * @param matcher - The string to create the regular expression with.\n * @returns The regular expression.\n */\nfunction createOriginRegExp(matcher: string) {\n // Escape potential Regex characters\n const escaped = matcher.replace(/[.*+?^${}()|[\\]\\\\]/gu, '\\\\$&');\n // Support wildcards\n const regex = escaped.replace(/\\\\\\*/gu, '.*');\n return RegExp(`^${regex}$`, 'u');\n}\n\n/**\n * Check whether an origin is allowed or not using a matcher string.\n *\n * The matcher string may be a specific origin to match or include wildcards.\n * The \"*\" symbol is treated as a wildcard and will match 0 or more characters.\n * Note: this means that https://*metamask.io matches both https://metamask.io\n * and https://snaps.metamask.io.\n *\n * @param matcher - The matcher string.\n * @param origin - The origin.\n * @returns Whether the origin is allowed.\n */\nfunction checkAllowedOrigin(matcher: string, origin: string) {\n // If the matcher is a single wildcard or identical to the origin we can return true immediately.\n if (matcher === '*' || matcher === origin) {\n return true;\n }\n\n const regex = createOriginRegExp(matcher);\n return regex.test(origin);\n}\n\n/**\n * Check if the given origin is allowed by the given JSON-RPC origins object.\n *\n * @param origins - The JSON-RPC origins object.\n * @param subjectType - The type of the origin.\n * @param origin - The origin to check.\n * @returns Whether the origin is allowed.\n */\nexport function isOriginAllowed(\n origins: RpcOrigins,\n subjectType: SubjectType,\n origin: string,\n) {\n // The MetaMask client is always allowed.\n if (origin === 'metamask') {\n return true;\n }\n\n // If the origin is in the `allowedOrigins` list, it is allowed.\n if (\n origins.allowedOrigins?.some((matcher) =>\n checkAllowedOrigin(matcher, origin),\n )\n ) {\n return true;\n }\n\n // If the origin is a website and `dapps` is true, it is allowed.\n if (subjectType === SubjectType.Website && origins.dapps) {\n return true;\n }\n\n // If the origin is a snap and `snaps` is true, it is allowed.\n return Boolean(subjectType === SubjectType.Snap && origins.snaps);\n}\n\n/**\n * Assert that the given value is a successful JSON-RPC response. If the value\n * is not a success response, an error is thrown. If the value is an JSON-RPC\n * error, the error message is included in the thrown error.\n *\n * @param value - The value to check.\n * @throws If the value is not a JSON-RPC success response.\n */\nexport function assertIsJsonRpcSuccess(\n value: unknown,\n): asserts value is JsonRpcSuccess {\n if (!isJsonRpcSuccess(value)) {\n if (isJsonRpcFailure(value)) {\n throw new Error(`JSON-RPC request failed: ${value.error.message}`);\n }\n\n throw new Error('Invalid JSON-RPC response.');\n }\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  import { SubjectType } from "@metamask/permission-controller";
2
2
  import type { Infer } from "@metamask/superstruct";
3
- import type { AssertionErrorConstructor, Json, JsonRpcSuccess } from "@metamask/utils";
3
+ import type { AssertionErrorConstructor, JsonRpcSuccess } from "@metamask/utils";
4
4
  export declare const RpcOriginsStruct: import("@metamask/superstruct").Struct<{
5
5
  snaps?: boolean | undefined;
6
6
  dapps?: boolean | undefined;
@@ -52,5 +52,5 @@ export declare function isOriginAllowed(origins: RpcOrigins, subjectType: Subjec
52
52
  * @param value - The value to check.
53
53
  * @throws If the value is not a JSON-RPC success response.
54
54
  */
55
- export declare function assertIsJsonRpcSuccess(value: unknown): asserts value is JsonRpcSuccess<Json>;
55
+ export declare function assertIsJsonRpcSuccess(value: unknown): asserts value is JsonRpcSuccess;
56
56
  //# sourceMappingURL=json-rpc.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"json-rpc.d.cts","sourceRoot":"","sources":["../src/json-rpc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,wCAAwC;AAC9D,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AASnD,OAAO,KAAK,EACV,yBAAyB,EACzB,IAAI,EACJ,cAAc,EACf,wBAAwB;AAkBzB,eAAO,MAAM,gBAAgB;;;;;;;;EAoB5B,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAExD;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,OAAO,EACd,YAAY,CAAC,EAAE,yBAAyB,GACvC,OAAO,CAAC,KAAK,IAAI,UAAU,CAO7B;AAED,eAAO,MAAM,oBAAoB;;;;EAE/B,CAAC;AAEH,MAAM,MAAM,cAAc,GAAG,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAEhE;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,OAAO,EACd,YAAY,CAAC,EAAE,yBAAyB,GACvC,OAAO,CAAC,KAAK,IAAI,cAAc,CAOjC;AAwCD;;;;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ask/permission-controller";
2
2
  import type { Infer } from "@metamask/superstruct";
3
- import type { AssertionErrorConstructor, Json, JsonRpcSuccess } from "@metamask/utils";
3
+ import type { AssertionErrorConstructor, JsonRpcSuccess } from "@metamask/utils";
4
4
  export declare const RpcOriginsStruct: import("@metamask/superstruct").Struct<{
5
5
  snaps?: boolean | undefined;
6
6
  dapps?: boolean | undefined;
@@ -52,5 +52,5 @@ export declare function isOriginAllowed(origins: RpcOrigins, subjectType: Subjec
52
52
  * @param value - The value to check.
53
53
  * @throws If the value is not a JSON-RPC success response.
54
54
  */
55
- export declare function assertIsJsonRpcSuccess(value: unknown): asserts value is JsonRpcSuccess<Json>;
55
+ export declare function assertIsJsonRpcSuccess(value: unknown): asserts value is JsonRpcSuccess;
56
56
  //# sourceMappingURL=json-rpc.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"json-rpc.d.mts","sourceRoot":"","sources":["../src/json-rpc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,wCAAwC;AAC9D,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AASnD,OAAO,KAAK,EACV,yBAAyB,EACzB,IAAI,EACJ,cAAc,EACf,wBAAwB;AAkBzB,eAAO,MAAM,gBAAgB;;;;;;;;EAoB5B,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAExD;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,OAAO,EACd,YAAY,CAAC,EAAE,yBAAyB,GACvC,OAAO,CAAC,KAAK,IAAI,UAAU,CAO7B;AAED,eAAO,MAAM,oBAAoB;;;;EAE/B,CAAC;AAEH,MAAM,MAAM,cAAc,GAAG,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAEhE;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,OAAO,EACd,YAAY,CAAC,EAAE,yBAAyB,GACvC,OAAO,CAAC,KAA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AC,OAAO,EAAE,EAAE,CACvC,kBAAkB,CAAC,OAAO,EAAE,MAAM,CAAC,CACpC,EACD,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,iEAAiE;IACjE,IAAI,WAAW,KAAK,WAAW,CAAC,OAAO,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;QACzD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,8DAA8D;IAC9D,OAAO,OAAO,CAAC,WAAW,KAAK,WAAW,CAAC,IAAI,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC;AACpE,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,sBAAsB,CACpC,KAAc;IAEd,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,EAAE,CAAC;QAC7B,IAAI,gBAAgB,CAAC,KAAK,CAAC,EAAE,CAAC;YAC5B,MAAM,IAAI,KAAK,CAAC,4BAA4B,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QACrE,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;IAChD,CAAC;AACH,CAAC","sourcesContent":["import { SubjectType } from '@metamask/permission-controller';\nimport type { Infer } from '@metamask/superstruct';\nimport {\n array,\n boolean,\n object,\n optional,\n refine,\n string,\n} from '@metamask/superstruct';\nimport type {\n AssertionErrorConstructor,\n Json,\n JsonRpcSuccess,\n} from '@metamask/utils';\nimport {\n assertStruct,\n isJsonRpcFailure,\n isJsonRpcSuccess,\n} from '@metamask/utils';\n\nconst AllowedOriginsStruct = array(\n refine(string(), 'Allowed origin', (value) => {\n const wildcards = value.split('*').length - 1;\n if (wildcards > 2) {\n return 'No more than two wildcards (\"*\") are allowed in an origin specifier.';\n }\n\n return true;\n }),\n);\n\nexport const RpcOriginsStruct = refine(\n object({\n dapps: optional(boolean()),\n snaps: optional(boolean()),\n allowedOrigins: optional(AllowedOriginsStruct),\n }),\n 'RPC origins',\n (value) => {\n const hasOrigins = Boolean(\n value.snaps === true ||\n value.dapps === true ||\n (value.allowedOrigins && value.allowedOrigins.length > 0),\n );\n\n if (hasOrigins) {\n return true;\n }\n\n return 'Must specify at least one JSON-RPC origin.';\n },\n);\n\nexport type RpcOrigins = Infer<typeof RpcOriginsStruct>;\n\n/**\n * Asserts that the given value is a valid {@link RpcOrigins} object.\n *\n * @param value - The value to assert.\n * @param ErrorWrapper - An optional error wrapper to use. Defaults to\n * {@link AssertionError}.\n * @throws If the value is not a valid {@link RpcOrigins} object.\n */\nexport function assertIsRpcOrigins(\n value: unknown,\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is RpcOrigins {\n assertStruct(\n value,\n RpcOriginsStruct,\n 'Invalid JSON-RPC origins',\n ErrorWrapper,\n );\n}\n\nexport const KeyringOriginsStruct = object({\n allowedOrigins: optional(AllowedOriginsStruct),\n});\n\nexport type KeyringOrigins = Infer<typeof KeyringOriginsStruct>;\n\n/**\n * Assert that the given value is a valid {@link KeyringOrigins} object.\n *\n * @param value - The value to assert.\n * @param ErrorWrapper - An optional error wrapper to use. Defaults to\n * {@link AssertionError}.\n * @throws If the value is not a valid {@link KeyringOrigins} object.\n */\nexport function assertIsKeyringOrigins(\n value: unknown,\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is KeyringOrigins {\n assertStruct(\n value,\n KeyringOriginsStruct,\n 'Invalid keyring origins',\n ErrorWrapper,\n );\n}\n\n/**\n * Create regular expression for matching against an origin while allowing wildcards.\n *\n * The \"*\" symbol is treated as a wildcard and will match 0 or more characters.\n *\n * @param matcher - The string to create the regular expression with.\n * @returns The regular expression.\n */\nfunction createOriginRegExp(matcher: string) {\n // Escape potential Regex characters\n const escaped = matcher.replace(/[.*+?^${}()|[\\]\\\\]/gu, '\\\\$&');\n // Support wildcards\n const regex = escaped.replace(/\\\\\\*/gu, '.*');\n return RegExp(`^${regex}$`, 'u');\n}\n\n/**\n * Check whether an origin is allowed or not using a matcher string.\n *\n * The matcher string may be a specific origin to match or include wildcards.\n * The \"*\" symbol is treated as a wildcard and will match 0 or more characters.\n * Note: this means that https://*metamask.io matches both https://metamask.io\n * and https://snaps.metamask.io.\n *\n * @param matcher - The matcher string.\n * @param origin - The origin.\n * @returns Whether the origin is allowed.\n */\nfunction checkAllowedOrigin(matcher: string, origin: string) {\n // If the matcher is a single wildcard or identical to the origin we can return true immediately.\n if (matcher === '*' || matcher === origin) {\n return true;\n }\n\n const regex = createOriginRegExp(matcher);\n return regex.test(origin);\n}\n\n/**\n * Check if the given origin is allowed by the given JSON-RPC origins object.\n *\n * @param origins - The JSON-RPC origins object.\n * @param subjectType - The type of the origin.\n * @param origin - The origin to check.\n * @returns Whether the origin is allowed.\n */\nexport function isOriginAllowed(\n origins: RpcOrigins,\n subjectType: SubjectType,\n origin: string,\n) {\n // The MetaMask client is always allowed.\n if (origin === 'metamask') {\n return true;\n }\n\n // If the origin is in the `allowedOrigins` list, it is allowed.\n if (\n origins.allowedOrigins?.some((matcher) =>\n checkAllowedOrigin(matcher, origin),\n )\n ) {\n return true;\n }\n\n // If the origin is a website and `dapps` is true, it is allowed.\n if (subjectType === SubjectType.Website && origins.dapps) {\n return true;\n }\n\n // If the origin is a snap and `snaps` is true, it is allowed.\n return Boolean(subjectType === SubjectType.Snap && origins.snaps);\n}\n\n/**\n * Assert that the given value is a successful JSON-RPC response. If the value\n * is not a success response, an error is thrown. If the value is an JSON-RPC\n * error, the error message is included in the thrown error.\n *\n * @param value - The value to check.\n * @throws If the value is not a JSON-RPC success response.\n */\nexport function assertIsJsonRpcSuccess(\n value: unknown,\n): asserts value is JsonRpcSuccess<Json> {\n if (!isJsonRpcSuccess(value)) {\n if (isJsonRpcFailure(value)) {\n throw new Error(`JSON-RPC request failed: ${value.error.message}`);\n }\n\n throw new Error('Invalid JSON-RPC response.');\n }\n}\n"]}
1
+ {"version":3,"file":"json-rpc.mjs","sourceRoot":"","sources":["../src/json-rpc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,wCAAwC;AAE9D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EAAiE;IACjE,IAAI,WAAW,KAAK,WAAW,CAAC,OAAO,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;QACzD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,8DAA8D;IAC9D,OAAO,OAAO,CAAC,WAAW,KAAK,WAAW,CAAC,IAAI,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC;AACpE,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,sBAAsB,CACpC,KAAc;IAEd,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,EAAE,CAAC;QAC7B,IAAI,gBAAgB,CAAC,KAAK,CAAC,EAAE,CAAC;YAC5B,MAAM,IAAI,KAAK,CAAC,4BAA4B,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QACrE,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;IAChD,CAAC;AACH,CAAC","sourcesContent":["import { SubjectType } from '@metamask/permission-controller';\nimport type { Infer } from '@metamask/superstruct';\nimport {\n array,\n boolean,\n object,\n optional,\n refine,\n string,\n} from '@metamask/superstruct';\nimport type {\n AssertionErrorConstructor,\n JsonRpcSuccess,\n} from '@metamask/utils';\nimport {\n assertStruct,\n isJsonRpcFailure,\n isJsonRpcSuccess,\n} from '@metamask/utils';\n\nconst AllowedOriginsStruct = array(\n refine(string(), 'Allowed origin', (value) => {\n const wildcards = value.split('*').length - 1;\n if (wildcards > 2) {\n return 'No more than two wildcards (\"*\") are allowed in an origin specifier.';\n }\n\n return true;\n }),\n);\n\nexport const RpcOriginsStruct = refine(\n object({\n dapps: optional(boolean()),\n snaps: optional(boolean()),\n allowedOrigins: optional(AllowedOriginsStruct),\n }),\n 'RPC origins',\n (value) => {\n const hasOrigins = Boolean(\n value.snaps === true ||\n value.dapps === true ||\n (value.allowedOrigins && value.allowedOrigins.length > 0),\n );\n\n if (hasOrigins) {\n return true;\n }\n\n return 'Must specify at least one JSON-RPC origin.';\n },\n);\n\nexport type RpcOrigins = Infer<typeof RpcOriginsStruct>;\n\n/**\n * Asserts that the given value is a valid {@link RpcOrigins} object.\n *\n * @param value - The value to assert.\n * @param ErrorWrapper - An optional error wrapper to use. Defaults to\n * {@link AssertionError}.\n * @throws If the value is not a valid {@link RpcOrigins} object.\n */\nexport function assertIsRpcOrigins(\n value: unknown,\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is RpcOrigins {\n assertStruct(\n value,\n RpcOriginsStruct,\n 'Invalid JSON-RPC origins',\n ErrorWrapper,\n );\n}\n\nexport const KeyringOriginsStruct = object({\n allowedOrigins: optional(AllowedOriginsStruct),\n});\n\nexport type KeyringOrigins = Infer<typeof KeyringOriginsStruct>;\n\n/**\n * Assert that the given value is a valid {@link KeyringOrigins} object.\n *\n * @param value - The value to assert.\n * @param ErrorWrapper - An optional error wrapper to use. Defaults to\n * {@link AssertionError}.\n * @throws If the value is not a valid {@link KeyringOrigins} object.\n */\nexport function assertIsKeyringOrigins(\n value: unknown,\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is KeyringOrigins {\n assertStruct(\n value,\n KeyringOriginsStruct,\n 'Invalid keyring origins',\n ErrorWrapper,\n );\n}\n\n/**\n * Create regular expression for matching against an origin while allowing wildcards.\n *\n * The \"*\" symbol is treated as a wildcard and will match 0 or more characters.\n *\n * @param matcher - The string to create the regular expression with.\n * @returns The regular expression.\n */\nfunction createOriginRegExp(matcher: string) {\n // Escape potential Regex characters\n const escaped = matcher.replace(/[.*+?^${}()|[\\]\\\\]/gu, '\\\\$&');\n // Support wildcards\n const regex = escaped.replace(/\\\\\\*/gu, '.*');\n return RegExp(`^${regex}$`, 'u');\n}\n\n/**\n * Check whether an origin is allowed or not using a matcher string.\n *\n * The matcher string may be a specific origin to match or include wildcards.\n * The \"*\" symbol is treated as a wildcard and will match 0 or more characters.\n * Note: this means that https://*metamask.io matches both https://metamask.io\n * and https://snaps.metamask.io.\n *\n * @param matcher - The matcher string.\n * @param origin - The origin.\n * @returns Whether the origin is allowed.\n */\nfunction checkAllowedOrigin(matcher: string, origin: string) {\n // If the matcher is a single wildcard or identical to the origin we can return true immediately.\n if (matcher === '*' || matcher === origin) {\n return true;\n }\n\n const regex = createOriginRegExp(matcher);\n return regex.test(origin);\n}\n\n/**\n * Check if the given origin is allowed by the given JSON-RPC origins object.\n *\n * @param origins - The JSON-RPC origins object.\n * @param subjectType - The type of the origin.\n * @param origin - The origin to check.\n * @returns Whether the origin is allowed.\n */\nexport function isOriginAllowed(\n origins: RpcOrigins,\n subjectType: SubjectType,\n origin: string,\n) {\n // The MetaMask client is always allowed.\n if (origin === 'metamask') {\n return true;\n }\n\n // If the origin is in the `allowedOrigins` list, it is allowed.\n if (\n origins.allowedOrigins?.some((matcher) =>\n checkAllowedOrigin(matcher, origin),\n )\n ) {\n return true;\n }\n\n // If the origin is a website and `dapps` is true, it is allowed.\n if (subjectType === SubjectType.Website && origins.dapps) {\n return true;\n }\n\n // If the origin is a snap and `snaps` is true, it is allowed.\n return Boolean(subjectType === SubjectType.Snap && origins.snaps);\n}\n\n/**\n * Assert that the given value is a successful JSON-RPC response. If the value\n * is not a success response, an error is thrown. If the value is an JSON-RPC\n * error, the error message is included in the thrown error.\n *\n * @param value - The value to check.\n * @throws If the value is not a JSON-RPC success response.\n */\nexport function assertIsJsonRpcSuccess(\n value: unknown,\n): asserts value is JsonRpcSuccess {\n if (!isJsonRpcSuccess(value)) {\n if (isJsonRpcFailure(value)) {\n throw new Error(`JSON-RPC request failed: ${value.error.message}`);\n }\n\n throw new Error('Invalid JSON-RPC response.');\n }\n}\n"]}
package/dist/json.cjs CHANGED
@@ -23,12 +23,16 @@ exports.parseJson = parseJson;
23
23
  *
24
24
  * This may sometimes be preferred over `getJsonSize` for performance reasons.
25
25
  *
26
+ * Note: This function does not encode the string to bytes, thus the input may
27
+ * be about 4x larger in practice. Use this function with caution.
28
+ *
26
29
  * @param value - The JSON value to get the size of.
27
30
  * @returns The size of the JSON value in bytes.
28
31
  */
29
32
  function getJsonSizeUnsafe(value) {
30
33
  const json = JSON.stringify(value);
31
- return new TextEncoder().encode(json).byteLength;
34
+ // We intentionally don't use `TextEncoder` because of bad performance on React Native.
35
+ return json.length;
32
36
  }
33
37
  exports.getJsonSizeUnsafe = getJsonSizeUnsafe;
34
38
  //# sourceMappingURL=json.cjs.map
package/dist/json.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"json.cjs","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":";;;AACA,2CAA8C;AAE9C,yCAAyC;AAEzC;;;;;;;;;;GAUG;AACH,SAAgB,SAAS,CAA2B,IAAY;IAC9D,OAAO,IAAA,mBAAW,EAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;AAC7C,CAAC;AAFD,8BAEC;AAED;;;;;;;GAOG;AACH,SAAgB,iBAAiB,CAAC,KAAW;IAC3C,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACnC,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC;AACnD,CAAC;AAHD,8CAGC","sourcesContent":["import type { Json } from '@metamask/utils';\nimport { getSafeJson } from '@metamask/utils';\n\n// TODO: Upstream this to @metamask/utils\n\n/**\n * Parse JSON safely.\n *\n * Does multiple kinds of validation and strips unwanted properties like\n * `__proto__` and `constructor`.\n *\n * @param json - A JSON string to be parsed.\n * @returns The parsed JSON object.\n * @template Type - The type of the JSON object. The type is not actually\n * checked, but it is used to infer the return type.\n */\nexport function parseJson<Type extends Json = Json>(json: string) {\n return getSafeJson<Type>(JSON.parse(json));\n}\n\n/**\n * Get the size of a JSON blob without validating that is valid JSON.\n *\n * This may sometimes be preferred over `getJsonSize` for performance reasons.\n *\n * @param value - The JSON value to get the size of.\n * @returns The size of the JSON value in bytes.\n */\nexport function getJsonSizeUnsafe(value: Json): number {\n const json = JSON.stringify(value);\n return new TextEncoder().encode(json).byteLength;\n}\n"]}
1
+ {"version":3,"file":"json.cjs","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":";;;AACA,2CAA8C;AAE9C,yCAAyC;AAEzC;;;;;;;;;;GAUG;AACH,SAAgB,SAAS,CAA2B,IAAY;IAC9D,OAAO,IAAA,mBAAW,EAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;AAC7C,CAAC;AAFD,8BAEC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,iBAAiB,CAAC,KAAW;IAC3C,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACnC,uFAAuF;IACvF,OAAO,IAAI,CAAC,MAAM,CAAC;AACrB,CAAC;AAJD,8CAIC","sourcesContent":["import type { Json } from '@metamask/utils';\nimport { getSafeJson } from '@metamask/utils';\n\n// TODO: Upstream this to @metamask/utils\n\n/**\n * Parse JSON safely.\n *\n * Does multiple kinds of validation and strips unwanted properties like\n * `__proto__` and `constructor`.\n *\n * @param json - A JSON string to be parsed.\n * @returns The parsed JSON object.\n * @template Type - The type of the JSON object. The type is not actually\n * checked, but it is used to infer the return type.\n */\nexport function parseJson<Type extends Json = Json>(json: string) {\n return getSafeJson<Type>(JSON.parse(json));\n}\n\n/**\n * Get the size of a JSON blob without validating that is valid JSON.\n *\n * This may sometimes be preferred over `getJsonSize` for performance reasons.\n *\n * Note: This function does not encode the string to bytes, thus the input may\n * be about 4x larger in practice. Use this function with caution.\n *\n * @param value - The JSON value to get the size of.\n * @returns The size of the JSON value in bytes.\n */\nexport function getJsonSizeUnsafe(value: Json): number {\n const json = JSON.stringify(value);\n // We intentionally don't use `TextEncoder` because of bad performance on React Native.\n return json.length;\n}\n"]}
package/dist/json.d.cts CHANGED
@@ -16,6 +16,9 @@ export declare function parseJson<Type extends Json = Json>(json: string): Type;
16
16
  *
17
17
  * This may sometimes be preferred over `getJsonSize` for performance reasons.
18
18
  *
19
+ * Note: This function does not encode the string to bytes, thus the input may
20
+ * be about 4x larger in practice. Use this function with caution.
21
+ *
19
22
  * @param value - The JSON value to get the size of.
20
23
  * @returns The size of the JSON value in bytes.
21
24
  */
@@ -1 +1 @@
1
- {"version":3,"file":"json.d.cts","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAK5C;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,IAAI,SAAS,IAAI,GAAG,IAAI,EAAE,IAAI,EAAE,MAAM,QAE/D;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,IAAI,GAAG,MAAM,CAGrD"}
1
+ {"version":3,"file":"json.d.cts","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAK5C;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,IAAI,SAAS,IAAI,GAAG,IAAI,EAAE,IAAI,EAAE,MAAM,QAE/D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,IAAI,GAAG,MAAM,CAIrD"}
package/dist/json.d.mts CHANGED
@@ -16,6 +16,9 @@ export declare function parseJson<Type extends Json = Json>(json: string): Type;
16
16
  *
17
17
  * This may sometimes be preferred over `getJsonSize` for performance reasons.
18
18
  *
19
+ * Note: This function does not encode the string to bytes, thus the input may
20
+ * be about 4x larger in practice. Use this function with caution.
21
+ *
19
22
  * @param value - The JSON value to get the size of.
20
23
  * @returns The size of the JSON value in bytes.
21
24
  */
@@ -1 +1 @@
1
- {"version":3,"file":"json.d.mts","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAK5C;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,IAAI,SAAS,IAAI,GAAG,IAAI,EAAE,IAAI,EAAE,MAAM,QAE/D;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,IAAI,GAAG,MAAM,CAGrD"}
1
+ {"version":3,"file":"json.d.mts","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAK5C;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,IAAI,SAAS,IAAI,GAAG,IAAI,EAAE,IAAI,EAAE,MAAM,QAE/D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,IAAI,GAAG,MAAM,CAIrD"}
package/dist/json.mjs CHANGED
@@ -19,11 +19,15 @@ export function parseJson(json) {
19
19
  *
20
20
  * This may sometimes be preferred over `getJsonSize` for performance reasons.
21
21
  *
22
+ * Note: This function does not encode the string to bytes, thus the input may
23
+ * be about 4x larger in practice. Use this function with caution.
24
+ *
22
25
  * @param value - The JSON value to get the size of.
23
26
  * @returns The size of the JSON value in bytes.
24
27
  */
25
28
  export function getJsonSizeUnsafe(value) {
26
29
  const json = JSON.stringify(value);
27
- return new TextEncoder().encode(json).byteLength;
30
+ // We intentionally don't use `TextEncoder` because of bad performance on React Native.
31
+ return json.length;
28
32
  }
29
33
  //# sourceMappingURL=json.mjs.map
package/dist/json.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"json.mjs","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,wBAAwB;AAE9C,yCAAyC;AAEzC;;;;;;;;;;GAUG;AACH,MAAM,UAAU,SAAS,CAA2B,IAAY;IAC9D,OAAO,WAAW,CAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;AAC7C,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAW;IAC3C,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACnC,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC;AACnD,CAAC","sourcesContent":["import type { Json } from '@metamask/utils';\nimport { getSafeJson } from '@metamask/utils';\n\n// TODO: Upstream this to @metamask/utils\n\n/**\n * Parse JSON safely.\n *\n * Does multiple kinds of validation and strips unwanted properties like\n * `__proto__` and `constructor`.\n *\n * @param json - A JSON string to be parsed.\n * @returns The parsed JSON object.\n * @template Type - The type of the JSON object. The type is not actually\n * checked, but it is used to infer the return type.\n */\nexport function parseJson<Type extends Json = Json>(json: string) {\n return getSafeJson<Type>(JSON.parse(json));\n}\n\n/**\n * Get the size of a JSON blob without validating that is valid JSON.\n *\n * This may sometimes be preferred over `getJsonSize` for performance reasons.\n *\n * @param value - The JSON value to get the size of.\n * @returns The size of the JSON value in bytes.\n */\nexport function getJsonSizeUnsafe(value: Json): number {\n const json = JSON.stringify(value);\n return new TextEncoder().encode(json).byteLength;\n}\n"]}
1
+ {"version":3,"file":"json.mjs","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,wBAAwB;AAE9C,yCAAyC;AAEzC;;;;;;;;;;GAUG;AACH,MAAM,UAAU,SAAS,CAA2B,IAAY;IAC9D,OAAO,WAAW,CAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;AAC7C,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAW;IAC3C,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACnC,uFAAuF;IACvF,OAAO,IAAI,CAAC,MAAM,CAAC;AACrB,CAAC","sourcesContent":["import type { Json } from '@metamask/utils';\nimport { getSafeJson } from '@metamask/utils';\n\n// TODO: Upstream this to @metamask/utils\n\n/**\n * Parse JSON safely.\n *\n * Does multiple kinds of validation and strips unwanted properties like\n * `__proto__` and `constructor`.\n *\n * @param json - A JSON string to be parsed.\n * @returns The parsed JSON object.\n * @template Type - The type of the JSON object. The type is not actually\n * checked, but it is used to infer the return type.\n */\nexport function parseJson<Type extends Json = Json>(json: string) {\n return getSafeJson<Type>(JSON.parse(json));\n}\n\n/**\n * Get the size of a JSON blob without validating that is valid JSON.\n *\n * This may sometimes be preferred over `getJsonSize` for performance reasons.\n *\n * Note: This function does not encode the string to bytes, thus the input may\n * be about 4x larger in practice. Use this function with caution.\n *\n * @param value - The JSON value to get the size of.\n * @returns The size of the JSON value in bytes.\n */\nexport function getJsonSizeUnsafe(value: Json): number {\n const json = JSON.stringify(value);\n // We intentionally don't use `TextEncoder` because of bad performance on React Native.\n return json.length;\n}\n"]}
@@ -3,11 +3,11 @@ import type { SnapManifest } from "./manifest/index.cjs";
3
3
  import type { VirtualFile } from "./virtual-file/index.cjs";
4
4
  export declare const LOCALIZABLE_FIELDS: readonly ["description", "proposedName"];
5
5
  export declare const LocalizationFileStruct: import("@metamask/superstruct").Struct<{
6
+ locale: string;
6
7
  messages: Record<string, {
7
8
  message: string;
8
9
  description?: string | undefined;
9
10
  }>;
10
- locale: string;
11
11
  }, {
12
12
  locale: import("@metamask/superstruct").Struct<string, null>;
13
13
  messages: import("@metamask/superstruct").Struct<Record<string, {
@@ -34,11 +34,11 @@ export declare function getValidatedLocalizationFiles(localizationFiles: Virtual
34
34
  * found.
35
35
  */
36
36
  export declare function getLocalizationFile(locale: string, localizationFiles: LocalizationFile[]): {
37
+ locale: string;
37
38
  messages: Record<string, {
38
39
  message: string;
39
40
  description?: string | undefined;
40
41
  }>;
41
- locale: string;
42
42
  } | undefined;
43
43
  export declare const TRANSLATION_REGEX: RegExp;
44
44
  /**
@@ -63,20 +63,20 @@ export declare function translate(value: string, file: LocalizationFile | undefi
63
63
  * @returns The localized Snap manifest.
64
64
  */
65
65
  export declare function getLocalizedSnapManifest(snapManifest: SnapManifest, locale: string, localizationFiles: LocalizationFile[]): {
66
+ description: string;
66
67
  source: {
68
+ shasum: string;
67
69
  location: {
68
70
  npm: {
69
- registry: "https://registry.npmjs.org" | "https://registry.npmjs.org/";
70
71
  filePath: string;
71
72
  packageName: string;
73
+ registry: "https://registry.npmjs.org" | "https://registry.npmjs.org/";
72
74
  iconPath?: string | undefined;
73
75
  };
74
76
  };
75
- shasum: string;
76
77
  files?: string[] | undefined;
77
78
  locales?: string[] | undefined;
78
79
  };
79
- description: string;
80
80
  version: import("@metamask/utils").SemVerVersion;
81
81
  proposedName: string;
82
82
  initialPermissions: Partial<{
@@ -3,11 +3,11 @@ import type { SnapManifest } from "./manifest/index.mjs";
3
3
  import type { VirtualFile } from "./virtual-file/index.mjs";
4
4
  export declare const LOCALIZABLE_FIELDS: readonly ["description", "proposedName"];
5
5
  export declare const LocalizationFileStruct: import("@metamask/superstruct").Struct<{
6
+ locale: string;
6
7
  messages: Record<string, {
7
8
  message: string;
8
9
  description?: string | undefined;
9
10
  }>;
10
- locale: string;
11
11
  }, {
12
12
  locale: import("@metamask/superstruct").Struct<string, null>;
13
13
  messages: import("@metamask/superstruct").Struct<Record<string, {
@@ -34,11 +34,11 @@ export declare function getValidatedLocalizationFiles(localizationFiles: Virtual
34
34
  * found.
35
35
  */
36
36
  export declare function getLocalizationFile(locale: string, localizationFiles: LocalizationFile[]): {
37
+ locale: string;
37
38
  messages: Record<string, {
38
39
  message: string;
39
40
  description?: string | undefined;
40
41
  }>;
41
- locale: string;
42
42
  } | undefined;
43
43
  export declare const TRANSLATION_REGEX: RegExp;
44
44
  /**
@@ -63,20 +63,20 @@ export declare function translate(value: string, file: LocalizationFile | undefi
63
63
  * @returns The localized Snap manifest.
64
64
  */
65
65
  export declare function getLocalizedSnapManifest(snapManifest: SnapManifest, locale: string, localizationFiles: LocalizationFile[]): {
66
+ description: string;
66
67
  source: {
68
+ shasum: string;
67
69
  location: {
68
70
  npm: {
69
- registry: "https://registry.npmjs.org" | "https://registry.npmjs.org/";
70
71
  filePath: string;
71
72
  packageName: string;
73
+ registry: "https://registry.npmjs.org" | "https://registry.npmjs.org/";
72
74
  iconPath?: string | undefined;
73
75
  };
74
76
  };
75
- shasum: string;
76
77
  files?: string[] | undefined;
77
78
  locales?: string[] | undefined;
78
79
  };
79
- description: string;
80
80
  version: import("@metamask/utils").SemVerVersion;
81
81
  proposedName: string;
82
82
  initialPermissions: Partial<{
@@ -10,22 +10,22 @@ export declare const bip32entropy: <Type extends {
10
10
  }, Schema>(struct: Struct<Type, Schema>) => Struct<Type, Schema>;
11
11
  export declare const CurveStruct: Describe<SupportedCurve>;
12
12
  export declare const Bip32EntropyStruct: Struct<{
13
- curve: "ed25519" | "ed25519Bip32" | "secp256k1";
14
13
  path: string[];
14
+ curve: "secp256k1" | "ed25519" | "ed25519Bip32";
15
15
  }, {
16
16
  path: Struct<string[], Struct<string, null>>;
17
- curve: Describe<"ed25519" | "ed25519Bip32" | "secp256k1">;
17
+ curve: Describe<"secp256k1" | "ed25519" | "ed25519Bip32">;
18
18
  }>;
19
19
  export type Bip32Entropy = Infer<typeof Bip32EntropyStruct>;
20
20
  export declare const SnapGetBip32EntropyPermissionsStruct: Struct<{
21
- curve: "ed25519" | "ed25519Bip32" | "secp256k1";
22
21
  path: string[];
22
+ curve: "secp256k1" | "ed25519" | "ed25519Bip32";
23
23
  }[], Struct<{
24
- curve: "ed25519" | "ed25519Bip32" | "secp256k1";
25
24
  path: string[];
25
+ curve: "secp256k1" | "ed25519" | "ed25519Bip32";
26
26
  }, {
27
27
  path: Struct<string[], Struct<string, null>>;
28
- curve: Describe<"ed25519" | "ed25519Bip32" | "secp256k1">;
28
+ curve: Describe<"secp256k1" | "ed25519" | "ed25519Bip32">;
29
29
  }>>;
30
30
  export declare const SemVerRangeStruct: Struct<string, null>;
31
31
  export declare const SnapIdsStruct: Struct<Record<string, {
@@ -60,20 +60,20 @@ export declare const SnapAuxilaryFilesStruct: Struct<string[], Struct<string, nu
60
60
  export declare const InitialConnectionsStruct: Struct<Record<string & URL, {}>, null>;
61
61
  export type InitialConnections = Infer<typeof InitialConnectionsStruct>;
62
62
  export declare const SnapManifestStruct: Struct<{
63
+ description: string;
63
64
  source: {
65
+ shasum: string;
64
66
  location: {
65
67
  npm: {
66
- registry: "https://registry.npmjs.org" | "https://registry.npmjs.org/";
67
68
  filePath: string;
68
69
  packageName: string;
70
+ registry: "https://registry.npmjs.org" | "https://registry.npmjs.org/";
69
71
  iconPath?: string | undefined;
70
72
  };
71
73
  };
72
- shasum: string;
73
74
  files?: string[] | undefined;
74
75
  locales?: string[] | undefined;
75
76
  };
76
- description: string;
77
77
  version: import("@metamask/utils").SemVerVersion;
78
78
  proposedName: string;
79
79
  initialPermissions: Partial<{
@@ -147,31 +147,31 @@ export declare const SnapManifestStruct: Struct<{
147
147
  url: Struct<string, null>;
148
148
  }>;
149
149
  source: Struct<{
150
+ shasum: string;
150
151
  location: {
151
152
  npm: {
152
- registry: "https://registry.npmjs.org" | "https://registry.npmjs.org/";
153
153
  filePath: string;
154
154
  packageName: string;
155
+ registry: "https://registry.npmjs.org" | "https://registry.npmjs.org/";
155
156
  iconPath?: string | undefined;
156
157
  };
157
158
  };
158
- shasum: string;
159
159
  files?: string[] | undefined;
160
160
  locales?: string[] | undefined;
161
161
  }, {
162
162
  shasum: Struct<string, null>;
163
163
  location: Struct<{
164
164
  npm: {
165
- registry: "https://registry.npmjs.org" | "https://registry.npmjs.org/";
166
165
  filePath: string;
167
166
  packageName: string;
167
+ registry: "https://registry.npmjs.org" | "https://registry.npmjs.org/";
168
168
  iconPath?: string | undefined;
169
169
  };
170
170
  }, {
171
171
  npm: Struct<{
172
- registry: "https://registry.npmjs.org" | "https://registry.npmjs.org/";
173
172
  filePath: string;
174
173
  packageName: string;
174
+ registry: "https://registry.npmjs.org" | "https://registry.npmjs.org/";
175
175
  iconPath?: string | undefined;
176
176
  }, {
177
177
  filePath: Struct<string, null>;