@metamask/snaps-rpc-methods 5.0.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 (124) hide show
  1. package/CHANGELOG.md +15 -3
  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/getFile.js +1 -1
  41. package/dist/cjs/permitted/getFile.js.map +1 -1
  42. package/dist/cjs/permitted/getInterfaceState.js +67 -0
  43. package/dist/cjs/permitted/getInterfaceState.js.map +1 -0
  44. package/dist/cjs/permitted/handlers.js +7 -1
  45. package/dist/cjs/permitted/handlers.js.map +1 -1
  46. package/dist/cjs/permitted/index.js.map +1 -1
  47. package/dist/cjs/permitted/updateInterface.js +70 -0
  48. package/dist/cjs/permitted/updateInterface.js.map +1 -0
  49. package/dist/cjs/restricted/dialog.js +51 -24
  50. package/dist/cjs/restricted/dialog.js.map +1 -1
  51. package/dist/esm/endowments/caveats/generic.js +40 -0
  52. package/dist/esm/endowments/caveats/generic.js.map +1 -0
  53. package/dist/esm/endowments/caveats/index.js +4 -0
  54. package/dist/esm/endowments/caveats/index.js.map +1 -0
  55. package/dist/esm/endowments/caveats/requestTime.js +93 -0
  56. package/dist/esm/endowments/caveats/requestTime.js.map +1 -0
  57. package/dist/esm/endowments/cronjob.js +99 -0
  58. package/dist/esm/endowments/cronjob.js.map +1 -0
  59. package/dist/esm/endowments/enum.js +16 -0
  60. package/dist/esm/endowments/enum.js.map +1 -0
  61. package/dist/esm/endowments/ethereum-provider.js +33 -0
  62. package/dist/esm/endowments/ethereum-provider.js.map +1 -0
  63. package/dist/esm/endowments/home-page.js +27 -0
  64. package/dist/esm/endowments/home-page.js.map +1 -0
  65. package/dist/esm/endowments/index.js +68 -0
  66. package/dist/esm/endowments/index.js.map +1 -0
  67. package/dist/esm/endowments/keyring.js +95 -0
  68. package/dist/esm/endowments/keyring.js.map +1 -0
  69. package/dist/esm/endowments/lifecycle-hooks.js +27 -0
  70. package/dist/esm/endowments/lifecycle-hooks.js.map +1 -0
  71. package/dist/esm/endowments/name-lookup.js +146 -0
  72. package/dist/esm/endowments/name-lookup.js.map +1 -0
  73. package/dist/esm/endowments/network-access.js +34 -0
  74. package/dist/esm/endowments/network-access.js.map +1 -0
  75. package/dist/esm/endowments/rpc.js +92 -0
  76. package/dist/esm/endowments/rpc.js.map +1 -0
  77. package/dist/esm/endowments/signature-insight.js +103 -0
  78. package/dist/esm/endowments/signature-insight.js.map +1 -0
  79. package/dist/esm/endowments/transaction-insight.js +104 -0
  80. package/dist/esm/endowments/transaction-insight.js.map +1 -0
  81. package/dist/esm/endowments/web-assembly.js +32 -0
  82. package/dist/esm/endowments/web-assembly.js.map +1 -0
  83. package/dist/esm/index.js +3 -1
  84. package/dist/esm/index.js.map +1 -1
  85. package/dist/esm/permissions.js +51 -0
  86. package/dist/esm/permissions.js.map +1 -0
  87. package/dist/esm/permitted/createInterface.js +58 -0
  88. package/dist/esm/permitted/createInterface.js.map +1 -0
  89. package/dist/esm/permitted/getFile.js +1 -1
  90. package/dist/esm/permitted/getFile.js.map +1 -1
  91. package/dist/esm/permitted/getInterfaceState.js +57 -0
  92. package/dist/esm/permitted/getInterfaceState.js.map +1 -0
  93. package/dist/esm/permitted/handlers.js +7 -1
  94. package/dist/esm/permitted/handlers.js.map +1 -1
  95. package/dist/esm/permitted/index.js.map +1 -1
  96. package/dist/esm/permitted/updateInterface.js +60 -0
  97. package/dist/esm/permitted/updateInterface.js.map +1 -0
  98. package/dist/esm/restricted/dialog.js +55 -29
  99. package/dist/esm/restricted/dialog.js.map +1 -1
  100. package/dist/types/endowments/caveats/generic.d.ts +19 -0
  101. package/dist/types/endowments/caveats/index.d.ts +2 -0
  102. package/dist/types/endowments/caveats/requestTime.d.ts +29 -0
  103. package/dist/types/endowments/cronjob.d.ts +51 -0
  104. package/dist/types/endowments/enum.d.ts +13 -0
  105. package/dist/types/endowments/ethereum-provider.d.ts +14 -0
  106. package/dist/types/endowments/home-page.d.ts +15 -0
  107. package/dist/types/endowments/index.d.ts +131 -0
  108. package/dist/types/endowments/keyring.d.ts +39 -0
  109. package/dist/types/endowments/lifecycle-hooks.d.ts +15 -0
  110. package/dist/types/endowments/name-lookup.d.ts +49 -0
  111. package/dist/types/endowments/network-access.d.ts +14 -0
  112. package/dist/types/endowments/rpc.d.ts +38 -0
  113. package/dist/types/endowments/signature-insight.d.ts +39 -0
  114. package/dist/types/endowments/transaction-insight.d.ts +39 -0
  115. package/dist/types/endowments/web-assembly.d.ts +14 -0
  116. package/dist/types/index.d.ts +4 -2
  117. package/dist/types/permissions.d.ts +16 -0
  118. package/dist/types/permitted/createInterface.d.ts +150 -0
  119. package/dist/types/permitted/getInterfaceState.d.ts +18 -0
  120. package/dist/types/permitted/handlers.d.ts +4 -1
  121. package/dist/types/permitted/index.d.ts +4 -1
  122. package/dist/types/permitted/updateInterface.d.ts +152 -0
  123. package/dist/types/restricted/dialog.d.ts +776 -14
  124. package/package.json +5 -5
