@metamask/snaps-simulation 4.1.3 → 4.1.4
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.
- package/CHANGELOG.md +13 -2
- package/dist/methods/hooks/index.cjs +0 -2
- package/dist/methods/hooks/index.cjs.map +1 -1
- package/dist/methods/hooks/index.d.cts +0 -2
- package/dist/methods/hooks/index.d.cts.map +1 -1
- package/dist/methods/hooks/index.d.mts +0 -2
- package/dist/methods/hooks/index.d.mts.map +1 -1
- package/dist/methods/hooks/index.mjs +0 -2
- package/dist/methods/hooks/index.mjs.map +1 -1
- package/dist/methods/hooks/state.cjs +1 -1
- package/dist/methods/hooks/state.cjs.map +1 -1
- package/dist/methods/hooks/state.d.cts +1 -1
- package/dist/methods/hooks/state.d.cts.map +1 -1
- package/dist/methods/hooks/state.d.mts +1 -1
- package/dist/methods/hooks/state.d.mts.map +1 -1
- package/dist/methods/hooks/state.mjs +1 -1
- package/dist/methods/hooks/state.mjs.map +1 -1
- package/dist/methods/specifications.cjs +5 -14
- package/dist/methods/specifications.cjs.map +1 -1
- package/dist/methods/specifications.d.cts +7 -17
- package/dist/methods/specifications.d.cts.map +1 -1
- package/dist/methods/specifications.d.mts +7 -17
- package/dist/methods/specifications.d.mts.map +1 -1
- package/dist/methods/specifications.mjs +6 -15
- package/dist/methods/specifications.mjs.map +1 -1
- package/dist/middleware/engine.cjs +8 -4
- package/dist/middleware/engine.cjs.map +1 -1
- package/dist/middleware/engine.d.cts +7 -6
- package/dist/middleware/engine.d.cts.map +1 -1
- package/dist/middleware/engine.d.mts +7 -6
- package/dist/middleware/engine.d.mts.map +1 -1
- package/dist/middleware/engine.mjs +9 -5
- package/dist/middleware/engine.mjs.map +1 -1
- package/dist/simulation.cjs +82 -27
- package/dist/simulation.cjs.map +1 -1
- package/dist/simulation.d.cts +18 -114
- package/dist/simulation.d.cts.map +1 -1
- package/dist/simulation.d.mts +18 -114
- package/dist/simulation.d.mts.map +1 -1
- package/dist/simulation.mjs +83 -28
- package/dist/simulation.mjs.map +1 -1
- package/package.json +12 -12
- package/dist/methods/hooks/get-entropy-sources.cjs +0 -30
- package/dist/methods/hooks/get-entropy-sources.cjs.map +0 -1
- package/dist/methods/hooks/get-entropy-sources.d.cts +0 -14
- package/dist/methods/hooks/get-entropy-sources.d.cts.map +0 -1
- package/dist/methods/hooks/get-entropy-sources.d.mts +0 -14
- package/dist/methods/hooks/get-entropy-sources.d.mts.map +0 -1
- package/dist/methods/hooks/get-entropy-sources.mjs +0 -26
- package/dist/methods/hooks/get-entropy-sources.mjs.map +0 -1
- package/dist/methods/hooks/get-mnemonic-seed.cjs +0 -29
- package/dist/methods/hooks/get-mnemonic-seed.cjs.map +0 -1
- package/dist/methods/hooks/get-mnemonic-seed.d.cts +0 -9
- package/dist/methods/hooks/get-mnemonic-seed.d.cts.map +0 -1
- package/dist/methods/hooks/get-mnemonic-seed.d.mts +0 -9
- package/dist/methods/hooks/get-mnemonic-seed.d.mts.map +0 -1
- package/dist/methods/hooks/get-mnemonic-seed.mjs +0 -25
- package/dist/methods/hooks/get-mnemonic-seed.mjs.map +0 -1
- package/dist/methods/hooks/interface.cjs +0 -34
- package/dist/methods/hooks/interface.cjs.map +0 -1
- package/dist/methods/hooks/interface.d.cts +0 -24
- package/dist/methods/hooks/interface.d.cts.map +0 -1
- package/dist/methods/hooks/interface.d.mts +0 -24
- package/dist/methods/hooks/interface.d.mts.map +0 -1
- package/dist/methods/hooks/interface.mjs +0 -28
- package/dist/methods/hooks/interface.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [4.1.4]
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- Bump `@metamask/snaps-rpc-methods` from `^15.1.1` to `16.0.0` and handle breaking changes ([#3968](https://github.com/MetaMask/snaps/pull/3968), [#3987](https://github.com/MetaMask/snaps/pull/3987), [#3993](https://github.com/MetaMask/snaps/pull/3993))
|
|
15
|
+
- Bump `@metamask/permission-controller` `12.3.0` to `^13.1.0` ([#3984](https://github.com/MetaMask/snaps/pull/3984), [#3989](https://github.com/MetaMask/snaps/pull/3989))
|
|
16
|
+
- Bump `@metamask/json-rpc-engine` from `^10.2.4` to `^10.5.0` ([#3982](https://github.com/MetaMask/snaps/pull/3982),[#3992](https://github.com/MetaMask/snaps/pull/3992), [#3998](https://github.com/MetaMask/snaps/pull/3998))
|
|
17
|
+
- Bump `@metamask/messenger` from `^1.1.1` to `^1.2.0` ([#3981](https://github.com/MetaMask/snaps/pull/3981))
|
|
18
|
+
- Bump `@metamask/chain-agnostic-permission` from `^1.5.0` to `^1.6.0` ([#3997](https://github.com/MetaMask/snaps/pull/3997))
|
|
19
|
+
|
|
10
20
|
## [4.1.3]
|
|
11
21
|
|
|
12
22
|
### Changed
|
|
@@ -71,7 +81,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
71
81
|
|
|
72
82
|
## Changed
|
|
73
83
|
|
|
74
|
-
- Bump `@metamask/permission-controller` from `12.0.0` to `12.1.1
|
|
84
|
+
- Bump `@metamask/permission-controller` from `12.0.0` to `12.1.1`, ([#3746](https://github.com/MetaMask/snaps/pull/3746), [#3714](https://github.com/MetaMask/snaps/pull/3714))
|
|
75
85
|
- Bump `@metamask/phishing-controller` from `13.1.0` to `15.0.0` ([#3707](https://github.com/MetaMask/snaps/pull/3707))
|
|
76
86
|
|
|
77
87
|
## [3.5.1]
|
|
@@ -300,7 +310,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
300
310
|
|
|
301
311
|
- Initial release of `@metamask/snaps-simulation` package ([#2727](https://github.com/MetaMask/snaps/pull/2727))
|
|
302
312
|
|
|
303
|
-
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-simulation@4.1.
|
|
313
|
+
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-simulation@4.1.4...HEAD
|
|
314
|
+
[4.1.4]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-simulation@4.1.3...@metamask/snaps-simulation@4.1.4
|
|
304
315
|
[4.1.3]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-simulation@4.1.2...@metamask/snaps-simulation@4.1.3
|
|
305
316
|
[4.1.2]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-simulation@4.1.1...@metamask/snaps-simulation@4.1.2
|
|
306
317
|
[4.1.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-simulation@4.1.0...@metamask/snaps-simulation@4.1.1
|
|
@@ -16,11 +16,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./chain.cjs"), exports);
|
|
18
18
|
__exportStar(require("./end-trace.cjs"), exports);
|
|
19
|
-
__exportStar(require("./get-entropy-sources.cjs"), exports);
|
|
20
19
|
__exportStar(require("./get-mnemonic.cjs"), exports);
|
|
21
20
|
__exportStar(require("./get-preferences.cjs"), exports);
|
|
22
21
|
__exportStar(require("./get-snap.cjs"), exports);
|
|
23
|
-
__exportStar(require("./interface.cjs"), exports);
|
|
24
22
|
__exportStar(require("./notifications.cjs"), exports);
|
|
25
23
|
__exportStar(require("./permitted/index.cjs"), exports);
|
|
26
24
|
__exportStar(require("./request-user-approval.cjs"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../src/methods/hooks/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAAwB;AACxB,kDAA4B;AAC5B,
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../src/methods/hooks/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAAwB;AACxB,kDAA4B;AAC5B,qDAA+B;AAC/B,wDAAkC;AAClC,iDAA2B;AAC3B,sDAAgC;AAChC,wDAA4B;AAC5B,8DAAwC;AACxC,oDAA8B;AAC9B,8CAAwB;AACxB,oDAA8B;AAC9B,oDAA8B","sourcesContent":["export * from './chain';\nexport * from './end-trace';\nexport * from './get-mnemonic';\nexport * from './get-preferences';\nexport * from './get-snap';\nexport * from './notifications';\nexport * from './permitted';\nexport * from './request-user-approval';\nexport * from './start-trace';\nexport * from './state';\nexport * from './track-error';\nexport * from './track-event';\n"]}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
export * from "./chain.cjs";
|
|
2
2
|
export * from "./end-trace.cjs";
|
|
3
|
-
export * from "./get-entropy-sources.cjs";
|
|
4
3
|
export * from "./get-mnemonic.cjs";
|
|
5
4
|
export * from "./get-preferences.cjs";
|
|
6
5
|
export * from "./get-snap.cjs";
|
|
7
|
-
export * from "./interface.cjs";
|
|
8
6
|
export * from "./notifications.cjs";
|
|
9
7
|
export * from "./permitted/index.cjs";
|
|
10
8
|
export * from "./request-user-approval.cjs";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/methods/hooks/index.ts"],"names":[],"mappings":"AAAA,4BAAwB;AACxB,gCAA4B;AAC5B,
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/methods/hooks/index.ts"],"names":[],"mappings":"AAAA,4BAAwB;AACxB,gCAA4B;AAC5B,mCAA+B;AAC/B,sCAAkC;AAClC,+BAA2B;AAC3B,oCAAgC;AAChC,sCAA4B;AAC5B,4CAAwC;AACxC,kCAA8B;AAC9B,4BAAwB;AACxB,kCAA8B;AAC9B,kCAA8B"}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
export * from "./chain.mjs";
|
|
2
2
|
export * from "./end-trace.mjs";
|
|
3
|
-
export * from "./get-entropy-sources.mjs";
|
|
4
3
|
export * from "./get-mnemonic.mjs";
|
|
5
4
|
export * from "./get-preferences.mjs";
|
|
6
5
|
export * from "./get-snap.mjs";
|
|
7
|
-
export * from "./interface.mjs";
|
|
8
6
|
export * from "./notifications.mjs";
|
|
9
7
|
export * from "./permitted/index.mjs";
|
|
10
8
|
export * from "./request-user-approval.mjs";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/methods/hooks/index.ts"],"names":[],"mappings":"AAAA,4BAAwB;AACxB,gCAA4B;AAC5B,
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/methods/hooks/index.ts"],"names":[],"mappings":"AAAA,4BAAwB;AACxB,gCAA4B;AAC5B,mCAA+B;AAC/B,sCAAkC;AAClC,+BAA2B;AAC3B,oCAAgC;AAChC,sCAA4B;AAC5B,4CAAwC;AACxC,kCAA8B;AAC9B,4BAAwB;AACxB,kCAA8B;AAC9B,kCAA8B"}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
export * from "./chain.mjs";
|
|
2
2
|
export * from "./end-trace.mjs";
|
|
3
|
-
export * from "./get-entropy-sources.mjs";
|
|
4
3
|
export * from "./get-mnemonic.mjs";
|
|
5
4
|
export * from "./get-preferences.mjs";
|
|
6
5
|
export * from "./get-snap.mjs";
|
|
7
|
-
export * from "./interface.mjs";
|
|
8
6
|
export * from "./notifications.mjs";
|
|
9
7
|
export * from "./permitted/index.mjs";
|
|
10
8
|
export * from "./request-user-approval.mjs";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../src/methods/hooks/index.ts"],"names":[],"mappings":"AAAA,4BAAwB;AACxB,gCAA4B;AAC5B,
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../src/methods/hooks/index.ts"],"names":[],"mappings":"AAAA,4BAAwB;AACxB,gCAA4B;AAC5B,mCAA+B;AAC/B,sCAAkC;AAClC,+BAA2B;AAC3B,oCAAgC;AAChC,sCAA4B;AAC5B,4CAAwC;AACxC,kCAA8B;AAC9B,4BAAwB;AACxB,kCAA8B;AAC9B,kCAA8B","sourcesContent":["export * from './chain';\nexport * from './end-trace';\nexport * from './get-mnemonic';\nexport * from './get-preferences';\nexport * from './get-snap';\nexport * from './notifications';\nexport * from './permitted';\nexport * from './request-user-approval';\nexport * from './start-trace';\nexport * from './state';\nexport * from './track-error';\nexport * from './track-event';\n"]}
|
|
@@ -52,7 +52,7 @@ function* updateSnapStateImplementation(_snapId, newState, encrypted = true) {
|
|
|
52
52
|
* @returns The implementation of the `updateSnapState` hook.
|
|
53
53
|
*/
|
|
54
54
|
function getUpdateSnapStateMethodImplementation(runSaga) {
|
|
55
|
-
return (...args) => {
|
|
55
|
+
return async (...args) => {
|
|
56
56
|
runSaga(updateSnapStateImplementation, ...args).result();
|
|
57
57
|
};
|
|
58
58
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.cjs","sourceRoot":"","sources":["../../../src/methods/hooks/state.ts"],"names":[],"mappings":";;;AAAA,uDAAkD;AAGlD,gDAAiD;AAGjD,iDAA6D;AAE7D;;;;;;;;;GASG;AACH,QAAQ,CAAC,CAAC,0BAA0B,CAClC,OAAe,EACf,SAAS,GAAG,IAAI;IAEhB,MAAM,KAAK,GAAG,MAAM,IAAA,gBAAM,EAAC,IAAA,gBAAQ,EAAC,SAAS,CAAC,CAAC,CAAC;IAChD,6CAA6C;IAC7C,OAAO,IAAA,uBAAS,EAAC,KAAK,CAAC,CAAC;AAC1B,CAAC;AAED;;;;;GAKG;AACH,SAAgB,mCAAmC,CAAC,OAAwB;IAC1E,OAAO,CAAC,GAAG,IAAmD,EAAE,EAAE;QAChE,OAAO,OAAO,CAAC,0BAA0B,EAAE,GAAG,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC;IAC/D,CAAC,CAAC;AACJ,CAAC;AAJD,kFAIC;AAED;;;;;;;;;GASG;AACH,QAAQ,CAAC,CAAC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AAO,KAAK,EAAE,GAAG,IAAsD,EAAE,EAAE;QACzE,OAAO,CAAC,6BAA6B,EAAE,GAAG,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC;IAC3D,CAAC,CAAC;AACJ,CAAC;AAND,wFAMC;AAED;;;;;;;;GAQG;AACH,QAAQ,CAAC,CAAC,4BAA4B,CACpC,OAAe,EACf,SAAS,GAAG,IAAI;IAEhB,MAAM,IAAA,aAAG,EAAC,IAAA,kBAAU,EAAC,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC;AACvC,CAAC;AAED;;;;;GAKG;AACH,SAAgB,qCAAqC,CACnD,OAAwB;IAExB,OAAO,KAAK,EAAE,GAAG,IAAqD,EAAE,EAAE;QACxE,OAAO,CAAC,4BAA4B,EAAE,GAAG,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC;IAC1D,CAAC,CAAC;AACJ,CAAC;AAND,sFAMC","sourcesContent":["import { parseJson } from '@metamask/snaps-utils';\nimport type { Json } from '@metamask/utils';\nimport type { SagaIterator } from 'redux-saga';\nimport { put, select } from 'redux-saga/effects';\n\nimport type { RunSagaFunction } from '../../store';\nimport { clearState, getState, setState } from '../../store';\n\n/**\n * Get the Snap state from the store.\n *\n * @param _snapId - The ID of the Snap to get the state for. This is ignored\n * because the simulator only supports one Snap.\n * @param encrypted - Whether to get the encrypted or unencrypted state.\n * Defaults to encrypted state.\n * @returns The state of the Snap.\n * @yields Selects the state from the store.\n */\nfunction* getSnapStateImplementation(\n _snapId: string,\n encrypted = true,\n): SagaIterator<string> {\n const state = yield select(getState(encrypted));\n // TODO: Use actual decryption implementation\n return parseJson(state);\n}\n\n/**\n * Get the implementation of the `getSnapState` hook.\n *\n * @param runSaga - The function to run a saga outside the usual Redux flow.\n * @returns The implementation of the `getSnapState` hook.\n */\nexport function getGetSnapStateMethodImplementation(runSaga: RunSagaFunction) {\n return (...args: Parameters<typeof getSnapStateImplementation>) => {\n return runSaga(getSnapStateImplementation, ...args).result();\n };\n}\n\n/**\n * Update the Snap state in the store.\n *\n * @param _snapId - The ID of the Snap to update the state for. This is ignored\n * because the simulator only supports one Snap.\n * @param newState - The new state.\n * @param encrypted - Whether to update the encrypted or unencrypted state.\n * Defaults to encrypted state.\n * @yields Puts the new state in the store.\n */\nfunction* updateSnapStateImplementation(\n _snapId: string,\n newState: Record<string, Json>,\n encrypted = true,\n): SagaIterator<void> {\n // TODO: Use actual encryption implementation\n yield put(setState({ state: JSON.stringify(newState), encrypted }));\n}\n\n/**\n * Get the implementation of the `updateSnapState` hook.\n *\n * @param runSaga - The function to run a saga outside the usual Redux flow.\n * @returns The implementation of the `updateSnapState` hook.\n */\nexport function getUpdateSnapStateMethodImplementation(\n runSaga: RunSagaFunction,\n) {\n return async (...args: Parameters<typeof updateSnapStateImplementation>) => {\n runSaga(updateSnapStateImplementation, ...args).result();\n };\n}\n\n/**\n * Clear the Snap state in the store.\n *\n * @param _snapId - The ID of the Snap to clear the state for. This is ignored\n * because the simulator only supports one Snap.\n * @param encrypted - Whether to clear the encrypted or unencrypted state.\n * Defaults to encrypted state.\n * @yields Puts the new state in the store.\n */\nfunction* clearSnapStateImplementation(\n _snapId: string,\n encrypted = true,\n): SagaIterator<void> {\n yield put(clearState({ encrypted }));\n}\n\n/**\n * Get the implementation of the `clearSnapState` hook.\n *\n * @param runSaga - The function to run a saga outside the usual Redux flow.\n * @returns The implementation of the `clearSnapState` hook.\n */\nexport function getClearSnapStateMethodImplementation(\n runSaga: RunSagaFunction,\n) {\n return async (...args: Parameters<typeof clearSnapStateImplementation>) => {\n runSaga(clearSnapStateImplementation, ...args).result();\n };\n}\n"]}
|
|
@@ -13,7 +13,7 @@ export declare function getGetSnapStateMethodImplementation(runSaga: RunSagaFunc
|
|
|
13
13
|
* @param runSaga - The function to run a saga outside the usual Redux flow.
|
|
14
14
|
* @returns The implementation of the `updateSnapState` hook.
|
|
15
15
|
*/
|
|
16
|
-
export declare function getUpdateSnapStateMethodImplementation(runSaga: RunSagaFunction): (_snapId: string, newState: Record<string, Json>, encrypted?: boolean | undefined) => void
|
|
16
|
+
export declare function getUpdateSnapStateMethodImplementation(runSaga: RunSagaFunction): (_snapId: string, newState: Record<string, Json>, encrypted?: boolean | undefined) => Promise<void>;
|
|
17
17
|
/**
|
|
18
18
|
* Get the implementation of the `clearSnapState` hook.
|
|
19
19
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.d.cts","sourceRoot":"","sources":["../../../src/methods/hooks/state.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAI5C,OAAO,KAAK,EAAE,eAAe,EAAE,8BAAoB;AAsBnD;;;;;GAKG;AACH,wBAAgB,mCAAmC,CAAC,OAAO,EAAE,eAAe,6DAI3E;AAqBD;;;;;GAKG;AACH,wBAAgB,sCAAsC,CACpD,OAAO,EAAE,eAAe,
|
|
1
|
+
{"version":3,"file":"state.d.cts","sourceRoot":"","sources":["../../../src/methods/hooks/state.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAI5C,OAAO,KAAK,EAAE,eAAe,EAAE,8BAAoB;AAsBnD;;;;;GAKG;AACH,wBAAgB,mCAAmC,CAAC,OAAO,EAAE,eAAe,6DAI3E;AAqBD;;;;;GAKG;AACH,wBAAgB,sCAAsC,CACpD,OAAO,EAAE,eAAe,uGAKzB;AAkBD;;;;;GAKG;AACH,wBAAgB,qCAAqC,CACnD,OAAO,EAAE,eAAe,uEAKzB"}
|
|
@@ -13,7 +13,7 @@ export declare function getGetSnapStateMethodImplementation(runSaga: RunSagaFunc
|
|
|
13
13
|
* @param runSaga - The function to run a saga outside the usual Redux flow.
|
|
14
14
|
* @returns The implementation of the `updateSnapState` hook.
|
|
15
15
|
*/
|
|
16
|
-
export declare function getUpdateSnapStateMethodImplementation(runSaga: RunSagaFunction): (_snapId: string, newState: Record<string, Json>, encrypted?: boolean | undefined) => void
|
|
16
|
+
export declare function getUpdateSnapStateMethodImplementation(runSaga: RunSagaFunction): (_snapId: string, newState: Record<string, Json>, encrypted?: boolean | undefined) => Promise<void>;
|
|
17
17
|
/**
|
|
18
18
|
* Get the implementation of the `clearSnapState` hook.
|
|
19
19
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.d.mts","sourceRoot":"","sources":["../../../src/methods/hooks/state.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAI5C,OAAO,KAAK,EAAE,eAAe,EAAE,8BAAoB;AAsBnD;;;;;GAKG;AACH,wBAAgB,mCAAmC,CAAC,OAAO,EAAE,eAAe,6DAI3E;AAqBD;;;;;GAKG;AACH,wBAAgB,sCAAsC,CACpD,OAAO,EAAE,eAAe,
|
|
1
|
+
{"version":3,"file":"state.d.mts","sourceRoot":"","sources":["../../../src/methods/hooks/state.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAI5C,OAAO,KAAK,EAAE,eAAe,EAAE,8BAAoB;AAsBnD;;;;;GAKG;AACH,wBAAgB,mCAAmC,CAAC,OAAO,EAAE,eAAe,6DAI3E;AAqBD;;;;;GAKG;AACH,wBAAgB,sCAAsC,CACpD,OAAO,EAAE,eAAe,uGAKzB;AAkBD;;;;;GAKG;AACH,wBAAgB,qCAAqC,CACnD,OAAO,EAAE,eAAe,uEAKzB"}
|
|
@@ -48,7 +48,7 @@ function* updateSnapStateImplementation(_snapId, newState, encrypted = true) {
|
|
|
48
48
|
* @returns The implementation of the `updateSnapState` hook.
|
|
49
49
|
*/
|
|
50
50
|
export function getUpdateSnapStateMethodImplementation(runSaga) {
|
|
51
|
-
return (...args) => {
|
|
51
|
+
return async (...args) => {
|
|
52
52
|
runSaga(updateSnapStateImplementation, ...args).result();
|
|
53
53
|
};
|
|
54
54
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.mjs","sourceRoot":"","sources":["../../../src/methods/hooks/state.ts"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AAC,CAAC;AACJ,CAAC","sourcesContent":["import { parseJson } from '@metamask/snaps-utils';\nimport type { Json } from '@metamask/utils';\nimport type { SagaIterator } from 'redux-saga';\nimport { put, select } from 'redux-saga/effects';\n\nimport type { RunSagaFunction } from '../../store';\nimport { clearState, getState, setState } from '../../store';\n\n/**\n * Get the Snap state from the store.\n *\n * @param _snapId - The ID of the Snap to get the state for. This is ignored\n * because the simulator only supports one Snap.\n * @param encrypted - Whether to get the encrypted or unencrypted state.\n * Defaults to encrypted state.\n * @returns The state of the Snap.\n * @yields Selects the state from the store.\n */\nfunction* getSnapStateImplementation(\n _snapId: string,\n encrypted = true,\n): SagaIterator<string> {\n const state = yield select(getState(encrypted));\n // TODO: Use actual decryption implementation\n return parseJson(state);\n}\n\n/**\n * Get the implementation of the `getSnapState` hook.\n *\n * @param runSaga - The function to run a saga outside the usual Redux flow.\n * @returns The implementation of the `getSnapState` hook.\n */\nexport function getGetSnapStateMethodImplementation(runSaga: RunSagaFunction) {\n return (...args: Parameters<typeof getSnapStateImplementation>) => {\n return runSaga(getSnapStateImplementation, ...args).result();\n };\n}\n\n/**\n * Update the Snap state in the store.\n *\n * @param _snapId - The ID of the Snap to update the state for. This is ignored\n * because the simulator only supports one Snap.\n * @param newState - The new state.\n * @param encrypted - Whether to update the encrypted or unencrypted state.\n * Defaults to encrypted state.\n * @yields Puts the new state in the store.\n */\nfunction* updateSnapStateImplementation(\n _snapId: string,\n newState: Record<string, Json>,\n encrypted = true,\n): SagaIterator<void> {\n // TODO: Use actual encryption implementation\n yield put(setState({ state: JSON.stringify(newState), encrypted }));\n}\n\n/**\n * Get the implementation of the `updateSnapState` hook.\n *\n * @param runSaga - The function to run a saga outside the usual Redux flow.\n * @returns The implementation of the `updateSnapState` hook.\n */\nexport function getUpdateSnapStateMethodImplementation(\n runSaga: RunSagaFunction,\n) {\n return async (...args: Parameters<typeof updateSnapStateImplementation>) => {\n runSaga(updateSnapStateImplementation, ...args).result();\n };\n}\n\n/**\n * Clear the Snap state in the store.\n *\n * @param _snapId - The ID of the Snap to clear the state for. This is ignored\n * because the simulator only supports one Snap.\n * @param encrypted - Whether to clear the encrypted or unencrypted state.\n * Defaults to encrypted state.\n * @yields Puts the new state in the store.\n */\nfunction* clearSnapStateImplementation(\n _snapId: string,\n encrypted = true,\n): SagaIterator<void> {\n yield put(clearState({ encrypted }));\n}\n\n/**\n * Get the implementation of the `clearSnapState` hook.\n *\n * @param runSaga - The function to run a saga outside the usual Redux flow.\n * @returns The implementation of the `clearSnapState` hook.\n */\nexport function getClearSnapStateMethodImplementation(\n runSaga: RunSagaFunction,\n) {\n return async (...args: Parameters<typeof clearSnapStateImplementation>) => {\n runSaga(clearSnapStateImplementation, ...args).result();\n };\n}\n"]}
|
|
@@ -33,34 +33,25 @@ exports.asyncResolve = asyncResolve;
|
|
|
33
33
|
* @param options - The options.
|
|
34
34
|
* @param options.controllerMessenger - The controller messenger.
|
|
35
35
|
* @param options.hooks - The hooks.
|
|
36
|
-
* @param options.runSaga - The function to run a saga outside the usual Redux
|
|
37
|
-
* flow.
|
|
38
36
|
* @param options.options - The simulation options.
|
|
39
37
|
* @returns The permission specifications for the Snap.
|
|
40
38
|
*/
|
|
41
|
-
function getPermissionSpecifications({ controllerMessenger, hooks,
|
|
39
|
+
function getPermissionSpecifications({ controllerMessenger, hooks, options, }) {
|
|
40
|
+
const { getClientCryptography } = hooks;
|
|
42
41
|
return {
|
|
43
42
|
[chain_agnostic_permission_1.caip25EndowmentBuilder.targetName]: chain_agnostic_permission_1.caip25EndowmentBuilder.specificationBuilder({}),
|
|
44
43
|
...(0, snaps_rpc_methods_1.buildSnapEndowmentSpecifications)(constants_1.EXCLUDED_SNAP_ENDOWMENTS),
|
|
45
44
|
...(0, snaps_rpc_methods_1.buildSnapRestrictedMethodSpecifications)(constants_1.EXCLUDED_SNAP_PERMISSIONS, {
|
|
46
45
|
// Shared hooks.
|
|
47
|
-
|
|
46
|
+
getClientCryptography,
|
|
48
47
|
// Snaps-specific hooks.
|
|
49
|
-
clearSnapState: (0, hooks_1.getClearSnapStateMethodImplementation)(runSaga),
|
|
50
48
|
getPreferences: (0, hooks_1.getGetPreferencesMethodImplementation)(options),
|
|
51
|
-
getSnapState: (0, hooks_1.getGetSnapStateMethodImplementation)(runSaga),
|
|
52
49
|
getUnlockPromise: asyncResolve(true),
|
|
50
|
+
getSnapKeyring: asyncResolve(null),
|
|
53
51
|
// TODO: Allow the user to specify the result of this function.
|
|
54
52
|
isOnPhishingList: resolve(false),
|
|
55
53
|
maybeUpdatePhishingList: asyncResolve(),
|
|
56
|
-
|
|
57
|
-
showInAppNotification: (0, hooks_1.getShowInAppNotificationImplementation)(runSaga),
|
|
58
|
-
showNativeNotification: (0, hooks_1.getShowNativeNotificationImplementation)(runSaga),
|
|
59
|
-
updateSnapState: (0, hooks_1.getUpdateSnapStateMethodImplementation)(runSaga),
|
|
60
|
-
createInterface: (0, hooks_1.getCreateInterfaceImplementation)(controllerMessenger),
|
|
61
|
-
getInterface: (0, hooks_1.getGetInterfaceImplementation)(controllerMessenger),
|
|
62
|
-
setInterfaceDisplayed: (0, hooks_1.getSetInterfaceDisplayedImplementation)(controllerMessenger),
|
|
63
|
-
}),
|
|
54
|
+
}, controllerMessenger),
|
|
64
55
|
};
|
|
65
56
|
}
|
|
66
57
|
exports.getPermissionSpecifications = getPermissionSpecifications;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"specifications.cjs","sourceRoot":"","sources":["../../src/methods/specifications.ts"],"names":[],"mappings":";;;AAAA,mFAA6E;
|
|
1
|
+
{"version":3,"file":"specifications.cjs","sourceRoot":"","sources":["../../src/methods/specifications.ts"],"names":[],"mappings":";;;AAAA,mFAA6E;AAQ7E,mEAIqC;AAErC,uDAA2D;AAE3D,+CAGqB;AACrB,6CAAgE;AAoBhE;;;;;GAKG;AACH,SAAgB,OAAO,CAAC,MAAe;IACrC,OAAO,GAAG,EAAE,CAAC,MAAM,CAAC;AACtB,CAAC;AAFD,0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f,OAAO,WAAW,CAAC,MAAM,CAAC,UAAsB,CAAC,CAAC;YACpD,CAAC;QACH,CAAC;QAED,OAAO,WAAW,CAAC;IACrB,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC;IAExB,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,gCAAkB,EAAE,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;AACjE,CAAC;AAvBD,sCAuBC","sourcesContent":["import { caip25EndowmentBuilder } from '@metamask/chain-agnostic-permission';\nimport type { CryptographicFunctions } from '@metamask/key-tree';\nimport type {\n GenericPermissionController,\n PermissionSpecificationConstraint,\n PermissionSpecificationMap,\n} from '@metamask/permission-controller';\nimport type { RestrictedMethodMessenger } from '@metamask/snaps-rpc-methods';\nimport {\n endowmentPermissionBuilders,\n buildSnapEndowmentSpecifications,\n buildSnapRestrictedMethodSpecifications,\n} from '@metamask/snaps-rpc-methods';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { DEFAULT_ENDOWMENTS } from '@metamask/snaps-utils';\n\nimport {\n EXCLUDED_SNAP_ENDOWMENTS,\n EXCLUDED_SNAP_PERMISSIONS,\n} from './constants';\nimport { getGetPreferencesMethodImplementation } from './hooks';\nimport type { RootControllerMessenger } from '../controllers';\nimport type { SimulationOptions } from '../options';\n\nexport type PermissionSpecificationsHooks = {\n /**\n * Get the cryptographic functions to use for the client. This may return an\n * empty object to fall back to the default cryptographic functions.\n *\n * @returns The cryptographic functions to use for the client.\n */\n getClientCryptography: () => CryptographicFunctions;\n};\n\nexport type GetPermissionSpecificationsOptions = {\n controllerMessenger: RootControllerMessenger;\n hooks: PermissionSpecificationsHooks;\n options: SimulationOptions;\n};\n\n/**\n * Get a function which resolves with the specified result.\n *\n * @param result - The result to return.\n * @returns The function implementation.\n */\nexport function resolve(result: unknown) {\n return () => result;\n}\n\n/**\n * Get a function which resolves with the specified result.\n *\n * @param result - The result to return. If not specified, the function will\n * resolve with `undefined`.\n * @returns The function implementation.\n */\nexport function asyncResolve<Type>(result?: Type) {\n return async () => result;\n}\n\n/**\n * Get the permission specifications for the Snap.\n *\n * @param options - The options.\n * @param options.controllerMessenger - The controller messenger.\n * @param options.hooks - The hooks.\n * @param options.options - The simulation options.\n * @returns The permission specifications for the Snap.\n */\nexport function getPermissionSpecifications({\n controllerMessenger,\n hooks,\n options,\n}: GetPermissionSpecificationsOptions): PermissionSpecificationMap<PermissionSpecificationConstraint> {\n const { getClientCryptography } = hooks;\n return {\n [caip25EndowmentBuilder.targetName]:\n caip25EndowmentBuilder.specificationBuilder({}),\n ...buildSnapEndowmentSpecifications(EXCLUDED_SNAP_ENDOWMENTS),\n ...buildSnapRestrictedMethodSpecifications(\n EXCLUDED_SNAP_PERMISSIONS,\n {\n // Shared hooks.\n getClientCryptography,\n\n // Snaps-specific hooks.\n getPreferences: getGetPreferencesMethodImplementation(options),\n getUnlockPromise: asyncResolve(true),\n getSnapKeyring: asyncResolve(null),\n\n // TODO: Allow the user to specify the result of this function.\n isOnPhishingList: resolve(false),\n\n maybeUpdatePhishingList: asyncResolve(),\n },\n controllerMessenger as RestrictedMethodMessenger,\n ),\n };\n}\n\n/**\n * Get the endowments for the Snap.\n *\n * @param permissionController - The permission controller.\n * @param snapId - The ID of the Snap.\n * @returns The endowments for the Snap.\n */\nexport async function getEndowments(\n permissionController: GenericPermissionController,\n snapId: SnapId,\n) {\n const allEndowments = await Object.keys(endowmentPermissionBuilders).reduce<\n Promise<string[]>\n >(async (promise, permissionName) => {\n const accumulator = await promise;\n if (permissionController.hasPermission(snapId, permissionName)) {\n const endowments = await permissionController.getEndowments(\n snapId,\n permissionName,\n );\n\n if (endowments) {\n return accumulator.concat(endowments as string[]);\n }\n }\n\n return accumulator;\n }, Promise.resolve([]));\n\n return [...new Set([...DEFAULT_ENDOWMENTS, ...allEndowments])];\n}\n"]}
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { CryptographicFunctions } from "@metamask/key-tree";
|
|
2
|
+
import type { GenericPermissionController, PermissionSpecificationConstraint, PermissionSpecificationMap } from "@metamask/permission-controller";
|
|
2
3
|
import type { SnapId } from "@metamask/snaps-sdk";
|
|
3
4
|
import type { RootControllerMessenger } from "../controllers.cjs";
|
|
4
5
|
import type { SimulationOptions } from "../options.cjs";
|
|
5
|
-
import type { RunSagaFunction } from "../store/index.cjs";
|
|
6
6
|
export type PermissionSpecificationsHooks = {
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* Get the cryptographic functions to use for the client. This may return an
|
|
9
|
+
* empty object to fall back to the default cryptographic functions.
|
|
9
10
|
*
|
|
10
|
-
* @returns The
|
|
11
|
+
* @returns The cryptographic functions to use for the client.
|
|
11
12
|
*/
|
|
12
|
-
|
|
13
|
+
getClientCryptography: () => CryptographicFunctions;
|
|
13
14
|
};
|
|
14
15
|
export type GetPermissionSpecificationsOptions = {
|
|
15
16
|
controllerMessenger: RootControllerMessenger;
|
|
16
17
|
hooks: PermissionSpecificationsHooks;
|
|
17
|
-
runSaga: RunSagaFunction;
|
|
18
18
|
options: SimulationOptions;
|
|
19
19
|
};
|
|
20
20
|
/**
|
|
@@ -38,20 +38,10 @@ export declare function asyncResolve<Type>(result?: Type): () => Promise<Type |
|
|
|
38
38
|
* @param options - The options.
|
|
39
39
|
* @param options.controllerMessenger - The controller messenger.
|
|
40
40
|
* @param options.hooks - The hooks.
|
|
41
|
-
* @param options.runSaga - The function to run a saga outside the usual Redux
|
|
42
|
-
* flow.
|
|
43
41
|
* @param options.options - The simulation options.
|
|
44
42
|
* @returns The permission specifications for the Snap.
|
|
45
43
|
*/
|
|
46
|
-
export declare function getPermissionSpecifications({ controllerMessenger, hooks,
|
|
47
|
-
"endowment:caip25": {
|
|
48
|
-
permissionType: import("@metamask/permission-controller").PermissionType.Endowment;
|
|
49
|
-
targetName: "endowment:caip25";
|
|
50
|
-
endowmentGetter: (_options?: import("@metamask/permission-controller").EndowmentGetterParams | undefined) => null;
|
|
51
|
-
validator: import("@metamask/permission-controller").PermissionValidatorConstraint;
|
|
52
|
-
allowedCaveats: readonly [string, ...string[]] | null;
|
|
53
|
-
};
|
|
54
|
-
};
|
|
44
|
+
export declare function getPermissionSpecifications({ controllerMessenger, hooks, options, }: GetPermissionSpecificationsOptions): PermissionSpecificationMap<PermissionSpecificationConstraint>;
|
|
55
45
|
/**
|
|
56
46
|
* Get the endowments for the Snap.
|
|
57
47
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"specifications.d.cts","sourceRoot":"","sources":["../../src/methods/specifications.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"specifications.d.cts","sourceRoot":"","sources":["../../src/methods/specifications.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,2BAA2B;AACjE,OAAO,KAAK,EACV,2BAA2B,EAC3B,iCAAiC,EACjC,0BAA0B,EAC3B,wCAAwC;AAOzC,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAQlD,OAAO,KAAK,EAAE,uBAAuB,EAAE,2BAAuB;AAC9D,OAAO,KAAK,EAAE,iBAAiB,EAAE,uBAAmB;AAEpD,MAAM,MAAM,6BAA6B,GAAG;IAC1C;;;;;OAKG;IACH,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;CACrD,CAAC;AAEF,MAAM,MAAM,kCAAkC,GAAG;IAC/C,mBAAmB,EAAE,uBAAuB,CAAC;IAC7C,KAAK,EAAE,6BAA6B,CAAC;IACrC,OAAO,EAAE,iBAAiB,CAAC;CAC5B,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,OAAO,iBAEtC;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,IAAI,mCAE/C;AAED;;;;;;;;GAQG;AACH,wBAAgB,2BAA2B,CAAC,EAC1C,mBAAmB,EACnB,KAAK,EACL,OAAO,GACR,EAAE,kCAAkC,GAAG,0BAA0B,CAAC,iCAAiC,CAAC,CAyBpG;AAED;;;;;;GAMG;AACH,wBAAsB,aAAa,CACjC,oBAAoB,EAAE,2BAA2B,EACjD,MAAM,EAAE,MAAM,qBAqBf"}
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { CryptographicFunctions } from "@metamask/key-tree";
|
|
2
|
+
import type { GenericPermissionController, PermissionSpecificationConstraint, PermissionSpecificationMap } from "@metamask/permission-controller";
|
|
2
3
|
import type { SnapId } from "@metamask/snaps-sdk";
|
|
3
4
|
import type { RootControllerMessenger } from "../controllers.mjs";
|
|
4
5
|
import type { SimulationOptions } from "../options.mjs";
|
|
5
|
-
import type { RunSagaFunction } from "../store/index.mjs";
|
|
6
6
|
export type PermissionSpecificationsHooks = {
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* Get the cryptographic functions to use for the client. This may return an
|
|
9
|
+
* empty object to fall back to the default cryptographic functions.
|
|
9
10
|
*
|
|
10
|
-
* @returns The
|
|
11
|
+
* @returns The cryptographic functions to use for the client.
|
|
11
12
|
*/
|
|
12
|
-
|
|
13
|
+
getClientCryptography: () => CryptographicFunctions;
|
|
13
14
|
};
|
|
14
15
|
export type GetPermissionSpecificationsOptions = {
|
|
15
16
|
controllerMessenger: RootControllerMessenger;
|
|
16
17
|
hooks: PermissionSpecificationsHooks;
|
|
17
|
-
runSaga: RunSagaFunction;
|
|
18
18
|
options: SimulationOptions;
|
|
19
19
|
};
|
|
20
20
|
/**
|
|
@@ -38,20 +38,10 @@ export declare function asyncResolve<Type>(result?: Type): () => Promise<Type |
|
|
|
38
38
|
* @param options - The options.
|
|
39
39
|
* @param options.controllerMessenger - The controller messenger.
|
|
40
40
|
* @param options.hooks - The hooks.
|
|
41
|
-
* @param options.runSaga - The function to run a saga outside the usual Redux
|
|
42
|
-
* flow.
|
|
43
41
|
* @param options.options - The simulation options.
|
|
44
42
|
* @returns The permission specifications for the Snap.
|
|
45
43
|
*/
|
|
46
|
-
export declare function getPermissionSpecifications({ controllerMessenger, hooks,
|
|
47
|
-
"endowment:caip25": {
|
|
48
|
-
permissionType: import("@metamask/permission-controller").PermissionType.Endowment;
|
|
49
|
-
targetName: "endowment:caip25";
|
|
50
|
-
endowmentGetter: (_options?: import("@metamask/permission-controller").EndowmentGetterParams | undefined) => null;
|
|
51
|
-
validator: import("@metamask/permission-controller").PermissionValidatorConstraint;
|
|
52
|
-
allowedCaveats: readonly [string, ...string[]] | null;
|
|
53
|
-
};
|
|
54
|
-
};
|
|
44
|
+
export declare function getPermissionSpecifications({ controllerMessenger, hooks, options, }: GetPermissionSpecificationsOptions): PermissionSpecificationMap<PermissionSpecificationConstraint>;
|
|
55
45
|
/**
|
|
56
46
|
* Get the endowments for the Snap.
|
|
57
47
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"specifications.d.mts","sourceRoot":"","sources":["../../src/methods/specifications.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"specifications.d.mts","sourceRoot":"","sources":["../../src/methods/specifications.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,2BAA2B;AACjE,OAAO,KAAK,EACV,2BAA2B,EAC3B,iCAAiC,EACjC,0BAA0B,EAC3B,wCAAwC;AAOzC,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAQlD,OAAO,KAAK,EAAE,uBAAuB,EAAE,2BAAuB;AAC9D,OAAO,KAAK,EAAE,iBAAiB,EAAE,uBAAmB;AAEpD,MAAM,MAAM,6BAA6B,GAAG;IAC1C;;;;;OAKG;IACH,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;CACrD,CAAC;AAEF,MAAM,MAAM,kCAAkC,GAAG;IAC/C,mBAAmB,EAAE,uBAAuB,CAAC;IAC7C,KAAK,EAAE,6BAA6B,CAAC;IACrC,OAAO,EAAE,iBAAiB,CAAC;CAC5B,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,OAAO,iBAEtC;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,IAAI,mCAE/C;AAED;;;;;;;;GAQG;AACH,wBAAgB,2BAA2B,CAAC,EAC1C,mBAAmB,EACnB,KAAK,EACL,OAAO,GACR,EAAE,kCAAkC,GAAG,0BAA0B,CAAC,iCAAiC,CAAC,CAyBpG;AAED;;;;;;GAMG;AACH,wBAAsB,aAAa,CACjC,oBAAoB,EAAE,2BAA2B,EACjD,MAAM,EAAE,MAAM,qBAqBf"}
|
|
@@ -2,7 +2,7 @@ import { caip25EndowmentBuilder } from "@metamask/chain-agnostic-permission";
|
|
|
2
2
|
import { endowmentPermissionBuilders, buildSnapEndowmentSpecifications, buildSnapRestrictedMethodSpecifications } from "@metamask/snaps-rpc-methods";
|
|
3
3
|
import { DEFAULT_ENDOWMENTS } from "@metamask/snaps-utils";
|
|
4
4
|
import { EXCLUDED_SNAP_ENDOWMENTS, EXCLUDED_SNAP_PERMISSIONS } from "./constants.mjs";
|
|
5
|
-
import { getGetPreferencesMethodImplementation
|
|
5
|
+
import { getGetPreferencesMethodImplementation } from "./hooks/index.mjs";
|
|
6
6
|
/**
|
|
7
7
|
* Get a function which resolves with the specified result.
|
|
8
8
|
*
|
|
@@ -28,34 +28,25 @@ export function asyncResolve(result) {
|
|
|
28
28
|
* @param options - The options.
|
|
29
29
|
* @param options.controllerMessenger - The controller messenger.
|
|
30
30
|
* @param options.hooks - The hooks.
|
|
31
|
-
* @param options.runSaga - The function to run a saga outside the usual Redux
|
|
32
|
-
* flow.
|
|
33
31
|
* @param options.options - The simulation options.
|
|
34
32
|
* @returns The permission specifications for the Snap.
|
|
35
33
|
*/
|
|
36
|
-
export function getPermissionSpecifications({ controllerMessenger, hooks,
|
|
34
|
+
export function getPermissionSpecifications({ controllerMessenger, hooks, options, }) {
|
|
35
|
+
const { getClientCryptography } = hooks;
|
|
37
36
|
return {
|
|
38
37
|
[caip25EndowmentBuilder.targetName]: caip25EndowmentBuilder.specificationBuilder({}),
|
|
39
38
|
...buildSnapEndowmentSpecifications(EXCLUDED_SNAP_ENDOWMENTS),
|
|
40
39
|
...buildSnapRestrictedMethodSpecifications(EXCLUDED_SNAP_PERMISSIONS, {
|
|
41
40
|
// Shared hooks.
|
|
42
|
-
|
|
41
|
+
getClientCryptography,
|
|
43
42
|
// Snaps-specific hooks.
|
|
44
|
-
clearSnapState: getClearSnapStateMethodImplementation(runSaga),
|
|
45
43
|
getPreferences: getGetPreferencesMethodImplementation(options),
|
|
46
|
-
getSnapState: getGetSnapStateMethodImplementation(runSaga),
|
|
47
44
|
getUnlockPromise: asyncResolve(true),
|
|
45
|
+
getSnapKeyring: asyncResolve(null),
|
|
48
46
|
// TODO: Allow the user to specify the result of this function.
|
|
49
47
|
isOnPhishingList: resolve(false),
|
|
50
48
|
maybeUpdatePhishingList: asyncResolve(),
|
|
51
|
-
|
|
52
|
-
showInAppNotification: getShowInAppNotificationImplementation(runSaga),
|
|
53
|
-
showNativeNotification: getShowNativeNotificationImplementation(runSaga),
|
|
54
|
-
updateSnapState: getUpdateSnapStateMethodImplementation(runSaga),
|
|
55
|
-
createInterface: getCreateInterfaceImplementation(controllerMessenger),
|
|
56
|
-
getInterface: getGetInterfaceImplementation(controllerMessenger),
|
|
57
|
-
setInterfaceDisplayed: getSetInterfaceDisplayedImplementation(controllerMessenger),
|
|
58
|
-
}),
|
|
49
|
+
}, controllerMessenger),
|
|
59
50
|
};
|
|
60
51
|
}
|
|
61
52
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"specifications.mjs","sourceRoot":"","sources":["../../src/methods/specifications.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,4CAA4C;
|
|
1
|
+
{"version":3,"file":"specifications.mjs","sourceRoot":"","sources":["../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AAM,aAAa,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC,MAAM,CAEzE,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,EAAE;QAClC,MAAM,WAAW,GAAG,MAAM,OAAO,CAAC;QAClC,IAAI,oBAAoB,CAAC,aAAa,CAAC,MAAM,EAAE,cAAc,CAAC,EAAE,CAAC;YAC/D,MAAM,UAAU,GAAG,MAAM,oBAAoB,CAAC,aAAa,CACzD,MAAM,EACN,cAAc,CACf,CAAC;YAEF,IAAI,UAAU,EAAE,CAAC;gBACf,OAAO,WAAW,CAAC,MAAM,CAAC,UAAsB,CAAC,CAAC;YACpD,CAAC;QACH,CAAC;QAED,OAAO,WAAW,CAAC;IACrB,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC;IAExB,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,kBAAkB,EAAE,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;AACjE,CAAC","sourcesContent":["import { caip25EndowmentBuilder } from '@metamask/chain-agnostic-permission';\nimport type { CryptographicFunctions } from '@metamask/key-tree';\nimport type {\n GenericPermissionController,\n PermissionSpecificationConstraint,\n PermissionSpecificationMap,\n} from '@metamask/permission-controller';\nimport type { RestrictedMethodMessenger } from '@metamask/snaps-rpc-methods';\nimport {\n endowmentPermissionBuilders,\n buildSnapEndowmentSpecifications,\n buildSnapRestrictedMethodSpecifications,\n} from '@metamask/snaps-rpc-methods';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { DEFAULT_ENDOWMENTS } from '@metamask/snaps-utils';\n\nimport {\n EXCLUDED_SNAP_ENDOWMENTS,\n EXCLUDED_SNAP_PERMISSIONS,\n} from './constants';\nimport { getGetPreferencesMethodImplementation } from './hooks';\nimport type { RootControllerMessenger } from '../controllers';\nimport type { SimulationOptions } from '../options';\n\nexport type PermissionSpecificationsHooks = {\n /**\n * Get the cryptographic functions to use for the client. This may return an\n * empty object to fall back to the default cryptographic functions.\n *\n * @returns The cryptographic functions to use for the client.\n */\n getClientCryptography: () => CryptographicFunctions;\n};\n\nexport type GetPermissionSpecificationsOptions = {\n controllerMessenger: RootControllerMessenger;\n hooks: PermissionSpecificationsHooks;\n options: SimulationOptions;\n};\n\n/**\n * Get a function which resolves with the specified result.\n *\n * @param result - The result to return.\n * @returns The function implementation.\n */\nexport function resolve(result: unknown) {\n return () => result;\n}\n\n/**\n * Get a function which resolves with the specified result.\n *\n * @param result - The result to return. If not specified, the function will\n * resolve with `undefined`.\n * @returns The function implementation.\n */\nexport function asyncResolve<Type>(result?: Type) {\n return async () => result;\n}\n\n/**\n * Get the permission specifications for the Snap.\n *\n * @param options - The options.\n * @param options.controllerMessenger - The controller messenger.\n * @param options.hooks - The hooks.\n * @param options.options - The simulation options.\n * @returns The permission specifications for the Snap.\n */\nexport function getPermissionSpecifications({\n controllerMessenger,\n hooks,\n options,\n}: GetPermissionSpecificationsOptions): PermissionSpecificationMap<PermissionSpecificationConstraint> {\n const { getClientCryptography } = hooks;\n return {\n [caip25EndowmentBuilder.targetName]:\n caip25EndowmentBuilder.specificationBuilder({}),\n ...buildSnapEndowmentSpecifications(EXCLUDED_SNAP_ENDOWMENTS),\n ...buildSnapRestrictedMethodSpecifications(\n EXCLUDED_SNAP_PERMISSIONS,\n {\n // Shared hooks.\n getClientCryptography,\n\n // Snaps-specific hooks.\n getPreferences: getGetPreferencesMethodImplementation(options),\n getUnlockPromise: asyncResolve(true),\n getSnapKeyring: asyncResolve(null),\n\n // TODO: Allow the user to specify the result of this function.\n isOnPhishingList: resolve(false),\n\n maybeUpdatePhishingList: asyncResolve(),\n },\n controllerMessenger as RestrictedMethodMessenger,\n ),\n };\n}\n\n/**\n * Get the endowments for the Snap.\n *\n * @param permissionController - The permission controller.\n * @param snapId - The ID of the Snap.\n * @returns The endowments for the Snap.\n */\nexport async function getEndowments(\n permissionController: GenericPermissionController,\n snapId: SnapId,\n) {\n const allEndowments = await Object.keys(endowmentPermissionBuilders).reduce<\n Promise<string[]>\n >(async (promise, permissionName) => {\n const accumulator = await promise;\n if (permissionController.hasPermission(snapId, permissionName)) {\n const endowments = await permissionController.getEndowments(\n snapId,\n permissionName,\n );\n\n if (endowments) {\n return accumulator.concat(endowments as string[]);\n }\n }\n\n return accumulator;\n }, Promise.resolve([]));\n\n return [...new Set([...DEFAULT_ENDOWMENTS, ...allEndowments])];\n}\n"]}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createJsonRpcEngine = void 0;
|
|
4
4
|
const json_rpc_engine_1 = require("@metamask/json-rpc-engine");
|
|
5
|
+
const permission_controller_1 = require("@metamask/permission-controller");
|
|
5
6
|
const snaps_rpc_methods_1 = require("@metamask/snaps-rpc-methods");
|
|
6
7
|
const internal_methods_1 = require("./internal-methods/index.cjs");
|
|
7
8
|
const mock_1 = require("./mock.cjs");
|
|
@@ -14,23 +15,26 @@ const provider_1 = require("./provider.cjs");
|
|
|
14
15
|
* well as Snap-specific requests.
|
|
15
16
|
*
|
|
16
17
|
* @param options - The options to use when creating the engine.
|
|
18
|
+
* @param options.snapId - The Snap ID.
|
|
19
|
+
* @param options.messenger - The messenger.
|
|
17
20
|
* @param options.store - The Redux store to use.
|
|
18
21
|
* @param options.restrictedHooks - Any hooks used by the middleware handlers.
|
|
19
22
|
* @param options.permittedHooks - Any hooks used by the middleware handlers.
|
|
20
|
-
* @param options.permissionMiddleware - The permission middleware to use.
|
|
21
23
|
* @param options.multichainHooks - Hooks used by the multichain middleware.
|
|
22
24
|
* @param options.isMultichain - Whether the engine is used for multichain.
|
|
23
25
|
* @returns A JSON-RPC engine.
|
|
24
26
|
*/
|
|
25
|
-
function createJsonRpcEngine({ store, restrictedHooks, permittedHooks,
|
|
27
|
+
function createJsonRpcEngine({ snapId, messenger, store, restrictedHooks, permittedHooks, multichainHooks, isMultichain, }) {
|
|
26
28
|
const engine = new json_rpc_engine_1.JsonRpcEngine();
|
|
29
|
+
engine.push((0, json_rpc_engine_1.createOriginMiddleware)(snapId));
|
|
27
30
|
engine.push((0, multichain_1.createMultichainMiddleware)(isMultichain, multichainHooks));
|
|
28
31
|
engine.push((0, mock_1.createMockMiddleware)(store));
|
|
29
32
|
// The hooks here do not match the hooks used by the clients, so this
|
|
30
33
|
// middleware should not be used outside of the simulation environment.
|
|
31
34
|
engine.push((0, internal_methods_1.createInternalMethodsMiddleware)(restrictedHooks));
|
|
32
|
-
|
|
33
|
-
engine.push(
|
|
35
|
+
// @ts-expect-error Hooks type mismatch.
|
|
36
|
+
engine.push((0, snaps_rpc_methods_1.createSnapsMethodMiddleware)(true, permittedHooks, messenger));
|
|
37
|
+
engine.push((0, permission_controller_1.createPermissionMiddleware)({ messenger, origin: snapId }));
|
|
34
38
|
engine.push((0, provider_1.createProviderMiddleware)(store));
|
|
35
39
|
return engine;
|
|
36
40
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine.cjs","sourceRoot":"","sources":["../../src/middleware/engine.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"engine.cjs","sourceRoot":"","sources":["../../src/middleware/engine.ts"],"names":[],"mappings":";;;AAAA,+DAGmC;AACnC,2EAA6E;AAC7E,mEAA0E;AAG1E,mEAAqE;AACrE,qCAA8C;AAC9C,uDAA0D;AAC1D,6CAAsD;AAoBtD;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,mBAAmB,CAAC,EAClC,MAAM,EACN,SAAS,EACT,KAAK,EACL,eAAe,EACf,cAAc,EACd,eAAe,EACf,YAAY,GACe;IAC3B,MAAM,MAAM,GAAG,IAAI,+BAAa,EAAE,CAAC;IAEnC,MAAM,CAAC,IAAI,CAAC,IAAA,wCAAsB,EAAC,MAAM,CAAC,CAAC,CAAC;IAE5C,MAAM,CAAC,IAAI,CAAC,IAAA,uCAA0B,EAAC,YAAY,EAAE,eAAe,CAAC,CAAC,CAAC;IAEvE,MAAM,CAAC,IAAI,CAAC,IAAA,2BAAoB,EAAC,KAAK,CAAC,CAAC,CAAC;IAEzC,qEAAqE;IACrE,uEAAuE;IACvE,MAAM,CAAC,IAAI,CAAC,IAAA,kDAA+B,EAAC,eAAe,CAAC,CAAC,CAAC;IAE9D,wCAAwC;IACxC,MAAM,CAAC,IAAI,CAAC,IAAA,+CAA2B,EAAC,IAAI,EAAE,cAAc,EAAE,SAAS,CAAC,CAAC,CAAC;IAE1E,MAAM,CAAC,IAAI,CAAC,IAAA,kDAA0B,EAAC,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;IACvE,MAAM,CAAC,IAAI,CAAC,IAAA,mCAAwB,EAAC,KAAK,CAAC,CAAC,CAAC;IAE7C,OAAO,MAAM,CAAC;AAChB,CAAC;AA5BD,kDA4BC","sourcesContent":["import {\n JsonRpcEngine,\n createOriginMiddleware,\n} from '@metamask/json-rpc-engine';\nimport { createPermissionMiddleware } from '@metamask/permission-controller';\nimport { createSnapsMethodMiddleware } from '@metamask/snaps-rpc-methods';\nimport type { SnapId } from '@metamask/snaps-sdk';\n\nimport { createInternalMethodsMiddleware } from './internal-methods';\nimport { createMockMiddleware } from './mock';\nimport { createMultichainMiddleware } from './multichain';\nimport { createProviderMiddleware } from './provider';\nimport type { RootControllerMessenger } from '../controllers';\nimport type {\n MultichainMiddlewareHooks,\n PermittedMiddlewareHooks,\n RestrictedMiddlewareHooks,\n} from '../simulation';\nimport type { Store } from '../store';\n\nexport type CreateJsonRpcEngineOptions = {\n snapId: SnapId;\n messenger: RootControllerMessenger;\n store: Store;\n restrictedHooks: RestrictedMiddlewareHooks;\n permittedHooks: PermittedMiddlewareHooks;\n multichainHooks: MultichainMiddlewareHooks;\n endpoint?: string;\n isMultichain: boolean;\n};\n\n/**\n * Create a JSON-RPC engine for use in a simulated environment. This engine\n * should be used to handle all JSON-RPC requests. It is set up to handle\n * requests that would normally be handled internally by the MetaMask client, as\n * well as Snap-specific requests.\n *\n * @param options - The options to use when creating the engine.\n * @param options.snapId - The Snap ID.\n * @param options.messenger - The messenger.\n * @param options.store - The Redux store to use.\n * @param options.restrictedHooks - Any hooks used by the middleware handlers.\n * @param options.permittedHooks - Any hooks used by the middleware handlers.\n * @param options.multichainHooks - Hooks used by the multichain middleware.\n * @param options.isMultichain - Whether the engine is used for multichain.\n * @returns A JSON-RPC engine.\n */\nexport function createJsonRpcEngine({\n snapId,\n messenger,\n store,\n restrictedHooks,\n permittedHooks,\n multichainHooks,\n isMultichain,\n}: CreateJsonRpcEngineOptions) {\n const engine = new JsonRpcEngine();\n\n engine.push(createOriginMiddleware(snapId));\n\n engine.push(createMultichainMiddleware(isMultichain, multichainHooks));\n\n engine.push(createMockMiddleware(store));\n\n // The hooks here do not match the hooks used by the clients, so this\n // middleware should not be used outside of the simulation environment.\n engine.push(createInternalMethodsMiddleware(restrictedHooks));\n\n // @ts-expect-error Hooks type mismatch.\n engine.push(createSnapsMethodMiddleware(true, permittedHooks, messenger));\n\n engine.push(createPermissionMiddleware({ messenger, origin: snapId }));\n engine.push(createProviderMiddleware(store));\n\n return engine;\n}\n"]}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import type { JsonRpcMiddleware } from "@metamask/json-rpc-engine";
|
|
2
1
|
import { JsonRpcEngine } from "@metamask/json-rpc-engine";
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
2
|
+
import type { SnapId } from "@metamask/snaps-sdk";
|
|
3
|
+
import type { RootControllerMessenger } from "../controllers.cjs";
|
|
5
4
|
import type { MultichainMiddlewareHooks, PermittedMiddlewareHooks, RestrictedMiddlewareHooks } from "../simulation.cjs";
|
|
6
5
|
import type { Store } from "../store/index.cjs";
|
|
7
6
|
export type CreateJsonRpcEngineOptions = {
|
|
7
|
+
snapId: SnapId;
|
|
8
|
+
messenger: RootControllerMessenger;
|
|
8
9
|
store: Store;
|
|
9
10
|
restrictedHooks: RestrictedMiddlewareHooks;
|
|
10
11
|
permittedHooks: PermittedMiddlewareHooks;
|
|
11
12
|
multichainHooks: MultichainMiddlewareHooks;
|
|
12
|
-
permissionMiddleware: JsonRpcMiddleware<RestrictedMethodParameters, Json>;
|
|
13
13
|
endpoint?: string;
|
|
14
14
|
isMultichain: boolean;
|
|
15
15
|
};
|
|
@@ -20,13 +20,14 @@ export type CreateJsonRpcEngineOptions = {
|
|
|
20
20
|
* well as Snap-specific requests.
|
|
21
21
|
*
|
|
22
22
|
* @param options - The options to use when creating the engine.
|
|
23
|
+
* @param options.snapId - The Snap ID.
|
|
24
|
+
* @param options.messenger - The messenger.
|
|
23
25
|
* @param options.store - The Redux store to use.
|
|
24
26
|
* @param options.restrictedHooks - Any hooks used by the middleware handlers.
|
|
25
27
|
* @param options.permittedHooks - Any hooks used by the middleware handlers.
|
|
26
|
-
* @param options.permissionMiddleware - The permission middleware to use.
|
|
27
28
|
* @param options.multichainHooks - Hooks used by the multichain middleware.
|
|
28
29
|
* @param options.isMultichain - Whether the engine is used for multichain.
|
|
29
30
|
* @returns A JSON-RPC engine.
|
|
30
31
|
*/
|
|
31
|
-
export declare function createJsonRpcEngine({ store, restrictedHooks, permittedHooks,
|
|
32
|
+
export declare function createJsonRpcEngine({ snapId, messenger, store, restrictedHooks, permittedHooks, multichainHooks, isMultichain, }: CreateJsonRpcEngineOptions): JsonRpcEngine;
|
|
32
33
|
//# sourceMappingURL=engine.d.cts.map
|