@metamask/snaps-rpc-methods 4.1.0 → 6.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 (144) hide show
  1. package/CHANGELOG.md +24 -2
  2. package/dist/cjs/endowments/caveats/generic.js +40 -0
  3. package/dist/cjs/endowments/caveats/generic.js.map +1 -0
  4. package/dist/cjs/endowments/caveats/index.js +21 -0
  5. package/dist/cjs/endowments/caveats/index.js.map +1 -0
  6. package/dist/cjs/endowments/caveats/requestTime.js +99 -0
  7. package/dist/cjs/endowments/caveats/requestTime.js.map +1 -0
  8. package/dist/cjs/endowments/cronjob.js +100 -0
  9. package/dist/cjs/endowments/cronjob.js.map +1 -0
  10. package/dist/cjs/endowments/enum.js +26 -0
  11. package/dist/cjs/endowments/enum.js.map +1 -0
  12. package/dist/cjs/endowments/ethereum-provider.js +43 -0
  13. package/dist/cjs/endowments/ethereum-provider.js.map +1 -0
  14. package/dist/cjs/endowments/home-page.js +37 -0
  15. package/dist/cjs/endowments/home-page.js.map +1 -0
  16. package/dist/cjs/endowments/index.js +121 -0
  17. package/dist/cjs/endowments/index.js.map +1 -0
  18. package/dist/cjs/endowments/keyring.js +104 -0
  19. package/dist/cjs/endowments/keyring.js.map +1 -0
  20. package/dist/cjs/endowments/lifecycle-hooks.js +37 -0
  21. package/dist/cjs/endowments/lifecycle-hooks.js.map +1 -0
  22. package/dist/cjs/endowments/name-lookup.js +148 -0
  23. package/dist/cjs/endowments/name-lookup.js.map +1 -0
  24. package/dist/cjs/endowments/network-access.js +44 -0
  25. package/dist/cjs/endowments/network-access.js.map +1 -0
  26. package/dist/cjs/endowments/rpc.js +103 -0
  27. package/dist/cjs/endowments/rpc.js.map +1 -0
  28. package/dist/cjs/endowments/signature-insight.js +110 -0
  29. package/dist/cjs/endowments/signature-insight.js.map +1 -0
  30. package/dist/cjs/endowments/transaction-insight.js +111 -0
  31. package/dist/cjs/endowments/transaction-insight.js.map +1 -0
  32. package/dist/cjs/endowments/web-assembly.js +42 -0
  33. package/dist/cjs/endowments/web-assembly.js.map +1 -0
  34. package/dist/cjs/index.js +3 -1
  35. package/dist/cjs/index.js.map +1 -1
  36. package/dist/cjs/permissions.js +62 -0
  37. package/dist/cjs/permissions.js.map +1 -0
  38. package/dist/cjs/permitted/createInterface.js +68 -0
  39. package/dist/cjs/permitted/createInterface.js.map +1 -0
  40. package/dist/cjs/permitted/getClientStatus.js +40 -0
  41. package/dist/cjs/permitted/getClientStatus.js.map +1 -0
  42. package/dist/cjs/permitted/getFile.js +1 -1
  43. package/dist/cjs/permitted/getFile.js.map +1 -1
  44. package/dist/cjs/permitted/getInterfaceState.js +67 -0
  45. package/dist/cjs/permitted/getInterfaceState.js.map +1 -0
  46. package/dist/cjs/permitted/handlers.js +9 -1
  47. package/dist/cjs/permitted/handlers.js.map +1 -1
  48. package/dist/cjs/permitted/index.js.map +1 -1
  49. package/dist/cjs/permitted/invokeKeyring.js +2 -3
  50. package/dist/cjs/permitted/invokeKeyring.js.map +1 -1
  51. package/dist/cjs/permitted/updateInterface.js +70 -0
  52. package/dist/cjs/permitted/updateInterface.js.map +1 -0
  53. package/dist/cjs/restricted/dialog.js +51 -24
  54. package/dist/cjs/restricted/dialog.js.map +1 -1
  55. package/dist/cjs/restricted/index.js +3 -0
  56. package/dist/cjs/restricted/index.js.map +1 -1
  57. package/dist/cjs/restricted/manageState.js +4 -13
  58. package/dist/cjs/restricted/manageState.js.map +1 -1
  59. package/dist/esm/endowments/caveats/generic.js +40 -0
  60. package/dist/esm/endowments/caveats/generic.js.map +1 -0
  61. package/dist/esm/endowments/caveats/index.js +4 -0
  62. package/dist/esm/endowments/caveats/index.js.map +1 -0
  63. package/dist/esm/endowments/caveats/requestTime.js +93 -0
  64. package/dist/esm/endowments/caveats/requestTime.js.map +1 -0
  65. package/dist/esm/endowments/cronjob.js +99 -0
  66. package/dist/esm/endowments/cronjob.js.map +1 -0
  67. package/dist/esm/endowments/enum.js +16 -0
  68. package/dist/esm/endowments/enum.js.map +1 -0
  69. package/dist/esm/endowments/ethereum-provider.js +33 -0
  70. package/dist/esm/endowments/ethereum-provider.js.map +1 -0
  71. package/dist/esm/endowments/home-page.js +27 -0
  72. package/dist/esm/endowments/home-page.js.map +1 -0
  73. package/dist/esm/endowments/index.js +68 -0
  74. package/dist/esm/endowments/index.js.map +1 -0
  75. package/dist/esm/endowments/keyring.js +95 -0
  76. package/dist/esm/endowments/keyring.js.map +1 -0
  77. package/dist/esm/endowments/lifecycle-hooks.js +27 -0
  78. package/dist/esm/endowments/lifecycle-hooks.js.map +1 -0
  79. package/dist/esm/endowments/name-lookup.js +146 -0
  80. package/dist/esm/endowments/name-lookup.js.map +1 -0
  81. package/dist/esm/endowments/network-access.js +34 -0
  82. package/dist/esm/endowments/network-access.js.map +1 -0
  83. package/dist/esm/endowments/rpc.js +92 -0
  84. package/dist/esm/endowments/rpc.js.map +1 -0
  85. package/dist/esm/endowments/signature-insight.js +103 -0
  86. package/dist/esm/endowments/signature-insight.js.map +1 -0
  87. package/dist/esm/endowments/transaction-insight.js +104 -0
  88. package/dist/esm/endowments/transaction-insight.js.map +1 -0
  89. package/dist/esm/endowments/web-assembly.js +32 -0
  90. package/dist/esm/endowments/web-assembly.js.map +1 -0
  91. package/dist/esm/index.js +3 -1
  92. package/dist/esm/index.js.map +1 -1
  93. package/dist/esm/permissions.js +51 -0
  94. package/dist/esm/permissions.js.map +1 -0
  95. package/dist/esm/permitted/createInterface.js +58 -0
  96. package/dist/esm/permitted/createInterface.js.map +1 -0
  97. package/dist/esm/permitted/getClientStatus.js +32 -0
  98. package/dist/esm/permitted/getClientStatus.js.map +1 -0
  99. package/dist/esm/permitted/getFile.js +1 -1
  100. package/dist/esm/permitted/getFile.js.map +1 -1
  101. package/dist/esm/permitted/getInterfaceState.js +57 -0
  102. package/dist/esm/permitted/getInterfaceState.js.map +1 -0
  103. package/dist/esm/permitted/handlers.js +9 -1
  104. package/dist/esm/permitted/handlers.js.map +1 -1
  105. package/dist/esm/permitted/index.js.map +1 -1
  106. package/dist/esm/permitted/invokeKeyring.js +2 -3
  107. package/dist/esm/permitted/invokeKeyring.js.map +1 -1
  108. package/dist/esm/permitted/updateInterface.js +60 -0
  109. package/dist/esm/permitted/updateInterface.js.map +1 -0
  110. package/dist/esm/restricted/dialog.js +55 -29
  111. package/dist/esm/restricted/dialog.js.map +1 -1
  112. package/dist/esm/restricted/index.js +1 -0
  113. package/dist/esm/restricted/index.js.map +1 -1
  114. package/dist/esm/restricted/manageState.js +1 -1
  115. package/dist/esm/restricted/manageState.js.map +1 -1
  116. package/dist/types/endowments/caveats/generic.d.ts +19 -0
  117. package/dist/types/endowments/caveats/index.d.ts +2 -0
  118. package/dist/types/endowments/caveats/requestTime.d.ts +29 -0
  119. package/dist/types/endowments/cronjob.d.ts +51 -0
  120. package/dist/types/endowments/enum.d.ts +13 -0
  121. package/dist/types/endowments/ethereum-provider.d.ts +14 -0
  122. package/dist/types/endowments/home-page.d.ts +15 -0
  123. package/dist/types/endowments/index.d.ts +131 -0
  124. package/dist/types/endowments/keyring.d.ts +39 -0
  125. package/dist/types/endowments/lifecycle-hooks.d.ts +15 -0
  126. package/dist/types/endowments/name-lookup.d.ts +49 -0
  127. package/dist/types/endowments/network-access.d.ts +14 -0
  128. package/dist/types/endowments/rpc.d.ts +38 -0
  129. package/dist/types/endowments/signature-insight.d.ts +39 -0
  130. package/dist/types/endowments/transaction-insight.d.ts +39 -0
  131. package/dist/types/endowments/web-assembly.d.ts +14 -0
  132. package/dist/types/index.d.ts +4 -2
  133. package/dist/types/permissions.d.ts +16 -0
  134. package/dist/types/permitted/createInterface.d.ts +150 -0
  135. package/dist/types/permitted/getClientStatus.d.ts +13 -0
  136. package/dist/types/permitted/getInterfaceState.d.ts +18 -0
  137. package/dist/types/permitted/handlers.d.ts +5 -1
  138. package/dist/types/permitted/index.d.ts +5 -1
  139. package/dist/types/permitted/invokeKeyring.d.ts +3 -3
  140. package/dist/types/permitted/updateInterface.d.ts +152 -0
  141. package/dist/types/restricted/dialog.d.ts +776 -14
  142. package/dist/types/restricted/index.d.ts +1 -0
  143. package/dist/types/restricted/manageState.d.ts +18 -0
  144. package/package.json +8 -8