@@ -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"}
@@ -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;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/permitted/getFile.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 { GetFileParams, GetFileResult } from '@metamask/snaps-sdk';\nimport { AuxiliaryFileEncoding, enumValue } from '@metamask/snaps-sdk';\nimport type { InferMatching } from '@metamask/snaps-utils';\nimport type { PendingJsonRpcResponse, JsonRpcRequest } from '@metamask/utils';\nimport { assertStruct } from '@metamask/utils';\nimport { object, optional, string, union } from 'superstruct';\n\nimport type { MethodHooksObject } from '../utils';\n\nexport const GetFileArgsStruct = object({\n path: string(),\n encoding: optional(\n union([\n enumValue(AuxiliaryFileEncoding.Base64),\n enumValue(AuxiliaryFileEncoding.Hex),\n enumValue(AuxiliaryFileEncoding.Utf8),\n ]),\n ),\n});\n\nexport type InferredGetFileParams = InferMatching<\n typeof GetFileArgsStruct,\n GetFileParams\n>;\n\nconst hookNames: MethodHooksObject<GetFileHooks> = {\n getSnapFile: true,\n};\n\nexport const getFileHandler: PermittedHandlerExport<\n GetFileHooks,\n InferredGetFileParams,\n string\n> = {\n methodNames: ['snap_getFile'],\n implementation,\n hookNames,\n};\n\nexport type GetFileHooks = {\n getSnapFile: (\n path: InferredGetFileParams['path'],\n encoding: InferredGetFileParams['encoding'],\n ) => Promise<string>;\n};\n\n/**\n * The `snap_getFile` method implementation.\n *\n * @param req - The JSON-RPC request object.\n * @param res - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param hooks - The RPC method hooks.\n * @param hooks.getSnapFile - The funnction to load a static snap file.\n * @returns Nothing.\n */\nasync function implementation(\n req: JsonRpcRequest<InferredGetFileParams>,\n res: PendingJsonRpcResponse<GetFileResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n { getSnapFile }: GetFileHooks,\n): Promise<void> {\n const { params } = req;\n\n assertStruct(\n params,\n GetFileArgsStruct,\n 'Invalid \"snap_getFile\" parameters',\n rpcErrors.invalidParams,\n );\n\n try {\n res.result = await getSnapFile(\n params.path,\n params.encoding ?? AuxiliaryFileEncoding.Base64,\n );\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n"],"names":["rpcErrors","AuxiliaryFileEncoding","enumValue","assertStruct","object","optional","string","union","GetFileArgsStruct","path","encoding","Base64","Hex","Utf8","hookNames","getSnapFile","getFileHandler","methodNames","implementation","req","res","_next","end","params","invalidParams","result","error"],"mappings":"AAEA,SAASA,SAAS,QAAQ,uBAAuB;AAEjD,SAASC,qBAAqB,EAAEC,SAAS,QAAQ,sBAAsB;AAGvE,SAASC,YAAY,QAAQ,kBAAkB;AAC/C,SAASC,MAAM,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,KAAK,QAAQ,cAAc;AAI9D,OAAO,MAAMC,oBAAoBJ,OAAO;IACtCK,MAAMH;IACNI,UAAUL,SACRE,MAAM;QACJL,UAAUD,sBAAsBU,MAAM;QACtCT,UAAUD,sBAAsBW,GAAG;QACnCV,UAAUD,sBAAsBY,IAAI;KACrC;AAEL,GAAG;AAOH,MAAMC,YAA6C;IACjDC,aAAa;AACf;AAEA,OAAO,MAAMC,iBAIT;IACFC,aAAa;QAAC;KAAe;IAC7BC;IACAJ;AACF,EAAE;AASF;;;;;;;;;;;CAWC,GACD,eAAeI,eACbC,GAA0C,EAC1CC,GAA0C,EAC1CC,KAAc,EACdC,GAA6B,EAC7B,EAAEP,WAAW,EAAgB;IAE7B,MAAM,EAAEQ,MAAM,EAAE,GAAGJ;IAEnBhB,aACEoB,QACAf,mBACA,qCACAR,UAAUwB,aAAa;IAGzB,IAAI;QACFJ,IAAIK,MAAM,GAAG,MAAMV,YACjBQ,OAAOd,IAAI,EACXc,OAAOb,QAAQ,IAAIT,sBAAsBU,MAAM;IAEnD,EAAE,OAAOe,OAAO;QACd,OAAOJ,IAAII;IACb;IAEA,OAAOJ;AACT"}
1
+ {"version":3,"sources":["../../../src/permitted/getFile.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 { GetFileParams, GetFileResult } from '@metamask/snaps-sdk';\nimport { AuxiliaryFileEncoding, enumValue } from '@metamask/snaps-sdk';\nimport type { InferMatching } from '@metamask/snaps-utils';\nimport type { PendingJsonRpcResponse, JsonRpcRequest } from '@metamask/utils';\nimport { assertStruct } from '@metamask/utils';\nimport { object, optional, string, union } from 'superstruct';\n\nimport type { MethodHooksObject } from '../utils';\n\nexport const GetFileArgsStruct = object({\n path: string(),\n encoding: optional(\n union([\n enumValue(AuxiliaryFileEncoding.Base64),\n enumValue(AuxiliaryFileEncoding.Hex),\n enumValue(AuxiliaryFileEncoding.Utf8),\n ]),\n ),\n});\n\nexport type InferredGetFileParams = InferMatching<\n typeof GetFileArgsStruct,\n GetFileParams\n>;\n\nconst hookNames: MethodHooksObject<GetFileHooks> = {\n getSnapFile: true,\n};\n\nexport const getFileHandler: PermittedHandlerExport<\n GetFileHooks,\n InferredGetFileParams,\n string\n> = {\n methodNames: ['snap_getFile'],\n implementation,\n hookNames,\n};\n\nexport type GetFileHooks = {\n getSnapFile: (\n path: InferredGetFileParams['path'],\n encoding: InferredGetFileParams['encoding'],\n ) => Promise<string>;\n};\n\n/**\n * The `snap_getFile` method implementation.\n *\n * @param req - The JSON-RPC request object.\n * @param res - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param hooks - The RPC method hooks.\n * @param hooks.getSnapFile - The function to load a static snap file.\n * @returns Nothing.\n */\nasync function implementation(\n req: JsonRpcRequest<InferredGetFileParams>,\n res: PendingJsonRpcResponse<GetFileResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n { getSnapFile }: GetFileHooks,\n): Promise<void> {\n const { params } = req;\n\n assertStruct(\n params,\n GetFileArgsStruct,\n 'Invalid \"snap_getFile\" parameters',\n rpcErrors.invalidParams,\n );\n\n try {\n res.result = await getSnapFile(\n params.path,\n params.encoding ?? AuxiliaryFileEncoding.Base64,\n );\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n"],"names":["rpcErrors","AuxiliaryFileEncoding","enumValue","assertStruct","object","optional","string","union","GetFileArgsStruct","path","encoding","Base64","Hex","Utf8","hookNames","getSnapFile","getFileHandler","methodNames","implementation","req","res","_next","end","params","invalidParams","result","error"],"mappings":"AAEA,SAASA,SAAS,QAAQ,uBAAuB;AAEjD,SAASC,qBAAqB,EAAEC,SAAS,QAAQ,sBAAsB;AAGvE,SAASC,YAAY,QAAQ,kBAAkB;AAC/C,SAASC,MAAM,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,KAAK,QAAQ,cAAc;AAI9D,OAAO,MAAMC,oBAAoBJ,OAAO;IACtCK,MAAMH;IACNI,UAAUL,SACRE,MAAM;QACJL,UAAUD,sBAAsBU,MAAM;QACtCT,UAAUD,sBAAsBW,GAAG;QACnCV,UAAUD,sBAAsBY,IAAI;KACrC;AAEL,GAAG;AAOH,MAAMC,YAA6C;IACjDC,aAAa;AACf;AAEA,OAAO,MAAMC,iBAIT;IACFC,aAAa;QAAC;KAAe;IAC7BC;IACAJ;AACF,EAAE;AASF;;;;;;;;;;;CAWC,GACD,eAAeI,eACbC,GAA0C,EAC1CC,GAA0C,EAC1CC,KAAc,EACdC,GAA6B,EAC7B,EAAEP,WAAW,EAAgB;IAE7B,MAAM,EAAEQ,MAAM,EAAE,GAAGJ;IAEnBhB,aACEoB,QACAf,mBACA,qCACAR,UAAUwB,aAAa;IAGzB,IAAI;QACFJ,IAAIK,MAAM,GAAG,MAAMV,YACjBQ,OAAOd,IAAI,EACXc,OAAOb,QAAQ,IAAIT,sBAAsBU,MAAM;IAEnD,EAAE,OAAOe,OAAO;QACd,OAAOJ,IAAII;IACb;IAEA,OAAOJ;AACT"}
@@ -0,0 +1,57 @@
1
+ import { rpcErrors } from '@metamask/rpc-errors';
2
+ import { StructError, create, object, string } from 'superstruct';
3
+ const hookNames = {
4
+ getInterfaceState: true
5
+ };
6
+ export const getInterfaceStateHandler = {
7
+ methodNames: [
8
+ 'snap_getInterfaceState'
9
+ ],
10
+ implementation: getGetInterfaceStateImplementation,
11
+ hookNames
12
+ };
13
+ const GetInterfaceStateParametersStruct = object({
14
+ id: string()
15
+ });
16
+ /**
17
+ * The `snap_getInterfaceState` method implementation.
18
+ *
19
+ * @param req - The JSON-RPC request object.
20
+ * @param res - The JSON-RPC response object.
21
+ * @param _next - The `json-rpc-engine` "next" callback. Not used by this
22
+ * function.
23
+ * @param end - The `json-rpc-engine` "end" callback.
24
+ * @param hooks - The RPC method hooks.
25
+ * @param hooks.getInterfaceState - The function to get the interface state.
26
+ * @returns Noting.
27
+ */ function getGetInterfaceStateImplementation(req, res, _next, end, { getInterfaceState }) {
28
+ const { params } = req;
29
+ try {
30
+ const validatedParams = getValidatedParams(params);
31
+ const { id } = validatedParams;
32
+ res.result = getInterfaceState(id);
33
+ } catch (error) {
34
+ return end(error);
35
+ }
36
+ return end();
37
+ }
38
+ /**
39
+ * Validate the getInterfaceState method `params` and returns them cast to the correct
40
+ * type. Throws if validation fails.
41
+ *
42
+ * @param params - The unvalidated params object from the method request.
43
+ * @returns The validated getInterfaceState method parameter object.
44
+ */ function getValidatedParams(params) {
45
+ try {
46
+ return create(params, GetInterfaceStateParametersStruct);
47
+ } catch (error) {
48
+ if (error instanceof StructError) {
49
+ throw rpcErrors.invalidParams({
50
+ message: `Invalid params: ${error.message}.`
51
+ });
52
+ }
53
+ /* istanbul ignore next */ throw rpcErrors.internal();
54
+ }
55
+ }
56
+
57
+ //# sourceMappingURL=getInterfaceState.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/permitted/getInterfaceState.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 GetInterfaceStateParams,\n GetInterfaceStateResult,\n InterfaceState,\n JsonRpcRequest,\n} from '@metamask/snaps-sdk';\nimport { type InferMatching } from '@metamask/snaps-utils';\nimport type { PendingJsonRpcResponse } from '@metamask/utils';\nimport { StructError, create, object, string } from 'superstruct';\n\nimport type { MethodHooksObject } from '../utils';\n\nconst hookNames: MethodHooksObject<GetInterfaceStateMethodHooks> = {\n getInterfaceState: true,\n};\n\nexport type GetInterfaceStateMethodHooks = {\n /**\n * @param id - The interface ID.\n * @returns The interface state.\n */\n getInterfaceState: (id: string) => InterfaceState;\n};\n\nexport const getInterfaceStateHandler: PermittedHandlerExport<\n GetInterfaceStateMethodHooks,\n GetInterfaceStateParameters,\n GetInterfaceStateResult\n> = {\n methodNames: ['snap_getInterfaceState'],\n implementation: getGetInterfaceStateImplementation,\n hookNames,\n};\n\nconst GetInterfaceStateParametersStruct = object({\n id: string(),\n});\n\nexport type GetInterfaceStateParameters = InferMatching<\n typeof GetInterfaceStateParametersStruct,\n GetInterfaceStateParams\n>;\n\n/**\n * The `snap_getInterfaceState` method implementation.\n *\n * @param req - The JSON-RPC request object.\n * @param res - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param hooks - The RPC method hooks.\n * @param hooks.getInterfaceState - The function to get the interface state.\n * @returns Noting.\n */\nfunction getGetInterfaceStateImplementation(\n req: JsonRpcRequest<GetInterfaceStateParameters>,\n res: PendingJsonRpcResponse<GetInterfaceStateResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n { getInterfaceState }: GetInterfaceStateMethodHooks,\n): void {\n const { params } = req;\n\n try {\n const validatedParams = getValidatedParams(params);\n\n const { id } = validatedParams;\n\n res.result = getInterfaceState(id);\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n\n/**\n * Validate the getInterfaceState method `params` and returns them cast to the correct\n * type. Throws if validation fails.\n *\n * @param params - The unvalidated params object from the method request.\n * @returns The validated getInterfaceState method parameter object.\n */\nfunction getValidatedParams(params: unknown): GetInterfaceStateParameters {\n try {\n return create(params, GetInterfaceStateParametersStruct);\n } catch (error) {\n if (error instanceof StructError) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}.`,\n });\n }\n /* istanbul ignore next */\n throw rpcErrors.internal();\n }\n}\n"],"names":["rpcErrors","StructError","create","object","string","hookNames","getInterfaceState","getInterfaceStateHandler","methodNames","implementation","getGetInterfaceStateImplementation","GetInterfaceStateParametersStruct","id","req","res","_next","end","params","validatedParams","getValidatedParams","result","error","invalidParams","message","internal"],"mappings":"AAEA,SAASA,SAAS,QAAQ,uBAAuB;AASjD,SAASC,WAAW,EAAEC,MAAM,EAAEC,MAAM,EAAEC,MAAM,QAAQ,cAAc;AAIlE,MAAMC,YAA6D;IACjEC,mBAAmB;AACrB;AAUA,OAAO,MAAMC,2BAIT;IACFC,aAAa;QAAC;KAAyB;IACvCC,gBAAgBC;IAChBL;AACF,EAAE;AAEF,MAAMM,oCAAoCR,OAAO;IAC/CS,IAAIR;AACN;AAOA;;;;;;;;;;;CAWC,GACD,SAASM,mCACPG,GAAgD,EAChDC,GAAoD,EACpDC,KAAc,EACdC,GAA6B,EAC7B,EAAEV,iBAAiB,EAAgC;IAEnD,MAAM,EAAEW,MAAM,EAAE,GAAGJ;IAEnB,IAAI;QACF,MAAMK,kBAAkBC,mBAAmBF;QAE3C,MAAM,EAAEL,EAAE,EAAE,GAAGM;QAEfJ,IAAIM,MAAM,GAAGd,kBAAkBM;IACjC,EAAE,OAAOS,OAAO;QACd,OAAOL,IAAIK;IACb;IAEA,OAAOL;AACT;AAEA;;;;;;CAMC,GACD,SAASG,mBAAmBF,MAAe;IACzC,IAAI;QACF,OAAOf,OAAOe,QAAQN;IACxB,EAAE,OAAOU,OAAO;QACd,IAAIA,iBAAiBpB,aAAa;YAChC,MAAMD,UAAUsB,aAAa,CAAC;gBAC5BC,SAAS,CAAC,gBAAgB,EAAEF,MAAME,OAAO,CAAC,CAAC,CAAC;YAC9C;QACF;QACA,wBAAwB,GACxB,MAAMvB,UAAUwB,QAAQ;IAC1B;AACF"}
@@ -1,10 +1,13 @@
1
+ import { createInterfaceHandler } from './createInterface';
1
2
  import { getAllSnapsHandler } from './getAllSnaps';
2
3
  import { getClientStatusHandler } from './getClientStatus';
3
4
  import { getFileHandler } from './getFile';
5
+ import { getInterfaceStateHandler } from './getInterfaceState';
4
6
  import { getSnapsHandler } from './getSnaps';
5
7
  import { invokeKeyringHandler } from './invokeKeyring';
6
8
  import { invokeSnapSugarHandler } from './invokeSnapSugar';
7
9
  import { requestSnapsHandler } from './requestSnaps';
10
+ import { updateInterfaceHandler } from './updateInterface';
8
11
  /* eslint-disable @typescript-eslint/naming-convention */ export const methodHandlers = {
9
12
  wallet_getAllSnaps: getAllSnapsHandler,
10
13
  wallet_getSnaps: getSnapsHandler,
@@ -12,7 +15,10 @@ import { requestSnapsHandler } from './requestSnaps';
12
15
  wallet_invokeSnap: invokeSnapSugarHandler,
13
16
  wallet_invokeKeyring: invokeKeyringHandler,
14
17
  snap_getClientStatus: getClientStatusHandler,
15
- snap_getFile: getFileHandler
18
+ snap_getFile: getFileHandler,
19
+ snap_createInterface: createInterfaceHandler,
20
+ snap_updateInterface: updateInterfaceHandler,
21
+ snap_getInterfaceState: getInterfaceStateHandler
16
22
  };
17
23
  /* eslint-enable @typescript-eslint/naming-convention */ export const handlers = Object.values(methodHandlers);
18
24
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/permitted/handlers.ts"],"sourcesContent":["import { getAllSnapsHandler } from './getAllSnaps';\nimport { getClientStatusHandler } from './getClientStatus';\nimport { getFileHandler } from './getFile';\nimport { getSnapsHandler } from './getSnaps';\nimport { invokeKeyringHandler } from './invokeKeyring';\nimport { invokeSnapSugarHandler } from './invokeSnapSugar';\nimport { requestSnapsHandler } from './requestSnaps';\n\n/* eslint-disable @typescript-eslint/naming-convention */\nexport const methodHandlers = {\n wallet_getAllSnaps: getAllSnapsHandler,\n wallet_getSnaps: getSnapsHandler,\n wallet_requestSnaps: requestSnapsHandler,\n wallet_invokeSnap: invokeSnapSugarHandler,\n wallet_invokeKeyring: invokeKeyringHandler,\n snap_getClientStatus: getClientStatusHandler,\n snap_getFile: getFileHandler,\n};\n/* eslint-enable @typescript-eslint/naming-convention */\n\nexport const handlers = Object.values(methodHandlers);\n"],"names":["getAllSnapsHandler","getClientStatusHandler","getFileHandler","getSnapsHandler","invokeKeyringHandler","invokeSnapSugarHandler","requestSnapsHandler","methodHandlers","wallet_getAllSnaps","wallet_getSnaps","wallet_requestSnaps","wallet_invokeSnap","wallet_invokeKeyring","snap_getClientStatus","snap_getFile","handlers","Object","values"],"mappings":"AAAA,SAASA,kBAAkB,QAAQ,gBAAgB;AACnD,SAASC,sBAAsB,QAAQ,oBAAoB;AAC3D,SAASC,cAAc,QAAQ,YAAY;AAC3C,SAASC,eAAe,QAAQ,aAAa;AAC7C,SAASC,oBAAoB,QAAQ,kBAAkB;AACvD,SAASC,sBAAsB,QAAQ,oBAAoB;AAC3D,SAASC,mBAAmB,QAAQ,iBAAiB;AAErD,uDAAuD,GACvD,OAAO,MAAMC,iBAAiB;IAC5BC,oBAAoBR;IACpBS,iBAAiBN;IACjBO,qBAAqBJ;IACrBK,mBAAmBN;IACnBO,sBAAsBR;IACtBS,sBAAsBZ;IACtBa,cAAcZ;AAChB,EAAE;AACF,sDAAsD,GAEtD,OAAO,MAAMa,WAAWC,OAAOC,MAAM,CAACV,gBAAgB"}
1
+ {"version":3,"sources":["../../../src/permitted/handlers.ts"],"sourcesContent":["import { createInterfaceHandler } from './createInterface';\nimport { getAllSnapsHandler } from './getAllSnaps';\nimport { getClientStatusHandler } from './getClientStatus';\nimport { getFileHandler } from './getFile';\nimport { getInterfaceStateHandler } from './getInterfaceState';\nimport { getSnapsHandler } from './getSnaps';\nimport { invokeKeyringHandler } from './invokeKeyring';\nimport { invokeSnapSugarHandler } from './invokeSnapSugar';\nimport { requestSnapsHandler } from './requestSnaps';\nimport { updateInterfaceHandler } from './updateInterface';\n\n/* eslint-disable @typescript-eslint/naming-convention */\nexport const methodHandlers = {\n wallet_getAllSnaps: getAllSnapsHandler,\n wallet_getSnaps: getSnapsHandler,\n wallet_requestSnaps: requestSnapsHandler,\n wallet_invokeSnap: invokeSnapSugarHandler,\n wallet_invokeKeyring: invokeKeyringHandler,\n snap_getClientStatus: getClientStatusHandler,\n snap_getFile: getFileHandler,\n snap_createInterface: createInterfaceHandler,\n snap_updateInterface: updateInterfaceHandler,\n snap_getInterfaceState: getInterfaceStateHandler,\n};\n/* eslint-enable @typescript-eslint/naming-convention */\n\nexport const handlers = Object.values(methodHandlers);\n"],"names":["createInterfaceHandler","getAllSnapsHandler","getClientStatusHandler","getFileHandler","getInterfaceStateHandler","getSnapsHandler","invokeKeyringHandler","invokeSnapSugarHandler","requestSnapsHandler","updateInterfaceHandler","methodHandlers","wallet_getAllSnaps","wallet_getSnaps","wallet_requestSnaps","wallet_invokeSnap","wallet_invokeKeyring","snap_getClientStatus","snap_getFile","snap_createInterface","snap_updateInterface","snap_getInterfaceState","handlers","Object","values"],"mappings":"AAAA,SAASA,sBAAsB,QAAQ,oBAAoB;AAC3D,SAASC,kBAAkB,QAAQ,gBAAgB;AACnD,SAASC,sBAAsB,QAAQ,oBAAoB;AAC3D,SAASC,cAAc,QAAQ,YAAY;AAC3C,SAASC,wBAAwB,QAAQ,sBAAsB;AAC/D,SAASC,eAAe,QAAQ,aAAa;AAC7C,SAASC,oBAAoB,QAAQ,kBAAkB;AACvD,SAASC,sBAAsB,QAAQ,oBAAoB;AAC3D,SAASC,mBAAmB,QAAQ,iBAAiB;AACrD,SAASC,sBAAsB,QAAQ,oBAAoB;AAE3D,uDAAuD,GACvD,OAAO,MAAMC,iBAAiB;IAC5BC,oBAAoBV;IACpBW,iBAAiBP;IACjBQ,qBAAqBL;IACrBM,mBAAmBP;IACnBQ,sBAAsBT;IACtBU,sBAAsBd;IACtBe,cAAcd;IACde,sBAAsBlB;IACtBmB,sBAAsBV;IACtBW,wBAAwBhB;AAC1B,EAAE;AACF,sDAAsD,GAEtD,OAAO,MAAMiB,WAAWC,OAAOC,MAAM,CAACb,gBAAgB"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/permitted/index.ts"],"sourcesContent":["import type { GetAllSnapsHooks } from './getAllSnaps';\nimport type { GetClientStatusHooks } from './getClientStatus';\nimport type { GetSnapsHooks } from './getSnaps';\nimport type { RequestSnapsHooks } from './requestSnaps';\n\nexport type PermittedRpcMethodHooks = GetAllSnapsHooks &\n GetClientStatusHooks &\n GetSnapsHooks &\n RequestSnapsHooks;\n\nexport * from './handlers';\nexport * from './middleware';\n"],"names":[],"mappings":"AAUA,cAAc,aAAa;AAC3B,cAAc,eAAe"}
1
+ {"version":3,"sources":["../../../src/permitted/index.ts"],"sourcesContent":["import type { CreateInterfaceMethodHooks } from './createInterface';\nimport type { GetAllSnapsHooks } from './getAllSnaps';\nimport type { GetClientStatusHooks } from './getClientStatus';\nimport type { GetInterfaceStateMethodHooks } from './getInterfaceState';\nimport type { GetSnapsHooks } from './getSnaps';\nimport type { RequestSnapsHooks } from './requestSnaps';\nimport type { UpdateInterfaceMethodHooks } from './updateInterface';\n\nexport type PermittedRpcMethodHooks = GetAllSnapsHooks &\n GetClientStatusHooks &\n GetSnapsHooks &\n RequestSnapsHooks &\n CreateInterfaceMethodHooks &\n UpdateInterfaceMethodHooks &\n GetInterfaceStateMethodHooks;\n\nexport * from './handlers';\nexport * from './middleware';\n"],"names":[],"mappings":"AAgBA,cAAc,aAAa;AAC3B,cAAc,eAAe"}