@metamask-previews/permission-log-controller 0.0.0-preview.3fbb6b41
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 +9 -0
- package/LICENSE +18 -0
- package/README.md +15 -0
- package/dist/PermissionLogController.d.ts +167 -0
- package/dist/PermissionLogController.d.ts.map +1 -0
- package/dist/PermissionLogController.js +339 -0
- package/dist/PermissionLogController.js.map +1 -0
- package/dist/enums.d.ts +14 -0
- package/dist/enums.d.ts.map +1 -0
- package/dist/enums.js +21 -0
- package/dist/enums.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/package.json +58 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
All notable changes to this project will be documented in this file.
|
|
3
|
+
|
|
4
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
5
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
|
+
|
|
7
|
+
## [Unreleased]
|
|
8
|
+
|
|
9
|
+
[Unreleased]: https://github.com/MetaMask/core/
|
package/LICENSE
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Copyright ConsenSys Software Inc. 2022. All rights reserved.
|
|
2
|
+
|
|
3
|
+
You acknowledge and agree that ConsenSys Software Inc. (“ConsenSys”) (or ConsenSys’s licensors) own all legal right, title and interest in and to the work, software, application, source code, documentation and any other documents in this repository (collectively, the “Program”), including any intellectual property rights which subsist in the Program (whether those rights happen to be registered or not, and wherever in the world those rights may exist), whether in source code or any other form.
|
|
4
|
+
|
|
5
|
+
Subject to the limited license below, you may not (and you may not permit anyone else to) distribute, publish, copy, modify, merge, combine with another program, create derivative works of, reverse engineer, decompile or otherwise attempt to extract the source code of, the Program or any part thereof, except that you may contribute to this repository.
|
|
6
|
+
|
|
7
|
+
You are granted a non-exclusive, non-transferable, non-sublicensable license to distribute, publish, copy, modify, merge, combine with another program or create derivative works of the Program (such resulting program, collectively, the “Resulting Program”) solely for Non-Commercial Use as long as you:
|
|
8
|
+
1. give prominent notice (“Notice”) with each copy of the Resulting Program that the Program is used in the Resulting Program and that the Program is the copyright of ConsenSys; and
|
|
9
|
+
2. subject the Resulting Program and any distribution, publication, copy, modification, merger therewith, combination with another program or derivative works thereof to the same Notice requirement and Non-Commercial Use restriction set forth herein.
|
|
10
|
+
|
|
11
|
+
“Non-Commercial Use” means each use as described in clauses (1)-(3) below, as reasonably determined by ConsenSys in its sole discretion:
|
|
12
|
+
1. personal use for research, personal study, private entertainment, hobby projects or amateur pursuits, in each case without any anticipated commercial application;
|
|
13
|
+
2. use by any charitable organization, educational institution, public research organization, public safety or health organization, environmental protection organization or government institution; or
|
|
14
|
+
3. the number of monthly active users of the Resulting Program across all versions thereof and platforms globally do not exceed 10,000 at any time.
|
|
15
|
+
|
|
16
|
+
You will not use any trade mark, service mark, trade name, logo of ConsenSys or any other company or organization in a way that is likely or intended to cause confusion about the owner or authorized user of such marks, names or logos.
|
|
17
|
+
|
|
18
|
+
If you have any questions, comments or interest in pursuing any other use cases, please reach out to us at communications@metamask.io.
|
package/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# `@metamask/permission-log-controller`
|
|
2
|
+
|
|
3
|
+
Controller with middleware for logging requests and responses to restricted and permissions-related methods.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
`yarn add @metamask/permission-log-controller`
|
|
8
|
+
|
|
9
|
+
or
|
|
10
|
+
|
|
11
|
+
`npm install @metamask/permission-log-controller`
|
|
12
|
+
|
|
13
|
+
## Contributing
|
|
14
|
+
|
|
15
|
+
This package is part of a monorepo. Instructions for contributing can be found in the [monorepo README](https://github.com/MetaMask/core#readme).
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { BaseController, type RestrictedControllerMessenger } from '@metamask/base-controller';
|
|
2
|
+
import type { JsonRpcMiddleware } from '@metamask/json-rpc-engine';
|
|
3
|
+
import type { Json, JsonRpcRequest, JsonRpcParams, PendingJsonRpcResponse } from '@metamask/utils';
|
|
4
|
+
import { LOG_METHOD_TYPES } from './enums';
|
|
5
|
+
export declare type JsonRpcRequestWithOrigin<Params extends JsonRpcParams = JsonRpcParams> = JsonRpcRequest<Params> & {
|
|
6
|
+
origin?: string;
|
|
7
|
+
};
|
|
8
|
+
export declare type Caveat = {
|
|
9
|
+
type: string;
|
|
10
|
+
value: string[];
|
|
11
|
+
};
|
|
12
|
+
export declare type Permission = {
|
|
13
|
+
parentCapability: string;
|
|
14
|
+
caveats?: Caveat[];
|
|
15
|
+
};
|
|
16
|
+
export declare type PermissionActivityLog = {
|
|
17
|
+
id: string | number | null;
|
|
18
|
+
method: string;
|
|
19
|
+
methodType: LOG_METHOD_TYPES;
|
|
20
|
+
origin?: string;
|
|
21
|
+
requestTime: number;
|
|
22
|
+
responseTime: number | null;
|
|
23
|
+
success: boolean | null;
|
|
24
|
+
};
|
|
25
|
+
export declare type PermissionName = string;
|
|
26
|
+
export declare type PermissionLog = {
|
|
27
|
+
accounts?: Record<string, number>;
|
|
28
|
+
lastApproved: number;
|
|
29
|
+
};
|
|
30
|
+
export declare type PermissionEntry = Record<PermissionName, PermissionLog>;
|
|
31
|
+
export declare type PermissionOrigin = string;
|
|
32
|
+
export declare type PermissionHistory = Record<PermissionOrigin, PermissionEntry>;
|
|
33
|
+
/**
|
|
34
|
+
*
|
|
35
|
+
* Permission log controller state
|
|
36
|
+
* @property permissionHistory - permission history
|
|
37
|
+
* @property permissionActivityLog - permission activity logs
|
|
38
|
+
*/
|
|
39
|
+
export declare type PermissionLogControllerState = {
|
|
40
|
+
permissionHistory: PermissionHistory;
|
|
41
|
+
permissionActivityLog: PermissionActivityLog[];
|
|
42
|
+
};
|
|
43
|
+
export declare type PermissionLogControllerOptions = {
|
|
44
|
+
restrictedMethods: Set<string>;
|
|
45
|
+
state?: Partial<PermissionLogControllerState>;
|
|
46
|
+
messenger: PermissionLogControllerMessenger;
|
|
47
|
+
};
|
|
48
|
+
export declare type PermissionLogControllerMessenger = RestrictedControllerMessenger<typeof name, never, never, never, never>;
|
|
49
|
+
/**
|
|
50
|
+
* The name of the {@link PermissionController}.
|
|
51
|
+
*/
|
|
52
|
+
declare const name = "PermissionLogController";
|
|
53
|
+
/**
|
|
54
|
+
* Controller with middleware for logging requests and responses to restricted
|
|
55
|
+
* and permissions-related methods.
|
|
56
|
+
*/
|
|
57
|
+
export declare class PermissionLogController extends BaseController<typeof name, PermissionLogControllerState, PermissionLogControllerMessenger> {
|
|
58
|
+
restrictedMethods: Set<string>;
|
|
59
|
+
constructor({ messenger, restrictedMethods, state, }: PermissionLogControllerOptions);
|
|
60
|
+
/**
|
|
61
|
+
* Get the restricted method activity log.
|
|
62
|
+
*
|
|
63
|
+
* @returns The activity log.
|
|
64
|
+
*/
|
|
65
|
+
getActivityLog(): PermissionActivityLog[];
|
|
66
|
+
/**
|
|
67
|
+
* Update the restricted method activity log.
|
|
68
|
+
*
|
|
69
|
+
* @param logs - The new activity log array.
|
|
70
|
+
*/
|
|
71
|
+
updateActivityLog(logs: PermissionActivityLog[]): void;
|
|
72
|
+
/**
|
|
73
|
+
* Get the permission history log.
|
|
74
|
+
*
|
|
75
|
+
* @returns The permissions history log.
|
|
76
|
+
*/
|
|
77
|
+
getHistory(): PermissionHistory;
|
|
78
|
+
/**
|
|
79
|
+
* Update the permission history log.
|
|
80
|
+
*
|
|
81
|
+
* @param history - The new permissions history log object.
|
|
82
|
+
*/
|
|
83
|
+
updateHistory(history: PermissionHistory): void;
|
|
84
|
+
/**
|
|
85
|
+
* Updates the exposed account history for the given origin.
|
|
86
|
+
* Sets the 'last seen' time to Date.now() for the given accounts.
|
|
87
|
+
* Does **not** update the 'lastApproved' time for the permission itself.
|
|
88
|
+
* Returns if the accounts array is empty.
|
|
89
|
+
*
|
|
90
|
+
* @param origin - The origin that the accounts are exposed to.
|
|
91
|
+
* @param accounts - The accounts.
|
|
92
|
+
*/
|
|
93
|
+
updateAccountsHistory(origin: string, accounts: string[]): void;
|
|
94
|
+
/**
|
|
95
|
+
* Create a permissions log middleware. Records permissions activity and history:
|
|
96
|
+
*
|
|
97
|
+
* Activity: requests and responses for restricted and most wallet_ methods.
|
|
98
|
+
*
|
|
99
|
+
* History: for each origin, the last time a permission was granted, including
|
|
100
|
+
* which accounts were exposed, if any.
|
|
101
|
+
*
|
|
102
|
+
* @returns The permissions log middleware.
|
|
103
|
+
*/
|
|
104
|
+
createMiddleware(): JsonRpcMiddleware<JsonRpcParams, Json>;
|
|
105
|
+
/**
|
|
106
|
+
* Creates and commits an activity log entry, without response data.
|
|
107
|
+
*
|
|
108
|
+
* @param request - The request object.
|
|
109
|
+
* @param isInternal - Whether the request is internal.
|
|
110
|
+
* @returns new added activity entry
|
|
111
|
+
*/
|
|
112
|
+
logRequest(request: JsonRpcRequestWithOrigin, isInternal: boolean): PermissionActivityLog;
|
|
113
|
+
/**
|
|
114
|
+
* Adds response data to an existing activity log entry.
|
|
115
|
+
* Entry assumed already committed (i.e., in the log).
|
|
116
|
+
*
|
|
117
|
+
* @param entry - The entry to add a response to.
|
|
118
|
+
* @param response - The response object.
|
|
119
|
+
* @param time - Output from Date.now()
|
|
120
|
+
*/
|
|
121
|
+
logResponse(entry: PermissionActivityLog, response: PendingJsonRpcResponse<Json>, time: number): void;
|
|
122
|
+
/**
|
|
123
|
+
* Commit a new entry to the activity log.
|
|
124
|
+
* Removes the oldest entry from the log if it exceeds the log limit.
|
|
125
|
+
*
|
|
126
|
+
* @param entry - The activity log entry.
|
|
127
|
+
*/
|
|
128
|
+
commitNewActivity(entry: PermissionActivityLog): void;
|
|
129
|
+
/**
|
|
130
|
+
* Create new permissions history log entries, if any, and commit them.
|
|
131
|
+
*
|
|
132
|
+
* @param requestedMethods - The method names corresponding to the requested permissions.
|
|
133
|
+
* @param origin - The origin of the permissions request.
|
|
134
|
+
* @param result - The permissions request response.result.
|
|
135
|
+
* @param time - The time of the request, i.e. Date.now().
|
|
136
|
+
* @param isEthRequestAccounts - Whether the permissions request was 'eth_requestAccounts'.
|
|
137
|
+
*/
|
|
138
|
+
logPermissionsHistory(requestedMethods: string[], origin: string, result: Json, time: number, isEthRequestAccounts: boolean): void;
|
|
139
|
+
/**
|
|
140
|
+
* Commit new entries to the permissions history log.
|
|
141
|
+
* Merges the history for the given origin, overwriting existing entries
|
|
142
|
+
* with the same key (permission name).
|
|
143
|
+
*
|
|
144
|
+
* @param origin - The requesting origin.
|
|
145
|
+
* @param newEntries - The new entries to commit.
|
|
146
|
+
*/
|
|
147
|
+
commitNewHistory(origin: string, newEntries: Record<PermissionName, Partial<PermissionLog>>): void;
|
|
148
|
+
/**
|
|
149
|
+
* Get all requested methods from a permissions request.
|
|
150
|
+
*
|
|
151
|
+
* @param request - The request object.
|
|
152
|
+
* @returns The names of the requested permissions.
|
|
153
|
+
*/
|
|
154
|
+
getRequestedMethods(request: JsonRpcRequestWithOrigin<any>): string[] | null;
|
|
155
|
+
/**
|
|
156
|
+
* Get the permitted accounts from an eth_accounts permissions object.
|
|
157
|
+
* Returns an empty array if the permission is not eth_accounts.
|
|
158
|
+
*
|
|
159
|
+
* @param perm - The permissions object.
|
|
160
|
+
* @param perm.parentCapability - The permissions parentCapability.
|
|
161
|
+
* @param perm.caveats - The permissions caveats.
|
|
162
|
+
* @returns The permitted accounts.
|
|
163
|
+
*/
|
|
164
|
+
getAccountsFromPermission(perm: Permission): string[];
|
|
165
|
+
}
|
|
166
|
+
export {};
|
|
167
|
+
//# sourceMappingURL=PermissionLogController.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PermissionLogController.d.ts","sourceRoot":"","sources":["../src/PermissionLogController.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,KAAK,6BAA6B,EACnC,MAAM,2BAA2B,CAAC;AACnC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BAAsB,CAAC,IAAI,CAAC,EACtC,IAAI,EAAE,MAAM;IAuBd;;;;;OAKG;IACH,iBAAiB,CAAC,KAAK,EAAE,qBAAqB;IAW9C;;;;;;;;OAQG;IACH,qBAAqB,CACnB,gBAAgB,EAAE,MAAM,EAAE,EAC1B,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,IAAI,EACZ,IAAI,EAAE,MAAM,EACZ,oBAAoB,EAAE,OAAO;IAyD/B;;;;;;;OAOG;IACH,gBAAgB,CACd,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,CAAC,cAAc,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;IAsC5D;;;;;OAKG;IACH,mBAAmB,CAAC,OAAO,EAAE,wBAAwB,CAAC,GAAG,CAAC,GAAG,MAAM,EAAE,GAAG,IAAI;IAY5E;;;;;;;;OAQG;IACH,yBAAyB,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,EAAE;CAkBtD"}
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PermissionLogController = void 0;
|
|
4
|
+
const base_controller_1 = require("@metamask/base-controller");
|
|
5
|
+
const enums_1 = require("./enums");
|
|
6
|
+
const defaultState = {
|
|
7
|
+
permissionHistory: {},
|
|
8
|
+
permissionActivityLog: [],
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* The name of the {@link PermissionController}.
|
|
12
|
+
*/
|
|
13
|
+
const name = 'PermissionLogController';
|
|
14
|
+
/**
|
|
15
|
+
* Controller with middleware for logging requests and responses to restricted
|
|
16
|
+
* and permissions-related methods.
|
|
17
|
+
*/
|
|
18
|
+
class PermissionLogController extends base_controller_1.BaseController {
|
|
19
|
+
constructor({ messenger, restrictedMethods, state, }) {
|
|
20
|
+
super({
|
|
21
|
+
messenger,
|
|
22
|
+
name,
|
|
23
|
+
metadata: {
|
|
24
|
+
permissionHistory: {
|
|
25
|
+
persist: true,
|
|
26
|
+
anonymous: false,
|
|
27
|
+
},
|
|
28
|
+
permissionActivityLog: {
|
|
29
|
+
persist: true,
|
|
30
|
+
anonymous: false,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
state: Object.assign(Object.assign({}, defaultState), state),
|
|
34
|
+
});
|
|
35
|
+
this.restrictedMethods = restrictedMethods;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Get the restricted method activity log.
|
|
39
|
+
*
|
|
40
|
+
* @returns The activity log.
|
|
41
|
+
*/
|
|
42
|
+
getActivityLog() {
|
|
43
|
+
return this.state.permissionActivityLog;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Update the restricted method activity log.
|
|
47
|
+
*
|
|
48
|
+
* @param logs - The new activity log array.
|
|
49
|
+
*/
|
|
50
|
+
updateActivityLog(logs) {
|
|
51
|
+
this.update((state) => {
|
|
52
|
+
state.permissionActivityLog = logs;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Get the permission history log.
|
|
57
|
+
*
|
|
58
|
+
* @returns The permissions history log.
|
|
59
|
+
*/
|
|
60
|
+
getHistory() {
|
|
61
|
+
return this.state.permissionHistory;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Update the permission history log.
|
|
65
|
+
*
|
|
66
|
+
* @param history - The new permissions history log object.
|
|
67
|
+
*/
|
|
68
|
+
updateHistory(history) {
|
|
69
|
+
this.update((state) => {
|
|
70
|
+
state.permissionHistory = history;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Updates the exposed account history for the given origin.
|
|
75
|
+
* Sets the 'last seen' time to Date.now() for the given accounts.
|
|
76
|
+
* Does **not** update the 'lastApproved' time for the permission itself.
|
|
77
|
+
* Returns if the accounts array is empty.
|
|
78
|
+
*
|
|
79
|
+
* @param origin - The origin that the accounts are exposed to.
|
|
80
|
+
* @param accounts - The accounts.
|
|
81
|
+
*/
|
|
82
|
+
updateAccountsHistory(origin, accounts) {
|
|
83
|
+
if (accounts.length === 0) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const accountToTimeMap = getAccountToTimeMap(accounts, Date.now());
|
|
87
|
+
this.commitNewHistory(origin, {
|
|
88
|
+
eth_accounts: {
|
|
89
|
+
accounts: accountToTimeMap,
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Create a permissions log middleware. Records permissions activity and history:
|
|
95
|
+
*
|
|
96
|
+
* Activity: requests and responses for restricted and most wallet_ methods.
|
|
97
|
+
*
|
|
98
|
+
* History: for each origin, the last time a permission was granted, including
|
|
99
|
+
* which accounts were exposed, if any.
|
|
100
|
+
*
|
|
101
|
+
* @returns The permissions log middleware.
|
|
102
|
+
*/
|
|
103
|
+
createMiddleware() {
|
|
104
|
+
return (req, res, next) => {
|
|
105
|
+
let activityEntry, requestedMethods;
|
|
106
|
+
const { origin, method } = req;
|
|
107
|
+
const isInternal = method.startsWith(enums_1.WALLET_PREFIX);
|
|
108
|
+
// we only log certain methods
|
|
109
|
+
if (!enums_1.LOG_IGNORE_METHODS.includes(method) &&
|
|
110
|
+
(isInternal || this.restrictedMethods.has(method))) {
|
|
111
|
+
activityEntry = this.logRequest(req, isInternal);
|
|
112
|
+
if (method === `${enums_1.WALLET_PREFIX}requestPermissions`) {
|
|
113
|
+
// get the corresponding methods from the requested permissions so
|
|
114
|
+
// that we can record permissions history
|
|
115
|
+
requestedMethods = this.getRequestedMethods(req);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
else if (method === 'eth_requestAccounts') {
|
|
119
|
+
// eth_requestAccounts is a special case; we need to extract the accounts
|
|
120
|
+
// from it
|
|
121
|
+
activityEntry = this.logRequest(req, isInternal);
|
|
122
|
+
requestedMethods = ['eth_accounts'];
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
// no-op
|
|
126
|
+
next();
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
// call next with a return handler for capturing the response
|
|
130
|
+
next((cb) => {
|
|
131
|
+
const time = Date.now();
|
|
132
|
+
this.logResponse(activityEntry, res, time);
|
|
133
|
+
if (requestedMethods && !res.error && res.result && origin) {
|
|
134
|
+
// any permissions or accounts changes will be recorded on the response,
|
|
135
|
+
// so we only log permissions history here
|
|
136
|
+
this.logPermissionsHistory(requestedMethods, origin, res.result, time, method === 'eth_requestAccounts');
|
|
137
|
+
}
|
|
138
|
+
cb();
|
|
139
|
+
});
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Creates and commits an activity log entry, without response data.
|
|
144
|
+
*
|
|
145
|
+
* @param request - The request object.
|
|
146
|
+
* @param isInternal - Whether the request is internal.
|
|
147
|
+
* @returns new added activity entry
|
|
148
|
+
*/
|
|
149
|
+
logRequest(request, isInternal) {
|
|
150
|
+
const activityEntry = {
|
|
151
|
+
id: request.id,
|
|
152
|
+
method: request.method,
|
|
153
|
+
methodType: isInternal
|
|
154
|
+
? enums_1.LOG_METHOD_TYPES.internal
|
|
155
|
+
: enums_1.LOG_METHOD_TYPES.restricted,
|
|
156
|
+
origin: request.origin,
|
|
157
|
+
requestTime: Date.now(),
|
|
158
|
+
responseTime: null,
|
|
159
|
+
success: null,
|
|
160
|
+
};
|
|
161
|
+
this.commitNewActivity(activityEntry);
|
|
162
|
+
return activityEntry;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Adds response data to an existing activity log entry.
|
|
166
|
+
* Entry assumed already committed (i.e., in the log).
|
|
167
|
+
*
|
|
168
|
+
* @param entry - The entry to add a response to.
|
|
169
|
+
* @param response - The response object.
|
|
170
|
+
* @param time - Output from Date.now()
|
|
171
|
+
*/
|
|
172
|
+
logResponse(entry, response, time) {
|
|
173
|
+
if (!entry || !response) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
// The JSON-RPC 2.0 specification defines "success" by the presence of
|
|
177
|
+
// either the "result" or "error" property. The specification forbids
|
|
178
|
+
// both properties from being present simultaneously, and our JSON-RPC
|
|
179
|
+
// stack is spec-compliant at the time of writing.
|
|
180
|
+
this.update((state) => {
|
|
181
|
+
const targetPermissionActivyLogIndex = state.permissionActivityLog.findIndex((pActivityLog) => pActivityLog.id === entry.id);
|
|
182
|
+
state.permissionActivityLog[targetPermissionActivyLogIndex] = Object.assign(Object.assign({}, entry), { success: Object.hasOwnProperty.call(response, 'result'), responseTime: time });
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Commit a new entry to the activity log.
|
|
187
|
+
* Removes the oldest entry from the log if it exceeds the log limit.
|
|
188
|
+
*
|
|
189
|
+
* @param entry - The activity log entry.
|
|
190
|
+
*/
|
|
191
|
+
commitNewActivity(entry) {
|
|
192
|
+
const logs = [...this.getActivityLog(), entry];
|
|
193
|
+
// remove oldest log if exceeding size limit
|
|
194
|
+
if (logs.length > enums_1.LOG_LIMIT) {
|
|
195
|
+
logs.shift();
|
|
196
|
+
}
|
|
197
|
+
this.updateActivityLog(logs);
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Create new permissions history log entries, if any, and commit them.
|
|
201
|
+
*
|
|
202
|
+
* @param requestedMethods - The method names corresponding to the requested permissions.
|
|
203
|
+
* @param origin - The origin of the permissions request.
|
|
204
|
+
* @param result - The permissions request response.result.
|
|
205
|
+
* @param time - The time of the request, i.e. Date.now().
|
|
206
|
+
* @param isEthRequestAccounts - Whether the permissions request was 'eth_requestAccounts'.
|
|
207
|
+
*/
|
|
208
|
+
logPermissionsHistory(requestedMethods, origin, result, time, isEthRequestAccounts) {
|
|
209
|
+
let accounts;
|
|
210
|
+
let newEntries;
|
|
211
|
+
if (isEthRequestAccounts) {
|
|
212
|
+
// Type assertion: We are assuming that the response data contains
|
|
213
|
+
// a set of accounts if the RPC method is "eth_requestAccounts".
|
|
214
|
+
accounts = result;
|
|
215
|
+
const accountToTimeMap = getAccountToTimeMap(accounts, time);
|
|
216
|
+
newEntries = {
|
|
217
|
+
eth_accounts: {
|
|
218
|
+
accounts: accountToTimeMap,
|
|
219
|
+
lastApproved: time,
|
|
220
|
+
},
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
// Records new "lastApproved" times for the granted permissions, if any.
|
|
225
|
+
// Special handling for eth_accounts, in order to record the time the
|
|
226
|
+
// accounts were last seen or approved by the origin.
|
|
227
|
+
// Type assertion: We are assuming that the response data contains
|
|
228
|
+
// a set of permissions if the RPC method is "eth_requestPermissions".
|
|
229
|
+
newEntries = result
|
|
230
|
+
.map((perm) => {
|
|
231
|
+
if (perm.parentCapability === 'eth_accounts') {
|
|
232
|
+
accounts = this.getAccountsFromPermission(perm);
|
|
233
|
+
}
|
|
234
|
+
return perm.parentCapability;
|
|
235
|
+
})
|
|
236
|
+
.reduce((acc, method) => {
|
|
237
|
+
// all approved permissions will be included in the response,
|
|
238
|
+
// not just the newly requested ones
|
|
239
|
+
if (requestedMethods.includes(method)) {
|
|
240
|
+
if (method === 'eth_accounts') {
|
|
241
|
+
const accountToTimeMap = getAccountToTimeMap(accounts, time);
|
|
242
|
+
acc[method] = {
|
|
243
|
+
lastApproved: time,
|
|
244
|
+
accounts: accountToTimeMap,
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
acc[method] = { lastApproved: time };
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return acc;
|
|
252
|
+
}, {});
|
|
253
|
+
}
|
|
254
|
+
if (Object.keys(newEntries).length > 0) {
|
|
255
|
+
this.commitNewHistory(origin, newEntries);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Commit new entries to the permissions history log.
|
|
260
|
+
* Merges the history for the given origin, overwriting existing entries
|
|
261
|
+
* with the same key (permission name).
|
|
262
|
+
*
|
|
263
|
+
* @param origin - The requesting origin.
|
|
264
|
+
* @param newEntries - The new entries to commit.
|
|
265
|
+
*/
|
|
266
|
+
commitNewHistory(origin, newEntries) {
|
|
267
|
+
var _a;
|
|
268
|
+
// a simple merge updates most permissions
|
|
269
|
+
const history = this.getHistory();
|
|
270
|
+
const newOriginHistory = Object.assign(Object.assign({}, history[origin]), newEntries);
|
|
271
|
+
// eth_accounts requires special handling, because of information
|
|
272
|
+
// we store about the accounts
|
|
273
|
+
const existingEthAccountsEntry = history[origin] && history[origin].eth_accounts;
|
|
274
|
+
const newEthAccountsEntry = newEntries.eth_accounts;
|
|
275
|
+
if (existingEthAccountsEntry && newEthAccountsEntry) {
|
|
276
|
+
// we may intend to update just the accounts, not the permission
|
|
277
|
+
// itself
|
|
278
|
+
const lastApproved = (_a = newEthAccountsEntry.lastApproved) !== null && _a !== void 0 ? _a : existingEthAccountsEntry.lastApproved;
|
|
279
|
+
// merge old and new eth_accounts history entries
|
|
280
|
+
newOriginHistory.eth_accounts = {
|
|
281
|
+
lastApproved,
|
|
282
|
+
accounts: Object.assign(Object.assign({}, existingEthAccountsEntry.accounts), newEthAccountsEntry.accounts),
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
this.updateHistory(Object.assign(Object.assign({}, history), { [origin]: newOriginHistory }));
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Get all requested methods from a permissions request.
|
|
289
|
+
*
|
|
290
|
+
* @param request - The request object.
|
|
291
|
+
* @returns The names of the requested permissions.
|
|
292
|
+
*/
|
|
293
|
+
getRequestedMethods(request) {
|
|
294
|
+
if (!request.params ||
|
|
295
|
+
!request.params[0] ||
|
|
296
|
+
typeof request.params[0] !== 'object' ||
|
|
297
|
+
Array.isArray(request.params[0])) {
|
|
298
|
+
return null;
|
|
299
|
+
}
|
|
300
|
+
return Object.keys(request.params[0]);
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Get the permitted accounts from an eth_accounts permissions object.
|
|
304
|
+
* Returns an empty array if the permission is not eth_accounts.
|
|
305
|
+
*
|
|
306
|
+
* @param perm - The permissions object.
|
|
307
|
+
* @param perm.parentCapability - The permissions parentCapability.
|
|
308
|
+
* @param perm.caveats - The permissions caveats.
|
|
309
|
+
* @returns The permitted accounts.
|
|
310
|
+
*/
|
|
311
|
+
getAccountsFromPermission(perm) {
|
|
312
|
+
if (perm.parentCapability !== 'eth_accounts' || !perm.caveats) {
|
|
313
|
+
return [];
|
|
314
|
+
}
|
|
315
|
+
const accounts = new Set();
|
|
316
|
+
for (const caveat of perm.caveats) {
|
|
317
|
+
if (caveat.type === enums_1.CAVEAT_TYPES.restrictReturnedAccounts &&
|
|
318
|
+
Array.isArray(caveat.value)) {
|
|
319
|
+
for (const value of caveat.value) {
|
|
320
|
+
accounts.add(value);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
return [...accounts];
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
exports.PermissionLogController = PermissionLogController;
|
|
328
|
+
// helper functions
|
|
329
|
+
/**
|
|
330
|
+
* Get a map from account addresses to the given time.
|
|
331
|
+
*
|
|
332
|
+
* @param accounts - An array of addresses.
|
|
333
|
+
* @param time - A time, e.g. Date.now().
|
|
334
|
+
* @returns A string:number map of addresses to time.
|
|
335
|
+
*/
|
|
336
|
+
function getAccountToTimeMap(accounts, time) {
|
|
337
|
+
return accounts.reduce((acc, account) => (Object.assign(Object.assign({}, acc), { [account]: time })), {});
|
|
338
|
+
}
|
|
339
|
+
//# sourceMappingURL=PermissionLogController.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PermissionLogController.js","sourceRoot":"","sources":["../src/PermissionLogController.ts"],"names":[],"mappings":";;;AAAA,+DAGmC;AASnC,mCAMiB;AA+DjB,MAAM,YAAY,GAAiC;IACjD,iBAAiB,EAAE,EAAE;IACrB,qBAAqB,EAAE,EAAE;CAC1B,CAAC;AAEF;;GAEG;AACH,MAAM,IAAI,GAAG,yBAAyB,CAAC;AAEv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,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE,CAAC,iCAAM,GAAG,KAAE,CAAC,OAAO,CAAC,EAAE,IAAI,IAAG,EAAE,EAAE,CAAC,CAAC;AAC9E,CAAC","sourcesContent":["import {\n BaseController,\n type RestrictedControllerMessenger,\n} from '@metamask/base-controller';\nimport type { JsonRpcMiddleware } from '@metamask/json-rpc-engine';\nimport type {\n Json,\n JsonRpcRequest,\n JsonRpcParams,\n PendingJsonRpcResponse,\n} from '@metamask/utils';\n\nimport {\n LOG_IGNORE_METHODS,\n LOG_LIMIT,\n LOG_METHOD_TYPES,\n WALLET_PREFIX,\n CAVEAT_TYPES,\n} from './enums';\n\nexport type JsonRpcRequestWithOrigin<\n Params extends JsonRpcParams = JsonRpcParams,\n> = JsonRpcRequest<Params> & {\n origin?: string;\n};\n\nexport type Caveat = {\n type: string;\n value: string[];\n};\n\nexport type Permission = {\n parentCapability: string;\n caveats?: Caveat[];\n};\n\nexport type PermissionActivityLog = {\n id: string | number | null;\n method: string;\n methodType: LOG_METHOD_TYPES;\n origin?: string;\n requestTime: number;\n responseTime: number | null;\n success: boolean | null;\n};\n\nexport type PermissionName = string;\nexport type PermissionLog = {\n accounts?: Record<string, number>;\n lastApproved: number;\n};\nexport type PermissionEntry = Record<PermissionName, PermissionLog>;\n\nexport type PermissionOrigin = string;\nexport type PermissionHistory = Record<PermissionOrigin, PermissionEntry>;\n\n/**\n *\n * Permission log controller state\n * @property permissionHistory - permission history\n * @property permissionActivityLog - permission activity logs\n */\nexport type PermissionLogControllerState = {\n permissionHistory: PermissionHistory;\n permissionActivityLog: PermissionActivityLog[];\n};\n\nexport type PermissionLogControllerOptions = {\n restrictedMethods: Set<string>;\n state?: Partial<PermissionLogControllerState>;\n messenger: PermissionLogControllerMessenger;\n};\n\nexport type PermissionLogControllerMessenger = RestrictedControllerMessenger<\n typeof name,\n never,\n never,\n never,\n never\n>;\n\nconst defaultState: PermissionLogControllerState = {\n permissionHistory: {},\n permissionActivityLog: [],\n};\n\n/**\n * The name of the {@link PermissionController}.\n */\nconst name = 'PermissionLogController';\n\n/**\n * Controller with middleware for logging requests and responses to restricted\n * and permissions-related methods.\n */\nexport class PermissionLogController extends BaseController<\n typeof name,\n PermissionLogControllerState,\n PermissionLogControllerMessenger\n> {\n restrictedMethods: Set<string>;\n\n constructor({\n messenger,\n restrictedMethods,\n state,\n }: PermissionLogControllerOptions) {\n super({\n messenger,\n name,\n metadata: {\n permissionHistory: {\n persist: true,\n anonymous: false,\n },\n permissionActivityLog: {\n persist: true,\n anonymous: false,\n },\n },\n state: { ...defaultState, ...state },\n });\n this.restrictedMethods = restrictedMethods;\n }\n\n /**\n * Get the restricted method activity log.\n *\n * @returns The activity log.\n */\n getActivityLog(): PermissionActivityLog[] {\n return this.state.permissionActivityLog;\n }\n\n /**\n * Update the restricted method activity log.\n *\n * @param logs - The new activity log array.\n */\n updateActivityLog(logs: PermissionActivityLog[]) {\n this.update((state) => {\n state.permissionActivityLog = logs;\n });\n }\n\n /**\n * Get the permission history log.\n *\n * @returns The permissions history log.\n */\n getHistory(): PermissionHistory {\n return this.state.permissionHistory;\n }\n\n /**\n * Update the permission history log.\n *\n * @param history - The new permissions history log object.\n */\n updateHistory(history: PermissionHistory) {\n this.update((state) => {\n state.permissionHistory = history;\n });\n }\n\n /**\n * Updates the exposed account history for the given origin.\n * Sets the 'last seen' time to Date.now() for the given accounts.\n * Does **not** update the 'lastApproved' time for the permission itself.\n * Returns if the accounts array is empty.\n *\n * @param origin - The origin that the accounts are exposed to.\n * @param accounts - The accounts.\n */\n updateAccountsHistory(origin: string, accounts: string[]) {\n if (accounts.length === 0) {\n return;\n }\n\n const accountToTimeMap = getAccountToTimeMap(accounts, Date.now());\n\n this.commitNewHistory(origin, {\n eth_accounts: {\n accounts: accountToTimeMap,\n },\n });\n }\n\n /**\n * Create a permissions log middleware. Records permissions activity and history:\n *\n * Activity: requests and responses for restricted and most wallet_ methods.\n *\n * History: for each origin, the last time a permission was granted, including\n * which accounts were exposed, if any.\n *\n * @returns The permissions log middleware.\n */\n createMiddleware(): JsonRpcMiddleware<JsonRpcParams, Json> {\n return (req: JsonRpcRequestWithOrigin, res, next) => {\n let activityEntry: PermissionActivityLog,\n requestedMethods: string[] | null;\n const { origin, method } = req;\n const isInternal = method.startsWith(WALLET_PREFIX);\n\n // we only log certain methods\n if (\n !LOG_IGNORE_METHODS.includes(method) &&\n (isInternal || this.restrictedMethods.has(method))\n ) {\n activityEntry = this.logRequest(req, isInternal);\n\n if (method === `${WALLET_PREFIX}requestPermissions`) {\n // get the corresponding methods from the requested permissions so\n // that we can record permissions history\n requestedMethods = this.getRequestedMethods(req);\n }\n } else if (method === 'eth_requestAccounts') {\n // eth_requestAccounts is a special case; we need to extract the accounts\n // from it\n activityEntry = this.logRequest(req, isInternal);\n requestedMethods = ['eth_accounts'];\n } else {\n // no-op\n next();\n return;\n }\n\n // call next with a return handler for capturing the response\n next((cb) => {\n const time = Date.now();\n this.logResponse(activityEntry, res, time);\n\n if (requestedMethods && !res.error && res.result && origin) {\n // any permissions or accounts changes will be recorded on the response,\n // so we only log permissions history here\n this.logPermissionsHistory(\n requestedMethods,\n origin,\n res.result,\n time,\n method === 'eth_requestAccounts',\n );\n }\n cb();\n });\n };\n }\n\n /**\n * Creates and commits an activity log entry, without response data.\n *\n * @param request - The request object.\n * @param isInternal - Whether the request is internal.\n * @returns new added activity entry\n */\n logRequest(\n request: JsonRpcRequestWithOrigin,\n isInternal: boolean,\n ): PermissionActivityLog {\n const activityEntry: PermissionActivityLog = {\n id: request.id,\n method: request.method,\n methodType: isInternal\n ? LOG_METHOD_TYPES.internal\n : LOG_METHOD_TYPES.restricted,\n origin: request.origin,\n requestTime: Date.now(),\n responseTime: null,\n success: null,\n };\n this.commitNewActivity(activityEntry);\n return activityEntry;\n }\n\n /**\n * Adds response data to an existing activity log entry.\n * Entry assumed already committed (i.e., in the log).\n *\n * @param entry - The entry to add a response to.\n * @param response - The response object.\n * @param time - Output from Date.now()\n */\n logResponse(\n entry: PermissionActivityLog,\n response: PendingJsonRpcResponse<Json>,\n time: number,\n ) {\n if (!entry || !response) {\n return;\n }\n\n // The JSON-RPC 2.0 specification defines \"success\" by the presence of\n // either the \"result\" or \"error\" property. The specification forbids\n // both properties from being present simultaneously, and our JSON-RPC\n // stack is spec-compliant at the time of writing.\n this.update((state) => {\n const targetPermissionActivyLogIndex =\n state.permissionActivityLog.findIndex(\n (pActivityLog) => pActivityLog.id === entry.id,\n );\n state.permissionActivityLog[targetPermissionActivyLogIndex] = {\n ...entry,\n success: Object.hasOwnProperty.call(response, 'result'),\n responseTime: time,\n };\n });\n }\n\n /**\n * Commit a new entry to the activity log.\n * Removes the oldest entry from the log if it exceeds the log limit.\n *\n * @param entry - The activity log entry.\n */\n commitNewActivity(entry: PermissionActivityLog) {\n const logs = [...this.getActivityLog(), entry];\n\n // remove oldest log if exceeding size limit\n if (logs.length > LOG_LIMIT) {\n logs.shift();\n }\n\n this.updateActivityLog(logs);\n }\n\n /**\n * Create new permissions history log entries, if any, and commit them.\n *\n * @param requestedMethods - The method names corresponding to the requested permissions.\n * @param origin - The origin of the permissions request.\n * @param result - The permissions request response.result.\n * @param time - The time of the request, i.e. Date.now().\n * @param isEthRequestAccounts - Whether the permissions request was 'eth_requestAccounts'.\n */\n logPermissionsHistory(\n requestedMethods: string[],\n origin: string,\n result: Json,\n time: number,\n isEthRequestAccounts: boolean,\n ) {\n let accounts: string[];\n let newEntries: PermissionEntry;\n\n if (isEthRequestAccounts) {\n // Type assertion: We are assuming that the response data contains\n // a set of accounts if the RPC method is \"eth_requestAccounts\".\n accounts = result as string[];\n const accountToTimeMap = getAccountToTimeMap(accounts, time);\n\n newEntries = {\n eth_accounts: {\n accounts: accountToTimeMap,\n lastApproved: time,\n },\n };\n } else {\n // Records new \"lastApproved\" times for the granted permissions, if any.\n // Special handling for eth_accounts, in order to record the time the\n // accounts were last seen or approved by the origin.\n\n // Type assertion: We are assuming that the response data contains\n // a set of permissions if the RPC method is \"eth_requestPermissions\".\n newEntries = (result as Permission[])\n .map((perm) => {\n if (perm.parentCapability === 'eth_accounts') {\n accounts = this.getAccountsFromPermission(perm);\n }\n\n return perm.parentCapability;\n })\n .reduce((acc: PermissionEntry, method) => {\n // all approved permissions will be included in the response,\n // not just the newly requested ones\n if (requestedMethods.includes(method)) {\n if (method === 'eth_accounts') {\n const accountToTimeMap = getAccountToTimeMap(accounts, time);\n\n acc[method] = {\n lastApproved: time,\n accounts: accountToTimeMap,\n };\n } else {\n acc[method] = { lastApproved: time };\n }\n }\n\n return acc;\n }, {});\n }\n\n if (Object.keys(newEntries).length > 0) {\n this.commitNewHistory(origin, newEntries);\n }\n }\n\n /**\n * Commit new entries to the permissions history log.\n * Merges the history for the given origin, overwriting existing entries\n * with the same key (permission name).\n *\n * @param origin - The requesting origin.\n * @param newEntries - The new entries to commit.\n */\n commitNewHistory(\n origin: string,\n newEntries: Record<PermissionName, Partial<PermissionLog>>,\n ) {\n // a simple merge updates most permissions\n const history = this.getHistory();\n const newOriginHistory = {\n ...history[origin],\n ...newEntries,\n };\n\n // eth_accounts requires special handling, because of information\n // we store about the accounts\n const existingEthAccountsEntry =\n history[origin] && history[origin].eth_accounts;\n const newEthAccountsEntry = newEntries.eth_accounts;\n\n if (existingEthAccountsEntry && newEthAccountsEntry) {\n // we may intend to update just the accounts, not the permission\n // itself\n const lastApproved =\n newEthAccountsEntry.lastApproved ??\n existingEthAccountsEntry.lastApproved;\n\n // merge old and new eth_accounts history entries\n newOriginHistory.eth_accounts = {\n lastApproved,\n accounts: {\n ...existingEthAccountsEntry.accounts,\n ...newEthAccountsEntry.accounts,\n },\n };\n }\n\n this.updateHistory({\n ...history,\n [origin]: newOriginHistory as PermissionEntry,\n });\n }\n\n /**\n * Get all requested methods from a permissions request.\n *\n * @param request - The request object.\n * @returns The names of the requested permissions.\n */\n getRequestedMethods(request: JsonRpcRequestWithOrigin<any>): string[] | null {\n if (\n !request.params ||\n !request.params[0] ||\n typeof request.params[0] !== 'object' ||\n Array.isArray(request.params[0])\n ) {\n return null;\n }\n return Object.keys(request.params[0]);\n }\n\n /**\n * Get the permitted accounts from an eth_accounts permissions object.\n * Returns an empty array if the permission is not eth_accounts.\n *\n * @param perm - The permissions object.\n * @param perm.parentCapability - The permissions parentCapability.\n * @param perm.caveats - The permissions caveats.\n * @returns The permitted accounts.\n */\n getAccountsFromPermission(perm: Permission): string[] {\n if (perm.parentCapability !== 'eth_accounts' || !perm.caveats) {\n return [];\n }\n\n const accounts = new Set<string>();\n for (const caveat of perm.caveats) {\n if (\n caveat.type === CAVEAT_TYPES.restrictReturnedAccounts &&\n Array.isArray(caveat.value)\n ) {\n for (const value of caveat.value) {\n accounts.add(value);\n }\n }\n }\n return [...accounts];\n }\n}\n\n// helper functions\n\n/**\n * Get a map from account addresses to the given time.\n *\n * @param accounts - An array of addresses.\n * @param time - A time, e.g. Date.now().\n * @returns A string:number map of addresses to time.\n */\nfunction getAccountToTimeMap(\n accounts: string[],\n time: number,\n): Record<string, number> {\n return accounts.reduce((acc, account) => ({ ...acc, [account]: time }), {});\n}\n"]}
|
package/dist/enums.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const WALLET_PREFIX = "wallet_";
|
|
2
|
+
export declare const CAVEAT_TYPES: Readonly<{
|
|
3
|
+
restrictReturnedAccounts: "restrictReturnedAccounts";
|
|
4
|
+
}>;
|
|
5
|
+
export declare const LOG_IGNORE_METHODS: string[];
|
|
6
|
+
export declare enum LOG_METHOD_TYPES {
|
|
7
|
+
restricted = "restricted",
|
|
8
|
+
internal = "internal"
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The permission activity log size limit.
|
|
12
|
+
*/
|
|
13
|
+
export declare const LOG_LIMIT = 100;
|
|
14
|
+
//# sourceMappingURL=enums.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enums.d.ts","sourceRoot":"","sources":["../src/enums.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,YAAY,CAAC;AAEvC,eAAO,MAAM,YAAY;;EAEvB,CAAC;AAEH,eAAO,MAAM,kBAAkB,UAG9B,CAAC;AAEF,oBAAY,gBAAgB;IAC1B,UAAU,eAAe;IACzB,QAAQ,aAAa;CACtB;AAED;;GAEG;AACH,eAAO,MAAM,SAAS,MAAM,CAAC"}
|
package/dist/enums.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LOG_LIMIT = exports.LOG_METHOD_TYPES = exports.LOG_IGNORE_METHODS = exports.CAVEAT_TYPES = exports.WALLET_PREFIX = void 0;
|
|
4
|
+
exports.WALLET_PREFIX = 'wallet_';
|
|
5
|
+
exports.CAVEAT_TYPES = Object.freeze({
|
|
6
|
+
restrictReturnedAccounts: 'restrictReturnedAccounts',
|
|
7
|
+
});
|
|
8
|
+
exports.LOG_IGNORE_METHODS = [
|
|
9
|
+
'wallet_registerOnboarding',
|
|
10
|
+
'wallet_watchAsset',
|
|
11
|
+
];
|
|
12
|
+
var LOG_METHOD_TYPES;
|
|
13
|
+
(function (LOG_METHOD_TYPES) {
|
|
14
|
+
LOG_METHOD_TYPES["restricted"] = "restricted";
|
|
15
|
+
LOG_METHOD_TYPES["internal"] = "internal";
|
|
16
|
+
})(LOG_METHOD_TYPES = exports.LOG_METHOD_TYPES || (exports.LOG_METHOD_TYPES = {}));
|
|
17
|
+
/**
|
|
18
|
+
* The permission activity log size limit.
|
|
19
|
+
*/
|
|
20
|
+
exports.LOG_LIMIT = 100;
|
|
21
|
+
//# sourceMappingURL=enums.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enums.js","sourceRoot":"","sources":["../src/enums.ts"],"names":[],"mappings":";;;AAAa,QAAA,aAAa,GAAG,SAAS,CAAC;AAE1B,QAAA,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC;IACxC,wBAAwB,EAAE,0BAAmC;CAC9D,CAAC,CAAC;AAEU,QAAA,kBAAkB,GAAG;IAChC,2BAA2B;IAC3B,mBAAmB;CACpB,CAAC;AAEF,IAAY,gBAGX;AAHD,WAAY,gBAAgB;IAC1B,6CAAyB,CAAA;IACzB,yCAAqB,CAAA;AACvB,CAAC,EAHW,gBAAgB,GAAhB,wBAAgB,KAAhB,wBAAgB,QAG3B;AAED;;GAEG;AACU,QAAA,SAAS,GAAG,GAAG,CAAC","sourcesContent":["export const WALLET_PREFIX = 'wallet_';\n\nexport const CAVEAT_TYPES = Object.freeze({\n restrictReturnedAccounts: 'restrictReturnedAccounts' as const,\n});\n\nexport const LOG_IGNORE_METHODS = [\n 'wallet_registerOnboarding',\n 'wallet_watchAsset',\n];\n\nexport enum LOG_METHOD_TYPES {\n restricted = 'restricted',\n internal = 'internal',\n}\n\n/**\n * The permission activity log size limit.\n */\nexport const LOG_LIMIT = 100;\n"]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./PermissionLogController"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4DAA0C","sourcesContent":["export * from './PermissionLogController';\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@metamask-previews/permission-log-controller",
|
|
3
|
+
"version": "0.0.0-preview.3fbb6b41",
|
|
4
|
+
"description": "Controller with middleware for logging requests and responses to restricted and permissions-related methods",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"MetaMask",
|
|
7
|
+
"Ethereum"
|
|
8
|
+
],
|
|
9
|
+
"homepage": "https://github.com/MetaMask/core/tree/main/packages/permission-log-controller#readme",
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/MetaMask/core/issues"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/MetaMask/core.git"
|
|
16
|
+
},
|
|
17
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
18
|
+
"main": "./dist/index.js",
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"files": [
|
|
21
|
+
"dist/"
|
|
22
|
+
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build:docs": "typedoc",
|
|
25
|
+
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/permission-log-controller",
|
|
26
|
+
"publish:preview": "yarn npm publish --tag preview",
|
|
27
|
+
"test": "jest --reporters=jest-silent-reporter",
|
|
28
|
+
"test:clean": "jest --clearCache",
|
|
29
|
+
"test:verbose": "jest --verbose",
|
|
30
|
+
"test:watch": "jest --watch"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@metamask/base-controller": "^4.0.0",
|
|
34
|
+
"@metamask/json-rpc-engine": "^7.3.0",
|
|
35
|
+
"@metamask/utils": "^8.2.0"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@metamask/auto-changelog": "^3.4.3",
|
|
39
|
+
"@types/deep-freeze-strict": "^1.1.0",
|
|
40
|
+
"@types/jest": "^27.4.1",
|
|
41
|
+
"deep-freeze-strict": "^1.1.1",
|
|
42
|
+
"deepmerge": "^4.2.2",
|
|
43
|
+
"jest": "^27.5.1",
|
|
44
|
+
"nanoid": "^3.1.31",
|
|
45
|
+
"sinon": "^9.2.4",
|
|
46
|
+
"ts-jest": "^27.1.4",
|
|
47
|
+
"typedoc": "^0.24.8",
|
|
48
|
+
"typedoc-plugin-missing-exports": "^2.0.0",
|
|
49
|
+
"typescript": "~4.8.4"
|
|
50
|
+
},
|
|
51
|
+
"engines": {
|
|
52
|
+
"node": ">=16.0.0"
|
|
53
|
+
},
|
|
54
|
+
"publishConfig": {
|
|
55
|
+
"access": "public",
|
|
56
|
+
"registry": "https://registry.npmjs.org/"
|
|
57
|
+
}
|
|
58
|
+
}
|