@@ -0,0 +1,34 @@
1
+ import { PermissionType, SubjectType } from '@metamask/permission-controller';
2
+ import { SnapEndowments } from './enum';
3
+ const permissionName = SnapEndowments.NetworkAccess;
4
+ /**
5
+ * `endowment:network-access` returns the name of global browser API(s) that
6
+ * enable network access. This is intended to populate the endowments of the
7
+ * SES Compartment in which a Snap executes.
8
+ *
9
+ * @param _builderOptions - Optional specification builder options.
10
+ * @returns The specification for the network endowment.
11
+ */ const specificationBuilder = (_builderOptions)=>{
12
+ return {
13
+ permissionType: PermissionType.Endowment,
14
+ targetName: permissionName,
15
+ allowedCaveats: null,
16
+ endowmentGetter: (_getterOptions)=>{
17
+ return [
18
+ 'fetch',
19
+ 'Request',
20
+ 'Headers',
21
+ 'Response'
22
+ ];
23
+ },
24
+ subjectTypes: [
25
+ SubjectType.Snap
26
+ ]
27
+ };
28
+ };
29
+ export const networkAccessEndowmentBuilder = Object.freeze({
30
+ targetName: permissionName,
31
+ specificationBuilder
32
+ });
33
+
34
+ //# sourceMappingURL=network-access.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/endowments/network-access.ts"],"sourcesContent":["import type {\n EndowmentGetterParams,\n PermissionSpecificationBuilder,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\n\nimport { SnapEndowments } from './enum';\n\nconst permissionName = SnapEndowments.NetworkAccess;\n\ntype NetworkAccessEndowmentSpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.Endowment;\n targetName: typeof permissionName;\n endowmentGetter: (\n _options?: any,\n ) => ['fetch', 'Request', 'Headers', 'Response'];\n allowedCaveats: null;\n}>;\n\n/**\n * `endowment:network-access` returns the name of global browser API(s) that\n * enable network access. This is intended to populate the endowments of the\n * SES Compartment in which a Snap executes.\n *\n * @param _builderOptions - Optional specification builder options.\n * @returns The specification for the network endowment.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.Endowment,\n any,\n NetworkAccessEndowmentSpecification\n> = (_builderOptions?: any) => {\n return {\n permissionType: PermissionType.Endowment,\n targetName: permissionName,\n allowedCaveats: null,\n endowmentGetter: (_getterOptions?: EndowmentGetterParams) => {\n return ['fetch', 'Request', 'Headers', 'Response'];\n },\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nexport const networkAccessEndowmentBuilder = Object.freeze({\n targetName: permissionName,\n specificationBuilder,\n} as const);\n"],"names":["PermissionType","SubjectType","SnapEndowments","permissionName","NetworkAccess","specificationBuilder","_builderOptions","permissionType","Endowment","targetName","allowedCaveats","endowmentGetter","_getterOptions","subjectTypes","Snap","networkAccessEndowmentBuilder","Object","freeze"],"mappings":"AAKA,SAASA,cAAc,EAAEC,WAAW,QAAQ,kCAAkC;AAE9E,SAASC,cAAc,QAAQ,SAAS;AAExC,MAAMC,iBAAiBD,eAAeE,aAAa;AAWnD;;;;;;;CAOC,GACD,MAAMC,uBAIF,CAACC;IACH,OAAO;QACLC,gBAAgBP,eAAeQ,SAAS;QACxCC,YAAYN;QACZO,gBAAgB;QAChBC,iBAAiB,CAACC;YAChB,OAAO;gBAAC;gBAAS;gBAAW;gBAAW;aAAW;QACpD;QACAC,cAAc;YAACZ,YAAYa,IAAI;SAAC;IAClC;AACF;AAEA,OAAO,MAAMC,gCAAgCC,OAAOC,MAAM,CAAC;IACzDR,YAAYN;IACZE;AACF,GAAY"}
@@ -0,0 +1,92 @@
1
+ import { PermissionType, SubjectType } from '@metamask/permission-controller';
2
+ import { rpcErrors } from '@metamask/rpc-errors';
3
+ import { assertIsRpcOrigins, SnapCaveatType } from '@metamask/snaps-utils';
4
+ import { hasProperty, isPlainObject, assert } from '@metamask/utils';
5
+ import { createGenericPermissionValidator } from './caveats';
6
+ import { SnapEndowments } from './enum';
7
+ const targetName = SnapEndowments.Rpc;
8
+ /**
9
+ * The specification builder for the JSON-RPC endowment permission.
10
+ *
11
+ * @param _builderOptions - Optional specification builder options.
12
+ * @returns The specification for the JSON-RPC endowment permission.
13
+ */ const specificationBuilder = (_builderOptions)=>{
14
+ return {
15
+ permissionType: PermissionType.Endowment,
16
+ targetName,
17
+ allowedCaveats: [
18
+ SnapCaveatType.RpcOrigin,
19
+ SnapCaveatType.MaxRequestTime
20
+ ],
21
+ endowmentGetter: (_getterOptions)=>undefined,
22
+ validator: createGenericPermissionValidator([
23
+ {
24
+ type: SnapCaveatType.RpcOrigin
25
+ },
26
+ {
27
+ type: SnapCaveatType.MaxRequestTime,
28
+ optional: true
29
+ }
30
+ ]),
31
+ subjectTypes: [
32
+ SubjectType.Snap
33
+ ]
34
+ };
35
+ };
36
+ export const rpcEndowmentBuilder = Object.freeze({
37
+ targetName,
38
+ specificationBuilder
39
+ });
40
+ /**
41
+ * Validate the value of a caveat. This does not validate the type of the
42
+ * caveat itself, only the value of the caveat.
43
+ *
44
+ * @param caveat - The caveat to validate.
45
+ * @throws If the caveat value is invalid.
46
+ */ function validateCaveatOrigins(caveat) {
47
+ if (!hasProperty(caveat, 'value') || !isPlainObject(caveat.value)) {
48
+ throw rpcErrors.invalidParams({
49
+ message: 'Invalid JSON-RPC origins: Expected a plain object.'
50
+ });
51
+ }
52
+ const { value } = caveat;
53
+ assertIsRpcOrigins(value, rpcErrors.invalidParams);
54
+ }
55
+ /**
56
+ * Map a raw value from the `initialPermissions` to a caveat specification.
57
+ * Note that this function does not do any validation, that's handled by the
58
+ * PermissionsController when the permission is requested.
59
+ *
60
+ * @param value - The raw value from the `initialPermissions`.
61
+ * @returns The caveat specification.
62
+ */ export function getRpcCaveatMapper(value) {
63
+ return {
64
+ caveats: [
65
+ {
66
+ type: SnapCaveatType.RpcOrigin,
67
+ value
68
+ }
69
+ ]
70
+ };
71
+ }
72
+ /**
73
+ * Getter function to get the {@link RpcOrigins} caveat value from a permission.
74
+ *
75
+ * @param permission - The permission to get the caveat value from.
76
+ * @returns The caveat value.
77
+ * @throws If the permission does not have a valid {@link RpcOrigins} caveat.
78
+ */ export function getRpcCaveatOrigins(permission) {
79
+ const caveats = permission?.caveats?.filter((caveat)=>caveat.type === SnapCaveatType.RpcOrigin);
80
+ assert(caveats);
81
+ assert(caveats.length === 1);
82
+ const caveat = caveats[0];
83
+ return caveat.value;
84
+ }
85
+ export const rpcCaveatSpecifications = {
86
+ [SnapCaveatType.RpcOrigin]: Object.freeze({
87
+ type: SnapCaveatType.RpcOrigin,
88
+ validator: (caveat)=>validateCaveatOrigins(caveat)
89
+ })
90
+ };
91
+
92
+ //# sourceMappingURL=rpc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/endowments/rpc.ts"],"sourcesContent":["import type {\n Caveat,\n CaveatSpecificationConstraint,\n EndowmentGetterParams,\n PermissionConstraint,\n PermissionSpecificationBuilder,\n PermissionValidatorConstraint,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type { RpcOrigins } from '@metamask/snaps-utils';\nimport { assertIsRpcOrigins, SnapCaveatType } from '@metamask/snaps-utils';\nimport type { Json, NonEmptyArray } from '@metamask/utils';\nimport { hasProperty, isPlainObject, assert } from '@metamask/utils';\n\nimport { createGenericPermissionValidator } from './caveats';\nimport { SnapEndowments } from './enum';\n\nconst targetName = SnapEndowments.Rpc;\n\ntype RpcSpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.Endowment;\n targetName: typeof targetName;\n endowmentGetter: (_options?: any) => undefined;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n validator: PermissionValidatorConstraint;\n subjectTypes: readonly SubjectType[];\n}>;\n\ntype RpcSpecificationBuilderOptions = {\n // Empty for now.\n};\n\n/**\n * The specification builder for the JSON-RPC endowment permission.\n *\n * @param _builderOptions - Optional specification builder options.\n * @returns The specification for the JSON-RPC endowment permission.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.Endowment,\n RpcSpecificationBuilderOptions,\n RpcSpecification\n> = (_builderOptions?: any): RpcSpecification => {\n return {\n permissionType: PermissionType.Endowment,\n targetName,\n allowedCaveats: [SnapCaveatType.RpcOrigin, SnapCaveatType.MaxRequestTime],\n endowmentGetter: (_getterOptions?: EndowmentGetterParams) => undefined,\n validator: createGenericPermissionValidator([\n { type: SnapCaveatType.RpcOrigin },\n { type: SnapCaveatType.MaxRequestTime, optional: true },\n ]),\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nexport const rpcEndowmentBuilder = Object.freeze({\n targetName,\n specificationBuilder,\n} as const);\n\n/**\n * Validate the value of a caveat. This does not validate the type of the\n * caveat itself, only the value of the caveat.\n *\n * @param caveat - The caveat to validate.\n * @throws If the caveat value is invalid.\n */\nfunction validateCaveatOrigins(caveat: Caveat<string, any>) {\n if (!hasProperty(caveat, 'value') || !isPlainObject(caveat.value)) {\n throw rpcErrors.invalidParams({\n message: 'Invalid JSON-RPC origins: Expected a plain object.',\n });\n }\n\n const { value } = caveat;\n assertIsRpcOrigins(value, rpcErrors.invalidParams);\n}\n\n/**\n * Map a raw value from the `initialPermissions` to a caveat specification.\n * Note that this function does not do any validation, that's handled by the\n * PermissionsController when the permission is requested.\n *\n * @param value - The raw value from the `initialPermissions`.\n * @returns The caveat specification.\n */\nexport function getRpcCaveatMapper(\n value: Json,\n): Pick<PermissionConstraint, 'caveats'> {\n return {\n caveats: [\n {\n type: SnapCaveatType.RpcOrigin,\n value,\n },\n ],\n };\n}\n\n/**\n * Getter function to get the {@link RpcOrigins} caveat value from a permission.\n *\n * @param permission - The permission to get the caveat value from.\n * @returns The caveat value.\n * @throws If the permission does not have a valid {@link RpcOrigins} caveat.\n */\nexport function getRpcCaveatOrigins(\n permission?: PermissionConstraint,\n): RpcOrigins | null {\n const caveats = permission?.caveats?.filter(\n (caveat) => caveat.type === SnapCaveatType.RpcOrigin,\n );\n assert(caveats);\n assert(caveats.length === 1);\n\n const caveat = caveats[0] as Caveat<string, RpcOrigins>;\n return caveat.value;\n}\n\nexport const rpcCaveatSpecifications: Record<\n SnapCaveatType.RpcOrigin,\n CaveatSpecificationConstraint\n> = {\n [SnapCaveatType.RpcOrigin]: Object.freeze({\n type: SnapCaveatType.RpcOrigin,\n validator: (caveat: Caveat<string, any>) => validateCaveatOrigins(caveat),\n }),\n};\n"],"names":["PermissionType","SubjectType","rpcErrors","assertIsRpcOrigins","SnapCaveatType","hasProperty","isPlainObject","assert","createGenericPermissionValidator","SnapEndowments","targetName","Rpc","specificationBuilder","_builderOptions","permissionType","Endowment","allowedCaveats","RpcOrigin","MaxRequestTime","endowmentGetter","_getterOptions","undefined","validator","type","optional","subjectTypes","Snap","rpcEndowmentBuilder","Object","freeze","validateCaveatOrigins","caveat","value","invalidParams","message","getRpcCaveatMapper","caveats","getRpcCaveatOrigins","permission","filter","length","rpcCaveatSpecifications"],"mappings":"AASA,SAASA,cAAc,EAAEC,WAAW,QAAQ,kCAAkC;AAC9E,SAASC,SAAS,QAAQ,uBAAuB;AAEjD,SAASC,kBAAkB,EAAEC,cAAc,QAAQ,wBAAwB;AAE3E,SAASC,WAAW,EAAEC,aAAa,EAAEC,MAAM,QAAQ,kBAAkB;AAErE,SAASC,gCAAgC,QAAQ,YAAY;AAC7D,SAASC,cAAc,QAAQ,SAAS;AAExC,MAAMC,aAAaD,eAAeE,GAAG;AAerC;;;;;CAKC,GACD,MAAMC,uBAIF,CAACC;IACH,OAAO;QACLC,gBAAgBd,eAAee,SAAS;QACxCL;QACAM,gBAAgB;YAACZ,eAAea,SAAS;YAAEb,eAAec,cAAc;SAAC;QACzEC,iBAAiB,CAACC,iBAA2CC;QAC7DC,WAAWd,iCAAiC;YAC1C;gBAAEe,MAAMnB,eAAea,SAAS;YAAC;YACjC;gBAAEM,MAAMnB,eAAec,cAAc;gBAAEM,UAAU;YAAK;SACvD;QACDC,cAAc;YAACxB,YAAYyB,IAAI;SAAC;IAClC;AACF;AAEA,OAAO,MAAMC,sBAAsBC,OAAOC,MAAM,CAAC;IAC/CnB;IACAE;AACF,GAAY;AAEZ;;;;;;CAMC,GACD,SAASkB,sBAAsBC,MAA2B;IACxD,IAAI,CAAC1B,YAAY0B,QAAQ,YAAY,CAACzB,cAAcyB,OAAOC,KAAK,GAAG;QACjE,MAAM9B,UAAU+B,aAAa,CAAC;YAC5BC,SAAS;QACX;IACF;IAEA,MAAM,EAAEF,KAAK,EAAE,GAAGD;IAClB5B,mBAAmB6B,OAAO9B,UAAU+B,aAAa;AACnD;AAEA;;;;;;;CAOC,GACD,OAAO,SAASE,mBACdH,KAAW;IAEX,OAAO;QACLI,SAAS;YACP;gBACEb,MAAMnB,eAAea,SAAS;gBAC9Be;YACF;SACD;IACH;AACF;AAEA;;;;;;CAMC,GACD,OAAO,SAASK,oBACdC,UAAiC;IAEjC,MAAMF,UAAUE,YAAYF,SAASG,OACnC,CAACR,SAAWA,OAAOR,IAAI,KAAKnB,eAAea,SAAS;IAEtDV,OAAO6B;IACP7B,OAAO6B,QAAQI,MAAM,KAAK;IAE1B,MAAMT,SAASK,OAAO,CAAC,EAAE;IACzB,OAAOL,OAAOC,KAAK;AACrB;AAEA,OAAO,MAAMS,0BAGT;IACF,CAACrC,eAAea,SAAS,CAAC,EAAEW,OAAOC,MAAM,CAAC;QACxCN,MAAMnB,eAAea,SAAS;QAC9BK,WAAW,CAACS,SAAgCD,sBAAsBC;IACpE;AACF,EAAE"}
@@ -0,0 +1,103 @@
1
+ import { PermissionType, SubjectType } from '@metamask/permission-controller';
2
+ import { rpcErrors } from '@metamask/rpc-errors';
3
+ import { SnapCaveatType } from '@metamask/snaps-utils';
4
+ import { assert, hasProperty, isObject, isPlainObject } from '@metamask/utils';
5
+ import { createGenericPermissionValidator } from './caveats';
6
+ import { SnapEndowments } from './enum';
7
+ const permissionName = SnapEndowments.SignatureInsight;
8
+ /**
9
+ * `endowment:signature-insight` returns nothing; it is intended to be used as a flag
10
+ * by the extension to detect whether the snap has the capability to show information on the signature confirmation screen.
11
+ *
12
+ * @param _builderOptions - Optional specification builder options.
13
+ * @returns The specification for the signature-insight endowment.
14
+ */ const specificationBuilder = (_builderOptions)=>{
15
+ return {
16
+ permissionType: PermissionType.Endowment,
17
+ targetName: permissionName,
18
+ allowedCaveats: [
19
+ SnapCaveatType.SignatureOrigin
20
+ ],
21
+ endowmentGetter: (_getterOptions)=>undefined,
22
+ validator: createGenericPermissionValidator([
23
+ {
24
+ type: SnapCaveatType.SignatureOrigin,
25
+ optional: true
26
+ },
27
+ {
28
+ type: SnapCaveatType.MaxRequestTime,
29
+ optional: true
30
+ }
31
+ ]),
32
+ subjectTypes: [
33
+ SubjectType.Snap
34
+ ]
35
+ };
36
+ };
37
+ export const signatureInsightEndowmentBuilder = Object.freeze({
38
+ targetName: permissionName,
39
+ specificationBuilder
40
+ });
41
+ /**
42
+ * Validates the type of the caveat value.
43
+ *
44
+ * @param caveat - The caveat to validate.
45
+ * @throws If the caveat value is invalid.
46
+ */ function validateCaveat(caveat) {
47
+ if (!hasProperty(caveat, 'value') || !isPlainObject(caveat)) {
48
+ throw rpcErrors.invalidParams({
49
+ message: 'Expected a plain object.'
50
+ });
51
+ }
52
+ const { value } = caveat;
53
+ assert(typeof value === 'boolean', 'Expected caveat value to have type "boolean"');
54
+ }
55
+ /**
56
+ * Map a raw value from the `initialPermissions` to a caveat specification.
57
+ * Note that this function does not do any validation, that's handled by the
58
+ * PermissionController when the permission is requested.
59
+ *
60
+ * @param value - The raw value from the `initialPermissions`.
61
+ * @returns The caveat specification.
62
+ */ export function getSignatureInsightCaveatMapper(value) {
63
+ if (!value || !isObject(value) || isObject(value) && Object.keys(value).length === 0) {
64
+ return {
65
+ caveats: null
66
+ };
67
+ }
68
+ return {
69
+ caveats: [
70
+ {
71
+ type: SnapCaveatType.SignatureOrigin,
72
+ value: hasProperty(value, 'allowSignatureOrigin') && value.allowSignatureOrigin
73
+ }
74
+ ]
75
+ };
76
+ }
77
+ /**
78
+ * Getter function to get the signature origin caveat from a permission.
79
+ *
80
+ * This does basic validation of the caveat, but does not validate the type or
81
+ * value of the namespaces object itself, as this is handled by the
82
+ * `PermissionsController` when the permission is requested.
83
+ *
84
+ * @param permission - The permission to get the signature origin caveat from.
85
+ * @returns The signature origin, or `null` if the permission does not have a
86
+ * signature origin caveat.
87
+ */ export function getSignatureOriginCaveat(permission) {
88
+ if (!permission?.caveats) {
89
+ return null;
90
+ }
91
+ assert(permission.caveats.length === 1);
92
+ assert(permission.caveats[0].type === SnapCaveatType.SignatureOrigin);
93
+ const caveat = permission.caveats[0];
94
+ return caveat.value ?? null;
95
+ }
96
+ export const signatureInsightCaveatSpecifications = {
97
+ [SnapCaveatType.SignatureOrigin]: Object.freeze({
98
+ type: SnapCaveatType.SignatureOrigin,
99
+ validator: (caveat)=>validateCaveat(caveat)
100
+ })
101
+ };
102
+
103
+ //# sourceMappingURL=signature-insight.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/endowments/signature-insight.ts"],"sourcesContent":["import type {\n PermissionSpecificationBuilder,\n EndowmentGetterParams,\n ValidPermissionSpecification,\n PermissionValidatorConstraint,\n PermissionConstraint,\n CaveatSpecificationConstraint,\n Caveat,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport { SnapCaveatType } from '@metamask/snaps-utils';\nimport type { Json, NonEmptyArray } from '@metamask/utils';\nimport { assert, hasProperty, isObject, isPlainObject } from '@metamask/utils';\n\nimport { createGenericPermissionValidator } from './caveats';\nimport { SnapEndowments } from './enum';\n\nconst permissionName = SnapEndowments.SignatureInsight;\n\ntype SignatureInsightEndowmentSpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.Endowment;\n targetName: typeof permissionName;\n endowmentGetter: (_options?: EndowmentGetterParams) => undefined;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n validator: PermissionValidatorConstraint;\n}>;\n\n/**\n * `endowment:signature-insight` returns nothing; it is intended to be used as a flag\n * by the extension to detect whether the snap has the capability to show information on the signature confirmation screen.\n *\n * @param _builderOptions - Optional specification builder options.\n * @returns The specification for the signature-insight endowment.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.Endowment,\n any,\n SignatureInsightEndowmentSpecification\n> = (_builderOptions?: unknown) => {\n return {\n permissionType: PermissionType.Endowment,\n targetName: permissionName,\n allowedCaveats: [SnapCaveatType.SignatureOrigin],\n endowmentGetter: (_getterOptions?: EndowmentGetterParams) => undefined,\n validator: createGenericPermissionValidator([\n { type: SnapCaveatType.SignatureOrigin, optional: true },\n { type: SnapCaveatType.MaxRequestTime, optional: true },\n ]),\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nexport const signatureInsightEndowmentBuilder = Object.freeze({\n targetName: permissionName,\n specificationBuilder,\n} as const);\n\n/**\n * Validates the type of the caveat value.\n *\n * @param caveat - The caveat to validate.\n * @throws If the caveat value is invalid.\n */\nfunction validateCaveat(caveat: Caveat<string, any>): void {\n if (!hasProperty(caveat, 'value') || !isPlainObject(caveat)) {\n throw rpcErrors.invalidParams({\n message: 'Expected a plain object.',\n });\n }\n\n const { value } = caveat;\n\n assert(\n typeof value === 'boolean',\n 'Expected caveat value to have type \"boolean\"',\n );\n}\n\n/**\n * Map a raw value from the `initialPermissions` to a caveat specification.\n * Note that this function does not do any validation, that's handled by the\n * PermissionController when the permission is requested.\n *\n * @param value - The raw value from the `initialPermissions`.\n * @returns The caveat specification.\n */\nexport function getSignatureInsightCaveatMapper(\n value: Json,\n): Pick<PermissionConstraint, 'caveats'> {\n if (\n !value ||\n !isObject(value) ||\n (isObject(value) && Object.keys(value).length === 0)\n ) {\n return { caveats: null };\n }\n return {\n caveats: [\n {\n type: SnapCaveatType.SignatureOrigin,\n value:\n hasProperty(value, 'allowSignatureOrigin') &&\n (value.allowSignatureOrigin as boolean),\n },\n ],\n };\n}\n\n/**\n * Getter function to get the signature origin caveat from a permission.\n *\n * This does basic validation of the caveat, but does not validate the type or\n * value of the namespaces object itself, as this is handled by the\n * `PermissionsController` when the permission is requested.\n *\n * @param permission - The permission to get the signature origin caveat from.\n * @returns The signature origin, or `null` if the permission does not have a\n * signature origin caveat.\n */\nexport function getSignatureOriginCaveat(\n permission?: PermissionConstraint,\n): boolean | null {\n if (!permission?.caveats) {\n return null;\n }\n\n assert(permission.caveats.length === 1);\n assert(permission.caveats[0].type === SnapCaveatType.SignatureOrigin);\n\n const caveat = permission.caveats[0] as Caveat<string, boolean>;\n\n return caveat.value ?? null;\n}\n\nexport const signatureInsightCaveatSpecifications: Record<\n SnapCaveatType.SignatureOrigin,\n CaveatSpecificationConstraint\n> = {\n [SnapCaveatType.SignatureOrigin]: Object.freeze({\n type: SnapCaveatType.SignatureOrigin,\n validator: (caveat: Caveat<string, any>) => validateCaveat(caveat),\n }),\n};\n"],"names":["PermissionType","SubjectType","rpcErrors","SnapCaveatType","assert","hasProperty","isObject","isPlainObject","createGenericPermissionValidator","SnapEndowments","permissionName","SignatureInsight","specificationBuilder","_builderOptions","permissionType","Endowment","targetName","allowedCaveats","SignatureOrigin","endowmentGetter","_getterOptions","undefined","validator","type","optional","MaxRequestTime","subjectTypes","Snap","signatureInsightEndowmentBuilder","Object","freeze","validateCaveat","caveat","invalidParams","message","value","getSignatureInsightCaveatMapper","keys","length","caveats","allowSignatureOrigin","getSignatureOriginCaveat","permission","signatureInsightCaveatSpecifications"],"mappings":"AASA,SAASA,cAAc,EAAEC,WAAW,QAAQ,kCAAkC;AAC9E,SAASC,SAAS,QAAQ,uBAAuB;AACjD,SAASC,cAAc,QAAQ,wBAAwB;AAEvD,SAASC,MAAM,EAAEC,WAAW,EAAEC,QAAQ,EAAEC,aAAa,QAAQ,kBAAkB;AAE/E,SAASC,gCAAgC,QAAQ,YAAY;AAC7D,SAASC,cAAc,QAAQ,SAAS;AAExC,MAAMC,iBAAiBD,eAAeE,gBAAgB;AAUtD;;;;;;CAMC,GACD,MAAMC,uBAIF,CAACC;IACH,OAAO;QACLC,gBAAgBd,eAAee,SAAS;QACxCC,YAAYN;QACZO,gBAAgB;YAACd,eAAee,eAAe;SAAC;QAChDC,iBAAiB,CAACC,iBAA2CC;QAC7DC,WAAWd,iCAAiC;YAC1C;gBAAEe,MAAMpB,eAAee,eAAe;gBAAEM,UAAU;YAAK;YACvD;gBAAED,MAAMpB,eAAesB,cAAc;gBAAED,UAAU;YAAK;SACvD;QACDE,cAAc;YAACzB,YAAY0B,IAAI;SAAC;IAClC;AACF;AAEA,OAAO,MAAMC,mCAAmCC,OAAOC,MAAM,CAAC;IAC5Dd,YAAYN;IACZE;AACF,GAAY;AAEZ;;;;;CAKC,GACD,SAASmB,eAAeC,MAA2B;IACjD,IAAI,CAAC3B,YAAY2B,QAAQ,YAAY,CAACzB,cAAcyB,SAAS;QAC3D,MAAM9B,UAAU+B,aAAa,CAAC;YAC5BC,SAAS;QACX;IACF;IAEA,MAAM,EAAEC,KAAK,EAAE,GAAGH;IAElB5B,OACE,OAAO+B,UAAU,WACjB;AAEJ;AAEA;;;;;;;CAOC,GACD,OAAO,SAASC,gCACdD,KAAW;IAEX,IACE,CAACA,SACD,CAAC7B,SAAS6B,UACT7B,SAAS6B,UAAUN,OAAOQ,IAAI,CAACF,OAAOG,MAAM,KAAK,GAClD;QACA,OAAO;YAAEC,SAAS;QAAK;IACzB;IACA,OAAO;QACLA,SAAS;YACP;gBACEhB,MAAMpB,eAAee,eAAe;gBACpCiB,OACE9B,YAAY8B,OAAO,2BAClBA,MAAMK,oBAAoB;YAC/B;SACD;IACH;AACF;AAEA;;;;;;;;;;CAUC,GACD,OAAO,SAASC,yBACdC,UAAiC;IAEjC,IAAI,CAACA,YAAYH,SAAS;QACxB,OAAO;IACT;IAEAnC,OAAOsC,WAAWH,OAAO,CAACD,MAAM,KAAK;IACrClC,OAAOsC,WAAWH,OAAO,CAAC,EAAE,CAAChB,IAAI,KAAKpB,eAAee,eAAe;IAEpE,MAAMc,SAASU,WAAWH,OAAO,CAAC,EAAE;IAEpC,OAAOP,OAAOG,KAAK,IAAI;AACzB;AAEA,OAAO,MAAMQ,uCAGT;IACF,CAACxC,eAAee,eAAe,CAAC,EAAEW,OAAOC,MAAM,CAAC;QAC9CP,MAAMpB,eAAee,eAAe;QACpCI,WAAW,CAACU,SAAgCD,eAAeC;IAC7D;AACF,EAAE"}
@@ -0,0 +1,104 @@
1
+ import { PermissionType, SubjectType } from '@metamask/permission-controller';
2
+ import { rpcErrors } from '@metamask/rpc-errors';
3
+ import { SnapCaveatType } from '@metamask/snaps-utils';
4
+ import { assert, hasProperty, isObject, isPlainObject } from '@metamask/utils';
5
+ import { createGenericPermissionValidator } from './caveats';
6
+ import { SnapEndowments } from './enum';
7
+ const permissionName = SnapEndowments.TransactionInsight;
8
+ /**
9
+ * `endowment:transaction-insight` returns nothing; it is intended to be used as a flag
10
+ * by the extension to detect whether the snap has the capability to show information on the transaction confirmation screen.
11
+ *
12
+ * @param _builderOptions - Optional specification builder options.
13
+ * @returns The specification for the transaction-insight endowment.
14
+ */ const specificationBuilder = (_builderOptions)=>{
15
+ return {
16
+ permissionType: PermissionType.Endowment,
17
+ targetName: permissionName,
18
+ allowedCaveats: [
19
+ SnapCaveatType.TransactionOrigin,
20
+ SnapCaveatType.MaxRequestTime
21
+ ],
22
+ endowmentGetter: (_getterOptions)=>undefined,
23
+ validator: createGenericPermissionValidator([
24
+ {
25
+ type: SnapCaveatType.TransactionOrigin,
26
+ optional: true
27
+ },
28
+ {
29
+ type: SnapCaveatType.MaxRequestTime,
30
+ optional: true
31
+ }
32
+ ]),
33
+ subjectTypes: [
34
+ SubjectType.Snap
35
+ ]
36
+ };
37
+ };
38
+ export const transactionInsightEndowmentBuilder = Object.freeze({
39
+ targetName: permissionName,
40
+ specificationBuilder
41
+ });
42
+ /**
43
+ * Validates the type of the caveat value.
44
+ *
45
+ * @param caveat - The caveat to validate.
46
+ * @throws If the caveat value is invalid.
47
+ */ function validateCaveat(caveat) {
48
+ if (!hasProperty(caveat, 'value') || !isPlainObject(caveat)) {
49
+ throw rpcErrors.invalidParams({
50
+ message: 'Expected a plain object.'
51
+ });
52
+ }
53
+ const { value } = caveat;
54
+ assert(typeof value === 'boolean', 'Expected caveat value to have type "boolean"');
55
+ }
56
+ /**
57
+ * Map a raw value from the `initialPermissions` to a caveat specification.
58
+ * Note that this function does not do any validation, that's handled by the
59
+ * PermissionsController when the permission is requested.
60
+ *
61
+ * @param value - The raw value from the `initialPermissions`.
62
+ * @returns The caveat specification.
63
+ */ export function getTransactionInsightCaveatMapper(value) {
64
+ if (!value || !isObject(value) || isObject(value) && Object.keys(value).length === 0) {
65
+ return {
66
+ caveats: null
67
+ };
68
+ }
69
+ return {
70
+ caveats: [
71
+ {
72
+ type: SnapCaveatType.TransactionOrigin,
73
+ value: hasProperty(value, 'allowTransactionOrigin') && value.allowTransactionOrigin
74
+ }
75
+ ]
76
+ };
77
+ }
78
+ /**
79
+ * Getter function to get the transaction origin caveat from a permission.
80
+ *
81
+ * This does basic validation of the caveat, but does not validate the type or
82
+ * value of the namespaces object itself, as this is handled by the
83
+ * `PermissionsController` when the permission is requested.
84
+ *
85
+ * @param permission - The permission to get the transaction origin caveat from.
86
+ * @returns The transaction origin, or `null` if the permission does not have a
87
+ * transaction origin caveat.
88
+ */ export function getTransactionOriginCaveat(permission) {
89
+ if (!permission?.caveats) {
90
+ return null;
91
+ }
92
+ assert(permission.caveats.length === 1);
93
+ assert(permission.caveats[0].type === SnapCaveatType.TransactionOrigin);
94
+ const caveat = permission.caveats[0];
95
+ return caveat.value ?? null;
96
+ }
97
+ export const transactionInsightCaveatSpecifications = {
98
+ [SnapCaveatType.TransactionOrigin]: Object.freeze({
99
+ type: SnapCaveatType.TransactionOrigin,
100
+ validator: (caveat)=>validateCaveat(caveat)
101
+ })
102
+ };
103
+
104
+ //# sourceMappingURL=transaction-insight.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/endowments/transaction-insight.ts"],"sourcesContent":["import type {\n PermissionSpecificationBuilder,\n EndowmentGetterParams,\n ValidPermissionSpecification,\n PermissionValidatorConstraint,\n PermissionConstraint,\n CaveatSpecificationConstraint,\n Caveat,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport { SnapCaveatType } from '@metamask/snaps-utils';\nimport type { Json, NonEmptyArray } from '@metamask/utils';\nimport { assert, hasProperty, isObject, isPlainObject } from '@metamask/utils';\n\nimport { createGenericPermissionValidator } from './caveats';\nimport { SnapEndowments } from './enum';\n\nconst permissionName = SnapEndowments.TransactionInsight;\n\ntype TransactionInsightEndowmentSpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.Endowment;\n targetName: typeof permissionName;\n endowmentGetter: (_options?: EndowmentGetterParams) => undefined;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n validator: PermissionValidatorConstraint;\n}>;\n\n/**\n * `endowment:transaction-insight` returns nothing; it is intended to be used as a flag\n * by the extension to detect whether the snap has the capability to show information on the transaction confirmation screen.\n *\n * @param _builderOptions - Optional specification builder options.\n * @returns The specification for the transaction-insight endowment.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.Endowment,\n any,\n TransactionInsightEndowmentSpecification\n> = (_builderOptions?: unknown) => {\n return {\n permissionType: PermissionType.Endowment,\n targetName: permissionName,\n allowedCaveats: [\n SnapCaveatType.TransactionOrigin,\n SnapCaveatType.MaxRequestTime,\n ],\n endowmentGetter: (_getterOptions?: EndowmentGetterParams) => undefined,\n validator: createGenericPermissionValidator([\n { type: SnapCaveatType.TransactionOrigin, optional: true },\n { type: SnapCaveatType.MaxRequestTime, optional: true },\n ]),\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nexport const transactionInsightEndowmentBuilder = Object.freeze({\n targetName: permissionName,\n specificationBuilder,\n} as const);\n\n/**\n * Validates the type of the caveat value.\n *\n * @param caveat - The caveat to validate.\n * @throws If the caveat value is invalid.\n */\nfunction validateCaveat(caveat: Caveat<string, any>): void {\n if (!hasProperty(caveat, 'value') || !isPlainObject(caveat)) {\n throw rpcErrors.invalidParams({\n message: 'Expected a plain object.',\n });\n }\n\n const { value } = caveat;\n\n assert(\n typeof value === 'boolean',\n 'Expected caveat value to have type \"boolean\"',\n );\n}\n\n/**\n * Map a raw value from the `initialPermissions` to a caveat specification.\n * Note that this function does not do any validation, that's handled by the\n * PermissionsController when the permission is requested.\n *\n * @param value - The raw value from the `initialPermissions`.\n * @returns The caveat specification.\n */\nexport function getTransactionInsightCaveatMapper(\n value: Json,\n): Pick<PermissionConstraint, 'caveats'> {\n if (\n !value ||\n !isObject(value) ||\n (isObject(value) && Object.keys(value).length === 0)\n ) {\n return { caveats: null };\n }\n return {\n caveats: [\n {\n type: SnapCaveatType.TransactionOrigin,\n value:\n hasProperty(value, 'allowTransactionOrigin') &&\n (value.allowTransactionOrigin as boolean),\n },\n ],\n };\n}\n\n/**\n * Getter function to get the transaction origin caveat from a permission.\n *\n * This does basic validation of the caveat, but does not validate the type or\n * value of the namespaces object itself, as this is handled by the\n * `PermissionsController` when the permission is requested.\n *\n * @param permission - The permission to get the transaction origin caveat from.\n * @returns The transaction origin, or `null` if the permission does not have a\n * transaction origin caveat.\n */\nexport function getTransactionOriginCaveat(\n permission?: PermissionConstraint,\n): boolean | null {\n if (!permission?.caveats) {\n return null;\n }\n\n assert(permission.caveats.length === 1);\n assert(permission.caveats[0].type === SnapCaveatType.TransactionOrigin);\n\n const caveat = permission.caveats[0] as Caveat<string, boolean>;\n\n return caveat.value ?? null;\n}\n\nexport const transactionInsightCaveatSpecifications: Record<\n SnapCaveatType.TransactionOrigin,\n CaveatSpecificationConstraint\n> = {\n [SnapCaveatType.TransactionOrigin]: Object.freeze({\n type: SnapCaveatType.TransactionOrigin,\n validator: (caveat: Caveat<string, any>) => validateCaveat(caveat),\n }),\n};\n"],"names":["PermissionType","SubjectType","rpcErrors","SnapCaveatType","assert","hasProperty","isObject","isPlainObject","createGenericPermissionValidator","SnapEndowments","permissionName","TransactionInsight","specificationBuilder","_builderOptions","permissionType","Endowment","targetName","allowedCaveats","TransactionOrigin","MaxRequestTime","endowmentGetter","_getterOptions","undefined","validator","type","optional","subjectTypes","Snap","transactionInsightEndowmentBuilder","Object","freeze","validateCaveat","caveat","invalidParams","message","value","getTransactionInsightCaveatMapper","keys","length","caveats","allowTransactionOrigin","getTransactionOriginCaveat","permission","transactionInsightCaveatSpecifications"],"mappings":"AASA,SAASA,cAAc,EAAEC,WAAW,QAAQ,kCAAkC;AAC9E,SAASC,SAAS,QAAQ,uBAAuB;AACjD,SAASC,cAAc,QAAQ,wBAAwB;AAEvD,SAASC,MAAM,EAAEC,WAAW,EAAEC,QAAQ,EAAEC,aAAa,QAAQ,kBAAkB;AAE/E,SAASC,gCAAgC,QAAQ,YAAY;AAC7D,SAASC,cAAc,QAAQ,SAAS;AAExC,MAAMC,iBAAiBD,eAAeE,kBAAkB;AAUxD;;;;;;CAMC,GACD,MAAMC,uBAIF,CAACC;IACH,OAAO;QACLC,gBAAgBd,eAAee,SAAS;QACxCC,YAAYN;QACZO,gBAAgB;YACdd,eAAee,iBAAiB;YAChCf,eAAegB,cAAc;SAC9B;QACDC,iBAAiB,CAACC,iBAA2CC;QAC7DC,WAAWf,iCAAiC;YAC1C;gBAAEgB,MAAMrB,eAAee,iBAAiB;gBAAEO,UAAU;YAAK;YACzD;gBAAED,MAAMrB,eAAegB,cAAc;gBAAEM,UAAU;YAAK;SACvD;QACDC,cAAc;YAACzB,YAAY0B,IAAI;SAAC;IAClC;AACF;AAEA,OAAO,MAAMC,qCAAqCC,OAAOC,MAAM,CAAC;IAC9Dd,YAAYN;IACZE;AACF,GAAY;AAEZ;;;;;CAKC,GACD,SAASmB,eAAeC,MAA2B;IACjD,IAAI,CAAC3B,YAAY2B,QAAQ,YAAY,CAACzB,cAAcyB,SAAS;QAC3D,MAAM9B,UAAU+B,aAAa,CAAC;YAC5BC,SAAS;QACX;IACF;IAEA,MAAM,EAAEC,KAAK,EAAE,GAAGH;IAElB5B,OACE,OAAO+B,UAAU,WACjB;AAEJ;AAEA;;;;;;;CAOC,GACD,OAAO,SAASC,kCACdD,KAAW;IAEX,IACE,CAACA,SACD,CAAC7B,SAAS6B,UACT7B,SAAS6B,UAAUN,OAAOQ,IAAI,CAACF,OAAOG,MAAM,KAAK,GAClD;QACA,OAAO;YAAEC,SAAS;QAAK;IACzB;IACA,OAAO;QACLA,SAAS;YACP;gBACEf,MAAMrB,eAAee,iBAAiB;gBACtCiB,OACE9B,YAAY8B,OAAO,6BAClBA,MAAMK,sBAAsB;YACjC;SACD;IACH;AACF;AAEA;;;;;;;;;;CAUC,GACD,OAAO,SAASC,2BACdC,UAAiC;IAEjC,IAAI,CAACA,YAAYH,SAAS;QACxB,OAAO;IACT;IAEAnC,OAAOsC,WAAWH,OAAO,CAACD,MAAM,KAAK;IACrClC,OAAOsC,WAAWH,OAAO,CAAC,EAAE,CAACf,IAAI,KAAKrB,eAAee,iBAAiB;IAEtE,MAAMc,SAASU,WAAWH,OAAO,CAAC,EAAE;IAEpC,OAAOP,OAAOG,KAAK,IAAI;AACzB;AAEA,OAAO,MAAMQ,yCAGT;IACF,CAACxC,eAAee,iBAAiB,CAAC,EAAEW,OAAOC,MAAM,CAAC;QAChDN,MAAMrB,eAAee,iBAAiB;QACtCK,WAAW,CAACS,SAAgCD,eAAeC;IAC7D;AACF,EAAE"}
@@ -0,0 +1,32 @@
1
+ import { PermissionType, SubjectType } from '@metamask/permission-controller';
2
+ import { SnapEndowments } from './enum';
3
+ const permissionName = SnapEndowments.WebAssemblyAccess;
4
+ /**
5
+ * `endowment:webassembly` returns the name of global browser API(s) that
6
+ * enable access to the WebAssembly API.
7
+ * This is intended to populate the endowments of the SES Compartment
8
+ * in which a Snap executes.
9
+ *
10
+ * @param _builderOptions - Optional specification builder options.
11
+ * @returns The specification for the WebAssembly endowment.
12
+ */ const specificationBuilder = (_builderOptions)=>{
13
+ return {
14
+ permissionType: PermissionType.Endowment,
15
+ targetName: permissionName,
16
+ allowedCaveats: null,
17
+ endowmentGetter: (_getterOptions)=>{
18
+ return [
19
+ 'WebAssembly'
20
+ ];
21
+ },
22
+ subjectTypes: [
23
+ SubjectType.Snap
24
+ ]
25
+ };
26
+ };
27
+ export const webAssemblyEndowmentBuilder = Object.freeze({
28
+ targetName: permissionName,
29
+ specificationBuilder
30
+ });
31
+
32
+ //# sourceMappingURL=web-assembly.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/endowments/web-assembly.ts"],"sourcesContent":["import type {\n EndowmentGetterParams,\n PermissionSpecificationBuilder,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\n\nimport { SnapEndowments } from './enum';\n\nconst permissionName = SnapEndowments.WebAssemblyAccess;\n\ntype WebAssemblyEndowmentSpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.Endowment;\n targetName: typeof permissionName;\n endowmentGetter: (_options?: any) => ['WebAssembly'];\n allowedCaveats: null;\n}>;\n\n/**\n * `endowment:webassembly` returns the name of global browser API(s) that\n * enable access to the WebAssembly API.\n * This is intended to populate the endowments of the SES Compartment\n * in which a Snap executes.\n *\n * @param _builderOptions - Optional specification builder options.\n * @returns The specification for the WebAssembly endowment.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.Endowment,\n any,\n WebAssemblyEndowmentSpecification\n> = (_builderOptions?: any) => {\n return {\n permissionType: PermissionType.Endowment,\n targetName: permissionName,\n allowedCaveats: null,\n endowmentGetter: (_getterOptions?: EndowmentGetterParams) => {\n return ['WebAssembly'];\n },\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nexport const webAssemblyEndowmentBuilder = Object.freeze({\n targetName: permissionName,\n specificationBuilder,\n} as const);\n"],"names":["PermissionType","SubjectType","SnapEndowments","permissionName","WebAssemblyAccess","specificationBuilder","_builderOptions","permissionType","Endowment","targetName","allowedCaveats","endowmentGetter","_getterOptions","subjectTypes","Snap","webAssemblyEndowmentBuilder","Object","freeze"],"mappings":"AAKA,SAASA,cAAc,EAAEC,WAAW,QAAQ,kCAAkC;AAE9E,SAASC,cAAc,QAAQ,SAAS;AAExC,MAAMC,iBAAiBD,eAAeE,iBAAiB;AASvD;;;;;;;;CAQC,GACD,MAAMC,uBAIF,CAACC;IACH,OAAO;QACLC,gBAAgBP,eAAeQ,SAAS;QACxCC,YAAYN;QACZO,gBAAgB;QAChBC,iBAAiB,CAACC;YAChB,OAAO;gBAAC;aAAc;QACxB;QACAC,cAAc;YAACZ,YAAYa,IAAI;SAAC;IAClC;AACF;AAEA,OAAO,MAAMC,8BAA8BC,OAAOC,MAAM,CAAC;IACvDR,YAAYN;IACZE;AACF,GAAY"}
package/dist/esm/index.js CHANGED
@@ -1,6 +1,8 @@
1
1
  export { handlers as permittedMethods, createSnapsMethodMiddleware } from './permitted';
2
- export * from './restricted';
3
2
  export { SnapCaveatType } from '@metamask/snaps-utils';
4
3
  export { selectHooks } from './utils';
4
+ export * from './endowments';
5
+ export * from './permissions';
6
+ export * from './restricted';
5
7
 
6
8
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export type { PermittedRpcMethodHooks } from './permitted';\nexport {\n handlers as permittedMethods,\n createSnapsMethodMiddleware,\n} from './permitted';\nexport * from './restricted';\nexport { SnapCaveatType } from '@metamask/snaps-utils';\nexport { selectHooks } from './utils';\n"],"names":["handlers","permittedMethods","createSnapsMethodMiddleware","SnapCaveatType","selectHooks"],"mappings":"AACA,SACEA,YAAYC,gBAAgB,EAC5BC,2BAA2B,QACtB,cAAc;AACrB,cAAc,eAAe;AAC7B,SAASC,cAAc,QAAQ,wBAAwB;AACvD,SAASC,WAAW,QAAQ,UAAU"}
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export {\n handlers as permittedMethods,\n createSnapsMethodMiddleware,\n} from './permitted';\nexport type { PermittedRpcMethodHooks } from './permitted';\nexport { SnapCaveatType } from '@metamask/snaps-utils';\nexport { selectHooks } from './utils';\nexport * from './endowments';\nexport * from './permissions';\nexport * from './restricted';\n"],"names":["handlers","permittedMethods","createSnapsMethodMiddleware","SnapCaveatType","selectHooks"],"mappings":"AAAA,SACEA,YAAYC,gBAAgB,EAC5BC,2BAA2B,QACtB,cAAc;AAErB,SAASC,cAAc,QAAQ,wBAAwB;AACvD,SAASC,WAAW,QAAQ,UAAU;AACtC,cAAc,eAAe;AAC7B,cAAc,gBAAgB;AAC9B,cAAc,eAAe"}
@@ -0,0 +1,51 @@
1
+ import { hasProperty } from '@metamask/utils';
2
+ import { endowmentCaveatMappers, endowmentPermissionBuilders } from './endowments';
3
+ import { caveatMappers, restrictedMethodPermissionBuilders } from './restricted';
4
+ import { selectHooks } from './utils';
5
+ /**
6
+ * Map initial permissions as defined in a Snap manifest to something that can
7
+ * be processed by the PermissionsController. Each caveat mapping function
8
+ * should return a valid permission caveat value.
9
+ *
10
+ * This function does not validate the caveat values, since that is done by
11
+ * the PermissionsController itself, upon requesting the permissions.
12
+ *
13
+ * @param initialPermissions - The initial permissions to process.
14
+ * @returns The processed permissions.
15
+ */ export function processSnapPermissions(initialPermissions) {
16
+ return Object.fromEntries(Object.entries(initialPermissions).map(([initialPermission, value])=>{
17
+ if (hasProperty(caveatMappers, initialPermission)) {
18
+ return [
19
+ initialPermission,
20
+ caveatMappers[initialPermission](value)
21
+ ];
22
+ } else if (hasProperty(endowmentCaveatMappers, initialPermission)) {
23
+ return [
24
+ initialPermission,
25
+ endowmentCaveatMappers[initialPermission](value)
26
+ ];
27
+ }
28
+ // If we have no mapping, this may be a non-snap permission, return as-is
29
+ return [
30
+ initialPermission,
31
+ value
32
+ ];
33
+ }));
34
+ }
35
+ export const buildSnapEndowmentSpecifications = (excludedEndowments)=>Object.values(endowmentPermissionBuilders).reduce((allSpecifications, { targetName, specificationBuilder })=>{
36
+ if (!excludedEndowments.includes(targetName)) {
37
+ allSpecifications[targetName] = specificationBuilder({});
38
+ }
39
+ return allSpecifications;
40
+ }, {});
41
+ export const buildSnapRestrictedMethodSpecifications = (excludedPermissions, hooks)=>Object.values(restrictedMethodPermissionBuilders).reduce((specifications, { targetName, specificationBuilder, methodHooks })=>{
42
+ if (!excludedPermissions.includes(targetName)) {
43
+ specifications[targetName] = specificationBuilder({
44
+ // @ts-expect-error The selectHooks type is wonky
45
+ methodHooks: selectHooks(hooks, methodHooks)
46
+ });
47
+ }
48
+ return specifications;
49
+ }, {});
50
+
51
+ //# sourceMappingURL=permissions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/permissions.ts"],"sourcesContent":["import type {\n PermissionConstraint,\n PermissionSpecificationConstraint,\n} from '@metamask/permission-controller';\nimport type { SnapPermissions } from '@metamask/snaps-utils';\nimport { hasProperty } from '@metamask/utils';\n\nimport {\n endowmentCaveatMappers,\n endowmentPermissionBuilders,\n} from './endowments';\nimport {\n caveatMappers,\n restrictedMethodPermissionBuilders,\n} from './restricted';\nimport { selectHooks } from './utils';\n\n/**\n * Map initial permissions as defined in a Snap manifest to something that can\n * be processed by the PermissionsController. Each caveat mapping function\n * should return a valid permission caveat value.\n *\n * This function does not validate the caveat values, since that is done by\n * the PermissionsController itself, upon requesting the permissions.\n *\n * @param initialPermissions - The initial permissions to process.\n * @returns The processed permissions.\n */\nexport function processSnapPermissions(\n initialPermissions: SnapPermissions,\n): Record<string, Pick<PermissionConstraint, 'caveats'>> {\n return Object.fromEntries(\n Object.entries(initialPermissions).map(([initialPermission, value]) => {\n if (hasProperty(caveatMappers, initialPermission)) {\n return [initialPermission, caveatMappers[initialPermission](value)];\n } else if (hasProperty(endowmentCaveatMappers, initialPermission)) {\n return [\n initialPermission,\n endowmentCaveatMappers[initialPermission](value),\n ];\n }\n\n // If we have no mapping, this may be a non-snap permission, return as-is\n return [\n initialPermission,\n value as Pick<PermissionConstraint, 'caveats'>,\n ];\n }),\n );\n}\n\nexport const buildSnapEndowmentSpecifications = (\n excludedEndowments: string[],\n) =>\n Object.values(endowmentPermissionBuilders).reduce<\n Record<string, PermissionSpecificationConstraint>\n >((allSpecifications, { targetName, specificationBuilder }) => {\n if (!excludedEndowments.includes(targetName)) {\n allSpecifications[targetName] = specificationBuilder({});\n }\n return allSpecifications;\n }, {});\n\nexport const buildSnapRestrictedMethodSpecifications = (\n excludedPermissions: string[],\n hooks: Record<string, unknown>,\n) =>\n Object.values(restrictedMethodPermissionBuilders).reduce<\n Record<string, PermissionSpecificationConstraint>\n >((specifications, { targetName, specificationBuilder, methodHooks }) => {\n if (!excludedPermissions.includes(targetName)) {\n specifications[targetName] = specificationBuilder({\n // @ts-expect-error The selectHooks type is wonky\n methodHooks: selectHooks<typeof hooks, keyof typeof methodHooks>(\n hooks,\n methodHooks,\n ) as Pick<typeof hooks, keyof typeof methodHooks>,\n });\n }\n return specifications;\n }, {});\n"],"names":["hasProperty","endowmentCaveatMappers","endowmentPermissionBuilders","caveatMappers","restrictedMethodPermissionBuilders","selectHooks","processSnapPermissions","initialPermissions","Object","fromEntries","entries","map","initialPermission","value","buildSnapEndowmentSpecifications","excludedEndowments","values","reduce","allSpecifications","targetName","specificationBuilder","includes","buildSnapRestrictedMethodSpecifications","excludedPermissions","hooks","specifications","methodHooks"],"mappings":"AAKA,SAASA,WAAW,QAAQ,kBAAkB;AAE9C,SACEC,sBAAsB,EACtBC,2BAA2B,QACtB,eAAe;AACtB,SACEC,aAAa,EACbC,kCAAkC,QAC7B,eAAe;AACtB,SAASC,WAAW,QAAQ,UAAU;AAEtC;;;;;;;;;;CAUC,GACD,OAAO,SAASC,uBACdC,kBAAmC;IAEnC,OAAOC,OAAOC,WAAW,CACvBD,OAAOE,OAAO,CAACH,oBAAoBI,GAAG,CAAC,CAAC,CAACC,mBAAmBC,MAAM;QAChE,IAAIb,YAAYG,eAAeS,oBAAoB;YACjD,OAAO;gBAACA;gBAAmBT,aAAa,CAACS,kBAAkB,CAACC;aAAO;QACrE,OAAO,IAAIb,YAAYC,wBAAwBW,oBAAoB;YACjE,OAAO;gBACLA;gBACAX,sBAAsB,CAACW,kBAAkB,CAACC;aAC3C;QACH;QAEA,yEAAyE;QACzE,OAAO;YACLD;YACAC;SACD;IACH;AAEJ;AAEA,OAAO,MAAMC,mCAAmC,CAC9CC,qBAEAP,OAAOQ,MAAM,CAACd,6BAA6Be,MAAM,CAE/C,CAACC,mBAAmB,EAAEC,UAAU,EAAEC,oBAAoB,EAAE;QACxD,IAAI,CAACL,mBAAmBM,QAAQ,CAACF,aAAa;YAC5CD,iBAAiB,CAACC,WAAW,GAAGC,qBAAqB,CAAC;QACxD;QACA,OAAOF;IACT,GAAG,CAAC,GAAG;AAET,OAAO,MAAMI,0CAA0C,CACrDC,qBACAC,QAEAhB,OAAOQ,MAAM,CAACZ,oCAAoCa,MAAM,CAEtD,CAACQ,gBAAgB,EAAEN,UAAU,EAAEC,oBAAoB,EAAEM,WAAW,EAAE;QAClE,IAAI,CAACH,oBAAoBF,QAAQ,CAACF,aAAa;YAC7CM,cAAc,CAACN,WAAW,GAAGC,qBAAqB;gBAChD,iDAAiD;gBACjDM,aAAarB,YACXmB,OACAE;YAEJ;QACF;QACA,OAAOD;IACT,GAAG,CAAC,GAAG"}
@@ -0,0 +1,58 @@
1
+ import { rpcErrors } from '@metamask/rpc-errors';
2
+ import { ComponentStruct } from '@metamask/snaps-sdk';
3
+ import { StructError, create, object } from 'superstruct';
4
+ const hookNames = {
5
+ createInterface: true
6
+ };
7
+ export const createInterfaceHandler = {
8
+ methodNames: [
9
+ 'snap_createInterface'
10
+ ],
11
+ implementation: getCreateInterfaceImplementation,
12
+ hookNames
13
+ };
14
+ const CreateInterfaceParametersStruct = object({
15
+ ui: ComponentStruct
16
+ });
17
+ /**
18
+ * The `snap_createInterface` method implementation.
19
+ *
20
+ * @param req - The JSON-RPC request object.
21
+ * @param res - The JSON-RPC response object.
22
+ * @param _next - The `json-rpc-engine` "next" callback. Not used by this
23
+ * function.
24
+ * @param end - The `json-rpc-engine` "end" callback.
25
+ * @param hooks - The RPC method hooks.
26
+ * @param hooks.createInterface - The function to create the interface.
27
+ * @returns Nothing.
28
+ */ async function getCreateInterfaceImplementation(req, res, _next, end, { createInterface }) {
29
+ const { params } = req;
30
+ try {
31
+ const validatedParams = getValidatedParams(params);
32
+ const { ui } = validatedParams;
33
+ res.result = await createInterface(ui);
34
+ } catch (error) {
35
+ return end(error);
36
+ }
37
+ return end();
38
+ }
39
+ /**
40
+ * Validate the createInterface method `params` and returns them cast to the correct
41
+ * type. Throws if validation fails.
42
+ *
43
+ * @param params - The unvalidated params object from the method request.
44
+ * @returns The validated createInterface method parameter object.
45
+ */ function getValidatedParams(params) {
46
+ try {
47
+ return create(params, CreateInterfaceParametersStruct);
48
+ } catch (error) {
49
+ if (error instanceof StructError) {
50
+ throw rpcErrors.invalidParams({
51
+ message: `Invalid params: ${error.message}.`
52
+ });
53
+ }
54
+ /* istanbul ignore next */ throw rpcErrors.internal();
55
+ }
56
+ }
57
+
58
+ //# sourceMappingURL=createInterface.js.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 Component,\n CreateInterfaceParams,\n CreateInterfaceResult,\n JsonRpcRequest,\n} from '@metamask/snaps-sdk';\nimport { ComponentStruct } 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: Component) => 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: ComponentStruct,\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"],"names":["rpcErrors","ComponentStruct","StructError","create","object","hookNames","createInterface","createInterfaceHandler","methodNames","implementation","getCreateInterfaceImplementation","CreateInterfaceParametersStruct","ui","req","res","_next","end","params","validatedParams","getValidatedParams","result","error","invalidParams","message","internal"],"mappings":"AAEA,SAASA,SAAS,QAAQ,uBAAuB;AAOjD,SAASC,eAAe,QAAQ,sBAAsB;AAGtD,SAASC,WAAW,EAAEC,MAAM,EAAEC,MAAM,QAAQ,cAAc;AAI1D,MAAMC,YAA2D;IAC/DC,iBAAiB;AACnB;AAUA,OAAO,MAAMC,yBAIT;IACFC,aAAa;QAAC;KAAuB;IACrCC,gBAAgBC;IAChBL;AACF,EAAE;AAEF,MAAMM,kCAAkCP,OAAO;IAC7CQ,IAAIX;AACN;AAOA;;;;;;;;;;;CAWC,GACD,eAAeS,iCACbG,GAA8C,EAC9CC,GAAkD,EAClDC,KAAc,EACdC,GAA6B,EAC7B,EAAEV,eAAe,EAA8B;IAE/C,MAAM,EAAEW,MAAM,EAAE,GAAGJ;IAEnB,IAAI;QACF,MAAMK,kBAAkBC,mBAAmBF;QAE3C,MAAM,EAAEL,EAAE,EAAE,GAAGM;QAEfJ,IAAIM,MAAM,GAAG,MAAMd,gBAAgBM;IACrC,EAAE,OAAOS,OAAO;QACd,OAAOL,IAAIK;IACb;IAEA,OAAOL;AACT;AAEA;;;;;;CAMC,GACD,SAASG,mBAAmBF,MAAe;IACzC,IAAI;QACF,OAAOd,OAAOc,QAAQN;IACxB,EAAE,OAAOU,OAAO;QACd,IAAIA,iBAAiBnB,aAAa;YAChC,MAAMF,UAAUsB,aAAa,CAAC;gBAC5BC,SAAS,CAAC,gBAAgB,EAAEF,MAAME,OAAO,CAAC,CAAC,CAAC;YAC9C;QACF;QACA,wBAAwB,GACxB,MAAMvB,UAAUwB,QAAQ;IAC1B;AACF"}
@@ -0,0 +1,32 @@
1
+ const hookNames = {
2
+ getIsLocked: true
3
+ };
4
+ /**
5
+ * `snap_getClientStatus` returns useful information about the client running the snap.
6
+ */ export const getClientStatusHandler = {
7
+ methodNames: [
8
+ 'snap_getClientStatus'
9
+ ],
10
+ implementation: getClientStatusImplementation,
11
+ hookNames
12
+ };
13
+ /**
14
+ * The `snap_getClientStatus` method implementation.
15
+ * Returns useful information about the client running the snap.
16
+ *
17
+ * @param _request - The JSON-RPC request object. Not used by this function.
18
+ * @param response - The JSON-RPC response object.
19
+ * @param _next - The `json-rpc-engine` "next" callback. Not used by this
20
+ * function.
21
+ * @param end - The `json-rpc-engine` "end" callback.
22
+ * @param hooks - The RPC method hooks.
23
+ * @param hooks.getIsLocked - A function that returns whether the client is locked or not.
24
+ * @returns Nothing.
25
+ */ async function getClientStatusImplementation(_request, response, _next, end, { getIsLocked }) {
26
+ response.result = {
27
+ locked: getIsLocked()
28
+ };
29
+ return end();
30
+ }
31
+
32
+ //# sourceMappingURL=getClientStatus.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/permitted/getClientStatus.ts"],"sourcesContent":["import type { JsonRpcEngineEndCallback } from '@metamask/json-rpc-engine';\nimport type { PermittedHandlerExport } from '@metamask/permission-controller';\nimport type { GetClientStatusResult } from '@metamask/snaps-sdk';\nimport type {\n JsonRpcParams,\n JsonRpcRequest,\n PendingJsonRpcResponse,\n} from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\n\nconst hookNames: MethodHooksObject<GetClientStatusHooks> = {\n getIsLocked: true,\n};\n\n/**\n * `snap_getClientStatus` returns useful information about the client running the snap.\n */\nexport const getClientStatusHandler: PermittedHandlerExport<\n GetClientStatusHooks,\n JsonRpcParams,\n GetClientStatusResult\n> = {\n methodNames: ['snap_getClientStatus'],\n implementation: getClientStatusImplementation,\n hookNames,\n};\n\nexport type GetClientStatusHooks = {\n /**\n * @returns Whether the client is locked or not.\n */\n getIsLocked: () => boolean;\n};\n\n/**\n * The `snap_getClientStatus` method implementation.\n * Returns useful information about the client running the snap.\n *\n * @param _request - The JSON-RPC request object. Not used by this function.\n * @param response - 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.getIsLocked - A function that returns whether the client is locked or not.\n * @returns Nothing.\n */\nasync function getClientStatusImplementation(\n _request: JsonRpcRequest,\n response: PendingJsonRpcResponse<GetClientStatusResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n { getIsLocked }: GetClientStatusHooks,\n): Promise<void> {\n response.result = { locked: getIsLocked() };\n return end();\n}\n"],"names":["hookNames","getIsLocked","getClientStatusHandler","methodNames","implementation","getClientStatusImplementation","_request","response","_next","end","result","locked"],"mappings":"AAWA,MAAMA,YAAqD;IACzDC,aAAa;AACf;AAEA;;CAEC,GACD,OAAO,MAAMC,yBAIT;IACFC,aAAa;QAAC;KAAuB;IACrCC,gBAAgBC;IAChBL;AACF,EAAE;AASF;;;;;;;;;;;;CAYC,GACD,eAAeK,8BACbC,QAAwB,EACxBC,QAAuD,EACvDC,KAAc,EACdC,GAA6B,EAC7B,EAAER,WAAW,EAAwB;IAErCM,SAASG,MAAM,GAAG;QAAEC,QAAQV;IAAc;IAC1C,OAAOQ;AACT"}
@@ -29,7 +29,7 @@ export const getFileHandler = {
29
29
  * function.
30
30
  * @param end - The `json-rpc-engine` "end" callback.
31
31
  * @param hooks - The RPC method hooks.
32
- * @param hooks.getSnapFile - The funnction to load a static snap file.
32
+ * @param hooks.getSnapFile - The function to load a static snap file.
33
33
  * @returns Nothing.
34
34
  */ async function implementation(req, res, _next, end, { getSnapFile }) {
35
35
  const { params } = req;